declare module 'mongoose' { type IfAny = 0 extends 1 & IFTYPE ? THENTYPE : ELSETYPE; type IsUnknown = unknown extends T ? true : false; type IsNotNever = [T] extends [never] ? false : true; type IsAny = 0 extends 1 & T ? true : false; type WithLevel1NestedPaths = IsItRecordAndNotAny extends true ? { [P in K | NestedPaths, K>]: P extends K // Handle top-level paths // First, drill into documents so we don't end up surfacing `$assertPopulated`, etc. ? Extract, Document> extends never // If not a document, then return the type. Otherwise, get the DocType. ? NonNullable : Extract, Document> extends Document ? DocType | Exclude, Document> : never // Handle nested paths : P extends `${infer Key}.${infer Rest}` ? Key extends keyof T ? NonNullable extends (infer U)[] ? NonNullable extends Types.DocumentArray ? Rest extends keyof NonNullable ? NonNullable[Rest] : never : Rest extends keyof NonNullable ? NonNullable[Rest] : never : Rest extends keyof NonNullable ? NonNullable[Rest] : never : never : never; } : T; type HasStringIndex = string extends Extract ? true : false; type SafeObjectKeys = HasStringIndex extends true ? never : Extract; type NestedPaths = K extends string ? T[K] extends TreatAsPrimitives ? never : Extract, Document> extends never ? NonNullable extends Array ? NonNullable extends Types.DocumentArray ? SafeObjectKeys> extends never ? never : `${K}.${SafeObjectKeys>}` : NonNullable extends Record ? SafeObjectKeys> extends never ? never : `${K}.${SafeObjectKeys>}` : never : NonNullable extends object ? SafeObjectKeys> extends never ? never : `${K}.${SafeObjectKeys>}` : never : Extract, Document> extends Document ? DocType extends object ? SafeObjectKeys> extends never ? never : `${K}.${SafeObjectKeys>}` : never : never : never; type WithoutUndefined = T extends undefined ? never : T; /** * @summary Removes keys from a type * @description It helps to exclude keys from a type * @param {T} T A generic type to be checked. * @param {K} K Keys from T that are to be excluded from the generic type * @returns T with the keys in K excluded */ type ExcludeKeys = { [P in keyof T as P extends K ? never : P]: T[P]; }; type Unpacked = T extends (infer U)[] ? U : T extends ReadonlyArray ? U : T; type DeepPartial = T extends TreatAsPrimitives ? T : T extends Array ? DeepPartial[] : T extends Record ? { [K in keyof T]?: DeepPartial } : T; type UnpackedIntersection = T extends null ? null : T extends (infer A)[] ? (A extends any ? (Omit & U) : never)[] : keyof U extends never ? T : T extends any ? (Omit & U) : never; type MergeType = A extends unknown ? Omit & B : never; /** * @summary Converts Unions to one record "object". * @description It makes intellisense dialog box easier to read as a single object instead of showing that in multiple object unions. * @param {T} T The type to be converted. */ type FlatRecord = { [K in keyof T]: T[K] }; /** Force an operation like `{ a: 0 } & { b: 1 }` to be computed so that it displays `{ a: 0; b: 1 }`. */ export type Show = { [k in keyof t]: t[k] } & unknown; /** * @summary Checks if a type is "Record" or "any". * @description It Helps to check if user has provided schema type "EnforcedDocType" * @param {T} T A generic type to be checked. * @returns true if {@link T} is Record OR false if {@link T} is of any type. */ type IsItRecordAndNotAny = IfEquals< T, any, false, T extends Record ? true : false >; /** * @summary Checks if two types are identical. * @param {T} T The first type to be compared with {@link U}. * @param {U} U The second type to be compared with {@link T}. * @param {Y} Y A type to be returned if {@link T} & {@link U} are identical. * @param {N} N A type to be returned if {@link T} & {@link U} are not identical. */ type IfEquals = (() => G extends T ? 1 : 0) extends () => G extends U ? 1 : 0 ? Y : N; /** * @summary Extracts 'this' parameter from a function, if it exists. Otherwise, returns fallback. * @param {T} T Function type to extract 'this' parameter from. * @param {F} F Fallback type to return if 'this' parameter does not exist. */ type ThisParameter = T extends { (this: infer This, ...args: never): void } ? This : F; /** * @summary Decorates all functions in an object with 'this' parameter. * @param {T} T Object with functions as values to add 'D' parameter to as 'this'. {@link D} * @param {D} D The type to be added as 'this' parameter to all functions in {@link T}. */ type AddThisParameter = { [K in keyof T]: T[K] extends (...args: infer A) => infer R ? IsUnknown> extends true ? (this: D, ...args: A) => R : T[K] : T[K]; }; /** * @summary Adds timestamp fields to a type * @description Adds createdAt and updatedAt fields of type Date, or custom timestamp fields if specified * @param {T} T The type to add timestamp fields to * @param {P} P Optional SchemaTimestampsConfig or boolean to customize timestamp field names * @returns T with timestamp fields added */ export type WithTimestamps< T, P extends SchemaTimestampsConfig | boolean = true > = ResolveTimestamps; }