jsonjsdb
Version:
2 lines (1 loc) • 37.3 kB
JavaScript
var Jsonjsdb=function(t){"use strict";var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function i(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function n(t){if(Object.prototype.hasOwnProperty.call(t,"__esModule"))return t;var e=t.default;if("function"==typeof e){var i=function t(){var i=!1;try{i=this instanceof t}catch{}return i?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)};i.prototype=e.prototype}else i={};return Object.defineProperty(i,"__esModule",{value:!0}),Object.keys(t).forEach(function(e){var n=Object.getOwnPropertyDescriptor(t,e);Object.defineProperty(i,e,n.get?n:{enumerable:!0,get:function(){return t[e]}})}),i}var s={exports:{}};var r={exports:{}};const a=n(Object.freeze(Object.defineProperty({__proto__:null,default:{}},Symbol.toStringTag,{value:"Module"})));var o;function c(){return o||(o=1,r.exports=(t=t||function(t,i){var n;if("undefined"!=typeof window&&window.crypto&&(n=window.crypto),"undefined"!=typeof self&&self.crypto&&(n=self.crypto),"undefined"!=typeof globalThis&&globalThis.crypto&&(n=globalThis.crypto),!n&&"undefined"!=typeof window&&window.msCrypto&&(n=window.msCrypto),!n&&void 0!==e&&e.crypto&&(n=e.crypto),!n)try{n=a}catch(b){}var s=function(){if(n){if("function"==typeof n.getRandomValues)try{return n.getRandomValues(new Uint32Array(1))[0]}catch(b){}if("function"==typeof n.randomBytes)try{return n.randomBytes(4).readInt32LE()}catch(b){}}throw new Error("Native crypto module could not be used to get secure random number.")},r=Object.create||function(){function t(){}return function(e){var i;return t.prototype=e,i=new t,t.prototype=null,i}}(),o={},c=o.lib={},d=c.Base=function(){return{extend:function(t){var e=r(this);return t&&e.mixIn(t),e.hasOwnProperty("init")&&this.init!==e.init||(e.init=function(){e.$super.init.apply(this,arguments)}),e.init.prototype=e,e.$super=this,e},create:function(){var t=this.extend();return t.init.apply(t,arguments),t},init:function(){},mixIn:function(t){for(var e in t)t.hasOwnProperty(e)&&(this[e]=t[e]);t.hasOwnProperty("toString")&&(this.toString=t.toString)},clone:function(){return this.init.prototype.extend(this)}}}(),h=c.WordArray=d.extend({init:function(t,e){t=this.words=t||[],this.sigBytes=e!=i?e:4*t.length},toString:function(t){return(t||f).stringify(this)},concat:function(t){var e=this.words,i=t.words,n=this.sigBytes,s=t.sigBytes;if(this.clamp(),n%4)for(var r=0;r<s;r++){var a=i[r>>>2]>>>24-r%4*8&255;e[n+r>>>2]|=a<<24-(n+r)%4*8}else for(var o=0;o<s;o+=4)e[n+o>>>2]=i[o>>>2];return this.sigBytes+=s,this},clamp:function(){var e=this.words,i=this.sigBytes;e[i>>>2]&=4294967295<<32-i%4*8,e.length=t.ceil(i/4)},clone:function(){var t=d.clone.call(this);return t.words=this.words.slice(0),t},random:function(t){for(var e=[],i=0;i<t;i+=4)e.push(s());return new h.init(e,t)}}),l=o.enc={},f=l.Hex={stringify:function(t){for(var e=t.words,i=t.sigBytes,n=[],s=0;s<i;s++){var r=e[s>>>2]>>>24-s%4*8&255;n.push((r>>>4).toString(16)),n.push((15&r).toString(16))}return n.join("")},parse:function(t){for(var e=t.length,i=[],n=0;n<e;n+=2)i[n>>>3]|=parseInt(t.substr(n,2),16)<<24-n%8*4;return new h.init(i,e/2)}},u=l.Latin1={stringify:function(t){for(var e=t.words,i=t.sigBytes,n=[],s=0;s<i;s++){var r=e[s>>>2]>>>24-s%4*8&255;n.push(String.fromCharCode(r))}return n.join("")},parse:function(t){for(var e=t.length,i=[],n=0;n<e;n++)i[n>>>2]|=(255&t.charCodeAt(n))<<24-n%4*8;return new h.init(i,e)}},p=l.Utf8={stringify:function(t){try{return decodeURIComponent(escape(u.stringify(t)))}catch(e){throw new Error("Malformed UTF-8 data")}},parse:function(t){return u.parse(unescape(encodeURIComponent(t)))}},m=c.BufferedBlockAlgorithm=d.extend({reset:function(){this._data=new h.init,this._nDataBytes=0},_append:function(t){"string"==typeof t&&(t=p.parse(t)),this._data.concat(t),this._nDataBytes+=t.sigBytes},_process:function(e){var i,n=this._data,s=n.words,r=n.sigBytes,a=this.blockSize,o=r/(4*a),c=(o=e?t.ceil(o):t.max((0|o)-this._minBufferSize,0))*a,d=t.min(4*c,r);if(c){for(var l=0;l<c;l+=a)this._doProcessBlock(s,l);i=s.splice(0,c),n.sigBytes-=d}return new h.init(i,d)},clone:function(){var t=d.clone.call(this);return t._data=this._data.clone(),t},_minBufferSize:0});c.Hasher=m.extend({cfg:d.extend(),init:function(t){this.cfg=this.cfg.extend(t),this.reset()},reset:function(){m.reset.call(this),this._doReset()},update:function(t){return this._append(t),this._process(),this},finalize:function(t){return t&&this._append(t),this._doFinalize()},blockSize:16,_createHelper:function(t){return function(e,i){return new t.init(i).finalize(e)}},_createHmacHelper:function(t){return function(e,i){return new y.HMAC.init(t,i).finalize(e)}}});var y=o.algo={};return o}(Math),t)),r.exports;var t}var d,h={exports:{}};function l(){return d||(d=1,h.exports=(t=c(),function(){var e=t,i=e.lib.WordArray;function n(t,e,n){for(var s=[],r=0,a=0;a<e;a++)if(a%4){var o=n[t.charCodeAt(a-1)]<<a%4*2|n[t.charCodeAt(a)]>>>6-a%4*2;s[r>>>2]|=o<<24-r%4*8,r++}return i.create(s,r)}e.enc.Base64={stringify:function(t){var e=t.words,i=t.sigBytes,n=this._map;t.clamp();for(var s=[],r=0;r<i;r+=3)for(var a=(e[r>>>2]>>>24-r%4*8&255)<<16|(e[r+1>>>2]>>>24-(r+1)%4*8&255)<<8|e[r+2>>>2]>>>24-(r+2)%4*8&255,o=0;o<4&&r+.75*o<i;o++)s.push(n.charAt(a>>>6*(3-o)&63));var c=n.charAt(64);if(c)for(;s.length%4;)s.push(c);return s.join("")},parse:function(t){var e=t.length,i=this._map,s=this._reverseMap;if(!s){s=this._reverseMap=[];for(var r=0;r<i.length;r++)s[i.charCodeAt(r)]=r}var a=i.charAt(64);if(a){var o=t.indexOf(a);-1!==o&&(e=o)}return n(t,e,s)},_map:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="}}(),t.enc.Base64)),h.exports;var t}var f,u={exports:{}};function p(){return f||(f=1,u.exports=(t=c(),function(e){var i=t,n=i.lib,s=n.WordArray,r=n.Hasher,a=i.algo,o=[];!function(){for(var t=0;t<64;t++)o[t]=4294967296*e.abs(e.sin(t+1))|0}();var c=a.MD5=r.extend({_doReset:function(){this._hash=new s.init([1732584193,4023233417,2562383102,271733878])},_doProcessBlock:function(t,e){for(var i=0;i<16;i++){var n=e+i,s=t[n];t[n]=16711935&(s<<8|s>>>24)|4278255360&(s<<24|s>>>8)}var r=this._hash.words,a=t[e+0],c=t[e+1],u=t[e+2],p=t[e+3],m=t[e+4],y=t[e+5],b=t[e+6],g=t[e+7],v=t[e+8],x=t[e+9],_=t[e+10],S=t[e+11],w=t[e+12],I=t[e+13],C=t[e+14],k=t[e+15],M=r[0],A=r[1],B=r[2],j=r[3];M=d(M,A,B,j,a,7,o[0]),j=d(j,M,A,B,c,12,o[1]),B=d(B,j,M,A,u,17,o[2]),A=d(A,B,j,M,p,22,o[3]),M=d(M,A,B,j,m,7,o[4]),j=d(j,M,A,B,y,12,o[5]),B=d(B,j,M,A,b,17,o[6]),A=d(A,B,j,M,g,22,o[7]),M=d(M,A,B,j,v,7,o[8]),j=d(j,M,A,B,x,12,o[9]),B=d(B,j,M,A,_,17,o[10]),A=d(A,B,j,M,S,22,o[11]),M=d(M,A,B,j,w,7,o[12]),j=d(j,M,A,B,I,12,o[13]),B=d(B,j,M,A,C,17,o[14]),M=h(M,A=d(A,B,j,M,k,22,o[15]),B,j,c,5,o[16]),j=h(j,M,A,B,b,9,o[17]),B=h(B,j,M,A,S,14,o[18]),A=h(A,B,j,M,a,20,o[19]),M=h(M,A,B,j,y,5,o[20]),j=h(j,M,A,B,_,9,o[21]),B=h(B,j,M,A,k,14,o[22]),A=h(A,B,j,M,m,20,o[23]),M=h(M,A,B,j,x,5,o[24]),j=h(j,M,A,B,C,9,o[25]),B=h(B,j,M,A,p,14,o[26]),A=h(A,B,j,M,v,20,o[27]),M=h(M,A,B,j,I,5,o[28]),j=h(j,M,A,B,u,9,o[29]),B=h(B,j,M,A,g,14,o[30]),M=l(M,A=h(A,B,j,M,w,20,o[31]),B,j,y,4,o[32]),j=l(j,M,A,B,v,11,o[33]),B=l(B,j,M,A,S,16,o[34]),A=l(A,B,j,M,C,23,o[35]),M=l(M,A,B,j,c,4,o[36]),j=l(j,M,A,B,m,11,o[37]),B=l(B,j,M,A,g,16,o[38]),A=l(A,B,j,M,_,23,o[39]),M=l(M,A,B,j,I,4,o[40]),j=l(j,M,A,B,a,11,o[41]),B=l(B,j,M,A,p,16,o[42]),A=l(A,B,j,M,b,23,o[43]),M=l(M,A,B,j,x,4,o[44]),j=l(j,M,A,B,w,11,o[45]),B=l(B,j,M,A,k,16,o[46]),M=f(M,A=l(A,B,j,M,u,23,o[47]),B,j,a,6,o[48]),j=f(j,M,A,B,g,10,o[49]),B=f(B,j,M,A,C,15,o[50]),A=f(A,B,j,M,y,21,o[51]),M=f(M,A,B,j,w,6,o[52]),j=f(j,M,A,B,p,10,o[53]),B=f(B,j,M,A,_,15,o[54]),A=f(A,B,j,M,c,21,o[55]),M=f(M,A,B,j,v,6,o[56]),j=f(j,M,A,B,k,10,o[57]),B=f(B,j,M,A,b,15,o[58]),A=f(A,B,j,M,I,21,o[59]),M=f(M,A,B,j,m,6,o[60]),j=f(j,M,A,B,S,10,o[61]),B=f(B,j,M,A,u,15,o[62]),A=f(A,B,j,M,x,21,o[63]),r[0]=r[0]+M|0,r[1]=r[1]+A|0,r[2]=r[2]+B|0,r[3]=r[3]+j|0},_doFinalize:function(){var t=this._data,i=t.words,n=8*this._nDataBytes,s=8*t.sigBytes;i[s>>>5]|=128<<24-s%32;var r=e.floor(n/4294967296),a=n;i[15+(s+64>>>9<<4)]=16711935&(r<<8|r>>>24)|4278255360&(r<<24|r>>>8),i[14+(s+64>>>9<<4)]=16711935&(a<<8|a>>>24)|4278255360&(a<<24|a>>>8),t.sigBytes=4*(i.length+1),this._process();for(var o=this._hash,c=o.words,d=0;d<4;d++){var h=c[d];c[d]=16711935&(h<<8|h>>>24)|4278255360&(h<<24|h>>>8)}return o},clone:function(){var t=r.clone.call(this);return t._hash=this._hash.clone(),t}});function d(t,e,i,n,s,r,a){var o=t+(e&i|~e&n)+s+a;return(o<<r|o>>>32-r)+e}function h(t,e,i,n,s,r,a){var o=t+(e&n|i&~n)+s+a;return(o<<r|o>>>32-r)+e}function l(t,e,i,n,s,r,a){var o=t+(e^i^n)+s+a;return(o<<r|o>>>32-r)+e}function f(t,e,i,n,s,r,a){var o=t+(i^(e|~n))+s+a;return(o<<r|o>>>32-r)+e}i.MD5=r._createHelper(c),i.HmacMD5=r._createHmacHelper(c)}(Math),t.MD5)),u.exports;var t}var m,y={exports:{}},b={exports:{}};function g(){return m||(m=1,b.exports=(o=c(),e=(t=o).lib,i=e.WordArray,n=e.Hasher,s=t.algo,r=[],a=s.SHA1=n.extend({_doReset:function(){this._hash=new i.init([1732584193,4023233417,2562383102,271733878,3285377520])},_doProcessBlock:function(t,e){for(var i=this._hash.words,n=i[0],s=i[1],a=i[2],o=i[3],c=i[4],d=0;d<80;d++){if(d<16)r[d]=0|t[e+d];else{var h=r[d-3]^r[d-8]^r[d-14]^r[d-16];r[d]=h<<1|h>>>31}var l=(n<<5|n>>>27)+c+r[d];l+=d<20?1518500249+(s&a|~s&o):d<40?1859775393+(s^a^o):d<60?(s&a|s&o|a&o)-1894007588:(s^a^o)-899497514,c=o,o=a,a=s<<30|s>>>2,s=n,n=l}i[0]=i[0]+n|0,i[1]=i[1]+s|0,i[2]=i[2]+a|0,i[3]=i[3]+o|0,i[4]=i[4]+c|0},_doFinalize:function(){var t=this._data,e=t.words,i=8*this._nDataBytes,n=8*t.sigBytes;return e[n>>>5]|=128<<24-n%32,e[14+(n+64>>>9<<4)]=Math.floor(i/4294967296),e[15+(n+64>>>9<<4)]=i,t.sigBytes=4*e.length,this._process(),this._hash},clone:function(){var t=n.clone.call(this);return t._hash=this._hash.clone(),t}}),t.SHA1=n._createHelper(a),t.HmacSHA1=n._createHmacHelper(a),o.SHA1)),b.exports;var t,e,i,n,s,r,a,o}var v,x={exports:{}};var _;function S(){return _||(_=1,y.exports=function(t){return function(){var e=t,i=e.lib,n=i.Base,s=i.WordArray,r=e.algo,a=r.MD5,o=r.EvpKDF=n.extend({cfg:n.extend({keySize:4,hasher:a,iterations:1}),init:function(t){this.cfg=this.cfg.extend(t)},compute:function(t,e){for(var i,n=this.cfg,r=n.hasher.create(),a=s.create(),o=a.words,c=n.keySize,d=n.iterations;o.length<c;){i&&r.update(i),i=r.update(t).finalize(e),r.reset();for(var h=1;h<d;h++)i=r.finalize(i),r.reset();a.concat(i)}return a.sigBytes=4*c,a}});e.EvpKDF=function(t,e,i){return o.create(i).compute(t,e)}}(),t.EvpKDF}(c(),g(),v||(v=1,x.exports=(t=c(),i=(e=t).lib.Base,n=e.enc.Utf8,void(e.algo.HMAC=i.extend({init:function(t,e){t=this._hasher=new t.init,"string"==typeof e&&(e=n.parse(e));var i=t.blockSize,s=4*i;e.sigBytes>s&&(e=t.finalize(e)),e.clamp();for(var r=this._oKey=e.clone(),a=this._iKey=e.clone(),o=r.words,c=a.words,d=0;d<i;d++)o[d]^=1549556828,c[d]^=909522486;r.sigBytes=a.sigBytes=s,this.reset()},reset:function(){var t=this._hasher;t.reset(),t.update(this._iKey)},update:function(t){return this._hasher.update(t),this},finalize:function(t){var e=this._hasher,i=e.finalize(t);return e.reset(),e.finalize(this._oKey.clone().concat(i))}})))))),y.exports;var t,e,i,n}var w,I={exports:{}};var C,k;const M=i((C||(C=1,s.exports=function(t){return function(){var e=t,i=e.lib.BlockCipher,n=e.algo,s=[],r=[],a=[],o=[],c=[],d=[],h=[],l=[],f=[],u=[];!function(){for(var t=[],e=0;e<256;e++)t[e]=e<128?e<<1:e<<1^283;var i=0,n=0;for(e=0;e<256;e++){var p=n^n<<1^n<<2^n<<3^n<<4;p=p>>>8^255&p^99,s[i]=p,r[p]=i;var m=t[i],y=t[m],b=t[y],g=257*t[p]^16843008*p;a[i]=g<<24|g>>>8,o[i]=g<<16|g>>>16,c[i]=g<<8|g>>>24,d[i]=g,g=16843009*b^65537*y^257*m^16843008*i,h[p]=g<<24|g>>>8,l[p]=g<<16|g>>>16,f[p]=g<<8|g>>>24,u[p]=g,i?(i=m^t[t[t[b^m]]],n^=t[t[n]]):i=n=1}}();var p=[0,1,2,4,8,16,32,64,128,27,54],m=n.AES=i.extend({_doReset:function(){if(!this._nRounds||this._keyPriorReset!==this._key){for(var t=this._keyPriorReset=this._key,e=t.words,i=t.sigBytes/4,n=4*((this._nRounds=i+6)+1),r=this._keySchedule=[],a=0;a<n;a++)a<i?r[a]=e[a]:(d=r[a-1],a%i?i>6&&a%i==4&&(d=s[d>>>24]<<24|s[d>>>16&255]<<16|s[d>>>8&255]<<8|s[255&d]):(d=s[(d=d<<8|d>>>24)>>>24]<<24|s[d>>>16&255]<<16|s[d>>>8&255]<<8|s[255&d],d^=p[a/i|0]<<24),r[a]=r[a-i]^d);for(var o=this._invKeySchedule=[],c=0;c<n;c++){if(a=n-c,c%4)var d=r[a];else d=r[a-4];o[c]=c<4||a<=4?d:h[s[d>>>24]]^l[s[d>>>16&255]]^f[s[d>>>8&255]]^u[s[255&d]]}}},encryptBlock:function(t,e){this._doCryptBlock(t,e,this._keySchedule,a,o,c,d,s)},decryptBlock:function(t,e){var i=t[e+1];t[e+1]=t[e+3],t[e+3]=i,this._doCryptBlock(t,e,this._invKeySchedule,h,l,f,u,r),i=t[e+1],t[e+1]=t[e+3],t[e+3]=i},_doCryptBlock:function(t,e,i,n,s,r,a,o){for(var c=this._nRounds,d=t[e]^i[0],h=t[e+1]^i[1],l=t[e+2]^i[2],f=t[e+3]^i[3],u=4,p=1;p<c;p++){var m=n[d>>>24]^s[h>>>16&255]^r[l>>>8&255]^a[255&f]^i[u++],y=n[h>>>24]^s[l>>>16&255]^r[f>>>8&255]^a[255&d]^i[u++],b=n[l>>>24]^s[f>>>16&255]^r[d>>>8&255]^a[255&h]^i[u++],g=n[f>>>24]^s[d>>>16&255]^r[h>>>8&255]^a[255&l]^i[u++];d=m,h=y,l=b,f=g}m=(o[d>>>24]<<24|o[h>>>16&255]<<16|o[l>>>8&255]<<8|o[255&f])^i[u++],y=(o[h>>>24]<<24|o[l>>>16&255]<<16|o[f>>>8&255]<<8|o[255&d])^i[u++],b=(o[l>>>24]<<24|o[f>>>16&255]<<16|o[d>>>8&255]<<8|o[255&h])^i[u++],g=(o[f>>>24]<<24|o[d>>>16&255]<<16|o[h>>>8&255]<<8|o[255&l])^i[u++],t[e]=m,t[e+1]=y,t[e+2]=b,t[e+3]=g},keySize:8});e.AES=i._createHelper(m)}(),t.AES}(c(),l(),p(),S(),w||(w=1,I.exports=(k=c(),S(),void(k.lib.Cipher||function(t){var e=k,i=e.lib,n=i.Base,s=i.WordArray,r=i.BufferedBlockAlgorithm,a=e.enc;a.Utf8;var o=a.Base64,c=e.algo.EvpKDF,d=i.Cipher=r.extend({cfg:n.extend(),createEncryptor:function(t,e){return this.create(this._ENC_XFORM_MODE,t,e)},createDecryptor:function(t,e){return this.create(this._DEC_XFORM_MODE,t,e)},init:function(t,e,i){this.cfg=this.cfg.extend(i),this._xformMode=t,this._key=e,this.reset()},reset:function(){r.reset.call(this),this._doReset()},process:function(t){return this._append(t),this._process()},finalize:function(t){return t&&this._append(t),this._doFinalize()},keySize:4,ivSize:4,_ENC_XFORM_MODE:1,_DEC_XFORM_MODE:2,_createHelper:function(){function t(t){return"string"==typeof t?g:y}return function(e){return{encrypt:function(i,n,s){return t(n).encrypt(e,i,n,s)},decrypt:function(i,n,s){return t(n).decrypt(e,i,n,s)}}}}()});i.StreamCipher=d.extend({_doFinalize:function(){return this._process(!0)},blockSize:1});var h=e.mode={},l=i.BlockCipherMode=n.extend({createEncryptor:function(t,e){return this.Encryptor.create(t,e)},createDecryptor:function(t,e){return this.Decryptor.create(t,e)},init:function(t,e){this._cipher=t,this._iv=e}}),f=h.CBC=function(){var e=l.extend();function i(e,i,n){var s,r=this._iv;r?(s=r,this._iv=t):s=this._prevBlock;for(var a=0;a<n;a++)e[i+a]^=s[a]}return e.Encryptor=e.extend({processBlock:function(t,e){var n=this._cipher,s=n.blockSize;i.call(this,t,e,s),n.encryptBlock(t,e),this._prevBlock=t.slice(e,e+s)}}),e.Decryptor=e.extend({processBlock:function(t,e){var n=this._cipher,s=n.blockSize,r=t.slice(e,e+s);n.decryptBlock(t,e),i.call(this,t,e,s),this._prevBlock=r}}),e}(),u=(e.pad={}).Pkcs7={pad:function(t,e){for(var i=4*e,n=i-t.sigBytes%i,r=n<<24|n<<16|n<<8|n,a=[],o=0;o<n;o+=4)a.push(r);var c=s.create(a,n);t.concat(c)},unpad:function(t){var e=255&t.words[t.sigBytes-1>>>2];t.sigBytes-=e}};i.BlockCipher=d.extend({cfg:d.cfg.extend({mode:f,padding:u}),reset:function(){var t;d.reset.call(this);var e=this.cfg,i=e.iv,n=e.mode;this._xformMode==this._ENC_XFORM_MODE?t=n.createEncryptor:(t=n.createDecryptor,this._minBufferSize=1),this._mode&&this._mode.__creator==t?this._mode.init(this,i&&i.words):(this._mode=t.call(n,this,i&&i.words),this._mode.__creator=t)},_doProcessBlock:function(t,e){this._mode.processBlock(t,e)},_doFinalize:function(){var t,e=this.cfg.padding;return this._xformMode==this._ENC_XFORM_MODE?(e.pad(this._data,this.blockSize),t=this._process(!0)):(t=this._process(!0),e.unpad(t)),t},blockSize:4});var p=i.CipherParams=n.extend({init:function(t){this.mixIn(t)},toString:function(t){return(t||this.formatter).stringify(this)}}),m=(e.format={}).OpenSSL={stringify:function(t){var e=t.ciphertext,i=t.salt;return(i?s.create([1398893684,1701076831]).concat(i).concat(e):e).toString(o)},parse:function(t){var e,i=o.parse(t),n=i.words;return 1398893684==n[0]&&1701076831==n[1]&&(e=s.create(n.slice(2,4)),n.splice(0,4),i.sigBytes-=16),p.create({ciphertext:i,salt:e})}},y=i.SerializableCipher=n.extend({cfg:n.extend({format:m}),encrypt:function(t,e,i,n){n=this.cfg.extend(n);var s=t.createEncryptor(i,n),r=s.finalize(e),a=s.cfg;return p.create({ciphertext:r,key:i,iv:a.iv,algorithm:t,mode:a.mode,padding:a.padding,blockSize:t.blockSize,formatter:n.format})},decrypt:function(t,e,i,n){return n=this.cfg.extend(n),e=this._parse(e,n.format),t.createDecryptor(i,n).finalize(e.ciphertext)},_parse:function(t,e){return"string"==typeof t?e.parse(t,this):t}}),b=(e.kdf={}).OpenSSL={execute:function(t,e,i,n,r){if(n||(n=s.random(8)),r)a=c.create({keySize:e+i,hasher:r}).compute(t,n);else var a=c.create({keySize:e+i}).compute(t,n);var o=s.create(a.words.slice(e),4*i);return a.sigBytes=4*e,p.create({key:a,iv:o,salt:n})}},g=i.PasswordBasedCipher=y.extend({cfg:y.cfg.extend({kdf:b}),encrypt:function(t,e,i,n){var s=(n=this.cfg.extend(n)).kdf.execute(i,t.keySize,t.ivSize,n.salt,n.hasher);n.iv=s.iv;var r=y.encrypt.call(this,t,e,s.key,n);return r.mixIn(s),r},decrypt:function(t,e,i,n){n=this.cfg.extend(n),e=this._parse(e,n.format);var s=n.kdf.execute(i,t.keySize,t.ivSize,e.salt,n.hasher);return n.iv=s.iv,y.decrypt.call(this,t,e,s.key,n)}})}()))))),s.exports));var A,B={exports:{}};var j=(A||(A=1,B.exports=function(t){return t.enc.Utf8}(c())),B.exports);const z=i(j);class D{browserKey;crypto;constructor(t){this.browserKey=t,this.crypto=M}encrypt(t){return this.crypto.encrypt(t,this.browserKey).toString()}decrypt(t){return this.crypto.decrypt(t,this.browserKey).toString(z)}}class O{encryption;ldb;namespaced;useEncryption;constructor(e,i,n){this.encryption=new D(e),this.ldb=t,this.namespaced=t=>i+"/"+t,this.useEncryption=n&&Boolean(e)}tryParseJson(t){try{return JSON.parse(t)}catch{return t}}tryDecrypt(t){try{return this.encryption.decrypt(t)}catch{return t}}getAll(t,e){const i=this.namespaced(t),n={};this.ldb.getAll(t=>{const s=t;for(const e of s){if(!e.k.startsWith(i))continue;let t=e.v;this.useEncryption&&(t=this.tryParseJson(this.tryDecrypt(t)));const s=e.k.substring(i.length);s&&(n[s]=t)}e(n)})}get(t){return new Promise(e=>{this.ldb.get(this.namespaced(t),t=>{let i=t;this.useEncryption&&(i=this.tryParseJson(this.tryDecrypt(t))),e(i)})})}set(t,e,i){let n;n=this.useEncryption?this.encryption.encrypt(JSON.stringify(e)):e,this.ldb.set(this.namespaced(t),n,i)}clear(){this.ldb.clear()}}class T{tableIndex="__table__";cachePrefix="dbCache/";idSuffix="Id";browser;tableIndexCache;lastModifTimestamp;metaVariable={};validIdChars;validIdPattern;invalidIdPattern;db={};metadata={schema:{aliases:[],oneToOne:[],oneToMany:[],manyToMany:[]},index:{},tables:[],dbSchema:void 0};constructor(t,e){window.jsonjs={},this.browser=t,this.validIdChars=e.validIdChars??"a-zA-Z0-9_, -",this.validIdPattern=new RegExp(`^[${this.validIdChars}]+$`),this.invalidIdPattern=new RegExp(`[^${this.validIdChars}]`,"g")}async load(t,e=!1,i={}){return await this.loadTables(t,e),this.normalizeSchema(),i.filter?.values?.length&&i.filter.values.length>0&&this.filter(i.filter),this.createAlias(i.aliases),this.createIndex(),this.db}async loadFromCache(t){return this.browser.get(this.cachePrefix+t)}async saveToCache(t,e){this.browser.set(this.cachePrefix+e,t)}async loadFromFile(t,e,i){const n=document.createElement("script");let s=t+"/"+e+".json.js?v=";return s+=i&&i.version?i.version:Math.random(),n.src=s,n.async=!1,new Promise((r,a)=>{n.onload=()=>{if(!(e in window.jsonjs.data)||void 0===window.jsonjs.data[e]){const t=`jsonjs.data.${e} not found in table ${e}`;return console.error(t),void a(new Error(t))}let t=window.jsonjs.data[e];delete window.jsonjs.data[e],t=t.length>0&&Array.isArray(t[0])?this.arrayToObject(t,i?.shouldStandardizeIds):this.applyTransform(t,i?.shouldStandardizeIds),r(t),document.querySelectorAll(`script[src="${s}"]`)[0].remove(),i&&i.useCache&&this.saveToCache(t,e)},n.onerror=()=>{const i=`table "${e}" not found in path "${t}"`;delete window.jsonjs.data[e],console.error(i),a(new Error(i))},document.head.appendChild(n)})}isVariableId(t){return"id"===t||t.endsWith(this.idSuffix)||t.endsWith(this.idSuffix+"s")}standardizeId(t){const e=t.trim();if(this.validIdPattern.test(e))return e;const i=e.replace(this.invalidIdPattern,"");return i!==e&&console.warn(`ID standardized: "${t}" → "${i}"`),i}snakeToCamel(t){return t.replace(/_([a-z])/g,(t,e)=>e.toUpperCase())}arrayToObject(t,e=!0){if(0===t.length)return[];const i=t[0].map(t=>this.snakeToCamel(String(t))),n=i.length,s=t.length,r=new Array(s-1);for(let a=1;a<s;a+=1){const s=t[a],o={};for(let t=0;t<n;t+=1){const n=s[t];o[i[t]]="string"==typeof n&&e&&this.isVariableId(i[t])?this.standardizeId(n):n}r[a-1]=o}return r}applyTransform(t,e=!0){if(0===t.length)return t;const i=t[0],n=Object.keys(i),s=n.length,r=n.map(t=>this.snakeToCamel(t)),a=r.map(t=>e&&this.isVariableId(t)),o=t.length,c=new Array(o);for(let d=0;d<o;d+=1){const e=t[d],i={};for(let t=0;t<s;t+=1){const s=e[n[t]];i[r[t]]="string"==typeof s&&a[t]?this.standardizeId(s):s}c[d]=i}return c}isInCache(t,e){return!!this.tableIndexCache&&(t in this.tableIndexCache&&this.tableIndexCache[t]===e)}async loadJsonjs(t,e,i){return"/"===t.slice(-1)&&(t=t.slice(0,-1)),void 0===window.jsonjs&&(window.jsonjs={}),void 0===window.jsonjs.data&&(window.jsonjs.data={}),i?.useCache&&this.isInCache(e,i.version)?this.loadFromCache(e):this.loadFromFile(t,e,i)}async loadTables(t,e){let i=await this.loadJsonjs(t,this.tableIndex);if(i=this.checkConformity(i),i=this.extractLastModif(i),e){this.tableIndexCache=await this.browser.get(this.cachePrefix+this.tableIndex);const t=i.reduce((t,e)=>({...t,[e.name]:e.lastModif}),{});this.saveToCache(t,this.tableIndex)}this.metadata.schema={aliases:[],oneToOne:[],oneToMany:[],manyToMany:[]},this.metadata.index={},this.metadata.tables=i,this.db={};const n=[],s=[];for(const a of i)s.push({name:a.name}),n.push(this.loadJsonjs(t,a.name,{version:a.lastModif??Date.now(),useCache:e,shouldStandardizeIds:!0}));const r=await Promise.all(n);for(const[a,o]of r.entries())this.db[s[a].name]=o}getLastModifTimestamp(){return this.lastModifTimestamp||0}extractLastModif(t){const e=t.filter(t=>t.name===this.tableIndex);return e.length>0&&e[0].lastModif&&(this.lastModifTimestamp=e[0].lastModif),t.filter(t=>t.name!==this.tableIndex)}checkConformity(t){const e=[],i=[];for(const n of t)"name"in n?i.includes(n.name)?console.error("table name already exists in meta",n):(i.push(n.name),e.push(n)):console.error("table name not found in meta",n);return e}normalizeSchema(){for(const t of this.metadata.tables)if(0!==this.db[t.name].length)for(const e in this.db[t.name][0]){if(!e.endsWith(this.idSuffix+"s"))continue;const i=e.slice(0,-(this.idSuffix.length+1));if(!(i in this.db))continue;const n=t.name+"_"+i;n in this.db||(this.metadata.tables.push({name:n}),this.db[n]=[]);for(const s of this.db[t.name]){if(!s[e])continue;const r="string"==typeof s[e]?s[e].split(","):[];if(0!==r.length)for(const e of r)this.db[n].push({[t.name+this.idSuffix]:s.id,[i+this.idSuffix]:e.trim()})}}}filter(t){if(!("entity"in t)||!t.entity)return!1;if(!("variable"in t)||!t.variable)return!1;if(!("values"in t)||!t.values)return!1;if(!(t.entity in this.db))return!1;const e=[];for(const i of this.db[t.entity])t.values.includes(i[t.variable])&&i.id&&e.push(String(i.id));this.db[t.entity]=this.db[t.entity].filter(t=>!e.includes(t.id));for(const i of this.metadata.tables){if(0===this.db[i.name].length)continue;if(!(t.entity+this.idSuffix in this.db[i.name][0]))continue;const n=[];for(const s of this.db[i.name]){const i=s[t.entity+this.idSuffix];i&&e.includes(String(i))&&s.id&&n.push(String(s.id))}this.db[i.name]=this.db[i.name].filter(i=>!e.includes(i[t.entity+this.idSuffix]));for(const t of this.metadata.tables)0!==this.db[t.name].length&&i.name+this.idSuffix in this.db[t.name][0]&&(this.db[t.name]=this.db[t.name].filter(t=>!n.includes(t[i.name+this.idSuffix])))}}idToIndex(t,e){if(!this.metadata.index[t])return console.error("idToIndex() table not found: ",t),!1;if(void 0===this.metadata.index[t].id[e])return console.error("idToIndex() table ",t,"id not found",e),!1;const i=this.metadata.index[t].id[e];return"number"==typeof i&&i}createAlias(t=null){let e=[];if(t&&(e=t.map(({table:t,alias:e})=>({table:t,alias:e}))),"config"in this.db)for(const i of this.db.config)if("string"==typeof i.id&&i.id.startsWith("alias_")){const t=i.value;if("string"==typeof t){const i=t.split(":")[0]?.trim(),n=t.split(":")[1]?.trim();i&&n&&e.push({table:i,alias:n})}}"alias"in this.db&&(e=e.concat(this.db.alias));for(const i of e){const t=[];if(i.table in this.db){for(const e of this.db[i.table]){const n={id:e.id};n[i.table+this.idSuffix]=e.id,t.push(n)}this.db[i.alias]=t,this.metadata.tables.push({name:i.alias,alias:!0}),this.metadata.schema.aliases.push(i.alias)}else console.error("createAlias() table not found:",i.table)}}createIndex(){this.metadata.index={};for(const t of this.metadata.tables)t.name.includes("_")||(this.metadata.index[t.name]={});for(const t of this.metadata.tables)!t.name.includes("_")&&this.db[t.name][0]&&(this.addPrimaryKey(t),this.processOneToMany(t));for(const t of this.metadata.tables)t.name.includes("_")&&this.db[t.name][0]&&(this.processManyToMany(t,"left"),this.processManyToMany(t,"right"))}processManyToMany(t,e){const i={},n=t.name.split("_");if(!(n[0]in this.metadata.index))return console.error("processManyToMany() table not found",n[0]),!1;if(!(n[1]in this.metadata.index))return console.error("processManyToMany() table not found",n[1]),!1;"right"===e&&n.reverse();const s=n[0]+this.idSuffix,r=n[1]+this.idSuffix;for(const a of this.db[t.name]){const t=a[s],e=a[r];if(null==t||null==e)continue;const o=this.idToIndex(n[0],t);if(!1===o)continue;const c=String(e);c in i?(Array.isArray(i[c])||(i[c]=[i[c]]),i[c].push(o)):i[c]=o}delete i.null,this.metadata.index[n[0]][r]=i,"left"===e&&this.metadata.schema.manyToMany.push([n[0],r.slice(0,-this.idSuffix.length)])}processOneToMany(t){for(const e in this.db[t.name][0])e!=="parent"+this.idSuffix?e.endsWith(this.idSuffix)&&e.slice(0,-this.idSuffix.length)in this.metadata.index&&this.addForeignKey(e,t):this.processSelfOneToMany(t)}processSelfOneToMany(t){const e={};for(const[i,n]of Object.entries(this.db[t.name])){const t=n["parent"+this.idSuffix];t in e?(Array.isArray(e[t])||(e[t]=[e[t]]),e[t].push(parseInt(i))):e[t]=parseInt(i)}this.metadata.index[t.name]["parent"+this.idSuffix]=e,this.metadata.schema.oneToMany.push([t.name,t.name])}addPrimaryKey(t){const e={};if(!(t.name in this.db))return!1;if(0===this.db[t.name].length)return!1;if(!("id"in this.db[t.name][0]))return!1;for(const[i,n]of Object.entries(this.db[t.name])){e[n.id]=parseInt(i)}this.metadata.index[t.name].id=e}addForeignKey(t,e){const i={};for(const[n,s]of Object.entries(this.db[e.name])){const e=s[t];e in i?(Array.isArray(i[e])||(i[e]=[i[e]]),i[e].push(parseInt(n))):i[e]=parseInt(n)}delete i.null,this.metadata.index[e.name][t]=i,this.metadata.schema.aliases.includes(e.name)?this.metadata.schema.oneToOne.push([e.name,t.slice(0,-this.idSuffix.length)]):this.metadata.schema.oneToMany.push([t.slice(0,-this.idSuffix.length),e.name])}addDbSchema(t){Array.isArray(t)&&t.length>0&&Array.isArray(t[0])&&(t=this.arrayToObject(t)),this.metadata.dbSchema=t}addMeta(t,e){const i={},n={};this.metaVariable={},e&&this.addDbSchema(e);const s=[];for(const c of this.metadata.tables)c.lastModif||s.push(c.name);if(this.metadata.dbSchema)for(const c of this.metadata.dbSchema){const t=c;t.folder&&(t.dataset?t.variable?(t.id=t.dataset+"---"+t.variable,this.metaVariable[t.id]=t):(t.id=t.dataset,i[t.id]=t):(t.id=t.folder,n[t.id]=t))}const r={id:"data",name:"data",description:n.data?.description,isInMeta:!!n.data,isInData:!0},a={id:"userData",name:"userData",description:n.userData?.description,isInMeta:!!n.userData,isInData:!0};this.db.metaFolder=[r,a],this.db.metaDataset=[],this.db.metaVariable=[];const o=Object.entries(t||{});for(const[c,d]of o){const t=d;if(0===t.length)continue;const e=Object.keys(t[0]);this.db.metaDataset.push({id:c,["metaFolder"+this.idSuffix]:"userData",name:c,nbRow:t.length,description:i[c]?.description,isInMeta:!!i[c],isInData:!0}),this.addMetaVariables(c,d,e),c in i&&delete i[c]}for(const c of this.metadata.tables){if(c.name.includes(this.tableIndex))continue;if(0===this.db[c.name].length)continue;if(s.includes(c.name))continue;const t=Object.keys(this.db[c.name][0]);this.db.metaDataset.push({id:c.name,["metaFolder"+this.idSuffix]:"data",name:c.name,nbRow:this.db[c.name].length,description:i[c.name]?.description,lastUpdateTimestamp:c.lastModif,isInMeta:!!i[c.name],isInData:!0}),this.addMetaVariables(c.name,this.db[c.name],t),c.name in i&&delete i[c.name]}for(const[c,d]of Object.entries(this.metaVariable)){const t=d,e=t.dataset;this.db.metaVariable.push({id:c,["metaDataset"+this.idSuffix]:e,name:t.variable,description:t.description,storageKey:t.storageKey,isInMeta:!0,isInData:!1})}for(const[c,d]of Object.entries(i)){const t=d;this.db.metaDataset.push({id:c,["metaFolder"+this.idSuffix]:t.folder,name:t.dataset,nbRow:0,description:t?.description,isInMeta:!0,isInData:!1})}this.metadata.index.metaFolder={},this.metadata.index.metaDataset={},this.metadata.index.metaVariable={},this.addPrimaryKey({name:"metaFolder"}),this.addPrimaryKey({name:"metaDataset"}),this.addPrimaryKey({name:"metaVariable"}),this.processOneToMany({name:"metaDataset"}),this.processOneToMany({name:"metaVariable"})}addMetaVariables(t,e,i){const n=e,s=Math.min(300,Math.floor(n.length/5));for(const r of i){let i="other";for(const t of e){const e=t[r];if(null!=e){if("string"==typeof e){i="string";break}if("number"==typeof e&&!isNaN(e)){if(Number.isInteger(e)){i="integer";break}i="float";break}if("boolean"==typeof e){i="boolean";break}}}let n=0;const a=new Set;for(const t of e){const e=t[r];""!==e&&null!=e?a.add(e):n+=1}let o=!1;if(a.size<s&&a.size>0){o=[];for(const t of a)o.push({value:t})}const c=t+"---"+r;this.db.metaVariable.push({id:c,["metaDataset"+this.idSuffix]:t,name:r,description:this.metaVariable[c]?.description,storageKey:this.metaVariable[c]?.storageKey,type:i,nbMissing:n,nbDistinct:a.size,nbDuplicate:e.length-a.size-n,values:o,valuesPreview:!!o&&o.slice(0,10),isInMeta:!!this.metaVariable[c],isInData:!0}),c in this.metaVariable&&delete this.metaVariable[c]}}}class P{idSuffix="Id";tables=[];tablesIds={};result;constructor(){this.tables=[],this.tablesIds={},this.result={emptyId:[],duplicateId:{},parentIdNotFound:{},parentIdSame:{},foreignIdNotFound:{}}}check(t,e){this.tables=[],this.tablesIds={},this.result={emptyId:[],duplicateId:{},parentIdNotFound:{},parentIdSame:{},foreignIdNotFound:{}};for(const i of e){this.tables.push(i.name);const e=t[i.name];this.tablesIds[i.name]=e.map(t=>t.id)}for(const i of this.tables)this.checkEmptyId(i),this.checkDuplicateId(i),this.checkParentIdSame(t,i),this.checkParentIdNotFound(t,i),this.checkForeignId(t,i);return this.result}checkEmptyId(t){const e=this.tablesIds[t];if(e.length>0&&e.every(t=>void 0===t))return;e.some(t=>null===t||""===t||void 0===t)&&this.result.emptyId.push(t)}checkDuplicateId(t){const e=this.tablesIds[t],i=new Set(e);let n=e.filter(t=>{if(!i.has(t))return t;i.delete(t)});n=Array.from(new Set(n)).filter(t=>null!=t),n.length>0&&(this.result.duplicateId[t]=n)}checkParentIdSame(t,e){const i=t[e];if(0===i.length)return;if(!Object.keys(i[0]).includes("parent"+this.idSuffix))return;const n=[];for(const s of i)null!=s.id&&s.id===s["parent"+this.idSuffix]&&n.push(s.id);n.length>0&&(this.result.parentIdSame[e]=n)}checkParentIdNotFound(t,e){const i=t[e];if(0===i.length)return;if(!Object.keys(i[0]).includes("parent"+this.idSuffix))return;const n=[];for(const s of i)null!==s["parent"+this.idSuffix]&&""!==s["parent"+this.idSuffix]&&(this.tablesIds[e].includes(s["parent"+this.idSuffix])||n.push(s["parent"+this.idSuffix]));n.length>0&&(this.result.parentIdNotFound[e]=n)}checkForeignId(t,e){const i=t[e];if(0===i.length)return;const n=[];for(const r in i[0])r!=="parent"+this.idSuffix&&r.endsWith(this.idSuffix)&&this.tables.includes(r.slice(0,-this.idSuffix.length))&&n.push(r.slice(0,-this.idSuffix.length));const s={};for(const r of n){const t=r+this.idSuffix,e=[];for(const n of i)null!==n[t]&&""!==n[t]&&(this.tablesIds[r].includes(n[t])||e.push(n[t]));e.length>0&&(s[t]=e)}Object.keys(s).length>0&&(this.result.foreignIdNotFound[e]=s)}}return class{defaultConfig;config;browser;loader;integrityChecker;tables;metadata;idSuffix="Id";usageCache={};recursiveUsageCache={};constructor(t){this.defaultConfig={path:"db",dbKey:!1,browserKey:!1,appName:"jsonjsdb",useCache:!1,useEncryption:!1,validIdChars:"a-zA-Z0-9_, -"};let e={};if("string"==typeof t){e=this.getHtmlConfig(t)||{}}else t&&(e=t);this.setConfig(e),this.browser=new O(this.config.browserKey,this.config.appName,this.config.useEncryption),this.loader=new T(this.browser,this.config),this.integrityChecker=new P}getHtmlConfig(t="#jsonjsdb-config"){const e=document.querySelector(t);if(!e)return!1;const{dataset:i}=e,n={};return i.path&&(n.path=i.path),i.dbKey&&(n.dbKey="false"!==i.dbKey&&i.dbKey),i.browserKey&&(n.browserKey="false"!==i.browserKey&&i.browserKey),i.appName&&(n.appName=i.appName),i.useCache&&(n.useCache="true"===i.useCache),i.useEncryption&&(n.useEncryption="true"===i.useEncryption),i.validIdChars&&(n.validIdChars=i.validIdChars),n}setConfig(t){this.config={...this.defaultConfig,...t},window?.location.protocol.startsWith("http")&&(this.config.useCache=!1),this.config.dbKey&&(this.config.path+="/"+this.config.dbKey)}async init(t={}){return this.tables=await this.loader.load(this.config.path,this.config.useCache,t),this.metadata=this.loader.metadata,this.computeUsage(),this}async load(t,e,i=!0){t=this.config.path+"/"+t;return await this.loader.loadJsonjs(t,e,{useCache:!1,version:Date.now(),shouldStandardizeIds:i})}get(t,e){try{const i=this.tables[t];if(!Array.isArray(i))return;const n=this.metadata.index[t].id[e];if("number"!=typeof n)return;const s=i[n];return s||console.error(`table ${t}, id not found: ${e}`),s}catch{return void(this.tables[t]?this.metadata.index[t]?"id"in this.metadata.index[t]?console.error("error not handled"):console.error(`table ${t}, props "id" not found in index`):console.error(`table ${t} not found in index`):console.error(`table ${t} not found`))}}getAll(t,e,i={}){const n=this.tables[t];if(!Array.isArray(n))return[];if(!e)return i.limit?n.slice(0,i.limit):n;const s=Object.entries(e)[0],r=s[0];let a=s[1];if(void 0===a)return[];"object"==typeof a&&null!==a&&"id"in a&&(a=a.id);let o=r+this.idSuffix;r===t&&(o="parent"+this.idSuffix);const c=this.metadata.index[t][o];if(!c||!(a in c))return[];const d=c[a];if(!Array.isArray(d))return"number"==typeof d&&n[d]?[n[d]]:(console.error("getAll() table",t,"has an index undefined"),[]);const h=[];for(const l of d){if(i.limit&&h.length>=i.limit)break;n[l]?h.push(n[l]):console.error("getAll() table",t,"has an index undefined")}return h}getAllChilds(t,e){const i=this.tables[t];if(!Array.isArray(i))return[];let n=[];if(!e)return console.error("getAllChilds()",t,"id",e),n;const s=this.getAll(t,{[t]:e});n=n.concat(s);for(const r of s){const i=r;if(e===i.id){const i="infinite loop for id";return console.error("getAllChilds()",t,i,e),n}const s=this.getAllChilds(t,i.id);n=n.concat(s)}return n}foreach(t,e){const i=this.getAll(t);for(const n of i)e(n)}exists(t,e){return!!this.tables[t]&&(!!this.metadata.index[t]&&(!!this.metadata.index[t].id&&e in this.metadata.index[t].id))}getConfig(t){const e=this.tables.config;if(!Array.isArray(e))return;const i=this.metadata.index.config.id;if(!i)return;if(!(t in i))return;const n=i[t];if("number"!=typeof n)return;return e[n].value}countRelated(t,e,i){if(!(i in this.metadata.index))return 0;const n=this.metadata.index[i][t+this.idSuffix];if(!n)return 0;if(!(e in n))return 0;const s=n[e];return Array.isArray(s)?s.length:1}getParents(t,e){if(!e||null===e)return[];let i=this.get(t,e);if(!i)return[];const n=[];let s=0;for(;s<30;){s+=1;const e=i["parent"+this.idSuffix];if([0,"",null].includes(e))return n.reverse();const r=i;if(i=this.get(t,e),!i){const e=r;return console.error("getParents() type",t,"cannot find id",e["parent"+this.idSuffix]),[]}n.push(i)}return console.error("getParents()",t,e,"iterationMax reached"),[]}addMeta(t,e){this.loader.addMeta(t,e)}getLastModifTimestamp(){return this.loader.getLastModifTimestamp()}get use(){return this.usageCache}get useRecursive(){return this.recursiveUsageCache}computeUsage(){this.usageCache={},this.recursiveUsageCache={};for(const t in this.tables){const e=this.tables[t];if(!Array.isArray(e))continue;if(0===e.length)continue;if(t.includes("_"))continue;this.usageCache[t]=!0;const i=e[0];i&&"object"==typeof i&&"parent"+this.idSuffix in i&&(this.recursiveUsageCache[t]=!0)}}getSchema(){return structuredClone(this.metadata.schema)}async checkIntegrity(){return await this.loader.loadTables(this.config.path,!1),this.integrityChecker.check(this.loader.db,this.loader.metadata.tables)}}}(localdata);