mqtt-plus 1.4.25 → 1.4.26

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.
Files changed (67) hide show
  1. package/.ase/config.yaml +1 -0
  2. package/.ase/service.log +34 -0
  3. package/.ase/service.yaml +1 -1
  4. package/.ase/task/TASK-P18.md +1 -1
  5. package/.ase/task/TASK-P21.md +1 -1
  6. package/.claude/settings.local.json +4 -1
  7. package/AGENTS.md +1 -1
  8. package/CHANGELOG.md +24 -5
  9. package/README.md +2 -2
  10. package/doc/mqtt-plus-broker-setup.md +1 -1
  11. package/doc/mqtt-plus-comm.md +3 -3
  12. package/doc/mqtt-plus-internals.md +6 -0
  13. package/dst-stage1/mqtt-plus-base.d.ts +2 -2
  14. package/dst-stage1/mqtt-plus-base.js +13 -10
  15. package/dst-stage1/mqtt-plus-error.js +54 -28
  16. package/dst-stage1/mqtt-plus-event.js +3 -1
  17. package/dst-stage1/mqtt-plus-options.js +7 -0
  18. package/dst-stage1/mqtt-plus-service.js +9 -6
  19. package/dst-stage1/mqtt-plus-sink.js +27 -54
  20. package/dst-stage1/mqtt-plus-source.js +13 -9
  21. package/dst-stage1/mqtt-plus-util.d.ts +1 -0
  22. package/dst-stage1/mqtt-plus-util.js +25 -4
  23. package/dst-stage1/mqtt-plus.d.ts +1 -1
  24. package/dst-stage1/mqtt-plus.js +2 -0
  25. package/dst-stage2/mqtt-plus.cjs.cjs +164 -123
  26. package/dst-stage2/mqtt-plus.esm.js +154 -122
  27. package/dst-stage2/mqtt-plus.umd.js +11 -11
  28. package/etc/stx.conf +3 -2
  29. package/package.d/@typescript-eslint+typescript-estree+8.66.0.patch +12 -0
  30. package/package.d/{vite+8.1.4.patch → vite+8.2.1.patch} +2 -2
  31. package/package.json +16 -15
  32. package/src/mqtt-plus-base.ts +15 -12
  33. package/src/mqtt-plus-error.ts +65 -33
  34. package/src/mqtt-plus-event.ts +2 -1
  35. package/src/mqtt-plus-options.ts +8 -0
  36. package/src/mqtt-plus-service.ts +9 -6
  37. package/src/mqtt-plus-sink.ts +28 -54
  38. package/src/mqtt-plus-source.ts +13 -9
  39. package/src/mqtt-plus-util.ts +27 -4
  40. package/src/mqtt-plus.ts +3 -1
  41. package/tst/mqtt-plus-0-fixture.ts +1 -0
  42. package/tst/mqtt-plus-2-event.spec.ts +25 -0
  43. package/tst/mqtt-plus-4-sink.spec.ts +23 -0
  44. package/tst/mqtt-plus-5-source.spec.ts +26 -0
  45. package/tst/mqtt-plus-6-misc.spec.ts +58 -0
  46. package/tst/mqtt-plus-8-run.spec.ts +60 -0
  47. package/dst-stage1/mqtt-plus-api.js.map +0 -1
  48. package/dst-stage1/mqtt-plus-auth.js.map +0 -1
  49. package/dst-stage1/mqtt-plus-base.js.map +0 -1
  50. package/dst-stage1/mqtt-plus-codec.js.map +0 -1
  51. package/dst-stage1/mqtt-plus-encode.js.map +0 -1
  52. package/dst-stage1/mqtt-plus-error.js.map +0 -1
  53. package/dst-stage1/mqtt-plus-event.js.map +0 -1
  54. package/dst-stage1/mqtt-plus-info.js.map +0 -1
  55. package/dst-stage1/mqtt-plus-meta.js.map +0 -1
  56. package/dst-stage1/mqtt-plus-msg.js.map +0 -1
  57. package/dst-stage1/mqtt-plus-options.js.map +0 -1
  58. package/dst-stage1/mqtt-plus-service.js.map +0 -1
  59. package/dst-stage1/mqtt-plus-sink.js.map +0 -1
  60. package/dst-stage1/mqtt-plus-source.js.map +0 -1
  61. package/dst-stage1/mqtt-plus-subscription.js.map +0 -1
  62. package/dst-stage1/mqtt-plus-timer.js.map +0 -1
  63. package/dst-stage1/mqtt-plus-trace.js.map +0 -1
  64. package/dst-stage1/mqtt-plus-util.js.map +0 -1
  65. package/dst-stage1/mqtt-plus-version.js.map +0 -1
  66. package/dst-stage1/mqtt-plus.js.map +0 -1
  67. package/package.d/@typescript-eslint+typescript-estree+8.63.0.patch +0 -12
@@ -1,13 +1,13 @@
1
- (function(e,t){typeof exports==`object`&&typeof module<`u`?module.exports=t():typeof define==`function`&&define.amd?define([],t):(e=typeof globalThis<`u`?globalThis:e||self,e.MQTTp=t())})(this,function(){var e=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(e){throw n=[e],e}},t=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),n=t(((e,t)=>{var n=typeof Reflect==`object`?Reflect:null,r=n&&typeof n.apply==`function`?n.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)},i=n&&typeof n.ownKeys==`function`?n.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};function a(e){console&&console.warn&&console.warn(e)}var o=Number.isNaN||function(e){return e!==e};function s(){s.init.call(this)}t.exports=s,t.exports.once=y,s.EventEmitter=s,s.prototype._events=void 0,s.prototype._eventsCount=0,s.prototype._maxListeners=void 0;var c=10;function l(e){if(typeof e!=`function`)throw TypeError(`The "listener" argument must be of type Function. Received type `+typeof e)}Object.defineProperty(s,"defaultMaxListeners",{enumerable:!0,get:function(){return c},set:function(e){if(typeof e!=`number`||e<0||o(e))throw RangeError(`The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received `+e+`.`);c=e}}),s.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},s.prototype.setMaxListeners=function(e){if(typeof e!=`number`||e<0||o(e))throw RangeError(`The value of "n" is out of range. It must be a non-negative number. Received `+e+`.`);return this._maxListeners=e,this};function u(e){return e._maxListeners===void 0?s.defaultMaxListeners:e._maxListeners}s.prototype.getMaxListeners=function(){return u(this)},s.prototype.emit=function(e){for(var t=[],n=1;n<arguments.length;n++)t.push(arguments[n]);var i=e===`error`,a=this._events;if(a!==void 0)i&&=a.error===void 0;else if(!i)return!1;if(i){var o;if(t.length>0&&(o=t[0]),o instanceof Error)throw o;var s=Error(`Unhandled error.`+(o?` (`+o.message+`)`:``));throw s.context=o,s}var c=a[e];if(c===void 0)return!1;if(typeof c==`function`)r(c,this,t);else for(var l=c.length,u=g(c,l),n=0;n<l;++n)r(u[n],this,t);return!0};function d(e,t,n,r){var i,o,s;if(l(n),o=e._events,o===void 0?(o=e._events=Object.create(null),e._eventsCount=0):(o.newListener!==void 0&&(e.emit(`newListener`,t,n.listener?n.listener:n),o=e._events),s=o[t]),s===void 0)s=o[t]=n,++e._eventsCount;else if(typeof s==`function`?s=o[t]=r?[n,s]:[s,n]:r?s.unshift(n):s.push(n),i=u(e),i>0&&s.length>i&&!s.warned){s.warned=!0;var c=Error(`Possible EventEmitter memory leak detected. `+s.length+` `+String(t)+` listeners added. Use emitter.setMaxListeners() to increase limit`);c.name=`MaxListenersExceededWarning`,c.emitter=e,c.type=t,c.count=s.length,a(c)}return e}s.prototype.addListener=function(e,t){return d(this,e,t,!1)},s.prototype.on=s.prototype.addListener,s.prototype.prependListener=function(e,t){return d(this,e,t,!0)};function f(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function p(e,t,n){var r={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},i=f.bind(r);return i.listener=n,r.wrapFn=i,i}s.prototype.once=function(e,t){return l(t),this.on(e,p(this,e,t)),this},s.prototype.prependOnceListener=function(e,t){return l(t),this.prependListener(e,p(this,e,t)),this},s.prototype.removeListener=function(e,t){var n,r,i,a,o;if(l(t),r=this._events,r===void 0||(n=r[e],n===void 0))return this;if(n===t||n.listener===t)--this._eventsCount===0?this._events=Object.create(null):(delete r[e],r.removeListener&&this.emit(`removeListener`,e,n.listener||t));else if(typeof n!=`function`){for(i=-1,a=n.length-1;a>=0;a--)if(n[a]===t||n[a].listener===t){o=n[a].listener,i=a;break}if(i<0)return this;i===0?n.shift():_(n,i),n.length===1&&(r[e]=n[0]),r.removeListener!==void 0&&this.emit(`removeListener`,e,o||t)}return this},s.prototype.off=s.prototype.removeListener,s.prototype.removeAllListeners=function(e){var t,n=this._events,r;if(n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[e]),this;if(arguments.length===0){var i=Object.keys(n),a;for(r=0;r<i.length;++r)a=i[r],a!==`removeListener`&&this.removeAllListeners(a);return this.removeAllListeners(`removeListener`),this._events=Object.create(null),this._eventsCount=0,this}if(t=n[e],typeof t==`function`)this.removeListener(e,t);else if(t!==void 0)for(r=t.length-1;r>=0;r--)this.removeListener(e,t[r]);return this};function m(e,t,n){var r=e._events;if(r===void 0)return[];var i=r[t];return i===void 0?[]:typeof i==`function`?n?[i.listener||i]:[i]:n?v(i):g(i,i.length)}s.prototype.listeners=function(e){return m(this,e,!0)},s.prototype.rawListeners=function(e){return m(this,e,!1)},s.listenerCount=function(e,t){return typeof e.listenerCount==`function`?e.listenerCount(t):h.call(e,t)},s.prototype.listenerCount=h;function h(e){var t=this._events;if(t!==void 0){var n=t[e];if(typeof n==`function`)return 1;if(n!==void 0)return n.length}return 0}s.prototype.eventNames=function(){return this._eventsCount>0?i(this._events):[]};function g(e,t){for(var n=Array(t),r=0;r<t;++r)n[r]=e[r];return n}function _(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}function v(e){for(var t=Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}function y(e,t){return new Promise(function(n,r){function i(n){e.removeListener(t,a),r(n)}function a(){typeof e.removeListener==`function`&&e.removeListener(`error`,i),n([].slice.call(arguments))}x(e,t,a,{once:!0}),t!==`error`&&b(e,i,{once:!0})})}function b(e,t,n){typeof e.on==`function`&&x(e,`error`,t,n)}function x(e,t,n,r){if(typeof e.on==`function`)r.once?e.once(t,n):e.on(t,n);else if(typeof e.addEventListener==`function`)e.addEventListener(t,function i(a){r.once&&e.removeEventListener(t,i),n(a)});else throw TypeError(`The "emitter" argument must be of type EventEmitter. Received type `+typeof e)}})),r=t(((e,t)=>{typeof Object.create==`function`?t.exports=function(e,t){t&&(e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}))}:t.exports=function(e,t){if(t){e.super_=t;var n=function(){};n.prototype=t.prototype,e.prototype=new n,e.prototype.constructor=e}}})),i,a=e((()=>{i=globalThis||self}));function o(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,`default`)?e.default:e}function s(){throw Error(`setTimeout has not been defined`)}function c(){throw Error(`clearTimeout has not been defined`)}function l(e){if(_===setTimeout)return setTimeout(e,0);if((_===s||!_)&&setTimeout)return _=setTimeout,setTimeout(e,0);try{return _(e,0)}catch{try{return _.call(null,e,0)}catch{return _.call(this,e,0)}}}function u(e){if(v===clearTimeout)return clearTimeout(e);if((v===c||!v)&&clearTimeout)return v=clearTimeout,clearTimeout(e);try{return v(e)}catch{try{return v.call(null,e)}catch{return v.call(this,e)}}}function d(){!b||!x||(b=!1,x.length?y=x.concat(y):S=-1,y.length&&f())}function f(){if(!b){var e=l(d);b=!0;for(var t=y.length;t;){for(x=y,y=[];++S<t;)x&&x[S].run();S=-1,t=y.length}x=null,b=!1,u(e)}}function p(e,t){this.fun=e,this.array=t}function m(){}var h,g,_,v,y,b,x,S,ee,C,w=e((()=>{h={exports:{}},g=h.exports={},(function(){try{_=typeof setTimeout==`function`?setTimeout:s}catch{_=s}try{v=typeof clearTimeout==`function`?clearTimeout:c}catch{v=c}})(),y=[],b=!1,S=-1,g.nextTick=function(e){var t=Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];y.push(new p(e,t)),y.length===1&&!b&&l(f)},p.prototype.run=function(){this.fun.apply(null,this.array)},g.title=`browser`,g.browser=!0,g.env={},g.argv=[],g.version=``,g.versions={},g.on=m,g.addListener=m,g.once=m,g.off=m,g.removeListener=m,g.removeAllListeners=m,g.emit=m,g.prependListener=m,g.prependOnceListener=m,g.listeners=function(e){return[]},g.binding=function(e){throw Error(`process.binding is not supported`)},g.cwd=function(){return`/`},g.chdir=function(e){throw Error(`process.chdir is not supported`)},g.umask=function(){return 0},ee=h.exports,C=o(ee)})),T=t(((e,t)=>{t.exports=n().EventEmitter})),E=t((e=>{Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var t={},n={};n.byteLength=u,n.toByteArray=f,n.fromByteArray=h;for(var r=[],i=[],a=typeof Uint8Array<`u`?Uint8Array:Array,o=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`,s=0,c=o.length;s<c;++s)r[s]=o[s],i[o.charCodeAt(s)]=s;i[45]=62,i[95]=63;function l(e){var t=e.length;if(t%4>0)throw Error(`Invalid string. Length must be a multiple of 4`);var n=e.indexOf(`=`);n===-1&&(n=t);var r=n===t?0:4-n%4;return[n,r]}function u(e){var t=l(e),n=t[0],r=t[1];return(n+r)*3/4-r}function d(e,t,n){return(t+n)*3/4-n}function f(e){var t,n=l(e),r=n[0],o=n[1],s=new a(d(e,r,o)),c=0,u=o>0?r-4:r,f;for(f=0;f<u;f+=4)t=i[e.charCodeAt(f)]<<18|i[e.charCodeAt(f+1)]<<12|i[e.charCodeAt(f+2)]<<6|i[e.charCodeAt(f+3)],s[c++]=t>>16&255,s[c++]=t>>8&255,s[c++]=t&255;return o===2&&(t=i[e.charCodeAt(f)]<<2|i[e.charCodeAt(f+1)]>>4,s[c++]=t&255),o===1&&(t=i[e.charCodeAt(f)]<<10|i[e.charCodeAt(f+1)]<<4|i[e.charCodeAt(f+2)]>>2,s[c++]=t>>8&255,s[c++]=t&255),s}function p(e){return r[e>>18&63]+r[e>>12&63]+r[e>>6&63]+r[e&63]}function m(e,t,n){for(var r,i=[],a=t;a<n;a+=3)r=(e[a]<<16&16711680)+(e[a+1]<<8&65280)+(e[a+2]&255),i.push(p(r));return i.join(``)}function h(e){for(var t,n=e.length,i=n%3,a=[],o=16383,s=0,c=n-i;s<c;s+=o)a.push(m(e,s,s+o>c?c:s+o));return i===1?(t=e[n-1],a.push(r[t>>2]+r[t<<4&63]+`==`)):i===2&&(t=(e[n-2]<<8)+e[n-1],a.push(r[t>>10]+r[t>>4&63]+r[t<<2&63]+`=`)),a.join(``)}var g={};g.read=function(e,t,n,r,i){var a,o,s=i*8-r-1,c=(1<<s)-1,l=c>>1,u=-7,d=n?i-1:0,f=n?-1:1,p=e[t+d];for(d+=f,a=p&(1<<-u)-1,p>>=-u,u+=s;u>0;a=a*256+e[t+d],d+=f,u-=8);for(o=a&(1<<-u)-1,a>>=-u,u+=r;u>0;o=o*256+e[t+d],d+=f,u-=8);if(a===0)a=1-l;else if(a===c)return o?NaN:(p?-1:1)*(1/0);else o+=2**r,a-=l;return(p?-1:1)*o*2**(a-r)},g.write=function(e,t,n,r,i,a){var o,s,c,l=a*8-i-1,u=(1<<l)-1,d=u>>1,f=i===23?2**-24-2**-77:0,p=r?0:a-1,m=r?1:-1,h=+(t<0||t===0&&1/t<0);for(t=Math.abs(t),isNaN(t)||t===1/0?(s=+!!isNaN(t),o=u):(o=Math.floor(Math.log(t)/Math.LN2),t*(c=2**-o)<1&&(o--,c*=2),o+d>=1?t+=f/c:t+=f*2**(1-d),t*c>=2&&(o++,c/=2),o+d>=u?(s=0,o=u):o+d>=1?(s=(t*c-1)*2**i,o+=d):(s=t*2**(d-1)*2**i,o=0));i>=8;e[n+p]=s&255,p+=m,s/=256,i-=8);for(o=o<<i|s,l+=i;l>0;e[n+p]=o&255,p+=m,o/=256,l-=8);e[n+p-m]|=h*128},(function(e){let t=n,r=g,i=typeof Symbol==`function`&&typeof Symbol.for==`function`?Symbol.for(`nodejs.util.inspect.custom`):null;e.Buffer=d,e.SlowBuffer=ee,e.INSPECT_MAX_BYTES=50;let a=2147483647;e.kMaxLength=a;let{Uint8Array:o,ArrayBuffer:s,SharedArrayBuffer:c}=globalThis;d.TYPED_ARRAY_SUPPORT=l(),!d.TYPED_ARRAY_SUPPORT&&typeof console<`u`&&typeof console.error==`function`&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function l(){try{let e=new o(1),t={foo:function(){return 42}};return Object.setPrototypeOf(t,o.prototype),Object.setPrototypeOf(e,t),e.foo()===42}catch{return!1}}Object.defineProperty(d.prototype,"parent",{enumerable:!0,get:function(){if(d.isBuffer(this))return this.buffer}}),Object.defineProperty(d.prototype,"offset",{enumerable:!0,get:function(){if(d.isBuffer(this))return this.byteOffset}});function u(e){if(e>a)throw RangeError(`The value "`+e+`" is invalid for option "size"`);let t=new o(e);return Object.setPrototypeOf(t,d.prototype),t}function d(e,t,n){if(typeof e==`number`){if(typeof t==`string`)throw TypeError(`The "string" argument must be of type string. Received type number`);return h(e)}return f(e,t,n)}d.poolSize=8192;function f(e,t,n){if(typeof e==`string`)return _(e,t);if(s.isView(e))return y(e);if(e==null)throw TypeError(`The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type `+typeof e);if(ye(e,s)||e&&ye(e.buffer,s)||c!==void 0&&(ye(e,c)||e&&ye(e.buffer,c)))return b(e,t,n);if(typeof e==`number`)throw TypeError(`The "value" argument must not be of type number. Received type number`);let r=e.valueOf&&e.valueOf();if(r!=null&&r!==e)return d.from(r,t,n);let i=x(e);if(i)return i;if(typeof Symbol<`u`&&Symbol.toPrimitive!=null&&typeof e[Symbol.toPrimitive]==`function`)return d.from(e[Symbol.toPrimitive](`string`),t,n);throw TypeError(`The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type `+typeof e)}d.from=function(e,t,n){return f(e,t,n)},Object.setPrototypeOf(d.prototype,o.prototype),Object.setPrototypeOf(d,o);function p(e){if(typeof e!=`number`)throw TypeError(`"size" argument must be of type number`);if(e<0)throw RangeError(`The value "`+e+`" is invalid for option "size"`)}function m(e,t,n){return p(e),e<=0||t===void 0?u(e):typeof n==`string`?u(e).fill(t,n):u(e).fill(t)}d.alloc=function(e,t,n){return m(e,t,n)};function h(e){return p(e),u(e<0?0:S(e)|0)}d.allocUnsafe=function(e){return h(e)},d.allocUnsafeSlow=function(e){return h(e)};function _(e,t){if((typeof t!=`string`||t===``)&&(t=`utf8`),!d.isEncoding(t))throw TypeError(`Unknown encoding: `+t);let n=C(e,t)|0,r=u(n),i=r.write(e,t);return i!==n&&(r=r.slice(0,i)),r}function v(e){let t=e.length<0?0:S(e.length)|0,n=u(t);for(let r=0;r<t;r+=1)n[r]=e[r]&255;return n}function y(e){if(ye(e,o)){let t=new o(e);return b(t.buffer,t.byteOffset,t.byteLength)}return v(e)}function b(e,t,n){if(t<0||e.byteLength<t)throw RangeError(`"offset" is outside of buffer bounds`);if(e.byteLength<t+(n||0))throw RangeError(`"length" is outside of buffer bounds`);let r;return r=t===void 0&&n===void 0?new o(e):n===void 0?new o(e,t):new o(e,t,n),Object.setPrototypeOf(r,d.prototype),r}function x(e){if(d.isBuffer(e)){let t=S(e.length)|0,n=u(t);return n.length===0||e.copy(n,0,0,t),n}if(e.length!==void 0)return typeof e.length!=`number`||be(e.length)?u(0):v(e);if(e.type===`Buffer`&&Array.isArray(e.data))return v(e.data)}function S(e){if(e>=a)throw RangeError(`Attempt to allocate Buffer larger than maximum size: 0x`+a.toString(16)+` bytes`);return e|0}function ee(e){return+e!=e&&(e=0),d.alloc(+e)}d.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==d.prototype},d.compare=function(e,t){if(ye(e,o)&&(e=d.from(e,e.offset,e.byteLength)),ye(t,o)&&(t=d.from(t,t.offset,t.byteLength)),!d.isBuffer(e)||!d.isBuffer(t))throw TypeError(`The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array`);if(e===t)return 0;let n=e.length,r=t.length;for(let i=0,a=Math.min(n,r);i<a;++i)if(e[i]!==t[i]){n=e[i],r=t[i];break}return n<r?-1:+(r<n)},d.isEncoding=function(e){switch(String(e).toLowerCase()){case`hex`:case`utf8`:case`utf-8`:case`ascii`:case`latin1`:case`binary`:case`base64`:case`ucs2`:case`ucs-2`:case`utf16le`:case`utf-16le`:return!0;default:return!1}},d.concat=function(e,t){if(!Array.isArray(e))throw TypeError(`"list" argument must be an Array of Buffers`);if(e.length===0)return d.alloc(0);let n;if(t===void 0)for(t=0,n=0;n<e.length;++n)t+=e[n].length;let r=d.allocUnsafe(t),i=0;for(n=0;n<e.length;++n){let t=e[n];if(ye(t,o))i+t.length>r.length?(d.isBuffer(t)||(t=d.from(t)),t.copy(r,i)):o.prototype.set.call(r,t,i);else if(d.isBuffer(t))t.copy(r,i);else throw TypeError(`"list" argument must be an Array of Buffers`);i+=t.length}return r};function C(e,t){if(d.isBuffer(e))return e.length;if(s.isView(e)||ye(e,s))return e.byteLength;if(typeof e!=`string`)throw TypeError(`The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type `+typeof e);let n=e.length,r=arguments.length>2&&arguments[2]===!0;if(!r&&n===0)return 0;let i=!1;for(;;)switch(t){case`ascii`:case`latin1`:case`binary`:return n;case`utf8`:case`utf-8`:return he(e).length;case`ucs2`:case`ucs-2`:case`utf16le`:case`utf-16le`:return n*2;case`hex`:return n>>>1;case`base64`:return ve(e).length;default:if(i)return r?-1:he(e).length;t=(``+t).toLowerCase(),i=!0}}d.byteLength=C;function w(e,t,n){let r=!1;if((t===void 0||t<0)&&(t=0),t>this.length||((n===void 0||n>this.length)&&(n=this.length),n<=0)||(n>>>=0,t>>>=0,n<=t))return``;for(e||=`utf8`;;)switch(e){case`hex`:return N(this,t,n);case`utf8`:case`utf-8`:return ie(this,t,n);case`ascii`:return ae(this,t,n);case`latin1`:case`binary`:return oe(this,t,n);case`base64`:return A(this,t,n);case`ucs2`:case`ucs-2`:case`utf16le`:case`utf-16le`:return P(this,t,n);default:if(r)throw TypeError(`Unknown encoding: `+e);e=(e+``).toLowerCase(),r=!0}}d.prototype._isBuffer=!0;function T(e,t,n){let r=e[t];e[t]=e[n],e[n]=r}d.prototype.swap16=function(){let e=this.length;if(e%2!=0)throw RangeError(`Buffer size must be a multiple of 16-bits`);for(let t=0;t<e;t+=2)T(this,t,t+1);return this},d.prototype.swap32=function(){let e=this.length;if(e%4!=0)throw RangeError(`Buffer size must be a multiple of 32-bits`);for(let t=0;t<e;t+=4)T(this,t,t+3),T(this,t+1,t+2);return this},d.prototype.swap64=function(){let e=this.length;if(e%8!=0)throw RangeError(`Buffer size must be a multiple of 64-bits`);for(let t=0;t<e;t+=8)T(this,t,t+7),T(this,t+1,t+6),T(this,t+2,t+5),T(this,t+3,t+4);return this},d.prototype.toString=function(){let e=this.length;return e===0?``:arguments.length===0?ie(this,0,e):w.apply(this,arguments)},d.prototype.toLocaleString=d.prototype.toString,d.prototype.equals=function(e){if(!d.isBuffer(e))throw TypeError(`Argument must be a Buffer`);return this===e||d.compare(this,e)===0},d.prototype.inspect=function(){let t=``,n=e.INSPECT_MAX_BYTES;return t=this.toString(`hex`,0,n).replace(/(.{2})/g,`$1 `).trim(),this.length>n&&(t+=` ... `),`<Buffer `+t+`>`},i&&(d.prototype[i]=d.prototype.inspect),d.prototype.compare=function(e,t,n,r,i){if(ye(e,o)&&(e=d.from(e,e.offset,e.byteLength)),!d.isBuffer(e))throw TypeError(`The "target" argument must be one of type Buffer or Uint8Array. Received type `+typeof e);if(t===void 0&&(t=0),n===void 0&&(n=e?e.length:0),r===void 0&&(r=0),i===void 0&&(i=this.length),t<0||n>e.length||r<0||i>this.length)throw RangeError(`out of range index`);if(r>=i&&t>=n)return 0;if(r>=i)return-1;if(t>=n)return 1;if(t>>>=0,n>>>=0,r>>>=0,i>>>=0,this===e)return 0;let a=i-r,s=n-t,c=Math.min(a,s),l=this.slice(r,i),u=e.slice(t,n);for(let e=0;e<c;++e)if(l[e]!==u[e]){a=l[e],s=u[e];break}return a<s?-1:+(s<a)};function E(e,t,n,r,i){if(e.length===0)return-1;if(typeof n==`string`?(r=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),n=+n,be(n)&&(n=i?0:e.length-1),n<0&&(n=e.length+n),n>=e.length){if(i)return-1;n=e.length-1}else if(n<0)if(i)n=0;else return-1;if(typeof t==`string`&&(t=d.from(t,r)),d.isBuffer(t))return t.length===0?-1:D(e,t,n,r,i);if(typeof t==`number`)return t&=255,typeof o.prototype.indexOf==`function`?i?o.prototype.indexOf.call(e,t,n):o.prototype.lastIndexOf.call(e,t,n):D(e,[t],n,r,i);throw TypeError(`val must be string, number or Buffer`)}function D(e,t,n,r,i){let a=1,o=e.length,s=t.length;if(r!==void 0&&(r=String(r).toLowerCase(),r===`ucs2`||r===`ucs-2`||r===`utf16le`||r===`utf-16le`)){if(e.length<2||t.length<2)return-1;a=2,o/=2,s/=2,n/=2}function c(e,t){return a===1?e[t]:e.readUInt16BE(t*a)}let l;if(i){let r=-1;for(l=n;l<o;l++)if(c(e,l)===c(t,r===-1?0:l-r)){if(r===-1&&(r=l),l-r+1===s)return r*a}else r!==-1&&(l-=l-r),r=-1}else for(n+s>o&&(n=o-s),l=n;l>=0;l--){let n=!0;for(let r=0;r<s;r++)if(c(e,l+r)!==c(t,r)){n=!1;break}if(n)return l}return-1}d.prototype.includes=function(e,t,n){return this.indexOf(e,t,n)!==-1},d.prototype.indexOf=function(e,t,n){return E(this,e,t,n,!0)},d.prototype.lastIndexOf=function(e,t,n){return E(this,e,t,n,!1)};function te(e,t,n,r){n=Number(n)||0;let i=e.length-n;r?(r=Number(r),r>i&&(r=i)):r=i;let a=t.length;r>a/2&&(r=a/2);let o;for(o=0;o<r;++o){let r=parseInt(t.substr(o*2,2),16);if(be(r))return o;e[n+o]=r}return o}function O(e,t,n,r){return U(he(t,e.length-n),e,n,r)}function ne(e,t,n,r){return U(ge(t),e,n,r)}function k(e,t,n,r){return U(ve(t),e,n,r)}function re(e,t,n,r){return U(_e(t,e.length-n),e,n,r)}d.prototype.write=function(e,t,n,r){if(t===void 0)r=`utf8`,n=this.length,t=0;else if(n===void 0&&typeof t==`string`)r=t,n=this.length,t=0;else if(isFinite(t))t>>>=0,isFinite(n)?(n>>>=0,r===void 0&&(r=`utf8`)):(r=n,n=void 0);else throw Error(`Buffer.write(string, encoding, offset[, length]) is no longer supported`);let i=this.length-t;if((n===void 0||n>i)&&(n=i),e.length>0&&(n<0||t<0)||t>this.length)throw RangeError(`Attempt to write outside buffer bounds`);r||=`utf8`;let a=!1;for(;;)switch(r){case`hex`:return te(this,e,t,n);case`utf8`:case`utf-8`:return O(this,e,t,n);case`ascii`:case`latin1`:case`binary`:return ne(this,e,t,n);case`base64`:return k(this,e,t,n);case`ucs2`:case`ucs-2`:case`utf16le`:case`utf-16le`:return re(this,e,t,n);default:if(a)throw TypeError(`Unknown encoding: `+r);r=(``+r).toLowerCase(),a=!0}},d.prototype.toJSON=function(){return{type:`Buffer`,data:Array.prototype.slice.call(this._arr||this,0)}};function A(e,n,r){return n===0&&r===e.length?t.fromByteArray(e):t.fromByteArray(e.slice(n,r))}function ie(e,t,n){n=Math.min(e.length,n);let r=[],i=t;for(;i<n;){let t=e[i],a=null,o=t>239?4:t>223?3:t>191?2:1;if(i+o<=n){let n,r,s,c;switch(o){case 1:t<128&&(a=t);break;case 2:n=e[i+1],(n&192)==128&&(c=(t&31)<<6|n&63,c>127&&(a=c));break;case 3:n=e[i+1],r=e[i+2],(n&192)==128&&(r&192)==128&&(c=(t&15)<<12|(n&63)<<6|r&63,c>2047&&(c<55296||c>57343)&&(a=c));break;case 4:n=e[i+1],r=e[i+2],s=e[i+3],(n&192)==128&&(r&192)==128&&(s&192)==128&&(c=(t&15)<<18|(n&63)<<12|(r&63)<<6|s&63,c>65535&&c<1114112&&(a=c))}}a===null?(a=65533,o=1):a>65535&&(a-=65536,r.push(a>>>10&1023|55296),a=56320|a&1023),r.push(a),i+=o}return M(r)}let j=4096;function M(e){let t=e.length;if(t<=j)return String.fromCharCode.apply(String,e);let n=``,r=0;for(;r<t;)n+=String.fromCharCode.apply(String,e.slice(r,r+=j));return n}function ae(e,t,n){let r=``;n=Math.min(e.length,n);for(let i=t;i<n;++i)r+=String.fromCharCode(e[i]&127);return r}function oe(e,t,n){let r=``;n=Math.min(e.length,n);for(let i=t;i<n;++i)r+=String.fromCharCode(e[i]);return r}function N(e,t,n){let r=e.length;(!t||t<0)&&(t=0),(!n||n<0||n>r)&&(n=r);let i=``;for(let r=t;r<n;++r)i+=xe[e[r]];return i}function P(e,t,n){let r=e.slice(t,n),i=``;for(let e=0;e<r.length-1;e+=2)i+=String.fromCharCode(r[e]+r[e+1]*256);return i}d.prototype.slice=function(e,t){let n=this.length;e=~~e,t=t===void 0?n:~~t,e<0?(e+=n,e<0&&(e=0)):e>n&&(e=n),t<0?(t+=n,t<0&&(t=0)):t>n&&(t=n),t<e&&(t=e);let r=this.subarray(e,t);return Object.setPrototypeOf(r,d.prototype),r};function F(e,t,n){if(e%1!=0||e<0)throw RangeError(`offset is not uint`);if(e+t>n)throw RangeError(`Trying to access beyond buffer length`)}d.prototype.readUintLE=d.prototype.readUIntLE=function(e,t,n){e>>>=0,t>>>=0,n||F(e,t,this.length);let r=this[e],i=1,a=0;for(;++a<t&&(i*=256);)r+=this[e+a]*i;return r},d.prototype.readUintBE=d.prototype.readUIntBE=function(e,t,n){e>>>=0,t>>>=0,n||F(e,t,this.length);let r=this[e+--t],i=1;for(;t>0&&(i*=256);)r+=this[e+--t]*i;return r},d.prototype.readUint8=d.prototype.readUInt8=function(e,t){return e>>>=0,t||F(e,1,this.length),this[e]},d.prototype.readUint16LE=d.prototype.readUInt16LE=function(e,t){return e>>>=0,t||F(e,2,this.length),this[e]|this[e+1]<<8},d.prototype.readUint16BE=d.prototype.readUInt16BE=function(e,t){return e>>>=0,t||F(e,2,this.length),this[e]<<8|this[e+1]},d.prototype.readUint32LE=d.prototype.readUInt32LE=function(e,t){return e>>>=0,t||F(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216},d.prototype.readUint32BE=d.prototype.readUInt32BE=function(e,t){return e>>>=0,t||F(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])},d.prototype.readBigUInt64LE=W(function(e){e>>>=0,H(e,`offset`);let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&fe(e,this.length-8);let r=t+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24,i=this[++e]+this[++e]*2**8+this[++e]*2**16+n*2**24;return BigInt(r)+(BigInt(i)<<BigInt(32))}),d.prototype.readBigUInt64BE=W(function(e){e>>>=0,H(e,`offset`);let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&fe(e,this.length-8);let r=t*2**24+this[++e]*2**16+this[++e]*2**8+this[++e],i=this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+n;return(BigInt(r)<<BigInt(32))+BigInt(i)}),d.prototype.readIntLE=function(e,t,n){e>>>=0,t>>>=0,n||F(e,t,this.length);let r=this[e],i=1,a=0;for(;++a<t&&(i*=256);)r+=this[e+a]*i;return i*=128,r>=i&&(r-=2**(8*t)),r},d.prototype.readIntBE=function(e,t,n){e>>>=0,t>>>=0,n||F(e,t,this.length);let r=t,i=1,a=this[e+--r];for(;r>0&&(i*=256);)a+=this[e+--r]*i;return i*=128,a>=i&&(a-=2**(8*t)),a},d.prototype.readInt8=function(e,t){return e>>>=0,t||F(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]},d.prototype.readInt16LE=function(e,t){e>>>=0,t||F(e,2,this.length);let n=this[e]|this[e+1]<<8;return n&32768?n|4294901760:n},d.prototype.readInt16BE=function(e,t){e>>>=0,t||F(e,2,this.length);let n=this[e+1]|this[e]<<8;return n&32768?n|4294901760:n},d.prototype.readInt32LE=function(e,t){return e>>>=0,t||F(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},d.prototype.readInt32BE=function(e,t){return e>>>=0,t||F(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},d.prototype.readBigInt64LE=W(function(e){e>>>=0,H(e,`offset`);let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&fe(e,this.length-8);let r=this[e+4]+this[e+5]*2**8+this[e+6]*2**16+(n<<24);return(BigInt(r)<<BigInt(32))+BigInt(t+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24)}),d.prototype.readBigInt64BE=W(function(e){e>>>=0,H(e,`offset`);let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&fe(e,this.length-8);let r=(t<<24)+this[++e]*2**16+this[++e]*2**8+this[++e];return(BigInt(r)<<BigInt(32))+BigInt(this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+n)}),d.prototype.readFloatLE=function(e,t){return e>>>=0,t||F(e,4,this.length),r.read(this,e,!0,23,4)},d.prototype.readFloatBE=function(e,t){return e>>>=0,t||F(e,4,this.length),r.read(this,e,!1,23,4)},d.prototype.readDoubleLE=function(e,t){return e>>>=0,t||F(e,8,this.length),r.read(this,e,!0,52,8)},d.prototype.readDoubleBE=function(e,t){return e>>>=0,t||F(e,8,this.length),r.read(this,e,!1,52,8)};function I(e,t,n,r,i,a){if(!d.isBuffer(e))throw TypeError(`"buffer" argument must be a Buffer instance`);if(t>i||t<a)throw RangeError(`"value" argument is out of bounds`);if(n+r>e.length)throw RangeError(`Index out of range`)}d.prototype.writeUintLE=d.prototype.writeUIntLE=function(e,t,n,r){if(e=+e,t>>>=0,n>>>=0,!r){let r=2**(8*n)-1;I(this,e,t,n,r,0)}let i=1,a=0;for(this[t]=e&255;++a<n&&(i*=256);)this[t+a]=e/i&255;return t+n},d.prototype.writeUintBE=d.prototype.writeUIntBE=function(e,t,n,r){if(e=+e,t>>>=0,n>>>=0,!r){let r=2**(8*n)-1;I(this,e,t,n,r,0)}let i=n-1,a=1;for(this[t+i]=e&255;--i>=0&&(a*=256);)this[t+i]=e/a&255;return t+n},d.prototype.writeUint8=d.prototype.writeUInt8=function(e,t,n){return e=+e,t>>>=0,n||I(this,e,t,1,255,0),this[t]=e&255,t+1},d.prototype.writeUint16LE=d.prototype.writeUInt16LE=function(e,t,n){return e=+e,t>>>=0,n||I(this,e,t,2,65535,0),this[t]=e&255,this[t+1]=e>>>8,t+2},d.prototype.writeUint16BE=d.prototype.writeUInt16BE=function(e,t,n){return e=+e,t>>>=0,n||I(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=e&255,t+2},d.prototype.writeUint32LE=d.prototype.writeUInt32LE=function(e,t,n){return e=+e,t>>>=0,n||I(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=e&255,t+4},d.prototype.writeUint32BE=d.prototype.writeUInt32BE=function(e,t,n){return e=+e,t>>>=0,n||I(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e&255,t+4};function se(e,t,n,r,i){de(t,r,i,e,n,7);let a=Number(t&BigInt(4294967295));e[n++]=a,a>>=8,e[n++]=a,a>>=8,e[n++]=a,a>>=8,e[n++]=a;let o=Number(t>>BigInt(32)&BigInt(4294967295));return e[n++]=o,o>>=8,e[n++]=o,o>>=8,e[n++]=o,o>>=8,e[n++]=o,n}function L(e,t,n,r,i){de(t,r,i,e,n,7);let a=Number(t&BigInt(4294967295));e[n+7]=a,a>>=8,e[n+6]=a,a>>=8,e[n+5]=a,a>>=8,e[n+4]=a;let o=Number(t>>BigInt(32)&BigInt(4294967295));return e[n+3]=o,o>>=8,e[n+2]=o,o>>=8,e[n+1]=o,o>>=8,e[n]=o,n+8}d.prototype.writeBigUInt64LE=W(function(e,t=0){return se(this,e,t,BigInt(0),BigInt(`0xffffffffffffffff`))}),d.prototype.writeBigUInt64BE=W(function(e,t=0){return L(this,e,t,BigInt(0),BigInt(`0xffffffffffffffff`))}),d.prototype.writeIntLE=function(e,t,n,r){if(e=+e,t>>>=0,!r){let r=2**(8*n-1);I(this,e,t,n,r-1,-r)}let i=0,a=1,o=0;for(this[t]=e&255;++i<n&&(a*=256);)e<0&&o===0&&this[t+i-1]!==0&&(o=1),this[t+i]=(e/a>>0)-o&255;return t+n},d.prototype.writeIntBE=function(e,t,n,r){if(e=+e,t>>>=0,!r){let r=2**(8*n-1);I(this,e,t,n,r-1,-r)}let i=n-1,a=1,o=0;for(this[t+i]=e&255;--i>=0&&(a*=256);)e<0&&o===0&&this[t+i+1]!==0&&(o=1),this[t+i]=(e/a>>0)-o&255;return t+n},d.prototype.writeInt8=function(e,t,n){return e=+e,t>>>=0,n||I(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=e&255,t+1},d.prototype.writeInt16LE=function(e,t,n){return e=+e,t>>>=0,n||I(this,e,t,2,32767,-32768),this[t]=e&255,this[t+1]=e>>>8,t+2},d.prototype.writeInt16BE=function(e,t,n){return e=+e,t>>>=0,n||I(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=e&255,t+2},d.prototype.writeInt32LE=function(e,t,n){return e=+e,t>>>=0,n||I(this,e,t,4,2147483647,-2147483648),this[t]=e&255,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4},d.prototype.writeInt32BE=function(e,t,n){return e=+e,t>>>=0,n||I(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e&255,t+4},d.prototype.writeBigInt64LE=W(function(e,t=0){return se(this,e,t,-BigInt(`0x8000000000000000`),BigInt(`0x7fffffffffffffff`))}),d.prototype.writeBigInt64BE=W(function(e,t=0){return L(this,e,t,-BigInt(`0x8000000000000000`),BigInt(`0x7fffffffffffffff`))});function ce(e,t,n,r,i,a){if(n+r>e.length||n<0)throw RangeError(`Index out of range`)}function R(e,t,n,i,a){return t=+t,n>>>=0,a||ce(e,t,n,4),r.write(e,t,n,i,23,4),n+4}d.prototype.writeFloatLE=function(e,t,n){return R(this,e,t,!0,n)},d.prototype.writeFloatBE=function(e,t,n){return R(this,e,t,!1,n)};function z(e,t,n,i,a){return t=+t,n>>>=0,a||ce(e,t,n,8),r.write(e,t,n,i,52,8),n+8}d.prototype.writeDoubleLE=function(e,t,n){return z(this,e,t,!0,n)},d.prototype.writeDoubleBE=function(e,t,n){return z(this,e,t,!1,n)},d.prototype.copy=function(e,t,n,r){if(!d.isBuffer(e))throw TypeError(`argument should be a Buffer`);if(n||=0,!r&&r!==0&&(r=this.length),t>=e.length&&(t=e.length),t||=0,r>0&&r<n&&(r=n),r===n||e.length===0||this.length===0)return 0;if(t<0)throw RangeError(`targetStart out of bounds`);if(n<0||n>=this.length)throw RangeError(`Index out of range`);if(r<0)throw RangeError(`sourceEnd out of bounds`);r>this.length&&(r=this.length),e.length-t<r-n&&(r=e.length-t+n);let i=r-n;return this===e&&typeof o.prototype.copyWithin==`function`?this.copyWithin(t,n,r):o.prototype.set.call(e,this.subarray(n,r),t),i},d.prototype.fill=function(e,t,n,r){if(typeof e==`string`){if(typeof t==`string`?(r=t,t=0,n=this.length):typeof n==`string`&&(r=n,n=this.length),r!==void 0&&typeof r!=`string`)throw TypeError(`encoding must be a string`);if(typeof r==`string`&&!d.isEncoding(r))throw TypeError(`Unknown encoding: `+r);if(e.length===1){let t=e.charCodeAt(0);(r===`utf8`&&t<128||r===`latin1`)&&(e=t)}}else typeof e==`number`?e&=255:typeof e==`boolean`&&(e=Number(e));if(t<0||this.length<t||this.length<n)throw RangeError(`Out of range index`);if(n<=t)return this;t>>>=0,n=n===void 0?this.length:n>>>0,e||=0;let i;if(typeof e==`number`)for(i=t;i<n;++i)this[i]=e;else{let a=d.isBuffer(e)?e:d.from(e,r),o=a.length;if(o===0)throw TypeError(`The value "`+e+`" is invalid for argument "value"`);for(i=0;i<n-t;++i)this[i+t]=a[i%o]}return this};let le={};function B(e,t,n){le[e]=class extends n{constructor(){super(),Object.defineProperty(this,"message",{value:t.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${e}]`,this.stack,delete this.name}get code(){return e}set code(e){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:e,writable:!0})}toString(){return`${this.name} [${e}]: ${this.message}`}}}B(`ERR_BUFFER_OUT_OF_BOUNDS`,function(e){return e?`${e} is outside of buffer bounds`:`Attempt to access memory outside buffer bounds`},RangeError),B(`ERR_INVALID_ARG_TYPE`,function(e,t){return`The "${e}" argument must be of type number. Received type ${typeof t}`},TypeError),B(`ERR_OUT_OF_RANGE`,function(e,t,n){let r=`The value of "${e}" is out of range.`,i=n;return Number.isInteger(n)&&Math.abs(n)>2**32?i=V(String(n)):typeof n==`bigint`&&(i=String(n),(n>BigInt(2)**BigInt(32)||n<-(BigInt(2)**BigInt(32)))&&(i=V(i)),i+=`n`),r+=` It must be ${t}. Received ${i}`,r},RangeError);function V(e){let t=``,n=e.length,r=+(e[0]===`-`);for(;n>=r+4;n-=3)t=`_${e.slice(n-3,n)}${t}`;return`${e.slice(0,n)}${t}`}function ue(e,t,n){H(t,`offset`),(e[t]===void 0||e[t+n]===void 0)&&fe(t,e.length-(n+1))}function de(e,t,n,r,i,a){if(e>n||e<t){let r=typeof t==`bigint`?`n`:``,i;throw i=a>3?t===0||t===BigInt(0)?`>= 0${r} and < 2${r} ** ${(a+1)*8}${r}`:`>= -(2${r} ** ${(a+1)*8-1}${r}) and < 2 ** ${(a+1)*8-1}${r}`:`>= ${t}${r} and <= ${n}${r}`,new le.ERR_OUT_OF_RANGE(`value`,i,e)}ue(r,i,a)}function H(e,t){if(typeof e!=`number`)throw new le.ERR_INVALID_ARG_TYPE(t,`number`,e)}function fe(e,t,n){throw Math.floor(e)===e?t<0?new le.ERR_BUFFER_OUT_OF_BOUNDS:new le.ERR_OUT_OF_RANGE(n||`offset`,`>= ${+!!n} and <= ${t}`,e):(H(e,n),new le.ERR_OUT_OF_RANGE(n||`offset`,`an integer`,e))}let pe=/[^+/0-9A-Za-z-_]/g;function me(e){if(e=e.split(`=`)[0],e=e.trim().replace(pe,``),e.length<2)return``;for(;e.length%4!=0;)e+=`=`;return e}function he(e,t){t||=1/0;let n,r=e.length,i=null,a=[];for(let o=0;o<r;++o){if(n=e.charCodeAt(o),n>55295&&n<57344){if(!i){if(n>56319){(t-=3)>-1&&a.push(239,191,189);continue}else if(o+1===r){(t-=3)>-1&&a.push(239,191,189);continue}i=n;continue}if(n<56320){(t-=3)>-1&&a.push(239,191,189),i=n;continue}n=(i-55296<<10|n-56320)+65536}else i&&(t-=3)>-1&&a.push(239,191,189);if(i=null,n<128){if(--t<0)break;a.push(n)}else if(n<2048){if((t-=2)<0)break;a.push(n>>6|192,n&63|128)}else if(n<65536){if((t-=3)<0)break;a.push(n>>12|224,n>>6&63|128,n&63|128)}else if(n<1114112){if((t-=4)<0)break;a.push(n>>18|240,n>>12&63|128,n>>6&63|128,n&63|128)}else throw Error(`Invalid code point`)}return a}function ge(e){let t=[];for(let n=0;n<e.length;++n)t.push(e.charCodeAt(n)&255);return t}function _e(e,t){let n,r,i,a=[];for(let o=0;o<e.length&&!((t-=2)<0);++o)n=e.charCodeAt(o),r=n>>8,i=n%256,a.push(i),a.push(r);return a}function ve(e){return t.toByteArray(me(e))}function U(e,t,n,r){let i;for(i=0;i<r&&!(i+n>=t.length||i>=e.length);++i)t[i+n]=e[i];return i}function ye(e,t){return e instanceof t||e!=null&&e.constructor!=null&&e.constructor.name!=null&&e.constructor.name===t.name}function be(e){return e!==e}let xe=(function(){let e=`0123456789abcdef`,t=Array(256);for(let n=0;n<16;++n){let r=n*16;for(let i=0;i<16;++i)t[r+i]=e[n]+e[i]}return t})();function W(e){return typeof BigInt>`u`?Se:e}function Se(){throw Error(`BigInt not supported`)}})(t);var _=t.Buffer;e.Blob=t.Blob,e.BlobOptions=t.BlobOptions,e.Buffer=t.Buffer,e.File=t.File,e.FileOptions=t.FileOptions,e.INSPECT_MAX_BYTES=t.INSPECT_MAX_BYTES,e.SlowBuffer=t.SlowBuffer,e.TranscodeEncoding=t.TranscodeEncoding,e.atob=t.atob,e.btoa=t.btoa,e.constants=t.constants,e.default=_,e.isAscii=t.isAscii,e.isUtf8=t.isUtf8,e.kMaxLength=t.kMaxLength,e.kStringMaxLength=t.kStringMaxLength,e.resolveObjectURL=t.resolveObjectURL,e.transcode=t.transcode})),D=t(((e,t)=>{t.exports={}})),te=t(((e,t)=>{function n(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function r(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]==null?{}:arguments[t];t%2?n(Object(r),!0).forEach(function(t){i(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):n(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function i(e,t,n){return t=c(t),t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function o(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,c(r.key),r)}}function s(e,t,n){return t&&o(e.prototype,t),n&&o(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function c(e){var t=l(e,`string`);return typeof t==`symbol`?t:String(t)}function l(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}var u=E().Buffer,d=D().inspect,f=d&&d.custom||`inspect`;function p(e,t,n){u.prototype.copy.call(e,t,n)}t.exports=function(){function e(){a(this,e),this.head=null,this.tail=null,this.length=0}return s(e,[{key:`push`,value:function(e){var t={data:e,next:null};this.length>0?this.tail.next=t:this.head=t,this.tail=t,++this.length}},{key:`unshift`,value:function(e){var t={data:e,next:this.head};this.length===0&&(this.tail=t),this.head=t,++this.length}},{key:`shift`,value: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}}},{key:`clear`,value:function(){this.head=this.tail=null,this.length=0}},{key:`join`,value:function(e){if(this.length===0)return``;for(var t=this.head,n=``+t.data;t=t.next;)n+=e+t.data;return n}},{key:`concat`,value:function(e){if(this.length===0)return u.alloc(0);for(var t=u.allocUnsafe(e>>>0),n=this.head,r=0;n;)p(n.data,t,r),r+=n.data.length,n=n.next;return t}},{key:`consume`,value:function(e,t){var n;return e<this.head.data.length?(n=this.head.data.slice(0,e),this.head.data=this.head.data.slice(e)):n=e===this.head.data.length?this.shift():t?this._getString(e):this._getBuffer(e),n}},{key:`first`,value:function(){return this.head.data}},{key:`_getString`,value:function(e){var t=this.head,n=1,r=t.data;for(e-=r.length;t=t.next;){var i=t.data,a=e>i.length?i.length:e;if(a===i.length?r+=i:r+=i.slice(0,e),e-=a,e===0){a===i.length?(++n,t.next?this.head=t.next:this.head=this.tail=null):(this.head=t,t.data=i.slice(a));break}++n}return this.length-=n,r}},{key:`_getBuffer`,value:function(e){var t=u.allocUnsafe(e),n=this.head,r=1;for(n.data.copy(t),e-=n.data.length;n=n.next;){var i=n.data,a=e>i.length?i.length:e;if(i.copy(t,t.length-e,0,a),e-=a,e===0){a===i.length?(++r,n.next?this.head=n.next:this.head=this.tail=null):(this.head=n,n.data=i.slice(a));break}++r}return this.length-=r,t}},{key:f,value:function(e,t){return d(this,r(r({},t),{},{depth:0,customInspect:!1}))}}]),e}()})),O=t(((e,t)=>{w();function n(e,t){var n=this,a=this._readableState&&this._readableState.destroyed,s=this._writableState&&this._writableState.destroyed;return a||s?(t?t(e):e&&(this._writableState?this._writableState.errorEmitted||(this._writableState.errorEmitted=!0,C.nextTick(o,this,e)):C.nextTick(o,this,e)),this):(this._readableState&&(this._readableState.destroyed=!0),this._writableState&&(this._writableState.destroyed=!0),this._destroy(e||null,function(e){!t&&e?n._writableState?n._writableState.errorEmitted?C.nextTick(i,n):(n._writableState.errorEmitted=!0,C.nextTick(r,n,e)):C.nextTick(r,n,e):t?(C.nextTick(i,n),t(e)):C.nextTick(i,n)}),this)}function r(e,t){o(e,t),i(e)}function i(e){e._writableState&&!e._writableState.emitClose||e._readableState&&!e._readableState.emitClose||e.emit(`close`)}function a(){this._readableState&&(this._readableState.destroyed=!1,this._readableState.reading=!1,this._readableState.ended=!1,this._readableState.endEmitted=!1),this._writableState&&(this._writableState.destroyed=!1,this._writableState.ended=!1,this._writableState.ending=!1,this._writableState.finalCalled=!1,this._writableState.prefinished=!1,this._writableState.finished=!1,this._writableState.errorEmitted=!1)}function o(e,t){e.emit(`error`,t)}function s(e,t){var n=e._readableState,r=e._writableState;n&&n.autoDestroy||r&&r.autoDestroy?e.destroy(t):e.emit(`error`,t)}t.exports={destroy:n,undestroy:a,errorOrDestroy:s}})),ne=t(((e,t)=>{function n(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}var r={};function i(e,t,i){i||=Error;function a(e,n,r){return typeof t==`string`?t:t(e,n,r)}var o=function(e){n(t,e);function t(t,n,r){return e.call(this,a(t,n,r))||this}return t}(i);o.prototype.name=i.name,o.prototype.code=e,r[e]=o}function a(e,t){if(Array.isArray(e)){var n=e.length;return e=e.map(function(e){return String(e)}),n>2?`one of ${t} ${e.slice(0,n-1).join(`, `)}, or `+e[n-1]:n===2?`one of ${t} ${e[0]} or ${e[1]}`:`of ${t} ${e[0]}`}else return`of ${t} ${String(e)}`}function o(e,t,n){return e.substr(!n||n<0?0:+n,t.length)===t}function s(e,t,n){return(n===void 0||n>e.length)&&(n=e.length),e.substring(n-t.length,n)===t}function c(e,t,n){return typeof n!=`number`&&(n=0),n+t.length>e.length?!1:e.indexOf(t,n)!==-1}i(`ERR_INVALID_OPT_VALUE`,function(e,t){return`The value "`+t+`" is invalid for option "`+e+`"`},TypeError),i(`ERR_INVALID_ARG_TYPE`,function(e,t,n){var r;typeof t==`string`&&o(t,`not `)?(r=`must not be`,t=t.replace(/^not /,``)):r=`must be`;var i=s(e,` argument`)?`The ${e} ${r} ${a(t,`type`)}`:`The "${e}" ${c(e,`.`)?`property`:`argument`} ${r} ${a(t,`type`)}`;return i+=`. Received type ${typeof n}`,i},TypeError),i(`ERR_STREAM_PUSH_AFTER_EOF`,`stream.push() after EOF`),i(`ERR_METHOD_NOT_IMPLEMENTED`,function(e){return`The `+e+` method is not implemented`}),i(`ERR_STREAM_PREMATURE_CLOSE`,`Premature close`),i(`ERR_STREAM_DESTROYED`,function(e){return`Cannot call `+e+` after a stream was destroyed`}),i(`ERR_MULTIPLE_CALLBACK`,`Callback called multiple times`),i(`ERR_STREAM_CANNOT_PIPE`,`Cannot pipe, not readable`),i(`ERR_STREAM_WRITE_AFTER_END`,`write after end`),i(`ERR_STREAM_NULL_VALUES`,`May not write null values to stream`,TypeError),i(`ERR_UNKNOWN_ENCODING`,function(e){return`Unknown encoding: `+e},TypeError),i(`ERR_STREAM_UNSHIFT_AFTER_END_EVENT`,`stream.unshift() after end event`),t.exports.codes=r})),k=t(((e,t)=>{var n=ne().codes.ERR_INVALID_OPT_VALUE;function r(e,t,n){return e.highWaterMark==null?t?e[n]:null:e.highWaterMark}function i(e,t,i,a){var o=r(t,a,i);if(o!=null){if(!(isFinite(o)&&Math.floor(o)===o)||o<0)throw new n(a?i:`highWaterMark`,o);return Math.floor(o)}return e.objectMode?16:16*1024}t.exports={getHighWaterMark:i}})),re=t(((e,t)=>{a(),t.exports=n;function n(e,t){if(r(`noDeprecation`))return e;var n=!1;function i(){if(!n){if(r(`throwDeprecation`))throw Error(t);r(`traceDeprecation`)?console.trace(t):console.warn(t),n=!0}return e.apply(this,arguments)}return i}function r(e){try{if(!i.localStorage)return!1}catch{return!1}var t=i.localStorage[e];return t!=null&&String(t).toLowerCase()===`true`}})),A=t(((e,t)=>{a(),w(),t.exports=M;function n(e){var t=this;this.next=null,this.entry=null,this.finish=function(){H(t,e)}}var o;M.WritableState=A;var s={deprecate:re()},c=T(),l=E().Buffer,u=(i===void 0?typeof window<`u`?window:typeof self<`u`?self:{}:i).Uint8Array||function(){};function d(e){return l.from(e)}function f(e){return l.isBuffer(e)||e instanceof u}var p=O(),m=k().getHighWaterMark,h=ne().codes,g=h.ERR_INVALID_ARG_TYPE,_=h.ERR_METHOD_NOT_IMPLEMENTED,v=h.ERR_MULTIPLE_CALLBACK,y=h.ERR_STREAM_CANNOT_PIPE,b=h.ERR_STREAM_DESTROYED,x=h.ERR_STREAM_NULL_VALUES,S=h.ERR_STREAM_WRITE_AFTER_END,ee=h.ERR_UNKNOWN_ENCODING,D=p.errorOrDestroy;r()(M,c);function te(){}function A(e,t,r){o||=ie(),e||={},typeof r!=`boolean`&&(r=t instanceof o),this.objectMode=!!e.objectMode,r&&(this.objectMode=this.objectMode||!!e.writableObjectMode),this.highWaterMark=m(this,e,`writableHighWaterMark`,r),this.finalCalled=!1,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1,this.destroyed=!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(e){L(t,e)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.emitClose=e.emitClose!==!1,this.autoDestroy=!!e.autoDestroy,this.bufferedRequestCount=0,this.corkedRequestsFree=new n(this)}A.prototype.getBuffer=function(){for(var e=this.bufferedRequest,t=[];e;)t.push(e),e=e.next;return t},(function(){try{Object.defineProperty(A.prototype,"buffer",{get:s.deprecate(function(){return this.getBuffer()},`_writableState.buffer is deprecated. Use _writableState.getBuffer instead.`,`DEP0003`)})}catch{}})();var j;typeof Symbol==`function`&&Symbol.hasInstance&&typeof Function.prototype[Symbol.hasInstance]==`function`?(j=Function.prototype[Symbol.hasInstance],Object.defineProperty(M,Symbol.hasInstance,{value:function(e){return j.call(this,e)?!0:this===M&&e&&e._writableState instanceof A}})):j=function(e){return e instanceof this};function M(e){o||=ie();var t=this instanceof o;if(!t&&!j.call(M,this))return new M(e);this._writableState=new A(e,this,t),this.writable=!0,e&&(typeof e.write==`function`&&(this._write=e.write),typeof e.writev==`function`&&(this._writev=e.writev),typeof e.destroy==`function`&&(this._destroy=e.destroy),typeof e.final==`function`&&(this._final=e.final)),c.call(this)}M.prototype.pipe=function(){D(this,new y)};function ae(e,t){var n=new S;D(e,n),C.nextTick(t,n)}function oe(e,t,n,r){var i;return n===null?i=new x:typeof n!=`string`&&!t.objectMode&&(i=new g(`chunk`,[`string`,`Buffer`],n)),i?(D(e,i),C.nextTick(r,i),!1):!0}M.prototype.write=function(e,t,n){var r=this._writableState,i=!1,a=!r.objectMode&&f(e);return a&&!l.isBuffer(e)&&(e=d(e)),typeof t==`function`&&(n=t,t=null),a?t=`buffer`:t||=r.defaultEncoding,typeof n!=`function`&&(n=te),r.ending?ae(this,n):(a||oe(this,r,e,n))&&(r.pendingcb++,i=P(this,r,a,e,t,n)),i},M.prototype.cork=function(){this._writableState.corked++},M.prototype.uncork=function(){var e=this._writableState;e.corked&&(e.corked--,!e.writing&&!e.corked&&!e.bufferProcessing&&e.bufferedRequest&&z(this,e))},M.prototype.setDefaultEncoding=function(e){if(typeof e==`string`&&(e=e.toLowerCase()),!([`hex`,`utf8`,`utf-8`,`ascii`,`binary`,`base64`,`ucs2`,`ucs-2`,`utf16le`,`utf-16le`,`raw`].indexOf((e+``).toLowerCase())>-1))throw new ee(e);return this._writableState.defaultEncoding=e,this},Object.defineProperty(M.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}});function N(e,t,n){return!e.objectMode&&e.decodeStrings!==!1&&typeof t==`string`&&(t=l.from(t,n)),t}Object.defineProperty(M.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}});function P(e,t,n,r,i,a){if(!n){var o=N(t,r,i);r!==o&&(n=!0,i=`buffer`,r=o)}var s=t.objectMode?1:r.length;t.length+=s;var c=t.length<t.highWaterMark;if(c||(t.needDrain=!0),t.writing||t.corked){var l=t.lastBufferedRequest;t.lastBufferedRequest={chunk:r,encoding:i,isBuf:n,callback:a,next:null},l?l.next=t.lastBufferedRequest:t.bufferedRequest=t.lastBufferedRequest,t.bufferedRequestCount+=1}else F(e,t,!1,s,r,i,a);return c}function F(e,t,n,r,i,a,o){t.writelen=r,t.writecb=o,t.writing=!0,t.sync=!0,t.destroyed?t.onwrite(new b(`write`)):n?e._writev(i,t.onwrite):e._write(i,a,t.onwrite),t.sync=!1}function I(e,t,n,r,i){--t.pendingcb,n?(C.nextTick(i,r),C.nextTick(ue,e,t),e._writableState.errorEmitted=!0,D(e,r)):(i(r),e._writableState.errorEmitted=!0,D(e,r),ue(e,t))}function se(e){e.writing=!1,e.writecb=null,e.length-=e.writelen,e.writelen=0}function L(e,t){var n=e._writableState,r=n.sync,i=n.writecb;if(typeof i!=`function`)throw new v;if(se(n),t)I(e,n,r,t,i);else{var a=le(n)||e.destroyed;!a&&!n.corked&&!n.bufferProcessing&&n.bufferedRequest&&z(e,n),r?C.nextTick(ce,e,n,a,i):ce(e,n,a,i)}}function ce(e,t,n,r){n||R(e,t),t.pendingcb--,r(),ue(e,t)}function R(e,t){t.length===0&&t.needDrain&&(t.needDrain=!1,e.emit(`drain`))}function z(e,t){t.bufferProcessing=!0;var r=t.bufferedRequest;if(e._writev&&r&&r.next){var i=t.bufferedRequestCount,a=Array(i),o=t.corkedRequestsFree;o.entry=r;for(var s=0,c=!0;r;)a[s]=r,r.isBuf||(c=!1),r=r.next,s+=1;a.allBuffers=c,F(e,t,!0,t.length,a,``,o.finish),t.pendingcb++,t.lastBufferedRequest=null,o.next?(t.corkedRequestsFree=o.next,o.next=null):t.corkedRequestsFree=new n(t),t.bufferedRequestCount=0}else{for(;r;){var l=r.chunk,u=r.encoding,d=r.callback;if(F(e,t,!1,t.objectMode?1:l.length,l,u,d),r=r.next,t.bufferedRequestCount--,t.writing)break}r===null&&(t.lastBufferedRequest=null)}t.bufferedRequest=r,t.bufferProcessing=!1}M.prototype._write=function(e,t,n){n(new _(`_write()`))},M.prototype._writev=null,M.prototype.end=function(e,t,n){var r=this._writableState;return typeof e==`function`?(n=e,e=null,t=null):typeof t==`function`&&(n=t,t=null),e!=null&&this.write(e,t),r.corked&&(r.corked=1,this.uncork()),r.ending||de(this,r,n),this},Object.defineProperty(M.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}});function le(e){return e.ending&&e.length===0&&e.bufferedRequest===null&&!e.finished&&!e.writing}function B(e,t){e._final(function(n){t.pendingcb--,n&&D(e,n),t.prefinished=!0,e.emit(`prefinish`),ue(e,t)})}function V(e,t){!t.prefinished&&!t.finalCalled&&(typeof e._final==`function`&&!t.destroyed?(t.pendingcb++,t.finalCalled=!0,C.nextTick(B,e,t)):(t.prefinished=!0,e.emit(`prefinish`)))}function ue(e,t){var n=le(t);if(n&&(V(e,t),t.pendingcb===0&&(t.finished=!0,e.emit(`finish`),t.autoDestroy))){var r=e._readableState;(!r||r.autoDestroy&&r.endEmitted)&&e.destroy()}return n}function de(e,t,n){t.ending=!0,ue(e,t),n&&(t.finished?C.nextTick(n):e.once(`finish`,n)),t.ended=!0,e.writable=!1}function H(e,t,n){var r=e.entry;for(e.entry=null;r;){var i=r.callback;t.pendingcb--,i(n),r=r.next}t.corkedRequestsFree.next=e}Object.defineProperty(M.prototype,"destroyed",{enumerable:!1,get:function(){return this._writableState!==void 0&&this._writableState.destroyed},set:function(e){this._writableState&&(this._writableState.destroyed=e)}}),M.prototype.destroy=p.destroy,M.prototype._undestroy=p.undestroy,M.prototype._destroy=function(e,t){t(e)}})),ie=t(((e,t)=>{w();var n=Object.keys||function(e){var t=[];for(var n in e)t.push(n);return t};t.exports=l;var i=P(),a=A();r()(l,i);for(var o=n(a.prototype),s=0;s<o.length;s++){var c=o[s];l.prototype[c]||(l.prototype[c]=a.prototype[c])}function l(e){if(!(this instanceof l))return new l(e);i.call(this,e),a.call(this,e),this.allowHalfOpen=!0,e&&(e.readable===!1&&(this.readable=!1),e.writable===!1&&(this.writable=!1),e.allowHalfOpen===!1&&(this.allowHalfOpen=!1,this.once(`end`,u)))}Object.defineProperty(l.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),Object.defineProperty(l.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(l.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}});function u(){this._writableState.ended||C.nextTick(d,this)}function d(e){e.end()}Object.defineProperty(l.prototype,"destroyed",{enumerable:!1,get:function(){return this._readableState===void 0||this._writableState===void 0?!1:this._readableState.destroyed&&this._writableState.destroyed},set:function(e){this._readableState===void 0||this._writableState===void 0||(this._readableState.destroyed=e,this._writableState.destroyed=e)}})})),j=t(((e,t)=>{var n=E(),r=n.Buffer;function i(e,t){for(var n in e)t[n]=e[n]}r.from&&r.alloc&&r.allocUnsafe&&r.allocUnsafeSlow?t.exports=n:(i(n,e),e.Buffer=a);function a(e,t,n){return r(e,t,n)}a.prototype=Object.create(r.prototype),i(r,a),a.from=function(e,t,n){if(typeof e==`number`)throw TypeError(`Argument must not be a number`);return r(e,t,n)},a.alloc=function(e,t,n){if(typeof e!=`number`)throw TypeError(`Argument must be a number`);var i=r(e);return t===void 0?i.fill(0):typeof n==`string`?i.fill(t,n):i.fill(t),i},a.allocUnsafe=function(e){if(typeof e!=`number`)throw TypeError(`Argument must be a number`);return r(e)},a.allocUnsafeSlow=function(e){if(typeof e!=`number`)throw TypeError(`Argument must be a number`);return n.SlowBuffer(e)}})),M=t((e=>{var t=j().Buffer,n=t.isEncoding||function(e){switch(e=``+e,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 r(e){if(!e)return`utf8`;for(var t;;)switch(e){case`utf8`:case`utf-8`:return`utf8`;case`ucs2`:case`ucs-2`:case`utf16le`:case`utf-16le`:return`utf16le`;case`latin1`:case`binary`:return`latin1`;case`base64`:case`ascii`:case`hex`:return e;default:if(t)return;e=(``+e).toLowerCase(),t=!0}}function i(e){var i=r(e);if(typeof i!=`string`&&(t.isEncoding===n||!n(e)))throw Error(`Unknown encoding: `+e);return i||e}e.StringDecoder=a;function a(e){this.encoding=i(e);var n;switch(this.encoding){case`utf16le`:this.text=f,this.end=p,n=4;break;case`utf8`:this.fillLast=l,n=4;break;case`base64`:this.text=m,this.end=h,n=3;break;default:this.write=g,this.end=_;return}this.lastNeed=0,this.lastTotal=0,this.lastChar=t.allocUnsafe(n)}a.prototype.write=function(e){if(e.length===0)return``;var t,n;if(this.lastNeed){if(t=this.fillLast(e),t===void 0)return``;n=this.lastNeed,this.lastNeed=0}else n=0;return n<e.length?t?t+this.text(e,n):this.text(e,n):t||``},a.prototype.end=d,a.prototype.text=u,a.prototype.fillLast=function(e){if(this.lastNeed<=e.length)return e.copy(this.lastChar,this.lastTotal-this.lastNeed,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);e.copy(this.lastChar,this.lastTotal-this.lastNeed,0,e.length),this.lastNeed-=e.length};function o(e){return e<=127?0:e>>5==6?2:e>>4==14?3:e>>3==30?4:e>>6==2?-1:-2}function s(e,t,n){var r=t.length-1;if(r<n)return 0;var i=o(t[r]);return i>=0?(i>0&&(e.lastNeed=i-1),i):--r<n||i===-2?0:(i=o(t[r]),i>=0?(i>0&&(e.lastNeed=i-2),i):--r<n||i===-2?0:(i=o(t[r]),i>=0?(i>0&&(i===2?i=0:e.lastNeed=i-3),i):0))}function c(e,t,n){if((t[0]&192)!=128)return e.lastNeed=0,`�`;if(e.lastNeed>1&&t.length>1){if((t[1]&192)!=128)return e.lastNeed=1,`�`;if(e.lastNeed>2&&t.length>2&&(t[2]&192)!=128)return e.lastNeed=2,`�`}}function l(e){var t=this.lastTotal-this.lastNeed,n=c(this,e,t);if(n!==void 0)return n;if(this.lastNeed<=e.length)return e.copy(this.lastChar,t,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);e.copy(this.lastChar,t,0,e.length),this.lastNeed-=e.length}function u(e,t){var n=s(this,e,t);if(!this.lastNeed)return e.toString(`utf8`,t);this.lastTotal=n;var r=e.length-(n-this.lastNeed);return e.copy(this.lastChar,0,r),e.toString(`utf8`,t,r)}function d(e){var t=e&&e.length?this.write(e):``;return this.lastNeed?t+`�`:t}function f(e,t){if((e.length-t)%2==0){var n=e.toString(`utf16le`,t);if(n){var r=n.charCodeAt(n.length-1);if(r>=55296&&r<=56319)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1],n.slice(0,-1)}return n}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=e[e.length-1],e.toString(`utf16le`,t,e.length-1)}function p(e){var t=e&&e.length?this.write(e):``;if(this.lastNeed){var n=this.lastTotal-this.lastNeed;return t+this.lastChar.toString(`utf16le`,0,n)}return t}function m(e,t){var n=(e.length-t)%3;return n===0?e.toString(`base64`,t):(this.lastNeed=3-n,this.lastTotal=3,n===1?this.lastChar[0]=e[e.length-1]:(this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1]),e.toString(`base64`,t,e.length-n))}function h(e){var t=e&&e.length?this.write(e):``;return this.lastNeed?t+this.lastChar.toString(`base64`,0,3-this.lastNeed):t}function g(e){return e.toString(this.encoding)}function _(e){return e&&e.length?this.write(e):``}})),ae=t(((e,t)=>{var n=ne().codes.ERR_STREAM_PREMATURE_CLOSE;function r(e){var t=!1;return function(){if(!t){t=!0;for(var n=arguments.length,r=Array(n),i=0;i<n;i++)r[i]=arguments[i];e.apply(this,r)}}}function i(){}function a(e){return e.setHeader&&typeof e.abort==`function`}function o(e,t,s){if(typeof t==`function`)return o(e,null,t);t||={},s=r(s||i);var c=t.readable||t.readable!==!1&&e.readable,l=t.writable||t.writable!==!1&&e.writable,u=function(){e.writable||f()},d=e._writableState&&e._writableState.finished,f=function(){l=!1,d=!0,c||s.call(e)},p=e._readableState&&e._readableState.endEmitted,m=function(){c=!1,p=!0,l||s.call(e)},h=function(t){s.call(e,t)},g=function(){var t;if(c&&!p)return(!e._readableState||!e._readableState.ended)&&(t=new n),s.call(e,t);if(l&&!d)return(!e._writableState||!e._writableState.ended)&&(t=new n),s.call(e,t)},_=function(){e.req.on(`finish`,f)};return a(e)?(e.on(`complete`,f),e.on(`abort`,g),e.req?_():e.on(`request`,_)):l&&!e._writableState&&(e.on(`end`,u),e.on(`close`,u)),e.on(`end`,m),e.on(`finish`,f),t.error!==!1&&e.on(`error`,h),e.on(`close`,g),function(){e.removeListener(`complete`,f),e.removeListener(`abort`,g),e.removeListener(`request`,_),e.req&&e.req.removeListener(`finish`,f),e.removeListener(`end`,u),e.removeListener(`close`,u),e.removeListener(`finish`,f),e.removeListener(`end`,m),e.removeListener(`error`,h),e.removeListener(`close`,g)}}t.exports=o})),oe=t(((e,t)=>{w();var n;function r(e,t,n){return t=i(t),t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e){var t=a(e,`string`);return typeof t==`symbol`?t:String(t)}function a(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}var o=ae(),s=Symbol(`lastResolve`),c=Symbol(`lastReject`),l=Symbol(`error`),u=Symbol(`ended`),d=Symbol(`lastPromise`),f=Symbol(`handlePromise`),p=Symbol(`stream`);function m(e,t){return{value:e,done:t}}function h(e){var t=e[s];if(t!==null){var n=e[p].read();n!==null&&(e[d]=null,e[s]=null,e[c]=null,t(m(n,!1)))}}function g(e){C.nextTick(h,e)}function _(e,t){return function(n,r){e.then(function(){if(t[u]){n(m(void 0,!0));return}t[f](n,r)},r)}}var v=Object.getPrototypeOf(function(){}),y=Object.setPrototypeOf((n={get stream(){return this[p]},next:function(){var e=this,t=this[l];if(t!==null)return Promise.reject(t);if(this[u])return Promise.resolve(m(void 0,!0));if(this[p].destroyed)return new Promise(function(t,n){C.nextTick(function(){e[l]?n(e[l]):t(m(void 0,!0))})});var n=this[d],r;if(n)r=new Promise(_(n,this));else{var i=this[p].read();if(i!==null)return Promise.resolve(m(i,!1));r=new Promise(this[f])}return this[d]=r,r}},r(n,Symbol.asyncIterator,function(){return this}),r(n,`return`,function(){var e=this;return new Promise(function(t,n){e[p].destroy(null,function(e){if(e){n(e);return}t(m(void 0,!0))})})}),n),v);t.exports=function(e){var t,n=Object.create(y,(t={},r(t,p,{value:e,writable:!0}),r(t,s,{value:null,writable:!0}),r(t,c,{value:null,writable:!0}),r(t,l,{value:null,writable:!0}),r(t,u,{value:e._readableState.endEmitted,writable:!0}),r(t,f,{value:function(e,t){var r=n[p].read();r?(n[d]=null,n[s]=null,n[c]=null,e(m(r,!1))):(n[s]=e,n[c]=t)},writable:!0}),t));return n[d]=null,o(e,function(e){if(e&&e.code!==`ERR_STREAM_PREMATURE_CLOSE`){var t=n[c];t!==null&&(n[d]=null,n[s]=null,n[c]=null,t(e)),n[l]=e;return}var r=n[s];r!==null&&(n[d]=null,n[s]=null,n[c]=null,r(m(void 0,!0))),n[u]=!0}),e.on(`readable`,g.bind(null,n)),n}})),N=t(((e,t)=>{t.exports=function(){throw Error(`Readable.from is not available in the browser`)}})),P=t(((e,t)=>{a(),w(),t.exports=I;var o;I.ReadableState=F,n().EventEmitter;var s=function(e,t){return e.listeners(t).length},c=T(),l=E().Buffer,u=(i===void 0?typeof window<`u`?window:typeof self<`u`?self:{}:i).Uint8Array||function(){};function d(e){return l.from(e)}function f(e){return l.isBuffer(e)||e instanceof u}var p=D(),m=p&&p.debuglog?p.debuglog(`stream`):function(){},h=te(),g=O(),_=k().getHighWaterMark,v=ne().codes,y=v.ERR_INVALID_ARG_TYPE,b=v.ERR_STREAM_PUSH_AFTER_EOF,x=v.ERR_METHOD_NOT_IMPLEMENTED,S=v.ERR_STREAM_UNSHIFT_AFTER_END_EVENT,ee,re,A;r()(I,c);var j=g.errorOrDestroy,ae=[`error`,`close`,`destroy`,`pause`,`resume`];function P(e,t,n){if(typeof e.prependListener==`function`)return e.prependListener(t,n);!e._events||!e._events[t]?e.on(t,n):Array.isArray(e._events[t])?e._events[t].unshift(n):e._events[t]=[n,e._events[t]]}function F(e,t,n){o||=ie(),e||={},typeof n!=`boolean`&&(n=t instanceof o),this.objectMode=!!e.objectMode,n&&(this.objectMode=this.objectMode||!!e.readableObjectMode),this.highWaterMark=_(this,e,`readableHighWaterMark`,n),this.buffer=new h,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.paused=!0,this.emitClose=e.emitClose!==!1,this.autoDestroy=!!e.autoDestroy,this.destroyed=!1,this.defaultEncoding=e.defaultEncoding||`utf8`,this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,e.encoding&&(ee||=M().StringDecoder,this.decoder=new ee(e.encoding),this.encoding=e.encoding)}function I(e){if(o||=ie(),!(this instanceof I))return new I(e);var t=this instanceof o;this._readableState=new F(e,this,t),this.readable=!0,e&&(typeof e.read==`function`&&(this._read=e.read),typeof e.destroy==`function`&&(this._destroy=e.destroy)),c.call(this)}Object.defineProperty(I.prototype,"destroyed",{enumerable:!1,get:function(){return this._readableState!==void 0&&this._readableState.destroyed},set:function(e){this._readableState&&(this._readableState.destroyed=e)}}),I.prototype.destroy=g.destroy,I.prototype._undestroy=g.undestroy,I.prototype._destroy=function(e,t){t(e)},I.prototype.push=function(e,t){var n=this._readableState,r;return n.objectMode?r=!0:typeof e==`string`&&(t||=n.defaultEncoding,t!==n.encoding&&(e=l.from(e,t),t=``),r=!0),se(this,e,t,!1,r)},I.prototype.unshift=function(e){return se(this,e,null,!0,!1)};function se(e,t,n,r,i){m(`readableAddChunk`,t);var a=e._readableState;if(t===null)a.reading=!1,B(e,a);else{var o;if(i||(o=ce(a,t)),o)j(e,o);else if(a.objectMode||t&&t.length>0)if(typeof t!=`string`&&!a.objectMode&&Object.getPrototypeOf(t)!==l.prototype&&(t=d(t)),r)a.endEmitted?j(e,new S):L(e,a,t,!0);else if(a.ended)j(e,new b);else if(a.destroyed)return!1;else a.reading=!1,a.decoder&&!n?(t=a.decoder.write(t),a.objectMode||t.length!==0?L(e,a,t,!1):de(e,a)):L(e,a,t,!1);else r||(a.reading=!1,de(e,a))}return!a.ended&&(a.length<a.highWaterMark||a.length===0)}function L(e,t,n,r){t.flowing&&t.length===0&&!t.sync?(t.awaitDrain=0,e.emit(`data`,n)):(t.length+=t.objectMode?1:n.length,r?t.buffer.unshift(n):t.buffer.push(n),t.needReadable&&V(e)),de(e,t)}function ce(e,t){var n;return!f(t)&&typeof t!=`string`&&t!==void 0&&!e.objectMode&&(n=new y(`chunk`,[`string`,`Buffer`,`Uint8Array`],t)),n}I.prototype.isPaused=function(){return this._readableState.flowing===!1},I.prototype.setEncoding=function(e){ee||=M().StringDecoder;var t=new ee(e);this._readableState.decoder=t,this._readableState.encoding=this._readableState.decoder.encoding;for(var n=this._readableState.buffer.head,r=``;n!==null;)r+=t.write(n.data),n=n.next;return this._readableState.buffer.clear(),r!==``&&this._readableState.buffer.push(r),this._readableState.length=r.length,this};var R=1073741824;function z(e){return e>=R?e=R:(e--,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e++),e}function le(e,t){return e<=0||t.length===0&&t.ended?0:t.objectMode?1:e===e?(e>t.highWaterMark&&(t.highWaterMark=z(e)),e<=t.length?e:t.ended?t.length:(t.needReadable=!0,0)):t.flowing&&t.length?t.buffer.head.data.length:t.length}I.prototype.read=function(e){m(`read`,e),e=parseInt(e,10);var t=this._readableState,n=e;if(e!==0&&(t.emittedReadable=!1),e===0&&t.needReadable&&((t.highWaterMark===0?t.length>0:t.length>=t.highWaterMark)||t.ended))return m(`read: emitReadable`,t.length,t.ended),t.length===0&&t.ended?U(this):V(this),null;if(e=le(e,t),e===0&&t.ended)return t.length===0&&U(this),null;var r=t.needReadable;m(`need readable`,r),(t.length===0||t.length-e<t.highWaterMark)&&(r=!0,m(`length less than watermark`,r)),t.ended||t.reading?(r=!1,m(`reading or ended`,r)):r&&(m(`do read`),t.reading=!0,t.sync=!0,t.length===0&&(t.needReadable=!0),this._read(t.highWaterMark),t.sync=!1,t.reading||(e=le(n,t)));var i=e>0?ve(e,t):null;return i===null?(t.needReadable=t.length<=t.highWaterMark,e=0):(t.length-=e,t.awaitDrain=0),t.length===0&&(t.ended||(t.needReadable=!0),n!==e&&t.ended&&U(this)),i!==null&&this.emit(`data`,i),i};function B(e,t){if(m(`onEofChunk`),!t.ended){if(t.decoder){var n=t.decoder.end();n&&n.length&&(t.buffer.push(n),t.length+=t.objectMode?1:n.length)}t.ended=!0,t.sync?V(e):(t.needReadable=!1,t.emittedReadable||(t.emittedReadable=!0,ue(e)))}}function V(e){var t=e._readableState;m(`emitReadable`,t.needReadable,t.emittedReadable),t.needReadable=!1,t.emittedReadable||(m(`emitReadable`,t.flowing),t.emittedReadable=!0,C.nextTick(ue,e))}function ue(e){var t=e._readableState;m(`emitReadable_`,t.destroyed,t.length,t.ended),!t.destroyed&&(t.length||t.ended)&&(e.emit(`readable`),t.emittedReadable=!1),t.needReadable=!t.flowing&&!t.ended&&t.length<=t.highWaterMark,_e(e)}function de(e,t){t.readingMore||(t.readingMore=!0,C.nextTick(H,e,t))}function H(e,t){for(;!t.reading&&!t.ended&&(t.length<t.highWaterMark||t.flowing&&t.length===0);){var n=t.length;if(m(`maybeReadMore read 0`),e.read(0),n===t.length)break}t.readingMore=!1}I.prototype._read=function(e){j(this,new x(`_read()`))},I.prototype.pipe=function(e,t){var n=this,r=this._readableState;switch(r.pipesCount){case 0:r.pipes=e;break;case 1:r.pipes=[r.pipes,e];break;default:r.pipes.push(e);break}r.pipesCount+=1,m(`pipe count=%d opts=%j`,r.pipesCount,t);var i=(!t||t.end!==!1)&&e!==C.stdout&&e!==C.stderr?o:g;r.endEmitted?C.nextTick(i):n.once(`end`,i),e.on(`unpipe`,a);function a(e,t){m(`onunpipe`),e===n&&t&&t.hasUnpiped===!1&&(t.hasUnpiped=!0,u())}function o(){m(`onend`),e.end()}var c=fe(n);e.on(`drain`,c);var l=!1;function u(){m(`cleanup`),e.removeListener(`close`,p),e.removeListener(`finish`,h),e.removeListener(`drain`,c),e.removeListener(`error`,f),e.removeListener(`unpipe`,a),n.removeListener(`end`,o),n.removeListener(`end`,g),n.removeListener(`data`,d),l=!0,r.awaitDrain&&(!e._writableState||e._writableState.needDrain)&&c()}n.on(`data`,d);function d(t){m(`ondata`);var i=e.write(t);m(`dest.write`,i),i===!1&&((r.pipesCount===1&&r.pipes===e||r.pipesCount>1&&be(r.pipes,e)!==-1)&&!l&&(m(`false write response, pause`,r.awaitDrain),r.awaitDrain++),n.pause())}function f(t){m(`onerror`,t),g(),e.removeListener(`error`,f),s(e,`error`)===0&&j(e,t)}P(e,`error`,f);function p(){e.removeListener(`finish`,h),g()}e.once(`close`,p);function h(){m(`onfinish`),e.removeListener(`close`,p),g()}e.once(`finish`,h);function g(){m(`unpipe`),n.unpipe(e)}return e.emit(`pipe`,n),r.flowing||(m(`pipe resume`),n.resume()),e};function fe(e){return function(){var t=e._readableState;m(`pipeOnDrain`,t.awaitDrain),t.awaitDrain&&t.awaitDrain--,t.awaitDrain===0&&s(e,`data`)&&(t.flowing=!0,_e(e))}}I.prototype.unpipe=function(e){var t=this._readableState,n={hasUnpiped:!1};if(t.pipesCount===0)return this;if(t.pipesCount===1)return e&&e!==t.pipes?this:(e||=t.pipes,t.pipes=null,t.pipesCount=0,t.flowing=!1,e&&e.emit(`unpipe`,this,n),this);if(!e){var r=t.pipes,i=t.pipesCount;t.pipes=null,t.pipesCount=0,t.flowing=!1;for(var a=0;a<i;a++)r[a].emit(`unpipe`,this,{hasUnpiped:!1});return this}var o=be(t.pipes,e);return o===-1?this:(t.pipes.splice(o,1),--t.pipesCount,t.pipesCount===1&&(t.pipes=t.pipes[0]),e.emit(`unpipe`,this,n),this)},I.prototype.on=function(e,t){var n=c.prototype.on.call(this,e,t),r=this._readableState;return e===`data`?(r.readableListening=this.listenerCount(`readable`)>0,r.flowing!==!1&&this.resume()):e===`readable`&&!r.endEmitted&&!r.readableListening&&(r.readableListening=r.needReadable=!0,r.flowing=!1,r.emittedReadable=!1,m(`on readable`,r.length,r.reading),r.length?V(this):r.reading||C.nextTick(me,this)),n},I.prototype.addListener=I.prototype.on,I.prototype.removeListener=function(e,t){var n=c.prototype.removeListener.call(this,e,t);return e===`readable`&&C.nextTick(pe,this),n},I.prototype.removeAllListeners=function(e){var t=c.prototype.removeAllListeners.apply(this,arguments);return(e===`readable`||e===void 0)&&C.nextTick(pe,this),t};function pe(e){var t=e._readableState;t.readableListening=e.listenerCount(`readable`)>0,t.resumeScheduled&&!t.paused?t.flowing=!0:e.listenerCount(`data`)>0&&e.resume()}function me(e){m(`readable nexttick read 0`),e.read(0)}I.prototype.resume=function(){var e=this._readableState;return e.flowing||(m(`resume`),e.flowing=!e.readableListening,he(this,e)),e.paused=!1,this};function he(e,t){t.resumeScheduled||(t.resumeScheduled=!0,C.nextTick(ge,e,t))}function ge(e,t){m(`resume`,t.reading),t.reading||e.read(0),t.resumeScheduled=!1,e.emit(`resume`),_e(e),t.flowing&&!t.reading&&e.read(0)}I.prototype.pause=function(){return m(`call pause flowing=%j`,this._readableState.flowing),this._readableState.flowing!==!1&&(m(`pause`),this._readableState.flowing=!1,this.emit(`pause`)),this._readableState.paused=!0,this};function _e(e){var t=e._readableState;for(m(`flow`,t.flowing);t.flowing&&e.read()!==null;);}I.prototype.wrap=function(e){var t=this,n=this._readableState,r=!1;for(var i in e.on(`end`,function(){if(m(`wrapped end`),n.decoder&&!n.ended){var e=n.decoder.end();e&&e.length&&t.push(e)}t.push(null)}),e.on(`data`,function(i){m(`wrapped data`),n.decoder&&(i=n.decoder.write(i)),!(n.objectMode&&i==null)&&(!n.objectMode&&(!i||!i.length)||t.push(i)||(r=!0,e.pause()))}),e)this[i]===void 0&&typeof e[i]==`function`&&(this[i]=function(t){return function(){return e[t].apply(e,arguments)}}(i));for(var a=0;a<ae.length;a++)e.on(ae[a],this.emit.bind(this,ae[a]));return this._read=function(t){m(`wrapped _read`,t),r&&(r=!1,e.resume())},this},typeof Symbol==`function`&&(I.prototype[Symbol.asyncIterator]=function(){return re===void 0&&(re=oe()),re(this)}),Object.defineProperty(I.prototype,"readableHighWaterMark",{enumerable:!1,get:function(){return this._readableState.highWaterMark}}),Object.defineProperty(I.prototype,"readableBuffer",{enumerable:!1,get:function(){return this._readableState&&this._readableState.buffer}}),Object.defineProperty(I.prototype,"readableFlowing",{enumerable:!1,get:function(){return this._readableState.flowing},set:function(e){this._readableState&&(this._readableState.flowing=e)}}),I._fromList=ve,Object.defineProperty(I.prototype,"readableLength",{enumerable:!1,get:function(){return this._readableState.length}});function ve(e,t){if(t.length===0)return null;var n;return t.objectMode?n=t.buffer.shift():!e||e>=t.length?(n=t.decoder?t.buffer.join(``):t.buffer.length===1?t.buffer.first():t.buffer.concat(t.length),t.buffer.clear()):n=t.buffer.consume(e,t.decoder),n}function U(e){var t=e._readableState;m(`endReadable`,t.endEmitted),t.endEmitted||(t.ended=!0,C.nextTick(ye,t,e))}function ye(e,t){if(m(`endReadableNT`,e.endEmitted,e.length),!e.endEmitted&&e.length===0&&(e.endEmitted=!0,t.readable=!1,t.emit(`end`),e.autoDestroy)){var n=t._writableState;(!n||n.autoDestroy&&n.finished)&&t.destroy()}}typeof Symbol==`function`&&(I.from=function(e,t){return A===void 0&&(A=N()),A(I,e,t)});function be(e,t){for(var n=0,r=e.length;n<r;n++)if(e[n]===t)return n;return-1}})),F=t(((e,t)=>{t.exports=u;var n=ne().codes,i=n.ERR_METHOD_NOT_IMPLEMENTED,a=n.ERR_MULTIPLE_CALLBACK,o=n.ERR_TRANSFORM_ALREADY_TRANSFORMING,s=n.ERR_TRANSFORM_WITH_LENGTH_0,c=ie();r()(u,c);function l(e,t){var n=this._transformState;n.transforming=!1;var r=n.writecb;if(r===null)return this.emit(`error`,new a);n.writechunk=null,n.writecb=null,t!=null&&this.push(t),r(e);var i=this._readableState;i.reading=!1,(i.needReadable||i.length<i.highWaterMark)&&this._read(i.highWaterMark)}function u(e){if(!(this instanceof u))return new u(e);c.call(this,e),this._transformState={afterTransform:l.bind(this),needTransform:!1,transforming:!1,writecb:null,writechunk:null,writeencoding:null},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.on(`prefinish`,d)}function d(){var e=this;typeof this._flush==`function`&&!this._readableState.destroyed?this._flush(function(t,n){f(e,t,n)}):f(this,null,null)}u.prototype.push=function(e,t){return this._transformState.needTransform=!1,c.prototype.push.call(this,e,t)},u.prototype._transform=function(e,t,n){n(new i(`_transform()`))},u.prototype._write=function(e,t,n){var r=this._transformState;if(r.writecb=n,r.writechunk=e,r.writeencoding=t,!r.transforming){var i=this._readableState;(r.needTransform||i.needReadable||i.length<i.highWaterMark)&&this._read(i.highWaterMark)}},u.prototype._read=function(e){var t=this._transformState;t.writechunk!==null&&!t.transforming?(t.transforming=!0,this._transform(t.writechunk,t.writeencoding,t.afterTransform)):t.needTransform=!0},u.prototype._destroy=function(e,t){c.prototype._destroy.call(this,e,function(e){t(e)})};function f(e,t,n){if(t)return e.emit(`error`,t);if(n!=null&&e.push(n),e._writableState.length)throw new s;if(e._transformState.transforming)throw new o;return e.push(null)}})),I=t(((e,t)=>{t.exports=i;var n=F();r()(i,n);function i(e){if(!(this instanceof i))return new i(e);n.call(this,e)}i.prototype._transform=function(e,t,n){n(null,e)}})),se=t(((e,t)=>{var n;function r(e){var t=!1;return function(){t||(t=!0,e.apply(void 0,arguments))}}var i=ne().codes,a=i.ERR_MISSING_ARGS,o=i.ERR_STREAM_DESTROYED;function s(e){if(e)throw e}function c(e){return e.setHeader&&typeof e.abort==`function`}function l(e,t,i,a){a=r(a);var s=!1;e.on(`close`,function(){s=!0}),n===void 0&&(n=ae()),n(e,{readable:t,writable:i},function(e){if(e)return a(e);s=!0,a()});var l=!1;return function(t){if(!s&&!l){if(l=!0,c(e))return e.abort();if(typeof e.destroy==`function`)return e.destroy();a(t||new o(`pipe`))}}}function u(e){e()}function d(e,t){return e.pipe(t)}function f(e){return!e.length||typeof e[e.length-1]!=`function`?s:e.pop()}function p(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];var r=f(t);if(Array.isArray(t[0])&&(t=t[0]),t.length<2)throw new a(`streams`);var i,o=t.map(function(e,n){var a=n<t.length-1;return l(e,a,n>0,function(e){i||=e,e&&o.forEach(u),!a&&(o.forEach(u),r(i))})});return t.reduce(d)}t.exports=p})),L=t(((e,t)=>{t.exports=a;var i=n().EventEmitter;r()(a,i),a.Readable=P(),a.Writable=A(),a.Duplex=ie(),a.Transform=F(),a.PassThrough=I(),a.finished=ae(),a.pipeline=se(),a.Stream=a;function a(){i.call(this)}a.prototype.pipe=function(e,t){var n=this;function r(t){e.writable&&!1===e.write(t)&&n.pause&&n.pause()}n.on(`data`,r);function a(){n.readable&&n.resume&&n.resume()}e.on(`drain`,a),!e._isStdio&&(!t||t.end!==!1)&&(n.on(`end`,s),n.on(`close`,c));var o=!1;function s(){o||(o=!0,e.end())}function c(){o||(o=!0,typeof e.destroy==`function`&&e.destroy())}function l(e){if(u(),i.listenerCount(this,`error`)===0)throw e}n.on(`error`,l),e.on(`error`,l);function u(){n.removeListener(`data`,r),e.removeListener(`drain`,a),n.removeListener(`end`,s),n.removeListener(`close`,c),n.removeListener(`error`,l),e.removeListener(`error`,l),n.removeListener(`end`,u),n.removeListener(`close`,u),e.removeListener(`close`,u)}return n.on(`end`,u),n.on(`close`,u),e.on(`close`,u),e.emit(`pipe`,n),e}}))(),ce=`useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict`,R=(e=21)=>{let t=``,n=crypto.getRandomValues(new Uint8Array(e|=0));for(;e--;)t+=ce[n[e]&63];return t},z={},le={};le.byteLength=me,le.toByteArray=ge,le.fromByteArray=U;for(var B=[],V=[],ue=typeof Uint8Array<`u`?Uint8Array:Array,de=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`,H=0,fe=de.length;H<fe;++H)B[H]=de[H],V[de.charCodeAt(H)]=H;V[45]=62,V[95]=63;function pe(e){var t=e.length;if(t%4>0)throw Error(`Invalid string. Length must be a multiple of 4`);var n=e.indexOf(`=`);n===-1&&(n=t);var r=n===t?0:4-n%4;return[n,r]}function me(e){var t=pe(e),n=t[0],r=t[1];return(n+r)*3/4-r}function he(e,t,n){return(t+n)*3/4-n}function ge(e){var t,n=pe(e),r=n[0],i=n[1],a=new ue(he(e,r,i)),o=0,s=i>0?r-4:r,c;for(c=0;c<s;c+=4)t=V[e.charCodeAt(c)]<<18|V[e.charCodeAt(c+1)]<<12|V[e.charCodeAt(c+2)]<<6|V[e.charCodeAt(c+3)],a[o++]=t>>16&255,a[o++]=t>>8&255,a[o++]=t&255;return i===2&&(t=V[e.charCodeAt(c)]<<2|V[e.charCodeAt(c+1)]>>4,a[o++]=t&255),i===1&&(t=V[e.charCodeAt(c)]<<10|V[e.charCodeAt(c+1)]<<4|V[e.charCodeAt(c+2)]>>2,a[o++]=t>>8&255,a[o++]=t&255),a}function _e(e){return B[e>>18&63]+B[e>>12&63]+B[e>>6&63]+B[e&63]}function ve(e,t,n){for(var r,i=[],a=t;a<n;a+=3)r=(e[a]<<16&16711680)+(e[a+1]<<8&65280)+(e[a+2]&255),i.push(_e(r));return i.join(``)}function U(e){for(var t,n=e.length,r=n%3,i=[],a=16383,o=0,s=n-r;o<s;o+=a)i.push(ve(e,o,o+a>s?s:o+a));return r===1?(t=e[n-1],i.push(B[t>>2]+B[t<<4&63]+`==`)):r===2&&(t=(e[n-2]<<8)+e[n-1],i.push(B[t>>10]+B[t>>4&63]+B[t<<2&63]+`=`)),i.join(``)}var ye={};ye.read=function(e,t,n,r,i){var a,o,s=i*8-r-1,c=(1<<s)-1,l=c>>1,u=-7,d=n?i-1:0,f=n?-1:1,p=e[t+d];for(d+=f,a=p&(1<<-u)-1,p>>=-u,u+=s;u>0;a=a*256+e[t+d],d+=f,u-=8);for(o=a&(1<<-u)-1,a>>=-u,u+=r;u>0;o=o*256+e[t+d],d+=f,u-=8);if(a===0)a=1-l;else if(a===c)return o?NaN:(p?-1:1)*(1/0);else o+=2**r,a-=l;return(p?-1:1)*o*2**(a-r)},ye.write=function(e,t,n,r,i,a){var o,s,c,l=a*8-i-1,u=(1<<l)-1,d=u>>1,f=i===23?2**-24-2**-77:0,p=r?0:a-1,m=r?1:-1,h=+(t<0||t===0&&1/t<0);for(t=Math.abs(t),isNaN(t)||t===1/0?(s=+!!isNaN(t),o=u):(o=Math.floor(Math.log(t)/Math.LN2),t*(c=2**-o)<1&&(o--,c*=2),o+d>=1?t+=f/c:t+=f*2**(1-d),t*c>=2&&(o++,c/=2),o+d>=u?(s=0,o=u):o+d>=1?(s=(t*c-1)*2**i,o+=d):(s=t*2**(d-1)*2**i,o=0));i>=8;e[n+p]=s&255,p+=m,s/=256,i-=8);for(o=o<<i|s,l+=i;l>0;e[n+p]=o&255,p+=m,o/=256,l-=8);e[n+p-m]|=h*128},(function(e){let t=le,n=ye,r=typeof Symbol==`function`&&typeof Symbol.for==`function`?Symbol.for(`nodejs.util.inspect.custom`):null;e.Buffer=u,e.SlowBuffer=x,e.INSPECT_MAX_BYTES=50;let i=2147483647;e.kMaxLength=i;let{Uint8Array:a,ArrayBuffer:o,SharedArrayBuffer:s}=globalThis;u.TYPED_ARRAY_SUPPORT=c(),!u.TYPED_ARRAY_SUPPORT&&typeof console<`u`&&typeof console.error==`function`&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function c(){try{let e=new a(1),t={foo:function(){return 42}};return Object.setPrototypeOf(t,a.prototype),Object.setPrototypeOf(e,t),e.foo()===42}catch{return!1}}Object.defineProperty(u.prototype,"parent",{enumerable:!0,get:function(){if(u.isBuffer(this))return this.buffer}}),Object.defineProperty(u.prototype,"offset",{enumerable:!0,get:function(){if(u.isBuffer(this))return this.byteOffset}});function l(e){if(e>i)throw RangeError(`The value "`+e+`" is invalid for option "size"`);let t=new a(e);return Object.setPrototypeOf(t,u.prototype),t}function u(e,t,n){if(typeof e==`number`){if(typeof t==`string`)throw TypeError(`The "string" argument must be of type string. Received type number`);return m(e)}return d(e,t,n)}u.poolSize=8192;function d(e,t,n){if(typeof e==`string`)return h(e,t);if(o.isView(e))return _(e);if(e==null)throw TypeError(`The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type `+typeof e);if(U(e,o)||e&&U(e.buffer,o)||s!==void 0&&(U(e,s)||e&&U(e.buffer,s)))return v(e,t,n);if(typeof e==`number`)throw TypeError(`The "value" argument must not be of type number. Received type number`);let r=e.valueOf&&e.valueOf();if(r!=null&&r!==e)return u.from(r,t,n);let i=y(e);if(i)return i;if(typeof Symbol<`u`&&Symbol.toPrimitive!=null&&typeof e[Symbol.toPrimitive]==`function`)return u.from(e[Symbol.toPrimitive](`string`),t,n);throw TypeError(`The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type `+typeof e)}u.from=function(e,t,n){return d(e,t,n)},Object.setPrototypeOf(u.prototype,a.prototype),Object.setPrototypeOf(u,a);function f(e){if(typeof e!=`number`)throw TypeError(`"size" argument must be of type number`);if(e<0)throw RangeError(`The value "`+e+`" is invalid for option "size"`)}function p(e,t,n){return f(e),e<=0||t===void 0?l(e):typeof n==`string`?l(e).fill(t,n):l(e).fill(t)}u.alloc=function(e,t,n){return p(e,t,n)};function m(e){return f(e),l(e<0?0:b(e)|0)}u.allocUnsafe=function(e){return m(e)},u.allocUnsafeSlow=function(e){return m(e)};function h(e,t){if((typeof t!=`string`||t===``)&&(t=`utf8`),!u.isEncoding(t))throw TypeError(`Unknown encoding: `+t);let n=S(e,t)|0,r=l(n),i=r.write(e,t);return i!==n&&(r=r.slice(0,i)),r}function g(e){let t=e.length<0?0:b(e.length)|0,n=l(t);for(let r=0;r<t;r+=1)n[r]=e[r]&255;return n}function _(e){if(U(e,a)){let t=new a(e);return v(t.buffer,t.byteOffset,t.byteLength)}return g(e)}function v(e,t,n){if(t<0||e.byteLength<t)throw RangeError(`"offset" is outside of buffer bounds`);if(e.byteLength<t+(n||0))throw RangeError(`"length" is outside of buffer bounds`);let r;return r=t===void 0&&n===void 0?new a(e):n===void 0?new a(e,t):new a(e,t,n),Object.setPrototypeOf(r,u.prototype),r}function y(e){if(u.isBuffer(e)){let t=b(e.length)|0,n=l(t);return n.length===0||e.copy(n,0,0,t),n}if(e.length!==void 0)return typeof e.length!=`number`||be(e.length)?l(0):g(e);if(e.type===`Buffer`&&Array.isArray(e.data))return g(e.data)}function b(e){if(e>=i)throw RangeError(`Attempt to allocate Buffer larger than maximum size: 0x`+i.toString(16)+` bytes`);return e|0}function x(e){return+e!=e&&(e=0),u.alloc(+e)}u.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==u.prototype},u.compare=function(e,t){if(U(e,a)&&(e=u.from(e,e.offset,e.byteLength)),U(t,a)&&(t=u.from(t,t.offset,t.byteLength)),!u.isBuffer(e)||!u.isBuffer(t))throw TypeError(`The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array`);if(e===t)return 0;let n=e.length,r=t.length;for(let i=0,a=Math.min(n,r);i<a;++i)if(e[i]!==t[i]){n=e[i],r=t[i];break}return n<r?-1:+(r<n)},u.isEncoding=function(e){switch(String(e).toLowerCase()){case`hex`:case`utf8`:case`utf-8`:case`ascii`:case`latin1`:case`binary`:case`base64`:case`ucs2`:case`ucs-2`:case`utf16le`:case`utf-16le`:return!0;default:return!1}},u.concat=function(e,t){if(!Array.isArray(e))throw TypeError(`"list" argument must be an Array of Buffers`);if(e.length===0)return u.alloc(0);let n;if(t===void 0)for(t=0,n=0;n<e.length;++n)t+=e[n].length;let r=u.allocUnsafe(t),i=0;for(n=0;n<e.length;++n){let t=e[n];if(U(t,a))i+t.length>r.length?(u.isBuffer(t)||(t=u.from(t)),t.copy(r,i)):a.prototype.set.call(r,t,i);else if(u.isBuffer(t))t.copy(r,i);else throw TypeError(`"list" argument must be an Array of Buffers`);i+=t.length}return r};function S(e,t){if(u.isBuffer(e))return e.length;if(o.isView(e)||U(e,o))return e.byteLength;if(typeof e!=`string`)throw TypeError(`The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type `+typeof e);let n=e.length,r=arguments.length>2&&arguments[2]===!0;if(!r&&n===0)return 0;let i=!1;for(;;)switch(t){case`ascii`:case`latin1`:case`binary`:return n;case`utf8`:case`utf-8`:return me(e).length;case`ucs2`:case`ucs-2`:case`utf16le`:case`utf-16le`:return n*2;case`hex`:return n>>>1;case`base64`:return _e(e).length;default:if(i)return r?-1:me(e).length;t=(``+t).toLowerCase(),i=!0}}u.byteLength=S;function ee(e,t,n){let r=!1;if((t===void 0||t<0)&&(t=0),t>this.length||((n===void 0||n>this.length)&&(n=this.length),n<=0)||(n>>>=0,t>>>=0,n<=t))return``;for(e||=`utf8`;;)switch(e){case`hex`:return ae(this,t,n);case`utf8`:case`utf-8`:return re(this,t,n);case`ascii`:return j(this,t,n);case`latin1`:case`binary`:return M(this,t,n);case`base64`:return k(this,t,n);case`ucs2`:case`ucs-2`:case`utf16le`:case`utf-16le`:return oe(this,t,n);default:if(r)throw TypeError(`Unknown encoding: `+e);e=(e+``).toLowerCase(),r=!0}}u.prototype._isBuffer=!0;function C(e,t,n){let r=e[t];e[t]=e[n],e[n]=r}u.prototype.swap16=function(){let e=this.length;if(e%2!=0)throw RangeError(`Buffer size must be a multiple of 16-bits`);for(let t=0;t<e;t+=2)C(this,t,t+1);return this},u.prototype.swap32=function(){let e=this.length;if(e%4!=0)throw RangeError(`Buffer size must be a multiple of 32-bits`);for(let t=0;t<e;t+=4)C(this,t,t+3),C(this,t+1,t+2);return this},u.prototype.swap64=function(){let e=this.length;if(e%8!=0)throw RangeError(`Buffer size must be a multiple of 64-bits`);for(let t=0;t<e;t+=8)C(this,t,t+7),C(this,t+1,t+6),C(this,t+2,t+5),C(this,t+3,t+4);return this},u.prototype.toString=function(){let e=this.length;return e===0?``:arguments.length===0?re(this,0,e):ee.apply(this,arguments)},u.prototype.toLocaleString=u.prototype.toString,u.prototype.equals=function(e){if(!u.isBuffer(e))throw TypeError(`Argument must be a Buffer`);return this===e||u.compare(this,e)===0},u.prototype.inspect=function(){let t=``,n=e.INSPECT_MAX_BYTES;return t=this.toString(`hex`,0,n).replace(/(.{2})/g,`$1 `).trim(),this.length>n&&(t+=` ... `),`<Buffer `+t+`>`},r&&(u.prototype[r]=u.prototype.inspect),u.prototype.compare=function(e,t,n,r,i){if(U(e,a)&&(e=u.from(e,e.offset,e.byteLength)),!u.isBuffer(e))throw TypeError(`The "target" argument must be one of type Buffer or Uint8Array. Received type `+typeof e);if(t===void 0&&(t=0),n===void 0&&(n=e?e.length:0),r===void 0&&(r=0),i===void 0&&(i=this.length),t<0||n>e.length||r<0||i>this.length)throw RangeError(`out of range index`);if(r>=i&&t>=n)return 0;if(r>=i)return-1;if(t>=n)return 1;if(t>>>=0,n>>>=0,r>>>=0,i>>>=0,this===e)return 0;let o=i-r,s=n-t,c=Math.min(o,s),l=this.slice(r,i),d=e.slice(t,n);for(let e=0;e<c;++e)if(l[e]!==d[e]){o=l[e],s=d[e];break}return o<s?-1:+(s<o)};function w(e,t,n,r,i){if(e.length===0)return-1;if(typeof n==`string`?(r=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),n=+n,be(n)&&(n=i?0:e.length-1),n<0&&(n=e.length+n),n>=e.length){if(i)return-1;n=e.length-1}else if(n<0)if(i)n=0;else return-1;if(typeof t==`string`&&(t=u.from(t,r)),u.isBuffer(t))return t.length===0?-1:T(e,t,n,r,i);if(typeof t==`number`)return t&=255,typeof a.prototype.indexOf==`function`?i?a.prototype.indexOf.call(e,t,n):a.prototype.lastIndexOf.call(e,t,n):T(e,[t],n,r,i);throw TypeError(`val must be string, number or Buffer`)}function T(e,t,n,r,i){let a=1,o=e.length,s=t.length;if(r!==void 0&&(r=String(r).toLowerCase(),r===`ucs2`||r===`ucs-2`||r===`utf16le`||r===`utf-16le`)){if(e.length<2||t.length<2)return-1;a=2,o/=2,s/=2,n/=2}function c(e,t){return a===1?e[t]:e.readUInt16BE(t*a)}let l;if(i){let r=-1;for(l=n;l<o;l++)if(c(e,l)===c(t,r===-1?0:l-r)){if(r===-1&&(r=l),l-r+1===s)return r*a}else r!==-1&&(l-=l-r),r=-1}else for(n+s>o&&(n=o-s),l=n;l>=0;l--){let n=!0;for(let r=0;r<s;r++)if(c(e,l+r)!==c(t,r)){n=!1;break}if(n)return l}return-1}u.prototype.includes=function(e,t,n){return this.indexOf(e,t,n)!==-1},u.prototype.indexOf=function(e,t,n){return w(this,e,t,n,!0)},u.prototype.lastIndexOf=function(e,t,n){return w(this,e,t,n,!1)};function E(e,t,n,r){n=Number(n)||0;let i=e.length-n;r?(r=Number(r),r>i&&(r=i)):r=i;let a=t.length;r>a/2&&(r=a/2);let o;for(o=0;o<r;++o){let r=parseInt(t.substr(o*2,2),16);if(be(r))return o;e[n+o]=r}return o}function D(e,t,n,r){return ve(me(t,e.length-n),e,n,r)}function te(e,t,n,r){return ve(he(t),e,n,r)}function O(e,t,n,r){return ve(_e(t),e,n,r)}function ne(e,t,n,r){return ve(ge(t,e.length-n),e,n,r)}u.prototype.write=function(e,t,n,r){if(t===void 0)r=`utf8`,n=this.length,t=0;else if(n===void 0&&typeof t==`string`)r=t,n=this.length,t=0;else if(isFinite(t))t>>>=0,isFinite(n)?(n>>>=0,r===void 0&&(r=`utf8`)):(r=n,n=void 0);else throw Error(`Buffer.write(string, encoding, offset[, length]) is no longer supported`);let i=this.length-t;if((n===void 0||n>i)&&(n=i),e.length>0&&(n<0||t<0)||t>this.length)throw RangeError(`Attempt to write outside buffer bounds`);r||=`utf8`;let a=!1;for(;;)switch(r){case`hex`:return E(this,e,t,n);case`utf8`:case`utf-8`:return D(this,e,t,n);case`ascii`:case`latin1`:case`binary`:return te(this,e,t,n);case`base64`:return O(this,e,t,n);case`ucs2`:case`ucs-2`:case`utf16le`:case`utf-16le`:return ne(this,e,t,n);default:if(a)throw TypeError(`Unknown encoding: `+r);r=(``+r).toLowerCase(),a=!0}},u.prototype.toJSON=function(){return{type:`Buffer`,data:Array.prototype.slice.call(this._arr||this,0)}};function k(e,n,r){return n===0&&r===e.length?t.fromByteArray(e):t.fromByteArray(e.slice(n,r))}function re(e,t,n){n=Math.min(e.length,n);let r=[],i=t;for(;i<n;){let t=e[i],a=null,o=t>239?4:t>223?3:t>191?2:1;if(i+o<=n){let n,r,s,c;switch(o){case 1:t<128&&(a=t);break;case 2:n=e[i+1],(n&192)==128&&(c=(t&31)<<6|n&63,c>127&&(a=c));break;case 3:n=e[i+1],r=e[i+2],(n&192)==128&&(r&192)==128&&(c=(t&15)<<12|(n&63)<<6|r&63,c>2047&&(c<55296||c>57343)&&(a=c));break;case 4:n=e[i+1],r=e[i+2],s=e[i+3],(n&192)==128&&(r&192)==128&&(s&192)==128&&(c=(t&15)<<18|(n&63)<<12|(r&63)<<6|s&63,c>65535&&c<1114112&&(a=c))}}a===null?(a=65533,o=1):a>65535&&(a-=65536,r.push(a>>>10&1023|55296),a=56320|a&1023),r.push(a),i+=o}return ie(r)}let A=4096;function ie(e){let t=e.length;if(t<=A)return String.fromCharCode.apply(String,e);let n=``,r=0;for(;r<t;)n+=String.fromCharCode.apply(String,e.slice(r,r+=A));return n}function j(e,t,n){let r=``;n=Math.min(e.length,n);for(let i=t;i<n;++i)r+=String.fromCharCode(e[i]&127);return r}function M(e,t,n){let r=``;n=Math.min(e.length,n);for(let i=t;i<n;++i)r+=String.fromCharCode(e[i]);return r}function ae(e,t,n){let r=e.length;(!t||t<0)&&(t=0),(!n||n<0||n>r)&&(n=r);let i=``;for(let r=t;r<n;++r)i+=xe[e[r]];return i}function oe(e,t,n){let r=e.slice(t,n),i=``;for(let e=0;e<r.length-1;e+=2)i+=String.fromCharCode(r[e]+r[e+1]*256);return i}u.prototype.slice=function(e,t){let n=this.length;e=~~e,t=t===void 0?n:~~t,e<0?(e+=n,e<0&&(e=0)):e>n&&(e=n),t<0?(t+=n,t<0&&(t=0)):t>n&&(t=n),t<e&&(t=e);let r=this.subarray(e,t);return Object.setPrototypeOf(r,u.prototype),r};function N(e,t,n){if(e%1!=0||e<0)throw RangeError(`offset is not uint`);if(e+t>n)throw RangeError(`Trying to access beyond buffer length`)}u.prototype.readUintLE=u.prototype.readUIntLE=function(e,t,n){e>>>=0,t>>>=0,n||N(e,t,this.length);let r=this[e],i=1,a=0;for(;++a<t&&(i*=256);)r+=this[e+a]*i;return r},u.prototype.readUintBE=u.prototype.readUIntBE=function(e,t,n){e>>>=0,t>>>=0,n||N(e,t,this.length);let r=this[e+--t],i=1;for(;t>0&&(i*=256);)r+=this[e+--t]*i;return r},u.prototype.readUint8=u.prototype.readUInt8=function(e,t){return e>>>=0,t||N(e,1,this.length),this[e]},u.prototype.readUint16LE=u.prototype.readUInt16LE=function(e,t){return e>>>=0,t||N(e,2,this.length),this[e]|this[e+1]<<8},u.prototype.readUint16BE=u.prototype.readUInt16BE=function(e,t){return e>>>=0,t||N(e,2,this.length),this[e]<<8|this[e+1]},u.prototype.readUint32LE=u.prototype.readUInt32LE=function(e,t){return e>>>=0,t||N(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216},u.prototype.readUint32BE=u.prototype.readUInt32BE=function(e,t){return e>>>=0,t||N(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])},u.prototype.readBigUInt64LE=W(function(e){e>>>=0,de(e,`offset`);let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&H(e,this.length-8);let r=t+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24,i=this[++e]+this[++e]*2**8+this[++e]*2**16+n*2**24;return BigInt(r)+(BigInt(i)<<BigInt(32))}),u.prototype.readBigUInt64BE=W(function(e){e>>>=0,de(e,`offset`);let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&H(e,this.length-8);let r=t*2**24+this[++e]*2**16+this[++e]*2**8+this[++e],i=this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+n;return(BigInt(r)<<BigInt(32))+BigInt(i)}),u.prototype.readIntLE=function(e,t,n){e>>>=0,t>>>=0,n||N(e,t,this.length);let r=this[e],i=1,a=0;for(;++a<t&&(i*=256);)r+=this[e+a]*i;return i*=128,r>=i&&(r-=2**(8*t)),r},u.prototype.readIntBE=function(e,t,n){e>>>=0,t>>>=0,n||N(e,t,this.length);let r=t,i=1,a=this[e+--r];for(;r>0&&(i*=256);)a+=this[e+--r]*i;return i*=128,a>=i&&(a-=2**(8*t)),a},u.prototype.readInt8=function(e,t){return e>>>=0,t||N(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]},u.prototype.readInt16LE=function(e,t){e>>>=0,t||N(e,2,this.length);let n=this[e]|this[e+1]<<8;return n&32768?n|4294901760:n},u.prototype.readInt16BE=function(e,t){e>>>=0,t||N(e,2,this.length);let n=this[e+1]|this[e]<<8;return n&32768?n|4294901760:n},u.prototype.readInt32LE=function(e,t){return e>>>=0,t||N(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},u.prototype.readInt32BE=function(e,t){return e>>>=0,t||N(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},u.prototype.readBigInt64LE=W(function(e){e>>>=0,de(e,`offset`);let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&H(e,this.length-8);let r=this[e+4]+this[e+5]*2**8+this[e+6]*2**16+(n<<24);return(BigInt(r)<<BigInt(32))+BigInt(t+this[++e]*2**8+this[++e]*2**16+this[++e]*2**24)}),u.prototype.readBigInt64BE=W(function(e){e>>>=0,de(e,`offset`);let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&H(e,this.length-8);let r=(t<<24)+this[++e]*2**16+this[++e]*2**8+this[++e];return(BigInt(r)<<BigInt(32))+BigInt(this[++e]*2**24+this[++e]*2**16+this[++e]*2**8+n)}),u.prototype.readFloatLE=function(e,t){return e>>>=0,t||N(e,4,this.length),n.read(this,e,!0,23,4)},u.prototype.readFloatBE=function(e,t){return e>>>=0,t||N(e,4,this.length),n.read(this,e,!1,23,4)},u.prototype.readDoubleLE=function(e,t){return e>>>=0,t||N(e,8,this.length),n.read(this,e,!0,52,8)},u.prototype.readDoubleBE=function(e,t){return e>>>=0,t||N(e,8,this.length),n.read(this,e,!1,52,8)};function P(e,t,n,r,i,a){if(!u.isBuffer(e))throw TypeError(`"buffer" argument must be a Buffer instance`);if(t>i||t<a)throw RangeError(`"value" argument is out of bounds`);if(n+r>e.length)throw RangeError(`Index out of range`)}u.prototype.writeUintLE=u.prototype.writeUIntLE=function(e,t,n,r){if(e=+e,t>>>=0,n>>>=0,!r){let r=2**(8*n)-1;P(this,e,t,n,r,0)}let i=1,a=0;for(this[t]=e&255;++a<n&&(i*=256);)this[t+a]=e/i&255;return t+n},u.prototype.writeUintBE=u.prototype.writeUIntBE=function(e,t,n,r){if(e=+e,t>>>=0,n>>>=0,!r){let r=2**(8*n)-1;P(this,e,t,n,r,0)}let i=n-1,a=1;for(this[t+i]=e&255;--i>=0&&(a*=256);)this[t+i]=e/a&255;return t+n},u.prototype.writeUint8=u.prototype.writeUInt8=function(e,t,n){return e=+e,t>>>=0,n||P(this,e,t,1,255,0),this[t]=e&255,t+1},u.prototype.writeUint16LE=u.prototype.writeUInt16LE=function(e,t,n){return e=+e,t>>>=0,n||P(this,e,t,2,65535,0),this[t]=e&255,this[t+1]=e>>>8,t+2},u.prototype.writeUint16BE=u.prototype.writeUInt16BE=function(e,t,n){return e=+e,t>>>=0,n||P(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=e&255,t+2},u.prototype.writeUint32LE=u.prototype.writeUInt32LE=function(e,t,n){return e=+e,t>>>=0,n||P(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=e&255,t+4},u.prototype.writeUint32BE=u.prototype.writeUInt32BE=function(e,t,n){return e=+e,t>>>=0,n||P(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e&255,t+4};function F(e,t,n,r,i){ue(t,r,i,e,n,7);let a=Number(t&BigInt(4294967295));e[n++]=a,a>>=8,e[n++]=a,a>>=8,e[n++]=a,a>>=8,e[n++]=a;let o=Number(t>>BigInt(32)&BigInt(4294967295));return e[n++]=o,o>>=8,e[n++]=o,o>>=8,e[n++]=o,o>>=8,e[n++]=o,n}function I(e,t,n,r,i){ue(t,r,i,e,n,7);let a=Number(t&BigInt(4294967295));e[n+7]=a,a>>=8,e[n+6]=a,a>>=8,e[n+5]=a,a>>=8,e[n+4]=a;let o=Number(t>>BigInt(32)&BigInt(4294967295));return e[n+3]=o,o>>=8,e[n+2]=o,o>>=8,e[n+1]=o,o>>=8,e[n]=o,n+8}u.prototype.writeBigUInt64LE=W(function(e,t=0){return F(this,e,t,BigInt(0),BigInt(`0xffffffffffffffff`))}),u.prototype.writeBigUInt64BE=W(function(e,t=0){return I(this,e,t,BigInt(0),BigInt(`0xffffffffffffffff`))}),u.prototype.writeIntLE=function(e,t,n,r){if(e=+e,t>>>=0,!r){let r=2**(8*n-1);P(this,e,t,n,r-1,-r)}let i=0,a=1,o=0;for(this[t]=e&255;++i<n&&(a*=256);)e<0&&o===0&&this[t+i-1]!==0&&(o=1),this[t+i]=(e/a>>0)-o&255;return t+n},u.prototype.writeIntBE=function(e,t,n,r){if(e=+e,t>>>=0,!r){let r=2**(8*n-1);P(this,e,t,n,r-1,-r)}let i=n-1,a=1,o=0;for(this[t+i]=e&255;--i>=0&&(a*=256);)e<0&&o===0&&this[t+i+1]!==0&&(o=1),this[t+i]=(e/a>>0)-o&255;return t+n},u.prototype.writeInt8=function(e,t,n){return e=+e,t>>>=0,n||P(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=e&255,t+1},u.prototype.writeInt16LE=function(e,t,n){return e=+e,t>>>=0,n||P(this,e,t,2,32767,-32768),this[t]=e&255,this[t+1]=e>>>8,t+2},u.prototype.writeInt16BE=function(e,t,n){return e=+e,t>>>=0,n||P(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=e&255,t+2},u.prototype.writeInt32LE=function(e,t,n){return e=+e,t>>>=0,n||P(this,e,t,4,2147483647,-2147483648),this[t]=e&255,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4},u.prototype.writeInt32BE=function(e,t,n){return e=+e,t>>>=0,n||P(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e&255,t+4},u.prototype.writeBigInt64LE=W(function(e,t=0){return F(this,e,t,-BigInt(`0x8000000000000000`),BigInt(`0x7fffffffffffffff`))}),u.prototype.writeBigInt64BE=W(function(e,t=0){return I(this,e,t,-BigInt(`0x8000000000000000`),BigInt(`0x7fffffffffffffff`))});function se(e,t,n,r,i,a){if(n+r>e.length||n<0)throw RangeError(`Index out of range`)}function L(e,t,r,i,a){return t=+t,r>>>=0,a||se(e,t,r,4),n.write(e,t,r,i,23,4),r+4}u.prototype.writeFloatLE=function(e,t,n){return L(this,e,t,!0,n)},u.prototype.writeFloatBE=function(e,t,n){return L(this,e,t,!1,n)};function ce(e,t,r,i,a){return t=+t,r>>>=0,a||se(e,t,r,8),n.write(e,t,r,i,52,8),r+8}u.prototype.writeDoubleLE=function(e,t,n){return ce(this,e,t,!0,n)},u.prototype.writeDoubleBE=function(e,t,n){return ce(this,e,t,!1,n)},u.prototype.copy=function(e,t,n,r){if(!u.isBuffer(e))throw TypeError(`argument should be a Buffer`);if(n||=0,!r&&r!==0&&(r=this.length),t>=e.length&&(t=e.length),t||=0,r>0&&r<n&&(r=n),r===n||e.length===0||this.length===0)return 0;if(t<0)throw RangeError(`targetStart out of bounds`);if(n<0||n>=this.length)throw RangeError(`Index out of range`);if(r<0)throw RangeError(`sourceEnd out of bounds`);r>this.length&&(r=this.length),e.length-t<r-n&&(r=e.length-t+n);let i=r-n;return this===e&&typeof a.prototype.copyWithin==`function`?this.copyWithin(t,n,r):a.prototype.set.call(e,this.subarray(n,r),t),i},u.prototype.fill=function(e,t,n,r){if(typeof e==`string`){if(typeof t==`string`?(r=t,t=0,n=this.length):typeof n==`string`&&(r=n,n=this.length),r!==void 0&&typeof r!=`string`)throw TypeError(`encoding must be a string`);if(typeof r==`string`&&!u.isEncoding(r))throw TypeError(`Unknown encoding: `+r);if(e.length===1){let t=e.charCodeAt(0);(r===`utf8`&&t<128||r===`latin1`)&&(e=t)}}else typeof e==`number`?e&=255:typeof e==`boolean`&&(e=Number(e));if(t<0||this.length<t||this.length<n)throw RangeError(`Out of range index`);if(n<=t)return this;t>>>=0,n=n===void 0?this.length:n>>>0,e||=0;let i;if(typeof e==`number`)for(i=t;i<n;++i)this[i]=e;else{let a=u.isBuffer(e)?e:u.from(e,r),o=a.length;if(o===0)throw TypeError(`The value "`+e+`" is invalid for argument "value"`);for(i=0;i<n-t;++i)this[i+t]=a[i%o]}return this};let R={};function z(e,t,n){R[e]=class extends n{constructor(){super(),Object.defineProperty(this,"message",{value:t.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${e}]`,this.stack,delete this.name}get code(){return e}set code(e){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:e,writable:!0})}toString(){return`${this.name} [${e}]: ${this.message}`}}}z(`ERR_BUFFER_OUT_OF_BOUNDS`,function(e){return e?`${e} is outside of buffer bounds`:`Attempt to access memory outside buffer bounds`},RangeError),z(`ERR_INVALID_ARG_TYPE`,function(e,t){return`The "${e}" argument must be of type number. Received type ${typeof t}`},TypeError),z(`ERR_OUT_OF_RANGE`,function(e,t,n){let r=`The value of "${e}" is out of range.`,i=n;return Number.isInteger(n)&&Math.abs(n)>2**32?i=B(String(n)):typeof n==`bigint`&&(i=String(n),(n>BigInt(2)**BigInt(32)||n<-(BigInt(2)**BigInt(32)))&&(i=B(i)),i+=`n`),r+=` It must be ${t}. Received ${i}`,r},RangeError);function B(e){let t=``,n=e.length,r=+(e[0]===`-`);for(;n>=r+4;n-=3)t=`_${e.slice(n-3,n)}${t}`;return`${e.slice(0,n)}${t}`}function V(e,t,n){de(t,`offset`),(e[t]===void 0||e[t+n]===void 0)&&H(t,e.length-(n+1))}function ue(e,t,n,r,i,a){if(e>n||e<t){let r=typeof t==`bigint`?`n`:``,i;throw i=a>3?t===0||t===BigInt(0)?`>= 0${r} and < 2${r} ** ${(a+1)*8}${r}`:`>= -(2${r} ** ${(a+1)*8-1}${r}) and < 2 ** ${(a+1)*8-1}${r}`:`>= ${t}${r} and <= ${n}${r}`,new R.ERR_OUT_OF_RANGE(`value`,i,e)}V(r,i,a)}function de(e,t){if(typeof e!=`number`)throw new R.ERR_INVALID_ARG_TYPE(t,`number`,e)}function H(e,t,n){throw Math.floor(e)===e?t<0?new R.ERR_BUFFER_OUT_OF_BOUNDS:new R.ERR_OUT_OF_RANGE(n||`offset`,`>= ${+!!n} and <= ${t}`,e):(de(e,n),new R.ERR_OUT_OF_RANGE(n||`offset`,`an integer`,e))}let fe=/[^+/0-9A-Za-z-_]/g;function pe(e){if(e=e.split(`=`)[0],e=e.trim().replace(fe,``),e.length<2)return``;for(;e.length%4!=0;)e+=`=`;return e}function me(e,t){t||=1/0;let n,r=e.length,i=null,a=[];for(let o=0;o<r;++o){if(n=e.charCodeAt(o),n>55295&&n<57344){if(!i){if(n>56319){(t-=3)>-1&&a.push(239,191,189);continue}else if(o+1===r){(t-=3)>-1&&a.push(239,191,189);continue}i=n;continue}if(n<56320){(t-=3)>-1&&a.push(239,191,189),i=n;continue}n=(i-55296<<10|n-56320)+65536}else i&&(t-=3)>-1&&a.push(239,191,189);if(i=null,n<128){if(--t<0)break;a.push(n)}else if(n<2048){if((t-=2)<0)break;a.push(n>>6|192,n&63|128)}else if(n<65536){if((t-=3)<0)break;a.push(n>>12|224,n>>6&63|128,n&63|128)}else if(n<1114112){if((t-=4)<0)break;a.push(n>>18|240,n>>12&63|128,n>>6&63|128,n&63|128)}else throw Error(`Invalid code point`)}return a}function he(e){let t=[];for(let n=0;n<e.length;++n)t.push(e.charCodeAt(n)&255);return t}function ge(e,t){let n,r,i,a=[];for(let o=0;o<e.length&&!((t-=2)<0);++o)n=e.charCodeAt(o),r=n>>8,i=n%256,a.push(i),a.push(r);return a}function _e(e){return t.toByteArray(pe(e))}function ve(e,t,n,r){let i;for(i=0;i<r&&!(i+n>=t.length||i>=e.length);++i)t[i+n]=e[i];return i}function U(e,t){return e instanceof t||e!=null&&e.constructor!=null&&e.constructor.name!=null&&e.constructor.name===t.name}function be(e){return e!==e}let xe=(function(){let e=`0123456789abcdef`,t=Array(256);for(let n=0;n<16;++n){let r=n*16;for(let i=0;i<16;++i)t[r+i]=e[n]+e[i]}return t})();function W(e){return typeof BigInt>`u`?Se:e}function Se(){throw Error(`BigInt not supported`)}})(z);var be=z.Buffer;z.Blob,z.BlobOptions;var xe=z.Buffer;z.File,z.FileOptions,z.INSPECT_MAX_BYTES,z.SlowBuffer,z.TranscodeEncoding,z.atob,z.btoa,z.constants,z.isAscii,z.isUtf8,z.kMaxLength,z.kStringMaxLength,z.resolveObjectURL,z.transcode;var W=class e extends Promise{#e;#t;constructor(e){super(e=>{e()}),this.#e=e}static from(t){return new e(e=>{e(t())})}static resolve(t){return new e(e=>{e(t)})}static reject(t){return new e((e,n)=>{n(t)})}then(e,t){return this.#t??=new Promise(this.#e),this.#t.then(e,t)}catch(e){return this.#t??=new Promise(this.#e),this.#t.catch(e)}finally(e){return this.#t??=new Promise(this.#e),this.#t.finally(e)}},Se=W.default??W,Ce=class{constructor(e){this.waiters=[],this.aborted=!1,this.remaining=e}async acquire(e){if(this.aborted)throw Error(`credit gate aborted`);if(e?.aborted)throw e.reason??Error(`aborted`);this.remaining>0?this.remaining--:await new Promise((t,n)=>{let r=r=>{if(e&&e.removeEventListener(`abort`,i),r){n(Error(`credit gate aborted`));return}this.remaining--,t()},i=()=>{let t=this.waiters.indexOf(r);t!==-1&&this.waiters.splice(t,1),n(e?.reason??Error(`aborted`))};if(e&&e.addEventListener(`abort`,i,{once:!0}),e?.aborted){e.removeEventListener(`abort`,i),n(e.reason??Error(`aborted`));return}this.waiters.push(r)})}replenish(e){for(this.remaining+=e;this.waiters.length>0&&this.remaining>0;)this.waiters.shift()(!1)}abort(){for(this.aborted=!0;this.waiters.length>0;)this.waiters.shift()(!0)}},we=new TextEncoder;function Te(e){let t=e.reduce((e,t)=>e+t.byteLength,0),n=new Uint8Array(t),r=0;for(let t of e)n.set(t,r),r+=t.byteLength;return n}function Ee(e){let t;if(e instanceof xe)t=new Uint8Array(e.buffer,e.byteOffset,e.byteLength);else if(e instanceof Uint8Array)t=e;else if(typeof e==`string`)t=we.encode(e);else throw Error(`invalid chunk type: expected Buffer, Uint8Array, or string`);return t}var De=class extends L.Readable{constructor(e){let t=e?.read;super({...e,read:()=>{}}),this._chunks=[],this._collecting=!0,this._onRead=t,this.buffer=new Promise((e,t)=>{this._resolve=e,this._reject=t}),this.buffer.catch(()=>{}),this.on(`error`,e=>{this._collecting&&(this._collecting=!1,this._reject(e))})}push(e,t){return this._collecting&&(e===null?(this._collecting=!1,this._resolve(Te(this._chunks))):e!==void 0&&this._chunks.push(Ee(e))),super.push(e,t)}read(e){return this._onRead?.(e??0),super.read(e)}get collecting(){return this._collecting}stopCollecting(){this._collecting&&(this._reject(Error(`collecting stopped`)),this._collecting=!1,this._chunks.length=0)}};async function Oe(e,t,n,r,i){if(e.byteLength===0)await n(void 0,void 0,!0);else for(let a=0;a<e.byteLength;a+=t){if(i?.aborted)throw i.reason??Error(`aborted`);let o=Math.min(e.byteLength-a,t),s=e.subarray(a,a+o),c=a+o>=e.byteLength;r&&await r.acquire(i),await n(s,void 0,c)}}async function ke(e,t,n,r,i){let a;for await(let o of e){if(i?.aborted)throw i.reason??Error(`aborted`);let e=Ee(o);if(e.byteLength!==0)for(let o=0;o<e.byteLength;o+=t){if(i?.aborted)throw i.reason??Error(`aborted`);let s=Math.min(e.byteLength-o,t),c=e.subarray(o,o+s);a!==void 0&&(r&&await r.acquire(i),await n(a,void 0,!1)),a=c}}if(i?.aborted)throw i.reason??Error(`aborted`);a===void 0?await n(void 0,void 0,!0):(r&&await r.acquire(i),await n(a,void 0,!0))}function Ae(e,t,n,r){if(!(typeof e==`object`&&e))throw Error(`invalid object`);let i,a=e[t],o=e[n];Object.defineProperty(e,t,{get:()=>{if(i===`f2`)throw Error(`field "${t}" is mutually exclusive with field "${n}" and "${n}" was already consumed`);return i||r?.(t),i=`f1`,a},enumerable:!0,configurable:!0}),Object.defineProperty(e,n,{get:()=>{if(i===`f1`)throw Error(`field "${n}" is mutually exclusive with field "${t}" and "${t}" was already consumed`);return i||r?.(n),i=`f2`,o},enumerable:!0,configurable:!0})}var je=class e{constructor(){this.resources=[],this.pending=null}roll(...e){let t,n;if(e.length===1)t=void 0,n=e[0];else if(e.length===2)t=e[0],n=e[1];else throw Error(`invalid number of arguments`);this.resources.push({resource:t,cleanup:n})}sub(){let t=new e;return this.roll(t,e=>e.unroll()),t}unroll(e=!0){if(this.pending!==null)return e?this.pending.catch(()=>{}):this.pending;let t=this.resources;this.resources=[];let n=[],r;for(;t.length>0;){let e=t.pop(),i=e.resource,a=e.cleanup;if(r)r=r.then(()=>a(i)).catch(e=>{n.push(e)});else try{let e=a(i);e instanceof Promise&&(r=e.catch(e=>{n.push(e)}))}catch(e){n.push(e)}}if(r)return this.pending=r.then(()=>{if(n.length===1)throw n[0];if(n.length>1)throw AggregateError(n,`multiple cleanup failures`)}).finally(()=>{this.pending=null}),e?this.pending.catch(()=>{}):this.pending;if(!e&&n.length===1)throw n[0];if(!e&&n.length>1)throw AggregateError(n,`multiple cleanup failures`)}};function G(e,t,n=!1){if(e instanceof Error&&t===void 0&&n===!1)return e;let r=e instanceof Error?e.message:String(e);if(t&&(r=`${t}: ${r}`),n&&e instanceof Error&&(r=`${r}\n${e.stack}`),e instanceof Error){let t=Error(r,{cause:e});return t.stack=e.stack,t}else return Error(r)}function Me(e,t,n){if(!t)return e?Promise.resolve():void 0;let r;try{r=t()}catch(t){if(e)return Promise.reject(G(t,n));throw G(t,n)}if(!e&&r instanceof Promise)throw Error(`onfinally callback returned Promise in non-async context`);return e&&!(r instanceof Promise)&&(r=Promise.resolve(r)),e&&r instanceof Promise?r.catch(e=>{throw G(e,n)}):r}function Ne(e,t){if(!t)return e?Promise.resolve():void 0;let n=t.unroll();if(!e&&n instanceof Promise)throw Error(`spool unroll returned Promise in non-async context`);return e&&!(n instanceof Promise)&&(n=Promise.resolve(n)),n}function Pe(e,t,n,r,i){if(e)return(async()=>{let e;try{await Me(!0,r,i)}catch(t){e=G(t,i)}if((t||e!==void 0)&&(await Ne(!0,n),!t&&e!==void 0))throw e})();{let e;try{Me(!1,r,i)}catch(t){e=G(t,i)}if((t||e!==void 0)&&(Ne(!1,n),!t&&e!==void 0))throw e}}function Fe(...e){let t,n,r,i,a,o;if(e.length===1&&typeof e[0]==`object`&&e[0]!==null?(t=e[0].description,n=e[0].spool,r=e[0].action,i=e[0].oncatch,a=e[0].onfinally,o=e[0].oncleanup):typeof e[0]==`string`?(t=e[0],e[1]instanceof je||e[1]===void 0&&typeof e[2]==`function`?(n=e[1],r=e[2],i=e[3],a=e[4],o=e[5]):(r=e[1],i=e[2],a=e[3],o=e[4])):e[0]instanceof je||e[0]===void 0&&typeof e[1]==`function`?(n=e[0],r=e[1],i=e[2],a=e[3],o=e[4]):(r=e[0],i=e[1],a=e[2],o=e[3]),o&&!n)throw Error(`oncleanup requires a spool`);let s;try{s=r()}catch(e){let r=G(e,t);if(i){try{s=i(r)}catch(e){throw r=G(e,t),Pe(!1,!0,n,a,t),r}return n&&o&&n.roll(s,o),Pe(!1,!1,n,a,t),s}throw Pe(!1,!0,n,a,t),r}return s instanceof Promise?s.then(async e=>(n&&o&&n.roll(e,o),await Pe(!0,!1,n,a,t),e),async e=>{let r=G(e,t);if(i){let e;try{e=await i(r)}catch(e){throw r=G(e,t),await Pe(!0,!0,n,a,t),r}return n&&o&&n.roll(e,o),await Pe(!0,!1,n,a,t),e}throw await Pe(!0,!0,n,a,t),r}):(n&&o&&n.roll(s,o),Pe(!1,!1,n,a,t),s)}var Ie=new TextEncoder,Le=new TextDecoder;function Re(...e){let t=e.reduce((e,{length:t})=>e+t,0),n=new Uint8Array(t),r=0;for(let t of e)n.set(t,r),r+=t.length;return n}function ze(e){let t=new Uint8Array(e.length);for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);if(r>127)throw TypeError(`non-ASCII string encountered in encode()`);t[n]=r}return t}function Be(e){if(Uint8Array.prototype.toBase64)return e.toBase64();let t=32768,n=[];for(let r=0;r<e.length;r+=t)n.push(String.fromCharCode.apply(null,e.subarray(r,r+t)));return btoa(n.join(``))}function Ve(e){if(Uint8Array.fromBase64)return Uint8Array.fromBase64(e);let t=atob(e),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}function He(e){if(Uint8Array.fromBase64)return Uint8Array.fromBase64(typeof e==`string`?e:Le.decode(e),{alphabet:`base64url`});let t=e;t instanceof Uint8Array&&(t=Le.decode(t)),t=t.replace(/-/g,`+`).replace(/_/g,`/`);try{return Ve(t)}catch{throw TypeError(`The input to be decoded is not correctly encoded.`)}}function Ue(e){let t=e;return typeof t==`string`&&(t=Ie.encode(t)),Uint8Array.prototype.toBase64?t.toBase64({alphabet:`base64url`,omitPadding:!0}):Be(t).replace(/=/g,``).replace(/\+/g,`-`).replace(/\//g,`_`)}var We=class extends Error{static code=`ERR_JOSE_GENERIC`;code=`ERR_JOSE_GENERIC`;constructor(e,t){super(e,t),this.name=this.constructor.name,Error.captureStackTrace?.(this,this.constructor)}},Ge=class extends We{static code=`ERR_JWT_CLAIM_VALIDATION_FAILED`;code=`ERR_JWT_CLAIM_VALIDATION_FAILED`;claim;reason;payload;constructor(e,t,n=`unspecified`,r=`unspecified`){super(e,{cause:{claim:n,reason:r,payload:t}}),this.claim=n,this.reason=r,this.payload=t}},Ke=class extends We{static code=`ERR_JWT_EXPIRED`;code=`ERR_JWT_EXPIRED`;claim;reason;payload;constructor(e,t,n=`unspecified`,r=`unspecified`){super(e,{cause:{claim:n,reason:r,payload:t}}),this.claim=n,this.reason=r,this.payload=t}},qe=class extends We{static code=`ERR_JOSE_ALG_NOT_ALLOWED`;code=`ERR_JOSE_ALG_NOT_ALLOWED`},Je=class extends We{static code=`ERR_JOSE_NOT_SUPPORTED`;code=`ERR_JOSE_NOT_SUPPORTED`},K=class extends We{static code=`ERR_JWS_INVALID`;code=`ERR_JWS_INVALID`},Ye=class extends We{static code=`ERR_JWT_INVALID`;code=`ERR_JWT_INVALID`},Xe=class extends We{static code=`ERR_JWS_SIGNATURE_VERIFICATION_FAILED`;code=`ERR_JWS_SIGNATURE_VERIFICATION_FAILED`;constructor(e=`signature verification failed`,t){super(e,t)}},Ze=(e,t=`algorithm.name`)=>TypeError(`CryptoKey does not support this operation, its ${t} must be ${e}`),Qe=(e,t)=>e.name===t;function $e(e){return parseInt(e.name.slice(4),10)}function et(e,t){if($e(e.hash)!==t)throw Ze(`SHA-${t}`,`algorithm.hash`)}function tt(e){switch(e){case`ES256`:return`P-256`;case`ES384`:return`P-384`;case`ES512`:return`P-521`;default:throw Error(`unreachable`)}}function nt(e,t){if(t&&!e.usages.includes(t))throw TypeError(`CryptoKey does not support this operation, its usages must include ${t}.`)}function rt(e,t,n){switch(t){case`HS256`:case`HS384`:case`HS512`:if(!Qe(e.algorithm,`HMAC`))throw Ze(`HMAC`);et(e.algorithm,parseInt(t.slice(2),10));break;case`RS256`:case`RS384`:case`RS512`:if(!Qe(e.algorithm,`RSASSA-PKCS1-v1_5`))throw Ze(`RSASSA-PKCS1-v1_5`);et(e.algorithm,parseInt(t.slice(2),10));break;case`PS256`:case`PS384`:case`PS512`:if(!Qe(e.algorithm,`RSA-PSS`))throw Ze(`RSA-PSS`);et(e.algorithm,parseInt(t.slice(2),10));break;case`Ed25519`:case`EdDSA`:if(!Qe(e.algorithm,`Ed25519`))throw Ze(`Ed25519`);break;case`ML-DSA-44`:case`ML-DSA-65`:case`ML-DSA-87`:if(!Qe(e.algorithm,t))throw Ze(t);break;case`ES256`:case`ES384`:case`ES512`:{if(!Qe(e.algorithm,`ECDSA`))throw Ze(`ECDSA`);let n=tt(t);if(e.algorithm.namedCurve!==n)throw Ze(n,`algorithm.namedCurve`);break}default:throw TypeError(`CryptoKey does not support this operation`)}nt(e,n)}function it(e,t,...n){if(n=n.filter(Boolean),n.length>2){let t=n.pop();e+=`one of type ${n.join(`, `)}, or ${t}.`}else n.length===2?e+=`one of type ${n[0]} or ${n[1]}.`:e+=`of type ${n[0]}.`;return t==null?e+=` Received ${t}`:typeof t==`function`&&t.name?e+=` Received function ${t.name}`:typeof t==`object`&&t&&t.constructor?.name&&(e+=` Received an instance of ${t.constructor.name}`),e}var at=(e,...t)=>it(`Key must be `,e,...t),ot=(e,t,...n)=>it(`Key for the ${e} algorithm must be `,t,...n);function st(e,t){if(e.startsWith(`RS`)||e.startsWith(`PS`)){let{modulusLength:n}=t.algorithm;if(typeof n!=`number`||n<2048)throw TypeError(`${e} requires key modulusLength to be 2048 bits or larger`)}}function ct(e,t){let n=`SHA-${e.slice(-3)}`;switch(e){case`HS256`:case`HS384`:case`HS512`:return{hash:n,name:`HMAC`};case`PS256`:case`PS384`:case`PS512`:return{hash:n,name:`RSA-PSS`,saltLength:parseInt(e.slice(-3),10)>>3};case`RS256`:case`RS384`:case`RS512`:return{hash:n,name:`RSASSA-PKCS1-v1_5`};case`ES256`:case`ES384`:case`ES512`:return{hash:n,name:`ECDSA`,namedCurve:t.namedCurve};case`Ed25519`:case`EdDSA`:return{name:`Ed25519`};case`ML-DSA-44`:case`ML-DSA-65`:case`ML-DSA-87`:return{name:e};default:throw new Je(`alg ${e} is not supported either by JOSE or your javascript runtime`)}}async function lt(e,t,n){if(t instanceof Uint8Array){if(!e.startsWith(`HS`))throw TypeError(at(t,`CryptoKey`,`KeyObject`,`JSON Web Key`));return crypto.subtle.importKey(`raw`,t,{hash:`SHA-${e.slice(-3)}`,name:`HMAC`},!1,[n])}return rt(t,e,n),t}async function ut(e,t,n){let r=await lt(e,t,`sign`);st(e,r);let i=await crypto.subtle.sign(ct(e,r.algorithm),r,n);return new Uint8Array(i)}async function dt(e,t,n,r){let i=await lt(e,t,`verify`);st(e,i);let a=ct(e,i.algorithm);try{return await crypto.subtle.verify(a,i,n,r)}catch{return!1}}var ft=e=>typeof e==`object`&&!!e;function pt(e){if(!ft(e)||Object.prototype.toString.call(e)!==`[object Object]`)return!1;if(Object.getPrototypeOf(e)===null)return!0;let t=e;for(;Object.getPrototypeOf(t)!==null;)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(e)===t}function mt(...e){let t=e.filter(Boolean);if(t.length===0||t.length===1)return!0;let n;for(let e of t){let t=Object.keys(e);if(!n||n.size===0){n=new Set(t);continue}for(let e of t){if(n.has(e))return!1;n.add(e)}}return!0}var ht=e=>pt(e)&&typeof e.kty==`string`,gt=e=>e.kty!==`oct`&&(e.kty===`AKP`&&typeof e.priv==`string`||typeof e.d==`string`),_t=e=>e.kty!==`oct`&&e.d===void 0&&e.priv===void 0,vt=e=>e.kty===`oct`&&typeof e.k==`string`,yt=e=>{if(e?.[Symbol.toStringTag]===`CryptoKey`)return!0;try{return e instanceof CryptoKey}catch{return!1}},bt=e=>e?.[Symbol.toStringTag]===`KeyObject`,xt=e=>yt(e)||bt(e),St=e=>e?.[Symbol.toStringTag],Ct=(e,t,n)=>{if(t.use!==void 0){let e;switch(n){case`sign`:case`verify`:e=`sig`;break;case`encrypt`:case`decrypt`:e=`enc`;break}if(t.use!==e)throw TypeError(`Invalid key for this operation, its "use" must be "${e}" when present`)}if(t.alg!==void 0&&t.alg!==e)throw TypeError(`Invalid key for this operation, its "alg" must be "${e}" when present`);if(Array.isArray(t.key_ops)){let r;switch(!0){case n===`sign`||n===`verify`:case e===`dir`:case e.includes(`CBC-HS`):r=n;break;case e.startsWith(`PBES2`):r=`deriveBits`;break;case/^A\d{3}(?:GCM)?(?:KW)?$/.test(e):r=!e.includes(`GCM`)&&e.endsWith(`KW`)?n===`encrypt`?`wrapKey`:`unwrapKey`:n;break;case n===`encrypt`&&e.startsWith(`RSA`):r=`wrapKey`;break;case n===`decrypt`:r=e.startsWith(`RSA`)?`unwrapKey`:`deriveBits`;break}if(r&&t.key_ops?.includes?.(r)===!1)throw TypeError(`Invalid key for this operation, its "key_ops" must include "${r}" when present`)}return!0},wt=(e,t,n)=>{if(!(t instanceof Uint8Array)){if(ht(t)){if(vt(t)&&Ct(e,t,n))return;throw TypeError(`JSON Web Key for symmetric algorithms must have JWK "kty" (Key Type) equal to "oct" and the JWK "k" (Key Value) present`)}if(!xt(t))throw TypeError(ot(e,t,`CryptoKey`,`KeyObject`,`JSON Web Key`,`Uint8Array`));if(t.type!==`secret`)throw TypeError(`${St(t)} instances for symmetric algorithms must be of type "secret"`)}},Tt=(e,t,n)=>{if(ht(t))switch(n){case`decrypt`:case`sign`:if(gt(t)&&Ct(e,t,n))return;throw TypeError(`JSON Web Key for this operation must be a private JWK`);case`encrypt`:case`verify`:if(_t(t)&&Ct(e,t,n))return;throw TypeError(`JSON Web Key for this operation must be a public JWK`)}if(!xt(t))throw TypeError(ot(e,t,`CryptoKey`,`KeyObject`,`JSON Web Key`));if(t.type===`secret`)throw TypeError(`${St(t)} instances for asymmetric algorithms must not be of type "secret"`);if(t.type===`public`)switch(n){case`sign`:throw TypeError(`${St(t)} instances for asymmetric algorithm signing must be of type "private"`);case`decrypt`:throw TypeError(`${St(t)} instances for asymmetric algorithm decryption must be of type "private"`)}if(t.type===`private`)switch(n){case`verify`:throw TypeError(`${St(t)} instances for asymmetric algorithm verifying must be of type "public"`);case`encrypt`:throw TypeError(`${St(t)} instances for asymmetric algorithm encryption must be of type "public"`)}};function Et(e,t,n){switch(e.substring(0,2)){case`A1`:case`A2`:case`di`:case`HS`:case`PB`:wt(e,t,n);break;default:Tt(e,t,n)}}function Dt(e,t,n,r,i){if(i.crit!==void 0&&r?.crit===void 0)throw new e(`"crit" (Critical) Header Parameter MUST be integrity protected`);if(!r||r.crit===void 0)return new Set;if(!Array.isArray(r.crit)||r.crit.length===0||r.crit.some(e=>typeof e!=`string`||e.length===0))throw new e(`"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present`);let a;a=n===void 0?t:new Map([...Object.entries(n),...t.entries()]);for(let t of r.crit){if(!a.has(t))throw new Je(`Extension Header Parameter "${t}" is not recognized`);if(i[t]===void 0)throw new e(`Extension Header Parameter "${t}" is missing`);if(a.get(t)&&r[t]===void 0)throw new e(`Extension Header Parameter "${t}" MUST be integrity protected`)}return new Set(r.crit)}var Ot=`Invalid or unsupported JWK "alg" (Algorithm) Parameter value`;function kt(e){let t,n;switch(e.kty){case`AKP`:switch(e.alg){case`ML-DSA-44`:case`ML-DSA-65`:case`ML-DSA-87`:t={name:e.alg},n=e.priv?[`sign`]:[`verify`];break;default:throw new Je(Ot)}break;case`RSA`:switch(e.alg){case`PS256`:case`PS384`:case`PS512`:t={name:`RSA-PSS`,hash:`SHA-${e.alg.slice(-3)}`},n=e.d?[`sign`]:[`verify`];break;case`RS256`:case`RS384`:case`RS512`:t={name:`RSASSA-PKCS1-v1_5`,hash:`SHA-${e.alg.slice(-3)}`},n=e.d?[`sign`]:[`verify`];break;case`RSA-OAEP`:case`RSA-OAEP-256`:case`RSA-OAEP-384`:case`RSA-OAEP-512`:t={name:`RSA-OAEP`,hash:`SHA-${parseInt(e.alg.slice(-3),10)||1}`},n=e.d?[`decrypt`,`unwrapKey`]:[`encrypt`,`wrapKey`];break;default:throw new Je(Ot)}break;case`EC`:switch(e.alg){case`ES256`:case`ES384`:case`ES512`:t={name:`ECDSA`,namedCurve:{ES256:`P-256`,ES384:`P-384`,ES512:`P-521`}[e.alg]},n=e.d?[`sign`]:[`verify`];break;case`ECDH-ES`:case`ECDH-ES+A128KW`:case`ECDH-ES+A192KW`:case`ECDH-ES+A256KW`:t={name:`ECDH`,namedCurve:e.crv},n=e.d?[`deriveBits`]:[];break;default:throw new Je(Ot)}break;case`OKP`:switch(e.alg){case`Ed25519`:case`EdDSA`:t={name:`Ed25519`},n=e.d?[`sign`]:[`verify`];break;case`ECDH-ES`:case`ECDH-ES+A128KW`:case`ECDH-ES+A192KW`:case`ECDH-ES+A256KW`:t={name:e.crv},n=e.d?[`deriveBits`]:[];break;default:throw new Je(Ot)}break;default:throw new Je(`Invalid or unsupported JWK "kty" (Key Type) Parameter value`)}return{algorithm:t,keyUsages:n}}async function At(e){if(!e.alg)throw TypeError(`"alg" argument is required when "jwk.alg" is not present`);let{algorithm:t,keyUsages:n}=kt(e),r={...e};return r.kty!==`AKP`&&delete r.alg,delete r.use,crypto.subtle.importKey(`jwk`,r,t,e.ext??!(e.d||e.priv),e.key_ops??n)}var jt=`given KeyObject instance cannot be used for this algorithm`,Mt,Nt=async(e,t,n,r=!1)=>{Mt||=new WeakMap;let i=Mt.get(e);if(i?.[n])return i[n];let a=await At({...t,alg:n});return r&&Object.freeze(e),i?i[n]=a:Mt.set(e,{[n]:a}),a},Pt=(e,t)=>{Mt||=new WeakMap;let n=Mt.get(e);if(n?.[t])return n[t];let r=e.type===`public`,i=!!r,a;if(e.asymmetricKeyType===`x25519`){switch(t){case`ECDH-ES`:case`ECDH-ES+A128KW`:case`ECDH-ES+A192KW`:case`ECDH-ES+A256KW`:break;default:throw TypeError(jt)}a=e.toCryptoKey(e.asymmetricKeyType,i,r?[]:[`deriveBits`])}if(e.asymmetricKeyType===`ed25519`){if(t!==`EdDSA`&&t!==`Ed25519`)throw TypeError(jt);a=e.toCryptoKey(e.asymmetricKeyType,i,[r?`verify`:`sign`])}switch(e.asymmetricKeyType){case`ml-dsa-44`:case`ml-dsa-65`:case`ml-dsa-87`:if(t!==e.asymmetricKeyType.toUpperCase())throw TypeError(jt);a=e.toCryptoKey(e.asymmetricKeyType,i,[r?`verify`:`sign`])}if(e.asymmetricKeyType===`rsa`){let n;switch(t){case`RSA-OAEP`:n=`SHA-1`;break;case`RS256`:case`PS256`:case`RSA-OAEP-256`:n=`SHA-256`;break;case`RS384`:case`PS384`:case`RSA-OAEP-384`:n=`SHA-384`;break;case`RS512`:case`PS512`:case`RSA-OAEP-512`:n=`SHA-512`;break;default:throw TypeError(jt)}if(t.startsWith(`RSA-OAEP`))return e.toCryptoKey({name:`RSA-OAEP`,hash:n},i,r?[`encrypt`]:[`decrypt`]);a=e.toCryptoKey({name:t.startsWith(`PS`)?`RSA-PSS`:`RSASSA-PKCS1-v1_5`,hash:n},i,[r?`verify`:`sign`])}if(e.asymmetricKeyType===`ec`){let n=new Map([[`prime256v1`,`P-256`],[`secp384r1`,`P-384`],[`secp521r1`,`P-521`]]).get(e.asymmetricKeyDetails?.namedCurve);if(!n)throw TypeError(jt);let o={ES256:`P-256`,ES384:`P-384`,ES512:`P-521`};o[t]&&n===o[t]&&(a=e.toCryptoKey({name:`ECDSA`,namedCurve:n},i,[r?`verify`:`sign`])),t.startsWith(`ECDH-ES`)&&(a=e.toCryptoKey({name:`ECDH`,namedCurve:n},i,r?[]:[`deriveBits`]))}if(!a)throw TypeError(jt);return n?n[t]=a:Mt.set(e,{[t]:a}),a};async function Ft(e,t){if(e instanceof Uint8Array||yt(e))return e;if(bt(e)){if(e.type===`secret`)return e.export();if(`toCryptoKey`in e&&typeof e.toCryptoKey==`function`)try{return Pt(e,t)}catch(e){if(e instanceof TypeError)throw e}return Nt(e,e.export({format:`jwk`}),t)}if(ht(e))return e.k?He(e.k):Nt(e,e,t,!0);throw Error(`unreachable`)}function It(e,t){if(e)throw TypeError(`${t} can only be called once`)}function Lt(e,t,n){try{return He(e)}catch{throw new n(`Failed to base64url decode the ${t}`)}}var Rt=class{#e;#t;#n;constructor(e){if(!(e instanceof Uint8Array))throw TypeError(`payload must be an instance of Uint8Array`);this.#e=e}setProtectedHeader(e){return It(this.#t,`setProtectedHeader`),this.#t=e,this}setUnprotectedHeader(e){return It(this.#n,`setUnprotectedHeader`),this.#n=e,this}async sign(e,t){if(!this.#t&&!this.#n)throw new K(`either setProtectedHeader or setUnprotectedHeader must be called before #sign()`);if(!mt(this.#t,this.#n))throw new K(`JWS Protected and JWS Unprotected Header Parameter names must be disjoint`);let n={...this.#t,...this.#n},r=Dt(K,new Map([[`b64`,!0]]),t?.crit,this.#t,n),i=!0;if(r.has(`b64`)&&(i=this.#t.b64,typeof i!=`boolean`))throw new K(`The "b64" (base64url-encode payload) Header Parameter must be a boolean`);let{alg:a}=n;if(typeof a!=`string`||!a)throw new K(`JWS "alg" (Algorithm) Header Parameter missing or invalid`);Et(a,e,`sign`);let o,s;i?(o=Ue(this.#e),s=ze(o)):(s=this.#e,o=``);let c,l;this.#t?(c=Ue(JSON.stringify(this.#t)),l=ze(c)):(c=``,l=new Uint8Array);let u=Re(l,ze(`.`),s),d={signature:Ue(await ut(a,await Ft(e,a),u)),payload:o};return this.#n&&(d.header=this.#n),this.#t&&(d.protected=c),d}},zt=class{#e;constructor(e){this.#e=new Rt(e)}setProtectedHeader(e){return this.#e.setProtectedHeader(e),this}async sign(e,t){let n=await this.#e.sign(e,t);if(n.payload===void 0)throw TypeError(`use the flattened module for creating JWS with b64: false`);return`${n.protected}.${n.payload}.${n.signature}`}},Bt=e=>Math.floor(e.getTime()/1e3),Vt=60,Ht=Vt*60,Ut=Ht*24,Wt=Ut*7,Gt=Ut*365.25,Kt=/^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i;function qt(e){let t=Kt.exec(e);if(!t||t[4]&&t[1])throw TypeError(`Invalid time period format`);let n=parseFloat(t[2]),r=t[3].toLowerCase(),i;switch(r){case`sec`:case`secs`:case`second`:case`seconds`:case`s`:i=Math.round(n);break;case`minute`:case`minutes`:case`min`:case`mins`:case`m`:i=Math.round(n*Vt);break;case`hour`:case`hours`:case`hr`:case`hrs`:case`h`:i=Math.round(n*Ht);break;case`day`:case`days`:case`d`:i=Math.round(n*Ut);break;case`week`:case`weeks`:case`w`:i=Math.round(n*Wt);break;default:i=Math.round(n*Gt);break}return t[1]===`-`||t[4]===`ago`?-i:i}function Jt(e,t){if(!Number.isFinite(t))throw TypeError(`Invalid ${e} input`);return t}var Yt=e=>e.includes(`/`)?e.toLowerCase():`application/${e.toLowerCase()}`,Xt=(e,t)=>typeof e==`string`?t.includes(e):Array.isArray(e)?t.some(Set.prototype.has.bind(new Set(e))):!1;function Zt(e,t,n={}){let r;try{r=JSON.parse(Le.decode(t))}catch{}if(!pt(r))throw new Ye(`JWT Claims Set must be a top-level JSON object`);let{typ:i}=n;if(i&&(typeof e.typ!=`string`||Yt(e.typ)!==Yt(i)))throw new Ge(`unexpected "typ" JWT header value`,r,`typ`,`check_failed`);let{requiredClaims:a=[],issuer:o,subject:s,audience:c,maxTokenAge:l}=n,u=[...a];l!==void 0&&u.push(`iat`),c!==void 0&&u.push(`aud`),s!==void 0&&u.push(`sub`),o!==void 0&&u.push(`iss`);for(let e of new Set(u.reverse()))if(!(e in r))throw new Ge(`missing required "${e}" claim`,r,e,`missing`);if(o&&!(Array.isArray(o)?o:[o]).includes(r.iss))throw new Ge(`unexpected "iss" claim value`,r,`iss`,`check_failed`);if(s&&r.sub!==s)throw new Ge(`unexpected "sub" claim value`,r,`sub`,`check_failed`);if(c&&!Xt(r.aud,typeof c==`string`?[c]:c))throw new Ge(`unexpected "aud" claim value`,r,`aud`,`check_failed`);let d;switch(typeof n.clockTolerance){case`string`:d=qt(n.clockTolerance);break;case`number`:d=n.clockTolerance;break;case`undefined`:d=0;break;default:throw TypeError(`Invalid clockTolerance option type`)}let{currentDate:f}=n,p=Bt(f||new Date);if((r.iat!==void 0||l)&&typeof r.iat!=`number`)throw new Ge(`"iat" claim must be a number`,r,`iat`,`invalid`);if(r.nbf!==void 0){if(typeof r.nbf!=`number`)throw new Ge(`"nbf" claim must be a number`,r,`nbf`,`invalid`);if(r.nbf>p+d)throw new Ge(`"nbf" claim timestamp check failed`,r,`nbf`,`check_failed`)}if(r.exp!==void 0){if(typeof r.exp!=`number`)throw new Ge(`"exp" claim must be a number`,r,`exp`,`invalid`);if(r.exp<=p-d)throw new Ke(`"exp" claim timestamp check failed`,r,`exp`,`check_failed`)}if(l){let e=p-r.iat,t=typeof l==`number`?l:qt(l);if(e-d>t)throw new Ke(`"iat" claim timestamp check failed (too far in the past)`,r,`iat`,`check_failed`);if(e<0-d)throw new Ge(`"iat" claim timestamp check failed (it should be in the past)`,r,`iat`,`check_failed`)}return r}var Qt=class{#e;constructor(e){if(!pt(e))throw TypeError(`JWT Claims Set MUST be an object`);this.#e=structuredClone(e)}data(){return Ie.encode(JSON.stringify(this.#e))}get iss(){return this.#e.iss}set iss(e){this.#e.iss=e}get sub(){return this.#e.sub}set sub(e){this.#e.sub=e}get aud(){return this.#e.aud}set aud(e){this.#e.aud=e}set jti(e){this.#e.jti=e}set nbf(e){typeof e==`number`?this.#e.nbf=Jt(`setNotBefore`,e):e instanceof Date?this.#e.nbf=Jt(`setNotBefore`,Bt(e)):this.#e.nbf=Bt(new Date)+qt(e)}set exp(e){typeof e==`number`?this.#e.exp=Jt(`setExpirationTime`,e):e instanceof Date?this.#e.exp=Jt(`setExpirationTime`,Bt(e)):this.#e.exp=Bt(new Date)+qt(e)}set iat(e){e===void 0?this.#e.iat=Bt(new Date):e instanceof Date?this.#e.iat=Jt(`setIssuedAt`,Bt(e)):typeof e==`string`?this.#e.iat=Jt(`setIssuedAt`,Bt(new Date)+qt(e)):this.#e.iat=Jt(`setIssuedAt`,e)}},$t=class{#e;#t;constructor(e={}){this.#t=new Qt(e)}setIssuer(e){return this.#t.iss=e,this}setSubject(e){return this.#t.sub=e,this}setAudience(e){return this.#t.aud=e,this}setJti(e){return this.#t.jti=e,this}setNotBefore(e){return this.#t.nbf=e,this}setExpirationTime(e){return this.#t.exp=e,this}setIssuedAt(e){return this.#t.iat=e,this}setProtectedHeader(e){return this.#e=e,this}async sign(e,t){let n=new zt(this.#t.data());if(n.setProtectedHeader(this.#e),Array.isArray(this.#e?.crit)&&this.#e.crit.includes(`b64`)&&this.#e.b64===!1)throw new Ye(`JWTs MUST NOT use unencoded payload`);return n.sign(e,t)}};function en(e,t){if(t!==void 0&&(!Array.isArray(t)||t.some(e=>typeof e!=`string`)))throw TypeError(`"${e}" option must be an array of strings`);if(t)return new Set(t)}async function tn(e,t,n){if(!pt(e))throw new K(`Flattened JWS must be an object`);if(e.protected===void 0&&e.header===void 0)throw new K(`Flattened JWS must have either of the "protected" or "header" members`);if(e.protected!==void 0&&typeof e.protected!=`string`)throw new K(`JWS Protected Header incorrect type`);if(e.payload===void 0)throw new K(`JWS Payload missing`);if(typeof e.signature!=`string`)throw new K(`JWS Signature missing or incorrect type`);if(e.header!==void 0&&!pt(e.header))throw new K(`JWS Unprotected Header incorrect type`);let r={};if(e.protected)try{let t=He(e.protected);r=JSON.parse(Le.decode(t))}catch{throw new K(`JWS Protected Header is invalid`)}if(!mt(r,e.header))throw new K(`JWS Protected and JWS Unprotected Header Parameter names must be disjoint`);let i={...r,...e.header},a=Dt(K,new Map([[`b64`,!0]]),n?.crit,r,i),o=!0;if(a.has(`b64`)&&(o=r.b64,typeof o!=`boolean`))throw new K(`The "b64" (base64url-encode payload) Header Parameter must be a boolean`);let{alg:s}=i;if(typeof s!=`string`||!s)throw new K(`JWS "alg" (Algorithm) Header Parameter missing or invalid`);let c=n&&en(`algorithms`,n.algorithms);if(c&&!c.has(s))throw new qe(`"alg" (Algorithm) Header Parameter value not allowed`);if(o){if(typeof e.payload!=`string`)throw new K(`JWS Payload must be a string`)}else if(typeof e.payload!=`string`&&!(e.payload instanceof Uint8Array))throw new K(`JWS Payload must be a string or an Uint8Array instance`);let l=!1;typeof t==`function`&&(t=await t(r,e),l=!0),Et(s,t,`verify`);let u=Re(e.protected===void 0?new Uint8Array:ze(e.protected),ze(`.`),typeof e.payload==`string`?o?ze(e.payload):Ie.encode(e.payload):e.payload),d=Lt(e.signature,`signature`,K),f=await Ft(t,s);if(!await dt(s,f,d,u))throw new Xe;let p;p=o?Lt(e.payload,`payload`,K):typeof e.payload==`string`?Ie.encode(e.payload):e.payload;let m={payload:p};return e.protected!==void 0&&(m.protectedHeader=r),e.header!==void 0&&(m.unprotectedHeader=e.header),l?{...m,key:f}:m}async function nn(e,t,n){if(e instanceof Uint8Array&&(e=Le.decode(e)),typeof e!=`string`)throw new K(`Compact JWS must be a string or Uint8Array`);let{0:r,1:i,2:a,length:o}=e.split(`.`);if(o!==3)throw new K(`Invalid Compact JWS`);let s=await tn({payload:i,protected:r,signature:a},t,n),c={payload:s.payload,protectedHeader:s.protectedHeader};return typeof t==`function`?{...c,key:s.key}:c}async function rn(e,t,n){let r=await nn(e,t,n);if(r.protectedHeader.crit?.includes(`b64`)&&r.protectedHeader.b64===!1)throw new Ye(`JWTs MUST NOT use unencoded payload`);let i={payload:Zt(r.protectedHeader,r.payload,n),protectedHeader:r.protectedHeader};return typeof t==`function`?{...i,key:r.key}:i}function an(e){return e.saveState!==void 0&&e.restoreState!==void 0&&e.cleanSavedState!==void 0}function on(e){for(let t=0;t<e.length;t++)e[t]=0;return e}var sn=class{blockSize;digestLength;_inner;_outer;_finished=!1;_innerKeyedState;_outerKeyedState;constructor(e,t){this._inner=new e,this._outer=new e,this.blockSize=this._outer.blockSize,this.digestLength=this._outer.digestLength;let n=new Uint8Array(this.blockSize);t.length>this.blockSize?this._inner.update(t).finish(n).clean():n.set(t);for(let e=0;e<n.length;e++)n[e]^=54;this._inner.update(n);for(let e=0;e<n.length;e++)n[e]^=106;this._outer.update(n),an(this._inner)&&an(this._outer)&&(this._innerKeyedState=this._inner.saveState(),this._outerKeyedState=this._outer.saveState()),on(n)}reset(){if(!an(this._inner)||!an(this._outer))throw Error(`hmac: can't reset() because hash doesn't implement restoreState()`);return this._inner.restoreState(this._innerKeyedState),this._outer.restoreState(this._outerKeyedState),this._finished=!1,this}clean(){an(this._inner)&&this._inner.cleanSavedState(this._innerKeyedState),an(this._outer)&&this._outer.cleanSavedState(this._outerKeyedState),this._inner.clean(),this._outer.clean()}update(e){return this._inner.update(e),this}finish(e){return this._finished?(this._outer.finish(e),this):(this._inner.finish(e),this._outer.update(e.subarray(0,this.digestLength)).finish(e),this._finished=!0,this)}digest(){let e=new Uint8Array(this.digestLength);return this.finish(e),e}saveState(){if(!an(this._inner))throw Error(`hmac: can't saveState() because hash doesn't implement it`);return this._inner.saveState()}restoreState(e){if(!an(this._inner)||!an(this._outer))throw Error(`hmac: can't restoreState() because hash doesn't implement it`);return this._inner.restoreState(e),this._outer.restoreState(this._outerKeyedState),this._finished=!1,this}cleanSavedState(e){if(!an(this._inner))throw Error(`hmac: can't cleanSavedState() because hash doesn't implement it`);this._inner.cleanSavedState(e)}};Number.isInteger,Number.isSafeInteger;function cn(e,t=0){return(e[t]<<24|e[t+1]<<16|e[t+2]<<8|e[t+3])>>>0}function ln(e,t=new Uint8Array(4),n=0){return t[n+0]=e>>>24,t[n+1]=e>>>16,t[n+2]=e>>>8,t[n+3]=e>>>0,t}function un(e,t,n,r,i){let a=new sn(e,t),o=a.digestLength,s=new Uint8Array(4),c=new Uint8Array(o),l=new Uint8Array(o),u=new Uint8Array(i),d=a.update(n).saveState();for(let e=0;e*o<i;e++){ln(e+1,s),a.restoreState(d).update(s).finish(l);for(let e=0;e<o;e++)c[e]=l[e];for(let e=2;e<=r;e++){a.reset().update(l).finish(l);for(let e=0;e<o;e++)c[e]^=l[e]}for(let t=0;t<o&&e*o+t<i;t++)u[e*o+t]=c[t]}return on(c),on(l),on(s),a.cleanSavedState(d),a.clean(),u}var dn=class{digestLength=32;blockSize=64;_state=new Int32Array(8);_temp=new Int32Array(64);_buffer=new Uint8Array(128);_bufferLength=0;_bytesHashed=0;_finished=!1;constructor(){this.reset()}_initState(){this._state[0]=1779033703,this._state[1]=3144134277,this._state[2]=1013904242,this._state[3]=2773480762,this._state[4]=1359893119,this._state[5]=2600822924,this._state[6]=528734635,this._state[7]=1541459225}reset(){return this._initState(),this._bufferLength=0,this._bytesHashed=0,this._finished=!1,this}clean(){on(this._buffer),on(this._temp),this.reset()}update(e,t=e.length){if(this._finished)throw Error(`SHA256: can't update because hash was finished.`);let n=0;if(this._bytesHashed+=t,this._bufferLength>0){for(;this._bufferLength<this.blockSize&&t>0;)this._buffer[this._bufferLength++]=e[n++],t--;this._bufferLength===this.blockSize&&(pn(this._temp,this._state,this._buffer,0,this.blockSize),this._bufferLength=0)}for(t>=this.blockSize&&(n=pn(this._temp,this._state,e,n,t),t%=this.blockSize);t>0;)this._buffer[this._bufferLength++]=e[n++],t--;return this}finish(e){if(!this._finished){let e=this._bytesHashed,t=this._bufferLength,n=e/536870912|0,r=e<<3,i=e%64<56?64:128;this._buffer[t]=128;for(let e=t+1;e<i-8;e++)this._buffer[e]=0;ln(n,this._buffer,i-8),ln(r,this._buffer,i-4),pn(this._temp,this._state,this._buffer,0,i),this._finished=!0}for(let t=0;t<this.digestLength/4;t++)ln(this._state[t],e,t*4);return this}digest(){let e=new Uint8Array(this.digestLength);return this.finish(e),e}saveState(){if(this._finished)throw Error(`SHA256: cannot save finished state`);return{state:new Int32Array(this._state),buffer:this._bufferLength>0?new Uint8Array(this._buffer):void 0,bufferLength:this._bufferLength,bytesHashed:this._bytesHashed}}restoreState(e){return this._state.set(e.state),this._bufferLength=e.bufferLength,e.buffer&&this._buffer.set(e.buffer),this._bytesHashed=e.bytesHashed,this._finished=!1,this}cleanSavedState(e){on(e.state),e.buffer&&on(e.buffer),e.bufferLength=0,e.bytesHashed=0}},fn=new Int32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]);function pn(e,t,n,r,i){for(;i>=64;){let a=t[0],o=t[1],s=t[2],c=t[3],l=t[4],u=t[5],d=t[6],f=t[7];for(let t=0;t<16;t++)e[t]=cn(n,r+t*4);for(let t=16;t<64;t++){let n=e[t-2],r=(n>>>17|n<<15)^(n>>>19|n<<13)^n>>>10;n=e[t-15];let i=(n>>>7|n<<25)^(n>>>18|n<<14)^n>>>3;e[t]=(r+e[t-7]|0)+(i+e[t-16]|0)}for(let t=0;t<64;t++){let n=(((l>>>6|l<<26)^(l>>>11|l<<21)^(l>>>25|l<<7))+(l&u^~l&d)|0)+(f+(fn[t]+e[t]|0)|0)|0,r=((a>>>2|a<<30)^(a>>>13|a<<19)^(a>>>22|a<<10))+(a&o^a&s^o&s)|0;f=d,d=u,u=l,l=c+n|0,c=s,s=o,o=a,a=n+r|0}t[0]+=a,t[1]+=o,t[2]+=s,t[3]+=c,t[4]+=l,t[5]+=u,t[6]+=d,t[7]+=f,r+=64,i-=64}return r}var mn=n(),hn,gn={lang:void 0,message:void 0,abortEarly:void 0,abortPipeEarly:void 0};function _n(e){return!e&&!hn?gn:{lang:e?.lang??hn?.lang,message:e?.message,abortEarly:e?.abortEarly??hn?.abortEarly,abortPipeEarly:e?.abortPipeEarly??hn?.abortPipeEarly}}var vn;function yn(e){return vn?.get(e)}var bn;function xn(e){return bn?.get(e)}var Sn;function Cn(e,t){return Sn?.get(e)?.get(t)}function wn(e){let t=typeof e;return t===`string`?`"${e}"`:t===`number`||t===`bigint`||t===`boolean`?`${e}`:t===`object`||t===`function`?(e&&Object.getPrototypeOf(e)?.constructor?.name)??`null`:t}function Tn(e,t,n,r,i){let a=i&&`input`in i?i.input:n.value,o=i?.expected??e.expects??null,s=i?.received??wn(a),c={kind:e.kind,type:e.type,input:a,expected:o,received:s,message:`Invalid ${t}: ${o?`Expected ${o} but r`:`R`}eceived ${s}`,requirement:e.requirement,path:i?.path,issues:i?.issues,lang:r.lang,abortEarly:r.abortEarly,abortPipeEarly:r.abortPipeEarly},l=e.kind===`schema`,u=i?.message??e.message??Cn(e.reference,c.lang)??(l?xn(c.lang):null)??r.message??yn(c.lang);u!==void 0&&(c.message=typeof u==`function`?u(c):u),l&&(n.typed=!1),n.issues?n.issues.push(c):n.issues=[c]}var En=new WeakMap;function Dn(e){let t=En.get(e);return t||(t={version:1,vendor:`valibot`,validate(t){return e[`~run`]({value:t},_n())}},En.set(e,t)),t}function On(e,t){return Object.prototype.hasOwnProperty.call(e,t)&&t!==`__proto__`&&t!==`prototype`&&t!==`constructor`}function kn(e,t){let n=[...new Set(e)];return n.length>1?`(${n.join(` ${t} `)})`:n[0]??`never`}function An(e,t){return{kind:`validation`,type:`check`,reference:An,async:!1,expects:null,requirement:e,message:t,"~run"(e,t){return e.typed&&!this.requirement(e.value)&&Tn(this,`input`,e,t),e}}}function jn(e){return{kind:`validation`,type:`integer`,reference:jn,async:!1,expects:null,requirement:Number.isInteger,message:e,"~run"(e,t){return e.typed&&!this.requirement(e.value)&&Tn(this,`integer`,e,t),e}}}function Mn(e,t){return{kind:`validation`,type:`max_length`,reference:Mn,async:!1,expects:`<=${e}`,requirement:e,message:t,"~run"(e,t){return e.typed&&e.value.length>this.requirement&&Tn(this,`length`,e,t,{received:`${e.value.length}`}),e}}}function Nn(e,t){return{kind:`validation`,type:`min_value`,reference:Nn,async:!1,expects:`>=${e instanceof Date?e.toJSON():wn(e)}`,requirement:e,message:t,"~run"(e,t){return e.typed&&!(e.value>=this.requirement)&&Tn(this,`value`,e,t,{received:e.value instanceof Date?e.value.toJSON():wn(e.value)}),e}}}function Pn(e,t){return{kind:`validation`,type:`regex`,reference:Pn,async:!1,expects:`${e}`,requirement:e,message:t,"~run"(e,t){return e.typed&&!this.requirement.test(e.value)&&Tn(this,`format`,e,t),e}}}function Fn(e,t,n){return typeof e.fallback==`function`?e.fallback(t,n):e.fallback}function In(e,t,n){return typeof e.default==`function`?e.default(t,n):e.default}function Ln(e,t){return{kind:`schema`,type:`array`,reference:Ln,expects:`Array`,async:!1,item:e,message:t,get"~standard"(){return Dn(this)},"~run"(e,t){let n=e.value;if(Array.isArray(n)){e.typed=!0,e.value=[];for(let r=0;r<n.length;r++){let i=n[r],a=this.item[`~run`]({value:i},t);if(a.issues){let o={type:`array`,origin:`value`,input:n,key:r,value:i};for(let t of a.issues)t.path?t.path.unshift(o):t.path=[o],e.issues?.push(t);if(e.issues||=a.issues,t.abortEarly){e.typed=!1;break}}a.typed||(e.typed=!1),e.value.push(a.value)}}else Tn(this,`type`,e,t);return e}}}function Rn(e){return{kind:`schema`,type:`boolean`,reference:Rn,expects:`boolean`,async:!1,message:e,get"~standard"(){return Dn(this)},"~run"(e,t){return typeof e.value==`boolean`?e.typed=!0:Tn(this,`type`,e,t),e}}}function zn(e,t){return{kind:`schema`,type:`instance`,reference:zn,expects:e.name,async:!1,class:e,message:t,get"~standard"(){return Dn(this)},"~run"(e,t){return e.value instanceof this.class?e.typed=!0:Tn(this,`type`,e,t),e}}}function Bn(e,t){return{kind:`schema`,type:`literal`,reference:Bn,expects:wn(e),async:!1,literal:e,message:t,get"~standard"(){return Dn(this)},"~run"(e,t){return e.value===this.literal?e.typed=!0:Tn(this,`type`,e,t),e}}}function Vn(e){return{kind:`schema`,type:`number`,reference:Vn,expects:`number`,async:!1,message:e,get"~standard"(){return Dn(this)},"~run"(e,t){return typeof e.value==`number`&&!isNaN(e.value)?e.typed=!0:Tn(this,`type`,e,t),e}}}function q(e,t){return{kind:`schema`,type:`optional`,reference:q,expects:`(${e.expects} | undefined)`,async:!1,wrapped:e,default:t,get"~standard"(){return Dn(this)},"~run"(e,t){return e.value===void 0&&(this.default!==void 0&&(e.value=In(this,e,t)),e.value===void 0)?(e.typed=!0,e):this.wrapped[`~run`](e,t)}}}function Hn(e,t){return{kind:`schema`,type:`picklist`,reference:Hn,expects:kn(e.map(wn),`|`),async:!1,options:e,message:t,get"~standard"(){return Dn(this)},"~run"(e,t){return this.options.includes(e.value)?e.typed=!0:Tn(this,`type`,e,t),e}}}function Un(e,t,n){return{kind:`schema`,type:`record`,reference:Un,expects:`Object`,async:!1,key:e,value:t,message:n,get"~standard"(){return Dn(this)},"~run"(e,t){let n=e.value;if(n&&typeof n==`object`){e.typed=!0,e.value={};for(let r in n)if(On(n,r)){let i=n[r],a=this.key[`~run`]({value:r},t);if(a.issues){let o={type:`object`,origin:`key`,input:n,key:r,value:i};for(let t of a.issues)t.path=[o],e.issues?.push(t);if(e.issues||=a.issues,t.abortEarly){e.typed=!1;break}}let o=this.value[`~run`]({value:i},t);if(o.issues){let a={type:`object`,origin:`value`,input:n,key:r,value:i};for(let t of o.issues)t.path?t.path.unshift(a):t.path=[a],e.issues?.push(t);if(e.issues||=o.issues,t.abortEarly){e.typed=!1;break}}(!a.typed||!o.typed)&&(e.typed=!1),a.typed&&(e.value[a.value]=o.value)}}else Tn(this,`type`,e,t);return e}}}function Wn(e,t){return{kind:`schema`,type:`strict_object`,reference:Wn,expects:`Object`,async:!1,entries:e,message:t,get"~standard"(){return Dn(this)},"~run"(e,t){let n=e.value;if(n&&typeof n==`object`){e.typed=!0,e.value={};for(let r in this.entries){let i=this.entries[r];if(r in n||(i.type===`exact_optional`||i.type===`optional`||i.type===`nullish`)&&i.default!==void 0){let a=r in n?n[r]:In(i),o=i[`~run`]({value:a},t);if(o.issues){let i={type:`object`,origin:`value`,input:n,key:r,value:a};for(let t of o.issues)t.path?t.path.unshift(i):t.path=[i],e.issues?.push(t);if(e.issues||=o.issues,t.abortEarly){e.typed=!1;break}}o.typed||(e.typed=!1),e.value[r]=o.value}else if(i.fallback!==void 0)e.value[r]=Fn(i);else if(i.type!==`exact_optional`&&i.type!==`optional`&&i.type!==`nullish`&&(Tn(this,`key`,e,t,{input:void 0,expected:`"${r}"`,path:[{type:`object`,origin:`key`,input:n,key:r,value:n[r]}]}),t.abortEarly))break}if(!e.issues||!t.abortEarly){for(let r in n)if(!(r in this.entries)){Tn(this,`key`,e,t,{input:r,expected:`never`,path:[{type:`object`,origin:`key`,input:n,key:r,value:n[r]}]});break}}}else Tn(this,`type`,e,t);return e}}}function J(e){return{kind:`schema`,type:`string`,reference:J,expects:`string`,async:!1,message:e,get"~standard"(){return Dn(this)},"~run"(e,t){return typeof e.value==`string`?e.typed=!0:Tn(this,`type`,e,t),e}}}function Gn(){return{kind:`schema`,type:`unknown`,reference:Gn,expects:`unknown`,async:!1,get"~standard"(){return Dn(this)},"~run"(e){return e.typed=!0,e}}}function Kn(...e){return{...e[0],pipe:e,get"~standard"(){return Dn(this)},"~run"(t,n){for(let r of e)if(r.kind!==`metadata`){if(t.issues&&(r.kind===`schema`||r.kind===`transformation`)){t.typed=!1;break}(!t.issues||!n.abortEarly&&!n.abortPipeEarly)&&(t=r[`~run`](t,n))}return t}}}function qn(e,t,n){let r=e[`~run`]({value:t},_n(n));return{typed:r.typed,success:!r.issues,output:r.value,issues:r.issues}}var Y={POS_INT:0,NEG_INT:1,BYTE_STRING:2,UTF8_STRING:3,ARRAY:4,MAP:5,TAG:6,SIMPLE_FLOAT:7},X={DATE_STRING:0,DATE_EPOCH:1,POS_BIGINT:2,NEG_BIGINT:3,DECIMAL_FRAC:4,BIGFLOAT:5,BASE64URL_EXPECTED:21,BASE64_EXPECTED:22,BASE16_EXPECTED:23,CBOR:24,URI:32,BASE64URL:33,BASE64:34,MIME:36,DATE_EPOCH_DAYS:100,SET:258,JSON:262,WTF8:273,SYMBOL:280,DATE_FULL:1004,REGEXP:21066,SELF_DESCRIBED:55799,INVALID_16:65535,INVALID_32:4294967295,INVALID_64:18446744073709551615n},Z={ZERO:0,ONE:24,TWO:25,FOUR:26,EIGHT:27,INDEFINITE:31},Jn={FALSE:20,TRUE:21,NULL:22,UNDEFINED:23},Yn=class{static BREAK=Symbol.for(`github.com/hildjj/cbor2/break`);static ENCODED=Symbol.for(`github.com/hildjj/cbor2/cbor-encoded`);static LENGTH=Symbol.for(`github.com/hildjj/cbor2/length`)},Xn={MIN:-(2n**63n),MAX:2n**64n-1n},Q=class e{static#e=new Map;tag;contents;constructor(e,t=void 0){this.tag=e,this.contents=t}get noChildren(){return!!e.#e.get(this.tag)?.noChildren}static registerDecoder(e,t,n){let r=this.#e.get(e);return this.#e.set(e,t),r&&(`comment`in t||(t.comment=r.comment),`noChildren`in t||(t.noChildren=r.noChildren)),n&&!t.comment&&(t.comment=()=>`(${n})`),r}static clearDecoder(e){let t=this.#e.get(e);return this.#e.delete(e),t}static getDecoder(e){return this.#e.get(e)}static getAllDecoders(){return new Map(this.#e)}*[Symbol.iterator](){yield this.contents}push(e){return this.contents=e,1}decode(t){let n=t?.tags?.get(this.tag)??(t?.ignoreGlobalTags?void 0:e.#e.get(this.tag));return n?n(this,t):this}comment(t,n){let r=t?.tags?.get(this.tag)??(t?.ignoreGlobalTags?void 0:e.#e.get(this.tag));if(r?.comment)return r.comment(this,t,n)}toCBOR(){return[this.tag,this.contents]}[Symbol.for(`nodejs.util.inspect.custom`)](e,t,n){return`${this.tag}(${n(this.contents,t)})`}};function Zn(e){if(typeof e==`object`&&e)return e[Yn.ENCODED]}function Qn(e){if(typeof e==`object`&&e)return e[Yn.LENGTH]}function $n(e,t){Object.defineProperty(e,Yn.ENCODED,{configurable:!0,enumerable:!1,value:t})}function er(e,t){let n=Object(e);return $n(n,t),n}var tr=Symbol(`CBOR_RANGES`);function nr(e,t){Object.defineProperty(e,tr,{configurable:!1,enumerable:!1,writable:!1,value:t})}function rr(e){return e[tr]}function ir(e){return rr(e)!==void 0}function ar(e,t=0,n=e.length-1){let r=e.subarray(t,n),i=rr(e);if(i){let e=[];for(let r of i)if(r[0]>=t&&r[0]+r[1]<=n){let n=[...r];n[0]-=t,e.push(n)}e.length&&nr(r,e)}return r}function or(e){let t=Math.ceil(e.length/2),n=new Uint8Array(t);t--;for(let r=e.length,i=r-2;r>=0;r=i,i-=2,t--)n[t]=parseInt(e.substring(i,r),16);return n}function sr(e){return e.reduce((e,t)=>e+t.toString(16).padStart(2,`0`),``)}function cr(e){let t=e.reduce((e,t)=>e+t.length,0),n=e.some(e=>ir(e)),r=[],i=new Uint8Array(t),a=0;for(let t of e){if(!(t instanceof Uint8Array))throw TypeError(`Invalid array: ${t}`);if(i.set(t,a),n){let e=t[tr]??[[0,t.length]];for(let t of e)t[0]+=a;r.push(...e)}a+=t.length}return n&&nr(i,r),i}function lr(e){let t=atob(e);return Uint8Array.from(t,e=>e.codePointAt(0))}var ur={"-":`+`,_:`/`};function dr(e){let t=e.replace(/[_-]/g,e=>ur[e]);return lr(t.padEnd(Math.ceil(t.length/4)*4,`=`))}function fr(){let e=new Uint8Array(4),t=new Uint32Array(e.buffer);return!((t[0]=1)&e[0])}function pr(e){let t=``;for(let n of e){let e=n.codePointAt(0)?.toString(16).padStart(4,`0`);t&&(t+=`, `),t+=`U+${e}`}return t}var mr=class{#e=new Map;registerEncoder(e,t){let n=this.#e.get(e);return this.#e.set(e,t),n}get(e){return this.#e.get(e)}delete(e){return this.#e.delete(e)}clear(){this.#e.clear()}};function hr(e,t){let[n,r,i]=e,[a,o,s]=t,c=Math.min(i.length,s.length);for(let e=0;e<c;e++){let t=i[e]-s[e];if(t!==0)return t}return 0}var gr=class e{static defaultOptions={chunkSize:4096};#e;#t=[];#n=null;#r=0;#i=0;constructor(t={}){if(this.#e={...e.defaultOptions,...t},this.#e.chunkSize<8)throw RangeError(`Expected size >= 8, got ${this.#e.chunkSize}`);this.#a()}get length(){return this.#i}read(){this.#o();let e=new Uint8Array(this.#i),t=0;for(let n of this.#t)e.set(n,t),t+=n.length;return this.#a(),e}write(e){let t=e.length;t>this.#s()?(this.#o(),t>this.#e.chunkSize?(this.#t.push(e),this.#a()):(this.#a(),this.#t[this.#t.length-1].set(e),this.#r=t)):(this.#t[this.#t.length-1].set(e,this.#r),this.#r+=t),this.#i+=t}writeUint8(e){this.#c(1),this.#n.setUint8(this.#r,e),this.#l(1)}writeUint16(e,t=!1){this.#c(2),this.#n.setUint16(this.#r,e,t),this.#l(2)}writeUint32(e,t=!1){this.#c(4),this.#n.setUint32(this.#r,e,t),this.#l(4)}writeBigUint64(e,t=!1){this.#c(8),this.#n.setBigUint64(this.#r,e,t),this.#l(8)}writeInt16(e,t=!1){this.#c(2),this.#n.setInt16(this.#r,e,t),this.#l(2)}writeInt32(e,t=!1){this.#c(4),this.#n.setInt32(this.#r,e,t),this.#l(4)}writeBigInt64(e,t=!1){this.#c(8),this.#n.setBigInt64(this.#r,e,t),this.#l(8)}writeFloat32(e,t=!1){this.#c(4),this.#n.setFloat32(this.#r,e,t),this.#l(4)}writeFloat64(e,t=!1){this.#c(8),this.#n.setFloat64(this.#r,e,t),this.#l(8)}clear(){this.#i=0,this.#t=[],this.#a()}#a(){let e=new Uint8Array(this.#e.chunkSize);this.#t.push(e),this.#r=0,this.#n=new DataView(e.buffer,e.byteOffset,e.byteLength)}#o(){if(this.#r===0){this.#t.pop();return}let e=this.#t.length-1;this.#t[e]=this.#t[e].subarray(0,this.#r),this.#r=0,this.#n=null}#s(){let e=this.#t.length-1;return this.#t[e].length-this.#r}#c(e){this.#s()<e&&(this.#o(),this.#a())}#l(e){this.#r+=e,this.#i+=e}},_r=1n<<15n,vr=31n<<10n,yr=1n<<9n,br=yr-1n,xr=yr|br,Sr=1n<<31n,Cr=255n<<23n,wr=1n<<22n,Tr=wr-1n,Er=wr|Tr,Dr=1n<<63n,Or=2047n<<52n,kr=1n<<51n,Ar=kr-1n,jr=kr|Ar,Mr=Ar-(br<<42n),Nr=Ar-(Tr<<29n),Pr={2:`0b`,8:`0o`,16:`0x`},Fr=(e=>(e[e.NATURAL=-2]=`NATURAL`,e[e.UNKNOWN=-1]=`UNKNOWN`,e[e.F16=2]=`F16`,e[e.F32=4]=`F32`,e[e.F64=8]=`F64`,e))(Fr||{});function Ir(e,t,n,r){let i=`nan'`;return e.quiet||(i+=`!`),e.sign===-1&&(i+=`-`),i+=r(Math.abs(e.payload),n),i+=`'`,i+=e.encodingIndicator,i}var Lr=class extends Number{#e;#t=-1;constructor(e,t=!0,n=-1){super(NaN);let r=e;if(typeof e==`number`){if(!Number.isSafeInteger(e))throw Error(`Invalid NAN payload: ${e}`);e=BigInt(e);let i=0n;if(e<0&&(i=Dr,e=-e),e>=kr)throw Error(`Payload too large: ${r}`);let a=t?kr:0n;switch(this.#e=i|Or|a|e,n){case-2:throw Error(`NAN_SIZE.NATURAL only valid for bigint constructor`);case-1:n=this.preferredSize;break;case 2:if(this.#e&Mr)throw Error(`Invalid size for payload`);break;case 4:if(this.#e&Nr)throw Error(`Invalid size for payload`);break;case 8:break;default:throw Error(`Invalid size: ${n}`)}this.#t=n}else if(typeof e==`bigint`){let t=-1;if((e&Or)===Or)this.#e=e,t=8;else if((e&Cr)===Cr){let n=(e&Sr)<<32n;this.#e=n|Or|(e&Er)<<29n,t=4}else if((e&vr)===vr){let n=(e&_r)<<48n;this.#e=n|Or|(e&xr)<<42n,t=2}else throw Error(`Invalid raw NaN value: ${e}`);if(n===-1)this.#t=this.preferredSize;else if(n===-2)this.#t=t;else{if(n<t)throw Error(`Invalid bigint NaN size`);this.#t=n}}else{let t=new DataView(e.buffer,e.byteOffset,e.byteLength);switch(e.length){case 3:{if(e[0]!==249)throw Error(`Invalid CBOR encoding for half float`);let n=BigInt(t.getUint16(1,!1));if((n&vr)!==vr)throw Error(`Not a NaN`);let r=(n&_r)<<48n;this.#e=r|Or|(n&xr)<<42n,this.#t=2;break}case 5:{if(e[0]!==250)throw Error(`Invalid CBOR encoding for single float`);let n=BigInt(t.getUint32(1,!1));if((n&Cr)!==Cr)throw Error(`Not a NaN`);let r=(n&Sr)<<32n;this.#e=r|Or|(n&Er)<<29n,this.#t=4;break}case 9:if(e[0]!==251)throw Error(`Invalid CBOR encoding for double float`);if(this.#e=t.getBigUint64(1,!1),(this.#e&Or)!==Or)throw Error(`Not a NaN (NaNaN)`);this.#t=8;break;default:throw RangeError(`Invalid NAN size (should be 2, 4, or 8): ${e.length-1}`)}}if(!this.payload&&!this.quiet)throw Error(`Signalling NaN with zero payload`)}get bytes(){let e=new ArrayBuffer(this.#t+1),t=new DataView(e);switch(this.#t){case 2:{t.setUint8(0,249);let e=(this.#e&Dr?_r:0n)|vr|(this.#e&jr)>>42n;t.setUint16(1,Number(e),!1);break}case 4:{t.setUint8(0,250);let e=(this.#e&Dr?Sr:0n)|Cr|(this.#e&jr)>>29n;t.setUint32(1,Number(e),!1);break}case 8:t.setUint8(0,251),t.setBigUint64(1,this.#e);break}return new Uint8Array(e)}get quiet(){return!!(this.#e&kr)}get sign(){return this.#e&Dr?-1:1}get payload(){return Number(this.#e&Ar)*this.sign}get raw(){return this.#e}get encodingIndicator(){switch(this.#t){case 2:return`_1`;case 4:return`_2`}return`_3`}get size(){return this.#t}get preferredSize(){return(this.#e&Mr)===0n?2:(this.#e&Nr)===0n?4:8}get isShortestEncoding(){return this.preferredSize===this.#t}toCBOR(e){e.write(this.bytes)}toString(e=10){return Ir(this,1,{},t=>(Pr[e]??``)+t.toString(e))}[Symbol.for(`nodejs.util.inspect.custom`)](e,t,n){return Ir(this,e,t,n)}};function Rr(e,t=0,n=!1){let r=e[t]&128?-1:1,i=(e[t]&124)>>2,a=(e[t]&3)<<8|e[t+1];if(i===0){if(n&&a!==0)throw Error(`Unwanted subnormal: ${r*5.960464477539063e-8*a}`);return r*5.960464477539063e-8*a}else if(i===31)return a?NaN:r*(1/0);return r*2**(i-25)*(1024+a)}function zr(e){let t=new DataView(new ArrayBuffer(4));t.setFloat32(0,e,!1);let n=t.getUint32(0,!1);if(n&8191)return null;let r=n>>16&32768,i=n>>23&255,a=n&8388607;if(!(i===0&&a===0))if(i>=113&&i<=142)r+=(i-112<<10)+(a>>13);else if(i>=103&&i<113){if(a&(1<<126-i)-1)return null;r+=a+8388608>>126-i}else if(i===255)r|=31744,r|=a>>13;else return null;return r}function Br(e){if(e!==0){let t=new DataView(new ArrayBuffer(8));t.setFloat64(0,e,!1);let n=t.getBigUint64(0,!1);if((n&9218868437227405312n)==0n)return n&9223372036854775808n?-0:0}return e}function Vr(e){switch(e.length){case 2:Rr(e,0,!0);break;case 4:{let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=t.getUint32(0,!1);if(!(n&2139095040)&&n&8388607)throw Error(`Unwanted subnormal: ${t.getFloat32(0,!1)}`);break}case 8:{let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=t.getBigUint64(0,!1);if((n&9218868437227405312n)==0n&&n&17592186044415n)throw Error(`Unwanted subnormal: ${t.getFloat64(0,!1)}`);break}default:throw TypeError(`Bad input to isSubnormal: ${e}`)}}var Hr=class extends TypeError{code=`ERR_ENCODING_INVALID_ENCODED_DATA`;constructor(){super(`The encoded data was not valid for encoding wtf-8`)}},Ur=class extends RangeError{code=`ERR_ENCODING_NOT_SUPPORTED`;constructor(e){super(`Invalid encoding: "${e}"`)}},Wr=new Uint8Array,Gr=55296,Kr=56320,qr=65533,Jr=`wtf-8`;function Yr(e){return e&&typeof e==`object`&&!(e instanceof ArrayBuffer)&&!(e instanceof SharedArrayBuffer)&&e.buffer instanceof ArrayBuffer}function Xr(e){return e?e instanceof Uint8Array?e:Yr(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):new Uint8Array(e):Wr}var Zr=[0,0,0,0,0,0,0,0,-1,-1,-1,-1,1,1,2,3],Qr=class e{static DEFAULT_BUFFERSIZE=4096;encoding=Jr;fatal;ignoreBOM;bufferSize;#e=0;#t=0;#n=0;#r=!0;#i;constructor(t=`wtf8`,n=void 0){if(t.toLowerCase().replace(`-`,``)!==`wtf8`)throw new Ur(t);if(this.fatal=!!n?.fatal,this.ignoreBOM=!!n?.ignoreBOM,this.bufferSize=Math.floor(n?.bufferSize??e.DEFAULT_BUFFERSIZE),isNaN(this.bufferSize)||this.bufferSize<1)throw RangeError(`Invalid buffer size: ${n?.bufferSize}`);this.#i=new Uint16Array(this.bufferSize)}decode(e,t){let n=!!t?.stream,r=Xr(e),i=[],a=this.#i,o=this.bufferSize-3,s=0,c=()=>{if(this.#t=0,this.#e=0,this.#n=0,this.fatal)throw new Hr;a[s++]=qr},l=()=>{let e=this.#n;for(let t=0;t<e;t++)c()},u=e=>{if(this.#e===0)switch(Zr[e>>4]){case-1:c();break;case 0:a[s++]=e;break;case 1:this.#t=e&31,this.#t&30?(this.#e=1,this.#n=1):c();break;case 2:this.#t=e&15,this.#e=2,this.#n=1;break;case 3:e&8?c():(this.#t=e&7,this.#e=3,this.#n=1);break}else{if((e&192)!=128||this.#n===1&&this.#e===2&&this.#t===0&&!(e&32)||this.#e===3&&this.#t===0&&!(e&48))return l(),u(e);if(this.#t=this.#t<<6|e&63,this.#n++,--this.#e===0){if(this.ignoreBOM||!this.#r||this.#t!==65279)if(this.#t<65536)a[s++]=this.#t;else{let e=this.#t-65536;a[s++]=e>>>10&1023|Gr,a[s++]=e&1023|Kr}this.#t=0,this.#n=0,this.#r=!1}}};for(let e of r)s>=o&&(i.push(String.fromCharCode.apply(null,a.subarray(0,s))),s=0),u(e);return n||(this.#r=!0,(this.#t||this.#e)&&l()),s>0&&i.push(String.fromCharCode.apply(null,a.subarray(0,s))),i.join(``)}};function $r(e){let t=0;for(let n of e){let e=n.codePointAt(0);e<128?t++:e<2048?t+=2:e<65536?t+=3:t+=4}return t}var ei=class{encoding=Jr;encode(e){if(!e)return Wr;let t=new Uint8Array($r(String(e)));return this.encodeInto(e,t),t}encodeInto(e,t){let n=String(e),r=n.length,i=t.length,a=0,o=0;for(o=0;o<r;o++){let e=n.codePointAt(o);if(e<128){if(a>=i)break;t[a++]=e}else if(e<2048){if(a>=i-1)break;t[a++]=192|e>>6,t[a++]=128|e&63}else if(e<65536){if(a>=i-2)break;t[a++]=224|e>>12,t[a++]=128|e>>6&63,t[a++]=128|e&63}else{if(a>=i-3)break;t[a++]=240|e>>18,t[a++]=128|e>>12&63,t[a++]=128|e>>6&63,t[a++]=128|e&63,o++}}return{read:o,written:a}}},{ENCODED:ti}=Yn,ni=Y.SIMPLE_FLOAT<<5|Z.TWO,ri=Y.SIMPLE_FLOAT<<5|Z.FOUR,ii=Y.SIMPLE_FLOAT<<5|Z.EIGHT,ai=Y.SIMPLE_FLOAT<<5|Jn.TRUE,oi=Y.SIMPLE_FLOAT<<5|Jn.FALSE,si=Y.SIMPLE_FLOAT<<5|Jn.UNDEFINED,ci=Y.SIMPLE_FLOAT<<5|Jn.NULL,li=new TextEncoder,ui=new ei,di={...gr.defaultOptions,avoidInts:!1,cde:!1,collapseBigInts:!0,dateTag:X.DATE_EPOCH,dcbor:!1,float64:!1,flushToZero:!1,forceEndian:null,ignoreOriginalEncoding:!1,largeNegativeAsBigInt:!1,reduceUnsafeNumbers:!1,rejectBigInts:!1,rejectCustomSimples:!1,rejectDuplicateKeys:!1,rejectFloats:!1,rejectUndefined:!1,simplifyNegativeZero:!1,sortKeys:null,stringNormalization:null,types:null,wtf8:!1,ignoreGlobalTags:!1},fi={cde:!0,ignoreOriginalEncoding:!0,sortKeys:hr},pi={...fi,dcbor:!0,largeNegativeAsBigInt:!0,reduceUnsafeNumbers:!0,rejectCustomSimples:!0,rejectDuplicateKeys:!0,rejectUndefined:!0,simplifyNegativeZero:!0,stringNormalization:`NFC`};function mi(e){let t=e<0;return typeof e==`bigint`?[t?-e-1n:e,t]:[t?-e-1:e,t]}function hi(e,t,n){if(n.rejectFloats)throw Error(`Attempt to encode an unwanted floating point number: ${e}`);if(isNaN(e))t.writeUint8(ni),t.writeUint16(32256);else if(!n.float64&&Math.fround(e)===e){let n=zr(e);n===null?(t.writeUint8(ri),t.writeFloat32(e)):(t.writeUint8(ni),t.writeUint16(n))}else t.writeUint8(ii),t.writeFloat64(e)}function gi(e,t,n){let[r,i]=mi(e);if(i&&n)throw TypeError(`Negative size: ${e}`);n??=i?Y.NEG_INT:Y.POS_INT,n<<=5,r<24?t.writeUint8(n|r):r<=255?(t.writeUint8(n|Z.ONE),t.writeUint8(r)):r<=65535?(t.writeUint8(n|Z.TWO),t.writeUint16(r)):r<=4294967295?(t.writeUint8(n|Z.FOUR),t.writeUint32(r)):(t.writeUint8(n|Z.EIGHT),t.writeBigUint64(BigInt(r)))}function _i(e,t,n){typeof e==`number`?gi(e,t,Y.TAG):typeof e==`object`&&!n.ignoreOriginalEncoding&&Yn.ENCODED in e?t.write(e[Yn.ENCODED]):e<=2**53-1?gi(Number(e),t,Y.TAG):(t.writeUint8(Y.TAG<<5|Z.EIGHT),t.writeBigUint64(BigInt(e)))}function vi(e,t,n){let[r,i]=mi(e);if(n.collapseBigInts&&(!n.largeNegativeAsBigInt||e>=-9223372036854775808n)){if(r<=4294967295n){gi(Number(e),t);return}if(r<=18446744073709551615n){let e=(i?Y.NEG_INT:Y.POS_INT)<<5;t.writeUint8(e|Z.EIGHT),t.writeBigUint64(r);return}}if(n.rejectBigInts)throw Error(`Attempt to encode unwanted bigint: ${e}`);let a=i?X.NEG_BIGINT:X.POS_BIGINT,o=r.toString(16),s=o.length%2?`0`:``;_i(a,t,n);let c=or(s+o);gi(c.length,t,Y.BYTE_STRING),t.write(c)}function yi(e,t,n){n.flushToZero&&(e=Br(e)),Object.is(e,-0)?n.simplifyNegativeZero?n.avoidInts?hi(0,t,n):gi(0,t):hi(e,t,n):!n.avoidInts&&Number.isSafeInteger(e)?gi(e,t):n.reduceUnsafeNumbers&&Math.floor(e)===e&&e>=Xn.MIN&&e<=Xn.MAX?vi(BigInt(e),t,n):hi(e,t,n)}function bi(e,t,n){let r=n.stringNormalization?e.normalize(n.stringNormalization):e;if(n.wtf8&&!e.isWellFormed()){let e=ui.encode(r);_i(X.WTF8,t,n),gi(e.length,t,Y.BYTE_STRING),t.write(e)}else{let e=li.encode(r);gi(e.length,t,Y.UTF8_STRING),t.write(e)}}function xi(e,t,n){let r=e;wi(r,r.length,Y.ARRAY,t,n);for(let e of r)Di(e,t,n)}function Si(e,t){gi(e.length,t,Y.BYTE_STRING),t.write(e)}var Ci=new mr;Ci.registerEncoder(Array,xi),Ci.registerEncoder(Uint8Array,Si);function $(e,t){return Ci.registerEncoder(e,t)}function wi(e,t,n,r,i){let a=Qn(e);a&&!i.ignoreOriginalEncoding?r.write(a):gi(t,r,n)}function Ti(e,t,n){if(e===null){t.writeUint8(ci);return}if(!n.ignoreOriginalEncoding&&Yn.ENCODED in e){t.write(e[Yn.ENCODED]);return}let r=e.constructor;if(r){let i=n.types?.get(r)??(n.ignoreGlobalTags?void 0:Ci.get(r));if(i){let r=i(e,t,n);if(r!==void 0){if(!Array.isArray(r)||r.length!==2)throw Error(`Invalid encoder return value`);(typeof r[0]==`bigint`||isFinite(Number(r[0])))&&_i(r[0],t,n),Di(r[1],t,n)}return}}if(typeof e.toCBOR==`function`){let r=e.toCBOR(t,n);r&&((typeof r[0]==`bigint`||isFinite(Number(r[0])))&&_i(r[0],t,n),Di(r[1],t,n));return}if(typeof e.toJSON==`function`){Di(e.toJSON(),t,n);return}let i=Object.entries(e).map(e=>[e[0],e[1],Oi(e[0],n)]);n.sortKeys&&i.sort(n.sortKeys),wi(e,i.length,Y.MAP,t,n);for(let[e,r,a]of i)t.write(a),Di(r,t,n)}function Ei(e,t,n){if(!e.description||e!==Symbol.for(e.description))throw TypeError(`Private or empty symbol: ${e.toString()}`);_i(280,t,n),bi(e.description,t,n)}function Di(e,t,n){switch(typeof e){case`number`:yi(e,t,n);break;case`bigint`:vi(e,t,n);break;case`string`:bi(e,t,n);break;case`boolean`:t.writeUint8(e?ai:oi);break;case`undefined`:if(n.rejectUndefined)throw Error(`Attempt to encode unwanted undefined.`);t.writeUint8(si);break;case`object`:Ti(e,t,n);break;case`symbol`:Ei(e,t,n);break;default:throw TypeError(`Unknown type: ${typeof e}, ${String(e)}`)}}function Oi(e,t={}){let n={...di};t.dcbor?Object.assign(n,pi):t.cde&&Object.assign(n,fi),Object.assign(n,t);let r=new gr(n);return Di(e,r,n),r.read()}var ki=(e=>(e[e.NEVER=-1]=`NEVER`,e[e.PREFERRED=0]=`PREFERRED`,e[e.ALWAYS=1]=`ALWAYS`,e))(ki||{}),Ai=class e{static KnownSimple=new Map([[Jn.FALSE,!1],[Jn.TRUE,!0],[Jn.NULL,null],[Jn.UNDEFINED,void 0]]);value;constructor(e){this.value=e}static create(t){return e.KnownSimple.has(t)?e.KnownSimple.get(t):new e(t)}toCBOR(e,t){if(t.rejectCustomSimples)throw Error(`Cannot encode non-standard Simple value: ${this.value}`);gi(this.value,e,Y.SIMPLE_FLOAT)}toString(){return`simple(${this.value})`}decode(){return e.KnownSimple.has(this.value)?e.KnownSimple.get(this.value):this}[Symbol.for(`nodejs.util.inspect.custom`)](e,t,n){return`simple(${n(this.value,t)})`}},ji=new TextDecoder(`utf8`,{fatal:!0,ignoreBOM:!0}),Mi=class e{static defaultOptions={maxDepth:1024,encoding:`hex`,requirePreferred:!1};#e;#t;#n=0;#r;constructor(t,n){if(this.#r={...e.defaultOptions,...n},typeof t==`string`)switch(this.#r.encoding){case`hex`:this.#e=or(t);break;case`base64`:this.#e=lr(t);break;default:throw TypeError(`Encoding not implemented: "${this.#r.encoding}"`)}else this.#e=t;this.#t=new DataView(this.#e.buffer,this.#e.byteOffset,this.#e.byteLength)}toHere(e){return ar(this.#e,e,this.#n)}*[Symbol.iterator](){if(yield*this.#i(0),this.#n!==this.#e.length)throw Error(`Extra data in input`)}*seq(){for(;this.#n<this.#e.length;)yield*this.#i(0)}*#i(e){if(e++>this.#r.maxDepth)throw Error(`Maximum depth ${this.#r.maxDepth} exceeded`);let t=this.#n,n=this.#t.getUint8(this.#n++),r=n>>5,i=n&31,a=i,o=!1,s=0;switch(i){case Z.ONE:if(s=1,a=this.#t.getUint8(this.#n),r===Y.SIMPLE_FLOAT){if(a<32)throw Error(`Invalid simple encoding in extra byte: ${a}`);o=!0}else if(this.#r.requirePreferred&&a<24)throw Error(`Unexpectedly long integer encoding (1) for ${a}`);break;case Z.TWO:if(s=2,r===Y.SIMPLE_FLOAT)a=Rr(this.#e,this.#n);else if(a=this.#t.getUint16(this.#n,!1),this.#r.requirePreferred&&a<=255)throw Error(`Unexpectedly long integer encoding (2) for ${a}`);break;case Z.FOUR:if(s=4,r===Y.SIMPLE_FLOAT)a=this.#t.getFloat32(this.#n,!1);else if(a=this.#t.getUint32(this.#n,!1),this.#r.requirePreferred&&a<=65535)throw Error(`Unexpectedly long integer encoding (4) for ${a}`);break;case Z.EIGHT:if(s=8,r===Y.SIMPLE_FLOAT)a=this.#t.getFloat64(this.#n,!1);else if(a=this.#t.getBigUint64(this.#n,!1),a<=2**53-1&&(a=Number(a)),this.#r.requirePreferred&&a<=4294967295)throw Error(`Unexpectedly long integer encoding (8) for ${a}`);break;case 28:case 29:case 30:throw Error(`Additional info not implemented: ${i}`);case Z.INDEFINITE:switch(r){case Y.POS_INT:case Y.NEG_INT:case Y.TAG:throw Error(`Invalid indefinite encoding for MT ${r}`);case Y.SIMPLE_FLOAT:yield[r,i,Yn.BREAK,t,0];return}a=1/0;break;default:o=!0}switch(this.#n+=s,r){case Y.POS_INT:yield[r,i,a,t,s];break;case Y.NEG_INT:yield[r,i,typeof a==`bigint`?-1n-a:-1-Number(a),t,s];break;case Y.BYTE_STRING:a===1/0?yield*this.#o(r,e,t):yield[r,i,this.#a(a),t,a];break;case Y.UTF8_STRING:a===1/0?yield*this.#o(r,e,t):yield[r,i,ji.decode(this.#a(a)),t,a];break;case Y.ARRAY:if(a===1/0)yield*this.#o(r,e,t,!1);else{let n=Number(a);yield[r,i,n,t,s];for(let t=0;t<n;t++)yield*this.#i(e+1)}break;case Y.MAP:if(a===1/0)yield*this.#o(r,e,t,!1);else{let n=Number(a);yield[r,i,n,t,s];for(let t=0;t<n;t++)yield*this.#i(e),yield*this.#i(e)}break;case Y.TAG:yield[r,i,a,t,s],yield*this.#i(e);break;case Y.SIMPLE_FLOAT:{let e=a;o&&(a=Ai.create(Number(a))),yield[r,i,a,t,e];break}}}#a(e){let t=ar(this.#e,this.#n,this.#n+=e);if(t.length!==e)throw Error(`Unexpected end of stream reading ${e} bytes, got ${t.length}`);return t}*#o(e,t,n,r=!0){for(yield[e,Z.INDEFINITE,1/0,n,1/0];;){let n=this.#i(t),i=n.next(),[a,o,s]=i.value;if(s===Yn.BREAK){yield i.value,n.next();return}if(r){if(a!==e)throw Error(`Unmatched major type. Expected ${e}, got ${a}.`);if(o===Z.INDEFINITE)throw Error(`New stream started in typed stream`)}yield i.value,yield*n}}},Ni=new Map([[Z.ZERO,1],[Z.ONE,2],[Z.TWO,3],[Z.FOUR,5],[Z.EIGHT,9]]),Pi=new Uint8Array;function Fi(e,t){return!t.boxed&&!t.preferMap&&e.every(([e])=>typeof e==`string`)?Object.fromEntries(e):new Map(e)}var Ii=class e{static defaultDecodeOptions={...Mi.defaultOptions,ParentType:e,boxed:!1,cde:!1,dcbor:!1,diagnosticSizes:ki.PREFERRED,collapseBigInts:!1,convertUnsafeIntsToFloat:!1,createObject:Fi,keepNanPayloads:!1,pretty:!1,preferBigInt:!1,preferMap:!1,rejectLargeNegatives:!1,rejectBigInts:!1,rejectDuplicateKeys:!1,rejectFloats:!1,rejectInts:!1,rejectLongLoundNaN:!1,rejectLongFloats:!1,rejectNegativeZero:!1,rejectSimple:!1,rejectStreaming:!1,rejectStringsNotNormalizedAs:null,rejectSubnormals:!1,rejectUndefined:!1,rejectUnsafeFloatInts:!1,saveOriginal:!1,sortKeys:null,tags:null,ignoreGlobalTags:!1};static cdeDecodeOptions={cde:!0,rejectStreaming:!0,requirePreferred:!0,sortKeys:hr};static dcborDecodeOptions={...this.cdeDecodeOptions,dcbor:!0,convertUnsafeIntsToFloat:!0,rejectDuplicateKeys:!0,rejectLargeNegatives:!0,rejectLongLoundNaN:!0,rejectLongFloats:!0,rejectNegativeZero:!0,rejectSimple:!0,rejectUndefined:!0,rejectUnsafeFloatInts:!0,rejectStringsNotNormalizedAs:`NFC`};parent;mt;ai;left;offset;count=0;children=[];depth=0;#e;#t=null;constructor(e,t,n,r){if([this.mt,this.ai,,this.offset]=e,this.left=t,this.parent=n,this.#e=r,n&&(this.depth=n.depth+1),this.mt===Y.MAP&&(this.#e.sortKeys||this.#e.rejectDuplicateKeys)&&(this.#t=[]),this.#e.rejectStreaming&&this.ai===Z.INDEFINITE)throw Error(`Streaming not supported`)}get isStreaming(){return this.left===1/0}get done(){return this.left===0}static create(e,t,n,r){let[i,a,o,s]=e;switch(i){case Y.POS_INT:case Y.NEG_INT:{if(n.rejectInts)throw Error(`Unexpected integer: ${o}`);if(n.rejectLargeNegatives&&o<-9223372036854775808n)throw Error(`Invalid 65bit negative number: ${o}`);let e=o;return n.preferBigInt?e=BigInt(e):n.convertUnsafeIntsToFloat&&e>=Xn.MIN&&e<=Xn.MAX&&(e=Number(o)),n.boxed?er(e,r.toHere(s)):e}case Y.SIMPLE_FLOAT:if(a>Z.ONE){if(typeof o==`symbol`)return o;if(n.rejectFloats)throw Error(`Decoding unwanted floating point number: ${o}`);if(n.rejectNegativeZero&&Object.is(o,-0))throw Error(`Decoding negative zero`);if(isNaN(o)){let e=r.toHere(s),t=new Lr(e);if(n.rejectLongLoundNaN){if(t.payload||e.length>3)throw Error(`Invalid NaN encoding: "${sr(e)}"`)}else if(n.keepNanPayloads&&(t.payload||t.sign===-1)){if(n.rejectLongFloats&&!t.isShortestEncoding)throw Error(`NaN should have been encoded shorter: ${o}`);return t}}if(n.rejectSubnormals&&Vr(r.toHere(s+1)),n.rejectLongFloats){let e=Oi(o,{chunkSize:9,reduceUnsafeNumbers:n.rejectUnsafeFloatInts});if(e[0]>>5!==i)throw Error(`Should have been encoded as int, not float: ${o}`);if(e.length<Ni.get(a))throw Error(`Number should have been encoded shorter: ${o}`)}if(typeof o==`number`&&n.boxed)return er(o,r.toHere(s))}else{if(n.rejectSimple&&o instanceof Ai)throw Error(`Invalid simple value: ${o}`);if(n.rejectUndefined&&o===void 0)throw Error(`Unexpected undefined`)}return o;case Y.BYTE_STRING:case Y.UTF8_STRING:if(o===1/0)return new n.ParentType(e,1/0,t,n);if(n.rejectStringsNotNormalizedAs&&typeof o==`string`){let e=o.normalize(n.rejectStringsNotNormalizedAs);if(o!==e)throw Error(`String not normalized as "${n.rejectStringsNotNormalizedAs}", got [${pr(o)}] instead of [${pr(e)}]`)}return n.boxed?er(o,r.toHere(s)):o;case Y.ARRAY:return new n.ParentType(e,o,t,n);case Y.MAP:return new n.ParentType(e,o*2,t,n);case Y.TAG:{let r=new n.ParentType(e,1,t,n);return r.children=new Q(o),r}}throw TypeError(`Invalid major type: ${i}`)}static decodeToEncodeOpts(e){return{...di,avoidInts:e.rejectInts,float64:!e.rejectLongFloats,flushToZero:e.rejectSubnormals,largeNegativeAsBigInt:e.rejectLargeNegatives,sortKeys:e.sortKeys}}push(e,t,n){if(this.children.push(e),this.#t){let r=Zn(e)||t.toHere(n);this.#t.push(r)}return--this.left}replaceLast(e,t,n){let r,i=-1/0;if(this.children instanceof Q?(i=0,r=this.children.contents,this.children.contents=e):(i=this.children.length-1,r=this.children[i],this.children[i]=e),this.#t){let r=Zn(e)||n.toHere(t.offset);this.#t[i]=r}return r}convert(e){let t;switch(this.mt){case Y.ARRAY:t=this.children;break;case Y.MAP:{let e=this.#n();if(this.#e.sortKeys){let t;for(let n of e){if(t&&this.#e.sortKeys(t,n)>=0)throw Error(`Duplicate or out of order key: "0x${n[2]}"`);t=n}}else if(this.#e.rejectDuplicateKeys){let t=new Set;for(let[n,r,i]of e){let e=sr(i);if(t.has(e))throw Error(`Duplicate key: "0x${e}"`);t.add(e)}}t=this.#e.createObject(e,this.#e);break}case Y.BYTE_STRING:return cr(this.children);case Y.UTF8_STRING:{let n=this.children.join(``);t=this.#e.boxed?er(n,e.toHere(this.offset)):n;break}case Y.TAG:t=this.children.decode(this.#e);break;default:throw TypeError(`Invalid mt on convert: ${this.mt}`)}return this.#e.saveOriginal&&t&&typeof t==`object`&&$n(t,e.toHere(this.offset)),t}#n(){let e=this.children,t=e.length;if(t%2)throw Error(`Missing map value`);let n=Array(t/2);if(this.#t)for(let r=0;r<t;r+=2)n[r>>1]=[e[r],e[r+1],this.#t[r]];else for(let r=0;r<t;r+=2)n[r>>1]=[e[r],e[r+1],Pi];return n}},Li=` `,Ri=new TextEncoder,zi=class extends Ii{close=``;quote=`"`;get isEmptyStream(){return(this.mt===Y.UTF8_STRING||this.mt===Y.BYTE_STRING)&&this.count===0}};function Bi(e,t,n,r){let i=``;if(t===Z.INDEFINITE)i+=`_`;else{if(r.diagnosticSizes===ki.NEVER)return``;{let a=r.diagnosticSizes===ki.ALWAYS;if(!a){let r=Z.ZERO;if(Object.is(n,-0))r=Z.TWO;else if(e===Y.POS_INT||e===Y.NEG_INT){let e=n<0,t=typeof n==`bigint`?1n:1,i=e?-n-t:n;r=i<=23?Number(i):i<=255?Z.ONE:i<=65535?Z.TWO:i<=4294967295?Z.FOUR:Z.EIGHT}else r=isFinite(n)?Math.fround(n)===n?zr(n)==null?Z.FOUR:Z.TWO:Z.EIGHT:Z.TWO;a=r!==t}a&&(i+=`_`,t<Z.ONE?i+=`i`:i+=String(t-24))}}return i}function Vi(e,t){let n={...Ii.defaultDecodeOptions,...t,ParentType:zi},r=new Mi(e,n),i,a,o=``;for(let e of r){let[t,s,c]=e;switch(i&&(i.count>0&&c!==Yn.BREAK&&(i.mt===Y.MAP&&i.count%2?o+=`: `:(o+=`,`,n.pretty||(o+=` `))),n.pretty&&(i.mt!==Y.MAP||i.count%2==0)&&(o+=`
2
- ${Li.repeat(i.depth+1)}`)),a=Ii.create(e,i,n,r),t){case Y.POS_INT:case Y.NEG_INT:o+=String(c),o+=Bi(t,s,c,n);break;case Y.SIMPLE_FLOAT:if(c!==Yn.BREAK)if(typeof c==`number`){let e=Object.is(c,-0)?`-0.0`:String(c);o+=e,isFinite(c)&&!/[.e]/.test(e)&&(o+=`.0`),o+=Bi(t,s,c,n)}else c instanceof Ai?(o+=`simple(`,o+=String(c.value),o+=Bi(Y.POS_INT,s,c.value,n),o+=`)`):o+=String(c);break;case Y.BYTE_STRING:c===1/0?(o+=`(_ `,a.close=`)`,a.quote=`'`):(o+=`h'`,o+=sr(c),o+=`'`,o+=Bi(Y.POS_INT,s,c.length,n));break;case Y.UTF8_STRING:c===1/0?(o+=`(_ `,a.close=`)`):(o+=JSON.stringify(c),o+=Bi(Y.POS_INT,s,Ri.encode(c).length,n));break;case Y.ARRAY:{o+=`[`;let e=Bi(Y.POS_INT,s,c,n);o+=e,e&&(o+=` `),n.pretty&&c?a.close=`
3
- ${Li.repeat(a.depth)}]`:a.close=`]`;break}case Y.MAP:{o+=`{`;let e=Bi(Y.POS_INT,s,c,n);o+=e,e&&(o+=` `),n.pretty&&c?a.close=`
4
- ${Li.repeat(a.depth)}}`:a.close=`}`;break}case Y.TAG:o+=String(c),o+=Bi(Y.POS_INT,s,c,n),o+=`(`,a.close=`)`;break}if(a===Yn.BREAK)if(i?.isStreaming)i.left=0;else throw Error(`Unexpected BREAK`);else i&&(i.count++,i.left--);for(a instanceof zi&&(i=a);i?.done;){if(i.isEmptyStream)o=o.slice(0,-3),o+=`${i.quote}${i.quote}_`;else{if(i.mt===Y.MAP&&i.count%2!=0)throw Error(`Odd streaming map size: ${i.count}`);o+=i.close}i=i.parent}}return o}var Hi=new TextDecoder,Ui=class extends Ii{depth=0;leaf=!1;value;length;[Yn.ENCODED];constructor(e,t,n,r){super(e,t,n,r),this.parent?this.depth=this.parent.depth+1:this.depth=r.initialDepth,[,,this.value,,this.length]=e}numBytes(){switch(this.ai){case Z.ONE:return 1;case Z.TWO:return 2;case Z.FOUR:return 4;case Z.EIGHT:return 8}return 0}};function Wi(e){return e instanceof Ui}function Gi(e,t){return e===1/0?`Indefinite`:t?`${e} ${t}${e!==1&&e!==1n?`s`:``}`:String(e)}function Ki(e){return``.padStart(e,` `)}function qi(e,t,n){let r=``;r+=Ki(e.depth*2);let i=Zn(e);r+=sr(i.subarray(0,1));let a=e.numBytes();a&&(r+=` `,r+=sr(i.subarray(1,a+1))),r=r.padEnd(t.minCol+1,` `),r+=`-- `,n!==void 0&&(r+=Ki(e.depth*2),n!==``&&(r+=`[${n}] `));let o=!1,[s]=e.children;switch(e.mt){case Y.POS_INT:r+=`Unsigned: ${s}`,typeof s==`bigint`&&(r+=`n`);break;case Y.NEG_INT:r+=`Negative: ${s}`,typeof s==`bigint`&&(r+=`n`);break;case Y.BYTE_STRING:r+=`Bytes (Length: ${Gi(e.length)})`;break;case Y.UTF8_STRING:r+=`UTF8 (Length: ${Gi(e.length)})`,e.length!==1/0&&(r+=`: ${JSON.stringify(s)}`);break;case Y.ARRAY:r+=`Array (Length: ${Gi(e.value,`item`)})`;break;case Y.MAP:r+=`Map (Length: ${Gi(e.value,`pair`)})`;break;case Y.TAG:{r+=`Tag #${e.value}`;let n=e.children,[a]=n.contents.children,s=new Q(n.tag,a);$n(s,i);let c=s.comment(t,e.depth);c&&(r+=`: `,r+=c),o||=s.noChildren;break}case Y.SIMPLE_FLOAT:s===Yn.BREAK?r+=`BREAK`:e.ai>Z.ONE?Object.is(s,-0)?r+=`Float: -0`:r+=`Float: ${s}`:(r+=`Simple: `,s instanceof Ai?r+=s.value:r+=s);break}if(!o)if(e.leaf){if(r+=`
5
- `,i.length>a+1){let n=Ki((e.depth+1)*2),o=rr(i);if(o?.length){o.sort((e,t)=>e[0]-t[0]||t[1]-e[1]);let s=0;for(let[c,l,u]of o)if(!(c<s)){if(s=c+l,u===`<<`){r+=Ki(t.minCol+1),r+=`--`,r+=n,r+=`<< `;let a=ar(i,c,c+l),o=rr(a);if(o){let e=o.findIndex(([e,t,n])=>e===0&&t===l&&n===`<<`);e>=0&&o.splice(e,1)}r+=Vi(a),r+=` >>
6
- `,r+=Yi(a,{initialDepth:e.depth+1,minCol:t.minCol,noPrefixHex:!0});continue}else u===`'`&&(r+=Ki(t.minCol+1),r+=`--`,r+=n,r+=`'`,r+=Hi.decode(i.subarray(c,c+l)),r+=`'
7
- `);if(c>a)for(let e=c;e<c+l;e+=8){let t=Math.min(e+8,c+l);r+=n,r+=sr(i.subarray(e,t)),r+=`
8
- `}}}else for(let e=a+1;e<i.length;e+=8)r+=n,r+=sr(i.subarray(e,e+8)),r+=`
1
+ (function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.MQTTp={}))})(this,function(e){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var t=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(e){throw n=[e],e}},n=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),r=n(((e,t)=>{var n=typeof Reflect==`object`?Reflect:null,r=n&&typeof n.apply==`function`?n.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)},i=n&&typeof n.ownKeys==`function`?n.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};function a(e){console&&console.warn&&console.warn(e)}var o=Number.isNaN||function(e){return e!==e};function s(){s.init.call(this)}t.exports=s,t.exports.once=y,s.EventEmitter=s,s.prototype._events=void 0,s.prototype._eventsCount=0,s.prototype._maxListeners=void 0;var c=10;function l(e){if(typeof e!=`function`)throw TypeError(`The "listener" argument must be of type Function. Received type `+typeof e)}Object.defineProperty(s,"defaultMaxListeners",{enumerable:!0,get:function(){return c},set:function(e){if(typeof e!=`number`||e<0||o(e))throw RangeError(`The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received `+e+`.`);c=e}}),s.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},s.prototype.setMaxListeners=function(e){if(typeof e!=`number`||e<0||o(e))throw RangeError(`The value of "n" is out of range. It must be a non-negative number. Received `+e+`.`);return this._maxListeners=e,this};function u(e){return e._maxListeners===void 0?s.defaultMaxListeners:e._maxListeners}s.prototype.getMaxListeners=function(){return u(this)},s.prototype.emit=function(e){for(var t=[],n=1;n<arguments.length;n++)t.push(arguments[n]);var i=e===`error`,a=this._events;if(a!==void 0)i&&=a.error===void 0;else if(!i)return!1;if(i){var o;if(t.length>0&&(o=t[0]),o instanceof Error)throw o;var s=Error(`Unhandled error.`+(o?` (`+o.message+`)`:``));throw s.context=o,s}var c=a[e];if(c===void 0)return!1;if(typeof c==`function`)r(c,this,t);else for(var l=c.length,u=g(c,l),n=0;n<l;++n)r(u[n],this,t);return!0};function d(e,t,n,r){var i,o,s;if(l(n),o=e._events,o===void 0?(o=e._events=Object.create(null),e._eventsCount=0):(o.newListener!==void 0&&(e.emit(`newListener`,t,n.listener?n.listener:n),o=e._events),s=o[t]),s===void 0)s=o[t]=n,++e._eventsCount;else if(typeof s==`function`?s=o[t]=r?[n,s]:[s,n]:r?s.unshift(n):s.push(n),i=u(e),i>0&&s.length>i&&!s.warned){s.warned=!0;var c=Error(`Possible EventEmitter memory leak detected. `+s.length+` `+String(t)+` listeners added. Use emitter.setMaxListeners() to increase limit`);c.name=`MaxListenersExceededWarning`,c.emitter=e,c.type=t,c.count=s.length,a(c)}return e}s.prototype.addListener=function(e,t){return d(this,e,t,!1)},s.prototype.on=s.prototype.addListener,s.prototype.prependListener=function(e,t){return d(this,e,t,!0)};function f(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function p(e,t,n){var r={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},i=f.bind(r);return i.listener=n,r.wrapFn=i,i}s.prototype.once=function(e,t){return l(t),this.on(e,p(this,e,t)),this},s.prototype.prependOnceListener=function(e,t){return l(t),this.prependListener(e,p(this,e,t)),this},s.prototype.removeListener=function(e,t){var n,r,i,a,o;if(l(t),r=this._events,r===void 0||(n=r[e],n===void 0))return this;if(n===t||n.listener===t)--this._eventsCount===0?this._events=Object.create(null):(delete r[e],r.removeListener&&this.emit(`removeListener`,e,n.listener||t));else if(typeof n!=`function`){for(i=-1,a=n.length-1;a>=0;a--)if(n[a]===t||n[a].listener===t){o=n[a].listener,i=a;break}if(i<0)return this;i===0?n.shift():_(n,i),n.length===1&&(r[e]=n[0]),r.removeListener!==void 0&&this.emit(`removeListener`,e,o||t)}return this},s.prototype.off=s.prototype.removeListener,s.prototype.removeAllListeners=function(e){var t,n=this._events,r;if(n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[e]),this;if(arguments.length===0){var i=Object.keys(n),a;for(r=0;r<i.length;++r)a=i[r],a!==`removeListener`&&this.removeAllListeners(a);return this.removeAllListeners(`removeListener`),this._events=Object.create(null),this._eventsCount=0,this}if(t=n[e],typeof t==`function`)this.removeListener(e,t);else if(t!==void 0)for(r=t.length-1;r>=0;r--)this.removeListener(e,t[r]);return this};function m(e,t,n){var r=e._events;if(r===void 0)return[];var i=r[t];return i===void 0?[]:typeof i==`function`?n?[i.listener||i]:[i]:n?v(i):g(i,i.length)}s.prototype.listeners=function(e){return m(this,e,!0)},s.prototype.rawListeners=function(e){return m(this,e,!1)},s.listenerCount=function(e,t){return typeof e.listenerCount==`function`?e.listenerCount(t):h.call(e,t)},s.prototype.listenerCount=h;function h(e){var t=this._events;if(t!==void 0){var n=t[e];if(typeof n==`function`)return 1;if(n!==void 0)return n.length}return 0}s.prototype.eventNames=function(){return this._eventsCount>0?i(this._events):[]};function g(e,t){for(var n=Array(t),r=0;r<t;++r)n[r]=e[r];return n}function _(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}function v(e){for(var t=Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}function y(e,t){return new Promise(function(n,r){function i(n){e.removeListener(t,a),r(n)}function a(){typeof e.removeListener==`function`&&e.removeListener(`error`,i),n([].slice.call(arguments))}x(e,t,a,{once:!0}),t!==`error`&&b(e,i,{once:!0})})}function b(e,t,n){typeof e.on==`function`&&x(e,`error`,t,n)}function x(e,t,n,r){if(typeof e.on==`function`)r.once?e.once(t,n):e.on(t,n);else if(typeof e.addEventListener==`function`)e.addEventListener(t,function i(a){r.once&&e.removeEventListener(t,i),n(a)});else throw TypeError(`The "emitter" argument must be of type EventEmitter. Received type `+typeof e)}})),i=n(((e,t)=>{t.exports=typeof Object.create==`function`?function(e,t){t&&(e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}}))}:function(e,t){if(t){e.super_=t;var n=function(){};n.prototype=t.prototype,e.prototype=new n,e.prototype.constructor=e}}})),a,o=t((()=>{a=globalThis||self}));function s(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,`default`)?e.default:e}function c(){throw Error(`setTimeout has not been defined`)}function l(){throw Error(`clearTimeout has not been defined`)}function u(e){if(v===setTimeout)return setTimeout(e,0);if((v===c||!v)&&setTimeout)return v=setTimeout,setTimeout(e,0);try{return v(e,0)}catch{try{return v.call(null,e,0)}catch{return v.call(this,e,0)}}}function d(e){if(y===clearTimeout)return clearTimeout(e);if((y===l||!y)&&clearTimeout)return y=clearTimeout,clearTimeout(e);try{return y(e)}catch{try{return y.call(null,e)}catch{return y.call(this,e)}}}function f(){!x||!S||(x=!1,S.length?b=S.concat(b):C=-1,b.length&&p())}function p(){if(!x){var e=u(f);x=!0;for(var t=b.length;t;){for(S=b,b=[];++C<t;)S&&S[C].run();C=-1,t=b.length}S=null,x=!1,d(e)}}function m(e,t){this.fun=e,this.array=t}function h(){}var g,_,v,y,b,x,S,C,w,T,E=t((()=>{g={exports:{}},_=g.exports={},(function(){try{v=typeof setTimeout==`function`?setTimeout:c}catch{v=c}try{y=typeof clearTimeout==`function`?clearTimeout:l}catch{y=l}})(),b=[],x=!1,C=-1,_.nextTick=function(e){var t=Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];b.push(new m(e,t)),b.length===1&&!x&&u(p)},m.prototype.run=function(){this.fun.apply(null,this.array)},_.title=`browser`,_.browser=!0,_.env={},_.argv=[],_.version=``,_.versions={},_.on=h,_.addListener=h,_.once=h,_.off=h,_.removeListener=h,_.removeAllListeners=h,_.emit=h,_.prependListener=h,_.prependOnceListener=h,_.listeners=function(e){return[]},_.binding=function(e){throw Error(`process.binding is not supported`)},_.cwd=function(){return`/`},_.chdir=function(e){throw Error(`process.chdir is not supported`)},_.umask=function(){return 0},w=g.exports,T=s(w)})),D=n(((e,t)=>{t.exports=r().EventEmitter})),O=n((e=>{Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var t={},n={};n.byteLength=u,n.toByteArray=f,n.fromByteArray=h;for(var r=[],i=[],a=typeof Uint8Array<`u`?Uint8Array:Array,o=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`,s=0,c=o.length;s<c;++s)r[s]=o[s],i[o.charCodeAt(s)]=s;i[45]=62,i[95]=63;function l(e){var t=e.length;if(t%4>0)throw Error(`Invalid string. Length must be a multiple of 4`);var n=e.indexOf(`=`);n===-1&&(n=t);var r=n===t?0:4-n%4;return[n,r]}function u(e){var t=l(e),n=t[0],r=t[1];return(n+r)*3/4-r}function d(e,t,n){return(t+n)*3/4-n}function f(e){var t,n=l(e),r=n[0],o=n[1],s=new a(d(e,r,o)),c=0,u=o>0?r-4:r,f;for(f=0;f<u;f+=4)t=i[e.charCodeAt(f)]<<18|i[e.charCodeAt(f+1)]<<12|i[e.charCodeAt(f+2)]<<6|i[e.charCodeAt(f+3)],s[c++]=t>>16&255,s[c++]=t>>8&255,s[c++]=t&255;return o===2&&(t=i[e.charCodeAt(f)]<<2|i[e.charCodeAt(f+1)]>>4,s[c++]=t&255),o===1&&(t=i[e.charCodeAt(f)]<<10|i[e.charCodeAt(f+1)]<<4|i[e.charCodeAt(f+2)]>>2,s[c++]=t>>8&255,s[c++]=t&255),s}function p(e){return r[e>>18&63]+r[e>>12&63]+r[e>>6&63]+r[e&63]}function m(e,t,n){for(var r,i=[],a=t;a<n;a+=3)r=(e[a]<<16&16711680)+(e[a+1]<<8&65280)+(e[a+2]&255),i.push(p(r));return i.join(``)}function h(e){for(var t,n=e.length,i=n%3,a=[],o=16383,s=0,c=n-i;s<c;s+=o)a.push(m(e,s,s+o>c?c:s+o));return i===1?(t=e[n-1],a.push(r[t>>2]+r[t<<4&63]+`==`)):i===2&&(t=(e[n-2]<<8)+e[n-1],a.push(r[t>>10]+r[t>>4&63]+r[t<<2&63]+`=`)),a.join(``)}var g={};g.read=function(e,t,n,r,i){var a,o,s=i*8-r-1,c=(1<<s)-1,l=c>>1,u=-7,d=n?i-1:0,f=n?-1:1,p=e[t+d];for(d+=f,a=p&(1<<-u)-1,p>>=-u,u+=s;u>0;a=a*256+e[t+d],d+=f,u-=8);for(o=a&(1<<-u)-1,a>>=-u,u+=r;u>0;o=o*256+e[t+d],d+=f,u-=8);if(a===0)a=1-l;else if(a===c)return o?NaN:(p?-1:1)*(1/0);else o+=2**r,a-=l;return(p?-1:1)*o*2**(a-r)},g.write=function(e,t,n,r,i,a){var o,s,c,l=a*8-i-1,u=(1<<l)-1,d=u>>1,f=i===23?2**-24-2**-77:0,p=r?0:a-1,m=r?1:-1,h=+(t<0||t===0&&1/t<0);for(t=Math.abs(t),isNaN(t)||t===1/0?(s=+!!isNaN(t),o=u):(o=Math.floor(Math.log(t)/Math.LN2),t*(c=2**-o)<1&&(o--,c*=2),o+d>=1?t+=f/c:t+=f*2**(1-d),t*c>=2&&(o++,c/=2),o+d>=u?(s=0,o=u):o+d>=1?(s=(t*c-1)*2**i,o+=d):(s=t*2**(d-1)*2**i,o=0));i>=8;e[n+p]=s&255,p+=m,s/=256,i-=8);for(o=o<<i|s,l+=i;l>0;e[n+p]=o&255,p+=m,o/=256,l-=8);e[n+p-m]|=h*128},(function(e){let t=n,r=g,i=typeof Symbol==`function`&&typeof Symbol.for==`function`?Symbol.for(`nodejs.util.inspect.custom`):null;e.Buffer=d,e.SlowBuffer=C,e.INSPECT_MAX_BYTES=50;let a=2147483647;e.kMaxLength=a;let{Uint8Array:o,ArrayBuffer:s,SharedArrayBuffer:c}=globalThis;d.TYPED_ARRAY_SUPPORT=l(),!d.TYPED_ARRAY_SUPPORT&&typeof console<`u`&&typeof console.error==`function`&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function l(){try{let e=new o(1),t={foo:function(){return 42}};return Object.setPrototypeOf(t,o.prototype),Object.setPrototypeOf(e,t),e.foo()===42}catch{return!1}}Object.defineProperty(d.prototype,"parent",{enumerable:!0,get:function(){if(d.isBuffer(this))return this.buffer}}),Object.defineProperty(d.prototype,"offset",{enumerable:!0,get:function(){if(d.isBuffer(this))return this.byteOffset}});function u(e){if(e>a)throw RangeError(`The value "`+e+`" is invalid for option "size"`);let t=new o(e);return Object.setPrototypeOf(t,d.prototype),t}function d(e,t,n){if(typeof e==`number`){if(typeof t==`string`)throw TypeError(`The "string" argument must be of type string. Received type number`);return h(e)}return f(e,t,n)}d.poolSize=8192;function f(e,t,n){if(typeof e==`string`)return _(e,t);if(s.isView(e))return y(e);if(e==null)throw TypeError(`The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type `+typeof e);if(xe(e,s)||e&&xe(e.buffer,s)||c!==void 0&&(xe(e,c)||e&&xe(e.buffer,c)))return b(e,t,n);if(typeof e==`number`)throw TypeError(`The "value" argument must not be of type number. Received type number`);let r=e.valueOf&&e.valueOf();if(r!=null&&r!==e)return d.from(r,t,n);let i=x(e);if(i)return i;if(typeof Symbol<`u`&&Symbol.toPrimitive!=null&&typeof e[Symbol.toPrimitive]==`function`)return d.from(e[Symbol.toPrimitive](`string`),t,n);throw TypeError(`The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type `+typeof e)}d.from=function(e,t,n){return f(e,t,n)},Object.setPrototypeOf(d.prototype,o.prototype),Object.setPrototypeOf(d,o);function p(e){if(typeof e!=`number`)throw TypeError(`"size" argument must be of type number`);if(e<0)throw RangeError(`The value "`+e+`" is invalid for option "size"`)}function m(e,t,n){return p(e),e<=0||t===void 0?u(e):typeof n==`string`?u(e).fill(t,n):u(e).fill(t)}d.alloc=function(e,t,n){return m(e,t,n)};function h(e){return p(e),u(e<0?0:S(e)|0)}d.allocUnsafe=function(e){return h(e)},d.allocUnsafeSlow=function(e){return h(e)};function _(e,t){if((typeof t!=`string`||t===``)&&(t=`utf8`),!d.isEncoding(t))throw TypeError(`Unknown encoding: `+t);let n=w(e,t)|0,r=u(n),i=r.write(e,t);return i!==n&&(r=r.slice(0,i)),r}function v(e){let t=e.length<0?0:S(e.length)|0,n=u(t);for(let r=0;r<t;r+=1)n[r]=e[r]&255;return n}function y(e){if(xe(e,o)){let t=new o(e);return b(t.buffer,t.byteOffset,t.byteLength)}return v(e)}function b(e,t,n){if(t<0||e.byteLength<t)throw RangeError(`"offset" is outside of buffer bounds`);if(e.byteLength<t+(n||0))throw RangeError(`"length" is outside of buffer bounds`);let r;return r=t===void 0&&n===void 0?new o(e):n===void 0?new o(e,t):new o(e,t,n),Object.setPrototypeOf(r,d.prototype),r}function x(e){if(d.isBuffer(e)){let t=S(e.length)|0,n=u(t);return n.length===0||e.copy(n,0,0,t),n}if(e.length!==void 0)return typeof e.length!=`number`||Se(e.length)?u(0):v(e);if(e.type===`Buffer`&&Array.isArray(e.data))return v(e.data)}function S(e){if(e>=a)throw RangeError(`Attempt to allocate Buffer larger than maximum size: 0x`+a.toString(16)+` bytes`);return e|0}function C(e){return+e!=e&&(e=0),d.alloc(+e)}d.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==d.prototype},d.compare=function(e,t){if(xe(e,o)&&(e=d.from(e,e.offset,e.byteLength)),xe(t,o)&&(t=d.from(t,t.offset,t.byteLength)),!d.isBuffer(e)||!d.isBuffer(t))throw TypeError(`The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array`);if(e===t)return 0;let n=e.length,r=t.length;for(let i=0,a=Math.min(n,r);i<a;++i)if(e[i]!==t[i]){n=e[i],r=t[i];break}return n<r?-1:+(r<n)},d.isEncoding=function(e){switch(String(e).toLowerCase()){case`hex`:case`utf8`:case`utf-8`:case`ascii`:case`latin1`:case`binary`:case`base64`:case`ucs2`:case`ucs-2`:case`utf16le`:case`utf-16le`:return!0;default:return!1}},d.concat=function(e,t){if(!Array.isArray(e))throw TypeError(`"list" argument must be an Array of Buffers`);if(e.length===0)return d.alloc(0);let n;if(t===void 0)for(t=0,n=0;n<e.length;++n)t+=e[n].length;let r=d.allocUnsafe(t),i=0;for(n=0;n<e.length;++n){let t=e[n];if(xe(t,o))i+t.length>r.length?(d.isBuffer(t)||(t=d.from(t)),t.copy(r,i)):o.prototype.set.call(r,t,i);else if(d.isBuffer(t))t.copy(r,i);else throw TypeError(`"list" argument must be an Array of Buffers`);i+=t.length}return r};function w(e,t){if(d.isBuffer(e))return e.length;if(s.isView(e)||xe(e,s))return e.byteLength;if(typeof e!=`string`)throw TypeError(`The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type `+typeof e);let n=e.length,r=arguments.length>2&&arguments[2]===!0;if(!r&&n===0)return 0;let i=!1;for(;;)switch(t){case`ascii`:case`latin1`:case`binary`:return n;case`utf8`:case`utf-8`:return _e(e).length;case`ucs2`:case`ucs-2`:case`utf16le`:case`utf-16le`:return n*2;case`hex`:return n>>>1;case`base64`:return be(e).length;default:if(i)return r?-1:_e(e).length;t=(``+t).toLowerCase(),i=!0}}d.byteLength=w;function T(e,t,n){let r=!1;if((t===void 0||t<0)&&(t=0),t>this.length||((n===void 0||n>this.length)&&(n=this.length),n<=0)||(n>>>=0,t>>>=0,n<=t))return``;for(e||=`utf8`;;)switch(e){case`hex`:return P(this,t,n);case`utf8`:case`utf-8`:return M(this,t,n);case`ascii`:return ie(this,t,n);case`latin1`:case`binary`:return ae(this,t,n);case`base64`:return ne(this,t,n);case`ucs2`:case`ucs-2`:case`utf16le`:case`utf-16le`:return F(this,t,n);default:if(r)throw TypeError(`Unknown encoding: `+e);e=(e+``).toLowerCase(),r=!0}}d.prototype._isBuffer=!0;function E(e,t,n){let r=e[t];e[t]=e[n],e[n]=r}d.prototype.swap16=function(){let e=this.length;if(e%2!=0)throw RangeError(`Buffer size must be a multiple of 16-bits`);for(let t=0;t<e;t+=2)E(this,t,t+1);return this},d.prototype.swap32=function(){let e=this.length;if(e%4!=0)throw RangeError(`Buffer size must be a multiple of 32-bits`);for(let t=0;t<e;t+=4)E(this,t,t+3),E(this,t+1,t+2);return this},d.prototype.swap64=function(){let e=this.length;if(e%8!=0)throw RangeError(`Buffer size must be a multiple of 64-bits`);for(let t=0;t<e;t+=8)E(this,t,t+7),E(this,t+1,t+6),E(this,t+2,t+5),E(this,t+3,t+4);return this},d.prototype.toString=function(){let e=this.length;return e===0?``:arguments.length===0?M(this,0,e):T.apply(this,arguments)},d.prototype.toLocaleString=d.prototype.toString,d.prototype.equals=function(e){if(!d.isBuffer(e))throw TypeError(`Argument must be a Buffer`);return this===e||d.compare(this,e)===0},d.prototype.inspect=function(){let t=``,n=e.INSPECT_MAX_BYTES;return t=this.toString(`hex`,0,n).replace(/(.{2})/g,`$1 `).trim(),this.length>n&&(t+=` ... `),`<Buffer `+t+`>`},i&&(d.prototype[i]=d.prototype.inspect),d.prototype.compare=function(e,t,n,r,i){if(xe(e,o)&&(e=d.from(e,e.offset,e.byteLength)),!d.isBuffer(e))throw TypeError(`The "target" argument must be one of type Buffer or Uint8Array. Received type `+typeof e);if(t===void 0&&(t=0),n===void 0&&(n=e?e.length:0),r===void 0&&(r=0),i===void 0&&(i=this.length),t<0||n>e.length||r<0||i>this.length)throw RangeError(`out of range index`);if(r>=i&&t>=n)return 0;if(r>=i)return-1;if(t>=n)return 1;if(t>>>=0,n>>>=0,r>>>=0,i>>>=0,this===e)return 0;let a=i-r,s=n-t,c=Math.min(a,s),l=this.slice(r,i),u=e.slice(t,n);for(let e=0;e<c;++e)if(l[e]!==u[e]){a=l[e],s=u[e];break}return a<s?-1:+(s<a)};function D(e,t,n,r,i){if(e.length===0)return-1;if(typeof n==`string`?(r=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),n=+n,Se(n)&&(n=i?0:e.length-1),n<0&&(n=e.length+n),n>=e.length){if(i)return-1;n=e.length-1}else if(n<0){if(i)n=0;else return-1}if(typeof t==`string`&&(t=d.from(t,r)),d.isBuffer(t))return t.length===0?-1:O(e,t,n,r,i);if(typeof t==`number`)return t&=255,typeof o.prototype.indexOf==`function`?i?o.prototype.indexOf.call(e,t,n):o.prototype.lastIndexOf.call(e,t,n):O(e,[t],n,r,i);throw TypeError(`val must be string, number or Buffer`)}function O(e,t,n,r,i){let a=1,o=e.length,s=t.length;if(r!==void 0&&(r=String(r).toLowerCase(),r===`ucs2`||r===`ucs-2`||r===`utf16le`||r===`utf-16le`)){if(e.length<2||t.length<2)return-1;a=2,o/=2,s/=2,n/=2}function c(e,t){return a===1?e[t]:e.readUInt16BE(t*a)}let l;if(i){let r=-1;for(l=n;l<o;l++)if(c(e,l)===c(t,r===-1?0:l-r)){if(r===-1&&(r=l),l-r+1===s)return r*a}else r!==-1&&(l-=l-r),r=-1}else for(n+s>o&&(n=o-s),l=n;l>=0;l--){let n=!0;for(let r=0;r<s;r++)if(c(e,l+r)!==c(t,r)){n=!1;break}if(n)return l}return-1}d.prototype.includes=function(e,t,n){return this.indexOf(e,t,n)!==-1},d.prototype.indexOf=function(e,t,n){return D(this,e,t,n,!0)},d.prototype.lastIndexOf=function(e,t,n){return D(this,e,t,n,!1)};function k(e,t,n,r){n=Number(n)||0;let i=e.length-n;r?(r=Number(r),r>i&&(r=i)):r=i;let a=t.length;r>a/2&&(r=a/2);let o;for(o=0;o<r;++o){let r=parseInt(t.substr(o*2,2),16);if(Se(r))return o;e[n+o]=r}return o}function A(e,t,n,r){return V(_e(t,e.length-n),e,n,r)}function ee(e,t,n,r){return V(ve(t),e,n,r)}function j(e,t,n,r){return V(be(t),e,n,r)}function te(e,t,n,r){return V(ye(t,e.length-n),e,n,r)}d.prototype.write=function(e,t,n,r){if(t===void 0)r=`utf8`,n=this.length,t=0;else if(n===void 0&&typeof t==`string`)r=t,n=this.length,t=0;else if(isFinite(t))t>>>=0,isFinite(n)?(n>>>=0,r===void 0&&(r=`utf8`)):(r=n,n=void 0);else throw Error(`Buffer.write(string, encoding, offset[, length]) is no longer supported`);let i=this.length-t;if((n===void 0||n>i)&&(n=i),e.length>0&&(n<0||t<0)||t>this.length)throw RangeError(`Attempt to write outside buffer bounds`);r||=`utf8`;let a=!1;for(;;)switch(r){case`hex`:return k(this,e,t,n);case`utf8`:case`utf-8`:return A(this,e,t,n);case`ascii`:case`latin1`:case`binary`:return ee(this,e,t,n);case`base64`:return j(this,e,t,n);case`ucs2`:case`ucs-2`:case`utf16le`:case`utf-16le`:return te(this,e,t,n);default:if(a)throw TypeError(`Unknown encoding: `+r);r=(``+r).toLowerCase(),a=!0}},d.prototype.toJSON=function(){return{type:`Buffer`,data:Array.prototype.slice.call(this._arr||this,0)}};function ne(e,n,r){return n===0&&r===e.length?t.fromByteArray(e):t.fromByteArray(e.slice(n,r))}function M(e,t,n){n=Math.min(e.length,n);let r=[],i=t;for(;i<n;){let t=e[i],a=null,o=t>239?4:t>223?3:t>191?2:1;if(i+o<=n){let n,r,s,c;switch(o){case 1:t<128&&(a=t);break;case 2:n=e[i+1],(n&192)==128&&(c=(t&31)<<6|n&63,c>127&&(a=c));break;case 3:n=e[i+1],r=e[i+2],(n&192)==128&&(r&192)==128&&(c=(t&15)<<12|(n&63)<<6|r&63,c>2047&&(c<55296||c>57343)&&(a=c));break;case 4:n=e[i+1],r=e[i+2],s=e[i+3],(n&192)==128&&(r&192)==128&&(s&192)==128&&(c=(t&15)<<18|(n&63)<<12|(r&63)<<6|s&63,c>65535&&c<1114112&&(a=c))}}a===null?(a=65533,o=1):a>65535&&(a-=65536,r.push(a>>>10&1023|55296),a=56320|a&1023),r.push(a),i+=o}return N(r)}let re=4096;function N(e){let t=e.length;if(t<=re)return String.fromCharCode.apply(String,e);let n=``,r=0;for(;r<t;)n+=String.fromCharCode.apply(String,e.slice(r,r+=re));return n}function ie(e,t,n){let r=``;n=Math.min(e.length,n);for(let i=t;i<n;++i)r+=String.fromCharCode(e[i]&127);return r}function ae(e,t,n){let r=``;n=Math.min(e.length,n);for(let i=t;i<n;++i)r+=String.fromCharCode(e[i]);return r}function P(e,t,n){let r=e.length;(!t||t<0)&&(t=0),(!n||n<0||n>r)&&(n=r);let i=``;for(let r=t;r<n;++r)i+=Ce[e[r]];return i}function F(e,t,n){let r=e.slice(t,n),i=``;for(let e=0;e<r.length-1;e+=2)i+=String.fromCharCode(r[e]+r[e+1]*256);return i}d.prototype.slice=function(e,t){let n=this.length;e=~~e,t=t===void 0?n:~~t,e<0?(e+=n,e<0&&(e=0)):e>n&&(e=n),t<0?(t+=n,t<0&&(t=0)):t>n&&(t=n),t<e&&(t=e);let r=this.subarray(e,t);return Object.setPrototypeOf(r,d.prototype),r};function I(e,t,n){if(e%1!=0||e<0)throw RangeError(`offset is not uint`);if(e+t>n)throw RangeError(`Trying to access beyond buffer length`)}d.prototype.readUintLE=d.prototype.readUIntLE=function(e,t,n){e>>>=0,t>>>=0,n||I(e,t,this.length);let r=this[e],i=1,a=0;for(;++a<t&&(i*=256);)r+=this[e+a]*i;return r},d.prototype.readUintBE=d.prototype.readUIntBE=function(e,t,n){e>>>=0,t>>>=0,n||I(e,t,this.length);let r=this[e+--t],i=1;for(;t>0&&(i*=256);)r+=this[e+--t]*i;return r},d.prototype.readUint8=d.prototype.readUInt8=function(e,t){return e>>>=0,t||I(e,1,this.length),this[e]},d.prototype.readUint16LE=d.prototype.readUInt16LE=function(e,t){return e>>>=0,t||I(e,2,this.length),this[e]|this[e+1]<<8},d.prototype.readUint16BE=d.prototype.readUInt16BE=function(e,t){return e>>>=0,t||I(e,2,this.length),this[e]<<8|this[e+1]},d.prototype.readUint32LE=d.prototype.readUInt32LE=function(e,t){return e>>>=0,t||I(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216},d.prototype.readUint32BE=d.prototype.readUInt32BE=function(e,t){return e>>>=0,t||I(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])},d.prototype.readBigUInt64LE=H(function(e){e>>>=0,pe(e,`offset`);let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&me(e,this.length-8);let r=t+this[++e]*256+this[++e]*2**16+this[++e]*2**24,i=this[++e]+this[++e]*256+this[++e]*2**16+n*2**24;return BigInt(r)+(BigInt(i)<<BigInt(32))}),d.prototype.readBigUInt64BE=H(function(e){e>>>=0,pe(e,`offset`);let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&me(e,this.length-8);let r=t*2**24+this[++e]*2**16+this[++e]*256+this[++e],i=this[++e]*2**24+this[++e]*2**16+this[++e]*256+n;return(BigInt(r)<<BigInt(32))+BigInt(i)}),d.prototype.readIntLE=function(e,t,n){e>>>=0,t>>>=0,n||I(e,t,this.length);let r=this[e],i=1,a=0;for(;++a<t&&(i*=256);)r+=this[e+a]*i;return i*=128,r>=i&&(r-=2**(8*t)),r},d.prototype.readIntBE=function(e,t,n){e>>>=0,t>>>=0,n||I(e,t,this.length);let r=t,i=1,a=this[e+--r];for(;r>0&&(i*=256);)a+=this[e+--r]*i;return i*=128,a>=i&&(a-=2**(8*t)),a},d.prototype.readInt8=function(e,t){return e>>>=0,t||I(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]},d.prototype.readInt16LE=function(e,t){e>>>=0,t||I(e,2,this.length);let n=this[e]|this[e+1]<<8;return n&32768?n|4294901760:n},d.prototype.readInt16BE=function(e,t){e>>>=0,t||I(e,2,this.length);let n=this[e+1]|this[e]<<8;return n&32768?n|4294901760:n},d.prototype.readInt32LE=function(e,t){return e>>>=0,t||I(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},d.prototype.readInt32BE=function(e,t){return e>>>=0,t||I(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},d.prototype.readBigInt64LE=H(function(e){e>>>=0,pe(e,`offset`);let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&me(e,this.length-8);let r=this[e+4]+this[e+5]*256+this[e+6]*2**16+(n<<24);return(BigInt(r)<<BigInt(32))+BigInt(t+this[++e]*256+this[++e]*2**16+this[++e]*2**24)}),d.prototype.readBigInt64BE=H(function(e){e>>>=0,pe(e,`offset`);let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&me(e,this.length-8);let r=(t<<24)+this[++e]*2**16+this[++e]*256+this[++e];return(BigInt(r)<<BigInt(32))+BigInt(this[++e]*2**24+this[++e]*2**16+this[++e]*256+n)}),d.prototype.readFloatLE=function(e,t){return e>>>=0,t||I(e,4,this.length),r.read(this,e,!0,23,4)},d.prototype.readFloatBE=function(e,t){return e>>>=0,t||I(e,4,this.length),r.read(this,e,!1,23,4)},d.prototype.readDoubleLE=function(e,t){return e>>>=0,t||I(e,8,this.length),r.read(this,e,!0,52,8)},d.prototype.readDoubleBE=function(e,t){return e>>>=0,t||I(e,8,this.length),r.read(this,e,!1,52,8)};function L(e,t,n,r,i,a){if(!d.isBuffer(e))throw TypeError(`"buffer" argument must be a Buffer instance`);if(t>i||t<a)throw RangeError(`"value" argument is out of bounds`);if(n+r>e.length)throw RangeError(`Index out of range`)}d.prototype.writeUintLE=d.prototype.writeUIntLE=function(e,t,n,r){if(e=+e,t>>>=0,n>>>=0,!r){let r=2**(8*n)-1;L(this,e,t,n,r,0)}let i=1,a=0;for(this[t]=e&255;++a<n&&(i*=256);)this[t+a]=e/i&255;return t+n},d.prototype.writeUintBE=d.prototype.writeUIntBE=function(e,t,n,r){if(e=+e,t>>>=0,n>>>=0,!r){let r=2**(8*n)-1;L(this,e,t,n,r,0)}let i=n-1,a=1;for(this[t+i]=e&255;--i>=0&&(a*=256);)this[t+i]=e/a&255;return t+n},d.prototype.writeUint8=d.prototype.writeUInt8=function(e,t,n){return e=+e,t>>>=0,n||L(this,e,t,1,255,0),this[t]=e&255,t+1},d.prototype.writeUint16LE=d.prototype.writeUInt16LE=function(e,t,n){return e=+e,t>>>=0,n||L(this,e,t,2,65535,0),this[t]=e&255,this[t+1]=e>>>8,t+2},d.prototype.writeUint16BE=d.prototype.writeUInt16BE=function(e,t,n){return e=+e,t>>>=0,n||L(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=e&255,t+2},d.prototype.writeUint32LE=d.prototype.writeUInt32LE=function(e,t,n){return e=+e,t>>>=0,n||L(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=e&255,t+4},d.prototype.writeUint32BE=d.prototype.writeUInt32BE=function(e,t,n){return e=+e,t>>>=0,n||L(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e&255,t+4};function oe(e,t,n,r,i){fe(t,r,i,e,n,7);let a=Number(t&BigInt(4294967295));e[n++]=a,a>>=8,e[n++]=a,a>>=8,e[n++]=a,a>>=8,e[n++]=a;let o=Number(t>>BigInt(32)&BigInt(4294967295));return e[n++]=o,o>>=8,e[n++]=o,o>>=8,e[n++]=o,o>>=8,e[n++]=o,n}function se(e,t,n,r,i){fe(t,r,i,e,n,7);let a=Number(t&BigInt(4294967295));e[n+7]=a,a>>=8,e[n+6]=a,a>>=8,e[n+5]=a,a>>=8,e[n+4]=a;let o=Number(t>>BigInt(32)&BigInt(4294967295));return e[n+3]=o,o>>=8,e[n+2]=o,o>>=8,e[n+1]=o,o>>=8,e[n]=o,n+8}d.prototype.writeBigUInt64LE=H(function(e,t=0){return oe(this,e,t,BigInt(0),BigInt(`0xffffffffffffffff`))}),d.prototype.writeBigUInt64BE=H(function(e,t=0){return se(this,e,t,BigInt(0),BigInt(`0xffffffffffffffff`))}),d.prototype.writeIntLE=function(e,t,n,r){if(e=+e,t>>>=0,!r){let r=2**(8*n-1);L(this,e,t,n,r-1,-r)}let i=0,a=1,o=0;for(this[t]=e&255;++i<n&&(a*=256);)e<0&&o===0&&this[t+i-1]!==0&&(o=1),this[t+i]=(e/a>>0)-o&255;return t+n},d.prototype.writeIntBE=function(e,t,n,r){if(e=+e,t>>>=0,!r){let r=2**(8*n-1);L(this,e,t,n,r-1,-r)}let i=n-1,a=1,o=0;for(this[t+i]=e&255;--i>=0&&(a*=256);)e<0&&o===0&&this[t+i+1]!==0&&(o=1),this[t+i]=(e/a>>0)-o&255;return t+n},d.prototype.writeInt8=function(e,t,n){return e=+e,t>>>=0,n||L(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=e&255,t+1},d.prototype.writeInt16LE=function(e,t,n){return e=+e,t>>>=0,n||L(this,e,t,2,32767,-32768),this[t]=e&255,this[t+1]=e>>>8,t+2},d.prototype.writeInt16BE=function(e,t,n){return e=+e,t>>>=0,n||L(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=e&255,t+2},d.prototype.writeInt32LE=function(e,t,n){return e=+e,t>>>=0,n||L(this,e,t,4,2147483647,-2147483648),this[t]=e&255,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4},d.prototype.writeInt32BE=function(e,t,n){return e=+e,t>>>=0,n||L(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e&255,t+4},d.prototype.writeBigInt64LE=H(function(e,t=0){return oe(this,e,t,-BigInt(`0x8000000000000000`),BigInt(`0x7fffffffffffffff`))}),d.prototype.writeBigInt64BE=H(function(e,t=0){return se(this,e,t,-BigInt(`0x8000000000000000`),BigInt(`0x7fffffffffffffff`))});function ce(e,t,n,r,i,a){if(n+r>e.length||n<0)throw RangeError(`Index out of range`)}function le(e,t,n,i,a){return t=+t,n>>>=0,a||ce(e,t,n,4),r.write(e,t,n,i,23,4),n+4}d.prototype.writeFloatLE=function(e,t,n){return le(this,e,t,!0,n)},d.prototype.writeFloatBE=function(e,t,n){return le(this,e,t,!1,n)};function ue(e,t,n,i,a){return t=+t,n>>>=0,a||ce(e,t,n,8),r.write(e,t,n,i,52,8),n+8}d.prototype.writeDoubleLE=function(e,t,n){return ue(this,e,t,!0,n)},d.prototype.writeDoubleBE=function(e,t,n){return ue(this,e,t,!1,n)},d.prototype.copy=function(e,t,n,r){if(!d.isBuffer(e))throw TypeError(`argument should be a Buffer`);if(n||=0,!r&&r!==0&&(r=this.length),t>=e.length&&(t=e.length),t||=0,r>0&&r<n&&(r=n),r===n||e.length===0||this.length===0)return 0;if(t<0)throw RangeError(`targetStart out of bounds`);if(n<0||n>=this.length)throw RangeError(`Index out of range`);if(r<0)throw RangeError(`sourceEnd out of bounds`);r>this.length&&(r=this.length),e.length-t<r-n&&(r=e.length-t+n);let i=r-n;return this===e&&typeof o.prototype.copyWithin==`function`?this.copyWithin(t,n,r):o.prototype.set.call(e,this.subarray(n,r),t),i},d.prototype.fill=function(e,t,n,r){if(typeof e==`string`){if(typeof t==`string`?(r=t,t=0,n=this.length):typeof n==`string`&&(r=n,n=this.length),r!==void 0&&typeof r!=`string`)throw TypeError(`encoding must be a string`);if(typeof r==`string`&&!d.isEncoding(r))throw TypeError(`Unknown encoding: `+r);if(e.length===1){let t=e.charCodeAt(0);(r===`utf8`&&t<128||r===`latin1`)&&(e=t)}}else typeof e==`number`?e&=255:typeof e==`boolean`&&(e=Number(e));if(t<0||this.length<t||this.length<n)throw RangeError(`Out of range index`);if(n<=t)return this;t>>>=0,n=n===void 0?this.length:n>>>0,e||=0;let i;if(typeof e==`number`)for(i=t;i<n;++i)this[i]=e;else{let a=d.isBuffer(e)?e:d.from(e,r),o=a.length;if(o===0)throw TypeError(`The value "`+e+`" is invalid for argument "value"`);for(i=0;i<n-t;++i)this[i+t]=a[i%o]}return this};let R={};function de(e,t,n){R[e]=class extends n{constructor(){super(),Object.defineProperty(this,"message",{value:t.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${e}]`,this.stack,delete this.name}get code(){return e}set code(e){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:e,writable:!0})}toString(){return`${this.name} [${e}]: ${this.message}`}}}de(`ERR_BUFFER_OUT_OF_BOUNDS`,function(e){return e?`${e} is outside of buffer bounds`:`Attempt to access memory outside buffer bounds`},RangeError),de(`ERR_INVALID_ARG_TYPE`,function(e,t){return`The "${e}" argument must be of type number. Received type ${typeof t}`},TypeError),de(`ERR_OUT_OF_RANGE`,function(e,t,n){let r=`The value of "${e}" is out of range.`,i=n;return Number.isInteger(n)&&Math.abs(n)>2**32?i=z(String(n)):typeof n==`bigint`&&(i=String(n),(n>BigInt(2)**BigInt(32)||n<-(BigInt(2)**BigInt(32)))&&(i=z(i)),i+=`n`),r+=` It must be ${t}. Received ${i}`,r},RangeError);function z(e){let t=``,n=e.length,r=+(e[0]===`-`);for(;n>=r+4;n-=3)t=`_${e.slice(n-3,n)}${t}`;return`${e.slice(0,n)}${t}`}function B(e,t,n){pe(t,`offset`),(e[t]===void 0||e[t+n]===void 0)&&me(t,e.length-(n+1))}function fe(e,t,n,r,i,a){if(e>n||e<t){let r=typeof t==`bigint`?`n`:``,i;throw i=a>3?t===0||t===BigInt(0)?`>= 0${r} and < 2${r} ** ${(a+1)*8}${r}`:`>= -(2${r} ** ${(a+1)*8-1}${r}) and < 2 ** ${(a+1)*8-1}${r}`:`>= ${t}${r} and <= ${n}${r}`,new R.ERR_OUT_OF_RANGE(`value`,i,e)}B(r,i,a)}function pe(e,t){if(typeof e!=`number`)throw new R.ERR_INVALID_ARG_TYPE(t,`number`,e)}function me(e,t,n){throw Math.floor(e)===e?t<0?new R.ERR_BUFFER_OUT_OF_BOUNDS:new R.ERR_OUT_OF_RANGE(n||`offset`,`>= ${+!!n} and <= ${t}`,e):(pe(e,n),new R.ERR_OUT_OF_RANGE(n||`offset`,`an integer`,e))}let he=/[^+/0-9A-Za-z-_]/g;function ge(e){if(e=e.split(`=`)[0],e=e.trim().replace(he,``),e.length<2)return``;for(;e.length%4!=0;)e+=`=`;return e}function _e(e,t){t||=1/0;let n,r=e.length,i=null,a=[];for(let o=0;o<r;++o){if(n=e.charCodeAt(o),n>55295&&n<57344){if(!i){if(n>56319){(t-=3)>-1&&a.push(239,191,189);continue}if(o+1===r){(t-=3)>-1&&a.push(239,191,189);continue}i=n;continue}if(n<56320){(t-=3)>-1&&a.push(239,191,189),i=n;continue}n=(i-55296<<10|n-56320)+65536}else i&&(t-=3)>-1&&a.push(239,191,189);if(i=null,n<128){if(--t<0)break;a.push(n)}else if(n<2048){if((t-=2)<0)break;a.push(n>>6|192,n&63|128)}else if(n<65536){if((t-=3)<0)break;a.push(n>>12|224,n>>6&63|128,n&63|128)}else if(n<1114112){if((t-=4)<0)break;a.push(n>>18|240,n>>12&63|128,n>>6&63|128,n&63|128)}else throw Error(`Invalid code point`)}return a}function ve(e){let t=[];for(let n=0;n<e.length;++n)t.push(e.charCodeAt(n)&255);return t}function ye(e,t){let n,r,i,a=[];for(let o=0;o<e.length&&!((t-=2)<0);++o)n=e.charCodeAt(o),r=n>>8,i=n%256,a.push(i),a.push(r);return a}function be(e){return t.toByteArray(ge(e))}function V(e,t,n,r){let i;for(i=0;i<r&&!(i+n>=t.length||i>=e.length);++i)t[i+n]=e[i];return i}function xe(e,t){return e instanceof t||e!=null&&e.constructor!=null&&e.constructor.name!=null&&e.constructor.name===t.name}function Se(e){return e!==e}let Ce=(function(){let e=`0123456789abcdef`,t=Array(256);for(let n=0;n<16;++n){let r=n*16;for(let i=0;i<16;++i)t[r+i]=e[n]+e[i]}return t})();function H(e){return typeof BigInt>`u`?we:e}function we(){throw Error(`BigInt not supported`)}})(t);var _=t.Buffer;e.Blob=t.Blob,e.BlobOptions=t.BlobOptions,e.Buffer=t.Buffer,e.File=t.File,e.FileOptions=t.FileOptions,e.INSPECT_MAX_BYTES=t.INSPECT_MAX_BYTES,e.SlowBuffer=t.SlowBuffer,e.TranscodeEncoding=t.TranscodeEncoding,e.atob=t.atob,e.btoa=t.btoa,e.constants=t.constants,e.default=_,e.isAscii=t.isAscii,e.isUtf8=t.isUtf8,e.kMaxLength=t.kMaxLength,e.kStringMaxLength=t.kStringMaxLength,e.resolveObjectURL=t.resolveObjectURL,e.transcode=t.transcode})),k=n(((e,t)=>{t.exports={}})),A=n(((e,t)=>{function n(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)}return n}function r(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]==null?{}:arguments[t];t%2?n(Object(r),!0).forEach(function(t){i(e,t,r[t])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):n(Object(r)).forEach(function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))})}return e}function i(e,t,n){return t=c(t),t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function a(e,t){if(!(e instanceof t))throw TypeError(`Cannot call a class as a function`)}function o(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,`value`in r&&(r.writable=!0),Object.defineProperty(e,c(r.key),r)}}function s(e,t,n){return t&&o(e.prototype,t),n&&o(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function c(e){var t=l(e,`string`);return typeof t==`symbol`?t:String(t)}function l(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}var u=O().Buffer,d=k().inspect,f=d&&d.custom||`inspect`;function p(e,t,n){u.prototype.copy.call(e,t,n)}t.exports=function(){function e(){a(this,e),this.head=null,this.tail=null,this.length=0}return s(e,[{key:`push`,value:function(e){var t={data:e,next:null};this.length>0?this.tail.next=t:this.head=t,this.tail=t,++this.length}},{key:`unshift`,value:function(e){var t={data:e,next:this.head};this.length===0&&(this.tail=t),this.head=t,++this.length}},{key:`shift`,value:function(){if(this.length!==0){var e=this.head.data;return this.head=this.length===1?this.tail=null:this.head.next,--this.length,e}}},{key:`clear`,value:function(){this.head=this.tail=null,this.length=0}},{key:`join`,value:function(e){if(this.length===0)return``;for(var t=this.head,n=``+t.data;t=t.next;)n+=e+t.data;return n}},{key:`concat`,value:function(e){if(this.length===0)return u.alloc(0);for(var t=u.allocUnsafe(e>>>0),n=this.head,r=0;n;)p(n.data,t,r),r+=n.data.length,n=n.next;return t}},{key:`consume`,value:function(e,t){var n;return e<this.head.data.length?(n=this.head.data.slice(0,e),this.head.data=this.head.data.slice(e)):n=e===this.head.data.length?this.shift():t?this._getString(e):this._getBuffer(e),n}},{key:`first`,value:function(){return this.head.data}},{key:`_getString`,value:function(e){var t=this.head,n=1,r=t.data;for(e-=r.length;t=t.next;){var i=t.data,a=e>i.length?i.length:e;if(a===i.length?r+=i:r+=i.slice(0,e),e-=a,e===0){a===i.length?(++n,this.head=t.next?t.next:this.tail=null):(this.head=t,t.data=i.slice(a));break}++n}return this.length-=n,r}},{key:`_getBuffer`,value:function(e){var t=u.allocUnsafe(e),n=this.head,r=1;for(n.data.copy(t),e-=n.data.length;n=n.next;){var i=n.data,a=e>i.length?i.length:e;if(i.copy(t,t.length-e,0,a),e-=a,e===0){a===i.length?(++r,this.head=n.next?n.next:this.tail=null):(this.head=n,n.data=i.slice(a));break}++r}return this.length-=r,t}},{key:f,value:function(e,t){return d(this,r(r({},t),{},{depth:0,customInspect:!1}))}}]),e}()})),ee=n(((e,t)=>{E();function n(e,t){var n=this,a=this._readableState&&this._readableState.destroyed,s=this._writableState&&this._writableState.destroyed;return a||s?(t?t(e):e&&(this._writableState?this._writableState.errorEmitted||(this._writableState.errorEmitted=!0,T.nextTick(o,this,e)):T.nextTick(o,this,e)),this):(this._readableState&&(this._readableState.destroyed=!0),this._writableState&&(this._writableState.destroyed=!0),this._destroy(e||null,function(e){!t&&e?n._writableState?n._writableState.errorEmitted?T.nextTick(i,n):(n._writableState.errorEmitted=!0,T.nextTick(r,n,e)):T.nextTick(r,n,e):t?(T.nextTick(i,n),t(e)):T.nextTick(i,n)}),this)}function r(e,t){o(e,t),i(e)}function i(e){e._writableState&&!e._writableState.emitClose||e._readableState&&!e._readableState.emitClose||e.emit(`close`)}function a(){this._readableState&&(this._readableState.destroyed=!1,this._readableState.reading=!1,this._readableState.ended=!1,this._readableState.endEmitted=!1),this._writableState&&(this._writableState.destroyed=!1,this._writableState.ended=!1,this._writableState.ending=!1,this._writableState.finalCalled=!1,this._writableState.prefinished=!1,this._writableState.finished=!1,this._writableState.errorEmitted=!1)}function o(e,t){e.emit(`error`,t)}function s(e,t){var n=e._readableState,r=e._writableState;n&&n.autoDestroy||r&&r.autoDestroy?e.destroy(t):e.emit(`error`,t)}t.exports={destroy:n,undestroy:a,errorOrDestroy:s}})),j=n(((e,t)=>{function n(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}var r={};function i(e,t,i){i||=Error;function a(e,n,r){return typeof t==`string`?t:t(e,n,r)}var o=function(e){n(t,e);function t(t,n,r){return e.call(this,a(t,n,r))||this}return t}(i);o.prototype.name=i.name,o.prototype.code=e,r[e]=o}function a(e,t){if(Array.isArray(e)){var n=e.length;return e=e.map(function(e){return String(e)}),n>2?`one of ${t} ${e.slice(0,n-1).join(`, `)}, or `+e[n-1]:n===2?`one of ${t} ${e[0]} or ${e[1]}`:`of ${t} ${e[0]}`}return`of ${t} ${String(e)}`}function o(e,t,n){return e.substr(!n||n<0?0:+n,t.length)===t}function s(e,t,n){return(n===void 0||n>e.length)&&(n=e.length),e.substring(n-t.length,n)===t}function c(e,t,n){return typeof n!=`number`&&(n=0),n+t.length>e.length?!1:e.indexOf(t,n)!==-1}i(`ERR_INVALID_OPT_VALUE`,function(e,t){return`The value "`+t+`" is invalid for option "`+e+`"`},TypeError),i(`ERR_INVALID_ARG_TYPE`,function(e,t,n){var r;typeof t==`string`&&o(t,`not `)?(r=`must not be`,t=t.replace(/^not /,``)):r=`must be`;var i=s(e,` argument`)?`The ${e} ${r} ${a(t,`type`)}`:`The "${e}" ${c(e,`.`)?`property`:`argument`} ${r} ${a(t,`type`)}`;return i+=`. Received type ${typeof n}`,i},TypeError),i(`ERR_STREAM_PUSH_AFTER_EOF`,`stream.push() after EOF`),i(`ERR_METHOD_NOT_IMPLEMENTED`,function(e){return`The `+e+` method is not implemented`}),i(`ERR_STREAM_PREMATURE_CLOSE`,`Premature close`),i(`ERR_STREAM_DESTROYED`,function(e){return`Cannot call `+e+` after a stream was destroyed`}),i(`ERR_MULTIPLE_CALLBACK`,`Callback called multiple times`),i(`ERR_STREAM_CANNOT_PIPE`,`Cannot pipe, not readable`),i(`ERR_STREAM_WRITE_AFTER_END`,`write after end`),i(`ERR_STREAM_NULL_VALUES`,`May not write null values to stream`,TypeError),i(`ERR_UNKNOWN_ENCODING`,function(e){return`Unknown encoding: `+e},TypeError),i(`ERR_STREAM_UNSHIFT_AFTER_END_EVENT`,`stream.unshift() after end event`),t.exports.codes=r})),te=n(((e,t)=>{var n=j().codes.ERR_INVALID_OPT_VALUE;function r(e,t,n){return e.highWaterMark==null?t?e[n]:null:e.highWaterMark}function i(e,t,i,a){var o=r(t,a,i);if(o!=null){if(!(isFinite(o)&&Math.floor(o)===o)||o<0)throw new n(a?i:`highWaterMark`,o);return Math.floor(o)}return e.objectMode?16:16384}t.exports={getHighWaterMark:i}})),ne=n(((e,t)=>{o(),t.exports=n;function n(e,t){if(r(`noDeprecation`))return e;var n=!1;function i(){if(!n){if(r(`throwDeprecation`))throw Error(t);r(`traceDeprecation`)?console.trace(t):console.warn(t),n=!0}return e.apply(this,arguments)}return i}function r(e){try{if(!a.localStorage)return!1}catch{return!1}var t=a.localStorage[e];return t!=null&&String(t).toLowerCase()===`true`}})),M=n(((e,t)=>{o(),E(),t.exports=N;function n(e){var t=this;this.next=null,this.entry=null,this.finish=function(){pe(t,e)}}var r;N.WritableState=A;var s={deprecate:ne()},c=D(),l=O().Buffer,u=(a===void 0?typeof window<`u`?window:typeof self<`u`?self:{}:a).Uint8Array||function(){};function d(e){return l.from(e)}function f(e){return l.isBuffer(e)||e instanceof u}var p=ee(),m=te().getHighWaterMark,h=j().codes,g=h.ERR_INVALID_ARG_TYPE,_=h.ERR_METHOD_NOT_IMPLEMENTED,v=h.ERR_MULTIPLE_CALLBACK,y=h.ERR_STREAM_CANNOT_PIPE,b=h.ERR_STREAM_DESTROYED,x=h.ERR_STREAM_NULL_VALUES,S=h.ERR_STREAM_WRITE_AFTER_END,C=h.ERR_UNKNOWN_ENCODING,w=p.errorOrDestroy;i()(N,c);function k(){}function A(e,t,i){r||=re(),e||={},typeof i!=`boolean`&&(i=t instanceof r),this.objectMode=!!e.objectMode,i&&(this.objectMode=this.objectMode||!!e.writableObjectMode),this.highWaterMark=m(this,e,`writableHighWaterMark`,i),this.finalCalled=!1,this.needDrain=!1,this.ending=!1,this.ended=!1,this.finished=!1,this.destroyed=!1;var a=e.decodeStrings===!1;this.decodeStrings=!a,this.defaultEncoding=e.defaultEncoding||`utf8`,this.length=0,this.writing=!1,this.corked=0,this.sync=!0,this.bufferProcessing=!1,this.onwrite=function(e){se(t,e)},this.writecb=null,this.writelen=0,this.bufferedRequest=null,this.lastBufferedRequest=null,this.pendingcb=0,this.prefinished=!1,this.errorEmitted=!1,this.emitClose=e.emitClose!==!1,this.autoDestroy=!!e.autoDestroy,this.bufferedRequestCount=0,this.corkedRequestsFree=new n(this)}A.prototype.getBuffer=function(){for(var e=this.bufferedRequest,t=[];e;)t.push(e),e=e.next;return t},(function(){try{Object.defineProperty(A.prototype,"buffer",{get:s.deprecate(function(){return this.getBuffer()},`_writableState.buffer is deprecated. Use _writableState.getBuffer instead.`,`DEP0003`)})}catch{}})();var M;typeof Symbol==`function`&&Symbol.hasInstance&&typeof Function.prototype[Symbol.hasInstance]==`function`?(M=Function.prototype[Symbol.hasInstance],Object.defineProperty(N,Symbol.hasInstance,{value:function(e){return M.call(this,e)?!0:this===N&&e&&e._writableState instanceof A}})):M=function(e){return e instanceof this};function N(e){r||=re();var t=this instanceof r;if(!t&&!M.call(N,this))return new N(e);this._writableState=new A(e,this,t),this.writable=!0,e&&(typeof e.write==`function`&&(this._write=e.write),typeof e.writev==`function`&&(this._writev=e.writev),typeof e.destroy==`function`&&(this._destroy=e.destroy),typeof e.final==`function`&&(this._final=e.final)),c.call(this)}N.prototype.pipe=function(){w(this,new y)};function ie(e,t){var n=new S;w(e,n),T.nextTick(t,n)}function ae(e,t,n,r){var i;return n===null?i=new x:typeof n!=`string`&&!t.objectMode&&(i=new g(`chunk`,[`string`,`Buffer`],n)),!i||(w(e,i),T.nextTick(r,i),!1)}N.prototype.write=function(e,t,n){var r=this._writableState,i=!1,a=!r.objectMode&&f(e);return a&&!l.isBuffer(e)&&(e=d(e)),typeof t==`function`&&(n=t,t=null),a?t=`buffer`:t||=r.defaultEncoding,typeof n!=`function`&&(n=k),r.ending?ie(this,n):(a||ae(this,r,e,n))&&(r.pendingcb++,i=F(this,r,a,e,t,n)),i},N.prototype.cork=function(){this._writableState.corked++},N.prototype.uncork=function(){var e=this._writableState;e.corked&&(e.corked--,!e.writing&&!e.corked&&!e.bufferProcessing&&e.bufferedRequest&&ue(this,e))},N.prototype.setDefaultEncoding=function(e){if(typeof e==`string`&&(e=e.toLowerCase()),!([`hex`,`utf8`,`utf-8`,`ascii`,`binary`,`base64`,`ucs2`,`ucs-2`,`utf16le`,`utf-16le`,`raw`].indexOf((e+``).toLowerCase())>-1))throw new C(e);return this._writableState.defaultEncoding=e,this},Object.defineProperty(N.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}});function P(e,t,n){return!e.objectMode&&e.decodeStrings!==!1&&typeof t==`string`&&(t=l.from(t,n)),t}Object.defineProperty(N.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}});function F(e,t,n,r,i,a){if(!n){var o=P(t,r,i);r!==o&&(n=!0,i=`buffer`,r=o)}var s=t.objectMode?1:r.length;t.length+=s;var c=t.length<t.highWaterMark;if(c||(t.needDrain=!0),t.writing||t.corked){var l=t.lastBufferedRequest;t.lastBufferedRequest={chunk:r,encoding:i,isBuf:n,callback:a,next:null},l?l.next=t.lastBufferedRequest:t.bufferedRequest=t.lastBufferedRequest,t.bufferedRequestCount+=1}else I(e,t,!1,s,r,i,a);return c}function I(e,t,n,r,i,a,o){t.writelen=r,t.writecb=o,t.writing=!0,t.sync=!0,t.destroyed?t.onwrite(new b(`write`)):n?e._writev(i,t.onwrite):e._write(i,a,t.onwrite),t.sync=!1}function L(e,t,n,r,i){--t.pendingcb,n?(T.nextTick(i,r),T.nextTick(B,e,t),e._writableState.errorEmitted=!0,w(e,r)):(i(r),e._writableState.errorEmitted=!0,w(e,r),B(e,t))}function oe(e){e.writing=!1,e.writecb=null,e.length-=e.writelen,e.writelen=0}function se(e,t){var n=e._writableState,r=n.sync,i=n.writecb;if(typeof i!=`function`)throw new v;if(oe(n),t)L(e,n,r,t,i);else{var a=R(n)||e.destroyed;!a&&!n.corked&&!n.bufferProcessing&&n.bufferedRequest&&ue(e,n),r?T.nextTick(ce,e,n,a,i):ce(e,n,a,i)}}function ce(e,t,n,r){n||le(e,t),t.pendingcb--,r(),B(e,t)}function le(e,t){t.length===0&&t.needDrain&&(t.needDrain=!1,e.emit(`drain`))}function ue(e,t){t.bufferProcessing=!0;var r=t.bufferedRequest;if(e._writev&&r&&r.next){var i=t.bufferedRequestCount,a=Array(i),o=t.corkedRequestsFree;o.entry=r;for(var s=0,c=!0;r;)a[s]=r,r.isBuf||(c=!1),r=r.next,s+=1;a.allBuffers=c,I(e,t,!0,t.length,a,``,o.finish),t.pendingcb++,t.lastBufferedRequest=null,o.next?(t.corkedRequestsFree=o.next,o.next=null):t.corkedRequestsFree=new n(t),t.bufferedRequestCount=0}else{for(;r;){var l=r.chunk,u=r.encoding,d=r.callback;if(I(e,t,!1,t.objectMode?1:l.length,l,u,d),r=r.next,t.bufferedRequestCount--,t.writing)break}r===null&&(t.lastBufferedRequest=null)}t.bufferedRequest=r,t.bufferProcessing=!1}N.prototype._write=function(e,t,n){n(new _(`_write()`))},N.prototype._writev=null,N.prototype.end=function(e,t,n){var r=this._writableState;return typeof e==`function`?(n=e,e=null,t=null):typeof t==`function`&&(n=t,t=null),e!=null&&this.write(e,t),r.corked&&(r.corked=1,this.uncork()),r.ending||fe(this,r,n),this},Object.defineProperty(N.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}});function R(e){return e.ending&&e.length===0&&e.bufferedRequest===null&&!e.finished&&!e.writing}function de(e,t){e._final(function(n){t.pendingcb--,n&&w(e,n),t.prefinished=!0,e.emit(`prefinish`),B(e,t)})}function z(e,t){!t.prefinished&&!t.finalCalled&&(typeof e._final==`function`&&!t.destroyed?(t.pendingcb++,t.finalCalled=!0,T.nextTick(de,e,t)):(t.prefinished=!0,e.emit(`prefinish`)))}function B(e,t){var n=R(t);if(n&&(z(e,t),t.pendingcb===0&&(t.finished=!0,e.emit(`finish`),t.autoDestroy))){var r=e._readableState;(!r||r.autoDestroy&&r.endEmitted)&&e.destroy()}return n}function fe(e,t,n){t.ending=!0,B(e,t),n&&(t.finished?T.nextTick(n):e.once(`finish`,n)),t.ended=!0,e.writable=!1}function pe(e,t,n){var r=e.entry;for(e.entry=null;r;){var i=r.callback;t.pendingcb--,i(n),r=r.next}t.corkedRequestsFree.next=e}Object.defineProperty(N.prototype,"destroyed",{enumerable:!1,get:function(){return this._writableState!==void 0&&this._writableState.destroyed},set:function(e){this._writableState&&(this._writableState.destroyed=e)}}),N.prototype.destroy=p.destroy,N.prototype._undestroy=p.undestroy,N.prototype._destroy=function(e,t){t(e)}})),re=n(((e,t)=>{E();var n=Object.keys||function(e){var t=[];for(var n in e)t.push(n);return t};t.exports=l;var r=I(),a=M();i()(l,r);for(var o=n(a.prototype),s=0;s<o.length;s++){var c=o[s];l.prototype[c]||(l.prototype[c]=a.prototype[c])}function l(e){if(!(this instanceof l))return new l(e);r.call(this,e),a.call(this,e),this.allowHalfOpen=!0,e&&(e.readable===!1&&(this.readable=!1),e.writable===!1&&(this.writable=!1),e.allowHalfOpen===!1&&(this.allowHalfOpen=!1,this.once(`end`,u)))}Object.defineProperty(l.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),Object.defineProperty(l.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(l.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}});function u(){this._writableState.ended||T.nextTick(d,this)}function d(e){e.end()}Object.defineProperty(l.prototype,"destroyed",{enumerable:!1,get:function(){return this._readableState===void 0||this._writableState===void 0?!1:this._readableState.destroyed&&this._writableState.destroyed},set:function(e){this._readableState!==void 0&&this._writableState!==void 0&&(this._readableState.destroyed=e,this._writableState.destroyed=e)}})})),N=n(((e,t)=>{var n=O(),r=n.Buffer;function i(e,t){for(var n in e)t[n]=e[n]}r.from&&r.alloc&&r.allocUnsafe&&r.allocUnsafeSlow?t.exports=n:(i(n,e),e.Buffer=a);function a(e,t,n){return r(e,t,n)}a.prototype=Object.create(r.prototype),i(r,a),a.from=function(e,t,n){if(typeof e==`number`)throw TypeError(`Argument must not be a number`);return r(e,t,n)},a.alloc=function(e,t,n){if(typeof e!=`number`)throw TypeError(`Argument must be a number`);var i=r(e);return t===void 0?i.fill(0):typeof n==`string`?i.fill(t,n):i.fill(t),i},a.allocUnsafe=function(e){if(typeof e!=`number`)throw TypeError(`Argument must be a number`);return r(e)},a.allocUnsafeSlow=function(e){if(typeof e!=`number`)throw TypeError(`Argument must be a number`);return n.SlowBuffer(e)}})),ie=n((e=>{var t=N().Buffer,n=t.isEncoding||function(e){switch(e=``+e,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 r(e){if(!e)return`utf8`;for(var t;;)switch(e){case`utf8`:case`utf-8`:return`utf8`;case`ucs2`:case`ucs-2`:case`utf16le`:case`utf-16le`:return`utf16le`;case`latin1`:case`binary`:return`latin1`;case`base64`:case`ascii`:case`hex`:return e;default:if(t)return;e=(``+e).toLowerCase(),t=!0}}function i(e){var i=r(e);if(typeof i!=`string`&&(t.isEncoding===n||!n(e)))throw Error(`Unknown encoding: `+e);return i||e}e.StringDecoder=a;function a(e){this.encoding=i(e);var n;switch(this.encoding){case`utf16le`:this.text=f,this.end=p,n=4;break;case`utf8`:this.fillLast=l,n=4;break;case`base64`:this.text=m,this.end=h,n=3;break;default:this.write=g,this.end=_;return}this.lastNeed=0,this.lastTotal=0,this.lastChar=t.allocUnsafe(n)}a.prototype.write=function(e){if(e.length===0)return``;var t,n;if(this.lastNeed){if(t=this.fillLast(e),t===void 0)return``;n=this.lastNeed,this.lastNeed=0}else n=0;return n<e.length?t?t+this.text(e,n):this.text(e,n):t||``},a.prototype.end=d,a.prototype.text=u,a.prototype.fillLast=function(e){if(this.lastNeed<=e.length)return e.copy(this.lastChar,this.lastTotal-this.lastNeed,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);e.copy(this.lastChar,this.lastTotal-this.lastNeed,0,e.length),this.lastNeed-=e.length};function o(e){return e<=127?0:e>>5==6?2:e>>4==14?3:e>>3==30?4:e>>6==2?-1:-2}function s(e,t,n){var r=t.length-1;if(r<n)return 0;var i=o(t[r]);return i>=0?(i>0&&(e.lastNeed=i-1),i):--r<n||i===-2?0:(i=o(t[r]),i>=0?(i>0&&(e.lastNeed=i-2),i):--r<n||i===-2?0:(i=o(t[r]),i>=0?(i>0&&(i===2?i=0:e.lastNeed=i-3),i):0))}function c(e,t,n){if((t[0]&192)!=128)return e.lastNeed=0,`�`;if(e.lastNeed>1&&t.length>1){if((t[1]&192)!=128)return e.lastNeed=1,`�`;if(e.lastNeed>2&&t.length>2&&(t[2]&192)!=128)return e.lastNeed=2,`�`}}function l(e){var t=this.lastTotal-this.lastNeed,n=c(this,e,t);if(n!==void 0)return n;if(this.lastNeed<=e.length)return e.copy(this.lastChar,t,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);e.copy(this.lastChar,t,0,e.length),this.lastNeed-=e.length}function u(e,t){var n=s(this,e,t);if(!this.lastNeed)return e.toString(`utf8`,t);this.lastTotal=n;var r=e.length-(n-this.lastNeed);return e.copy(this.lastChar,0,r),e.toString(`utf8`,t,r)}function d(e){var t=e&&e.length?this.write(e):``;return this.lastNeed?t+`�`:t}function f(e,t){if((e.length-t)%2==0){var n=e.toString(`utf16le`,t);if(n){var r=n.charCodeAt(n.length-1);if(r>=55296&&r<=56319)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1],n.slice(0,-1)}return n}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=e[e.length-1],e.toString(`utf16le`,t,e.length-1)}function p(e){var t=e&&e.length?this.write(e):``;if(this.lastNeed){var n=this.lastTotal-this.lastNeed;return t+this.lastChar.toString(`utf16le`,0,n)}return t}function m(e,t){var n=(e.length-t)%3;return n===0?e.toString(`base64`,t):(this.lastNeed=3-n,this.lastTotal=3,n===1?this.lastChar[0]=e[e.length-1]:(this.lastChar[0]=e[e.length-2],this.lastChar[1]=e[e.length-1]),e.toString(`base64`,t,e.length-n))}function h(e){var t=e&&e.length?this.write(e):``;return this.lastNeed?t+this.lastChar.toString(`base64`,0,3-this.lastNeed):t}function g(e){return e.toString(this.encoding)}function _(e){return e&&e.length?this.write(e):``}})),ae=n(((e,t)=>{var n=j().codes.ERR_STREAM_PREMATURE_CLOSE;function r(e){var t=!1;return function(){if(!t){t=!0;for(var n=arguments.length,r=Array(n),i=0;i<n;i++)r[i]=arguments[i];e.apply(this,r)}}}function i(){}function a(e){return e.setHeader&&typeof e.abort==`function`}function o(e,t,s){if(typeof t==`function`)return o(e,null,t);t||={},s=r(s||i);var c=t.readable||t.readable!==!1&&e.readable,l=t.writable||t.writable!==!1&&e.writable,u=function(){e.writable||f()},d=e._writableState&&e._writableState.finished,f=function(){l=!1,d=!0,c||s.call(e)},p=e._readableState&&e._readableState.endEmitted,m=function(){c=!1,p=!0,l||s.call(e)},h=function(t){s.call(e,t)},g=function(){var t;if(c&&!p)return(!e._readableState||!e._readableState.ended)&&(t=new n),s.call(e,t);if(l&&!d)return(!e._writableState||!e._writableState.ended)&&(t=new n),s.call(e,t)},_=function(){e.req.on(`finish`,f)};return a(e)?(e.on(`complete`,f),e.on(`abort`,g),e.req?_():e.on(`request`,_)):l&&!e._writableState&&(e.on(`end`,u),e.on(`close`,u)),e.on(`end`,m),e.on(`finish`,f),t.error!==!1&&e.on(`error`,h),e.on(`close`,g),function(){e.removeListener(`complete`,f),e.removeListener(`abort`,g),e.removeListener(`request`,_),e.req&&e.req.removeListener(`finish`,f),e.removeListener(`end`,u),e.removeListener(`close`,u),e.removeListener(`finish`,f),e.removeListener(`end`,m),e.removeListener(`error`,h),e.removeListener(`close`,g)}}t.exports=o})),P=n(((e,t)=>{E();var n;function r(e,t,n){return t=i(t),t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e){var t=a(e,`string`);return typeof t==`symbol`?t:String(t)}function a(e,t){if(typeof e!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(typeof r!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}var o=ae(),s=Symbol(`lastResolve`),c=Symbol(`lastReject`),l=Symbol(`error`),u=Symbol(`ended`),d=Symbol(`lastPromise`),f=Symbol(`handlePromise`),p=Symbol(`stream`);function m(e,t){return{value:e,done:t}}function h(e){var t=e[s];if(t!==null){var n=e[p].read();n!==null&&(e[d]=null,e[s]=null,e[c]=null,t(m(n,!1)))}}function g(e){T.nextTick(h,e)}function _(e,t){return function(n,r){e.then(function(){if(t[u]){n(m(void 0,!0));return}t[f](n,r)},r)}}var v=Object.getPrototypeOf(function(){}),y=Object.setPrototypeOf((n={get stream(){return this[p]},next:function(){var e=this,t=this[l];if(t!==null)return Promise.reject(t);if(this[u])return Promise.resolve(m(void 0,!0));if(this[p].destroyed)return new Promise(function(t,n){T.nextTick(function(){e[l]?n(e[l]):t(m(void 0,!0))})});var n=this[d],r;if(n)r=new Promise(_(n,this));else{var i=this[p].read();if(i!==null)return Promise.resolve(m(i,!1));r=new Promise(this[f])}return this[d]=r,r}},r(n,Symbol.asyncIterator,function(){return this}),r(n,`return`,function(){var e=this;return new Promise(function(t,n){e[p].destroy(null,function(e){if(e){n(e);return}t(m(void 0,!0))})})}),n),v);t.exports=function(e){var t,n=Object.create(y,(t={},r(t,p,{value:e,writable:!0}),r(t,s,{value:null,writable:!0}),r(t,c,{value:null,writable:!0}),r(t,l,{value:null,writable:!0}),r(t,u,{value:e._readableState.endEmitted,writable:!0}),r(t,f,{value:function(e,t){var r=n[p].read();r?(n[d]=null,n[s]=null,n[c]=null,e(m(r,!1))):(n[s]=e,n[c]=t)},writable:!0}),t));return n[d]=null,o(e,function(e){if(e&&e.code!==`ERR_STREAM_PREMATURE_CLOSE`){var t=n[c];t!==null&&(n[d]=null,n[s]=null,n[c]=null,t(e)),n[l]=e;return}var r=n[s];r!==null&&(n[d]=null,n[s]=null,n[c]=null,r(m(void 0,!0))),n[u]=!0}),e.on(`readable`,g.bind(null,n)),n}})),F=n(((e,t)=>{t.exports=function(){throw Error(`Readable.from is not available in the browser`)}})),I=n(((e,t)=>{o(),E(),t.exports=L;var n;L.ReadableState=I,r().EventEmitter;var s=function(e,t){return e.listeners(t).length},c=D(),l=O().Buffer,u=(a===void 0?typeof window<`u`?window:typeof self<`u`?self:{}:a).Uint8Array||function(){};function d(e){return l.from(e)}function f(e){return l.isBuffer(e)||e instanceof u}var p=k(),m=p&&p.debuglog?p.debuglog(`stream`):function(){},h=A(),g=ee(),_=te().getHighWaterMark,v=j().codes,y=v.ERR_INVALID_ARG_TYPE,b=v.ERR_STREAM_PUSH_AFTER_EOF,x=v.ERR_METHOD_NOT_IMPLEMENTED,S=v.ERR_STREAM_UNSHIFT_AFTER_END_EVENT,C,w,ne;i()(L,c);var M=g.errorOrDestroy,N=[`error`,`close`,`destroy`,`pause`,`resume`];function ae(e,t,n){if(typeof e.prependListener==`function`)return e.prependListener(t,n);!e._events||!e._events[t]?e.on(t,n):Array.isArray(e._events[t])?e._events[t].unshift(n):e._events[t]=[n,e._events[t]]}function I(e,t,r){n||=re(),e||={},typeof r!=`boolean`&&(r=t instanceof n),this.objectMode=!!e.objectMode,r&&(this.objectMode=this.objectMode||!!e.readableObjectMode),this.highWaterMark=_(this,e,`readableHighWaterMark`,r),this.buffer=new h,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.paused=!0,this.emitClose=e.emitClose!==!1,this.autoDestroy=!!e.autoDestroy,this.destroyed=!1,this.defaultEncoding=e.defaultEncoding||`utf8`,this.awaitDrain=0,this.readingMore=!1,this.decoder=null,this.encoding=null,e.encoding&&(C||=ie().StringDecoder,this.decoder=new C(e.encoding),this.encoding=e.encoding)}function L(e){if(n||=re(),!(this instanceof L))return new L(e);var t=this instanceof n;this._readableState=new I(e,this,t),this.readable=!0,e&&(typeof e.read==`function`&&(this._read=e.read),typeof e.destroy==`function`&&(this._destroy=e.destroy)),c.call(this)}Object.defineProperty(L.prototype,"destroyed",{enumerable:!1,get:function(){return this._readableState!==void 0&&this._readableState.destroyed},set:function(e){this._readableState&&(this._readableState.destroyed=e)}}),L.prototype.destroy=g.destroy,L.prototype._undestroy=g.undestroy,L.prototype._destroy=function(e,t){t(e)},L.prototype.push=function(e,t){var n=this._readableState,r;return n.objectMode?r=!0:typeof e==`string`&&(t||=n.defaultEncoding,t!==n.encoding&&(e=l.from(e,t),t=``),r=!0),oe(this,e,t,!1,r)},L.prototype.unshift=function(e){return oe(this,e,null,!0,!1)};function oe(e,t,n,r,i){m(`readableAddChunk`,t);var a=e._readableState;if(t===null)a.reading=!1,de(e,a);else{var o;if(i||(o=ce(a,t)),o)M(e,o);else if(a.objectMode||t&&t.length>0){if(typeof t!=`string`&&!a.objectMode&&Object.getPrototypeOf(t)!==l.prototype&&(t=d(t)),r)a.endEmitted?M(e,new S):se(e,a,t,!0);else if(a.ended)M(e,new b);else if(a.destroyed)return!1;else a.reading=!1,a.decoder&&!n?(t=a.decoder.write(t),a.objectMode||t.length!==0?se(e,a,t,!1):fe(e,a)):se(e,a,t,!1)}else r||(a.reading=!1,fe(e,a))}return!a.ended&&(a.length<a.highWaterMark||a.length===0)}function se(e,t,n,r){t.flowing&&t.length===0&&!t.sync?(t.awaitDrain=0,e.emit(`data`,n)):(t.length+=t.objectMode?1:n.length,r?t.buffer.unshift(n):t.buffer.push(n),t.needReadable&&z(e)),fe(e,t)}function ce(e,t){var n;return!f(t)&&typeof t!=`string`&&t!==void 0&&!e.objectMode&&(n=new y(`chunk`,[`string`,`Buffer`,`Uint8Array`],t)),n}L.prototype.isPaused=function(){return this._readableState.flowing===!1},L.prototype.setEncoding=function(e){C||=ie().StringDecoder;var t=new C(e);this._readableState.decoder=t,this._readableState.encoding=this._readableState.decoder.encoding;for(var n=this._readableState.buffer.head,r=``;n!==null;)r+=t.write(n.data),n=n.next;return this._readableState.buffer.clear(),r!==``&&this._readableState.buffer.push(r),this._readableState.length=r.length,this};var le=1073741824;function ue(e){return e>=le?e=le:(e--,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e++),e}function R(e,t){return e<=0||t.length===0&&t.ended?0:t.objectMode?1:e===e?(e>t.highWaterMark&&(t.highWaterMark=ue(e)),e<=t.length?e:t.ended?t.length:(t.needReadable=!0,0)):t.flowing&&t.length?t.buffer.head.data.length:t.length}L.prototype.read=function(e){m(`read`,e),e=parseInt(e,10);var t=this._readableState,n=e;if(e!==0&&(t.emittedReadable=!1),e===0&&t.needReadable&&((t.highWaterMark===0?t.length>0:t.length>=t.highWaterMark)||t.ended))return m(`read: emitReadable`,t.length,t.ended),t.length===0&&t.ended?V(this):z(this),null;if(e=R(e,t),e===0&&t.ended)return t.length===0&&V(this),null;var r=t.needReadable;m(`need readable`,r),(t.length===0||t.length-e<t.highWaterMark)&&(r=!0,m(`length less than watermark`,r)),t.ended||t.reading?(r=!1,m(`reading or ended`,r)):r&&(m(`do read`),t.reading=!0,t.sync=!0,t.length===0&&(t.needReadable=!0),this._read(t.highWaterMark),t.sync=!1,t.reading||(e=R(n,t)));var i=e>0?be(e,t):null;return i===null?(t.needReadable=t.length<=t.highWaterMark,e=0):(t.length-=e,t.awaitDrain=0),t.length===0&&(t.ended||(t.needReadable=!0),n!==e&&t.ended&&V(this)),i!==null&&this.emit(`data`,i),i};function de(e,t){if(m(`onEofChunk`),!t.ended){if(t.decoder){var n=t.decoder.end();n&&n.length&&(t.buffer.push(n),t.length+=t.objectMode?1:n.length)}t.ended=!0,t.sync?z(e):(t.needReadable=!1,t.emittedReadable||(t.emittedReadable=!0,B(e)))}}function z(e){var t=e._readableState;m(`emitReadable`,t.needReadable,t.emittedReadable),t.needReadable=!1,t.emittedReadable||(m(`emitReadable`,t.flowing),t.emittedReadable=!0,T.nextTick(B,e))}function B(e){var t=e._readableState;m(`emitReadable_`,t.destroyed,t.length,t.ended),!t.destroyed&&(t.length||t.ended)&&(e.emit(`readable`),t.emittedReadable=!1),t.needReadable=!t.flowing&&!t.ended&&t.length<=t.highWaterMark,ye(e)}function fe(e,t){t.readingMore||(t.readingMore=!0,T.nextTick(pe,e,t))}function pe(e,t){for(;!t.reading&&!t.ended&&(t.length<t.highWaterMark||t.flowing&&t.length===0);){var n=t.length;if(m(`maybeReadMore read 0`),e.read(0),n===t.length)break}t.readingMore=!1}L.prototype._read=function(e){M(this,new x(`_read()`))},L.prototype.pipe=function(e,t){var n=this,r=this._readableState;switch(r.pipesCount){case 0:r.pipes=e;break;case 1:r.pipes=[r.pipes,e];break;default:r.pipes.push(e)}r.pipesCount+=1,m(`pipe count=%d opts=%j`,r.pipesCount,t);var i=(!t||t.end!==!1)&&e!==T.stdout&&e!==T.stderr?o:g;r.endEmitted?T.nextTick(i):n.once(`end`,i),e.on(`unpipe`,a);function a(e,t){m(`onunpipe`),e===n&&t&&t.hasUnpiped===!1&&(t.hasUnpiped=!0,u())}function o(){m(`onend`),e.end()}var c=me(n);e.on(`drain`,c);var l=!1;function u(){m(`cleanup`),e.removeListener(`close`,p),e.removeListener(`finish`,h),e.removeListener(`drain`,c),e.removeListener(`error`,f),e.removeListener(`unpipe`,a),n.removeListener(`end`,o),n.removeListener(`end`,g),n.removeListener(`data`,d),l=!0,r.awaitDrain&&(!e._writableState||e._writableState.needDrain)&&c()}n.on(`data`,d);function d(t){m(`ondata`);var i=e.write(t);m(`dest.write`,i),i===!1&&((r.pipesCount===1&&r.pipes===e||r.pipesCount>1&&Se(r.pipes,e)!==-1)&&!l&&(m(`false write response, pause`,r.awaitDrain),r.awaitDrain++),n.pause())}function f(t){m(`onerror`,t),g(),e.removeListener(`error`,f),s(e,`error`)===0&&M(e,t)}ae(e,`error`,f);function p(){e.removeListener(`finish`,h),g()}e.once(`close`,p);function h(){m(`onfinish`),e.removeListener(`close`,p),g()}e.once(`finish`,h);function g(){m(`unpipe`),n.unpipe(e)}return e.emit(`pipe`,n),r.flowing||(m(`pipe resume`),n.resume()),e};function me(e){return function(){var t=e._readableState;m(`pipeOnDrain`,t.awaitDrain),t.awaitDrain&&t.awaitDrain--,t.awaitDrain===0&&s(e,`data`)&&(t.flowing=!0,ye(e))}}L.prototype.unpipe=function(e){var t=this._readableState,n={hasUnpiped:!1};if(t.pipesCount===0)return this;if(t.pipesCount===1)return e&&e!==t.pipes?this:(e||=t.pipes,t.pipes=null,t.pipesCount=0,t.flowing=!1,e&&e.emit(`unpipe`,this,n),this);if(!e){var r=t.pipes,i=t.pipesCount;t.pipes=null,t.pipesCount=0,t.flowing=!1;for(var a=0;a<i;a++)r[a].emit(`unpipe`,this,{hasUnpiped:!1});return this}var o=Se(t.pipes,e);return o===-1?this:(t.pipes.splice(o,1),--t.pipesCount,t.pipesCount===1&&(t.pipes=t.pipes[0]),e.emit(`unpipe`,this,n),this)},L.prototype.on=function(e,t){var n=c.prototype.on.call(this,e,t),r=this._readableState;return e===`data`?(r.readableListening=this.listenerCount(`readable`)>0,r.flowing!==!1&&this.resume()):e===`readable`&&!r.endEmitted&&!r.readableListening&&(r.readableListening=r.needReadable=!0,r.flowing=!1,r.emittedReadable=!1,m(`on readable`,r.length,r.reading),r.length?z(this):r.reading||T.nextTick(ge,this)),n},L.prototype.addListener=L.prototype.on,L.prototype.removeListener=function(e,t){var n=c.prototype.removeListener.call(this,e,t);return e===`readable`&&T.nextTick(he,this),n},L.prototype.removeAllListeners=function(e){var t=c.prototype.removeAllListeners.apply(this,arguments);return(e===`readable`||e===void 0)&&T.nextTick(he,this),t};function he(e){var t=e._readableState;t.readableListening=e.listenerCount(`readable`)>0,t.resumeScheduled&&!t.paused?t.flowing=!0:e.listenerCount(`data`)>0&&e.resume()}function ge(e){m(`readable nexttick read 0`),e.read(0)}L.prototype.resume=function(){var e=this._readableState;return e.flowing||(m(`resume`),e.flowing=!e.readableListening,_e(this,e)),e.paused=!1,this};function _e(e,t){t.resumeScheduled||(t.resumeScheduled=!0,T.nextTick(ve,e,t))}function ve(e,t){m(`resume`,t.reading),t.reading||e.read(0),t.resumeScheduled=!1,e.emit(`resume`),ye(e),t.flowing&&!t.reading&&e.read(0)}L.prototype.pause=function(){return m(`call pause flowing=%j`,this._readableState.flowing),this._readableState.flowing!==!1&&(m(`pause`),this._readableState.flowing=!1,this.emit(`pause`)),this._readableState.paused=!0,this};function ye(e){var t=e._readableState;for(m(`flow`,t.flowing);t.flowing&&e.read()!==null;);}L.prototype.wrap=function(e){var t=this,n=this._readableState,r=!1;for(var i in e.on(`end`,function(){if(m(`wrapped end`),n.decoder&&!n.ended){var e=n.decoder.end();e&&e.length&&t.push(e)}t.push(null)}),e.on(`data`,function(i){m(`wrapped data`),n.decoder&&(i=n.decoder.write(i)),!(n.objectMode&&i==null)&&(!n.objectMode&&(!i||!i.length)||t.push(i)||(r=!0,e.pause()))}),e)this[i]===void 0&&typeof e[i]==`function`&&(this[i]=function(t){return function(){return e[t].apply(e,arguments)}}(i));for(var a=0;a<N.length;a++)e.on(N[a],this.emit.bind(this,N[a]));return this._read=function(t){m(`wrapped _read`,t),r&&(r=!1,e.resume())},this},typeof Symbol==`function`&&(L.prototype[Symbol.asyncIterator]=function(){return w===void 0&&(w=P()),w(this)}),Object.defineProperty(L.prototype,"readableHighWaterMark",{enumerable:!1,get:function(){return this._readableState.highWaterMark}}),Object.defineProperty(L.prototype,"readableBuffer",{enumerable:!1,get:function(){return this._readableState&&this._readableState.buffer}}),Object.defineProperty(L.prototype,"readableFlowing",{enumerable:!1,get:function(){return this._readableState.flowing},set:function(e){this._readableState&&(this._readableState.flowing=e)}}),L._fromList=be,Object.defineProperty(L.prototype,"readableLength",{enumerable:!1,get:function(){return this._readableState.length}});function be(e,t){if(t.length===0)return null;var n;return t.objectMode?n=t.buffer.shift():!e||e>=t.length?(n=t.decoder?t.buffer.join(``):t.buffer.length===1?t.buffer.first():t.buffer.concat(t.length),t.buffer.clear()):n=t.buffer.consume(e,t.decoder),n}function V(e){var t=e._readableState;m(`endReadable`,t.endEmitted),t.endEmitted||(t.ended=!0,T.nextTick(xe,t,e))}function xe(e,t){if(m(`endReadableNT`,e.endEmitted,e.length),!e.endEmitted&&e.length===0&&(e.endEmitted=!0,t.readable=!1,t.emit(`end`),e.autoDestroy)){var n=t._writableState;(!n||n.autoDestroy&&n.finished)&&t.destroy()}}typeof Symbol==`function`&&(L.from=function(e,t){return ne===void 0&&(ne=F()),ne(L,e,t)});function Se(e,t){for(var n=0,r=e.length;n<r;n++)if(e[n]===t)return n;return-1}})),L=n(((e,t)=>{t.exports=u;var n=j().codes,r=n.ERR_METHOD_NOT_IMPLEMENTED,a=n.ERR_MULTIPLE_CALLBACK,o=n.ERR_TRANSFORM_ALREADY_TRANSFORMING,s=n.ERR_TRANSFORM_WITH_LENGTH_0,c=re();i()(u,c);function l(e,t){var n=this._transformState;n.transforming=!1;var r=n.writecb;if(r===null)return this.emit(`error`,new a);n.writechunk=null,n.writecb=null,t!=null&&this.push(t),r(e);var i=this._readableState;i.reading=!1,(i.needReadable||i.length<i.highWaterMark)&&this._read(i.highWaterMark)}function u(e){if(!(this instanceof u))return new u(e);c.call(this,e),this._transformState={afterTransform:l.bind(this),needTransform:!1,transforming:!1,writecb:null,writechunk:null,writeencoding:null},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.on(`prefinish`,d)}function d(){var e=this;typeof this._flush==`function`&&!this._readableState.destroyed?this._flush(function(t,n){f(e,t,n)}):f(this,null,null)}u.prototype.push=function(e,t){return this._transformState.needTransform=!1,c.prototype.push.call(this,e,t)},u.prototype._transform=function(e,t,n){n(new r(`_transform()`))},u.prototype._write=function(e,t,n){var r=this._transformState;if(r.writecb=n,r.writechunk=e,r.writeencoding=t,!r.transforming){var i=this._readableState;(r.needTransform||i.needReadable||i.length<i.highWaterMark)&&this._read(i.highWaterMark)}},u.prototype._read=function(e){var t=this._transformState;t.writechunk!==null&&!t.transforming?(t.transforming=!0,this._transform(t.writechunk,t.writeencoding,t.afterTransform)):t.needTransform=!0},u.prototype._destroy=function(e,t){c.prototype._destroy.call(this,e,function(e){t(e)})};function f(e,t,n){if(t)return e.emit(`error`,t);if(n!=null&&e.push(n),e._writableState.length)throw new s;if(e._transformState.transforming)throw new o;return e.push(null)}})),oe=n(((e,t)=>{t.exports=r;var n=L();i()(r,n);function r(e){if(!(this instanceof r))return new r(e);n.call(this,e)}r.prototype._transform=function(e,t,n){n(null,e)}})),se=n(((e,t)=>{var n;function r(e){var t=!1;return function(){t||(t=!0,e.apply(void 0,arguments))}}var i=j().codes,a=i.ERR_MISSING_ARGS,o=i.ERR_STREAM_DESTROYED;function s(e){if(e)throw e}function c(e){return e.setHeader&&typeof e.abort==`function`}function l(e,t,i,a){a=r(a);var s=!1;e.on(`close`,function(){s=!0}),n===void 0&&(n=ae()),n(e,{readable:t,writable:i},function(e){if(e)return a(e);s=!0,a()});var l=!1;return function(t){if(!s&&!l){if(l=!0,c(e))return e.abort();if(typeof e.destroy==`function`)return e.destroy();a(t||new o(`pipe`))}}}function u(e){e()}function d(e,t){return e.pipe(t)}function f(e){return!e.length||typeof e[e.length-1]!=`function`?s:e.pop()}function p(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];var r=f(t);if(Array.isArray(t[0])&&(t=t[0]),t.length<2)throw new a(`streams`);var i,o=t.map(function(e,n){var a=n<t.length-1;return l(e,a,n>0,function(e){i||=e,e&&o.forEach(u),!a&&(o.forEach(u),r(i))})});return t.reduce(d)}t.exports=p})),ce=n(((e,t)=>{t.exports=a;var n=r().EventEmitter;i()(a,n),a.Readable=I(),a.Writable=M(),a.Duplex=re(),a.Transform=L(),a.PassThrough=oe(),a.finished=ae(),a.pipeline=se(),a.Stream=a;function a(){n.call(this)}a.prototype.pipe=function(e,t){var r=this;function i(t){e.writable&&!1===e.write(t)&&r.pause&&r.pause()}r.on(`data`,i);function a(){r.readable&&r.resume&&r.resume()}e.on(`drain`,a),!e._isStdio&&(!t||t.end!==!1)&&(r.on(`end`,s),r.on(`close`,c));var o=!1;function s(){o||(o=!0,e.end())}function c(){o||(o=!0,typeof e.destroy==`function`&&e.destroy())}function l(e){if(u(),n.listenerCount(this,`error`)===0)throw e}r.on(`error`,l),e.on(`error`,l);function u(){r.removeListener(`data`,i),e.removeListener(`drain`,a),r.removeListener(`end`,s),r.removeListener(`close`,c),r.removeListener(`error`,l),e.removeListener(`error`,l),r.removeListener(`end`,u),r.removeListener(`close`,u),e.removeListener(`close`,u)}return r.on(`end`,u),r.on(`close`,u),e.on(`close`,u),e.emit(`pipe`,r),e}}))(),le=`useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict`,ue=(e=21)=>{let t=``,n=crypto.getRandomValues(new Uint8Array(e|=0));for(;e--;)t+=le[n[e]&63];return t},R={},de={};de.byteLength=_e,de.toByteArray=ye,de.fromByteArray=xe;for(var z=[],B=[],fe=typeof Uint8Array<`u`?Uint8Array:Array,pe=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/`,me=0,he=pe.length;me<he;++me)z[me]=pe[me],B[pe.charCodeAt(me)]=me;B[45]=62,B[95]=63;function ge(e){var t=e.length;if(t%4>0)throw Error(`Invalid string. Length must be a multiple of 4`);var n=e.indexOf(`=`);n===-1&&(n=t);var r=n===t?0:4-n%4;return[n,r]}function _e(e){var t=ge(e),n=t[0],r=t[1];return(n+r)*3/4-r}function ve(e,t,n){return(t+n)*3/4-n}function ye(e){var t,n=ge(e),r=n[0],i=n[1],a=new fe(ve(e,r,i)),o=0,s=i>0?r-4:r,c;for(c=0;c<s;c+=4)t=B[e.charCodeAt(c)]<<18|B[e.charCodeAt(c+1)]<<12|B[e.charCodeAt(c+2)]<<6|B[e.charCodeAt(c+3)],a[o++]=t>>16&255,a[o++]=t>>8&255,a[o++]=t&255;return i===2&&(t=B[e.charCodeAt(c)]<<2|B[e.charCodeAt(c+1)]>>4,a[o++]=t&255),i===1&&(t=B[e.charCodeAt(c)]<<10|B[e.charCodeAt(c+1)]<<4|B[e.charCodeAt(c+2)]>>2,a[o++]=t>>8&255,a[o++]=t&255),a}function be(e){return z[e>>18&63]+z[e>>12&63]+z[e>>6&63]+z[e&63]}function V(e,t,n){for(var r,i=[],a=t;a<n;a+=3)r=(e[a]<<16&16711680)+(e[a+1]<<8&65280)+(e[a+2]&255),i.push(be(r));return i.join(``)}function xe(e){for(var t,n=e.length,r=n%3,i=[],a=16383,o=0,s=n-r;o<s;o+=a)i.push(V(e,o,o+a>s?s:o+a));return r===1?(t=e[n-1],i.push(z[t>>2]+z[t<<4&63]+`==`)):r===2&&(t=(e[n-2]<<8)+e[n-1],i.push(z[t>>10]+z[t>>4&63]+z[t<<2&63]+`=`)),i.join(``)}var Se={};Se.read=function(e,t,n,r,i){var a,o,s=i*8-r-1,c=(1<<s)-1,l=c>>1,u=-7,d=n?i-1:0,f=n?-1:1,p=e[t+d];for(d+=f,a=p&(1<<-u)-1,p>>=-u,u+=s;u>0;a=a*256+e[t+d],d+=f,u-=8);for(o=a&(1<<-u)-1,a>>=-u,u+=r;u>0;o=o*256+e[t+d],d+=f,u-=8);if(a===0)a=1-l;else if(a===c)return o?NaN:(p?-1:1)*(1/0);else o+=2**r,a-=l;return(p?-1:1)*o*2**(a-r)},Se.write=function(e,t,n,r,i,a){var o,s,c,l=a*8-i-1,u=(1<<l)-1,d=u>>1,f=i===23?2**-24-2**-77:0,p=r?0:a-1,m=r?1:-1,h=+(t<0||t===0&&1/t<0);for(t=Math.abs(t),isNaN(t)||t===1/0?(s=+!!isNaN(t),o=u):(o=Math.floor(Math.log(t)/Math.LN2),t*(c=2**-o)<1&&(o--,c*=2),o+d>=1?t+=f/c:t+=f*2**(1-d),t*c>=2&&(o++,c/=2),o+d>=u?(s=0,o=u):o+d>=1?(s=(t*c-1)*2**i,o+=d):(s=t*2**(d-1)*2**i,o=0));i>=8;e[n+p]=s&255,p+=m,s/=256,i-=8);for(o=o<<i|s,l+=i;l>0;e[n+p]=o&255,p+=m,o/=256,l-=8);e[n+p-m]|=h*128},(function(e){let t=de,n=Se,r=typeof Symbol==`function`&&typeof Symbol.for==`function`?Symbol.for(`nodejs.util.inspect.custom`):null;e.Buffer=u,e.SlowBuffer=x,e.INSPECT_MAX_BYTES=50;let i=2147483647;e.kMaxLength=i;let{Uint8Array:a,ArrayBuffer:o,SharedArrayBuffer:s}=globalThis;u.TYPED_ARRAY_SUPPORT=c(),!u.TYPED_ARRAY_SUPPORT&&typeof console<`u`&&typeof console.error==`function`&&console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support.");function c(){try{let e=new a(1),t={foo:function(){return 42}};return Object.setPrototypeOf(t,a.prototype),Object.setPrototypeOf(e,t),e.foo()===42}catch{return!1}}Object.defineProperty(u.prototype,"parent",{enumerable:!0,get:function(){if(u.isBuffer(this))return this.buffer}}),Object.defineProperty(u.prototype,"offset",{enumerable:!0,get:function(){if(u.isBuffer(this))return this.byteOffset}});function l(e){if(e>i)throw RangeError(`The value "`+e+`" is invalid for option "size"`);let t=new a(e);return Object.setPrototypeOf(t,u.prototype),t}function u(e,t,n){if(typeof e==`number`){if(typeof t==`string`)throw TypeError(`The "string" argument must be of type string. Received type number`);return m(e)}return d(e,t,n)}u.poolSize=8192;function d(e,t,n){if(typeof e==`string`)return h(e,t);if(o.isView(e))return _(e);if(e==null)throw TypeError(`The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type `+typeof e);if(V(e,o)||e&&V(e.buffer,o)||s!==void 0&&(V(e,s)||e&&V(e.buffer,s)))return v(e,t,n);if(typeof e==`number`)throw TypeError(`The "value" argument must not be of type number. Received type number`);let r=e.valueOf&&e.valueOf();if(r!=null&&r!==e)return u.from(r,t,n);let i=y(e);if(i)return i;if(typeof Symbol<`u`&&Symbol.toPrimitive!=null&&typeof e[Symbol.toPrimitive]==`function`)return u.from(e[Symbol.toPrimitive](`string`),t,n);throw TypeError(`The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type `+typeof e)}u.from=function(e,t,n){return d(e,t,n)},Object.setPrototypeOf(u.prototype,a.prototype),Object.setPrototypeOf(u,a);function f(e){if(typeof e!=`number`)throw TypeError(`"size" argument must be of type number`);if(e<0)throw RangeError(`The value "`+e+`" is invalid for option "size"`)}function p(e,t,n){return f(e),e<=0||t===void 0?l(e):typeof n==`string`?l(e).fill(t,n):l(e).fill(t)}u.alloc=function(e,t,n){return p(e,t,n)};function m(e){return f(e),l(e<0?0:b(e)|0)}u.allocUnsafe=function(e){return m(e)},u.allocUnsafeSlow=function(e){return m(e)};function h(e,t){if((typeof t!=`string`||t===``)&&(t=`utf8`),!u.isEncoding(t))throw TypeError(`Unknown encoding: `+t);let n=S(e,t)|0,r=l(n),i=r.write(e,t);return i!==n&&(r=r.slice(0,i)),r}function g(e){let t=e.length<0?0:b(e.length)|0,n=l(t);for(let r=0;r<t;r+=1)n[r]=e[r]&255;return n}function _(e){if(V(e,a)){let t=new a(e);return v(t.buffer,t.byteOffset,t.byteLength)}return g(e)}function v(e,t,n){if(t<0||e.byteLength<t)throw RangeError(`"offset" is outside of buffer bounds`);if(e.byteLength<t+(n||0))throw RangeError(`"length" is outside of buffer bounds`);let r;return r=t===void 0&&n===void 0?new a(e):n===void 0?new a(e,t):new a(e,t,n),Object.setPrototypeOf(r,u.prototype),r}function y(e){if(u.isBuffer(e)){let t=b(e.length)|0,n=l(t);return n.length===0||e.copy(n,0,0,t),n}if(e.length!==void 0)return typeof e.length!=`number`||xe(e.length)?l(0):g(e);if(e.type===`Buffer`&&Array.isArray(e.data))return g(e.data)}function b(e){if(e>=i)throw RangeError(`Attempt to allocate Buffer larger than maximum size: 0x`+i.toString(16)+` bytes`);return e|0}function x(e){return+e!=e&&(e=0),u.alloc(+e)}u.isBuffer=function(e){return e!=null&&e._isBuffer===!0&&e!==u.prototype},u.compare=function(e,t){if(V(e,a)&&(e=u.from(e,e.offset,e.byteLength)),V(t,a)&&(t=u.from(t,t.offset,t.byteLength)),!u.isBuffer(e)||!u.isBuffer(t))throw TypeError(`The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array`);if(e===t)return 0;let n=e.length,r=t.length;for(let i=0,a=Math.min(n,r);i<a;++i)if(e[i]!==t[i]){n=e[i],r=t[i];break}return n<r?-1:+(r<n)},u.isEncoding=function(e){switch(String(e).toLowerCase()){case`hex`:case`utf8`:case`utf-8`:case`ascii`:case`latin1`:case`binary`:case`base64`:case`ucs2`:case`ucs-2`:case`utf16le`:case`utf-16le`:return!0;default:return!1}},u.concat=function(e,t){if(!Array.isArray(e))throw TypeError(`"list" argument must be an Array of Buffers`);if(e.length===0)return u.alloc(0);let n;if(t===void 0)for(t=0,n=0;n<e.length;++n)t+=e[n].length;let r=u.allocUnsafe(t),i=0;for(n=0;n<e.length;++n){let t=e[n];if(V(t,a))i+t.length>r.length?(u.isBuffer(t)||(t=u.from(t)),t.copy(r,i)):a.prototype.set.call(r,t,i);else if(u.isBuffer(t))t.copy(r,i);else throw TypeError(`"list" argument must be an Array of Buffers`);i+=t.length}return r};function S(e,t){if(u.isBuffer(e))return e.length;if(o.isView(e)||V(e,o))return e.byteLength;if(typeof e!=`string`)throw TypeError(`The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type `+typeof e);let n=e.length,r=arguments.length>2&&arguments[2]===!0;if(!r&&n===0)return 0;let i=!1;for(;;)switch(t){case`ascii`:case`latin1`:case`binary`:return n;case`utf8`:case`utf-8`:return ge(e).length;case`ucs2`:case`ucs-2`:case`utf16le`:case`utf-16le`:return n*2;case`hex`:return n>>>1;case`base64`:return ye(e).length;default:if(i)return r?-1:ge(e).length;t=(``+t).toLowerCase(),i=!0}}u.byteLength=S;function C(e,t,n){let r=!1;if((t===void 0||t<0)&&(t=0),t>this.length||((n===void 0||n>this.length)&&(n=this.length),n<=0)||(n>>>=0,t>>>=0,n<=t))return``;for(e||=`utf8`;;)switch(e){case`hex`:return ie(this,t,n);case`utf8`:case`utf-8`:return te(this,t,n);case`ascii`:return re(this,t,n);case`latin1`:case`binary`:return N(this,t,n);case`base64`:return j(this,t,n);case`ucs2`:case`ucs-2`:case`utf16le`:case`utf-16le`:return ae(this,t,n);default:if(r)throw TypeError(`Unknown encoding: `+e);e=(e+``).toLowerCase(),r=!0}}u.prototype._isBuffer=!0;function w(e,t,n){let r=e[t];e[t]=e[n],e[n]=r}u.prototype.swap16=function(){let e=this.length;if(e%2!=0)throw RangeError(`Buffer size must be a multiple of 16-bits`);for(let t=0;t<e;t+=2)w(this,t,t+1);return this},u.prototype.swap32=function(){let e=this.length;if(e%4!=0)throw RangeError(`Buffer size must be a multiple of 32-bits`);for(let t=0;t<e;t+=4)w(this,t,t+3),w(this,t+1,t+2);return this},u.prototype.swap64=function(){let e=this.length;if(e%8!=0)throw RangeError(`Buffer size must be a multiple of 64-bits`);for(let t=0;t<e;t+=8)w(this,t,t+7),w(this,t+1,t+6),w(this,t+2,t+5),w(this,t+3,t+4);return this},u.prototype.toString=function(){let e=this.length;return e===0?``:arguments.length===0?te(this,0,e):C.apply(this,arguments)},u.prototype.toLocaleString=u.prototype.toString,u.prototype.equals=function(e){if(!u.isBuffer(e))throw TypeError(`Argument must be a Buffer`);return this===e||u.compare(this,e)===0},u.prototype.inspect=function(){let t=``,n=e.INSPECT_MAX_BYTES;return t=this.toString(`hex`,0,n).replace(/(.{2})/g,`$1 `).trim(),this.length>n&&(t+=` ... `),`<Buffer `+t+`>`},r&&(u.prototype[r]=u.prototype.inspect),u.prototype.compare=function(e,t,n,r,i){if(V(e,a)&&(e=u.from(e,e.offset,e.byteLength)),!u.isBuffer(e))throw TypeError(`The "target" argument must be one of type Buffer or Uint8Array. Received type `+typeof e);if(t===void 0&&(t=0),n===void 0&&(n=e?e.length:0),r===void 0&&(r=0),i===void 0&&(i=this.length),t<0||n>e.length||r<0||i>this.length)throw RangeError(`out of range index`);if(r>=i&&t>=n)return 0;if(r>=i)return-1;if(t>=n)return 1;if(t>>>=0,n>>>=0,r>>>=0,i>>>=0,this===e)return 0;let o=i-r,s=n-t,c=Math.min(o,s),l=this.slice(r,i),d=e.slice(t,n);for(let e=0;e<c;++e)if(l[e]!==d[e]){o=l[e],s=d[e];break}return o<s?-1:+(s<o)};function T(e,t,n,r,i){if(e.length===0)return-1;if(typeof n==`string`?(r=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),n=+n,xe(n)&&(n=i?0:e.length-1),n<0&&(n=e.length+n),n>=e.length){if(i)return-1;n=e.length-1}else if(n<0){if(i)n=0;else return-1}if(typeof t==`string`&&(t=u.from(t,r)),u.isBuffer(t))return t.length===0?-1:E(e,t,n,r,i);if(typeof t==`number`)return t&=255,typeof a.prototype.indexOf==`function`?i?a.prototype.indexOf.call(e,t,n):a.prototype.lastIndexOf.call(e,t,n):E(e,[t],n,r,i);throw TypeError(`val must be string, number or Buffer`)}function E(e,t,n,r,i){let a=1,o=e.length,s=t.length;if(r!==void 0&&(r=String(r).toLowerCase(),r===`ucs2`||r===`ucs-2`||r===`utf16le`||r===`utf-16le`)){if(e.length<2||t.length<2)return-1;a=2,o/=2,s/=2,n/=2}function c(e,t){return a===1?e[t]:e.readUInt16BE(t*a)}let l;if(i){let r=-1;for(l=n;l<o;l++)if(c(e,l)===c(t,r===-1?0:l-r)){if(r===-1&&(r=l),l-r+1===s)return r*a}else r!==-1&&(l-=l-r),r=-1}else for(n+s>o&&(n=o-s),l=n;l>=0;l--){let n=!0;for(let r=0;r<s;r++)if(c(e,l+r)!==c(t,r)){n=!1;break}if(n)return l}return-1}u.prototype.includes=function(e,t,n){return this.indexOf(e,t,n)!==-1},u.prototype.indexOf=function(e,t,n){return T(this,e,t,n,!0)},u.prototype.lastIndexOf=function(e,t,n){return T(this,e,t,n,!1)};function D(e,t,n,r){n=Number(n)||0;let i=e.length-n;r?(r=Number(r),r>i&&(r=i)):r=i;let a=t.length;r>a/2&&(r=a/2);let o;for(o=0;o<r;++o){let r=parseInt(t.substr(o*2,2),16);if(xe(r))return o;e[n+o]=r}return o}function O(e,t,n,r){return be(ge(t,e.length-n),e,n,r)}function k(e,t,n,r){return be(_e(t),e,n,r)}function A(e,t,n,r){return be(ye(t),e,n,r)}function ee(e,t,n,r){return be(ve(t,e.length-n),e,n,r)}u.prototype.write=function(e,t,n,r){if(t===void 0)r=`utf8`,n=this.length,t=0;else if(n===void 0&&typeof t==`string`)r=t,n=this.length,t=0;else if(isFinite(t))t>>>=0,isFinite(n)?(n>>>=0,r===void 0&&(r=`utf8`)):(r=n,n=void 0);else throw Error(`Buffer.write(string, encoding, offset[, length]) is no longer supported`);let i=this.length-t;if((n===void 0||n>i)&&(n=i),e.length>0&&(n<0||t<0)||t>this.length)throw RangeError(`Attempt to write outside buffer bounds`);r||=`utf8`;let a=!1;for(;;)switch(r){case`hex`:return D(this,e,t,n);case`utf8`:case`utf-8`:return O(this,e,t,n);case`ascii`:case`latin1`:case`binary`:return k(this,e,t,n);case`base64`:return A(this,e,t,n);case`ucs2`:case`ucs-2`:case`utf16le`:case`utf-16le`:return ee(this,e,t,n);default:if(a)throw TypeError(`Unknown encoding: `+r);r=(``+r).toLowerCase(),a=!0}},u.prototype.toJSON=function(){return{type:`Buffer`,data:Array.prototype.slice.call(this._arr||this,0)}};function j(e,n,r){return n===0&&r===e.length?t.fromByteArray(e):t.fromByteArray(e.slice(n,r))}function te(e,t,n){n=Math.min(e.length,n);let r=[],i=t;for(;i<n;){let t=e[i],a=null,o=t>239?4:t>223?3:t>191?2:1;if(i+o<=n){let n,r,s,c;switch(o){case 1:t<128&&(a=t);break;case 2:n=e[i+1],(n&192)==128&&(c=(t&31)<<6|n&63,c>127&&(a=c));break;case 3:n=e[i+1],r=e[i+2],(n&192)==128&&(r&192)==128&&(c=(t&15)<<12|(n&63)<<6|r&63,c>2047&&(c<55296||c>57343)&&(a=c));break;case 4:n=e[i+1],r=e[i+2],s=e[i+3],(n&192)==128&&(r&192)==128&&(s&192)==128&&(c=(t&15)<<18|(n&63)<<12|(r&63)<<6|s&63,c>65535&&c<1114112&&(a=c))}}a===null?(a=65533,o=1):a>65535&&(a-=65536,r.push(a>>>10&1023|55296),a=56320|a&1023),r.push(a),i+=o}return M(r)}let ne=4096;function M(e){let t=e.length;if(t<=ne)return String.fromCharCode.apply(String,e);let n=``,r=0;for(;r<t;)n+=String.fromCharCode.apply(String,e.slice(r,r+=ne));return n}function re(e,t,n){let r=``;n=Math.min(e.length,n);for(let i=t;i<n;++i)r+=String.fromCharCode(e[i]&127);return r}function N(e,t,n){let r=``;n=Math.min(e.length,n);for(let i=t;i<n;++i)r+=String.fromCharCode(e[i]);return r}function ie(e,t,n){let r=e.length;(!t||t<0)&&(t=0),(!n||n<0||n>r)&&(n=r);let i=``;for(let r=t;r<n;++r)i+=Ce[e[r]];return i}function ae(e,t,n){let r=e.slice(t,n),i=``;for(let e=0;e<r.length-1;e+=2)i+=String.fromCharCode(r[e]+r[e+1]*256);return i}u.prototype.slice=function(e,t){let n=this.length;e=~~e,t=t===void 0?n:~~t,e<0?(e+=n,e<0&&(e=0)):e>n&&(e=n),t<0?(t+=n,t<0&&(t=0)):t>n&&(t=n),t<e&&(t=e);let r=this.subarray(e,t);return Object.setPrototypeOf(r,u.prototype),r};function P(e,t,n){if(e%1!=0||e<0)throw RangeError(`offset is not uint`);if(e+t>n)throw RangeError(`Trying to access beyond buffer length`)}u.prototype.readUintLE=u.prototype.readUIntLE=function(e,t,n){e>>>=0,t>>>=0,n||P(e,t,this.length);let r=this[e],i=1,a=0;for(;++a<t&&(i*=256);)r+=this[e+a]*i;return r},u.prototype.readUintBE=u.prototype.readUIntBE=function(e,t,n){e>>>=0,t>>>=0,n||P(e,t,this.length);let r=this[e+--t],i=1;for(;t>0&&(i*=256);)r+=this[e+--t]*i;return r},u.prototype.readUint8=u.prototype.readUInt8=function(e,t){return e>>>=0,t||P(e,1,this.length),this[e]},u.prototype.readUint16LE=u.prototype.readUInt16LE=function(e,t){return e>>>=0,t||P(e,2,this.length),this[e]|this[e+1]<<8},u.prototype.readUint16BE=u.prototype.readUInt16BE=function(e,t){return e>>>=0,t||P(e,2,this.length),this[e]<<8|this[e+1]},u.prototype.readUint32LE=u.prototype.readUInt32LE=function(e,t){return e>>>=0,t||P(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+this[e+3]*16777216},u.prototype.readUint32BE=u.prototype.readUInt32BE=function(e,t){return e>>>=0,t||P(e,4,this.length),this[e]*16777216+(this[e+1]<<16|this[e+2]<<8|this[e+3])},u.prototype.readBigUInt64LE=H(function(e){e>>>=0,fe(e,`offset`);let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&pe(e,this.length-8);let r=t+this[++e]*256+this[++e]*2**16+this[++e]*2**24,i=this[++e]+this[++e]*256+this[++e]*2**16+n*2**24;return BigInt(r)+(BigInt(i)<<BigInt(32))}),u.prototype.readBigUInt64BE=H(function(e){e>>>=0,fe(e,`offset`);let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&pe(e,this.length-8);let r=t*2**24+this[++e]*2**16+this[++e]*256+this[++e],i=this[++e]*2**24+this[++e]*2**16+this[++e]*256+n;return(BigInt(r)<<BigInt(32))+BigInt(i)}),u.prototype.readIntLE=function(e,t,n){e>>>=0,t>>>=0,n||P(e,t,this.length);let r=this[e],i=1,a=0;for(;++a<t&&(i*=256);)r+=this[e+a]*i;return i*=128,r>=i&&(r-=2**(8*t)),r},u.prototype.readIntBE=function(e,t,n){e>>>=0,t>>>=0,n||P(e,t,this.length);let r=t,i=1,a=this[e+--r];for(;r>0&&(i*=256);)a+=this[e+--r]*i;return i*=128,a>=i&&(a-=2**(8*t)),a},u.prototype.readInt8=function(e,t){return e>>>=0,t||P(e,1,this.length),this[e]&128?(255-this[e]+1)*-1:this[e]},u.prototype.readInt16LE=function(e,t){e>>>=0,t||P(e,2,this.length);let n=this[e]|this[e+1]<<8;return n&32768?n|4294901760:n},u.prototype.readInt16BE=function(e,t){e>>>=0,t||P(e,2,this.length);let n=this[e+1]|this[e]<<8;return n&32768?n|4294901760:n},u.prototype.readInt32LE=function(e,t){return e>>>=0,t||P(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},u.prototype.readInt32BE=function(e,t){return e>>>=0,t||P(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},u.prototype.readBigInt64LE=H(function(e){e>>>=0,fe(e,`offset`);let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&pe(e,this.length-8);let r=this[e+4]+this[e+5]*256+this[e+6]*2**16+(n<<24);return(BigInt(r)<<BigInt(32))+BigInt(t+this[++e]*256+this[++e]*2**16+this[++e]*2**24)}),u.prototype.readBigInt64BE=H(function(e){e>>>=0,fe(e,`offset`);let t=this[e],n=this[e+7];(t===void 0||n===void 0)&&pe(e,this.length-8);let r=(t<<24)+this[++e]*2**16+this[++e]*256+this[++e];return(BigInt(r)<<BigInt(32))+BigInt(this[++e]*2**24+this[++e]*2**16+this[++e]*256+n)}),u.prototype.readFloatLE=function(e,t){return e>>>=0,t||P(e,4,this.length),n.read(this,e,!0,23,4)},u.prototype.readFloatBE=function(e,t){return e>>>=0,t||P(e,4,this.length),n.read(this,e,!1,23,4)},u.prototype.readDoubleLE=function(e,t){return e>>>=0,t||P(e,8,this.length),n.read(this,e,!0,52,8)},u.prototype.readDoubleBE=function(e,t){return e>>>=0,t||P(e,8,this.length),n.read(this,e,!1,52,8)};function F(e,t,n,r,i,a){if(!u.isBuffer(e))throw TypeError(`"buffer" argument must be a Buffer instance`);if(t>i||t<a)throw RangeError(`"value" argument is out of bounds`);if(n+r>e.length)throw RangeError(`Index out of range`)}u.prototype.writeUintLE=u.prototype.writeUIntLE=function(e,t,n,r){if(e=+e,t>>>=0,n>>>=0,!r){let r=2**(8*n)-1;F(this,e,t,n,r,0)}let i=1,a=0;for(this[t]=e&255;++a<n&&(i*=256);)this[t+a]=e/i&255;return t+n},u.prototype.writeUintBE=u.prototype.writeUIntBE=function(e,t,n,r){if(e=+e,t>>>=0,n>>>=0,!r){let r=2**(8*n)-1;F(this,e,t,n,r,0)}let i=n-1,a=1;for(this[t+i]=e&255;--i>=0&&(a*=256);)this[t+i]=e/a&255;return t+n},u.prototype.writeUint8=u.prototype.writeUInt8=function(e,t,n){return e=+e,t>>>=0,n||F(this,e,t,1,255,0),this[t]=e&255,t+1},u.prototype.writeUint16LE=u.prototype.writeUInt16LE=function(e,t,n){return e=+e,t>>>=0,n||F(this,e,t,2,65535,0),this[t]=e&255,this[t+1]=e>>>8,t+2},u.prototype.writeUint16BE=u.prototype.writeUInt16BE=function(e,t,n){return e=+e,t>>>=0,n||F(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=e&255,t+2},u.prototype.writeUint32LE=u.prototype.writeUInt32LE=function(e,t,n){return e=+e,t>>>=0,n||F(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=e&255,t+4},u.prototype.writeUint32BE=u.prototype.writeUInt32BE=function(e,t,n){return e=+e,t>>>=0,n||F(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e&255,t+4};function I(e,t,n,r,i){B(t,r,i,e,n,7);let a=Number(t&BigInt(4294967295));e[n++]=a,a>>=8,e[n++]=a,a>>=8,e[n++]=a,a>>=8,e[n++]=a;let o=Number(t>>BigInt(32)&BigInt(4294967295));return e[n++]=o,o>>=8,e[n++]=o,o>>=8,e[n++]=o,o>>=8,e[n++]=o,n}function L(e,t,n,r,i){B(t,r,i,e,n,7);let a=Number(t&BigInt(4294967295));e[n+7]=a,a>>=8,e[n+6]=a,a>>=8,e[n+5]=a,a>>=8,e[n+4]=a;let o=Number(t>>BigInt(32)&BigInt(4294967295));return e[n+3]=o,o>>=8,e[n+2]=o,o>>=8,e[n+1]=o,o>>=8,e[n]=o,n+8}u.prototype.writeBigUInt64LE=H(function(e,t=0){return I(this,e,t,BigInt(0),BigInt(`0xffffffffffffffff`))}),u.prototype.writeBigUInt64BE=H(function(e,t=0){return L(this,e,t,BigInt(0),BigInt(`0xffffffffffffffff`))}),u.prototype.writeIntLE=function(e,t,n,r){if(e=+e,t>>>=0,!r){let r=2**(8*n-1);F(this,e,t,n,r-1,-r)}let i=0,a=1,o=0;for(this[t]=e&255;++i<n&&(a*=256);)e<0&&o===0&&this[t+i-1]!==0&&(o=1),this[t+i]=(e/a>>0)-o&255;return t+n},u.prototype.writeIntBE=function(e,t,n,r){if(e=+e,t>>>=0,!r){let r=2**(8*n-1);F(this,e,t,n,r-1,-r)}let i=n-1,a=1,o=0;for(this[t+i]=e&255;--i>=0&&(a*=256);)e<0&&o===0&&this[t+i+1]!==0&&(o=1),this[t+i]=(e/a>>0)-o&255;return t+n},u.prototype.writeInt8=function(e,t,n){return e=+e,t>>>=0,n||F(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=e&255,t+1},u.prototype.writeInt16LE=function(e,t,n){return e=+e,t>>>=0,n||F(this,e,t,2,32767,-32768),this[t]=e&255,this[t+1]=e>>>8,t+2},u.prototype.writeInt16BE=function(e,t,n){return e=+e,t>>>=0,n||F(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=e&255,t+2},u.prototype.writeInt32LE=function(e,t,n){return e=+e,t>>>=0,n||F(this,e,t,4,2147483647,-2147483648),this[t]=e&255,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4},u.prototype.writeInt32BE=function(e,t,n){return e=+e,t>>>=0,n||F(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e&255,t+4},u.prototype.writeBigInt64LE=H(function(e,t=0){return I(this,e,t,-BigInt(`0x8000000000000000`),BigInt(`0x7fffffffffffffff`))}),u.prototype.writeBigInt64BE=H(function(e,t=0){return L(this,e,t,-BigInt(`0x8000000000000000`),BigInt(`0x7fffffffffffffff`))});function oe(e,t,n,r,i,a){if(n+r>e.length||n<0)throw RangeError(`Index out of range`)}function se(e,t,r,i,a){return t=+t,r>>>=0,a||oe(e,t,r,4),n.write(e,t,r,i,23,4),r+4}u.prototype.writeFloatLE=function(e,t,n){return se(this,e,t,!0,n)},u.prototype.writeFloatBE=function(e,t,n){return se(this,e,t,!1,n)};function ce(e,t,r,i,a){return t=+t,r>>>=0,a||oe(e,t,r,8),n.write(e,t,r,i,52,8),r+8}u.prototype.writeDoubleLE=function(e,t,n){return ce(this,e,t,!0,n)},u.prototype.writeDoubleBE=function(e,t,n){return ce(this,e,t,!1,n)},u.prototype.copy=function(e,t,n,r){if(!u.isBuffer(e))throw TypeError(`argument should be a Buffer`);if(n||=0,!r&&r!==0&&(r=this.length),t>=e.length&&(t=e.length),t||=0,r>0&&r<n&&(r=n),r===n||e.length===0||this.length===0)return 0;if(t<0)throw RangeError(`targetStart out of bounds`);if(n<0||n>=this.length)throw RangeError(`Index out of range`);if(r<0)throw RangeError(`sourceEnd out of bounds`);r>this.length&&(r=this.length),e.length-t<r-n&&(r=e.length-t+n);let i=r-n;return this===e&&typeof a.prototype.copyWithin==`function`?this.copyWithin(t,n,r):a.prototype.set.call(e,this.subarray(n,r),t),i},u.prototype.fill=function(e,t,n,r){if(typeof e==`string`){if(typeof t==`string`?(r=t,t=0,n=this.length):typeof n==`string`&&(r=n,n=this.length),r!==void 0&&typeof r!=`string`)throw TypeError(`encoding must be a string`);if(typeof r==`string`&&!u.isEncoding(r))throw TypeError(`Unknown encoding: `+r);if(e.length===1){let t=e.charCodeAt(0);(r===`utf8`&&t<128||r===`latin1`)&&(e=t)}}else typeof e==`number`?e&=255:typeof e==`boolean`&&(e=Number(e));if(t<0||this.length<t||this.length<n)throw RangeError(`Out of range index`);if(n<=t)return this;t>>>=0,n=n===void 0?this.length:n>>>0,e||=0;let i;if(typeof e==`number`)for(i=t;i<n;++i)this[i]=e;else{let a=u.isBuffer(e)?e:u.from(e,r),o=a.length;if(o===0)throw TypeError(`The value "`+e+`" is invalid for argument "value"`);for(i=0;i<n-t;++i)this[i+t]=a[i%o]}return this};let le={};function ue(e,t,n){le[e]=class extends n{constructor(){super(),Object.defineProperty(this,"message",{value:t.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${e}]`,this.stack,delete this.name}get code(){return e}set code(e){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:e,writable:!0})}toString(){return`${this.name} [${e}]: ${this.message}`}}}ue(`ERR_BUFFER_OUT_OF_BOUNDS`,function(e){return e?`${e} is outside of buffer bounds`:`Attempt to access memory outside buffer bounds`},RangeError),ue(`ERR_INVALID_ARG_TYPE`,function(e,t){return`The "${e}" argument must be of type number. Received type ${typeof t}`},TypeError),ue(`ERR_OUT_OF_RANGE`,function(e,t,n){let r=`The value of "${e}" is out of range.`,i=n;return Number.isInteger(n)&&Math.abs(n)>2**32?i=R(String(n)):typeof n==`bigint`&&(i=String(n),(n>BigInt(2)**BigInt(32)||n<-(BigInt(2)**BigInt(32)))&&(i=R(i)),i+=`n`),r+=` It must be ${t}. Received ${i}`,r},RangeError);function R(e){let t=``,n=e.length,r=+(e[0]===`-`);for(;n>=r+4;n-=3)t=`_${e.slice(n-3,n)}${t}`;return`${e.slice(0,n)}${t}`}function z(e,t,n){fe(t,`offset`),(e[t]===void 0||e[t+n]===void 0)&&pe(t,e.length-(n+1))}function B(e,t,n,r,i,a){if(e>n||e<t){let r=typeof t==`bigint`?`n`:``,i;throw i=a>3?t===0||t===BigInt(0)?`>= 0${r} and < 2${r} ** ${(a+1)*8}${r}`:`>= -(2${r} ** ${(a+1)*8-1}${r}) and < 2 ** ${(a+1)*8-1}${r}`:`>= ${t}${r} and <= ${n}${r}`,new le.ERR_OUT_OF_RANGE(`value`,i,e)}z(r,i,a)}function fe(e,t){if(typeof e!=`number`)throw new le.ERR_INVALID_ARG_TYPE(t,`number`,e)}function pe(e,t,n){throw Math.floor(e)===e?t<0?new le.ERR_BUFFER_OUT_OF_BOUNDS:new le.ERR_OUT_OF_RANGE(n||`offset`,`>= ${+!!n} and <= ${t}`,e):(fe(e,n),new le.ERR_OUT_OF_RANGE(n||`offset`,`an integer`,e))}let me=/[^+/0-9A-Za-z-_]/g;function he(e){if(e=e.split(`=`)[0],e=e.trim().replace(me,``),e.length<2)return``;for(;e.length%4!=0;)e+=`=`;return e}function ge(e,t){t||=1/0;let n,r=e.length,i=null,a=[];for(let o=0;o<r;++o){if(n=e.charCodeAt(o),n>55295&&n<57344){if(!i){if(n>56319){(t-=3)>-1&&a.push(239,191,189);continue}if(o+1===r){(t-=3)>-1&&a.push(239,191,189);continue}i=n;continue}if(n<56320){(t-=3)>-1&&a.push(239,191,189),i=n;continue}n=(i-55296<<10|n-56320)+65536}else i&&(t-=3)>-1&&a.push(239,191,189);if(i=null,n<128){if(--t<0)break;a.push(n)}else if(n<2048){if((t-=2)<0)break;a.push(n>>6|192,n&63|128)}else if(n<65536){if((t-=3)<0)break;a.push(n>>12|224,n>>6&63|128,n&63|128)}else if(n<1114112){if((t-=4)<0)break;a.push(n>>18|240,n>>12&63|128,n>>6&63|128,n&63|128)}else throw Error(`Invalid code point`)}return a}function _e(e){let t=[];for(let n=0;n<e.length;++n)t.push(e.charCodeAt(n)&255);return t}function ve(e,t){let n,r,i,a=[];for(let o=0;o<e.length&&!((t-=2)<0);++o)n=e.charCodeAt(o),r=n>>8,i=n%256,a.push(i),a.push(r);return a}function ye(e){return t.toByteArray(he(e))}function be(e,t,n,r){let i;for(i=0;i<r&&!(i+n>=t.length||i>=e.length);++i)t[i+n]=e[i];return i}function V(e,t){return e instanceof t||e!=null&&e.constructor!=null&&e.constructor.name!=null&&e.constructor.name===t.name}function xe(e){return e!==e}let Ce=(function(){let e=`0123456789abcdef`,t=Array(256);for(let n=0;n<16;++n){let r=n*16;for(let i=0;i<16;++i)t[r+i]=e[n]+e[i]}return t})();function H(e){return typeof BigInt>`u`?we:e}function we(){throw Error(`BigInt not supported`)}})(R);var Ce=R.Buffer;R.Blob,R.BlobOptions;var H=R.Buffer;R.File,R.FileOptions,R.INSPECT_MAX_BYTES,R.SlowBuffer,R.TranscodeEncoding,R.atob,R.btoa,R.constants,R.isAscii,R.isUtf8,R.kMaxLength,R.kStringMaxLength,R.resolveObjectURL,R.transcode;var we=class e extends Promise{#e;#t;constructor(e){super(e=>{e()}),this.#e=e}static from(t){return new e(e=>{e(t())})}static resolve(t){return new e(e=>{e(t)})}static reject(t){return new e((e,n)=>{n(t)})}then(e,t){return this.#t??=new Promise(this.#e),this.#t.then(e,t)}catch(e){return this.#t??=new Promise(this.#e),this.#t.catch(e)}finally(e){return this.#t??=new Promise(this.#e),this.#t.finally(e)}},Te=we.default??we,Ee=class{constructor(e){this.waiters=[],this.aborted=!1,this.remaining=e}async acquire(e){if(this.aborted)throw Error(`credit gate aborted`);if(e?.aborted)throw e.reason??Error(`aborted`);this.remaining>0?this.remaining--:await new Promise((t,n)=>{let r=r=>{if(e&&e.removeEventListener(`abort`,i),r){n(Error(`credit gate aborted`));return}this.remaining--,t()},i=()=>{let t=this.waiters.indexOf(r);t!==-1&&this.waiters.splice(t,1),n(e?.reason??Error(`aborted`))};if(e&&e.addEventListener(`abort`,i,{once:!0}),e?.aborted){e.removeEventListener(`abort`,i),n(e.reason??Error(`aborted`));return}this.waiters.push(r)})}replenish(e){for(this.remaining+=e;this.waiters.length>0&&this.remaining>0;)this.waiters.shift()(!1)}abort(){for(this.aborted=!0;this.waiters.length>0;)this.waiters.shift()(!0)}},De=new TextEncoder;function Oe(e){let t=e.reduce((e,t)=>e+t.byteLength,0),n=new Uint8Array(t),r=0;for(let t of e)n.set(t,r),r+=t.byteLength;return n}function ke(e){let t;if(e instanceof H)t=new Uint8Array(e.buffer,e.byteOffset,e.byteLength);else if(e instanceof Uint8Array)t=e;else if(typeof e==`string`)t=De.encode(e);else throw Error(`invalid chunk type: expected Buffer, Uint8Array, or string`);return t}var Ae=class extends ce.Readable{constructor(e){let t=e?.read;super({...e,read:()=>{}}),this._chunks=[],this._collecting=!0,this._onRead=t,this.buffer=new Promise((e,t)=>{this._resolve=e,this._reject=t}),this.buffer.catch(()=>{}),this.on(`error`,e=>{this._collecting&&(this._collecting=!1,this._reject(e))})}push(e,t){return this._collecting&&(e===null?(this._collecting=!1,this._resolve(Oe(this._chunks))):e!==void 0&&this._chunks.push(ke(e))),super.push(e,t)}read(e){return this._onRead?.(e??0),super.read(e)}get collecting(){return this._collecting}stopCollecting(){this._collecting&&(this._reject(Error(`collecting stopped`)),this._collecting=!1,this._chunks.length=0)}};async function je(e,t,n,r,i){if(!(Number.isFinite(t)&&t>0))throw Error(`invalid chunk size`);if(e.byteLength===0)await n(void 0,void 0,!0);else for(let a=0;a<e.byteLength;a+=t){if(i?.aborted)throw i.reason??Error(`aborted`);let o=Math.min(e.byteLength-a,t),s=e.subarray(a,a+o),c=a+o>=e.byteLength;r&&await r.acquire(i),await n(s,void 0,c)}}async function Me(e,t,n,r,i){if(!(Number.isFinite(t)&&t>0))throw Error(`invalid chunk size`);let a;for await(let o of e){if(i?.aborted)throw i.reason??Error(`aborted`);let e=ke(o);if(e.byteLength!==0)for(let o=0;o<e.byteLength;o+=t){if(i?.aborted)throw i.reason??Error(`aborted`);let s=Math.min(e.byteLength-o,t),c=e.subarray(o,o+s);a!==void 0&&(r&&await r.acquire(i),await n(a,void 0,!1)),a=c}}if(i?.aborted)throw i.reason??Error(`aborted`);a===void 0?await n(void 0,void 0,!0):(r&&await r.acquire(i),await n(a,void 0,!0))}function Ne(e,t){if(typeof t!=`function`)return e;let n=t.length-1;return e.length>=n?e:[...e,...Array(n-e.length).fill(void 0)]}function Pe(e,t,n,r){if(!(typeof e==`object`&&e))throw Error(`invalid object`);let i,a=e[t],o=e[n];Object.defineProperty(e,t,{get:()=>{if(i===`f2`)throw Error(`field "${t}" is mutually exclusive with field "${n}" and "${n}" was already consumed`);return i||r?.(t),i=`f1`,a},set:e=>{a=e},enumerable:!1,configurable:!0}),Object.defineProperty(e,n,{get:()=>{if(i===`f1`)throw Error(`field "${n}" is mutually exclusive with field "${t}" and "${t}" was already consumed`);return i||r?.(n),i=`f2`,o},set:e=>{o=e},enumerable:!1,configurable:!0})}var Fe=class e{constructor(){this.resources=[],this.pending=null}roll(...e){let t,n;if(e.length===1)t=void 0,n=e[0];else if(e.length===2)t=e[0],n=e[1];else throw Error(`invalid number of arguments`);this.resources.push({resource:t,cleanup:n})}sub(){let t=new e;return this.roll(t,e=>e.unroll()),t}unroll(e=!0){if(this.pending!==null)return e?this.pending.catch(()=>{}):this.pending;let t=this.resources;this.resources=[];let n=[],r;for(;t.length>0;){let e=t.pop(),i=e.resource,a=e.cleanup;if(r)r=r.then(()=>a(i)).catch(e=>{n.push(e)});else try{let e=a(i);e instanceof Promise&&(r=e.catch(e=>{n.push(e)}))}catch(e){n.push(e)}}if(r)return this.pending=r.then(()=>{if(n.length===1)throw n[0];if(n.length>1)throw AggregateError(n,`multiple cleanup failures`)}).finally(()=>{this.pending=null}),e?this.pending.catch(()=>{}):this.pending;if(!e&&n.length===1)throw n[0];if(!e&&n.length>1)throw AggregateError(n,`multiple cleanup failures`)}};function U(e,t,n=!1){if(e instanceof Error&&t===void 0&&n===!1)return e;let r=e instanceof Error?e.message:String(e);if(t&&(r=`${t}: ${r}`),n&&e instanceof Error&&(r=`${r}\n${e.stack}`),e instanceof Error){let t=Error(r,{cause:e});return t.stack=e.stack,t}return Error(r)}function Ie(e,t,n){if(!t)return e?Promise.resolve():void 0;let r;try{r=t()}catch(t){if(e)return Promise.reject(U(t,n));throw U(t,n)}if(!e&&r instanceof Promise)throw Error(`onfinally callback returned Promise in non-async context`);return e&&!(r instanceof Promise)&&(r=Promise.resolve(r)),e&&r instanceof Promise?r.catch(e=>{throw U(e,n)}):r}function Le(e,t){if(!t)return e?Promise.resolve():void 0;let n=t.unroll();if(!e&&n instanceof Promise)throw Error(`spool unroll returned Promise in non-async context`);return e&&!(n instanceof Promise)&&(n=Promise.resolve(n)),n}function Re(e,t,n,r,i){if(e)return(async()=>{let e;try{await Ie(!0,r,i)}catch(t){e=U(t,i)}if((t!==void 0||e!==void 0)&&(await Le(!0,n),e!==void 0)){if(t!==void 0)t.suppressed=e;else throw e}})();{let e;try{Ie(!1,r,i)}catch(t){e=U(t,i)}if((t!==void 0||e!==void 0)&&(Le(!1,n),e!==void 0)){if(t!==void 0)t.suppressed=e;else throw e}}}function ze(e,t,n,r){let i=t=>{e.suppressed=U(t,r)},a;try{a=n?.()}catch(e){i(e)}if(a instanceof Promise)return a.catch(i).then(()=>t?.unroll()).then(()=>{throw e});let o=t?.unroll();if(o instanceof Promise)return o.then(()=>{throw e});throw e}function Be(...e){let t,n,r,i,a,o;if(e.length===1&&typeof e[0]==`object`&&e[0]!==null?(t=e[0].description,n=e[0].spool,r=e[0].action,i=e[0].oncatch,a=e[0].onfinally,o=e[0].oncleanup):typeof e[0]==`string`?(t=e[0],e[1]instanceof Fe||e[1]===void 0&&typeof e[2]==`function`?(n=e[1],r=e[2],i=e[3],a=e[4],o=e[5]):(r=e[1],i=e[2],a=e[3],o=e[4])):e[0]instanceof Fe||e[0]===void 0&&typeof e[1]==`function`?(n=e[0],r=e[1],i=e[2],a=e[3],o=e[4]):(r=e[0],i=e[1],a=e[2],o=e[3]),o&&!n)throw Error(`oncleanup requires a spool`);let s;try{s=r()}catch(e){let r=U(e,t);if(!i)return ze(r,n,a,t);try{s=i(r)}catch(e){return ze(U(e,t),n,a,t)}i=void 0}return s instanceof Promise?s.then(async e=>(n&&o&&n.roll(e,o),await Re(!0,void 0,n,a,t),e),async e=>{let r=U(e,t);if(i){let e;try{e=await i(r)}catch(e){throw r=U(e,t),await Re(!0,r,n,a,t),r}return n&&o&&n.roll(e,o),await Re(!0,void 0,n,a,t),e}throw await Re(!0,r,n,a,t),r}):(n&&o&&n.roll(s,o),Re(!1,void 0,n,a,t),s)}var Ve=new TextEncoder,He=new TextDecoder,Ue=new TextDecoder(`utf-8`,{fatal:!0});function We(...e){let t=e.reduce((e,{length:t})=>e+t,0),n=new Uint8Array(t),r=0;for(let t of e)n.set(t,r),r+=t.length;return n}function Ge(e){let t=new Uint8Array(e.length);for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);if(r>127)throw TypeError(`non-ASCII string encountered in encode()`);t[n]=r}return t}function Ke(e){if(Uint8Array.prototype.toBase64)return e.toBase64();let t=32768,n=[];for(let r=0;r<e.length;r+=t)n.push(String.fromCharCode.apply(null,e.subarray(r,r+t)));return btoa(n.join(``))}function qe(e){if(Uint8Array.fromBase64)return Uint8Array.fromBase64(e);let t=atob(e),n=new Uint8Array(t.length);for(let e=0;e<t.length;e++)n[e]=t.charCodeAt(e);return n}var Je=`The input to be decoded is not correctly encoded.`;function Ye(e){if(Uint8Array.fromBase64)try{return Uint8Array.fromBase64(typeof e==`string`?e:He.decode(e),{alphabet:`base64url`})}catch(e){throw TypeError(Je,{cause:e})}let t=e;if(t instanceof Uint8Array&&(t=He.decode(t)),t.includes(`+`)||t.includes(`/`))throw TypeError(Je);t=t.replace(/-/g,`+`).replace(/_/g,`/`);try{return qe(t)}catch{throw TypeError(Je)}}function Xe(e){let t=e;return typeof t==`string`&&(t=Ve.encode(t)),Uint8Array.prototype.toBase64?t.toBase64({alphabet:`base64url`,omitPadding:!0}):Ke(t).replace(/=/g,``).replace(/\+/g,`-`).replace(/\//g,`_`)}var Ze=(e,t=`algorithm.name`)=>TypeError(`CryptoKey does not support this operation, its ${t} must be ${e}`);function Qe(e,t){if(t&&!e.usages.includes(t))throw TypeError(`CryptoKey does not support this operation, its usages must include ${t}.`)}function $e(e,t){let{modulusLength:n}=t.algorithm;if(typeof n!=`number`||n<2048)throw TypeError(`${e} requires key modulusLength to be 2048 bits or larger`)}function et(e,t,n){let r=e.algorithm;if(r.name!==t.name)throw Ze(t.name);if(t.hash&&r.hash?.name!==t.hash)throw Ze(t.hash,`algorithm.hash`);if(t.namedCurve&&r.namedCurve!==t.namedCurve)throw Ze(t.namedCurve,`algorithm.namedCurve`);if(t.length!==void 0&&r.length!==t.length)throw Ze(t.length,`algorithm.length`);Qe(e,n)}async function tt(e,t,n){return t instanceof Uint8Array?crypto.subtle.importKey(`raw`,t,e.subtle,!1,[n]):(et(t,e.subtle,n),e.minRsaBits&&$e(e.alg,t),t)}async function nt(e,t,n){let r=await tt(e,t,`sign`),i=await crypto.subtle.sign(e.signing,r,n);return new Uint8Array(i)}async function rt(e,t,n,r){let i=await tt(e,t,`verify`);try{return await crypto.subtle.verify(e.signing,i,n,r)}catch{return!1}}var it=class extends Error{static code=`ERR_JOSE_GENERIC`;code=`ERR_JOSE_GENERIC`;constructor(e,t){super(e,t),this.name=this.constructor.name,Error.captureStackTrace?.(this,this.constructor)}},at=class extends it{static code=`ERR_JWT_CLAIM_VALIDATION_FAILED`;code=`ERR_JWT_CLAIM_VALIDATION_FAILED`;claim;reason;payload;constructor(e,t,n=`unspecified`,r=`unspecified`){super(e,{cause:{claim:n,reason:r,payload:t}}),this.claim=n,this.reason=r,this.payload=t}},ot=class extends it{static code=`ERR_JWT_EXPIRED`;code=`ERR_JWT_EXPIRED`;claim;reason;payload;constructor(e,t,n=`unspecified`,r=`unspecified`){super(e,{cause:{claim:n,reason:r,payload:t}}),this.claim=n,this.reason=r,this.payload=t}},st=class extends it{static code=`ERR_JOSE_ALG_NOT_ALLOWED`;code=`ERR_JOSE_ALG_NOT_ALLOWED`},ct=class extends it{static code=`ERR_JOSE_NOT_SUPPORTED`;code=`ERR_JOSE_NOT_SUPPORTED`},W=class extends it{static code=`ERR_JWS_INVALID`;code=`ERR_JWS_INVALID`},lt=class extends it{static code=`ERR_JWT_INVALID`;code=`ERR_JWT_INVALID`},ut=class extends it{static code=`ERR_JWS_SIGNATURE_VERIFICATION_FAILED`;code=`ERR_JWS_SIGNATURE_VERIFICATION_FAILED`;constructor(e=`signature verification failed`,t){super(e,t)}};function dt(e){let t={__proto__:null};for(let n in e)t[n]={...e[n],alg:n};return t}var ft=[[`verify`],[`sign`]];function pt(e){let t={name:`HMAC`,hash:`SHA-${e}`};return{kty:[`oct`],secret:!0,subtle:t,signing:t,usages:ft}}function mt(e,t){let n={name:t?`RSA-PSS`:`RSASSA-PKCS1-v1_5`,hash:`SHA-${e}`};return{kty:[`RSA`],subtle:n,signing:t?{...n,saltLength:t}:n,usages:ft,minRsaBits:2048}}function ht(e,t){return{kty:[`EC`],crv:e,subtle:{name:`ECDSA`,namedCurve:e},signing:{name:`ECDSA`,hash:`SHA-${t}`},usages:ft}}function gt(){let e={name:`Ed25519`};return{kty:[`OKP`],crv:`Ed25519`,subtle:e,signing:e,usages:ft}}function _t(e){let t={name:`ML-DSA-${e}`};return{kty:[`AKP`],subtle:t,signing:t,usages:ft}}var vt=dt({HS256:pt(256),HS384:pt(384),HS512:pt(512),RS256:mt(256),RS384:mt(384),RS512:mt(512),PS256:mt(256,32),PS384:mt(384,48),PS512:mt(512,64),ES256:ht(`P-256`,256),ES384:ht(`P-384`,384),ES512:ht(`P-521`,512),EdDSA:gt(),Ed25519:gt(),"ML-DSA-44":_t(44),"ML-DSA-65":_t(65),"ML-DSA-87":_t(87)});function yt(e){let t=typeof e==`string`?vt[e]:void 0;if(!t)throw new ct(`alg ${e} is not supported either by JOSE or your javascript runtime`);return t}function bt(e){if(typeof e!=`object`||!e||Object.prototype.toString.call(e)!==`[object Object]`)return!1;let t=Object.getPrototypeOf(e);if(t===null)return!0;let n=t;for(;Object.getPrototypeOf(n)!==null;)n=Object.getPrototypeOf(n);return t===n}function xt(...e){let t=new Set;for(let n of e)if(n)for(let e of Object.keys(n)){if(t.has(e))return!1;t.add(e)}return!0}var St=e=>bt(e)&&typeof e.kty==`string`,Ct=e=>e.kty!==`oct`&&(e.kty===`AKP`&&typeof e.priv==`string`||typeof e.d==`string`),wt=e=>e.kty!==`oct`&&e.d===void 0&&e.priv===void 0,Tt=e=>e.kty===`oct`&&typeof e.k==`string`,Et={__proto__:null,b64:!0};function Dt(e,t){if(t!==void 0&&(!Array.isArray(t)||t.some(e=>typeof e!=`string`)))throw TypeError(`"${e}" option must be an array of strings`);if(t)return new Set(t)}function Ot(e,t){let{crit:n}=t??{};if(Array.isArray(n)&&new Set(n).size!==n.length)throw new e(`"crit" (Critical) Header Parameter MUST NOT contain duplicate values`)}function kt(e,t,n,r,i){if(i.crit!==void 0&&r?.crit===void 0)throw new e(`"crit" (Critical) Header Parameter MUST be integrity protected`);if(!r||r.crit===void 0)return[];if(!Array.isArray(r.crit)||r.crit.length===0||r.crit.some(e=>typeof e!=`string`||e.length===0))throw new e(`"crit" (Critical) Header Parameter MUST be an array of non-empty strings when present`);let a=n===void 0?t:{__proto__:null,...n,...t};for(let t of r.crit){if(!(t in a))throw new ct(`Extension Header Parameter "${t}" is not recognized`);if(!Object.hasOwn(i,t)||i[t]===void 0)throw new e(`Extension Header Parameter "${t}" is missing`);if(a[t]&&(!Object.hasOwn(r,t)||r[t]===void 0))throw new e(`Extension Header Parameter "${t}" MUST be integrity protected`)}return r.crit}function At(e,t,...n){if(n.length>2){let t=n.pop();e+=`one of type ${n.join(`, `)}, or ${t}.`}else n.length===2?e+=`one of type ${n[0]} or ${n[1]}.`:e+=`of type ${n[0]}.`;return t==null?e+=` Received ${t}`:typeof t==`function`&&t.name?e+=` Received function ${t.name}`:typeof t==`object`&&t&&t.constructor?.name&&(e+=` Received an instance of ${t.constructor.name}`),e}var jt=(e,t,...n)=>At(`Key for the ${e} algorithm must be `,t,...n),Mt=e=>{if(e?.[Symbol.toStringTag]===`CryptoKey`)return!0;try{return e instanceof CryptoKey}catch{return!1}},Nt=e=>e?.[Symbol.toStringTag]===`KeyObject`,Pt=e=>Mt(e)||Nt(e);async function Ft(e,t){if(t.kty===`RSA`&&`oth`in t&&t.oth!==void 0)throw new ct(`RSA JWK "oth" (Other Primes Info) Parameter value is not supported`);if(!e.kty.includes(t.kty))throw new ct(`Invalid or unsupported JWK "alg" (Algorithm) Parameter value`);let n=e.resolve?.({kty:t.kty,crv:t.crv})??e.subtle,r=!!(t.d||t.priv),i={...t};return i.kty!==`AKP`&&delete i.alg,delete i.use,crypto.subtle.importKey(`jwk`,i,n,t.ext??!r,t.key_ops??e.usages[+!!r])}var It=e=>e[Symbol.toStringTag],Lt=(e,t,n)=>{let{alg:r}=e;if(t.use!==void 0){let e=n===`sign`||n===`verify`?`sig`:`enc`;if(t.use!==e)throw TypeError(`Invalid key for this operation, its "use" must be "${e}" when present`)}if(t.alg!==void 0&&t.alg!==r)throw TypeError(`Invalid key for this operation, its "alg" must be "${r}" when present`);if(Array.isArray(t.key_ops)){let r=n===`encrypt`||n===`decrypt`?e.ops?.[n===`encrypt`?0:1]:n;if(r&&!t.key_ops.includes(r))throw TypeError(`Invalid key for this operation, its "key_ops" must include "${r}" when present`)}};function Rt(e,t,n){let{alg:r,secret:i}=e,a=n===`decrypt`||n===`sign`;if(i&&t instanceof Uint8Array)return[zt,t];if(St(t)){if(i?!Tt(t):!(a?Ct(t):wt(t)))throw TypeError(i?`JSON Web Key for symmetric algorithms must have JWK "kty" (Key Type) equal to "oct" and the JWK "k" (Key Value) present`:`JSON Web Key for this operation must be a ${a?`private`:`public`} JWK`);return Lt(e,t,n),[Ht,t]}if(!Pt(t))throw TypeError(i?jt(r,t,`CryptoKey`,`KeyObject`,`JSON Web Key`,`Uint8Array`):jt(r,t,`CryptoKey`,`KeyObject`,`JSON Web Key`));if(i){if(t.type!==`secret`)throw TypeError(`${It(t)} instances for symmetric algorithms must be of type "secret"`)}else{if(t.type===`secret`)throw TypeError(`${It(t)} instances for asymmetric algorithms must not be of type "secret"`);let e=a?`private`:`public`;if((t.type===`public`||t.type===`private`)&&t.type!==e){let r=n===`sign`?`signing`:n===`verify`?`verifying`:`${n.slice(0,-1)}tion`;throw TypeError(`${It(t)} instances for asymmetric algorithm ${r} must be of type "${e}"`)}}return Mt(t)?[Bt,t]:[Vt,t]}var zt=0,Bt=1,Vt=2,Ht=3,Ut,Wt={__proto__:null,prime256v1:`P-256`,secp384r1:`P-384`,secp521r1:`P-521`};function Gt(e,t,n){Ut||=new WeakMap;let r=Ut.get(e);return n&&(r?r[t]=n:Ut.set(e,{__proto__:null,[t]:n})),n??r?.[t]}var Kt=async(e,t,n)=>Gt(e,n.alg)??Gt(e,n.alg,await Ft(n,{...t,alg:n.alg})),qt=(e,t)=>{let n=Gt(e,t.alg);if(n)return n;let r=e.type===`public`,i=t.usages[+!r],{asymmetricKeyType:a}=e,o=Wt[e.asymmetricKeyDetails?.namedCurve],s=t.resolve?.({crv:o,asymmetricKeyType:a})??t.subtle;return Gt(e,t.alg,e.toCryptoKey(s,r,i))};async function Jt(e,t,n){let r=Rt(e,t,n);switch(r[0]){case zt:case Bt:return r[1];case Ht:{let t=r[1];if(t.k)return Ye(t.k);if(!Object.isFrozen(t)){let{key_ops:e}=t;Array.isArray(e)&&Object.freeze(e),Object.freeze(t)}return Kt(t,t,e)}case Vt:{let t=r[1];return t.type===`secret`?t.export():`toCryptoKey`in t&&typeof t.toCryptoKey==`function`?qt(t,e):Kt(t,t.export({format:`jwk`}),e)}}}function Yt(e){return e?.b64===!1&&Array.isArray(e.crit)&&e.crit.includes(`b64`)}async function Xt(e,t){let{protectedHeader:n,unprotectedHeader:r}=e;if(!n&&!r)throw new W(`either setProtectedHeader or setUnprotectedHeader must be called before #sign()`);if(!xt(n,r))throw new W(`JWS Protected and JWS Unprotected Header Parameter names must be disjoint`);let i={...n,...r};Ot(W,n);let a=kt(W,Et,e.crit,n,i),o=!0;if(a.includes(`b64`)&&(o=n.b64,typeof o!=`boolean`))throw new W(`The "b64" (base64url-encode payload) Header Parameter must be a boolean`);let{alg:s}=i;if(typeof s!=`string`||!s)throw new W(`JWS "alg" (Algorithm) Header Parameter missing or invalid`);let c=yt(s),l,u;if(o){let t=e.encoded??=[];t[0]??=Xe(e.payload),t[1]??=Ge(t[0]),l=t[0],u=t[1]}else u=e.payload,l=``;let d,f;n?(d=Xe(JSON.stringify(n)),f=Ge(d)):(d=``,f=new Uint8Array);let p=We(f,Ge(`.`),u),m={signature:Xe(await nt(c,await Jt(c,t,`sign`),p)),payload:l};return n&&(m.protected=d),r&&(m.header=r),m}function Zt(e,t){if(e)throw TypeError(`${t} can only be called once`)}function Qt(e,t,n){try{return Ye(e)}catch{throw new n(`Failed to base64url decode the ${t}`)}}function $t(e,t,n){try{return Ge(e)}catch{throw new n(`The ${t} is not a valid base64url string`)}}function en(e,t,n){let r;try{r=JSON.parse(Ue.decode(Ye(e)))}catch{throw new t(n)}if(!bt(r))throw new t(n);return r}var tn=class{#e;#t;#n;constructor(e){if(!(e instanceof Uint8Array))throw TypeError(`payload must be an instance of Uint8Array`);this.#e=e}setProtectedHeader(e){return Zt(this.#t,`setProtectedHeader`),this.#t=e,this}setUnprotectedHeader(e){return Zt(this.#n,`setUnprotectedHeader`),this.#n=e,this}async sign(e,t){return Xt({payload:this.#e,protectedHeader:this.#t,unprotectedHeader:this.#n,crit:t?.crit},e)}},nn=class{#e;#t;constructor(e){this.#e=new tn(e)}setProtectedHeader(e){return this.#e.setProtectedHeader(e),this.#t=e,this}async sign(e,t){if(Yt(this.#t))throw TypeError(`use the flattened module for creating JWS with b64: false`);let n=await this.#e.sign(e,t);return`${n.protected}.${n.payload}.${n.signature}`}},rn=e=>Math.floor(e.getTime()/1e3),an={s:1,m:60,h:3600,d:86400,w:604800,y:31557600},on=/^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i,sn=`check_failed`;function cn(e){let t=on.exec(e);if(!t||t[4]&&t[1])throw TypeError(`Invalid time period format`);let n=parseFloat(t[2]),r=Math.round(n*an[t[3][0].toLowerCase()]);return t[1]===`-`||t[4]===`ago`?-r:r}function ln(e,t){if(!Number.isFinite(t))throw TypeError(`Invalid ${e} input`);return t}function un(e,t){return typeof e==`number`?ln(t,e):e instanceof Date?ln(t,rn(e)):rn(new Date)+cn(e)}var dn=e=>e.includes(`/`)?e.toLowerCase():`application/${e.toLowerCase()}`,fn=(e,t)=>typeof e==`string`?t.includes(e):Array.isArray(e)?t.some(t=>e.includes(t)):!1;function pn(e,t,n=!1){let r=e[t];if(!(r===void 0&&!n)){if(typeof r!=`number`)throw new at(`"${t}" claim must be a number`,e,t,`invalid`);return r}}function mn(e,t){throw new at(`unexpected "${t}" claim value`,e,t,sn)}function hn(e,t,n={}){let r;try{r=JSON.parse(Ue.decode(t))}catch{}if(!bt(r))throw new lt(`JWT Claims Set must be a top-level JSON object`);let{typ:i}=n;if(i&&(typeof e.typ!=`string`||dn(e.typ)!==dn(i)))throw new at(`unexpected "typ" JWT header value`,r,`typ`,sn);let{requiredClaims:a=[],issuer:o,subject:s,audience:c,maxTokenAge:l}=n,u=[...a];l!==void 0&&u.push(`iat`),c!==void 0&&u.push(`aud`),s!==void 0&&u.push(`sub`),o!==void 0&&u.push(`iss`);for(let e of new Set(u.reverse()))if(!Object.hasOwn(r,e))throw new at(`missing required "${e}" claim`,r,e,`missing`);o!==void 0&&!(Array.isArray(o)?o:[o]).includes(r.iss)&&mn(r,`iss`),s!==void 0&&r.sub!==s&&mn(r,`sub`),c!==void 0&&!fn(r.aud,typeof c==`string`?[c]:c)&&mn(r,`aud`);let{clockTolerance:d}=n,f=0;if(typeof d==`string`)f=cn(d);else if(d!==void 0){if(typeof d!=`number`)throw TypeError(`Invalid clockTolerance option type`);f=d}ln(`clockTolerance option`,f);let{currentDate:p}=n,m=ln(`currentDate option`,rn(p||new Date)),h=pn(r,`iat`,l!==void 0),g=pn(r,`nbf`);if(g!==void 0&&g>m+f)throw new at(`"nbf" claim timestamp check failed`,r,`nbf`,sn);let _=pn(r,`exp`);if(_!==void 0&&_<=m-f)throw new ot(`"exp" claim timestamp check failed`,r,`exp`,sn);if(l!==void 0){let e=m-h,t=typeof l==`number`?l:cn(l);if(e-f>t)throw new ot(`"iat" claim timestamp check failed (too far in the past)`,r,`iat`,sn);if(e<0-f)throw new at(`"iat" claim timestamp check failed (it should be in the past)`,r,`iat`,sn)}return r}var gn=class{#e;constructor(e){if(!bt(e))throw TypeError(`JWT Claims Set MUST be an object`);this.#e=structuredClone(e)}data(){return Ve.encode(JSON.stringify(this.#e))}get iss(){return this.#e.iss}set iss(e){this.#e.iss=e}get sub(){return this.#e.sub}set sub(e){this.#e.sub=e}get aud(){return this.#e.aud}set aud(e){this.#e.aud=e}set jti(e){this.#e.jti=e}set nbf(e){this.#e.nbf=un(e,`setNotBefore`)}set exp(e){this.#e.exp=un(e,`setExpirationTime`)}set iat(e){e===void 0?this.#e.iat=rn(new Date):typeof e==`string`?this.#e.iat=ln(`setIssuedAt`,rn(new Date)+cn(e)):this.#e.iat=un(e,`setIssuedAt`)}},_n=class{#e;#t;constructor(e={}){this.#t=new gn(e)}setIssuer(e){return this.#t.iss=e,this}setSubject(e){return this.#t.sub=e,this}setAudience(e){return this.#t.aud=e,this}setJti(e){return this.#t.jti=e,this}setNotBefore(e){return this.#t.nbf=e,this}setExpirationTime(e){return this.#t.exp=e,this}setIssuedAt(e){return this.#t.iat=e,this}setProtectedHeader(e){return this.#e=e,this}async sign(e,t){let n=new nn(this.#t.data());if(n.setProtectedHeader(this.#e),Yt(this.#e))throw new lt(`JWTs MUST NOT use unencoded payload`);return n.sign(e,t)}};function vn(e){return[e&&Dt(`algorithms`,e.algorithms),e?.crit]}async function yn(e,t,n){let{protected:r,header:i,payload:a}=e,o={};r&&(o=en(r,W,`JWS Protected Header is invalid`));let s;if(i!==void 0){if(!xt(o,i))throw new W(`JWS Protected and JWS Unprotected Header Parameter names must be disjoint`);s={...o,...i}}else s=o;let c=kt(W,Et,t[1],o,s),l=!0;if(c.includes(`b64`)&&(l=o.b64,typeof l!=`boolean`))throw new W(`The "b64" (base64url-encode payload) Header Parameter must be a boolean`);let{alg:u}=s;if(typeof u!=`string`||!u)throw new W(`JWS "alg" (Algorithm) Header Parameter missing or invalid`);if(t[0]&&!t[0].has(u))throw new st(`"alg" (Algorithm) Header Parameter value not allowed`);if(l){if(typeof a!=`string`)throw new W(`JWS Payload must be a string`)}else if(typeof a!=`string`&&!(a instanceof Uint8Array))throw new W(`JWS Payload must be a string or an Uint8Array instance`);let d=!1;typeof n==`function`&&(n=await n(o,e),d=!0);let f=yt(u),p=We(r===void 0?new Uint8Array:Ge(r),Ge(`.`),typeof a==`string`?l?t[2]??=$t(a,`payload`,W):Ve.encode(a):a),m=Qt(e.signature,`signature`,W),h=await Jt(f,n,`verify`);if(!await rt(f,h,m,p))throw new ut;let g;return g=l?Qt(a,`payload`,W):typeof a==`string`?Ve.encode(a):a,[g,o,l,h,d]}async function bn(e,t,n){if(e instanceof Uint8Array&&(e=He.decode(e)),typeof e!=`string`)throw new W(`Compact JWS must be a string or Uint8Array`);let{0:r,1:i,2:a,length:o}=e.split(`.`);if(o!==3)throw new W(`Invalid Compact JWS`);return yn({payload:i,protected:r,signature:a},t,n)}async function xn(e,t,n){let r=await bn(e,vn(n),t);if(!r[2])throw new lt(`JWTs MUST NOT use unencoded payload`);let i={payload:hn(r[1],r[0],n),protectedHeader:r[1]};return typeof t==`function`?{...i,key:r[3]}:i}function Sn(e){return e.saveState!==void 0&&e.restoreState!==void 0&&e.cleanSavedState!==void 0}function Cn(e){for(let t=0;t<e.length;t++)e[t]=0;return e}var wn=class{blockSize;digestLength;_inner;_outer;_finished=!1;_innerKeyedState;_outerKeyedState;constructor(e,t){this._inner=new e,this._outer=new e,this.blockSize=this._outer.blockSize,this.digestLength=this._outer.digestLength;let n=new Uint8Array(this.blockSize);t.length>this.blockSize?this._inner.update(t).finish(n).clean():n.set(t);for(let e=0;e<n.length;e++)n[e]^=54;this._inner.update(n);for(let e=0;e<n.length;e++)n[e]^=106;this._outer.update(n),Sn(this._inner)&&Sn(this._outer)&&(this._innerKeyedState=this._inner.saveState(),this._outerKeyedState=this._outer.saveState()),Cn(n)}reset(){if(!Sn(this._inner)||!Sn(this._outer))throw Error(`hmac: can't reset() because hash doesn't implement restoreState()`);return this._inner.restoreState(this._innerKeyedState),this._outer.restoreState(this._outerKeyedState),this._finished=!1,this}clean(){Sn(this._inner)&&this._inner.cleanSavedState(this._innerKeyedState),Sn(this._outer)&&this._outer.cleanSavedState(this._outerKeyedState),this._inner.clean(),this._outer.clean()}update(e){return this._inner.update(e),this}finish(e){return this._finished?(this._outer.finish(e),this):(this._inner.finish(e),this._outer.update(e.subarray(0,this.digestLength)).finish(e),this._finished=!0,this)}digest(){let e=new Uint8Array(this.digestLength);return this.finish(e),e}saveState(){if(!Sn(this._inner))throw Error(`hmac: can't saveState() because hash doesn't implement it`);return this._inner.saveState()}restoreState(e){if(!Sn(this._inner)||!Sn(this._outer))throw Error(`hmac: can't restoreState() because hash doesn't implement it`);return this._inner.restoreState(e),this._outer.restoreState(this._outerKeyedState),this._finished=!1,this}cleanSavedState(e){if(!Sn(this._inner))throw Error(`hmac: can't cleanSavedState() because hash doesn't implement it`);this._inner.cleanSavedState(e)}};Number.isInteger,Number.isSafeInteger;function Tn(e,t=0){return(e[t]<<24|e[t+1]<<16|e[t+2]<<8|e[t+3])>>>0}function En(e,t=new Uint8Array(4),n=0){return t[n+0]=e>>>24,t[n+1]=e>>>16,t[n+2]=e>>>8,t[n+3]=e>>>0,t}function Dn(e,t,n,r,i){let a=new wn(e,t),o=a.digestLength,s=new Uint8Array(4),c=new Uint8Array(o),l=new Uint8Array(o),u=new Uint8Array(i),d=a.update(n).saveState();for(let e=0;e*o<i;e++){En(e+1,s),a.restoreState(d).update(s).finish(l);for(let e=0;e<o;e++)c[e]=l[e];for(let e=2;e<=r;e++){a.reset().update(l).finish(l);for(let e=0;e<o;e++)c[e]^=l[e]}for(let t=0;t<o&&e*o+t<i;t++)u[e*o+t]=c[t]}return Cn(c),Cn(l),Cn(s),a.cleanSavedState(d),a.clean(),u}var On=class{digestLength=32;blockSize=64;_state=new Int32Array(8);_temp=new Int32Array(64);_buffer=new Uint8Array(128);_bufferLength=0;_bytesHashed=0;_finished=!1;constructor(){this.reset()}_initState(){this._state[0]=1779033703,this._state[1]=3144134277,this._state[2]=1013904242,this._state[3]=2773480762,this._state[4]=1359893119,this._state[5]=2600822924,this._state[6]=528734635,this._state[7]=1541459225}reset(){return this._initState(),this._bufferLength=0,this._bytesHashed=0,this._finished=!1,this}clean(){Cn(this._buffer),Cn(this._temp),this.reset()}update(e,t=e.length){if(this._finished)throw Error(`SHA256: can't update because hash was finished.`);let n=0;if(this._bytesHashed+=t,this._bufferLength>0){for(;this._bufferLength<this.blockSize&&t>0;)this._buffer[this._bufferLength++]=e[n++],t--;this._bufferLength===this.blockSize&&(An(this._temp,this._state,this._buffer,0,this.blockSize),this._bufferLength=0)}for(t>=this.blockSize&&(n=An(this._temp,this._state,e,n,t),t%=this.blockSize);t>0;)this._buffer[this._bufferLength++]=e[n++],t--;return this}finish(e){if(!this._finished){let e=this._bytesHashed,t=this._bufferLength,n=e/536870912|0,r=e<<3,i=e%64<56?64:128;this._buffer[t]=128;for(let e=t+1;e<i-8;e++)this._buffer[e]=0;En(n,this._buffer,i-8),En(r,this._buffer,i-4),An(this._temp,this._state,this._buffer,0,i),this._finished=!0}for(let t=0;t<this.digestLength/4;t++)En(this._state[t],e,t*4);return this}digest(){let e=new Uint8Array(this.digestLength);return this.finish(e),e}saveState(){if(this._finished)throw Error(`SHA256: cannot save finished state`);return{state:new Int32Array(this._state),buffer:this._bufferLength>0?new Uint8Array(this._buffer):void 0,bufferLength:this._bufferLength,bytesHashed:this._bytesHashed}}restoreState(e){return this._state.set(e.state),this._bufferLength=e.bufferLength,e.buffer&&this._buffer.set(e.buffer),this._bytesHashed=e.bytesHashed,this._finished=!1,this}cleanSavedState(e){Cn(e.state),e.buffer&&Cn(e.buffer),e.bufferLength=0,e.bytesHashed=0}},kn=new Int32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]);function An(e,t,n,r,i){for(;i>=64;){let a=t[0],o=t[1],s=t[2],c=t[3],l=t[4],u=t[5],d=t[6],f=t[7];for(let t=0;t<16;t++){let i=r+t*4;e[t]=Tn(n,i)}for(let t=16;t<64;t++){let n=e[t-2],r=(n>>>17|n<<15)^(n>>>19|n<<13)^n>>>10;n=e[t-15];let i=(n>>>7|n<<25)^(n>>>18|n<<14)^n>>>3;e[t]=(r+e[t-7]|0)+(i+e[t-16]|0)}for(let t=0;t<64;t++){let n=(((l>>>6|l<<26)^(l>>>11|l<<21)^(l>>>25|l<<7))+(l&u^~l&d)|0)+(f+(kn[t]+e[t]|0)|0)|0,r=((a>>>2|a<<30)^(a>>>13|a<<19)^(a>>>22|a<<10))+(a&o^a&s^o&s)|0;f=d,d=u,u=l,l=c+n|0,c=s,s=o,o=a,a=n+r|0}t[0]+=a,t[1]+=o,t[2]+=s,t[3]+=c,t[4]+=l,t[5]+=u,t[6]+=d,t[7]+=f,r+=64,i-=64}return r}var jn=r(),Mn,Nn={lang:void 0,message:void 0,abortEarly:void 0,abortPipeEarly:void 0};function Pn(e){return!e&&!Mn?Nn:{lang:e?.lang??Mn?.lang,message:e?.message,abortEarly:e?.abortEarly??Mn?.abortEarly,abortPipeEarly:e?.abortPipeEarly??Mn?.abortPipeEarly}}var Fn;function In(e){return Fn?.get(e)}var Ln;function Rn(e){return Ln?.get(e)}var zn;function Bn(e,t){return zn?.get(e)?.get(t)}function Vn(e){let t=typeof e;return t===`string`?`"${e}"`:t===`number`||t===`bigint`||t===`boolean`?`${e}`:t===`object`||t===`function`?(e&&Object.getPrototypeOf(e)?.constructor?.name)??`null`:t}function G(e,t,n,r,i){let a=i&&`input`in i?i.input:n.value,o=i?.expected??e.expects??null,s=i?.received??Vn(a),c={kind:e.kind,type:e.type,input:a,expected:o,received:s,message:`Invalid ${t}: ${o?`Expected ${o} but r`:`R`}eceived ${s}`,requirement:e.requirement,path:i?.path,issues:i?.issues,lang:r.lang,abortEarly:r.abortEarly,abortPipeEarly:r.abortPipeEarly},l=e.kind===`schema`,u=i?.message??e.message??Bn(e.reference,c.lang)??(l?Rn(c.lang):null)??r.message??In(c.lang);u!==void 0&&(c.message=typeof u==`function`?u(c):u),l&&(n.typed=!1),n.issues?n.issues.push(c):n.issues=[c]}var Hn=new WeakMap;function Un(e){let t=Hn.get(e);return t||(t={version:1,vendor:`valibot`,validate(t){return e[`~run`]({value:t},Pn())}},Hn.set(e,t)),t}function Wn(e,t){return Object.prototype.hasOwnProperty.call(e,t)&&t!==`__proto__`&&t!==`prototype`&&t!==`constructor`}function Gn(e,t){let n=[...new Set(e)];return n.length>1?`(${n.join(` ${t} `)})`:n[0]??`never`}function Kn(e,t){return{kind:`validation`,type:`check`,reference:Kn,async:!1,expects:null,requirement:e,message:t,"~run"(e,t){return e.typed&&!this.requirement(e.value)&&G(this,`input`,e,t),e}}}function qn(e){return{kind:`validation`,type:`integer`,reference:qn,async:!1,expects:null,requirement:Number.isInteger,message:e,"~run"(e,t){return e.typed&&!this.requirement(e.value)&&G(this,`integer`,e,t),e}}}function Jn(e,t){return{kind:`validation`,type:`max_length`,reference:Jn,async:!1,expects:`<=${e}`,requirement:e,message:t,"~run"(e,t){return e.typed&&e.value.length>this.requirement&&G(this,`length`,e,t,{received:`${e.value.length}`}),e}}}function Yn(e,t){return{kind:`validation`,type:`min_value`,reference:Yn,async:!1,expects:`>=${e instanceof Date?e.toJSON():Vn(e)}`,requirement:e,message:t,"~run"(e,t){return e.typed&&!(e.value>=this.requirement)&&G(this,`value`,e,t,{received:e.value instanceof Date?e.value.toJSON():Vn(e.value)}),e}}}function Xn(e,t){return{kind:`validation`,type:`regex`,reference:Xn,async:!1,expects:`${e}`,requirement:e,message:t,"~run"(e,t){return e.typed&&!this.requirement.test(e.value)&&G(this,`format`,e,t),e}}}function Zn(e,t,n){return typeof e.fallback==`function`?e.fallback(t,n):e.fallback}function Qn(e,t,n){return typeof e.default==`function`?e.default(t,n):e.default}function $n(e,t){return{kind:`schema`,type:`array`,reference:$n,expects:`Array`,async:!1,item:e,message:t,get"~standard"(){return Un(this)},"~run"(e,t){let n=e.value;if(Array.isArray(n)){e.typed=!0,e.value=[];for(let r=0;r<n.length;r++){let i=n[r],a=this.item[`~run`]({value:i},t);if(a.issues){let o={type:`array`,origin:`value`,input:n,key:r,value:i};for(let t of a.issues)t.path?t.path.unshift(o):t.path=[o],e.issues?.push(t);if(e.issues||=a.issues,t.abortEarly){e.typed=!1;break}}a.typed||(e.typed=!1),e.value.push(a.value)}}else G(this,`type`,e,t);return e}}}function er(e){return{kind:`schema`,type:`boolean`,reference:er,expects:`boolean`,async:!1,message:e,get"~standard"(){return Un(this)},"~run"(e,t){return typeof e.value==`boolean`?e.typed=!0:G(this,`type`,e,t),e}}}function tr(e,t){return{kind:`schema`,type:`instance`,reference:tr,expects:e.name,async:!1,class:e,message:t,get"~standard"(){return Un(this)},"~run"(e,t){return e.value instanceof this.class?e.typed=!0:G(this,`type`,e,t),e}}}function nr(e,t){return{kind:`schema`,type:`literal`,reference:nr,expects:Vn(e),async:!1,literal:e,message:t,get"~standard"(){return Un(this)},"~run"(e,t){return e.value===this.literal?e.typed=!0:G(this,`type`,e,t),e}}}function rr(e){return{kind:`schema`,type:`number`,reference:rr,expects:`number`,async:!1,message:e,get"~standard"(){return Un(this)},"~run"(e,t){return typeof e.value==`number`&&!isNaN(e.value)?e.typed=!0:G(this,`type`,e,t),e}}}function K(e,t){return{kind:`schema`,type:`optional`,reference:K,expects:`(${e.expects} | undefined)`,async:!1,wrapped:e,default:t,get"~standard"(){return Un(this)},"~run"(e,t){return e.value===void 0&&(this.default!==void 0&&(e.value=Qn(this,e,t)),e.value===void 0)?(e.typed=!0,e):this.wrapped[`~run`](e,t)}}}function ir(e,t){return{kind:`schema`,type:`picklist`,reference:ir,expects:Gn(e.map(Vn),`|`),async:!1,options:e,message:t,get"~standard"(){return Un(this)},"~run"(e,t){return this.options.includes(e.value)?e.typed=!0:G(this,`type`,e,t),e}}}function ar(e,t,n){return{kind:`schema`,type:`record`,reference:ar,expects:`Object`,async:!1,key:e,value:t,message:n,get"~standard"(){return Un(this)},"~run"(e,t){let n=e.value;if(n&&typeof n==`object`){e.typed=!0,e.value={};for(let r in n)if(Wn(n,r)){let i=n[r],a=this.key[`~run`]({value:r},t);if(a.issues){let o={type:`object`,origin:`key`,input:n,key:r,value:i};for(let t of a.issues)t.path=[o],e.issues?.push(t);if(e.issues||=a.issues,t.abortEarly){e.typed=!1;break}}let o=this.value[`~run`]({value:i},t);if(o.issues){let a={type:`object`,origin:`value`,input:n,key:r,value:i};for(let t of o.issues)t.path?t.path.unshift(a):t.path=[a],e.issues?.push(t);if(e.issues||=o.issues,t.abortEarly){e.typed=!1;break}}(!a.typed||!o.typed)&&(e.typed=!1),a.typed&&(e.value[a.value]=o.value)}}else G(this,`type`,e,t);return e}}}function or(e,t){return{kind:`schema`,type:`strict_object`,reference:or,expects:`Object`,async:!1,entries:e,message:t,get"~standard"(){return Un(this)},"~run"(e,t){let n=e.value;if(n&&typeof n==`object`){e.typed=!0,e.value={};for(let r in this.entries){let i=this.entries[r];if(r in n||(i.type===`exact_optional`||i.type===`optional`||i.type===`nullish`)&&i.default!==void 0){let a=r in n?n[r]:Qn(i),o=i[`~run`]({value:a},t);if(o.issues){let i={type:`object`,origin:`value`,input:n,key:r,value:a};for(let t of o.issues)t.path?t.path.unshift(i):t.path=[i],e.issues?.push(t);if(e.issues||=o.issues,t.abortEarly){e.typed=!1;break}}o.typed||(e.typed=!1),e.value[r]=o.value}else if(i.fallback!==void 0)e.value[r]=Zn(i);else if(i.type!==`exact_optional`&&i.type!==`optional`&&i.type!==`nullish`&&(G(this,`key`,e,t,{input:void 0,expected:`"${r}"`,path:[{type:`object`,origin:`key`,input:n,key:r,value:n[r]}]}),t.abortEarly))break}if(!e.issues||!t.abortEarly){for(let r in n)if(!(r in this.entries)){G(this,`key`,e,t,{input:r,expected:`never`,path:[{type:`object`,origin:`key`,input:n,key:r,value:n[r]}]});break}}}else G(this,`type`,e,t);return e}}}function q(e){return{kind:`schema`,type:`string`,reference:q,expects:`string`,async:!1,message:e,get"~standard"(){return Un(this)},"~run"(e,t){return typeof e.value==`string`?e.typed=!0:G(this,`type`,e,t),e}}}function sr(){return{kind:`schema`,type:`unknown`,reference:sr,expects:`unknown`,async:!1,get"~standard"(){return Un(this)},"~run"(e){return e.typed=!0,e}}}function cr(...e){return{...e[0],pipe:e,get"~standard"(){return Un(this)},"~run"(t,n){for(let r of e)if(r.kind!==`metadata`){if(t.issues&&(r.kind===`schema`||r.kind===`transformation`)){t.typed=!1;break}(!t.issues||!n.abortEarly&&!n.abortPipeEarly)&&(t=r[`~run`](t,n))}return t}}}function lr(e,t,n){let r=e[`~run`]({value:t},Pn(n));return{typed:r.typed,success:!r.issues,output:r.value,issues:r.issues}}var J={POS_INT:0,NEG_INT:1,BYTE_STRING:2,UTF8_STRING:3,ARRAY:4,MAP:5,TAG:6,SIMPLE_FLOAT:7},Y={DATE_STRING:0,DATE_EPOCH:1,POS_BIGINT:2,NEG_BIGINT:3,DECIMAL_FRAC:4,BIGFLOAT:5,BASE64URL_EXPECTED:21,BASE64_EXPECTED:22,BASE16_EXPECTED:23,CBOR:24,URI:32,BASE64URL:33,BASE64:34,MIME:36,DATE_EPOCH_DAYS:100,SET:258,JSON:262,WTF8:273,SYMBOL:280,DATE_FULL:1004,REGEXP:21066,SELF_DESCRIBED:55799,INVALID_16:65535,INVALID_32:4294967295,INVALID_64:18446744073709551615n},X={ZERO:0,ONE:24,TWO:25,FOUR:26,EIGHT:27,INDEFINITE:31},ur={FALSE:20,TRUE:21,NULL:22,UNDEFINED:23},Z=class{static BREAK=Symbol.for(`github.com/hildjj/cbor2/break`);static ENCODED=Symbol.for(`github.com/hildjj/cbor2/cbor-encoded`);static LENGTH=Symbol.for(`github.com/hildjj/cbor2/length`)},dr={MIN:-(2n**63n),MAX:2n**64n-1n},Q=class e{static#e=new Map;tag;contents;constructor(e,t=void 0){this.tag=e,this.contents=t}get noChildren(){return!!e.#e.get(this.tag)?.noChildren}static registerDecoder(e,t,n){let r=this.#e.get(e);return this.#e.set(e,t),r&&(`comment`in t||(t.comment=r.comment),`noChildren`in t||(t.noChildren=r.noChildren)),n&&!t.comment&&(t.comment=()=>`(${n})`),r}static clearDecoder(e){let t=this.#e.get(e);return this.#e.delete(e),t}static getDecoder(e){return this.#e.get(e)}static getAllDecoders(){return new Map(this.#e)}*[Symbol.iterator](){yield this.contents}push(e){return this.contents=e,1}decode(t){let n=t?.tags?.get(this.tag)??(t?.ignoreGlobalTags?void 0:e.#e.get(this.tag));return n?n(this,t):this}comment(t,n){let r=t?.tags?.get(this.tag)??(t?.ignoreGlobalTags?void 0:e.#e.get(this.tag));if(r?.comment)return r.comment(this,t,n)}toCBOR(){return[this.tag,this.contents]}[Symbol.for(`nodejs.util.inspect.custom`)](e,t,n){return`${this.tag}(${n(this.contents,t)})`}};function fr(e){if(typeof e==`object`&&e)return e[Z.ENCODED]}function pr(e){if(typeof e==`object`&&e)return e[Z.LENGTH]}function mr(e,t){Object.defineProperty(e,Z.ENCODED,{configurable:!0,enumerable:!1,value:t})}function hr(e,t){let n=Object(e);return mr(n,t),n}var gr=Symbol(`CBOR_RANGES`);function _r(e,t){Object.defineProperty(e,gr,{configurable:!1,enumerable:!1,writable:!1,value:t})}function vr(e){return e[gr]}function yr(e){return vr(e)!==void 0}function br(e,t=0,n=e.length-1){let r=e.subarray(t,n),i=vr(e);if(i){let e=[];for(let r of i)if(r[0]>=t&&r[0]+r[1]<=n){let n=[...r];n[0]-=t,e.push(n)}e.length&&_r(r,e)}return r}function xr(e){let t=Math.ceil(e.length/2),n=new Uint8Array(t);t--;for(let r=e.length,i=r-2;r>=0;r=i,i-=2,t--)n[t]=parseInt(e.substring(i,r),16);return n}function Sr(e){return e.reduce((e,t)=>e+t.toString(16).padStart(2,`0`),``)}function Cr(e){let t=e.reduce((e,t)=>e+t.length,0),n=e.some(e=>yr(e)),r=[],i=new Uint8Array(t),a=0;for(let t of e){if(!(t instanceof Uint8Array))throw TypeError(`Invalid array: ${t}`);if(i.set(t,a),n){let e=t[gr]??[[0,t.length]];for(let t of e)t[0]+=a;r.push(...e)}a+=t.length}return n&&_r(i,r),i}function wr(e){let t=atob(e);return Uint8Array.from(t,e=>e.codePointAt(0))}var Tr={"-":`+`,_:`/`};function Er(e){let t=e.replace(/[_-]/g,e=>Tr[e]);return wr(t.padEnd(Math.ceil(t.length/4)*4,`=`))}function Dr(){let e=new Uint8Array(4),t=new Uint32Array(e.buffer);return!((t[0]=1)&e[0])}function Or(e){let t=``;for(let n of e){let e=n.codePointAt(0)?.toString(16).padStart(4,`0`);t&&(t+=`, `),t+=`U+${e}`}return t}var kr=class{#e=new Map;registerEncoder(e,t){let n=this.#e.get(e);return this.#e.set(e,t),n}get(e){return this.#e.get(e)}delete(e){return this.#e.delete(e)}clear(){this.#e.clear()}};function Ar(e,t){let[n,r,i]=e,[a,o,s]=t,c=Math.min(i.length,s.length);for(let e=0;e<c;e++){let t=i[e]-s[e];if(t!==0)return t}return 0}var jr=class e{static defaultOptions={chunkSize:4096};#e;#t=[];#n=null;#r=0;#i=0;constructor(t={}){if(this.#e={...e.defaultOptions,...t},this.#e.chunkSize<8)throw RangeError(`Expected size >= 8, got ${this.#e.chunkSize}`);this.#a()}get length(){return this.#i}read(){this.#o();let e=new Uint8Array(this.#i),t=0;for(let n of this.#t)e.set(n,t),t+=n.length;return this.#a(),e}write(e){let t=e.length;t>this.#s()?(this.#o(),t>this.#e.chunkSize?(this.#t.push(e),this.#a()):(this.#a(),this.#t[this.#t.length-1].set(e),this.#r=t)):(this.#t[this.#t.length-1].set(e,this.#r),this.#r+=t),this.#i+=t}writeUint8(e){this.#c(1),this.#n.setUint8(this.#r,e),this.#l(1)}writeUint16(e,t=!1){this.#c(2),this.#n.setUint16(this.#r,e,t),this.#l(2)}writeUint32(e,t=!1){this.#c(4),this.#n.setUint32(this.#r,e,t),this.#l(4)}writeBigUint64(e,t=!1){this.#c(8),this.#n.setBigUint64(this.#r,e,t),this.#l(8)}writeInt16(e,t=!1){this.#c(2),this.#n.setInt16(this.#r,e,t),this.#l(2)}writeInt32(e,t=!1){this.#c(4),this.#n.setInt32(this.#r,e,t),this.#l(4)}writeBigInt64(e,t=!1){this.#c(8),this.#n.setBigInt64(this.#r,e,t),this.#l(8)}writeFloat32(e,t=!1){this.#c(4),this.#n.setFloat32(this.#r,e,t),this.#l(4)}writeFloat64(e,t=!1){this.#c(8),this.#n.setFloat64(this.#r,e,t),this.#l(8)}clear(){this.#i=0,this.#t=[],this.#a()}#a(){let e=new Uint8Array(this.#e.chunkSize);this.#t.push(e),this.#r=0,this.#n=new DataView(e.buffer,e.byteOffset,e.byteLength)}#o(){if(this.#r===0){this.#t.pop();return}let e=this.#t.length-1;this.#t[e]=this.#t[e].subarray(0,this.#r),this.#r=0,this.#n=null}#s(){let e=this.#t.length-1;return this.#t[e].length-this.#r}#c(e){this.#s()<e&&(this.#o(),this.#a())}#l(e){this.#r+=e,this.#i+=e}},Mr=1n<<15n,Nr=31n<<10n,Pr=1n<<9n,Fr=Pr-1n,Ir=Pr|Fr,Lr=1n<<31n,Rr=255n<<23n,zr=1n<<22n,Br=zr-1n,Vr=zr|Br,Hr=1n<<63n,Ur=2047n<<52n,Wr=1n<<51n,Gr=Wr-1n,Kr=Wr|Gr,qr=Gr-(Fr<<42n),Jr=Gr-(Br<<29n),Yr={2:`0b`,8:`0o`,16:`0x`},Xr=(e=>(e[e.NATURAL=-2]=`NATURAL`,e[e.UNKNOWN=-1]=`UNKNOWN`,e[e.F16=2]=`F16`,e[e.F32=4]=`F32`,e[e.F64=8]=`F64`,e))(Xr||{});function Zr(e,t,n,r){let i=`nan'`;return e.quiet||(i+=`!`),e.sign===-1&&(i+=`-`),i+=r(Math.abs(e.payload),n),i+=`'`,i+=e.encodingIndicator,i}var Qr=class extends Number{#e;#t=-1;constructor(e,t=!0,n=-1){super(NaN);let r=e;if(typeof e==`number`){if(!Number.isSafeInteger(e))throw Error(`Invalid NAN payload: ${e}`);e=BigInt(e);let i=0n;if(e<0&&(i=Hr,e=-e),e>=Wr)throw Error(`Payload too large: ${r}`);let a=t?Wr:0n;switch(this.#e=i|Ur|a|e,n){case-2:throw Error(`NAN_SIZE.NATURAL only valid for bigint constructor`);case-1:n=this.preferredSize;break;case 2:if(this.#e&qr)throw Error(`Invalid size for payload`);break;case 4:if(this.#e&Jr)throw Error(`Invalid size for payload`);break;case 8:break;default:throw Error(`Invalid size: ${n}`)}this.#t=n}else if(typeof e==`bigint`){let t=-1;if((e&Ur)===Ur)this.#e=e,t=8;else if((e&Rr)===Rr){let n=(e&Lr)<<32n;this.#e=n|Ur|(e&Vr)<<29n,t=4}else if((e&Nr)===Nr){let n=(e&Mr)<<48n;this.#e=n|Ur|(e&Ir)<<42n,t=2}else throw Error(`Invalid raw NaN value: ${e}`);if(n===-1)this.#t=this.preferredSize;else if(n===-2)this.#t=t;else{if(n<t)throw Error(`Invalid bigint NaN size`);this.#t=n}}else{let t=new DataView(e.buffer,e.byteOffset,e.byteLength);switch(e.length){case 3:{if(e[0]!==249)throw Error(`Invalid CBOR encoding for half float`);let n=BigInt(t.getUint16(1,!1));if((n&Nr)!==Nr)throw Error(`Not a NaN`);let r=(n&Mr)<<48n;this.#e=r|Ur|(n&Ir)<<42n,this.#t=2;break}case 5:{if(e[0]!==250)throw Error(`Invalid CBOR encoding for single float`);let n=BigInt(t.getUint32(1,!1));if((n&Rr)!==Rr)throw Error(`Not a NaN`);let r=(n&Lr)<<32n;this.#e=r|Ur|(n&Vr)<<29n,this.#t=4;break}case 9:if(e[0]!==251)throw Error(`Invalid CBOR encoding for double float`);if(this.#e=t.getBigUint64(1,!1),(this.#e&Ur)!==Ur)throw Error(`Not a NaN (NaNaN)`);this.#t=8;break;default:throw RangeError(`Invalid NAN size (should be 2, 4, or 8): ${e.length-1}`)}}if(!this.payload&&!this.quiet)throw Error(`Signalling NaN with zero payload`)}get bytes(){let e=new ArrayBuffer(this.#t+1),t=new DataView(e);switch(this.#t){case 2:{t.setUint8(0,249);let e=(this.#e&Hr?Mr:0n)|Nr|(this.#e&Kr)>>42n;t.setUint16(1,Number(e),!1);break}case 4:{t.setUint8(0,250);let e=(this.#e&Hr?Lr:0n)|Rr|(this.#e&Kr)>>29n;t.setUint32(1,Number(e),!1);break}case 8:t.setUint8(0,251),t.setBigUint64(1,this.#e)}return new Uint8Array(e)}get quiet(){return!!(this.#e&Wr)}get sign(){return this.#e&Hr?-1:1}get payload(){return Number(this.#e&Gr)*this.sign}get raw(){return this.#e}get encodingIndicator(){switch(this.#t){case 2:return`_1`;case 4:return`_2`}return`_3`}get size(){return this.#t}get preferredSize(){return(this.#e&qr)===0n?2:(this.#e&Jr)===0n?4:8}get isShortestEncoding(){return this.preferredSize===this.#t}toCBOR(e){e.write(this.bytes)}toString(e=10){return Zr(this,1,{},t=>(Yr[e]??``)+t.toString(e))}[Symbol.for(`nodejs.util.inspect.custom`)](e,t,n){return Zr(this,e,t,n)}};function $r(e,t=0,n=!1){let r=e[t]&128?-1:1,i=(e[t]&124)>>2,a=(e[t]&3)<<8|e[t+1];if(i===0){if(n&&a!==0)throw Error(`Unwanted subnormal: ${r*5.960464477539063e-8*a}`);return r*5.960464477539063e-8*a}return i===31?a?NaN:1/0*r:r*2**(i-25)*(1024+a)}function ei(e){let t=new DataView(new ArrayBuffer(4));t.setFloat32(0,e,!1);let n=t.getUint32(0,!1);if(n&8191)return null;let r=n>>16&32768,i=n>>23&255,a=n&8388607;if(i!==0||a!==0){if(i>=113&&i<=142)r+=(i-112<<10)+(a>>13);else if(i>=103&&i<113){if(a&(1<<126-i)-1)return null;r+=a+8388608>>126-i}else if(i===255)r|=31744,r|=a>>13;else return null}return r}function ti(e){if(e!==0){let t=new DataView(new ArrayBuffer(8));t.setFloat64(0,e,!1);let n=t.getBigUint64(0,!1);if((n&9218868437227405312n)==0n)return n&9223372036854775808n?-0:0}return e}function ni(e){switch(e.length){case 2:$r(e,0,!0);break;case 4:{let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=t.getUint32(0,!1);if(!(n&2139095040)&&n&8388607)throw Error(`Unwanted subnormal: ${t.getFloat32(0,!1)}`);break}case 8:{let t=new DataView(e.buffer,e.byteOffset,e.byteLength),n=t.getBigUint64(0,!1);if((n&9218868437227405312n)==0n&&n&17592186044415n)throw Error(`Unwanted subnormal: ${t.getFloat64(0,!1)}`);break}default:throw TypeError(`Bad input to isSubnormal: ${e}`)}}var ri=class extends TypeError{code=`ERR_ENCODING_INVALID_ENCODED_DATA`;constructor(){super(`The encoded data was not valid for encoding wtf-8`)}},ii=class extends RangeError{code=`ERR_ENCODING_NOT_SUPPORTED`;constructor(e){super(`Invalid encoding: "${e}"`)}},ai=new Uint8Array,oi=55296,si=56320,ci=65533,li=`wtf-8`;function ui(e){return e&&typeof e==`object`&&!(e instanceof ArrayBuffer)&&!(e instanceof SharedArrayBuffer)&&e.buffer instanceof ArrayBuffer}function di(e){return e?e instanceof Uint8Array?e:ui(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):new Uint8Array(e):ai}var fi=[0,0,0,0,0,0,0,0,-1,-1,-1,-1,1,1,2,3],pi=class e{static DEFAULT_BUFFERSIZE=4096;encoding=li;fatal;ignoreBOM;bufferSize;#e=0;#t=0;#n=0;#r=!0;#i;constructor(t=`wtf8`,n=void 0){if(t.toLowerCase().replace(`-`,``)!==`wtf8`)throw new ii(t);if(this.fatal=!!n?.fatal,this.ignoreBOM=!!n?.ignoreBOM,this.bufferSize=Math.floor(n?.bufferSize??e.DEFAULT_BUFFERSIZE),isNaN(this.bufferSize)||this.bufferSize<1)throw RangeError(`Invalid buffer size: ${n?.bufferSize}`);this.#i=new Uint16Array(this.bufferSize)}decode(e,t){let n=!!t?.stream,r=di(e),i=[],a=this.#i,o=this.bufferSize-3,s=0,c=()=>{if(this.#t=0,this.#e=0,this.#n=0,this.fatal)throw new ri;a[s++]=ci},l=()=>{let e=this.#n;for(let t=0;t<e;t++)c()},u=e=>{if(this.#e===0)switch(fi[e>>4]){case-1:c();break;case 0:a[s++]=e;break;case 1:this.#t=e&31,this.#t&30?(this.#e=1,this.#n=1):c();break;case 2:this.#t=e&15,this.#e=2,this.#n=1;break;case 3:e&8?c():(this.#t=e&7,this.#e=3,this.#n=1)}else{if((e&192)!=128||this.#n===1&&this.#e===2&&this.#t===0&&!(e&32)||this.#e===3&&this.#t===0&&!(e&48))return l(),u(e);if(this.#t=this.#t<<6|e&63,this.#n++,--this.#e===0){if(this.ignoreBOM||!this.#r||this.#t!==65279){if(this.#t<65536)a[s++]=this.#t;else{let e=this.#t-65536;a[s++]=e>>>10&1023|oi,a[s++]=e&1023|si}}this.#t=0,this.#n=0,this.#r=!1}}};for(let e of r)s>=o&&(i.push(String.fromCharCode.apply(null,a.subarray(0,s))),s=0),u(e);return n||(this.#r=!0,(this.#t||this.#e)&&l()),s>0&&i.push(String.fromCharCode.apply(null,a.subarray(0,s))),i.join(``)}};function mi(e){let t=0;for(let n of e){let e=n.codePointAt(0);e<128?t++:t+=e<2048?2:e<65536?3:4}return t}var hi=class{encoding=li;encode(e){if(!e)return ai;let t=new Uint8Array(mi(String(e)));return this.encodeInto(e,t),t}encodeInto(e,t){let n=String(e),r=n.length,i=t.length,a=0,o=0;for(o=0;o<r;o++){let e=n.codePointAt(o);if(e<128){if(a>=i)break;t[a++]=e}else if(e<2048){if(a>=i-1)break;t[a++]=192|e>>6,t[a++]=128|e&63}else if(e<65536){if(a>=i-2)break;t[a++]=224|e>>12,t[a++]=128|e>>6&63,t[a++]=128|e&63}else{if(a>=i-3)break;t[a++]=240|e>>18,t[a++]=128|e>>12&63,t[a++]=128|e>>6&63,t[a++]=128|e&63,o++}}return{read:o,written:a}}},{ENCODED:gi}=Z,_i=J.SIMPLE_FLOAT<<5|X.TWO,vi=J.SIMPLE_FLOAT<<5|X.FOUR,yi=J.SIMPLE_FLOAT<<5|X.EIGHT,bi=J.SIMPLE_FLOAT<<5|ur.TRUE,xi=J.SIMPLE_FLOAT<<5|ur.FALSE,Si=J.SIMPLE_FLOAT<<5|ur.UNDEFINED,Ci=J.SIMPLE_FLOAT<<5|ur.NULL,wi=new TextEncoder,Ti=new hi,Ei={...jr.defaultOptions,avoidInts:!1,cde:!1,collapseBigInts:!0,dateTag:Y.DATE_EPOCH,dcbor:!1,float64:!1,flushToZero:!1,forceEndian:null,ignoreOriginalEncoding:!1,largeNegativeAsBigInt:!1,reduceUnsafeNumbers:!1,rejectBigInts:!1,rejectCustomSimples:!1,rejectDuplicateKeys:!1,rejectFloats:!1,rejectUndefined:!1,simplifyNegativeZero:!1,sortKeys:null,stringNormalization:null,types:null,wtf8:!1,ignoreGlobalTags:!1},Di={cde:!0,ignoreOriginalEncoding:!0,sortKeys:Ar},Oi={...Di,dcbor:!0,largeNegativeAsBigInt:!0,reduceUnsafeNumbers:!0,rejectCustomSimples:!0,rejectDuplicateKeys:!0,rejectUndefined:!0,simplifyNegativeZero:!0,stringNormalization:`NFC`};function ki(e){let t=e<0;return typeof e==`bigint`?[t?-e-1n:e,t]:[t?-e-1:e,t]}function Ai(e,t,n){if(n.rejectFloats)throw Error(`Attempt to encode an unwanted floating point number: ${e}`);if(isNaN(e))t.writeUint8(_i),t.writeUint16(32256);else if(!n.float64&&Math.fround(e)===e){let n=ei(e);n===null?(t.writeUint8(vi),t.writeFloat32(e)):(t.writeUint8(_i),t.writeUint16(n))}else t.writeUint8(yi),t.writeFloat64(e)}function ji(e,t,n){let[r,i]=ki(e);if(i&&n)throw TypeError(`Negative size: ${e}`);n??=i?J.NEG_INT:J.POS_INT,n<<=5,r<24?t.writeUint8(n|r):r<=255?(t.writeUint8(n|X.ONE),t.writeUint8(r)):r<=65535?(t.writeUint8(n|X.TWO),t.writeUint16(r)):r<=4294967295?(t.writeUint8(n|X.FOUR),t.writeUint32(r)):(t.writeUint8(n|X.EIGHT),t.writeBigUint64(BigInt(r)))}function Mi(e,t,n){typeof e==`number`?ji(e,t,J.TAG):typeof e==`object`&&!n.ignoreOriginalEncoding&&Z.ENCODED in e?t.write(e[Z.ENCODED]):e<=2**53-1?ji(Number(e),t,J.TAG):(t.writeUint8(J.TAG<<5|X.EIGHT),t.writeBigUint64(BigInt(e)))}function Ni(e,t,n){let[r,i]=ki(e);if(n.collapseBigInts&&(!n.largeNegativeAsBigInt||e>=-9223372036854775808n)){if(r<=4294967295n){ji(Number(e),t);return}if(r<=18446744073709551615n){let e=(i?J.NEG_INT:J.POS_INT)<<5;t.writeUint8(e|X.EIGHT),t.writeBigUint64(r);return}}if(n.rejectBigInts)throw Error(`Attempt to encode unwanted bigint: ${e}`);let a=i?Y.NEG_BIGINT:Y.POS_BIGINT,o=r.toString(16),s=o.length%2?`0`:``;Mi(a,t,n);let c=xr(s+o);ji(c.length,t,J.BYTE_STRING),t.write(c)}function Pi(e,t,n){n.flushToZero&&(e=ti(e)),Object.is(e,-0)?n.simplifyNegativeZero?n.avoidInts?Ai(0,t,n):ji(0,t):Ai(e,t,n):!n.avoidInts&&Number.isSafeInteger(e)?ji(e,t):n.reduceUnsafeNumbers&&Math.floor(e)===e&&e>=dr.MIN&&e<=dr.MAX?Ni(BigInt(e),t,n):Ai(e,t,n)}function Fi(e,t,n){let r=n.stringNormalization?e.normalize(n.stringNormalization):e;if(n.wtf8&&!e.isWellFormed()){let e=Ti.encode(r);Mi(Y.WTF8,t,n),ji(e.length,t,J.BYTE_STRING),t.write(e)}else{let e=wi.encode(r);ji(e.length,t,J.UTF8_STRING),t.write(e)}}function Ii(e,t,n){let r=e;zi(r,r.length,J.ARRAY,t,n);for(let e of r)Hi(e,t,n)}function Li(e,t){ji(e.length,t,J.BYTE_STRING),t.write(e)}var Ri=new kr;Ri.registerEncoder(Array,Ii),Ri.registerEncoder(Uint8Array,Li);function $(e,t){return Ri.registerEncoder(e,t)}function zi(e,t,n,r,i){let a=pr(e);a&&!i.ignoreOriginalEncoding?r.write(a):ji(t,r,n)}function Bi(e,t,n){if(e===null){t.writeUint8(Ci);return}if(!n.ignoreOriginalEncoding&&Z.ENCODED in e){t.write(e[Z.ENCODED]);return}let r=e.constructor;if(r){let i=n.types?.get(r)??(n.ignoreGlobalTags?void 0:Ri.get(r));if(i){let r=i(e,t,n);if(r!==void 0){if(!Array.isArray(r)||r.length!==2)throw Error(`Invalid encoder return value`);(typeof r[0]==`bigint`||isFinite(Number(r[0])))&&Mi(r[0],t,n),Hi(r[1],t,n)}return}}if(typeof e.toCBOR==`function`){let r=e.toCBOR(t,n);r&&((typeof r[0]==`bigint`||isFinite(Number(r[0])))&&Mi(r[0],t,n),Hi(r[1],t,n));return}if(typeof e.toJSON==`function`){Hi(e.toJSON(),t,n);return}let i=Object.entries(e).map(e=>[e[0],e[1],Ui(e[0],n)]);n.sortKeys&&i.sort(n.sortKeys),zi(e,i.length,J.MAP,t,n);for(let[e,r,a]of i)t.write(a),Hi(r,t,n)}function Vi(e,t,n){if(!e.description||e!==Symbol.for(e.description))throw TypeError(`Private or empty symbol: ${e.toString()}`);Mi(280,t,n),Fi(e.description,t,n)}function Hi(e,t,n){switch(typeof e){case`number`:Pi(e,t,n);break;case`bigint`:Ni(e,t,n);break;case`string`:Fi(e,t,n);break;case`boolean`:t.writeUint8(e?bi:xi);break;case`undefined`:if(n.rejectUndefined)throw Error(`Attempt to encode unwanted undefined.`);t.writeUint8(Si);break;case`object`:Bi(e,t,n);break;case`symbol`:Vi(e,t,n);break;default:throw TypeError(`Unknown type: ${typeof e}, ${String(e)}`)}}function Ui(e,t={}){let n={...Ei};t.dcbor?Object.assign(n,Oi):t.cde&&Object.assign(n,Di),Object.assign(n,t);let r=new jr(n);return Hi(e,r,n),r.read()}var Wi=(e=>(e[e.NEVER=-1]=`NEVER`,e[e.PREFERRED=0]=`PREFERRED`,e[e.ALWAYS=1]=`ALWAYS`,e))(Wi||{}),Gi=class e{static KnownSimple=new Map([[ur.FALSE,!1],[ur.TRUE,!0],[ur.NULL,null],[ur.UNDEFINED,void 0]]);value;constructor(e){this.value=e}static create(t){return e.KnownSimple.has(t)?e.KnownSimple.get(t):new e(t)}toCBOR(e,t){if(t.rejectCustomSimples)throw Error(`Cannot encode non-standard Simple value: ${this.value}`);ji(this.value,e,J.SIMPLE_FLOAT)}toString(){return`simple(${this.value})`}decode(){return e.KnownSimple.has(this.value)?e.KnownSimple.get(this.value):this}[Symbol.for(`nodejs.util.inspect.custom`)](e,t,n){return`simple(${n(this.value,t)})`}},Ki=new TextDecoder(`utf8`,{fatal:!0,ignoreBOM:!0}),qi=class e{static defaultOptions={maxDepth:1024,encoding:`hex`,requirePreferred:!1};#e;#t;#n=0;#r;constructor(t,n){if(this.#r={...e.defaultOptions,...n},typeof t==`string`)switch(this.#r.encoding){case`hex`:this.#e=xr(t);break;case`base64`:this.#e=wr(t);break;default:throw TypeError(`Encoding not implemented: "${this.#r.encoding}"`)}else this.#e=t;this.#t=new DataView(this.#e.buffer,this.#e.byteOffset,this.#e.byteLength)}toHere(e){return br(this.#e,e,this.#n)}*[Symbol.iterator](){if(yield*this.#i(0),this.#n!==this.#e.length)throw Error(`Extra data in input`)}*seq(){for(;this.#n<this.#e.length;)yield*this.#i(0)}*#i(e){if(e++>this.#r.maxDepth)throw Error(`Maximum depth ${this.#r.maxDepth} exceeded`);let t=this.#n,n=this.#t.getUint8(this.#n++),r=n>>5,i=n&31,a=i,o=!1,s=0;switch(i){case X.ONE:if(s=1,a=this.#t.getUint8(this.#n),r===J.SIMPLE_FLOAT){if(a<32)throw Error(`Invalid simple encoding in extra byte: ${a}`);o=!0}else if(this.#r.requirePreferred&&a<24)throw Error(`Unexpectedly long integer encoding (1) for ${a}`);break;case X.TWO:if(s=2,r===J.SIMPLE_FLOAT)a=$r(this.#e,this.#n);else if(a=this.#t.getUint16(this.#n,!1),this.#r.requirePreferred&&a<=255)throw Error(`Unexpectedly long integer encoding (2) for ${a}`);break;case X.FOUR:if(s=4,r===J.SIMPLE_FLOAT)a=this.#t.getFloat32(this.#n,!1);else if(a=this.#t.getUint32(this.#n,!1),this.#r.requirePreferred&&a<=65535)throw Error(`Unexpectedly long integer encoding (4) for ${a}`);break;case X.EIGHT:if(s=8,r===J.SIMPLE_FLOAT)a=this.#t.getFloat64(this.#n,!1);else if(a=this.#t.getBigUint64(this.#n,!1),a<=2**53-1&&(a=Number(a)),this.#r.requirePreferred&&a<=4294967295)throw Error(`Unexpectedly long integer encoding (8) for ${a}`);break;case 28:case 29:case 30:throw Error(`Additional info not implemented: ${i}`);case X.INDEFINITE:switch(r){case J.POS_INT:case J.NEG_INT:case J.TAG:throw Error(`Invalid indefinite encoding for MT ${r}`);case J.SIMPLE_FLOAT:yield[r,i,Z.BREAK,t,0];return}a=1/0;break;default:o=!0}switch(this.#n+=s,r){case J.POS_INT:yield[r,i,a,t,s];break;case J.NEG_INT:yield[r,i,typeof a==`bigint`?-1n-a:-1-Number(a),t,s];break;case J.BYTE_STRING:a===1/0?yield*this.#o(r,e,t):yield[r,i,this.#a(a),t,a];break;case J.UTF8_STRING:a===1/0?yield*this.#o(r,e,t):yield[r,i,Ki.decode(this.#a(a)),t,a];break;case J.ARRAY:if(a===1/0)yield*this.#o(r,e,t,!1);else{let n=Number(a);yield[r,i,n,t,s];for(let t=0;t<n;t++)yield*this.#i(e+1)}break;case J.MAP:if(a===1/0)yield*this.#o(r,e,t,!1);else{let n=Number(a);yield[r,i,n,t,s];for(let t=0;t<n;t++)yield*this.#i(e),yield*this.#i(e)}break;case J.TAG:yield[r,i,a,t,s],yield*this.#i(e);break;case J.SIMPLE_FLOAT:{let e=a;o&&(a=Gi.create(Number(a))),yield[r,i,a,t,e];break}}}#a(e){let t=br(this.#e,this.#n,this.#n+=e);if(t.length!==e)throw Error(`Unexpected end of stream reading ${e} bytes, got ${t.length}`);return t}*#o(e,t,n,r=!0){for(yield[e,X.INDEFINITE,1/0,n,1/0];;){let n=this.#i(t),i=n.next(),[a,o,s]=i.value;if(s===Z.BREAK){yield i.value,n.next();return}if(r){if(a!==e)throw Error(`Unmatched major type. Expected ${e}, got ${a}.`);if(o===X.INDEFINITE)throw Error(`New stream started in typed stream`)}yield i.value,yield*n}}},Ji=new Map([[X.ZERO,1],[X.ONE,2],[X.TWO,3],[X.FOUR,5],[X.EIGHT,9]]),Yi=new Uint8Array;function Xi(e,t){return!t.boxed&&!t.preferMap&&e.every(([e])=>typeof e==`string`)?Object.fromEntries(e):new Map(e)}var Zi=class e{static defaultDecodeOptions={...qi.defaultOptions,ParentType:e,boxed:!1,cde:!1,dcbor:!1,diagnosticSizes:Wi.PREFERRED,collapseBigInts:!1,convertUnsafeIntsToFloat:!1,createObject:Xi,keepNanPayloads:!1,pretty:!1,preferBigInt:!1,preferMap:!1,rejectLargeNegatives:!1,rejectBigInts:!1,rejectDuplicateKeys:!1,rejectFloats:!1,rejectInts:!1,rejectLongLoundNaN:!1,rejectLongFloats:!1,rejectNegativeZero:!1,rejectSimple:!1,rejectStreaming:!1,rejectStringsNotNormalizedAs:null,rejectSubnormals:!1,rejectUndefined:!1,rejectUnsafeFloatInts:!1,saveOriginal:!1,sortKeys:null,tags:null,ignoreGlobalTags:!1};static cdeDecodeOptions={cde:!0,rejectStreaming:!0,requirePreferred:!0,sortKeys:Ar};static dcborDecodeOptions={...this.cdeDecodeOptions,dcbor:!0,convertUnsafeIntsToFloat:!0,rejectDuplicateKeys:!0,rejectLargeNegatives:!0,rejectLongLoundNaN:!0,rejectLongFloats:!0,rejectNegativeZero:!0,rejectSimple:!0,rejectUndefined:!0,rejectUnsafeFloatInts:!0,rejectStringsNotNormalizedAs:`NFC`};parent;mt;ai;left;offset;count=0;children=[];depth=0;#e;#t=null;constructor(e,t,n,r){if([this.mt,this.ai,,this.offset]=e,this.left=t,this.parent=n,this.#e=r,n&&(this.depth=n.depth+1),this.mt===J.MAP&&(this.#e.sortKeys||this.#e.rejectDuplicateKeys)&&(this.#t=[]),this.#e.rejectStreaming&&this.ai===X.INDEFINITE)throw Error(`Streaming not supported`)}get isStreaming(){return this.left===1/0}get done(){return this.left===0}static create(e,t,n,r){let[i,a,o,s]=e;switch(i){case J.POS_INT:case J.NEG_INT:{if(n.rejectInts)throw Error(`Unexpected integer: ${o}`);if(n.rejectLargeNegatives&&o<-9223372036854775808n)throw Error(`Invalid 65bit negative number: ${o}`);let e=o;return n.preferBigInt?e=BigInt(e):n.convertUnsafeIntsToFloat&&e>=dr.MIN&&e<=dr.MAX&&(e=Number(o)),n.boxed?hr(e,r.toHere(s)):e}case J.SIMPLE_FLOAT:if(a>X.ONE){if(typeof o==`symbol`)return o;if(n.rejectFloats)throw Error(`Decoding unwanted floating point number: ${o}`);if(n.rejectNegativeZero&&Object.is(o,-0))throw Error(`Decoding negative zero`);if(isNaN(o)){let e=r.toHere(s),t=new Qr(e);if(n.rejectLongLoundNaN){if(t.payload||e.length>3)throw Error(`Invalid NaN encoding: "${Sr(e)}"`)}else if(n.keepNanPayloads&&(t.payload||t.sign===-1)){if(n.rejectLongFloats&&!t.isShortestEncoding)throw Error(`NaN should have been encoded shorter: ${o}`);return t}}if(n.rejectSubnormals&&ni(r.toHere(s+1)),n.rejectLongFloats){let e=Ui(o,{chunkSize:9,reduceUnsafeNumbers:n.rejectUnsafeFloatInts});if(e[0]>>5!==i)throw Error(`Should have been encoded as int, not float: ${o}`);if(e.length<Ji.get(a))throw Error(`Number should have been encoded shorter: ${o}`)}if(typeof o==`number`&&n.boxed)return hr(o,r.toHere(s))}else{if(n.rejectSimple&&o instanceof Gi)throw Error(`Invalid simple value: ${o}`);if(n.rejectUndefined&&o===void 0)throw Error(`Unexpected undefined`)}return o;case J.BYTE_STRING:case J.UTF8_STRING:if(o===1/0)return new n.ParentType(e,1/0,t,n);if(n.rejectStringsNotNormalizedAs&&typeof o==`string`){let e=o.normalize(n.rejectStringsNotNormalizedAs);if(o!==e)throw Error(`String not normalized as "${n.rejectStringsNotNormalizedAs}", got [${Or(o)}] instead of [${Or(e)}]`)}return n.boxed?hr(o,r.toHere(s)):o;case J.ARRAY:return new n.ParentType(e,o,t,n);case J.MAP:return new n.ParentType(e,o*2,t,n);case J.TAG:{let r=new n.ParentType(e,1,t,n);return r.children=new Q(o),r}}throw TypeError(`Invalid major type: ${i}`)}static decodeToEncodeOpts(e){return{...Ei,avoidInts:e.rejectInts,float64:!e.rejectLongFloats,flushToZero:e.rejectSubnormals,largeNegativeAsBigInt:e.rejectLargeNegatives,sortKeys:e.sortKeys}}push(e,t,n){if(this.children.push(e),this.#t){let r=fr(e)||t.toHere(n);this.#t.push(r)}return--this.left}replaceLast(e,t,n){let r,i=-1/0;if(this.children instanceof Q?(i=0,r=this.children.contents,this.children.contents=e):(i=this.children.length-1,r=this.children[i],this.children[i]=e),this.#t){let r=fr(e)||n.toHere(t.offset);this.#t[i]=r}return r}convert(e){let t;switch(this.mt){case J.ARRAY:t=this.children;break;case J.MAP:{let e=this.#n();if(this.#e.sortKeys){let t;for(let n of e){if(t&&this.#e.sortKeys(t,n)>=0)throw Error(`Duplicate or out of order key: "0x${n[2]}"`);t=n}}else if(this.#e.rejectDuplicateKeys){let t=new Set;for(let[n,r,i]of e){let e=Sr(i);if(t.has(e))throw Error(`Duplicate key: "0x${e}"`);t.add(e)}}t=this.#e.createObject(e,this.#e);break}case J.BYTE_STRING:return Cr(this.children);case J.UTF8_STRING:{let n=this.children.join(``);t=this.#e.boxed?hr(n,e.toHere(this.offset)):n;break}case J.TAG:t=this.children.decode(this.#e);break;default:throw TypeError(`Invalid mt on convert: ${this.mt}`)}return this.#e.saveOriginal&&t&&typeof t==`object`&&mr(t,e.toHere(this.offset)),t}#n(){let e=this.children,t=e.length;if(t%2)throw Error(`Missing map value`);let n=Array(t/2);if(this.#t)for(let r=0;r<t;r+=2)n[r>>1]=[e[r],e[r+1],this.#t[r]];else for(let r=0;r<t;r+=2)n[r>>1]=[e[r],e[r+1],Yi];return n}},Qi=` `,$i=new TextEncoder,ea=class extends Zi{close=``;quote=`"`;get isEmptyStream(){return(this.mt===J.UTF8_STRING||this.mt===J.BYTE_STRING)&&this.count===0}};function ta(e,t,n,r){let i=``;if(t===X.INDEFINITE)i+=`_`;else{if(r.diagnosticSizes===Wi.NEVER)return``;{let a=r.diagnosticSizes===Wi.ALWAYS;if(!a){let r=X.ZERO;if(Object.is(n,-0))r=X.TWO;else if(e===J.POS_INT||e===J.NEG_INT){let e=n<0,t=typeof n==`bigint`?1n:1,i=e?-n-t:n;r=i<=23?Number(i):i<=255?X.ONE:i<=65535?X.TWO:i<=4294967295?X.FOUR:X.EIGHT}else r=isFinite(n)?Math.fround(n)===n?ei(n)==null?X.FOUR:X.TWO:X.EIGHT:X.TWO;a=r!==t}a&&(i+=`_`,t<X.ONE?i+=`i`:i+=String(t-24))}}return i}function na(e,t){let n={...Zi.defaultDecodeOptions,...t,ParentType:ea},r=new qi(e,n),i,a,o=``;for(let e of r){let[t,s,c]=e;switch(i&&(i.count>0&&c!==Z.BREAK&&(i.mt===J.MAP&&i.count%2?o+=`: `:(o+=`,`,n.pretty||(o+=` `))),n.pretty&&(i.mt!==J.MAP||i.count%2==0)&&(o+=`
2
+ ${Qi.repeat(i.depth+1)}`)),a=Zi.create(e,i,n,r),t){case J.POS_INT:case J.NEG_INT:o+=String(c),o+=ta(t,s,c,n);break;case J.SIMPLE_FLOAT:if(c!==Z.BREAK){if(typeof c==`number`){let e=Object.is(c,-0)?`-0.0`:String(c);o+=e,isFinite(c)&&!/[.e]/.test(e)&&(o+=`.0`),o+=ta(t,s,c,n)}else c instanceof Gi?(o+=`simple(`,o+=String(c.value),o+=ta(J.POS_INT,s,c.value,n),o+=`)`):o+=String(c)}break;case J.BYTE_STRING:c===1/0?(o+=`(_ `,a.close=`)`,a.quote=`'`):(o+=`h'`,o+=Sr(c),o+=`'`,o+=ta(J.POS_INT,s,c.length,n));break;case J.UTF8_STRING:c===1/0?(o+=`(_ `,a.close=`)`):(o+=JSON.stringify(c),o+=ta(J.POS_INT,s,$i.encode(c).length,n));break;case J.ARRAY:{o+=`[`;let e=ta(J.POS_INT,s,c,n);o+=e,e&&(o+=` `),n.pretty&&c?a.close=`
3
+ ${Qi.repeat(a.depth)}]`:a.close=`]`;break}case J.MAP:{o+=`{`;let e=ta(J.POS_INT,s,c,n);o+=e,e&&(o+=` `),n.pretty&&c?a.close=`
4
+ ${Qi.repeat(a.depth)}}`:a.close=`}`;break}case J.TAG:o+=String(c),o+=ta(J.POS_INT,s,c,n),o+=`(`,a.close=`)`}if(a===Z.BREAK){if(i?.isStreaming)i.left=0;else throw Error(`Unexpected BREAK`)}else i&&(i.count++,i.left--);for(a instanceof ea&&(i=a);i?.done;){if(i.isEmptyStream)o=o.slice(0,-3),o+=`${i.quote}${i.quote}_`;else{if(i.mt===J.MAP&&i.count%2!=0)throw Error(`Odd streaming map size: ${i.count}`);o+=i.close}i=i.parent}}return o}var ra=new TextDecoder,ia=class extends Zi{depth=0;leaf=!1;value;length;[Z.ENCODED];constructor(e,t,n,r){super(e,t,n,r),this.depth=this.parent?this.parent.depth+1:r.initialDepth,[,,this.value,,this.length]=e}numBytes(){switch(this.ai){case X.ONE:return 1;case X.TWO:return 2;case X.FOUR:return 4;case X.EIGHT:return 8}return 0}};function aa(e){return e instanceof ia}function oa(e,t){return e===1/0?`Indefinite`:t?`${e} ${t}${e!==1&&e!==1n?`s`:``}`:String(e)}function sa(e){return``.padStart(e,` `)}function ca(e,t,n){let r=``;r+=sa(e.depth*2);let i=fr(e);r+=Sr(i.subarray(0,1));let a=e.numBytes();a&&(r+=` `,r+=Sr(i.subarray(1,a+1))),r=r.padEnd(t.minCol+1,` `),r+=`-- `,n!==void 0&&(r+=sa(e.depth*2),n!==``&&(r+=`[${n}] `));let o=!1,[s]=e.children;switch(e.mt){case J.POS_INT:r+=`Unsigned: ${s}`,typeof s==`bigint`&&(r+=`n`);break;case J.NEG_INT:r+=`Negative: ${s}`,typeof s==`bigint`&&(r+=`n`);break;case J.BYTE_STRING:r+=`Bytes (Length: ${oa(e.length)})`;break;case J.UTF8_STRING:r+=`UTF8 (Length: ${oa(e.length)})`,e.length!==1/0&&(r+=`: ${JSON.stringify(s)}`);break;case J.ARRAY:r+=`Array (Length: ${oa(e.value,`item`)})`;break;case J.MAP:r+=`Map (Length: ${oa(e.value,`pair`)})`;break;case J.TAG:{r+=`Tag #${e.value}`;let n=e.children,[a]=n.contents.children,s=new Q(n.tag,a);mr(s,i);let c=s.comment(t,e.depth);c&&(r+=`: `,r+=c),o||=s.noChildren;break}case J.SIMPLE_FLOAT:s===Z.BREAK?r+=`BREAK`:e.ai>X.ONE?r+=Object.is(s,-0)?`Float: -0`:`Float: ${s}`:(r+=`Simple: `,s instanceof Gi?r+=s.value:r+=s)}if(!o){if(e.leaf){if(r+=`
5
+ `,i.length>a+1){let n=sa((e.depth+1)*2),o=vr(i);if(o?.length){o.sort((e,t)=>e[0]-t[0]||t[1]-e[1]);let s=0;for(let[c,l,u]of o)if(!(c<s)){if(s=c+l,u===`<<`){r+=sa(t.minCol+1),r+=`--`,r+=n,r+=`<< `;let a=br(i,c,c+l),o=vr(a);if(o){let e=o.findIndex(([e,t,n])=>e===0&&t===l&&n===`<<`);e>=0&&o.splice(e,1)}r+=na(a),r+=` >>
6
+ `,r+=ua(a,{initialDepth:e.depth+1,minCol:t.minCol,noPrefixHex:!0});continue}if(u===`'`&&(r+=sa(t.minCol+1),r+=`--`,r+=n,r+=`'`,r+=ra.decode(i.subarray(c,c+l)),r+=`'
7
+ `),c>a)for(let e=c;e<c+l;e+=8){let t=Math.min(e+8,c+l);r+=n,r+=Sr(i.subarray(e,t)),r+=`
8
+ `}}}else for(let e=a+1;e<i.length;e+=8)r+=n,r+=Sr(i.subarray(e,e+8)),r+=`
9
9
  `}}else{r+=`
10
- `;let n=0;for(let i of e.children){if(Wi(i)){let a=String(n);e.mt===Y.MAP?a=n%2?`val ${(n-1)/2}`:`key ${n/2}`:e.mt===Y.TAG&&(a=``),r+=qi(i,t,a)}n++}}return r}var Ji={...Ii.defaultDecodeOptions,initialDepth:0,noPrefixHex:!1,minCol:0};function Yi(e,t){let n={...Ji,...t,ParentType:Ui,saveOriginal:!0},r=new Mi(e,n),i,a;for(let e of r){if(a=Ii.create(e,i,n,r),e[2]===Yn.BREAK)if(i?.isStreaming)i.left=1;else throw Error(`Unexpected BREAK`);if(!Wi(a)){let t=new Ui(e,0,i,n);t.leaf=!0,t.children.push(a),$n(t,r.toHere(e[3])),a=t}let t=(a.depth+1)*2,o=a.numBytes();for(o&&(t+=1,t+=o*2),n.minCol=Math.max(n.minCol,t),i&&i.push(a,r,e[3]),i=a;i?.done;)a=i,a.leaf||$n(a,r.toHere(a.offset)),{parent:i}=i}t&&(t.minCol=n.minCol);let o=n.noPrefixHex?``:`0x${sr(r.toHere(0))}
11
- `;return o+=qi(a,n),o}var Xi=!fr();function Zi(e){if(typeof e==`object`&&e){if(e.constructor!==Number)throw Error(`Expected number: ${e}`)}else if(typeof e!=`number`)throw Error(`Expected number: ${e}`)}function Qi(e){if(typeof e==`object`&&e){if(e.constructor!==String)throw Error(`Expected string: ${e}`)}else if(typeof e!=`string`)throw Error(`Expected string: ${e}`)}function $i(e){if(!(e instanceof Uint8Array))throw Error(`Expected Uint8Array: ${e}`)}function ea(e){if(!Array.isArray(e))throw Error(`Expected Array: ${e}`)}$(Map,(e,t,n)=>{let r=[...e.entries()].map(e=>[e[0],e[1],Oi(e[0],n)]);if(n.rejectDuplicateKeys){let e=new Set;for(let[t,n,i]of r){let t=sr(i);if(e.has(t))throw Error(`Duplicate map key: 0x${t}`);e.add(t)}}n.sortKeys&&r.sort(n.sortKeys),wi(e,e.size,Y.MAP,t,n);for(let[e,i,a]of r)t.write(a),Di(i,t,n)});function ta(e){return Qi(e.contents),new Date(e.contents)}ta.comment=e=>{Qi(e.contents);let t=new Date(e.contents);return`(String ${e.tag===X.DATE_FULL?`Full `:``}Date) ${t.toISOString()}`},Q.registerDecoder(X.DATE_STRING,ta),Q.registerDecoder(X.DATE_FULL,ta);function na(e){return Zi(e.contents),new Date(e.contents*1e3)}na.comment=e=>(Zi(e.contents),`(Epoch Date) ${new Date(e.contents*1e3).toISOString()}`),Q.registerDecoder(X.DATE_EPOCH,na);var ra=1e3*60*60*24;function ia(e){return Zi(e.contents),new Date(e.contents*ra)}ia.comment=e=>(Zi(e.contents),`(Epoch Date) ${new Date(e.contents*ra).toISOString()}`),Q.registerDecoder(X.DATE_EPOCH_DAYS,ia),$(Date,(e,t,n)=>{switch(n.dateTag){case X.DATE_EPOCH:return[n.dateTag,e.valueOf()/1e3];case X.DATE_STRING:return[n.dateTag,e.toISOString().replace(/\.000Z$/,`Z`)];case X.DATE_EPOCH_DAYS:return[n.dateTag,Math.floor(e.valueOf()/ra)];case X.DATE_FULL:return[n.dateTag,e.toISOString().split(`T`)[0]];default:throw Error(`Unsupported date tag: ${n.dateTag}`)}});function aa(e,t,n){if($i(t.contents),n.rejectBigInts)throw Error(`Decoding unwanted big integer: ${t}(h'${sr(t.contents)}')`);if(n.requirePreferred&&t.contents[0]===0)throw Error(`Decoding overly-large bigint: ${t.tag}(h'${sr(t.contents)})`);let r=t.contents.reduce((e,t)=>e<<8n|BigInt(t),0n);e&&(r=-1n-r);let i=r>=-(2**53-1)&&r<=2**53-1;if(n.requirePreferred&&i)throw Error(`Decoding bigint that could have been int: ${r}n`);return n.collapseBigInts&&i&&(r=Number(r)),n.boxed?er(r,t.contents):r}var oa=aa.bind(null,!1),sa=aa.bind(null,!0);oa.comment=(e,t)=>`(Positive BigInt) ${aa(!1,e,t)}n`,sa.comment=(e,t)=>`(Negative BigInt) ${aa(!0,e,t)}n`,Q.registerDecoder(X.POS_BIGINT,oa),Q.registerDecoder(X.NEG_BIGINT,sa);function ca(e,t){return $i(e.contents),e}ca.comment=(e,t,n)=>{$i(e.contents);let r={...t,initialDepth:n+2,noPrefixHex:!0},i=Zn(e),a=2**((i[0]&31)-24)+1,o=i[a]&31,s=sr(i.subarray(a,++a));o>=24&&(s+=` `,s+=sr(i.subarray(a,a+2**(o-24)))),r.minCol=Math.max(r.minCol,(n+1)*2+s.length);let c=Yi(e.contents,r),l=`Embedded CBOR
10
+ `;let n=0;for(let i of e.children){if(aa(i)){let a=String(n);e.mt===J.MAP?a=n%2?`val ${(n-1)/2}`:`key ${n/2}`:e.mt===J.TAG&&(a=``),r+=ca(i,t,a)}n++}}}return r}var la={...Zi.defaultDecodeOptions,initialDepth:0,noPrefixHex:!1,minCol:0};function ua(e,t){let n={...la,...t,ParentType:ia,saveOriginal:!0},r=new qi(e,n),i,a;for(let e of r){if(a=Zi.create(e,i,n,r),e[2]===Z.BREAK){if(i?.isStreaming)i.left=1;else throw Error(`Unexpected BREAK`)}if(!aa(a)){let t=new ia(e,0,i,n);t.leaf=!0,t.children.push(a),mr(t,r.toHere(e[3])),a=t}let t=(a.depth+1)*2,o=a.numBytes();for(o&&(t+=1,t+=o*2),n.minCol=Math.max(n.minCol,t),i&&i.push(a,r,e[3]),i=a;i?.done;)a=i,a.leaf||mr(a,r.toHere(a.offset)),{parent:i}=i}t&&(t.minCol=n.minCol);let o=n.noPrefixHex?``:`0x${Sr(r.toHere(0))}
11
+ `;return o+=ca(a,n),o}var da=!Dr();function fa(e){if(typeof e==`object`&&e){if(e.constructor!==Number)throw Error(`Expected number: ${e}`)}else if(typeof e!=`number`)throw Error(`Expected number: ${e}`)}function pa(e){if(typeof e==`object`&&e){if(e.constructor!==String)throw Error(`Expected string: ${e}`)}else if(typeof e!=`string`)throw Error(`Expected string: ${e}`)}function ma(e){if(!(e instanceof Uint8Array))throw Error(`Expected Uint8Array: ${e}`)}function ha(e){if(!Array.isArray(e))throw Error(`Expected Array: ${e}`)}$(Map,(e,t,n)=>{let r=[...e.entries()].map(e=>[e[0],e[1],Ui(e[0],n)]);if(n.rejectDuplicateKeys){let e=new Set;for(let[t,n,i]of r){let t=Sr(i);if(e.has(t))throw Error(`Duplicate map key: 0x${t}`);e.add(t)}}n.sortKeys&&r.sort(n.sortKeys),zi(e,e.size,J.MAP,t,n);for(let[e,i,a]of r)t.write(a),Hi(i,t,n)});function ga(e){return pa(e.contents),new Date(e.contents)}ga.comment=e=>{pa(e.contents);let t=new Date(e.contents);return`(String ${e.tag===Y.DATE_FULL?`Full `:``}Date) ${t.toISOString()}`},Q.registerDecoder(Y.DATE_STRING,ga),Q.registerDecoder(Y.DATE_FULL,ga);function _a(e){return fa(e.contents),new Date(e.contents*1e3)}_a.comment=e=>(fa(e.contents),`(Epoch Date) ${new Date(e.contents*1e3).toISOString()}`),Q.registerDecoder(Y.DATE_EPOCH,_a);var va=864e5;function ya(e){return fa(e.contents),new Date(e.contents*va)}ya.comment=e=>(fa(e.contents),`(Epoch Date) ${new Date(e.contents*va).toISOString()}`),Q.registerDecoder(Y.DATE_EPOCH_DAYS,ya),$(Date,(e,t,n)=>{switch(n.dateTag){case Y.DATE_EPOCH:return[n.dateTag,e.valueOf()/1e3];case Y.DATE_STRING:return[n.dateTag,e.toISOString().replace(/\.000Z$/,`Z`)];case Y.DATE_EPOCH_DAYS:return[n.dateTag,Math.floor(e.valueOf()/va)];case Y.DATE_FULL:return[n.dateTag,e.toISOString().split(`T`)[0]];default:throw Error(`Unsupported date tag: ${n.dateTag}`)}});function ba(e,t,n){if(ma(t.contents),n.rejectBigInts)throw Error(`Decoding unwanted big integer: ${t}(h'${Sr(t.contents)}')`);if(n.requirePreferred&&t.contents[0]===0)throw Error(`Decoding overly-large bigint: ${t.tag}(h'${Sr(t.contents)})`);let r=t.contents.reduce((e,t)=>e<<8n|BigInt(t),0n);e&&(r=-1n-r);let i=r>=-(2**53-1)&&r<=2**53-1;if(n.requirePreferred&&i)throw Error(`Decoding bigint that could have been int: ${r}n`);return n.collapseBigInts&&i&&(r=Number(r)),n.boxed?hr(r,t.contents):r}var xa=ba.bind(null,!1),Sa=ba.bind(null,!0);xa.comment=(e,t)=>`(Positive BigInt) ${ba(!1,e,t)}n`,Sa.comment=(e,t)=>`(Negative BigInt) ${ba(!0,e,t)}n`,Q.registerDecoder(Y.POS_BIGINT,xa),Q.registerDecoder(Y.NEG_BIGINT,Sa);function Ca(e,t){return ma(e.contents),e}Ca.comment=(e,t,n)=>{ma(e.contents);let r={...t,initialDepth:n+2,noPrefixHex:!0},i=fr(e),a=2**((i[0]&31)-24)+1,o=i[a]&31,s=Sr(i.subarray(a,++a));o>=24&&(s+=` `,s+=Sr(i.subarray(a,a+2**(o-24)))),r.minCol=Math.max(r.minCol,(n+1)*2+s.length);let c=ua(e.contents,r),l=`Embedded CBOR
12
12
  `;return l+=`${``.padStart((n+1)*2,` `)}${s}`.padEnd(r.minCol+1,` `),l+=`-- Bytes (Length: ${e.contents.length})
13
- `,l+=c,l},ca.noChildren=!0,Q.registerDecoder(X.CBOR,ca),Q.registerDecoder(X.URI,e=>(Qi(e.contents),new URL(e.contents)),`URI`),$(URL,e=>[X.URI,e.toString()]),Q.registerDecoder(X.BASE64URL,e=>(Qi(e.contents),dr(e.contents)),`Base64url-encoded`),Q.registerDecoder(X.BASE64,e=>(Qi(e.contents),lr(e.contents)),`Base64-encoded`),Q.registerDecoder(35,e=>(Qi(e.contents),new RegExp(e.contents)),`RegExp`),Q.registerDecoder(21065,e=>{Qi(e.contents);let t=`^(?:${e.contents})$`;return new RegExp(t,`u`)},`I-RegExp`),Q.registerDecoder(X.REGEXP,e=>{if(ea(e.contents),e.contents.length<1||e.contents.length>2)throw Error(`Invalid RegExp Array: ${e.contents}`);return new RegExp(e.contents[0],e.contents[1])},`RegExp`),$(RegExp,e=>[X.REGEXP,[e.source,e.flags]]),Q.registerDecoder(64,e=>($i(e.contents),e.contents),`uint8 Typed Array`);function la(e,t,n){$i(e.contents);let r=e.contents.length;if(r%t.BYTES_PER_ELEMENT!==0)throw Error(`Number of bytes must be divisible by ${t.BYTES_PER_ELEMENT}, got: ${r}`);r/=t.BYTES_PER_ELEMENT;let i=new t(r),a=new DataView(e.contents.buffer,e.contents.byteOffset,e.contents.byteLength),o=a[`get${t.name.replace(/Array/,``)}`].bind(a);for(let e=0;e<r;e++)i[e]=o(e*t.BYTES_PER_ELEMENT,n);return i}function ua(e,t,n,r,i){let a=i.forceEndian??Xi;if(_i(a?t:n,e,i),gi(r.byteLength,e,Y.BYTE_STRING),Xi===a)e.write(new Uint8Array(r.buffer,r.byteOffset,r.byteLength));else{let t=e[`write${r.constructor.name.replace(/Array/,``)}`].bind(e);for(let e of r)t(e,a)}}Q.registerDecoder(65,e=>la(e,Uint16Array,!1),`uint16, big endian, Typed Array`),Q.registerDecoder(66,e=>la(e,Uint32Array,!1),`uint32, big endian, Typed Array`),Q.registerDecoder(67,e=>la(e,BigUint64Array,!1),`uint64, big endian, Typed Array`),Q.registerDecoder(68,e=>($i(e.contents),new Uint8ClampedArray(e.contents)),`uint8 Typed Array, clamped arithmetic`),$(Uint8ClampedArray,e=>[68,new Uint8Array(e.buffer,e.byteOffset,e.byteLength)]),Q.registerDecoder(69,e=>la(e,Uint16Array,!0),`uint16, little endian, Typed Array`),$(Uint16Array,(e,t,n)=>ua(t,69,65,e,n)),Q.registerDecoder(70,e=>la(e,Uint32Array,!0),`uint32, little endian, Typed Array`),$(Uint32Array,(e,t,n)=>ua(t,70,66,e,n)),Q.registerDecoder(71,e=>la(e,BigUint64Array,!0),`uint64, little endian, Typed Array`),$(BigUint64Array,(e,t,n)=>ua(t,71,67,e,n)),Q.registerDecoder(72,e=>($i(e.contents),new Int8Array(e.contents)),`sint8 Typed Array`),$(Int8Array,e=>[72,new Uint8Array(e.buffer,e.byteOffset,e.byteLength)]),Q.registerDecoder(73,e=>la(e,Int16Array,!1),`sint16, big endian, Typed Array`),Q.registerDecoder(74,e=>la(e,Int32Array,!1),`sint32, big endian, Typed Array`),Q.registerDecoder(75,e=>la(e,BigInt64Array,!1),`sint64, big endian, Typed Array`),Q.registerDecoder(77,e=>la(e,Int16Array,!0),`sint16, little endian, Typed Array`),$(Int16Array,(e,t,n)=>ua(t,77,73,e,n)),Q.registerDecoder(78,e=>la(e,Int32Array,!0),`sint32, little endian, Typed Array`),$(Int32Array,(e,t,n)=>ua(t,78,74,e,n)),Q.registerDecoder(79,e=>la(e,BigInt64Array,!0),`sint64, little endian, Typed Array`),$(BigInt64Array,(e,t,n)=>ua(t,79,75,e,n)),Q.registerDecoder(81,e=>la(e,Float32Array,!1),`IEEE 754 binary32, big endian, Typed Array`),Q.registerDecoder(82,e=>la(e,Float64Array,!1),`IEEE 754 binary64, big endian, Typed Array`),Q.registerDecoder(85,e=>la(e,Float32Array,!0),`IEEE 754 binary32, little endian, Typed Array`),$(Float32Array,(e,t,n)=>ua(t,85,81,e,n)),Q.registerDecoder(86,e=>la(e,Float64Array,!0),`IEEE 754 binary64, big endian, Typed Array`),$(Float64Array,(e,t,n)=>ua(t,86,82,e,n)),Q.registerDecoder(X.SET,(e,t)=>{if(ea(e.contents),t.sortKeys){let n=Ii.decodeToEncodeOpts(t),r=null;for(let i of e.contents){let e=[i,void 0,Oi(i,n)];if(r&&t.sortKeys(r,e)>=0)throw Error(`Set items out of order in tag #${X.SET}`);r=e}}return new Set(e.contents)},`Set`),$(Set,(e,t,n)=>{let r=[...e];if(n.sortKeys){let e=r.map(e=>[e,void 0,Oi(e,n)]);e.sort(n.sortKeys),r=e.map(([e])=>e)}return[X.SET,r]}),Q.registerDecoder(X.JSON,e=>(Qi(e.contents),JSON.parse(e.contents)),`JSON-encoded`);function da(e){return $i(e.contents),new Qr().decode(e.contents)}da.comment=e=>{$i(e.contents);let t=new Qr;return`(WTF8 string): ${JSON.stringify(t.decode(e.contents))}`},Q.registerDecoder(X.WTF8,da),Q.registerDecoder(X.SELF_DESCRIBED,e=>e.contents,`Self-Described`),Q.registerDecoder(X.INVALID_16,()=>{throw Error(`Tag always invalid: ${X.INVALID_16}`)},`Invalid`),Q.registerDecoder(X.INVALID_32,()=>{throw Error(`Tag always invalid: ${X.INVALID_32}`)},`Invalid`),Q.registerDecoder(X.INVALID_64,()=>{throw Error(`Tag always invalid: ${X.INVALID_64}`)},`Invalid`),Q.registerDecoder(X.SYMBOL,e=>{let t=e.contents;if(Array.isArray(e.contents)){if(e.contents.length!==1)throw Error(`Expected Array of size 1: ${e.contents}`);[t]=e.contents}if(Qi(t),!t.length)throw Error(`Expected non-empty string: ${e.contents}`);return Symbol.for(t)},`Symbol`);function fa(e){throw Error(`Encoding ${e.constructor.name} intentionally unimplmented. It is not concrete enough to interoperate. Convert to Uint8Array first.`)}$(ArrayBuffer,fa),$(DataView,fa),typeof SharedArrayBuffer<`u`&&$(SharedArrayBuffer,fa);function pa(e){return[NaN,e.valueOf()]}$(Boolean,pa),$(Number,pa),$(String,pa),$(BigInt,pa);function ma(e){let t={...Ii.defaultDecodeOptions};if(e.dcbor?Object.assign(t,Ii.dcborDecodeOptions):e.cde&&Object.assign(t,Ii.cdeDecodeOptions),Object.assign(t,e),Object.hasOwn(t,`rejectLongNumbers`))throw TypeError(`rejectLongNumbers has changed to requirePreferred`);return t.boxed&&(t.saveOriginal=!0),t}var ha=class{parent=void 0;ret=void 0;step(e,t,n){if(this.ret=Ii.create(e,this.parent,t,n),e[2]===Yn.BREAK)if(this.parent?.isStreaming)this.parent.left=0;else throw Error(`Unexpected BREAK`);else this.parent&&this.parent.push(this.ret,n,e[3]);for(this.ret instanceof Ii&&(this.parent=this.ret);this.parent?.done;){this.ret=this.parent.convert(n);let e=this.parent.parent;e?.replaceLast(this.ret,this.parent,n),this.parent=e}}};function ga(e,t={}){let n=ma(t),r=new Mi(e,n),i=new ha;for(let e of r)i.step(e,n,r);return i.ret}var{cdeDecodeOptions:_a,dcborDecodeOptions:va,defaultDecodeOptions:ya}=Ii,ba=class{constructor(e={}){this.options={id:``,codec:`cbor`,timeout:10*1e3,share:``,chunkSize:16*1024,chunkCredit:4,topicMake:(e,t,n)=>`${e}/${t}/${n??`any`}`,topicMatch:e=>{let t=e.match(/^(.+)\/([^/]+)\/([^/]+)$/);return t?{name:t[1],operation:t[2],peerId:t[3]===`any`?void 0:t[3]}:null},...e}}},xa=class e{static uint8ArrayToBase64(e){return xe.from(e.buffer,e.byteOffset,e.byteLength).toString(`base64`)}static base64ToUint8Array(e){return new Uint8Array(xe.from(e,`base64`))}static stringify(t){return JSON.stringify(t,function(t,n){let r=this[t];return r instanceof xe?{__Buffer:e.uint8ArrayToBase64(r)}:r instanceof Uint8Array?{__Uint8Array:e.uint8ArrayToBase64(r)}:n})}static parse(e){return JSON.parse(e,(e,t)=>typeof t?.__Buffer==`string`?xe.from(t.__Buffer,`base64`):typeof t?.__Uint8Array==`string`?this.base64ToUint8Array(t.__Uint8Array):t)}},Sa=class{constructor(e){this.format=e,this.types=new mr,this.tags=new Map;let t=64e3;this.types.registerEncoder(xe,e=>[t,new Uint8Array(e.buffer,e.byteOffset,e.byteLength)]),this.tags.set(t,e=>xe.from(e.contents))}encode(e){let t;if(this.format===`cbor`)try{t=Oi(e,{types:this.types})}catch(e){throw Error(`failed to encode CBOR format`,{cause:e})}else if(this.format===`json`)try{t=xa.stringify(e)}catch(e){throw Error(`failed to encode JSON format`,{cause:e})}else throw Error(`invalid format "${this.format}"`);return t}decode(e){let t;if(this.format===`cbor`){if(!(e instanceof Uint8Array))throw Error(`failed to decode CBOR format (data type is not Uint8Array)`);if(e.byteLength===0)throw Error(`failed to decode CBOR format (data is empty)`);try{t=ga(e,{tags:this.tags})}catch(e){throw Error(`failed to decode CBOR format`,{cause:e})}}else if(this.format===`json`){if(typeof e!=`string`)throw Error(`failed to decode JSON format (data type is not string)`);if(e.length===0)throw Error(`failed to decode JSON format (data is empty)`);try{t=xa.parse(e)}catch(e){throw Error(`failed to decode JSON format`,{cause:e})}}else throw Error(`invalid format "${this.format}"`);return t}},Ca=class extends ba{constructor(e={}){super(e),this.codec=new Sa(this.options.codec)}},wa=class e extends Ca{static{this.encoder=new TextEncoder}static{this.decoder=new TextDecoder}str2buf(t){return e.encoder.encode(t)}buf2str(t){return e.decoder.decode(t)}arr2buf(e){let t;return t=e instanceof Uint8Array?e:new Uint8Array(e.buffer,e.byteOffset,e.byteLength),t}buf2arr(e,t){let n,r=t;if(r===xe)n=xe.from(e.buffer,e.byteOffset,e.byteLength);else if(r===Uint8Array)n=e;else if(r===Int8Array)n=new Int8Array(e.buffer,e.byteOffset,e.byteLength);else throw Error(`invalid data type`);return n}},Ta=e=>{let t=e.match(/^(\d+)\.(\d+)$/);if(t===null)throw Error(`invalid version string`);let n=parseInt(t[2],10);if(n>99)throw Error(`invalid version string: minor version exceeds 99`);return parseInt(t[1],10)*100+n},Ea=Ta(`1.4`),Da=Ta(`1.4`),Oa=Kn(Un(J(),Gn()),An(e=>!Array.isArray(e))),ka=Kn(Ln(Kn(J(),Mn(8192))),Mn(8)),Aa=class{constructor(e,t,n,r){this.type=e,this.id=t,this.sender=n,this.receiver=r,this.version=`MQTT+/1.4`}},ja={version:Kn(J(),Pn(/^MQTT\+\/\d+\.\d+$/)),type:J(),id:J(),sender:q(J()),receiver:q(J())},Ma=class extends Aa{constructor(e,t,n,r,i,a,o){super(`event-emission`,e,r,i),this.name=t,this.params=n,this.auth=a,this.meta=o}},Na=Wn({...ja,type:Bn(`event-emission`),name:J(),params:q(Kn(Ln(Gn()),Mn(64))),auth:q(ka),meta:q(Oa)}),Pa=class extends Aa{constructor(e,t,n,r,i,a,o,s){super(`service-call-request`,e,r,i),this.name=t,this.params=n,this.auth=a,this.meta=o,this.qos=s}},Fa=Wn({...ja,type:Bn(`service-call-request`),name:J(),params:q(Kn(Ln(Gn()),Mn(64))),auth:q(ka),meta:q(Oa),qos:q(Hn([0,1,2]))}),Ia=class extends Aa{constructor(e,t,n,r,i,a){super(`service-call-response`,e,i,a),this.name=t,this.result=n,this.error=r}},La=Wn({...ja,type:Bn(`service-call-response`),name:J(),result:q(Gn()),error:q(J())}),Ra=class extends Aa{constructor(e,t,n,r,i,a,o,s){super(`sink-push-request`,e,r,i),this.name=t,this.params=n,this.auth=a,this.meta=o,this.qos=s}},za=Wn({...ja,type:Bn(`sink-push-request`),name:J(),params:q(Kn(Ln(Gn()),Mn(64))),auth:q(ka),meta:q(Oa),qos:q(Hn([0,1,2]))}),Ba=class extends Aa{constructor(e,t,n,r,i,a){super(`sink-push-response`,e,r,i),this.name=t,this.error=n,this.credit=a}},Va=Wn({...ja,type:Bn(`sink-push-response`),name:J(),error:q(J()),credit:q(Kn(Vn(),jn(),Nn(1)))}),Ha=class extends Aa{constructor(e,t,n,r,i,a,o){super(`sink-push-chunk`,e,a,o),this.name=t,this.chunk=n,this.error=r,this.final=i}},Ua=Wn({...ja,type:Bn(`sink-push-chunk`),name:J(),chunk:q(zn(Uint8Array)),error:q(J()),final:q(Rn())}),Wa=class extends Aa{constructor(e,t,n,r,i){super(`sink-push-credit`,e,r,i),this.name=t,this.credit=n}},Ga=Wn({...ja,type:Bn(`sink-push-credit`),name:J(),credit:Kn(Vn(),jn(),Nn(0))}),Ka=class extends Aa{constructor(e,t,n,r,i,a,o,s,c){super(`source-fetch-request`,e,r,i),this.name=t,this.params=n,this.auth=a,this.meta=o,this.credit=s,this.qos=c}},qa=Wn({...ja,type:Bn(`source-fetch-request`),name:J(),params:q(Kn(Ln(Gn()),Mn(64))),auth:q(ka),meta:q(Oa),credit:q(Kn(Vn(),jn(),Nn(1))),qos:q(Hn([0,1,2]))}),Ja=class extends Aa{constructor(e,t,n,r,i,a){super(`source-fetch-response`,e,r,i),this.name=t,this.error=n,this.meta=a}},Ya=Wn({...ja,type:Bn(`source-fetch-response`),name:J(),error:q(J()),meta:q(Oa)}),Xa=class extends Aa{constructor(e,t,n,r,i,a,o){super(`source-fetch-chunk`,e,a,o),this.name=t,this.chunk=n,this.error=r,this.final=i}},Za=Wn({...ja,type:Bn(`source-fetch-chunk`),name:J(),chunk:q(zn(Uint8Array)),error:q(J()),final:q(Rn())}),Qa=class extends Aa{constructor(e,t,n,r,i){super(`source-fetch-credit`,e,r,i),this.name=t,this.credit=n}},$a=Wn({...ja,type:Bn(`source-fetch-credit`),name:J(),credit:Kn(Vn(),jn(),Nn(0))}),eo=class{makeEventEmission(e,t,n,r,i,a,o){return new Ma(e,t,n,r,i,a,o)}makeServiceCallRequest(e,t,n,r,i,a,o,s){return new Pa(e,t,n,r,i,a,o,s)}makeServiceCallResponse(e,t,n,r,i,a){return new Ia(e,t,n,r,i,a)}makeSinkPushRequest(e,t,n,r,i,a,o,s){return new Ra(e,t,n,r,i,a,o,s)}makeSinkPushResponse(e,t,n,r,i,a){return new Ba(e,t,n,r,i,a)}makeSinkPushChunk(e,t,n,r,i,a,o){return new Ha(e,t,n,r,i,a,o)}makeSinkPushCredit(e,t,n,r,i){return new Wa(e,t,n,r,i)}makeSourceFetchRequest(e,t,n,r,i,a,o,s,c){return new Ka(e,t,n,r,i,a,o,s,c)}makeSourceFetchResponse(e,t,n,r,i,a){return new Ja(e,t,n,r,i,a)}makeSourceFetchChunk(e,t,n,r,i,a,o){return new Xa(e,t,n,r,i,a,o)}makeSourceFetchCredit(e,t,n,r,i){return new Qa(e,t,n,r,i)}parse(e){if(typeof e!=`object`||!e)throw Error(`invalid argument: not an object`);if(typeof e.version!=`string`)throw Error(`invalid object: missing or invalid "version" field`);let t=e.version.match(/^MQTT\+\/(\d+\.\d+)$/),n=t===null?0:Ta(t[1]);if(Math.floor(n/100)!==Math.floor(Ea/100)||n<Da)throw Error(`protocol version mismatch (expected version 1.4...1.4, got version ${e.version})`);let r=(e,t,n)=>{let r=qn(n,e);if(!r.success){let e=r.issues.map(e=>e.message).join(`; `);throw Error(`invalid ${t} object: ${e}`)}return r.output};if(typeof e.type!=`string`)throw Error(`invalid object: missing or invalid "type" field`);if(e.type===`event-emission`){let t=r(e,`EventEmission`,Na);return this.makeEventEmission(t.id,t.name,t.params,t.sender,t.receiver,t.auth,t.meta)}else if(e.type===`service-call-request`){let t=r(e,`ServiceCallRequest`,Fa);return this.makeServiceCallRequest(t.id,t.name,t.params,t.sender,t.receiver,t.auth,t.meta,t.qos)}else if(e.type===`service-call-response`){let t=r(e,`ServiceCallResponse`,La);return this.makeServiceCallResponse(t.id,t.name,t.result,t.error,t.sender,t.receiver)}else if(e.type===`sink-push-request`){let t=r(e,`SinkPushRequest`,za);return this.makeSinkPushRequest(t.id,t.name,t.params,t.sender,t.receiver,t.auth,t.meta,t.qos)}else if(e.type===`sink-push-response`){let t=r(e,`SinkPushResponse`,Va);return this.makeSinkPushResponse(t.id,t.name,t.error,t.sender,t.receiver,t.credit)}else if(e.type===`sink-push-chunk`){let t=r(e,`SinkPushChunk`,Ua);return this.makeSinkPushChunk(t.id,t.name,t.chunk,t.error,t.final,t.sender,t.receiver)}else if(e.type===`sink-push-credit`){let t=r(e,`SinkPushCredit`,Ga);return this.makeSinkPushCredit(t.id,t.name,t.credit,t.sender,t.receiver)}else if(e.type===`source-fetch-request`){let t=r(e,`SourceFetchRequest`,qa);return this.makeSourceFetchRequest(t.id,t.name,t.params,t.sender,t.receiver,t.auth,t.meta,t.credit,t.qos)}else if(e.type===`source-fetch-response`){let t=r(e,`SourceFetchResponse`,Ya);return this.makeSourceFetchResponse(t.id,t.name,t.error,t.sender,t.receiver,t.meta)}else if(e.type===`source-fetch-chunk`){let t=r(e,`SourceFetchChunk`,Za);return this.makeSourceFetchChunk(t.id,t.name,t.chunk,t.error,t.final,t.sender,t.receiver)}else if(e.type===`source-fetch-credit`){let t=r(e,`SourceFetchCredit`,$a);return this.makeSourceFetchCredit(t.id,t.name,t.credit,t.sender,t.receiver)}else throw Error(`invalid object: not of any known type`)}isRequest(e){return e instanceof Ma||e instanceof Pa||e instanceof Ka||e instanceof Ra}isResponse(e){return e instanceof Ia||e instanceof Ba||e instanceof Ha||e instanceof Wa||e instanceof Ja||e instanceof Xa||e instanceof Qa}},to=class extends wa{constructor(){super(...arguments),this.msg=new eo}},no=class{constructor(e,t,n,r){this.timestamp=e,this.level=t,this.msg=n,this.data=r}async resolve(){if(this.msg instanceof Promise&&(this.msg=await this.msg.catch(()=>`<resolve-failed>`)),this.data)for(let e of Object.keys(this.data))this.data[e]instanceof Promise&&(this.data[e]=await this.data[e].catch(()=>`<resolve-failed>`))}toString(){let e=new Date(this.timestamp),t=`${e.getFullYear()}-${(e.getMonth()+1).toString().padStart(2,`0`)}-${e.getDate().toString().padStart(2,`0`)} ${e.getHours().toString().padStart(2,`0`)}:${e.getMinutes().toString().padStart(2,`0`)}:${e.getSeconds().toString().padStart(2,`0`)}.${e.getMilliseconds().toString().padStart(3,`0`)}`,n=this.msg instanceof Promise?`<unresolved>`:this.msg,r=``;if(this.data!==void 0){let e=this.data;r=` (${Object.keys(e).map(t=>{let n=e[t]instanceof Promise?`<unresolved>`:e[t];return`${t}: ${xa.stringify(n)}`}).join(`, `)})`}return`[${t}] ${this.level}: ${n}${r}`}},ro=class extends to{constructor(){super(...arguments),this._events=new mn.EventEmitter}on(...e){this._events.on(...e)}off(...e){this._events.off(...e)}emitEvent(...e){return this._events.listenerCount(e[0])!==0&&this._events.emit(...e)}log(e,t,n){let r=new no(Date.now(),e,t,n);this.emitEvent(`log`,r)}error(e,t){let n=e;t!==void 0&&(n=Error(`${t}: ${e.message}`,{cause:e}),n.stack=e.stack);try{this.emitEvent(`error`,n),this.log(`error`,n.message)}catch{}}},io=class extends ro{constructor(e,t={}){if(super(t),this.destroyed=!1,this.onRequest=new Map,this.onResponse=new Map,e===null&&(this.log(`info`,`establishing proxy MQTT client`),e=new Proxy({},{get(e,t,n){return t===`isFakeProxy`?!0:typeof t==`string`&&[`on`,`off`,`once`].includes(t)?()=>{}:()=>{throw Error(`Underlying MQTT operation "${String(t)}" called on a null MQTT client -- only MQTT+ "emit({ ..., dry: true })" is supported in this special operation mode`)}}})),this.mqtt=e,this.options.id===``){let t=e.isFakeProxy?void 0:e.options?.clientId;this.options.id=typeof t==`string`&&t!==``?t:R()}this.log(`info`,`hooking into MQTT client`),this.messageHandler=(e,t,n)=>{if(this.destroyed)return;let r;if(this.options.codec===`json`)r=t.toString();else if(this.options.codec===`cbor`)r=be.isBuffer(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t;else{this.error(Error(`invalid codec configured`));return}this._onMessage(e,r,n)},this.mqtt.on(`message`,this.messageHandler)}async destroy(){this.destroyed=!0,this.log(`info`,`un-hooking from MQTT client`),this.mqtt.off(`message`,this.messageHandler),this.onRequest.clear(),this.onResponse.clear()}makeRegistration(e,t,n){let r=!1;return{destroy:async()=>{r||(r=!0,await e.unroll(!1)?.catch(e=>{let r=G(e,`destroy: ${t} "${n}" failed to cleanup`);throw this.error(r),r}))}}}async subscribeTopic(e,t={}){return this.log(`info`,`subscribing to MQTT topic "${e}"`),new Promise((n,r)=>{this.mqtt.subscribe(e,{qos:2,...t},(t,i)=>{if(t)this.error(t,`subscribing to MQTT topic "${e}" failed`),r(t);else if(Array.isArray(i)&&i.some(e=>typeof e?.qos==`number`&&e.qos>=128)){let t=Error(`broker rejected subscription to MQTT topic "${e}" (grant codes: ${i.map(e=>e?.qos).join(`, `)})`);this.error(t,`subscribing to MQTT topic "${e}" failed`),r(t)}else n()})})}async unsubscribeTopic(e){return this.log(`info`,`unsubscribing from MQTT topic "${e}"`),new Promise((t,n)=>{this.mqtt.unsubscribe(e,(r,i)=>{r?(this.error(r,`unsubscribing from MQTT topic "${e}" failed`),n(r)):t()})})}async publishToTopic(e,t,n={}){typeof t==`string`?this.log(`info`,`publishing to MQTT topic "${e}" (type: string, length: ${t.length} chars)`):this.log(`info`,`publishing to MQTT topic "${e}" (type: buffer, length: ${t.byteLength} bytes)`);let r=new Se((e,n)=>{let r;try{let e=this.codec.decode(t);r=this.msg.parse(e)}catch(e){return n(e)}e(r)});return this.log(`debug`,`publishing to MQTT topic "${e}"`,{message:r}),new Promise((r,i)=>{let a=typeof t==`string`?t:be.from(t.buffer,t.byteOffset,t.byteLength);this.mqtt.publish(e,a,n,t=>{t?(this.error(t,`publishing to MQTT topic "${e}" failed`),i(t)):r()})})}_onMessage(e,t,n){if(this.destroyed)return;let r;try{r=this.options.topicMatch(e)}catch(e){this.error(G(e,`failed to match MQTT topic`));return}if(r===null)return;typeof t==`string`?this.log(`info`,`received from MQTT topic "${e}" (type: string, length: ${t.length} chars)`):this.log(`info`,`received from MQTT topic "${e}" (type: buffer, length: ${t.byteLength} bytes)`);let i;try{i=this.codec.decode(t)}catch(e){this.error(G(e,`failed to parse message into object`));return}let a;try{a=this.msg.parse(i)}catch(e){this.error(G(e,`failed to parse object into typed message object`));return}if(this.log(`debug`,`received from MQTT topic "${e}"`,{message:a}),r.peerId!==void 0&&a.receiver!==void 0&&a.receiver!==r.peerId&&this.log(`warning`,`receiver mismatch on direct topic "${e}" (expected "${r.peerId}", got "${a.receiver}")`),this.msg.isRequest(a)){let t=this.onRequest.get(`${a.type}:${a.name}`);t!==void 0&&Promise.resolve().then(()=>{if(!this.destroyed)return t(a,r.name)}).catch(t=>{this.error(G(t,`dispatching request message from MQTT topic "${e}" (type: ${a.type}, id: ${a.id}, name: ${a.name}) failed`))})}else if(this.msg.isResponse(a)){let t=this.onResponse.get(`${a.type}:${a.id}`);t!==void 0&&Promise.resolve().then(()=>{if(!this.destroyed)return t(a,r.name)}).catch(t=>{this.error(G(t,`dispatching response message from MQTT topic "${e}" (type: ${a.type}, id: ${a.id}, name: ${a.name}) failed`))})}}},ao=class{constructor(e,t,n=30*1e3){this.subscribeFn=e,this.unsubscribeFn=t,this.lingerMs=n,this.counts=new Map,this.pending=new Map,this.lingers=new Map,this.unsubbing=new Map}incrementCount(e){let t=this.counts.get(e)??0;return this.counts.set(e,t+1),t}decrementCount(e){let t=this.counts.get(e);if(t!==void 0)return t<=1?(this.counts.delete(e),0):(this.counts.set(e,t-1),t-1)}clearCount(e){this.counts.delete(e)}async subscribe(e,t={qos:2}){if(this.incrementCount(e)===0){let n=this.lingers.get(e);if(n){clearTimeout(n),this.lingers.delete(e);return}let r,i,a=new Promise((e,t)=>{r=e,i=t});a.catch(()=>{}),this.pending.set(e,a);let o=this.unsubbing.get(e);return o&&await o,this.subscribeFn(e,t).then(()=>{this.pending.delete(e),r()},t=>{this.pending.delete(e),this.clearCount(e),i(t)}),a}else{let t=this.pending.get(e);if(t)return t}}async unsubscribe(e){if(this.decrementCount(e)===0)if(this.lingerMs>0&&!e.startsWith(`$share/`)){let t=setTimeout(()=>{this.lingers.delete(e);let t=this.unsubscribeFn(e).catch(()=>{}).finally(()=>{this.unsubbing.delete(e)});this.unsubbing.set(e,t)},this.lingerMs);this.lingers.set(e,t)}else{let t=this.unsubscribeFn(e).catch(()=>{}).finally(()=>{this.unsubbing.delete(e)});this.unsubbing.set(e,t),await t}}async flush(){let e=new Set([...this.counts.keys(),...this.lingers.keys(),...this.pending.keys(),...this.unsubbing.keys()]);for(let e of this.lingers.values())clearTimeout(e);this.lingers.clear(),this.counts.clear(),await Promise.allSettled([...this.pending.values(),...this.unsubbing.values()]),await Promise.allSettled([...e].map(e=>this.unsubscribeFn(e).catch(()=>{}))),this.pending.clear(),this.unsubbing.clear()}},oo=class extends io{constructor(){super(...arguments),this.subscriptions=new ao((e,t)=>this.subscribeTopic(e,t),e=>this.unsubscribeTopic(e))}async subscribeTopicAndSpool(e,t,n={}){await Fe(`subscribe to MQTT topic "${t}"`,e,()=>this.subscriptions.subscribe(t,{qos:2,...n})),e.roll(()=>this.subscriptions.unsubscribe(t))}async destroy(){await this.subscriptions.flush(),await super.destroy()}},so=class extends oo{constructor(){super(...arguments),this.timers=new Map}async destroy(){for(let e of this.timers.values())clearTimeout(e);this.timers.clear(),await super.destroy()}timerRefresh(e,t){let n=this.timers.get(e);n!==void 0&&clearTimeout(n),this.timers.set(e,setTimeout(async()=>{if(!this.destroyed){this.timers.delete(e);try{await t()}catch(t){this.error(G(t),`timer "${e}" failed`)}}},this.options.timeout))}timerClear(e){let t=this.timers.get(e);t!==void 0&&(clearTimeout(t),this.timers.delete(e))}sleep(e,t){return new Promise(n=>{if(t?.aborted){n();return}let r=t===void 0?void 0:new AbortController,i=setTimeout(()=>{i=null,r!==void 0&&r.abort(),n()},e);typeof i.unref==`function`&&i.unref(),t!==void 0&&r!==void 0&&t.addEventListener(`abort`,()=>{i!==null&&clearTimeout(i),n()},{once:!0,signal:r.signal})})}timeout(e,t=`timeout`,n){return new Promise((r,i)=>{if(n?.aborted){i(Error(`aborted`));return}let a=n===void 0?void 0:new AbortController,o=setTimeout(()=>{o=null,a!==void 0&&a.abort(),i(Error(t))},e);typeof o.unref==`function`&&o.unref(),n!==void 0&&a!==void 0&&n.addEventListener(`abort`,()=>{o!==null&&clearTimeout(o),i(Error(`aborted`))},{once:!0,signal:a.signal})})}},co=class extends so{constructor(){super(...arguments),this._meta=new Map}meta(...e){let[t,n]=e;if(e.length===0)return Object.fromEntries(this._meta);if(e.length===1)return this._meta.get(t);n==null?this._meta.delete(t):this._meta.set(t,n)}metaStore(e){let t=e===void 0||Object.keys(e).length===0;if(!(this._meta.size===0&&t))return this._meta.size>0&&t?Object.fromEntries(this._meta):this._meta.size===0&&!t?e:{...Object.fromEntries(this._meta),...e}}},lo=new TextEncoder,uo=class extends co{constructor(){super(...arguments),this._credential=null,this._tokens=new Set}credential(e){if(e.length===0)throw Error(`credential must not be empty`);let t=lo.encode(e),n=lo.encode(`mqtt-plus`);this._credential=un(dn,t,n,6e5,32)}async issue(e){if(this._credential===null)throw Error(`credential has to be provided before issuing tokens`);if(e.roles.length===0)throw Error(`payload.roles must be a non-empty array`);if(e.roles.length>64)throw Error(`payload.roles must not exceed 64 roles`);let t=new $t(e);return t.setProtectedHeader({alg:`HS256`,typ:`JWT`}),await t.sign(this._credential)}authenticate(e,t){if(e===void 0){let e=Array.from(this._tokens);return e.length>0?e:void 0}else if(t===!0)this._tokens.delete(e);else{if(e.length>8192)throw Error(`token must not exceed 8192 characters`);if(!this._tokens.has(e)&&this._tokens.size>=8)throw Error(`at most 8 tokens can be authenticated at once`);this._tokens.add(e)}}async validateToken(e){if(this._credential===null)throw Error(`credential has to be provided before validating tokens`);try{return(await rn(e,this._credential)).payload}catch(e){let t=e?.code??e?.name??`unknown`,n=e?.message??``;return this.log(`warning`,`token validation failed`,{code:t,reason:n}),null}}async authenticated(e,t,n,r){let i=!1,a=typeof n==`string`?[n]:n.roles;if(t!==void 0)for(let n of t.slice(0,8)){if(n.length>8192)continue;let t=await this.validateToken(n);if(t!==null&&!(t.id&&t.id!==e)&&Array.isArray(t.roles)&&!(t.roles.length>64)){for(let e of a)if(t.roles.includes(e)){i=!0;break}if(i)break}}let o=typeof n==`string`||n.mode===`require`;if(!i&&o)throw Error(`${r} failed authentication`);return i}},fo=class extends uo{constructor(){super(...arguments),this.eventControllers=new Map}async destroy(){for(let e of this.eventControllers.values())e.abort(Error(`event destroyed`));this.eventControllers.clear(),await super.destroy()}async event(e,...t){if(this.destroyed)throw Error(`event: instance already destroyed`);let n,r,i={},a=this.options.share,o;if(typeof e==`object`&&e&&`name`in e?(n=e.name,r=e.callback,i=e.options??{},a=e.share??this.options.share,o=e.auth):(n=e,r=t[0]),typeof r!=`function`)throw Error(`event: callback argument is required and must be a function`);let s=new je;if(this.onRequest.has(`event-emission:${n}`))throw Error(`event: event "${n}" already registered`);let c=new Set;s.roll(()=>{for(let e of c)this.eventControllers.get(e)?.abort(Error(`event "${n}" destroyed`)),this.eventControllers.delete(e);c.clear()});let l=a===``?n:`$share/${a}/${n}`,u=this.options.topicMake(l,`event-emission`),d=this.options.topicMake(n,`event-emission`,this.options.id);return this.onRequest.set(`event-emission:${n}`,async(e,t)=>{if(e.receiver&&e.receiver!==this.options.id)return;let i=e.id,a=e.sender;if(a===void 0||a===``){this.error(Error(`invalid request: missing sender`));return}if(t!==e.name){this.log(`warning`,`event name mismatch -- dropped request for "${n}" (topic: "${t}", payload: "${e.name}")`,{requestId:i});return}let s=e.params??[];if(this.eventControllers.has(i)){this.log(`warning`,`duplicate event request id -- dropped request for event "${n}"`,{requestId:i});return}let l=new AbortController,u=l.signal;c.add(i),this.eventControllers.set(i,l);let d={sender:a,signal:u};e.receiver&&(d.receiver=e.receiver),e.meta&&(d.meta=e.meta);try{o!==void 0&&(d.authenticated=await this.authenticated(a,e.auth,o,`event "${n}"`)),await r(...s,d)}catch(e){let t=G(e);this.error(t,`handler for event "${n}" failed`)}finally{l.abort(),c.delete(i),this.eventControllers.delete(i)}}),s.roll(()=>{this.onRequest.delete(`event-emission:${n}`)}),await this.subscribeTopicAndSpool(s,u,i),await this.subscribeTopicAndSpool(s,d,i),this.makeRegistration(s,`event`,n)}emit(e,...t){if(this.destroyed)throw Error(`emit: instance already destroyed`);let n,r,i,a={},o,s;typeof e==`object`&&e&&`name`in e?(n=e.name,r=e.params,i=e.receiver,a=e.options??{},o=e.meta,s=e.dry):(n=e,r=t);let c=R(),l=this.authenticate(),u=this.metaStore(o),d=this.msg.makeEventEmission(c,n,r,this.options.id,i,l,u),f=this.codec.encode(d),p=this.options.topicMake(n,`event-emission`,i);return s?{topic:p,payload:f,options:{qos:2,...a}}:Fe(`publish event as MQTT message to topic "${p}"`,()=>this.publishToTopic(p,f,{qos:2,...a}))}},po=class extends fo{constructor(){super(...arguments),this.serviceControllers=new Map,this.pendingCalls=new Map}async destroy(){for(let e of this.serviceControllers.values())e.abort(Error(`service destroyed`));this.serviceControllers.clear();let e=[...this.pendingCalls.values()];this.pendingCalls.clear();for(let t of e)t(Error(`instance destroyed`));await super.destroy()}async service(e,...t){if(this.destroyed)throw Error(`service: instance already destroyed`);let n,r,i={},a=this.options.share,o;if(typeof e==`object`&&e&&`name`in e?(n=e.name,r=e.callback,i=e.options??{},a=e.share??this.options.share,o=e.auth):(n=e,r=t[0]),typeof r!=`function`)throw Error(`service: callback argument is required and must be a function`);let s=new je;if(this.onRequest.has(`service-call-request:${n}`))throw Error(`service: service "${n}" already registered`);let c=new Set;s.roll(()=>{for(let e of c)this.serviceControllers.get(e)?.abort(Error(`service "${n}" destroyed`)),this.serviceControllers.delete(e);c.clear()});let l=a===``?n:`$share/${a}/${n}`,u=this.options.topicMake(l,`service-call-request`),d=this.options.topicMake(n,`service-call-request`,this.options.id);return this.onRequest.set(`service-call-request:${n}`,async(e,t)=>{if(e.receiver&&e.receiver!==this.options.id)return;let i=e.id,a=e.sender,s=e.params??[];if(a===void 0||a===``){this.error(Error(`invalid request: missing sender`));return}if(t!==e.name){this.log(`warning`,`service name mismatch -- dropped request for "${n}" (topic: "${t}", payload: "${e.name}")`,{requestId:i});return}if(this.serviceControllers.has(i)){this.log(`warning`,`duplicate service request id -- dropped request for "${n}"`,{requestId:i});return}let l=new AbortController,u=l.signal;c.add(i),this.serviceControllers.set(i,l);let d={sender:a,signal:u};e.receiver&&(d.receiver=e.receiver),e.meta&&(d.meta=e.meta);let f=`service-call-handler:${i}`,p=()=>{this.timerRefresh(f,()=>{l.abort(Error(`service "${n}" handler timeout`))})},m=()=>this.timerClear(f);p();let h;try{o!==void 0&&(d.authenticated=await this.authenticated(a,e.auth,o,`service "${n}"`));let t=new Promise((e,t)=>{let n=()=>{t(G(u.reason))};u.aborted?n():(u.addEventListener(`abort`,n,{once:!0}),h=()=>u.removeEventListener(`abort`,n))}),c=await Promise.race([r(...s,d),t]),l=this.msg.makeServiceCallResponse(i,n,c,void 0,this.options.id,a),f=this.codec.encode(l),p=this.options.topicMake(n,`service-call-response`,a);await this.publishToTopic(p,f,{qos:e.qos??2})}catch(t){let r=G(t);this.error(r,`handler for service "${n}" failed`);let o=this.msg.makeServiceCallResponse(i,n,void 0,r.message,this.options.id,a);try{let t=this.codec.encode(o),r=this.options.topicMake(n,`service-call-response`,a);await this.publishToTopic(r,t,{qos:e.qos??2})}catch(e){this.error(G(e),`sending error response for service "${n}" failed`)}}finally{h?.(),m(),l.abort(),c.delete(i),this.serviceControllers.delete(i)}}),s.roll(()=>{this.onRequest.delete(`service-call-request:${n}`)}),await this.subscribeTopicAndSpool(s,u,i),await this.subscribeTopicAndSpool(s,d,i),this.makeRegistration(s,`service`,n)}async call(e,...t){if(this.destroyed)throw Error(`call: instance already destroyed`);let n,r,i,a={},o;typeof e==`object`&&e&&`name`in e?(n=e.name,r=e.params,i=e.receiver,a=e.options??{},o=e.meta):(n=e,r=t);let s=new je,c=R();for(let e=0;e<10&&this.onResponse.has(`service-call-response:${c}`);e++)c=R();if(this.onResponse.has(`service-call-response:${c}`))throw Error(`failed to generate unique request id`);let l=this.options.topicMake(n,`service-call-response`,this.options.id);await this.subscribeTopicAndSpool(s,l,{qos:a.qos??2});let u=`service-call:${c}`,d,f=!1,p=()=>f?!1:(f=!0,s.unroll(),!0),m=new Promise((e,t)=>{d=t,this.timerRefresh(u,()=>{p()&&t(Error(`communication timeout`))}),s.roll(()=>{this.timerClear(u)}),this.pendingCalls.set(c,e=>{p()&&t(e)}),s.roll(()=>{this.pendingCalls.delete(c)}),this.onResponse.set(`service-call-response:${c}`,r=>{if(!(i!==void 0&&r.sender!==i)){if(r.sender===void 0||r.sender===``){if(!p())return;t(Error(`received service response without sender`));return}if(r.name!==n){if(!p())return;t(Error(`received service response with name mismatch (expected: "${n}", received: "${r.name}")`));return}p()&&(r.error===void 0?e(r.result):t(Error(r.error)))}}),s.roll(()=>{this.onResponse.delete(`service-call-response:${c}`)})}),h=this.authenticate(),g=this.metaStore(o),_=a.qos??2,v=this.msg.makeServiceCallRequest(c,n,r,this.options.id,i,h,g,_),y=this.codec.encode(v),b=this.options.topicMake(n,`service-call-request`,i);try{await Fe(`publish service request as MQTT message to topic "${b}"`,()=>this.publishToTopic(b,y,{...a,qos:_}))}catch(e){return p()&&d(e),m}return m}},mo=class extends po{constructor(){super(...arguments),this.sourceCreditGates=new Map,this.sourceControllers=new Map,this.sourceSpools=new Map,this.sourceRequests=new Map,this.fetchAborts=new Map}async destroy(){for(let e of this.fetchAborts.values())e(Error(`instance destroyed`));this.fetchAborts.clear();for(let e of this.sourceControllers.values())e.abort(Error(`source destroyed`));for(let e of this.sourceCreditGates.values())e.abort();for(let e of[...this.sourceSpools.values()])await e.unroll();this.sourceSpools.clear(),this.sourceControllers.clear(),this.sourceCreditGates.clear(),this.sourceRequests.clear(),await super.destroy()}async source(e,...t){if(this.destroyed)throw Error(`source: instance already destroyed`);let n,r,i={},a=this.options.share,o;if(typeof e==`object`&&e&&`name`in e?(n=e.name,r=e.callback,i=e.options??{},a=e.share??this.options.share,o=e.auth):(n=e,r=t[0]),typeof r!=`function`)throw Error(`source: callback argument is required and must be a function`);let s=new je;if(this.onRequest.has(`source-fetch-request:${n}`))throw Error(`source: source "${n}" already registered`);let c=a===``?n:`$share/${a}/${n}`,l=this.options.topicMake(c,`source-fetch-request`),u=this.options.topicMake(n,`source-fetch-request`,this.options.id);return this.onRequest.set(`source-fetch-request:${n}`,async(e,t)=>{if(e.receiver&&e.receiver!==this.options.id)return;let a=e.id,s=e.params??[],c=e.sender,l=e.receiver,u=new je;if(c===void 0||c===``){this.error(Error(`invalid request: missing sender`)),await u.unroll();return}let d=this.options.topicMake(n,`source-fetch-response`,c),f=(e,t)=>Error(`${e} name mismatch (expected "${n}", got "${t}")`),p=async(t,r)=>{let o=this.metaStore(r),s=this.msg.makeSourceFetchResponse(a,n,t,this.options.id,c,o),l=this.codec.encode(s);await this.publishToTopic(d,l,{qos:e.qos??i.qos??2})},m=new AbortController,h=m.signal;if(this.sourceControllers.has(a)){let e=Error(`source: duplicate request id "${a}"`);this.error(e),await p(e.message).catch(()=>{}),await u.unroll();return}this.sourceControllers.set(a,m),u.roll(()=>{this.sourceControllers.delete(a)}),this.sourceSpools.set(a,u),u.roll(()=>{this.sourceSpools.delete(a)});let g={sender:c,signal:h};l&&(g.receiver=l),e.meta&&(g.meta=e.meta);let _=this.sourceRequests.get(n);_||(_=new Set,this.sourceRequests.set(n,_)),_.add(a),u.roll(()=>{let e=this.sourceRequests.get(n);e===_&&(e.delete(a),e.size===0&&this.sourceRequests.delete(n))}),h.addEventListener(`abort`,()=>{g.stream instanceof L.Readable&&!g.stream.destroyed&&g.stream.destroy(G(h.reason))},{once:!0}),u.roll(()=>{h.aborted&&g.stream instanceof L.Readable&&!g.stream.destroyed&&g.stream.destroy(G(h.reason))});let v,y=new Promise((e,t)=>{v=t});y.catch(()=>{});let b=()=>{v(G(h.reason))};h.aborted?b():h.addEventListener(`abort`,b,{once:!0}),u.roll(()=>{h.removeEventListener(`abort`,b)});let x=`source-fetch-send:${a}`,S=()=>{h.aborted||this.timerRefresh(x,()=>{m.abort(Error(`source fetch "${n}" timed out`))})},ee=()=>this.timerClear(x);S(),u.roll(()=>{ee()});let C=async(t,r,o)=>{S();let s=this.msg.makeSourceFetchChunk(a,n,t,r,o,this.options.id,c),l=this.codec.encode(s);await this.publishToTopic(d,l,{qos:e.qos??i.qos??2})},w=!1,T,E=!1;try{if(t!==e.name)throw Error(`source name mismatch (topic: "${t}", payload: "${e.name}")`);this.onResponse.set(`source-fetch-credit:${a}`,e=>{if(!h.aborted){if(e.name!==n){m.abort(f(`source credit`,e.name));return}if(e.sender===void 0||e.sender===``){m.abort(Error(`source credit for "${n}" missing sender`));return}if(e.sender===c){if(e.credit===0){E=!0,m.abort(Error(`source fetch "${n}" cancelled by fetcher`));return}T&&(T.replenish(e.credit),S())}}}),u.roll(()=>{this.onResponse.delete(`source-fetch-credit:${a}`)}),o!==void 0&&(g.authenticated=await this.authenticated(c,e.auth,o,`source "${n}"`));let i=Promise.resolve(r(...s,g));if(i.catch(()=>{}),await Promise.race([i,y]),!(g.stream instanceof L.Readable)&&!(g.buffer instanceof Promise)&&!(g.buffer instanceof Uint8Array))throw Error(`handler did not provide data via info.stream or info.buffer fields`);if(g.stream instanceof L.Readable&&(g.buffer instanceof Promise||g.buffer instanceof Uint8Array))throw Error(`handler has set both info.stream and info.buffer fields`);let l=e.credit;if(T=l!==void 0&&l>0?new Ce(l):void 0,T){let e=T;this.sourceCreditGates.set(a,e),u.roll(()=>{e.abort(),this.sourceCreditGates.delete(a)})}if(await p(void 0,g.meta),w=!0,g.stream instanceof L.Readable)await ke(g.stream,this.options.chunkSize,C,T,h);else if(g.buffer instanceof Promise||g.buffer instanceof Uint8Array){let e;if(g.buffer instanceof Promise){let t=g.buffer;t.catch(()=>{}),e=await Promise.race([t,y])}else e=g.buffer;h.throwIfAborted(),await Oe(e,this.options.chunkSize,C,T,h)}}catch(e){let t=G(e,`handler for source "${n}" failed`);m.abort(t),E||(this.error(t),w?await C(void 0,t.message,!0).catch(()=>{}):await p(t.message).catch(()=>{}))}finally{await u.unroll()}}),s.roll(()=>{this.onRequest.delete(`source-fetch-request:${n}`)}),s.roll(()=>{let e=this.sourceRequests.get(n);if(e){for(let t of e){let e=this.sourceControllers.get(t);e&&e.abort(Error(`source "${n}" destroyed`));let r=this.sourceCreditGates.get(t);r&&r.abort()}this.sourceRequests.delete(n)}}),await this.subscribeTopicAndSpool(s,l,i),await this.subscribeTopicAndSpool(s,u,i),this.makeRegistration(s,`source`,n)}async fetch(e,...t){if(this.destroyed)throw Error(`fetch: instance already destroyed`);let n,r,i,a={},o;typeof e==`object`&&e&&`name`in e?(n=e.name,r=e.params,i=e.receiver,a=e.options??{},o=e.meta):(n=e,r=t);let s=new je,c=R();for(let e=0;e<10&&(this.onResponse.has(`source-fetch-response:${c}`)||this.onResponse.has(`source-fetch-chunk:${c}`));e++)c=R();if(this.onResponse.has(`source-fetch-response:${c}`)||this.onResponse.has(`source-fetch-chunk:${c}`))throw Error(`failed to generate unique request id`);let l=this.options.topicMake(n,`source-fetch-response`,this.options.id),u=(e,t)=>Error(`${e} name mismatch (expected "${n}", got "${t}")`);await this.subscribeTopicAndSpool(s,l,{qos:a.qos??2});let d=this.options.chunkCredit,f=d>0?d*this.options.chunkSize:16*1024,p=0,m=d,h=i,g=!1,_=!1,v=[],y=(e,t)=>{if(t===void 0||t===``){_=!0;let t=Error(`received ${e} without sender`);return x(t),C?.destroy(t),s.unroll()?.catch(()=>{}),!1}if(h===void 0)h=t;else if(t!==h)return!1;return!0},b,x,S=new Promise((e,t)=>{b=e,x=t});S.catch(()=>{}),s.roll(()=>{b(void 0)});let ee=`source-fetch-recv:${c}`,C,w=()=>{_||C&&C.destroyed||this.timerRefresh(ee,()=>{let e=Error(`communication timeout`);x(e),C?.destroy(e)})};s.roll(()=>{this.timerClear(ee)}),C=new De({highWaterMark:f,read:e=>{if(d<=0||_)return;let t=h;if(!t)return;let r=m-p,i=Math.max(0,f-(C?.readableLength??0)),o=Math.floor(i/this.options.chunkSize),s=Math.max(0,o-r);if(s>0){m+=s;let e=this.msg.makeSourceFetchCredit(c,n,s,this.options.id,t),r=this.codec.encode(e),i=this.options.topicMake(n,`source-fetch-request`,t);this.publishToTopic(i,r,{qos:a.qos??2}).catch(e=>{let t=G(e,`sending source fetch credit failed`);this.error(t),E(t)}),w()}}});let T=C.buffer;w();let E=e=>{_=!0,x(e),C.destroy(e)};this.fetchAborts.set(c,E),s.roll(()=>{this.fetchAborts.delete(c)});let D=!1,te=e=>{if(!D&&!_){D=!0;let e=h;if(e){let t=this.msg.makeSourceFetchCredit(c,n,0,this.options.id,e),r=this.codec.encode(t),i=this.options.topicMake(n,`source-fetch-request`,e);this.publishToTopic(i,r,{qos:a.qos??2}).catch(e=>this.error(G(e,`sending source fetch cancel failed`)))}}_||x(e===void 0?Error(`stream aborted`):G(e)),s.unroll()?.catch(()=>{})};C.once(`close`,()=>te()),C.once(`error`,e=>te(e));let O=e=>{if(e.error)E(Error(e.error));else{if(w(),e.chunk!==void 0){if(d>0&&p>=m){E(Error(`flow control violation`));return}p++,C.destroyed||C.push(e.chunk)}e.final&&(_=!0,C.destroyed||C.push(null),s.unroll()?.catch(()=>{}))}};this.onResponse.set(`source-fetch-response:${c}`,e=>{if(!_){if(e.name!==n){E(u(`source response`,e.name));return}if(y(`source response`,e.sender))if(e.error)E(Error(e.error));else{if(g)return;g=!0,b(e.meta),w();for(let e of v){if(_)break;O(e)}v.length=0}}}),this.onResponse.set(`source-fetch-chunk:${c}`,e=>{if(!_){if(e.name!==n){E(u(`source chunk`,e.name));return}if(y(`source chunk`,e.sender)){if(!g){if(d>0&&v.length>=m){E(Error(`flow control violation`));return}v.push(e);return}O(e)}}}),s.roll(()=>{this.onResponse.delete(`source-fetch-response:${c}`),this.onResponse.delete(`source-fetch-chunk:${c}`)});let ne=this.authenticate(),k=this.metaStore(o),re=d>0?d:void 0,A=this.msg.makeSourceFetchRequest(c,n,r,this.options.id,i,ne,k,re,a.qos),ie=this.codec.encode(A),j=this.options.topicMake(n,`source-fetch-request`,i);await Fe(`publish fetch request as MQTT message to topic "${j}"`,()=>this.publishToTopic(j,ie,{qos:2,...a})).catch(e=>{let t=G(e);x(t),C.destroy(t)});let M={stream:C,buffer:T,meta:S};return Ae(M,`stream`,`buffer`,e=>{e===`stream`?C.stopCollecting():e===`buffer`&&C.resume()}),M}},ho=class extends mo{constructor(){super(...arguments),this.pushStreams=new Map,this.pushSpools=new Map,this.pushRecvControllers=new Map,this.destroying=!1,this.pushControllers=new Map,this.pushCreditGates=new Map,this.pushSenderSpools=new Map}async destroy(){this.destroying=!0;for(let e of this.pushSenderSpools.keys())this.timerClear(`sink-push-send:${e}`);for(let e of this.pushSpools.keys())this.timerClear(`sink-push-recv:${e}`);for(let e of this.pushControllers.values())e.abort(Error(`sink destroyed`));for(let e of this.pushCreditGates.values())e.abort();for(let e of[...this.pushSenderSpools.values()])await e.unroll();this.pushSenderSpools.clear(),this.pushControllers.clear(),this.pushCreditGates.clear();for(let e of this.pushRecvControllers.values())e.abort(Error(`sink destroyed`));this.pushRecvControllers.clear();for(let e of this.pushStreams.values())e.destroy(Error(`sink destroyed`));this.pushStreams.clear();for(let e of[...this.pushSpools.values()])await e.unroll();this.pushSpools.clear(),await super.destroy()}async sink(e,...t){if(this.destroyed)throw Error(`sink: instance already destroyed`);let n,r,i={},a=this.options.share,o;if(typeof e==`object`&&e&&`name`in e?(n=e.name,r=e.callback,i=e.options??{},a=e.share??this.options.share,o=e.auth):(n=e,r=t[0]),typeof r!=`function`)throw Error(`sink: callback argument is required and must be a function`);let s=new je;if(this.onRequest.has(`sink-push-request:${n}`))throw Error(`sink: sink "${n}" already registered`);let c=a===``?n:`$share/${a}/${n}`,l=this.options.topicMake(c,`sink-push-request`),u=this.options.topicMake(n,`sink-push-request`,this.options.id);return this.onRequest.set(`sink-push-request:${n}`,async(e,t)=>{if(e.receiver&&e.receiver!==this.options.id)return;let a=e.id,s=e.params??[],c=e.sender,l=e.receiver,u=new je;if(c===void 0||c===``){this.error(Error(`invalid request: missing sender`)),await u.unroll();return}let d=this.options.topicMake(n,`sink-push-response`,c),f=e=>Error(`sink name mismatch (expected "${n}", got "${e}")`),p=this.options.chunkCredit,m=async(t,r=!1)=>{let o=t===void 0&&r&&p>0?p:void 0,s=this.msg.makeSinkPushResponse(a,n,t,this.options.id,c,o),l=this.codec.encode(s);await this.publishToTopic(d,l,{qos:e.qos??i.qos??2})},h=new AbortController,g=h.signal,_,v=new Promise((e,t)=>{_=t});v.catch(()=>{});let y=()=>{_(G(g.reason))};if(g.aborted?y():g.addEventListener(`abort`,y,{once:!0}),u.roll(()=>{g.removeEventListener(`abort`,y)}),this.pushRecvControllers.has(a)){let e=Error(`sink: duplicate request id "${a}"`);this.error(e),await m(e.message).catch(()=>{}),await u.unroll();return}this.pushRecvControllers.set(a,h),u.roll(()=>{this.pushRecvControllers.delete(a)}),this.pushSpools.set(a,u),u.roll(()=>{this.pushSpools.delete(a)});let b=!1,x=!1,S=!1,ee,C=()=>{};try{if(t!==e.name)throw Error(`sink name mismatch (topic: "${t}", payload: "${e.name}")`);let _;o!==void 0&&(_=await this.authenticated(c,e.auth,o,`sink "${n}"`));let y=p>0?{chunksReceived:0,creditGranted:p}:void 0,w=p>0?p*this.options.chunkSize:16*1024,T=!1,E=`sink-push-recv:${a}`,D=()=>this.timerRefresh(E,()=>{if(T||this.destroying)return;let t=Error(`push stream timeout`);h.abort(t),T=!0;let r=this.pushStreams.get(a);if(r!==void 0&&!r.destroyed&&r.destroy(t),c&&!S){S=!0;let t=this.msg.makeSinkPushCredit(a,n,0,this.options.id,c),r=this.codec.encode(t);this.publishToTopic(d,r,{qos:e.qos??i.qos??2}).catch(()=>{})}}),te=()=>this.timerClear(E),O=new De({highWaterMark:w,read:t=>{if(!y||!this.pushSpools.has(a))return;let r=y.creditGranted-y.chunksReceived,o=Math.max(0,w-O.readableLength),s=Math.floor(o/this.options.chunkSize),l=Math.max(0,s-r);if(l>0){y.creditGranted+=l;let t=this.msg.makeSinkPushCredit(a,n,l,this.options.id,c),r=this.codec.encode(t);this.publishToTopic(d,r,{qos:e.qos??i.qos??2}).catch(e=>{let t=G(e,`sending sink push credit failed`);this.error(t),O.destroy(t)}),D()}}});ee=O,this.pushStreams.set(a,O),u.roll(()=>{this.pushStreams.delete(a)}),O.on(`error`,C),u.roll(()=>{if(!b&&!g.aborted&&!this.destroying&&h.abort(Error(`push stream closed`)),!b&&!this.destroying&&!S&&c){let t=this.msg.makeSinkPushCredit(a,n,0,this.options.id,c),r=this.codec.encode(t);this.publishToTopic(d,r,{qos:e.qos??i.qos??2}).catch(e=>this.error(G(e,`sending sink push cancel failed`)))}}),this.onResponse.set(`sink-push-chunk:${a}`,async e=>{if(!T){if(e.name!==n){T=!0,te(),O.destroy(f(e.name));return}if(e.sender===void 0||e.sender===``){T=!0,te(),O.destroy(Error(`sink chunk for "${n}" missing sender`));return}if(e.sender===c)if(e.error!==void 0)T=!0,te(),O.destroy(Error(e.error));else{if(D(),e.chunk!==void 0){if(y){if(y.chunksReceived>=y.creditGranted){T=!0,te(),O.destroy(Error(`flow control violation`));return}y.chunksReceived++}O.destroyed||O.push(e.chunk)}e.final&&(T=!0,te(),O.destroyed||O.push(null))}}}),u.roll(()=>{this.onResponse.delete(`sink-push-chunk:${a}`)}),D(),u.roll(()=>{te()});let ne=O.buffer,k=!1,re,A,ie=()=>{k||(k=!0,re())},j=()=>{k||(k=!0,T||O.readableEnded?re():A(Error(`push stream closed before end`)))},M=e=>{k||(k=!0,A(e))},ae=new Promise((e,t)=>{re=e,A=t,O.once(`end`,ie),O.once(`close`,j),O.once(`error`,M)});ae.finally(()=>{O.removeListener(`end`,ie),O.removeListener(`close`,j),O.removeListener(`error`,M)}).catch(()=>{});let oe={sender:c,signal:g,stream:O,buffer:ne};l&&(oe.receiver=l),_!==void 0&&(oe.authenticated=_),e.meta&&(oe.meta=e.meta),Ae(oe,`stream`,`buffer`,e=>{e===`stream`?O.stopCollecting():e===`buffer`&&O.resume()}),await m(void 0,!0),x=!0;let N=Promise.resolve(r(...s,oe));if(N.catch(()=>{}),await Promise.race([N,v]),O.readableFlowing!==!0&&!O.destroyed&&O.resume(),await ae.catch(e=>{throw this.error(G(e),`stream drain after sink "${n}" callback failed`),e}),O.collecting&&O.stopCollecting(),!g.aborted)try{b=!0,await m()}catch(e){this.error(G(e),`sending terminal response for sink "${n}" failed`)}}catch(e){let t=G(e,`handler for sink "${n}" failed`);if(h.abort(t),x&&!this.destroying){let e=this.pushStreams.get(a);e!==void 0&&!e.destroyed&&e.destroy(t)}this.error(t),S||(S=!0,await m(t.message).catch(()=>{}))}finally{let e=this.pushStreams.get(a);e!==void 0&&!e.destroyed&&!b&&!S&&e.destroy(g.aborted?G(g.reason):Error(`sink push aborted without cause`)),await u.unroll(),ee!==void 0&&ee.removeListener(`error`,C)}}),s.roll(()=>{this.onRequest.delete(`sink-push-request:${n}`)}),await this.subscribeTopicAndSpool(s,l,i),await this.subscribeTopicAndSpool(s,u,i),this.makeRegistration(s,`sink`,n)}async push(e,...t){if(this.destroyed)throw Error(`push: instance already destroyed`);let n,r,i,a,o={},s;if(typeof e==`object`&&e&&`name`in e?(n=e.name,r=e.data,i=e.params,a=e.receiver,o=e.options??{},s=e.meta):(n=e,r=t[0],i=t.slice(1)),!(r instanceof L.Readable)&&!(r instanceof Uint8Array))throw Error(`invalid data type: expected Readable or Uint8Array`);let c=new je,l=R();for(let e=0;e<10&&(this.onResponse.has(`sink-push-response:${l}`)||this.onResponse.has(`sink-push-credit:${l}`));e++)l=R();if(this.onResponse.has(`sink-push-response:${l}`)||this.onResponse.has(`sink-push-credit:${l}`))throw Error(`failed to generate unique request id`);this.pushSenderSpools.set(l,c),c.roll(()=>{this.pushSenderSpools.delete(l)});let u=this.options.topicMake(n,`sink-push-response`,this.options.id);await this.subscribeTopicAndSpool(c,u,{qos:o.qos??2});let d=new AbortController,f=d.signal;if(this.pushControllers.set(l,d),c.roll(()=>{this.pushControllers.delete(l)}),r instanceof L.Readable){let e=r;f.addEventListener(`abort`,()=>{e.destroyed||e.destroy(G(f.reason))},{once:!0})}let p=`sink-push-send:${l}`,m=()=>{f.aborted||this.timerRefresh(p,()=>{let e=Error(`push to sink "${n}" timed out`);d.abort(e)})};c.roll(()=>{this.timerClear(p)}),m();let h,g,_=0,v,y=!1,b=!1,x=!1,S=!1,ee=!1,C=!1,w=!1,T=a,E,D,te=new Promise((e,t)=>{E=e,D=t});te.catch(()=>{});let O=(e,t)=>{if(t===void 0||t===``){let t=Error(`received ${e} without sender`);return v=t,d.abort(t),b?S||(S=!0,D(t)):(x=!0,k(t)),!1}if(T===void 0)T=t;else if(t!==T)return!1;return!0},ne,k,re=new Promise((e,t)=>{ne=e,k=t});re.catch(()=>{}),this.onResponse.set(`sink-push-response:${l}`,e=>{if(e.name!==n){let t=Error(`sink response name mismatch (expected "${n}", got "${e.name}")`);v=t,d.abort(t),b?S||(S=!0,D(t)):(x=!0,k(t));return}if(O(`sink response`,e.sender))if(e.error){let t=Error(e.error);v=t,d.abort(t),b?S||(S=!0,D(t)):(x=!0,k(t))}else b?S||(C?(S=!0,E()):w=!0):(h=e.credit,b=!0,x=!0,ne())}),c.roll(()=>{this.onResponse.delete(`sink-push-response:${l}`)}),this.onResponse.set(`sink-push-credit:${l}`,e=>{if(e.name!==n){let t=Error(`sink credit name mismatch (expected "${n}", got "${e.name}")`);v=t,d.abort(t),b?S||(S=!0,D(t)):(x=!0,k(t));return}if(O(`sink credit`,e.sender)){if(e.credit===0){y=!0;let e=Error(`push to sink "${n}" cancelled by receiver`);d.abort(e),b?S||(S=!0,D(e)):(x=!0,k(e));return}if(g!==void 0)g.replenish(e.credit),m();else if(b&&h===void 0){let e=Error(`push to sink "${n}" received unsolicited credit (credit-flow disabled)`);v=e,d.abort(e),S||(S=!0,D(e))}else _+=e.credit}}),c.roll(()=>{this.onResponse.delete(`sink-push-credit:${l}`)});try{let e=()=>{let e=G(f.reason);x||(x=!0,k(e)),S||(S=!0,D(e))};f.addEventListener(`abort`,e,{once:!0}),c.roll(()=>{f.removeEventListener(`abort`,e)});let t=this.authenticate(),u=this.metaStore(s),d=this.msg.makeSinkPushRequest(l,n,i,this.options.id,a,t,u,o.qos),p=this.codec.encode(d),v=this.options.topicMake(n,`sink-push-request`,a);if(await Fe(`publish push request as MQTT message to topic "${v}"`,()=>this.publishToTopic(v,p,{qos:2,...o})),await re,h!==void 0&&h>0)g=new Ce(h+_),_>0&&m(),_=0;else if(_>0)throw Error(`push to sink "${n}" received unsolicited credit (credit-flow disabled)`);if(g&&(this.pushCreditGates.set(l,g),c.roll(()=>{this.pushCreditGates.delete(l)})),g){let e=g;c.roll(()=>{e.abort()})}let y=T;if(y===void 0)throw Error(`push to sink "${n}" missing responder`);let b=this.options.topicMake(n,`sink-push-request`,y),O=async(e,t,r)=>{m();let i=this.msg.makeSinkPushChunk(l,n,e,t,r,this.options.id,y),a=this.codec.encode(i);await this.publishToTopic(b,a,{qos:2,...o}),t===void 0&&r&&(ee=!0)};r instanceof L.Readable?await ke(r,this.options.chunkSize,O,g,f):r instanceof Uint8Array&&await Oe(r,this.options.chunkSize,O,g,f),C=!0,w&&!S&&(S=!0,E()),m(),S||await te}catch(e){let t=G(e);if(d.abort(t),b&&!v&&!y&&!ee)try{let e=T;if(e!==void 0){let r=this.options.topicMake(n,`sink-push-request`,e),i=this.msg.makeSinkPushChunk(l,n,void 0,t.message,!0,this.options.id,e),a=this.codec.encode(i);await this.publishToTopic(r,a,{qos:2,...o}).catch(()=>{})}}catch{}throw b&&!v&&await new Promise(e=>{setImmediate(e)}),v||e}finally{await c.unroll()}}};return class extends ho{}});
13
+ `,l+=c,l},Ca.noChildren=!0,Q.registerDecoder(Y.CBOR,Ca),Q.registerDecoder(Y.URI,e=>(pa(e.contents),new URL(e.contents)),`URI`),$(URL,e=>[Y.URI,e.toString()]),Q.registerDecoder(Y.BASE64URL,e=>(pa(e.contents),Er(e.contents)),`Base64url-encoded`),Q.registerDecoder(Y.BASE64,e=>(pa(e.contents),wr(e.contents)),`Base64-encoded`),Q.registerDecoder(35,e=>(pa(e.contents),new RegExp(e.contents)),`RegExp`),Q.registerDecoder(21065,e=>{pa(e.contents);let t=`^(?:${e.contents})$`;return new RegExp(t,`u`)},`I-RegExp`),Q.registerDecoder(Y.REGEXP,e=>{if(ha(e.contents),e.contents.length<1||e.contents.length>2)throw Error(`Invalid RegExp Array: ${e.contents}`);return new RegExp(e.contents[0],e.contents[1])},`RegExp`),$(RegExp,e=>[Y.REGEXP,[e.source,e.flags]]),Q.registerDecoder(64,e=>(ma(e.contents),e.contents),`uint8 Typed Array`);function wa(e,t,n){ma(e.contents);let r=e.contents.length;if(r%t.BYTES_PER_ELEMENT!==0)throw Error(`Number of bytes must be divisible by ${t.BYTES_PER_ELEMENT}, got: ${r}`);r/=t.BYTES_PER_ELEMENT;let i=new t(r),a=new DataView(e.contents.buffer,e.contents.byteOffset,e.contents.byteLength),o=a[`get${t.name.replace(/Array/,``)}`].bind(a);for(let e=0;e<r;e++)i[e]=o(e*t.BYTES_PER_ELEMENT,n);return i}function Ta(e,t,n,r,i){let a=i.forceEndian??da;if(Mi(a?t:n,e,i),ji(r.byteLength,e,J.BYTE_STRING),da===a)e.write(new Uint8Array(r.buffer,r.byteOffset,r.byteLength));else{let t=e[`write${r.constructor.name.replace(/Array/,``)}`].bind(e);for(let e of r)t(e,a)}}Q.registerDecoder(65,e=>wa(e,Uint16Array,!1),`uint16, big endian, Typed Array`),Q.registerDecoder(66,e=>wa(e,Uint32Array,!1),`uint32, big endian, Typed Array`),Q.registerDecoder(67,e=>wa(e,BigUint64Array,!1),`uint64, big endian, Typed Array`),Q.registerDecoder(68,e=>(ma(e.contents),new Uint8ClampedArray(e.contents)),`uint8 Typed Array, clamped arithmetic`),$(Uint8ClampedArray,e=>[68,new Uint8Array(e.buffer,e.byteOffset,e.byteLength)]),Q.registerDecoder(69,e=>wa(e,Uint16Array,!0),`uint16, little endian, Typed Array`),$(Uint16Array,(e,t,n)=>Ta(t,69,65,e,n)),Q.registerDecoder(70,e=>wa(e,Uint32Array,!0),`uint32, little endian, Typed Array`),$(Uint32Array,(e,t,n)=>Ta(t,70,66,e,n)),Q.registerDecoder(71,e=>wa(e,BigUint64Array,!0),`uint64, little endian, Typed Array`),$(BigUint64Array,(e,t,n)=>Ta(t,71,67,e,n)),Q.registerDecoder(72,e=>(ma(e.contents),new Int8Array(e.contents)),`sint8 Typed Array`),$(Int8Array,e=>[72,new Uint8Array(e.buffer,e.byteOffset,e.byteLength)]),Q.registerDecoder(73,e=>wa(e,Int16Array,!1),`sint16, big endian, Typed Array`),Q.registerDecoder(74,e=>wa(e,Int32Array,!1),`sint32, big endian, Typed Array`),Q.registerDecoder(75,e=>wa(e,BigInt64Array,!1),`sint64, big endian, Typed Array`),Q.registerDecoder(77,e=>wa(e,Int16Array,!0),`sint16, little endian, Typed Array`),$(Int16Array,(e,t,n)=>Ta(t,77,73,e,n)),Q.registerDecoder(78,e=>wa(e,Int32Array,!0),`sint32, little endian, Typed Array`),$(Int32Array,(e,t,n)=>Ta(t,78,74,e,n)),Q.registerDecoder(79,e=>wa(e,BigInt64Array,!0),`sint64, little endian, Typed Array`),$(BigInt64Array,(e,t,n)=>Ta(t,79,75,e,n)),Q.registerDecoder(81,e=>wa(e,Float32Array,!1),`IEEE 754 binary32, big endian, Typed Array`),Q.registerDecoder(82,e=>wa(e,Float64Array,!1),`IEEE 754 binary64, big endian, Typed Array`),Q.registerDecoder(85,e=>wa(e,Float32Array,!0),`IEEE 754 binary32, little endian, Typed Array`),$(Float32Array,(e,t,n)=>Ta(t,85,81,e,n)),Q.registerDecoder(86,e=>wa(e,Float64Array,!0),`IEEE 754 binary64, big endian, Typed Array`),$(Float64Array,(e,t,n)=>Ta(t,86,82,e,n)),Q.registerDecoder(Y.SET,(e,t)=>{if(ha(e.contents),t.sortKeys){let n=Zi.decodeToEncodeOpts(t),r=null;for(let i of e.contents){let e=[i,void 0,Ui(i,n)];if(r&&t.sortKeys(r,e)>=0)throw Error(`Set items out of order in tag #${Y.SET}`);r=e}}return new Set(e.contents)},`Set`),$(Set,(e,t,n)=>{let r=[...e];if(n.sortKeys){let e=r.map(e=>[e,void 0,Ui(e,n)]);e.sort(n.sortKeys),r=e.map(([e])=>e)}return[Y.SET,r]}),Q.registerDecoder(Y.JSON,e=>(pa(e.contents),JSON.parse(e.contents)),`JSON-encoded`);function Ea(e){return ma(e.contents),new pi().decode(e.contents)}Ea.comment=e=>{ma(e.contents);let t=new pi;return`(WTF8 string): ${JSON.stringify(t.decode(e.contents))}`},Q.registerDecoder(Y.WTF8,Ea),Q.registerDecoder(Y.SELF_DESCRIBED,e=>e.contents,`Self-Described`),Q.registerDecoder(Y.INVALID_16,()=>{throw Error(`Tag always invalid: ${Y.INVALID_16}`)},`Invalid`),Q.registerDecoder(Y.INVALID_32,()=>{throw Error(`Tag always invalid: ${Y.INVALID_32}`)},`Invalid`),Q.registerDecoder(Y.INVALID_64,()=>{throw Error(`Tag always invalid: ${Y.INVALID_64}`)},`Invalid`),Q.registerDecoder(Y.SYMBOL,e=>{let t=e.contents;if(Array.isArray(e.contents)){if(e.contents.length!==1)throw Error(`Expected Array of size 1: ${e.contents}`);[t]=e.contents}if(pa(t),!t.length)throw Error(`Expected non-empty string: ${e.contents}`);return Symbol.for(t)},`Symbol`);function Da(e){throw Error(`Encoding ${e.constructor.name} intentionally unimplmented. It is not concrete enough to interoperate. Convert to Uint8Array first.`)}$(ArrayBuffer,Da),$(DataView,Da),typeof SharedArrayBuffer<`u`&&$(SharedArrayBuffer,Da);function Oa(e){return[NaN,e.valueOf()]}$(Boolean,Oa),$(Number,Oa),$(String,Oa),$(BigInt,Oa);function ka(e){let t={...Zi.defaultDecodeOptions};if(e.dcbor?Object.assign(t,Zi.dcborDecodeOptions):e.cde&&Object.assign(t,Zi.cdeDecodeOptions),Object.assign(t,e),Object.hasOwn(t,`rejectLongNumbers`))throw TypeError(`rejectLongNumbers has changed to requirePreferred`);return t.boxed&&(t.saveOriginal=!0),t}var Aa=class{parent=void 0;ret=void 0;step(e,t,n){if(this.ret=Zi.create(e,this.parent,t,n),e[2]===Z.BREAK){if(this.parent?.isStreaming)this.parent.left=0;else throw Error(`Unexpected BREAK`)}else this.parent&&this.parent.push(this.ret,n,e[3]);for(this.ret instanceof Zi&&(this.parent=this.ret);this.parent?.done;){this.ret=this.parent.convert(n);let e=this.parent.parent;e?.replaceLast(this.ret,this.parent,n),this.parent=e}}};function ja(e,t={}){let n=ka(t),r=new qi(e,n),i=new Aa;for(let e of r)i.step(e,n,r);return i.ret}var{cdeDecodeOptions:Ma,dcborDecodeOptions:Na,defaultDecodeOptions:Pa}=Zi,Fa=class{constructor(e={}){if(this.options={id:``,codec:`cbor`,timeout:1e4,share:``,chunkSize:16384,chunkCredit:4,topicMake:(e,t,n)=>`${e}/${t}/${n??`any`}`,topicMatch:e=>{let t=e.match(/^(.+)\/([^/]+)\/([^/]+)$/);return t?{name:t[1],operation:t[2],peerId:t[3]===`any`?void 0:t[3]}:null},...e},!(Number.isFinite(this.options.timeout)&&this.options.timeout>0))throw Error(`options: "timeout" must be a positive number`);if(!(Number.isInteger(this.options.chunkSize)&&this.options.chunkSize>0))throw Error(`options: "chunkSize" must be a positive integer`);if(!(Number.isInteger(this.options.chunkCredit)&&this.options.chunkCredit>=0))throw Error(`options: "chunkCredit" must be a non-negative integer`)}},Ia=class e{static uint8ArrayToBase64(e){return H.from(e.buffer,e.byteOffset,e.byteLength).toString(`base64`)}static base64ToUint8Array(e){return new Uint8Array(H.from(e,`base64`))}static stringify(t){return JSON.stringify(t,function(t,n){let r=this[t];return r instanceof H?{__Buffer:e.uint8ArrayToBase64(r)}:r instanceof Uint8Array?{__Uint8Array:e.uint8ArrayToBase64(r)}:n})}static parse(e){return JSON.parse(e,(e,t)=>typeof t?.__Buffer==`string`?H.from(t.__Buffer,`base64`):typeof t?.__Uint8Array==`string`?this.base64ToUint8Array(t.__Uint8Array):t)}},La=class{constructor(e){this.format=e,this.types=new kr,this.tags=new Map;let t=64e3;this.types.registerEncoder(H,e=>[t,new Uint8Array(e.buffer,e.byteOffset,e.byteLength)]),this.tags.set(t,e=>H.from(e.contents))}encode(e){let t;if(this.format===`cbor`)try{t=Ui(e,{types:this.types})}catch(e){throw Error(`failed to encode CBOR format`,{cause:e})}else if(this.format===`json`)try{t=Ia.stringify(e)}catch(e){throw Error(`failed to encode JSON format`,{cause:e})}else throw Error(`invalid format "${this.format}"`);return t}decode(e){let t;if(this.format===`cbor`){if(!(e instanceof Uint8Array))throw Error(`failed to decode CBOR format (data type is not Uint8Array)`);if(e.byteLength===0)throw Error(`failed to decode CBOR format (data is empty)`);try{t=ja(e,{tags:this.tags})}catch(e){throw Error(`failed to decode CBOR format`,{cause:e})}}else if(this.format===`json`){if(typeof e!=`string`)throw Error(`failed to decode JSON format (data type is not string)`);if(e.length===0)throw Error(`failed to decode JSON format (data is empty)`);try{t=Ia.parse(e)}catch(e){throw Error(`failed to decode JSON format`,{cause:e})}}else throw Error(`invalid format "${this.format}"`);return t}},Ra=class extends Fa{constructor(e={}){super(e),this.codec=new La(this.options.codec)}},za=class e extends Ra{static{this.encoder=new TextEncoder}static{this.decoder=new TextDecoder}str2buf(t){return e.encoder.encode(t)}buf2str(t){return e.decoder.decode(t)}arr2buf(e){let t;return t=e instanceof Uint8Array?e:new Uint8Array(e.buffer,e.byteOffset,e.byteLength),t}buf2arr(e,t){let n,r=t;if(r===H)n=H.from(e.buffer,e.byteOffset,e.byteLength);else if(r===Uint8Array)n=e;else if(r===Int8Array)n=new Int8Array(e.buffer,e.byteOffset,e.byteLength);else throw Error(`invalid data type`);return n}},Ba=e=>{let t=e.match(/^(\d+)\.(\d+)$/);if(t===null)throw Error(`invalid version string`);let n=parseInt(t[2],10);if(n>99)throw Error(`invalid version string: minor version exceeds 99`);return parseInt(t[1],10)*100+n},Va=`1.4`,Ha=`1.4`,Ua=Ba(`1.4`),Wa=Ba(`1.4`),Ga=cr(ar(q(),sr()),Kn(e=>!Array.isArray(e))),Ka=cr($n(cr(q(),Jn(8192))),Jn(8)),qa=class{constructor(e,t,n,r){this.type=e,this.id=t,this.sender=n,this.receiver=r,this.version=`MQTT+/1.4`}},Ja={version:cr(q(),Xn(/^MQTT\+\/\d+\.\d+$/)),type:q(),id:q(),sender:K(q()),receiver:K(q())},Ya=class extends qa{constructor(e,t,n,r,i,a,o){super(`event-emission`,e,r,i),this.name=t,this.params=n,this.auth=a,this.meta=o}},Xa=or({...Ja,type:nr(`event-emission`),name:q(),params:K(cr($n(sr()),Jn(64))),auth:K(Ka),meta:K(Ga)}),Za=class extends qa{constructor(e,t,n,r,i,a,o,s){super(`service-call-request`,e,r,i),this.name=t,this.params=n,this.auth=a,this.meta=o,this.qos=s}},Qa=or({...Ja,type:nr(`service-call-request`),name:q(),params:K(cr($n(sr()),Jn(64))),auth:K(Ka),meta:K(Ga),qos:K(ir([0,1,2]))}),$a=class extends qa{constructor(e,t,n,r,i,a){super(`service-call-response`,e,i,a),this.name=t,this.result=n,this.error=r}},eo=or({...Ja,type:nr(`service-call-response`),name:q(),result:K(sr()),error:K(q())}),to=class extends qa{constructor(e,t,n,r,i,a,o,s){super(`sink-push-request`,e,r,i),this.name=t,this.params=n,this.auth=a,this.meta=o,this.qos=s}},no=or({...Ja,type:nr(`sink-push-request`),name:q(),params:K(cr($n(sr()),Jn(64))),auth:K(Ka),meta:K(Ga),qos:K(ir([0,1,2]))}),ro=class extends qa{constructor(e,t,n,r,i,a){super(`sink-push-response`,e,r,i),this.name=t,this.error=n,this.credit=a}},io=or({...Ja,type:nr(`sink-push-response`),name:q(),error:K(q()),credit:K(cr(rr(),qn(),Yn(1)))}),ao=class extends qa{constructor(e,t,n,r,i,a,o){super(`sink-push-chunk`,e,a,o),this.name=t,this.chunk=n,this.error=r,this.final=i}},oo=or({...Ja,type:nr(`sink-push-chunk`),name:q(),chunk:K(tr(Uint8Array)),error:K(q()),final:K(er())}),so=class extends qa{constructor(e,t,n,r,i){super(`sink-push-credit`,e,r,i),this.name=t,this.credit=n}},co=or({...Ja,type:nr(`sink-push-credit`),name:q(),credit:cr(rr(),qn(),Yn(0))}),lo=class extends qa{constructor(e,t,n,r,i,a,o,s,c){super(`source-fetch-request`,e,r,i),this.name=t,this.params=n,this.auth=a,this.meta=o,this.credit=s,this.qos=c}},uo=or({...Ja,type:nr(`source-fetch-request`),name:q(),params:K(cr($n(sr()),Jn(64))),auth:K(Ka),meta:K(Ga),credit:K(cr(rr(),qn(),Yn(1))),qos:K(ir([0,1,2]))}),fo=class extends qa{constructor(e,t,n,r,i,a){super(`source-fetch-response`,e,r,i),this.name=t,this.error=n,this.meta=a}},po=or({...Ja,type:nr(`source-fetch-response`),name:q(),error:K(q()),meta:K(Ga)}),mo=class extends qa{constructor(e,t,n,r,i,a,o){super(`source-fetch-chunk`,e,a,o),this.name=t,this.chunk=n,this.error=r,this.final=i}},ho=or({...Ja,type:nr(`source-fetch-chunk`),name:q(),chunk:K(tr(Uint8Array)),error:K(q()),final:K(er())}),go=class extends qa{constructor(e,t,n,r,i){super(`source-fetch-credit`,e,r,i),this.name=t,this.credit=n}},_o=or({...Ja,type:nr(`source-fetch-credit`),name:q(),credit:cr(rr(),qn(),Yn(0))}),vo=class{makeEventEmission(e,t,n,r,i,a,o){return new Ya(e,t,n,r,i,a,o)}makeServiceCallRequest(e,t,n,r,i,a,o,s){return new Za(e,t,n,r,i,a,o,s)}makeServiceCallResponse(e,t,n,r,i,a){return new $a(e,t,n,r,i,a)}makeSinkPushRequest(e,t,n,r,i,a,o,s){return new to(e,t,n,r,i,a,o,s)}makeSinkPushResponse(e,t,n,r,i,a){return new ro(e,t,n,r,i,a)}makeSinkPushChunk(e,t,n,r,i,a,o){return new ao(e,t,n,r,i,a,o)}makeSinkPushCredit(e,t,n,r,i){return new so(e,t,n,r,i)}makeSourceFetchRequest(e,t,n,r,i,a,o,s,c){return new lo(e,t,n,r,i,a,o,s,c)}makeSourceFetchResponse(e,t,n,r,i,a){return new fo(e,t,n,r,i,a)}makeSourceFetchChunk(e,t,n,r,i,a,o){return new mo(e,t,n,r,i,a,o)}makeSourceFetchCredit(e,t,n,r,i){return new go(e,t,n,r,i)}parse(e){if(typeof e!=`object`||!e)throw Error(`invalid argument: not an object`);if(typeof e.version!=`string`)throw Error(`invalid object: missing or invalid "version" field`);let t=e.version.match(/^MQTT\+\/(\d+\.\d+)$/),n=t===null?0:Ba(t[1]);if(Math.floor(n/100)!==Math.floor(Ua/100)||n<Wa)throw Error(`protocol version mismatch (expected version 1.4...1.4, got version ${e.version})`);let r=(e,t,n)=>{let r=lr(n,e);if(!r.success){let e=r.issues.map(e=>e.message).join(`; `);throw Error(`invalid ${t} object: ${e}`)}return r.output};if(typeof e.type!=`string`)throw Error(`invalid object: missing or invalid "type" field`);if(e.type===`event-emission`){let t=r(e,`EventEmission`,Xa);return this.makeEventEmission(t.id,t.name,t.params,t.sender,t.receiver,t.auth,t.meta)}if(e.type===`service-call-request`){let t=r(e,`ServiceCallRequest`,Qa);return this.makeServiceCallRequest(t.id,t.name,t.params,t.sender,t.receiver,t.auth,t.meta,t.qos)}if(e.type===`service-call-response`){let t=r(e,`ServiceCallResponse`,eo);return this.makeServiceCallResponse(t.id,t.name,t.result,t.error,t.sender,t.receiver)}if(e.type===`sink-push-request`){let t=r(e,`SinkPushRequest`,no);return this.makeSinkPushRequest(t.id,t.name,t.params,t.sender,t.receiver,t.auth,t.meta,t.qos)}if(e.type===`sink-push-response`){let t=r(e,`SinkPushResponse`,io);return this.makeSinkPushResponse(t.id,t.name,t.error,t.sender,t.receiver,t.credit)}if(e.type===`sink-push-chunk`){let t=r(e,`SinkPushChunk`,oo);return this.makeSinkPushChunk(t.id,t.name,t.chunk,t.error,t.final,t.sender,t.receiver)}if(e.type===`sink-push-credit`){let t=r(e,`SinkPushCredit`,co);return this.makeSinkPushCredit(t.id,t.name,t.credit,t.sender,t.receiver)}if(e.type===`source-fetch-request`){let t=r(e,`SourceFetchRequest`,uo);return this.makeSourceFetchRequest(t.id,t.name,t.params,t.sender,t.receiver,t.auth,t.meta,t.credit,t.qos)}if(e.type===`source-fetch-response`){let t=r(e,`SourceFetchResponse`,po);return this.makeSourceFetchResponse(t.id,t.name,t.error,t.sender,t.receiver,t.meta)}if(e.type===`source-fetch-chunk`){let t=r(e,`SourceFetchChunk`,ho);return this.makeSourceFetchChunk(t.id,t.name,t.chunk,t.error,t.final,t.sender,t.receiver)}if(e.type===`source-fetch-credit`){let t=r(e,`SourceFetchCredit`,_o);return this.makeSourceFetchCredit(t.id,t.name,t.credit,t.sender,t.receiver)}throw Error(`invalid object: not of any known type`)}isRequest(e){return e instanceof Ya||e instanceof Za||e instanceof lo||e instanceof to}isResponse(e){return e instanceof $a||e instanceof ro||e instanceof ao||e instanceof so||e instanceof fo||e instanceof mo||e instanceof go}},yo=class extends za{constructor(){super(...arguments),this.msg=new vo}},bo=class{constructor(e,t,n,r){this.timestamp=e,this.level=t,this.msg=n,this.data=r}async resolve(){if(this.msg instanceof Promise&&(this.msg=await this.msg.catch(()=>`<resolve-failed>`)),this.data)for(let e of Object.keys(this.data))this.data[e]instanceof Promise&&(this.data[e]=await this.data[e].catch(()=>`<resolve-failed>`))}toString(){let e=new Date(this.timestamp),t=`${e.getFullYear()}-${(e.getMonth()+1).toString().padStart(2,`0`)}-${e.getDate().toString().padStart(2,`0`)} ${e.getHours().toString().padStart(2,`0`)}:${e.getMinutes().toString().padStart(2,`0`)}:${e.getSeconds().toString().padStart(2,`0`)}.${e.getMilliseconds().toString().padStart(3,`0`)}`,n=this.msg instanceof Promise?`<unresolved>`:this.msg,r=``;if(this.data!==void 0){let e=this.data;r=` (${Object.keys(e).map(t=>{let n=e[t]instanceof Promise?`<unresolved>`:e[t];return`${t}: ${Ia.stringify(n)}`}).join(`, `)})`}return`[${t}] ${this.level}: ${n}${r}`}},xo=class extends yo{constructor(){super(...arguments),this._events=new jn.EventEmitter}on(...e){this._events.on(...e)}off(...e){this._events.off(...e)}emitEvent(...e){return this._events.listenerCount(e[0])!==0&&this._events.emit(...e)}log(e,t,n){let r=new bo(Date.now(),e,t,n);this.emitEvent(`log`,r)}error(e,t){let n=e;t!==void 0&&(n=Error(`${t}: ${e.message}`,{cause:e}),n.stack=e.stack);try{this.emitEvent(`error`,n),this.log(`error`,n.message)}catch{}}},So=class extends xo{constructor(e,t={}){if(super(t),this.destroyed=!1,this.onRequest=new Map,this.onResponse=new Map,e===null&&(this.log(`info`,`establishing proxy MQTT client`),e=new Proxy({},{get(e,t,n){return t===`isFakeProxy`?!0:typeof t==`string`&&[`on`,`off`,`once`].includes(t)?()=>{}:()=>{throw Error(`Underlying MQTT operation "${String(t)}" called on a null MQTT client -- only MQTT+ "emit({ ..., dry: true })" is supported in this special operation mode`)}}})),this._mqtt=e,this.options.id===``){let t=e.isFakeProxy?void 0:e.options?.clientId;this.options.id=typeof t==`string`&&t!==``?t:ue()}this.log(`info`,`hooking into MQTT client`),this._messageHandler=(e,t,n)=>{if(this.destroyed)return;let r;if(this.options.codec===`json`)r=t.toString();else if(this.options.codec===`cbor`)r=Ce.isBuffer(t)?new Uint8Array(t.buffer,t.byteOffset,t.byteLength):t;else{this.error(Error(`invalid codec configured`));return}this._onMessage(e,r,n)},this._mqtt.on(`message`,this._messageHandler)}async destroy(){this.destroyed=!0,this.log(`info`,`un-hooking from MQTT client`),this._mqtt.off(`message`,this._messageHandler),this.onRequest.clear(),this.onResponse.clear()}makeRegistration(e,t,n){let r=!1;return{destroy:async()=>{r||(r=!0,await e.unroll(!1)?.catch(e=>{let r=U(e,`destroy: ${t} "${n}" failed to cleanup`);throw this.error(r),r}))}}}async subscribeTopic(e,t={}){return this.log(`info`,`subscribing to MQTT topic "${e}"`),new Promise((n,r)=>{this._mqtt.subscribe(e,{qos:2,...t},(t,i)=>{if(t)this.error(t,`subscribing to MQTT topic "${e}" failed`),r(t);else if(Array.isArray(i)&&i.some(e=>typeof e?.qos==`number`&&e.qos>=128)){let t=Error(`broker rejected subscription to MQTT topic "${e}" (grant codes: ${i.map(e=>e?.qos).join(`, `)})`);this.error(t,`subscribing to MQTT topic "${e}" failed`),r(t)}else n()})})}async unsubscribeTopic(e){return this.log(`info`,`unsubscribing from MQTT topic "${e}"`),new Promise((t,n)=>{this._mqtt.unsubscribe(e,(r,i)=>{r?(this.error(r,`unsubscribing from MQTT topic "${e}" failed`),n(r)):t()})})}async publishToTopic(e,t,n={}){typeof t==`string`?this.log(`info`,`publishing to MQTT topic "${e}" (type: string, length: ${t.length} chars)`):this.log(`info`,`publishing to MQTT topic "${e}" (type: buffer, length: ${t.byteLength} bytes)`);let r=new Te((e,n)=>{let r;try{let e=this.codec.decode(t);r=this.msg.parse(e)}catch(e){return n(e)}e(r)});return this.log(`debug`,`publishing to MQTT topic "${e}"`,{message:r}),new Promise((r,i)=>{let a=typeof t==`string`?t:Ce.from(t.buffer,t.byteOffset,t.byteLength);this._mqtt.publish(e,a,n,t=>{t?(this.error(t,`publishing to MQTT topic "${e}" failed`),i(t)):r()})})}_onMessage(e,t,n){if(this.destroyed)return;let r;try{r=this.options.topicMatch(e)}catch(e){this.error(U(e,`failed to match MQTT topic`));return}if(r===null)return;typeof t==`string`?this.log(`info`,`received from MQTT topic "${e}" (type: string, length: ${t.length} chars)`):this.log(`info`,`received from MQTT topic "${e}" (type: buffer, length: ${t.byteLength} bytes)`);let i;try{i=this.codec.decode(t)}catch(e){this.error(U(e,`failed to parse message into object`));return}let a;try{a=this.msg.parse(i)}catch(e){this.error(U(e,`failed to parse object into typed message object`));return}if(this.log(`debug`,`received from MQTT topic "${e}"`,{message:a}),r.peerId!==void 0&&a.receiver!==void 0&&a.receiver!==r.peerId){this.log(`warning`,`receiver mismatch -- dropped message from direct topic "${e}" (expected "${r.peerId}", got "${a.receiver}")`);return}if(this.msg.isRequest(a)){let t=this.onRequest.get(`${a.type}:${a.name}`);t!==void 0&&Promise.resolve().then(()=>{if(!this.destroyed)return t(a,r.name)}).catch(t=>{this.error(U(t,`dispatching request message from MQTT topic "${e}" (type: ${a.type}, id: ${a.id}, name: ${a.name}) failed`))})}else if(this.msg.isResponse(a)){let t=this.onResponse.get(`${a.type}:${a.id}`);t!==void 0&&Promise.resolve().then(()=>{if(!this.destroyed)return t(a,r.name)}).catch(t=>{this.error(U(t,`dispatching response message from MQTT topic "${e}" (type: ${a.type}, id: ${a.id}, name: ${a.name}) failed`))})}}},Co=class{constructor(e,t,n=3e4){this.subscribeFn=e,this.unsubscribeFn=t,this.lingerMs=n,this.counts=new Map,this.pending=new Map,this.lingers=new Map,this.unsubbing=new Map}incrementCount(e){let t=this.counts.get(e)??0;return this.counts.set(e,t+1),t}decrementCount(e){let t=this.counts.get(e);if(t!==void 0)return t<=1?(this.counts.delete(e),0):(this.counts.set(e,t-1),t-1)}clearCount(e){this.counts.delete(e)}async subscribe(e,t={qos:2}){if(this.incrementCount(e)===0){let n=this.lingers.get(e);if(n){clearTimeout(n),this.lingers.delete(e);return}let r,i,a=new Promise((e,t)=>{r=e,i=t});a.catch(()=>{}),this.pending.set(e,a);let o=this.unsubbing.get(e);return o&&await o,this.subscribeFn(e,t).then(()=>{this.pending.delete(e),r()},t=>{this.pending.delete(e),this.clearCount(e),i(t)}),a}{let t=this.pending.get(e);if(t)return t}}async unsubscribe(e){if(this.decrementCount(e)===0){if(this.lingerMs>0&&!e.startsWith(`$share/`)){let t=setTimeout(()=>{this.lingers.delete(e);let t=this.unsubscribeFn(e).catch(()=>{}).finally(()=>{this.unsubbing.delete(e)});this.unsubbing.set(e,t)},this.lingerMs);this.lingers.set(e,t)}else{let t=this.unsubscribeFn(e).catch(()=>{}).finally(()=>{this.unsubbing.delete(e)});this.unsubbing.set(e,t),await t}}}async flush(){let e=new Set([...this.counts.keys(),...this.lingers.keys(),...this.pending.keys(),...this.unsubbing.keys()]);for(let e of this.lingers.values())clearTimeout(e);this.lingers.clear(),this.counts.clear(),await Promise.allSettled([...this.pending.values(),...this.unsubbing.values()]),await Promise.allSettled([...e].map(e=>this.unsubscribeFn(e).catch(()=>{}))),this.pending.clear(),this.unsubbing.clear()}},wo=class extends So{constructor(){super(...arguments),this.subscriptions=new Co((e,t)=>this.subscribeTopic(e,t),e=>this.unsubscribeTopic(e))}async subscribeTopicAndSpool(e,t,n={}){await Be(`subscribe to MQTT topic "${t}"`,e,()=>this.subscriptions.subscribe(t,{qos:2,...n})),e.roll(()=>this.subscriptions.unsubscribe(t))}async destroy(){await this.subscriptions.flush(),await super.destroy()}},To=class extends wo{constructor(){super(...arguments),this.timers=new Map}async destroy(){for(let e of this.timers.values())clearTimeout(e);this.timers.clear(),await super.destroy()}timerRefresh(e,t){let n=this.timers.get(e);n!==void 0&&clearTimeout(n),this.timers.set(e,setTimeout(async()=>{if(!this.destroyed){this.timers.delete(e);try{await t()}catch(t){this.error(U(t),`timer "${e}" failed`)}}},this.options.timeout))}timerClear(e){let t=this.timers.get(e);t!==void 0&&(clearTimeout(t),this.timers.delete(e))}sleep(e,t){return new Promise(n=>{if(t?.aborted){n();return}let r=t===void 0?void 0:new AbortController,i=setTimeout(()=>{i=null,r!==void 0&&r.abort(),n()},e);typeof i.unref==`function`&&i.unref(),t!==void 0&&r!==void 0&&t.addEventListener(`abort`,()=>{i!==null&&clearTimeout(i),n()},{once:!0,signal:r.signal})})}timeout(e,t=`timeout`,n){return new Promise((r,i)=>{if(n?.aborted){i(Error(`aborted`));return}let a=n===void 0?void 0:new AbortController,o=setTimeout(()=>{o=null,a!==void 0&&a.abort(),i(Error(t))},e);typeof o.unref==`function`&&o.unref(),n!==void 0&&a!==void 0&&n.addEventListener(`abort`,()=>{o!==null&&clearTimeout(o),i(Error(`aborted`))},{once:!0,signal:a.signal})})}},Eo=class extends To{constructor(){super(...arguments),this._meta=new Map}meta(...e){let[t,n]=e;if(e.length===0)return Object.fromEntries(this._meta);if(e.length===1)return this._meta.get(t);n==null?this._meta.delete(t):this._meta.set(t,n)}metaStore(e){let t=e===void 0||Object.keys(e).length===0;if(!(this._meta.size===0&&t))return this._meta.size>0&&t?Object.fromEntries(this._meta):this._meta.size===0&&!t?e:{...Object.fromEntries(this._meta),...e}}},Do=new TextEncoder,Oo=class extends Eo{constructor(){super(...arguments),this._credential=null,this._tokens=new Set}credential(e){if(e.length===0)throw Error(`credential must not be empty`);let t=Do.encode(e),n=Do.encode(`mqtt-plus`);this._credential=Dn(On,t,n,6e5,32)}async issue(e){if(this._credential===null)throw Error(`credential has to be provided before issuing tokens`);if(e.roles.length===0)throw Error(`payload.roles must be a non-empty array`);if(e.roles.length>64)throw Error(`payload.roles must not exceed 64 roles`);let t=new _n(e);return t.setProtectedHeader({alg:`HS256`,typ:`JWT`}),await t.sign(this._credential)}authenticate(e,t){if(e===void 0){let e=Array.from(this._tokens);return e.length>0?e:void 0}if(t===!0)this._tokens.delete(e);else{if(e.length>8192)throw Error(`token must not exceed 8192 characters`);if(!this._tokens.has(e)&&this._tokens.size>=8)throw Error(`at most 8 tokens can be authenticated at once`);this._tokens.add(e)}}async validateToken(e){if(this._credential===null)throw Error(`credential has to be provided before validating tokens`);try{return(await xn(e,this._credential)).payload}catch(e){let t=e?.code??e?.name??`unknown`,n=e?.message??``;return this.log(`warning`,`token validation failed`,{code:t,reason:n}),null}}async authenticated(e,t,n,r){let i=!1,a=typeof n==`string`?[n]:n.roles;if(t!==void 0)for(let n of t.slice(0,8)){if(n.length>8192)continue;let t=await this.validateToken(n);if(t!==null&&!(t.id&&t.id!==e)&&Array.isArray(t.roles)&&!(t.roles.length>64)){for(let e of a)if(t.roles.includes(e)){i=!0;break}if(i)break}}let o=typeof n==`string`||n.mode===`require`;if(!i&&o)throw Error(`${r} failed authentication`);return i}},ko=class extends Oo{constructor(){super(...arguments),this.eventControllers=new Map}async destroy(){for(let e of this.eventControllers.values())e.abort(Error(`event destroyed`));this.eventControllers.clear(),await super.destroy()}async event(e,...t){if(this.destroyed)throw Error(`event: instance already destroyed`);let n,r,i={},a=this.options.share,o;if(typeof e==`object`&&e&&`name`in e?(n=e.name,r=e.callback,i=e.options??{},a=e.share??this.options.share,o=e.auth):(n=e,r=t[0]),typeof r!=`function`)throw Error(`event: callback argument is required and must be a function`);let s=new Fe;if(this.onRequest.has(`event-emission:${n}`))throw Error(`event: event "${n}" already registered`);let c=new Set;s.roll(()=>{for(let e of c)this.eventControllers.get(e)?.abort(Error(`event "${n}" destroyed`)),this.eventControllers.delete(e);c.clear()});let l=a===``?n:`$share/${a}/${n}`,u=this.options.topicMake(l,`event-emission`),d=this.options.topicMake(n,`event-emission`,this.options.id);return this.onRequest.set(`event-emission:${n}`,async(e,t)=>{if(e.receiver&&e.receiver!==this.options.id)return;let i=e.id,a=e.sender;if(a===void 0||a===``){this.error(Error(`invalid request: missing sender`));return}if(t!==e.name){this.log(`warning`,`event name mismatch -- dropped request for "${n}" (topic: "${t}", payload: "${e.name}")`,{requestId:i});return}let s=Ne(e.params??[],r);if(this.eventControllers.has(i)){this.log(`warning`,`duplicate event request id -- dropped request for event "${n}"`,{requestId:i});return}let l=new AbortController,u=l.signal;c.add(i),this.eventControllers.set(i,l);let d={sender:a,signal:u};e.receiver&&(d.receiver=e.receiver),e.meta&&(d.meta=e.meta);try{o!==void 0&&(d.authenticated=await this.authenticated(a,e.auth,o,`event "${n}"`)),await r(...s,d)}catch(e){let t=U(e);this.error(t,`handler for event "${n}" failed`)}finally{l.abort(),c.delete(i),this.eventControllers.delete(i)}}),s.roll(()=>{this.onRequest.delete(`event-emission:${n}`)}),await this.subscribeTopicAndSpool(s,u,i),await this.subscribeTopicAndSpool(s,d,i),this.makeRegistration(s,`event`,n)}emit(e,...t){if(this.destroyed)throw Error(`emit: instance already destroyed`);let n,r,i,a={},o,s;typeof e==`object`&&e&&`name`in e?(n=e.name,r=e.params,i=e.receiver,a=e.options??{},o=e.meta,s=e.dry):(n=e,r=t);let c=ue(),l=this.authenticate(),u=this.metaStore(o),d=this.msg.makeEventEmission(c,n,r,this.options.id,i,l,u),f=this.codec.encode(d),p=this.options.topicMake(n,`event-emission`,i);return s?{topic:p,payload:f,options:{qos:2,...a}}:Be(`publish event as MQTT message to topic "${p}"`,()=>this.publishToTopic(p,f,{qos:2,...a}))}},Ao=class extends ko{constructor(){super(...arguments),this.serviceControllers=new Map,this.pendingCalls=new Map}async destroy(){for(let e of this.serviceControllers.values())e.abort(Error(`service destroyed`));this.serviceControllers.clear();let e=[...this.pendingCalls.values()];this.pendingCalls.clear();for(let t of e)t(Error(`instance destroyed`));await super.destroy()}async service(e,...t){if(this.destroyed)throw Error(`service: instance already destroyed`);let n,r,i={},a=this.options.share,o;if(typeof e==`object`&&e&&`name`in e?(n=e.name,r=e.callback,i=e.options??{},a=e.share??this.options.share,o=e.auth):(n=e,r=t[0]),typeof r!=`function`)throw Error(`service: callback argument is required and must be a function`);let s=new Fe;if(this.onRequest.has(`service-call-request:${n}`))throw Error(`service: service "${n}" already registered`);let c=new Set;s.roll(()=>{for(let e of c)this.serviceControllers.get(e)?.abort(Error(`service "${n}" destroyed`)),this.serviceControllers.delete(e);c.clear()});let l=a===``?n:`$share/${a}/${n}`,u=this.options.topicMake(l,`service-call-request`),d=this.options.topicMake(n,`service-call-request`,this.options.id);return this.onRequest.set(`service-call-request:${n}`,async(e,t)=>{if(e.receiver&&e.receiver!==this.options.id)return;let i=e.id,a=e.sender,s=Ne(e.params??[],r);if(a===void 0||a===``){this.error(Error(`invalid request: missing sender`));return}if(t!==e.name){this.log(`warning`,`service name mismatch -- dropped request for "${n}" (topic: "${t}", payload: "${e.name}")`,{requestId:i});return}if(this.serviceControllers.has(i)){this.log(`warning`,`duplicate service request id -- dropped request for "${n}"`,{requestId:i});return}let l=new AbortController,u=l.signal;c.add(i),this.serviceControllers.set(i,l);let d={sender:a,signal:u};e.receiver&&(d.receiver=e.receiver),e.meta&&(d.meta=e.meta);let f=`service-call-handler:${i}`,p=()=>{this.timerRefresh(f,()=>{l.abort(Error(`service "${n}" handler timeout`))})},m=()=>this.timerClear(f);p();let h;try{o!==void 0&&(d.authenticated=await this.authenticated(a,e.auth,o,`service "${n}"`));let t=new Promise((e,t)=>{let n=()=>{t(U(u.reason))};u.aborted?n():(u.addEventListener(`abort`,n,{once:!0}),h=()=>u.removeEventListener(`abort`,n))}),c=await Promise.race([r(...s,d),t]),l=this.msg.makeServiceCallResponse(i,n,c,void 0,this.options.id,a),f=this.codec.encode(l),p=this.options.topicMake(n,`service-call-response`,a);await this.publishToTopic(p,f,{qos:e.qos??2})}catch(t){let r=U(t);this.error(r,`handler for service "${n}" failed`);let o=this.msg.makeServiceCallResponse(i,n,void 0,r.message,this.options.id,a);try{let t=this.codec.encode(o),r=this.options.topicMake(n,`service-call-response`,a);await this.publishToTopic(r,t,{qos:e.qos??2})}catch(e){this.error(U(e),`sending error response for service "${n}" failed`)}}finally{h?.(),m(),l.abort(),c.delete(i),this.serviceControllers.delete(i)}}),s.roll(()=>{this.onRequest.delete(`service-call-request:${n}`)}),await this.subscribeTopicAndSpool(s,u,i),await this.subscribeTopicAndSpool(s,d,i),this.makeRegistration(s,`service`,n)}async call(e,...t){if(this.destroyed)throw Error(`call: instance already destroyed`);let n,r,i,a={},o;typeof e==`object`&&e&&`name`in e?(n=e.name,r=e.params,i=e.receiver,a=e.options??{},o=e.meta):(n=e,r=t);let s=new Fe,c=ue();for(let e=0;e<10&&this.onResponse.has(`service-call-response:${c}`);e++)c=ue();if(this.onResponse.has(`service-call-response:${c}`))throw Error(`failed to generate unique request id`);let l=this.options.topicMake(n,`service-call-response`,this.options.id);await this.subscribeTopicAndSpool(s,l,{qos:a.qos??2});let u=`service-call:${c}`,d,f=!1,p=()=>!f&&(f=!0,s.unroll(!1)?.catch(e=>{this.error(U(e,`cleanup after call of service "${n}" failed`))}),!0),m=new Promise((e,t)=>{d=t,this.timerRefresh(u,()=>{p()&&t(Error(`communication timeout`))}),s.roll(()=>{this.timerClear(u)}),this.pendingCalls.set(c,e=>{p()&&t(e)}),s.roll(()=>{this.pendingCalls.delete(c)}),this.onResponse.set(`service-call-response:${c}`,r=>{if(i===void 0||r.sender===i){if(r.sender===void 0||r.sender===``){if(!p())return;t(Error(`received service response without sender`));return}if(r.name!==n){if(!p())return;t(Error(`received service response with name mismatch (expected: "${n}", received: "${r.name}")`));return}p()&&(r.error===void 0?e(r.result):t(Error(r.error)))}}),s.roll(()=>{this.onResponse.delete(`service-call-response:${c}`)})}),h=this.authenticate(),g=this.metaStore(o),_=a.qos??2,v=this.msg.makeServiceCallRequest(c,n,r,this.options.id,i,h,g,_),y=this.codec.encode(v),b=this.options.topicMake(n,`service-call-request`,i);try{await Be(`publish service request as MQTT message to topic "${b}"`,()=>this.publishToTopic(b,y,{...a,qos:_}))}catch(e){return p()&&d(e),m}return m}},jo=class extends Ao{constructor(){super(...arguments),this.sourceCreditGates=new Map,this.sourceControllers=new Map,this.sourceSpools=new Map,this.sourceRequests=new Map,this.fetchAborts=new Map}async destroy(){for(let e of this.fetchAborts.values())e(Error(`instance destroyed`));this.fetchAborts.clear();for(let e of this.sourceControllers.values())e.abort(Error(`source destroyed`));for(let e of this.sourceCreditGates.values())e.abort();for(let e of[...this.sourceSpools.values()])await e.unroll();this.sourceSpools.clear(),this.sourceControllers.clear(),this.sourceCreditGates.clear(),this.sourceRequests.clear(),await super.destroy()}async source(e,...t){if(this.destroyed)throw Error(`source: instance already destroyed`);let n,r,i={},a=this.options.share,o;if(typeof e==`object`&&e&&`name`in e?(n=e.name,r=e.callback,i=e.options??{},a=e.share??this.options.share,o=e.auth):(n=e,r=t[0]),typeof r!=`function`)throw Error(`source: callback argument is required and must be a function`);let s=new Fe;if(this.onRequest.has(`source-fetch-request:${n}`))throw Error(`source: source "${n}" already registered`);let c=a===``?n:`$share/${a}/${n}`,l=this.options.topicMake(c,`source-fetch-request`),u=this.options.topicMake(n,`source-fetch-request`,this.options.id);return this.onRequest.set(`source-fetch-request:${n}`,async(e,t)=>{if(e.receiver&&e.receiver!==this.options.id)return;let a=e.id,s=Ne(e.params??[],r),c=e.sender,l=e.receiver,u=new Fe;if(c===void 0||c===``){this.error(Error(`invalid request: missing sender`)),await u.unroll();return}let d=this.options.topicMake(n,`source-fetch-response`,c),f=(e,t)=>Error(`${e} name mismatch (expected "${n}", got "${t}")`),p=async(t,r)=>{let o=this.metaStore(r),s=this.msg.makeSourceFetchResponse(a,n,t,this.options.id,c,o),l=this.codec.encode(s);await this.publishToTopic(d,l,{qos:e.qos??i.qos??2})},m=new AbortController,h=m.signal;if(this.sourceControllers.has(a)){let e=Error(`source: duplicate request id "${a}"`);this.error(e),await p(e.message).catch(()=>{}),await u.unroll();return}this.sourceControllers.set(a,m),u.roll(()=>{this.sourceControllers.delete(a)}),this.sourceSpools.set(a,u),u.roll(()=>{this.sourceSpools.delete(a)});let g={sender:c,signal:h};l&&(g.receiver=l),e.meta&&(g.meta=e.meta);let _=this.sourceRequests.get(n);_||(_=new Set,this.sourceRequests.set(n,_)),_.add(a),u.roll(()=>{let e=this.sourceRequests.get(n);e===_&&(e.delete(a),e.size===0&&this.sourceRequests.delete(n))});let v=()=>{},y=()=>{g.stream instanceof ce.Readable&&!g.stream.destroyed&&(g.stream.on(`error`,v),g.stream.destroy(U(h.reason)))};h.addEventListener(`abort`,y,{once:!0}),u.roll(()=>{h.aborted&&y()});let b,x=new Promise((e,t)=>{b=t});x.catch(()=>{});let S=()=>{b(U(h.reason))};h.aborted?S():h.addEventListener(`abort`,S,{once:!0}),u.roll(()=>{h.removeEventListener(`abort`,S)});let C=`source-fetch-send:${a}`,w=()=>{h.aborted||this.timerRefresh(C,()=>{m.abort(Error(`source fetch "${n}" timed out`))})},T=()=>this.timerClear(C);w(),u.roll(()=>{T()});let E=async(t,r,o)=>{w();let s=this.msg.makeSourceFetchChunk(a,n,t,r,o,this.options.id,c),l=this.codec.encode(s);await this.publishToTopic(d,l,{qos:e.qos??i.qos??2})},D=!1,O,k=!1;try{if(t!==e.name)throw Error(`source name mismatch (topic: "${t}", payload: "${e.name}")`);this.onResponse.set(`source-fetch-credit:${a}`,e=>{if(!h.aborted){if(e.name!==n){m.abort(f(`source credit`,e.name));return}if(e.sender===void 0||e.sender===``){m.abort(Error(`source credit for "${n}" missing sender`));return}if(e.sender===c){if(e.credit===0){k=!0,m.abort(Error(`source fetch "${n}" cancelled by fetcher`));return}O&&(O.replenish(e.credit),w())}}}),u.roll(()=>{this.onResponse.delete(`source-fetch-credit:${a}`)}),o!==void 0&&(g.authenticated=await this.authenticated(c,e.auth,o,`source "${n}"`));let i=Promise.resolve(r(...s,g));if(i.catch(()=>{}),await Promise.race([i,x]),!(g.stream instanceof ce.Readable)&&!(g.buffer instanceof Promise)&&!(g.buffer instanceof Uint8Array))throw Error(`handler did not provide data via info.stream or info.buffer fields`);if(g.stream instanceof ce.Readable&&(g.buffer instanceof Promise||g.buffer instanceof Uint8Array))throw Error(`handler has set both info.stream and info.buffer fields`);let l=e.credit;if(O=l!==void 0&&l>0?new Ee(l):void 0,O){let e=O;this.sourceCreditGates.set(a,e),u.roll(()=>{e.abort(),this.sourceCreditGates.delete(a)})}if(await p(void 0,g.meta),D=!0,g.stream instanceof ce.Readable)await Me(g.stream,this.options.chunkSize,E,O,h);else if(g.buffer instanceof Promise||g.buffer instanceof Uint8Array){let e;if(g.buffer instanceof Promise){let t=g.buffer;t.catch(()=>{}),e=await Promise.race([t,x])}else e=g.buffer;h.throwIfAborted(),await je(e,this.options.chunkSize,E,O,h)}}catch(e){let t=U(e,`handler for source "${n}" failed`);m.abort(t),k||(this.error(t),D?await E(void 0,t.message,!0).catch(()=>{}):await p(t.message).catch(()=>{}))}finally{await u.unroll()}}),s.roll(()=>{this.onRequest.delete(`source-fetch-request:${n}`)}),s.roll(()=>{let e=this.sourceRequests.get(n);if(e){for(let t of e){let e=this.sourceControllers.get(t);e&&e.abort(Error(`source "${n}" destroyed`));let r=this.sourceCreditGates.get(t);r&&r.abort()}this.sourceRequests.delete(n)}}),await this.subscribeTopicAndSpool(s,l,i),await this.subscribeTopicAndSpool(s,u,i),this.makeRegistration(s,`source`,n)}async fetch(e,...t){if(this.destroyed)throw Error(`fetch: instance already destroyed`);let n,r,i,a={},o;typeof e==`object`&&e&&`name`in e?(n=e.name,r=e.params,i=e.receiver,a=e.options??{},o=e.meta):(n=e,r=t);let s=new Fe,c=ue();for(let e=0;e<10&&(this.onResponse.has(`source-fetch-response:${c}`)||this.onResponse.has(`source-fetch-chunk:${c}`));e++)c=ue();if(this.onResponse.has(`source-fetch-response:${c}`)||this.onResponse.has(`source-fetch-chunk:${c}`))throw Error(`failed to generate unique request id`);let l=this.options.topicMake(n,`source-fetch-response`,this.options.id),u=(e,t)=>Error(`${e} name mismatch (expected "${n}", got "${t}")`);await this.subscribeTopicAndSpool(s,l,{qos:a.qos??2});let d=this.options.chunkCredit,f=d>0?d*this.options.chunkSize:16384,p=0,m=d,h=i,g=!1,_=!1,v=[],y=(e,t)=>{if(t===void 0||t===``){_=!0;let t=Error(`received ${e} without sender`);return x(t),w?.destroy(t),s.unroll()?.catch(()=>{}),!1}if(h===void 0)h=t;else if(t!==h)return!1;return!0},b,x,S=new Promise((e,t)=>{b=e,x=t});S.catch(()=>{}),s.roll(()=>{b(void 0)});let C=`source-fetch-recv:${c}`,w,T=()=>{_||w&&w.destroyed||this.timerRefresh(C,()=>{let e=Error(`communication timeout`);x(e),w?.destroy(e)})};s.roll(()=>{this.timerClear(C)}),w=new Ae({highWaterMark:f,read:e=>{if(d<=0||_)return;let t=h;if(!t)return;let r=m-p,i=Math.max(0,f-(w?.readableLength??0)),o=Math.floor(i/this.options.chunkSize),s=Math.max(0,o-r);if(s>0){m+=s;let e=this.msg.makeSourceFetchCredit(c,n,s,this.options.id,t),r=this.codec.encode(e),i=this.options.topicMake(n,`source-fetch-request`,t);this.publishToTopic(i,r,{qos:a.qos??2}).catch(e=>{let t=U(e,`sending source fetch credit failed`);this.error(t),D(t)}),T()}}});let E=w.buffer;T();let D=e=>{_=!0,x(e),w.destroy(e)};this.fetchAborts.set(c,D),s.roll(()=>{this.fetchAborts.delete(c)});let O=!1,k=e=>{if(!O&&!_){O=!0;let e=h;if(e){let t=this.msg.makeSourceFetchCredit(c,n,0,this.options.id,e),r=this.codec.encode(t),i=this.options.topicMake(n,`source-fetch-request`,e);this.publishToTopic(i,r,{qos:a.qos??2}).catch(e=>this.error(U(e,`sending source fetch cancel failed`)))}}_||x(e===void 0?Error(`stream aborted`):U(e)),s.unroll()?.catch(()=>{})};w.once(`close`,()=>k()),w.once(`error`,e=>k(e));let A=e=>{if(e.error)D(Error(e.error));else{if(T(),e.chunk!==void 0){if(d>0&&p>=m){D(Error(`flow control violation`));return}p++,w.destroyed||w.push(e.chunk)}e.final&&(_=!0,w.destroyed||w.push(null),s.unroll()?.catch(()=>{}))}};this.onResponse.set(`source-fetch-response:${c}`,e=>{if(!_){if(e.name!==n){D(u(`source response`,e.name));return}if(y(`source response`,e.sender)){if(e.error)D(Error(e.error));else{if(g)return;g=!0,b(e.meta),T();for(let e of v){if(_)break;A(e)}v.length=0}}}}),this.onResponse.set(`source-fetch-chunk:${c}`,e=>{if(!_){if(e.name!==n){D(u(`source chunk`,e.name));return}if(y(`source chunk`,e.sender)){if(!g){if(d>0&&v.length>=m){D(Error(`flow control violation`));return}v.push(e);return}A(e)}}}),s.roll(()=>{this.onResponse.delete(`source-fetch-response:${c}`),this.onResponse.delete(`source-fetch-chunk:${c}`)});let ee=this.authenticate(),j=this.metaStore(o),te=d>0?d:void 0,ne=this.msg.makeSourceFetchRequest(c,n,r,this.options.id,i,ee,j,te,a.qos),M=this.codec.encode(ne),re=this.options.topicMake(n,`source-fetch-request`,i);await Be(`publish fetch request as MQTT message to topic "${re}"`,()=>this.publishToTopic(re,M,{qos:2,...a})).catch(e=>{let t=U(e);x(t),w.destroy(t)});let N={stream:w,buffer:E,meta:S};return Pe(N,`stream`,`buffer`,e=>{e===`stream`?w.stopCollecting():e===`buffer`&&w.resume()}),N}},Mo=class extends jo{constructor(){super(...arguments),this.pushStreams=new Map,this.pushSpools=new Map,this.pushRecvControllers=new Map,this.destroying=!1,this.pushControllers=new Map,this.pushCreditGates=new Map,this.pushSenderSpools=new Map}async destroy(){this.destroying=!0;for(let e of this.pushSenderSpools.keys())this.timerClear(`sink-push-send:${e}`);for(let e of this.pushSpools.keys())this.timerClear(`sink-push-recv:${e}`);for(let e of this.pushControllers.values())e.abort(Error(`sink destroyed`));for(let e of this.pushCreditGates.values())e.abort();for(let e of[...this.pushSenderSpools.values()])await e.unroll();this.pushSenderSpools.clear(),this.pushControllers.clear(),this.pushCreditGates.clear();for(let e of this.pushRecvControllers.values())e.abort(Error(`sink destroyed`));this.pushRecvControllers.clear();for(let e of this.pushStreams.values())e.destroy(Error(`sink destroyed`));this.pushStreams.clear();for(let e of[...this.pushSpools.values()])await e.unroll();this.pushSpools.clear(),await super.destroy()}async sink(e,...t){if(this.destroyed)throw Error(`sink: instance already destroyed`);let n,r,i={},a=this.options.share,o;if(typeof e==`object`&&e&&`name`in e?(n=e.name,r=e.callback,i=e.options??{},a=e.share??this.options.share,o=e.auth):(n=e,r=t[0]),typeof r!=`function`)throw Error(`sink: callback argument is required and must be a function`);let s=new Fe;if(this.onRequest.has(`sink-push-request:${n}`))throw Error(`sink: sink "${n}" already registered`);let c=a===``?n:`$share/${a}/${n}`,l=this.options.topicMake(c,`sink-push-request`),u=this.options.topicMake(n,`sink-push-request`,this.options.id);return this.onRequest.set(`sink-push-request:${n}`,async(e,t)=>{if(e.receiver&&e.receiver!==this.options.id)return;let a=e.id,s=Ne(e.params??[],r),c=e.sender,l=e.receiver,u=new Fe;if(c===void 0||c===``){this.error(Error(`invalid request: missing sender`)),await u.unroll();return}let d=this.options.topicMake(n,`sink-push-response`,c),f=e=>Error(`sink name mismatch (expected "${n}", got "${e}")`),p=this.options.chunkCredit,m=async(t,r=!1)=>{let o=t===void 0&&r&&p>0?p:void 0,s=this.msg.makeSinkPushResponse(a,n,t,this.options.id,c,o),l=this.codec.encode(s);await this.publishToTopic(d,l,{qos:e.qos??i.qos??2})},h=new AbortController,g=h.signal,_,v=new Promise((e,t)=>{_=t});v.catch(()=>{});let y=()=>{_(U(g.reason))};if(g.aborted?y():g.addEventListener(`abort`,y,{once:!0}),u.roll(()=>{g.removeEventListener(`abort`,y)}),this.pushRecvControllers.has(a)){let e=Error(`sink: duplicate request id "${a}"`);this.error(e),await m(e.message).catch(()=>{}),await u.unroll();return}this.pushRecvControllers.set(a,h),u.roll(()=>{this.pushRecvControllers.delete(a)}),this.pushSpools.set(a,u),u.roll(()=>{this.pushSpools.delete(a)});let b=!1,x=!1,S=!1,C,w=()=>{};try{if(t!==e.name)throw Error(`sink name mismatch (topic: "${t}", payload: "${e.name}")`);let _;o!==void 0&&(_=await this.authenticated(c,e.auth,o,`sink "${n}"`));let y=p>0?{chunksReceived:0,creditGranted:p}:void 0,T=p>0?p*this.options.chunkSize:16384,E=!1,D=`sink-push-recv:${a}`,O=()=>this.timerRefresh(D,()=>{if(E||this.destroying)return;let t=Error(`push stream timeout`);h.abort(t),E=!0;let r=this.pushStreams.get(a);if(r!==void 0&&!r.destroyed&&r.destroy(t),c&&!S){S=!0;let t=this.msg.makeSinkPushCredit(a,n,0,this.options.id,c),r=this.codec.encode(t);this.publishToTopic(d,r,{qos:e.qos??i.qos??2}).catch(()=>{})}}),k=()=>this.timerClear(D),A=new Ae({highWaterMark:T,read:t=>{if(!y||!this.pushSpools.has(a))return;let r=y.creditGranted-y.chunksReceived,o=Math.max(0,T-A.readableLength),s=Math.floor(o/this.options.chunkSize),l=Math.max(0,s-r);if(l>0){y.creditGranted+=l;let t=this.msg.makeSinkPushCredit(a,n,l,this.options.id,c),r=this.codec.encode(t);this.publishToTopic(d,r,{qos:e.qos??i.qos??2}).catch(e=>{let t=U(e,`sending sink push credit failed`);this.error(t),A.destroy(t)}),O()}}});C=A,this.pushStreams.set(a,A),u.roll(()=>{this.pushStreams.delete(a)}),A.on(`error`,w),u.roll(()=>{if(!b&&!g.aborted&&!this.destroying&&h.abort(Error(`push stream closed`)),!b&&!this.destroying&&!S&&c){let t=this.msg.makeSinkPushCredit(a,n,0,this.options.id,c),r=this.codec.encode(t);this.publishToTopic(d,r,{qos:e.qos??i.qos??2}).catch(e=>this.error(U(e,`sending sink push cancel failed`)))}}),this.onResponse.set(`sink-push-chunk:${a}`,async e=>{if(!E){if(e.name!==n){E=!0,k(),A.destroy(f(e.name));return}if(e.sender===void 0||e.sender===``){E=!0,k(),A.destroy(Error(`sink chunk for "${n}" missing sender`));return}if(e.sender===c){if(e.error!==void 0)E=!0,k(),A.destroy(Error(e.error));else{if(O(),e.chunk!==void 0){if(y){if(y.chunksReceived>=y.creditGranted){E=!0,k(),A.destroy(Error(`flow control violation`));return}y.chunksReceived++}A.destroyed||A.push(e.chunk)}e.final&&(E=!0,k(),A.destroyed||A.push(null))}}}}),u.roll(()=>{this.onResponse.delete(`sink-push-chunk:${a}`)}),O(),u.roll(()=>{k()});let ee=A.buffer,j=!1,te,ne,M=()=>{j||(j=!0,te())},re=()=>{j||(j=!0,E||A.readableEnded?te():ne(Error(`push stream closed before end`)))},N=e=>{j||(j=!0,ne(e))},ie=new Promise((e,t)=>{te=e,ne=t,A.once(`end`,M),A.once(`close`,re),A.once(`error`,N)});ie.finally(()=>{A.removeListener(`end`,M),A.removeListener(`close`,re),A.removeListener(`error`,N)}).catch(()=>{});let ae={sender:c,signal:g,stream:A,buffer:ee};l&&(ae.receiver=l),_!==void 0&&(ae.authenticated=_),e.meta&&(ae.meta=e.meta),Pe(ae,`stream`,`buffer`,e=>{e===`stream`?A.stopCollecting():e===`buffer`&&A.resume()}),await m(void 0,!0),x=!0;let P=Promise.resolve(r(...s,ae));if(P.catch(()=>{}),await Promise.race([P,v]),A.readableFlowing!==!0&&!A.destroyed&&A.resume(),await ie.catch(e=>{throw this.error(U(e),`stream drain after sink "${n}" callback failed`),e}),A.collecting&&A.stopCollecting(),!g.aborted)try{b=!0,await m()}catch(e){this.error(U(e),`sending terminal response for sink "${n}" failed`)}}catch(e){let t=U(e,`handler for sink "${n}" failed`);if(h.abort(t),x&&!this.destroying){let e=this.pushStreams.get(a);e!==void 0&&!e.destroyed&&e.destroy(t)}this.error(t),S||(S=!0,await m(t.message).catch(()=>{}))}finally{let e=this.pushStreams.get(a);e!==void 0&&!e.destroyed&&!b&&!S&&e.destroy(g.aborted?U(g.reason):Error(`sink push aborted without cause`)),await u.unroll(),C!==void 0&&C.removeListener(`error`,w)}}),s.roll(()=>{this.onRequest.delete(`sink-push-request:${n}`)}),await this.subscribeTopicAndSpool(s,l,i),await this.subscribeTopicAndSpool(s,u,i),this.makeRegistration(s,`sink`,n)}async push(e,...t){if(this.destroyed)throw Error(`push: instance already destroyed`);let n,r,i,a,o={},s;if(typeof e==`object`&&e&&`name`in e?(n=e.name,r=e.data,i=e.params,a=e.receiver,o=e.options??{},s=e.meta):(n=e,r=t[0],i=t.slice(1)),!(r instanceof ce.Readable)&&!(r instanceof Uint8Array))throw Error(`invalid data type: expected Readable or Uint8Array`);let c=new Fe,l=ue();for(let e=0;e<10&&(this.onResponse.has(`sink-push-response:${l}`)||this.onResponse.has(`sink-push-credit:${l}`));e++)l=ue();if(this.onResponse.has(`sink-push-response:${l}`)||this.onResponse.has(`sink-push-credit:${l}`))throw Error(`failed to generate unique request id`);this.pushSenderSpools.set(l,c),c.roll(()=>{this.pushSenderSpools.delete(l)});let u=this.options.topicMake(n,`sink-push-response`,this.options.id);await this.subscribeTopicAndSpool(c,u,{qos:o.qos??2});let d=new AbortController,f=d.signal;if(this.pushControllers.set(l,d),c.roll(()=>{this.pushControllers.delete(l)}),r instanceof ce.Readable){let e=r,t=()=>{};f.addEventListener(`abort`,()=>{e.destroyed||(e.on(`error`,t),e.destroy(U(f.reason)))},{once:!0})}let p=`sink-push-send:${l}`,m=()=>{f.aborted||this.timerRefresh(p,()=>{let e=Error(`push to sink "${n}" timed out`);d.abort(e)})};c.roll(()=>{this.timerClear(p)}),m();let h,g,_=0,v,y=!1,b=!1,x=!1,S=!1,C=!1,w=!1,T=!1,E=a,D,O,k=new Promise((e,t)=>{D=e,O=t});k.catch(()=>{});let A=e=>{d.abort(e),b?S||(S=!0,O(e)):(x=!0,te(e))},ee=(e,t)=>{if(t===void 0||t===``){let t=Error(`received ${e} without sender`);return v=t,A(t),!1}if(E===void 0)E=t;else if(t!==E)return!1;return!0},j,te,ne=new Promise((e,t)=>{j=e,te=t});ne.catch(()=>{}),this.onResponse.set(`sink-push-response:${l}`,e=>{if(e.name!==n){let t=Error(`sink response name mismatch (expected "${n}", got "${e.name}")`);v=t,A(t);return}if(ee(`sink response`,e.sender)){if(e.error){let t=Error(e.error);v=t,A(t)}else b?S||(w?(S=!0,D()):T=!0):(h=e.credit,b=!0,x=!0,j())}}),c.roll(()=>{this.onResponse.delete(`sink-push-response:${l}`)}),this.onResponse.set(`sink-push-credit:${l}`,e=>{if(e.name!==n){let t=Error(`sink credit name mismatch (expected "${n}", got "${e.name}")`);v=t,A(t);return}if(ee(`sink credit`,e.sender)){if(e.credit===0){y=!0;let e=Error(`push to sink "${n}" cancelled by receiver`);A(e);return}if(g!==void 0)g.replenish(e.credit),m();else if(b&&h===void 0){let e=Error(`push to sink "${n}" received unsolicited credit (credit-flow disabled)`);v=e,A(e)}else _+=e.credit}}),c.roll(()=>{this.onResponse.delete(`sink-push-credit:${l}`)});try{let e=()=>{let e=U(f.reason);x||(x=!0,te(e)),S||(S=!0,O(e))};f.addEventListener(`abort`,e,{once:!0}),c.roll(()=>{f.removeEventListener(`abort`,e)});let t=this.authenticate(),u=this.metaStore(s),d=this.msg.makeSinkPushRequest(l,n,i,this.options.id,a,t,u,o.qos),p=this.codec.encode(d),v=this.options.topicMake(n,`sink-push-request`,a);if(await Be(`publish push request as MQTT message to topic "${v}"`,()=>this.publishToTopic(v,p,{qos:2,...o})),await ne,h!==void 0&&h>0)g=new Ee(h+_),_>0&&m(),_=0;else if(_>0)throw Error(`push to sink "${n}" received unsolicited credit (credit-flow disabled)`);if(g&&(this.pushCreditGates.set(l,g),c.roll(()=>{this.pushCreditGates.delete(l)})),g){let e=g;c.roll(()=>{e.abort()})}let y=E;if(y===void 0)throw Error(`push to sink "${n}" missing responder`);let b=this.options.topicMake(n,`sink-push-request`,y),A=async(e,t,r)=>{m();let i=this.msg.makeSinkPushChunk(l,n,e,t,r,this.options.id,y),a=this.codec.encode(i);await this.publishToTopic(b,a,{qos:2,...o}),t===void 0&&r&&(C=!0)};r instanceof ce.Readable?await Me(r,this.options.chunkSize,A,g,f):r instanceof Uint8Array&&await je(r,this.options.chunkSize,A,g,f),w=!0,T&&!S&&(S=!0,D()),m(),S||await k}catch(e){let t=U(e);if(d.abort(t),b&&!v&&!y&&!C)try{let e=E;if(e!==void 0){let r=this.options.topicMake(n,`sink-push-request`,e),i=this.msg.makeSinkPushChunk(l,n,void 0,t.message,!0,this.options.id,e),a=this.codec.encode(i);await this.publishToTopic(r,a,{qos:2,...o}).catch(()=>{})}}catch{}throw b&&!v&&await new Promise(e=>{setTimeout(e,0)}),v||e}finally{await c.unroll()}}},No=class extends Mo{};e.MIN_VERSION=Ha,e.VERSION=Va,e.default=No,e.minVersion=Wa,e.version=Ua,e.versionToNum=Ba});