mongoose 6.4.1 → 6.4.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.
Files changed (109) hide show
  1. package/.eslintrc.json +3 -2
  2. package/lib/cast/date.js +1 -1
  3. package/lib/cast/decimal128.js +1 -1
  4. package/lib/cast/objectid.js +1 -1
  5. package/lib/cast.js +1 -1
  6. package/lib/drivers/node-mongodb-native/index.js +1 -1
  7. package/lib/error/parallelValidate.js +1 -1
  8. package/lib/helpers/aggregate/prepareDiscriminatorPipeline.js +1 -1
  9. package/lib/helpers/aggregate/stringifyFunctionOperators.js +1 -1
  10. package/lib/helpers/arrayDepth.js +1 -1
  11. package/lib/helpers/cursor/eachAsync.js +1 -1
  12. package/lib/helpers/discriminator/areDiscriminatorValuesEqual.js +1 -1
  13. package/lib/helpers/discriminator/checkEmbeddedDiscriminatorKeyProjection.js +1 -1
  14. package/lib/helpers/discriminator/getConstructor.js +1 -1
  15. package/lib/helpers/discriminator/getDiscriminatorByValue.js +1 -1
  16. package/lib/helpers/discriminator/getSchemaDiscriminatorByValue.js +1 -1
  17. package/lib/helpers/document/handleSpreadDoc.js +1 -1
  18. package/lib/helpers/each.js +1 -1
  19. package/lib/helpers/get.js +1 -1
  20. package/lib/helpers/getConstructorName.js +1 -1
  21. package/lib/helpers/getDefaultBulkwriteResult.js +1 -1
  22. package/lib/helpers/indexes/applySchemaCollation.js +1 -1
  23. package/lib/helpers/indexes/decorateDiscriminatorIndexOptions.js +1 -1
  24. package/lib/helpers/indexes/isDefaultIdIndex.js +1 -1
  25. package/lib/helpers/indexes/isTextIndex.js +1 -1
  26. package/lib/helpers/isMongooseObject.js +1 -1
  27. package/lib/helpers/isObject.js +1 -1
  28. package/lib/helpers/isPromise.js +1 -1
  29. package/lib/helpers/model/applyHooks.js +1 -1
  30. package/lib/helpers/model/applyStaticHooks.js +1 -1
  31. package/lib/helpers/once.js +1 -1
  32. package/lib/helpers/path/flattenObjectWithDottedPaths.js +1 -1
  33. package/lib/helpers/path/parentPaths.js +1 -1
  34. package/lib/helpers/path/setDottedPath.js +1 -1
  35. package/lib/helpers/pluralize.js +1 -1
  36. package/lib/helpers/populate/SkipPopulateValue.js +1 -1
  37. package/lib/helpers/populate/assignRawDocsToIdStructure.js +1 -1
  38. package/lib/helpers/populate/assignVals.js +1 -1
  39. package/lib/helpers/populate/createPopulateQueryFilter.js +1 -1
  40. package/lib/helpers/populate/getModelsMapForPopulate.js +1 -1
  41. package/lib/helpers/populate/leanPopulateMap.js +1 -1
  42. package/lib/helpers/populate/lookupLocalFields.js +1 -1
  43. package/lib/helpers/populate/markArraySubdocsPopulated.js +1 -1
  44. package/lib/helpers/populate/modelNamesFromRefPath.js +1 -1
  45. package/lib/helpers/populate/removeDeselectedForeignField.js +1 -1
  46. package/lib/helpers/populate/validateRef.js +1 -1
  47. package/lib/helpers/printJestWarning.js +1 -1
  48. package/lib/helpers/processConnectionOptions.js +1 -1
  49. package/lib/helpers/projection/applyProjection.js +1 -1
  50. package/lib/helpers/projection/hasIncludedChildren.js +1 -1
  51. package/lib/helpers/projection/parseProjection.js +1 -1
  52. package/lib/helpers/query/applyGlobalOption.js +1 -1
  53. package/lib/helpers/query/applyQueryMiddleware.js +1 -1
  54. package/lib/helpers/query/cast$expr.js +1 -1
  55. package/lib/helpers/query/castFilterPath.js +1 -1
  56. package/lib/helpers/query/sanitizeFilter.js +1 -1
  57. package/lib/helpers/query/sanitizeProjection.js +1 -1
  58. package/lib/helpers/query/trusted.js +1 -1
  59. package/lib/helpers/query/validOps.js +1 -1
  60. package/lib/helpers/query/wrapThunk.js +1 -1
  61. package/lib/helpers/schema/addAutoId.js +1 -1
  62. package/lib/helpers/schema/applyPlugins.js +1 -1
  63. package/lib/helpers/schema/cleanPositionalOperators.js +1 -1
  64. package/lib/helpers/schema/getKeysInSchemaOrder.js +1 -1
  65. package/lib/helpers/schema/getPath.js +1 -1
  66. package/lib/helpers/schema/handleIdOption.js +1 -1
  67. package/lib/helpers/schema/handleTimestampOption.js +1 -1
  68. package/lib/helpers/specialProperties.js +1 -1
  69. package/lib/helpers/symbols.js +1 -1
  70. package/lib/helpers/timers.js +1 -1
  71. package/lib/helpers/timestamps/setupTimestamps.js +1 -1
  72. package/lib/helpers/topology/allServersUnknown.js +1 -1
  73. package/lib/helpers/topology/isAtlas.js +1 -1
  74. package/lib/helpers/topology/isSSLError.js +1 -1
  75. package/lib/helpers/update/applyTimestampsToChildren.js +1 -1
  76. package/lib/helpers/update/castArrayFilters.js +1 -1
  77. package/lib/helpers/update/moveImmutableProperties.js +1 -1
  78. package/lib/helpers/update/removeUnusedArrayFilters.js +1 -1
  79. package/lib/helpers/update/updatedPathsByArrayFilter.js +1 -1
  80. package/lib/index.js +2 -2
  81. package/lib/options/PopulateOptions.js +1 -1
  82. package/lib/options/SchemaArrayOptions.js +1 -1
  83. package/lib/options/SchemaBufferOptions.js +1 -1
  84. package/lib/options/SchemaDocumentArrayOptions.js +1 -1
  85. package/lib/options/SchemaMapOptions.js +1 -1
  86. package/lib/options/SchemaNumberOptions.js +1 -1
  87. package/lib/options/SchemaObjectIdOptions.js +1 -1
  88. package/lib/options/SchemaSubdocumentOptions.js +1 -1
  89. package/lib/options/SchemaTypeOptions.js +1 -1
  90. package/lib/options/VirtualOptions.js +1 -1
  91. package/lib/options/propertyOptions.js +1 -1
  92. package/lib/options/removeOptions.js +1 -1
  93. package/lib/options/saveOptions.js +1 -1
  94. package/lib/plugins/trackTransaction.js +1 -1
  95. package/lib/schema/symbols.js +1 -1
  96. package/lib/schema.js +3 -3
  97. package/lib/types/DocumentArray/methods/index.js +1 -1
  98. package/package.json +1 -1
  99. package/types/collection.d.ts +1 -1
  100. package/types/document.d.ts +4 -4
  101. package/types/expressions.d.ts +2 -2
  102. package/types/index.d.ts +1 -1
  103. package/types/indexes.d.ts +2 -2
  104. package/types/inferschematype.d.ts +51 -33
  105. package/types/middlewares.d.ts +1 -1
  106. package/types/models.d.ts +6 -6
  107. package/types/mongooseoptions.d.ts +1 -1
  108. package/types/schemaoptions.d.ts +1 -1
  109. package/types/utility.d.ts +7 -0
