import { IsPathRequired, IsSchemaTypeFromBuiltinClass, RequiredPaths, OptionalPaths, PathEnumOrString } from './inferschematype'; import { UUID } from 'mongodb'; declare module 'mongoose' { export type InferHydratedDocTypeFromSchema> = ObtainSchemaGeneric; /** * Given a schema definition, returns the hydrated document type from the schema definition. */ export type InferHydratedDocType< DocDefinition, TSchemaOptions extends Record = DefaultSchemaOptions > = Require_id & OptionalPaths) ]: IsPathRequired extends true ? ObtainHydratedDocumentPathType : ObtainHydratedDocumentPathType | null; }, TSchemaOptions>>; /** * @summary Obtains schema Path type. * @description Obtains Path type by separating path type from other options and calling {@link ResolveHydratedPathType} * @param {PathValueType} PathValueType Document definition path type. * @param {TypeKey} TypeKey A generic refers to document definition. */ type ObtainHydratedDocumentPathType< PathValueType, TypeKey extends string = DefaultTypeKey > = ResolveHydratedPathType< TypeKey extends keyof PathValueType ? TypeKey extends keyof PathValueType[TypeKey] ? PathValueType : PathValueType[TypeKey] : PathValueType, TypeKey extends keyof PathValueType ? TypeKey extends keyof PathValueType[TypeKey] ? {} : Omit : {}, TypeKey, HydratedDocTypeHint, HydratedDiscriminatorEnumType >; /** * @summary Allows users to optionally choose their own type for a schema field for stronger typing. */ type HydratedDocTypeHint = T extends { __hydratedDocTypeHint: infer U } ? U : never; type ResolveDiscriminatorHydratedPathType = IsAny extends true ? never : TDiscriminators extends Record ? TDiscriminators[keyof TDiscriminators] extends Schema ? MergeType, InferHydratedDocTypeFromSchema> : never : never; type HydratedDiscriminatorEnumType = string extends keyof T ? never : number extends keyof T ? never : T extends { type: infer BaseType; discriminators: infer TDiscriminators } ? IsAny extends true ? never : BaseType extends Schema ? ResolveDiscriminatorHydratedPathType : never : never; /** * Same as inferSchemaType, except: * * 1. Replace `Types.DocumentArray` and `Types.Array` with vanilla `Array` * 2. Replace `ObtainDocumentPathType` with `ObtainHydratedDocumentPathType` * 3. Replace `ResolvePathType` with `ResolveHydratedPathType` * * @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 Type */ type ResolveHydratedPathType = {}, TypeKey extends string = DefaultSchemaOptions['typeKey'], TypeHint = never, TDiscriminatorEnumType = never> = IsNotNever extends true ? TypeHint : IsNotNever extends true ? TDiscriminatorEnumType : PathValueType extends Schema ? THydratedDocumentType : PathValueType extends AnyArray ? IfEquals ? IsItRecordAndNotAny extends true ? Types.DocumentArray & EmbeddedHydratedDocType> : Types.DocumentArray, Types.Subdocument['_id'], unknown, InferHydratedDocType> & InferHydratedDocType> : Item extends Record ? Item[TypeKey] extends Function | String ? Types.Array> : Types.DocumentArray< InferRawDocType, Types.Subdocument['_id'], unknown, InferHydratedDocType> & InferHydratedDocType >: IsSchemaTypeFromBuiltinClass extends true ? Types.Array> : IsItRecordAndNotAny extends true ? Item extends Record ? Types.Array> : Types.DocumentArray< InferRawDocType, Types.Subdocument['_id'], unknown, InferHydratedDocType> & InferHydratedDocType > : Types.Array> > : PathValueType extends StringSchemaDefinition ? PathEnumOrString : IfEquals extends true ? PathEnumOrString : PathValueType extends NumberSchemaDefinition ? Options['enum'] extends ReadonlyArray ? Options['enum'][number] : number : PathValueType extends DateSchemaDefinition ? NativeDate : PathValueType extends BufferSchemaDefinition ? Buffer : PathValueType extends BooleanSchemaDefinition ? boolean : PathValueType extends ObjectIdSchemaDefinition ? Types.ObjectId : PathValueType extends Decimal128SchemaDefinition ? Types.Decimal128 : PathValueType extends BigintSchemaDefinition ? bigint : PathValueType extends UuidSchemaDefinition ? UUID : PathValueType extends DoubleSchemaDefinition ? Types.Double : PathValueType extends typeof Schema.Types.Mixed ? any : PathValueType extends MapSchemaDefinition ? Map> : IfEquals extends true ? any : PathValueType extends typeof SchemaType ? PathValueType['prototype'] : PathValueType extends ArrayConstructor ? Types.Array : PathValueType extends Record ? InferHydratedDocType : unknown; }