w-orm-lowdb 1.0.32 → 1.0.33

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
@@ -40,15 +40,18 @@ An operator for lowdb in nodejs.
40
40
  接受:
41
41
 
42
42
  - 未給、`undefined`、`{}`:全部數據。`delAll()` 不給條件即刪除全部,須審慎使用、非必要不用;可先以 `select(find)` 確認 `delAll(find)` 之命中範圍(`useCache` 開啟且他行程已寫入時,`select` 可能回傳快取而與 `delAll` 直讀資料庫所見不同)。
43
- - 欄位等值 `{ 欄: 純量 }`,多欄為 AND。純量為字串(不含 NUL 字元與孤立代理字元)、有限數字、布林、有效 `Date`;`null` 僅可用於欄位等值、`$eq`、`$ne`。
43
+ - 欄位等值 `{ 欄: 純量 }`,多欄為 AND。純量為字串(不含 NUL 字元與孤立代理字元)、有限數字、布林、有效 `Date`(年份須介於 0000–9999,範圍外 reject,見下方 Date 節);`null` 僅可用於欄位等值、`$eq`、`$ne`。
44
44
  - 欄位運算子 `$eq $ne $gt $gte $lt $lte`(值為純量)與 `$in $nin`(值為純量陣列;`$in: []` 恆假、不命中任何數據,`$nin: []` reject)。同欄多個運算子為 AND。
45
45
  - 文件層 `$and`、`$or`:值為條件物件之非空陣列,可巢狀。
46
46
  - 欄名須符合 `^[\p{L}_][\p{L}\p{M}\p{N}_]*$`,長度不超過 128,且不為 `__proto__`;`'o.k'` 之點路徑不是欄名。
47
47
  - 上限:巢狀深度 32、`$and`/`$or` 項數 1000、`$in`/`$nin` 項數 10000、節點總數 100000。
48
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 鍵、存取器、不可列舉鍵、稀疏陣列。
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`、年份小於 0 或大於 9999 之 `Date`(如 `new Date(8.64e15)`)、`BigInt`、函數、`Symbol`、`RegExp` 之值;陣列值或巢狀物件之等值;`$nin: []`、`$and: []`、`$or: []`、`$and`/`$or` 內之 `{}`、`{ 欄: {} }`;`$gt $gte $lt $lte $in $nin` 內之 `null`;Symbol 鍵、存取器、不可列舉鍵、稀疏陣列。
50
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: 現在 } }` 會命中哨兵)。
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()` 恆為 24 字元 `YYYY-MM-DDTHH:mm:ss.sssZ`;範圍外輸出 `+yyyyyy-`、`-yyyyyy-` 前綴,字典序與時間序顛倒)。
52
+
53
+ - **條件側 fail-closed**:條件內任何位置(欄位等值、`$eq $ne $gt $gte $lt $lte`、`$in $nin` 之元素、`$and`/`$or` 內)之 `Date` 年份小於 0 或大於 9999(如 `new Date(8.64e15)`、`new Date(-8.64e15)`、`-000001` 年、`+010000` 年),`select` 與 `delAll` 皆整批 reject,訊息為 `invalid find: Date year is out of range 0000-9999 at [<路徑>]`(不回顯值),於讀檔之前 reject,不讀檔、不刪除、不改寫資料庫檔、不發出 `change` 事件。邊界 `0000-01-01T00:00:00.000Z` 與 `9999-12-31T23:59:59.999Z` 接受。此檢核屬本套件轉譯層(共用檢核 `cvOrmFind` 接受一切有效 `Date`)。例如修正前 `delAll({ t: { $gt: new Date(8.64e15) } })`(意為「晚於最大日期」,應無命中)會因字典序顛倒而刪除所有帶日期之數據,現改為 reject。
54
+ - **數據側不處理**:寫入(`insert`、`insertBulk`、`save`)範圍外 `Date` 之行為不變,仍存為 `+yyyyyy-…`、`-yyyyyy-…` 之 ISO 字串;**範圍外 `Date` 之資料無法以 `Date` 條件正確比較**。例如以 `new Date(8.64e15)` 作「永不過期」哨兵時,範圍內之條件 `{ expireAt: { $lt: 現在 } }` 仍會因字典序命中哨兵(`'+275760-…' < '2026-…'`),`delAll` 會將其刪除。此限制是雙向的:既可能誤命中(上例),亦可能漏命中(例如 `{ t: { $gt: new Date('9999-12-31T23:59:59.999Z') } }` 不會命中 `new Date(8.64e15)` 之資料),範圍外 `Date` 之資料彼此間的順序亦不可靠。請勿以範圍外 `Date` 作哨兵,改用範圍內之值(如 `new Date('9999-12-31T23:59:59.999Z')`)或 `null` 表示永不過期(此二者不會被 `{ t: { $lt: 現在 } }` 命中,但仍會被 `$ne`、`$nin` 命中,依條件自行斟酌)。
52
55
 
53
56
  語意為 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
57
 
@@ -59,6 +62,7 @@ Date:本套件以 JSON 存檔,Date 存入後為 ISO 字串(`toISOString()`)
59
62
  - 移除:白名單以外之全部 `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
