import { createSchema , typedModel , Type } from '../src' ; import { Types , Document } from 'mongoose' ; import { UpdatedAt , CreatedAt , VerKey , Id } from '../src/types/_shared' ; type NotPresent < T , V > = T & Partial < Record < keyof V , never > > ; const TimestampsTests = ( ) => { type CreatedAtObj = Record < CreatedAt , Date > ; type UpdatedAtObj = Record < UpdatedAt , Date > ; type CreatedAtCustomObj = Record < 'customCreatedAt' , Date > ; type UpdatedAtCustomObj = Record < 'customUpdatedAt' , Date > ; function createdAtNotPresent ( _ ) { } function updatedAtNotPresent ( _ ) { } function createdAtPresent ( _ ) { } function updatedAtPresent ( _ ) { } function createdAtCustomPresent ( _ ) { } function updatedAtCustomPresent ( _ ) { } typedModel ( '' , createSchema ( { } ) ) . findOne ( ) . then ( val => val && createdAtNotPresent ( val ) && updatedAtNotPresent ( val ) ) ; typedModel ( '' , createSchema ( { } , { timestamps : false } ) ) . findOne ( ) . then ( val => val && createdAtNotPresent ( val ) && updatedAtNotPresent ( val ) ) ; typedModel ( '' , createSchema ( { } , { timestamps : true } ) ) . findOne ( ) . then ( val => val && createdAtPresent ( val ) && updatedAtPresent ( val ) ) ; typedModel ( '' , createSchema ( { } , { timestamps : { createdAt : true , updatedAt : true } } ) ) . findOne ( ) . then ( val => val && createdAtPresent ( val ) && updatedAtPresent ( val ) ) ; typedModel ( '' , createSchema ( { } , { timestamps : { createdAt : true } } ) ) . findOne ( ) . then ( val => val && createdAtPresent ( val ) && updatedAtNotPresent ( val ) ) ; typedModel ( '' , createSchema ( { } , { timestamps : { createdAt : true , updatedAt : false } } ) ) . findOne ( ) . then ( val => val && createdAtPresent ( val ) && updatedAtNotPresent ( val ) ) ; typedModel ( '' , createSchema ( { } , { timestamps : { createdAt : false } } ) ) . findOne ( ) . then ( val => val && createdAtNotPresent ( val ) && updatedAtNotPresent ( val ) ) ; typedModel ( '' , createSchema ( { } , { timestamps : { updatedAt : true } } ) ) . findOne ( ) . then ( val => val && createdAtNotPresent ( val ) && updatedAtPresent ( val ) ) ; typedModel ( '' , createSchema ( { } , { timestamps : { updatedAt : false } } ) ) . findOne ( ) . then ( val => val && createdAtNotPresent ( val ) && updatedAtNotPresent ( val ) ) ; typedModel ( '' , createSchema ( { } , { timestamps : { createdAt : 'customCreatedAt' as const } } ) ) . findOne ( ) . then ( val => val && createdAtCustomPresent ( val ) && updatedAtNotPresent ( val ) ) ; typedModel ( '' , createSchema ( { } , { timestamps : { updatedAt : 'customUpdatedAt' as const } } ) ) . findOne ( ) . then ( val => val && createdAtNotPresent ( val ) && updatedAtCustomPresent ( val ) ) ; typedModel ( '' , createSchema ( { } , { timestamps : { createdAt : 'customCreatedAt' as const , updatedAt : 'customUpdatedAt' as const , } , } ) ) . findOne ( ) . then ( val => val && createdAtCustomPresent ( val ) && updatedAtCustomPresent ( val ) ) ; } ; const VersionTests = ( ) => { type VersionObj = Record < VerKey , number > ; type VersionAtCustomObj = Record < 'customVer' , number > ; function VersionNotPresent ( _ ) { } function VersionPresent ( _ ) { } function VersionCustomPresent ( _ ) { } typedModel ( '' , createSchema ( { } ) ) . findOne ( ) . then ( val => val && VersionPresent ( val ) ) ; typedModel ( '' , createSchema ( { } , { versionKey : true } ) ) . findOne ( ) . then ( val => val && VersionPresent ( val ) ) ; typedModel ( '' , createSchema ( { } , { versionKey : false } ) ) . findOne ( ) . then ( val => val && VersionNotPresent ( val ) ) ; typedModel ( '' , createSchema ( { } , { versionKey : 'customVer' as const } ) ) . findOne ( ) . then ( val => val && VersionCustomPresent ( val ) ) ; } ; const IdTest = ( ) => { type IdObj = Record < Id , Types . ObjectId > ; function IdPresent ( _ ) { } typedModel ( '' , createSchema ( { } ) ) . findOne ( ) . then ( val => val && IdPresent ( val ) ) ; typedModel ( '' , createSchema ( { } , { id : true } ) ) . findOne ( ) . then ( val => val && IdPresent ( val ) ) ; typedModel ( '' , createSchema ( { } , { id : false } ) ) . findOne ( ) . then ( val => val && IdPresent ( val ) ) ; } ;