@datanimbus/mongoose 6.13.10
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/.eslintrc.js +232 -0
- package/.mocharc.yml +4 -0
- package/LICENSE.md +22 -0
- package/README.md +387 -0
- package/SECURITY.md +1 -0
- package/browser.js +8 -0
- package/dist/browser.umd.js +2 -0
- package/index.js +63 -0
- package/lgtm.yml +12 -0
- package/lib/aggregate.js +1164 -0
- package/lib/browser.js +158 -0
- package/lib/browserDocument.js +101 -0
- package/lib/cast/boolean.js +32 -0
- package/lib/cast/date.js +41 -0
- package/lib/cast/decimal128.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.js +418 -0
- package/lib/collection.js +311 -0
- package/lib/connection.js +1574 -0
- package/lib/connectionstate.js +26 -0
- package/lib/cursor/AggregationCursor.js +380 -0
- package/lib/cursor/ChangeStream.js +154 -0
- package/lib/cursor/QueryCursor.js +538 -0
- package/lib/document.js +4771 -0
- package/lib/document_provider.js +30 -0
- package/lib/driver.js +15 -0
- package/lib/drivers/SPEC.md +4 -0
- package/lib/drivers/browser/ReadPreference.js +7 -0
- package/lib/drivers/browser/binary.js +14 -0
- package/lib/drivers/browser/decimal128.js +7 -0
- package/lib/drivers/browser/index.js +16 -0
- package/lib/drivers/browser/objectid.js +29 -0
- package/lib/drivers/node-mongodb-native/ReadPreference.js +47 -0
- package/lib/drivers/node-mongodb-native/binary.js +10 -0
- package/lib/drivers/node-mongodb-native/collection.js +460 -0
- package/lib/drivers/node-mongodb-native/connection.js +166 -0
- package/lib/drivers/node-mongodb-native/decimal128.js +7 -0
- package/lib/drivers/node-mongodb-native/index.js +12 -0
- package/lib/drivers/node-mongodb-native/objectid.js +16 -0
- package/lib/error/browserMissingSchema.js +28 -0
- package/lib/error/bulkWriteError.js +41 -0
- package/lib/error/cast.js +158 -0
- package/lib/error/disconnected.js +33 -0
- package/lib/error/divergentArray.js +38 -0
- package/lib/error/eachAsyncMultiError.js +41 -0
- package/lib/error/index.js +228 -0
- package/lib/error/messages.js +47 -0
- package/lib/error/missingSchema.js +31 -0
- package/lib/error/mongooseError.js +13 -0
- package/lib/error/notFound.js +45 -0
- package/lib/error/objectExpected.js +30 -0
- package/lib/error/objectParameter.js +30 -0
- package/lib/error/overwriteModel.js +30 -0
- package/lib/error/parallelSave.js +30 -0
- package/lib/error/parallelValidate.js +31 -0
- package/lib/error/serverSelection.js +61 -0
- package/lib/error/setOptionError.js +101 -0
- package/lib/error/strict.js +33 -0
- package/lib/error/strictPopulate.js +29 -0
- package/lib/error/syncIndexes.js +30 -0
- package/lib/error/validation.js +103 -0
- package/lib/error/validator.js +99 -0
- package/lib/error/version.js +36 -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 +177 -0
- package/lib/helpers/common.js +127 -0
- package/lib/helpers/cursor/eachAsync.js +222 -0
- package/lib/helpers/discriminator/areDiscriminatorValuesEqual.js +16 -0
- package/lib/helpers/discriminator/checkEmbeddedDiscriminatorKeyProjection.js +12 -0
- package/lib/helpers/discriminator/getConstructor.js +26 -0
- package/lib/helpers/discriminator/getDiscriminatorByValue.js +28 -0
- package/lib/helpers/discriminator/getSchemaDiscriminatorByValue.js +27 -0
- package/lib/helpers/discriminator/mergeDiscriminatorSchema.js +64 -0
- package/lib/helpers/document/applyDefaults.js +128 -0
- package/lib/helpers/document/cleanModifiedSubpaths.js +35 -0
- package/lib/helpers/document/compile.js +237 -0
- package/lib/helpers/document/getEmbeddedDiscriminatorPath.js +50 -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 +27 -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 +59 -0
- package/lib/helpers/indexes/isDefaultIdIndex.js +18 -0
- package/lib/helpers/indexes/isIndexEqual.js +96 -0
- package/lib/helpers/indexes/isTextIndex.js +16 -0
- package/lib/helpers/isAsyncFunction.js +9 -0
- package/lib/helpers/isBsonType.js +16 -0
- package/lib/helpers/isMongooseObject.js +22 -0
- package/lib/helpers/isObject.js +16 -0
- package/lib/helpers/isPromise.js +6 -0
- package/lib/helpers/isSimpleValidator.js +22 -0
- package/lib/helpers/model/applyDefaultsToPOJO.js +52 -0
- package/lib/helpers/model/applyHooks.js +149 -0
- package/lib/helpers/model/applyMethods.js +70 -0
- package/lib/helpers/model/applyStaticHooks.js +71 -0
- package/lib/helpers/model/applyStatics.js +13 -0
- package/lib/helpers/model/castBulkWrite.js +240 -0
- package/lib/helpers/model/discriminator.js +218 -0
- package/lib/helpers/model/pushNestedArrayPaths.js +15 -0
- package/lib/helpers/once.js +12 -0
- package/lib/helpers/parallelLimit.js +55 -0
- package/lib/helpers/path/parentPaths.js +18 -0
- package/lib/helpers/path/setDottedPath.js +33 -0
- package/lib/helpers/pluralize.js +94 -0
- package/lib/helpers/populate/SkipPopulateValue.js +10 -0
- package/lib/helpers/populate/assignRawDocsToIdStructure.js +124 -0
- package/lib/helpers/populate/assignVals.js +337 -0
- package/lib/helpers/populate/createPopulateQueryFilter.js +97 -0
- package/lib/helpers/populate/getModelsMapForPopulate.js +756 -0
- package/lib/helpers/populate/getSchemaTypes.js +233 -0
- package/lib/helpers/populate/getVirtual.js +72 -0
- package/lib/helpers/populate/leanPopulateMap.js +7 -0
- package/lib/helpers/populate/lookupLocalFields.js +40 -0
- package/lib/helpers/populate/markArraySubdocsPopulated.js +47 -0
- package/lib/helpers/populate/modelNamesFromRefPath.js +68 -0
- package/lib/helpers/populate/removeDeselectedForeignField.js +31 -0
- package/lib/helpers/populate/validateRef.js +19 -0
- package/lib/helpers/printJestWarning.js +21 -0
- package/lib/helpers/printStrictQueryWarning.js +11 -0
- package/lib/helpers/processConnectionOptions.js +65 -0
- package/lib/helpers/projection/applyProjection.js +77 -0
- package/lib/helpers/projection/hasIncludedChildren.js +41 -0
- package/lib/helpers/projection/isDefiningProjection.js +18 -0
- package/lib/helpers/projection/isExclusive.js +35 -0
- package/lib/helpers/projection/isInclusive.js +38 -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/promiseOrCallback.js +55 -0
- package/lib/helpers/query/applyGlobalOption.js +29 -0
- package/lib/helpers/query/applyQueryMiddleware.js +79 -0
- package/lib/helpers/query/cast$expr.js +282 -0
- package/lib/helpers/query/castFilterPath.js +54 -0
- package/lib/helpers/query/castUpdate.js +560 -0
- package/lib/helpers/query/completeMany.js +52 -0
- package/lib/helpers/query/getEmbeddedDiscriminatorPath.js +90 -0
- package/lib/helpers/query/handleImmutable.js +28 -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 +49 -0
- package/lib/helpers/query/trusted.js +13 -0
- package/lib/helpers/query/validOps.js +24 -0
- package/lib/helpers/query/wrapThunk.js +31 -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/applyWriteConcern.js +30 -0
- package/lib/helpers/schema/cleanPositionalOperators.js +12 -0
- package/lib/helpers/schema/getIndexes.js +164 -0
- package/lib/helpers/schema/getKeysInSchemaOrder.js +28 -0
- package/lib/helpers/schema/getPath.js +37 -0
- package/lib/helpers/schema/handleIdOption.js +20 -0
- package/lib/helpers/schema/handleTimestampOption.js +24 -0
- package/lib/helpers/schema/idGetter.js +32 -0
- package/lib/helpers/schema/merge.js +28 -0
- package/lib/helpers/schematype/handleImmutable.js +50 -0
- package/lib/helpers/setDefaultsOnInsert.js +132 -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 +101 -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 +117 -0
- package/lib/helpers/update/castArrayFilters.js +109 -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 +249 -0
- package/lib/index.js +1338 -0
- package/lib/internal.js +46 -0
- package/lib/model.js +5474 -0
- package/lib/options/PopulateOptions.js +36 -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 +42 -0
- package/lib/options/SchemaTypeOptions.js +244 -0
- package/lib/options/VirtualOptions.js +164 -0
- package/lib/options/propertyOptions.js +8 -0
- package/lib/options/removeOptions.js +14 -0
- package/lib/options/saveOptions.js +14 -0
- package/lib/options.js +15 -0
- package/lib/plugins/index.js +7 -0
- package/lib/plugins/removeSubdocs.js +31 -0
- package/lib/plugins/saveSubdocs.js +66 -0
- package/lib/plugins/sharding.js +83 -0
- package/lib/plugins/trackTransaction.js +92 -0
- package/lib/plugins/validateBeforeSave.js +45 -0
- package/lib/promise_provider.js +49 -0
- package/lib/query.js +5982 -0
- package/lib/queryhelpers.js +353 -0
- package/lib/schema/DocumentArrayElement.js +100 -0
- package/lib/schema/SubdocumentPath.js +369 -0
- package/lib/schema/array.js +663 -0
- package/lib/schema/boolean.js +267 -0
- package/lib/schema/buffer.js +269 -0
- package/lib/schema/date.js +404 -0
- package/lib/schema/decimal128.js +210 -0
- package/lib/schema/documentarray.js +598 -0
- package/lib/schema/index.js +39 -0
- package/lib/schema/map.js +84 -0
- package/lib/schema/mixed.js +132 -0
- package/lib/schema/number.js +438 -0
- package/lib/schema/objectid.js +295 -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 +694 -0
- package/lib/schema/symbols.js +5 -0
- package/lib/schema/uuid.js +334 -0
- package/lib/schema.js +2665 -0
- package/lib/schematype.js +1727 -0
- package/lib/statemachine.js +207 -0
- package/lib/types/ArraySubdocument.js +189 -0
- package/lib/types/DocumentArray/index.js +113 -0
- package/lib/types/DocumentArray/isMongooseDocumentArray.js +5 -0
- package/lib/types/DocumentArray/methods/index.js +383 -0
- package/lib/types/array/index.js +116 -0
- package/lib/types/array/isMongooseArray.js +5 -0
- package/lib/types/array/methods/index.js +1014 -0
- package/lib/types/buffer.js +277 -0
- package/lib/types/decimal128.js +13 -0
- package/lib/types/index.js +20 -0
- package/lib/types/map.js +354 -0
- package/lib/types/objectid.js +41 -0
- package/lib/types/subdocument.js +432 -0
- package/lib/utils.js +1011 -0
- package/lib/validoptions.js +36 -0
- package/lib/virtualtype.js +175 -0
- package/package.json +164 -0
- package/scripts/build-browser.js +18 -0
- package/scripts/create-tarball.js +7 -0
- package/scripts/generateSearch.js +154 -0
- package/scripts/tsc-diagnostics-check.js +15 -0
- package/tools/auth.js +31 -0
- package/tools/repl.js +35 -0
- package/tools/sharded.js +46 -0
- package/tsconfig.json +9 -0
- package/types/aggregate.d.ts +174 -0
- package/types/augmentations.d.ts +9 -0
- package/types/callback.d.ts +8 -0
- package/types/collection.d.ts +44 -0
- package/types/connection.d.ts +242 -0
- package/types/cursor.d.ts +62 -0
- package/types/document.d.ts +266 -0
- package/types/error.d.ts +138 -0
- package/types/expressions.d.ts +2936 -0
- package/types/helpers.d.ts +32 -0
- package/types/index.d.ts +627 -0
- package/types/indexes.d.ts +98 -0
- package/types/inferschematype.d.ts +228 -0
- package/types/middlewares.d.ts +32 -0
- package/types/models.d.ts +488 -0
- package/types/mongooseoptions.d.ts +206 -0
- package/types/pipelinestage.d.ts +297 -0
- package/types/populate.d.ts +45 -0
- package/types/query.d.ts +659 -0
- package/types/schemaoptions.d.ts +231 -0
- package/types/schematypes.d.ts +478 -0
- package/types/session.d.ts +36 -0
- package/types/types.d.ts +104 -0
- package/types/utility.d.ts +43 -0
- package/types/validation.d.ts +34 -0
- package/types/virtuals.d.ts +14 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = function merge(s1, s2, skipConflictingPaths) {
|
|
4
|
+
const paths = Object.keys(s2.tree);
|
|
5
|
+
const pathsToAdd = {};
|
|
6
|
+
for (const key of paths) {
|
|
7
|
+
if (skipConflictingPaths && (s1.paths[key] || s1.nested[key] || s1.singleNestedPaths[key])) {
|
|
8
|
+
continue;
|
|
9
|
+
}
|
|
10
|
+
pathsToAdd[key] = s2.tree[key];
|
|
11
|
+
}
|
|
12
|
+
s1.add(pathsToAdd);
|
|
13
|
+
|
|
14
|
+
s1.callQueue = s1.callQueue.concat(s2.callQueue);
|
|
15
|
+
s1.method(s2.methods);
|
|
16
|
+
s1.static(s2.statics);
|
|
17
|
+
|
|
18
|
+
for (const query in s2.query) {
|
|
19
|
+
s1.query[query] = s2.query[query];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
for (const virtual in s2.virtuals) {
|
|
23
|
+
s1.virtuals[virtual] = s2.virtuals[virtual].clone();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
s1._indexes = s1._indexes.concat(s2._indexes || []);
|
|
27
|
+
s1.s.hooks.merge(s2.s.hooks, false);
|
|
28
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const StrictModeError = require('../../error/strict');
|
|
4
|
+
|
|
5
|
+
/*!
|
|
6
|
+
* ignore
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
module.exports = function(schematype) {
|
|
10
|
+
if (schematype.$immutable) {
|
|
11
|
+
schematype.$immutableSetter = createImmutableSetter(schematype.path,
|
|
12
|
+
schematype.options.immutable);
|
|
13
|
+
schematype.set(schematype.$immutableSetter);
|
|
14
|
+
} else if (schematype.$immutableSetter) {
|
|
15
|
+
schematype.setters = schematype.setters.
|
|
16
|
+
filter(fn => fn !== schematype.$immutableSetter);
|
|
17
|
+
delete schematype.$immutableSetter;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
function createImmutableSetter(path, immutable) {
|
|
22
|
+
return function immutableSetter(v, _priorVal, _doc, options) {
|
|
23
|
+
if (this == null || this.$__ == null) {
|
|
24
|
+
return v;
|
|
25
|
+
}
|
|
26
|
+
if (this.isNew) {
|
|
27
|
+
return v;
|
|
28
|
+
}
|
|
29
|
+
if (options && options.overwriteImmutable) {
|
|
30
|
+
return v;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const _immutable = typeof immutable === 'function' ?
|
|
34
|
+
immutable.call(this, this) :
|
|
35
|
+
immutable;
|
|
36
|
+
if (!_immutable) {
|
|
37
|
+
return v;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const _value = this.$__.priorDoc != null ?
|
|
41
|
+
this.$__.priorDoc.$__getValue(path) :
|
|
42
|
+
this.$__getValue(path);
|
|
43
|
+
if (this.$__.strictMode === 'throw' && v !== _value) {
|
|
44
|
+
throw new StrictModeError(path, 'Path `' + path + '` is immutable ' +
|
|
45
|
+
'and strict mode is set to throw.', true);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return _value;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
const modifiedPaths = require('./common').modifiedPaths;
|
|
3
|
+
const get = require('./get');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Applies defaults to update and findOneAndUpdate operations.
|
|
7
|
+
*
|
|
8
|
+
* @param {Object} filter
|
|
9
|
+
* @param {Schema} schema
|
|
10
|
+
* @param {Object} castedDoc
|
|
11
|
+
* @param {Object} options
|
|
12
|
+
* @method setDefaultsOnInsert
|
|
13
|
+
* @api private
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
module.exports = function(filter, schema, castedDoc, options) {
|
|
17
|
+
options = options || {};
|
|
18
|
+
|
|
19
|
+
const shouldSetDefaultsOnInsert =
|
|
20
|
+
options.setDefaultsOnInsert != null ?
|
|
21
|
+
options.setDefaultsOnInsert :
|
|
22
|
+
schema.base.options.setDefaultsOnInsert;
|
|
23
|
+
|
|
24
|
+
if (!options.upsert || shouldSetDefaultsOnInsert === false) {
|
|
25
|
+
return castedDoc;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const keys = Object.keys(castedDoc || {});
|
|
29
|
+
const updatedKeys = {};
|
|
30
|
+
const updatedValues = {};
|
|
31
|
+
const numKeys = keys.length;
|
|
32
|
+
const modified = {};
|
|
33
|
+
|
|
34
|
+
let hasDollarUpdate = false;
|
|
35
|
+
|
|
36
|
+
for (let i = 0; i < numKeys; ++i) {
|
|
37
|
+
if (keys[i].startsWith('$')) {
|
|
38
|
+
modifiedPaths(castedDoc[keys[i]], '', modified);
|
|
39
|
+
hasDollarUpdate = true;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (!hasDollarUpdate) {
|
|
44
|
+
modifiedPaths(castedDoc, '', modified);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const paths = Object.keys(filter);
|
|
48
|
+
const numPaths = paths.length;
|
|
49
|
+
for (let i = 0; i < numPaths; ++i) {
|
|
50
|
+
const path = paths[i];
|
|
51
|
+
const condition = filter[path];
|
|
52
|
+
if (condition && typeof condition === 'object') {
|
|
53
|
+
const conditionKeys = Object.keys(condition);
|
|
54
|
+
const numConditionKeys = conditionKeys.length;
|
|
55
|
+
let hasDollarKey = false;
|
|
56
|
+
for (let j = 0; j < numConditionKeys; ++j) {
|
|
57
|
+
if (conditionKeys[j].startsWith('$')) {
|
|
58
|
+
hasDollarKey = true;
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (hasDollarKey) {
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
updatedKeys[path] = true;
|
|
67
|
+
modified[path] = true;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (options && options.overwrite && !hasDollarUpdate) {
|
|
71
|
+
// Defaults will be set later, since we're overwriting we'll cast
|
|
72
|
+
// the whole update to a document
|
|
73
|
+
return castedDoc;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
schema.eachPath(function(path, schemaType) {
|
|
77
|
+
// Skip single nested paths if underneath a map
|
|
78
|
+
if (schemaType.path === '_id' && schemaType.options.auto) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const def = schemaType.getDefault(null, true);
|
|
82
|
+
if (isModified(modified, path)) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
if (typeof def === 'undefined') {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (schemaType.splitPath().includes('$*')) {
|
|
89
|
+
// Skip defaults underneath maps. We should never do `$setOnInsert` on a path with `$*`
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
castedDoc = castedDoc || {};
|
|
94
|
+
castedDoc.$setOnInsert = castedDoc.$setOnInsert || {};
|
|
95
|
+
if (get(castedDoc, path) == null) {
|
|
96
|
+
castedDoc.$setOnInsert[path] = def;
|
|
97
|
+
}
|
|
98
|
+
updatedValues[path] = def;
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
return castedDoc;
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
function isModified(modified, path) {
|
|
105
|
+
if (modified[path]) {
|
|
106
|
+
return true;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Is any parent path of `path` modified?
|
|
110
|
+
const sp = path.split('.');
|
|
111
|
+
let cur = sp[0];
|
|
112
|
+
for (let i = 1; i < sp.length; ++i) {
|
|
113
|
+
if (modified[cur]) {
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
cur += '.' + sp[i];
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Is any child of `path` modified?
|
|
120
|
+
const modifiedKeys = Object.keys(modified);
|
|
121
|
+
if (modifiedKeys.length) {
|
|
122
|
+
const parentPath = path + '.';
|
|
123
|
+
|
|
124
|
+
for (const modifiedPath of modifiedKeys) {
|
|
125
|
+
if (modifiedPath.slice(0, path.length + 1) === parentPath) {
|
|
126
|
+
return true;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
exports.arrayAtomicsBackupSymbol = Symbol('mongoose#Array#atomicsBackup');
|
|
4
|
+
exports.arrayAtomicsSymbol = Symbol('mongoose#Array#_atomics');
|
|
5
|
+
exports.arrayParentSymbol = Symbol('mongoose#Array#_parent');
|
|
6
|
+
exports.arrayPathSymbol = Symbol('mongoose#Array#_path');
|
|
7
|
+
exports.arraySchemaSymbol = Symbol('mongoose#Array#_schema');
|
|
8
|
+
exports.documentArrayParent = Symbol('mongoose:documentArrayParent');
|
|
9
|
+
exports.documentIsSelected = Symbol('mongoose#Document#isSelected');
|
|
10
|
+
exports.documentIsModified = Symbol('mongoose#Document#isModified');
|
|
11
|
+
exports.documentModifiedPaths = Symbol('mongoose#Document#modifiedPaths');
|
|
12
|
+
exports.documentSchemaSymbol = Symbol('mongoose#Document#schema');
|
|
13
|
+
exports.getSymbol = Symbol('mongoose#Document#get');
|
|
14
|
+
exports.modelSymbol = Symbol('mongoose#Model');
|
|
15
|
+
exports.objectIdSymbol = Symbol('mongoose#ObjectId');
|
|
16
|
+
exports.populateModelSymbol = Symbol('mongoose.PopulateOptions#Model');
|
|
17
|
+
exports.schemaTypeSymbol = Symbol('mongoose#schemaType');
|
|
18
|
+
exports.sessionNewDocuments = Symbol('mongoose:ClientSession#newDocuments');
|
|
19
|
+
exports.scopeSymbol = Symbol('mongoose#Document#scope');
|
|
20
|
+
exports.validatorErrorSymbol = Symbol('mongoose:validatorError');
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports = function setDocumentTimestamps(doc, timestampOption, currentTime, createdAt, updatedAt) {
|
|
4
|
+
const skipUpdatedAt = timestampOption != null && timestampOption.updatedAt === false;
|
|
5
|
+
const skipCreatedAt = timestampOption != null && timestampOption.createdAt === false;
|
|
6
|
+
|
|
7
|
+
const defaultTimestamp = currentTime != null ?
|
|
8
|
+
currentTime() :
|
|
9
|
+
doc.ownerDocument().constructor.base.now();
|
|
10
|
+
|
|
11
|
+
if (!skipCreatedAt &&
|
|
12
|
+
(doc.isNew || doc.$isSubdocument) &&
|
|
13
|
+
createdAt &&
|
|
14
|
+
!doc.$__getValue(createdAt) &&
|
|
15
|
+
doc.$__isSelected(createdAt)) {
|
|
16
|
+
doc.$set(createdAt, defaultTimestamp, undefined, { overwriteImmutable: true });
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (!skipUpdatedAt && updatedAt && (doc.isNew || doc.$isModified())) {
|
|
20
|
+
let ts = defaultTimestamp;
|
|
21
|
+
if (doc.isNew && createdAt != null) {
|
|
22
|
+
ts = doc.$__getValue(createdAt);
|
|
23
|
+
}
|
|
24
|
+
doc.$set(updatedAt, ts);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const applyTimestampsToChildren = require('../update/applyTimestampsToChildren');
|
|
4
|
+
const applyTimestampsToUpdate = require('../update/applyTimestampsToUpdate');
|
|
5
|
+
const get = require('../get');
|
|
6
|
+
const handleTimestampOption = require('../schema/handleTimestampOption');
|
|
7
|
+
const setDocumentTimestamps = require('./setDocumentTimestamps');
|
|
8
|
+
const symbols = require('../../schema/symbols');
|
|
9
|
+
|
|
10
|
+
module.exports = function setupTimestamps(schema, timestamps) {
|
|
11
|
+
const childHasTimestamp = schema.childSchemas.find(withTimestamp);
|
|
12
|
+
function withTimestamp(s) {
|
|
13
|
+
const ts = s.schema.options.timestamps;
|
|
14
|
+
return !!ts;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (!timestamps && !childHasTimestamp) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const createdAt = handleTimestampOption(timestamps, 'createdAt');
|
|
22
|
+
const updatedAt = handleTimestampOption(timestamps, 'updatedAt');
|
|
23
|
+
const currentTime = timestamps != null && timestamps.hasOwnProperty('currentTime') ?
|
|
24
|
+
timestamps.currentTime :
|
|
25
|
+
null;
|
|
26
|
+
const schemaAdditions = {};
|
|
27
|
+
|
|
28
|
+
schema.$timestamps = { createdAt: createdAt, updatedAt: updatedAt };
|
|
29
|
+
|
|
30
|
+
if (createdAt && !schema.paths[createdAt]) {
|
|
31
|
+
const baseImmutableCreatedAt = schema.base != null ? schema.base.get('timestamps.createdAt.immutable') : null;
|
|
32
|
+
const immutable = baseImmutableCreatedAt != null ? baseImmutableCreatedAt : true;
|
|
33
|
+
schemaAdditions[createdAt] = { [schema.options.typeKey || 'type']: Date, immutable };
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (updatedAt && !schema.paths[updatedAt]) {
|
|
37
|
+
schemaAdditions[updatedAt] = Date;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
schema.add(schemaAdditions);
|
|
41
|
+
|
|
42
|
+
schema.pre('save', function timestampsPreSave(next) {
|
|
43
|
+
const timestampOption = get(this, '$__.saveOptions.timestamps');
|
|
44
|
+
if (timestampOption === false) {
|
|
45
|
+
return next();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
setDocumentTimestamps(this, timestampOption, currentTime, createdAt, updatedAt);
|
|
49
|
+
|
|
50
|
+
next();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
schema.methods.initializeTimestamps = function() {
|
|
54
|
+
const ts = currentTime != null ?
|
|
55
|
+
currentTime() :
|
|
56
|
+
this.constructor.base.now();
|
|
57
|
+
if (createdAt && !this.get(createdAt)) {
|
|
58
|
+
this.$set(createdAt, ts);
|
|
59
|
+
}
|
|
60
|
+
if (updatedAt && !this.get(updatedAt)) {
|
|
61
|
+
this.$set(updatedAt, ts);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (this.$isSubdocument) {
|
|
65
|
+
return this;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const subdocs = this.$getAllSubdocs();
|
|
69
|
+
for (const subdoc of subdocs) {
|
|
70
|
+
if (subdoc.initializeTimestamps) {
|
|
71
|
+
subdoc.initializeTimestamps();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return this;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
_setTimestampsOnUpdate[symbols.builtInMiddleware] = true;
|
|
79
|
+
|
|
80
|
+
const opts = { query: true, model: false };
|
|
81
|
+
schema.pre('findOneAndReplace', opts, _setTimestampsOnUpdate);
|
|
82
|
+
schema.pre('findOneAndUpdate', opts, _setTimestampsOnUpdate);
|
|
83
|
+
schema.pre('replaceOne', opts, _setTimestampsOnUpdate);
|
|
84
|
+
schema.pre('update', opts, _setTimestampsOnUpdate);
|
|
85
|
+
schema.pre('updateOne', opts, _setTimestampsOnUpdate);
|
|
86
|
+
schema.pre('updateMany', opts, _setTimestampsOnUpdate);
|
|
87
|
+
|
|
88
|
+
function _setTimestampsOnUpdate(next) {
|
|
89
|
+
const now = currentTime != null ?
|
|
90
|
+
currentTime() :
|
|
91
|
+
this.model.base.now();
|
|
92
|
+
// Replacing with null update should still trigger timestamps
|
|
93
|
+
if (this.op === 'findOneAndReplace' && this.getUpdate() == null) {
|
|
94
|
+
this.setUpdate({});
|
|
95
|
+
}
|
|
96
|
+
applyTimestampsToUpdate(now, createdAt, updatedAt, this.getUpdate(),
|
|
97
|
+
this.options, this.schema);
|
|
98
|
+
applyTimestampsToChildren(now, this.getUpdate(), this.model.schema);
|
|
99
|
+
next();
|
|
100
|
+
}
|
|
101
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const getConstructorName = require('../getConstructorName');
|
|
4
|
+
|
|
5
|
+
module.exports = function allServersUnknown(topologyDescription) {
|
|
6
|
+
if (getConstructorName(topologyDescription) !== 'TopologyDescription') {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const servers = Array.from(topologyDescription.servers.values());
|
|
11
|
+
return servers.length > 0 && servers.every(server => server.type === 'Unknown');
|
|
12
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const getConstructorName = require('../getConstructorName');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @typedef { import('mongodb').TopologyDescription } TopologyDescription
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Checks if topologyDescription contains servers connected to an atlas instance
|
|
11
|
+
*
|
|
12
|
+
* @param {TopologyDescription} topologyDescription
|
|
13
|
+
* @returns {boolean}
|
|
14
|
+
*/
|
|
15
|
+
module.exports = function isAtlas(topologyDescription) {
|
|
16
|
+
if (getConstructorName(topologyDescription) !== 'TopologyDescription') {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (topologyDescription.servers.size === 0) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
for (const server of topologyDescription.servers.values()) {
|
|
25
|
+
if (server.host.endsWith('.mongodb.net') === false || server.port !== 27017) {
|
|
26
|
+
return false;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return true;
|
|
31
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const getConstructorName = require('../getConstructorName');
|
|
4
|
+
|
|
5
|
+
const nonSSLMessage = 'Client network socket disconnected before secure TLS ' +
|
|
6
|
+
'connection was established';
|
|
7
|
+
|
|
8
|
+
module.exports = function isSSLError(topologyDescription) {
|
|
9
|
+
if (getConstructorName(topologyDescription) !== 'TopologyDescription') {
|
|
10
|
+
return false;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const descriptions = Array.from(topologyDescription.servers.values());
|
|
14
|
+
return descriptions.length > 0 &&
|
|
15
|
+
descriptions.every(descr => descr.error && descr.error.message.indexOf(nonSSLMessage) !== -1);
|
|
16
|
+
};
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const cleanPositionalOperators = require('../schema/cleanPositionalOperators');
|
|
4
|
+
const handleTimestampOption = require('../schema/handleTimestampOption');
|
|
5
|
+
|
|
6
|
+
module.exports = applyTimestampsToChildren;
|
|
7
|
+
|
|
8
|
+
/*!
|
|
9
|
+
* ignore
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
function applyTimestampsToChildren(now, update, schema) {
|
|
13
|
+
if (update == null) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const keys = Object.keys(update);
|
|
18
|
+
const hasDollarKey = keys.some(key => key[0] === '$');
|
|
19
|
+
|
|
20
|
+
if (hasDollarKey) {
|
|
21
|
+
if (update.$push) {
|
|
22
|
+
_applyTimestampToUpdateOperator(update.$push);
|
|
23
|
+
}
|
|
24
|
+
if (update.$addToSet) {
|
|
25
|
+
_applyTimestampToUpdateOperator(update.$addToSet);
|
|
26
|
+
}
|
|
27
|
+
if (update.$set != null) {
|
|
28
|
+
const keys = Object.keys(update.$set);
|
|
29
|
+
for (const key of keys) {
|
|
30
|
+
applyTimestampsToUpdateKey(schema, key, update.$set, now);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (update.$setOnInsert != null) {
|
|
34
|
+
const keys = Object.keys(update.$setOnInsert);
|
|
35
|
+
for (const key of keys) {
|
|
36
|
+
applyTimestampsToUpdateKey(schema, key, update.$setOnInsert, now);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const updateKeys = Object.keys(update).filter(key => key[0] !== '$');
|
|
42
|
+
for (const key of updateKeys) {
|
|
43
|
+
applyTimestampsToUpdateKey(schema, key, update, now);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function _applyTimestampToUpdateOperator(op) {
|
|
47
|
+
for (const key of Object.keys(op)) {
|
|
48
|
+
const $path = schema.path(key.replace(/\.\$\./i, '.').replace(/.\$$/, ''));
|
|
49
|
+
if (op[key] &&
|
|
50
|
+
$path &&
|
|
51
|
+
$path.$isMongooseDocumentArray &&
|
|
52
|
+
$path.schema.options.timestamps) {
|
|
53
|
+
const timestamps = $path.schema.options.timestamps;
|
|
54
|
+
const createdAt = handleTimestampOption(timestamps, 'createdAt');
|
|
55
|
+
const updatedAt = handleTimestampOption(timestamps, 'updatedAt');
|
|
56
|
+
if (op[key].$each) {
|
|
57
|
+
op[key].$each.forEach(function(subdoc) {
|
|
58
|
+
if (updatedAt != null) {
|
|
59
|
+
subdoc[updatedAt] = now;
|
|
60
|
+
}
|
|
61
|
+
if (createdAt != null) {
|
|
62
|
+
subdoc[createdAt] = now;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
applyTimestampsToChildren(now, subdoc, $path.schema);
|
|
66
|
+
});
|
|
67
|
+
} else {
|
|
68
|
+
if (updatedAt != null) {
|
|
69
|
+
op[key][updatedAt] = now;
|
|
70
|
+
}
|
|
71
|
+
if (createdAt != null) {
|
|
72
|
+
op[key][createdAt] = now;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
applyTimestampsToChildren(now, op[key], $path.schema);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function applyTimestampsToDocumentArray(arr, schematype, now) {
|
|
83
|
+
const timestamps = schematype.schema.options.timestamps;
|
|
84
|
+
|
|
85
|
+
const len = arr.length;
|
|
86
|
+
|
|
87
|
+
if (!timestamps) {
|
|
88
|
+
for (let i = 0; i < len; ++i) {
|
|
89
|
+
applyTimestampsToChildren(now, arr[i], schematype.schema);
|
|
90
|
+
}
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const createdAt = handleTimestampOption(timestamps, 'createdAt');
|
|
95
|
+
const updatedAt = handleTimestampOption(timestamps, 'updatedAt');
|
|
96
|
+
for (let i = 0; i < len; ++i) {
|
|
97
|
+
if (updatedAt != null) {
|
|
98
|
+
arr[i][updatedAt] = now;
|
|
99
|
+
}
|
|
100
|
+
if (createdAt != null) {
|
|
101
|
+
arr[i][createdAt] = now;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
applyTimestampsToChildren(now, arr[i], schematype.schema);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function applyTimestampsToSingleNested(subdoc, schematype, now) {
|
|
109
|
+
const timestamps = schematype.schema.options.timestamps;
|
|
110
|
+
if (!timestamps) {
|
|
111
|
+
applyTimestampsToChildren(now, subdoc, schematype.schema);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const createdAt = handleTimestampOption(timestamps, 'createdAt');
|
|
116
|
+
const updatedAt = handleTimestampOption(timestamps, 'updatedAt');
|
|
117
|
+
if (updatedAt != null) {
|
|
118
|
+
subdoc[updatedAt] = now;
|
|
119
|
+
}
|
|
120
|
+
if (createdAt != null) {
|
|
121
|
+
subdoc[createdAt] = now;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
applyTimestampsToChildren(now, subdoc, schematype.schema);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function applyTimestampsToUpdateKey(schema, key, update, now) {
|
|
128
|
+
// Replace positional operator `$` and array filters `$[]` and `$[.*]`
|
|
129
|
+
const keyToSearch = cleanPositionalOperators(key);
|
|
130
|
+
const path = schema.path(keyToSearch);
|
|
131
|
+
if (!path) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const parentSchemaTypes = [];
|
|
136
|
+
const pieces = keyToSearch.split('.');
|
|
137
|
+
for (let i = pieces.length - 1; i > 0; --i) {
|
|
138
|
+
const s = schema.path(pieces.slice(0, i).join('.'));
|
|
139
|
+
if (s != null &&
|
|
140
|
+
(s.$isMongooseDocumentArray || s.$isSingleNested)) {
|
|
141
|
+
parentSchemaTypes.push({ parentPath: key.split('.').slice(0, i).join('.'), parentSchemaType: s });
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
if (Array.isArray(update[key]) && path.$isMongooseDocumentArray) {
|
|
146
|
+
applyTimestampsToDocumentArray(update[key], path, now);
|
|
147
|
+
} else if (update[key] && path.$isSingleNested) {
|
|
148
|
+
applyTimestampsToSingleNested(update[key], path, now);
|
|
149
|
+
} else if (parentSchemaTypes.length > 0) {
|
|
150
|
+
for (const item of parentSchemaTypes) {
|
|
151
|
+
const parentPath = item.parentPath;
|
|
152
|
+
const parentSchemaType = item.parentSchemaType;
|
|
153
|
+
const timestamps = parentSchemaType.schema.options.timestamps;
|
|
154
|
+
const updatedAt = handleTimestampOption(timestamps, 'updatedAt');
|
|
155
|
+
|
|
156
|
+
if (!timestamps || updatedAt == null) {
|
|
157
|
+
continue;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (parentSchemaType.$isSingleNested) {
|
|
161
|
+
// Single nested is easy
|
|
162
|
+
update[parentPath + '.' + updatedAt] = now;
|
|
163
|
+
} else if (parentSchemaType.$isMongooseDocumentArray) {
|
|
164
|
+
let childPath = key.substring(parentPath.length + 1);
|
|
165
|
+
|
|
166
|
+
if (/^\d+$/.test(childPath)) {
|
|
167
|
+
update[parentPath + '.' + childPath][updatedAt] = now;
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const firstDot = childPath.indexOf('.');
|
|
172
|
+
childPath = firstDot !== -1 ? childPath.substring(0, firstDot) : childPath;
|
|
173
|
+
|
|
174
|
+
update[parentPath + '.' + childPath + '.' + updatedAt] = now;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
} else if (path.schema != null && path.schema != schema && update[key]) {
|
|
178
|
+
const timestamps = path.schema.options.timestamps;
|
|
179
|
+
const createdAt = handleTimestampOption(timestamps, 'createdAt');
|
|
180
|
+
const updatedAt = handleTimestampOption(timestamps, 'updatedAt');
|
|
181
|
+
|
|
182
|
+
if (!timestamps) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
if (updatedAt != null) {
|
|
187
|
+
update[key][updatedAt] = now;
|
|
188
|
+
}
|
|
189
|
+
if (createdAt != null) {
|
|
190
|
+
update[key][createdAt] = now;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|