package/.eslintrc.json CHANGED
@@ -186,6 +186,7 @@
186
186
  "mocha-no-only/mocha-no-only": [
187
187
  "error"
188
188
  ],
189
- "no-empty": "off"
189
+ "no-empty": "off",
190
+ "eol-last": "warn"
190
191
  }
191
- }
192
+ }
package/lib/cast/date.js CHANGED
@@ -38,4 +38,4 @@ module.exports = function castDate(value) {
38
38
  }
39
39
 
40
40
  assert.ok(false);
41
- };
41
+ };
@@ -33,4 +33,4 @@ module.exports = function castDecimal128(value) {
33
33
  }
34
34
 
35
35
  assert.ok(false);
36
- };
36
+ };
@@ -26,4 +26,4 @@ module.exports = function castObjectId(value) {
26
26
  }
27
27
 
28
28
  return new ObjectId(value);
29
- };
29
+ };
package/lib/cast.js CHANGED
@@ -374,4 +374,4 @@ function _cast(val, numbertype, context) {
374
374
  }
375
375
  }
376
376
  }
377
- }
377
+ }
@@ -9,4 +9,4 @@ exports.Collection = require('./collection');
9
9
  exports.Decimal128 = require('./decimal128');
10
10
  exports.ObjectId = require('./objectid');
11
11
  exports.ReadPreference = require('./ReadPreference');
12
- exports.getConnection = () => require('./connection');
12
+ exports.getConnection = () => require('./connection');
@@ -28,4 +28,4 @@ Object.defineProperty(ParallelValidateError.prototype, 'name', {
28
28
  * exports
29
29
  */
30
30
 
31
- module.exports = ParallelValidateError;
31
+ module.exports = ParallelValidateError;
@@ -34,4 +34,4 @@ module.exports = function prepareDiscriminatorPipeline(pipeline, schema, prefix)
34
34
  originalPipeline.unshift({ $match: match });
35
35
  }
36
36
  }
37
- };
37
+ };
@@ -47,4 +47,4 @@ function handleAccumulator(operator) {
47
47
  operator.$accumulator[key] = String(operator.$accumulator[key]);
48
48
  }
49
49
  }
50
- }
50
+ }
@@ -30,4 +30,4 @@ function arrayDepth(arr) {
30
30
  res.max = res.max + 1;
31
31
 
32
32
  return res;
33
- }
33
+ }
@@ -189,4 +189,4 @@ function createEachAsyncMultiError(aggregatedErrors) {
189
189
  }
190
190
 
191
191
  return new EachAsyncMultiError(aggregatedErrors);
192
- }
192
+ }
@@ -13,4 +13,4 @@ module.exports = function areDiscriminatorValuesEqual(a, b) {
13
13
  return a.toString() === b.toString();
14
14
  }
15
15
  return false;
16
- };
16
+ };
@@ -9,4 +9,4 @@ module.exports = function checkEmbeddedDiscriminatorKeyProjection(userProjection
9
9
  addedPaths[0] === _discriminatorKey) {
10
10
  selected.splice(selected.indexOf(_discriminatorKey), 1);
11
11
  }
12
- };
12
+ };
@@ -22,4 +22,4 @@ module.exports = function getConstructor(Constructor, value) {
22
22
  }
23
23
 
24
24
  return Constructor;
25
- };
25
+ };
@@ -24,4 +24,4 @@ module.exports = function getDiscriminatorByValue(discriminators, value) {
24
24
  }
25
25
  }
26
26
  return null;
27
- };
27
+ };
@@ -23,4 +23,4 @@ module.exports = function getSchemaDiscriminatorByValue(schema, value) {
23
23
  }
24
24
  }
25
25
  return null;
26
- };
26
+ };
@@ -32,4 +32,4 @@ module.exports = function handleSpreadDoc(v, includeExtraKeys) {
32
32
  }
33
33
 
34
34
  return v;
35
- };
35
+ };
@@ -22,4 +22,4 @@ module.exports = function each(arr, cb, done) {
22
22
  }
23
23
  });
24
24
  }
25
- };
25
+ };
@@ -61,4 +61,4 @@ function getProperty(obj, prop) {
61
61
  return obj.get(prop);
62
62
  }
63
63
  return obj[prop];
64
- }
64
+ }
@@ -12,4 +12,4 @@ module.exports = function getConstructorName(val) {
12
12
  return void 0;
13
13
  }
14
14
  return val.constructor.name;
15
- };
15
+ };
@@ -24,4 +24,4 @@ function getDefaultBulkwriteResult() {
24
24
  };
25
25
  }
26
26
 
27
- module.exports = getDefaultBulkwriteResult;
27
+ module.exports = getDefaultBulkwriteResult;
@@ -10,4 +10,4 @@ module.exports = function applySchemaCollation(indexKeys, indexOptions, schemaOp
10
10
  if (schemaOptions.hasOwnProperty('collation') && !indexOptions.hasOwnProperty('collation')) {
11
11
  indexOptions.collation = schemaOptions.collation;
12
12
  }
13
- };
13
+ };
@@ -11,4 +11,4 @@ module.exports = function decorateDiscriminatorIndexOptions(schema, indexOptions
11
11
  indexOptions.partialFilterExpression[discriminatorKey] = discriminatorName;
12
12
  }
