w-orm-lmdb 1.0.12 → 1.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -8,6 +8,39 @@ An operator for lmdb in nodejs.
8
8
  [![npm download](https://img.shields.io/npm/dm/w-orm-lmdb.svg)](https://npmjs.org/package/w-orm-lmdb)
9
9
  [![jsdelivr download](https://img.shields.io/jsdelivr/npm/hm/w-orm-lmdb.svg)](https://www.jsdelivr.com/package/npm/w-orm-lmdb)
10
10
 
11
+ ## Keypoint
12
+
13
+ 注意: 因lmdb-js綁定層限制, 須使用單程序操作lmdb, 才能避免競爭條件失效.
14
+
15
+ ### Use a single process for writing
16
+
17
+ `w-orm-lmdb` guarantees write atomicity **within a single process only**. Do not have two or more processes writing to the same collection concurrently.
18
+
19
+ Within one process, `insert` and `save` are safe under any amount of concurrency:
20
+
21
+ - `insert` uses LMDB's conditional write (`ifNoExists`), so the "check the key is absent" and "write" steps happen inside one write transaction. Concurrent `insert` calls on the same id produce exactly one `nInserted: 1`; the rest report `nInserted: 0`.
22
+ - `save` wraps its read-merge-write inside an LMDB write transaction, so concurrent `save` calls on the same id never lose an update.
23
+
24
+ Across processes these guarantees do not hold, and the limitation comes from the underlying `lmdb-js` binding rather than from this package or from LMDB itself. LMDB's own multi-process design is sound — one writer at a time, serialized through a lock file — and `lmdb-js` documents its conditional writes as resolving `true` only "if the put was successful" and `false` "if the put did not occur due to the ifVersion not matching at the time of the commit". In practice that contract was observed to break when two processes contend for the same key at the same instant.
25
+
26
+ Measured on Windows 11 with `lmdb-js` 3.5.6, under CPU load, using plain `lmdb-js` with no part of this package involved:
27
+
28
+ - 4 processes racing to create the same key, 30 attempts each, 40 rounds — a few percent of rounds ended with **two** processes both resolving `true`, where exactly one should have.
29
+ - 4 processes running an optimistic `ifVersion` increment loop, 20 attempts each, 40 rounds — reported successes exceeded the actual number of increments in 12 rounds, i.e. two increments collapsed into one.
30
+ - The same tests inside a **single process** never produced an anomaly, across every configuration tried.
31
+ - `ifNoExists`, `transaction` and `transactionSync` all showed it, and it was independent of the `compression` option, so switching API does not avoid it.
32
+
33
+ Notably, the failure needs an actual race. With the key already present before the processes start — 4 processes, 30 attempts each, 40 rounds, 4800 conditional writes in total — there was **not one** false success and **not one** overwrite. A record that already exists is never clobbered; only writes landing in the same instant can interfere.
34
+
35
+ What that means in practice when two processes write concurrently:
36
+
37
+ - `nInserted` and `nModified` can be over-reported. Code that treats `nInserted === 1` as "this record is new" — to trigger a notification, an AI call, or any other expensive downstream action — may fire more than once for the same record.
38
+ - When two processes create the same id at the same instant, both may report success and only one of the two payloads is kept.
39
+ - `save` may lose an update, keeping only one side of two concurrent merges.
40
+ - Key uniqueness and record count stay correct, and records that already exist are never overwritten. The database is not left structurally inconsistent.
41
+
42
+ If your deployment needs more than one process, serialize writes yourself: keep a single writer process, or guard writes with a cross-process lock (a lock file, or a queue). Readers are unaffected — `select` and `selectByPk` are safe from any number of processes.
43
+
11
44
  ## Documentation
12
45
  To view documentation or get support, visit [docs](https://yuda-lyu.github.io/w-orm-lmdb/WOrm.html).
13
46
 
@@ -121,13 +154,13 @@ async function test() {
121
154
  let so = await wo.select({ id: 'id-rosemary' })
122
155
  console.log('select', so)
123
156
 
124
- //selectById
125
- let sb = await wo.selectById('id-rosemary')
126
- console.log('selectById', sb)
157
+ //selectByPk
158
+ let sb = await wo.selectByPk('id-rosemary')
159
+ console.log('selectByPk', sb)
127
160
 
128
- //selectById by id not existed
129
- let sbn = await wo.selectById('id-not-existed')
130
- console.log('selectById by id not existed', sbn)
161
+ //selectByPk by pk not existed
162
+ let sbn = await wo.selectByPk('id-not-existed')
163
+ console.log('selectByPk by pk not existed', sbn)
131
164
 
132
165
  //select by $and, $gt, $lt
133
166
  let spa = await wo.select({ '$and': [{ value: { '$gt': 123 } }, { value: { '$lt': 200 } }] })
@@ -175,9 +208,9 @@ test()
175
208
  // insert then { n: 3, nInserted: 3, ok: 1 }
176
209
  // change save
177
210
  // save then [
178
- // { n: 1, nModified: 1, ok: 1 },
179
- // { n: 1, nModified: 1, ok: 1 },
180
- // { n: 0, nModified: 0, ok: 1 }
211
+ // { n: 1, nInserted: 0, nModified: 1, ok: 1 },
212
+ // { n: 1, nInserted: 0, nModified: 1, ok: 1 },
213
+ // { n: 0, nInserted: 0, nModified: 0, ok: 1 }
181
214
  // ]
182
215
  // select all [
183
216
  // {
@@ -189,8 +222,8 @@ test()
189
222
  // { id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 }
190
223
  // ]
191
224
  // select [ { id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 } ]
192
- // selectById { id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 }
193
- // selectById by id not existed null
225
+ // selectByPk { id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 }
226
+ // selectByPk by pk not existed null
194
227
  // select by $and, $gt, $lt [ { id: 'id-rosemary', name: 'rosemary(modify)', value: 123.456 } ]
195
228
  // select by $or, $gte, $lte [
196
229
  // {
@@ -212,7 +245,7 @@ test()
212
245
  // }
213
246
  // ]
214
247
  // change save
215
- // save then [ { n: 1, nModified: 1, ok: 1 } ]
248
+ // save then [ { n: 1, nInserted: 0, nModified: 1, ok: 1 } ]
216
249
  // change del
217
250
  // del then [ { n: 1, nDeleted: 1, ok: 1 } ]
218
251
  ```
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * req-mingo v1.0.12
2
+ * req-mingo v1.0.14
3
3
  * (c) 2018-2021 yuda-lyu(semisphere)
4
4
  * Released under the MIT License.
5
5
  */
@@ -1,7 +1,7 @@
1
1
  /*!
2
- * w-orm-lmdb v1.0.12
2
+ * w-orm-lmdb v1.0.14
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("lmdb"),require("mingo")):"function"==typeof define&&define.amd?define(["lmdb","mingo"],e):(t="undefined"!=typeof globalThis?globalThis:t||self)["w-orm-lmdb"]=e(t.lmdb,t.mingo)}(this,function(t,e){"use strict";function r(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var n=r(e),o=Object.prototype;function u(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||o)}function i(t,e){return function(r){return t(e(r))}}var c=i(Object.keys,Object),a=Object.prototype.hasOwnProperty;function f(t){if(!u(t))return c(t);var e=[];for(var r in Object(t))a.call(t,r)&&"constructor"!=r&&e.push(r);return e}var l="object"==typeof global&&global&&global.Object===Object&&global,s="object"==typeof self&&self&&self.Object===Object&&self,p=l||s||Function("return this")(),v=p.Symbol,y=Object.prototype,b=y.hasOwnProperty,h=y.toString,d=v?v.toStringTag:void 0;var j=Object.prototype.toString;var g=v?v.toStringTag:void 0;function _(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":g&&g in Object(t)?function(t){var e=b.call(t,d),r=t[d];try{t[d]=void 0;var n=!0}catch(t){}var o=h.call(t);return n&&(e?t[d]=r:delete t[d]),o}(t):function(t){return j.call(t)}(t)}function w(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}function m(t){if(!w(t))return!1;var e=_(t);return"[object Function]"==e||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e}var O,A=p["__core-js_shared__"],x=(O=/[^.]+$/.exec(A&&A.keys&&A.keys.IE_PROTO||""))?"Symbol(src)_1."+O:"";var S=Function.prototype.toString;function P(t){if(null!=t){try{return S.call(t)}catch(t){}try{return t+""}catch(t){}}return""}var k=/^\[object .+?Constructor\]$/,z=Function.prototype,I=Object.prototype,E=z.toString,$=I.hasOwnProperty,F=RegExp("^"+E.call($).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function M(t){return!(!w(t)||(e=t,x&&x in e))&&(m(t)?F:k).test(P(t));var e}function U(t,e){var r=function(t,e){return null==t?void 0:t[e]}(t,e);return M(r)?r:void 0}var N=U(p,"DataView"),D=U(p,"Map"),C=U(p,"Promise"),T=U(p,"Set"),B=U(p,"WeakMap"),L="[object Map]",R="[object Promise]",q="[object Set]",V="[object WeakMap]",W="[object DataView]",G=P(N),Q=P(D),J=P(C),H=P(T),K=P(B),X=_;(N&&X(new N(new ArrayBuffer(1)))!=W||D&&X(new D)!=L||C&&X(C.resolve())!=R||T&&X(new T)!=q||B&&X(new B)!=V)&&(X=function(t){var e=_(t),r="[object Object]"==e?t.constructor:void 0,n=r?P(r):"";if(n)switch(n){case G:return W;case Q:return L;case J:return R;case H:return q;case K:return V}return e});var Y=X;function Z(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991}function tt(t){return null!=t&&Z(t.length)&&!m(t)}var et=Array.isArray;function rt(t){return null!=t&&"object"==typeof t}function nt(t){return function(e){return null==e?void 0:e[t]}}var ot=nt("length"),ut=RegExp("[\\u200d\\ud800-\\udfff\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff\\ufe0e\\ufe0f]");var it="\\ud800-\\udfff",ct="["+it+"]",at="[\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff]",ft="\\ud83c[\\udffb-\\udfff]",lt="[^"+it+"]",st="(?:\\ud83c[\\udde6-\\uddff]){2}",pt="[\\ud800-\\udbff][\\udc00-\\udfff]",vt="(?:"+at+"|"+ft+")"+"?",yt="[\\ufe0e\\ufe0f]?",bt=yt+vt+("(?:\\u200d(?:"+[lt,st,pt].join("|")+")"+yt+vt+")*"),ht="(?:"+[lt+at+"?",at,st,pt,ct].join("|")+")",dt=RegExp(ft+"(?="+ft+")|"+ht+bt,"g");function jt(t){return function(t){return ut.test(t)}(t)?function(t){for(var e=dt.lastIndex=0;dt.test(t);)++e;return e}(t):ot(t)}function gt(t){if(null==t)return 0;if(tt(t))return"string"==typeof(e=t)||!et(e)&&rt(e)&&"[object String]"==_(e)?jt(t):t.length;var e,r=Y(t);return"[object Map]"==r||"[object Set]"==r?t.size:f(t).length}function _t(t){return"symbol"==typeof t||rt(t)&&"[object Symbol]"==_(t)}var wt=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,mt=/^\w*$/;function Ot(t,e){if(et(t))return!1;var r=typeof t;return!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=t&&!_t(t))||(mt.test(t)||!wt.test(t)||null!=e&&t in Object(e))}var At=U(Object,"create");var xt=Object.prototype.hasOwnProperty;var St=Object.prototype.hasOwnProperty;function Pt(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 kt(t,e){return t===e||t!=t&&e!=e}function zt(t,e){for(var r=t.length;r--;)if(kt(t[r][0],e))return r;return-1}Pt.prototype.clear=function(){this.__data__=At?At(null):{},this.size=0},Pt.prototype.delete=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},Pt.prototype.get=function(t){var e=this.__data__;if(At){var r=e[t];return"__lodash_hash_undefined__"===r?void 0:r}return xt.call(e,t)?e[t]:void 0},Pt.prototype.has=function(t){var e=this.__data__;return At?void 0!==e[t]:St.call(e,t)},Pt.prototype.set=function(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=At&&void 0===e?"__lodash_hash_undefined__":e,this};var It=Array.prototype.splice;function Et(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 $t(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 Ft(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])}}Et.prototype.clear=function(){this.__data__=[],this.size=0},Et.prototype.delete=function(t){var e=this.__data__,r=zt(e,t);return!(r<0)&&(r==e.length-1?e.pop():It.call(e,r,1),--this.size,!0)},Et.prototype.get=function(t){var e=this.__data__,r=zt(e,t);return r<0?void 0:e[r][1]},Et.prototype.has=function(t){return zt(this.__data__,t)>-1},Et.prototype.set=function(t,e){var r=this.__data__,n=zt(r,t);return n<0?(++this.size,r.push([t,e])):r[n][1]=e,this},Ft.prototype.clear=function(){this.size=0,this.__data__={hash:new Pt,map:new(D||Et),string:new Pt}},Ft.prototype.delete=function(t){var e=$t(this,t).delete(t);return this.size-=e?1:0,e},Ft.prototype.get=function(t){return $t(this,t).get(t)},Ft.prototype.has=function(t){return $t(this,t).has(t)},Ft.prototype.set=function(t,e){var r=$t(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,this};function Mt(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],u=r.cache;if(u.has(o))return u.get(o);var i=t.apply(this,n);return r.cache=u.set(o,i)||u,i};return r.cache=new(Mt.Cache||Ft),r}Mt.Cache=Ft;var Ut,Nt,Dt,Ct=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Tt=/\\(\\)?/g,Bt=(Ut=function(t){var e=[];return 46===t.charCodeAt(0)&&e.push(""),t.replace(Ct,function(t,r,n,o){e.push(n?o.replace(Tt,"$1"):r||t)}),e},Nt=Mt(Ut,function(t){return 500===Dt.size&&Dt.clear(),t}),Dt=Nt.cache,Nt),Lt=Bt;function Rt(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 qt=v?v.prototype:void 0,Vt=qt?qt.toString:void 0;function Wt(t){if("string"==typeof t)return t;if(et(t))return Rt(t,Wt)+"";if(_t(t))return Vt?Vt.call(t):"";var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}function Gt(t){return null==t?"":Wt(t)}function Qt(t,e){return et(t)?t:Ot(t,e)?[t]:Lt(Gt(t))}function Jt(t){if("string"==typeof t||_t(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}function Ht(t,e){for(var r=0,n=(e=Qt(e,t)).length;null!=t&&r<n;)t=t[Jt(e[r++])];return r&&r==n?t:void 0}function Kt(t,e,r){var n=null==t?void 0:Ht(t,e);return void 0===n?r:n}function Xt(t,e){for(var r=-1,n=null==t?0:t.length;++r<n&&!1!==e(t[r],r,t););return t}var Yt,Zt=function(t,e,r){for(var n=-1,o=Object(t),u=r(t),i=u.length;i--;){var c=u[Yt?i:++n];if(!1===e(o[c],c,o))break}return t};function te(t){return rt(t)&&"[object Arguments]"==_(t)}var ee=Object.prototype,re=ee.hasOwnProperty,ne=ee.propertyIsEnumerable,oe=te(function(){return arguments}())?te:function(t){return rt(t)&&re.call(t,"callee")&&!ne.call(t,"callee")},ue=oe;var ie="object"==typeof exports&&exports&&!exports.nodeType&&exports,ce=ie&&"object"==typeof module&&module&&!module.nodeType&&module,ae=ce&&ce.exports===ie?p.Buffer:void 0,fe=(ae?ae.isBuffer:void 0)||function(){return!1},le=/^(?:0|[1-9]\d*)$/;function se(t,e){var r=typeof t;return!!(e=null==e?9007199254740991:e)&&("number"==r||"symbol"!=r&&le.test(t))&&t>-1&&t%1==0&&t<e}var pe={};function ve(t){return function(e){return t(e)}}pe["[object Float32Array]"]=pe["[object Float64Array]"]=pe["[object Int8Array]"]=pe["[object Int16Array]"]=pe["[object Int32Array]"]=pe["[object Uint8Array]"]=pe["[object Uint8ClampedArray]"]=pe["[object Uint16Array]"]=pe["[object Uint32Array]"]=!0,pe["[object Arguments]"]=pe["[object Array]"]=pe["[object ArrayBuffer]"]=pe["[object Boolean]"]=pe["[object DataView]"]=pe["[object Date]"]=pe["[object Error]"]=pe["[object Function]"]=pe["[object Map]"]=pe["[object Number]"]=pe["[object Object]"]=pe["[object RegExp]"]=pe["[object Set]"]=pe["[object String]"]=pe["[object WeakMap]"]=!1;var ye="object"==typeof exports&&exports&&!exports.nodeType&&exports,be=ye&&"object"==typeof module&&module&&!module.nodeType&&module,he=be&&be.exports===ye&&l.process,de=function(){try{var t=be&&be.require&&be.require("util").types;return t||he&&he.binding&&he.binding("util")}catch(t){}}(),je=de&&de.isTypedArray,ge=je?ve(je):function(t){return rt(t)&&Z(t.length)&&!!pe[_(t)]},_e=Object.prototype.hasOwnProperty;function we(t,e){var r=et(t),n=!r&&ue(t),o=!r&&!n&&fe(t),u=!r&&!n&&!o&&ge(t),i=r||n||o||u,c=i?function(t,e){for(var r=-1,n=Array(t);++r<t;)n[r]=e(r);return n}(t.length,String):[],a=c.length;for(var f in t)!e&&!_e.call(t,f)||i&&("length"==f||o&&("offset"==f||"parent"==f)||u&&("buffer"==f||"byteLength"==f||"byteOffset"==f)||se(f,a))||c.push(f);return c}function me(t){return tt(t)?we(t):f(t)}var Oe=function(t,e){return function(r,n){if(null==r)return r;if(!tt(r))return t(r,n);for(var o=r.length,u=e?o:-1,i=Object(r);(e?u--:++u<o)&&!1!==n(i[u],u,i););return r}}(function(t,e){return t&&Zt(t,e,me)}),Ae=Oe;function xe(t){return t}function Se(t,e){var r;return(et(t)?Xt:Ae)(t,"function"==typeof(r=e)?r:xe)}function Pe(t){var e=this.__data__=new Et(t);this.size=e.size}Pe.prototype.clear=function(){this.__data__=new Et,this.size=0},Pe.prototype.delete=function(t){var e=this.__data__,r=e.delete(t);return this.size=e.size,r},Pe.prototype.get=function(t){return this.__data__.get(t)},Pe.prototype.has=function(t){return this.__data__.has(t)},Pe.prototype.set=function(t,e){var r=this.__data__;if(r instanceof Et){var n=r.__data__;if(!D||n.length<199)return n.push([t,e]),this.size=++r.size,this;r=this.__data__=new Ft(n)}return r.set(t,e),this.size=r.size,this};function ke(t){var e=-1,r=null==t?0:t.length;for(this.__data__=new Ft;++e<r;)this.add(t[e])}function ze(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 Ie(t,e){return t.has(e)}ke.prototype.add=ke.prototype.push=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this},ke.prototype.has=function(t){return this.__data__.has(t)};function Ee(t,e,r,n,o,u){var i=1&r,c=t.length,a=e.length;if(c!=a&&!(i&&a>c))return!1;var f=u.get(t),l=u.get(e);if(f&&l)return f==e&&l==t;var s=-1,p=!0,v=2&r?new ke:void 0;for(u.set(t,e),u.set(e,t);++s<c;){var y=t[s],b=e[s];if(n)var h=i?n(b,y,s,e,t,u):n(y,b,s,t,e,u);if(void 0!==h){if(h)continue;p=!1;break}if(v){if(!ze(e,function(t,e){if(!Ie(v,e)&&(y===t||o(y,t,r,n,u)))return v.push(e)})){p=!1;break}}else if(y!==b&&!o(y,b,r,n,u)){p=!1;break}}return u.delete(t),u.delete(e),p}var $e=p.Uint8Array;function Fe(t){var e=-1,r=Array(t.size);return t.forEach(function(t,n){r[++e]=[n,t]}),r}function Me(t){var e=-1,r=Array(t.size);return t.forEach(function(t){r[++e]=t}),r}var Ue=v?v.prototype:void 0,Ne=Ue?Ue.valueOf:void 0;function De(t,e){for(var r=-1,n=e.length,o=t.length;++r<n;)t[o+r]=e[r];return t}function Ce(t,e,r){var n=e(t);return et(t)?n:De(n,r(t))}function Te(){return[]}var Be=Object.prototype.propertyIsEnumerable,Le=Object.getOwnPropertySymbols,Re=Le?function(t){return null==t?[]:(t=Object(t),function(t,e){for(var r=-1,n=null==t?0:t.length,o=0,u=[];++r<n;){var i=t[r];e(i,r,t)&&(u[o++]=i)}return u}(Le(t),function(e){return Be.call(t,e)}))}:Te,qe=Re;function Ve(t){return Ce(t,me,qe)}var We=Object.prototype.hasOwnProperty;var Ge="[object Arguments]",Qe="[object Array]",Je="[object Object]",He=Object.prototype.hasOwnProperty;function Ke(t,e,r,n,o,u){var i=et(t),c=et(e),a=i?Qe:Y(t),f=c?Qe:Y(e),l=(a=a==Ge?Je:a)==Je,s=(f=f==Ge?Je:f)==Je,p=a==f;if(p&&fe(t)){if(!fe(e))return!1;i=!0,l=!1}if(p&&!l)return u||(u=new Pe),i||ge(t)?Ee(t,e,r,n,o,u):function(t,e,r,n,o,u,i){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||!u(new $e(t),new $e(e)));case"[object Boolean]":case"[object Date]":case"[object Number]":return kt(+t,+e);case"[object Error]":return t.name==e.name&&t.message==e.message;case"[object RegExp]":case"[object String]":return t==e+"";case"[object Map]":var c=Fe;case"[object Set]":var a=1&n;if(c||(c=Me),t.size!=e.size&&!a)return!1;var f=i.get(t);if(f)return f==e;n|=2,i.set(t,e);var l=Ee(c(t),c(e),n,o,u,i);return i.delete(t),l;case"[object Symbol]":if(Ne)return Ne.call(t)==Ne.call(e)}return!1}(t,e,a,r,n,o,u);if(!(1&r)){var v=l&&He.call(t,"__wrapped__"),y=s&&He.call(e,"__wrapped__");if(v||y){var b=v?t.value():t,h=y?e.value():e;return u||(u=new Pe),o(b,h,r,n,u)}}return!!p&&(u||(u=new Pe),function(t,e,r,n,o,u){var i=1&r,c=Ve(t),a=c.length;if(a!=Ve(e).length&&!i)return!1;for(var f=a;f--;){var l=c[f];if(!(i?l in e:We.call(e,l)))return!1}var s=u.get(t),p=u.get(e);if(s&&p)return s==e&&p==t;var v=!0;u.set(t,e),u.set(e,t);for(var y=i;++f<a;){var b=t[l=c[f]],h=e[l];if(n)var d=i?n(h,b,l,e,t,u):n(b,h,l,t,e,u);if(!(void 0===d?b===h||o(b,h,r,n,u):d)){v=!1;break}y||(y="constructor"==l)}if(v&&!y){var j=t.constructor,g=e.constructor;j==g||!("constructor"in t)||!("constructor"in e)||"function"==typeof j&&j instanceof j&&"function"==typeof g&&g instanceof g||(v=!1)}return u.delete(t),u.delete(e),v}(t,e,r,n,o,u))}function Xe(t,e,r,n,o){return t===e||(null==t||null==e||!rt(t)&&!rt(e)?t!=t&&e!=e:Ke(t,e,r,n,Xe,o))}function Ye(t){return t==t&&!w(t)}function Ze(t,e){return function(r){return null!=r&&(r[t]===e&&(void 0!==e||t in Object(r)))}}function tr(t){var e=function(t){for(var e=me(t),r=e.length;r--;){var n=e[r],o=t[n];e[r]=[n,o,Ye(o)]}return e}(t);return 1==e.length&&e[0][2]?Ze(e[0][0],e[0][1]):function(r){return r===t||function(t,e,r,n){var o=r.length,u=o,i=!n;if(null==t)return!u;for(t=Object(t);o--;){var c=r[o];if(i&&c[2]?c[1]!==t[c[0]]:!(c[0]in t))return!1}for(;++o<u;){var a=(c=r[o])[0],f=t[a],l=c[1];if(i&&c[2]){if(void 0===f&&!(a in t))return!1}else{var s=new Pe;if(n)var p=n(f,l,a,t,e,s);if(!(void 0===p?Xe(l,f,3,n,s):p))return!1}}return!0}(r,t,e)}}function er(t,e){return null!=t&&e in Object(t)}function rr(t,e){return null!=t&&function(t,e,r){for(var n=-1,o=(e=Qt(e,t)).length,u=!1;++n<o;){var i=Jt(e[n]);if(!(u=null!=t&&r(t,i)))break;t=t[i]}return u||++n!=o?u:!!(o=null==t?0:t.length)&&Z(o)&&se(i,o)&&(et(t)||ue(t))}(t,e,er)}function nr(t){return Ot(t)?nt(Jt(t)):function(t){return function(e){return Ht(e,t)}}(t)}function or(t){return"function"==typeof t?t:null==t?xe:"object"==typeof t?et(t)?(e=t[0],r=t[1],Ot(e)&&Ye(r)?Ze(Jt(e),r):function(t){var n=Kt(t,e);return void 0===n&&n===r?rr(t,e):Xe(r,n,3)}):tr(t):nr(t);var e,r}function ur(t,e){var r=-1,n=tt(t)?Array(t.length):[];return Ae(t,function(t,o,u){n[++r]=e(t,o,u)}),n}function ir(t,e){return(et(t)?Rt:ur)(t,or(e))}var cr=function(){try{var t=U(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),ar=cr;function fr(t,e,r){"__proto__"==e&&ar?ar(t,e,{configurable:!0,enumerable:!0,value:r,writable:!0}):t[e]=r}function lr(t,e,r){(void 0!==r&&!kt(t[e],r)||void 0===r&&!(e in t))&&fr(t,e,r)}var sr="object"==typeof exports&&exports&&!exports.nodeType&&exports,pr=sr&&"object"==typeof module&&module&&!module.nodeType&&module,vr=pr&&pr.exports===sr?p.Buffer:void 0,yr=vr?vr.allocUnsafe:void 0;function br(t,e){if(e)return t.slice();var r=t.length,n=yr?yr(r):new t.constructor(r);return t.copy(n),n}function hr(t){var e=new t.constructor(t.byteLength);return new $e(e).set(new $e(t)),e}function dr(t,e){var r=e?hr(t.buffer):t.buffer;return new t.constructor(r,t.byteOffset,t.length)}function jr(t,e){var r=-1,n=t.length;for(e||(e=Array(n));++r<n;)e[r]=t[r];return e}var gr=Object.create,_r=function(){function t(){}return function(e){if(!w(e))return{};if(gr)return gr(e);t.prototype=e;var r=new t;return t.prototype=void 0,r}}(),wr=_r,mr=i(Object.getPrototypeOf,Object);function Or(t){return"function"!=typeof t.constructor||u(t)?{}:wr(mr(t))}var Ar=Function.prototype,xr=Object.prototype,Sr=Ar.toString,Pr=xr.hasOwnProperty,kr=Sr.call(Object);function zr(t,e){if(("constructor"!==e||"function"!=typeof t[e])&&"__proto__"!=e)return t[e]}var Ir=Object.prototype.hasOwnProperty;function Er(t,e,r){var n=t[e];Ir.call(t,e)&&kt(n,r)&&(void 0!==r||e in t)||fr(t,e,r)}function $r(t,e,r,n){var o=!r;r||(r={});for(var u=-1,i=e.length;++u<i;){var c=e[u],a=n?n(r[c],t[c],c,r,t):void 0;void 0===a&&(a=t[c]),o?fr(r,c,a):Er(r,c,a)}return r}var Fr=Object.prototype.hasOwnProperty;function Mr(t){if(!w(t))return function(t){var e=[];if(null!=t)for(var r in Object(t))e.push(r);return e}(t);var e=u(t),r=[];for(var n in t)("constructor"!=n||!e&&Fr.call(t,n))&&r.push(n);return r}function Ur(t){return tt(t)?we(t,!0):Mr(t)}function Nr(t,e,r,n,o,u,i){var c=zr(t,r),a=zr(e,r),f=i.get(a);if(f)lr(t,r,f);else{var l,s=u?u(c,a,r+"",t,e,i):void 0,p=void 0===s;if(p){var v=et(a),y=!v&&fe(a),b=!v&&!y&&ge(a);s=a,v||y||b?et(c)?s=c:rt(l=c)&&tt(l)?s=jr(c):y?(p=!1,s=br(a,!0)):b?(p=!1,s=dr(a,!0)):s=[]:function(t){if(!rt(t)||"[object Object]"!=_(t))return!1;var e=mr(t);if(null===e)return!0;var r=Pr.call(e,"constructor")&&e.constructor;return"function"==typeof r&&r instanceof r&&Sr.call(r)==kr}(a)||ue(a)?(s=c,ue(c)?s=function(t){return $r(t,Ur(t))}(c):w(c)&&!m(c)||(s=Or(a))):p=!1}p&&(i.set(a,s),o(s,a,n,u,i),i.delete(a)),lr(t,r,s)}}function Dr(t,e,r,n,o){t!==e&&Zt(e,function(u,i){if(o||(o=new Pe),w(u))Nr(t,e,i,r,Dr,n,o);else{var c=n?n(zr(t,i),u,i+"",t,e,o):void 0;void 0===c&&(c=u),lr(t,i,c)}},Ur)}var Cr=Math.max;var Tr=ar?function(t,e){return ar(t,"toString",{configurable:!0,enumerable:!1,value:(r=e,function(){return r}),writable:!0});var r}:xe,Br=Tr,Lr=Date.now;var Rr=function(t){var e=0,r=0;return function(){var n=Lr(),o=16-(n-r);if(r=n,o>0){if(++e>=800)return arguments[0]}else e=0;return t.apply(void 0,arguments)}}(Br),qr=Rr;function Vr(t,e){return qr(function(t,e,r){return e=Cr(void 0===e?t.length-1:e,0),function(){for(var n=arguments,o=-1,u=Cr(n.length-e,0),i=Array(u);++o<u;)i[o]=n[e+o];o=-1;for(var c=Array(e+1);++o<e;)c[o]=n[o];return c[e]=r(i),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,c)}}(t,e,xe),t+"")}var Wr,Gr=(Wr=function(t,e,r){Dr(t,e,r)},Vr(function(t,e){var r=-1,n=e.length,o=n>1?e[n-1]:void 0,u=n>2?e[2]:void 0;for(o=Wr.length>3&&"function"==typeof o?(n--,o):void 0,u&&function(t,e,r){if(!w(r))return!1;var n=typeof e;return!!("number"==n?tt(r)&&se(e,r.length):"string"==n&&e in r)&&kt(r[e],t)}(e[0],e[1],u)&&(o=n<3?void 0:o,n=1),t=Object(t);++r<n;){var i=e[r];i&&Wr(t,i,r,o)}return t}));function Qr(t,e){return Xe(t,e)}var Jr=Object.getOwnPropertySymbols?function(t){for(var e=[];t;)De(e,qe(t)),t=mr(t);return e}:Te,Hr=Jr;function Kr(t){return Ce(t,Ur,Hr)}var Xr=Object.prototype.hasOwnProperty;var Yr=/\w*$/;var Zr=v?v.prototype:void 0,tn=Zr?Zr.valueOf:void 0;function en(t,e,r){var n,o=t.constructor;switch(e){case"[object ArrayBuffer]":return hr(t);case"[object Boolean]":case"[object Date]":return new o(+t);case"[object DataView]":return function(t,e){var r=e?hr(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 dr(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,Yr.exec(t));return e.lastIndex=t.lastIndex,e}(t);case"[object Symbol]":return n=t,tn?Object(tn.call(n)):{}}}var rn=de&&de.isMap,nn=rn?ve(rn):function(t){return rt(t)&&"[object Map]"==Y(t)};var on=de&&de.isSet,un=on?ve(on):function(t){return rt(t)&&"[object Set]"==Y(t)},cn="[object Arguments]",an="[object Function]",fn="[object Object]",ln={};function sn(t,e,r,n,o,u){var i,c=1&e,a=2&e,f=4&e;if(r&&(i=o?r(t,n,o,u):r(t)),void 0!==i)return i;if(!w(t))return t;var l=et(t);if(l){if(i=function(t){var e=t.length,r=new t.constructor(e);return e&&"string"==typeof t[0]&&Xr.call(t,"index")&&(r.index=t.index,r.input=t.input),r}(t),!c)return jr(t,i)}else{var s=Y(t),p=s==an||"[object GeneratorFunction]"==s;if(fe(t))return br(t,c);if(s==fn||s==cn||p&&!o){if(i=a||p?{}:Or(t),!c)return a?function(t,e){return $r(t,Hr(t),e)}(t,function(t,e){return t&&$r(e,Ur(e),t)}(i,t)):function(t,e){return $r(t,qe(t),e)}(t,function(t,e){return t&&$r(e,me(e),t)}(i,t))}else{if(!ln[s])return o?t:{};i=en(t,s,c)}}u||(u=new Pe);var v=u.get(t);if(v)return v;u.set(t,i),un(t)?t.forEach(function(n){i.add(sn(n,e,r,n,t,u))}):nn(t)&&t.forEach(function(n,o){i.set(o,sn(n,e,r,o,t,u))});var y=l?void 0:(f?a?Kr:Ve:a?Ur:me)(t);return Xt(y||t,function(n,o){y&&(n=t[o=n]),Er(i,o,sn(n,e,r,o,t,u))}),i}ln[cn]=ln["[object Array]"]=ln["[object ArrayBuffer]"]=ln["[object DataView]"]=ln["[object Boolean]"]=ln["[object Date]"]=ln["[object Float32Array]"]=ln["[object Float64Array]"]=ln["[object Int8Array]"]=ln["[object Int16Array]"]=ln["[object Int32Array]"]=ln["[object Map]"]=ln["[object Number]"]=ln[fn]=ln["[object RegExp]"]=ln["[object Set]"]=ln["[object String]"]=ln["[object Symbol]"]=ln["[object Uint8Array]"]=ln["[object Uint8ClampedArray]"]=ln["[object Uint16Array]"]=ln["[object Uint32Array]"]=!0,ln["[object Error]"]=ln[an]=ln["[object WeakMap]"]=!1;function pn(t){return sn(t,5)}function vn(t){return"[object String]"===Object.prototype.toString.call(t)}function yn(t){return!(!vn(t)||""===t)}function bn(t){return"[object Array]"===Object.prototype.toString.call(t)}function hn(t){return"[object Object]"===Object.prototype.toString.call(t)}function dn(t){return t!=t}function jn(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(hn(t)){for(let e in t)return!1;return!0}return!1}(t)||(!!function(t){return!(!vn(t)||""!==t)}(t)||(!!function(t){return!!bn(t)&&0===t.length}(t)||!!dn(t)))))}function gn(t){return!!bn(t)&&(0!==t.length&&(1!==t.length||!jn(t[0])))}function _n(t){if(hn(t)){for(let e in t)return!0;return!1}return!1}function wn(t){return!0===(e=t)||!1===e||rt(e)&&"[object Boolean]"==_(e);var e}function mn(t){let e=!1;if(yn(t))e=!isNaN(Number(t));else if(function(t){return"[object Number]"===Object.prototype.toString.call(t)}(t)){if(dn(t))return!1;e=!0}return e}function On(t,e){return!!hn(t)&&(!(!yn(e)&&!mn(e))&&e in t)}var An={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 u(t,e,n,u,i){if("function"!=typeof n)throw new TypeError("The listener must be a function");var c=new o(n,u||t,i),a=r?r+e:e;return t._events[a]?t._events[a].fn?t._events[a]=[t._events[a],c]:t._events[a].push(c):(t._events[a]=c,t._eventsCount++),t}function i(t,e){0===--t._eventsCount?t._events=new n:delete t._events[e]}function c(){this._events=new n,this._eventsCount=0}Object.create&&(n.prototype=Object.create(null),(new n).__proto__||(r=!1)),c.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},c.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,u=n.length,i=new Array(u);o<u;o++)i[o]=n[o].fn;return i},c.prototype.listenerCount=function(t){var e=r?r+t:t,n=this._events[e];return n?n.fn?1:n.length:0},c.prototype.emit=function(t,e,n,o,u,i){var c=r?r+t:t;if(!this._events[c])return!1;var a,f,l=this._events[c],s=arguments.length;if(l.fn){switch(l.once&&this.removeListener(t,l.fn,void 0,!0),s){case 1:return l.fn.call(l.context),!0;case 2:return l.fn.call(l.context,e),!0;case 3:return l.fn.call(l.context,e,n),!0;case 4:return l.fn.call(l.context,e,n,o),!0;case 5:return l.fn.call(l.context,e,n,o,u),!0;case 6:return l.fn.call(l.context,e,n,o,u,i),!0}for(f=1,a=new Array(s-1);f<s;f++)a[f-1]=arguments[f];l.fn.apply(l.context,a)}else{var p,v=l.length;for(f=0;f<v;f++)switch(l[f].once&&this.removeListener(t,l[f].fn,void 0,!0),s){case 1:l[f].fn.call(l[f].context);break;case 2:l[f].fn.call(l[f].context,e);break;case 3:l[f].fn.call(l[f].context,e,n);break;case 4:l[f].fn.call(l[f].context,e,n,o);break;default:if(!a)for(p=1,a=new Array(s-1);p<s;p++)a[p-1]=arguments[p];l[f].fn.apply(l[f].context,a)}}return!0},c.prototype.on=function(t,e,r){return u(this,t,e,r,!1)},c.prototype.once=function(t,e,r){return u(this,t,e,r,!0)},c.prototype.removeListener=function(t,e,n,o){var u=r?r+t:t;if(!this._events[u])return this;if(!e)return i(this,u),this;var c=this._events[u];if(c.fn)c.fn!==e||o&&!c.once||n&&c.context!==n||i(this,u);else{for(var a=0,f=[],l=c.length;a<l;a++)(c[a].fn!==e||o&&!c[a].once||n&&c[a].context!==n)&&f.push(c[a]);f.length?this._events[u]=1===f.length?f[0]:f:i(this,u)}return this},c.prototype.removeAllListeners=function(t){var e;return t?(e=r?r+t:t,this._events[e]&&i(this,e)):(this._events=new n,this._eventsCount=0),this},c.prototype.off=c.prototype.removeListener,c.prototype.addListener=c.prototype.on,c.prefixed=r,c.EventEmitter=c,t.exports=c}(An);var xn=r(An.exports);const Sn=[];for(let t=0;t<256;++t)Sn.push((t+256).toString(16).slice(1));const Pn=new Uint8Array(16);function kn(){return crypto.getRandomValues(Pn)}const zn={};function In(t,e,r){let n;if(t)n=En(t.random??t.rng?.()??kn(),t.msecs,t.seq,e,r);else{const t=Date.now(),o=kn();!function(t,e,r){t.msecs??=-1/0,t.seq??=0,e>t.msecs?(t.seq=r[6]<<23|r[7]<<16|r[8]<<8|r[9],t.msecs=e):(t.seq=t.seq+1|0,0===t.seq&&t.msecs++)}(zn,t,o),n=En(o,zn.msecs,zn.seq,e,r)}return e??function(t,e=0){return(Sn[t[e+0]]+Sn[t[e+1]]+Sn[t[e+2]]+Sn[t[e+3]]+"-"+Sn[t[e+4]]+Sn[t[e+5]]+"-"+Sn[t[e+6]]+Sn[t[e+7]]+"-"+Sn[t[e+8]]+Sn[t[e+9]]+"-"+Sn[t[e+10]]+Sn[t[e+11]]+Sn[t[e+12]]+Sn[t[e+13]]+Sn[t[e+14]]+Sn[t[e+15]]).toLowerCase()}(n)}function En(t,e,r,n,o=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??=127*t[6]<<24|t[7]<<16|t[8]<<8|t[9],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 $n(){return In()}var Fn=/\s/;var Mn=/^\s+/;function Un(t){return t?t.slice(0,function(t){for(var e=t.length;e--&&Fn.test(t.charAt(e)););return e}(t)+1).replace(Mn,""):t}var Nn=/^[-+]0x[0-9a-f]+$/i,Dn=/^0b[01]+$/i,Cn=/^0o[0-7]+$/i,Tn=parseInt;function Bn(t){if("number"==typeof t)return t;if(_t(t))return NaN;if(w(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=w(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=Un(t);var r=Dn.test(t);return r||Cn.test(t)?Tn(t.slice(2),r?2:8):Nn.test(t)?NaN:+t}var Ln=1/0;function Rn(t){return t?(t=Bn(t))===Ln||t===-1/0?17976931348623157e292*(t<0?-1:1):t==t?t:0:0===t?t:0}function qn(t){var e=Rn(t),r=e%1;return e==e?r?e-r:e:0}function Vn(t,e,r){var n=null==t?0:t.length;return n?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 u=Array(o);++n<o;)u[n]=t[n+e];return u}(t,(e=r||void 0===e?1:qn(e))<0?0:e,n):[]}function Wn(){let t,e,r=new Promise(function(){t=arguments[0],e=arguments[1]});return r.resolve=t,r.reject=e,r}function Gn(t){let e=Object.prototype.toString.call(t);return"[object Function]"===e||"[object AsyncFunction]"===e}function Qn(t,e){let r=Wn();if(!bn(t)&&!hn(t))return r.reject("rs is not an array or object"),r;let n=!1;if(hn(t)){n=!0;let e=[];Se(t,(t,r)=>{e.push({k:r,v:t})}),t=e}Gn(e)||(e=function(t){return t});let o=-1,u=[];return t.reduce(function(t,r){return t.then(function(t){u.push(t),o+=1;let i=o,c=r;return n&&(i=r.k,c=r.v),Gn(e)?e(c,i):c})},Promise.resolve()).then(function(t){u.push(t),u=Vn(u),r.resolve(u)}).catch(function(t){r.reject(t)}),r}function Jn(t){if(!mn(t))return 0;return Rn(t)}function Hn(t){return!!mn(t)&&(t=Jn(t),"number"==typeof(e=t)&&e==qn(e));var e}var Kn=p.isFinite,Xn=Math.min;var Yn=function(t){var e=Math[t];return function(t,r){if(t=Bn(t),(r=null==r?0:Xn(qn(r),292))&&Kn(t)){var n=(Gt(t)+"e").split("e");return+((n=(Gt(e(n[0]+"e"+(+n[1]+r)))+"e").split("e"))[0]+"e"+(+n[1]-r))}return e(t)}}("round"),Zn=Yn;function to(t){if(!Hn(t))return!1;let e=function(t){if(!mn(t))return 0;t=Jn(t);let e=Zn(t);return"0"===String(e)?0:e}(t)>0;return e}async function eo(t,e={}){let r=null,n=Wn();if(!Gn(t))return n.reject("waitfunction需輸入函數f"),n;let o=async()=>{let e=t();return function(t){let e,r=Object.prototype.toString.call(t);if(e="[object Promise]"===r,e)return!0;if("[object Function]"!==r)return!1;try{e="function"!=typeof t.subscribe&&"function"==typeof t.then}catch(t){}return e}(e)&&(e=await e),e};if(r=await o(),!0===r)return n.resolve(),n;let u=Kt(e,"attemptNum",null);to(u)||(u=200);let i=Kt(e,"timeInterval",null);to(i)||(i=1e3);let c=0,a=setInterval(async()=>{c+=1,r=await o(),!0===r&&(clearInterval(a),n.resolve()),c>u&&(clearInterval(a),n.reject(`exceeded attemptNum[${u}]`))},i);return n}return function(e={}){let r=null,o=Kt(e,"url");yn(o)||(o="./_db");let u=Kt(e,"db");yn(u)||(u="worm");let i=Kt(e,"cl");yn(i)||(i="test");let c=Kt(e,"useCache");wn(c)||(c=!1);let a=`${o}/${u}/${i}`,f=t.open({path:a,compression:!0,useVersions:!0}),l=new xn,s=async()=>{if(c&&bn(r))return pn(r);await p();let t=[];for await(let{value:e}of f.getRange())t.push(e);return c?(r=t,pn(t)):t},p=async()=>{await eo(()=>("closed"===f.status&&console.log(`client.status[${f.status}], level is closed`),"open"===f.status))},v=async t=>{let e=null;try{e=await f.get(t)}catch(t){}return e};return l.select=async function(t={}){let e=!1,r=null;try{let o=await s();if(_n(t)){r=new n.Query(t).find(o).all()}else r=o;bn(r)||(e=!0,r=`can not select by find[${JSON.stringify(t)}]`)}catch(t){e=!0,r=t}return e?Promise.reject(r):r},l.selectById=async function(t){let e=!1,r=null;try{if(!yn(t))return null;await p();let e=await v(t);r=_n(e)?e:null}catch(t){e=!0,r=t}return e?Promise.reject(r):r},l.insert=async function(t){let e=!1;if(!_n(t)&&!gn(t))return{n:0,nInserted:0,ok:1};t=pn(t);let n=null;try{bn(t)||(t=[t]);let e=gt(t=ir(t,function(t){return yn(t.id)||(t.id=$n()),t})),r=await Promise.all(ir(t,function(t){return f.ifNoExists(t.id,()=>{f.put(t.id,t)})})),o=0;Se(r,function(t){t&&o++}),n={n:e,nInserted:o,ok:1}}catch(t){e=!0,n=t}if(r=null,!e)try{l.emit("change","insert",t,n)}catch(t){console.log(t)}return e?Promise.reject(n):n},l.save=async function(t,e={}){let n=!1;if(!_n(t)&&!gn(t))return[];t=pn(t);let o=Kt(e,"autoInsert",!0),u=null;try{bn(t)||(t=[t]),t=ir(t,function(t){return yn(t.id)||(t.id=$n()),t}),u=await Qn(t,async t=>{let e=null,n=await v(t.id);if(_n(n)&&Qr(t,n))return{n:0,nModified:0,ok:1};let u=!1,i=!1,c=!1;if(await f.transaction(()=>{let e=f.get(t.id);u=_n(e),u?Qr(t,e)||(f.put(t.id,Gr(e,t)),i=!0):o&&(f.put(t.id,t),c=!0)}),e=c?{n:1,nInserted:1,ok:1}:i?{n:1,nModified:1,ok:1}:{n:0,nModified:0,ok:1},c){r=null;try{l.emit("change","insert",[t],e)}catch(t){console.log(t)}}return e})}catch(t){n=!0,u=t}if(r=null,!n)try{l.emit("change","save",t,u)}catch(t){console.log(t)}return n?Promise.reject(u):u},l.del=async function(t){let e=!1;if(!_n(t)&&!gn(t))return[];t=pn(t);let n=null;try{bn(t)||(t=[t]),n=await Qn(t,async t=>{let e=null;if(yn(Kt(t,"id",""))){_n(await v(t.id))?(await f.del(t.id),e={n:1,nDeleted:1,ok:1}):e={n:1,nDeleted:0,ok:1}}else e={n:1,nDeleted:0,ok:0};return e})}catch(t){e=!0,n=t}if(r=null,!e)try{l.emit("change","del",t,n)}catch(t){console.log(t)}return e?Promise.reject(n):n},l.delAll=async function(t={}){let e=!1,o=null;try{let e=await s(),r=gt(e),u=0;if(_n(t)){let o=new n.Query(t).find(e).all();if(u=gt(o),0===u);else if(r===u)for(let t of e)await f.del(t.id);else{let t={};Se(o,(e,r)=>{t[e.id]={k:r,v:e}});for(let r of e)On(t,r.id)&&await f.del(r.id)}}else{u=r;for(let t of e)await f.del(t.id)}o={n:r,nDeleted:u,ok:1}}catch(t){e=!0,o=t}if(r=null,!e)try{l.emit("change","delAll",null,o)}catch(t){console.log(t)}return e?Promise.reject(o):o},l.close=async()=>{f&&"closed"!==f.status&&await f.close()},l}});
6
+ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("lmdb"),require("mingo")):"function"==typeof define&&define.amd?define(["lmdb","mingo"],e):(t="undefined"!=typeof globalThis?globalThis:t||self)["w-orm-lmdb"]=e(t.lmdb,t.mingo)}(this,function(t,e){"use strict";function n(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}var r=n(e),o=Object.prototype;function u(t){var e=t&&t.constructor;return t===("function"==typeof e&&e.prototype||o)}function i(t,e){return function(n){return t(e(n))}}var c=i(Object.keys,Object),a=Object.prototype.hasOwnProperty;function f(t){if(!u(t))return c(t);var e=[];for(var n in Object(t))a.call(t,n)&&"constructor"!=n&&e.push(n);return e}var l="object"==typeof global&&global&&global.Object===Object&&global,s="object"==typeof self&&self&&self.Object===Object&&self,p=l||s||Function("return this")(),v=p.Symbol,y=Object.prototype,b=y.hasOwnProperty,h=y.toString,d=v?v.toStringTag:void 0;var j=Object.prototype.toString;var g=v?v.toStringTag:void 0;function _(t){return null==t?void 0===t?"[object Undefined]":"[object Null]":g&&g in Object(t)?function(t){var e=b.call(t,d),n=t[d];try{t[d]=void 0;var r=!0}catch(t){}var o=h.call(t);return r&&(e?t[d]=n:delete t[d]),o}(t):function(t){return j.call(t)}(t)}function w(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}function m(t){if(!w(t))return!1;var e=_(t);return"[object Function]"==e||"[object GeneratorFunction]"==e||"[object AsyncFunction]"==e||"[object Proxy]"==e}var O,A=p["__core-js_shared__"],x=(O=/[^.]+$/.exec(A&&A.keys&&A.keys.IE_PROTO||""))?"Symbol(src)_1."+O:"";var S=Function.prototype.toString;function P(t){if(null!=t){try{return S.call(t)}catch(t){}try{return t+""}catch(t){}}return""}var k=/^\[object .+?Constructor\]$/,I=Function.prototype,z=Object.prototype,E=I.toString,$=z.hasOwnProperty,M=RegExp("^"+E.call($).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");function F(t){return!(!w(t)||(e=t,x&&x in e))&&(m(t)?M:k).test(P(t));var e}function U(t,e){var n=function(t,e){return null==t?void 0:t[e]}(t,e);return F(n)?n:void 0}var D=U(p,"DataView"),N=U(p,"Map"),C=U(p,"Promise"),T=U(p,"Set"),B=U(p,"WeakMap"),L="[object Map]",R="[object Promise]",q="[object Set]",V="[object WeakMap]",W="[object DataView]",G=P(D),Q=P(N),J=P(C),H=P(T),K=P(B),X=_;(D&&X(new D(new ArrayBuffer(1)))!=W||N&&X(new N)!=L||C&&X(C.resolve())!=R||T&&X(new T)!=q||B&&X(new B)!=V)&&(X=function(t){var e=_(t),n="[object Object]"==e?t.constructor:void 0,r=n?P(n):"";if(r)switch(r){case G:return W;case Q:return L;case J:return R;case H:return q;case K:return V}return e});var Y=X;function Z(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=9007199254740991}function tt(t){return null!=t&&Z(t.length)&&!m(t)}var et=Array.isArray;function nt(t){return null!=t&&"object"==typeof t}function rt(t){return function(e){return null==e?void 0:e[t]}}var ot=rt("length"),ut=RegExp("[\\u200d\\ud800-\\udfff\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff\\ufe0e\\ufe0f]");var it="\\ud800-\\udfff",ct="["+it+"]",at="[\\u0300-\\u036f\\ufe20-\\ufe2f\\u20d0-\\u20ff]",ft="\\ud83c[\\udffb-\\udfff]",lt="[^"+it+"]",st="(?:\\ud83c[\\udde6-\\uddff]){2}",pt="[\\ud800-\\udbff][\\udc00-\\udfff]",vt="(?:"+at+"|"+ft+")"+"?",yt="[\\ufe0e\\ufe0f]?",bt=yt+vt+("(?:\\u200d(?:"+[lt,st,pt].join("|")+")"+yt+vt+")*"),ht="(?:"+[lt+at+"?",at,st,pt,ct].join("|")+")",dt=RegExp(ft+"(?="+ft+")|"+ht+bt,"g");function jt(t){return function(t){return ut.test(t)}(t)?function(t){for(var e=dt.lastIndex=0;dt.test(t);)++e;return e}(t):ot(t)}function gt(t){if(null==t)return 0;if(tt(t))return"string"==typeof(e=t)||!et(e)&&nt(e)&&"[object String]"==_(e)?jt(t):t.length;var e,n=Y(t);return"[object Map]"==n||"[object Set]"==n?t.size:f(t).length}function _t(t){return"symbol"==typeof t||nt(t)&&"[object Symbol]"==_(t)}var wt=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,mt=/^\w*$/;function Ot(t,e){if(et(t))return!1;var n=typeof t;return!("number"!=n&&"symbol"!=n&&"boolean"!=n&&null!=t&&!_t(t))||(mt.test(t)||!wt.test(t)||null!=e&&t in Object(e))}var At=U(Object,"create");var xt=Object.prototype.hasOwnProperty;var St=Object.prototype.hasOwnProperty;function Pt(t){var e=-1,n=null==t?0:t.length;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function kt(t,e){return t===e||t!=t&&e!=e}function It(t,e){for(var n=t.length;n--;)if(kt(t[n][0],e))return n;return-1}Pt.prototype.clear=function(){this.__data__=At?At(null):{},this.size=0},Pt.prototype.delete=function(t){var e=this.has(t)&&delete this.__data__[t];return this.size-=e?1:0,e},Pt.prototype.get=function(t){var e=this.__data__;if(At){var n=e[t];return"__lodash_hash_undefined__"===n?void 0:n}return xt.call(e,t)?e[t]:void 0},Pt.prototype.has=function(t){var e=this.__data__;return At?void 0!==e[t]:St.call(e,t)},Pt.prototype.set=function(t,e){var n=this.__data__;return this.size+=this.has(t)?0:1,n[t]=At&&void 0===e?"__lodash_hash_undefined__":e,this};var zt=Array.prototype.splice;function Et(t){var e=-1,n=null==t?0:t.length;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}function $t(t,e){var n,r,o=t.__data__;return("string"==(r=typeof(n=e))||"number"==r||"symbol"==r||"boolean"==r?"__proto__"!==n:null===n)?o["string"==typeof e?"string":"hash"]:o.map}function Mt(t){var e=-1,n=null==t?0:t.length;for(this.clear();++e<n;){var r=t[e];this.set(r[0],r[1])}}Et.prototype.clear=function(){this.__data__=[],this.size=0},Et.prototype.delete=function(t){var e=this.__data__,n=It(e,t);return!(n<0)&&(n==e.length-1?e.pop():zt.call(e,n,1),--this.size,!0)},Et.prototype.get=function(t){var e=this.__data__,n=It(e,t);return n<0?void 0:e[n][1]},Et.prototype.has=function(t){return It(this.__data__,t)>-1},Et.prototype.set=function(t,e){var n=this.__data__,r=It(n,t);return r<0?(++this.size,n.push([t,e])):n[r][1]=e,this},Mt.prototype.clear=function(){this.size=0,this.__data__={hash:new Pt,map:new(N||Et),string:new Pt}},Mt.prototype.delete=function(t){var e=$t(this,t).delete(t);return this.size-=e?1:0,e},Mt.prototype.get=function(t){return $t(this,t).get(t)},Mt.prototype.has=function(t){return $t(this,t).has(t)},Mt.prototype.set=function(t,e){var n=$t(this,t),r=n.size;return n.set(t,e),this.size+=n.size==r?0:1,this};function Ft(t,e){if("function"!=typeof t||null!=e&&"function"!=typeof e)throw new TypeError("Expected a function");var n=function(){var r=arguments,o=e?e.apply(this,r):r[0],u=n.cache;if(u.has(o))return u.get(o);var i=t.apply(this,r);return n.cache=u.set(o,i)||u,i};return n.cache=new(Ft.Cache||Mt),n}Ft.Cache=Mt;var Ut,Dt,Nt,Ct=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,Tt=/\\(\\)?/g,Bt=(Ut=function(t){var e=[];return 46===t.charCodeAt(0)&&e.push(""),t.replace(Ct,function(t,n,r,o){e.push(r?o.replace(Tt,"$1"):n||t)}),e},Dt=Ft(Ut,function(t){return 500===Nt.size&&Nt.clear(),t}),Nt=Dt.cache,Dt),Lt=Bt;function Rt(t,e){for(var n=-1,r=null==t?0:t.length,o=Array(r);++n<r;)o[n]=e(t[n],n,t);return o}var qt=v?v.prototype:void 0,Vt=qt?qt.toString:void 0;function Wt(t){if("string"==typeof t)return t;if(et(t))return Rt(t,Wt)+"";if(_t(t))return Vt?Vt.call(t):"";var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}function Gt(t){return null==t?"":Wt(t)}function Qt(t,e){return et(t)?t:Ot(t,e)?[t]:Lt(Gt(t))}function Jt(t){if("string"==typeof t||_t(t))return t;var e=t+"";return"0"==e&&1/t==-1/0?"-0":e}function Ht(t,e){for(var n=0,r=(e=Qt(e,t)).length;null!=t&&n<r;)t=t[Jt(e[n++])];return n&&n==r?t:void 0}function Kt(t,e,n){var r=null==t?void 0:Ht(t,e);return void 0===r?n:r}function Xt(t,e){for(var n=-1,r=null==t?0:t.length;++n<r&&!1!==e(t[n],n,t););return t}var Yt,Zt=function(t,e,n){for(var r=-1,o=Object(t),u=n(t),i=u.length;i--;){var c=u[Yt?i:++r];if(!1===e(o[c],c,o))break}return t};function te(t){return nt(t)&&"[object Arguments]"==_(t)}var ee=Object.prototype,ne=ee.hasOwnProperty,re=ee.propertyIsEnumerable,oe=te(function(){return arguments}())?te:function(t){return nt(t)&&ne.call(t,"callee")&&!re.call(t,"callee")},ue=oe;var ie="object"==typeof exports&&exports&&!exports.nodeType&&exports,ce=ie&&"object"==typeof module&&module&&!module.nodeType&&module,ae=ce&&ce.exports===ie?p.Buffer:void 0,fe=(ae?ae.isBuffer:void 0)||function(){return!1},le=/^(?:0|[1-9]\d*)$/;function se(t,e){var n=typeof t;return!!(e=null==e?9007199254740991:e)&&("number"==n||"symbol"!=n&&le.test(t))&&t>-1&&t%1==0&&t<e}var pe={};function ve(t){return function(e){return t(e)}}pe["[object Float32Array]"]=pe["[object Float64Array]"]=pe["[object Int8Array]"]=pe["[object Int16Array]"]=pe["[object Int32Array]"]=pe["[object Uint8Array]"]=pe["[object Uint8ClampedArray]"]=pe["[object Uint16Array]"]=pe["[object Uint32Array]"]=!0,pe["[object Arguments]"]=pe["[object Array]"]=pe["[object ArrayBuffer]"]=pe["[object Boolean]"]=pe["[object DataView]"]=pe["[object Date]"]=pe["[object Error]"]=pe["[object Function]"]=pe["[object Map]"]=pe["[object Number]"]=pe["[object Object]"]=pe["[object RegExp]"]=pe["[object Set]"]=pe["[object String]"]=pe["[object WeakMap]"]=!1;var ye="object"==typeof exports&&exports&&!exports.nodeType&&exports,be=ye&&"object"==typeof module&&module&&!module.nodeType&&module,he=be&&be.exports===ye&&l.process,de=function(){try{var t=be&&be.require&&be.require("util").types;return t||he&&he.binding&&he.binding("util")}catch(t){}}(),je=de&&de.isTypedArray,ge=je?ve(je):function(t){return nt(t)&&Z(t.length)&&!!pe[_(t)]},_e=Object.prototype.hasOwnProperty;function we(t,e){var n=et(t),r=!n&&ue(t),o=!n&&!r&&fe(t),u=!n&&!r&&!o&&ge(t),i=n||r||o||u,c=i?function(t,e){for(var n=-1,r=Array(t);++n<t;)r[n]=e(n);return r}(t.length,String):[],a=c.length;for(var f in t)!e&&!_e.call(t,f)||i&&("length"==f||o&&("offset"==f||"parent"==f)||u&&("buffer"==f||"byteLength"==f||"byteOffset"==f)||se(f,a))||c.push(f);return c}function me(t){return tt(t)?we(t):f(t)}var Oe=function(t,e){return function(n,r){if(null==n)return n;if(!tt(n))return t(n,r);for(var o=n.length,u=e?o:-1,i=Object(n);(e?u--:++u<o)&&!1!==r(i[u],u,i););return n}}(function(t,e){return t&&Zt(t,e,me)}),Ae=Oe;function xe(t){return t}function Se(t,e){var n;return(et(t)?Xt:Ae)(t,"function"==typeof(n=e)?n:xe)}function Pe(t){var e=this.__data__=new Et(t);this.size=e.size}Pe.prototype.clear=function(){this.__data__=new Et,this.size=0},Pe.prototype.delete=function(t){var e=this.__data__,n=e.delete(t);return this.size=e.size,n},Pe.prototype.get=function(t){return this.__data__.get(t)},Pe.prototype.has=function(t){return this.__data__.has(t)},Pe.prototype.set=function(t,e){var n=this.__data__;if(n instanceof Et){var r=n.__data__;if(!N||r.length<199)return r.push([t,e]),this.size=++n.size,this;n=this.__data__=new Mt(r)}return n.set(t,e),this.size=n.size,this};function ke(t){var e=-1,n=null==t?0:t.length;for(this.__data__=new Mt;++e<n;)this.add(t[e])}function Ie(t,e){for(var n=-1,r=null==t?0:t.length;++n<r;)if(e(t[n],n,t))return!0;return!1}function ze(t,e){return t.has(e)}ke.prototype.add=ke.prototype.push=function(t){return this.__data__.set(t,"__lodash_hash_undefined__"),this},ke.prototype.has=function(t){return this.__data__.has(t)};function Ee(t,e,n,r,o,u){var i=1&n,c=t.length,a=e.length;if(c!=a&&!(i&&a>c))return!1;var f=u.get(t),l=u.get(e);if(f&&l)return f==e&&l==t;var s=-1,p=!0,v=2&n?new ke:void 0;for(u.set(t,e),u.set(e,t);++s<c;){var y=t[s],b=e[s];if(r)var h=i?r(b,y,s,e,t,u):r(y,b,s,t,e,u);if(void 0!==h){if(h)continue;p=!1;break}if(v){if(!Ie(e,function(t,e){if(!ze(v,e)&&(y===t||o(y,t,n,r,u)))return v.push(e)})){p=!1;break}}else if(y!==b&&!o(y,b,n,r,u)){p=!1;break}}return u.delete(t),u.delete(e),p}var $e=p.Uint8Array;function Me(t){var e=-1,n=Array(t.size);return t.forEach(function(t,r){n[++e]=[r,t]}),n}function Fe(t){var e=-1,n=Array(t.size);return t.forEach(function(t){n[++e]=t}),n}var Ue=v?v.prototype:void 0,De=Ue?Ue.valueOf:void 0;function Ne(t,e){for(var n=-1,r=e.length,o=t.length;++n<r;)t[o+n]=e[n];return t}function Ce(t,e,n){var r=e(t);return et(t)?r:Ne(r,n(t))}function Te(){return[]}var Be=Object.prototype.propertyIsEnumerable,Le=Object.getOwnPropertySymbols,Re=Le?function(t){return null==t?[]:(t=Object(t),function(t,e){for(var n=-1,r=null==t?0:t.length,o=0,u=[];++n<r;){var i=t[n];e(i,n,t)&&(u[o++]=i)}return u}(Le(t),function(e){return Be.call(t,e)}))}:Te,qe=Re;function Ve(t){return Ce(t,me,qe)}var We=Object.prototype.hasOwnProperty;var Ge="[object Arguments]",Qe="[object Array]",Je="[object Object]",He=Object.prototype.hasOwnProperty;function Ke(t,e,n,r,o,u){var i=et(t),c=et(e),a=i?Qe:Y(t),f=c?Qe:Y(e),l=(a=a==Ge?Je:a)==Je,s=(f=f==Ge?Je:f)==Je,p=a==f;if(p&&fe(t)){if(!fe(e))return!1;i=!0,l=!1}if(p&&!l)return u||(u=new Pe),i||ge(t)?Ee(t,e,n,r,o,u):function(t,e,n,r,o,u,i){switch(n){case"[object DataView]":if(t.byteLength!=e.byteLength||t.byteOffset!=e.byteOffset)return!1;t=t.buffer,e=e.buffer;case"[object ArrayBuffer]":return!(t.byteLength!=e.byteLength||!u(new $e(t),new $e(e)));case"[object Boolean]":case"[object Date]":case"[object Number]":return kt(+t,+e);case"[object Error]":return t.name==e.name&&t.message==e.message;case"[object RegExp]":case"[object String]":return t==e+"";case"[object Map]":var c=Me;case"[object Set]":var a=1&r;if(c||(c=Fe),t.size!=e.size&&!a)return!1;var f=i.get(t);if(f)return f==e;r|=2,i.set(t,e);var l=Ee(c(t),c(e),r,o,u,i);return i.delete(t),l;case"[object Symbol]":if(De)return De.call(t)==De.call(e)}return!1}(t,e,a,n,r,o,u);if(!(1&n)){var v=l&&He.call(t,"__wrapped__"),y=s&&He.call(e,"__wrapped__");if(v||y){var b=v?t.value():t,h=y?e.value():e;return u||(u=new Pe),o(b,h,n,r,u)}}return!!p&&(u||(u=new Pe),function(t,e,n,r,o,u){var i=1&n,c=Ve(t),a=c.length;if(a!=Ve(e).length&&!i)return!1;for(var f=a;f--;){var l=c[f];if(!(i?l in e:We.call(e,l)))return!1}var s=u.get(t),p=u.get(e);if(s&&p)return s==e&&p==t;var v=!0;u.set(t,e),u.set(e,t);for(var y=i;++f<a;){var b=t[l=c[f]],h=e[l];if(r)var d=i?r(h,b,l,e,t,u):r(b,h,l,t,e,u);if(!(void 0===d?b===h||o(b,h,n,r,u):d)){v=!1;break}y||(y="constructor"==l)}if(v&&!y){var j=t.constructor,g=e.constructor;j==g||!("constructor"in t)||!("constructor"in e)||"function"==typeof j&&j instanceof j&&"function"==typeof g&&g instanceof g||(v=!1)}return u.delete(t),u.delete(e),v}(t,e,n,r,o,u))}function Xe(t,e,n,r,o){return t===e||(null==t||null==e||!nt(t)&&!nt(e)?t!=t&&e!=e:Ke(t,e,n,r,Xe,o))}function Ye(t){return t==t&&!w(t)}function Ze(t,e){return function(n){return null!=n&&(n[t]===e&&(void 0!==e||t in Object(n)))}}function tn(t){var e=function(t){for(var e=me(t),n=e.length;n--;){var r=e[n],o=t[r];e[n]=[r,o,Ye(o)]}return e}(t);return 1==e.length&&e[0][2]?Ze(e[0][0],e[0][1]):function(n){return n===t||function(t,e,n,r){var o=n.length,u=o,i=!r;if(null==t)return!u;for(t=Object(t);o--;){var c=n[o];if(i&&c[2]?c[1]!==t[c[0]]:!(c[0]in t))return!1}for(;++o<u;){var a=(c=n[o])[0],f=t[a],l=c[1];if(i&&c[2]){if(void 0===f&&!(a in t))return!1}else{var s=new Pe;if(r)var p=r(f,l,a,t,e,s);if(!(void 0===p?Xe(l,f,3,r,s):p))return!1}}return!0}(n,t,e)}}function en(t,e){return null!=t&&e in Object(t)}function nn(t,e){return null!=t&&function(t,e,n){for(var r=-1,o=(e=Qt(e,t)).length,u=!1;++r<o;){var i=Jt(e[r]);if(!(u=null!=t&&n(t,i)))break;t=t[i]}return u||++r!=o?u:!!(o=null==t?0:t.length)&&Z(o)&&se(i,o)&&(et(t)||ue(t))}(t,e,en)}function rn(t){return Ot(t)?rt(Jt(t)):function(t){return function(e){return Ht(e,t)}}(t)}function on(t){return"function"==typeof t?t:null==t?xe:"object"==typeof t?et(t)?(e=t[0],n=t[1],Ot(e)&&Ye(n)?Ze(Jt(e),n):function(t){var r=Kt(t,e);return void 0===r&&r===n?nn(t,e):Xe(n,r,3)}):tn(t):rn(t);var e,n}function un(t,e){var n=-1,r=tt(t)?Array(t.length):[];return Ae(t,function(t,o,u){r[++n]=e(t,o,u)}),r}function cn(t,e){return(et(t)?Rt:un)(t,on(e))}var an=function(){try{var t=U(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),fn=an;function ln(t,e,n){"__proto__"==e&&fn?fn(t,e,{configurable:!0,enumerable:!0,value:n,writable:!0}):t[e]=n}function sn(t,e,n){(void 0!==n&&!kt(t[e],n)||void 0===n&&!(e in t))&&ln(t,e,n)}var pn="object"==typeof exports&&exports&&!exports.nodeType&&exports,vn=pn&&"object"==typeof module&&module&&!module.nodeType&&module,yn=vn&&vn.exports===pn?p.Buffer:void 0,bn=yn?yn.allocUnsafe:void 0;function hn(t,e){if(e)return t.slice();var n=t.length,r=bn?bn(n):new t.constructor(n);return t.copy(r),r}function dn(t){var e=new t.constructor(t.byteLength);return new $e(e).set(new $e(t)),e}function jn(t,e){var n=e?dn(t.buffer):t.buffer;return new t.constructor(n,t.byteOffset,t.length)}function gn(t,e){var n=-1,r=t.length;for(e||(e=Array(r));++n<r;)e[n]=t[n];return e}var _n=Object.create,wn=function(){function t(){}return function(e){if(!w(e))return{};if(_n)return _n(e);t.prototype=e;var n=new t;return t.prototype=void 0,n}}(),mn=wn,On=i(Object.getPrototypeOf,Object);function An(t){return"function"!=typeof t.constructor||u(t)?{}:mn(On(t))}var xn=Function.prototype,Sn=Object.prototype,Pn=xn.toString,kn=Sn.hasOwnProperty,In=Pn.call(Object);function zn(t,e){if(("constructor"!==e||"function"!=typeof t[e])&&"__proto__"!=e)return t[e]}var En=Object.prototype.hasOwnProperty;function $n(t,e,n){var r=t[e];En.call(t,e)&&kt(r,n)&&(void 0!==n||e in t)||ln(t,e,n)}function Mn(t,e,n,r){var o=!n;n||(n={});for(var u=-1,i=e.length;++u<i;){var c=e[u],a=r?r(n[c],t[c],c,n,t):void 0;void 0===a&&(a=t[c]),o?ln(n,c,a):$n(n,c,a)}return n}var Fn=Object.prototype.hasOwnProperty;function Un(t){if(!w(t))return function(t){var e=[];if(null!=t)for(var n in Object(t))e.push(n);return e}(t);var e=u(t),n=[];for(var r in t)("constructor"!=r||!e&&Fn.call(t,r))&&n.push(r);return n}function Dn(t){return tt(t)?we(t,!0):Un(t)}function Nn(t,e,n,r,o,u,i){var c=zn(t,n),a=zn(e,n),f=i.get(a);if(f)sn(t,n,f);else{var l,s=u?u(c,a,n+"",t,e,i):void 0,p=void 0===s;if(p){var v=et(a),y=!v&&fe(a),b=!v&&!y&&ge(a);s=a,v||y||b?et(c)?s=c:nt(l=c)&&tt(l)?s=gn(c):y?(p=!1,s=hn(a,!0)):b?(p=!1,s=jn(a,!0)):s=[]:function(t){if(!nt(t)||"[object Object]"!=_(t))return!1;var e=On(t);if(null===e)return!0;var n=kn.call(e,"constructor")&&e.constructor;return"function"==typeof n&&n instanceof n&&Pn.call(n)==In}(a)||ue(a)?(s=c,ue(c)?s=function(t){return Mn(t,Dn(t))}(c):w(c)&&!m(c)||(s=An(a))):p=!1}p&&(i.set(a,s),o(s,a,r,u,i),i.delete(a)),sn(t,n,s)}}function Cn(t,e,n,r,o){t!==e&&Zt(e,function(u,i){if(o||(o=new Pe),w(u))Nn(t,e,i,n,Cn,r,o);else{var c=r?r(zn(t,i),u,i+"",t,e,o):void 0;void 0===c&&(c=u),sn(t,i,c)}},Dn)}var Tn=Math.max;var Bn=fn?function(t,e){return fn(t,"toString",{configurable:!0,enumerable:!1,value:(n=e,function(){return n}),writable:!0});var n}:xe,Ln=Bn,Rn=Date.now;var qn=function(t){var e=0,n=0;return function(){var r=Rn(),o=16-(r-n);if(n=r,o>0){if(++e>=800)return arguments[0]}else e=0;return t.apply(void 0,arguments)}}(Ln),Vn=qn;function Wn(t,e){return Vn(function(t,e,n){return e=Tn(void 0===e?t.length-1:e,0),function(){for(var r=arguments,o=-1,u=Tn(r.length-e,0),i=Array(u);++o<u;)i[o]=r[e+o];o=-1;for(var c=Array(e+1);++o<e;)c[o]=r[o];return c[e]=n(i),function(t,e,n){switch(n.length){case 0:return t.call(e);case 1:return t.call(e,n[0]);case 2:return t.call(e,n[0],n[1]);case 3:return t.call(e,n[0],n[1],n[2])}return t.apply(e,n)}(t,this,c)}}(t,e,xe),t+"")}var Gn,Qn=(Gn=function(t,e,n){Cn(t,e,n)},Wn(function(t,e){var n=-1,r=e.length,o=r>1?e[r-1]:void 0,u=r>2?e[2]:void 0;for(o=Gn.length>3&&"function"==typeof o?(r--,o):void 0,u&&function(t,e,n){if(!w(n))return!1;var r=typeof e;return!!("number"==r?tt(n)&&se(e,n.length):"string"==r&&e in n)&&kt(n[e],t)}(e[0],e[1],u)&&(o=r<3?void 0:o,r=1),t=Object(t);++n<r;){var i=e[n];i&&Gn(t,i,n,o)}return t}));function Jn(t,e){return Xe(t,e)}var Hn=Object.getOwnPropertySymbols?function(t){for(var e=[];t;)Ne(e,qe(t)),t=On(t);return e}:Te,Kn=Hn;function Xn(t){return Ce(t,Dn,Kn)}var Yn=Object.prototype.hasOwnProperty;var Zn=/\w*$/;var tr=v?v.prototype:void 0,er=tr?tr.valueOf:void 0;function nr(t,e,n){var r,o=t.constructor;switch(e){case"[object ArrayBuffer]":return dn(t);case"[object Boolean]":case"[object Date]":return new o(+t);case"[object DataView]":return function(t,e){var n=e?dn(t.buffer):t.buffer;return new t.constructor(n,t.byteOffset,t.byteLength)}(t,n);case"[object Float32Array]":case"[object Float64Array]":case"[object Int8Array]":case"[object Int16Array]":case"[object Int32Array]":case"[object Uint8Array]":case"[object Uint8ClampedArray]":case"[object Uint16Array]":case"[object Uint32Array]":return jn(t,n);case"[object Map]":case"[object Set]":return new o;case"[object Number]":case"[object String]":return new o(t);case"[object RegExp]":return function(t){var e=new t.constructor(t.source,Zn.exec(t));return e.lastIndex=t.lastIndex,e}(t);case"[object Symbol]":return r=t,er?Object(er.call(r)):{}}}var rr=de&&de.isMap,or=rr?ve(rr):function(t){return nt(t)&&"[object Map]"==Y(t)};var ur=de&&de.isSet,ir=ur?ve(ur):function(t){return nt(t)&&"[object Set]"==Y(t)},cr="[object Arguments]",ar="[object Function]",fr="[object Object]",lr={};function sr(t,e,n,r,o,u){var i,c=1&e,a=2&e,f=4&e;if(n&&(i=o?n(t,r,o,u):n(t)),void 0!==i)return i;if(!w(t))return t;var l=et(t);if(l){if(i=function(t){var e=t.length,n=new t.constructor(e);return e&&"string"==typeof t[0]&&Yn.call(t,"index")&&(n.index=t.index,n.input=t.input),n}(t),!c)return gn(t,i)}else{var s=Y(t),p=s==ar||"[object GeneratorFunction]"==s;if(fe(t))return hn(t,c);if(s==fr||s==cr||p&&!o){if(i=a||p?{}:An(t),!c)return a?function(t,e){return Mn(t,Kn(t),e)}(t,function(t,e){return t&&Mn(e,Dn(e),t)}(i,t)):function(t,e){return Mn(t,qe(t),e)}(t,function(t,e){return t&&Mn(e,me(e),t)}(i,t))}else{if(!lr[s])return o?t:{};i=nr(t,s,c)}}u||(u=new Pe);var v=u.get(t);if(v)return v;u.set(t,i),ir(t)?t.forEach(function(r){i.add(sr(r,e,n,r,t,u))}):or(t)&&t.forEach(function(r,o){i.set(o,sr(r,e,n,o,t,u))});var y=l?void 0:(f?a?Xn:Ve:a?Dn:me)(t);return Xt(y||t,function(r,o){y&&(r=t[o=r]),$n(i,o,sr(r,e,n,o,t,u))}),i}lr[cr]=lr["[object Array]"]=lr["[object ArrayBuffer]"]=lr["[object DataView]"]=lr["[object Boolean]"]=lr["[object Date]"]=lr["[object Float32Array]"]=lr["[object Float64Array]"]=lr["[object Int8Array]"]=lr["[object Int16Array]"]=lr["[object Int32Array]"]=lr["[object Map]"]=lr["[object Number]"]=lr[fr]=lr["[object RegExp]"]=lr["[object Set]"]=lr["[object String]"]=lr["[object Symbol]"]=lr["[object Uint8Array]"]=lr["[object Uint8ClampedArray]"]=lr["[object Uint16Array]"]=lr["[object Uint32Array]"]=!0,lr["[object Error]"]=lr[ar]=lr["[object WeakMap]"]=!1;function pr(t){return sr(t,5)}function vr(t){return"[object String]"===Object.prototype.toString.call(t)}function yr(t){return!(!vr(t)||""===t)}function br(t){return"[object Array]"===Object.prototype.toString.call(t)}function hr(t){return"[object Object]"===Object.prototype.toString.call(t)}function dr(t){return t!=t}function jr(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(hr(t)){for(let e in t)return!1;return!0}return!1}(t)||(!!function(t){return!(!vr(t)||""!==t)}(t)||(!!function(t){return!!br(t)&&0===t.length}(t)||!!dr(t)))))}function gr(t){return!!br(t)&&(0!==t.length&&(1!==t.length||!jr(t[0])))}function _r(t){if(hr(t)){for(let e in t)return!0;return!1}return!1}function wr(t){return!0===(e=t)||!1===e||nt(e)&&"[object Boolean]"==_(e);var e}function mr(t){let e=!1;if(yr(t))e=!isNaN(Number(t));else if(function(t){return"[object Number]"===Object.prototype.toString.call(t)}(t)){if(dr(t))return!1;e=!0}return e}function Or(t,e){return!!hr(t)&&(!(!yr(e)&&!mr(e))&&e in t)}var Ar={exports:{}};!function(t){var e=Object.prototype.hasOwnProperty,n="~";function r(){}function o(t,e,n){this.fn=t,this.context=e,this.once=n||!1}function u(t,e,r,u,i){if("function"!=typeof r)throw new TypeError("The listener must be a function");var c=new o(r,u||t,i),a=n?n+e:e;return t._events[a]?t._events[a].fn?t._events[a]=[t._events[a],c]:t._events[a].push(c):(t._events[a]=c,t._eventsCount++),t}function i(t,e){0===--t._eventsCount?t._events=new r:delete t._events[e]}function c(){this._events=new r,this._eventsCount=0}Object.create&&(r.prototype=Object.create(null),(new r).__proto__||(n=!1)),c.prototype.eventNames=function(){var t,r,o=[];if(0===this._eventsCount)return o;for(r in t=this._events)e.call(t,r)&&o.push(n?r.slice(1):r);return Object.getOwnPropertySymbols?o.concat(Object.getOwnPropertySymbols(t)):o},c.prototype.listeners=function(t){var e=n?n+t:t,r=this._events[e];if(!r)return[];if(r.fn)return[r.fn];for(var o=0,u=r.length,i=new Array(u);o<u;o++)i[o]=r[o].fn;return i},c.prototype.listenerCount=function(t){var e=n?n+t:t,r=this._events[e];return r?r.fn?1:r.length:0},c.prototype.emit=function(t,e,r,o,u,i){var c=n?n+t:t;if(!this._events[c])return!1;var a,f,l=this._events[c],s=arguments.length;if(l.fn){switch(l.once&&this.removeListener(t,l.fn,void 0,!0),s){case 1:return l.fn.call(l.context),!0;case 2:return l.fn.call(l.context,e),!0;case 3:return l.fn.call(l.context,e,r),!0;case 4:return l.fn.call(l.context,e,r,o),!0;case 5:return l.fn.call(l.context,e,r,o,u),!0;case 6:return l.fn.call(l.context,e,r,o,u,i),!0}for(f=1,a=new Array(s-1);f<s;f++)a[f-1]=arguments[f];l.fn.apply(l.context,a)}else{var p,v=l.length;for(f=0;f<v;f++)switch(l[f].once&&this.removeListener(t,l[f].fn,void 0,!0),s){case 1:l[f].fn.call(l[f].context);break;case 2:l[f].fn.call(l[f].context,e);break;case 3:l[f].fn.call(l[f].context,e,r);break;case 4:l[f].fn.call(l[f].context,e,r,o);break;default:if(!a)for(p=1,a=new Array(s-1);p<s;p++)a[p-1]=arguments[p];l[f].fn.apply(l[f].context,a)}}return!0},c.prototype.on=function(t,e,n){return u(this,t,e,n,!1)},c.prototype.once=function(t,e,n){return u(this,t,e,n,!0)},c.prototype.removeListener=function(t,e,r,o){var u=n?n+t:t;if(!this._events[u])return this;if(!e)return i(this,u),this;var c=this._events[u];if(c.fn)c.fn!==e||o&&!c.once||r&&c.context!==r||i(this,u);else{for(var a=0,f=[],l=c.length;a<l;a++)(c[a].fn!==e||o&&!c[a].once||r&&c[a].context!==r)&&f.push(c[a]);f.length?this._events[u]=1===f.length?f[0]:f:i(this,u)}return this},c.prototype.removeAllListeners=function(t){var e;return t?(e=n?n+t:t,this._events[e]&&i(this,e)):(this._events=new r,this._eventsCount=0),this},c.prototype.off=c.prototype.removeListener,c.prototype.addListener=c.prototype.on,c.prefixed=n,c.EventEmitter=c,t.exports=c}(Ar);var xr=n(Ar.exports);const Sr=[];for(let t=0;t<256;++t)Sr.push((t+256).toString(16).slice(1));const Pr=new Uint8Array(16);function kr(){return crypto.getRandomValues(Pr)}const Ir={};function zr(t,e,n){let r;if(t)r=Er(t.random??t.rng?.()??kr(),t.msecs,t.seq,e,n);else{const t=Date.now(),o=kr();!function(t,e,n){t.msecs??=-1/0,t.seq??=0,e>t.msecs?(t.seq=n[6]<<23|n[7]<<16|n[8]<<8|n[9],t.msecs=e):(t.seq=t.seq+1|0,0===t.seq&&t.msecs++)}(Ir,t,o),r=Er(o,Ir.msecs,Ir.seq,e,n)}return e??function(t,e=0){return(Sr[t[e+0]]+Sr[t[e+1]]+Sr[t[e+2]]+Sr[t[e+3]]+"-"+Sr[t[e+4]]+Sr[t[e+5]]+"-"+Sr[t[e+6]]+Sr[t[e+7]]+"-"+Sr[t[e+8]]+Sr[t[e+9]]+"-"+Sr[t[e+10]]+Sr[t[e+11]]+Sr[t[e+12]]+Sr[t[e+13]]+Sr[t[e+14]]+Sr[t[e+15]]).toLowerCase()}(r)}function Er(t,e,n,r,o=0){if(t.length<16)throw new Error("Random bytes length must be >= 16");if(r){if(o<0||o+16>r.length)throw new RangeError(`UUID byte range ${o}:${o+15} is out of buffer bounds`)}else r=new Uint8Array(16),o=0;return e??=Date.now(),n??=127*t[6]<<24|t[7]<<16|t[8]<<8|t[9],r[o++]=e/1099511627776&255,r[o++]=e/4294967296&255,r[o++]=e/16777216&255,r[o++]=e/65536&255,r[o++]=e/256&255,r[o++]=255&e,r[o++]=112|n>>>28&15,r[o++]=n>>>20&255,r[o++]=128|n>>>14&63,r[o++]=n>>>6&255,r[o++]=n<<2&255|3&t[10],r[o++]=t[11],r[o++]=t[12],r[o++]=t[13],r[o++]=t[14],r[o++]=t[15],r}function $r(){return zr()}var Mr=/\s/;var Fr=/^\s+/;function Ur(t){return t?t.slice(0,function(t){for(var e=t.length;e--&&Mr.test(t.charAt(e)););return e}(t)+1).replace(Fr,""):t}var Dr=/^[-+]0x[0-9a-f]+$/i,Nr=/^0b[01]+$/i,Cr=/^0o[0-7]+$/i,Tr=parseInt;function Br(t){if("number"==typeof t)return t;if(_t(t))return NaN;if(w(t)){var e="function"==typeof t.valueOf?t.valueOf():t;t=w(e)?e+"":e}if("string"!=typeof t)return 0===t?t:+t;t=Ur(t);var n=Nr.test(t);return n||Cr.test(t)?Tr(t.slice(2),n?2:8):Dr.test(t)?NaN:+t}var Lr=1/0;function Rr(t){return t?(t=Br(t))===Lr||t===-1/0?17976931348623157e292*(t<0?-1:1):t==t?t:0:0===t?t:0}function qr(t){var e=Rr(t),n=e%1;return e==e?n?e-n:e:0}function Vr(t,e,n){var r=null==t?0:t.length;return r?function(t,e,n){var r=-1,o=t.length;e<0&&(e=-e>o?0:o+e),(n=n>o?o:n)<0&&(n+=o),o=e>n?0:n-e>>>0,e>>>=0;for(var u=Array(o);++r<o;)u[r]=t[r+e];return u}(t,(e=n||void 0===e?1:qr(e))<0?0:e,r):[]}function Wr(){let t,e,n=new Promise(function(){t=arguments[0],e=arguments[1]});return n.resolve=t,n.reject=e,n}function Gr(t){let e=Object.prototype.toString.call(t);return"[object Function]"===e||"[object AsyncFunction]"===e}function Qr(t,e){let n=Wr();if(!br(t)&&!hr(t))return n.reject("rs is not an array or object"),n;let r=!1;if(hr(t)){r=!0;let e=[];Se(t,(t,n)=>{e.push({k:n,v:t})}),t=e}Gr(e)||(e=function(t){return t});let o=-1,u=[];return t.reduce(function(t,n){return t.then(function(t){u.push(t),o+=1;let i=o,c=n;return r&&(i=n.k,c=n.v),Gr(e)?e(c,i):c})},Promise.resolve()).then(function(t){u.push(t),u=Vr(u),n.resolve(u)}).catch(function(t){n.reject(t)}),n}function Jr(t){if(!mr(t))return 0;return Rr(t)}function Hr(t){return!!mr(t)&&(t=Jr(t),"number"==typeof(e=t)&&e==qr(e));var e}var Kr=p.isFinite,Xr=Math.min;var Yr=function(t){var e=Math[t];return function(t,n){if(t=Br(t),(n=null==n?0:Xr(qr(n),292))&&Kr(t)){var r=(Gt(t)+"e").split("e");return+((r=(Gt(e(r[0]+"e"+(+r[1]+n)))+"e").split("e"))[0]+"e"+(+r[1]-n))}return e(t)}}("round"),Zr=Yr;function to(t){if(!Hr(t))return!1;let e=function(t){if(!mr(t))return 0;t=Jr(t);let e=Zr(t);return"0"===String(e)?0:e}(t)>0;return e}async function eo(t,e={}){let n=null,r=Wr();if(!Gr(t))return r.reject("waitfunction需輸入函數f"),r;let o=async()=>{let e=t();return function(t){let e,n=Object.prototype.toString.call(t);if(e="[object Promise]"===n,e)return!0;if("[object Function]"!==n)return!1;try{e="function"!=typeof t.subscribe&&"function"==typeof t.then}catch(t){}return e}(e)&&(e=await e),e};if(n=await o(),!0===n)return r.resolve(),r;let u=Kt(e,"attemptNum",null);to(u)||(u=200);let i=Kt(e,"timeInterval",null);to(i)||(i=1e3);let c=0,a=setInterval(async()=>{c+=1,n=await o(),!0===n&&(clearInterval(a),r.resolve()),c>u&&(clearInterval(a),r.reject(`exceeded attemptNum[${u}]`))},i);return r}return function(e={}){let n=null,o=Kt(e,"url");yr(o)||(o="./_db");let u=Kt(e,"db");yr(u)||(u="worm");let i=Kt(e,"cl");yr(i)||(i="test");let c=Kt(e,"useCache");wr(c)||(c=!1);let a=`${o}/${u}/${i}`,f=t.open({path:a,compression:!0,useVersions:!0}),l=new xr,s=async()=>{if(c&&br(n))return pr(n);await p();let t=[];for await(let{value:e}of f.getRange())t.push(e);return c?(n=t,pr(t)):t},p=async()=>{await eo(()=>("closed"===f.status&&console.log(`client.status[${f.status}], level is closed`),"open"===f.status))},v=t=>{let e=Kt(t,"message");return yr(e)?e:String(t)},y=async t=>{let e=null;try{e=await f.get(t)}catch(t){}return e};return l.select=async function(t={}){let e=!1,n=null;try{let o=await s();if(_r(t)){n=new r.Query(t).find(o).all()}else n=o;br(n)||(e=!0,n=`can not select by find[${JSON.stringify(t)}]`)}catch(t){e=!0,n=t}return e?Promise.reject(n):n},l.selectByPk=async function(t){let e=!1,n=null;try{if(!yr(t))return null;await p();let e=await y(t);n=_r(e)?e:null}catch(t){e=!0,n=t}return e?Promise.reject(n):n},l.insert=async function(t){let e=!1;if(!_r(t)&&!gr(t))return{n:0,nInserted:0,ok:1};t=pr(t);let r=null;try{br(t)||(t=[t]);let e=gt(t=cn(t,function(t){return yr(t.id)||(t.id=$r()),t})),n=await Promise.all(cn(t,function(t){return f.ifNoExists(t.id,()=>{f.put(t.id,t)})})),o=0;Se(n,function(t){t&&o++}),r={n:e,nInserted:o,ok:1}}catch(t){e=!0,r=t}if(n=null,!e)try{l.emit("change","insert",t,r)}catch(t){console.log(t)}return e?Promise.reject(r):r},l.save=async function(t,e={}){let r=!1;if(!_r(t)&&!gr(t))return[];t=pr(t);let o=Kt(e,"autoInsert",!0),u=null;try{br(t)||(t=[t]),t=cn(t,function(t){return yr(t.id)||(t.id=$r()),t}),u=await Qr(t,async t=>{let e=null,r=!1;try{let n=await y(t.id);if(_r(n)&&Jn(Qn({},n,t),n))return{n:1,nInserted:0,nModified:0,ok:1};let u=!1,i=!1;await f.transaction(()=>{let e=f.get(t.id);if(u=_r(e),u){let n=Qn({},e,t);Jn(n,e)||(f.put(t.id,n),i=!0)}else o&&(f.put(t.id,t),r=!0)}),e=r?{n:1,nInserted:1,nModified:0,ok:1}:i?{n:1,nInserted:0,nModified:1,ok:1}:{n:u?1:0,nInserted:0,nModified:0,ok:1}}catch(t){e={n:1,nInserted:0,nModified:0,ok:0,err:v(t)}}if(r){n=null;try{l.emit("change","insert",[t],e)}catch(t){console.log(t)}}return e})}catch(t){r=!0,u=t}if(n=null,!r)try{l.emit("change","save",t,u)}catch(t){console.log(t)}return r?Promise.reject(u):u},l.del=async function(t){let e=!1;if(!_r(t)&&!gr(t))return[];t=pr(t);let r=null;try{br(t)||(t=[t]),r=await Qr(t,async t=>{let e=null;try{let n=Kt(t,"id","");if(!yr(n))return{n:0,nDeleted:0,ok:0,err:`can not delete by invalid id[${n}]`};_r(await y(n))?(await f.del(n),e={n:1,nDeleted:1,ok:1}):e={n:0,nDeleted:0,ok:1}}catch(t){e={n:1,nDeleted:0,ok:0,err:v(t)}}return e})}catch(t){e=!0,r=t}if(n=null,!e)try{l.emit("change","del",t,r)}catch(t){console.log(t)}return e?Promise.reject(r):r},l.delAll=async function(t={}){let e=!1,o=null;try{let e=await s(),n=gt(e),u=0;if(_r(t)){let o=new r.Query(t).find(e).all();if(u=gt(o),0===u);else if(n===u)for(let t of e)await f.del(t.id);else{let t={};Se(o,(e,n)=>{t[e.id]={k:n,v:e}});for(let n of e)Or(t,n.id)&&await f.del(n.id)}}else{u=n;for(let t of e)await f.del(t.id)}o={n:u,nDeleted:u,ok:1}}catch(t){e=!0,o=t}if(n=null,!e)try{l.emit("change","delAll",null,o)}catch(t){console.log(t)}return e?Promise.reject(o):o},l.close=async()=>{f&&"closed"!==f.status&&await f.close()},l}});
7
7
  //# sourceMappingURL=w-orm-lmdb.umd.js.map