63
  - 改為 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
64
  - 新行為:條件內之 Date 可命中(原本因數據為 ISO 字串而條件為 Date,`$eq`、`$gt`、`$gte`、`$lt`、`$lte`、`$in` 恆不命中,`$ne`、`$nin` 恆命中,`delAll` 因而可能刪除全部);Date 範圍比較之限制見上。
65
+ - 改為 reject(Date 範圍):條件內任何位置之 `Date` 年份小於 0 或大於 9999(如 `new Date(8.64e15)`),原本轉為帶正負號之 ISO 字串後以字典序比較,結果與時間序顛倒(`$gt` 哨兵命中所有帶日期之數據、`$lt` 哨兵恆無命中),現整批 reject;數據側範圍外 `Date` 之寫入行為不變,惟其資料無法以 `Date` 條件正確比較(見上方 Date 節)。
62
66
  - 錯誤訊息為 `invalid find: <原因> at [<路徑>]`;原本由 `mingo` 拋出錯誤者,現統一為此訊息。
63
67
 
64
68
  ## Documentation
@@ -1,7 +1,7 @@
1
1
  /*!
2
- * w-orm-lowdb v1.0.32
2
+ * w-orm-lowdb v1.0.33
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,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}}));
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{#f;#s;#p;constructor(t,e){let{parse:r,stringify:n}=e;this.#f=new c(t),this.#s=r,this.#p=n}async read(){const t=await this.#f.read();return null===t?null:this.#s(t)}write(t){return this.#f.write(this.#p(t))}}class f extends l{constructor(t){super(t,{parse:JSON.parse,stringify:t=>JSON.stringify(t,null,2)})}}var s=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,b=Object.prototype,v=b.hasOwnProperty,g=b.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=v.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 A=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,k=/^\w*$/;function $(t,e){if(s(t))return!1;var r=typeof t;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&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 P(t){if(!S(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 F=Function.prototype.toString;function N(t){if(null!=t){try{return F.call(t)}catch(t){}try{return t+""}catch(t){}}return""}var B=/^\[object .+?Constructor\]$/,L=Function.prototype,z=Object.prototype,M=L.toString,U=z.hasOwnProperty,C=RegExp("^"+M.call(U).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function R(t){return!(!S(t)||(e=t,E&&E in e))&&(P(t)?C:B).test(N(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 W=T(Object,"create");var q=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__=W?W(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(W){var r=e[t];return"__lodash_hash_undefined__"===r?void 0:r}return q.call(e,t)?e[t]:void 0},V.prototype.has=function(t){var e=this.__data__;return W?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]=W&&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,ft=lt?lt.toString:void 0;function st(t){if("string"==typeof t)return t;if(s(t))return ct(t,st)+"";if(x(t))return ft?ft.call(t):"";var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}function pt(t,e){return s(t)?t:$(t,e)?[t]:at(function(t){return null==t?"":st(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 bt(t,e){for(var r=-1,n=null==t?0:t.length;++r<n&&!1!==e(t[r],r,t););return t}var vt,gt=function(t,e,r){for(var n=-1,o=Object(t),i=r(t),u=i.length;u--;){var a=i[vt?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 At="object"==typeof exports&&exports&&!exports.nodeType&&exports,kt=At&&"object"==typeof module&&module&&!module.nodeType&&module,$t=kt&&kt.exports===At?y.Buffer:void 0,St=($t?$t.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 Ft(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 Nt="object"==typeof exports&&exports&&!exports.nodeType&&exports,Bt=Nt&&"object"==typeof module&&module&&!module.nodeType&&module,Lt=Bt&&Bt.exports===Nt&&p.process,zt=function(){try{var t=Bt&&Bt.require&&Bt.require("util").types;return t||Lt&&Lt.binding&&Lt.binding("util")}catch(t){}}(),Mt=zt&&zt.isTypedArray,Ut=Mt?Ft(Mt):function(t){return O(t)&&It(t.length)&&!!Et[_(t)]},Ct=Object.prototype.hasOwnProperty;function Rt(t,e){var r=s(t),n=!r&&xt(t),o=!r&&!n&&St(t),i=!r&&!n&&!o&&Ut(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 Wt(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||Tt)}function qt(t,e){return function(r){return t(e(r))}}var Kt=qt(Object.keys,Object),Vt=Object.prototype.hasOwnProperty;function Gt(t){if(!Wt(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(s(t)?bt: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),f=i.get(e);if(l&&f)return l==e&&f==t;var s=-1,p=!0,h=2&r?new ee:void 0;for(i.set(t,e),i.set(e,t);++s<a;){var y=t[s],d=e[s];if(n)var b=u?n(d,y,s,e,t,i):n(y,d,s,t,e,i);if(void 0!==b){if(b)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 fe(t,e){for(var r=-1,n=e.length,o=t.length;++r<n;)t[o+r]=e[r];return t}function se(t,e,r){var n=e(t);return s(t)?n:fe(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,be=de?function(t){return null==t?[]:(t=Object(t),pe(de(t),(function(e){return ye.call(t,e)})))}:he;function ve(t){return se(t,Zt,be)}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]",Ae="[object Set]",ke="[object WeakMap]",$e="[object DataView]",Se=N(je),Pe=N(H),De=N(me),Ie=N(we),Ee=N(_e),Fe=_;(je&&Fe(new je(new ArrayBuffer(1)))!=$e||H&&Fe(new H)!=Oe||me&&Fe(me.resolve())!=xe||we&&Fe(new we)!=Ae||_e&&Fe(new _e)!=ke)&&(Fe=function(t){var e=_(t),r="[object Object]"==e?t.constructor:void 0,n=r?N(r):"";if(n)switch(n){case Se:return $e;case Pe:return Oe;case De:return xe;case Ie:return Ae;case Ee:return ke}return e});var Ne=Fe,Be="[object Arguments]",Le="[object Array]",ze="[object Object]",Me=Object.prototype.hasOwnProperty;function Ue(t,e,r,n,o,i){var u=s(t),a=s(e),c=u?Le:Ne(t),l=a?Le:Ne(e),f=(c=c==Be?ze:c)==ze,p=(l=l==Be?ze:l)==ze,h=c==l;if(h&&St(t)){if(!St(e))return!1;u=!0,f=!1}if(h&&!f)return i||(i=new te),u||Ut(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 f=oe(a(t),a(e),n,o,i,u);return u.delete(t),f;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=f&&Me.call(t,"__wrapped__"),d=p&&Me.call(e,"__wrapped__");if(y||d){var b=y?t.value():t,v=d?e.value():e;return i||(i=new te),o(b,v,r,n,i)}}return!!h&&(i||(i=new te),function(t,e,r,n,o,i){var u=1&r,a=ve(t),c=a.length;if(c!=ve(e).length&&!u)return!1;for(var l=c;l--;){var f=a[l];if(!(u?f in e:ge.call(e,f)))return!1}var s=i.get(t),p=i.get(e);if(s&&p)return s==e&&p==t;var h=!0;i.set(t,e),i.set(e,t);for(var y=u;++l<c;){var d=t[f=a[l]],b=e[f];if(n)var v=u?n(b,d,f,e,t,i):n(d,b,f,t,e,i);if(!(void 0===v?d===b||o(d,b,r,n,i):v)){h=!1;break}y||(y="constructor"==f)}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:Ue(t,e,r,n,Ce,o))}function Re(t){return t==t&&!S(t)}function Te(t,e){return function(r){return null!=r&&(r[t]===e&&(void 0!==e||t in Object(r)))}}function We(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],f=a[1];if(u&&a[2]){if(void 0===l&&!(c in t))return!1}else{var s=new te;if(n)var p=n(l,f,c,t,e,s);if(!(void 0===p?Ce(f,l,3,n,s):p))return!1}}return!0}(r,t,e)}}function qe(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)&&(s(t)||xt(t))}(t,e,qe)}function Ve(t){return function(e){return null==e?void 0:e[t]}}function Ge(t){return $(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?s(t)?function(t,e){return $(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]):We(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(s(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(s(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 fr(t,e){var r=-1,n=t.length;for(e||(e=Array(n));++r<n;)e[r]=t[r];return e}var sr=Object.create,pr=function(){function t(){}return function(e){if(!S(e))return{};if(sr)return sr(e);t.prototype=e;var r=new t;return t.prototype=void 0,r}}(),hr=pr,yr=qt(Object.getPrototypeOf,Object);function dr(t){return"function"!=typeof t.constructor||Wt(t)?{}:hr(yr(t))}var br=Function.prototype,vr=Object.prototype,gr=br.toString,jr=vr.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 Ar=Object.prototype.hasOwnProperty;function kr(t){if(!S(t))return function(t){var e=[];if(null!=t)for(var r in Object(t))e.push(r);return e}(t);var e=Wt(t),r=[];for(var n in t)("constructor"!=n||!e&&Ar.call(t,n))&&r.push(n);return r}function $r(t){return Jt(t)?Rt(t,!0):kr(t)}function Sr(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 f,p=i?i(a,c,r+"",t,e,u):void 0,h=void 0===p;if(h){var y=s(c),d=!y&&St(c),b=!y&&!d&&Ut(c);p=c,y||d||b?s(a)?p=a:O(f=a)&&Jt(f)?p=fr(a):d?(h=!1,p=ar(c,!0)):b?(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,$r(t))}(a):S(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),S(i))Sr(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)}}),$r)}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,Fr=Date.now;var Nr=function(t){var e=0,r=0;return function(){var n=Fr(),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=Nr;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 zr,Mr=(zr=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=zr.length>3&&"function"==typeof o?(n--,o):void 0,i&&function(t,e,r){if(!S(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&&zr(t,u,r,o)}return t})));var Ur=Ve("length"),Cr=RegExp("[\\u200d\\ud800-\\udfff\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff\\ufe0e\\ufe0f]");var Rr="\\ud800-\\udfff",Tr="["+Rr+"]",Wr="[\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff]",qr="\\ud83c[\\udffb-\\udfff]",Kr="[^"+Rr+"]",Vr="(?:\\ud83c[\\udde6-\\uddff]){2}",Gr="[\\ud800-\\udbff][\\udc00-\\udfff]",Jr="(?:"+Wr+"|"+qr+")"+"?",Zr="[\\ufe0e\\ufe0f]?",Qr=Zr+Jr+("(?:\\u200d(?:"+[Kr,Vr,Gr].join("|")+")"+Zr+Jr+")*"),Hr="(?:"+[Kr+Wr+"?",Wr,Vr,Gr,Tr].join("|")+")",Xr=RegExp(qr+"(?="+qr+")|"+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):Ur(t)}function tn(t){if(null==t)return 0;if(Jt(t))return"string"==typeof(e=t)||!s(e)&&O(e)&&"[object String]"==_(e)?Yr(t):t.length;var e,r=Ne(t);return"[object Map]"==r||"[object Set]"==r?t.size:Gt(t).length}var en=Object.getOwnPropertySymbols?function(t){for(var e=[];t;)fe(e,be(t)),t=yr(t);return e}:he,rn=en;function nn(t){return se(t,$r,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 fn=zt&&zt.isMap,sn=fn?Ft(fn):function(t){return O(t)&&"[object Map]"==Ne(t)};var pn=zt&&zt.isSet,hn=pn?Ft(pn):function(t){return O(t)&&"[object Set]"==Ne(t)},yn="[object Arguments]",dn="[object Function]",bn="[object Object]",vn={};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(!S(t))return t;var f=s(t);if(f){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 fr(t,u)}else{var p=Ne(t),h=p==dn||"[object GeneratorFunction]"==p;if(St(t))return ar(t,a);if(p==bn||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,$r(e),t)}(u,t)):function(t,e){return xr(t,be(t),e)}(t,function(t,e){return t&&xr(e,Zt(e),t)}(u,t))}else{if(!vn[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))})):sn(t)&&t.forEach((function(n,o){u.set(o,gn(n,e,r,o,t,i))}));var d=f?void 0:(l?c?nn:ve:c?$r:Zt)(t);return bt(d||t,(function(n,o){d&&(n=t[o=n]),Or(u,o,gn(n,e,r,o,t,i))})),u}vn[yn]=vn["[object Array]"]=vn["[object ArrayBuffer]"]=vn["[object DataView]"]=vn["[object Boolean]"]=vn["[object Date]"]=vn["[object Float32Array]"]=vn["[object Float64Array]"]=vn["[object Int8Array]"]=vn["[object Int16Array]"]=vn["[object Int32Array]"]=vn["[object Map]"]=vn["[object Number]"]=vn[bn]=vn["[object RegExp]"]=vn["[object Set]"]=vn["[object String]"]=vn["[object Symbol]"]=vn["[object Uint8Array]"]=vn["[object Uint8ClampedArray]"]=vn["[object Uint16Array]"]=vn["[object Uint32Array]"]=!0,vn["[object Error]"]=vn[dn]=vn["[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,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,n),!0;case 4:return f.fn.call(f.context,e,n,o),!0;case 5:return f.fn.call(f.context,e,n,o,i),!0;case 6:return f.fn.call(f.context,e,n,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,h=f.length;for(l=0;l<h;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,n);break;case 4:f[l].fn.call(f[l].context,e,n,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,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=[],f=a.length;c<f;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 An(){return crypto.getRandomValues(xn)}const kn={};function $n(t,e,r){let n;if(t)n=Sn(t.random??t.rng?.()??An(),t.msecs,t.seq,e,r);else{const t=Date.now(),o=An();!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++)}(kn,t,o),n=Sn(o,kn.msecs,kn.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 Sn(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 Fn=/^[-+]0x[0-9a-f]+$/i,Nn=/^0b[01]+$/i,Bn=/^0o[0-7]+$/i,Ln=parseInt;var zn=1/0;function Mn(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=En(t);var r=Nn.test(t);return r||Bn.test(t)?Ln(t.slice(2),r?2:8):Fn.test(t)?NaN:+t}(t))===zn||t===-1/0?17976931348623157e292*(t<0?-1:1):t==t?t:0:0===t?t:0}function Un(t,e,r){var n=null==t?0:t.length;return n?(e=r||void 0===e?1:function(t){var e=Mn(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 Wn(t){return"[object Object]"===Object.prototype.toString.call(t)}function qn(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||!Wn(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=Un(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(Wn(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(Wn(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!!Wn(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=Object.setPrototypeOf,ao=Array.isArray,co=Number.isInteger,lo=Number.isFinite,fo=Number.isNaN,so=Number.isSafeInteger,po=Object.prototype,ho=Date,yo=Function.prototype.call,bo=yo.bind(Object.prototype.hasOwnProperty),vo=yo.bind(Object.prototype.toString),go=yo.bind(Date.prototype.getTime),jo=yo.bind(WeakSet.prototype.add),mo=yo.bind(WeakSet.prototype.has),wo=bo(String.prototype,"isWellFormed")?yo.bind(String.prototype.isWellFormed):null,_o=yo.bind(String.prototype.indexOf),Oo=yo.bind(String.prototype.charCodeAt),xo=yo.bind(String.prototype.slice),Ao=yo.bind(RegExp.prototype.exec),ko=String,$o=yo.bind(ro(no(Uint8Array.prototype),Symbol.toStringTag).get),So={},Po=()=>{},Do=yo.bind(Map.prototype.has),Io=yo.bind(Set.prototype.has),Eo=yo.bind(WeakMap.prototype.has),Fo=yo.bind(ro(ArrayBuffer.prototype,"byteLength").get),No=yo.bind(ro(DataView.prototype,"buffer").get),Bo=yo.bind(Symbol.prototype.valueOf),Lo=yo.bind(Promise.prototype.then),zo=[t=>Do(t,0),t=>Io(t,0),t=>Eo(t,So),t=>mo(t,So),t=>Fo(t),t=>No(t),t=>Bo(t),t=>Lo(t,Po,Po)];if("function"==typeof SharedArrayBuffer){let t=yo.bind(ro(SharedArrayBuffer.prototype,"byteLength").get);zo[zo.length]=e=>t(e)}if("function"==typeof WeakRef){let t=yo.bind(WeakRef.prototype.deref);zo[zo.length]=e=>t(e)}if("function"==typeof FinalizationRegistry){let t=yo.bind(FinalizationRegistry.prototype.unregister);zo[zo.length]=e=>t(e,So)}if("function"==typeof BigInt){let t=yo.bind(BigInt.prototype.valueOf);zo[zo.length]=e=>t(e)}let Mo=null,Uo=null;if("function"==typeof structuredClone)try{let t=structuredClone,e=!1;try{t(new Proxy({},{}))}catch(t){e=!0}let r=t({}),n=no(r);if(e&&"[object Map]"===vo(t(new Map))&&"[object Object]"===vo(r)&&0===eo(r).length&&null!==n&&null===no(n)&&bo(n,"hasOwnProperty")&&no(t({a:1}))===n){let e=!0,r=[()=>new Map,()=>new Set,()=>new WeakMap,()=>new WeakSet,()=>Promise.resolve(0),()=>new ArrayBuffer(1),()=>new DataView(new ArrayBuffer(1)),()=>Object(Symbol("s"))];"function"==typeof SharedArrayBuffer&&(r[r.length]=()=>new SharedArrayBuffer(1)),"function"==typeof WeakRef&&(r[r.length]=()=>new WeakRef(So)),"function"==typeof FinalizationRegistry&&(r[r.length]=()=>new FinalizationRegistry(Po)),"function"==typeof BigInt&&(r[r.length]=()=>Object(BigInt(1)));for(let o=0;o<r.length&&e;o++){let i=uo(r[o](),null);try{no(t(i))===n&&(e=!1)}catch(t){}}e&&(Mo=t,Uo=n)}}catch(t){}let Co="condition must be a plain object",Ro="symbol key is not allowed",To="non-enumerable property is not allowed",Wo="non-enumerable element is not allowed",qo="accessor property is not allowed",Ko="accessor element is not allowed",Vo="undefined is not allowed",Go="null is not allowed here",Jo="unsupported value type",Zo="number is not finite",Qo="invalid Date",Ho="string contains NUL",Xo="string contains lone surrogate",Yo="array value is not supported, use $in",ti="empty operator object",ei="empty condition",ri="$nin with empty array is always true",ni="value must be an array",oi="invalid array length",ii="array carries extra properties",ui="nesting is too deep",ai="condition is too large",ci="an exception was thrown while reading the condition",li="an empty find must be an ordinary object",fi=/^[\p{L}_][\p{L}\p{M}\p{N}_]*$/u,si=/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:^|[^\uD800-\uDBFF])[\uDC00-\uDFFF]/,pi=/[\p{Cc}\p{Cf}\p{Zl}\p{Zp}\p{Co}\p{Cs}[\]]/u,hi=/^\[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)\]$/,yi=new WeakSet,di=t=>{let e={reason:t};throw jo(yi,e),e},bi=(t,e)=>{let r=t.length>e?`${xo(t,0,e)}...`:t,n="";for(let t=0;t<r.length;t++){let e=r[t],o=Oo(r,t);if(o>=55296&&o<=56319&&t+1<r.length){let n=Oo(r,t+1);n>=56320&&n<=57343&&(e+=r[t+1],t++)}n+=null===Ao(pi,e)?e:"?"}return n},vi=t=>{if(null===t)return"null";let e=typeof t;if("object"!==e)return e;if(ao(t))return"array";let r=Ao(hi,vo(t));return r?r[1]:"object"},gi=t=>null===t?"find":gi(t.up)+("number"==typeof t.k?`[${t.k}]`:`.${bi(t.k,30)}`),ji=t=>{t.nodes+=1,t.nodes>t.maxNodes&&di(ai)},mi=(t,e,r)=>{oo(t,e,{__proto__:null,value:r,enumerable:!0,writable:!0,configurable:!0})},wi=t=>{try{return go(t)}catch(t){return}},_i=t=>{if(null===t||"object"!=typeof t||ao(t))return!1;let e=no(t);return(e===po||null===e)&&("[object Object]"===vo(t)&&void 0===$o(t))},Oi=t=>{for(let e=0;e<zo.length;e++)try{return zo[e](t),!0}catch(t){}return!1},xi=(t,e,r)=>{let n=t.nt;t.ob[n]=e,t.pa[n]=t.path,t.op[n]=r,t.nt=n+1},Ai=t=>{let e=t.nt;if(!(0===e||t.chars<=4e6&&((t,e)=>{if(null===Mo)return!1;try{let r=Mo(t);for(let t=0;t<e;t++)if(no(r[t])!==Uo)return!1;return!0}catch(t){return!1}})(t.ob,e)))for(let r=0;r<e;r++)Oi(t.ob[r])&&(t.path=t.pa[r],di(t.op[r]?`${Jo} [object]`:`${Co}, got [object]`))},ki=(t,e,r)=>{"string"!=typeof r&&di(Ro),t.path={up:t.path,k:r};let n=ro(e,r);return void 0!==n&&n.enumerable||di(To),bo(n,"value")||di(qo),n.value},$i=t=>{let e=t.length;return("number"!=typeof e||!co(e)||e<0)&&di(oi),e},Si=(t,e,r)=>{t.path={up:t.path,k:r};let n=ro(e,r);return void 0===n&&(t.path=t.path.up,di(`sparse array hole at index ${r}`)),n.enumerable||di(Wo),bo(n,"value")||di(Ko),n.value},Pi=(t,e)=>{let r=eo(t),n=r.length;n>e+1&&di(ii);for(let t=0;t<n;t++){let n=r[t];if("string"!=typeof n&&di(ii),"length"===n)continue;let o=+n;co(o)&&o>=0&&o<e&&ko(o)===n||di(ii)}},Di=t=>(fo(t)&&di(Qo),new ho(t)),Ii=(t,e,r)=>{if(ji(t),null===e)return r||di(Go),null;switch(typeof e){case"string":return-1!==_o(n=e,"\0")&&di(Ho),(null!==wo?wo(n):null===Ao(si,n))||di(Xo),t.chars+=e.length,e;case"number":return lo(e)||di(Zo),e;case"boolean":return e;case"undefined":return di(Vo);case"object":{let t=wi(e);return void 0!==t?Di(t):di(`${Jo} [${vi(e)}]`)}default:return di(`${Jo} [${vi(e)}]`)}var n},Ei=(t,e)=>{36===Oo(e,0)&&di(`unsupported operator [${bi(e,30)}]`),e.length>t.maxKey&&di(`column name is too long (> ${t.maxKey})`),null!==Ao(fi,e)&&"__proto__"!==e||di(`unsupported column name [${bi(e,30)}]`)},Fi=(t,e,r)=>{ao(r)||di(ni);let n=$i(r);n>t.maxIn&&di(`array is too large (> ${t.maxIn})`),0===n&&"$nin"===e&&di(ri);let o=[];for(let e=0;e<n;e++){let n=Si(t,r,e);mi(o,e,Ii(t,n,!1)),t.path=t.path.up}return Pi(r,n),o},Ni=(t,e)=>{if(null===e)return ji(t),null;if("object"==typeof e){let r=wi(e);return void 0!==r?(ji(t),Di(r)):(ao(e)&&di(Yo),((t,e)=>{_i(e)||di(`${Jo} [${vi(e)}]`),ji(t);let r=eo(e),n=r.length;0===n&&di(ti),xi(t,e,!0);let o=io(null);for(let i=0;i<n;i++){let n=r[i],u=ki(t,e,n);switch(n){case"$eq":case"$ne":mi(o,n,Ii(t,u,!0));break;case"$gt":case"$gte":case"$lt":case"$lte":mi(o,n,Ii(t,u,!1));break;case"$in":case"$nin":mi(o,n,Fi(t,n,u));break;default:36===Oo(n,0)&&di(`unsupported operator [${bi(n,30)}]`),di(`unexpected key [${bi(n,30)}] in operator object (nested conditions are not supported)`)}t.path=t.path.up}return o})(t,e))}return Ii(t,e,!0)},Bi=(t,e,r,n)=>{ao(r)||di(ni);let o=$i(r);0===o&&di(`${e} with empty array`),o>t.maxList&&di(`array is too large (> ${t.maxList})`);let i=[];for(let e=0;e<o;e++){let o=Si(t,r,e);mi(i,e,Li(t,o,n,!1)),t.path=t.path.up}return Pi(r,o),i},Li=(t,e,r,n)=>{r>t.maxDepth&&di(ui),_i(e)||di(`${Co}, got [${vi(e)}]`),ji(t);let o=eo(e),i=o.length;if(0===i){if(n)return(t=>{if(null===Mo)return!1;try{let e=Mo(t);return no(e)===Uo&&0===eo(e).length}catch(t){return!1}})(e)||(Oi(e)&&di(`${Co}, got [object]`),null!==Mo&&di(li)),io(null);di(ei)}xi(t,e,!1);let u=io(null);for(let n=0;n<i;n++){let i=o[n],a=ki(t,e,i);"$and"===i||"$or"===i?mi(u,i,Bi(t,i,a,r+1)):(Ei(t,i),mi(u,i,Ni(t,a))),t.path=t.path.up}return u};function zi(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||!bo(r,n))throw new Error(`invalid opt: unknown option [${"string"==typeof n?bi(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(!bo(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,chars:0,ob:uo([],null),pa:uo([],null),op:uo([],null),nt:0};try{if(void 0===t)return io(null);let e=Li(n,t,0,!0);return Ai(n),e}catch(t){let e=mo(yi,t)?t.reason:ci;throw new Error(`invalid find: ${e} at [${(t=>{let e=gi(t);return e.length>120?`...${xo(e,-100)}`:e})(n.path)}]`)}}let Mi={};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 s=`${i}:${a}`,p=new f(o),h=new e.Low(p,{}),y=new _n,d=t.resolve(o);Yn(Mi,d)||(Mi[d]=Promise.resolve());let b=t=>{let e=Mi[d].then((()=>t()));return Mi[d]=e.catch((()=>{})),e},v=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/,g=t=>{if(t.length<=30)return t;let e=t.slice(0,30),r=e.charCodeAt(29);return r>=55296&&r<=56319&&(e=`${e.slice(0,29)}?`),`${e}...`},j=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"find";if(t instanceof Date){let r=t.toISOString();if(!v.test(r))throw new Error(`invalid find: Date year is out of range 0000-9999 at [${(t=>t.length>120?`...${t.slice(-100)}`:t)(e)}]`);return r}if(null!==t&&"object"==typeof t){let r=Array.isArray(t);for(let n of Object.keys(t))t[n]=j(t[n],r?`${e}[${n}]`:`${e}.${g(n)}`)}return t},m=t=>{for(let e of Object.keys(t))if("$and"===e||"$or"===e){for(let r of t[e])if(m(r))return!0}else if(e in Object.prototype)return!0;return!1},w=t=>{let e=new u.Query(t);return m(t)?t=>e.test(null!==t&&"object"==typeof t?Object.assign(Object.create(null),t):t):t=>e.test(t)},_=(t,e)=>{try{return{fc:j(zi(e))}}catch(e){return x(t,null,e),{err:e}}},O=(t,e,r)=>{try{y.emit("change",t,e,r)}catch(t){console.log(t)}},x=(t,e,r)=>{try{y.emit("error",t,e,A(r))}catch(t){console.log(t)}},A=t=>{let e=dt(t,"message");return Gn(e)?e:String(t)},k=(t,e)=>l?Qe(t,(function(t){return Gn(t.id)||(t.id=$n()),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),$=async()=>(await h.read(),Yn(h.data,s)||(h.data[s]=[]),h.data[s]),S=async(t,e)=>{h.data[s]=e;try{await h.write()}catch(e){throw h.data[s]=t,e}},P=t=>{let e={};return Yt(t,((t,r)=>{let n=dt(t,"id");Gn(n)&&(e[n]={k:r,v:t})})),e},D=async()=>{if(c&&Tn(n))return jn(n);let t=await $();return t=jn(t),c?(n=t,jn(t)):t};async function I(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=k(t,"save");let e=await $(),r=[...e],n=P(r),u=!1;i=await qn(t,(async t=>{let e=null;try{let i=dt(n,t.id,null);if(Jn(i)){let o=i.v,a=Mr({},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:A(t)}}return e})),u&&await S(e,r)}catch(t){r=!0,i=t}return n=null,r||(Yt(i,((e,r)=>{0===dt(e,"ok")&&x("save",[dt(t,r)],dt(e,"err"))})),Yt(i,((e,r)=>{1===dt(e,"nInserted")&&O("insert",[dt(t,r)],e)})),O("save",t,i)),r?(x("save",t,i),Promise.reject(i)):i}return y.select=async function(){let t=_("select",arguments.length>0&&void 0!==arguments[0]?arguments[0]:{});return t.err?Promise.reject(t.err):b((()=>async function(t){let e=!1,r=null;try{let n=await D();r=Reflect.ownKeys(t).length>0?n.filter(w(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?(x("select",null,r),Promise.reject(r)):r}(t.fc)))},y.selectByPk=async function(t){return b((()=>async function(t){let e=!1,r=null;try{if(!Gn(t))return null;let e=await D(),n=dt(P(e),t,null);r=Jn(n)?n.v:null}catch(t){e=!0,r=t}return e?(x("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 b((()=>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=k(t,"insert");let e=await $(),n=P(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 S(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||O("insert",t,o),e?(x("insert",t,o),Promise.reject(o)):o}(t,e)))},y.insertBulk=async function(t){return b((()=>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=k(t,"insertBulk");let e=await $(),n=P(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 S(e,[...e,...t]),r={n:o,nInserted:o,ok:1}}catch(t){e=!0,r=t}return n=null,e||O("insertBulk",t,r),e?(x("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 b((()=>I(t,e)))},y.del=async function(t){return b((()=>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 $(),n=P(e),o={},i=!1;if(r=await qn(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:A(t)}}return e})),i){let t=Xe(e,((t,e)=>!Yn(o,e)));await S(e,t)}}catch(t){e=!0,r=t}return n=null,e||(Yt(r,((e,r)=>{0===dt(e,"ok")&&x("del",[dt(t,r)],dt(e,"err"))})),O("del",t,r)),e?(x("del",t,r),Promise.reject(r)):r}(t)))},y.delAll=async function(){let t=_("delAll",arguments.length>0&&void 0!==arguments[0]?arguments[0]:{});return t.err?Promise.reject(t.err):b((()=>async function(t){let e=!1,r=null;try{let e=await $(),n=tn(e),o=0,i=null;if(Reflect.ownKeys(t).length>0){let r=w(t);i=Xe(e,(t=>!r(t))),o=n-tn(i)}else o=n,i=[];o>0&&await S(e,i),r={n:o,nDeleted:o,ok:1}}catch(t){e=!0,r=t}return n=null,e||O("delAll",null,r),e?(x("delAll",null,r),Promise.reject(r)):r}(t.fc)))},y}}));
7
7
  //# sourceMappingURL=w-orm-lowdb.umd.js.map