deno.land / x / mongoose@6.7.5 / types / schematypes.d.ts

schematypes.d.ts
نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
declare module 'mongoose' {
/** The Mongoose Date [SchemaType](/docs/schematypes.html). */ type Date = Schema.Types.Date;
/** * The Mongoose Decimal128 [SchemaType](/docs/schematypes.html). Used for * declaring paths in your schema that should be * [128-bit decimal floating points](http://thecodebarbarian.com/a-nodejs-perspective-on-mongodb-34-decimal.html). * Do not use this to create a new Decimal128 instance, use `mongoose.Types.Decimal128` * instead. */ type Decimal128 = Schema.Types.Decimal128;
/** * The Mongoose Mixed [SchemaType](/docs/schematypes.html). Used for * declaring paths in your schema that Mongoose's change tracking, casting, * and validation should ignore. */ type Mixed = Schema.Types.Mixed;
/** * The Mongoose Number [SchemaType](/docs/schematypes.html). Used for * declaring paths in your schema that Mongoose should cast to numbers. */ type Number = Schema.Types.Number;
/** * The Mongoose ObjectId [SchemaType](/docs/schematypes.html). Used for * declaring paths in your schema that should be * [MongoDB ObjectIds](https://docs.mongodb.com/manual/reference/method/ObjectId/). * Do not use this to create a new ObjectId instance, use `mongoose.Types.ObjectId` * instead. */ type ObjectId = Schema.Types.ObjectId;
/** The various Mongoose SchemaTypes. */ const SchemaTypes: typeof Schema.Types;
type DefaultType<T> = T extends Schema.Types.Mixed ? any : Partial<ExtractMongooseArray<T>>;
class SchemaTypeOptions<T> { type?: T extends string ? StringSchemaDefinition : T extends number ? NumberSchemaDefinition : T extends boolean ? BooleanSchemaDefinition : T extends NativeDate ? DateSchemaDefinition : T extends Map<any, any> ? SchemaDefinition<typeof Map> : T extends Buffer ? SchemaDefinition<typeof Buffer> : T extends Types.ObjectId ? ObjectIdSchemaDefinition : T extends Types.ObjectId[] ? AnyArray<ObjectIdSchemaDefinition> | AnyArray<SchemaTypeOptions<ObjectId>> : T extends object[] ? (AnyArray<Schema<any, any, any>> | AnyArray<SchemaDefinition<Unpacked<T>>> | AnyArray<SchemaTypeOptions<Unpacked<T>>>) : T extends string[] ? AnyArray<StringSchemaDefinition> | AnyArray<SchemaTypeOptions<string>> : T extends number[] ? AnyArray<NumberSchemaDefinition> | AnyArray<SchemaTypeOptions<number>> : T extends boolean[] ? AnyArray<BooleanSchemaDefinition> | AnyArray<SchemaTypeOptions<boolean>> : T extends Function[] ? AnyArray<Function | string> | AnyArray<SchemaTypeOptions<Unpacked<T>>> : T | typeof SchemaType | Schema<any, any, any> | SchemaDefinition<T> | Function | AnyArray<Function>;
/** Defines a virtual with the given name that gets/sets this path. */ alias?: string | string[];
/** Function or object describing how to validate this schematype. See [validation docs](https://mongoosejs.com/docs/validation.html). */ validate?: SchemaValidator<T> | AnyArray<SchemaValidator<T>>;
/** Allows overriding casting logic for this individual path. If a string, the given string overwrites Mongoose's default cast error message. */ cast?: string;
/** * If true, attach a required validator to this path, which ensures this path * path cannot be set to a nullish value. If a function, Mongoose calls the * function and only checks for nullish values if the function returns a truthy value. */ required?: boolean | (() => boolean) | [boolean, string] | [() => boolean, string];
/** * The default value for this path. If a function, Mongoose executes the function * and uses the return value as the default. */ default?: DefaultType<T> | ((this: any, doc: any) => DefaultType<T>) | null;
/** * The model that `populate()` should use if populating this path. */ ref?: string | Model<any> | ((this: any, doc: any) => string | Model<any>);
/** * The path in the document that `populate()` should use to find the model * to use. */
refPath?: string | ((this: any, doc: any) => string);
/** * Whether to include or exclude this path by default when loading documents * using `find()`, `findOne()`, etc. */ select?: boolean | number;
/** * If [truthy](https://masteringjs.io/tutorials/fundamentals/truthy), Mongoose will * build an index on this path when the model is compiled. */ index?: boolean | IndexDirection | IndexOptions;
/** * If [truthy](https://masteringjs.io/tutorials/fundamentals/truthy), Mongoose * will build a unique index on this path when the * model is compiled. [The `unique` option is **not** a validator](/docs/validation.html#the-unique-option-is-not-a-validator). */ unique?: boolean | number;
/** * If [truthy](https://masteringjs.io/tutorials/fundamentals/truthy), Mongoose will * disallow changes to this path once the document is saved to the database for the first time. Read more * about [immutability in Mongoose here](http://thecodebarbarian.com/whats-new-in-mongoose-5-6-immutable-properties.html). */ immutable?: boolean | ((this: any, doc: any) => boolean);
/** * If [truthy](https://masteringjs.io/tutorials/fundamentals/truthy), Mongoose will * build a sparse index on this path. */ sparse?: boolean | number;
/** * If [truthy](https://masteringjs.io/tutorials/fundamentals/truthy), Mongoose * will build a text index on this path. */ text?: boolean | number | any;
/** * Define a transform function for this individual schema type. * Only called when calling `toJSON()` or `toObject()`. */ transform?: (this: any, val: T) => any;
/** defines a custom getter for this property using [`Object.defineProperty()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty). */ get?: (value: any, doc?: this) => T | undefined;
/** defines a custom setter for this property using [`Object.defineProperty()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty). */ set?: (value: any, priorVal?: T, doc?: this) => any;
/** array of allowed values for this path. Allowed for strings, numbers, and arrays of strings */ enum?: Array<string | number | null> | ReadonlyArray<string | number | null> | { values: Array<string | number | null> | ReadonlyArray<string | number | null>, message?: string } | { [path: string]: string | number | null };
/** The default [subtype](http://bsonspec.org/spec.html) associated with this buffer when it is stored in MongoDB. Only allowed for buffer paths */ subtype?: number;
/** The minimum value allowed for this path. Only allowed for numbers and dates. */ min?: number | NativeDate | [number, string] | [NativeDate, string] | readonly [number, string] | readonly [NativeDate, string];
/** The maximum value allowed for this path. Only allowed for numbers and dates. */ max?: number | NativeDate | [number, string] | [NativeDate, string] | readonly [number, string] | readonly [NativeDate, string];
/** Defines a TTL index on this path. Only allowed for dates. */ expires?: string | number;
/** If `true`, Mongoose will skip gathering indexes on subpaths. Only allowed for subdocuments and subdocument arrays. */ excludeIndexes?: boolean;
/** If set, overrides the child schema's `_id` option. Only allowed for subdocuments and subdocument arrays. */ _id?: boolean;
/** If set, specifies the type of this map's values. Mongoose will cast this map's values to the given type. */ of?: Function | SchemaDefinitionProperty<any>;
/** If true, uses Mongoose's default `_id` settings. Only allowed for ObjectIds */ auto?: boolean;
/** Attaches a validator that succeeds if the data string matches the given regular expression, and fails otherwise. */ match?: RegExp | [RegExp, string] | readonly [RegExp, string];
/** If truthy, Mongoose will add a custom setter that lowercases this string using JavaScript's built-in `String#toLowerCase()`. */ lowercase?: boolean;
/** If truthy, Mongoose will add a custom setter that removes leading and trailing whitespace using JavaScript's built-in `String#trim()`. */ trim?: boolean;
/** If truthy, Mongoose will add a custom setter that uppercases this string using JavaScript's built-in `String#toUpperCase()`. */ uppercase?: boolean;
/** If set, Mongoose will add a custom validator that ensures the given string's `length` is at least the given number. */ minlength?: number | [number, string] | readonly [number, string];
/** If set, Mongoose will add a custom validator that ensures the given string's `length` is at most the given number. */ maxlength?: number | [number, string] | readonly [number, string];
[other: string]: any; }
interface Validator { message?: string; type?: string; validator?: Function }
class SchemaType<T = any, DocType = any> { /** SchemaType constructor */ constructor(path: string, options?: AnyObject, instance?: string);
/** Get/set the function used to cast arbitrary values to this type. */ static cast(caster?: Function | boolean): Function;
static checkRequired(checkRequired?: (v: any) => boolean): (v: any) => boolean;
/** Sets a default option for this schema type. */ static set(option: string, value: any): void;
/** Attaches a getter for all instances of this schema type. */ static get(getter: (value: any) => any): void;
/** The class that Mongoose uses internally to instantiate this SchemaType's `options` property. */ OptionsConstructor: SchemaTypeOptions<T>;
/** Cast `val` to this schema type. Each class that inherits from schema type should implement this function. */ cast(val: any, doc: Document<any>, init: boolean, prev?: any, options?: any): any;
/** Sets a default value for this SchemaType. */ default(val: any): any;
/** Adds a getter to this schematype. */ get(fn: Function): this;
/** * Defines this path as immutable. Mongoose prevents you from changing * immutable paths unless the parent document has [`isNew: true`](/docs/api.html#document_Document-isNew). */ immutable(bool: boolean): this;
/** Declares the index options for this schematype. */ index(options: any): this;
/** String representation of what type this is, like 'ObjectID' or 'Number' */ instance: string;
/** True if this SchemaType has a required validator. False otherwise. */ isRequired?: boolean;
/** The options this SchemaType was instantiated with */ options: AnyObject;
/** The path to this SchemaType in a Schema. */ path: string;
/** * Set the model that this path refers to. This is the option that [populate](https://mongoosejs.com/docs/populate.html) * looks at to determine the foreign collection it should query. */ ref(ref: string | boolean | Model<any>): this;
/** * Adds a required validator to this SchemaType. The validator gets added * to the front of this SchemaType's validators array using unshift(). */ required(required: boolean, message?: string): this;
/** The schema this SchemaType instance is part of */ schema: Schema<any>;
/** Sets default select() behavior for this path. */ select(val: boolean): this;
/** Adds a setter to this schematype. */ set(fn: Function): this;
/** Declares a sparse index. */ sparse(bool: boolean): this;
/** Declares a full text index. */ text(bool: boolean): this;
/** Defines a custom function for transforming this path when converting a document to JSON. */ transform(fn: (value: any) => any): this;
/** Declares an unique index. */ unique(bool: boolean): this;
/** The validators that Mongoose should run to validate properties at this SchemaType's path. */ validators: Validator[];
/** Adds validator(s) for this document path. */ validate(obj: RegExp | ((this: DocType, value: any, validatorProperties?: Validator) => any), errorMsg?: string, type?: string): this; }
namespace Schema { namespace Types { class Array extends SchemaType implements AcceptsDiscriminator { /** This schema type's name, to defend against minifiers that mangle function names. */ static schemaName: 'Array';
static options: { castNonArrays: boolean; };
discriminator<T, U>(name: string | number, schema: Schema<T, U>, value?: string): U; discriminator<D>(name: string | number, schema: Schema, value?: string): Model<D>;
/** The schematype embedded in this array */ caster?: SchemaType;
/** * Adds an enum validator if this is an array of strings or numbers. Equivalent to * `SchemaString.prototype.enum()` or `SchemaNumber.prototype.enum()` */ enum(vals: string[] | number[]): this; }
class Boolean extends SchemaType { /** This schema type's name, to defend against minifiers that mangle function names. */ static schemaName: 'Boolean';
/** Configure which values get casted to `true`. */ static convertToTrue: Set<any>;
/** Configure which values get casted to `false`. */ static convertToFalse: Set<any>; }
class Buffer extends SchemaType { /** This schema type's name, to defend against minifiers that mangle function names. */ static schemaName: 'Buffer';
/** * Sets the default [subtype](https://studio3t.com/whats-new/best-practices-uuid-mongodb/) * for this buffer. You can find a [list of allowed subtypes here](http://api.mongodb.com/python/current/api/bson/binary.html). */ subtype(subtype: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 128): this; }
class Date extends SchemaType { /** This schema type's name, to defend against minifiers that mangle function names. */ static schemaName: 'Date';
/** Declares a TTL index (rounded to the nearest second) for _Date_ types only. */ expires(when: number | string): this;
/** Sets a maximum date validator. */ max(value: NativeDate, message: string): this;
/** Sets a minimum date validator. */ min(value: NativeDate, message: string): this; }
class Decimal128 extends SchemaType { /** This schema type's name, to defend against minifiers that mangle function names. */ static schemaName: 'Decimal128'; }
class DocumentArray extends SchemaType implements AcceptsDiscriminator { /** This schema type's name, to defend against minifiers that mangle function names. */ static schemaName: 'DocumentArray';
static options: { castNonArrays: boolean; };
discriminator<D>(name: string | number, schema: Schema, value?: string): Model<D>; discriminator<T, U>(name: string | number, schema: Schema<T, U>, value?: string): U;
/** The schema used for documents in this array */ schema: Schema;
/** The constructor used for subdocuments in this array */ caster?: typeof Types.Subdocument; }
class Map extends SchemaType { /** This schema type's name, to defend against minifiers that mangle function names. */ static schemaName: 'Map'; }
class Mixed extends SchemaType { /** This schema type's name, to defend against minifiers that mangle function names. */ static schemaName: 'Mixed'; }
class Number extends SchemaType { /** This schema type's name, to defend against minifiers that mangle function names. */ static schemaName: 'Number';
/** Sets a enum validator */ enum(vals: number[]): this;
/** Sets a maximum number validator. */ max(value: number, message: string): this;
/** Sets a minimum number validator. */ min(value: number, message: string): this; }
class ObjectId extends SchemaType { /** This schema type's name, to defend against minifiers that mangle function names. */ static schemaName: 'ObjectId';
/** Adds an auto-generated ObjectId default if turnOn is true. */ auto(turnOn: boolean): this; }
class Subdocument extends SchemaType implements AcceptsDiscriminator { /** This schema type's name, to defend against minifiers that mangle function names. */ static schemaName: string;
/** The document's schema */ schema: Schema;
discriminator<T, U>(name: string | number, schema: Schema<T, U>, value?: string): U; discriminator<D>(name: string | number, schema: Schema, value?: string): Model<D>; }
class String extends SchemaType { /** This schema type's name, to defend against minifiers that mangle function names. */ static schemaName: 'String';
/** Adds an enum validator */ enum(vals: string[] | any): this;
/** Adds a lowercase [setter](http://mongoosejs.com/docs/api.html#schematype_SchemaType-set). */ lowercase(shouldApply?: boolean): this;
/** Sets a regexp validator. */ match(value: RegExp, message: string): this;
/** Sets a maximum length validator. */ maxlength(value: number, message: string): this;
/** Sets a minimum length validator. */ minlength(value: number, message: string): this;
/** Adds a trim [setter](http://mongoosejs.com/docs/api.html#schematype_SchemaType-set). */ trim(shouldTrim?: boolean): this;
/** Adds an uppercase [setter](http://mongoosejs.com/docs/api.html#schematype_SchemaType-set). */ uppercase(shouldApply?: boolean): this; }
class UUID extends SchemaType { /** This schema type's name, to defend against minifiers that mangle function names. */ static schemaName: 'UUID'; } } }}
mongoose

Version Info

Tagged at
a year ago