w-orm-mongodb 1.1.40 → 1.1.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -1
- package/dist/w-orm-mongodb.umd.js +2 -2
- package/dist/w-orm-mongodb.umd.js.map +1 -1
- package/docs/WOrmMongodb.html +11 -11
- package/docs/WOrmMongodb.mjs.html +160 -59
- package/docs/index.html +1 -1
- package/package.json +1 -1
- package/src/WOrmMongodb.mjs +158 -57
- package/test/api-basic.test.mjs +245 -0
- package/test/api-gfs.test.mjs +107 -0
package/README.md
CHANGED
|
@@ -236,6 +236,43 @@ delAll(find) → { n, nDeleted, ok }
|
|
|
236
236
|
|
|
237
237
|
`del`對未帶有效`id`者不送查詢條件,直接回`ok: 0`並附`err`,以免`undefined`經序列化為`null`而誤刪`id`為`null`之數據。
|
|
238
238
|
|
|
239
|
+
## Events
|
|
240
|
+
|
|
241
|
+
操作物件為`EventEmitter`,發出`change`與`error`兩種事件,供於單一處集中觀察資料異動與失敗,不必在每個呼叫點各自包裝。
|
|
242
|
+
|
|
243
|
+
```alias
|
|
244
|
+
change (mode, data, res) 資料實際異動成功後,整批一次
|
|
245
|
+
error (mode, data, err) 整批性錯誤於 reject 前;逐筆失敗於該筆定案後,每筆一次
|
|
246
|
+
|
|
247
|
+
mode 函數名稱,如 'insert'、'save'、'del'、'delAll'、'select'、'selectByPk'、'insertGfs' 等
|
|
248
|
+
data 輸入數據,無輸入數據者(如 delAll、select、selectByPk)為 null
|
|
249
|
+
err 錯誤訊息字串
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
```alias
|
|
253
|
+
let wo = WOrm(opt)
|
|
254
|
+
|
|
255
|
+
wo.on('change', function(mode, data, res) {
|
|
256
|
+
console.log('change', mode, res)
|
|
257
|
+
})
|
|
258
|
+
|
|
259
|
+
wo.on('error', function(mode, data, err) {
|
|
260
|
+
console.log('error', mode, err)
|
|
261
|
+
})
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
**事件僅為附加通知,不承擔任何回傳義務。** 凡經由事件送出之資訊,必同時經由正規管道送達——整批性錯誤經`Promise.reject`,逐筆失敗經該筆之`err`欄位,操作結果經 resolve 值。把全部事件移除之後,呼叫端仍能取得完整資訊。
|
|
265
|
+
|
|
266
|
+
**操作行為不因監聽者之有無而改變。** 同一份程式碼、同一組輸入,於有註冊監聽與未註冊監聽兩種情況下,回傳值與 resolve/reject 之選擇完全相同。本套件之`EventEmitter`採`eventemitter3`(`wsemi`之`evem()`),其於`'error'`無監聽者時僅回傳`false`而不拋出;Node 內建之`events.EventEmitter`具「`'error'`無監聽者時將錯誤拋出」之語義,故不採用。
|
|
267
|
+
|
|
268
|
+
訂閱函數自身拋錯亦不影響本次操作之結果——每一處`emit`皆以 try/catch 包覆。
|
|
269
|
+
|
|
270
|
+
**正常結果不發出`error`。** `insert`全數已存在、`save`合併後內容相同而未寫入、`del`主鍵未命中、`delAll`條件無命中、`selectByPk`查無數據,皆為正常結果而非錯誤。
|
|
271
|
+
|
|
272
|
+
**收到`error`不表示該次呼叫失敗。** 逐筆失敗時整批仍 resolve,欲判斷整批成敗仍依上方「判讀準則」。
|
|
273
|
+
|
|
274
|
+
`save`於逐筆插入時另發出`mode`為`'insert'`之`change`事件,供區辨新增與更新。讀取函數(`select`、`selectByPk`、`selectByPkGfs`)不發出`change`。
|
|
275
|
+
|
|
239
276
|
## Primary key
|
|
240
277
|
|
|
241
278
|
本套件之主鍵欄位固定為`id`,尚未支援由呼叫端指定。`id`為無業務語義之識別碼。
|
|
@@ -244,7 +281,7 @@ delAll(find) → { n, nDeleted, ok }
|
|
|
244
281
|
|
|
245
282
|
| `opt.autoGenPk` | 行為 |
|
|
246
283
|
|---|---|
|
|
247
|
-
| `true`(預設) | `insert`、`save`、`insertGfs`於輸入未帶有效`id`時,由套件以`
|
|
284
|
+
| `true`(預設) | `insert`、`save`、`insertGfs`於輸入未帶有效`id`時,由套件以`genIDSeq()`自動產生(UUIDv7,時間有序) |
|
|
248
285
|
| `false` | 套件一律不產生`id`,`id`須由呼叫端於寫入前自備 |
|
|
249
286
|
|
|
250
287
|
`autoGenPk: false`之定位為**依賴注入**:`id`的產生規則改由呼叫端掌握(如採用外部發號器、以業務欄位組合、沿用上游系統既有識別碼),套件不介入。採用此設定後,**`id`之唯一性、格式與是否與既有資料衝突,皆由呼叫端自負**。
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* w-orm-mongodb v1.1.
|
|
2
|
+
* w-orm-mongodb v1.1.42
|
|
3
3
|
* (c) 2018-2021 yuda-lyu(semisphere)
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
*/
|
|
6
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("events"),require("mongodb"),require("stream")):"function"==typeof define&&define.amd?define(["events","mongodb","stream"],e):(t="undefined"!=typeof globalThis?globalThis:t||self)["w-orm-mongodb"]=e(t.events,t.mongodb,t.stream)}(this,(function(t,e,r){"use strict";function n(t,e){return t===e||t!=t&&e!=e}function o(t,e){for(var r=t.length;r--;)if(n(t[r][0],e))return r;return-1}var u=Array.prototype.splice;function i(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}i.prototype.clear=function(){this.__data__=[],this.size=0},i.prototype.delete=function(t){var e=this.__data__,r=o(e,t);return!(r<0)&&(r==e.length-1?e.pop():u.call(e,r,1),--this.size,!0)},i.prototype.get=function(t){var e=this.__data__,r=o(e,t);return r<0?void 0:e[r][1]},i.prototype.has=function(t){return o(this.__data__,t)>-1},i.prototype.set=function(t,e){var r=this.__data__,n=o(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};var c="object"==typeof global&&global&&global.Object===Object&&global,a="object"==typeof self&&self&&self.Object===Object&&self,l=c||a||Function("return this")(),f=l.Symbol,s=Object.prototype,d=s.hasOwnProperty,v=s.toString,p=f?f.toStringTag:void 0;var b=Object.prototype.toString;var y="[object Null]",h="[object Undefined]",j=f?f.toStringTag:void 0;function g(t){return null==t?void 0===t?h:y:j&&j in Object(t)?function(t){var e=d.call(t,p),r=t[p];try{t[p]=void 0;var n=!0}catch(t){}var o=v.call(t);return n&&(e?t[p]=r:delete t[p]),o}(t):function(t){return b.call(t)}(t)}function _(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}var w="[object AsyncFunction]",m="[object Function]",O="[object GeneratorFunction]",A="[object Proxy]";function S(t){if(!_(t))return!1;var e=g(t);return e==m||e==O||e==w||e==A}var k,P=l["__core-js_shared__"],x=(k=/[^.]+$/.exec(P&&P.keys&&P.keys.IE_PROTO||""))?"Symbol(src)_1."+k:"";var z=Function.prototype.toString;function B(t){if(null!=t){try{return z.call(t)}catch(t){}try{return t+""}catch(t){}}return""}var I=/^\[object .+?Constructor\]$/,E=Function.prototype,M=Object.prototype,F=E.toString,D=M.hasOwnProperty,$=RegExp("^"+F.call(D).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function N(t){return!(!_(t)||(e=t,x&&x in e))&&(S(t)?$:I).test(B(t));var e}function U(t,e){var r=function(t,e){return null==t?void 0:t[e]}(t,e);return N(r)?r:void 0}var C=U(l,"Map"),G=U(Object,"create");var T=Object.prototype.hasOwnProperty;var R=Object.prototype.hasOwnProperty;function q(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function L(t,e){var r,n,o=t.__data__;return("string"==(n=typeof(r=e))||"number"==n||"symbol"==n||"boolean"==n?"__proto__"!==r:null===r)?o["string"==typeof e?"string":"hash"]:o.map}function V(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}q.prototype.clear=function(){this.__data__=G?G(null):{},this.size=0},q.prototype.delete=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},q.prototype.get=function(t){var e=this.__data__;if(G){var r=e[t];return"__lodash_hash_undefined__"===r?void 0:r}return T.call(e,t)?e[t]:void 0},q.prototype.has=function(t){var e=this.__data__;return G?void 0!==e[t]:R.call(e,t)},q.prototype.set=function(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=G&&void 0===e?"__lodash_hash_undefined__":e,this},V.prototype.clear=function(){this.size=0,this.__data__={hash:new q,map:new(C||i),string:new q}},V.prototype.delete=function(t){var e=L(this,t).delete(t);return this.size-=e?1:0,e},V.prototype.get=function(t){return L(this,t).get(t)},V.prototype.has=function(t){return L(this,t).has(t)},V.prototype.set=function(t,e){var r=L(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,this};function W(t){var e=this.__data__=new i(t);this.size=e.size}function H(t,e){for(var r=-1,n=null==t?0:t.length;++r<n&&!1!==e(t[r],r,t););return t}W.prototype.clear=function(){this.__data__=new i,this.size=0},W.prototype.delete=function(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r},W.prototype.get=function(t){return this.__data__.get(t)},W.prototype.has=function(t){return this.__data__.has(t)},W.prototype.set=function(t,e){var r=this.__data__;if(r instanceof i){var n=r.__data__;if(!C||n.length<199)return n.push([t,e]),this.size=++r.size,this;r=this.__data__=new V(n)}return r.set(t,e),this.size=r.size,this};var J=function(){try{var t=U(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),K=J;function Q(t,e,r){"__proto__"==e&&K?K(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r}var X=Object.prototype.hasOwnProperty;function Y(t,e,r){var o=t[e];X.call(t,e)&&n(o,r)&&(void 0!==r||e in t)||Q(t,e,r)}function Z(t,e,r,n){var o=!r;r||(r={});for(var u=-1,i=e.length;++u<i;){var c=e[u],a=n?n(r[c],t[c],c,r,t):void 0;void 0===a&&(a=t[c]),o?Q(r,c,a):Y(r,c,a)}return r}function tt(t){return null!=t&&"object"==typeof t}function et(t){return tt(t)&&"[object Arguments]"==g(t)}var rt=Object.prototype,nt=rt.hasOwnProperty,ot=rt.propertyIsEnumerable,ut=et(function(){return arguments}())?et:function(t){return tt(t)&&nt.call(t,"callee")&&!ot.call(t,"callee")},it=ut,ct=Array.isArray;var at="object"==typeof exports&&exports&&!exports.nodeType&&exports,lt=at&&"object"==typeof module&&module&&!module.nodeType&&module,ft=lt&<.exports===at?l.Buffer:void 0,st=(ft?ft.isBuffer:void 0)||function(){return!1},dt=9007199254740991,vt=/^(?:0|[1-9]\d*)$/;function pt(t,e){var r=typeof t;return!!(e=null==e?dt:e)&&("number"==r||"symbol"!=r&&vt.test(t))&&t>-1&&t%1==0&&t<e}var bt=9007199254740991;function yt(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=bt}var ht={};function jt(t){return function(e){return t(e)}}ht["[object Float32Array]"]=ht["[object Float64Array]"]=ht["[object Int8Array]"]=ht["[object Int16Array]"]=ht["[object Int32Array]"]=ht["[object Uint8Array]"]=ht["[object Uint8ClampedArray]"]=ht["[object Uint16Array]"]=ht["[object Uint32Array]"]=!0,ht["[object Arguments]"]=ht["[object Array]"]=ht["[object ArrayBuffer]"]=ht["[object Boolean]"]=ht["[object DataView]"]=ht["[object Date]"]=ht["[object Error]"]=ht["[object Function]"]=ht["[object Map]"]=ht["[object Number]"]=ht["[object Object]"]=ht["[object RegExp]"]=ht["[object Set]"]=ht["[object String]"]=ht["[object WeakMap]"]=!1;var gt="object"==typeof exports&&exports&&!exports.nodeType&&exports,_t=gt&&"object"==typeof module&&module&&!module.nodeType&&module,wt=_t&&_t.exports===gt&&c.process,mt=function(){try{var t=_t&&_t.require&&_t.require("util").types;return t||wt&&wt.binding&&wt.binding("util")}catch(t){}}(),Ot=mt&&mt.isTypedArray,At=Ot?jt(Ot):function(t){return tt(t)&&yt(t.length)&&!!ht[g(t)]},St=Object.prototype.hasOwnProperty;function kt(t,e){var r=ct(t),n=!r&&it(t),o=!r&&!n&&st(t),u=!r&&!n&&!o&&At(t),i=r||n||o||u,c=i?function(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n}(t.length,String):[],a=c.length;for(var l in t)!e&&!St.call(t,l)||i&&("length"==l||o&&("offset"==l||"parent"==l)||u&&("buffer"==l||"byteLength"==l||"byteOffset"==l)||pt(l,a))||c.push(l);return c}var Pt=Object.prototype;function xt(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||Pt)}function zt(t,e){return function(r){return t(e(r))}}var Bt=zt(Object.keys,Object),It=Object.prototype.hasOwnProperty;function Et(t){if(!xt(t))return Bt(t);var e=[];for(var r in Object(t))It.call(t,r)&&"constructor"!=r&&e.push(r);return e}function Mt(t){return null!=t&&yt(t.length)&&!S(t)}function Ft(t){return Mt(t)?kt(t):Et(t)}var Dt=Object.prototype.hasOwnProperty;function $t(t){if(!_(t))return function(t){var e=[];if(null!=t)for(var r in Object(t))e.push(r);return e}(t);var e=xt(t),r=[];for(var n in t)("constructor"!=n||!e&&Dt.call(t,n))&&r.push(n);return r}function Nt(t){return Mt(t)?kt(t,!0):$t(t)}var Ut="object"==typeof exports&&exports&&!exports.nodeType&&exports,Ct=Ut&&"object"==typeof module&&module&&!module.nodeType&&module,Gt=Ct&&Ct.exports===Ut?l.Buffer:void 0,Tt=Gt?Gt.allocUnsafe:void 0;function Rt(){return[]}var qt=Object.prototype.propertyIsEnumerable,Lt=Object.getOwnPropertySymbols,Vt=Lt?function(t){return null==t?[]:(t=Object(t),function(t,e){for(var r=-1,n=null==t?0:t.length,o=0,u=[];++r<n;){var i=t[r];e(i,r,t)&&(u[o++]=i)}return u}(Lt(t),(function(e){return qt.call(t,e)})))}:Rt,Wt=Vt;function Ht(t,e){for(var r=-1,n=e.length,o=t.length;++r<n;)t[o+r]=e[r];return t}var Jt=zt(Object.getPrototypeOf,Object),Kt=Object.getOwnPropertySymbols?function(t){for(var e=[];t;)Ht(e,Wt(t)),t=Jt(t);return e}:Rt,Qt=Kt;function Xt(t,e,r){var n=e(t);return ct(t)?n:Ht(n,r(t))}function Yt(t){return Xt(t,Ft,Wt)}function Zt(t){return Xt(t,Nt,Qt)}var te=U(l,"DataView"),ee=U(l,"Promise"),re=U(l,"Set"),ne=U(l,"WeakMap"),oe="[object Map]",ue="[object Promise]",ie="[object Set]",ce="[object WeakMap]",ae="[object DataView]",le=B(te),fe=B(C),se=B(ee),de=B(re),ve=B(ne),pe=g;(te&&pe(new te(new ArrayBuffer(1)))!=ae||C&&pe(new C)!=oe||ee&&pe(ee.resolve())!=ue||re&&pe(new re)!=ie||ne&&pe(new ne)!=ce)&&(pe=function(t){var e=g(t),r="[object Object]"==e?t.constructor:void 0,n=r?B(r):"";if(n)switch(n){case le:return ae;case fe:return oe;case se:return ue;case de:return ie;case ve:return ce}return e});var be=pe,ye=Object.prototype.hasOwnProperty;var he=l.Uint8Array;function je(t){var e=new t.constructor(t.byteLength);return new he(e).set(new he(t)),e}var ge=/\w*$/;var _e=f?f.prototype:void 0,we=_e?_e.valueOf:void 0;var me="[object Boolean]",Oe="[object Date]",Ae="[object Map]",Se="[object Number]",ke="[object RegExp]",Pe="[object Set]",xe="[object String]",ze="[object Symbol]",Be="[object ArrayBuffer]",Ie="[object DataView]",Ee="[object Float32Array]",Me="[object Float64Array]",Fe="[object Int8Array]",De="[object Int16Array]",$e="[object Int32Array]",Ne="[object Uint8Array]",Ue="[object Uint8ClampedArray]",Ce="[object Uint16Array]",Ge="[object Uint32Array]";function Te(t,e,r){var n,o,u,i=t.constructor;switch(e){case Be:return je(t);case me:case Oe:return new i(+t);case Ie:return function(t,e){var r=e?je(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.byteLength)}(t,r);case Ee:case Me:case Fe:case De:case $e:case Ne:case Ue:case Ce:case Ge:return function(t,e){var r=e?je(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.length)}(t,r);case Ae:return new i;case Se:case xe:return new i(t);case ke:return(u=new(o=t).constructor(o.source,ge.exec(o))).lastIndex=o.lastIndex,u;case Pe:return new i;case ze:return n=t,we?Object(we.call(n)):{}}}var Re=Object.create,qe=function(){function t(){}return function(e){if(!_(e))return{};if(Re)return Re(e);t.prototype=e;var r=new t;return t.prototype=void 0,r}}(),Le=qe;var Ve=mt&&mt.isMap,We=Ve?jt(Ve):function(t){return tt(t)&&"[object Map]"==be(t)};var He=mt&&mt.isSet,Je=He?jt(He):function(t){return tt(t)&&"[object Set]"==be(t)},Ke=1,Qe=2,Xe=4,Ye="[object Arguments]",Ze="[object Function]",tr="[object GeneratorFunction]",er="[object Object]",rr={};function nr(t,e,r,n,o,u){var i,c=e&Ke,a=e&Qe,l=e&Xe;if(r&&(i=o?r(t,n,o,u):r(t)),void 0!==i)return i;if(!_(t))return t;var f=ct(t);if(f){if(i=function(t){var e=t.length,r=new t.constructor(e);return e&&"string"==typeof t[0]&&ye.call(t,"index")&&(r.index=t.index,r.input=t.input),r}(t),!c)return function(t,e){var r=-1,n=t.length;for(e||(e=Array(n));++r<n;)e[r]=t[r];return e}(t,i)}else{var s=be(t),d=s==Ze||s==tr;if(st(t))return function(t,e){if(e)return t.slice();var r=t.length,n=Tt?Tt(r):new t.constructor(r);return t.copy(n),n}(t,c);if(s==er||s==Ye||d&&!o){if(i=a||d?{}:function(t){return"function"!=typeof t.constructor||xt(t)?{}:Le(Jt(t))}(t),!c)return a?function(t,e){return Z(t,Qt(t),e)}(t,function(t,e){return t&&Z(e,Nt(e),t)}(i,t)):function(t,e){return Z(t,Wt(t),e)}(t,function(t,e){return t&&Z(e,Ft(e),t)}(i,t))}else{if(!rr[s])return o?t:{};i=Te(t,s,c)}}u||(u=new W);var v=u.get(t);if(v)return v;u.set(t,i),Je(t)?t.forEach((function(n){i.add(nr(n,e,r,n,t,u))})):We(t)&&t.forEach((function(n,o){i.set(o,nr(n,e,r,o,t,u))}));var p=f?void 0:(l?a?Zt:Yt:a?Nt:Ft)(t);return H(p||t,(function(n,o){p&&(n=t[o=n]),Y(i,o,nr(n,e,r,o,t,u))})),i}rr[Ye]=rr["[object Array]"]=rr["[object ArrayBuffer]"]=rr["[object DataView]"]=rr["[object Boolean]"]=rr["[object Date]"]=rr["[object Float32Array]"]=rr["[object Float64Array]"]=rr["[object Int8Array]"]=rr["[object Int16Array]"]=rr["[object Int32Array]"]=rr["[object Map]"]=rr["[object Number]"]=rr[er]=rr["[object RegExp]"]=rr["[object Set]"]=rr["[object String]"]=rr["[object Symbol]"]=rr["[object Uint8Array]"]=rr["[object Uint8ClampedArray]"]=rr["[object Uint16Array]"]=rr["[object Uint32Array]"]=!0,rr["[object Error]"]=rr[Ze]=rr["[object WeakMap]"]=!1;var or=1,ur=4;function ir(t){return nr(t,or|ur)}function cr(t,e){for(var r=-1,n=null==t?0:t.length;++r<n;)if(!e(t[r],r,t))return!1;return!0}var ar,lr=function(t,e,r){for(var n=-1,o=Object(t),u=r(t),i=u.length;i--;){var c=u[ar?i:++n];if(!1===e(o[c],c,o))break}return t};var fr=function(t,e){return function(r,n){if(null==r)return r;if(!Mt(r))return t(r,n);for(var o=r.length,u=e?o:-1,i=Object(r);(e?u--:++u<o)&&!1!==n(i[u],u,i););return r}}((function(t,e){return t&&lr(t,e,Ft)})),sr=fr;function dr(t,e){var r=!0;return sr(t,(function(t,n,o){return r=!!e(t,n,o)})),r}function vr(t){var e=-1,r=null==t?0:t.length;for(this.__data__=new V;++e<r;)this.add(t[e])}function pr(t,e){for(var r=-1,n=null==t?0:t.length;++r<n;)if(e(t[r],r,t))return!0;return!1}vr.prototype.add=vr.prototype.push=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this},vr.prototype.has=function(t){return this.__data__.has(t)};var br=1,yr=2;function hr(t,e,r,n,o,u){var i=r&br,c=t.length,a=e.length;if(c!=a&&!(i&&a>c))return!1;var l=u.get(t),f=u.get(e);if(l&&f)return l==e&&f==t;var s=-1,d=!0,v=r&yr?new vr:void 0;for(u.set(t,e),u.set(e,t);++s<c;){var p=t[s],b=e[s];if(n)var y=i?n(b,p,s,e,t,u):n(p,b,s,t,e,u);if(void 0!==y){if(y)continue;d=!1;break}if(v){if(!pr(e,(function(t,e){if(i=e,!v.has(i)&&(p===t||o(p,t,r,n,u)))return v.push(e);var i}))){d=!1;break}}else if(p!==b&&!o(p,b,r,n,u)){d=!1;break}}return u.delete(t),u.delete(e),d}function jr(t){var e=-1,r=Array(t.size);return t.forEach((function(t,n){r[++e]=[n,t]})),r}function gr(t){var e=-1,r=Array(t.size);return t.forEach((function(t){r[++e]=t})),r}var _r=1,wr=2,mr="[object Boolean]",Or="[object Date]",Ar="[object Error]",Sr="[object Map]",kr="[object Number]",Pr="[object RegExp]",xr="[object Set]",zr="[object String]",Br="[object Symbol]",Ir="[object ArrayBuffer]",Er="[object DataView]",Mr=f?f.prototype:void 0,Fr=Mr?Mr.valueOf:void 0;var Dr=1,$r=Object.prototype.hasOwnProperty;var Nr=1,Ur="[object Arguments]",Cr="[object Array]",Gr="[object Object]",Tr=Object.prototype.hasOwnProperty;function Rr(t,e,r,o,u,i){var c=ct(t),a=ct(e),l=c?Cr:be(t),f=a?Cr:be(e),s=(l=l==Ur?Gr:l)==Gr,d=(f=f==Ur?Gr:f)==Gr,v=l==f;if(v&&st(t)){if(!st(e))return!1;c=!0,s=!1}if(v&&!s)return i||(i=new W),c||At(t)?hr(t,e,r,o,u,i):function(t,e,r,o,u,i,c){switch(r){case Er:if(t.byteLength!=e.byteLength||t.byteOffset!=e.byteOffset)return!1;t=t.buffer,e=e.buffer;case Ir:return!(t.byteLength!=e.byteLength||!i(new he(t),new he(e)));case mr:case Or:case kr:return n(+t,+e);case Ar:return t.name==e.name&&t.message==e.message;case Pr:case zr:return t==e+"";case Sr:var a=jr;case xr:var l=o&_r;if(a||(a=gr),t.size!=e.size&&!l)return!1;var f=c.get(t);if(f)return f==e;o|=wr,c.set(t,e);var s=hr(a(t),a(e),o,u,i,c);return c.delete(t),s;case Br:if(Fr)return Fr.call(t)==Fr.call(e)}return!1}(t,e,l,r,o,u,i);if(!(r&Nr)){var p=s&&Tr.call(t,"__wrapped__"),b=d&&Tr.call(e,"__wrapped__");if(p||b){var y=p?t.value():t,h=b?e.value():e;return i||(i=new W),u(y,h,r,o,i)}}return!!v&&(i||(i=new W),function(t,e,r,n,o,u){var i=r&Dr,c=Yt(t),a=c.length;if(a!=Yt(e).length&&!i)return!1;for(var l=a;l--;){var f=c[l];if(!(i?f in e:$r.call(e,f)))return!1}var s=u.get(t),d=u.get(e);if(s&&d)return s==e&&d==t;var v=!0;u.set(t,e),u.set(e,t);for(var p=i;++l<a;){var b=t[f=c[l]],y=e[f];if(n)var h=i?n(y,b,f,e,t,u):n(b,y,f,t,e,u);if(!(void 0===h?b===y||o(b,y,r,n,u):h)){v=!1;break}p||(p="constructor"==f)}if(v&&!p){var j=t.constructor,g=e.constructor;j==g||!("constructor"in t)||!("constructor"in e)||"function"==typeof j&&j instanceof j&&"function"==typeof g&&g instanceof g||(v=!1)}return u.delete(t),u.delete(e),v}(t,e,r,o,u,i))}function qr(t,e,r,n,o){return t===e||(null==t||null==e||!tt(t)&&!tt(e)?t!=t&&e!=e:Rr(t,e,r,n,qr,o))}var Lr=1,Vr=2;function Wr(t){return t==t&&!_(t)}function Hr(t,e){return function(r){return null!=r&&(r[t]===e&&(void 0!==e||t in Object(r)))}}function Jr(t){var e=function(t){for(var e=Ft(t),r=e.length;r--;){var n=e[r],o=t[n];e[r]=[n,o,Wr(o)]}return e}(t);return 1==e.length&&e[0][2]?Hr(e[0][0],e[0][1]):function(r){return r===t||function(t,e,r,n){var o=r.length,u=o,i=!n;if(null==t)return!u;for(t=Object(t);o--;){var c=r[o];if(i&&c[2]?c[1]!==t[c[0]]:!(c[0]in t))return!1}for(;++o<u;){var a=(c=r[o])[0],l=t[a],f=c[1];if(i&&c[2]){if(void 0===l&&!(a in t))return!1}else{var s=new W;if(n)var d=n(l,f,a,t,e,s);if(!(void 0===d?qr(f,l,Lr|Vr,n,s):d))return!1}}return!0}(r,t,e)}}var Kr="[object Symbol]";function Qr(t){return"symbol"==typeof t||tt(t)&&g(t)==Kr}var Xr=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Yr=/^\w*$/;function Zr(t,e){if(ct(t))return!1;var r=typeof t;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=t&&!Qr(t))||(Yr.test(t)||!Xr.test(t)||null!=e&&t in Object(e))}var tn="Expected a function";function en(t,e){if("function"!=typeof t||null!=e&&"function"!=typeof e)throw new TypeError(tn);var r=function(){var n=arguments,o=e?e.apply(this,n):n[0],u=r.cache;if(u.has(o))return u.get(o);var i=t.apply(this,n);return r.cache=u.set(o,i)||u,i};return r.cache=new(en.Cache||V),r}en.Cache=V;var rn,nn,on,un=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,cn=/\\(\\)?/g,an=(rn=function(t){var e=[];return 46===t.charCodeAt(0)&&e.push(""),t.replace(un,(function(t,r,n,o){e.push(n?o.replace(cn,"$1"):r||t)})),e},nn=en(rn,(function(t){return 500===on.size&&on.clear(),t})),on=nn.cache,nn),ln=an;function fn(t,e){for(var r=-1,n=null==t?0:t.length,o=Array(n);++r<n;)o[r]=e(t[r],r,t);return o}var sn=1/0,dn=f?f.prototype:void 0,vn=dn?dn.toString:void 0;function pn(t){if("string"==typeof t)return t;if(ct(t))return fn(t,pn)+"";if(Qr(t))return vn?vn.call(t):"";var e=t+"";return"0"==e&&1/t==-sn?"-0":e}function bn(t){return null==t?"":pn(t)}function yn(t,e){return ct(t)?t:Zr(t,e)?[t]:ln(bn(t))}var hn=1/0;function jn(t){if("string"==typeof t||Qr(t))return t;var e=t+"";return"0"==e&&1/t==-hn?"-0":e}function gn(t,e){for(var r=0,n=(e=yn(e,t)).length;null!=t&&r<n;)t=t[jn(e[r++])];return r&&r==n?t:void 0}function _n(t,e,r){var n=null==t?void 0:gn(t,e);return void 0===n?r:n}function wn(t,e){return null!=t&&e in Object(t)}function mn(t,e){return null!=t&&function(t,e,r){for(var n=-1,o=(e=yn(e,t)).length,u=!1;++n<o;){var i=jn(e[n]);if(!(u=null!=t&&r(t,i)))break;t=t[i]}return u||++n!=o?u:!!(o=null==t?0:t.length)&&yt(o)&&pt(i,o)&&(ct(t)||it(t))}(t,e,wn)}var On=1,An=2;function Sn(t){return t}function kn(t){return function(e){return null==e?void 0:e[t]}}function Pn(t){return Zr(t)?kn(jn(t)):function(t){return function(e){return gn(e,t)}}(t)}function xn(t){return"function"==typeof t?t:null==t?Sn:"object"==typeof t?ct(t)?(e=t[0],r=t[1],Zr(e)&&Wr(r)?Hr(jn(e),r):function(t){var n=_n(t,e);return void 0===n&&n===r?mn(t,e):qr(r,n,On|An)}):Jr(t):Pn(t);var e,r}function zn(t,e,r){var o=ct(t)?cr:dr;return r&&function(t,e,r){if(!_(r))return!1;var o=typeof e;return!!("number"==o?Mt(r)&&pt(e,r.length):"string"==o&&e in r)&&n(r[e],t)}(t,e,r)&&(e=void 0),o(t,xn(e))}function Bn(t,e){var r=-1,n=Mt(t)?Array(t.length):[];return sr(t,(function(t,o,u){n[++r]=e(t,o,u)})),n}function In(t,e){return(ct(t)?fn:Bn)(t,xn(e))}function En(t,e,r){var n=-1,o=t.length;e<0&&(e=-e>o?0:o+e),(r=r>o?o:r)<0&&(r+=o),o=e>r?0:r-e>>>0,e>>>=0;for(var u=Array(o);++n<o;)u[n]=t[n+e];return u}var Mn=Object.prototype.hasOwnProperty;function Fn(t,e){var r=-1,n=(e=yn(e,t)).length;if(!n)return!0;for(;++r<n;){var o=jn(e[r]);if("__proto__"===o&&!Mn.call(t,"__proto__"))return!1;if(("constructor"===o||"prototype"===o)&&r<n-1)return!1}var u=function(t,e){return e.length<2?t:gn(t,En(e,0,-1))}(t,e);return null==u||delete u[jn(function(t){var e=null==t?0:t.length;return e?t[e-1]:void 0}(e))]}var Dn="[object Object]",$n=Function.prototype,Nn=Object.prototype,Un=$n.toString,Cn=Nn.hasOwnProperty,Gn=Un.call(Object);function Tn(t){return function(t){if(!tt(t)||g(t)!=Dn)return!1;var e=Jt(t);if(null===e)return!0;var r=Cn.call(e,"constructor")&&e.constructor;return"function"==typeof r&&r instanceof r&&Un.call(r)==Gn}(t)?void 0:t}var Rn=f?f.isConcatSpreadable:void 0;function qn(t){return ct(t)||it(t)||!!(Rn&&t&&t[Rn])}function Ln(t,e,r,n,o){var u=-1,i=t.length;for(r||(r=qn),o||(o=[]);++u<i;){var c=t[u];e>0&&r(c)?e>1?Ln(c,e-1,r,n,o):Ht(o,c):n||(o[o.length]=c)}return o}function Vn(t){return(null==t?0:t.length)?Ln(t,1):[]}var Wn=Math.max;var Hn=K?function(t,e){return K(t,"toString",{configurable:!0,enumerable:!1,value:(r=e,function(){return r}),writable:!0});var r}:Sn,Jn=Hn,Kn=Date.now;var Qn=function(t){var e=0,r=0;return function(){var n=Kn(),o=16-(n-r);if(r=n,o>0){if(++e>=800)return arguments[0]}else e=0;return t.apply(void 0,arguments)}}(Jn),Xn=Qn;var Yn=function(t){return Xn(function(t,e,r){return e=Wn(void 0===e?t.length-1:e,0),function(){for(var n=arguments,o=-1,u=Wn(n.length-e,0),i=Array(u);++o<u;)i[o]=n[e+o];o=-1;for(var c=Array(e+1);++o<e;)c[o]=n[o];return c[e]=r(i),function(t,e,r){switch(r.length){case 0:return t.call(e);case 1:return t.call(e,r[0]);case 2:return t.call(e,r[0],r[1]);case 3:return t.call(e,r[0],r[1],r[2])}return t.apply(e,r)}(t,this,c)}}(t,void 0,Vn),t+"")}((function(t,e){var r={};if(null==t)return r;var n=!1;e=fn(e,(function(e){return e=yn(e,t),n||(n=e.length>1),e})),Z(t,Zt(t),r),n&&(r=nr(r,7,Tn));for(var o=e.length;o--;)Fn(r,e[o]);return r})),Zn=Yn,to="[object String]";var eo=kn("length"),ro=RegExp("[\\u200d\\ud800-\\udfff\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff\\ufe0e\\ufe0f]");var no="\\ud800-\\udfff",oo="["+no+"]",uo="[\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff]",io="\\ud83c[\\udffb-\\udfff]",co="[^"+no+"]",ao="(?:\\ud83c[\\udde6-\\uddff]){2}",lo="[\\ud800-\\udbff][\\udc00-\\udfff]",fo="(?:"+uo+"|"+io+")"+"?",so="[\\ufe0e\\ufe0f]?",vo=so+fo+("(?:\\u200d(?:"+[co,ao,lo].join("|")+")"+so+fo+")*"),po="(?:"+[co+uo+"?",uo,ao,lo,oo].join("|")+")",bo=RegExp(io+"(?="+io+")|"+po+vo,"g");function yo(t){return function(t){return ro.test(t)}(t)?function(t){for(var e=bo.lastIndex=0;bo.test(t);)++e;return e}(t):eo(t)}var ho="[object Map]",jo="[object Set]";function go(t){if(null==t)return 0;if(Mt(t))return"string"==typeof(e=t)||!ct(e)&&tt(e)&&g(e)==to?yo(t):t.length;var e,r=be(t);return r==ho||r==jo?t.size:Et(t).length}function _o(){let t,e,r=new Promise((function(){t=arguments[0],e=arguments[1]}));return r.resolve=t,r.reject=e,r}var wo=/\s/;var mo=/^\s+/;function Oo(t){return t?t.slice(0,function(t){for(var e=t.length;e--&&wo.test(t.charAt(e)););return e}(t)+1).replace(mo,""):t}var Ao=NaN,So=/^[-+]0x[0-9a-f]+$/i,ko=/^0b[01]+$/i,Po=/^0o[0-7]+$/i,xo=parseInt;function zo(t){if("number"==typeof t)return t;if(Qr(t))return Ao;if(_(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=_(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=Oo(t);var r=ko.test(t);return r||Po.test(t)?xo(t.slice(2),r?2:8):So.test(t)?Ao:+t}var Bo=1/0,Io=17976931348623157e292;function Eo(t){return t?(t=zo(t))===Bo||t===-Bo?(t<0?-1:1)*Io:t==t?t:0:0===t?t:0}function Mo(t){var e=Eo(t),r=e%1;return e==e?r?e-r:e:0}function Fo(t){return"[object String]"===Object.prototype.toString.call(t)}function Do(t){return!(!Fo(t)||""===t)}function $o(t){return t!=t}function No(t){let e=!1;if(Do(t))e=!isNaN(Number(t));else if(function(t){return"[object Number]"===Object.prototype.toString.call(t)}(t)){if($o(t))return!1;e=!0}return e}function Uo(t){if(!No(t))return 0;return Eo(t)}function Co(t){return!!No(t)&&(t=Uo(t),"number"==typeof(e=t)&&e==Mo(e));var e}var Go=l.isFinite,To=Math.min;var Ro=function(t){var e=Math[t];return function(t,r){if(t=zo(t),(r=null==r?0:To(Mo(r),292))&&Go(t)){var n=(bn(t)+"e").split("e");return+((n=(bn(e(n[0]+"e"+(+n[1]+r)))+"e").split("e"))[0]+"e"+(+n[1]-r))}return e(t)}}("round"),qo=Ro;function Lo(t){if(!No(t))return 0;t=Uo(t);let e=qo(t);return"0"===String(e)?0:e}let Vo="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),Wo=Vo.length;function Ho(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:32,e=[];var r;t=Co(r=t)&&Lo(r)>0?Lo(t):32;for(let r=0;r<t;r++)e[r]=Vo[0|Math.random()*Wo];return e.join("")}var Jo="[object Boolean]";function Ko(t){return!0===(e=t)||!1===e||tt(e)&&g(e)==Jo;var e}function Qo(t){return"[object Array]"===Object.prototype.toString.call(t)}function Xo(t){return"[object Object]"===Object.prototype.toString.call(t)}function Yo(t){return!!function(t){return"[object Undefined]"===Object.prototype.toString.call(t)}(t)||(!!function(t){return"[object Null]"===Object.prototype.toString.call(t)}(t)||(!!function(t){if(Xo(t)){for(let e in t)return!1;return!0}return!1}(t)||(!!function(t){return!(!Fo(t)||""!==t)}(t)||(!!function(t){return!!Qo(t)&&0===t.length}(t)||!!$o(t)))))}function Zo(t){return!!Qo(t)&&(0!==t.length&&(1!==t.length||!Yo(t[0])))}function tu(t){if(Xo(t)){for(let e in t)return!0;return!1}return!1}function eu(t,e){var r;return(ct(t)?H:sr)(t,"function"==typeof(r=e)?r:Sn)}function ru(t){let e=Object.prototype.toString.call(t);return"[object Function]"===e||"[object AsyncFunction]"===e}function nu(t,e){let r=_o();if(!Qo(t)&&!Xo(t))return r.reject("rs is not an array or object"),r;let n=!1;if(Xo(t)){n=!0;let e=[];eu(t,((t,r)=>{e.push({k:r,v:t})})),t=e}ru(e)||(e=function(t){return t});let o=-1,u=[];return t.reduce((function(t,r){return t.then((function(t){u.push(t),o+=1;let i=o,c=r;return n&&(i=r.k,c=r.v),ru(e)?e(c,i):c}))}),Promise.resolve()).then((function(t){var e,n,o,i;u.push(t),i=null==(e=u)?0:e.length,u=i?En(e,(n=o||void 0===n?1:Mo(n))<0?0:n,i):[],r.resolve(u)})).catch((function(t){r.reject(t)})),r}return function(){let n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};n.url||(n.url="mongodb://127.0.0.1:27017"),n.db||(n.db="worm"),n.cl||(n.cl="test");let o=_n(n,"autoGenPk");Ko(o)||(o=!0);let u=!1,i=!1,c=new t.EventEmitter,a=e.MongoClient;function l(t){let e=_n(t,"message");return Do(e)?e:String(t)}function f(t,e,r){try{c.emit("change",t,e,r)}catch(t){console.log(t)}}function s(t,e){if(!Do(t.id)){if(!o)throw new Error(`invalid data[${e}].id, autoGenPk is false`);t.id=Ho()}return t}function d(t){let e=_n(t,"writeErrors");return Zo(e)?zn(e,(function(t){return 11e3===_n(t,"code")||11e3===_n(t,"err.code")})):11e3===_n(t,"code")}async function v(t){u||(await t.createIndex({id:1},{unique:!0}),u=!0)}async function p(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=arguments.length>1?arguments[1]:void 0,r=!1,n=null;try{let r=e.find(t);n=await r.toArray()}catch(t){r=!0,n=t}return r?Promise.reject(n):n}return c.select=async function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=!1,r=new a(n.url),o=null;try{let e=r.db(n.db).collection(n.cl).find(t);o=await e.toArray(),o=In(o,(function(t){return t=Zn(t,"_id")}))}catch(t){e=!0,o=t}finally{await r.close(),r=null}return e?Promise.reject(o):o},c.selectByPk=async function(t){let e=!1;if(!Do(t))return null;let r=new a(n.url),o=null;try{let e=r.db(n.db).collection(n.cl),u=await e.findOne({id:t},{projection:{_id:0}});o=tu(u)?u:null}catch(t){e=!0,o=t}finally{await r.close(),r=null}return e?Promise.reject(o):o},c.insert=async function(t){let e=!1;if(!tu(t)&&!Zo(t))return{n:0,nInserted:0,ok:1};t=ir(t);let r=new a(n.url),o=null;try{await r.connect();let e=r.db(n.db).collection(n.cl);Qo(t)||(t=[t]),t=In(t,s),await v(e);let u=go(t),i=0;try{i=(await e.insertMany(t,{ordered:!1})).insertedCount}catch(t){if(!d(t))throw t;i=_n(t,"result.insertedCount",0)}o={n:u,nInserted:i,ok:1}}catch(t){e=!0,o=t}finally{await r.close(),r=null}return e||f("insert",t,o),e?Promise.reject(o):o},c.save=async function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=!1;if(!tu(t)&&!Zo(t))return[];t=ir(t);let o=_n(e,"autoInsert",!0),u=new a(n.url),i=null;try{await u.connect();let e=u.db(n.db).collection(n.cl);Qo(t)||(t=[t]),t=In(t,s),await v(e),i=await nu(t,(async t=>async function(t,e,r){let n=null,o=!1;for(let u=0;u<3;u++)try{let u=await t.updateOne({id:e.id},{$set:e},{upsert:r}),i=_n(u,"matchedCount",0),c=_n(u,"modifiedCount",0);_n(u,"upsertedCount",0)>0?(n={n:1,nInserted:1,nModified:0,ok:1},o=!0):n=i>0?{n:1,nInserted:0,nModified:c>0?1:0,ok:1}:{n:0,nInserted:0,nModified:0,ok:1};break}catch(t){if(d(t)&&u<2)continue;n={n:1,nInserted:0,nModified:0,ok:0,err:l(t)};break}return o&&f("insert",[e],n),n}(e,t,o)))}catch(t){r=!0,i=t}finally{await u.close(),u=null}return r||f("save",t,i),r?Promise.reject(i):i},c.del=async function(t){let e=!1;if(!tu(t)&&!Zo(t))return[];t=ir(t);let r=new a(n.url),o=null;try{await r.connect();let e=r.db(n.db).collection(n.cl);Qo(t)||(t=[t]),o=await nu(t,(async t=>{let r=_n(t,"id");if(!Do(r))return{n:0,nDeleted:0,ok:0,err:`invalid id[${r}]`};let n=null;try{let t=_n(await e.deleteOne({id:r}),"deletedCount",0);n={n:t,nDeleted:t,ok:1}}catch(t){n={n:1,nDeleted:0,ok:0,err:l(t)}}return n}))}catch(t){e=!0,o=t}finally{await r.close(),r=null}return e||f("del",t,o),e?Promise.reject(o):o},c.delAll=async function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=!1,r=new a(n.url),o=null;try{let e=r.db(n.db).collection(n.cl),u=_n(await e.deleteMany(t),"deletedCount",0);o={n:u,nDeleted:u,ok:1}}catch(t){e=!0,o=t}finally{await r.close(),r=null}return e||f("delAll",null,o),e?Promise.reject(o):o},c.selectByPkGfs=async function(t){let r=!1;if(!Do(t))return null;let o=new a(n.url),u=null;try{u={id:t,u8a:await(async t=>{let r=_o(),u=o.db(n.db),i=new e.GridFSBucket(u,{chunkSizeBytes:10485760,bucketName:n.cl}),c=Buffer.from(""),a=i.openDownloadStreamByName(t);return a.on("data",(function(t){c=Buffer.concat([c,t])})),a.on("error",(function(t){r.reject(t)})),a.on("end",(function(){let t=new Uint8Array(c);c=null,r.resolve(t)})),r})(t)}}catch(t){"ENOENT"===_n(t,"code")?u=null:(r=!0,u=t)}finally{await o.close(),o=null}return r?Promise.reject(u):u},c.insertGfs=async function(t){let o=!1;if(!tu(t)&&!Zo(t))return{n:0,nInserted:0,ok:1};let u=new a(n.url),c=null;try{await u.connect();let o=u.db(n.db),a=new e.GridFSBucket(o,{chunkSizeBytes:10485760,bucketName:n.cl}),l=o.collection(`${n.cl}.chunks`);Qo(t)||(t=[t]),t=In(t,(function(t,e){if(!function(t){return"[object Uint8Array]"===Object.prototype.toString.call(t)}((t=s(t={...t},e)).u8a))throw new Error(`invalid data[${e}].u8a`);return t})),await async function(t){i||(await t.collection(`${n.cl}.files`).createIndex({filename:1},{unique:!0}),i=!0)}(o);let f=go(t),v=0;await nu(t,(async t=>{let e=await function(t,e,n,o){let u=_o(),i=t.openUploadStream(n),c=i.id,a=new r.Readable;return a._read=()=>{},a.push(Buffer.from(o)),a.push(null),a.pipe(i).on("error",(function(t){d(t)?e.deleteMany({files_id:c}).then((function(){u.resolve(!1)})).catch((function(t){u.reject(t)})):u.reject(t)})).on("finish",(function(){u.resolve(!0)})),u}(a,l,t.id,t.u8a);e&&v++})),c={n:f,nInserted:v,ok:1}}catch(t){o=!0,c=t}finally{await u.close(),u=null}return o||f("insertGfs",t,c),o?Promise.reject(c):c},c.delGfs=async function(t){let r=!1;if(!tu(t)&&!Zo(t))return[];let o=new a(n.url),u=null;try{await o.connect();let r=o.db(n.db),i=new e.GridFSBucket(r,{chunkSizeBytes:10485760,bucketName:n.cl});Qo(t)||(t=[t]),u=await nu(t,(async t=>{let e=_n(t,"id");if(!Do(e))return{n:0,nDeleted:0,ok:0,err:`invalid id[${e}]`};let r=null;try{let t=await p({filename:e},i),n=0;for(let e of t)await i.delete(e._id),n++;r={n:n>0?1:0,nDeleted:n,ok:1}}catch(t){r={n:1,nDeleted:0,ok:0,err:l(t)}}return r}))}catch(t){r=!0,u=t}finally{await o.close(),o=null}return r||f("delGfs",t,u),r?Promise.reject(u):u},c.delAllGfs=async function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=!1,o=new a(n.url),u=null;try{let r=o.db(n.db),i=new e.GridFSBucket(r,{chunkSizeBytes:10485760,bucketName:n.cl}),c=await p(t,i),a=In(c,(function(t){return async function(t,e){await e.delete(t)}(t._id,i)}));await Promise.all(a);let l=go(c);u={n:l,nDeleted:l,ok:1}}catch(t){r=!0,u=t}finally{await o.close(),o=null}return r||f("delAllGfs",null,u),r?Promise.reject(u):u},c}}));
|
|
6
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("mongodb"),require("stream")):"function"==typeof define&&define.amd?define(["mongodb","stream"],e):(t="undefined"!=typeof globalThis?globalThis:t||self)["w-orm-mongodb"]=e(t.mongodb,t.stream)}(this,(function(t,e){"use strict";function n(t,e){return t===e||t!=t&&e!=e}function r(t,e){for(var r=t.length;r--;)if(n(t[r][0],e))return r;return-1}var o=Array.prototype.splice;function u(t){var e=-1,n=null==t?0:t.length;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}u.prototype.clear=function(){this.__data__=[],this.size=0},u.prototype.delete=function(t){var e=this.__data__,n=r(e,t);return!(n<0)&&(n==e.length-1?e.pop():o.call(e,n,1),--this.size,!0)},u.prototype.get=function(t){var e=this.__data__,n=r(e,t);return n<0?void 0:e[n][1]},u.prototype.has=function(t){return r(this.__data__,t)>-1},u.prototype.set=function(t,e){var n=this.__data__,o=r(n,t);return o<0?(++this.size,n.push([t,e])):n[o][1]=e,this};var c="object"==typeof global&&global&&global.Object===Object&&global,i="object"==typeof self&&self&&self.Object===Object&&self,a=c||i||Function("return this")(),l=a.Symbol,f=Object.prototype,s=f.hasOwnProperty,v=f.toString,p=l?l.toStringTag:void 0;var d=Object.prototype.toString;var y="[object Null]",b="[object Undefined]",h=l?l.toStringTag:void 0;function j(t){return null==t?void 0===t?b:y:h&&h in Object(t)?function(t){var e=s.call(t,p),n=t[p];try{t[p]=void 0;var r=!0}catch(t){}var o=v.call(t);return r&&(e?t[p]=n:delete t[p]),o}(t):function(t){return d.call(t)}(t)}function g(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}var _="[object AsyncFunction]",w="[object Function]",m="[object GeneratorFunction]",O="[object Proxy]";function A(t){if(!g(t))return!1;var e=j(t);return e==w||e==m||e==_||e==O}var k,x=a["__core-js_shared__"],S=(k=/[^.]+$/.exec(x&&x.keys&&x.keys.IE_PROTO||""))?"Symbol(src)_1."+k:"";var P=Function.prototype.toString;function z(t){if(null!=t){try{return P.call(t)}catch(t){}try{return t+""}catch(t){}}return""}var B=/^\[object .+?Constructor\]$/,E=Function.prototype,I=Object.prototype,C=E.toString,D=I.hasOwnProperty,U=RegExp("^"+C.call(D).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function $(t){return!(!g(t)||(e=t,S&&S in e))&&(A(t)?U:B).test(z(t));var e}function F(t,e){var n=function(t,e){return null==t?void 0:t[e]}(t,e);return $(n)?n:void 0}var M=F(a,"Map"),G=F(Object,"create");var N=Object.prototype.hasOwnProperty;var T=Object.prototype.hasOwnProperty;function L(t){var e=-1,n=null==t?0:t.length;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function q(t,e){var n,r,o=t.__data__;return("string"==(r=typeof(n=e))||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==n:null===n)?o["string"==typeof e?"string":"hash"]:o.map}function R(t){var e=-1,n=null==t?0:t.length;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}L.prototype.clear=function(){this.__data__=G?G(null):{},this.size=0},L.prototype.delete=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},L.prototype.get=function(t){var e=this.__data__;if(G){var n=e[t];return"__lodash_hash_undefined__"===n?void 0:n}return N.call(e,t)?e[t]:void 0},L.prototype.has=function(t){var e=this.__data__;return G?void 0!==e[t]:T.call(e,t)},L.prototype.set=function(t,e){var n=this.__data__;return this.size+=this.has(t)?0:1,n[t]=G&&void 0===e?"__lodash_hash_undefined__":e,this},R.prototype.clear=function(){this.size=0,this.__data__={hash:new L,map:new(M||u),string:new L}},R.prototype.delete=function(t){var e=q(this,t).delete(t);return this.size-=e?1:0,e},R.prototype.get=function(t){return q(this,t).get(t)},R.prototype.has=function(t){return q(this,t).has(t)},R.prototype.set=function(t,e){var n=q(this,t),r=n.size;return n.set(t,e),this.size+=n.size==r?0:1,this};function V(t){var e=this.__data__=new u(t);this.size=e.size}function W(t,e){for(var n=-1,r=null==t?0:t.length;++n<r&&!1!==e(t[n],n,t););return t}V.prototype.clear=function(){this.__data__=new u,this.size=0},V.prototype.delete=function(t){var e=this.__data__,n=e.delete(t);return this.size=e.size,n},V.prototype.get=function(t){return this.__data__.get(t)},V.prototype.has=function(t){return this.__data__.has(t)},V.prototype.set=function(t,e){var n=this.__data__;if(n instanceof u){var r=n.__data__;if(!M||r.length<199)return r.push([t,e]),this.size=++n.size,this;n=this.__data__=new R(r)}return n.set(t,e),this.size=n.size,this};var H=function(){try{var t=F(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),J=H;function K(t,e,n){"__proto__"==e&&J?J(t,e,{configurable:!0,enumerable:!0,value:n,writable:!0}):t[e]=n}var Q=Object.prototype.hasOwnProperty;function X(t,e,r){var o=t[e];Q.call(t,e)&&n(o,r)&&(void 0!==r||e in t)||K(t,e,r)}function Y(t,e,n,r){var o=!n;n||(n={});for(var u=-1,c=e.length;++u<c;){var i=e[u],a=r?r(n[i],t[i],i,n,t):void 0;void 0===a&&(a=t[i]),o?K(n,i,a):X(n,i,a)}return n}function Z(t){return null!=t&&"object"==typeof t}function tt(t){return Z(t)&&"[object Arguments]"==j(t)}var et=Object.prototype,nt=et.hasOwnProperty,rt=et.propertyIsEnumerable,ot=tt(function(){return arguments}())?tt:function(t){return Z(t)&&nt.call(t,"callee")&&!rt.call(t,"callee")},ut=ot,ct=Array.isArray;var it="object"==typeof exports&&exports&&!exports.nodeType&&exports,at=it&&"object"==typeof module&&module&&!module.nodeType&&module,lt=at&&at.exports===it?a.Buffer:void 0,ft=(lt?lt.isBuffer:void 0)||function(){return!1},st=9007199254740991,vt=/^(?:0|[1-9]\d*)$/;function pt(t,e){var n=typeof t;return!!(e=null==e?st:e)&&("number"==n||"symbol"!=n&&vt.test(t))&&t>-1&&t%1==0&&t<e}var dt=9007199254740991;function yt(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=dt}var bt={};function ht(t){return function(e){return t(e)}}bt["[object Float32Array]"]=bt["[object Float64Array]"]=bt["[object Int8Array]"]=bt["[object Int16Array]"]=bt["[object Int32Array]"]=bt["[object Uint8Array]"]=bt["[object Uint8ClampedArray]"]=bt["[object Uint16Array]"]=bt["[object Uint32Array]"]=!0,bt["[object Arguments]"]=bt["[object Array]"]=bt["[object ArrayBuffer]"]=bt["[object Boolean]"]=bt["[object DataView]"]=bt["[object Date]"]=bt["[object Error]"]=bt["[object Function]"]=bt["[object Map]"]=bt["[object Number]"]=bt["[object Object]"]=bt["[object RegExp]"]=bt["[object Set]"]=bt["[object String]"]=bt["[object WeakMap]"]=!1;var jt="object"==typeof exports&&exports&&!exports.nodeType&&exports,gt=jt&&"object"==typeof module&&module&&!module.nodeType&&module,_t=gt&>.exports===jt&&c.process,wt=function(){try{var t=gt&>.require&>.require("util").types;return t||_t&&_t.binding&&_t.binding("util")}catch(t){}}(),mt=wt&&wt.isTypedArray,Ot=mt?ht(mt):function(t){return Z(t)&&yt(t.length)&&!!bt[j(t)]},At=Object.prototype.hasOwnProperty;function kt(t,e){var n=ct(t),r=!n&&ut(t),o=!n&&!r&&ft(t),u=!n&&!r&&!o&&Ot(t),c=n||r||o||u,i=c?function(t,e){for(var n=-1,r=Array(t);++n<t;)r[n]=e(n);return r}(t.length,String):[],a=i.length;for(var l in t)!e&&!At.call(t,l)||c&&("length"==l||o&&("offset"==l||"parent"==l)||u&&("buffer"==l||"byteLength"==l||"byteOffset"==l)||pt(l,a))||i.push(l);return i}var xt=Object.prototype;function St(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||xt)}function Pt(t,e){return function(n){return t(e(n))}}var zt=Pt(Object.keys,Object),Bt=Object.prototype.hasOwnProperty;function Et(t){if(!St(t))return zt(t);var e=[];for(var n in Object(t))Bt.call(t,n)&&"constructor"!=n&&e.push(n);return e}function It(t){return null!=t&&yt(t.length)&&!A(t)}function Ct(t){return It(t)?kt(t):Et(t)}var Dt=Object.prototype.hasOwnProperty;function Ut(t){if(!g(t))return function(t){var e=[];if(null!=t)for(var n in Object(t))e.push(n);return e}(t);var e=St(t),n=[];for(var r in t)("constructor"!=r||!e&&Dt.call(t,r))&&n.push(r);return n}function $t(t){return It(t)?kt(t,!0):Ut(t)}var Ft="object"==typeof exports&&exports&&!exports.nodeType&&exports,Mt=Ft&&"object"==typeof module&&module&&!module.nodeType&&module,Gt=Mt&&Mt.exports===Ft?a.Buffer:void 0,Nt=Gt?Gt.allocUnsafe:void 0;function Tt(){return[]}var Lt=Object.prototype.propertyIsEnumerable,qt=Object.getOwnPropertySymbols,Rt=qt?function(t){return null==t?[]:(t=Object(t),function(t,e){for(var n=-1,r=null==t?0:t.length,o=0,u=[];++n<r;){var c=t[n];e(c,n,t)&&(u[o++]=c)}return u}(qt(t),(function(e){return Lt.call(t,e)})))}:Tt,Vt=Rt;function Wt(t,e){for(var n=-1,r=e.length,o=t.length;++n<r;)t[o+n]=e[n];return t}var Ht=Pt(Object.getPrototypeOf,Object),Jt=Object.getOwnPropertySymbols?function(t){for(var e=[];t;)Wt(e,Vt(t)),t=Ht(t);return e}:Tt,Kt=Jt;function Qt(t,e,n){var r=e(t);return ct(t)?r:Wt(r,n(t))}function Xt(t){return Qt(t,Ct,Vt)}function Yt(t){return Qt(t,$t,Kt)}var Zt=F(a,"DataView"),te=F(a,"Promise"),ee=F(a,"Set"),ne=F(a,"WeakMap"),re="[object Map]",oe="[object Promise]",ue="[object Set]",ce="[object WeakMap]",ie="[object DataView]",ae=z(Zt),le=z(M),fe=z(te),se=z(ee),ve=z(ne),pe=j;(Zt&&pe(new Zt(new ArrayBuffer(1)))!=ie||M&&pe(new M)!=re||te&&pe(te.resolve())!=oe||ee&&pe(new ee)!=ue||ne&&pe(new ne)!=ce)&&(pe=function(t){var e=j(t),n="[object Object]"==e?t.constructor:void 0,r=n?z(n):"";if(r)switch(r){case ae:return ie;case le:return re;case fe:return oe;case se:return ue;case ve:return ce}return e});var de=pe,ye=Object.prototype.hasOwnProperty;var be=a.Uint8Array;function he(t){var e=new t.constructor(t.byteLength);return new be(e).set(new be(t)),e}var je=/\w*$/;var ge=l?l.prototype:void 0,_e=ge?ge.valueOf:void 0;var we="[object Boolean]",me="[object Date]",Oe="[object Map]",Ae="[object Number]",ke="[object RegExp]",xe="[object Set]",Se="[object String]",Pe="[object Symbol]",ze="[object ArrayBuffer]",Be="[object DataView]",Ee="[object Float32Array]",Ie="[object Float64Array]",Ce="[object Int8Array]",De="[object Int16Array]",Ue="[object Int32Array]",$e="[object Uint8Array]",Fe="[object Uint8ClampedArray]",Me="[object Uint16Array]",Ge="[object Uint32Array]";function Ne(t,e,n){var r,o,u,c=t.constructor;switch(e){case ze:return he(t);case we:case me:return new c(+t);case Be:return function(t,e){var n=e?he(t.buffer):t.buffer;return new t.constructor(n,t.byteOffset,t.byteLength)}(t,n);case Ee:case Ie:case Ce:case De:case Ue:case $e:case Fe:case Me:case Ge:return function(t,e){var n=e?he(t.buffer):t.buffer;return new t.constructor(n,t.byteOffset,t.length)}(t,n);case Oe:return new c;case Ae:case Se:return new c(t);case ke:return(u=new(o=t).constructor(o.source,je.exec(o))).lastIndex=o.lastIndex,u;case xe:return new c;case Pe:return r=t,_e?Object(_e.call(r)):{}}}var Te=Object.create,Le=function(){function t(){}return function(e){if(!g(e))return{};if(Te)return Te(e);t.prototype=e;var n=new t;return t.prototype=void 0,n}}(),qe=Le;var Re=wt&&wt.isMap,Ve=Re?ht(Re):function(t){return Z(t)&&"[object Map]"==de(t)};var We=wt&&wt.isSet,He=We?ht(We):function(t){return Z(t)&&"[object Set]"==de(t)},Je=1,Ke=2,Qe=4,Xe="[object Arguments]",Ye="[object Function]",Ze="[object GeneratorFunction]",tn="[object Object]",en={};function nn(t,e,n,r,o,u){var c,i=e&Je,a=e&Ke,l=e&Qe;if(n&&(c=o?n(t,r,o,u):n(t)),void 0!==c)return c;if(!g(t))return t;var f=ct(t);if(f){if(c=function(t){var e=t.length,n=new t.constructor(e);return e&&"string"==typeof t[0]&&ye.call(t,"index")&&(n.index=t.index,n.input=t.input),n}(t),!i)return function(t,e){var n=-1,r=t.length;for(e||(e=Array(r));++n<r;)e[n]=t[n];return e}(t,c)}else{var s=de(t),v=s==Ye||s==Ze;if(ft(t))return function(t,e){if(e)return t.slice();var n=t.length,r=Nt?Nt(n):new t.constructor(n);return t.copy(r),r}(t,i);if(s==tn||s==Xe||v&&!o){if(c=a||v?{}:function(t){return"function"!=typeof t.constructor||St(t)?{}:qe(Ht(t))}(t),!i)return a?function(t,e){return Y(t,Kt(t),e)}(t,function(t,e){return t&&Y(e,$t(e),t)}(c,t)):function(t,e){return Y(t,Vt(t),e)}(t,function(t,e){return t&&Y(e,Ct(e),t)}(c,t))}else{if(!en[s])return o?t:{};c=Ne(t,s,i)}}u||(u=new V);var p=u.get(t);if(p)return p;u.set(t,c),He(t)?t.forEach((function(r){c.add(nn(r,e,n,r,t,u))})):Ve(t)&&t.forEach((function(r,o){c.set(o,nn(r,e,n,o,t,u))}));var d=f?void 0:(l?a?Yt:Xt:a?$t:Ct)(t);return W(d||t,(function(r,o){d&&(r=t[o=r]),X(c,o,nn(r,e,n,o,t,u))})),c}en[Xe]=en["[object Array]"]=en["[object ArrayBuffer]"]=en["[object DataView]"]=en["[object Boolean]"]=en["[object Date]"]=en["[object Float32Array]"]=en["[object Float64Array]"]=en["[object Int8Array]"]=en["[object Int16Array]"]=en["[object Int32Array]"]=en["[object Map]"]=en["[object Number]"]=en[tn]=en["[object RegExp]"]=en["[object Set]"]=en["[object String]"]=en["[object Symbol]"]=en["[object Uint8Array]"]=en["[object Uint8ClampedArray]"]=en["[object Uint16Array]"]=en["[object Uint32Array]"]=!0,en["[object Error]"]=en[Ye]=en["[object WeakMap]"]=!1;var rn=1,on=4;function un(t){return nn(t,rn|on)}function cn(t,e){for(var n=-1,r=null==t?0:t.length;++n<r;)if(!e(t[n],n,t))return!1;return!0}var an,ln=function(t,e,n){for(var r=-1,o=Object(t),u=n(t),c=u.length;c--;){var i=u[an?c:++r];if(!1===e(o[i],i,o))break}return t};var fn=function(t,e){return function(n,r){if(null==n)return n;if(!It(n))return t(n,r);for(var o=n.length,u=e?o:-1,c=Object(n);(e?u--:++u<o)&&!1!==r(c[u],u,c););return n}}((function(t,e){return t&&ln(t,e,Ct)})),sn=fn;function vn(t,e){var n=!0;return sn(t,(function(t,r,o){return n=!!e(t,r,o)})),n}function pn(t){var e=-1,n=null==t?0:t.length;for(this.__data__=new R;++e<n;)this.add(t[e])}function dn(t,e){for(var n=-1,r=null==t?0:t.length;++n<r;)if(e(t[n],n,t))return!0;return!1}pn.prototype.add=pn.prototype.push=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this},pn.prototype.has=function(t){return this.__data__.has(t)};var yn=1,bn=2;function hn(t,e,n,r,o,u){var c=n&yn,i=t.length,a=e.length;if(i!=a&&!(c&&a>i))return!1;var l=u.get(t),f=u.get(e);if(l&&f)return l==e&&f==t;var s=-1,v=!0,p=n&bn?new pn:void 0;for(u.set(t,e),u.set(e,t);++s<i;){var d=t[s],y=e[s];if(r)var b=c?r(y,d,s,e,t,u):r(d,y,s,t,e,u);if(void 0!==b){if(b)continue;v=!1;break}if(p){if(!dn(e,(function(t,e){if(c=e,!p.has(c)&&(d===t||o(d,t,n,r,u)))return p.push(e);var c}))){v=!1;break}}else if(d!==y&&!o(d,y,n,r,u)){v=!1;break}}return u.delete(t),u.delete(e),v}function jn(t){var e=-1,n=Array(t.size);return t.forEach((function(t,r){n[++e]=[r,t]})),n}function gn(t){var e=-1,n=Array(t.size);return t.forEach((function(t){n[++e]=t})),n}var _n=1,wn=2,mn="[object Boolean]",On="[object Date]",An="[object Error]",kn="[object Map]",xn="[object Number]",Sn="[object RegExp]",Pn="[object Set]",zn="[object String]",Bn="[object Symbol]",En="[object ArrayBuffer]",In="[object DataView]",Cn=l?l.prototype:void 0,Dn=Cn?Cn.valueOf:void 0;var Un=1,$n=Object.prototype.hasOwnProperty;var Fn=1,Mn="[object Arguments]",Gn="[object Array]",Nn="[object Object]",Tn=Object.prototype.hasOwnProperty;function Ln(t,e,r,o,u,c){var i=ct(t),a=ct(e),l=i?Gn:de(t),f=a?Gn:de(e),s=(l=l==Mn?Nn:l)==Nn,v=(f=f==Mn?Nn:f)==Nn,p=l==f;if(p&&ft(t)){if(!ft(e))return!1;i=!0,s=!1}if(p&&!s)return c||(c=new V),i||Ot(t)?hn(t,e,r,o,u,c):function(t,e,r,o,u,c,i){switch(r){case In:if(t.byteLength!=e.byteLength||t.byteOffset!=e.byteOffset)return!1;t=t.buffer,e=e.buffer;case En:return!(t.byteLength!=e.byteLength||!c(new be(t),new be(e)));case mn:case On:case xn:return n(+t,+e);case An:return t.name==e.name&&t.message==e.message;case Sn:case zn:return t==e+"";case kn:var a=jn;case Pn:var l=o&_n;if(a||(a=gn),t.size!=e.size&&!l)return!1;var f=i.get(t);if(f)return f==e;o|=wn,i.set(t,e);var s=hn(a(t),a(e),o,u,c,i);return i.delete(t),s;case Bn:if(Dn)return Dn.call(t)==Dn.call(e)}return!1}(t,e,l,r,o,u,c);if(!(r&Fn)){var d=s&&Tn.call(t,"__wrapped__"),y=v&&Tn.call(e,"__wrapped__");if(d||y){var b=d?t.value():t,h=y?e.value():e;return c||(c=new V),u(b,h,r,o,c)}}return!!p&&(c||(c=new V),function(t,e,n,r,o,u){var c=n&Un,i=Xt(t),a=i.length;if(a!=Xt(e).length&&!c)return!1;for(var l=a;l--;){var f=i[l];if(!(c?f in e:$n.call(e,f)))return!1}var s=u.get(t),v=u.get(e);if(s&&v)return s==e&&v==t;var p=!0;u.set(t,e),u.set(e,t);for(var d=c;++l<a;){var y=t[f=i[l]],b=e[f];if(r)var h=c?r(b,y,f,e,t,u):r(y,b,f,t,e,u);if(!(void 0===h?y===b||o(y,b,n,r,u):h)){p=!1;break}d||(d="constructor"==f)}if(p&&!d){var j=t.constructor,g=e.constructor;j==g||!("constructor"in t)||!("constructor"in e)||"function"==typeof j&&j instanceof j&&"function"==typeof g&&g instanceof g||(p=!1)}return u.delete(t),u.delete(e),p}(t,e,r,o,u,c))}function qn(t,e,n,r,o){return t===e||(null==t||null==e||!Z(t)&&!Z(e)?t!=t&&e!=e:Ln(t,e,n,r,qn,o))}var Rn=1,Vn=2;function Wn(t){return t==t&&!g(t)}function Hn(t,e){return function(n){return null!=n&&(n[t]===e&&(void 0!==e||t in Object(n)))}}function Jn(t){var e=function(t){for(var e=Ct(t),n=e.length;n--;){var r=e[n],o=t[r];e[n]=[r,o,Wn(o)]}return e}(t);return 1==e.length&&e[0][2]?Hn(e[0][0],e[0][1]):function(n){return n===t||function(t,e,n,r){var o=n.length,u=o,c=!r;if(null==t)return!u;for(t=Object(t);o--;){var i=n[o];if(c&&i[2]?i[1]!==t[i[0]]:!(i[0]in t))return!1}for(;++o<u;){var a=(i=n[o])[0],l=t[a],f=i[1];if(c&&i[2]){if(void 0===l&&!(a in t))return!1}else{var s=new V;if(r)var v=r(l,f,a,t,e,s);if(!(void 0===v?qn(f,l,Rn|Vn,r,s):v))return!1}}return!0}(n,t,e)}}var Kn="[object Symbol]";function Qn(t){return"symbol"==typeof t||Z(t)&&j(t)==Kn}var Xn=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,Yn=/^\w*$/;function Zn(t,e){if(ct(t))return!1;var n=typeof t;return!("number"!=n&&"symbol"!=n&&"boolean"!=n&&null!=t&&!Qn(t))||(Yn.test(t)||!Xn.test(t)||null!=e&&t in Object(e))}var tr="Expected a function";function er(t,e){if("function"!=typeof t||null!=e&&"function"!=typeof e)throw new TypeError(tr);var n=function(){var r=arguments,o=e?e.apply(this,r):r[0],u=n.cache;if(u.has(o))return u.get(o);var c=t.apply(this,r);return n.cache=u.set(o,c)||u,c};return n.cache=new(er.Cache||R),n}er.Cache=R;var nr,rr,or,ur=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,cr=/\\(\\)?/g,ir=(nr=function(t){var e=[];return 46===t.charCodeAt(0)&&e.push(""),t.replace(ur,(function(t,n,r,o){e.push(r?o.replace(cr,"$1"):n||t)})),e},rr=er(nr,(function(t){return 500===or.size&&or.clear(),t})),or=rr.cache,rr),ar=ir;function lr(t,e){for(var n=-1,r=null==t?0:t.length,o=Array(r);++n<r;)o[n]=e(t[n],n,t);return o}var fr=1/0,sr=l?l.prototype:void 0,vr=sr?sr.toString:void 0;function pr(t){if("string"==typeof t)return t;if(ct(t))return lr(t,pr)+"";if(Qn(t))return vr?vr.call(t):"";var e=t+"";return"0"==e&&1/t==-fr?"-0":e}function dr(t,e){return ct(t)?t:Zn(t,e)?[t]:ar(function(t){return null==t?"":pr(t)}(t))}var yr=1/0;function br(t){if("string"==typeof t||Qn(t))return t;var e=t+"";return"0"==e&&1/t==-yr?"-0":e}function hr(t,e){for(var n=0,r=(e=dr(e,t)).length;null!=t&&n<r;)t=t[br(e[n++])];return n&&n==r?t:void 0}function jr(t,e,n){var r=null==t?void 0:hr(t,e);return void 0===r?n:r}function gr(t,e){return null!=t&&e in Object(t)}function _r(t,e){return null!=t&&function(t,e,n){for(var r=-1,o=(e=dr(e,t)).length,u=!1;++r<o;){var c=br(e[r]);if(!(u=null!=t&&n(t,c)))break;t=t[c]}return u||++r!=o?u:!!(o=null==t?0:t.length)&&yt(o)&&pt(c,o)&&(ct(t)||ut(t))}(t,e,gr)}var wr=1,mr=2;function Or(t){return t}function Ar(t){return function(e){return null==e?void 0:e[t]}}function kr(t){return Zn(t)?Ar(br(t)):function(t){return function(e){return hr(e,t)}}(t)}function xr(t){return"function"==typeof t?t:null==t?Or:"object"==typeof t?ct(t)?(e=t[0],n=t[1],Zn(e)&&Wn(n)?Hn(br(e),n):function(t){var r=jr(t,e);return void 0===r&&r===n?_r(t,e):qn(n,r,wr|mr)}):Jn(t):kr(t);var e,n}function Sr(t,e,r){var o=ct(t)?cn:vn;return r&&function(t,e,r){if(!g(r))return!1;var o=typeof e;return!!("number"==o?It(r)&&pt(e,r.length):"string"==o&&e in r)&&n(r[e],t)}(t,e,r)&&(e=void 0),o(t,xr(e))}function Pr(t,e){var n=-1,r=It(t)?Array(t.length):[];return sn(t,(function(t,o,u){r[++n]=e(t,o,u)})),r}function zr(t,e){return(ct(t)?lr:Pr)(t,xr(e))}function Br(t,e,n){var r=-1,o=t.length;e<0&&(e=-e>o?0:o+e),(n=n>o?o:n)<0&&(n+=o),o=e>n?0:n-e>>>0,e>>>=0;for(var u=Array(o);++r<o;)u[r]=t[r+e];return u}var Er=Object.prototype.hasOwnProperty;function Ir(t,e){var n=-1,r=(e=dr(e,t)).length;if(!r)return!0;for(;++n<r;){var o=br(e[n]);if("__proto__"===o&&!Er.call(t,"__proto__"))return!1;if(("constructor"===o||"prototype"===o)&&n<r-1)return!1}var u=function(t,e){return e.length<2?t:hr(t,Br(e,0,-1))}(t,e);return null==u||delete u[br(function(t){var e=null==t?0:t.length;return e?t[e-1]:void 0}(e))]}var Cr="[object Object]",Dr=Function.prototype,Ur=Object.prototype,$r=Dr.toString,Fr=Ur.hasOwnProperty,Mr=$r.call(Object);function Gr(t){return function(t){if(!Z(t)||j(t)!=Cr)return!1;var e=Ht(t);if(null===e)return!0;var n=Fr.call(e,"constructor")&&e.constructor;return"function"==typeof n&&n instanceof n&&$r.call(n)==Mr}(t)?void 0:t}var Nr=l?l.isConcatSpreadable:void 0;function Tr(t){return ct(t)||ut(t)||!!(Nr&&t&&t[Nr])}function Lr(t,e,n,r,o){var u=-1,c=t.length;for(n||(n=Tr),o||(o=[]);++u<c;){var i=t[u];e>0&&n(i)?e>1?Lr(i,e-1,n,r,o):Wt(o,i):r||(o[o.length]=i)}return o}function qr(t){return(null==t?0:t.length)?Lr(t,1):[]}var Rr=Math.max;var Vr=J?function(t,e){return J(t,"toString",{configurable:!0,enumerable:!1,value:(n=e,function(){return n}),writable:!0});var n}:Or,Wr=Vr,Hr=Date.now;var Jr=function(t){var e=0,n=0;return function(){var r=Hr(),o=16-(r-n);if(n=r,o>0){if(++e>=800)return arguments[0]}else e=0;return t.apply(void 0,arguments)}}(Wr),Kr=Jr;var Qr=function(t){return Kr(function(t,e,n){return e=Rr(void 0===e?t.length-1:e,0),function(){for(var r=arguments,o=-1,u=Rr(r.length-e,0),c=Array(u);++o<u;)c[o]=r[e+o];o=-1;for(var i=Array(e+1);++o<e;)i[o]=r[o];return i[e]=n(c),function(t,e,n){switch(n.length){case 0:return t.call(e);case 1:return t.call(e,n[0]);case 2:return t.call(e,n[0],n[1]);case 3:return t.call(e,n[0],n[1],n[2])}return t.apply(e,n)}(t,this,i)}}(t,void 0,qr),t+"")}((function(t,e){var n={};if(null==t)return n;var r=!1;e=lr(e,(function(e){return e=dr(e,t),r||(r=e.length>1),e})),Y(t,Yt(t),n),r&&(n=nn(n,7,Gr));for(var o=e.length;o--;)Ir(n,e[o]);return n})),Xr=Qr,Yr="[object String]";var Zr=Ar("length"),to=RegExp("[\\u200d\\ud800-\\udfff\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff\\ufe0e\\ufe0f]");var eo="\\ud800-\\udfff",no="["+eo+"]",ro="[\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff]",oo="\\ud83c[\\udffb-\\udfff]",uo="[^"+eo+"]",co="(?:\\ud83c[\\udde6-\\uddff]){2}",io="[\\ud800-\\udbff][\\udc00-\\udfff]",ao="(?:"+ro+"|"+oo+")"+"?",lo="[\\ufe0e\\ufe0f]?",fo=lo+ao+("(?:\\u200d(?:"+[uo,co,io].join("|")+")"+lo+ao+")*"),so="(?:"+[uo+ro+"?",ro,co,io,no].join("|")+")",vo=RegExp(oo+"(?="+oo+")|"+so+fo,"g");function po(t){return function(t){return to.test(t)}(t)?function(t){for(var e=vo.lastIndex=0;vo.test(t);)++e;return e}(t):Zr(t)}var yo="[object Map]",bo="[object Set]";function ho(t){if(null==t)return 0;if(It(t))return"string"==typeof(e=t)||!ct(e)&&Z(e)&&j(e)==Yr?po(t):t.length;var e,n=de(t);return n==yo||n==bo?t.size:Et(t).length}var jo={};!function(t){var e=Object.prototype.hasOwnProperty,n="~";function r(){}function o(t,e,n){this.fn=t,this.context=e,this.once=n||!1}function u(t,e,r,u,c){if("function"!=typeof r)throw new TypeError("The listener must be a function");var i=new o(r,u||t,c),a=n?n+e:e;return t._events[a]?t._events[a].fn?t._events[a]=[t._events[a],i]:t._events[a].push(i):(t._events[a]=i,t._eventsCount++),t}function c(t,e){0==--t._eventsCount?t._events=new r:delete t._events[e]}function i(){this._events=new r,this._eventsCount=0}Object.create&&(r.prototype=Object.create(null),(new r).__proto__||(n=!1)),i.prototype.eventNames=function(){var t,r,o=[];if(0===this._eventsCount)return o;for(r in t=this._events)e.call(t,r)&&o.push(n?r.slice(1):r);return Object.getOwnPropertySymbols?o.concat(Object.getOwnPropertySymbols(t)):o},i.prototype.listeners=function(t){var e=n?n+t:t,r=this._events[e];if(!r)return[];if(r.fn)return[r.fn];for(var o=0,u=r.length,c=new Array(u);o<u;o++)c[o]=r[o].fn;return c},i.prototype.listenerCount=function(t){var e=n?n+t:t,r=this._events[e];return r?r.fn?1:r.length:0},i.prototype.emit=function(t,e,r,o,u,c){var i=n?n+t:t;if(!this._events[i])return!1;var a,l,f=this._events[i],s=arguments.length;if(f.fn){switch(f.once&&this.removeListener(t,f.fn,void 0,!0),s){case 1:return f.fn.call(f.context),!0;case 2:return f.fn.call(f.context,e),!0;case 3:return f.fn.call(f.context,e,r),!0;case 4:return f.fn.call(f.context,e,r,o),!0;case 5:return f.fn.call(f.context,e,r,o,u),!0;case 6:return f.fn.call(f.context,e,r,o,u,c),!0}for(l=1,a=new Array(s-1);l<s;l++)a[l-1]=arguments[l];f.fn.apply(f.context,a)}else{var v,p=f.length;for(l=0;l<p;l++)switch(f[l].once&&this.removeListener(t,f[l].fn,void 0,!0),s){case 1:f[l].fn.call(f[l].context);break;case 2:f[l].fn.call(f[l].context,e);break;case 3:f[l].fn.call(f[l].context,e,r);break;case 4:f[l].fn.call(f[l].context,e,r,o);break;default:if(!a)for(v=1,a=new Array(s-1);v<s;v++)a[v-1]=arguments[v];f[l].fn.apply(f[l].context,a)}}return!0},i.prototype.on=function(t,e,n){return u(this,t,e,n,!1)},i.prototype.once=function(t,e,n){return u(this,t,e,n,!0)},i.prototype.removeListener=function(t,e,r,o){var u=n?n+t:t;if(!this._events[u])return this;if(!e)return c(this,u),this;var i=this._events[u];if(i.fn)i.fn!==e||o&&!i.once||r&&i.context!==r||c(this,u);else{for(var a=0,l=[],f=i.length;a<f;a++)(i[a].fn!==e||o&&!i[a].once||r&&i[a].context!==r)&&l.push(i[a]);l.length?this._events[u]=1===l.length?l[0]:l:c(this,u)}return this},i.prototype.removeAllListeners=function(t){var e;return t?(e=n?n+t:t,this._events[e]&&c(this,e)):(this._events=new r,this._eventsCount=0),this},i.prototype.off=i.prototype.removeListener,i.prototype.addListener=i.prototype.on,i.prefixed=n,i.EventEmitter=i,t.exports=i}({get exports(){return jo},set exports(t){jo=t}});var go=jo;function _o(){let t,e,n=new Promise((function(){t=arguments[0],e=arguments[1]}));return n.resolve=t,n.reject=e,n}const wo=[];for(let t=0;t<256;++t)wo.push((t+256).toString(16).slice(1));const mo=new Uint8Array(16);function Oo(){return crypto.getRandomValues(mo)}const Ao={};function ko(t,e,n){let r;if(t)r=xo(t.random??t.rng?.()??Oo(),t.msecs,t.seq,e,n);else{const t=Date.now(),o=Oo();!function(t,e,n){t.msecs??=-1/0,t.seq??=0,e>t.msecs?(t.seq=n[6]<<23|n[7]<<16|n[8]<<8|n[9],t.msecs=e):(t.seq=t.seq+1|0,0===t.seq&&t.msecs++)}(Ao,t,o),r=xo(o,Ao.msecs,Ao.seq,e,n)}return e??function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return(wo[t[e+0]]+wo[t[e+1]]+wo[t[e+2]]+wo[t[e+3]]+"-"+wo[t[e+4]]+wo[t[e+5]]+"-"+wo[t[e+6]]+wo[t[e+7]]+"-"+wo[t[e+8]]+wo[t[e+9]]+"-"+wo[t[e+10]]+wo[t[e+11]]+wo[t[e+12]]+wo[t[e+13]]+wo[t[e+14]]+wo[t[e+15]]).toLowerCase()}(r)}function xo(t,e,n,r){let o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:0;if(t.length<16)throw new Error("Random bytes length must be >= 16");if(r){if(o<0||o+16>r.length)throw new RangeError(`UUID byte range ${o}:${o+15} is out of buffer bounds`)}else r=new Uint8Array(16),o=0;return e??=Date.now(),n??=127*t[6]<<24|t[7]<<16|t[8]<<8|t[9],r[o++]=e/1099511627776&255,r[o++]=e/4294967296&255,r[o++]=e/16777216&255,r[o++]=e/65536&255,r[o++]=e/256&255,r[o++]=255&e,r[o++]=112|n>>>28&15,r[o++]=n>>>20&255,r[o++]=128|n>>>14&63,r[o++]=n>>>6&255,r[o++]=n<<2&255|3&t[10],r[o++]=t[11],r[o++]=t[12],r[o++]=t[13],r[o++]=t[14],r[o++]=t[15],r}var So="[object Boolean]";function Po(t){return!0===(e=t)||!1===e||Z(e)&&j(e)==So;var e}function zo(t){return"[object String]"===Object.prototype.toString.call(t)}function Bo(t){return!(!zo(t)||""===t)}function Eo(t){return"[object Array]"===Object.prototype.toString.call(t)}function Io(t){return"[object Object]"===Object.prototype.toString.call(t)}function Co(t){return!!function(t){return"[object Undefined]"===Object.prototype.toString.call(t)}(t)||(!!function(t){return"[object Null]"===Object.prototype.toString.call(t)}(t)||(!!function(t){if(Io(t)){for(let e in t)return!1;return!0}return!1}(t)||(!!function(t){return!(!zo(t)||""!==t)}(t)||(!!function(t){return!!Eo(t)&&0===t.length}(t)||!!function(t){return t!=t}(t)))))}function Do(t){return!!Eo(t)&&(0!==t.length&&(1!==t.length||!Co(t[0])))}function Uo(t){if(Io(t)){for(let e in t)return!0;return!1}return!1}var $o=/\s/;var Fo=/^\s+/;function Mo(t){return t?t.slice(0,function(t){for(var e=t.length;e--&&$o.test(t.charAt(e)););return e}(t)+1).replace(Fo,""):t}var Go=NaN,No=/^[-+]0x[0-9a-f]+$/i,To=/^0b[01]+$/i,Lo=/^0o[0-7]+$/i,qo=parseInt;var Ro=1/0,Vo=17976931348623157e292;function Wo(t){return t?(t=function(t){if("number"==typeof t)return t;if(Qn(t))return Go;if(g(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=g(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=Mo(t);var n=To.test(t);return n||Lo.test(t)?qo(t.slice(2),n?2:8):No.test(t)?Go:+t}(t))===Ro||t===-Ro?(t<0?-1:1)*Vo:t==t?t:0:0===t?t:0}function Ho(t,e,n){var r=null==t?0:t.length;return r?(e=n||void 0===e?1:function(t){var e=Wo(t),n=e%1;return e==e?n?e-n:e:0}(e),Br(t,e<0?0:e,r)):[]}function Jo(t,e){var n;return(ct(t)?W:sn)(t,"function"==typeof(n=e)?n:Or)}function Ko(t){let e=Object.prototype.toString.call(t);return"[object Function]"===e||"[object AsyncFunction]"===e}function Qo(t,e){let n=_o();if(!Eo(t)&&!Io(t))return n.reject("rs is not an array or object"),n;let r=!1;if(Io(t)){r=!0;let e=[];Jo(t,((t,n)=>{e.push({k:n,v:t})})),t=e}Ko(e)||(e=function(t){return t});let o=-1,u=[];return t.reduce((function(t,n){return t.then((function(t){u.push(t),o+=1;let c=o,i=n;return r&&(c=n.k,i=n.v),Ko(e)?e(i,c):i}))}),Promise.resolve()).then((function(t){u.push(t),u=Ho(u),n.resolve(u)})).catch((function(t){n.reject(t)})),n}return function(){let n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};n.url||(n.url="mongodb://127.0.0.1:27017"),n.db||(n.db="worm"),n.cl||(n.cl="test");let r=jr(n,"autoGenPk");Po(r)||(r=!0);let o=!1,u=!1,c=new go,i=t.MongoClient;function a(t){let e=jr(t,"message");return Bo(e)?e:String(t)}function l(t,e,n){try{c.emit("change",t,e,n)}catch(t){console.log(t)}}function f(t,e,n){try{c.emit("error",t,e,a(n))}catch(t){console.log(t)}}function s(t,e){if(!Bo(t.id)){if(!r)throw new Error(`invalid data[${e}].id, autoGenPk is false`);t.id=ko()}return t}function v(t){let e=jr(t,"writeErrors");return Do(e)?Sr(e,(function(t){return 11e3===jr(t,"code")||11e3===jr(t,"err.code")})):11e3===jr(t,"code")}async function p(t){o||(await t.createIndex({id:1},{unique:!0}),o=!0)}async function d(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=arguments.length>1?arguments[1]:void 0,n=!1,r=null;try{let n=e.find(t);r=await n.toArray()}catch(t){n=!0,r=t}return n?Promise.reject(r):r}return c.select=async function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=!1,r=new i(n.url),o=null;try{let e=r.db(n.db).collection(n.cl).find(t);o=await e.toArray(),o=zr(o,(function(t){return t=Xr(t,"_id")}))}catch(t){e=!0,o=t}finally{await r.close(),r=null}return e?(f("select",null,o),Promise.reject(o)):o},c.selectByPk=async function(t){let e=!1;if(!Bo(t))return null;let r=new i(n.url),o=null;try{let e=r.db(n.db).collection(n.cl),u=await e.findOne({id:t},{projection:{_id:0}});o=Uo(u)?u:null}catch(t){e=!0,o=t}finally{await r.close(),r=null}return e?(f("selectByPk",null,o),Promise.reject(o)):o},c.insert=async function(t){let e=!1;if(!Uo(t)&&!Do(t))return{n:0,nInserted:0,ok:1};t=un(t);let r=new i(n.url),o=null;try{await r.connect();let e=r.db(n.db).collection(n.cl);Eo(t)||(t=[t]),t=zr(t,s),await p(e);let u=ho(t),c=0;try{c=(await e.insertMany(t,{ordered:!1})).insertedCount}catch(t){if(!v(t))throw t;c=jr(t,"result.insertedCount",0)}o={n:u,nInserted:c,ok:1}}catch(t){e=!0,o=t}finally{await r.close(),r=null}return e||l("insert",t,o),e?(f("insert",t,o),Promise.reject(o)):o},c.save=async function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=!1;if(!Uo(t)&&!Do(t))return[];t=un(t);let o=jr(e,"autoInsert",!0),u=new i(n.url),c=null;try{await u.connect();let e=u.db(n.db).collection(n.cl);Eo(t)||(t=[t]),t=zr(t,s),await p(e),c=await Qo(t,(async t=>async function(t,e,n){let r=null,o=!1;for(let u=0;u<3;u++)try{let u=await t.updateOne({id:e.id},{$set:e},{upsert:n}),c=jr(u,"matchedCount",0),i=jr(u,"modifiedCount",0);jr(u,"upsertedCount",0)>0?(r={n:1,nInserted:1,nModified:0,ok:1},o=!0):r=c>0?{n:1,nInserted:0,nModified:i>0?1:0,ok:1}:{n:0,nInserted:0,nModified:0,ok:1};break}catch(t){if(v(t)&&u<2)continue;r={n:1,nInserted:0,nModified:0,ok:0,err:a(t)};break}return o&&l("insert",[e],r),0===r.ok&&f("save",[e],r.err),r}(e,t,o)))}catch(t){r=!0,c=t}finally{await u.close(),u=null}return r||l("save",t,c),r?(f("save",t,c),Promise.reject(c)):c},c.del=async function(t){let e=!1;if(!Uo(t)&&!Do(t))return[];t=un(t);let r=new i(n.url),o=null;try{await r.connect();let e=r.db(n.db).collection(n.cl);Eo(t)||(t=[t]),o=await Qo(t,(async t=>{let n=jr(t,"id"),r=null;if(Bo(n))try{let t=jr(await e.deleteOne({id:n}),"deletedCount",0);r={n:t,nDeleted:t,ok:1}}catch(t){r={n:1,nDeleted:0,ok:0,err:a(t)}}else r={n:0,nDeleted:0,ok:0,err:`invalid id[${n}]`};return 0===r.ok&&f("del",[t],r.err),r}))}catch(t){e=!0,o=t}finally{await r.close(),r=null}return e||l("del",t,o),e?(f("del",t,o),Promise.reject(o)):o},c.delAll=async function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=!1,r=new i(n.url),o=null;try{let e=r.db(n.db).collection(n.cl),u=jr(await e.deleteMany(t),"deletedCount",0);o={n:u,nDeleted:u,ok:1}}catch(t){e=!0,o=t}finally{await r.close(),r=null}return e||l("delAll",null,o),e?(f("delAll",null,o),Promise.reject(o)):o},c.selectByPkGfs=async function(e){let r=!1;if(!Bo(e))return null;let o=new i(n.url),u=null;try{u={id:e,u8a:await(async e=>{let r=_o(),u=o.db(n.db),c=new t.GridFSBucket(u,{chunkSizeBytes:10485760,bucketName:n.cl}),i=Buffer.from(""),a=c.openDownloadStreamByName(e);return a.on("data",(function(t){i=Buffer.concat([i,t])})),a.on("error",(function(t){r.reject(t)})),a.on("end",(function(){let t=new Uint8Array(i);i=null,r.resolve(t)})),r})(e)}}catch(t){"ENOENT"===jr(t,"code")?u=null:(r=!0,u=t)}finally{await o.close(),o=null}return r?(f("selectByPkGfs",null,u),Promise.reject(u)):u},c.insertGfs=async function(r){let o=!1;if(!Uo(r)&&!Do(r))return{n:0,nInserted:0,ok:1};let c=new i(n.url),a=null;try{await c.connect();let o=c.db(n.db),i=new t.GridFSBucket(o,{chunkSizeBytes:10485760,bucketName:n.cl}),l=o.collection(`${n.cl}.chunks`);Eo(r)||(r=[r]),r=zr(r,(function(t,e){if(!function(t){return"[object Uint8Array]"===Object.prototype.toString.call(t)}((t=s(t={...t},e)).u8a))throw new Error(`invalid data[${e}].u8a`);return t})),await async function(t){u||(await t.collection(`${n.cl}.files`).createIndex({filename:1},{unique:!0}),u=!0)}(o);let f=ho(r),p=0;await Qo(r,(async t=>{let n=await function(t,n,r,o){let u=_o(),c=t.openUploadStream(r),i=c.id,a=new e.Readable;return a._read=()=>{},a.push(Buffer.from(o)),a.push(null),a.pipe(c).on("error",(function(t){v(t)?n.deleteMany({files_id:i}).then((function(){u.resolve(!1)})).catch((function(t){u.reject(t)})):u.reject(t)})).on("finish",(function(){u.resolve(!0)})),u}(i,l,t.id,t.u8a);n&&p++})),a={n:f,nInserted:p,ok:1}}catch(t){o=!0,a=t}finally{await c.close(),c=null}return o||l("insertGfs",r,a),o?(f("insertGfs",r,a),Promise.reject(a)):a},c.delGfs=async function(e){let r=!1;if(!Uo(e)&&!Do(e))return[];let o=new i(n.url),u=null;try{await o.connect();let r=o.db(n.db),c=new t.GridFSBucket(r,{chunkSizeBytes:10485760,bucketName:n.cl});Eo(e)||(e=[e]),u=await Qo(e,(async t=>{let e=jr(t,"id"),n=null;if(Bo(e))try{let t=await d({filename:e},c),r=0;for(let e of t)await c.delete(e._id),r++;n={n:r>0?1:0,nDeleted:r,ok:1}}catch(t){n={n:1,nDeleted:0,ok:0,err:a(t)}}else n={n:0,nDeleted:0,ok:0,err:`invalid id[${e}]`};return 0===n.ok&&f("delGfs",[t],n.err),n}))}catch(t){r=!0,u=t}finally{await o.close(),o=null}return r||l("delGfs",e,u),r?(f("delGfs",e,u),Promise.reject(u)):u},c.delAllGfs=async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=!1,o=new i(n.url),u=null;try{let r=o.db(n.db),c=new t.GridFSBucket(r,{chunkSizeBytes:10485760,bucketName:n.cl}),i=await d(e,c),a=zr(i,(function(t){return async function(t,e){await e.delete(t)}(t._id,c)}));await Promise.all(a);let l=ho(i);u={n:l,nDeleted:l,ok:1}}catch(t){r=!0,u=t}finally{await o.close(),o=null}return r||l("delAllGfs",null,u),r?(f("delAllGfs",null,u),Promise.reject(u)):u},c}}));
|
|
7
7
|
//# sourceMappingURL=w-orm-mongodb.umd.js.map
|