w-orm-lowdb 1.0.33 → 1.0.35

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
@@ -51,7 +51,19 @@ An operator for lowdb in nodejs.
51
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
52
 
53
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` 命中,依條件自行斟酌)。
54
+ - **數據側**:寫入(`insert`、`insertBulk`、`save`)範圍外 `Date` 自 1.0.34 起整批 reject,見下節「寫入數據之 Date」。**資料庫檔內既有之範圍外 `Date` 字串(舊版存入者)仍無法以 `Date` 條件正確比較**:例如舊版以 `new Date(8.64e15)` 作「永不過期」哨兵存入之 `'+275760-…'`,範圍內之條件 `{ expireAt: { $lt: 現在 } }` 仍會因字典序命中哨兵(`'+275760-…' < '2026-…'`),`delAll` 會將其刪除。此限制是雙向的:既可能誤命中(上例),亦可能漏命中(例如 `{ t: { $gt: new Date('9999-12-31T23:59:59.999Z') } }` 不會命中 `'+275760-…'` 之資料),範圍外資料彼此間的順序亦不可靠。請自行清理或改寫既有資料,清理方式見下節。
55
+
56
+ ### 寫入數據之 Date (Date in written data)
57
+
58
+ 自 1.0.34 起,`insert`、`insertBulk`、`save`(含自動插入、更新既有與合併)於寫入前檢核數據內**任何深度**(頂層欄位、巢狀物件、陣列內)之 `Date`:年份須介於 0000–9999(此範圍內序列化後恆為 24 字元 `YYYY-MM-DDTHH:mm:ss.sssZ`,字典序等於時間序)。年份小於 0 或大於 9999 者(如 `new Date(8.64e15)`、`new Date(-8.64e15)`、`-000001` 年、`+010000` 年)整批 reject(fail-closed,與條件側一致):
59
+
60
+ - 訊息為 `invalid data: Date year is out of range 0000-9999 at [<路徑>]`,路徑形如 `data[0].expireAt`、`data[2].list[1].t`(輸入為單一物件時視為長度 1 之陣列;物件之鍵非一般識別字者以 `["a.b"]` 表示),不回顯值。於 reject 之前發出一次 `error` 事件,不發出 `change` 事件。
61
+ - 整批中任一筆含範圍外 `Date` 即整批 reject,不讀檔、不寫檔,資料庫檔不變。`save` 即使因 `autoInsert: false` 而主鍵不存在(不會寫入)亦先經同一檢核。`autoGenPk: false` 而缺主鍵者仍先以缺主鍵訊息 reject。
62
+ - 邊界 `0000-01-01T00:00:00.000Z` 與 `9999-12-31T23:59:59.999Z` 接受。無效 `Date`(`Invalid Date`)處置不變,序列化為 `null` 存入。
63
+ - 只檢核 `Date` 物件,以 `JSON.stringify`(即實際寫入之序列化)之結果判定:已是字串者(如讀出後再存回之 `'+275760-09-13T00:00:00.000Z'`)、`Map`/`Set` 內之 `Date`(序列化為 `{}`)、非 `Date` 之 `toJSON` 物件(含 `Buffer`)之輸出皆不檢核;`TypedArray`、`DataView` 的自有屬性照常序列化,其內之 `Date` 會檢核。刻意構造之物件(自訂 `toJSON` 回傳含 `Date` 之物件、依屬性鍵或狀態回傳不同值之 `toJSON`、`Proxy` 包裝之 `Date`、`cloneDeep` 不複製之物件)不在檢核範圍。
64
+ - 原因:範圍外 `Date` 存為 `+yyyyyy-…`、`-yyyyyy-…` 字串後,字典序與時間序顛倒。例如以 `new Date(8.64e15)` 作「永不過期」哨兵,`delAll({ t: { $lt: new Date() } })` 會因字典序把它當成過去而刪除。「永不過期」請改用 `null`,或範圍內之 `new Date('9999-12-31T23:59:59.999Z')`(此二者不會被 `{ t: { $lt: 現在 } }` 命中,但仍會被 `$ne`、`$nin` 命中,依條件自行斟酌)。
65
+
66
+ **既有資料不遷移、不改讀取**:1.0.34 起寫入拒收,但資料庫檔內已存在之範圍外 `Date` 字串仍有字典序風險,請自行清理或改寫。例如 `let rows = (await wo.select()).filter((v) => /^[+-]\d{6}-/.test(v.t))` 找出欄位 `t` 為範圍外字串者(巢狀欄位同理自行走訪),再 `for (let v of rows) { await wo.save({ id: v.id, t: null }) }` 或以範圍內之值覆寫。
55
67
 
56
68
  語意為 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 } }] }`。