13
13
  return indexOptions;
14
- };
14
+ };
@@ -15,4 +15,4 @@ module.exports = function isDefaultIdIndex(index) {
15
15
 
16
16
  const key = get(index, 'key', {});
17
17
  return Object.keys(key).length === 1 && key.hasOwnProperty('_id');
18
- };
18
+ };
@@ -13,4 +13,4 @@ module.exports = function isTextIndex(indexKeys) {
13
13
  }
14
14
 
15
15
  return isTextIndex;
16
- };
16
+ };
@@ -19,4 +19,4 @@ module.exports = function(v) {
19
19
  v.$isMongooseMap // Map
20
20
  )
21
21
  );
22
- };
22
+ };
@@ -13,4 +13,4 @@ module.exports = function(arg) {
13
13
  Buffer.isBuffer(arg) ||
14
14
  Object.prototype.toString.call(arg) === '[object Object]'
15
15
  );
16
- };
16
+ };
@@ -3,4 +3,4 @@ function isPromise(val) {
3
3
  return !!val && (typeof val === 'object' || typeof val === 'function') && typeof val.then === 'function';
4
4
  }
5
5
 
6
- module.exports = isPromise;
6
+ module.exports = isPromise;
@@ -135,4 +135,4 @@ function applyHooks(model, schema, options) {
135
135
  objToDecorate[`$__${method}`] = middleware.
136
136
  createWrapper(method, originalMethod, null, customMethodOptions);
137
137
  }
138
- }
138
+ }
@@ -68,4 +68,4 @@ module.exports = function applyStaticHooks(model, hooks, statics) {
68
68
  };
69
69
  }
70
70
  }
71
- };
71
+ };
@@ -9,4 +9,4 @@ module.exports = function once(fn) {
9
9
  called = true;
10
10
  return fn.apply(null, arguments);
11
11
  };
12
- };
12
+ };
@@ -35,4 +35,4 @@ module.exports = function flattenObjectWithDottedPaths(obj) {
35
35
 
36
36
  flattenObjectWithDottedPaths(obj[key]);
37
37
  }
38
- };
38
+ };
@@ -15,4 +15,4 @@ module.exports = function parentPaths(path) {
15
15
  }
16
16
 
17
17
  return ret;
18
- };
18
+ };
@@ -30,4 +30,4 @@ module.exports = function setDottedPath(obj, path, val) {
30
30
  if (!specialProperties.has(last)) {
31
31
  cur[last] = val;
32
32
  }
33
- };
33
+ };
@@ -91,4 +91,4 @@ function pluralize(str) {
91
91
  }
92
92
  }
93
93
  return str;
94
- }
94
+ }
@@ -7,4 +7,4 @@ module.exports = function SkipPopulateValue(val) {
7
7
 
8
8
  this.val = val;
9
9
  return this;
10
- };
10
+ };
@@ -106,4 +106,4 @@ function assignRawDocsToIdStructure(rawIds, resultDocs, resultOrder, options, re
106
106
  rawIds[i] = doc;
107
107
  });
108
108
  }
109
- }
109
+ }
@@ -320,4 +320,4 @@ function isPopulatedObject(obj) {
320
320
 
321
321
  function noop(v) {
322
322
  return v;
323
- }
323
+ }
@@ -77,4 +77,4 @@ function _formatMatch(match) {
77
77
  return Object.assign({}, match[0]);
78
78
  }
79
79
  return Object.assign({}, match);
80
- }
80
+ }
@@ -726,4 +726,4 @@ function _findRefPathForDiscriminators(doc, modelSchema, data, options, normaliz
726
726
  }
727
727
 
728
728
  return modelNames;
729
- }
729
+ }
@@ -4,4 +4,4 @@
4
4
  * ignore
5
5
  */
6
6
 
7
- module.exports = new WeakMap();
7
+ module.exports = new WeakMap();
@@ -37,4 +37,4 @@ module.exports = function lookupLocalFields(cur, path, val) {
37
37
  }
38
38
 
39
39
  return cur[path];
40
- };
40
+ };
@@ -39,4 +39,4 @@ module.exports = function markArraySubdocsPopulated(doc, populated) {
39
39
  }
40
40
  }
41
41
  }
42
- };
42
+ };
@@ -65,4 +65,4 @@ module.exports = function modelNamesFromRefPath(refPath, doc, populatedPath, mod
65
65
  modelNames = utils.array.flatten(modelNames);
66
66
 
67
67
  return modelNames;
68
- };
68
+ };
@@ -28,4 +28,4 @@ module.exports = function removeDeselectedForeignField(foreignFields, options, d
28
28
  }
29
29
  }
30
30
  }
31
- };
31
+ };
@@ -16,4 +16,4 @@ function validateRef(ref, path) {
16
16
 
17
17
  throw new MongooseError('Invalid ref at path "' + path + '". Got ' +
18
18
  util.inspect(ref, { depth: 0 }));
19
- }
19
+ }
@@ -14,4 +14,4 @@ if (typeof jest !== 'undefined' && process.nextTick.toString().indexOf('nextTick
14
14
  'with Jest\'s mock timers enabled. Please make sure you read ' +
15
15
  'Mongoose\'s docs on configuring Jest to test Node.js apps: ' +
16
16
  'https://mongoosejs.com/docs/jest.html');
17
- }
17
+ }
@@ -9,7 +9,7 @@ function processConnectionOptions(uri, options) {
9
9
  ? opts.readPreference
10
10
  : getUriReadPreference(uri);
11
11
 
12
- const resolvedOpts = (readPreference && readPreference !== 'primary')
12
+ const resolvedOpts = (readPreference && readPreference !== 'primary' && readPreference !== 'primaryPreferred')
13
13
  ? resolveOptsConflicts(readPreference, opts)
14
14
  : opts;
15
15
 
@@ -74,4 +74,4 @@ function applyInclusiveProjection(doc, projection, hasIncludedChildren, projecti
74
74
  }
75
75
  }
76
76
  return ret;
77
- }
77
+ }
@@ -33,4 +33,4 @@ module.exports = function hasIncludedChildren(fields) {
33
33
  }
34
34
 
