mongoose 5.11.3 → 5.11.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/History.md +47 -1
- package/dist/browser.umd.js +5 -5
- package/index.d.ts +167 -41
- package/lib/model.js +7 -3
- package/lib/schema/map.js +14 -2
- package/package.json +5 -5
package/History.md
CHANGED
|
@@ -1,6 +1,52 @@
|
|
|
1
|
+
5.11.7 / 2020-12-10
|
|
2
|
+
===================
|
|
3
|
+
* fix(document): ensure calling `get()` with empty string returns undefined for mongoose-plugin-autoinc #9681
|
|
4
|
+
* fix(model): set `isNew` to false for documents that were successfully inserted by `insertMany` with `ordered = false` when an error occurred #9677
|
|
5
|
+
* fix(index.d.ts): add missing Aggregate#skip() & Aggregate#limit() #9692 [sahasayan](https://github.com/sahasayan)
|
|
6
|
+
* fix(index.d.ts): make `Document#id` optional so types that use `id` can use `Model<IMyType & Document>` #9684
|
|
7
|
+
|
|
8
|
+
5.11.6 / 2020-12-09
|
|
9
|
+
===================
|
|
10
|
+
* fix(middleware): ensure sync errors in pre hooks always bubble up to the calling code #9659
|
|
11
|
+
* fix(index.d.ts): allow passing ObjectId properties as strings to `create()` and `findOneAndReplace()` #9676
|
|
12
|
+
* fix(index.d.ts): allow calling `mongoose.model()` and `Connection#model()` with model as generic param #9685 #9678 [sahasayan](https://github.com/sahasayan)
|
|
13
|
+
* fix(index.d.ts): Fix return type of Model#aggregate() #9680 [orgads](https://github.com/orgads)
|
|
14
|
+
* fix(index.d.ts): optional next() parameter for post middleware #9683 [isengartz](https://github.com/isengartz)
|
|
15
|
+
* fix(index.d.ts): allow array of validators in SchemaTypeOptions #9686 [cjroebuck](https://github.com/cjroebuck)
|
|
16
|
+
|
|
17
|
+
5.11.5 / 2020-12-07
|
|
18
|
+
===================
|
|
19
|
+
* fix(map): support `null` in maps of subdocs #9628
|
|
20
|
+
* fix(index.d.ts): support object syntax for `validate` #9667
|
|
21
|
+
* fix(index.d.ts): Allow number for Schema expires #9670 [alecgibson](https://github.com/alecgibson)
|
|
22
|
+
* fix(index.d.ts): allow definining arbitrary properties on SchemaTypeOpts for plugins like mongoose-autopopulate #9669
|
|
23
|
+
* fix(index.d.ts): add mongoose.models #9661 #9660 [AbdelrahmanHafez](https://github.com/AbdelrahmanHafez)
|
|
24
|
+
* fix(index.d.ts): allow the next() argument to be optional #9665 #9664 [sahasayan](https://github.com/sahasayan)
|
|
25
|
+
* fix(index.d.ts): add missing `VirtualType#applyGetters()` and `applySetters()`, `Schema#virtuals`, `Schema#childSchemas`, `Query#_mongooseOptions` #9658
|
|
26
|
+
* fix(index.d.ts): add `id` to LeanDocuments in case it is defined in the user's schema #9657
|
|
27
|
+
* fix(index.d.ts): add missing types for hook functions #9653
|
|
28
|
+
* fix(index.d.ts): improve support for strict null checks with `upsert` and `orFail()` #9654
|
|
29
|
+
* fix(index.d.ts): make return values for `insertMany()` more consistent #9662
|
|
30
|
+
* fix(index.d.ts): Change options in Connection#collection() to be optional #9663 [orgads](https://github.com/orgads)
|
|
31
|
+
* fix(index.d.ts): add the missing generic declaration for Schema #9655 [sahasayan](https://github.com/sahasayan)
|
|
32
|
+
* fix(index.d.ts): add missing `SchemaTypeOpts` and `ConnectionOptions` aliases for backwards compat
|
|
33
|
+
* docs(populate): remove `sort()` from `limit` example to avoid potential confusion #9584
|
|
34
|
+
* docs(compatibility): add MongoDB server 4.4 version compatibility #9641
|
|
35
|
+
|
|
36
|
+
5.11.4 / 2020-12-04
|
|
37
|
+
===================
|
|
38
|
+
* fix(index.d.ts): add `Document#__v` so documents have a Version by default #9652 [sahasayan](https://github.com/sahasayan)
|
|
39
|
+
* fix(index.d.ts): add missing `session` option to `SaveOptions` #9642
|
|
40
|
+
* fix(index.d.ts): add `Schema#paths`, `Schema#static(obj)`, `Embedded#schema`, `DocumentArray#schema`, make Schema inherit from EventEmitter #9650
|
|
41
|
+
* fix(index.d.ts): order when cb is optional in method #9647 [CatsMiaow](https://github.com/CatsMiaow)
|
|
42
|
+
* fix(index.d.ts): use DocumentDefinition for `FilterQuery` #9649
|
|
43
|
+
* fix(index.d.ts): correct callback result types for `find()`, `findOne()`, `findById()` #9648
|
|
44
|
+
* fix(index.d.ts): remove `Document#parent()` method because it conflicts with existing user code #9645
|
|
45
|
+
* fix(index.d.ts): add missing `Connection#db` property #9643
|
|
46
|
+
* test(typescript): add `tsconfig.json` file for intellisense #9611 [alecgibson](https://github.com/alecgibson)
|
|
47
|
+
|
|
1
48
|
5.11.3 / 2020-12-03
|
|
2
49
|
===================
|
|
3
|
-
* fix(schematype): pass document to default functions as first parameter #9636 #9633 [AbdelrahmanHafez](https://github.com/AbdelrahmanHafez)
|
|
4
50
|
* fix(index.d.ts): make Mongoose collection inherit MongoDB collection #9637 #9630 [AbdelrahmanHafez](https://github.com/AbdelrahmanHafez)
|
|
5
51
|
* fix(index.d.ts): add `Document#_id` so documents have an id by default #9632
|
|
6
52
|
* fix(index.d.ts): allow inline schema definitions for nested properties #9639 [Green-Cat](https://github.com/Green-Cat)
|
package/dist/browser.umd.js
CHANGED
|
@@ -752,11 +752,11 @@ i.set(e.Promise),t.exports=i}).call(this,r(11))},function(t,e,r){"use strict";(f
|
|
|
752
752
|
/*!
|
|
753
753
|
* Module dependencies.
|
|
754
754
|
*/
|
|
755
|
-
function o(t){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var i=r(118).Buffer,s=r(64),a=e.clone=function t(r,n){if(null==r)return r;if(Array.isArray(r))return e.cloneArray(r,n);if(r.constructor){if(/ObjectI[dD]$/.test(r.constructor.name))return"function"==typeof r.clone?r.clone():new r.constructor(r.id);if("ReadPreference"===r.constructor.name)return new r.constructor(r.mode,t(r.tags,n));if("Binary"==r._bsontype&&r.buffer&&r.value)return"function"==typeof r.clone?r.clone():new r.constructor(r.value(!0),r.sub_type);if("Date"===r.constructor.name||"Function"===r.constructor.name)return new r.constructor(+r);if("RegExp"===r.constructor.name)return s(r);if("Buffer"===r.constructor.name)return e.cloneBuffer(r)}return
|
|
755
|
+
function o(t){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var i=r(118).Buffer,s=r(64),a=["__proto__","constructor","prototype"],u=e.clone=function t(r,n){if(null==r)return r;if(Array.isArray(r))return e.cloneArray(r,n);if(r.constructor){if(/ObjectI[dD]$/.test(r.constructor.name))return"function"==typeof r.clone?r.clone():new r.constructor(r.id);if("ReadPreference"===r.constructor.name)return new r.constructor(r.mode,t(r.tags,n));if("Binary"==r._bsontype&&r.buffer&&r.value)return"function"==typeof r.clone?r.clone():new r.constructor(r.value(!0),r.sub_type);if("Date"===r.constructor.name||"Function"===r.constructor.name)return new r.constructor(+r);if("RegExp"===r.constructor.name)return s(r);if("Buffer"===r.constructor.name)return e.cloneBuffer(r)}return l(r)?e.cloneObject(r,n):r.valueOf?r.valueOf():void 0};
|
|
756
756
|
/*!
|
|
757
757
|
* ignore
|
|
758
758
|
*/
|
|
759
|
-
e.cloneObject=function(t,e){var r,n,o,i=e&&e.minimize,s={};for(o in t)n=
|
|
759
|
+
e.cloneObject=function(t,e){var r,n,o,i=e&&e.minimize,s={};for(o in t)-1===a.indexOf(o)&&(n=u(t[o],e),i&&void 0===n||(r||(r=!0),s[o]=n));return i?r&&s:s},e.cloneArray=function(t,e){for(var r=[],n=0,o=t.length;n<o;n++)r.push(u(t[n],e));return r},e.tick=function(t){if("function"==typeof t)return function(){var e=arguments;f((function(){t.apply(this,e)}))}},e.merge=function t(r,n){for(var o,i=Object.keys(n),s=i.length;s--;)o=i[s],-1===a.indexOf(o)&&(void 0===r[o]?r[o]=n[o]:e.isObject(n[o])?t(r[o],n[o]):r[o]=n[o])},e.mergeClone=function t(r,n){for(var o,i=Object.keys(n),s=i.length;s--;)void 0===r[o=i[s]]?r[o]=u(n[o]):e.isObject(n[o])?t(r[o],n[o]):r[o]=u(n[o])},e.readPref=function(t){switch(t){case"p":t="primary";break;case"pp":t="primaryPreferred";break;case"s":t="secondary";break;case"sp":t="secondaryPreferred";break;case"n":t="nearest"}return t},e.readConcern=function(t){if("string"==typeof t){switch(t){case"l":t="local";break;case"a":t="available";break;case"m":t="majority";break;case"lz":t="linearizable";break;case"s":t="snapshot"}t={level:t}}return t};var c=Object.prototype.toString;e.toString=function(t){return c.call(t)};var l=e.isObject=function(t){return"[object Object]"==e.toString(t)};e.isArray=function(t){return Array.isArray(t)||"object"==o(t)&&"[object Array]"==e.toString(t)},e.keys=Object.keys||function(t){var e=[];for(var r in t)t.hasOwnProperty(r)&&e.push(r);return e},e.create="function"==typeof Object.create?Object.create:function(t){if(arguments.length>1)throw new Error("Adding properties is not supported");function e(){}return e.prototype=t,new e},e.inherits=function(t,r){t.prototype=e.create(r.prototype),t.prototype.constructor=t};var f=e.soon="function"==typeof t?t:n.nextTick;e.cloneBuffer=function(t){var e=i.alloc(t.length);return t.copy(e,0,0,t.length),e},e.isArgumentsObject=function(t){return"[object Arguments]"===Object.prototype.toString.call(t)}}).call(this,r(69).setImmediate,r(8))},function(t,e,r){(function(t){var n=void 0!==t&&t||"undefined"!=typeof self&&self||window,o=Function.prototype.apply;function i(t,e){this._id=t,this._clearFn=e}e.setTimeout=function(){return new i(o.call(setTimeout,n,arguments),clearTimeout)},e.setInterval=function(){return new i(o.call(setInterval,n,arguments),clearInterval)},e.clearTimeout=e.clearInterval=function(t){t&&t.close()},i.prototype.unref=i.prototype.ref=function(){},i.prototype.close=function(){this._clearFn.call(n,this._id)},e.enroll=function(t,e){clearTimeout(t._idleTimeoutId),t._idleTimeout=e},e.unenroll=function(t){clearTimeout(t._idleTimeoutId),t._idleTimeout=-1},e._unrefActive=e.active=function(t){clearTimeout(t._idleTimeoutId);var e=t._idleTimeout;e>=0&&(t._idleTimeoutId=setTimeout((function(){t._onTimeout&&t._onTimeout()}),e))},r(117),e.setImmediate="undefined"!=typeof self&&self.setImmediate||void 0!==t&&t.setImmediate||this&&this.setImmediate,e.clearImmediate="undefined"!=typeof self&&self.clearImmediate||void 0!==t&&t.clearImmediate||this&&this.clearImmediate}).call(this,r(11))},function(t,e,r){"use strict";(function(t,r,n,o){function i(t){return(i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}e.isNode=void 0!==t&&"object"==i(r)&&"object"==(void 0===n?"undefined":i(n))&&"function"==typeof o&&t.argv,e.isMongo=!e.isNode&&"function"==typeof printjson&&"function"==typeof ObjectId&&"function"==typeof rs&&"function"==typeof sh,e.isBrowser=!e.isNode&&!e.isMongo&&"undefined"!=typeof window,e.type=e.isNode?"node":e.isMongo?"mongo":e.isBrowser?"browser":"unknown"}).call(this,r(8),r(123)(t),r(11),r(1).Buffer)},function(t,e,r){"use strict";
|
|
760
760
|
/*!
|
|
761
761
|
* Module dependencies.
|
|
762
762
|
*/function n(t){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function o(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function i(t,e){return(i=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function s(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=u(t);if(e){var o=u(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return a(this,r)}}function a(t,e){return!e||"object"!==n(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function u(t){return(u=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var c=r(5),l=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&i(t,e)}(u,t);var e,r,n,a=s(u);function u(t){var e;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,u);var r=t.message;r||(r=c.messages.general.default);var n=f(r,t);return e=a.call(this,n),t=Object.assign({},t,{message:n}),e.properties=t,e.kind=t.type,e.path=t.path,e.value=t.value,e.reason=t.reason,e}
|
|
@@ -1073,7 +1073,7 @@ function s(t){return t}e.get=function(t,r,n,i){var a;"function"==typeof n&&(n.le
|
|
|
1073
1073
|
/*!
|
|
1074
1074
|
* Recursively set nested arrays
|
|
1075
1075
|
*/
|
|
1076
|
-
function t(e,r,n,o,i,s){for(var a,u=0;u<e.length&&u<r.length;++u)a=e[u],Array.isArray(a)&&Array.isArray(r[u])?t(a,r[u],n,o,i,s):a&&(o?o(a,n,s(r[u])):(a[i]&&(a=a[i]),a[n]=s(r[u])))}(d,r,h,l,a,u);else for(v=0;v<d.length;++v)item=d[v],item&&(l?l(item,h,u(r)):(item[a]&&(item=item[a]),item[h]=u(r)));else l?l(d,h,u(r)):d instanceof Map?d.set(h,u(r)):d[h]=u(r)}}},function(t,e,r){"use strict";t.exports=function(t){for(var e=[],r="",n=!1,o=0;o<t.length;++o){if(n&&!/\d/.test(t[o])&&"]"!==t[o])throw new Error('Can only use numbers in square bracket path notation, got character "'+t[o]+'" in path "'+t+'"');"."===t[o]||"["===t[o]||"]"===t[o]?("["===t[o]?n=!0:"]"===t[o]&&(n=!1),r.length>0&&e.push(r),r=""):r+=t[o]}return
|
|
1076
|
+
function t(e,r,n,o,i,s){for(var a,u=0;u<e.length&&u<r.length;++u)a=e[u],Array.isArray(a)&&Array.isArray(r[u])?t(a,r[u],n,o,i,s):a&&(o?o(a,n,s(r[u])):(a[i]&&(a=a[i]),a[n]=s(r[u])))}(d,r,h,l,a,u);else for(v=0;v<d.length;++v)item=d[v],item&&(l?l(item,h,u(r)):(item[a]&&(item=item[a]),item[h]=u(r)));else l?l(d,h,u(r)):d instanceof Map?d.set(h,u(r)):d[h]=u(r)}}},function(t,e,r){"use strict";t.exports=function(t){for(var e=[],r="",n=!1,o=0;o<t.length;++o){if(n&&!/\d/.test(t[o])&&"]"!==t[o])throw new Error('Can only use numbers in square bracket path notation, got character "'+t[o]+'" in path "'+t+'"');"."===t[o]||"["===t[o]||"]"===t[o]?("["===t[o]?n=!0:"]"===t[o]&&(n=!1),r.length>0&&e.push(r),r=""):r+=t[o]}return e.push(r),e}},function(t,e,r){"use strict";function n(t){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var o=r(28);t.exports=function t(e){if(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this._docs={},this._childDocs=[],null!=e&&(e=o(e),Object.assign(this,e),"object"===n(e.subPopulate)&&(this.populate=e.subPopulate),null!=e.perDocumentLimit&&null!=e.limit))throw new Error("Can not use `limit` and `perDocumentLimit` at the same time. Path: `"+e.path+"`.")}},function(t,e,r){"use strict";
|
|
1077
1077
|
/*
|
|
1078
1078
|
object-assign
|
|
1079
1079
|
(c) Sindre Sorhus
|
|
@@ -1201,7 +1201,7 @@ t.exports=u},function(t,e,r){"use strict";var n=r(32);
|
|
|
1201
1201
|
/*!
|
|
1202
1202
|
* exports
|
|
1203
1203
|
*/
|
|
1204
|
-
t.exports=u},function(t,e,r){"use strict";(function(e){function r(t,e){var r;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(r=function(t,e){if(!t)return;if("string"==typeof t)return n(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return n(t,e)}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var o=0,i=function(){};return{s:i,n:function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,a=!0,u=!1;return{s:function(){r=t[Symbol.iterator]()},n:function(){var t=r.next();return a=t.done,t},e:function(t){u=!0,s=t},f:function(){try{a||null==r.return||r.return()}finally{if(u)throw s}}}}function n(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function o(t){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function i(){this._pres=new Map,this._posts=new Map}function s(t,e,r,n,o,i,s){if(i.useErrorHandlers){var a={error:e};return t.execPost(r,n,o,a,(function(t){return"function"==typeof s&&s(t)}))}return"function"==typeof s?s(e):void 0}function a(t,e,r){return t.has(e)?t.get(e):r}function u(t,e,r,n){var o;try{o=t.apply(e,r)}catch(t){return n(t)}c(o)&&o.then((function(){return n()}),(function(t){return n(t)}))}function c(t){return null!=t&&"function"==typeof t.then}function l(t){var r=!1,n=this;return function(){var o=arguments;if(!r)return r=!0,e.nextTick((function(){return t.apply(n,o)}))}}i.prototype.execPre=function(t,r,n,o){3===arguments.length&&(o=n,n=[]);var i=a(this._pres,t,[]),s=i.length,f=i.numAsync||0,p=0,h=f,y=!1,d=n;if(!s)return e.nextTick((function(){o(null)}));var _=function t(){if(!(p>=s)){var n=i[p];if(n.isAsync){var a=[l(m),l((function(t){if(t){if(y)return;return y=!0,o(t)}if(0==--h&&p>=s)return o(null)}))];u(n.fn,r,a,a[0])}else if(n.fn.length>0){a=[l(m)];for(var f=arguments.length>=2?arguments:[null].concat(d),_=1;_<f.length;++_)a.push(f[_]);u(n.fn,r,a,a[0])}else{var v=null
|
|
1204
|
+
t.exports=u},function(t,e,r){"use strict";(function(e){function r(t,e){var r;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(r=function(t,e){if(!t)return;if("string"==typeof t)return n(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return n(t,e)}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var o=0,i=function(){};return{s:i,n:function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}},e:function(t){throw t},f:i}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,a=!0,u=!1;return{s:function(){r=t[Symbol.iterator]()},n:function(){var t=r.next();return a=t.done,t},e:function(t){u=!0,s=t},f:function(){try{a||null==r.return||r.return()}finally{if(u)throw s}}}}function n(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function o(t){return(o="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function i(){this._pres=new Map,this._posts=new Map}function s(t,e,r,n,o,i,s){if(i.useErrorHandlers){var a={error:e};return t.execPost(r,n,o,a,(function(t){return"function"==typeof s&&s(t)}))}return"function"==typeof s?s(e):void 0}function a(t,e,r){return t.has(e)?t.get(e):r}function u(t,e,r,n){var o;try{o=t.apply(e,r)}catch(t){return n(t)}c(o)&&o.then((function(){return n()}),(function(t){return n(t)}))}function c(t){return null!=t&&"function"==typeof t.then}function l(t){var r=!1,n=this;return function(){var o=arguments;if(!r)return r=!0,e.nextTick((function(){return t.apply(n,o)}))}}i.prototype.execPre=function(t,r,n,o){3===arguments.length&&(o=n,n=[]);var i=a(this._pres,t,[]),s=i.length,f=i.numAsync||0,p=0,h=f,y=!1,d=n;if(!s)return e.nextTick((function(){o(null)}));var _=function t(){if(!(p>=s)){var n=i[p];if(n.isAsync){var a=[l(m),l((function(t){if(t){if(y)return;return y=!0,o(t)}if(0==--h&&p>=s)return o(null)}))];u(n.fn,r,a,a[0])}else if(n.fn.length>0){a=[l(m)];for(var f=arguments.length>=2?arguments:[null].concat(d),_=1;_<f.length;++_)a.push(f[_]);u(n.fn,r,a,a[0])}else{var v=null;try{v=n.fn.call(r)}catch(t){if(null!=t)return o(t)}if(c(v))v.then((function(){return m()}),(function(t){return m(t)}));else{if(++p>=s)return h>0?void 0:e.nextTick((function(){o(null)}));t()}}}};function m(t){if(t){if(y)return;return y=!0,o(t)}if(++p>=s)return h>0?void 0:o(null);_.apply(r,arguments)}_.apply(null,[null].concat(n))},i.prototype.execPreSync=function(t,e,r){for(var n=a(this._pres,t,[]),o=n.length,i=0;i<o;++i)n[i].fn.apply(e,r||[])},i.prototype.execPost=function(t,r,n,o,i){arguments.length<5&&(i=o,o=null);var s=a(this._posts,t,[]),f=s.length,p=0,h=null;if(o&&o.error&&(h=o.error),!f)return e.nextTick((function(){i.apply(null,[h].concat(n))}));var y=function t(){for(var e=s[p].fn,o=0,a=n.length,y=[],d=0;d<a;++d)o+=n[d]&&n[d]._kareemIgnore?0:1,n[d]&&n[d]._kareemIgnore||y.push(n[d]);if(h)if(e.length===o+2){var _=l((function(e){if(e&&(h=e),++p>=f)return i.call(null,h);t()}));u(e,r,[h].concat(y).concat([_]),_)}else{if(++p>=f)return i.call(null,h);t()}else{var m=l((function(e){return e?(h=e,t()):++p>=f?i.apply(null,[null].concat(n)):void t()}));if(e.length===o+2)return++p>=f?i.apply(null,[null].concat(n)):t();if(e.length===o+1)u(e,r,y.concat([m]),m);else{var v,g;try{g=e.apply(r,y)}catch(t){v=t,h=t}if(c(g))return g.then((function(){return m()}),(function(t){return m(t)}));if(++p>=f)return i.apply(null,[v].concat(n));t()}}};y()},i.prototype.execPostSync=function(t,e,r){for(var n=a(this._posts,t,[]),o=n.length,i=0;i<o;++i)n[i].fn.apply(e,r||[])},i.prototype.createWrapperSync=function(t,e){var r=this;return function(){r.execPreSync(t,this,arguments);var n=e.apply(this,arguments);return r.execPostSync(t,this,[n]),n}},i.prototype.wrap=function(t,e,r,n,o){var i=n.length>0?n[n.length-1]:null,a=("function"==typeof i&&n.slice(0,n.length-1),this),u=(o=o||{}).checkForPromise;this.execPre(t,r,n,(function(c){if(c){for(var l=o.numCallbackParams||0,f=o.contextParameter?[r]:[],p=f.length;p<l;++p)f.push(null);return s(a,c,t,r,f,o,i)}var h="function"==typeof i?n.length-1:n.length,y=e.length,d=e.apply(r,n.slice(0,h).concat(_));if(u){if(null!=d&&"function"==typeof d.then)return d.then((function(t){return _(null,t)}),(function(t){return _(t)}));if(y<h+1)return _(null,d)}function _(){var e=Array.prototype.slice.call(arguments,1);if(o.nullResultByDefault&&0===e.length&&e.push(null),arguments[0])return s(a,arguments[0],t,r,e,o,i);a.execPost(t,r,e,(function(){return arguments[0]?"function"==typeof i?i(arguments[0]):void 0:"function"==typeof i?i.apply(r,arguments):void 0}))}}))},i.prototype.filter=function(t){for(var e=this,r=this.clone(),n=Array.from(r._pres.keys()),o=function(){var n=s[i],o=e._pres.get(n).map((function(t){return Object.assign({},t,{name:n})})).filter(t);if(0===o.length)return r._pres.delete(n),"continue";o.numAsync=o.filter((function(t){return t.isAsync})).length,r._pres.set(n,o)},i=0,s=n;i<s.length;i++)o();for(var a=Array.from(r._posts.keys()),u=function(){var n=l[c],o=e._posts.get(n).map((function(t){return Object.assign({},t,{name:n})})).filter(t);if(0===o.length)return r._posts.delete(n),"continue";r._posts.set(n,o)},c=0,l=a;c<l.length;c++)u();return r},i.prototype.hasHooks=function(t){return this._pres.has(t)||this._posts.has(t)},i.prototype.createWrapper=function(t,r,n,o){var i=this;return this.hasHooks(t)?function(){var e=n||this,s=Array.prototype.slice.call(arguments);i.wrap(t,r,e,s,o)}:function(){var t=arguments,n=this;e.nextTick((function(){return r.apply(n,t)}))}},i.prototype.pre=function(t,e,r,n,i){var s={};"object"===o(e)&&null!=e?e=(s=e).isAsync:"boolean"!=typeof arguments[1]&&(n=r,r=e,e=!1);var u=a(this._pres,t,[]);if(this._pres.set(t,u),e&&(u.numAsync=u.numAsync||0,++u.numAsync),"function"!=typeof r)throw new Error('pre() requires a function, got "'+o(r)+'"');return i?u.unshift(Object.assign({},s,{fn:r,isAsync:e})):u.push(Object.assign({},s,{fn:r,isAsync:e})),this},i.prototype.post=function(t,e,r,n){var i=a(this._posts,t,[]);if("function"==typeof e&&(n=!!r,r=e,e={}),"function"!=typeof r)throw new Error('post() requires a function, got "'+o(r)+'"');return n?i.unshift(Object.assign({},e,{fn:r})):i.push(Object.assign({},e,{fn:r})),this._posts.set(t,i),this},i.prototype.clone=function(){var t,e=new i,n=r(this._pres.keys());try{for(n.s();!(t=n.n()).done;){var o=t.value,s=this._pres.get(o).slice();s.numAsync=this._pres.get(o).numAsync,e._pres.set(o,s)}}catch(t){n.e(t)}finally{n.f()}var a,u=r(this._posts.keys());try{for(u.s();!(a=u.n()).done;){var c=a.value;e._posts.set(c,this._posts.get(c).slice())}}catch(t){u.e(t)}finally{u.f()}return e},i.prototype.merge=function(t,e){var n,o=(e=1===arguments.length||e)?this.clone():this,i=r(t._pres.keys());try{var s=function(){var e=n.value,r=a(o._pres,e,[]),i=t._pres.get(e).filter((function(t){return-1===r.map((function(t){return t.fn})).indexOf(t.fn)})),s=r.concat(i);s.numAsync=r.numAsync||0,s.numAsync+=i.filter((function(t){return t.isAsync})).length,o._pres.set(e,s)};for(i.s();!(n=i.n()).done;)s()}catch(t){i.e(t)}finally{i.f()}var u,c=r(t._posts.keys());try{var l=function(){var e=u.value,r=a(o._posts,e,[]),n=t._posts.get(e).filter((function(t){return-1===r.indexOf(t)}));o._posts.set(e,r.concat(n))};for(c.s();!(u=c.n()).done;)l()}catch(t){c.e(t)}finally{c.f()}return o},t.exports=i}).call(this,r(8))},function(t,e,r){"use strict";var n=r(10),o=function t(e){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),Object.assign(this,e),null!=e&&null!=e.options&&(this.options=Object.assign({},e.options))};Object.defineProperty(o.prototype,"ref",n),Object.defineProperty(o.prototype,"refPath",n),Object.defineProperty(o.prototype,"localField",n),Object.defineProperty(o.prototype,"foreignField",n),Object.defineProperty(o.prototype,"justOne",n),Object.defineProperty(o.prototype,"count",n),Object.defineProperty(o.prototype,"match",n),Object.defineProperty(o.prototype,"options",n),Object.defineProperty(o.prototype,"skip",n),Object.defineProperty(o.prototype,"limit",n),Object.defineProperty(o.prototype,"perDocumentLimit",n),t.exports=o},function(t,e,r){"use strict";var n=r(3),o=r(21);
|
|
1205
1205
|
/*!
|
|
1206
1206
|
* Gather all indexes defined in the schema, including single nested,
|
|
1207
1207
|
* document arrays, and embedded discriminators.
|
|
@@ -1517,7 +1517,7 @@ t.exports=l}).call(this,r(1).Buffer)},function(t,e,r){"use strict";(function(e){
|
|
|
1517
1517
|
/*!
|
|
1518
1518
|
* ignore
|
|
1519
1519
|
*/
|
|
1520
|
-
function n(t){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function o(t,e){var r;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(r=function(t,e){if(!t)return;if("string"==typeof t)return i(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return i(t,e)}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,a=!0,u=!1;return{s:function(){r=t[Symbol.iterator]()},n:function(){var t=r.next();return a=t.done,t},e:function(t){u=!0,s=t},f:function(){try{a||null==r.return||r.return()}finally{if(u)throw s}}}}function i(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function s(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function a(t,e,r){return(a="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,r){var n=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=f(t)););return t}(t,e);if(n){var o=Object.getOwnPropertyDescriptor(n,e);return o.get?o.get.call(r):o.value}})(t,e,r||t)}function u(t,e){return(u=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function c(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=f(t);if(e){var o=f(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return l(this,r)}}function l(t,e){return!e||"object"!==n(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function f(t){return(f=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var p=r(87),h=r(171),y=r(7),d=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&u(t,e)}(h,t);var r,n,i,l=c(h);function h(t,e){var r;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,h),(r=l.call(this,t,e,"Map")).$isSchemaMap=!0,r}return r=h,(n=[{key:"set",value:function(t,e){return y.set(t,e)}},{key:"cast",value:function(t,r,n){if(t instanceof p)return t;if(n){var i=new p({},this.path,r,this.$__schemaType);if(t instanceof e.Map){var s,a=o(t.keys());try{for(a.s();!(s=a.n()).done;){var u=s.value;i.$
|
|
1520
|
+
function n(t){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function o(t,e){var r;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(r=function(t,e){if(!t)return;if("string"==typeof t)return i(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return i(t,e)}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var s,a=!0,u=!1;return{s:function(){r=t[Symbol.iterator]()},n:function(){var t=r.next();return a=t.done,t},e:function(t){u=!0,s=t},f:function(){try{a||null==r.return||r.return()}finally{if(u)throw s}}}}function i(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function s(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function a(t,e,r){return(a="undefined"!=typeof Reflect&&Reflect.get?Reflect.get:function(t,e,r){var n=function(t,e){for(;!Object.prototype.hasOwnProperty.call(t,e)&&null!==(t=f(t)););return t}(t,e);if(n){var o=Object.getOwnPropertyDescriptor(n,e);return o.get?o.get.call(r):o.value}})(t,e,r||t)}function u(t,e){return(u=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function c(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=f(t);if(e){var o=f(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return l(this,r)}}function l(t,e){return!e||"object"!==n(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function f(t){return(f=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var p=r(87),h=r(171),y=r(7),d=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&u(t,e)}(h,t);var r,n,i,l=c(h);function h(t,e){var r;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,h),(r=l.call(this,t,e,"Map")).$isSchemaMap=!0,r}return r=h,(n=[{key:"set",value:function(t,e){return y.set(t,e)}},{key:"cast",value:function(t,r,n){if(t instanceof p)return t;if(n){var i=new p({},this.path,r,this.$__schemaType);if(t instanceof e.Map){var s,a=o(t.keys());try{for(a.s();!(s=a.n()).done;){var u=s.value,c=t.get(u);c=null==c?i.$__schemaType._castNullish(c):i.$__schemaType.cast(c,r,!0),i.$init(u,c)}}catch(t){a.e(t)}finally{a.f()}}else for(var l=0,f=Object.keys(t);l<f.length;l++){var h=f[l],y=t[h];y=null==y?i.$__schemaType._castNullish(y):i.$__schemaType.cast(y,r,!0),i.$init(h,y)}return i}return new p(t,this.path,r,this.$__schemaType)}},{key:"clone",value:function(){var t=a(f(h.prototype),"clone",this).call(this);return null!=this.$__schemaType&&(t.$__schemaType=this.$__schemaType.clone()),t}}])&&s(r.prototype,n),i&&s(r,i),h}(y);d.prototype.OptionsConstructor=h,d.defaultOptions={},t.exports=d}).call(this,r(11))},function(t,e,r){"use strict";function n(t){return(n="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function o(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function i(t,e){return(i=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function s(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=u(t);if(e){var o=u(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return a(this,r)}}function a(t,e){return!e||"object"!==n(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function u(t){return(u=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}var c=function(t){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&i(t,e)}(r,t);var e=s(r);function r(){return o(this,r),e.apply(this,arguments)}return r}(r(9)),l=r(10);Object.defineProperty(c.prototype,"of",l),t.exports=c},function(t,e,r){"use strict";(function(t){
|
|
1521
1521
|
/*!
|
|
1522
1522
|
* Module dependencies.
|
|
1523
1523
|
*/
|
package/index.d.ts
CHANGED
|
@@ -72,6 +72,8 @@ declare module "mongoose" {
|
|
|
72
72
|
/** An array containing all connections associated with this Mongoose instance. */
|
|
73
73
|
export var connections: Connection[];
|
|
74
74
|
|
|
75
|
+
/** An array containing all models associated with this Mongoose instance. */
|
|
76
|
+
export var models: { [index: string]: Model<any> };
|
|
75
77
|
/** Creates a Connection instance. */
|
|
76
78
|
export function createConnection(uri: string, options?: ConnectOptions): Connection & Promise<Connection>;
|
|
77
79
|
export function createConnection(): Connection;
|
|
@@ -97,6 +99,12 @@ declare module "mongoose" {
|
|
|
97
99
|
export function isValidObjectId(v: any): boolean;
|
|
98
100
|
|
|
99
101
|
export function model<T extends Document>(name: string, schema?: Schema, collection?: string, skipInit?: boolean): Model<T>;
|
|
102
|
+
export function model<T extends Document, U extends Model<T>>(
|
|
103
|
+
name: string,
|
|
104
|
+
schema?: Schema,
|
|
105
|
+
collection?: string,
|
|
106
|
+
skipInit?: boolean
|
|
107
|
+
): U;
|
|
100
108
|
|
|
101
109
|
/** Returns an array of model names created on this instance of Mongoose. */
|
|
102
110
|
export function modelNames(): Array<string>;
|
|
@@ -163,7 +171,7 @@ declare module "mongoose" {
|
|
|
163
171
|
close(force?: boolean): Promise<void>;
|
|
164
172
|
|
|
165
173
|
/** Retrieves a collection, creating it if not cached. */
|
|
166
|
-
collection(name: string, options
|
|
174
|
+
collection(name: string, options?: mongodb.CollectionCreateOptions): Collection;
|
|
167
175
|
|
|
168
176
|
/** A hash of the collections associated with this connection */
|
|
169
177
|
collections: { [index: string]: Collection };
|
|
@@ -171,6 +179,9 @@ declare module "mongoose" {
|
|
|
171
179
|
/** A hash of the global options that are associated with this connection */
|
|
172
180
|
config: any;
|
|
173
181
|
|
|
182
|
+
/** The mongodb.Db instance, set when the connection is opened */
|
|
183
|
+
db: mongodb.Db;
|
|
184
|
+
|
|
174
185
|
/**
|
|
175
186
|
* Helper for `createCollection()`. Will explicitly create the given collection
|
|
176
187
|
* with specified options. Used to create [capped collections](https://docs.mongodb.com/manual/core/capped-collections/)
|
|
@@ -231,6 +242,12 @@ declare module "mongoose" {
|
|
|
231
242
|
|
|
232
243
|
/** Defines or retrieves a model. */
|
|
233
244
|
model<T extends Document>(name: string, schema?: Schema, collection?: string): Model<T>;
|
|
245
|
+
model<T extends Document, U extends Model<T>>(
|
|
246
|
+
name: string,
|
|
247
|
+
schema?: Schema,
|
|
248
|
+
collection?: string,
|
|
249
|
+
skipInit?: boolean
|
|
250
|
+
): U;
|
|
234
251
|
|
|
235
252
|
/** Returns an array of model names created on this connection. */
|
|
236
253
|
modelNames(): Array<string>;
|
|
@@ -260,7 +277,7 @@ declare module "mongoose" {
|
|
|
260
277
|
|
|
261
278
|
/**
|
|
262
279
|
* Connection ready state
|
|
263
|
-
*
|
|
280
|
+
*
|
|
264
281
|
* - 0 = disconnected
|
|
265
282
|
* - 1 = connected
|
|
266
283
|
* - 2 = connecting
|
|
@@ -352,6 +369,9 @@ declare module "mongoose" {
|
|
|
352
369
|
/** This documents _id. */
|
|
353
370
|
_id?: any;
|
|
354
371
|
|
|
372
|
+
/** This documents __v. */
|
|
373
|
+
__v?: number;
|
|
374
|
+
|
|
355
375
|
/** Don't run validation on this path or persist changes to this path. */
|
|
356
376
|
$ignore(path: string): void;
|
|
357
377
|
|
|
@@ -412,12 +432,12 @@ declare module "mongoose" {
|
|
|
412
432
|
db: Connection;
|
|
413
433
|
|
|
414
434
|
/** Removes this document from the db. */
|
|
415
|
-
delete(options?: QueryOptions, cb?: (err: CallbackError, res: any) => void): void;
|
|
416
435
|
delete(options?: QueryOptions): Query<any, this>;
|
|
436
|
+
delete(options?: QueryOptions, cb?: (err: CallbackError, res: any) => void): void;
|
|
417
437
|
|
|
418
438
|
/** Removes this document from the db. */
|
|
419
|
-
deleteOne(options?: QueryOptions, cb?: (err: CallbackError, res: any) => void): void;
|
|
420
439
|
deleteOne(options?: QueryOptions): Query<any, this>;
|
|
440
|
+
deleteOne(options?: QueryOptions, cb?: (err: CallbackError, res: any) => void): void;
|
|
421
441
|
|
|
422
442
|
/** Takes a populated field and returns it to its unpopulated state. */
|
|
423
443
|
depopulate(path: string): this;
|
|
@@ -455,7 +475,7 @@ declare module "mongoose" {
|
|
|
455
475
|
getChanges(): UpdateQuery<this>;
|
|
456
476
|
|
|
457
477
|
/** The string version of this documents _id. */
|
|
458
|
-
id
|
|
478
|
+
id?: string;
|
|
459
479
|
|
|
460
480
|
/** Signal that we desire an increment of this documents version. */
|
|
461
481
|
increment(): this;
|
|
@@ -510,9 +530,6 @@ declare module "mongoose" {
|
|
|
510
530
|
*/
|
|
511
531
|
overwrite(obj: DocumentDefinition<this>): this;
|
|
512
532
|
|
|
513
|
-
/** If this document is a subdocument or populated document, returns the document's parent. Returns `undefined` otherwise. */
|
|
514
|
-
parent(): Document | undefined;
|
|
515
|
-
|
|
516
533
|
/**
|
|
517
534
|
* Populates document references, executing the `callback` when complete.
|
|
518
535
|
* If you want to use promises instead, use this function with
|
|
@@ -525,8 +542,8 @@ declare module "mongoose" {
|
|
|
525
542
|
populated(path: string): any;
|
|
526
543
|
|
|
527
544
|
/** Removes this document from the db. */
|
|
528
|
-
remove(options?: QueryOptions, cb?: (err: CallbackError, res: any) => void): void;
|
|
529
545
|
remove(options?: QueryOptions): Query<any, this>;
|
|
546
|
+
remove(options?: QueryOptions, cb?: (err: CallbackError, res: any) => void): void;
|
|
530
547
|
|
|
531
548
|
/** Sends a replaceOne command with this document `_id` as the query selector. */
|
|
532
549
|
replaceOne(replacement?: DocumentDefinition<this>, options?: QueryOptions | null, callback?: (err: any, res: any) => void): Query<any, this>;
|
|
@@ -573,8 +590,8 @@ declare module "mongoose" {
|
|
|
573
590
|
interface Model<T extends Document> extends NodeJS.EventEmitter {
|
|
574
591
|
new(doc?: any): T;
|
|
575
592
|
|
|
576
|
-
aggregate<R>(pipeline?: any[]): Aggregate<Array<R>>;
|
|
577
|
-
aggregate<R>(pipeline: any[], cb: Function): Promise<Array<R>>;
|
|
593
|
+
aggregate<R = any>(pipeline?: any[]): Aggregate<Array<R>>;
|
|
594
|
+
aggregate<R = any>(pipeline: any[], cb: Function): Promise<Array<R>>;
|
|
578
595
|
|
|
579
596
|
/** Base Mongoose instance the model uses. */
|
|
580
597
|
base: typeof mongoose;
|
|
@@ -592,8 +609,8 @@ declare module "mongoose" {
|
|
|
592
609
|
* if you use `create()`) because with `bulkWrite()` there is only one round
|
|
593
610
|
* trip to MongoDB.
|
|
594
611
|
*/
|
|
595
|
-
bulkWrite(writes: Array<any>, options?: mongodb.CollectionBulkWriteOptions, cb?: (err: any, res: mongodb.BulkWriteOpResultObject) => void): void;
|
|
596
612
|
bulkWrite(writes: Array<any>, options?: mongodb.CollectionBulkWriteOptions): Promise<mongodb.BulkWriteOpResultObject>;
|
|
613
|
+
bulkWrite(writes: Array<any>, options?: mongodb.CollectionBulkWriteOptions, cb?: (err: any, res: mongodb.BulkWriteOpResultObject) => void): void;
|
|
597
614
|
|
|
598
615
|
/** Collection the model uses. */
|
|
599
616
|
collection: Collection;
|
|
@@ -663,10 +680,10 @@ declare module "mongoose" {
|
|
|
663
680
|
* equivalent to `findOne({ _id: id })`. If you want to query by a document's
|
|
664
681
|
* `_id`, use `findById()` instead of `findOne()`.
|
|
665
682
|
*/
|
|
666
|
-
findById(id: any, projection?: any | null, options?: QueryOptions | null, callback?: (err: CallbackError,
|
|
683
|
+
findById(id: any, projection?: any | null, options?: QueryOptions | null, callback?: (err: CallbackError, doc: T | null) => void): Query<T | null, T>;
|
|
667
684
|
|
|
668
685
|
/** Finds one document. */
|
|
669
|
-
findOne(filter?: FilterQuery<T>, projection?: any | null, options?: QueryOptions | null, callback?: (err: CallbackError,
|
|
686
|
+
findOne(filter?: FilterQuery<T>, projection?: any | null, options?: QueryOptions | null, callback?: (err: CallbackError, doc: T | null) => void): Query<T | null, T>;
|
|
670
687
|
|
|
671
688
|
/**
|
|
672
689
|
* Shortcut for creating a new Document from existing raw data, pre-saved in the DB.
|
|
@@ -685,8 +702,10 @@ declare module "mongoose" {
|
|
|
685
702
|
init(callback?: (err: any) => void): Promise<T>;
|
|
686
703
|
|
|
687
704
|
/** Inserts one or more new documents as a single `insertMany` call to the MongoDB server. */
|
|
688
|
-
insertMany(doc: T | DocumentDefinition<T>, options
|
|
689
|
-
insertMany(
|
|
705
|
+
insertMany(doc: T | DocumentDefinition<T>, options: InsertManyOptions & { rawResult: true }): Promise<InsertManyResult>;
|
|
706
|
+
insertMany(doc: T | DocumentDefinition<T>, options?: InsertManyOptions): Promise<T>;
|
|
707
|
+
insertMany(docs: Array<T | DocumentDefinition<T>>, options: InsertManyOptions & { rawResult: true }): Promise<InsertManyResult>;
|
|
708
|
+
insertMany(docs: Array<T | DocumentDefinition<T>>, options?: InsertManyOptions): Promise<Array<T>>;
|
|
690
709
|
insertMany(doc: T | DocumentDefinition<T>, options?: InsertManyOptions, callback?: (err: CallbackError, res: T | InsertManyResult) => void): void;
|
|
691
710
|
insertMany(docs: Array<T | DocumentDefinition<T>>, options?: InsertManyOptions, callback?: (err: CallbackError, res: Array<T> | InsertManyResult) => void): void;
|
|
692
711
|
|
|
@@ -699,6 +718,10 @@ declare module "mongoose" {
|
|
|
699
718
|
listIndexes(callback: (err: CallbackError, res: Array<any>) => void): void;
|
|
700
719
|
listIndexes(): Promise<Array<any>>;
|
|
701
720
|
|
|
721
|
+
/** The name of the model */
|
|
722
|
+
modelName: string;
|
|
723
|
+
|
|
724
|
+
/** Populates document references. */
|
|
702
725
|
populate(docs: Array<any>, options: PopulateOptions | Array<PopulateOptions> | string,
|
|
703
726
|
callback?: (err: any, res: T[]) => void): Promise<Array<T>>;
|
|
704
727
|
|
|
@@ -751,9 +774,9 @@ declare module "mongoose" {
|
|
|
751
774
|
exists(filter: FilterQuery<T>, callback: (err: any, res: boolean) => void): void;
|
|
752
775
|
|
|
753
776
|
/** Creates a `find` query: gets a list of documents that match `filter`. */
|
|
754
|
-
find(callback?: (err: any,
|
|
755
|
-
find(filter: FilterQuery<T>, callback?: (err: any,
|
|
756
|
-
find(filter: FilterQuery<T>, projection?: any | null, options?: QueryOptions | null, callback?: (err: any,
|
|
777
|
+
find(callback?: (err: any, docs: T[]) => void): Query<Array<T>, T>;
|
|
778
|
+
find(filter: FilterQuery<T>, callback?: (err: any, docs: T[]) => void): Query<Array<T>, T>;
|
|
779
|
+
find(filter: FilterQuery<T>, projection?: any | null, options?: QueryOptions | null, callback?: (err: any, docs: T[]) => void): Query<Array<T>, T>;
|
|
757
780
|
|
|
758
781
|
/** Creates a `findByIdAndDelete` query, filtering by the given `_id`. */
|
|
759
782
|
findByIdAndDelete(id?: mongodb.ObjectId | any, options?: QueryOptions | null, callback?: (err: any, doc: T | null, res: any) => void): Query<T | null, T>;
|
|
@@ -762,6 +785,7 @@ declare module "mongoose" {
|
|
|
762
785
|
findByIdAndRemove(id?: mongodb.ObjectId | any, options?: QueryOptions | null, callback?: (err: any, doc: T | null, res: any) => void): Query<T | null, T>;
|
|
763
786
|
|
|
764
787
|
/** Creates a `findOneAndUpdate` query, filtering by the given `_id`. */
|
|
788
|
+
findByIdAndUpdate(id: mongodb.ObjectId | any, update: UpdateQuery<T>, options: QueryOptions & { upsert: true }, callback?: (err: any, doc: T, res: any) => void): Query<T, T>;
|
|
765
789
|
findByIdAndUpdate(id?: mongodb.ObjectId | any, update?: UpdateQuery<T>, options?: QueryOptions | null, callback?: (err: any, doc: T | null, res: any) => void): Query<T | null, T>;
|
|
766
790
|
|
|
767
791
|
/** Creates a `findOneAndDelete` query: atomically finds the given document, deletes it, and returns the document as it was before deletion. */
|
|
@@ -771,9 +795,11 @@ declare module "mongoose" {
|
|
|
771
795
|
findOneAndRemove(filter?: FilterQuery<T>, options?: QueryOptions | null, callback?: (err: any, doc: T | null, res: any) => void): Query<T | null, T>;
|
|
772
796
|
|
|
773
797
|
/** Creates a `findOneAndReplace` query: atomically finds the given document and replaces it with `replacement`. */
|
|
798
|
+
findOneAndReplace(filter: FilterQuery<T>, replacement: DocumentDefinition<T>, options: QueryOptions & { upsert: true }, callback?: (err: any, doc: T, res: any) => void): Query<T, T>;
|
|
774
799
|
findOneAndReplace(filter?: FilterQuery<T>, replacement?: DocumentDefinition<T>, options?: QueryOptions | null, callback?: (err: any, doc: T | null, res: any) => void): Query<T | null, T>;
|
|
775
800
|
|
|
776
801
|
/** Creates a `findOneAndUpdate` query: atomically find the first document that matches `filter` and apply `update`. */
|
|
802
|
+
findOneAndUpdate(filter: FilterQuery<T>, update: UpdateQuery<T>, options: QueryOptions & { upsert: true }, callback?: (err: any, doc: T, res: any) => void): Query<T, T>;
|
|
777
803
|
findOneAndUpdate(filter?: FilterQuery<T>, update?: UpdateQuery<T>, options?: QueryOptions | null, callback?: (err: any, doc: T | null, res: any) => void): Query<T | null, T>;
|
|
778
804
|
|
|
779
805
|
geoSearch(filter?: FilterQuery<T>, options?: GeoSearchOptions, callback?: (err: CallbackError, res: Array<T>) => void): Query<Array<T>, T>;
|
|
@@ -793,6 +819,7 @@ declare module "mongoose" {
|
|
|
793
819
|
schema: Schema;
|
|
794
820
|
|
|
795
821
|
/** Creates a `findOneAndReplace` query: atomically finds the given document and replaces it with `replacement`. */
|
|
822
|
+
findOneAndReplace(filter: FilterQuery<T>, replacement: DocumentDefinition<T>, options: QueryOptions & { upsert: true }, callback?: (err: any, doc: T, res: any) => void): Query<T, T>;
|
|
796
823
|
findOneAndReplace(filter?: FilterQuery<T>, replacement?: DocumentDefinition<T>, options?: QueryOptions | null, callback?: (err: any, doc: T | null, res: any) => void): Query<T | null, T>;
|
|
797
824
|
|
|
798
825
|
/** Creates a `update` query: updates one or many documents that match `filter` with `update`, based on the `multi` option. */
|
|
@@ -867,18 +894,16 @@ declare module "mongoose" {
|
|
|
867
894
|
writeConcern?: any;
|
|
868
895
|
}
|
|
869
896
|
|
|
870
|
-
/** Alias for QueryOptions for backwards compatability. */
|
|
871
|
-
type ModelUpdateOptions = QueryOptions;
|
|
872
|
-
|
|
873
897
|
interface SaveOptions {
|
|
874
898
|
checkKeys?: boolean;
|
|
899
|
+
j?: boolean;
|
|
900
|
+
safe?: boolean | WriteConcern;
|
|
901
|
+
session?: ClientSession | null;
|
|
902
|
+
timestamps?: boolean;
|
|
875
903
|
validateBeforeSave?: boolean;
|
|
876
904
|
validateModifiedOnly?: boolean;
|
|
877
|
-
timestamps?: boolean;
|
|
878
|
-
j?: boolean;
|
|
879
905
|
w?: number | string;
|
|
880
906
|
wtimeout?: number;
|
|
881
|
-
safe?: boolean | WriteConcern;
|
|
882
907
|
}
|
|
883
908
|
|
|
884
909
|
interface WriteConcern {
|
|
@@ -997,7 +1022,7 @@ declare module "mongoose" {
|
|
|
997
1022
|
useProjection?: boolean;
|
|
998
1023
|
}
|
|
999
1024
|
|
|
1000
|
-
class Schema {
|
|
1025
|
+
class Schema<T = any> extends events.EventEmitter {
|
|
1001
1026
|
/**
|
|
1002
1027
|
* Create a new schema
|
|
1003
1028
|
*/
|
|
@@ -1006,9 +1031,19 @@ declare module "mongoose" {
|
|
|
1006
1031
|
/** Adds key path / schema type pairs to this schema. */
|
|
1007
1032
|
add(obj: SchemaDefinition | Schema, prefix?: string): this;
|
|
1008
1033
|
|
|
1034
|
+
/**
|
|
1035
|
+
* Array of child schemas (from document arrays and single nested subdocs)
|
|
1036
|
+
* and their corresponding compiled models. Each element of the array is
|
|
1037
|
+
* an object with 2 properties: `schema` and `model`.
|
|
1038
|
+
*/
|
|
1039
|
+
childSchemas: { schema: Schema, model: any }[];
|
|
1040
|
+
|
|
1009
1041
|
/** Returns a copy of this schema */
|
|
1010
1042
|
clone(): Schema;
|
|
1011
1043
|
|
|
1044
|
+
/** Object containing discriminators defined on this schema */
|
|
1045
|
+
discriminators?: { [name: string]: Schema };
|
|
1046
|
+
|
|
1012
1047
|
/** Iterates the schemas paths similar to Array#forEach. */
|
|
1013
1048
|
eachPath(fn: (path: string, type: SchemaType) => void): this;
|
|
1014
1049
|
|
|
@@ -1047,6 +1082,11 @@ declare module "mongoose" {
|
|
|
1047
1082
|
path(path: string): SchemaType;
|
|
1048
1083
|
path(path: string, constructor: any): this;
|
|
1049
1084
|
|
|
1085
|
+
/** Lists all paths and their type in the schema. */
|
|
1086
|
+
paths: {
|
|
1087
|
+
[key: string]: SchemaType;
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1050
1090
|
/** Returns the pathType of `path` for this schema. */
|
|
1051
1091
|
pathType(path: string): string;
|
|
1052
1092
|
|
|
@@ -1054,18 +1094,18 @@ declare module "mongoose" {
|
|
|
1054
1094
|
plugin(fn: (schema: Schema, opts?: any) => void, opts?: any): this;
|
|
1055
1095
|
|
|
1056
1096
|
/** Defines a post hook for the model. */
|
|
1057
|
-
post<T extends Document = Document>(method: "validate" | "save" | "remove" | "updateOne" | "deleteOne" | "init" | RegExp, fn: (this: T, res: any, next: (err
|
|
1097
|
+
post<T extends Document = Document>(method: "validate" | "save" | "remove" | "updateOne" | "deleteOne" | "init" | RegExp, fn: (this: T, res: any, next: (err?: CallbackError) => void) => void): this;
|
|
1058
1098
|
post<T extends Query<any, any> = Query<any, any>>(method: string | RegExp, fn: (this: T, res: any, next: (err: CallbackError) => void) => void): this;
|
|
1059
1099
|
post<T extends Aggregate<any> = Aggregate<any>>(method: "aggregate" | RegExp, fn: (this: T, res: Array<any>, next: (err: CallbackError) => void) => void): this;
|
|
1060
1100
|
post<T extends Model<any> = Model<any>>(method: "insertMany" | RegExp, fn: (this: T, res: any, next: (err: CallbackError) => void) => void): this;
|
|
1061
1101
|
|
|
1062
|
-
post<T extends Document = Document>(method: "validate" | "save" | "remove" | "updateOne" | "deleteOne" | "init" | RegExp, fn: (this: T, err: NativeError, res: any, next: (err
|
|
1102
|
+
post<T extends Document = Document>(method: "validate" | "save" | "remove" | "updateOne" | "deleteOne" | "init" | RegExp, fn: (this: T, err: NativeError, res: any, next: (err?: CallbackError) => void) => void): this;
|
|
1063
1103
|
post<T extends Query<any, any> = Query<any, any>>(method: string | RegExp, fn: (this: T, err: NativeError, res: any, next: (err: CallbackError) => void) => void): this;
|
|
1064
1104
|
post<T extends Aggregate<any> = Aggregate<any>>(method: "aggregate" | RegExp, fn: (this: T, err: NativeError, res: Array<any>, next: (err: CallbackError) => void) => void): this;
|
|
1065
1105
|
post<T extends Model<any> = Model<any>>(method: "insertMany" | RegExp, fn: (this: T, err: NativeError, res: any, next: (err: CallbackError) => void) => void): this;
|
|
1066
1106
|
|
|
1067
1107
|
/** Defines a pre hook for the model. */
|
|
1068
|
-
pre<T extends Document = Document>(method: "validate" | "save" | "remove" | "updateOne" | "deleteOne" | "init" | RegExp, fn: (this: T, next: (err
|
|
1108
|
+
pre<T extends Document = Document>(method: "validate" | "save" | "remove" | "updateOne" | "deleteOne" | "init" | RegExp, fn: (this: T, next: (err?: CallbackError) => void) => void): this;
|
|
1069
1109
|
pre<T extends Query<any, any> = Query<any, any>>(method: string | RegExp, fn: (this: T, next: (err: CallbackError) => void) => void): this;
|
|
1070
1110
|
pre<T extends Aggregate<any> = Aggregate<any>>(method: "aggregate" | RegExp, fn: (this: T, next: (err: CallbackError) => void) => void): this;
|
|
1071
1111
|
pre<T extends Model<any> = Model<any>>(method: "insertMany" | RegExp, fn: (this: T, next: (err: CallbackError) => void) => void): this;
|
|
@@ -1087,6 +1127,7 @@ declare module "mongoose" {
|
|
|
1087
1127
|
|
|
1088
1128
|
/** Adds static "class" methods to Models compiled from this schema. */
|
|
1089
1129
|
static(name: string, fn: Function): this;
|
|
1130
|
+
static(obj: { [name: string]: Function }): this;
|
|
1090
1131
|
|
|
1091
1132
|
/** Object of currently defined statics on this schema. */
|
|
1092
1133
|
statics: any;
|
|
@@ -1094,6 +1135,9 @@ declare module "mongoose" {
|
|
|
1094
1135
|
/** Creates a virtual type with the given name. */
|
|
1095
1136
|
virtual(name: string, options?: any): VirtualType;
|
|
1096
1137
|
|
|
1138
|
+
/** Object of currently defined virtuals on this schema */
|
|
1139
|
+
virtuals: any;
|
|
1140
|
+
|
|
1097
1141
|
/** Returns the virtual type with the given `name`. */
|
|
1098
1142
|
virtualpath(name: string): VirtualType | null;
|
|
1099
1143
|
}
|
|
@@ -1271,7 +1315,7 @@ declare module "mongoose" {
|
|
|
1271
1315
|
alias?: string;
|
|
1272
1316
|
|
|
1273
1317
|
/** Function or object describing how to validate this schematype. See [validation docs](https://mongoosejs.com/docs/validation.html). */
|
|
1274
|
-
validate?: RegExp | [RegExp, string] | Function | [Function , string];
|
|
1318
|
+
validate?: RegExp | [RegExp, string] | Function | [Function , string] | ValidateOpts<T> | ValidateOpts<T>[];
|
|
1275
1319
|
|
|
1276
1320
|
/** Allows overriding casting logic for this individual path. If a string, the given string overwrites Mongoose's default cast error message. */
|
|
1277
1321
|
cast?: string;
|
|
@@ -1357,7 +1401,7 @@ declare module "mongoose" {
|
|
|
1357
1401
|
max?: number | Date;
|
|
1358
1402
|
|
|
1359
1403
|
/** Defines a TTL index on this path. Only allowed for dates. */
|
|
1360
|
-
expires?: Date;
|
|
1404
|
+
expires?: number | Date;
|
|
1361
1405
|
|
|
1362
1406
|
/** If `true`, Mongoose will skip gathering indexes on subpaths. Only allowed for subdocuments and subdocument arrays. */
|
|
1363
1407
|
excludeIndexes?: boolean;
|
|
@@ -1388,6 +1432,8 @@ declare module "mongoose" {
|
|
|
1388
1432
|
|
|
1389
1433
|
/** If set, Mongoose will add a custom validator that ensures the given string's `length` is at most the given number. */
|
|
1390
1434
|
maxlength?: number | [number, string];
|
|
1435
|
+
|
|
1436
|
+
[other: string]: any;
|
|
1391
1437
|
}
|
|
1392
1438
|
|
|
1393
1439
|
interface IndexOptions {
|
|
@@ -1398,7 +1444,31 @@ declare module "mongoose" {
|
|
|
1398
1444
|
unique?: boolean
|
|
1399
1445
|
}
|
|
1400
1446
|
|
|
1447
|
+
interface ValidateFn<T> {
|
|
1448
|
+
(value: T): boolean;
|
|
1449
|
+
}
|
|
1450
|
+
|
|
1451
|
+
interface LegacyAsyncValidateFn<T> {
|
|
1452
|
+
(value: T, done: (result: boolean) => void): void;
|
|
1453
|
+
}
|
|
1454
|
+
|
|
1455
|
+
interface AsyncValidateFn<T> {
|
|
1456
|
+
(value: any): Promise<boolean>;
|
|
1457
|
+
}
|
|
1458
|
+
|
|
1459
|
+
interface ValidateOpts<T> {
|
|
1460
|
+
msg?: string;
|
|
1461
|
+
message?: string;
|
|
1462
|
+
type?: string;
|
|
1463
|
+
validator: ValidateFn<T> | LegacyAsyncValidateFn<T> | AsyncValidateFn<T>;
|
|
1464
|
+
}
|
|
1465
|
+
|
|
1401
1466
|
class VirtualType {
|
|
1467
|
+
/** Applies getters to `value`. */
|
|
1468
|
+
applyGetters(value: any, doc: Document): any;
|
|
1469
|
+
/** Applies setters to `value`. */
|
|
1470
|
+
applySetters(value: any, doc: Document): any;
|
|
1471
|
+
|
|
1402
1472
|
/** Adds a custom getter to this virtual. */
|
|
1403
1473
|
get(fn: Function): this;
|
|
1404
1474
|
/** Adds a custom setter to this virtual. */
|
|
@@ -1470,6 +1540,9 @@ declare module "mongoose" {
|
|
|
1470
1540
|
static options: { castNonArrays: boolean; };
|
|
1471
1541
|
|
|
1472
1542
|
discriminator(name: string, schema: Schema, tag?: string): any;
|
|
1543
|
+
|
|
1544
|
+
/** The schema used for documents in this array */
|
|
1545
|
+
schema: Schema;
|
|
1473
1546
|
}
|
|
1474
1547
|
|
|
1475
1548
|
class Map extends SchemaType {
|
|
@@ -1507,6 +1580,9 @@ declare module "mongoose" {
|
|
|
1507
1580
|
class Embedded extends SchemaType {
|
|
1508
1581
|
/** This schema type's name, to defend against minifiers that mangle function names. */
|
|
1509
1582
|
static schemaName: string;
|
|
1583
|
+
|
|
1584
|
+
/** The document's schema */
|
|
1585
|
+
schema: Schema;
|
|
1510
1586
|
}
|
|
1511
1587
|
|
|
1512
1588
|
class String extends SchemaType {
|
|
@@ -1647,6 +1723,8 @@ declare module "mongoose" {
|
|
|
1647
1723
|
}
|
|
1648
1724
|
|
|
1649
1725
|
interface Query<ResultType, DocType extends Document> {
|
|
1726
|
+
_mongooseOptions: QueryOptions;
|
|
1727
|
+
|
|
1650
1728
|
exec(): Promise<ResultType>;
|
|
1651
1729
|
exec(callback?: (err: CallbackError, res: ResultType) => void): void;
|
|
1652
1730
|
|
|
@@ -1749,12 +1827,12 @@ declare module "mongoose" {
|
|
|
1749
1827
|
explain(verbose?: string): this;
|
|
1750
1828
|
|
|
1751
1829
|
/** Creates a `find` query: gets a list of documents that match `filter`. */
|
|
1752
|
-
find(callback?: (err: any,
|
|
1753
|
-
find(filter: FilterQuery<DocType>, callback?: (err: any,
|
|
1754
|
-
find(filter: FilterQuery<DocType>, projection?: any | null, options?: QueryOptions | null, callback?: (err: CallbackError,
|
|
1830
|
+
find(callback?: (err: any, docs: DocType[]) => void): Query<Array<DocType>, DocType>;
|
|
1831
|
+
find(filter: FilterQuery<DocType>, callback?: (err: any, docs: DocType[]) => void): Query<Array<DocType>, DocType>;
|
|
1832
|
+
find(filter: FilterQuery<DocType>, projection?: any | null, options?: QueryOptions | null, callback?: (err: CallbackError, docs: DocType[]) => void): Query<Array<DocType>, DocType>;
|
|
1755
1833
|
|
|
1756
1834
|
/** Declares the query a findOne operation. When executed, the first found document is passed to the callback. */
|
|
1757
|
-
findOne(filter?: FilterQuery<DocType>, projection?: any | null, options?: QueryOptions | null, callback?: (err: CallbackError,
|
|
1835
|
+
findOne(filter?: FilterQuery<DocType>, projection?: any | null, options?: QueryOptions | null, callback?: (err: CallbackError, doc: DocType | null) => void): Query<DocType | null, DocType>;
|
|
1758
1836
|
|
|
1759
1837
|
/** Creates a `findOneAndDelete` query: atomically finds the given document, deletes it, and returns the document as it was before deletion. */
|
|
1760
1838
|
findOneAndDelete(filter?: FilterQuery<DocType>, options?: QueryOptions | null, callback?: (err: any, doc: DocType | null, res: any) => void): Query<DocType | null, DocType>;
|
|
@@ -1763,12 +1841,14 @@ declare module "mongoose" {
|
|
|
1763
1841
|
findOneAndRemove(filter?: FilterQuery<DocType>, options?: QueryOptions | null, callback?: (err: any, doc: DocType | null, res: any) => void): Query<DocType | null, DocType>;
|
|
1764
1842
|
|
|
1765
1843
|
/** Creates a `findOneAndUpdate` query: atomically find the first document that matches `filter` and apply `update`. */
|
|
1844
|
+
findOneAndUpdate(filter: FilterQuery<DocType>, update: UpdateQuery<DocType>, options: QueryOptions & { upsert: true }, callback?: (err: any, doc: DocType, res: any) => void): Query<DocType, DocType>;
|
|
1766
1845
|
findOneAndUpdate(filter?: FilterQuery<DocType>, update?: UpdateQuery<DocType>, options?: QueryOptions | null, callback?: (err: any, doc: DocType | null, res: any) => void): Query<DocType | null, DocType>;
|
|
1767
1846
|
|
|
1768
1847
|
/** Creates a `findByIdAndDelete` query, filtering by the given `_id`. */
|
|
1769
1848
|
findByIdAndDelete(id?: mongodb.ObjectId | any, options?: QueryOptions | null, callback?: (err: any, doc: DocType | null, res: any) => void): Query<DocType | null, DocType>;
|
|
1770
1849
|
|
|
1771
1850
|
/** Creates a `findOneAndUpdate` query, filtering by the given `_id`. */
|
|
1851
|
+
findByIdAndUpdate(id: mongodb.ObjectId | any, update: UpdateQuery<DocType>, options: QueryOptions & { upsert: true }, callback?: (err: any, doc: DocType, res: any) => void): Query<DocType, DocType>;
|
|
1772
1852
|
findByIdAndUpdate(id?: mongodb.ObjectId | any, update?: UpdateQuery<DocType>, options?: QueryOptions | null, callback?: (err: any, doc: DocType | null, res: any) => void): Query<DocType | null, DocType>;
|
|
1773
1853
|
|
|
1774
1854
|
/** Specifies a `$geometry` condition */
|
|
@@ -1887,7 +1967,7 @@ declare module "mongoose" {
|
|
|
1887
1967
|
* This is handy for integrating with async/await, because `orFail()` saves you
|
|
1888
1968
|
* an extra `if` statement to check if no document was found.
|
|
1889
1969
|
*/
|
|
1890
|
-
orFail(err?: NativeError | (() => NativeError)):
|
|
1970
|
+
orFail(err?: NativeError | (() => NativeError)): Query<NonNullable<ResultType>, DocType>;
|
|
1891
1971
|
|
|
1892
1972
|
/** Specifies a `$polygon` condition */
|
|
1893
1973
|
polygon(...coordinatePairs: number[][]): this;
|
|
@@ -1913,7 +1993,7 @@ declare module "mongoose" {
|
|
|
1913
1993
|
/**
|
|
1914
1994
|
* Declare and/or execute this query as a remove() operation. `remove()` is
|
|
1915
1995
|
* deprecated, you should use [`deleteOne()`](#query_Query-deleteOne)
|
|
1916
|
-
* or [`deleteMany()`](#query_Query-deleteMany) instead.
|
|
1996
|
+
* or [`deleteMany()`](#query_Query-deleteMany) instead.
|
|
1917
1997
|
*/
|
|
1918
1998
|
remove(filter?: FilterQuery<DocType>, callback?: (err: CallbackError, res: mongodb.WriteOpResult['result']) => void): Query<mongodb.WriteOpResult['result'], DocType>;
|
|
1919
1999
|
|
|
@@ -1946,7 +2026,7 @@ declare module "mongoose" {
|
|
|
1946
2026
|
/**
|
|
1947
2027
|
* Adds a `$set` to this query's update without changing the operation.
|
|
1948
2028
|
* This is useful for query middleware so you can add an update regardless
|
|
1949
|
-
* of whether you use `updateOne()`, `updateMany()`, `findOneAndUpdate()`, etc.
|
|
2029
|
+
* of whether you use `updateOne()`, `updateMany()`, `findOneAndUpdate()`, etc.
|
|
1950
2030
|
*/
|
|
1951
2031
|
set(path: string, value: any): this;
|
|
1952
2032
|
|
|
@@ -2027,7 +2107,7 @@ declare module "mongoose" {
|
|
|
2027
2107
|
wtimeout(ms: number): this;
|
|
2028
2108
|
}
|
|
2029
2109
|
|
|
2030
|
-
|
|
2110
|
+
type _FilterQuery<T> = {
|
|
2031
2111
|
[P in keyof T]?: P extends '_id'
|
|
2032
2112
|
? [Extract<T[P], mongodb.ObjectId>] extends [never]
|
|
2033
2113
|
? mongodb.Condition<T[P]>
|
|
@@ -2038,9 +2118,14 @@ declare module "mongoose" {
|
|
|
2038
2118
|
} &
|
|
2039
2119
|
mongodb.RootQuerySelector<T>;
|
|
2040
2120
|
|
|
2121
|
+
export type FilterQuery<T> = _FilterQuery<DocumentDefinition<T>>;
|
|
2122
|
+
|
|
2041
2123
|
export type UpdateQuery<T> = mongodb.UpdateQuery<DocumentDefinition<T>> & mongodb.MatchKeysAndValues<DocumentDefinition<T>>;
|
|
2042
2124
|
|
|
2043
|
-
|
|
2125
|
+
type _AllowStringsForIds<T> = {
|
|
2126
|
+
[K in keyof T]: [Extract<T[K], mongodb.ObjectId>] extends [never] ? T[K] : T[K] | string;
|
|
2127
|
+
};
|
|
2128
|
+
export type DocumentDefinition<T> = _AllowStringsForIds<Omit<T, Exclude<keyof Document, '_id'>>>;
|
|
2044
2129
|
|
|
2045
2130
|
type FunctionPropertyNames<T> = {
|
|
2046
2131
|
// The 1 & T[K] check comes from: https://stackoverflow.com/questions/55541275/typescript-check-for-the-any-type
|
|
@@ -2064,7 +2149,7 @@ declare module "mongoose" {
|
|
|
2064
2149
|
T[K];
|
|
2065
2150
|
};
|
|
2066
2151
|
|
|
2067
|
-
export type LeanDocument<T> = Omit<Omit<_LeanDocument<T>, Exclude<keyof Document, '_id'>>, FunctionPropertyNames<T>>;
|
|
2152
|
+
export type LeanDocument<T> = Omit<Omit<_LeanDocument<T>, Exclude<keyof Document, '_id' | 'id'>>, FunctionPropertyNames<T>>;
|
|
2068
2153
|
|
|
2069
2154
|
export type LeanDocumentOrArray<T> = 0 extends (1 & T) ? T :
|
|
2070
2155
|
T extends unknown[] ? LeanDocument<T[number]>[] :
|
|
@@ -2151,6 +2236,12 @@ declare module "mongoose" {
|
|
|
2151
2236
|
/** Sets the hint option for the aggregation query (ignored for < 3.6.0) */
|
|
2152
2237
|
hint(value: object | string): this;
|
|
2153
2238
|
|
|
2239
|
+
/**
|
|
2240
|
+
* Appends a new $limit operator to this aggregate pipeline.
|
|
2241
|
+
* @param num maximum number of records to pass to the next stage
|
|
2242
|
+
*/
|
|
2243
|
+
limit(num: number): this;
|
|
2244
|
+
|
|
2154
2245
|
/** Appends new custom $lookup operator to this aggregate pipeline. */
|
|
2155
2246
|
lookup(options: any): this;
|
|
2156
2247
|
|
|
@@ -2180,6 +2271,12 @@ declare module "mongoose" {
|
|
|
2180
2271
|
|
|
2181
2272
|
/** Sets the session for this aggregation. Useful for [transactions](/docs/transactions.html). */
|
|
2182
2273
|
session(session: mongodb.ClientSession | null): this;
|
|
2274
|
+
|
|
2275
|
+
/**
|
|
2276
|
+
* Appends a new $skip operator to this aggregate pipeline.
|
|
2277
|
+
* @param num number of records to skip before next stage
|
|
2278
|
+
*/
|
|
2279
|
+
skip(num: number): this;
|
|
2183
2280
|
|
|
2184
2281
|
/** Appends a new $sort operator to this aggregate pipeline. */
|
|
2185
2282
|
sort(arg: any): this;
|
|
@@ -2401,4 +2498,33 @@ declare module "mongoose" {
|
|
|
2401
2498
|
modifiedPaths: Array<string>;
|
|
2402
2499
|
}
|
|
2403
2500
|
}
|
|
2501
|
+
|
|
2502
|
+
/** Deprecated types for backwards compatibility. */
|
|
2503
|
+
|
|
2504
|
+
/** Alias for QueryOptions for backwards compatability. */
|
|
2505
|
+
type ModelUpdateOptions = QueryOptions;
|
|
2506
|
+
|
|
2507
|
+
/** Backwards support for DefinitelyTyped */
|
|
2508
|
+
interface HookSyncCallback<T> {
|
|
2509
|
+
(this: T, next: HookNextFunction, docs: any[]): Promise<any> | void;
|
|
2510
|
+
}
|
|
2511
|
+
|
|
2512
|
+
interface HookAsyncCallback<T> {
|
|
2513
|
+
(this: T, next: HookNextFunction, done: HookDoneFunction, docs: any[]): Promise<any> | void;
|
|
2514
|
+
}
|
|
2515
|
+
|
|
2516
|
+
interface HookErrorCallback {
|
|
2517
|
+
(error?: Error): any;
|
|
2518
|
+
}
|
|
2519
|
+
|
|
2520
|
+
interface HookNextFunction {
|
|
2521
|
+
(error?: Error): any;
|
|
2522
|
+
}
|
|
2523
|
+
|
|
2524
|
+
interface HookDoneFunction {
|
|
2525
|
+
(error?: Error): any;
|
|
2526
|
+
}
|
|
2527
|
+
|
|
2528
|
+
export type SchemaTypeOpts<T> = SchemaTypeOptions<T>;
|
|
2529
|
+
export type ConnectionOptions = ConnectOptions;
|
|
2404
2530
|
}
|
package/lib/model.js
CHANGED
|
@@ -3332,9 +3332,13 @@ Model.$__insertMany = function(arr, options, callback) {
|
|
|
3332
3332
|
|
|
3333
3333
|
// `insertedDocs` is a Mongoose-specific property
|
|
3334
3334
|
const erroredIndexes = new Set(get(error, 'writeErrors', []).map(err => err.index));
|
|
3335
|
-
error.insertedDocs = docAttributes.
|
|
3336
|
-
|
|
3337
|
-
|
|
3335
|
+
error.insertedDocs = docAttributes.
|
|
3336
|
+
filter((doc, i) => !erroredIndexes.has(i)).
|
|
3337
|
+
map(function setIsNewForInsertedDoc(doc) {
|
|
3338
|
+
doc.$__reset();
|
|
3339
|
+
_setIsNew(doc, false);
|
|
3340
|
+
return doc;
|
|
3341
|
+
});
|
|
3338
3342
|
|
|
3339
3343
|
callback(error, null);
|
|
3340
3344
|
return;
|
package/lib/schema/map.js
CHANGED
|
@@ -31,11 +31,23 @@ class Map extends SchemaType {
|
|
|
31
31
|
|
|
32
32
|
if (val instanceof global.Map) {
|
|
33
33
|
for (const key of val.keys()) {
|
|
34
|
-
|
|
34
|
+
let _val = val.get(key);
|
|
35
|
+
if (_val == null) {
|
|
36
|
+
_val = map.$__schemaType._castNullish(_val);
|
|
37
|
+
} else {
|
|
38
|
+
_val = map.$__schemaType.cast(_val, doc, true);
|
|
39
|
+
}
|
|
40
|
+
map.$init(key, _val);
|
|
35
41
|
}
|
|
36
42
|
} else {
|
|
37
43
|
for (const key of Object.keys(val)) {
|
|
38
|
-
|
|
44
|
+
let _val = val[key];
|
|
45
|
+
if (_val == null) {
|
|
46
|
+
_val = map.$__schemaType._castNullish(_val);
|
|
47
|
+
} else {
|
|
48
|
+
_val = map.$__schemaType.cast(_val, doc, true);
|
|
49
|
+
}
|
|
50
|
+
map.$init(key, _val);
|
|
39
51
|
}
|
|
40
52
|
}
|
|
41
53
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mongoose",
|
|
3
3
|
"description": "Mongoose MongoDB ODM",
|
|
4
|
-
"version": "5.11.
|
|
4
|
+
"version": "5.11.7",
|
|
5
5
|
"author": "Guillermo Rauch <guillermo@learnboost.com>",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"mongodb",
|
|
@@ -21,11 +21,11 @@
|
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@types/mongodb": "^3.5.27",
|
|
23
23
|
"bson": "^1.1.4",
|
|
24
|
-
"kareem": "2.3.
|
|
24
|
+
"kareem": "2.3.2",
|
|
25
25
|
"mongodb": "3.6.3",
|
|
26
26
|
"mongoose-legacy-pluralize": "1.0.2",
|
|
27
|
-
"mpath": "0.8.
|
|
28
|
-
"mquery": "3.2.
|
|
27
|
+
"mpath": "0.8.1",
|
|
28
|
+
"mquery": "3.2.3",
|
|
29
29
|
"ms": "2.1.2",
|
|
30
30
|
"regexp-clone": "1.0.0",
|
|
31
31
|
"safe-buffer": "5.2.1",
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"prepublishOnly": "npm run build-browser",
|
|
77
77
|
"release": "git pull && git push origin master --tags && npm publish",
|
|
78
78
|
"release-legacy": "git pull origin 4.x && git push origin 4.x --tags && npm publish --tag legacy",
|
|
79
|
-
"test": "mocha --exit",
|
|
79
|
+
"test": "mocha --exit ./test/*.test.js ./test/typescript/main.test.js",
|
|
80
80
|
"test-cov": "nyc --reporter=html --reporter=text npm test"
|
|
81
81
|
},
|
|
82
82
|
"main": "./index.js",
|