w-orm-mongodb 1.1.42 → 1.1.44
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 +77 -4
- package/dist/w-orm-mongodb.umd.js +2 -2
- package/dist/w-orm-mongodb.umd.js.map +1 -1
- package/docs/WOrmMongodb.html +311 -15
- package/docs/WOrmMongodb.mjs.html +261 -9
- package/docs/index.html +2 -2
- package/g-basic.mjs +7 -1
- package/g-gfs.mjs +7 -1
- package/package.json +1 -1
- package/src/WOrmMongodb.mjs +259 -7
- package/test/api-basic.test.mjs +386 -0
- package/test/api-insertbulk-rs.test.mjs +290 -0
- package/test/lib/api-setup.mjs +93 -12
- package/toolg/gDistRollup.mjs +1 -1
package/README.md
CHANGED
|
@@ -68,11 +68,17 @@ async function test() {
|
|
|
68
68
|
//wo
|
|
69
69
|
let wo = WOrm(opt)
|
|
70
70
|
|
|
71
|
-
//on
|
|
71
|
+
//on change, 資料實際異動成功後發出
|
|
72
72
|
wo.on('change', function(mode, data, res) {
|
|
73
73
|
console.log('change', mode)
|
|
74
74
|
})
|
|
75
75
|
|
|
76
|
+
//on error, 操作發生錯誤時發出, 整批性錯誤於reject前、逐筆失敗於該筆定案後
|
|
77
|
+
//註: 事件僅為附加通知, 錯誤仍可由reject或逐筆之err欄位取得; 正常結果不會發出
|
|
78
|
+
wo.on('error', function(mode, data, err) {
|
|
79
|
+
console.log('error', mode, err)
|
|
80
|
+
})
|
|
81
|
+
|
|
76
82
|
//delAll
|
|
77
83
|
await wo.delAll()
|
|
78
84
|
.then(function(msg) {
|
|
@@ -195,13 +201,15 @@ test()
|
|
|
195
201
|
|
|
196
202
|
## Return values
|
|
197
203
|
|
|
198
|
-
本套件屬`w-orm
|
|
204
|
+
本套件屬`w-orm-*`系列,七個函數`select`、`selectByPk`、`insert`、`insertBulk`、`save`、`del`、`delAll`之回傳結構依系列統一規格:
|
|
199
205
|
|
|
200
206
|
```alias
|
|
201
207
|
select(find) → [ {...}, {...} ] 無符合為 []
|
|
202
208
|
selectByPk(pk) → {...} | null
|
|
203
209
|
|
|
204
|
-
insert(data)
|
|
210
|
+
insert(data, option) → { n, nInserted, ok }
|
|
211
|
+
insert(data, {returnList: true}) → [ { n, nInserted, ok }, ... ] 與輸入等長保序
|
|
212
|
+
insertBulk(data) → { n, nInserted, ok } 衝突即整批reject且不寫入任何一筆
|
|
205
213
|
save(data, option) → [ { n, nInserted, nModified, ok }, ... ]
|
|
206
214
|
del(data) → [ { n, nDeleted, ok }, ... ]
|
|
207
215
|
delAll(find) → { n, nDeleted, ok }
|
|
@@ -225,7 +233,9 @@ delAll(find) → { n, nDeleted, ok }
|
|
|
225
233
|
|
|
226
234
|
| 要判斷什麼 | 看什麼 |
|
|
227
235
|
|---|---|
|
|
236
|
+
| 這批有沒有撞到既有主鍵 | `insertBulk`是否`reject` |
|
|
228
237
|
| 這批有幾筆是新資料 | `insert`之`nInserted` |
|
|
238
|
+
| 這批**是哪幾筆**是新資料 | `insert(data, {returnList: true})`之各元素`nInserted === 1` |
|
|
229
239
|
| 這筆是不是新資料 | `save`之`nInserted === 1` |
|
|
230
240
|
| 這筆內容有沒有實際寫入 | `save`之`nModified === 1` |
|
|
231
241
|
| 這筆有沒有真的被刪 | `nDeleted` |
|
|
@@ -236,6 +246,63 @@ delAll(find) → { n, nDeleted, ok }
|
|
|
236
246
|
|
|
237
247
|
`del`對未帶有效`id`者不送查詢條件,直接回`ok: 0`並附`err`,以免`undefined`經序列化為`null`而誤刪`id`為`null`之數據。
|
|
238
248
|
|
|
249
|
+
## insert 的 returnList
|
|
250
|
+
|
|
251
|
+
聚合的`nInserted`回答「有幾筆是新的」,回答不了「**是哪幾筆**」——而後者正是去重的產出物(下游只對新資料做昂貴動作)。`option.returnList`把函數內部本就算出的逐筆判定交出來,免得呼叫端為了知道哪幾筆而把批次退化成單筆呼叫。
|
|
252
|
+
|
|
253
|
+
| `option.returnList` | 回傳 |
|
|
254
|
+
|---|---|
|
|
255
|
+
| `false`(預設) | `{ n, nInserted, ok }` |
|
|
256
|
+
| `true` | 與輸入**等長且保序**之陣列,元素為`{ n, nInserted, ok }` |
|
|
257
|
+
|
|
258
|
+
逐筆元素:已插入者`nInserted`為`1`,主鍵已存在而跳過者(含同批重複之非首筆)為`0`;`n`與`ok`恆為`1`——`insert`的任何錯誤都是整批性錯誤而`reject`,故逐筆元素不出現`ok: 0`與`err`。
|
|
259
|
+
|
|
260
|
+
```alias
|
|
261
|
+
let rs = await wo.insert([
|
|
262
|
+
{ id: 'a', name: 'x' },
|
|
263
|
+
{ id: 'b', name: 'y' }, //假設b已存在
|
|
264
|
+
{ id: 'c', name: 'z' },
|
|
265
|
+
], { returnList: true })
|
|
266
|
+
// => [ {n:1,nInserted:1,ok:1}, {n:1,nInserted:0,ok:1}, {n:1,nInserted:1,ok:1} ]
|
|
267
|
+
|
|
268
|
+
//取出本次真正新增的那幾筆
|
|
269
|
+
let rsNew = data.filter((v, k) => rs[k].nInserted === 1)
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
不變式:陣列長度等於輸入筆數,且`rs.filter(v => v.nInserted === 1).length`等於預設模式的`nInserted`。輸入無效時回`[]`。
|
|
273
|
+
|
|
274
|
+
回傳形式的切換是**靜態**的——呼叫點寫死取值即知回傳形狀。兩種取值是兩份契約,共用的結果處理程式碼不要跨不同取值的呼叫點混用。
|
|
275
|
+
|
|
276
|
+
`save`與`del`不提供此選項,因為它們本來就回等長保序的逐筆陣列,資訊已經在裡面(`rs[i].nInserted === 1`、`rs[i].nModified === 1`);`insertBulk`也不提供,因為成功時逐筆恆為已插入(零資訊量)、失敗時整批`reject`而無部分結果。
|
|
277
|
+
|
|
278
|
+
## insert vs insertBulk
|
|
279
|
+
|
|
280
|
+
兩者**衝突政策不同,不是同一個操作的加速版**:
|
|
281
|
+
|
|
282
|
+
| 情形 | `insert` | `insertBulk` |
|
|
283
|
+
|---|---|---|
|
|
284
|
+
| 主鍵已存在 | 跳過該筆,整批`ok: 1` | **整批`reject`,且不寫入任何一筆** |
|
|
285
|
+
| 同批重複主鍵 | 僅首筆計入`nInserted` | 視為衝突,整批`reject` |
|
|
286
|
+
| `nInserted` | 實際插入筆數,`0 ≤ nInserted ≤ n` | 成功時恆等於`n` |
|
|
287
|
+
| 適用場景 | 一般寫入,資料表可能已有既有資料 | 批次匯入,本即預期無衝突 |
|
|
288
|
+
|
|
289
|
+
確無衝突時兩者的可觀察結果完全相同(皆回`{ n, nInserted: n, ok: 1 }`),差異只在有衝突時顯現。需要逐筆處置者用`insert`;`insertBulk`不提供逐筆結果,故不出現`ok: 0`與`err`。
|
|
290
|
+
|
|
291
|
+
**本套件的`insertBulk`不會比`insert`快**——`insert`本來就是一次往返且計數精確。提供它是為了語義(全有全無)與跨套件的可替換性。
|
|
292
|
+
|
|
293
|
+
### 全有全無的達成方式
|
|
294
|
+
|
|
295
|
+
依部署而異,由套件於執行期以`hello`回應自動判定(`setName`或`msg`為`isdbgrid`),每個實例判定一次:
|
|
296
|
+
|
|
297
|
+
| 部署 | 作法 |
|
|
298
|
+
|---|---|
|
|
299
|
+
| replica set / 分片叢集 | 以交易包覆`insertMany`,失敗即回滾 |
|
|
300
|
+
| standalone | **無交易可用**,改以補償動作:偵測到衝突後刪除本次已寫入者,再`reject` |
|
|
301
|
+
|
|
302
|
+
補償動作刪除的依據是**本次由驅動在用戶端產生的`_id`**,與呼叫前既有資料的`_id`必不相同,故縱使該筆的`id`已存在也不會誤刪既有資料。
|
|
303
|
+
|
|
304
|
+
> **standalone 的限制**:補償動作於正常運作下可使狀態回復如初,但**行程若於補償途中中止(斷電、強制終止),已寫入的部分可能殘留**。這是無交易可用的固有限制。需要嚴格保證者請部署 replica set(單成員即可啟用交易)。
|
|
305
|
+
|
|
239
306
|
## Events
|
|
240
307
|
|
|
241
308
|
操作物件為`EventEmitter`,發出`change`與`error`兩種事件,供於單一處集中觀察資料異動與失敗,不必在每個呼叫點各自包裝。
|
|
@@ -434,11 +501,17 @@ async function test() {
|
|
|
434
501
|
//wo
|
|
435
502
|
let wo = WOrm(opt)
|
|
436
503
|
|
|
437
|
-
//on
|
|
504
|
+
//on change, 資料實際異動成功後發出
|
|
438
505
|
wo.on('change', function(mode, data, res) {
|
|
439
506
|
console.log('change', mode)
|
|
440
507
|
})
|
|
441
508
|
|
|
509
|
+
//on error, 操作發生錯誤時發出, 整批性錯誤於reject前、逐筆失敗於該筆定案後
|
|
510
|
+
//註: 事件僅為附加通知, 錯誤仍可由reject或逐筆之err欄位取得; 正常結果不會發出
|
|
511
|
+
wo.on('error', function(mode, data, err) {
|
|
512
|
+
console.log('error', mode, err)
|
|
513
|
+
})
|
|
514
|
+
|
|
442
515
|
//u8a, 亦可為瀏覽器或nodejs取得之任何Uint8Array
|
|
443
516
|
let u8a = genU8a(1000)
|
|
444
517
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* w-orm-mongodb v1.1.
|
|
2
|
+
* w-orm-mongodb v1.1.44
|
|
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("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}}));
|
|
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 i="object"==typeof global&&global&&global.Object===Object&&global,c="object"==typeof self&&self&&self.Object===Object&&self,a=i||c||Function("return this")(),l=a.Symbol,f=Object.prototype,s=f.hasOwnProperty,d=f.toString,v=l?l.toStringTag:void 0;var p=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,v),n=t[v];try{t[v]=void 0;var r=!0}catch(t){}var o=d.call(t);return r&&(e?t[v]=n:delete t[v]),o}(t):function(t){return p.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 B(t){if(null!=t){try{return P.call(t)}catch(t){}try{return t+""}catch(t){}}return""}var I=/^\[object .+?Constructor\]$/,z=Function.prototype,E=Object.prototype,M=z.toString,$=E.hasOwnProperty,C=RegExp("^"+M.call($).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function D(t){return!(!g(t)||(e=t,S&&S in e))&&(A(t)?C:I).test(B(t));var e}function U(t,e){var n=function(t,e){return null==t?void 0:t[e]}(t,e);return D(n)?n:void 0}var F=U(a,"Map"),N=U(Object,"create");var G=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__=N?N(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(N){var n=e[t];return"__lodash_hash_undefined__"===n?void 0:n}return G.call(e,t)?e[t]:void 0},L.prototype.has=function(t){var e=this.__data__;return N?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]=N&&void 0===e?"__lodash_hash_undefined__":e,this},R.prototype.clear=function(){this.size=0,this.__data__={hash:new L,map:new(F||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(!F||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=U(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,i=e.length;++u<i;){var c=e[u],a=r?r(n[c],t[c],c,n,t):void 0;void 0===a&&(a=t[c]),o?K(n,c,a):X(n,c,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,it=Array.isArray;var ct="object"==typeof exports&&exports&&!exports.nodeType&&exports,at=ct&&"object"==typeof module&&module&&!module.nodeType&&module,lt=at&&at.exports===ct?a.Buffer:void 0,ft=(lt?lt.isBuffer:void 0)||function(){return!1},st=9007199254740991,dt=/^(?:0|[1-9]\d*)$/;function vt(t,e){var n=typeof t;return!!(e=null==e?st:e)&&("number"==n||"symbol"!=n&&dt.test(t))&&t>-1&&t%1==0&&t<e}var pt=9007199254740991;function yt(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=pt}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&&i.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=it(t),r=!n&&ut(t),o=!n&&!r&&ft(t),u=!n&&!r&&!o&&Ot(t),i=n||r||o||u,c=i?function(t,e){for(var n=-1,r=Array(t);++n<t;)r[n]=e(n);return r}(t.length,String):[],a=c.length;for(var l in t)!e&&!At.call(t,l)||i&&("length"==l||o&&("offset"==l||"parent"==l)||u&&("buffer"==l||"byteLength"==l||"byteOffset"==l)||vt(l,a))||c.push(l);return c}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 Bt=Pt(Object.keys,Object),It=Object.prototype.hasOwnProperty;function zt(t){if(!St(t))return Bt(t);var e=[];for(var n in Object(t))It.call(t,n)&&"constructor"!=n&&e.push(n);return e}function Et(t){return null!=t&&yt(t.length)&&!A(t)}function Mt(t){return Et(t)?kt(t):zt(t)}var $t=Object.prototype.hasOwnProperty;function Ct(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&&$t.call(t,r))&&n.push(r);return n}function Dt(t){return Et(t)?kt(t,!0):Ct(t)}var Ut="object"==typeof exports&&exports&&!exports.nodeType&&exports,Ft=Ut&&"object"==typeof module&&module&&!module.nodeType&&module,Nt=Ft&&Ft.exports===Ut?a.Buffer:void 0,Gt=Nt?Nt.allocUnsafe:void 0;function Tt(t,e){for(var n=-1,r=null==t?0:t.length,o=0,u=[];++n<r;){var i=t[n];e(i,n,t)&&(u[o++]=i)}return u}function Lt(){return[]}var qt=Object.prototype.propertyIsEnumerable,Rt=Object.getOwnPropertySymbols,Vt=Rt?function(t){return null==t?[]:(t=Object(t),Tt(Rt(t),(function(e){return qt.call(t,e)})))}:Lt;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}:Lt,Kt=Jt;function Qt(t,e,n){var r=e(t);return it(t)?r:Wt(r,n(t))}function Xt(t){return Qt(t,Mt,Vt)}function Yt(t){return Qt(t,Dt,Kt)}var Zt=U(a,"DataView"),te=U(a,"Promise"),ee=U(a,"Set"),ne=U(a,"WeakMap"),re="[object Map]",oe="[object Promise]",ue="[object Set]",ie="[object WeakMap]",ce="[object DataView]",ae=B(Zt),le=B(F),fe=B(te),se=B(ee),de=B(ne),ve=j;(Zt&&ve(new Zt(new ArrayBuffer(1)))!=ce||F&&ve(new F)!=re||te&&ve(te.resolve())!=oe||ee&&ve(new ee)!=ue||ne&&ve(new ne)!=ie)&&(ve=function(t){var e=j(t),n="[object Object]"==e?t.constructor:void 0,r=n?B(n):"";if(r)switch(r){case ae:return ce;case le:return re;case fe:return oe;case se:return ue;case de:return ie}return e});var pe=ve,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]",Be="[object ArrayBuffer]",Ie="[object DataView]",ze="[object Float32Array]",Ee="[object Float64Array]",Me="[object Int8Array]",$e="[object Int16Array]",Ce="[object Int32Array]",De="[object Uint8Array]",Ue="[object Uint8ClampedArray]",Fe="[object Uint16Array]",Ne="[object Uint32Array]";function Ge(t,e,n){var r,o,u,i=t.constructor;switch(e){case Be:return he(t);case we:case me:return new i(+t);case Ie:return function(t,e){var n=e?he(t.buffer):t.buffer;return new t.constructor(n,t.byteOffset,t.byteLength)}(t,n);case ze:case Ee:case Me:case $e:case Ce:case De:case Ue:case Fe:case Ne: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 i;case Ae:case Se:return new i(t);case ke:return(u=new(o=t).constructor(o.source,je.exec(o))).lastIndex=o.lastIndex,u;case xe:return new i;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]"==pe(t)};var We=wt&&wt.isSet,He=We?ht(We):function(t){return Z(t)&&"[object Set]"==pe(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 i,c=e&Je,a=e&Ke,l=e&Qe;if(n&&(i=o?n(t,r,o,u):n(t)),void 0!==i)return i;if(!g(t))return t;var f=it(t);if(f){if(i=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),!c)return function(t,e){var n=-1,r=t.length;for(e||(e=Array(r));++n<r;)e[n]=t[n];return e}(t,i)}else{var s=pe(t),d=s==Ye||s==Ze;if(ft(t))return function(t,e){if(e)return t.slice();var n=t.length,r=Gt?Gt(n):new t.constructor(n);return t.copy(r),r}(t,c);if(s==tn||s==Xe||d&&!o){if(i=a||d?{}:function(t){return"function"!=typeof t.constructor||St(t)?{}:qe(Ht(t))}(t),!c)return a?function(t,e){return Y(t,Kt(t),e)}(t,function(t,e){return t&&Y(e,Dt(e),t)}(i,t)):function(t,e){return Y(t,Vt(t),e)}(t,function(t,e){return t&&Y(e,Mt(e),t)}(i,t))}else{if(!en[s])return o?t:{};i=Ge(t,s,c)}}u||(u=new V);var v=u.get(t);if(v)return v;u.set(t,i),He(t)?t.forEach((function(r){i.add(nn(r,e,n,r,t,u))})):Ve(t)&&t.forEach((function(r,o){i.set(o,nn(r,e,n,o,t,u))}));var p=f?void 0:(l?a?Yt:Xt:a?Dt:Mt)(t);return W(p||t,(function(r,o){p&&(r=t[o=r]),X(i,o,nn(r,e,n,o,t,u))})),i}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)}var cn,an=function(t,e,n){for(var r=-1,o=Object(t),u=n(t),i=u.length;i--;){var c=u[cn?i:++r];if(!1===e(o[c],c,o))break}return t};var ln=function(t,e){return function(n,r){if(null==n)return n;if(!Et(n))return t(n,r);for(var o=n.length,u=e?o:-1,i=Object(n);(e?u--:++u<o)&&!1!==r(i[u],u,i););return n}}((function(t,e){return t&&an(t,e,Mt)})),fn=ln;function sn(t){return t}function dn(t,e){var n;return(it(t)?W:fn)(t,"function"==typeof(n=e)?n:sn)}function vn(t,e){for(var n=-1,r=null==t?0:t.length;++n<r;)if(!e(t[n],n,t))return!1;return!0}function pn(t,e){var n=!0;return fn(t,(function(t,r,o){return n=!!e(t,r,o)})),n}function yn(t){var e=-1,n=null==t?0:t.length;for(this.__data__=new R;++e<n;)this.add(t[e])}function bn(t,e){for(var n=-1,r=null==t?0:t.length;++n<r;)if(e(t[n],n,t))return!0;return!1}yn.prototype.add=yn.prototype.push=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this},yn.prototype.has=function(t){return this.__data__.has(t)};var hn=1,jn=2;function gn(t,e,n,r,o,u){var i=n&hn,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=n&jn?new yn:void 0;for(u.set(t,e),u.set(e,t);++s<c;){var p=t[s],y=e[s];if(r)var b=i?r(y,p,s,e,t,u):r(p,y,s,t,e,u);if(void 0!==b){if(b)continue;d=!1;break}if(v){if(!bn(e,(function(t,e){if(i=e,!v.has(i)&&(p===t||o(p,t,n,r,u)))return v.push(e);var i}))){d=!1;break}}else if(p!==y&&!o(p,y,n,r,u)){d=!1;break}}return u.delete(t),u.delete(e),d}function _n(t){var e=-1,n=Array(t.size);return t.forEach((function(t,r){n[++e]=[r,t]})),n}function wn(t){var e=-1,n=Array(t.size);return t.forEach((function(t){n[++e]=t})),n}var mn=1,On=2,An="[object Boolean]",kn="[object Date]",xn="[object Error]",Sn="[object Map]",Pn="[object Number]",Bn="[object RegExp]",In="[object Set]",zn="[object String]",En="[object Symbol]",Mn="[object ArrayBuffer]",$n="[object DataView]",Cn=l?l.prototype:void 0,Dn=Cn?Cn.valueOf:void 0;var Un=1,Fn=Object.prototype.hasOwnProperty;var Nn=1,Gn="[object Arguments]",Tn="[object Array]",Ln="[object Object]",qn=Object.prototype.hasOwnProperty;function Rn(t,e,r,o,u,i){var c=it(t),a=it(e),l=c?Tn:pe(t),f=a?Tn:pe(e),s=(l=l==Gn?Ln:l)==Ln,d=(f=f==Gn?Ln:f)==Ln,v=l==f;if(v&&ft(t)){if(!ft(e))return!1;c=!0,s=!1}if(v&&!s)return i||(i=new V),c||Ot(t)?gn(t,e,r,o,u,i):function(t,e,r,o,u,i,c){switch(r){case $n:if(t.byteLength!=e.byteLength||t.byteOffset!=e.byteOffset)return!1;t=t.buffer,e=e.buffer;case Mn:return!(t.byteLength!=e.byteLength||!i(new be(t),new be(e)));case An:case kn:case Pn:return n(+t,+e);case xn:return t.name==e.name&&t.message==e.message;case Bn:case zn:return t==e+"";case Sn:var a=_n;case In:var l=o&mn;if(a||(a=wn),t.size!=e.size&&!l)return!1;var f=c.get(t);if(f)return f==e;o|=On,c.set(t,e);var s=gn(a(t),a(e),o,u,i,c);return c.delete(t),s;case En:if(Dn)return Dn.call(t)==Dn.call(e)}return!1}(t,e,l,r,o,u,i);if(!(r&Nn)){var p=s&&qn.call(t,"__wrapped__"),y=d&&qn.call(e,"__wrapped__");if(p||y){var b=p?t.value():t,h=y?e.value():e;return i||(i=new V),u(b,h,r,o,i)}}return!!v&&(i||(i=new V),function(t,e,n,r,o,u){var i=n&Un,c=Xt(t),a=c.length;if(a!=Xt(e).length&&!i)return!1;for(var l=a;l--;){var f=c[l];if(!(i?f in e:Fn.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 y=t[f=c[l]],b=e[f];if(r)var h=i?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)){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 Vn(t,e,n,r,o){return t===e||(null==t||null==e||!Z(t)&&!Z(e)?t!=t&&e!=e:Rn(t,e,n,r,Vn,o))}var Wn=1,Hn=2;function Jn(t){return t==t&&!g(t)}function Kn(t,e){return function(n){return null!=n&&(n[t]===e&&(void 0!==e||t in Object(n)))}}function Qn(t){var e=function(t){for(var e=Mt(t),n=e.length;n--;){var r=e[n],o=t[r];e[n]=[r,o,Jn(o)]}return e}(t);return 1==e.length&&e[0][2]?Kn(e[0][0],e[0][1]):function(n){return n===t||function(t,e,n,r){var o=n.length,u=o,i=!r;if(null==t)return!u;for(t=Object(t);o--;){var c=n[o];if(i&&c[2]?c[1]!==t[c[0]]:!(c[0]in t))return!1}for(;++o<u;){var a=(c=n[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 V;if(r)var d=r(l,f,a,t,e,s);if(!(void 0===d?Vn(f,l,Wn|Hn,r,s):d))return!1}}return!0}(n,t,e)}}var Xn="[object Symbol]";function Yn(t){return"symbol"==typeof t||Z(t)&&j(t)==Xn}var Zn=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,tr=/^\w*$/;function er(t,e){if(it(t))return!1;var n=typeof t;return!("number"!=n&&"symbol"!=n&&"boolean"!=n&&null!=t&&!Yn(t))||(tr.test(t)||!Zn.test(t)||null!=e&&t in Object(e))}var nr="Expected a function";function rr(t,e){if("function"!=typeof t||null!=e&&"function"!=typeof e)throw new TypeError(nr);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 i=t.apply(this,r);return n.cache=u.set(o,i)||u,i};return n.cache=new(rr.Cache||R),n}rr.Cache=R;var or,ur,ir,cr=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,ar=/\\(\\)?/g,lr=(or=function(t){var e=[];return 46===t.charCodeAt(0)&&e.push(""),t.replace(cr,(function(t,n,r,o){e.push(r?o.replace(ar,"$1"):n||t)})),e},ur=rr(or,(function(t){return 500===ir.size&&ir.clear(),t})),ir=ur.cache,ur),fr=lr;function sr(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 dr=1/0,vr=l?l.prototype:void 0,pr=vr?vr.toString:void 0;function yr(t){if("string"==typeof t)return t;if(it(t))return sr(t,yr)+"";if(Yn(t))return pr?pr.call(t):"";var e=t+"";return"0"==e&&1/t==-dr?"-0":e}function br(t,e){return it(t)?t:er(t,e)?[t]:fr(function(t){return null==t?"":yr(t)}(t))}var hr=1/0;function jr(t){if("string"==typeof t||Yn(t))return t;var e=t+"";return"0"==e&&1/t==-hr?"-0":e}function gr(t,e){for(var n=0,r=(e=br(e,t)).length;null!=t&&n<r;)t=t[jr(e[n++])];return n&&n==r?t:void 0}function _r(t,e,n){var r=null==t?void 0:gr(t,e);return void 0===r?n:r}function wr(t,e){return null!=t&&e in Object(t)}function mr(t,e){return null!=t&&function(t,e,n){for(var r=-1,o=(e=br(e,t)).length,u=!1;++r<o;){var i=jr(e[r]);if(!(u=null!=t&&n(t,i)))break;t=t[i]}return u||++r!=o?u:!!(o=null==t?0:t.length)&&yt(o)&&vt(i,o)&&(it(t)||ut(t))}(t,e,wr)}var Or=1,Ar=2;function kr(t){return function(e){return null==e?void 0:e[t]}}function xr(t){return er(t)?kr(jr(t)):function(t){return function(e){return gr(e,t)}}(t)}function Sr(t){return"function"==typeof t?t:null==t?sn:"object"==typeof t?it(t)?(e=t[0],n=t[1],er(e)&&Jn(n)?Kn(jr(e),n):function(t){var r=_r(t,e);return void 0===r&&r===n?mr(t,e):Vn(n,r,Or|Ar)}):Qn(t):xr(t);var e,n}function Pr(t,e,r){var o=it(t)?vn:pn;return r&&function(t,e,r){if(!g(r))return!1;var o=typeof e;return!!("number"==o?Et(r)&&vt(e,r.length):"string"==o&&e in r)&&n(r[e],t)}(t,e,r)&&(e=void 0),o(t,Sr(e))}function Br(t,e){var n=[];return fn(t,(function(t,r,o){e(t,r,o)&&n.push(t)})),n}function Ir(t,e){var n=-1,r=Et(t)?Array(t.length):[];return fn(t,(function(t,o,u){r[++n]=e(t,o,u)})),r}function zr(t,e){return(it(t)?sr:Ir)(t,Sr(e))}function Er(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 Mr=Object.prototype.hasOwnProperty;function $r(t,e){var n=-1,r=(e=br(e,t)).length;if(!r)return!0;for(;++n<r;){var o=jr(e[n]);if("__proto__"===o&&!Mr.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:gr(t,Er(e,0,-1))}(t,e);return null==u||delete u[jr(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,Fr=Dr.toString,Nr=Ur.hasOwnProperty,Gr=Fr.call(Object);function Tr(t){return function(t){if(!Z(t)||j(t)!=Cr)return!1;var e=Ht(t);if(null===e)return!0;var n=Nr.call(e,"constructor")&&e.constructor;return"function"==typeof n&&n instanceof n&&Fr.call(n)==Gr}(t)?void 0:t}var Lr=l?l.isConcatSpreadable:void 0;function qr(t){return it(t)||ut(t)||!!(Lr&&t&&t[Lr])}function Rr(t,e,n,r,o){var u=-1,i=t.length;for(n||(n=qr),o||(o=[]);++u<i;){var c=t[u];e>0&&n(c)?e>1?Rr(c,e-1,n,r,o):Wt(o,c):r||(o[o.length]=c)}return o}function Vr(t){return(null==t?0:t.length)?Rr(t,1):[]}var Wr=Math.max;var Hr=J?function(t,e){return J(t,"toString",{configurable:!0,enumerable:!1,value:(n=e,function(){return n}),writable:!0});var n}:sn,Jr=Hr,Kr=Date.now;var Qr=function(t){var e=0,n=0;return function(){var r=Kr(),o=16-(r-n);if(n=r,o>0){if(++e>=800)return arguments[0]}else e=0;return t.apply(void 0,arguments)}}(Jr),Xr=Qr;var Yr=function(t){return Xr(function(t,e,n){return e=Wr(void 0===e?t.length-1:e,0),function(){for(var r=arguments,o=-1,u=Wr(r.length-e,0),i=Array(u);++o<u;)i[o]=r[e+o];o=-1;for(var c=Array(e+1);++o<e;)c[o]=r[o];return c[e]=n(i),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,c)}}(t,void 0,Vr),t+"")}((function(t,e){var n={};if(null==t)return n;var r=!1;e=sr(e,(function(e){return e=br(e,t),r||(r=e.length>1),e})),Y(t,Yt(t),n),r&&(n=nn(n,7,Tr));for(var o=e.length;o--;)$r(n,e[o]);return n})),Zr=Yr,to="[object String]";var eo=kr("length"),no=RegExp("[\\u200d\\ud800-\\udfff\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff\\ufe0e\\ufe0f]");var ro="\\ud800-\\udfff",oo="["+ro+"]",uo="[\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff]",io="\\ud83c[\\udffb-\\udfff]",co="[^"+ro+"]",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("|")+")",yo=RegExp(io+"(?="+io+")|"+po+vo,"g");function bo(t){return function(t){return no.test(t)}(t)?function(t){for(var e=yo.lastIndex=0;yo.test(t);)++e;return e}(t):eo(t)}var ho="[object Map]",jo="[object Set]";function go(t){if(null==t)return 0;if(Et(t))return"string"==typeof(e=t)||!it(e)&&Z(e)&&j(e)==to?bo(t):t.length;var e,n=pe(t);return n==ho||n==jo?t.size:zt(t).length}var _o={};!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,i){if("function"!=typeof r)throw new TypeError("The listener must be a function");var c=new o(r,u||t,i),a=n?n+e:e;return t._events[a]?t._events[a].fn?t._events[a]=[t._events[a],c]:t._events[a].push(c):(t._events[a]=c,t._eventsCount++),t}function i(t,e){0==--t._eventsCount?t._events=new r:delete t._events[e]}function c(){this._events=new r,this._eventsCount=0}Object.create&&(r.prototype=Object.create(null),(new r).__proto__||(n=!1)),c.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},c.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,i=new Array(u);o<u;o++)i[o]=r[o].fn;return i},c.prototype.listenerCount=function(t){var e=n?n+t:t,r=this._events[e];return r?r.fn?1:r.length:0},c.prototype.emit=function(t,e,r,o,u,i){var c=n?n+t:t;if(!this._events[c])return!1;var a,l,f=this._events[c],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,i),!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 d,v=f.length;for(l=0;l<v;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(d=1,a=new Array(s-1);d<s;d++)a[d-1]=arguments[d];f[l].fn.apply(f[l].context,a)}}return!0},c.prototype.on=function(t,e,n){return u(this,t,e,n,!1)},c.prototype.once=function(t,e,n){return u(this,t,e,n,!0)},c.prototype.removeListener=function(t,e,r,o){var u=n?n+t:t;if(!this._events[u])return this;if(!e)return i(this,u),this;var c=this._events[u];if(c.fn)c.fn!==e||o&&!c.once||r&&c.context!==r||i(this,u);else{for(var a=0,l=[],f=c.length;a<f;a++)(c[a].fn!==e||o&&!c[a].once||r&&c[a].context!==r)&&l.push(c[a]);l.length?this._events[u]=1===l.length?l[0]:l:i(this,u)}return this},c.prototype.removeAllListeners=function(t){var e;return t?(e=n?n+t:t,this._events[e]&&i(this,e)):(this._events=new r,this._eventsCount=0),this},c.prototype.off=c.prototype.removeListener,c.prototype.addListener=c.prototype.on,c.prefixed=n,c.EventEmitter=c,t.exports=c}({get exports(){return _o},set exports(t){_o=t}});var wo=_o;function mo(){let t,e,n=new Promise((function(){t=arguments[0],e=arguments[1]}));return n.resolve=t,n.reject=e,n}const Oo=[];for(let t=0;t<256;++t)Oo.push((t+256).toString(16).slice(1));const Ao=new Uint8Array(16);function ko(){return crypto.getRandomValues(Ao)}const xo={};function So(t,e,n){let r;if(t)r=Po(t.random??t.rng?.()??ko(),t.msecs,t.seq,e,n);else{const t=Date.now(),o=ko();!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++)}(xo,t,o),r=Po(o,xo.msecs,xo.seq,e,n)}return e??function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return(Oo[t[e+0]]+Oo[t[e+1]]+Oo[t[e+2]]+Oo[t[e+3]]+"-"+Oo[t[e+4]]+Oo[t[e+5]]+"-"+Oo[t[e+6]]+Oo[t[e+7]]+"-"+Oo[t[e+8]]+Oo[t[e+9]]+"-"+Oo[t[e+10]]+Oo[t[e+11]]+Oo[t[e+12]]+Oo[t[e+13]]+Oo[t[e+14]]+Oo[t[e+15]]).toLowerCase()}(r)}function Po(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 Bo="[object Boolean]";function Io(t){return!0===(e=t)||!1===e||Z(e)&&j(e)==Bo;var e}function zo(t){return"[object String]"===Object.prototype.toString.call(t)}function Eo(t){return!(!zo(t)||""===t)}function Mo(t){return"[object Array]"===Object.prototype.toString.call(t)}function $o(t){return"[object Object]"===Object.prototype.toString.call(t)}function Co(t){return t!=t}function Do(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($o(t)){for(let e in t)return!1;return!0}return!1}(t)||(!!function(t){return!(!zo(t)||""!==t)}(t)||(!!function(t){return!!Mo(t)&&0===t.length}(t)||!!Co(t)))))}function Uo(t){return!!Mo(t)&&(0!==t.length&&(1!==t.length||!Do(t[0])))}function Fo(t){if($o(t)){for(let e in t)return!0;return!1}return!1}function No(t){let e=!1;if(Eo(t))e=!isNaN(Number(t));else if(function(t){return"[object Number]"===Object.prototype.toString.call(t)}(t)){if(Co(t))return!1;e=!0}return e}var Go=/\s/;var To=/^\s+/;function Lo(t){return t?t.slice(0,function(t){for(var e=t.length;e--&&Go.test(t.charAt(e)););return e}(t)+1).replace(To,""):t}var qo=NaN,Ro=/^[-+]0x[0-9a-f]+$/i,Vo=/^0b[01]+$/i,Wo=/^0o[0-7]+$/i,Ho=parseInt;var Jo=1/0,Ko=17976931348623157e292;function Qo(t){return t?(t=function(t){if("number"==typeof t)return t;if(Yn(t))return qo;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=Lo(t);var n=Vo.test(t);return n||Wo.test(t)?Ho(t.slice(2),n?2:8):Ro.test(t)?qo:+t}(t))===Jo||t===-Jo?(t<0?-1:1)*Ko:t==t?t:0:0===t?t:0}function Xo(t,e,n){var r=null==t?0:t.length;return r?(e=n||void 0===e?1:function(t){var e=Qo(t),n=e%1;return e==e?n?e-n:e:0}(e),Er(t,e<0?0:e,r)):[]}function Yo(t){let e=Object.prototype.toString.call(t);return"[object Function]"===e||"[object AsyncFunction]"===e}function Zo(t,e){let n=mo();if(!Mo(t)&&!$o(t))return n.reject("rs is not an array or object"),n;let r=!1;if($o(t)){r=!0;let e=[];dn(t,((t,n)=>{e.push({k:n,v:t})})),t=e}Yo(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 i=o,c=n;return r&&(i=n.k,c=n.v),Yo(e)?e(c,i):c}))}),Promise.resolve()).then((function(t){u.push(t),u=Xo(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=_r(n,"autoGenPk");Io(r)||(r=!0);let o=!1,u=!1,i=null,c=new wo,a=t.MongoClient;function l(t){let e=_r(t,"message");return Eo(e)?e:String(t)}function f(t,e,n){try{c.emit("change",t,e,n)}catch(t){console.log(t)}}function s(t,e,n){try{c.emit("error",t,e,l(n))}catch(t){console.log(t)}}function d(t,e){if(!Eo(t.id)){if(!r)throw new Error(`invalid data[${e}].id, autoGenPk is false`);t.id=So()}return t}function v(t){let e=_r(t,"writeErrors");return Uo(e)?Pr(e,(function(t){return 11e3===_r(t,"code")||11e3===_r(t,"err.code")})):11e3===_r(t,"code")}async function p(t){o||(await t.createIndex({id:1},{unique:!0}),o=!0)}async function y(t,e){let n=null;try{await t.insertMany(e,{ordered:!1})}catch(t){n=t}if(null===n)return;let r=zr(e,(function(t){return t._id}));throw r=function(t,e){return(it(t)?Tt:Br)(t,Sr(e))}(r,(function(t){return null!=t})),go(r)>0&&await t.deleteMany({_id:{$in:r}}),n}async function b(){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 a(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=Zr(t,"_id")}))}catch(t){e=!0,o=t}finally{await r.close(),r=null}return e?(s("select",null,o),Promise.reject(o)):o},c.selectByPk=async function(t){let e=!1;if(!Eo(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=Fo(u)?u:null}catch(t){e=!0,o=t}finally{await r.close(),r=null}return e?(s("selectByPk",null,o),Promise.reject(o)):o},c.insert=async function(t){let e=!1,r=_r(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},"returnList");if(Io(r)||(r=!1),!Fo(t)&&!Uo(t))return r?[]:{n:0,nInserted:0,ok:1};t=un(t);let o=new a(n.url),u=null;try{await o.connect();let e=o.db(n.db).collection(n.cl);Mo(t)||(t=[t]),t=zr(t,d),await p(e);let i=go(t),c=0,a={};try{c=(await e.insertMany(t,{ordered:!1})).insertedCount}catch(t){if(!v(t))throw t;c=_r(t,"result.insertedCount",0),dn(_r(t,"writeErrors",[]),(function(t){let e=_r(t,"index",_r(t,"err.index"));No(e)&&(a[e]=!0)}))}u=r?zr(t,(function(t,e){return{n:1,nInserted:!0===a[e]?0:1,ok:1}})):{n:i,nInserted:c,ok:1}}catch(t){e=!0,u=t}finally{await o.close(),o=null}return e||f("insert",t,u),e?(s("insert",t,u),Promise.reject(u)):u},c.insertBulk=async function(t){let e=!1;if(!Fo(t)&&!Uo(t))return{n:0,nInserted:0,ok:1};t=un(t);let r=new a(n.url),o=null;try{await r.connect();let e=r.db(n.db).collection(n.cl);Mo(t)||(t=[t]),t=zr(t,d),await p(e);let u=go(t),c=await async function(t){if(Io(i))return i;let e=await t.db(n.db).admin().command({hello:1});return i=Eo(_r(e,"setName"))||"isdbgrid"===_r(e,"msg"),i}(r);c?await async function(t,e,n){let r=t.startSession();try{await r.withTransaction((async()=>{await e.insertMany(n,{session:r,ordered:!0})}))}finally{await r.endSession()}}(r,e,t):await y(e,t),o={n:u,nInserted:u,ok:1}}catch(t){e=!0,o=t}finally{await r.close(),r=null}return e||f("insertBulk",t,o),e?(s("insertBulk",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(!Fo(t)&&!Uo(t))return[];t=un(t);let o=_r(e,"autoInsert",!0),u=new a(n.url),i=null;try{await u.connect();let e=u.db(n.db).collection(n.cl);Mo(t)||(t=[t]),t=zr(t,d),await p(e),i=await Zo(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}),i=_r(u,"matchedCount",0),c=_r(u,"modifiedCount",0);_r(u,"upsertedCount",0)>0?(r={n:1,nInserted:1,nModified:0,ok:1},o=!0):r=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(v(t)&&u<2)continue;r={n:1,nInserted:0,nModified:0,ok:0,err:l(t)};break}return o&&f("insert",[e],r),0===r.ok&&s("save",[e],r.err),r}(e,t,o)))}catch(t){r=!0,i=t}finally{await u.close(),u=null}return r||f("save",t,i),r?(s("save",t,i),Promise.reject(i)):i},c.del=async function(t){let e=!1;if(!Fo(t)&&!Uo(t))return[];t=un(t);let r=new a(n.url),o=null;try{await r.connect();let e=r.db(n.db).collection(n.cl);Mo(t)||(t=[t]),o=await Zo(t,(async t=>{let n=_r(t,"id"),r=null;if(Eo(n))try{let t=_r(await e.deleteOne({id:n}),"deletedCount",0);r={n:t,nDeleted:t,ok:1}}catch(t){r={n:1,nDeleted:0,ok:0,err:l(t)}}else r={n:0,nDeleted:0,ok:0,err:`invalid id[${n}]`};return 0===r.ok&&s("del",[t],r.err),r}))}catch(t){e=!0,o=t}finally{await r.close(),r=null}return e||f("del",t,o),e?(s("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 a(n.url),o=null;try{let e=r.db(n.db).collection(n.cl),u=_r(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?(s("delAll",null,o),Promise.reject(o)):o},c.selectByPkGfs=async function(e){let r=!1;if(!Eo(e))return null;let o=new a(n.url),u=null;try{u={id:e,u8a:await(async e=>{let r=mo(),u=o.db(n.db),i=new t.GridFSBucket(u,{chunkSizeBytes:10485760,bucketName:n.cl}),c=Buffer.from(""),a=i.openDownloadStreamByName(e);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})(e)}}catch(t){"ENOENT"===_r(t,"code")?u=null:(r=!0,u=t)}finally{await o.close(),o=null}return r?(s("selectByPkGfs",null,u),Promise.reject(u)):u},c.insertGfs=async function(r){let o=!1;if(!Fo(r)&&!Uo(r))return{n:0,nInserted:0,ok:1};let i=new a(n.url),c=null;try{await i.connect();let o=i.db(n.db),a=new t.GridFSBucket(o,{chunkSizeBytes:10485760,bucketName:n.cl}),l=o.collection(`${n.cl}.chunks`);Mo(r)||(r=[r]),r=zr(r,(function(t,e){if(!function(t){return"[object Uint8Array]"===Object.prototype.toString.call(t)}((t=d(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=go(r),s=0;await Zo(r,(async t=>{let n=await function(t,n,r,o){let u=mo(),i=t.openUploadStream(r),c=i.id,a=new e.Readable;return a._read=()=>{},a.push(Buffer.from(o)),a.push(null),a.pipe(i).on("error",(function(t){v(t)?n.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);n&&s++})),c={n:f,nInserted:s,ok:1}}catch(t){o=!0,c=t}finally{await i.close(),i=null}return o||f("insertGfs",r,c),o?(s("insertGfs",r,c),Promise.reject(c)):c},c.delGfs=async function(e){let r=!1;if(!Fo(e)&&!Uo(e))return[];let o=new a(n.url),u=null;try{await o.connect();let r=o.db(n.db),i=new t.GridFSBucket(r,{chunkSizeBytes:10485760,bucketName:n.cl});Mo(e)||(e=[e]),u=await Zo(e,(async t=>{let e=_r(t,"id"),n=null;if(Eo(e))try{let t=await b({filename:e},i),r=0;for(let e of t)await i.delete(e._id),r++;n={n:r>0?1:0,nDeleted:r,ok:1}}catch(t){n={n:1,nDeleted:0,ok:0,err:l(t)}}else n={n:0,nDeleted:0,ok:0,err:`invalid id[${e}]`};return 0===n.ok&&s("delGfs",[t],n.err),n}))}catch(t){r=!0,u=t}finally{await o.close(),o=null}return r||f("delGfs",e,u),r?(s("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 a(n.url),u=null;try{let r=o.db(n.db),i=new t.GridFSBucket(r,{chunkSizeBytes:10485760,bucketName:n.cl}),c=await b(e,i),a=zr(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?(s("delAllGfs",null,u),Promise.reject(u)):u},c}}));
|
|
7
7
|
//# sourceMappingURL=w-orm-mongodb.umd.js.map
|