import { IsSchemaTypeFromBuiltinClass, RequiredPaths, OptionalPaths, PathWithTypePropertyBaseType, PathEnumOrString } from './inferschematype'; declare module 'mongoose' { export type InferRawDocType< DocDefinition, TSchemaOptions extends Record = DefaultSchemaOptions > = ApplySchemaOptions<{ [ K in keyof (RequiredPaths & OptionalPaths) ]: ObtainRawDocumentPathType; }, TSchemaOptions>; /** * @summary Obtains schema Path type. * @description Obtains Path type by separating path type from other options and calling {@link ResolvePathType} * @param {PathValueType} PathValueType Document definition path type. * @param {TypeKey} TypeKey A generic refers to document definition. */ type ObtainRawDocumentPathType< PathValueType, TypeKey extends string = DefaultTypeKey > = ResolveRawPathType< PathValueType extends PathWithTypePropertyBaseType ? PathValueType[TypeKey] : PathValueType, PathValueType extends PathWithTypePropertyBaseType ? Omit : {}, TypeKey >; /** * Same as inferSchemaType, except: * * 1. Replace `Types.DocumentArray` and `Types.Array` with vanilla `Array` * 2. Replace `ObtainDocumentPathType` with `ObtainRawDocumentPathType` * 3. Replace `ResolvePathType` with `ResolveRawPathType` * * @summary Resolve path type by returning the corresponding type. * @param {PathValueType} PathValueType Document definition path type. * @param {Options} Options Document definition path options except path type. * @param {TypeKey} TypeKey A generic of literal string type."Refers to the property used for path type definition". * @returns Number, "Number" or "number" will be resolved to number type. */ type ResolveRawPathType = {}, TypeKey extends string = DefaultSchemaOptions['typeKey']> = PathValueType extends Schema ? InferSchemaType : PathValueType extends (infer Item)[] ? IfEquals> : Item extends Record ? Item[TypeKey] extends Function | String ? // If Item has a type key that's a string or a callable, it must be a scalar, // so we can directly obtain its path type. ObtainRawDocumentPathType[] : // If the type key isn't callable, then this is an array of objects, in which case // we need to call ObtainDocumentType to correctly infer its type. Array> : IsSchemaTypeFromBuiltinClass extends true ? ObtainRawDocumentPathType[] : IsItRecordAndNotAny extends true ? Item extends Record ? ObtainRawDocumentPathType[] : Array> : ObtainRawDocumentPathType[] >: PathValueType extends ReadonlyArray ? IfEquals> : Item extends Record ? Item[TypeKey] extends Function | String ? ObtainRawDocumentPathType[] : ObtainDocumentType[]: IsSchemaTypeFromBuiltinClass extends true ? ObtainRawDocumentPathType[] : IsItRecordAndNotAny extends true ? Item extends Record ? ObtainRawDocumentPathType[] : Array> : ObtainRawDocumentPathType[] >: PathValueType extends StringSchemaDefinition ? PathEnumOrString : IfEquals extends true ? PathEnumOrString : IfEquals extends true ? PathEnumOrString : PathValueType extends NumberSchemaDefinition ? Options['enum'] extends ReadonlyArray ? Options['enum'][number] : number : IfEquals extends true ? number : PathValueType extends DateSchemaDefinition ? Date : IfEquals extends true ? Date : PathValueType extends typeof Buffer | 'buffer' | 'Buffer' | typeof Schema.Types.Buffer ? Buffer : PathValueType extends BooleanSchemaDefinition ? boolean : IfEquals extends true ? boolean : PathValueType extends ObjectIdSchemaDefinition ? Types.ObjectId : IfEquals extends true ? Types.ObjectId : IfEquals extends true ? Types.ObjectId : PathValueType extends 'decimal128' | 'Decimal128' | typeof Schema.Types.Decimal128 ? Types.Decimal128 : IfEquals extends true ? Types.Decimal128 : IfEquals extends true ? Types.Decimal128 : IfEquals extends true ? bigint : IfEquals extends true ? bigint : PathValueType extends 'bigint' | 'BigInt' | typeof Schema.Types.BigInt | typeof BigInt ? bigint : PathValueType extends 'uuid' | 'UUID' | typeof Schema.Types.UUID ? Buffer : IfEquals extends true ? Buffer : PathValueType extends MapConstructor | 'Map' ? Map> : IfEquals extends true ? Map> : PathValueType extends ArrayConstructor ? any[] : PathValueType extends typeof Schema.Types.Mixed ? any: IfEquals extends true ? any: IfEquals extends true ? any: PathValueType extends typeof SchemaType ? PathValueType['prototype'] : PathValueType extends Record ? ObtainDocumentType : unknown; }