cqm-models 3.1.1 → 3.1.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.
data/dist/browser.js CHANGED
@@ -3408,7 +3408,7 @@ function Any(key, options) {
3408
3408
  Any.prototype = Object.create(mongoose.SchemaType.prototype);
3409
3409
 
3410
3410
  function RecursiveCast(any) {
3411
- if (any && any.value && any.unit) {
3411
+ if (any && any.value !== undefined && any.unit) {
3412
3412
  return new cql.Quantity(any.value, any.unit);
3413
3413
  }
3414
3414
 
@@ -7032,8 +7032,8 @@ class Unit {
7032
7032
  * concatenated string. Basically it checks to see if the string
7033
7033
  * needs to be enclosed either in parentheses or square brackets.
7034
7034
  *
7035
- * The string is enclosed if it is not a number, does not start with
7036
- * a parenthesis or square bracket, and includes a period, and asterisk,
7035
+ * The string is enclosed if it is not a number, is not already enclosed in a pair of
7036
+ * parentheses or square brackets, and includes a period, and asterisk,
7037
7037
  * a slash or a blank space.
7038
7038
  *
7039
7039
  * @param str the string
@@ -7049,7 +7049,7 @@ class Unit {
7049
7049
  if (intUtils_.isNumericString(str)) {
7050
7050
  ret = str;
7051
7051
  } else {
7052
- if (str.charAt(0) === '(' || str.charAt(0) === '[') {
7052
+ if (str.charAt(0) === '(' && str.endsWith(')') || str.charAt(0) === '[' && str.endsWith(']')) {
7053
7053
  ret = str;
7054
7054
  } else if (/[./* ]/.test(str)) {
7055
7055
  ret = startChar + str + endChar;
@@ -9931,7 +9931,7 @@ var objectKeys = Object.keys || function (obj) {
9931
9931
  };
9932
9932
 
9933
9933
  }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
9934
- },{"object-assign":324,"util/":106}],104:[function(require,module,exports){
9934
+ },{"object-assign":326,"util/":106}],104:[function(require,module,exports){
9935
9935
  if (typeof Object.create === 'function') {
9936
9936
  // implementation from standard node.js 'util' module
9937
9937
  module.exports = function inherits(ctor, superCtor) {
@@ -10553,7 +10553,7 @@ function hasOwnProperty(obj, prop) {
10553
10553
  }
10554
10554
 
10555
10555
  }).call(this)}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
10556
- },{"./support/isBuffer":105,"_process":325,"inherits":104}],107:[function(require,module,exports){
10556
+ },{"./support/isBuffer":105,"_process":327,"inherits":104}],107:[function(require,module,exports){
10557
10557
  'use strict'
10558
10558
 
10559
10559
  exports.byteLength = byteLength
@@ -16331,7 +16331,7 @@ module.exports = ret;
16331
16331
  },{"./es5":13}]},{},[4])(4)
16332
16332
  }); ;if (typeof window !== 'undefined' && window !== null) { window.P = window.Promise; } else if (typeof self !== 'undefined' && self !== null) { self.P = self.Promise; }
16333
16333
  }).call(this)}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("timers").setImmediate)
16334
- },{"_process":325,"timers":329}],109:[function(require,module,exports){
16334
+ },{"_process":327,"timers":331}],109:[function(require,module,exports){
16335
16335
  (function (global){(function (){
16336
16336
  /**
16337
16337
  * Module dependencies.
@@ -18265,6 +18265,11 @@ Long.prototype.toNumber = function() {
18265
18265
  return this.high_ * Long.TWO_PWR_32_DBL_ + this.getLowBitsUnsigned();
18266
18266
  };
18267
18267
 
18268
+ /** Converts the Long to a BigInt (arbitrary precision). */
18269
+ Long.prototype.toBigInt = function () {
18270
+ return BigInt(this.toString());
18271
+ }
18272
+
18268
18273
  /**
18269
18274
  * Return the JSON value.
18270
18275
  *
@@ -18899,6 +18904,15 @@ Long.fromNumber = function(value) {
18899
18904
  }
18900
18905
  };
18901
18906
 
18907
+ /**
18908
+ * Returns a Long representing the given value, provided that it is a finite number. Otherwise, zero is returned.
18909
+ * @param {bigint} value - The number in question
18910
+ * @returns {Long} The corresponding Long value
18911
+ */
18912
+ Long.fromBigInt = function(value) {
18913
+ return Long.fromString(value.toString(10), 10);
18914
+ }
18915
+
18902
18916
  /**
18903
18917
  * Returns a Long representing the 64-bit integer that comes by concatenating the given high and low bits. Each is assumed to use 32 bits.
18904
18918
  *
@@ -19598,7 +19612,7 @@ module.exports.ObjectID = ObjectID;
19598
19612
  module.exports.ObjectId = ObjectID;
19599
19613
 
19600
19614
  }).call(this)}).call(this,require('_process'),require("buffer").Buffer)
19601
- },{"./parser/utils":125,"_process":325,"buffer":129,"util":332}],122:[function(require,module,exports){
19615
+ },{"./parser/utils":125,"_process":327,"buffer":129,"util":334}],122:[function(require,module,exports){
19602
19616
  (function (Buffer){(function (){
19603
19617
  'use strict';
19604
19618
 
@@ -21354,6 +21368,8 @@ var serializeInto = function serializeInto(
21354
21368
  index = serializeString(buffer, key, value, index, true);
21355
21369
  } else if (type === 'number') {
21356
21370
  index = serializeNumber(buffer, key, value, index, true);
21371
+ } else if(type === 'bigint') {
21372
+ throw new TypeError('Unsupported type BigInt, please use Decimal128');
21357
21373
  } else if (type === 'boolean') {
21358
21374
  index = serializeBoolean(buffer, key, value, index, true);
21359
21375
  } else if (value instanceof Date || isDate(value)) {
@@ -21465,6 +21481,8 @@ var serializeInto = function serializeInto(
21465
21481
  index = serializeString(buffer, key, value, index);
21466
21482
  } else if (type === 'number') {
21467
21483
  index = serializeNumber(buffer, key, value, index);
21484
+ } else if(type === 'bigint') {
21485
+ throw new TypeError('Unsupported type BigInt, please use Decimal128');
21468
21486
  } else if (type === 'boolean') {
21469
21487
  index = serializeBoolean(buffer, key, value, index);
21470
21488
  } else if (value instanceof Date || isDate(value)) {
@@ -21568,6 +21586,8 @@ var serializeInto = function serializeInto(
21568
21586
  index = serializeString(buffer, key, value, index);
21569
21587
  } else if (type === 'number') {
21570
21588
  index = serializeNumber(buffer, key, value, index);
21589
+ } else if(type === 'bigint') {
21590
+ throw new TypeError('Unsupported type BigInt, please use Decimal128');
21571
21591
  } else if (type === 'boolean') {
21572
21592
  index = serializeBoolean(buffer, key, value, index);
21573
21593
  } else if (value instanceof Date || isDate(value)) {
@@ -21954,7 +21974,7 @@ module.exports = Symbol;
21954
21974
  module.exports.Symbol = Symbol;
21955
21975
 
21956
21976
  }).call(this)}).call(this,require("buffer").Buffer)
21957
- },{"buffer":129,"util":332}],128:[function(require,module,exports){
21977
+ },{"buffer":129,"util":334}],128:[function(require,module,exports){
21958
21978
  // Licensed under the Apache License, Version 2.0 (the "License");
21959
21979
  // you may not use this file except in compliance with the License.
21960
21980
  // You may obtain a copy of the License at
@@ -40718,7 +40738,7 @@ function decorateNextFn(fn) {
40718
40738
  module.exports = Kareem;
40719
40739
 
40720
40740
  }).call(this)}).call(this,require('_process'))
40721
- },{"_process":325}],183:[function(require,module,exports){
40741
+ },{"_process":327}],183:[function(require,module,exports){
40722
40742
  'use strict';
40723
40743
 
40724
40744
  Object.defineProperty(exports, '__esModule', { value: true });
@@ -41435,13 +41455,13 @@ var monthsNarrow = ["J", "F", "M", "A", "M", "J", "J", "A", "S", "O", "N", "D"];
41435
41455
  function months(length) {
41436
41456
  switch (length) {
41437
41457
  case "narrow":
41438
- return monthsNarrow;
41458
+ return [].concat(monthsNarrow);
41439
41459
 
41440
41460
  case "short":
41441
- return monthsShort;
41461
+ return [].concat(monthsShort);
41442
41462
 
41443
41463
  case "long":
41444
- return monthsLong;
41464
+ return [].concat(monthsLong);
41445
41465
 
41446
41466
  case "numeric":
41447
41467
  return ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"];
@@ -41459,13 +41479,13 @@ var weekdaysNarrow = ["M", "T", "W", "T", "F", "S", "S"];
41459
41479
  function weekdays(length) {
41460
41480
  switch (length) {
41461
41481
  case "narrow":
41462
- return weekdaysNarrow;
41482
+ return [].concat(weekdaysNarrow);
41463
41483
 
41464
41484
  case "short":
41465
- return weekdaysShort;
41485
+ return [].concat(weekdaysShort);
41466
41486
 
41467
41487
  case "long":
41468
- return weekdaysLong;
41488
+ return [].concat(weekdaysLong);
41469
41489
 
41470
41490
  case "numeric":
41471
41491
  return ["1", "2", "3", "4", "5", "6", "7"];
@@ -41481,13 +41501,13 @@ var erasNarrow = ["B", "A"];
41481
41501
  function eras(length) {
41482
41502
  switch (length) {
41483
41503
  case "narrow":
41484
- return erasNarrow;
41504
+ return [].concat(erasNarrow);
41485
41505
 
41486
41506
  case "short":
41487
- return erasShort;
41507
+ return [].concat(erasShort);
41488
41508
 
41489
41509
  case "long":
41490
- return erasLong;
41510
+ return [].concat(erasLong);
41491
41511
 
41492
41512
  default:
41493
41513
  return null;
@@ -42502,7 +42522,7 @@ var IANAZone = /*#__PURE__*/function (_Zone) {
42502
42522
 
42503
42523
  IANAZone.parseGMTOffset = function parseGMTOffset(specifier) {
42504
42524
  if (specifier) {
42505
- var match = specifier.match(/^Etc\/GMT([+-]\d{1,2})$/i);
42525
+ var match = specifier.match(/^Etc\/GMT(0|[+-]\d{1,2})$/i);
42506
42526
 
42507
42527
  if (match) {
42508
42528
  return -60 * parseInt(match[1]);
@@ -42545,8 +42565,10 @@ var IANAZone = /*#__PURE__*/function (_Zone) {
42545
42565
  ;
42546
42566
 
42547
42567
  _proto.offset = function offset(ts) {
42548
- var date = new Date(ts),
42549
- dtf = makeDTF(this.name),
42568
+ var date = new Date(ts);
42569
+ if (isNaN(date)) return NaN;
42570
+
42571
+ var dtf = makeDTF(this.name),
42550
42572
  _ref2 = dtf.formatToParts ? partsOffset(dtf, date) : hackyOffset(dtf, date),
42551
42573
  year = _ref2[0],
42552
42574
  month = _ref2[1],
@@ -43205,12 +43227,16 @@ var PolyDateFormatter = /*#__PURE__*/function () {
43205
43227
  if (dt.zone.universal && this.hasIntl) {
43206
43228
  // UTC-8 or Etc/UTC-8 are not part of tzdata, only Etc/GMT+8 and the like.
43207
43229
  // That is why fixed-offset TZ is set to that unless it is:
43208
- // 1. Outside of the supported range Etc/GMT-14 to Etc/GMT+12.
43209
- // 2. Not a whole hour, e.g. UTC+4:30.
43230
+ // 1. Representing offset 0 when UTC is used to maintain previous behavior and does not become GMT.
43231
+ // 2. Unsupported by the browser:
43232
+ // - some do not support Etc/
43233
+ // - < Etc/GMT-14, > Etc/GMT+12, and 30-minute or 45-minute offsets are not part of tzdata
43210
43234
  var gmtOffset = -1 * (dt.offset / 60);
43235
+ var offsetZ = gmtOffset >= 0 ? "Etc/GMT+" + gmtOffset : "Etc/GMT" + gmtOffset;
43236
+ var isOffsetZoneSupported = IANAZone.isValidZone(offsetZ);
43211
43237
 
43212
- if (gmtOffset >= -14 && gmtOffset <= 12 && gmtOffset % 1 === 0) {
43213
- z = gmtOffset >= 0 ? "Etc/GMT+" + gmtOffset : "Etc/GMT" + gmtOffset;
43238
+ if (dt.offset !== 0 && isOffsetZoneSupported) {
43239
+ z = offsetZ;
43214
43240
  this.dt = dt;
43215
43241
  } else {
43216
43242
  // Not all fixed-offset zones like Etc/+4:30 are present in tzdata.
@@ -43747,9 +43773,14 @@ function extractISODuration(match) {
43747
43773
  secondStr = match[7],
43748
43774
  millisecondsStr = match[8];
43749
43775
  var hasNegativePrefix = s[0] === "-";
43776
+ var negativeSeconds = secondStr && secondStr[0] === "-";
43777
+
43778
+ var maybeNegate = function maybeNegate(num, force) {
43779
+ if (force === void 0) {
43780
+ force = false;
43781
+ }
43750
43782
 
43751
- var maybeNegate = function maybeNegate(num) {
43752
- return num && hasNegativePrefix ? -num : num;
43783
+ return num !== undefined && (force || num && hasNegativePrefix) ? -num : num;
43753
43784
  };
43754
43785
 
43755
43786
  return [{
@@ -43759,8 +43790,8 @@ function extractISODuration(match) {
43759
43790
  days: maybeNegate(parseInteger(dayStr)),
43760
43791
  hours: maybeNegate(parseInteger(hourStr)),
43761
43792
  minutes: maybeNegate(parseInteger(minuteStr)),
43762
- seconds: maybeNegate(parseInteger(secondStr)),
43763
- milliseconds: maybeNegate(parseMillis(millisecondsStr))
43793
+ seconds: maybeNegate(parseInteger(secondStr), secondStr === "-0"),
43794
+ milliseconds: maybeNegate(parseMillis(millisecondsStr), negativeSeconds)
43764
43795
  }];
43765
43796
  } // These are a little braindead. EDT *should* tell us that we're in, say, America/New_York
43766
43797
  // and not just that we're in -240 *right now*. But since I don't think these are used that often
@@ -43865,14 +43896,14 @@ var isoOrdinalWithTimeExtensionRegex = combineRegexes(isoOrdinalRegex, isoTimeEx
43865
43896
  var isoTimeCombinedRegex = combineRegexes(isoTimeRegex);
43866
43897
  var extractISOYmdTimeAndOffset = combineExtractors(extractISOYmd, extractISOTime, extractISOOffset);
43867
43898
  var extractISOWeekTimeAndOffset = combineExtractors(extractISOWeekData, extractISOTime, extractISOOffset);
43868
- var extractISOOrdinalDataAndTime = combineExtractors(extractISOOrdinalData, extractISOTime);
43899
+ var extractISOOrdinalDateAndTime = combineExtractors(extractISOOrdinalData, extractISOTime, extractISOOffset);
43869
43900
  var extractISOTimeAndOffset = combineExtractors(extractISOTime, extractISOOffset);
43870
43901
  /**
43871
43902
  * @private
43872
43903
  */
43873
43904
 
43874
43905
  function parseISODate(s) {
43875
- return parse(s, [isoYmdWithTimeExtensionRegex, extractISOYmdTimeAndOffset], [isoWeekWithTimeExtensionRegex, extractISOWeekTimeAndOffset], [isoOrdinalWithTimeExtensionRegex, extractISOOrdinalDataAndTime], [isoTimeCombinedRegex, extractISOTimeAndOffset]);
43906
+ return parse(s, [isoYmdWithTimeExtensionRegex, extractISOYmdTimeAndOffset], [isoWeekWithTimeExtensionRegex, extractISOWeekTimeAndOffset], [isoOrdinalWithTimeExtensionRegex, extractISOOrdinalDateAndTime], [isoTimeCombinedRegex, extractISOTimeAndOffset]);
43876
43907
  }
43877
43908
  function parseRFC2822Date(s) {
43878
43909
  return parse(preprocessRFC2822(s), [rfc2822, extractRFC2822]);
@@ -44100,7 +44131,7 @@ var Duration = /*#__PURE__*/function () {
44100
44131
  }, opts));
44101
44132
  }
44102
44133
  /**
44103
- * Create a Duration from a JavaScript object with keys like 'years' and 'hours.
44134
+ * Create a Duration from a JavaScript object with keys like 'years' and 'hours'.
44104
44135
  * If this object is empty then a zero milliseconds duration is returned.
44105
44136
  * @param {Object} obj - the object to create the DateTime from
44106
44137
  * @param {number} obj.years
@@ -44492,9 +44523,9 @@ var Duration = /*#__PURE__*/function () {
44492
44523
  /**
44493
44524
  * Get the value of unit.
44494
44525
  * @param {string} unit - a unit such as 'minute' or 'day'
44495
- * @example Duration.fromObject({years: 2, days: 3}).years //=> 2
44496
- * @example Duration.fromObject({years: 2, days: 3}).months //=> 0
44497
- * @example Duration.fromObject({years: 2, days: 3}).days //=> 3
44526
+ * @example Duration.fromObject({years: 2, days: 3}).get('years') //=> 2
44527
+ * @example Duration.fromObject({years: 2, days: 3}).get('months') //=> 0
44528
+ * @example Duration.fromObject({years: 2, days: 3}).get('days') //=> 3
44498
44529
  * @return {number}
44499
44530
  */
44500
44531
  ;
@@ -45200,15 +45231,18 @@ var Interval = /*#__PURE__*/function () {
45200
45231
  }
45201
45232
 
45202
45233
  var s = this.s,
45203
- added,
45234
+ idx = 1,
45204
45235
  next;
45205
45236
  var results = [];
45206
45237
 
45207
45238
  while (s < this.e) {
45208
- added = s.plus(dur);
45239
+ var added = this.start.plus(dur.mapUnits(function (x) {
45240
+ return x * idx;
45241
+ }));
45209
45242
  next = +added > +this.e ? this.e : added;
45210
45243
  results.push(Interval.fromDateTimes(s, next));
45211
45244
  s = next;
45245
+ idx += 1;
45212
45246
  }
45213
45247
 
45214
45248
  return results;
@@ -45295,7 +45329,7 @@ var Interval = /*#__PURE__*/function () {
45295
45329
  var s = this.s > other.s ? this.s : other.s,
45296
45330
  e = this.e < other.e ? this.e : other.e;
45297
45331
 
45298
- if (s > e) {
45332
+ if (s >= e) {
45299
45333
  return null;
45300
45334
  } else {
45301
45335
  return Interval.fromDateTimes(s, e);
@@ -45620,6 +45654,7 @@ var Info = /*#__PURE__*/function () {
45620
45654
  * @param {Object} opts - options
45621
45655
  * @param {string} [opts.locale] - the locale code
45622
45656
  * @param {string} [opts.numberingSystem=null] - the numbering system
45657
+ * @param {string} [opts.locObj=null] - an existing locale object to use
45623
45658
  * @param {string} [opts.outputCalendar='gregory'] - the calendar
45624
45659
  * @example Info.months()[0] //=> 'January'
45625
45660
  * @example Info.months('short')[0] //=> 'Jan'
@@ -45641,10 +45676,12 @@ var Info = /*#__PURE__*/function () {
45641
45676
  locale = _ref$locale === void 0 ? null : _ref$locale,
45642
45677
  _ref$numberingSystem = _ref.numberingSystem,
45643
45678
  numberingSystem = _ref$numberingSystem === void 0 ? null : _ref$numberingSystem,
45679
+ _ref$locObj = _ref.locObj,
45680
+ locObj = _ref$locObj === void 0 ? null : _ref$locObj,
45644
45681
  _ref$outputCalendar = _ref.outputCalendar,
45645
45682
  outputCalendar = _ref$outputCalendar === void 0 ? "gregory" : _ref$outputCalendar;
45646
45683
 
45647
- return Locale.create(locale, numberingSystem, outputCalendar).months(length);
45684
+ return (locObj || Locale.create(locale, numberingSystem, outputCalendar)).months(length);
45648
45685
  }
45649
45686
  /**
45650
45687
  * Return an array of format month names.
@@ -45655,6 +45692,7 @@ var Info = /*#__PURE__*/function () {
45655
45692
  * @param {Object} opts - options
45656
45693
  * @param {string} [opts.locale] - the locale code
45657
45694
  * @param {string} [opts.numberingSystem=null] - the numbering system
45695
+ * @param {string} [opts.locObj=null] - an existing locale object to use
45658
45696
  * @param {string} [opts.outputCalendar='gregory'] - the calendar
45659
45697
  * @return {[string]}
45660
45698
  */
@@ -45670,10 +45708,12 @@ var Info = /*#__PURE__*/function () {
45670
45708
  locale = _ref2$locale === void 0 ? null : _ref2$locale,
45671
45709
  _ref2$numberingSystem = _ref2.numberingSystem,
45672
45710
  numberingSystem = _ref2$numberingSystem === void 0 ? null : _ref2$numberingSystem,
45711
+ _ref2$locObj = _ref2.locObj,
45712
+ locObj = _ref2$locObj === void 0 ? null : _ref2$locObj,
45673
45713
  _ref2$outputCalendar = _ref2.outputCalendar,
45674
45714
  outputCalendar = _ref2$outputCalendar === void 0 ? "gregory" : _ref2$outputCalendar;
45675
45715
 
45676
- return Locale.create(locale, numberingSystem, outputCalendar).months(length, true);
45716
+ return (locObj || Locale.create(locale, numberingSystem, outputCalendar)).months(length, true);
45677
45717
  }
45678
45718
  /**
45679
45719
  * Return an array of standalone week names.
@@ -45682,6 +45722,7 @@ var Info = /*#__PURE__*/function () {
45682
45722
  * @param {Object} opts - options
45683
45723
  * @param {string} [opts.locale] - the locale code
45684
45724
  * @param {string} [opts.numberingSystem=null] - the numbering system
45725
+ * @param {string} [opts.locObj=null] - an existing locale object to use
45685
45726
  * @example Info.weekdays()[0] //=> 'Monday'
45686
45727
  * @example Info.weekdays('short')[0] //=> 'Mon'
45687
45728
  * @example Info.weekdays('short', { locale: 'fr-CA' })[0] //=> 'lun.'
@@ -45699,9 +45740,11 @@ var Info = /*#__PURE__*/function () {
45699
45740
  _ref3$locale = _ref3.locale,
45700
45741
  locale = _ref3$locale === void 0 ? null : _ref3$locale,
45701
45742
  _ref3$numberingSystem = _ref3.numberingSystem,
45702
- numberingSystem = _ref3$numberingSystem === void 0 ? null : _ref3$numberingSystem;
45743
+ numberingSystem = _ref3$numberingSystem === void 0 ? null : _ref3$numberingSystem,
45744
+ _ref3$locObj = _ref3.locObj,
45745
+ locObj = _ref3$locObj === void 0 ? null : _ref3$locObj;
45703
45746
 
45704
- return Locale.create(locale, numberingSystem, null).weekdays(length);
45747
+ return (locObj || Locale.create(locale, numberingSystem, null)).weekdays(length);
45705
45748
  }
45706
45749
  /**
45707
45750
  * Return an array of format week names.
@@ -45712,6 +45755,7 @@ var Info = /*#__PURE__*/function () {
45712
45755
  * @param {Object} opts - options
45713
45756
  * @param {string} [opts.locale=null] - the locale code
45714
45757
  * @param {string} [opts.numberingSystem=null] - the numbering system
45758
+ * @param {string} [opts.locObj=null] - an existing locale object to use
45715
45759
  * @return {[string]}
45716
45760
  */
45717
45761
  ;
@@ -45725,9 +45769,11 @@ var Info = /*#__PURE__*/function () {
45725
45769
  _ref4$locale = _ref4.locale,
45726
45770
  locale = _ref4$locale === void 0 ? null : _ref4$locale,
45727
45771
  _ref4$numberingSystem = _ref4.numberingSystem,
45728
- numberingSystem = _ref4$numberingSystem === void 0 ? null : _ref4$numberingSystem;
45772
+ numberingSystem = _ref4$numberingSystem === void 0 ? null : _ref4$numberingSystem,
45773
+ _ref4$locObj = _ref4.locObj,
45774
+ locObj = _ref4$locObj === void 0 ? null : _ref4$locObj;
45729
45775
 
45730
- return Locale.create(locale, numberingSystem, null).weekdays(length, true);
45776
+ return (locObj || Locale.create(locale, numberingSystem, null)).weekdays(length, true);
45731
45777
  }
45732
45778
  /**
45733
45779
  * Return an array of meridiems.
@@ -47018,7 +47064,7 @@ function diffRelative(start, end, opts) {
47018
47064
  }
47019
47065
  }
47020
47066
 
47021
- return format(0, opts.units[opts.units.length - 1]);
47067
+ return format(start > end ? -0 : 0, opts.units[opts.units.length - 1]);
47022
47068
  }
47023
47069
  /**
47024
47070
  * A DateTime is an immutable data structure representing a specific date and time and accompanying methods. It contains class and instance methods for creating, parsing, interrogating, transforming, and formatting them.
@@ -47145,7 +47191,7 @@ var DateTime = /*#__PURE__*/function () {
47145
47191
 
47146
47192
  DateTime.local = function local(year, month, day, hour, minute, second, millisecond) {
47147
47193
  if (isUndefined(year)) {
47148
- return new DateTime({});
47194
+ return DateTime.now();
47149
47195
  } else {
47150
47196
  return quickDT({
47151
47197
  year: year,
@@ -47413,8 +47459,8 @@ var DateTime = /*#__PURE__*/function () {
47413
47459
  * @param {string|Zone} [opts.zone='local'] - use this zone if no offset is specified in the input string itself. Will also convert the time to this zone
47414
47460
  * @param {boolean} [opts.setZone=false] - override the zone with a fixed-offset zone specified in the string itself, if it specifies one
47415
47461
  * @param {string} [opts.locale='system's locale'] - a locale to set on the resulting DateTime instance
47416
- * @param {string} opts.outputCalendar - the output calendar to set on the resulting DateTime instance
47417
- * @param {string} opts.numberingSystem - the numbering system to set on the resulting DateTime instance
47462
+ * @param {string} [opts.outputCalendar] - the output calendar to set on the resulting DateTime instance
47463
+ * @param {string} [opts.numberingSystem] - the numbering system to set on the resulting DateTime instance
47418
47464
  * @example DateTime.fromISO('2016-05-25T09:08:34.123')
47419
47465
  * @example DateTime.fromISO('2016-05-25T09:08:34.123+06:00')
47420
47466
  * @example DateTime.fromISO('2016-05-25T09:08:34.123+06:00', {setZone: true})
@@ -47789,7 +47835,21 @@ var DateTime = /*#__PURE__*/function () {
47789
47835
  _proto.set = function set(values) {
47790
47836
  if (!this.isValid) return this;
47791
47837
  var normalized = normalizeObject(values, normalizeUnit, []),
47792
- settingWeekStuff = !isUndefined(normalized.weekYear) || !isUndefined(normalized.weekNumber) || !isUndefined(normalized.weekday);
47838
+ settingWeekStuff = !isUndefined(normalized.weekYear) || !isUndefined(normalized.weekNumber) || !isUndefined(normalized.weekday),
47839
+ containsOrdinal = !isUndefined(normalized.ordinal),
47840
+ containsGregorYear = !isUndefined(normalized.year),
47841
+ containsGregorMD = !isUndefined(normalized.month) || !isUndefined(normalized.day),
47842
+ containsGregor = containsGregorYear || containsGregorMD,
47843
+ definiteWeekDef = normalized.weekYear || normalized.weekNumber;
47844
+
47845
+ if ((containsGregor || containsOrdinal) && definiteWeekDef) {
47846
+ throw new ConflictingSpecificationError("Can't mix weekYear/weekNumber units with year/month/day or ordinals");
47847
+ }
47848
+
47849
+ if (containsGregorMD && containsOrdinal) {
47850
+ throw new ConflictingSpecificationError("Can't mix ordinal dates with month/day");
47851
+ }
47852
+
47793
47853
  var mixed;
47794
47854
 
47795
47855
  if (settingWeekStuff) {
@@ -48373,7 +48433,7 @@ var DateTime = /*#__PURE__*/function () {
48373
48433
  * @param {Object} options - options that affect the output
48374
48434
  * @param {DateTime} [options.base=DateTime.now()] - the DateTime to use as the basis to which this time is compared. Defaults to now.
48375
48435
  * @param {string} [options.style="long"] - the style of units, must be "long", "short", or "narrow"
48376
- * @param {string} options.unit - use a specific unit; if omitted, the method will pick the unit. Use one of "years", "quarters", "months", "weeks", "days", "hours", "minutes", or "seconds"
48436
+ * @param {string|string[]} options.unit - use a specific unit or array of units; if omitted, or an array, the method will pick the best unit. Use an array or one of "years", "quarters", "months", "weeks", "days", "hours", "minutes", or "seconds"
48377
48437
  * @param {boolean} [options.round=true] - whether to round the numbers in the output.
48378
48438
  * @param {number} [options.padding=0] - padding in milliseconds. This allows you to round up the result if it fits inside the threshold. Don't use in combination with {round: false} because the decimal output will include the padding.
48379
48439
  * @param {string} options.locale - override the locale of this DateTime
@@ -48397,9 +48457,18 @@ var DateTime = /*#__PURE__*/function () {
48397
48457
  zone: this.zone
48398
48458
  }),
48399
48459
  padding = options.padding ? this < base ? -options.padding : options.padding : 0;
48460
+ var units = ["years", "months", "days", "hours", "minutes", "seconds"];
48461
+ var unit = options.unit;
48462
+
48463
+ if (Array.isArray(options.unit)) {
48464
+ units = options.unit;
48465
+ unit = undefined;
48466
+ }
48467
+
48400
48468
  return diffRelative(base, this.plus(padding), Object.assign(options, {
48401
48469
  numeric: "always",
48402
- units: ["years", "months", "days", "hours", "minutes", "seconds"]
48470
+ units: units,
48471
+ unit: unit
48403
48472
  }));
48404
48473
  }
48405
48474
  /**
@@ -48686,7 +48755,7 @@ var DateTime = /*#__PURE__*/function () {
48686
48755
  /**
48687
48756
  * Get the week year
48688
48757
  * @see https://en.wikipedia.org/wiki/ISO_week_date
48689
- * @example DateTime.local(2014, 11, 31).weekYear //=> 2015
48758
+ * @example DateTime.local(2014, 12, 31).weekYear //=> 2015
48690
48759
  * @type {number}
48691
48760
  */
48692
48761
 
@@ -48742,7 +48811,7 @@ var DateTime = /*#__PURE__*/function () {
48742
48811
  key: "monthShort",
48743
48812
  get: function get() {
48744
48813
  return this.isValid ? Info.months("short", {
48745
- locale: this.locale
48814
+ locObj: this.loc
48746
48815
  })[this.month - 1] : null;
48747
48816
  }
48748
48817
  /**
@@ -48756,7 +48825,7 @@ var DateTime = /*#__PURE__*/function () {
48756
48825
  key: "monthLong",
48757
48826
  get: function get() {
48758
48827
  return this.isValid ? Info.months("long", {
48759
- locale: this.locale
48828
+ locObj: this.loc
48760
48829
  })[this.month - 1] : null;
48761
48830
  }
48762
48831
  /**
@@ -48770,7 +48839,7 @@ var DateTime = /*#__PURE__*/function () {
48770
48839
  key: "weekdayShort",
48771
48840
  get: function get() {
48772
48841
  return this.isValid ? Info.weekdays("short", {
48773
- locale: this.locale
48842
+ locObj: this.loc
48774
48843
  })[this.weekday - 1] : null;
48775
48844
  }
48776
48845
  /**
@@ -48784,7 +48853,7 @@ var DateTime = /*#__PURE__*/function () {
48784
48853
  key: "weekdayLong",
48785
48854
  get: function get() {
48786
48855
  return this.isValid ? Info.weekdays("long", {
48787
- locale: this.locale
48856
+ locObj: this.loc
48788
48857
  })[this.weekday - 1] : null;
48789
48858
  }
48790
48859
  /**
@@ -49143,7 +49212,7 @@ function friendlyDateTime(dateTimeish) {
49143
49212
  }
49144
49213
  }
49145
49214
 
49146
- var VERSION = "1.26.0";
49215
+ var VERSION = "1.28.0";
49147
49216
 
49148
49217
  exports.DateTime = DateTime;
49149
49218
  exports.Duration = Duration;
@@ -49240,11 +49309,14 @@ exports.Schema = require('./schema');
49240
49309
  *
49241
49310
  * ####Types:
49242
49311
  *
49243
- * - [ObjectId](#types-objectid-js)
49244
- * - [Buffer](#types-buffer-js)
49245
- * - [SubDocument](#types-embedded-js)
49246
- * - [Array](#types-array-js)
49247
- * - [DocumentArray](#types-documentarray-js)
49312
+ * - [Array](/docs/schematypes.html#arrays)
49313
+ * - [Buffer](/docs/schematypes.html#buffers)
49314
+ * - [Embedded](/docs/schematypes.html#schemas)
49315
+ * - [DocumentArray](/docs/api/documentarraypath.html)
49316
+ * - [Decimal128](/docs/api.html#mongoose_Mongoose-Decimal128)
49317
+ * - [ObjectId](/docs/schematypes.html#objectids)
49318
+ * - [Map](/docs/schematypes.html#maps)
49319
+ * - [Subdocument](/docs/schematypes.html#schemas)
49248
49320
  *
49249
49321
  * Using this exposed access to the `ObjectId` type, we can construct ids on demand.
49250
49322
  *
@@ -49327,7 +49399,7 @@ if (typeof window !== 'undefined') {
49327
49399
  }
49328
49400
 
49329
49401
  }).call(this)}).call(this,require("buffer").Buffer)
49330
- },{"./document_provider.js":195,"./driver":196,"./drivers/browser":200,"./error/index":204,"./promise_provider":272,"./schema":274,"./schematype.js":295,"./types":303,"./utils.js":307,"./virtualtype":308,"buffer":129}],186:[function(require,module,exports){
49402
+ },{"./document_provider.js":195,"./driver":196,"./drivers/browser":200,"./error/index":204,"./promise_provider":274,"./schema":276,"./schematype.js":297,"./types":305,"./utils.js":309,"./virtualtype":310,"buffer":129}],186:[function(require,module,exports){
49331
49403
  /*!
49332
49404
  * Module dependencies.
49333
49405
  */
@@ -49429,7 +49501,7 @@ Document.$emitter = new EventEmitter();
49429
49501
  Document.ValidationError = ValidationError;
49430
49502
  module.exports = exports = Document;
49431
49503
 
49432
- },{"./document":194,"./error/index":204,"./helpers/isObject":234,"./helpers/model/applyHooks":236,"./schema":274,"./types/objectid":305,"events":177}],187:[function(require,module,exports){
49504
+ },{"./document":194,"./error/index":204,"./helpers/isObject":236,"./helpers/model/applyHooks":238,"./schema":276,"./types/objectid":307,"events":177}],187:[function(require,module,exports){
49433
49505
  'use strict';
49434
49506
 
49435
49507
  /*!
@@ -49441,6 +49513,7 @@ const StrictModeError = require('./error/strict');
49441
49513
  const Types = require('./schema/index');
49442
49514
  const castTextSearch = require('./schema/operators/text');
49443
49515
  const get = require('./helpers/get');
49516
+ const getConstructorName = require('./helpers/getConstructorName');
49444
49517
  const getSchemaDiscriminatorByValue = require('./helpers/discriminator/getSchemaDiscriminatorByValue');
49445
49518
  const isOperator = require('./helpers/query/isOperator');
49446
49519
  const util = require('util');
@@ -49699,7 +49772,7 @@ module.exports = function cast(schema, obj, options, context) {
49699
49772
  }
49700
49773
  } else if (val == null) {
49701
49774
  continue;
49702
- } else if (val.constructor.name === 'Object') {
49775
+ } else if (getConstructorName(val) === 'Object') {
49703
49776
  any$conditionals = Object.keys(val).some(isOperator);
49704
49777
 
49705
49778
  if (!any$conditionals) {
@@ -49794,7 +49867,7 @@ function _cast(val, numbertype, context) {
49794
49867
  }
49795
49868
  }
49796
49869
  }
49797
- },{"./error/cast":202,"./error/strict":214,"./helpers/discriminator/getSchemaDiscriminatorByValue":224,"./helpers/get":229,"./helpers/isMongooseObject":233,"./helpers/isObject":234,"./helpers/query/isOperator":243,"./schema/index":282,"./schema/operators/text":291,"util":332}],188:[function(require,module,exports){
49870
+ },{"./error/cast":202,"./error/strict":214,"./helpers/discriminator/getSchemaDiscriminatorByValue":225,"./helpers/get":230,"./helpers/getConstructorName":231,"./helpers/isMongooseObject":235,"./helpers/isObject":236,"./helpers/query/isOperator":245,"./schema/index":284,"./schema/operators/text":293,"util":334}],188:[function(require,module,exports){
49798
49871
  'use strict';
49799
49872
 
49800
49873
  const CastError = require('../error/cast');
@@ -49909,7 +49982,7 @@ module.exports = function castDecimal128(value) {
49909
49982
  assert.ok(false);
49910
49983
  };
49911
49984
  }).call(this)}).call(this,{"isBuffer":require("../../../is-buffer/index.js")})
49912
- },{"../../../is-buffer/index.js":179,"../types/decimal128":300,"assert":103}],191:[function(require,module,exports){
49985
+ },{"../../../is-buffer/index.js":179,"../types/decimal128":302,"assert":103}],191:[function(require,module,exports){
49913
49986
  'use strict';
49914
49987
 
49915
49988
  const assert = require('assert');
@@ -50024,7 +50097,7 @@ module.exports = function castString(value, path) {
50024
50097
  };
50025
50098
 
50026
50099
  },{"../error/cast":202}],194:[function(require,module,exports){
50027
- (function (Buffer,process){(function (){
50100
+ (function (Buffer){(function (){
50028
50101
  'use strict';
50029
50102
 
50030
50103
  /*!
@@ -50052,6 +50125,7 @@ const get = require('./helpers/get');
50052
50125
  const getEmbeddedDiscriminatorPath = require('./helpers/document/getEmbeddedDiscriminatorPath');
50053
50126
  const handleSpreadDoc = require('./helpers/document/handleSpreadDoc');
50054
50127
  const idGetter = require('./plugins/idGetter');
50128
+ const immediate = require('./helpers/immediate');
50055
50129
  const isDefiningProjection = require('./helpers/projection/isDefiningProjection');
50056
50130
  const isExclusive = require('./helpers/projection/isExclusive');
50057
50131
  const inspect = require('util').inspect;
@@ -50074,6 +50148,7 @@ const documentSchemaSymbol = require('./helpers/symbols').documentSchemaSymbol;
50074
50148
  const getSymbol = require('./helpers/symbols').getSymbol;
50075
50149
  const populateModelSymbol = require('./helpers/symbols').populateModelSymbol;
50076
50150
  const scopeSymbol = require('./helpers/symbols').scopeSymbol;
50151
+ const schemaMixedSymbol = require('./schema/symbols').schemaMixedSymbol;
50077
50152
 
50078
50153
  let DocumentArray;
50079
50154
  let MongooseArray;
@@ -50103,9 +50178,8 @@ function Document(obj, fields, skipId, options) {
50103
50178
  options = Object.assign({}, options);
50104
50179
  const defaults = get(options, 'defaults', true);
50105
50180
  options.defaults = defaults;
50106
-
50107
50181
  // Support `browserDocument.js` syntax
50108
- if (this.schema == null) {
50182
+ if (this.$__schema == null) {
50109
50183
  const _schema = utils.isObject(fields) && !fields.instanceOfSchema ?
50110
50184
  new Schema(fields) :
50111
50185
  fields;
@@ -50122,12 +50196,11 @@ function Document(obj, fields, skipId, options) {
50122
50196
  this.$__.$options = options || {};
50123
50197
  this.$locals = {};
50124
50198
  this.$op = null;
50125
-
50126
50199
  if (obj != null && typeof obj !== 'object') {
50127
50200
  throw new ObjectParameterError(obj, 'obj', 'Document');
50128
50201
  }
50129
50202
 
50130
- const schema = this.schema;
50203
+ const schema = this.$__schema;
50131
50204
 
50132
50205
  if (typeof fields === 'boolean' || fields === 'throw') {
50133
50206
  this.$__.strictMode = fields;
@@ -50230,6 +50303,17 @@ for (const i in EventEmitter.prototype) {
50230
50303
  Document[i] = EventEmitter.prototype[i];
50231
50304
  }
50232
50305
 
50306
+ /**
50307
+ * The document's internal schema.
50308
+ *
50309
+ * @api private
50310
+ * @property schema
50311
+ * @memberOf Document
50312
+ * @instance
50313
+ */
50314
+
50315
+ Document.prototype.$__schema;
50316
+
50233
50317
  /**
50234
50318
  * The document's schema.
50235
50319
  *
@@ -50281,6 +50365,28 @@ Object.defineProperty(Document.prototype, '$locals', {
50281
50365
 
50282
50366
  Document.prototype.isNew;
50283
50367
 
50368
+ /**
50369
+ * Set this property to add additional query filters when Mongoose saves this document and `isNew` is false.
50370
+ *
50371
+ * ####Example:
50372
+ *
50373
+ * // Make sure `save()` never updates a soft deleted document.
50374
+ * schema.pre('save', function() {
50375
+ * this.$where = { isDeleted: false };
50376
+ * });
50377
+ *
50378
+ * @api public
50379
+ * @property $where
50380
+ * @memberOf Document
50381
+ * @instance
50382
+ */
50383
+
50384
+ Object.defineProperty(Document.prototype, '$where', {
50385
+ configurable: false,
50386
+ enumerable: false,
50387
+ writable: true
50388
+ });
50389
+
50284
50390
  /**
50285
50391
  * The string version of this documents _id.
50286
50392
  *
@@ -50359,7 +50465,7 @@ function $__hasIncludedChildren(fields) {
50359
50465
  */
50360
50466
 
50361
50467
  function $__applyDefaults(doc, fields, skipId, exclude, hasIncludedChildren, isBeforeSetters, pathsToSkip) {
50362
- const paths = Object.keys(doc.schema.paths);
50468
+ const paths = Object.keys(doc.$__schema.paths);
50363
50469
  const plen = paths.length;
50364
50470
 
50365
50471
  for (let i = 0; i < plen; ++i) {
@@ -50371,12 +50477,11 @@ function $__applyDefaults(doc, fields, skipId, exclude, hasIncludedChildren, isB
50371
50477
  continue;
50372
50478
  }
50373
50479
 
50374
- const type = doc.schema.paths[p];
50375
- const path = p.indexOf('.') === -1 ? [p] : p.split('.');
50480
+ const type = doc.$__schema.paths[p];
50481
+ const path = type.splitPath();
50376
50482
  const len = path.length;
50377
50483
  let included = false;
50378
50484
  let doc_ = doc._doc;
50379
-
50380
50485
  for (let j = 0; j < len; ++j) {
50381
50486
  if (doc_ == null) {
50382
50487
  break;
@@ -50485,7 +50590,7 @@ function $__applyDefaults(doc, fields, skipId, exclude, hasIncludedChildren, isB
50485
50590
  Document.prototype.$__buildDoc = function(obj, fields, skipId, exclude, hasIncludedChildren) {
50486
50591
  const doc = {};
50487
50592
 
50488
- const paths = Object.keys(this.schema.paths).
50593
+ const paths = Object.keys(this.$__schema.paths).
50489
50594
  // Don't build up any paths that are underneath a map, we don't know
50490
50595
  // what the keys will be
50491
50596
  filter(p => !p.includes('$*'));
@@ -50504,7 +50609,7 @@ Document.prototype.$__buildDoc = function(obj, fields, skipId, exclude, hasInclu
50504
50609
  }
50505
50610
  }
50506
50611
 
50507
- const path = p.split('.');
50612
+ const path = this.$__schema.paths[p].splitPath();
50508
50613
  const len = path.length;
50509
50614
  const last = len - 1;
50510
50615
  let curPath = '';
@@ -50605,6 +50710,7 @@ Document.prototype.$__init = function(doc, opts) {
50605
50710
  }
50606
50711
  child.$__.parent = this;
50607
50712
  }
50713
+ item._childDocs = [];
50608
50714
  }
50609
50715
  }
50610
50716
 
@@ -50616,7 +50722,6 @@ Document.prototype.$__init = function(doc, opts) {
50616
50722
  this.constructor.emit('init', this);
50617
50723
 
50618
50724
  this.$__._id = this._id;
50619
-
50620
50725
  return this;
50621
50726
  };
50622
50727
 
@@ -50685,12 +50790,12 @@ function init(self, obj, doc, opts, prefix) {
50685
50790
  function _init(index) {
50686
50791
  i = keys[index];
50687
50792
  path = prefix + i;
50688
- schema = self.schema.path(path);
50793
+ schema = self.$__schema.path(path);
50689
50794
 
50690
50795
  // Should still work if not a model-level discriminator, but should not be
50691
50796
  // necessary. This is *only* to catch the case where we queried using the
50692
50797
  // base model and the discriminated model has a projection
50693
- if (self.schema.$isRootDiscriminator && !self.$__isSelected(path)) {
50798
+ if (self.$__schema.$isRootDiscriminator && !self.$__isSelected(path)) {
50694
50799
  return;
50695
50800
  }
50696
50801
 
@@ -50795,10 +50900,10 @@ Document.prototype.update = function update() {
50795
50900
 
50796
50901
  Document.prototype.updateOne = function updateOne(doc, options, callback) {
50797
50902
  const query = this.constructor.updateOne({ _id: this._id }, doc, options);
50798
- query._pre(cb => {
50903
+ query.pre(cb => {
50799
50904
  this.constructor._middleware.execPre('updateOne', this, [this], cb);
50800
50905
  });
50801
- query._post(cb => {
50906
+ query.post(cb => {
50802
50907
  this.constructor._middleware.execPost('updateOne', this, [this], {}, cb);
50803
50908
  });
50804
50909
 
@@ -50820,7 +50925,7 @@ Document.prototype.updateOne = function updateOne(doc, options, callback) {
50820
50925
  *
50821
50926
  * ####Valid options:
50822
50927
  *
50823
- * - same as in [Model.replaceOne](#model_Model.replaceOne)
50928
+ * - same as in [Model.replaceOne](https://mongoosejs.com/docs/api/model.html#model_Model.replaceOne)
50824
50929
  *
50825
50930
  * @see Model.replaceOne #model_Model.replaceOne
50826
50931
  * @param {Object} doc
@@ -50863,12 +50968,22 @@ Document.prototype.replaceOne = function replaceOne() {
50863
50968
 
50864
50969
  Document.prototype.$session = function $session(session) {
50865
50970
  if (arguments.length === 0) {
50971
+ if (this.$__.session != null && this.$__.session.hasEnded) {
50972
+ this.$__.session = null;
50973
+ return null;
50974
+ }
50866
50975
  return this.$__.session;
50867
50976
  }
50977
+
50978
+ if (session != null && session.hasEnded) {
50979
+ throw new MongooseError('Cannot set a document\'s session to a session that has ended. Make sure you haven\'t ' +
50980
+ 'called `endSession()` on the session you are passing to `$session()`.');
50981
+ }
50982
+
50868
50983
  this.$__.session = session;
50869
50984
 
50870
50985
  if (!this.ownerDocument) {
50871
- const subdocs = this.$__getAllSubdocs();
50986
+ const subdocs = this.$getAllSubdocs();
50872
50987
  for (const child of subdocs) {
50873
50988
  child.$session(session);
50874
50989
  }
@@ -50898,10 +51013,10 @@ Document.prototype.overwrite = function overwrite(obj) {
50898
51013
  continue;
50899
51014
  }
50900
51015
  // Explicitly skip version key
50901
- if (this.schema.options.versionKey && key === this.schema.options.versionKey) {
51016
+ if (this.$__schema.options.versionKey && key === this.$__schema.options.versionKey) {
50902
51017
  continue;
50903
51018
  }
50904
- if (this.schema.options.discriminatorKey && key === this.schema.options.discriminatorKey) {
51019
+ if (this.$__schema.options.discriminatorKey && key === this.$__schema.options.discriminatorKey) {
50905
51020
  continue;
50906
51021
  }
50907
51022
  this.$set(key, obj[key]);
@@ -50925,7 +51040,6 @@ Document.prototype.overwrite = function overwrite(obj) {
50925
51040
  */
50926
51041
 
50927
51042
  Document.prototype.$set = function $set(path, val, type, options) {
50928
-
50929
51043
  if (utils.isPOJO(type)) {
50930
51044
  options = type;
50931
51045
  type = undefined;
@@ -50935,6 +51049,7 @@ Document.prototype.$set = function $set(path, val, type, options) {
50935
51049
  const merge = options.merge;
50936
51050
  const adhoc = type && type !== true;
50937
51051
  const constructing = type === true;
51052
+ const typeKey = this.$__schema.options.typeKey;
50938
51053
  let adhocs;
50939
51054
  let keys;
50940
51055
  let i = 0;
@@ -50948,7 +51063,7 @@ Document.prototype.$set = function $set(path, val, type, options) {
50948
51063
 
50949
51064
  if (adhoc) {
50950
51065
  adhocs = this.$__.adhocPaths || (this.$__.adhocPaths = {});
50951
- adhocs[path] = this.schema.interpretAsType(path, type, this.schema.options);
51066
+ adhocs[path] = this.$__schema.interpretAsType(path, type, this.$__schema.options);
50952
51067
  }
50953
51068
 
50954
51069
  if (path == null) {
@@ -50988,7 +51103,7 @@ Document.prototype.$set = function $set(path, val, type, options) {
50988
51103
  for (let i = 0; i < len; ++i) {
50989
51104
  key = keys[i];
50990
51105
  const pathName = prefix + key;
50991
- pathtype = this.schema.pathType(pathName);
51106
+ pathtype = this.$__schema.pathType(pathName);
50992
51107
 
50993
51108
  // On initial set, delete any nested keys if we're going to overwrite
50994
51109
  // them to ensure we keep the user's key order.
@@ -51001,6 +51116,9 @@ Document.prototype.$set = function $set(path, val, type, options) {
51001
51116
  delete this._doc[key];
51002
51117
  // Make sure we set `{}` back even if we minimize re: gh-8565
51003
51118
  options = Object.assign({}, options, { _skipMinimizeTopLevel: true });
51119
+ } else {
51120
+ // Make sure we set `{_skipMinimizeTopLevel: false}` if don't have overwrite: gh-10441
51121
+ options = Object.assign({}, options, { _skipMinimizeTopLevel: false });
51004
51122
  }
51005
51123
 
51006
51124
  const someCondition = typeof path[key] === 'object' &&
@@ -51011,9 +51129,9 @@ Document.prototype.$set = function $set(path, val, type, options) {
51011
51129
  pathtype !== 'real' &&
51012
51130
  pathtype !== 'adhocOrUndefined' &&
51013
51131
  !(this.$__path(pathName) instanceof MixedSchema) &&
51014
- !(this.schema.paths[pathName] &&
51015
- this.schema.paths[pathName].options &&
51016
- this.schema.paths[pathName].options.ref);
51132
+ !(this.$__schema.paths[pathName] &&
51133
+ this.$__schema.paths[pathName].options &&
51134
+ this.$__schema.paths[pathName].options.ref);
51017
51135
 
51018
51136
  if (someCondition) {
51019
51137
  this.$__.$setCalled.add(prefix + key);
@@ -51032,8 +51150,8 @@ Document.prototype.$set = function $set(path, val, type, options) {
51032
51150
  if (pathtype === 'real' || pathtype === 'virtual') {
51033
51151
  // Check for setting single embedded schema to document (gh-3535)
51034
51152
  let p = path[key];
51035
- if (this.schema.paths[pathName] &&
51036
- this.schema.paths[pathName].$isSingleNested &&
51153
+ if (this.$__schema.paths[pathName] &&
51154
+ this.$__schema.paths[pathName].$isSingleNested &&
51037
51155
  path[key] instanceof Document) {
51038
51156
  p = p.toObject({ virtuals: false, transform: false });
51039
51157
  }
@@ -51058,7 +51176,7 @@ Document.prototype.$set = function $set(path, val, type, options) {
51058
51176
  this.$__.$setCalled.add(path);
51059
51177
  }
51060
51178
 
51061
- let pathType = this.schema.pathType(path);
51179
+ let pathType = this.$__schema.pathType(path);
51062
51180
  if (pathType === 'adhocOrUndefined') {
51063
51181
  pathType = getEmbeddedDiscriminatorPath(this, path, { typeOnly: true });
51064
51182
  }
@@ -51109,8 +51227,8 @@ Document.prototype.$set = function $set(path, val, type, options) {
51109
51227
  const parts = path.indexOf('.') === -1 ? [path] : path.split('.');
51110
51228
 
51111
51229
  // Might need to change path for top-level alias
51112
- if (typeof this.schema.aliases[parts[0]] == 'string') {
51113
- parts[0] = this.schema.aliases[parts[0]];
51230
+ if (typeof this.$__schema.aliases[parts[0]] == 'string') {
51231
+ parts[0] = this.$__schema.aliases[parts[0]];
51114
51232
  }
51115
51233
 
51116
51234
  if (pathType === 'adhocOrUndefined' && strict) {
@@ -51121,12 +51239,12 @@ Document.prototype.$set = function $set(path, val, type, options) {
51121
51239
  const subpath = parts.slice(0, i + 1).join('.');
51122
51240
 
51123
51241
  // If path is underneath a virtual, bypass everything and just set it.
51124
- if (i + 1 < parts.length && this.schema.pathType(subpath) === 'virtual') {
51242
+ if (i + 1 < parts.length && this.$__schema.pathType(subpath) === 'virtual') {
51125
51243
  mpath.set(path, val, this);
51126
51244
  return this;
51127
51245
  }
51128
51246
 
51129
- schema = this.schema.path(subpath);
51247
+ schema = this.$__schema.path(subpath);
51130
51248
  if (schema == null) {
51131
51249
  continue;
51132
51250
  }
@@ -51150,7 +51268,7 @@ Document.prototype.$set = function $set(path, val, type, options) {
51150
51268
  return this;
51151
51269
  }
51152
51270
  } else if (pathType === 'virtual') {
51153
- schema = this.schema.virtualpath(path);
51271
+ schema = this.$__schema.virtualpath(path);
51154
51272
  schema.applySetters(val, this);
51155
51273
  return this;
51156
51274
  } else {
@@ -51270,25 +51388,20 @@ Document.prototype.$set = function $set(path, val, type, options) {
51270
51388
 
51271
51389
  let popOpts;
51272
51390
  if (schema.options &&
51273
- Array.isArray(schema.options[this.schema.options.typeKey]) &&
51274
- schema.options[this.schema.options.typeKey].length &&
51275
- schema.options[this.schema.options.typeKey][0].ref &&
51276
- _isManuallyPopulatedArray(val, schema.options[this.schema.options.typeKey][0].ref)) {
51277
- if (this.ownerDocument) {
51278
- popOpts = { [populateModelSymbol]: val[0].constructor };
51279
- this.ownerDocument().populated(this.$__fullPath(path),
51280
- val.map(function(v) { return v._id; }), popOpts);
51281
- } else {
51282
- popOpts = { [populateModelSymbol]: val[0].constructor };
51283
- this.populated(path, val.map(function(v) { return v._id; }), popOpts);
51284
- }
51391
+ Array.isArray(schema.options[typeKey]) &&
51392
+ schema.options[typeKey].length &&
51393
+ schema.options[typeKey][0].ref &&
51394
+ _isManuallyPopulatedArray(val, schema.options[typeKey][0].ref)) {
51395
+ popOpts = { [populateModelSymbol]: val[0].constructor };
51396
+ this.populated(path, val.map(function(v) { return v._id; }), popOpts);
51397
+
51285
51398
  for (const doc of val) {
51286
51399
  doc.$__.wasPopulated = true;
51287
51400
  }
51288
51401
  didPopulate = true;
51289
51402
  }
51290
51403
 
51291
- if (this.schema.singleNestedPaths[path] == null) {
51404
+ if (this.$__schema.singleNestedPaths[path] == null) {
51292
51405
  // If this path is underneath a single nested schema, we'll call the setter
51293
51406
  // later in `$__set()` because we don't take `_doc` when we iterate through
51294
51407
  // a single nested doc. That's to make sure we get the correct context.
@@ -51447,7 +51560,7 @@ Document.prototype.$__shouldModify = function(pathToMark, path, constructing, pa
51447
51560
  // Re: the note about gh-7196, `val` is the raw value without casting or
51448
51561
  // setters if the full path is under a single nested subdoc because we don't
51449
51562
  // want to double run setters. So don't set it as modified. See gh-7264.
51450
- if (this.schema.singleNestedPaths[path] != null) {
51563
+ if (this.$__schema.singleNestedPaths[path] != null) {
51451
51564
  return false;
51452
51565
  }
51453
51566
 
@@ -51610,20 +51723,20 @@ Document.prototype.get = function(path, type, options) {
51610
51723
  let adhoc;
51611
51724
  options = options || {};
51612
51725
  if (type) {
51613
- adhoc = this.schema.interpretAsType(path, type, this.schema.options);
51726
+ adhoc = this.$__schema.interpretAsType(path, type, this.$__schema.options);
51614
51727
  }
51615
51728
 
51616
51729
  let schema = this.$__path(path);
51617
51730
  if (schema == null) {
51618
- schema = this.schema.virtualpath(path);
51731
+ schema = this.$__schema.virtualpath(path);
51619
51732
  }
51620
51733
  if (schema instanceof MixedSchema) {
51621
- const virtual = this.schema.virtualpath(path);
51734
+ const virtual = this.$__schema.virtualpath(path);
51622
51735
  if (virtual != null) {
51623
51736
  schema = virtual;
51624
51737
  }
51625
51738
  }
51626
- const pieces = path.split('.');
51739
+ const pieces = path.indexOf('.') === -1 ? [path] : path.split('.');
51627
51740
  let obj = this._doc;
51628
51741
 
51629
51742
  if (schema instanceof VirtualType) {
@@ -51631,8 +51744,8 @@ Document.prototype.get = function(path, type, options) {
51631
51744
  }
51632
51745
 
51633
51746
  // Might need to change path for top-level alias
51634
- if (typeof this.schema.aliases[pieces[0]] == 'string') {
51635
- pieces[0] = this.schema.aliases[pieces[0]];
51747
+ if (typeof this.$__schema.aliases[pieces[0]] == 'string') {
51748
+ pieces[0] = this.$__schema.aliases[pieces[0]];
51636
51749
  }
51637
51750
 
51638
51751
  for (let i = 0, l = pieces.length; i < l; i++) {
@@ -51657,7 +51770,7 @@ Document.prototype.get = function(path, type, options) {
51657
51770
 
51658
51771
  if (schema != null && options.getters !== false) {
51659
51772
  obj = schema.applyGetters(obj, this);
51660
- } else if (this.schema.nested[path] && options.virtuals) {
51773
+ } else if (this.$__schema.nested[path] && options.virtuals) {
51661
51774
  // Might need to apply virtuals if this is a nested path
51662
51775
  return applyVirtuals(this, utils.clone(obj) || {}, { path: path });
51663
51776
  }
@@ -51688,7 +51801,7 @@ Document.prototype.$__path = function(path) {
51688
51801
  if (adhocType) {
51689
51802
  return adhocType;
51690
51803
  }
51691
- return this.schema.path(path);
51804
+ return this.$__schema.path(path);
51692
51805
  };
51693
51806
 
51694
51807
  /**
@@ -52223,6 +52336,7 @@ Document.prototype.isDirectSelected = function isDirectSelected(path) {
52223
52336
  * @param {Array|String} [pathsToValidate] list of paths to validate. If set, Mongoose will validate only the modified paths that are in the given list.
52224
52337
  * @param {Object} [options] internal options
52225
52338
  * @param {Boolean} [options.validateModifiedOnly=false] if `true` mongoose validates only modified paths.
52339
+ * @param {Array|string} [options.pathsToSkip] list of paths to skip. If set, Mongoose will validate every modified path that is not in this list.
52226
52340
  * @param {Function} [callback] optional callback called after validation completes, passing an error if one occurred
52227
52341
  * @return {Promise} Promise
52228
52342
  * @api public
@@ -52243,7 +52357,17 @@ Document.prototype.validate = function(pathsToValidate, options, callback) {
52243
52357
  this.$__.validating = new ParallelValidateError(this, { parentStack: options && options.parentStack });
52244
52358
  }
52245
52359
 
52246
- if (typeof pathsToValidate === 'function') {
52360
+ if (arguments.length === 1) {
52361
+ if (typeof arguments[0] === 'object' && !Array.isArray(arguments[0])) {
52362
+ options = arguments[0];
52363
+ callback = null;
52364
+ pathsToValidate = null;
52365
+ } else if (typeof arguments[0] === 'function') {
52366
+ callback = arguments[0];
52367
+ options = null;
52368
+ pathsToValidate = null;
52369
+ }
52370
+ } else if (typeof pathsToValidate === 'function') {
52247
52371
  callback = pathsToValidate;
52248
52372
  options = null;
52249
52373
  pathsToValidate = null;
@@ -52252,6 +52376,10 @@ Document.prototype.validate = function(pathsToValidate, options, callback) {
52252
52376
  options = pathsToValidate;
52253
52377
  pathsToValidate = null;
52254
52378
  }
52379
+ if (options && typeof options.pathsToSkip === 'string') {
52380
+ const isOnePathOnly = options.pathsToSkip.indexOf(' ') === -1;
52381
+ options.pathsToSkip = isOnePathOnly ? [options.pathsToSkip] : options.pathsToSkip.split(' ');
52382
+ }
52255
52383
 
52256
52384
  return promiseOrCallback(callback, cb => {
52257
52385
  if (parallelValidate != null) {
@@ -52271,7 +52399,7 @@ Document.prototype.validate = function(pathsToValidate, options, callback) {
52271
52399
 
52272
52400
  function _evaluateRequiredFunctions(doc) {
52273
52401
  Object.keys(doc.$__.activePaths.states.require).forEach(path => {
52274
- const p = doc.schema.path(path);
52402
+ const p = doc.$__schema.path(path);
52275
52403
 
52276
52404
  if (p != null && typeof p.originalRequiredValue === 'function') {
52277
52405
  doc.$__.cachedRequired[path] = p.originalRequiredValue.call(doc, doc);
@@ -52304,7 +52432,7 @@ function _getPathsToValidate(doc) {
52304
52432
  Object.keys(doc.$__.activePaths.states.default).forEach(addToPaths);
52305
52433
  function addToPaths(p) { paths.add(p); }
52306
52434
 
52307
- const subdocs = doc.$__getAllSubdocs();
52435
+ const subdocs = doc.$getAllSubdocs();
52308
52436
  const modifiedPaths = doc.modifiedPaths();
52309
52437
  for (const subdoc of subdocs) {
52310
52438
  if (subdoc.$basePath) {
@@ -52331,7 +52459,7 @@ function _getPathsToValidate(doc) {
52331
52459
  // gh-661: if a whole array is modified, make sure to run validation on all
52332
52460
  // the children as well
52333
52461
  for (const path of paths) {
52334
- const _pathType = doc.schema.path(path);
52462
+ const _pathType = doc.$__schema.path(path);
52335
52463
  if (!_pathType ||
52336
52464
  !_pathType.$isMongooseArray ||
52337
52465
  // To avoid potential performance issues, skip doc arrays whose children
@@ -52360,12 +52488,12 @@ function _getPathsToValidate(doc) {
52360
52488
 
52361
52489
  const flattenOptions = { skipArrays: true };
52362
52490
  for (const pathToCheck of paths) {
52363
- if (doc.schema.nested[pathToCheck]) {
52491
+ if (doc.$__schema.nested[pathToCheck]) {
52364
52492
  let _v = doc.$__getValue(pathToCheck);
52365
52493
  if (isMongooseObject(_v)) {
52366
52494
  _v = _v.toObject({ transform: false });
52367
52495
  }
52368
- const flat = flatten(_v, pathToCheck, flattenOptions, doc.schema);
52496
+ const flat = flatten(_v, pathToCheck, flattenOptions, doc.$__schema);
52369
52497
  Object.keys(flat).forEach(addToPaths);
52370
52498
  }
52371
52499
  }
@@ -52374,11 +52502,11 @@ function _getPathsToValidate(doc) {
52374
52502
  // Single nested paths (paths embedded under single nested subdocs) will
52375
52503
  // be validated on their own when we call `validate()` on the subdoc itself.
52376
52504
  // Re: gh-8468
52377
- if (doc.schema.singleNestedPaths.hasOwnProperty(path)) {
52505
+ if (doc.$__schema.singleNestedPaths.hasOwnProperty(path)) {
52378
52506
  paths.delete(path);
52379
52507
  continue;
52380
52508
  }
52381
- const _pathType = doc.schema.path(path);
52509
+ const _pathType = doc.$__schema.path(path);
52382
52510
  if (!_pathType || !_pathType.$isSchemaMap) {
52383
52511
  continue;
52384
52512
  }
@@ -52414,11 +52542,13 @@ Document.prototype.$__validate = function(pathsToValidate, options, callback) {
52414
52542
  (typeof options === 'object') &&
52415
52543
  ('validateModifiedOnly' in options);
52416
52544
 
52545
+ const pathsToSkip = get(options, 'pathsToSkip', null);
52546
+
52417
52547
  let shouldValidateModifiedOnly;
52418
52548
  if (hasValidateModifiedOnlyOption) {
52419
52549
  shouldValidateModifiedOnly = !!options.validateModifiedOnly;
52420
52550
  } else {
52421
- shouldValidateModifiedOnly = this.schema.options.validateModifiedOnly;
52551
+ shouldValidateModifiedOnly = this.$__schema.options.validateModifiedOnly;
52422
52552
  }
52423
52553
 
52424
52554
  const _this = this;
@@ -52463,14 +52593,19 @@ Document.prototype.$__validate = function(pathsToValidate, options, callback) {
52463
52593
  pathDetails[0].filter((path) => this.isModified(path)) :
52464
52594
  pathDetails[0];
52465
52595
  const skipSchemaValidators = pathDetails[1];
52596
+ if (typeof pathsToValidate === 'string') {
52597
+ pathsToValidate = pathsToValidate.split(' ');
52598
+ }
52466
52599
  if (Array.isArray(pathsToValidate)) {
52467
52600
  paths = _handlePathsToValidate(paths, pathsToValidate);
52601
+ } else if (pathsToSkip) {
52602
+ paths = _handlePathsToSkip(paths, pathsToSkip);
52468
52603
  }
52469
52604
  if (paths.length === 0) {
52470
- return process.nextTick(function() {
52605
+ return immediate(function() {
52471
52606
  const error = _complete();
52472
52607
  if (error) {
52473
- return _this.schema.s.hooks.execPost('validate:error', _this, [_this], { error: error }, function(error) {
52608
+ return _this.$__schema.s.hooks.execPost('validate:error', _this, [_this], { error: error }, function(error) {
52474
52609
  callback(error);
52475
52610
  });
52476
52611
  }
@@ -52481,17 +52616,11 @@ Document.prototype.$__validate = function(pathsToValidate, options, callback) {
52481
52616
  const validated = {};
52482
52617
  let total = 0;
52483
52618
 
52484
- const complete = function() {
52485
- const error = _complete();
52486
- if (error) {
52487
- return _this.schema.s.hooks.execPost('validate:error', _this, [_this], { error: error }, function(error) {
52488
- callback(error);
52489
- });
52490
- }
52491
- callback(null, _this);
52492
- };
52619
+ for (const path of paths) {
52620
+ validatePath(path);
52621
+ }
52493
52622
 
52494
- const validatePath = function(path) {
52623
+ function validatePath(path) {
52495
52624
  if (path == null || validated[path]) {
52496
52625
  return;
52497
52626
  }
@@ -52499,8 +52628,8 @@ Document.prototype.$__validate = function(pathsToValidate, options, callback) {
52499
52628
  validated[path] = true;
52500
52629
  total++;
52501
52630
 
52502
- process.nextTick(function() {
52503
- const schemaType = _this.schema.path(path);
52631
+ immediate(function() {
52632
+ const schemaType = _this.$__schema.path(path);
52504
52633
 
52505
52634
  if (!schemaType) {
52506
52635
  return --total || complete();
@@ -52512,6 +52641,11 @@ Document.prototype.$__validate = function(pathsToValidate, options, callback) {
52512
52641
  return;
52513
52642
  }
52514
52643
 
52644
+ // If setting a path under a mixed path, avoid using the mixed path validator (gh-10141)
52645
+ if (schemaType[schemaMixedSymbol] != null && path !== schemaType.path) {
52646
+ return --total || complete();
52647
+ }
52648
+
52515
52649
  let val = _this.$__getValue(path);
52516
52650
 
52517
52651
  // If you `populate()` and get back a null value, required validators
@@ -52542,12 +52676,18 @@ Document.prototype.$__validate = function(pathsToValidate, options, callback) {
52542
52676
  --total || complete();
52543
52677
  }, scope, doValidateOptions);
52544
52678
  });
52545
- };
52679
+ }
52546
52680
 
52547
- const numPaths = paths.length;
52548
- for (let i = 0; i < numPaths; ++i) {
52549
- validatePath(paths[i]);
52681
+ function complete() {
52682
+ const error = _complete();
52683
+ if (error) {
52684
+ return _this.$__schema.s.hooks.execPost('validate:error', _this, [_this], { error: error }, function(error) {
52685
+ callback(error);
52686
+ });
52687
+ }
52688
+ callback(null, _this);
52550
52689
  }
52690
+
52551
52691
  };
52552
52692
 
52553
52693
  /*!
@@ -52583,6 +52723,15 @@ function _handlePathsToValidate(paths, pathsToValidate) {
52583
52723
  return ret;
52584
52724
  }
52585
52725
 
52726
+ /*!
52727
+ * ignore
52728
+ */
52729
+ function _handlePathsToSkip(paths, pathsToSkip) {
52730
+ pathsToSkip = new Set(pathsToSkip);
52731
+ paths = paths.filter(p => !pathsToSkip.has(p));
52732
+ return paths;
52733
+ }
52734
+
52586
52735
  /**
52587
52736
  * Executes registered validation rules (skipping asynchronous validators) for this document.
52588
52737
  *
@@ -52602,6 +52751,7 @@ function _handlePathsToValidate(paths, pathsToValidate) {
52602
52751
  * @param {Array|string} pathsToValidate only validate the given paths
52603
52752
  * @param {Object} [options] options for validation
52604
52753
  * @param {Boolean} [options.validateModifiedOnly=false] If `true`, Mongoose will only validate modified paths, as opposed to modified paths and `required` paths.
52754
+ * @param {Array|string} [options.pathsToSkip] list of paths to skip. If set, Mongoose will validate every modified path that is not in this list.
52605
52755
  * @return {ValidationError|undefined} ValidationError if there are errors during validation, or undefined if there is no error.
52606
52756
  * @api public
52607
52757
  */
@@ -52609,6 +52759,11 @@ function _handlePathsToValidate(paths, pathsToValidate) {
52609
52759
  Document.prototype.validateSync = function(pathsToValidate, options) {
52610
52760
  const _this = this;
52611
52761
 
52762
+ if (arguments.length === 1 && typeof arguments[0] === 'object' && !Array.isArray(arguments[0])) {
52763
+ options = arguments[0];
52764
+ pathsToValidate = null;
52765
+ }
52766
+
52612
52767
  const hasValidateModifiedOnlyOption = options &&
52613
52768
  (typeof options === 'object') &&
52614
52769
  ('validateModifiedOnly' in options);
@@ -52617,11 +52772,16 @@ Document.prototype.validateSync = function(pathsToValidate, options) {
52617
52772
  if (hasValidateModifiedOnlyOption) {
52618
52773
  shouldValidateModifiedOnly = !!options.validateModifiedOnly;
52619
52774
  } else {
52620
- shouldValidateModifiedOnly = this.schema.options.validateModifiedOnly;
52775
+ shouldValidateModifiedOnly = this.$__schema.options.validateModifiedOnly;
52621
52776
  }
52622
52777
 
52778
+ let pathsToSkip = options && options.pathsToSkip;
52779
+
52623
52780
  if (typeof pathsToValidate === 'string') {
52624
- pathsToValidate = pathsToValidate.split(' ');
52781
+ const isOnePathOnly = pathsToValidate.indexOf(' ') === -1;
52782
+ pathsToValidate = isOnePathOnly ? [pathsToValidate] : pathsToValidate.split(' ');
52783
+ } else if (typeof pathsToSkip === 'string' && pathsToSkip.indexOf(' ') !== -1) {
52784
+ pathsToSkip = pathsToSkip.split(' ');
52625
52785
  }
52626
52786
 
52627
52787
  // only validate required fields when necessary
@@ -52633,6 +52793,8 @@ Document.prototype.validateSync = function(pathsToValidate, options) {
52633
52793
 
52634
52794
  if (Array.isArray(pathsToValidate)) {
52635
52795
  paths = _handlePathsToValidate(paths, pathsToValidate);
52796
+ } else if (Array.isArray(pathsToSkip)) {
52797
+ paths = _handlePathsToSkip(paths, pathsToSkip);
52636
52798
  }
52637
52799
  const validating = {};
52638
52800
 
@@ -52643,7 +52805,7 @@ Document.prototype.validateSync = function(pathsToValidate, options) {
52643
52805
 
52644
52806
  validating[path] = true;
52645
52807
 
52646
- const p = _this.schema.path(path);
52808
+ const p = _this.$__schema.path(path);
52647
52809
  if (!p) {
52648
52810
  return;
52649
52811
  }
@@ -52916,7 +53078,13 @@ Document.prototype.$__reset = function reset() {
52916
53078
  }).
52917
53079
  forEach(function(doc) {
52918
53080
  doc.$__reset();
52919
- _this.$__.activePaths.init(doc.$basePath);
53081
+ if (doc.$__parent === _this) {
53082
+ _this.$__.activePaths.init(doc.$basePath);
53083
+ } else if (doc.$__parent != null && doc.$__parent.ownerDocument) {
53084
+ // If map path underneath subdocument, may end up with a case where
53085
+ // map path is modified but parent still needs to be reset. See gh-10295
53086
+ doc.$__parent.$__reset();
53087
+ }
52920
53088
  });
52921
53089
 
52922
53090
  // clear atomics
@@ -52943,7 +53111,7 @@ Document.prototype.$__reset = function reset() {
52943
53111
  this.$__.validationError = undefined;
52944
53112
  this.errors = undefined;
52945
53113
  _this = this;
52946
- this.schema.requiredPaths().forEach(function(path) {
53114
+ this.$__schema.requiredPaths().forEach(function(path) {
52947
53115
  _this.$__.activePaths.require(path);
52948
53116
  });
52949
53117
 
@@ -52973,7 +53141,7 @@ Document.prototype.$__undoReset = function $__undoReset() {
52973
53141
  }
52974
53142
  }
52975
53143
 
52976
- for (const subdoc of this.$__getAllSubdocs()) {
53144
+ for (const subdoc of this.$getAllSubdocs()) {
52977
53145
  subdoc.$__undoReset();
52978
53146
  }
52979
53147
  };
@@ -52997,7 +53165,6 @@ Document.prototype.$__dirty = function() {
52997
53165
  schema: _this.$__path(path)
52998
53166
  };
52999
53167
  });
53000
-
53001
53168
  // gh-2558: if we had to set a default and the value is not undefined,
53002
53169
  // we have to save as well
53003
53170
  all = all.concat(this.$__.activePaths.map('default', function(path) {
@@ -53041,7 +53208,6 @@ Document.prototype.$__dirty = function() {
53041
53208
  top.value[arrayAtomicsSymbol].$set = top.value;
53042
53209
  }
53043
53210
  });
53044
-
53045
53211
  top = lastPath = null;
53046
53212
  return minimal;
53047
53213
  };
@@ -53064,8 +53230,10 @@ Document.prototype.$__setSchema = function(schema) {
53064
53230
  for (const key of Object.keys(schema.virtuals)) {
53065
53231
  schema.virtuals[key]._applyDefaultGetters();
53066
53232
  }
53067
-
53068
- this.schema = schema;
53233
+ if (schema.path('schema') == null) {
53234
+ this.schema = schema;
53235
+ }
53236
+ this.$__schema = schema;
53069
53237
  this[documentSchemaSymbol] = schema;
53070
53238
  };
53071
53239
 
@@ -53101,21 +53269,25 @@ Document.prototype.$__getArrayPathsToValidate = function() {
53101
53269
  /**
53102
53270
  * Get all subdocs (by bfs)
53103
53271
  *
53104
- * @api private
53105
- * @method $__getAllSubdocs
53272
+ * @api public
53273
+ * @method $getAllSubdocs
53106
53274
  * @memberOf Document
53107
53275
  * @instance
53108
53276
  */
53109
53277
 
53110
- Document.prototype.$__getAllSubdocs = function() {
53278
+ Document.prototype.$getAllSubdocs = function $getAllSubdocs() {
53111
53279
  DocumentArray || (DocumentArray = require('./types/documentarray'));
53112
53280
  Embedded = Embedded || require('./types/embedded');
53113
53281
 
53114
53282
  function docReducer(doc, seed, path) {
53115
53283
  let val = doc;
53284
+ let isNested = false;
53116
53285
  if (path) {
53117
53286
  if (doc instanceof Document && doc[documentSchemaSymbol].paths[path]) {
53118
53287
  val = doc._doc[path];
53288
+ } else if (doc instanceof Document && doc[documentSchemaSymbol].nested[path]) {
53289
+ val = doc._doc[path];
53290
+ isNested = true;
53119
53291
  } else {
53120
53292
  val = doc[path];
53121
53293
  }
@@ -53143,18 +53315,18 @@ Document.prototype.$__getAllSubdocs = function() {
53143
53315
  seed.push(doc);
53144
53316
  }
53145
53317
  });
53146
- } else if (val instanceof Document && val.$__isNested) {
53147
- seed = Object.keys(val).reduce(function(seed, path) {
53148
- return docReducer(val, seed, path);
53149
- }, seed);
53318
+ } else if (isNested && val != null) {
53319
+ for (const path of Object.keys(val)) {
53320
+ docReducer(val, seed, path);
53321
+ }
53150
53322
  }
53151
53323
  return seed;
53152
53324
  }
53153
53325
 
53154
- const _this = this;
53155
- const subDocs = Object.keys(this._doc).reduce(function(seed, path) {
53156
- return docReducer(_this, seed, path);
53157
- }, []);
53326
+ const subDocs = [];
53327
+ for (const path of Object.keys(this._doc)) {
53328
+ docReducer(this, subDocs, path);
53329
+ }
53158
53330
 
53159
53331
  return subDocs;
53160
53332
  };
@@ -53164,7 +53336,7 @@ Document.prototype.$__getAllSubdocs = function() {
53164
53336
  */
53165
53337
 
53166
53338
  function applyQueue(doc) {
53167
- const q = doc.schema && doc.schema.callQueue;
53339
+ const q = doc.$__schema && doc.$__schema.callQueue;
53168
53340
  if (!q.length) {
53169
53341
  return;
53170
53342
  }
@@ -53206,7 +53378,7 @@ Document.prototype.$toObject = function(options, json) {
53206
53378
 
53207
53379
  const path = json ? 'toJSON' : 'toObject';
53208
53380
  const baseOptions = get(this, 'constructor.base.options.' + path, {});
53209
- const schemaOptions = get(this, 'schema.options', {});
53381
+ const schemaOptions = get(this, '$__schema.options', {});
53210
53382
  // merge base default options with Schema's set default options if available.
53211
53383
  // `clone` is necessary here because `utils.options` directly modifies the second input.
53212
53384
  defaultOptions = utils.options(defaultOptions, clone(baseOptions));
@@ -53216,10 +53388,6 @@ Document.prototype.$toObject = function(options, json) {
53216
53388
  options = utils.isPOJO(options) ? clone(options) : {};
53217
53389
  options._calledWithOptions = options._calledWithOptions || clone(options);
53218
53390
 
53219
- if (!('flattenMaps' in options)) {
53220
- options.flattenMaps = defaultOptions.flattenMaps;
53221
- }
53222
-
53223
53391
  let _minimize;
53224
53392
  if (options._calledWithOptions.minimize != null) {
53225
53393
  _minimize = options.minimize;
@@ -53229,6 +53397,15 @@ Document.prototype.$toObject = function(options, json) {
53229
53397
  _minimize = schemaOptions.minimize;
53230
53398
  }
53231
53399
 
53400
+ let flattenMaps;
53401
+ if (options._calledWithOptions.flattenMaps != null) {
53402
+ flattenMaps = options.flattenMaps;
53403
+ } else if (defaultOptions.flattenMaps != null) {
53404
+ flattenMaps = defaultOptions.flattenMaps;
53405
+ } else {
53406
+ flattenMaps = schemaOptions.flattenMaps;
53407
+ }
53408
+
53232
53409
  // The original options that will be passed to `clone()`. Important because
53233
53410
  // `clone()` will recursively call `$toObject()` on embedded docs, so we
53234
53411
  // need the original options the user passed in, plus `_isNested` and
@@ -53236,7 +53413,8 @@ Document.prototype.$toObject = function(options, json) {
53236
53413
  const cloneOptions = Object.assign(utils.clone(options), {
53237
53414
  _isNested: true,
53238
53415
  json: json,
53239
- minimize: _minimize
53416
+ minimize: _minimize,
53417
+ flattenMaps: flattenMaps
53240
53418
  });
53241
53419
 
53242
53420
  if (utils.hasUserDefinedProperty(options, 'getters')) {
@@ -53285,8 +53463,8 @@ Document.prototype.$toObject = function(options, json) {
53285
53463
  applyVirtuals(this, ret, gettersOptions, options);
53286
53464
  }
53287
53465
 
53288
- if (options.versionKey === false && this.schema.options.versionKey) {
53289
- delete ret[this.schema.options.versionKey];
53466
+ if (options.versionKey === false && this.$__schema.options.versionKey) {
53467
+ delete ret[this.$__schema.options.versionKey];
53290
53468
  }
53291
53469
 
53292
53470
  let transform = options.transform;
@@ -53516,7 +53694,7 @@ function minimize(obj) {
53516
53694
  */
53517
53695
 
53518
53696
  function applyVirtuals(self, json, options, toObjectOptions) {
53519
- const schema = self.schema;
53697
+ const schema = self.$__schema;
53520
53698
  const paths = Object.keys(schema.virtuals);
53521
53699
  let i = paths.length;
53522
53700
  const numPaths = i;
@@ -53526,6 +53704,19 @@ function applyVirtuals(self, json, options, toObjectOptions) {
53526
53704
  let v;
53527
53705
  const aliases = get(toObjectOptions, 'aliases', true);
53528
53706
 
53707
+ let virtualsToApply = null;
53708
+ if (Array.isArray(options.virtuals)) {
53709
+ virtualsToApply = new Set(options.virtuals);
53710
+ }
53711
+ else if (options.virtuals && options.virtuals.pathsToSkip) {
53712
+ virtualsToApply = new Set(paths);
53713
+ for (let i = 0; i < options.virtuals.pathsToSkip.length; i++) {
53714
+ if (virtualsToApply.has(options.virtuals.pathsToSkip[i])) {
53715
+ virtualsToApply.delete(options.virtuals.pathsToSkip[i]);
53716
+ }
53717
+ }
53718
+ }
53719
+
53529
53720
  if (!cur) {
53530
53721
  return json;
53531
53722
  }
@@ -53534,6 +53725,10 @@ function applyVirtuals(self, json, options, toObjectOptions) {
53534
53725
  for (i = 0; i < numPaths; ++i) {
53535
53726
  path = paths[i];
53536
53727
 
53728
+ if (virtualsToApply != null && !virtualsToApply.has(path)) {
53729
+ continue;
53730
+ }
53731
+
53537
53732
  // Allow skipping aliases with `toObject({ virtuals: true, aliases: false })`
53538
53733
  if (!aliases && schema.aliases.hasOwnProperty(path)) {
53539
53734
  continue;
@@ -53566,6 +53761,7 @@ function applyVirtuals(self, json, options, toObjectOptions) {
53566
53761
  return json;
53567
53762
  }
53568
53763
 
53764
+
53569
53765
  /*!
53570
53766
  * Applies virtuals properties to `json`.
53571
53767
  *
@@ -53575,7 +53771,7 @@ function applyVirtuals(self, json, options, toObjectOptions) {
53575
53771
  */
53576
53772
 
53577
53773
  function applyGetters(self, json, options) {
53578
- const schema = self.schema;
53774
+ const schema = self.$__schema;
53579
53775
  const paths = Object.keys(schema.paths);
53580
53776
  let i = paths.length;
53581
53777
  let path;
@@ -53630,7 +53826,7 @@ function applyGetters(self, json, options) {
53630
53826
  */
53631
53827
 
53632
53828
  function applySchemaTypeTransforms(self, json) {
53633
- const schema = self.schema;
53829
+ const schema = self.$__schema;
53634
53830
  const paths = Object.keys(schema.paths || {});
53635
53831
  const cur = self._doc;
53636
53832
 
@@ -53673,7 +53869,7 @@ function throwErrorIfPromise(path, transformedValue) {
53673
53869
  */
53674
53870
 
53675
53871
  function omitDeselectedFields(self, json) {
53676
- const schema = self.schema;
53872
+ const schema = self.$__schema;
53677
53873
  const paths = Object.keys(schema.paths || {});
53678
53874
  const cur = self._doc;
53679
53875
 
@@ -53928,6 +54124,34 @@ Document.prototype.populate = function populate() {
53928
54124
  return this;
53929
54125
  };
53930
54126
 
54127
+ /**
54128
+ * Gets all populated documents associated with this document.
54129
+ *
54130
+ * @api public
54131
+ * @return {Array<Document>} array of populated documents. Empty array if there are no populated documents associated with this document.
54132
+ * @memberOf Document
54133
+ * @instance
54134
+ */
54135
+ Document.prototype.$getPopulatedDocs = function $getPopulatedDocs() {
54136
+ let keys = [];
54137
+ if (this.$__.populated != null) {
54138
+ keys = keys.concat(Object.keys(this.$__.populated));
54139
+ }
54140
+ if (this.$$populatedVirtuals != null) {
54141
+ keys = keys.concat(Object.keys(this.$$populatedVirtuals));
54142
+ }
54143
+ let result = [];
54144
+ for (const key of keys) {
54145
+ const value = this.get(key);
54146
+ if (Array.isArray(value)) {
54147
+ result = result.concat(value);
54148
+ } else if (value instanceof Document) {
54149
+ result.push(value);
54150
+ }
54151
+ }
54152
+ return result;
54153
+ };
54154
+
53931
54155
  /**
53932
54156
  * Explicitly executes population and returns a promise. Useful for promises integration.
53933
54157
  *
@@ -53997,25 +54221,21 @@ Document.prototype.execPopulate = function(callback) {
53997
54221
 
53998
54222
  Document.prototype.populated = function(path, val, options) {
53999
54223
  // val and options are internal
54000
- if (val === null || val === void 0) {
54224
+ if (val == null || val === true) {
54001
54225
  if (!this.$__.populated) {
54002
54226
  return undefined;
54003
54227
  }
54004
- const v = this.$__.populated[path];
54228
+
54229
+ // Map paths can be populated with either `path.$*` or just `path`
54230
+ const _path = path.endsWith('.$*') ? path.replace(/\.\$\*$/, '') : path;
54231
+
54232
+ const v = this.$__.populated[_path];
54005
54233
  if (v) {
54006
- return v.value;
54234
+ return val === true ? v : v.value;
54007
54235
  }
54008
54236
  return undefined;
54009
54237
  }
54010
54238
 
54011
- // internal
54012
- if (val === true) {
54013
- if (!this.$__.populated) {
54014
- return undefined;
54015
- }
54016
- return this.$__.populated[path];
54017
- }
54018
-
54019
54239
  this.$__.populated || (this.$__.populated = {});
54020
54240
  this.$__.populated[path] = { value: val, options: options };
54021
54241
 
@@ -54048,7 +54268,7 @@ Document.prototype.populated = function(path, val, options) {
54048
54268
  * console.log(doc.author); // '5144cf8050f071d979c118a7'
54049
54269
  * })
54050
54270
  *
54051
- * If the path was not populated, this is a no-op.
54271
+ * If the path was not provided, then all populated fields are returned to their unpopulated state.
54052
54272
  *
54053
54273
  * @param {String} path
54054
54274
  * @return {Document} this
@@ -54083,7 +54303,7 @@ Document.prototype.depopulate = function(path) {
54083
54303
  continue;
54084
54304
  }
54085
54305
  delete populated[key];
54086
- this.$set(key, populatedIds);
54306
+ utils.setValue(key, populatedIds, this._doc);
54087
54307
  }
54088
54308
  return this;
54089
54309
  }
@@ -54096,7 +54316,7 @@ Document.prototype.depopulate = function(path) {
54096
54316
  delete this.$$populatedVirtuals[singlePath];
54097
54317
  delete this._doc[singlePath];
54098
54318
  } else if (populatedIds) {
54099
- this.$set(singlePath, populatedIds);
54319
+ utils.setValue(singlePath, populatedIds, this._doc);
54100
54320
  }
54101
54321
  }
54102
54322
  return this;
@@ -54173,8 +54393,8 @@ Document.prototype.getChanges = function() {
54173
54393
  Document.ValidationError = ValidationError;
54174
54394
  module.exports = exports = Document;
54175
54395
 
54176
- }).call(this)}).call(this,{"isBuffer":require("../../is-buffer/index.js")},require('_process'))
54177
- },{"../../is-buffer/index.js":179,"./error/index":204,"./error/objectExpected":209,"./error/objectParameter":210,"./error/parallelValidate":213,"./error/strict":214,"./error/validation":215,"./error/validator":216,"./helpers/common":220,"./helpers/document/cleanModifiedSubpaths":225,"./helpers/document/compile":226,"./helpers/document/getEmbeddedDiscriminatorPath":227,"./helpers/document/handleSpreadDoc":228,"./helpers/get":229,"./helpers/isPromise":235,"./helpers/projection/isDefiningProjection":239,"./helpers/projection/isExclusive":240,"./helpers/promiseOrCallback":241,"./helpers/symbols":252,"./internal":256,"./options":257,"./plugins/idGetter":271,"./queryhelpers":273,"./schema":274,"./schema/mixed":284,"./types/array":297,"./types/documentarray":301,"./types/embedded":302,"./utils":307,"./virtualtype":308,"_process":325,"events":177,"mpath":310,"util":332}],195:[function(require,module,exports){
54396
+ }).call(this)}).call(this,{"isBuffer":require("../../is-buffer/index.js")})
54397
+ },{"../../is-buffer/index.js":179,"./error/index":204,"./error/objectExpected":209,"./error/objectParameter":210,"./error/parallelValidate":213,"./error/strict":214,"./error/validation":215,"./error/validator":216,"./helpers/common":220,"./helpers/document/cleanModifiedSubpaths":226,"./helpers/document/compile":227,"./helpers/document/getEmbeddedDiscriminatorPath":228,"./helpers/document/handleSpreadDoc":229,"./helpers/get":230,"./helpers/immediate":233,"./helpers/isPromise":237,"./helpers/projection/isDefiningProjection":241,"./helpers/projection/isExclusive":242,"./helpers/promiseOrCallback":243,"./helpers/symbols":254,"./internal":258,"./options":259,"./plugins/idGetter":273,"./queryhelpers":275,"./schema":276,"./schema/mixed":286,"./schema/symbols":296,"./types/array":299,"./types/documentarray":303,"./types/embedded":304,"./utils":309,"./virtualtype":310,"events":177,"mpath":312,"util":334}],195:[function(require,module,exports){
54178
54398
  'use strict';
54179
54399
 
54180
54400
  /* eslint-env browser */
@@ -54268,6 +54488,9 @@ exports.Binary = require('./binary');
54268
54488
  exports.Collection = function() {
54269
54489
  throw new Error('Cannot create a collection from browser library');
54270
54490
  };
54491
+ exports.getConnection = () => function() {
54492
+ throw new Error('Cannot create a connection from browser library');
54493
+ };
54271
54494
  exports.Decimal128 = require('./decimal128');
54272
54495
  exports.ObjectId = require('./objectid');
54273
54496
  exports.ReadPreference = require('./ReadPreference');
@@ -54327,8 +54550,9 @@ class CastError extends MongooseError {
54327
54550
  // If no args, assume we'll `init()` later.
54328
54551
  if (arguments.length > 0) {
54329
54552
  const stringValue = getStringValue(value);
54553
+ const valueType = getValueType(value);
54330
54554
  const messageFormat = getMessageFormat(schemaType);
54331
- const msg = formatMessage(null, type, stringValue, path, messageFormat);
54555
+ const msg = formatMessage(null, type, stringValue, path, messageFormat, valueType);
54332
54556
  super(msg);
54333
54557
  this.init(type, value, path, reason, schemaType);
54334
54558
  } else {
@@ -54336,6 +54560,18 @@ class CastError extends MongooseError {
54336
54560
  }
54337
54561
  }
54338
54562
 
54563
+ toJSON() {
54564
+ return {
54565
+ stringValue: this.stringValue,
54566
+ valueType: this.valueType,
54567
+ kind: this.kind,
54568
+ value: this.value,
54569
+ path: this.path,
54570
+ reason: this.reason,
54571
+ name: this.name,
54572
+ message: this.message
54573
+ };
54574
+ }
54339
54575
  /*!
54340
54576
  * ignore
54341
54577
  */
@@ -54346,6 +54582,7 @@ class CastError extends MongooseError {
54346
54582
  this.value = value;
54347
54583
  this.path = path;
54348
54584
  this.reason = reason;
54585
+ this.valueType = getValueType(value);
54349
54586
  }
54350
54587
 
54351
54588
  /*!
@@ -54360,6 +54597,7 @@ class CastError extends MongooseError {
54360
54597
  this.path = other.path;
54361
54598
  this.reason = other.reason;
54362
54599
  this.message = other.message;
54600
+ this.valueType = other.valueType;
54363
54601
  }
54364
54602
 
54365
54603
  /*!
@@ -54368,7 +54606,7 @@ class CastError extends MongooseError {
54368
54606
  setModel(model) {
54369
54607
  this.model = model;
54370
54608
  this.message = formatMessage(model, this.kind, this.stringValue, this.path,
54371
- this.messageFormat);
54609
+ this.messageFormat, this.valueType);
54372
54610
  }
54373
54611
  }
54374
54612
 
@@ -54385,6 +54623,21 @@ function getStringValue(value) {
54385
54623
  return stringValue;
54386
54624
  }
54387
54625
 
54626
+ function getValueType(value) {
54627
+ if (value == null) {
54628
+ return '' + value;
54629
+ }
54630
+
54631
+ const t = typeof value;
54632
+ if (t !== 'object') {
54633
+ return t;
54634
+ }
54635
+ if (typeof value.constructor !== 'function') {
54636
+ return t;
54637
+ }
54638
+ return value.constructor.name;
54639
+ }
54640
+
54388
54641
  function getMessageFormat(schemaType) {
54389
54642
  const messageFormat = get(schemaType, 'options.cast', null);
54390
54643
  if (typeof messageFormat === 'string') {
@@ -54396,7 +54649,7 @@ function getMessageFormat(schemaType) {
54396
54649
  * ignore
54397
54650
  */
54398
54651
 
54399
- function formatMessage(model, kind, stringValue, path, messageFormat) {
54652
+ function formatMessage(model, kind, stringValue, path, messageFormat, valueType) {
54400
54653
  if (messageFormat != null) {
54401
54654
  let ret = messageFormat.
54402
54655
  replace('{KIND}', kind).
@@ -54408,12 +54661,12 @@ function formatMessage(model, kind, stringValue, path, messageFormat) {
54408
54661
 
54409
54662
  return ret;
54410
54663
  } else {
54664
+ const valueTypeMsg = valueType ? ' (type ' + valueType + ')' : '';
54411
54665
  let ret = 'Cast to ' + kind + ' failed for value ' +
54412
- stringValue + ' at path "' + path + '"';
54666
+ stringValue + valueTypeMsg + ' at path "' + path + '"';
54413
54667
  if (model != null) {
54414
54668
  ret += ' for model "' + model.modelName + '"';
54415
54669
  }
54416
-
54417
54670
  return ret;
54418
54671
  }
54419
54672
  }
@@ -54424,7 +54677,7 @@ function formatMessage(model, kind, stringValue, path, messageFormat) {
54424
54677
 
54425
54678
  module.exports = CastError;
54426
54679
 
54427
- },{"../helpers/get":229,"./mongooseError":207,"util":332}],203:[function(require,module,exports){
54680
+ },{"../helpers/get":230,"./mongooseError":207,"util":334}],203:[function(require,module,exports){
54428
54681
 
54429
54682
  /*!
54430
54683
  * Module dependencies.
@@ -54812,7 +55065,7 @@ Object.defineProperty(DocumentNotFoundError.prototype, 'name', {
54812
55065
 
54813
55066
  module.exports = DocumentNotFoundError;
54814
55067
 
54815
- },{"./":204,"util":332}],209:[function(require,module,exports){
55068
+ },{"./":204,"util":334}],209:[function(require,module,exports){
54816
55069
  /*!
54817
55070
  * Module dependencies.
54818
55071
  */
@@ -55014,6 +55267,7 @@ module.exports = StrictModeError;
55014
55267
  'use strict';
55015
55268
 
55016
55269
  const MongooseError = require('./mongooseError');
55270
+ const getConstructorName = require('../helpers/getConstructorName');
55017
55271
  const util = require('util');
55018
55272
 
55019
55273
  class ValidationError extends MongooseError {
@@ -55026,7 +55280,7 @@ class ValidationError extends MongooseError {
55026
55280
  */
55027
55281
  constructor(instance) {
55028
55282
  let _message;
55029
- if (instance && instance.constructor.name === 'model') {
55283
+ if (getConstructorName(instance) === 'model') {
55030
55284
  _message = instance.constructor.modelName + ' validation failed';
55031
55285
  } else {
55032
55286
  _message = 'Validation failed';
@@ -55119,7 +55373,7 @@ function _generateMessage(err) {
55119
55373
 
55120
55374
  module.exports = ValidationError;
55121
55375
 
55122
- },{"./mongooseError":207,"util":332}],216:[function(require,module,exports){
55376
+ },{"../helpers/getConstructorName":231,"./mongooseError":207,"util":334}],216:[function(require,module,exports){
55123
55377
  /*!
55124
55378
  * Module dependencies.
55125
55379
  */
@@ -55265,6 +55519,9 @@ function arrayDepth(arr) {
55265
55519
  if (arr.length === 0) {
55266
55520
  return { min: 1, max: 1, containsNonArrayItem: false };
55267
55521
  }
55522
+ if (arr.length === 1 && !Array.isArray(arr[0])) {
55523
+ return { min: 1, max: 1, containsNonArrayItem: false };
55524
+ }
55268
55525
 
55269
55526
  const res = arrayDepth(arr[0]);
55270
55527
 
@@ -55428,7 +55685,7 @@ function cloneArray(arr, options) {
55428
55685
 
55429
55686
  return ret;
55430
55687
  }
55431
- },{"../types/decimal128":300,"../types/objectid":305,"../utils":307,"./getFunctionName":230,"./isBsonType":232,"./isMongooseObject":233,"./isObject":234,"./specialProperties":251,"./symbols":252,"regexp-clone":326}],220:[function(require,module,exports){
55688
+ },{"../types/decimal128":302,"../types/objectid":307,"../utils":309,"./getFunctionName":232,"./isBsonType":234,"./isMongooseObject":235,"./isObject":236,"./specialProperties":253,"./symbols":254,"regexp-clone":328}],220:[function(require,module,exports){
55432
55689
  (function (Buffer){(function (){
55433
55690
  'use strict';
55434
55691
 
@@ -55538,7 +55795,24 @@ function shouldFlatten(val) {
55538
55795
  }
55539
55796
 
55540
55797
  }).call(this)}).call(this,require("buffer").Buffer)
55541
- },{"../driver":196,"../types/decimal128":300,"../types/objectid":305,"./isMongooseObject":233,"buffer":129}],221:[function(require,module,exports){
55798
+ },{"../driver":196,"../types/decimal128":302,"../types/objectid":307,"./isMongooseObject":235,"buffer":129}],221:[function(require,module,exports){
55799
+ 'use strict';
55800
+
55801
+ const ObjectId = require('../../types/objectid');
55802
+
55803
+ module.exports = function areDiscriminatorValuesEqual(a, b) {
55804
+ if (typeof a === 'string' && typeof b === 'string') {
55805
+ return a === b;
55806
+ }
55807
+ if (typeof a === 'number' && typeof b === 'number') {
55808
+ return a === b;
55809
+ }
55810
+ if (a instanceof ObjectId && b instanceof ObjectId) {
55811
+ return a.toString() === b.toString();
55812
+ }
55813
+ return false;
55814
+ };
55815
+ },{"../../types/objectid":307}],222:[function(require,module,exports){
55542
55816
  'use strict';
55543
55817
 
55544
55818
  module.exports = function checkEmbeddedDiscriminatorKeyProjection(userProjection, path, schema, selected, addedPaths) {
@@ -55551,7 +55825,7 @@ module.exports = function checkEmbeddedDiscriminatorKeyProjection(userProjection
55551
55825
  selected.splice(selected.indexOf(_discriminatorKey), 1);
55552
55826
  }
55553
55827
  };
55554
- },{}],222:[function(require,module,exports){
55828
+ },{}],223:[function(require,module,exports){
55555
55829
  'use strict';
55556
55830
 
55557
55831
  const getDiscriminatorByValue = require('./getDiscriminatorByValue');
@@ -55568,7 +55842,7 @@ module.exports = function getConstructor(Constructor, value) {
55568
55842
  if (Constructor.discriminators[value[discriminatorKey]]) {
55569
55843
  Constructor = Constructor.discriminators[value[discriminatorKey]];
55570
55844
  } else {
55571
- const constructorByValue = getDiscriminatorByValue(Constructor, value[discriminatorKey]);
55845
+ const constructorByValue = getDiscriminatorByValue(Constructor.discriminators, value[discriminatorKey]);
55572
55846
  if (constructorByValue) {
55573
55847
  Constructor = constructorByValue;
55574
55848
  }
@@ -55577,9 +55851,11 @@ module.exports = function getConstructor(Constructor, value) {
55577
55851
 
55578
55852
  return Constructor;
55579
55853
  };
55580
- },{"./getDiscriminatorByValue":223}],223:[function(require,module,exports){
55854
+ },{"./getDiscriminatorByValue":224}],224:[function(require,module,exports){
55581
55855
  'use strict';
55582
55856
 
55857
+ const areDiscriminatorValuesEqual = require('./areDiscriminatorValuesEqual');
55858
+
55583
55859
  /*!
55584
55860
  * returns discriminator by discriminatorMapping.value
55585
55861
  *
@@ -55587,27 +55863,27 @@ module.exports = function getConstructor(Constructor, value) {
55587
55863
  * @param {string} value
55588
55864
  */
55589
55865
 
55590
- module.exports = function getDiscriminatorByValue(model, value) {
55591
- let discriminator = null;
55592
- if (!model.discriminators) {
55593
- return discriminator;
55866
+ module.exports = function getDiscriminatorByValue(discriminators, value) {
55867
+ if (discriminators == null) {
55868
+ return null;
55594
55869
  }
55595
- for (const name in model.discriminators) {
55596
- const it = model.discriminators[name];
55870
+ for (const name of Object.keys(discriminators)) {
55871
+ const it = discriminators[name];
55597
55872
  if (
55598
55873
  it.schema &&
55599
55874
  it.schema.discriminatorMapping &&
55600
- it.schema.discriminatorMapping.value == value
55875
+ areDiscriminatorValuesEqual(it.schema.discriminatorMapping.value, value)
55601
55876
  ) {
55602
- discriminator = it;
55603
- break;
55877
+ return it;
55604
55878
  }
55605
55879
  }
55606
- return discriminator;
55880
+ return null;
55607
55881
  };
55608
- },{}],224:[function(require,module,exports){
55882
+ },{"./areDiscriminatorValuesEqual":221}],225:[function(require,module,exports){
55609
55883
  'use strict';
55610
55884
 
55885
+ const areDiscriminatorValuesEqual = require('./areDiscriminatorValuesEqual');
55886
+
55611
55887
  /*!
55612
55888
  * returns discriminator by discriminatorMapping.value
55613
55889
  *
@@ -55624,13 +55900,13 @@ module.exports = function getSchemaDiscriminatorByValue(schema, value) {
55624
55900
  if (discriminatorSchema.discriminatorMapping == null) {
55625
55901
  continue;
55626
55902
  }
55627
- if (discriminatorSchema.discriminatorMapping.value === value) {
55903
+ if (areDiscriminatorValuesEqual(discriminatorSchema.discriminatorMapping.value, value)) {
55628
55904
  return discriminatorSchema;
55629
55905
  }
55630
55906
  }
55631
55907
  return null;
55632
55908
  };
55633
- },{}],225:[function(require,module,exports){
55909
+ },{"./areDiscriminatorValuesEqual":221}],226:[function(require,module,exports){
55634
55910
  'use strict';
55635
55911
 
55636
55912
  /*!
@@ -55647,7 +55923,7 @@ module.exports = function cleanModifiedSubpaths(doc, path, options) {
55647
55923
  }
55648
55924
  for (const modifiedPath of Object.keys(doc.$__.activePaths.states.modify)) {
55649
55925
  if (skipDocArrays) {
55650
- const schemaType = doc.schema.path(modifiedPath);
55926
+ const schemaType = doc.$__schema.path(modifiedPath);
55651
55927
  if (schemaType && schemaType.$isMongooseDocumentArray) {
55652
55928
  continue;
55653
55929
  }
@@ -55660,7 +55936,7 @@ module.exports = function cleanModifiedSubpaths(doc, path, options) {
55660
55936
  return deleted;
55661
55937
  };
55662
55938
 
55663
- },{}],226:[function(require,module,exports){
55939
+ },{}],227:[function(require,module,exports){
55664
55940
  'use strict';
55665
55941
 
55666
55942
  const documentSchemaSymbol = require('../../helpers/symbols').documentSchemaSymbol;
@@ -55737,6 +56013,13 @@ function defineKey(prop, subprops, prototype, prefix, keys, options) {
55737
56013
  value: prototype.schema
55738
56014
  });
55739
56015
 
56016
+ Object.defineProperty(nested, '$__schema', {
56017
+ enumerable: false,
56018
+ configurable: true,
56019
+ writable: false,
56020
+ value: prototype.schema
56021
+ });
56022
+
55740
56023
  Object.defineProperty(nested, documentSchemaSymbol, {
55741
56024
  enumerable: false,
55742
56025
  configurable: true,
@@ -55844,13 +56127,7 @@ function getOwnPropertyDescriptors(object) {
55844
56127
  const result = {};
55845
56128
 
55846
56129
  Object.getOwnPropertyNames(object).forEach(function(key) {
55847
- result[key] = Object.getOwnPropertyDescriptor(object, key);
55848
- // Assume these are schema paths, ignore them re: #5470
55849
- if (result[key].get) {
55850
- delete result[key];
55851
- return;
55852
- }
55853
- result[key].enumerable = [
56130
+ const skip = [
55854
56131
  'isNew',
55855
56132
  '$__',
55856
56133
  'errors',
@@ -55861,12 +56138,18 @@ function getOwnPropertyDescriptors(object) {
55861
56138
  '__index',
55862
56139
  '$isDocumentArrayElement'
55863
56140
  ].indexOf(key) === -1;
56141
+ if (skip) {
56142
+ return;
56143
+ }
56144
+
56145
+ result[key] = Object.getOwnPropertyDescriptor(object, key);
56146
+ result[key].enumerable = false;
55864
56147
  });
55865
56148
 
55866
56149
  return result;
55867
56150
  }
55868
56151
 
55869
- },{"../../document":194,"../../helpers/get":229,"../../helpers/symbols":252,"../../options":257,"../../utils":307}],227:[function(require,module,exports){
56152
+ },{"../../document":194,"../../helpers/get":230,"../../helpers/symbols":254,"../../options":259,"../../utils":309}],228:[function(require,module,exports){
55870
56153
  'use strict';
55871
56154
 
55872
56155
  const get = require('../get');
@@ -55911,7 +56194,7 @@ module.exports = function getEmbeddedDiscriminatorPath(doc, path, options) {
55911
56194
  return typeOnly ? type : schema;
55912
56195
  };
55913
56196
 
55914
- },{"../get":229}],228:[function(require,module,exports){
56197
+ },{"../get":230}],229:[function(require,module,exports){
55915
56198
  'use strict';
55916
56199
 
55917
56200
  const utils = require('../../utils');
@@ -55929,7 +56212,7 @@ module.exports = function handleSpreadDoc(v) {
55929
56212
 
55930
56213
  return v;
55931
56214
  };
55932
- },{"../../utils":307}],229:[function(require,module,exports){
56215
+ },{"../../utils":309}],230:[function(require,module,exports){
55933
56216
  'use strict';
55934
56217
 
55935
56218
  /*!
@@ -55938,7 +56221,30 @@ module.exports = function handleSpreadDoc(v) {
55938
56221
  */
55939
56222
 
55940
56223
  module.exports = function get(obj, path, def) {
55941
- const parts = path.split('.');
56224
+ let parts;
56225
+ let isPathArray = false;
56226
+ if (typeof path === 'string') {
56227
+ if (path.indexOf('.') === -1) {
56228
+ const _v = getProperty(obj, path);
56229
+ if (_v == null) {
56230
+ return def;
56231
+ }
56232
+ return _v;
56233
+ }
56234
+
56235
+ parts = path.split('.');
56236
+ } else {
56237
+ isPathArray = true;
56238
+ parts = path;
56239
+
56240
+ if (parts.length === 1) {
56241
+ const _v = getProperty(obj, parts[0]);
56242
+ if (_v == null) {
56243
+ return def;
56244
+ }
56245
+ return _v;
56246
+ }
56247
+ }
55942
56248
  let rest = path;
55943
56249
  let cur = obj;
55944
56250
  for (const part of parts) {
@@ -55948,13 +56254,15 @@ module.exports = function get(obj, path, def) {
55948
56254
 
55949
56255
  // `lib/cast.js` depends on being able to get dotted paths in updates,
55950
56256
  // like `{ $set: { 'a.b': 42 } }`
55951
- if (cur[rest] != null) {
56257
+ if (!isPathArray && cur[rest] != null) {
55952
56258
  return cur[rest];
55953
56259
  }
55954
56260
 
55955
56261
  cur = getProperty(cur, part);
55956
56262
 
55957
- rest = rest.substr(part.length + 1);
56263
+ if (!isPathArray) {
56264
+ rest = rest.substr(part.length + 1);
56265
+ }
55958
56266
  }
55959
56267
 
55960
56268
  return cur == null ? def : cur;
@@ -55969,7 +56277,23 @@ function getProperty(obj, prop) {
55969
56277
  }
55970
56278
  return obj[prop];
55971
56279
  }
55972
- },{}],230:[function(require,module,exports){
56280
+ },{}],231:[function(require,module,exports){
56281
+ 'use strict';
56282
+
56283
+ /*!
56284
+ * If `val` is an object, returns constructor name, if possible. Otherwise returns undefined.
56285
+ */
56286
+
56287
+ module.exports = function getConstructorName(val) {
56288
+ if (val == null) {
56289
+ return void 0;
56290
+ }
56291
+ if (typeof val.constructor !== 'function') {
56292
+ return void 0;
56293
+ }
56294
+ return val.constructor.name;
56295
+ };
56296
+ },{}],232:[function(require,module,exports){
55973
56297
  'use strict';
55974
56298
 
55975
56299
  module.exports = function(fn) {
@@ -55979,7 +56303,7 @@ module.exports = function(fn) {
55979
56303
  return (fn.toString().trim().match(/^function\s*([^\s(]+)/) || [])[1];
55980
56304
  };
55981
56305
 
55982
- },{}],231:[function(require,module,exports){
56306
+ },{}],233:[function(require,module,exports){
55983
56307
  (function (process){(function (){
55984
56308
  /*!
55985
56309
  * Centralize this so we can more easily work around issues with people
@@ -55990,12 +56314,14 @@ module.exports = function(fn) {
55990
56314
 
55991
56315
  'use strict';
55992
56316
 
56317
+ const nextTick = process.nextTick.bind(process);
56318
+
55993
56319
  module.exports = function immediate(cb) {
55994
- return process.nextTick(cb);
56320
+ return nextTick(cb);
55995
56321
  };
55996
56322
 
55997
56323
  }).call(this)}).call(this,require('_process'))
55998
- },{"_process":325}],232:[function(require,module,exports){
56324
+ },{"_process":327}],234:[function(require,module,exports){
55999
56325
  'use strict';
56000
56326
 
56001
56327
  const get = require('./get');
@@ -56010,7 +56336,7 @@ function isBsonType(obj, typename) {
56010
56336
 
56011
56337
  module.exports = isBsonType;
56012
56338
 
56013
- },{"./get":229}],233:[function(require,module,exports){
56339
+ },{"./get":230}],235:[function(require,module,exports){
56014
56340
  'use strict';
56015
56341
 
56016
56342
  /*!
@@ -56032,7 +56358,7 @@ module.exports = function(v) {
56032
56358
  v.isMongooseBuffer || // Buffer
56033
56359
  v.$isMongooseMap; // Map
56034
56360
  };
56035
- },{}],234:[function(require,module,exports){
56361
+ },{}],236:[function(require,module,exports){
56036
56362
  (function (Buffer){(function (){
56037
56363
  'use strict';
56038
56364
 
@@ -56051,14 +56377,14 @@ module.exports = function(arg) {
56051
56377
  return Object.prototype.toString.call(arg) === '[object Object]';
56052
56378
  };
56053
56379
  }).call(this)}).call(this,{"isBuffer":require("../../../is-buffer/index.js")})
56054
- },{"../../../is-buffer/index.js":179}],235:[function(require,module,exports){
56380
+ },{"../../../is-buffer/index.js":179}],237:[function(require,module,exports){
56055
56381
  'use strict';
56056
56382
  function isPromise(val) {
56057
56383
  return !!val && (typeof val === 'object' || typeof val === 'function') && typeof val.then === 'function';
56058
56384
  }
56059
56385
 
56060
56386
  module.exports = isPromise;
56061
- },{}],236:[function(require,module,exports){
56387
+ },{}],238:[function(require,module,exports){
56062
56388
  'use strict';
56063
56389
 
56064
56390
  const symbols = require('../../schema/symbols');
@@ -56197,7 +56523,7 @@ function applyHooks(model, schema, options) {
56197
56523
  createWrapper(method, originalMethod, null, customMethodOptions);
56198
56524
  }
56199
56525
  }
56200
- },{"../../schema/symbols":294,"../promiseOrCallback":241}],237:[function(require,module,exports){
56526
+ },{"../../schema/symbols":296,"../promiseOrCallback":243}],239:[function(require,module,exports){
56201
56527
  'use strict';
56202
56528
 
56203
56529
  const Mixed = require('../../schema/mixed');
@@ -56263,7 +56589,7 @@ module.exports = function discriminator(model, name, schema, tiedValue, applyPlu
56263
56589
  }
56264
56590
 
56265
56591
  let value = name;
56266
- if (typeof tiedValue == 'string' && tiedValue.length) {
56592
+ if ((typeof tiedValue === 'string' && tiedValue.length) || tiedValue != null) {
56267
56593
  value = tiedValue;
56268
56594
  }
56269
56595
 
@@ -56326,17 +56652,17 @@ module.exports = function discriminator(model, name, schema, tiedValue, applyPlu
56326
56652
  default: value,
56327
56653
  select: true,
56328
56654
  set: function(newName) {
56329
- if (newName === value) {
56655
+ if (newName === value || (Array.isArray(value) && utils.deepEqual(newName, value))) {
56330
56656
  return value;
56331
56657
  }
56332
56658
  throw new Error('Can\'t set discriminator key "' + key + '"');
56333
56659
  },
56334
56660
  $skipDiscriminatorCheck: true
56335
56661
  };
56336
- obj[key][schema.options.typeKey] = existingPath ?
56337
- existingPath.instance :
56338
- String;
56662
+ obj[key][schema.options.typeKey] = existingPath ? existingPath.options[schema.options.typeKey] : String;
56339
56663
  schema.add(obj);
56664
+
56665
+
56340
56666
  schema.discriminatorMapping = { key: key, value: value, isRoot: false };
56341
56667
 
56342
56668
  if (baseSchema.options.collection) {
@@ -56404,7 +56730,7 @@ module.exports = function discriminator(model, name, schema, tiedValue, applyPlu
56404
56730
  return schema;
56405
56731
  };
56406
56732
 
56407
- },{"../../schema/mixed":284,"../../utils":307,"../document/compile":226,"../get":229}],238:[function(require,module,exports){
56733
+ },{"../../schema/mixed":286,"../../utils":309,"../document/compile":227,"../get":230}],240:[function(require,module,exports){
56408
56734
  'use strict';
56409
56735
 
56410
56736
  const MongooseError = require('../../error/mongooseError');
@@ -56424,7 +56750,7 @@ function validateRef(ref, path) {
56424
56750
  throw new MongooseError('Invalid ref at path "' + path + '". Got ' +
56425
56751
  util.inspect(ref, { depth: 0 }));
56426
56752
  }
56427
- },{"../../error/mongooseError":207,"util":332}],239:[function(require,module,exports){
56753
+ },{"../../error/mongooseError":207,"util":334}],241:[function(require,module,exports){
56428
56754
  'use strict';
56429
56755
 
56430
56756
  /*!
@@ -56444,7 +56770,7 @@ module.exports = function isDefiningProjection(val) {
56444
56770
  return true;
56445
56771
  };
56446
56772
 
56447
- },{}],240:[function(require,module,exports){
56773
+ },{}],242:[function(require,module,exports){
56448
56774
  'use strict';
56449
56775
 
56450
56776
  const isDefiningProjection = require('./isDefiningProjection');
@@ -56454,6 +56780,10 @@ const isDefiningProjection = require('./isDefiningProjection');
56454
56780
  */
56455
56781
 
56456
56782
  module.exports = function isExclusive(projection) {
56783
+ if (projection == null) {
56784
+ return null;
56785
+ }
56786
+
56457
56787
  const keys = Object.keys(projection);
56458
56788
  let ki = keys.length;
56459
56789
  let exclude = null;
@@ -56474,26 +56804,26 @@ module.exports = function isExclusive(projection) {
56474
56804
  return exclude;
56475
56805
  };
56476
56806
 
56477
- },{"./isDefiningProjection":239}],241:[function(require,module,exports){
56478
- (function (process){(function (){
56807
+ },{"./isDefiningProjection":241}],243:[function(require,module,exports){
56479
56808
  'use strict';
56480
56809
 
56481
56810
  const PromiseProvider = require('../promise_provider');
56811
+ const immediate = require('./immediate');
56482
56812
 
56483
- const emittedSymbol = Symbol.for('mongoose:emitted');
56813
+ const emittedSymbol = Symbol('mongoose:emitted');
56484
56814
 
56485
56815
  module.exports = function promiseOrCallback(callback, fn, ee, Promise) {
56486
56816
  if (typeof callback === 'function') {
56487
56817
  return fn(function(error) {
56488
56818
  if (error != null) {
56489
- if (ee != null && ee.listeners('error').length > 0 && !error[emittedSymbol]) {
56819
+ if (ee != null && ee.listeners != null && ee.listeners('error').length > 0 && !error[emittedSymbol]) {
56490
56820
  error[emittedSymbol] = true;
56491
56821
  ee.emit('error', error);
56492
56822
  }
56493
56823
  try {
56494
56824
  callback(error);
56495
56825
  } catch (error) {
56496
- return process.nextTick(() => {
56826
+ return immediate(() => {
56497
56827
  throw error;
56498
56828
  });
56499
56829
  }
@@ -56508,7 +56838,7 @@ module.exports = function promiseOrCallback(callback, fn, ee, Promise) {
56508
56838
  return new Promise((resolve, reject) => {
56509
56839
  fn(function(error, res) {
56510
56840
  if (error != null) {
56511
- if (ee != null && ee.listeners('error').length > 0 && !error[emittedSymbol]) {
56841
+ if (ee != null && ee.listeners != null && ee.listeners('error').length > 0 && !error[emittedSymbol]) {
56512
56842
  error[emittedSymbol] = true;
56513
56843
  ee.emit('error', error);
56514
56844
  }
@@ -56521,8 +56851,8 @@ module.exports = function promiseOrCallback(callback, fn, ee, Promise) {
56521
56851
  });
56522
56852
  });
56523
56853
  };
56524
- }).call(this)}).call(this,require('_process'))
56525
- },{"../promise_provider":272,"_process":325}],242:[function(require,module,exports){
56854
+
56855
+ },{"../promise_provider":274,"./immediate":233}],244:[function(require,module,exports){
56526
56856
  'use strict';
56527
56857
 
56528
56858
  /*!
@@ -56616,7 +56946,7 @@ function _getContexts(hook) {
56616
56946
  }
56617
56947
  return ret;
56618
56948
  }
56619
- },{}],243:[function(require,module,exports){
56949
+ },{}],245:[function(require,module,exports){
56620
56950
  'use strict';
56621
56951
 
56622
56952
  const specialKeys = new Set([
@@ -56628,7 +56958,7 @@ const specialKeys = new Set([
56628
56958
  module.exports = function isOperator(path) {
56629
56959
  return path.startsWith('$') && !specialKeys.has(path);
56630
56960
  };
56631
- },{}],244:[function(require,module,exports){
56961
+ },{}],246:[function(require,module,exports){
56632
56962
  'use strict';
56633
56963
 
56634
56964
  module.exports = function addAutoId(schema) {
@@ -56636,7 +56966,7 @@ module.exports = function addAutoId(schema) {
56636
56966
  _obj._id[schema.options.typeKey] = 'ObjectId';
56637
56967
  schema.add(_obj);
56638
56968
  };
56639
- },{}],245:[function(require,module,exports){
56969
+ },{}],247:[function(require,module,exports){
56640
56970
  'use strict';
56641
56971
 
56642
56972
  /**
@@ -56649,7 +56979,7 @@ module.exports = function cleanPositionalOperators(path) {
56649
56979
  replace(/\.\$(\[[^\]]*\])?(?=\.)/g, '.0').
56650
56980
  replace(/\.\$(\[[^\]]*\])?$/g, '.0');
56651
56981
  };
56652
- },{}],246:[function(require,module,exports){
56982
+ },{}],248:[function(require,module,exports){
56653
56983
  'use strict';
56654
56984
 
56655
56985
  const get = require('../get');
@@ -56806,7 +57136,7 @@ module.exports = function getIndexes(schema) {
56806
57136
  }
56807
57137
  };
56808
57138
 
56809
- },{"../get":229,"../isObject":234}],247:[function(require,module,exports){
57139
+ },{"../get":230,"../isObject":236}],249:[function(require,module,exports){
56810
57140
  'use strict';
56811
57141
 
56812
57142
  const addAutoId = require('./addAutoId');
@@ -56827,7 +57157,7 @@ module.exports = function handleIdOption(schema, options) {
56827
57157
 
56828
57158
  return schema;
56829
57159
  };
56830
- },{"./addAutoId":244}],248:[function(require,module,exports){
57160
+ },{"./addAutoId":246}],250:[function(require,module,exports){
56831
57161
  'use strict';
56832
57162
 
56833
57163
  module.exports = handleTimestampOption;
@@ -56852,11 +57182,19 @@ function handleTimestampOption(arg, prop) {
56852
57182
  }
56853
57183
  return arg[prop];
56854
57184
  }
56855
- },{}],249:[function(require,module,exports){
57185
+ },{}],251:[function(require,module,exports){
56856
57186
  'use strict';
56857
57187
 
56858
- module.exports = function merge(s1, s2) {
56859
- s1.add(s2.tree || {});
57188
+ module.exports = function merge(s1, s2, skipConflictingPaths) {
57189
+ const paths = Object.keys(s2.tree);
57190
+ const pathsToAdd = {};
57191
+ for (const key of paths) {
57192
+ if (skipConflictingPaths && (s1.paths[key] || s1.nested[key] || s1.singleNestedPaths[key])) {
57193
+ continue;
57194
+ }
57195
+ pathsToAdd[key] = s2.tree[key];
57196
+ }
57197
+ s1.add(pathsToAdd);
56860
57198
 
56861
57199
  s1.callQueue = s1.callQueue.concat(s2.callQueue);
56862
57200
  s1.method(s2.methods);
@@ -56873,7 +57211,7 @@ module.exports = function merge(s1, s2) {
56873
57211
  s1.s.hooks.merge(s2.s.hooks, false);
56874
57212
  };
56875
57213
 
56876
- },{}],250:[function(require,module,exports){
57214
+ },{}],252:[function(require,module,exports){
56877
57215
  'use strict';
56878
57216
 
56879
57217
  const StrictModeError = require('../../error/strict');
@@ -56920,11 +57258,11 @@ function createImmutableSetter(path, immutable) {
56920
57258
  };
56921
57259
  }
56922
57260
 
56923
- },{"../../error/strict":214}],251:[function(require,module,exports){
57261
+ },{"../../error/strict":214}],253:[function(require,module,exports){
56924
57262
  'use strict';
56925
57263
 
56926
57264
  module.exports = new Set(['__proto__', 'constructor', 'prototype']);
56927
- },{}],252:[function(require,module,exports){
57265
+ },{}],254:[function(require,module,exports){
56928
57266
  'use strict';
56929
57267
 
56930
57268
  exports.arrayAtomicsSymbol = Symbol('mongoose#Array#_atomics');
@@ -56944,7 +57282,7 @@ exports.schemaTypeSymbol = Symbol('mongoose#schemaType');
56944
57282
  exports.sessionNewDocuments = Symbol('mongoose:ClientSession#newDocuments');
56945
57283
  exports.scopeSymbol = Symbol('mongoose#Document#scope');
56946
57284
  exports.validatorErrorSymbol = Symbol('mongoose:validatorError');
56947
- },{}],253:[function(require,module,exports){
57285
+ },{}],255:[function(require,module,exports){
56948
57286
  'use strict';
56949
57287
 
56950
57288
  const applyTimestampsToChildren = require('../update/applyTimestampsToChildren');
@@ -56998,7 +57336,7 @@ module.exports = function setupTimestamps(schema, timestamps) {
56998
57336
  (this.ownerDocument ? this.ownerDocument() : this).constructor.base.now();
56999
57337
  const auto_id = this._id && this._id.auto;
57000
57338
 
57001
- if (!skipCreatedAt && createdAt && !this.get(createdAt) && this.$__isSelected(createdAt)) {
57339
+ if (!skipCreatedAt && this.isNew && createdAt && !this.get(createdAt) && this.$__isSelected(createdAt)) {
57002
57340
  this.$set(createdAt, auto_id ? this._id.getTimestamp() : defaultTimestamp);
57003
57341
  }
57004
57342
 
@@ -57056,7 +57394,7 @@ module.exports = function setupTimestamps(schema, timestamps) {
57056
57394
  next();
57057
57395
  }
57058
57396
  };
57059
- },{"../../schema/symbols":294,"../get":229,"../schema/handleTimestampOption":248,"../update/applyTimestampsToChildren":254,"../update/applyTimestampsToUpdate":255}],254:[function(require,module,exports){
57397
+ },{"../../schema/symbols":296,"../get":230,"../schema/handleTimestampOption":250,"../update/applyTimestampsToChildren":256,"../update/applyTimestampsToUpdate":257}],256:[function(require,module,exports){
57060
57398
  'use strict';
57061
57399
 
57062
57400
  const cleanPositionalOperators = require('../schema/cleanPositionalOperators');
@@ -57078,34 +57416,10 @@ function applyTimestampsToChildren(now, update, schema) {
57078
57416
 
57079
57417
  if (hasDollarKey) {
57080
57418
  if (update.$push) {
57081
- for (const key of Object.keys(update.$push)) {
57082
- const $path = schema.path(key);
57083
- if (update.$push[key] &&
57084
- $path &&
57085
- $path.$isMongooseDocumentArray &&
57086
- $path.schema.options.timestamps) {
57087
- const timestamps = $path.schema.options.timestamps;
57088
- const createdAt = handleTimestampOption(timestamps, 'createdAt');
57089
- const updatedAt = handleTimestampOption(timestamps, 'updatedAt');
57090
- if (update.$push[key].$each) {
57091
- update.$push[key].$each.forEach(function(subdoc) {
57092
- if (updatedAt != null) {
57093
- subdoc[updatedAt] = now;
57094
- }
57095
- if (createdAt != null) {
57096
- subdoc[createdAt] = now;
57097
- }
57098
- });
57099
- } else {
57100
- if (updatedAt != null) {
57101
- update.$push[key][updatedAt] = now;
57102
- }
57103
- if (createdAt != null) {
57104
- update.$push[key][createdAt] = now;
57105
- }
57106
- }
57107
- }
57108
- }
57419
+ _applyTimestampToUpdateOperator(update.$push);
57420
+ }
57421
+ if (update.$addToSet) {
57422
+ _applyTimestampToUpdateOperator(update.$addToSet);
57109
57423
  }
57110
57424
  if (update.$set != null) {
57111
57425
  const keys = Object.keys(update.$set);
@@ -57113,12 +57427,49 @@ function applyTimestampsToChildren(now, update, schema) {
57113
57427
  applyTimestampsToUpdateKey(schema, key, update.$set, now);
57114
57428
  }
57115
57429
  }
57430
+ if (update.$setOnInsert != null) {
57431
+ const keys = Object.keys(update.$setOnInsert);
57432
+ for (const key of keys) {
57433
+ applyTimestampsToUpdateKey(schema, key, update.$setOnInsert, now);
57434
+ }
57435
+ }
57116
57436
  }
57117
57437
 
57118
57438
  const updateKeys = Object.keys(update).filter(key => !key.startsWith('$'));
57119
57439
  for (const key of updateKeys) {
57120
57440
  applyTimestampsToUpdateKey(schema, key, update, now);
57121
57441
  }
57442
+
57443
+ function _applyTimestampToUpdateOperator(op) {
57444
+ for (const key of Object.keys(op)) {
57445
+ const $path = schema.path(key.replace(/\.\$\./i, '.').replace(/.\$$/, ''));
57446
+ if (op[key] &&
57447
+ $path &&
57448
+ $path.$isMongooseDocumentArray &&
57449
+ $path.schema.options.timestamps) {
57450
+ const timestamps = $path.schema.options.timestamps;
57451
+ const createdAt = handleTimestampOption(timestamps, 'createdAt');
57452
+ const updatedAt = handleTimestampOption(timestamps, 'updatedAt');
57453
+ if (op[key].$each) {
57454
+ op[key].$each.forEach(function(subdoc) {
57455
+ if (updatedAt != null) {
57456
+ subdoc[updatedAt] = now;
57457
+ }
57458
+ if (createdAt != null) {
57459
+ subdoc[createdAt] = now;
57460
+ }
57461
+ });
57462
+ } else {
57463
+ if (updatedAt != null) {
57464
+ op[key][updatedAt] = now;
57465
+ }
57466
+ if (createdAt != null) {
57467
+ op[key][createdAt] = now;
57468
+ }
57469
+ }
57470
+ }
57471
+ }
57472
+ }
57122
57473
  }
57123
57474
 
57124
57475
  function applyTimestampsToDocumentArray(arr, schematype, now) {
@@ -57229,7 +57580,7 @@ function applyTimestampsToUpdateKey(schema, key, update, now) {
57229
57580
  }
57230
57581
  }
57231
57582
  }
57232
- },{"../schema/cleanPositionalOperators":245,"../schema/handleTimestampOption":248}],255:[function(require,module,exports){
57583
+ },{"../schema/cleanPositionalOperators":247,"../schema/handleTimestampOption":250}],257:[function(require,module,exports){
57233
57584
  'use strict';
57234
57585
 
57235
57586
  /*!
@@ -57350,7 +57701,7 @@ function applyTimestampsToUpdate(now, createdAt, updatedAt, currentUpdate, optio
57350
57701
  return updates;
57351
57702
  }
57352
57703
 
57353
- },{"../get":229}],256:[function(require,module,exports){
57704
+ },{"../get":230}],258:[function(require,module,exports){
57354
57705
  /*!
57355
57706
  * Dependencies
57356
57707
  */
@@ -57390,7 +57741,7 @@ function InternalCache() {
57390
57741
  this.fullPath = undefined;
57391
57742
  }
57392
57743
 
57393
- },{"./statemachine":296}],257:[function(require,module,exports){
57744
+ },{"./statemachine":298}],259:[function(require,module,exports){
57394
57745
  'use strict';
57395
57746
 
57396
57747
  /*!
@@ -57403,10 +57754,11 @@ exports.internalToObjectOptions = {
57403
57754
  getters: false,
57404
57755
  _skipDepopulateTopLevel: true,
57405
57756
  depopulate: true,
57406
- flattenDecimals: false
57757
+ flattenDecimals: false,
57758
+ useProjection: false
57407
57759
  };
57408
57760
 
57409
- },{}],258:[function(require,module,exports){
57761
+ },{}],260:[function(require,module,exports){
57410
57762
  'use strict';
57411
57763
 
57412
57764
  const clone = require('../helpers/clone');
@@ -57443,7 +57795,7 @@ class PopulateOptions {
57443
57795
  */
57444
57796
 
57445
57797
  module.exports = PopulateOptions;
57446
- },{"../helpers/clone":219}],259:[function(require,module,exports){
57798
+ },{"../helpers/clone":219}],261:[function(require,module,exports){
57447
57799
  'use strict';
57448
57800
 
57449
57801
  const SchemaTypeOptions = require('./SchemaTypeOptions');
@@ -57496,14 +57848,14 @@ Object.defineProperty(SchemaArrayOptions.prototype, 'enum', opts);
57496
57848
  * @instance
57497
57849
  */
57498
57850
 
57499
- Object.defineProperty(SchemaArrayOptions.prototype, 'enum', opts);
57851
+ Object.defineProperty(SchemaArrayOptions.prototype, 'of', opts);
57500
57852
 
57501
57853
  /*!
57502
57854
  * ignore
57503
57855
  */
57504
57856
 
57505
57857
  module.exports = SchemaArrayOptions;
57506
- },{"./SchemaTypeOptions":268,"./propertyOptions":270}],260:[function(require,module,exports){
57858
+ },{"./SchemaTypeOptions":270,"./propertyOptions":272}],262:[function(require,module,exports){
57507
57859
  'use strict';
57508
57860
 
57509
57861
  const SchemaTypeOptions = require('./SchemaTypeOptions');
@@ -57542,7 +57894,7 @@ Object.defineProperty(SchemaBufferOptions.prototype, 'subtype', opts);
57542
57894
  */
57543
57895
 
57544
57896
  module.exports = SchemaBufferOptions;
57545
- },{"./SchemaTypeOptions":268,"./propertyOptions":270}],261:[function(require,module,exports){
57897
+ },{"./SchemaTypeOptions":270,"./propertyOptions":272}],263:[function(require,module,exports){
57546
57898
  'use strict';
57547
57899
 
57548
57900
  const SchemaTypeOptions = require('./SchemaTypeOptions');
@@ -57607,7 +57959,7 @@ Object.defineProperty(SchemaDateOptions.prototype, 'expires', opts);
57607
57959
  */
57608
57960
 
57609
57961
  module.exports = SchemaDateOptions;
57610
- },{"./SchemaTypeOptions":268,"./propertyOptions":270}],262:[function(require,module,exports){
57962
+ },{"./SchemaTypeOptions":270,"./propertyOptions":272}],264:[function(require,module,exports){
57611
57963
  'use strict';
57612
57964
 
57613
57965
  const SchemaTypeOptions = require('./SchemaTypeOptions');
@@ -57676,7 +58028,7 @@ Object.defineProperty(SchemaDocumentArrayOptions.prototype, '_id', opts);
57676
58028
  */
57677
58029
 
57678
58030
  module.exports = SchemaDocumentArrayOptions;
57679
- },{"./SchemaTypeOptions":268,"./propertyOptions":270}],263:[function(require,module,exports){
58031
+ },{"./SchemaTypeOptions":270,"./propertyOptions":272}],265:[function(require,module,exports){
57680
58032
  'use strict';
57681
58033
 
57682
58034
  const SchemaTypeOptions = require('./SchemaTypeOptions');
@@ -57720,7 +58072,7 @@ const opts = require('./propertyOptions');
57720
58072
  Object.defineProperty(SchemaMapOptions.prototype, 'of', opts);
57721
58073
 
57722
58074
  module.exports = SchemaMapOptions;
57723
- },{"./SchemaTypeOptions":268,"./propertyOptions":270}],264:[function(require,module,exports){
58075
+ },{"./SchemaTypeOptions":270,"./propertyOptions":272}],266:[function(require,module,exports){
57724
58076
  'use strict';
57725
58077
 
57726
58078
  const SchemaTypeOptions = require('./SchemaTypeOptions');
@@ -57820,7 +58172,7 @@ Object.defineProperty(SchemaNumberOptions.prototype, 'populate', opts);
57820
58172
  */
57821
58173
 
57822
58174
  module.exports = SchemaNumberOptions;
57823
- },{"./SchemaTypeOptions":268,"./propertyOptions":270}],265:[function(require,module,exports){
58175
+ },{"./SchemaTypeOptions":270,"./propertyOptions":272}],267:[function(require,module,exports){
57824
58176
  'use strict';
57825
58177
 
57826
58178
  const SchemaTypeOptions = require('./SchemaTypeOptions');
@@ -57884,7 +58236,7 @@ Object.defineProperty(SchemaObjectIdOptions.prototype, 'populate', opts);
57884
58236
  */
57885
58237
 
57886
58238
  module.exports = SchemaObjectIdOptions;
57887
- },{"./SchemaTypeOptions":268,"./propertyOptions":270}],266:[function(require,module,exports){
58239
+ },{"./SchemaTypeOptions":270,"./propertyOptions":272}],268:[function(require,module,exports){
57888
58240
  'use strict';
57889
58241
 
57890
58242
  const SchemaTypeOptions = require('./SchemaTypeOptions');
@@ -57927,7 +58279,7 @@ const opts = require('./propertyOptions');
57927
58279
  Object.defineProperty(SchemaSingleNestedOptions.prototype, '_id', opts);
57928
58280
 
57929
58281
  module.exports = SchemaSingleNestedOptions;
57930
- },{"./SchemaTypeOptions":268,"./propertyOptions":270}],267:[function(require,module,exports){
58282
+ },{"./SchemaTypeOptions":270,"./propertyOptions":272}],269:[function(require,module,exports){
57931
58283
  'use strict';
57932
58284
 
57933
58285
  const SchemaTypeOptions = require('./SchemaTypeOptions');
@@ -58067,7 +58419,7 @@ Object.defineProperty(SchemaStringOptions.prototype, 'populate', opts);
58067
58419
 
58068
58420
  module.exports = SchemaStringOptions;
58069
58421
 
58070
- },{"./SchemaTypeOptions":268,"./propertyOptions":270}],268:[function(require,module,exports){
58422
+ },{"./SchemaTypeOptions":270,"./propertyOptions":272}],270:[function(require,module,exports){
58071
58423
  'use strict';
58072
58424
 
58073
58425
  const clone = require('../helpers/clone');
@@ -58299,7 +58651,7 @@ Object.defineProperty(SchemaTypeOptions.prototype, 'text', opts);
58299
58651
  Object.defineProperty(SchemaTypeOptions.prototype, 'transform', opts);
58300
58652
 
58301
58653
  module.exports = SchemaTypeOptions;
58302
- },{"../helpers/clone":219,"./propertyOptions":270}],269:[function(require,module,exports){
58654
+ },{"../helpers/clone":219,"./propertyOptions":272}],271:[function(require,module,exports){
58303
58655
  'use strict';
58304
58656
 
58305
58657
  const opts = require('./propertyOptions');
@@ -58464,7 +58816,7 @@ Object.defineProperty(VirtualOptions.prototype, 'limit', opts);
58464
58816
  Object.defineProperty(VirtualOptions.prototype, 'perDocumentLimit', opts);
58465
58817
 
58466
58818
  module.exports = VirtualOptions;
58467
- },{"./propertyOptions":270}],270:[function(require,module,exports){
58819
+ },{"./propertyOptions":272}],272:[function(require,module,exports){
58468
58820
  'use strict';
58469
58821
 
58470
58822
  module.exports = Object.freeze({
@@ -58473,7 +58825,7 @@ module.exports = Object.freeze({
58473
58825
  writable: true,
58474
58826
  value: void 0
58475
58827
  });
58476
- },{}],271:[function(require,module,exports){
58828
+ },{}],273:[function(require,module,exports){
58477
58829
  'use strict';
58478
58830
 
58479
58831
  /*!
@@ -58503,7 +58855,7 @@ function idGetter() {
58503
58855
  return null;
58504
58856
  }
58505
58857
 
58506
- },{}],272:[function(require,module,exports){
58858
+ },{}],274:[function(require,module,exports){
58507
58859
  (function (global){(function (){
58508
58860
  /*!
58509
58861
  * ignore
@@ -58556,7 +58908,7 @@ store.set(global.Promise);
58556
58908
  module.exports = store;
58557
58909
 
58558
58910
  }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
58559
- },{"assert":103,"mquery":317}],273:[function(require,module,exports){
58911
+ },{"assert":103,"mquery":319}],275:[function(require,module,exports){
58560
58912
  'use strict';
58561
58913
 
58562
58914
  /*!
@@ -58590,6 +58942,10 @@ exports.preparePopulationOptions = function preparePopulationOptions(query, opti
58590
58942
  forEach(makeLean(options.lean));
58591
58943
  }
58592
58944
 
58945
+ pop.forEach(opts => {
58946
+ opts._localModel = query.model;
58947
+ });
58948
+
58593
58949
  return pop;
58594
58950
  };
58595
58951
 
@@ -58630,6 +58986,9 @@ exports.preparePopulationOptionsMQ = function preparePopulationOptionsMQ(query,
58630
58986
  pop.forEach(p => {
58631
58987
  p._queryProjection = projection;
58632
58988
  });
58989
+ pop.forEach(opts => {
58990
+ opts._localModel = query.model;
58991
+ });
58633
58992
 
58634
58993
  return pop;
58635
58994
  };
@@ -58644,7 +59003,7 @@ exports.preparePopulationOptionsMQ = function preparePopulationOptionsMQ(query,
58644
59003
  *
58645
59004
  * @return {Document}
58646
59005
  */
58647
- exports.createModel = function createModel(model, doc, fields, userProvidedFields) {
59006
+ exports.createModel = function createModel(model, doc, fields, userProvidedFields, options) {
58648
59007
  model.hooks.execPreSync('createModel', doc);
58649
59008
  const discriminatorMapping = model.schema ?
58650
59009
  model.schema.discriminatorMapping :
@@ -58656,18 +59015,22 @@ exports.createModel = function createModel(model, doc, fields, userProvidedField
58656
59015
 
58657
59016
  const value = doc[key];
58658
59017
  if (key && value && model.discriminators) {
58659
- const discriminator = model.discriminators[value] || getDiscriminatorByValue(model, value);
59018
+ const discriminator = model.discriminators[value] || getDiscriminatorByValue(model.discriminators, value);
58660
59019
  if (discriminator) {
58661
59020
  const _fields = clone(userProvidedFields);
58662
59021
  exports.applyPaths(_fields, discriminator.schema);
58663
59022
  return new discriminator(undefined, _fields, true);
58664
59023
  }
58665
59024
  }
58666
-
59025
+ if (typeof options === 'undefined') {
59026
+ options = {};
59027
+ options.defaults = true;
59028
+ }
58667
59029
  return new model(undefined, fields, {
58668
59030
  skipId: true,
58669
59031
  isNew: false,
58670
- willInit: true
59032
+ willInit: true,
59033
+ defaults: options.defaults
58671
59034
  });
58672
59035
  };
58673
59036
 
@@ -58758,7 +59121,11 @@ exports.applyPaths = function applyPaths(fields, schema) {
58758
59121
  schema.eachPath(function(path, type) {
58759
59122
  if (prefix) path = prefix + '.' + path;
58760
59123
 
58761
- const addedPath = analyzePath(path, type);
59124
+ let addedPath = analyzePath(path, type);
59125
+ // arrays
59126
+ if (addedPath == null && type.$isMongooseArray && !type.$isMongooseDocumentArray) {
59127
+ addedPath = analyzePath(path, type.caster);
59128
+ }
58762
59129
  if (addedPath != null) {
58763
59130
  addedPaths.push(addedPath);
58764
59131
  }
@@ -58873,7 +59240,7 @@ exports.handleDeleteWriteOpResult = function handleDeleteWriteOpResult(callback)
58873
59240
  };
58874
59241
  };
58875
59242
 
58876
- },{"./helpers/clone":219,"./helpers/discriminator/checkEmbeddedDiscriminatorKeyProjection":221,"./helpers/discriminator/getDiscriminatorByValue":223,"./helpers/get":229,"./helpers/projection/isDefiningProjection":239}],274:[function(require,module,exports){
59243
+ },{"./helpers/clone":219,"./helpers/discriminator/checkEmbeddedDiscriminatorKeyProjection":222,"./helpers/discriminator/getDiscriminatorByValue":224,"./helpers/get":230,"./helpers/projection/isDefiningProjection":241}],276:[function(require,module,exports){
58877
59244
  (function (Buffer){(function (){
58878
59245
  'use strict';
58879
59246
 
@@ -58891,6 +59258,7 @@ const VirtualType = require('./virtualtype');
58891
59258
  const addAutoId = require('./helpers/schema/addAutoId');
58892
59259
  const arrayParentSymbol = require('./helpers/symbols').arrayParentSymbol;
58893
59260
  const get = require('./helpers/get');
59261
+ const getConstructorName = require('./helpers/getConstructorName');
58894
59262
  const getIndexes = require('./helpers/schema/getIndexes');
58895
59263
  const merge = require('./helpers/schema/merge');
58896
59264
  const mpath = require('mpath');
@@ -58930,6 +59298,7 @@ let id = 0;
58930
59298
  * - [bufferTimeoutMS](/docs/guide.html#bufferTimeoutMS): number - defaults to 10000 (10 seconds). If `bufferCommands` is enabled, the amount of time Mongoose will wait for connectivity to be restablished before erroring out.
58931
59299
  * - [capped](/docs/guide.html#capped): bool - defaults to false
58932
59300
  * - [collection](/docs/guide.html#collection): string - no default
59301
+ * - [discriminatorKey](/docs/guide.html#discriminatorKey): string - defaults to `__t`
58933
59302
  * - [id](/docs/guide.html#id): bool - defaults to true
58934
59303
  * - [_id](/docs/guide.html#_id): bool - defaults to true
58935
59304
  * - [minimize](/docs/guide.html#minimize): bool - controls [document#toObject](#document_Document-toObject) behavior when called manually - defaults to true
@@ -58990,6 +59359,7 @@ function Schema(obj, options) {
58990
59359
  this.plugins = [];
58991
59360
  // For internal debugging. Do not use this to try to save a schema in MDB.
58992
59361
  this.$id = ++id;
59362
+ this.mapPaths = [];
58993
59363
 
58994
59364
  this.s = {
58995
59365
  hooks: new Kareem()
@@ -59196,6 +59566,7 @@ Schema.prototype.clone = function() {
59196
59566
  s.$globalPluginsApplied = this.$globalPluginsApplied;
59197
59567
  s.$isRootDiscriminator = this.$isRootDiscriminator;
59198
59568
  s.$implicitlyCreated = this.$implicitlyCreated;
59569
+ s.mapPaths = [].concat(this.mapPaths);
59199
59570
 
59200
59571
  if (this.discriminatorMapping != null) {
59201
59572
  s.discriminatorMapping = Object.assign({}, this.discriminatorMapping);
@@ -59343,6 +59714,11 @@ Schema.prototype.add = function add(obj, prefix) {
59343
59714
  }
59344
59715
 
59345
59716
  prefix = prefix || '';
59717
+ // avoid prototype pollution
59718
+ if (prefix === '__proto__.' || prefix === 'constructor.' || prefix === 'prototype.') {
59719
+ return this;
59720
+ }
59721
+
59346
59722
  const keys = Object.keys(obj);
59347
59723
 
59348
59724
  for (const key of keys) {
@@ -59468,7 +59844,6 @@ reserved.isNew =
59468
59844
  reserved.populated =
59469
59845
  reserved.remove =
59470
59846
  reserved.save =
59471
- reserved.schema =
59472
59847
  reserved.toObject =
59473
59848
  reserved.validate = 1;
59474
59849
 
@@ -59565,8 +59940,13 @@ Schema.prototype.path = function(path, obj) {
59565
59940
  !utils.hasUserDefinedProperty(obj.of, this.options.typeKey);
59566
59941
  _mapType = isInlineSchema ? new Schema(obj.of) : obj.of;
59567
59942
  }
59943
+ if (utils.hasUserDefinedProperty(obj, 'ref')) {
59944
+ _mapType = { type: _mapType, ref: obj.ref };
59945
+ }
59946
+
59568
59947
  this.paths[mapPath] = this.interpretAsType(mapPath,
59569
59948
  _mapType, this.options);
59949
+ this.mapPaths.push(this.paths[mapPath]);
59570
59950
  schemaType.$__schemaType = this.paths[mapPath];
59571
59951
  }
59572
59952
 
@@ -59643,19 +60023,25 @@ Schema.prototype.path = function(path, obj) {
59643
60023
 
59644
60024
  if (schemaType.$isMongooseDocumentArray) {
59645
60025
  for (const key of Object.keys(schemaType.schema.paths)) {
59646
- this.subpaths[path + '.' + key] = schemaType.schema.paths[key];
59647
- schemaType.schema.paths[key].$isUnderneathDocArray = true;
60026
+ const _schemaType = schemaType.schema.paths[key];
60027
+ this.subpaths[path + '.' + key] = _schemaType;
60028
+ if (typeof _schemaType === 'object' && _schemaType != null) {
60029
+ _schemaType.$isUnderneathDocArray = true;
60030
+ }
59648
60031
  }
59649
60032
  for (const key of Object.keys(schemaType.schema.subpaths)) {
59650
- this.subpaths[path + '.' + key] = schemaType.schema.subpaths[key];
59651
- schemaType.schema.subpaths[key].$isUnderneathDocArray = true;
60033
+ const _schemaType = schemaType.schema.subpaths[key];
60034
+ this.subpaths[path + '.' + key] = _schemaType;
60035
+ if (typeof _schemaType === 'object' && _schemaType != null) {
60036
+ _schemaType.$isUnderneathDocArray = true;
60037
+ }
59652
60038
  }
59653
60039
  for (const key of Object.keys(schemaType.schema.singleNestedPaths)) {
59654
- if (typeof schemaType.schema.singleNestedPaths[cleanPath] !== 'object') {
59655
- continue;
60040
+ const _schemaType = schemaType.schema.singleNestedPaths[key];
60041
+ this.subpaths[path + '.' + key] = _schemaType;
60042
+ if (typeof _schemaType === 'object' && _schemaType != null) {
60043
+ _schemaType.$isUnderneathDocArray = true;
59656
60044
  }
59657
- this.subpaths[path + '.' + key] = schemaType.schema.singleNestedPaths[key];
59658
- schemaType.schema.singleNestedPaths[key].$isUnderneathDocArray = true;
59659
60045
  }
59660
60046
  }
59661
60047
 
@@ -59713,10 +60099,11 @@ function _pathToPositionalSyntax(path) {
59713
60099
  */
59714
60100
 
59715
60101
  function getMapPath(schema, path) {
59716
- for (const _path of Object.keys(schema.paths)) {
59717
- if (!_path.includes('.$*')) {
59718
- continue;
59719
- }
60102
+ if (schema.mapPaths.length === 0) {
60103
+ return null;
60104
+ }
60105
+ for (const val of schema.mapPaths) {
60106
+ const _path = val.path;
59720
60107
  const re = new RegExp('^' + _path.replace(/\.\$\*/g, '\\.[^.]+') + '$');
59721
60108
  if (re.test(path)) {
59722
60109
  return schema.paths[_path];
@@ -59790,11 +60177,21 @@ Schema.prototype.interpretAsType = function(path, obj, options) {
59790
60177
  : type[0];
59791
60178
 
59792
60179
  if (cast && cast.instanceOfSchema) {
60180
+ if (!(cast instanceof Schema)) {
60181
+ throw new TypeError('Schema for array path `' + path +
60182
+ '` is from a different copy of the Mongoose module. Please make sure you\'re using the same version ' +
60183
+ 'of Mongoose everywhere with `npm list mongoose`.');
60184
+ }
59793
60185
  return new MongooseTypes.DocumentArray(path, cast, obj);
59794
60186
  }
59795
60187
  if (cast &&
59796
60188
  cast[options.typeKey] &&
59797
60189
  cast[options.typeKey].instanceOfSchema) {
60190
+ if (!(cast[options.typeKey] instanceof Schema)) {
60191
+ throw new TypeError('Schema for array path `' + path +
60192
+ '` is from a different copy of the Mongoose module. Please make sure you\'re using the same version ' +
60193
+ 'of Mongoose everywhere with `npm list mongoose`.');
60194
+ }
59798
60195
  return new MongooseTypes.DocumentArray(path, cast[options.typeKey], obj, cast);
59799
60196
  }
59800
60197
 
@@ -59847,6 +60244,11 @@ Schema.prototype.interpretAsType = function(path, obj, options) {
59847
60244
  ? type
59848
60245
  : type.schemaName || utils.getFunctionName(type);
59849
60246
 
60247
+ // For Jest 26+, see #10296
60248
+ if (name === 'ClockDate') {
60249
+ name = 'Date';
60250
+ }
60251
+
59850
60252
  if (!MongooseTypes.hasOwnProperty(name)) {
59851
60253
  throw new TypeError('Invalid schema configuration: ' +
59852
60254
  `\`${name}\` is not a valid type within the array \`${path}\`.` +
@@ -59877,6 +60279,10 @@ Schema.prototype.interpretAsType = function(path, obj, options) {
59877
60279
  if (name === 'ObjectID') {
59878
60280
  name = 'ObjectId';
59879
60281
  }
60282
+ // For Jest 26+, see #10296
60283
+ if (name === 'ClockDate') {
60284
+ name = 'Date';
60285
+ }
59880
60286
 
59881
60287
  if (MongooseTypes[name] == null) {
59882
60288
  throw new TypeError(`Invalid schema configuration: \`${name}\` is not ` +
@@ -60331,7 +60737,7 @@ Schema.prototype.plugin = function(fn, opts) {
60331
60737
  * fizz.purr();
60332
60738
  * fizz.scratch();
60333
60739
  *
60334
- * NOTE: `Schema.method()` adds instance methods to the `Schema.methods` object. You can also add instance methods directly to the `Schema.methods` object as seen in the [guide](./guide.html#methods)
60740
+ * NOTE: `Schema.method()` adds instance methods to the `Schema.methods` object. You can also add instance methods directly to the `Schema.methods` object as seen in the [guide](/docs/guide.html#methods)
60335
60741
  *
60336
60742
  * @param {String|Object} method name
60337
60743
  * @param {Function} [fn]
@@ -60393,7 +60799,7 @@ Schema.prototype.static = function(name, fn) {
60393
60799
  *
60394
60800
  * @param {Object} fields
60395
60801
  * @param {Object} [options] Options to pass to [MongoDB driver's `createIndex()` function](http://mongodb.github.io/node-mongodb-native/2.0/api/Collection.html#createIndex)
60396
- * @param {String} [options.expires=null] Mongoose-specific syntactic sugar, uses [ms](https://www.npmjs.com/package/ms) to convert `expires` option into seconds for the `expireAfterSeconds` in the above link.
60802
+ * @param {String | number} [options.expires=null] Mongoose-specific syntactic sugar, uses [ms](https://www.npmjs.com/package/ms) to convert `expires` option into seconds for the `expireAfterSeconds` in the above link.
60397
60803
  * @api public
60398
60804
  */
60399
60805
 
@@ -60514,8 +60920,8 @@ Object.defineProperty(Schema, 'indexTypes', {
60514
60920
  });
60515
60921
 
60516
60922
  /**
60517
- * Returns a list of indexes that this schema declares, via `schema.index()`
60518
- * or by `index: true` in a path's options.
60923
+ * Returns a list of indexes that this schema declares, via `schema.index()` or by `index: true` in a path's options.
60924
+ * Indexes are expressed as an array `[spec, options]`.
60519
60925
  *
60520
60926
  * ####Example:
60521
60927
  *
@@ -60528,6 +60934,17 @@ Object.defineProperty(Schema, 'indexTypes', {
60528
60934
  * // [ { registeredAt: 1 }, { background: true } ] ]
60529
60935
  * userSchema.indexes();
60530
60936
  *
60937
+ * [Plugins](/docs/plugins.html) can use the return value of this function to modify a schema's indexes.
60938
+ * For example, the below plugin makes every index unique by default.
60939
+ *
60940
+ * function myPlugin(schema) {
60941
+ * for (const index of schema.indexes()) {
60942
+ * if (index[1].unique === undefined) {
60943
+ * index[1].unique = true;
60944
+ * }
60945
+ * }
60946
+ * }
60947
+ *
60531
60948
  * @api public
60532
60949
  * @return {Array} list of indexes defined in the schema
60533
60950
  */
@@ -60551,7 +60968,7 @@ Schema.prototype.indexes = function() {
60551
60968
  */
60552
60969
 
60553
60970
  Schema.prototype.virtual = function(name, options) {
60554
- if (name instanceof VirtualType || (name != null && name.constructor.name === 'VirtualType')) {
60971
+ if (name instanceof VirtualType || getConstructorName(name) === 'VirtualType') {
60555
60972
  return this.virtual(name.path, name.options);
60556
60973
  }
60557
60974
 
@@ -60735,9 +61152,9 @@ function _deletePath(schema, name) {
60735
61152
  /**
60736
61153
  * Loads an ES6 class into a schema. Maps [setters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/set) + [getters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get), [static methods](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/static),
60737
61154
  * and [instance methods](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes#Class_body_and_method_definitions)
60738
- * to schema [virtuals](http://mongoosejs.com/docs/guide.html#virtuals),
60739
- * [statics](http://mongoosejs.com/docs/guide.html#statics), and
60740
- * [methods](http://mongoosejs.com/docs/guide.html#methods).
61155
+ * to schema [virtuals](/docs/guide.html#virtuals),
61156
+ * [statics](/docs/guide.html#statics), and
61157
+ * [methods](/docs/guide.html#methods).
60741
61158
  *
60742
61159
  * ####Example:
60743
61160
  *
@@ -60782,12 +61199,12 @@ Schema.prototype.loadClass = function(model, virtualsOnly) {
60782
61199
  // Add static methods
60783
61200
  if (!virtualsOnly) {
60784
61201
  Object.getOwnPropertyNames(model).forEach(function(name) {
60785
- if (name.match(/^(length|name|prototype)$/)) {
61202
+ if (name.match(/^(length|name|prototype|constructor|__proto__)$/)) {
60786
61203
  return;
60787
61204
  }
60788
- const method = Object.getOwnPropertyDescriptor(model, name);
60789
- if (typeof method.value === 'function') {
60790
- this.static(name, method.value);
61205
+ const prop = Object.getOwnPropertyDescriptor(model, name);
61206
+ if (prop.hasOwnProperty('value')) {
61207
+ this.static(name, prop.value);
60791
61208
  }
60792
61209
  }, this);
60793
61210
  }
@@ -60885,7 +61302,7 @@ Schema.prototype._getSchema = function(path) {
60885
61302
  }
60886
61303
  } else if (foundschema.$isSchemaMap) {
60887
61304
  if (p + 1 >= parts.length) {
60888
- return foundschema.$__schemaType;
61305
+ return foundschema;
60889
61306
  }
60890
61307
  const ret = search(parts.slice(p + 1), foundschema.$__schemaType.schema);
60891
61308
  return ret;
@@ -60996,14 +61413,14 @@ module.exports = exports = Schema;
60996
61413
  *
60997
61414
  * ####Types:
60998
61415
  *
60999
- * - [String](#schema-string-js)
61000
- * - [Number](#schema-number-js)
61001
- * - [Boolean](#schema-boolean-js) | Bool
61002
- * - [Array](#schema-array-js)
61003
- * - [Buffer](#schema-buffer-js)
61004
- * - [Date](#schema-date-js)
61005
- * - [ObjectId](#schema-objectid-js) | Oid
61006
- * - [Mixed](#schema-mixed-js)
61416
+ * - [String](/docs/schematypes.html#strings)
61417
+ * - [Number](/docs/schematypes.html#numbers)
61418
+ * - [Boolean](/docs/schematypes.html#booleans) | Bool
61419
+ * - [Array](/docs/schematypes.html#arrays)
61420
+ * - [Buffer](/docs/schematypes.html#buffers)
61421
+ * - [Date](/docs/schematypes.html#dates)
61422
+ * - [ObjectId](/docs/schematypes.html#objectids) | Oid
61423
+ * - [Mixed](/docs/schematypes.html#mixed)
61007
61424
  *
61008
61425
  * Using this exposed access to the `Mixed` SchemaType, we can use them in our schema.
61009
61426
  *
@@ -61022,7 +61439,7 @@ Schema.Types = MongooseTypes = require('./schema/index');
61022
61439
  exports.ObjectId = MongooseTypes.ObjectId;
61023
61440
 
61024
61441
  }).call(this)}).call(this,{"isBuffer":require("../../is-buffer/index.js")})
61025
- },{"../../is-buffer/index.js":179,"./driver":196,"./error/mongooseError":207,"./helpers/get":229,"./helpers/model/applyHooks":236,"./helpers/populate/validateRef":238,"./helpers/query/applyQueryMiddleware":242,"./helpers/schema/addAutoId":244,"./helpers/schema/getIndexes":246,"./helpers/schema/merge":249,"./helpers/symbols":252,"./helpers/timestamps/setupTimestamps":253,"./options/SchemaTypeOptions":268,"./options/VirtualOptions":269,"./schema/index":282,"./schematype":295,"./utils":307,"./virtualtype":308,"events":177,"kareem":182,"mpath":310,"util":332}],275:[function(require,module,exports){
61442
+ },{"../../is-buffer/index.js":179,"./driver":196,"./error/mongooseError":207,"./helpers/get":230,"./helpers/getConstructorName":231,"./helpers/model/applyHooks":238,"./helpers/populate/validateRef":240,"./helpers/query/applyQueryMiddleware":244,"./helpers/schema/addAutoId":246,"./helpers/schema/getIndexes":248,"./helpers/schema/merge":251,"./helpers/symbols":254,"./helpers/timestamps/setupTimestamps":255,"./options/SchemaTypeOptions":270,"./options/VirtualOptions":271,"./schema/index":284,"./schematype":297,"./utils":309,"./virtualtype":310,"events":177,"kareem":182,"mpath":312,"util":334}],277:[function(require,module,exports){
61026
61443
  'use strict';
61027
61444
 
61028
61445
  /*!
@@ -61360,7 +61777,7 @@ SingleNestedPath.prototype.clone = function() {
61360
61777
  return schematype;
61361
61778
  };
61362
61779
 
61363
- },{"../error/cast":202,"../error/objectExpected":209,"../helpers/discriminator/getConstructor":222,"../helpers/get":229,"../helpers/model/discriminator":237,"../helpers/schema/handleIdOption":247,"../options":257,"../options/SchemaSingleNestedOptions":266,"../schematype":295,"../types/subdocument":306,"./operators/exists":288,"./operators/geospatial":289,"./operators/helpers":290,"events":177}],276:[function(require,module,exports){
61780
+ },{"../error/cast":202,"../error/objectExpected":209,"../helpers/discriminator/getConstructor":223,"../helpers/get":230,"../helpers/model/discriminator":239,"../helpers/schema/handleIdOption":249,"../options":259,"../options/SchemaSingleNestedOptions":268,"../schematype":297,"../types/subdocument":308,"./operators/exists":290,"./operators/geospatial":291,"./operators/helpers":292,"events":177}],278:[function(require,module,exports){
61364
61781
  'use strict';
61365
61782
 
61366
61783
  /*!
@@ -61388,6 +61805,7 @@ let MongooseArray;
61388
61805
  let EmbeddedDoc;
61389
61806
 
61390
61807
  const isNestedArraySymbol = Symbol('mongoose#isNestedArray');
61808
+ const emptyOpts = Object.freeze({});
61391
61809
 
61392
61810
  /**
61393
61811
  * Array SchemaType constructor
@@ -61423,6 +61841,10 @@ function SchemaArray(key, cast, options, schemaOptions) {
61423
61841
  }
61424
61842
  }
61425
61843
 
61844
+ if (options != null && options.ref != null && castOptions.ref == null) {
61845
+ castOptions.ref = options.ref;
61846
+ }
61847
+
61426
61848
  if (cast === Object) {
61427
61849
  cast = Mixed;
61428
61850
  }
@@ -61444,16 +61866,16 @@ function SchemaArray(key, cast, options, schemaOptions) {
61444
61866
  if (typeof caster === 'function' &&
61445
61867
  !caster.$isArraySubdocument &&
61446
61868
  !caster.$isSchemaMap) {
61447
- this.caster = new caster(null, castOptions);
61869
+ const path = this.caster instanceof EmbeddedDoc ? null : key;
61870
+ this.caster = new caster(path, castOptions);
61448
61871
  } else {
61449
61872
  this.caster = caster;
61873
+ if (!(this.caster instanceof EmbeddedDoc)) {
61874
+ this.caster.path = key;
61875
+ }
61450
61876
  }
61451
61877
 
61452
61878
  this.$embeddedSchemaType = this.caster;
61453
-
61454
- if (!(this.caster instanceof EmbeddedDoc)) {
61455
- this.caster.path = key;
61456
- }
61457
61879
  }
61458
61880
 
61459
61881
  this.$isMongooseArray = true;
@@ -61504,6 +61926,10 @@ SchemaArray.schemaName = 'Array';
61504
61926
 
61505
61927
  SchemaArray.options = { castNonArrays: true };
61506
61928
 
61929
+ /*!
61930
+ * ignore
61931
+ */
61932
+
61507
61933
  SchemaArray.defaultOptions = {};
61508
61934
 
61509
61935
  /**
@@ -61521,7 +61947,6 @@ SchemaArray.defaultOptions = {};
61521
61947
  * @param {*} value - value for option
61522
61948
  * @return {undefined}
61523
61949
  * @function set
61524
- * @static
61525
61950
  * @api public
61526
61951
  */
61527
61952
  SchemaArray.set = SchemaType.set;
@@ -61554,7 +61979,6 @@ SchemaArray._checkRequired = SchemaType.prototype.checkRequired;
61554
61979
  * @param {Function} fn
61555
61980
  * @return {Function}
61556
61981
  * @function checkRequired
61557
- * @static
61558
61982
  * @api public
61559
61983
  */
61560
61984
 
@@ -61624,7 +62048,7 @@ SchemaArray.prototype.enum = function() {
61624
62048
  */
61625
62049
 
61626
62050
  SchemaArray.prototype.applyGetters = function(value, scope) {
61627
- if (scope != null && scope.populated(this.path)) {
62051
+ if (scope != null && scope.$__ != null && scope.populated(this.path)) {
61628
62052
  // means the object id was populated
61629
62053
  return value;
61630
62054
  }
@@ -61640,14 +62064,14 @@ SchemaArray.prototype.applyGetters = function(value, scope) {
61640
62064
  };
61641
62065
 
61642
62066
  SchemaArray.prototype._applySetters = function(value, scope, init, priorVal) {
61643
- if (this.casterConstructor instanceof SchemaArray &&
62067
+ if (this.casterConstructor.$isMongooseArray &&
61644
62068
  SchemaArray.options.castNonArrays &&
61645
62069
  !this[isNestedArraySymbol]) {
61646
62070
  // Check nesting levels and wrap in array if necessary
61647
62071
  let depth = 0;
61648
62072
  let arr = this;
61649
62073
  while (arr != null &&
61650
- arr instanceof SchemaArray &&
62074
+ arr.$isMongooseArray &&
61651
62075
  !arr.$isMongooseDocumentArray) {
61652
62076
  ++depth;
61653
62077
  arr = arr.casterConstructor;
@@ -61684,7 +62108,8 @@ SchemaArray.prototype.cast = function(value, doc, init, prev, options) {
61684
62108
  let l;
61685
62109
 
61686
62110
  if (Array.isArray(value)) {
61687
- if (!value.length && doc) {
62111
+ const len = value.length;
62112
+ if (!len && doc) {
61688
62113
  const indexes = doc.schema.indexedPaths();
61689
62114
 
61690
62115
  const arrayPath = this.path;
@@ -61709,39 +62134,35 @@ SchemaArray.prototype.cast = function(value, doc, init, prev, options) {
61709
62134
  }
61710
62135
  }
61711
62136
 
61712
- if (!(value && value.isMongooseArray)) {
61713
- value = MongooseArray(value, get(options, 'path', null) || this._arrayPath || this.path, doc, this);
61714
- } else if (value && value.isMongooseArray) {
61715
- // We need to create a new array, otherwise change tracking will
61716
- // update the old doc (gh-4449)
61717
- value = MongooseArray(value, get(options, 'path', null) || this._arrayPath || this.path, doc, this);
61718
- }
62137
+ options = options || emptyOpts;
62138
+
62139
+ value = MongooseArray(value, options.path || this._arrayPath || this.path, doc, this);
61719
62140
 
61720
- const isPopulated = doc != null && doc.$__ != null && doc.populated(this.path);
61721
- if (isPopulated && init) {
62141
+ if (init && doc != null && doc.$__ != null && doc.populated(this.path)) {
61722
62142
  return value;
61723
62143
  }
61724
62144
 
61725
62145
  const caster = this.caster;
62146
+ const isMongooseArray = caster.$isMongooseArray;
62147
+ const isArrayOfNumbers = caster.instance === 'Number';
61726
62148
  if (caster && this.casterConstructor !== Mixed) {
61727
62149
  try {
61728
- const len = value.length;
61729
62150
  for (i = 0; i < len; i++) {
61730
62151
  // Special case: number arrays disallow undefined.
61731
62152
  // Re: gh-840
61732
62153
  // See commit 1298fe92d2c790a90594bd08199e45a4a09162a6
61733
- if (caster.instance === 'Number' && value[i] === void 0) {
62154
+ if (isArrayOfNumbers && value[i] === void 0) {
61734
62155
  throw new MongooseError('Mongoose number arrays disallow storing undefined');
61735
62156
  }
61736
62157
  const opts = {};
61737
62158
  // Perf: creating `arrayPath` is expensive for large arrays.
61738
62159
  // We only need `arrayPath` if this is a nested array, so
61739
62160
  // skip if possible.
61740
- if (caster.$isMongooseArray) {
61741
- if (options != null && options.arrayPath != null) {
61742
- opts.arrayPath = options.arrayPath + '.' + i;
61743
- } else if (this.caster._arrayParentPath != null) {
61744
- opts.arrayPath = this.caster._arrayParentPath + '.' + i;
62161
+ if (isMongooseArray) {
62162
+ if (options.arrayPath != null) {
62163
+ opts.arrayPathIndex = i;
62164
+ } else if (caster._arrayParentPath != null) {
62165
+ opts.arrayPathIndex = i;
61745
62166
  }
61746
62167
  }
61747
62168
  value[i] = caster.applySetters(value[i], doc, init, void 0, opts);
@@ -61767,12 +62188,50 @@ SchemaArray.prototype.cast = function(value, doc, init, prev, options) {
61767
62188
  throw new CastError('Array', util.inspect(value), this.path, null, this);
61768
62189
  };
61769
62190
 
62191
+ /*!
62192
+ * ignore
62193
+ */
62194
+
62195
+ SchemaArray.prototype._castForPopulate = function _castForPopulate(value, doc) {
62196
+ // lazy load
62197
+ MongooseArray || (MongooseArray = require('../types').Array);
62198
+
62199
+ if (Array.isArray(value)) {
62200
+ let i;
62201
+ const len = value.length;
62202
+
62203
+ const caster = this.caster;
62204
+ if (caster && this.casterConstructor !== Mixed) {
62205
+ try {
62206
+ for (i = 0; i < len; i++) {
62207
+ const opts = {};
62208
+ // Perf: creating `arrayPath` is expensive for large arrays.
62209
+ // We only need `arrayPath` if this is a nested array, so
62210
+ // skip if possible.
62211
+ if (caster.$isMongooseArray && caster._arrayParentPath != null) {
62212
+ opts.arrayPathIndex = i;
62213
+ }
62214
+
62215
+ value[i] = caster.cast(value[i], doc, false, void 0, opts);
62216
+ }
62217
+ } catch (e) {
62218
+ // rethrow
62219
+ throw new CastError('[' + e.kind + ']', util.inspect(value), this.path + '.' + i, e, this);
62220
+ }
62221
+ }
62222
+
62223
+ return value;
62224
+ }
62225
+
62226
+ throw new CastError('Array', util.inspect(value), this.path, null, this);
62227
+ };
62228
+
61770
62229
  /*!
61771
62230
  * Ignore
61772
62231
  */
61773
62232
 
61774
62233
  SchemaArray.prototype.discriminator = function(name, schema) {
61775
- let arr = this; // eslint-disable-line consistent-this
62234
+ let arr = this;
61776
62235
  while (arr.$isMongooseArray && !arr.$isMongooseDocumentArray) {
61777
62236
  arr = arr.casterConstructor;
61778
62237
  if (arr == null || typeof arr === 'function') {
@@ -61830,7 +62289,7 @@ SchemaArray.prototype.castForQuery = function($conditional, value) {
61830
62289
  Constructor.discriminators[val[Constructor.schema.options.discriminatorKey]]) {
61831
62290
  Constructor = Constructor.discriminators[val[Constructor.schema.options.discriminatorKey]];
61832
62291
  } else {
61833
- const constructorByValue = getDiscriminatorByValue(Constructor, val[Constructor.schema.options.discriminatorKey]);
62292
+ const constructorByValue = getDiscriminatorByValue(Constructor.discriminators, val[Constructor.schema.options.discriminatorKey]);
61834
62293
  if (constructorByValue) {
61835
62294
  Constructor = constructorByValue;
61836
62295
  }
@@ -61971,7 +62430,7 @@ handle.$in = SchemaType.prototype.$conditionalHandlers.$in;
61971
62430
 
61972
62431
  module.exports = SchemaArray;
61973
62432
 
61974
- },{"../cast":187,"../error/mongooseError":207,"../helpers/arrayDepth":218,"../helpers/discriminator/getDiscriminatorByValue":223,"../helpers/get":229,"../helpers/query/isOperator":243,"../options/SchemaArrayOptions":259,"../schematype":295,"../types":303,"../utils":307,"./index.js":282,"./mixed":284,"./operators/exists":288,"./operators/geospatial":289,"./operators/helpers":290,"./operators/type":292,"util":332}],277:[function(require,module,exports){
62433
+ },{"../cast":187,"../error/mongooseError":207,"../helpers/arrayDepth":218,"../helpers/discriminator/getDiscriminatorByValue":224,"../helpers/get":230,"../helpers/query/isOperator":245,"../options/SchemaArrayOptions":261,"../schematype":297,"../types":305,"../utils":309,"./index.js":284,"./mixed":286,"./operators/exists":290,"./operators/geospatial":291,"./operators/helpers":292,"./operators/type":294,"util":334}],279:[function(require,module,exports){
61975
62434
  'use strict';
61976
62435
 
61977
62436
  /*!
@@ -62243,7 +62702,7 @@ SchemaBoolean.prototype._castNullish = function _castNullish(v) {
62243
62702
 
62244
62703
  module.exports = SchemaBoolean;
62245
62704
 
62246
- },{"../cast/boolean":188,"../error/cast":202,"../schematype":295,"../utils":307}],278:[function(require,module,exports){
62705
+ },{"../cast/boolean":188,"../error/cast":202,"../schematype":297,"../utils":309}],280:[function(require,module,exports){
62247
62706
  (function (Buffer){(function (){
62248
62707
  /*!
62249
62708
  * Module dependencies.
@@ -62257,11 +62716,8 @@ const SchemaType = require('../schematype');
62257
62716
  const handleBitwiseOperator = require('./operators/bitwise');
62258
62717
  const utils = require('../utils');
62259
62718
 
62260
- const populateModelSymbol = require('../helpers/symbols').populateModelSymbol;
62261
-
62262
62719
  const Binary = MongooseBuffer.Binary;
62263
62720
  const CastError = SchemaType.CastError;
62264
- let Document;
62265
62721
 
62266
62722
  /**
62267
62723
  * Buffer SchemaType constructor
@@ -62371,36 +62827,30 @@ SchemaBuffer.prototype.checkRequired = function(value, doc) {
62371
62827
  SchemaBuffer.prototype.cast = function(value, doc, init) {
62372
62828
  let ret;
62373
62829
  if (SchemaType._isRef(this, value, doc, init)) {
62374
- // wait! we may need to cast this to a document
62375
-
62376
- if (value === null || value === undefined) {
62830
+ if (value && value.isMongooseBuffer) {
62377
62831
  return value;
62378
62832
  }
62379
62833
 
62380
- // lazy load
62381
- Document || (Document = require('./../document'));
62382
-
62383
- if (value instanceof Document) {
62384
- value.$__.wasPopulated = true;
62834
+ if (Buffer.isBuffer(value)) {
62835
+ if (!value || !value.isMongooseBuffer) {
62836
+ value = new MongooseBuffer(value, [this.path, doc]);
62837
+ if (this.options.subtype != null) {
62838
+ value._subtype = this.options.subtype;
62839
+ }
62840
+ }
62385
62841
  return value;
62386
62842
  }
62387
62843
 
62388
- // setting a populated path
62389
- if (Buffer.isBuffer(value)) {
62390
- return value;
62391
- } else if (!utils.isObject(value)) {
62392
- throw new CastError('Buffer', value, this.path, null, this);
62844
+ if (value instanceof Binary) {
62845
+ ret = new MongooseBuffer(value.value(true), [this.path, doc]);
62846
+ if (typeof value.sub_type !== 'number') {
62847
+ throw new CastError('Buffer', value, this.path, null, this);
62848
+ }
62849
+ ret._subtype = value.sub_type;
62850
+ return ret;
62393
62851
  }
62394
62852
 
62395
- // Handle the case where user directly sets a populated
62396
- // path to a plain object; cast to the Model used in
62397
- // the population query.
62398
- const path = doc.$__fullPath(this.path);
62399
- const owner = doc.ownerDocument ? doc.ownerDocument() : doc;
62400
- const pop = owner.populated(path, true);
62401
- ret = new pop.options[populateModelSymbol](value);
62402
- ret.$__.wasPopulated = true;
62403
- return ret;
62853
+ return this._castRef(value, doc, init);
62404
62854
  }
62405
62855
 
62406
62856
  // documents
@@ -62523,7 +62973,7 @@ SchemaBuffer.prototype.castForQuery = function($conditional, val) {
62523
62973
  module.exports = SchemaBuffer;
62524
62974
 
62525
62975
  }).call(this)}).call(this,{"isBuffer":require("../../../is-buffer/index.js")})
62526
- },{"../../../is-buffer/index.js":179,"../helpers/symbols":252,"../options/SchemaBufferOptions":260,"../schematype":295,"../types/buffer":298,"../utils":307,"./../document":194,"./operators/bitwise":287}],279:[function(require,module,exports){
62976
+ },{"../../../is-buffer/index.js":179,"../options/SchemaBufferOptions":262,"../schematype":297,"../types/buffer":300,"../utils":309,"./operators/bitwise":289}],281:[function(require,module,exports){
62527
62977
  /*!
62528
62978
  * Module requirements.
62529
62979
  */
@@ -62534,6 +62984,7 @@ const MongooseError = require('../error/index');
62534
62984
  const SchemaDateOptions = require('../options/SchemaDateOptions');
62535
62985
  const SchemaType = require('../schematype');
62536
62986
  const castDate = require('../cast/date');
62987
+ const getConstructorName = require('../helpers/getConstructorName');
62537
62988
  const utils = require('../utils');
62538
62989
 
62539
62990
  const CastError = SchemaType.CastError;
@@ -62673,7 +63124,7 @@ SchemaDate._defaultCaster = v => {
62673
63124
  */
62674
63125
 
62675
63126
  SchemaDate.prototype.expires = function(when) {
62676
- if (!this._index || this._index.constructor.name !== 'Object') {
63127
+ if (getConstructorName(this._index) !== 'Object') {
62677
63128
  this._index = {};
62678
63129
  }
62679
63130
 
@@ -62927,8 +63378,7 @@ SchemaDate.prototype.castForQuery = function($conditional, val) {
62927
63378
 
62928
63379
  module.exports = SchemaDate;
62929
63380
 
62930
- },{"../cast/date":189,"../error/index":204,"../options/SchemaDateOptions":261,"../schematype":295,"../utils":307}],280:[function(require,module,exports){
62931
- (function (Buffer){(function (){
63381
+ },{"../cast/date":189,"../error/index":204,"../helpers/getConstructorName":231,"../options/SchemaDateOptions":263,"../schematype":297,"../utils":309}],282:[function(require,module,exports){
62932
63382
  /*!
62933
63383
  * Module dependencies.
62934
63384
  */
@@ -62941,10 +63391,6 @@ const Decimal128Type = require('../types/decimal128');
62941
63391
  const castDecimal128 = require('../cast/decimal128');
62942
63392
  const utils = require('../utils');
62943
63393
 
62944
- const populateModelSymbol = require('../helpers/symbols').populateModelSymbol;
62945
-
62946
- let Document;
62947
-
62948
63394
  /**
62949
63395
  * Decimal128 SchemaType constructor.
62950
63396
  *
@@ -63099,44 +63545,11 @@ Decimal128.prototype.checkRequired = function checkRequired(value, doc) {
63099
63545
 
63100
63546
  Decimal128.prototype.cast = function(value, doc, init) {
63101
63547
  if (SchemaType._isRef(this, value, doc, init)) {
63102
- // wait! we may need to cast this to a document
63103
-
63104
- if (value === null || value === undefined) {
63105
- return value;
63106
- }
63107
-
63108
- // lazy load
63109
- Document || (Document = require('./../document'));
63110
-
63111
- if (value instanceof Document) {
63112
- value.$__.wasPopulated = true;
63113
- return value;
63114
- }
63115
-
63116
- // setting a populated path
63117
63548
  if (value instanceof Decimal128Type) {
63118
63549
  return value;
63119
- } else if (Buffer.isBuffer(value) || !utils.isObject(value)) {
63120
- throw new CastError('Decimal128', value, this.path, null, this);
63121
- }
63122
-
63123
- // Handle the case where user directly sets a populated
63124
- // path to a plain object; cast to the Model used in
63125
- // the population query.
63126
- const path = doc.$__fullPath(this.path);
63127
- const owner = doc.ownerDocument ? doc.ownerDocument() : doc;
63128
- const pop = owner.populated(path, true);
63129
- let ret = value;
63130
- if (!doc.$__.populated ||
63131
- !doc.$__.populated[path] ||
63132
- !doc.$__.populated[path].options ||
63133
- !doc.$__.populated[path].options.options ||
63134
- !doc.$__.populated[path].options.options.lean) {
63135
- ret = new pop.options[populateModelSymbol](value);
63136
- ret.$__.wasPopulated = true;
63137
63550
  }
63138
63551
 
63139
- return ret;
63552
+ return this._castRef(value, doc, init);
63140
63553
  }
63141
63554
 
63142
63555
  let castDecimal128;
@@ -63177,8 +63590,7 @@ Decimal128.prototype.$conditionalHandlers =
63177
63590
 
63178
63591
  module.exports = Decimal128;
63179
63592
 
63180
- }).call(this)}).call(this,{"isBuffer":require("../../../is-buffer/index.js")})
63181
- },{"../../../is-buffer/index.js":179,"../cast/decimal128":190,"../helpers/symbols":252,"../schematype":295,"../types/decimal128":300,"../utils":307,"./../document":194}],281:[function(require,module,exports){
63593
+ },{"../cast/decimal128":190,"../schematype":297,"../types/decimal128":302,"../utils":309}],283:[function(require,module,exports){
63182
63594
  'use strict';
63183
63595
 
63184
63596
  /*!
@@ -63199,6 +63611,7 @@ const util = require('util');
63199
63611
  const utils = require('../utils');
63200
63612
  const getConstructor = require('../helpers/discriminator/getConstructor');
63201
63613
 
63614
+ const arrayAtomicsSymbol = require('../helpers/symbols').arrayAtomicsSymbol;
63202
63615
  const arrayPathSymbol = require('../helpers/symbols').arrayPathSymbol;
63203
63616
  const documentArrayParent = require('../helpers/symbols').documentArrayParent;
63204
63617
 
@@ -63582,8 +63995,12 @@ DocumentArrayPath.prototype.cast = function(value, doc, init, prev, options) {
63582
63995
  value = new MongooseDocumentArray(value, this.path, doc);
63583
63996
  }
63584
63997
 
63585
- if (options.arrayPath != null) {
63586
- value[arrayPathSymbol] = options.arrayPath;
63998
+ if (prev != null) {
63999
+ value[arrayAtomicsSymbol] = prev[arrayAtomicsSymbol] || {};
64000
+ }
64001
+
64002
+ if (options.arrayPathIndex != null) {
64003
+ value[arrayPathSymbol] = this.path + '.' + options.arrayPathIndex;
63587
64004
  }
63588
64005
 
63589
64006
  const len = value.length;
@@ -63743,7 +64160,7 @@ DocumentArrayPath.set = SchemaType.set;
63743
64160
 
63744
64161
  module.exports = DocumentArrayPath;
63745
64162
 
63746
- },{"../error/cast":202,"../error/validation":215,"../helpers/discriminator/getConstructor":222,"../helpers/get":229,"../helpers/model/discriminator":237,"../helpers/schema/handleIdOption":247,"../helpers/symbols":252,"../options/SchemaDocumentArrayOptions":262,"../schematype":295,"../types/documentarray":301,"../types/embedded":302,"../utils":307,"./array":276,"events":177,"util":332}],282:[function(require,module,exports){
64163
+ },{"../error/cast":202,"../error/validation":215,"../helpers/discriminator/getConstructor":223,"../helpers/get":230,"../helpers/model/discriminator":239,"../helpers/schema/handleIdOption":249,"../helpers/symbols":254,"../options/SchemaDocumentArrayOptions":264,"../schematype":297,"../types/documentarray":303,"../types/embedded":304,"../utils":309,"./array":278,"events":177,"util":334}],284:[function(require,module,exports){
63747
64164
 
63748
64165
  /*!
63749
64166
  * Module exports.
@@ -63782,7 +64199,7 @@ exports.Object = exports.Mixed;
63782
64199
  exports.Bool = exports.Boolean;
63783
64200
  exports.ObjectID = exports.ObjectId;
63784
64201
 
63785
- },{"./SingleNestedPath":275,"./array":276,"./boolean":277,"./buffer":278,"./date":279,"./decimal128":280,"./documentarray":281,"./map":283,"./mixed":284,"./number":285,"./objectid":286,"./string":293}],283:[function(require,module,exports){
64202
+ },{"./SingleNestedPath":277,"./array":278,"./boolean":279,"./buffer":280,"./date":281,"./decimal128":282,"./documentarray":283,"./map":285,"./mixed":286,"./number":287,"./objectid":288,"./string":295}],285:[function(require,module,exports){
63786
64203
  (function (global){(function (){
63787
64204
  'use strict';
63788
64205
 
@@ -63862,7 +64279,7 @@ Map.defaultOptions = {};
63862
64279
  module.exports = Map;
63863
64280
 
63864
64281
  }).call(this)}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
63865
- },{"../options/SchemaMapOptions":263,"../schematype":295,"../types/map":304}],284:[function(require,module,exports){
64282
+ },{"../options/SchemaMapOptions":265,"../schematype":297,"../types/map":306}],286:[function(require,module,exports){
63866
64283
  /*!
63867
64284
  * Module dependencies.
63868
64285
  */
@@ -63872,6 +64289,7 @@ module.exports = Map;
63872
64289
  const SchemaType = require('../schematype');
63873
64290
  const symbols = require('./symbols');
63874
64291
  const isObject = require('../helpers/isObject');
64292
+ const utils = require('../utils');
63875
64293
 
63876
64294
  /**
63877
64295
  * Mixed SchemaType constructor.
@@ -63968,6 +64386,9 @@ Mixed.set = SchemaType.set;
63968
64386
  */
63969
64387
 
63970
64388
  Mixed.prototype.cast = function(val) {
64389
+ if (val instanceof Error) {
64390
+ return utils.errorToPOJO(val);
64391
+ }
63971
64392
  return val;
63972
64393
  };
63973
64394
 
@@ -63992,8 +64413,7 @@ Mixed.prototype.castForQuery = function($cond, val) {
63992
64413
 
63993
64414
  module.exports = Mixed;
63994
64415
 
63995
- },{"../helpers/isObject":234,"../schematype":295,"./symbols":294}],285:[function(require,module,exports){
63996
- (function (Buffer){(function (){
64416
+ },{"../helpers/isObject":236,"../schematype":297,"../utils":309,"./symbols":296}],287:[function(require,module,exports){
63997
64417
  'use strict';
63998
64418
 
63999
64419
  /*!
@@ -64007,10 +64427,7 @@ const castNumber = require('../cast/number');
64007
64427
  const handleBitwiseOperator = require('./operators/bitwise');
64008
64428
  const utils = require('../utils');
64009
64429
 
64010
- const populateModelSymbol = require('../helpers/symbols').populateModelSymbol;
64011
-
64012
64430
  const CastError = SchemaType.CastError;
64013
- let Document;
64014
64431
 
64015
64432
  /**
64016
64433
  * Number SchemaType constructor.
@@ -64346,36 +64763,11 @@ SchemaNumber.prototype.enum = function(values, message) {
64346
64763
 
64347
64764
  SchemaNumber.prototype.cast = function(value, doc, init) {
64348
64765
  if (SchemaType._isRef(this, value, doc, init)) {
64349
- // wait! we may need to cast this to a document
64350
-
64351
- if (value === null || value === undefined) {
64352
- return value;
64353
- }
64354
-
64355
- // lazy load
64356
- Document || (Document = require('./../document'));
64357
-
64358
- if (value instanceof Document) {
64359
- value.$__.wasPopulated = true;
64360
- return value;
64361
- }
64362
-
64363
- // setting a populated path
64364
64766
  if (typeof value === 'number') {
64365
64767
  return value;
64366
- } else if (Buffer.isBuffer(value) || !utils.isObject(value)) {
64367
- throw new CastError('Number', value, this.path, null, this);
64368
64768
  }
64369
64769
 
64370
- // Handle the case where user directly sets a populated
64371
- // path to a plain object; cast to the Model used in
64372
- // the population query.
64373
- const path = doc.$__fullPath(this.path);
64374
- const owner = doc.ownerDocument ? doc.ownerDocument() : doc;
64375
- const pop = owner.populated(path, true);
64376
- const ret = new pop.options[populateModelSymbol](value);
64377
- ret.$__.wasPopulated = true;
64378
- return ret;
64770
+ return this._castRef(value, doc, init);
64379
64771
  }
64380
64772
 
64381
64773
  const val = value && typeof value._id !== 'undefined' ?
@@ -64456,9 +64848,7 @@ SchemaNumber.prototype.castForQuery = function($conditional, val) {
64456
64848
 
64457
64849
  module.exports = SchemaNumber;
64458
64850
 
64459
- }).call(this)}).call(this,{"isBuffer":require("../../../is-buffer/index.js")})
64460
- },{"../../../is-buffer/index.js":179,"../cast/number":191,"../error/index":204,"../helpers/symbols":252,"../options/SchemaNumberOptions":264,"../schematype":295,"../utils":307,"./../document":194,"./operators/bitwise":287}],286:[function(require,module,exports){
64461
- (function (Buffer){(function (){
64851
+ },{"../cast/number":191,"../error/index":204,"../options/SchemaNumberOptions":266,"../schematype":297,"../utils":309,"./operators/bitwise":289}],288:[function(require,module,exports){
64462
64852
  /*!
64463
64853
  * Module dependencies.
64464
64854
  */
@@ -64468,11 +64858,10 @@ module.exports = SchemaNumber;
64468
64858
  const SchemaObjectIdOptions = require('../options/SchemaObjectIdOptions');
64469
64859
  const SchemaType = require('../schematype');
64470
64860
  const castObjectId = require('../cast/objectid');
64861
+ const getConstructorName = require('../helpers/getConstructorName');
64471
64862
  const oid = require('../types/objectid');
64472
64863
  const utils = require('../utils');
64473
64864
 
64474
- const populateModelSymbol = require('../helpers/symbols').populateModelSymbol;
64475
-
64476
64865
  const CastError = SchemaType.CastError;
64477
64866
  let Document;
64478
64867
 
@@ -64686,45 +65075,13 @@ ObjectId.prototype.checkRequired = function checkRequired(value, doc) {
64686
65075
  ObjectId.prototype.cast = function(value, doc, init) {
64687
65076
  if (SchemaType._isRef(this, value, doc, init)) {
64688
65077
  // wait! we may need to cast this to a document
64689
-
64690
- if (value === null || value === undefined) {
64691
- return value;
64692
- }
64693
-
64694
- // lazy load
64695
- Document || (Document = require('./../document'));
64696
-
64697
- if (value instanceof Document) {
64698
- value.$__.wasPopulated = true;
64699
- return value;
64700
- }
64701
-
64702
- // setting a populated path
64703
65078
  if (value instanceof oid) {
64704
65079
  return value;
64705
- } else if ((value.constructor.name || '').toLowerCase() === 'objectid') {
65080
+ } else if ((getConstructorName(value) || '').toLowerCase() === 'objectid') {
64706
65081
  return new oid(value.toHexString());
64707
- } else if (Buffer.isBuffer(value) || !utils.isObject(value)) {
64708
- throw new CastError('ObjectId', value, this.path, null, this);
64709
- }
64710
-
64711
- // Handle the case where user directly sets a populated
64712
- // path to a plain object; cast to the Model used in
64713
- // the population query.
64714
- const path = doc.$__fullPath(this.path);
64715
- const owner = doc.ownerDocument ? doc.ownerDocument() : doc;
64716
- const pop = owner.populated(path, true);
64717
- let ret = value;
64718
- if (!doc.$__.populated ||
64719
- !doc.$__.populated[path] ||
64720
- !doc.$__.populated[path].options ||
64721
- !doc.$__.populated[path].options.options ||
64722
- !doc.$__.populated[path].options.options.lean) {
64723
- ret = new pop.options[populateModelSymbol](value);
64724
- ret.$__.wasPopulated = true;
64725
65082
  }
64726
65083
 
64727
- return ret;
65084
+ return this._castRef(value, doc, init);
64728
65085
  }
64729
65086
 
64730
65087
  let castObjectId;
@@ -64791,8 +65148,7 @@ function resetId(v) {
64791
65148
 
64792
65149
  module.exports = ObjectId;
64793
65150
 
64794
- }).call(this)}).call(this,{"isBuffer":require("../../../is-buffer/index.js")})
64795
- },{"../../../is-buffer/index.js":179,"../cast/objectid":192,"../helpers/symbols":252,"../options/SchemaObjectIdOptions":265,"../schematype":295,"../types/objectid":305,"../utils":307,"./../document":194}],287:[function(require,module,exports){
65151
+ },{"../cast/objectid":192,"../helpers/getConstructorName":231,"../options/SchemaObjectIdOptions":267,"../schematype":297,"../types/objectid":307,"../utils":309,"./../document":194}],289:[function(require,module,exports){
64796
65152
  (function (Buffer){(function (){
64797
65153
  /*!
64798
65154
  * Module requirements.
@@ -64834,7 +65190,7 @@ function _castNumber(path, num) {
64834
65190
  module.exports = handleBitwiseOperator;
64835
65191
 
64836
65192
  }).call(this)}).call(this,{"isBuffer":require("../../../../is-buffer/index.js")})
64837
- },{"../../../../is-buffer/index.js":179,"../../error/cast":202}],288:[function(require,module,exports){
65193
+ },{"../../../../is-buffer/index.js":179,"../../error/cast":202}],290:[function(require,module,exports){
64838
65194
  'use strict';
64839
65195
 
64840
65196
  const castBoolean = require('../../cast/boolean');
@@ -64848,7 +65204,7 @@ module.exports = function(val) {
64848
65204
  return castBoolean(val, path);
64849
65205
  };
64850
65206
 
64851
- },{"../../cast/boolean":188}],289:[function(require,module,exports){
65207
+ },{"../../cast/boolean":188}],291:[function(require,module,exports){
64852
65208
  /*!
64853
65209
  * Module requirements.
64854
65210
  */
@@ -64957,7 +65313,7 @@ function _castMinMaxDistance(self, val) {
64957
65313
  }
64958
65314
  }
64959
65315
 
64960
- },{"../array":276,"./helpers":290}],290:[function(require,module,exports){
65316
+ },{"../array":278,"./helpers":292}],292:[function(require,module,exports){
64961
65317
  'use strict';
64962
65318
 
64963
65319
  /*!
@@ -64991,7 +65347,7 @@ function castArraysOfNumbers(arr, self) {
64991
65347
  });
64992
65348
  }
64993
65349
 
64994
- },{"../number":285}],291:[function(require,module,exports){
65350
+ },{"../number":287}],293:[function(require,module,exports){
64995
65351
  'use strict';
64996
65352
 
64997
65353
  const CastError = require('../../error/cast');
@@ -65032,7 +65388,7 @@ module.exports = function(val, path) {
65032
65388
  return val;
65033
65389
  };
65034
65390
 
65035
- },{"../../cast/boolean":188,"../../cast/string":193,"../../error/cast":202}],292:[function(require,module,exports){
65391
+ },{"../../cast/boolean":188,"../../cast/string":193,"../../error/cast":202}],294:[function(require,module,exports){
65036
65392
  'use strict';
65037
65393
 
65038
65394
  /*!
@@ -65054,8 +65410,7 @@ module.exports = function(val) {
65054
65410
  return val;
65055
65411
  };
65056
65412
 
65057
- },{}],293:[function(require,module,exports){
65058
- (function (Buffer){(function (){
65413
+ },{}],295:[function(require,module,exports){
65059
65414
  'use strict';
65060
65415
 
65061
65416
  /*!
@@ -65068,10 +65423,7 @@ const SchemaStringOptions = require('../options/SchemaStringOptions');
65068
65423
  const castString = require('../cast/string');
65069
65424
  const utils = require('../utils');
65070
65425
 
65071
- const populateModelSymbol = require('../helpers/symbols').populateModelSymbol;
65072
-
65073
65426
  const CastError = SchemaType.CastError;
65074
- let Document;
65075
65427
 
65076
65428
  /**
65077
65429
  * String SchemaType constructor.
@@ -65642,36 +65994,11 @@ SchemaString.prototype.checkRequired = function checkRequired(value, doc) {
65642
65994
 
65643
65995
  SchemaString.prototype.cast = function(value, doc, init) {
65644
65996
  if (SchemaType._isRef(this, value, doc, init)) {
65645
- // wait! we may need to cast this to a document
65646
-
65647
- if (value === null || value === undefined) {
65648
- return value;
65649
- }
65650
-
65651
- // lazy load
65652
- Document || (Document = require('./../document'));
65653
-
65654
- if (value instanceof Document) {
65655
- value.$__.wasPopulated = true;
65656
- return value;
65657
- }
65658
-
65659
- // setting a populated path
65660
65997
  if (typeof value === 'string') {
65661
65998
  return value;
65662
- } else if (Buffer.isBuffer(value) || !utils.isObject(value)) {
65663
- throw new CastError('string', value, this.path, null, this);
65664
65999
  }
65665
66000
 
65666
- // Handle the case where user directly sets a populated
65667
- // path to a plain object; cast to the Model used in
65668
- // the population query.
65669
- const path = doc.$__fullPath(this.path);
65670
- const owner = doc.ownerDocument ? doc.ownerDocument() : doc;
65671
- const pop = owner.populated(path, true);
65672
- const ret = new pop.options[populateModelSymbol](value);
65673
- ret.$__.wasPopulated = true;
65674
- return ret;
66001
+ return this._castRef(value, doc, init);
65675
66002
  }
65676
66003
 
65677
66004
  let castString;
@@ -65757,14 +66084,13 @@ SchemaString.prototype.castForQuery = function($conditional, val) {
65757
66084
 
65758
66085
  module.exports = SchemaString;
65759
66086
 
65760
- }).call(this)}).call(this,{"isBuffer":require("../../../is-buffer/index.js")})
65761
- },{"../../../is-buffer/index.js":179,"../cast/string":193,"../error/index":204,"../helpers/symbols":252,"../options/SchemaStringOptions":267,"../schematype":295,"../utils":307,"./../document":194}],294:[function(require,module,exports){
66087
+ },{"../cast/string":193,"../error/index":204,"../options/SchemaStringOptions":269,"../schematype":297,"../utils":309}],296:[function(require,module,exports){
65762
66088
  'use strict';
65763
66089
 
65764
66090
  exports.schemaMixedSymbol = Symbol.for('mongoose:schema_mixed');
65765
66091
 
65766
66092
  exports.builtInMiddleware = Symbol.for('mongoose:built-in-middleware');
65767
- },{}],295:[function(require,module,exports){
66093
+ },{}],297:[function(require,module,exports){
65768
66094
  (function (Buffer){(function (){
65769
66095
  'use strict';
65770
66096
 
@@ -65785,6 +66111,8 @@ const utils = require('./utils');
65785
66111
  const validatorErrorSymbol = require('./helpers/symbols').validatorErrorSymbol;
65786
66112
  const documentIsModified = require('./helpers/symbols').documentIsModified;
65787
66113
 
66114
+ const populateModelSymbol = require('./helpers/symbols').populateModelSymbol;
66115
+
65788
66116
  const CastError = MongooseError.CastError;
65789
66117
  const ValidatorError = MongooseError.ValidatorError;
65790
66118
 
@@ -65813,6 +66141,8 @@ function SchemaType(path, options, instance) {
65813
66141
  [];
65814
66142
  this.setters = [];
65815
66143
 
66144
+ this.splitPath();
66145
+
65816
66146
  options = options || {};
65817
66147
  const defaultOptions = this.constructor.defaultOptions || {};
65818
66148
  const defaultOptionsKeys = Object.keys(defaultOptions);
@@ -65887,11 +66217,27 @@ function SchemaType(path, options, instance) {
65887
66217
  }
65888
66218
 
65889
66219
  /*!
65890
- * ignore
66220
+ * The class that Mongoose uses internally to instantiate this SchemaType's `options` property.
65891
66221
  */
65892
66222
 
65893
66223
  SchemaType.prototype.OptionsConstructor = SchemaTypeOptions;
65894
66224
 
66225
+ /*!
66226
+ * ignore
66227
+ */
66228
+
66229
+ SchemaType.prototype.splitPath = function() {
66230
+ if (this._presplitPath != null) {
66231
+ return this._presplitPath;
66232
+ }
66233
+ if (this.path == null) {
66234
+ return undefined;
66235
+ }
66236
+
66237
+ this._presplitPath = this.path.indexOf('.') === -1 ? [this.path] : this.path.split('.');
66238
+ return this._presplitPath;
66239
+ };
66240
+
65895
66241
  /**
65896
66242
  * Get/set the function used to cast arbitrary values to this type.
65897
66243
  *
@@ -65958,6 +66304,19 @@ SchemaType.prototype.castFunction = function castFunction(caster) {
65958
66304
  return this._castFunction;
65959
66305
  };
65960
66306
 
66307
+ /**
66308
+ * The function that Mongoose calls to cast arbitrary values to this SchemaType.
66309
+ *
66310
+ * @param {Object} value value to cast
66311
+ * @param {Document} doc document that triggers the casting
66312
+ * @param {Boolean} init
66313
+ * @api public
66314
+ */
66315
+
66316
+ SchemaType.prototype.cast = function cast() {
66317
+ throw new Error('Base SchemaType class does not implement a `cast()` function');
66318
+ };
66319
+
65961
66320
  /**
65962
66321
  * Sets a default option for this schema type.
65963
66322
  *
@@ -66824,8 +67183,8 @@ SchemaType.prototype._applySetters = function(value, scope, init) {
66824
67183
  }
66825
67184
  const setters = this.setters;
66826
67185
 
66827
- for (const setter of utils.clone(setters).reverse()) {
66828
- v = setter.call(scope, v, this);
67186
+ for (let i = setters.length - 1; i >= 0; i--) {
67187
+ v = setters[i].call(scope, v, this);
66829
67188
  }
66830
67189
 
66831
67190
  return v;
@@ -66850,7 +67209,6 @@ SchemaType.prototype._castNullish = function _castNullish(v) {
66850
67209
 
66851
67210
  SchemaType.prototype.applySetters = function(value, scope, init, priorVal, options) {
66852
67211
  let v = this._applySetters(value, scope, init, priorVal, options);
66853
-
66854
67212
  if (v == null) {
66855
67213
  return this._castNullish(v);
66856
67214
  }
@@ -67182,11 +67540,54 @@ SchemaType._isRef = function(self, value, doc, init) {
67182
67540
  ) {
67183
67541
  return true;
67184
67542
  }
67543
+
67544
+ return init;
67185
67545
  }
67186
67546
 
67187
67547
  return false;
67188
67548
  };
67189
67549
 
67550
+ /*!
67551
+ * ignore
67552
+ */
67553
+
67554
+ SchemaType.prototype._castRef = function _castRef(value, doc, init) {
67555
+ if (value == null) {
67556
+ return value;
67557
+ }
67558
+
67559
+ if (value.$__ != null) {
67560
+ value.$__.wasPopulated = true;
67561
+ return value;
67562
+ }
67563
+
67564
+ // setting a populated path
67565
+ if (Buffer.isBuffer(value) || !utils.isObject(value)) {
67566
+ if (init) {
67567
+ return value;
67568
+ }
67569
+ throw new CastError(this.instance, value, this.path, null, this);
67570
+ }
67571
+
67572
+ // Handle the case where user directly sets a populated
67573
+ // path to a plain object; cast to the Model used in
67574
+ // the population query.
67575
+ const path = doc.$__fullPath(this.path);
67576
+ const owner = doc.ownerDocument ? doc.ownerDocument() : doc;
67577
+ const pop = owner.populated(path, true);
67578
+ let ret = value;
67579
+ if (!doc.$__.populated ||
67580
+ !doc.$__.populated[path] ||
67581
+ !doc.$__.populated[path].options ||
67582
+ !doc.$__.populated[path].options.options ||
67583
+ !doc.$__.populated[path].options.options.lean) {
67584
+ ret = new pop.options[populateModelSymbol](value);
67585
+ ret.$__.wasPopulated = true;
67586
+ }
67587
+
67588
+ return ret;
67589
+ };
67590
+
67190
67591
  /*!
67191
67592
  * ignore
67192
67593
  */
@@ -67365,7 +67766,7 @@ exports.CastError = CastError;
67365
67766
  exports.ValidatorError = ValidatorError;
67366
67767
 
67367
67768
  }).call(this)}).call(this,{"isBuffer":require("../../is-buffer/index.js")})
67368
- },{"../../is-buffer/index.js":179,"./error/index":204,"./helpers/get":229,"./helpers/immediate":231,"./helpers/schematype/handleImmutable":250,"./helpers/symbols":252,"./options/SchemaTypeOptions":268,"./schema/operators/exists":288,"./schema/operators/type":292,"./utils":307,"util":332}],296:[function(require,module,exports){
67769
+ },{"../../is-buffer/index.js":179,"./error/index":204,"./helpers/get":230,"./helpers/immediate":233,"./helpers/schematype/handleImmutable":252,"./helpers/symbols":254,"./options/SchemaTypeOptions":270,"./schema/operators/exists":290,"./schema/operators/type":294,"./utils":309,"util":334}],298:[function(require,module,exports){
67369
67770
 
67370
67771
  /*!
67371
67772
  * Module dependencies.
@@ -67547,7 +67948,7 @@ StateMachine.prototype.map = function map() {
67547
67948
  return this.map.apply(this, arguments);
67548
67949
  };
67549
67950
 
67550
- },{"./utils":307}],297:[function(require,module,exports){
67951
+ },{"./utils":309}],299:[function(require,module,exports){
67551
67952
  /*!
67552
67953
  * Module dependencies.
67553
67954
  */
@@ -67555,7 +67956,6 @@ StateMachine.prototype.map = function map() {
67555
67956
  'use strict';
67556
67957
 
67557
67958
  const CoreMongooseArray = require('./core_array');
67558
- const Document = require('../document');
67559
67959
 
67560
67960
  const arrayAtomicsSymbol = require('../helpers/symbols').arrayAtomicsSymbol;
67561
67961
  const arrayParentSymbol = require('../helpers/symbols').arrayParentSymbol;
@@ -67580,28 +67980,44 @@ const _basePush = Array.prototype.push;
67580
67980
  */
67581
67981
 
67582
67982
  function MongooseArray(values, path, doc, schematype) {
67583
- const arr = new CoreMongooseArray();
67584
- arr[arrayAtomicsSymbol] = {};
67983
+ let arr;
67585
67984
 
67586
67985
  if (Array.isArray(values)) {
67587
67986
  const len = values.length;
67588
- for (let i = 0; i < len; ++i) {
67589
- _basePush.call(arr, values[i]);
67987
+
67988
+ // Perf optimizations for small arrays: much faster to use `...` than `for` + `push`,
67989
+ // but large arrays may cause stack overflows. And for arrays of length 0/1, just
67990
+ // modifying the array is faster. Seems small, but adds up when you have a document
67991
+ // with thousands of nested arrays.
67992
+ if (len === 0) {
67993
+ arr = new CoreMongooseArray();
67994
+ } else if (len === 1) {
67995
+ arr = new CoreMongooseArray(1);
67996
+ arr[0] = values[0];
67997
+ } else if (len < 10000) {
67998
+ arr = new CoreMongooseArray();
67999
+ _basePush.apply(arr, values);
68000
+ } else {
68001
+ arr = new CoreMongooseArray();
68002
+ for (let i = 0; i < len; ++i) {
68003
+ _basePush.call(arr, values[i]);
68004
+ }
67590
68005
  }
67591
68006
 
67592
68007
  if (values[arrayAtomicsSymbol] != null) {
67593
68008
  arr[arrayAtomicsSymbol] = values[arrayAtomicsSymbol];
67594
68009
  }
68010
+ } else {
68011
+ arr = new CoreMongooseArray();
67595
68012
  }
67596
68013
 
67597
68014
  arr[arrayPathSymbol] = path;
67598
- arr[arraySchemaSymbol] = void 0;
67599
68015
 
67600
68016
  // Because doc comes from the context of another function, doc === global
67601
68017
  // can happen if there was a null somewhere up the chain (see #3020)
67602
68018
  // RB Jun 17, 2015 updated to check for presence of expected paths instead
67603
68019
  // to make more proof against unusual node environments
67604
- if (doc && doc instanceof Document) {
68020
+ if (doc != null && doc.$__ != null) {
67605
68021
  arr[arrayParentSymbol] = doc;
67606
68022
  arr[arraySchemaSymbol] = schematype || doc.schema.path(path);
67607
68023
  }
@@ -67615,7 +68031,7 @@ function MongooseArray(values, path, doc, schematype) {
67615
68031
 
67616
68032
  module.exports = exports = MongooseArray;
67617
68033
 
67618
- },{"../document":194,"../helpers/symbols":252,"./core_array":299}],298:[function(require,module,exports){
68034
+ },{"../helpers/symbols":254,"./core_array":301}],300:[function(require,module,exports){
67619
68035
  /*!
67620
68036
  * Module dependencies.
67621
68037
  */
@@ -67893,7 +68309,7 @@ MongooseBuffer.Binary = Binary;
67893
68309
 
67894
68310
  module.exports = MongooseBuffer;
67895
68311
 
67896
- },{"../driver":196,"../utils":307,"safe-buffer":327}],299:[function(require,module,exports){
68312
+ },{"../driver":196,"../utils":309,"safe-buffer":329}],301:[function(require,module,exports){
67897
68313
  (function (Buffer){(function (){
67898
68314
  'use strict';
67899
68315
 
@@ -67991,7 +68407,7 @@ class CoreMongooseArray extends Array {
67991
68407
  */
67992
68408
 
67993
68409
  $atomics() {
67994
- return this[arrayAtomicsSymbol];
68410
+ return this[arrayAtomicsSymbol] || {};
67995
68411
  }
67996
68412
 
67997
68413
  /*!
@@ -68145,8 +68561,8 @@ class CoreMongooseArray extends Array {
68145
68561
 
68146
68562
  // gh-2399
68147
68563
  // we should cast model only when it's not a discriminator
68148
- const isDisc = value.schema && value.schema.discriminatorMapping &&
68149
- value.schema.discriminatorMapping.key !== undefined;
68564
+ const isDisc = value.$__schema && value.$__schema.discriminatorMapping &&
68565
+ value.$__schema.discriminatorMapping.key !== undefined;
68150
68566
  if (!isDisc) {
68151
68567
  value = new Model(value);
68152
68568
  }
@@ -68225,6 +68641,8 @@ class CoreMongooseArray extends Array {
68225
68641
  return this;
68226
68642
  }
68227
68643
 
68644
+ this[arrayAtomicsSymbol] || (this[arrayAtomicsSymbol] = {});
68645
+
68228
68646
  const atomics = this[arrayAtomicsSymbol];
68229
68647
 
68230
68648
  // reset pop/shift after save
@@ -68865,7 +69283,7 @@ function _checkManualPopulation(arr, docs) {
68865
69283
  module.exports = CoreMongooseArray;
68866
69284
 
68867
69285
  }).call(this)}).call(this,{"isBuffer":require("../../../is-buffer/index.js")})
68868
- },{"../../../is-buffer/index.js":179,"../document":194,"../error/mongooseError":207,"../helpers/document/cleanModifiedSubpaths":225,"../helpers/get":229,"../helpers/symbols":252,"../options":257,"../utils":307,"./embedded":302,"./objectid":305,"util":332}],300:[function(require,module,exports){
69286
+ },{"../../../is-buffer/index.js":179,"../document":194,"../error/mongooseError":207,"../helpers/document/cleanModifiedSubpaths":226,"../helpers/get":230,"../helpers/symbols":254,"../options":259,"../utils":309,"./embedded":304,"./objectid":307,"util":334}],302:[function(require,module,exports){
68869
69287
  /**
68870
69288
  * ObjectId type constructor
68871
69289
  *
@@ -68880,7 +69298,7 @@ module.exports = CoreMongooseArray;
68880
69298
 
68881
69299
  module.exports = require('../driver').get().Decimal128;
68882
69300
 
68883
- },{"../driver":196}],301:[function(require,module,exports){
69301
+ },{"../driver":196}],303:[function(require,module,exports){
68884
69302
  (function (Buffer){(function (){
68885
69303
  'use strict';
68886
69304
 
@@ -68980,7 +69398,7 @@ class CoreDocumentArray extends CoreMongooseArray {
68980
69398
  Constructor.discriminators[value[Constructor.schema.options.discriminatorKey]]) {
68981
69399
  Constructor = Constructor.discriminators[value[Constructor.schema.options.discriminatorKey]];
68982
69400
  } else {
68983
- const constructorByValue = getDiscriminatorByValue(Constructor, value[Constructor.schema.options.discriminatorKey]);
69401
+ const constructorByValue = getDiscriminatorByValue(Constructor.discriminators, value[Constructor.schema.options.discriminatorKey]);
68984
69402
  if (constructorByValue) {
68985
69403
  Constructor = constructorByValue;
68986
69404
  }
@@ -69173,7 +69591,7 @@ class CoreDocumentArray extends CoreMongooseArray {
69173
69591
  Constructor.discriminators[obj[Constructor.schema.options.discriminatorKey]]) {
69174
69592
  Constructor = Constructor.discriminators[obj[Constructor.schema.options.discriminatorKey]];
69175
69593
  } else {
69176
- const constructorByValue = getDiscriminatorByValue(Constructor, obj[Constructor.schema.options.discriminatorKey]);
69594
+ const constructorByValue = getDiscriminatorByValue(Constructor.discriminators, obj[Constructor.schema.options.discriminatorKey]);
69177
69595
  if (constructorByValue) {
69178
69596
  Constructor = constructorByValue;
69179
69597
  }
@@ -69332,7 +69750,7 @@ function MongooseDocumentArray(values, path, doc) {
69332
69750
  module.exports = MongooseDocumentArray;
69333
69751
 
69334
69752
  }).call(this)}).call(this,{"isBuffer":require("../../../is-buffer/index.js")})
69335
- },{"../../../is-buffer/index.js":179,"../cast/objectid":192,"../document":194,"../helpers/discriminator/getDiscriminatorByValue":223,"../helpers/symbols":252,"../options":257,"../utils":307,"./core_array":299,"./objectid":305,"util":332}],302:[function(require,module,exports){
69753
+ },{"../../../is-buffer/index.js":179,"../cast/objectid":192,"../document":194,"../helpers/discriminator/getDiscriminatorByValue":224,"../helpers/symbols":254,"../options":259,"../utils":309,"./core_array":301,"./objectid":307,"util":334}],304:[function(require,module,exports){
69336
69754
  /* eslint no-func-assign: 1 */
69337
69755
 
69338
69756
  /*!
@@ -69732,7 +70150,7 @@ EmbeddedDocument.prototype.ownerDocument = function() {
69732
70150
 
69733
70151
  EmbeddedDocument.prototype.$__fullPath = function(path) {
69734
70152
  if (!this.$__.fullPath) {
69735
- let parent = this; // eslint-disable-line consistent-this
70153
+ let parent = this;
69736
70154
  if (!parent[documentArrayParent]) {
69737
70155
  return path;
69738
70156
  }
@@ -69794,7 +70212,7 @@ EmbeddedDocument.prototype.parentArray = function() {
69794
70212
 
69795
70213
  module.exports = EmbeddedDocument;
69796
70214
 
69797
- },{"../document_provider":195,"../error/validation":215,"../helpers/get":229,"../helpers/immediate":231,"../helpers/promiseOrCallback":241,"../helpers/symbols":252,"../options":257,"events":177,"util":332}],303:[function(require,module,exports){
70215
+ },{"../document_provider":195,"../error/validation":215,"../helpers/get":230,"../helpers/immediate":233,"../helpers/promiseOrCallback":243,"../helpers/symbols":254,"../options":259,"events":177,"util":334}],305:[function(require,module,exports){
69798
70216
 
69799
70217
  /*!
69800
70218
  * Module exports.
@@ -69816,13 +70234,15 @@ exports.Map = require('./map');
69816
70234
 
69817
70235
  exports.Subdocument = require('./subdocument');
69818
70236
 
69819
- },{"./array":297,"./buffer":298,"./decimal128":300,"./documentarray":301,"./embedded":302,"./map":304,"./objectid":305,"./subdocument":306}],304:[function(require,module,exports){
70237
+ },{"./array":299,"./buffer":300,"./decimal128":302,"./documentarray":303,"./embedded":304,"./map":306,"./objectid":307,"./subdocument":308}],306:[function(require,module,exports){
69820
70238
  'use strict';
69821
70239
 
69822
70240
  const Mixed = require('../schema/mixed');
69823
70241
  const ObjectId = require('./objectid');
70242
+ const clone = require('../helpers/clone');
69824
70243
  const deepEqual = require('../utils').deepEqual;
69825
70244
  const get = require('../helpers/get');
70245
+ const getConstructorName = require('../helpers/getConstructorName');
69826
70246
  const handleSpreadDoc = require('../helpers/document/handleSpreadDoc');
69827
70247
  const util = require('util');
69828
70248
  const specialProperties = require('../helpers/specialProperties');
@@ -69835,7 +70255,7 @@ const populateModelSymbol = require('../helpers/symbols').populateModelSymbol;
69835
70255
 
69836
70256
  class MongooseMap extends Map {
69837
70257
  constructor(v, path, doc, schemaType) {
69838
- if (v != null && v.constructor.name === 'Object') {
70258
+ if (getConstructorName(v) === 'Object') {
69839
70259
  v = Object.keys(v).reduce((arr, key) => arr.concat([[key, v[key]]]), []);
69840
70260
  }
69841
70261
  super(v);
@@ -69952,7 +70372,7 @@ class MongooseMap extends Map {
69952
70372
  const ret = {};
69953
70373
  const keys = this.keys();
69954
70374
  for (const key of keys) {
69955
- ret[key] = this.get(key);
70375
+ ret[key] = clone(this.get(key));
69956
70376
  }
69957
70377
  return ret;
69958
70378
  }
@@ -70056,7 +70476,7 @@ function checkValidKey(key) {
70056
70476
 
70057
70477
  module.exports = MongooseMap;
70058
70478
 
70059
- },{"../helpers/document/handleSpreadDoc":228,"../helpers/get":229,"../helpers/specialProperties":251,"../helpers/symbols":252,"../schema/mixed":284,"../utils":307,"./objectid":305,"util":332}],305:[function(require,module,exports){
70479
+ },{"../helpers/clone":219,"../helpers/document/handleSpreadDoc":229,"../helpers/get":230,"../helpers/getConstructorName":231,"../helpers/specialProperties":253,"../helpers/symbols":254,"../schema/mixed":286,"../utils":309,"./objectid":307,"util":334}],307:[function(require,module,exports){
70060
70480
  /**
70061
70481
  * ObjectId type constructor
70062
70482
  *
@@ -70088,7 +70508,7 @@ ObjectId.prototype[objectIdSymbol] = true;
70088
70508
 
70089
70509
  module.exports = ObjectId;
70090
70510
 
70091
- },{"../driver":196,"../helpers/symbols":252}],306:[function(require,module,exports){
70511
+ },{"../driver":196,"../helpers/symbols":254}],308:[function(require,module,exports){
70092
70512
  'use strict';
70093
70513
 
70094
70514
  const Document = require('../document');
@@ -70116,9 +70536,9 @@ function Subdocument(value, fields, parent, skipId, options) {
70116
70536
  let initedPaths = null;
70117
70537
  if (hasPriorDoc) {
70118
70538
  this._doc = Object.assign({}, options.priorDoc._doc);
70119
- delete this._doc[this.schema.options.discriminatorKey];
70539
+ delete this._doc[this.$__schema.options.discriminatorKey];
70120
70540
  initedPaths = Object.keys(options.priorDoc._doc || {}).
70121
- filter(key => key !== this.schema.options.discriminatorKey);
70541
+ filter(key => key !== this.$__schema.options.discriminatorKey);
70122
70542
  }
70123
70543
  if (parent != null) {
70124
70544
  // If setting a nested path, should copy isNew from parent re: gh-7048
@@ -70134,7 +70554,7 @@ function Subdocument(value, fields, parent, skipId, options) {
70134
70554
  if (!this.$__.activePaths.states.modify[key] &&
70135
70555
  !this.$__.activePaths.states.default[key] &&
70136
70556
  !this.$__.$setCalled.has(key)) {
70137
- const schematype = this.schema.path(key);
70557
+ const schematype = this.$__schema.path(key);
70138
70558
  const def = schematype == null ? void 0 : schematype.getDefault(this);
70139
70559
  if (def === void 0) {
70140
70560
  delete this._doc[key];
@@ -70391,7 +70811,7 @@ function registerRemoveListener(sub) {
70391
70811
  owner.on('remove', emitRemove);
70392
70812
  }
70393
70813
 
70394
- },{"../document":194,"../helpers/immediate":231,"../helpers/promiseOrCallback":241,"../helpers/symbols":252,"../options":257}],307:[function(require,module,exports){
70814
+ },{"../document":194,"../helpers/immediate":233,"../helpers/promiseOrCallback":243,"../helpers/symbols":254,"../options":259}],309:[function(require,module,exports){
70395
70815
  (function (process){(function (){
70396
70816
  'use strict';
70397
70817
 
@@ -70407,11 +70827,13 @@ const Decimal = require('./types/decimal128');
70407
70827
  const ObjectId = require('./types/objectid');
70408
70828
  const PopulateOptions = require('./options/PopulateOptions');
70409
70829
  const clone = require('./helpers/clone');
70830
+ const immediate = require('./helpers/immediate');
70410
70831
  const isObject = require('./helpers/isObject');
70411
70832
  const isBsonType = require('./helpers/isBsonType');
70412
70833
  const getFunctionName = require('./helpers/getFunctionName');
70413
70834
  const isMongooseObject = require('./helpers/isMongooseObject');
70414
70835
  const promiseOrCallback = require('./helpers/promiseOrCallback');
70836
+ const schemaMerge = require('./helpers/schema/merge');
70415
70837
  const specialProperties = require('./helpers/specialProperties');
70416
70838
 
70417
70839
  let Document;
@@ -70677,7 +71099,7 @@ exports.merge = function merge(to, from, options, path) {
70677
71099
  continue;
70678
71100
  } else if (from[key].instanceOfSchema) {
70679
71101
  if (to[key].instanceOfSchema) {
70680
- to[key].add(from[key].clone());
71102
+ schemaMerge(to[key], from[key].clone(), options.isDiscriminatorSchemaMerge);
70681
71103
  } else {
70682
71104
  to[key] = from[key].clone();
70683
71105
  }
@@ -70834,7 +71256,7 @@ exports.tick = function tick(callback) {
70834
71256
  } catch (err) {
70835
71257
  // only nextTick on err to get out of
70836
71258
  // the event loop and avoid state corruption.
70837
- process.nextTick(function() {
71259
+ immediate(function() {
70838
71260
  throw err;
70839
71261
  });
70840
71262
  }
@@ -71150,23 +71572,23 @@ exports.isArrayIndex = function(val) {
71150
71572
  */
71151
71573
 
71152
71574
  exports.array.unique = function(arr) {
71153
- const primitives = {};
71154
- const ids = {};
71575
+ const primitives = new Set();
71576
+ const ids = new Set();
71155
71577
  const ret = [];
71156
71578
 
71157
71579
  for (const item of arr) {
71158
71580
  if (typeof item === 'number' || typeof item === 'string' || item == null) {
71159
- if (primitives[item]) {
71581
+ if (primitives.has(item)) {
71160
71582
  continue;
71161
71583
  }
71162
71584
  ret.push(item);
71163
- primitives[item] = true;
71585
+ primitives.add(item);
71164
71586
  } else if (item instanceof ObjectId) {
71165
- if (ids[item.toString()]) {
71587
+ if (ids.has(item.toString())) {
71166
71588
  continue;
71167
71589
  }
71168
71590
  ret.push(item);
71169
- ids[item.toString()] = true;
71591
+ ids.add(item.toString());
71170
71592
  } else {
71171
71593
  ret.push(item);
71172
71594
  }
@@ -71316,8 +71738,23 @@ exports.getOption = function(name) {
71316
71738
 
71317
71739
  exports.noop = function() {};
71318
71740
 
71741
+ exports.errorToPOJO = function errorToPOJO(error) {
71742
+ const isError = error instanceof Error;
71743
+ if (!isError) {
71744
+ throw new Error('`error` must be `instanceof Error`.');
71745
+ }
71746
+
71747
+ const ret = {};
71748
+ for (const properyName of Object.getOwnPropertyNames(error)) {
71749
+ ret[properyName] = error[properyName];
71750
+ }
71751
+ return ret;
71752
+ };
71753
+
71754
+ exports.nodeMajorVersion = parseInt(process.versions.node.split('.')[0], 10);
71755
+
71319
71756
  }).call(this)}).call(this,require('_process'))
71320
- },{"./document":194,"./helpers/clone":219,"./helpers/getFunctionName":230,"./helpers/isBsonType":232,"./helpers/isMongooseObject":233,"./helpers/isObject":234,"./helpers/promiseOrCallback":241,"./helpers/specialProperties":251,"./options/PopulateOptions":258,"./types/decimal128":300,"./types/objectid":305,"_process":325,"mpath":310,"ms":309,"safe-buffer":327,"sliced":328}],308:[function(require,module,exports){
71757
+ },{"./document":194,"./helpers/clone":219,"./helpers/getFunctionName":232,"./helpers/immediate":233,"./helpers/isBsonType":234,"./helpers/isMongooseObject":235,"./helpers/isObject":236,"./helpers/promiseOrCallback":243,"./helpers/schema/merge":251,"./helpers/specialProperties":253,"./options/PopulateOptions":260,"./types/decimal128":302,"./types/objectid":307,"_process":327,"mpath":312,"ms":311,"safe-buffer":329,"sliced":330}],310:[function(require,module,exports){
71321
71758
  'use strict';
71322
71759
 
71323
71760
  const utils = require('./utils');
@@ -71495,7 +71932,7 @@ VirtualType.prototype.applySetters = function(value, doc) {
71495
71932
 
71496
71933
  module.exports = VirtualType;
71497
71934
 
71498
- },{"./utils":307}],309:[function(require,module,exports){
71935
+ },{"./utils":309}],311:[function(require,module,exports){
71499
71936
  /**
71500
71937
  * Helpers.
71501
71938
  */
@@ -71659,12 +72096,12 @@ function plural(ms, msAbs, n, name) {
71659
72096
  return Math.round(ms / n) + ' ' + name + (isPlural ? 's' : '');
71660
72097
  }
71661
72098
 
71662
- },{}],310:[function(require,module,exports){
72099
+ },{}],312:[function(require,module,exports){
71663
72100
  'use strict';
71664
72101
 
71665
72102
  module.exports = exports = require('./lib');
71666
72103
 
71667
- },{"./lib":311}],311:[function(require,module,exports){
72104
+ },{"./lib":313}],313:[function(require,module,exports){
71668
72105
  /* eslint strict:off */
71669
72106
  /* eslint no-var: off */
71670
72107
  /* eslint no-redeclare: off */
@@ -71731,6 +72168,9 @@ exports.get = function(path, o, special, map) {
71731
72168
 
71732
72169
  for (var i = 0; i < parts.length; ++i) {
71733
72170
  part = parts[i];
72171
+ if (typeof parts[i] !== 'string' && typeof parts[i] !== 'number') {
72172
+ throw new TypeError('Each segment of path to `get()` must be a string or number, got ' + typeof parts[i]);
72173
+ }
71734
72174
 
71735
72175
  if (Array.isArray(obj) && !/^\d+$/.test(part)) {
71736
72176
  // reading a property from the array items
@@ -71779,6 +72219,9 @@ exports.has = function(path, o) {
71779
72219
  var len = parts.length;
71780
72220
  var cur = o;
71781
72221
  for (var i = 0; i < len; ++i) {
72222
+ if (typeof parts[i] !== 'string' && typeof parts[i] !== 'number') {
72223
+ throw new TypeError('Each segment of path to `has()` must be a string or number, got ' + typeof parts[i]);
72224
+ }
71782
72225
  if (cur == null || typeof cur !== 'object' || !(parts[i] in cur)) {
71783
72226
  return false;
71784
72227
  }
@@ -71810,6 +72253,9 @@ exports.unset = function(path, o) {
71810
72253
  if (cur == null || typeof cur !== 'object' || !(parts[i] in cur)) {
71811
72254
  return false;
71812
72255
  }
72256
+ if (typeof parts[i] !== 'string' && typeof parts[i] !== 'number') {
72257
+ throw new TypeError('Each segment of path to `unset()` must be a string or number, got ' + typeof parts[i]);
72258
+ }
71813
72259
  // Disallow any updates to __proto__ or special properties.
71814
72260
  if (ignoreProperties.indexOf(parts[i]) !== -1) {
71815
72261
  return false;
@@ -71860,6 +72306,9 @@ exports.set = function(path, val, o, special, map, _copying) {
71860
72306
  if (null == o) return;
71861
72307
 
71862
72308
  for (var i = 0; i < parts.length; ++i) {
72309
+ if (typeof parts[i] !== 'string' && typeof parts[i] !== 'number') {
72310
+ throw new TypeError('Each segment of path to `set()` must be a string or number, got ' + typeof parts[i]);
72311
+ }
71863
72312
  // Silently ignore any updates to `__proto__`, these are potentially
71864
72313
  // dangerous if using mpath with unsanitized data.
71865
72314
  if (ignoreProperties.indexOf(parts[i]) !== -1) {
@@ -71979,7 +72428,7 @@ function _setArray(obj, val, part, lookup, special, map) {
71979
72428
  function K(v) {
71980
72429
  return v;
71981
72430
  }
71982
- },{"./stringToParts":312}],312:[function(require,module,exports){
72431
+ },{"./stringToParts":314}],314:[function(require,module,exports){
71983
72432
  'use strict';
71984
72433
 
71985
72434
  module.exports = function stringToParts(str) {
@@ -72028,7 +72477,7 @@ module.exports = function stringToParts(str) {
72028
72477
 
72029
72478
  return result;
72030
72479
  };
72031
- },{}],313:[function(require,module,exports){
72480
+ },{}],315:[function(require,module,exports){
72032
72481
  'use strict';
72033
72482
 
72034
72483
  /**
@@ -72076,7 +72525,7 @@ function notImplemented(method) {
72076
72525
  };
72077
72526
  }
72078
72527
 
72079
- },{}],314:[function(require,module,exports){
72528
+ },{}],316:[function(require,module,exports){
72080
72529
  'use strict';
72081
72530
 
72082
72531
  var env = require('../env');
@@ -72091,7 +72540,7 @@ module.exports =
72091
72540
  require('./collection');
72092
72541
 
72093
72542
 
72094
- },{"../env":316,"./collection":313,"./node":315}],315:[function(require,module,exports){
72543
+ },{"../env":318,"./collection":315,"./node":317}],317:[function(require,module,exports){
72095
72544
  'use strict';
72096
72545
 
72097
72546
  /**
@@ -72244,7 +72693,7 @@ NodeCollection.prototype.findCursor = function(match, findOptions) {
72244
72693
 
72245
72694
  module.exports = exports = NodeCollection;
72246
72695
 
72247
- },{"../utils":319,"./collection":313}],316:[function(require,module,exports){
72696
+ },{"../utils":321,"./collection":315}],318:[function(require,module,exports){
72248
72697
  (function (process,global,Buffer){(function (){
72249
72698
  'use strict';
72250
72699
 
@@ -72270,7 +72719,7 @@ exports.type = exports.isNode ? 'node'
72270
72719
  : 'unknown';
72271
72720
 
72272
72721
  }).call(this)}).call(this,require('_process'),typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {},require("buffer").Buffer)
72273
- },{"_process":325,"buffer":129}],317:[function(require,module,exports){
72722
+ },{"_process":327,"buffer":129}],319:[function(require,module,exports){
72274
72723
  'use strict';
72275
72724
 
72276
72725
  /**
@@ -75524,7 +75973,7 @@ module.exports = exports = Query;
75524
75973
  // TODO
75525
75974
  // test utils
75526
75975
 
75527
- },{"./collection":314,"./collection/collection":313,"./env":316,"./permissions":318,"./utils":319,"assert":103,"bluebird":108,"debug":320,"sliced":328,"util":332}],318:[function(require,module,exports){
75976
+ },{"./collection":316,"./collection/collection":315,"./env":318,"./permissions":320,"./utils":321,"assert":103,"bluebird":108,"debug":322,"sliced":330,"util":334}],320:[function(require,module,exports){
75528
75977
  'use strict';
75529
75978
 
75530
75979
  var denied = exports;
@@ -75614,7 +76063,7 @@ denied.count.maxScan =
75614
76063
  denied.count.snapshot =
75615
76064
  denied.count.tailable = true;
75616
76065
 
75617
- },{}],319:[function(require,module,exports){
76066
+ },{}],321:[function(require,module,exports){
75618
76067
  (function (process,setImmediate){(function (){
75619
76068
  'use strict';
75620
76069
 
@@ -75788,6 +76237,9 @@ exports.mergeClone = function mergeClone(to, from) {
75788
76237
 
75789
76238
  while (i--) {
75790
76239
  key = keys[i];
76240
+ if (specialProperties.indexOf(key) !== -1) {
76241
+ continue;
76242
+ }
75791
76243
  if ('undefined' === typeof to[key]) {
75792
76244
  to[key] = clone(from[key]);
75793
76245
  } else {
@@ -75978,7 +76430,7 @@ exports.isArgumentsObject = function(v) {
75978
76430
  };
75979
76431
 
75980
76432
  }).call(this)}).call(this,require('_process'),require("timers").setImmediate)
75981
- },{"_process":325,"regexp-clone":326,"safe-buffer":322,"timers":329}],320:[function(require,module,exports){
76433
+ },{"_process":327,"regexp-clone":328,"safe-buffer":324,"timers":331}],322:[function(require,module,exports){
75982
76434
  (function (process){(function (){
75983
76435
  /**
75984
76436
  * This is the web browser implementation of `debug()`.
@@ -76177,7 +76629,7 @@ function localstorage() {
76177
76629
  }
76178
76630
 
76179
76631
  }).call(this)}).call(this,require('_process'))
76180
- },{"./debug":321,"_process":325}],321:[function(require,module,exports){
76632
+ },{"./debug":323,"_process":327}],323:[function(require,module,exports){
76181
76633
 
76182
76634
  /**
76183
76635
  * This is the common logic for both the Node.js and web browser
@@ -76404,7 +76856,7 @@ function coerce(val) {
76404
76856
  return val;
76405
76857
  }
76406
76858
 
76407
- },{"ms":323}],322:[function(require,module,exports){
76859
+ },{"ms":325}],324:[function(require,module,exports){
76408
76860
  /* eslint-disable node/no-deprecated-api */
76409
76861
  var buffer = require('buffer')
76410
76862
  var Buffer = buffer.Buffer
@@ -76468,7 +76920,7 @@ SafeBuffer.allocUnsafeSlow = function (size) {
76468
76920
  return buffer.SlowBuffer(size)
76469
76921
  }
76470
76922
 
76471
- },{"buffer":129}],323:[function(require,module,exports){
76923
+ },{"buffer":129}],325:[function(require,module,exports){
76472
76924
  /**
76473
76925
  * Helpers.
76474
76926
  */
@@ -76622,7 +77074,7 @@ function plural(ms, n, name) {
76622
77074
  return Math.ceil(ms / n) + ' ' + name + 's';
76623
77075
  }
76624
77076
 
76625
- },{}],324:[function(require,module,exports){
77077
+ },{}],326:[function(require,module,exports){
76626
77078
  /*
76627
77079
  object-assign
76628
77080
  (c) Sindre Sorhus
@@ -76714,7 +77166,7 @@ module.exports = shouldUseNative() ? Object.assign : function (target, source) {
76714
77166
  return to;
76715
77167
  };
76716
77168
 
76717
- },{}],325:[function(require,module,exports){
77169
+ },{}],327:[function(require,module,exports){
76718
77170
  // shim for using process in browser
76719
77171
  var process = module.exports = {};
76720
77172
 
@@ -76900,7 +77352,7 @@ process.chdir = function (dir) {
76900
77352
  };
76901
77353
  process.umask = function() { return 0; };
76902
77354
 
76903
- },{}],326:[function(require,module,exports){
77355
+ },{}],328:[function(require,module,exports){
76904
77356
 
76905
77357
  const toString = Object.prototype.toString;
76906
77358
 
@@ -76929,7 +77381,7 @@ module.exports = exports = function (regexp) {
76929
77381
  }
76930
77382
 
76931
77383
 
76932
- },{}],327:[function(require,module,exports){
77384
+ },{}],329:[function(require,module,exports){
76933
77385
  /*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
76934
77386
  /* eslint-disable node/no-deprecated-api */
76935
77387
  var buffer = require('buffer')
@@ -76996,7 +77448,7 @@ SafeBuffer.allocUnsafeSlow = function (size) {
76996
77448
  return buffer.SlowBuffer(size)
76997
77449
  }
76998
77450
 
76999
- },{"buffer":129}],328:[function(require,module,exports){
77451
+ },{"buffer":129}],330:[function(require,module,exports){
77000
77452
 
77001
77453
  /**
77002
77454
  * An Array.prototype.slice.call(arguments) alternative
@@ -77031,7 +77483,7 @@ module.exports = function (args, slice, sliceEnd) {
77031
77483
  }
77032
77484
 
77033
77485
 
77034
- },{}],329:[function(require,module,exports){
77486
+ },{}],331:[function(require,module,exports){
77035
77487
  (function (setImmediate,clearImmediate){(function (){
77036
77488
  var nextTick = require('process/browser.js').nextTick;
77037
77489
  var apply = Function.prototype.apply;
@@ -77110,10 +77562,10 @@ exports.clearImmediate = typeof clearImmediate === "function" ? clearImmediate :
77110
77562
  delete immediateIds[id];
77111
77563
  };
77112
77564
  }).call(this)}).call(this,require("timers").setImmediate,require("timers").clearImmediate)
77113
- },{"process/browser.js":325,"timers":329}],330:[function(require,module,exports){
77565
+ },{"process/browser.js":327,"timers":331}],332:[function(require,module,exports){
77114
77566
  arguments[4][104][0].apply(exports,arguments)
77115
- },{"dup":104}],331:[function(require,module,exports){
77567
+ },{"dup":104}],333:[function(require,module,exports){
77116
77568
  arguments[4][105][0].apply(exports,arguments)
77117
- },{"dup":105}],332:[function(require,module,exports){
77569
+ },{"dup":105}],334:[function(require,module,exports){
77118
77570
  arguments[4][106][0].apply(exports,arguments)
77119
- },{"./support/isBuffer":331,"_process":325,"dup":106,"inherits":330}]},{},[75]);
77571
+ },{"./support/isBuffer":333,"_process":327,"dup":106,"inherits":332}]},{},[75]);