35
35
  return hasIncludedChildren;
36
- };
36
+ };
@@ -30,4 +30,4 @@ module.exports = function parseProjection(v, retainMinusPaths) {
30
30
  }
31
31
 
32
32
  return ret;
33
- };
33
+ };
@@ -26,4 +26,4 @@ function applyGlobalOption(options, model, optionName) {
26
26
  } else if (utils.hasUserDefinedProperty(model.base.options, optionName)) {
27
27
  options[optionName] = model.base.options[optionName];
28
28
  }
29
- }
29
+ }
@@ -75,4 +75,4 @@ function _getContexts(hook) {
75
75
  ret.document = hook.document;
76
76
  }
77
77
  return ret;
78
- }
78
+ }
@@ -279,4 +279,4 @@ function isLiteral(val) {
279
279
  return val.$literal != null;
280
280
  }
281
281
  return true;
282
- }
282
+ }
@@ -51,4 +51,4 @@ module.exports = function castFilterPath(query, schematype, val) {
51
51
  }
52
52
 
53
53
  return val;
54
- };
54
+ };
@@ -35,4 +35,4 @@ module.exports = function sanitizeFilter(filter) {
35
35
  }
36
36
 
37
37
  return filter;
38
- };
38
+ };
@@ -11,4 +11,4 @@ module.exports = function sanitizeProjection(projection) {
11
11
  projection[keys[i]] = 1;
12
12
  }
13
13
  }
14
- };
14
+ };
@@ -10,4 +10,4 @@ exports.trusted = function trusted(obj) {
10
10
  }
11
11
  obj[trustedSymbol] = true;
12
12
  return obj;
13
- };
13
+ };
@@ -21,4 +21,4 @@ module.exports = Object.freeze([
21
21
  'findOneAndDelete',
22
22
  'findOneAndRemove',
23
23
  'remove'
24
- ]);
24
+ ]);
@@ -26,4 +26,4 @@ module.exports = function wrapThunk(fn) {
26
26
 
27
27
  fn.call(this, cb);
28
28
  };
29
- };
29
+ };
@@ -4,4 +4,4 @@ module.exports = function addAutoId(schema) {
4
4
  const _obj = { _id: { auto: true } };
5
5
  _obj._id[schema.options.typeKey] = 'ObjectId';
6
6
  schema.add(_obj);
7
- };
7
+ };
@@ -52,4 +52,4 @@ module.exports = function applyPlugins(schema, plugins, options, cacheKey) {
52
52
  applyPlugins(discriminatorSchema, plugins,
53
53
  { skipTopLevel: !applyPluginsToDiscriminators }, cacheKey);
54
54
  }
55
- };
55
+ };
@@ -9,4 +9,4 @@ module.exports = function cleanPositionalOperators(path) {
9
9
  return path.
10
10
  replace(/\.\$(\[[^\]]*\])?(?=\.)/g, '.0').
11
11
  replace(/\.\$(\[[^\]]*\])?$/g, '.0');
12
- };
12
+ };
@@ -25,4 +25,4 @@ module.exports = function getKeysInSchemaOrder(schema, val, path) {
25
25
  }
26
26
 
27
27
  return keys;
28
- };
28
+ };
@@ -34,4 +34,4 @@ module.exports = function getPath(schema, path) {
34
34
  }
35
35
 
36
36
  return schematype;
37
- };
37
+ };
@@ -17,4 +17,4 @@ module.exports = function handleIdOption(schema, options) {
17
17
  }
18
18
 
19
19
  return schema;
20
- };
20
+ };
@@ -21,4 +21,4 @@ function handleTimestampOption(arg, prop) {
21
21
  return prop;
22
22
  }
23
23
  return arg[prop];
24
- }
24
+ }
@@ -1,3 +1,3 @@
1
1
  'use strict';
2
2
 
3
- module.exports = new Set(['__proto__', 'constructor', 'prototype']);
3
+ module.exports = new Set(['__proto__', 'constructor', 'prototype']);
@@ -17,4 +17,4 @@ exports.populateModelSymbol = Symbol('mongoose.PopulateOptions#Model');
17
17
  exports.schemaTypeSymbol = Symbol('mongoose#schemaType');
18
18
  exports.sessionNewDocuments = Symbol('mongoose:ClientSession#newDocuments');
19
19
  exports.scopeSymbol = Symbol('mongoose#Document#scope');
20
- exports.validatorErrorSymbol = Symbol('mongoose:validatorError');
20
+ exports.validatorErrorSymbol = Symbol('mongoose:validatorError');
@@ -1,3 +1,3 @@
1
1
  'use strict';
2
2
 
3
- exports.setTimeout = setTimeout;
3
+ exports.setTimeout = setTimeout;
@@ -102,4 +102,4 @@ module.exports = function setupTimestamps(schema, timestamps) {
102
102
  applyTimestampsToChildren(now, this.getUpdate(), this.model.schema);
103
103
  next();
104
104
  }
105
- };
105
+ };
@@ -9,4 +9,4 @@ module.exports = function allServersUnknown(topologyDescription) {
9
9
 
10
10
  const servers = Array.from(topologyDescription.servers.values());
11
11
  return servers.length > 0 && servers.every(server => server.type === 'Unknown');
12
- };
12
+ };
@@ -23,4 +23,4 @@ module.exports = function isAtlas(topologyDescription) {
23
23
  }
24
24
  }
25
25
  return true;
26
- };
26
+ };
@@ -13,4 +13,4 @@ module.exports = function isSSLError(topologyDescription) {
13
13
  const descriptions = Array.from(topologyDescription.servers.values());
14
14
  return descriptions.length > 0 &&
15
15
  descriptions.every(descr => descr.error && descr.error.message.indexOf(nonSSLMessage) !== -1);
16
- };
16
+ };
@@ -186,4 +186,4 @@ function applyTimestampsToUpdateKey(schema, key, update, now) {
186
186
  update[key][createdAt] = now;
187
187
  }
188
188
  }
189
- }
189
+ }
@@ -80,4 +80,4 @@ function _castArrayFilters(arrayFilters, schema, strictQuery, updatedPathsByFilt
80
80
  }
81
81
  }
82
82
  }
