w-orm-lowdb 1.0.30 → 1.0.32

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
@@ -33,6 +33,34 @@ An operator for lowdb in nodejs.
33
33
 
34
34
  `opt.useCache` 開啟時,`select` 與 `selectByPk` 之快取為行程內狀態:本行程之寫入會重設快取,他行程之寫入則不會,故縱使僅由他行程寫入亦可能讀到過期數據。該選項預設關閉,僅適用於單程序操作。
35
35
 
36
+ ### 條件(find)白名單 (Condition whitelist)
37
+
38
+ `select` 與 `delAll` 共用同一個 `find` 條件與同一道檢核,於呼叫入口執行(任何讀取之前,不占用序列化佇列)。檢核為 `wsemi` 之 `cvOrmFind`(w-orm 系列共用),其後查詢與刪除只使用檢核所回傳之複本,不再讀取呼叫端傳入之物件。條件不在白名單內者整批 reject,訊息為 `invalid find: <原因> at [<路徑>]`,於 reject 之前發出一次 `error` 事件,不讀取資料庫檔案、不刪除任何數據,亦不發出 `change` 事件。
39
+
40
+ 接受:
41
+
42
+ - 未給、`undefined`、`{}`:全部數據。`delAll()` 不給條件即刪除全部,須審慎使用、非必要不用;可先以 `select(find)` 確認 `delAll(find)` 之命中範圍(`useCache` 開啟且他行程已寫入時,`select` 可能回傳快取而與 `delAll` 直讀資料庫所見不同)。
43
+ - 欄位等值 `{ 欄: 純量 }`,多欄為 AND。純量為字串(不含 NUL 字元與孤立代理字元)、有限數字、布林、有效 `Date`;`null` 僅可用於欄位等值、`$eq`、`$ne`。
44
+ - 欄位運算子 `$eq $ne $gt $gte $lt $lte`(值為純量)與 `$in $nin`(值為純量陣列;`$in: []` 恆假、不命中任何數據,`$nin: []` reject)。同欄多個運算子為 AND。
45
+ - 文件層 `$and`、`$or`:值為條件物件之非空陣列,可巢狀。
46
+ - 欄名須符合 `^[\p{L}_][\p{L}\p{M}\p{N}_]*$`,長度不超過 128,且不為 `__proto__`;`'o.k'` 之點路徑不是欄名。
47
+ - 上限:巢狀深度 32、`$and`/`$or` 項數 1000、`$in`/`$nin` 項數 10000、節點總數 100000。
48
+
49
+ 整批 reject:非條件物件之值(`null`、陣列、字串、數值、布林、函數、`Date`、`RegExp`、`Map`、`Set`、類別實例等);白名單外之運算子(`$not $nor $regex $options $exists $where $expr $type $mod $elemMatch $size $all` 等);欄位層 `$and/$or`;`undefined`、`NaN`、`Infinity`、無效 `Date`、`BigInt`、函數、`Symbol`、`RegExp` 之值;陣列值或巢狀物件之等值;`$nin: []`、`$and: []`、`$or: []`、`$and`/`$or` 內之 `{}`、`{ 欄: {} }`;`$gt $gte $lt $lte $in $nin` 內之 `null`;Symbol 鍵、存取器、不可列舉鍵、稀疏陣列。
50
+
51
+ Date:本套件以 JSON 存檔,Date 存入後為 ISO 字串(`toISOString()`);條件內之 Date 於入口檢核之後、查詢之前轉為同一格式之 ISO 字串(只轉換檢核所回傳之複本,不改動呼叫端之物件),故 `{ d: new Date(...) }`、`$gte`、`$in` 等皆可命中。注意 Date 條件等同於其 ISO 字串條件,以字串字典序比較:① 與字串型欄位亦會比較(`{ d: { $lt: new Date(...) } }` 可能命中 `d` 為字典序較小之字串的數據),欄位混放 Date 與字串時請勿用 Date 條件刪除;② 範圍比較僅在所有 Date 皆介於西元 0000–9999 年時正確(`toISOString()` 於此範圍外輸出 `+yyyyyy-`、`-yyyyyy-` 前綴,字典序顛倒,例如以 `new Date(8.64e15)` 作「永不過期」哨兵時,`{ expireAt: { $lt: 現在 } }` 會命中哨兵)。
52
+
53
+ 語意為 MongoDB 式:`{ f: null }` 命中 `f` 為 `null` 或缺欄之數據,`$ne: x`(x 非 `null`)與 `$nin` 亦命中欄位為 `null` 或缺欄之數據,`$ne: null` 則排除之。欄名同於 `Object.prototype` 成員者(`constructor`、`toString`、`hasOwnProperty` 等),數據無此自有欄位時視為缺欄。欄位值為陣列時,純量與 `$in` 條件仍以元素比對(`{ tags: 'x' }` 命中 `tags: ['x', 'y']`)。欲在 `w-orm-*` 各後端得到相同結果,請明確寫出:排除 null/缺欄用 `{ $and: [{ f: { $ne: null } }, { f: { $ne: x } }] }`,含 null/缺欄用 `{ $or: [{ f: null }, { f: { $ne: x } }] }`。
54
+
55
+ ### 破壞性變更 (Breaking changes)
56
+
57
+ 原本被接受或被靜默放行之條件,現改為 reject,不設過渡期。
58
+
59
+ - 移除:白名單以外之全部 `mingo` 運算子(`$not $nor $regex $options $exists $type $mod $elemMatch $size $all $expr $where $bitsAllSet` 等);`RegExp` 值(`{ name: /x/i }`、`$in: [/x/]`);陣列字面值之等值、巢狀物件等值(`{ tags: ['x', 'y'] }`、`{ o: { k: 1 } }`)與 `$elemMatch`、`$all`、`$size`(欄位值為陣列時,純量與 `$in` 條件之元素比對語意仍保留);點路徑(`{ 'o.k': 1 }`)。需要時請 `select()` 後於記憶體過濾。
60
+ - 改為 reject(原本靜默放行):不是條件物件之 `find`(`null`、`[]`、`'x'`、`123`、`true`、函數、`Date`、`Map`、`Set`、僅含 Symbol 鍵之物件、條件在原型上之物件),原本 `select(find)` 回傳全部數據、`delAll(find)` 刪除全部數據(帶自有鍵之類別實例原本即由 `mingo` 拒收,訊息為 `query criteria must be an object`,現統一為 `invalid find`);`undefined` 值(`{ age: undefined }`、`$eq: undefined` 原本命中欄位為 null 或缺欄之數據,`$in: [undefined]` 原本無命中,稀疏陣列之洞原被當缺欄);`NaN`、`Infinity`、函數、`Symbol` 之值;`$nin: []`、`$and: []`、`$or: []`、`$and: [{}]`、`$or: [{}]`、`{ age: {} }`;不合文法之欄名、存取器與不可列舉鍵;巢狀深度超過 32、`$in` 超過 10000 項。
61
+ - 新行為:條件內之 Date 可命中(原本因數據為 ISO 字串而條件為 Date,`$eq`、`$gt`、`$gte`、`$lt`、`$lte`、`$in` 恆不命中,`$ne`、`$nin` 恆命中,`delAll` 因而可能刪除全部);Date 範圍比較之限制見上。
62
+ - 錯誤訊息為 `invalid find: <原因> at [<路徑>]`;原本由 `mingo` 拋出錯誤者,現統一為此訊息。
63
+
36
64
  ## Documentation
37
65
  To view documentation or get support, visit [docs](https://yuda-lyu.github.io/w-orm-lowdbOrm.html).
38
66
 
@@ -203,7 +231,7 @@ async function test() {
203
231
  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 } }] }] })
204
232
  console.log('select by $or, $and, $ne, $in, $nin', spc)
205
233
 
206
- // //select by regex //mingo不支援regex
234
+ // //select by regex //系列條件白名單不支援$regex(含$options), 會整批reject(invalid find: unsupported operator), 須改為select後自行過濾
207
235
  // let sr = await wo.select({ name: { $regex: 'PeT', $options: '$i' } })
208
236
  // console.log('selectReg', sr)
209
237
 
