s3db.js 4.1.13 → 4.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/s3db.cjs.js +3 -4
- package/dist/s3db.cjs.min.js +1 -1
- package/dist/s3db.es.js +3 -4
- package/dist/s3db.es.min.js +1 -1
- package/dist/s3db.iife.js +3 -4
- package/dist/s3db.iife.min.js +1 -1
- package/package.json +14 -14
package/dist/s3db.iife.min.js
CHANGED
|
@@ -28,4 +28,4 @@ ${JSON.stringify(i,null,2)}`,{bucket:t,resourceName:r,attributes:n,validation:i}
|
|
|
28
28
|
`)+" "+e.join(`,
|
|
29
29
|
`)+" "+r[1]:r[0]+t+" "+e.join(", ")+" "+r[1]}function Xl(e){return Array.isArray(e)}function Mo(e){return typeof e=="boolean"}function Gn(e){return e===null}function Ql(e){return typeof e=="number"}function Yn(e){return typeof e=="string"}function Fe(e){return e===void 0}function Jn(e){return It(e)&&ei(e)==="[object RegExp]"}function It(e){return typeof e=="object"&&e!==null}function Lo(e){return It(e)&&ei(e)==="[object Date]"}function Xn(e){return It(e)&&(ei(e)==="[object Error]"||e instanceof Error)}function Qn(e){return typeof e=="function"}function ei(e){return Object.prototype.toString.call(e)}function eu(e,t){if(!t||!It(t))return e;for(var r=Object.keys(t),n=r.length;n--;)e[r[n]]=t[r[n]];return e}function $o(e,t){return Object.prototype.hasOwnProperty.call(e,t)}function Ve(){this.head=null,this.tail=null,this.length=0}Ve.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},Ve.prototype.unshift=function(e){var t={data:e,next:this.head};this.length===0&&(this.tail=t),this.head=t,++this.length},Ve.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}},Ve.prototype.clear=function(){this.head=this.tail=null,this.length=0},Ve.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},Ve.prototype.concat=function(e){if(this.length===0)return y.alloc(0);if(this.length===1)return this.head.data;for(var t=y.allocUnsafe(e>>>0),r=this.head,n=0;r;)r.data.copy(t,n),n+=r.data.length,r=r.next;return t};var tu=y.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 ru(e){if(e&&!tu(e))throw new Error("Unknown encoding: "+e)}function Tt(e){switch(this.encoding=(e||"utf8").toLowerCase().replace(/[-_]/,""),ru(e),this.encoding){case"utf8":this.surrogateSize=3;break;case"ucs2":case"utf16le":this.surrogateSize=2,this.detectIncompleteChar=iu;break;case"base64":this.surrogateSize=3,this.detectIncompleteChar=au;break;default:this.write=nu;return}this.charBuffer=new y(6),this.charReceived=0,this.charLength=0}Tt.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},Tt.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},Tt.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 nu(e){return e.toString(this.encoding)}function iu(e){this.charReceived=e.length%2,this.charLength=this.charReceived?2:0}function au(e){this.charReceived=e.length%3,this.charLength=this.charReceived?3:0}L.ReadableState=Bo;var C=Hl("stream");W(L,O);function ou(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 su(e,t){return e.listeners(t).length}function Bo(e,t){e=e||{},this.objectMode=!!e.objectMode,t instanceof oe&&(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 Ve,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 Tt(e.encoding),this.encoding=e.encoding)}function L(e){if(!(this instanceof L))return new L(e);this._readableState=new Bo(e,this),this.readable=!0,e&&typeof e.read=="function"&&(this._read=e.read),O.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=y.from(e,t),t="")),Uo(this,r,e,t,!1)},L.prototype.unshift=function(e){var t=this._readableState;return Uo(this,t,e,"",!0)},L.prototype.isPaused=function(){return this._readableState.flowing===!1};function Uo(e,t,r,n,i){var a=lu(t,r);if(a)e.emit("error",a);else if(r===null)t.reading=!1,uu(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&&hr(e))),hu(e,t)}else i||(t.reading=!1);return cu(t)}function cu(e){return!e.ended&&(e.needReadable||e.length<e.highWaterMark||e.length===0)}L.prototype.setEncoding=function(e){return this._readableState.decoder=new Tt(e),this._readableState.encoding=e,this};var zo=8388608;function fu(e){return e>=zo?e=zo:(e--,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e++),e}function Zo(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=fu(e)),e<=t.length?e:t.ended?t.length:(t.needReadable=!0,0))}L.prototype.read=function(e){C("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 C("read: emitReadable",t.length,t.ended),t.length===0&&t.ended?ri(this):hr(this),null;if(e=Zo(e,t),e===0&&t.ended)return t.length===0&&ri(this),null;var n=t.needReadable;C("need readable",n),(t.length===0||t.length-e<t.highWaterMark)&&(n=!0,C("length less than watermark",n)),t.ended||t.reading?(n=!1,C("reading or ended",n)):n&&(C("do read"),t.reading=!0,t.sync=!0,t.length===0&&(t.needReadable=!0),this._read(t.highWaterMark),t.sync=!1,t.reading||(e=Zo(r,t)));var i;return e>0?i=Ho(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&&ri(this)),i!==null&&this.emit("data",i),i};function lu(e,t){var r=null;return!y.isBuffer(t)&&typeof t!="string"&&t!==null&&t!==void 0&&!e.objectMode&&(r=new TypeError("Invalid non-string/buffer chunk")),r}function uu(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,hr(e)}}function hr(e){var t=e._readableState;t.needReadable=!1,t.emittedReadable||(C("emitReadable",t.flowing),t.emittedReadable=!0,t.sync?ne(qo,e):qo(e))}function qo(e){C("emit readable"),e.emit("readable"),ti(e)}function hu(e,t){t.readingMore||(t.readingMore=!0,ne(du,e,t))}function du(e,t){for(var r=t.length;!t.reading&&!t.flowing&&!t.ended&&t.length<t.highWaterMark&&(C("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,C("pipe count=%d opts=%j",n.pipesCount,t);var i=!t||t.end!==!1,a=i?s:l;n.endEmitted?ne(a):r.once("end",a),e.on("unpipe",o);function o(_){C("onunpipe"),_===r&&l()}function s(){C("onend"),e.end()}var f=pu(r);e.on("drain",f);var c=!1;function l(){C("cleanup"),e.removeListener("close",p),e.removeListener("finish",g),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(_){C("ondata"),d=!1;var m=e.write(_);m===!1&&!d&&((n.pipesCount===1&&n.pipes===e||n.pipesCount>1&&Ko(n.pipes,e)!==-1)&&!c&&(C("false write response, pause",r._readableState.awaitDrain),r._readableState.awaitDrain++,d=!0),r.pause())}function u(_){C("onerror",_),w(),e.removeListener("error",u),su(e,"error")===0&&e.emit("error",_)}ou(e,"error",u);function p(){e.removeListener("finish",g),w()}e.once("close",p);function g(){C("onfinish"),e.removeListener("close",p),w()}e.once("finish",g);function w(){C("unpipe"),r.unpipe(e)}return e.emit("pipe",r),n.flowing||(C("pipe resume"),r.resume()),e};function pu(e){return function(){var t=e._readableState;C("pipeOnDrain",t.awaitDrain),t.awaitDrain&&t.awaitDrain--,t.awaitDrain===0&&e.listeners("data").length&&(t.flowing=!0,ti(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=Ko(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=O.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&&hr(this):ne(yu,this))}return r},L.prototype.addListener=L.prototype.on;function yu(e){C("readable nexttick read 0"),e.read(0)}L.prototype.resume=function(){var e=this._readableState;return e.flowing||(C("resume"),e.flowing=!0,gu(this,e)),this};function gu(e,t){t.resumeScheduled||(t.resumeScheduled=!0,ne(vu,e,t))}function vu(e,t){t.reading||(C("resume read 0"),e.read(0)),t.resumeScheduled=!1,t.awaitDrain=0,e.emit("resume"),ti(e),t.flowing&&!t.reading&&e.read(0)}L.prototype.pause=function(){return C("call pause flowing=%j",this._readableState.flowing),this._readableState.flowing!==!1&&(C("pause"),this._readableState.flowing=!1,this.emit("pause")),this};function ti(e){var t=e._readableState;for(C("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(C("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(C("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 Eu(a,function(o){e.on(o,n.emit.bind(n,o))}),n._read=function(o){C("wrapped _read",o),r&&(r=!1,e.resume())},n},L._fromList=Ho;function Ho(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=wu(e,t.buffer,t.decoder),r}function wu(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?_u(e,t):bu(e,t),n}function _u(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 bu(e,t){var r=y.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 ri(e){var t=e._readableState;if(t.length>0)throw new Error('"endReadable()" called on non-empty stream');t.endEmitted||(t.ended=!0,ne(mu,t,e))}function mu(e,t){!e.endEmitted&&e.length===0&&(e.endEmitted=!0,t.readable=!1,t.emit("end"))}function Eu(e,t){for(var r=0,n=e.length;r<n;r++)t(e[r],r)}function Ko(e,t){for(var r=0,n=e.length;r<n;r++)if(e[r]===t)return r;return-1}H.WritableState=ni,W(H,O);function xu(){}function Su(e,t,r){this.chunk=e,this.encoding=t,this.callback=r,this.next=null}function ni(e,t){Object.defineProperty(this,"buffer",{get:No(function(){return this.getBuffer()},"_writableState.buffer is deprecated. Use _writableState.getBuffer instead.")}),e=e||{},this.objectMode=!!e.objectMode,t instanceof oe&&(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){Pu(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 Xo(this)}ni.prototype.getBuffer=function(){for(var t=this.bufferedRequest,r=[];t;)r.push(t),t=t.next;return r};function H(e){if(!(this instanceof H)&&!(this instanceof oe))return new H(e);this._writableState=new ni(e,this),this.writable=!0,e&&(typeof e.write=="function"&&(this._write=e.write),typeof e.writev=="function"&&(this._writev=e.writev)),O.call(this)}H.prototype.pipe=function(){this.emit("error",new Error("Cannot pipe, not readable"))};function Au(e,t){var r=new Error("write after end");e.emit("error",r),ne(t,r)}function ku(e,t,r,n){var i=!0,a=!1;return r===null?a=new TypeError("May not write null values to stream"):!y.isBuffer(r)&&typeof r!="string"&&r!==void 0&&!t.objectMode&&(a=new TypeError("Invalid non-string/buffer chunk")),a&&(e.emit("error",a),ne(n,a),i=!1),i}H.prototype.write=function(e,t,r){var n=this._writableState,i=!1;return typeof t=="function"&&(r=t,t=null),y.isBuffer(e)?t="buffer":t||(t=n.defaultEncoding),typeof r!="function"&&(r=xu),n.ended?Au(this,r):ku(this,n,e,r)&&(n.pendingcb++,i=Ou(this,n,e,t,r)),i},H.prototype.cork=function(){var e=this._writableState;e.corked++},H.prototype.uncork=function(){var e=this._writableState;e.corked&&(e.corked--,!e.writing&&!e.corked&&!e.finished&&!e.bufferProcessing&&e.bufferedRequest&&Wo(this,e))},H.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 Ru(e,t,r){return!e.objectMode&&e.decodeStrings!==!1&&typeof t=="string"&&(t=y.from(t,r)),t}function Ou(e,t,r,n,i){r=Ru(t,r,n),y.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 Su(r,n,i),s?s.next=t.lastBufferedRequest:t.bufferedRequest=t.lastBufferedRequest,t.bufferedRequestCount+=1}else ii(e,t,!1,a,r,n,i);return o}function ii(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 Iu(e,t,r,n,i){--t.pendingcb,r?ne(i,n):i(n),e._writableState.errorEmitted=!0,e.emit("error",n)}function Tu(e){e.writing=!1,e.writecb=null,e.length-=e.writelen,e.writelen=0}function Pu(e,t){var r=e._writableState,n=r.sync,i=r.writecb;if(Tu(r),t)Iu(e,r,n,t,i);else{var a=Go(r);!a&&!r.corked&&!r.bufferProcessing&&r.bufferedRequest&&Wo(e,r),n?ne(Vo,e,r,a,i):Vo(e,r,a,i)}}function Vo(e,t,r,n){r||Du(e,t),t.pendingcb--,n(),Jo(e,t)}function Du(e,t){t.length===0&&t.needDrain&&(t.needDrain=!1,e.emit("drain"))}function Wo(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;ii(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 Xo(t)}else{for(;r;){var s=r.chunk,f=r.encoding,c=r.callback,l=t.objectMode?1:s.length;if(ii(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}H.prototype._write=function(e,t,r){r(new Error("not implemented"))},H.prototype._writev=null,H.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&&Cu(this,n,r)};function Go(e){return e.ending&&e.length===0&&e.bufferedRequest===null&&!e.finished&&!e.writing}function Yo(e,t){t.prefinished||(t.prefinished=!0,e.emit("prefinish"))}function Jo(e,t){var r=Go(t);return r&&(t.pendingcb===0?(Yo(e,t),t.finished=!0,e.emit("finish")):Yo(e,t)),r}function Cu(e,t,r){t.ending=!0,Jo(e,t),r&&(t.finished?ne(r):e.once("finish",r)),t.ended=!0,e.writable=!1}function Xo(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(oe,L);for(var Qo=Object.keys(H.prototype),ai=0;ai<Qo.length;ai++){var oi=Qo[ai];oe.prototype[oi]||(oe.prototype[oi]=H.prototype[oi])}function oe(e){if(!(this instanceof oe))return new oe(e);L.call(this,e),H.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",ju)}function ju(){this.allowHalfOpen||this._writableState.ended||ne(Fu,this)}function Fu(e){e.end()}W(ie,oe);function Nu(e){this.afterTransform=function(t,r){return Mu(e,t,r)},this.needTransform=!1,this.transforming=!1,this.writecb=null,this.writechunk=null,this.writeencoding=null}function Mu(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 ie(e){if(!(this instanceof ie))return new ie(e);oe.call(this,e),this._transformState=new Nu(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){es(t,r)}):es(t)})}ie.prototype.push=function(e,t){return this._transformState.needTransform=!1,oe.prototype.push.call(this,e,t)},ie.prototype._transform=function(e,t,r){throw new Error("Not implemented")},ie.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)}},ie.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 es(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(Pt,ie);function Pt(e){if(!(this instanceof Pt))return new Pt(e);ie.call(this,e)}Pt.prototype._transform=function(e,t,r){r(null,e)},W(ke,O),ke.Readable=L,ke.Writable=H,ke.Duplex=oe,ke.Transform=ie,ke.PassThrough=Pt,ke.Stream=ke;function ke(){O.call(this)}ke.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(),O.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 ts extends O{constructor({resource:t}){super(),this.resource=t,this.client=t.client,this.stream=new Cc.ReadableStream({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 rs extends ts{enqueue(t){this.controller.enqueue(t),this.emit("page",t)}}class ns extends O{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 rs({resource:this.resource}),this.transform=new ie({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 ue.PromisePool.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 is extends O{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 H({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 ue.PromisePool.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 gt(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 vt(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 Lu(e){let t=0;for(const r of Object.keys(e))r!=="_v"&&(t+=vt(r));return t}function as(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 si(e){const t={};for(const[r,n]of Object.entries(e)){const i=as(n),a=vt(i);t[r]=a}return t}function We(e){const t=si(e),r=Object.values(t).reduce((i,a)=>i+a,0),n=Lu(e);return r+n}const B=2048;async function $u({resource:e,data:t,mappedData:r}){const n=We(r);if(n>B)throw new Error(`S3 metadata size exceeds 2KB limit. Current size: ${n} bytes, limit: ${B} bytes`);return{mappedData:r,body:""}}async function Bu({resource:e,id:t,data:r,mappedData:n}){const i=We(n);if(i>B)throw new Error(`S3 metadata size exceeds 2KB limit. Current size: ${i} bytes, limit: ${B} bytes`);return{mappedData:n,body:""}}async function Uu({resource:e,id:t,data:r,mappedData:n}){const i=We(n);if(i>B)throw new Error(`S3 metadata size exceeds 2KB limit. Current size: ${i} bytes, limit: ${B} bytes`);return{mappedData:n,body:""}}async function zu({resource:e,metadata:t,body:r}){return{metadata:t,body:r}}var Zu=Object.freeze({__proto__:null,S3_METADATA_LIMIT_BYTES:B,handleGet:zu,handleInsert:$u,handleUpdate:Bu,handleUpsert:Uu});async function qu({resource:e,data:t,mappedData:r}){const n=We(r);return n>B&&e.emit("exceedsLimit",{operation:"insert",totalSize:n,limit:B,excess:n-B,data:t}),{mappedData:r,body:""}}async function Hu({resource:e,id:t,data:r,mappedData:n}){const i=We(n);return i>B&&e.emit("exceedsLimit",{operation:"update",id:t,totalSize:i,limit:B,excess:i-B,data:r}),{mappedData:n,body:""}}async function Ku({resource:e,id:t,data:r,mappedData:n}){const i=We(n);return i>B&&e.emit("exceedsLimit",{operation:"upsert",id:t,totalSize:i,limit:B,excess:i-B,data:r}),{mappedData:n,body:""}}async function Vu({resource:e,metadata:t,body:r}){return{metadata:t,body:r}}var Wu=Object.freeze({__proto__:null,handleGet:Vu,handleInsert:qu,handleUpdate:Hu,handleUpsert:Ku});const os="...",ss=vt(os);async function Gu({resource:e,data:t,mappedData:r}){return ci({resource:e,data:t,mappedData:r})}async function Yu({resource:e,id:t,data:r,mappedData:n}){return ci({resource:e,data:r,mappedData:n})}async function Ju({resource:e,id:t,data:r,mappedData:n}){return ci({resource:e,data:r,mappedData:n})}async function Xu({resource:e,metadata:t,body:r}){return{metadata:t,body:r}}function ci({resource:e,data:t,mappedData:r}){const n=si(r),i=Object.entries(n).sort(([,s],[,f])=>s-f),a={};let o=0;for(const[s,f]of i){const c=B-o;if(f<=c)a[s]=r[s],o+=f;else if(c>ss){const l=c-ss,d=as(r[s]);let h="",u=0;for(let p=0;p<d.length;p++){const g=d[p],w=vt(g);if(u+w<=l)h+=g,u+=w;else break}a[s]=h+os,o=B;break}else break}return{mappedData:a,body:""}}var Qu=Object.freeze({__proto__:null,handleGet:Xu,handleInsert:Gu,handleUpdate:Yu,handleUpsert:Ju});const dr="$overflow",fi="true",eh=vt(dr)+vt(fi);async function th({resource:e,data:t,mappedData:r}){return li({resource:e,data:t,mappedData:r})}async function rh({resource:e,id:t,data:r,mappedData:n}){return li({resource:e,data:r,mappedData:n})}async function nh({resource:e,id:t,data:r,mappedData:n}){return li({resource:e,data:r,mappedData:n})}async function ih({resource:e,metadata:t,body:r}){if(t[dr]===fi)try{const n=r?JSON.parse(r):{},i={...t};return delete i[dr],{metadata:{...i,...n},body:""}}catch{return{metadata:t,body:r}}return{metadata:t,body:r}}function li({resource:e,data:t,mappedData:r}){if(We(r)<=B)return{mappedData:r,body:""};const i=B-eh,a=si(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[dr]=fi;const l=Object.keys(f).length>0?JSON.stringify(f):"";return{mappedData:s,body:l}}var ah=Object.freeze({__proto__:null,handleGet:ih,handleInsert:th,handleUpdate:rh,handleUpsert:nh});const cs={"user-management":Wu,"enforce-limits":Zu,"data-truncate":Qu,"body-overflow":ah};function Ge(e){const t=cs[e];if(!t)throw new Error(`Unknown behavior: ${e}. Available behaviors: ${Object.keys(cs).join(", ")}`);return t}const oh="user-management";class ui extends O{constructor(t){super();const r=sh(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=oh,passphrase:f="secret",parallelism:c=10,observers:l=[],cache:d=!1,autoDecrypt:h=!0,timestamps:u=!1,partitions:p={},paranoid:g=!0,allNestedObjectsOptional:w=!0,hooks:_={},options:m={}}=t,x={cache:typeof m.cache=="boolean"?m.cache:d,autoDecrypt:typeof m.autoDecrypt=="boolean"?m.autoDecrypt:h,timestamps:typeof m.timestamps=="boolean"?m.timestamps:u,paranoid:typeof m.paranoid=="boolean"?m.paranoid:g,allNestedObjectsOptional:typeof m.allNestedObjectsOptional=="boolean"?m.allNestedObjectsOptional:w,partitions:m.partitions||p||{}};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:x.cache,hooks:_,paranoid:x.paranoid,timestamps:x.timestamps,partitions:x.partitions,autoDecrypt:x.autoDecrypt,allNestedObjectsOptional:x.allNestedObjectsOptional},this.hooks={preInsert:[],afterInsert:[],preUpdate:[],afterUpdate:[],preDelete:[],afterDelete:[]},this.attributes=o||{},this.config.timestamps&&(this.attributes.createdAt="string|optional",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.schema=new pe({name:n,attributes:this.attributes,passphrase:f,version:this.version,options:{autoDecrypt:this.config.autoDecrypt,allNestedObjectsOptional:this.config.allNestedObjectsOptional}}),this.setupPartitionHooks(),this.validatePartitions(),_){for(const[v,A]of Object.entries(_))if(Array.isArray(A)&&this.hooks[v])for(const I of A)typeof I=="function"&&this.hooks[v].push(I.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}updateAttributes(t){const r=this.attributes;return this.attributes=t,this.config.timestamps&&(t.createdAt="string|optional",t.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.schema=new pe({name:this.name,attributes:t,passphrase:this.passphrase,version:this.version,options:{autoDecrypt:this.config.autoDecrypt,allNestedObjectsOptional:this.config.allNestedObjectsOptional}}),this.setupPartitionHooks(),this.validatePartitions(),{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:M.cloneDeep(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 version '${this.version}'. Available fields: ${r.join(", ")}. This version of resource does not have support for this partition.`)}}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 Ee(`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(([s],[f])=>s.localeCompare(f));for(const[s,f]of o){const c=this.getNestedFieldValue(n,s),l=this.applyPartitionRule(c,f);if(l==null)return null;a.push(`${s}=${l}`)}return a.length===0?null:Ee(`resource=${this.name}`,`partition=${t}`,...a,`id=${r}`)}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 Jt({bucket:this.client.config.bucket,resourceName:this.name,attributes:n,validation:i});!t&&t!==0&&(t=qi());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=M.merge({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 gt(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 pe({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 gt(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=M.merge(n,i);delete a.id;const{isValid:o,errors:s,data:f}=await this.validate(a);if(!o)throw new Jt({bucket:this.client.bucket,resourceName:this.name,attributes:i,validation:s});const c=await this.schema.mapper(f),l=Ge(this.behavior),{mappedData:d,body:h}=await l.handleUpdate({resource:this,id:t,data:f,mappedData:c}),u=this.getResourceKey(t);let p,g=h;if(h===""&&this.behavior!=="body-overflow")try{const w=await this.client.getObject(u);if(w.ContentLength>0){const _=Buffer.from(await w.Body.transformToByteArray()),m=_.toString();try{JSON.parse(m)}catch{g=_,p=w.ContentType}}}catch{}return await this.client.putObject({key:u,body:g,contentType:p,metadata:d}),f.id=t,await this.executeHooks("afterUpdate",f),await this.updatePartitionReferences(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 ue.PromisePool.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=M.chunk(t.map(i=>this.getResourceKey(i)),1e3),{results:n}=await ue.PromisePool.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}={}){if(!t){let w=(await this.listIds({partition:t,partitionValues:r})).slice(i);n&&(w=w.slice(0,n));const{results:_,errors:m}=await ue.PromisePool.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])throw new Error(`Partition '${t}' not found`);const a=this.config.partitions[t],o=[],s=Object.entries(a.fields).sort(([g],[w])=>g.localeCompare(w));for(const[g,w]of s){const _=r[g];if(_!=null){const m=this.applyPartitionRule(_,w);o.push(`${g}=${m}`)}}let f;o.length>0?f=`resource=${this.name}/partition=${t}/${o.join("/")}`:f=`resource=${this.name}/partition=${t}`;let d=(await this.client.getAllKeys({prefix:f})).map(g=>{const _=g.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 ue.PromisePool.for(d).withConcurrency(this.parallelism).handleError(async(g,w)=>(console.warn(`Failed to get partition resource ${w}:`,g.message),null)).process(async g=>{try{return await this.getFromPartition({id:g,partitionName:t,partitionValues:r})}catch(w){if(w.message.includes("Cipher job failed")||w.message.includes("OperationError"))return console.warn(`Decryption failed for partition resource ${g}, returning basic info`),{id:g,_partition:t,_partitionValues:r,_decryptionFailed:!0,_error:w.message};throw w}}),p=h.filter(g=>g!==null);return this.emit("list",{partition:t,partitionValues:r,count:p.length,errors:u.length}),p}async getMany(t){const{results:r,errors:n}=await ue.PromisePool.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 ue.PromisePool.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}={}){let o=null,s=null;a||(o=await this.count({partition:n,partitionValues:i}),s=Math.ceil(o/r));const f=Math.floor(t/r),c=await this.list({partition:n,partitionValues:i,limit:r,offset:t}),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}readable(){return new ns({resource:this}).build()}writable(){return new is({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=fo(t);return`sha256:${Bi.createHash("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 pe({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 updatePartitionReferences(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.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=Ee(`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 gt(w.Body)}catch{u=""}const{metadata:p}=await h.handleGet({resource:this,metadata:d,body:u});let g=p;return g.id=t,g._contentLength=f.ContentLength,g._lastModified=f.LastModified,g._hasContent=f.ContentLength>0,g._mimeType=f.ContentType||null,g._partition=r,g._partitionValues=n,f.VersionId&&(g._versionId=f.VersionId),f.Expiration&&(g._expiresAt=f.Expiration),g._definitionHash=this.getDefinitionHash(),this.emit("getFromPartition",g),g}}function sh(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 fs extends O{constructor(t){super(),this.version="1",this.s3dbVersion=(()=>{try{return"4.1.12"}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;!r&&(t.bucket||t.accessKeyId||t.secretAccessKey)&&(r=zr.buildFromParams({bucket:t.bucket,region:t.region,accessKeyId:t.accessKeyId,secretAccessKey:t.secretAccessKey,endpoint:t.endpoint,forcePathStyle:t.forcePathStyle})),this.client=t.client||new ia({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 gt(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 ui({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.options?.timestamps||!1,partitions:i.partitions||o.options?.partitions||{},paranoid:o.options?.paranoid!==!1,allNestedObjectsOptional:o.options?.allNestedObjectsOptional||!1,autoDecrypt:o.options?.autoDecrypt!==!1,hooks:o.options?.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=fo(a);return`sha256:${Bi.createHash("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(!M.isEmpty(this.plugins)){const r=this.plugins.map(a=>M.isFunction(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,options:{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:i.hooks||{}},behavior:i.behavior||"user-management",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,options:n={},behavior:i="user-management"}){if(!this.resources[t])return{exists:!1,sameHash:!1,hash:null};const a=new ui({name:t,attributes:r,behavior:i,observers:[],client:this.client,version:"temp",passphrase:this.passphrase,cache:this.cache,...n}),o=this.generateDefinitionHash(a.export(),i),s=this.generateDefinitionHash(this.resources[t].export(),this.resources[t].behavior);return{exists:!0,sameHash:o===s,hash:o,existingHash:s}}async createResourceIfNotExists({name:t,attributes:r,options:n={},behavior:i="user-management"}){const a=!!this.resources[t],o=this.resourceExistsWithSameHash({name:t,attributes:r,options:n,behavior:i});return o.exists&&o.sameHash?{resource:this.resources[t],created:!1,reason:"Resource already exists with same definition hash"}:{resource:await this.createResource({name:t,attributes:r,options:n,behavior:i}),created:!a,reason:a?"Resource updated with new definition":"New resource created"}}async createResource({name:t,attributes:r,options:n={},behavior:i="user-management"}){if(this.resources[t]){const f=this.resources[t];Object.assign(f.config,{cache:this.cache,...n}),i&&(f.behavior=i),f.updateAttributes(r);const c=this.generateDefinitionHash(f.export(),f.behavior),l=this.savedMetadata?.resources?.[t],d=l?.currentVersion||"v0",h=l?.versions?.[d];return(!h||h.hash!==c)&&await this.uploadMetadataFile(),this.emit("s3db.resourceUpdated",t),f}const o=this.savedMetadata?.resources?.[t]?.currentVersion||"v0",s=new ui({name:t,attributes:r,behavior:i,observers:[this],client:this.client,version:o,passphrase:this.passphrase,cache:this.cache,...n});return this.resources[t]=s,await this.uploadMetadataFile(),this.emit("s3db.resourceCreated",t),s}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 hi extends fs{}class di extends O{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 ch extends di{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 ls={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 fh(){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 Re(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 pr=Uint8Array,se=Uint16Array,yr=Int32Array,lh=4,us=0,hs=1,uh=2;function wt(e){for(var t=e.length;--t>=0;)e[t]=0}var hh=0,ds=1,dh=2,ph=3,yh=258,pi=29,Dt=256,Ct=Dt+1+pi,_t=30,yi=19,ps=2*Ct+1,Ye=15,gi=16,gh=7,vi=256,ys=16,gs=17,vs=18,wi=[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],gr=[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],ws=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],wh=512,Oe=new Array((Ct+2)*2);wt(Oe);var jt=new Array(_t*2);wt(jt);var Ft=new Array(wh);wt(Ft);var Nt=new Array(yh-ph+1);wt(Nt);var _i=new Array(pi);wt(_i);var vr=new Array(_t);wt(vr);function bi(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 _s,bs,ms;function mi(e,t){this.dyn_tree=e,this.max_code=0,this.stat_desc=t}function Es(e){return e<256?Ft[e]:Ft[256+(e>>>7)]}function Mt(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>gi-r?(e.bi_buf|=t<<e.bi_valid&65535,Mt(e,e.bi_buf),e.bi_buf=t>>gi-e.bi_valid,e.bi_valid+=r-gi):(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 xs(e,t){var r=0;do r|=e&1,e>>>=1,r<<=1;while(--t>0);return r>>>1}function _h(e){e.bi_valid===16?(Mt(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 bh(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,g=0;for(h=0;h<=Ye;h++)e.bl_count[h]=0;for(r[e.heap[e.heap_max]*2+1]=0,c=e.heap_max+1;c<ps;c++)l=e.heap[c],h=r[r[l*2+1]*2+1]+1,h>f&&(h=f,g++),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(g!==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]--,g-=2}while(g>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 Ss(e,t,r){var n=new Array(Ye+1),i=0,a,o;for(a=1;a<=Ye;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]=xs(n[s]++,s))}}function mh(){var e,t,r,n,i,a=new Array(Ye+1);for(r=0,n=0;n<pi-1;n++)for(_i[n]=r,e=0;e<1<<wi[n];e++)Nt[r++]=n;for(Nt[r-1]=n,i=0,n=0;n<16;n++)for(vr[n]=i,e=0;e<1<<gr[n];e++)Ft[i++]=n;for(i>>=7;n<_t;n++)for(vr[n]=i<<7,e=0;e<1<<gr[n]-7;e++)Ft[256+i++]=n;for(t=0;t<=Ye;t++)a[t]=0;for(e=0;e<=143;)Oe[e*2+1]=8,e++,a[8]++;for(;e<=255;)Oe[e*2+1]=9,e++,a[9]++;for(;e<=279;)Oe[e*2+1]=7,e++,a[7]++;for(;e<=287;)Oe[e*2+1]=8,e++,a[8]++;for(Ss(Oe,Ct+1,a),e=0;e<_t;e++)jt[e*2+1]=5,jt[e*2]=xs(e,5);_s=new bi(Oe,wi,Dt+1,Ct,Ye),bs=new bi(jt,gr,0,_t,Ye),ms=new bi(new Array(0),vh,0,yi,gh)}function As(e){var t;for(t=0;t<Ct;t++)e.dyn_ltree[t*2]=0;for(t=0;t<_t;t++)e.dyn_dtree[t*2]=0;for(t=0;t<yi;t++)e.bl_tree[t*2]=0;e.dyn_ltree[vi*2]=1,e.opt_len=e.static_len=0,e.last_lit=e.matches=0}function ks(e){e.bi_valid>8?Mt(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 Eh(e,t,r,n){ks(e),Mt(e,r),Mt(e,~r),Re(e.pending_buf,e.window,t,r,e.pending),e.pending+=r}function Rs(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 Ei(e,t,r){for(var n=e.heap[r],i=r<<1;i<=e.heap_len&&(i<e.heap_len&&Rs(t,e.heap[i+1],e.heap[i],e.depth)&&i++,!Rs(t,n,e.heap[i],e.depth));)e.heap[r]=e.heap[i],r=i,i<<=1;e.heap[r]=n}function Os(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+Dt+1,t),s=wi[o],s!==0&&(i-=_i[o],Q(e,i,s)),n--,o=Es(n),ve(e,o,r),s=gr[o],s!==0&&(n-=vr[o],Q(e,n,s)));while(a<e.last_lit);ve(e,vi,t)}function xi(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=ps,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--)Ei(e,r,o);c=a;do o=e.heap[1],e.heap[1]=e.heap[e.heap_len--],Ei(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++,Ei(e,r,1);while(e.heap_len>=2);e.heap[--e.heap_max]=e.heap[1],bh(e,t),Ss(r,f,e.bl_count)}function Is(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[ys*2]++):s<=10?e.bl_tree[gs*2]++:e.bl_tree[vs*2]++,s=0,i=a,o===0?(f=138,c=3):a===o?(f=6,c=3):(f=7,c=4))}function Ts(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,ys,e.bl_tree),Q(e,s-3,2)):s<=10?(ve(e,gs,e.bl_tree),Q(e,s-3,3)):(ve(e,vs,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 xh(e){var t;for(Is(e,e.dyn_ltree,e.l_desc.max_code),Is(e,e.dyn_dtree,e.d_desc.max_code),xi(e,e.bl_desc),t=yi-1;t>=3&&e.bl_tree[ws[t]*2+1]===0;t--);return e.opt_len+=3*(t+1)+5+5+4,t}function Sh(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[ws[i]*2+1],3);Ts(e,e.dyn_ltree,t-1),Ts(e,e.dyn_dtree,r-1)}function Ah(e){var t=4093624447,r;for(r=0;r<=31;r++,t>>>=1)if(t&1&&e.dyn_ltree[r*2]!==0)return us;if(e.dyn_ltree[18]!==0||e.dyn_ltree[20]!==0||e.dyn_ltree[26]!==0)return hs;for(r=32;r<Dt;r++)if(e.dyn_ltree[r*2]!==0)return hs;return us}var Ps=!1;function kh(e){Ps||(mh(),Ps=!0),e.l_desc=new mi(e.dyn_ltree,_s),e.d_desc=new mi(e.dyn_dtree,bs),e.bl_desc=new mi(e.bl_tree,ms),e.bi_buf=0,e.bi_valid=0,As(e)}function Ds(e,t,r,n){Q(e,(hh<<1)+(n?1:0),3),Eh(e,t,r)}function Rh(e){Q(e,ds<<1,3),ve(e,vi,Oe),_h(e)}function Oh(e,t,r,n){var i,a,o=0;e.level>0?(e.strm.data_type===uh&&(e.strm.data_type=Ah(e)),xi(e,e.l_desc),xi(e,e.d_desc),o=xh(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?Ds(e,t,r,n):e.strategy===lh||a===i?(Q(e,(ds<<1)+(n?1:0),3),Os(e,Oe,jt)):(Q(e,(dh<<1)+(n?1:0),3),Sh(e,e.l_desc.max_code+1,e.d_desc.max_code+1,o+1),Os(e,e.dyn_ltree,e.dyn_dtree)),As(e),n&&ks(e)}function Ne(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]+Dt+1)*2]++,e.dyn_dtree[Es(t)*2]++),e.last_lit===e.lit_bufsize-1}function Si(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 Ih(){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 Th=Ih();function q(e,t,r,n){var i=Th,a=n+r;e^=-1;for(var o=n;o<a;o++)e=e>>>8^i[(e^t[o])&255];return e^-1}var Je=0,Ph=1,Dh=3,Me=4,Cs=5,Le=0,js=1,$e=-2,Ch=-3,Ai=-5,jh=-1,Fh=1,wr=2,Nh=3,Mh=4,Lh=2,ki=8,$h=9,Bh=29,Uh=256,Ri=Uh+1+Bh,zh=30,Zh=19,qh=2*Ri+1,Hh=15,D=3,Be=258,fe=Be+D+1,Kh=32,Oi=42,Ii=69,_r=73,br=91,mr=103,Xe=113,Lt=666,z=1,$t=2,Qe=3,bt=4,Vh=3;function Ue(e,t){return e.msg=ls[t],t}function Fs(e){return(e<<1)-(e>4?9:0)}function et(e){for(var t=e.length;--t>=0;)e[t]=0}function ze(e){var t=e.state,r=t.pending;r>e.avail_out&&(r=e.avail_out),r!==0&&(Re(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 K(e,t){Oh(e,e.block_start>=0?e.block_start:-1,e.strstart-e.block_start,t),e.block_start=e.strstart,ze(e.strm)}function P(e,t){e.pending_buf[e.pending++]=t}function Bt(e,t){e.pending_buf[e.pending++]=t>>>8&255,e.pending_buf[e.pending++]=t&255}function Wh(e,t,r,n){var i=e.avail_in;return i>n&&(i=n),i===0?0:(e.avail_in-=i,Re(t,e.input,e.next_in,i,r),e.state.wrap===1?e.adler=Si(e.adler,t,i,r):e.state.wrap===2&&(e.adler=q(e.adler,t,i,r)),e.next_in+=i,e.total_in+=i,i)}function Ns(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-fe?e.strstart-(e.w_size-fe):0,c=e.window,l=e.w_mask,d=e.prev,h=e.strstart+Be,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=Be-(h-n),n=h-Be,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 Ut(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-fe)){Re(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=Wh(e.strm,e.window,e.strstart+e.lookahead,a),e.lookahead+=n,e.lookahead+e.insert>=D)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+D-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<D)););}while(e.lookahead<fe&&e.strm.avail_in!==0)}function Gh(e,t){var r=65535;for(r>e.pending_buf_size-5&&(r=e.pending_buf_size-5);;){if(e.lookahead<=1){if(Ut(e),e.lookahead===0&&t===Je)return z;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,K(e,!1),e.strm.avail_out===0)||e.strstart-e.block_start>=e.w_size-fe&&(K(e,!1),e.strm.avail_out===0))return z}return e.insert=0,t===Me?(K(e,!0),e.strm.avail_out===0?Qe:bt):(e.strstart>e.block_start&&(K(e,!1),e.strm.avail_out===0),z)}function Ti(e,t){for(var r,n;;){if(e.lookahead<fe){if(Ut(e),e.lookahead<fe&&t===Je)return z;if(e.lookahead===0)break}if(r=0,e.lookahead>=D&&(e.ins_h=(e.ins_h<<e.hash_shift^e.window[e.strstart+D-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-fe&&(e.match_length=Ns(e,r)),e.match_length>=D)if(n=Ne(e,e.strstart-e.match_start,e.match_length-D),e.lookahead-=e.match_length,e.match_length<=e.max_lazy_match&&e.lookahead>=D){e.match_length--;do e.strstart++,e.ins_h=(e.ins_h<<e.hash_shift^e.window[e.strstart+D-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=Ne(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++;if(n&&(K(e,!1),e.strm.avail_out===0))return z}return e.insert=e.strstart<D-1?e.strstart:D-1,t===Me?(K(e,!0),e.strm.avail_out===0?Qe:bt):e.last_lit&&(K(e,!1),e.strm.avail_out===0)?z:$t}function mt(e,t){for(var r,n,i;;){if(e.lookahead<fe){if(Ut(e),e.lookahead<fe&&t===Je)return z;if(e.lookahead===0)break}if(r=0,e.lookahead>=D&&(e.ins_h=(e.ins_h<<e.hash_shift^e.window[e.strstart+D-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=D-1,r!==0&&e.prev_length<e.max_lazy_match&&e.strstart-r<=e.w_size-fe&&(e.match_length=Ns(e,r),e.match_length<=5&&(e.strategy===Fh||e.match_length===D&&e.strstart-e.match_start>4096)&&(e.match_length=D-1)),e.prev_length>=D&&e.match_length<=e.prev_length){i=e.strstart+e.lookahead-D,n=Ne(e,e.strstart-1-e.prev_match,e.prev_length-D),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+D-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=D-1,e.strstart++,n&&(K(e,!1),e.strm.avail_out===0))return z}else if(e.match_available){if(n=Ne(e,0,e.window[e.strstart-1]),n&&K(e,!1),e.strstart++,e.lookahead--,e.strm.avail_out===0)return z}else e.match_available=1,e.strstart++,e.lookahead--}return e.match_available&&(n=Ne(e,0,e.window[e.strstart-1]),e.match_available=0),e.insert=e.strstart<D-1?e.strstart:D-1,t===Me?(K(e,!0),e.strm.avail_out===0?Qe:bt):e.last_lit&&(K(e,!1),e.strm.avail_out===0)?z:$t}function Yh(e,t){for(var r,n,i,a,o=e.window;;){if(e.lookahead<=Be){if(Ut(e),e.lookahead<=Be&&t===Je)return z;if(e.lookahead===0)break}if(e.match_length=0,e.lookahead>=D&&e.strstart>0&&(i=e.strstart-1,n=o[i],n===o[++i]&&n===o[++i]&&n===o[++i])){a=e.strstart+Be;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=Be-(a-i),e.match_length>e.lookahead&&(e.match_length=e.lookahead)}if(e.match_length>=D?(r=Ne(e,1,e.match_length-D),e.lookahead-=e.match_length,e.strstart+=e.match_length,e.match_length=0):(r=Ne(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++),r&&(K(e,!1),e.strm.avail_out===0))return z}return e.insert=0,t===Me?(K(e,!0),e.strm.avail_out===0?Qe:bt):e.last_lit&&(K(e,!1),e.strm.avail_out===0)?z:$t}function Jh(e,t){for(var r;;){if(e.lookahead===0&&(Ut(e),e.lookahead===0)){if(t===Je)return z;break}if(e.match_length=0,r=Ne(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++,r&&(K(e,!1),e.strm.avail_out===0))return z}return e.insert=0,t===Me?(K(e,!0),e.strm.avail_out===0?Qe:bt):e.last_lit&&(K(e,!1),e.strm.avail_out===0)?z:$t}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 Et;Et=[new we(0,0,0,0,Gh),new we(4,4,8,4,Ti),new we(4,5,16,8,Ti),new we(4,6,32,32,Ti),new we(4,4,16,16,mt),new we(8,16,32,32,mt),new we(8,16,128,128,mt),new we(8,32,128,256,mt),new we(32,128,258,1024,mt),new we(32,258,258,4096,mt)];function Xh(e){e.window_size=2*e.w_size,et(e.head),e.max_lazy_match=Et[e.level].max_lazy,e.good_match=Et[e.level].good_length,e.nice_match=Et[e.level].nice_length,e.max_chain_length=Et[e.level].max_chain,e.strstart=0,e.block_start=0,e.lookahead=0,e.insert=0,e.match_length=e.prev_length=D-1,e.match_available=0,e.ins_h=0}function Qh(){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=ki,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 se(qh*2),this.dyn_dtree=new se((2*zh+1)*2),this.bl_tree=new se((2*Zh+1)*2),et(this.dyn_ltree),et(this.dyn_dtree),et(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new se(Hh+1),this.heap=new se(2*Ri+1),et(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new se(2*Ri+1),et(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 ed(e){var t;return!e||!e.state?Ue(e,$e):(e.total_in=e.total_out=0,e.data_type=Lh,t=e.state,t.pending=0,t.pending_out=0,t.wrap<0&&(t.wrap=-t.wrap),t.status=t.wrap?Oi:Xe,e.adler=t.wrap===2?0:1,t.last_flush=Je,kh(t),Le)}function Ms(e){var t=ed(e);return t===Le&&Xh(e.state),t}function td(e,t,r,n,i,a){if(!e)return $e;var o=1;if(t===jh&&(t=6),n<0?(o=0,n=-n):n>15&&(o=2,n-=16),i<1||i>$h||r!==ki||n<8||n>15||t<0||t>9||a<0||a>Mh)return Ue(e,$e);n===8&&(n=9);var s=new Qh;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+D-1)/D),s.window=new pr(s.w_size*2),s.head=new se(s.hash_size),s.prev=new se(s.w_size),s.lit_bufsize=1<<i+6,s.pending_buf_size=s.lit_bufsize*4,s.pending_buf=new pr(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,Ms(e)}function rd(e,t){var r,n,i,a;if(!e||!e.state||t>Cs||t<0)return e?Ue(e,$e):$e;if(n=e.state,!e.output||!e.input&&e.avail_in!==0||n.status===Lt&&t!==Me)return Ue(e,e.avail_out===0?Ai:$e);if(n.strm=e,r=n.last_flush,n.last_flush=t,n.status===Oi)if(n.wrap===2)e.adler=0,P(n,31),P(n,139),P(n,8),n.gzhead?(P(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)),P(n,n.gzhead.time&255),P(n,n.gzhead.time>>8&255),P(n,n.gzhead.time>>16&255),P(n,n.gzhead.time>>24&255),P(n,n.level===9?2:n.strategy>=wr||n.level<2?4:0),P(n,n.gzhead.os&255),n.gzhead.extra&&n.gzhead.extra.length&&(P(n,n.gzhead.extra.length&255),P(n,n.gzhead.extra.length>>8&255)),n.gzhead.hcrc&&(e.adler=q(e.adler,n.pending_buf,n.pending,0)),n.gzindex=0,n.status=Ii):(P(n,0),P(n,0),P(n,0),P(n,0),P(n,0),P(n,n.level===9?2:n.strategy>=wr||n.level<2?4:0),P(n,Vh),n.status=Xe);else{var o=ki+(n.w_bits-8<<4)<<8,s=-1;n.strategy>=wr||n.level<2?s=0:n.level<6?s=1:n.level===6?s=2:s=3,o|=s<<6,n.strstart!==0&&(o|=Kh),o+=31-o%31,n.status=Xe,Bt(n,o),n.strstart!==0&&(Bt(n,e.adler>>>16),Bt(n,e.adler&65535)),e.adler=1}if(n.status===Ii)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=q(e.adler,n.pending_buf,n.pending-i,i)),ze(e),i=n.pending,n.pending===n.pending_buf_size));)P(n,n.gzhead.extra[n.gzindex]&255),n.gzindex++;n.gzhead.hcrc&&n.pending>i&&(e.adler=q(e.adler,n.pending_buf,n.pending-i,i)),n.gzindex===n.gzhead.extra.length&&(n.gzindex=0,n.status=_r)}else n.status=_r;if(n.status===_r)if(n.gzhead.name){i=n.pending;do{if(n.pending===n.pending_buf_size&&(n.gzhead.hcrc&&n.pending>i&&(e.adler=q(e.adler,n.pending_buf,n.pending-i,i)),ze(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,P(n,a)}while(a!==0);n.gzhead.hcrc&&n.pending>i&&(e.adler=q(e.adler,n.pending_buf,n.pending-i,i)),a===0&&(n.gzindex=0,n.status=br)}else n.status=br;if(n.status===br)if(n.gzhead.comment){i=n.pending;do{if(n.pending===n.pending_buf_size&&(n.gzhead.hcrc&&n.pending>i&&(e.adler=q(e.adler,n.pending_buf,n.pending-i,i)),ze(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,P(n,a)}while(a!==0);n.gzhead.hcrc&&n.pending>i&&(e.adler=q(e.adler,n.pending_buf,n.pending-i,i)),a===0&&(n.status=mr)}else n.status=mr;if(n.status===mr&&(n.gzhead.hcrc?(n.pending+2>n.pending_buf_size&&ze(e),n.pending+2<=n.pending_buf_size&&(P(n,e.adler&255),P(n,e.adler>>8&255),e.adler=0,n.status=Xe)):n.status=Xe),n.pending!==0){if(ze(e),e.avail_out===0)return n.last_flush=-1,Le}else if(e.avail_in===0&&Fs(t)<=Fs(r)&&t!==Me)return Ue(e,Ai);if(n.status===Lt&&e.avail_in!==0)return Ue(e,Ai);if(e.avail_in!==0||n.lookahead!==0||t!==Je&&n.status!==Lt){var f=n.strategy===wr?Jh(n,t):n.strategy===Nh?Yh(n,t):Et[n.level].func(n,t);if((f===Qe||f===bt)&&(n.status=Lt),f===z||f===Qe)return e.avail_out===0&&(n.last_flush=-1),Le;if(f===$t&&(t===Ph?Rh(n):t!==Cs&&(Ds(n,0,0,!1),t===Dh&&(et(n.head),n.lookahead===0&&(n.strstart=0,n.block_start=0,n.insert=0))),ze(e),e.avail_out===0))return n.last_flush=-1,Le}return t!==Me?Le:n.wrap<=0?js:(n.wrap===2?(P(n,e.adler&255),P(n,e.adler>>8&255),P(n,e.adler>>16&255),P(n,e.adler>>24&255),P(n,e.total_in&255),P(n,e.total_in>>8&255),P(n,e.total_in>>16&255),P(n,e.total_in>>24&255)):(Bt(n,e.adler>>>16),Bt(n,e.adler&65535)),ze(e),n.wrap>0&&(n.wrap=-n.wrap),n.pending!==0?Le:js)}function nd(e){var t;return!e||!e.state?$e:(t=e.state.status,t!==Oi&&t!==Ii&&t!==_r&&t!==br&&t!==mr&&t!==Xe&&t!==Lt?Ue(e,$e):(e.state=null,t===Xe?Ue(e,Ch):Le))}var Er=30,id=12;function ad(e,t){var r,n,i,a,o,s,f,c,l,d,h,u,p,g,w,_,m,x,v,A,I,b,S,T,k;r=e.state,n=e.next_in,T=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,g=r.lencode,w=r.distcode,_=(1<<r.lenbits)-1,m=(1<<r.distbits)-1;e:do{p<15&&(u+=T[n++]<<p,p+=8,u+=T[n++]<<p,p+=8),x=g[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+=T[n++]<<p,p+=8),A+=u&(1<<v)-1,u>>>=v,p-=v),p<15&&(u+=T[n++]<<p,p+=8,u+=T[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(I=x&65535,v&=15,p<v&&(u+=T[n++]<<p,p+=8,p<v&&(u+=T[n++]<<p,p+=8)),I+=u&(1<<v)-1,I>f){e.msg="invalid distance too far back",r.mode=Er;break e}if(u>>>=v,p-=v,v=a-o,I>v){if(v=I-v,v>l&&r.sane){e.msg="invalid distance too far back",r.mode=Er;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-I,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-I,S=k}}}else if(b+=d-v,v<A){A-=v;do k[a++]=h[b++];while(--v);b=a-I,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-I;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=Er;break e}break}}else if((v&64)===0){x=g[(x&65535)+(u&(1<<v)-1)];continue t}else if(v&32){r.mode=id;break e}else{e.msg="invalid literal/length code",r.mode=Er;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 xt=15,Ls=852,$s=592,Bs=0,Pi=1,Us=2,od=[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],sd=[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],cd=[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],fd=[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 zt(e,t,r,n,i,a,o,s){var f=s.bits,c=0,l=0,d=0,h=0,u=0,p=0,g=0,w=0,_=0,m=0,x,v,A,I,b,S=null,T=0,k,j=new se(xt+1),V=new se(xt+1),Y=null,ce=0,lt,ee,_e;for(c=0;c<=xt;c++)j[c]=0;for(l=0;l<n;l++)j[t[r+l]]++;for(u=f,h=xt;h>=1&&j[h]===0;h--);if(u>h&&(u=h),h===0)return i[a++]=20971520,i[a++]=20971520,s.bits=1,0;for(d=1;d<h&&j[d]===0;d++);for(u<d&&(u=d),w=1,c=1;c<=xt;c++)if(w<<=1,w-=j[c],w<0)return-1;if(w>0&&(e===Bs||h!==1))return-1;for(V[1]=0,c=1;c<xt;c++)V[c+1]=V[c]+j[c];for(l=0;l<n;l++)t[r+l]!==0&&(o[V[t[r+l]]++]=l);if(e===Bs?(S=Y=o,k=19):e===Pi?(S=od,T-=257,Y=sd,ce-=257,k=256):(S=cd,Y=fd,k=-1),m=0,l=0,c=d,b=a,p=u,g=0,A=-1,_=1<<u,I=_-1,e===Pi&&_>Ls||e===Us&&_>$s)return 1;for(;;){lt=c-g,o[l]<k?(ee=0,_e=o[l]):o[l]>k?(ee=Y[ce+o[l]],_e=S[T+o[l]]):(ee=96,_e=0),x=1<<c-g,v=1<<p,d=v;do v-=x,i[b+(m>>g)+v]=lt<<24|ee<<16|_e|0;while(v!==0);for(x=1<<c-1;m&x;)x>>=1;if(x!==0?(m&=x-1,m+=x):m=0,l++,--j[c]===0){if(c===h)break;c=t[r+o[l]]}if(c>u&&(m&I)!==A){for(g===0&&(g=u),b+=d,p=c-g,w=1<<p;p+g<h&&(w-=j[p+g],!(w<=0));)p++,w<<=1;if(_+=1<<p,e===Pi&&_>Ls||e===Us&&_>$s)return 1;A=m&I,i[A]=u<<24|p<<16|b-a|0}}return m!==0&&(i[b+m]=c-g<<24|4194304|0),s.bits=u,0}var ld=0,zs=1,Zs=2,qs=4,ud=5,xr=6,Zt=0,hd=1,dd=2,Ze=-2,pd=-3,yd=-4,gd=-5,Hs=8,Ks=1,Vs=2,Ws=3,Gs=4,Ys=5,Js=6,Xs=7,Qs=8,ec=9,tc=10,rc=11,Ie=12,Di=13,nc=14,Ci=15,ic=16,ac=17,oc=18,sc=19,Sr=20,Ar=21,cc=22,fc=23,lc=24,uc=25,hc=26,ji=27,dc=28,pc=29,F=30,vd=31,wd=32,_d=852,bd=592;function yc(e){return(e>>>24&255)+(e>>>8&65280)+((e&65280)<<8)+((e&255)<<24)}function md(){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 se(320),this.work=new se(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function Ed(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=Ks,t.last=0,t.havedict=0,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=t.lendyn=new yr(_d),t.distcode=t.distdyn=new yr(bd),t.sane=1,t.back=-1,Zt)}function gc(e){var t;return!e||!e.state?Ze:(t=e.state,t.wsize=0,t.whave=0,t.wnext=0,Ed(e))}function xd(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,gc(e))}function Sd(e,t){var r,n;return e?(n=new md,e.state=n,n.window=null,r=xd(e,t),r!==Zt&&(e.state=null),r):Ze}var vc=!0,Fi,Ni;function Ad(e){if(vc){var t;for(Fi=new yr(512),Ni=new yr(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(zt(zs,e.lens,0,288,Fi,0,e.work,{bits:9}),t=0;t<32;)e.lens[t++]=5;zt(Zs,e.lens,0,32,Ni,0,e.work,{bits:5}),vc=!1}e.lencode=Fi,e.lenbits=9,e.distcode=Ni,e.distbits=5}function kd(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 pr(a.wsize)),n>=a.wsize?(Re(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),Re(a.window,t,r-n,i,a.wnext),n-=i,n?(Re(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 Rd(e,t){var r,n,i,a,o,s,f,c,l,d,h,u,p,g,w=0,_,m,x,v,A,I,b,S,T=new pr(4),k,j,V=[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===Ie&&(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=Zt;e:for(;;)switch(r.mode){case Ks: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,T[0]=c&255,T[1]=c>>>8&255,r.check=q(r.check,T,2,0),c=0,l=0,r.mode=Vs;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=F;break}if((c&15)!==Hs){e.msg="unknown compression method",r.mode=F;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=F;break}r.dmax=1<<b,e.adler=r.check=1,r.mode=c&512?tc:Ie,c=0,l=0;break;case Vs:for(;l<16;){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}if(r.flags=c,(r.flags&255)!==Hs){e.msg="unknown compression method",r.mode=F;break}if(r.flags&57344){e.msg="unknown header flags set",r.mode=F;break}r.head&&(r.head.text=c>>8&1),r.flags&512&&(T[0]=c&255,T[1]=c>>>8&255,r.check=q(r.check,T,2,0)),c=0,l=0,r.mode=Ws;case Ws:for(;l<32;){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}r.head&&(r.head.time=c),r.flags&512&&(T[0]=c&255,T[1]=c>>>8&255,T[2]=c>>>16&255,T[3]=c>>>24&255,r.check=q(r.check,T,4,0)),c=0,l=0,r.mode=Gs;case Gs: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&&(T[0]=c&255,T[1]=c>>>8&255,r.check=q(r.check,T,2,0)),c=0,l=0,r.mode=Ys;case Ys: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&&(T[0]=c&255,T[1]=c>>>8&255,r.check=q(r.check,T,2,0)),c=0,l=0}else r.head&&(r.head.extra=null);r.mode=Js;case Js: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)),Re(r.head.extra,n,a,u,b)),r.flags&512&&(r.check=q(r.check,n,u,a)),s-=u,a+=u,r.length-=u),r.length))break e;r.length=0,r.mode=Xs;case Xs: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=q(r.check,n,u,a)),s-=u,a+=u,b)break e}else r.head&&(r.head.name=null);r.length=0,r.mode=Qs;case Qs: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=q(r.check,n,u,a)),s-=u,a+=u,b)break e}else r.head&&(r.head.comment=null);r.mode=ec;case ec: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=F;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=Ie;break;case tc:for(;l<32;){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}e.adler=r.check=yc(c),c=0,l=0,r.mode=rc;case rc: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,dd;e.adler=r.check=1,r.mode=Ie;case Ie:if(t===ud||t===xr)break e;case Di:if(r.last){c>>>=l&7,l-=l&7,r.mode=ji;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=nc;break;case 1:if(Ad(r),r.mode=Sr,t===xr){c>>>=2,l-=2;break e}break;case 2:r.mode=ac;break;case 3:e.msg="invalid block type",r.mode=F}c>>>=2,l-=2;break;case nc: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=F;break}if(r.length=c&65535,c=0,l=0,r.mode=Ci,t===xr)break e;case Ci:r.mode=ic;case ic:if(u=r.length,u){if(u>s&&(u=s),u>f&&(u=f),u===0)break e;Re(i,n,a,u,o),s-=u,a+=u,f-=u,o+=u,r.length-=u;break}r.mode=Ie;break;case ac: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=F;break}r.have=0,r.mode=oc;case oc:for(;r.have<r.ncode;){for(;l<3;){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}r.lens[V[r.have++]]=c&7,c>>>=3,l-=3}for(;r.have<19;)r.lens[V[r.have++]]=0;if(r.lencode=r.lendyn,r.lenbits=7,k={bits:r.lenbits},S=zt(ld,r.lens,0,19,r.lencode,0,r.work,k),r.lenbits=k.bits,S){e.msg="invalid code lengths set",r.mode=F;break}r.have=0,r.mode=sc;case sc: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(j=_+2;l<j;){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=F;break}b=r.lens[r.have-1],u=3+(c&3),c>>>=2,l-=2}else if(x===17){for(j=_+3;l<j;){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(j=_+7;l<j;){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=F;break}for(;u--;)r.lens[r.have++]=b}}if(r.mode===F)break;if(r.lens[256]===0){e.msg="invalid code -- missing end-of-block",r.mode=F;break}if(r.lenbits=9,k={bits:r.lenbits},S=zt(zs,r.lens,0,r.nlen,r.lencode,0,r.work,k),r.lenbits=k.bits,S){e.msg="invalid literal/lengths set",r.mode=F;break}if(r.distbits=6,r.distcode=r.distdyn,k={bits:r.distbits},S=zt(Zs,r.lens,r.nlen,r.ndist,r.distcode,0,r.work,k),r.distbits=k.bits,S){e.msg="invalid distances set",r.mode=F;break}if(r.mode=Sr,t===xr)break e;case Sr:r.mode=Ar;case Ar: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,ad(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===Ie&&(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,I=x;w=r.lencode[I+((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=hc;break}if(m&32){r.back=-1,r.mode=Ie;break}if(m&64){e.msg="invalid literal/length code",r.mode=F;break}r.extra=m&15,r.mode=cc;case cc:if(r.extra){for(j=r.extra;l<j;){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=fc;case fc: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,I=x;w=r.distcode[I+((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=F;break}r.offset=x,r.extra=m&15,r.mode=lc;case lc:if(r.extra){for(j=r.extra;l<j;){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=F;break}r.mode=uc;case uc: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=F;break}u>r.wnext?(u-=r.wnext,p=r.wsize-u):p=r.wnext-u,u>r.length&&(u=r.length),g=r.window}else g=i,p=o-r.offset,u=r.length;u>f&&(u=f),f-=u,r.length-=u;do i[o++]=g[p++];while(--u);r.length===0&&(r.mode=Ar);break;case hc:if(f===0)break e;i[o++]=r.length,f--,r.mode=Ar;break;case ji: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?q(r.check,i,h,o-h):Si(r.check,i,h,o-h)),h=f,(r.flags?c:yc(c))!==r.check){e.msg="incorrect data check",r.mode=F;break}c=0,l=0}r.mode=dc;case dc: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=F;break}c=0,l=0}r.mode=pc;case pc:S=hd;break e;case F:S=pd;break e;case vd:return yd;case wd: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<F&&(r.mode<ji||t!==qs))&&kd(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?q(r.check,i,h,e.next_out-h):Si(r.check,i,h,e.next_out-h)),e.data_type=r.bits+(r.last?64:0)+(r.mode===Ie?128:0)+(r.mode===Sr||r.mode===Ci?256:0),(d===0&&h===0||t===qs)&&S===Zt&&(S=gd),S}function Od(e){if(!e||!e.state)return Ze;var t=e.state;return t.window&&(t.window=null),e.state=null,Zt}var Mi=0,St=1,kr=2,qt=3,Rr=4,At=5,Ht=6,Kt=7,wc=0,_c=1,bc=2,mc=3,Li=4,Ec=5,Id=6,Or=0,xc=1,Sc=2,Td=-1,Pd=-2,Dd=-3,Ac=-5,Cd=0,jd=1,Fd=9,Nd=-1,Md=1,Ld=2,$d=3,Bd=4,Ud=0,zd=0,Zd=1,qd=2,kc=8;function le(e){if(e<St||e>Kt)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}le.prototype.init=function(e,t,r,n,i){this.windowBits=e,this.level=t,this.memLevel=r,this.strategy=n,(this.mode===qt||this.mode===Rr)&&(this.windowBits+=16),this.mode===Kt&&(this.windowBits+=32),(this.mode===At||this.mode===Ht)&&(this.windowBits=-this.windowBits),this.strm=new fh;var a;switch(this.mode){case St:case qt:case At:a=td(this.strm,this.level,kc,this.windowBits,this.memLevel,this.strategy);break;case kr:case Rr:case Ht:case Kt:a=Sd(this.strm,this.windowBits);break;default:throw new Error("Unknown mode "+this.mode)}if(a!==Or){this._error(a);return}this.write_in_progress=!1,this.init_done=!0},le.prototype.params=function(){throw new Error("deflateParams Not supported")},le.prototype._writeCheck=function(){if(!this.init_done)throw new Error("write before init");if(this.mode===Mi)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")},le.prototype.write=function(e,t,r,n,i,a,o){this._writeCheck(),this.write_in_progress=!0;var s=this;return Ae.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 Hd(e,t){for(var r=0;r<e.length;r++)this[t+r]=e[r]}le.prototype.writeSync=function(e,t,r,n,i,a,o){return this._writeCheck(),this._write(e,t,r,n,i,a,o)},le.prototype._write=function(e,t,r,n,i,a,o){if(this.write_in_progress=!0,e!==wc&&e!==_c&&e!==bc&&e!==mc&&e!==Li&&e!==Ec)throw new Error("Invalid flush value");t==null&&(t=new y(0),n=0,r=0),i._set?i.set=i._set:i.set=Hd;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 St:case qt:case At:f=rd(s,e);break;case Kt:case kr:case Rr:case Ht:f=Rd(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]},le.prototype._checkError=function(e,t,r){switch(e){case Or:case Ac:if(t.avail_out!==0&&r===Li)return!1;break;case xc:break;case Sc:return!1;default:return!1}return!0},le.prototype.close=function(){if(this.write_in_progress){this.pending_close=!0;return}this.pending_close=!1,this.mode===St||this.mode===qt||this.mode===At?nd(this.strm):Od(this.strm),this.mode=Mi};var Ir;le.prototype.reset=function(){switch(this.mode){case St:case At:Ir=Ms(this.strm);break;case kr:case Ht:Ir=gc(this.strm);break}Ir!==Or&&this._error(Ir)},le.prototype._error=function(e){this.onerror(ls[e]+": "+this.strm.msg,e),this.write_in_progress=!1,this.pending_close&&this.close()};var Rc=Object.freeze({__proto__:null,DEFLATE:St,DEFLATERAW:At,GUNZIP:Rr,GZIP:qt,INFLATE:kr,INFLATERAW:Ht,NONE:Mi,UNZIP:Kt,Z_BEST_COMPRESSION:Fd,Z_BEST_SPEED:jd,Z_BINARY:zd,Z_BLOCK:Ec,Z_BUF_ERROR:Ac,Z_DATA_ERROR:Dd,Z_DEFAULT_COMPRESSION:Nd,Z_DEFAULT_STRATEGY:Ud,Z_DEFLATED:kc,Z_ERRNO:Td,Z_FILTERED:Md,Z_FINISH:Li,Z_FIXED:Bd,Z_FULL_FLUSH:mc,Z_HUFFMAN_ONLY:Ld,Z_NEED_DICT:Sc,Z_NO_COMPRESSION:Cd,Z_NO_FLUSH:wc,Z_OK:Or,Z_PARTIAL_FLUSH:_c,Z_RLE:$d,Z_STREAM_END:xc,Z_STREAM_ERROR:Pd,Z_SYNC_FLUSH:bc,Z_TEXT:Zd,Z_TREES:Id,Z_UNKNOWN:qd,Zlib:le});function Kd(e,t){if(!e)throw new Error(t)}var E={};Object.keys(Rc).forEach(function(e){E[e]=Rc[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=16384,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 Vt={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(Vt).forEach(function(e){Vt[Vt[e]]=e});function Vd(e){return new nt(e)}function Wd(e){return new it(e)}function Gd(e){return new st(e)}function Yd(e){return new ct(e)}function Jd(e){return new at(e)}function Xd(e){return new ot(e)}function Qd(e){return new ft(e)}function ep(e,t,r){return typeof t=="function"&&(r=t,t={}),tt(new nt(t),e,r)}function tp(e,t){return rt(new nt(t),e)}function rp(e,t,r){return typeof t=="function"&&(r=t,t={}),tt(new at(t),e,r)}function np(e,t){return rt(new at(t),e)}function ip(e,t,r){return typeof t=="function"&&(r=t,t={}),tt(new st(t),e,r)}function ap(e,t){return rt(new st(t),e)}function op(e,t,r){return typeof t=="function"&&(r=t,t={}),tt(new ft(t),e,r)}function sp(e,t){return rt(new ft(t),e)}function cp(e,t,r){return typeof t=="function"&&(r=t,t={}),tt(new it(t),e,r)}function fp(e,t){return rt(new it(t),e)}function lp(e,t,r){return typeof t=="function"&&(r=t,t={}),tt(new ot(t),e,r)}function up(e,t){return rt(new ot(t),e)}function hp(e,t,r){return typeof t=="function"&&(r=t,t={}),tt(new ct(t),e,r)}function dp(e,t){return rt(new ct(t),e)}function tt(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=y.concat(n,i);n=[],r(null,f),e.close()}}function rt(e,t){if(typeof t=="string"&&(t=new y(t)),!y.isBuffer(t))throw new TypeError("Not a string or buffer");var r=E.Z_FINISH;return e._processChunk(t,r)}function nt(e){if(!(this instanceof nt))return new nt(e);N.call(this,e,E.DEFLATE)}function it(e){if(!(this instanceof it))return new it(e);N.call(this,e,E.INFLATE)}function at(e){if(!(this instanceof at))return new at(e);N.call(this,e,E.GZIP)}function ot(e){if(!(this instanceof ot))return new ot(e);N.call(this,e,E.GUNZIP)}function st(e){if(!(this instanceof st))return new st(e);N.call(this,e,E.DEFLATERAW)}function ct(e){if(!(this instanceof ct))return new ct(e);N.call(this,e,E.INFLATERAW)}function ft(e){if(!(this instanceof ft))return new ft(e);N.call(this,e,E.UNZIP)}function N(e,t){if(this._opts=e=e||{},this._chunkSize=e.chunkSize||E.Z_DEFAULT_CHUNK,ie.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&&!y.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=Vt[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 y(this._chunkSize),this._offset=0,this._closed=!1,this._level=n,this._strategy=i,this.once("end",this.close)}W(N,ie),N.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 Ae.nextTick(r)},N.prototype.reset=function(){return this._binding.reset()},N.prototype._flush=function(e){this._transform(new y(0),"",e)},N.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&&Ae.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 y(0),"",t)},N.prototype.close=function(e){if(e&&Ae.nextTick(e),!this._closed){this._closed=!0,this._binding.close();var t=this;Ae.nextTick(function(){t.emit("close")})}},N.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&&!y.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)},N.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(g){l=g});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=y.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(g,w){if(!o._hadError){var _=i-w;if(Kd(_>=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 y(o._chunkSize)),w===0){if(a+=n-g,n=g,!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(nt,N),W(it,N),W(at,N),W(ot,N),W(st,N),W(ct,N),W(ft,N);var Oc={codes:Vt,createDeflate:Vd,createInflate:Wd,createDeflateRaw:Gd,createInflateRaw:Yd,createGzip:Jd,createGunzip:Xd,createUnzip:Qd,deflate:ep,deflateSync:tp,gzip:rp,gzipSync:np,deflateRaw:ip,deflateRawSync:ap,unzip:op,unzipSync:sp,inflate:cp,inflateSync:fp,gunzip:lp,gunzipSync:up,inflateRaw:hp,inflateRawSync:dp,Deflate:nt,Inflate:it,Gzip:at,Gunzip:ot,DeflateRaw:st,InflateRaw:ct,Unzip:ft,Zlib:N};class Ic extends di{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=Oc.gzipSync(n).toString("base64"),this.client.putObject({key:Ee(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(Ee(this.keyPrefix,t));let n=await gt(r);return n=Buffer.from(n,"base64"),n=Oc.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(Ee(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 Tc extends O{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 pp={setup(e){},start(){},stop(){}},yp={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 gp extends Tc{constructor(t={}){super(),this.driver=t.driver}async setup(t){this.database=t,this.driver||(this.driver=new Ic({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=Ee(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 aa(a),a=Ee(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}}}return R.AuthenticationError=Xc,R.BaseError=Gi,R.Cache=di,R.CachePlugin=gp,R.Client=ia,R.ConnectionString=zr,R.CostsPlugin=yp,R.Database=fs,R.DatabaseError=Yc,R.EncryptionError=ef,R.ErrorMap=ta,R.InvalidResourceItem=Jt,R.MemoryCache=ch,R.MissingMetadata=Qi,R.NoSuchBucket=Ji,R.NoSuchKey=Ur,R.NotFound=Xi,R.PermissionError=Qc,R.Plugin=Tc,R.PluginObject=pp,R.ResourceIdsPageReader=rs,R.ResourceIdsReader=ts,R.ResourceNotFound=Yi,R.ResourceNotFoundError=Yi,R.ResourceReader=ns,R.ResourceWriter=is,R.S3Cache=Ic,R.S3DB=hi,R.S3DBError=re,R.S3_DEFAULT_ENDPOINT=na,R.S3_DEFAULT_REGION=ra,R.S3db=hi,R.S3dbError=re,R.UnknownError=ea,R.ValidationError=Jc,R.Validator=lo,R.ValidatorManager=uo,R.decrypt=oa,R.default=hi,R.encrypt=Zr,R.sha256=aa,R.streamToString=gt,Object.defineProperty(R,"__esModule",{value:!0}),R}({},nanoid,lodashEs,promisePool,clientS3,crypto,flat,FastestValidator,web);
|
|
31
|
+
`)}`);const{name:n,client:i,version:a="1",attributes:o={},behavior:s=oh,passphrase:f="secret",parallelism:c=10,observers:l=[],cache:d=!1,autoDecrypt:h=!0,timestamps:u=!1,partitions:p={},paranoid:g=!0,allNestedObjectsOptional:w=!0,hooks:_={},options:m={}}=t,x={cache:typeof m.cache=="boolean"?m.cache:d,autoDecrypt:typeof m.autoDecrypt=="boolean"?m.autoDecrypt:h,timestamps:typeof m.timestamps=="boolean"?m.timestamps:u,paranoid:typeof m.paranoid=="boolean"?m.paranoid:g,allNestedObjectsOptional:typeof m.allNestedObjectsOptional=="boolean"?m.allNestedObjectsOptional:w,partitions:m.partitions||p||{}};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:x.cache,hooks:_,paranoid:x.paranoid,timestamps:x.timestamps,partitions:x.partitions,autoDecrypt:x.autoDecrypt,allNestedObjectsOptional:x.allNestedObjectsOptional},this.hooks={preInsert:[],afterInsert:[],preUpdate:[],afterUpdate:[],preDelete:[],afterDelete:[]},this.attributes=o||{},this.config.timestamps&&(this.attributes.createdAt="string|optional",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.schema=new pe({name:n,attributes:this.attributes,passphrase:f,version:this.version,options:{autoDecrypt:this.config.autoDecrypt,allNestedObjectsOptional:this.config.allNestedObjectsOptional}}),this.setupPartitionHooks(),this.validatePartitions(),_){for(const[v,A]of Object.entries(_))if(Array.isArray(A)&&this.hooks[v])for(const I of A)typeof I=="function"&&this.hooks[v].push(I.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}updateAttributes(t){const r=this.attributes;return this.attributes=t,this.config.timestamps&&(t.createdAt="string|optional",t.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.schema=new pe({name:this.name,attributes:t,passphrase:this.passphrase,version:this.version,options:{autoDecrypt:this.config.autoDecrypt,allNestedObjectsOptional:this.config.allNestedObjectsOptional}}),this.setupPartitionHooks(),this.validatePartitions(),{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:M.cloneDeep(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 version '${this.version}'. Available fields: ${r.join(", ")}. This version of resource does not have support for this partition.`)}}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 Ee(`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(([s],[f])=>s.localeCompare(f));for(const[s,f]of o){const c=this.getNestedFieldValue(n,s),l=this.applyPartitionRule(c,f);if(l==null)return null;a.push(`${s}=${l}`)}return a.length===0?null:Ee(`resource=${this.name}`,`partition=${t}`,...a,`id=${r}`)}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 Jt({bucket:this.client.config.bucket,resourceName:this.name,attributes:n,validation:i});!t&&t!==0&&(t=qi());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=M.merge({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 gt(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 pe({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 gt(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=M.merge(n,i);delete a.id;const{isValid:o,errors:s,data:f}=await this.validate(a);if(!o)throw new Jt({bucket:this.client.bucket,resourceName:this.name,attributes:i,validation:s});const c=await this.schema.mapper(f),l=Ge(this.behavior),{mappedData:d,body:h}=await l.handleUpdate({resource:this,id:t,data:f,mappedData:c}),u=this.getResourceKey(t);let p,g=h;if(h===""&&this.behavior!=="body-overflow")try{const w=await this.client.getObject(u);if(w.ContentLength>0){const _=Buffer.from(await w.Body.transformToByteArray()),m=_.toString();try{JSON.parse(m)}catch{g=_,p=w.ContentType}}}catch{}return await this.client.putObject({key:u,body:g,contentType:p,metadata:d}),f.id=t,await this.executeHooks("afterUpdate",f),await this.updatePartitionReferences(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 ue.PromisePool.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=M.chunk(t.map(i=>this.getResourceKey(i)),1e3),{results:n}=await ue.PromisePool.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}={}){if(!t){let w=(await this.listIds({partition:t,partitionValues:r})).slice(i);n&&(w=w.slice(0,n));const{results:_,errors:m}=await ue.PromisePool.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])throw new Error(`Partition '${t}' not found`);const a=this.config.partitions[t],o=[],s=Object.entries(a.fields).sort(([g],[w])=>g.localeCompare(w));for(const[g,w]of s){const _=r[g];if(_!=null){const m=this.applyPartitionRule(_,w);o.push(`${g}=${m}`)}}let f;o.length>0?f=`resource=${this.name}/partition=${t}/${o.join("/")}`:f=`resource=${this.name}/partition=${t}`;let d=(await this.client.getAllKeys({prefix:f})).map(g=>{const _=g.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 ue.PromisePool.for(d).withConcurrency(this.parallelism).handleError(async(g,w)=>(console.warn(`Failed to get partition resource ${w}:`,g.message),null)).process(async g=>{try{return await this.getFromPartition({id:g,partitionName:t,partitionValues:r})}catch(w){if(w.message.includes("Cipher job failed")||w.message.includes("OperationError"))return console.warn(`Decryption failed for partition resource ${g}, returning basic info`),{id:g,_partition:t,_partitionValues:r,_decryptionFailed:!0,_error:w.message};throw w}}),p=h.filter(g=>g!==null);return this.emit("list",{partition:t,partitionValues:r,count:p.length,errors:u.length}),p}async getMany(t){const{results:r,errors:n}=await ue.PromisePool.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 ue.PromisePool.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}={}){let o=null,s=null;a||(o=await this.count({partition:n,partitionValues:i}),s=Math.ceil(o/r));const f=Math.floor(t/r),c=await this.list({partition:n,partitionValues:i,limit:r,offset:t}),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}readable(){return new ns({resource:this}).build()}writable(){return new is({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=fo(t);return`sha256:${Bi.createHash("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 pe({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 updatePartitionReferences(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.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=Ee(`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 gt(w.Body)}catch{u=""}const{metadata:p}=await h.handleGet({resource:this,metadata:d,body:u});let g=p;return g.id=t,g._contentLength=f.ContentLength,g._lastModified=f.LastModified,g._hasContent=f.ContentLength>0,g._mimeType=f.ContentType||null,g._partition=r,g._partitionValues=n,f.VersionId&&(g._versionId=f.VersionId),f.Expiration&&(g._expiresAt=f.Expiration),g._definitionHash=this.getDefinitionHash(),this.emit("getFromPartition",g),g}}function sh(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 fs extends O{constructor(t){super(),this.version="1",this.s3dbVersion=(()=>{try{return"4.1.10"}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;!r&&(t.bucket||t.accessKeyId||t.secretAccessKey)&&(r=zr.buildFromParams({bucket:t.bucket,region:t.region,accessKeyId:t.accessKeyId,secretAccessKey:t.secretAccessKey,endpoint:t.endpoint,forcePathStyle:t.forcePathStyle})),this.client=t.client||new ia({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 gt(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 ui({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.options?.timestamps||!1,partitions:i.partitions||o.options?.partitions||{},paranoid:o.options?.paranoid!==!1,allNestedObjectsOptional:o.options?.allNestedObjectsOptional||!1,autoDecrypt:o.options?.autoDecrypt!==!1,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=fo(a);return`sha256:${Bi.createHash("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(!M.isEmpty(this.plugins)){const r=this.plugins.map(a=>M.isFunction(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,options:{timestamps:n.config.timestamps,partitions:n.config.partitions,paranoid:n.config.paranoid,allNestedObjectsOptional:n.config.allNestedObjectsOptional,autoDecrypt:n.config.autoDecrypt,cache:n.config.cache},behavior:i.behavior||"user-management",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,options:n={},behavior:i="user-management"}){if(!this.resources[t])return{exists:!1,sameHash:!1,hash:null};const a=new ui({name:t,attributes:r,behavior:i,observers:[],client:this.client,version:"temp",passphrase:this.passphrase,cache:this.cache,...n}),o=this.generateDefinitionHash(a.export(),i),s=this.generateDefinitionHash(this.resources[t].export(),this.resources[t].behavior);return{exists:!0,sameHash:o===s,hash:o,existingHash:s}}async createResourceIfNotExists({name:t,attributes:r,options:n={},behavior:i="user-management"}){const a=!!this.resources[t],o=this.resourceExistsWithSameHash({name:t,attributes:r,options:n,behavior:i});return o.exists&&o.sameHash?{resource:this.resources[t],created:!1,reason:"Resource already exists with same definition hash"}:{resource:await this.createResource({name:t,attributes:r,options:n,behavior:i}),created:!a,reason:a?"Resource updated with new definition":"New resource created"}}async createResource({name:t,attributes:r,options:n={},behavior:i="user-management"}){if(this.resources[t]){const f=this.resources[t];Object.assign(f.config,{cache:this.cache,...n}),i&&(f.behavior=i),f.updateAttributes(r);const c=this.generateDefinitionHash(f.export(),f.behavior),l=this.savedMetadata?.resources?.[t],d=l?.currentVersion||"v0",h=l?.versions?.[d];return(!h||h.hash!==c)&&await this.uploadMetadataFile(),this.emit("s3db.resourceUpdated",t),f}const o=this.savedMetadata?.resources?.[t]?.currentVersion||"v0",s=new ui({name:t,attributes:r,behavior:i,observers:[this],client:this.client,version:o,passphrase:this.passphrase,cache:this.cache,...n});return this.resources[t]=s,await this.uploadMetadataFile(),this.emit("s3db.resourceCreated",t),s}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 hi extends fs{}class di extends O{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 ch extends di{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 ls={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 fh(){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 Re(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 pr=Uint8Array,se=Uint16Array,yr=Int32Array,lh=4,us=0,hs=1,uh=2;function wt(e){for(var t=e.length;--t>=0;)e[t]=0}var hh=0,ds=1,dh=2,ph=3,yh=258,pi=29,Dt=256,Ct=Dt+1+pi,_t=30,yi=19,ps=2*Ct+1,Ye=15,gi=16,gh=7,vi=256,ys=16,gs=17,vs=18,wi=[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],gr=[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],ws=[16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15],wh=512,Oe=new Array((Ct+2)*2);wt(Oe);var jt=new Array(_t*2);wt(jt);var Ft=new Array(wh);wt(Ft);var Nt=new Array(yh-ph+1);wt(Nt);var _i=new Array(pi);wt(_i);var vr=new Array(_t);wt(vr);function bi(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 _s,bs,ms;function mi(e,t){this.dyn_tree=e,this.max_code=0,this.stat_desc=t}function Es(e){return e<256?Ft[e]:Ft[256+(e>>>7)]}function Mt(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>gi-r?(e.bi_buf|=t<<e.bi_valid&65535,Mt(e,e.bi_buf),e.bi_buf=t>>gi-e.bi_valid,e.bi_valid+=r-gi):(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 xs(e,t){var r=0;do r|=e&1,e>>>=1,r<<=1;while(--t>0);return r>>>1}function _h(e){e.bi_valid===16?(Mt(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 bh(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,g=0;for(h=0;h<=Ye;h++)e.bl_count[h]=0;for(r[e.heap[e.heap_max]*2+1]=0,c=e.heap_max+1;c<ps;c++)l=e.heap[c],h=r[r[l*2+1]*2+1]+1,h>f&&(h=f,g++),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(g!==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]--,g-=2}while(g>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 Ss(e,t,r){var n=new Array(Ye+1),i=0,a,o;for(a=1;a<=Ye;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]=xs(n[s]++,s))}}function mh(){var e,t,r,n,i,a=new Array(Ye+1);for(r=0,n=0;n<pi-1;n++)for(_i[n]=r,e=0;e<1<<wi[n];e++)Nt[r++]=n;for(Nt[r-1]=n,i=0,n=0;n<16;n++)for(vr[n]=i,e=0;e<1<<gr[n];e++)Ft[i++]=n;for(i>>=7;n<_t;n++)for(vr[n]=i<<7,e=0;e<1<<gr[n]-7;e++)Ft[256+i++]=n;for(t=0;t<=Ye;t++)a[t]=0;for(e=0;e<=143;)Oe[e*2+1]=8,e++,a[8]++;for(;e<=255;)Oe[e*2+1]=9,e++,a[9]++;for(;e<=279;)Oe[e*2+1]=7,e++,a[7]++;for(;e<=287;)Oe[e*2+1]=8,e++,a[8]++;for(Ss(Oe,Ct+1,a),e=0;e<_t;e++)jt[e*2+1]=5,jt[e*2]=xs(e,5);_s=new bi(Oe,wi,Dt+1,Ct,Ye),bs=new bi(jt,gr,0,_t,Ye),ms=new bi(new Array(0),vh,0,yi,gh)}function As(e){var t;for(t=0;t<Ct;t++)e.dyn_ltree[t*2]=0;for(t=0;t<_t;t++)e.dyn_dtree[t*2]=0;for(t=0;t<yi;t++)e.bl_tree[t*2]=0;e.dyn_ltree[vi*2]=1,e.opt_len=e.static_len=0,e.last_lit=e.matches=0}function ks(e){e.bi_valid>8?Mt(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 Eh(e,t,r,n){ks(e),Mt(e,r),Mt(e,~r),Re(e.pending_buf,e.window,t,r,e.pending),e.pending+=r}function Rs(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 Ei(e,t,r){for(var n=e.heap[r],i=r<<1;i<=e.heap_len&&(i<e.heap_len&&Rs(t,e.heap[i+1],e.heap[i],e.depth)&&i++,!Rs(t,n,e.heap[i],e.depth));)e.heap[r]=e.heap[i],r=i,i<<=1;e.heap[r]=n}function Os(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+Dt+1,t),s=wi[o],s!==0&&(i-=_i[o],Q(e,i,s)),n--,o=Es(n),ve(e,o,r),s=gr[o],s!==0&&(n-=vr[o],Q(e,n,s)));while(a<e.last_lit);ve(e,vi,t)}function xi(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=ps,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--)Ei(e,r,o);c=a;do o=e.heap[1],e.heap[1]=e.heap[e.heap_len--],Ei(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++,Ei(e,r,1);while(e.heap_len>=2);e.heap[--e.heap_max]=e.heap[1],bh(e,t),Ss(r,f,e.bl_count)}function Is(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[ys*2]++):s<=10?e.bl_tree[gs*2]++:e.bl_tree[vs*2]++,s=0,i=a,o===0?(f=138,c=3):a===o?(f=6,c=3):(f=7,c=4))}function Ts(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,ys,e.bl_tree),Q(e,s-3,2)):s<=10?(ve(e,gs,e.bl_tree),Q(e,s-3,3)):(ve(e,vs,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 xh(e){var t;for(Is(e,e.dyn_ltree,e.l_desc.max_code),Is(e,e.dyn_dtree,e.d_desc.max_code),xi(e,e.bl_desc),t=yi-1;t>=3&&e.bl_tree[ws[t]*2+1]===0;t--);return e.opt_len+=3*(t+1)+5+5+4,t}function Sh(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[ws[i]*2+1],3);Ts(e,e.dyn_ltree,t-1),Ts(e,e.dyn_dtree,r-1)}function Ah(e){var t=4093624447,r;for(r=0;r<=31;r++,t>>>=1)if(t&1&&e.dyn_ltree[r*2]!==0)return us;if(e.dyn_ltree[18]!==0||e.dyn_ltree[20]!==0||e.dyn_ltree[26]!==0)return hs;for(r=32;r<Dt;r++)if(e.dyn_ltree[r*2]!==0)return hs;return us}var Ps=!1;function kh(e){Ps||(mh(),Ps=!0),e.l_desc=new mi(e.dyn_ltree,_s),e.d_desc=new mi(e.dyn_dtree,bs),e.bl_desc=new mi(e.bl_tree,ms),e.bi_buf=0,e.bi_valid=0,As(e)}function Ds(e,t,r,n){Q(e,(hh<<1)+(n?1:0),3),Eh(e,t,r)}function Rh(e){Q(e,ds<<1,3),ve(e,vi,Oe),_h(e)}function Oh(e,t,r,n){var i,a,o=0;e.level>0?(e.strm.data_type===uh&&(e.strm.data_type=Ah(e)),xi(e,e.l_desc),xi(e,e.d_desc),o=xh(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?Ds(e,t,r,n):e.strategy===lh||a===i?(Q(e,(ds<<1)+(n?1:0),3),Os(e,Oe,jt)):(Q(e,(dh<<1)+(n?1:0),3),Sh(e,e.l_desc.max_code+1,e.d_desc.max_code+1,o+1),Os(e,e.dyn_ltree,e.dyn_dtree)),As(e),n&&ks(e)}function Ne(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]+Dt+1)*2]++,e.dyn_dtree[Es(t)*2]++),e.last_lit===e.lit_bufsize-1}function Si(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 Ih(){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 Th=Ih();function q(e,t,r,n){var i=Th,a=n+r;e^=-1;for(var o=n;o<a;o++)e=e>>>8^i[(e^t[o])&255];return e^-1}var Je=0,Ph=1,Dh=3,Me=4,Cs=5,Le=0,js=1,$e=-2,Ch=-3,Ai=-5,jh=-1,Fh=1,wr=2,Nh=3,Mh=4,Lh=2,ki=8,$h=9,Bh=29,Uh=256,Ri=Uh+1+Bh,zh=30,Zh=19,qh=2*Ri+1,Hh=15,D=3,Be=258,fe=Be+D+1,Kh=32,Oi=42,Ii=69,_r=73,br=91,mr=103,Xe=113,Lt=666,z=1,$t=2,Qe=3,bt=4,Vh=3;function Ue(e,t){return e.msg=ls[t],t}function Fs(e){return(e<<1)-(e>4?9:0)}function et(e){for(var t=e.length;--t>=0;)e[t]=0}function ze(e){var t=e.state,r=t.pending;r>e.avail_out&&(r=e.avail_out),r!==0&&(Re(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 K(e,t){Oh(e,e.block_start>=0?e.block_start:-1,e.strstart-e.block_start,t),e.block_start=e.strstart,ze(e.strm)}function P(e,t){e.pending_buf[e.pending++]=t}function Bt(e,t){e.pending_buf[e.pending++]=t>>>8&255,e.pending_buf[e.pending++]=t&255}function Wh(e,t,r,n){var i=e.avail_in;return i>n&&(i=n),i===0?0:(e.avail_in-=i,Re(t,e.input,e.next_in,i,r),e.state.wrap===1?e.adler=Si(e.adler,t,i,r):e.state.wrap===2&&(e.adler=q(e.adler,t,i,r)),e.next_in+=i,e.total_in+=i,i)}function Ns(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-fe?e.strstart-(e.w_size-fe):0,c=e.window,l=e.w_mask,d=e.prev,h=e.strstart+Be,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=Be-(h-n),n=h-Be,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 Ut(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-fe)){Re(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=Wh(e.strm,e.window,e.strstart+e.lookahead,a),e.lookahead+=n,e.lookahead+e.insert>=D)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+D-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<D)););}while(e.lookahead<fe&&e.strm.avail_in!==0)}function Gh(e,t){var r=65535;for(r>e.pending_buf_size-5&&(r=e.pending_buf_size-5);;){if(e.lookahead<=1){if(Ut(e),e.lookahead===0&&t===Je)return z;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,K(e,!1),e.strm.avail_out===0)||e.strstart-e.block_start>=e.w_size-fe&&(K(e,!1),e.strm.avail_out===0))return z}return e.insert=0,t===Me?(K(e,!0),e.strm.avail_out===0?Qe:bt):(e.strstart>e.block_start&&(K(e,!1),e.strm.avail_out===0),z)}function Ti(e,t){for(var r,n;;){if(e.lookahead<fe){if(Ut(e),e.lookahead<fe&&t===Je)return z;if(e.lookahead===0)break}if(r=0,e.lookahead>=D&&(e.ins_h=(e.ins_h<<e.hash_shift^e.window[e.strstart+D-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-fe&&(e.match_length=Ns(e,r)),e.match_length>=D)if(n=Ne(e,e.strstart-e.match_start,e.match_length-D),e.lookahead-=e.match_length,e.match_length<=e.max_lazy_match&&e.lookahead>=D){e.match_length--;do e.strstart++,e.ins_h=(e.ins_h<<e.hash_shift^e.window[e.strstart+D-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=Ne(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++;if(n&&(K(e,!1),e.strm.avail_out===0))return z}return e.insert=e.strstart<D-1?e.strstart:D-1,t===Me?(K(e,!0),e.strm.avail_out===0?Qe:bt):e.last_lit&&(K(e,!1),e.strm.avail_out===0)?z:$t}function mt(e,t){for(var r,n,i;;){if(e.lookahead<fe){if(Ut(e),e.lookahead<fe&&t===Je)return z;if(e.lookahead===0)break}if(r=0,e.lookahead>=D&&(e.ins_h=(e.ins_h<<e.hash_shift^e.window[e.strstart+D-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=D-1,r!==0&&e.prev_length<e.max_lazy_match&&e.strstart-r<=e.w_size-fe&&(e.match_length=Ns(e,r),e.match_length<=5&&(e.strategy===Fh||e.match_length===D&&e.strstart-e.match_start>4096)&&(e.match_length=D-1)),e.prev_length>=D&&e.match_length<=e.prev_length){i=e.strstart+e.lookahead-D,n=Ne(e,e.strstart-1-e.prev_match,e.prev_length-D),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+D-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=D-1,e.strstart++,n&&(K(e,!1),e.strm.avail_out===0))return z}else if(e.match_available){if(n=Ne(e,0,e.window[e.strstart-1]),n&&K(e,!1),e.strstart++,e.lookahead--,e.strm.avail_out===0)return z}else e.match_available=1,e.strstart++,e.lookahead--}return e.match_available&&(n=Ne(e,0,e.window[e.strstart-1]),e.match_available=0),e.insert=e.strstart<D-1?e.strstart:D-1,t===Me?(K(e,!0),e.strm.avail_out===0?Qe:bt):e.last_lit&&(K(e,!1),e.strm.avail_out===0)?z:$t}function Yh(e,t){for(var r,n,i,a,o=e.window;;){if(e.lookahead<=Be){if(Ut(e),e.lookahead<=Be&&t===Je)return z;if(e.lookahead===0)break}if(e.match_length=0,e.lookahead>=D&&e.strstart>0&&(i=e.strstart-1,n=o[i],n===o[++i]&&n===o[++i]&&n===o[++i])){a=e.strstart+Be;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=Be-(a-i),e.match_length>e.lookahead&&(e.match_length=e.lookahead)}if(e.match_length>=D?(r=Ne(e,1,e.match_length-D),e.lookahead-=e.match_length,e.strstart+=e.match_length,e.match_length=0):(r=Ne(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++),r&&(K(e,!1),e.strm.avail_out===0))return z}return e.insert=0,t===Me?(K(e,!0),e.strm.avail_out===0?Qe:bt):e.last_lit&&(K(e,!1),e.strm.avail_out===0)?z:$t}function Jh(e,t){for(var r;;){if(e.lookahead===0&&(Ut(e),e.lookahead===0)){if(t===Je)return z;break}if(e.match_length=0,r=Ne(e,0,e.window[e.strstart]),e.lookahead--,e.strstart++,r&&(K(e,!1),e.strm.avail_out===0))return z}return e.insert=0,t===Me?(K(e,!0),e.strm.avail_out===0?Qe:bt):e.last_lit&&(K(e,!1),e.strm.avail_out===0)?z:$t}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 Et;Et=[new we(0,0,0,0,Gh),new we(4,4,8,4,Ti),new we(4,5,16,8,Ti),new we(4,6,32,32,Ti),new we(4,4,16,16,mt),new we(8,16,32,32,mt),new we(8,16,128,128,mt),new we(8,32,128,256,mt),new we(32,128,258,1024,mt),new we(32,258,258,4096,mt)];function Xh(e){e.window_size=2*e.w_size,et(e.head),e.max_lazy_match=Et[e.level].max_lazy,e.good_match=Et[e.level].good_length,e.nice_match=Et[e.level].nice_length,e.max_chain_length=Et[e.level].max_chain,e.strstart=0,e.block_start=0,e.lookahead=0,e.insert=0,e.match_length=e.prev_length=D-1,e.match_available=0,e.ins_h=0}function Qh(){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=ki,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 se(qh*2),this.dyn_dtree=new se((2*zh+1)*2),this.bl_tree=new se((2*Zh+1)*2),et(this.dyn_ltree),et(this.dyn_dtree),et(this.bl_tree),this.l_desc=null,this.d_desc=null,this.bl_desc=null,this.bl_count=new se(Hh+1),this.heap=new se(2*Ri+1),et(this.heap),this.heap_len=0,this.heap_max=0,this.depth=new se(2*Ri+1),et(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 ed(e){var t;return!e||!e.state?Ue(e,$e):(e.total_in=e.total_out=0,e.data_type=Lh,t=e.state,t.pending=0,t.pending_out=0,t.wrap<0&&(t.wrap=-t.wrap),t.status=t.wrap?Oi:Xe,e.adler=t.wrap===2?0:1,t.last_flush=Je,kh(t),Le)}function Ms(e){var t=ed(e);return t===Le&&Xh(e.state),t}function td(e,t,r,n,i,a){if(!e)return $e;var o=1;if(t===jh&&(t=6),n<0?(o=0,n=-n):n>15&&(o=2,n-=16),i<1||i>$h||r!==ki||n<8||n>15||t<0||t>9||a<0||a>Mh)return Ue(e,$e);n===8&&(n=9);var s=new Qh;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+D-1)/D),s.window=new pr(s.w_size*2),s.head=new se(s.hash_size),s.prev=new se(s.w_size),s.lit_bufsize=1<<i+6,s.pending_buf_size=s.lit_bufsize*4,s.pending_buf=new pr(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,Ms(e)}function rd(e,t){var r,n,i,a;if(!e||!e.state||t>Cs||t<0)return e?Ue(e,$e):$e;if(n=e.state,!e.output||!e.input&&e.avail_in!==0||n.status===Lt&&t!==Me)return Ue(e,e.avail_out===0?Ai:$e);if(n.strm=e,r=n.last_flush,n.last_flush=t,n.status===Oi)if(n.wrap===2)e.adler=0,P(n,31),P(n,139),P(n,8),n.gzhead?(P(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)),P(n,n.gzhead.time&255),P(n,n.gzhead.time>>8&255),P(n,n.gzhead.time>>16&255),P(n,n.gzhead.time>>24&255),P(n,n.level===9?2:n.strategy>=wr||n.level<2?4:0),P(n,n.gzhead.os&255),n.gzhead.extra&&n.gzhead.extra.length&&(P(n,n.gzhead.extra.length&255),P(n,n.gzhead.extra.length>>8&255)),n.gzhead.hcrc&&(e.adler=q(e.adler,n.pending_buf,n.pending,0)),n.gzindex=0,n.status=Ii):(P(n,0),P(n,0),P(n,0),P(n,0),P(n,0),P(n,n.level===9?2:n.strategy>=wr||n.level<2?4:0),P(n,Vh),n.status=Xe);else{var o=ki+(n.w_bits-8<<4)<<8,s=-1;n.strategy>=wr||n.level<2?s=0:n.level<6?s=1:n.level===6?s=2:s=3,o|=s<<6,n.strstart!==0&&(o|=Kh),o+=31-o%31,n.status=Xe,Bt(n,o),n.strstart!==0&&(Bt(n,e.adler>>>16),Bt(n,e.adler&65535)),e.adler=1}if(n.status===Ii)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=q(e.adler,n.pending_buf,n.pending-i,i)),ze(e),i=n.pending,n.pending===n.pending_buf_size));)P(n,n.gzhead.extra[n.gzindex]&255),n.gzindex++;n.gzhead.hcrc&&n.pending>i&&(e.adler=q(e.adler,n.pending_buf,n.pending-i,i)),n.gzindex===n.gzhead.extra.length&&(n.gzindex=0,n.status=_r)}else n.status=_r;if(n.status===_r)if(n.gzhead.name){i=n.pending;do{if(n.pending===n.pending_buf_size&&(n.gzhead.hcrc&&n.pending>i&&(e.adler=q(e.adler,n.pending_buf,n.pending-i,i)),ze(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,P(n,a)}while(a!==0);n.gzhead.hcrc&&n.pending>i&&(e.adler=q(e.adler,n.pending_buf,n.pending-i,i)),a===0&&(n.gzindex=0,n.status=br)}else n.status=br;if(n.status===br)if(n.gzhead.comment){i=n.pending;do{if(n.pending===n.pending_buf_size&&(n.gzhead.hcrc&&n.pending>i&&(e.adler=q(e.adler,n.pending_buf,n.pending-i,i)),ze(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,P(n,a)}while(a!==0);n.gzhead.hcrc&&n.pending>i&&(e.adler=q(e.adler,n.pending_buf,n.pending-i,i)),a===0&&(n.status=mr)}else n.status=mr;if(n.status===mr&&(n.gzhead.hcrc?(n.pending+2>n.pending_buf_size&&ze(e),n.pending+2<=n.pending_buf_size&&(P(n,e.adler&255),P(n,e.adler>>8&255),e.adler=0,n.status=Xe)):n.status=Xe),n.pending!==0){if(ze(e),e.avail_out===0)return n.last_flush=-1,Le}else if(e.avail_in===0&&Fs(t)<=Fs(r)&&t!==Me)return Ue(e,Ai);if(n.status===Lt&&e.avail_in!==0)return Ue(e,Ai);if(e.avail_in!==0||n.lookahead!==0||t!==Je&&n.status!==Lt){var f=n.strategy===wr?Jh(n,t):n.strategy===Nh?Yh(n,t):Et[n.level].func(n,t);if((f===Qe||f===bt)&&(n.status=Lt),f===z||f===Qe)return e.avail_out===0&&(n.last_flush=-1),Le;if(f===$t&&(t===Ph?Rh(n):t!==Cs&&(Ds(n,0,0,!1),t===Dh&&(et(n.head),n.lookahead===0&&(n.strstart=0,n.block_start=0,n.insert=0))),ze(e),e.avail_out===0))return n.last_flush=-1,Le}return t!==Me?Le:n.wrap<=0?js:(n.wrap===2?(P(n,e.adler&255),P(n,e.adler>>8&255),P(n,e.adler>>16&255),P(n,e.adler>>24&255),P(n,e.total_in&255),P(n,e.total_in>>8&255),P(n,e.total_in>>16&255),P(n,e.total_in>>24&255)):(Bt(n,e.adler>>>16),Bt(n,e.adler&65535)),ze(e),n.wrap>0&&(n.wrap=-n.wrap),n.pending!==0?Le:js)}function nd(e){var t;return!e||!e.state?$e:(t=e.state.status,t!==Oi&&t!==Ii&&t!==_r&&t!==br&&t!==mr&&t!==Xe&&t!==Lt?Ue(e,$e):(e.state=null,t===Xe?Ue(e,Ch):Le))}var Er=30,id=12;function ad(e,t){var r,n,i,a,o,s,f,c,l,d,h,u,p,g,w,_,m,x,v,A,I,b,S,T,k;r=e.state,n=e.next_in,T=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,g=r.lencode,w=r.distcode,_=(1<<r.lenbits)-1,m=(1<<r.distbits)-1;e:do{p<15&&(u+=T[n++]<<p,p+=8,u+=T[n++]<<p,p+=8),x=g[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+=T[n++]<<p,p+=8),A+=u&(1<<v)-1,u>>>=v,p-=v),p<15&&(u+=T[n++]<<p,p+=8,u+=T[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(I=x&65535,v&=15,p<v&&(u+=T[n++]<<p,p+=8,p<v&&(u+=T[n++]<<p,p+=8)),I+=u&(1<<v)-1,I>f){e.msg="invalid distance too far back",r.mode=Er;break e}if(u>>>=v,p-=v,v=a-o,I>v){if(v=I-v,v>l&&r.sane){e.msg="invalid distance too far back",r.mode=Er;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-I,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-I,S=k}}}else if(b+=d-v,v<A){A-=v;do k[a++]=h[b++];while(--v);b=a-I,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-I;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=Er;break e}break}}else if((v&64)===0){x=g[(x&65535)+(u&(1<<v)-1)];continue t}else if(v&32){r.mode=id;break e}else{e.msg="invalid literal/length code",r.mode=Er;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 xt=15,Ls=852,$s=592,Bs=0,Pi=1,Us=2,od=[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],sd=[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],cd=[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],fd=[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 zt(e,t,r,n,i,a,o,s){var f=s.bits,c=0,l=0,d=0,h=0,u=0,p=0,g=0,w=0,_=0,m=0,x,v,A,I,b,S=null,T=0,k,j=new se(xt+1),V=new se(xt+1),Y=null,ce=0,lt,ee,_e;for(c=0;c<=xt;c++)j[c]=0;for(l=0;l<n;l++)j[t[r+l]]++;for(u=f,h=xt;h>=1&&j[h]===0;h--);if(u>h&&(u=h),h===0)return i[a++]=20971520,i[a++]=20971520,s.bits=1,0;for(d=1;d<h&&j[d]===0;d++);for(u<d&&(u=d),w=1,c=1;c<=xt;c++)if(w<<=1,w-=j[c],w<0)return-1;if(w>0&&(e===Bs||h!==1))return-1;for(V[1]=0,c=1;c<xt;c++)V[c+1]=V[c]+j[c];for(l=0;l<n;l++)t[r+l]!==0&&(o[V[t[r+l]]++]=l);if(e===Bs?(S=Y=o,k=19):e===Pi?(S=od,T-=257,Y=sd,ce-=257,k=256):(S=cd,Y=fd,k=-1),m=0,l=0,c=d,b=a,p=u,g=0,A=-1,_=1<<u,I=_-1,e===Pi&&_>Ls||e===Us&&_>$s)return 1;for(;;){lt=c-g,o[l]<k?(ee=0,_e=o[l]):o[l]>k?(ee=Y[ce+o[l]],_e=S[T+o[l]]):(ee=96,_e=0),x=1<<c-g,v=1<<p,d=v;do v-=x,i[b+(m>>g)+v]=lt<<24|ee<<16|_e|0;while(v!==0);for(x=1<<c-1;m&x;)x>>=1;if(x!==0?(m&=x-1,m+=x):m=0,l++,--j[c]===0){if(c===h)break;c=t[r+o[l]]}if(c>u&&(m&I)!==A){for(g===0&&(g=u),b+=d,p=c-g,w=1<<p;p+g<h&&(w-=j[p+g],!(w<=0));)p++,w<<=1;if(_+=1<<p,e===Pi&&_>Ls||e===Us&&_>$s)return 1;A=m&I,i[A]=u<<24|p<<16|b-a|0}}return m!==0&&(i[b+m]=c-g<<24|4194304|0),s.bits=u,0}var ld=0,zs=1,Zs=2,qs=4,ud=5,xr=6,Zt=0,hd=1,dd=2,Ze=-2,pd=-3,yd=-4,gd=-5,Hs=8,Ks=1,Vs=2,Ws=3,Gs=4,Ys=5,Js=6,Xs=7,Qs=8,ec=9,tc=10,rc=11,Ie=12,Di=13,nc=14,Ci=15,ic=16,ac=17,oc=18,sc=19,Sr=20,Ar=21,cc=22,fc=23,lc=24,uc=25,hc=26,ji=27,dc=28,pc=29,F=30,vd=31,wd=32,_d=852,bd=592;function yc(e){return(e>>>24&255)+(e>>>8&65280)+((e&65280)<<8)+((e&255)<<24)}function md(){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 se(320),this.work=new se(288),this.lendyn=null,this.distdyn=null,this.sane=0,this.back=0,this.was=0}function Ed(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=Ks,t.last=0,t.havedict=0,t.dmax=32768,t.head=null,t.hold=0,t.bits=0,t.lencode=t.lendyn=new yr(_d),t.distcode=t.distdyn=new yr(bd),t.sane=1,t.back=-1,Zt)}function gc(e){var t;return!e||!e.state?Ze:(t=e.state,t.wsize=0,t.whave=0,t.wnext=0,Ed(e))}function xd(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,gc(e))}function Sd(e,t){var r,n;return e?(n=new md,e.state=n,n.window=null,r=xd(e,t),r!==Zt&&(e.state=null),r):Ze}var vc=!0,Fi,Ni;function Ad(e){if(vc){var t;for(Fi=new yr(512),Ni=new yr(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(zt(zs,e.lens,0,288,Fi,0,e.work,{bits:9}),t=0;t<32;)e.lens[t++]=5;zt(Zs,e.lens,0,32,Ni,0,e.work,{bits:5}),vc=!1}e.lencode=Fi,e.lenbits=9,e.distcode=Ni,e.distbits=5}function kd(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 pr(a.wsize)),n>=a.wsize?(Re(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),Re(a.window,t,r-n,i,a.wnext),n-=i,n?(Re(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 Rd(e,t){var r,n,i,a,o,s,f,c,l,d,h,u,p,g,w=0,_,m,x,v,A,I,b,S,T=new pr(4),k,j,V=[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===Ie&&(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=Zt;e:for(;;)switch(r.mode){case Ks: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,T[0]=c&255,T[1]=c>>>8&255,r.check=q(r.check,T,2,0),c=0,l=0,r.mode=Vs;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=F;break}if((c&15)!==Hs){e.msg="unknown compression method",r.mode=F;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=F;break}r.dmax=1<<b,e.adler=r.check=1,r.mode=c&512?tc:Ie,c=0,l=0;break;case Vs:for(;l<16;){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}if(r.flags=c,(r.flags&255)!==Hs){e.msg="unknown compression method",r.mode=F;break}if(r.flags&57344){e.msg="unknown header flags set",r.mode=F;break}r.head&&(r.head.text=c>>8&1),r.flags&512&&(T[0]=c&255,T[1]=c>>>8&255,r.check=q(r.check,T,2,0)),c=0,l=0,r.mode=Ws;case Ws:for(;l<32;){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}r.head&&(r.head.time=c),r.flags&512&&(T[0]=c&255,T[1]=c>>>8&255,T[2]=c>>>16&255,T[3]=c>>>24&255,r.check=q(r.check,T,4,0)),c=0,l=0,r.mode=Gs;case Gs: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&&(T[0]=c&255,T[1]=c>>>8&255,r.check=q(r.check,T,2,0)),c=0,l=0,r.mode=Ys;case Ys: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&&(T[0]=c&255,T[1]=c>>>8&255,r.check=q(r.check,T,2,0)),c=0,l=0}else r.head&&(r.head.extra=null);r.mode=Js;case Js: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)),Re(r.head.extra,n,a,u,b)),r.flags&512&&(r.check=q(r.check,n,u,a)),s-=u,a+=u,r.length-=u),r.length))break e;r.length=0,r.mode=Xs;case Xs: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=q(r.check,n,u,a)),s-=u,a+=u,b)break e}else r.head&&(r.head.name=null);r.length=0,r.mode=Qs;case Qs: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=q(r.check,n,u,a)),s-=u,a+=u,b)break e}else r.head&&(r.head.comment=null);r.mode=ec;case ec: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=F;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=Ie;break;case tc:for(;l<32;){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}e.adler=r.check=yc(c),c=0,l=0,r.mode=rc;case rc: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,dd;e.adler=r.check=1,r.mode=Ie;case Ie:if(t===ud||t===xr)break e;case Di:if(r.last){c>>>=l&7,l-=l&7,r.mode=ji;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=nc;break;case 1:if(Ad(r),r.mode=Sr,t===xr){c>>>=2,l-=2;break e}break;case 2:r.mode=ac;break;case 3:e.msg="invalid block type",r.mode=F}c>>>=2,l-=2;break;case nc: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=F;break}if(r.length=c&65535,c=0,l=0,r.mode=Ci,t===xr)break e;case Ci:r.mode=ic;case ic:if(u=r.length,u){if(u>s&&(u=s),u>f&&(u=f),u===0)break e;Re(i,n,a,u,o),s-=u,a+=u,f-=u,o+=u,r.length-=u;break}r.mode=Ie;break;case ac: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=F;break}r.have=0,r.mode=oc;case oc:for(;r.have<r.ncode;){for(;l<3;){if(s===0)break e;s--,c+=n[a++]<<l,l+=8}r.lens[V[r.have++]]=c&7,c>>>=3,l-=3}for(;r.have<19;)r.lens[V[r.have++]]=0;if(r.lencode=r.lendyn,r.lenbits=7,k={bits:r.lenbits},S=zt(ld,r.lens,0,19,r.lencode,0,r.work,k),r.lenbits=k.bits,S){e.msg="invalid code lengths set",r.mode=F;break}r.have=0,r.mode=sc;case sc: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(j=_+2;l<j;){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=F;break}b=r.lens[r.have-1],u=3+(c&3),c>>>=2,l-=2}else if(x===17){for(j=_+3;l<j;){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(j=_+7;l<j;){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=F;break}for(;u--;)r.lens[r.have++]=b}}if(r.mode===F)break;if(r.lens[256]===0){e.msg="invalid code -- missing end-of-block",r.mode=F;break}if(r.lenbits=9,k={bits:r.lenbits},S=zt(zs,r.lens,0,r.nlen,r.lencode,0,r.work,k),r.lenbits=k.bits,S){e.msg="invalid literal/lengths set",r.mode=F;break}if(r.distbits=6,r.distcode=r.distdyn,k={bits:r.distbits},S=zt(Zs,r.lens,r.nlen,r.ndist,r.distcode,0,r.work,k),r.distbits=k.bits,S){e.msg="invalid distances set",r.mode=F;break}if(r.mode=Sr,t===xr)break e;case Sr:r.mode=Ar;case Ar: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,ad(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===Ie&&(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,I=x;w=r.lencode[I+((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=hc;break}if(m&32){r.back=-1,r.mode=Ie;break}if(m&64){e.msg="invalid literal/length code",r.mode=F;break}r.extra=m&15,r.mode=cc;case cc:if(r.extra){for(j=r.extra;l<j;){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=fc;case fc: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,I=x;w=r.distcode[I+((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=F;break}r.offset=x,r.extra=m&15,r.mode=lc;case lc:if(r.extra){for(j=r.extra;l<j;){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=F;break}r.mode=uc;case uc: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=F;break}u>r.wnext?(u-=r.wnext,p=r.wsize-u):p=r.wnext-u,u>r.length&&(u=r.length),g=r.window}else g=i,p=o-r.offset,u=r.length;u>f&&(u=f),f-=u,r.length-=u;do i[o++]=g[p++];while(--u);r.length===0&&(r.mode=Ar);break;case hc:if(f===0)break e;i[o++]=r.length,f--,r.mode=Ar;break;case ji: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?q(r.check,i,h,o-h):Si(r.check,i,h,o-h)),h=f,(r.flags?c:yc(c))!==r.check){e.msg="incorrect data check",r.mode=F;break}c=0,l=0}r.mode=dc;case dc: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=F;break}c=0,l=0}r.mode=pc;case pc:S=hd;break e;case F:S=pd;break e;case vd:return yd;case wd: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<F&&(r.mode<ji||t!==qs))&&kd(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?q(r.check,i,h,e.next_out-h):Si(r.check,i,h,e.next_out-h)),e.data_type=r.bits+(r.last?64:0)+(r.mode===Ie?128:0)+(r.mode===Sr||r.mode===Ci?256:0),(d===0&&h===0||t===qs)&&S===Zt&&(S=gd),S}function Od(e){if(!e||!e.state)return Ze;var t=e.state;return t.window&&(t.window=null),e.state=null,Zt}var Mi=0,St=1,kr=2,qt=3,Rr=4,At=5,Ht=6,Kt=7,wc=0,_c=1,bc=2,mc=3,Li=4,Ec=5,Id=6,Or=0,xc=1,Sc=2,Td=-1,Pd=-2,Dd=-3,Ac=-5,Cd=0,jd=1,Fd=9,Nd=-1,Md=1,Ld=2,$d=3,Bd=4,Ud=0,zd=0,Zd=1,qd=2,kc=8;function le(e){if(e<St||e>Kt)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}le.prototype.init=function(e,t,r,n,i){this.windowBits=e,this.level=t,this.memLevel=r,this.strategy=n,(this.mode===qt||this.mode===Rr)&&(this.windowBits+=16),this.mode===Kt&&(this.windowBits+=32),(this.mode===At||this.mode===Ht)&&(this.windowBits=-this.windowBits),this.strm=new fh;var a;switch(this.mode){case St:case qt:case At:a=td(this.strm,this.level,kc,this.windowBits,this.memLevel,this.strategy);break;case kr:case Rr:case Ht:case Kt:a=Sd(this.strm,this.windowBits);break;default:throw new Error("Unknown mode "+this.mode)}if(a!==Or){this._error(a);return}this.write_in_progress=!1,this.init_done=!0},le.prototype.params=function(){throw new Error("deflateParams Not supported")},le.prototype._writeCheck=function(){if(!this.init_done)throw new Error("write before init");if(this.mode===Mi)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")},le.prototype.write=function(e,t,r,n,i,a,o){this._writeCheck(),this.write_in_progress=!0;var s=this;return Ae.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 Hd(e,t){for(var r=0;r<e.length;r++)this[t+r]=e[r]}le.prototype.writeSync=function(e,t,r,n,i,a,o){return this._writeCheck(),this._write(e,t,r,n,i,a,o)},le.prototype._write=function(e,t,r,n,i,a,o){if(this.write_in_progress=!0,e!==wc&&e!==_c&&e!==bc&&e!==mc&&e!==Li&&e!==Ec)throw new Error("Invalid flush value");t==null&&(t=new y(0),n=0,r=0),i._set?i.set=i._set:i.set=Hd;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 St:case qt:case At:f=rd(s,e);break;case Kt:case kr:case Rr:case Ht:f=Rd(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]},le.prototype._checkError=function(e,t,r){switch(e){case Or:case Ac:if(t.avail_out!==0&&r===Li)return!1;break;case xc:break;case Sc:return!1;default:return!1}return!0},le.prototype.close=function(){if(this.write_in_progress){this.pending_close=!0;return}this.pending_close=!1,this.mode===St||this.mode===qt||this.mode===At?nd(this.strm):Od(this.strm),this.mode=Mi};var Ir;le.prototype.reset=function(){switch(this.mode){case St:case At:Ir=Ms(this.strm);break;case kr:case Ht:Ir=gc(this.strm);break}Ir!==Or&&this._error(Ir)},le.prototype._error=function(e){this.onerror(ls[e]+": "+this.strm.msg,e),this.write_in_progress=!1,this.pending_close&&this.close()};var Rc=Object.freeze({__proto__:null,DEFLATE:St,DEFLATERAW:At,GUNZIP:Rr,GZIP:qt,INFLATE:kr,INFLATERAW:Ht,NONE:Mi,UNZIP:Kt,Z_BEST_COMPRESSION:Fd,Z_BEST_SPEED:jd,Z_BINARY:zd,Z_BLOCK:Ec,Z_BUF_ERROR:Ac,Z_DATA_ERROR:Dd,Z_DEFAULT_COMPRESSION:Nd,Z_DEFAULT_STRATEGY:Ud,Z_DEFLATED:kc,Z_ERRNO:Td,Z_FILTERED:Md,Z_FINISH:Li,Z_FIXED:Bd,Z_FULL_FLUSH:mc,Z_HUFFMAN_ONLY:Ld,Z_NEED_DICT:Sc,Z_NO_COMPRESSION:Cd,Z_NO_FLUSH:wc,Z_OK:Or,Z_PARTIAL_FLUSH:_c,Z_RLE:$d,Z_STREAM_END:xc,Z_STREAM_ERROR:Pd,Z_SYNC_FLUSH:bc,Z_TEXT:Zd,Z_TREES:Id,Z_UNKNOWN:qd,Zlib:le});function Kd(e,t){if(!e)throw new Error(t)}var E={};Object.keys(Rc).forEach(function(e){E[e]=Rc[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=16384,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 Vt={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(Vt).forEach(function(e){Vt[Vt[e]]=e});function Vd(e){return new nt(e)}function Wd(e){return new it(e)}function Gd(e){return new st(e)}function Yd(e){return new ct(e)}function Jd(e){return new at(e)}function Xd(e){return new ot(e)}function Qd(e){return new ft(e)}function ep(e,t,r){return typeof t=="function"&&(r=t,t={}),tt(new nt(t),e,r)}function tp(e,t){return rt(new nt(t),e)}function rp(e,t,r){return typeof t=="function"&&(r=t,t={}),tt(new at(t),e,r)}function np(e,t){return rt(new at(t),e)}function ip(e,t,r){return typeof t=="function"&&(r=t,t={}),tt(new st(t),e,r)}function ap(e,t){return rt(new st(t),e)}function op(e,t,r){return typeof t=="function"&&(r=t,t={}),tt(new ft(t),e,r)}function sp(e,t){return rt(new ft(t),e)}function cp(e,t,r){return typeof t=="function"&&(r=t,t={}),tt(new it(t),e,r)}function fp(e,t){return rt(new it(t),e)}function lp(e,t,r){return typeof t=="function"&&(r=t,t={}),tt(new ot(t),e,r)}function up(e,t){return rt(new ot(t),e)}function hp(e,t,r){return typeof t=="function"&&(r=t,t={}),tt(new ct(t),e,r)}function dp(e,t){return rt(new ct(t),e)}function tt(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=y.concat(n,i);n=[],r(null,f),e.close()}}function rt(e,t){if(typeof t=="string"&&(t=new y(t)),!y.isBuffer(t))throw new TypeError("Not a string or buffer");var r=E.Z_FINISH;return e._processChunk(t,r)}function nt(e){if(!(this instanceof nt))return new nt(e);N.call(this,e,E.DEFLATE)}function it(e){if(!(this instanceof it))return new it(e);N.call(this,e,E.INFLATE)}function at(e){if(!(this instanceof at))return new at(e);N.call(this,e,E.GZIP)}function ot(e){if(!(this instanceof ot))return new ot(e);N.call(this,e,E.GUNZIP)}function st(e){if(!(this instanceof st))return new st(e);N.call(this,e,E.DEFLATERAW)}function ct(e){if(!(this instanceof ct))return new ct(e);N.call(this,e,E.INFLATERAW)}function ft(e){if(!(this instanceof ft))return new ft(e);N.call(this,e,E.UNZIP)}function N(e,t){if(this._opts=e=e||{},this._chunkSize=e.chunkSize||E.Z_DEFAULT_CHUNK,ie.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&&!y.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=Vt[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 y(this._chunkSize),this._offset=0,this._closed=!1,this._level=n,this._strategy=i,this.once("end",this.close)}W(N,ie),N.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 Ae.nextTick(r)},N.prototype.reset=function(){return this._binding.reset()},N.prototype._flush=function(e){this._transform(new y(0),"",e)},N.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&&Ae.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 y(0),"",t)},N.prototype.close=function(e){if(e&&Ae.nextTick(e),!this._closed){this._closed=!0,this._binding.close();var t=this;Ae.nextTick(function(){t.emit("close")})}},N.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&&!y.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)},N.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(g){l=g});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=y.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(g,w){if(!o._hadError){var _=i-w;if(Kd(_>=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 y(o._chunkSize)),w===0){if(a+=n-g,n=g,!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(nt,N),W(it,N),W(at,N),W(ot,N),W(st,N),W(ct,N),W(ft,N);var Oc={codes:Vt,createDeflate:Vd,createInflate:Wd,createDeflateRaw:Gd,createInflateRaw:Yd,createGzip:Jd,createGunzip:Xd,createUnzip:Qd,deflate:ep,deflateSync:tp,gzip:rp,gzipSync:np,deflateRaw:ip,deflateRawSync:ap,unzip:op,unzipSync:sp,inflate:cp,inflateSync:fp,gunzip:lp,gunzipSync:up,inflateRaw:hp,inflateRawSync:dp,Deflate:nt,Inflate:it,Gzip:at,Gunzip:ot,DeflateRaw:st,InflateRaw:ct,Unzip:ft,Zlib:N};class Ic extends di{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=Oc.gzipSync(n).toString("base64"),this.client.putObject({key:Ee(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(Ee(this.keyPrefix,t));let n=await gt(r);return n=Buffer.from(n,"base64"),n=Oc.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(Ee(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 Tc extends O{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 pp={setup(e){},start(){},stop(){}},yp={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 gp extends Tc{constructor(t={}){super(),this.driver=t.driver}async setup(t){this.database=t,this.driver||(this.driver=new Ic({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=Ee(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 aa(a),a=Ee(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}}}return R.AuthenticationError=Xc,R.BaseError=Gi,R.Cache=di,R.CachePlugin=gp,R.Client=ia,R.ConnectionString=zr,R.CostsPlugin=yp,R.Database=fs,R.DatabaseError=Yc,R.EncryptionError=ef,R.ErrorMap=ta,R.InvalidResourceItem=Jt,R.MemoryCache=ch,R.MissingMetadata=Qi,R.NoSuchBucket=Ji,R.NoSuchKey=Ur,R.NotFound=Xi,R.PermissionError=Qc,R.Plugin=Tc,R.PluginObject=pp,R.ResourceIdsPageReader=rs,R.ResourceIdsReader=ts,R.ResourceNotFound=Yi,R.ResourceNotFoundError=Yi,R.ResourceReader=ns,R.ResourceWriter=is,R.S3Cache=Ic,R.S3DB=hi,R.S3DBError=re,R.S3_DEFAULT_ENDPOINT=na,R.S3_DEFAULT_REGION=ra,R.S3db=hi,R.S3dbError=re,R.UnknownError=ea,R.ValidationError=Jc,R.Validator=lo,R.ValidatorManager=uo,R.decrypt=oa,R.default=hi,R.encrypt=Zr,R.sha256=aa,R.streamToString=gt,Object.defineProperty(R,"__esModule",{value:!0}),R}({},nanoid,lodashEs,promisePool,clientS3,crypto,flat,FastestValidator,web);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "s3db.js",
|
|
3
|
-
"version": "4.1.
|
|
3
|
+
"version": "4.1.14",
|
|
4
4
|
"description": "Use AWS S3, the world's most reliable document storage, as a database with this ORM.",
|
|
5
5
|
"main": "dist/s3db.cjs.js",
|
|
6
6
|
"module": "dist/s3db.es.js",
|
|
@@ -35,18 +35,6 @@
|
|
|
35
35
|
"aws",
|
|
36
36
|
"database"
|
|
37
37
|
],
|
|
38
|
-
"scripts": {
|
|
39
|
-
"build": "rollup -c",
|
|
40
|
-
"clean-build": "node scripts/clean-build.js",
|
|
41
|
-
"postbuild": "node scripts/prefix-files-istanbul-ignore.js",
|
|
42
|
-
"verify": "node scripts/verify-build.js",
|
|
43
|
-
"test-builds": "node examples/test-builds.js",
|
|
44
|
-
"coverage": "coveralls < coverage/lcov.info",
|
|
45
|
-
"coverage:serve": "npx http-server ./coverage/lcov-report",
|
|
46
|
-
"test": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js --coverage --detectOpenHandles",
|
|
47
|
-
"test:watch": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js --coverage --watch --detectOpenHandles",
|
|
48
|
-
"test:dist": "node --no-warnings --experimental-vm-modules ./tests/dist.js"
|
|
49
|
-
},
|
|
50
38
|
"dependencies": {
|
|
51
39
|
"@aws-sdk/client-s3": "^3.837.0",
|
|
52
40
|
"@supercharge/promise-pool": "^3.2.0",
|
|
@@ -78,5 +66,17 @@
|
|
|
78
66
|
"rollup": "^4.44.1",
|
|
79
67
|
"rollup-plugin-esbuild": "^6.2.1",
|
|
80
68
|
"rollup-plugin-polyfill-node": "^0.13.0"
|
|
69
|
+
},
|
|
70
|
+
"scripts": {
|
|
71
|
+
"build": "rollup -c",
|
|
72
|
+
"clean-build": "node scripts/clean-build.js",
|
|
73
|
+
"postbuild": "node scripts/prefix-files-istanbul-ignore.js",
|
|
74
|
+
"verify": "node scripts/verify-build.js",
|
|
75
|
+
"test-builds": "node examples/test-builds.js",
|
|
76
|
+
"coverage": "coveralls < coverage/lcov.info",
|
|
77
|
+
"coverage:serve": "npx http-server ./coverage/lcov-report",
|
|
78
|
+
"test": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js --coverage --detectOpenHandles",
|
|
79
|
+
"test:watch": "node --no-warnings --experimental-vm-modules node_modules/jest/bin/jest.js --coverage --watch --detectOpenHandles",
|
|
80
|
+
"test:dist": "node --no-warnings --experimental-vm-modules ./tests/dist.js"
|
|
81
81
|
}
|
|
82
|
-
}
|
|
82
|
+
}
|