UNPKG

27.4 kBTypeScriptView Raw
1/// <reference types="mongoose/types/aggregate" />
2/// <reference types="mongoose/types/callback" />
3/// <reference types="mongoose/types/collection" />
4/// <reference types="mongoose/types/connection" />
5/// <reference types="mongoose/types/cursor" />
6/// <reference types="mongoose/types/document" />
7/// <reference types="mongoose/types/error" />
8/// <reference types="mongoose/types/expressions" />
9/// <reference types="mongoose/types/helpers" />
10/// <reference types="mongoose/types/middlewares" />
11/// <reference types="mongoose/types/indexes" />
12/// <reference types="mongoose/types/models" />
13/// <reference types="mongoose/types/mongooseoptions" />
14/// <reference types="mongoose/types/pipelinestage" />
15/// <reference types="mongoose/types/populate" />
16/// <reference types="mongoose/types/query" />
17/// <reference types="mongoose/types/schemaoptions" />
18/// <reference types="mongoose/types/schematypes" />
19/// <reference types="mongoose/types/session" />
20/// <reference types="mongoose/types/types" />
21/// <reference types="mongoose/types/utility" />
22/// <reference types="mongoose/types/validation" />
23/// <reference types="mongoose/types/virtuals" />
24/// <reference types="mongoose/types/inferschematype" />
25/// <reference types="mongoose/types/inferrawdoctype" />
26import type * as mongoose from 'mongoose';
27import type { PropType, Severity } from './internal/constants';
28/**
29 * Get the Type of an instance of a Document with Class properties
30 * @example
31 * ```ts
32 * class ClassName {
33 * @prop()
34 * public someProperty: string;
35 * }
36 * const NameModel = getModelForClass(ClassName);
37 *
38 * const doc: DocumentType<ClassName> = await NameModel.create({});
39 * ```
40 */
41export type DocumentType<T, QueryHelpers = BeAnObject> = mongoose.Document<unknown, QueryHelpers, T> & mongoose.Default__v<mongoose.Require_id<T>> & IObjectWithTypegooseFunction;
42/**
43 * Get the Type of an instance of a SubDocument with Class properties
44 */
45export type SubDocumentType<T, QueryHelpers = BeAnObject> = DocumentType<T, QueryHelpers> & mongoose.Types.Subdocument;
46/**
47 * Get the Type of an instance of a SubDocument that exists within an array, with Class properties
48 */
49export type ArraySubDocumentType<T, QueryHelpers = BeAnObject> = DocumentType<T, QueryHelpers> & mongoose.Types.ArraySubdocument;
50/**
51 * Used Internally for ModelTypes
52 */
53export type ModelType<T, QueryHelpers = BeAnObject> = mongoose.Model<T, // raw doc type
54QueryHelpers, // query helpers
55IObjectWithTypegooseFunction, // instance methods
56BeAnyObject>;
57/**
58 * Any-param Constructor
59 */
60export type AnyParamConstructor<T> = new (...args: any) => T;
61/**
62 * The Type for Models used in typegoose, mostly returned by "getModelForClass" and "addModelToTypegoose"
63 * @example
64 * const Model: ReturnModelType<typeof YourClass, YourClassQueryHelper> = mongoose.model("YourClass", YourClassSchema);
65 */
66export type ReturnModelType<U extends AnyParamConstructor<any>, QueryHelpers = BeAnObject> = ModelType<InstanceType<U>, QueryHelpers> & U;
67/** Generic "Function" type, because typescript does not like using "Function" directly in strict mode */
68export type Func = (...args: any[]) => any;
69/**
70 * The Type of a function to generate a custom model name.
71 */
72export type CustomNameFunction = (options: IModelOptions) => string;
73/**
74 * Defer a reference with a function (or as other projects call it "Forward declaration")
75 * @param type This is just to comply with the common pattern of `type => ActualType`
76 */
77export type DeferredFunc<T = any> = (...args: unknown[]) => T;
78/**
79 * Dynamic Functions, since mongoose 4.13
80 * @param doc The Document current document
81 */
82export type DynamicStringFunc<T extends AnyParamConstructor<any>> = (doc: DocumentType<T>) => string;
83/** Type to keep the "discriminators" options consistent in types */
84export type NestedDiscriminatorsFunction = DeferredFunc<(AnyParamConstructor<any> | DiscriminatorObject)[]>;
85/** Type for enum "values" */
86export type EnumValues = Array<string | number | null> | ReadonlyArray<string | number | null> | {
87 [path: string | number]: string | number | null;
88};
89/** Type for the enum object with custom message*/
90export interface EnumObj {
91 values: EnumValues | DeferredFunc<EnumValues>;
92 message?: string;
93}
94/** Type for combines {@link EnumValues} and {@link @EnumObj} */
95export type EnumCombinedType = EnumValues | EnumObj;
96/**
97 * This Interface for most properties uses "mongoose.SchemaTypeOptions<any>['']", but for some special (or typegoose custom) options, it is not used
98 *
99 * Example: `index` is directly from mongoose, where as `type` is from typegoose
100 */
101export interface BasePropOptions {
102 /**
103 * include this value?
104 * @default true (Implicitly)
105 */
106 select?: mongoose.SchemaTypeOptions<any>['select'];
107 /**
108 * is this value required?
109 * @default false (Implicitly)
110 */
111 required?: mongoose.SchemaTypeOptions<any>['required'];
112 /** Only accept Values from the Enum(|Array) */
113 enum?: EnumCombinedType | DeferredFunc<EnumCombinedType> | {
114 values: DeferredFunc<EnumValues>;
115 message?: string;
116 };
117 /**
118 * Add "null" to the enum array
119 * Note: Custom Typegoose Option
120 */
121 addNullToEnum?: boolean;
122 /**
123 * Set Custom "warnMixed" Severity for a specific property
124 * Overwrites Severity set in "modelOptions" for a specific property
125 * Note: Custom Typegoose Option
126 */
127 allowMixed?: Severity;
128 /** Give the Property a default Value */
129 default?: mongoose.SchemaTypeOptions<any>['default'];
130 /** Give a Validator RegExp or Function */
131 validate?: mongoose.SchemaTypeOptions<any>['validate'];
132 /**
133 * Should this property have a "unique" index?
134 * @link https://docs.mongodb.com/manual/indexes/#unique-indexes
135 */
136 unique?: mongoose.SchemaTypeOptions<any>['unique'];
137 /**
138 * Should this property have an index?
139 * Note: don't use this if you want to do a compound index
140 * @link https://docs.mongodb.com/manual/indexes
141 */
142 index?: mongoose.SchemaTypeOptions<any>['index'];
143 /**
144 * Should this property have a "sparse" index?
145 * @link https://docs.mongodb.com/manual/indexes/#sparse-indexes
146 */
147 sparse?: mongoose.SchemaTypeOptions<any>['sparse'];
148 /**
149 * Should this property have an "expires" index?
150 * @link https://docs.mongodb.com/manual/tutorial/expire-data
151 */
152 expires?: mongoose.SchemaTypeOptions<any>['expires'];
153 /**
154 * Should this property have a "text" index?
155 * @link https://mongoosejs.com/docs/api/schematype.html#schematype_SchemaType-text
156 */
157 text?: mongoose.SchemaTypeOptions<any>['text'];
158 /** Should subdocuments get their own id?
159 * @default true (Implicitly)
160 */
161 _id?: mongoose.SchemaTypeOptions<any>['_id'];
162 /**
163 * Set a Setter (Non-Virtual) to pre-process your value
164 * (when using get/set both are required)
165 * Please note that the option `type` is required, if get/set saves a different value than what is defined
166 * @param value The Value that needs to get modified
167 * @returns The Value, but modified OR anything
168 * @example
169 * ```ts
170 * function setHello(val: string): string {
171 * return val.toLowerCase()
172 * }
173 * function getHello(val: string): string {
174 * return val.toUpperCase();
175 * }
176 * class Dummy {
177 * @prop({ set: setHello, get: getHello }) // many options can be used, like required
178 * public hello: string;
179 * }
180 * ```
181 */
182 set?: mongoose.SchemaTypeOptions<any>['set'];
183 /**
184 * Set a Getter (Non-Virtual) to Post-process your value
185 * (when using get/set both are required)
186 * Please note that the option `type` is required, if get/set saves a different value than what is defined
187 * @param value The Value that needs to get modified
188 * @returns The Value, but modified OR anything
189 * @example
190 * ```ts
191 * function setHello(val: string): string {
192 * return val.toLowerCase()
193 * }
194 * function getHello(val: string): string {
195 * return val.toUpperCase();
196 * }
197 * class Dummy {
198 * @prop({ set: setHello, get: getHello }) // many options can be used, like required
199 * public hello: string;
200 * }
201 * ```
202 */
203 get?: mongoose.SchemaTypeOptions<any>['get'];
204 /**
205 * This may be needed if get/set is used
206 * (this sets the type how it is saved to the DB)
207 */
208 type?: DeferredFunc<AnyParamConstructor<any>> | DeferredFunc<unknown> | unknown;
209 /**
210 * Make a property read-only
211 * @example
212 * ```ts
213 * class SomeClass {
214 * @prop({ immutable: true })
215 * public someprop: Readonly<string>;
216 * }
217 * ```
218 */
219 immutable?: mongoose.SchemaTypeOptions<any>['immutable'];
220 /**
221 * Give the Property an alias in the output
222 *
223 * Note: you should include the alias as a variable in the class, but not with a prop decorator
224 * @example
225 * ```ts
226 * class Dummy {
227 * @prop({ alias: "helloWorld" })
228 * public hello: string; // normal, with @prop
229 * public helloWorld: string; // is just for type Completion, will not be included in the DB
230 * }
231 * ```
232 */
233 alias?: mongoose.SchemaTypeOptions<any>['alias'];
234 /**
235 * This option has only an effect when the plugin `mongoose-autopopulate` is used
236 */
237 autopopulate?: boolean | Function | KeyStringAny;
238 /** Reference another Document (you should use Ref<T> as Prop type) */
239 ref?: DeferredFunc<string | AnyParamConstructor<any> | DynamicStringFunc<any>> | string | AnyParamConstructor<any>;
240 /** Take the Path and try to resolve it to a Model */
241 refPath?: string;
242 /**
243 * Set the Nested Discriminators
244 *
245 * Note: "_id: false" as a prop option doesn't work here
246 *
247 * Note: Custom Typegoose Option
248 */
249 discriminators?: NestedDiscriminatorsFunction;
250 /**
251 * Use option {@link BasePropOptions.type}
252 * @see https://typegoose.github.io/typegoose/docs/api/decorators/prop#map-options
253 * @see https://typegoose.github.io/typegoose/docs/api/decorators/prop#proptype
254 */
255 of?: never;
256 /**
257 * If true, uses Mongoose's default `_id` settings. Only allowed for ObjectIds
258 *
259 * Note: Copied from mongoose's "index.d.ts"#SchemaTypeOptions
260 */
261 auto?: mongoose.SchemaTypeOptions<any>['auto'];
262 /**
263 * The default [subtype](http://bsonspec.org/spec.html) associated with this buffer when it is stored in MongoDB. Only allowed for buffer paths
264 *
265 * Note: Copied from mongoose's "index.d.ts"#SchemaTypeOptions
266 */
267 subtype?: mongoose.SchemaTypeOptions<any>['subtype'];
268 /**
269 * If `true`, Mongoose will skip gathering indexes on subpaths. Only allowed for subdocuments and subdocument arrays.
270 *
271 * Note: Copied from mongoose's "index.d.ts"#SchemaTypeOptions
272 */
273 excludeIndexes?: mongoose.SchemaTypeOptions<any>['excludeIndexes'];
274 /**
275 * Define a transform function for this individual schema type.
276 * Only called when calling `toJSON()` or `toObject()`.
277 *
278 * Note: Copied from mongoose's "index.d.ts"#SchemaTypeOptions
279 */
280 transform?: mongoose.SchemaTypeOptions<any>['transform'];
281 [extra: string]: any;
282}
283export interface InnerOuterOptions {
284 /**
285 * Use this to define inner-options
286 * Use this if the auto-mapping is not correct or for plugin options
287 *
288 * Please open a new issue if some option is mismatched or not existing / mapped
289 */
290 innerOptions?: KeyStringAny;
291 /**
292 * Use this to define outer-options
293 * Use this if the auto-mapping is not correct or for plugin options
294 *
295 * Please open a new issue if some option is mismatched or not existing / mapped
296 */
297 outerOptions?: KeyStringAny;
298}
299/**
300 * Internal type for `utils.mapOptions`
301 * @internal
302 */
303export interface MappedInnerOuterOptions {
304 /**
305 * Mapped options for the inner of the Type
306 */
307 inner: NonNullable<KeyStringAny>;
308 /**
309 * Mapped options for the outer of the type
310 */
311 outer: NonNullable<KeyStringAny>;
312}
313/** Options for Array's */
314export interface ArrayPropOptions extends BasePropOptions, InnerOuterOptions {
315 /**
316 * How many dimensions this Array should have
317 * (needs to be higher than 0)
318 *
319 * Note: Custom Typegoose Option
320 * @default 1
321 */
322 dim?: number;
323 /**
324 * Set if Non-Array values will be cast to an array
325 *
326 * NOTE: This option currently only really affects "DocumentArray" and not normal arrays, https://github.com/Automattic/mongoose/issues/10398
327 * @see https://mongoosejs.com/docs/api/schemaarray.html#schemaarray_SchemaArray.options
328 * @example
329 * ```ts
330 * new Model({ array: "string" });
331 * // will be cast to equal
332 * new Model({ array: ["string"] });
333 * ```
334 * @default true
335 */
336 castNonArrays?: boolean;
337}
338/** Options For Map's */
339export interface MapPropOptions extends BasePropOptions, InnerOuterOptions {
340}
341export interface ValidateNumberOptions {
342 /** Only allow numbers that are higher than this */
343 min?: mongoose.SchemaTypeOptions<any>['min'];
344 /** Only allow numbers lower than this */
345 max?: mongoose.SchemaTypeOptions<any>['max'];
346 /** Only allow Values from the enum */
347 enum?: number[];
348}
349export interface ValidateStringOptions {
350 /** Only allow values that match this RegExp */
351 match?: mongoose.SchemaTypeOptions<any>['match'];
352 /** Only allow Values from the enum */
353 enum?: string[];
354 /** Only allow values that have at least this length */
355 minlength?: mongoose.SchemaTypeOptions<any>['minlength'];
356 /** Only allow values that have at max this length */
357 maxlength?: mongoose.SchemaTypeOptions<any>['maxlength'];
358}
359export interface TransformStringOptions {
360 /** Should it be lowercased before save? */
361 lowercase?: mongoose.SchemaTypeOptions<any>['lowercase'];
362 /** Should it be uppercased before save? */
363 uppercase?: mongoose.SchemaTypeOptions<any>['uppercase'];
364 /** Should it be trimmed before save? */
365 trim?: mongoose.SchemaTypeOptions<any>['trim'];
366}
367export interface VirtualOptions {
368 /** Reference another Document (Ref<T> should be used as property type) */
369 ref: NonNullable<BasePropOptions['ref']>;
370 /** Which property(on the current-Class) to match `foreignField` against */
371 localField: mongoose.VirtualTypeOptions['localField'];
372 /** Which property(on the ref-Class) to match `localField` against */
373 foreignField: mongoose.VirtualTypeOptions['foreignField'];
374 /** Return as One Document(true) or as Array(false) */
375 justOne?: mongoose.VirtualTypeOptions['justOne'];
376 /** Return the number of Documents found instead of the actual Documents */
377 count?: mongoose.VirtualTypeOptions['count'];
378 /** Extra Query Options */
379 options?: mongoose.VirtualTypeOptions['options'];
380 /** Match Options */
381 match?: mongoose.VirtualTypeOptions['match'];
382 /**
383 * If you set this to `true`, Mongoose will call any custom getters you defined on this virtual.
384 *
385 * Note: Copied from mongoose's "index.d.ts"#VirtualTypeOptions
386 */
387 getters?: mongoose.VirtualTypeOptions['getters'];
388 /**
389 * Add a default `limit` to the `populate()` query.
390 *
391 * Note: Copied from mongoose's "index.d.ts"#VirtualTypeOptions
392 */
393 limit?: mongoose.VirtualTypeOptions['limit'];
394 /**
395 * Add a default `skip` to the `populate()` query.
396 *
397 * Note: Copied from mongoose's "index.d.ts"#VirtualTypeOptions
398 */
399 skip?: mongoose.VirtualTypeOptions['skip'];
400 /**
401 * For legacy reasons, `limit` with `populate()` may give incorrect results because it only
402 * executes a single query for every document being populated. If you set `perDocumentLimit`,
403 * Mongoose will ensure correct `limit` per document by executing a separate query for each
404 * document to `populate()`. For example, `.find().populate({ path: 'test', perDocumentLimit: 2 })`
405 * will execute 2 additional queries if `.find()` returns 2 documents.
406 *
407 * Note: Copied from mongoose's "index.d.ts"#VirtualTypeOptions
408 */
409 perDocumentLimit?: mongoose.VirtualTypeOptions['perDocumentLimit'];
410 [extra: string]: any;
411}
412export type PropOptionsForNumber = BasePropOptions & ValidateNumberOptions;
413export type PropOptionsForString = BasePropOptions & TransformStringOptions & ValidateStringOptions;
414export type RefType = mongoose.RefType;
415/**
416 * Reference another Model
417 */
418export type Ref<PopulatedType, RawId extends mongoose.RefType = PopulatedType extends {
419 _id?: mongoose.RefType;
420} ? NonNullable<PopulatedType['_id']> : mongoose.Types.ObjectId> = mongoose.PopulatedDoc<DocumentType<PopulatedType>, RawId>;
421export interface DiscriminatorObject {
422 /** The Class to use */
423 type: AnyParamConstructor<any>;
424 /**
425 * The Name to differentiate between other classes
426 * Mongoose JSDOC: [value] the string stored in the `discriminatorKey` property. If not specified, Mongoose uses the `name` parameter.
427 * @default {string} The output of "getName"
428 */
429 value?: string;
430}
431export interface IModelOptions {
432 /** An Existing Mongoose Connection */
433 existingMongoose?: mongoose.Mongoose;
434 /** Supports all Mongoose's Schema Options */
435 schemaOptions?: mongoose.SchemaOptions;
436 /** An Existing Connection */
437 existingConnection?: mongoose.Connection;
438 /** Typegoose Custom Options */
439 options?: ICustomOptions;
440}
441/** Interface for just all naming options */
442export interface INamingOptions {
443 /** Same as in {@link ICustomOptions} */
444 customName?: ICustomOptions['customName'];
445 /** Same as in {@link ICustomOptions} */
446 automaticName?: ICustomOptions['automaticName'];
447 /** Same as in {@link mongoose.SchemaOptions} */
448 schemaCollection?: mongoose.SchemaOptions['collection'];
449}
450/** Typegoose options, mostly for "modelOptions({ options: ICustomOptions })" */
451export interface ICustomOptions {
452 /**
453 * Set the modelName of the class.
454 * If it is a function, the function will be executed. The function will override
455 * "automaticName". If "automaticName" is true and "customName" is a string, it
456 * sets a *suffix* instead of the whole name.
457 * @default schemaOptions.collection
458 */
459 customName?: string | CustomNameFunction;
460 /**
461 * Enable Automatic Name generation of a model
462 * Example:
463 * class with name of "SomeClass"
464 * and option "collection" of "SC"
465 *
466 * will generate the name of "SomeClass_SC"
467 * @default false
468 */
469 automaticName?: boolean;
470 /** Allow "mongoose.Schema.Types.Mixed"? */
471 allowMixed?: Severity;
472 /**
473 * Enable Overwriting of the plugins on the "to-be" discriminator schema with the base schema's
474 * Note: this does not actually "merge plugins", it will overwrite the "to-be" discriminator's plugins with the base schema's
475 * If {@link ICustomOptions.enableMergePlugins} and {@link ICustomOptions.enableMergeHooks} are both "false", then the global plugins will be automatically applied by typegoose, see https://github.com/Automattic/mongoose/issues/12696
476 * @default false
477 */
478 enableMergePlugins?: boolean;
479 /**
480 * Enable Merging of Hooks
481 * Note: only hooks that can be matched against each-other can be de-duplicated
482 * If {@link ICustomOptions.enableMergePlugins} and {@link ICustomOptions.enableMergeHooks} are both "false", then the global plugins will be automatically applied by typegoose, see https://github.com/Automattic/mongoose/issues/12696
483 * @default false
484 */
485 enableMergeHooks?: boolean;
486 /**
487 * Disable all lower indexes than this class (works like `sch.clone().clearIndexes()`)
488 *
489 * This option DOES NOT get inherited
490 * @default false
491 */
492 disableLowerIndexes?: boolean;
493 /**
494 * Set the Nested Discriminators on the *base* of the Discriminators
495 *
496 * This option can be used over the prop-option to not have to re-define discriminators if used in multiple classes
497 */
498 discriminators?: NestedDiscriminatorsFunction;
499 /**
500 * Disable Caching for this Class if defined via `@modelOptions`, or disable caching for the `getModelForClass` / `buildSchema` / `getDiscriminatorModelForClass`
501 * Does NOT overwrite global disabled caching
502 * "undefined" and "false" have the same meaning
503 * @default false
504 */
505 disableCaching?: boolean;
506}
507/** Extra options for "_buildSchema" in "schema.ts" */
508export interface IBuildSchemaOptions {
509 /**
510 * Add indexes from this class?
511 * will be "false" when "ICustomOptions.disableLowerIndexes" is "true" for some upper class
512 * @default true
513 */
514 buildIndexes?: boolean;
515 /**
516 * Add search indexes from this class?
517 * @default true
518 */
519 buildSearchIndexes?: boolean;
520}
521/** Type for the Values stored in the Reflection for Properties */
522export interface DecoratedPropertyMetadata {
523 /** Prop Options */
524 options: KeyStringAny;
525 /** The Target Reflection target for getting metadata from keys */
526 target: AnyParamConstructor<any>;
527 /** Property name */
528 key: string | symbol;
529 /** What is it for a prop type? */
530 propType?: PropType;
531}
532export type DecoratedPropertyMetadataMap = Map<string | symbol, DecoratedPropertyMetadata>;
533/**
534 * Alias of "mongoose.IndexOptions" for convenience
535 */
536export type IndexOptions = mongoose.IndexOptions;
537/**
538 * Type for the Values stored in the Reflection for Indexes
539 * @example
540 * ```ts
541 * const indices: IIndexArray[] = Reflect.getMetadata(DecoratorKeys.Index, target) || [];
542 * ```
543 */
544export interface IIndexArray {
545 fields: KeyStringAny;
546 options?: IndexOptions;
547}
548/**
549 * Type for the Values stored in the Reflection for Search Indexes
550 * @example
551 * ```ts
552 * const searchIndices: SearchIndexDescription[] = Reflect.getMetadata(DecoratorKeys.SearchIndex, target) || [];
553 * ```
554 */
555export type SearchIndexDescription = mongoose.SearchIndexDescription;
556/**
557 * Type for the Values stored in the Reflection for Plugins
558 * @example
559 * ```ts
560 * const plugins: IPluginsArray[] = Array.from(Reflect.getMetadata(DecoratorKeys.Plugins, target) ?? []);
561 * ```
562 */
563export interface IPluginsArray {
564 /** The Plugin Function to add */
565 mongoosePlugin: Func;
566 /** The Plugin's options, which could be anything because mongoose does not enforce it to be a object */
567 options: any | undefined;
568}
569/**
570 * Type for the Values stored in the Reflection for Virtual Populates
571 * @example
572 * ```ts
573 * const virtuals: VirtualPopulateMap = new Map(Reflect.getMetadata(DecoratorKeys.VirtualPopulate, target.constructor) ?? []);
574 * ```
575 */
576export type VirtualPopulateMap = Map<string, VirtualOptions & Record<string, unknown>>;
577/**
578 * Gets the signature (parameters with their types, and the return type) of a function type.
579 *
580 * @description Should be used when defining an interface for a class that uses query methods.
581 *
582 * @example
583 * ```ts
584 * function sendMessage(recipient: string, sender: string, priority: number, retryIfFails: boolean) {
585 * // some logic...
586 * return true;
587 * }
588 *
589 * // Both of the following types will be identical.
590 * type SendMessageType = AsQueryMethod<typeof sendMessage>;
591 * type SendMessageManualType = (recipient: string, sender: string, priority: number, retryIfFails: boolean) => boolean;
592 * ```
593 */
594export type AsQueryMethod<T extends (...args: any) => any> = (...args: Parameters<T>) => ReturnType<T>;
595/**
596 * Helper type to easily set the `this` type in a QueryHelper function
597 *
598 * @example
599 * function findById(this: QueryHelperThis<typeof YourClass, YourClassQueryHelpers>, id: string) {
600 * return this.findOne({ _id: id });
601 * }
602 */
603export type QueryHelperThis<T extends AnyParamConstructor<any>, QueryHelpers, S = DocumentType<InstanceType<T>, QueryHelpers>> = mongoose.QueryWithHelpers<S | null, S, QueryHelpers, InstanceType<T>>;
604/**
605 * Type for the Values stored in the Reflection for Query Methods
606 * @example
607 * ```ts
608 * const queryMethods: QueryMethodMap = new Map(Reflect.getMetadata(DecoratorKeys.QueryMethod, target) ?? []);
609 * ```
610 */
611export type QueryMethodMap = Map<string, Func>;
612/**
613 * Type for the Values stored in the Reflection for Nested Discriminators
614 * @example
615 * ```ts
616 * const disMap: NestedDiscriminatorsMap = new Map(Reflect.getMetadata(DecoratorKeys.NestedDiscriminators, target) ?? []);
617 * ```
618 */
619export type NestedDiscriminatorsMap = Map<string, DiscriminatorObject[]>;
620/** A Helper type to combine both mongoose Hook Option types */
621export type HookOptionsEither = mongoose.SchemaPreOptions | mongoose.SchemaPostOptions;
622/**
623 * Type for the Values stored in the Reflection for Hooks
624 * @example
625 * ```ts
626 * const postHooks: IHooksArray[] = Array.from(Reflect.getMetadata(DecoratorKeys.HooksPost, target) ?? []);
627 * ```
628 */
629export interface IHooksArray {
630 /** The Function to add as a hooks */
631 func: Func;
632 /** The Method to where this hook gets triggered */
633 methods: (string | RegExp)[];
634 /**
635 * Options for Hooks
636 * @see https://mongoosejs.com/docs/middleware.html#naming
637 */
638 options?: HookOptionsEither;
639}
640export interface IGlobalOptions {
641 /** Typegoose Options */
642 options?: ICustomOptions;
643 /** Schema Options that should get applied to all models */
644 schemaOptions?: mongoose.SchemaOptions;
645 /**
646 * Global Options for general Typegoose
647 */
648 globalOptions?: ITypegooseOptions;
649}
650export interface ITypegooseOptions {
651 /**
652 * Option to disable caching globally
653 * completely disables the "constructors" and "models" maps
654 * "false" and "undefined" have the same result of enabling caching
655 * @default false
656 */
657 disableGlobalCaching?: boolean;
658}
659/** Interface describing a Object that has a "typegooseName" Function */
660export interface IObjectWithTypegooseFunction {
661 typegooseName(): string;
662}
663/** For the types that error that seemingly don't have a prototype */
664export interface IPrototype {
665 prototype?: any;
666}
667/** A Helper Interface for defining a "key" index of "string" and "value" of "any" */
668export type KeyStringAny = Record<string, any>;
669/**
670 * The Return Type of "utils.getType"
671 */
672export interface GetTypeReturn {
673 type: unknown;
674 dim: number;
675}
676/**
677 * This type is for lint error "ban-types" where "{}" would be used
678 * This type is separate from "{@link KeyStringAny}" because it has a different meaning
679 */
680export type BeAnObject = Record<string, any>;
681/**
682 * This type is for mongoose-specific things where {@link BeAnObject} does not work
683 * see https://github.com/Automattic/mongoose/issues/13094
684 */
685export type BeAnyObject = {};
686/** Options used for "processProp" */
687export interface ProcessPropOptions extends DecoratedPropertyMetadata {
688 /** The target Class's static version */
689 cl: AnyParamConstructor<any>;
690}
691/**
692 * Get all keys from "T" that are a function
693 * does NOT filter out getters / setters
694 */
695export type GetFunctionKeys<T extends object> = {
696 [K in keyof T]: T[K] extends (...args: any) => any ? K : never;
697}[keyof T];
698/**
699 * Remove all properties from "T" that are a function
700 * does NOT filter out getters / setters
701 */
702export type FilterOutFunctionKeys<T extends object> = Omit<T, GetFunctionKeys<T>>;