@@ -1,7 +1,7 @@
1
1
  /*!
2
- * w-orm-lowdb v1.0.30
2
+ * w-orm-lowdb v1.0.32
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("path"),require("lowdb"),require("node:fs"),require("node:fs/promises"),require("node:path"),require("node:url"),require("mingo")):"function"==typeof define&&define.amd?define(["path","lowdb","node:fs","node:fs/promises","node:path","node:url","mingo"],e):(t="undefined"!=typeof globalThis?globalThis:t||self)["w-orm-lowdb"]=e(t.path,t.lowdb,null,t.promises,t.path,t.node_url,t.mingo)}(this,(function(t,e,n,r,o,i,u){"use strict";class c{#t;#e;#n=!1;#r=null;#o=null;#i=null;#u=null;#c(t){return this.#u=t,this.#i||=new Promise(((t,e)=>{this.#o=[t,e]})),new Promise(((t,e)=>{this.#i?.then(t).catch(e)}))}async#a(t){this.#n=!0;try{await r.writeFile(this.#e,t,"utf-8"),await async function(t,e,n){for(let r=0;r<e;r++)try{return await t()}catch(t){if(!(r<e-1))throw t;await new Promise((t=>setTimeout(t,n)))}}((async()=>{await r.rename(this.#e,this.#t)}),10,100),this.#r?.[0]()}catch(t){throw t instanceof Error&&this.#r?.[1](t),t}finally{if(this.#n=!1,this.#r=this.#o,this.#o=this.#i=null,null!==this.#u){const t=this.#u;this.#u=null,await this.write(t)}}}constructor(t){this.#t=t,this.#e=function(t){const e=t instanceof URL?i.fileURLToPath(t):t.toString();return o.join(o.dirname(e),`.${o.basename(e)}.tmp`)}(t)}async write(t){return this.#n?this.#c(t):this.#a(t)}}class a{#t;#f;constructor(t){this.#t=t,this.#f=new c(t)}async read(){let t;try{t=await r.readFile(this.#t,"utf-8")}catch(t){if("ENOENT"===t.code)return null;throw t}return t}write(t){return this.#f.write(t)}}class f{#s;#l;#p;constructor(t,e){let{parse:n,stringify:r}=e;this.#s=new a(t),this.#l=n,this.#p=r}async read(){const t=await this.#s.read();return null===t?null:this.#l(t)}write(t){return this.#s.write(this.#p(t))}}class s extends f{constructor(t){super(t,{parse:JSON.parse,stringify:t=>JSON.stringify(t,null,2)})}}var l=Array.isArray,p="object"==typeof global&&global&&global.Object===Object&&global,v="object"==typeof self&&self&&self.Object===Object&&self,h=p||v||Function("return this")(),y=h.Symbol,d=Object.prototype,b=d.hasOwnProperty,j=d.toString,g=y?y.toStringTag:void 0;var _=Object.prototype.toString;var w=y?y.toStringTag:void 0;function m(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":w&&w in Object(t)?function(t){var e=b.call(t,g),n=t[g];try{t[g]=void 0;var r=!0}catch(t){}var o=j.call(t);return r&&(e?t[g]=n:delete t[g]),o}(t):function(t){return _.call(t)}(t)}function O(t){return null!=t&&"object"==typeof t}function x(t){return"symbol"==typeof t||O(t)&&"[object Symbol]"==m(t)}var A=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,k=/^\w*$/;function P(t,e){if(l(t))return!1;var n=typeof t;return!("number"!=n&&"symbol"!=n&&"boolean"!=n&&null!=t&&!x(t))||(k.test(t)||!A.test(t)||null!=e&&t in Object(e))}function S(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}function E(t){if(!S(t))return!1;var e=m(t);return"[object Function]"==e||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e}var I,z=h["__core-js_shared__"],D=(I=/[^.]+$/.exec(z&&z.keys&&z.keys.IE_PROTO||""))?"Symbol(src)_1."+I:"";var $=Function.prototype.toString;function F(t){if(null!=t){try{return $.call(t)}catch(t){}try{return t+""}catch(t){}}return""}var U=/^\[object .+?Constructor\]$/,B=Function.prototype,M=Object.prototype,N=B.toString,L=M.hasOwnProperty,T=RegExp("^"+N.call(L).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function q(t){return!(!S(t)||(e=t,D&&D in e))&&(E(t)?T:U).test(F(t));var e}function C(t,e){var n=function(t,e){return null==t?void 0:t[e]}(t,e);return q(n)?n:void 0}var R=C(Object,"create");var V=Object.prototype.hasOwnProperty;var G=Object.prototype.hasOwnProperty;function W(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 J(t,e){return t===e||t!=t&&e!=e}function Q(t,e){for(var n=t.length;n--;)if(J(t[n][0],e))return n;return-1}W.prototype.clear=function(){this.__data__=R?R(null):{},this.size=0},W.prototype.delete=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},W.prototype.get=function(t){var e=this.__data__;if(R){var n=e[t];return"__lodash_hash_undefined__"===n?void 0:n}return V.call(e,t)?e[t]:void 0},W.prototype.has=function(t){var e=this.__data__;return R?void 0!==e[t]:G.call(e,t)},W.prototype.set=function(t,e){var n=this.__data__;return this.size+=this.has(t)?0:1,n[t]=R&&void 0===e?"__lodash_hash_undefined__":e,this};var H=Array.prototype.splice;function K(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])}}K.prototype.clear=function(){this.__data__=[],this.size=0},K.prototype.delete=function(t){var e=this.__data__,n=Q(e,t);return!(n<0)&&(n==e.length-1?e.pop():H.call(e,n,1),--this.size,!0)},K.prototype.get=function(t){var e=this.__data__,n=Q(e,t);return n<0?void 0:e[n][1]},K.prototype.has=function(t){return Q(this.__data__,t)>-1},K.prototype.set=function(t,e){var n=this.__data__,r=Q(n,t);return r<0?(++this.size,n.push([t,e])):n[r][1]=e,this};var X=C(h,"Map");function Y(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 Z(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])}}Z.prototype.clear=function(){this.size=0,this.__data__={hash:new W,map:new(X||K),string:new W}},Z.prototype.delete=function(t){var e=Y(this,t).delete(t);return this.size-=e?1:0,e},Z.prototype.get=function(t){return Y(this,t).get(t)},Z.prototype.has=function(t){return Y(this,t).has(t)},Z.prototype.set=function(t,e){var n=Y(this,t),r=n.size;return n.set(t,e),this.size+=n.size==r?0:1,this};function tt(t,e){if("function"!=typeof t||null!=e&&"function"!=typeof e)throw new TypeError("Expected a function");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(tt.Cache||Z),n}tt.Cache=Z;var et,nt,rt,ot=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,it=/\\(\\)?/g,ut=(et=function(t){var e=[];return 46===t.charCodeAt(0)&&e.push(""),t.replace(ot,(function(t,n,r,o){e.push(r?o.replace(it,"$1"):n||t)})),e},nt=tt(et,(function(t){return 500===rt.size&&rt.clear(),t})),rt=nt.cache,nt),ct=ut;function at(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 ft=y?y.prototype:void 0,st=ft?ft.toString:void 0;function lt(t){if("string"==typeof t)return t;if(l(t))return at(t,lt)+"";if(x(t))return st?st.call(t):"";var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}function pt(t,e){return l(t)?t:P(t,e)?[t]:ct(function(t){return null==t?"":lt(t)}(t))}function vt(t){if("string"==typeof t||x(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}function ht(t,e){for(var n=0,r=(e=pt(e,t)).length;null!=t&&n<r;)t=t[vt(e[n++])];return n&&n==r?t:void 0}function yt(t,e,n){var r=null==t?void 0:ht(t,e);return void 0===r?n:r}function dt(t,e){for(var n=-1,r=null==t?0:t.length;++n<r&&!1!==e(t[n],n,t););return t}var bt,jt=function(t,e,n){for(var r=-1,o=Object(t),i=n(t),u=i.length;u--;){var c=i[bt?u:++r];if(!1===e(o[c],c,o))break}return t};function gt(t){return O(t)&&"[object Arguments]"==m(t)}var _t=Object.prototype,wt=_t.hasOwnProperty,mt=_t.propertyIsEnumerable,Ot=gt(function(){return arguments}())?gt:function(t){return O(t)&&wt.call(t,"callee")&&!mt.call(t,"callee")},xt=Ot;var At="object"==typeof exports&&exports&&!exports.nodeType&&exports,kt=At&&"object"==typeof module&&module&&!module.nodeType&&module,Pt=kt&&kt.exports===At?h.Buffer:void 0,St=(Pt?Pt.isBuffer:void 0)||function(){return!1},Et=/^(?:0|[1-9]\d*)$/;function It(t,e){var n=typeof t;return!!(e=null==e?9007199254740991:e)&&("number"==n||"symbol"!=n&&Et.test(t))&&t>-1&&t%1==0&&t<e}function zt(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991}var Dt={};function $t(t){return function(e){return t(e)}}Dt["[object Float32Array]"]=Dt["[object Float64Array]"]=Dt["[object Int8Array]"]=Dt["[object Int16Array]"]=Dt["[object Int32Array]"]=Dt["[object Uint8Array]"]=Dt["[object Uint8ClampedArray]"]=Dt["[object Uint16Array]"]=Dt["[object Uint32Array]"]=!0,Dt["[object Arguments]"]=Dt["[object Array]"]=Dt["[object ArrayBuffer]"]=Dt["[object Boolean]"]=Dt["[object DataView]"]=Dt["[object Date]"]=Dt["[object Error]"]=Dt["[object Function]"]=Dt["[object Map]"]=Dt["[object Number]"]=Dt["[object Object]"]=Dt["[object RegExp]"]=Dt["[object Set]"]=Dt["[object String]"]=Dt["[object WeakMap]"]=!1;var Ft="object"==typeof exports&&exports&&!exports.nodeType&&exports,Ut=Ft&&"object"==typeof module&&module&&!module.nodeType&&module,Bt=Ut&&Ut.exports===Ft&&p.process,Mt=function(){try{var t=Ut&&Ut.require&&Ut.require("util").types;return t||Bt&&Bt.binding&&Bt.binding("util")}catch(t){}}(),Nt=Mt&&Mt.isTypedArray,Lt=Nt?$t(Nt):function(t){return O(t)&&zt(t.length)&&!!Dt[m(t)]},Tt=Object.prototype.hasOwnProperty;function qt(t,e){var n=l(t),r=!n&&xt(t),o=!n&&!r&&St(t),i=!n&&!r&&!o&&Lt(t),u=n||r||o||i,c=u?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 f in t)!e&&!Tt.call(t,f)||u&&("length"==f||o&&("offset"==f||"parent"==f)||i&&("buffer"==f||"byteLength"==f||"byteOffset"==f)||It(f,a))||c.push(f);return c}var Ct=Object.prototype;function Rt(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||Ct)}function Vt(t,e){return function(n){return t(e(n))}}var Gt=Vt(Object.keys,Object),Wt=Object.prototype.hasOwnProperty;function Jt(t){if(!Rt(t))return Gt(t);var e=[];for(var n in Object(t))Wt.call(t,n)&&"constructor"!=n&&e.push(n);return e}function Qt(t){return null!=t&&zt(t.length)&&!E(t)}function Ht(t){return Qt(t)?qt(t):Jt(t)}var Kt=function(t,e){return function(n,r){if(null==n)return n;if(!Qt(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&&jt(t,e,Ht)})),Xt=Kt;function Yt(t){return t}function Zt(t,e){var n;return(l(t)?dt:Xt)(t,"function"==typeof(n=e)?n:Yt)}function te(t){var e=this.__data__=new K(t);this.size=e.size}te.prototype.clear=function(){this.__data__=new K,this.size=0},te.prototype.delete=function(t){var e=this.__data__,n=e.delete(t);return this.size=e.size,n},te.prototype.get=function(t){return this.__data__.get(t)},te.prototype.has=function(t){return this.__data__.has(t)},te.prototype.set=function(t,e){var n=this.__data__;if(n instanceof K){var r=n.__data__;if(!X||r.length<199)return r.push([t,e]),this.size=++n.size,this;n=this.__data__=new Z(r)}return n.set(t,e),this.size=n.size,this};function ee(t){var e=-1,n=null==t?0:t.length;for(this.__data__=new Z;++e<n;)this.add(t[e])}function ne(t,e){for(var n=-1,r=null==t?0:t.length;++n<r;)if(e(t[n],n,t))return!0;return!1}function re(t,e){return t.has(e)}ee.prototype.add=ee.prototype.push=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this},ee.prototype.has=function(t){return this.__data__.has(t)};function oe(t,e,n,r,o,i){var u=1&n,c=t.length,a=e.length;if(c!=a&&!(u&&a>c))return!1;var f=i.get(t),s=i.get(e);if(f&&s)return f==e&&s==t;var l=-1,p=!0,v=2&n?new ee:void 0;for(i.set(t,e),i.set(e,t);++l<c;){var h=t[l],y=e[l];if(r)var d=u?r(y,h,l,e,t,i):r(h,y,l,t,e,i);if(void 0!==d){if(d)continue;p=!1;break}if(v){if(!ne(e,(function(t,e){if(!re(v,e)&&(h===t||o(h,t,n,r,i)))return v.push(e)}))){p=!1;break}}else if(h!==y&&!o(h,y,n,r,i)){p=!1;break}}return i.delete(t),i.delete(e),p}var ie=h.Uint8Array;function ue(t){var e=-1,n=Array(t.size);return t.forEach((function(t,r){n[++e]=[r,t]})),n}function ce(t){var e=-1,n=Array(t.size);return t.forEach((function(t){n[++e]=t})),n}var ae=y?y.prototype:void 0,fe=ae?ae.valueOf:void 0;function se(t,e){for(var n=-1,r=e.length,o=t.length;++n<r;)t[o+n]=e[n];return t}function le(t,e,n){var r=e(t);return l(t)?r:se(r,n(t))}function pe(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 ve(){return[]}var he=Object.prototype.propertyIsEnumerable,ye=Object.getOwnPropertySymbols,de=ye?function(t){return null==t?[]:(t=Object(t),pe(ye(t),(function(e){return he.call(t,e)})))}:ve;function be(t){return le(t,Ht,de)}var je=Object.prototype.hasOwnProperty;var ge=C(h,"DataView"),_e=C(h,"Promise"),we=C(h,"Set"),me=C(h,"WeakMap"),Oe="[object Map]",xe="[object Promise]",Ae="[object Set]",ke="[object WeakMap]",Pe="[object DataView]",Se=F(ge),Ee=F(X),Ie=F(_e),ze=F(we),De=F(me),$e=m;(ge&&$e(new ge(new ArrayBuffer(1)))!=Pe||X&&$e(new X)!=Oe||_e&&$e(_e.resolve())!=xe||we&&$e(new we)!=Ae||me&&$e(new me)!=ke)&&($e=function(t){var e=m(t),n="[object Object]"==e?t.constructor:void 0,r=n?F(n):"";if(r)switch(r){case Se:return Pe;case Ee:return Oe;case Ie:return xe;case ze:return Ae;case De:return ke}return e});var Fe=$e,Ue="[object Arguments]",Be="[object Array]",Me="[object Object]",Ne=Object.prototype.hasOwnProperty;function Le(t,e,n,r,o,i){var u=l(t),c=l(e),a=u?Be:Fe(t),f=c?Be:Fe(e),s=(a=a==Ue?Me:a)==Me,p=(f=f==Ue?Me:f)==Me,v=a==f;if(v&&St(t)){if(!St(e))return!1;u=!0,s=!1}if(v&&!s)return i||(i=new te),u||Lt(t)?oe(t,e,n,r,o,i):function(t,e,n,r,o,i,u){switch(n){case"[object DataView]":if(t.byteLength!=e.byteLength||t.byteOffset!=e.byteOffset)return!1;t=t.buffer,e=e.buffer;case"[object ArrayBuffer]":return!(t.byteLength!=e.byteLength||!i(new ie(t),new ie(e)));case"[object Boolean]":case"[object Date]":case"[object Number]":return J(+t,+e);case"[object Error]":return t.name==e.name&&t.message==e.message;case"[object RegExp]":case"[object String]":return t==e+"";case"[object Map]":var c=ue;case"[object Set]":var a=1&r;if(c||(c=ce),t.size!=e.size&&!a)return!1;var f=u.get(t);if(f)return f==e;r|=2,u.set(t,e);var s=oe(c(t),c(e),r,o,i,u);return u.delete(t),s;case"[object Symbol]":if(fe)return fe.call(t)==fe.call(e)}return!1}(t,e,a,n,r,o,i);if(!(1&n)){var h=s&&Ne.call(t,"__wrapped__"),y=p&&Ne.call(e,"__wrapped__");if(h||y){var d=h?t.value():t,b=y?e.value():e;return i||(i=new te),o(d,b,n,r,i)}}return!!v&&(i||(i=new te),function(t,e,n,r,o,i){var u=1&n,c=be(t),a=c.length;if(a!=be(e).length&&!u)return!1;for(var f=a;f--;){var s=c[f];if(!(u?s in e:je.call(e,s)))return!1}var l=i.get(t),p=i.get(e);if(l&&p)return l==e&&p==t;var v=!0;i.set(t,e),i.set(e,t);for(var h=u;++f<a;){var y=t[s=c[f]],d=e[s];if(r)var b=u?r(d,y,s,e,t,i):r(y,d,s,t,e,i);if(!(void 0===b?y===d||o(y,d,n,r,i):b)){v=!1;break}h||(h="constructor"==s)}if(v&&!h){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 i.delete(t),i.delete(e),v}(t,e,n,r,o,i))}function Te(t,e,n,r,o){return t===e||(null==t||null==e||!O(t)&&!O(e)?t!=t&&e!=e:Le(t,e,n,r,Te,o))}function qe(t){return t==t&&!S(t)}function Ce(t,e){return function(n){return null!=n&&(n[t]===e&&(void 0!==e||t in Object(n)))}}function Re(t){var e=function(t){for(var e=Ht(t),n=e.length;n--;){var r=e[n],o=t[r];e[n]=[r,o,qe(o)]}return e}(t);return 1==e.length&&e[0][2]?Ce(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 c=n[o];if(u&&c[2]?c[1]!==t[c[0]]:!(c[0]in t))return!1}for(;++o<i;){var a=(c=n[o])[0],f=t[a],s=c[1];if(u&&c[2]){if(void 0===f&&!(a in t))return!1}else{var l=new te;if(r)var p=r(f,s,a,t,e,l);if(!(void 0===p?Te(s,f,3,r,l):p))return!1}}return!0}(n,t,e)}}function Ve(t,e){return null!=t&&e in Object(t)}function Ge(t,e){return null!=t&&function(t,e,n){for(var r=-1,o=(e=pt(e,t)).length,i=!1;++r<o;){var u=vt(e[r]);if(!(i=null!=t&&n(t,u)))break;t=t[u]}return i||++r!=o?i:!!(o=null==t?0:t.length)&&zt(o)&&It(u,o)&&(l(t)||xt(t))}(t,e,Ve)}function We(t){return function(e){return null==e?void 0:e[t]}}function Je(t){return P(t)?We(vt(t)):function(t){return function(e){return ht(e,t)}}(t)}function Qe(t){return"function"==typeof t?t:null==t?Yt:"object"==typeof t?l(t)?function(t,e){return P(t)&&qe(e)?Ce(vt(t),e):function(n){var r=yt(n,t);return void 0===r&&r===e?Ge(n,t):Te(e,r,3)}}(t[0],t[1]):Re(t):Je(t)}function He(t,e){var n=-1,r=Qt(t)?Array(t.length):[];return Xt(t,(function(t,o,i){r[++n]=e(t,o,i)})),r}function Ke(t,e){return(l(t)?at:He)(t,Qe(e))}function Xe(t,e){var n=[];return Xt(t,(function(t,r,o){e(t,r,o)&&n.push(t)})),n}function Ye(t,e){return(l(t)?pe:Xe)(t,Qe(e))}var Ze=function(){try{var t=C(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),tn=Ze;function en(t,e,n){"__proto__"==e&&tn?tn(t,e,{configurable:!0,enumerable:!0,value:n,writable:!0}):t[e]=n}function nn(t,e,n){(void 0!==n&&!J(t[e],n)||void 0===n&&!(e in t))&&en(t,e,n)}var rn="object"==typeof exports&&exports&&!exports.nodeType&&exports,on=rn&&"object"==typeof module&&module&&!module.nodeType&&module,un=on&&on.exports===rn?h.Buffer:void 0,cn=un?un.allocUnsafe:void 0;function an(t,e){if(e)return t.slice();var n=t.length,r=cn?cn(n):new t.constructor(n);return t.copy(r),r}function fn(t){var e=new t.constructor(t.byteLength);return new ie(e).set(new ie(t)),e}function sn(t,e){var n=e?fn(t.buffer):t.buffer;return new t.constructor(n,t.byteOffset,t.length)}function ln(t,e){var n=-1,r=t.length;for(e||(e=Array(r));++n<r;)e[n]=t[n];return e}var pn=Object.create,vn=function(){function t(){}return function(e){if(!S(e))return{};if(pn)return pn(e);t.prototype=e;var n=new t;return t.prototype=void 0,n}}(),hn=vn,yn=Vt(Object.getPrototypeOf,Object);function dn(t){return"function"!=typeof t.constructor||Rt(t)?{}:hn(yn(t))}var bn=Function.prototype,jn=Object.prototype,gn=bn.toString,_n=jn.hasOwnProperty,wn=gn.call(Object);function mn(t,e){if(("constructor"!==e||"function"!=typeof t[e])&&"__proto__"!=e)return t[e]}var On=Object.prototype.hasOwnProperty;function xn(t,e,n){var r=t[e];On.call(t,e)&&J(r,n)&&(void 0!==n||e in t)||en(t,e,n)}function An(t,e,n,r){var o=!n;n||(n={});for(var i=-1,u=e.length;++i<u;){var c=e[i],a=r?r(n[c],t[c],c,n,t):void 0;void 0===a&&(a=t[c]),o?en(n,c,a):xn(n,c,a)}return n}var kn=Object.prototype.hasOwnProperty;function Pn(t){if(!S(t))return function(t){var e=[];if(null!=t)for(var n in Object(t))e.push(n);return e}(t);var e=Rt(t),n=[];for(var r in t)("constructor"!=r||!e&&kn.call(t,r))&&n.push(r);return n}function Sn(t){return Qt(t)?qt(t,!0):Pn(t)}function En(t,e,n,r,o,i,u){var c=mn(t,n),a=mn(e,n),f=u.get(a);if(f)nn(t,n,f);else{var s,p=i?i(c,a,n+"",t,e,u):void 0,v=void 0===p;if(v){var h=l(a),y=!h&&St(a),d=!h&&!y&&Lt(a);p=a,h||y||d?l(c)?p=c:O(s=c)&&Qt(s)?p=ln(c):y?(v=!1,p=an(a,!0)):d?(v=!1,p=sn(a,!0)):p=[]:function(t){if(!O(t)||"[object Object]"!=m(t))return!1;var e=yn(t);if(null===e)return!0;var n=_n.call(e,"constructor")&&e.constructor;return"function"==typeof n&&n instanceof n&&gn.call(n)==wn}(a)||xt(a)?(p=c,xt(c)?p=function(t){return An(t,Sn(t))}(c):S(c)&&!E(c)||(p=dn(a))):v=!1}v&&(u.set(a,p),o(p,a,r,i,u),u.delete(a)),nn(t,n,p)}}function In(t,e,n,r,o){t!==e&&jt(e,(function(i,u){if(o||(o=new te),S(i))En(t,e,u,n,In,r,o);else{var c=r?r(mn(t,u),i,u+"",t,e,o):void 0;void 0===c&&(c=i),nn(t,u,c)}}),Sn)}var zn=Math.max;var Dn=tn?function(t,e){return tn(t,"toString",{configurable:!0,enumerable:!1,value:(n=e,function(){return n}),writable:!0});var n}:Yt,$n=Dn,Fn=Date.now;var Un=function(t){var e=0,n=0;return function(){var r=Fn(),o=16-(r-n);if(n=r,o>0){if(++e>=800)return arguments[0]}else e=0;return t.apply(void 0,arguments)}}($n),Bn=Un;function Mn(t,e){return Bn(function(t,e,n){return e=zn(void 0===e?t.length-1:e,0),function(){for(var r=arguments,o=-1,i=zn(r.length-e,0),u=Array(i);++o<i;)u[o]=r[e+o];o=-1;for(var c=Array(e+1);++o<e;)c[o]=r[o];return c[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,c)}}(t,e,Yt),t+"")}var Nn,Ln=(Nn=function(t,e,n){In(t,e,n)},Mn((function(t,e){var n=-1,r=e.length,o=r>1?e[r-1]:void 0,i=r>2?e[2]:void 0;for(o=Nn.length>3&&"function"==typeof o?(r--,o):void 0,i&&function(t,e,n){if(!S(n))return!1;var r=typeof e;return!!("number"==r?Qt(n)&&It(e,n.length):"string"==r&&e in n)&&J(n[e],t)}(e[0],e[1],i)&&(o=r<3?void 0:o,r=1),t=Object(t);++n<r;){var u=e[n];u&&Nn(t,u,n,o)}return t})));var Tn=We("length"),qn=RegExp("[\\u200d\\ud800-\\udfff\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff\\ufe0e\\ufe0f]");var Cn="\\ud800-\\udfff",Rn="["+Cn+"]",Vn="[\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff]",Gn="\\ud83c[\\udffb-\\udfff]",Wn="[^"+Cn+"]",Jn="(?:\\ud83c[\\udde6-\\uddff]){2}",Qn="[\\ud800-\\udbff][\\udc00-\\udfff]",Hn="(?:"+Vn+"|"+Gn+")"+"?",Kn="[\\ufe0e\\ufe0f]?",Xn=Kn+Hn+("(?:\\u200d(?:"+[Wn,Jn,Qn].join("|")+")"+Kn+Hn+")*"),Yn="(?:"+[Wn+Vn+"?",Vn,Jn,Qn,Rn].join("|")+")",Zn=RegExp(Gn+"(?="+Gn+")|"+Yn+Xn,"g");function tr(t){return function(t){return qn.test(t)}(t)?function(t){for(var e=Zn.lastIndex=0;Zn.test(t);)++e;return e}(t):Tn(t)}function er(t){if(null==t)return 0;if(Qt(t))return"string"==typeof(e=t)||!l(e)&&O(e)&&"[object String]"==m(e)?tr(t):t.length;var e,n=Fe(t);return"[object Map]"==n||"[object Set]"==n?t.size:Jt(t).length}var nr=Object.getOwnPropertySymbols?function(t){for(var e=[];t;)se(e,de(t)),t=yn(t);return e}:ve,rr=nr;function or(t){return le(t,Sn,rr)}var ir=Object.prototype.hasOwnProperty;var ur=/\w*$/;var cr=y?y.prototype:void 0,ar=cr?cr.valueOf:void 0;function fr(t,e,n){var r,o=t.constructor;switch(e){case"[object ArrayBuffer]":return fn(t);case"[object Boolean]":case"[object Date]":return new o(+t);case"[object DataView]":return function(t,e){var n=e?fn(t.buffer):t.buffer;return new t.constructor(n,t.byteOffset,t.byteLength)}(t,n);case"[object Float32Array]":case"[object Float64Array]":case"[object Int8Array]":case"[object Int16Array]":case"[object Int32Array]":case"[object Uint8Array]":case"[object Uint8ClampedArray]":case"[object Uint16Array]":case"[object Uint32Array]":return sn(t,n);case"[object Map]":case"[object Set]":return new o;case"[object Number]":case"[object String]":return new o(t);case"[object RegExp]":return function(t){var e=new t.constructor(t.source,ur.exec(t));return e.lastIndex=t.lastIndex,e}(t);case"[object Symbol]":return r=t,ar?Object(ar.call(r)):{}}}var sr=Mt&&Mt.isMap,lr=sr?$t(sr):function(t){return O(t)&&"[object Map]"==Fe(t)};var pr=Mt&&Mt.isSet,vr=pr?$t(pr):function(t){return O(t)&&"[object Set]"==Fe(t)},hr="[object Arguments]",yr="[object Function]",dr="[object Object]",br={};function jr(t,e,n,r,o,i){var u,c=1&e,a=2&e,f=4&e;if(n&&(u=o?n(t,r,o,i):n(t)),void 0!==u)return u;if(!S(t))return t;var s=l(t);if(s){if(u=function(t){var e=t.length,n=new t.constructor(e);return e&&"string"==typeof t[0]&&ir.call(t,"index")&&(n.index=t.index,n.input=t.input),n}(t),!c)return ln(t,u)}else{var p=Fe(t),v=p==yr||"[object GeneratorFunction]"==p;if(St(t))return an(t,c);if(p==dr||p==hr||v&&!o){if(u=a||v?{}:dn(t),!c)return a?function(t,e){return An(t,rr(t),e)}(t,function(t,e){return t&&An(e,Sn(e),t)}(u,t)):function(t,e){return An(t,de(t),e)}(t,function(t,e){return t&&An(e,Ht(e),t)}(u,t))}else{if(!br[p])return o?t:{};u=fr(t,p,c)}}i||(i=new te);var h=i.get(t);if(h)return h;i.set(t,u),vr(t)?t.forEach((function(r){u.add(jr(r,e,n,r,t,i))})):lr(t)&&t.forEach((function(r,o){u.set(o,jr(r,e,n,o,t,i))}));var y=s?void 0:(f?a?or:be:a?Sn:Ht)(t);return dt(y||t,(function(r,o){y&&(r=t[o=r]),xn(u,o,jr(r,e,n,o,t,i))})),u}br[hr]=br["[object Array]"]=br["[object ArrayBuffer]"]=br["[object DataView]"]=br["[object Boolean]"]=br["[object Date]"]=br["[object Float32Array]"]=br["[object Float64Array]"]=br["[object Int8Array]"]=br["[object Int16Array]"]=br["[object Int32Array]"]=br["[object Map]"]=br["[object Number]"]=br[dr]=br["[object RegExp]"]=br["[object Set]"]=br["[object String]"]=br["[object Symbol]"]=br["[object Uint8Array]"]=br["[object Uint8ClampedArray]"]=br["[object Uint16Array]"]=br["[object Uint32Array]"]=!0,br["[object Error]"]=br[yr]=br["[object WeakMap]"]=!1;function gr(t){return jr(t,5)}function _r(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var wr={exports:{}};!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 c=new o(r,i||t,u),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 u(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,i=r.length,u=new Array(i);o<i;o++)u[o]=r[o].fn;return u},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,i,u){var c=n?n+t:t;if(!this._events[c])return!1;var a,f,s=this._events[c],l=arguments.length;if(s.fn){switch(s.once&&this.removeListener(t,s.fn,void 0,!0),l){case 1:return s.fn.call(s.context),!0;case 2:return s.fn.call(s.context,e),!0;case 3:return s.fn.call(s.context,e,r),!0;case 4:return s.fn.call(s.context,e,r,o),!0;case 5:return s.fn.call(s.context,e,r,o,i),!0;case 6:return s.fn.call(s.context,e,r,o,i,u),!0}for(f=1,a=new Array(l-1);f<l;f++)a[f-1]=arguments[f];s.fn.apply(s.context,a)}else{var p,v=s.length;for(f=0;f<v;f++)switch(s[f].once&&this.removeListener(t,s[f].fn,void 0,!0),l){case 1:s[f].fn.call(s[f].context);break;case 2:s[f].fn.call(s[f].context,e);break;case 3:s[f].fn.call(s[f].context,e,r);break;case 4:s[f].fn.call(s[f].context,e,r,o);break;default:if(!a)for(p=1,a=new Array(l-1);p<l;p++)a[p-1]=arguments[p];s[f].fn.apply(s[f].context,a)}}return!0},c.prototype.on=function(t,e,n){return i(this,t,e,n,!1)},c.prototype.once=function(t,e,n){return i(this,t,e,n,!0)},c.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 c=this._events[i];if(c.fn)c.fn!==e||o&&!c.once||r&&c.context!==r||u(this,i);else{for(var a=0,f=[],s=c.length;a<s;a++)(c[a].fn!==e||o&&!c[a].once||r&&c[a].context!==r)&&f.push(c[a]);f.length?this._events[i]=1===f.length?f[0]:f:u(this,i)}return this},c.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},c.prototype.off=c.prototype.removeListener,c.prototype.addListener=c.prototype.on,c.prefixed=n,c.EventEmitter=c,t.exports=c}(wr);var mr=_r(wr.exports);const Or=[];for(let t=0;t<256;++t)Or.push((t+256).toString(16).slice(1));const xr=new Uint8Array(16);function Ar(){return crypto.getRandomValues(xr)}const kr={};function Pr(t,e,n){let r;if(t)r=Sr(t.random??t.rng?.()??Ar(),t.msecs,t.seq,e,n);else{const t=Date.now(),o=Ar();!function(t,e,n){t.msecs??=-1/0,t.seq??=0,e>t.msecs?(t.seq=Er(n),t.msecs=e):(t.seq=t.seq+1|0,0===t.seq&&t.msecs++)}(kr,t,o),r=Sr(o,kr.msecs,kr.seq,e,n)}return e??function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return(Or[t[e+0]]+Or[t[e+1]]+Or[t[e+2]]+Or[t[e+3]]+"-"+Or[t[e+4]]+Or[t[e+5]]+"-"+Or[t[e+6]]+Or[t[e+7]]+"-"+Or[t[e+8]]+Or[t[e+9]]+"-"+Or[t[e+10]]+Or[t[e+11]]+Or[t[e+12]]+Or[t[e+13]]+Or[t[e+14]]+Or[t[e+15]]).toLowerCase()}(r)}function Sr(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??=Er(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 Er(t){return(127&t[6])<<24|t[7]<<16|t[8]<<8|t[9]}var Ir=/\s/;var zr=/^\s+/;function Dr(t){return t?t.slice(0,function(t){for(var e=t.length;e--&&Ir.test(t.charAt(e)););return e}(t)+1).replace(zr,""):t}var $r=/^[-+]0x[0-9a-f]+$/i,Fr=/^0b[01]+$/i,Ur=/^0o[0-7]+$/i,Br=parseInt;var Mr=1/0;function Nr(t){return t?(t=function(t){if("number"==typeof t)return t;if(x(t))return NaN;if(S(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=S(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=Dr(t);var n=Fr.test(t);return n||Ur.test(t)?Br(t.slice(2),n?2:8):$r.test(t)?NaN:+t}(t))===Mr||t===-1/0?17976931348623157e292*(t<0?-1:1):t==t?t:0:0===t?t:0}function Lr(t,e,n){var r=null==t?0:t.length;return r?(e=n||void 0===e?1:function(t){var e=Nr(t),n=e%1;return e==e?n?e-n:e:0}(e),function(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}(t,e<0?0:e,r)):[]}function Tr(t){return"[object Array]"===Object.prototype.toString.call(t)}function qr(t){return"[object Object]"===Object.prototype.toString.call(t)}function Cr(t){return E(t)}function Rr(t,e){let n=function(){let t,e,n=new Promise((function(){t=arguments[0],e=arguments[1]}));return n.resolve=t,n.reject=e,n}();if(!Tr(t)&&!qr(t))return n.reject("rs is not an array or object"),n;let r=!1;if(qr(t)){r=!0;let e=[];Zt(t,((t,n)=>{e.push({k:n,v:t})})),t=e}Cr(e)||(e=function(t){return t});let o=-1,i=[];return t.reduce((function(t,n){return t.then((function(t){i.push(t),o+=1;let u=o,c=n;return r&&(u=n.k,c=n.v),Cr(e)?e(c,u):c}))}),Promise.resolve()).then((function(t){i.push(t),i=Lr(i),n.resolve(i)})).catch((function(t){n.reject(t)})),n}function Vr(t){return!0===(e=t)||!1===e||O(e)&&"[object Boolean]"==m(e);var e}function Gr(t){return"[object String]"===Object.prototype.toString.call(t)}function Wr(t){return!(!Gr(t)||""===t)}function Jr(t){if(qr(t)){for(let e in t)return!0;return!1}return!1}function Qr(t){return t!=t}function Hr(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(qr(t)){for(let e in t)return!1;return!0}return!1}(t)||(!!function(t){return!(!Gr(t)||""!==t)}(t)||(!!function(t){return!!Tr(t)&&0===t.length}(t)||!!Qr(t)))))}function Kr(t){return!!Tr(t)&&(0!==t.length&&(1!==t.length||!Hr(t[0])))}function Xr(t){let e=!1;if(Wr(t)){if(""===t.trim())return!1;e=!isNaN(Number(t))}else if(function(t){return"[object Number]"===Object.prototype.toString.call(t)}(t)){if(Qr(t))return!1;e=!0}return e}function Yr(t,e){return!!qr(t)&&(!(!Wr(e)&&!Xr(e))&&e in t)}let Zr={};return function(){let n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=null,o=yt(n,"url");Wr(o)||(o="./db.json");let i=yt(n,"db");Wr(i)||(i="worm");let c=yt(n,"cl");Wr(c)||(c="test");let a=yt(n,"useCache");Vr(a)||(a=!1);let f=yt(n,"autoGenPk");Vr(f)||(f=!0);let l=`${i}:${c}`,p=new s(o),v=new e.Low(p,{}),h=new mr,y=t.resolve(o);Yr(Zr,y)||(Zr[y]=Promise.resolve());let d=t=>{let e=Zr[y].then((()=>t()));return Zr[y]=e.catch((()=>{})),e},b=(t,e,n)=>{try{h.emit("change",t,e,n)}catch(t){console.log(t)}},j=(t,e,n)=>{try{h.emit("error",t,e,g(n))}catch(t){console.log(t)}},g=t=>{let e=yt(t,"message");return Wr(e)?e:String(t)},_=(t,e)=>f?Ke(t,(function(t){return Wr(t.id)||(t.id=Pr()),t})):(Zt(t,(function(t,n){if(!Wr(yt(t,"id")))throw new Error(`can not ${e} by data[${n}] without valid id when autoGenPk is false`)})),t),w=async()=>(await v.read(),Yr(v.data,l)||(v.data[l]=[]),v.data[l]),m=async(t,e)=>{v.data[l]=e;try{await v.write()}catch(e){throw v.data[l]=t,e}},O=t=>{let e={};return Zt(t,((t,n)=>{let r=yt(t,"id");Wr(r)&&(e[r]={k:n,v:t})})),e},x=async()=>{if(a&&Tr(r))return gr(r);let t=await w();return t=gr(t),a?(r=t,gr(t)):t};async function A(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=!1;if(!Jr(t)&&!Kr(t))return[];t=gr(t);let o=yt(e,"autoInsert",!0),i=null;try{Tr(t)||(t=[t]),t=_(t,"save");let e=await w(),n=[...e],r=O(n),u=!1;i=await Rr(t,(async t=>{let e=null;try{let i=yt(r,t.id,null);if(Jr(i)){let o=i.v,c=Ln({},o,t);Te(c,o)?e={n:1,nInserted:0,nModified:0,ok:1}:(n[i.k]=c,r[t.id]={k:i.k,v:c},u=!0,e={n:1,nInserted:0,nModified:1,ok:1})}else if(o){let o=er(n);n.push(t),r[t.id]={k:o,v:t},u=!0,e={n:1,nInserted:1,nModified:0,ok:1}}else e={n:0,nInserted:0,nModified:0,ok:1}}catch(t){e={n:1,nInserted:0,nModified:0,ok:0,err:g(t)}}return e})),u&&await m(e,n)}catch(t){n=!0,i=t}return r=null,n||(Zt(i,((e,n)=>{0===yt(e,"ok")&&j("save",[yt(t,n)],yt(e,"err"))})),Zt(i,((e,n)=>{1===yt(e,"nInserted")&&b("insert",[yt(t,n)],e)})),b("save",t,i)),n?(j("save",t,i),Promise.reject(i)):i}return h.select=async function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return d((()=>async function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=!1,n=null;try{let r=await x();n=Jr(t)?new u.Query(t).find(r).all():r,Tr(n)||(e=!0,n=new Error(`can not select by find[${JSON.stringify(t)}]`))}catch(t){e=!0,n=t}return e?(j("select",null,n),Promise.reject(n)):n}(t)))},h.selectByPk=async function(t){return d((()=>async function(t){let e=!1,n=null;try{if(!Wr(t))return null;let e=await x(),r=yt(O(e),t,null);n=Jr(r)?r.v:null}catch(t){e=!0,n=t}return e?(j("selectByPk",null,n),Promise.reject(n)):n}(t)))},h.insert=async function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return d((()=>async function(t){let e=!1,n=yt(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},"returnList");if(Vr(n)||(n=!1),!Jr(t)&&!Kr(t))return n?[]:{n:0,nInserted:0,ok:1};t=gr(t);let o=null;try{Tr(t)||(t=[t]),t=_(t,"insert");let e=await w(),r=O(e),i=er(t),u=[],c=[];Zt(t,(t=>{Yr(r,t.id)?u.push(!1):(c.push(t),r[t.id]={k:-1,v:t},u.push(!0))})),er(c)>0&&await m(e,[...e,...c]),o=n?Ke(u,(function(t){return{n:1,nInserted:t?1:0,ok:1}})):{n:i,nInserted:er(c),ok:1}}catch(t){e=!0,o=t}return r=null,e||b("insert",t,o),e?(j("insert",t,o),Promise.reject(o)):o}(t,e)))},h.insertBulk=async function(t){return d((()=>async function(t){let e=!1;if(!Jr(t)&&!Kr(t))return{n:0,nInserted:0,ok:1};t=gr(t);let n=null;try{Tr(t)||(t=[t]),t=_(t,"insertBulk");let e=await w(),r=O(e),o=er(t),i=null;if(Zt(t,(t=>{if(Yr(r,t.id))return i=t.id,!1;r[t.id]={k:-1,v:t}})),null!==i)throw new Error(`can not insertBulk by existed id[${i}]`);await m(e,[...e,...t]),n={n:o,nInserted:o,ok:1}}catch(t){e=!0,n=t}return r=null,e||b("insertBulk",t,n),e?(j("insertBulk",t,n),Promise.reject(n)):n}(t)))},h.save=async function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return d((()=>A(t,e)))},h.del=async function(t){return d((()=>async function(t){let e=!1;if(!Jr(t)&&!Kr(t))return[];t=gr(t);let n=null;try{Tr(t)||(t=[t]);let e=await w(),r=O(e),o={},i=!1;if(n=await Rr(t,(async t=>{let e=null;try{let n=yt(t,"id","");if(Wr(n)){let t=yt(r,n,null);Jr(t)?(o[t.k]=!0,delete r[n],i=!0,e={n:1,nDeleted:1,ok:1}):e={n:0,nDeleted:0,ok:1}}else e={n:0,nDeleted:0,ok:0,err:`can not delete by invalid id[${n}]`}}catch(t){e={n:1,nDeleted:0,ok:0,err:g(t)}}return e})),i){let t=Ye(e,((t,e)=>!Yr(o,e)));await m(e,t)}}catch(t){e=!0,n=t}return r=null,e||(Zt(n,((e,n)=>{0===yt(e,"ok")&&j("del",[yt(t,n)],yt(e,"err"))})),b("del",t,n)),e?(j("del",t,n),Promise.reject(n)):n}(t)))},h.delAll=async function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};return d((()=>async function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=!1,n=null;try{let e=await w(),r=er(e),o=0,i=null;if(Jr(t)){let n=new u.Query(t);i=Ye(e,(t=>!n.test(t))),o=r-er(i)}else o=r,i=[];o>0&&await m(e,i),n={n:o,nDeleted:o,ok:1}}catch(t){e=!0,n=t}return r=null,e||b("delAll",null,n),e?(j("delAll",null,n),Promise.reject(n)):n}(t)))},h}}));
6
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("path"),require("lowdb"),require("node:fs"),require("node:fs/promises"),require("node:path"),require("node:url"),require("mingo")):"function"==typeof define&&define.amd?define(["path","lowdb","node:fs","node:fs/promises","node:path","node:url","mingo"],e):(t="undefined"!=typeof globalThis?globalThis:t||self)["w-orm-lowdb"]=e(t.path,t.lowdb,null,t.promises,t.path,t.node_url,t.mingo)}(this,(function(t,e,r,n,o,i,u){"use strict";class a{#t;#e;#r=!1;#n=null;#o=null;#i=null;#u=null;#a(t){return this.#u=t,this.#i||=new Promise(((t,e)=>{this.#o=[t,e]})),new Promise(((t,e)=>{this.#i?.then(t).catch(e)}))}async#c(t){this.#r=!0;try{await n.writeFile(this.#e,t,"utf-8"),await async function(t,e,r){for(let n=0;n<e;n++)try{return await t()}catch(t){if(!(n<e-1))throw t;await new Promise((t=>setTimeout(t,r)))}}((async()=>{await n.rename(this.#e,this.#t)}),10,100),this.#n?.[0]()}catch(t){throw t instanceof Error&&this.#n?.[1](t),t}finally{if(this.#r=!1,this.#n=this.#o,this.#o=this.#i=null,null!==this.#u){const t=this.#u;this.#u=null,await this.write(t)}}}constructor(t){this.#t=t,this.#e=function(t){const e=t instanceof URL?i.fileURLToPath(t):t.toString();return o.join(o.dirname(e),`.${o.basename(e)}.tmp`)}(t)}async write(t){return this.#r?this.#a(t):this.#c(t)}}class c{#t;#l;constructor(t){this.#t=t,this.#l=new a(t)}async read(){let t;try{t=await n.readFile(this.#t,"utf-8")}catch(t){if("ENOENT"===t.code)return null;throw t}return t}write(t){return this.#l.write(t)}}class l{#s;#f;#p;constructor(t,e){let{parse:r,stringify:n}=e;this.#s=new c(t),this.#f=r,this.#p=n}async read(){const t=await this.#s.read();return null===t?null:this.#f(t)}write(t){return this.#s.write(this.#p(t))}}class s extends l{constructor(t){super(t,{parse:JSON.parse,stringify:t=>JSON.stringify(t,null,2)})}}var f=Array.isArray,p="object"==typeof global&&global&&global.Object===Object&&global,h="object"==typeof self&&self&&self.Object===Object&&self,y=p||h||Function("return this")(),d=y.Symbol,v=Object.prototype,b=v.hasOwnProperty,g=v.toString,j=d?d.toStringTag:void 0;var m=Object.prototype.toString;var w=d?d.toStringTag:void 0;function _(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":w&&w in Object(t)?function(t){var e=b.call(t,j),r=t[j];try{t[j]=void 0;var n=!0}catch(t){}var o=g.call(t);return n&&(e?t[j]=r:delete t[j]),o}(t):function(t){return m.call(t)}(t)}function O(t){return null!=t&&"object"==typeof t}function x(t){return"symbol"==typeof t||O(t)&&"[object Symbol]"==_(t)}var k=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,A=/^\w*$/;function S(t,e){if(f(t))return!1;var r=typeof t;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=t&&!x(t))||(A.test(t)||!k.test(t)||null!=e&&t in Object(e))}function $(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}function P(t){if(!$(t))return!1;var e=_(t);return"[object Function]"==e||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e}var D,I=y["__core-js_shared__"],E=(D=/[^.]+$/.exec(I&&I.keys&&I.keys.IE_PROTO||""))?"Symbol(src)_1."+D:"";var N=Function.prototype.toString;function F(t){if(null!=t){try{return N.call(t)}catch(t){}try{return t+""}catch(t){}}return""}var B=/^\[object .+?Constructor\]$/,L=Function.prototype,U=Object.prototype,z=L.toString,M=U.hasOwnProperty,C=RegExp("^"+z.call(M).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function R(t){return!(!$(t)||(e=t,E&&E in e))&&(P(t)?C:B).test(F(t));var e}function T(t,e){var r=function(t,e){return null==t?void 0:t[e]}(t,e);return R(r)?r:void 0}var q=T(Object,"create");var W=Object.prototype.hasOwnProperty;var K=Object.prototype.hasOwnProperty;function V(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function G(t,e){return t===e||t!=t&&e!=e}function J(t,e){for(var r=t.length;r--;)if(G(t[r][0],e))return r;return-1}V.prototype.clear=function(){this.__data__=q?q(null):{},this.size=0},V.prototype.delete=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},V.prototype.get=function(t){var e=this.__data__;if(q){var r=e[t];return"__lodash_hash_undefined__"===r?void 0:r}return W.call(e,t)?e[t]:void 0},V.prototype.has=function(t){var e=this.__data__;return q?void 0!==e[t]:K.call(e,t)},V.prototype.set=function(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=q&&void 0===e?"__lodash_hash_undefined__":e,this};var Z=Array.prototype.splice;function Q(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}Q.prototype.clear=function(){this.__data__=[],this.size=0},Q.prototype.delete=function(t){var e=this.__data__,r=J(e,t);return!(r<0)&&(r==e.length-1?e.pop():Z.call(e,r,1),--this.size,!0)},Q.prototype.get=function(t){var e=this.__data__,r=J(e,t);return r<0?void 0:e[r][1]},Q.prototype.has=function(t){return J(this.__data__,t)>-1},Q.prototype.set=function(t,e){var r=this.__data__,n=J(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this};var H=T(y,"Map");function X(t,e){var r,n,o=t.__data__;return("string"==(n=typeof(r=e))||"number"==n||"symbol"==n||"boolean"==n?"__proto__"!==r:null===r)?o["string"==typeof e?"string":"hash"]:o.map}function Y(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}Y.prototype.clear=function(){this.size=0,this.__data__={hash:new V,map:new(H||Q),string:new V}},Y.prototype.delete=function(t){var e=X(this,t).delete(t);return this.size-=e?1:0,e},Y.prototype.get=function(t){return X(this,t).get(t)},Y.prototype.has=function(t){return X(this,t).has(t)},Y.prototype.set=function(t,e){var r=X(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,this};function tt(t,e){if("function"!=typeof t||null!=e&&"function"!=typeof e)throw new TypeError("Expected a function");var r=function(){var n=arguments,o=e?e.apply(this,n):n[0],i=r.cache;if(i.has(o))return i.get(o);var u=t.apply(this,n);return r.cache=i.set(o,u)||i,u};return r.cache=new(tt.Cache||Y),r}tt.Cache=Y;var et,rt,nt,ot=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,it=/\\(\\)?/g,ut=(et=function(t){var e=[];return 46===t.charCodeAt(0)&&e.push(""),t.replace(ot,(function(t,r,n,o){e.push(n?o.replace(it,"$1"):r||t)})),e},rt=tt(et,(function(t){return 500===nt.size&&nt.clear(),t})),nt=rt.cache,rt),at=ut;function ct(t,e){for(var r=-1,n=null==t?0:t.length,o=Array(n);++r<n;)o[r]=e(t[r],r,t);return o}var lt=d?d.prototype:void 0,st=lt?lt.toString:void 0;function ft(t){if("string"==typeof t)return t;if(f(t))return ct(t,ft)+"";if(x(t))return st?st.call(t):"";var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}function pt(t,e){return f(t)?t:S(t,e)?[t]:at(function(t){return null==t?"":ft(t)}(t))}function ht(t){if("string"==typeof t||x(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}function yt(t,e){for(var r=0,n=(e=pt(e,t)).length;null!=t&&r<n;)t=t[ht(e[r++])];return r&&r==n?t:void 0}function dt(t,e,r){var n=null==t?void 0:yt(t,e);return void 0===n?r:n}function vt(t,e){for(var r=-1,n=null==t?0:t.length;++r<n&&!1!==e(t[r],r,t););return t}var bt,gt=function(t,e,r){for(var n=-1,o=Object(t),i=r(t),u=i.length;u--;){var a=i[bt?u:++n];if(!1===e(o[a],a,o))break}return t};function jt(t){return O(t)&&"[object Arguments]"==_(t)}var mt=Object.prototype,wt=mt.hasOwnProperty,_t=mt.propertyIsEnumerable,Ot=jt(function(){return arguments}())?jt:function(t){return O(t)&&wt.call(t,"callee")&&!_t.call(t,"callee")},xt=Ot;var kt="object"==typeof exports&&exports&&!exports.nodeType&&exports,At=kt&&"object"==typeof module&&module&&!module.nodeType&&module,St=At&&At.exports===kt?y.Buffer:void 0,$t=(St?St.isBuffer:void 0)||function(){return!1},Pt=/^(?:0|[1-9]\d*)$/;function Dt(t,e){var r=typeof t;return!!(e=null==e?9007199254740991:e)&&("number"==r||"symbol"!=r&&Pt.test(t))&&t>-1&&t%1==0&&t<e}function It(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991}var Et={};function Nt(t){return function(e){return t(e)}}Et["[object Float32Array]"]=Et["[object Float64Array]"]=Et["[object Int8Array]"]=Et["[object Int16Array]"]=Et["[object Int32Array]"]=Et["[object Uint8Array]"]=Et["[object Uint8ClampedArray]"]=Et["[object Uint16Array]"]=Et["[object Uint32Array]"]=!0,Et["[object Arguments]"]=Et["[object Array]"]=Et["[object ArrayBuffer]"]=Et["[object Boolean]"]=Et["[object DataView]"]=Et["[object Date]"]=Et["[object Error]"]=Et["[object Function]"]=Et["[object Map]"]=Et["[object Number]"]=Et["[object Object]"]=Et["[object RegExp]"]=Et["[object Set]"]=Et["[object String]"]=Et["[object WeakMap]"]=!1;var Ft="object"==typeof exports&&exports&&!exports.nodeType&&exports,Bt=Ft&&"object"==typeof module&&module&&!module.nodeType&&module,Lt=Bt&&Bt.exports===Ft&&p.process,Ut=function(){try{var t=Bt&&Bt.require&&Bt.require("util").types;return t||Lt&&Lt.binding&&Lt.binding("util")}catch(t){}}(),zt=Ut&&Ut.isTypedArray,Mt=zt?Nt(zt):function(t){return O(t)&&It(t.length)&&!!Et[_(t)]},Ct=Object.prototype.hasOwnProperty;function Rt(t,e){var r=f(t),n=!r&&xt(t),o=!r&&!n&&$t(t),i=!r&&!n&&!o&&Mt(t),u=r||n||o||i,a=u?function(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n}(t.length,String):[],c=a.length;for(var l in t)!e&&!Ct.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 Tt=Object.prototype;function qt(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||Tt)}function Wt(t,e){return function(r){return t(e(r))}}var Kt=Wt(Object.keys,Object),Vt=Object.prototype.hasOwnProperty;function Gt(t){if(!qt(t))return Kt(t);var e=[];for(var r in Object(t))Vt.call(t,r)&&"constructor"!=r&&e.push(r);return e}function Jt(t){return null!=t&&It(t.length)&&!P(t)}function Zt(t){return Jt(t)?Rt(t):Gt(t)}var Qt=function(t,e){return function(r,n){if(null==r)return r;if(!Jt(r))return t(r,n);for(var o=r.length,i=e?o:-1,u=Object(r);(e?i--:++i<o)&&!1!==n(u[i],i,u););return r}}((function(t,e){return t&&gt(t,e,Zt)})),Ht=Qt;function Xt(t){return t}function Yt(t,e){var r;return(f(t)?vt:Ht)(t,"function"==typeof(r=e)?r:Xt)}function te(t){var e=this.__data__=new Q(t);this.size=e.size}te.prototype.clear=function(){this.__data__=new Q,this.size=0},te.prototype.delete=function(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r},te.prototype.get=function(t){return this.__data__.get(t)},te.prototype.has=function(t){return this.__data__.has(t)},te.prototype.set=function(t,e){var r=this.__data__;if(r instanceof Q){var n=r.__data__;if(!H||n.length<199)return n.push([t,e]),this.size=++r.size,this;r=this.__data__=new Y(n)}return r.set(t,e),this.size=r.size,this};function ee(t){var e=-1,r=null==t?0:t.length;for(this.__data__=new Y;++e<r;)this.add(t[e])}function re(t,e){for(var r=-1,n=null==t?0:t.length;++r<n;)if(e(t[r],r,t))return!0;return!1}function ne(t,e){return t.has(e)}ee.prototype.add=ee.prototype.push=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this},ee.prototype.has=function(t){return this.__data__.has(t)};function oe(t,e,r,n,o,i){var u=1&r,a=t.length,c=e.length;if(a!=c&&!(u&&c>a))return!1;var l=i.get(t),s=i.get(e);if(l&&s)return l==e&&s==t;var f=-1,p=!0,h=2&r?new ee:void 0;for(i.set(t,e),i.set(e,t);++f<a;){var y=t[f],d=e[f];if(n)var v=u?n(d,y,f,e,t,i):n(y,d,f,t,e,i);if(void 0!==v){if(v)continue;p=!1;break}if(h){if(!re(e,(function(t,e){if(!ne(h,e)&&(y===t||o(y,t,r,n,i)))return h.push(e)}))){p=!1;break}}else if(y!==d&&!o(y,d,r,n,i)){p=!1;break}}return i.delete(t),i.delete(e),p}var ie=y.Uint8Array;function ue(t){var e=-1,r=Array(t.size);return t.forEach((function(t,n){r[++e]=[n,t]})),r}function ae(t){var e=-1,r=Array(t.size);return t.forEach((function(t){r[++e]=t})),r}var ce=d?d.prototype:void 0,le=ce?ce.valueOf:void 0;function se(t,e){for(var r=-1,n=e.length,o=t.length;++r<n;)t[o+r]=e[r];return t}function fe(t,e,r){var n=e(t);return f(t)?n:se(n,r(t))}function pe(t,e){for(var r=-1,n=null==t?0:t.length,o=0,i=[];++r<n;){var u=t[r];e(u,r,t)&&(i[o++]=u)}return i}function he(){return[]}var ye=Object.prototype.propertyIsEnumerable,de=Object.getOwnPropertySymbols,ve=de?function(t){return null==t?[]:(t=Object(t),pe(de(t),(function(e){return ye.call(t,e)})))}:he;function be(t){return fe(t,Zt,ve)}var ge=Object.prototype.hasOwnProperty;var je=T(y,"DataView"),me=T(y,"Promise"),we=T(y,"Set"),_e=T(y,"WeakMap"),Oe="[object Map]",xe="[object Promise]",ke="[object Set]",Ae="[object WeakMap]",Se="[object DataView]",$e=F(je),Pe=F(H),De=F(me),Ie=F(we),Ee=F(_e),Ne=_;(je&&Ne(new je(new ArrayBuffer(1)))!=Se||H&&Ne(new H)!=Oe||me&&Ne(me.resolve())!=xe||we&&Ne(new we)!=ke||_e&&Ne(new _e)!=Ae)&&(Ne=function(t){var e=_(t),r="[object Object]"==e?t.constructor:void 0,n=r?F(r):"";if(n)switch(n){case $e:return Se;case Pe:return Oe;case De:return xe;case Ie:return ke;case Ee:return Ae}return e});var Fe=Ne,Be="[object Arguments]",Le="[object Array]",Ue="[object Object]",ze=Object.prototype.hasOwnProperty;function Me(t,e,r,n,o,i){var u=f(t),a=f(e),c=u?Le:Fe(t),l=a?Le:Fe(e),s=(c=c==Be?Ue:c)==Ue,p=(l=l==Be?Ue:l)==Ue,h=c==l;if(h&&$t(t)){if(!$t(e))return!1;u=!0,s=!1}if(h&&!s)return i||(i=new te),u||Mt(t)?oe(t,e,r,n,o,i):function(t,e,r,n,o,i,u){switch(r){case"[object DataView]":if(t.byteLength!=e.byteLength||t.byteOffset!=e.byteOffset)return!1;t=t.buffer,e=e.buffer;case"[object ArrayBuffer]":return!(t.byteLength!=e.byteLength||!i(new ie(t),new ie(e)));case"[object Boolean]":case"[object Date]":case"[object Number]":return G(+t,+e);case"[object Error]":return t.name==e.name&&t.message==e.message;case"[object RegExp]":case"[object String]":return t==e+"";case"[object Map]":var a=ue;case"[object Set]":var c=1&n;if(a||(a=ae),t.size!=e.size&&!c)return!1;var l=u.get(t);if(l)return l==e;n|=2,u.set(t,e);var s=oe(a(t),a(e),n,o,i,u);return u.delete(t),s;case"[object Symbol]":if(le)return le.call(t)==le.call(e)}return!1}(t,e,c,r,n,o,i);if(!(1&r)){var y=s&&ze.call(t,"__wrapped__"),d=p&&ze.call(e,"__wrapped__");if(y||d){var v=y?t.value():t,b=d?e.value():e;return i||(i=new te),o(v,b,r,n,i)}}return!!h&&(i||(i=new te),function(t,e,r,n,o,i){var u=1&r,a=be(t),c=a.length;if(c!=be(e).length&&!u)return!1;for(var l=c;l--;){var s=a[l];if(!(u?s in e:ge.call(e,s)))return!1}var f=i.get(t),p=i.get(e);if(f&&p)return f==e&&p==t;var h=!0;i.set(t,e),i.set(e,t);for(var y=u;++l<c;){var d=t[s=a[l]],v=e[s];if(n)var b=u?n(v,d,s,e,t,i):n(d,v,s,t,e,i);if(!(void 0===b?d===v||o(d,v,r,n,i):b)){h=!1;break}y||(y="constructor"==s)}if(h&&!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||(h=!1)}return i.delete(t),i.delete(e),h}(t,e,r,n,o,i))}function Ce(t,e,r,n,o){return t===e||(null==t||null==e||!O(t)&&!O(e)?t!=t&&e!=e:Me(t,e,r,n,Ce,o))}function Re(t){return t==t&&!$(t)}function Te(t,e){return function(r){return null!=r&&(r[t]===e&&(void 0!==e||t in Object(r)))}}function qe(t){var e=function(t){for(var e=Zt(t),r=e.length;r--;){var n=e[r],o=t[n];e[r]=[n,o,Re(o)]}return e}(t);return 1==e.length&&e[0][2]?Te(e[0][0],e[0][1]):function(r){return r===t||function(t,e,r,n){var o=r.length,i=o,u=!n;if(null==t)return!i;for(t=Object(t);o--;){var a=r[o];if(u&&a[2]?a[1]!==t[a[0]]:!(a[0]in t))return!1}for(;++o<i;){var c=(a=r[o])[0],l=t[c],s=a[1];if(u&&a[2]){if(void 0===l&&!(c in t))return!1}else{var f=new te;if(n)var p=n(l,s,c,t,e,f);if(!(void 0===p?Ce(s,l,3,n,f):p))return!1}}return!0}(r,t,e)}}function We(t,e){return null!=t&&e in Object(t)}function Ke(t,e){return null!=t&&function(t,e,r){for(var n=-1,o=(e=pt(e,t)).length,i=!1;++n<o;){var u=ht(e[n]);if(!(i=null!=t&&r(t,u)))break;t=t[u]}return i||++n!=o?i:!!(o=null==t?0:t.length)&&It(o)&&Dt(u,o)&&(f(t)||xt(t))}(t,e,We)}function Ve(t){return function(e){return null==e?void 0:e[t]}}function Ge(t){return S(t)?Ve(ht(t)):function(t){return function(e){return yt(e,t)}}(t)}function Je(t){return"function"==typeof t?t:null==t?Xt:"object"==typeof t?f(t)?function(t,e){return S(t)&&Re(e)?Te(ht(t),e):function(r){var n=dt(r,t);return void 0===n&&n===e?Ke(r,t):Ce(e,n,3)}}(t[0],t[1]):qe(t):Ge(t)}function Ze(t,e){var r=-1,n=Jt(t)?Array(t.length):[];return Ht(t,(function(t,o,i){n[++r]=e(t,o,i)})),n}function Qe(t,e){return(f(t)?ct:Ze)(t,Je(e))}function He(t,e){var r=[];return Ht(t,(function(t,n,o){e(t,n,o)&&r.push(t)})),r}function Xe(t,e){return(f(t)?pe:He)(t,Je(e))}var Ye=function(){try{var t=T(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),tr=Ye;function er(t,e,r){"__proto__"==e&&tr?tr(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r}function rr(t,e,r){(void 0!==r&&!G(t[e],r)||void 0===r&&!(e in t))&&er(t,e,r)}var nr="object"==typeof exports&&exports&&!exports.nodeType&&exports,or=nr&&"object"==typeof module&&module&&!module.nodeType&&module,ir=or&&or.exports===nr?y.Buffer:void 0,ur=ir?ir.allocUnsafe:void 0;function ar(t,e){if(e)return t.slice();var r=t.length,n=ur?ur(r):new t.constructor(r);return t.copy(n),n}function cr(t){var e=new t.constructor(t.byteLength);return new ie(e).set(new ie(t)),e}function lr(t,e){var r=e?cr(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.length)}function sr(t,e){var r=-1,n=t.length;for(e||(e=Array(n));++r<n;)e[r]=t[r];return e}var fr=Object.create,pr=function(){function t(){}return function(e){if(!$(e))return{};if(fr)return fr(e);t.prototype=e;var r=new t;return t.prototype=void 0,r}}(),hr=pr,yr=Wt(Object.getPrototypeOf,Object);function dr(t){return"function"!=typeof t.constructor||qt(t)?{}:hr(yr(t))}var vr=Function.prototype,br=Object.prototype,gr=vr.toString,jr=br.hasOwnProperty,mr=gr.call(Object);function wr(t,e){if(("constructor"!==e||"function"!=typeof t[e])&&"__proto__"!=e)return t[e]}var _r=Object.prototype.hasOwnProperty;function Or(t,e,r){var n=t[e];_r.call(t,e)&&G(n,r)&&(void 0!==r||e in t)||er(t,e,r)}function xr(t,e,r,n){var o=!r;r||(r={});for(var i=-1,u=e.length;++i<u;){var a=e[i],c=n?n(r[a],t[a],a,r,t):void 0;void 0===c&&(c=t[a]),o?er(r,a,c):Or(r,a,c)}return r}var kr=Object.prototype.hasOwnProperty;function Ar(t){if(!$(t))return function(t){var e=[];if(null!=t)for(var r in Object(t))e.push(r);return e}(t);var e=qt(t),r=[];for(var n in t)("constructor"!=n||!e&&kr.call(t,n))&&r.push(n);return r}function Sr(t){return Jt(t)?Rt(t,!0):Ar(t)}function $r(t,e,r,n,o,i,u){var a=wr(t,r),c=wr(e,r),l=u.get(c);if(l)rr(t,r,l);else{var s,p=i?i(a,c,r+"",t,e,u):void 0,h=void 0===p;if(h){var y=f(c),d=!y&&$t(c),v=!y&&!d&&Mt(c);p=c,y||d||v?f(a)?p=a:O(s=a)&&Jt(s)?p=sr(a):d?(h=!1,p=ar(c,!0)):v?(h=!1,p=lr(c,!0)):p=[]:function(t){if(!O(t)||"[object Object]"!=_(t))return!1;var e=yr(t);if(null===e)return!0;var r=jr.call(e,"constructor")&&e.constructor;return"function"==typeof r&&r instanceof r&&gr.call(r)==mr}(c)||xt(c)?(p=a,xt(a)?p=function(t){return xr(t,Sr(t))}(a):$(a)&&!P(a)||(p=dr(c))):h=!1}h&&(u.set(c,p),o(p,c,n,i,u),u.delete(c)),rr(t,r,p)}}function Pr(t,e,r,n,o){t!==e&&gt(e,(function(i,u){if(o||(o=new te),$(i))$r(t,e,u,r,Pr,n,o);else{var a=n?n(wr(t,u),i,u+"",t,e,o):void 0;void 0===a&&(a=i),rr(t,u,a)}}),Sr)}var Dr=Math.max;var Ir=tr?function(t,e){return tr(t,"toString",{configurable:!0,enumerable:!1,value:(r=e,function(){return r}),writable:!0});var r}:Xt,Er=Ir,Nr=Date.now;var Fr=function(t){var e=0,r=0;return function(){var n=Nr(),o=16-(n-r);if(r=n,o>0){if(++e>=800)return arguments[0]}else e=0;return t.apply(void 0,arguments)}}(Er),Br=Fr;function Lr(t,e){return Br(function(t,e,r){return e=Dr(void 0===e?t.length-1:e,0),function(){for(var n=arguments,o=-1,i=Dr(n.length-e,0),u=Array(i);++o<i;)u[o]=n[e+o];o=-1;for(var a=Array(e+1);++o<e;)a[o]=n[o];return a[e]=r(u),function(t,e,r){switch(r.length){case 0:return t.call(e);case 1:return t.call(e,r[0]);case 2:return t.call(e,r[0],r[1]);case 3:return t.call(e,r[0],r[1],r[2])}return t.apply(e,r)}(t,this,a)}}(t,e,Xt),t+"")}var Ur,zr=(Ur=function(t,e,r){Pr(t,e,r)},Lr((function(t,e){var r=-1,n=e.length,o=n>1?e[n-1]:void 0,i=n>2?e[2]:void 0;for(o=Ur.length>3&&"function"==typeof o?(n--,o):void 0,i&&function(t,e,r){if(!$(r))return!1;var n=typeof e;return!!("number"==n?Jt(r)&&Dt(e,r.length):"string"==n&&e in r)&&G(r[e],t)}(e[0],e[1],i)&&(o=n<3?void 0:o,n=1),t=Object(t);++r<n;){var u=e[r];u&&Ur(t,u,r,o)}return t})));var Mr=Ve("length"),Cr=RegExp("[\\u200d\\ud800-\\udfff\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff\\ufe0e\\ufe0f]");var Rr="\\ud800-\\udfff",Tr="["+Rr+"]",qr="[\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff]",Wr="\\ud83c[\\udffb-\\udfff]",Kr="[^"+Rr+"]",Vr="(?:\\ud83c[\\udde6-\\uddff]){2}",Gr="[\\ud800-\\udbff][\\udc00-\\udfff]",Jr="(?:"+qr+"|"+Wr+")"+"?",Zr="[\\ufe0e\\ufe0f]?",Qr=Zr+Jr+("(?:\\u200d(?:"+[Kr,Vr,Gr].join("|")+")"+Zr+Jr+")*"),Hr="(?:"+[Kr+qr+"?",qr,Vr,Gr,Tr].join("|")+")",Xr=RegExp(Wr+"(?="+Wr+")|"+Hr+Qr,"g");function Yr(t){return function(t){return Cr.test(t)}(t)?function(t){for(var e=Xr.lastIndex=0;Xr.test(t);)++e;return e}(t):Mr(t)}function tn(t){if(null==t)return 0;if(Jt(t))return"string"==typeof(e=t)||!f(e)&&O(e)&&"[object String]"==_(e)?Yr(t):t.length;var e,r=Fe(t);return"[object Map]"==r||"[object Set]"==r?t.size:Gt(t).length}var en=Object.getOwnPropertySymbols?function(t){for(var e=[];t;)se(e,ve(t)),t=yr(t);return e}:he,rn=en;function nn(t){return fe(t,Sr,rn)}var on=Object.prototype.hasOwnProperty;var un=/\w*$/;var an=d?d.prototype:void 0,cn=an?an.valueOf:void 0;function ln(t,e,r){var n,o=t.constructor;switch(e){case"[object ArrayBuffer]":return cr(t);case"[object Boolean]":case"[object Date]":return new o(+t);case"[object DataView]":return function(t,e){var r=e?cr(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.byteLength)}(t,r);case"[object Float32Array]":case"[object Float64Array]":case"[object Int8Array]":case"[object Int16Array]":case"[object Int32Array]":case"[object Uint8Array]":case"[object Uint8ClampedArray]":case"[object Uint16Array]":case"[object Uint32Array]":return lr(t,r);case"[object Map]":case"[object Set]":return new o;case"[object Number]":case"[object String]":return new o(t);case"[object RegExp]":return function(t){var e=new t.constructor(t.source,un.exec(t));return e.lastIndex=t.lastIndex,e}(t);case"[object Symbol]":return n=t,cn?Object(cn.call(n)):{}}}var sn=Ut&&Ut.isMap,fn=sn?Nt(sn):function(t){return O(t)&&"[object Map]"==Fe(t)};var pn=Ut&&Ut.isSet,hn=pn?Nt(pn):function(t){return O(t)&&"[object Set]"==Fe(t)},yn="[object Arguments]",dn="[object Function]",vn="[object Object]",bn={};function gn(t,e,r,n,o,i){var u,a=1&e,c=2&e,l=4&e;if(r&&(u=o?r(t,n,o,i):r(t)),void 0!==u)return u;if(!$(t))return t;var s=f(t);if(s){if(u=function(t){var e=t.length,r=new t.constructor(e);return e&&"string"==typeof t[0]&&on.call(t,"index")&&(r.index=t.index,r.input=t.input),r}(t),!a)return sr(t,u)}else{var p=Fe(t),h=p==dn||"[object GeneratorFunction]"==p;if($t(t))return ar(t,a);if(p==vn||p==yn||h&&!o){if(u=c||h?{}:dr(t),!a)return c?function(t,e){return xr(t,rn(t),e)}(t,function(t,e){return t&&xr(e,Sr(e),t)}(u,t)):function(t,e){return xr(t,ve(t),e)}(t,function(t,e){return t&&xr(e,Zt(e),t)}(u,t))}else{if(!bn[p])return o?t:{};u=ln(t,p,a)}}i||(i=new te);var y=i.get(t);if(y)return y;i.set(t,u),hn(t)?t.forEach((function(n){u.add(gn(n,e,r,n,t,i))})):fn(t)&&t.forEach((function(n,o){u.set(o,gn(n,e,r,o,t,i))}));var d=s?void 0:(l?c?nn:be:c?Sr:Zt)(t);return vt(d||t,(function(n,o){d&&(n=t[o=n]),Or(u,o,gn(n,e,r,o,t,i))})),u}bn[yn]=bn["[object Array]"]=bn["[object ArrayBuffer]"]=bn["[object DataView]"]=bn["[object Boolean]"]=bn["[object Date]"]=bn["[object Float32Array]"]=bn["[object Float64Array]"]=bn["[object Int8Array]"]=bn["[object Int16Array]"]=bn["[object Int32Array]"]=bn["[object Map]"]=bn["[object Number]"]=bn[vn]=bn["[object RegExp]"]=bn["[object Set]"]=bn["[object String]"]=bn["[object Symbol]"]=bn["[object Uint8Array]"]=bn["[object Uint8ClampedArray]"]=bn["[object Uint16Array]"]=bn["[object Uint32Array]"]=!0,bn["[object Error]"]=bn[dn]=bn["[object WeakMap]"]=!1;function jn(t){return gn(t,5)}function mn(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var wn={exports:{}};!function(t){var e=Object.prototype.hasOwnProperty,r="~";function n(){}function o(t,e,r){this.fn=t,this.context=e,this.once=r||!1}function i(t,e,n,i,u){if("function"!=typeof n)throw new TypeError("The listener must be a function");var a=new o(n,i||t,u),c=r?r+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 n:delete t._events[e]}function a(){this._events=new n,this._eventsCount=0}Object.create&&(n.prototype=Object.create(null),(new n).__proto__||(r=!1)),a.prototype.eventNames=function(){var t,n,o=[];if(0===this._eventsCount)return o;for(n in t=this._events)e.call(t,n)&&o.push(r?n.slice(1):n);return Object.getOwnPropertySymbols?o.concat(Object.getOwnPropertySymbols(t)):o},a.prototype.listeners=function(t){var e=r?r+t:t,n=this._events[e];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,i=n.length,u=new Array(i);o<i;o++)u[o]=n[o].fn;return u},a.prototype.listenerCount=function(t){var e=r?r+t:t,n=this._events[e];return n?n.fn?1:n.length:0},a.prototype.emit=function(t,e,n,o,i,u){var a=r?r+t:t;if(!this._events[a])return!1;var c,l,s=this._events[a],f=arguments.length;if(s.fn){switch(s.once&&this.removeListener(t,s.fn,void 0,!0),f){case 1:return s.fn.call(s.context),!0;case 2:return s.fn.call(s.context,e),!0;case 3:return s.fn.call(s.context,e,n),!0;case 4:return s.fn.call(s.context,e,n,o),!0;case 5:return s.fn.call(s.context,e,n,o,i),!0;case 6:return s.fn.call(s.context,e,n,o,i,u),!0}for(l=1,c=new Array(f-1);l<f;l++)c[l-1]=arguments[l];s.fn.apply(s.context,c)}else{var p,h=s.length;for(l=0;l<h;l++)switch(s[l].once&&this.removeListener(t,s[l].fn,void 0,!0),f){case 1:s[l].fn.call(s[l].context);break;case 2:s[l].fn.call(s[l].context,e);break;case 3:s[l].fn.call(s[l].context,e,n);break;case 4:s[l].fn.call(s[l].context,e,n,o);break;default:if(!c)for(p=1,c=new Array(f-1);p<f;p++)c[p-1]=arguments[p];s[l].fn.apply(s[l].context,c)}}return!0},a.prototype.on=function(t,e,r){return i(this,t,e,r,!1)},a.prototype.once=function(t,e,r){return i(this,t,e,r,!0)},a.prototype.removeListener=function(t,e,n,o){var i=r?r+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||n&&a.context!==n||u(this,i);else{for(var c=0,l=[],s=a.length;c<s;c++)(a[c].fn!==e||o&&!a[c].once||n&&a[c].context!==n)&&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=r?r+t:t,this._events[e]&&u(this,e)):(this._events=new n,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=r,a.EventEmitter=a,t.exports=a}(wn);var _n=mn(wn.exports);const On=[];for(let t=0;t<256;++t)On.push((t+256).toString(16).slice(1));const xn=new Uint8Array(16);function kn(){return crypto.getRandomValues(xn)}const An={};function Sn(t,e,r){let n;if(t)n=$n(t.random??t.rng?.()??kn(),t.msecs,t.seq,e,r);else{const t=Date.now(),o=kn();!function(t,e,r){t.msecs??=-1/0,t.seq??=0,e>t.msecs?(t.seq=Pn(r),t.msecs=e):(t.seq=t.seq+1|0,0===t.seq&&t.msecs++)}(An,t,o),n=$n(o,An.msecs,An.seq,e,r)}return e??function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return(On[t[e+0]]+On[t[e+1]]+On[t[e+2]]+On[t[e+3]]+"-"+On[t[e+4]]+On[t[e+5]]+"-"+On[t[e+6]]+On[t[e+7]]+"-"+On[t[e+8]]+On[t[e+9]]+"-"+On[t[e+10]]+On[t[e+11]]+On[t[e+12]]+On[t[e+13]]+On[t[e+14]]+On[t[e+15]]).toLowerCase()}(n)}function $n(t,e,r,n){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(n){if(o<0||o+16>n.length)throw new RangeError(`UUID byte range ${o}:${o+15} is out of buffer bounds`)}else n=new Uint8Array(16),o=0;return e??=Date.now(),r??=Pn(t),n[o++]=e/1099511627776&255,n[o++]=e/4294967296&255,n[o++]=e/16777216&255,n[o++]=e/65536&255,n[o++]=e/256&255,n[o++]=255&e,n[o++]=112|r>>>28&15,n[o++]=r>>>20&255,n[o++]=128|r>>>14&63,n[o++]=r>>>6&255,n[o++]=r<<2&255|3&t[10],n[o++]=t[11],n[o++]=t[12],n[o++]=t[13],n[o++]=t[14],n[o++]=t[15],n}function Pn(t){return(127&t[6])<<24|t[7]<<16|t[8]<<8|t[9]}var Dn=/\s/;var In=/^\s+/;function En(t){return t?t.slice(0,function(t){for(var e=t.length;e--&&Dn.test(t.charAt(e)););return e}(t)+1).replace(In,""):t}var Nn=/^[-+]0x[0-9a-f]+$/i,Fn=/^0b[01]+$/i,Bn=/^0o[0-7]+$/i,Ln=parseInt;var Un=1/0;function zn(t){return t?(t=function(t){if("number"==typeof t)return t;if(x(t))return NaN;if($(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=$(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=En(t);var r=Fn.test(t);return r||Bn.test(t)?Ln(t.slice(2),r?2:8):Nn.test(t)?NaN:+t}(t))===Un||t===-1/0?17976931348623157e292*(t<0?-1:1):t==t?t:0:0===t?t:0}function Mn(t,e,r){var n=null==t?0:t.length;return n?(e=r||void 0===e?1:function(t){var e=zn(t),r=e%1;return e==e?r?e-r:e:0}(e),function(t,e,r){var n=-1,o=t.length;e<0&&(e=-e>o?0:o+e),(r=r>o?o:r)<0&&(r+=o),o=e>r?0:r-e>>>0,e>>>=0;for(var i=Array(o);++n<o;)i[n]=t[n+e];return i}(t,e<0?0:e,n)):[]}function Cn(t){return P(t)}function Rn(t){try{t instanceof Promise&&Promise.prototype.then.call(t,void 0,(()=>{}))}catch(t){}}function Tn(t){return"[object Array]"===Object.prototype.toString.call(t)}function qn(t){return"[object Object]"===Object.prototype.toString.call(t)}function Wn(t,e){let r=function(){let t,e,r=new Promise((function(){t=arguments[0],e=arguments[1]}));return r.resolve=t,r.reject=e,r}(),n=!1;try{let e=function(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],r=[],n=!1;try{if(Array.isArray(t)){let e=t.length;r.length=e;for(let n=0;n<e;n++)n in t&&(r[n]=t[n])}else{if(e||!qn(t)&&!Tn(t))return null;{n=!0;let e=Object.keys(t);for(let n=0;n<e.length;n++)r.push({k:e[n],v:t[e[n]]})}}}catch(t){throw r.forEach((t=>{Rn(n?t.v:t)})),t}return{items:r,useObj:n}}(t);if(null===e)return r.reject("rs is not an array or object"),r;t=e.items,n=e.useObj}catch(t){return r.reject(t),r}Cn(e)||(Yt(t,(t=>{Rn(n?t.v:t)})),e=function(t){return t});let o=Cn(e),i=-1,u=[];return t.reduce((function(t,r){return t.then((function(t){u.push(t),i+=1;let a=i,c=r;return n&&(a=r.k,c=r.v),o?e(c,a):c}))}),Promise.resolve()).then((function(t){u.push(t),u=Mn(u),r.resolve(u)})).catch((function(t){r.reject(t)})),r}function Kn(t){return!0===(e=t)||!1===e||O(e)&&"[object Boolean]"==_(e);var e}function Vn(t){return"[object String]"===Object.prototype.toString.call(t)}function Gn(t){return!!(Vn(t)&&t.length>0)}function Jn(t){if(qn(t)){for(let e in t)return!0;return!1}return!1}function Zn(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 Qn(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(qn(t)){for(let e in t)return!1;return!0}return!1}(t)||(!!function(t){return!(!Vn(t)||0!==t.length)}(t)||(!!function(t){return!!Tn(t)&&0===t.length}(t)||!!Zn(t)))))}function Hn(t){return!!Tn(t)&&(0!==t.length&&(1!==t.length||!Qn(t[0])))}function Xn(t){let e=!1;if(Gn(t)){if(""===t.trim())return!1;e=!isNaN(Number(t))}else if(function(t){return"[object Number]"===Object.prototype.toString.call(t)}(t)){if(Zn(t))return!1;e=!0}return e}function Yn(t,e){return!!qn(t)&&(!(!Gn(e)&&!Xn(e))&&e in t)}let to={maxDepth:32,maxList:1e3,maxIn:1e4,maxNodes:1e5,maxKey:128},eo=Reflect.ownKeys,ro=Object.getOwnPropertyDescriptor,no=Object.getPrototypeOf,oo=Object.defineProperty,io=Object.create,uo=Array.isArray,ao=Number.isInteger,co=Number.isFinite,lo=Number.isNaN,so=Number.isSafeInteger,fo=Object.prototype,po=Date,ho=Function.prototype.call,yo=ho.bind(Object.prototype.hasOwnProperty),vo=ho.bind(Object.prototype.toString),bo=ho.bind(Date.prototype.getTime),go=ho.bind(WeakSet.prototype.add),jo=ho.bind(WeakSet.prototype.has),mo=yo(String.prototype,"isWellFormed")?ho.bind(String.prototype.isWellFormed):null,wo=ho.bind(String.prototype.indexOf),_o=ho.bind(String.prototype.charCodeAt),Oo=ho.bind(String.prototype.slice),xo=ho.bind(RegExp.prototype.exec),ko=String,Ao=ho.bind(ro(no(Uint8Array.prototype),Symbol.toStringTag).get),So={},$o=()=>{},Po=ho.bind(Map.prototype.has),Do=ho.bind(Set.prototype.has),Io=ho.bind(WeakMap.prototype.has),Eo=ho.bind(ro(ArrayBuffer.prototype,"byteLength").get),No=ho.bind(ro(DataView.prototype,"byteLength").get),Fo=ho.bind(Symbol.prototype.valueOf),Bo=ho.bind(Promise.prototype.then),Lo=[t=>Po(t,0),t=>Do(t,0),t=>Io(t,So),t=>jo(t,So),t=>Eo(t),t=>No(t),t=>Fo(t),t=>Bo(t,$o,$o)];if("function"==typeof SharedArrayBuffer){let t=ho.bind(ro(SharedArrayBuffer.prototype,"byteLength").get);Lo[Lo.length]=e=>t(e)}if("function"==typeof WeakRef){let t=ho.bind(WeakRef.prototype.deref);Lo[Lo.length]=e=>t(e)}if("function"==typeof BigInt){let t=ho.bind(BigInt.prototype.valueOf);Lo[Lo.length]=e=>t(e)}let Uo="condition must be a plain object",zo="symbol key is not allowed",Mo="non-enumerable property is not allowed",Co="non-enumerable element is not allowed",Ro="accessor property is not allowed",To="accessor element is not allowed",qo="undefined is not allowed",Wo="null is not allowed here",Ko="unsupported value type",Vo="number is not finite",Go="invalid Date",Jo="string contains NUL",Zo="string contains lone surrogate",Qo="array value is not supported, use $in",Ho="empty operator object",Xo="empty condition",Yo="$nin with empty array is always true",ti="value must be an array",ei="invalid array length",ri="array carries extra properties",ni="nesting is too deep",oi="condition is too large",ii="an exception was thrown while reading the condition",ui=/^[\p{L}_][\p{L}\p{M}\p{N}_]*$/u,ai=/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:^|[^\uD800-\uDBFF])[\uDC00-\uDFFF]/,ci=/[\p{Cc}\p{Cf}\p{Zl}\p{Zp}\p{Co}\p{Cs}[\]]/u,li=/^\[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)\]$/,si=new WeakSet,fi=t=>{let e={reason:t};throw go(si,e),e},pi=(t,e)=>{let r=t.length>e?`${Oo(t,0,e)}...`:t,n="";for(let t=0;t<r.length;t++){let e=r[t],o=_o(r,t);if(o>=55296&&o<=56319&&t+1<r.length){let n=_o(r,t+1);n>=56320&&n<=57343&&(e+=r[t+1],t++)}n+=null===xo(ci,e)?e:"?"}return n},hi=t=>{if(null===t)return"null";let e=typeof t;if("object"!==e)return e;if(uo(t))return"array";let r=xo(li,vo(t));return r?r[1]:"object"},yi=t=>null===t?"find":yi(t.up)+("number"==typeof t.k?`[${t.k}]`:`.${pi(t.k,30)}`),di=t=>{t.nodes+=1,t.nodes>t.maxNodes&&fi(oi)},vi=(t,e,r)=>{oo(t,e,{__proto__:null,value:r,enumerable:!0,writable:!0,configurable:!0})},bi=t=>{try{return bo(t)}catch(t){return}},gi=t=>{if(null===t||"object"!=typeof t||uo(t))return!1;let e=no(t);return(e===fo||null===e)&&("[object Object]"===vo(t)&&void 0===Ao(t))},ji=(t,e)=>{"string"!=typeof e&&fi(zo);let r=ro(t,e);return void 0!==r&&r.enumerable||fi(Mo),yo(r,"value")||fi(Ro),r.value},mi=t=>{let e=t.length;return("number"!=typeof e||!ao(e)||e<0)&&fi(ei),e},wi=(t,e,r)=>{let n=ro(e,r);return void 0===n&&fi(`sparse array hole at index ${r}`),n.enumerable||(t.path={up:t.path,k:r},fi(Co)),yo(n,"value")||(t.path={up:t.path,k:r},fi(To)),n.value},_i=(t,e)=>{let r=eo(t),n=r.length;n>e+1&&fi(ri);for(let t=0;t<n;t++){let n=r[t];if("string"!=typeof n&&fi(ri),"length"===n)continue;let o=+n;ao(o)&&o>=0&&o<e&&ko(o)===n||fi(ri)}},Oi=t=>(lo(t)&&fi(Go),new po(t)),xi=(t,e,r)=>{if(di(t),null===e)return r||fi(Wo),null;switch(typeof e){case"string":return-1!==wo(n=e,"\0")&&fi(Jo),(null!==mo?mo(n):null===xo(ai,n))||fi(Zo),e;case"number":return co(e)||fi(Vo),e;case"boolean":return e;case"undefined":return fi(qo);case"object":{let t=bi(e);return void 0!==t?Oi(t):fi(`${Ko} [${hi(e)}]`)}default:return fi(`${Ko} [${hi(e)}]`)}var n},ki=(t,e)=>{36===_o(e,0)&&fi(`unsupported operator [${pi(e,30)}]`),e.length>t.maxKey&&fi(`column name is too long (> ${t.maxKey})`),null!==xo(ui,e)&&"__proto__"!==e||fi(`unsupported column name [${pi(e,30)}]`)},Ai=(t,e,r)=>{uo(r)||fi(ti);let n=mi(r);n>t.maxIn&&fi(`array is too large (> ${t.maxIn})`),0===n&&"$nin"===e&&fi(Yo);let o=[];for(let e=0;e<n;e++){let n=wi(t,r,e);t.path={up:t.path,k:e},vi(o,e,xi(t,n,!1)),t.path=t.path.up}return _i(r,n),o},Si=(t,e)=>{if(null===e)return di(t),null;if("object"==typeof e){let r=bi(e);return void 0!==r?(di(t),Oi(r)):(uo(e)&&fi(Qo),((t,e)=>{gi(e)||fi(`${Ko} [${hi(e)}]`),di(t);let r=eo(e),n=r.length;0===n&&fi(Ho);let o=io(null);for(let i=0;i<n;i++){let n=r[i],u=ji(e,n);switch(t.path={up:t.path,k:n},n){case"$eq":case"$ne":vi(o,n,xi(t,u,!0));break;case"$gt":case"$gte":case"$lt":case"$lte":vi(o,n,xi(t,u,!1));break;case"$in":case"$nin":vi(o,n,Ai(t,n,u));break;default:36===_o(n,0)&&fi(`unsupported operator [${pi(n,30)}]`),fi(`unexpected key [${pi(n,30)}] in operator object (nested conditions are not supported)`)}t.path=t.path.up}return o})(t,e))}return xi(t,e,!0)},$i=(t,e,r,n)=>{uo(r)||fi(ti);let o=mi(r);0===o&&fi(`${e} with empty array`),o>t.maxList&&fi(`array is too large (> ${t.maxList})`);let i=[];for(let e=0;e<o;e++){let o=wi(t,r,e);t.path={up:t.path,k:e},vi(i,e,Pi(t,o,n,!1)),t.path=t.path.up}return _i(r,o),i},Pi=(t,e,r,n)=>{r>t.maxDepth&&fi(ni),gi(e)||fi(`${Uo}, got [${hi(e)}]`),di(t);let o=eo(e),i=o.length;if(0===i){if(n)return(t=>{for(let e=0;e<Lo.length;e++)try{return Lo[e](t),!0}catch(t){}return!1})(e)&&fi(`${Uo}, got [object]`),io(null);fi(Xo)}let u=io(null);for(let n=0;n<i;n++){let i=o[n],a=ji(e,i);t.path={up:t.path,k:i},"$and"===i||"$or"===i?vi(u,i,$i(t,i,a,r+1)):(ki(t,i),vi(u,i,Si(t,a))),t.path=t.path.up}return u};function Di(t,e){let r=(t=>{let e,r={maxDepth:to.maxDepth,maxList:to.maxList,maxIn:to.maxIn,maxNodes:to.maxNodes,maxKey:to.maxKey};if(null==t)return r;if("object"!=typeof t)throw new Error("invalid opt: opt must be an object");try{e=eo(t)}catch(t){throw new Error("invalid opt: can not read opt")}for(let t=0;t<e.length;t++){let n=e[t];if("string"!=typeof n||!yo(r,n))throw new Error(`invalid opt: unknown option [${"string"==typeof n?pi(n,30):"symbol"}]`)}let n=["maxDepth","maxList","maxIn","maxNodes","maxKey"];for(let e=0;e<n.length;e++){let o,i=n[e];try{o=ro(t,i)}catch(t){throw new Error(`invalid opt: can not read option [${i}]`)}if(void 0===o)continue;if(!yo(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||!so(u)||u<1)throw new Error(`invalid opt: ${i} must be a positive integer`);r[i]=u<to[i]?u:to[i]}}return r})(e),n={nodes:0,path:null,maxDepth:r.maxDepth,maxList:r.maxList,maxIn:r.maxIn,maxNodes:r.maxNodes,maxKey:r.maxKey};try{return void 0===t?io(null):Pi(n,t,0,!0)}catch(t){let e=jo(si,t)?t.reason:ii;throw new Error(`invalid find: ${e} at [${(t=>{let e=yi(t);return e.length>120?`...${Oo(e,-100)}`:e})(n.path)}]`)}}let Ii={};return function(){let r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},n=null,o=dt(r,"url");Gn(o)||(o="./db.json");let i=dt(r,"db");Gn(i)||(i="worm");let a=dt(r,"cl");Gn(a)||(a="test");let c=dt(r,"useCache");Kn(c)||(c=!1);let l=dt(r,"autoGenPk");Kn(l)||(l=!0);let f=`${i}:${a}`,p=new s(o),h=new e.Low(p,{}),y=new _n,d=t.resolve(o);Yn(Ii,d)||(Ii[d]=Promise.resolve());let v=t=>{let e=Ii[d].then((()=>t()));return Ii[d]=e.catch((()=>{})),e},b=t=>{if(t instanceof Date)return t.toISOString();if(null!==t&&"object"==typeof t)for(let e of Object.keys(t))t[e]=b(t[e]);return t},g=t=>{for(let e of Object.keys(t))if("$and"===e||"$or"===e){for(let r of t[e])if(g(r))return!0}else if(e in Object.prototype)return!0;return!1},j=t=>{let e=new u.Query(t);return g(t)?t=>e.test(null!==t&&"object"==typeof t?Object.assign(Object.create(null),t):t):t=>e.test(t)},m=(t,e)=>{try{return{fc:b(Di(e))}}catch(e){return _(t,null,e),{err:e}}},w=(t,e,r)=>{try{y.emit("change",t,e,r)}catch(t){console.log(t)}},_=(t,e,r)=>{try{y.emit("error",t,e,O(r))}catch(t){console.log(t)}},O=t=>{let e=dt(t,"message");return Gn(e)?e:String(t)},x=(t,e)=>l?Qe(t,(function(t){return Gn(t.id)||(t.id=Sn()),t})):(Yt(t,(function(t,r){if(!Gn(dt(t,"id")))throw new Error(`can not ${e} by data[${r}] without valid id when autoGenPk is false`)})),t),k=async()=>(await h.read(),Yn(h.data,f)||(h.data[f]=[]),h.data[f]),A=async(t,e)=>{h.data[f]=e;try{await h.write()}catch(e){throw h.data[f]=t,e}},S=t=>{let e={};return Yt(t,((t,r)=>{let n=dt(t,"id");Gn(n)&&(e[n]={k:r,v:t})})),e},$=async()=>{if(c&&Tn(n))return jn(n);let t=await k();return t=jn(t),c?(n=t,jn(t)):t};async function P(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=!1;if(!Jn(t)&&!Hn(t))return[];t=jn(t);let o=dt(e,"autoInsert",!0),i=null;try{Tn(t)||(t=[t]),t=x(t,"save");let e=await k(),r=[...e],n=S(r),u=!1;i=await Wn(t,(async t=>{let e=null;try{let i=dt(n,t.id,null);if(Jn(i)){let o=i.v,a=zr({},o,t);Ce(a,o)?e={n:1,nInserted:0,nModified:0,ok:1}:(r[i.k]=a,n[t.id]={k:i.k,v:a},u=!0,e={n:1,nInserted:0,nModified:1,ok:1})}else if(o){let o=tn(r);r.push(t),n[t.id]={k:o,v:t},u=!0,e={n:1,nInserted:1,nModified:0,ok:1}}else e={n:0,nInserted:0,nModified:0,ok:1}}catch(t){e={n:1,nInserted:0,nModified:0,ok:0,err:O(t)}}return e})),u&&await A(e,r)}catch(t){r=!0,i=t}return n=null,r||(Yt(i,((e,r)=>{0===dt(e,"ok")&&_("save",[dt(t,r)],dt(e,"err"))})),Yt(i,((e,r)=>{1===dt(e,"nInserted")&&w("insert",[dt(t,r)],e)})),w("save",t,i)),r?(_("save",t,i),Promise.reject(i)):i}return y.select=async function(){let t=m("select",arguments.length>0&&void 0!==arguments[0]?arguments[0]:{});return t.err?Promise.reject(t.err):v((()=>async function(t){let e=!1,r=null;try{let n=await $();r=Reflect.ownKeys(t).length>0?n.filter(j(t)):n,Tn(r)||(e=!0,r=new Error(`can not select by find[${JSON.stringify(t)}]`))}catch(t){e=!0,r=t}return e?(_("select",null,r),Promise.reject(r)):r}(t.fc)))},y.selectByPk=async function(t){return v((()=>async function(t){let e=!1,r=null;try{if(!Gn(t))return null;let e=await $(),n=dt(S(e),t,null);r=Jn(n)?n.v:null}catch(t){e=!0,r=t}return e?(_("selectByPk",null,r),Promise.reject(r)):r}(t)))},y.insert=async function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return v((()=>async function(t){let e=!1,r=dt(arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},"returnList");if(Kn(r)||(r=!1),!Jn(t)&&!Hn(t))return r?[]:{n:0,nInserted:0,ok:1};t=jn(t);let o=null;try{Tn(t)||(t=[t]),t=x(t,"insert");let e=await k(),n=S(e),i=tn(t),u=[],a=[];Yt(t,(t=>{Yn(n,t.id)?u.push(!1):(a.push(t),n[t.id]={k:-1,v:t},u.push(!0))})),tn(a)>0&&await A(e,[...e,...a]),o=r?Qe(u,(function(t){return{n:1,nInserted:t?1:0,ok:1}})):{n:i,nInserted:tn(a),ok:1}}catch(t){e=!0,o=t}return n=null,e||w("insert",t,o),e?(_("insert",t,o),Promise.reject(o)):o}(t,e)))},y.insertBulk=async function(t){return v((()=>async function(t){let e=!1;if(!Jn(t)&&!Hn(t))return{n:0,nInserted:0,ok:1};t=jn(t);let r=null;try{Tn(t)||(t=[t]),t=x(t,"insertBulk");let e=await k(),n=S(e),o=tn(t),i=null;if(Yt(t,(t=>{if(Yn(n,t.id))return i=t.id,!1;n[t.id]={k:-1,v:t}})),null!==i)throw new Error(`can not insertBulk by existed id[${i}]`);await A(e,[...e,...t]),r={n:o,nInserted:o,ok:1}}catch(t){e=!0,r=t}return n=null,e||w("insertBulk",t,r),e?(_("insertBulk",t,r),Promise.reject(r)):r}(t)))},y.save=async function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return v((()=>P(t,e)))},y.del=async function(t){return v((()=>async function(t){let e=!1;if(!Jn(t)&&!Hn(t))return[];t=jn(t);let r=null;try{Tn(t)||(t=[t]);let e=await k(),n=S(e),o={},i=!1;if(r=await Wn(t,(async t=>{let e=null;try{let r=dt(t,"id","");if(Gn(r)){let t=dt(n,r,null);Jn(t)?(o[t.k]=!0,delete n[r],i=!0,e={n:1,nDeleted:1,ok:1}):e={n:0,nDeleted:0,ok:1}}else e={n:0,nDeleted:0,ok:0,err:`can not delete by invalid id[${r}]`}}catch(t){e={n:1,nDeleted:0,ok:0,err:O(t)}}return e})),i){let t=Xe(e,((t,e)=>!Yn(o,e)));await A(e,t)}}catch(t){e=!0,r=t}return n=null,e||(Yt(r,((e,r)=>{0===dt(e,"ok")&&_("del",[dt(t,r)],dt(e,"err"))})),w("del",t,r)),e?(_("del",t,r),Promise.reject(r)):r}(t)))},y.delAll=async function(){let t=m("delAll",arguments.length>0&&void 0!==arguments[0]?arguments[0]:{});return t.err?Promise.reject(t.err):v((()=>async function(t){let e=!1,r=null;try{let e=await k(),n=tn(e),o=0,i=null;if(Reflect.ownKeys(t).length>0){let r=j(t);i=Xe(e,(t=>!r(t))),o=n-tn(i)}else o=n,i=[];o>0&&await A(e,i),r={n:o,nDeleted:o,ok:1}}catch(t){e=!0,r=t}return n=null,e||w("delAll",null,r),e?(_("delAll",null,r),Promise.reject(r)):r}(t.fc)))},y}}));
7
7
  //# sourceMappingURL=w-orm-lowdb.umd.js.map