import { ModelInit, PersistentModelConstructor, Predicates, __modelMeta__, } from '../../../src'; import { DataStore, dummyInstance, expectType, ManagedCustomRO, ManagedDefaultRO, } from '../../helpers'; describe('Managed Identifier', () => { test(`ManagedDefaultRO`, async () => { expectType>({ // @ts-expect-error // id: 'eeeeeee', name: '', description: '', }); expectType>({ name: '', description: '', // @ts-expect-error // x: 234, }); expectType>({ name: '', description: '', // @ts-expect-error // x: 234, }); ManagedDefaultRO.copyOf({} as ManagedDefaultRO, d => { d.id; // @ts-expect-error // d.id = ''; d.name = ''; d.description = ''; d.createdAt; // @ts-expect-error // d.createdAt = ''; d.updatedAt; // @ts-expect-error // d.updatedAt = ''; }); // Query expectType( await DataStore.query(ManagedDefaultRO, 'someid') ); expectType( await DataStore.query(ManagedDefaultRO, { id: 'someid' }) ); expectType(await DataStore.query(ManagedDefaultRO)); expectType( await DataStore.query(ManagedDefaultRO, Predicates.ALL) ); expectType( await DataStore.query(ManagedDefaultRO, c => c.createdAt.ge('2019')) ); // Save expectType( await DataStore.save(dummyInstance()) ); expectType( await DataStore.save(dummyInstance(), c => c.createdAt.ge('2019') ) ); // Delete expectType( await DataStore.delete(ManagedDefaultRO, '') ); expectType( await DataStore.delete(dummyInstance()) ); expectType( await DataStore.delete(dummyInstance(), c => c.description.contains('something') ) ); expectType( await DataStore.delete(ManagedDefaultRO, Predicates.ALL) ); expectType( await DataStore.delete(ManagedDefaultRO, c => c.createdAt.le('2019')) ); // Observe DataStore.observe(ManagedDefaultRO).subscribe(({ model, element }) => { expectType>(model); expectType(element); }); DataStore.observe(ManagedDefaultRO, c => c.description.beginsWith('something') ).subscribe(({ model, element }) => { expectType>(model); expectType(element); }); DataStore.observe(dummyInstance()).subscribe( ({ model, element }) => { expectType>(model); expectType(element); } ); // Observe query DataStore.observeQuery(ManagedDefaultRO).subscribe(({ items }) => { expectType(items); }); DataStore.observeQuery(ManagedDefaultRO, c => c.description.notContains('something') ).subscribe(({ items }) => { expectType(items); }); DataStore.observeQuery( ManagedDefaultRO, c => c.description.notContains('something'), { sort: c => c.createdAt('ASCENDING') } ).subscribe(({ items }) => { expectType(items); }); }); test(`ManagedCustomRO`, async () => { expectType>({ // @ts-expect-error // id: 'eeeeeee', name: '', description: '', }); expectType>({ name: '', description: '', // @ts-expect-error // x: 234, }); expectType>({ name: '', description: '', // @ts-expect-error // x: 234, }); ManagedCustomRO.copyOf({} as ManagedCustomRO, d => { d.id; // @ts-expect-error // d.id = ''; d.name = ''; d.description = ''; d.createdOn; // @ts-expect-error // d.createdOn = ''; d.updatedOn; // @ts-expect-error // d.updatedOn = ''; }); // Query expectType( await DataStore.query(ManagedCustomRO, 'someid') ); expectType(await DataStore.query(ManagedCustomRO)); expectType( await DataStore.query(ManagedCustomRO, Predicates.ALL) ); expectType( await DataStore.query(ManagedCustomRO, c => c.createdOn.ge('2019')) ); // Save expectType( await DataStore.save(dummyInstance()) ); expectType( await DataStore.save(dummyInstance(), c => c.createdOn.ge('2019') ) ); // Delete expectType(await DataStore.delete(ManagedCustomRO, '')); expectType( await DataStore.delete(dummyInstance()) ); expectType( await DataStore.delete(dummyInstance(), c => c.description.contains('something') ) ); expectType( await DataStore.delete(ManagedCustomRO, Predicates.ALL) ); expectType( await DataStore.delete(ManagedCustomRO, c => c.createdOn.le('2019')) ); // Observe DataStore.observe(ManagedCustomRO).subscribe(({ model, element }) => { expectType>(model); expectType(element); }); DataStore.observe(ManagedCustomRO, c => c.description.beginsWith('something') ).subscribe(({ model, element }) => { expectType>(model); expectType(element); }); DataStore.observe(dummyInstance()).subscribe( ({ model, element }) => { expectType>(model); expectType(element); } ); // Observe query DataStore.observeQuery(ManagedCustomRO).subscribe(({ items }) => { expectType(items); }); DataStore.observeQuery(ManagedCustomRO, c => c.description.notContains('something') ).subscribe(({ items }) => { expectType(items); }); DataStore.observeQuery( ManagedCustomRO, c => c.description.notContains('something'), { sort: c => c.createdOn('ASCENDING') } ).subscribe(({ items }) => { expectType(items); }); }); });