83
- }
83
+ }
@@ -50,4 +50,4 @@ function _walkUpdatePath(schema, op, path, update, ctx) {
50
50
  update.$setOnInsert = update.$setOnInsert || {};
51
51
  update.$setOnInsert[path] = op[path];
52
52
  delete op[path];
53
- }
53
+ }
@@ -29,4 +29,4 @@ function _checkSingleFilterKey(arrayFilter, updateKeys) {
29
29
  const arrayFilterKey = firstDot === -1 ? firstKey : firstKey.slice(0, firstDot);
30
30
 
31
31
  return updateKeys.find(key => key.includes('$[' + arrayFilterKey + ']')) != null;
32
- }
32
+ }
@@ -24,4 +24,4 @@ module.exports = function updatedPathsByArrayFilter(update) {
24
24
  }
25
25
  return cur;
26
26
  }, {});
27
- };
27
+ };
package/lib/index.js CHANGED
@@ -1223,7 +1223,7 @@ Mongoose.prototype._promiseOrCallback = function(callback, fn, ee) {
1223
1223
  /**
1224
1224
  * Use this function in `pre()` middleware to skip calling the wrapped function.
1225
1225
  *
1226
- * ####Example:
1226
+ * #### Example:
1227
1227
  *
1228
1228
  * schema.pre('save', function() {
1229
1229
  * // Will skip executing `save()`, but will execute post hooks as if
@@ -1241,7 +1241,7 @@ Mongoose.prototype.skipMiddlewareFunction = Kareem.skipWrappedFunction;
1241
1241
  /**
1242
1242
  * Use this function in `post()` middleware to replace the result
1243
1243
  *
1244
- * ####Example:
1244
+ * #### Example:
1245
1245
  *
1246
1246
  * schema.post('find', function(res) {
1247
1247
  * // Normally you have to modify `res` in place. But with
@@ -33,4 +33,4 @@ class PopulateOptions {
33
33
  * @api public
34
34
  */
35
35
 
36
- module.exports = PopulateOptions;
36
+ module.exports = PopulateOptions;
@@ -56,4 +56,4 @@ Object.defineProperty(SchemaArrayOptions.prototype, 'of', opts);
56
56
  * ignore
57
57
  */
58
58
 
59
- module.exports = SchemaArrayOptions;
59
+ module.exports = SchemaArrayOptions;
@@ -35,4 +35,4 @@ Object.defineProperty(SchemaBufferOptions.prototype, 'subtype', opts);
35
35
  * ignore
36
36
  */
37
37
 
38
- module.exports = SchemaBufferOptions;
38
+ module.exports = SchemaBufferOptions;
@@ -65,4 +65,4 @@ Object.defineProperty(SchemaDocumentArrayOptions.prototype, '_id', opts);
65
65
  * ignore
66
66
  */
67
67
 
68
- module.exports = SchemaDocumentArrayOptions;
68
+ module.exports = SchemaDocumentArrayOptions;
@@ -40,4 +40,4 @@ const opts = require('./propertyOptions');
40
40
 
41
41
  Object.defineProperty(SchemaMapOptions.prototype, 'of', opts);
42
42
 
43
- module.exports = SchemaMapOptions;
43
+ module.exports = SchemaMapOptions;
@@ -96,4 +96,4 @@ Object.defineProperty(SchemaNumberOptions.prototype, 'populate', opts);
96
96
  * ignore
97
97
  */
98
98
 
99
- module.exports = SchemaNumberOptions;
99
+ module.exports = SchemaNumberOptions;
@@ -60,4 +60,4 @@ Object.defineProperty(SchemaObjectIdOptions.prototype, 'populate', opts);
60
60
  * ignore
61
61
  */
62
62
 
63
- module.exports = SchemaObjectIdOptions;
63
+ module.exports = SchemaObjectIdOptions;
@@ -39,4 +39,4 @@ const opts = require('./propertyOptions');
39
39
 
40
40
  Object.defineProperty(SchemaSubdocumentOptions.prototype, '_id', opts);
41
41
 
42
- module.exports = SchemaSubdocumentOptions;
42
+ module.exports = SchemaSubdocumentOptions;
@@ -241,4 +241,4 @@ Object.defineProperty(SchemaTypeOptions.prototype, 'text', opts);
241
241
 
242
242
  Object.defineProperty(SchemaTypeOptions.prototype, 'transform', opts);
243
243
 
244
- module.exports = SchemaTypeOptions;
244
+ module.exports = SchemaTypeOptions;
@@ -161,4 +161,4 @@ Object.defineProperty(VirtualOptions.prototype, 'limit', opts);
161
161
 
162
162
  Object.defineProperty(VirtualOptions.prototype, 'perDocumentLimit', opts);
163
163
 
164
- module.exports = VirtualOptions;
164
+ module.exports = VirtualOptions;
@@ -5,4 +5,4 @@ module.exports = Object.freeze({
5
5
  configurable: true,
6
6
  writable: true,
7
7
  value: void 0
8
- });
8
+ });
@@ -11,4 +11,4 @@ class RemoveOptions {
11
11
  }
12
12
  }
13
13
 
14
- module.exports = RemoveOptions;
14
+ module.exports = RemoveOptions;
@@ -11,4 +11,4 @@ class SaveOptions {
11
11
  }
12
12
  }
13
13
 
14
- module.exports = SaveOptions;
14
+ module.exports = SaveOptions;
@@ -89,4 +89,4 @@ function mergeAtomics(destination, source) {
89
89
  }
90
90
 
91
91
  return destination;
92
- }
92
+ }
@@ -2,4 +2,4 @@
2
2
 
3
3
  exports.schemaMixedSymbol = Symbol.for('mongoose:schema_mixed');
4
4
 