57
69
 
@@ -62,7 +74,8 @@ Date:本套件以 JSON 存檔,Date 存入後為 ISO 字串(`toISOString()`)
62
74
  - 移除:白名單以外之全部 `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()` 後於記憶體過濾。
63
75
  - 改為 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 項。
64
76
  - 新行為:條件內之 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 節)。
77
+ - 改為 reject(Date 範圍):條件內任何位置之 `Date` 年份小於 0 或大於 9999(如 `new Date(8.64e15)`),原本轉為帶正負號之 ISO 字串後以字典序比較,結果與時間序顛倒(`$gt` 哨兵命中所有帶日期之數據、`$lt` 哨兵恆無命中),現整批 reject;數據側見下一條。
78
+ - 改為 reject(寫入 Date 範圍,1.0.34 起):`insert`、`insertBulk`、`save` 寫入之數據內任何深度之 `Date` 年份小於 0 或大於 9999(如以 `new Date(8.64e15)` 作「永不過期」哨兵),原本照存為 `+yyyyyy-…`、`-yyyyyy-…` 字串(其後會被 `{ t: { $lt: 現在 } }` 因字典序命中而遭 `delAll` 刪除),現整批 reject,訊息為 `invalid data: Date year is out of range 0000-9999 at [<路徑>]`;請改用 `null` 或 `new Date('9999-12-31T23:59:59.999Z')`。既有資料不遷移,仍有字典序風險,請自行清理或改寫(見上方「寫入數據之 Date」)。
66
79
  - 錯誤訊息為 `invalid find: <原因> at [<路徑>]`;原本由 `mingo` 拋出錯誤者,現統一為此訊息。
67
80
 
68
81
  ## Documentation
