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