5
- exports.builtInMiddleware = Symbol.for('mongoose:built-in-middleware');
5
+ exports.builtInMiddleware = Symbol.for('mongoose:built-in-middleware');
package/lib/schema.js CHANGED
@@ -477,7 +477,7 @@ Schema.prototype.defaultOptions = function(options) {
477
477
  * Inherit a Schema by applying a discriminator on an existing Schema.
478
478
  *
479
479
  *
480
- * ####Example:
480
+ * #### Example:
481
481
  *
482
482
  * const options = { discriminatorKey: 'kind' };
483
483
  *
@@ -648,7 +648,7 @@ Schema.prototype.add = function add(obj, prefix) {
648
648
  * removeIndex only removes indexes from your schema object. Does **not** affect the indexes
649
649
  * in MongoDB.
650
650
  *
651
- * ####Example:
651
+ * #### Example:
652
652
  *
653
653
  * const ToySchema = new Schema({ name: String, color: String, price: Number });
654
654
  *
@@ -701,7 +701,7 @@ Schema.prototype.removeIndex = function removeIndex(index) {
701
701
  * clearIndexes only removes indexes from your schema object. Does **not** affect the indexes
702
702
  * in MongoDB.
703
703
  *
704
- * ####Example:
704
+ * #### Example:
705
705
  *
706
706
  * const ToySchema = new Schema({ name: String, color: String, price: Number });
707
707
  * ToySchema.index({ name: 1 });
@@ -376,4 +376,4 @@ function _updateParentPopulated(arr) {
376
376
 
377
377
  parent.$__.populated[path].value = arr.map(val => val.$populated(remnant));
378
378
  }
379
- }
379
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mongoose",
3
3
  "description": "Mongoose MongoDB ODM",
4
- "version": "6.4.1",
4
+ "version": "6.4.2",
5
5
  "author": "Guillermo Rauch <guillermo@learnboost.com>",
6
6
  "keywords": [
7
7
  "mongodb",
@@ -43,4 +43,4 @@ declare module 'mongoose' {
43
43
  getIndexes(): ReturnType<mongodb.Collection<T>['indexInformation']>;
44
44
  }
45
45
  let Collection: Collection;
46
- }
46
+ }
@@ -200,10 +200,10 @@ declare module 'mongoose' {
200
200
  $parent(): Document | undefined;
201
201
 
202
202
  /** Populates document references. */
203
- populate<Paths = {}>(path: string | PopulateOptions | (string | PopulateOptions)[]): Promise<this & Paths>;
204
- populate<Paths = {}>(path: string | PopulateOptions | (string | PopulateOptions)[], callback: Callback<this & Paths>): void;
205
- populate<Paths = {}>(path: string, select?: string | AnyObject, model?: Model<any>, match?: AnyObject, options?: PopulateOptions): Promise<this & Paths>;
206
- populate<Paths = {}>(path: string, select?: string | AnyObject, model?: Model<any>, match?: AnyObject, options?: PopulateOptions, callback?: Callback<this & Paths>): void;
203
+ populate<Paths = {}>(path: string | PopulateOptions | (string | PopulateOptions)[]): Promise<MergeType<this, Paths>>;
204
+ populate<Paths = {}>(path: string | PopulateOptions | (string | PopulateOptions)[], callback: Callback<MergeType<this, Paths>>): void;
205
+ populate<Paths = {}>(path: string, select?: string | AnyObject, model?: Model<any>, match?: AnyObject, options?: PopulateOptions): Promise<MergeType<this, Paths>>;
206
+ populate<Paths = {}>(path: string, select?: string | AnyObject, model?: Model<any>, match?: AnyObject, options?: PopulateOptions, callback?: Callback<MergeType<this, Paths>>): void;
207
207
 
208
208
  /** Gets _id(s) used during population of the given `path`. If the path was not populated, returns `undefined`. */
209
209
  populated(path: string): any;
@@ -1034,7 +1034,7 @@ declare module 'mongoose' {
1034
1034
  *
1035
1035
  * @see https://docs.mongodb.com/manual/reference/operator/aggregation/ne/#mongodb-expression-exp.-ne
1036
1036
  */
1037
- $ne: Expression | [Expression, Expression] | null;
1037
+ $ne: Expression | [Expression, Expression | NullExpression] | null;
1038
1038
  }
1039
1039
 
1040
1040
  export interface Cond {
@@ -2879,4 +2879,4 @@ declare module 'mongoose' {
2879
2879
  export type DateExpressionOperatorReturningString =
2880
2880
  Expression.DateToString;
2881
2881
 
2882
- }
2882
+ }
package/types/index.d.ts CHANGED
@@ -166,7 +166,7 @@ declare module 'mongoose' {
166
166
  /**
167
167
  * Create a new schema
168
168
  */
169
- constructor(definition?: SchemaDefinition<SchemaDefinitionType<EnforcedDocType>> | DocType, options?: SchemaOptions<TPathTypeKey, DocType, TInstanceMethods, TQueryHelpers, TStaticMethods>);
169
+ constructor(definition?: SchemaDefinition<SchemaDefinitionType<EnforcedDocType>> | DocType, options?: SchemaOptions<TPathTypeKey, FlatRecord<DocType>, TInstanceMethods, TQueryHelpers, TStaticMethods>);
170
170
 
171
171
  /** Adds key path / schema type pairs to this schema. */
172
172
  add(obj: SchemaDefinition<SchemaDefinitionType<EnforcedDocType>> | Schema, prefix?: string): this;
@@ -93,6 +93,6 @@ declare module 'mongoose' {
93
93
  * ```
94
94
  */
95
95
  expires?: number | string;
96
- weights?: AnyObject;
96
+ weights?: Record<string, number>;
97
97
  }
98
- }
98
+ }
@@ -1,4 +1,4 @@
1
- import { Schema, InferSchemaType, SchemaType, SchemaTypeOptions, TypeKeyBaseType } from 'mongoose';
1
+ import { Schema, InferSchemaType, SchemaType, SchemaTypeOptions, TypeKeyBaseType, Types, NumberSchemaDefinition, StringSchemaDefinition, BooleanSchemaDefinition, DateSchemaDefinition } from 'mongoose';
2
2
 
3
3
  declare module 'mongoose' {
4
4
  /**
@@ -6,13 +6,13 @@ declare module 'mongoose' {
6
6
  * @description Obtains document schema type from document Definition OR returns enforced schema type if it's provided.
7
7
  * @param {DocDefinition} DocDefinition A generic equals to the type of document definition "provided in as first parameter in Schema constructor".
8
8
  * @param {EnforcedDocType} EnforcedDocType A generic type enforced by user "provided before schema constructor".
9
- * @param {TypeKey} TypeKey A generic of literal string type.
9
+ * @param {TypeKey} TypeKey A generic of literal string type."Refers to the property used for path type definition".
10
10
  */
11
- type ObtainDocumentType<DocDefinition, EnforcedDocType = any, TypeKey extends TypeKeyBaseType = DefaultTypeKey> =
12
- IsItRecordAndNotAny<EnforcedDocType> extends true ? EnforcedDocType : {
13
- [K in keyof (RequiredPaths<DocDefinition> &
14
- OptionalPaths<DocDefinition>)]: ObtainDocumentPathType<DocDefinition[K], TypeKey>;
15
- };
11
+ type ObtainDocumentType<DocDefinition, EnforcedDocType = any, TypeKey extends TypeKeyBaseType = DefaultTypeKey> =
12
+ IsItRecordAndNotAny<EnforcedDocType> extends true ? EnforcedDocType : {
13
+ [K in keyof (RequiredPaths<DocDefinition, TypeKey> &
14
+ OptionalPaths<DocDefinition, TypeKey>)]: ObtainDocumentPathType<DocDefinition[K], TypeKey>;
15
+ };
16
16
 
17
17
  /**
18
18
  * @summary Obtains document schema type from Schema instance.
@@ -64,10 +64,22 @@ type IfEquals<T, U, Y = true, N = false> =
64
64
  (<G>() => G extends U ? 1 : 0) ? Y : N;
65
65
 
66
66
  /**
67
- * @summary Required path base type.
68
- * @description It helps to check whereas if a path is required OR optional.
67
+ * @summary Checks if a document path is required or optional.
68
+ * @param {P} P Document path.
69
+ * @param {TypeKey} TypeKey A generic of literal string type."Refers to the property used for path type definition".
69
70
  */
70
- type RequiredPathBaseType = { required: true | [true, string | undefined] };
71
+ type IsPathRequired<P, TypeKey extends TypeKeyBaseType> =
72
+ P extends { required: true | [true, string | undefined] } | ArrayConstructor | any[]
73
+ ? true
74
+ : P extends (Record<TypeKey, ArrayConstructor | any[]>)
75
+ ? P extends { default: undefined }
76
+ ? false
77
+ : true
78
+ : P extends (Record<TypeKey, NumberSchemaDefinition | StringSchemaDefinition | BooleanSchemaDefinition | DateSchemaDefinition>)
79
+ ? P extends { default: ResolvePathType<P[TypeKey]> }
80
+ ? true
81
+ : false
82
+ : false;
71
83
 
72
84
  /**
73
85
  * @summary Path base type defined by using TypeKey
@@ -79,37 +91,41 @@ type PathWithTypePropertyBaseType<TypeKey extends TypeKeyBaseType> = { [k in Typ
79
91
  /**
80
92
  * @summary A Utility to obtain schema's required path keys.
81
93
  * @param {T} T A generic refers to document definition.
94
+ * @param {TypeKey} TypeKey A generic of literal string type."Refers to the property used for path type definition".
82
95
  * @returns required paths keys of document definition.
83
96
  */
84
- type RequiredPathKeys<T> = {
85
- [K in keyof T]: T[K] extends RequiredPathBaseType ? IfEquals<T[K], any, never, K> : never;
97
+ type RequiredPathKeys<T, TypeKey extends TypeKeyBaseType> = {
98
+ [K in keyof T]: IsPathRequired<T[K], TypeKey> extends true ? IfEquals<T[K], any, never, K> : never;
86
99
  }[keyof T];
87
100
 
88
101
  /**
89
102
  * @summary A Utility to obtain schema's required paths.
90
103
  * @param {T} T A generic refers to document definition.
104
+ * @param {TypeKey} TypeKey A generic of literal string type."Refers to the property used for path type definition".
91
105
  * @returns a record contains required paths with the corresponding type.
92
106
  */
93
- type RequiredPaths<T> = {
94
- [K in RequiredPathKeys<T>]: T[K];
107
+ type RequiredPaths<T, TypeKey extends TypeKeyBaseType> = {
108
+ [K in RequiredPathKeys<T, TypeKey>]: T[K];
95
109
  };
96
110
 
97
111
  /**
98
112
  * @summary A Utility to obtain schema's optional path keys.
99
113
  * @param {T} T A generic refers to document definition.
114
+ * @param {TypeKey} TypeKey A generic of literal string type."Refers to the property used for path type definition".
100
115
  * @returns optional paths keys of document definition.
101
116
  */
102
- type OptionalPathKeys<T> = {
103
- [K in keyof T]: T[K] extends RequiredPathBaseType ? never : K;
117
+ type OptionalPathKeys<T, TypeKey extends TypeKeyBaseType> = {
118
+ [K in keyof T]: IsPathRequired<T[K], TypeKey> extends true ? never : K;
104
119
  }[keyof T];
105
120
 
106
121
  /**
107
122
  * @summary A Utility to obtain schema's optional paths.
108
123
  * @param {T} T A generic refers to document definition.
124
+ * @param {TypeKey} TypeKey A generic of literal string type."Refers to the property used for path type definition".
109
125
  * @returns a record contains optional paths with the corresponding type.
110
126
  */
111
- type OptionalPaths<T> = {
112
- [K in OptionalPathKeys<T>]?: T[K];
127
+ type OptionalPaths<T, TypeKey extends TypeKeyBaseType> = {
128
+ [K in OptionalPathKeys<T, TypeKey>]?: T[K];
113
129
  };
114
130
 
115
131
  /**
@@ -138,18 +154,20 @@ type PathEnumOrString<T extends SchemaTypeOptions<string>['enum']> = T extends (
138
154
  * @returns Number, "Number" or "number" will be resolved to string type.
139
155
  */
140
156
  type ResolvePathType<PathValueType, Options extends SchemaTypeOptions<PathValueType> = {}> =
141
- PathValueType extends (infer Item)[] ? IfEquals<Item, never, any, ResolvePathType<Item>>[] :
142
- PathValueType extends StringConstructor | 'string' | 'String' | typeof Schema.Types.String ? PathEnumOrString<Options['enum']> :
143
- PathValueType extends NumberConstructor | 'number' | 'Number' | typeof Schema.Types.Number ? number :
144
- PathValueType extends DateConstructor | 'date' | 'Date' | typeof Schema.Types.Date ? Date :
145
- PathValueType extends typeof Buffer | 'buffer' | 'Buffer' | typeof Schema.Types.Buffer ? Buffer :
146
- PathValueType extends BooleanConstructor | 'boolean' | 'Boolean' | typeof Schema.Types.Boolean ? boolean :
147
- PathValueType extends 'objectId' | 'ObjectId' | typeof Schema.Types.ObjectId ? Schema.Types.ObjectId :
148
- PathValueType extends 'decimal128' | 'Decimal128' | typeof Schema.Types.Decimal128 ? Schema.Types.Decimal128 :
149
- PathValueType extends MapConstructor ? Map<string, ResolvePathType<Options['of']>> :
150
- PathValueType extends ArrayConstructor ? any[] :
151
- PathValueType extends typeof Schema.Types.Mixed ? any:
152
- IfEquals<PathValueType, ObjectConstructor> extends true ? any:
153
- IfEquals<PathValueType, {}> extends true ? any:
154
- PathValueType extends typeof SchemaType ? PathValueType['prototype'] :
155
- unknown;
157
+ PathValueType extends Schema ? InferSchemaType<PathValueType> :
158
+ PathValueType extends (infer Item)[] ? IfEquals<Item, never, any, ResolvePathType<Item>>[] :
159
+ PathValueType extends StringSchemaDefinition ? PathEnumOrString<Options['enum']> :
160
+ PathValueType extends NumberSchemaDefinition ? number :
161
+ PathValueType extends DateSchemaDefinition ? Date :
162
+ PathValueType extends typeof Buffer | 'buffer' | 'Buffer' | typeof Schema.Types.Buffer ? Buffer :
163
+ PathValueType extends BooleanSchemaDefinition ? boolean :
164
+ PathValueType extends 'objectId' | 'ObjectId' | typeof Schema.Types.ObjectId ? Types.ObjectId :
165
+ PathValueType extends 'decimal128' | 'Decimal128' | typeof Schema.Types.Decimal128 ? Types.Decimal128 :
166
+ PathValueType extends MapConstructor ? Map<string, ResolvePathType<Options['of']>> :
167
+ PathValueType extends ArrayConstructor ? any[] :
168
+ PathValueType extends typeof Schema.Types.Mixed ? any:
169
+ IfEquals<PathValueType, ObjectConstructor> extends true ? any:
170
+ IfEquals<PathValueType, {}> extends true ? any:
171
+ PathValueType extends typeof SchemaType ? PathValueType['prototype'] :
172
+ PathValueType extends {} ? PathValueType :
173
+ unknown;
@@ -11,4 +11,4 @@ declare module 'mongoose' {
11
11
  type PreSaveMiddlewareFunction<ThisType = any> = (this: ThisType, next: CallbackWithoutResultAndOptionalError, opts: SaveOptions) => void | Promise<void>;
12
12
  type PostMiddlewareFunction<ThisType = any, ResType = any> = (this: ThisType, res: ResType, next: CallbackWithoutResultAndOptionalError) => void | Promise<void>;
13
13
  type ErrorHandlingMiddlewareFunction<ThisType = any, ResType = any> = (this: ThisType, err: NativeError, res: ResType, next: CallbackWithoutResultAndOptionalError) => void;
14
- }
14
+ }
package/types/models.d.ts CHANGED
@@ -163,11 +163,11 @@ declare module 'mongoose' {
163
163
  countDocuments(callback?: Callback<number>): QueryWithHelpers<number, HydratedDocument<T, TMethodsAndOverrides, TVirtuals>, TQueryHelpers, T>;
164
164
 
165
165
  /** Creates a new document or documents */
166
- create<DocContents = T>(docs: Array<T | DocContents>, options?: SaveOptions): Promise<HydratedDocument<MergeType<MergeType<T, DocContents>, RequireOnlyTypedId<T>>, TMethodsAndOverrides, TVirtuals>[]>;
167
- create<DocContents = T>(docs: Array<T | DocContents>, callback: Callback<HydratedDocument<MergeType<MergeType<T, DocContents>, RequireOnlyTypedId<T>>, TMethodsAndOverrides, TVirtuals>[]>): void;
168
- create<DocContents = T>(doc: DocContents | T): Promise<HydratedDocument<MergeType<MergeType<T, DocContents>, RequireOnlyTypedId<T>>, TMethodsAndOverrides, TVirtuals>>;
169
- create<DocContents = T>(...docs: Array<T | DocContents>): Promise<HydratedDocument<MergeType<MergeType<T, DocContents>, RequireOnlyTypedId<T>>, TMethodsAndOverrides, TVirtuals>[]>;
170
- create<DocContents = T>(doc: T | DocContents, callback: Callback<HydratedDocument<MergeType<MergeType<T, DocContents>, RequireOnlyTypedId<T>>, TMethodsAndOverrides, TVirtuals>>): void;
166
+ create<DocContents = AnyKeys<T>>(docs: Array<T | DocContents>, options?: SaveOptions): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>[]>;
167
+ create<DocContents = AnyKeys<T>>(docs: Array<T | DocContents>, callback: Callback<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>[]>): void;
168
+ create<DocContents = AnyKeys<T>>(doc: DocContents | T): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>;
169
+ create<DocContents = AnyKeys<T>>(...docs: Array<T | DocContents>): Promise<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>[]>;
170
+ create<DocContents = AnyKeys<T>>(doc: T | DocContents, callback: Callback<HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>): void;
171
171
 
172
172
  /**
173
173
  * Create the collection for this model. By default, if no indexes are specified,
@@ -431,4 +431,4 @@ declare module 'mongoose' {
431
431
  where<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(obj: object): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
432
432
  where<ResultDoc = HydratedDocument<T, TMethodsAndOverrides, TVirtuals>>(): QueryWithHelpers<Array<ResultDoc>, ResultDoc, TQueryHelpers, T>;
433
433
  }
434
- }
434
+ }
@@ -190,4 +190,4 @@ declare module 'mongoose' {
190
190
  */
191
191
  toObject?: ToObjectOptions;
192
192
  }
193
- }
193
+ }
@@ -203,4 +203,4 @@ declare module 'mongoose' {
203
203
  */
204
204
  query?: Record<any, <T extends QueryWithHelpers<unknown, DocType>>(this: T, ...args: any) => T> | QueryHelpers,
205
205
  }
206
- }
206
+ }
@@ -12,4 +12,11 @@ declare module 'mongoose' {
12
12
 
13
13
  type MergeType<A, B> = Omit<A, keyof B> & B;
14
14
 
15
+ /**
16
+ * @summary Converts Unions to one record "object".
17
+ * @description It makes intellisense dialog box easier to read as a single object instead of showing that in multiple object unions.
18
+ * @param {T} T The type to be converted.
19
+ */
20
+ type FlatRecord<T> = { [K in keyof T]: T[K] };
21
+
15
22
  }