w-orm-mongodb 1.2.6 → 1.2.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -8,6 +8,27 @@ An operator for mongodb in nodejs.
8
8
  [![npm download](https://img.shields.io/npm/dm/w-orm-mongodb.svg)](https://npmjs.org/package/w-orm-mongodb)
9
9
  [![jsdelivr download](https://img.shields.io/jsdelivr/npm/hm/w-orm-mongodb.svg)](https://www.jsdelivr.com/package/npm/w-orm-mongodb)
10
10
 
11
+ ## 破壞性變更
12
+
13
+ `select(find)`、`delAll(find)`、`delAllGfs(find)`之條件(find)改為**系列條件白名單**(`w-orm-*`系列一致,詳見下方「條件(find)白名單」),白名單外之輸入一律於到達MongoDB之前以`invalid find: 原因 at [路徑]`整批`reject`,不設過渡期:
14
+
15
+ | 項目 | 原行為 | 現行為 |
16
+ |---|---|---|
17
+ | `$regex`、`$options`、`$exists`、`$not`、`$nor`、`$where`、`$expr`、`$text`、`$jsonSchema`、`$comment`、`$type`、`$mod`、`$elemMatch`、`$size`、`$all`、地理空間等運算子 | 交由MongoDB伺服器處理(`$where`字串會於伺服器執行) | `reject` |
18
+ | 點路徑(`{ 'a.b': 1 }`)、含連字號或空白之欄名、欄位層`$and`/`$or`、RegExp值、陣列值、巢狀物件等值 | 交由MongoDB伺服器處理 | `reject` |
19
+ | 頂層為`null`、陣列、字串、數字、布林、函數、`Date`、`Map`、`Set`、類別實例等非條件物件 | 部分被驅動拒收;`Map`、`Set`、類別實例、僅Symbol鍵之物件被放行 | 一律`reject`,不視為`{}` |
20
+ | 函數值、Symbol值、不可列舉鍵、稀疏陣列之洞 | 被BSON序列化略過,條件消失(`delAll`刪光全表) | `reject` |
21
+ | 存取器(getter)屬性、Symbol鍵 | 存取器於序列化時被執行;Symbol鍵被忽略 | `reject` |
22
+ | `undefined`值 | 被序列化為`null`,命中欄位為`null`或缺欄之數據 | `reject` |
23
+ | NaN、±Infinity、無效`Date`、BigInt、Buffer、字串含NUL或孤立代理字元 | 依BSON表示交由MongoDB伺服器比對(多半無命中) | `reject` |
24
+ | `$nin: []`、`$and: [{}]`、`$or: [{}]`、`$expr: true` | 條件為恆真,`delAll`刪光全表 | `reject` |
25
+ | `$and: []`、`$or: []` | 由MongoDB伺服器拒收 | `reject`(改為連線前拒收,訊息為`invalid find: ...`) |
26
+ | `{ f: {} }`、`{ f: { $ne: [20] } }` 等文件值或陣列值之等值比對 | 交由MongoDB伺服器依文件值或陣列值比對 | `reject` |
27
+ | `$gt`、`$gte`、`$lt`、`$lte`之`null`值,`$in`、`$nin`元素含`null` | 交由MongoDB伺服器處理 | `reject`(`null`僅可用於欄位等值、`$eq`、`$ne`) |
28
+ | `delAllGfs`之GridFS條件(含`delGfs`逐筆之`{ filename: id }`) | `metadata.*`等點路徑可用;`id`含NUL者可刪 | 同一白名單,點路徑不可用;`id`含NUL或孤立代理字元者`delGfs`該筆回`n: 0`、`ok: 0`與`err`(不論該`id`是否存在,不影響同批其他筆) |
29
+
30
+ 未變:`{}`、未給、`undefined`皆代表全部;白名單內之條件,命中集合不變(MongoDB式語意);`select`回傳仍不含`_id`。需要被移除之功能者(如模糊比對),請改為`select`後於記憶體過濾。
31
+
11
32
  ## Documentation
12
33
  To view documentation or get support, visit [docs](https://yuda-lyu.github.io/w-orm-mongodb/WOrmMongodb.html).
13
34
 
@@ -126,8 +147,10 @@ async function test() {
126
147
  let spc = await wo.select({ '$or': [{ '$and': [{ value: { '$ne': 123 } }, { value: { '$in': [123, 321, 123.456, 456] } }, { value: { '$nin': [456, 654] } }] }, { '$or': [{ value: { '$lte': -1 } }, { value: { '$gte': 400 } }] }] })
127
148
  console.log('select by $or, $and, $ne, $in, $nin', spc)
128
149
 
129
- //select by regex, $options之合法flag僅有i、m、x、s
130
- let sr = await wo.select({ name: { $regex: 'PeT', $options: 'i' } })
150
+ //select by regex, $regex與$options不在條件(find)白名單內(會reject), 需要模糊比對時改為select後於記憶體過濾
151
+ let sr = ss.filter(function(v) {
152
+ return /PeT/i.test(v.name)
153
+ })
131
154
  console.log('selectReg', sr)
132
155
 
133
156
  //selectByPk, 由id直接查找單筆, 不需如select提取全部符合數據再處理
@@ -246,6 +269,36 @@ delAll(find) → { n, nDeleted, ok }
246
269
 
247
270
  `del`對未帶有效`id`者不送查詢條件,直接回`ok: 0`並附`err`,以免`undefined`經序列化為`null`而誤刪`id`為`null`之數據。
248
271
 
272
+ ## 條件(find)白名單
273
+
274
+ `select(find)`、`delAll(find)`、`delAllGfs(find)`之`find`只支援下列系列白名單(`w-orm-*`系列一致),其餘一律整批`reject`,訊息為`invalid find: 原因 at [路徑]`(不回顯值),且不建立連線、不讀取、不刪除。檢核由`wsemi`之`cvOrmFind`負責,檢核後之條件副本才交給MongoDB(檢查之值即使用之值)。
275
+
276
+ | 項目 | 說明 |
277
+ |---|---|
278
+ | 全部 | 未給、`undefined`、`{}`皆為全部數據。除此之外`find`須為一般物件(原型為`Object.prototype`或`null`),`null`、陣列、字串、數值、布林、函數、`Date`、`RegExp`、`Map`、`Set`、類別實例等一律`reject`,不視為`{}` |
279
+ | 欄位等值 | `{ 欄: 純量 }`,多欄為AND |
280
+ | 欄位運算子 | `$eq $ne $gt $gte $lt $lte`(值為純量)、`$in $nin`(值為純量陣列) |
281
+ | 文件層邏輯 | `$and`、`$or`(值為條件物件之非空陣列) |
282
+ | 純量 | 字串、有限數字、布林、有效`Date`;`null`僅可用於欄位等值、`$eq`、`$ne`;字串不得含NUL與孤立代理字元 |
283
+ | 空集合 | `$in: []`恆假(命中0筆);`$nin: []`、`$and: []`、`$or: []`、`$and`/`$or`之元素為`{}`、運算子物件為`{}`一律`reject` |
284
+ | 欄名 | 1~128個UTF-16碼元(以字串`length`計),符合`^[\p{L}_][\p{L}\p{M}\p{N}_]*$`,禁`__proto__`;點路徑、`$`開頭、含連字號/空白/引號者`reject`。`_bsontype`為BSON保留欄名,雖符合文法,MongoDB driver無法將其作為一般欄位送出而會`reject`(不會命中或刪除任何數據) |
285
+ | 上限 | 邏輯巢狀深度32、`$and`/`$or`長度1000、`$in`/`$nin`長度10000、節點總數100000 |
286
+ | 其餘 | `$not $nor $regex $options $exists $type $where $expr $function $text $elemMatch $size $all $mod`、地理空間、欄位層`$and`/`$or`、`undefined`值、函數值、Symbol鍵與值等白名單外輸入一律`reject` |
287
+
288
+ 語意為MongoDB伺服器原生行為(MongoDB式):
289
+
290
+ - 欄位值以BSON型別比對,`{ age: '20' }`不命中數字`20`;字串區分大小寫。
291
+ - `{ f: null }`、`{ f: { $eq: null } }`會命中欄位為`null`或缺欄之數據;因此欄名拼錯時,`delAll({ 拼錯之欄: null })`、`$ne`、`$nin`會命中全部數據,呼叫`delAll`前須確認欄名。
292
+ - `$ne`(比較值非`null`)、`$nin`會命中欄位為`null`或缺欄之數據,`$ne: null`則僅命中欄位存在且非`null`者。需明確表達時可用可攜寫法(與`w-orm-*`其他套件之結果一致):排除null為`{ $and: [{ f: { $ne: null } }, { f: { $ne: x } }] }`,含null為`{ $or: [{ f: null }, { f: { $ne: x } }] }`。
293
+ - 同一`find`,`select`命中之數據即`delAll`刪除之數據。
294
+
295
+ `delAll`/`delAllGfs`使用須知:
296
+
297
+ - 不給條件(未給、`undefined`、`{}`)即刪除全部數據,不另行確認;給了條件才是部分刪除。經資料通道(如`w-serv-webdata`)呼叫者語意與本套件一致,不另加限制。
298
+ - 傳了值卻不是條件物件(`null`、陣列、字串等)會整批`reject`,不會視為`{}`。
299
+ - 條件須審慎:`undefined`值會`reject`而非被忽略,`$nin: []`會`reject`,`$in: []`為恆假(刪除0筆);條件值若來自可能為`undefined`、`null`或空陣列之變數,呼叫端須先自行判斷。建議先以`select(find)`確認命中範圍再刪除。
300
+ - `delAll`須審慎使用,非必要不用;刪除單筆請用`del`。
301
+
249
302
  ## insert 的 returnList
250
303
 
251
304
  聚合的`nInserted`回答「有幾筆是新的」,回答不了「**是哪幾筆**」——而後者正是去重的產出物(下游只對新資料做昂貴動作)。`option.returnList`把函數內部本就算出的逐筆判定交出來,免得呼叫端為了知道哪幾筆而把批次退化成單筆呼叫。
@@ -472,6 +525,8 @@ GridFS函數之參數與回傳形狀比照一般操作,數據物件為`{ id, u
472
525
  | `delGfs(data)` | `del` | `[ { n, nDeleted, ok }, ... ]` |
473
526
  | `delAllGfs(find)` | `delAll` | `{ n, nDeleted, ok }` |
474
527
 
528
+ `delAllGfs(find)`之`find`適用上方「條件(find)白名單」(`<cl>.files`之欄位如`filename`、`length`、`uploadDate`可用,`metadata.*`等點路徑不可用),不給條件即刪除全部檔案。
529
+
475
530
  `insertGfs`同樣具備「已存在則跳過」語義,以`<cl>.files`之`filename`唯一索引達成,升級前提與一般操作相同。GridFS無法於單一原子操作內取代既有內容,故不提供`saveGfs`,更新請以`delGfs`後再`insertGfs`完成。
476
531
 
477
532
  ```alias
@@ -1,7 +1,7 @@
1
1
  /*!
2
- * w-orm-mongodb v1.2.6
2
+ * w-orm-mongodb v1.2.7
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 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 N=U(a,"Map"),F=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__=F?F(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(F){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 F?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]=F&&void 0===e?"__lodash_hash_undefined__":e,this},R.prototype.clear=function(){this.size=0,this.__data__={hash:new L,map:new(N||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(!N||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&&gt.exports===jt&&i.process,wt=function(){try{var t=gt&&gt.require&&gt.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,Nt=Ut&&"object"==typeof module&&module&&!module.nodeType&&module,Ft=Nt&&Nt.exports===Ut?a.Buffer:void 0,Gt=Ft?Ft.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(N),fe=B(te),se=B(ee),de=B(ne),ve=j;(Zt&&ve(new Zt(new ArrayBuffer(1)))!=ce||N&&ve(new N)!=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]",Ne="[object Uint16Array]",Fe="[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 Ne:case Fe: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,Nn=Object.prototype.hasOwnProperty;var Fn=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&Fn)){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:Nn.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,Nr=Dr.toString,Fr=Ur.hasOwnProperty,Gr=Nr.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=Fr.call(e,"constructor")&&e.constructor;return"function"==typeof n&&n instanceof n&&Nr.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=Bo(n),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??=Bo(t),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}function Bo(t){return(127&t[6])<<24|t[7]<<16|t[8]<<8|t[9]}var Io="[object Boolean]";function zo(t){return!0===(e=t)||!1===e||Z(e)&&j(e)==Io;var e}function Eo(t){return"[object String]"===Object.prototype.toString.call(t)}function Mo(t){return!(!Eo(t)||""===t)}function $o(t){return"[object Array]"===Object.prototype.toString.call(t)}function Co(t){return"[object Object]"===Object.prototype.toString.call(t)}function Do(t){return t!=t}function Uo(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(Co(t)){for(let e in t)return!1;return!0}return!1}(t)||(!!function(t){return!(!Eo(t)||""!==t)}(t)||(!!function(t){return!!$o(t)&&0===t.length}(t)||!!Do(t)))))}function No(t){return!!$o(t)&&(0!==t.length&&(1!==t.length||!Uo(t[0])))}function Fo(t){if(Co(t)){for(let e in t)return!0;return!1}return!1}function Go(t){let e=!1;if(Mo(t)){if(""===t.trim())return!1;e=!isNaN(Number(t))}else if(function(t){return"[object Number]"===Object.prototype.toString.call(t)}(t)){if(Do(t))return!1;e=!0}return e}var To=/\s/;var Lo=/^\s+/;function qo(t){return t?t.slice(0,function(t){for(var e=t.length;e--&&To.test(t.charAt(e)););return e}(t)+1).replace(Lo,""):t}var Ro=NaN,Vo=/^[-+]0x[0-9a-f]+$/i,Wo=/^0b[01]+$/i,Ho=/^0o[0-7]+$/i,Jo=parseInt;var Ko=1/0,Qo=17976931348623157e292;function Xo(t){return t?(t=function(t){if("number"==typeof t)return t;if(Yn(t))return Ro;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=qo(t);var n=Wo.test(t);return n||Ho.test(t)?Jo(t.slice(2),n?2:8):Vo.test(t)?Ro:+t}(t))===Ko||t===-Ko?(t<0?-1:1)*Qo:t==t?t:0:0===t?t:0}function Yo(t,e,n){var r=null==t?0:t.length;return r?(e=n||void 0===e?1:function(t){var e=Xo(t),n=e%1;return e==e?n?e-n:e:0}(e),Er(t,e<0?0:e,r)):[]}function Zo(t){return A(t)}function tu(t,e){let n=mo();if(!$o(t)&&!Co(t))return n.reject("rs is not an array or object"),n;let r=!1;if(Co(t)){r=!0;let e=[];dn(t,((t,n)=>{e.push({k:n,v:t})})),t=e}Zo(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),Zo(e)?e(c,i):c}))}),Promise.resolve()).then((function(t){u.push(t),u=Yo(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");zo(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 Mo(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(!Mo(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 No(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(!Mo(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(zo(r)||(r=!1),!Fo(t)&&!No(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);$o(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"));Go(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)&&!No(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);$o(t)||(t=[t]),t=zr(t,d),await p(e);let u=go(t),c=await async function(t){if(zo(i))return i;let e=await t.db(n.db).admin().command({hello:1});return i=Mo(_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)&&!No(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);$o(t)||(t=[t]),t=zr(t,d),await p(e),i=await tu(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)&&!No(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);$o(t)||(t=[t]),o=await tu(t,(async t=>{let n=_r(t,"id"),r=null;if(Mo(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(!Mo(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)&&!No(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`);$o(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 tu(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)&&!No(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});$o(e)||(e=[e]),u=await tu(e,(async t=>{let e=_r(t,"id"),n=null;if(Mo(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}}));
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 i(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])}}i.prototype.clear=function(){this.__data__=[],this.size=0},i.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)},i.prototype.get=function(t){var e=this.__data__,n=r(e,t);return n<0?void 0:e[n][1]},i.prototype.has=function(t){return r(this.__data__,t)>-1},i.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 u="object"==typeof global&&global&&global.Object===Object&&global,a="object"==typeof self&&self&&self.Object===Object&&self,c=u||a||Function("return this")(),l=c.Symbol,f=Object.prototype,s=f.hasOwnProperty,p=f.toString,d=l?l.toStringTag:void 0;var y=Object.prototype.toString;var h="[object Null]",b="[object Undefined]",v=l?l.toStringTag:void 0;function g(t){return null==t?void 0===t?b:h:v&&v in Object(t)?function(t){var e=s.call(t,d),n=t[d];try{t[d]=void 0;var r=!0}catch(t){}var o=p.call(t);return r&&(e?t[d]=n:delete t[d]),o}(t):function(t){return y.call(t)}(t)}function j(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}var m="[object AsyncFunction]",w="[object Function]",_="[object GeneratorFunction]",O="[object Proxy]";function x(t){if(!j(t))return!1;var e=g(t);return e==w||e==_||e==m||e==O}var k,A=c["__core-js_shared__"],S=(k=/[^.]+$/.exec(A&&A.keys&&A.keys.IE_PROTO||""))?"Symbol(src)_1."+k:"";var $=Function.prototype.toString;function P(t){if(null!=t){try{return $.call(t)}catch(t){}try{return t+""}catch(t){}}return""}var E=/^\[object .+?Constructor\]$/,I=Function.prototype,D=Object.prototype,B=I.toString,N=D.hasOwnProperty,F=RegExp("^"+B.call(N).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function C(t){return!(!j(t)||(e=t,S&&S in e))&&(x(t)?F:E).test(P(t));var e}function L(t,e){var n=function(t,e){return null==t?void 0:t[e]}(t,e);return C(n)?n:void 0}var z=L(c,"Map"),M=L(Object,"create");var U=Object.prototype.hasOwnProperty;var G=Object.prototype.hasOwnProperty;function T(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 R(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 q(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])}}T.prototype.clear=function(){this.__data__=M?M(null):{},this.size=0},T.prototype.delete=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},T.prototype.get=function(t){var e=this.__data__;if(M){var n=e[t];return"__lodash_hash_undefined__"===n?void 0:n}return U.call(e,t)?e[t]:void 0},T.prototype.has=function(t){var e=this.__data__;return M?void 0!==e[t]:G.call(e,t)},T.prototype.set=function(t,e){var n=this.__data__;return this.size+=this.has(t)?0:1,n[t]=M&&void 0===e?"__lodash_hash_undefined__":e,this},q.prototype.clear=function(){this.size=0,this.__data__={hash:new T,map:new(z||i),string:new T}},q.prototype.delete=function(t){var e=R(this,t).delete(t);return this.size-=e?1:0,e},q.prototype.get=function(t){return R(this,t).get(t)},q.prototype.has=function(t){return R(this,t).has(t)},q.prototype.set=function(t,e){var n=R(this,t),r=n.size;return n.set(t,e),this.size+=n.size==r?0:1,this};function W(t){var e=this.__data__=new i(t);this.size=e.size}function V(t,e){for(var n=-1,r=null==t?0:t.length;++n<r&&!1!==e(t[n],n,t););return t}W.prototype.clear=function(){this.__data__=new i,this.size=0},W.prototype.delete=function(t){var e=this.__data__,n=e.delete(t);return this.size=e.size,n},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 n=this.__data__;if(n instanceof i){var r=n.__data__;if(!z||r.length<199)return r.push([t,e]),this.size=++n.size,this;n=this.__data__=new q(r)}return n.set(t,e),this.size=n.size,this};var K=function(){try{var t=L(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),Z=K;function H(t,e,n){"__proto__"==e&&Z?Z(t,e,{configurable:!0,enumerable:!0,value:n,writable:!0}):t[e]=n}var J=Object.prototype.hasOwnProperty;function Q(t,e,r){var o=t[e];J.call(t,e)&&n(o,r)&&(void 0!==r||e in t)||H(t,e,r)}function X(t,e,n,r){var o=!n;n||(n={});for(var i=-1,u=e.length;++i<u;){var a=e[i],c=r?r(n[a],t[a],a,n,t):void 0;void 0===c&&(c=t[a]),o?H(n,a,c):Q(n,a,c)}return n}function Y(t){return null!=t&&"object"==typeof t}function tt(t){return Y(t)&&"[object Arguments]"==g(t)}var et=Object.prototype,nt=et.hasOwnProperty,rt=et.propertyIsEnumerable,ot=tt(function(){return arguments}())?tt:function(t){return Y(t)&&nt.call(t,"callee")&&!rt.call(t,"callee")},it=ot,ut=Array.isArray;var at="object"==typeof exports&&exports&&!exports.nodeType&&exports,ct=at&&"object"==typeof module&&module&&!module.nodeType&&module,lt=ct&&ct.exports===at?c.Buffer:void 0,ft=(lt?lt.isBuffer:void 0)||function(){return!1},st=9007199254740991,pt=/^(?:0|[1-9]\d*)$/;function dt(t,e){var n=typeof t;return!!(e=null==e?st:e)&&("number"==n||"symbol"!=n&&pt.test(t))&&t>-1&&t%1==0&&t<e}var yt=9007199254740991;function ht(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=yt}var bt={};function vt(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 gt="object"==typeof exports&&exports&&!exports.nodeType&&exports,jt=gt&&"object"==typeof module&&module&&!module.nodeType&&module,mt=jt&&jt.exports===gt&&u.process,wt=function(){try{var t=jt&&jt.require&&jt.require("util").types;return t||mt&&mt.binding&&mt.binding("util")}catch(t){}}(),_t=wt&&wt.isTypedArray,Ot=_t?vt(_t):function(t){return Y(t)&&ht(t.length)&&!!bt[g(t)]},xt=Object.prototype.hasOwnProperty;function kt(t,e){var n=ut(t),r=!n&&it(t),o=!n&&!r&&ft(t),i=!n&&!r&&!o&&Ot(t),u=n||r||o||i,a=u?function(t,e){for(var n=-1,r=Array(t);++n<t;)r[n]=e(n);return r}(t.length,String):[],c=a.length;for(var l in t)!e&&!xt.call(t,l)||u&&("length"==l||o&&("offset"==l||"parent"==l)||i&&("buffer"==l||"byteLength"==l||"byteOffset"==l)||dt(l,c))||a.push(l);return a}var At=Object.prototype;function St(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||At)}function $t(t,e){return function(n){return t(e(n))}}var Pt=$t(Object.keys,Object),Et=Object.prototype.hasOwnProperty;function It(t){if(!St(t))return Pt(t);var e=[];for(var n in Object(t))Et.call(t,n)&&"constructor"!=n&&e.push(n);return e}function Dt(t){return null!=t&&ht(t.length)&&!x(t)}function Bt(t){return Dt(t)?kt(t):It(t)}var Nt=Object.prototype.hasOwnProperty;function Ft(t){if(!j(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&&Nt.call(t,r))&&n.push(r);return n}function Ct(t){return Dt(t)?kt(t,!0):Ft(t)}var Lt="object"==typeof exports&&exports&&!exports.nodeType&&exports,zt=Lt&&"object"==typeof module&&module&&!module.nodeType&&module,Mt=zt&&zt.exports===Lt?c.Buffer:void 0,Ut=Mt?Mt.allocUnsafe:void 0;function Gt(t,e){for(var n=-1,r=null==t?0:t.length,o=0,i=[];++n<r;){var u=t[n];e(u,n,t)&&(i[o++]=u)}return i}function Tt(){return[]}var Rt=Object.prototype.propertyIsEnumerable,qt=Object.getOwnPropertySymbols,Wt=qt?function(t){return null==t?[]:(t=Object(t),Gt(qt(t),(function(e){return Rt.call(t,e)})))}:Tt;function Vt(t,e){for(var n=-1,r=e.length,o=t.length;++n<r;)t[o+n]=e[n];return t}var Kt=$t(Object.getPrototypeOf,Object),Zt=Object.getOwnPropertySymbols?function(t){for(var e=[];t;)Vt(e,Wt(t)),t=Kt(t);return e}:Tt,Ht=Zt;function Jt(t,e,n){var r=e(t);return ut(t)?r:Vt(r,n(t))}function Qt(t){return Jt(t,Bt,Wt)}function Xt(t){return Jt(t,Ct,Ht)}var Yt=L(c,"DataView"),te=L(c,"Promise"),ee=L(c,"Set"),ne=L(c,"WeakMap"),re="[object Map]",oe="[object Promise]",ie="[object Set]",ue="[object WeakMap]",ae="[object DataView]",ce=P(Yt),le=P(z),fe=P(te),se=P(ee),pe=P(ne),de=g;(Yt&&de(new Yt(new ArrayBuffer(1)))!=ae||z&&de(new z)!=re||te&&de(te.resolve())!=oe||ee&&de(new ee)!=ie||ne&&de(new ne)!=ue)&&(de=function(t){var e=g(t),n="[object Object]"==e?t.constructor:void 0,r=n?P(n):"";if(r)switch(r){case ce:return ae;case le:return re;case fe:return oe;case se:return ie;case pe:return ue}return e});var ye=de,he=Object.prototype.hasOwnProperty;var be=c.Uint8Array;function ve(t){var e=new t.constructor(t.byteLength);return new be(e).set(new be(t)),e}var ge=/\w*$/;var je=l?l.prototype:void 0,me=je?je.valueOf:void 0;var we="[object Boolean]",_e="[object Date]",Oe="[object Map]",xe="[object Number]",ke="[object RegExp]",Ae="[object Set]",Se="[object String]",$e="[object Symbol]",Pe="[object ArrayBuffer]",Ee="[object DataView]",Ie="[object Float32Array]",De="[object Float64Array]",Be="[object Int8Array]",Ne="[object Int16Array]",Fe="[object Int32Array]",Ce="[object Uint8Array]",Le="[object Uint8ClampedArray]",ze="[object Uint16Array]",Me="[object Uint32Array]";function Ue(t,e,n){var r,o,i,u=t.constructor;switch(e){case Pe:return ve(t);case we:case _e:return new u(+t);case Ee:return function(t,e){var n=e?ve(t.buffer):t.buffer;return new t.constructor(n,t.byteOffset,t.byteLength)}(t,n);case Ie:case De:case Be:case Ne:case Fe:case Ce:case Le:case ze:case Me:return function(t,e){var n=e?ve(t.buffer):t.buffer;return new t.constructor(n,t.byteOffset,t.length)}(t,n);case Oe:return new u;case xe:case Se:return new u(t);case ke:return(i=new(o=t).constructor(o.source,ge.exec(o))).lastIndex=o.lastIndex,i;case Ae:return new u;case $e:return r=t,me?Object(me.call(r)):{}}}var Ge=Object.create,Te=function(){function t(){}return function(e){if(!j(e))return{};if(Ge)return Ge(e);t.prototype=e;var n=new t;return t.prototype=void 0,n}}(),Re=Te;var qe=wt&&wt.isMap,We=qe?vt(qe):function(t){return Y(t)&&"[object Map]"==ye(t)};var Ve=wt&&wt.isSet,Ke=Ve?vt(Ve):function(t){return Y(t)&&"[object Set]"==ye(t)},Ze=1,He=2,Je=4,Qe="[object Arguments]",Xe="[object Function]",Ye="[object GeneratorFunction]",tn="[object Object]",en={};function nn(t,e,n,r,o,i){var u,a=e&Ze,c=e&He,l=e&Je;if(n&&(u=o?n(t,r,o,i):n(t)),void 0!==u)return u;if(!j(t))return t;var f=ut(t);if(f){if(u=function(t){var e=t.length,n=new t.constructor(e);return e&&"string"==typeof t[0]&&he.call(t,"index")&&(n.index=t.index,n.input=t.input),n}(t),!a)return function(t,e){var n=-1,r=t.length;for(e||(e=Array(r));++n<r;)e[n]=t[n];return e}(t,u)}else{var s=ye(t),p=s==Xe||s==Ye;if(ft(t))return function(t,e){if(e)return t.slice();var n=t.length,r=Ut?Ut(n):new t.constructor(n);return t.copy(r),r}(t,a);if(s==tn||s==Qe||p&&!o){if(u=c||p?{}:function(t){return"function"!=typeof t.constructor||St(t)?{}:Re(Kt(t))}(t),!a)return c?function(t,e){return X(t,Ht(t),e)}(t,function(t,e){return t&&X(e,Ct(e),t)}(u,t)):function(t,e){return X(t,Wt(t),e)}(t,function(t,e){return t&&X(e,Bt(e),t)}(u,t))}else{if(!en[s])return o?t:{};u=Ue(t,s,a)}}i||(i=new W);var d=i.get(t);if(d)return d;i.set(t,u),Ke(t)?t.forEach((function(r){u.add(nn(r,e,n,r,t,i))})):We(t)&&t.forEach((function(r,o){u.set(o,nn(r,e,n,o,t,i))}));var y=f?void 0:(l?c?Xt:Qt:c?Ct:Bt)(t);return V(y||t,(function(r,o){y&&(r=t[o=r]),Q(u,o,nn(r,e,n,o,t,i))})),u}en[Qe]=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[Xe]=en["[object WeakMap]"]=!1;var rn=1,on=4;function un(t){return nn(t,rn|on)}var an,cn=function(t,e,n){for(var r=-1,o=Object(t),i=n(t),u=i.length;u--;){var a=i[an?u:++r];if(!1===e(o[a],a,o))break}return t};var ln=function(t,e){return function(n,r){if(null==n)return n;if(!Dt(n))return t(n,r);for(var o=n.length,i=e?o:-1,u=Object(n);(e?i--:++i<o)&&!1!==r(u[i],i,u););return n}}((function(t,e){return t&&cn(t,e,Bt)})),fn=ln;function sn(t){return t}function pn(t,e){var n;return(ut(t)?V:fn)(t,"function"==typeof(n=e)?n:sn)}function dn(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 yn(t,e){var n=!0;return fn(t,(function(t,r,o){return n=!!e(t,r,o)})),n}function hn(t){var e=-1,n=null==t?0:t.length;for(this.__data__=new q;++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}hn.prototype.add=hn.prototype.push=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this},hn.prototype.has=function(t){return this.__data__.has(t)};var vn=1,gn=2;function jn(t,e,n,r,o,i){var u=n&vn,a=t.length,c=e.length;if(a!=c&&!(u&&c>a))return!1;var l=i.get(t),f=i.get(e);if(l&&f)return l==e&&f==t;var s=-1,p=!0,d=n&gn?new hn:void 0;for(i.set(t,e),i.set(e,t);++s<a;){var y=t[s],h=e[s];if(r)var b=u?r(h,y,s,e,t,i):r(y,h,s,t,e,i);if(void 0!==b){if(b)continue;p=!1;break}if(d){if(!bn(e,(function(t,e){if(u=e,!d.has(u)&&(y===t||o(y,t,n,r,i)))return d.push(e);var u}))){p=!1;break}}else if(y!==h&&!o(y,h,n,r,i)){p=!1;break}}return i.delete(t),i.delete(e),p}function mn(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 _n=1,On=2,xn="[object Boolean]",kn="[object Date]",An="[object Error]",Sn="[object Map]",$n="[object Number]",Pn="[object RegExp]",En="[object Set]",In="[object String]",Dn="[object Symbol]",Bn="[object ArrayBuffer]",Nn="[object DataView]",Fn=l?l.prototype:void 0,Cn=Fn?Fn.valueOf:void 0;var Ln=1,zn=Object.prototype.hasOwnProperty;var Mn=1,Un="[object Arguments]",Gn="[object Array]",Tn="[object Object]",Rn=Object.prototype.hasOwnProperty;function qn(t,e,r,o,i,u){var a=ut(t),c=ut(e),l=a?Gn:ye(t),f=c?Gn:ye(e),s=(l=l==Un?Tn:l)==Tn,p=(f=f==Un?Tn:f)==Tn,d=l==f;if(d&&ft(t)){if(!ft(e))return!1;a=!0,s=!1}if(d&&!s)return u||(u=new W),a||Ot(t)?jn(t,e,r,o,i,u):function(t,e,r,o,i,u,a){switch(r){case Nn:if(t.byteLength!=e.byteLength||t.byteOffset!=e.byteOffset)return!1;t=t.buffer,e=e.buffer;case Bn:return!(t.byteLength!=e.byteLength||!u(new be(t),new be(e)));case xn:case kn:case $n:return n(+t,+e);case An:return t.name==e.name&&t.message==e.message;case Pn:case In:return t==e+"";case Sn:var c=mn;case En:var l=o&_n;if(c||(c=wn),t.size!=e.size&&!l)return!1;var f=a.get(t);if(f)return f==e;o|=On,a.set(t,e);var s=jn(c(t),c(e),o,i,u,a);return a.delete(t),s;case Dn:if(Cn)return Cn.call(t)==Cn.call(e)}return!1}(t,e,l,r,o,i,u);if(!(r&Mn)){var y=s&&Rn.call(t,"__wrapped__"),h=p&&Rn.call(e,"__wrapped__");if(y||h){var b=y?t.value():t,v=h?e.value():e;return u||(u=new W),i(b,v,r,o,u)}}return!!d&&(u||(u=new W),function(t,e,n,r,o,i){var u=n&Ln,a=Qt(t),c=a.length;if(c!=Qt(e).length&&!u)return!1;for(var l=c;l--;){var f=a[l];if(!(u?f in e:zn.call(e,f)))return!1}var s=i.get(t),p=i.get(e);if(s&&p)return s==e&&p==t;var d=!0;i.set(t,e),i.set(e,t);for(var y=u;++l<c;){var h=t[f=a[l]],b=e[f];if(r)var v=u?r(b,h,f,e,t,i):r(h,b,f,t,e,i);if(!(void 0===v?h===b||o(h,b,n,r,i):v)){d=!1;break}y||(y="constructor"==f)}if(d&&!y){var g=t.constructor,j=e.constructor;g==j||!("constructor"in t)||!("constructor"in e)||"function"==typeof g&&g instanceof g&&"function"==typeof j&&j instanceof j||(d=!1)}return i.delete(t),i.delete(e),d}(t,e,r,o,i,u))}function Wn(t,e,n,r,o){return t===e||(null==t||null==e||!Y(t)&&!Y(e)?t!=t&&e!=e:qn(t,e,n,r,Wn,o))}var Vn=1,Kn=2;function Zn(t){return t==t&&!j(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=Bt(t),n=e.length;n--;){var r=e[n],o=t[r];e[n]=[r,o,Zn(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,i=o,u=!r;if(null==t)return!i;for(t=Object(t);o--;){var a=n[o];if(u&&a[2]?a[1]!==t[a[0]]:!(a[0]in t))return!1}for(;++o<i;){var c=(a=n[o])[0],l=t[c],f=a[1];if(u&&a[2]){if(void 0===l&&!(c in t))return!1}else{var s=new W;if(r)var p=r(l,f,c,t,e,s);if(!(void 0===p?Wn(f,l,Vn|Kn,r,s):p))return!1}}return!0}(n,t,e)}}var Qn="[object Symbol]";function Xn(t){return"symbol"==typeof t||Y(t)&&g(t)==Qn}var Yn=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,tr=/^\w*$/;function er(t,e){if(ut(t))return!1;var n=typeof t;return!("number"!=n&&"symbol"!=n&&"boolean"!=n&&null!=t&&!Xn(t))||(tr.test(t)||!Yn.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],i=n.cache;if(i.has(o))return i.get(o);var u=t.apply(this,r);return n.cache=i.set(o,u)||i,u};return n.cache=new(rr.Cache||q),n}rr.Cache=q;var or,ir,ur,ar=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,cr=/\\(\\)?/g,lr=(or=function(t){var e=[];return 46===t.charCodeAt(0)&&e.push(""),t.replace(ar,(function(t,n,r,o){e.push(r?o.replace(cr,"$1"):n||t)})),e},ir=rr(or,(function(t){return 500===ur.size&&ur.clear(),t})),ur=ir.cache,ir),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 pr=1/0,dr=l?l.prototype:void 0,yr=dr?dr.toString:void 0;function hr(t){if("string"==typeof t)return t;if(ut(t))return sr(t,hr)+"";if(Xn(t))return yr?yr.call(t):"";var e=t+"";return"0"==e&&1/t==-pr?"-0":e}function br(t,e){return ut(t)?t:er(t,e)?[t]:fr(function(t){return null==t?"":hr(t)}(t))}var vr=1/0;function gr(t){if("string"==typeof t||Xn(t))return t;var e=t+"";return"0"==e&&1/t==-vr?"-0":e}function jr(t,e){for(var n=0,r=(e=br(e,t)).length;null!=t&&n<r;)t=t[gr(e[n++])];return n&&n==r?t:void 0}function mr(t,e,n){var r=null==t?void 0:jr(t,e);return void 0===r?n:r}function wr(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=br(e,t)).length,i=!1;++r<o;){var u=gr(e[r]);if(!(i=null!=t&&n(t,u)))break;t=t[u]}return i||++r!=o?i:!!(o=null==t?0:t.length)&&ht(o)&&dt(u,o)&&(ut(t)||it(t))}(t,e,wr)}var Or=1,xr=2;function kr(t){return function(e){return null==e?void 0:e[t]}}function Ar(t){return er(t)?kr(gr(t)):function(t){return function(e){return jr(e,t)}}(t)}function Sr(t){return"function"==typeof t?t:null==t?sn:"object"==typeof t?ut(t)?(e=t[0],n=t[1],er(e)&&Zn(n)?Hn(gr(e),n):function(t){var r=mr(t,e);return void 0===r&&r===n?_r(t,e):Wn(n,r,Or|xr)}):Jn(t):Ar(t);var e,n}function $r(t,e,r){var o=ut(t)?dn:yn;return r&&function(t,e,r){if(!j(r))return!1;var o=typeof e;return!!("number"==o?Dt(r)&&dt(e,r.length):"string"==o&&e in r)&&n(r[e],t)}(t,e,r)&&(e=void 0),o(t,Sr(e))}function Pr(t,e){var n=[];return fn(t,(function(t,r,o){e(t,r,o)&&n.push(t)})),n}function Er(t,e){var n=-1,r=Dt(t)?Array(t.length):[];return fn(t,(function(t,o,i){r[++n]=e(t,o,i)})),r}function Ir(t,e){return(ut(t)?sr:Er)(t,Sr(e))}function Dr(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 i=Array(o);++r<o;)i[r]=t[r+e];return i}var Br=Object.prototype.hasOwnProperty;function Nr(t,e){var n=-1,r=(e=br(e,t)).length;if(!r)return!0;for(;++n<r;){var o=gr(e[n]);if("__proto__"===o&&!Br.call(t,"__proto__"))return!1;if(("constructor"===o||"prototype"===o)&&n<r-1)return!1}var i=function(t,e){return e.length<2?t:jr(t,Dr(e,0,-1))}(t,e);return null==i||delete i[gr(function(t){var e=null==t?0:t.length;return e?t[e-1]:void 0}(e))]}var Fr="[object Object]",Cr=Function.prototype,Lr=Object.prototype,zr=Cr.toString,Mr=Lr.hasOwnProperty,Ur=zr.call(Object);function Gr(t){return function(t){if(!Y(t)||g(t)!=Fr)return!1;var e=Kt(t);if(null===e)return!0;var n=Mr.call(e,"constructor")&&e.constructor;return"function"==typeof n&&n instanceof n&&zr.call(n)==Ur}(t)?void 0:t}var Tr=l?l.isConcatSpreadable:void 0;function Rr(t){return ut(t)||it(t)||!!(Tr&&t&&t[Tr])}function qr(t,e,n,r,o){var i=-1,u=t.length;for(n||(n=Rr),o||(o=[]);++i<u;){var a=t[i];e>0&&n(a)?e>1?qr(a,e-1,n,r,o):Vt(o,a):r||(o[o.length]=a)}return o}function Wr(t){return(null==t?0:t.length)?qr(t,1):[]}var Vr=Math.max;var Kr=Z?function(t,e){return Z(t,"toString",{configurable:!0,enumerable:!1,value:(n=e,function(){return n}),writable:!0});var n}:sn,Zr=Kr,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)}}(Zr),Qr=Jr;var Xr=function(t){return Qr(function(t,e,n){return e=Vr(void 0===e?t.length-1:e,0),function(){for(var r=arguments,o=-1,i=Vr(r.length-e,0),u=Array(i);++o<i;)u[o]=r[e+o];o=-1;for(var a=Array(e+1);++o<e;)a[o]=r[o];return a[e]=n(u),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,a)}}(t,void 0,Wr),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})),X(t,Xt(t),n),r&&(n=nn(n,7,Gr));for(var o=e.length;o--;)Nr(n,e[o]);return n})),Yr=Xr,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+"]",io="[\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff]",uo="\\ud83c[\\udffb-\\udfff]",ao="[^"+ro+"]",co="(?:\\ud83c[\\udde6-\\uddff]){2}",lo="[\\ud800-\\udbff][\\udc00-\\udfff]",fo="(?:"+io+"|"+uo+")"+"?",so="[\\ufe0e\\ufe0f]?",po=so+fo+("(?:\\u200d(?:"+[ao,co,lo].join("|")+")"+so+fo+")*"),yo="(?:"+[ao+io+"?",io,co,lo,oo].join("|")+")",ho=RegExp(uo+"(?="+uo+")|"+yo+po,"g");function bo(t){return function(t){return no.test(t)}(t)?function(t){for(var e=ho.lastIndex=0;ho.test(t);)++e;return e}(t):eo(t)}var vo="[object Map]",go="[object Set]";function jo(t){if(null==t)return 0;if(Dt(t))return"string"==typeof(e=t)||!ut(e)&&Y(e)&&g(e)==to?bo(t):t.length;var e,n=ye(t);return n==vo||n==go?t.size:It(t).length}let mo={maxDepth:32,maxList:1e3,maxIn:1e4,maxNodes:1e5,maxKey:128},wo=Reflect.ownKeys,_o=Object.getOwnPropertyDescriptor,Oo=Object.getPrototypeOf,xo=Object.defineProperty,ko=Object.create,Ao=Array.isArray,So=Number.isInteger,$o=Number.isFinite,Po=Number.isNaN,Eo=Number.isSafeInteger,Io=Object.prototype,Do=Date,Bo=Function.prototype.call,No=Bo.bind(Object.prototype.hasOwnProperty),Fo=Bo.bind(Object.prototype.toString),Co=Bo.bind(Date.prototype.getTime),Lo=Bo.bind(WeakSet.prototype.add),zo=Bo.bind(WeakSet.prototype.has),Mo=No(String.prototype,"isWellFormed")?Bo.bind(String.prototype.isWellFormed):null,Uo=Bo.bind(String.prototype.indexOf),Go=Bo.bind(String.prototype.charCodeAt),To=Bo.bind(String.prototype.slice),Ro=Bo.bind(RegExp.prototype.exec),qo=String,Wo=Bo.bind(_o(Oo(Uint8Array.prototype),Symbol.toStringTag).get),Vo={},Ko=()=>{},Zo=Bo.bind(Map.prototype.has),Ho=Bo.bind(Set.prototype.has),Jo=Bo.bind(WeakMap.prototype.has),Qo=Bo.bind(_o(ArrayBuffer.prototype,"byteLength").get),Xo=Bo.bind(_o(DataView.prototype,"byteLength").get),Yo=Bo.bind(Symbol.prototype.valueOf),ti=Bo.bind(Promise.prototype.then),ei=[t=>Zo(t,0),t=>Ho(t,0),t=>Jo(t,Vo),t=>zo(t,Vo),t=>Qo(t),t=>Xo(t),t=>Yo(t),t=>ti(t,Ko,Ko)];if("function"==typeof SharedArrayBuffer){let t=Bo.bind(_o(SharedArrayBuffer.prototype,"byteLength").get);ei[ei.length]=e=>t(e)}if("function"==typeof WeakRef){let t=Bo.bind(WeakRef.prototype.deref);ei[ei.length]=e=>t(e)}if("function"==typeof BigInt){let t=Bo.bind(BigInt.prototype.valueOf);ei[ei.length]=e=>t(e)}let ni={plain:"condition must be a plain object",sym:"symbol key is not allowed",nonEnumProp:"non-enumerable property is not allowed",nonEnumEl:"non-enumerable element is not allowed",accProp:"accessor property is not allowed",accEl:"accessor element is not allowed",undef:"undefined is not allowed",nul:"null is not allowed here",type:"unsupported value type",num:"number is not finite",date:"invalid Date",nul0:"string contains NUL",lone:"string contains lone surrogate",arrVal:"array value is not supported, use $in",emptyOp:"empty operator object",emptyDoc:"empty condition",ninEmpty:"$nin with empty array is always true",notArr:"value must be an array",badLen:"invalid array length",extra:"array carries extra properties",deep:"nesting is too deep",big:"condition is too large",exc:"an exception was thrown while reading the condition"},ri=/^[\p{L}_][\p{L}\p{M}\p{N}_]*$/u,oi=/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:^|[^\uD800-\uDBFF])[\uDC00-\uDFFF]/,ii=/[\p{Cc}\p{Cf}\p{Zl}\p{Zp}\p{Co}\p{Cs}[\]]/u,ui=/^\[object (Date|RegExp|Map|Set|WeakMap|WeakSet|Promise|Error|String|Number|Boolean|BigInt|Symbol|ArrayBuffer|SharedArrayBuffer|DataView|Arguments|(?:Int8|Uint8|Uint8Clamped|Int16|Uint16|Int32|Uint32|Float32|Float64|BigInt64|BigUint64)Array)\]$/,ai=new WeakSet,ci=t=>{let e={reason:t};throw Lo(ai,e),e},li=(t,e)=>{let n=t.length>e?`${To(t,0,e)}...`:t,r="";for(let t=0;t<n.length;t++){let e=n[t],o=Go(n,t);if(o>=55296&&o<=56319&&t+1<n.length){let r=Go(n,t+1);r>=56320&&r<=57343&&(e+=n[t+1],t++)}r+=null===Ro(ii,e)?e:"?"}return r},fi=t=>{if(null===t)return"null";let e=typeof t;if("object"!==e)return e;if(Ao(t))return"array";let n=Ro(ui,Fo(t));return n?n[1]:"object"},si=t=>null===t?"find":si(t.up)+("number"==typeof t.k?`[${t.k}]`:`.${li(t.k,30)}`),pi=t=>{let e=si(t);return e.length>120?`...${To(e,-100)}`:e},di=t=>{t.nodes+=1,t.nodes>t.maxNodes&&ci(ni.big)},yi=(t,e,n)=>{xo(t,e,{__proto__:null,value:n,enumerable:!0,writable:!0,configurable:!0})},hi=t=>{try{return Co(t)}catch(t){return}},bi=t=>{if(null===t||"object"!=typeof t||Ao(t))return!1;let e=Oo(t);return(e===Io||null===e)&&("[object Object]"===Fo(t)&&void 0===Wo(t))},vi=(t,e)=>{"string"!=typeof e&&ci(ni.sym);let n=_o(t,e);return void 0!==n&&n.enumerable||ci(ni.nonEnumProp),No(n,"value")||ci(ni.accProp),n.value},gi=t=>{let e=t.length;return("number"!=typeof e||!So(e)||e<0)&&ci(ni.badLen),e},ji=(t,e,n)=>{let r=_o(e,n);return void 0===r&&ci(`sparse array hole at index ${n}`),r.enumerable||(t.path={up:t.path,k:n},ci(ni.nonEnumEl)),No(r,"value")||(t.path={up:t.path,k:n},ci(ni.accEl)),r.value},mi=(t,e)=>{let n=wo(t),r=n.length;r>e+1&&ci(ni.extra);for(let t=0;t<r;t++){let r=n[t];if("string"!=typeof r&&ci(ni.extra),"length"===r)continue;let o=+r;So(o)&&o>=0&&o<e&&qo(o)===r||ci(ni.extra)}},wi=t=>(Po(t)&&ci(ni.date),new Do(t)),_i=(t,e,n)=>{if(di(t),null===e)return n||ci(ni.nul),null;switch(typeof e){case"string":return-1!==Uo(r=e,"\0")&&ci(ni.nul0),(null!==Mo?Mo(r):null===Ro(oi,r))||ci(ni.lone),e;case"number":return $o(e)||ci(ni.num),e;case"boolean":return e;case"undefined":return ci(ni.undef);case"object":{let t=hi(e);return void 0!==t?wi(t):ci(`${ni.type} [${fi(e)}]`)}default:return ci(`${ni.type} [${fi(e)}]`)}var r},Oi=(t,e)=>{36===Go(e,0)&&ci(`unsupported operator [${li(e,30)}]`),e.length>t.maxKey&&ci(`column name is too long (> ${t.maxKey})`),null!==Ro(ri,e)&&"__proto__"!==e||ci(`unsupported column name [${li(e,30)}]`)},xi=(t,e,n)=>{Ao(n)||ci(ni.notArr);let r=gi(n);r>t.maxIn&&ci(`array is too large (> ${t.maxIn})`),0===r&&"$nin"===e&&ci(ni.ninEmpty);let o=[];for(let e=0;e<r;e++){let r=ji(t,n,e);t.path={up:t.path,k:e},yi(o,e,_i(t,r,!1)),t.path=t.path.up}return mi(n,r),o},ki=(t,e)=>{if(null===e)return di(t),null;if("object"==typeof e){let n=hi(e);return void 0!==n?(di(t),wi(n)):(Ao(e)&&ci(ni.arrVal),((t,e)=>{bi(e)||ci(`${ni.type} [${fi(e)}]`),di(t);let n=wo(e),r=n.length;0===r&&ci(ni.emptyOp);let o=ko(null);for(let i=0;i<r;i++){let r=n[i],u=vi(e,r);switch(t.path={up:t.path,k:r},r){case"$eq":case"$ne":yi(o,r,_i(t,u,!0));break;case"$gt":case"$gte":case"$lt":case"$lte":yi(o,r,_i(t,u,!1));break;case"$in":case"$nin":yi(o,r,xi(t,r,u));break;default:36===Go(r,0)&&ci(`unsupported operator [${li(r,30)}]`),ci(`unexpected key [${li(r,30)}] in operator object (nested conditions are not supported)`)}t.path=t.path.up}return o})(t,e))}return _i(t,e,!0)},Ai=(t,e,n,r)=>{Ao(n)||ci(ni.notArr);let o=gi(n);0===o&&ci(`${e} with empty array`),o>t.maxList&&ci(`array is too large (> ${t.maxList})`);let i=[];for(let e=0;e<o;e++){let o=ji(t,n,e);t.path={up:t.path,k:e},yi(i,e,Si(t,o,r,!1)),t.path=t.path.up}return mi(n,o),i},Si=(t,e,n,r)=>{n>t.maxDepth&&ci(ni.deep),bi(e)||ci(`${ni.plain}, got [${fi(e)}]`),di(t);let o=wo(e),i=o.length;if(0===i){if(r)return(t=>{for(let e=0;e<ei.length;e++)try{return ei[e](t),!0}catch(t){}return!1})(e)&&ci(`${ni.plain}, got [object]`),ko(null);ci(ni.emptyDoc)}let u=ko(null);for(let r=0;r<i;r++){let i=o[r],a=vi(e,i);t.path={up:t.path,k:i},"$and"===i||"$or"===i?yi(u,i,Ai(t,i,a,n+1)):(Oi(t,i),yi(u,i,ki(t,a))),t.path=t.path.up}return u},$i=t=>{let e,n={maxDepth:mo.maxDepth,maxList:mo.maxList,maxIn:mo.maxIn,maxNodes:mo.maxNodes,maxKey:mo.maxKey};if(null==t)return n;if("object"!=typeof t)throw new Error("invalid opt: opt must be an object");try{e=wo(t)}catch(t){throw new Error("invalid opt: can not read opt")}for(let t=0;t<e.length;t++){let r=e[t];if("string"!=typeof r||!No(n,r))throw new Error(`invalid opt: unknown option [${"string"==typeof r?li(r,30):"symbol"}]`)}let r=["maxDepth","maxList","maxIn","maxNodes","maxKey"];for(let e=0;e<r.length;e++){let o,i=r[e];try{o=_o(t,i)}catch(t){throw new Error(`invalid opt: can not read option [${i}]`)}if(void 0===o)continue;if(!No(o,"value"))throw new Error(`invalid opt: accessor option [${i}] is not allowed`);let u=o.value;if(void 0!==u){if("number"!=typeof u||!Eo(u)||u<1)throw new Error(`invalid opt: ${i} must be a positive integer`);n[i]=u<mo[i]?u:mo[i]}}return n};function Pi(t,e){let n=$i(e),r={nodes:0,path:null,maxDepth:n.maxDepth,maxList:n.maxList,maxIn:n.maxIn,maxNodes:n.maxNodes,maxKey:n.maxKey};try{return void 0===t?ko(null):Si(r,t,0,!0)}catch(t){let e=zo(ai,t)?t.reason:ni.exc;throw new Error(`invalid find: ${e} at [${pi(r.path)}]`)}}var Ei={};!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 i(t,e,r,i,u){if("function"!=typeof r)throw new TypeError("The listener must be a function");var a=new o(r,i||t,u),c=n?n+e:e;return t._events[c]?t._events[c].fn?t._events[c]=[t._events[c],a]:t._events[c].push(a):(t._events[c]=a,t._eventsCount++),t}function u(t,e){0==--t._eventsCount?t._events=new r:delete t._events[e]}function a(){this._events=new r,this._eventsCount=0}Object.create&&(r.prototype=Object.create(null),(new r).__proto__||(n=!1)),a.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},a.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,i=r.length,u=new Array(i);o<i;o++)u[o]=r[o].fn;return u},a.prototype.listenerCount=function(t){var e=n?n+t:t,r=this._events[e];return r?r.fn?1:r.length:0},a.prototype.emit=function(t,e,r,o,i,u){var a=n?n+t:t;if(!this._events[a])return!1;var c,l,f=this._events[a],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,i),!0;case 6:return f.fn.call(f.context,e,r,o,i,u),!0}for(l=1,c=new Array(s-1);l<s;l++)c[l-1]=arguments[l];f.fn.apply(f.context,c)}else{var p,d=f.length;for(l=0;l<d;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(!c)for(p=1,c=new Array(s-1);p<s;p++)c[p-1]=arguments[p];f[l].fn.apply(f[l].context,c)}}return!0},a.prototype.on=function(t,e,n){return i(this,t,e,n,!1)},a.prototype.once=function(t,e,n){return i(this,t,e,n,!0)},a.prototype.removeListener=function(t,e,r,o){var i=n?n+t:t;if(!this._events[i])return this;if(!e)return u(this,i),this;var a=this._events[i];if(a.fn)a.fn!==e||o&&!a.once||r&&a.context!==r||u(this,i);else{for(var c=0,l=[],f=a.length;c<f;c++)(a[c].fn!==e||o&&!a[c].once||r&&a[c].context!==r)&&l.push(a[c]);l.length?this._events[i]=1===l.length?l[0]:l:u(this,i)}return this},a.prototype.removeAllListeners=function(t){var e;return t?(e=n?n+t:t,this._events[e]&&u(this,e)):(this._events=new r,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=n,a.EventEmitter=a,t.exports=a}({get exports(){return Ei},set exports(t){Ei=t}});var Ii=Ei;function Di(){let t,e,n=new Promise((function(){t=arguments[0],e=arguments[1]}));return n.resolve=t,n.reject=e,n}const Bi=[];for(let t=0;t<256;++t)Bi.push((t+256).toString(16).slice(1));const Ni=new Uint8Array(16);function Fi(){return crypto.getRandomValues(Ni)}const Ci={};function Li(t,e,n){let r;if(t)r=zi(t.random??t.rng?.()??Fi(),t.msecs,t.seq,e,n);else{const t=Date.now(),o=Fi();!function(t,e,n){t.msecs??=-1/0,t.seq??=0,e>t.msecs?(t.seq=Mi(n),t.msecs=e):(t.seq=t.seq+1|0,0===t.seq&&t.msecs++)}(Ci,t,o),r=zi(o,Ci.msecs,Ci.seq,e,n)}return e??function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return(Bi[t[e+0]]+Bi[t[e+1]]+Bi[t[e+2]]+Bi[t[e+3]]+"-"+Bi[t[e+4]]+Bi[t[e+5]]+"-"+Bi[t[e+6]]+Bi[t[e+7]]+"-"+Bi[t[e+8]]+Bi[t[e+9]]+"-"+Bi[t[e+10]]+Bi[t[e+11]]+Bi[t[e+12]]+Bi[t[e+13]]+Bi[t[e+14]]+Bi[t[e+15]]).toLowerCase()}(r)}function zi(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??=Mi(t),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}function Mi(t){return(127&t[6])<<24|t[7]<<16|t[8]<<8|t[9]}var Ui="[object Boolean]";function Gi(t){return!0===(e=t)||!1===e||Y(e)&&g(e)==Ui;var e}function Ti(t){return"[object String]"===Object.prototype.toString.call(t)}function Ri(t){return!!(Ti(t)&&t.length>0)}function qi(t){return"[object Array]"===Object.prototype.toString.call(t)}function Wi(t){return"[object Object]"===Object.prototype.toString.call(t)}function Vi(t){if(t!=t)return!0;if(null!==t&&"object"==typeof t)try{let e=Number.prototype.valueOf.call(t);return Number.isNaN(e)}catch(t){return!1}return!1}function Ki(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(Wi(t)){for(let e in t)return!1;return!0}return!1}(t)||(!!function(t){return!(!Ti(t)||0!==t.length)}(t)||(!!function(t){return!!qi(t)&&0===t.length}(t)||!!Vi(t)))))}function Zi(t){return!!qi(t)&&(0!==t.length&&(1!==t.length||!Ki(t[0])))}function Hi(t){if(Wi(t)){for(let e in t)return!0;return!1}return!1}function Ji(t){let e=!1;if(Ri(t)){if(""===t.trim())return!1;e=!isNaN(Number(t))}else if(function(t){return"[object Number]"===Object.prototype.toString.call(t)}(t)){if(Vi(t))return!1;e=!0}return e}var Qi=/\s/;var Xi=/^\s+/;function Yi(t){return t?t.slice(0,function(t){for(var e=t.length;e--&&Qi.test(t.charAt(e)););return e}(t)+1).replace(Xi,""):t}var tu=NaN,eu=/^[-+]0x[0-9a-f]+$/i,nu=/^0b[01]+$/i,ru=/^0o[0-7]+$/i,ou=parseInt;var iu=1/0,uu=17976931348623157e292;function au(t){return t?(t=function(t){if("number"==typeof t)return t;if(Xn(t))return tu;if(j(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=j(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=Yi(t);var n=nu.test(t);return n||ru.test(t)?ou(t.slice(2),n?2:8):eu.test(t)?tu:+t}(t))===iu||t===-iu?(t<0?-1:1)*uu:t==t?t:0:0===t?t:0}function cu(t,e,n){var r=null==t?0:t.length;return r?(e=n||void 0===e?1:function(t){var e=au(t),n=e%1;return e==e?n?e-n:e:0}(e),Dr(t,e<0?0:e,r)):[]}function lu(t){return x(t)}function fu(t){try{t instanceof Promise&&Promise.prototype.then.call(t,void 0,(()=>{}))}catch(t){}}function su(t,e){let n=Di(),r=!1;try{let e=function(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],n=[],r=!1;try{if(Array.isArray(t)){let e=t.length;n.length=e;for(let r=0;r<e;r++)r in t&&(n[r]=t[r])}else{if(e||!Wi(t)&&!qi(t))return null;{r=!0;let e=Object.keys(t);for(let r=0;r<e.length;r++)n.push({k:e[r],v:t[e[r]]})}}}catch(t){throw n.forEach((t=>{fu(r?t.v:t)})),t}return{items:n,useObj:r}}(t);if(null===e)return n.reject("rs is not an array or object"),n;t=e.items,r=e.useObj}catch(t){return n.reject(t),n}lu(e)||(pn(t,(t=>{fu(r?t.v:t)})),e=function(t){return t});let o=lu(e),i=-1,u=[];return t.reduce((function(t,n){return t.then((function(t){u.push(t),i+=1;let a=i,c=n;return r&&(a=n.k,c=n.v),o?e(c,a):c}))}),Promise.resolve()).then((function(t){u.push(t),u=cu(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=mr(n,"autoGenPk");Gi(r)||(r=!0);let o=!1,i=!1,u=null,a=new Ii,c=t.MongoClient;function l(t){let e=mr(t,"message");return Ri(e)?e:String(t)}function f(t,e,n){try{a.emit("change",t,e,n)}catch(t){console.log(t)}}function s(t,e,n){try{a.emit("error",t,e,l(n))}catch(t){console.log(t)}}function p(t,e){if(!Ri(t.id)){if(!r)throw new Error(`invalid data[${e}].id, autoGenPk is false`);t.id=Li()}return t}function d(t){let e=mr(t,"writeErrors");return Zi(e)?$r(e,(function(t){return 11e3===mr(t,"code")||11e3===mr(t,"err.code")})):11e3===mr(t,"code")}async function y(t){o||(await t.createIndex({id:1},{unique:!0}),o=!0)}async function h(t,e){let n=null;try{await t.insertMany(e,{ordered:!1})}catch(t){n=t}if(null===n)return;let r=Ir(e,(function(t){return t._id}));throw r=function(t,e){return(ut(t)?Gt:Pr)(t,Sr(e))}(r,(function(t){return null!=t})),jo(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{t=Pi(t);let n=e.find(t);r=await n.toArray()}catch(t){n=!0,r=t}return n?Promise.reject(r):r}return a.select=async function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=!1,r=null,o=null;try{t=Pi(t),r=new c(n.url);let e=r.db(n.db).collection(n.cl).find(t);o=await e.toArray(),o=Ir(o,(function(t){return t=Yr(t,"_id")}))}catch(t){e=!0,o=t}finally{null!==r&&(await r.close(),r=null)}return e?(s("select",null,o),Promise.reject(o)):o},a.selectByPk=async function(t){let e=!1;if(!Ri(t))return null;let r=new c(n.url),o=null;try{let e=r.db(n.db).collection(n.cl),i=await e.findOne({id:t},{projection:{_id:0}});o=Hi(i)?i:null}catch(t){e=!0,o=t}finally{await r.close(),r=null}return e?(s("selectByPk",null,o),Promise.reject(o)):o},a.insert=async function(t){let e=!1,r=mr(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},"returnList");if(Gi(r)||(r=!1),!Hi(t)&&!Zi(t))return r?[]:{n:0,nInserted:0,ok:1};t=un(t);let o=new c(n.url),i=null;try{await o.connect();let e=o.db(n.db).collection(n.cl);qi(t)||(t=[t]),t=Ir(t,p),await y(e);let u=jo(t),a=0,c={};try{a=(await e.insertMany(t,{ordered:!1})).insertedCount}catch(t){if(!d(t))throw t;a=mr(t,"result.insertedCount",0),pn(mr(t,"writeErrors",[]),(function(t){let e=mr(t,"index",mr(t,"err.index"));Ji(e)&&(c[e]=!0)}))}i=r?Ir(t,(function(t,e){return{n:1,nInserted:!0===c[e]?0:1,ok:1}})):{n:u,nInserted:a,ok:1}}catch(t){e=!0,i=t}finally{await o.close(),o=null}return e||f("insert",t,i),e?(s("insert",t,i),Promise.reject(i)):i},a.insertBulk=async function(t){let e=!1;if(!Hi(t)&&!Zi(t))return{n:0,nInserted:0,ok:1};t=un(t);let r=new c(n.url),o=null;try{await r.connect();let e=r.db(n.db).collection(n.cl);qi(t)||(t=[t]),t=Ir(t,p),await y(e);let i=jo(t),a=await async function(t){if(Gi(u))return u;let e=await t.db(n.db).admin().command({hello:1});return u=Ri(mr(e,"setName"))||"isdbgrid"===mr(e,"msg"),u}(r);a?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 h(e,t),o={n:i,nInserted:i,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},a.save=async function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=!1;if(!Hi(t)&&!Zi(t))return[];t=un(t);let o=mr(e,"autoInsert",!0),i=new c(n.url),u=null;try{await i.connect();let e=i.db(n.db).collection(n.cl);qi(t)||(t=[t]),t=Ir(t,p),await y(e),u=await su(t,(async t=>async function(t,e,n){let r=null,o=!1;for(let i=0;i<3;i++)try{let i=await t.updateOne({id:e.id},{$set:e},{upsert:n}),u=mr(i,"matchedCount",0),a=mr(i,"modifiedCount",0);mr(i,"upsertedCount",0)>0?(r={n:1,nInserted:1,nModified:0,ok:1},o=!0):r=u>0?{n:1,nInserted:0,nModified:a>0?1:0,ok:1}:{n:0,nInserted:0,nModified:0,ok:1};break}catch(t){if(d(t)&&i<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,u=t}finally{await i.close(),i=null}return r||f("save",t,u),r?(s("save",t,u),Promise.reject(u)):u},a.del=async function(t){let e=!1;if(!Hi(t)&&!Zi(t))return[];t=un(t);let r=new c(n.url),o=null;try{await r.connect();let e=r.db(n.db).collection(n.cl);qi(t)||(t=[t]),o=await su(t,(async t=>{let n=mr(t,"id"),r=null;if(Ri(n))try{let t=mr(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},a.delAll=async function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=!1,r=null,o=null;try{t=Pi(t),r=new c(n.url);let e=r.db(n.db).collection(n.cl),i=mr(await e.deleteMany(t),"deletedCount",0);o={n:i,nDeleted:i,ok:1}}catch(t){e=!0,o=t}finally{null!==r&&(await r.close(),r=null)}return e||f("delAll",null,o),e?(s("delAll",null,o),Promise.reject(o)):o},a.selectByPkGfs=async function(e){let r=!1;if(!Ri(e))return null;let o=new c(n.url),i=null;try{i={id:e,u8a:await(async e=>{let r=Di(),i=o.db(n.db),u=new t.GridFSBucket(i,{chunkSizeBytes:10485760,bucketName:n.cl}),a=Buffer.from(""),c=u.openDownloadStreamByName(e);return c.on("data",(function(t){a=Buffer.concat([a,t])})),c.on("error",(function(t){r.reject(t)})),c.on("end",(function(){let t=new Uint8Array(a);a=null,r.resolve(t)})),r})(e)}}catch(t){"ENOENT"===mr(t,"code")?i=null:(r=!0,i=t)}finally{await o.close(),o=null}return r?(s("selectByPkGfs",null,i),Promise.reject(i)):i},a.insertGfs=async function(r){let o=!1;if(!Hi(r)&&!Zi(r))return{n:0,nInserted:0,ok:1};let u=new c(n.url),a=null;try{await u.connect();let o=u.db(n.db),c=new t.GridFSBucket(o,{chunkSizeBytes:10485760,bucketName:n.cl}),l=o.collection(`${n.cl}.chunks`);qi(r)||(r=[r]),r=Ir(r,(function(t,e){if(!function(t){return"[object Uint8Array]"===Object.prototype.toString.call(t)}((t=p(t={...t},e)).u8a))throw new Error(`invalid data[${e}].u8a`);return t})),await async function(t){i||(await t.collection(`${n.cl}.files`).createIndex({filename:1},{unique:!0}),i=!0)}(o);let f=jo(r),s=0;await su(r,(async t=>{let n=await function(t,n,r,o){let i=Di(),u=t.openUploadStream(r),a=u.id,c=new e.Readable;return c._read=()=>{},c.push(Buffer.from(o)),c.push(null),c.pipe(u).on("error",(function(t){d(t)?n.deleteMany({files_id:a}).then((function(){i.resolve(!1)})).catch((function(t){i.reject(t)})):i.reject(t)})).on("finish",(function(){i.resolve(!0)})),i}(c,l,t.id,t.u8a);n&&s++})),a={n:f,nInserted:s,ok:1}}catch(t){o=!0,a=t}finally{await u.close(),u=null}return o||f("insertGfs",r,a),o?(s("insertGfs",r,a),Promise.reject(a)):a},a.delGfs=async function(e){let r=!1;if(!Hi(e)&&!Zi(e))return[];let o=new c(n.url),i=null;try{await o.connect();let r=o.db(n.db),u=new t.GridFSBucket(r,{chunkSizeBytes:10485760,bucketName:n.cl});qi(e)||(e=[e]),i=await su(e,(async t=>{let e=mr(t,"id"),n=null;if(Ri(e))try{let t=await b({filename:e},u),r=0;for(let e of t)await u.delete(e._id),r++;n={n:r>0?1:0,nDeleted:r,ok:1}}catch(t){let e=l(t);n={n:0===e.indexOf("invalid find: ")?0:1,nDeleted:0,ok:0,err:e}}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,i=t}finally{await o.close(),o=null}return r||f("delGfs",e,i),r?(s("delGfs",e,i),Promise.reject(i)):i},a.delAllGfs=async function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=!1,o=null,i=null;try{e=Pi(e),o=new c(n.url);let r=o.db(n.db),u=new t.GridFSBucket(r,{chunkSizeBytes:10485760,bucketName:n.cl}),a=await b(e,u),l=Ir(a,(function(t){return async function(t,e){await e.delete(t)}(t._id,u)}));await Promise.all(l);let f=jo(a);i={n:f,nDeleted:f,ok:1}}catch(t){r=!0,i=t}finally{null!==o&&(await o.close(),o=null)}return r||f("delAllGfs",null,i),r?(s("delAllGfs",null,i),Promise.reject(i)):i},a}}));
7
7
  //# sourceMappingURL=w-orm-mongodb.umd.js.map