@datanimbus/mongoose 6.13.13 → 9.13.2
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/README.md +80 -70
- package/eslint.config.mjs +202 -0
- package/index.js +2 -1
- package/lib/aggregate.js +276 -174
- package/lib/cast/bigint.js +46 -0
- package/lib/cast/boolean.js +3 -3
- package/lib/cast/decimal128.js +4 -1
- package/lib/cast/double.js +56 -0
- package/lib/cast/int32.js +42 -0
- package/lib/cast/number.js +6 -6
- package/lib/cast/objectid.js +3 -3
- package/lib/cast/string.js +3 -3
- package/lib/cast/uuid.js +35 -0
- package/lib/cast.js +100 -92
- package/lib/collection.js +31 -22
- package/lib/connection.js +792 -507
- package/lib/constants.js +73 -0
- package/lib/cursor/{AggregationCursor.js → aggregationCursor.js} +205 -52
- package/lib/cursor/changeStream.js +218 -0
- package/lib/cursor/queryCursor.js +676 -0
- package/lib/defaults/schemaDefaultsCache.js +62 -0
- package/lib/document.js +2419 -1306
- package/lib/drivers/node-mongodb-native/bulkWriteResult.js +5 -0
- package/lib/drivers/node-mongodb-native/collection.js +101 -135
- package/lib/drivers/node-mongodb-native/connection.js +386 -28
- package/lib/drivers/node-mongodb-native/index.js +3 -5
- package/lib/error/browserMissingSchema.js +5 -4
- package/lib/error/bulkSaveIncompleteError.js +44 -0
- package/lib/error/cast.js +30 -21
- package/lib/error/createCollectionsError.js +26 -0
- package/lib/error/divergentArray.js +11 -9
- package/lib/error/eachAsyncMultiError.js +2 -2
- package/lib/error/index.js +38 -29
- package/lib/error/invalidSchemaOption.js +32 -0
- package/lib/error/messages.js +4 -3
- package/lib/error/missingSchema.js +8 -6
- package/lib/error/notFound.js +7 -5
- package/lib/error/objectExpected.js +9 -8
- package/lib/error/objectParameter.js +12 -11
- package/lib/error/overwriteModel.js +7 -6
- package/lib/error/parallelSave.js +11 -8
- package/lib/error/parallelValidate.js +9 -7
- package/lib/error/serverSelection.js +1 -0
- package/lib/error/setOptionError.js +11 -9
- package/lib/error/strict.js +12 -10
- package/lib/error/strictPopulate.js +11 -9
- package/lib/error/syncIndexes.js +2 -2
- package/lib/error/validation.js +11 -17
- package/lib/error/validator.js +9 -8
- package/lib/error/version.js +12 -10
- package/lib/filters/operators.js +8 -0
- package/lib/helpers/aggregate/prepareDiscriminatorPipeline.js +4 -4
- package/lib/helpers/buildMiddlewareFilter.js +42 -0
- package/lib/helpers/clone.js +121 -35
- package/lib/helpers/common.js +7 -7
- package/lib/helpers/cursor/eachAsync.js +14 -11
- package/lib/helpers/cursor/waitForInitialization.js +17 -0
- package/lib/helpers/discriminator/applyEmbeddedDiscriminators.js +36 -0
- package/lib/helpers/discriminator/areDiscriminatorValuesEqual.js +1 -1
- package/lib/helpers/discriminator/getConstructor.js +9 -6
- package/lib/helpers/discriminator/getDiscriminatorByKey.js +1 -1
- package/lib/helpers/discriminator/getDiscriminatorByValue.js +1 -1
- package/lib/helpers/discriminator/getDiscriminatorValueFromFilter.js +30 -0
- package/lib/helpers/discriminator/getSchemaDiscriminatorByValue.js +1 -1
- package/lib/helpers/discriminator/mergeDiscriminatorSchema.js +41 -9
- package/lib/helpers/document/applyDefaults.js +82 -14
- package/lib/helpers/document/applyTimestamps.js +106 -0
- package/lib/helpers/document/applyVirtuals.js +147 -0
- package/lib/helpers/document/cleanModifiedSubpaths.js +14 -4
- package/lib/helpers/document/compile.js +20 -15
- package/lib/helpers/document/getDeepestSubdocumentForPath.js +38 -0
- package/lib/helpers/document/getEmbeddedDiscriminatorPath.js +6 -3
- package/lib/helpers/document/handleSpreadDoc.js +2 -1
- package/lib/helpers/document/isInPathsToSave.js +24 -0
- package/lib/helpers/document/toObjectRecursive.js +49 -0
- package/lib/helpers/get.js +1 -1
- package/lib/helpers/getDefaultBulkwriteResult.js +11 -20
- package/lib/helpers/getInheritedProperty.js +28 -0
- package/lib/helpers/getOwnProperty.js +19 -0
- package/lib/helpers/indexes/applySchemaCollation.js +1 -1
- package/lib/helpers/indexes/decorateDiscriminatorIndexOptions.js +1 -1
- package/lib/helpers/indexes/getRelatedIndexes.js +8 -4
- package/lib/helpers/indexes/isDefaultIdIndex.js +1 -1
- package/lib/helpers/indexes/isIndexEqual.js +13 -12
- package/lib/helpers/indexes/isIndexSpecEqual.js +32 -0
- package/lib/helpers/indexes/isTimeseriesIndex.js +16 -0
- package/lib/helpers/isBsonType.js +3 -6
- package/lib/helpers/isMongooseDocument.js +24 -0
- package/lib/helpers/isMongooseObject.js +6 -4
- package/lib/helpers/isObject.js +2 -2
- package/lib/helpers/isPOJO.js +12 -0
- package/lib/helpers/isSimpleValidator.js +2 -2
- package/lib/helpers/minimize.js +41 -0
- package/lib/helpers/model/applyDefaultsToPOJO.js +2 -2
- package/lib/helpers/model/applyHooks.js +72 -54
- package/lib/helpers/model/applyMethods.js +3 -3
- package/lib/helpers/model/applyStaticHooks.js +20 -50
- package/lib/helpers/model/castBulkWrite.js +278 -172
- package/lib/helpers/model/decorateBulkWriteResult.js +8 -0
- package/lib/helpers/model/discriminator.js +77 -21
- package/lib/helpers/omitUndefined.js +20 -0
- package/lib/helpers/parallelLimit.js +61 -34
- package/lib/helpers/path/setDottedPath.js +1 -1
- package/lib/helpers/pathTrie.js +167 -0
- package/lib/helpers/pluralize.js +5 -4
- package/lib/helpers/populate/assignRawDocsToIdStructure.js +12 -7
- package/lib/helpers/populate/assignVals.js +46 -21
- package/lib/helpers/populate/createPopulateQueryFilter.js +13 -5
- package/lib/helpers/populate/getModelsMapForPopulate.js +250 -108
- package/lib/helpers/populate/getSchemaTypes.js +27 -30
- package/lib/helpers/populate/getVirtual.js +31 -0
- package/lib/helpers/populate/markArraySubdocsPopulated.js +6 -4
- package/lib/helpers/populate/modelNamesFromRefPath.js +11 -5
- package/lib/helpers/populate/removeDeselectedForeignField.js +3 -2
- package/lib/helpers/populate/setInheritedReadOptions.js +21 -0
- package/lib/helpers/populate/setPopulatedVirtualValue.js +33 -0
- package/lib/helpers/populate/splitPopulateQuery.js +81 -0
- package/lib/helpers/printJestWarning.js +1 -1
- package/lib/helpers/processConnectionOptions.js +7 -2
- package/lib/helpers/projection/applyProjection.js +8 -2
- package/lib/helpers/projection/hasIncludedChildren.js +1 -1
- package/lib/helpers/projection/isExclusive.js +8 -6
- package/lib/helpers/projection/isInclusive.js +2 -1
- package/lib/helpers/projection/isPathExcluded.js +3 -3
- package/lib/helpers/projection/isPathSelectedInclusive.js +1 -11
- package/lib/helpers/projection/isSubpath.js +1 -1
- package/lib/helpers/projection/parseProjection.js +9 -4
- package/lib/helpers/query/applyGlobalOption.js +9 -9
- package/lib/helpers/query/cast$expr.js +52 -23
- package/lib/helpers/query/castFilterPath.js +22 -22
- package/lib/helpers/query/castUpdate.js +207 -79
- package/lib/helpers/query/cloneMongooseOptions.js +44 -0
- package/lib/helpers/query/getEmbeddedDiscriminatorPath.js +27 -13
- package/lib/helpers/query/handleImmutable.js +18 -2
- package/lib/helpers/query/handleReadPreferenceAliases.js +23 -0
- package/lib/helpers/query/sanitizeFilter.js +3 -2
- package/lib/helpers/query/selectPopulatedFields.js +13 -0
- package/lib/helpers/query/validOps.js +1 -22
- package/lib/helpers/schema/applyPlugins.js +2 -2
- package/lib/helpers/schema/applyReadConcern.js +20 -0
- package/lib/helpers/schema/applyWriteConcern.js +12 -3
- package/lib/helpers/schema/cleanPositionalOperators.js +5 -3
- package/lib/helpers/schema/getIndexes.js +20 -13
- package/lib/helpers/schema/getKeysInSchemaOrder.js +13 -16
- package/lib/helpers/schema/getPath.js +11 -3
- package/lib/helpers/schema/getSubdocumentStrictValue.js +32 -0
- package/lib/helpers/schema/handleIdOption.js +1 -1
- package/lib/helpers/schema/idGetter.js +7 -2
- package/lib/helpers/schema/merge.js +9 -1
- package/lib/helpers/schematype/getConditionalHandler.js +23 -0
- package/lib/helpers/schematype/handleImmutable.js +1 -1
- package/lib/helpers/setDefaultsOnInsert.js +85 -43
- package/lib/helpers/symbols.js +4 -4
- package/lib/helpers/timestamps/setDocumentTimestamps.js +2 -2
- package/lib/helpers/timestamps/setupTimestamps.js +69 -37
- package/lib/helpers/update/applyTimestampsToChildren.js +1 -1
- package/lib/helpers/update/applyTimestampsToUpdate.js +53 -37
- package/lib/helpers/update/castArrayFilters.js +68 -29
- package/lib/helpers/update/decorateUpdateWithVersionKey.js +35 -0
- package/lib/helpers/update/modifiedPaths.js +2 -2
- package/lib/helpers/update/removeUnusedArrayFilters.js +11 -2
- package/lib/helpers/updateValidators.js +87 -128
- package/lib/index.js +6 -1320
- package/lib/internal.js +7 -1
- package/lib/model.js +2587 -2618
- package/lib/modifiedPathsSnapshot.js +9 -0
- package/lib/mongoose.js +1456 -0
- package/lib/options/saveOptions.js +2 -0
- package/lib/options/{SchemaArrayOptions.js → schemaArrayOptions.js} +16 -5
- package/lib/options/{SchemaBufferOptions.js → schemaBufferOptions.js} +2 -2
- package/lib/options/{SchemaDateOptions.js → schemaDateOptions.js} +1 -1
- package/lib/options/{SchemaDocumentArrayOptions.js → schemaDocumentArrayOptions.js} +24 -1
- package/lib/options/{SchemaMapOptions.js → schemaMapOptions.js} +1 -1
- package/lib/options/{SchemaNumberOptions.js → schemaNumberOptions.js} +5 -5
- package/lib/options/{SchemaObjectIdOptions.js → schemaObjectIdOptions.js} +4 -4
- package/lib/options/{SchemaStringOptions.js → schemaStringOptions.js} +10 -10
- package/lib/options/schemaSubdocumentOptions.js +89 -0
- package/lib/options/{SchemaTypeOptions.js → schemaTypeOptions.js} +28 -14
- package/lib/options/schemaUnionOptions.js +32 -0
- package/lib/options/{VirtualOptions.js → virtualOptions.js} +13 -13
- package/lib/options.js +4 -1
- package/lib/plugins/index.js +0 -2
- package/lib/plugins/saveSubdocs.js +85 -50
- package/lib/plugins/sharding.js +43 -15
- package/lib/plugins/trackTransaction.js +46 -34
- package/lib/query.js +1844 -1909
- package/lib/{queryhelpers.js → queryHelpers.js} +184 -81
- package/lib/schema/array.js +229 -169
- package/lib/schema/bigint.js +281 -0
- package/lib/schema/boolean.js +90 -26
- package/lib/schema/buffer.js +119 -50
- package/lib/schema/date.js +102 -38
- package/lib/schema/decimal128.js +88 -37
- package/lib/schema/{documentarray.js → documentArray.js} +259 -151
- package/lib/schema/documentArrayElement.js +180 -0
- package/lib/schema/double.js +244 -0
- package/lib/schema/index.js +12 -19
- package/lib/schema/int32.js +288 -0
- package/lib/schema/map.js +129 -20
- package/lib/schema/mixed.js +40 -26
- package/lib/schema/number.js +128 -51
- package/lib/schema/{objectid.js → objectId.js} +89 -47
- package/lib/schema/operators/exists.js +1 -1
- package/lib/schema/operators/geospatial.js +2 -2
- package/lib/schema/operators/text.js +4 -4
- package/lib/schema/string.js +125 -66
- package/lib/schema/subdocument.js +443 -0
- package/lib/schema/symbols.js +2 -0
- package/lib/schema/union.js +167 -0
- package/lib/schema/uuid.js +90 -120
- package/lib/schema.js +1267 -388
- package/lib/{schematype.js → schemaType.js} +481 -246
- package/lib/standardSchema/convertErrorToIssues.js +20 -0
- package/lib/{statemachine.js → stateMachine.js} +66 -17
- package/lib/tracing.js +38 -0
- package/lib/types/array/index.js +13 -10
- package/lib/types/array/methods/index.js +243 -63
- package/lib/types/{ArraySubdocument.js → arraySubdocument.js} +35 -14
- package/lib/types/buffer.js +31 -14
- package/lib/types/decimal128.js +1 -1
- package/lib/types/{DocumentArray → documentArray}/index.js +13 -13
- package/lib/types/{DocumentArray → documentArray}/methods/index.js +197 -31
- package/lib/types/double.js +13 -0
- package/lib/types/index.js +5 -2
- package/lib/types/map.js +62 -25
- package/lib/types/objectid.js +2 -2
- package/lib/types/subdocument.js +79 -58
- package/lib/types/uuid.js +13 -0
- package/lib/utils.js +201 -155
- package/lib/{validoptions.js → validOptions.js} +10 -2
- package/lib/{virtualtype.js → virtualType.js} +47 -18
- package/package.json +75 -92
- package/types/aggregate.d.ts +31 -7
- package/types/augmentations.d.ts +2 -2
- package/types/collection.d.ts +21 -16
- package/types/connection.d.ts +82 -27
- package/types/cursor.d.ts +15 -10
- package/types/document.d.ts +137 -56
- package/types/error.d.ts +11 -6
- package/types/expressions.d.ts +33 -2
- package/types/index.d.ts +805 -190
- package/types/indexes.d.ts +85 -13
- package/types/inferhydrateddoctype.d.ts +151 -0
- package/types/inferrawdoctype.d.ts +201 -0
- package/types/inferschematype.d.ts +287 -128
- package/types/middlewares.d.ts +50 -7
- package/types/models.d.ts +1555 -268
- package/types/mongooseoptions.d.ts +56 -7
- package/types/pipelinestage.d.ts +42 -3
- package/types/populate.d.ts +63 -1
- package/types/query.d.ts +592 -255
- package/types/schemaoptions.d.ts +78 -12
- package/types/schematypes.d.ts +254 -65
- package/types/session.d.ts +0 -4
- package/types/tracing.d.ts +10 -0
- package/types/types.d.ts +25 -8
- package/types/utility.d.ts +329 -30
- package/types/validation.d.ts +19 -14
- package/types/virtuals.d.ts +10 -10
- package/.eslintrc.js +0 -232
- package/.mocharc.yml +0 -4
- package/browser.js +0 -8
- package/lgtm.yml +0 -12
- package/lib/browser.js +0 -158
- package/lib/browserDocument.js +0 -101
- package/lib/cursor/ChangeStream.js +0 -154
- package/lib/cursor/QueryCursor.js +0 -545
- package/lib/document_provider.js +0 -30
- package/lib/drivers/browser/ReadPreference.js +0 -7
- package/lib/drivers/browser/binary.js +0 -14
- package/lib/drivers/browser/decimal128.js +0 -7
- package/lib/drivers/browser/index.js +0 -16
- package/lib/drivers/browser/objectid.js +0 -29
- package/lib/drivers/node-mongodb-native/ReadPreference.js +0 -47
- package/lib/drivers/node-mongodb-native/binary.js +0 -10
- package/lib/drivers/node-mongodb-native/decimal128.js +0 -7
- package/lib/drivers/node-mongodb-native/objectid.js +0 -16
- package/lib/error/disconnected.js +0 -33
- package/lib/helpers/printStrictQueryWarning.js +0 -11
- package/lib/helpers/promiseOrCallback.js +0 -55
- package/lib/helpers/query/applyQueryMiddleware.js +0 -79
- package/lib/helpers/query/completeMany.js +0 -52
- package/lib/helpers/query/wrapThunk.js +0 -36
- package/lib/options/SchemaSubdocumentOptions.js +0 -42
- package/lib/options/removeOptions.js +0 -14
- package/lib/plugins/removeSubdocs.js +0 -31
- package/lib/plugins/validateBeforeSave.js +0 -45
- package/lib/promise_provider.js +0 -49
- package/lib/schema/DocumentArrayElement.js +0 -100
- package/lib/schema/SubdocumentPath.js +0 -369
- package/scripts/build-browser.js +0 -18
- package/scripts/create-tarball.js +0 -7
- package/scripts/generateSearch.js +0 -154
- package/scripts/tsc-diagnostics-check.js +0 -15
- package/tools/auth.js +0 -31
- package/tools/repl.js +0 -35
- package/tools/sharded.js +0 -46
- package/tsconfig.json +0 -9
- /package/lib/{connectionstate.js → connectionState.js} +0 -0
- /package/lib/helpers/populate/{SkipPopulateValue.js → skipPopulateValue.js} +0 -0
- /package/lib/options/{PopulateOptions.js → populateOptions.js} +0 -0
- /package/lib/types/{DocumentArray → documentArray}/isMongooseDocumentArray.js +0 -0
|
@@ -1,19 +1,29 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
InferSchemaType,
|
|
4
|
-
SchemaType,
|
|
5
|
-
SchemaTypeOptions,
|
|
6
|
-
TypeKeyBaseType,
|
|
7
|
-
Types,
|
|
8
|
-
NumberSchemaDefinition,
|
|
9
|
-
StringSchemaDefinition,
|
|
2
|
+
AnyArray,
|
|
10
3
|
BooleanSchemaDefinition,
|
|
4
|
+
BigintSchemaDefinition,
|
|
5
|
+
BufferSchemaDefinition,
|
|
11
6
|
DateSchemaDefinition,
|
|
12
|
-
|
|
7
|
+
Decimal128SchemaDefinition,
|
|
8
|
+
DefaultSchemaOptions,
|
|
13
9
|
DefaultTypeKey,
|
|
14
|
-
|
|
10
|
+
DoubleSchemaDefinition,
|
|
11
|
+
IfAny,
|
|
15
12
|
IfEquals,
|
|
16
|
-
|
|
13
|
+
InferSchemaType,
|
|
14
|
+
IsItRecordAndNotAny,
|
|
15
|
+
MapSchemaDefinition,
|
|
16
|
+
MergeType,
|
|
17
|
+
NumberSchemaDefinition,
|
|
18
|
+
ObjectIdSchemaDefinition,
|
|
19
|
+
ObtainDocumentType,
|
|
20
|
+
Schema,
|
|
21
|
+
SchemaType,
|
|
22
|
+
SchemaTypeOptions,
|
|
23
|
+
StringSchemaDefinition,
|
|
24
|
+
Types,
|
|
25
|
+
UnionSchemaDefinition,
|
|
26
|
+
UuidSchemaDefinition
|
|
17
27
|
} from 'mongoose';
|
|
18
28
|
|
|
19
29
|
declare module 'mongoose' {
|
|
@@ -24,11 +34,23 @@ declare module 'mongoose' {
|
|
|
24
34
|
* @param {EnforcedDocType} EnforcedDocType A generic type enforced by user "provided before schema constructor".
|
|
25
35
|
* @param {TypeKey} TypeKey A generic of literal string type."Refers to the property used for path type definition".
|
|
26
36
|
*/
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
37
|
+
type ObtainDocumentType<
|
|
38
|
+
DocDefinition,
|
|
39
|
+
EnforcedDocType = any,
|
|
40
|
+
TSchemaOptions extends Record<any, any> = DefaultSchemaOptions
|
|
41
|
+
> =
|
|
42
|
+
IsItRecordAndNotAny<EnforcedDocType> extends true ? EnforcedDocType
|
|
43
|
+
: {
|
|
44
|
+
[K in keyof (RequiredPaths<DocDefinition, TSchemaOptions['typeKey']> &
|
|
45
|
+
OptionalPaths<DocDefinition, TSchemaOptions['typeKey']>)]: IsPathRequired<
|
|
46
|
+
DocDefinition[K],
|
|
47
|
+
TSchemaOptions['typeKey']
|
|
48
|
+
> extends true ?
|
|
49
|
+
ObtainDocumentPathType<DocDefinition[K], TSchemaOptions['typeKey']>
|
|
50
|
+
: PathAllowsNull<DocDefinition[K]> extends true ?
|
|
51
|
+
ObtainDocumentPathType<DocDefinition[K], TSchemaOptions['typeKey']> | null
|
|
52
|
+
: ObtainDocumentPathType<DocDefinition[K], TSchemaOptions['typeKey']>;
|
|
53
|
+
};
|
|
32
54
|
|
|
33
55
|
/**
|
|
34
56
|
* @summary Obtains document schema type from Schema instance.
|
|
@@ -39,47 +61,106 @@ declare module 'mongoose' {
|
|
|
39
61
|
* // result
|
|
40
62
|
* type UserType = {userName?: string}
|
|
41
63
|
*/
|
|
42
|
-
type InferSchemaType<TSchema> = IfAny<TSchema, any, ObtainSchemaGeneric<TSchema, 'DocType'>>;
|
|
64
|
+
export type InferSchemaType<TSchema> = IfAny<TSchema, any, ObtainSchemaGeneric<TSchema, 'DocType'>>;
|
|
65
|
+
|
|
66
|
+
export type DefaultIdVirtual = { id: string };
|
|
67
|
+
export type AddDefaultId<DocType, TVirtuals, TSchemaOptions> = (DocType extends { id: any } ? TVirtuals : TSchemaOptions extends { id: false } ? TVirtuals : TVirtuals & { id: string });
|
|
43
68
|
|
|
44
69
|
/**
|
|
45
70
|
* @summary Obtains schema Generic type by using generic alias.
|
|
46
71
|
* @param {TSchema} TSchema A generic of schema type instance.
|
|
47
72
|
* @param {alias} alias Targeted generic alias.
|
|
48
73
|
*/
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
74
|
+
type ObtainSchemaGeneric<
|
|
75
|
+
TSchema,
|
|
76
|
+
alias extends
|
|
77
|
+
| 'EnforcedDocType'
|
|
78
|
+
| 'M'
|
|
79
|
+
| 'TInstanceMethods'
|
|
80
|
+
| 'TQueryHelpers'
|
|
81
|
+
| 'TVirtuals'
|
|
82
|
+
| 'TStaticMethods'
|
|
83
|
+
| 'TSchemaOptions'
|
|
84
|
+
| 'DocType'
|
|
85
|
+
| 'THydratedDocumentType'
|
|
86
|
+
| 'TSchemaDefinition'
|
|
87
|
+
| 'TLeanResultType'
|
|
88
|
+
> =
|
|
89
|
+
TSchema extends (
|
|
90
|
+
Schema<
|
|
91
|
+
infer EnforcedDocType,
|
|
92
|
+
infer M,
|
|
93
|
+
infer TInstanceMethods,
|
|
94
|
+
infer TQueryHelpers,
|
|
95
|
+
infer TVirtuals,
|
|
96
|
+
infer TStaticMethods,
|
|
97
|
+
infer TSchemaOptions,
|
|
98
|
+
infer DocType,
|
|
99
|
+
infer THydratedDocumentType,
|
|
100
|
+
infer TSchemaDefinition,
|
|
101
|
+
infer TLeanResultType
|
|
102
|
+
>
|
|
103
|
+
) ?
|
|
104
|
+
{
|
|
105
|
+
EnforcedDocType: EnforcedDocType;
|
|
106
|
+
M: M;
|
|
107
|
+
TInstanceMethods: IfEquals<TInstanceMethods, {}, TSchemaOptions extends { methods: infer M } ? M : {}, TInstanceMethods>;
|
|
108
|
+
TQueryHelpers: IfEquals<TQueryHelpers, {}, TSchemaOptions extends { query: infer Q } ? Q : {}, TQueryHelpers>;
|
|
109
|
+
TVirtuals: AddDefaultId<DocType, IfEquals<TVirtuals, {}, TSchemaOptions extends { virtuals: infer V } ? V : {}, TVirtuals>, TSchemaOptions>;
|
|
110
|
+
TStaticMethods: IfEquals<TStaticMethods, {}, TSchemaOptions extends { statics: infer S } ? S : {}, TStaticMethods>;
|
|
111
|
+
TSchemaOptions: TSchemaOptions;
|
|
112
|
+
DocType: DocType;
|
|
113
|
+
THydratedDocumentType: THydratedDocumentType;
|
|
114
|
+
TSchemaDefinition: TSchemaDefinition;
|
|
115
|
+
TLeanResultType: TLeanResultType;
|
|
116
|
+
}[alias]
|
|
117
|
+
: unknown;
|
|
118
|
+
|
|
119
|
+
type TypesAreEqual<A, B> = [A] extends [B] ? [B] extends [A] ? true : false : false;
|
|
120
|
+
|
|
121
|
+
type ResolveSchemaOptions<T> =
|
|
122
|
+
keyof T extends never ? DefaultSchemaOptions :
|
|
123
|
+
TypesAreEqual<T, DefaultSchemaOptions> extends true ? DefaultSchemaOptions :
|
|
124
|
+
MergeType<DefaultSchemaOptions, T>;
|
|
125
|
+
|
|
126
|
+
/*!
|
|
127
|
+
* ResolveVirtuals resolves the virtuals option from the schema options.
|
|
128
|
+
* Adds the default `id` virtual if it is not disabled in schema options or
|
|
129
|
+
* overwritten in the RawDocType.
|
|
130
|
+
*/
|
|
131
|
+
type ResolveVirtuals<TSchemaOptions, RawDocType> =
|
|
132
|
+
ResolveSchemaOptions<TSchemaOptions> extends { virtuals: infer V }
|
|
133
|
+
? AddDefaultId<RawDocType, V, ResolveSchemaOptions<TSchemaOptions>>
|
|
134
|
+
: {};
|
|
65
135
|
|
|
66
136
|
type ApplySchemaOptions<T, O = DefaultSchemaOptions> = ResolveTimestamps<T, O>;
|
|
67
137
|
|
|
68
|
-
type
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
138
|
+
type DefaultTimestampProps = {
|
|
139
|
+
createdAt: NativeDate;
|
|
140
|
+
updatedAt: NativeDate;
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
type ResolveTimestamps<T, O> =
|
|
144
|
+
O extends { timestamps?: false } ? T
|
|
145
|
+
: O extends { timestamps: infer TimestampOptions } ?
|
|
146
|
+
TimestampOptions extends true ? T & DefaultTimestampProps
|
|
147
|
+
: TimestampOptions extends SchemaTimestampsConfig ?
|
|
148
|
+
Show<
|
|
149
|
+
T & {
|
|
150
|
+
[K in keyof TimestampOptions & keyof DefaultTimestampProps as TimestampOptions[K] extends true ? K
|
|
151
|
+
: TimestampOptions[K] & string]: NativeDate;
|
|
152
|
+
}
|
|
153
|
+
>
|
|
154
|
+
: T
|
|
75
155
|
: T;
|
|
76
156
|
}
|
|
77
157
|
|
|
78
|
-
type
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
158
|
+
type RequiredPropertyDefinition =
|
|
159
|
+
| {
|
|
160
|
+
required: true | string | [true, string | undefined] | { isRequired: true };
|
|
161
|
+
}
|
|
162
|
+
| ArrayConstructor
|
|
163
|
+
| any[];
|
|
83
164
|
|
|
84
165
|
/**
|
|
85
166
|
* @summary Checks if a document path is required or optional.
|
|
@@ -87,28 +168,21 @@ type IsPathDefaultUndefined<PathType> = PathType extends { default: undefined }
|
|
|
87
168
|
* @param {TypeKey} TypeKey A generic of literal string type."Refers to the property used for path type definition".
|
|
88
169
|
*/
|
|
89
170
|
type IsPathRequired<P, TypeKey extends string = DefaultTypeKey> =
|
|
90
|
-
P extends
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
: true
|
|
100
|
-
: P extends (Record<TypeKey, any>)
|
|
101
|
-
? P extends { default: any }
|
|
102
|
-
? IfEquals<P['default'], undefined, false, true>
|
|
103
|
-
: false
|
|
104
|
-
: false;
|
|
171
|
+
P extends RequiredPropertyDefinition ? true
|
|
172
|
+
: P extends { required: boolean } ?
|
|
173
|
+
P extends { required: false } ?
|
|
174
|
+
false
|
|
175
|
+
: true
|
|
176
|
+
: P extends { default: undefined | null | ((...args: any[]) => undefined) | ((...args: any[]) => null) } ? false
|
|
177
|
+
: P extends { default: any } ? true
|
|
178
|
+
: P extends Record<TypeKey, ArrayConstructor | any[]> ? true
|
|
179
|
+
: false;
|
|
105
180
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
type PathWithTypePropertyBaseType<TypeKey extends string = DefaultTypeKey> = { [k in TypeKey]: any };
|
|
181
|
+
// Internal type used to efficiently check for never or any types
|
|
182
|
+
// can be efficiently checked like:
|
|
183
|
+
// `[T] extends [neverOrAny] ? T : ...`
|
|
184
|
+
// to avoid edge cases
|
|
185
|
+
type neverOrAny = ' ~neverOrAny~';
|
|
112
186
|
|
|
113
187
|
/**
|
|
114
188
|
* @summary A Utility to obtain schema's required path keys.
|
|
@@ -116,9 +190,7 @@ type PathWithTypePropertyBaseType<TypeKey extends string = DefaultTypeKey> = { [
|
|
|
116
190
|
* @param {TypeKey} TypeKey A generic of literal string type."Refers to the property used for path type definition".
|
|
117
191
|
* @returns required paths keys of document definition.
|
|
118
192
|
*/
|
|
119
|
-
type RequiredPathKeys<T, TypeKey extends string = DefaultTypeKey> =
|
|
120
|
-
[K in keyof T]: IsPathRequired<T[K], TypeKey> extends true ? IfEquals<T[K], any, never, K> : never;
|
|
121
|
-
}[keyof T];
|
|
193
|
+
type RequiredPathKeys<T, TypeKey extends string = DefaultTypeKey> = Exclude<keyof T, OptionalPathKeys<T, TypeKey>>;
|
|
122
194
|
|
|
123
195
|
/**
|
|
124
196
|
* @summary A Utility to obtain schema's required paths.
|
|
@@ -126,9 +198,10 @@ type RequiredPathKeys<T, TypeKey extends string = DefaultTypeKey> = {
|
|
|
126
198
|
* @param {TypeKey} TypeKey A generic of literal string type."Refers to the property used for path type definition".
|
|
127
199
|
* @returns a record contains required paths with the corresponding type.
|
|
128
200
|
*/
|
|
129
|
-
type RequiredPaths<T, TypeKey extends string = DefaultTypeKey> =
|
|
130
|
-
[K in
|
|
131
|
-
|
|
201
|
+
type RequiredPaths<T, TypeKey extends string = DefaultTypeKey> = Pick<
|
|
202
|
+
{ -readonly [K in keyof T]: T[K] },
|
|
203
|
+
RequiredPathKeys<T, TypeKey>
|
|
204
|
+
>;
|
|
132
205
|
|
|
133
206
|
/**
|
|
134
207
|
* @summary A Utility to obtain schema's optional path keys.
|
|
@@ -146,9 +219,21 @@ type OptionalPathKeys<T, TypeKey extends string = DefaultTypeKey> = {
|
|
|
146
219
|
* @param {TypeKey} TypeKey A generic of literal string type."Refers to the property used for path type definition".
|
|
147
220
|
* @returns a record contains optional paths with the corresponding type.
|
|
148
221
|
*/
|
|
149
|
-
type OptionalPaths<T, TypeKey extends string = DefaultTypeKey> =
|
|
150
|
-
[K in
|
|
151
|
-
|
|
222
|
+
type OptionalPaths<T, TypeKey extends string = DefaultTypeKey> = Pick<
|
|
223
|
+
{ -readonly [K in keyof T]?: T[K] },
|
|
224
|
+
OptionalPathKeys<T, TypeKey>
|
|
225
|
+
>;
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* @summary Checks if a document path allows `null` values.
|
|
229
|
+
* @param {P} P Document path.
|
|
230
|
+
*/
|
|
231
|
+
export type PathAllowsNull<P> = P extends { allowNull: false } ? false : true;
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* @summary Allows users to optionally choose their own type for a schema field for stronger typing.
|
|
235
|
+
*/
|
|
236
|
+
type TypeHint<T> = T extends { __typehint: infer U } ? U : never;
|
|
152
237
|
|
|
153
238
|
/**
|
|
154
239
|
* @summary Obtains schema Path type.
|
|
@@ -157,16 +242,73 @@ type OptionalPaths<T, TypeKey extends string = DefaultTypeKey> = {
|
|
|
157
242
|
* @param {TypeKey} TypeKey A generic refers to document definition.
|
|
158
243
|
*/
|
|
159
244
|
type ObtainDocumentPathType<PathValueType, TypeKey extends string = DefaultTypeKey> = ResolvePathType<
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
245
|
+
TypeKey extends keyof PathValueType ?
|
|
246
|
+
TypeKey extends keyof PathValueType[TypeKey] ?
|
|
247
|
+
PathValueType
|
|
248
|
+
: PathValueType[TypeKey]
|
|
249
|
+
: PathValueType,
|
|
250
|
+
TypeKey extends keyof PathValueType ?
|
|
251
|
+
TypeKey extends keyof PathValueType[TypeKey] ?
|
|
252
|
+
{}
|
|
253
|
+
: Omit<PathValueType, TypeKey>
|
|
254
|
+
: {},
|
|
255
|
+
TypeKey,
|
|
256
|
+
TypeHint<PathValueType>,
|
|
257
|
+
DiscriminatorEnumType<PathValueType>
|
|
163
258
|
>;
|
|
164
259
|
|
|
165
260
|
/**
|
|
166
261
|
* @param {T} T A generic refers to string path enums.
|
|
167
262
|
* @returns Path enum values type as literal strings or string.
|
|
168
263
|
*/
|
|
169
|
-
type PathEnumOrString<T extends SchemaTypeOptions<string>['enum']> =
|
|
264
|
+
type PathEnumOrString<T extends SchemaTypeOptions<string>['enum']> =
|
|
265
|
+
T extends ReadonlyArray<infer E> ? E
|
|
266
|
+
: T extends { values: any } ? PathEnumOrString<T['values']>
|
|
267
|
+
: T extends Record<string, infer V> ? V
|
|
268
|
+
: string;
|
|
269
|
+
|
|
270
|
+
type UnionToType<T extends readonly any[]> = T[number] extends infer U
|
|
271
|
+
? ResolvePathType<U>
|
|
272
|
+
: never;
|
|
273
|
+
|
|
274
|
+
type ResolveDiscriminatorPathType<TBaseSchema extends Schema, TDiscriminators> =
|
|
275
|
+
IfAny<TDiscriminators, never,
|
|
276
|
+
TDiscriminators extends Record<string, any> ?
|
|
277
|
+
TDiscriminators[keyof TDiscriminators] extends Schema ?
|
|
278
|
+
MergeType<InferSchemaType<TBaseSchema>, InferSchemaType<TDiscriminators[keyof TDiscriminators]>>
|
|
279
|
+
: never
|
|
280
|
+
: never>;
|
|
281
|
+
|
|
282
|
+
type DiscriminatorEnumType<T> = string extends keyof T ? never
|
|
283
|
+
: number extends keyof T ? never
|
|
284
|
+
: T extends { type: infer BaseType; discriminators: infer TDiscriminators } ?
|
|
285
|
+
IfAny<BaseType, never, BaseType extends Schema ?
|
|
286
|
+
ResolveDiscriminatorPathType<BaseType, TDiscriminators>
|
|
287
|
+
: never>
|
|
288
|
+
: never;
|
|
289
|
+
|
|
290
|
+
type IsSchemaTypeFromBuiltinClass<T> =
|
|
291
|
+
T extends typeof String ? true
|
|
292
|
+
: unknown extends Buffer ? false
|
|
293
|
+
: T extends typeof Number ? true
|
|
294
|
+
: T extends typeof Boolean ? true
|
|
295
|
+
: T extends typeof Buffer ? true
|
|
296
|
+
: T extends typeof Schema.Types.ObjectId ? true
|
|
297
|
+
: T extends typeof Schema.Types.UUID ? true
|
|
298
|
+
: T extends typeof Schema.Types.Decimal128 ? true
|
|
299
|
+
: T extends typeof Schema.Types.Int32 ? true
|
|
300
|
+
: T extends typeof Schema.Types.String ? true
|
|
301
|
+
: T extends typeof Schema.Types.Number ? true
|
|
302
|
+
: T extends typeof Schema.Types.Date ? true
|
|
303
|
+
: T extends typeof Schema.Types.Double ? true
|
|
304
|
+
: T extends typeof Schema.Types.Boolean ? true
|
|
305
|
+
: T extends Types.ObjectId ? true
|
|
306
|
+
: T extends Types.Decimal128 ? true
|
|
307
|
+
: T extends NativeDate ? true
|
|
308
|
+
: T extends typeof Schema.Types.Mixed ? true
|
|
309
|
+
: T extends Types.UUID ? true
|
|
310
|
+
: T extends Buffer ? true
|
|
311
|
+
: false;
|
|
170
312
|
|
|
171
313
|
/**
|
|
172
314
|
* @summary Resolve path type by returning the corresponding type.
|
|
@@ -175,54 +317,71 @@ type PathEnumOrString<T extends SchemaTypeOptions<string>['enum']> = T extends R
|
|
|
175
317
|
* @param {TypeKey} TypeKey A generic of literal string type."Refers to the property used for path type definition".
|
|
176
318
|
* @returns Number, "Number" or "number" will be resolved to number type.
|
|
177
319
|
*/
|
|
178
|
-
type ResolvePathType<
|
|
179
|
-
PathValueType
|
|
180
|
-
|
|
181
|
-
|
|
320
|
+
type ResolvePathType<
|
|
321
|
+
PathValueType,
|
|
322
|
+
Options extends SchemaTypeOptions<PathValueType> = {},
|
|
323
|
+
TypeKey extends string = DefaultSchemaOptions['typeKey'],
|
|
324
|
+
TypeHint = never,
|
|
325
|
+
TDiscriminatorEnumType = never
|
|
326
|
+
> = [TypeHint] extends [never]
|
|
327
|
+
? [TDiscriminatorEnumType] extends [never]
|
|
328
|
+
? PathValueType extends Schema ?
|
|
329
|
+
InferSchemaType<PathValueType>
|
|
330
|
+
: PathValueType extends AnyArray<infer Item> ?
|
|
331
|
+
[Item] extends [never]
|
|
332
|
+
? any[]
|
|
333
|
+
: Item extends Schema ?
|
|
182
334
|
// If Item is a schema, infer its type.
|
|
183
|
-
Types.DocumentArray<InferSchemaType<Item>>
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
335
|
+
Types.DocumentArray<InferSchemaType<Item>>
|
|
336
|
+
: Item extends Record<TypeKey, any> ?
|
|
337
|
+
Item[TypeKey] extends Schema ?
|
|
338
|
+
Types.DocumentArray<
|
|
339
|
+
[DiscriminatorEnumType<Item>] extends [never] ? InferSchemaType<Item[TypeKey]> : DiscriminatorEnumType<Item>
|
|
340
|
+
>
|
|
341
|
+
: Item[TypeKey] extends Function | String ?
|
|
342
|
+
// If Item has a type key that's a string or a callable, it must be a scalar,
|
|
343
|
+
// so we can directly obtain its path type.
|
|
344
|
+
ObtainDocumentPathType<Item, TypeKey>[]
|
|
345
|
+
: // If the type key isn't callable, then this is an array of objects, in which case
|
|
346
|
+
// we need to call ObtainDocumentType to correctly infer its type.
|
|
347
|
+
Types.DocumentArray<ObtainDocumentType<Item, any, { typeKey: TypeKey }>>
|
|
348
|
+
: IsSchemaTypeFromBuiltinClass<Item> extends true ? ResolvePathType<Item, { enum: Exclude<Options['enum'], undefined> }, TypeKey>[]
|
|
349
|
+
: IsItRecordAndNotAny<Item> extends true ?
|
|
350
|
+
Item extends Record<string, never> ?
|
|
192
351
|
ObtainDocumentPathType<Item, TypeKey>[]
|
|
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
|
-
|
|
352
|
+
: Types.DocumentArray<ObtainDocumentType<Item, any, { typeKey: TypeKey }>>
|
|
353
|
+
: ObtainDocumentPathType<Item, TypeKey>[]
|
|
354
|
+
: PathValueType extends StringSchemaDefinition ? PathEnumOrString<Options['enum']>
|
|
355
|
+
: IfEquals<PathValueType, String> extends true ? PathEnumOrString<Options['enum']>
|
|
356
|
+
: PathValueType extends NumberSchemaDefinition ?
|
|
357
|
+
Options['enum'] extends ReadonlyArray<any> ?
|
|
358
|
+
Options['enum'][number]
|
|
359
|
+
: number
|
|
360
|
+
: PathValueType extends DateSchemaDefinition ? NativeDate
|
|
361
|
+
: PathValueType extends UuidSchemaDefinition ? Types.UUID
|
|
362
|
+
: PathValueType extends BufferSchemaDefinition ? Buffer
|
|
363
|
+
: PathValueType extends BooleanSchemaDefinition ? boolean
|
|
364
|
+
: PathValueType extends ObjectIdSchemaDefinition ? Types.ObjectId
|
|
365
|
+
: PathValueType extends Decimal128SchemaDefinition ? Types.Decimal128
|
|
366
|
+
: PathValueType extends BigintSchemaDefinition ? bigint
|
|
367
|
+
: PathValueType extends DoubleSchemaDefinition ? Types.Double
|
|
368
|
+
: PathValueType extends MapSchemaDefinition ? Map<string, ObtainDocumentPathType<Options['of']>>
|
|
369
|
+
: PathValueType extends UnionSchemaDefinition ?
|
|
370
|
+
Options['of'] extends AnyArray<infer U> ? ResolvePathType<U>
|
|
371
|
+
: never
|
|
372
|
+
: PathValueType extends ArrayConstructor ? any[]
|
|
373
|
+
: PathValueType extends typeof Schema.Types.Mixed ? any
|
|
374
|
+
: PathValueType extends ObjectConstructor ? any
|
|
375
|
+
: IfEquals<PathValueType, {}> extends true ? any
|
|
376
|
+
: PathValueType extends typeof SchemaType ? PathValueType['prototype']
|
|
377
|
+
: PathValueType extends Record<string, any> ?
|
|
378
|
+
ObtainDocumentType<
|
|
379
|
+
PathValueType,
|
|
380
|
+
any,
|
|
381
|
+
{
|
|
382
|
+
typeKey: TypeKey;
|
|
383
|
+
}
|
|
384
|
+
>
|
|
385
|
+
: unknown
|
|
386
|
+
: TDiscriminatorEnumType
|
|
387
|
+
: TypeHint;
|
package/types/middlewares.d.ts
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
1
|
declare module 'mongoose' {
|
|
2
|
+
import Kareem = require('kareem');
|
|
2
3
|
|
|
3
|
-
type
|
|
4
|
-
|
|
5
|
-
type
|
|
4
|
+
type MongooseQueryAndDocumentMiddleware = 'updateOne' | 'deleteOne';
|
|
5
|
+
|
|
6
|
+
type MongooseDistinctDocumentMiddleware = 'save' | 'validate';
|
|
7
|
+
type MongooseDocumentMiddleware = MongooseDistinctDocumentMiddleware | MongooseQueryAndDocumentMiddleware;
|
|
8
|
+
|
|
9
|
+
type MongooseRawResultQueryMiddleware = 'findOneAndUpdate' | 'findOneAndReplace' | 'findOneAndDelete';
|
|
10
|
+
type MongooseDistinctQueryMiddleware = 'estimatedDocumentCount' | 'countDocuments' | 'deleteMany' | 'distinct' | 'find' | 'findOne' | 'findOneAndDelete' | 'findOneAndReplace' | 'findOneAndUpdate' | 'replaceOne' | 'updateMany';
|
|
11
|
+
|
|
12
|
+
type MongooseDefaultQueryMiddleware = MongooseDistinctQueryMiddleware | 'updateOne' | 'deleteOne';
|
|
13
|
+
type MongooseQueryMiddleware = MongooseDistinctQueryMiddleware | MongooseQueryAndDocumentMiddleware;
|
|
14
|
+
|
|
15
|
+
type MongooseQueryOrDocumentMiddleware = MongooseDistinctQueryMiddleware|MongooseDistinctDocumentMiddleware|MongooseQueryAndDocumentMiddleware;
|
|
6
16
|
|
|
7
17
|
type MiddlewareOptions = {
|
|
8
18
|
/**
|
|
@@ -24,9 +34,42 @@ declare module 'mongoose' {
|
|
|
24
34
|
type SchemaPreOptions = MiddlewareOptions;
|
|
25
35
|
type SchemaPostOptions = MiddlewareOptions;
|
|
26
36
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
37
|
+
interface SkipMiddlewareOptions {
|
|
38
|
+
/** If `false`, skip pre middleware. */
|
|
39
|
+
pre?: boolean;
|
|
40
|
+
/** If `false`, skip post middleware. */
|
|
41
|
+
post?: boolean;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
interface SupportsMiddlewareOption {
|
|
45
|
+
/**
|
|
46
|
+
* Set to `true` to let callers skip this custom static's or method's middleware
|
|
47
|
+
* by passing `{ middleware: false }` as the last argument.
|
|
48
|
+
* See [skipping middleware for custom statics and methods](https://mongoosejs.com/docs/middleware.html#skip-custom-statics-and-methods).
|
|
49
|
+
*/
|
|
50
|
+
supportsMiddlewareOption?: boolean;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
type PreMiddlewareFunction<ThisType = any> = (
|
|
54
|
+
this: ThisType,
|
|
55
|
+
opts?: Record<string, any>
|
|
56
|
+
) => void | Promise<void> | Kareem.SkipWrappedFunction;
|
|
57
|
+
type PreDeleteOneMiddlewareFunction<ThisType = any> = (
|
|
58
|
+
this: ThisType,
|
|
59
|
+
doc: ThisType,
|
|
60
|
+
opts?: Record<string, any>
|
|
61
|
+
) => void | Promise<void> | Kareem.SkipWrappedFunction;
|
|
62
|
+
type PreUpdateOneMiddlewareFunction<ThisType = any> = (
|
|
63
|
+
this: ThisType,
|
|
64
|
+
doc: ThisType,
|
|
65
|
+
update?: Record<string, any>,
|
|
66
|
+
opts?: Record<string, any>
|
|
67
|
+
) => void | Promise<void> | Kareem.SkipWrappedFunction;
|
|
68
|
+
type PreSaveMiddlewareFunction<ThisType = any> = (
|
|
69
|
+
this: ThisType,
|
|
70
|
+
opts: SaveOptions
|
|
71
|
+
) => void | Promise<void> | Kareem.SkipWrappedFunction;
|
|
72
|
+
type PostMiddlewareFunction<ThisType = any, ResType = any> = (this: ThisType, res: ResType, next: CallbackWithoutResultAndOptionalError) => void | Promise<void> | Kareem.OverwriteResult;
|
|
30
73
|
type ErrorHandlingMiddlewareFunction<ThisType = any, ResType = any> = (this: ThisType, err: NativeError, res: ResType, next: CallbackWithoutResultAndOptionalError) => void;
|
|
31
|
-
type ErrorHandlingMiddlewareWithOption<ThisType = any, ResType = any> = (this: ThisType, err: NativeError, res: ResType | null, next: CallbackWithoutResultAndOptionalError) => void | Promise<void
|
|
74
|
+
type ErrorHandlingMiddlewareWithOption<ThisType = any, ResType = any> = (this: ThisType, err: NativeError, res: ResType | null, next: CallbackWithoutResultAndOptionalError) => void | Promise<void> | Kareem.OverwriteResult;
|
|
32
75
|
}
|