@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
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const ValidationError = require('../error/validation');
|
|
4
|
+
|
|
5
|
+
module.exports = function convertErrorToIssues(error) {
|
|
6
|
+
if (error instanceof ValidationError) {
|
|
7
|
+
return Object.keys(error.errors).map(path => {
|
|
8
|
+
const err = error.errors[path];
|
|
9
|
+
return {
|
|
10
|
+
message: err.message,
|
|
11
|
+
path: path.split('.').map(part => {
|
|
12
|
+
const num = +part;
|
|
13
|
+
return Number.isInteger(num) && String(num) === part ? num : part;
|
|
14
|
+
})
|
|
15
|
+
};
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return [{ message: error.message }];
|
|
20
|
+
};
|
|
@@ -25,8 +25,7 @@ const StateMachine = module.exports = exports = function StateMachine() {
|
|
|
25
25
|
* methods named after each state. These transition methods
|
|
26
26
|
* place their path argument into the given state.
|
|
27
27
|
*
|
|
28
|
-
* @param {
|
|
29
|
-
* @param {String} [state]
|
|
28
|
+
* @param {...string} state one or more state names
|
|
30
29
|
* @return {Function} subclass constructor
|
|
31
30
|
* @api private
|
|
32
31
|
*/
|
|
@@ -35,12 +34,12 @@ StateMachine.ctor = function() {
|
|
|
35
34
|
const states = [...arguments];
|
|
36
35
|
|
|
37
36
|
const ctor = function() {
|
|
38
|
-
StateMachine.apply(this, arguments);
|
|
39
37
|
this.paths = {};
|
|
40
38
|
this.states = {};
|
|
41
39
|
};
|
|
42
40
|
|
|
43
41
|
ctor.prototype = new StateMachine();
|
|
42
|
+
ctor.prototype.constructor = ctor;
|
|
44
43
|
|
|
45
44
|
ctor.prototype.stateNames = states;
|
|
46
45
|
|
|
@@ -65,12 +64,43 @@ StateMachine.ctor = function() {
|
|
|
65
64
|
*/
|
|
66
65
|
|
|
67
66
|
StateMachine.prototype._changeState = function _changeState(path, nextState) {
|
|
68
|
-
const
|
|
69
|
-
if (
|
|
67
|
+
const prevState = this.paths[path];
|
|
68
|
+
if (prevState === nextState) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (prevState !== undefined) {
|
|
72
|
+
const prevBucket = this.states[prevState];
|
|
73
|
+
if (prevBucket) delete prevBucket[path];
|
|
74
|
+
}
|
|
70
75
|
|
|
71
76
|
this.paths[path] = nextState;
|
|
72
|
-
|
|
73
|
-
|
|
77
|
+
let bucket = this.states[nextState];
|
|
78
|
+
if (bucket == null) {
|
|
79
|
+
bucket = this.states[nextState] = {};
|
|
80
|
+
}
|
|
81
|
+
bucket[path] = true;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
/*!
|
|
85
|
+
* ignore
|
|
86
|
+
*/
|
|
87
|
+
|
|
88
|
+
StateMachine.prototype.clearAllExcept = function clearAllExcept(state) {
|
|
89
|
+
// State buckets are created lazily, so `states[state]` may not exist yet.
|
|
90
|
+
const bucket = this.states[state];
|
|
91
|
+
const keys = bucket == null ? [] : Object.keys(bucket);
|
|
92
|
+
if (keys.length === 0) {
|
|
93
|
+
this.paths = {};
|
|
94
|
+
this.states = {};
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
this.paths = {};
|
|
98
|
+
for (const path of keys) {
|
|
99
|
+
this.paths[path] = state;
|
|
100
|
+
}
|
|
101
|
+
this.states = {
|
|
102
|
+
[state]: this.states[state]
|
|
103
|
+
};
|
|
74
104
|
};
|
|
75
105
|
|
|
76
106
|
/*!
|
|
@@ -82,13 +112,14 @@ StateMachine.prototype.clear = function clear(state) {
|
|
|
82
112
|
return;
|
|
83
113
|
}
|
|
84
114
|
const keys = Object.keys(this.states[state]);
|
|
115
|
+
if (keys.length === 0) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
this.states[state] = {};
|
|
85
119
|
let i = keys.length;
|
|
86
|
-
let path;
|
|
87
120
|
|
|
88
121
|
while (i--) {
|
|
89
|
-
|
|
90
|
-
delete this.states[state][path];
|
|
91
|
-
delete this.paths[path];
|
|
122
|
+
delete this.paths[keys[i]];
|
|
92
123
|
}
|
|
93
124
|
};
|
|
94
125
|
|
|
@@ -121,7 +152,7 @@ StateMachine.prototype.getStatePaths = function getStatePaths(state) {
|
|
|
121
152
|
* Checks to see if at least one path is in the states passed in via `arguments`
|
|
122
153
|
* e.g., this.some('required', 'inited')
|
|
123
154
|
*
|
|
124
|
-
* @param {
|
|
155
|
+
* @param {string} state that we want to check for.
|
|
125
156
|
* @api private
|
|
126
157
|
*/
|
|
127
158
|
|
|
@@ -140,7 +171,7 @@ StateMachine.prototype.some = function some() {
|
|
|
140
171
|
* This function builds the functions that get assigned to `forEach` and `map`,
|
|
141
172
|
* since both of those methods share a lot of the same logic.
|
|
142
173
|
*
|
|
143
|
-
* @param {
|
|
174
|
+
* @param {string} iterMethod is either 'forEach' or 'map'
|
|
144
175
|
* @return {Function}
|
|
145
176
|
* @api private
|
|
146
177
|
*/
|
|
@@ -175,8 +206,7 @@ StateMachine.prototype._iter = function _iter(iterMethod) {
|
|
|
175
206
|
* this.forEach(state1, state2, fn); // iterates over all paths in state1 or state2
|
|
176
207
|
* this.forEach(fn); // iterates over all paths in all states
|
|
177
208
|
*
|
|
178
|
-
* @param {
|
|
179
|
-
* @param {String} [state]
|
|
209
|
+
* @param {...string} [state] one or more state names to filter by
|
|
180
210
|
* @param {Function} callback
|
|
181
211
|
* @api private
|
|
182
212
|
*/
|
|
@@ -194,8 +224,7 @@ StateMachine.prototype.forEach = function forEach() {
|
|
|
194
224
|
* this.forEach(state1, state2, fn); // iterates over all paths in state1 or state2
|
|
195
225
|
* this.forEach(fn); // iterates over all paths in all states
|
|
196
226
|
*
|
|
197
|
-
* @param {
|
|
198
|
-
* @param {String} [state]
|
|
227
|
+
* @param {...string} [state] one or more state names to filter by
|
|
199
228
|
* @param {Function} callback
|
|
200
229
|
* @return {Array}
|
|
201
230
|
* @api private
|
|
@@ -205,3 +234,23 @@ StateMachine.prototype.map = function map() {
|
|
|
205
234
|
this.map = this._iter('map');
|
|
206
235
|
return this.map.apply(this, arguments);
|
|
207
236
|
};
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Returns a copy of this state machine
|
|
240
|
+
*
|
|
241
|
+
* @param {Function} callback
|
|
242
|
+
* @return {StateMachine}
|
|
243
|
+
* @api private
|
|
244
|
+
*/
|
|
245
|
+
|
|
246
|
+
StateMachine.prototype.clone = function clone() {
|
|
247
|
+
const result = new this.constructor();
|
|
248
|
+
result.paths = { ...this.paths };
|
|
249
|
+
for (const state of this.stateNames) {
|
|
250
|
+
if (!(state in this.states)) {
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
result.states[state] = this.states[state] == null ? this.states[state] : { ...this.states[state] };
|
|
254
|
+
}
|
|
255
|
+
return result;
|
|
256
|
+
};
|
package/lib/tracing.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
let dc;
|
|
4
|
+
try {
|
|
5
|
+
dc = (typeof process !== 'undefined' && 'getBuiltinModule' in process)
|
|
6
|
+
? process.getBuiltinModule('node:diagnostics_channel')
|
|
7
|
+
: require('node:diagnostics_channel');
|
|
8
|
+
} catch {
|
|
9
|
+
// diagnostics_channel not available
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const hasTracingChannel = !!dc && typeof dc.tracingChannel === 'function';
|
|
13
|
+
|
|
14
|
+
function shouldTrace(channel) {
|
|
15
|
+
// Node 18 and Bun don't expose hasSubscribers on TracingChannel
|
|
16
|
+
// so undefined means it may or may not have subscribers, so we'll trace anyway
|
|
17
|
+
return !!channel && channel.hasSubscribers !== false;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function createTracedChannel(name) {
|
|
21
|
+
const ch = hasTracingChannel ? dc.tracingChannel(name) : undefined;
|
|
22
|
+
|
|
23
|
+
function trace(fn, contextFactory) {
|
|
24
|
+
if (!shouldTrace(ch)) {
|
|
25
|
+
return fn();
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const traced = ch.tracePromise(fn, contextFactory());
|
|
29
|
+
return traced;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return { channel: ch, trace };
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
module.exports = {
|
|
36
|
+
createTracedChannel,
|
|
37
|
+
cursorNextChannel: createTracedChannel('mongoose:cursor:next')
|
|
38
|
+
};
|
package/lib/types/array/index.js
CHANGED
|
@@ -4,7 +4,6 @@
|
|
|
4
4
|
|
|
5
5
|
'use strict';
|
|
6
6
|
|
|
7
|
-
const Document = require('../../document');
|
|
8
7
|
const mongooseArrayMethods = require('./methods');
|
|
9
8
|
|
|
10
9
|
const arrayAtomicsSymbol = require('../../helpers/symbols').arrayAtomicsSymbol;
|
|
@@ -21,7 +20,7 @@ const arraySchemaSymbol = require('../../helpers/symbols').arraySchemaSymbol;
|
|
|
21
20
|
* _Values always have to be passed to the constructor to initialize, otherwise `MongooseArray#push` will mark the array as modified._
|
|
22
21
|
*
|
|
23
22
|
* @param {Array} values
|
|
24
|
-
* @param {
|
|
23
|
+
* @param {string} path
|
|
25
24
|
* @param {Document} doc parent document
|
|
26
25
|
* @api private
|
|
27
26
|
* @inherits Array https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
|
|
@@ -73,31 +72,35 @@ function MongooseArray(values, path, doc, schematype) {
|
|
|
73
72
|
internals[arrayAtomicsSymbol] = values[arrayAtomicsSymbol];
|
|
74
73
|
}
|
|
75
74
|
|
|
76
|
-
|
|
77
|
-
// can happen if there was a null somewhere up the chain (see #3020)
|
|
78
|
-
// RB Jun 17, 2015 updated to check for presence of expected paths instead
|
|
79
|
-
// to make more proof against unusual node environments
|
|
80
|
-
if (doc != null && doc instanceof Document) {
|
|
75
|
+
if (doc?.$__) {
|
|
81
76
|
internals[arrayParentSymbol] = doc;
|
|
82
77
|
internals[arraySchemaSymbol] = schematype || doc.schema.path(path);
|
|
83
78
|
}
|
|
84
79
|
|
|
85
80
|
const proxy = new Proxy(__array, {
|
|
86
81
|
get: function(target, prop) {
|
|
87
|
-
if (
|
|
82
|
+
if (Object.hasOwn(internals, prop)) {
|
|
88
83
|
return internals[prop];
|
|
89
84
|
}
|
|
90
|
-
if (
|
|
85
|
+
if (Object.hasOwn(mongooseArrayMethods, prop)) {
|
|
91
86
|
return mongooseArrayMethods[prop];
|
|
92
87
|
}
|
|
88
|
+
if (schematype?.virtuals && Object.hasOwn(schematype.virtuals, prop)) {
|
|
89
|
+
return schematype.virtuals[prop].applyGetters(undefined, target);
|
|
90
|
+
}
|
|
91
|
+
if (typeof prop === 'string' && numberRE.test(prop) && schematype?.embeddedSchemaType != null) {
|
|
92
|
+
return schematype.embeddedSchemaType.applyGetters(__array[prop], doc);
|
|
93
|
+
}
|
|
93
94
|
|
|
94
95
|
return __array[prop];
|
|
95
96
|
},
|
|
96
97
|
set: function(target, prop, value) {
|
|
97
98
|
if (typeof prop === 'string' && numberRE.test(prop)) {
|
|
98
99
|
mongooseArrayMethods.set.call(proxy, prop, value, false);
|
|
99
|
-
} else if (
|
|
100
|
+
} else if (Object.hasOwn(internals, prop)) {
|
|
100
101
|
internals[prop] = value;
|
|
102
|
+
} else if (schematype?.virtuals && Object.hasOwn(schematype.virtuals, prop)) {
|
|
103
|
+
schematype.virtuals[prop].applySetters(value, target);
|
|
101
104
|
} else {
|
|
102
105
|
__array[prop] = value;
|
|
103
106
|
}
|