@@ -1,7 +1,7 @@
1
1
  /*!
2
- * w-orm-lowdb v1.0.33
2
+ * w-orm-lowdb v1.0.35
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{#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}}));
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,a){"use strict";class u{#t;#e;#r=!1;#n=null;#o=null;#i=null;#a=null;#u(t){return this.#a=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.#a){const t=this.#a;this.#a=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.#u(t):this.#c(t)}}class c{#t;#l;constructor(t){this.#t=t,this.#l=new u(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 w=Object.prototype.toString;var m=d?d.toStringTag:void 0;function _(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":m&&m 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 w.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)\]/,$=/^\w*$/;function k(t,e){if(s(t))return!1;var r=typeof t;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=t&&!x(t))||($.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__"],N=(D=/[^.]+$/.exec(I&&I.keys&&I.keys.IE_PROTO||""))?"Symbol(src)_1."+D:"";var E=Function.prototype.toString;function F(t){if(null!=t){try{return E.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,N&&N 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 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 J(t,e){return t===e||t!=t&&e!=e}function G(t,e){for(var r=t.length;r--;)if(J(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=G(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=G(e,t);return r<0?void 0:e[r][1]},Q.prototype.has=function(t){return G(this.__data__,t)>-1},Q.prototype.set=function(t,e){var r=this.__data__,n=G(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 a=t.apply(this,n);return r.cache=i.set(o,a)||i,a};return r.cache=new(tt.Cache||Y),r}tt.Cache=Y;var et,rt,nt,ot=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,it=/\\(\\)?/g,at=(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),ut=at;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:k(t,e)?[t]:ut(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),a=i.length;a--;){var u=i[vt?a:++n];if(!1===e(o[u],u,o))break}return t};function jt(t){return O(t)&&"[object Arguments]"==_(t)}var wt=Object.prototype,mt=wt.hasOwnProperty,_t=wt.propertyIsEnumerable,Ot=jt(function(){return arguments}())?jt:function(t){return O(t)&&mt.call(t,"callee")&&!_t.call(t,"callee")},xt=Ot;var At="object"==typeof exports&&exports&&!exports.nodeType&&exports,$t=At&&"object"==typeof module&&module&&!module.nodeType&&module,kt=$t&&$t.exports===At?y.Buffer:void 0,St=(kt?kt.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 Nt={};function Et(t){return function(e){return t(e)}}Nt["[object Float32Array]"]=Nt["[object Float64Array]"]=Nt["[object Int8Array]"]=Nt["[object Int16Array]"]=Nt["[object Int32Array]"]=Nt["[object Uint8Array]"]=Nt["[object Uint8ClampedArray]"]=Nt["[object Uint16Array]"]=Nt["[object Uint32Array]"]=!0,Nt["[object Arguments]"]=Nt["[object Array]"]=Nt["[object ArrayBuffer]"]=Nt["[object Boolean]"]=Nt["[object DataView]"]=Nt["[object Date]"]=Nt["[object Error]"]=Nt["[object Function]"]=Nt["[object Map]"]=Nt["[object Number]"]=Nt["[object Object]"]=Nt["[object RegExp]"]=Nt["[object Set]"]=Nt["[object String]"]=Nt["[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,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?Et(Mt):function(t){return O(t)&&It(t.length)&&!!Nt[_(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),a=r||n||o||i,u=a?function(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n}(t.length,String):[],c=u.length;for(var l in t)!e&&!Ct.call(t,l)||a&&("length"==l||o&&("offset"==l||"parent"==l)||i&&("buffer"==l||"byteLength"==l||"byteOffset"==l)||Dt(l,c))||u.push(l);return u}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 Jt(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 Gt(t){return null!=t&&It(t.length)&&!P(t)}function Zt(t){return Gt(t)?Rt(t):Jt(t)}var Qt=function(t,e){return function(r,n){if(null==r)return r;if(!Gt(r))return t(r,n);for(var o=r.length,i=e?o:-1,a=Object(r);(e?i--:++i<o)&&!1!==n(a[i],i,a););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 a=1&r,u=t.length,c=e.length;if(u!=c&&!(a&&c>u))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<u;){var y=t[s],d=e[s];if(n)var b=a?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 ae(t){var e=-1,r=Array(t.size);return t.forEach((function(t,n){r[++e]=[n,t]})),r}function ue(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 a=t[r];e(a,r,t)&&(i[o++]=a)}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"),we=T(y,"Promise"),me=T(y,"Set"),_e=T(y,"WeakMap"),Oe="[object Map]",xe="[object Promise]",Ae="[object Set]",$e="[object WeakMap]",ke="[object DataView]",Se=F(je),Pe=F(H),De=F(we),Ie=F(me),Ne=F(_e),Ee=_;(je&&Ee(new je(new ArrayBuffer(1)))!=ke||H&&Ee(new H)!=Oe||we&&Ee(we.resolve())!=xe||me&&Ee(new me)!=Ae||_e&&Ee(new _e)!=$e)&&(Ee=function(t){var e=_(t),r="[object Object]"==e?t.constructor:void 0,n=r?F(r):"";if(n)switch(n){case Se:return ke;case Pe:return Oe;case De:return xe;case Ie:return Ae;case Ne:return $e}return e});var Fe=Ee,Be="[object Arguments]",Le="[object Array]",ze="[object Object]",Me=Object.prototype.hasOwnProperty;function Ue(t,e,r,n,o,i){var a=s(t),u=s(e),c=a?Le:Fe(t),l=u?Le:Fe(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;a=!0,f=!1}if(h&&!f)return i||(i=new te),a||Ut(t)?oe(t,e,r,n,o,i):function(t,e,r,n,o,i,a){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 J(+t,+e);case"[object Error]":return t.name==e.name&&t.message==e.message;case"[object RegExp]":case"[object String]":return t==e+"";case"[object Map]":var u=ae;case"[object Set]":var c=1&n;if(u||(u=ue),t.size!=e.size&&!c)return!1;var l=a.get(t);if(l)return l==e;n|=2,a.set(t,e);var f=oe(u(t),u(e),n,o,i,a);return a.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 a=1&r,u=ve(t),c=u.length;if(c!=ve(e).length&&!a)return!1;for(var l=c;l--;){var f=u[l];if(!(a?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=a;++l<c;){var d=t[f=u[l]],b=e[f];if(n)var v=a?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,a=!n;if(null==t)return!i;for(t=Object(t);o--;){var u=r[o];if(a&&u[2]?u[1]!==t[u[0]]:!(u[0]in t))return!1}for(;++o<i;){var c=(u=r[o])[0],l=t[c],f=u[1];if(a&&u[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 a=ht(e[n]);if(!(i=null!=t&&r(t,a)))break;t=t[a]}return i||++n!=o?i:!!(o=null==t?0:t.length)&&It(o)&&Dt(a,o)&&(s(t)||xt(t))}(t,e,qe)}function Ve(t){return function(e){return null==e?void 0:e[t]}}function Je(t){return k(t)?Ve(ht(t)):function(t){return function(e){return yt(e,t)}}(t)}function Ge(t){return"function"==typeof t?t:null==t?Xt:"object"==typeof t?s(t)?function(t,e){return k(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):Je(t)}function Ze(t,e){var r=-1,n=Gt(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,Ge(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,Ge(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&&!J(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,ar=ir?ir.allocUnsafe:void 0;function ur(t,e){if(e)return t.slice();var r=t.length,n=ar?ar(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,wr=gr.call(Object);function mr(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)&&J(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,a=e.length;++i<a;){var u=e[i],c=n?n(r[u],t[u],u,r,t):void 0;void 0===c&&(c=t[u]),o?er(r,u,c):Or(r,u,c)}return r}var Ar=Object.prototype.hasOwnProperty;function $r(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 kr(t){return Gt(t)?Rt(t,!0):$r(t)}function Sr(t,e,r,n,o,i,a){var u=mr(t,r),c=mr(e,r),l=a.get(c);if(l)rr(t,r,l);else{var f,p=i?i(u,c,r+"",t,e,a):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(u)?p=u:O(f=u)&&Gt(f)?p=fr(u):d?(h=!1,p=ur(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)==wr}(c)||xt(c)?(p=u,xt(u)?p=function(t){return xr(t,kr(t))}(u):S(u)&&!P(u)||(p=dr(c))):h=!1}h&&(a.set(c,p),o(p,c,n,i,a),a.delete(c)),rr(t,r,p)}}function Pr(t,e,r,n,o){t!==e&&gt(e,(function(i,a){if(o||(o=new te),S(i))Sr(t,e,a,r,Pr,n,o);else{var u=n?n(mr(t,a),i,a+"",t,e,o):void 0;void 0===u&&(u=i),rr(t,a,u)}}),kr)}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,Nr=Ir,Er=Date.now;var Fr=function(t){var e=0,r=0;return function(){var n=Er(),o=16-(n-r);if(r=n,o>0){if(++e>=800)return arguments[0]}else e=0;return t.apply(void 0,arguments)}}(Nr),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),a=Array(i);++o<i;)a[o]=n[e+o];o=-1;for(var u=Array(e+1);++o<e;)u[o]=n[o];return u[e]=r(a),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,u)}}(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?Gt(r)&&Dt(e,r.length):"string"==n&&e in r)&&J(r[e],t)}(e[0],e[1],i)&&(o=n<3?void 0:o,n=1),t=Object(t);++r<n;){var a=e[r];a&&zr(t,a,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}",Jr="[\\ud800-\\udbff][\\udc00-\\udfff]",Gr="(?:"+Wr+"|"+qr+")"+"?",Zr="[\\ufe0e\\ufe0f]?",Qr=Zr+Gr+("(?:\\u200d(?:"+[Kr,Vr,Jr].join("|")+")"+Zr+Gr+")*"),Hr="(?:"+[Kr+Wr+"?",Wr,Vr,Jr,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(Gt(t))return"string"==typeof(e=t)||!s(e)&&O(e)&&"[object String]"==_(e)?Yr(t):t.length;var e,r=Fe(t);return"[object Map]"==r||"[object Set]"==r?t.size:Jt(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,kr,rn)}var on=Object.prototype.hasOwnProperty;var an=/\w*$/;var un=d?d.prototype:void 0,cn=un?un.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,an.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?Et(fn):function(t){return O(t)&&"[object Map]"==Fe(t)};var pn=zt&&zt.isSet,hn=pn?Et(pn):function(t){return O(t)&&"[object Set]"==Fe(t)},yn="[object Arguments]",dn="[object Function]",bn="[object Object]",vn={};function gn(t,e,r,n,o,i){var a,u=1&e,c=2&e,l=4&e;if(r&&(a=o?r(t,n,o,i):r(t)),void 0!==a)return a;if(!S(t))return t;var f=s(t);if(f){if(a=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),!u)return fr(t,a)}else{var p=Fe(t),h=p==dn||"[object GeneratorFunction]"==p;if(St(t))return ur(t,u);if(p==bn||p==yn||h&&!o){if(a=c||h?{}:dr(t),!u)return c?function(t,e){return xr(t,rn(t),e)}(t,function(t,e){return t&&xr(e,kr(e),t)}(a,t)):function(t,e){return xr(t,be(t),e)}(t,function(t,e){return t&&xr(e,Zt(e),t)}(a,t))}else{if(!vn[p])return o?t:{};a=ln(t,p,u)}}i||(i=new te);var y=i.get(t);if(y)return y;i.set(t,a),hn(t)?t.forEach((function(n){a.add(gn(n,e,r,n,t,i))})):sn(t)&&t.forEach((function(n,o){a.set(o,gn(n,e,r,o,t,i))}));var d=f?void 0:(l?c?nn:ve:c?kr:Zt)(t);return bt(d||t,(function(n,o){d&&(n=t[o=n]),Or(a,o,gn(n,e,r,o,t,i))})),a}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 wn(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var mn={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,a){if("function"!=typeof n)throw new TypeError("The listener must be a function");var u=new o(n,i||t,a),c=r?r+e:e;return t._events[c]?t._events[c].fn?t._events[c]=[t._events[c],u]:t._events[c].push(u):(t._events[c]=u,t._eventsCount++),t}function a(t,e){0==--t._eventsCount?t._events=new n:delete t._events[e]}function u(){this._events=new n,this._eventsCount=0}Object.create&&(n.prototype=Object.create(null),(new n).__proto__||(r=!1)),u.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},u.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,a=new Array(i);o<i;o++)a[o]=n[o].fn;return a},u.prototype.listenerCount=function(t){var e=r?r+t:t,n=this._events[e];return n?n.fn?1:n.length:0},u.prototype.emit=function(t,e,n,o,i,a){var u=r?r+t:t;if(!this._events[u])return!1;var c,l,f=this._events[u],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,a),!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},u.prototype.on=function(t,e,r){return i(this,t,e,r,!1)},u.prototype.once=function(t,e,r){return i(this,t,e,r,!0)},u.prototype.removeListener=function(t,e,n,o){var i=r?r+t:t;if(!this._events[i])return this;if(!e)return a(this,i),this;var u=this._events[i];if(u.fn)u.fn!==e||o&&!u.once||n&&u.context!==n||a(this,i);else{for(var c=0,l=[],f=u.length;c<f;c++)(u[c].fn!==e||o&&!u[c].once||n&&u[c].context!==n)&&l.push(u[c]);l.length?this._events[i]=1===l.length?l[0]:l:a(this,i)}return this},u.prototype.removeAllListeners=function(t){var e;return t?(e=r?r+t:t,this._events[e]&&a(this,e)):(this._events=new n,this._eventsCount=0),this},u.prototype.off=u.prototype.removeListener,u.prototype.addListener=u.prototype.on,u.prefixed=r,u.EventEmitter=u,t.exports=u}(mn);var _n=wn(mn.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 $n={};function kn(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++)}($n,t,o),n=Sn(o,$n.msecs,$n.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 Nn(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 En=/^[-+]0x[0-9a-f]+$/i,Fn=/^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=Nn(t);var r=Fn.test(t);return r||Bn.test(t)?Ln(t.slice(2),r?2:8):En.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,a=[];return t.reduce((function(t,r){return t.then((function(t){a.push(t),i+=1;let u=i,c=r;return n&&(u=r.k,c=r.v),o?e(c,u):c}))}),Promise.resolve()).then((function(t){a.push(t),a=Un(a),r.resolve(a)})).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 Jn(t){return!!(Vn(t)&&t.length>0)}function Gn(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(Jn(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)&&(!(!Jn(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,ao=Object.setPrototypeOf,uo=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),wo=yo.bind(WeakSet.prototype.has),mo=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),$o=String,ko=yo.bind(ro(no(Uint8Array.prototype),Symbol.toStringTag).get),So={},Po=()=>{},Do=yo.bind(Map.prototype.has),Io=yo.bind(Set.prototype.has),No=yo.bind(WeakMap.prototype.has),Eo=yo.bind(ro(ArrayBuffer.prototype,"byteLength").get),Fo=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=>No(t,So),t=>wo(t,So),t=>Eo(t),t=>Fo(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=ao(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",Jo="null is not allowed here",Go="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",ai="nesting is too deep",ui="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(uo(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(ui)},wi=(t,e,r)=>{oo(t,e,{__proto__:null,value:r,enumerable:!0,writable:!0,configurable:!0})},mi=t=>{try{return go(t)}catch(t){return}},_i=t=>{if(null===t||"object"!=typeof t||uo(t))return!1;let e=no(t);return(e===po||null===e)&&("[object Object]"===vo(t)&&void 0===ko(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]?`${Go} [object]`:`${Co}, got [object]`))},$i=(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},ki=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&&$o(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(Jo),null;switch(typeof e){case"string":return-1!==_o(n=e,"\0")&&di(Ho),(null!==mo?mo(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=mi(e);return void 0!==t?Di(t):di(`${Go} [${vi(e)}]`)}default:return di(`${Go} [${vi(e)}]`)}var n},Ni=(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)}]`)},Ei=(t,e,r)=>{uo(r)||di(ni);let n=ki(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);wi(o,e,Ii(t,n,!1)),t.path=t.path.up}return Pi(r,n),o},Fi=(t,e)=>{if(null===e)return ji(t),null;if("object"==typeof e){let r=mi(e);return void 0!==r?(ji(t),Di(r)):(uo(e)&&di(Yo),((t,e)=>{_i(e)||di(`${Go} [${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],a=$i(t,e,n);switch(n){case"$eq":case"$ne":wi(o,n,Ii(t,a,!0));break;case"$gt":case"$gte":case"$lt":case"$lte":wi(o,n,Ii(t,a,!1));break;case"$in":case"$nin":wi(o,n,Ei(t,n,a));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)=>{uo(r)||di(ni);let o=ki(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);wi(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(ai),_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 a=io(null);for(let n=0;n<i;n++){let i=o[n],u=$i(t,e,i);"$and"===i||"$or"===i?wi(a,i,Bi(t,i,u,r+1)):(Ni(t,i),wi(a,i,Fi(t,u))),t.path=t.path.up}return a};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 a=o.value;if(void 0!==a){if("number"!=typeof a||!so(a)||a<1)throw new Error(`invalid opt: ${i} must be a positive integer`);r[i]=a<to[i]?a: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:ao([],null),pa:ao([],null),op:ao([],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=wo(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");Jn(o)||(o="./db.json");let i=dt(r,"db");Jn(i)||(i="worm");let u=dt(r,"cl");Jn(u)||(u="test");let c=dt(r,"useCache");Kn(c)||(c=!1);let l=dt(r,"autoGenPk");Kn(l)||(l=!0);let s=`${i}:${u}`,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=t=>t.length>120?`...${t.slice(-100)}`:t,w=/^[\p{L}_$][\p{L}\p{M}\p{N}_$]*$/u,m=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:new WeakSet;if(!(null===t||"object"!=typeof t||r.has(t)||ArrayBuffer.isView(t)&&"function"==typeof t.toJSON))if((t=>{if("function"!=typeof t.toJSON)return!1;try{return Date.prototype.getTime.call(t),!0}catch(t){return!1}})(t)){let r=JSON.stringify(t);if("string"==typeof r&&'"'===r.charAt(0)&&!v.test(r.slice(1,-1))){let t=`data${e.map((t=>"number"==typeof t?`[${t}]`:(t=>{let e=g(t);return w.test(t)?`.${e}`:`[${JSON.stringify(e)}]`})(t))).join("")}`;throw new Error(`invalid data: Date year is out of range 0000-9999 at [${j(t)}]`)}}else if(r.add(t),Array.isArray(t))for(let n=0;n<t.length;n++)e.push(n),m(t[n],e,r),e.pop();else for(let n of Object.keys(t))e.push(n),m(t[n],e,r),e.pop()},_=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 [${j(e)}]`);return r}if(null!==t&&"object"==typeof t){let r=Array.isArray(t);for(let n of Object.keys(t))t[n]=_(t[n],r?`${e}[${n}]`:`${e}.${g(n)}`)}return t},O=t=>{for(let e of Object.keys(t))if("$and"===e||"$or"===e){for(let r of t[e])if(O(r))return!0}else if(e in Object.prototype)return!0;return!1},x=t=>{let e=new a.Query(t);return O(t)?t=>e.test(null!==t&&"object"==typeof t?Object.assign(Object.create(null),t):t):t=>e.test(t)},A=(t,e)=>{try{return{fc:_(zi(e))}}catch(e){return k(t,null,e),{err:e}}},$=(t,e,r)=>{try{y.emit("change",t,e,r)}catch(t){console.log(t)}},k=(t,e,r)=>{try{y.emit("error",t,e,S(r))}catch(t){console.log(t)}},S=t=>{let e=dt(t,"message");return Jn(e)?e:String(t)},P=(t,e)=>l?Qe(t,(function(t){return Jn(t.id)||(t.id=kn()),t})):(Yt(t,(function(t,r){if(!Jn(dt(t,"id")))throw new Error(`can not ${e} by data[${r}] without valid id when autoGenPk is false`)})),t),D=async()=>(await h.read(),Yn(h.data,s)||(h.data[s]=[]),h.data[s]),I=async(t,e)=>{h.data[s]=e;try{await h.write()}catch(e){throw h.data[s]=t,e}},N=t=>{let e={};return Yt(t,((t,r)=>{let n=dt(t,"id");Jn(n)&&(e[n]={k:r,v:t})})),e},E=async()=>{if(c&&Tn(n))return jn(n);let t=await D();return t=jn(t),c?(n=t,jn(t)):t};async function F(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=!1;if(!Gn(t)&&!Hn(t))return[];t=jn(t);let o=dt(e,"autoInsert",!0),i=null;try{Tn(t)||(t=[t]),t=P(t,"save"),m(t);let e=await D(),r=[...e],n=N(r),a=!1;i=await qn(t,(async t=>{let e=null;try{let i=dt(n,t.id,null);if(Gn(i)){let o=i.v,u=Mr({},o,t);Ce(u,o)?e={n:1,nInserted:0,nModified:0,ok:1}:(r[i.k]=u,n[t.id]={k:i.k,v:u},a=!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},a=!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:S(t)}}return e})),a&&await I(e,r)}catch(t){r=!0,i=t}return n=null,r||(Yt(i,((e,r)=>{0===dt(e,"ok")&&k("save",[dt(t,r)],dt(e,"err"))})),Yt(i,((e,r)=>{1===dt(e,"nInserted")&&$("insert",[dt(t,r)],e)})),$("save",t,i)),r?(k("save",t,i),Promise.reject(i)):i}return y.select=async function(){let t=A("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 E();r=Reflect.ownKeys(t).length>0?n.filter(x(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?(k("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(!Jn(t))return null;let e=await E(),n=dt(N(e),t,null);r=Gn(n)?n.v:null}catch(t){e=!0,r=t}return e?(k("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),!Gn(t)&&!Hn(t))return r?[]:{n:0,nInserted:0,ok:1};t=jn(t);let o=null;try{Tn(t)||(t=[t]),t=P(t,"insert"),m(t);let e=await D(),n=N(e),i=tn(t),a=[],u=[];Yt(t,(t=>{Yn(n,t.id)?a.push(!1):(u.push(t),n[t.id]={k:-1,v:t},a.push(!0))})),tn(u)>0&&await I(e,[...e,...u]),o=r?Qe(a,(function(t){return{n:1,nInserted:t?1:0,ok:1}})):{n:i,nInserted:tn(u),ok:1}}catch(t){e=!0,o=t}return n=null,e||$("insert",t,o),e?(k("insert",t,o),Promise.reject(o)):o}(t,e)))},y.insertBulk=async function(t){return b((()=>async function(t){let e=!1;if(!Gn(t)&&!Hn(t))return{n:0,nInserted:0,ok:1};t=jn(t);let r=null;try{Tn(t)||(t=[t]),t=P(t,"insertBulk"),m(t);let e=await D(),n=N(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 I(e,[...e,...t]),r={n:o,nInserted:o,ok:1}}catch(t){e=!0,r=t}return n=null,e||$("insertBulk",t,r),e?(k("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((()=>F(t,e)))},y.del=async function(t){return b((()=>async function(t){let e=!1;if(!Gn(t)&&!Hn(t))return[];t=jn(t);let r=null;try{Tn(t)||(t=[t]);let e=await D(),n=N(e),o={},i=!1;if(r=await qn(t,(async t=>{let e=null;try{let r=dt(t,"id","");if(Jn(r)){let t=dt(n,r,null);Gn(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:S(t)}}return e})),i){let t=Xe(e,((t,e)=>!Yn(o,e)));await I(e,t)}}catch(t){e=!0,r=t}return n=null,e||(Yt(r,((e,r)=>{0===dt(e,"ok")&&k("del",[dt(t,r)],dt(e,"err"))})),$("del",t,r)),e?(k("del",t,r),Promise.reject(r)):r}(t)))},y.delAll=async function(){let t=A("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 D(),n=tn(e),o=0,i=null;if(Reflect.ownKeys(t).length>0){let r=x(t);i=Xe(e,(t=>!r(t))),o=n-tn(i)}else o=n,i=[];o>0&&await I(e,i),r={n:o,nDeleted:o,ok:1}}catch(t){e=!0,r=t}return n=null,e||$("delAll",null,r),e?(k("delAll",null,r),Promise.reject(r)):r}(t.fc)))},y}}));
7
7
  //# sourceMappingURL=w-orm-lowdb.umd.js.map