gitoriaLog in with ident

mpackdb

All repositories: gitoria

ReadmeCodePull requestsReleasesTicketsSettings
Commitb4db6391b4db6391initial commitcaramboleyob4db6391/dist/mpackdb.min.js

57.9 KB

  1. var ee=(t=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(t,{get:(e,r)=>(typeof require<"u"?require:e)[r]}):t)(function(t){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+t+'" is not supported')});var Ie=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var wr=Ie((Gi,mr)=>{"use strict";var pr=()=>process.platform==="linux",Qe=null,qn=()=>{if(!Qe)if(pr()&&process.report){let t=process.report.excludeNetwork;process.report.excludeNetwork=!0,Qe=process.report.getReport(),process.report.excludeNetwork=t}else Qe={};return Qe};mr.exports={isLinux:pr,getReport:qn}});var br=Ie((Ji,gr)=>{"use strict";var Me=ee("fs"),$n="/usr/bin/ldd",Hn="/proc/self/exe",et=2048,Gn=t=>{let e=Me.openSync(t,"r"),r=Buffer.alloc(et),n=Me.readSync(e,r,0,et,0);return Me.close(e,()=>{}),r.subarray(0,n)},Jn=t=>new Promise((e,r)=>{Me.open(t,"r",(n,i)=>{if(n)r(n);else{let s=Buffer.alloc(et);Me.read(i,s,0,et,0,(f,u)=>{e(s.subarray(0,u)),Me.close(i,()=>{})})}})});gr.exports={LDD_PATH:$n,SELF_PATH:Hn,readFileSync:Gn,readFile:Jn}});var Sr=Ie((Wi,_r)=>{"use strict";var Wn=t=>{if(t.length<64||t.readUInt32BE(0)!==2135247942||t.readUInt8(4)!==2||t.readUInt8(5)!==1)return null;let e=t.readUInt32LE(32),r=t.readUInt16LE(54),n=t.readUInt16LE(56);for(let i=0;i<n;i++){let s=e+i*r;if(t.readUInt32LE(s)===3){let u=t.readUInt32LE(s+8),d=t.readUInt32LE(s+32);return t.subarray(u,u+d).toString().replace(/\0.*$/g,"")}}return null};_r.exports={interpreterPath:Wn}});var jr=Ie((Yi,Vr)=>{"use strict";var Er=ee("child_process"),{isLinux:De,getReport:kr}=wr(),{LDD_PATH:tt,SELF_PATH:Tr,readFile:It,readFileSync:Et}=br(),{interpreterPath:Ur}=Sr(),ce,ue,de,Or="getconf GNU_LIBC_VERSION 2>&1 || true; ldd --version 2>&1 || true",Se="",vr=()=>Se||new Promise(t=>{Er.exec(Or,(e,r)=>{Se=e?" ":r,t(Se)})}),Ar=()=>{if(!Se)try{Se=Er.execSync(Or,{encoding:"utf8"})}catch{Se=" "}return Se},pe="glibc",Lr=/LIBC[a-z0-9 \-).]*?(\d+\.\d+)/i,ve="musl",Yn=t=>t.includes("libc.musl-")||t.includes("ld-musl-"),Pr=()=>{let t=kr();return t.header&&t.header.glibcVersionRuntime?pe:Array.isArray(t.sharedObjects)&&t.sharedObjects.some(Yn)?ve:null},Br=t=>{let[e,r]=t.split(/[\r\n]+/);return e&&e.includes(pe)?pe:r&&r.includes(ve)?ve:null},Rr=t=>{if(t){if(t.includes("/ld-musl-"))return ve;if(t.includes("/ld-linux-"))return pe}return null},Nr=t=>(t=t.toString(),t.includes("musl")?ve:t.includes("GNU C Library")?pe:null),Xn=async()=>{if(ue!==void 0)return ue;ue=null;try{let t=await It(tt);ue=Nr(t)}catch{}return ue},Zn=()=>{if(ue!==void 0)return ue;ue=null;try{let t=Et(tt);ue=Nr(t)}catch{}return ue},Qn=async()=>{if(ce!==void 0)return ce;ce=null;try{let t=await It(Tr),e=Ur(t);ce=Rr(e)}catch{}return ce},ei=()=>{if(ce!==void 0)return ce;ce=null;try{let t=Et(Tr),e=Ur(t);ce=Rr(e)}catch{}return ce},Mr=async()=>{let t=null;if(De()&&(t=await Qn(),!t&&(t=await Xn(),t||(t=Pr()),!t))){let e=await vr();t=Br(e)}return t},Dr=()=>{let t=null;if(De()&&(t=ei(),!t&&(t=Zn(),t||(t=Pr()),!t))){let e=Ar();t=Br(e)}return t},ti=async()=>De()&&await Mr()!==pe,ri=()=>De()&&Dr()!==pe,ni=async()=>{if(de!==void 0)return de;de=null;try{let e=(await It(tt)).match(Lr);e&&(de=e[1])}catch{}return de},ii=()=>{if(de!==void 0)return de;de=null;try{let e=Et(tt).match(Lr);e&&(de=e[1])}catch{}return de},Cr=()=>{let t=kr();return t.header&&t.header.glibcVersionRuntime?t.header.glibcVersionRuntime:null},Ir=t=>t.trim().split(/\s+/)[1],Fr=t=>{let[e,r,n]=t.split(/[\r\n]+/);return e&&e.includes(pe)?Ir(e):r&&n&&r.includes(ve)?Ir(n):null},si=async()=>{let t=null;if(De()&&(t=await ni(),t||(t=Cr()),!t)){let e=await vr();t=Fr(e)}return t},ai=()=>{let t=null;if(De()&&(t=ii(),t||(t=Cr()),!t)){let e=Ar();t=Fr(e)}return t};Vr.exports={GLIBC:pe,MUSL:ve,family:Mr,familySync:Dr,isNonGlibcLinux:ti,isNonGlibcLinuxSync:ri,version:si,versionSync:ai}});var tn=Ie((Xi,en)=>{var li=ee("fs"),ae=ee("path"),fi=ee("url"),qr=ee("os"),$r=typeof __webpack_require__=="function"?__non_webpack_require__:ee,oi=process.config&&process.config.variables||{},ci=!!process.env.PREBUILDS_ONLY,vt=process.versions,Tt=vt.modules;(vt.deno||process.isBun)&&(Tt="unsupported");var kt=hi()?"electron":di()?"node-webkit":"node",rt=process.env.npm_config_arch||qr.arch(),nt=process.env.npm_config_platform||qr.platform(),Hr=process.env.LIBC||(xi(nt)?"musl":"glibc"),Ut=process.env.ARM_VERSION||(rt==="arm64"?"8":oi.arm_version)||"",Gr=(vt.uv||"").split(".")[0];en.exports=he;function he(t){return $r(he.resolve(t))}he.resolve=he.path=function(t){t=ae.resolve(t||".");var e="",r;try{e=$r(ae.join(t,"package.json")).name;var n=e.toUpperCase().replace(/-/g,"_");process.env[n+"_PREBUILD"]&&(t=process.env[n+"_PREBUILD"])}catch(_){r=_}if(!ci){var i=Kr(ae.join(t,"build/Release"),zr);if(i)return i;var s=Kr(ae.join(t,"build/Debug"),zr);if(s)return s}var f=U(t);if(f)return f;var u=U(ae.dirname(process.execPath));if(u)return u;var d=(e[0]=="@"?"":"@"+e+"/")+e+"-"+nt+"-"+rt,w;try{var g=ae.dirname(ee("module").createRequire(fi.pathToFileURL(ae.join(t,"package.json"))).resolve(d));return k(g)}catch(_){w=_}var T=["platform="+nt,"arch="+rt,"runtime="+kt,"abi="+Tt,"uv="+Gr,Ut?"armv="+Ut:"","libc="+Hr,"node="+process.versions.node,process.versions.electron?"electron="+process.versions.electron:"",typeof __webpack_require__=="function"?"webpack=true":""].filter(Boolean).join(" ");let E="No native build was found for "+T+`
  2. attempted loading from: `+t+" and package: "+d+`
  3. `;throw r&&(E+="Error finding package.json: "+r.message+`
  4. `),w&&(E+="Error resolving package: "+w.message+`
  5. `),new Error(E);function U(_){var M=Ot(ae.join(_,"prebuilds")).map(Jr),q=M.filter(Wr(nt,rt)).sort(Yr)[0];if(q)return k(ae.join(_,"prebuilds",q.name))}function k(_){var M=Ot(_).map(Xr),q=M.filter(Zr(kt,Tt)),D=q.sort(Qr(kt))[0];if(D)return ae.join(_,D.file)}};function Ot(t){try{return li.readdirSync(t)}catch{return[]}}function Kr(t,e){var r=Ot(t).filter(e);return r[0]&&ae.join(t,r[0])}function zr(t){return/\.node$/.test(t)}function Jr(t){var e=t.split("-");if(e.length===2){var r=e[0],n=e[1].split("+");if(r&&n.length&&n.every(Boolean))return{name:t,platform:r,architectures:n}}}function Wr(t,e){return function(r){return r==null||r.platform!==t?!1:r.architectures.includes(e)}}function Yr(t,e){return t.architectures.length-e.architectures.length}function Xr(t){var e=t.split("."),r=e.pop(),n={file:t,specificity:0};if(r==="node"){for(var i=0;i<e.length;i++){var s=e[i];if(s==="node"||s==="electron"||s==="node-webkit")n.runtime=s;else if(s==="napi")n.napi=!0;else if(s.slice(0,3)==="abi")n.abi=s.slice(3);else if(s.slice(0,2)==="uv")n.uv=s.slice(2);else if(s.slice(0,4)==="armv")n.armv=s.slice(4);else if(s==="glibc"||s==="musl")n.libc=s;else continue;n.specificity++}return n}}function Zr(t,e){return function(r){return!(r==null||r.runtime!==t&&!ui(r)||r.abi!==e&&!r.napi||r.uv&&r.uv!==Gr||r.armv&&r.armv!==Ut||r.libc&&r.libc!==Hr)}}function ui(t){return t.runtime==="node"&&t.napi}function Qr(t){return function(e,r){return e.runtime!==r.runtime?e.runtime===t?-1:1:e.abi!==r.abi?e.abi?-1:1:e.specificity!==r.specificity?e.specificity>r.specificity?-1:1:0}}function di(){return!!(process.versions&&process.versions.nw)}function hi(){return process.versions&&process.versions.electron||process.env.ELECTRON_RUN_AS_NODE?!0:typeof window<"u"&&window.process&&window.process.type==="renderer"}function xi(t){if(t!=="linux")return!1;let{familySync:e,MUSL:r}=jr();return e()===r}he.parseTags=Xr;he.matchTags=Zr;he.compareTags=Qr;he.parseTuple=Jr;he.matchTuple=Wr;he.compareTuples=Yr});var rn=Ie((Qi,Lt)=>{var At=typeof __webpack_require__=="function"?__non_webpack_require__:ee;typeof At.addon=="function"?Lt.exports=At.addon.bind(At):Lt.exports=tn()});var sn=Ie((ts,nn)=>{nn.exports=rn()(__dirname)});var Le=class{#t;#r;#e;#n;constructor(e,r=()=>!0,n={}){this.#t=e,this.#r=r,this.#n=n}then(e,r){this.toArray().then(e,r)}async*[Symbol.asyncIterator](){this.#e||(this.#e=this.#t.recordGenerator(this.#r,this.#n)),yield*this.#e}next(){return this.#e||(this.#e=this.#t.recordGenerator(this.#r,this.#n)),this.#e.next()}async toArray(){let e=[];for await(let r of this)e.push(r);return e}};import{dirname as cn,basename as un,extname as dn,resolve as hn}from"path";import{createReadStream as Si,createWriteStream as xn}from"fs";import{mkdir as Ii,open as Ei,stat as yn,readFile as ki,writeFile as pn,rename as Ti,unlink as Ui}from"fs/promises";var at;try{at=new TextDecoder}catch{}var p,re,a=0;var ct=[],ke=ct,Ve=0,$={},N,xe,te=0,ie=0,W,ye,Z=[],R,Nt={useRecords:!1,mapsAsObjects:!0},je=class{},ut=new je;ut.name="MessagePack 0xC1";var be=!1,qt=2,lt,ft,ot;try{new Function("")}catch{qt=1/0}var _e=class t{constructor(e){e&&(e.useRecords===!1&&e.mapsAsObjects===void 0&&(e.mapsAsObjects=!0),e.sequential&&e.trusted!==!1&&(e.trusted=!0,!e.structures&&e.useRecords!=!1&&(e.structures=[],e.maxSharedStructures||(e.maxSharedStructures=0))),e.structures?e.structures.sharedLength=e.structures.length:e.getStructures&&((e.structures=[]).uninitialized=!0,e.structures.sharedLength=0),e.int64AsNumber&&(e.int64AsType="number")),Object.assign(this,e)}unpack(e,r){if(p)return tr(()=>(He(),this?this.unpack(e,r):t.prototype.unpack.call(Nt,e,r)));!e.buffer&&e.constructor===ArrayBuffer&&(e=typeof Buffer<"u"?Buffer.from(e):new Uint8Array(e)),typeof r=="object"?(re=r.end||e.length,a=r.start||0):(a=0,re=r>-1?r:e.length),Ve=0,ie=0,xe=null,ke=ct,W=null,p=e;try{R=e.dataView||(e.dataView=new DataView(e.buffer,e.byteOffset,e.byteLength))}catch(n){throw p=null,e instanceof Uint8Array?n:new Error("Source must be a Uint8Array or Buffer but was a "+(e&&typeof e=="object"?e.constructor.name:typeof e))}if(this instanceof t){if($=this,this.structures)return N=this.structures,qe(r);(!N||N.length>0)&&(N=[])}else $=Nt,(!N||N.length>0)&&(N=[]);return qe(r)}unpackMultiple(e,r){let n,i=0;try{be=!0;let s=e.length,f=this?this.unpack(e,s):Ge.unpack(e,s);if(r){if(r(f,i,a)===!1)return;for(;a<s;)if(i=a,r(qe(),i,a)===!1)return}else{for(n=[f];a<s;)i=a,n.push(qe());return n}}catch(s){throw s.lastPosition=i,s.values=n,s}finally{be=!1,He()}}_mergeStructures(e,r){ft&&(e=ft.call(this,e)),e=e||[],Object.isFrozen(e)&&(e=e.map(n=>n.slice(0)));for(let n=0,i=e.length;n<i;n++){let s=e[n];s&&(s.isShared=!0,n>=32&&(s.highByte=n-32>>5))}e.sharedLength=e.length;for(let n in r||[])if(n>=0){let i=e[n],s=r[n];s&&(i&&((e.restoreStructures||(e.restoreStructures=[]))[n]=i),e[n]=s)}return this.structures=e}decode(e,r){return this.unpack(e,r)}};function qe(t){try{if(!$.trusted&&!be){let r=N.sharedLength||0;r<N.length&&(N.length=r)}let e;if($.randomAccessStructure&&p[a]<64&&p[a]>=32&&lt?(e=lt(p,a,re,$),p=null,!(t&&t.lazy)&&e&&(e=e.toJSON()),a=re):e=J(),W&&(a=W.postBundlePosition,W=null),be&&(N.restoreStructures=null),a==re)N&&N.restoreStructures&&Mt(),N=null,p=null,ye&&(ye=null);else{if(a>re)throw new Error("Unexpected end of MessagePack data");if(!be){let r;try{r=JSON.stringify(e,(n,i)=>typeof i=="bigint"?`${i}n`:i).slice(0,100)}catch(n){r="(JSON view not available "+n+")"}throw new Error("Data read, but end of buffer not reached "+r)}}return e}catch(e){throw N&&N.restoreStructures&&Mt(),He(),(e instanceof RangeError||e.message.startsWith("Unexpected end of buffer")||a>re)&&(e.incomplete=!0),e}}function Mt(){for(let t in N.restoreStructures)N[t]=N.restoreStructures[t];N.restoreStructures=null}function J(){let t=p[a++];if(t<160)if(t<128){if(t<64)return t;{let e=N[t&63]||$.getStructures&&$t()[t&63];return e?(e.read||(e.read=dt(e,t&63)),e.read()):t}}else if(t<144)if(t-=128,$.mapsAsObjects){let e={};for(let r=0;r<t;r++){let n=Qt();n==="__proto__"&&(n="__proto_"),e[n]=J()}return e}else{let e=new Map;for(let r=0;r<t;r++)e.set(J(),J());return e}else{t-=144;let e=new Array(t);for(let r=0;r<t;r++)e[r]=J();return $.freezeData?Object.freeze(e):e}else if(t<192){let e=t-160;if(ie>=a)return xe.slice(a-te,(a+=e)-te);if(ie==0&&re<140){let r=e<16?ht(e):Zt(e);if(r!=null)return r}return $e(e)}else{let e;switch(t){case 192:return null;case 193:return W?(e=J(),e>0?W[1].slice(W.position1,W.position1+=e):W[0].slice(W.position0,W.position0-=e)):ut;case 194:return!1;case 195:return!0;case 196:if(e=p[a++],e===void 0)throw new Error("Unexpected end of buffer");return st(e);case 197:return e=R.getUint16(a),a+=2,st(e);case 198:return e=R.getUint32(a),a+=4,st(e);case 199:return Ee(p[a++]);case 200:return e=R.getUint16(a),a+=2,Ee(e);case 201:return e=R.getUint32(a),a+=4,Ee(e);case 202:if(e=R.getFloat32(a),$.useFloat32>2){let r=Ue[(p[a]&127)<<1|p[a+1]>>7];return a+=4,(r*e+(e>0?.5:-.5)>>0)/r}return a+=4,e;case 203:return e=R.getFloat64(a),a+=8,e;case 204:return p[a++];case 205:return e=R.getUint16(a),a+=2,e;case 206:return e=R.getUint32(a),a+=4,e;case 207:return $.int64AsType==="number"?(e=R.getUint32(a)*4294967296,e+=R.getUint32(a+4)):$.int64AsType==="string"?e=R.getBigUint64(a).toString():$.int64AsType==="auto"?(e=R.getBigUint64(a),e<=BigInt(2)<<BigInt(52)&&(e=Number(e))):e=R.getBigUint64(a),a+=8,e;case 208:return R.getInt8(a++);case 209:return e=R.getInt16(a),a+=2,e;case 210:return e=R.getInt32(a),a+=4,e;case 211:return $.int64AsType==="number"?(e=R.getInt32(a)*4294967296,e+=R.getUint32(a+4)):$.int64AsType==="string"?e=R.getBigInt64(a).toString():$.int64AsType==="auto"?(e=R.getBigInt64(a),e>=BigInt(-2)<<BigInt(52)&&e<=BigInt(2)<<BigInt(52)&&(e=Number(e))):e=R.getBigInt64(a),a+=8,e;case 212:if(e=p[a++],e==114)return Kt(p[a++]&63);{let r=Z[e];if(r)return r.read?(a++,r.read(J())):r.noBuffer?(a++,r()):r(p.subarray(a,++a));throw new Error("Unknown extension "+e)}case 213:return e=p[a],e==114?(a++,Kt(p[a++]&63,p[a++])):Ee(2);case 214:return Ee(4);case 215:return Ee(8);case 216:return Ee(16);case 217:return e=p[a++],ie>=a?xe.slice(a-te,(a+=e)-te):Ht(e);case 218:return e=R.getUint16(a),a+=2,ie>=a?xe.slice(a-te,(a+=e)-te):Gt(e);case 219:return e=R.getUint32(a),a+=4,ie>=a?xe.slice(a-te,(a+=e)-te):Jt(e);case 220:return e=R.getUint16(a),a+=2,Ct(e);case 221:return e=R.getUint32(a),a+=4,Ct(e);case 222:return e=R.getUint16(a),a+=2,Ft(e);case 223:return e=R.getUint32(a),a+=4,Ft(e);default:if(t>=224)return t-256;if(t===void 0){let r=new Error("Unexpected end of MessagePack data");throw r.incomplete=!0,r}throw new Error("Unknown MessagePack token "+t)}}}var gn=/^[a-zA-Z_$][a-zA-Z\d_$]*$/;function dt(t,e){function r(){if(r.count++>qt){let i=t.read=new Function("r","return function(){return "+($.freezeData?"Object.freeze":"")+"({"+t.map(s=>s==="__proto__"?"__proto_:r()":gn.test(s)?s+":r()":"["+JSON.stringify(s)+"]:r()").join(",")+"})}")(J);return t.highByte===0&&(t.read=Dt(e,t.read)),i()}let n={};for(let i=0,s=t.length;i<s;i++){let f=t[i];f==="__proto__"&&(f="__proto_"),n[f]=J()}return $.freezeData?Object.freeze(n):n}return r.count=0,t.highByte===0?Dt(e,r):r}var Dt=(t,e)=>function(){let r=p[a++];if(r===0)return e();let n=t<32?-(t+(r<<5)):t+(r<<5),i=N[n]||$t()[n];if(!i)throw new Error("Record id is not defined for "+n);return i.read||(i.read=dt(i,t)),i.read()};function $t(){let t=tr(()=>(p=null,$.getStructures()));return N=$._mergeStructures(t,N)}var $e=Te,Ht=Te,Gt=Te,Jt=Te,Wt=!1;function Yt(t){Wt=!0,$e=e(1),Ht=e(2),Gt=e(3),Jt=e(5);function e(r){return function(i){let s=ke[Ve++];if(s==null){if(W)return Te(i);let u=p.byteOffset,d=t(a-r+u,re+u,p.buffer);if(typeof d=="string")s=d,ke=ct;else if(ke=d,Ve=1,ie=1,s=ke[0],s===void 0)throw new Error("Unexpected end of buffer")}let f=s.length;return f<=i?(a+=i,s):(xe=s,te=a,ie=a+f,a+=i,s.slice(0,i))}}}function Te(t){let e;if(t<16&&(e=ht(t)))return e;if(t>64&&at)return at.decode(p.subarray(a,a+=t));let r=a+t,n=[];for(e="";a<r;){let i=p[a++];if((i&128)===0)n.push(i);else if((i&224)===192){let s=p[a++]&63;n.push((i&31)<<6|s)}else if((i&240)===224){let s=p[a++]&63,f=p[a++]&63;n.push((i&31)<<12|s<<6|f)}else if((i&248)===240){let s=p[a++]&63,f=p[a++]&63,u=p[a++]&63,d=(i&7)<<18|s<<12|f<<6|u;d>65535&&(d-=65536,n.push(d>>>10&1023|55296),d=56320|d&1023),n.push(d)}else n.push(i);n.length>=4096&&(e+=Y.apply(String,n),n.length=0)}return n.length>0&&(e+=Y.apply(String,n)),e}function Xt(t,e,r){let n=p;p=t,a=e;try{return Te(r)}finally{p=n}}function Ct(t){let e=new Array(t);for(let r=0;r<t;r++)e[r]=J();return $.freezeData?Object.freeze(e):e}function Ft(t){if($.mapsAsObjects){let e={};for(let r=0;r<t;r++){let n=Qt();n==="__proto__"&&(n="__proto_"),e[n]=J()}return e}else{let e=new Map;for(let r=0;r<t;r++)e.set(J(),J());return e}}var Y=String.fromCharCode;function Zt(t){let e=a,r=new Array(t);for(let n=0;n<t;n++){let i=p[a++];if((i&128)>0){a=e;return}r[n]=i}return Y.apply(String,r)}function ht(t){if(t<4)if(t<2){if(t===0)return"";{let e=p[a++];if((e&128)>1){a-=1;return}return Y(e)}}else{let e=p[a++],r=p[a++];if((e&128)>0||(r&128)>0){a-=2;return}if(t<3)return Y(e,r);let n=p[a++];if((n&128)>0){a-=3;return}return Y(e,r,n)}else{let e=p[a++],r=p[a++],n=p[a++],i=p[a++];if((e&128)>0||(r&128)>0||(n&128)>0||(i&128)>0){a-=4;return}if(t<6){if(t===4)return Y(e,r,n,i);{let s=p[a++];if((s&128)>0){a-=5;return}return Y(e,r,n,i,s)}}else if(t<8){let s=p[a++],f=p[a++];if((s&128)>0||(f&128)>0){a-=6;return}if(t<7)return Y(e,r,n,i,s,f);let u=p[a++];if((u&128)>0){a-=7;return}return Y(e,r,n,i,s,f,u)}else{let s=p[a++],f=p[a++],u=p[a++],d=p[a++];if((s&128)>0||(f&128)>0||(u&128)>0||(d&128)>0){a-=8;return}if(t<10){if(t===8)return Y(e,r,n,i,s,f,u,d);{let w=p[a++];if((w&128)>0){a-=9;return}return Y(e,r,n,i,s,f,u,d,w)}}else if(t<12){let w=p[a++],g=p[a++];if((w&128)>0||(g&128)>0){a-=10;return}if(t<11)return Y(e,r,n,i,s,f,u,d,w,g);let T=p[a++];if((T&128)>0){a-=11;return}return Y(e,r,n,i,s,f,u,d,w,g,T)}else{let w=p[a++],g=p[a++],T=p[a++],E=p[a++];if((w&128)>0||(g&128)>0||(T&128)>0||(E&128)>0){a-=12;return}if(t<14){if(t===12)return Y(e,r,n,i,s,f,u,d,w,g,T,E);{let U=p[a++];if((U&128)>0){a-=13;return}return Y(e,r,n,i,s,f,u,d,w,g,T,E,U)}}else{let U=p[a++],k=p[a++];if((U&128)>0||(k&128)>0){a-=14;return}if(t<15)return Y(e,r,n,i,s,f,u,d,w,g,T,E,U,k);let _=p[a++];if((_&128)>0){a-=15;return}return Y(e,r,n,i,s,f,u,d,w,g,T,E,U,k,_)}}}}}function Vt(){let t=p[a++],e;if(t<192)e=t-160;else switch(t){case 217:e=p[a++];break;case 218:e=R.getUint16(a),a+=2;break;case 219:e=R.getUint32(a),a+=4;break;default:throw new Error("Expected string")}return Te(e)}function st(t){return $.copyBuffers?Uint8Array.prototype.slice.call(p,a,a+=t):p.subarray(a,a+=t)}function Ee(t){let e=p[a++];if(Z[e]){let r;return Z[e](p.subarray(a,r=a+=t),n=>{a=n;try{return J()}finally{a=r}})}else throw new Error("Unknown extension type "+e)}var jt=new Array(4096);function Qt(){let t=p[a++];if(t>=160&&t<192){if(t=t-160,ie>=a)return xe.slice(a-te,(a+=t)-te);if(!(ie==0&&re<180))return $e(t)}else return a--,er(J());let e=(t<<5^(t>1?R.getUint16(a):t>0?p[a]:0))&4095,r=jt[e],n=a,i=a+t-3,s,f=0;if(r&&r.bytes==t){for(;n<i;){if(s=R.getUint32(n),s!=r[f++]){n=1879048192;break}n+=4}for(i+=3;n<i;)if(s=p[n++],s!=r[f++]){n=1879048192;break}if(n===i)return a=n,r.string;i-=3,n=a}for(r=[],jt[e]=r,r.bytes=t;n<i;)s=R.getUint32(n),r.push(s),n+=4;for(i+=3;n<i;)s=p[n++],r.push(s);let u=t<16?ht(t):Zt(t);return u!=null?r.string=u:r.string=$e(t)}function er(t){if(typeof t=="string")return t;if(typeof t=="number"||typeof t=="boolean"||typeof t=="bigint")return t.toString();if(t==null)return t+"";if($.allowArraysInMapKeys&&Array.isArray(t)&&t.flat().every(e=>["string","number","boolean","bigint"].includes(typeof e)))return t.flat().toString();throw new Error(`Invalid property type for record: ${typeof t}`)}var Kt=(t,e)=>{let r=J().map(er),n=t;e!==void 0&&(t=t<32?-((e<<5)+t):(e<<5)+t,r.highByte=e);let i=N[t];return i&&(i.isShared||be)&&((N.restoreStructures||(N.restoreStructures=[]))[t]=i),N[t]=r,r.read=dt(r,n),r.read()};Z[0]=()=>{};Z[0].noBuffer=!0;Z[66]=t=>{let e=t.byteLength%8||8,r=BigInt(t[0]&128?t[0]-256:t[0]);for(let n=1;n<e;n++)r<<=BigInt(8),r+=BigInt(t[n]);if(t.byteLength!==e){let n=new DataView(t.buffer,t.byteOffset,t.byteLength),i=(s,f)=>{let u=f-s;if(u<=40){let T=n.getBigUint64(s);for(let E=s+8;E<f;E+=8)T<<=64n,T|=n.getBigUint64(E);return T}let d=s+(u>>4<<3),w=i(s,d),g=i(d,f);return w<<BigInt((f-d)*8)|g};r=r<<BigInt((n.byteLength-e)*8)|i(e,n.byteLength)}return r};var zt={Error,EvalError,RangeError,ReferenceError,SyntaxError,TypeError,URIError,AggregateError:typeof AggregateError=="function"?AggregateError:null};Z[101]=()=>{let t=J();if(!zt[t[0]]){let e=Error(t[1],{cause:t[2]});return e.name=t[0],e}return zt[t[0]](t[1],{cause:t[2]})};Z[105]=t=>{if($.structuredClone===!1)throw new Error("Structured clone extension is disabled");let e=R.getUint32(a-4);ye||(ye=new Map);let r=p[a],n;r>=144&&r<160||r==220||r==221?n=[]:r>=128&&r<144||r==222||r==223?n=new Map:(r>=199&&r<=201||r>=212&&r<=216)&&p[a+1]===115?n=new Set:n={};let i={target:n};ye.set(e,i);let s=J();if(i.used)Object.assign(n,s);else return i.target=s;if(n instanceof Map)for(let[f,u]of s.entries())n.set(f,u);if(n instanceof Set)for(let f of Array.from(s))n.add(f);return n};Z[112]=t=>{if($.structuredClone===!1)throw new Error("Structured clone extension is disabled");let e=R.getUint32(a-4),r=ye.get(e);return r.used=!0,r.target};Z[115]=()=>new Set(J());var xt=["Int8","Uint8","Uint8Clamped","Int16","Uint16","Int32","Uint32","Float32","Float64","BigInt64","BigUint64"].map(t=>t+"Array"),bn=typeof globalThis=="object"?globalThis:window;Z[116]=t=>{let e=t[0],r=Uint8Array.prototype.slice.call(t,1).buffer,n=xt[e];if(!n){if(e===16)return r;if(e===17)return new DataView(r);throw new Error("Could not find typed array for code "+e)}return new bn[n](r)};Z[120]=()=>{let t=J();return new RegExp(t[0],t[1])};var _n=[];Z[98]=t=>{let e=(t[0]<<24)+(t[1]<<16)+(t[2]<<8)+t[3],r=a;return a+=e-t.length,W=_n,W=[Vt(),Vt()],W.position0=0,W.position1=0,W.postBundlePosition=a,a=r,J()};Z[255]=t=>t.length==4?new Date((t[0]*16777216+(t[1]<<16)+(t[2]<<8)+t[3])*1e3):t.length==8?new Date(((t[0]<<22)+(t[1]<<14)+(t[2]<<6)+(t[3]>>2))/1e6+((t[3]&3)*4294967296+t[4]*16777216+(t[5]<<16)+(t[6]<<8)+t[7])*1e3):t.length==12?new Date(((t[0]<<24)+(t[1]<<16)+(t[2]<<8)+t[3])/1e6+((t[4]&128?-281474976710656:0)+t[6]*1099511627776+t[7]*4294967296+t[8]*16777216+(t[9]<<16)+(t[10]<<8)+t[11])*1e3):new Date("invalid");function tr(t){ot&&ot();let e=re,r=a,n=Ve,i=te,s=ie,f=xe,u=ke,d=ye,w=W,g=new Uint8Array(p.slice(0,re)),T=N,E=N.slice(0,N.length),U=$,k=be,_=t();return re=e,a=r,Ve=n,te=i,ie=s,xe=f,ke=u,ye=d,W=w,p=g,be=k,N=T,N.splice(0,N.length,...E),$=U,R=new DataView(p.buffer,p.byteOffset,p.byteLength),_}function He(){p=null,ye=null,N=null}var Ue=new Array(147);for(let t=0;t<256;t++)Ue[t]=+("1e"+Math.floor(45.15-t*.30103));var Ge=new _e({useRecords:!1}),yt=Ge.unpack,Sn=Ge.unpackMultiple,In=Ge.unpack,Je={NEVER:0,ALWAYS:1,DECIMAL_ROUND:3,DECIMAL_FIT:4},En=new Float32Array(1),Li=new Uint8Array(En.buffer,0,4);function rr(t,e,r){lt=t,ft=e,ot=r}var Ye;try{Ye=new TextEncoder}catch{}var wt,ar,Pe=typeof Buffer<"u",We=Pe?function(t){return Buffer.allocUnsafeSlow(t)}:Uint8Array,lr=Pe?Buffer:Uint8Array,nr=Pe?4294967296:2144337920,c,Ke,H,l=0,X,G=null,fr,kn=21760,Tn=/[\u0080-\uFFFF]/,fe=Symbol("record-id"),Be=class extends _e{constructor(e){super(e),this.offset=0;let r,n,i,s,f,u=lr.prototype.utf8Write?function(o,b){return c.utf8Write(o,b,c.byteLength-b)}:Ye&&Ye.encodeInto?function(o,b){return Ye.encodeInto(o,c.subarray(b)).written}:!1,d=this;e||(e={});let w=e&&e.sequential,g=e.structures||e.saveStructures,T=e.maxSharedStructures;if(T==null&&(T=g?32:0),T>8160)throw new Error("Maximum maxSharedStructure is 8160");e.structuredClone&&e.moreTypes==null&&(this.moreTypes=!0);let E=e.maxOwnStructures;E==null&&(E=g?32:64),!this.structures&&e.useRecords!=!1&&(this.structures=[]);let U=T>32||E+T>64,k=T+64,_=T+E+64;if(_>8256)throw new Error("Maximum maxSharedStructure + maxOwnStructure is 8192");let M=[],q=0,D=0;this.pack=this.encode=function(o,b){if(c||(c=new We(8192),H=c.dataView||(c.dataView=new DataView(c.buffer,0,8192)),l=0),X=c.length-10,X-l<2048?(c=new We(c.length),H=c.dataView||(c.dataView=new DataView(c.buffer,0,c.length)),X=c.length-10,l=0):l=l+7&2147483640,n=l,b&Nn&&(l+=b&255),f=d.structuredClone?new Map:null,d.bundleStrings&&typeof o!="string"?(G=[],G.size=1/0):G=null,s=d.structures,s){s.uninitialized&&(s=d._mergeStructures(d.getStructures()));let h=s.sharedLength||0;if(h>T)throw new Error("Shared structures is larger than maximum shared structures, try increasing maxSharedStructures to "+s.sharedLength);if(!s.transitions){s.transitions=Object.create(null);for(let y=0;y<h;y++){let A=s[y];if(!A)continue;let L,O=s.transitions;for(let K=0,z=A.length;K<z;K++){let le=A[K];L=O[le],L||(L=O[le]=Object.create(null)),O=L}O[fe]=y+64}this.lastNamedStructuresLength=h}w||(s.nextId=h+64)}i&&(i=!1);let m;try{d.randomAccessStructure&&o&&o.constructor&&o.constructor===Object?V(o):P(o);let h=G;if(G&&sr(n,P,0),f&&f.idsToInsert){let y=f.idsToInsert.sort((K,z)=>K.offset>z.offset?1:-1),A=y.length,L=-1;for(;h&&A>0;){let K=y[--A].offset+n;K<h.stringsPosition+n&&L===-1&&(L=0),K>h.position+n?L>=0&&(L+=6):(L>=0&&(H.setUint32(h.position+n,H.getUint32(h.position+n)+L),L=-1),h=h.previous,A++)}L>=0&&h&&H.setUint32(h.position+n,H.getUint32(h.position+n)+L),l+=y.length*6,l>X&&B(l),d.offset=l;let O=Un(c.subarray(n,l),y);return f=null,O}return d.offset=l,b&Bn?(c.start=n,c.end=l,c):c.subarray(n,l)}catch(h){throw m=h,h}finally{if(s&&(se(),i&&d.saveStructures)){let h=s.sharedLength||0,y=c.subarray(n,l),A=or(s,d);if(!m)return d.saveStructures(A,A.isCompatible)===!1?d.pack(o,b):(d.lastNamedStructuresLength=h,c.length>1073741824&&(c=null),y)}c.length>1073741824&&(c=null),b&Rn&&(l=n)}};let se=()=>{D<10&&D++;let o=s.sharedLength||0;if(s.length>o&&!w&&(s.length=o),q>1e4)s.transitions=null,D=0,q=0,M.length>0&&(M=[]);else if(M.length>0&&!w){for(let b=0,m=M.length;b<m;b++)M[b][fe]=0;M=[]}},C=o=>{var b=o.length;b<16?c[l++]=144|b:b<65536?(c[l++]=220,c[l++]=b>>8,c[l++]=b&255):(c[l++]=221,H.setUint32(l,b),l+=4);for(let m=0;m<b;m++)P(o[m])},P=o=>{l>X&&(c=B(l));var b=typeof o,m;if(b==="string"){let h=o.length;if(G&&h>=4&&h<4096){if((G.size+=h)>kn){let O,K=(G[0]?G[0].length*3+G[1].length:0)+10;l+K>X&&(c=B(l+K));let z;G.position?(z=G,c[l]=200,l+=3,c[l++]=98,O=l-n,l+=4,sr(n,P,0),H.setUint16(O+n-3,l-n-O)):(c[l++]=214,c[l++]=98,O=l-n,l+=4),G=["",""],G.previous=z,G.size=0,G.position=O}let L=Tn.test(o);G[L?0:1]+=o,c[l++]=193,P(L?-h:h);return}let y;h<32?y=1:h<256?y=2:h<65536?y=3:y=5;let A=h*3;if(l+A>X&&(c=B(l+A)),h<64||!u){let L,O,K,z=l+y;for(L=0;L<h;L++)O=o.charCodeAt(L),O<128?c[z++]=O:O<2048?(c[z++]=O>>6|192,c[z++]=O&63|128):(O&64512)===55296&&((K=o.charCodeAt(L+1))&64512)===56320?(O=65536+((O&1023)<<10)+(K&1023),L++,c[z++]=O>>18|240,c[z++]=O>>12&63|128,c[z++]=O>>6&63|128,c[z++]=O&63|128):(c[z++]=O>>12|224,c[z++]=O>>6&63|128,c[z++]=O&63|128);m=z-l-y}else m=u(o,l+y);m<32?c[l++]=160|m:m<256?(y<2&&c.copyWithin(l+2,l+1,l+1+m),c[l++]=217,c[l++]=m):m<65536?(y<3&&c.copyWithin(l+3,l+2,l+2+m),c[l++]=218,c[l++]=m>>8,c[l++]=m&255):(y<5&&c.copyWithin(l+5,l+3,l+3+m),c[l++]=219,H.setUint32(l,m),l+=4),l+=m}else if(b==="number")if(o>>>0===o)o<32||o<128&&this.useRecords===!1||o<64&&!this.randomAccessStructure?c[l++]=o:o<256?(c[l++]=204,c[l++]=o):o<65536?(c[l++]=205,c[l++]=o>>8,c[l++]=o&255):(c[l++]=206,H.setUint32(l,o),l+=4);else if(o>>0===o)o>=-32?c[l++]=256+o:o>=-128?(c[l++]=208,c[l++]=o+256):o>=-32768?(c[l++]=209,H.setInt16(l,o),l+=2):(c[l++]=210,H.setInt32(l,o),l+=4);else{let h;if((h=this.useFloat32)>0&&o<4294967296&&o>=-2147483648){c[l++]=202,H.setFloat32(l,o);let y;if(h<4||(y=o*Ue[(c[l]&127)<<1|c[l+1]>>7])>>0===y){l+=4;return}else l--}c[l++]=203,H.setFloat64(l,o),l+=8}else if(b==="object"||b==="function")if(!o)c[l++]=192;else{if(f){let y=f.get(o);if(y){if(!y.id){let A=f.idsToInsert||(f.idsToInsert=[]);y.id=A.push(y)}c[l++]=214,c[l++]=112,H.setUint32(l,y.id),l+=4;return}else f.set(o,{offset:l-n})}let h=o.constructor;if(h===Object)I(o);else if(h===Array)C(o);else if(h===Map)if(this.mapAsEmptyObject)c[l++]=128;else{m=o.size,m<16?c[l++]=128|m:m<65536?(c[l++]=222,c[l++]=m>>8,c[l++]=m&255):(c[l++]=223,H.setUint32(l,m),l+=4);for(let[y,A]of o)P(y),P(A)}else{for(let y=0,A=wt.length;y<A;y++){let L=ar[y];if(o instanceof L){let O=wt[y];if(O.write){O.type&&(c[l++]=212,c[l++]=O.type,c[l++]=0);let Fe=O.write.call(this,o);Fe===o?Array.isArray(o)?C(o):I(o):P(Fe);return}let K=c,z=H,le=l;c=null;let ge;try{ge=O.pack.call(this,o,Fe=>(c=K,K=null,l+=Fe,l>X&&B(l),{target:c,targetView:H,position:l-Fe}),P)}finally{K&&(c=K,H=z,l=le,X=c.length-10)}ge&&(ge.length+l>X&&B(ge.length+l),l=ir(ge,c,l,O.type));return}}if(Array.isArray(o))C(o);else{if(o.toJSON){let y=o.toJSON();if(y!==o)return P(y)}if(b==="function")return P(this.writeFunction&&this.writeFunction(o));I(o)}}}else if(b==="boolean")c[l++]=o?195:194;else if(b==="bigint"){if(o<9223372036854776e3&&o>=-9223372036854776e3)c[l++]=211,H.setBigInt64(l,o);else if(o<18446744073709552e3&&o>0)c[l++]=207,H.setBigUint64(l,o);else if(this.largeBigIntToFloat)c[l++]=203,H.setFloat64(l,Number(o));else{if(this.largeBigIntToString)return P(o.toString());if(this.useBigIntExtension||this.moreTypes){let h=o<0?BigInt(-1):BigInt(0),y;if(o>>BigInt(65536)===h){let A=BigInt(18446744073709552e3)-BigInt(1),L=[];for(;L.push(o&A),o>>BigInt(63)!==h;)o>>=BigInt(64);y=new Uint8Array(new BigUint64Array(L).buffer),y.reverse()}else{let A=o<0,L=(A?~o:o).toString(16);if(L.length%2?L="0"+L:parseInt(L.charAt(0),16)>=8&&(L="00"+L),Pe)y=Buffer.from(L,"hex");else{y=new Uint8Array(L.length/2);for(let O=0;O<y.length;O++)y[O]=parseInt(L.slice(O*2,O*2+2),16)}if(A)for(let O=0;O<y.length;O++)y[O]=~y[O]}y.length+l>X&&B(y.length+l),l=ir(y,c,l,66);return}else throw new RangeError(o+" was too large to fit in MessagePack 64-bit integer format, use useBigIntExtension, or set largeBigIntToFloat to convert to float-64, or set largeBigIntToString to convert to string")}l+=8}else if(b==="undefined")this.encodeUndefinedAsNil?c[l++]=192:(c[l++]=212,c[l++]=0,c[l++]=0);else throw new Error("Unknown type: "+b)},j=this.variableMapSize||this.coercibleKeyAsNumber||this.skipValues?o=>{let b;if(this.skipValues){b=[];for(let y in o)(typeof o.hasOwnProperty!="function"||o.hasOwnProperty(y))&&!this.skipValues.includes(o[y])&&b.push(y)}else b=Object.keys(o);let m=b.length;m<16?c[l++]=128|m:m<65536?(c[l++]=222,c[l++]=m>>8,c[l++]=m&255):(c[l++]=223,H.setUint32(l,m),l+=4);let h;if(this.coercibleKeyAsNumber)for(let y=0;y<m;y++){h=b[y];let A=Number(h);P(isNaN(A)?h:A),P(o[h])}else for(let y=0;y<m;y++)P(h=b[y]),P(o[h])}:o=>{c[l++]=222;let b=l-n;l+=2;let m=0;for(let h in o)(typeof o.hasOwnProperty!="function"||o.hasOwnProperty(h))&&(P(h),P(o[h]),m++);if(m>65535)throw new Error('Object is too large to serialize with fast 16-bit map size, use the "variableMapSize" option to serialize this object');c[b+++n]=m>>8,c[b+n]=m&255},S=this.useRecords===!1?j:e.progressiveRecords&&!U?o=>{let b,m=s.transitions||(s.transitions=Object.create(null)),h=l++-n,y;for(let A in o)if(typeof o.hasOwnProperty!="function"||o.hasOwnProperty(A)){if(b=m[A],b)m=b;else{let L=Object.keys(o),O=m;m=s.transitions;let K=0;for(let z=0,le=L.length;z<le;z++){let ge=L[z];b=m[ge],b||(b=m[ge]=Object.create(null),K++),m=b}h+n+1==l?(l--,v(m,L,K)):F(m,L,h,K),y=!0,m=O[A]}P(o[A])}if(!y){let A=m[fe];A?c[h+n]=A:F(m,Object.keys(o),h,0)}}:o=>{let b,m=s.transitions||(s.transitions=Object.create(null)),h=0;for(let A in o)(typeof o.hasOwnProperty!="function"||o.hasOwnProperty(A))&&(b=m[A],b||(b=m[A]=Object.create(null),h++),m=b);let y=m[fe];y?y>=96&&U?(c[l++]=((y-=96)&31)+96,c[l++]=y>>5):c[l++]=y:v(m,m.__keys__||Object.keys(o),h);for(let A in o)(typeof o.hasOwnProperty!="function"||o.hasOwnProperty(A))&&P(o[A])},x=typeof this.useRecords=="function"&&this.useRecords,I=x?o=>{x(o)?S(o):j(o)}:S,B=o=>{let b;if(o>16777216){if(o-n>nr)throw new Error("Packed buffer would be larger than maximum buffer size");b=Math.min(nr,Math.round(Math.max((o-n)*(o>67108864?1.25:2),4194304)/4096)*4096)}else b=(Math.max(o-n<<2,c.length-1)>>12)+1<<12;let m=new We(b);return H=m.dataView||(m.dataView=new DataView(m.buffer,0,b)),o=Math.min(o,c.length),c.copy?c.copy(m,0,n,o):m.set(c.slice(n,o)),l-=n,n=0,X=m.length-10,c=m},v=(o,b,m)=>{let h=s.nextId;h||(h=64),h<k&&this.shouldShareStructure&&!this.shouldShareStructure(b)?(h=s.nextOwnId,h<_||(h=k),s.nextOwnId=h+1):(h>=_&&(h=k),s.nextId=h+1);let y=b.highByte=h>=96&&U?h-96>>5:-1;o[fe]=h,o.__keys__=b,s[h-64]=b,h<k?(b.isShared=!0,s.sharedLength=h-63,i=!0,y>=0?(c[l++]=(h&31)+96,c[l++]=y):c[l++]=h):(y>=0?(c[l++]=213,c[l++]=114,c[l++]=(h&31)+96,c[l++]=y):(c[l++]=212,c[l++]=114,c[l++]=h),m&&(q+=D*m),M.length>=E&&(M.shift()[fe]=0),M.push(o),P(b))},F=(o,b,m,h)=>{let y=c,A=l,L=X,O=n;c=Ke,l=0,n=0,c||(Ke=c=new We(8192)),X=c.length-10,v(o,b,h),Ke=c;let K=l;if(c=y,l=A,X=L,n=O,K>1){let z=l+K-1;z>X&&B(z);let le=m+n;c.copyWithin(le+K,le+1,l),c.set(Ke.slice(0,K),le),l=z}else c[m+n]=Ke[0]},V=o=>{let b=fr(o,c,n,l,s,B,(m,h,y)=>{if(y)return i=!0;l=h;let A=c;return P(m),se(),A!==c?{position:l,targetView:H,target:c}:l},this);if(b===0)return I(o);l=b}}useBuffer(e){c=e,c.dataView||(c.dataView=new DataView(c.buffer,c.byteOffset,c.byteLength)),H=c.dataView,l=0}set position(e){l=e}get position(){return l}clearSharedData(){this.structures&&(this.structures=[]),this.typedStructs&&(this.typedStructs=[])}};ar=[Date,Set,Error,RegExp,ArrayBuffer,Object.getPrototypeOf(Uint8Array.prototype).constructor,DataView,je];wt=[{pack(t,e,r){let n=t.getTime()/1e3;if((this.useTimestamp32||t.getMilliseconds()===0)&&n>=0&&n<4294967296){let{target:i,targetView:s,position:f}=e(6);i[f++]=214,i[f++]=255,s.setUint32(f,n)}else if(n>0&&n<4294967296){let{target:i,targetView:s,position:f}=e(10);i[f++]=215,i[f++]=255,s.setUint32(f,t.getMilliseconds()*4e6+(n/1e3/4294967296>>0)),s.setUint32(f+4,n)}else if(isNaN(n)){if(this.onInvalidDate)return e(0),r(this.onInvalidDate());let{target:i,targetView:s,position:f}=e(3);i[f++]=212,i[f++]=255,i[f++]=255}else{let{target:i,targetView:s,position:f}=e(15);i[f++]=199,i[f++]=12,i[f++]=255,s.setUint32(f,t.getMilliseconds()*1e6),s.setBigInt64(f+4,BigInt(Math.floor(n)))}}},{pack(t,e,r){if(this.setAsEmptyObject)return e(0),r({});let n=Array.from(t),{target:i,position:s}=e(this.moreTypes?3:0);this.moreTypes&&(i[s++]=212,i[s++]=115,i[s++]=0),r(n)}},{pack(t,e,r){let{target:n,position:i}=e(this.moreTypes?3:0);this.moreTypes&&(n[i++]=212,n[i++]=101,n[i++]=0),r([t.name,t.message,t.cause])}},{pack(t,e,r){let{target:n,position:i}=e(this.moreTypes?3:0);this.moreTypes&&(n[i++]=212,n[i++]=120,n[i++]=0),r([t.source,t.flags])}},{pack(t,e){this.moreTypes?pt(t,16,e):mt(Pe?Buffer.from(t):new Uint8Array(t),e)}},{pack(t,e){let r=t.constructor;r!==lr&&this.moreTypes?pt(t,xt.indexOf(r.name),e):mt(t,e)}},{pack(t,e){this.moreTypes?pt(t,17,e):mt(Pe?Buffer.from(t):new Uint8Array(t),e)}},{pack(t,e){let{target:r,position:n}=e(1);r[n]=193}}];function pt(t,e,r,n){let i=t.byteLength;if(i+1<256){var{target:s,position:f}=r(4+i);s[f++]=199,s[f++]=i+1}else if(i+1<65536){var{target:s,position:f}=r(5+i);s[f++]=200,s[f++]=i+1>>8,s[f++]=i+1&255}else{var{target:s,position:f,targetView:u}=r(7+i);s[f++]=201,u.setUint32(f,i+1),f+=4}s[f++]=116,s[f++]=e,t.buffer||(t=new Uint8Array(t)),s.set(new Uint8Array(t.buffer,t.byteOffset,t.byteLength),f)}function mt(t,e){let r=t.byteLength;var n,i;if(r<256){var{target:n,position:i}=e(r+2);n[i++]=196,n[i++]=r}else if(r<65536){var{target:n,position:i}=e(r+3);n[i++]=197,n[i++]=r>>8,n[i++]=r&255}else{var{target:n,position:i,targetView:s}=e(r+5);n[i++]=198,s.setUint32(i,r),i+=4}n.set(t,i)}function ir(t,e,r,n){let i=t.length;switch(i){case 1:e[r++]=212;break;case 2:e[r++]=213;break;case 4:e[r++]=214;break;case 8:e[r++]=215;break;case 16:e[r++]=216;break;default:i<256?(e[r++]=199,e[r++]=i):i<65536?(e[r++]=200,e[r++]=i>>8,e[r++]=i&255):(e[r++]=201,e[r++]=i>>24,e[r++]=i>>16&255,e[r++]=i>>8&255,e[r++]=i&255)}return e[r++]=n,e.set(t,r),r+=i,r}function Un(t,e){let r,n=e.length*6,i=t.length-n;for(;r=e.pop();){let s=r.offset,f=r.id;t.copyWithin(s+n,s,i),n-=6;let u=s+n;t[u++]=214,t[u++]=105,t[u++]=f>>24,t[u++]=f>>16&255,t[u++]=f>>8&255,t[u++]=f&255,i=s}return t}function sr(t,e,r){if(G.length>0){H.setUint32(G.position+t,l+r-G.position-t),G.stringsPosition=l-t;let n=G;G=null,e(n[0]),e(n[1])}}function or(t,e){return t.isCompatible=r=>{let n=!r||(e.lastNamedStructuresLength||0)===r.length;return n||e._mergeStructures(r),n},t}function cr(t,e){fr=t,or=e}var ur=new Be({useRecords:!1}),gt=ur.pack,On=ur.pack;var{NEVER:vn,ALWAYS:An,DECIMAL_ROUND:Ln,DECIMAL_FIT:Pn}=Je,Bn=512,Rn=1024,Nn=2048;var bt=3,Ne=0,ze=2,Xe=1,St=16,hr=["num","object","string","ascii"];hr[St]="date";var Mn=[!1,!0,!0,!1,!1,!0,!0,!1],xr;try{new Function(""),xr=!0}catch{}var Oe,Dn=typeof Buffer<"u",Ze,oe;try{Ze=new TextEncoder}catch{}var Cn=Dn?function(t,e,r){return t.utf8Write(e,r,t.byteLength-r)}:Ze&&Ze.encodeInto?function(t,e,r){return Ze.encodeInto(e,t.subarray(r)).written}:!1;cr(yr,zn);function yr(t,e,r,n,i,s,f,u){let d=u.typedStructs||(u.typedStructs=[]),w=e.dataView,g=(d.lastStringStart||100)+n,T=e.length-10,E=n;n>T&&(e=s(n),w=e.dataView,n-=r,E-=r,g-=r,r=0,T=e.length-10);let U,k=g,_=d.transitions||(d.transitions=Object.create(null)),M=d.nextId||d.length,q=M<15?1:M<240?2:M<61440?3:M<15728640?4:0;if(q===0)return 0;n+=q;let D=[],se,C=0;for(let j in t){let S=t[j],x=_[j];switch(x||(_[j]=x={key:j,parent:_,enumerationOffset:0,ascii0:null,ascii8:null,num8:null,string16:null,object16:null,num32:null,float64:null,date64:null}),n>T&&(e=s(n),w=e.dataView,n-=r,E-=r,g-=r,k-=r,r=0,T=e.length-10),typeof S){case"number":let I=S;if(M<200||!x.num64){if(I>>0===I&&I<536870912&&I>-520093696){I<246&&I>=0&&(x.num8&&!(M>200&&x.num32)||I<32&&!x.num32)?(_=x.num8||Q(x,Ne,1),e[n++]=I):(_=x.num32||Q(x,Ne,4),w.setUint32(n,I,!0),n+=4);break}else if(I<4294967296&&I>=-2147483648&&(w.setFloat32(n,I,!0),Mn[e[n+3]>>>5])){let V;if((V=I*Ue[(e[n+3]&127)<<1|e[n+2]>>7])>>0===V){_=x.num32||Q(x,Ne,4),n+=4;break}}}_=x.num64||Q(x,Ne,8),w.setFloat64(n,I,!0),n+=8;break;case"string":let B=S.length;if(U=k-g,(B<<2)+k>T&&(e=s((B<<2)+k),w=e.dataView,n-=r,E-=r,g-=r,k-=r,r=0,T=e.length-10),B>65280+U>>2){D.push(j,S,n-E);break}let v,F=k;if(B<64){let V,o,b;for(V=0;V<B;V++)o=S.charCodeAt(V),o<128?e[k++]=o:o<2048?(v=!0,e[k++]=o>>6|192,e[k++]=o&63|128):(o&64512)===55296&&((b=S.charCodeAt(V+1))&64512)===56320?(v=!0,o=65536+((o&1023)<<10)+(b&1023),V++,e[k++]=o>>18|240,e[k++]=o>>12&63|128,e[k++]=o>>6&63|128,e[k++]=o&63|128):(v=!0,e[k++]=o>>12|224,e[k++]=o>>6&63|128,e[k++]=o&63|128)}else k+=Cn(e,S,k),v=k-F>B;if(U<160||U<246&&(x.ascii8||x.string8)){if(v)(_=x.string8)||(d.length>10&&(_=x.ascii8)?(_.__type=ze,x.ascii8=null,x.string8=_,f(null,0,!0)):_=Q(x,ze,1));else if(U===0&&!se){se=!0,_=x.ascii0||Q(x,bt,0);break}else!(_=x.ascii8)&&!(d.length>10&&(_=x.string8))&&(_=Q(x,bt,1));e[n++]=U}else _=x.string16||Q(x,ze,2),w.setUint16(n,U,!0),n+=2;break;case"object":if(S){S.constructor===Date?(_=x.date64||Q(x,St,8),w.setFloat64(n,S.getTime(),!0),n+=8):D.push(j,S,C);break}else x=dr(x,n,w,-10),x?(_=x,n=Oe):D.push(j,S,C);break;case"boolean":_=x.num8||x.ascii8||Q(x,Ne,1),e[n++]=S?249:248;break;case"undefined":x=dr(x,n,w,-9),x?(_=x,n=Oe):D.push(j,S,C);break;default:D.push(j,S,C)}C++}for(let j=0,S=D.length;j<S;){let x=D[j++],I=D[j++],B=D[j++],v=_[x];v||(_[x]=v={key:x,parent:_,enumerationOffset:B-C,ascii0:null,ascii8:null,num8:null,string16:null,object16:null,num32:null,float64:null});let F;if(I){let V;U=k-g,U<65280?(_=v.object16,_?V=2:(_=v.object32)?V=4:(_=Q(v,Xe,2),V=2)):(_=v.object32||Q(v,Xe,4),V=4),F=f(I,k),typeof F=="object"?(k=F.position,w=F.targetView,e=F.target,g-=r,n-=r,E-=r,r=0):k=F,V===2?(w.setUint16(n,U,!0),n+=2):(w.setUint32(n,U,!0),n+=4)}else _=v.object16||Q(v,Xe,2),w.setInt16(n,I===null?-10:-9,!0),n+=2;C++}let P=_[fe];if(P==null){P=u.typedStructs.length;let j=[],S=_,x,I;for(;(I=S.__type)!==void 0;){let B=S.__size;S=S.__parent,x=S.key;let v=[I,B,x];S.enumerationOffset&&v.push(S.enumerationOffset),j.push(v),S=S.parent}j.reverse(),_[fe]=P,u.typedStructs[P]=j,f(null,0,!0)}switch(q){case 1:if(P>=16)return 0;e[E]=P+32;break;case 2:if(P>=256)return 0;e[E]=56,e[E+1]=P;break;case 3:if(P>=65536)return 0;e[E]=57,w.setUint16(E+1,P,!0);break;case 4:if(P>=16777216)return 0;w.setUint32(E,(P<<8)+58,!0);break}if(n<g){if(g===k)return n;e.copyWithin(n,g,k),k+=n-g,d.lastStringStart=n-E}else if(n>g)return g===k?n:(d.lastStringStart=n-E,yr(t,e,r,E,i,s,f,u));return k}function dr(t,e,r,n){let i;if(i=t.ascii8||t.num8)return r.setInt8(e,n,!0),Oe=e+1,i;if(i=t.string16||t.object16)return r.setInt16(e,n,!0),Oe=e+2,i;if(i=t.num32)return r.setUint32(e,3758096640+n,!0),Oe=e+4,i;if(i=t.num64)return r.setFloat64(e,NaN,!0),r.setInt8(e,n),Oe=e+8,i;Oe=e}function Q(t,e,r){let n=hr[e]+(r<<3),i=t[n]||(t[n]=Object.create(null));return i.__type=e,i.__size=r,i.__parent=t,i}function Fn(t){if(!(t instanceof Map))return t;let e=t.get("typed")||[];Object.isFrozen(e)&&(e=e.map(i=>i.slice(0)));let r=t.get("named"),n=Object.create(null);for(let i=0,s=e.length;i<s;i++){let f=e[i],u=n;for(let[d,w,g]of f){let T=u[g];T||(u[g]=T={key:g,parent:u,enumerationOffset:0,ascii0:null,ascii8:null,num8:null,string16:null,object16:null,num32:null,float64:null,date64:null}),u=Q(T,d,w)}u[fe]=i}return e.transitions=n,this.typedStructs=e,this.lastTypedStructuresLength=e.length,r}var _t=Symbol.for("source");function Vn(t,e,r,n){let i=t[e++]-32;if(i>=24)switch(i){case 24:i=t[e++];break;case 25:i=t[e++]+(t[e++]<<8);break;case 26:i=t[e++]+(t[e++]<<8)+(t[e++]<<16);break;case 27:i=t[e++]+(t[e++]<<8)+(t[e++]<<16)+(t[e++]<<24);break}let s=n.typedStructs&&n.typedStructs[i];if(!s){if(t=Uint8Array.prototype.slice.call(t,e,r),r-=e,e=0,!n.getStructures)throw new Error(`Reference to shared structure ${i} without getStructures method`);if(n._mergeStructures(n.getStructures()),!n.typedStructs)throw new Error("Could not find any shared typed structures");if(n.lastTypedStructuresLength=n.typedStructs.length,s=n.typedStructs[i],!s)throw new Error("Could not find typed structure "+i)}var f=s.construct,u=s.fullConstruct;if(!f){f=s.construct=function(){},u=s.fullConstruct=function(){},u.prototype=n.structPrototype||{};var d=f.prototype=n.structPrototype?Object.create(n.structPrototype):{};let g=[],T=0,E;for(let U=0,k=s.length;U<k;U++){let _=s[U],[M,q,D,se]=_;D==="__proto__"&&(D="__proto_");let C={key:D,offset:T};se?g.splice(U+se,0,C):g.push(C);let P;switch(q){case 0:P=()=>0;break;case 1:P=(S,x)=>{let I=S.bytes[x+C.offset];return I>=246?Re(I):I};break;case 2:P=(S,x)=>{let I=S.bytes,v=(I.dataView||(I.dataView=new DataView(I.buffer,I.byteOffset,I.byteLength))).getUint16(x+C.offset,!0);return v>=65280?Re(v&255):v};break;case 4:P=(S,x)=>{let I=S.bytes,v=(I.dataView||(I.dataView=new DataView(I.buffer,I.byteOffset,I.byteLength))).getUint32(x+C.offset,!0);return v>=4294967040?Re(v&255):v};break}C.getRef=P,T+=q;let j;switch(M){case bt:E&&!E.next&&(E.next=C),E=C,C.multiGetCount=0,j=function(S){let x=S.bytes,I=S.position,B=T+I,v=P(S,I);if(typeof v!="number")return v;let F,V=C.next;for(;V&&(F=V.getRef(S,I),typeof F!="number");)F=null,V=V.next;return F==null&&(F=S.bytesEnd-B),S.srcString?S.srcString.slice(v,F):Xt(x,v+B,F-v)};break;case ze:case Xe:E&&!E.next&&(E.next=C),E=C,j=function(S){let x=S.position,I=T+x,B=P(S,x);if(typeof B!="number")return B;let v=S.bytes,F,V=C.next;for(;V&&(F=V.getRef(S,x),typeof F!="number");)F=null,V=V.next;if(F==null&&(F=S.bytesEnd-I),M===ze)return v.toString("utf8",B+I,F+I);oe=S;try{return n.unpack(v,{start:B+I,end:F+I})}finally{oe=null}};break;case Ne:switch(q){case 4:j=function(S){let x=S.bytes,I=x.dataView||(x.dataView=new DataView(x.buffer,x.byteOffset,x.byteLength)),B=S.position+C.offset,v=I.getInt32(B,!0);if(v<536870912){if(v>-520093696)return v;if(v>-536870912)return Re(v&255)}let F=I.getFloat32(B,!0),V=Ue[(x[B+3]&127)<<1|x[B+2]>>7];return(V*F+(F>0?.5:-.5)>>0)/V};break;case 8:j=function(S){let x=S.bytes,B=(x.dataView||(x.dataView=new DataView(x.buffer,x.byteOffset,x.byteLength))).getFloat64(S.position+C.offset,!0);if(isNaN(B)){let v=x[S.position+C.offset];if(v>=246)return Re(v)}return B};break;case 1:j=function(S){let I=S.bytes[S.position+C.offset];return I<246?I:Re(I)};break}break;case St:j=function(S){let x=S.bytes,I=x.dataView||(x.dataView=new DataView(x.buffer,x.byteOffset,x.byteLength));return new Date(I.getFloat64(S.position+C.offset,!0))};break}C.get=j}if(xr){let U=[],k=[],_=0,M;for(let D of g){if(n.alwaysLazyProperty&&n.alwaysLazyProperty(D.key)){M=!0;continue}Object.defineProperty(d,D.key,{get:jn(D.get),enumerable:!0});let se="v"+_++;k.push(se),U.push("o["+JSON.stringify(D.key)+"]="+se+"(s)")}M&&U.push("__proto__:this");let q=new Function(...k,"var c=this;return function(s){var o=new c();"+U.join(";")+";return o;}").apply(u,g.map(D=>D.get));Object.defineProperty(d,"toJSON",{value(D){return q.call(this,this[_t])}})}else Object.defineProperty(d,"toJSON",{value(U){let k={};for(let _=0,M=g.length;_<M;_++){let q=g[_].key;k[q]=this[q]}return k}})}var w=new f;return w[_t]={bytes:t,position:e,srcString:"",bytesEnd:r},w}function Re(t){switch(t){case 246:return null;case 247:return;case 248:return!1;case 249:return!0}throw new Error("Unknown constant")}function jn(t){return function(){return t(this[_t])}}function Kn(){oe&&(oe.bytes=Uint8Array.prototype.slice.call(oe.bytes,oe.position,oe.bytesEnd),oe.position=0,oe.bytesEnd=oe.bytes.length)}function zn(t,e){if(e.typedStructs){let n=new Map;n.set("named",t),n.set("typed",e.typedStructs),t=n}let r=e.lastTypedStructuresLength||0;return t.isCompatible=n=>{let i=!0;return n instanceof Map?((n.get("named")||[]).length!==(e.lastNamedStructuresLength||0)&&(i=!1),(n.get("typed")||[]).length!==r&&(i=!1)):(n instanceof Array||Array.isArray(n))&&n.length!==(e.lastNamedStructuresLength||0)&&(i=!1),i||e._mergeStructures(n),i},e.lastTypedStructuresLength=e.typedStructs&&e.typedStructs.length,t}rr(Vn,Fn,Kn);import{createRequire as mi}from"module";var wi=process.env.MSGPACKR_NATIVE_ACCELERATION_DISABLED!==void 0&&process.env.MSGPACKR_NATIVE_ACCELERATION_DISABLED.toLowerCase()==="true";if(!wi){let t;try{typeof ee=="function"?t=sn():t=mi(import.meta.url)("msgpackr-extract"),t&&Yt(t.extractStrings)}catch{}}function an(t){let e=gt(t),r=4+e.length,n=Buffer.allocUnsafe(r);return n.writeInt32LE(r,0),e.copy(n,4),n}function Ae(t){return yt(t)}function ln(){let t=Date.now().toString(36).padStart(9,"0"),e=Math.random().toString(36).slice(2,5).padStart(3,"0");return t+e}var ne={NUMBER:0,UUID:1,STRING:2},me={LEXICAL:0,NUMERIC:1};import{writeFile as fn,readFile as on,open as Ce,rename as gi}from"fs/promises";import{createWriteStream as bi}from"fs";import{resolve as _i}from"path";var we=4096,it=class{_dbDir;_dbName;_indexes;_indexTypes;_primaryKeyType;_persistIntervalId=null;_indexPaths={};_deltaIndexes={};_tombstones={};_persistThreshold=1e3;_totalDeltaCount=0;constructor(e,r,n,i,s){this._dbDir=e,this._dbName=r,this._indexes=n,this._indexTypes=i,this._primaryKeyType=s}async init(e){for(let r of this._indexes){this._deltaIndexes[r]=[],this._tombstones[r]=new Map;let n=_i(this._dbDir,`${this._dbName}.${r}.txt`);this._indexPaths[r]=n;try{let i=await Ce(n,"r"),s=await i.stat();await i.close(),s.size===0&&await this._rebuildIndex(e,r)}catch(i){if(i.code==="ENOENT")await this._rebuildIndex(e,r);else throw i}}}async _rebuildIndex(e,r){let n=`${this._indexPaths[r]}.${Date.now()}.tmp`,i=bi(n,{flags:"w",encoding:"utf-8"}),s=this._getDocsAndLocationsFromDataFile(e),f=[];for await(let{doc:u,loc:d}of s)if(u&&u[r]!==void 0){let w=u[r];f.push({key:w,loc:d})}f.sort((u,d)=>this._compareKeys(u.key,d.key));for(let u of f)i.write(`${u.key},${u.loc[0]},${u.loc[1]}
  6. `);await new Promise(u=>i.end(u)),await gi(n,this._indexPaths[r])}async*_getDocsAndLocationsFromDataFile(e){let r;try{r=await Ce(e,"r");let n=await r.stat(),i=0;for(;i<n.size;){let s=Buffer.alloc(4);await r.read(s,0,4,i);let f=s.readInt32LE(0);if(f<=0||i+f>n.size)break;let u=Buffer.alloc(f);await r.read(u,0,f,i),yield{doc:Ae(u),loc:[i,f]},i+=f}}catch(n){if(n.code!=="ENOENT")throw n}finally{await r?.close()}}_compareKeys(e,r){return e&&typeof e.equals=="function"?r&&typeof r.equals=="function"?e.equals(r)?0:e.toHexString()<r.toHexString()?-1:1:e.toHexString().localeCompare(String(r)):r&&typeof r.equals=="function"?String(e).localeCompare(r.toHexString()):typeof e=="number"&&typeof r=="number"?e-r:String(e).localeCompare(String(r))}startAutoPersist(e,r){this._persistThreshold=r,e>0&&(this._persistIntervalId=setInterval(async()=>{this._totalDeltaCount>0&&await this.persist()},e),this._persistIntervalId.unref())}async close(){this._persistIntervalId&&(clearInterval(this._persistIntervalId),this._persistIntervalId=null),await this.persist()}async persist(){for(let e of this._indexes){let r=[],n=this._indexPaths[e];try{r=(await on(n,"utf-8")).trim().split(`
  7. `).filter(Boolean).map(w=>{let[g,T,E]=w.split(",");return{key:this._parseKey(g,e),loc:[parseInt(T),parseInt(E)]}})}catch(d){if(d.code!=="ENOENT")throw d}let i=this._tombstones[e],s=r.filter(d=>!i.has(d.loc[0])),f=this._deltaIndexes[e]||[],u=[...s,...f];if(u.sort((d,w)=>this._compareKeys(d.key,w.key)),u.length>0){let d=u.map(w=>`${w.key},${w.loc[0]},${w.loc[1]}`).join(`
  8. `)+`
  9. `;await fn(n,d,"utf-8")}else await fn(n,"","utf-8");this._deltaIndexes[e]=[],this._tombstones[e].clear()}this._totalDeltaCount=0}_parseKey(e,r){let n=this._indexTypes[r];if(n===me.NUMERIC){let i=parseInt(e,10);if(!isNaN(i))return i}else if(n===me.LEXICAL)return e;if(this._primaryKeyType===ne.NUMBER){let i=parseInt(e,10);if(!isNaN(i))return i}return this._primaryKeyType===ne.OBJECT_ID&&ObjectId.isValid(e)?new ObjectId(e):e}async _binarySearchOnDisk(e,r){try{let n=await Ce(this._indexPaths[e],"r"),i=await n.stat(),s=Math.ceil(i.size/we),f=0,u=s-1,d=Buffer.alloc(1024);for(;f<=u;){let g=Math.floor((f+u)/2),T=g*we,{bytesRead:E}=await n.read(d,0,1024,T);if(E===0)break;let k=d.subarray(0,E).toString("utf-8").split(`
  10. `),_=this._parseKey(k[0].split(",")[0],e),M=this._parseKey(k[k.length-2]?.split(",")[0]||_,e);this._compareKeys(M,r)<0?f=g+1:u=g-1}return await n.close(),Math.max(0,f-1)*we}catch(n){if(n.code==="ENOENT")return-1;throw n}}async findLastEntry(e,r){let n=this._parseKey(r,e),i=this._deltaIndexes[e]||[];for(let u=i.length-1;u>=0;u--){let d=i[u];if(this._compareKeys(d.key,n)===0)return d}let s=await this._findLastEntryOnDisk(e,n);return s?this._tombstones[e].has(s.loc[0])?null:s:null}async _findLastEntryOnDisk(e,r){let n=await this._binarySearchOnDisk(e,r);if(n===-1)return null;let i=null,s=await Ce(this._indexPaths[e],"r"),f=Buffer.alloc(we),u=n;try{let d=await s.stat();for(;u<d.size;){let{bytesRead:w}=await s.read(f,0,we,u);if(w===0)break;let T=f.slice(0,w).toString("utf-8").split(`
  11. `),E=!1;for(let U of T){if(!U)continue;let[k,_,M]=U.split(","),q=this._parseKey(k,e);this._compareKeys(q,r)===0&&(E=!0,i={key:q,loc:[parseInt(_),parseInt(M)]})}if(E)break;u+=we}}finally{await s.close()}return i}insert(e,r){for(let n of this._indexes)e[n]!==void 0&&(this._deltaIndexes[n].push({key:e[n],loc:r}),this._totalDeltaCount++);this._totalDeltaCount>=this._persistThreshold&&this.persist().catch(n=>console.error("Index persist error:",n))}async remove(e,r){let n=e[r],i=this._deltaIndexes[r]||[],s=i.findIndex(f=>this._compareKeys(f.key,n)===0);if(s!==-1){let f=i[s].loc[0];for(let u of this._indexes)this._deltaIndexes[u]=(this._deltaIndexes[u]||[]).filter(d=>d.loc[0]!==f)}else{let f=await this._findLastEntryOnDisk(r,n);if(f)for(let u of this._indexes)e[u]!==void 0&&this._tombstones[u].set(f.loc[0],!0)}}async getAllLocations(){let e=this._indexes[0],r=this._indexPaths[e],n=[];try{n=(await on(r,"utf-8")).trim().split(`
  12. `).filter(Boolean).map(w=>{let[,g,T]=w.split(",");return{loc:[parseInt(g),parseInt(T)]}})}catch(d){if(d.code!=="ENOENT")throw d}let i=this._tombstones[e]||new Map,s=n.filter(d=>!i.has(d.loc[0])),f=this._deltaIndexes[e]||[],u=new Map;for(let d of s)u.set(`${d.loc[0]}:${d.loc[1]}`,d.loc);for(let d of f)u.set(`${d.loc[0]}:${d.loc[1]}`,d.loc);return Array.from(u.values())}async get(e,r){let n=this._parseKey(r,e),i=await this._getOnDisk(e,n),s=(this._deltaIndexes[e]||[]).filter(d=>this._compareKeys(d.key,n)===0),f=this._tombstones[e]||new Map,u=new Map;for(let d of i)f.has(d.loc[0])||u.set(`${d.loc[0]}:${d.loc[1]}`,d);for(let d of s)u.set(`${d.loc[0]}:${d.loc[1]}`,d);return Array.from(u.values())}async _getOnDisk(e,r){let n=await this._binarySearchOnDisk(e,r);if(n===-1)return[];let i=[],s=await Ce(this._indexPaths[e],"r"),f=Buffer.alloc(we),u=n;try{let d=await s.stat();for(;u<d.size;){let{bytesRead:w}=await s.read(f,0,we,u);if(w===0)break;let T=f.subarray(0,w).toString("utf-8").split(`
  13. `),E,U=!1;for(let k of T){if(!k)continue;let[_,M,q]=k.split(",");E===void 0&&(E=this._parseKey(_,e));let D=this._parseKey(_,e);this._compareKeys(D,r)===0&&(U=!0,i.push({key:D,loc:[parseInt(M),parseInt(q)]}))}if(i.length>0&&!U||U===!1&&E&&this._compareKeys(E,r)>0)break;u+=we}}finally{await s.close()}return i}async*_getDocsByLocation(e,r){let n=await Ce(e,"r");try{for(let i of r)if(i&&i.length===2&&i[1]>0){let[s,f]=i,u=Buffer.alloc(f);await n.read(u,0,f,s),yield Ae(u)}}finally{await n.close()}}};var Pt=class{_dbFile=null;_primaryKeyType=null;_primaryKey=null;_classToUse=null;_indexes=[];_indexTypes={};_initPromise=null;_initState=0;_dataPath=null;_dataStream=null;_lockPath=null;_indexManager=null;_meta={nextId:0,deleted:[]};_debug=!1;_indexPersistInterval=6e4;_indexPersistThreshold=1e3;_processExitHandler=null;constructor(e,{primaryKey:r,primaryKeyType:n,indexes:i,debug:s,indexPersistInterval:f,indexPersistThreshold:u}={}){this._dbFile=e||this._dbFile,this._debug=s||this._debug,f!==void 0&&(this._indexPersistInterval=f),u!==void 0&&(this._indexPersistThreshold=u),r&&(r.startsWith("*")?(this._primaryKey=r.slice(1),this._primaryKeyType=ne.NUMBER):r.startsWith("@")?(this._primaryKey=r.slice(1),this._primaryKeyType=ne.UUID):(this._primaryKey=r,this._primaryKeyType=ne.STRING),n!==void 0&&(this._primaryKeyType=n));let d=[...new Set([...this._primaryKey?[this._primaryKey]:[],...i||[],...this._indexes||[]])];this._indexes=[];for(let w of d){let g=w;w.startsWith("*")?(g=w.slice(1),this._indexTypes[g]=me.NUMERIC):w.startsWith("@")?(g=w.slice(1),this._indexTypes[g]=me.LEXICAL):w===this._primaryKey&&this._primaryKeyType===ne.NUMBER?this._indexTypes[w]=me.NUMERIC:this._indexTypes[w]=me.LEXICAL,this._indexes.push(g)}}async init(){return this._initState===2?this:this._initState===1?this._initPromise:(this._initState=1,this._initPromise=new Promise(async e=>{if(!this._dbFile)throw new Error("No database file specified.");let r=cn(this._dbFile),n=un(this._dbFile,dn(this._dbFile));await Ii(r,{recursive:!0}),this._dataPath=hn(r,`${n}.mpack`),this._lockPath=hn(r,`${n}.lock`);try{this._meta=JSON.parse(await ki(`${this._dbFile}.meta.json`))}catch{this._meta={nextId:0,deleted:[]}}if(this._initState=2,await this.compact(),this._dataStream=xn(this._dataPath,{flags:"a"}),this._indexes.length>0){let i=cn(this._dbFile),s=un(this._dbFile,dn(this._dbFile));this._indexManager=new it(i,s,this._indexes,this._indexTypes,this._primaryKeyType),await this._indexManager.init(this._dataPath),this._indexManager.startAutoPersist(this._indexPersistInterval,this._indexPersistThreshold),this._processExitHandler=async()=>{await this.close(),process.exit(0)},process.once("SIGINT",this._processExitHandler),process.once("SIGTERM",this._processExitHandler)}this._initPromise=null,e(this)}))}async insert(e,{skipPrimaryKey:r=!1}={}){await this.init(),await this._acquireLock("insert",e);try{let n={...e};this._primaryKey&&!r&&!n[this._primaryKey]&&(this._primaryKeyType===ne.NUMBER?n[this._primaryKey]=this._meta.nextId++:this._primaryKeyType===ne.UUID&&(n[this._primaryKey]=ln()));let i=an(n),f=(await yn(this._dataPath).catch(()=>({size:0}))).size;await new Promise(d=>this._dataStream.write(i,d));let u=[f,i.length];return this._indexManager&&this._indexManager.insert(n,u),this._primaryKey&&this._primaryKeyType===ne.NUMBER&&!r&&!e[this._primaryKey]&&await this.persistMeta(),this._primaryKey?n[this._primaryKey]:n}finally{await this._releaseLock()}}async update(e,r,{upsert:n=!1}={}){let i=await this.delete(e,async s=>this.insert(typeof r=="function"?await r(s):r,{skipPrimaryKey:!0}));return console.log("insertedRecords",i),n&&i.length===0&&(i=await this.insert(typeof r=="function"?await r({}):r)),i}async upsert(e,r){return this.update(e,r,{upsert:!0})}async delete(e,r=async n=>n){await this.init(),await this._acquireLock("delete",e);try{let n=[];for await(let[i,s]of this.find(e,{mode:"mixed"}))this._meta.deleted.push(s),this._indexManager&&await this._indexManager.remove(i,this._primaryKey),n.push(r(i));return await this.persistMeta(),Promise.all(n)}finally{await this._releaseLock()}}find(e,r={}){if(typeof e>"u"||e===null||typeof e=="function")return new Le(this,e,r);if(!this._primaryKey)throw new Error("No primary key specified.");return new Le(this,n=>n[this._primaryKey]===e,r)}async*recordGenerator(e=null,{mode:r="record"}={}){await this.init();try{await yn(this._dataPath)}catch{return}let n=new Set(this._meta.deleted),i=Si(this._dataPath),s=[],f=0,u=0;for await(let d of i)for(s.push(d),f+=d.length;!(f<4);){let w;s[0].length>=4?w=s[0]:w=Buffer.concat(s,4);let g=w.readInt32LE(0);if(g<=4)throw new Error(`Invalid record size read from stream: ${g}`);if(f<g)break;if(n.has(u)){[u,f]=mn(g,u,f,s);continue}switch(r){case"raw":yield Buffer.concat(s,g).subarray(0,g);break;case"mixed":case"record":let T=Buffer.concat(s,g).subarray(0,g),E=Ae(T.subarray(4)),U=this._classToUse?Object.assign(new this._classToUse,E):E;e?e(U)&&(yield r==="mixed"?[U,u,g]:U):yield r==="mixed"?[U,u,g]:U;break;case"offset":if(e){let k=Buffer.concat(s,g).subarray(0,g),_=Ae(k.subarray(4));e(_)&&(yield[u,g])}else yield[u,g];break;default:throw new Error(`Invalid mode: ${r}`)}[u,f]=mn(g,u,f,s)}}async persistMeta(){let e={...this._meta};this._primaryKeyType!==ne.NUMBER&&delete e.nextId,await pn(`${this._dbFile}.meta.json`,JSON.stringify(e))}async compact(){await this._acquireLock("compact");try{let e=xn(this._dataPath+".tmp",{flags:"w"});for await(let r of this.find(null,{mode:"raw"}))e.write(r);e.end(),await Ti(this._dataPath+".tmp",this._dataPath),this._meta.deleted=[],await this.persistMeta()}finally{await this._releaseLock()}}async _acquireLock(e,r,n=0){try{await pn(this._lockPath,String(process.pid),{flag:"wx"})}catch(i){if(i.code==="EEXIST")return this.debug(`Waiting for lock file ${e} retry #${n}`,r),await new Promise(s=>setTimeout(s,100)),this._acquireLock(e,r,n+1);throw i}}async _releaseLock(){await Ui(this._lockPath).catch(()=>{})}async _getDocByLocation([e,r]){if(!e||r===0)return null;let n=await Ei(this._dataPath,"r");try{let i=Buffer.alloc(r);return await n.read(i,0,r,e),Ae(i)}finally{await n.close()}}async close(){this._indexManager&&await this._indexManager.close(),this._dataStream&&await new Promise((e,r)=>{this._dataStream.end(n=>n?r(n):e())}),this._processExitHandler&&(process.off("SIGINT",this._processExitHandler),process.off("SIGTERM",this._processExitHandler),this._processExitHandler=null)}debug(...e){this._debug&&console.log(...e)}};function mn(t,e,r,n){e+=t,r-=t;let i=t;for(;i>0&&n.length>0;){let s=n[0];i>=s.length?(i-=s.length,n.shift()):(n[0]=s.subarray(i),i=0)}return[e,r]}var wn=Pt;function Bt(t){return t&&t!==null&&typeof t=="object"&&!Array.isArray(t)}function Oi(t,...e){let r=new WeakSet,n=(i,s)=>{if(!(!Bt(i)||!Bt(s))&&!r.has(s)){r.add(s);for(let f in s)if(Bt(s[f])&&i[f])n(i[f],s[f]);else try{i[f]=s[f]}catch{}}};for(let i of e)n(t,i);return t}var Rt=class{constructor(e={},r=!0){r?Oi(this,e):Object.assign(this,e)}};export{Le as Cursor,me as IndexType,wn as MPackDB,Rt as Model,ne as PrimaryKeyType,wn as default};
  14. //# sourceMappingURL=mpackdb.min.js.map

Branches

Latest commits

  • b4db6391initial commitcaramboleyo