s3db.js 5.1.0 → 6.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,31 +1,31 @@
1
1
  /* istanbul ignore file */
2
- import{customAlphabet as Zi,urlAlphabet as Zc}from"nanoid";import{chunk as qi,merge as kt,isString as Nr,isEmpty as Hi,invert as qc,uniq as Hc,cloneDeep as Rt,get as Kc,set as Wc,isFunction as Vc}from"lodash-es";import{PromisePool as he}from"@supercharge/promise-pool";import{S3Client as Gc,PutObjectCommand as Yc,GetObjectCommand as Jc,HeadObjectCommand as Xc,CopyObjectCommand as Qc,DeleteObjectCommand as ef,DeleteObjectsCommand as Ki,ListObjectsV2Command as Wi}from"@aws-sdk/client-s3";import{createHash as Vi}from"crypto";import{flatten as $r,unflatten as tf}from"flat";import rf from"fastest-validator";import{ReadableStream as nf}from"node:stream/web";function Gi(e,t){for(var r=0,n=e.length-1;n>=0;n--){var i=e[n];i==="."?e.splice(n,1):i===".."?(e.splice(n,1),r++):r&&(e.splice(n,1),r--)}if(t)for(;r--;r)e.unshift("..");return e}var af=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/,Ur=function(e){return af.exec(e).slice(1)};function Br(){for(var e="",t=!1,r=arguments.length-1;r>=-1&&!t;r--){var n=r>=0?arguments[r]:"/";if(typeof n!="string")throw new TypeError("Arguments to path.resolve must be strings");if(!n)continue;e=n+"/"+e,t=n.charAt(0)==="/"}return e=Gi(zr(e.split("/"),function(i){return!!i}),!t).join("/"),(t?"/":"")+e||"."}function Yi(e){var t=Ji(e),r=hf(e,-1)==="/";return e=Gi(zr(e.split("/"),function(n){return!!n}),!t).join("/"),!e&&!t&&(e="."),e&&r&&(e+="/"),(t?"/":"")+e}function Ji(e){return e.charAt(0)==="/"}function me(){var e=Array.prototype.slice.call(arguments,0);return Yi(zr(e,function(t,r){if(typeof t!="string")throw new TypeError("Arguments to path.join must be strings");return t}).join("/"))}function of(e,t){e=Br(e).substr(1),t=Br(t).substr(1);function r(c){for(var l=0;l<c.length&&c[l]==="";l++);for(var d=c.length-1;d>=0&&c[d]==="";d--);return l>d?[]:c.slice(l,d-l+1)}for(var n=r(e.split("/")),i=r(t.split("/")),a=Math.min(n.length,i.length),o=a,s=0;s<a;s++)if(n[s]!==i[s]){o=s;break}for(var f=[],s=o;s<n.length;s++)f.push("..");return f=f.concat(i.slice(o)),f.join("/")}var sf="/",cf=":";function ff(e){var t=Ur(e),r=t[0],n=t[1];return!r&&!n?".":(n&&(n=n.substr(0,n.length-1)),r+n)}function lf(e,t){var r=Ur(e)[2];return t&&r.substr(-1*t.length)===t&&(r=r.substr(0,r.length-t.length)),r}function uf(e){return Ur(e)[3]}var de={extname:uf,basename:lf,dirname:ff,sep:sf,delimiter:cf,relative:of,join:me,isAbsolute:Ji,normalize:Yi,resolve:Br};function zr(e,t){if(e.filter)return e.filter(t);for(var r=[],n=0;n<e.length;n++)t(e[n],n,e)&&r.push(e[n]);return r}var hf="ab".substr(-1)==="b"?function(e,t,r){return e.substr(t,r)}:function(e,t,r){return t<0&&(t=e.length+t),e.substr(t,r)};const Zr=Zi(Zc,22),df="ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz23456789",pf=Zi(df,12);var qr;function Ie(){}Ie.prototype=Object.create(null);function R(){R.init.call(this)}R.EventEmitter=R,R.usingDomains=!1,R.prototype.domain=void 0,R.prototype._events=void 0,R.prototype._maxListeners=void 0,R.defaultMaxListeners=10,R.init=function(){this.domain=null,R.usingDomains&&qr.active&&!(this instanceof qr.Domain)&&(this.domain=qr.active),(!this._events||this._events===Object.getPrototypeOf(this)._events)&&(this._events=new Ie,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},R.prototype.setMaxListeners=function(t){if(typeof t!="number"||t<0||isNaN(t))throw new TypeError('"n" argument must be a positive number');return this._maxListeners=t,this};function Xi(e){return e._maxListeners===void 0?R.defaultMaxListeners:e._maxListeners}R.prototype.getMaxListeners=function(){return Xi(this)};function yf(e,t,r){if(t)e.call(r);else for(var n=e.length,i=Ot(e,n),a=0;a<n;++a)i[a].call(r)}function gf(e,t,r,n){if(t)e.call(r,n);else for(var i=e.length,a=Ot(e,i),o=0;o<i;++o)a[o].call(r,n)}function vf(e,t,r,n,i){if(t)e.call(r,n,i);else for(var a=e.length,o=Ot(e,a),s=0;s<a;++s)o[s].call(r,n,i)}function wf(e,t,r,n,i,a){if(t)e.call(r,n,i,a);else for(var o=e.length,s=Ot(e,o),f=0;f<o;++f)s[f].call(r,n,i,a)}function _f(e,t,r,n){if(t)e.apply(r,n);else for(var i=e.length,a=Ot(e,i),o=0;o<i;++o)a[o].apply(r,n)}R.prototype.emit=function(t){var r,n,i,a,o,s,f,c=t==="error";if(s=this._events,s)c=c&&s.error==null;else if(!c)return!1;if(f=this.domain,c){if(r=arguments[1],f)r||(r=new Error('Uncaught, unspecified "error" event')),r.domainEmitter=this,r.domain=f,r.domainThrown=!1,f.emit("error",r);else{if(r instanceof Error)throw r;var l=new Error('Uncaught, unspecified "error" event. ('+r+")");throw l.context=r,l}return!1}if(n=s[t],!n)return!1;var d=typeof n=="function";switch(i=arguments.length,i){case 1:yf(n,d,this);break;case 2:gf(n,d,this,arguments[1]);break;case 3:vf(n,d,this,arguments[1],arguments[2]);break;case 4:wf(n,d,this,arguments[1],arguments[2],arguments[3]);break;default:for(a=new Array(i-1),o=1;o<i;o++)a[o-1]=arguments[o];_f(n,d,this,a)}return!0};function Qi(e,t,r,n){var i,a,o;if(typeof r!="function")throw new TypeError('"listener" argument must be a function');if(a=e._events,a?(a.newListener&&(e.emit("newListener",t,r.listener?r.listener:r),a=e._events),o=a[t]):(a=e._events=new Ie,e._eventsCount=0),!o)o=a[t]=r,++e._eventsCount;else if(typeof o=="function"?o=a[t]=n?[r,o]:[o,r]:n?o.unshift(r):o.push(r),!o.warned&&(i=Xi(e),i&&i>0&&o.length>i)){o.warned=!0;var s=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+t+" listeners added. Use emitter.setMaxListeners() to increase limit");s.name="MaxListenersExceededWarning",s.emitter=e,s.type=t,s.count=o.length,bf(s)}return e}function bf(e){typeof console.warn=="function"?console.warn(e):console.log(e)}R.prototype.addListener=function(t,r){return Qi(this,t,r,!1)},R.prototype.on=R.prototype.addListener,R.prototype.prependListener=function(t,r){return Qi(this,t,r,!0)};function ea(e,t,r){var n=!1;function i(){e.removeListener(t,i),n||(n=!0,r.apply(e,arguments))}return i.listener=r,i}R.prototype.once=function(t,r){if(typeof r!="function")throw new TypeError('"listener" argument must be a function');return this.on(t,ea(this,t,r)),this},R.prototype.prependOnceListener=function(t,r){if(typeof r!="function")throw new TypeError('"listener" argument must be a function');return this.prependListener(t,ea(this,t,r)),this},R.prototype.removeListener=function(t,r){var n,i,a,o,s;if(typeof r!="function")throw new TypeError('"listener" argument must be a function');if(i=this._events,!i)return this;if(n=i[t],!n)return this;if(n===r||n.listener&&n.listener===r)--this._eventsCount===0?this._events=new Ie:(delete i[t],i.removeListener&&this.emit("removeListener",t,n.listener||r));else if(typeof n!="function"){for(a=-1,o=n.length;o-- >0;)if(n[o]===r||n[o].listener&&n[o].listener===r){s=n[o].listener,a=o;break}if(a<0)return this;if(n.length===1){if(n[0]=void 0,--this._eventsCount===0)return this._events=new Ie,this;delete i[t]}else mf(n,a);i.removeListener&&this.emit("removeListener",t,s||r)}return this},R.prototype.off=function(e,t){return this.removeListener(e,t)},R.prototype.removeAllListeners=function(t){var r,n;if(n=this._events,!n)return this;if(!n.removeListener)return arguments.length===0?(this._events=new Ie,this._eventsCount=0):n[t]&&(--this._eventsCount===0?this._events=new Ie:delete n[t]),this;if(arguments.length===0){for(var i=Object.keys(n),a=0,o;a<i.length;++a)o=i[a],o!=="removeListener"&&this.removeAllListeners(o);return this.removeAllListeners("removeListener"),this._events=new Ie,this._eventsCount=0,this}if(r=n[t],typeof r=="function")this.removeListener(t,r);else if(r)do this.removeListener(t,r[r.length-1]);while(r[0]);return this},R.prototype.listeners=function(t){var r,n,i=this._events;return i?(r=i[t],r?typeof r=="function"?n=[r.listener||r]:n=xf(r):n=[]):n=[],n},R.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):ta.call(e,t)},R.prototype.listenerCount=ta;function ta(e){var t=this._events;if(t){var r=t[e];if(typeof r=="function")return 1;if(r)return r.length}return 0}R.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};function mf(e,t){for(var r=t,n=r+1,i=e.length;n<i;r+=1,n+=1)e[r]=e[n];e.pop()}function Ot(e,t){for(var r=new Array(t);t--;)r[t]=e[t];return r}function xf(e){for(var t=new Array(e.length),r=0;r<t.length;++r)t[r]=e[r].listener||e[r];return t}class ra extends Error{constructor({verbose:t,bucket:r,message:n,...i}){t&&(n=n+`
2
+ import{customAlphabet as Lr,urlAlphabet as qi}from"nanoid";import{chunk as Hi,merge as kt,isString as $r,isEmpty as Ki,invert as Hc,uniq as Kc,cloneDeep as Rt,get as Wc,set as Vc,isFunction as Gc}from"lodash-es";import{PromisePool as he}from"@supercharge/promise-pool";import{S3Client as Yc,PutObjectCommand as Jc,GetObjectCommand as Xc,HeadObjectCommand as Qc,CopyObjectCommand as ef,DeleteObjectCommand as tf,DeleteObjectsCommand as Wi,ListObjectsV2Command as Vi}from"@aws-sdk/client-s3";import{createHash as Gi}from"crypto";import{flatten as Ur,unflatten as rf}from"flat";import nf from"fastest-validator";import{ReadableStream as af}from"node:stream/web";function Yi(e,t){for(var r=0,n=e.length-1;n>=0;n--){var i=e[n];i==="."?e.splice(n,1):i===".."?(e.splice(n,1),r++):r&&(e.splice(n,1),r--)}if(t)for(;r--;r)e.unshift("..");return e}var of=/^(\/?|)([\s\S]*?)((?:\.{1,2}|[^\/]+?|)(\.[^.\/]*|))(?:[\/]*)$/,Br=function(e){return of.exec(e).slice(1)};function zr(){for(var e="",t=!1,r=arguments.length-1;r>=-1&&!t;r--){var n=r>=0?arguments[r]:"/";if(typeof n!="string")throw new TypeError("Arguments to path.resolve must be strings");if(!n)continue;e=n+"/"+e,t=n.charAt(0)==="/"}return e=Yi(Zr(e.split("/"),function(i){return!!i}),!t).join("/"),(t?"/":"")+e||"."}function Ji(e){var t=Xi(e),r=df(e,-1)==="/";return e=Yi(Zr(e.split("/"),function(n){return!!n}),!t).join("/"),!e&&!t&&(e="."),e&&r&&(e+="/"),(t?"/":"")+e}function Xi(e){return e.charAt(0)==="/"}function me(){var e=Array.prototype.slice.call(arguments,0);return Ji(Zr(e,function(t,r){if(typeof t!="string")throw new TypeError("Arguments to path.join must be strings");return t}).join("/"))}function sf(e,t){e=zr(e).substr(1),t=zr(t).substr(1);function r(c){for(var l=0;l<c.length&&c[l]==="";l++);for(var h=c.length-1;h>=0&&c[h]==="";h--);return l>h?[]:c.slice(l,h-l+1)}for(var n=r(e.split("/")),i=r(t.split("/")),a=Math.min(n.length,i.length),o=a,s=0;s<a;s++)if(n[s]!==i[s]){o=s;break}for(var f=[],s=o;s<n.length;s++)f.push("..");return f=f.concat(i.slice(o)),f.join("/")}var cf="/",ff=":";function lf(e){var t=Br(e),r=t[0],n=t[1];return!r&&!n?".":(n&&(n=n.substr(0,n.length-1)),r+n)}function uf(e,t){var r=Br(e)[2];return t&&r.substr(-1*t.length)===t&&(r=r.substr(0,r.length-t.length)),r}function hf(e){return Br(e)[3]}var de={extname:hf,basename:uf,dirname:lf,sep:cf,delimiter:ff,relative:sf,join:me,isAbsolute:Xi,normalize:Ji,resolve:zr};function Zr(e,t){if(e.filter)return e.filter(t);for(var r=[],n=0;n<e.length;n++)t(e[n],n,e)&&r.push(e[n]);return r}var df="ab".substr(-1)==="b"?function(e,t,r){return e.substr(t,r)}:function(e,t,r){return t<0&&(t=e.length+t),e.substr(t,r)};const qr=Lr(qi,22),pf="ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz23456789",yf=Lr(pf,12);var Hr;function Ie(){}Ie.prototype=Object.create(null);function R(){R.init.call(this)}R.EventEmitter=R,R.usingDomains=!1,R.prototype.domain=void 0,R.prototype._events=void 0,R.prototype._maxListeners=void 0,R.defaultMaxListeners=10,R.init=function(){this.domain=null,R.usingDomains&&Hr.active&&!(this instanceof Hr.Domain)&&(this.domain=Hr.active),(!this._events||this._events===Object.getPrototypeOf(this)._events)&&(this._events=new Ie,this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},R.prototype.setMaxListeners=function(t){if(typeof t!="number"||t<0||isNaN(t))throw new TypeError('"n" argument must be a positive number');return this._maxListeners=t,this};function Qi(e){return e._maxListeners===void 0?R.defaultMaxListeners:e._maxListeners}R.prototype.getMaxListeners=function(){return Qi(this)};function gf(e,t,r){if(t)e.call(r);else for(var n=e.length,i=Ot(e,n),a=0;a<n;++a)i[a].call(r)}function vf(e,t,r,n){if(t)e.call(r,n);else for(var i=e.length,a=Ot(e,i),o=0;o<i;++o)a[o].call(r,n)}function wf(e,t,r,n,i){if(t)e.call(r,n,i);else for(var a=e.length,o=Ot(e,a),s=0;s<a;++s)o[s].call(r,n,i)}function bf(e,t,r,n,i,a){if(t)e.call(r,n,i,a);else for(var o=e.length,s=Ot(e,o),f=0;f<o;++f)s[f].call(r,n,i,a)}function _f(e,t,r,n){if(t)e.apply(r,n);else for(var i=e.length,a=Ot(e,i),o=0;o<i;++o)a[o].apply(r,n)}R.prototype.emit=function(t){var r,n,i,a,o,s,f,c=t==="error";if(s=this._events,s)c=c&&s.error==null;else if(!c)return!1;if(f=this.domain,c){if(r=arguments[1],f)r||(r=new Error('Uncaught, unspecified "error" event')),r.domainEmitter=this,r.domain=f,r.domainThrown=!1,f.emit("error",r);else{if(r instanceof Error)throw r;var l=new Error('Uncaught, unspecified "error" event. ('+r+")");throw l.context=r,l}return!1}if(n=s[t],!n)return!1;var h=typeof n=="function";switch(i=arguments.length,i){case 1:gf(n,h,this);break;case 2:vf(n,h,this,arguments[1]);break;case 3:wf(n,h,this,arguments[1],arguments[2]);break;case 4:bf(n,h,this,arguments[1],arguments[2],arguments[3]);break;default:for(a=new Array(i-1),o=1;o<i;o++)a[o-1]=arguments[o];_f(n,h,this,a)}return!0};function ea(e,t,r,n){var i,a,o;if(typeof r!="function")throw new TypeError('"listener" argument must be a function');if(a=e._events,a?(a.newListener&&(e.emit("newListener",t,r.listener?r.listener:r),a=e._events),o=a[t]):(a=e._events=new Ie,e._eventsCount=0),!o)o=a[t]=r,++e._eventsCount;else if(typeof o=="function"?o=a[t]=n?[r,o]:[o,r]:n?o.unshift(r):o.push(r),!o.warned&&(i=Qi(e),i&&i>0&&o.length>i)){o.warned=!0;var s=new Error("Possible EventEmitter memory leak detected. "+o.length+" "+t+" listeners added. Use emitter.setMaxListeners() to increase limit");s.name="MaxListenersExceededWarning",s.emitter=e,s.type=t,s.count=o.length,mf(s)}return e}function mf(e){typeof console.warn=="function"?console.warn(e):console.log(e)}R.prototype.addListener=function(t,r){return ea(this,t,r,!1)},R.prototype.on=R.prototype.addListener,R.prototype.prependListener=function(t,r){return ea(this,t,r,!0)};function ta(e,t,r){var n=!1;function i(){e.removeListener(t,i),n||(n=!0,r.apply(e,arguments))}return i.listener=r,i}R.prototype.once=function(t,r){if(typeof r!="function")throw new TypeError('"listener" argument must be a function');return this.on(t,ta(this,t,r)),this},R.prototype.prependOnceListener=function(t,r){if(typeof r!="function")throw new TypeError('"listener" argument must be a function');return this.prependListener(t,ta(this,t,r)),this},R.prototype.removeListener=function(t,r){var n,i,a,o,s;if(typeof r!="function")throw new TypeError('"listener" argument must be a function');if(i=this._events,!i)return this;if(n=i[t],!n)return this;if(n===r||n.listener&&n.listener===r)--this._eventsCount===0?this._events=new Ie:(delete i[t],i.removeListener&&this.emit("removeListener",t,n.listener||r));else if(typeof n!="function"){for(a=-1,o=n.length;o-- >0;)if(n[o]===r||n[o].listener&&n[o].listener===r){s=n[o].listener,a=o;break}if(a<0)return this;if(n.length===1){if(n[0]=void 0,--this._eventsCount===0)return this._events=new Ie,this;delete i[t]}else xf(n,a);i.removeListener&&this.emit("removeListener",t,s||r)}return this},R.prototype.off=function(e,t){return this.removeListener(e,t)},R.prototype.removeAllListeners=function(t){var r,n;if(n=this._events,!n)return this;if(!n.removeListener)return arguments.length===0?(this._events=new Ie,this._eventsCount=0):n[t]&&(--this._eventsCount===0?this._events=new Ie:delete n[t]),this;if(arguments.length===0){for(var i=Object.keys(n),a=0,o;a<i.length;++a)o=i[a],o!=="removeListener"&&this.removeAllListeners(o);return this.removeAllListeners("removeListener"),this._events=new Ie,this._eventsCount=0,this}if(r=n[t],typeof r=="function")this.removeListener(t,r);else if(r)do this.removeListener(t,r[r.length-1]);while(r[0]);return this},R.prototype.listeners=function(t){var r,n,i=this._events;return i?(r=i[t],r?typeof r=="function"?n=[r.listener||r]:n=Ef(r):n=[]):n=[],n},R.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):ra.call(e,t)},R.prototype.listenerCount=ra;function ra(e){var t=this._events;if(t){var r=t[e];if(typeof r=="function")return 1;if(r)return r.length}return 0}R.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]};function xf(e,t){for(var r=t,n=r+1,i=e.length;n<i;r+=1,n+=1)e[r]=e[n];e.pop()}function Ot(e,t){for(var r=new Array(t);t--;)r[t]=e[t];return r}function Ef(e){for(var t=new Array(e.length),r=0;r<t.length;++r)t[r]=e[r].listener||e[r];return t}class na extends Error{constructor({verbose:t,bucket:r,message:n,...i}){t&&(n=n+`
3
3
 
4
4
  Verbose:
5
5
 
6
- ${JSON.stringify(i,null,2)}`),super(n),typeof Error.captureStackTrace=="function"?Error.captureStackTrace(this,this.constructor):this.stack=new Error(n).stack,super.name=this.constructor.name,this.name=this.constructor.name,this.bucket=r,this.thrownAt=new Date}toJson(){return{...this}}toString(){return`${this.name} | ${this.message}`}}class ne extends ra{constructor(t,r={}){super({message:t,...r})}}class Ef extends ne{constructor(t,r={}){super(t,r),Object.assign(this,r)}}class Sf extends ne{constructor(t,r={}){super(t,r),Object.assign(this,r)}}class Af extends ne{constructor(t,r={}){super(t,r),Object.assign(this,r)}}class kf extends ne{constructor(t,r={}){super(t,r),Object.assign(this,r)}}class Rf extends ne{constructor(t,r={}){super(t,r),Object.assign(this,r)}}class Of extends ne{constructor({bucket:t,resourceName:r,id:n,...i}){super(`Resource not found: ${r}/${n} [bucket:${t}]`,{bucket:t,resourceName:r,id:n,...i})}}class na extends ne{constructor({bucket:t,...r}){super(`Bucket does not exists [bucket:${t}]`,{bucket:t,...r})}}class Hr extends ne{constructor({bucket:t,key:r,...n}){super(`Key [${r}] does not exists [bucket:${t}/${r}]`,{bucket:t,key:r,...n})}}class ia extends Hr{}class aa extends ne{constructor({bucket:t,...r}){super(`Missing metadata for bucket [bucket:${t}]`,{bucket:t,...r})}}class rr extends ne{constructor({bucket:t,resourceName:r,attributes:n,validation:i}){super(`This item is not valid. Resource=${r} [bucket:${t}].
7
- ${JSON.stringify(i,null,2)}`,{bucket:t,resourceName:r,attributes:n,validation:i})}}class oa extends ne{}const sa={NotFound:ia,NoSuchKey:Hr,UnknownError:oa,NoSuchBucket:na,MissingMetadata:aa,InvalidResourceItem:rr},ca="us-east-1",fa="https://s3.us-east-1.amazonaws.com";class la{constructor(t){let r;try{r=new URL(t)}catch{throw new Error("Invalid connection string: "+t)}this.region=ca,r.protocol==="s3:"?this.defineS3(r):this.defineMinio(r);for(const[n,i]of r.searchParams.entries())this[n]=i}defineS3(t){if(this.bucket=decodeURIComponent(t.hostname),this.accessKeyId=decodeURIComponent(t.username),this.secretAccessKey=decodeURIComponent(t.password),this.endpoint=fa,["/","",null].includes(t.pathname))this.keyPrefix="";else{let[,...r]=t.pathname.split("/");this.keyPrefix=[...r||[]].join("/")}}defineMinio(t){if(this.forcePathStyle=!0,this.endpoint=t.origin,this.accessKeyId=decodeURIComponent(t.username),this.secretAccessKey=decodeURIComponent(t.password),["/","",null].includes(t.pathname))this.bucket="s3db",this.keyPrefix="";else{let[,r,...n]=t.pathname.split("/");this.bucket=decodeURIComponent(r),this.keyPrefix=[...n||[]].join("/")}}}class ua extends R{constructor({verbose:t=!1,id:r=null,AwsS3Client:n,connectionString:i,parallelism:a=10}){super(),this.verbose=t,this.id=r??Zr(),this.parallelism=a,this.config=new la(i),this.client=n||this.createClient()}createClient(){let t={region:this.config.region,endpoint:this.config.endpoint};return this.config.forcePathStyle&&(t.forcePathStyle=!0),this.config.accessKeyId&&(t.credentials={accessKeyId:this.config.accessKeyId,secretAccessKey:this.config.secretAccessKey}),new Gc(t)}async sendCommand(t){this.emit("command.request",t.constructor.name,t.input);const r=console.warn;try{console.warn=i=>{i.includes("Stream of unknown length")||r(i)}}catch(i){console.error(i)}const n=await this.client.send(t);this.emit("command.response",t.constructor.name,n,t.input);try{console.warn=r}catch(i){console.error(i)}return n}errorProxy(t,r){this.verbose&&(r.bucket=this.config.bucket,r.config=this.config,r.verbose=this.verbose),t.data=r;const n=sa[t.name];return n?new n(r):t}async putObject({key:t,metadata:r,contentType:n,body:i,contentEncoding:a}){const o={Bucket:this.config.bucket,Key:this.config.keyPrefix?de.join(this.config.keyPrefix,t):t,Metadata:{...r},Body:i||Buffer.alloc(0)};n!==void 0&&(o.ContentType=n),a!==void 0&&(o.ContentEncoding=a);try{const s=await this.sendCommand(new Yc(o));return this.emit("putObject",s,o),s}catch(s){throw this.errorProxy(s,{key:t,command:o})}}async getObject(t){const r={Bucket:this.config.bucket,Key:de.join(this.config.keyPrefix,t)};try{const n=await this.sendCommand(new Jc(r));return this.emit("getObject",n,r),n}catch(n){throw this.errorProxy(n,{key:t,command:r})}}async headObject(t){const r={Bucket:this.config.bucket,Key:this.config.keyPrefix?de.join(this.config.keyPrefix,t):t};try{const n=await this.sendCommand(new Xc(r));return this.emit("headObject",n,r),n}catch(n){throw this.errorProxy(n,{key:t,command:r})}}async copyObject({from:t,to:r}){const n={Bucket:this.config.bucket,Key:this.config.keyPrefix?de.join(this.config.keyPrefix,r):r,CopySource:de.join(this.config.bucket,this.config.keyPrefix?de.join(this.config.keyPrefix,t):t)};try{const i=await this.client.send(new Qc(n));return this.emit("copyObject",i,n),i}catch(i){throw this.errorProxy(i,{from:t,to:r,command:n})}}async exists(t){try{return await this.headObject(t),!0}catch(r){if(r.name==="NoSuchKey")return!1;if(r.name==="NotFound")return!1;throw r}}async deleteObject(t){const r={Bucket:this.config.bucket,Key:this.config.keyPrefix?de.join(this.config.keyPrefix,t):t};try{const n=await this.sendCommand(new ef(r));return this.emit("deleteObject",n,r),n}catch(n){throw this.errorProxy(n,{key:t,command:r})}}async deleteObjects(t){const r=qi(t,1e3),{results:n,errors:i}=await he.for(r).withConcurrency(this.parallelism).process(async o=>{const s={Bucket:this.config.bucket,Delete:{Objects:o.map(f=>({Key:this.config.keyPrefix?de.join(this.config.keyPrefix,f):f}))}};try{return await this.sendCommand(new Ki(s))}catch(f){throw this.errorProxy(f,{keys:o,command:s})}}),a={deleted:n,notFound:i};return this.emit("deleteObjects",a,t),a}async deleteAll({prefix:t}={}){let r,n=0;do{const i=new Wi({Bucket:this.config.bucket,Prefix:this.config.keyPrefix?de.join(this.config.keyPrefix,t):t,ContinuationToken:r}),a=await this.client.send(i);if(a.Contents&&a.Contents.length>0){const o=new Ki({Bucket:this.config.bucket,Delete:{Objects:a.Contents.map(c=>({Key:c.Key}))}}),s=await this.client.send(o),f=s.Deleted?s.Deleted.length:0;n+=f,this.emit("deleteAll",{prefix:t,batch:f,total:n})}r=a.IsTruncated?a.NextContinuationToken:void 0}while(r);return this.emit("deleteAllComplete",{prefix:t,totalDeleted:n}),n}async moveObject({from:t,to:r}){try{return await this.copyObject({from:t,to:r}),await this.deleteObject(t),!0}catch(n){throw this.errorProxy(n,{from:t,to:r,command:options})}}async listObjects({prefix:t,maxKeys:r=1e3,continuationToken:n}={}){const i={Bucket:this.config.bucket,MaxKeys:r,ContinuationToken:n,Prefix:this.config.keyPrefix?de.join(this.config.keyPrefix,t||""):t||""};try{const a=await this.sendCommand(new Wi(i));return this.emit("listObjects",a,i),a}catch(a){throw this.errorProxy(a,{command:i})}}async count({prefix:t}={}){let r=0,n=!0,i;for(;n;){const a={prefix:t,continuationToken:i},o=await this.listObjects(a);r+=o.KeyCount||0,n=o.IsTruncated||!1,i=o.NextContinuationToken}return this.emit("count",r,{prefix:t}),r}async getAllKeys({prefix:t}={}){let r=[],n=!0,i;for(;n;){const a={prefix:t,continuationToken:i},o=await this.listObjects(a);o.Contents&&(r=r.concat(o.Contents.map(s=>s.Key))),n=o.IsTruncated||!1,i=o.NextContinuationToken}return this.config.keyPrefix&&(r=r.map(a=>a.replace(this.config.keyPrefix,"")).map(a=>a.startsWith("/")?a.replace("/",""):a)),this.emit("getAllKeys",r,{prefix:t}),r}async getContinuationTokenAfterOffset(t={}){const{prefix:r,offset:n=1e3}=t;if(n===0)return null;let i=!0,a,o=0;for(;i;){let s=n<1e3?n:n-o>1e3?1e3:n-o;const f={prefix:r,maxKeys:s,continuationToken:a},c=await this.listObjects(f);if(c.Contents&&(o+=c.Contents.length),i=c.IsTruncated||!1,a=c.NextContinuationToken,o>=n)break}return this.emit("getContinuationTokenAfterOffset",a||null,t),a||null}async getKeysPage(t={}){const{prefix:r,offset:n=0,amount:i=100}=t;let a=[],o=!0,s;for(n>0&&(s=await this.getContinuationTokenAfterOffset({prefix:r,offset:n}));o;){const f={prefix:r,continuationToken:s},c=await this.listObjects(f);if(c.Contents&&(a=a.concat(c.Contents.map(l=>l.Key))),o=c.IsTruncated||!1,s=c.NextContinuationToken,a.length>i){a=a.splice(0,i);break}}return this.config.keyPrefix&&(a=a.map(f=>f.replace(this.config.keyPrefix,"")).map(f=>f.startsWith("/")?f.replace("/",""):f)),this.emit("getKeysPage",a,t),a}async moveAllObjects({prefixFrom:t,prefixTo:r}){const n=await this.getAllKeys({prefix:t}),{results:i,errors:a}=await he.for(n).withConcurrency(this.parallelism).process(async o=>{const s=o.replace(t,r);try{return await this.moveObject({from:o,to:s}),s}catch(f){throw this.errorProxy(f,{from:o,to:s})}});if(this.emit("moveAllObjects",{results:i,errors:a},{prefixFrom:t,prefixTo:r}),a.length>0)throw new Error("Some objects could not be moved");return i}}async function nr(){let e;if(typeof process<"u")try{const{webcrypto:t}=await import("crypto");e=t}catch{throw new Error("Crypto API not available")}else typeof window<"u"&&(e=window.crypto);if(!e)throw new Error("Could not load any crypto library");return e}async function ha(e){const t=await nr(),n=new TextEncoder().encode(e),i=await t.subtle.digest("SHA-256",n);return Array.from(new Uint8Array(i)).map(s=>s.toString(16).padStart(2,"0")).join("")}async function Kr(e,t){const r=await nr(),n=r.getRandomValues(new Uint8Array(16)),i=await pa(t,n),a=r.getRandomValues(new Uint8Array(12)),s=new TextEncoder().encode(e),f=await r.subtle.encrypt({name:"AES-GCM",iv:a},i,s),c=new Uint8Array(n.length+a.length+f.byteLength);return c.set(n),c.set(a,n.length),c.set(new Uint8Array(f),n.length+a.length),If(c)}async function da(e,t){const r=await nr(),n=Tf(e),i=n.slice(0,16),a=n.slice(16,28),o=n.slice(28),s=await pa(t,i),f=await r.subtle.decrypt({name:"AES-GCM",iv:a},s,o);return new TextDecoder().decode(f)}async function pa(e,t){const r=await nr(),i=new TextEncoder().encode(e),a=await r.subtle.importKey("raw",i,{name:"PBKDF2"},!1,["deriveKey"]);return await r.subtle.deriveKey({name:"PBKDF2",salt:t,iterations:1e5,hash:"SHA-256"},a,{name:"AES-GCM",length:256},!0,["encrypt","decrypt"])}function If(e){if(typeof process<"u")return Buffer.from(e).toString("base64");{const t=String.fromCharCode.apply(null,new Uint8Array(e));return window.btoa(t)}}function Tf(e){if(typeof process<"u")return new Uint8Array(Buffer.from(e,"base64"));{const t=window.atob(e),r=t.length,n=new Uint8Array(r);for(let i=0;i<r;i++)n[i]=t.charCodeAt(i);return n}}function Pf(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var ir={},Wr,ya;function jf(){if(ya)return Wr;ya=1;var e,t,r={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:`
8
- `,r:"\r",t:" "},n;function i(u){throw{name:"SyntaxError",message:u,at:e,text:n}}function a(u){return u&&u!==t&&i("Expected '"+u+"' instead of '"+t+"'"),t=n.charAt(e),e+=1,t}function o(){var u,p="";for(t==="-"&&(p="-",a("-"));t>="0"&&t<="9";)p+=t,a();if(t===".")for(p+=".";a()&&t>="0"&&t<="9";)p+=t;if(t==="e"||t==="E")for(p+=t,a(),(t==="-"||t==="+")&&(p+=t,a());t>="0"&&t<="9";)p+=t,a();return u=Number(p),isFinite(u)||i("Bad number"),u}function s(){var u,p,y="",w;if(t==='"')for(;a();){if(t==='"')return a(),y;if(t==="\\")if(a(),t==="u"){for(w=0,p=0;p<4&&(u=parseInt(a(),16),!!isFinite(u));p+=1)w=w*16+u;y+=String.fromCharCode(w)}else if(typeof r[t]=="string")y+=r[t];else break;else y+=t}i("Bad string")}function f(){for(;t&&t<=" ";)a()}function c(){switch(t){case"t":return a("t"),a("r"),a("u"),a("e"),!0;case"f":return a("f"),a("a"),a("l"),a("s"),a("e"),!1;case"n":return a("n"),a("u"),a("l"),a("l"),null;default:i("Unexpected '"+t+"'")}}function l(){var u=[];if(t==="["){if(a("["),f(),t==="]")return a("]"),u;for(;t;){if(u.push(h()),f(),t==="]")return a("]"),u;a(","),f()}}i("Bad array")}function d(){var u,p={};if(t==="{"){if(a("{"),f(),t==="}")return a("}"),p;for(;t;){if(u=s(),f(),a(":"),Object.prototype.hasOwnProperty.call(p,u)&&i('Duplicate key "'+u+'"'),p[u]=h(),f(),t==="}")return a("}"),p;a(","),f()}}i("Bad object")}function h(){switch(f(),t){case"{":return d();case"[":return l();case'"':return s();case"-":return o();default:return t>="0"&&t<="9"?o():c()}}return Wr=function(u,p){var y;return n=u,e=0,t=" ",y=h(),f(),t&&i("Syntax error"),typeof p=="function"?function w(_,m){var x,v,A=_[m];if(A&&typeof A=="object")for(x in h)Object.prototype.hasOwnProperty.call(A,x)&&(v=w(A,x),typeof v>"u"?delete A[x]:A[x]=v);return p.call(_,m,A)}({"":y},""):y},Wr}var Vr,ga;function Ff(){if(ga)return Vr;ga=1;var e=/[\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,t,r,n={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},i;function a(s){return e.lastIndex=0,e.test(s)?'"'+s.replace(e,function(f){var c=n[f];return typeof c=="string"?c:"\\u"+("0000"+f.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+s+'"'}function o(s,f){var c,l,d,h,u=t,p,y=f[s];switch(y&&typeof y=="object"&&typeof y.toJSON=="function"&&(y=y.toJSON(s)),typeof i=="function"&&(y=i.call(f,s,y)),typeof y){case"string":return a(y);case"number":return isFinite(y)?String(y):"null";case"boolean":case"null":return String(y);case"object":if(!y)return"null";if(t+=r,p=[],Object.prototype.toString.apply(y)==="[object Array]"){for(h=y.length,c=0;c<h;c+=1)p[c]=o(c,y)||"null";return d=p.length===0?"[]":t?`[
6
+ ${JSON.stringify(i,null,2)}`),super(n),typeof Error.captureStackTrace=="function"?Error.captureStackTrace(this,this.constructor):this.stack=new Error(n).stack,super.name=this.constructor.name,this.name=this.constructor.name,this.bucket=r,this.thrownAt=new Date}toJson(){return{...this}}toString(){return`${this.name} | ${this.message}`}}class ne extends na{constructor(t,r={}){super({message:t,...r})}}class Sf extends ne{constructor(t,r={}){super(t,r),Object.assign(this,r)}}class Af extends ne{constructor(t,r={}){super(t,r),Object.assign(this,r)}}class kf extends ne{constructor(t,r={}){super(t,r),Object.assign(this,r)}}class Rf extends ne{constructor(t,r={}){super(t,r),Object.assign(this,r)}}class Of extends ne{constructor(t,r={}){super(t,r),Object.assign(this,r)}}class If extends ne{constructor({bucket:t,resourceName:r,id:n,...i}){super(`Resource not found: ${r}/${n} [bucket:${t}]`,{bucket:t,resourceName:r,id:n,...i})}}class ia extends ne{constructor({bucket:t,...r}){super(`Bucket does not exists [bucket:${t}]`,{bucket:t,...r})}}class Kr extends ne{constructor({bucket:t,key:r,...n}){super(`Key [${r}] does not exists [bucket:${t}/${r}]`,{bucket:t,key:r,...n})}}class aa extends Kr{}class oa extends ne{constructor({bucket:t,...r}){super(`Missing metadata for bucket [bucket:${t}]`,{bucket:t,...r})}}class rr extends ne{constructor({bucket:t,resourceName:r,attributes:n,validation:i}){super(`This item is not valid. Resource=${r} [bucket:${t}].
7
+ ${JSON.stringify(i,null,2)}`,{bucket:t,resourceName:r,attributes:n,validation:i})}}class sa extends ne{}const ca={NotFound:aa,NoSuchKey:Kr,UnknownError:sa,NoSuchBucket:ia,MissingMetadata:oa,InvalidResourceItem:rr},fa="us-east-1",la="https://s3.us-east-1.amazonaws.com";class ua{constructor(t){let r;try{r=new URL(t)}catch{throw new Error("Invalid connection string: "+t)}this.region=fa,r.protocol==="s3:"?this.defineS3(r):this.defineMinio(r);for(const[n,i]of r.searchParams.entries())this[n]=i}defineS3(t){if(this.bucket=decodeURIComponent(t.hostname),this.accessKeyId=decodeURIComponent(t.username),this.secretAccessKey=decodeURIComponent(t.password),this.endpoint=la,["/","",null].includes(t.pathname))this.keyPrefix="";else{let[,...r]=t.pathname.split("/");this.keyPrefix=[...r||[]].join("/")}}defineMinio(t){if(this.forcePathStyle=!0,this.endpoint=t.origin,this.accessKeyId=decodeURIComponent(t.username),this.secretAccessKey=decodeURIComponent(t.password),["/","",null].includes(t.pathname))this.bucket="s3db",this.keyPrefix="";else{let[,r,...n]=t.pathname.split("/");this.bucket=decodeURIComponent(r),this.keyPrefix=[...n||[]].join("/")}}}class ha extends R{constructor({verbose:t=!1,id:r=null,AwsS3Client:n,connectionString:i,parallelism:a=10}){super(),this.verbose=t,this.id=r??qr(),this.parallelism=a,this.config=new ua(i),this.client=n||this.createClient()}createClient(){let t={region:this.config.region,endpoint:this.config.endpoint};return this.config.forcePathStyle&&(t.forcePathStyle=!0),this.config.accessKeyId&&(t.credentials={accessKeyId:this.config.accessKeyId,secretAccessKey:this.config.secretAccessKey}),new Yc(t)}async sendCommand(t){this.emit("command.request",t.constructor.name,t.input);const r=console.warn;try{console.warn=i=>{i.includes("Stream of unknown length")||r(i)}}catch(i){console.error(i)}const n=await this.client.send(t);this.emit("command.response",t.constructor.name,n,t.input);try{console.warn=r}catch(i){console.error(i)}return n}errorProxy(t,r){this.verbose&&(r.bucket=this.config.bucket,r.config=this.config,r.verbose=this.verbose),t.data=r;const n=ca[t.name];return n?new n(r):t}async putObject({key:t,metadata:r,contentType:n,body:i,contentEncoding:a}){const o={Bucket:this.config.bucket,Key:this.config.keyPrefix?de.join(this.config.keyPrefix,t):t,Metadata:{...r},Body:i||Buffer.alloc(0)};n!==void 0&&(o.ContentType=n),a!==void 0&&(o.ContentEncoding=a);try{const s=await this.sendCommand(new Jc(o));return this.emit("putObject",s,o),s}catch(s){throw this.errorProxy(s,{key:t,command:o})}}async getObject(t){const r={Bucket:this.config.bucket,Key:de.join(this.config.keyPrefix,t)};try{const n=await this.sendCommand(new Xc(r));return this.emit("getObject",n,r),n}catch(n){throw this.errorProxy(n,{key:t,command:r})}}async headObject(t){const r={Bucket:this.config.bucket,Key:this.config.keyPrefix?de.join(this.config.keyPrefix,t):t};try{const n=await this.sendCommand(new Qc(r));return this.emit("headObject",n,r),n}catch(n){throw this.errorProxy(n,{key:t,command:r})}}async copyObject({from:t,to:r}){const n={Bucket:this.config.bucket,Key:this.config.keyPrefix?de.join(this.config.keyPrefix,r):r,CopySource:de.join(this.config.bucket,this.config.keyPrefix?de.join(this.config.keyPrefix,t):t)};try{const i=await this.client.send(new ef(n));return this.emit("copyObject",i,n),i}catch(i){throw this.errorProxy(i,{from:t,to:r,command:n})}}async exists(t){try{return await this.headObject(t),!0}catch(r){if(r.name==="NoSuchKey")return!1;if(r.name==="NotFound")return!1;throw r}}async deleteObject(t){const r={Bucket:this.config.bucket,Key:this.config.keyPrefix?de.join(this.config.keyPrefix,t):t};try{const n=await this.sendCommand(new tf(r));return this.emit("deleteObject",n,r),n}catch(n){throw this.errorProxy(n,{key:t,command:r})}}async deleteObjects(t){const r=Hi(t,1e3),{results:n,errors:i}=await he.for(r).withConcurrency(this.parallelism).process(async o=>{const s={Bucket:this.config.bucket,Delete:{Objects:o.map(f=>({Key:this.config.keyPrefix?de.join(this.config.keyPrefix,f):f}))}};try{return await this.sendCommand(new Wi(s))}catch(f){throw this.errorProxy(f,{keys:o,command:s})}}),a={deleted:n,notFound:i};return this.emit("deleteObjects",a,t),a}async deleteAll({prefix:t}={}){let r,n=0;do{const i=new Vi({Bucket:this.config.bucket,Prefix:this.config.keyPrefix?de.join(this.config.keyPrefix,t):t,ContinuationToken:r}),a=await this.client.send(i);if(a.Contents&&a.Contents.length>0){const o=new Wi({Bucket:this.config.bucket,Delete:{Objects:a.Contents.map(c=>({Key:c.Key}))}}),s=await this.client.send(o),f=s.Deleted?s.Deleted.length:0;n+=f,this.emit("deleteAll",{prefix:t,batch:f,total:n})}r=a.IsTruncated?a.NextContinuationToken:void 0}while(r);return this.emit("deleteAllComplete",{prefix:t,totalDeleted:n}),n}async moveObject({from:t,to:r}){try{return await this.copyObject({from:t,to:r}),await this.deleteObject(t),!0}catch(n){throw this.errorProxy(n,{from:t,to:r,command:options})}}async listObjects({prefix:t,maxKeys:r=1e3,continuationToken:n}={}){const i={Bucket:this.config.bucket,MaxKeys:r,ContinuationToken:n,Prefix:this.config.keyPrefix?de.join(this.config.keyPrefix,t||""):t||""};try{const a=await this.sendCommand(new Vi(i));return this.emit("listObjects",a,i),a}catch(a){throw this.errorProxy(a,{command:i})}}async count({prefix:t}={}){let r=0,n=!0,i;for(;n;){const a={prefix:t,continuationToken:i},o=await this.listObjects(a);r+=o.KeyCount||0,n=o.IsTruncated||!1,i=o.NextContinuationToken}return this.emit("count",r,{prefix:t}),r}async getAllKeys({prefix:t}={}){let r=[],n=!0,i;for(;n;){const a={prefix:t,continuationToken:i},o=await this.listObjects(a);o.Contents&&(r=r.concat(o.Contents.map(s=>s.Key))),n=o.IsTruncated||!1,i=o.NextContinuationToken}return this.config.keyPrefix&&(r=r.map(a=>a.replace(this.config.keyPrefix,"")).map(a=>a.startsWith("/")?a.replace("/",""):a)),this.emit("getAllKeys",r,{prefix:t}),r}async getContinuationTokenAfterOffset(t={}){const{prefix:r,offset:n=1e3}=t;if(n===0)return null;let i=!0,a,o=0;for(;i;){let s=n<1e3?n:n-o>1e3?1e3:n-o;const f={prefix:r,maxKeys:s,continuationToken:a},c=await this.listObjects(f);if(c.Contents&&(o+=c.Contents.length),i=c.IsTruncated||!1,a=c.NextContinuationToken,o>=n)break}return this.emit("getContinuationTokenAfterOffset",a||null,t),a||null}async getKeysPage(t={}){const{prefix:r,offset:n=0,amount:i=100}=t;let a=[],o=!0,s;for(n>0&&(s=await this.getContinuationTokenAfterOffset({prefix:r,offset:n}));o;){const f={prefix:r,continuationToken:s},c=await this.listObjects(f);if(c.Contents&&(a=a.concat(c.Contents.map(l=>l.Key))),o=c.IsTruncated||!1,s=c.NextContinuationToken,a.length>i){a=a.splice(0,i);break}}return this.config.keyPrefix&&(a=a.map(f=>f.replace(this.config.keyPrefix,"")).map(f=>f.startsWith("/")?f.replace("/",""):f)),this.emit("getKeysPage",a,t),a}async moveAllObjects({prefixFrom:t,prefixTo:r}){const n=await this.getAllKeys({prefix:t}),{results:i,errors:a}=await he.for(n).withConcurrency(this.parallelism).process(async o=>{const s=o.replace(t,r);try{return await this.moveObject({from:o,to:s}),s}catch(f){throw this.errorProxy(f,{from:o,to:s})}});if(this.emit("moveAllObjects",{results:i,errors:a},{prefixFrom:t,prefixTo:r}),a.length>0)throw new Error("Some objects could not be moved");return i}}async function nr(){let e;if(typeof process<"u")try{const{webcrypto:t}=await import("crypto");e=t}catch{throw new Error("Crypto API not available")}else typeof window<"u"&&(e=window.crypto);if(!e)throw new Error("Could not load any crypto library");return e}async function da(e){const t=await nr(),n=new TextEncoder().encode(e),i=await t.subtle.digest("SHA-256",n);return Array.from(new Uint8Array(i)).map(s=>s.toString(16).padStart(2,"0")).join("")}async function Wr(e,t){const r=await nr(),n=r.getRandomValues(new Uint8Array(16)),i=await ya(t,n),a=r.getRandomValues(new Uint8Array(12)),s=new TextEncoder().encode(e),f=await r.subtle.encrypt({name:"AES-GCM",iv:a},i,s),c=new Uint8Array(n.length+a.length+f.byteLength);return c.set(n),c.set(a,n.length),c.set(new Uint8Array(f),n.length+a.length),Tf(c)}async function pa(e,t){const r=await nr(),n=Pf(e),i=n.slice(0,16),a=n.slice(16,28),o=n.slice(28),s=await ya(t,i),f=await r.subtle.decrypt({name:"AES-GCM",iv:a},s,o);return new TextDecoder().decode(f)}async function ya(e,t){const r=await nr(),i=new TextEncoder().encode(e),a=await r.subtle.importKey("raw",i,{name:"PBKDF2"},!1,["deriveKey"]);return await r.subtle.deriveKey({name:"PBKDF2",salt:t,iterations:1e5,hash:"SHA-256"},a,{name:"AES-GCM",length:256},!0,["encrypt","decrypt"])}function Tf(e){if(typeof process<"u")return Buffer.from(e).toString("base64");{const t=String.fromCharCode.apply(null,new Uint8Array(e));return window.btoa(t)}}function Pf(e){if(typeof process<"u")return new Uint8Array(Buffer.from(e,"base64"));{const t=window.atob(e),r=t.length,n=new Uint8Array(r);for(let i=0;i<r;i++)n[i]=t.charCodeAt(i);return n}}function jf(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var ir={},Vr,ga;function Ff(){if(ga)return Vr;ga=1;var e,t,r={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:`
8
+ `,r:"\r",t:" "},n;function i(u){throw{name:"SyntaxError",message:u,at:e,text:n}}function a(u){return u&&u!==t&&i("Expected '"+u+"' instead of '"+t+"'"),t=n.charAt(e),e+=1,t}function o(){var u,p="";for(t==="-"&&(p="-",a("-"));t>="0"&&t<="9";)p+=t,a();if(t===".")for(p+=".";a()&&t>="0"&&t<="9";)p+=t;if(t==="e"||t==="E")for(p+=t,a(),(t==="-"||t==="+")&&(p+=t,a());t>="0"&&t<="9";)p+=t,a();return u=Number(p),isFinite(u)||i("Bad number"),u}function s(){var u,p,y="",w;if(t==='"')for(;a();){if(t==='"')return a(),y;if(t==="\\")if(a(),t==="u"){for(w=0,p=0;p<4&&(u=parseInt(a(),16),!!isFinite(u));p+=1)w=w*16+u;y+=String.fromCharCode(w)}else if(typeof r[t]=="string")y+=r[t];else break;else y+=t}i("Bad string")}function f(){for(;t&&t<=" ";)a()}function c(){switch(t){case"t":return a("t"),a("r"),a("u"),a("e"),!0;case"f":return a("f"),a("a"),a("l"),a("s"),a("e"),!1;case"n":return a("n"),a("u"),a("l"),a("l"),null;default:i("Unexpected '"+t+"'")}}function l(){var u=[];if(t==="["){if(a("["),f(),t==="]")return a("]"),u;for(;t;){if(u.push(d()),f(),t==="]")return a("]"),u;a(","),f()}}i("Bad array")}function h(){var u,p={};if(t==="{"){if(a("{"),f(),t==="}")return a("}"),p;for(;t;){if(u=s(),f(),a(":"),Object.prototype.hasOwnProperty.call(p,u)&&i('Duplicate key "'+u+'"'),p[u]=d(),f(),t==="}")return a("}"),p;a(","),f()}}i("Bad object")}function d(){switch(f(),t){case"{":return h();case"[":return l();case'"':return s();case"-":return o();default:return t>="0"&&t<="9"?o():c()}}return Vr=function(u,p){var y;return n=u,e=0,t=" ",y=d(),f(),t&&i("Syntax error"),typeof p=="function"?function w(b,m){var x,v,S=b[m];if(S&&typeof S=="object")for(x in d)Object.prototype.hasOwnProperty.call(S,x)&&(v=w(S,x),typeof v>"u"?delete S[x]:S[x]=v);return p.call(b,m,S)}({"":y},""):y},Vr}var Gr,va;function Cf(){if(va)return Gr;va=1;var e=/[\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,t,r,n={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},i;function a(s){return e.lastIndex=0,e.test(s)?'"'+s.replace(e,function(f){var c=n[f];return typeof c=="string"?c:"\\u"+("0000"+f.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+s+'"'}function o(s,f){var c,l,h,d,u=t,p,y=f[s];switch(y&&typeof y=="object"&&typeof y.toJSON=="function"&&(y=y.toJSON(s)),typeof i=="function"&&(y=i.call(f,s,y)),typeof y){case"string":return a(y);case"number":return isFinite(y)?String(y):"null";case"boolean":case"null":return String(y);case"object":if(!y)return"null";if(t+=r,p=[],Object.prototype.toString.apply(y)==="[object Array]"){for(d=y.length,c=0;c<d;c+=1)p[c]=o(c,y)||"null";return h=p.length===0?"[]":t?`[
9
9
  `+t+p.join(`,
10
10
  `+t)+`
11
- `+u+"]":"["+p.join(",")+"]",t=u,d}if(i&&typeof i=="object")for(h=i.length,c=0;c<h;c+=1)l=i[c],typeof l=="string"&&(d=o(l,y),d&&p.push(a(l)+(t?": ":":")+d));else for(l in y)Object.prototype.hasOwnProperty.call(y,l)&&(d=o(l,y),d&&p.push(a(l)+(t?": ":":")+d));return d=p.length===0?"{}":t?`{
11
+ `+u+"]":"["+p.join(",")+"]",t=u,h}if(i&&typeof i=="object")for(d=i.length,c=0;c<d;c+=1)l=i[c],typeof l=="string"&&(h=o(l,y),h&&p.push(a(l)+(t?": ":":")+h));else for(l in y)Object.prototype.hasOwnProperty.call(y,l)&&(h=o(l,y),h&&p.push(a(l)+(t?": ":":")+h));return h=p.length===0?"{}":t?`{
12
12
  `+t+p.join(`,
13
13
  `+t)+`
14
- `+u+"}":"{"+p.join(",")+"}",t=u,d}}return Vr=function(s,f,c){var l;if(t="",r="",typeof c=="number")for(l=0;l<c;l+=1)r+=" ";else typeof c=="string"&&(r=c);if(i=f,f&&typeof f!="function"&&(typeof f!="object"||typeof f.length!="number"))throw new Error("JSON.stringify");return o("",{"":s})},Vr}var va;function Cf(){return va||(va=1,ir.parse=jf(),ir.stringify=Ff()),ir}var Gr,wa;function Df(){if(wa)return Gr;wa=1;var e={}.toString;return Gr=Array.isArray||function(t){return e.call(t)=="[object Array]"},Gr}var Yr,_a;function ba(){if(_a)return Yr;_a=1;var e=Object.prototype.toString;return Yr=function(r){var n=e.call(r),i=n==="[object Arguments]";return i||(i=n!=="[object Array]"&&r!==null&&typeof r=="object"&&typeof r.length=="number"&&r.length>=0&&e.call(r.callee)==="[object Function]"),i},Yr}var Jr,ma;function Mf(){if(ma)return Jr;ma=1;var e;if(!Object.keys){var t=Object.prototype.hasOwnProperty,r=Object.prototype.toString,n=ba(),i=Object.prototype.propertyIsEnumerable,a=!i.call({toString:null},"toString"),o=i.call(function(){},"prototype"),s=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"],f=function(h){var u=h.constructor;return u&&u.prototype===h},c={$applicationCache:!0,$console:!0,$external:!0,$frame:!0,$frameElement:!0,$frames:!0,$innerHeight:!0,$innerWidth:!0,$onmozfullscreenchange:!0,$onmozfullscreenerror:!0,$outerHeight:!0,$outerWidth:!0,$pageXOffset:!0,$pageYOffset:!0,$parent:!0,$scrollLeft:!0,$scrollTop:!0,$scrollX:!0,$scrollY:!0,$self:!0,$webkitIndexedDB:!0,$webkitStorageInfo:!0,$window:!0},l=function(){if(typeof window>"u")return!1;for(var h in window)try{if(!c["$"+h]&&t.call(window,h)&&window[h]!==null&&typeof window[h]=="object")try{f(window[h])}catch{return!0}}catch{return!0}return!1}(),d=function(h){if(typeof window>"u"||!l)return f(h);try{return f(h)}catch{return!1}};e=function(u){var p=u!==null&&typeof u=="object",y=r.call(u)==="[object Function]",w=n(u),_=p&&r.call(u)==="[object String]",m=[];if(!p&&!y&&!w)throw new TypeError("Object.keys called on a non-object");var x=o&&y;if(_&&u.length>0&&!t.call(u,0))for(var v=0;v<u.length;++v)m.push(String(v));if(w&&u.length>0)for(var A=0;A<u.length;++A)m.push(String(A));else for(var O in u)!(x&&O==="prototype")&&t.call(u,O)&&m.push(String(O));if(a)for(var b=d(u),S=0;S<s.length;++S)!(b&&s[S]==="constructor")&&t.call(u,s[S])&&m.push(s[S]);return m}}return Jr=e,Jr}var Xr,xa;function Lf(){if(xa)return Xr;xa=1;var e=Array.prototype.slice,t=ba(),r=Object.keys,n=r?function(o){return r(o)}:Mf(),i=Object.keys;return n.shim=function(){if(Object.keys){var o=function(){var s=Object.keys(arguments);return s&&s.length===arguments.length}(1,2);o||(Object.keys=function(f){return t(f)?i(e.call(f)):i(f)})}else Object.keys=n;return Object.keys||n},Xr=n,Xr}var Qr={exports:{}},en,Ea;function Sa(){return Ea||(Ea=1,en=Object),en}var tn,Aa;function Nf(){return Aa||(Aa=1,tn=Error),tn}var rn,ka;function $f(){return ka||(ka=1,rn=EvalError),rn}var nn,Ra;function Uf(){return Ra||(Ra=1,nn=RangeError),nn}var an,Oa;function Bf(){return Oa||(Oa=1,an=ReferenceError),an}var on,Ia;function Ta(){return Ia||(Ia=1,on=SyntaxError),on}var sn,Pa;function ar(){return Pa||(Pa=1,sn=TypeError),sn}var cn,ja;function zf(){return ja||(ja=1,cn=URIError),cn}var fn,Fa;function Zf(){return Fa||(Fa=1,fn=Math.abs),fn}var ln,Ca;function qf(){return Ca||(Ca=1,ln=Math.floor),ln}var un,Da;function Hf(){return Da||(Da=1,un=Math.max),un}var hn,Ma;function Kf(){return Ma||(Ma=1,hn=Math.min),hn}var dn,La;function Wf(){return La||(La=1,dn=Math.pow),dn}var pn,Na;function Vf(){return Na||(Na=1,pn=Math.round),pn}var yn,$a;function Gf(){return $a||($a=1,yn=Number.isNaN||function(t){return t!==t}),yn}var gn,Ua;function Yf(){if(Ua)return gn;Ua=1;var e=Gf();return gn=function(r){return e(r)||r===0?r:r<0?-1:1},gn}var vn,Ba;function Jf(){return Ba||(Ba=1,vn=Object.getOwnPropertyDescriptor),vn}var wn,za;function or(){if(za)return wn;za=1;var e=Jf();if(e)try{e([],"length")}catch{e=null}return wn=e,wn}var _n,Za;function sr(){if(Za)return _n;Za=1;var e=Object.defineProperty||!1;if(e)try{e({},"a",{value:1})}catch{e=!1}return _n=e,_n}var bn,qa;function Xf(){return qa||(qa=1,bn=function(){if(typeof Symbol!="function"||typeof Object.getOwnPropertySymbols!="function")return!1;if(typeof Symbol.iterator=="symbol")return!0;var t={},r=Symbol("test"),n=Object(r);if(typeof r=="string"||Object.prototype.toString.call(r)!=="[object Symbol]"||Object.prototype.toString.call(n)!=="[object Symbol]")return!1;var i=42;t[r]=i;for(var a in t)return!1;if(typeof Object.keys=="function"&&Object.keys(t).length!==0||typeof Object.getOwnPropertyNames=="function"&&Object.getOwnPropertyNames(t).length!==0)return!1;var o=Object.getOwnPropertySymbols(t);if(o.length!==1||o[0]!==r||!Object.prototype.propertyIsEnumerable.call(t,r))return!1;if(typeof Object.getOwnPropertyDescriptor=="function"){var s=Object.getOwnPropertyDescriptor(t,r);if(s.value!==i||s.enumerable!==!0)return!1}return!0}),bn}var mn,Ha;function Qf(){if(Ha)return mn;Ha=1;var e=typeof Symbol<"u"&&Symbol,t=Xf();return mn=function(){return typeof e!="function"||typeof Symbol!="function"||typeof e("foo")!="symbol"||typeof Symbol("bar")!="symbol"?!1:t()},mn}var xn,Ka;function Wa(){return Ka||(Ka=1,xn=typeof Reflect<"u"&&Reflect.getPrototypeOf||null),xn}var En,Va;function Ga(){if(Va)return En;Va=1;var e=Sa();return En=e.getPrototypeOf||null,En}var Sn,Ya;function el(){if(Ya)return Sn;Ya=1;var e="Function.prototype.bind called on incompatible ",t=Object.prototype.toString,r=Math.max,n="[object Function]",i=function(f,c){for(var l=[],d=0;d<f.length;d+=1)l[d]=f[d];for(var h=0;h<c.length;h+=1)l[h+f.length]=c[h];return l},a=function(f,c){for(var l=[],d=c,h=0;d<f.length;d+=1,h+=1)l[h]=f[d];return l},o=function(s,f){for(var c="",l=0;l<s.length;l+=1)c+=s[l],l+1<s.length&&(c+=f);return c};return Sn=function(f){var c=this;if(typeof c!="function"||t.apply(c)!==n)throw new TypeError(e+c);for(var l=a(arguments,1),d,h=function(){if(this instanceof d){var _=c.apply(this,i(l,arguments));return Object(_)===_?_:this}return c.apply(f,i(l,arguments))},u=r(0,c.length-l.length),p=[],y=0;y<u;y++)p[y]="$"+y;if(d=Function("binder","return function ("+o(p,",")+"){ return binder.apply(this,arguments); }")(h),c.prototype){var w=function(){};w.prototype=c.prototype,d.prototype=new w,w.prototype=null}return d},Sn}var An,Ja;function It(){if(Ja)return An;Ja=1;var e=el();return An=Function.prototype.bind||e,An}var kn,Xa;function Rn(){return Xa||(Xa=1,kn=Function.prototype.call),kn}var On,Qa;function In(){return Qa||(Qa=1,On=Function.prototype.apply),On}var Tn,eo;function tl(){return eo||(eo=1,Tn=typeof Reflect<"u"&&Reflect&&Reflect.apply),Tn}var Pn,to;function ro(){if(to)return Pn;to=1;var e=It(),t=In(),r=Rn(),n=tl();return Pn=n||e.call(r,t),Pn}var jn,no;function Fn(){if(no)return jn;no=1;var e=It(),t=ar(),r=Rn(),n=ro();return jn=function(a){if(a.length<1||typeof a[0]!="function")throw new t("a function is required");return n(e,r,a)},jn}var Cn,io;function rl(){if(io)return Cn;io=1;var e=Fn(),t=or(),r;try{r=[].__proto__===Array.prototype}catch(o){if(!o||typeof o!="object"||!("code"in o)||o.code!=="ERR_PROTO_ACCESS")throw o}var n=!!r&&t&&t(Object.prototype,"__proto__"),i=Object,a=i.getPrototypeOf;return Cn=n&&typeof n.get=="function"?e([n.get]):typeof a=="function"?function(s){return a(s==null?s:i(s))}:!1,Cn}var Dn,ao;function nl(){if(ao)return Dn;ao=1;var e=Wa(),t=Ga(),r=rl();return Dn=e?function(i){return e(i)}:t?function(i){if(!i||typeof i!="object"&&typeof i!="function")throw new TypeError("getProto: not an object");return t(i)}:r?function(i){return r(i)}:null,Dn}var Mn,oo;function il(){if(oo)return Mn;oo=1;var e=Function.prototype.call,t=Object.prototype.hasOwnProperty,r=It();return Mn=r.call(e,t),Mn}var Ln,so;function co(){if(so)return Ln;so=1;var e,t=Sa(),r=Nf(),n=$f(),i=Uf(),a=Bf(),o=Ta(),s=ar(),f=zf(),c=Zf(),l=qf(),d=Hf(),h=Kf(),u=Wf(),p=Vf(),y=Yf(),w=Function,_=function(le){try{return w('"use strict"; return ('+le+").constructor;")()}catch{}},m=or(),x=sr(),v=function(){throw new s},A=m?function(){try{return arguments.callee,v}catch{try{return m(arguments,"callee").get}catch{return v}}}():v,O=Qf()(),b=nl(),S=Ga(),I=Wa(),k=In(),F=Rn(),Z={},V=typeof Uint8Array>"u"||!b?e:b(Uint8Array),re={__proto__:null,"%AggregateError%":typeof AggregateError>"u"?e:AggregateError,"%Array%":Array,"%ArrayBuffer%":typeof ArrayBuffer>"u"?e:ArrayBuffer,"%ArrayIteratorPrototype%":O&&b?b([][Symbol.iterator]()):e,"%AsyncFromSyncIteratorPrototype%":e,"%AsyncFunction%":Z,"%AsyncGenerator%":Z,"%AsyncGeneratorFunction%":Z,"%AsyncIteratorPrototype%":Z,"%Atomics%":typeof Atomics>"u"?e:Atomics,"%BigInt%":typeof BigInt>"u"?e:BigInt,"%BigInt64Array%":typeof BigInt64Array>"u"?e:BigInt64Array,"%BigUint64Array%":typeof BigUint64Array>"u"?e:BigUint64Array,"%Boolean%":Boolean,"%DataView%":typeof DataView>"u"?e:DataView,"%Date%":Date,"%decodeURI%":decodeURI,"%decodeURIComponent%":decodeURIComponent,"%encodeURI%":encodeURI,"%encodeURIComponent%":encodeURIComponent,"%Error%":r,"%eval%":eval,"%EvalError%":n,"%Float16Array%":typeof Float16Array>"u"?e:Float16Array,"%Float32Array%":typeof Float32Array>"u"?e:Float32Array,"%Float64Array%":typeof Float64Array>"u"?e:Float64Array,"%FinalizationRegistry%":typeof FinalizationRegistry>"u"?e:FinalizationRegistry,"%Function%":w,"%GeneratorFunction%":Z,"%Int8Array%":typeof Int8Array>"u"?e:Int8Array,"%Int16Array%":typeof Int16Array>"u"?e:Int16Array,"%Int32Array%":typeof Int32Array>"u"?e:Int32Array,"%isFinite%":isFinite,"%isNaN%":isNaN,"%IteratorPrototype%":O&&b?b(b([][Symbol.iterator]())):e,"%JSON%":typeof JSON=="object"?JSON:e,"%Map%":typeof Map>"u"?e:Map,"%MapIteratorPrototype%":typeof Map>"u"||!O||!b?e:b(new Map()[Symbol.iterator]()),"%Math%":Math,"%Number%":Number,"%Object%":t,"%Object.getOwnPropertyDescriptor%":m,"%parseFloat%":parseFloat,"%parseInt%":parseInt,"%Promise%":typeof Promise>"u"?e:Promise,"%Proxy%":typeof Proxy>"u"?e:Proxy,"%RangeError%":i,"%ReferenceError%":a,"%Reflect%":typeof Reflect>"u"?e:Reflect,"%RegExp%":RegExp,"%Set%":typeof Set>"u"?e:Set,"%SetIteratorPrototype%":typeof Set>"u"||!O||!b?e:b(new Set()[Symbol.iterator]()),"%SharedArrayBuffer%":typeof SharedArrayBuffer>"u"?e:SharedArrayBuffer,"%String%":String,"%StringIteratorPrototype%":O&&b?b(""[Symbol.iterator]()):e,"%Symbol%":O?Symbol:e,"%SyntaxError%":o,"%ThrowTypeError%":A,"%TypedArray%":V,"%TypeError%":s,"%Uint8Array%":typeof Uint8Array>"u"?e:Uint8Array,"%Uint8ClampedArray%":typeof Uint8ClampedArray>"u"?e:Uint8ClampedArray,"%Uint16Array%":typeof Uint16Array>"u"?e:Uint16Array,"%Uint32Array%":typeof Uint32Array>"u"?e:Uint32Array,"%URIError%":f,"%WeakMap%":typeof WeakMap>"u"?e:WeakMap,"%WeakRef%":typeof WeakRef>"u"?e:WeakRef,"%WeakSet%":typeof WeakSet>"u"?e:WeakSet,"%Function.prototype.call%":F,"%Function.prototype.apply%":k,"%Object.defineProperty%":x,"%Object.getPrototypeOf%":S,"%Math.abs%":c,"%Math.floor%":l,"%Math.max%":d,"%Math.min%":h,"%Math.pow%":u,"%Math.round%":p,"%Math.sign%":y,"%Reflect.getPrototypeOf%":I};if(b)try{null.error}catch(le){var Ze=b(b(le));re["%Error.prototype%"]=Ze}var Y=function le(M){var K;if(M==="%AsyncFunction%")K=_("async function () {}");else if(M==="%GeneratorFunction%")K=_("function* () {}");else if(M==="%AsyncGeneratorFunction%")K=_("async function* () {}");else if(M==="%AsyncGenerator%"){var N=le("%AsyncGeneratorFunction%");N&&(K=N.prototype)}else if(M==="%AsyncIteratorPrototype%"){var G=le("%AsyncGenerator%");G&&b&&(K=b(G.prototype))}return re[M]=K,K},fe={__proto__:null,"%ArrayBufferPrototype%":["ArrayBuffer","prototype"],"%ArrayPrototype%":["Array","prototype"],"%ArrayProto_entries%":["Array","prototype","entries"],"%ArrayProto_forEach%":["Array","prototype","forEach"],"%ArrayProto_keys%":["Array","prototype","keys"],"%ArrayProto_values%":["Array","prototype","values"],"%AsyncFunctionPrototype%":["AsyncFunction","prototype"],"%AsyncGenerator%":["AsyncGeneratorFunction","prototype"],"%AsyncGeneratorPrototype%":["AsyncGeneratorFunction","prototype","prototype"],"%BooleanPrototype%":["Boolean","prototype"],"%DataViewPrototype%":["DataView","prototype"],"%DatePrototype%":["Date","prototype"],"%ErrorPrototype%":["Error","prototype"],"%EvalErrorPrototype%":["EvalError","prototype"],"%Float32ArrayPrototype%":["Float32Array","prototype"],"%Float64ArrayPrototype%":["Float64Array","prototype"],"%FunctionPrototype%":["Function","prototype"],"%Generator%":["GeneratorFunction","prototype"],"%GeneratorPrototype%":["GeneratorFunction","prototype","prototype"],"%Int8ArrayPrototype%":["Int8Array","prototype"],"%Int16ArrayPrototype%":["Int16Array","prototype"],"%Int32ArrayPrototype%":["Int32Array","prototype"],"%JSONParse%":["JSON","parse"],"%JSONStringify%":["JSON","stringify"],"%MapPrototype%":["Map","prototype"],"%NumberPrototype%":["Number","prototype"],"%ObjectPrototype%":["Object","prototype"],"%ObjProto_toString%":["Object","prototype","toString"],"%ObjProto_valueOf%":["Object","prototype","valueOf"],"%PromisePrototype%":["Promise","prototype"],"%PromiseProto_then%":["Promise","prototype","then"],"%Promise_all%":["Promise","all"],"%Promise_reject%":["Promise","reject"],"%Promise_resolve%":["Promise","resolve"],"%RangeErrorPrototype%":["RangeError","prototype"],"%ReferenceErrorPrototype%":["ReferenceError","prototype"],"%RegExpPrototype%":["RegExp","prototype"],"%SetPrototype%":["Set","prototype"],"%SharedArrayBufferPrototype%":["SharedArrayBuffer","prototype"],"%StringPrototype%":["String","prototype"],"%SymbolPrototype%":["Symbol","prototype"],"%SyntaxErrorPrototype%":["SyntaxError","prototype"],"%TypedArrayPrototype%":["TypedArray","prototype"],"%TypeErrorPrototype%":["TypeError","prototype"],"%Uint8ArrayPrototype%":["Uint8Array","prototype"],"%Uint8ClampedArrayPrototype%":["Uint8ClampedArray","prototype"],"%Uint16ArrayPrototype%":["Uint16Array","prototype"],"%Uint32ArrayPrototype%":["Uint32Array","prototype"],"%URIErrorPrototype%":["URIError","prototype"],"%WeakMapPrototype%":["WeakMap","prototype"],"%WeakSetPrototype%":["WeakSet","prototype"]},qe=It(),He=il(),St=qe.call(F,Array.prototype.concat),Lc=qe.call(k,Array.prototype.splice),zi=qe.call(F,String.prototype.replace),Yt=qe.call(F,String.prototype.slice),Nc=qe.call(F,RegExp.prototype.exec),$c=/[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g,Uc=/\\(\\)?/g,Bc=function(M){var K=Yt(M,0,1),N=Yt(M,-1);if(K==="%"&&N!=="%")throw new o("invalid intrinsic syntax, expected closing `%`");if(N==="%"&&K!=="%")throw new o("invalid intrinsic syntax, expected opening `%`");var G=[];return zi(M,$c,function(ue,ut,J,Jt){G[G.length]=J?zi(Jt,Uc,"$1"):ut||ue}),G},zc=function(M,K){var N=M,G;if(He(fe,N)&&(G=fe[N],N="%"+G[0]+"%"),He(re,N)){var ue=re[N];if(ue===Z&&(ue=Y(N)),typeof ue>"u"&&!K)throw new s("intrinsic "+M+" exists, but is not available. Please file an issue!");return{alias:G,name:N,value:ue}}throw new o("intrinsic "+M+" does not exist!")};return Ln=function(M,K){if(typeof M!="string"||M.length===0)throw new s("intrinsic name must be a non-empty string");if(arguments.length>1&&typeof K!="boolean")throw new s('"allowMissing" argument must be a boolean');if(Nc(/^%?[^%]*%?$/,M)===null)throw new o("`%` may not be present anywhere but at the beginning and end of the intrinsic name");var N=Bc(M),G=N.length>0?N[0]:"",ue=zc("%"+G+"%",K),ut=ue.name,J=ue.value,Jt=!1,Lr=ue.alias;Lr&&(G=Lr[0],Lc(N,St([0,1],Lr)));for(var Xt=1,At=!0;Xt<N.length;Xt+=1){var be=N[Xt],Qt=Yt(be,0,1),er=Yt(be,-1);if((Qt==='"'||Qt==="'"||Qt==="`"||er==='"'||er==="'"||er==="`")&&Qt!==er)throw new o("property names with quotes must have matching quotes");if((be==="constructor"||!At)&&(Jt=!0),G+="."+be,ut="%"+G+"%",He(re,ut))J=re[ut];else if(J!=null){if(!(be in J)){if(!K)throw new s("base intrinsic for "+M+" exists, but the property is not available.");return}if(m&&Xt+1>=N.length){var tr=m(J,be);At=!!tr,At&&"get"in tr&&!("originalValue"in tr.get)?J=tr.get:J=J[be]}else At=He(J,be),J=J[be];At&&!Jt&&(re[ut]=J)}}return J},Ln}var Nn,fo;function al(){if(fo)return Nn;fo=1;var e=sr(),t=Ta(),r=ar(),n=or();return Nn=function(a,o,s){if(!a||typeof a!="object"&&typeof a!="function")throw new r("`obj` must be an object or a function`");if(typeof o!="string"&&typeof o!="symbol")throw new r("`property` must be a string or a symbol`");if(arguments.length>3&&typeof arguments[3]!="boolean"&&arguments[3]!==null)throw new r("`nonEnumerable`, if provided, must be a boolean or null");if(arguments.length>4&&typeof arguments[4]!="boolean"&&arguments[4]!==null)throw new r("`nonWritable`, if provided, must be a boolean or null");if(arguments.length>5&&typeof arguments[5]!="boolean"&&arguments[5]!==null)throw new r("`nonConfigurable`, if provided, must be a boolean or null");if(arguments.length>6&&typeof arguments[6]!="boolean")throw new r("`loose`, if provided, must be a boolean");var f=arguments.length>3?arguments[3]:null,c=arguments.length>4?arguments[4]:null,l=arguments.length>5?arguments[5]:null,d=arguments.length>6?arguments[6]:!1,h=!!n&&n(a,o);if(e)e(a,o,{configurable:l===null&&h?h.configurable:!l,enumerable:f===null&&h?h.enumerable:!f,value:s,writable:c===null&&h?h.writable:!c});else if(d||!f&&!c&&!l)a[o]=s;else throw new t("This environment does not support defining a property as non-configurable, non-writable, or non-enumerable.")},Nn}var $n,lo;function ol(){if(lo)return $n;lo=1;var e=sr(),t=function(){return!!e};return t.hasArrayLengthDefineBug=function(){if(!e)return null;try{return e([],"length",{value:1}).length!==1}catch{return!0}},$n=t,$n}var Un,uo;function sl(){if(uo)return Un;uo=1;var e=co(),t=al(),r=ol()(),n=or(),i=ar(),a=e("%Math.floor%");return Un=function(s,f){if(typeof s!="function")throw new i("`fn` is not a function");if(typeof f!="number"||f<0||f>4294967295||a(f)!==f)throw new i("`length` must be a positive 32-bit integer");var c=arguments.length>2&&!!arguments[2],l=!0,d=!0;if("length"in s&&n){var h=n(s,"length");h&&!h.configurable&&(l=!1),h&&!h.writable&&(d=!1)}return(l||d||!c)&&(r?t(s,"length",f,!0,!0):t(s,"length",f)),s},Un}var Bn,ho;function cl(){if(ho)return Bn;ho=1;var e=It(),t=In(),r=ro();return Bn=function(){return r(e,t,arguments)},Bn}var po;function fl(){return po||(po=1,function(e){var t=sl(),r=sr(),n=Fn(),i=cl();e.exports=function(o){var s=n(arguments),f=o.length-(arguments.length-1);return t(s,1+(f>0?f:0),!0)},r?r(e.exports,"apply",{value:i}):e.exports.apply=i}(Qr)),Qr.exports}var zn,yo;function ll(){if(yo)return zn;yo=1;var e=co(),t=Fn(),r=t([e("%String.prototype.indexOf%")]);return zn=function(i,a){var o=e(i,!!a);return typeof o=="function"&&r(i,".prototype.")>-1?t([o]):o},zn}var Zn,go;function ul(){if(go)return Zn;go=1;var e=(typeof JSON<"u"?JSON:Cf()).stringify,t=Df(),r=Lf(),n=fl(),i=ll(),a=i("Array.prototype.join"),o=i("Array.prototype.indexOf"),s=i("Array.prototype.splice"),f=i("Array.prototype.sort"),c=function(h,u){for(var p="",y=0;y<h;y+=1)p+=u;return p},l=function(d,h,u){return u};return Zn=function(h){var u=arguments.length>1?arguments[1]:void 0,p=u&&u.space||"";typeof p=="number"&&(p=c(p," "));var y=!!u&&typeof u.cycles=="boolean"&&u.cycles,w=u&&u.replacer?n(u.replacer):l;if(u&&typeof u.collapseEmpty<"u"&&typeof u.collapseEmpty!="boolean")throw new TypeError("`collapseEmpty` must be a boolean, if provided");var _=!!u&&u.collapseEmpty,m=typeof u=="function"?u:u&&u.cmp,x=m&&function(A){var O=m.length>2&&function(S){return A[S]};return function(b,S){return m({key:b,value:A[b]},{key:S,value:A[S]},O?{__proto__:null,get:O}:void 0)}},v=[];return function A(O,b,S,I){var k=p?`
15
- `+c(I,p):"",F=p?": ":":";if(S&&S.toJSON&&typeof S.toJSON=="function"&&(S=S.toJSON()),S=w(O,b,S),S!==void 0){if(typeof S!="object"||S===null)return e(S);var Z=function(He,St){return _&&He.length===0?St:(St==="[]"?"[":"{")+a(He,",")+k+(St==="[]"?"]":"}")};if(t(S)){for(var Y=[],V=0;V<S.length;V++){var re=A(S,V,S[V],I+1)||e(null);Y[Y.length]=k+p+re}return Z(Y,"[]")}if(o(v,S)!==-1){if(y)return e("__cycle__");throw new TypeError("Converting circular structure to JSON")}else v[v.length]=S;for(var Ze=f(r(S),x&&x(S)),Y=[],V=0;V<Ze.length;V++){var b=Ze[V],fe=A(S,b,S[b],I+1);if(fe){var qe=e(b)+F+fe;Y[Y.length]=k+p+qe}}return s(v,o(v,S),1),Z(Y,"{}")}}({"":h},"",h,0)},Zn}var hl=ul(),vo=Pf(hl);async function qn(e,t,r){if(!this.passphrase)return t.push({actual:e,type:"encryptionKeyMissing"}),e;try{return await Kr(String(e),this.passphrase)}catch(n){t.push({actual:e,type:"encryptionProblem",error:n})}return e}async function dl(e,t,r){return Nr(e)?e:JSON.stringify(e)}class wo extends rf{constructor({options:t,passphrase:r,autoEncrypt:n=!0}={}){super(kt({},{useNewCustomCheckerFunction:!0,messages:{encryptionKeyMissing:"Missing configuration for secrets encryption.",encryptionProblem:"Problem encrypting secret. Actual: {actual}. Error: {error}"},defaults:{string:{trim:!0},object:{strict:"remove"}}},t)),this.passphrase=r,this.autoEncrypt=n,this.alias("secret",{type:"string",custom:this.autoEncrypt?qn:void 0,messages:{string:"The '{field}' field must be a string.",stringMin:"This secret '{field}' field length must be at least {expected} long."}}),this.alias("secretAny",{type:"any",custom:this.autoEncrypt?qn:void 0}),this.alias("secretNumber",{type:"number",custom:this.autoEncrypt?qn:void 0}),this.alias("json",{type:"any",custom:this.autoEncrypt?dl:void 0})}}const _o=new Proxy(wo,{instance:null,construct(e,t){return this.instance||(this.instance=new e(...t)),this.instance}});function pl(e){return e.toString(36)}function yl(e){const t={},r={};return e.forEach((n,i)=>{const a=pl(i);t[n]=a,r[a]=n}),{mapping:t,reversedMapping:r}}const Hn={trim:e=>e.trim(),encrypt:(e,{passphrase:t})=>Kr(e,t),decrypt:async(e,{passphrase:t})=>{try{return await da(e,t)}catch(r){return console.warn(`Schema decrypt error: ${r}`,r),e}},toString:e=>String(e),fromArray:(e,{separator:t})=>e==null||!Array.isArray(e)?e:e.length===0?"[]":e.map(n=>typeof n=="string"?n.replace(/\\/g,"\\\\").replace(new RegExp(`\\${t}`,"g"),`\\${t}`):String(n)).join(t),toArray:(e,{separator:t})=>{if(e==null)return e;if(e==="[]")return[];if(e==="")return[];const r=[];let n="",i=0;const a=String(e);for(;i<a.length;)a[i]==="\\"&&i+1<a.length?a[i+1]===t?(n+=t,i+=2):a[i+1]==="\\"?(n+="\\",i+=2):(n+=a[i],i++):a[i]===t?(r.push(n),n="",i++):(n+=a[i],i++);return r.push(n),r},toJSON:e=>JSON.stringify(e),fromJSON:e=>JSON.parse(e),toNumber:e=>Nr(e)?e.includes(".")?parseFloat(e):parseInt(e):e,toBool:e=>[!0,1,"true","1","yes","y"].includes(e),fromBool:e=>[!0,1,"true","1","yes","y"].includes(e)?"1":"0"};class _e{constructor(t){const{map:r,name:n,attributes:i,passphrase:a,version:o=1,options:s={}}=t;this.name=n,this.version=o,this.attributes=i||{},this.passphrase=a??"secret",this.options=kt({},this.defaultOptions(),s),this.allNestedObjectsOptional=this.options.allNestedObjectsOptional??!1;const f=this.preprocessAttributesForValidation(this.attributes);if(this.validator=new _o({autoEncrypt:!1}).compile(kt({$$async:!0},f)),this.options.generateAutoHooks&&this.generateAutoHooks(),!Hi(r))this.map=r,this.reversedMap=qc(r);else{const c=$r(this.attributes,{safe:!0}),l=Object.keys(c).filter(y=>!y.includes("$$")),d=this.extractObjectKeys(this.attributes),h=[...new Set([...l,...d])],{mapping:u,reversedMapping:p}=yl(h);this.map=u,this.reversedMap=p}}defaultOptions(){return{autoEncrypt:!0,autoDecrypt:!0,arraySeparator:"|",generateAutoHooks:!0,hooks:{beforeMap:{},afterMap:{},beforeUnmap:{},afterUnmap:{}}}}addHook(t,r,n){this.options.hooks[t][r]||(this.options.hooks[t][r]=[]),this.options.hooks[t][r]=Hc([...this.options.hooks[t][r],n])}extractObjectKeys(t,r=""){const n=[];for(const[i,a]of Object.entries(t)){if(i.startsWith("$$"))continue;const o=r?`${r}.${i}`:i;typeof a=="object"&&a!==null&&!Array.isArray(a)&&(n.push(o),a.$$type==="object"&&n.push(...this.extractObjectKeys(a,o)))}return n}generateAutoHooks(){const t=$r(Rt(this.attributes),{safe:!0});for(const[r,n]of Object.entries(t))n.includes("array")&&(this.addHook("beforeMap",r,"fromArray"),this.addHook("afterUnmap",r,"toArray")),n.includes("secret")&&(this.options.autoEncrypt&&this.addHook("beforeMap",r,"encrypt"),this.options.autoDecrypt&&this.addHook("afterUnmap",r,"decrypt")),n.includes("number")&&(this.addHook("beforeMap",r,"toString"),this.addHook("afterUnmap",r,"toNumber")),n.includes("boolean")&&(this.addHook("beforeMap",r,"fromBool"),this.addHook("afterUnmap",r,"toBool")),n.includes("json")&&(this.addHook("beforeMap",r,"toJSON"),this.addHook("afterUnmap",r,"fromJSON"))}static import(t){let{map:r,name:n,options:i,version:a,attributes:o}=Nr(t)?JSON.parse(t):t;return o=_e._importAttributes(o),new _e({map:r,name:n,options:i,version:a,attributes:o})}static _importAttributes(t){if(typeof t=="string"){try{const r=JSON.parse(t);if(typeof r=="object"&&r!==null)return _e._importAttributes(r)}catch{}return t}if(Array.isArray(t))return t.map(r=>_e._importAttributes(r));if(typeof t=="object"&&t!==null){const r={};for(const[n,i]of Object.entries(t))r[n]=_e._importAttributes(i);return r}return t}export(){return{version:this.version,name:this.name,options:this.options,attributes:this._exportAttributes(this.attributes),map:this.map}}_exportAttributes(t){if(typeof t=="string")return t;if(Array.isArray(t))return t.map(r=>this._exportAttributes(r));if(typeof t=="object"&&t!==null){const r={};for(const[n,i]of Object.entries(t))r[n]=this._exportAttributes(i);return r}return t}async applyHooksActions(t,r){for(const[n,i]of Object.entries(this.options.hooks[r]))for(const a of i){const o=Kc(t,n);o!==void 0&&typeof Hn[a]=="function"&&Wc(t,n,await Hn[a](o,{passphrase:this.passphrase,separator:this.options.arraySeparator}))}}async validate(t,{mutateOriginal:r=!1}={}){let n=r?t:Rt(t);return await this.validator(n)}async mapper(t){const r=$r(Rt(t),{safe:!0});await this.applyHooksActions(r,"beforeMap");const n={_v:this.version+""};for(const[i,a]of Object.entries(r))n[this.map[i]]=a;return await this.applyHooksActions(n,"afterMap"),n}async unmapper(t){const r=Rt(t);delete r._v,await this.applyHooksActions(r,"beforeUnmap");const n={};for(const[i,a]of Object.entries(r))n[this.reversedMap[i]]=a;return await this.applyHooksActions(n,"afterUnmap"),tf(n)}preprocessAttributesForValidation(t){const r={};for(const[n,i]of Object.entries(t))if(typeof i=="object"&&i!==null&&!Array.isArray(i)){const a=i.$$type&&i.$$type.includes("required"),o=i.$$type&&i.$$type.includes("optional"),s={type:"object",properties:this.preprocessAttributesForValidation(i),strict:!1};a||(o||this.allNestedObjectsOptional)&&(s.optional=!0),r[n]=s}else r[n]=i;return r}}var ht=typeof global<"u"?global:typeof self<"u"?self:typeof window<"u"?window:{},pe=[],ie=[],gl=typeof Uint8Array<"u"?Uint8Array:Array,Kn=!1;function bo(){Kn=!0;for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",t=0,r=e.length;t<r;++t)pe[t]=e[t],ie[e.charCodeAt(t)]=t;ie[45]=62,ie[95]=63}function vl(e){Kn||bo();var t,r,n,i,a,o,s=e.length;if(s%4>0)throw new Error("Invalid string. Length must be a multiple of 4");a=e[s-2]==="="?2:e[s-1]==="="?1:0,o=new gl(s*3/4-a),n=a>0?s-4:s;var f=0;for(t=0,r=0;t<n;t+=4,r+=3)i=ie[e.charCodeAt(t)]<<18|ie[e.charCodeAt(t+1)]<<12|ie[e.charCodeAt(t+2)]<<6|ie[e.charCodeAt(t+3)],o[f++]=i>>16&255,o[f++]=i>>8&255,o[f++]=i&255;return a===2?(i=ie[e.charCodeAt(t)]<<2|ie[e.charCodeAt(t+1)]>>4,o[f++]=i&255):a===1&&(i=ie[e.charCodeAt(t)]<<10|ie[e.charCodeAt(t+1)]<<4|ie[e.charCodeAt(t+2)]>>2,o[f++]=i>>8&255,o[f++]=i&255),o}function wl(e){return pe[e>>18&63]+pe[e>>12&63]+pe[e>>6&63]+pe[e&63]}function _l(e,t,r){for(var n,i=[],a=t;a<r;a+=3)n=(e[a]<<16)+(e[a+1]<<8)+e[a+2],i.push(wl(n));return i.join("")}function mo(e){Kn||bo();for(var t,r=e.length,n=r%3,i="",a=[],o=16383,s=0,f=r-n;s<f;s+=o)a.push(_l(e,s,s+o>f?f:s+o));return n===1?(t=e[r-1],i+=pe[t>>2],i+=pe[t<<4&63],i+="=="):n===2&&(t=(e[r-2]<<8)+e[r-1],i+=pe[t>>10],i+=pe[t>>4&63],i+=pe[t<<2&63],i+="="),a.push(i),a.join("")}function cr(e,t,r,n,i){var a,o,s=i*8-n-1,f=(1<<s)-1,c=f>>1,l=-7,d=r?i-1:0,h=r?-1:1,u=e[t+d];for(d+=h,a=u&(1<<-l)-1,u>>=-l,l+=s;l>0;a=a*256+e[t+d],d+=h,l-=8);for(o=a&(1<<-l)-1,a>>=-l,l+=n;l>0;o=o*256+e[t+d],d+=h,l-=8);if(a===0)a=1-c;else{if(a===f)return o?NaN:(u?-1:1)*(1/0);o=o+Math.pow(2,n),a=a-c}return(u?-1:1)*o*Math.pow(2,a-n)}function xo(e,t,r,n,i,a){var o,s,f,c=a*8-i-1,l=(1<<c)-1,d=l>>1,h=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,u=n?0:a-1,p=n?1:-1,y=t<0||t===0&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(s=isNaN(t)?1:0,o=l):(o=Math.floor(Math.log(t)/Math.LN2),t*(f=Math.pow(2,-o))<1&&(o--,f*=2),o+d>=1?t+=h/f:t+=h*Math.pow(2,1-d),t*f>=2&&(o++,f/=2),o+d>=l?(s=0,o=l):o+d>=1?(s=(t*f-1)*Math.pow(2,i),o=o+d):(s=t*Math.pow(2,d-1)*Math.pow(2,i),o=0));i>=8;e[r+u]=s&255,u+=p,s/=256,i-=8);for(o=o<<i|s,c+=i;c>0;e[r+u]=o&255,u+=p,o/=256,c-=8);e[r+u-p]|=y*128}var bl={}.toString,Eo=Array.isArray||function(e){return bl.call(e)=="[object Array]"};/*!
14
+ `+u+"}":"{"+p.join(",")+"}",t=u,h}}return Gr=function(s,f,c){var l;if(t="",r="",typeof c=="number")for(l=0;l<c;l+=1)r+=" ";else typeof c=="string"&&(r=c);if(i=f,f&&typeof f!="function"&&(typeof f!="object"||typeof f.length!="number"))throw new Error("JSON.stringify");return o("",{"":s})},Gr}var wa;function Df(){return wa||(wa=1,ir.parse=Ff(),ir.stringify=Cf()),ir}var Yr,ba;function Mf(){if(ba)return Yr;ba=1;var e={}.toString;return Yr=Array.isArray||function(t){return e.call(t)=="[object Array]"},Yr}var Jr,_a;function ma(){if(_a)return Jr;_a=1;var e=Object.prototype.toString;return Jr=function(r){var n=e.call(r),i=n==="[object Arguments]";return i||(i=n!=="[object Array]"&&r!==null&&typeof r=="object"&&typeof r.length=="number"&&r.length>=0&&e.call(r.callee)==="[object Function]"),i},Jr}var Xr,xa;function Nf(){if(xa)return Xr;xa=1;var e;if(!Object.keys){var t=Object.prototype.hasOwnProperty,r=Object.prototype.toString,n=ma(),i=Object.prototype.propertyIsEnumerable,a=!i.call({toString:null},"toString"),o=i.call(function(){},"prototype"),s=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"],f=function(d){var u=d.constructor;return u&&u.prototype===d},c={$applicationCache:!0,$console:!0,$external:!0,$frame:!0,$frameElement:!0,$frames:!0,$innerHeight:!0,$innerWidth:!0,$onmozfullscreenchange:!0,$onmozfullscreenerror:!0,$outerHeight:!0,$outerWidth:!0,$pageXOffset:!0,$pageYOffset:!0,$parent:!0,$scrollLeft:!0,$scrollTop:!0,$scrollX:!0,$scrollY:!0,$self:!0,$webkitIndexedDB:!0,$webkitStorageInfo:!0,$window:!0},l=function(){if(typeof window>"u")return!1;for(var d in window)try{if(!c["$"+d]&&t.call(window,d)&&window[d]!==null&&typeof window[d]=="object")try{f(window[d])}catch{return!0}}catch{return!0}return!1}(),h=function(d){if(typeof window>"u"||!l)return f(d);try{return f(d)}catch{return!1}};e=function(u){var p=u!==null&&typeof u=="object",y=r.call(u)==="[object Function]",w=n(u),b=p&&r.call(u)==="[object String]",m=[];if(!p&&!y&&!w)throw new TypeError("Object.keys called on a non-object");var x=o&&y;if(b&&u.length>0&&!t.call(u,0))for(var v=0;v<u.length;++v)m.push(String(v));if(w&&u.length>0)for(var S=0;S<u.length;++S)m.push(String(S));else for(var O in u)!(x&&O==="prototype")&&t.call(u,O)&&m.push(String(O));if(a)for(var _=h(u),A=0;A<s.length;++A)!(_&&s[A]==="constructor")&&t.call(u,s[A])&&m.push(s[A]);return m}}return Xr=e,Xr}var Qr,Ea;function Lf(){if(Ea)return Qr;Ea=1;var e=Array.prototype.slice,t=ma(),r=Object.keys,n=r?function(o){return r(o)}:Nf(),i=Object.keys;return n.shim=function(){if(Object.keys){var o=function(){var s=Object.keys(arguments);return s&&s.length===arguments.length}(1,2);o||(Object.keys=function(f){return t(f)?i(e.call(f)):i(f)})}else Object.keys=n;return Object.keys||n},Qr=n,Qr}var en={exports:{}},tn,Sa;function Aa(){return Sa||(Sa=1,tn=Object),tn}var rn,ka;function $f(){return ka||(ka=1,rn=Error),rn}var nn,Ra;function Uf(){return Ra||(Ra=1,nn=EvalError),nn}var an,Oa;function Bf(){return Oa||(Oa=1,an=RangeError),an}var on,Ia;function zf(){return Ia||(Ia=1,on=ReferenceError),on}var sn,Ta;function Pa(){return Ta||(Ta=1,sn=SyntaxError),sn}var cn,ja;function ar(){return ja||(ja=1,cn=TypeError),cn}var fn,Fa;function Zf(){return Fa||(Fa=1,fn=URIError),fn}var ln,Ca;function qf(){return Ca||(Ca=1,ln=Math.abs),ln}var un,Da;function Hf(){return Da||(Da=1,un=Math.floor),un}var hn,Ma;function Kf(){return Ma||(Ma=1,hn=Math.max),hn}var dn,Na;function Wf(){return Na||(Na=1,dn=Math.min),dn}var pn,La;function Vf(){return La||(La=1,pn=Math.pow),pn}var yn,$a;function Gf(){return $a||($a=1,yn=Math.round),yn}var gn,Ua;function Yf(){return Ua||(Ua=1,gn=Number.isNaN||function(t){return t!==t}),gn}var vn,Ba;function Jf(){if(Ba)return vn;Ba=1;var e=Yf();return vn=function(r){return e(r)||r===0?r:r<0?-1:1},vn}var wn,za;function Xf(){return za||(za=1,wn=Object.getOwnPropertyDescriptor),wn}var bn,Za;function or(){if(Za)return bn;Za=1;var e=Xf();if(e)try{e([],"length")}catch{e=null}return bn=e,bn}var _n,qa;function sr(){if(qa)return _n;qa=1;var e=Object.defineProperty||!1;if(e)try{e({},"a",{value:1})}catch{e=!1}return _n=e,_n}var mn,Ha;function Qf(){return Ha||(Ha=1,mn=function(){if(typeof Symbol!="function"||typeof Object.getOwnPropertySymbols!="function")return!1;if(typeof Symbol.iterator=="symbol")return!0;var t={},r=Symbol("test"),n=Object(r);if(typeof r=="string"||Object.prototype.toString.call(r)!=="[object Symbol]"||Object.prototype.toString.call(n)!=="[object Symbol]")return!1;var i=42;t[r]=i;for(var a in t)return!1;if(typeof Object.keys=="function"&&Object.keys(t).length!==0||typeof Object.getOwnPropertyNames=="function"&&Object.getOwnPropertyNames(t).length!==0)return!1;var o=Object.getOwnPropertySymbols(t);if(o.length!==1||o[0]!==r||!Object.prototype.propertyIsEnumerable.call(t,r))return!1;if(typeof Object.getOwnPropertyDescriptor=="function"){var s=Object.getOwnPropertyDescriptor(t,r);if(s.value!==i||s.enumerable!==!0)return!1}return!0}),mn}var xn,Ka;function el(){if(Ka)return xn;Ka=1;var e=typeof Symbol<"u"&&Symbol,t=Qf();return xn=function(){return typeof e!="function"||typeof Symbol!="function"||typeof e("foo")!="symbol"||typeof Symbol("bar")!="symbol"?!1:t()},xn}var En,Wa;function Va(){return Wa||(Wa=1,En=typeof Reflect<"u"&&Reflect.getPrototypeOf||null),En}var Sn,Ga;function Ya(){if(Ga)return Sn;Ga=1;var e=Aa();return Sn=e.getPrototypeOf||null,Sn}var An,Ja;function tl(){if(Ja)return An;Ja=1;var e="Function.prototype.bind called on incompatible ",t=Object.prototype.toString,r=Math.max,n="[object Function]",i=function(f,c){for(var l=[],h=0;h<f.length;h+=1)l[h]=f[h];for(var d=0;d<c.length;d+=1)l[d+f.length]=c[d];return l},a=function(f,c){for(var l=[],h=c,d=0;h<f.length;h+=1,d+=1)l[d]=f[h];return l},o=function(s,f){for(var c="",l=0;l<s.length;l+=1)c+=s[l],l+1<s.length&&(c+=f);return c};return An=function(f){var c=this;if(typeof c!="function"||t.apply(c)!==n)throw new TypeError(e+c);for(var l=a(arguments,1),h,d=function(){if(this instanceof h){var b=c.apply(this,i(l,arguments));return Object(b)===b?b:this}return c.apply(f,i(l,arguments))},u=r(0,c.length-l.length),p=[],y=0;y<u;y++)p[y]="$"+y;if(h=Function("binder","return function ("+o(p,",")+"){ return binder.apply(this,arguments); }")(d),c.prototype){var w=function(){};w.prototype=c.prototype,h.prototype=new w,w.prototype=null}return h},An}var kn,Xa;function It(){if(Xa)return kn;Xa=1;var e=tl();return kn=Function.prototype.bind||e,kn}var Rn,Qa;function On(){return Qa||(Qa=1,Rn=Function.prototype.call),Rn}var In,eo;function Tn(){return eo||(eo=1,In=Function.prototype.apply),In}var Pn,to;function rl(){return to||(to=1,Pn=typeof Reflect<"u"&&Reflect&&Reflect.apply),Pn}var jn,ro;function no(){if(ro)return jn;ro=1;var e=It(),t=Tn(),r=On(),n=rl();return jn=n||e.call(r,t),jn}var Fn,io;function Cn(){if(io)return Fn;io=1;var e=It(),t=ar(),r=On(),n=no();return Fn=function(a){if(a.length<1||typeof a[0]!="function")throw new t("a function is required");return n(e,r,a)},Fn}var Dn,ao;function nl(){if(ao)return Dn;ao=1;var e=Cn(),t=or(),r;try{r=[].__proto__===Array.prototype}catch(o){if(!o||typeof o!="object"||!("code"in o)||o.code!=="ERR_PROTO_ACCESS")throw o}var n=!!r&&t&&t(Object.prototype,"__proto__"),i=Object,a=i.getPrototypeOf;return Dn=n&&typeof n.get=="function"?e([n.get]):typeof a=="function"?function(s){return a(s==null?s:i(s))}:!1,Dn}var Mn,oo;function il(){if(oo)return Mn;oo=1;var e=Va(),t=Ya(),r=nl();return Mn=e?function(i){return e(i)}:t?function(i){if(!i||typeof i!="object"&&typeof i!="function")throw new TypeError("getProto: not an object");return t(i)}:r?function(i){return r(i)}:null,Mn}var Nn,so;function al(){if(so)return Nn;so=1;var e=Function.prototype.call,t=Object.prototype.hasOwnProperty,r=It();return Nn=r.call(e,t),Nn}var Ln,co;function fo(){if(co)return Ln;co=1;var e,t=Aa(),r=$f(),n=Uf(),i=Bf(),a=zf(),o=Pa(),s=ar(),f=Zf(),c=qf(),l=Hf(),h=Kf(),d=Wf(),u=Vf(),p=Gf(),y=Jf(),w=Function,b=function(le){try{return w('"use strict"; return ('+le+").constructor;")()}catch{}},m=or(),x=sr(),v=function(){throw new s},S=m?function(){try{return arguments.callee,v}catch{try{return m(arguments,"callee").get}catch{return v}}}():v,O=el()(),_=il(),A=Ya(),I=Va(),k=Tn(),F=On(),Z={},V=typeof Uint8Array>"u"||!_?e:_(Uint8Array),re={__proto__:null,"%AggregateError%":typeof AggregateError>"u"?e:AggregateError,"%Array%":Array,"%ArrayBuffer%":typeof ArrayBuffer>"u"?e:ArrayBuffer,"%ArrayIteratorPrototype%":O&&_?_([][Symbol.iterator]()):e,"%AsyncFromSyncIteratorPrototype%":e,"%AsyncFunction%":Z,"%AsyncGenerator%":Z,"%AsyncGeneratorFunction%":Z,"%AsyncIteratorPrototype%":Z,"%Atomics%":typeof Atomics>"u"?e:Atomics,"%BigInt%":typeof BigInt>"u"?e:BigInt,"%BigInt64Array%":typeof BigInt64Array>"u"?e:BigInt64Array,"%BigUint64Array%":typeof BigUint64Array>"u"?e:BigUint64Array,"%Boolean%":Boolean,"%DataView%":typeof DataView>"u"?e:DataView,"%Date%":Date,"%decodeURI%":decodeURI,"%decodeURIComponent%":decodeURIComponent,"%encodeURI%":encodeURI,"%encodeURIComponent%":encodeURIComponent,"%Error%":r,"%eval%":eval,"%EvalError%":n,"%Float16Array%":typeof Float16Array>"u"?e:Float16Array,"%Float32Array%":typeof Float32Array>"u"?e:Float32Array,"%Float64Array%":typeof Float64Array>"u"?e:Float64Array,"%FinalizationRegistry%":typeof FinalizationRegistry>"u"?e:FinalizationRegistry,"%Function%":w,"%GeneratorFunction%":Z,"%Int8Array%":typeof Int8Array>"u"?e:Int8Array,"%Int16Array%":typeof Int16Array>"u"?e:Int16Array,"%Int32Array%":typeof Int32Array>"u"?e:Int32Array,"%isFinite%":isFinite,"%isNaN%":isNaN,"%IteratorPrototype%":O&&_?_(_([][Symbol.iterator]())):e,"%JSON%":typeof JSON=="object"?JSON:e,"%Map%":typeof Map>"u"?e:Map,"%MapIteratorPrototype%":typeof Map>"u"||!O||!_?e:_(new Map()[Symbol.iterator]()),"%Math%":Math,"%Number%":Number,"%Object%":t,"%Object.getOwnPropertyDescriptor%":m,"%parseFloat%":parseFloat,"%parseInt%":parseInt,"%Promise%":typeof Promise>"u"?e:Promise,"%Proxy%":typeof Proxy>"u"?e:Proxy,"%RangeError%":i,"%ReferenceError%":a,"%Reflect%":typeof Reflect>"u"?e:Reflect,"%RegExp%":RegExp,"%Set%":typeof Set>"u"?e:Set,"%SetIteratorPrototype%":typeof Set>"u"||!O||!_?e:_(new Set()[Symbol.iterator]()),"%SharedArrayBuffer%":typeof SharedArrayBuffer>"u"?e:SharedArrayBuffer,"%String%":String,"%StringIteratorPrototype%":O&&_?_(""[Symbol.iterator]()):e,"%Symbol%":O?Symbol:e,"%SyntaxError%":o,"%ThrowTypeError%":S,"%TypedArray%":V,"%TypeError%":s,"%Uint8Array%":typeof Uint8Array>"u"?e:Uint8Array,"%Uint8ClampedArray%":typeof Uint8ClampedArray>"u"?e:Uint8ClampedArray,"%Uint16Array%":typeof Uint16Array>"u"?e:Uint16Array,"%Uint32Array%":typeof Uint32Array>"u"?e:Uint32Array,"%URIError%":f,"%WeakMap%":typeof WeakMap>"u"?e:WeakMap,"%WeakRef%":typeof WeakRef>"u"?e:WeakRef,"%WeakSet%":typeof WeakSet>"u"?e:WeakSet,"%Function.prototype.call%":F,"%Function.prototype.apply%":k,"%Object.defineProperty%":x,"%Object.getPrototypeOf%":A,"%Math.abs%":c,"%Math.floor%":l,"%Math.max%":h,"%Math.min%":d,"%Math.pow%":u,"%Math.round%":p,"%Math.sign%":y,"%Reflect.getPrototypeOf%":I};if(_)try{null.error}catch(le){var Ze=_(_(le));re["%Error.prototype%"]=Ze}var Y=function le(M){var K;if(M==="%AsyncFunction%")K=b("async function () {}");else if(M==="%GeneratorFunction%")K=b("function* () {}");else if(M==="%AsyncGeneratorFunction%")K=b("async function* () {}");else if(M==="%AsyncGenerator%"){var L=le("%AsyncGeneratorFunction%");L&&(K=L.prototype)}else if(M==="%AsyncIteratorPrototype%"){var G=le("%AsyncGenerator%");G&&_&&(K=_(G.prototype))}return re[M]=K,K},fe={__proto__:null,"%ArrayBufferPrototype%":["ArrayBuffer","prototype"],"%ArrayPrototype%":["Array","prototype"],"%ArrayProto_entries%":["Array","prototype","entries"],"%ArrayProto_forEach%":["Array","prototype","forEach"],"%ArrayProto_keys%":["Array","prototype","keys"],"%ArrayProto_values%":["Array","prototype","values"],"%AsyncFunctionPrototype%":["AsyncFunction","prototype"],"%AsyncGenerator%":["AsyncGeneratorFunction","prototype"],"%AsyncGeneratorPrototype%":["AsyncGeneratorFunction","prototype","prototype"],"%BooleanPrototype%":["Boolean","prototype"],"%DataViewPrototype%":["DataView","prototype"],"%DatePrototype%":["Date","prototype"],"%ErrorPrototype%":["Error","prototype"],"%EvalErrorPrototype%":["EvalError","prototype"],"%Float32ArrayPrototype%":["Float32Array","prototype"],"%Float64ArrayPrototype%":["Float64Array","prototype"],"%FunctionPrototype%":["Function","prototype"],"%Generator%":["GeneratorFunction","prototype"],"%GeneratorPrototype%":["GeneratorFunction","prototype","prototype"],"%Int8ArrayPrototype%":["Int8Array","prototype"],"%Int16ArrayPrototype%":["Int16Array","prototype"],"%Int32ArrayPrototype%":["Int32Array","prototype"],"%JSONParse%":["JSON","parse"],"%JSONStringify%":["JSON","stringify"],"%MapPrototype%":["Map","prototype"],"%NumberPrototype%":["Number","prototype"],"%ObjectPrototype%":["Object","prototype"],"%ObjProto_toString%":["Object","prototype","toString"],"%ObjProto_valueOf%":["Object","prototype","valueOf"],"%PromisePrototype%":["Promise","prototype"],"%PromiseProto_then%":["Promise","prototype","then"],"%Promise_all%":["Promise","all"],"%Promise_reject%":["Promise","reject"],"%Promise_resolve%":["Promise","resolve"],"%RangeErrorPrototype%":["RangeError","prototype"],"%ReferenceErrorPrototype%":["ReferenceError","prototype"],"%RegExpPrototype%":["RegExp","prototype"],"%SetPrototype%":["Set","prototype"],"%SharedArrayBufferPrototype%":["SharedArrayBuffer","prototype"],"%StringPrototype%":["String","prototype"],"%SymbolPrototype%":["Symbol","prototype"],"%SyntaxErrorPrototype%":["SyntaxError","prototype"],"%TypedArrayPrototype%":["TypedArray","prototype"],"%TypeErrorPrototype%":["TypeError","prototype"],"%Uint8ArrayPrototype%":["Uint8Array","prototype"],"%Uint8ClampedArrayPrototype%":["Uint8ClampedArray","prototype"],"%Uint16ArrayPrototype%":["Uint16Array","prototype"],"%Uint32ArrayPrototype%":["Uint32Array","prototype"],"%URIErrorPrototype%":["URIError","prototype"],"%WeakMapPrototype%":["WeakMap","prototype"],"%WeakSetPrototype%":["WeakSet","prototype"]},qe=It(),He=al(),St=qe.call(F,Array.prototype.concat),$c=qe.call(k,Array.prototype.splice),Zi=qe.call(F,String.prototype.replace),Yt=qe.call(F,String.prototype.slice),Uc=qe.call(F,RegExp.prototype.exec),Bc=/[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g,zc=/\\(\\)?/g,Zc=function(M){var K=Yt(M,0,1),L=Yt(M,-1);if(K==="%"&&L!=="%")throw new o("invalid intrinsic syntax, expected closing `%`");if(L==="%"&&K!=="%")throw new o("invalid intrinsic syntax, expected opening `%`");var G=[];return Zi(M,Bc,function(ue,ut,J,Jt){G[G.length]=J?Zi(Jt,zc,"$1"):ut||ue}),G},qc=function(M,K){var L=M,G;if(He(fe,L)&&(G=fe[L],L="%"+G[0]+"%"),He(re,L)){var ue=re[L];if(ue===Z&&(ue=Y(L)),typeof ue>"u"&&!K)throw new s("intrinsic "+M+" exists, but is not available. Please file an issue!");return{alias:G,name:L,value:ue}}throw new o("intrinsic "+M+" does not exist!")};return Ln=function(M,K){if(typeof M!="string"||M.length===0)throw new s("intrinsic name must be a non-empty string");if(arguments.length>1&&typeof K!="boolean")throw new s('"allowMissing" argument must be a boolean');if(Uc(/^%?[^%]*%?$/,M)===null)throw new o("`%` may not be present anywhere but at the beginning and end of the intrinsic name");var L=Zc(M),G=L.length>0?L[0]:"",ue=qc("%"+G+"%",K),ut=ue.name,J=ue.value,Jt=!1,Nr=ue.alias;Nr&&(G=Nr[0],$c(L,St([0,1],Nr)));for(var Xt=1,At=!0;Xt<L.length;Xt+=1){var _e=L[Xt],Qt=Yt(_e,0,1),er=Yt(_e,-1);if((Qt==='"'||Qt==="'"||Qt==="`"||er==='"'||er==="'"||er==="`")&&Qt!==er)throw new o("property names with quotes must have matching quotes");if((_e==="constructor"||!At)&&(Jt=!0),G+="."+_e,ut="%"+G+"%",He(re,ut))J=re[ut];else if(J!=null){if(!(_e in J)){if(!K)throw new s("base intrinsic for "+M+" exists, but the property is not available.");return}if(m&&Xt+1>=L.length){var tr=m(J,_e);At=!!tr,At&&"get"in tr&&!("originalValue"in tr.get)?J=tr.get:J=J[_e]}else At=He(J,_e),J=J[_e];At&&!Jt&&(re[ut]=J)}}return J},Ln}var $n,lo;function ol(){if(lo)return $n;lo=1;var e=sr(),t=Pa(),r=ar(),n=or();return $n=function(a,o,s){if(!a||typeof a!="object"&&typeof a!="function")throw new r("`obj` must be an object or a function`");if(typeof o!="string"&&typeof o!="symbol")throw new r("`property` must be a string or a symbol`");if(arguments.length>3&&typeof arguments[3]!="boolean"&&arguments[3]!==null)throw new r("`nonEnumerable`, if provided, must be a boolean or null");if(arguments.length>4&&typeof arguments[4]!="boolean"&&arguments[4]!==null)throw new r("`nonWritable`, if provided, must be a boolean or null");if(arguments.length>5&&typeof arguments[5]!="boolean"&&arguments[5]!==null)throw new r("`nonConfigurable`, if provided, must be a boolean or null");if(arguments.length>6&&typeof arguments[6]!="boolean")throw new r("`loose`, if provided, must be a boolean");var f=arguments.length>3?arguments[3]:null,c=arguments.length>4?arguments[4]:null,l=arguments.length>5?arguments[5]:null,h=arguments.length>6?arguments[6]:!1,d=!!n&&n(a,o);if(e)e(a,o,{configurable:l===null&&d?d.configurable:!l,enumerable:f===null&&d?d.enumerable:!f,value:s,writable:c===null&&d?d.writable:!c});else if(h||!f&&!c&&!l)a[o]=s;else throw new t("This environment does not support defining a property as non-configurable, non-writable, or non-enumerable.")},$n}var Un,uo;function sl(){if(uo)return Un;uo=1;var e=sr(),t=function(){return!!e};return t.hasArrayLengthDefineBug=function(){if(!e)return null;try{return e([],"length",{value:1}).length!==1}catch{return!0}},Un=t,Un}var Bn,ho;function cl(){if(ho)return Bn;ho=1;var e=fo(),t=ol(),r=sl()(),n=or(),i=ar(),a=e("%Math.floor%");return Bn=function(s,f){if(typeof s!="function")throw new i("`fn` is not a function");if(typeof f!="number"||f<0||f>4294967295||a(f)!==f)throw new i("`length` must be a positive 32-bit integer");var c=arguments.length>2&&!!arguments[2],l=!0,h=!0;if("length"in s&&n){var d=n(s,"length");d&&!d.configurable&&(l=!1),d&&!d.writable&&(h=!1)}return(l||h||!c)&&(r?t(s,"length",f,!0,!0):t(s,"length",f)),s},Bn}var zn,po;function fl(){if(po)return zn;po=1;var e=It(),t=Tn(),r=no();return zn=function(){return r(e,t,arguments)},zn}var yo;function ll(){return yo||(yo=1,function(e){var t=cl(),r=sr(),n=Cn(),i=fl();e.exports=function(o){var s=n(arguments),f=o.length-(arguments.length-1);return t(s,1+(f>0?f:0),!0)},r?r(e.exports,"apply",{value:i}):e.exports.apply=i}(en)),en.exports}var Zn,go;function ul(){if(go)return Zn;go=1;var e=fo(),t=Cn(),r=t([e("%String.prototype.indexOf%")]);return Zn=function(i,a){var o=e(i,!!a);return typeof o=="function"&&r(i,".prototype.")>-1?t([o]):o},Zn}var qn,vo;function hl(){if(vo)return qn;vo=1;var e=(typeof JSON<"u"?JSON:Df()).stringify,t=Mf(),r=Lf(),n=ll(),i=ul(),a=i("Array.prototype.join"),o=i("Array.prototype.indexOf"),s=i("Array.prototype.splice"),f=i("Array.prototype.sort"),c=function(d,u){for(var p="",y=0;y<d;y+=1)p+=u;return p},l=function(h,d,u){return u};return qn=function(d){var u=arguments.length>1?arguments[1]:void 0,p=u&&u.space||"";typeof p=="number"&&(p=c(p," "));var y=!!u&&typeof u.cycles=="boolean"&&u.cycles,w=u&&u.replacer?n(u.replacer):l;if(u&&typeof u.collapseEmpty<"u"&&typeof u.collapseEmpty!="boolean")throw new TypeError("`collapseEmpty` must be a boolean, if provided");var b=!!u&&u.collapseEmpty,m=typeof u=="function"?u:u&&u.cmp,x=m&&function(S){var O=m.length>2&&function(A){return S[A]};return function(_,A){return m({key:_,value:S[_]},{key:A,value:S[A]},O?{__proto__:null,get:O}:void 0)}},v=[];return function S(O,_,A,I){var k=p?`
15
+ `+c(I,p):"",F=p?": ":":";if(A&&A.toJSON&&typeof A.toJSON=="function"&&(A=A.toJSON()),A=w(O,_,A),A!==void 0){if(typeof A!="object"||A===null)return e(A);var Z=function(He,St){return b&&He.length===0?St:(St==="[]"?"[":"{")+a(He,",")+k+(St==="[]"?"]":"}")};if(t(A)){for(var Y=[],V=0;V<A.length;V++){var re=S(A,V,A[V],I+1)||e(null);Y[Y.length]=k+p+re}return Z(Y,"[]")}if(o(v,A)!==-1){if(y)return e("__cycle__");throw new TypeError("Converting circular structure to JSON")}else v[v.length]=A;for(var Ze=f(r(A),x&&x(A)),Y=[],V=0;V<Ze.length;V++){var _=Ze[V],fe=S(A,_,A[_],I+1);if(fe){var qe=e(_)+F+fe;Y[Y.length]=k+p+qe}}return s(v,o(v,A),1),Z(Y,"{}")}}({"":d},"",d,0)},qn}var dl=hl(),wo=jf(dl);async function Hn(e,t,r){if(!this.passphrase)return t.push({actual:e,type:"encryptionKeyMissing"}),e;try{return await Wr(String(e),this.passphrase)}catch(n){t.push({actual:e,type:"encryptionProblem",error:n})}return e}async function pl(e,t,r){return $r(e)?e:JSON.stringify(e)}class bo extends nf{constructor({options:t,passphrase:r,autoEncrypt:n=!0}={}){super(kt({},{useNewCustomCheckerFunction:!0,messages:{encryptionKeyMissing:"Missing configuration for secrets encryption.",encryptionProblem:"Problem encrypting secret. Actual: {actual}. Error: {error}"},defaults:{string:{trim:!0},object:{strict:"remove"}}},t)),this.passphrase=r,this.autoEncrypt=n,this.alias("secret",{type:"string",custom:this.autoEncrypt?Hn:void 0,messages:{string:"The '{field}' field must be a string.",stringMin:"This secret '{field}' field length must be at least {expected} long."}}),this.alias("secretAny",{type:"any",custom:this.autoEncrypt?Hn:void 0}),this.alias("secretNumber",{type:"number",custom:this.autoEncrypt?Hn:void 0}),this.alias("json",{type:"any",custom:this.autoEncrypt?pl:void 0})}}const _o=new Proxy(bo,{instance:null,construct(e,t){return this.instance||(this.instance=new e(...t)),this.instance}});function yl(e){return e.toString(36)}function gl(e){const t={},r={};return e.forEach((n,i)=>{const a=yl(i);t[n]=a,r[a]=n}),{mapping:t,reversedMapping:r}}const Kn={trim:e=>e.trim(),encrypt:(e,{passphrase:t})=>Wr(e,t),decrypt:async(e,{passphrase:t})=>{try{return await pa(e,t)}catch(r){return console.warn(`Schema decrypt error: ${r}`,r),e}},toString:e=>String(e),fromArray:(e,{separator:t})=>e==null||!Array.isArray(e)?e:e.length===0?"[]":e.map(n=>typeof n=="string"?n.replace(/\\/g,"\\\\").replace(new RegExp(`\\${t}`,"g"),`\\${t}`):String(n)).join(t),toArray:(e,{separator:t})=>{if(e==null)return e;if(e==="[]")return[];if(e==="")return[];const r=[];let n="",i=0;const a=String(e);for(;i<a.length;)a[i]==="\\"&&i+1<a.length?a[i+1]===t?(n+=t,i+=2):a[i+1]==="\\"?(n+="\\",i+=2):(n+=a[i],i++):a[i]===t?(r.push(n),n="",i++):(n+=a[i],i++);return r.push(n),r},toJSON:e=>JSON.stringify(e),fromJSON:e=>JSON.parse(e),toNumber:e=>$r(e)?e.includes(".")?parseFloat(e):parseInt(e):e,toBool:e=>[!0,1,"true","1","yes","y"].includes(e),fromBool:e=>[!0,1,"true","1","yes","y"].includes(e)?"1":"0"};class be{constructor(t){const{map:r,name:n,attributes:i,passphrase:a,version:o=1,options:s={}}=t;this.name=n,this.version=o,this.attributes=i||{},this.passphrase=a??"secret",this.options=kt({},this.defaultOptions(),s),this.allNestedObjectsOptional=this.options.allNestedObjectsOptional??!1;const f=this.preprocessAttributesForValidation(this.attributes);if(this.validator=new _o({autoEncrypt:!1}).compile(kt({$$async:!0},f)),this.options.generateAutoHooks&&this.generateAutoHooks(),!Ki(r))this.map=r,this.reversedMap=Hc(r);else{const c=Ur(this.attributes,{safe:!0}),l=Object.keys(c).filter(y=>!y.includes("$$")),h=this.extractObjectKeys(this.attributes),d=[...new Set([...l,...h])],{mapping:u,reversedMapping:p}=gl(d);this.map=u,this.reversedMap=p}}defaultOptions(){return{autoEncrypt:!0,autoDecrypt:!0,arraySeparator:"|",generateAutoHooks:!0,hooks:{beforeMap:{},afterMap:{},beforeUnmap:{},afterUnmap:{}}}}addHook(t,r,n){this.options.hooks[t][r]||(this.options.hooks[t][r]=[]),this.options.hooks[t][r]=Kc([...this.options.hooks[t][r],n])}extractObjectKeys(t,r=""){const n=[];for(const[i,a]of Object.entries(t)){if(i.startsWith("$$"))continue;const o=r?`${r}.${i}`:i;typeof a=="object"&&a!==null&&!Array.isArray(a)&&(n.push(o),a.$$type==="object"&&n.push(...this.extractObjectKeys(a,o)))}return n}generateAutoHooks(){const t=Ur(Rt(this.attributes),{safe:!0});for(const[r,n]of Object.entries(t))n.includes("array")&&(this.addHook("beforeMap",r,"fromArray"),this.addHook("afterUnmap",r,"toArray")),n.includes("secret")&&(this.options.autoEncrypt&&this.addHook("beforeMap",r,"encrypt"),this.options.autoDecrypt&&this.addHook("afterUnmap",r,"decrypt")),n.includes("number")&&(this.addHook("beforeMap",r,"toString"),this.addHook("afterUnmap",r,"toNumber")),n.includes("boolean")&&(this.addHook("beforeMap",r,"fromBool"),this.addHook("afterUnmap",r,"toBool")),n.includes("json")&&(this.addHook("beforeMap",r,"toJSON"),this.addHook("afterUnmap",r,"fromJSON"))}static import(t){let{map:r,name:n,options:i,version:a,attributes:o}=$r(t)?JSON.parse(t):t;return o=be._importAttributes(o),new be({map:r,name:n,options:i,version:a,attributes:o})}static _importAttributes(t){if(typeof t=="string"){try{const r=JSON.parse(t);if(typeof r=="object"&&r!==null)return be._importAttributes(r)}catch{}return t}if(Array.isArray(t))return t.map(r=>be._importAttributes(r));if(typeof t=="object"&&t!==null){const r={};for(const[n,i]of Object.entries(t))r[n]=be._importAttributes(i);return r}return t}export(){return{version:this.version,name:this.name,options:this.options,attributes:this._exportAttributes(this.attributes),map:this.map}}_exportAttributes(t){if(typeof t=="string")return t;if(Array.isArray(t))return t.map(r=>this._exportAttributes(r));if(typeof t=="object"&&t!==null){const r={};for(const[n,i]of Object.entries(t))r[n]=this._exportAttributes(i);return r}return t}async applyHooksActions(t,r){for(const[n,i]of Object.entries(this.options.hooks[r]))for(const a of i){const o=Wc(t,n);o!==void 0&&typeof Kn[a]=="function"&&Vc(t,n,await Kn[a](o,{passphrase:this.passphrase,separator:this.options.arraySeparator}))}}async validate(t,{mutateOriginal:r=!1}={}){let n=r?t:Rt(t);return await this.validator(n)}async mapper(t){const r=Ur(Rt(t),{safe:!0});await this.applyHooksActions(r,"beforeMap");const n={_v:this.version+""};for(const[i,a]of Object.entries(r))n[this.map[i]]=a;return await this.applyHooksActions(n,"afterMap"),n}async unmapper(t){const r=Rt(t);delete r._v,await this.applyHooksActions(r,"beforeUnmap");const n={};for(const[i,a]of Object.entries(r))n[this.reversedMap[i]]=a;return await this.applyHooksActions(n,"afterUnmap"),rf(n)}preprocessAttributesForValidation(t){const r={};for(const[n,i]of Object.entries(t))if(typeof i=="object"&&i!==null&&!Array.isArray(i)){const a=i.$$type&&i.$$type.includes("required"),o=i.$$type&&i.$$type.includes("optional"),s={type:"object",properties:this.preprocessAttributesForValidation(i),strict:!1};a||(o||this.allNestedObjectsOptional)&&(s.optional=!0),r[n]=s}else r[n]=i;return r}}var ht=typeof global<"u"?global:typeof self<"u"?self:typeof window<"u"?window:{},pe=[],ie=[],vl=typeof Uint8Array<"u"?Uint8Array:Array,Wn=!1;function mo(){Wn=!0;for(var e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",t=0,r=e.length;t<r;++t)pe[t]=e[t],ie[e.charCodeAt(t)]=t;ie[45]=62,ie[95]=63}function wl(e){Wn||mo();var t,r,n,i,a,o,s=e.length;if(s%4>0)throw new Error("Invalid string. Length must be a multiple of 4");a=e[s-2]==="="?2:e[s-1]==="="?1:0,o=new vl(s*3/4-a),n=a>0?s-4:s;var f=0;for(t=0,r=0;t<n;t+=4,r+=3)i=ie[e.charCodeAt(t)]<<18|ie[e.charCodeAt(t+1)]<<12|ie[e.charCodeAt(t+2)]<<6|ie[e.charCodeAt(t+3)],o[f++]=i>>16&255,o[f++]=i>>8&255,o[f++]=i&255;return a===2?(i=ie[e.charCodeAt(t)]<<2|ie[e.charCodeAt(t+1)]>>4,o[f++]=i&255):a===1&&(i=ie[e.charCodeAt(t)]<<10|ie[e.charCodeAt(t+1)]<<4|ie[e.charCodeAt(t+2)]>>2,o[f++]=i>>8&255,o[f++]=i&255),o}function bl(e){return pe[e>>18&63]+pe[e>>12&63]+pe[e>>6&63]+pe[e&63]}function _l(e,t,r){for(var n,i=[],a=t;a<r;a+=3)n=(e[a]<<16)+(e[a+1]<<8)+e[a+2],i.push(bl(n));return i.join("")}function xo(e){Wn||mo();for(var t,r=e.length,n=r%3,i="",a=[],o=16383,s=0,f=r-n;s<f;s+=o)a.push(_l(e,s,s+o>f?f:s+o));return n===1?(t=e[r-1],i+=pe[t>>2],i+=pe[t<<4&63],i+="=="):n===2&&(t=(e[r-2]<<8)+e[r-1],i+=pe[t>>10],i+=pe[t>>4&63],i+=pe[t<<2&63],i+="="),a.push(i),a.join("")}function cr(e,t,r,n,i){var a,o,s=i*8-n-1,f=(1<<s)-1,c=f>>1,l=-7,h=r?i-1:0,d=r?-1:1,u=e[t+h];for(h+=d,a=u&(1<<-l)-1,u>>=-l,l+=s;l>0;a=a*256+e[t+h],h+=d,l-=8);for(o=a&(1<<-l)-1,a>>=-l,l+=n;l>0;o=o*256+e[t+h],h+=d,l-=8);if(a===0)a=1-c;else{if(a===f)return o?NaN:(u?-1:1)*(1/0);o=o+Math.pow(2,n),a=a-c}return(u?-1:1)*o*Math.pow(2,a-n)}function Eo(e,t,r,n,i,a){var o,s,f,c=a*8-i-1,l=(1<<c)-1,h=l>>1,d=i===23?Math.pow(2,-24)-Math.pow(2,-77):0,u=n?0:a-1,p=n?1:-1,y=t<0||t===0&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(s=isNaN(t)?1:0,o=l):(o=Math.floor(Math.log(t)/Math.LN2),t*(f=Math.pow(2,-o))<1&&(o--,f*=2),o+h>=1?t+=d/f:t+=d*Math.pow(2,1-h),t*f>=2&&(o++,f/=2),o+h>=l?(s=0,o=l):o+h>=1?(s=(t*f-1)*Math.pow(2,i),o=o+h):(s=t*Math.pow(2,h-1)*Math.pow(2,i),o=0));i>=8;e[r+u]=s&255,u+=p,s/=256,i-=8);for(o=o<<i|s,c+=i;c>0;e[r+u]=o&255,u+=p,o/=256,c-=8);e[r+u-p]|=y*128}var ml={}.toString,So=Array.isArray||function(e){return ml.call(e)=="[object Array]"};/*!
16
16
  * The buffer module from node.js, for the browser.
17
17
  *
18
18
  * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
19
19
  * @license MIT
20
- */var ml=50;g.TYPED_ARRAY_SUPPORT=ht.TYPED_ARRAY_SUPPORT!==void 0?ht.TYPED_ARRAY_SUPPORT:!0,fr();function fr(){return g.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function xe(e,t){if(fr()<t)throw new RangeError("Invalid typed array length");return g.TYPED_ARRAY_SUPPORT?(e=new Uint8Array(t),e.__proto__=g.prototype):(e===null&&(e=new g(t)),e.length=t),e}function g(e,t,r){if(!g.TYPED_ARRAY_SUPPORT&&!(this instanceof g))return new g(e,t,r);if(typeof e=="number"){if(typeof t=="string")throw new Error("If encoding is specified then the first argument must be a string");return Wn(this,e)}return So(this,e,t,r)}g.poolSize=8192,g._augment=function(e){return e.__proto__=g.prototype,e};function So(e,t,r,n){if(typeof t=="number")throw new TypeError('"value" argument must not be a number');return typeof ArrayBuffer<"u"&&t instanceof ArrayBuffer?Sl(e,t,r,n):typeof t=="string"?El(e,t,r):Al(e,t)}g.from=function(e,t,r){return So(null,e,t,r)},g.TYPED_ARRAY_SUPPORT&&(g.prototype.__proto__=Uint8Array.prototype,g.__proto__=Uint8Array,typeof Symbol<"u"&&Symbol.species&&g[Symbol.species]);function Ao(e){if(typeof e!="number")throw new TypeError('"size" argument must be a number');if(e<0)throw new RangeError('"size" argument must not be negative')}function xl(e,t,r,n){return Ao(t),t<=0?xe(e,t):r!==void 0?typeof n=="string"?xe(e,t).fill(r,n):xe(e,t).fill(r):xe(e,t)}g.alloc=function(e,t,r){return xl(null,e,t,r)};function Wn(e,t){if(Ao(t),e=xe(e,t<0?0:Gn(t)|0),!g.TYPED_ARRAY_SUPPORT)for(var r=0;r<t;++r)e[r]=0;return e}g.allocUnsafe=function(e){return Wn(null,e)},g.allocUnsafeSlow=function(e){return Wn(null,e)};function El(e,t,r){if((typeof r!="string"||r==="")&&(r="utf8"),!g.isEncoding(r))throw new TypeError('"encoding" must be a valid string encoding');var n=ko(t,r)|0;e=xe(e,n);var i=e.write(t,r);return i!==n&&(e=e.slice(0,i)),e}function Vn(e,t){var r=t.length<0?0:Gn(t.length)|0;e=xe(e,r);for(var n=0;n<r;n+=1)e[n]=t[n]&255;return e}function Sl(e,t,r,n){if(t.byteLength,r<0||t.byteLength<r)throw new RangeError("'offset' is out of bounds");if(t.byteLength<r+(n||0))throw new RangeError("'length' is out of bounds");return r===void 0&&n===void 0?t=new Uint8Array(t):n===void 0?t=new Uint8Array(t,r):t=new Uint8Array(t,r,n),g.TYPED_ARRAY_SUPPORT?(e=t,e.__proto__=g.prototype):e=Vn(e,t),e}function Al(e,t){if(ye(t)){var r=Gn(t.length)|0;return e=xe(e,r),e.length===0||t.copy(e,0,0,r),e}if(t){if(typeof ArrayBuffer<"u"&&t.buffer instanceof ArrayBuffer||"length"in t)return typeof t.length!="number"||ql(t.length)?xe(e,0):Vn(e,t);if(t.type==="Buffer"&&Eo(t.data))return Vn(e,t.data)}throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}function Gn(e){if(e>=fr())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+fr().toString(16)+" bytes");return e|0}g.isBuffer=Hl;function ye(e){return!!(e!=null&&e._isBuffer)}g.compare=function(t,r){if(!ye(t)||!ye(r))throw new TypeError("Arguments must be Buffers");if(t===r)return 0;for(var n=t.length,i=r.length,a=0,o=Math.min(n,i);a<o;++a)if(t[a]!==r[a]){n=t[a],i=r[a];break}return n<i?-1:i<n?1:0},g.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},g.concat=function(t,r){if(!Eo(t))throw new TypeError('"list" argument must be an Array of Buffers');if(t.length===0)return g.alloc(0);var n;if(r===void 0)for(r=0,n=0;n<t.length;++n)r+=t[n].length;var i=g.allocUnsafe(r),a=0;for(n=0;n<t.length;++n){var o=t[n];if(!ye(o))throw new TypeError('"list" argument must be an Array of Buffers');o.copy(i,a),a+=o.length}return i};function ko(e,t){if(ye(e))return e.length;if(typeof ArrayBuffer<"u"&&typeof ArrayBuffer.isView=="function"&&(ArrayBuffer.isView(e)||e instanceof ArrayBuffer))return e.byteLength;typeof e!="string"&&(e=""+e);var r=e.length;if(r===0)return 0;for(var n=!1;;)switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":case void 0:return hr(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return r*2;case"hex":return r>>>1;case"base64":return Do(e).length;default:if(n)return hr(e).length;t=(""+t).toLowerCase(),n=!0}}g.byteLength=ko;function kl(e,t,r){var n=!1;if((t===void 0||t<0)&&(t=0),t>this.length||((r===void 0||r>this.length)&&(r=this.length),r<=0)||(r>>>=0,t>>>=0,r<=t))return"";for(e||(e="utf8");;)switch(e){case"hex":return Ml(this,t,r);case"utf8":case"utf-8":return To(this,t,r);case"ascii":return Cl(this,t,r);case"latin1":case"binary":return Dl(this,t,r);case"base64":return jl(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Ll(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}g.prototype._isBuffer=!0;function Ke(e,t,r){var n=e[t];e[t]=e[r],e[r]=n}g.prototype.swap16=function(){var t=this.length;if(t%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var r=0;r<t;r+=2)Ke(this,r,r+1);return this},g.prototype.swap32=function(){var t=this.length;if(t%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var r=0;r<t;r+=4)Ke(this,r,r+3),Ke(this,r+1,r+2);return this},g.prototype.swap64=function(){var t=this.length;if(t%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var r=0;r<t;r+=8)Ke(this,r,r+7),Ke(this,r+1,r+6),Ke(this,r+2,r+5),Ke(this,r+3,r+4);return this},g.prototype.toString=function(){var t=this.length|0;return t===0?"":arguments.length===0?To(this,0,t):kl.apply(this,arguments)},g.prototype.equals=function(t){if(!ye(t))throw new TypeError("Argument must be a Buffer");return this===t?!0:g.compare(this,t)===0},g.prototype.inspect=function(){var t="",r=ml;return this.length>0&&(t=this.toString("hex",0,r).match(/.{2}/g).join(" "),this.length>r&&(t+=" ... ")),"<Buffer "+t+">"},g.prototype.compare=function(t,r,n,i,a){if(!ye(t))throw new TypeError("Argument must be a Buffer");if(r===void 0&&(r=0),n===void 0&&(n=t?t.length:0),i===void 0&&(i=0),a===void 0&&(a=this.length),r<0||n>t.length||i<0||a>this.length)throw new RangeError("out of range index");if(i>=a&&r>=n)return 0;if(i>=a)return-1;if(r>=n)return 1;if(r>>>=0,n>>>=0,i>>>=0,a>>>=0,this===t)return 0;for(var o=a-i,s=n-r,f=Math.min(o,s),c=this.slice(i,a),l=t.slice(r,n),d=0;d<f;++d)if(c[d]!==l[d]){o=c[d],s=l[d];break}return o<s?-1:s<o?1:0};function Ro(e,t,r,n,i){if(e.length===0)return-1;if(typeof r=="string"?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,isNaN(r)&&(r=i?0:e.length-1),r<0&&(r=e.length+r),r>=e.length){if(i)return-1;r=e.length-1}else if(r<0)if(i)r=0;else return-1;if(typeof t=="string"&&(t=g.from(t,n)),ye(t))return t.length===0?-1:Oo(e,t,r,n,i);if(typeof t=="number")return t=t&255,g.TYPED_ARRAY_SUPPORT&&typeof Uint8Array.prototype.indexOf=="function"?i?Uint8Array.prototype.indexOf.call(e,t,r):Uint8Array.prototype.lastIndexOf.call(e,t,r):Oo(e,[t],r,n,i);throw new TypeError("val must be string, number or Buffer")}function Oo(e,t,r,n,i){var a=1,o=e.length,s=t.length;if(n!==void 0&&(n=String(n).toLowerCase(),n==="ucs2"||n==="ucs-2"||n==="utf16le"||n==="utf-16le")){if(e.length<2||t.length<2)return-1;a=2,o/=2,s/=2,r/=2}function f(u,p){return a===1?u[p]:u.readUInt16BE(p*a)}var c;if(i){var l=-1;for(c=r;c<o;c++)if(f(e,c)===f(t,l===-1?0:c-l)){if(l===-1&&(l=c),c-l+1===s)return l*a}else l!==-1&&(c-=c-l),l=-1}else for(r+s>o&&(r=o-s),c=r;c>=0;c--){for(var d=!0,h=0;h<s;h++)if(f(e,c+h)!==f(t,h)){d=!1;break}if(d)return c}return-1}g.prototype.includes=function(t,r,n){return this.indexOf(t,r,n)!==-1},g.prototype.indexOf=function(t,r,n){return Ro(this,t,r,n,!0)},g.prototype.lastIndexOf=function(t,r,n){return Ro(this,t,r,n,!1)};function Rl(e,t,r,n){r=Number(r)||0;var i=e.length-r;n?(n=Number(n),n>i&&(n=i)):n=i;var a=t.length;if(a%2!==0)throw new TypeError("Invalid hex string");n>a/2&&(n=a/2);for(var o=0;o<n;++o){var s=parseInt(t.substr(o*2,2),16);if(isNaN(s))return o;e[r+o]=s}return o}function Ol(e,t,r,n){return dr(hr(t,e.length-r),e,r,n)}function Io(e,t,r,n){return dr(zl(t),e,r,n)}function Il(e,t,r,n){return Io(e,t,r,n)}function Tl(e,t,r,n){return dr(Do(t),e,r,n)}function Pl(e,t,r,n){return dr(Zl(t,e.length-r),e,r,n)}g.prototype.write=function(t,r,n,i){if(r===void 0)i="utf8",n=this.length,r=0;else if(n===void 0&&typeof r=="string")i=r,n=this.length,r=0;else if(isFinite(r))r=r|0,isFinite(n)?(n=n|0,i===void 0&&(i="utf8")):(i=n,n=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");var a=this.length-r;if((n===void 0||n>a)&&(n=a),t.length>0&&(n<0||r<0)||r>this.length)throw new RangeError("Attempt to write outside buffer bounds");i||(i="utf8");for(var o=!1;;)switch(i){case"hex":return Rl(this,t,r,n);case"utf8":case"utf-8":return Ol(this,t,r,n);case"ascii":return Io(this,t,r,n);case"latin1":case"binary":return Il(this,t,r,n);case"base64":return Tl(this,t,r,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Pl(this,t,r,n);default:if(o)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),o=!0}},g.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function jl(e,t,r){return t===0&&r===e.length?mo(e):mo(e.slice(t,r))}function To(e,t,r){r=Math.min(e.length,r);for(var n=[],i=t;i<r;){var a=e[i],o=null,s=a>239?4:a>223?3:a>191?2:1;if(i+s<=r){var f,c,l,d;switch(s){case 1:a<128&&(o=a);break;case 2:f=e[i+1],(f&192)===128&&(d=(a&31)<<6|f&63,d>127&&(o=d));break;case 3:f=e[i+1],c=e[i+2],(f&192)===128&&(c&192)===128&&(d=(a&15)<<12|(f&63)<<6|c&63,d>2047&&(d<55296||d>57343)&&(o=d));break;case 4:f=e[i+1],c=e[i+2],l=e[i+3],(f&192)===128&&(c&192)===128&&(l&192)===128&&(d=(a&15)<<18|(f&63)<<12|(c&63)<<6|l&63,d>65535&&d<1114112&&(o=d))}}o===null?(o=65533,s=1):o>65535&&(o-=65536,n.push(o>>>10&1023|55296),o=56320|o&1023),n.push(o),i+=s}return Fl(n)}var Po=4096;function Fl(e){var t=e.length;if(t<=Po)return String.fromCharCode.apply(String,e);for(var r="",n=0;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=Po));return r}function Cl(e,t,r){var n="";r=Math.min(e.length,r);for(var i=t;i<r;++i)n+=String.fromCharCode(e[i]&127);return n}function Dl(e,t,r){var n="";r=Math.min(e.length,r);for(var i=t;i<r;++i)n+=String.fromCharCode(e[i]);return n}function Ml(e,t,r){var n=e.length;(!t||t<0)&&(t=0),(!r||r<0||r>n)&&(r=n);for(var i="",a=t;a<r;++a)i+=Bl(e[a]);return i}function Ll(e,t,r){for(var n=e.slice(t,r),i="",a=0;a<n.length;a+=2)i+=String.fromCharCode(n[a]+n[a+1]*256);return i}g.prototype.slice=function(t,r){var n=this.length;t=~~t,r=r===void 0?n:~~r,t<0?(t+=n,t<0&&(t=0)):t>n&&(t=n),r<0?(r+=n,r<0&&(r=0)):r>n&&(r=n),r<t&&(r=t);var i;if(g.TYPED_ARRAY_SUPPORT)i=this.subarray(t,r),i.__proto__=g.prototype;else{var a=r-t;i=new g(a,void 0);for(var o=0;o<a;++o)i[o]=this[o+t]}return i};function B(e,t,r){if(e%1!==0||e<0)throw new RangeError("offset is not uint");if(e+t>r)throw new RangeError("Trying to access beyond buffer length")}g.prototype.readUIntLE=function(t,r,n){t=t|0,r=r|0,n||B(t,r,this.length);for(var i=this[t],a=1,o=0;++o<r&&(a*=256);)i+=this[t+o]*a;return i},g.prototype.readUIntBE=function(t,r,n){t=t|0,r=r|0,n||B(t,r,this.length);for(var i=this[t+--r],a=1;r>0&&(a*=256);)i+=this[t+--r]*a;return i},g.prototype.readUInt8=function(t,r){return r||B(t,1,this.length),this[t]},g.prototype.readUInt16LE=function(t,r){return r||B(t,2,this.length),this[t]|this[t+1]<<8},g.prototype.readUInt16BE=function(t,r){return r||B(t,2,this.length),this[t]<<8|this[t+1]},g.prototype.readUInt32LE=function(t,r){return r||B(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+this[t+3]*16777216},g.prototype.readUInt32BE=function(t,r){return r||B(t,4,this.length),this[t]*16777216+(this[t+1]<<16|this[t+2]<<8|this[t+3])},g.prototype.readIntLE=function(t,r,n){t=t|0,r=r|0,n||B(t,r,this.length);for(var i=this[t],a=1,o=0;++o<r&&(a*=256);)i+=this[t+o]*a;return a*=128,i>=a&&(i-=Math.pow(2,8*r)),i},g.prototype.readIntBE=function(t,r,n){t=t|0,r=r|0,n||B(t,r,this.length);for(var i=r,a=1,o=this[t+--i];i>0&&(a*=256);)o+=this[t+--i]*a;return a*=128,o>=a&&(o-=Math.pow(2,8*r)),o},g.prototype.readInt8=function(t,r){return r||B(t,1,this.length),this[t]&128?(255-this[t]+1)*-1:this[t]},g.prototype.readInt16LE=function(t,r){r||B(t,2,this.length);var n=this[t]|this[t+1]<<8;return n&32768?n|4294901760:n},g.prototype.readInt16BE=function(t,r){r||B(t,2,this.length);var n=this[t+1]|this[t]<<8;return n&32768?n|4294901760:n},g.prototype.readInt32LE=function(t,r){return r||B(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},g.prototype.readInt32BE=function(t,r){return r||B(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},g.prototype.readFloatLE=function(t,r){return r||B(t,4,this.length),cr(this,t,!0,23,4)},g.prototype.readFloatBE=function(t,r){return r||B(t,4,this.length),cr(this,t,!1,23,4)},g.prototype.readDoubleLE=function(t,r){return r||B(t,8,this.length),cr(this,t,!0,52,8)},g.prototype.readDoubleBE=function(t,r){return r||B(t,8,this.length),cr(this,t,!1,52,8)};function X(e,t,r,n,i,a){if(!ye(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>i||t<a)throw new RangeError('"value" argument is out of bounds');if(r+n>e.length)throw new RangeError("Index out of range")}g.prototype.writeUIntLE=function(t,r,n,i){if(t=+t,r=r|0,n=n|0,!i){var a=Math.pow(2,8*n)-1;X(this,t,r,n,a,0)}var o=1,s=0;for(this[r]=t&255;++s<n&&(o*=256);)this[r+s]=t/o&255;return r+n},g.prototype.writeUIntBE=function(t,r,n,i){if(t=+t,r=r|0,n=n|0,!i){var a=Math.pow(2,8*n)-1;X(this,t,r,n,a,0)}var o=n-1,s=1;for(this[r+o]=t&255;--o>=0&&(s*=256);)this[r+o]=t/s&255;return r+n},g.prototype.writeUInt8=function(t,r,n){return t=+t,r=r|0,n||X(this,t,r,1,255,0),g.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[r]=t&255,r+1};function lr(e,t,r,n){t<0&&(t=65535+t+1);for(var i=0,a=Math.min(e.length-r,2);i<a;++i)e[r+i]=(t&255<<8*(n?i:1-i))>>>(n?i:1-i)*8}g.prototype.writeUInt16LE=function(t,r,n){return t=+t,r=r|0,n||X(this,t,r,2,65535,0),g.TYPED_ARRAY_SUPPORT?(this[r]=t&255,this[r+1]=t>>>8):lr(this,t,r,!0),r+2},g.prototype.writeUInt16BE=function(t,r,n){return t=+t,r=r|0,n||X(this,t,r,2,65535,0),g.TYPED_ARRAY_SUPPORT?(this[r]=t>>>8,this[r+1]=t&255):lr(this,t,r,!1),r+2};function ur(e,t,r,n){t<0&&(t=4294967295+t+1);for(var i=0,a=Math.min(e.length-r,4);i<a;++i)e[r+i]=t>>>(n?i:3-i)*8&255}g.prototype.writeUInt32LE=function(t,r,n){return t=+t,r=r|0,n||X(this,t,r,4,4294967295,0),g.TYPED_ARRAY_SUPPORT?(this[r+3]=t>>>24,this[r+2]=t>>>16,this[r+1]=t>>>8,this[r]=t&255):ur(this,t,r,!0),r+4},g.prototype.writeUInt32BE=function(t,r,n){return t=+t,r=r|0,n||X(this,t,r,4,4294967295,0),g.TYPED_ARRAY_SUPPORT?(this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=t&255):ur(this,t,r,!1),r+4},g.prototype.writeIntLE=function(t,r,n,i){if(t=+t,r=r|0,!i){var a=Math.pow(2,8*n-1);X(this,t,r,n,a-1,-a)}var o=0,s=1,f=0;for(this[r]=t&255;++o<n&&(s*=256);)t<0&&f===0&&this[r+o-1]!==0&&(f=1),this[r+o]=(t/s>>0)-f&255;return r+n},g.prototype.writeIntBE=function(t,r,n,i){if(t=+t,r=r|0,!i){var a=Math.pow(2,8*n-1);X(this,t,r,n,a-1,-a)}var o=n-1,s=1,f=0;for(this[r+o]=t&255;--o>=0&&(s*=256);)t<0&&f===0&&this[r+o+1]!==0&&(f=1),this[r+o]=(t/s>>0)-f&255;return r+n},g.prototype.writeInt8=function(t,r,n){return t=+t,r=r|0,n||X(this,t,r,1,127,-128),g.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[r]=t&255,r+1},g.prototype.writeInt16LE=function(t,r,n){return t=+t,r=r|0,n||X(this,t,r,2,32767,-32768),g.TYPED_ARRAY_SUPPORT?(this[r]=t&255,this[r+1]=t>>>8):lr(this,t,r,!0),r+2},g.prototype.writeInt16BE=function(t,r,n){return t=+t,r=r|0,n||X(this,t,r,2,32767,-32768),g.TYPED_ARRAY_SUPPORT?(this[r]=t>>>8,this[r+1]=t&255):lr(this,t,r,!1),r+2},g.prototype.writeInt32LE=function(t,r,n){return t=+t,r=r|0,n||X(this,t,r,4,2147483647,-2147483648),g.TYPED_ARRAY_SUPPORT?(this[r]=t&255,this[r+1]=t>>>8,this[r+2]=t>>>16,this[r+3]=t>>>24):ur(this,t,r,!0),r+4},g.prototype.writeInt32BE=function(t,r,n){return t=+t,r=r|0,n||X(this,t,r,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),g.TYPED_ARRAY_SUPPORT?(this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=t&255):ur(this,t,r,!1),r+4};function jo(e,t,r,n,i,a){if(r+n>e.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function Fo(e,t,r,n,i){return i||jo(e,t,r,4),xo(e,t,r,n,23,4),r+4}g.prototype.writeFloatLE=function(t,r,n){return Fo(this,t,r,!0,n)},g.prototype.writeFloatBE=function(t,r,n){return Fo(this,t,r,!1,n)};function Co(e,t,r,n,i){return i||jo(e,t,r,8),xo(e,t,r,n,52,8),r+8}g.prototype.writeDoubleLE=function(t,r,n){return Co(this,t,r,!0,n)},g.prototype.writeDoubleBE=function(t,r,n){return Co(this,t,r,!1,n)},g.prototype.copy=function(t,r,n,i){if(n||(n=0),!i&&i!==0&&(i=this.length),r>=t.length&&(r=t.length),r||(r=0),i>0&&i<n&&(i=n),i===n||t.length===0||this.length===0)return 0;if(r<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("sourceStart out of bounds");if(i<0)throw new RangeError("sourceEnd out of bounds");i>this.length&&(i=this.length),t.length-r<i-n&&(i=t.length-r+n);var a=i-n,o;if(this===t&&n<r&&r<i)for(o=a-1;o>=0;--o)t[o+r]=this[o+n];else if(a<1e3||!g.TYPED_ARRAY_SUPPORT)for(o=0;o<a;++o)t[o+r]=this[o+n];else Uint8Array.prototype.set.call(t,this.subarray(n,n+a),r);return a},g.prototype.fill=function(t,r,n,i){if(typeof t=="string"){if(typeof r=="string"?(i=r,r=0,n=this.length):typeof n=="string"&&(i=n,n=this.length),t.length===1){var a=t.charCodeAt(0);a<256&&(t=a)}if(i!==void 0&&typeof i!="string")throw new TypeError("encoding must be a string");if(typeof i=="string"&&!g.isEncoding(i))throw new TypeError("Unknown encoding: "+i)}else typeof t=="number"&&(t=t&255);if(r<0||this.length<r||this.length<n)throw new RangeError("Out of range index");if(n<=r)return this;r=r>>>0,n=n===void 0?this.length:n>>>0,t||(t=0);var o;if(typeof t=="number")for(o=r;o<n;++o)this[o]=t;else{var s=ye(t)?t:hr(new g(t,i).toString()),f=s.length;for(o=0;o<n-r;++o)this[o+r]=s[o%f]}return this};var Nl=/[^+\/0-9A-Za-z-_]/g;function $l(e){if(e=Ul(e).replace(Nl,""),e.length<2)return"";for(;e.length%4!==0;)e=e+"=";return e}function Ul(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}function Bl(e){return e<16?"0"+e.toString(16):e.toString(16)}function hr(e,t){t=t||1/0;for(var r,n=e.length,i=null,a=[],o=0;o<n;++o){if(r=e.charCodeAt(o),r>55295&&r<57344){if(!i){if(r>56319){(t-=3)>-1&&a.push(239,191,189);continue}else if(o+1===n){(t-=3)>-1&&a.push(239,191,189);continue}i=r;continue}if(r<56320){(t-=3)>-1&&a.push(239,191,189),i=r;continue}r=(i-55296<<10|r-56320)+65536}else i&&(t-=3)>-1&&a.push(239,191,189);if(i=null,r<128){if((t-=1)<0)break;a.push(r)}else if(r<2048){if((t-=2)<0)break;a.push(r>>6|192,r&63|128)}else if(r<65536){if((t-=3)<0)break;a.push(r>>12|224,r>>6&63|128,r&63|128)}else if(r<1114112){if((t-=4)<0)break;a.push(r>>18|240,r>>12&63|128,r>>6&63|128,r&63|128)}else throw new Error("Invalid code point")}return a}function zl(e){for(var t=[],r=0;r<e.length;++r)t.push(e.charCodeAt(r)&255);return t}function Zl(e,t){for(var r,n,i,a=[],o=0;o<e.length&&!((t-=2)<0);++o)r=e.charCodeAt(o),n=r>>8,i=r%256,a.push(i),a.push(n);return a}function Do(e){return vl($l(e))}function dr(e,t,r,n){for(var i=0;i<n&&!(i+r>=t.length||i>=e.length);++i)t[i+r]=e[i];return i}function ql(e){return e!==e}function Hl(e){return e!=null&&(!!e._isBuffer||Mo(e)||Kl(e))}function Mo(e){return!!e.constructor&&typeof e.constructor.isBuffer=="function"&&e.constructor.isBuffer(e)}function Kl(e){return typeof e.readFloatLE=="function"&&typeof e.slice=="function"&&Mo(e.slice(0,0))}function Lo(){throw new Error("setTimeout has not been defined")}function No(){throw new Error("clearTimeout has not been defined")}var Te=Lo,Pe=No;typeof ht.setTimeout=="function"&&(Te=setTimeout),typeof ht.clearTimeout=="function"&&(Pe=clearTimeout);function $o(e){if(Te===setTimeout)return setTimeout(e,0);if((Te===Lo||!Te)&&setTimeout)return Te=setTimeout,setTimeout(e,0);try{return Te(e,0)}catch{try{return Te.call(null,e,0)}catch{return Te.call(this,e,0)}}}function Wl(e){if(Pe===clearTimeout)return clearTimeout(e);if((Pe===No||!Pe)&&clearTimeout)return Pe=clearTimeout,clearTimeout(e);try{return Pe(e)}catch{try{return Pe.call(null,e)}catch{return Pe.call(this,e)}}}var Ee=[],dt=!1,We,pr=-1;function Vl(){!dt||!We||(dt=!1,We.length?Ee=We.concat(Ee):pr=-1,Ee.length&&Uo())}function Uo(){if(!dt){var e=$o(Vl);dt=!0;for(var t=Ee.length;t;){for(We=Ee,Ee=[];++pr<t;)We&&We[pr].run();pr=-1,t=Ee.length}We=null,dt=!1,Wl(e)}}function ee(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)t[r-1]=arguments[r];Ee.push(new Bo(e,t)),Ee.length===1&&!dt&&$o(Uo)}function Bo(e,t){this.fun=e,this.array=t}Bo.prototype.run=function(){this.fun.apply(null,this.array)};var Gl="browser",Yl="browser",Jl=!0,Xl={},Ql=[],eu="",tu={},ru={},nu={};function Ve(){}var iu=Ve,au=Ve,ou=Ve,su=Ve,cu=Ve,fu=Ve,lu=Ve;function uu(e){throw new Error("process.binding is not supported")}function hu(){return"/"}function du(e){throw new Error("process.chdir is not supported")}function pu(){return 0}var pt=ht.performance||{},yu=pt.now||pt.mozNow||pt.msNow||pt.oNow||pt.webkitNow||function(){return new Date().getTime()};function gu(e){var t=yu.call(pt)*.001,r=Math.floor(t),n=Math.floor(t%1*1e9);return e&&(r=r-e[0],n=n-e[1],n<0&&(r--,n+=1e9)),[r,n]}var vu=new Date;function wu(){var e=new Date,t=e-vu;return t/1e3}var Se={nextTick:ee,title:Gl,browser:Jl,env:Xl,argv:Ql,version:eu,versions:tu,on:iu,addListener:au,once:ou,off:su,removeListener:cu,removeAllListeners:fu,emit:lu,binding:uu,cwd:hu,chdir:du,umask:pu,hrtime:gu,platform:Yl,release:ru,config:nu,uptime:wu},W;typeof Object.create=="function"?W=function(t,r){t.super_=r,t.prototype=Object.create(r.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}})}:W=function(t,r){t.super_=r;var n=function(){};n.prototype=r.prototype,t.prototype=new n,t.prototype.constructor=t};var _u=/%[sdj%]/g;function bu(e){if(!ei(e)){for(var t=[],r=0;r<arguments.length;r++)t.push(je(arguments[r]));return t.join(" ")}for(var r=1,n=arguments,i=n.length,a=String(e).replace(_u,function(s){if(s==="%%")return"%";if(r>=i)return s;switch(s){case"%s":return String(n[r++]);case"%d":return Number(n[r++]);case"%j":try{return JSON.stringify(n[r++])}catch{return"[Circular]"}default:return s}}),o=n[r];r<i;o=n[++r])Qn(o)||!Tt(o)?a+=" "+o:a+=" "+je(o);return a}function zo(e,t){if(Fe(ht.process))return function(){return zo(e,t).apply(this,arguments)};if(Se.noDeprecation===!0)return e;var r=!1;function n(){if(!r){if(Se.throwDeprecation)throw new Error(t);Se.traceDeprecation?console.trace(t):console.error(t),r=!0}return e.apply(this,arguments)}return n}var yr={},Yn;function mu(e){if(Fe(Yn)&&(Yn=Se.env.NODE_DEBUG||""),e=e.toUpperCase(),!yr[e])if(new RegExp("\\b"+e+"\\b","i").test(Yn)){var t=0;yr[e]=function(){var r=bu.apply(null,arguments);console.error("%s %d: %s",e,t,r)}}else yr[e]=function(){};return yr[e]}function je(e,t){var r={seen:[],stylize:Eu};return arguments.length>=3&&(r.depth=arguments[2]),arguments.length>=4&&(r.colors=arguments[3]),Zo(t)?r.showHidden=t:t&&Tu(r,t),Fe(r.showHidden)&&(r.showHidden=!1),Fe(r.depth)&&(r.depth=2),Fe(r.colors)&&(r.colors=!1),Fe(r.customInspect)&&(r.customInspect=!0),r.colors&&(r.stylize=xu),gr(r,e,r.depth)}je.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},je.styles={special:"cyan",number:"yellow",boolean:"yellow",undefined:"grey",null:"bold",string:"green",date:"magenta",regexp:"red"};function xu(e,t){var r=je.styles[t];return r?"\x1B["+je.colors[r][0]+"m"+e+"\x1B["+je.colors[r][1]+"m":e}function Eu(e,t){return e}function Su(e){var t={};return e.forEach(function(r,n){t[r]=!0}),t}function gr(e,t,r){if(e.customInspect&&t&&ni(t.inspect)&&t.inspect!==je&&!(t.constructor&&t.constructor.prototype===t)){var n=t.inspect(r,e);return ei(n)||(n=gr(e,n,r)),n}var i=Au(e,t);if(i)return i;var a=Object.keys(t),o=Su(a);if(e.showHidden&&(a=Object.getOwnPropertyNames(t)),ri(t)&&(a.indexOf("message")>=0||a.indexOf("description")>=0))return Jn(t);if(a.length===0){if(ni(t)){var s=t.name?": "+t.name:"";return e.stylize("[Function"+s+"]","special")}if(ti(t))return e.stylize(RegExp.prototype.toString.call(t),"regexp");if(qo(t))return e.stylize(Date.prototype.toString.call(t),"date");if(ri(t))return Jn(t)}var f="",c=!1,l=["{","}"];if(Ou(t)&&(c=!0,l=["[","]"]),ni(t)){var d=t.name?": "+t.name:"";f=" [Function"+d+"]"}if(ti(t)&&(f=" "+RegExp.prototype.toString.call(t)),qo(t)&&(f=" "+Date.prototype.toUTCString.call(t)),ri(t)&&(f=" "+Jn(t)),a.length===0&&(!c||t.length==0))return l[0]+f+l[1];if(r<0)return ti(t)?e.stylize(RegExp.prototype.toString.call(t),"regexp"):e.stylize("[Object]","special");e.seen.push(t);var h;return c?h=ku(e,t,r,o,a):h=a.map(function(u){return Xn(e,t,r,o,u,c)}),e.seen.pop(),Ru(h,f,l)}function Au(e,t){if(Fe(t))return e.stylize("undefined","undefined");if(ei(t)){var r="'"+JSON.stringify(t).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return e.stylize(r,"string")}if(Iu(t))return e.stylize(""+t,"number");if(Zo(t))return e.stylize(""+t,"boolean");if(Qn(t))return e.stylize("null","null")}function Jn(e){return"["+Error.prototype.toString.call(e)+"]"}function ku(e,t,r,n,i){for(var a=[],o=0,s=t.length;o<s;++o)Ho(t,String(o))?a.push(Xn(e,t,r,n,String(o),!0)):a.push("");return i.forEach(function(f){f.match(/^\d+$/)||a.push(Xn(e,t,r,n,f,!0))}),a}function Xn(e,t,r,n,i,a){var o,s,f;if(f=Object.getOwnPropertyDescriptor(t,i)||{value:t[i]},f.get?f.set?s=e.stylize("[Getter/Setter]","special"):s=e.stylize("[Getter]","special"):f.set&&(s=e.stylize("[Setter]","special")),Ho(n,i)||(o="["+i+"]"),s||(e.seen.indexOf(f.value)<0?(Qn(r)?s=gr(e,f.value,null):s=gr(e,f.value,r-1),s.indexOf(`
20
+ */var xl=50;g.TYPED_ARRAY_SUPPORT=ht.TYPED_ARRAY_SUPPORT!==void 0?ht.TYPED_ARRAY_SUPPORT:!0,fr();function fr(){return g.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function xe(e,t){if(fr()<t)throw new RangeError("Invalid typed array length");return g.TYPED_ARRAY_SUPPORT?(e=new Uint8Array(t),e.__proto__=g.prototype):(e===null&&(e=new g(t)),e.length=t),e}function g(e,t,r){if(!g.TYPED_ARRAY_SUPPORT&&!(this instanceof g))return new g(e,t,r);if(typeof e=="number"){if(typeof t=="string")throw new Error("If encoding is specified then the first argument must be a string");return Vn(this,e)}return Ao(this,e,t,r)}g.poolSize=8192,g._augment=function(e){return e.__proto__=g.prototype,e};function Ao(e,t,r,n){if(typeof t=="number")throw new TypeError('"value" argument must not be a number');return typeof ArrayBuffer<"u"&&t instanceof ArrayBuffer?Al(e,t,r,n):typeof t=="string"?Sl(e,t,r):kl(e,t)}g.from=function(e,t,r){return Ao(null,e,t,r)},g.TYPED_ARRAY_SUPPORT&&(g.prototype.__proto__=Uint8Array.prototype,g.__proto__=Uint8Array,typeof Symbol<"u"&&Symbol.species&&g[Symbol.species]);function ko(e){if(typeof e!="number")throw new TypeError('"size" argument must be a number');if(e<0)throw new RangeError('"size" argument must not be negative')}function El(e,t,r,n){return ko(t),t<=0?xe(e,t):r!==void 0?typeof n=="string"?xe(e,t).fill(r,n):xe(e,t).fill(r):xe(e,t)}g.alloc=function(e,t,r){return El(null,e,t,r)};function Vn(e,t){if(ko(t),e=xe(e,t<0?0:Yn(t)|0),!g.TYPED_ARRAY_SUPPORT)for(var r=0;r<t;++r)e[r]=0;return e}g.allocUnsafe=function(e){return Vn(null,e)},g.allocUnsafeSlow=function(e){return Vn(null,e)};function Sl(e,t,r){if((typeof r!="string"||r==="")&&(r="utf8"),!g.isEncoding(r))throw new TypeError('"encoding" must be a valid string encoding');var n=Ro(t,r)|0;e=xe(e,n);var i=e.write(t,r);return i!==n&&(e=e.slice(0,i)),e}function Gn(e,t){var r=t.length<0?0:Yn(t.length)|0;e=xe(e,r);for(var n=0;n<r;n+=1)e[n]=t[n]&255;return e}function Al(e,t,r,n){if(t.byteLength,r<0||t.byteLength<r)throw new RangeError("'offset' is out of bounds");if(t.byteLength<r+(n||0))throw new RangeError("'length' is out of bounds");return r===void 0&&n===void 0?t=new Uint8Array(t):n===void 0?t=new Uint8Array(t,r):t=new Uint8Array(t,r,n),g.TYPED_ARRAY_SUPPORT?(e=t,e.__proto__=g.prototype):e=Gn(e,t),e}function kl(e,t){if(ye(t)){var r=Yn(t.length)|0;return e=xe(e,r),e.length===0||t.copy(e,0,0,r),e}if(t){if(typeof ArrayBuffer<"u"&&t.buffer instanceof ArrayBuffer||"length"in t)return typeof t.length!="number"||Hl(t.length)?xe(e,0):Gn(e,t);if(t.type==="Buffer"&&So(t.data))return Gn(e,t.data)}throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}function Yn(e){if(e>=fr())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+fr().toString(16)+" bytes");return e|0}g.isBuffer=Kl;function ye(e){return!!(e!=null&&e._isBuffer)}g.compare=function(t,r){if(!ye(t)||!ye(r))throw new TypeError("Arguments must be Buffers");if(t===r)return 0;for(var n=t.length,i=r.length,a=0,o=Math.min(n,i);a<o;++a)if(t[a]!==r[a]){n=t[a],i=r[a];break}return n<i?-1:i<n?1:0},g.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},g.concat=function(t,r){if(!So(t))throw new TypeError('"list" argument must be an Array of Buffers');if(t.length===0)return g.alloc(0);var n;if(r===void 0)for(r=0,n=0;n<t.length;++n)r+=t[n].length;var i=g.allocUnsafe(r),a=0;for(n=0;n<t.length;++n){var o=t[n];if(!ye(o))throw new TypeError('"list" argument must be an Array of Buffers');o.copy(i,a),a+=o.length}return i};function Ro(e,t){if(ye(e))return e.length;if(typeof ArrayBuffer<"u"&&typeof ArrayBuffer.isView=="function"&&(ArrayBuffer.isView(e)||e instanceof ArrayBuffer))return e.byteLength;typeof e!="string"&&(e=""+e);var r=e.length;if(r===0)return 0;for(var n=!1;;)switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":case void 0:return hr(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return r*2;case"hex":return r>>>1;case"base64":return Mo(e).length;default:if(n)return hr(e).length;t=(""+t).toLowerCase(),n=!0}}g.byteLength=Ro;function Rl(e,t,r){var n=!1;if((t===void 0||t<0)&&(t=0),t>this.length||((r===void 0||r>this.length)&&(r=this.length),r<=0)||(r>>>=0,t>>>=0,r<=t))return"";for(e||(e="utf8");;)switch(e){case"hex":return Nl(this,t,r);case"utf8":case"utf-8":return Po(this,t,r);case"ascii":return Dl(this,t,r);case"latin1":case"binary":return Ml(this,t,r);case"base64":return Fl(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Ll(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}g.prototype._isBuffer=!0;function Ke(e,t,r){var n=e[t];e[t]=e[r],e[r]=n}g.prototype.swap16=function(){var t=this.length;if(t%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var r=0;r<t;r+=2)Ke(this,r,r+1);return this},g.prototype.swap32=function(){var t=this.length;if(t%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var r=0;r<t;r+=4)Ke(this,r,r+3),Ke(this,r+1,r+2);return this},g.prototype.swap64=function(){var t=this.length;if(t%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var r=0;r<t;r+=8)Ke(this,r,r+7),Ke(this,r+1,r+6),Ke(this,r+2,r+5),Ke(this,r+3,r+4);return this},g.prototype.toString=function(){var t=this.length|0;return t===0?"":arguments.length===0?Po(this,0,t):Rl.apply(this,arguments)},g.prototype.equals=function(t){if(!ye(t))throw new TypeError("Argument must be a Buffer");return this===t?!0:g.compare(this,t)===0},g.prototype.inspect=function(){var t="",r=xl;return this.length>0&&(t=this.toString("hex",0,r).match(/.{2}/g).join(" "),this.length>r&&(t+=" ... ")),"<Buffer "+t+">"},g.prototype.compare=function(t,r,n,i,a){if(!ye(t))throw new TypeError("Argument must be a Buffer");if(r===void 0&&(r=0),n===void 0&&(n=t?t.length:0),i===void 0&&(i=0),a===void 0&&(a=this.length),r<0||n>t.length||i<0||a>this.length)throw new RangeError("out of range index");if(i>=a&&r>=n)return 0;if(i>=a)return-1;if(r>=n)return 1;if(r>>>=0,n>>>=0,i>>>=0,a>>>=0,this===t)return 0;for(var o=a-i,s=n-r,f=Math.min(o,s),c=this.slice(i,a),l=t.slice(r,n),h=0;h<f;++h)if(c[h]!==l[h]){o=c[h],s=l[h];break}return o<s?-1:s<o?1:0};function Oo(e,t,r,n,i){if(e.length===0)return-1;if(typeof r=="string"?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,isNaN(r)&&(r=i?0:e.length-1),r<0&&(r=e.length+r),r>=e.length){if(i)return-1;r=e.length-1}else if(r<0)if(i)r=0;else return-1;if(typeof t=="string"&&(t=g.from(t,n)),ye(t))return t.length===0?-1:Io(e,t,r,n,i);if(typeof t=="number")return t=t&255,g.TYPED_ARRAY_SUPPORT&&typeof Uint8Array.prototype.indexOf=="function"?i?Uint8Array.prototype.indexOf.call(e,t,r):Uint8Array.prototype.lastIndexOf.call(e,t,r):Io(e,[t],r,n,i);throw new TypeError("val must be string, number or Buffer")}function Io(e,t,r,n,i){var a=1,o=e.length,s=t.length;if(n!==void 0&&(n=String(n).toLowerCase(),n==="ucs2"||n==="ucs-2"||n==="utf16le"||n==="utf-16le")){if(e.length<2||t.length<2)return-1;a=2,o/=2,s/=2,r/=2}function f(u,p){return a===1?u[p]:u.readUInt16BE(p*a)}var c;if(i){var l=-1;for(c=r;c<o;c++)if(f(e,c)===f(t,l===-1?0:c-l)){if(l===-1&&(l=c),c-l+1===s)return l*a}else l!==-1&&(c-=c-l),l=-1}else for(r+s>o&&(r=o-s),c=r;c>=0;c--){for(var h=!0,d=0;d<s;d++)if(f(e,c+d)!==f(t,d)){h=!1;break}if(h)return c}return-1}g.prototype.includes=function(t,r,n){return this.indexOf(t,r,n)!==-1},g.prototype.indexOf=function(t,r,n){return Oo(this,t,r,n,!0)},g.prototype.lastIndexOf=function(t,r,n){return Oo(this,t,r,n,!1)};function Ol(e,t,r,n){r=Number(r)||0;var i=e.length-r;n?(n=Number(n),n>i&&(n=i)):n=i;var a=t.length;if(a%2!==0)throw new TypeError("Invalid hex string");n>a/2&&(n=a/2);for(var o=0;o<n;++o){var s=parseInt(t.substr(o*2,2),16);if(isNaN(s))return o;e[r+o]=s}return o}function Il(e,t,r,n){return dr(hr(t,e.length-r),e,r,n)}function To(e,t,r,n){return dr(Zl(t),e,r,n)}function Tl(e,t,r,n){return To(e,t,r,n)}function Pl(e,t,r,n){return dr(Mo(t),e,r,n)}function jl(e,t,r,n){return dr(ql(t,e.length-r),e,r,n)}g.prototype.write=function(t,r,n,i){if(r===void 0)i="utf8",n=this.length,r=0;else if(n===void 0&&typeof r=="string")i=r,n=this.length,r=0;else if(isFinite(r))r=r|0,isFinite(n)?(n=n|0,i===void 0&&(i="utf8")):(i=n,n=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");var a=this.length-r;if((n===void 0||n>a)&&(n=a),t.length>0&&(n<0||r<0)||r>this.length)throw new RangeError("Attempt to write outside buffer bounds");i||(i="utf8");for(var o=!1;;)switch(i){case"hex":return Ol(this,t,r,n);case"utf8":case"utf-8":return Il(this,t,r,n);case"ascii":return To(this,t,r,n);case"latin1":case"binary":return Tl(this,t,r,n);case"base64":return Pl(this,t,r,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return jl(this,t,r,n);default:if(o)throw new TypeError("Unknown encoding: "+i);i=(""+i).toLowerCase(),o=!0}},g.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function Fl(e,t,r){return t===0&&r===e.length?xo(e):xo(e.slice(t,r))}function Po(e,t,r){r=Math.min(e.length,r);for(var n=[],i=t;i<r;){var a=e[i],o=null,s=a>239?4:a>223?3:a>191?2:1;if(i+s<=r){var f,c,l,h;switch(s){case 1:a<128&&(o=a);break;case 2:f=e[i+1],(f&192)===128&&(h=(a&31)<<6|f&63,h>127&&(o=h));break;case 3:f=e[i+1],c=e[i+2],(f&192)===128&&(c&192)===128&&(h=(a&15)<<12|(f&63)<<6|c&63,h>2047&&(h<55296||h>57343)&&(o=h));break;case 4:f=e[i+1],c=e[i+2],l=e[i+3],(f&192)===128&&(c&192)===128&&(l&192)===128&&(h=(a&15)<<18|(f&63)<<12|(c&63)<<6|l&63,h>65535&&h<1114112&&(o=h))}}o===null?(o=65533,s=1):o>65535&&(o-=65536,n.push(o>>>10&1023|55296),o=56320|o&1023),n.push(o),i+=s}return Cl(n)}var jo=4096;function Cl(e){var t=e.length;if(t<=jo)return String.fromCharCode.apply(String,e);for(var r="",n=0;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=jo));return r}function Dl(e,t,r){var n="";r=Math.min(e.length,r);for(var i=t;i<r;++i)n+=String.fromCharCode(e[i]&127);return n}function Ml(e,t,r){var n="";r=Math.min(e.length,r);for(var i=t;i<r;++i)n+=String.fromCharCode(e[i]);return n}function Nl(e,t,r){var n=e.length;(!t||t<0)&&(t=0),(!r||r<0||r>n)&&(r=n);for(var i="",a=t;a<r;++a)i+=zl(e[a]);return i}function Ll(e,t,r){for(var n=e.slice(t,r),i="",a=0;a<n.length;a+=2)i+=String.fromCharCode(n[a]+n[a+1]*256);return i}g.prototype.slice=function(t,r){var n=this.length;t=~~t,r=r===void 0?n:~~r,t<0?(t+=n,t<0&&(t=0)):t>n&&(t=n),r<0?(r+=n,r<0&&(r=0)):r>n&&(r=n),r<t&&(r=t);var i;if(g.TYPED_ARRAY_SUPPORT)i=this.subarray(t,r),i.__proto__=g.prototype;else{var a=r-t;i=new g(a,void 0);for(var o=0;o<a;++o)i[o]=this[o+t]}return i};function B(e,t,r){if(e%1!==0||e<0)throw new RangeError("offset is not uint");if(e+t>r)throw new RangeError("Trying to access beyond buffer length")}g.prototype.readUIntLE=function(t,r,n){t=t|0,r=r|0,n||B(t,r,this.length);for(var i=this[t],a=1,o=0;++o<r&&(a*=256);)i+=this[t+o]*a;return i},g.prototype.readUIntBE=function(t,r,n){t=t|0,r=r|0,n||B(t,r,this.length);for(var i=this[t+--r],a=1;r>0&&(a*=256);)i+=this[t+--r]*a;return i},g.prototype.readUInt8=function(t,r){return r||B(t,1,this.length),this[t]},g.prototype.readUInt16LE=function(t,r){return r||B(t,2,this.length),this[t]|this[t+1]<<8},g.prototype.readUInt16BE=function(t,r){return r||B(t,2,this.length),this[t]<<8|this[t+1]},g.prototype.readUInt32LE=function(t,r){return r||B(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+this[t+3]*16777216},g.prototype.readUInt32BE=function(t,r){return r||B(t,4,this.length),this[t]*16777216+(this[t+1]<<16|this[t+2]<<8|this[t+3])},g.prototype.readIntLE=function(t,r,n){t=t|0,r=r|0,n||B(t,r,this.length);for(var i=this[t],a=1,o=0;++o<r&&(a*=256);)i+=this[t+o]*a;return a*=128,i>=a&&(i-=Math.pow(2,8*r)),i},g.prototype.readIntBE=function(t,r,n){t=t|0,r=r|0,n||B(t,r,this.length);for(var i=r,a=1,o=this[t+--i];i>0&&(a*=256);)o+=this[t+--i]*a;return a*=128,o>=a&&(o-=Math.pow(2,8*r)),o},g.prototype.readInt8=function(t,r){return r||B(t,1,this.length),this[t]&128?(255-this[t]+1)*-1:this[t]},g.prototype.readInt16LE=function(t,r){r||B(t,2,this.length);var n=this[t]|this[t+1]<<8;return n&32768?n|4294901760:n},g.prototype.readInt16BE=function(t,r){r||B(t,2,this.length);var n=this[t+1]|this[t]<<8;return n&32768?n|4294901760:n},g.prototype.readInt32LE=function(t,r){return r||B(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},g.prototype.readInt32BE=function(t,r){return r||B(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},g.prototype.readFloatLE=function(t,r){return r||B(t,4,this.length),cr(this,t,!0,23,4)},g.prototype.readFloatBE=function(t,r){return r||B(t,4,this.length),cr(this,t,!1,23,4)},g.prototype.readDoubleLE=function(t,r){return r||B(t,8,this.length),cr(this,t,!0,52,8)},g.prototype.readDoubleBE=function(t,r){return r||B(t,8,this.length),cr(this,t,!1,52,8)};function X(e,t,r,n,i,a){if(!ye(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>i||t<a)throw new RangeError('"value" argument is out of bounds');if(r+n>e.length)throw new RangeError("Index out of range")}g.prototype.writeUIntLE=function(t,r,n,i){if(t=+t,r=r|0,n=n|0,!i){var a=Math.pow(2,8*n)-1;X(this,t,r,n,a,0)}var o=1,s=0;for(this[r]=t&255;++s<n&&(o*=256);)this[r+s]=t/o&255;return r+n},g.prototype.writeUIntBE=function(t,r,n,i){if(t=+t,r=r|0,n=n|0,!i){var a=Math.pow(2,8*n)-1;X(this,t,r,n,a,0)}var o=n-1,s=1;for(this[r+o]=t&255;--o>=0&&(s*=256);)this[r+o]=t/s&255;return r+n},g.prototype.writeUInt8=function(t,r,n){return t=+t,r=r|0,n||X(this,t,r,1,255,0),g.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[r]=t&255,r+1};function lr(e,t,r,n){t<0&&(t=65535+t+1);for(var i=0,a=Math.min(e.length-r,2);i<a;++i)e[r+i]=(t&255<<8*(n?i:1-i))>>>(n?i:1-i)*8}g.prototype.writeUInt16LE=function(t,r,n){return t=+t,r=r|0,n||X(this,t,r,2,65535,0),g.TYPED_ARRAY_SUPPORT?(this[r]=t&255,this[r+1]=t>>>8):lr(this,t,r,!0),r+2},g.prototype.writeUInt16BE=function(t,r,n){return t=+t,r=r|0,n||X(this,t,r,2,65535,0),g.TYPED_ARRAY_SUPPORT?(this[r]=t>>>8,this[r+1]=t&255):lr(this,t,r,!1),r+2};function ur(e,t,r,n){t<0&&(t=4294967295+t+1);for(var i=0,a=Math.min(e.length-r,4);i<a;++i)e[r+i]=t>>>(n?i:3-i)*8&255}g.prototype.writeUInt32LE=function(t,r,n){return t=+t,r=r|0,n||X(this,t,r,4,4294967295,0),g.TYPED_ARRAY_SUPPORT?(this[r+3]=t>>>24,this[r+2]=t>>>16,this[r+1]=t>>>8,this[r]=t&255):ur(this,t,r,!0),r+4},g.prototype.writeUInt32BE=function(t,r,n){return t=+t,r=r|0,n||X(this,t,r,4,4294967295,0),g.TYPED_ARRAY_SUPPORT?(this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=t&255):ur(this,t,r,!1),r+4},g.prototype.writeIntLE=function(t,r,n,i){if(t=+t,r=r|0,!i){var a=Math.pow(2,8*n-1);X(this,t,r,n,a-1,-a)}var o=0,s=1,f=0;for(this[r]=t&255;++o<n&&(s*=256);)t<0&&f===0&&this[r+o-1]!==0&&(f=1),this[r+o]=(t/s>>0)-f&255;return r+n},g.prototype.writeIntBE=function(t,r,n,i){if(t=+t,r=r|0,!i){var a=Math.pow(2,8*n-1);X(this,t,r,n,a-1,-a)}var o=n-1,s=1,f=0;for(this[r+o]=t&255;--o>=0&&(s*=256);)t<0&&f===0&&this[r+o+1]!==0&&(f=1),this[r+o]=(t/s>>0)-f&255;return r+n},g.prototype.writeInt8=function(t,r,n){return t=+t,r=r|0,n||X(this,t,r,1,127,-128),g.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[r]=t&255,r+1},g.prototype.writeInt16LE=function(t,r,n){return t=+t,r=r|0,n||X(this,t,r,2,32767,-32768),g.TYPED_ARRAY_SUPPORT?(this[r]=t&255,this[r+1]=t>>>8):lr(this,t,r,!0),r+2},g.prototype.writeInt16BE=function(t,r,n){return t=+t,r=r|0,n||X(this,t,r,2,32767,-32768),g.TYPED_ARRAY_SUPPORT?(this[r]=t>>>8,this[r+1]=t&255):lr(this,t,r,!1),r+2},g.prototype.writeInt32LE=function(t,r,n){return t=+t,r=r|0,n||X(this,t,r,4,2147483647,-2147483648),g.TYPED_ARRAY_SUPPORT?(this[r]=t&255,this[r+1]=t>>>8,this[r+2]=t>>>16,this[r+3]=t>>>24):ur(this,t,r,!0),r+4},g.prototype.writeInt32BE=function(t,r,n){return t=+t,r=r|0,n||X(this,t,r,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),g.TYPED_ARRAY_SUPPORT?(this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=t&255):ur(this,t,r,!1),r+4};function Fo(e,t,r,n,i,a){if(r+n>e.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function Co(e,t,r,n,i){return i||Fo(e,t,r,4),Eo(e,t,r,n,23,4),r+4}g.prototype.writeFloatLE=function(t,r,n){return Co(this,t,r,!0,n)},g.prototype.writeFloatBE=function(t,r,n){return Co(this,t,r,!1,n)};function Do(e,t,r,n,i){return i||Fo(e,t,r,8),Eo(e,t,r,n,52,8),r+8}g.prototype.writeDoubleLE=function(t,r,n){return Do(this,t,r,!0,n)},g.prototype.writeDoubleBE=function(t,r,n){return Do(this,t,r,!1,n)},g.prototype.copy=function(t,r,n,i){if(n||(n=0),!i&&i!==0&&(i=this.length),r>=t.length&&(r=t.length),r||(r=0),i>0&&i<n&&(i=n),i===n||t.length===0||this.length===0)return 0;if(r<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("sourceStart out of bounds");if(i<0)throw new RangeError("sourceEnd out of bounds");i>this.length&&(i=this.length),t.length-r<i-n&&(i=t.length-r+n);var a=i-n,o;if(this===t&&n<r&&r<i)for(o=a-1;o>=0;--o)t[o+r]=this[o+n];else if(a<1e3||!g.TYPED_ARRAY_SUPPORT)for(o=0;o<a;++o)t[o+r]=this[o+n];else Uint8Array.prototype.set.call(t,this.subarray(n,n+a),r);return a},g.prototype.fill=function(t,r,n,i){if(typeof t=="string"){if(typeof r=="string"?(i=r,r=0,n=this.length):typeof n=="string"&&(i=n,n=this.length),t.length===1){var a=t.charCodeAt(0);a<256&&(t=a)}if(i!==void 0&&typeof i!="string")throw new TypeError("encoding must be a string");if(typeof i=="string"&&!g.isEncoding(i))throw new TypeError("Unknown encoding: "+i)}else typeof t=="number"&&(t=t&255);if(r<0||this.length<r||this.length<n)throw new RangeError("Out of range index");if(n<=r)return this;r=r>>>0,n=n===void 0?this.length:n>>>0,t||(t=0);var o;if(typeof t=="number")for(o=r;o<n;++o)this[o]=t;else{var s=ye(t)?t:hr(new g(t,i).toString()),f=s.length;for(o=0;o<n-r;++o)this[o+r]=s[o%f]}return this};var $l=/[^+\/0-9A-Za-z-_]/g;function Ul(e){if(e=Bl(e).replace($l,""),e.length<2)return"";for(;e.length%4!==0;)e=e+"=";return e}function Bl(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}function zl(e){return e<16?"0"+e.toString(16):e.toString(16)}function hr(e,t){t=t||1/0;for(var r,n=e.length,i=null,a=[],o=0;o<n;++o){if(r=e.charCodeAt(o),r>55295&&r<57344){if(!i){if(r>56319){(t-=3)>-1&&a.push(239,191,189);continue}else if(o+1===n){(t-=3)>-1&&a.push(239,191,189);continue}i=r;continue}if(r<56320){(t-=3)>-1&&a.push(239,191,189),i=r;continue}r=(i-55296<<10|r-56320)+65536}else i&&(t-=3)>-1&&a.push(239,191,189);if(i=null,r<128){if((t-=1)<0)break;a.push(r)}else if(r<2048){if((t-=2)<0)break;a.push(r>>6|192,r&63|128)}else if(r<65536){if((t-=3)<0)break;a.push(r>>12|224,r>>6&63|128,r&63|128)}else if(r<1114112){if((t-=4)<0)break;a.push(r>>18|240,r>>12&63|128,r>>6&63|128,r&63|128)}else throw new Error("Invalid code point")}return a}function Zl(e){for(var t=[],r=0;r<e.length;++r)t.push(e.charCodeAt(r)&255);return t}function ql(e,t){for(var r,n,i,a=[],o=0;o<e.length&&!((t-=2)<0);++o)r=e.charCodeAt(o),n=r>>8,i=r%256,a.push(i),a.push(n);return a}function Mo(e){return wl(Ul(e))}function dr(e,t,r,n){for(var i=0;i<n&&!(i+r>=t.length||i>=e.length);++i)t[i+r]=e[i];return i}function Hl(e){return e!==e}function Kl(e){return e!=null&&(!!e._isBuffer||No(e)||Wl(e))}function No(e){return!!e.constructor&&typeof e.constructor.isBuffer=="function"&&e.constructor.isBuffer(e)}function Wl(e){return typeof e.readFloatLE=="function"&&typeof e.slice=="function"&&No(e.slice(0,0))}function Lo(){throw new Error("setTimeout has not been defined")}function $o(){throw new Error("clearTimeout has not been defined")}var Te=Lo,Pe=$o;typeof ht.setTimeout=="function"&&(Te=setTimeout),typeof ht.clearTimeout=="function"&&(Pe=clearTimeout);function Uo(e){if(Te===setTimeout)return setTimeout(e,0);if((Te===Lo||!Te)&&setTimeout)return Te=setTimeout,setTimeout(e,0);try{return Te(e,0)}catch{try{return Te.call(null,e,0)}catch{return Te.call(this,e,0)}}}function Vl(e){if(Pe===clearTimeout)return clearTimeout(e);if((Pe===$o||!Pe)&&clearTimeout)return Pe=clearTimeout,clearTimeout(e);try{return Pe(e)}catch{try{return Pe.call(null,e)}catch{return Pe.call(this,e)}}}var Ee=[],dt=!1,We,pr=-1;function Gl(){!dt||!We||(dt=!1,We.length?Ee=We.concat(Ee):pr=-1,Ee.length&&Bo())}function Bo(){if(!dt){var e=Uo(Gl);dt=!0;for(var t=Ee.length;t;){for(We=Ee,Ee=[];++pr<t;)We&&We[pr].run();pr=-1,t=Ee.length}We=null,dt=!1,Vl(e)}}function ee(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var r=1;r<arguments.length;r++)t[r-1]=arguments[r];Ee.push(new zo(e,t)),Ee.length===1&&!dt&&Uo(Bo)}function zo(e,t){this.fun=e,this.array=t}zo.prototype.run=function(){this.fun.apply(null,this.array)};var Yl="browser",Jl="browser",Xl=!0,Ql={},eu=[],tu="",ru={},nu={},iu={};function Ve(){}var au=Ve,ou=Ve,su=Ve,cu=Ve,fu=Ve,lu=Ve,uu=Ve;function hu(e){throw new Error("process.binding is not supported")}function du(){return"/"}function pu(e){throw new Error("process.chdir is not supported")}function yu(){return 0}var pt=ht.performance||{},gu=pt.now||pt.mozNow||pt.msNow||pt.oNow||pt.webkitNow||function(){return new Date().getTime()};function vu(e){var t=gu.call(pt)*.001,r=Math.floor(t),n=Math.floor(t%1*1e9);return e&&(r=r-e[0],n=n-e[1],n<0&&(r--,n+=1e9)),[r,n]}var wu=new Date;function bu(){var e=new Date,t=e-wu;return t/1e3}var Se={nextTick:ee,title:Yl,browser:Xl,env:Ql,argv:eu,version:tu,versions:ru,on:au,addListener:ou,once:su,off:cu,removeListener:fu,removeAllListeners:lu,emit:uu,binding:hu,cwd:du,chdir:pu,umask:yu,hrtime:vu,platform:Jl,release:nu,config:iu,uptime:bu},W;typeof Object.create=="function"?W=function(t,r){t.super_=r,t.prototype=Object.create(r.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}})}:W=function(t,r){t.super_=r;var n=function(){};n.prototype=r.prototype,t.prototype=new n,t.prototype.constructor=t};var _u=/%[sdj%]/g;function mu(e){if(!ti(e)){for(var t=[],r=0;r<arguments.length;r++)t.push(je(arguments[r]));return t.join(" ")}for(var r=1,n=arguments,i=n.length,a=String(e).replace(_u,function(s){if(s==="%%")return"%";if(r>=i)return s;switch(s){case"%s":return String(n[r++]);case"%d":return Number(n[r++]);case"%j":try{return JSON.stringify(n[r++])}catch{return"[Circular]"}default:return s}}),o=n[r];r<i;o=n[++r])ei(o)||!Tt(o)?a+=" "+o:a+=" "+je(o);return a}function Zo(e,t){if(Fe(ht.process))return function(){return Zo(e,t).apply(this,arguments)};if(Se.noDeprecation===!0)return e;var r=!1;function n(){if(!r){if(Se.throwDeprecation)throw new Error(t);Se.traceDeprecation?console.trace(t):console.error(t),r=!0}return e.apply(this,arguments)}return n}var yr={},Jn;function xu(e){if(Fe(Jn)&&(Jn=Se.env.NODE_DEBUG||""),e=e.toUpperCase(),!yr[e])if(new RegExp("\\b"+e+"\\b","i").test(Jn)){var t=0;yr[e]=function(){var r=mu.apply(null,arguments);console.error("%s %d: %s",e,t,r)}}else yr[e]=function(){};return yr[e]}function je(e,t){var r={seen:[],stylize:Su};return arguments.length>=3&&(r.depth=arguments[2]),arguments.length>=4&&(r.colors=arguments[3]),qo(t)?r.showHidden=t:t&&Pu(r,t),Fe(r.showHidden)&&(r.showHidden=!1),Fe(r.depth)&&(r.depth=2),Fe(r.colors)&&(r.colors=!1),Fe(r.customInspect)&&(r.customInspect=!0),r.colors&&(r.stylize=Eu),gr(r,e,r.depth)}je.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},je.styles={special:"cyan",number:"yellow",boolean:"yellow",undefined:"grey",null:"bold",string:"green",date:"magenta",regexp:"red"};function Eu(e,t){var r=je.styles[t];return r?"\x1B["+je.colors[r][0]+"m"+e+"\x1B["+je.colors[r][1]+"m":e}function Su(e,t){return e}function Au(e){var t={};return e.forEach(function(r,n){t[r]=!0}),t}function gr(e,t,r){if(e.customInspect&&t&&ii(t.inspect)&&t.inspect!==je&&!(t.constructor&&t.constructor.prototype===t)){var n=t.inspect(r,e);return ti(n)||(n=gr(e,n,r)),n}var i=ku(e,t);if(i)return i;var a=Object.keys(t),o=Au(a);if(e.showHidden&&(a=Object.getOwnPropertyNames(t)),ni(t)&&(a.indexOf("message")>=0||a.indexOf("description")>=0))return Xn(t);if(a.length===0){if(ii(t)){var s=t.name?": "+t.name:"";return e.stylize("[Function"+s+"]","special")}if(ri(t))return e.stylize(RegExp.prototype.toString.call(t),"regexp");if(Ho(t))return e.stylize(Date.prototype.toString.call(t),"date");if(ni(t))return Xn(t)}var f="",c=!1,l=["{","}"];if(Iu(t)&&(c=!0,l=["[","]"]),ii(t)){var h=t.name?": "+t.name:"";f=" [Function"+h+"]"}if(ri(t)&&(f=" "+RegExp.prototype.toString.call(t)),Ho(t)&&(f=" "+Date.prototype.toUTCString.call(t)),ni(t)&&(f=" "+Xn(t)),a.length===0&&(!c||t.length==0))return l[0]+f+l[1];if(r<0)return ri(t)?e.stylize(RegExp.prototype.toString.call(t),"regexp"):e.stylize("[Object]","special");e.seen.push(t);var d;return c?d=Ru(e,t,r,o,a):d=a.map(function(u){return Qn(e,t,r,o,u,c)}),e.seen.pop(),Ou(d,f,l)}function ku(e,t){if(Fe(t))return e.stylize("undefined","undefined");if(ti(t)){var r="'"+JSON.stringify(t).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return e.stylize(r,"string")}if(Tu(t))return e.stylize(""+t,"number");if(qo(t))return e.stylize(""+t,"boolean");if(ei(t))return e.stylize("null","null")}function Xn(e){return"["+Error.prototype.toString.call(e)+"]"}function Ru(e,t,r,n,i){for(var a=[],o=0,s=t.length;o<s;++o)Ko(t,String(o))?a.push(Qn(e,t,r,n,String(o),!0)):a.push("");return i.forEach(function(f){f.match(/^\d+$/)||a.push(Qn(e,t,r,n,f,!0))}),a}function Qn(e,t,r,n,i,a){var o,s,f;if(f=Object.getOwnPropertyDescriptor(t,i)||{value:t[i]},f.get?f.set?s=e.stylize("[Getter/Setter]","special"):s=e.stylize("[Getter]","special"):f.set&&(s=e.stylize("[Setter]","special")),Ko(n,i)||(o="["+i+"]"),s||(e.seen.indexOf(f.value)<0?(ei(r)?s=gr(e,f.value,null):s=gr(e,f.value,r-1),s.indexOf(`
21
21
  `)>-1&&(a?s=s.split(`
22
22
  `).map(function(c){return" "+c}).join(`
23
23
  `).substr(2):s=`
24
24
  `+s.split(`
25
25
  `).map(function(c){return" "+c}).join(`
26
- `))):s=e.stylize("[Circular]","special")),Fe(o)){if(a&&i.match(/^\d+$/))return s;o=JSON.stringify(""+i),o.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(o=o.substr(1,o.length-2),o=e.stylize(o,"name")):(o=o.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),o=e.stylize(o,"string"))}return o+": "+s}function Ru(e,t,r){var n=e.reduce(function(i,a){return a.indexOf(`
26
+ `))):s=e.stylize("[Circular]","special")),Fe(o)){if(a&&i.match(/^\d+$/))return s;o=JSON.stringify(""+i),o.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(o=o.substr(1,o.length-2),o=e.stylize(o,"name")):(o=o.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),o=e.stylize(o,"string"))}return o+": "+s}function Ou(e,t,r){var n=e.reduce(function(i,a){return a.indexOf(`
27
27
  `)>=0,i+a.replace(/\u001b\[\d\d?m/g,"").length+1},0);return n>60?r[0]+(t===""?"":t+`
28
28
  `)+" "+e.join(`,
29
- `)+" "+r[1]:r[0]+t+" "+e.join(", ")+" "+r[1]}function Ou(e){return Array.isArray(e)}function Zo(e){return typeof e=="boolean"}function Qn(e){return e===null}function Iu(e){return typeof e=="number"}function ei(e){return typeof e=="string"}function Fe(e){return e===void 0}function ti(e){return Tt(e)&&ii(e)==="[object RegExp]"}function Tt(e){return typeof e=="object"&&e!==null}function qo(e){return Tt(e)&&ii(e)==="[object Date]"}function ri(e){return Tt(e)&&(ii(e)==="[object Error]"||e instanceof Error)}function ni(e){return typeof e=="function"}function ii(e){return Object.prototype.toString.call(e)}function Tu(e,t){if(!t||!Tt(t))return e;for(var r=Object.keys(t),n=r.length;n--;)e[r[n]]=t[r[n]];return e}function Ho(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Ge(){this.head=null,this.tail=null,this.length=0}Ge.prototype.push=function(e){var t={data:e,next:null};this.length>0?this.tail.next=t:this.head=t,this.tail=t,++this.length},Ge.prototype.unshift=function(e){var t={data:e,next:this.head};this.length===0&&(this.tail=t),this.head=t,++this.length},Ge.prototype.shift=function(){if(this.length!==0){var e=this.head.data;return this.length===1?this.head=this.tail=null:this.head=this.head.next,--this.length,e}},Ge.prototype.clear=function(){this.head=this.tail=null,this.length=0},Ge.prototype.join=function(e){if(this.length===0)return"";for(var t=this.head,r=""+t.data;t=t.next;)r+=e+t.data;return r},Ge.prototype.concat=function(e){if(this.length===0)return g.alloc(0);if(this.length===1)return this.head.data;for(var t=g.allocUnsafe(e>>>0),r=this.head,n=0;r;)r.data.copy(t,n),n+=r.data.length,r=r.next;return t};var Pu=g.isEncoding||function(e){switch(e&&e.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1}};function ju(e){if(e&&!Pu(e))throw new Error("Unknown encoding: "+e)}function Pt(e){switch(this.encoding=(e||"utf8").toLowerCase().replace(/[-_]/,""),ju(e),this.encoding){case"utf8":this.surrogateSize=3;break;case"ucs2":case"utf16le":this.surrogateSize=2,this.detectIncompleteChar=Cu;break;case"base64":this.surrogateSize=3,this.detectIncompleteChar=Du;break;default:this.write=Fu;return}this.charBuffer=new g(6),this.charReceived=0,this.charLength=0}Pt.prototype.write=function(e){for(var t="";this.charLength;){var r=e.length>=this.charLength-this.charReceived?this.charLength-this.charReceived:e.length;if(e.copy(this.charBuffer,this.charReceived,0,r),this.charReceived+=r,this.charReceived<this.charLength)return"";e=e.slice(r,e.length),t=this.charBuffer.slice(0,this.charLength).toString(this.encoding);var i=t.charCodeAt(t.length-1);if(i>=55296&&i<=56319){this.charLength+=this.surrogateSize,t="";continue}if(this.charReceived=this.charLength=0,e.length===0)return t;break}this.detectIncompleteChar(e);var n=e.length;this.charLength&&(e.copy(this.charBuffer,0,e.length-this.charReceived,n),n-=this.charReceived),t+=e.toString(this.encoding,0,n);var n=t.length-1,i=t.charCodeAt(n);if(i>=55296&&i<=56319){var a=this.surrogateSize;return this.charLength+=a,this.charReceived+=a,this.charBuffer.copy(this.charBuffer,a,0,a),e.copy(this.charBuffer,0,0,a),t.substring(0,n)}return t},Pt.prototype.detectIncompleteChar=function(e){for(var t=e.length>=3?3:e.length;t>0;t--){var r=e[e.length-t];if(t==1&&r>>5==6){this.charLength=2;break}if(t<=2&&r>>4==14){this.charLength=3;break}if(t<=3&&r>>3==30){this.charLength=4;break}}this.charReceived=t},Pt.prototype.end=function(e){var t="";if(e&&e.length&&(t=this.write(e)),this.charReceived){var r=this.charReceived,n=this.charBuffer,i=this.encoding;t+=n.slice(0,r).toString(i)}return t};function Fu(e){return e.toString(this.encoding)}function Cu(e){this.charReceived=e.length%2,this.charLength=this.charReceived?2:0}function Du(e){this.charReceived=e.length%3,this.charLength=this.charReceived?3:0}L.ReadableState=Ko;var j=mu("stream");W(L,R);function Mu(e,t,r){if(typeof e.prependListener=="function")return e.prependListener(t,r);!e._events||!e._events[t]?e.on(t,r):Array.isArray(e._events[t])?e._events[t].unshift(r):e._events[t]=[r,e._events[t]]}function Lu(e,t){return e.listeners(t).length}function Ko(e,t){e=e||{},this.objectMode=!!e.objectMode,t instanceof ae&&(this.objectMode=this.objectMode||!!e.readableObjectMode);var r=e.highWaterMark,n=this.objectMode?16:16*1024;this.highWaterMark=r||r===0?r:n,this.highWaterMark=~~this.highWaterMark,this.buffer=new Ge,this.length=0,this.pipes=null,this.pipesCount=0,this.flowing=null,this.ended=!1,this.endEmitted=!1,this.reading=!1,this.sync=!0,this.needReadable=!1,this.emittedReadable=!1,this.readableListening=!1,this.resumeScheduled=!1,this.defaultEncoding=e.defaultEncoding||"utf8",this.ranOut=!1,this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,e.encoding&&(this.decoder=new Pt(e.encoding),this.encoding=e.encoding)}function L(e){if(!(this instanceof L))return new L(e);this._readableState=new Ko(e,this),this.readable=!0,e&&typeof e.read=="function"&&(this._read=e.read),R.call(this)}L.prototype.push=function(e,t){var r=this._readableState;return!r.objectMode&&typeof e=="string"&&(t=t||r.defaultEncoding,t!==r.encoding&&(e=g.from(e,t),t="")),Wo(this,r,e,t,!1)},L.prototype.unshift=function(e){var t=this._readableState;return Wo(this,t,e,"",!0)},L.prototype.isPaused=function(){return this._readableState.flowing===!1};function Wo(e,t,r,n,i){var a=Uu(t,r);if(a)e.emit("error",a);else if(r===null)t.reading=!1,Bu(e,t);else if(t.objectMode||r&&r.length>0)if(t.ended&&!i){var o=new Error("stream.push() after EOF");e.emit("error",o)}else if(t.endEmitted&&i){var s=new Error("stream.unshift() after end event");e.emit("error",s)}else{var f;t.decoder&&!i&&!n&&(r=t.decoder.write(r),f=!t.objectMode&&r.length===0),i||(t.reading=!1),f||(t.flowing&&t.length===0&&!t.sync?(e.emit("data",r),e.read(0)):(t.length+=t.objectMode?1:r.length,i?t.buffer.unshift(r):t.buffer.push(r),t.needReadable&&vr(e))),zu(e,t)}else i||(t.reading=!1);return Nu(t)}function Nu(e){return!e.ended&&(e.needReadable||e.length<e.highWaterMark||e.length===0)}L.prototype.setEncoding=function(e){return this._readableState.decoder=new Pt(e),this._readableState.encoding=e,this};var Vo=8388608;function $u(e){return e>=Vo?e=Vo:(e--,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e++),e}function Go(e,t){return e<=0||t.length===0&&t.ended?0:t.objectMode?1:e!==e?t.flowing&&t.length?t.buffer.head.data.length:t.length:(e>t.highWaterMark&&(t.highWaterMark=$u(e)),e<=t.length?e:t.ended?t.length:(t.needReadable=!0,0))}L.prototype.read=function(e){j("read",e),e=parseInt(e,10);var t=this._readableState,r=e;if(e!==0&&(t.emittedReadable=!1),e===0&&t.needReadable&&(t.length>=t.highWaterMark||t.ended))return j("read: emitReadable",t.length,t.ended),t.length===0&&t.ended?oi(this):vr(this),null;if(e=Go(e,t),e===0&&t.ended)return t.length===0&&oi(this),null;var n=t.needReadable;j("need readable",n),(t.length===0||t.length-e<t.highWaterMark)&&(n=!0,j("length less than watermark",n)),t.ended||t.reading?(n=!1,j("reading or ended",n)):n&&(j("do read"),t.reading=!0,t.sync=!0,t.length===0&&(t.needReadable=!0),this._read(t.highWaterMark),t.sync=!1,t.reading||(e=Go(r,t)));var i;return e>0?i=Jo(e,t):i=null,i===null?(t.needReadable=!0,e=0):t.length-=e,t.length===0&&(t.ended||(t.needReadable=!0),r!==e&&t.ended&&oi(this)),i!==null&&this.emit("data",i),i};function Uu(e,t){var r=null;return!g.isBuffer(t)&&typeof t!="string"&&t!==null&&t!==void 0&&!e.objectMode&&(r=new TypeError("Invalid non-string/buffer chunk")),r}function Bu(e,t){if(!t.ended){if(t.decoder){var r=t.decoder.end();r&&r.length&&(t.buffer.push(r),t.length+=t.objectMode?1:r.length)}t.ended=!0,vr(e)}}function vr(e){var t=e._readableState;t.needReadable=!1,t.emittedReadable||(j("emitReadable",t.flowing),t.emittedReadable=!0,t.sync?ee(Yo,e):Yo(e))}function Yo(e){j("emit readable"),e.emit("readable"),ai(e)}function zu(e,t){t.readingMore||(t.readingMore=!0,ee(Zu,e,t))}function Zu(e,t){for(var r=t.length;!t.reading&&!t.flowing&&!t.ended&&t.length<t.highWaterMark&&(j("maybeReadMore read 0"),e.read(0),r!==t.length);)r=t.length;t.readingMore=!1}L.prototype._read=function(e){this.emit("error",new Error("not implemented"))},L.prototype.pipe=function(e,t){var r=this,n=this._readableState;switch(n.pipesCount){case 0:n.pipes=e;break;case 1:n.pipes=[n.pipes,e];break;default:n.pipes.push(e);break}n.pipesCount+=1,j("pipe count=%d opts=%j",n.pipesCount,t);var i=!t||t.end!==!1,a=i?s:l;n.endEmitted?ee(a):r.once("end",a),e.on("unpipe",o);function o(_){j("onunpipe"),_===r&&l()}function s(){j("onend"),e.end()}var f=qu(r);e.on("drain",f);var c=!1;function l(){j("cleanup"),e.removeListener("close",p),e.removeListener("finish",y),e.removeListener("drain",f),e.removeListener("error",u),e.removeListener("unpipe",o),r.removeListener("end",s),r.removeListener("end",l),r.removeListener("data",h),c=!0,n.awaitDrain&&(!e._writableState||e._writableState.needDrain)&&f()}var d=!1;r.on("data",h);function h(_){j("ondata"),d=!1;var m=e.write(_);m===!1&&!d&&((n.pipesCount===1&&n.pipes===e||n.pipesCount>1&&Xo(n.pipes,e)!==-1)&&!c&&(j("false write response, pause",r._readableState.awaitDrain),r._readableState.awaitDrain++,d=!0),r.pause())}function u(_){j("onerror",_),w(),e.removeListener("error",u),Lu(e,"error")===0&&e.emit("error",_)}Mu(e,"error",u);function p(){e.removeListener("finish",y),w()}e.once("close",p);function y(){j("onfinish"),e.removeListener("close",p),w()}e.once("finish",y);function w(){j("unpipe"),r.unpipe(e)}return e.emit("pipe",r),n.flowing||(j("pipe resume"),r.resume()),e};function qu(e){return function(){var t=e._readableState;j("pipeOnDrain",t.awaitDrain),t.awaitDrain&&t.awaitDrain--,t.awaitDrain===0&&e.listeners("data").length&&(t.flowing=!0,ai(e))}}L.prototype.unpipe=function(e){var t=this._readableState;if(t.pipesCount===0)return this;if(t.pipesCount===1)return e&&e!==t.pipes?this:(e||(e=t.pipes),t.pipes=null,t.pipesCount=0,t.flowing=!1,e&&e.emit("unpipe",this),this);if(!e){var r=t.pipes,n=t.pipesCount;t.pipes=null,t.pipesCount=0,t.flowing=!1;for(var i=0;i<n;i++)r[i].emit("unpipe",this);return this}var a=Xo(t.pipes,e);return a===-1?this:(t.pipes.splice(a,1),t.pipesCount-=1,t.pipesCount===1&&(t.pipes=t.pipes[0]),e.emit("unpipe",this),this)},L.prototype.on=function(e,t){var r=R.prototype.on.call(this,e,t);if(e==="data")this._readableState.flowing!==!1&&this.resume();else if(e==="readable"){var n=this._readableState;!n.endEmitted&&!n.readableListening&&(n.readableListening=n.needReadable=!0,n.emittedReadable=!1,n.reading?n.length&&vr(this):ee(Hu,this))}return r},L.prototype.addListener=L.prototype.on;function Hu(e){j("readable nexttick read 0"),e.read(0)}L.prototype.resume=function(){var e=this._readableState;return e.flowing||(j("resume"),e.flowing=!0,Ku(this,e)),this};function Ku(e,t){t.resumeScheduled||(t.resumeScheduled=!0,ee(Wu,e,t))}function Wu(e,t){t.reading||(j("resume read 0"),e.read(0)),t.resumeScheduled=!1,t.awaitDrain=0,e.emit("resume"),ai(e),t.flowing&&!t.reading&&e.read(0)}L.prototype.pause=function(){return j("call pause flowing=%j",this._readableState.flowing),this._readableState.flowing!==!1&&(j("pause"),this._readableState.flowing=!1,this.emit("pause")),this};function ai(e){var t=e._readableState;for(j("flow",t.flowing);t.flowing&&e.read()!==null;);}L.prototype.wrap=function(e){var t=this._readableState,r=!1,n=this;e.on("end",function(){if(j("wrapped end"),t.decoder&&!t.ended){var o=t.decoder.end();o&&o.length&&n.push(o)}n.push(null)}),e.on("data",function(o){if(j("wrapped data"),t.decoder&&(o=t.decoder.write(o)),!(t.objectMode&&o==null)&&!(!t.objectMode&&(!o||!o.length))){var s=n.push(o);s||(r=!0,e.pause())}});for(var i in e)this[i]===void 0&&typeof e[i]=="function"&&(this[i]=function(o){return function(){return e[o].apply(e,arguments)}}(i));var a=["error","close","destroy","pause","resume"];return Xu(a,function(o){e.on(o,n.emit.bind(n,o))}),n._read=function(o){j("wrapped _read",o),r&&(r=!1,e.resume())},n},L._fromList=Jo;function Jo(e,t){if(t.length===0)return null;var r;return t.objectMode?r=t.buffer.shift():!e||e>=t.length?(t.decoder?r=t.buffer.join(""):t.buffer.length===1?r=t.buffer.head.data:r=t.buffer.concat(t.length),t.buffer.clear()):r=Vu(e,t.buffer,t.decoder),r}function Vu(e,t,r){var n;return e<t.head.data.length?(n=t.head.data.slice(0,e),t.head.data=t.head.data.slice(e)):e===t.head.data.length?n=t.shift():n=r?Gu(e,t):Yu(e,t),n}function Gu(e,t){var r=t.head,n=1,i=r.data;for(e-=i.length;r=r.next;){var a=r.data,o=e>a.length?a.length:e;if(o===a.length?i+=a:i+=a.slice(0,e),e-=o,e===0){o===a.length?(++n,r.next?t.head=r.next:t.head=t.tail=null):(t.head=r,r.data=a.slice(o));break}++n}return t.length-=n,i}function Yu(e,t){var r=g.allocUnsafe(e),n=t.head,i=1;for(n.data.copy(r),e-=n.data.length;n=n.next;){var a=n.data,o=e>a.length?a.length:e;if(a.copy(r,r.length-e,0,o),e-=o,e===0){o===a.length?(++i,n.next?t.head=n.next:t.head=t.tail=null):(t.head=n,n.data=a.slice(o));break}++i}return t.length-=i,r}function oi(e){var t=e._readableState;if(t.length>0)throw new Error('"endReadable()" called on non-empty stream');t.endEmitted||(t.ended=!0,ee(Ju,t,e))}function Ju(e,t){!e.endEmitted&&e.length===0&&(e.endEmitted=!0,t.readable=!1,t.emit("end"))}function Xu(e,t){for(var r=0,n=e.length;r<n;r++)t(e[r],r)}function Xo(e,t){for(var r=0,n=e.length;r<n;r++)if(e[r]===t)return r;return-1}q.WritableState=si,W(q,R);function Qu(){}function eh(e,t,r){this.chunk=e,this.encoding=t,this.callback=r,this.next=null}function si(e,t){Object.defineProperty(this,"buffer",{get:zo(function(){return this.getBuffer()},"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.")}),e=e||{},this.objectMode=!!e.objectMode,t instanceof ae&&(this.objectMode=this.objectMode||!!e.writableObjectMode);var r=e.highWaterMark,n=this.objectMode?16:16*1024;this.highWaterMark=r||r===0?r:n,this.highWaterMark=~~this.highWaterMark,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1;var i=e.decodeStrings===!1;this.decodeStrings=!i,this.defaultEncoding=e.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(a){sh(t,a)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.bufferedRequestCount=0,this.corkedRequestsFree=new is(this)}si.prototype.getBuffer=function(){for(var t=this.bufferedRequest,r=[];t;)r.push(t),t=t.next;return r};function q(e){if(!(this instanceof q)&&!(this instanceof ae))return new q(e);this._writableState=new si(e,this),this.writable=!0,e&&(typeof e.write=="function"&&(this._write=e.write),typeof e.writev=="function"&&(this._writev=e.writev)),R.call(this)}q.prototype.pipe=function(){this.emit("error",new Error("Cannot pipe, not readable"))};function th(e,t){var r=new Error("write after end");e.emit("error",r),ee(t,r)}function rh(e,t,r,n){var i=!0,a=!1;return r===null?a=new TypeError("May not write null values to stream"):!g.isBuffer(r)&&typeof r!="string"&&r!==void 0&&!t.objectMode&&(a=new TypeError("Invalid non-string/buffer chunk")),a&&(e.emit("error",a),ee(n,a),i=!1),i}q.prototype.write=function(e,t,r){var n=this._writableState,i=!1;return typeof t=="function"&&(r=t,t=null),g.isBuffer(e)?t="buffer":t||(t=n.defaultEncoding),typeof r!="function"&&(r=Qu),n.ended?th(this,r):rh(this,n,e,r)&&(n.pendingcb++,i=ih(this,n,e,t,r)),i},q.prototype.cork=function(){var e=this._writableState;e.corked++},q.prototype.uncork=function(){var e=this._writableState;e.corked&&(e.corked--,!e.writing&&!e.corked&&!e.finished&&!e.bufferProcessing&&e.bufferedRequest&&es(this,e))},q.prototype.setDefaultEncoding=function(t){if(typeof t=="string"&&(t=t.toLowerCase()),!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((t+"").toLowerCase())>-1))throw new TypeError("Unknown encoding: "+t);return this._writableState.defaultEncoding=t,this};function nh(e,t,r){return!e.objectMode&&e.decodeStrings!==!1&&typeof t=="string"&&(t=g.from(t,r)),t}function ih(e,t,r,n,i){r=nh(t,r,n),g.isBuffer(r)&&(n="buffer");var a=t.objectMode?1:r.length;t.length+=a;var o=t.length<t.highWaterMark;if(o||(t.needDrain=!0),t.writing||t.corked){var s=t.lastBufferedRequest;t.lastBufferedRequest=new eh(r,n,i),s?s.next=t.lastBufferedRequest:t.bufferedRequest=t.lastBufferedRequest,t.bufferedRequestCount+=1}else ci(e,t,!1,a,r,n,i);return o}function ci(e,t,r,n,i,a,o){t.writelen=n,t.writecb=o,t.writing=!0,t.sync=!0,r?e._writev(i,t.onwrite):e._write(i,a,t.onwrite),t.sync=!1}function ah(e,t,r,n,i){--t.pendingcb,r?ee(i,n):i(n),e._writableState.errorEmitted=!0,e.emit("error",n)}function oh(e){e.writing=!1,e.writecb=null,e.length-=e.writelen,e.writelen=0}function sh(e,t){var r=e._writableState,n=r.sync,i=r.writecb;if(oh(r),t)ah(e,r,n,t,i);else{var a=ts(r);!a&&!r.corked&&!r.bufferProcessing&&r.bufferedRequest&&es(e,r),n?ee(Qo,e,r,a,i):Qo(e,r,a,i)}}function Qo(e,t,r,n){r||ch(e,t),t.pendingcb--,n(),ns(e,t)}function ch(e,t){t.length===0&&t.needDrain&&(t.needDrain=!1,e.emit("drain"))}function es(e,t){t.bufferProcessing=!0;var r=t.bufferedRequest;if(e._writev&&r&&r.next){var n=t.bufferedRequestCount,i=new Array(n),a=t.corkedRequestsFree;a.entry=r;for(var o=0;r;)i[o]=r,r=r.next,o+=1;ci(e,t,!0,t.length,i,"",a.finish),t.pendingcb++,t.lastBufferedRequest=null,a.next?(t.corkedRequestsFree=a.next,a.next=null):t.corkedRequestsFree=new is(t)}else{for(;r;){var s=r.chunk,f=r.encoding,c=r.callback,l=t.objectMode?1:s.length;if(ci(e,t,!1,l,s,f,c),r=r.next,t.writing)break}r===null&&(t.lastBufferedRequest=null)}t.bufferedRequestCount=0,t.bufferedRequest=r,t.bufferProcessing=!1}q.prototype._write=function(e,t,r){r(new Error("not implemented"))},q.prototype._writev=null,q.prototype.end=function(e,t,r){var n=this._writableState;typeof e=="function"?(r=e,e=null,t=null):typeof t=="function"&&(r=t,t=null),e!=null&&this.write(e,t),n.corked&&(n.corked=1,this.uncork()),!n.ending&&!n.finished&&fh(this,n,r)};function ts(e){return e.ending&&e.length===0&&e.bufferedRequest===null&&!e.finished&&!e.writing}function rs(e,t){t.prefinished||(t.prefinished=!0,e.emit("prefinish"))}function ns(e,t){var r=ts(t);return r&&(t.pendingcb===0?(rs(e,t),t.finished=!0,e.emit("finish")):rs(e,t)),r}function fh(e,t,r){t.ending=!0,ns(e,t),r&&(t.finished?ee(r):e.once("finish",r)),t.ended=!0,e.writable=!1}function is(e){var t=this;this.next=null,this.entry=null,this.finish=function(r){var n=t.entry;for(t.entry=null;n;){var i=n.callback;e.pendingcb--,i(r),n=n.next}e.corkedRequestsFree?e.corkedRequestsFree.next=t:e.corkedRequestsFree=t}}W(ae,L);for(var as=Object.keys(q.prototype),fi=0;fi<as.length;fi++){var li=as[fi];ae.prototype[li]||(ae.prototype[li]=q.prototype[li])}function ae(e){if(!(this instanceof ae))return new ae(e);L.call(this,e),q.call(this,e),e&&e.readable===!1&&(this.readable=!1),e&&e.writable===!1&&(this.writable=!1),this.allowHalfOpen=!0,e&&e.allowHalfOpen===!1&&(this.allowHalfOpen=!1),this.once("end",lh)}function lh(){this.allowHalfOpen||this._writableState.ended||ee(uh,this)}function uh(e){e.end()}W(te,ae);function hh(e){this.afterTransform=function(t,r){return dh(e,t,r)},this.needTransform=!1,this.transforming=!1,this.writecb=null,this.writechunk=null,this.writeencoding=null}function dh(e,t,r){var n=e._transformState;n.transforming=!1;var i=n.writecb;if(!i)return e.emit("error",new Error("no writecb in Transform class"));n.writechunk=null,n.writecb=null,r!=null&&e.push(r),i(t);var a=e._readableState;a.reading=!1,(a.needReadable||a.length<a.highWaterMark)&&e._read(a.highWaterMark)}function te(e){if(!(this instanceof te))return new te(e);ae.call(this,e),this._transformState=new hh(this);var t=this;this._readableState.needReadable=!0,this._readableState.sync=!1,e&&(typeof e.transform=="function"&&(this._transform=e.transform),typeof e.flush=="function"&&(this._flush=e.flush)),this.once("prefinish",function(){typeof this._flush=="function"?this._flush(function(r){os(t,r)}):os(t)})}te.prototype.push=function(e,t){return this._transformState.needTransform=!1,ae.prototype.push.call(this,e,t)},te.prototype._transform=function(e,t,r){throw new Error("Not implemented")},te.prototype._write=function(e,t,r){var n=this._transformState;if(n.writecb=r,n.writechunk=e,n.writeencoding=t,!n.transforming){var i=this._readableState;(n.needTransform||i.needReadable||i.length<i.highWaterMark)&&this._read(i.highWaterMark)}},te.prototype._read=function(e){var t=this._transformState;t.writechunk!==null&&t.writecb&&!t.transforming?(t.transforming=!0,this._transform(t.writechunk,t.writeencoding,t.afterTransform)):t.needTransform=!0};function os(e,t){if(t)return e.emit("error",t);var r=e._writableState,n=e._transformState;if(r.length)throw new Error("Calling transform done when ws.length != 0");if(n.transforming)throw new Error("Calling transform done when still transforming");return e.push(null)}W(jt,te);function jt(e){if(!(this instanceof jt))return new jt(e);te.call(this,e)}jt.prototype._transform=function(e,t,r){r(null,e)},W(Ae,R),Ae.Readable=L,Ae.Writable=q,Ae.Duplex=ae,Ae.Transform=te,Ae.PassThrough=jt,Ae.Stream=Ae;function Ae(){R.call(this)}Ae.prototype.pipe=function(e,t){var r=this;function n(l){e.writable&&e.write(l)===!1&&r.pause&&r.pause()}r.on("data",n);function i(){r.readable&&r.resume&&r.resume()}e.on("drain",i),!e._isStdio&&(!t||t.end!==!1)&&(r.on("end",o),r.on("close",s));var a=!1;function o(){a||(a=!0,e.end())}function s(){a||(a=!0,typeof e.destroy=="function"&&e.destroy())}function f(l){if(c(),R.listenerCount(this,"error")===0)throw l}r.on("error",f),e.on("error",f);function c(){r.removeListener("data",n),e.removeListener("drain",i),r.removeListener("end",o),r.removeListener("close",s),r.removeListener("error",f),e.removeListener("error",f),r.removeListener("end",c),r.removeListener("close",c),e.removeListener("close",c)}return r.on("end",c),r.on("close",c),e.on("close",c),e.emit("pipe",r),e};class ss extends R{constructor({resource:t}){super(),this.resource=t,this.client=t.client,this.stream=new nf({highWaterMark:this.client.parallelism*3,start:this._start.bind(this),pull:this._pull.bind(this),cancel:this._cancel.bind(this)})}build(){return this.stream.getReader()}async _start(t){this.controller=t,this.continuationToken=null,this.closeNextIteration=!1}async _pull(t){if(this.closeNextIteration){t.close();return}const r=await this.client.listObjects({prefix:`resource=${this.resource.name}`,continuationToken:this.continuationToken}),n=r?.Contents.map(i=>i.Key).map(i=>i.replace(this.client.config.keyPrefix,"")).map(i=>i.startsWith("/")?i.replace("/",""):i).map(i=>i.replace(`resource=${this.resource.name}/id=`,""));this.continuationToken=r.NextContinuationToken,this.enqueue(n),r.IsTruncated||(this.closeNextIteration=!0)}enqueue(t){t.forEach(r=>{this.controller.enqueue(r),this.emit("id",r)})}_cancel(t){console.warn("Stream cancelled",t)}}class cs extends ss{enqueue(t){this.controller.enqueue(t),this.emit("page",t)}}class fs extends R{constructor({resource:t,batchSize:r=10,concurrency:n=5}){if(super(),!t)throw new Error("Resource is required for ResourceReader");this.resource=t,this.client=t.client,this.batchSize=r,this.concurrency=n,this.input=new cs({resource:this.resource}),this.transform=new te({objectMode:!0,transform:this._transform.bind(this)}),this.input.on("data",i=>{this.transform.write(i)}),this.input.on("end",()=>{this.transform.end()}),this.input.on("error",i=>{this.emit("error",i)}),this.transform.on("data",i=>{this.emit("data",i)}),this.transform.on("end",()=>{this.emit("end")}),this.transform.on("error",i=>{this.emit("error",i)})}build(){return this}async _transform(t,r,n){try{await he.for(t).withConcurrency(this.concurrency).handleError(async(i,a)=>{this.emit("error",i,a)}).process(async i=>{const a=await this.resource.get(i);return this.push(a),a}),n()}catch(i){n(i)}}resume(){this.input.resume()}}class ls extends R{constructor({resource:t,batchSize:r=10,concurrency:n=5}){super(),this.resource=t,this.client=t.client,this.batchSize=r,this.concurrency=n,this.buffer=[],this.writing=!1,this.writable=new q({objectMode:!0,write:this._write.bind(this)}),this.writable.on("finish",()=>{this.emit("finish")}),this.writable.on("error",i=>{this.emit("error",i)})}build(){return this}write(t){return this.buffer.push(t),this._maybeWrite().catch(r=>{this.emit("error",r)}),!0}end(){this.ended=!0,this._maybeWrite().catch(t=>{this.emit("error",t)})}async _maybeWrite(){if(!this.writing&&!(this.buffer.length===0&&!this.ended)){for(this.writing=!0;this.buffer.length>0;){const t=this.buffer.splice(0,this.batchSize);try{await he.for(t).withConcurrency(this.concurrency).handleError(async(r,n)=>{this.emit("error",r,n)}).process(async r=>{await this.resource.insert(r)})}catch(r){this.emit("error",r)}}this.writing=!1,this.ended&&this.writable.emit("finish")}}async _write(t,r,n){n()}}function yt(e){return new Promise((t,r)=>{const n=[];e.on("data",i=>n.push(i)),e.on("error",r),e.on("end",()=>t(Buffer.concat(n).toString("utf-8")))})}function Ye(e){typeof e!="string"&&(e=String(e));let t=0;for(let r=0;r<e.length;r++){const n=e.codePointAt(r);n<=127?t+=1:n<=2047?t+=2:n<=65535?t+=3:n<=1114111&&(t+=4,n>65535&&r++)}return t}function ui(e){let t=0;for(const r of Object.keys(e))t+=Ye(r);return t}function hi(e){return e==null?"":typeof e=="boolean"?e?"1":"0":typeof e=="number"?String(e):typeof e=="string"?e:Array.isArray(e)?e.length===0?"[]":e.map(t=>String(t)).join("|"):typeof e=="object"?JSON.stringify(e):String(e)}function Ft(e){const t={};for(const[r,n]of Object.entries(e)){const i=hi(n),a=Ye(i);t[r]=a}return t}function Ce(e){const t=Ft(e),r=Object.values(t).reduce((i,a)=>i+a,0),n=ui(e);return r+n}function ph(e){const t=Ft(e),r=ui(e),n=Object.values(t).reduce((o,s)=>o+s,0),i=n+r,a=Object.entries(t).sort(([,o],[,s])=>s-o).map(([o,s])=>({attribute:o,size:s,percentage:(s/i*100).toFixed(2)+"%"}));return{total:i,valueSizes:t,namesSize:r,valueTotal:n,breakdown:a,detailedBreakdown:{values:n,names:r,total:i}}}const $=2048;async function yh({resource:e,data:t,mappedData:r}){const n=Ce(r);if(n>$)throw new Error(`S3 metadata size exceeds 2KB limit. Current size: ${n} bytes, limit: ${$} bytes`);return{mappedData:r,body:""}}async function gh({resource:e,id:t,data:r,mappedData:n}){const i=Ce(n);if(i>$)throw new Error(`S3 metadata size exceeds 2KB limit. Current size: ${i} bytes, limit: ${$} bytes`);return{mappedData:n,body:""}}async function vh({resource:e,id:t,data:r,mappedData:n}){const i=Ce(n);if(i>$)throw new Error(`S3 metadata size exceeds 2KB limit. Current size: ${i} bytes, limit: ${$} bytes`);return{mappedData:n,body:""}}async function wh({resource:e,metadata:t,body:r}){return{metadata:t,body:r}}var _h=Object.freeze({__proto__:null,S3_METADATA_LIMIT_BYTES:$,handleGet:wh,handleInsert:yh,handleUpdate:gh,handleUpsert:vh});async function bh({resource:e,data:t,mappedData:r}){const n=Ce(r);return n>$&&e.emit("exceedsLimit",{operation:"insert",totalSize:n,limit:$,excess:n-$,data:t}),{mappedData:r,body:""}}async function mh({resource:e,id:t,data:r,mappedData:n}){const i=Ce(n);return i>$&&e.emit("exceedsLimit",{operation:"update",id:t,totalSize:i,limit:$,excess:i-$,data:r}),{mappedData:n,body:""}}async function xh({resource:e,id:t,data:r,mappedData:n}){const i=Ce(n);return i>$&&e.emit("exceedsLimit",{operation:"upsert",id:t,totalSize:i,limit:$,excess:i-$,data:r}),{mappedData:n,body:""}}async function Eh({resource:e,metadata:t,body:r}){return{metadata:t,body:r}}var Sh=Object.freeze({__proto__:null,handleGet:Eh,handleInsert:bh,handleUpdate:mh,handleUpsert:xh});const us="...",hs=Ye(us);async function Ah({resource:e,data:t,mappedData:r}){return di({resource:e,data:t,mappedData:r})}async function kh({resource:e,id:t,data:r,mappedData:n}){return di({resource:e,data:r,mappedData:n})}async function Rh({resource:e,id:t,data:r,mappedData:n}){return di({resource:e,data:r,mappedData:n})}async function Oh({resource:e,metadata:t,body:r}){return{metadata:t,body:r}}function di({resource:e,data:t,mappedData:r}){const n=Ft(r),i=Object.entries(n).sort(([,s],[,f])=>s-f),a={};let o=0;for(const[s,f]of i){const c=$-o;if(f<=c)a[s]=r[s],o+=f;else if(c>hs){const l=c-hs,d=hi(r[s]);let h="",u=0;for(let p=0;p<d.length;p++){const y=d[p],w=Ye(y);if(u+w<=l)h+=y,u+=w;else break}a[s]=h+us,o=$;break}else break}return{mappedData:a,body:""}}var Ih=Object.freeze({__proto__:null,handleGet:Oh,handleInsert:Ah,handleUpdate:kh,handleUpsert:Rh});const wr="$overflow",pi="true",Th=Ye(wr)+Ye(pi);async function Ph({resource:e,data:t,mappedData:r}){return yi({resource:e,data:t,mappedData:r})}async function jh({resource:e,id:t,data:r,mappedData:n}){return yi({resource:e,data:r,mappedData:n})}async function Fh({resource:e,id:t,data:r,mappedData:n}){return yi({resource:e,data:r,mappedData:n})}async function Ch({resource:e,metadata:t,body:r}){if(t[wr]===pi)try{const n=r?JSON.parse(r):{},i={...t};return delete i[wr],{metadata:{...i,...n},body:""}}catch{return{metadata:t,body:r}}return{metadata:t,body:r}}function yi({resource:e,data:t,mappedData:r}){if(Ce(r)<=$)return{mappedData:r,body:""};const i=$-Th,a=Ft(r),o=Object.entries(a).sort(([,d],[,h])=>d-h),s={},f={};let c=0;for(const[d,h]of o)c+h<=i?(s[d]=r[d],c+=h):f[d]=r[d];s[wr]=pi;const l=Object.keys(f).length>0?JSON.stringify(f):"";return{mappedData:s,body:l}}var Dh=Object.freeze({__proto__:null,handleGet:Ch,handleInsert:Ph,handleUpdate:jh,handleUpsert:Fh});const _r={"user-management":Sh,"enforce-limits":_h,"data-truncate":Ih,"body-overflow":Dh};function ge(e){const t=_r[e];if(!t)throw new Error(`Unknown behavior: ${e}. Available behaviors: ${Object.keys(_r).join(", ")}`);return t}const Mh=Object.keys(_r),ds="user-management";class br extends R{constructor(t){super();const r=Lh(t);if(!r.isValid)throw new Error(`Invalid Resource configuration:
29
+ `)+" "+r[1]:r[0]+t+" "+e.join(", ")+" "+r[1]}function Iu(e){return Array.isArray(e)}function qo(e){return typeof e=="boolean"}function ei(e){return e===null}function Tu(e){return typeof e=="number"}function ti(e){return typeof e=="string"}function Fe(e){return e===void 0}function ri(e){return Tt(e)&&ai(e)==="[object RegExp]"}function Tt(e){return typeof e=="object"&&e!==null}function Ho(e){return Tt(e)&&ai(e)==="[object Date]"}function ni(e){return Tt(e)&&(ai(e)==="[object Error]"||e instanceof Error)}function ii(e){return typeof e=="function"}function ai(e){return Object.prototype.toString.call(e)}function Pu(e,t){if(!t||!Tt(t))return e;for(var r=Object.keys(t),n=r.length;n--;)e[r[n]]=t[r[n]];return e}function Ko(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Ge(){this.head=null,this.tail=null,this.length=0}Ge.prototype.push=function(e){var t={data:e,next:null};this.length>0?this.tail.next=t:this.head=t,this.tail=t,++this.length},Ge.prototype.unshift=function(e){var t={data:e,next:this.head};this.length===0&&(this.tail=t),this.head=t,++this.length},Ge.prototype.shift=function(){if(this.length!==0){var e=this.head.data;return this.length===1?this.head=this.tail=null:this.head=this.head.next,--this.length,e}},Ge.prototype.clear=function(){this.head=this.tail=null,this.length=0},Ge.prototype.join=function(e){if(this.length===0)return"";for(var t=this.head,r=""+t.data;t=t.next;)r+=e+t.data;return r},Ge.prototype.concat=function(e){if(this.length===0)return g.alloc(0);if(this.length===1)return this.head.data;for(var t=g.allocUnsafe(e>>>0),r=this.head,n=0;r;)r.data.copy(t,n),n+=r.data.length,r=r.next;return t};var ju=g.isEncoding||function(e){switch(e&&e.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1}};function Fu(e){if(e&&!ju(e))throw new Error("Unknown encoding: "+e)}function Pt(e){switch(this.encoding=(e||"utf8").toLowerCase().replace(/[-_]/,""),Fu(e),this.encoding){case"utf8":this.surrogateSize=3;break;case"ucs2":case"utf16le":this.surrogateSize=2,this.detectIncompleteChar=Du;break;case"base64":this.surrogateSize=3,this.detectIncompleteChar=Mu;break;default:this.write=Cu;return}this.charBuffer=new g(6),this.charReceived=0,this.charLength=0}Pt.prototype.write=function(e){for(var t="";this.charLength;){var r=e.length>=this.charLength-this.charReceived?this.charLength-this.charReceived:e.length;if(e.copy(this.charBuffer,this.charReceived,0,r),this.charReceived+=r,this.charReceived<this.charLength)return"";e=e.slice(r,e.length),t=this.charBuffer.slice(0,this.charLength).toString(this.encoding);var i=t.charCodeAt(t.length-1);if(i>=55296&&i<=56319){this.charLength+=this.surrogateSize,t="";continue}if(this.charReceived=this.charLength=0,e.length===0)return t;break}this.detectIncompleteChar(e);var n=e.length;this.charLength&&(e.copy(this.charBuffer,0,e.length-this.charReceived,n),n-=this.charReceived),t+=e.toString(this.encoding,0,n);var n=t.length-1,i=t.charCodeAt(n);if(i>=55296&&i<=56319){var a=this.surrogateSize;return this.charLength+=a,this.charReceived+=a,this.charBuffer.copy(this.charBuffer,a,0,a),e.copy(this.charBuffer,0,0,a),t.substring(0,n)}return t},Pt.prototype.detectIncompleteChar=function(e){for(var t=e.length>=3?3:e.length;t>0;t--){var r=e[e.length-t];if(t==1&&r>>5==6){this.charLength=2;break}if(t<=2&&r>>4==14){this.charLength=3;break}if(t<=3&&r>>3==30){this.charLength=4;break}}this.charReceived=t},Pt.prototype.end=function(e){var t="";if(e&&e.length&&(t=this.write(e)),this.charReceived){var r=this.charReceived,n=this.charBuffer,i=this.encoding;t+=n.slice(0,r).toString(i)}return t};function Cu(e){return e.toString(this.encoding)}function Du(e){this.charReceived=e.length%2,this.charLength=this.charReceived?2:0}function Mu(e){this.charReceived=e.length%3,this.charLength=this.charReceived?3:0}N.ReadableState=Wo;var j=xu("stream");W(N,R);function Nu(e,t,r){if(typeof e.prependListener=="function")return e.prependListener(t,r);!e._events||!e._events[t]?e.on(t,r):Array.isArray(e._events[t])?e._events[t].unshift(r):e._events[t]=[r,e._events[t]]}function Lu(e,t){return e.listeners(t).length}function Wo(e,t){e=e||{},this.objectMode=!!e.objectMode,t instanceof ae&&(this.objectMode=this.objectMode||!!e.readableObjectMode);var r=e.highWaterMark,n=this.objectMode?16:16*1024;this.highWaterMark=r||r===0?r:n,this.highWaterMark=~~this.highWaterMark,this.buffer=new Ge,this.length=0,this.pipes=null,this.pipesCount=0,this.flowing=null,this.ended=!1,this.endEmitted=!1,this.reading=!1,this.sync=!0,this.needReadable=!1,this.emittedReadable=!1,this.readableListening=!1,this.resumeScheduled=!1,this.defaultEncoding=e.defaultEncoding||"utf8",this.ranOut=!1,this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,e.encoding&&(this.decoder=new Pt(e.encoding),this.encoding=e.encoding)}function N(e){if(!(this instanceof N))return new N(e);this._readableState=new Wo(e,this),this.readable=!0,e&&typeof e.read=="function"&&(this._read=e.read),R.call(this)}N.prototype.push=function(e,t){var r=this._readableState;return!r.objectMode&&typeof e=="string"&&(t=t||r.defaultEncoding,t!==r.encoding&&(e=g.from(e,t),t="")),Vo(this,r,e,t,!1)},N.prototype.unshift=function(e){var t=this._readableState;return Vo(this,t,e,"",!0)},N.prototype.isPaused=function(){return this._readableState.flowing===!1};function Vo(e,t,r,n,i){var a=Bu(t,r);if(a)e.emit("error",a);else if(r===null)t.reading=!1,zu(e,t);else if(t.objectMode||r&&r.length>0)if(t.ended&&!i){var o=new Error("stream.push() after EOF");e.emit("error",o)}else if(t.endEmitted&&i){var s=new Error("stream.unshift() after end event");e.emit("error",s)}else{var f;t.decoder&&!i&&!n&&(r=t.decoder.write(r),f=!t.objectMode&&r.length===0),i||(t.reading=!1),f||(t.flowing&&t.length===0&&!t.sync?(e.emit("data",r),e.read(0)):(t.length+=t.objectMode?1:r.length,i?t.buffer.unshift(r):t.buffer.push(r),t.needReadable&&vr(e))),Zu(e,t)}else i||(t.reading=!1);return $u(t)}function $u(e){return!e.ended&&(e.needReadable||e.length<e.highWaterMark||e.length===0)}N.prototype.setEncoding=function(e){return this._readableState.decoder=new Pt(e),this._readableState.encoding=e,this};var Go=8388608;function Uu(e){return e>=Go?e=Go:(e--,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e++),e}function Yo(e,t){return e<=0||t.length===0&&t.ended?0:t.objectMode?1:e!==e?t.flowing&&t.length?t.buffer.head.data.length:t.length:(e>t.highWaterMark&&(t.highWaterMark=Uu(e)),e<=t.length?e:t.ended?t.length:(t.needReadable=!0,0))}N.prototype.read=function(e){j("read",e),e=parseInt(e,10);var t=this._readableState,r=e;if(e!==0&&(t.emittedReadable=!1),e===0&&t.needReadable&&(t.length>=t.highWaterMark||t.ended))return j("read: emitReadable",t.length,t.ended),t.length===0&&t.ended?si(this):vr(this),null;if(e=Yo(e,t),e===0&&t.ended)return t.length===0&&si(this),null;var n=t.needReadable;j("need readable",n),(t.length===0||t.length-e<t.highWaterMark)&&(n=!0,j("length less than watermark",n)),t.ended||t.reading?(n=!1,j("reading or ended",n)):n&&(j("do read"),t.reading=!0,t.sync=!0,t.length===0&&(t.needReadable=!0),this._read(t.highWaterMark),t.sync=!1,t.reading||(e=Yo(r,t)));var i;return e>0?i=Xo(e,t):i=null,i===null?(t.needReadable=!0,e=0):t.length-=e,t.length===0&&(t.ended||(t.needReadable=!0),r!==e&&t.ended&&si(this)),i!==null&&this.emit("data",i),i};function Bu(e,t){var r=null;return!g.isBuffer(t)&&typeof t!="string"&&t!==null&&t!==void 0&&!e.objectMode&&(r=new TypeError("Invalid non-string/buffer chunk")),r}function zu(e,t){if(!t.ended){if(t.decoder){var r=t.decoder.end();r&&r.length&&(t.buffer.push(r),t.length+=t.objectMode?1:r.length)}t.ended=!0,vr(e)}}function vr(e){var t=e._readableState;t.needReadable=!1,t.emittedReadable||(j("emitReadable",t.flowing),t.emittedReadable=!0,t.sync?ee(Jo,e):Jo(e))}function Jo(e){j("emit readable"),e.emit("readable"),oi(e)}function Zu(e,t){t.readingMore||(t.readingMore=!0,ee(qu,e,t))}function qu(e,t){for(var r=t.length;!t.reading&&!t.flowing&&!t.ended&&t.length<t.highWaterMark&&(j("maybeReadMore read 0"),e.read(0),r!==t.length);)r=t.length;t.readingMore=!1}N.prototype._read=function(e){this.emit("error",new Error("not implemented"))},N.prototype.pipe=function(e,t){var r=this,n=this._readableState;switch(n.pipesCount){case 0:n.pipes=e;break;case 1:n.pipes=[n.pipes,e];break;default:n.pipes.push(e);break}n.pipesCount+=1,j("pipe count=%d opts=%j",n.pipesCount,t);var i=!t||t.end!==!1,a=i?s:l;n.endEmitted?ee(a):r.once("end",a),e.on("unpipe",o);function o(b){j("onunpipe"),b===r&&l()}function s(){j("onend"),e.end()}var f=Hu(r);e.on("drain",f);var c=!1;function l(){j("cleanup"),e.removeListener("close",p),e.removeListener("finish",y),e.removeListener("drain",f),e.removeListener("error",u),e.removeListener("unpipe",o),r.removeListener("end",s),r.removeListener("end",l),r.removeListener("data",d),c=!0,n.awaitDrain&&(!e._writableState||e._writableState.needDrain)&&f()}var h=!1;r.on("data",d);function d(b){j("ondata"),h=!1;var m=e.write(b);m===!1&&!h&&((n.pipesCount===1&&n.pipes===e||n.pipesCount>1&&Qo(n.pipes,e)!==-1)&&!c&&(j("false write response, pause",r._readableState.awaitDrain),r._readableState.awaitDrain++,h=!0),r.pause())}function u(b){j("onerror",b),w(),e.removeListener("error",u),Lu(e,"error")===0&&e.emit("error",b)}Nu(e,"error",u);function p(){e.removeListener("finish",y),w()}e.once("close",p);function y(){j("onfinish"),e.removeListener("close",p),w()}e.once("finish",y);function w(){j("unpipe"),r.unpipe(e)}return e.emit("pipe",r),n.flowing||(j("pipe resume"),r.resume()),e};function Hu(e){return function(){var t=e._readableState;j("pipeOnDrain",t.awaitDrain),t.awaitDrain&&t.awaitDrain--,t.awaitDrain===0&&e.listeners("data").length&&(t.flowing=!0,oi(e))}}N.prototype.unpipe=function(e){var t=this._readableState;if(t.pipesCount===0)return this;if(t.pipesCount===1)return e&&e!==t.pipes?this:(e||(e=t.pipes),t.pipes=null,t.pipesCount=0,t.flowing=!1,e&&e.emit("unpipe",this),this);if(!e){var r=t.pipes,n=t.pipesCount;t.pipes=null,t.pipesCount=0,t.flowing=!1;for(var i=0;i<n;i++)r[i].emit("unpipe",this);return this}var a=Qo(t.pipes,e);return a===-1?this:(t.pipes.splice(a,1),t.pipesCount-=1,t.pipesCount===1&&(t.pipes=t.pipes[0]),e.emit("unpipe",this),this)},N.prototype.on=function(e,t){var r=R.prototype.on.call(this,e,t);if(e==="data")this._readableState.flowing!==!1&&this.resume();else if(e==="readable"){var n=this._readableState;!n.endEmitted&&!n.readableListening&&(n.readableListening=n.needReadable=!0,n.emittedReadable=!1,n.reading?n.length&&vr(this):ee(Ku,this))}return r},N.prototype.addListener=N.prototype.on;function Ku(e){j("readable nexttick read 0"),e.read(0)}N.prototype.resume=function(){var e=this._readableState;return e.flowing||(j("resume"),e.flowing=!0,Wu(this,e)),this};function Wu(e,t){t.resumeScheduled||(t.resumeScheduled=!0,ee(Vu,e,t))}function Vu(e,t){t.reading||(j("resume read 0"),e.read(0)),t.resumeScheduled=!1,t.awaitDrain=0,e.emit("resume"),oi(e),t.flowing&&!t.reading&&e.read(0)}N.prototype.pause=function(){return j("call pause flowing=%j",this._readableState.flowing),this._readableState.flowing!==!1&&(j("pause"),this._readableState.flowing=!1,this.emit("pause")),this};function oi(e){var t=e._readableState;for(j("flow",t.flowing);t.flowing&&e.read()!==null;);}N.prototype.wrap=function(e){var t=this._readableState,r=!1,n=this;e.on("end",function(){if(j("wrapped end"),t.decoder&&!t.ended){var o=t.decoder.end();o&&o.length&&n.push(o)}n.push(null)}),e.on("data",function(o){if(j("wrapped data"),t.decoder&&(o=t.decoder.write(o)),!(t.objectMode&&o==null)&&!(!t.objectMode&&(!o||!o.length))){var s=n.push(o);s||(r=!0,e.pause())}});for(var i in e)this[i]===void 0&&typeof e[i]=="function"&&(this[i]=function(o){return function(){return e[o].apply(e,arguments)}}(i));var a=["error","close","destroy","pause","resume"];return Qu(a,function(o){e.on(o,n.emit.bind(n,o))}),n._read=function(o){j("wrapped _read",o),r&&(r=!1,e.resume())},n},N._fromList=Xo;function Xo(e,t){if(t.length===0)return null;var r;return t.objectMode?r=t.buffer.shift():!e||e>=t.length?(t.decoder?r=t.buffer.join(""):t.buffer.length===1?r=t.buffer.head.data:r=t.buffer.concat(t.length),t.buffer.clear()):r=Gu(e,t.buffer,t.decoder),r}function Gu(e,t,r){var n;return e<t.head.data.length?(n=t.head.data.slice(0,e),t.head.data=t.head.data.slice(e)):e===t.head.data.length?n=t.shift():n=r?Yu(e,t):Ju(e,t),n}function Yu(e,t){var r=t.head,n=1,i=r.data;for(e-=i.length;r=r.next;){var a=r.data,o=e>a.length?a.length:e;if(o===a.length?i+=a:i+=a.slice(0,e),e-=o,e===0){o===a.length?(++n,r.next?t.head=r.next:t.head=t.tail=null):(t.head=r,r.data=a.slice(o));break}++n}return t.length-=n,i}function Ju(e,t){var r=g.allocUnsafe(e),n=t.head,i=1;for(n.data.copy(r),e-=n.data.length;n=n.next;){var a=n.data,o=e>a.length?a.length:e;if(a.copy(r,r.length-e,0,o),e-=o,e===0){o===a.length?(++i,n.next?t.head=n.next:t.head=t.tail=null):(t.head=n,n.data=a.slice(o));break}++i}return t.length-=i,r}function si(e){var t=e._readableState;if(t.length>0)throw new Error('"endReadable()" called on non-empty stream');t.endEmitted||(t.ended=!0,ee(Xu,t,e))}function Xu(e,t){!e.endEmitted&&e.length===0&&(e.endEmitted=!0,t.readable=!1,t.emit("end"))}function Qu(e,t){for(var r=0,n=e.length;r<n;r++)t(e[r],r)}function Qo(e,t){for(var r=0,n=e.length;r<n;r++)if(e[r]===t)return r;return-1}q.WritableState=ci,W(q,R);function eh(){}function th(e,t,r){this.chunk=e,this.encoding=t,this.callback=r,this.next=null}function ci(e,t){Object.defineProperty(this,"buffer",{get:Zo(function(){return this.getBuffer()},"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.")}),e=e||{},this.objectMode=!!e.objectMode,t instanceof ae&&(this.objectMode=this.objectMode||!!e.writableObjectMode);var r=e.highWaterMark,n=this.objectMode?16:16*1024;this.highWaterMark=r||r===0?r:n,this.highWaterMark=~~this.highWaterMark,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1;var i=e.decodeStrings===!1;this.decodeStrings=!i,this.defaultEncoding=e.defaultEncoding||"utf8",this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(a){ch(t,a)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.bufferedRequestCount=0,this.corkedRequestsFree=new as(this)}ci.prototype.getBuffer=function(){for(var t=this.bufferedRequest,r=[];t;)r.push(t),t=t.next;return r};function q(e){if(!(this instanceof q)&&!(this instanceof ae))return new q(e);this._writableState=new ci(e,this),this.writable=!0,e&&(typeof e.write=="function"&&(this._write=e.write),typeof e.writev=="function"&&(this._writev=e.writev)),R.call(this)}q.prototype.pipe=function(){this.emit("error",new Error("Cannot pipe, not readable"))};function rh(e,t){var r=new Error("write after end");e.emit("error",r),ee(t,r)}function nh(e,t,r,n){var i=!0,a=!1;return r===null?a=new TypeError("May not write null values to stream"):!g.isBuffer(r)&&typeof r!="string"&&r!==void 0&&!t.objectMode&&(a=new TypeError("Invalid non-string/buffer chunk")),a&&(e.emit("error",a),ee(n,a),i=!1),i}q.prototype.write=function(e,t,r){var n=this._writableState,i=!1;return typeof t=="function"&&(r=t,t=null),g.isBuffer(e)?t="buffer":t||(t=n.defaultEncoding),typeof r!="function"&&(r=eh),n.ended?rh(this,r):nh(this,n,e,r)&&(n.pendingcb++,i=ah(this,n,e,t,r)),i},q.prototype.cork=function(){var e=this._writableState;e.corked++},q.prototype.uncork=function(){var e=this._writableState;e.corked&&(e.corked--,!e.writing&&!e.corked&&!e.finished&&!e.bufferProcessing&&e.bufferedRequest&&ts(this,e))},q.prototype.setDefaultEncoding=function(t){if(typeof t=="string"&&(t=t.toLowerCase()),!(["hex","utf8","utf-8","ascii","binary","base64","ucs2","ucs-2","utf16le","utf-16le","raw"].indexOf((t+"").toLowerCase())>-1))throw new TypeError("Unknown encoding: "+t);return this._writableState.defaultEncoding=t,this};function ih(e,t,r){return!e.objectMode&&e.decodeStrings!==!1&&typeof t=="string"&&(t=g.from(t,r)),t}function ah(e,t,r,n,i){r=ih(t,r,n),g.isBuffer(r)&&(n="buffer");var a=t.objectMode?1:r.length;t.length+=a;var o=t.length<t.highWaterMark;if(o||(t.needDrain=!0),t.writing||t.corked){var s=t.lastBufferedRequest;t.lastBufferedRequest=new th(r,n,i),s?s.next=t.lastBufferedRequest:t.bufferedRequest=t.lastBufferedRequest,t.bufferedRequestCount+=1}else fi(e,t,!1,a,r,n,i);return o}function fi(e,t,r,n,i,a,o){t.writelen=n,t.writecb=o,t.writing=!0,t.sync=!0,r?e._writev(i,t.onwrite):e._write(i,a,t.onwrite),t.sync=!1}function oh(e,t,r,n,i){--t.pendingcb,r?ee(i,n):i(n),e._writableState.errorEmitted=!0,e.emit("error",n)}function sh(e){e.writing=!1,e.writecb=null,e.length-=e.writelen,e.writelen=0}function ch(e,t){var r=e._writableState,n=r.sync,i=r.writecb;if(sh(r),t)oh(e,r,n,t,i);else{var a=rs(r);!a&&!r.corked&&!r.bufferProcessing&&r.bufferedRequest&&ts(e,r),n?ee(es,e,r,a,i):es(e,r,a,i)}}function es(e,t,r,n){r||fh(e,t),t.pendingcb--,n(),is(e,t)}function fh(e,t){t.length===0&&t.needDrain&&(t.needDrain=!1,e.emit("drain"))}function ts(e,t){t.bufferProcessing=!0;var r=t.bufferedRequest;if(e._writev&&r&&r.next){var n=t.bufferedRequestCount,i=new Array(n),a=t.corkedRequestsFree;a.entry=r;for(var o=0;r;)i[o]=r,r=r.next,o+=1;fi(e,t,!0,t.length,i,"",a.finish),t.pendingcb++,t.lastBufferedRequest=null,a.next?(t.corkedRequestsFree=a.next,a.next=null):t.corkedRequestsFree=new as(t)}else{for(;r;){var s=r.chunk,f=r.encoding,c=r.callback,l=t.objectMode?1:s.length;if(fi(e,t,!1,l,s,f,c),r=r.next,t.writing)break}r===null&&(t.lastBufferedRequest=null)}t.bufferedRequestCount=0,t.bufferedRequest=r,t.bufferProcessing=!1}q.prototype._write=function(e,t,r){r(new Error("not implemented"))},q.prototype._writev=null,q.prototype.end=function(e,t,r){var n=this._writableState;typeof e=="function"?(r=e,e=null,t=null):typeof t=="function"&&(r=t,t=null),e!=null&&this.write(e,t),n.corked&&(n.corked=1,this.uncork()),!n.ending&&!n.finished&&lh(this,n,r)};function rs(e){return e.ending&&e.length===0&&e.bufferedRequest===null&&!e.finished&&!e.writing}function ns(e,t){t.prefinished||(t.prefinished=!0,e.emit("prefinish"))}function is(e,t){var r=rs(t);return r&&(t.pendingcb===0?(ns(e,t),t.finished=!0,e.emit("finish")):ns(e,t)),r}function lh(e,t,r){t.ending=!0,is(e,t),r&&(t.finished?ee(r):e.once("finish",r)),t.ended=!0,e.writable=!1}function as(e){var t=this;this.next=null,this.entry=null,this.finish=function(r){var n=t.entry;for(t.entry=null;n;){var i=n.callback;e.pendingcb--,i(r),n=n.next}e.corkedRequestsFree?e.corkedRequestsFree.next=t:e.corkedRequestsFree=t}}W(ae,N);for(var os=Object.keys(q.prototype),li=0;li<os.length;li++){var ui=os[li];ae.prototype[ui]||(ae.prototype[ui]=q.prototype[ui])}function ae(e){if(!(this instanceof ae))return new ae(e);N.call(this,e),q.call(this,e),e&&e.readable===!1&&(this.readable=!1),e&&e.writable===!1&&(this.writable=!1),this.allowHalfOpen=!0,e&&e.allowHalfOpen===!1&&(this.allowHalfOpen=!1),this.once("end",uh)}function uh(){this.allowHalfOpen||this._writableState.ended||ee(hh,this)}function hh(e){e.end()}W(te,ae);function dh(e){this.afterTransform=function(t,r){return ph(e,t,r)},this.needTransform=!1,this.transforming=!1,this.writecb=null,this.writechunk=null,this.writeencoding=null}function ph(e,t,r){var n=e._transformState;n.transforming=!1;var i=n.writecb;if(!i)return e.emit("error",new Error("no writecb in Transform class"));n.writechunk=null,n.writecb=null,r!=null&&e.push(r),i(t);var a=e._readableState;a.reading=!1,(a.needReadable||a.length<a.highWaterMark)&&e._read(a.highWaterMark)}function te(e){if(!(this instanceof te))return new te(e);ae.call(this,e),this._transformState=new dh(this);var t=this;this._readableState.needReadable=!0,this._readableState.sync=!1,e&&(typeof e.transform=="function"&&(this._transform=e.transform),typeof e.flush=="function"&&(this._flush=e.flush)),this.once("prefinish",function(){typeof this._flush=="function"?this._flush(function(r){ss(t,r)}):ss(t)})}te.prototype.push=function(e,t){return this._transformState.needTransform=!1,ae.prototype.push.call(this,e,t)},te.prototype._transform=function(e,t,r){throw new Error("Not implemented")},te.prototype._write=function(e,t,r){var n=this._transformState;if(n.writecb=r,n.writechunk=e,n.writeencoding=t,!n.transforming){var i=this._readableState;(n.needTransform||i.needReadable||i.length<i.highWaterMark)&&this._read(i.highWaterMark)}},te.prototype._read=function(e){var t=this._transformState;t.writechunk!==null&&t.writecb&&!t.transforming?(t.transforming=!0,this._transform(t.writechunk,t.writeencoding,t.afterTransform)):t.needTransform=!0};function ss(e,t){if(t)return e.emit("error",t);var r=e._writableState,n=e._transformState;if(r.length)throw new Error("Calling transform done when ws.length != 0");if(n.transforming)throw new Error("Calling transform done when still transforming");return e.push(null)}W(jt,te);function jt(e){if(!(this instanceof jt))return new jt(e);te.call(this,e)}jt.prototype._transform=function(e,t,r){r(null,e)},W(Ae,R),Ae.Readable=N,Ae.Writable=q,Ae.Duplex=ae,Ae.Transform=te,Ae.PassThrough=jt,Ae.Stream=Ae;function Ae(){R.call(this)}Ae.prototype.pipe=function(e,t){var r=this;function n(l){e.writable&&e.write(l)===!1&&r.pause&&r.pause()}r.on("data",n);function i(){r.readable&&r.resume&&r.resume()}e.on("drain",i),!e._isStdio&&(!t||t.end!==!1)&&(r.on("end",o),r.on("close",s));var a=!1;function o(){a||(a=!0,e.end())}function s(){a||(a=!0,typeof e.destroy=="function"&&e.destroy())}function f(l){if(c(),R.listenerCount(this,"error")===0)throw l}r.on("error",f),e.on("error",f);function c(){r.removeListener("data",n),e.removeListener("drain",i),r.removeListener("end",o),r.removeListener("close",s),r.removeListener("error",f),e.removeListener("error",f),r.removeListener("end",c),r.removeListener("close",c),e.removeListener("close",c)}return r.on("end",c),r.on("close",c),e.on("close",c),e.emit("pipe",r),e};class cs extends R{constructor({resource:t}){super(),this.resource=t,this.client=t.client,this.stream=new af({highWaterMark:this.client.parallelism*3,start:this._start.bind(this),pull:this._pull.bind(this),cancel:this._cancel.bind(this)})}build(){return this.stream.getReader()}async _start(t){this.controller=t,this.continuationToken=null,this.closeNextIteration=!1}async _pull(t){if(this.closeNextIteration){t.close();return}const r=await this.client.listObjects({prefix:`resource=${this.resource.name}`,continuationToken:this.continuationToken}),n=r?.Contents.map(i=>i.Key).map(i=>i.replace(this.client.config.keyPrefix,"")).map(i=>i.startsWith("/")?i.replace("/",""):i).map(i=>i.replace(`resource=${this.resource.name}/id=`,""));this.continuationToken=r.NextContinuationToken,this.enqueue(n),r.IsTruncated||(this.closeNextIteration=!0)}enqueue(t){t.forEach(r=>{this.controller.enqueue(r),this.emit("id",r)})}_cancel(t){console.warn("Stream cancelled",t)}}class fs extends cs{enqueue(t){this.controller.enqueue(t),this.emit("page",t)}}class ls extends R{constructor({resource:t,batchSize:r=10,concurrency:n=5}){if(super(),!t)throw new Error("Resource is required for ResourceReader");this.resource=t,this.client=t.client,this.batchSize=r,this.concurrency=n,this.input=new fs({resource:this.resource}),this.transform=new te({objectMode:!0,transform:this._transform.bind(this)}),this.input.on("data",i=>{this.transform.write(i)}),this.input.on("end",()=>{this.transform.end()}),this.input.on("error",i=>{this.emit("error",i)}),this.transform.on("data",i=>{this.emit("data",i)}),this.transform.on("end",()=>{this.emit("end")}),this.transform.on("error",i=>{this.emit("error",i)})}build(){return this}async _transform(t,r,n){try{await he.for(t).withConcurrency(this.concurrency).handleError(async(i,a)=>{this.emit("error",i,a)}).process(async i=>{const a=await this.resource.get(i);return this.push(a),a}),n()}catch(i){n(i)}}resume(){this.input.resume()}}class us extends R{constructor({resource:t,batchSize:r=10,concurrency:n=5}){super(),this.resource=t,this.client=t.client,this.batchSize=r,this.concurrency=n,this.buffer=[],this.writing=!1,this.writable=new q({objectMode:!0,write:this._write.bind(this)}),this.writable.on("finish",()=>{this.emit("finish")}),this.writable.on("error",i=>{this.emit("error",i)})}build(){return this}write(t){return this.buffer.push(t),this._maybeWrite().catch(r=>{this.emit("error",r)}),!0}end(){this.ended=!0,this._maybeWrite().catch(t=>{this.emit("error",t)})}async _maybeWrite(){if(!this.writing&&!(this.buffer.length===0&&!this.ended)){for(this.writing=!0;this.buffer.length>0;){const t=this.buffer.splice(0,this.batchSize);try{await he.for(t).withConcurrency(this.concurrency).handleError(async(r,n)=>{this.emit("error",r,n)}).process(async r=>{await this.resource.insert(r)})}catch(r){this.emit("error",r)}}this.writing=!1,this.ended&&this.writable.emit("finish")}}async _write(t,r,n){n()}}function yt(e){return new Promise((t,r)=>{const n=[];e.on("data",i=>n.push(i)),e.on("error",r),e.on("end",()=>t(Buffer.concat(n).toString("utf-8")))})}function Ye(e){typeof e!="string"&&(e=String(e));let t=0;for(let r=0;r<e.length;r++){const n=e.codePointAt(r);n<=127?t+=1:n<=2047?t+=2:n<=65535?t+=3:n<=1114111&&(t+=4,n>65535&&r++)}return t}function hi(e){let t=0;for(const r of Object.keys(e))t+=Ye(r);return t}function di(e){return e==null?"":typeof e=="boolean"?e?"1":"0":typeof e=="number"?String(e):typeof e=="string"?e:Array.isArray(e)?e.length===0?"[]":e.map(t=>String(t)).join("|"):typeof e=="object"?JSON.stringify(e):String(e)}function Ft(e){const t={};for(const[r,n]of Object.entries(e)){const i=di(n),a=Ye(i);t[r]=a}return t}function Ce(e){const t=Ft(e),r=Object.values(t).reduce((i,a)=>i+a,0),n=hi(e);return r+n}function yh(e){const t=Ft(e),r=hi(e),n=Object.values(t).reduce((o,s)=>o+s,0),i=n+r,a=Object.entries(t).sort(([,o],[,s])=>s-o).map(([o,s])=>({attribute:o,size:s,percentage:(s/i*100).toFixed(2)+"%"}));return{total:i,valueSizes:t,namesSize:r,valueTotal:n,breakdown:a,detailedBreakdown:{values:n,names:r,total:i}}}const $=2048;async function gh({resource:e,data:t,mappedData:r}){const n=Ce(r);if(n>$)throw new Error(`S3 metadata size exceeds 2KB limit. Current size: ${n} bytes, limit: ${$} bytes`);return{mappedData:r,body:""}}async function vh({resource:e,id:t,data:r,mappedData:n}){const i=Ce(n);if(i>$)throw new Error(`S3 metadata size exceeds 2KB limit. Current size: ${i} bytes, limit: ${$} bytes`);return{mappedData:n,body:""}}async function wh({resource:e,id:t,data:r,mappedData:n}){const i=Ce(n);if(i>$)throw new Error(`S3 metadata size exceeds 2KB limit. Current size: ${i} bytes, limit: ${$} bytes`);return{mappedData:n,body:""}}async function bh({resource:e,metadata:t,body:r}){return{metadata:t,body:r}}var _h=Object.freeze({__proto__:null,S3_METADATA_LIMIT_BYTES:$,handleGet:bh,handleInsert:gh,handleUpdate:vh,handleUpsert:wh});async function mh({resource:e,data:t,mappedData:r}){const n=Ce(r);return n>$&&e.emit("exceedsLimit",{operation:"insert",totalSize:n,limit:$,excess:n-$,data:t}),{mappedData:r,body:""}}async function xh({resource:e,id:t,data:r,mappedData:n}){const i=Ce(n);return i>$&&e.emit("exceedsLimit",{operation:"update",id:t,totalSize:i,limit:$,excess:i-$,data:r}),{mappedData:n,body:""}}async function Eh({resource:e,id:t,data:r,mappedData:n}){const i=Ce(n);return i>$&&e.emit("exceedsLimit",{operation:"upsert",id:t,totalSize:i,limit:$,excess:i-$,data:r}),{mappedData:n,body:""}}async function Sh({resource:e,metadata:t,body:r}){return{metadata:t,body:r}}var Ah=Object.freeze({__proto__:null,handleGet:Sh,handleInsert:mh,handleUpdate:xh,handleUpsert:Eh});const hs="...",ds=Ye(hs);async function kh({resource:e,data:t,mappedData:r}){return pi({resource:e,data:t,mappedData:r})}async function Rh({resource:e,id:t,data:r,mappedData:n}){return pi({resource:e,data:r,mappedData:n})}async function Oh({resource:e,id:t,data:r,mappedData:n}){return pi({resource:e,data:r,mappedData:n})}async function Ih({resource:e,metadata:t,body:r}){return{metadata:t,body:r}}function pi({resource:e,data:t,mappedData:r}){const n=Ft(r),i=Object.entries(n).sort(([,s],[,f])=>s-f),a={};let o=0;for(const[s,f]of i){const c=$-o;if(f<=c)a[s]=r[s],o+=f;else if(c>ds){const l=c-ds,h=di(r[s]);let d="",u=0;for(let p=0;p<h.length;p++){const y=h[p],w=Ye(y);if(u+w<=l)d+=y,u+=w;else break}a[s]=d+hs,o=$;break}else break}return{mappedData:a,body:""}}var Th=Object.freeze({__proto__:null,handleGet:Ih,handleInsert:kh,handleUpdate:Rh,handleUpsert:Oh});const wr="$overflow",yi="true",Ph=Ye(wr)+Ye(yi);async function jh({resource:e,data:t,mappedData:r}){return gi({resource:e,data:t,mappedData:r})}async function Fh({resource:e,id:t,data:r,mappedData:n}){return gi({resource:e,data:r,mappedData:n})}async function Ch({resource:e,id:t,data:r,mappedData:n}){return gi({resource:e,data:r,mappedData:n})}async function Dh({resource:e,metadata:t,body:r}){if(t[wr]===yi)try{const n=r?JSON.parse(r):{},i={...t};return delete i[wr],{metadata:{...i,...n},body:""}}catch{return{metadata:t,body:r}}return{metadata:t,body:r}}function gi({resource:e,data:t,mappedData:r}){if(Ce(r)<=$)return{mappedData:r,body:""};const i=$-Ph,a=Ft(r),o=Object.entries(a).sort(([,h],[,d])=>h-d),s={},f={};let c=0;for(const[h,d]of o)c+d<=i?(s[h]=r[h],c+=d):f[h]=r[h];s[wr]=yi;const l=Object.keys(f).length>0?JSON.stringify(f):"";return{mappedData:s,body:l}}var Mh=Object.freeze({__proto__:null,handleGet:Dh,handleInsert:jh,handleUpdate:Fh,handleUpsert:Ch});const br={"user-management":Ah,"enforce-limits":_h,"data-truncate":Th,"body-overflow":Mh};function ge(e){const t=br[e];if(!t)throw new Error(`Unknown behavior: ${e}. Available behaviors: ${Object.keys(br).join(", ")}`);return t}const Nh=Object.keys(br),ps="user-management";function ys(e){return Lr(qi,e)}class _r extends R{constructor(t){super();const r=Lh(t);if(!r.isValid)throw new Error(`Invalid Resource configuration:
30
30
  ${r.errors.join(`
31
- `)}`);const{name:n,client:i,version:a="1",attributes:o={},behavior:s=ds,passphrase:f="secret",parallelism:c=10,observers:l=[],cache:d=!1,autoDecrypt:h=!0,timestamps:u=!1,partitions:p={},paranoid:y=!0,allNestedObjectsOptional:w=!0,hooks:_={}}=t;if(this.name=n,this.client=i,this.version=a,this.behavior=s,this.observers=l,this.parallelism=c,this.passphrase=f??"secret",this.config={cache:d,hooks:_,paranoid:y,timestamps:u,partitions:p,autoDecrypt:h,allNestedObjectsOptional:w},this.hooks={preInsert:[],afterInsert:[],preUpdate:[],afterUpdate:[],preDelete:[],afterDelete:[]},this.attributes=o||{},this.applyConfiguration(),_){for(const[m,x]of Object.entries(_))if(Array.isArray(x)&&this.hooks[m])for(const v of x)typeof v=="function"&&this.hooks[m].push(v.bind(this))}}get options(){return{timestamps:this.config.timestamps,partitions:this.config.partitions||{},cache:this.config.cache,autoDecrypt:this.config.autoDecrypt,paranoid:this.config.paranoid,allNestedObjectsOptional:this.config.allNestedObjectsOptional}}export(){const t=this.schema.export();return t.behavior=this.behavior,t.timestamps=this.config.timestamps,t.partitions=this.config.partitions||{},t.paranoid=this.config.paranoid,t.allNestedObjectsOptional=this.config.allNestedObjectsOptional,t.autoDecrypt=this.config.autoDecrypt,t.cache=this.config.cache,t.hooks=this.hooks,t}applyConfiguration(){this.config.timestamps&&(this.attributes.createdAt||(this.attributes.createdAt="string|optional"),this.attributes.updatedAt||(this.attributes.updatedAt="string|optional"),this.config.partitions||(this.config.partitions={}),this.config.partitions.byCreatedDate||(this.config.partitions.byCreatedDate={fields:{createdAt:"date|maxlength:10"}}),this.config.partitions.byUpdatedDate||(this.config.partitions.byUpdatedDate={fields:{updatedAt:"date|maxlength:10"}})),this.setupPartitionHooks(),this.schema=new _e({name:this.name,attributes:this.attributes,passphrase:this.passphrase,version:this.version,options:{autoDecrypt:this.config.autoDecrypt,allNestedObjectsOptional:this.config.allNestedObjectsOptional}}),this.validatePartitions()}updateAttributes(t){const r=this.attributes;return this.attributes=t,this.applyConfiguration(),{oldAttributes:r,newAttributes:t}}addHook(t,r){this.hooks[t]&&this.hooks[t].push(r.bind(this))}async executeHooks(t,r){if(!this.hooks[t])return r;let n=r;for(const i of this.hooks[t])n=await i(n);return n}setupPartitionHooks(){if(!this.config.partitions)return;const t=this.config.partitions;Object.keys(t).length!==0&&(this.hooks.afterInsert||(this.hooks.afterInsert=[]),this.hooks.afterInsert.push(async r=>(await this.createPartitionReferences(r),r)),this.hooks.afterDelete||(this.hooks.afterDelete=[]),this.hooks.afterDelete.push(async r=>(await this.deletePartitionReferences(r),r)))}async validate(t){const r={original:Rt(t),isValid:!1,errors:[]},n=await this.schema.validate(t,{mutateOriginal:!0});return n===!0?r.isValid=!0:r.errors=n,r.data=t,r}validatePartitions(){if(!this.config.partitions)return;const t=this.config.partitions;if(Object.keys(t).length===0)return;const r=Object.keys(this.attributes||{});for(const[n,i]of Object.entries(t))if(i.fields){for(const a of Object.keys(i.fields))if(!this.fieldExistsInAttributes(a))throw new Error(`Partition '${n}' uses field '${a}' which does not exist in resource attributes. Available fields: ${r.join(", ")}.`)}}fieldExistsInAttributes(t){if(!t.includes("."))return Object.keys(this.attributes||{}).includes(t);const r=t.split(".");let n=this.attributes||{};for(const i of r){if(!n||typeof n!="object"||!(i in n))return!1;n=n[i]}return!0}applyPartitionRule(t,r){if(t==null)return t;let n=t;if(typeof r=="string"&&r.includes("maxlength:")){const i=r.match(/maxlength:(\d+)/);if(i){const a=parseInt(i[1]);typeof n=="string"&&n.length>a&&(n=n.substring(0,a))}}if(r.includes("date")){if(n instanceof Date)n=n.toISOString().split("T")[0];else if(typeof n=="string")try{if(n.includes("T")&&n.includes("Z"))n=n.split("T")[0];else{const i=new Date(n);isNaN(i.getTime())||(n=i.toISOString().split("T")[0])}}catch{}}return n}getResourceKey(t){return me(`resource=${this.name}`,`v=${this.version}`,`id=${t}`)}getPartitionKey({partitionName:t,id:r,data:n}){if(!this.config.partitions||!this.config.partitions[t])throw new Error(`Partition '${t}' not found`);const i=this.config.partitions[t],a=[],o=Object.entries(i.fields).sort(([f],[c])=>f.localeCompare(c));for(const[f,c]of o){const l=this.getNestedFieldValue(n,f),d=this.applyPartitionRule(l,c);if(d==null)return null;a.push(`${f}=${d}`)}if(a.length===0)return null;const s=r||n?.id;return s?me(`resource=${this.name}`,`partition=${t}`,...a,`id=${s}`):null}getNestedFieldValue(t,r){if(!r.includes("."))return t[r];const n=r.split(".");let i=t;for(const a of n){if(!i||typeof i!="object"||!(a in i))return;i=i[a]}return i}async insert({id:t,...r}){this.options.timestamps&&(r.createdAt=new Date().toISOString(),r.updatedAt=new Date().toISOString());const n=await this.executeHooks("preInsert",r),{errors:i,isValid:a,data:o}=await this.validate(n);if(!a)throw new rr({bucket:this.client.config.bucket,resourceName:this.name,attributes:n,validation:i});!t&&t!==0&&(t=Zr());const s=await this.schema.mapper(o),f=ge(this.behavior),{mappedData:c,body:l}=await f.handleInsert({resource:this,data:o,mappedData:s}),d=this.getResourceKey(t);await this.client.putObject({metadata:c,key:d,body:l});const h=kt({id:t},o);return await this.executeHooks("afterInsert",h),this.emit("insert",h),h}async get(t){const r=this.getResourceKey(t);try{const n=await this.client.headObject(r),i=this.extractVersionFromKey(r)||this.version;let o=await(await this.getSchemaForVersion(i)).unmapper(n.Metadata);const s=ge(this.behavior);let f="";if(n.ContentLength>0)try{const d=await this.client.getObject(r);f=await yt(d.Body)}catch(d){console.warn(`Failed to read body for resource ${t}:`,d.message),f=""}const{metadata:c}=await s.handleGet({resource:this,metadata:o,body:f});let l=c;return l.id=t,l._contentLength=n.ContentLength,l._lastModified=n.LastModified,l._hasContent=n.ContentLength>0,l._mimeType=n.ContentType||null,n.VersionId&&(l._versionId=n.VersionId),n.Expiration&&(l._expiresAt=n.Expiration),l._definitionHash=this.getDefinitionHash(),this.emit("get",l),l}catch(n){if(n.message.includes("Cipher job failed")||n.message.includes("OperationError")||n.originalError?.message?.includes("Cipher job failed"))try{console.warn(`Decryption failed for resource ${t}, attempting to get raw metadata`);const a=await this.client.headObject(r),o=this.extractVersionFromKey(r)||this.version;let f=await new _e({name:this.name,attributes:this.attributes,passphrase:this.passphrase,version:o,options:{...this.config,autoDecrypt:!1,autoEncrypt:!1}}).unmapper(a.Metadata);const c=ge(this.behavior);let l="";if(a.ContentLength>0)try{const u=await this.client.getObject(r);l=await yt(u.Body)}catch(u){console.warn(`Failed to read body for resource ${t}:`,u.message),l=""}const{metadata:d}=await c.handleGet({resource:this,metadata:f,body:l});let h=d;return h.id=t,h._contentLength=a.ContentLength,h._lastModified=a.LastModified,h._hasContent=a.ContentLength>0,h._mimeType=a.ContentType||null,h._version=o,h._decryptionFailed=!0,a.VersionId&&(h._versionId=a.VersionId),a.Expiration&&(h._expiresAt=a.Expiration),h._definitionHash=this.getDefinitionHash(),this.emit("get",h),h}catch(a){console.error(`Fallback attempt also failed for resource ${t}:`,a.message)}const i=new Error(`Failed to get resource with id '${t}': ${n.message}`);throw i.originalError=n,i.resourceId=t,i.resourceKey=r,i}}async exists(t){try{const r=this.getResourceKey(t);return await this.client.headObject(r),!0}catch{return!1}}async update(t,r){const n=await this.get(t);this.config.timestamps&&(r.updatedAt=new Date().toISOString());const i=await this.executeHooks("preUpdate",r),a=kt(n,i);delete a.id;const{isValid:o,errors:s,data:f}=await this.validate(a);if(!o)throw new rr({bucket:this.client.bucket,resourceName:this.name,attributes:i,validation:s});const c={...n,id:t},l={...f,id:t};await this.handlePartitionReferenceUpdates(c,l);const d=await this.schema.mapper(f),h=ge(this.behavior),{mappedData:u,body:p}=await h.handleUpdate({resource:this,id:t,data:f,mappedData:d}),y=this.getResourceKey(t);let w,_=p;if(p===""&&this.behavior!=="body-overflow")try{const m=await this.client.getObject(y);if(m.ContentLength>0){const x=Buffer.from(await m.Body.transformToByteArray()),v=x.toString();try{JSON.parse(v)}catch{_=x,w=m.ContentType}}}catch{}return await this.client.putObject({key:y,body:_,contentType:w,metadata:u}),f.id=t,await this.executeHooks("afterUpdate",f),this.emit("update",i,f),f}async delete(t){let r;try{r=await this.get(t)}catch{r={id:t}}await this.executeHooks("preDelete",r);const n=this.getResourceKey(t),i=await this.client.deleteObject(n);return await this.executeHooks("afterDelete",r),this.emit("delete",t),i}async upsert({id:t,...r}){return await this.exists(t)?this.update(t,r):this.insert({id:t,...r})}async count({partition:t=null,partitionValues:r={}}={}){let n;if(t&&Object.keys(r).length>0){const a=this.config.partitions[t];if(!a)throw new Error(`Partition '${t}' not found`);const o=[],s=Object.entries(a.fields).sort(([f],[c])=>f.localeCompare(c));for(const[f,c]of s){const l=r[f];if(l!=null){const d=this.applyPartitionRule(l,c);o.push(`${f}=${d}`)}}o.length>0?n=`resource=${this.name}/partition=${t}/${o.join("/")}`:n=`resource=${this.name}/partition=${t}`}else n=`resource=${this.name}/v=${this.version}`;const i=await this.client.count({prefix:n});return this.emit("count",i),i}async insertMany(t){const{results:r}=await he.for(t).withConcurrency(this.parallelism).handleError(async(n,i)=>{this.emit("error",n,i),this.observers.map(a=>a.emit("error",this.name,n,i))}).process(async n=>await this.insert(n));return this.emit("insertMany",t.length),r}async deleteMany(t){const r=qi(t.map(i=>this.getResourceKey(i)),1e3),{results:n}=await he.for(r).withConcurrency(this.parallelism).handleError(async(i,a)=>{this.emit("error",i,a),this.observers.map(o=>o.emit("error",this.name,i,a))}).process(async i=>{const a=await this.client.deleteObjects(i);return i.forEach(o=>{const f=o.split("/").find(l=>l.startsWith("id=")),c=f?f.replace("id=",""):null;c&&(this.emit("deleted",c),this.observers.map(l=>l.emit("deleted",this.name,c)))}),a});return this.emit("deleteMany",t.length),n}async deleteAll(){if(this.config.paranoid!==!1)throw new Error(`deleteAll() is a dangerous operation and requires paranoid: false option. Current paranoid setting: ${this.config.paranoid}`);const t=`resource=${this.name}/v=${this.version}`,r=await this.client.deleteAll({prefix:t});return this.emit("deleteAll",{version:this.version,prefix:t,deletedCount:r}),{deletedCount:r,version:this.version}}async deleteAllData(){if(this.config.paranoid!==!1)throw new Error(`deleteAllData() is a dangerous operation and requires paranoid: false option. Current paranoid setting: ${this.config.paranoid}`);const t=`resource=${this.name}`,r=await this.client.deleteAll({prefix:t});return this.emit("deleteAllData",{resource:this.name,prefix:t,deletedCount:r}),{deletedCount:r,resource:this.name}}async listIds({partition:t=null,partitionValues:r={},limit:n,offset:i=0}={}){let a;if(t&&Object.keys(r).length>0){if(!this.config.partitions||!this.config.partitions[t])throw new Error(`Partition '${t}' not found`);const f=this.config.partitions[t],c=[],l=Object.entries(f.fields).sort(([d],[h])=>d.localeCompare(h));for(const[d,h]of l){const u=r[d];if(u!=null){const p=this.applyPartitionRule(u,h);c.push(`${d}=${p}`)}}c.length>0?a=`resource=${this.name}/partition=${t}/${c.join("/")}`:a=`resource=${this.name}/partition=${t}`}else a=`resource=${this.name}/v=${this.version}`;const s=(await this.client.getKeysPage({prefix:a,offset:i,amount:n||1e3})).map(f=>{const l=f.split("/").find(d=>d.startsWith("id="));return l?l.replace("id=",""):null}).filter(Boolean);return this.emit("listIds",s.length),s}async list({partition:t=null,partitionValues:r={},limit:n,offset:i=0}={}){try{if(!t){let y=[];try{y=await this.listIds({partition:t,partitionValues:r})}catch(v){return console.warn("Failed to get list IDs:",v.message),[]}let w=y.slice(i);n&&(w=w.slice(0,n));const{results:_,errors:m}=await he.for(w).withConcurrency(this.parallelism).handleError(async(v,A)=>(console.warn(`Failed to get resource ${A}:`,v.message),null)).process(async v=>{try{return await this.get(v)}catch(A){if(A.message.includes("Cipher job failed")||A.message.includes("OperationError"))return console.warn(`Decryption failed for ${v}, returning basic info`),{id:v,_decryptionFailed:!0,_error:A.message};throw A}}),x=_.filter(v=>v!==null);return this.emit("list",{partition:t,partitionValues:r,count:x.length,errors:m.length}),x}if(!this.config.partitions||!this.config.partitions[t])return console.warn(`Partition '${t}' not found in resource '${this.name}'`),this.emit("list",{partition:t,partitionValues:r,count:0,errors:0}),[];const a=this.config.partitions[t],o=[],s=Object.entries(a.fields).sort(([y],[w])=>y.localeCompare(w));for(const[y,w]of s){const _=r[y];if(_!=null){const m=this.applyPartitionRule(_,w);o.push(`${y}=${m}`)}}let f;o.length>0?f=`resource=${this.name}/partition=${t}/${o.join("/")}`:f=`resource=${this.name}/partition=${t}`;let c=[];try{c=await this.client.getAllKeys({prefix:f})}catch(y){return console.warn("Failed to get partition keys:",y.message),[]}let d=c.map(y=>{const _=y.split("/").find(m=>m.startsWith("id="));return _?_.replace("id=",""):null}).filter(Boolean).slice(i);n&&(d=d.slice(0,n));const{results:h,errors:u}=await he.for(d).withConcurrency(this.parallelism).handleError(async(y,w)=>(console.warn(`Failed to get partition resource ${w}:`,y.message),null)).process(async y=>{try{const w=c.find(x=>x.includes(`id=${y}`));if(!w)throw new Error(`Partition key not found for ID ${y}`);const _=w.split("/"),m={};for(const[x,v]of s){const A=_.find(O=>O.startsWith(`${x}=`));if(A){const O=A.replace(`${x}=`,"");m[x]=O}}return await this.getFromPartition({id:y,partitionName:t,partitionValues:m})}catch(w){if(w.message.includes("Cipher job failed")||w.message.includes("OperationError"))return console.warn(`Decryption failed for partition resource ${y}, returning basic info`),{id:y,_partition:t,_partitionValues:r,_decryptionFailed:!0,_error:w.message};throw w}}),p=h.filter(y=>y!==null);return this.emit("list",{partition:t,partitionValues:r,count:p.length,errors:u.length}),p}catch(a){return a.message.includes("Partition '")&&a.message.includes("' not found")?(console.warn("Partition error in list method:",a.message),this.emit("list",{partition:t,partitionValues:r,count:0,errors:1}),[]):(console.error("Critical error in list method:",a.message),this.emit("list",{partition:t,partitionValues:r,count:0,errors:1}),[])}}async getMany(t){const{results:r,errors:n}=await he.for(t).withConcurrency(this.client.parallelism).handleError(async(i,a)=>(console.warn(`Failed to get resource ${a}:`,i.message),{id:a,_error:i.message,_decryptionFailed:i.message.includes("Cipher job failed")||i.message.includes("OperationError")})).process(async i=>{this.emit("id",i);try{const a=await this.get(i);return this.emit("data",a),a}catch(a){if(a.message.includes("Cipher job failed")||a.message.includes("OperationError"))return console.warn(`Decryption failed for ${i}, returning basic info`),{id:i,_decryptionFailed:!0,_error:a.message};throw a}});return this.emit("getMany",t.length),r}async getAll(){let t=await this.listIds();if(t.length===0)return[];const{results:r,errors:n}=await he.for(t).withConcurrency(this.client.parallelism).handleError(async(i,a)=>(console.warn(`Failed to get resource ${a}:`,i.message),{id:a,_error:i.message,_decryptionFailed:i.message.includes("Cipher job failed")||i.message.includes("OperationError")})).process(async i=>{try{return await this.get(i)}catch(a){if(a.message.includes("Cipher job failed")||a.message.includes("OperationError"))return console.warn(`Decryption failed for ${i}, returning basic info`),{id:i,_decryptionFailed:!0,_error:a.message};throw a}});return this.emit("getAll",r.length),r}async page({offset:t=0,size:r=100,partition:n=null,partitionValues:i={},skipCount:a=!1}={}){try{let o=null,s=null;if(!a)try{o=await this.count({partition:n,partitionValues:i}),s=Math.ceil(o/r)}catch(d){console.warn("Failed to get count for page:",d.message),o=null,s=null}const f=Math.floor(t/r);let c=[];try{c=await this.list({partition:n,partitionValues:i,limit:r,offset:t})}catch(d){console.warn("Failed to get items for page:",d.message),c=[]}const l={items:c,totalItems:o,page:f,pageSize:r,totalPages:s,_debug:{requestedSize:r,requestedOffset:t,actualItemsReturned:c.length,skipCount:a,hasTotalItems:o!==null}};return this.emit("page",l),l}catch(o){return console.error("Critical error in page method:",o.message),{items:[],totalItems:null,page:Math.floor(t/r),pageSize:r,totalPages:null,_debug:{requestedSize:r,requestedOffset:t,actualItemsReturned:0,skipCount:a,hasTotalItems:!1,error:o.message}}}}readable(){return new fs({resource:this}).build()}writable(){return new ls({resource:this}).build()}async setContent({id:t,buffer:r,contentType:n="application/octet-stream"}){const i=await this.get(t);if(!i)throw new Error(`Resource with id '${t}' not found`);const a={...i,_hasContent:!0,_contentLength:r.length,_mimeType:n};return await this.client.putObject({key:this.getResourceKey(t),metadata:await this.schema.mapper(a),body:r,contentType:n}),this.emit("setContent",{id:t,contentType:n,contentLength:r.length}),a}async content(t){const r=this.getResourceKey(t);try{const n=await this.client.getObject(r),i=Buffer.from(await n.Body.transformToByteArray()),a=n.ContentType||null;return this.emit("content",t,i.length,a),{buffer:i,contentType:a}}catch(n){if(n.name==="NoSuchKey")return{buffer:null,contentType:null};throw n}}async hasContent(t){const r=this.getResourceKey(t);try{return(await this.client.headObject(r)).ContentLength>0}catch{return!1}}async deleteContent(t){const r=this.getResourceKey(t),i=(await this.client.headObject(r)).Metadata||{},a=await this.client.putObject({key:r,body:"",metadata:i});return this.emit("deleteContent",t),a}getDefinitionHash(){const t={attributes:this.attributes,behavior:this.behavior},r=vo(t);return`sha256:${Vi("sha256").update(r).digest("hex")}`}extractVersionFromKey(t){const n=t.split("/").find(i=>i.startsWith("v="));return n?n.replace("v=",""):null}async getSchemaForVersion(t){if(t===this.version)return this.schema;try{return new _e({name:this.name,attributes:this.attributes,passphrase:this.passphrase,version:t,options:{...this.config,autoDecrypt:!0,autoEncrypt:!0}})}catch(r){return console.warn(`Failed to create compatible schema for version ${t}, using current schema:`,r.message),this.schema}}async createPartitionReferences(t){const r=this.config.partitions;if(!(!r||Object.keys(r).length===0))for(const[n,i]of Object.entries(r)){const a=this.getPartitionKey({partitionName:n,id:t.id,data:t});if(a){const o=await this.schema.mapper(t),s=ge(this.behavior),{mappedData:f,body:c}=await s.handleInsert({resource:this,data:t,mappedData:o}),l={...f,_version:this.version};await this.client.putObject({key:a,metadata:l,body:c})}}}async deletePartitionReferences(t){const r=this.config.partitions;if(!r||Object.keys(r).length===0)return;const n=[];for(const[i,a]of Object.entries(r)){const o=this.getPartitionKey({partitionName:i,id:t.id,data:t});o&&n.push(o)}if(n.length>0)try{await this.client.deleteObjects(n)}catch(i){console.warn("Some partition objects could not be deleted:",i.message)}}async query(t={},{limit:r=100,offset:n=0,partition:i=null,partitionValues:a={}}={}){if(Object.keys(t).length===0)return await this.list({partition:i,partitionValues:a,limit:r,offset:n});const o=[];let s=n;const f=Math.min(r,50);for(;o.length<r;){const c=await this.list({partition:i,partitionValues:a,limit:f,offset:s});if(c.length===0)break;const l=c.filter(d=>Object.entries(t).every(([h,u])=>d[h]===u));if(o.push(...l),s+=f,c.length<f)break}return o.slice(0,r)}async handlePartitionReferenceUpdates(t,r){const n=this.config.partitions;if(!n||Object.keys(n).length===0)return;for(const[a,o]of Object.entries(n))try{await this.handlePartitionReferenceUpdate(a,o,t,r)}catch(s){console.warn(`Failed to update partition references for ${a}:`,s.message)}const i=r.id||t.id;for(const[a,o]of Object.entries(n)){const s=`resource=${this.name}/partition=${a}`;let f=[];try{f=await this.client.getAllKeys({prefix:s})}catch(l){console.warn(`Aggressive cleanup: could not list keys for partition ${a}:`,l.message);continue}const c=this.getPartitionKey({partitionName:a,id:i,data:r});for(const l of f)if(l.endsWith(`/id=${i}`)&&l!==c)try{await this.client.deleteObject(l)}catch(d){console.warn(`Aggressive cleanup: could not delete stale partition key ${l}:`,d.message)}}}async handlePartitionReferenceUpdate(t,r,n,i){const a=i.id||n.id,o=this.getPartitionKey({partitionName:t,id:a,data:n}),s=this.getPartitionKey({partitionName:t,id:a,data:i});if(o!==s){if(o)try{await this.client.deleteObject(o)}catch(f){console.warn(`Old partition object could not be deleted for ${t}:`,f.message)}if(s)try{const f=await this.schema.mapper(i);f.undefined!==void 0&&delete f.undefined;const c=ge(this.behavior),{mappedData:l,body:d}=await c.handleUpdate({resource:this,id:a,data:i,mappedData:f});l.undefined!==void 0&&delete l.undefined;const h={...l,_version:this.version};h.undefined!==void 0&&delete h.undefined,await this.client.putObject({key:s,metadata:h,body:d})}catch(f){console.warn(`New partition object could not be created for ${t}:`,f.message)}}else if(s)try{const f=await this.schema.mapper(i);f.undefined!==void 0&&delete f.undefined;const c=ge(this.behavior),{mappedData:l,body:d}=await c.handleUpdate({resource:this,id:a,data:i,mappedData:f});l.undefined!==void 0&&delete l.undefined;const h={...l,_version:this.version};h.undefined!==void 0&&delete h.undefined,await this.client.putObject({key:s,metadata:h,body:d})}catch(f){console.warn(`Partition object could not be updated for ${t}:`,f.message)}}async updatePartitionReferences(t){const r=this.config.partitions;if(!(!r||Object.keys(r).length===0))for(const[n,i]of Object.entries(r)){if(!i||!i.fields||typeof i.fields!="object"){console.warn(`Skipping invalid partition '${n}' in resource '${this.name}'`);continue}const a=this.getPartitionKey({partitionName:n,id:t.id,data:t});if(a){const o=await this.schema.mapper(t),s=ge(this.behavior),{mappedData:f,body:c}=await s.handleUpdate({resource:this,id:t.id,data:t,mappedData:o}),l={...f,_version:this.version};try{await this.client.putObject({key:a,metadata:l,body:c})}catch(d){console.warn(`Partition object could not be updated for ${n}:`,d.message)}}}}async getFromPartition({id:t,partitionName:r,partitionValues:n={}}){if(!this.config.partitions||!this.config.partitions[r])throw new Error(`Partition '${r}' not found`);const i=this.config.partitions[r],a=[],o=Object.entries(i.fields).sort(([w],[_])=>w.localeCompare(_));for(const[w,_]of o){const m=n[w];if(m!=null){const x=this.applyPartitionRule(m,_);a.push(`${w}=${x}`)}}if(a.length===0)throw new Error(`No partition values provided for partition '${r}'`);const s=me(`resource=${this.name}`,`partition=${r}`,...a,`id=${t}`),f=await this.client.headObject(s),c=f.Metadata?._version||this.version;let d=await(await this.getSchemaForVersion(c)).unmapper(f.Metadata);const h=ge(this.behavior);let u="";if(f.ContentLength>0)try{const w=await this.client.getObject(s);u=await yt(w.Body)}catch{u=""}const{metadata:p}=await h.handleGet({resource:this,metadata:d,body:u});let y=p;return y.id=t,y._contentLength=f.ContentLength,y._lastModified=f.LastModified,y._hasContent=f.ContentLength>0,y._mimeType=f.ContentType||null,y._partition=r,y._partitionValues=n,f.VersionId&&(y._versionId=f.VersionId),f.Expiration&&(y._expiresAt=f.Expiration),y._definitionHash=this.getDefinitionHash(),y.undefined!==void 0&&delete y.undefined,this.emit("getFromPartition",y),y}}function Lh(e){const t=[];e.name?typeof e.name!="string"?t.push("Resource 'name' must be a string"):e.name.trim()===""&&t.push("Resource 'name' cannot be empty"):t.push("Resource 'name' is required"),e.client||t.push("S3 'client' is required"),e.attributes?typeof e.attributes!="object"||Array.isArray(e.attributes)?t.push("Resource 'attributes' must be an object"):Object.keys(e.attributes).length===0&&t.push("Resource 'attributes' cannot be empty"):t.push("Resource 'attributes' are required"),e.version!==void 0&&typeof e.version!="string"&&t.push("Resource 'version' must be a string"),e.behavior!==void 0&&typeof e.behavior!="string"&&t.push("Resource 'behavior' must be a string"),e.passphrase!==void 0&&typeof e.passphrase!="string"&&t.push("Resource 'passphrase' must be a string"),e.parallelism!==void 0&&(typeof e.parallelism!="number"||!Number.isInteger(e.parallelism)?t.push("Resource 'parallelism' must be an integer"):e.parallelism<1&&t.push("Resource 'parallelism' must be greater than 0")),e.observers!==void 0&&!Array.isArray(e.observers)&&t.push("Resource 'observers' must be an array");const r=["cache","autoDecrypt","timestamps","paranoid","allNestedObjectsOptional"];for(const n of r)e[n]!==void 0&&typeof e[n]!="boolean"&&t.push(`Resource '${n}' must be a boolean`);if(e.partitions!==void 0)if(typeof e.partitions!="object"||Array.isArray(e.partitions))t.push("Resource 'partitions' must be an object");else for(const[n,i]of Object.entries(e.partitions))if(typeof i!="object"||Array.isArray(i))t.push(`Partition '${n}' must be an object`);else if(!i.fields)t.push(`Partition '${n}' must have a 'fields' property`);else if(typeof i.fields!="object"||Array.isArray(i.fields))t.push(`Partition '${n}.fields' must be an object`);else for(const[a,o]of Object.entries(i.fields))typeof o!="string"&&t.push(`Partition '${n}.fields.${a}' must be a string`);if(e.hooks!==void 0)if(typeof e.hooks!="object"||Array.isArray(e.hooks))t.push("Resource 'hooks' must be an object");else{const n=["preInsert","afterInsert","preUpdate","afterUpdate","preDelete","afterDelete"];for(const[i,a]of Object.entries(e.hooks))if(!n.includes(i))t.push(`Invalid hook event '${i}'. Valid events: ${n.join(", ")}`);else if(!Array.isArray(a))t.push(`Resource 'hooks.${i}' must be an array`);else for(let o=0;o<a.length;o++){const s=a[o];if(typeof s!="function"){if(typeof s=="string")continue;continue}}}return{isValid:t.length===0,errors:t}}class ps extends R{constructor(t){super(),this.version="1",this.s3dbVersion=(()=>{try{return"5.0.0"}catch{return"latest"}})(),this.resources={},this.savedMetadata=null,this.options=t,this.verbose=t.verbose||!1,this.parallelism=parseInt(t.parallelism+"")||10,this.plugins=t.plugins||[],this.cache=t.cache,this.passphrase=t.passphrase||"secret";let r=t.connectionString;if(!r&&(t.bucket||t.accessKeyId||t.secretAccessKey)){const{bucket:n,region:i,accessKeyId:a,secretAccessKey:o,endpoint:s,forcePathStyle:f}=t;if(s){const c=new URL(s);a&&(c.username=encodeURIComponent(a)),o&&(c.password=encodeURIComponent(o)),c.pathname=`/${n||"s3db"}`,f&&c.searchParams.set("forcePathStyle","true"),r=c.toString()}else if(a&&o){const c=new URLSearchParams;c.set("region",i||"us-east-1"),f&&c.set("forcePathStyle","true"),r=`s3://${encodeURIComponent(a)}:${encodeURIComponent(o)}@${n||"s3db"}?${c.toString()}`}}this.client=t.client||new ua({verbose:this.verbose,parallelism:this.parallelism,connectionString:r}),this.bucket=this.client.bucket,this.keyPrefix=this.client.keyPrefix}async connect(){await this.startPlugins();let t=null;if(await this.client.exists("s3db.json")){const n=await this.client.getObject("s3db.json");t=JSON.parse(await yt(n?.Body))}else t=this.blankMetadataStructure(),await this.uploadMetadataFile();this.savedMetadata=t;const r=this.detectDefinitionChanges(t);for(const[n,i]of Object.entries(t.resources||{})){const a=i.currentVersion||"v0",o=i.versions?.[a];o&&(this.resources[n]=new br({name:n,client:this.client,version:a,attributes:o.attributes,behavior:o.behavior||"user-management",parallelism:this.parallelism,passphrase:this.passphrase,observers:[this],cache:this.cache,timestamps:o.timestamps!==void 0?o.timestamps:!1,partitions:i.partitions||o.partitions||{},paranoid:o.paranoid!==void 0?o.paranoid:!0,allNestedObjectsOptional:o.allNestedObjectsOptional!==void 0?o.allNestedObjectsOptional:!0,autoDecrypt:o.autoDecrypt!==void 0?o.autoDecrypt:!0,hooks:o.hooks||{}}))}r.length>0&&this.emit("resourceDefinitionsChanged",{changes:r,metadata:this.savedMetadata}),this.emit("connected",new Date)}detectDefinitionChanges(t){const r=[];for(const[n,i]of Object.entries(this.resources)){const a=this.generateDefinitionHash(i.export()),o=t.resources?.[n];if(!o)r.push({type:"new",resourceName:n,currentHash:a,savedHash:null});else{const s=o.currentVersion||"v0",c=o.versions?.[s]?.hash;c!==a&&r.push({type:"changed",resourceName:n,currentHash:a,savedHash:c,fromVersion:s,toVersion:this.getNextVersion(o.versions)})}}for(const[n,i]of Object.entries(t.resources||{}))if(!this.resources[n]){const a=i.currentVersion||"v0",o=i.versions?.[a];r.push({type:"deleted",resourceName:n,currentHash:null,savedHash:o?.hash,deletedVersion:a})}return r}generateDefinitionHash(t,r=void 0){const i={...t.attributes};t.timestamps&&(delete i.createdAt,delete i.updatedAt);const a={attributes:i,behavior:r||t.behavior||"user-management"},o=vo(a);return`sha256:${Vi("sha256").update(o).digest("hex")}`}getNextVersion(t={}){const r=Object.keys(t).filter(i=>i.startsWith("v")).map(i=>parseInt(i.substring(1))).filter(i=>!isNaN(i));return`v${(r.length>0?Math.max(...r):-1)+1}`}async startPlugins(){const t=this;if(!Hi(this.plugins)){const r=this.plugins.map(a=>Vc(a)?new a(this):a),n=r.map(async a=>{a.beforeSetup&&await a.beforeSetup(),await a.setup(t),a.afterSetup&&await a.afterSetup()});await Promise.all(n);const i=r.map(async a=>{a.beforeStart&&await a.beforeStart(),await a.start(),a.afterStart&&await a.afterStart()});await Promise.all(i)}}async uploadMetadataFile(){const t={version:this.version,s3dbVersion:this.s3dbVersion,lastUpdated:new Date().toISOString(),resources:{}};Object.entries(this.resources).forEach(([r,n])=>{const i=n.export(),a=this.generateDefinitionHash(i),o=this.savedMetadata?.resources?.[r],s=o?.currentVersion||"v0",f=o?.versions?.[s];let c,l;!f||f.hash!==a?(c=this.getNextVersion(o?.versions),l=!0):(c=s,l=!1),t.resources[r]={currentVersion:c,partitions:n.config.partitions||{},versions:{...o?.versions,[c]:{hash:a,attributes:i.attributes,behavior:i.behavior||"user-management",timestamps:n.config.timestamps,partitions:n.config.partitions,paranoid:n.config.paranoid,allNestedObjectsOptional:n.config.allNestedObjectsOptional,autoDecrypt:n.config.autoDecrypt,cache:n.config.cache,hooks:n.config.hooks,createdAt:l?new Date().toISOString():f?.createdAt}}},n.version!==c&&(n.version=c,n.emit("versionUpdated",{oldVersion:s,newVersion:c}))}),await this.client.putObject({key:"s3db.json",body:JSON.stringify(t,null,2),contentType:"application/json"}),this.savedMetadata=t,this.emit("metadataUploaded",t)}blankMetadataStructure(){return{version:"1",s3dbVersion:this.s3dbVersion,resources:{}}}resourceExists(t){return!!this.resources[t]}resourceExistsWithSameHash({name:t,attributes:r,behavior:n="user-management",options:i={}}){if(!this.resources[t])return{exists:!1,sameHash:!1,hash:null};const a=this.resources[t],o=this.generateDefinitionHash(a.export()),s=new br({name:t,attributes:r,behavior:n,client:this.client,version:a.version,passphrase:this.passphrase,...i}),f=this.generateDefinitionHash(s.export());return{exists:!0,sameHash:o===f,hash:f,existingHash:o}}async createResource({name:t,attributes:r,behavior:n="user-management",hooks:i,...a}){if(this.resources[t]){const c=this.resources[t];if(Object.assign(c.config,{cache:this.cache,...a}),n&&(c.behavior=n),c.updateAttributes(r),i){for(const[p,y]of Object.entries(i))if(Array.isArray(y)&&c.hooks[p])for(const w of y)typeof w=="function"&&c.hooks[p].push(w.bind(c))}const l=this.generateDefinitionHash(c.export(),c.behavior),d=this.savedMetadata?.resources?.[t],h=d?.currentVersion||"v0",u=d?.versions?.[h];return(!u||u.hash!==l)&&await this.uploadMetadataFile(),this.emit("s3db.resourceUpdated",t),c}const s=this.savedMetadata?.resources?.[t]?.currentVersion||"v0",f=new br({name:t,attributes:r,behavior:n,observers:[this],client:this.client,version:s,passphrase:this.passphrase,cache:this.cache,hooks:i,...a});return this.resources[t]=f,await this.uploadMetadataFile(),this.emit("s3db.resourceCreated",t),f}resource(t){return this.resources[t]?this.resources[t]:Promise.reject(`resource ${t} does not exist`)}async listResources(){return Object.keys(this.resources).map(t=>({name:t}))}async getResource(t){if(!this.resources[t])throw new Error(`Resource not found: ${t}`);return this.resources[t]}get config(){return{version:this.version,s3dbVersion:this.s3dbVersion,bucket:this.bucket,keyPrefix:this.keyPrefix,parallelism:this.parallelism,verbose:this.verbose}}isConnected(){return!!this.savedMetadata}}class ys extends ps{}class gi extends R{constructor(t={}){super(),this.config=t}async _set(t,r){}async _get(t){}async _del(t){}async _clear(t){}validateKey(t){if(t==null||typeof t!="string"||!t)throw new Error("Invalid key")}async set(t,r){return this.validateKey(t),await this._set(t,r),this.emit("set",r),r}async get(t){this.validateKey(t);const r=await this._get(t);return this.emit("get",r),r}async del(t){this.validateKey(t);const r=await this._del(t);return this.emit("delete",r),r}async delete(t){return this.del(t)}async clear(){const t=await this._clear();return this.emit("clear",t),t}}class Nh extends gi{constructor(t={}){super(t),this.cache={},this.meta={},this.maxSize=t.maxSize||0,this.ttl=t.ttl||0}async _set(t,r){if(this.maxSize>0&&Object.keys(this.cache).length>=this.maxSize){const n=Object.entries(this.meta).sort((i,a)=>i[1].ts-a[1].ts)[0]?.[0];n&&(delete this.cache[n],delete this.meta[n])}return this.cache[t]=r,this.meta[t]={ts:Date.now()},r}async _get(t){if(!Object.prototype.hasOwnProperty.call(this.cache,t))return null;if(this.ttl>0){const r=Date.now(),n=this.meta[t];if(n&&r-n.ts>this.ttl*1e3)return delete this.cache[t],delete this.meta[t],null}return this.cache[t]}async _del(t){return delete this.cache[t],delete this.meta[t],!0}async _clear(){return this.cache={},this.meta={},!0}async size(){return Object.keys(this.cache).length}async keys(){return Object.keys(this.cache)}}var gs={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"};function $h(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}function ke(e,t,r,n,i){if(t.subarray&&e.subarray){e.set(t.subarray(r,r+n),i);return}for(var a=0;a<n;a++)e[i+a]=t[r+a]}var mr=Uint8Array,oe=Uint16Array,xr=Int32Array,Uh=4,vs=0,ws=1,Bh=2;function gt(e){for(var t=e.length;--t>=0;)e[t]=0}var zh=0,_s=1,Zh=2,qh=3,Hh=258,vi=29,Ct=256,Dt=Ct+1+vi,vt=30,wi=19,bs=2*Dt+1,Je=15,_i=16,Kh=7,bi=256,ms=16,xs=17,Es=18,mi=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],Er=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],Wh=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],Ss=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],Vh=512,Re=new Array((Dt+2)*2);gt(Re);var Mt=new Array(vt*2);gt(Mt);var Lt=new Array(Vh);gt(Lt);var Nt=new Array(Hh-qh+1);gt(Nt);var xi=new Array(vi);gt(xi);var Sr=new Array(vt);gt(Sr);function Ei(e,t,r,n,i){this.static_tree=e,this.extra_bits=t,this.extra_base=r,this.elems=n,this.max_length=i,this.has_stree=e&&e.length}var As,ks,Rs;function Si(e,t){this.dyn_tree=e,this.max_code=0,this.stat_desc=t}function Os(e){return e<256?Lt[e]:Lt[256+(e>>>7)]}function $t(e,t){e.pending_buf[e.pending++]=t&255,e.pending_buf[e.pending++]=t>>>8&255}function Q(e,t,r){e.bi_valid>_i-r?(e.bi_buf|=t<<e.bi_valid&65535,$t(e,e.bi_buf),e.bi_buf=t>>_i-e.bi_valid,e.bi_valid+=r-_i):(e.bi_buf|=t<<e.bi_valid&65535,e.bi_valid+=r)}function ve(e,t,r){Q(e,r[t*2],r[t*2+1])}function Is(e,t){var r=0;do r|=e&1,e>>>=1,r<<=1;while(--t>0);return r>>>1}function Gh(e){e.bi_valid===16?($t(e,e.bi_buf),e.bi_buf=0,e.bi_valid=0):e.bi_valid>=8&&(e.pending_buf[e.pending++]=e.bi_buf&255,e.bi_buf>>=8,e.bi_valid-=8)}function Yh(e,t){var r=t.dyn_tree,n=t.max_code,i=t.stat_desc.static_tree,a=t.stat_desc.has_stree,o=t.stat_desc.extra_bits,s=t.stat_desc.extra_base,f=t.stat_desc.max_length,c,l,d,h,u,p,y=0;for(h=0;h<=Je;h++)e.bl_count[h]=0;for(r[e.heap[e.heap_max]*2+1]=0,c=e.heap_max+1;c<bs;c++)l=e.heap[c],h=r[r[l*2+1]*2+1]+1,h>f&&(h=f,y++),r[l*2+1]=h,!(l>n)&&(e.bl_count[h]++,u=0,l>=s&&(u=o[l-s]),p=r[l*2],e.opt_len+=p*(h+u),a&&(e.static_len+=p*(i[l*2+1]+u)));if(y!==0){do{for(h=f-1;e.bl_count[h]===0;)h--;e.bl_count[h]--,e.bl_count[h+1]+=2,e.bl_count[f]--,y-=2}while(y>0);for(h=f;h!==0;h--)for(l=e.bl_count[h];l!==0;)d=e.heap[--c],!(d>n)&&(r[d*2+1]!==h&&(e.opt_len+=(h-r[d*2+1])*r[d*2],r[d*2+1]=h),l--)}}function Ts(e,t,r){var n=new Array(Je+1),i=0,a,o;for(a=1;a<=Je;a++)n[a]=i=i+r[a-1]<<1;for(o=0;o<=t;o++){var s=e[o*2+1];s!==0&&(e[o*2]=Is(n[s]++,s))}}function Jh(){var e,t,r,n,i,a=new Array(Je+1);for(r=0,n=0;n<vi-1;n++)for(xi[n]=r,e=0;e<1<<mi[n];e++)Nt[r++]=n;for(Nt[r-1]=n,i=0,n=0;n<16;n++)for(Sr[n]=i,e=0;e<1<<Er[n];e++)Lt[i++]=n;for(i>>=7;n<vt;n++)for(Sr[n]=i<<7,e=0;e<1<<Er[n]-7;e++)Lt[256+i++]=n;for(t=0;t<=Je;t++)a[t]=0;for(e=0;e<=143;)Re[e*2+1]=8,e++,a[8]++;for(;e<=255;)Re[e*2+1]=9,e++,a[9]++;for(;e<=279;)Re[e*2+1]=7,e++,a[7]++;for(;e<=287;)Re[e*2+1]=8,e++,a[8]++;for(Ts(Re,Dt+1,a),e=0;e<vt;e++)Mt[e*2+1]=5,Mt[e*2]=Is(e,5);As=new Ei(Re,mi,Ct+1,Dt,Je),ks=new Ei(Mt,Er,0,vt,Je),Rs=new Ei(new Array(0),Wh,0,wi,Kh)}function Ps(e){var t;for(t=0;t<Dt;t++)e.dyn_ltree[t*2]=0;for(t=0;t<vt;t++)e.dyn_dtree[t*2]=0;for(t=0;t<wi;t++)e.bl_tree[t*2]=0;e.dyn_ltree[bi*2]=1,e.opt_len=e.static_len=0,e.last_lit=e.matches=0}function js(e){e.bi_valid>8?$t(e,e.bi_buf):e.bi_valid>0&&(e.pending_buf[e.pending++]=e.bi_buf),e.bi_buf=0,e.bi_valid=0}function Xh(e,t,r,n){js(e),$t(e,r),$t(e,~r),ke(e.pending_buf,e.window,t,r,e.pending),e.pending+=r}function Fs(e,t,r,n){var i=t*2,a=r*2;return e[i]<e[a]||e[i]===e[a]&&n[t]<=n[r]}function Ai(e,t,r){for(var n=e.heap[r],i=r<<1;i<=e.heap_len&&(i<e.heap_len&&Fs(t,e.heap[i+1],e.heap[i],e.depth)&&i++,!Fs(t,n,e.heap[i],e.depth));)e.heap[r]=e.heap[i],r=i,i<<=1;e.heap[r]=n}function Cs(e,t,r){var n,i,a=0,o,s;if(e.last_lit!==0)do n=e.pending_buf[e.d_buf+a*2]<<8|e.pending_buf[e.d_buf+a*2+1],i=e.pending_buf[e.l_buf+a],a++,n===0?ve(e,i,t):(o=Nt[i],ve(e,o+Ct+1,t),s=mi[o],s!==0&&(i-=xi[o],Q(e,i,s)),n--,o=Os(n),ve(e,o,r),s=Er[o],s!==0&&(n-=Sr[o],Q(e,n,s)));while(a<e.last_lit);ve(e,bi,t)}function ki(e,t){var r=t.dyn_tree,n=t.stat_desc.static_tree,i=t.stat_desc.has_stree,a=t.stat_desc.elems,o,s,f=-1,c;for(e.heap_len=0,e.heap_max=bs,o=0;o<a;o++)r[o*2]!==0?(e.heap[++e.heap_len]=f=o,e.depth[o]=0):r[o*2+1]=0;for(;e.heap_len<2;)c=e.heap[++e.heap_len]=f<2?++f:0,r[c*2]=1,e.depth[c]=0,e.opt_len--,i&&(e.static_len-=n[c*2+1]);for(t.max_code=f,o=e.heap_len>>1;o>=1;o--)Ai(e,r,o);c=a;do o=e.heap[1],e.heap[1]=e.heap[e.heap_len--],Ai(e,r,1),s=e.heap[1],e.heap[--e.heap_max]=o,e.heap[--e.heap_max]=s,r[c*2]=r[o*2]+r[s*2],e.depth[c]=(e.depth[o]>=e.depth[s]?e.depth[o]:e.depth[s])+1,r[o*2+1]=r[s*2+1]=c,e.heap[1]=c++,Ai(e,r,1);while(e.heap_len>=2);e.heap[--e.heap_max]=e.heap[1],Yh(e,t),Ts(r,f,e.bl_count)}function Ds(e,t,r){var n,i=-1,a,o=t[0*2+1],s=0,f=7,c=4;for(o===0&&(f=138,c=3),t[(r+1)*2+1]=65535,n=0;n<=r;n++)a=o,o=t[(n+1)*2+1],!(++s<f&&a===o)&&(s<c?e.bl_tree[a*2]+=s:a!==0?(a!==i&&e.bl_tree[a*2]++,e.bl_tree[ms*2]++):s<=10?e.bl_tree[xs*2]++:e.bl_tree[Es*2]++,s=0,i=a,o===0?(f=138,c=3):a===o?(f=6,c=3):(f=7,c=4))}function Ms(e,t,r){var n,i=-1,a,o=t[0*2+1],s=0,f=7,c=4;for(o===0&&(f=138,c=3),n=0;n<=r;n++)if(a=o,o=t[(n+1)*2+1],!(++s<f&&a===o)){if(s<c)do ve(e,a,e.bl_tree);while(--s!==0);else a!==0?(a!==i&&(ve(e,a,e.bl_tree),s--),ve(e,ms,e.bl_tree),Q(e,s-3,2)):s<=10?(ve(e,xs,e.bl_tree),Q(e,s-3,3)):(ve(e,Es,e.bl_tree),Q(e,s-11,7));s=0,i=a,o===0?(f=138,c=3):a===o?(f=6,c=3):(f=7,c=4)}}function Qh(e){var t;for(Ds(e,e.dyn_ltree,e.l_desc.max_code),Ds(e,e.dyn_dtree,e.d_desc.max_code),ki(e,e.bl_desc),t=wi-1;t>=3&&e.bl_tree[Ss[t]*2+1]===0;t--);return e.opt_len+=3*(t+1)+5+5+4,t}function ed(e,t,r,n){var i;for(Q(e,t-257,5),Q(e,r-1,5),Q(e,n-4,4),i=0;i<n;i++)Q(e,e.bl_tree[Ss[i]*2+1],3);Ms(e,e.dyn_ltree,t-1),Ms(e,e.dyn_dtree,r-1)}function td(e){var t=4093624447,r;for(r=0;r<=31;r++,t>>>=1)if(t&1&&e.dyn_ltree[r*2]!==0)return vs;if(e.dyn_ltree[9*2]!==0||e.dyn_ltree[10*2]!==0||e.dyn_ltree[13*2]!==0)return ws;for(r=32;r<Ct;r++)if(e.dyn_ltree[r*2]!==0)return ws;return vs}var Ls=!1;function rd(e){Ls||(Jh(),Ls=!0),e.l_desc=new Si(e.dyn_ltree,As),e.d_desc=new Si(e.dyn_dtree,ks),e.bl_desc=new Si(e.bl_tree,Rs),e.bi_buf=0,e.bi_valid=0,Ps(e)}function Ns(e,t,r,n){Q(e,(zh<<1)+(n?1:0),3),Xh(e,t,r)}function nd(e){Q(e,_s<<1,3),ve(e,bi,Re),Gh(e)}function id(e,t,r,n){var i,a,o=0;e.level>0?(e.strm.data_type===Bh&&(e.strm.data_type=td(e)),ki(e,e.l_desc),ki(e,e.d_desc),o=Qh(e),i=e.opt_len+3+7>>>3,a=e.static_len+3+7>>>3,a<=i&&(i=a)):i=a=r+5,r+4<=i&&t!==-1?Ns(e,t,r,n):e.strategy===Uh||a===i?(Q(e,(_s<<1)+(n?1:0),3),Cs(e,Re,Mt)):(Q(e,(Zh<<1)+(n?1:0),3),ed(e,e.l_desc.max_code+1,e.d_desc.max_code+1,o+1),Cs(e,e.dyn_ltree,e.dyn_dtree)),Ps(e),n&&js(e)}function De(e,t,r){return e.pending_buf[e.d_buf+e.last_lit*2]=t>>>8&255,e.pending_buf[e.d_buf+e.last_lit*2+1]=t&255,e.pending_buf[e.l_buf+e.last_lit]=r&255,e.last_lit++,t===0?e.dyn_ltree[r*2]++:(e.matches++,t--,e.dyn_ltree[(Nt[r]+Ct+1)*2]++,e.dyn_dtree[Os(t)*2]++),e.last_lit===e.lit_bufsize-1}function Ri(e,t,r,n){for(var i=e&65535|0,a=e>>>16&65535|0,o=0;r!==0;){o=r>2e3?2e3:r,r-=o;do i=i+t[n++]|0,a=a+i|0;while(--o);i%=65521,a%=65521}return i|a<<16|0}function ad(){for(var e,t=[],r=0;r<256;r++){e=r;for(var n=0;n<8;n++)e=e&1?3988292384^e>>>1:e>>>1;t[r]=e}return t}var od=ad();function z(e,t,r,n){var i=od,a=n+r;e^=-1;for(var o=n;o<a;o++)e=e>>>8^i[(e^t[o])&255];return e^-1}var Xe=0,sd=1,cd=3,Me=4,$s=5,Le=0,Us=1,Ne=-2,fd=-3,Oi=-5,ld=-1,ud=1,Ar=2,hd=3,dd=4,pd=2,Ii=8,yd=9,gd=29,vd=256,Ti=vd+1+gd,wd=30,_d=19,bd=2*Ti+1,md=15,P=3,$e=258,se=$e+P+1,xd=32,Pi=42,ji=69,kr=73,Rr=91,Or=103,Qe=113,Ut=666,U=1,Bt=2,et=3,wt=4,Ed=3;function Ue(e,t){return e.msg=gs[t],t}function Bs(e){return(e<<1)-(e>4?9:0)}function tt(e){for(var t=e.length;--t>=0;)e[t]=0}function Be(e){var t=e.state,r=t.pending;r>e.avail_out&&(r=e.avail_out),r!==0&&(ke(e.output,t.pending_buf,t.pending_out,r,e.next_out),e.next_out+=r,t.pending_out+=r,e.total_out+=r,e.avail_out-=r,t.pending-=r,t.pending===0&&(t.pending_out=0))}function H(e,t){id(e,e.block_start>=0?e.block_start:-1,e.strstart-e.block_start,t),e.block_start=e.strstart,Be(e.strm)}function T(e,t){e.pending_buf[e.pending++]=t}function zt(e,t){e.pending_buf[e.pending++]=t>>>8&255,e.pending_buf[e.pending++]=t&255}function Sd(e,t,r,n){var i=e.avail_in;return i>n&&(i=n),i===0?0:(e.avail_in-=i,ke(t,e.input,e.next_in,i,r),e.state.wrap===1?e.adler=Ri(e.adler,t,i,r):e.state.wrap===2&&(e.adler=z(e.adler,t,i,r)),e.next_in+=i,e.total_in+=i,i)}function zs(e,t){var r=e.max_chain_length,n=e.strstart,i,a,o=e.prev_length,s=e.nice_match,f=e.strstart>e.w_size-se?e.strstart-(e.w_size-se):0,c=e.window,l=e.w_mask,d=e.prev,h=e.strstart+$e,u=c[n+o-1],p=c[n+o];e.prev_length>=e.good_match&&(r>>=2),s>e.lookahead&&(s=e.lookahead);do if(i=t,!(c[i+o]!==p||c[i+o-1]!==u||c[i]!==c[n]||c[++i]!==c[n+1])){n+=2,i++;do;while(c[++n]===c[++i]&&c[++n]===c[++i]&&c[++n]===c[++i]&&c[++n]===c[++i]&&c[++n]===c[++i]&&c[++n]===c[++i]&&c[++n]===c[++i]&&c[++n]===c[++i]&&n<h);if(a=$e-(h-n),n=h-$e,a>o){if(e.match_start=t,o=a,a>=s)break;u=c[n+o-1],p=c[n+o]}}while((t=d[t&l])>f&&--r!==0);return o<=e.lookahead?o:e.lookahead}function Zt(e){var t=e.w_size,r,n,i,a,o;do{if(a=e.window_size-e.lookahead-e.strstart,e.strstart>=t+(t-se)){ke(e.window,e.window,t,t,0),e.match_start-=t,e.strstart-=t,e.block_start-=t,n=e.hash_size,r=n;do i=e.head[--r],e.head[r]=i>=t?i-t:0;while(--n);n=t,r=n;do i=e.prev[--r],e.prev[r]=i>=t?i-t:0;while(--n);a+=t}if(e.strm.avail_in===0)break;if(n=Sd(e.strm,e.window,e.strstart+e.lookahead,a),e.lookahead+=n,e.lookahead+e.insert>=P)for(o=e.strstart-e.insert,e.ins_h=e.window[o],e.ins_h=(e.ins_h<<e.hash_shift^e.window[o+1])&e.hash_mask;e.insert&&(e.ins_h=(e.ins_h<<e.hash_shift^e.window[o+P-1])&e.hash_mask,e.prev[o&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=o,o++,e.insert--,!(e.lookahead+e.insert<P)););}while(e.lookahead<se&&e.strm.avail_in!==0)}function Ad(e,t){var r=65535;for(r>e.pending_buf_size-5&&(r=e.pending_buf_size-5);;){if(e.lookahead<=1){if(Zt(e),e.lookahead===0&&t===Xe)return U;if(e.lookahead===0)break}e.strstart+=e.lookahead,e.lookahead=0;var n=e.block_start+r;if((e.strstart===0||e.strstart>=n)&&(e.lookahead=e.strstart-n,e.strstart=n,H(e,!1),e.strm.avail_out===0)||e.strstart-e.block_start>=e.w_size-se&&(H(e,!1),e.strm.avail_out===0))return U}return e.insert=0,t===Me?(H(e,!0),e.strm.avail_out===0?et:wt):(e.strstart>e.block_start&&(H(e,!1),e.strm.avail_out===0),U)}function Fi(e,t){for(var r,n;;){if(e.lookahead<se){if(Zt(e),e.lookahead<se&&t===Xe)return U;if(e.lookahead===0)break}if(r=0,e.lookahead>=P&&(e.ins_h=(e.ins_h<<e.hash_shift^e.window[e.strstart+P-1])&e.hash_mask,r=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart),r!==0&&e.strstart-r<=e.w_size-se&&(e.match_length=zs(e,r)),e.match_length>=P)if(n=De(e,e.strstart-e.match_start,e.match_length-P),e.lookahead-=e.match_length,e.match_length<=e.max_lazy_match&&e.lookahead>=P){e.match_length--;do e.strstart++,e.ins_h=(e.ins_h<<e.hash_shift^e.window[e.strstart+P-1])&e.hash_mask,r=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart;while(--e.match_length!==0);e.strstart++}else e.strstart+=e.match_length,e.match_length=0,e.ins_h=e.window[e.strstart],e.ins_h=(e.ins_h<<e.hash_shift^e.window[e.strstart+1])&e.hash_mask;else n=De(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++;if(n&&(H(e,!1),e.strm.avail_out===0))return U}return e.insert=e.strstart<P-1?e.strstart:P-1,t===Me?(H(e,!0),e.strm.avail_out===0?et:wt):e.last_lit&&(H(e,!1),e.strm.avail_out===0)?U:Bt}function _t(e,t){for(var r,n,i;;){if(e.lookahead<se){if(Zt(e),e.lookahead<se&&t===Xe)return U;if(e.lookahead===0)break}if(r=0,e.lookahead>=P&&(e.ins_h=(e.ins_h<<e.hash_shift^e.window[e.strstart+P-1])&e.hash_mask,r=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart),e.prev_length=e.match_length,e.prev_match=e.match_start,e.match_length=P-1,r!==0&&e.prev_length<e.max_lazy_match&&e.strstart-r<=e.w_size-se&&(e.match_length=zs(e,r),e.match_length<=5&&(e.strategy===ud||e.match_length===P&&e.strstart-e.match_start>4096)&&(e.match_length=P-1)),e.prev_length>=P&&e.match_length<=e.prev_length){i=e.strstart+e.lookahead-P,n=De(e,e.strstart-1-e.prev_match,e.prev_length-P),e.lookahead-=e.prev_length-1,e.prev_length-=2;do++e.strstart<=i&&(e.ins_h=(e.ins_h<<e.hash_shift^e.window[e.strstart+P-1])&e.hash_mask,r=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart);while(--e.prev_length!==0);if(e.match_available=0,e.match_length=P-1,e.strstart++,n&&(H(e,!1),e.strm.avail_out===0))return U}else if(e.match_available){if(n=De(e,0,e.window[e.strstart-1]),n&&H(e,!1),e.strstart++,e.lookahead--,e.strm.avail_out===0)return U}else e.match_available=1,e.strstart++,e.lookahead--}return e.match_available&&(n=De(e,0,e.window[e.strstart-1]),e.match_available=0),e.insert=e.strstart<P-1?e.strstart:P-1,t===Me?(H(e,!0),e.strm.avail_out===0?et:wt):e.last_lit&&(H(e,!1),e.strm.avail_out===0)?U:Bt}function kd(e,t){for(var r,n,i,a,o=e.window;;){if(e.lookahead<=$e){if(Zt(e),e.lookahead<=$e&&t===Xe)return U;if(e.lookahead===0)break}if(e.match_length=0,e.lookahead>=P&&e.strstart>0&&(i=e.strstart-1,n=o[i],n===o[++i]&&n===o[++i]&&n===o[++i])){a=e.strstart+$e;do;while(n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&i<a);e.match_length=$e-(a-i),e.match_length>e.lookahead&&(e.match_length=e.lookahead)}if(e.match_length>=P?(r=De(e,1,e.match_length-P),e.lookahead-=e.match_length,e.strstart+=e.match_length,e.match_length=0):(r=De(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++),r&&(H(e,!1),e.strm.avail_out===0))return U}return e.insert=0,t===Me?(H(e,!0),e.strm.avail_out===0?et:wt):e.last_lit&&(H(e,!1),e.strm.avail_out===0)?U:Bt}function Rd(e,t){for(var r;;){if(e.lookahead===0&&(Zt(e),e.lookahead===0)){if(t===Xe)return U;break}if(e.match_length=0,r=De(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++,r&&(H(e,!1),e.strm.avail_out===0))return U}return e.insert=0,t===Me?(H(e,!0),e.strm.avail_out===0?et:wt):e.last_lit&&(H(e,!1),e.strm.avail_out===0)?U:Bt}function we(e,t,r,n,i){this.good_length=e,this.max_lazy=t,this.nice_length=r,this.max_chain=n,this.func=i}var bt;bt=[new we(0,0,0,0,Ad),new we(4,4,8,4,Fi),new we(4,5,16,8,Fi),new we(4,6,32,32,Fi),new we(4,4,16,16,_t),new we(8,16,32,32,_t),new we(8,16,128,128,_t),new we(8,32,128,256,_t),new we(32,128,258,1024,_t),new we(32,258,258,4096,_t)];function Od(e){e.window_size=2*e.w_size,tt(e.head),e.max_lazy_match=bt[e.level].max_lazy,e.good_match=bt[e.level].good_length,e.nice_match=bt[e.level].nice_length,e.max_chain_length=bt[e.level].max_chain,e.strstart=0,e.block_start=0,e.lookahead=0,e.insert=0,e.match_length=e.prev_length=P-1,e.match_available=0,e.ins_h=0}function Id(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=Ii,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new oe(bd*2),this.dyn_dtree=new oe((2*wd+1)*2),this.bl_tree=new oe((2*_d+1)*2),tt(this.dyn_ltree),tt(this.dyn_dtree),tt(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new oe(md+1),this.heap=new oe(2*Ti+1),tt(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new oe(2*Ti+1),tt(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}function Td(e){var t;return!e||!e.state?Ue(e,Ne):(e.total_in=e.total_out=0,e.data_type=pd,t=e.state,t.pending=0,t.pending_out=0,t.wrap<0&&(t.wrap=-t.wrap),t.status=t.wrap?Pi:Qe,e.adler=t.wrap===2?0:1,t.last_flush=Xe,rd(t),Le)}function Zs(e){var t=Td(e);return t===Le&&Od(e.state),t}function Pd(e,t,r,n,i,a){if(!e)return Ne;var o=1;if(t===ld&&(t=6),n<0?(o=0,n=-n):n>15&&(o=2,n-=16),i<1||i>yd||r!==Ii||n<8||n>15||t<0||t>9||a<0||a>dd)return Ue(e,Ne);n===8&&(n=9);var s=new Id;return e.state=s,s.strm=e,s.wrap=o,s.gzhead=null,s.w_bits=n,s.w_size=1<<s.w_bits,s.w_mask=s.w_size-1,s.hash_bits=i+7,s.hash_size=1<<s.hash_bits,s.hash_mask=s.hash_size-1,s.hash_shift=~~((s.hash_bits+P-1)/P),s.window=new mr(s.w_size*2),s.head=new oe(s.hash_size),s.prev=new oe(s.w_size),s.lit_bufsize=1<<i+6,s.pending_buf_size=s.lit_bufsize*4,s.pending_buf=new mr(s.pending_buf_size),s.d_buf=1*s.lit_bufsize,s.l_buf=3*s.lit_bufsize,s.level=t,s.strategy=a,s.method=r,Zs(e)}function jd(e,t){var r,n,i,a;if(!e||!e.state||t>$s||t<0)return e?Ue(e,Ne):Ne;if(n=e.state,!e.output||!e.input&&e.avail_in!==0||n.status===Ut&&t!==Me)return Ue(e,e.avail_out===0?Oi:Ne);if(n.strm=e,r=n.last_flush,n.last_flush=t,n.status===Pi)if(n.wrap===2)e.adler=0,T(n,31),T(n,139),T(n,8),n.gzhead?(T(n,(n.gzhead.text?1:0)+(n.gzhead.hcrc?2:0)+(n.gzhead.extra?4:0)+(n.gzhead.name?8:0)+(n.gzhead.comment?16:0)),T(n,n.gzhead.time&255),T(n,n.gzhead.time>>8&255),T(n,n.gzhead.time>>16&255),T(n,n.gzhead.time>>24&255),T(n,n.level===9?2:n.strategy>=Ar||n.level<2?4:0),T(n,n.gzhead.os&255),n.gzhead.extra&&n.gzhead.extra.length&&(T(n,n.gzhead.extra.length&255),T(n,n.gzhead.extra.length>>8&255)),n.gzhead.hcrc&&(e.adler=z(e.adler,n.pending_buf,n.pending,0)),n.gzindex=0,n.status=ji):(T(n,0),T(n,0),T(n,0),T(n,0),T(n,0),T(n,n.level===9?2:n.strategy>=Ar||n.level<2?4:0),T(n,Ed),n.status=Qe);else{var o=Ii+(n.w_bits-8<<4)<<8,s=-1;n.strategy>=Ar||n.level<2?s=0:n.level<6?s=1:n.level===6?s=2:s=3,o|=s<<6,n.strstart!==0&&(o|=xd),o+=31-o%31,n.status=Qe,zt(n,o),n.strstart!==0&&(zt(n,e.adler>>>16),zt(n,e.adler&65535)),e.adler=1}if(n.status===ji)if(n.gzhead.extra){for(i=n.pending;n.gzindex<(n.gzhead.extra.length&65535)&&!(n.pending===n.pending_buf_size&&(n.gzhead.hcrc&&n.pending>i&&(e.adler=z(e.adler,n.pending_buf,n.pending-i,i)),Be(e),i=n.pending,n.pending===n.pending_buf_size));)T(n,n.gzhead.extra[n.gzindex]&255),n.gzindex++;n.gzhead.hcrc&&n.pending>i&&(e.adler=z(e.adler,n.pending_buf,n.pending-i,i)),n.gzindex===n.gzhead.extra.length&&(n.gzindex=0,n.status=kr)}else n.status=kr;if(n.status===kr)if(n.gzhead.name){i=n.pending;do{if(n.pending===n.pending_buf_size&&(n.gzhead.hcrc&&n.pending>i&&(e.adler=z(e.adler,n.pending_buf,n.pending-i,i)),Be(e),i=n.pending,n.pending===n.pending_buf_size)){a=1;break}n.gzindex<n.gzhead.name.length?a=n.gzhead.name.charCodeAt(n.gzindex++)&255:a=0,T(n,a)}while(a!==0);n.gzhead.hcrc&&n.pending>i&&(e.adler=z(e.adler,n.pending_buf,n.pending-i,i)),a===0&&(n.gzindex=0,n.status=Rr)}else n.status=Rr;if(n.status===Rr)if(n.gzhead.comment){i=n.pending;do{if(n.pending===n.pending_buf_size&&(n.gzhead.hcrc&&n.pending>i&&(e.adler=z(e.adler,n.pending_buf,n.pending-i,i)),Be(e),i=n.pending,n.pending===n.pending_buf_size)){a=1;break}n.gzindex<n.gzhead.comment.length?a=n.gzhead.comment.charCodeAt(n.gzindex++)&255:a=0,T(n,a)}while(a!==0);n.gzhead.hcrc&&n.pending>i&&(e.adler=z(e.adler,n.pending_buf,n.pending-i,i)),a===0&&(n.status=Or)}else n.status=Or;if(n.status===Or&&(n.gzhead.hcrc?(n.pending+2>n.pending_buf_size&&Be(e),n.pending+2<=n.pending_buf_size&&(T(n,e.adler&255),T(n,e.adler>>8&255),e.adler=0,n.status=Qe)):n.status=Qe),n.pending!==0){if(Be(e),e.avail_out===0)return n.last_flush=-1,Le}else if(e.avail_in===0&&Bs(t)<=Bs(r)&&t!==Me)return Ue(e,Oi);if(n.status===Ut&&e.avail_in!==0)return Ue(e,Oi);if(e.avail_in!==0||n.lookahead!==0||t!==Xe&&n.status!==Ut){var f=n.strategy===Ar?Rd(n,t):n.strategy===hd?kd(n,t):bt[n.level].func(n,t);if((f===et||f===wt)&&(n.status=Ut),f===U||f===et)return e.avail_out===0&&(n.last_flush=-1),Le;if(f===Bt&&(t===sd?nd(n):t!==$s&&(Ns(n,0,0,!1),t===cd&&(tt(n.head),n.lookahead===0&&(n.strstart=0,n.block_start=0,n.insert=0))),Be(e),e.avail_out===0))return n.last_flush=-1,Le}return t!==Me?Le:n.wrap<=0?Us:(n.wrap===2?(T(n,e.adler&255),T(n,e.adler>>8&255),T(n,e.adler>>16&255),T(n,e.adler>>24&255),T(n,e.total_in&255),T(n,e.total_in>>8&255),T(n,e.total_in>>16&255),T(n,e.total_in>>24&255)):(zt(n,e.adler>>>16),zt(n,e.adler&65535)),Be(e),n.wrap>0&&(n.wrap=-n.wrap),n.pending!==0?Le:Us)}function Fd(e){var t;return!e||!e.state?Ne:(t=e.state.status,t!==Pi&&t!==ji&&t!==kr&&t!==Rr&&t!==Or&&t!==Qe&&t!==Ut?Ue(e,Ne):(e.state=null,t===Qe?Ue(e,fd):Le))}var Ir=30,Cd=12;function Dd(e,t){var r,n,i,a,o,s,f,c,l,d,h,u,p,y,w,_,m,x,v,A,O,b,S,I,k;r=e.state,n=e.next_in,I=e.input,i=n+(e.avail_in-5),a=e.next_out,k=e.output,o=a-(t-e.avail_out),s=a+(e.avail_out-257),f=r.dmax,c=r.wsize,l=r.whave,d=r.wnext,h=r.window,u=r.hold,p=r.bits,y=r.lencode,w=r.distcode,_=(1<<r.lenbits)-1,m=(1<<r.distbits)-1;e:do{p<15&&(u+=I[n++]<<p,p+=8,u+=I[n++]<<p,p+=8),x=y[u&_];t:for(;;){if(v=x>>>24,u>>>=v,p-=v,v=x>>>16&255,v===0)k[a++]=x&65535;else if(v&16){A=x&65535,v&=15,v&&(p<v&&(u+=I[n++]<<p,p+=8),A+=u&(1<<v)-1,u>>>=v,p-=v),p<15&&(u+=I[n++]<<p,p+=8,u+=I[n++]<<p,p+=8),x=w[u&m];r:for(;;){if(v=x>>>24,u>>>=v,p-=v,v=x>>>16&255,v&16){if(O=x&65535,v&=15,p<v&&(u+=I[n++]<<p,p+=8,p<v&&(u+=I[n++]<<p,p+=8)),O+=u&(1<<v)-1,O>f){e.msg="invalid distance too far back",r.mode=Ir;break e}if(u>>>=v,p-=v,v=a-o,O>v){if(v=O-v,v>l&&r.sane){e.msg="invalid distance too far back",r.mode=Ir;break e}if(b=0,S=h,d===0){if(b+=c-v,v<A){A-=v;do k[a++]=h[b++];while(--v);b=a-O,S=k}}else if(d<v){if(b+=c+d-v,v-=d,v<A){A-=v;do k[a++]=h[b++];while(--v);if(b=0,d<A){v=d,A-=v;do k[a++]=h[b++];while(--v);b=a-O,S=k}}}else if(b+=d-v,v<A){A-=v;do k[a++]=h[b++];while(--v);b=a-O,S=k}for(;A>2;)k[a++]=S[b++],k[a++]=S[b++],k[a++]=S[b++],A-=3;A&&(k[a++]=S[b++],A>1&&(k[a++]=S[b++]))}else{b=a-O;do k[a++]=k[b++],k[a++]=k[b++],k[a++]=k[b++],A-=3;while(A>2);A&&(k[a++]=k[b++],A>1&&(k[a++]=k[b++]))}}else if((v&64)===0){x=w[(x&65535)+(u&(1<<v)-1)];continue r}else{e.msg="invalid distance code",r.mode=Ir;break e}break}}else if((v&64)===0){x=y[(x&65535)+(u&(1<<v)-1)];continue t}else if(v&32){r.mode=Cd;break e}else{e.msg="invalid literal/length code",r.mode=Ir;break e}break}}while(n<i&&a<s);A=p>>3,n-=A,p-=A<<3,u&=(1<<p)-1,e.next_in=n,e.next_out=a,e.avail_in=n<i?5+(i-n):5-(n-i),e.avail_out=a<s?257+(s-a):257-(a-s),r.hold=u,r.bits=p}var mt=15,qs=852,Hs=592,Ks=0,Ci=1,Ws=2,Md=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0],Ld=[16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78],Nd=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0],$d=[16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64];function qt(e,t,r,n,i,a,o,s){var f=s.bits,c=0,l=0,d=0,h=0,u=0,p=0,y=0,w=0,_=0,m=0,x,v,A,O,b,S=null,I=0,k,F=new oe(mt+1),Z=new oe(mt+1),V=null,re=0,Ze,Y,fe;for(c=0;c<=mt;c++)F[c]=0;for(l=0;l<n;l++)F[t[r+l]]++;for(u=f,h=mt;h>=1&&F[h]===0;h--);if(u>h&&(u=h),h===0)return i[a++]=1<<24|64<<16|0,i[a++]=1<<24|64<<16|0,s.bits=1,0;for(d=1;d<h&&F[d]===0;d++);for(u<d&&(u=d),w=1,c=1;c<=mt;c++)if(w<<=1,w-=F[c],w<0)return-1;if(w>0&&(e===Ks||h!==1))return-1;for(Z[1]=0,c=1;c<mt;c++)Z[c+1]=Z[c]+F[c];for(l=0;l<n;l++)t[r+l]!==0&&(o[Z[t[r+l]]++]=l);if(e===Ks?(S=V=o,k=19):e===Ci?(S=Md,I-=257,V=Ld,re-=257,k=256):(S=Nd,V=$d,k=-1),m=0,l=0,c=d,b=a,p=u,y=0,A=-1,_=1<<u,O=_-1,e===Ci&&_>qs||e===Ws&&_>Hs)return 1;for(;;){Ze=c-y,o[l]<k?(Y=0,fe=o[l]):o[l]>k?(Y=V[re+o[l]],fe=S[I+o[l]]):(Y=96,fe=0),x=1<<c-y,v=1<<p,d=v;do v-=x,i[b+(m>>y)+v]=Ze<<24|Y<<16|fe|0;while(v!==0);for(x=1<<c-1;m&x;)x>>=1;if(x!==0?(m&=x-1,m+=x):m=0,l++,--F[c]===0){if(c===h)break;c=t[r+o[l]]}if(c>u&&(m&O)!==A){for(y===0&&(y=u),b+=d,p=c-y,w=1<<p;p+y<h&&(w-=F[p+y],!(w<=0));)p++,w<<=1;if(_+=1<<p,e===Ci&&_>qs||e===Ws&&_>Hs)return 1;A=m&O,i[A]=u<<24|p<<16|b-a|0}}return m!==0&&(i[b+m]=c-y<<24|64<<16|0),s.bits=u,0}var Ud=0,Vs=1,Gs=2,Ys=4,Bd=5,Tr=6,Ht=0,zd=1,Zd=2,ze=-2,qd=-3,Hd=-4,Kd=-5,Js=8,Xs=1,Qs=2,ec=3,tc=4,rc=5,nc=6,ic=7,ac=8,oc=9,sc=10,cc=11,Oe=12,Di=13,fc=14,Mi=15,lc=16,uc=17,hc=18,dc=19,Pr=20,jr=21,pc=22,yc=23,gc=24,vc=25,wc=26,Li=27,_c=28,bc=29,C=30,Wd=31,Vd=32,Gd=852,Yd=592;function mc(e){return(e>>>24&255)+(e>>>8&65280)+((e&65280)<<8)+((e&255)<<24)}function Jd(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new oe(320),this.work=new oe(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function Xd(e){var t;return!e||!e.state?ze:(t=e.state,e.total_in=e.total_out=t.total=0,e.msg="",t.wrap&&(e.adler=t.wrap&1),t.mode=Xs,t.last=0,t.havedict=0,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=t.lendyn=new xr(Gd),t.distcode=t.distdyn=new xr(Yd),t.sane=1,t.back=-1,Ht)}function xc(e){var t;return!e||!e.state?ze:(t=e.state,t.wsize=0,t.whave=0,t.wnext=0,Xd(e))}function Qd(e,t){var r,n;return!e||!e.state||(n=e.state,t<0?(r=0,t=-t):(r=(t>>4)+1,t<48&&(t&=15)),t&&(t<8||t>15))?ze:(n.window!==null&&n.wbits!==t&&(n.window=null),n.wrap=r,n.wbits=t,xc(e))}function ep(e,t){var r,n;return e?(n=new Jd,e.state=n,n.window=null,r=Qd(e,t),r!==Ht&&(e.state=null),r):ze}var Ec=!0,Ni,$i;function tp(e){if(Ec){var t;for(Ni=new xr(512),$i=new xr(32),t=0;t<144;)e.lens[t++]=8;for(;t<256;)e.lens[t++]=9;for(;t<280;)e.lens[t++]=7;for(;t<288;)e.lens[t++]=8;for(qt(Vs,e.lens,0,288,Ni,0,e.work,{bits:9}),t=0;t<32;)e.lens[t++]=5;qt(Gs,e.lens,0,32,$i,0,e.work,{bits:5}),Ec=!1}e.lencode=Ni,e.lenbits=9,e.distcode=$i,e.distbits=5}function rp(e,t,r,n){var i,a=e.state;return a.window===null&&(a.wsize=1<<a.wbits,a.wnext=0,a.whave=0,a.window=new mr(a.wsize)),n>=a.wsize?(ke(a.window,t,r-a.wsize,a.wsize,0),a.wnext=0,a.whave=a.wsize):(i=a.wsize-a.wnext,i>n&&(i=n),ke(a.window,t,r-n,i,a.wnext),n-=i,n?(ke(a.window,t,r-n,n,0),a.wnext=n,a.whave=a.wsize):(a.wnext+=i,a.wnext===a.wsize&&(a.wnext=0),a.whave<a.wsize&&(a.whave+=i))),0}function np(e,t){var r,n,i,a,o,s,f,c,l,d,h,u,p,y,w=0,_,m,x,v,A,O,b,S,I=new mr(4),k,F,Z=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];if(!e||!e.state||!e.output||!e.input&&e.avail_in!==0)return ze;r=e.state,r.mode===Oe&&(r.mode=Di),o=e.next_out,i=e.output,f=e.avail_out,a=e.next_in,n=e.input,s=e.avail_in,c=r.hold,l=r.bits,d=s,h=f,S=Ht;e:for(;;)switch(r.mode){case Xs:if(r.wrap===0){r.mode=Di;break}for(;l<16;){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}if(r.wrap&2&&c===35615){r.check=0,I[0]=c&255,I[1]=c>>>8&255,r.check=z(r.check,I,2,0),c=0,l=0,r.mode=Qs;break}if(r.flags=0,r.head&&(r.head.done=!1),!(r.wrap&1)||(((c&255)<<8)+(c>>8))%31){e.msg="incorrect header check",r.mode=C;break}if((c&15)!==Js){e.msg="unknown compression method",r.mode=C;break}if(c>>>=4,l-=4,b=(c&15)+8,r.wbits===0)r.wbits=b;else if(b>r.wbits){e.msg="invalid window size",r.mode=C;break}r.dmax=1<<b,e.adler=r.check=1,r.mode=c&512?sc:Oe,c=0,l=0;break;case Qs:for(;l<16;){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}if(r.flags=c,(r.flags&255)!==Js){e.msg="unknown compression method",r.mode=C;break}if(r.flags&57344){e.msg="unknown header flags set",r.mode=C;break}r.head&&(r.head.text=c>>8&1),r.flags&512&&(I[0]=c&255,I[1]=c>>>8&255,r.check=z(r.check,I,2,0)),c=0,l=0,r.mode=ec;case ec:for(;l<32;){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}r.head&&(r.head.time=c),r.flags&512&&(I[0]=c&255,I[1]=c>>>8&255,I[2]=c>>>16&255,I[3]=c>>>24&255,r.check=z(r.check,I,4,0)),c=0,l=0,r.mode=tc;case tc:for(;l<16;){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}r.head&&(r.head.xflags=c&255,r.head.os=c>>8),r.flags&512&&(I[0]=c&255,I[1]=c>>>8&255,r.check=z(r.check,I,2,0)),c=0,l=0,r.mode=rc;case rc:if(r.flags&1024){for(;l<16;){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}r.length=c,r.head&&(r.head.extra_len=c),r.flags&512&&(I[0]=c&255,I[1]=c>>>8&255,r.check=z(r.check,I,2,0)),c=0,l=0}else r.head&&(r.head.extra=null);r.mode=nc;case nc:if(r.flags&1024&&(u=r.length,u>s&&(u=s),u&&(r.head&&(b=r.head.extra_len-r.length,r.head.extra||(r.head.extra=new Array(r.head.extra_len)),ke(r.head.extra,n,a,u,b)),r.flags&512&&(r.check=z(r.check,n,u,a)),s-=u,a+=u,r.length-=u),r.length))break e;r.length=0,r.mode=ic;case ic:if(r.flags&2048){if(s===0)break e;u=0;do b=n[a+u++],r.head&&b&&r.length<65536&&(r.head.name+=String.fromCharCode(b));while(b&&u<s);if(r.flags&512&&(r.check=z(r.check,n,u,a)),s-=u,a+=u,b)break e}else r.head&&(r.head.name=null);r.length=0,r.mode=ac;case ac:if(r.flags&4096){if(s===0)break e;u=0;do b=n[a+u++],r.head&&b&&r.length<65536&&(r.head.comment+=String.fromCharCode(b));while(b&&u<s);if(r.flags&512&&(r.check=z(r.check,n,u,a)),s-=u,a+=u,b)break e}else r.head&&(r.head.comment=null);r.mode=oc;case oc:if(r.flags&512){for(;l<16;){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}if(c!==(r.check&65535)){e.msg="header crc mismatch",r.mode=C;break}c=0,l=0}r.head&&(r.head.hcrc=r.flags>>9&1,r.head.done=!0),e.adler=r.check=0,r.mode=Oe;break;case sc:for(;l<32;){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}e.adler=r.check=mc(c),c=0,l=0,r.mode=cc;case cc:if(r.havedict===0)return e.next_out=o,e.avail_out=f,e.next_in=a,e.avail_in=s,r.hold=c,r.bits=l,Zd;e.adler=r.check=1,r.mode=Oe;case Oe:if(t===Bd||t===Tr)break e;case Di:if(r.last){c>>>=l&7,l-=l&7,r.mode=Li;break}for(;l<3;){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}switch(r.last=c&1,c>>>=1,l-=1,c&3){case 0:r.mode=fc;break;case 1:if(tp(r),r.mode=Pr,t===Tr){c>>>=2,l-=2;break e}break;case 2:r.mode=uc;break;case 3:e.msg="invalid block type",r.mode=C}c>>>=2,l-=2;break;case fc:for(c>>>=l&7,l-=l&7;l<32;){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}if((c&65535)!==(c>>>16^65535)){e.msg="invalid stored block lengths",r.mode=C;break}if(r.length=c&65535,c=0,l=0,r.mode=Mi,t===Tr)break e;case Mi:r.mode=lc;case lc:if(u=r.length,u){if(u>s&&(u=s),u>f&&(u=f),u===0)break e;ke(i,n,a,u,o),s-=u,a+=u,f-=u,o+=u,r.length-=u;break}r.mode=Oe;break;case uc:for(;l<14;){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}if(r.nlen=(c&31)+257,c>>>=5,l-=5,r.ndist=(c&31)+1,c>>>=5,l-=5,r.ncode=(c&15)+4,c>>>=4,l-=4,r.nlen>286||r.ndist>30){e.msg="too many length or distance symbols",r.mode=C;break}r.have=0,r.mode=hc;case hc:for(;r.have<r.ncode;){for(;l<3;){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}r.lens[Z[r.have++]]=c&7,c>>>=3,l-=3}for(;r.have<19;)r.lens[Z[r.have++]]=0;if(r.lencode=r.lendyn,r.lenbits=7,k={bits:r.lenbits},S=qt(Ud,r.lens,0,19,r.lencode,0,r.work,k),r.lenbits=k.bits,S){e.msg="invalid code lengths set",r.mode=C;break}r.have=0,r.mode=dc;case dc:for(;r.have<r.nlen+r.ndist;){for(;w=r.lencode[c&(1<<r.lenbits)-1],_=w>>>24,m=w>>>16&255,x=w&65535,!(_<=l);){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}if(x<16)c>>>=_,l-=_,r.lens[r.have++]=x;else{if(x===16){for(F=_+2;l<F;){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}if(c>>>=_,l-=_,r.have===0){e.msg="invalid bit length repeat",r.mode=C;break}b=r.lens[r.have-1],u=3+(c&3),c>>>=2,l-=2}else if(x===17){for(F=_+3;l<F;){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}c>>>=_,l-=_,b=0,u=3+(c&7),c>>>=3,l-=3}else{for(F=_+7;l<F;){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}c>>>=_,l-=_,b=0,u=11+(c&127),c>>>=7,l-=7}if(r.have+u>r.nlen+r.ndist){e.msg="invalid bit length repeat",r.mode=C;break}for(;u--;)r.lens[r.have++]=b}}if(r.mode===C)break;if(r.lens[256]===0){e.msg="invalid code -- missing end-of-block",r.mode=C;break}if(r.lenbits=9,k={bits:r.lenbits},S=qt(Vs,r.lens,0,r.nlen,r.lencode,0,r.work,k),r.lenbits=k.bits,S){e.msg="invalid literal/lengths set",r.mode=C;break}if(r.distbits=6,r.distcode=r.distdyn,k={bits:r.distbits},S=qt(Gs,r.lens,r.nlen,r.ndist,r.distcode,0,r.work,k),r.distbits=k.bits,S){e.msg="invalid distances set",r.mode=C;break}if(r.mode=Pr,t===Tr)break e;case Pr:r.mode=jr;case jr:if(s>=6&&f>=258){e.next_out=o,e.avail_out=f,e.next_in=a,e.avail_in=s,r.hold=c,r.bits=l,Dd(e,h),o=e.next_out,i=e.output,f=e.avail_out,a=e.next_in,n=e.input,s=e.avail_in,c=r.hold,l=r.bits,r.mode===Oe&&(r.back=-1);break}for(r.back=0;w=r.lencode[c&(1<<r.lenbits)-1],_=w>>>24,m=w>>>16&255,x=w&65535,!(_<=l);){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}if(m&&(m&240)===0){for(v=_,A=m,O=x;w=r.lencode[O+((c&(1<<v+A)-1)>>v)],_=w>>>24,m=w>>>16&255,x=w&65535,!(v+_<=l);){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}c>>>=v,l-=v,r.back+=v}if(c>>>=_,l-=_,r.back+=_,r.length=x,m===0){r.mode=wc;break}if(m&32){r.back=-1,r.mode=Oe;break}if(m&64){e.msg="invalid literal/length code",r.mode=C;break}r.extra=m&15,r.mode=pc;case pc:if(r.extra){for(F=r.extra;l<F;){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}r.length+=c&(1<<r.extra)-1,c>>>=r.extra,l-=r.extra,r.back+=r.extra}r.was=r.length,r.mode=yc;case yc:for(;w=r.distcode[c&(1<<r.distbits)-1],_=w>>>24,m=w>>>16&255,x=w&65535,!(_<=l);){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}if((m&240)===0){for(v=_,A=m,O=x;w=r.distcode[O+((c&(1<<v+A)-1)>>v)],_=w>>>24,m=w>>>16&255,x=w&65535,!(v+_<=l);){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}c>>>=v,l-=v,r.back+=v}if(c>>>=_,l-=_,r.back+=_,m&64){e.msg="invalid distance code",r.mode=C;break}r.offset=x,r.extra=m&15,r.mode=gc;case gc:if(r.extra){for(F=r.extra;l<F;){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}r.offset+=c&(1<<r.extra)-1,c>>>=r.extra,l-=r.extra,r.back+=r.extra}if(r.offset>r.dmax){e.msg="invalid distance too far back",r.mode=C;break}r.mode=vc;case vc:if(f===0)break e;if(u=h-f,r.offset>u){if(u=r.offset-u,u>r.whave&&r.sane){e.msg="invalid distance too far back",r.mode=C;break}u>r.wnext?(u-=r.wnext,p=r.wsize-u):p=r.wnext-u,u>r.length&&(u=r.length),y=r.window}else y=i,p=o-r.offset,u=r.length;u>f&&(u=f),f-=u,r.length-=u;do i[o++]=y[p++];while(--u);r.length===0&&(r.mode=jr);break;case wc:if(f===0)break e;i[o++]=r.length,f--,r.mode=jr;break;case Li:if(r.wrap){for(;l<32;){if(s===0)break e;s--,c|=n[a++]<<l,l+=8}if(h-=f,e.total_out+=h,r.total+=h,h&&(e.adler=r.check=r.flags?z(r.check,i,h,o-h):Ri(r.check,i,h,o-h)),h=f,(r.flags?c:mc(c))!==r.check){e.msg="incorrect data check",r.mode=C;break}c=0,l=0}r.mode=_c;case _c:if(r.wrap&&r.flags){for(;l<32;){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}if(c!==(r.total&4294967295)){e.msg="incorrect length check",r.mode=C;break}c=0,l=0}r.mode=bc;case bc:S=zd;break e;case C:S=qd;break e;case Wd:return Hd;case Vd:default:return ze}return e.next_out=o,e.avail_out=f,e.next_in=a,e.avail_in=s,r.hold=c,r.bits=l,(r.wsize||h!==e.avail_out&&r.mode<C&&(r.mode<Li||t!==Ys))&&rp(e,e.output,e.next_out,h-e.avail_out),d-=e.avail_in,h-=e.avail_out,e.total_in+=d,e.total_out+=h,r.total+=h,r.wrap&&h&&(e.adler=r.check=r.flags?z(r.check,i,h,e.next_out-h):Ri(r.check,i,h,e.next_out-h)),e.data_type=r.bits+(r.last?64:0)+(r.mode===Oe?128:0)+(r.mode===Pr||r.mode===Mi?256:0),(d===0&&h===0||t===Ys)&&S===Ht&&(S=Kd),S}function ip(e){if(!e||!e.state)return ze;var t=e.state;return t.window&&(t.window=null),e.state=null,Ht}var Ui=0,xt=1,Fr=2,Kt=3,Cr=4,Et=5,Wt=6,Vt=7,Sc=0,Ac=1,kc=2,Rc=3,Bi=4,Oc=5,ap=6,Dr=0,Ic=1,Tc=2,op=-1,sp=-2,cp=-3,Pc=-5,fp=0,lp=1,up=9,hp=-1,dp=1,pp=2,yp=3,gp=4,vp=0,wp=0,_p=1,bp=2,jc=8;function ce(e){if(e<xt||e>Vt)throw new TypeError("Bad argument");this.mode=e,this.init_done=!1,this.write_in_progress=!1,this.pending_close=!1,this.windowBits=0,this.level=0,this.memLevel=0,this.strategy=0,this.dictionary=null}ce.prototype.init=function(e,t,r,n,i){this.windowBits=e,this.level=t,this.memLevel=r,this.strategy=n,(this.mode===Kt||this.mode===Cr)&&(this.windowBits+=16),this.mode===Vt&&(this.windowBits+=32),(this.mode===Et||this.mode===Wt)&&(this.windowBits=-this.windowBits),this.strm=new $h;var a;switch(this.mode){case xt:case Kt:case Et:a=Pd(this.strm,this.level,jc,this.windowBits,this.memLevel,this.strategy);break;case Fr:case Cr:case Wt:case Vt:a=ep(this.strm,this.windowBits);break;default:throw new Error("Unknown mode "+this.mode)}if(a!==Dr){this._error(a);return}this.write_in_progress=!1,this.init_done=!0},ce.prototype.params=function(){throw new Error("deflateParams Not supported")},ce.prototype._writeCheck=function(){if(!this.init_done)throw new Error("write before init");if(this.mode===Ui)throw new Error("already finalized");if(this.write_in_progress)throw new Error("write already in progress");if(this.pending_close)throw new Error("close is pending")},ce.prototype.write=function(e,t,r,n,i,a,o){this._writeCheck(),this.write_in_progress=!0;var s=this;return Se.nextTick(function(){s.write_in_progress=!1;var f=s._write(e,t,r,n,i,a,o);s.callback(f[0],f[1]),s.pending_close&&s.close()}),this};function mp(e,t){for(var r=0;r<e.length;r++)this[t+r]=e[r]}ce.prototype.writeSync=function(e,t,r,n,i,a,o){return this._writeCheck(),this._write(e,t,r,n,i,a,o)},ce.prototype._write=function(e,t,r,n,i,a,o){if(this.write_in_progress=!0,e!==Sc&&e!==Ac&&e!==kc&&e!==Rc&&e!==Bi&&e!==Oc)throw new Error("Invalid flush value");t==null&&(t=new g(0),n=0,r=0),i._set?i.set=i._set:i.set=mp;var s=this.strm;s.avail_in=n,s.input=t,s.next_in=r,s.avail_out=o,s.output=i,s.next_out=a;var f;switch(this.mode){case xt:case Kt:case Et:f=jd(s,e);break;case Vt:case Fr:case Cr:case Wt:f=np(s,e);break;default:throw new Error("Unknown mode "+this.mode)}return this._checkError(f,s,e)||this._error(f),this.write_in_progress=!1,[s.avail_in,s.avail_out]},ce.prototype._checkError=function(e,t,r){switch(e){case Dr:case Pc:if(t.avail_out!==0&&r===Bi)return!1;break;case Ic:break;case Tc:return!1;default:return!1}return!0},ce.prototype.close=function(){if(this.write_in_progress){this.pending_close=!0;return}this.pending_close=!1,this.mode===xt||this.mode===Kt||this.mode===Et?Fd(this.strm):ip(this.strm),this.mode=Ui};var Mr;ce.prototype.reset=function(){switch(this.mode){case xt:case Et:Mr=Zs(this.strm);break;case Fr:case Wt:Mr=xc(this.strm);break}Mr!==Dr&&this._error(Mr)},ce.prototype._error=function(e){this.onerror(gs[e]+": "+this.strm.msg,e),this.write_in_progress=!1,this.pending_close&&this.close()};var Fc=Object.freeze({__proto__:null,DEFLATE:xt,DEFLATERAW:Et,GUNZIP:Cr,GZIP:Kt,INFLATE:Fr,INFLATERAW:Wt,NONE:Ui,UNZIP:Vt,Z_BEST_COMPRESSION:up,Z_BEST_SPEED:lp,Z_BINARY:wp,Z_BLOCK:Oc,Z_BUF_ERROR:Pc,Z_DATA_ERROR:cp,Z_DEFAULT_COMPRESSION:hp,Z_DEFAULT_STRATEGY:vp,Z_DEFLATED:jc,Z_ERRNO:op,Z_FILTERED:dp,Z_FINISH:Bi,Z_FIXED:gp,Z_FULL_FLUSH:Rc,Z_HUFFMAN_ONLY:pp,Z_NEED_DICT:Tc,Z_NO_COMPRESSION:fp,Z_NO_FLUSH:Sc,Z_OK:Dr,Z_PARTIAL_FLUSH:Ac,Z_RLE:yp,Z_STREAM_END:Ic,Z_STREAM_ERROR:sp,Z_SYNC_FLUSH:kc,Z_TEXT:_p,Z_TREES:ap,Z_UNKNOWN:bp,Zlib:ce});function xp(e,t){if(!e)throw new Error(t)}var E={};Object.keys(Fc).forEach(function(e){E[e]=Fc[e]}),E.Z_MIN_WINDOWBITS=8,E.Z_MAX_WINDOWBITS=15,E.Z_DEFAULT_WINDOWBITS=15,E.Z_MIN_CHUNK=64,E.Z_MAX_CHUNK=1/0,E.Z_DEFAULT_CHUNK=16*1024,E.Z_MIN_MEMLEVEL=1,E.Z_MAX_MEMLEVEL=9,E.Z_DEFAULT_MEMLEVEL=8,E.Z_MIN_LEVEL=-1,E.Z_MAX_LEVEL=9,E.Z_DEFAULT_LEVEL=E.Z_DEFAULT_COMPRESSION;var Gt={Z_OK:E.Z_OK,Z_STREAM_END:E.Z_STREAM_END,Z_NEED_DICT:E.Z_NEED_DICT,Z_ERRNO:E.Z_ERRNO,Z_STREAM_ERROR:E.Z_STREAM_ERROR,Z_DATA_ERROR:E.Z_DATA_ERROR,Z_MEM_ERROR:E.Z_MEM_ERROR,Z_BUF_ERROR:E.Z_BUF_ERROR,Z_VERSION_ERROR:E.Z_VERSION_ERROR};Object.keys(Gt).forEach(function(e){Gt[Gt[e]]=e});function Ep(e){return new it(e)}function Sp(e){return new at(e)}function Ap(e){return new ct(e)}function kp(e){return new ft(e)}function Rp(e){return new ot(e)}function Op(e){return new st(e)}function Ip(e){return new lt(e)}function Tp(e,t,r){return typeof t=="function"&&(r=t,t={}),rt(new it(t),e,r)}function Pp(e,t){return nt(new it(t),e)}function jp(e,t,r){return typeof t=="function"&&(r=t,t={}),rt(new ot(t),e,r)}function Fp(e,t){return nt(new ot(t),e)}function Cp(e,t,r){return typeof t=="function"&&(r=t,t={}),rt(new ct(t),e,r)}function Dp(e,t){return nt(new ct(t),e)}function Mp(e,t,r){return typeof t=="function"&&(r=t,t={}),rt(new lt(t),e,r)}function Lp(e,t){return nt(new lt(t),e)}function Np(e,t,r){return typeof t=="function"&&(r=t,t={}),rt(new at(t),e,r)}function $p(e,t){return nt(new at(t),e)}function Up(e,t,r){return typeof t=="function"&&(r=t,t={}),rt(new st(t),e,r)}function Bp(e,t){return nt(new st(t),e)}function zp(e,t,r){return typeof t=="function"&&(r=t,t={}),rt(new ft(t),e,r)}function Zp(e,t){return nt(new ft(t),e)}function rt(e,t,r){var n=[],i=0;e.on("error",o),e.on("end",s),e.end(t),a();function a(){for(var f;(f=e.read())!==null;)n.push(f),i+=f.length;e.once("readable",a)}function o(f){e.removeListener("end",s),e.removeListener("readable",a),r(f)}function s(){var f=g.concat(n,i);n=[],r(null,f),e.close()}}function nt(e,t){if(typeof t=="string"&&(t=new g(t)),!g.isBuffer(t))throw new TypeError("Not a string or buffer");var r=E.Z_FINISH;return e._processChunk(t,r)}function it(e){if(!(this instanceof it))return new it(e);D.call(this,e,E.DEFLATE)}function at(e){if(!(this instanceof at))return new at(e);D.call(this,e,E.INFLATE)}function ot(e){if(!(this instanceof ot))return new ot(e);D.call(this,e,E.GZIP)}function st(e){if(!(this instanceof st))return new st(e);D.call(this,e,E.GUNZIP)}function ct(e){if(!(this instanceof ct))return new ct(e);D.call(this,e,E.DEFLATERAW)}function ft(e){if(!(this instanceof ft))return new ft(e);D.call(this,e,E.INFLATERAW)}function lt(e){if(!(this instanceof lt))return new lt(e);D.call(this,e,E.UNZIP)}function D(e,t){if(this._opts=e=e||{},this._chunkSize=e.chunkSize||E.Z_DEFAULT_CHUNK,te.call(this,e),e.flush&&e.flush!==E.Z_NO_FLUSH&&e.flush!==E.Z_PARTIAL_FLUSH&&e.flush!==E.Z_SYNC_FLUSH&&e.flush!==E.Z_FULL_FLUSH&&e.flush!==E.Z_FINISH&&e.flush!==E.Z_BLOCK)throw new Error("Invalid flush flag: "+e.flush);if(this._flushFlag=e.flush||E.Z_NO_FLUSH,e.chunkSize&&(e.chunkSize<E.Z_MIN_CHUNK||e.chunkSize>E.Z_MAX_CHUNK))throw new Error("Invalid chunk size: "+e.chunkSize);if(e.windowBits&&(e.windowBits<E.Z_MIN_WINDOWBITS||e.windowBits>E.Z_MAX_WINDOWBITS))throw new Error("Invalid windowBits: "+e.windowBits);if(e.level&&(e.level<E.Z_MIN_LEVEL||e.level>E.Z_MAX_LEVEL))throw new Error("Invalid compression level: "+e.level);if(e.memLevel&&(e.memLevel<E.Z_MIN_MEMLEVEL||e.memLevel>E.Z_MAX_MEMLEVEL))throw new Error("Invalid memLevel: "+e.memLevel);if(e.strategy&&e.strategy!=E.Z_FILTERED&&e.strategy!=E.Z_HUFFMAN_ONLY&&e.strategy!=E.Z_RLE&&e.strategy!=E.Z_FIXED&&e.strategy!=E.Z_DEFAULT_STRATEGY)throw new Error("Invalid strategy: "+e.strategy);if(e.dictionary&&!g.isBuffer(e.dictionary))throw new Error("Invalid dictionary: it should be a Buffer instance");this._binding=new E.Zlib(t);var r=this;this._hadError=!1,this._binding.onerror=function(a,o){r._binding=null,r._hadError=!0;var s=new Error(a);s.errno=o,s.code=Gt[o],r.emit("error",s)};var n=E.Z_DEFAULT_COMPRESSION;typeof e.level=="number"&&(n=e.level);var i=E.Z_DEFAULT_STRATEGY;typeof e.strategy=="number"&&(i=e.strategy),this._binding.init(e.windowBits||E.Z_DEFAULT_WINDOWBITS,n,e.memLevel||E.Z_DEFAULT_MEMLEVEL,i,e.dictionary),this._buffer=new g(this._chunkSize),this._offset=0,this._closed=!1,this._level=n,this._strategy=i,this.once("end",this.close)}W(D,te),D.prototype.params=function(e,t,r){if(e<E.Z_MIN_LEVEL||e>E.Z_MAX_LEVEL)throw new RangeError("Invalid compression level: "+e);if(t!=E.Z_FILTERED&&t!=E.Z_HUFFMAN_ONLY&&t!=E.Z_RLE&&t!=E.Z_FIXED&&t!=E.Z_DEFAULT_STRATEGY)throw new TypeError("Invalid strategy: "+t);if(this._level!==e||this._strategy!==t){var n=this;this.flush(E.Z_SYNC_FLUSH,function(){n._binding.params(e,t),n._hadError||(n._level=e,n._strategy=t,r&&r())})}else Se.nextTick(r)},D.prototype.reset=function(){return this._binding.reset()},D.prototype._flush=function(e){this._transform(new g(0),"",e)},D.prototype.flush=function(e,t){var r=this._writableState;if((typeof e=="function"||e===void 0&&!t)&&(t=e,e=E.Z_FULL_FLUSH),r.ended)t&&Se.nextTick(t);else if(r.ending)t&&this.once("end",t);else if(r.needDrain){var n=this;this.once("drain",function(){n.flush(t)})}else this._flushFlag=e,this.write(new g(0),"",t)},D.prototype.close=function(e){if(e&&Se.nextTick(e),!this._closed){this._closed=!0,this._binding.close();var t=this;Se.nextTick(function(){t.emit("close")})}},D.prototype._transform=function(e,t,r){var n,i=this._writableState,a=i.ending||i.ended,o=a&&(!e||i.length===e.length);if(!e===null&&!g.isBuffer(e))return r(new Error("invalid input"));o?n=E.Z_FINISH:(n=this._flushFlag,e.length>=i.length&&(this._flushFlag=this._opts.flush||E.Z_NO_FLUSH)),this._processChunk(e,n,r)},D.prototype._processChunk=function(e,t,r){var n=e&&e.length,i=this._chunkSize-this._offset,a=0,o=this,s=typeof r=="function";if(!s){var f=[],c=0,l;this.on("error",function(y){l=y});do var d=this._binding.writeSync(t,e,a,n,this._buffer,this._offset,i);while(!this._hadError&&p(d[0],d[1]));if(this._hadError)throw l;var h=g.concat(f,c);return this.close(),h}var u=this._binding.write(t,e,a,n,this._buffer,this._offset,i);u.buffer=e,u.callback=p;function p(y,w){if(!o._hadError){var _=i-w;if(xp(_>=0,"have should not go down"),_>0){var m=o._buffer.slice(o._offset,o._offset+_);o._offset+=_,s?o.push(m):(f.push(m),c+=m.length)}if((w===0||o._offset>=o._chunkSize)&&(i=o._chunkSize,o._offset=0,o._buffer=new g(o._chunkSize)),w===0){if(a+=n-y,n=y,!s)return!0;var x=o._binding.write(t,e,a,n,o._buffer,o._offset,o._chunkSize);x.callback=p,x.buffer=e;return}if(!s)return!1;r()}}},W(it,D),W(at,D),W(ot,D),W(st,D),W(ct,D),W(ft,D),W(lt,D);var Cc={codes:Gt,createDeflate:Ep,createInflate:Sp,createDeflateRaw:Ap,createInflateRaw:kp,createGzip:Rp,createGunzip:Op,createUnzip:Ip,deflate:Tp,deflateSync:Pp,gzip:jp,gzipSync:Fp,deflateRaw:Cp,deflateRawSync:Dp,unzip:Mp,unzipSync:Lp,inflate:Np,inflateSync:$p,gunzip:Up,gunzipSync:Bp,inflateRaw:zp,inflateRawSync:Zp,Deflate:it,Inflate:at,Gzip:ot,Gunzip:st,DeflateRaw:ct,InflateRaw:ft,Unzip:lt,Zlib:D};class Dc extends gi{constructor({client:t,keyPrefix:r="cache",ttl:n=0,prefix:i=void 0}){super({client:t,keyPrefix:r,ttl:n,prefix:i}),this.client=t,this.keyPrefix=r,this.config.ttl=n,this.config.client=t,this.config.prefix=i!==void 0?i:r+(r.endsWith("/")?"":"/")}async _set(t,r){let n=JSON.stringify(r);const i=n.length;return n=Cc.gzipSync(n).toString("base64"),this.client.putObject({key:me(this.keyPrefix,t),body:n,contentEncoding:"gzip",contentType:"application/gzip",metadata:{compressor:"zlib",compressed:"true","client-id":this.client.id,"length-serialized":String(i),"length-compressed":String(n.length),"compression-gain":(n.length/i).toFixed(2)}})}async _get(t){try{const{Body:r}=await this.client.getObject(me(this.keyPrefix,t));let n=await yt(r);return n=Buffer.from(n,"base64"),n=Cc.unzipSync(n).toString(),JSON.parse(n)}catch(r){if(r.name==="NoSuchKey"||r.name==="NotFound")return null;throw r}}async _del(t){return await this.client.deleteObject(me(this.keyPrefix,t)),!0}async _clear(){const t=await this.client.getAllKeys({prefix:this.keyPrefix});for(const r of t)await this.client.deleteObject(r)}async size(){return(await this.keys()).length}async keys(){const t=await this.client.getAllKeys({prefix:this.keyPrefix}),r=this.keyPrefix.endsWith("/")?this.keyPrefix:this.keyPrefix+"/";return t.map(n=>n.startsWith(r)?n.slice(r.length):n)}}class Mc extends R{async setup(t){}async start(){}async stop(){}beforeSetup(){this.emit("plugin.beforeSetup",new Date)}afterSetup(){this.emit("plugin.afterSetup",new Date)}beforeStart(){this.emit("plugin.beforeStart",new Date)}afterStart(){this.emit("plugin.afterStart",new Date)}beforeStop(){this.emit("plugin.beforeStop",new Date)}afterStop(){this.emit("plugin.afterStop",new Date)}}const qp={setup(e){},start(){},stop(){}},Hp={async setup(e){this.client=e.client,this.map={PutObjectCommand:"put",GetObjectCommand:"get",HeadObjectCommand:"get",DeleteObjectCommand:"delete",DeleteObjectsCommand:"delete",ListObjectsV2Command:"list"},this.costs={total:0,prices:{put:.005/1e3,copy:.005/1e3,list:.005/1e3,post:.005/1e3,get:4e-4/1e3,select:4e-4/1e3,delete:4e-4/1e3},requests:{total:0,put:0,post:0,copy:0,list:0,get:0,select:0,delete:0},events:{total:0,PutObjectCommand:0,GetObjectCommand:0,HeadObjectCommand:0,DeleteObjectCommand:0,DeleteObjectsCommand:0,ListObjectsV2Command:0}},this.client.costs=JSON.parse(JSON.stringify(this.costs))},async start(){this.client.on("command.response",e=>this.addRequest(e,this.map[e]))},addRequest(e,t){this.costs.events[e]++,this.costs.events.total++,this.costs.requests.total++,this.costs.requests[t]++,this.costs.total+=this.costs.prices[t],this.client.costs.events[e]++,this.client.costs.events.total++,this.client.costs.requests.total++,this.client.costs.requests[t]++,this.client.costs.total+=this.client.costs.prices[t]}};class Kp extends Mc{constructor(t={}){super(),this.driver=t.driver}async setup(t){this.database=t,this.driver||(this.driver=new Dc({keyPrefix:"cache",client:t.client})),this.installDatabaseProxy();for(const r of Object.values(t.resources))this.installResourcesProxies(r)}async start(){}async stop(){}installDatabaseProxy(){const t=this.installResourcesProxies.bind(this);this.database._createResource=this.database.createResource,this.database.createResource=async function(...r){const n=await this._createResource(...r);return t(n),n}}installResourcesProxies(t){t.cache=this.driver;let r=`resource=${t.name}`;this.driver.keyPrefix&&(this.driver.keyPrefix=me(this.driver.keyPrefix,r)),t.cacheKeyFor=async function({params:n={},action:i="list"}){let a=Object.keys(n).sort().map(o=>`${o}:${n[o]}`).join("|")||"empty";return a=await ha(a),a=me(r,`action=${i}`,`${a}.json.gz`),a},t._count=t.count,t._listIds=t.listIds,t._getMany=t.getMany,t._getAll=t.getAll,t._page=t.page,t.count=async function(){const n=await this.cacheKeyFor({action:"count"});try{const a=await this.cache.get(n);if(a)return a}catch(a){if(a.name!=="NoSuchKey")throw a}const i=await t._count();return await this.cache.set(n,i),i},t.listIds=async function(){const n=await this.cacheKeyFor({action:"listIds"});try{const a=await this.cache.get(n);if(a)return a}catch(a){if(a.name!=="NoSuchKey")throw a}const i=await t._listIds();return await this.cache.set(n,i),i},t.getMany=async function(n){const i=await this.cacheKeyFor({action:"getMany",params:{ids:n}});try{const o=await this.cache.get(i);if(o)return o}catch(o){if(o.name!=="NoSuchKey")throw o}const a=await t._getMany(n);return await this.cache.set(i,a),a},t.getAll=async function(){const n=await this.cacheKeyFor({action:"getAll"});try{const a=await this.cache.get(n);if(a)return a}catch(a){if(a.name!=="NoSuchKey")throw a}const i=await t._getAll();return await this.cache.set(n,i),i},t.page=async function({offset:n,size:i}){const a=await this.cacheKeyFor({action:"page",params:{offset:n,size:i}});try{const s=await this.cache.get(a);if(s)return s}catch(s){if(s.name!=="NoSuchKey")throw s}const o=await t._page({offset:n,size:i});return await this.cache.set(a,o),o},t._insert=t.insert,t._update=t.update,t._delete=t.delete,t._deleteMany=t.deleteMany,t.insert=async function(...n){const i=await t._insert(...n);return await this.cache.clear(r),i},t.update=async function(...n){const i=await t._update(...n);return await this.cache.clear(r),i},t.delete=async function(...n){const i=await t._delete(...n);return await this.cache.clear(r),i},t.deleteMany=async function(...n){const i=await t._deleteMany(...n);return await this.cache.clear(r),i}}}export{Mh as AVAILABLE_BEHAVIORS,Af as AuthenticationError,ra as BaseError,gi as Cache,Kp as CachePlugin,ua as Client,la as ConnectionString,Hp as CostsPlugin,ds as DEFAULT_BEHAVIOR,ps as Database,Ef as DatabaseError,Rf as EncryptionError,sa as ErrorMap,rr as InvalidResourceItem,Nh as MemoryCache,aa as MissingMetadata,na as NoSuchBucket,Hr as NoSuchKey,ia as NotFound,kf as PermissionError,Mc as Plugin,qp as PluginObject,br as Resource,cs as ResourceIdsPageReader,ss as ResourceIdsReader,Of as ResourceNotFound,fs as ResourceReader,ls as ResourceWriter,Dc as S3Cache,ne as S3DBError,fa as S3_DEFAULT_ENDPOINT,ca as S3_DEFAULT_REGION,ys as S3db,_e as Schema,Hn as SchemaActions,oa as UnknownError,Sf as ValidationError,wo as Validator,_o as ValidatorManager,_r as behaviors,ui as calculateAttributeNamesSize,Ft as calculateAttributeSizes,Ce as calculateTotalSize,Ye as calculateUTF8Bytes,da as decrypt,ys as default,Kr as encrypt,ge as getBehavior,ph as getSizeBreakdown,Zr as idGenerator,pf as passwordGenerator,ha as sha256,yt as streamToString,hi as transformValue};
31
+ `)}`);const{name:n,client:i,version:a="1",attributes:o={},behavior:s=ps,passphrase:f="secret",parallelism:c=10,observers:l=[],cache:h=!1,autoDecrypt:d=!0,timestamps:u=!1,partitions:p={},paranoid:y=!0,allNestedObjectsOptional:w=!0,hooks:b={},idGenerator:m,idSize:x=22}=t;if(this.name=n,this.client=i,this.version=a,this.behavior=s,this.observers=l,this.parallelism=c,this.passphrase=f??"secret",this.idGenerator=this.configureIdGenerator(m,x),this.config={cache:h,hooks:b,paranoid:y,timestamps:u,partitions:p,autoDecrypt:d,allNestedObjectsOptional:w},this.hooks={preInsert:[],afterInsert:[],preUpdate:[],afterUpdate:[],preDelete:[],afterDelete:[]},this.attributes=o||{},this.applyConfiguration(),b){for(const[v,S]of Object.entries(b))if(Array.isArray(S)&&this.hooks[v])for(const O of S)typeof O=="function"&&this.hooks[v].push(O.bind(this))}}configureIdGenerator(t,r){return typeof t=="function"?t:typeof t=="number"&&t>0?ys(t):typeof r=="number"&&r>0?ys(r):qr}get options(){return{timestamps:this.config.timestamps,partitions:this.config.partitions||{},cache:this.config.cache,autoDecrypt:this.config.autoDecrypt,paranoid:this.config.paranoid,allNestedObjectsOptional:this.config.allNestedObjectsOptional}}export(){const t=this.schema.export();return t.behavior=this.behavior,t.timestamps=this.config.timestamps,t.partitions=this.config.partitions||{},t.paranoid=this.config.paranoid,t.allNestedObjectsOptional=this.config.allNestedObjectsOptional,t.autoDecrypt=this.config.autoDecrypt,t.cache=this.config.cache,t.hooks=this.hooks,t}applyConfiguration(){this.config.timestamps&&(this.attributes.createdAt||(this.attributes.createdAt="string|optional"),this.attributes.updatedAt||(this.attributes.updatedAt="string|optional"),this.config.partitions||(this.config.partitions={}),this.config.partitions.byCreatedDate||(this.config.partitions.byCreatedDate={fields:{createdAt:"date|maxlength:10"}}),this.config.partitions.byUpdatedDate||(this.config.partitions.byUpdatedDate={fields:{updatedAt:"date|maxlength:10"}})),this.setupPartitionHooks(),this.schema=new be({name:this.name,attributes:this.attributes,passphrase:this.passphrase,version:this.version,options:{autoDecrypt:this.config.autoDecrypt,allNestedObjectsOptional:this.config.allNestedObjectsOptional}}),this.validatePartitions()}updateAttributes(t){const r=this.attributes;return this.attributes=t,this.applyConfiguration(),{oldAttributes:r,newAttributes:t}}addHook(t,r){this.hooks[t]&&this.hooks[t].push(r.bind(this))}async executeHooks(t,r){if(!this.hooks[t])return r;let n=r;for(const i of this.hooks[t])n=await i(n);return n}setupPartitionHooks(){if(!this.config.partitions)return;const t=this.config.partitions;Object.keys(t).length!==0&&(this.hooks.afterInsert||(this.hooks.afterInsert=[]),this.hooks.afterInsert.push(async r=>(await this.createPartitionReferences(r),r)),this.hooks.afterDelete||(this.hooks.afterDelete=[]),this.hooks.afterDelete.push(async r=>(await this.deletePartitionReferences(r),r)))}async validate(t){const r={original:Rt(t),isValid:!1,errors:[]},n=await this.schema.validate(t,{mutateOriginal:!0});return n===!0?r.isValid=!0:r.errors=n,r.data=t,r}validatePartitions(){if(!this.config.partitions)return;const t=this.config.partitions;if(Object.keys(t).length===0)return;const r=Object.keys(this.attributes||{});for(const[n,i]of Object.entries(t))if(i.fields){for(const a of Object.keys(i.fields))if(!this.fieldExistsInAttributes(a))throw new Error(`Partition '${n}' uses field '${a}' which does not exist in resource attributes. Available fields: ${r.join(", ")}.`)}}fieldExistsInAttributes(t){if(!t.includes("."))return Object.keys(this.attributes||{}).includes(t);const r=t.split(".");let n=this.attributes||{};for(const i of r){if(!n||typeof n!="object"||!(i in n))return!1;n=n[i]}return!0}applyPartitionRule(t,r){if(t==null)return t;let n=t;if(typeof r=="string"&&r.includes("maxlength:")){const i=r.match(/maxlength:(\d+)/);if(i){const a=parseInt(i[1]);typeof n=="string"&&n.length>a&&(n=n.substring(0,a))}}if(r.includes("date")){if(n instanceof Date)n=n.toISOString().split("T")[0];else if(typeof n=="string")try{if(n.includes("T")&&n.includes("Z"))n=n.split("T")[0];else{const i=new Date(n);isNaN(i.getTime())||(n=i.toISOString().split("T")[0])}}catch{}}return n}getResourceKey(t){return me(`resource=${this.name}`,`v=${this.version}`,`id=${t}`)}getPartitionKey({partitionName:t,id:r,data:n}){if(!this.config.partitions||!this.config.partitions[t])throw new Error(`Partition '${t}' not found`);const i=this.config.partitions[t],a=[],o=Object.entries(i.fields).sort(([f],[c])=>f.localeCompare(c));for(const[f,c]of o){const l=this.getNestedFieldValue(n,f),h=this.applyPartitionRule(l,c);if(h==null)return null;a.push(`${f}=${h}`)}if(a.length===0)return null;const s=r||n?.id;return s?me(`resource=${this.name}`,`partition=${t}`,...a,`id=${s}`):null}getNestedFieldValue(t,r){if(!r.includes("."))return t[r];const n=r.split(".");let i=t;for(const a of n){if(!i||typeof i!="object"||!(a in i))return;i=i[a]}return i}async insert({id:t,...r}){this.options.timestamps&&(r.createdAt=new Date().toISOString(),r.updatedAt=new Date().toISOString());const n=await this.executeHooks("preInsert",r),{errors:i,isValid:a,data:o}=await this.validate(n);if(!a)throw new rr({bucket:this.client.config.bucket,resourceName:this.name,attributes:n,validation:i});!t&&t!==0&&(t=this.idGenerator());const s=await this.schema.mapper(o),f=ge(this.behavior),{mappedData:c,body:l}=await f.handleInsert({resource:this,data:o,mappedData:s}),h=this.getResourceKey(t);let d;if(l&&l!=="")try{JSON.parse(l),d="application/json"}catch{}await this.client.putObject({metadata:c,key:h,body:l,contentType:d});const u=kt({id:t},o);return await this.executeHooks("afterInsert",u),this.emit("insert",u),u}async get(t){const r=this.getResourceKey(t);try{const n=await this.client.headObject(r),i=this.extractVersionFromKey(r)||this.version;let o=await(await this.getSchemaForVersion(i)).unmapper(n.Metadata);const s=ge(this.behavior);let f="";if(n.ContentLength>0)try{const h=await this.client.getObject(r);f=await yt(h.Body)}catch(h){console.warn(`Failed to read body for resource ${t}:`,h.message),f=""}const{metadata:c}=await s.handleGet({resource:this,metadata:o,body:f});let l=c;return l.id=t,l._contentLength=n.ContentLength,l._lastModified=n.LastModified,l._hasContent=n.ContentLength>0,l._mimeType=n.ContentType||null,n.VersionId&&(l._versionId=n.VersionId),n.Expiration&&(l._expiresAt=n.Expiration),l._definitionHash=this.getDefinitionHash(),this.emit("get",l),l}catch(n){if(n.message.includes("Cipher job failed")||n.message.includes("OperationError")||n.originalError?.message?.includes("Cipher job failed"))try{console.warn(`Decryption failed for resource ${t}, attempting to get raw metadata`);const a=await this.client.headObject(r),o=this.extractVersionFromKey(r)||this.version;let f=await new be({name:this.name,attributes:this.attributes,passphrase:this.passphrase,version:o,options:{...this.config,autoDecrypt:!1,autoEncrypt:!1}}).unmapper(a.Metadata);const c=ge(this.behavior);let l="";if(a.ContentLength>0)try{const u=await this.client.getObject(r);l=await yt(u.Body)}catch(u){console.warn(`Failed to read body for resource ${t}:`,u.message),l=""}const{metadata:h}=await c.handleGet({resource:this,metadata:f,body:l});let d=h;return d.id=t,d._contentLength=a.ContentLength,d._lastModified=a.LastModified,d._hasContent=a.ContentLength>0,d._mimeType=a.ContentType||null,d._version=o,d._decryptionFailed=!0,a.VersionId&&(d._versionId=a.VersionId),a.Expiration&&(d._expiresAt=a.Expiration),d._definitionHash=this.getDefinitionHash(),this.emit("get",d),d}catch(a){console.error(`Fallback attempt also failed for resource ${t}:`,a.message)}const i=new Error(`Failed to get resource with id '${t}': ${n.message}`);throw i.originalError=n,i.resourceId=t,i.resourceKey=r,i}}async exists(t){try{const r=this.getResourceKey(t);return await this.client.headObject(r),!0}catch{return!1}}async update(t,r){const n=await this.get(t);this.config.timestamps&&(r.updatedAt=new Date().toISOString());const i=await this.executeHooks("preUpdate",r),a=kt(n,i);delete a.id;const{isValid:o,errors:s,data:f}=await this.validate(a);if(!o)throw new rr({bucket:this.client.bucket,resourceName:this.name,attributes:i,validation:s});const c={...n,id:t},l={...f,id:t};await this.handlePartitionReferenceUpdates(c,l);const h=await this.schema.mapper(f),d=ge(this.behavior),{mappedData:u,body:p}=await d.handleUpdate({resource:this,id:t,data:f,mappedData:h}),y=this.getResourceKey(t);let w,b=p;if(p===""&&this.behavior!=="body-overflow")try{const x=await this.client.getObject(y);if(x.ContentLength>0){const v=Buffer.from(await x.Body.transformToByteArray()),S=v.toString();try{JSON.parse(S)}catch{b=v,w=x.ContentType}}}catch{}let m=w;if(b&&b!==""&&!m)try{JSON.parse(b),m="application/json"}catch{}return await this.client.putObject({key:y,body:b,contentType:m,metadata:u}),f.id=t,await this.executeHooks("afterUpdate",f),this.emit("update",i,f),f}async delete(t){let r;try{r=await this.get(t)}catch{r={id:t}}await this.executeHooks("preDelete",r);const n=this.getResourceKey(t),i=await this.client.deleteObject(n);return await this.executeHooks("afterDelete",r),this.emit("delete",t),i}async upsert({id:t,...r}){return await this.exists(t)?this.update(t,r):this.insert({id:t,...r})}async count({partition:t=null,partitionValues:r={}}={}){let n;if(t&&Object.keys(r).length>0){const a=this.config.partitions[t];if(!a)throw new Error(`Partition '${t}' not found`);const o=[],s=Object.entries(a.fields).sort(([f],[c])=>f.localeCompare(c));for(const[f,c]of s){const l=r[f];if(l!=null){const h=this.applyPartitionRule(l,c);o.push(`${f}=${h}`)}}o.length>0?n=`resource=${this.name}/partition=${t}/${o.join("/")}`:n=`resource=${this.name}/partition=${t}`}else n=`resource=${this.name}/v=${this.version}`;const i=await this.client.count({prefix:n});return this.emit("count",i),i}async insertMany(t){const{results:r}=await he.for(t).withConcurrency(this.parallelism).handleError(async(n,i)=>{this.emit("error",n,i),this.observers.map(a=>a.emit("error",this.name,n,i))}).process(async n=>await this.insert(n));return this.emit("insertMany",t.length),r}async deleteMany(t){const r=Hi(t.map(i=>this.getResourceKey(i)),1e3),{results:n}=await he.for(r).withConcurrency(this.parallelism).handleError(async(i,a)=>{this.emit("error",i,a),this.observers.map(o=>o.emit("error",this.name,i,a))}).process(async i=>{const a=await this.client.deleteObjects(i);return i.forEach(o=>{const f=o.split("/").find(l=>l.startsWith("id=")),c=f?f.replace("id=",""):null;c&&(this.emit("deleted",c),this.observers.map(l=>l.emit("deleted",this.name,c)))}),a});return this.emit("deleteMany",t.length),n}async deleteAll(){if(this.config.paranoid!==!1)throw new Error(`deleteAll() is a dangerous operation and requires paranoid: false option. Current paranoid setting: ${this.config.paranoid}`);const t=`resource=${this.name}/v=${this.version}`,r=await this.client.deleteAll({prefix:t});return this.emit("deleteAll",{version:this.version,prefix:t,deletedCount:r}),{deletedCount:r,version:this.version}}async deleteAllData(){if(this.config.paranoid!==!1)throw new Error(`deleteAllData() is a dangerous operation and requires paranoid: false option. Current paranoid setting: ${this.config.paranoid}`);const t=`resource=${this.name}`,r=await this.client.deleteAll({prefix:t});return this.emit("deleteAllData",{resource:this.name,prefix:t,deletedCount:r}),{deletedCount:r,resource:this.name}}async listIds({partition:t=null,partitionValues:r={},limit:n,offset:i=0}={}){let a;if(t&&Object.keys(r).length>0){if(!this.config.partitions||!this.config.partitions[t])throw new Error(`Partition '${t}' not found`);const f=this.config.partitions[t],c=[],l=Object.entries(f.fields).sort(([h],[d])=>h.localeCompare(d));for(const[h,d]of l){const u=r[h];if(u!=null){const p=this.applyPartitionRule(u,d);c.push(`${h}=${p}`)}}c.length>0?a=`resource=${this.name}/partition=${t}/${c.join("/")}`:a=`resource=${this.name}/partition=${t}`}else a=`resource=${this.name}/v=${this.version}`;const s=(await this.client.getKeysPage({prefix:a,offset:i,amount:n||1e3})).map(f=>{const l=f.split("/").find(h=>h.startsWith("id="));return l?l.replace("id=",""):null}).filter(Boolean);return this.emit("listIds",s.length),s}async list({partition:t=null,partitionValues:r={},limit:n,offset:i=0}={}){try{if(!t){let y=[];try{y=await this.listIds({partition:t,partitionValues:r})}catch(v){return console.warn("Failed to get list IDs:",v.message),[]}let w=y.slice(i);n&&(w=w.slice(0,n));const{results:b,errors:m}=await he.for(w).withConcurrency(this.parallelism).handleError(async(v,S)=>(console.warn(`Failed to get resource ${S}:`,v.message),null)).process(async v=>{try{return await this.get(v)}catch(S){if(S.message.includes("Cipher job failed")||S.message.includes("OperationError"))return console.warn(`Decryption failed for ${v}, returning basic info`),{id:v,_decryptionFailed:!0,_error:S.message};throw S}}),x=b.filter(v=>v!==null);return this.emit("list",{partition:t,partitionValues:r,count:x.length,errors:m.length}),x}if(!this.config.partitions||!this.config.partitions[t])return console.warn(`Partition '${t}' not found in resource '${this.name}'`),this.emit("list",{partition:t,partitionValues:r,count:0,errors:0}),[];const a=this.config.partitions[t],o=[],s=Object.entries(a.fields).sort(([y],[w])=>y.localeCompare(w));for(const[y,w]of s){const b=r[y];if(b!=null){const m=this.applyPartitionRule(b,w);o.push(`${y}=${m}`)}}let f;o.length>0?f=`resource=${this.name}/partition=${t}/${o.join("/")}`:f=`resource=${this.name}/partition=${t}`;let c=[];try{c=await this.client.getAllKeys({prefix:f})}catch(y){return console.warn("Failed to get partition keys:",y.message),[]}let h=c.map(y=>{const b=y.split("/").find(m=>m.startsWith("id="));return b?b.replace("id=",""):null}).filter(Boolean).slice(i);n&&(h=h.slice(0,n));const{results:d,errors:u}=await he.for(h).withConcurrency(this.parallelism).handleError(async(y,w)=>(console.warn(`Failed to get partition resource ${w}:`,y.message),null)).process(async y=>{try{const w=c.find(x=>x.includes(`id=${y}`));if(!w)throw new Error(`Partition key not found for ID ${y}`);const b=w.split("/"),m={};for(const[x,v]of s){const S=b.find(O=>O.startsWith(`${x}=`));if(S){const O=S.replace(`${x}=`,"");m[x]=O}}return await this.getFromPartition({id:y,partitionName:t,partitionValues:m})}catch(w){if(w.message.includes("Cipher job failed")||w.message.includes("OperationError"))return console.warn(`Decryption failed for partition resource ${y}, returning basic info`),{id:y,_partition:t,_partitionValues:r,_decryptionFailed:!0,_error:w.message};throw w}}),p=d.filter(y=>y!==null);return this.emit("list",{partition:t,partitionValues:r,count:p.length,errors:u.length}),p}catch(a){return a.message.includes("Partition '")&&a.message.includes("' not found")?(console.warn("Partition error in list method:",a.message),this.emit("list",{partition:t,partitionValues:r,count:0,errors:1}),[]):(console.error("Critical error in list method:",a.message),this.emit("list",{partition:t,partitionValues:r,count:0,errors:1}),[])}}async getMany(t){const{results:r,errors:n}=await he.for(t).withConcurrency(this.client.parallelism).handleError(async(i,a)=>(console.warn(`Failed to get resource ${a}:`,i.message),{id:a,_error:i.message,_decryptionFailed:i.message.includes("Cipher job failed")||i.message.includes("OperationError")})).process(async i=>{this.emit("id",i);try{const a=await this.get(i);return this.emit("data",a),a}catch(a){if(a.message.includes("Cipher job failed")||a.message.includes("OperationError"))return console.warn(`Decryption failed for ${i}, returning basic info`),{id:i,_decryptionFailed:!0,_error:a.message};throw a}});return this.emit("getMany",t.length),r}async getAll(){let t=await this.listIds();if(t.length===0)return[];const{results:r,errors:n}=await he.for(t).withConcurrency(this.client.parallelism).handleError(async(i,a)=>(console.warn(`Failed to get resource ${a}:`,i.message),{id:a,_error:i.message,_decryptionFailed:i.message.includes("Cipher job failed")||i.message.includes("OperationError")})).process(async i=>{try{return await this.get(i)}catch(a){if(a.message.includes("Cipher job failed")||a.message.includes("OperationError"))return console.warn(`Decryption failed for ${i}, returning basic info`),{id:i,_decryptionFailed:!0,_error:a.message};throw a}});return this.emit("getAll",r.length),r}async page({offset:t=0,size:r=100,partition:n=null,partitionValues:i={},skipCount:a=!1}={}){try{let o=null,s=null;if(!a)try{o=await this.count({partition:n,partitionValues:i}),s=Math.ceil(o/r)}catch(h){console.warn("Failed to get count for page:",h.message),o=null,s=null}const f=Math.floor(t/r);let c=[];try{c=await this.list({partition:n,partitionValues:i,limit:r,offset:t})}catch(h){console.warn("Failed to get items for page:",h.message),c=[]}const l={items:c,totalItems:o,page:f,pageSize:r,totalPages:s,_debug:{requestedSize:r,requestedOffset:t,actualItemsReturned:c.length,skipCount:a,hasTotalItems:o!==null}};return this.emit("page",l),l}catch(o){return console.error("Critical error in page method:",o.message),{items:[],totalItems:null,page:Math.floor(t/r),pageSize:r,totalPages:null,_debug:{requestedSize:r,requestedOffset:t,actualItemsReturned:0,skipCount:a,hasTotalItems:!1,error:o.message}}}}readable(){return new ls({resource:this}).build()}writable(){return new us({resource:this}).build()}async setContent({id:t,buffer:r,contentType:n="application/octet-stream"}){const i=await this.get(t);if(!i)throw new Error(`Resource with id '${t}' not found`);const a={...i,_hasContent:!0,_contentLength:r.length,_mimeType:n};return await this.client.putObject({key:this.getResourceKey(t),metadata:await this.schema.mapper(a),body:r,contentType:n}),this.emit("setContent",{id:t,contentType:n,contentLength:r.length}),a}async content(t){const r=this.getResourceKey(t);try{const n=await this.client.getObject(r),i=Buffer.from(await n.Body.transformToByteArray()),a=n.ContentType||null;return this.emit("content",t,i.length,a),{buffer:i,contentType:a}}catch(n){if(n.name==="NoSuchKey")return{buffer:null,contentType:null};throw n}}async hasContent(t){const r=this.getResourceKey(t);try{return(await this.client.headObject(r)).ContentLength>0}catch{return!1}}async deleteContent(t){const r=this.getResourceKey(t),i=(await this.client.headObject(r)).Metadata||{},a=await this.client.putObject({key:r,body:"",metadata:i});return this.emit("deleteContent",t),a}getDefinitionHash(){const t={attributes:this.attributes,behavior:this.behavior},r=wo(t);return`sha256:${Gi("sha256").update(r).digest("hex")}`}extractVersionFromKey(t){const n=t.split("/").find(i=>i.startsWith("v="));return n?n.replace("v=",""):null}async getSchemaForVersion(t){if(t===this.version)return this.schema;try{return new be({name:this.name,attributes:this.attributes,passphrase:this.passphrase,version:t,options:{...this.config,autoDecrypt:!0,autoEncrypt:!0}})}catch(r){return console.warn(`Failed to create compatible schema for version ${t}, using current schema:`,r.message),this.schema}}async createPartitionReferences(t){const r=this.config.partitions;if(!(!r||Object.keys(r).length===0))for(const[n,i]of Object.entries(r)){const a=this.getPartitionKey({partitionName:n,id:t.id,data:t});if(a){const o=await this.schema.mapper(t),s=ge(this.behavior),{mappedData:f,body:c}=await s.handleInsert({resource:this,data:t,mappedData:o}),l={...f,_version:this.version};let h;if(c&&c!=="")try{JSON.parse(c),h="application/json"}catch{}await this.client.putObject({key:a,metadata:l,body:c,contentType:h})}}}async deletePartitionReferences(t){const r=this.config.partitions;if(!r||Object.keys(r).length===0)return;const n=[];for(const[i,a]of Object.entries(r)){const o=this.getPartitionKey({partitionName:i,id:t.id,data:t});o&&n.push(o)}if(n.length>0)try{await this.client.deleteObjects(n)}catch(i){console.warn("Some partition objects could not be deleted:",i.message)}}async query(t={},{limit:r=100,offset:n=0,partition:i=null,partitionValues:a={}}={}){if(Object.keys(t).length===0)return await this.list({partition:i,partitionValues:a,limit:r,offset:n});const o=[];let s=n;const f=Math.min(r,50);for(;o.length<r;){const c=await this.list({partition:i,partitionValues:a,limit:f,offset:s});if(c.length===0)break;const l=c.filter(h=>Object.entries(t).every(([d,u])=>h[d]===u));if(o.push(...l),s+=f,c.length<f)break}return o.slice(0,r)}async handlePartitionReferenceUpdates(t,r){const n=this.config.partitions;if(!n||Object.keys(n).length===0)return;for(const[a,o]of Object.entries(n))try{await this.handlePartitionReferenceUpdate(a,o,t,r)}catch(s){console.warn(`Failed to update partition references for ${a}:`,s.message)}const i=r.id||t.id;for(const[a,o]of Object.entries(n)){const s=`resource=${this.name}/partition=${a}`;let f=[];try{f=await this.client.getAllKeys({prefix:s})}catch(l){console.warn(`Aggressive cleanup: could not list keys for partition ${a}:`,l.message);continue}const c=this.getPartitionKey({partitionName:a,id:i,data:r});for(const l of f)if(l.endsWith(`/id=${i}`)&&l!==c)try{await this.client.deleteObject(l)}catch(h){console.warn(`Aggressive cleanup: could not delete stale partition key ${l}:`,h.message)}}}async handlePartitionReferenceUpdate(t,r,n,i){const a=i.id||n.id,o=this.getPartitionKey({partitionName:t,id:a,data:n}),s=this.getPartitionKey({partitionName:t,id:a,data:i});if(o!==s){if(o)try{await this.client.deleteObject(o)}catch(f){console.warn(`Old partition object could not be deleted for ${t}:`,f.message)}if(s)try{const f=await this.schema.mapper(i);f.undefined!==void 0&&delete f.undefined;const c=ge(this.behavior),{mappedData:l,body:h}=await c.handleUpdate({resource:this,id:a,data:i,mappedData:f});l.undefined!==void 0&&delete l.undefined;const d={...l,_version:this.version};d.undefined!==void 0&&delete d.undefined;let u;if(h&&h!=="")try{JSON.parse(h),u="application/json"}catch{}await this.client.putObject({key:s,metadata:d,body:h,contentType:u})}catch(f){console.warn(`New partition object could not be created for ${t}:`,f.message)}}else if(s)try{const f=await this.schema.mapper(i);f.undefined!==void 0&&delete f.undefined;const c=ge(this.behavior),{mappedData:l,body:h}=await c.handleUpdate({resource:this,id:a,data:i,mappedData:f});l.undefined!==void 0&&delete l.undefined;const d={...l,_version:this.version};d.undefined!==void 0&&delete d.undefined;let u;if(h&&h!=="")try{JSON.parse(h),u="application/json"}catch{}await this.client.putObject({key:s,metadata:d,body:h,contentType:u})}catch(f){console.warn(`Partition object could not be updated for ${t}:`,f.message)}}async updatePartitionReferences(t){const r=this.config.partitions;if(!(!r||Object.keys(r).length===0))for(const[n,i]of Object.entries(r)){if(!i||!i.fields||typeof i.fields!="object"){console.warn(`Skipping invalid partition '${n}' in resource '${this.name}'`);continue}const a=this.getPartitionKey({partitionName:n,id:t.id,data:t});if(a){const o=await this.schema.mapper(t),s=ge(this.behavior),{mappedData:f,body:c}=await s.handleUpdate({resource:this,id:t.id,data:t,mappedData:o}),l={...f,_version:this.version};let h;if(c&&c!=="")try{JSON.parse(c),h="application/json"}catch{}try{await this.client.putObject({key:a,metadata:l,body:c,contentType:h})}catch(d){console.warn(`Partition object could not be updated for ${n}:`,d.message)}}}}async getFromPartition({id:t,partitionName:r,partitionValues:n={}}){if(!this.config.partitions||!this.config.partitions[r])throw new Error(`Partition '${r}' not found`);const i=this.config.partitions[r],a=[],o=Object.entries(i.fields).sort(([w],[b])=>w.localeCompare(b));for(const[w,b]of o){const m=n[w];if(m!=null){const x=this.applyPartitionRule(m,b);a.push(`${w}=${x}`)}}if(a.length===0)throw new Error(`No partition values provided for partition '${r}'`);const s=me(`resource=${this.name}`,`partition=${r}`,...a,`id=${t}`),f=await this.client.headObject(s),c=f.Metadata?._version||this.version;let h=await(await this.getSchemaForVersion(c)).unmapper(f.Metadata);const d=ge(this.behavior);let u="";if(f.ContentLength>0)try{const w=await this.client.getObject(s);u=await yt(w.Body)}catch{u=""}const{metadata:p}=await d.handleGet({resource:this,metadata:h,body:u});let y=p;return y.id=t,y._contentLength=f.ContentLength,y._lastModified=f.LastModified,y._hasContent=f.ContentLength>0,y._mimeType=f.ContentType||null,y._partition=r,y._partitionValues=n,f.VersionId&&(y._versionId=f.VersionId),f.Expiration&&(y._expiresAt=f.Expiration),y._definitionHash=this.getDefinitionHash(),y.undefined!==void 0&&delete y.undefined,this.emit("getFromPartition",y),y}}function Lh(e){const t=[];e.name?typeof e.name!="string"?t.push("Resource 'name' must be a string"):e.name.trim()===""&&t.push("Resource 'name' cannot be empty"):t.push("Resource 'name' is required"),e.client||t.push("S3 'client' is required"),e.attributes?typeof e.attributes!="object"||Array.isArray(e.attributes)?t.push("Resource 'attributes' must be an object"):Object.keys(e.attributes).length===0&&t.push("Resource 'attributes' cannot be empty"):t.push("Resource 'attributes' are required"),e.version!==void 0&&typeof e.version!="string"&&t.push("Resource 'version' must be a string"),e.behavior!==void 0&&typeof e.behavior!="string"&&t.push("Resource 'behavior' must be a string"),e.passphrase!==void 0&&typeof e.passphrase!="string"&&t.push("Resource 'passphrase' must be a string"),e.parallelism!==void 0&&(typeof e.parallelism!="number"||!Number.isInteger(e.parallelism)?t.push("Resource 'parallelism' must be an integer"):e.parallelism<1&&t.push("Resource 'parallelism' must be greater than 0")),e.observers!==void 0&&!Array.isArray(e.observers)&&t.push("Resource 'observers' must be an array");const r=["cache","autoDecrypt","timestamps","paranoid","allNestedObjectsOptional"];for(const n of r)e[n]!==void 0&&typeof e[n]!="boolean"&&t.push(`Resource '${n}' must be a boolean`);if(e.idGenerator!==void 0&&(typeof e.idGenerator!="function"&&typeof e.idGenerator!="number"?t.push("Resource 'idGenerator' must be a function or a number (size)"):typeof e.idGenerator=="number"&&e.idGenerator<=0&&t.push("Resource 'idGenerator' size must be greater than 0")),e.idSize!==void 0&&(typeof e.idSize!="number"||!Number.isInteger(e.idSize)?t.push("Resource 'idSize' must be an integer"):e.idSize<=0&&t.push("Resource 'idSize' must be greater than 0")),e.partitions!==void 0)if(typeof e.partitions!="object"||Array.isArray(e.partitions))t.push("Resource 'partitions' must be an object");else for(const[n,i]of Object.entries(e.partitions))if(typeof i!="object"||Array.isArray(i))t.push(`Partition '${n}' must be an object`);else if(!i.fields)t.push(`Partition '${n}' must have a 'fields' property`);else if(typeof i.fields!="object"||Array.isArray(i.fields))t.push(`Partition '${n}.fields' must be an object`);else for(const[a,o]of Object.entries(i.fields))typeof o!="string"&&t.push(`Partition '${n}.fields.${a}' must be a string`);if(e.hooks!==void 0)if(typeof e.hooks!="object"||Array.isArray(e.hooks))t.push("Resource 'hooks' must be an object");else{const n=["preInsert","afterInsert","preUpdate","afterUpdate","preDelete","afterDelete"];for(const[i,a]of Object.entries(e.hooks))if(!n.includes(i))t.push(`Invalid hook event '${i}'. Valid events: ${n.join(", ")}`);else if(!Array.isArray(a))t.push(`Resource 'hooks.${i}' must be an array`);else for(let o=0;o<a.length;o++){const s=a[o];if(typeof s!="function"){if(typeof s=="string")continue;continue}}}return{isValid:t.length===0,errors:t}}class gs extends R{constructor(t){super(),this.version="1",this.s3dbVersion=(()=>{try{return"5.2.0"}catch{return"latest"}})(),this.resources={},this.savedMetadata=null,this.options=t,this.verbose=t.verbose||!1,this.parallelism=parseInt(t.parallelism+"")||10,this.plugins=t.plugins||[],this.cache=t.cache,this.passphrase=t.passphrase||"secret";let r=t.connectionString;if(!r&&(t.bucket||t.accessKeyId||t.secretAccessKey)){const{bucket:n,region:i,accessKeyId:a,secretAccessKey:o,endpoint:s,forcePathStyle:f}=t;if(s){const c=new URL(s);a&&(c.username=encodeURIComponent(a)),o&&(c.password=encodeURIComponent(o)),c.pathname=`/${n||"s3db"}`,f&&c.searchParams.set("forcePathStyle","true"),r=c.toString()}else if(a&&o){const c=new URLSearchParams;c.set("region",i||"us-east-1"),f&&c.set("forcePathStyle","true"),r=`s3://${encodeURIComponent(a)}:${encodeURIComponent(o)}@${n||"s3db"}?${c.toString()}`}}this.client=t.client||new ha({verbose:this.verbose,parallelism:this.parallelism,connectionString:r}),this.bucket=this.client.bucket,this.keyPrefix=this.client.keyPrefix}async connect(){await this.startPlugins();let t=null;if(await this.client.exists("s3db.json")){const n=await this.client.getObject("s3db.json");t=JSON.parse(await yt(n?.Body))}else t=this.blankMetadataStructure(),await this.uploadMetadataFile();this.savedMetadata=t;const r=this.detectDefinitionChanges(t);for(const[n,i]of Object.entries(t.resources||{})){const a=i.currentVersion||"v0",o=i.versions?.[a];o&&(this.resources[n]=new _r({name:n,client:this.client,version:a,attributes:o.attributes,behavior:o.behavior||"user-management",parallelism:this.parallelism,passphrase:this.passphrase,observers:[this],cache:this.cache,timestamps:o.timestamps!==void 0?o.timestamps:!1,partitions:i.partitions||o.partitions||{},paranoid:o.paranoid!==void 0?o.paranoid:!0,allNestedObjectsOptional:o.allNestedObjectsOptional!==void 0?o.allNestedObjectsOptional:!0,autoDecrypt:o.autoDecrypt!==void 0?o.autoDecrypt:!0,hooks:o.hooks||{}}))}r.length>0&&this.emit("resourceDefinitionsChanged",{changes:r,metadata:this.savedMetadata}),this.emit("connected",new Date)}detectDefinitionChanges(t){const r=[];for(const[n,i]of Object.entries(this.resources)){const a=this.generateDefinitionHash(i.export()),o=t.resources?.[n];if(!o)r.push({type:"new",resourceName:n,currentHash:a,savedHash:null});else{const s=o.currentVersion||"v0",c=o.versions?.[s]?.hash;c!==a&&r.push({type:"changed",resourceName:n,currentHash:a,savedHash:c,fromVersion:s,toVersion:this.getNextVersion(o.versions)})}}for(const[n,i]of Object.entries(t.resources||{}))if(!this.resources[n]){const a=i.currentVersion||"v0",o=i.versions?.[a];r.push({type:"deleted",resourceName:n,currentHash:null,savedHash:o?.hash,deletedVersion:a})}return r}generateDefinitionHash(t,r=void 0){const i={...t.attributes};t.timestamps&&(delete i.createdAt,delete i.updatedAt);const a={attributes:i,behavior:r||t.behavior||"user-management"},o=wo(a);return`sha256:${Gi("sha256").update(o).digest("hex")}`}getNextVersion(t={}){const r=Object.keys(t).filter(i=>i.startsWith("v")).map(i=>parseInt(i.substring(1))).filter(i=>!isNaN(i));return`v${(r.length>0?Math.max(...r):-1)+1}`}async startPlugins(){const t=this;if(!Ki(this.plugins)){const r=this.plugins.map(a=>Gc(a)?new a(this):a),n=r.map(async a=>{a.beforeSetup&&await a.beforeSetup(),await a.setup(t),a.afterSetup&&await a.afterSetup()});await Promise.all(n);const i=r.map(async a=>{a.beforeStart&&await a.beforeStart(),await a.start(),a.afterStart&&await a.afterStart()});await Promise.all(i)}}async uploadMetadataFile(){const t={version:this.version,s3dbVersion:this.s3dbVersion,lastUpdated:new Date().toISOString(),resources:{}};Object.entries(this.resources).forEach(([r,n])=>{const i=n.export(),a=this.generateDefinitionHash(i),o=this.savedMetadata?.resources?.[r],s=o?.currentVersion||"v0",f=o?.versions?.[s];let c,l;!f||f.hash!==a?(c=this.getNextVersion(o?.versions),l=!0):(c=s,l=!1),t.resources[r]={currentVersion:c,partitions:n.config.partitions||{},versions:{...o?.versions,[c]:{hash:a,attributes:i.attributes,behavior:i.behavior||"user-management",timestamps:n.config.timestamps,partitions:n.config.partitions,paranoid:n.config.paranoid,allNestedObjectsOptional:n.config.allNestedObjectsOptional,autoDecrypt:n.config.autoDecrypt,cache:n.config.cache,hooks:n.config.hooks,createdAt:l?new Date().toISOString():f?.createdAt}}},n.version!==c&&(n.version=c,n.emit("versionUpdated",{oldVersion:s,newVersion:c}))}),await this.client.putObject({key:"s3db.json",body:JSON.stringify(t,null,2),contentType:"application/json"}),this.savedMetadata=t,this.emit("metadataUploaded",t)}blankMetadataStructure(){return{version:"1",s3dbVersion:this.s3dbVersion,resources:{}}}resourceExists(t){return!!this.resources[t]}resourceExistsWithSameHash({name:t,attributes:r,behavior:n="user-management",options:i={}}){if(!this.resources[t])return{exists:!1,sameHash:!1,hash:null};const a=this.resources[t],o=this.generateDefinitionHash(a.export()),s=new _r({name:t,attributes:r,behavior:n,client:this.client,version:a.version,passphrase:this.passphrase,...i}),f=this.generateDefinitionHash(s.export());return{exists:!0,sameHash:o===f,hash:f,existingHash:o}}async createResource({name:t,attributes:r,behavior:n="user-management",hooks:i,...a}){if(this.resources[t]){const c=this.resources[t];if(Object.assign(c.config,{cache:this.cache,...a}),n&&(c.behavior=n),c.updateAttributes(r),i){for(const[p,y]of Object.entries(i))if(Array.isArray(y)&&c.hooks[p])for(const w of y)typeof w=="function"&&c.hooks[p].push(w.bind(c))}const l=this.generateDefinitionHash(c.export(),c.behavior),h=this.savedMetadata?.resources?.[t],d=h?.currentVersion||"v0",u=h?.versions?.[d];return(!u||u.hash!==l)&&await this.uploadMetadataFile(),this.emit("s3db.resourceUpdated",t),c}const s=this.savedMetadata?.resources?.[t]?.currentVersion||"v0",f=new _r({name:t,attributes:r,behavior:n,observers:[this],client:this.client,version:s,passphrase:this.passphrase,cache:this.cache,hooks:i,...a});return this.resources[t]=f,await this.uploadMetadataFile(),this.emit("s3db.resourceCreated",t),f}resource(t){return this.resources[t]?this.resources[t]:Promise.reject(`resource ${t} does not exist`)}async listResources(){return Object.keys(this.resources).map(t=>({name:t}))}async getResource(t){if(!this.resources[t])throw new Error(`Resource not found: ${t}`);return this.resources[t]}get config(){return{version:this.version,s3dbVersion:this.s3dbVersion,bucket:this.bucket,keyPrefix:this.keyPrefix,parallelism:this.parallelism,verbose:this.verbose}}isConnected(){return!!this.savedMetadata}}class vs extends gs{}class vi extends R{constructor(t={}){super(),this.config=t}async _set(t,r){}async _get(t){}async _del(t){}async _clear(t){}validateKey(t){if(t==null||typeof t!="string"||!t)throw new Error("Invalid key")}async set(t,r){return this.validateKey(t),await this._set(t,r),this.emit("set",r),r}async get(t){this.validateKey(t);const r=await this._get(t);return this.emit("get",r),r}async del(t){this.validateKey(t);const r=await this._del(t);return this.emit("delete",r),r}async delete(t){return this.del(t)}async clear(){const t=await this._clear();return this.emit("clear",t),t}}class $h extends vi{constructor(t={}){super(t),this.cache={},this.meta={},this.maxSize=t.maxSize||0,this.ttl=t.ttl||0}async _set(t,r){if(this.maxSize>0&&Object.keys(this.cache).length>=this.maxSize){const n=Object.entries(this.meta).sort((i,a)=>i[1].ts-a[1].ts)[0]?.[0];n&&(delete this.cache[n],delete this.meta[n])}return this.cache[t]=r,this.meta[t]={ts:Date.now()},r}async _get(t){if(!Object.prototype.hasOwnProperty.call(this.cache,t))return null;if(this.ttl>0){const r=Date.now(),n=this.meta[t];if(n&&r-n.ts>this.ttl*1e3)return delete this.cache[t],delete this.meta[t],null}return this.cache[t]}async _del(t){return delete this.cache[t],delete this.meta[t],!0}async _clear(){return this.cache={},this.meta={},!0}async size(){return Object.keys(this.cache).length}async keys(){return Object.keys(this.cache)}}var ws={2:"need dictionary",1:"stream end",0:"","-1":"file error","-2":"stream error","-3":"data error","-4":"insufficient memory","-5":"buffer error","-6":"incompatible version"};function Uh(){this.input=null,this.next_in=0,this.avail_in=0,this.total_in=0,this.output=null,this.next_out=0,this.avail_out=0,this.total_out=0,this.msg="",this.state=null,this.data_type=2,this.adler=0}function ke(e,t,r,n,i){if(t.subarray&&e.subarray){e.set(t.subarray(r,r+n),i);return}for(var a=0;a<n;a++)e[i+a]=t[r+a]}var mr=Uint8Array,oe=Uint16Array,xr=Int32Array,Bh=4,bs=0,_s=1,zh=2;function gt(e){for(var t=e.length;--t>=0;)e[t]=0}var Zh=0,ms=1,qh=2,Hh=3,Kh=258,wi=29,Ct=256,Dt=Ct+1+wi,vt=30,bi=19,xs=2*Dt+1,Je=15,_i=16,Wh=7,mi=256,Es=16,Ss=17,As=18,xi=[0,0,0,0,0,0,0,0,1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,0],Er=[0,0,0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13],Vh=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7],ks=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],Gh=512,Re=new Array((Dt+2)*2);gt(Re);var Mt=new Array(vt*2);gt(Mt);var Nt=new Array(Gh);gt(Nt);var Lt=new Array(Kh-Hh+1);gt(Lt);var Ei=new Array(wi);gt(Ei);var Sr=new Array(vt);gt(Sr);function Si(e,t,r,n,i){this.static_tree=e,this.extra_bits=t,this.extra_base=r,this.elems=n,this.max_length=i,this.has_stree=e&&e.length}var Rs,Os,Is;function Ai(e,t){this.dyn_tree=e,this.max_code=0,this.stat_desc=t}function Ts(e){return e<256?Nt[e]:Nt[256+(e>>>7)]}function $t(e,t){e.pending_buf[e.pending++]=t&255,e.pending_buf[e.pending++]=t>>>8&255}function Q(e,t,r){e.bi_valid>_i-r?(e.bi_buf|=t<<e.bi_valid&65535,$t(e,e.bi_buf),e.bi_buf=t>>_i-e.bi_valid,e.bi_valid+=r-_i):(e.bi_buf|=t<<e.bi_valid&65535,e.bi_valid+=r)}function ve(e,t,r){Q(e,r[t*2],r[t*2+1])}function Ps(e,t){var r=0;do r|=e&1,e>>>=1,r<<=1;while(--t>0);return r>>>1}function Yh(e){e.bi_valid===16?($t(e,e.bi_buf),e.bi_buf=0,e.bi_valid=0):e.bi_valid>=8&&(e.pending_buf[e.pending++]=e.bi_buf&255,e.bi_buf>>=8,e.bi_valid-=8)}function Jh(e,t){var r=t.dyn_tree,n=t.max_code,i=t.stat_desc.static_tree,a=t.stat_desc.has_stree,o=t.stat_desc.extra_bits,s=t.stat_desc.extra_base,f=t.stat_desc.max_length,c,l,h,d,u,p,y=0;for(d=0;d<=Je;d++)e.bl_count[d]=0;for(r[e.heap[e.heap_max]*2+1]=0,c=e.heap_max+1;c<xs;c++)l=e.heap[c],d=r[r[l*2+1]*2+1]+1,d>f&&(d=f,y++),r[l*2+1]=d,!(l>n)&&(e.bl_count[d]++,u=0,l>=s&&(u=o[l-s]),p=r[l*2],e.opt_len+=p*(d+u),a&&(e.static_len+=p*(i[l*2+1]+u)));if(y!==0){do{for(d=f-1;e.bl_count[d]===0;)d--;e.bl_count[d]--,e.bl_count[d+1]+=2,e.bl_count[f]--,y-=2}while(y>0);for(d=f;d!==0;d--)for(l=e.bl_count[d];l!==0;)h=e.heap[--c],!(h>n)&&(r[h*2+1]!==d&&(e.opt_len+=(d-r[h*2+1])*r[h*2],r[h*2+1]=d),l--)}}function js(e,t,r){var n=new Array(Je+1),i=0,a,o;for(a=1;a<=Je;a++)n[a]=i=i+r[a-1]<<1;for(o=0;o<=t;o++){var s=e[o*2+1];s!==0&&(e[o*2]=Ps(n[s]++,s))}}function Xh(){var e,t,r,n,i,a=new Array(Je+1);for(r=0,n=0;n<wi-1;n++)for(Ei[n]=r,e=0;e<1<<xi[n];e++)Lt[r++]=n;for(Lt[r-1]=n,i=0,n=0;n<16;n++)for(Sr[n]=i,e=0;e<1<<Er[n];e++)Nt[i++]=n;for(i>>=7;n<vt;n++)for(Sr[n]=i<<7,e=0;e<1<<Er[n]-7;e++)Nt[256+i++]=n;for(t=0;t<=Je;t++)a[t]=0;for(e=0;e<=143;)Re[e*2+1]=8,e++,a[8]++;for(;e<=255;)Re[e*2+1]=9,e++,a[9]++;for(;e<=279;)Re[e*2+1]=7,e++,a[7]++;for(;e<=287;)Re[e*2+1]=8,e++,a[8]++;for(js(Re,Dt+1,a),e=0;e<vt;e++)Mt[e*2+1]=5,Mt[e*2]=Ps(e,5);Rs=new Si(Re,xi,Ct+1,Dt,Je),Os=new Si(Mt,Er,0,vt,Je),Is=new Si(new Array(0),Vh,0,bi,Wh)}function Fs(e){var t;for(t=0;t<Dt;t++)e.dyn_ltree[t*2]=0;for(t=0;t<vt;t++)e.dyn_dtree[t*2]=0;for(t=0;t<bi;t++)e.bl_tree[t*2]=0;e.dyn_ltree[mi*2]=1,e.opt_len=e.static_len=0,e.last_lit=e.matches=0}function Cs(e){e.bi_valid>8?$t(e,e.bi_buf):e.bi_valid>0&&(e.pending_buf[e.pending++]=e.bi_buf),e.bi_buf=0,e.bi_valid=0}function Qh(e,t,r,n){Cs(e),$t(e,r),$t(e,~r),ke(e.pending_buf,e.window,t,r,e.pending),e.pending+=r}function Ds(e,t,r,n){var i=t*2,a=r*2;return e[i]<e[a]||e[i]===e[a]&&n[t]<=n[r]}function ki(e,t,r){for(var n=e.heap[r],i=r<<1;i<=e.heap_len&&(i<e.heap_len&&Ds(t,e.heap[i+1],e.heap[i],e.depth)&&i++,!Ds(t,n,e.heap[i],e.depth));)e.heap[r]=e.heap[i],r=i,i<<=1;e.heap[r]=n}function Ms(e,t,r){var n,i,a=0,o,s;if(e.last_lit!==0)do n=e.pending_buf[e.d_buf+a*2]<<8|e.pending_buf[e.d_buf+a*2+1],i=e.pending_buf[e.l_buf+a],a++,n===0?ve(e,i,t):(o=Lt[i],ve(e,o+Ct+1,t),s=xi[o],s!==0&&(i-=Ei[o],Q(e,i,s)),n--,o=Ts(n),ve(e,o,r),s=Er[o],s!==0&&(n-=Sr[o],Q(e,n,s)));while(a<e.last_lit);ve(e,mi,t)}function Ri(e,t){var r=t.dyn_tree,n=t.stat_desc.static_tree,i=t.stat_desc.has_stree,a=t.stat_desc.elems,o,s,f=-1,c;for(e.heap_len=0,e.heap_max=xs,o=0;o<a;o++)r[o*2]!==0?(e.heap[++e.heap_len]=f=o,e.depth[o]=0):r[o*2+1]=0;for(;e.heap_len<2;)c=e.heap[++e.heap_len]=f<2?++f:0,r[c*2]=1,e.depth[c]=0,e.opt_len--,i&&(e.static_len-=n[c*2+1]);for(t.max_code=f,o=e.heap_len>>1;o>=1;o--)ki(e,r,o);c=a;do o=e.heap[1],e.heap[1]=e.heap[e.heap_len--],ki(e,r,1),s=e.heap[1],e.heap[--e.heap_max]=o,e.heap[--e.heap_max]=s,r[c*2]=r[o*2]+r[s*2],e.depth[c]=(e.depth[o]>=e.depth[s]?e.depth[o]:e.depth[s])+1,r[o*2+1]=r[s*2+1]=c,e.heap[1]=c++,ki(e,r,1);while(e.heap_len>=2);e.heap[--e.heap_max]=e.heap[1],Jh(e,t),js(r,f,e.bl_count)}function Ns(e,t,r){var n,i=-1,a,o=t[0*2+1],s=0,f=7,c=4;for(o===0&&(f=138,c=3),t[(r+1)*2+1]=65535,n=0;n<=r;n++)a=o,o=t[(n+1)*2+1],!(++s<f&&a===o)&&(s<c?e.bl_tree[a*2]+=s:a!==0?(a!==i&&e.bl_tree[a*2]++,e.bl_tree[Es*2]++):s<=10?e.bl_tree[Ss*2]++:e.bl_tree[As*2]++,s=0,i=a,o===0?(f=138,c=3):a===o?(f=6,c=3):(f=7,c=4))}function Ls(e,t,r){var n,i=-1,a,o=t[0*2+1],s=0,f=7,c=4;for(o===0&&(f=138,c=3),n=0;n<=r;n++)if(a=o,o=t[(n+1)*2+1],!(++s<f&&a===o)){if(s<c)do ve(e,a,e.bl_tree);while(--s!==0);else a!==0?(a!==i&&(ve(e,a,e.bl_tree),s--),ve(e,Es,e.bl_tree),Q(e,s-3,2)):s<=10?(ve(e,Ss,e.bl_tree),Q(e,s-3,3)):(ve(e,As,e.bl_tree),Q(e,s-11,7));s=0,i=a,o===0?(f=138,c=3):a===o?(f=6,c=3):(f=7,c=4)}}function ed(e){var t;for(Ns(e,e.dyn_ltree,e.l_desc.max_code),Ns(e,e.dyn_dtree,e.d_desc.max_code),Ri(e,e.bl_desc),t=bi-1;t>=3&&e.bl_tree[ks[t]*2+1]===0;t--);return e.opt_len+=3*(t+1)+5+5+4,t}function td(e,t,r,n){var i;for(Q(e,t-257,5),Q(e,r-1,5),Q(e,n-4,4),i=0;i<n;i++)Q(e,e.bl_tree[ks[i]*2+1],3);Ls(e,e.dyn_ltree,t-1),Ls(e,e.dyn_dtree,r-1)}function rd(e){var t=4093624447,r;for(r=0;r<=31;r++,t>>>=1)if(t&1&&e.dyn_ltree[r*2]!==0)return bs;if(e.dyn_ltree[9*2]!==0||e.dyn_ltree[10*2]!==0||e.dyn_ltree[13*2]!==0)return _s;for(r=32;r<Ct;r++)if(e.dyn_ltree[r*2]!==0)return _s;return bs}var $s=!1;function nd(e){$s||(Xh(),$s=!0),e.l_desc=new Ai(e.dyn_ltree,Rs),e.d_desc=new Ai(e.dyn_dtree,Os),e.bl_desc=new Ai(e.bl_tree,Is),e.bi_buf=0,e.bi_valid=0,Fs(e)}function Us(e,t,r,n){Q(e,(Zh<<1)+(n?1:0),3),Qh(e,t,r)}function id(e){Q(e,ms<<1,3),ve(e,mi,Re),Yh(e)}function ad(e,t,r,n){var i,a,o=0;e.level>0?(e.strm.data_type===zh&&(e.strm.data_type=rd(e)),Ri(e,e.l_desc),Ri(e,e.d_desc),o=ed(e),i=e.opt_len+3+7>>>3,a=e.static_len+3+7>>>3,a<=i&&(i=a)):i=a=r+5,r+4<=i&&t!==-1?Us(e,t,r,n):e.strategy===Bh||a===i?(Q(e,(ms<<1)+(n?1:0),3),Ms(e,Re,Mt)):(Q(e,(qh<<1)+(n?1:0),3),td(e,e.l_desc.max_code+1,e.d_desc.max_code+1,o+1),Ms(e,e.dyn_ltree,e.dyn_dtree)),Fs(e),n&&Cs(e)}function De(e,t,r){return e.pending_buf[e.d_buf+e.last_lit*2]=t>>>8&255,e.pending_buf[e.d_buf+e.last_lit*2+1]=t&255,e.pending_buf[e.l_buf+e.last_lit]=r&255,e.last_lit++,t===0?e.dyn_ltree[r*2]++:(e.matches++,t--,e.dyn_ltree[(Lt[r]+Ct+1)*2]++,e.dyn_dtree[Ts(t)*2]++),e.last_lit===e.lit_bufsize-1}function Oi(e,t,r,n){for(var i=e&65535|0,a=e>>>16&65535|0,o=0;r!==0;){o=r>2e3?2e3:r,r-=o;do i=i+t[n++]|0,a=a+i|0;while(--o);i%=65521,a%=65521}return i|a<<16|0}function od(){for(var e,t=[],r=0;r<256;r++){e=r;for(var n=0;n<8;n++)e=e&1?3988292384^e>>>1:e>>>1;t[r]=e}return t}var sd=od();function z(e,t,r,n){var i=sd,a=n+r;e^=-1;for(var o=n;o<a;o++)e=e>>>8^i[(e^t[o])&255];return e^-1}var Xe=0,cd=1,fd=3,Me=4,Bs=5,Ne=0,zs=1,Le=-2,ld=-3,Ii=-5,ud=-1,hd=1,Ar=2,dd=3,pd=4,yd=2,Ti=8,gd=9,vd=29,wd=256,Pi=wd+1+vd,bd=30,_d=19,md=2*Pi+1,xd=15,P=3,$e=258,se=$e+P+1,Ed=32,ji=42,Fi=69,kr=73,Rr=91,Or=103,Qe=113,Ut=666,U=1,Bt=2,et=3,wt=4,Sd=3;function Ue(e,t){return e.msg=ws[t],t}function Zs(e){return(e<<1)-(e>4?9:0)}function tt(e){for(var t=e.length;--t>=0;)e[t]=0}function Be(e){var t=e.state,r=t.pending;r>e.avail_out&&(r=e.avail_out),r!==0&&(ke(e.output,t.pending_buf,t.pending_out,r,e.next_out),e.next_out+=r,t.pending_out+=r,e.total_out+=r,e.avail_out-=r,t.pending-=r,t.pending===0&&(t.pending_out=0))}function H(e,t){ad(e,e.block_start>=0?e.block_start:-1,e.strstart-e.block_start,t),e.block_start=e.strstart,Be(e.strm)}function T(e,t){e.pending_buf[e.pending++]=t}function zt(e,t){e.pending_buf[e.pending++]=t>>>8&255,e.pending_buf[e.pending++]=t&255}function Ad(e,t,r,n){var i=e.avail_in;return i>n&&(i=n),i===0?0:(e.avail_in-=i,ke(t,e.input,e.next_in,i,r),e.state.wrap===1?e.adler=Oi(e.adler,t,i,r):e.state.wrap===2&&(e.adler=z(e.adler,t,i,r)),e.next_in+=i,e.total_in+=i,i)}function qs(e,t){var r=e.max_chain_length,n=e.strstart,i,a,o=e.prev_length,s=e.nice_match,f=e.strstart>e.w_size-se?e.strstart-(e.w_size-se):0,c=e.window,l=e.w_mask,h=e.prev,d=e.strstart+$e,u=c[n+o-1],p=c[n+o];e.prev_length>=e.good_match&&(r>>=2),s>e.lookahead&&(s=e.lookahead);do if(i=t,!(c[i+o]!==p||c[i+o-1]!==u||c[i]!==c[n]||c[++i]!==c[n+1])){n+=2,i++;do;while(c[++n]===c[++i]&&c[++n]===c[++i]&&c[++n]===c[++i]&&c[++n]===c[++i]&&c[++n]===c[++i]&&c[++n]===c[++i]&&c[++n]===c[++i]&&c[++n]===c[++i]&&n<d);if(a=$e-(d-n),n=d-$e,a>o){if(e.match_start=t,o=a,a>=s)break;u=c[n+o-1],p=c[n+o]}}while((t=h[t&l])>f&&--r!==0);return o<=e.lookahead?o:e.lookahead}function Zt(e){var t=e.w_size,r,n,i,a,o;do{if(a=e.window_size-e.lookahead-e.strstart,e.strstart>=t+(t-se)){ke(e.window,e.window,t,t,0),e.match_start-=t,e.strstart-=t,e.block_start-=t,n=e.hash_size,r=n;do i=e.head[--r],e.head[r]=i>=t?i-t:0;while(--n);n=t,r=n;do i=e.prev[--r],e.prev[r]=i>=t?i-t:0;while(--n);a+=t}if(e.strm.avail_in===0)break;if(n=Ad(e.strm,e.window,e.strstart+e.lookahead,a),e.lookahead+=n,e.lookahead+e.insert>=P)for(o=e.strstart-e.insert,e.ins_h=e.window[o],e.ins_h=(e.ins_h<<e.hash_shift^e.window[o+1])&e.hash_mask;e.insert&&(e.ins_h=(e.ins_h<<e.hash_shift^e.window[o+P-1])&e.hash_mask,e.prev[o&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=o,o++,e.insert--,!(e.lookahead+e.insert<P)););}while(e.lookahead<se&&e.strm.avail_in!==0)}function kd(e,t){var r=65535;for(r>e.pending_buf_size-5&&(r=e.pending_buf_size-5);;){if(e.lookahead<=1){if(Zt(e),e.lookahead===0&&t===Xe)return U;if(e.lookahead===0)break}e.strstart+=e.lookahead,e.lookahead=0;var n=e.block_start+r;if((e.strstart===0||e.strstart>=n)&&(e.lookahead=e.strstart-n,e.strstart=n,H(e,!1),e.strm.avail_out===0)||e.strstart-e.block_start>=e.w_size-se&&(H(e,!1),e.strm.avail_out===0))return U}return e.insert=0,t===Me?(H(e,!0),e.strm.avail_out===0?et:wt):(e.strstart>e.block_start&&(H(e,!1),e.strm.avail_out===0),U)}function Ci(e,t){for(var r,n;;){if(e.lookahead<se){if(Zt(e),e.lookahead<se&&t===Xe)return U;if(e.lookahead===0)break}if(r=0,e.lookahead>=P&&(e.ins_h=(e.ins_h<<e.hash_shift^e.window[e.strstart+P-1])&e.hash_mask,r=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart),r!==0&&e.strstart-r<=e.w_size-se&&(e.match_length=qs(e,r)),e.match_length>=P)if(n=De(e,e.strstart-e.match_start,e.match_length-P),e.lookahead-=e.match_length,e.match_length<=e.max_lazy_match&&e.lookahead>=P){e.match_length--;do e.strstart++,e.ins_h=(e.ins_h<<e.hash_shift^e.window[e.strstart+P-1])&e.hash_mask,r=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart;while(--e.match_length!==0);e.strstart++}else e.strstart+=e.match_length,e.match_length=0,e.ins_h=e.window[e.strstart],e.ins_h=(e.ins_h<<e.hash_shift^e.window[e.strstart+1])&e.hash_mask;else n=De(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++;if(n&&(H(e,!1),e.strm.avail_out===0))return U}return e.insert=e.strstart<P-1?e.strstart:P-1,t===Me?(H(e,!0),e.strm.avail_out===0?et:wt):e.last_lit&&(H(e,!1),e.strm.avail_out===0)?U:Bt}function bt(e,t){for(var r,n,i;;){if(e.lookahead<se){if(Zt(e),e.lookahead<se&&t===Xe)return U;if(e.lookahead===0)break}if(r=0,e.lookahead>=P&&(e.ins_h=(e.ins_h<<e.hash_shift^e.window[e.strstart+P-1])&e.hash_mask,r=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart),e.prev_length=e.match_length,e.prev_match=e.match_start,e.match_length=P-1,r!==0&&e.prev_length<e.max_lazy_match&&e.strstart-r<=e.w_size-se&&(e.match_length=qs(e,r),e.match_length<=5&&(e.strategy===hd||e.match_length===P&&e.strstart-e.match_start>4096)&&(e.match_length=P-1)),e.prev_length>=P&&e.match_length<=e.prev_length){i=e.strstart+e.lookahead-P,n=De(e,e.strstart-1-e.prev_match,e.prev_length-P),e.lookahead-=e.prev_length-1,e.prev_length-=2;do++e.strstart<=i&&(e.ins_h=(e.ins_h<<e.hash_shift^e.window[e.strstart+P-1])&e.hash_mask,r=e.prev[e.strstart&e.w_mask]=e.head[e.ins_h],e.head[e.ins_h]=e.strstart);while(--e.prev_length!==0);if(e.match_available=0,e.match_length=P-1,e.strstart++,n&&(H(e,!1),e.strm.avail_out===0))return U}else if(e.match_available){if(n=De(e,0,e.window[e.strstart-1]),n&&H(e,!1),e.strstart++,e.lookahead--,e.strm.avail_out===0)return U}else e.match_available=1,e.strstart++,e.lookahead--}return e.match_available&&(n=De(e,0,e.window[e.strstart-1]),e.match_available=0),e.insert=e.strstart<P-1?e.strstart:P-1,t===Me?(H(e,!0),e.strm.avail_out===0?et:wt):e.last_lit&&(H(e,!1),e.strm.avail_out===0)?U:Bt}function Rd(e,t){for(var r,n,i,a,o=e.window;;){if(e.lookahead<=$e){if(Zt(e),e.lookahead<=$e&&t===Xe)return U;if(e.lookahead===0)break}if(e.match_length=0,e.lookahead>=P&&e.strstart>0&&(i=e.strstart-1,n=o[i],n===o[++i]&&n===o[++i]&&n===o[++i])){a=e.strstart+$e;do;while(n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&n===o[++i]&&i<a);e.match_length=$e-(a-i),e.match_length>e.lookahead&&(e.match_length=e.lookahead)}if(e.match_length>=P?(r=De(e,1,e.match_length-P),e.lookahead-=e.match_length,e.strstart+=e.match_length,e.match_length=0):(r=De(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++),r&&(H(e,!1),e.strm.avail_out===0))return U}return e.insert=0,t===Me?(H(e,!0),e.strm.avail_out===0?et:wt):e.last_lit&&(H(e,!1),e.strm.avail_out===0)?U:Bt}function Od(e,t){for(var r;;){if(e.lookahead===0&&(Zt(e),e.lookahead===0)){if(t===Xe)return U;break}if(e.match_length=0,r=De(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++,r&&(H(e,!1),e.strm.avail_out===0))return U}return e.insert=0,t===Me?(H(e,!0),e.strm.avail_out===0?et:wt):e.last_lit&&(H(e,!1),e.strm.avail_out===0)?U:Bt}function we(e,t,r,n,i){this.good_length=e,this.max_lazy=t,this.nice_length=r,this.max_chain=n,this.func=i}var _t;_t=[new we(0,0,0,0,kd),new we(4,4,8,4,Ci),new we(4,5,16,8,Ci),new we(4,6,32,32,Ci),new we(4,4,16,16,bt),new we(8,16,32,32,bt),new we(8,16,128,128,bt),new we(8,32,128,256,bt),new we(32,128,258,1024,bt),new we(32,258,258,4096,bt)];function Id(e){e.window_size=2*e.w_size,tt(e.head),e.max_lazy_match=_t[e.level].max_lazy,e.good_match=_t[e.level].good_length,e.nice_match=_t[e.level].nice_length,e.max_chain_length=_t[e.level].max_chain,e.strstart=0,e.block_start=0,e.lookahead=0,e.insert=0,e.match_length=e.prev_length=P-1,e.match_available=0,e.ins_h=0}function Td(){this.strm=null,this.status=0,this.pending_buf=null,this.pending_buf_size=0,this.pending_out=0,this.pending=0,this.wrap=0,this.gzhead=null,this.gzindex=0,this.method=Ti,this.last_flush=-1,this.w_size=0,this.w_bits=0,this.w_mask=0,this.window=null,this.window_size=0,this.prev=null,this.head=null,this.ins_h=0,this.hash_size=0,this.hash_bits=0,this.hash_mask=0,this.hash_shift=0,this.block_start=0,this.match_length=0,this.prev_match=0,this.match_available=0,this.strstart=0,this.match_start=0,this.lookahead=0,this.prev_length=0,this.max_chain_length=0,this.max_lazy_match=0,this.level=0,this.strategy=0,this.good_match=0,this.nice_match=0,this.dyn_ltree=new oe(md*2),this.dyn_dtree=new oe((2*bd+1)*2),this.bl_tree=new oe((2*_d+1)*2),tt(this.dyn_ltree),tt(this.dyn_dtree),tt(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new oe(xd+1),this.heap=new oe(2*Pi+1),tt(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new oe(2*Pi+1),tt(this.depth),this.l_buf=0,this.lit_bufsize=0,this.last_lit=0,this.d_buf=0,this.opt_len=0,this.static_len=0,this.matches=0,this.insert=0,this.bi_buf=0,this.bi_valid=0}function Pd(e){var t;return!e||!e.state?Ue(e,Le):(e.total_in=e.total_out=0,e.data_type=yd,t=e.state,t.pending=0,t.pending_out=0,t.wrap<0&&(t.wrap=-t.wrap),t.status=t.wrap?ji:Qe,e.adler=t.wrap===2?0:1,t.last_flush=Xe,nd(t),Ne)}function Hs(e){var t=Pd(e);return t===Ne&&Id(e.state),t}function jd(e,t,r,n,i,a){if(!e)return Le;var o=1;if(t===ud&&(t=6),n<0?(o=0,n=-n):n>15&&(o=2,n-=16),i<1||i>gd||r!==Ti||n<8||n>15||t<0||t>9||a<0||a>pd)return Ue(e,Le);n===8&&(n=9);var s=new Td;return e.state=s,s.strm=e,s.wrap=o,s.gzhead=null,s.w_bits=n,s.w_size=1<<s.w_bits,s.w_mask=s.w_size-1,s.hash_bits=i+7,s.hash_size=1<<s.hash_bits,s.hash_mask=s.hash_size-1,s.hash_shift=~~((s.hash_bits+P-1)/P),s.window=new mr(s.w_size*2),s.head=new oe(s.hash_size),s.prev=new oe(s.w_size),s.lit_bufsize=1<<i+6,s.pending_buf_size=s.lit_bufsize*4,s.pending_buf=new mr(s.pending_buf_size),s.d_buf=1*s.lit_bufsize,s.l_buf=3*s.lit_bufsize,s.level=t,s.strategy=a,s.method=r,Hs(e)}function Fd(e,t){var r,n,i,a;if(!e||!e.state||t>Bs||t<0)return e?Ue(e,Le):Le;if(n=e.state,!e.output||!e.input&&e.avail_in!==0||n.status===Ut&&t!==Me)return Ue(e,e.avail_out===0?Ii:Le);if(n.strm=e,r=n.last_flush,n.last_flush=t,n.status===ji)if(n.wrap===2)e.adler=0,T(n,31),T(n,139),T(n,8),n.gzhead?(T(n,(n.gzhead.text?1:0)+(n.gzhead.hcrc?2:0)+(n.gzhead.extra?4:0)+(n.gzhead.name?8:0)+(n.gzhead.comment?16:0)),T(n,n.gzhead.time&255),T(n,n.gzhead.time>>8&255),T(n,n.gzhead.time>>16&255),T(n,n.gzhead.time>>24&255),T(n,n.level===9?2:n.strategy>=Ar||n.level<2?4:0),T(n,n.gzhead.os&255),n.gzhead.extra&&n.gzhead.extra.length&&(T(n,n.gzhead.extra.length&255),T(n,n.gzhead.extra.length>>8&255)),n.gzhead.hcrc&&(e.adler=z(e.adler,n.pending_buf,n.pending,0)),n.gzindex=0,n.status=Fi):(T(n,0),T(n,0),T(n,0),T(n,0),T(n,0),T(n,n.level===9?2:n.strategy>=Ar||n.level<2?4:0),T(n,Sd),n.status=Qe);else{var o=Ti+(n.w_bits-8<<4)<<8,s=-1;n.strategy>=Ar||n.level<2?s=0:n.level<6?s=1:n.level===6?s=2:s=3,o|=s<<6,n.strstart!==0&&(o|=Ed),o+=31-o%31,n.status=Qe,zt(n,o),n.strstart!==0&&(zt(n,e.adler>>>16),zt(n,e.adler&65535)),e.adler=1}if(n.status===Fi)if(n.gzhead.extra){for(i=n.pending;n.gzindex<(n.gzhead.extra.length&65535)&&!(n.pending===n.pending_buf_size&&(n.gzhead.hcrc&&n.pending>i&&(e.adler=z(e.adler,n.pending_buf,n.pending-i,i)),Be(e),i=n.pending,n.pending===n.pending_buf_size));)T(n,n.gzhead.extra[n.gzindex]&255),n.gzindex++;n.gzhead.hcrc&&n.pending>i&&(e.adler=z(e.adler,n.pending_buf,n.pending-i,i)),n.gzindex===n.gzhead.extra.length&&(n.gzindex=0,n.status=kr)}else n.status=kr;if(n.status===kr)if(n.gzhead.name){i=n.pending;do{if(n.pending===n.pending_buf_size&&(n.gzhead.hcrc&&n.pending>i&&(e.adler=z(e.adler,n.pending_buf,n.pending-i,i)),Be(e),i=n.pending,n.pending===n.pending_buf_size)){a=1;break}n.gzindex<n.gzhead.name.length?a=n.gzhead.name.charCodeAt(n.gzindex++)&255:a=0,T(n,a)}while(a!==0);n.gzhead.hcrc&&n.pending>i&&(e.adler=z(e.adler,n.pending_buf,n.pending-i,i)),a===0&&(n.gzindex=0,n.status=Rr)}else n.status=Rr;if(n.status===Rr)if(n.gzhead.comment){i=n.pending;do{if(n.pending===n.pending_buf_size&&(n.gzhead.hcrc&&n.pending>i&&(e.adler=z(e.adler,n.pending_buf,n.pending-i,i)),Be(e),i=n.pending,n.pending===n.pending_buf_size)){a=1;break}n.gzindex<n.gzhead.comment.length?a=n.gzhead.comment.charCodeAt(n.gzindex++)&255:a=0,T(n,a)}while(a!==0);n.gzhead.hcrc&&n.pending>i&&(e.adler=z(e.adler,n.pending_buf,n.pending-i,i)),a===0&&(n.status=Or)}else n.status=Or;if(n.status===Or&&(n.gzhead.hcrc?(n.pending+2>n.pending_buf_size&&Be(e),n.pending+2<=n.pending_buf_size&&(T(n,e.adler&255),T(n,e.adler>>8&255),e.adler=0,n.status=Qe)):n.status=Qe),n.pending!==0){if(Be(e),e.avail_out===0)return n.last_flush=-1,Ne}else if(e.avail_in===0&&Zs(t)<=Zs(r)&&t!==Me)return Ue(e,Ii);if(n.status===Ut&&e.avail_in!==0)return Ue(e,Ii);if(e.avail_in!==0||n.lookahead!==0||t!==Xe&&n.status!==Ut){var f=n.strategy===Ar?Od(n,t):n.strategy===dd?Rd(n,t):_t[n.level].func(n,t);if((f===et||f===wt)&&(n.status=Ut),f===U||f===et)return e.avail_out===0&&(n.last_flush=-1),Ne;if(f===Bt&&(t===cd?id(n):t!==Bs&&(Us(n,0,0,!1),t===fd&&(tt(n.head),n.lookahead===0&&(n.strstart=0,n.block_start=0,n.insert=0))),Be(e),e.avail_out===0))return n.last_flush=-1,Ne}return t!==Me?Ne:n.wrap<=0?zs:(n.wrap===2?(T(n,e.adler&255),T(n,e.adler>>8&255),T(n,e.adler>>16&255),T(n,e.adler>>24&255),T(n,e.total_in&255),T(n,e.total_in>>8&255),T(n,e.total_in>>16&255),T(n,e.total_in>>24&255)):(zt(n,e.adler>>>16),zt(n,e.adler&65535)),Be(e),n.wrap>0&&(n.wrap=-n.wrap),n.pending!==0?Ne:zs)}function Cd(e){var t;return!e||!e.state?Le:(t=e.state.status,t!==ji&&t!==Fi&&t!==kr&&t!==Rr&&t!==Or&&t!==Qe&&t!==Ut?Ue(e,Le):(e.state=null,t===Qe?Ue(e,ld):Ne))}var Ir=30,Dd=12;function Md(e,t){var r,n,i,a,o,s,f,c,l,h,d,u,p,y,w,b,m,x,v,S,O,_,A,I,k;r=e.state,n=e.next_in,I=e.input,i=n+(e.avail_in-5),a=e.next_out,k=e.output,o=a-(t-e.avail_out),s=a+(e.avail_out-257),f=r.dmax,c=r.wsize,l=r.whave,h=r.wnext,d=r.window,u=r.hold,p=r.bits,y=r.lencode,w=r.distcode,b=(1<<r.lenbits)-1,m=(1<<r.distbits)-1;e:do{p<15&&(u+=I[n++]<<p,p+=8,u+=I[n++]<<p,p+=8),x=y[u&b];t:for(;;){if(v=x>>>24,u>>>=v,p-=v,v=x>>>16&255,v===0)k[a++]=x&65535;else if(v&16){S=x&65535,v&=15,v&&(p<v&&(u+=I[n++]<<p,p+=8),S+=u&(1<<v)-1,u>>>=v,p-=v),p<15&&(u+=I[n++]<<p,p+=8,u+=I[n++]<<p,p+=8),x=w[u&m];r:for(;;){if(v=x>>>24,u>>>=v,p-=v,v=x>>>16&255,v&16){if(O=x&65535,v&=15,p<v&&(u+=I[n++]<<p,p+=8,p<v&&(u+=I[n++]<<p,p+=8)),O+=u&(1<<v)-1,O>f){e.msg="invalid distance too far back",r.mode=Ir;break e}if(u>>>=v,p-=v,v=a-o,O>v){if(v=O-v,v>l&&r.sane){e.msg="invalid distance too far back",r.mode=Ir;break e}if(_=0,A=d,h===0){if(_+=c-v,v<S){S-=v;do k[a++]=d[_++];while(--v);_=a-O,A=k}}else if(h<v){if(_+=c+h-v,v-=h,v<S){S-=v;do k[a++]=d[_++];while(--v);if(_=0,h<S){v=h,S-=v;do k[a++]=d[_++];while(--v);_=a-O,A=k}}}else if(_+=h-v,v<S){S-=v;do k[a++]=d[_++];while(--v);_=a-O,A=k}for(;S>2;)k[a++]=A[_++],k[a++]=A[_++],k[a++]=A[_++],S-=3;S&&(k[a++]=A[_++],S>1&&(k[a++]=A[_++]))}else{_=a-O;do k[a++]=k[_++],k[a++]=k[_++],k[a++]=k[_++],S-=3;while(S>2);S&&(k[a++]=k[_++],S>1&&(k[a++]=k[_++]))}}else if((v&64)===0){x=w[(x&65535)+(u&(1<<v)-1)];continue r}else{e.msg="invalid distance code",r.mode=Ir;break e}break}}else if((v&64)===0){x=y[(x&65535)+(u&(1<<v)-1)];continue t}else if(v&32){r.mode=Dd;break e}else{e.msg="invalid literal/length code",r.mode=Ir;break e}break}}while(n<i&&a<s);S=p>>3,n-=S,p-=S<<3,u&=(1<<p)-1,e.next_in=n,e.next_out=a,e.avail_in=n<i?5+(i-n):5-(n-i),e.avail_out=a<s?257+(s-a):257-(a-s),r.hold=u,r.bits=p}var mt=15,Ks=852,Ws=592,Vs=0,Di=1,Gs=2,Nd=[3,4,5,6,7,8,9,10,11,13,15,17,19,23,27,31,35,43,51,59,67,83,99,115,131,163,195,227,258,0,0],Ld=[16,16,16,16,16,16,16,16,17,17,17,17,18,18,18,18,19,19,19,19,20,20,20,20,21,21,21,21,16,72,78],$d=[1,2,3,4,5,7,9,13,17,25,33,49,65,97,129,193,257,385,513,769,1025,1537,2049,3073,4097,6145,8193,12289,16385,24577,0,0],Ud=[16,16,16,16,17,17,18,18,19,19,20,20,21,21,22,22,23,23,24,24,25,25,26,26,27,27,28,28,29,29,64,64];function qt(e,t,r,n,i,a,o,s){var f=s.bits,c=0,l=0,h=0,d=0,u=0,p=0,y=0,w=0,b=0,m=0,x,v,S,O,_,A=null,I=0,k,F=new oe(mt+1),Z=new oe(mt+1),V=null,re=0,Ze,Y,fe;for(c=0;c<=mt;c++)F[c]=0;for(l=0;l<n;l++)F[t[r+l]]++;for(u=f,d=mt;d>=1&&F[d]===0;d--);if(u>d&&(u=d),d===0)return i[a++]=1<<24|64<<16|0,i[a++]=1<<24|64<<16|0,s.bits=1,0;for(h=1;h<d&&F[h]===0;h++);for(u<h&&(u=h),w=1,c=1;c<=mt;c++)if(w<<=1,w-=F[c],w<0)return-1;if(w>0&&(e===Vs||d!==1))return-1;for(Z[1]=0,c=1;c<mt;c++)Z[c+1]=Z[c]+F[c];for(l=0;l<n;l++)t[r+l]!==0&&(o[Z[t[r+l]]++]=l);if(e===Vs?(A=V=o,k=19):e===Di?(A=Nd,I-=257,V=Ld,re-=257,k=256):(A=$d,V=Ud,k=-1),m=0,l=0,c=h,_=a,p=u,y=0,S=-1,b=1<<u,O=b-1,e===Di&&b>Ks||e===Gs&&b>Ws)return 1;for(;;){Ze=c-y,o[l]<k?(Y=0,fe=o[l]):o[l]>k?(Y=V[re+o[l]],fe=A[I+o[l]]):(Y=96,fe=0),x=1<<c-y,v=1<<p,h=v;do v-=x,i[_+(m>>y)+v]=Ze<<24|Y<<16|fe|0;while(v!==0);for(x=1<<c-1;m&x;)x>>=1;if(x!==0?(m&=x-1,m+=x):m=0,l++,--F[c]===0){if(c===d)break;c=t[r+o[l]]}if(c>u&&(m&O)!==S){for(y===0&&(y=u),_+=h,p=c-y,w=1<<p;p+y<d&&(w-=F[p+y],!(w<=0));)p++,w<<=1;if(b+=1<<p,e===Di&&b>Ks||e===Gs&&b>Ws)return 1;S=m&O,i[S]=u<<24|p<<16|_-a|0}}return m!==0&&(i[_+m]=c-y<<24|64<<16|0),s.bits=u,0}var Bd=0,Ys=1,Js=2,Xs=4,zd=5,Tr=6,Ht=0,Zd=1,qd=2,ze=-2,Hd=-3,Kd=-4,Wd=-5,Qs=8,ec=1,tc=2,rc=3,nc=4,ic=5,ac=6,oc=7,sc=8,cc=9,fc=10,lc=11,Oe=12,Mi=13,uc=14,Ni=15,hc=16,dc=17,pc=18,yc=19,Pr=20,jr=21,gc=22,vc=23,wc=24,bc=25,_c=26,Li=27,mc=28,xc=29,C=30,Vd=31,Gd=32,Yd=852,Jd=592;function Ec(e){return(e>>>24&255)+(e>>>8&65280)+((e&65280)<<8)+((e&255)<<24)}function Xd(){this.mode=0,this.last=!1,this.wrap=0,this.havedict=!1,this.flags=0,this.dmax=0,this.check=0,this.total=0,this.head=null,this.wbits=0,this.wsize=0,this.whave=0,this.wnext=0,this.window=null,this.hold=0,this.bits=0,this.length=0,this.offset=0,this.extra=0,this.lencode=null,this.distcode=null,this.lenbits=0,this.distbits=0,this.ncode=0,this.nlen=0,this.ndist=0,this.have=0,this.next=null,this.lens=new oe(320),this.work=new oe(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function Qd(e){var t;return!e||!e.state?ze:(t=e.state,e.total_in=e.total_out=t.total=0,e.msg="",t.wrap&&(e.adler=t.wrap&1),t.mode=ec,t.last=0,t.havedict=0,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=t.lendyn=new xr(Yd),t.distcode=t.distdyn=new xr(Jd),t.sane=1,t.back=-1,Ht)}function Sc(e){var t;return!e||!e.state?ze:(t=e.state,t.wsize=0,t.whave=0,t.wnext=0,Qd(e))}function ep(e,t){var r,n;return!e||!e.state||(n=e.state,t<0?(r=0,t=-t):(r=(t>>4)+1,t<48&&(t&=15)),t&&(t<8||t>15))?ze:(n.window!==null&&n.wbits!==t&&(n.window=null),n.wrap=r,n.wbits=t,Sc(e))}function tp(e,t){var r,n;return e?(n=new Xd,e.state=n,n.window=null,r=ep(e,t),r!==Ht&&(e.state=null),r):ze}var Ac=!0,$i,Ui;function rp(e){if(Ac){var t;for($i=new xr(512),Ui=new xr(32),t=0;t<144;)e.lens[t++]=8;for(;t<256;)e.lens[t++]=9;for(;t<280;)e.lens[t++]=7;for(;t<288;)e.lens[t++]=8;for(qt(Ys,e.lens,0,288,$i,0,e.work,{bits:9}),t=0;t<32;)e.lens[t++]=5;qt(Js,e.lens,0,32,Ui,0,e.work,{bits:5}),Ac=!1}e.lencode=$i,e.lenbits=9,e.distcode=Ui,e.distbits=5}function np(e,t,r,n){var i,a=e.state;return a.window===null&&(a.wsize=1<<a.wbits,a.wnext=0,a.whave=0,a.window=new mr(a.wsize)),n>=a.wsize?(ke(a.window,t,r-a.wsize,a.wsize,0),a.wnext=0,a.whave=a.wsize):(i=a.wsize-a.wnext,i>n&&(i=n),ke(a.window,t,r-n,i,a.wnext),n-=i,n?(ke(a.window,t,r-n,n,0),a.wnext=n,a.whave=a.wsize):(a.wnext+=i,a.wnext===a.wsize&&(a.wnext=0),a.whave<a.wsize&&(a.whave+=i))),0}function ip(e,t){var r,n,i,a,o,s,f,c,l,h,d,u,p,y,w=0,b,m,x,v,S,O,_,A,I=new mr(4),k,F,Z=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15];if(!e||!e.state||!e.output||!e.input&&e.avail_in!==0)return ze;r=e.state,r.mode===Oe&&(r.mode=Mi),o=e.next_out,i=e.output,f=e.avail_out,a=e.next_in,n=e.input,s=e.avail_in,c=r.hold,l=r.bits,h=s,d=f,A=Ht;e:for(;;)switch(r.mode){case ec:if(r.wrap===0){r.mode=Mi;break}for(;l<16;){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}if(r.wrap&2&&c===35615){r.check=0,I[0]=c&255,I[1]=c>>>8&255,r.check=z(r.check,I,2,0),c=0,l=0,r.mode=tc;break}if(r.flags=0,r.head&&(r.head.done=!1),!(r.wrap&1)||(((c&255)<<8)+(c>>8))%31){e.msg="incorrect header check",r.mode=C;break}if((c&15)!==Qs){e.msg="unknown compression method",r.mode=C;break}if(c>>>=4,l-=4,_=(c&15)+8,r.wbits===0)r.wbits=_;else if(_>r.wbits){e.msg="invalid window size",r.mode=C;break}r.dmax=1<<_,e.adler=r.check=1,r.mode=c&512?fc:Oe,c=0,l=0;break;case tc:for(;l<16;){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}if(r.flags=c,(r.flags&255)!==Qs){e.msg="unknown compression method",r.mode=C;break}if(r.flags&57344){e.msg="unknown header flags set",r.mode=C;break}r.head&&(r.head.text=c>>8&1),r.flags&512&&(I[0]=c&255,I[1]=c>>>8&255,r.check=z(r.check,I,2,0)),c=0,l=0,r.mode=rc;case rc:for(;l<32;){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}r.head&&(r.head.time=c),r.flags&512&&(I[0]=c&255,I[1]=c>>>8&255,I[2]=c>>>16&255,I[3]=c>>>24&255,r.check=z(r.check,I,4,0)),c=0,l=0,r.mode=nc;case nc:for(;l<16;){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}r.head&&(r.head.xflags=c&255,r.head.os=c>>8),r.flags&512&&(I[0]=c&255,I[1]=c>>>8&255,r.check=z(r.check,I,2,0)),c=0,l=0,r.mode=ic;case ic:if(r.flags&1024){for(;l<16;){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}r.length=c,r.head&&(r.head.extra_len=c),r.flags&512&&(I[0]=c&255,I[1]=c>>>8&255,r.check=z(r.check,I,2,0)),c=0,l=0}else r.head&&(r.head.extra=null);r.mode=ac;case ac:if(r.flags&1024&&(u=r.length,u>s&&(u=s),u&&(r.head&&(_=r.head.extra_len-r.length,r.head.extra||(r.head.extra=new Array(r.head.extra_len)),ke(r.head.extra,n,a,u,_)),r.flags&512&&(r.check=z(r.check,n,u,a)),s-=u,a+=u,r.length-=u),r.length))break e;r.length=0,r.mode=oc;case oc:if(r.flags&2048){if(s===0)break e;u=0;do _=n[a+u++],r.head&&_&&r.length<65536&&(r.head.name+=String.fromCharCode(_));while(_&&u<s);if(r.flags&512&&(r.check=z(r.check,n,u,a)),s-=u,a+=u,_)break e}else r.head&&(r.head.name=null);r.length=0,r.mode=sc;case sc:if(r.flags&4096){if(s===0)break e;u=0;do _=n[a+u++],r.head&&_&&r.length<65536&&(r.head.comment+=String.fromCharCode(_));while(_&&u<s);if(r.flags&512&&(r.check=z(r.check,n,u,a)),s-=u,a+=u,_)break e}else r.head&&(r.head.comment=null);r.mode=cc;case cc:if(r.flags&512){for(;l<16;){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}if(c!==(r.check&65535)){e.msg="header crc mismatch",r.mode=C;break}c=0,l=0}r.head&&(r.head.hcrc=r.flags>>9&1,r.head.done=!0),e.adler=r.check=0,r.mode=Oe;break;case fc:for(;l<32;){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}e.adler=r.check=Ec(c),c=0,l=0,r.mode=lc;case lc:if(r.havedict===0)return e.next_out=o,e.avail_out=f,e.next_in=a,e.avail_in=s,r.hold=c,r.bits=l,qd;e.adler=r.check=1,r.mode=Oe;case Oe:if(t===zd||t===Tr)break e;case Mi:if(r.last){c>>>=l&7,l-=l&7,r.mode=Li;break}for(;l<3;){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}switch(r.last=c&1,c>>>=1,l-=1,c&3){case 0:r.mode=uc;break;case 1:if(rp(r),r.mode=Pr,t===Tr){c>>>=2,l-=2;break e}break;case 2:r.mode=dc;break;case 3:e.msg="invalid block type",r.mode=C}c>>>=2,l-=2;break;case uc:for(c>>>=l&7,l-=l&7;l<32;){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}if((c&65535)!==(c>>>16^65535)){e.msg="invalid stored block lengths",r.mode=C;break}if(r.length=c&65535,c=0,l=0,r.mode=Ni,t===Tr)break e;case Ni:r.mode=hc;case hc:if(u=r.length,u){if(u>s&&(u=s),u>f&&(u=f),u===0)break e;ke(i,n,a,u,o),s-=u,a+=u,f-=u,o+=u,r.length-=u;break}r.mode=Oe;break;case dc:for(;l<14;){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}if(r.nlen=(c&31)+257,c>>>=5,l-=5,r.ndist=(c&31)+1,c>>>=5,l-=5,r.ncode=(c&15)+4,c>>>=4,l-=4,r.nlen>286||r.ndist>30){e.msg="too many length or distance symbols",r.mode=C;break}r.have=0,r.mode=pc;case pc:for(;r.have<r.ncode;){for(;l<3;){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}r.lens[Z[r.have++]]=c&7,c>>>=3,l-=3}for(;r.have<19;)r.lens[Z[r.have++]]=0;if(r.lencode=r.lendyn,r.lenbits=7,k={bits:r.lenbits},A=qt(Bd,r.lens,0,19,r.lencode,0,r.work,k),r.lenbits=k.bits,A){e.msg="invalid code lengths set",r.mode=C;break}r.have=0,r.mode=yc;case yc:for(;r.have<r.nlen+r.ndist;){for(;w=r.lencode[c&(1<<r.lenbits)-1],b=w>>>24,m=w>>>16&255,x=w&65535,!(b<=l);){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}if(x<16)c>>>=b,l-=b,r.lens[r.have++]=x;else{if(x===16){for(F=b+2;l<F;){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}if(c>>>=b,l-=b,r.have===0){e.msg="invalid bit length repeat",r.mode=C;break}_=r.lens[r.have-1],u=3+(c&3),c>>>=2,l-=2}else if(x===17){for(F=b+3;l<F;){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}c>>>=b,l-=b,_=0,u=3+(c&7),c>>>=3,l-=3}else{for(F=b+7;l<F;){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}c>>>=b,l-=b,_=0,u=11+(c&127),c>>>=7,l-=7}if(r.have+u>r.nlen+r.ndist){e.msg="invalid bit length repeat",r.mode=C;break}for(;u--;)r.lens[r.have++]=_}}if(r.mode===C)break;if(r.lens[256]===0){e.msg="invalid code -- missing end-of-block",r.mode=C;break}if(r.lenbits=9,k={bits:r.lenbits},A=qt(Ys,r.lens,0,r.nlen,r.lencode,0,r.work,k),r.lenbits=k.bits,A){e.msg="invalid literal/lengths set",r.mode=C;break}if(r.distbits=6,r.distcode=r.distdyn,k={bits:r.distbits},A=qt(Js,r.lens,r.nlen,r.ndist,r.distcode,0,r.work,k),r.distbits=k.bits,A){e.msg="invalid distances set",r.mode=C;break}if(r.mode=Pr,t===Tr)break e;case Pr:r.mode=jr;case jr:if(s>=6&&f>=258){e.next_out=o,e.avail_out=f,e.next_in=a,e.avail_in=s,r.hold=c,r.bits=l,Md(e,d),o=e.next_out,i=e.output,f=e.avail_out,a=e.next_in,n=e.input,s=e.avail_in,c=r.hold,l=r.bits,r.mode===Oe&&(r.back=-1);break}for(r.back=0;w=r.lencode[c&(1<<r.lenbits)-1],b=w>>>24,m=w>>>16&255,x=w&65535,!(b<=l);){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}if(m&&(m&240)===0){for(v=b,S=m,O=x;w=r.lencode[O+((c&(1<<v+S)-1)>>v)],b=w>>>24,m=w>>>16&255,x=w&65535,!(v+b<=l);){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}c>>>=v,l-=v,r.back+=v}if(c>>>=b,l-=b,r.back+=b,r.length=x,m===0){r.mode=_c;break}if(m&32){r.back=-1,r.mode=Oe;break}if(m&64){e.msg="invalid literal/length code",r.mode=C;break}r.extra=m&15,r.mode=gc;case gc:if(r.extra){for(F=r.extra;l<F;){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}r.length+=c&(1<<r.extra)-1,c>>>=r.extra,l-=r.extra,r.back+=r.extra}r.was=r.length,r.mode=vc;case vc:for(;w=r.distcode[c&(1<<r.distbits)-1],b=w>>>24,m=w>>>16&255,x=w&65535,!(b<=l);){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}if((m&240)===0){for(v=b,S=m,O=x;w=r.distcode[O+((c&(1<<v+S)-1)>>v)],b=w>>>24,m=w>>>16&255,x=w&65535,!(v+b<=l);){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}c>>>=v,l-=v,r.back+=v}if(c>>>=b,l-=b,r.back+=b,m&64){e.msg="invalid distance code",r.mode=C;break}r.offset=x,r.extra=m&15,r.mode=wc;case wc:if(r.extra){for(F=r.extra;l<F;){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}r.offset+=c&(1<<r.extra)-1,c>>>=r.extra,l-=r.extra,r.back+=r.extra}if(r.offset>r.dmax){e.msg="invalid distance too far back",r.mode=C;break}r.mode=bc;case bc:if(f===0)break e;if(u=d-f,r.offset>u){if(u=r.offset-u,u>r.whave&&r.sane){e.msg="invalid distance too far back",r.mode=C;break}u>r.wnext?(u-=r.wnext,p=r.wsize-u):p=r.wnext-u,u>r.length&&(u=r.length),y=r.window}else y=i,p=o-r.offset,u=r.length;u>f&&(u=f),f-=u,r.length-=u;do i[o++]=y[p++];while(--u);r.length===0&&(r.mode=jr);break;case _c:if(f===0)break e;i[o++]=r.length,f--,r.mode=jr;break;case Li:if(r.wrap){for(;l<32;){if(s===0)break e;s--,c|=n[a++]<<l,l+=8}if(d-=f,e.total_out+=d,r.total+=d,d&&(e.adler=r.check=r.flags?z(r.check,i,d,o-d):Oi(r.check,i,d,o-d)),d=f,(r.flags?c:Ec(c))!==r.check){e.msg="incorrect data check",r.mode=C;break}c=0,l=0}r.mode=mc;case mc:if(r.wrap&&r.flags){for(;l<32;){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}if(c!==(r.total&4294967295)){e.msg="incorrect length check",r.mode=C;break}c=0,l=0}r.mode=xc;case xc:A=Zd;break e;case C:A=Hd;break e;case Vd:return Kd;case Gd:default:return ze}return e.next_out=o,e.avail_out=f,e.next_in=a,e.avail_in=s,r.hold=c,r.bits=l,(r.wsize||d!==e.avail_out&&r.mode<C&&(r.mode<Li||t!==Xs))&&np(e,e.output,e.next_out,d-e.avail_out),h-=e.avail_in,d-=e.avail_out,e.total_in+=h,e.total_out+=d,r.total+=d,r.wrap&&d&&(e.adler=r.check=r.flags?z(r.check,i,d,e.next_out-d):Oi(r.check,i,d,e.next_out-d)),e.data_type=r.bits+(r.last?64:0)+(r.mode===Oe?128:0)+(r.mode===Pr||r.mode===Ni?256:0),(h===0&&d===0||t===Xs)&&A===Ht&&(A=Wd),A}function ap(e){if(!e||!e.state)return ze;var t=e.state;return t.window&&(t.window=null),e.state=null,Ht}var Bi=0,xt=1,Fr=2,Kt=3,Cr=4,Et=5,Wt=6,Vt=7,kc=0,Rc=1,Oc=2,Ic=3,zi=4,Tc=5,op=6,Dr=0,Pc=1,jc=2,sp=-1,cp=-2,fp=-3,Fc=-5,lp=0,up=1,hp=9,dp=-1,pp=1,yp=2,gp=3,vp=4,wp=0,bp=0,_p=1,mp=2,Cc=8;function ce(e){if(e<xt||e>Vt)throw new TypeError("Bad argument");this.mode=e,this.init_done=!1,this.write_in_progress=!1,this.pending_close=!1,this.windowBits=0,this.level=0,this.memLevel=0,this.strategy=0,this.dictionary=null}ce.prototype.init=function(e,t,r,n,i){this.windowBits=e,this.level=t,this.memLevel=r,this.strategy=n,(this.mode===Kt||this.mode===Cr)&&(this.windowBits+=16),this.mode===Vt&&(this.windowBits+=32),(this.mode===Et||this.mode===Wt)&&(this.windowBits=-this.windowBits),this.strm=new Uh;var a;switch(this.mode){case xt:case Kt:case Et:a=jd(this.strm,this.level,Cc,this.windowBits,this.memLevel,this.strategy);break;case Fr:case Cr:case Wt:case Vt:a=tp(this.strm,this.windowBits);break;default:throw new Error("Unknown mode "+this.mode)}if(a!==Dr){this._error(a);return}this.write_in_progress=!1,this.init_done=!0},ce.prototype.params=function(){throw new Error("deflateParams Not supported")},ce.prototype._writeCheck=function(){if(!this.init_done)throw new Error("write before init");if(this.mode===Bi)throw new Error("already finalized");if(this.write_in_progress)throw new Error("write already in progress");if(this.pending_close)throw new Error("close is pending")},ce.prototype.write=function(e,t,r,n,i,a,o){this._writeCheck(),this.write_in_progress=!0;var s=this;return Se.nextTick(function(){s.write_in_progress=!1;var f=s._write(e,t,r,n,i,a,o);s.callback(f[0],f[1]),s.pending_close&&s.close()}),this};function xp(e,t){for(var r=0;r<e.length;r++)this[t+r]=e[r]}ce.prototype.writeSync=function(e,t,r,n,i,a,o){return this._writeCheck(),this._write(e,t,r,n,i,a,o)},ce.prototype._write=function(e,t,r,n,i,a,o){if(this.write_in_progress=!0,e!==kc&&e!==Rc&&e!==Oc&&e!==Ic&&e!==zi&&e!==Tc)throw new Error("Invalid flush value");t==null&&(t=new g(0),n=0,r=0),i._set?i.set=i._set:i.set=xp;var s=this.strm;s.avail_in=n,s.input=t,s.next_in=r,s.avail_out=o,s.output=i,s.next_out=a;var f;switch(this.mode){case xt:case Kt:case Et:f=Fd(s,e);break;case Vt:case Fr:case Cr:case Wt:f=ip(s,e);break;default:throw new Error("Unknown mode "+this.mode)}return this._checkError(f,s,e)||this._error(f),this.write_in_progress=!1,[s.avail_in,s.avail_out]},ce.prototype._checkError=function(e,t,r){switch(e){case Dr:case Fc:if(t.avail_out!==0&&r===zi)return!1;break;case Pc:break;case jc:return!1;default:return!1}return!0},ce.prototype.close=function(){if(this.write_in_progress){this.pending_close=!0;return}this.pending_close=!1,this.mode===xt||this.mode===Kt||this.mode===Et?Cd(this.strm):ap(this.strm),this.mode=Bi};var Mr;ce.prototype.reset=function(){switch(this.mode){case xt:case Et:Mr=Hs(this.strm);break;case Fr:case Wt:Mr=Sc(this.strm);break}Mr!==Dr&&this._error(Mr)},ce.prototype._error=function(e){this.onerror(ws[e]+": "+this.strm.msg,e),this.write_in_progress=!1,this.pending_close&&this.close()};var Dc=Object.freeze({__proto__:null,DEFLATE:xt,DEFLATERAW:Et,GUNZIP:Cr,GZIP:Kt,INFLATE:Fr,INFLATERAW:Wt,NONE:Bi,UNZIP:Vt,Z_BEST_COMPRESSION:hp,Z_BEST_SPEED:up,Z_BINARY:bp,Z_BLOCK:Tc,Z_BUF_ERROR:Fc,Z_DATA_ERROR:fp,Z_DEFAULT_COMPRESSION:dp,Z_DEFAULT_STRATEGY:wp,Z_DEFLATED:Cc,Z_ERRNO:sp,Z_FILTERED:pp,Z_FINISH:zi,Z_FIXED:vp,Z_FULL_FLUSH:Ic,Z_HUFFMAN_ONLY:yp,Z_NEED_DICT:jc,Z_NO_COMPRESSION:lp,Z_NO_FLUSH:kc,Z_OK:Dr,Z_PARTIAL_FLUSH:Rc,Z_RLE:gp,Z_STREAM_END:Pc,Z_STREAM_ERROR:cp,Z_SYNC_FLUSH:Oc,Z_TEXT:_p,Z_TREES:op,Z_UNKNOWN:mp,Zlib:ce});function Ep(e,t){if(!e)throw new Error(t)}var E={};Object.keys(Dc).forEach(function(e){E[e]=Dc[e]}),E.Z_MIN_WINDOWBITS=8,E.Z_MAX_WINDOWBITS=15,E.Z_DEFAULT_WINDOWBITS=15,E.Z_MIN_CHUNK=64,E.Z_MAX_CHUNK=1/0,E.Z_DEFAULT_CHUNK=16*1024,E.Z_MIN_MEMLEVEL=1,E.Z_MAX_MEMLEVEL=9,E.Z_DEFAULT_MEMLEVEL=8,E.Z_MIN_LEVEL=-1,E.Z_MAX_LEVEL=9,E.Z_DEFAULT_LEVEL=E.Z_DEFAULT_COMPRESSION;var Gt={Z_OK:E.Z_OK,Z_STREAM_END:E.Z_STREAM_END,Z_NEED_DICT:E.Z_NEED_DICT,Z_ERRNO:E.Z_ERRNO,Z_STREAM_ERROR:E.Z_STREAM_ERROR,Z_DATA_ERROR:E.Z_DATA_ERROR,Z_MEM_ERROR:E.Z_MEM_ERROR,Z_BUF_ERROR:E.Z_BUF_ERROR,Z_VERSION_ERROR:E.Z_VERSION_ERROR};Object.keys(Gt).forEach(function(e){Gt[Gt[e]]=e});function Sp(e){return new it(e)}function Ap(e){return new at(e)}function kp(e){return new ct(e)}function Rp(e){return new ft(e)}function Op(e){return new ot(e)}function Ip(e){return new st(e)}function Tp(e){return new lt(e)}function Pp(e,t,r){return typeof t=="function"&&(r=t,t={}),rt(new it(t),e,r)}function jp(e,t){return nt(new it(t),e)}function Fp(e,t,r){return typeof t=="function"&&(r=t,t={}),rt(new ot(t),e,r)}function Cp(e,t){return nt(new ot(t),e)}function Dp(e,t,r){return typeof t=="function"&&(r=t,t={}),rt(new ct(t),e,r)}function Mp(e,t){return nt(new ct(t),e)}function Np(e,t,r){return typeof t=="function"&&(r=t,t={}),rt(new lt(t),e,r)}function Lp(e,t){return nt(new lt(t),e)}function $p(e,t,r){return typeof t=="function"&&(r=t,t={}),rt(new at(t),e,r)}function Up(e,t){return nt(new at(t),e)}function Bp(e,t,r){return typeof t=="function"&&(r=t,t={}),rt(new st(t),e,r)}function zp(e,t){return nt(new st(t),e)}function Zp(e,t,r){return typeof t=="function"&&(r=t,t={}),rt(new ft(t),e,r)}function qp(e,t){return nt(new ft(t),e)}function rt(e,t,r){var n=[],i=0;e.on("error",o),e.on("end",s),e.end(t),a();function a(){for(var f;(f=e.read())!==null;)n.push(f),i+=f.length;e.once("readable",a)}function o(f){e.removeListener("end",s),e.removeListener("readable",a),r(f)}function s(){var f=g.concat(n,i);n=[],r(null,f),e.close()}}function nt(e,t){if(typeof t=="string"&&(t=new g(t)),!g.isBuffer(t))throw new TypeError("Not a string or buffer");var r=E.Z_FINISH;return e._processChunk(t,r)}function it(e){if(!(this instanceof it))return new it(e);D.call(this,e,E.DEFLATE)}function at(e){if(!(this instanceof at))return new at(e);D.call(this,e,E.INFLATE)}function ot(e){if(!(this instanceof ot))return new ot(e);D.call(this,e,E.GZIP)}function st(e){if(!(this instanceof st))return new st(e);D.call(this,e,E.GUNZIP)}function ct(e){if(!(this instanceof ct))return new ct(e);D.call(this,e,E.DEFLATERAW)}function ft(e){if(!(this instanceof ft))return new ft(e);D.call(this,e,E.INFLATERAW)}function lt(e){if(!(this instanceof lt))return new lt(e);D.call(this,e,E.UNZIP)}function D(e,t){if(this._opts=e=e||{},this._chunkSize=e.chunkSize||E.Z_DEFAULT_CHUNK,te.call(this,e),e.flush&&e.flush!==E.Z_NO_FLUSH&&e.flush!==E.Z_PARTIAL_FLUSH&&e.flush!==E.Z_SYNC_FLUSH&&e.flush!==E.Z_FULL_FLUSH&&e.flush!==E.Z_FINISH&&e.flush!==E.Z_BLOCK)throw new Error("Invalid flush flag: "+e.flush);if(this._flushFlag=e.flush||E.Z_NO_FLUSH,e.chunkSize&&(e.chunkSize<E.Z_MIN_CHUNK||e.chunkSize>E.Z_MAX_CHUNK))throw new Error("Invalid chunk size: "+e.chunkSize);if(e.windowBits&&(e.windowBits<E.Z_MIN_WINDOWBITS||e.windowBits>E.Z_MAX_WINDOWBITS))throw new Error("Invalid windowBits: "+e.windowBits);if(e.level&&(e.level<E.Z_MIN_LEVEL||e.level>E.Z_MAX_LEVEL))throw new Error("Invalid compression level: "+e.level);if(e.memLevel&&(e.memLevel<E.Z_MIN_MEMLEVEL||e.memLevel>E.Z_MAX_MEMLEVEL))throw new Error("Invalid memLevel: "+e.memLevel);if(e.strategy&&e.strategy!=E.Z_FILTERED&&e.strategy!=E.Z_HUFFMAN_ONLY&&e.strategy!=E.Z_RLE&&e.strategy!=E.Z_FIXED&&e.strategy!=E.Z_DEFAULT_STRATEGY)throw new Error("Invalid strategy: "+e.strategy);if(e.dictionary&&!g.isBuffer(e.dictionary))throw new Error("Invalid dictionary: it should be a Buffer instance");this._binding=new E.Zlib(t);var r=this;this._hadError=!1,this._binding.onerror=function(a,o){r._binding=null,r._hadError=!0;var s=new Error(a);s.errno=o,s.code=Gt[o],r.emit("error",s)};var n=E.Z_DEFAULT_COMPRESSION;typeof e.level=="number"&&(n=e.level);var i=E.Z_DEFAULT_STRATEGY;typeof e.strategy=="number"&&(i=e.strategy),this._binding.init(e.windowBits||E.Z_DEFAULT_WINDOWBITS,n,e.memLevel||E.Z_DEFAULT_MEMLEVEL,i,e.dictionary),this._buffer=new g(this._chunkSize),this._offset=0,this._closed=!1,this._level=n,this._strategy=i,this.once("end",this.close)}W(D,te),D.prototype.params=function(e,t,r){if(e<E.Z_MIN_LEVEL||e>E.Z_MAX_LEVEL)throw new RangeError("Invalid compression level: "+e);if(t!=E.Z_FILTERED&&t!=E.Z_HUFFMAN_ONLY&&t!=E.Z_RLE&&t!=E.Z_FIXED&&t!=E.Z_DEFAULT_STRATEGY)throw new TypeError("Invalid strategy: "+t);if(this._level!==e||this._strategy!==t){var n=this;this.flush(E.Z_SYNC_FLUSH,function(){n._binding.params(e,t),n._hadError||(n._level=e,n._strategy=t,r&&r())})}else Se.nextTick(r)},D.prototype.reset=function(){return this._binding.reset()},D.prototype._flush=function(e){this._transform(new g(0),"",e)},D.prototype.flush=function(e,t){var r=this._writableState;if((typeof e=="function"||e===void 0&&!t)&&(t=e,e=E.Z_FULL_FLUSH),r.ended)t&&Se.nextTick(t);else if(r.ending)t&&this.once("end",t);else if(r.needDrain){var n=this;this.once("drain",function(){n.flush(t)})}else this._flushFlag=e,this.write(new g(0),"",t)},D.prototype.close=function(e){if(e&&Se.nextTick(e),!this._closed){this._closed=!0,this._binding.close();var t=this;Se.nextTick(function(){t.emit("close")})}},D.prototype._transform=function(e,t,r){var n,i=this._writableState,a=i.ending||i.ended,o=a&&(!e||i.length===e.length);if(!e===null&&!g.isBuffer(e))return r(new Error("invalid input"));o?n=E.Z_FINISH:(n=this._flushFlag,e.length>=i.length&&(this._flushFlag=this._opts.flush||E.Z_NO_FLUSH)),this._processChunk(e,n,r)},D.prototype._processChunk=function(e,t,r){var n=e&&e.length,i=this._chunkSize-this._offset,a=0,o=this,s=typeof r=="function";if(!s){var f=[],c=0,l;this.on("error",function(y){l=y});do var h=this._binding.writeSync(t,e,a,n,this._buffer,this._offset,i);while(!this._hadError&&p(h[0],h[1]));if(this._hadError)throw l;var d=g.concat(f,c);return this.close(),d}var u=this._binding.write(t,e,a,n,this._buffer,this._offset,i);u.buffer=e,u.callback=p;function p(y,w){if(!o._hadError){var b=i-w;if(Ep(b>=0,"have should not go down"),b>0){var m=o._buffer.slice(o._offset,o._offset+b);o._offset+=b,s?o.push(m):(f.push(m),c+=m.length)}if((w===0||o._offset>=o._chunkSize)&&(i=o._chunkSize,o._offset=0,o._buffer=new g(o._chunkSize)),w===0){if(a+=n-y,n=y,!s)return!0;var x=o._binding.write(t,e,a,n,o._buffer,o._offset,o._chunkSize);x.callback=p,x.buffer=e;return}if(!s)return!1;r()}}},W(it,D),W(at,D),W(ot,D),W(st,D),W(ct,D),W(ft,D),W(lt,D);var Mc={codes:Gt,createDeflate:Sp,createInflate:Ap,createDeflateRaw:kp,createInflateRaw:Rp,createGzip:Op,createGunzip:Ip,createUnzip:Tp,deflate:Pp,deflateSync:jp,gzip:Fp,gzipSync:Cp,deflateRaw:Dp,deflateRawSync:Mp,unzip:Np,unzipSync:Lp,inflate:$p,inflateSync:Up,gunzip:Bp,gunzipSync:zp,inflateRaw:Zp,inflateRawSync:qp,Deflate:it,Inflate:at,Gzip:ot,Gunzip:st,DeflateRaw:ct,InflateRaw:ft,Unzip:lt,Zlib:D};class Nc extends vi{constructor({client:t,keyPrefix:r="cache",ttl:n=0,prefix:i=void 0}){super({client:t,keyPrefix:r,ttl:n,prefix:i}),this.client=t,this.keyPrefix=r,this.config.ttl=n,this.config.client=t,this.config.prefix=i!==void 0?i:r+(r.endsWith("/")?"":"/")}async _set(t,r){let n=JSON.stringify(r);const i=n.length;return n=Mc.gzipSync(n).toString("base64"),this.client.putObject({key:me(this.keyPrefix,t),body:n,contentEncoding:"gzip",contentType:"application/gzip",metadata:{compressor:"zlib",compressed:"true","client-id":this.client.id,"length-serialized":String(i),"length-compressed":String(n.length),"compression-gain":(n.length/i).toFixed(2)}})}async _get(t){try{const{Body:r}=await this.client.getObject(me(this.keyPrefix,t));let n=await yt(r);return n=Buffer.from(n,"base64"),n=Mc.unzipSync(n).toString(),JSON.parse(n)}catch(r){if(r.name==="NoSuchKey"||r.name==="NotFound")return null;throw r}}async _del(t){return await this.client.deleteObject(me(this.keyPrefix,t)),!0}async _clear(){const t=await this.client.getAllKeys({prefix:this.keyPrefix});for(const r of t)await this.client.deleteObject(r)}async size(){return(await this.keys()).length}async keys(){const t=await this.client.getAllKeys({prefix:this.keyPrefix}),r=this.keyPrefix.endsWith("/")?this.keyPrefix:this.keyPrefix+"/";return t.map(n=>n.startsWith(r)?n.slice(r.length):n)}}class Lc extends R{async setup(t){}async start(){}async stop(){}beforeSetup(){this.emit("plugin.beforeSetup",new Date)}afterSetup(){this.emit("plugin.afterSetup",new Date)}beforeStart(){this.emit("plugin.beforeStart",new Date)}afterStart(){this.emit("plugin.afterStart",new Date)}beforeStop(){this.emit("plugin.beforeStop",new Date)}afterStop(){this.emit("plugin.afterStop",new Date)}}const Hp={setup(e){},start(){},stop(){}},Kp={async setup(e){this.client=e.client,this.map={PutObjectCommand:"put",GetObjectCommand:"get",HeadObjectCommand:"get",DeleteObjectCommand:"delete",DeleteObjectsCommand:"delete",ListObjectsV2Command:"list"},this.costs={total:0,prices:{put:.005/1e3,copy:.005/1e3,list:.005/1e3,post:.005/1e3,get:4e-4/1e3,select:4e-4/1e3,delete:4e-4/1e3},requests:{total:0,put:0,post:0,copy:0,list:0,get:0,select:0,delete:0},events:{total:0,PutObjectCommand:0,GetObjectCommand:0,HeadObjectCommand:0,DeleteObjectCommand:0,DeleteObjectsCommand:0,ListObjectsV2Command:0}},this.client.costs=JSON.parse(JSON.stringify(this.costs))},async start(){this.client.on("command.response",e=>this.addRequest(e,this.map[e]))},addRequest(e,t){this.costs.events[e]++,this.costs.events.total++,this.costs.requests.total++,this.costs.requests[t]++,this.costs.total+=this.costs.prices[t],this.client.costs.events[e]++,this.client.costs.events.total++,this.client.costs.requests.total++,this.client.costs.requests[t]++,this.client.costs.total+=this.client.costs.prices[t]}};class Wp extends Lc{constructor(t={}){super(),this.driver=t.driver}async setup(t){this.database=t,this.driver||(this.driver=new Nc({keyPrefix:"cache",client:t.client})),this.installDatabaseProxy();for(const r of Object.values(t.resources))this.installResourcesProxies(r)}async start(){}async stop(){}installDatabaseProxy(){const t=this.installResourcesProxies.bind(this);this.database._createResource=this.database.createResource,this.database.createResource=async function(...r){const n=await this._createResource(...r);return t(n),n}}installResourcesProxies(t){t.cache=this.driver;let r=`resource=${t.name}`;this.driver.keyPrefix&&(this.driver.keyPrefix=me(this.driver.keyPrefix,r)),t.cacheKeyFor=async function({params:n={},action:i="list"}){let a=Object.keys(n).sort().map(o=>`${o}:${n[o]}`).join("|")||"empty";return a=await da(a),a=me(r,`action=${i}`,`${a}.json.gz`),a},t._count=t.count,t._listIds=t.listIds,t._getMany=t.getMany,t._getAll=t.getAll,t._page=t.page,t.count=async function(){const n=await this.cacheKeyFor({action:"count"});try{const a=await this.cache.get(n);if(a)return a}catch(a){if(a.name!=="NoSuchKey")throw a}const i=await t._count();return await this.cache.set(n,i),i},t.listIds=async function(){const n=await this.cacheKeyFor({action:"listIds"});try{const a=await this.cache.get(n);if(a)return a}catch(a){if(a.name!=="NoSuchKey")throw a}const i=await t._listIds();return await this.cache.set(n,i),i},t.getMany=async function(n){const i=await this.cacheKeyFor({action:"getMany",params:{ids:n}});try{const o=await this.cache.get(i);if(o)return o}catch(o){if(o.name!=="NoSuchKey")throw o}const a=await t._getMany(n);return await this.cache.set(i,a),a},t.getAll=async function(){const n=await this.cacheKeyFor({action:"getAll"});try{const a=await this.cache.get(n);if(a)return a}catch(a){if(a.name!=="NoSuchKey")throw a}const i=await t._getAll();return await this.cache.set(n,i),i},t.page=async function({offset:n,size:i}){const a=await this.cacheKeyFor({action:"page",params:{offset:n,size:i}});try{const s=await this.cache.get(a);if(s)return s}catch(s){if(s.name!=="NoSuchKey")throw s}const o=await t._page({offset:n,size:i});return await this.cache.set(a,o),o},t._insert=t.insert,t._update=t.update,t._delete=t.delete,t._deleteMany=t.deleteMany,t.insert=async function(...n){const i=await t._insert(...n);return await this.cache.clear(r),i},t.update=async function(...n){const i=await t._update(...n);return await this.cache.clear(r),i},t.delete=async function(...n){const i=await t._delete(...n);return await this.cache.clear(r),i},t.deleteMany=async function(...n){const i=await t._deleteMany(...n);return await this.cache.clear(r),i}}}export{Nh as AVAILABLE_BEHAVIORS,kf as AuthenticationError,na as BaseError,vi as Cache,Wp as CachePlugin,ha as Client,ua as ConnectionString,Kp as CostsPlugin,ps as DEFAULT_BEHAVIOR,gs as Database,Sf as DatabaseError,Of as EncryptionError,ca as ErrorMap,rr as InvalidResourceItem,$h as MemoryCache,oa as MissingMetadata,ia as NoSuchBucket,Kr as NoSuchKey,aa as NotFound,Rf as PermissionError,Lc as Plugin,Hp as PluginObject,_r as Resource,fs as ResourceIdsPageReader,cs as ResourceIdsReader,If as ResourceNotFound,ls as ResourceReader,us as ResourceWriter,Nc as S3Cache,ne as S3DBError,la as S3_DEFAULT_ENDPOINT,fa as S3_DEFAULT_REGION,vs as S3db,be as Schema,Kn as SchemaActions,sa as UnknownError,Af as ValidationError,bo as Validator,_o as ValidatorManager,br as behaviors,hi as calculateAttributeNamesSize,Ft as calculateAttributeSizes,Ce as calculateTotalSize,Ye as calculateUTF8Bytes,pa as decrypt,vs as default,Wr as encrypt,ge as getBehavior,yh as getSizeBreakdown,qr as idGenerator,yf as passwordGenerator,da as sha256,yt as streamToString,di as transformValue};