@depup/mongoose 9.1.3-depup.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +22 -0
- package/README.md +397 -0
- package/SECURITY.md +1 -0
- package/eslint.config.mjs +198 -0
- package/index.js +64 -0
- package/lib/aggregate.js +1189 -0
- package/lib/cast/bigint.js +46 -0
- package/lib/cast/boolean.js +32 -0
- package/lib/cast/date.js +41 -0
- package/lib/cast/decimal128.js +39 -0
- package/lib/cast/double.js +50 -0
- package/lib/cast/int32.js +36 -0
- package/lib/cast/number.js +42 -0
- package/lib/cast/objectid.js +29 -0
- package/lib/cast/string.js +37 -0
- package/lib/cast/uuid.js +35 -0
- package/lib/cast.js +436 -0
- package/lib/collection.js +321 -0
- package/lib/connection.js +1855 -0
- package/lib/connectionState.js +26 -0
- package/lib/constants.js +73 -0
- package/lib/cursor/aggregationCursor.js +466 -0
- package/lib/cursor/changeStream.js +198 -0
- package/lib/cursor/queryCursor.js +622 -0
- package/lib/document.js +5521 -0
- package/lib/driver.js +15 -0
- package/lib/drivers/SPEC.md +4 -0
- package/lib/drivers/node-mongodb-native/bulkWriteResult.js +5 -0
- package/lib/drivers/node-mongodb-native/collection.js +393 -0
- package/lib/drivers/node-mongodb-native/connection.js +506 -0
- package/lib/drivers/node-mongodb-native/index.js +10 -0
- package/lib/error/browserMissingSchema.js +29 -0
- package/lib/error/bulkSaveIncompleteError.js +44 -0
- package/lib/error/bulkWriteError.js +41 -0
- package/lib/error/cast.js +158 -0
- package/lib/error/createCollectionsError.js +26 -0
- package/lib/error/divergentArray.js +40 -0
- package/lib/error/eachAsyncMultiError.js +41 -0
- package/lib/error/index.js +237 -0
- package/lib/error/invalidSchemaOption.js +32 -0
- package/lib/error/messages.js +47 -0
- package/lib/error/missingSchema.js +33 -0
- package/lib/error/mongooseError.js +13 -0
- package/lib/error/notFound.js +47 -0
- package/lib/error/objectExpected.js +31 -0
- package/lib/error/objectParameter.js +31 -0
- package/lib/error/overwriteModel.js +31 -0
- package/lib/error/parallelSave.js +33 -0
- package/lib/error/parallelValidate.js +33 -0
- package/lib/error/serverSelection.js +62 -0
- package/lib/error/setOptionError.js +103 -0
- package/lib/error/strict.js +35 -0
- package/lib/error/strictPopulate.js +31 -0
- package/lib/error/syncIndexes.js +30 -0
- package/lib/error/validation.js +97 -0
- package/lib/error/validator.js +100 -0
- package/lib/error/version.js +38 -0
- package/lib/helpers/aggregate/prepareDiscriminatorPipeline.js +39 -0
- package/lib/helpers/aggregate/stringifyFunctionOperators.js +50 -0
- package/lib/helpers/arrayDepth.js +33 -0
- package/lib/helpers/clone.js +204 -0
- package/lib/helpers/common.js +127 -0
- package/lib/helpers/createJSONSchemaTypeDefinition.js +24 -0
- package/lib/helpers/cursor/eachAsync.js +225 -0
- package/lib/helpers/discriminator/applyEmbeddedDiscriminators.js +36 -0
- package/lib/helpers/discriminator/areDiscriminatorValuesEqual.js +16 -0
- package/lib/helpers/discriminator/checkEmbeddedDiscriminatorKeyProjection.js +12 -0
- package/lib/helpers/discriminator/getConstructor.js +29 -0
- package/lib/helpers/discriminator/getDiscriminatorByValue.js +28 -0
- package/lib/helpers/discriminator/getSchemaDiscriminatorByValue.js +27 -0
- package/lib/helpers/discriminator/mergeDiscriminatorSchema.js +91 -0
- package/lib/helpers/document/applyDefaults.js +132 -0
- package/lib/helpers/document/applyTimestamps.js +106 -0
- package/lib/helpers/document/applyVirtuals.js +147 -0
- package/lib/helpers/document/cleanModifiedSubpaths.js +45 -0
- package/lib/helpers/document/compile.js +238 -0
- package/lib/helpers/document/getDeepestSubdocumentForPath.js +38 -0
- package/lib/helpers/document/getEmbeddedDiscriminatorPath.js +53 -0
- package/lib/helpers/document/handleSpreadDoc.js +35 -0
- package/lib/helpers/each.js +25 -0
- package/lib/helpers/error/combinePathErrors.js +22 -0
- package/lib/helpers/firstKey.js +8 -0
- package/lib/helpers/get.js +65 -0
- package/lib/helpers/getConstructorName.js +16 -0
- package/lib/helpers/getDefaultBulkwriteResult.js +18 -0
- package/lib/helpers/getFunctionName.js +10 -0
- package/lib/helpers/immediate.js +16 -0
- package/lib/helpers/indexes/applySchemaCollation.js +13 -0
- package/lib/helpers/indexes/decorateDiscriminatorIndexOptions.js +14 -0
- package/lib/helpers/indexes/getRelatedIndexes.js +63 -0
- package/lib/helpers/indexes/isDefaultIdIndex.js +18 -0
- package/lib/helpers/indexes/isIndexEqual.js +95 -0
- package/lib/helpers/indexes/isIndexSpecEqual.js +32 -0
- package/lib/helpers/indexes/isTextIndex.js +16 -0
- package/lib/helpers/indexes/isTimeseriesIndex.js +16 -0
- package/lib/helpers/isAsyncFunction.js +9 -0
- package/lib/helpers/isBsonType.js +15 -0
- package/lib/helpers/isMongooseObject.js +22 -0
- package/lib/helpers/isObject.js +16 -0
- package/lib/helpers/isPOJO.js +12 -0
- package/lib/helpers/isPromise.js +6 -0
- package/lib/helpers/isSimpleValidator.js +22 -0
- package/lib/helpers/minimize.js +41 -0
- package/lib/helpers/model/applyDefaultsToPOJO.js +52 -0
- package/lib/helpers/model/applyHooks.js +140 -0
- package/lib/helpers/model/applyMethods.js +70 -0
- package/lib/helpers/model/applyStaticHooks.js +33 -0
- package/lib/helpers/model/applyStatics.js +13 -0
- package/lib/helpers/model/castBulkWrite.js +316 -0
- package/lib/helpers/model/decorateBulkWriteResult.js +8 -0
- package/lib/helpers/model/discriminator.js +265 -0
- package/lib/helpers/model/pushNestedArrayPaths.js +15 -0
- package/lib/helpers/omitUndefined.js +20 -0
- package/lib/helpers/once.js +12 -0
- package/lib/helpers/parallelLimit.js +37 -0
- package/lib/helpers/path/parentPaths.js +18 -0
- package/lib/helpers/path/setDottedPath.js +33 -0
- package/lib/helpers/pluralize.js +95 -0
- package/lib/helpers/populate/assignRawDocsToIdStructure.js +129 -0
- package/lib/helpers/populate/assignVals.js +360 -0
- package/lib/helpers/populate/createPopulateQueryFilter.js +97 -0
- package/lib/helpers/populate/getModelsMapForPopulate.js +776 -0
- package/lib/helpers/populate/getSchemaTypes.js +228 -0
- package/lib/helpers/populate/getVirtual.js +103 -0
- package/lib/helpers/populate/leanPopulateMap.js +7 -0
- package/lib/helpers/populate/lookupLocalFields.js +40 -0
- package/lib/helpers/populate/markArraySubdocsPopulated.js +49 -0
- package/lib/helpers/populate/modelNamesFromRefPath.js +66 -0
- package/lib/helpers/populate/removeDeselectedForeignField.js +31 -0
- package/lib/helpers/populate/setPopulatedVirtualValue.js +33 -0
- package/lib/helpers/populate/skipPopulateValue.js +10 -0
- package/lib/helpers/populate/validateRef.js +19 -0
- package/lib/helpers/printJestWarning.js +21 -0
- package/lib/helpers/processConnectionOptions.js +65 -0
- package/lib/helpers/projection/applyProjection.js +83 -0
- package/lib/helpers/projection/hasIncludedChildren.js +41 -0
- package/lib/helpers/projection/isDefiningProjection.js +18 -0
- package/lib/helpers/projection/isExclusive.js +37 -0
- package/lib/helpers/projection/isInclusive.js +39 -0
- package/lib/helpers/projection/isNestedProjection.js +8 -0
- package/lib/helpers/projection/isPathExcluded.js +40 -0
- package/lib/helpers/projection/isPathSelectedInclusive.js +28 -0
- package/lib/helpers/projection/isSubpath.js +14 -0
- package/lib/helpers/projection/parseProjection.js +33 -0
- package/lib/helpers/query/applyGlobalOption.js +29 -0
- package/lib/helpers/query/cast$expr.js +287 -0
- package/lib/helpers/query/castFilterPath.js +54 -0
- package/lib/helpers/query/castUpdate.js +643 -0
- package/lib/helpers/query/getEmbeddedDiscriminatorPath.js +103 -0
- package/lib/helpers/query/handleImmutable.js +44 -0
- package/lib/helpers/query/handleReadPreferenceAliases.js +23 -0
- package/lib/helpers/query/hasDollarKeys.js +23 -0
- package/lib/helpers/query/isOperator.js +14 -0
- package/lib/helpers/query/sanitizeFilter.js +38 -0
- package/lib/helpers/query/sanitizeProjection.js +14 -0
- package/lib/helpers/query/selectPopulatedFields.js +62 -0
- package/lib/helpers/query/trusted.js +13 -0
- package/lib/helpers/query/validOps.js +3 -0
- package/lib/helpers/schema/addAutoId.js +7 -0
- package/lib/helpers/schema/applyBuiltinPlugins.js +12 -0
- package/lib/helpers/schema/applyPlugins.js +55 -0
- package/lib/helpers/schema/applyReadConcern.js +20 -0
- package/lib/helpers/schema/applyWriteConcern.js +39 -0
- package/lib/helpers/schema/cleanPositionalOperators.js +12 -0
- package/lib/helpers/schema/getIndexes.js +171 -0
- package/lib/helpers/schema/getKeysInSchemaOrder.js +28 -0
- package/lib/helpers/schema/getPath.js +43 -0
- package/lib/helpers/schema/getSubdocumentStrictValue.js +32 -0
- package/lib/helpers/schema/handleIdOption.js +20 -0
- package/lib/helpers/schema/handleTimestampOption.js +24 -0
- package/lib/helpers/schema/idGetter.js +34 -0
- package/lib/helpers/schema/merge.js +36 -0
- package/lib/helpers/schematype/handleImmutable.js +50 -0
- package/lib/helpers/setDefaultsOnInsert.js +158 -0
- package/lib/helpers/specialProperties.js +3 -0
- package/lib/helpers/symbols.js +20 -0
- package/lib/helpers/timers.js +3 -0
- package/lib/helpers/timestamps/setDocumentTimestamps.js +26 -0
- package/lib/helpers/timestamps/setupTimestamps.js +116 -0
- package/lib/helpers/topology/allServersUnknown.js +12 -0
- package/lib/helpers/topology/isAtlas.js +31 -0
- package/lib/helpers/topology/isSSLError.js +16 -0
- package/lib/helpers/update/applyTimestampsToChildren.js +193 -0
- package/lib/helpers/update/applyTimestampsToUpdate.js +131 -0
- package/lib/helpers/update/castArrayFilters.js +113 -0
- package/lib/helpers/update/decorateUpdateWithVersionKey.js +35 -0
- package/lib/helpers/update/modifiedPaths.js +33 -0
- package/lib/helpers/update/moveImmutableProperties.js +53 -0
- package/lib/helpers/update/removeUnusedArrayFilters.js +32 -0
- package/lib/helpers/update/updatedPathsByArrayFilter.js +27 -0
- package/lib/helpers/updateValidators.js +193 -0
- package/lib/index.js +17 -0
- package/lib/internal.js +46 -0
- package/lib/model.js +5010 -0
- package/lib/modifiedPathsSnapshot.js +9 -0
- package/lib/mongoose.js +1411 -0
- package/lib/options/populateOptions.js +36 -0
- package/lib/options/propertyOptions.js +8 -0
- package/lib/options/saveOptions.js +16 -0
- package/lib/options/schemaArrayOptions.js +78 -0
- package/lib/options/schemaBufferOptions.js +38 -0
- package/lib/options/schemaDateOptions.js +71 -0
- package/lib/options/schemaDocumentArrayOptions.js +68 -0
- package/lib/options/schemaMapOptions.js +43 -0
- package/lib/options/schemaNumberOptions.js +101 -0
- package/lib/options/schemaObjectIdOptions.js +64 -0
- package/lib/options/schemaStringOptions.js +138 -0
- package/lib/options/schemaSubdocumentOptions.js +66 -0
- package/lib/options/schemaTypeOptions.js +244 -0
- package/lib/options/schemaUnionOptions.js +32 -0
- package/lib/options/virtualOptions.js +164 -0
- package/lib/options.js +17 -0
- package/lib/plugins/index.js +6 -0
- package/lib/plugins/saveSubdocs.js +76 -0
- package/lib/plugins/sharding.js +84 -0
- package/lib/plugins/trackTransaction.js +84 -0
- package/lib/plugins/validateBeforeSave.js +41 -0
- package/lib/query.js +5673 -0
- package/lib/queryHelpers.js +387 -0
- package/lib/schema/array.js +699 -0
- package/lib/schema/bigint.js +282 -0
- package/lib/schema/boolean.js +332 -0
- package/lib/schema/buffer.js +343 -0
- package/lib/schema/date.js +467 -0
- package/lib/schema/decimal128.js +263 -0
- package/lib/schema/documentArray.js +656 -0
- package/lib/schema/documentArrayElement.js +137 -0
- package/lib/schema/double.js +246 -0
- package/lib/schema/index.js +32 -0
- package/lib/schema/int32.js +289 -0
- package/lib/schema/map.js +201 -0
- package/lib/schema/mixed.js +146 -0
- package/lib/schema/number.js +510 -0
- package/lib/schema/objectId.js +333 -0
- package/lib/schema/operators/bitwise.js +38 -0
- package/lib/schema/operators/exists.js +12 -0
- package/lib/schema/operators/geospatial.js +107 -0
- package/lib/schema/operators/helpers.js +32 -0
- package/lib/schema/operators/text.js +39 -0
- package/lib/schema/operators/type.js +20 -0
- package/lib/schema/string.js +733 -0
- package/lib/schema/subdocument.js +436 -0
- package/lib/schema/symbols.js +5 -0
- package/lib/schema/union.js +113 -0
- package/lib/schema/uuid.js +305 -0
- package/lib/schema.js +3226 -0
- package/lib/schemaType.js +1835 -0
- package/lib/stateMachine.js +232 -0
- package/lib/types/array/index.js +119 -0
- package/lib/types/array/isMongooseArray.js +5 -0
- package/lib/types/array/methods/index.js +1095 -0
- package/lib/types/arraySubdocument.js +207 -0
- package/lib/types/buffer.js +294 -0
- package/lib/types/decimal128.js +13 -0
- package/lib/types/documentArray/index.js +113 -0
- package/lib/types/documentArray/isMongooseDocumentArray.js +5 -0
- package/lib/types/documentArray/methods/index.js +415 -0
- package/lib/types/double.js +13 -0
- package/lib/types/index.js +23 -0
- package/lib/types/map.js +419 -0
- package/lib/types/objectid.js +41 -0
- package/lib/types/subdocument.js +464 -0
- package/lib/types/uuid.js +13 -0
- package/lib/utils.js +1054 -0
- package/lib/validOptions.js +42 -0
- package/lib/virtualType.js +204 -0
- package/package.json +148 -0
- package/types/aggregate.d.ts +180 -0
- package/types/augmentations.d.ts +9 -0
- package/types/callback.d.ts +8 -0
- package/types/collection.d.ts +49 -0
- package/types/connection.d.ts +297 -0
- package/types/cursor.d.ts +67 -0
- package/types/document.d.ts +374 -0
- package/types/error.d.ts +143 -0
- package/types/expressions.d.ts +3053 -0
- package/types/helpers.d.ts +32 -0
- package/types/index.d.ts +1056 -0
- package/types/indexes.d.ts +97 -0
- package/types/inferhydrateddoctype.d.ts +115 -0
- package/types/inferrawdoctype.d.ts +135 -0
- package/types/inferschematype.d.ts +337 -0
- package/types/middlewares.d.ts +59 -0
- package/types/models.d.ts +1306 -0
- package/types/mongooseoptions.d.ts +228 -0
- package/types/pipelinestage.d.ts +333 -0
- package/types/populate.d.ts +53 -0
- package/types/query.d.ts +934 -0
- package/types/schemaoptions.d.ts +282 -0
- package/types/schematypes.d.ts +654 -0
- package/types/session.d.ts +32 -0
- package/types/types.d.ts +109 -0
- package/types/utility.d.ts +175 -0
- package/types/validation.d.ts +39 -0
- package/types/virtuals.d.ts +14 -0
|
@@ -0,0 +1,654 @@
|
|
|
1
|
+
import * as BSON from 'bson';
|
|
2
|
+
|
|
3
|
+
declare module 'mongoose' {
|
|
4
|
+
/** The Mongoose Date [SchemaType](/docs/schematypes.html). */
|
|
5
|
+
type Date = Schema.Types.Date;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The Mongoose Decimal128 [SchemaType](/docs/schematypes.html). Used for
|
|
9
|
+
* declaring paths in your schema that should be
|
|
10
|
+
* [128-bit decimal floating points](http://thecodebarbarian.com/a-nodejs-perspective-on-mongodb-34-decimal.html).
|
|
11
|
+
* Do not use this to create a new Decimal128 instance, use `mongoose.Types.Decimal128`
|
|
12
|
+
* instead.
|
|
13
|
+
*/
|
|
14
|
+
type Decimal128 = Schema.Types.Decimal128;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The Mongoose Int32 [SchemaType](/docs/schematypes.html). Used for
|
|
18
|
+
* declaring paths in your schema that should be
|
|
19
|
+
* 32-bit integers
|
|
20
|
+
* Do not use this to create a new Int32 instance, use `mongoose.Types.Int32`
|
|
21
|
+
* instead.
|
|
22
|
+
*/
|
|
23
|
+
type Int32 = Schema.Types.Int32;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* The Mongoose Mixed [SchemaType](/docs/schematypes.html). Used for
|
|
27
|
+
* declaring paths in your schema that Mongoose's change tracking, casting,
|
|
28
|
+
* and validation should ignore.
|
|
29
|
+
*/
|
|
30
|
+
type Mixed = Schema.Types.Mixed;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* The Mongoose Number [SchemaType](/docs/schematypes.html). Used for
|
|
34
|
+
* declaring paths in your schema that Mongoose should cast to numbers.
|
|
35
|
+
*/
|
|
36
|
+
type Number = Schema.Types.Number;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* The Mongoose Double [SchemaType](/docs/schematypes.html). Used for
|
|
40
|
+
* declaring paths in your schema that Mongoose should cast to doubles (IEEE 754-2008)/
|
|
41
|
+
*/
|
|
42
|
+
type Double = Schema.Types.Double;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The Mongoose ObjectId [SchemaType](/docs/schematypes.html). Used for
|
|
46
|
+
* declaring paths in your schema that should be
|
|
47
|
+
* [MongoDB ObjectIds](https://www.mongodb.com/docs/manual/reference/method/ObjectId/).
|
|
48
|
+
* Do not use this to create a new ObjectId instance, use `mongoose.Types.ObjectId`
|
|
49
|
+
* instead.
|
|
50
|
+
*/
|
|
51
|
+
type ObjectId = Schema.Types.ObjectId;
|
|
52
|
+
|
|
53
|
+
/** The various Mongoose SchemaTypes. */
|
|
54
|
+
const SchemaTypes: typeof Schema.Types;
|
|
55
|
+
|
|
56
|
+
type DefaultType<T> = T extends Schema.Types.Mixed ? any : Partial<ExtractMongooseArray<T>>;
|
|
57
|
+
|
|
58
|
+
class SchemaTypeOptions<T, EnforcedDocType = any, THydratedDocumentType = HydratedDocument<EnforcedDocType>> {
|
|
59
|
+
type?: T extends string ? StringSchemaDefinition
|
|
60
|
+
: T extends number ? NumberSchemaDefinition
|
|
61
|
+
: T extends boolean ? BooleanSchemaDefinition
|
|
62
|
+
: T extends NativeDate ? DateSchemaDefinition
|
|
63
|
+
: T extends Map<any, any> ? SchemaDefinition<typeof Map>
|
|
64
|
+
: T extends Buffer ? SchemaDefinition<typeof Buffer>
|
|
65
|
+
: T extends Types.ObjectId ? ObjectIdSchemaDefinition
|
|
66
|
+
: T extends Types.ObjectId[] ?
|
|
67
|
+
AnyArray<ObjectIdSchemaDefinition> | AnyArray<SchemaTypeOptions<ObjectId, EnforcedDocType, THydratedDocumentType>>
|
|
68
|
+
: T extends object[] ?
|
|
69
|
+
| AnyArray<Schema<any, any, any>>
|
|
70
|
+
| AnyArray<SchemaDefinition<Unpacked<T>, EnforcedDocType, THydratedDocumentType>>
|
|
71
|
+
| AnyArray<SchemaTypeOptions<Unpacked<T>, EnforcedDocType, THydratedDocumentType>>
|
|
72
|
+
: T extends string[] ?
|
|
73
|
+
AnyArray<StringSchemaDefinition> | AnyArray<SchemaTypeOptions<string, EnforcedDocType, THydratedDocumentType>>
|
|
74
|
+
: T extends number[] ?
|
|
75
|
+
AnyArray<NumberSchemaDefinition> | AnyArray<SchemaTypeOptions<number, EnforcedDocType, THydratedDocumentType>>
|
|
76
|
+
: T extends boolean[] ?
|
|
77
|
+
AnyArray<BooleanSchemaDefinition> | AnyArray<SchemaTypeOptions<boolean, EnforcedDocType, THydratedDocumentType>>
|
|
78
|
+
: T extends Function[] ?
|
|
79
|
+
AnyArray<Function | string> | AnyArray<SchemaTypeOptions<Unpacked<T>, EnforcedDocType, THydratedDocumentType>>
|
|
80
|
+
: T | typeof SchemaType | Schema<any, any, any> | SchemaDefinition<T, EnforcedDocType, THydratedDocumentType> | Function | AnyArray<Function>;
|
|
81
|
+
|
|
82
|
+
/** Defines a virtual with the given name that gets/sets this path. */
|
|
83
|
+
alias?: string | string[];
|
|
84
|
+
|
|
85
|
+
/** Function or object describing how to validate this schematype. See [validation docs](https://mongoosejs.com/docs/validation.html). */
|
|
86
|
+
validate?: SchemaValidator<T, THydratedDocumentType> | AnyArray<SchemaValidator<T, THydratedDocumentType>>;
|
|
87
|
+
|
|
88
|
+
/** Allows overriding casting logic for this individual path. If a string, the given string overwrites Mongoose's default cast error message. */
|
|
89
|
+
cast?:
|
|
90
|
+
| string
|
|
91
|
+
| boolean
|
|
92
|
+
| ((value: any) => T)
|
|
93
|
+
| [(value: any) => T, string]
|
|
94
|
+
| [((value: any) => T) | null, (value: any, path: string, model: Model<any>, kind: string) => string];
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* If true, attach a required validator to this path, which ensures this path
|
|
98
|
+
* cannot be set to a nullish value. If a function, Mongoose calls the
|
|
99
|
+
* function and only checks for nullish values if the function returns a truthy value.
|
|
100
|
+
*/
|
|
101
|
+
required?:
|
|
102
|
+
| boolean
|
|
103
|
+
| ((this: THydratedDocumentType) => boolean)
|
|
104
|
+
| [boolean, string]
|
|
105
|
+
| [(this: THydratedDocumentType) => boolean, string];
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* The default value for this path. If a function, Mongoose executes the function
|
|
109
|
+
* and uses the return value as the default.
|
|
110
|
+
*/
|
|
111
|
+
default?: DefaultType<T> | ((this: THydratedDocumentType, doc: THydratedDocumentType) => DefaultType<T> | null | undefined) | null;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* The model that `populate()` should use if populating this path.
|
|
115
|
+
*/
|
|
116
|
+
ref?: string | Model<any> | ((this: any, doc: any) => string | Model<any>);
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* The path in the document that `populate()` should use to find the model
|
|
120
|
+
* to use.
|
|
121
|
+
*/
|
|
122
|
+
|
|
123
|
+
refPath?: string | ((this: any, doc: any) => string);
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Whether to include or exclude this path by default when loading documents
|
|
127
|
+
* using `find()`, `findOne()`, etc.
|
|
128
|
+
*/
|
|
129
|
+
select?: boolean | number;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* If [truthy](https://masteringjs.io/tutorials/fundamentals/truthy), Mongoose will
|
|
133
|
+
* build an index on this path when the model is compiled.
|
|
134
|
+
*/
|
|
135
|
+
index?: boolean | IndexDirection | IndexOptions;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* If [truthy](https://masteringjs.io/tutorials/fundamentals/truthy), Mongoose
|
|
139
|
+
* will build a unique index on this path when the
|
|
140
|
+
* model is compiled. [The `unique` option is **not** a validator](/docs/validation.html#the-unique-option-is-not-a-validator).
|
|
141
|
+
*/
|
|
142
|
+
unique?: boolean | number | [true, string];
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* If [truthy](https://masteringjs.io/tutorials/fundamentals/truthy), Mongoose will
|
|
146
|
+
* disallow changes to this path once the document is saved to the database for the first time. Read more
|
|
147
|
+
* about [immutability in Mongoose here](http://thecodebarbarian.com/whats-new-in-mongoose-5-6-immutable-properties.html).
|
|
148
|
+
*/
|
|
149
|
+
immutable?: boolean | ((this: any, doc: any) => boolean);
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* If [truthy](https://masteringjs.io/tutorials/fundamentals/truthy), Mongoose will
|
|
153
|
+
* build a sparse index on this path.
|
|
154
|
+
*/
|
|
155
|
+
sparse?: boolean | number;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* If [truthy](https://masteringjs.io/tutorials/fundamentals/truthy), Mongoose
|
|
159
|
+
* will build a text index on this path.
|
|
160
|
+
*/
|
|
161
|
+
text?: boolean | number | any;
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Define a transform function for this individual schema type.
|
|
165
|
+
* Only called when calling `toJSON()` or `toObject()`.
|
|
166
|
+
*/
|
|
167
|
+
transform?: (this: any, val: T) => any;
|
|
168
|
+
|
|
169
|
+
/** defines a custom getter for this property using [`Object.defineProperty()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty). */
|
|
170
|
+
get?: (value: any, doc?: this) => T | undefined;
|
|
171
|
+
|
|
172
|
+
/** defines a custom setter for this property using [`Object.defineProperty()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty). */
|
|
173
|
+
set?: (value: any, priorVal?: T, doc?: this) => any;
|
|
174
|
+
|
|
175
|
+
/** array of allowed values for this path. Allowed for strings, numbers, and arrays of strings */
|
|
176
|
+
enum?:
|
|
177
|
+
| Array<string | number | null>
|
|
178
|
+
| ReadonlyArray<string | number | null>
|
|
179
|
+
| { values: Array<string | number | null> | ReadonlyArray<string | number | null>; message?: string }
|
|
180
|
+
| { [path: string]: string | number | null };
|
|
181
|
+
|
|
182
|
+
/** The default [subtype](http://bsonspec.org/spec.html) associated with this buffer when it is stored in MongoDB. Only allowed for buffer paths */
|
|
183
|
+
subtype?: number;
|
|
184
|
+
|
|
185
|
+
/** The minimum value allowed for this path. Only allowed for numbers and dates. */
|
|
186
|
+
min?:
|
|
187
|
+
| number
|
|
188
|
+
| NativeDate
|
|
189
|
+
| [number, string]
|
|
190
|
+
| [NativeDate, string]
|
|
191
|
+
| readonly [number, string]
|
|
192
|
+
| readonly [NativeDate, string];
|
|
193
|
+
|
|
194
|
+
/** The maximum value allowed for this path. Only allowed for numbers and dates. */
|
|
195
|
+
max?:
|
|
196
|
+
| number
|
|
197
|
+
| NativeDate
|
|
198
|
+
| [number, string]
|
|
199
|
+
| [NativeDate, string]
|
|
200
|
+
| readonly [number, string]
|
|
201
|
+
| readonly [NativeDate, string];
|
|
202
|
+
|
|
203
|
+
/** Set to false to disable minimizing empty single nested subdocuments by default */
|
|
204
|
+
minimize?: boolean;
|
|
205
|
+
|
|
206
|
+
/** Defines a TTL index on this path. Only allowed for dates. */
|
|
207
|
+
expires?: string | number;
|
|
208
|
+
|
|
209
|
+
/** If `true`, Mongoose will skip gathering indexes on subpaths. Only allowed for subdocuments and subdocument arrays. */
|
|
210
|
+
excludeIndexes?: boolean;
|
|
211
|
+
|
|
212
|
+
/** If set, overrides the child schema's `_id` option. Only allowed for subdocuments and subdocument arrays. */
|
|
213
|
+
_id?: boolean;
|
|
214
|
+
|
|
215
|
+
/** If set, specifies the type of this map's values. Mongoose will cast this map's values to the given type. */
|
|
216
|
+
of?: Function | SchemaDefinitionProperty<any> | (Function | SchemaDefinitionProperty<any>)[];
|
|
217
|
+
|
|
218
|
+
/** If true, uses Mongoose's default `_id` settings. Only allowed for ObjectIds */
|
|
219
|
+
auto?: boolean;
|
|
220
|
+
|
|
221
|
+
/** Attaches a validator that succeeds if the data string matches the given regular expression, and fails otherwise. */
|
|
222
|
+
match?: RegExp | [RegExp, string] | readonly [RegExp, string];
|
|
223
|
+
|
|
224
|
+
/** If truthy, Mongoose will add a [custom setter](https://mongoosejs.com/docs/api/schematype.html#SchemaType.prototype.set()) that lowercases this string using JavaScript's built-in `String#toLowerCase()`. */
|
|
225
|
+
lowercase?: boolean;
|
|
226
|
+
|
|
227
|
+
/** If truthy, Mongoose will add a [custom setter](https://mongoosejs.com/docs/api/schematype.html#SchemaType.prototype.set()) that removes leading and trailing whitespace using JavaScript's built-in `String#trim()`. */
|
|
228
|
+
trim?: boolean;
|
|
229
|
+
|
|
230
|
+
/** If truthy, Mongoose will add a [custom setter](https://mongoosejs.com/docs/api/schematype.html#SchemaType.prototype.set()) that uppercases this string using JavaScript's built-in `String#toUpperCase()`. */
|
|
231
|
+
uppercase?: boolean;
|
|
232
|
+
|
|
233
|
+
/** If set, Mongoose will add a custom validator that ensures the given string's `length` is at least the given number. */
|
|
234
|
+
minlength?: number | [number, string] | readonly [number, string];
|
|
235
|
+
minLength?: number | [number, string] | readonly [number, string];
|
|
236
|
+
|
|
237
|
+
/** If set, Mongoose will add a custom validator that ensures the given string's `length` is at most the given number. */
|
|
238
|
+
maxlength?: number | [number, string] | readonly [number, string];
|
|
239
|
+
maxLength?: number | [number, string] | readonly [number, string];
|
|
240
|
+
|
|
241
|
+
[other: string]: any;
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* If set, configures the field for automatic encryption.
|
|
245
|
+
*/
|
|
246
|
+
encrypt?: EncryptSchemaTypeOptions;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
interface Validator<DocType = any> {
|
|
250
|
+
message?: string | ((props: ValidatorProps) => string);
|
|
251
|
+
type?: string;
|
|
252
|
+
validator?: ValidatorFunction<DocType>;
|
|
253
|
+
reason?: Error;
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
type ValidatorFunction<DocType = any> = (this: DocType, value: any, validatorProperties?: Validator) => any;
|
|
257
|
+
|
|
258
|
+
interface QueryEncryptionEncryptOptions {
|
|
259
|
+
/** The id of the dataKey to use for encryption. Must be a BSON binary subtype 4 (UUID). */
|
|
260
|
+
keyId: BSON.Binary;
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* Specifies the type of queries that the field can be queried on the encrypted field.
|
|
264
|
+
*/
|
|
265
|
+
queries?: 'equality' | 'range';
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
interface ClientSideEncryptionEncryptOptions {
|
|
269
|
+
/** The id of the dataKey to use for encryption. Must be a BSON binary subtype 4 (UUID). */
|
|
270
|
+
keyId: [BSON.Binary];
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* The algorithm to use for encryption.
|
|
274
|
+
*/
|
|
275
|
+
algorithm: 'AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic' | 'AEAD_AES_256_CBC_HMAC_SHA_512-Random';
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
export type EncryptSchemaTypeOptions = QueryEncryptionEncryptOptions | ClientSideEncryptionEncryptOptions;
|
|
279
|
+
|
|
280
|
+
class SchemaType<T = any, DocType = any> {
|
|
281
|
+
/** SchemaType constructor */
|
|
282
|
+
constructor(path: string, options?: AnyObject, instance?: string);
|
|
283
|
+
|
|
284
|
+
/** Get/set the function used to cast arbitrary values to this type. */
|
|
285
|
+
static cast(caster?: Function | boolean): Function;
|
|
286
|
+
|
|
287
|
+
static checkRequired(checkRequired?: (v: any) => boolean): (v: any) => boolean;
|
|
288
|
+
|
|
289
|
+
/** Sets a default option for this schema type. */
|
|
290
|
+
static set(option: string, value: any): void;
|
|
291
|
+
|
|
292
|
+
/** Attaches a getter for all instances of this schema type. */
|
|
293
|
+
static get(getter: (value: any) => any): void;
|
|
294
|
+
|
|
295
|
+
/** Array containing default setters for all instances of this SchemaType */
|
|
296
|
+
static setters: ((
|
|
297
|
+
val?: unknown,
|
|
298
|
+
priorVal?: unknown,
|
|
299
|
+
doc?: Document<unknown>,
|
|
300
|
+
options?: Record<string, any> | null
|
|
301
|
+
) => unknown)[];
|
|
302
|
+
|
|
303
|
+
/** Contains the handlers for different query operators for this schema type. */
|
|
304
|
+
$conditionalHandlers: { [op: string]: (val: any, context: any) => any };
|
|
305
|
+
|
|
306
|
+
/** The class that Mongoose uses internally to instantiate this SchemaType's `options` property. */
|
|
307
|
+
OptionsConstructor: SchemaTypeOptions<T>;
|
|
308
|
+
|
|
309
|
+
/** Cast `val` to this schema type. Each class that inherits from schema type should implement this function. */
|
|
310
|
+
cast(val: any, doc?: Document<any>, init?: boolean, prev?: any, options?: any): any;
|
|
311
|
+
cast<ResultType>(val: any, doc?: Document<any>, init?: boolean, prev?: any, options?: any): ResultType;
|
|
312
|
+
|
|
313
|
+
/** Sets a default value for this SchemaType. */
|
|
314
|
+
default(val: any): any;
|
|
315
|
+
|
|
316
|
+
/** Adds a getter to this schematype. */
|
|
317
|
+
get(fn: Function): this;
|
|
318
|
+
|
|
319
|
+
/** Gets this SchemaType's embedded SchemaType, if any */
|
|
320
|
+
getEmbeddedSchemaType<T = any, DocType = any>(): SchemaType<T, DocType> | undefined;
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Defines this path as immutable. Mongoose prevents you from changing
|
|
324
|
+
* immutable paths unless the parent document has [`isNew: true`](/docs/api/document.html#document_Document-isNew).
|
|
325
|
+
*/
|
|
326
|
+
immutable(bool: boolean): this;
|
|
327
|
+
|
|
328
|
+
/** Declares the index options for this schematype. */
|
|
329
|
+
index(options: any): this;
|
|
330
|
+
|
|
331
|
+
/** String representation of what type this is, like 'ObjectID' or 'Number' */
|
|
332
|
+
instance: string;
|
|
333
|
+
|
|
334
|
+
/** True if this SchemaType has a required validator. False otherwise. */
|
|
335
|
+
isRequired?: boolean;
|
|
336
|
+
|
|
337
|
+
/** The options this SchemaType was instantiated with */
|
|
338
|
+
options: AnyObject;
|
|
339
|
+
|
|
340
|
+
/** The path to this SchemaType in a Schema. */
|
|
341
|
+
path: string;
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Set the model that this path refers to. This is the option that [populate](https://mongoosejs.com/docs/populate.html)
|
|
345
|
+
* looks at to determine the foreign collection it should query.
|
|
346
|
+
*/
|
|
347
|
+
ref(ref: string | boolean | Model<any>): this;
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Adds a required validator to this SchemaType. The validator gets added
|
|
351
|
+
* to the front of this SchemaType's validators array using unshift().
|
|
352
|
+
*/
|
|
353
|
+
required(required: boolean, message?: string): this;
|
|
354
|
+
|
|
355
|
+
/** If the SchemaType is a subdocument or document array, this is the schema of that subdocument */
|
|
356
|
+
schema?: Schema<any>;
|
|
357
|
+
|
|
358
|
+
/** Sets default select() behavior for this path. */
|
|
359
|
+
select(val: boolean): this;
|
|
360
|
+
|
|
361
|
+
/** Adds a setter to this schematype. */
|
|
362
|
+
set(fn: Function): this;
|
|
363
|
+
|
|
364
|
+
/** Declares a sparse index. */
|
|
365
|
+
sparse(bool: boolean): this;
|
|
366
|
+
|
|
367
|
+
/** Declares a full text index. */
|
|
368
|
+
text(bool: boolean): this;
|
|
369
|
+
|
|
370
|
+
toJSONSchema(options?: { useBsonType?: boolean }): Record<string, any>;
|
|
371
|
+
|
|
372
|
+
/** Defines a custom function for transforming this path when converting a document to JSON. */
|
|
373
|
+
transform(fn: (value: any) => any): this;
|
|
374
|
+
|
|
375
|
+
/** Declares an unique index. */
|
|
376
|
+
unique(bool: boolean): this;
|
|
377
|
+
|
|
378
|
+
/** The validators that Mongoose should run to validate properties at this SchemaType's path. */
|
|
379
|
+
validators: Validator[];
|
|
380
|
+
|
|
381
|
+
/** Adds validator(s) for this document path. */
|
|
382
|
+
validate(obj: RegExp | ValidatorFunction<DocType> | Validator<DocType>, errorMsg?: string, type?: string): this;
|
|
383
|
+
|
|
384
|
+
/** Adds multiple validators for this document path. */
|
|
385
|
+
validateAll(validators: Array<RegExp | ValidatorFunction<DocType> | Validator<DocType>>): this;
|
|
386
|
+
|
|
387
|
+
/** Default options for this SchemaType */
|
|
388
|
+
static defaultOptions?: Record<string, any>;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
namespace Schema {
|
|
392
|
+
namespace Types {
|
|
393
|
+
class Array extends SchemaType implements AcceptsDiscriminator {
|
|
394
|
+
/** This schema type's name, to defend against minifiers that mangle function names. */
|
|
395
|
+
static schemaName: 'Array';
|
|
396
|
+
readonly schemaName: 'Array';
|
|
397
|
+
|
|
398
|
+
static options: { castNonArrays: boolean };
|
|
399
|
+
|
|
400
|
+
discriminator<T, U>(name: string | number, schema: Schema<T, U>, value?: string): U;
|
|
401
|
+
discriminator<D>(name: string | number, schema: Schema, value?: string): Model<D>;
|
|
402
|
+
|
|
403
|
+
/** The schematype embedded in this array */
|
|
404
|
+
embeddedSchemaType: SchemaType;
|
|
405
|
+
|
|
406
|
+
/** Default options for this SchemaType */
|
|
407
|
+
static defaultOptions: Record<string, any>;
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* Adds an enum validator if this is an array of strings or numbers. Equivalent to
|
|
411
|
+
* `SchemaString.prototype.enum()` or `SchemaNumber.prototype.enum()`
|
|
412
|
+
*/
|
|
413
|
+
enum(vals: string[] | number[]): this;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
class BigInt extends SchemaType {
|
|
417
|
+
/** This schema type's name, to defend against minifiers that mangle function names. */
|
|
418
|
+
static schemaName: 'BigInt';
|
|
419
|
+
readonly schemaName: 'BigInt';
|
|
420
|
+
|
|
421
|
+
/** Default options for this SchemaType */
|
|
422
|
+
static defaultOptions: Record<string, any>;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
class Boolean extends SchemaType {
|
|
426
|
+
/** This schema type's name, to defend against minifiers that mangle function names. */
|
|
427
|
+
static schemaName: 'Boolean';
|
|
428
|
+
readonly schemaName: 'Boolean';
|
|
429
|
+
|
|
430
|
+
/** Configure which values get casted to `true`. */
|
|
431
|
+
static convertToTrue: Set<any>;
|
|
432
|
+
|
|
433
|
+
/** Configure which values get casted to `false`. */
|
|
434
|
+
static convertToFalse: Set<any>;
|
|
435
|
+
|
|
436
|
+
/** Default options for this SchemaType */
|
|
437
|
+
static defaultOptions: Record<string, any>;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
class Buffer extends SchemaType {
|
|
441
|
+
/** This schema type's name, to defend against minifiers that mangle function names. */
|
|
442
|
+
static schemaName: 'Buffer';
|
|
443
|
+
readonly schemaName: 'Buffer';
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* Sets the default [subtype](https://studio3t.com/whats-new/best-practices-uuid-mongodb/)
|
|
447
|
+
* for this buffer. You can find a [list of allowed subtypes here](http://api.mongodb.com/python/current/api/bson/binary.html).
|
|
448
|
+
*/
|
|
449
|
+
subtype(subtype: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 128): this;
|
|
450
|
+
|
|
451
|
+
/** Default options for this SchemaType */
|
|
452
|
+
static defaultOptions: Record<string, any>;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
class Date extends SchemaType {
|
|
456
|
+
/** This schema type's name, to defend against minifiers that mangle function names. */
|
|
457
|
+
static schemaName: 'Date';
|
|
458
|
+
readonly schemaName: 'Date';
|
|
459
|
+
|
|
460
|
+
/** Declares a TTL index (rounded to the nearest second) for _Date_ types only. */
|
|
461
|
+
expires(when: number | string): this;
|
|
462
|
+
|
|
463
|
+
/** Sets a maximum date validator. */
|
|
464
|
+
max(value: NativeDate, message?: string): this;
|
|
465
|
+
|
|
466
|
+
/** Sets a minimum date validator. */
|
|
467
|
+
min(value: NativeDate, message?: string): this;
|
|
468
|
+
|
|
469
|
+
/** Default options for this SchemaType */
|
|
470
|
+
static defaultOptions: Record<string, any>;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
class Decimal128 extends SchemaType {
|
|
474
|
+
/** This schema type's name, to defend against minifiers that mangle function names. */
|
|
475
|
+
static schemaName: 'Decimal128';
|
|
476
|
+
readonly schemaName: 'Decimal128';
|
|
477
|
+
|
|
478
|
+
/** Default options for this SchemaType */
|
|
479
|
+
static defaultOptions: Record<string, any>;
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
class Int32 extends SchemaType {
|
|
483
|
+
/** This schema type's name, to defend against minifiers that mangle function names. */
|
|
484
|
+
static schemaName: 'Int32';
|
|
485
|
+
readonly schemaName: 'Int32';
|
|
486
|
+
|
|
487
|
+
/** Default options for this SchemaType */
|
|
488
|
+
static defaultOptions: Record<string, any>;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
class DocumentArray extends SchemaType implements AcceptsDiscriminator {
|
|
492
|
+
/** This schema type's name, to defend against minifiers that mangle function names. */
|
|
493
|
+
static schemaName: 'DocumentArray';
|
|
494
|
+
readonly schemaName: 'DocumentArray';
|
|
495
|
+
|
|
496
|
+
static options: { castNonArrays: boolean };
|
|
497
|
+
|
|
498
|
+
schemaOptions?: SchemaOptions;
|
|
499
|
+
|
|
500
|
+
discriminator<D>(name: string | number, schema: Schema, value?: string): Model<D>;
|
|
501
|
+
discriminator<T, U>(name: string | number, schema: Schema<T, U>, value?: string): U;
|
|
502
|
+
|
|
503
|
+
/** The schema used for documents in this array */
|
|
504
|
+
schema: Schema;
|
|
505
|
+
|
|
506
|
+
/** The schematype embedded in this array */
|
|
507
|
+
embeddedSchemaType: Subdocument;
|
|
508
|
+
|
|
509
|
+
/** The constructor used for subdocuments in this array */
|
|
510
|
+
Constructor: typeof Types.Subdocument;
|
|
511
|
+
|
|
512
|
+
/** Default options for this SchemaType */
|
|
513
|
+
static defaultOptions: Record<string, any>;
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
class DocumentArrayElement extends SchemaType {
|
|
517
|
+
/** This schema type's name, to defend against minifiers that mangle function names. */
|
|
518
|
+
static schemaName: 'DocumentArrayElement';
|
|
519
|
+
readonly schemaName: 'DocumentArrayElement';
|
|
520
|
+
|
|
521
|
+
/** Default options for this SchemaType */
|
|
522
|
+
static defaultOptions: Record<string, any>;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
class Map extends SchemaType {
|
|
526
|
+
/** This schema type's name, to defend against minifiers that mangle function names. */
|
|
527
|
+
static schemaName: 'Map';
|
|
528
|
+
readonly schemaName: 'Map';
|
|
529
|
+
|
|
530
|
+
/** Default options for this SchemaType */
|
|
531
|
+
static defaultOptions: Record<string, any>;
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
class Mixed extends SchemaType {
|
|
535
|
+
/** This schema type's name, to defend against minifiers that mangle function names. */
|
|
536
|
+
static schemaName: 'Mixed';
|
|
537
|
+
readonly schemaName: 'Mixed';
|
|
538
|
+
|
|
539
|
+
/** Default options for this SchemaType */
|
|
540
|
+
static defaultOptions: Record<string, any>;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
class Number extends SchemaType {
|
|
544
|
+
/** This schema type's name, to defend against minifiers that mangle function names. */
|
|
545
|
+
static schemaName: 'Number';
|
|
546
|
+
readonly schemaName: 'Number';
|
|
547
|
+
|
|
548
|
+
/** Sets a enum validator */
|
|
549
|
+
enum(vals: number[]): this;
|
|
550
|
+
|
|
551
|
+
/** Sets a maximum number validator. */
|
|
552
|
+
max(value: number, message?: string): this;
|
|
553
|
+
|
|
554
|
+
/** Sets a minimum number validator. */
|
|
555
|
+
min(value: number, message?: string): this;
|
|
556
|
+
|
|
557
|
+
/** Default options for this SchemaType */
|
|
558
|
+
static defaultOptions: Record<string, any>;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
class Double extends SchemaType {
|
|
562
|
+
/** This schema type's name, to defend against minifiers that mangle function names. */
|
|
563
|
+
static schemaName: 'Double';
|
|
564
|
+
readonly schemaName: 'Double';
|
|
565
|
+
|
|
566
|
+
/** Default options for this SchemaType */
|
|
567
|
+
static defaultOptions: Record<string, any>;
|
|
568
|
+
}
|
|
569
|
+
|
|
570
|
+
class ObjectId extends SchemaType {
|
|
571
|
+
/** This schema type's name, to defend against minifiers that mangle function names. */
|
|
572
|
+
static schemaName: 'ObjectId';
|
|
573
|
+
readonly schemaName: 'ObjectId';
|
|
574
|
+
|
|
575
|
+
/** Adds an auto-generated ObjectId default if turnOn is true. */
|
|
576
|
+
auto(turnOn: boolean): this;
|
|
577
|
+
|
|
578
|
+
/** Default options for this SchemaType */
|
|
579
|
+
static defaultOptions: Record<string, any>;
|
|
580
|
+
}
|
|
581
|
+
|
|
582
|
+
class Subdocument<DocType = unknown> extends SchemaType implements AcceptsDiscriminator {
|
|
583
|
+
/** This schema type's name, to defend against minifiers that mangle function names. */
|
|
584
|
+
static schemaName: string;
|
|
585
|
+
|
|
586
|
+
/** The document's schema */
|
|
587
|
+
schema: Schema;
|
|
588
|
+
|
|
589
|
+
/** The constructor used to create subdocuments based on this schematype */
|
|
590
|
+
Constructor: typeof Types.Subdocument;
|
|
591
|
+
|
|
592
|
+
/** Default options for this SchemaType */
|
|
593
|
+
static defaultOptions: Record<string, any>;
|
|
594
|
+
|
|
595
|
+
discriminator<T, U>(name: string | number, schema: Schema<T, U>, value?: string): U;
|
|
596
|
+
discriminator<D>(name: string | number, schema: Schema, value?: string): Model<D>;
|
|
597
|
+
|
|
598
|
+
cast(
|
|
599
|
+
val: any,
|
|
600
|
+
doc?: Document<any>,
|
|
601
|
+
init?: boolean,
|
|
602
|
+
prev?: any,
|
|
603
|
+
options?: any
|
|
604
|
+
): HydratedSingleSubdocument<DocType>;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
class String extends SchemaType {
|
|
608
|
+
/** This schema type's name, to defend against minifiers that mangle function names. */
|
|
609
|
+
static schemaName: 'String';
|
|
610
|
+
readonly schemaName: 'String';
|
|
611
|
+
|
|
612
|
+
/** Adds an enum validator */
|
|
613
|
+
enum(vals: string[] | any): this;
|
|
614
|
+
|
|
615
|
+
/** Adds a lowercase [setter](http://mongoosejs.com/docs/api/schematype.html#schematype_SchemaType-set). */
|
|
616
|
+
lowercase(shouldApply?: boolean): this;
|
|
617
|
+
|
|
618
|
+
/** Sets a regexp validator. */
|
|
619
|
+
match(value: RegExp, message: string): this;
|
|
620
|
+
|
|
621
|
+
/** Sets a maximum length validator. */
|
|
622
|
+
maxlength(value: number, message: string): this;
|
|
623
|
+
|
|
624
|
+
/** Sets a minimum length validator. */
|
|
625
|
+
minlength(value: number, message: string): this;
|
|
626
|
+
|
|
627
|
+
/** Adds a trim [setter](http://mongoosejs.com/docs/api/schematype.html#schematype_SchemaType-set). */
|
|
628
|
+
trim(shouldTrim?: boolean): this;
|
|
629
|
+
|
|
630
|
+
/** Adds an uppercase [setter](http://mongoosejs.com/docs/api/schematype.html#schematype_SchemaType-set). */
|
|
631
|
+
uppercase(shouldApply?: boolean): this;
|
|
632
|
+
|
|
633
|
+
/** Default options for this SchemaType */
|
|
634
|
+
static defaultOptions: Record<string, any>;
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
class Union extends SchemaType {
|
|
638
|
+
static schemaName: 'Union';
|
|
639
|
+
|
|
640
|
+
/** Default options for this SchemaType */
|
|
641
|
+
static defaultOptions: Record<string, any>;
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
class UUID extends SchemaType {
|
|
645
|
+
/** This schema type's name, to defend against minifiers that mangle function names. */
|
|
646
|
+
static schemaName: 'UUID';
|
|
647
|
+
readonly schemaName: 'UUID';
|
|
648
|
+
|
|
649
|
+
/** Default options for this SchemaType */
|
|
650
|
+
static defaultOptions: Record<string, any>;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
declare module 'mongoose' {
|
|
2
|
+
import mongodb = require('mongodb');
|
|
3
|
+
|
|
4
|
+
type ClientSessionOptions = mongodb.ClientSessionOptions;
|
|
5
|
+
type ClientSession = mongodb.ClientSession;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* _Requires MongoDB >= 3.6.0._ Starts a [MongoDB session](https://www.mongodb.com/docs/manual/release-notes/3.6/#client-sessions)
|
|
9
|
+
* for benefits like causal consistency, [retryable writes](https://www.mongodb.com/docs/manual/core/retryable-writes/),
|
|
10
|
+
* and [transactions](http://thecodebarbarian.com/a-node-js-perspective-on-mongodb-4-transactions.html).
|
|
11
|
+
*/
|
|
12
|
+
function startSession(options?: ClientSessionOptions): Promise<ClientSession>;
|
|
13
|
+
|
|
14
|
+
interface SessionOperation {
|
|
15
|
+
/** Sets the session. Useful for [transactions](/docs/transactions.html). */
|
|
16
|
+
session(session: mongodb.ClientSession | null): this;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface SessionStarter {
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Starts a [MongoDB session](https://www.mongodb.com/docs/manual/release-notes/3.6/#client-sessions)
|
|
23
|
+
* for benefits like causal consistency, [retryable writes](https://www.mongodb.com/docs/manual/core/retryable-writes/),
|
|
24
|
+
* and [transactions](http://thecodebarbarian.com/a-node-js-perspective-on-mongodb-4-transactions.html).
|
|
25
|
+
*/
|
|
26
|
+
startSession(options?: ClientSessionOptions): Promise<ClientSession>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface SessionOption {
|
|
30
|
+
session?: ClientSession | null;
|
|
31
|
+
}
|
|
32
|
+
}
|