w-orm-mongodb 1.1.38 → 1.1.39
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 +31 -55
- package/dist/w-orm-mongodb.umd.js +2 -2
- package/dist/w-orm-mongodb.umd.js.map +1 -1
- package/docs/WOrmMongodb.html +29 -25
- package/docs/WOrmMongodb.mjs.html +25 -20
- package/docs/index.html +2 -2
- package/g-basic.mjs +8 -8
- package/g-gfs.mjs +12 -12
- package/g-unique.mjs +6 -6
- package/package.json +1 -1
- package/src/WOrmMongodb.mjs +23 -18
- package/test/api-basic.test.mjs +29 -29
- package/test/api-gfs.test.mjs +14 -14
package/README.md
CHANGED
|
@@ -124,13 +124,13 @@ async function test() {
|
|
|
124
124
|
let sr = await wo.select({ name: { $regex: 'PeT', $options: 'i' } })
|
|
125
125
|
console.log('selectReg', sr)
|
|
126
126
|
|
|
127
|
-
//
|
|
128
|
-
let sbi = await wo.
|
|
129
|
-
console.log('
|
|
127
|
+
//selectByPk, 由id直接查找單筆, 不需如select提取全部符合數據再處理
|
|
128
|
+
let sbi = await wo.selectByPk('id-rosemary')
|
|
129
|
+
console.log('selectByPk', sbi)
|
|
130
130
|
|
|
131
|
-
//
|
|
132
|
-
let sbn = await wo.
|
|
133
|
-
console.log('
|
|
131
|
+
//selectByPk by id not existed
|
|
132
|
+
let sbn = await wo.selectByPk('id-not-existed')
|
|
133
|
+
console.log('selectByPk by id not existed', sbn)
|
|
134
134
|
|
|
135
135
|
//del
|
|
136
136
|
let d = ss.filter(function(v) {
|
|
@@ -187,19 +187,19 @@ test()
|
|
|
187
187
|
// }
|
|
188
188
|
// ]
|
|
189
189
|
// selectReg [ { id: 'id-peter', name: 'peter(modify)', value: 123 } ]
|
|
190
|
-
//
|
|
191
|
-
//
|
|
190
|
+
// selectByPk { id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 }
|
|
191
|
+
// selectByPk by id not existed null
|
|
192
192
|
// change del
|
|
193
193
|
// del then [ { n: 1, nDeleted: 1, ok: 1 } ]
|
|
194
194
|
```
|
|
195
195
|
|
|
196
196
|
## Return values
|
|
197
197
|
|
|
198
|
-
本套件屬`w-orm-*`系列,六個函數`select`、`
|
|
198
|
+
本套件屬`w-orm-*`系列,六個函數`select`、`selectByPk`、`insert`、`save`、`del`、`delAll`之回傳結構依系列統一規格:
|
|
199
199
|
|
|
200
200
|
```alias
|
|
201
201
|
select(find) → [ {...}, {...} ] 無符合為 []
|
|
202
|
-
|
|
202
|
+
selectByPk(pk) → {...} | null
|
|
203
203
|
|
|
204
204
|
insert(data) → { n, nInserted, ok }
|
|
205
205
|
save(data, option) → [ { n, nInserted, nModified, ok }, ... ]
|
|
@@ -236,31 +236,7 @@ delAll(find) → { n, nDeleted, ok }
|
|
|
236
236
|
|
|
237
237
|
`del`對未帶有效`id`者不送查詢條件,直接回`ok: 0`並附`err`,以免`undefined`經序列化為`null`而誤刪`id`為`null`之數據。
|
|
238
238
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
`insert`之「已存在則跳過」與`save`之「不遺失更新」,由MongoDB於單一文件操作內原子完成,**不須開啟transaction**(transaction另須replica set,standalone不支援)。
|
|
242
|
-
|
|
243
|
-
| 適用範圍 | 是否保證 |
|
|
244
|
-
|---|---|
|
|
245
|
-
| 單一行程內併發 | 是 |
|
|
246
|
-
| 跨行程併發 | 是 |
|
|
247
|
-
|
|
248
|
-
原子性全由MongoDB伺服器端提供,本套件每次操作各自建立連線、不持有跨呼叫狀態,故兩種範圍之保證相同。
|
|
249
|
-
|
|
250
|
-
實測依據(Windows 11 / Node.js 24.19.0 / mongodb driver 7.5.0 / MongoDB 8 單機):
|
|
251
|
-
|
|
252
|
-
- 單一行程內對同一`id`併發`insert` 10次,`nInserted`總和為`1`,資料表僅`1`筆。
|
|
253
|
-
- 單一行程內對同一全新`id`併發`save` 5次,`nInserted === 1`者恰`1`筆,資料表僅`1`筆,5次所給欄位全數保留。
|
|
254
|
-
- 跨行程(2個獨立node行程)各自對相同20個`id`執行`insert`,`nInserted`總和為`20`,資料表恰`20`筆。
|
|
255
|
-
- 跨行程(2個獨立node行程)各自對同一既有`id`寫入20個不同欄位,40個欄位全數保留且原欄位未遺失,資料表恰`1`筆。
|
|
256
|
-
|
|
257
|
-
GridFS亦同(`test/api-gfs.test.mjs`):
|
|
258
|
-
|
|
259
|
-
- 對同一`id`併發`insertGfs` 10次,`nInserted`總和為`1`,僅新增1筆files且**未殘留孤兒chunks**。
|
|
260
|
-
|
|
261
|
-
以上皆為測試案例,可以`npm test`複現。
|
|
262
|
-
|
|
263
|
-
`delAll`之`nDeleted`於併發下反映該次`deleteMany`實際刪除筆數,不保證等於呼叫當下符合條件之筆數。
|
|
239
|
+
本套件之主鍵欄位固定為`id`,尚未支援由呼叫端指定。`id`為無業務語義之識別碼,故`insert`與`save`於輸入未帶有效`id`時自動補值,`del`則不補值。
|
|
264
240
|
|
|
265
241
|
## Upgrading
|
|
266
242
|
|
|
@@ -286,7 +262,7 @@ db['usersGfs.files'].aggregate([
|
|
|
286
262
|
])
|
|
287
263
|
```
|
|
288
264
|
|
|
289
|
-
`
|
|
265
|
+
`selectByPkGfs`、`delGfs`、`delAllGfs`皆不建立索引,故既有數據縱使尚存重複`id`亦可正常查詢與清除,`delGfs`會將同一`id`之多筆一併刪除並如實回報`nDeleted`。
|
|
290
266
|
|
|
291
267
|
#### Example for unique id and concurrency
|
|
292
268
|
> **Link:** [[dev source code](https://github.com/yuda-lyu/w-orm-mongodb/blob/master/g-unique.mjs)]
|
|
@@ -316,12 +292,12 @@ async function test() {
|
|
|
316
292
|
{ id: 'id-uniq', name: 'uniq' },
|
|
317
293
|
])
|
|
318
294
|
console.log('insert with duplicated id', ri)
|
|
319
|
-
console.log('
|
|
295
|
+
console.log('selectByPk(id-dup)', await wo.selectByPk('id-dup'))
|
|
320
296
|
|
|
321
297
|
//insert, 對已存在id再插入則跳過而不覆寫
|
|
322
298
|
let re = await wo.insert({ id: 'id-dup', name: 'dup-3' })
|
|
323
299
|
console.log('insert existed id', re)
|
|
324
|
-
console.log('
|
|
300
|
+
console.log('selectByPk(id-dup)', await wo.selectByPk('id-dup'))
|
|
325
301
|
|
|
326
302
|
//insert, 併發對同一id插入10次, nInserted總和為1
|
|
327
303
|
let rc = await Promise.all(Array.from({ length: 10 }, (v, k) => {
|
|
@@ -336,19 +312,19 @@ async function test() {
|
|
|
336
312
|
}))
|
|
337
313
|
console.log('count of nInserted===1 by 5 concurrent save', rs.filter((v) => v[0].nInserted === 1).length)
|
|
338
314
|
console.log('records of id-new', (await wo.select({ id: 'id-new' })).length)
|
|
339
|
-
console.log('
|
|
315
|
+
console.log('selectByPk(id-new)', await wo.selectByPk('id-new'))
|
|
340
316
|
|
|
341
317
|
}
|
|
342
318
|
test()
|
|
343
319
|
// insert with duplicated id { n: 3, nInserted: 2, ok: 1 }
|
|
344
|
-
//
|
|
320
|
+
// selectByPk(id-dup) { id: 'id-dup', name: 'dup-1' }
|
|
345
321
|
// insert existed id { n: 1, nInserted: 0, ok: 1 }
|
|
346
|
-
//
|
|
322
|
+
// selectByPk(id-dup) { id: 'id-dup', name: 'dup-1' }
|
|
347
323
|
// sum of nInserted by 10 concurrent insert 1
|
|
348
324
|
// records of id-race 1
|
|
349
325
|
// count of nInserted===1 by 5 concurrent save 1
|
|
350
326
|
// records of id-new 1
|
|
351
|
-
//
|
|
327
|
+
// selectByPk(id-new) { id: 'id-new', f0: 0, f1: 1, f2: 2, f4: 4, f3: 3 }
|
|
352
328
|
// 註: 併發儲存之各欄位皆會保留, 惟欄位順序取決於各次儲存之完成順序, 故每次執行不盡相同
|
|
353
329
|
```
|
|
354
330
|
|
|
@@ -359,7 +335,7 @@ GridFS函數之參數與回傳形狀比照一般操作,數據物件為`{ id, u
|
|
|
359
335
|
|
|
360
336
|
| GridFS函數 | 對應一般函數 | 回傳 |
|
|
361
337
|
|---|---|---|
|
|
362
|
-
| `
|
|
338
|
+
| `selectByPkGfs(id)` | `selectByPk` | `{ id, u8a }` 或 `null` |
|
|
363
339
|
| `insertGfs(data)` | `insert` | `{ n, nInserted, ok }` |
|
|
364
340
|
| `delGfs(data)` | `del` | `[ { n, nDeleted, ok }, ... ]` |
|
|
365
341
|
| `delAllGfs(find)` | `delAll` | `{ n, nDeleted, ok }` |
|
|
@@ -418,15 +394,15 @@ async function test() {
|
|
|
418
394
|
let gr = await wo.insertGfs({ id: 'id-file', u8a: genU8a(50) })
|
|
419
395
|
console.log('insertGfs existed id', gr)
|
|
420
396
|
|
|
421
|
-
//
|
|
422
|
-
let gs = await wo.
|
|
423
|
-
console.log('
|
|
424
|
-
console.log('
|
|
425
|
-
console.log('
|
|
397
|
+
//selectByPkGfs
|
|
398
|
+
let gs = await wo.selectByPkGfs('id-file')
|
|
399
|
+
console.log('selectByPkGfs id', gs.id)
|
|
400
|
+
console.log('selectByPkGfs u8a.length', gs.u8a.length)
|
|
401
|
+
console.log('selectByPkGfs u8a[0..3]', gs.u8a[0], gs.u8a[1], gs.u8a[2], gs.u8a[3])
|
|
426
402
|
|
|
427
|
-
//
|
|
428
|
-
let gn = await wo.
|
|
429
|
-
console.log('
|
|
403
|
+
//selectByPkGfs by id not existed
|
|
404
|
+
let gn = await wo.selectByPkGfs('id-not-existed')
|
|
405
|
+
console.log('selectByPkGfs by id not existed', gn)
|
|
430
406
|
|
|
431
407
|
//insertGfs, 一次插入多筆
|
|
432
408
|
let gm = await wo.insertGfs([
|
|
@@ -455,10 +431,10 @@ test()
|
|
|
455
431
|
// insertGfs { n: 1, nInserted: 1, ok: 1 }
|
|
456
432
|
// change insertGfs
|
|
457
433
|
// insertGfs existed id { n: 1, nInserted: 0, ok: 1 }
|
|
458
|
-
//
|
|
459
|
-
//
|
|
460
|
-
//
|
|
461
|
-
//
|
|
434
|
+
// selectByPkGfs id id-file
|
|
435
|
+
// selectByPkGfs u8a.length 1000
|
|
436
|
+
// selectByPkGfs u8a[0..3] 0 1 2 3
|
|
437
|
+
// selectByPkGfs by id not existed null
|
|
462
438
|
// change insertGfs
|
|
463
439
|
// insertGfs multi { n: 2, nInserted: 2, ok: 1 }
|
|
464
440
|
// change delGfs
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* w-orm-mongodb v1.1.
|
|
2
|
+
* w-orm-mongodb v1.1.39
|
|
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,x=l["__core-js_shared__"],P=(k=/[^.]+$/.exec(x&&x.keys&&x.keys.IE_PROTO||""))?"Symbol(src)_1."+k:"";var z=Function.prototype.toString;function I(t){if(null!=t){try{return z.call(t)}catch(t){}try{return t+""}catch(t){}}return""}var B=/^\[object .+?Constructor\]$/,E=Function.prototype,M=Object.prototype,F=E.toString,D=M.hasOwnProperty,N=RegExp("^"+F.call(D).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function U(t){return!(!_(t)||(e=t,P&&P in e))&&(S(t)?N:B).test(I(t));var e}function $(t,e){var r=function(t,e){return null==t?void 0:t[e]}(t,e);return U(r)?r:void 0}var C=$(l,"Map"),T=$(Object,"create");var G=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__=T?T(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(T){var r=e[t];return"__lodash_hash_undefined__"===r?void 0:r}return G.call(e,t)?e[t]:void 0},q.prototype.has=function(t){var e=this.__data__;return T?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]=T&&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=$(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 xt=Object.prototype;function Pt(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||xt)}function zt(t,e){return function(r){return t(e(r))}}var It=zt(Object.keys,Object),Bt=Object.prototype.hasOwnProperty;function Et(t){if(!Pt(t))return It(t);var e=[];for(var r in Object(t))Bt.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 Nt(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=Pt(t),r=[];for(var n in t)("constructor"!=n||!e&&Dt.call(t,n))&&r.push(n);return r}function Ut(t){return Mt(t)?kt(t,!0):Nt(t)}var $t="object"==typeof exports&&exports&&!exports.nodeType&&exports,Ct=$t&&"object"==typeof module&&module&&!module.nodeType&&module,Tt=Ct&&Ct.exports===$t?l.Buffer:void 0,Gt=Tt?Tt.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,Ut,Qt)}var te=$(l,"DataView"),ee=$(l,"Promise"),re=$(l,"Set"),ne=$(l,"WeakMap"),oe="[object Map]",ue="[object Promise]",ie="[object Set]",ce="[object WeakMap]",ae="[object DataView]",le=I(te),fe=I(C),se=I(ee),de=I(re),ve=I(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?I(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]",xe="[object Set]",Pe="[object String]",ze="[object Symbol]",Ie="[object ArrayBuffer]",Be="[object DataView]",Ee="[object Float32Array]",Me="[object Float64Array]",Fe="[object Int8Array]",De="[object Int16Array]",Ne="[object Int32Array]",Ue="[object Uint8Array]",$e="[object Uint8ClampedArray]",Ce="[object Uint16Array]",Te="[object Uint32Array]";function Ge(t,e,r){var n,o,u,i=t.constructor;switch(e){case Ie:return je(t);case me:case Oe:return new i(+t);case Be: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 Ne:case Ue:case $e:case Ce:case Te: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 Pe:return new i(t);case ke:return(u=new(o=t).constructor(o.source,ge.exec(o))).lastIndex=o.lastIndex,u;case xe: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=Gt?Gt(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||Pt(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,Ut(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=Ge(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?Ut: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]",xr="[object RegExp]",Pr="[object Set]",zr="[object String]",Ir="[object Symbol]",Br="[object ArrayBuffer]",Er="[object DataView]",Mr=f?f.prototype:void 0,Fr=Mr?Mr.valueOf:void 0;var Dr=1,Nr=Object.prototype.hasOwnProperty;var Ur=1,$r="[object Arguments]",Cr="[object Array]",Tr="[object Object]",Gr=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==$r?Tr:l)==Tr,d=(f=f==$r?Tr:f)==Tr,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 Br: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 xr:case zr:return t==e+"";case Sr:var a=jr;case Pr: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 Ir:if(Fr)return Fr.call(t)==Fr.call(e)}return!1}(t,e,l,r,o,u,i);if(!(r&Ur)){var p=s&&Gr.call(t,"__wrapped__"),b=d&&Gr.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:Nr.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 xn(t){return Zr(t)?kn(jn(t)):function(t){return function(e){return gn(e,t)}}(t)}function Pn(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):xn(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,Pn(e))}function In(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 Bn(t,e){return(ct(t)?fn:In)(t,Pn(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]",Nn=Function.prototype,Un=Object.prototype,$n=Nn.toString,Cn=Un.hasOwnProperty,Tn=$n.call(Object);function Gn(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&&$n.call(r)==Tn}(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,Gn));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,xo=/^0o[0-7]+$/i,Po=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||xo.test(t)?Po(t.slice(2),r?2:8):So.test(t)?Ao:+t}var Io=1/0,Bo=17976931348623157e292;function Eo(t){return t?(t=zo(t))===Io||t===-Io?(t<0?-1:1)*Bo: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 No(t){return t!=t}function Uo(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(No(t))return!1;e=!0}return e}function $o(t){if(!Uo(t))return 0;return Eo(t)}function Co(t){return!!Uo(t)&&(t=$o(t),"number"==typeof(e=t)&&e==Mo(e));var e}var To=l.isFinite,Go=Math.min;var Ro=function(t){var e=Math[t];return function(t,r){if(t=zo(t),(r=null==r?0:Go(Mo(r),292))&&To(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(!Uo(t))return 0;t=$o(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("")}function Jo(t){return"[object Array]"===Object.prototype.toString.call(t)}function Ko(t){return"[object Object]"===Object.prototype.toString.call(t)}function Qo(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(Ko(t)){for(let e in t)return!1;return!0}return!1}(t)||(!!function(t){return!(!Fo(t)||""!==t)}(t)||(!!function(t){return!!Jo(t)&&0===t.length}(t)||!!No(t)))))}function Xo(t){return!!Jo(t)&&(0!==t.length&&(1!==t.length||!Qo(t[0])))}function Yo(t){if(Ko(t)){for(let e in t)return!0;return!1}return!1}function Zo(t,e){var r;return(ct(t)?H:sr)(t,"function"==typeof(r=e)?r:Sn)}function tu(t){let e=Object.prototype.toString.call(t);return"[object Function]"===e||"[object AsyncFunction]"===e}function eu(t,e){let r=_o();if(!Jo(t)&&!Ko(t))return r.reject("rs is not an array or object"),r;let n=!1;if(Ko(t)){n=!0;let e=[];Zo(t,((t,r)=>{e.push({k:r,v:t})})),t=e}tu(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),tu(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=!1,u=!1,i=new t.EventEmitter,c=e.MongoClient;function a(t){let e=_n(t,"message");return Do(e)?e:String(t)}function l(t,e,r){try{i.emit("change",t,e,r)}catch(t){console.log(t)}}function f(t){let e=_n(t,"writeErrors");return Xo(e)?zn(e,(function(t){return 11e3===_n(t,"code")||11e3===_n(t,"err.code")})):11e3===_n(t,"code")}async function s(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,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 i.select=async function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=!1,r=new c(n.url),o=null;try{let e=r.db(n.db).collection(n.cl).find(t);o=await e.toArray(),o=Bn(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},i.selectById=async function(t){let e=!1;if(!Do(t))return null;let r=new c(n.url),o=null;try{let e=r.db(n.db).collection(n.cl),u=await e.findOne({id:t},{projection:{_id:0}});o=Yo(u)?u:null}catch(t){e=!0,o=t}finally{await r.close(),r=null}return e?Promise.reject(o):o},i.insert=async function(t){let e=!1;if(!Yo(t)&&!Xo(t))return{n:0,nInserted:0,ok:1};t=ir(t);let r=new c(n.url),o=null;try{await r.connect();let e=r.db(n.db).collection(n.cl);Jo(t)||(t=[t]),t=Bn(t,(function(t){return Do(t.id)||(t.id=Ho()),t})),await s(e);let u=go(t),i=0;try{i=(await e.insertMany(t,{ordered:!1})).insertedCount}catch(t){if(!f(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||l("insert",t,o),e?Promise.reject(o):o},i.save=async function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=!1;if(!Yo(t)&&!Xo(t))return[];t=ir(t);let o=_n(e,"autoInsert",!0),u=new c(n.url),i=null;try{await u.connect();let e=u.db(n.db).collection(n.cl);Jo(t)||(t=[t]),t=Bn(t,(function(t){return Do(t.id)||(t.id=Ho()),t})),await s(e),i=await eu(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(f(t)&&u<2)continue;n={n:1,nInserted:0,nModified:0,ok:0,err:a(t)};break}return o&&l("insert",[e],n),n}(e,t,o)))}catch(t){r=!0,i=t}finally{await u.close(),u=null}return r||l("save",t,i),r?Promise.reject(i):i},i.del=async function(t){let e=!1;if(!Yo(t)&&!Xo(t))return[];t=ir(t);let r=new c(n.url),o=null;try{await r.connect();let e=r.db(n.db).collection(n.cl);Jo(t)||(t=[t]),o=await eu(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:a(t)}}return n}))}catch(t){e=!0,o=t}finally{await r.close(),r=null}return e||l("del",t,o),e?Promise.reject(o):o},i.delAll=async function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=!1,r=new c(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||l("delAll",null,o),e?Promise.reject(o):o},i.selectByIdGfs=async function(t){let r=!1;if(!Do(t))return null;let o=new c(n.url),u=null;try{let r=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);u={id:t,u8a:r}}catch(t){"ENOENT"===_n(t,"code")?u=null:(r=!0,u=t)}finally{await o.close(),o=null}return r?Promise.reject(u):u},i.insertGfs=async function(t){let o=!1;if(!Yo(t)&&!Xo(t))return{n:0,nInserted:0,ok:1};let i=new c(n.url),a=null;try{await i.connect();let o=i.db(n.db),c=new e.GridFSBucket(o,{chunkSizeBytes:10485760,bucketName:n.cl}),l=o.collection(`${n.cl}.chunks`);Jo(t)||(t=[t]),t=Bn(t,(function(t,e){if(Do((t={...t}).id)||(t.id=Ho()),!function(t){return"[object Uint8Array]"===Object.prototype.toString.call(t)}(t.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 s=go(t),d=0;await eu(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){f(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}(c,l,t.id,t.u8a);e&&d++})),a={n:s,nInserted:d,ok:1}}catch(t){o=!0,a=t}finally{await i.close(),i=null}return o||l("insertGfs",t,a),o?Promise.reject(a):a},i.delGfs=async function(t){let r=!1;if(!Yo(t)&&!Xo(t))return[];let o=new c(n.url),u=null;try{await o.connect();let r=o.db(n.db),i=new e.GridFSBucket(r,{chunkSizeBytes:10485760,bucketName:n.cl});Jo(t)||(t=[t]),u=await eu(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 d({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:a(t)}}return r}))}catch(t){r=!0,u=t}finally{await o.close(),o=null}return r||l("delGfs",t,u),r?Promise.reject(u):u},i.delAllGfs=async function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=!1,o=new c(n.url),u=null;try{let r=o.db(n.db),i=new e.GridFSBucket(r,{chunkSizeBytes:10485760,bucketName:n.cl}),c=await d(t,i),a=Bn(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||l("delAllGfs",null,u),r?Promise.reject(u):u},i}}));
|
|
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 I(t){if(null!=t){try{return z.call(t)}catch(t){}try{return t+""}catch(t){}}return""}var B=/^\[object .+?Constructor\]$/,E=Function.prototype,M=Object.prototype,F=E.toString,D=M.hasOwnProperty,N=RegExp("^"+F.call(D).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function U(t){return!(!_(t)||(e=t,x&&x in e))&&(S(t)?N:B).test(I(t));var e}function $(t,e){var r=function(t,e){return null==t?void 0:t[e]}(t,e);return U(r)?r:void 0}var C=$(l,"Map"),T=$(Object,"create");var G=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__=T?T(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(T){var r=e[t];return"__lodash_hash_undefined__"===r?void 0:r}return G.call(e,t)?e[t]:void 0},q.prototype.has=function(t){var e=this.__data__;return T?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]=T&&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=$(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 It=zt(Object.keys,Object),Bt=Object.prototype.hasOwnProperty;function Et(t){if(!xt(t))return It(t);var e=[];for(var r in Object(t))Bt.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 Nt(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 Ut(t){return Mt(t)?kt(t,!0):Nt(t)}var $t="object"==typeof exports&&exports&&!exports.nodeType&&exports,Ct=$t&&"object"==typeof module&&module&&!module.nodeType&&module,Tt=Ct&&Ct.exports===$t?l.Buffer:void 0,Gt=Tt?Tt.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,Ut,Qt)}var te=$(l,"DataView"),ee=$(l,"Promise"),re=$(l,"Set"),ne=$(l,"WeakMap"),oe="[object Map]",ue="[object Promise]",ie="[object Set]",ce="[object WeakMap]",ae="[object DataView]",le=I(te),fe=I(C),se=I(ee),de=I(re),ve=I(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?I(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]",Ie="[object ArrayBuffer]",Be="[object DataView]",Ee="[object Float32Array]",Me="[object Float64Array]",Fe="[object Int8Array]",De="[object Int16Array]",Ne="[object Int32Array]",Ue="[object Uint8Array]",$e="[object Uint8ClampedArray]",Ce="[object Uint16Array]",Te="[object Uint32Array]";function Ge(t,e,r){var n,o,u,i=t.constructor;switch(e){case Ie:return je(t);case me:case Oe:return new i(+t);case Be: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 Ne:case Ue:case $e:case Ce:case Te: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=Gt?Gt(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,Ut(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=Ge(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?Ut: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]",Ir="[object Symbol]",Br="[object ArrayBuffer]",Er="[object DataView]",Mr=f?f.prototype:void 0,Fr=Mr?Mr.valueOf:void 0;var Dr=1,Nr=Object.prototype.hasOwnProperty;var Ur=1,$r="[object Arguments]",Cr="[object Array]",Tr="[object Object]",Gr=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==$r?Tr:l)==Tr,d=(f=f==$r?Tr:f)==Tr,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 Br: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 Ir:if(Fr)return Fr.call(t)==Fr.call(e)}return!1}(t,e,l,r,o,u,i);if(!(r&Ur)){var p=s&&Gr.call(t,"__wrapped__"),b=d&&Gr.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:Nr.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 In(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 Bn(t,e){return(ct(t)?fn:In)(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]",Nn=Function.prototype,Un=Object.prototype,$n=Nn.toString,Cn=Un.hasOwnProperty,Tn=$n.call(Object);function Gn(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&&$n.call(r)==Tn}(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,Gn));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 Io=1/0,Bo=17976931348623157e292;function Eo(t){return t?(t=zo(t))===Io||t===-Io?(t<0?-1:1)*Bo: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 No(t){return t!=t}function Uo(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(No(t))return!1;e=!0}return e}function $o(t){if(!Uo(t))return 0;return Eo(t)}function Co(t){return!!Uo(t)&&(t=$o(t),"number"==typeof(e=t)&&e==Mo(e));var e}var To=l.isFinite,Go=Math.min;var Ro=function(t){var e=Math[t];return function(t,r){if(t=zo(t),(r=null==r?0:Go(Mo(r),292))&&To(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(!Uo(t))return 0;t=$o(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("")}function Jo(t){return"[object Array]"===Object.prototype.toString.call(t)}function Ko(t){return"[object Object]"===Object.prototype.toString.call(t)}function Qo(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(Ko(t)){for(let e in t)return!1;return!0}return!1}(t)||(!!function(t){return!(!Fo(t)||""!==t)}(t)||(!!function(t){return!!Jo(t)&&0===t.length}(t)||!!No(t)))))}function Xo(t){return!!Jo(t)&&(0!==t.length&&(1!==t.length||!Qo(t[0])))}function Yo(t){if(Ko(t)){for(let e in t)return!0;return!1}return!1}function Zo(t,e){var r;return(ct(t)?H:sr)(t,"function"==typeof(r=e)?r:Sn)}function tu(t){let e=Object.prototype.toString.call(t);return"[object Function]"===e||"[object AsyncFunction]"===e}function eu(t,e){let r=_o();if(!Jo(t)&&!Ko(t))return r.reject("rs is not an array or object"),r;let n=!1;if(Ko(t)){n=!0;let e=[];Zo(t,((t,r)=>{e.push({k:r,v:t})})),t=e}tu(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),tu(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=!1,u=!1,i=new t.EventEmitter,c=e.MongoClient;function a(t){let e=_n(t,"message");return Do(e)?e:String(t)}function l(t,e,r){try{i.emit("change",t,e,r)}catch(t){console.log(t)}}function f(t){let e=_n(t,"writeErrors");return Xo(e)?zn(e,(function(t){return 11e3===_n(t,"code")||11e3===_n(t,"err.code")})):11e3===_n(t,"code")}async function s(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,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 i.select=async function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=!1,r=new c(n.url),o=null;try{let e=r.db(n.db).collection(n.cl).find(t);o=await e.toArray(),o=Bn(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},i.selectByPk=async function(t){let e=!1;if(!Do(t))return null;let r=new c(n.url),o=null;try{let e=r.db(n.db).collection(n.cl),u=await e.findOne({id:t},{projection:{_id:0}});o=Yo(u)?u:null}catch(t){e=!0,o=t}finally{await r.close(),r=null}return e?Promise.reject(o):o},i.insert=async function(t){let e=!1;if(!Yo(t)&&!Xo(t))return{n:0,nInserted:0,ok:1};t=ir(t);let r=new c(n.url),o=null;try{await r.connect();let e=r.db(n.db).collection(n.cl);Jo(t)||(t=[t]),t=Bn(t,(function(t){return Do(t.id)||(t.id=Ho()),t})),await s(e);let u=go(t),i=0;try{i=(await e.insertMany(t,{ordered:!1})).insertedCount}catch(t){if(!f(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||l("insert",t,o),e?Promise.reject(o):o},i.save=async function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=!1;if(!Yo(t)&&!Xo(t))return[];t=ir(t);let o=_n(e,"autoInsert",!0),u=new c(n.url),i=null;try{await u.connect();let e=u.db(n.db).collection(n.cl);Jo(t)||(t=[t]),t=Bn(t,(function(t){return Do(t.id)||(t.id=Ho()),t})),await s(e),i=await eu(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(f(t)&&u<2)continue;n={n:1,nInserted:0,nModified:0,ok:0,err:a(t)};break}return o&&l("insert",[e],n),n}(e,t,o)))}catch(t){r=!0,i=t}finally{await u.close(),u=null}return r||l("save",t,i),r?Promise.reject(i):i},i.del=async function(t){let e=!1;if(!Yo(t)&&!Xo(t))return[];t=ir(t);let r=new c(n.url),o=null;try{await r.connect();let e=r.db(n.db).collection(n.cl);Jo(t)||(t=[t]),o=await eu(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:a(t)}}return n}))}catch(t){e=!0,o=t}finally{await r.close(),r=null}return e||l("del",t,o),e?Promise.reject(o):o},i.delAll=async function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=!1,r=new c(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||l("delAll",null,o),e?Promise.reject(o):o},i.selectByPkGfs=async function(t){let r=!1;if(!Do(t))return null;let o=new c(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},i.insertGfs=async function(t){let o=!1;if(!Yo(t)&&!Xo(t))return{n:0,nInserted:0,ok:1};let i=new c(n.url),a=null;try{await i.connect();let o=i.db(n.db),c=new e.GridFSBucket(o,{chunkSizeBytes:10485760,bucketName:n.cl}),l=o.collection(`${n.cl}.chunks`);Jo(t)||(t=[t]),t=Bn(t,(function(t,e){if(Do((t={...t}).id)||(t.id=Ho()),!function(t){return"[object Uint8Array]"===Object.prototype.toString.call(t)}(t.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 s=go(t),d=0;await eu(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){f(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}(c,l,t.id,t.u8a);e&&d++})),a={n:s,nInserted:d,ok:1}}catch(t){o=!0,a=t}finally{await i.close(),i=null}return o||l("insertGfs",t,a),o?Promise.reject(a):a},i.delGfs=async function(t){let r=!1;if(!Yo(t)&&!Xo(t))return[];let o=new c(n.url),u=null;try{await o.connect();let r=o.db(n.db),i=new e.GridFSBucket(r,{chunkSizeBytes:10485760,bucketName:n.cl});Jo(t)||(t=[t]),u=await eu(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 d({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:a(t)}}return r}))}catch(t){r=!0,u=t}finally{await o.close(),o=null}return r||l("delGfs",t,u),r?Promise.reject(u):u},i.delAllGfs=async function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=!1,o=new c(n.url),u=null;try{let r=o.db(n.db),i=new e.GridFSBucket(r,{chunkSizeBytes:10485760,bucketName:n.cl}),c=await d(t,i),a=Bn(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||l("delAllGfs",null,u),r?Promise.reject(u):u},i}}));
|
|
7
7
|
//# sourceMappingURL=w-orm-mongodb.umd.js.map
|