@synnaxlabs/freighter 0.54.0 → 0.55.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,21 +1,21 @@
1
1
 
2
- > @synnaxlabs/freighter@0.54.0 build /home/runner/work/synnax/synnax/freighter/ts
2
+ > @synnaxlabs/freighter@0.55.0 build /home/runner/work/synnax/synnax/freighter/ts
3
3
  > tsc --noEmit && vite build
4
4
 
5
5
   Synnax - Production mode
6
- vite v8.0.3 building client environment for production...
6
+ vite v8.0.8 building client environment for production...
7
7
  
8
8
  rendering chunks...
9
9
  
10
10
  [vite:dts] Start generate declaration files...
11
- [vite:dts] Declaration files built in 1747ms.
11
+ [vite:dts] Declaration files built in 1755ms.
12
12
  
13
13
  computing gzip size...
14
- dist/freighter.js 76.93 kB │ gzip: 20.39 kB
14
+ dist/freighter.js 86.57 kB │ gzip: 23.27 kB
15
15
 
16
16
  
17
17
  rendering chunks...
18
18
  computing gzip size...
19
- dist/freighter.cjs 63.19 kB │ gzip: 18.78 kB
19
+ dist/freighter.cjs 70.52 kB │ gzip: 21.29 kB
20
20
 
21
- ✓ built in 1.95s
21
+ ✓ built in 2.01s
@@ -1,6 +1,11 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`zod`);c=s(c);var l=Object.defineProperty,u=(e,t)=>{let n={};for(var r in e)l(n,r,{get:e[r],enumerable:!0});return t||l(n,Symbol.toStringTag,{value:`Module`}),n},d=(e,t)=>{if(Array.isArray(t))return t.reduce((e,t)=>d(e,t),e??[]);if(e==null)return[t];let n=e.findIndex(e=>e==t),r=[...e];return n===-1?r.push(t):r[n]=t,r},f=(e,t)=>{if(Array.isArray(t))return t.reduce((e,t)=>f(e,t),e??[]);if(e==null)return[t];let n=e.findIndex(e=>e.key===t.key),r=[...e];return n===-1?r.push(t):r[n]=t,r},p=`synnax.caseconv.preserveCase`,m=e=>{if(typeof e!=`object`||!e)return!1;if(p in e)return!0;let t=e._zod?.def;return t==null?!1:t.innerType&&m(t.innerType)?!0:t.type===`union`&&Array.isArray(t.options)?t.options.some(m):t.type===`pipe`?m(t.in)||m(t.out):!1},h=e=>{if(e==null)return;let t=e._zod?.def;if(t?.type===`array`&&t.element!=null)return t.element;if(t?.type===`union`&&Array.isArray(t.options))for(let e of t.options){let t=h(e);if(t!=null)return t}},g=e=>{if(e==null)return null;let t=e;if(t.shape!=null)return t.shape;if(typeof t.sourceType==`function`){let e=t.sourceType();if(e?.shape!=null)return e.shape}let n=t._zod?.def;if(n==null)return null;if(n.innerType!=null)return g(n.innerType);if(n.type===`union`&&Array.isArray(n.options))for(let e of n.options){let t=g(e);if(t!=null)return t}return n.type===`pipe`?g(n.in)??g(n.out):null},ee=e=>{if(e.length===0)return e;let t=e.indexOf(`_`)===-1?e:e.replace(/_[a-z]/g,e=>e[1].toUpperCase()),n=t.charCodeAt(0);return n<65||n>90||t.length>1&&t.charCodeAt(1)>=65&&t.charCodeAt(1)<=90?t:String.fromCharCode(n+32)+t.slice(1)},te=e=>{let t=(n,r=ie)=>{if(typeof n==`string`)return e(n);if(Array.isArray(n)){let e=h(r.schema),i={recursive:r.recursive,recursiveInArray:r.recursiveInArray,schema:e};return n.map(e=>t(e,i))}if(!_(n)||r.schema!=null&&m(r.schema))return n;let i=r.recursive??!0,a=r.recursiveInArray??i,o=r.schema,s={},c=n;if(`toJSON`in c&&typeof c.toJSON==`function`)return t(c.toJSON(),r);let l=g(o),u={recursive:i,recursiveInArray:a,schema:void 0},d=Object.keys(c);for(let n=0;n<d.length;n++){let r=d[n],o=c[r],f=e(r),p=l==null?void 0:l[r]??l[f]??void 0;i&&(_(o)?ae(o)||(u.schema=p,o=t(o,u)):a&&Array.isArray(o)&&(u.schema=h(p),o=o.map(e=>{if(_(e)){if(!ae(e))return t(e,u)}else if(Array.isArray(e))return t({key:e},u).key;return e}))),s[f]=o}return s};return t},ne=te(ee),re=te(e=>e.replace(/([a-z0-9])([A-Z])/g,(e,t,n)=>`${t}_${n.toLowerCase()}`)),ie={recursive:!0,recursiveInArray:!0,schema:void 0},_=e=>typeof e==`object`&&!!e&&!Array.isArray(e),ae=e=>e instanceof Uint8Array||e instanceof Number||e instanceof String,v=e=>typeof e==`object`&&!!e&&!Array.isArray(e),oe=class{contentType=`application/json`;decoder;encoder;constructor(){this.decoder=new TextDecoder,this.encoder=new TextEncoder}encode(e,t){return this.encoder.encode(this.encodeString(e,t))}decode(e,t){return this.decodeString(this.decoder.decode(e),t)}decodeString(e,t){let n=ne(JSON.parse(e),{schema:t});return t==null?n:t.parse(n)}encodeString(e,t){let n=re((t==null?e:t.parse(e))??{},{schema:t});return JSON.stringify(n,(e,t)=>ArrayBuffer.isView(t)?Array.from(t):typeof t==`bigint`?t.toString():t)}},se=class{contentType=`text/csv`;encode(e){let t=this.encodeString(e);return new TextEncoder().encode(t)}decode(e,t){let n=new TextDecoder().decode(e);return this.decodeString(n,t)}encodeString(e){if(!Array.isArray(e)||e.length===0||!v(e[0]))throw Error(`Payload must be an array of objects`);let t=Object.keys(e[0]),n=[t.join(`,`)];return e.forEach(e=>{let r=t.map(t=>JSON.stringify(e[t]??``));n.push(r.join(`,`))}),n.join(`
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`zod`);c=s(c,1);var l=Object.defineProperty,u=(e,t)=>{let n={};for(var r in e)l(n,r,{get:e[r],enumerable:!0});return t||l(n,Symbol.toStringTag,{value:`Module`}),n},d=(e,t)=>{if(Array.isArray(t))return t.reduce((e,t)=>d(e,t),e??[]);if(e==null)return[t];let n=e.findIndex(e=>e==t),r=[...e];return n===-1?r.push(t):r[n]=t,r},f=(e,t)=>{if(Array.isArray(t))return t.reduce((e,t)=>f(e,t),e??[]);if(e==null)return[t];let n=e.findIndex(e=>e.key===t.key),r=[...e];return n===-1?r.push(t):r[n]=t,r},p=`synnax.caseconv.preserveCase`,m=e=>{if(typeof e!=`object`||!e)return!1;if(p in e)return!0;let t=e._zod?.def;return t==null?!1:t.innerType&&m(t.innerType)?!0:t.type===`union`&&Array.isArray(t.options)?t.options.some(m):t.type===`pipe`?m(t.in)||m(t.out):!1},h=e=>{if(e==null)return;let t=e._zod?.def;if(t?.type===`array`&&t.element!=null)return t.element;if(t?.type===`union`&&Array.isArray(t.options))for(let e of t.options){let t=h(e);if(t!=null)return t}},g=e=>{if(e==null)return null;let t=e;if(t.shape!=null)return t.shape;if(typeof t.sourceType==`function`){let e=t.sourceType();if(e?.shape!=null)return e.shape}let n=t._zod?.def;if(n==null)return null;if(n.innerType!=null)return g(n.innerType);if(n.type===`union`&&Array.isArray(n.options))for(let e of n.options){let t=g(e);if(t!=null)return t}return n.type===`pipe`?g(n.in)??g(n.out):null},ee=e=>{if(e.length===0)return e;let t=e.indexOf(`_`)===-1?e:e.replace(/_[a-z]/g,e=>e[1].toUpperCase()),n=t.charCodeAt(0);return n<65||n>90||t.length>1&&t.charCodeAt(1)>=65&&t.charCodeAt(1)<=90?t:String.fromCharCode(n+32)+t.slice(1)},te=e=>{let t=(n,r=ie)=>{if(typeof n==`string`)return e(n);if(Array.isArray(n)){let e=h(r.schema),i={recursive:r.recursive,recursiveInArray:r.recursiveInArray,schema:e};return n.map(e=>t(e,i))}if(!ae(n)||r.schema!=null&&m(r.schema))return n;let i=r.recursive??!0,a=r.recursiveInArray??i,o=r.schema,s={},c=n;if(`toJSON`in c&&typeof c.toJSON==`function`)return t(c.toJSON(),r);let l=g(o),u={recursive:i,recursiveInArray:a,schema:void 0},d=Object.keys(c);for(let n=0;n<d.length;n++){let r=d[n],o=c[r],f=e(r),p=l==null?void 0:l[r]??l[f]??void 0;i&&(ae(o)?oe(o)||(u.schema=p,o=t(o,u)):a&&Array.isArray(o)&&(u.schema=h(p),o=o.map(e=>{if(ae(e)){if(!oe(e))return t(e,u)}else if(Array.isArray(e))return t({key:e},u).key;return e}))),s[f]=o}return s};return t},ne=te(ee),re=te(e=>e.replace(/([a-z0-9])([A-Z])/g,(e,t,n)=>`${t}_${n.toLowerCase()}`)),ie={recursive:!0,recursiveInArray:!0,schema:void 0},ae=e=>typeof e==`object`&&!!e&&!Array.isArray(e),oe=e=>e instanceof Uint8Array||e instanceof Number||e instanceof String,_=e=>typeof e==`object`&&!!e&&!Array.isArray(e),se=e=>{if(typeof e!=`object`||!e||Array.isArray(e))return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null},ce=(e,t)=>{let n=e;for(let e of t){if(typeof n!=`object`||!n)return{present:!1,value:void 0};let t=n;if(!(e in t))return{present:!1,value:void 0};n=t[e]}return{present:!0,value:n}},le=(e,t)=>{let n=Array.isArray(e),r=Array.isArray(t);if(n!==r)return!1;if(n&&r){let n=e,r=t;if(n.length!==r.length)return!1;for(let e=0;e<n.length;e++)if(!le(n[e],r[e]))return!1;return!0}if(e==null||t==null||typeof e!=`object`||typeof t!=`object`)return e===t;if(`equals`in e)return e.equals(t);let i=Object.keys(e),a=Object.keys(t);if(i.length!==a.length)return!1;for(let n of i){let r=e[n],i=t[n];if(typeof r==`object`&&typeof i==`object`){if(!le(r,i))return!1}else if(r!==i)return!1}return!0},ue=(e,t)=>{if(typeof e!=`object`||!e)return e===t;let n=Object.keys(e),r=Object.keys(t);if(r.length>n.length)return!1;for(let n of r){let r=e[n],i=t[n];if(typeof r==`object`&&typeof i==`object`){if(!ue(r,i))return!1}else if(r!==i)return!1}return!0},de=(e,...t)=>{if(t.length===0)return e;let n=t.shift();if(_(e)&&_(n))for(let t in n)try{_(n[t])?(t in e||Object.assign(e,{[t]:{}}),de(e[t],n[t])):Object.assign(e,{[t]:n[t]})}catch(e){throw e instanceof TypeError?TypeError(`.${t}: ${e.message}`,{cause:e}):e}return de(e,...t)},fe=e=>Object.getOwnPropertySymbols(globalThis).includes(e),pe=(e,t)=>{let n=Symbol.for(e);if(!fe(n)){let e=t();Object.defineProperty(globalThis,n,{value:e})}return()=>globalThis[n]},v=u({Canceled:()=>we,NONE:()=>`nil`,NotImplemented:()=>Te,UNKNOWN:()=>b,Unknown:()=>Se,createTyped:()=>y,decode:()=>xe,encode:()=>be,isTyped:()=>ge,payloadZ:()=>Ce,register:()=>ye}),me=`sy_x_error`,he=e=>t=>typeof t==`object`&&t&&`type`in t&&typeof t.type==`string`?t.type.startsWith(e):t instanceof Error?t.message.startsWith(e):typeof t==`string`?t.startsWith(e):!1,y=e=>class t extends Error{static discriminator=me;discriminator=t.discriminator;static TYPE=e;type=t.TYPE;static matches=he(e);matches=t.matches;constructor(e,n){super(e,n),this.name=t.TYPE}static sub(t){return y(`${e}.${t}`)}},ge=e=>{if(typeof e!=`object`||!e)return!1;let t=e;if(t.discriminator!==me)return!1;if(!(`type`in t))throw Error(`X Error is missing its type property: ${JSON.stringify(t)}`);return!0},b=`unknown`,_e=class{providers=[];register(e){this.providers.push(e)}encode(e){if(e==null)return{type:`nil`,data:``};if(ge(e))for(let t of this.providers){let n=t.encode(e);if(n!=null)return n}if(e instanceof Error)return{type:b,data:e.message};if(typeof e==`string`)return{type:b,data:e};try{return{type:b,data:JSON.stringify(e)}}catch{return{type:b,data:`unable to encode error information`}}}decode(e){if(e==null||e.type===`nil`)return null;if(e.type===`unknown`)return new Se(e.data);for(let t of this.providers){let n=t.decode(e);if(n!=null)return n}return new Se(e.data)}},ve=pe(`synnax-error-registry`,()=>new _e),ye=({encode:e,decode:t})=>ve().register({encode:e,decode:t}),be=e=>ve().encode(e),xe=e=>e==null?null:ve().decode(e),Se=class extends y(`unknown`){},Ce=c.z.object({type:c.z.string(),data:c.z.string()}),we=class extends y(`canceled`){},Te=class extends y(`not_implemented`){},Ee=e=>{if(e.length===0)return`<root>`;let t=``;return e.forEach((e,n)=>{typeof e==`number`?t+=`[${e}]`:n===0?t+=String(e):t+=`.${String(e)}`}),t},De=200,Oe=10,ke=8,x=(e,t={})=>{let n=t.maxStringLength??De,r=t.maxArrayLength??Oe,i=t.maxDepth??ke,a=(e,t)=>{if(e===null)return null;if(e===void 0)return`[undefined]`;let o=typeof e;if(o===`string`){let t=e;return t.length>n?`${t.slice(0,n)}…(+${t.length-n} chars)`:t}if(o===`number`||o===`boolean`)return e;if(o===`bigint`)return`${e.toString()}n`;if(o===`symbol`||o===`function`)return`[${o}]`;if(Array.isArray(e)){if(t>=i)return`[Array(${e.length})]`;let n=e.slice(0,r).map(e=>a(e,t+1));return e.length>r&&n.push(`…(+${e.length-r} more)`),n}if(se(e)){if(t>=i)return`[Object]`;let n={};for(let[r,i]of Object.entries(e))n[r]=a(i,t+1);return n}if(e instanceof Date)return e.toISOString();if(e instanceof Error)return`[Error: ${e.message}]`;try{return`[${Object.prototype.toString.call(e)}]`}catch{return`[unknown]`}};return a(e,0)},Ae=(e,t={})=>JSON.stringify(x(e,t),null,2),S=e=>typeof e==`object`&&!!e&&`value`in e,C=class{value;constructor(e){this.value=e}valueOf(){return this.value}toJSON(){return this.value}toString(){return this.value.toString()}},je=e=>typeof e==`object`&&!!e&&`toString`in e,Me=e=>e==null||typeof e!=`object`&&typeof e!=`function`,Ne=`value`,Pe=`zod.parse`,Fe=`✗`,Ie=60,Le={maxStringLength:60,maxArrayLength:3,maxDepth:3},Re=e=>e.slice(0,-1),ze=e=>{switch(e.code){case`invalid_type`:return`expected ${e.expected}`;case`invalid_value`:return`expected one of ${JSON.stringify(e.values)}`;case`unrecognized_keys`:return`unexpected key`;case`too_small`:{let t=e.inclusive===!1?`>`:`>=`;return`${e.origin} too small: expected ${t}${e.minimum}`}case`too_big`:{let t=e.inclusive===!1?`<`:`<=`;return`${e.origin} too large: expected ${t}${e.maximum}`}case`invalid_format`:return`expected ${e.format} format`;case`not_multiple_of`:return`expected multiple of ${e.divisor}`;case`custom`:return e.message||`custom validation failed`;default:return e.message}},Be=(e,t,n)=>{let r=JSON.stringify(x(t,n));return`${ze(e)}, received ${r}`},w=e=>{let t=0;for(let n of e){if(n.path.length>t&&(t=n.path.length),n.code===`invalid_union`&&`errors`in n)for(let e of n.errors){let n=w(e);n>t&&(t=n)}if((n.code===`invalid_key`||n.code===`invalid_element`)&&`issues`in n){let e=w(n.issues);e>t&&(t=e)}}return t},T=(e,t=[])=>{let n=[];for(let r of e){let e=[...t,...r.path];if(r.code===`invalid_union`&&`errors`in r&&r.errors.length>0){let t=r.errors[0],i=w(t);for(let e=1;e<r.errors.length;e++){let n=w(r.errors[e]);n>i&&(t=r.errors[e],i=n)}n.push(...T(t,e));continue}if(r.code===`invalid_element`&&`issues`in r&&`key`in r&&(typeof r.key==`string`||typeof r.key==`number`)){n.push(...T(r.issues,[...e,r.key]));continue}if(r.code===`invalid_key`&&`issues`in r){n.push(...T(r.issues,e));continue}n.push({...r,path:e})}return n},Ve=e=>{let t=[];for(let n of e){if(n.code===`unrecognized_keys`&&`keys`in n&&Array.isArray(n.keys)){for(let e of n.keys)t.push({...n,path:[...n.path,e]});continue}t.push(n)}return t},He=(e,t,n,r)=>{let i=`${n} `,a=`${n+Fe} `,o={...Le,...r};if(Array.isArray(e)){let e=-1;for(let n of t.keys()){let t=Number(n);Number.isInteger(t)&&t>e&&(e=t)}let n=o.maxArrayLength??3;e>=n&&(o={...o,maxArrayLength:e+2})}let s=x(e,o);if(typeof s!=`object`||!s){let e=JSON.stringify(s),n=t.values().next().value;return[`${a}${e}${n?` × ${n.reason}`:``}`]}let c=[],l=Array.isArray(s);c.push(`${n}${l?`[`:`{`}`);let u=[];if(l){let e=s;for(let n=0;n<e.length;n++){let r=t.get(String(n));u.push({content:JSON.stringify(e[n]),mark:r&&!r.missing?r:void 0})}}else{let e=s;for(let n of Object.keys(e)){let r=t.get(n);u.push({content:`"${n}": ${JSON.stringify(e[n])}`,mark:r&&!r.missing?r:void 0})}for(let[e,n]of t.entries())n.missing&&u.push({content:`"${e}": <missing>`,mark:n})}let d=0;return u.forEach((e,t)=>{if(e.mark==null)return;let n=+(t<u.length-1),r=e.content.length+n;r>d&&r<=Ie&&(d=r)}),u.forEach((e,t)=>{let n=t<u.length-1?`,`:``,r=e.content+n;if(e.mark!=null){let t=` `.repeat(Math.max(2,d-r.length+2));c.push(`${a}${r}${t}× ${e.mark.reason}`)}else c.push(`${i}${r}`)}),c.push(n+(l?`]`:`}`)),c},Ue=`__root__`,We=(e,t,n)=>{let r=new Map;for(let t of e){let e=t.path.length===0?Ue:`::${Ee(Re(t.path))}`,n=r.get(e);n==null?r.set(e,[t]):n.push(t)}let i=[];for(let[e,a]of r){if(e===Ue){i.push(a.map(e=>` × ${Be(e,t,n)}`).join(`
2
+ `));continue}let r=Re(a[0].path),{present:o,value:s}=ce(t,r);if(!o){i.push(a.map(e=>` at ${Ee(e.path)}\n × ${Be(e,t,n)}`).join(`
3
+ `));continue}let c=new Map;for(let e of a){let n=String(e.path[e.path.length-1]),r=ce(t,e.path);c.set(n,{reason:ze(e),missing:!r.present})}let l=r.length===0,u=He(s,c,l?` `:` `,n);l?i.push(u.join(`
4
+ `)):i.push([` at ${Ee(r)}`,...u].join(`
5
+ `))}return i.join(`
6
+
7
+ `)},Ge=(e,t)=>{let n=Object.entries(e);return n.every(([,e])=>Me(e))?n.map(([e,t])=>`${e}=${typeof t==`string`?t:String(t)}`).join(`, `):Ae(e,t)},Ke=({issues:e,input:t,label:n,context:r,formatOptions:i})=>{let a=i??{},o=Ve(T(e)),s=[`Failed to parse ${n} (${o.length===1?`1 issue`:`${o.length} issues`})`];return s.push(We(o,t,a)),r!=null&&Object.keys(r).length>0&&s.push(` context: ${Ge(r,a)}`),s.join(`
8
+
9
+ `)},qe=class extends y(Pe){issues;input;label;context;constructor({issues:e,input:t,label:n,context:r,cause:i,formatOptions:a}){super(Ke({issues:e,input:t,label:n,context:r,formatOptions:a}),{cause:i}),this.issues=e,this.input=t,this.label=n,this.context=r}toStatus(){let e={input:x(this.input),issues:this.issues};return this.context!=null&&(e.context=this.context),{message:`Failed to parse ${this.label}`,description:this.message,details:e}}};ye({encode:e=>{if(!qe.matches(e))return null;let t=e,n={label:t.label,context:t.context,issues:t.issues,input:x(t.input)};return{type:Pe,data:JSON.stringify(n)}},decode:e=>{if(e.type!==Pe)return null;let t=JSON.parse(e.data);return new qe({issues:t.issues,input:t.input,label:t.label,context:t.context})}});var Je=(e,t,n={})=>{let r=e.safeParse(t);if(r.success)return r.data;throw new qe({issues:r.error.issues,input:t,label:n.label??Ne,context:n.context,cause:r.error})},Ye=2**12-1,Xe=2**16-1,Ze=2**20-1,Qe=-128,$e=-(2**15),et=2**15-1,tt=-(2n**63n),E=2n**63n-1n,nt=-(2**63),rt=2**63-1,D=e=>(t,n)=>{if(typeof t==`bigint`){if(it(n))return e(t,BigInt(n));let r=e(Number(t),Number(n));return typeof r==`number`?BigInt(Math.round(r)):r}return e(Number(t),Number(n))},O=D((e,t)=>e-t),k=D((e,t)=>e+t),it=e=>typeof e==`bigint`?!0:Number.isInteger(e),A=D((e,t)=>e*t),j=D((e,t)=>e/t),at=c.z.tuple([c.z.number(),c.z.number()]),ot=c.z.enum([`x`,`y`]),st=[`top`,`right`,`bottom`,`left`];c.z.enum(st);var ct=[`left`,`right`],lt=c.z.enum(ct),ut=c.z.enum([`top`,`bottom`]),dt=[`center`],ft=c.z.enum(dt);c.z.enum([`top`,`right`,`bottom`,`left`,`center`]),c.z.enum([`start`,`center`,`end`]),c.z.enum([`first`,`last`]);var pt=c.z.object({clientX:c.z.number(),clientY:c.z.number()}),mt=c.z.object({width:c.z.number(),height:c.z.number()}),ht=c.z.object({signedWidth:c.z.number(),signedHeight:c.z.number()});c.z.object({lower:c.z.number(),upper:c.z.number()}),c.z.enum([`x`,`y`,...st,...dt]),c.z.union([ot,c.z.enum([...st,...dt]),c.z.instanceof(String)]);var M=(e,t,n)=>{let r={};if(typeof t==`object`&&(n=t,t=void 0),n={makeValid:!0,...n},typeof e==`number`||typeof e==`bigint`)t==null?(r.lower=typeof e==`bigint`?0n:0,r.upper=e):(r.lower=e,r.upper=t);else if(Array.isArray(e)){if(e.length!==2)throw Error(`bounds: expected array of length 2`);[r.lower,r.upper]=e}else r.lower=e.lower,r.upper=e.upper;return n?.makeValid?gt(r):r};Object.freeze({lower:0,upper:0}),Object.freeze({lower:-1/0,upper:1/0}),Object.freeze({lower:0,upper:1}),Object.freeze({lower:-1,upper:1});var gt=e=>e.lower>e.upper?{lower:e.upper,upper:e.lower}:e,_t=(e,t)=>{let n=M(e);return t<n.lower?n.lower:t>=n.upper?n.upper-(typeof n.upper==`number`?1:1n):t};c.z.int().min(Qe).max(127),c.z.int().min($e).max(et),c.z.int().min(nt).max(rt);var vt=c.z.int().min(0).max(255);c.z.int().min(0).max(Ye),c.z.int().min(0).max(Xe),c.z.int().min(0).max(Ze);var yt=class{contentType=`application/json`;decoder;encoder;constructor(){this.decoder=new TextDecoder,this.encoder=new TextEncoder}encode(e,t){return this.encoder.encode(this.encodeString(e,t))}decode(e,t){return this.decodeString(this.decoder.decode(e),t)}decodeString(e,t){let n=ne(JSON.parse(e),{schema:t});return t==null?n:Je(t,n)}encodeString(e,t){let n=re((t==null?e:Je(t,e))??{},{schema:t});return JSON.stringify(n,(e,t)=>ArrayBuffer.isView(t)?Array.from(t):typeof t==`bigint`?t.toString():t)}},bt=class{contentType=`text/csv`;encode(e){let t=this.encodeString(e);return new TextEncoder().encode(t)}decode(e,t){let n=new TextDecoder().decode(e);return this.decodeString(n,t)}encodeString(e){if(!Array.isArray(e)||e.length===0||!_(e[0]))throw Error(`Payload must be an array of objects`);let t=Object.keys(e[0]),n=[t.join(`,`)];return e.forEach(e=>{let r=t.map(t=>JSON.stringify(e[t]??``));n.push(r.join(`,`))}),n.join(`
2
10
  `)}decodeString(e,t){let[n,...r]=e.trim().split(`
3
- `).map(e=>e.trim());if(n.length===0)return t==null?{}:t.parse({});let i=n.split(`,`).map(e=>e.trim()),a={};return i.forEach(e=>{a[e]=[]}),r.forEach(e=>{let t=e.split(`,`).map(e=>e.trim());i.forEach((e,n)=>{let r=this.parseValue(t[n]);r!=null&&a[e].push(r)})}),t==null?a:t.parse(a)}parseValue(e){if(e==null||e.length===0)return null;let t=Number(e);return isNaN(t)?e.startsWith(`"`)&&e.endsWith(`"`)?e.slice(1,-1):e:t}},ce=class{contentType=`text/plain`;encode(e){if(typeof e!=`string`)throw Error(`TextCodec.encode payload must be a string`);return new TextEncoder().encode(e)}decode(e,t){let n=new TextDecoder().decode(e);return t==null?n:t.parse(n)}},le=new oe;new se,new ce;var y=e=>typeof e==`object`&&!!e&&`value`in e,b=class{value;constructor(e){this.value=e}valueOf(){return this.value}toJSON(){return this.value}toString(){return this.value.toString()}},ue=e=>typeof e==`object`&&!!e&&`toString`in e,de=(e,t=!1)=>{let n=ue(e)?`stringer`:typeof e,r;switch(n){case`string`:r=(e,t)=>e.localeCompare(t);break;case`stringer`:r=(e,t)=>e.toString().localeCompare(t.toString());break;case`number`:r=(e,t)=>Number(e)-Number(t);break;case`bigint`:r=(e,t)=>BigInt(e)-BigInt(t)>0n?1:-1;break;case`boolean`:r=(e,t)=>Number(e)-Number(t);break;case`undefined`:r=()=>0;break;default:return console.warn(`sortFunc: unknown type ${n}`),()=>-1}return t?fe(r):r},fe=e=>(t,n)=>e(n,t),pe=(e,t=21)=>(n=t)=>{let r=``,i=n|0;for(;i--;)r+=e[Math.random()*e.length|0];return r},me=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`,he=`0123456789${me}`,ge=pe(me,1),_e=pe(he,10),ve=()=>`${ge()}${_e()}`,ye=(e,t)=>n=>n instanceof t||typeof n==`object`&&!!n&&`discriminator`in n&&n.discriminator===e,be=2**12-1,xe=2**16-1,Se=2**20-1,Ce=-128,we=-(2**15),Te=2**15-1,Ee=-(2n**63n),x=2n**63n-1n,De=-(2**63),Oe=2**63-1,S=e=>(t,n)=>{if(typeof t==`bigint`){if(ke(n))return e(t,BigInt(n));let r=e(Number(t),Number(n));return typeof r==`number`?BigInt(Math.round(r)):r}return e(Number(t),Number(n))},C=S((e,t)=>e-t),w=S((e,t)=>e+t),ke=e=>typeof e==`bigint`?!0:Number.isInteger(e),T=S((e,t)=>e*t),E=S((e,t)=>e/t),Ae=c.z.tuple([c.z.number(),c.z.number()]),je=c.z.enum([`x`,`y`]),D=[`top`,`right`,`bottom`,`left`];c.z.enum(D);var Me=[`left`,`right`],Ne=c.z.enum(Me),Pe=c.z.enum([`top`,`bottom`]),O=[`center`],Fe=c.z.enum(O);c.z.enum([`top`,`right`,`bottom`,`left`,`center`]),c.z.enum([`start`,`center`,`end`]),c.z.enum([`first`,`last`]);var Ie=c.z.object({clientX:c.z.number(),clientY:c.z.number()}),Le=c.z.object({width:c.z.number(),height:c.z.number()}),Re=c.z.object({signedWidth:c.z.number(),signedHeight:c.z.number()});c.z.object({lower:c.z.number(),upper:c.z.number()}),c.z.enum([`x`,`y`,...D,...O]),c.z.union([je,c.z.enum([...D,...O]),c.z.instanceof(String)]);var k=(e,t,n)=>{let r={};if(typeof t==`object`&&(n=t,t=void 0),n={makeValid:!0,...n},typeof e==`number`||typeof e==`bigint`)t==null?(r.lower=typeof e==`bigint`?0n:0,r.upper=e):(r.lower=e,r.upper=t);else if(Array.isArray(e)){if(e.length!==2)throw Error(`bounds: expected array of length 2`);[r.lower,r.upper]=e}else r.lower=e.lower,r.upper=e.upper;return n?.makeValid?ze(r):r};Object.freeze({lower:0,upper:0}),Object.freeze({lower:-1/0,upper:1/0}),Object.freeze({lower:0,upper:1}),Object.freeze({lower:-1,upper:1});var ze=e=>e.lower>e.upper?{lower:e.upper,upper:e.lower}:e,Be=(e,t)=>{let n=k(e);return t<n.lower?n.lower:t>=n.upper?n.upper-(typeof n.upper==`number`?1:1n):t};c.z.object({x:Ne.or(Fe),y:Pe.or(Fe)});var Ve=c.z.object({x:Ne,y:Pe}),He=Object.freeze({x:`left`,y:`top`}),Ue=Object.freeze({x:`right`,y:`top`}),We=Object.freeze({x:`left`,y:`bottom`}),Ge=Object.freeze({x:`right`,y:`bottom`}),Ke=Object.freeze({x:`center`,y:`center`}),qe=Object.freeze({x:`center`,y:`top`}),Je=Object.freeze({x:`center`,y:`bottom`}),Ye=Object.freeze({x:`right`,y:`center`}),Xe=Object.freeze({x:`left`,y:`center`});Object.freeze([Xe,Ye,qe,Je,He,Ue,We,Ge,Ke]);var Ze=(e,t)=>e.x===t.x&&e.y===t.y,Qe=e=>[e.x,e.y];c.z.enum([`top`,`right`,`bottom`,`left`]);var A=c.z.object({x:c.z.number(),y:c.z.number()}),$e=c.z.union([c.z.number(),A,Ae,Le,Re,Ie]),j=(e,t)=>{if(typeof e==`string`){if(t===void 0)throw Error(`The y coordinate must be given.`);return e===`x`?{x:t,y:0}:{x:0,y:t}}return typeof e==`number`?{x:e,y:t??e}:Array.isArray(e)?{x:e[0],y:e[1]}:`signedWidth`in e?{x:e.signedWidth,y:e.signedHeight}:`clientX`in e?{x:e.clientX,y:e.clientY}:`width`in e?{x:e.width,y:e.height}:{x:e.x,y:e.y}},M=Object.freeze({x:0,y:0});Object.freeze({x:1,y:1}),Object.freeze({x:1/0,y:1/0}),Object.freeze({x:NaN,y:NaN});var et=(e,t)=>{let n=j(e);return{x:n.x+t,y:n.y}},tt=(e,t)=>{let n=j(e);return{x:n.x,y:n.y+t}},nt=(e,t,n,...r)=>{if(typeof t==`string`){if(typeof n!=`number`)throw Error(`The value must be a number.`);return t===`x`?et(e,n):tt(e,n)}if(typeof t==`object`&&`x`in t&&typeof t.x==`string`){let r=j(n),i=j(e);return t.x===`left`?r.x=-r.x:t.x===`center`&&(r.x=0),t.y===`top`?r.y=-r.y:t.y===`center`&&(r.y=0),{x:i.x+r.x,y:i.y+r.y}}return[e,t,n??M,...r].reduce((e,t)=>{let n=j(t);return{x:e.x+n.x,y:e.y+n.y}},M)},N=c.z.union([c.z.number(),c.z.string()]);c.z.object({top:N,left:N,width:N,height:N}),c.z.object({left:c.z.number(),top:c.z.number(),right:c.z.number(),bottom:c.z.number()}),c.z.object({one:A,two:A,root:Ve});var P=(e,t,n=0,r=0,i)=>{let a={one:{...M},two:{...M},root:i??He};if(typeof e==`number`){if(typeof t!=`number`)throw Error(`Box constructor called with invalid arguments`);return a.one={x:e,y:t},a.two={x:a.one.x+n,y:a.one.y+r},a}return`one`in e&&`two`in e&&`root`in e?{...e,root:i??e.root}:(`getBoundingClientRect`in e&&(e=e.getBoundingClientRect()),`left`in e?(a.one={x:e.left,y:e.top},a.two={x:e.right,y:e.bottom},a):(a.one=e,t==null?a.two={x:a.one.x+n,y:a.one.y+r}:typeof t==`number`?a.two={x:a.one.x+t,y:a.one.y+n}:`width`in t?a.two={x:a.one.x+t.width,y:a.one.y+t.height}:`signedWidth`in t?a.two={x:a.one.x+t.signedWidth,y:a.one.y+t.signedHeight}:a.two=t,a))},rt=(e,t)=>{let n=P(e);return{x:t.x===`center`?ct(n).x:it(n,t.x),y:t.y===`center`?ct(n).y:it(n,t.y)}},it=(e,t)=>{let n=P(e),r=Qe(n.root).includes(t)?Math.min:Math.max;return Me.includes(t)?r(n.one.x,n.two.x):r(n.one.y,n.two.y)},at=e=>{let t=P(e);return t.two.x-t.one.x},ot=e=>{let t=P(e);return t.two.y-t.one.y},st=e=>rt(e,He),ct=e=>nt(st(e),{x:at(e)/2,y:ot(e)/2}),lt=e=>{let t=P(e);return{lower:t.one.x,upper:t.two.x}},ut=e=>{let t=P(e);return{lower:t.one.y,upper:t.two.y}},dt=e=>typeof e!=`object`||!e?!1:`one`in e&&`two`in e&&`root`in e;c.z.union([Le,Re,A,Ae]);var ft=(e,t,n)=>t!==void 0&&e<t?t:n!==void 0&&e>n?n:e;c.z.object({offset:$e,scale:$e}),c.z.object({offset:c.z.number(),scale:c.z.number()});var pt=e=>(t,n,r,i)=>n===`dimension`?[t,r]:[t,i?r-e:r+e],mt=e=>(t,n,r,i)=>[t,i?r/e:r*e],ht=e=>(t,n,r)=>{if(t===null)return[e,r];let{lower:i,upper:a}=t,{lower:o,upper:s}=e,c=a-i,l=s-o;return n===`dimension`?[e,l/c*r]:[e,(r-i)*(l/c)+o]},gt=e=>(t,n,r)=>[e,r],_t=()=>(e,t,n)=>{if(e===null)throw Error(`cannot invert without bounds`);if(t===`dimension`)return[e,n];let{lower:r,upper:i}=e;return[e,i-(n-r)]},vt=e=>(t,n,r)=>{let{lower:i,upper:a}=e;return r=ft(r,i,a),[t,r]},yt=class e{ops=[];currBounds=null;currType=null;reversed=!1;constructor(){this.ops=[]}static translate(t){return new e().translate(t)}static magnify(t){return new e().magnify(t)}static scale(t,n){return new e().scale(t,n)}translate(e){let t=this.new(),n=pt(e);return n.type=`translate`,t.ops.push(n),t}magnify(e){let t=this.new(),n=mt(e);return n.type=`magnify`,t.ops.push(n),t}scale(e,t){let n=k(e,t),r=this.new(),i=ht(n);return i.type=`scale`,r.ops.push(i),r}clamp(e,t){let n=k(e,t),r=this.new(),i=vt(n);return i.type=`clamp`,r.ops.push(i),r}reBound(e,t){let n=k(e,t),r=this.new(),i=gt(n);return i.type=`re-bound`,r.ops.push(i),r}invert(){let e=_t();e.type=`invert`;let t=this.new();return t.ops.push(e),t}pos(e){return this.exec(`position`,e)}dim(e){return this.exec(`dimension`,e)}new(){let t=new e;return t.ops=this.ops.slice(),t.reversed=this.reversed,t}exec(e,t){return this.currBounds=null,this.ops.reduce(([t,n],r)=>r(t,e,n,this.reversed),[null,t])[1]}reverse(){let e=this.new();e.ops.reverse();let t=[];return e.ops.forEach((n,r)=>{if(n.type===`scale`||t.some(([e,t])=>r>=e&&r<=t))return;let i=e.ops.findIndex((e,t)=>e.type===`scale`&&t>r);i!==-1&&t.push([r,i])}),t.forEach(([t,n])=>{let r=e.ops.slice(t,n);r.unshift(e.ops[n]),e.ops.splice(t,n-t+1,...r)}),e.reversed=!e.reversed,e}get transform(){return{scale:this.dim(1),offset:this.pos(0)}}static IDENTITY=new e};(class e{x;y;currRoot;constructor(e=new yt,t=new yt,n=null){this.x=e,this.y=t,this.currRoot=n}static translate(t,n){return new e().translate(t,n)}static translateX(t){return new e().translateX(t)}static translateY(t){return new e().translateY(t)}static clamp(t){return new e().clamp(t)}static magnify(t){return new e().magnify(t)}static scale(t){return new e().scale(t)}static reBound(t){return new e().reBound(t)}translate(e,t){let n=j(e,t),r=this.copy();return r.x=this.x.translate(n.x),r.y=this.y.translate(n.y),r}translateX(e){let t=this.copy();return t.x=this.x.translate(e),t}translateY(e){let t=this.copy();return t.y=this.y.translate(e),t}magnify(e){let t=this.copy();return t.x=this.x.magnify(e.x),t.y=this.y.magnify(e.y),t}scale(e){let t=this.copy();if(dt(e)){let n=this.currRoot;return t.currRoot=e.root,n!=null&&!Ze(n,e.root)&&(n.x!==e.root.x&&(t.x=t.x.invert()),n.y!==e.root.y&&(t.y=t.y.invert())),t.x=t.x.scale(lt(e)),t.y=t.y.scale(ut(e)),t}return t.x=t.x.scale(e.width),t.y=t.y.scale(e.height),t}reBound(e){let t=this.copy();return t.x=this.x.reBound(lt(e)),t.y=this.y.reBound(ut(e)),t}clamp(e){let t=this.copy();return t.x=this.x.clamp(lt(e)),t.y=this.y.clamp(ut(e)),t}copy(){let t=new e;return t.currRoot=this.currRoot,t.x=this.x,t.y=this.y,t}reverse(){let e=this.copy();return e.x=this.x.reverse(),e.y=this.y.reverse(),e}pos(e){return{x:this.x.pos(e.x),y:this.y.pos(e.y)}}dim(e){return{x:this.x.dim(e.x),y:this.y.dim(e.y)}}box(e){return P(this.pos(e.one),this.pos(e.two),0,0,this.currRoot??e.root)}get transform(){return{scale:this.dim({x:1,y:1}),offset:this.pos({x:0,y:0})}}static IDENTITY=new e}),A.extend({root:Ve,units:c.default.object({x:c.default.enum([`px`,`decimal`]),y:c.default.enum([`px`,`decimal`])})}).partial({root:!0,units:!0});var bt=c.z.enum([`static`,`dynamic`]),xt=365,F=30,St=c.z.union([c.z.tuple([c.z.int()]),c.z.tuple([c.z.int(),c.z.int().min(1).max(12)]),c.z.tuple([c.z.int(),c.z.int().min(1).max(12),c.z.int().min(1).max(31)])]),Ct=(e,t)=>{let n=new I(t);if(![L.DAY,L.HOUR,L.MINUTE,L.SECOND,L.MILLISECOND,L.MICROSECOND,L.NANOSECOND].some(e=>e.equals(n)))throw Error(`Invalid argument for remainder. Must be an even TimeSpan or Timestamp`);let r=e.valueOf()%n.valueOf();return e instanceof I?new I(r):new L(r)},I=class e extends b{constructor(t,n=`UTC`){if(t==null)super(e.now().valueOf());else if(t instanceof Date)super(BigInt(t.getTime())*e.MILLISECOND.valueOf());else if(typeof t==`string`)super(e.parseDateTimeString(t,n).valueOf());else if(Array.isArray(t))super(e.parseDate(t));else{let r=0n;t instanceof Number&&(t=t.valueOf()),n===`local`&&(r=e.utcOffset.valueOf()),typeof t==`number`&&(isFinite(t)?t=t===Oe?x:Math.trunc(t):(isNaN(t)&&(t=0),t=t===1/0?e.MAX:e.MIN)),y(t)&&(t=t.value),super(BigInt(t.valueOf())+r)}}static parseDate([t=1970,n=1,r=1]){let i=new Date(t,n-1,r,0,0,0,0);return new e(BigInt(i.getTime())*e.MILLISECOND.valueOf()).truncate(e.DAY).valueOf()}valueOf(){return this.value}static parseTimeString(t,n=`UTC`){let[r,i,a]=t.split(`:`),o=`00`,s=`00`;a!=null&&([o,s]=a.split(`.`));let c=e.hours(parseInt(r??`00`,10)).add(e.minutes(parseInt(i??`00`,10))).add(e.seconds(parseInt(o??`00`,10))).add(e.milliseconds(parseInt(s??`00`,10)));return n===`local`&&(c=c.add(e.utcOffset)),c.valueOf()}static parseDateTimeString(t,n=`UTC`){if(!t.includes(`/`)&&!t.includes(`-`))return e.parseTimeString(t,n);if(t.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,3})?$/)!=null){let r=t,i=0;if(t.includes(`.`)){let e=t.split(`.`);r=e[0];let n=e[1]||`0`;i=parseInt(n.padEnd(3,`0`).slice(0,3),10)}let a=n===`local`?new Date(r.replace(`T`,` `)):new Date(`${r}Z`);return BigInt(a.getTime())*e.MILLISECOND.valueOf()+BigInt(i)*e.MILLISECOND.valueOf()}let r=new Date(t);return t.includes(`:`)||r.setUTCHours(0,0,0,0),new e(BigInt(r.getTime())*e.MILLISECOND.valueOf(),n).valueOf()}toISOString(t=`UTC`){if(t===`UTC`)return this.date().toISOString();let n=this.date(),r=new L(BigInt(n.getTimezoneOffset())*e.MINUTE.valueOf());return this.sub(r).date().toISOString()}timeString(e=!1,t=`UTC`){let n=this.toISOString(t);return e?n.slice(11,23):n.slice(11,19)}dateString(){let e=this.date();return`${e.toLocaleString(`default`,{month:`short`})} ${e.toLocaleString(`default`,{day:`numeric`})}`}static get utcOffset(){return new L(BigInt(new Date().getTimezoneOffset())*e.MINUTE.valueOf())}static since(t){return new e().span(t)}date(){return new Date(this.milliseconds)}equals(t){return this.valueOf()===new e(t).valueOf()}span(e){return this.range(e).span}range(e){return new B(this,e).makeValid()}spanRange(e){return this.range(this.add(e)).makeValid()}get isZero(){return this.valueOf()===0n}after(t){return this.valueOf()>new e(t).valueOf()}afterEq(t){return this.valueOf()>=new e(t).valueOf()}before(t){return this.valueOf()<new e(t).valueOf()}beforeEq(t){return this.valueOf()<=new e(t).valueOf()}add(t){return new e(w(this.valueOf(),new L(t).valueOf()))}sub(t){return new e(C(this.valueOf(),new L(t).valueOf()))}get hours(){return Number(this.valueOf())/Number(L.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(L.MINUTE.valueOf())}get days(){return Number(this.valueOf())/Number(L.DAY.valueOf())}get seconds(){return Number(this.valueOf())/Number(L.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(e.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(e.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get year(){return this.date().getUTCFullYear()}get localYear(){return this.date().getFullYear()}setYear(t){let n=this.date();return n.setUTCFullYear(t),new e(n)}setLocalYear(t){let n=this.date();return n.setFullYear(t),new e(n)}get month(){return this.date().getUTCMonth()}get localMonth(){return this.date().getMonth()}setMonth(t){let n=this.date();return n.setUTCMonth(t),new e(n)}setLocalMonth(t){let n=this.date();return n.setMonth(t),new e(n)}get day(){return this.date().getUTCDate()}get localDay(){return this.date().getDate()}setDay(t){let n=this.date();return n.setUTCDate(t),new e(n)}setLocalDay(t){let n=this.date();return n.setDate(t),new e(n)}get hour(){return this.date().getUTCHours()}get localHour(){return this.date().getHours()}setLocalHour(t){let n=this.date();return n.setHours(t),new e(n)}setHour(t){let n=this.date();return n.setUTCHours(t),new e(n)}get minute(){return this.date().getUTCMinutes()}get localMinute(){return this.date().getMinutes()}setMinute(t){let n=this.date();return n.setUTCMinutes(t),new e(n)}setLocalMinute(t){let n=this.date();return n.setMinutes(t),new e(n)}get second(){return this.date().getUTCSeconds()}get localSecond(){return this.date().getSeconds()}setSecond(t){let n=this.date();return n.setUTCSeconds(t),new e(n)}setLocalSecond(t){let n=this.date();return n.setSeconds(t),new e(n)}get millisecond(){return this.date().getUTCMilliseconds()}get localMillisecond(){return this.date().getMilliseconds()}setMillisecond(t){let n=this.date();return n.setUTCMilliseconds(t),new e(n)}setLocalMillisecond(t){let n=this.date();return n.setMilliseconds(t),new e(n)}toString(e=`ISO`,t=`UTC`){switch(e){case`ISODate`:return this.toISOString(t).slice(0,10);case`ISOTime`:return this.toISOString(t).slice(11,23);case`time`:return this.timeString(!1,t);case`preciseTime`:return this.timeString(!0,t);case`date`:return this.dateString();case`preciseDate`:return`${this.dateString()} ${this.timeString(!0,t)}`;case`dateTime`:return`${this.dateString()} ${this.timeString(!1,t)}`;default:return this.toISOString(t)}}remainder(e){return Ct(this,e)}get isToday(){return this.truncate(L.DAY).equals(e.now().truncate(L.DAY))}truncate(e){return this.sub(this.remainder(e))}formatBySpan(e){return e.greaterThanOrEqual(L.days(30))?`shortDate`:e.greaterThanOrEqual(L.DAY)?`dateTime`:e.greaterThanOrEqual(L.HOUR)?`time`:e.greaterThanOrEqual(L.SECOND)?`preciseTime`:`ISOTime`}static now(){return new e(new Date)}static max(...t){let n=e.MIN;for(let r of t){let t=new e(r);t.after(n)&&(n=t)}return n}static min(...t){let n=e.MAX;for(let r of t){let t=new e(r);t.before(n)&&(n=t)}return n}static nanoseconds(t,n=`UTC`){return new e(t,n)}static NANOSECOND=e.nanoseconds(1);static microseconds(t,n=`UTC`){return e.nanoseconds(t*1e3,n)}static MICROSECOND=e.microseconds(1);static milliseconds(t,n=`UTC`){return e.microseconds(t*1e3,n)}static MILLISECOND=e.milliseconds(1);static seconds(t,n=`UTC`){return e.milliseconds(t*1e3,n)}static SECOND=e.seconds(1);static minutes(t,n=`UTC`){return e.seconds(t*60,n)}static MINUTE=e.minutes(1);static hours(t,n=`UTC`){return e.minutes(t*60,n)}static HOUR=e.hours(1);static days(t,n=`UTC`){return e.hours(t*24,n)}static DAY=e.days(1);static MAX=new e(x);static MIN=new e(0);static ZERO=new e(0);static z=c.z.union([c.z.instanceof(e),c.z.object({value:c.z.bigint()}).transform(t=>new e(t.value)),c.z.string().transform(t=>new e(BigInt(t))),c.z.number().transform(t=>new e(t)),c.z.bigint().transform(t=>new e(t)),c.z.date().transform(t=>new e(t)),c.z.custom(e=>e instanceof L).transform(t=>new e(t)),St.transform(t=>new e(t))]);static sort(e,t){return Number(e.valueOf()-t.valueOf())}},L=class e extends b{constructor(e){typeof e==`number`&&(e=Math.trunc(e.valueOf())),y(e)&&(e=e.value),super(BigInt(e.valueOf()))}static fromSeconds(t){return t instanceof e?t:t instanceof R?t.period:t instanceof I?new e(t):(y(t)&&(t=t.value),[`number`,`bigint`].includes(typeof t)?e.seconds(t):new e(t))}static fromMilliseconds(t){return t instanceof e?t:t instanceof R?t.period:t instanceof I?new e(t):(y(t)&&(t=t.value),[`number`,`bigint`].includes(typeof t)?e.milliseconds(t):new e(t))}valueOf(){return this.value}lessThan(t){return this.valueOf()<new e(t).valueOf()}greaterThan(t){return this.valueOf()>new e(t).valueOf()}lessThanOrEqual(t){return this.valueOf()<=new e(t).valueOf()}greaterThanOrEqual(t){return this.valueOf()>=new e(t).valueOf()}remainder(e){return Ct(this,e)}truncate(t){return new e(BigInt(Math.trunc(Number(this.valueOf()/t.valueOf())))*t.valueOf())}toString(t=`full`){if(t===`semantic`)return this.toSemanticString();let n=this.truncate(e.DAY),r=this.truncate(e.HOUR),i=this.truncate(e.MINUTE),a=this.truncate(e.SECOND),o=this.truncate(e.MILLISECOND),s=this.truncate(e.MICROSECOND),c=this.truncate(e.NANOSECOND),l=n,u=r.sub(n),d=i.sub(r),f=a.sub(i),p=o.sub(a),m=s.sub(o),h=c.sub(s),g=``;return l.isZero||(g+=`${l.days}d `),u.isZero||(g+=`${u.hours}h `),d.isZero||(g+=`${d.minutes}m `),f.isZero||(g+=`${f.seconds}s `),p.isZero||(g+=`${p.milliseconds}ms `),m.isZero||(g+=`${m.microseconds}µs `),h.isZero||(g+=`${h.nanoseconds}ns`),g.trim()}toSemanticString(){let t=new e(this.valueOf()<0n?-this.valueOf():this.valueOf()),n=this.valueOf()<0n;if(t.valueOf()===0n)return`0s`;if(t.lessThan(e.SECOND))return`< 1s`;let r=t.days,i=t.hours,a=t.minutes,o=t.seconds,s=Math.floor(r/xt),c=Math.floor(r/F),l=Math.floor(r/7),u=Math.floor(r),d=Math.floor(i),f=Math.floor(a),p=Math.floor(o),m=n?`-`:``;if(s>=1){let e=`${s}y`;if(s<2){let t=Math.floor(r%xt/F);t>0&&(e+=` ${t}mo`)}return m+e}if(l>=1&&r<F&&r%7==0){let e=`${l}w`,t=Math.floor(r%7),n=Math.floor(i-l*7*24);return l<2&&(t>0?e+=` ${t}d`:n>0&&n<24&&(e+=` ${n}h`)),m+e}if(c>=1){let e=`${c}mo`;if(c<3){let t=Math.floor(r%F);t>0&&(e+=` ${t}d`)}return m+e}if(l>=1){let e=`${l}w`,t=Math.floor(r%7),n=Math.floor(i-l*7*24);return l<2&&(t>0?e+=` ${t}d`:n>0&&n<24&&(e+=` ${n}h`)),m+e}if(u>=1){let e=`${u}d`,t=Math.floor(i-u*24);return u<2&&t>0&&(e+=` ${t}h`),m+e}if(d>=1){let e=`${d}h`;if(d<3){let t=Math.floor(a-d*60);t>0&&(e+=` ${t}m`)}return m+e}if(f>=1){let e=`${f}m`;if(f<5){let t=Math.floor(o-f*60);t>0&&(e+=` ${t}s`)}return m+e}return`${m}${p}s`}mult(t){return new e(T(this.valueOf(),t))}div(t){return new e(E(this.valueOf(),t))}get days(){return Number(this.valueOf())/Number(e.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(e.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(e.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(e.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(e.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(e.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get isZero(){return this.valueOf()===0n}equals(t){return this.valueOf()===new e(t).valueOf()}add(t){return new e(this.valueOf()+new e(t).valueOf())}sub(t){return new e(this.valueOf()-new e(t).valueOf())}static nanoseconds(t=1){return new e(t)}static NANOSECOND=e.nanoseconds(1);static microseconds(t=1){return e.nanoseconds(T(t,1e3))}static MICROSECOND=e.microseconds(1);static milliseconds(t=1){return e.microseconds(T(t,1e3))}static MILLISECOND=e.milliseconds(1);static seconds(t=1){return e.milliseconds(T(t,1e3))}static SECOND=e.seconds(1);static minutes(t=1){return e.seconds(T(t,60))}static MINUTE=e.minutes(1);static hours(t){return e.minutes(T(t,60))}static HOUR=e.hours(1);static days(t){return e.hours(T(t,24))}static DAY=e.days(1);static MAX=new e(x);static MIN=new e(0);static ZERO=new e(0);static z=c.z.union([c.z.object({value:c.z.bigint()}).transform(t=>new e(t.value)),c.z.string().transform(t=>new e(BigInt(t))),c.z.number().transform(t=>new e(t)),c.z.bigint().transform(t=>new e(t)),c.z.instanceof(e),c.z.instanceof(I).transform(t=>new e(t)),c.z.custom(e=>e instanceof R).transform(t=>new e(t))])},R=class e extends b{constructor(e){y(e)&&(e=e.value),super(e.valueOf())}toString(){return`${this.valueOf()} Hz`}equals(t){return this.valueOf()===new e(t).valueOf()}get period(){return L.seconds(1/this.valueOf())}sampleCount(e){return new L(e).seconds*this.valueOf()}byteCount(e,t){return this.sampleCount(e)*new z(t).valueOf()}span(e){return L.seconds(e/this.valueOf())}byteSpan(e,t){return this.span(e.valueOf()/new z(t).valueOf())}add(t){return new e(w(this.valueOf(),new e(t).valueOf()))}sub(t){return new e(C(this.valueOf(),new e(t).valueOf()))}mult(t){return new e(T(this.valueOf(),t))}div(t){return new e(E(this.valueOf(),t))}static hz(t){return new e(t)}static khz(t){return e.hz(t*1e3)}static z=c.z.union([c.z.number().transform(t=>new e(t)),c.z.instanceof(e)])},z=class e extends b{constructor(e){y(e)&&(e=e.value),super(e.valueOf())}length(e){return e.valueOf()/this.valueOf()}size(e){return new H(e*this.valueOf())}add(t){return new e(w(this.valueOf(),new e(t).valueOf()))}sub(t){return new e(C(this.valueOf(),new e(t).valueOf()))}mult(t){return new e(T(this.valueOf(),t))}div(t){return new e(E(this.valueOf(),t))}static UNKNOWN=new e(0);static BIT128=new e(16);static BIT64=new e(8);static BIT32=new e(4);static BIT16=new e(2);static BIT8=new e(1);static z=c.z.union([c.z.number().transform(t=>new e(t)),c.z.instanceof(e)])},B=class e{start;end;constructor(e,t){typeof e==`object`&&`start`in e?(this.start=new I(e.start),this.end=new I(e.end)):(this.start=new I(e),this.end=new I(t))}get span(){return new L(this.end.valueOf()-this.start.valueOf())}get isValid(){return this.start.valueOf()<=this.end.valueOf()}makeValid(){return this.isValid?this:this.swap()}get isZero(){return this.start.isZero&&this.end.isZero}get numeric(){return{start:Number(this.start.valueOf()),end:Number(this.end.valueOf())}}swap(){return new e(this.end,this.start)}get numericBounds(){return{lower:Number(this.start.valueOf()),upper:Number(this.end.valueOf())}}equals(e,t=L.ZERO){if(t.isZero)return this.start.equals(e.start)&&this.end.equals(e.end);let n=this.start.sub(e.start).valueOf(),r=this.end.sub(e.end).valueOf();return n<0&&(n=-n),r<0&&(r=-r),n<=t.valueOf()&&r<=t.valueOf()}toString(){return`${this.start.toString()} - ${this.end.toString()}`}toPrettyString(){return`${this.start.toString(`preciseDate`)} - ${this.span.toString()}`}overlapsWith(e,t=L.ZERO){e=e.makeValid();let n=this.makeValid();if(this.equals(e))return!0;if(e.end.equals(n.start)||n.end.equals(e.start))return!1;let r=I.max(n.start,e.start),i=I.min(n.end,e.end);return i.before(r)?!1:new L(i.sub(r)).greaterThanOrEqual(t)}contains(t){return t instanceof e?this.contains(t.start)&&this.contains(t.end):this.start.beforeEq(t)&&this.end.after(t)}boundBy(t){let n=new e(this.start,this.end);return t.start.after(this.start)&&(n.start=t.start),t.start.after(this.end)&&(n.end=t.start),t.end.before(this.end)&&(n.end=t.end),t.end.before(this.start)&&(n.start=t.end),n}static max(...t){return new e(I.min(...t.map(e=>e.start)),I.max(...t.map(e=>e.end)))}static MAX=new e(I.MIN,I.MAX);static ZERO=new e(I.ZERO,I.ZERO);static z=c.z.union([c.z.object({start:I.z,end:I.z}).transform(t=>new e(t.start,t.end)),c.z.instanceof(e)]);static boundedZ=e.z.refine(({isValid:e})=>e,{message:`Time range start time must be before or equal to time range end time`}).refine(({end:e})=>e.valueOf()<=x,{message:`Time range end time must be less than or equal to the maximum value of an int64`}).refine(({start:e})=>e.valueOf()>=Ee,{message:`Time range start time must be greater than or equal to the minimum value of an int64`});static sort(e,t){return I.sort(e.start,t.start)||I.sort(e.end,t.end)}static merge(...t){return e.max(...t.map(t=>new e(t).makeValid()))}},V=class e extends b{constructor(t){if(y(t)&&(t=t.value),t instanceof e||typeof t==`string`||typeof t.valueOf()==`string`)super(t.valueOf());else{let n=e.ARRAY_CONSTRUCTOR_DATA_TYPES.get(t.constructor.name);if(n==null)throw Error(`unable to find data type for ${t.toString()}`);super(n.valueOf())}}get Array(){let t=e.ARRAY_CONSTRUCTORS.get(this.toString());if(t==null)throw Error(`unable to find array constructor for ${this.valueOf()}`);return t}equals(e){return this.valueOf()===e.valueOf()}matches(...e){return e.some(e=>this.equals(e))}toString(t=!1){return t?e.SHORT_STRINGS.get(this.valueOf())??this.valueOf():this.valueOf()}get isVariable(){return this.equals(e.JSON)||this.equals(e.STRING)||this.equals(e.BYTES)}get isNumeric(){return!this.isVariable&&!this.equals(e.UUID)}get isInteger(){let e=this.toString();return e.startsWith(`int`)||e.startsWith(`uint`)}get isFloat(){return this.toString().startsWith(`float`)}get density(){let t=e.DENSITIES.get(this.toString());if(t==null)throw Error(`unable to find density for ${this.valueOf()}`);return t}get isUnsignedInteger(){return this.equals(e.UINT8)||this.equals(e.UINT16)||this.equals(e.UINT32)||this.equals(e.UINT64)}get isSignedInteger(){return this.equals(e.INT8)||this.equals(e.INT16)||this.equals(e.INT32)||this.equals(e.INT64)}canSafelyCastTo(t){return this.equals(t)?!0:!this.isNumeric||!t.isNumeric||this.isVariable||t.isVariable||this.isUnsignedInteger&&t.isSignedInteger?!1:this.isFloat?t.isFloat&&this.density.valueOf()<=t.density.valueOf():this.equals(e.INT32)&&t.equals(e.FLOAT64)||this.equals(e.INT8)&&t.equals(e.FLOAT32)?!0:this.isInteger&&t.isInteger?this.density.valueOf()<=t.density.valueOf()&&this.isUnsignedInteger===t.isUnsignedInteger:!1}canCastTo(e){return this.isNumeric&&e.isNumeric?!0:this.equals(e)}checkArray(e){return e.constructor===this.Array}get usesBigInt(){return e.BIG_INT_TYPES.some(e=>e.equals(this))}static UNKNOWN=new e(`unknown`);static FLOAT64=new e(`float64`);static FLOAT32=new e(`float32`);static INT64=new e(`int64`);static INT32=new e(`int32`);static INT16=new e(`int16`);static INT8=new e(`int8`);static UINT64=new e(`uint64`);static UINT32=new e(`uint32`);static UINT16=new e(`uint16`);static UINT8=new e(`uint8`);static TIMESTAMP=new e(`timestamp`);static UUID=new e(`uuid`);static STRING=new e(`string`);static JSON=new e(`json`);static BYTES=new e(`bytes`);static ARRAY_CONSTRUCTORS=new Map([[e.UINT8.toString(),Uint8Array],[e.UINT16.toString(),Uint16Array],[e.UINT32.toString(),Uint32Array],[e.UINT64.toString(),BigUint64Array],[e.FLOAT32.toString(),Float32Array],[e.FLOAT64.toString(),Float64Array],[e.INT8.toString(),Int8Array],[e.INT16.toString(),Int16Array],[e.INT32.toString(),Int32Array],[e.INT64.toString(),BigInt64Array],[e.TIMESTAMP.toString(),BigInt64Array],[e.STRING.toString(),Uint8Array],[e.JSON.toString(),Uint8Array],[e.UUID.toString(),Uint8Array],[e.BYTES.toString(),Uint8Array]]);static ARRAY_CONSTRUCTOR_DATA_TYPES=new Map([[Uint8Array.name,e.UINT8],[Uint16Array.name,e.UINT16],[Uint32Array.name,e.UINT32],[BigUint64Array.name,e.UINT64],[Float32Array.name,e.FLOAT32],[Float64Array.name,e.FLOAT64],[Int8Array.name,e.INT8],[Int16Array.name,e.INT16],[Int32Array.name,e.INT32],[BigInt64Array.name,e.INT64]]);static DENSITIES=new Map([[e.UINT8.toString(),z.BIT8],[e.UINT16.toString(),z.BIT16],[e.UINT32.toString(),z.BIT32],[e.UINT64.toString(),z.BIT64],[e.FLOAT32.toString(),z.BIT32],[e.FLOAT64.toString(),z.BIT64],[e.INT8.toString(),z.BIT8],[e.INT16.toString(),z.BIT16],[e.INT32.toString(),z.BIT32],[e.INT64.toString(),z.BIT64],[e.TIMESTAMP.toString(),z.BIT64],[e.STRING.toString(),z.UNKNOWN],[e.JSON.toString(),z.UNKNOWN],[e.UUID.toString(),z.BIT128],[e.BYTES.toString(),z.UNKNOWN]]);static ALL=[e.UNKNOWN,e.UINT8,e.UINT16,e.UINT32,e.UINT64,e.INT8,e.INT16,e.INT32,e.INT64,e.FLOAT32,e.FLOAT64,e.TIMESTAMP,e.UUID,e.STRING,e.JSON,e.BYTES];static SHORT_STRINGS=new Map([[e.UINT8.toString(),`u8`],[e.UINT16.toString(),`u16`],[e.UINT32.toString(),`u32`],[e.UINT64.toString(),`u64`],[e.INT8.toString(),`i8`],[e.INT16.toString(),`i16`],[e.INT32.toString(),`i32`],[e.INT64.toString(),`i64`],[e.FLOAT32.toString(),`f32`],[e.FLOAT64.toString(),`f64`],[e.TIMESTAMP.toString(),`ts`],[e.UUID.toString(),`uuid`],[e.STRING.toString(),`str`],[e.JSON.toString(),`json`],[e.BYTES.toString(),`bytes`]]);static BIG_INT_TYPES=[e.INT64,e.UINT64,e.TIMESTAMP];static z=c.z.union([c.z.string().transform(t=>new e(t)),c.z.instanceof(e)])},H=class e extends b{constructor(e){y(e)&&(e=e.value),super(e.valueOf())}largerThan(e){return y(e)&&(e=e.value),this.valueOf()>e.valueOf()}smallerThan(e){return y(e)&&(e=e.value),this.valueOf()<e.valueOf()}add(t){return y(t)&&(t=t.value),new e(w(this.valueOf(),t.valueOf()))}sub(t){return y(t)&&(t=t.value),new e(C(this.valueOf(),t.valueOf()))}mult(t){return new e(T(this.valueOf(),t))}div(t){return new e(E(this.valueOf(),t))}truncate(t){return new e(Math.trunc(this.valueOf()/new e(t).valueOf())*new e(t).valueOf())}remainder(t){return e.bytes(this.valueOf()%new e(t).valueOf())}get gigabytes(){return this.valueOf()/e.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/e.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/e.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/e.TERABYTE.valueOf()}toString(){let t=this.truncate(e.TERABYTE),n=this.truncate(e.GIGABYTE),r=this.truncate(e.MEGABYTE),i=this.truncate(e.KILOBYTE),a=this.truncate(e.BYTE),o=t,s=n.sub(t),c=r.sub(n),l=i.sub(r),u=a.sub(i),d=``;return o.isZero||(d+=`${o.terabytes}TB `),s.isZero||(d+=`${s.gigabytes}GB `),c.isZero||(d+=`${c.megabytes}MB `),l.isZero||(d+=`${l.kilobytes}KB `),(!u.isZero||d===``)&&(d+=`${u.valueOf()}B`),d.trim()}static bytes(t=1){return new e(t)}static BYTE=new e(1);static kilobytes(t=1){return e.bytes(new e(t).valueOf()*1e3)}static KILOBYTE=e.kilobytes(1);static megabytes(t=1){return e.kilobytes(new e(t).valueOf()*1e3)}static MEGABYTE=e.megabytes(1);static gigabytes(t=1){return e.megabytes(new e(t).valueOf()*1e3)}static GIGABYTE=e.gigabytes(1);static terabytes(t){return e.gigabytes(new e(t).valueOf()*1e3)}static TERABYTE=e.terabytes(1);static ZERO=new e(0);static z=c.z.union([c.z.number().transform(t=>new e(t)),c.z.instanceof(e)]);get isZero(){return this.valueOf()===0}};c.z.object({start:c.z.number(),end:c.z.number()}),c.z.union([c.z.instanceof(Uint8Array),c.z.instanceof(Uint16Array),c.z.instanceof(Uint32Array),c.z.instanceof(BigUint64Array),c.z.instanceof(Float32Array),c.z.instanceof(Float64Array),c.z.instanceof(Int8Array),c.z.instanceof(Int16Array),c.z.instanceof(Int32Array),c.z.instanceof(BigInt64Array)]);var wt=e=>{let t=typeof e;return t===`string`||t===`number`||t===`boolean`||t===`bigint`||e instanceof I||e instanceof L||e instanceof Date},Tt=(e,t,n,r=0)=>e.usesBigInt&&!t.usesBigInt?Number(n)-Number(r):!e.usesBigInt&&t.usesBigInt?BigInt(n.valueOf())-BigInt(r.valueOf()):C(n,r);B.z,I.z,L.z,R.z,H.z,V.z,B.boundedZ;var Et=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;function Dt(e){return typeof e==`string`&&Et.test(e)}var U=[];for(let e=0;e<256;++e)U.push((e+256).toString(16).slice(1));function Ot(e,t=0){return(U[e[t+0]]+U[e[t+1]]+U[e[t+2]]+U[e[t+3]]+`-`+U[e[t+4]]+U[e[t+5]]+`-`+U[e[t+6]]+U[e[t+7]]+`-`+U[e[t+8]]+U[e[t+9]]+`-`+U[e[t+10]]+U[e[t+11]]+U[e[t+12]]+U[e[t+13]]+U[e[t+14]]+U[e[t+15]]).toLowerCase()}function kt(e,t=0){let n=Ot(e,t);if(!Dt(n))throw TypeError(`Stringified UUID is invalid`);return n}typeof crypto<`u`&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);var At=(e,t)=>kt(e,t),W=-1,jt={[Symbol.iterator]:()=>jt,next:()=>({done:!0,value:void 0})},Mt=c.z.string().transform(e=>new Uint8Array(atob(e).split(``).map(e=>e.charCodeAt(0))).buffer),Nt=c.z.union([c.z.null(),c.z.undefined()]).transform(()=>new Uint8Array().buffer),Pt=10,Ft=(e,t)=>{if(e===`number`&&!t.isNumeric)throw Error(`cannot convert series of type ${t.toString()} to number`);if(e===`bigint`&&!t.usesBigInt)throw Error(`cannot convert series of type ${t.toString()} to bigint`)},It=`sy_x_telem_series`,Lt=class e{key;discriminator=It;dataType;sampleOffset;gl;_data;timeRange=B.ZERO;alignment=0n;alignmentMultiple=1n;cachedMin;cachedMax;writePos=W;_refCount=0;cachedLength;_cachedIndexes;static crudeZ=c.z.object({timeRange:B.z.optional(),dataType:V.z,alignment:c.z.coerce.bigint().optional(),data:c.z.union([Mt,Nt,c.z.instanceof(ArrayBuffer),c.z.instanceof(Uint8Array)]),glBufferUsage:bt.default(`static`).optional()});static z=e.crudeZ.transform(t=>new e(t));constructor(e){Rt(e)&&(e={data:e}),e.data??=[];let{dataType:t,timeRange:n,sampleOffset:r=0,glBufferUsage:i=`static`,alignment:a=0n,alignmentMultiple:o=1n,key:s=ve(),data:c}=e;if(zt(c)){let e=c;this.key=e.key,this.dataType=e.dataType,this.sampleOffset=e.sampleOffset,this.gl=e.gl,this._data=e._data,this.timeRange=e.timeRange,this.alignment=e.alignment,this.alignmentMultiple=e.alignmentMultiple,this.cachedMin=e.cachedMin,this.cachedMax=e.cachedMax,this.writePos=e.writePos,this._refCount=e._refCount,this.cachedLength=e.cachedLength;return}let l=wt(c),u=Array.isArray(c);if(t!=null)this.dataType=new V(t);else if(c instanceof ArrayBuffer)throw Error(`cannot infer data type from an ArrayBuffer instance when constructing a Series. Please provide a data type.`);else if(u||l){let e=c;if(!l){if(c.length===0)throw Error(`cannot infer data type from a zero length JS array when constructing a Series. Please provide a data type.`);e=c[0]}if(typeof e==`string`)this.dataType=V.STRING;else if(typeof e==`number`)this.dataType=V.FLOAT64;else if(typeof e==`bigint`)this.dataType=V.INT64;else if(typeof e==`boolean`)this.dataType=V.UINT8;else if(e instanceof I||e instanceof Date||e instanceof I)this.dataType=V.TIMESTAMP;else if(typeof e==`object`)this.dataType=V.JSON;else throw Error(`cannot infer data type of ${typeof e} when constructing a Series from a JS array`)}else this.dataType=new V(c);if(!u&&!l)this._data=c;else if(u&&c.length===0)this._data=new this.dataType.Array([]).buffer;else{let e=l?[c]:c,t=e[0];(t instanceof I||t instanceof Date||t instanceof L)&&(e=e.map(e=>new I(e).valueOf())),this.dataType.equals(V.STRING)?(this.cachedLength=e.length,this._data=new TextEncoder().encode(`${e.join(`
4
- `)}\n`).buffer):this.dataType.equals(V.JSON)?(this.cachedLength=e.length,this._data=new TextEncoder().encode(`${e.map(e=>le.encodeString(e)).join(`
5
- `)}\n`).buffer):this.dataType.usesBigInt&&typeof t==`number`?this._data=new this.dataType.Array(e.map(e=>BigInt(Math.round(e)))).buffer:!this.dataType.usesBigInt&&typeof t==`bigint`?this._data=new this.dataType.Array(e.map(Number)).buffer:this._data=new this.dataType.Array(e).buffer}this.key=s,this.alignment=a,this.alignmentMultiple=o,this.sampleOffset=r??0,this.timeRange=n??B.ZERO,this.gl={control:null,buffer:null,prevBuffer:0,bufferUsage:i}}static alloc({capacity:t,dataType:n,...r}){if(t===0)throw Error(`[Series] - cannot allocate an array of length 0`);let i=new e({data:new new V(n).Array(t).buffer,dataType:n,...r});return i.writePos=0,i}get refCount(){return this._refCount}acquire(e){this._refCount++,e!=null&&this.updateGLBuffer(e)}release(){this._refCount--,this.refCount===0&&this.gl.control!=null?this.maybeGarbageCollectGLBuffer(this.gl.control):this.refCount<0&&console.warn(`cannot release a series with a negative reference count`)}write(e){if(!e.dataType.equals(this.dataType))throw Error(`buffer must be of the same type as this array`);return this.dataType.isVariable?this.writeVariable(e):this.writeFixed(e)}writeVariable(e){if(this.writePos===W)return 0;let t=this.byteCapacity.valueOf()-this.writePos,n=e.subBytes(0,t);return this.writeToUnderlyingData(n),this.writePos+=n.byteLength.valueOf(),this.cachedLength!=null&&(this.cachedLength+=n.length,this.calculateCachedLength()),n.length}writeFixed(e){if(this.writePos===W)return 0;let t=this.capacity-this.writePos,n=e.sub(0,t);return this.writeToUnderlyingData(n),this.cachedLength=void 0,this.maybeRecomputeMinMax(n),this.writePos+=n.length,n.length}writeToUnderlyingData(e){this.underlyingData.set(e.data,this.writePos)}get buffer(){return typeof this._data==`object`&&`buffer`in this._data?this._data.buffer:this._data}get underlyingData(){return new this.dataType.Array(this._data)}get data(){return this.writePos===W?this.underlyingData:new this.dataType.Array(this._data,0,this.writePos)}toStrings(){return this.dataType.isVariable?new TextDecoder().decode(this.underlyingData).split(`
6
- `).slice(0,-1):Array.from(this).map(e=>e.toString())}parseJSON(e){if(!this.dataType.equals(V.JSON))throw Error(`cannot parse non-JSON series as JSON`);return this.toStrings().map(t=>e.parse(le.decodeString(t)))}get byteCapacity(){return new H(this.underlyingData.byteLength)}get capacity(){return this.dataType.isVariable?this.byteCapacity.valueOf():this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===W?this.byteCapacity:this.dataType.isVariable?new H(this.writePos):this.dataType.density.size(this.writePos)}get length(){return this.cachedLength==null?this.dataType.isVariable?this.calculateCachedLength():this.writePos===W?this.byteCapacity.valueOf()/this.dataType.density.valueOf():this.writePos:this.cachedLength}calculateCachedLength(){if(!this.dataType.isVariable)throw Error(`cannot calculate length of a non-variable length data type`);let e=0,t=[0];return this.data.forEach((n,r)=>{n===Pt&&(e++,t.push(r+1))}),this._cachedIndexes=t,this.cachedLength=e,e}convert(t,n=0){if(this.dataType.equals(t))return this;let r=new t.Array(this.length);for(let e=0;e<this.length;e++)r[e]=Tt(this.dataType,t,this.data[e],n);return new e({data:r.buffer,dataType:t,timeRange:this.timeRange,sampleOffset:n,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment})}calcRawMax(){return this.length===0?-1/0:(this.dataType.equals(V.TIMESTAMP)?this.cachedMax=this.data[this.data.length-1]:(this.dataType.usesBigInt,this.cachedMax=this.data.reduce((e,t)=>e>t?e:t)),this.cachedMax)}get max(){return this.calcMax()}calcMax(){if(this.dataType.isVariable)throw Error(`cannot calculate maximum on a variable length data type`);return this.writePos===0?-1/0:(this.cachedMax??=this.calcRawMax(),w(this.cachedMax,this.sampleOffset))}calcRawMin(){return this.length===0?1/0:(this.dataType.equals(V.TIMESTAMP)?this.cachedMin=this.data[0]:(this.dataType.usesBigInt,this.cachedMin=this.data.reduce((e,t)=>e<t?e:t)),this.cachedMin)}get min(){return this.calcMin()}calcMin(){if(this.dataType.isVariable)throw Error(`cannot calculate minimum on a variable length data type`);return this.writePos===0?1/0:(this.cachedMin??=this.calcRawMin(),w(this.cachedMin,this.sampleOffset))}get bounds(){return k(Number(this.min),Number(this.max),{makeValid:!1})}maybeRecomputeMinMax(e){if(this.cachedMin!=null){let t=e.cachedMin??e.calcRawMin();t<this.cachedMin&&(this.cachedMin=t)}if(this.cachedMax!=null){let t=e.cachedMax??e.calcRawMax();t>this.cachedMax&&(this.cachedMax=t)}}atAlignment(e,t){let n=Number((e-this.alignment)/this.alignmentMultiple);if(n<0||n>=this.length){if(t===!0)throw Error(`[series] - no value at index ${n}`);return}return this.at(n,t)}at(e,t=!1){if(this.dataType.isVariable)return this.atVariable(e,t??!1);if(this.dataType.equals(V.UUID))return this.atUUID(e,t);e<0&&(e=this.length+e);let n=this.data[e];if(n==null){if(t===!0)throw Error(`[series] - no value at index ${e}`);return}return w(n,this.sampleOffset)}atUUID(e,t){e<0&&(e=this.length+e);let n=At(new Uint8Array(this.buffer,e*this.dataType.density.valueOf()));if(n==null){if(t)throw Error(`[series] - no value at index ${e}`);return}return n}atVariable(e,t){let n=0,r=0;if(this._cachedIndexes!=null)n=this._cachedIndexes[e],r=this._cachedIndexes[e+1]-1;else{e<0&&(e=this.length+e);for(let t=0;t<this.data.length;t++)if(this.data[t]===Pt){if(e===0){r=t;break}n=t+1,e--}if(r===0&&(r=this.data.length),n>=r||e>0){if(t)throw Error(`[series] - no value at index ${e}`);return}}let i=this.data.slice(n,r);return this.dataType.equals(V.STRING)?new TextDecoder().decode(i):ne(JSON.parse(new TextDecoder().decode(i)))}binarySearch(e){let t=0,n=this.length-1,r=de(e);for(;t<=n;){let i=Math.floor((t+n)/2),a=r(this.at(i,!0),e);if(a===0)return i;a<0?t=i+1:n=i-1}return t}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals(V.FLOAT32)&&!this.dataType.equals(V.UINT8))throw Error(`Only FLOAT32 and UINT8 arrays can be used in WebGL`);let{buffer:t,bufferUsage:n,prevBuffer:r}=this.gl;if(t??(this.gl.buffer=e.createBuffer()),this.writePos!==r)if(e.bindBuffer(e.ARRAY_BUFFER,this.gl.buffer),this.writePos!==W){r===0&&e.bufferData(e.ARRAY_BUFFER,this.byteCapacity.valueOf(),e.STATIC_DRAW);let t=this.dataType.density.size(r).valueOf(),n=this.underlyingData.slice(this.gl.prevBuffer,this.writePos);e.bufferSubData(e.ARRAY_BUFFER,t,n.buffer),this.gl.prevBuffer=this.writePos}else e.bufferData(e.ARRAY_BUFFER,this.buffer,n===`static`?e.STATIC_DRAW:e.DYNAMIC_DRAW),this.gl.prevBuffer=W}as(e){return Ft(e,this.dataType),this}get digest(){return{key:this.key,dataType:this.dataType.toString(),sampleOffset:this.sampleOffset,alignment:{lower:Gt(this.alignmentBounds.lower),upper:Gt(this.alignmentBounds.upper),multiple:this.alignmentMultiple},timeRange:this.timeRange.toString(),length:this.length,capacity:this.capacity}}get alignmentBounds(){return k(this.alignment,this.alignment+BigInt(this.length)*this.alignmentMultiple)}maybeGarbageCollectGLBuffer(e){this.gl.buffer!=null&&(e.deleteBuffer(this.gl.buffer),this.gl.buffer=null,this.gl.prevBuffer=0,this.gl.control=null)}get glBuffer(){if(this.gl.buffer==null)throw Error(`gl buffer not initialized`);return this.gl.prevBuffer!==this.writePos&&console.warn(`buffer not updated`),this.gl.buffer}[Symbol.iterator](){if(this.dataType.isVariable){let e=new Vt(this);return this.dataType.equals(V.JSON)?new Ht(e):e}return this.dataType.equals(V.UUID)?new Ut(this):new Wt(this)}slice(e,t){return this.sliceSub(!1,e,t)}sub(e,t){return this.sliceSub(!0,e,t)}subIterator(e,t){return new Bt(this,e,t??this.length)}subAlignmentIterator(e,t){let n=Math.ceil(Number(e-this.alignment)/Number(this.alignmentMultiple)),r=Math.ceil(Number(t-this.alignment)/Number(this.alignmentMultiple));return new Bt(this,n,r)}subBytes(t,n){return t>=0&&(n==null||n>=this.byteLength.valueOf())?this:new e({data:this.data.subarray(t,n),dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(t)})}sliceSub(t,n,r){if(n<=0&&(r==null||r>=this.length))return this;let i;return i=t?this.data.subarray(n,r):this.data.slice(n,r),new e({data:i,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(n)})}reAlign(t){return new e({data:this.buffer,dataType:this.dataType,timeRange:B.ZERO,sampleOffset:this.sampleOffset,glBufferUsage:`static`,alignment:t})}toString(){let e=`Series(${this.dataType.toString()} ${this.length} [`;if(this.length<=10)e+=Array.from(this).map(e=>e.toString());else{for(let t=0;t<5;t++)e+=`${this.at(t)?.toString()}`,e+=`,`;e+=`...,`;for(let t=-5;t<0;t++)e+=this.at(t)?.toString(),t<-1&&(e+=`,`)}return e+=`])`,e}},Rt=e=>e==null?!1:Array.isArray(e)||e instanceof ArrayBuffer||ArrayBuffer.isView(e)&&!(e instanceof DataView)||e instanceof Lt?!0:wt(e),zt=ye(It,Lt),Bt=class{series;end;index;constructor(e,t,n){this.series=e;let r=k(0,e.length+1);this.end=Be(r,n),this.index=Be(r,t)}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}},Vt=class{series;index;decoder;constructor(e){if(!e.dataType.isVariable)throw Error(`cannot create a variable series iterator for a non-variable series`);this.series=e,this.index=0,this.decoder=new TextDecoder}next(){let e=this.index,t=this.series.data;for(;this.index<t.length&&t[this.index]!==Pt;)this.index++;let n=this.index;return e===n?{done:!0,value:void 0}:(this.index++,{done:!1,value:this.decoder.decode(this.series.buffer.slice(e,n))})}},Ht=class e{wrapped;static schema=c.z.record(c.z.string(),c.z.unknown());constructor(e){this.wrapped=e}next(){let t=this.wrapped.next();return t.done===!0?{done:!0,value:void 0}:{done:!1,value:le.decodeString(t.value,e.schema)}}},Ut=class{series;index;data;density;constructor(e){if(!e.dataType.equals(V.UUID))throw Error(`cannot create a UUID series iterator for a non-UUID series`);this.series=e,this.index=0,this.data=new Uint8Array(e.buffer),this.density=V.UUID.density.valueOf()}next(){if(this.index>=this.series.length)return{done:!0,value:void 0};let e=At(this.data,this.index*this.density);return this.index++,{done:!1,value:e}}},Wt=class{series;index;constructor(e){this.series=e,this.index=0}next(){return this.index>=this.series.length?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}},Gt=e=>({domain:e>>32n,sample:e&4294967295n}),Kt=async e=>await new Promise(t=>setTimeout(t,L.fromMilliseconds(e).milliseconds)),qt=u({Breaker:()=>Jt,breakerConfigZ:()=>Yt}),Jt=class{config;retries;interval;constructor(e){this.config={baseInterval:new L(e?.baseInterval??L.seconds(1)),maxRetries:e?.maxRetries??5,scale:e?.scale??1,sleepFn:e?.sleepFn??Kt},this.retries=0,this.interval=new L(this.config.baseInterval)}async wait(){let{maxRetries:e,scale:t,sleepFn:n}=this.config;return this.retries>=e?!1:(await n(this.interval),this.interval=this.interval.mult(t),this.retries++,!0)}get retryMessage(){return`breaker triggered ${this.retries+1}/${this.config.maxRetries} times, retrying in ${this.interval.toString()}`}reset(){this.retries=0,this.interval=this.config.baseInterval}},Yt=c.z.object({baseInterval:L.z.optional(),maxRetries:c.z.number().optional(),scale:c.z.number().optional()});c.z.int().min(Ce).max(127),c.z.int().min(we).max(Te),c.z.int().min(De).max(Oe);var Xt=c.z.int().min(0).max(255);c.z.int().min(0).max(be),c.z.int().min(0).max(xe),c.z.int().min(0).max(Se);var Zt=(e,t)=>{let n=Array.isArray(e),r=Array.isArray(t);if(n!==r)return!1;if(n&&r){let n=e,r=t;if(n.length!==r.length)return!1;for(let e=0;e<n.length;e++)if(!Zt(n[e],r[e]))return!1;return!0}if(e==null||t==null||typeof e!=`object`||typeof t!=`object`)return e===t;if(`equals`in e)return e.equals(t);let i=Object.keys(e),a=Object.keys(t);if(i.length!==a.length)return!1;for(let n of i){let r=e[n],i=t[n];if(typeof r==`object`&&typeof i==`object`){if(!Zt(r,i))return!1}else if(r!==i)return!1}return!0},Qt=(e,t)=>{if(typeof e!=`object`||!e)return e===t;let n=Object.keys(e),r=Object.keys(t);if(r.length>n.length)return!1;for(let n of r){let r=e[n],i=t[n];if(typeof r==`object`&&typeof i==`object`){if(!Qt(r,i))return!1}else if(r!==i)return!1}return!0},$t=(e,...t)=>{if(t.length===0)return e;let n=t.shift();if(v(e)&&v(n))for(let t in n)try{v(n[t])?(t in e||Object.assign(e,{[t]:{}}),$t(e[t],n[t])):Object.assign(e,{[t]:n[t]})}catch(e){throw e instanceof TypeError?TypeError(`.${t}: ${e.message}`,{cause:e}):e}return $t(e,...t)},en=c.z.string().regex(/^#?([0-9a-f]{6}|[0-9a-f]{8})$/i),G=Xt,tn=c.z.number().min(0).max(1),nn=c.z.tuple([G,G,G,tn]),rn=c.z.tuple([G,G,G]),an=c.z.object({rgba255:nn}),on=c.z.object({r:G,g:G,b:G,a:tn}),sn=c.z.number().min(0).max(360),cn=c.z.number().min(0).max(100),ln=c.z.number().min(0).max(100),un=c.z.tuple([sn,cn,ln,tn]),dn=c.z.union([en,rn,nn,un,an,on]),fn=dn.transform(e=>pn(e)),pn=(e,t=1)=>{if(e=dn.parse(e),typeof e==`string`)return mn(e,t);if(Array.isArray(e)){if(e.length<3||e.length>4)throw Error(`Invalid color: [${e.join(`, `)}]`);return e.length===3?[...e,t]:e}return`a`in e&&`r`in e?[e.r,e.g,e.b,e.a]:e.rgba255},mn=(e,t=1)=>(e=en.parse(e),e=hn(e),[K(e,0),K(e,2),K(e,4),e.length===8?K(e,6)/255:t]),K=(e,t)=>parseInt(e.slice(t,t+2),16),hn=e=>e.startsWith(`#`)?e.slice(1):e;pn(`#000000`),pn(`#ffffff`);var gn=c.z.object({key:c.z.string(),color:dn,position:c.z.number(),switched:c.z.boolean().optional()});c.z.array(gn);var _n=c.z.object({key:c.z.string(),name:c.z.string(),color:fn});c.z.object({key:c.z.string(),name:c.z.string(),swatches:c.z.array(_n)});var vn=function(e){return e[e.exclusive=0]=`exclusive`,e[e.shared=1]=`shared`,e}({});c.z.enum(vn),c.z.object({key:c.z.string(),name:c.z.string(),group:c.z.uint32().optional()});var yn=e=>Object.getOwnPropertySymbols(globalThis).includes(e),bn=(e,t)=>{let n=Symbol.for(e);if(!yn(n)){let e=t();Object.defineProperty(globalThis,n,{value:e})}return()=>globalThis[n]},q=u({Canceled:()=>jn,NONE:()=>`nil`,NotImplemented:()=>Mn,UNKNOWN:()=>Y,Unknown:()=>kn,createTyped:()=>J,decode:()=>On,encode:()=>Dn,isTyped:()=>Cn,payloadZ:()=>An,register:()=>En}),xn=`sy_x_error`,Sn=e=>t=>typeof t==`object`&&t&&`type`in t&&typeof t.type==`string`?t.type.startsWith(e):t instanceof Error?t.message.startsWith(e):typeof t==`string`?t.startsWith(e):!1,J=e=>class t extends Error{static discriminator=xn;discriminator=t.discriminator;static TYPE=e;type=t.TYPE;static matches=Sn(e);matches=t.matches;constructor(e,n){super(e,n),this.name=t.TYPE}static sub(t){return J(`${e}.${t}`)}},Cn=e=>{if(typeof e!=`object`||!e)return!1;let t=e;if(t.discriminator!==xn)return!1;if(!(`type`in t))throw Error(`X Error is missing its type property: ${JSON.stringify(t)}`);return!0},Y=`unknown`,wn=class{providers=[];register(e){this.providers.push(e)}encode(e){if(e==null)return{type:`nil`,data:``};if(Cn(e))for(let t of this.providers){let n=t.encode(e);if(n!=null)return n}if(e instanceof Error)return{type:Y,data:e.message};if(typeof e==`string`)return{type:Y,data:e};try{return{type:Y,data:JSON.stringify(e)}}catch{return{type:Y,data:`unable to encode error information`}}}decode(e){if(e==null||e.type===`nil`)return null;if(e.type===`unknown`)return new kn(e.data);for(let t of this.providers){let n=t.decode(e);if(n!=null)return n}return new kn(e.data)}},Tn=bn(`synnax-error-registry`,()=>new wn),En=({encode:e,decode:t})=>Tn().register({encode:e,decode:t}),Dn=e=>Tn().encode(e),On=e=>e==null?null:Tn().decode(e),kn=class extends J(`unknown`){},An=c.z.object({type:c.z.string(),data:c.z.string()}),jn=class extends J(`canceled`){},Mn=class extends J(`not_implemented`){};c.z.string().regex(/^(?:$|(?:\/(?:[^~/]|~0|~1)*)+)$/,`must be a valid JSON pointer (RFC 6901)`),c.z.union([c.z.string(),c.z.number(),c.z.boolean(),c.z.null()]),c.z.enum([`string`,`number`,`boolean`,`null`]),c.z.object({key:c.z.string(),value:c.z.string()});var Nn=c.z.uuid();c.z.object({key:Nn,name:c.z.string().min(1),color:fn}).partial({key:!0}),c.z.string().regex(/^\d+\.\d+\.\d+(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$/),c.z.enum([`standard`,`scientific`,`engineering`]),c.z.union([c.z.string(),c.z.number()]),typeof process<`u`&&process.versions!=null&&process.versions.node!=null||typeof window>`u`||window.document;var Pn=[`macOS`,`Windows`,`Linux`],Fn=[`macos`,`windows`,`linux`],In={macos:`macOS`,windows:`Windows`,linux:`Linux`};c.z.enum(Pn).or(c.z.enum(Fn).transform(e=>In[e])),c.z.object({stack:c.z.string(),error:c.z.instanceof(Error)}),c.z.enum([`success`,`info`,`warning`,`error`,`loading`,`disabled`]),c.z.literal(`success`),c.z.literal(`info`),c.z.literal(`warning`),c.z.literal(`error`),c.z.literal(`loading`),c.z.literal(`disabled`);var Ln=(...e)=>e.map(Rn).join(``),Rn=e=>(e.endsWith(`/`)||(e+=`/`),e.startsWith(`/`)&&(e=e.slice(1)),e),zn=e=>e.endsWith(`/`)?e.slice(0,-1):e,Bn=(e,t=``)=>e===null?``:`?${Object.entries(e).filter(([,e])=>e==null?!1:Array.isArray(e)?e.length>0:!0).map(([e,n])=>`${t}${e}=${n}`).join(`&`)}`,Vn=class e{protocol;host;port;path;constructor({host:e,port:t,protocol:n=``,pathPrefix:r=``}){this.protocol=n,this.host=e,this.port=t,this.path=Rn(r)}replace(t){return new e({host:t.host??this.host,port:t.port??this.port,protocol:t.protocol??this.protocol,pathPrefix:t.pathPrefix??this.path})}child(t){return new e({...this,pathPrefix:Ln(this.path,t)})}toString(){return zn(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}static UNKNOWN=new e({host:`unknown`,port:0})},X=class extends q.createTyped(`freighter`){},Z=class extends X.sub(`eof`){constructor(){super(`EOF`)}},Q=class extends X.sub(`stream_closed`){constructor(){super(`StreamClosed`)}},$=class extends X.sub(`unreachable`){url;constructor(e={}){let{message:t=`Unreachable`,url:n=Vn.UNKNOWN}=e;super(t),this.url=n}};q.register({encode:e=>{if(!e.type.startsWith(X.TYPE))return null;if(Z.matches(e))return{type:Z.TYPE,data:`EOF`};if(Q.matches(e))return{type:Q.TYPE,data:`StreamClosed`};if($.matches(e))return{type:$.TYPE,data:`Unreachable`};throw Error(`Unknown error type: ${e.type}: ${e.message}`)},decode:e=>{if(!e.type.startsWith(X.TYPE))return null;switch(e.type){case Z.TYPE:return new Z;case Q.TYPE:return new Q;case $.TYPE:return new $;default:throw new q.Unknown(`Unknown error type: ${e.data}`)}}});var Hn=class{middleware=[];use(...e){this.middleware.push(...e)}async executeMiddleware(e,t){let n=0,r=async e=>{if(n===this.middleware.length)return await t(e);let i=this.middleware[n];return n++,await i(e,r)};return await r(e)}},Un=`Content-Type`,Wn=new Set([`ECONNREFUSED`,`ECONNRESET`,`ETIMEDOUT`,`EPIPE`,`UND_ERR_CONNECT_TIMEOUT`,`UND_ERR_SOCKET`]),Gn=e=>{let t=e?.cause?.code??e?.code??e?.errno;if(typeof t==`string`&&Wn.has(t))return!0;if(e.name===`TypeError`){let t=String(e.message||``).toLowerCase();if(/load failed|failed to fetch|networkerror|network error/.test(t))return typeof navigator<`u`&&navigator.onLine,!0}return e?.name===`AbortError`||e?.code,!1},Kn=400,qn=class extends Hn{endpoint;encoder;constructor(e,t,n=!1){return super(),this.endpoint=e.replace({protocol:n?`https`:`http`}),this.encoder=t,new Proxy(this,{get:(e,t,n)=>t===`endpoint`?this.endpoint:Reflect.get(e,t,n)})}get headers(){return{[Un]:this.encoder.contentType}}async send(e,t,n,r){let i=null,a=this.endpoint.child(e),o={};o.method=`POST`,o.body=this.encoder.encode(t,n);let[,s]=await this.executeMiddleware({target:a.toString(),protocol:this.endpoint.protocol,params:{},role:`client`},async e=>{let t={...e,params:{}};o.headers={...this.headers,...e.params};let n;try{n=await fetch(e.target,o)}catch(e){if(!(e instanceof Error))throw e;return[t,Gn(e)?new $({url:a}):e]}let s=await n.arrayBuffer();if(n?.ok)return r!=null&&(i=this.encoder.decode(s,r)),[t,null];try{if(n.status!==Kn)return[t,Error(n.statusText)];let e=this.encoder.decode(s,q.payloadZ);return[t,q.decode(e)]}catch(e){return[t,Error(`[freighter] - failed to decode error: ${n.statusText}: ${e.message}`)]}});if(s!=null)return[null,s];if(i==null)throw Error(`Response must be defined`);return[i,null]}},Jn=(e,t)=>{class n{wrapped;constructor(e){this.wrapped=e}use(...e){this.wrapped.use(...e)}async send(e,n,r,i){let a=new qt.Breaker(t);do{let[t,o]=await this.wrapped.send(e,n,r,i);if(o==null)return[t,null];if(!$.matches(o))return[null,o];if(console.warn(`[freighter] ${a.retryMessage}`,o),!await a.wait())return[t,o]}while(!0)}}return new n(e)},Yn=async(e,t,n,r,i)=>{let[a,o]=await e.send(t,n,r,i);if(o!=null)throw o;return a},Xn=c.z.object({type:c.z.enum([`data`,`close`,`open`]),payload:c.z.unknown(),error:c.z.optional(q.payloadZ)}),Zn=class{codec;reqSchema;resSchema;ws;serverClosed;sendClosed;receiveDataQueue=[];receiveCallbacksQueue=[];constructor(e,t,n,r){this.codec=t,this.reqSchema=n,this.resSchema=r,this.ws=e,this.sendClosed=!1,this.serverClosed=null,this.listenForMessages()}async receiveOpenAck(){let e=await this.receiveMsg();if(e.type!==`open`){if(e.error==null)throw Error(`Message error must be defined`);return q.decode(e.error)}return null}send(e){if(this.serverClosed!=null)return new Z;if(this.sendClosed)throw new Q;return this.ws.send(this.codec.encode({type:`data`,payload:e})),null}async receive(){if(this.serverClosed!=null)return[null,this.serverClosed];let e=await this.receiveMsg();if(e.type===`close`){if(e.error==null||(this.serverClosed=q.decode(e.error),this.serverClosed==null))throw Error(`Message error must be defined`);return[null,this.serverClosed]}return[this.resSchema.parse(e.payload),null]}received(){return this.receiveDataQueue.length!==0}closeSend(){if(this.sendClosed||this.serverClosed!=null)return;let e={type:`close`};try{this.ws.send(this.codec.encode(e))}finally{this.sendClosed=!0}}async receiveMsg(){return this.receiveDataQueue.shift()??await new Promise((e,t)=>this.receiveCallbacksQueue.push({resolve:e,reject:t}))}addMessage(e){let t=this.receiveCallbacksQueue.shift();t==null?this.receiveDataQueue.push(e):t.resolve(e)}listenForMessages(){this.ws.onmessage=this.onMessage.bind(this),this.ws.onclose=this.onClose.bind(this)}onMessage(e){this.addMessage(this.codec.decode(e.data,Xn))}onClose(e){this.addMessage({type:`close`,error:{type:e.code===$n?Z.TYPE:Q.TYPE,data:``}})}},Qn=`freighterctx`,$n=1e3,er=class e extends Hn{baseUrl;encoder;secure;static MESSAGE_TYPE=`arraybuffer`;constructor(e,t,n=!1){super(),this.secure=n,this.baseUrl=e.replace({protocol:n?`wss`:`ws`}),this.encoder=t}withCodec(t){let n=new e(this.baseUrl,t,this.secure);return n.use(...this.middleware),n}async stream(t,n,r){let i,[,a]=await this.executeMiddleware({target:t,protocol:`websocket`,params:{},role:`client`},async a=>{let o=new WebSocket(this.buildURL(t,a)),s={...a,params:{}};o.binaryType=e.MESSAGE_TYPE;let c=await this.wrapSocket(o,n,r);return c instanceof Error?[s,c]:(i=c,[s,null])});if(a!=null)throw a;return i}buildURL(e,t){let n=Bn({[Un]:this.encoder.contentType,...t.params},Qn);return this.baseUrl.child(e).toString()+n}async wrapSocket(e,t,n){return await new Promise(r=>{e.onopen=()=>{let i=new Zn(e,this.encoder,t,n);i.receiveOpenAck().then(e=>{r(e??i)}).catch(e=>r(e))},e.onerror=e=>{r(Error(e.message))}})}};exports.EOF=Z,exports.HTTPClient=qn,exports.StreamClosed=Q,exports.Unreachable=$,exports.WebSocketClient=er,exports.sendRequired=Yn,exports.unaryWithBreaker=Jn;
11
+ `).map(e=>e.trim());if(n.length===0)return t==null?{}:t.parse({});let i=n.split(`,`).map(e=>e.trim()),a={};return i.forEach(e=>{a[e]=[]}),r.forEach(e=>{let t=e.split(`,`).map(e=>e.trim());i.forEach((e,n)=>{let r=this.parseValue(t[n]);r!=null&&a[e].push(r)})}),t==null?a:t.parse(a)}parseValue(e){if(e==null||e.length===0)return null;let t=Number(e);return isNaN(t)?e.startsWith(`"`)&&e.endsWith(`"`)?e.slice(1,-1):e:t}},xt=class{contentType=`text/plain`;encode(e){if(typeof e!=`string`)throw Error(`TextCodec.encode payload must be a string`);return new TextEncoder().encode(e)}decode(e,t){let n=new TextDecoder().decode(e);return t==null?n:t.parse(n)}},St=new yt;new bt,new xt;var Ct=365,N=30,wt=c.z.union([c.z.tuple([c.z.int()]),c.z.tuple([c.z.int(),c.z.int().min(1).max(12)]),c.z.tuple([c.z.int(),c.z.int().min(1).max(12),c.z.int().min(1).max(31)])]),Tt=(e,t)=>{let n=new P(t);if(![F.DAY,F.HOUR,F.MINUTE,F.SECOND,F.MILLISECOND,F.MICROSECOND,F.NANOSECOND].some(e=>e.equals(n)))throw Error(`Invalid argument for remainder. Must be an even TimeSpan or Timestamp`);let r=e.valueOf()%n.valueOf();return e instanceof P?new P(r):new F(r)},P=class e extends C{constructor(t,n=`UTC`){if(t==null)super(e.now().valueOf());else if(t instanceof Date)super(BigInt(t.getTime())*e.MILLISECOND.valueOf());else if(typeof t==`string`)super(e.parseDateTimeString(t,n).valueOf());else if(Array.isArray(t))super(e.parseDate(t));else{let r=0n;t instanceof Number&&(t=t.valueOf()),n===`local`&&(r=e.utcOffset.valueOf()),typeof t==`number`&&(isFinite(t)?t=t===rt?E:Math.trunc(t):(isNaN(t)&&(t=0),t=t===1/0?e.MAX:e.MIN)),S(t)&&(t=t.value),super(BigInt(t.valueOf())+r)}}static parseDate([t=1970,n=1,r=1]){let i=new Date(t,n-1,r,0,0,0,0);return new e(BigInt(i.getTime())*e.MILLISECOND.valueOf()).truncate(e.DAY).valueOf()}valueOf(){return this.value}static parseTimeString(t,n=`UTC`){let[r,i,a]=t.split(`:`),o=`00`,s=`00`;a!=null&&([o,s]=a.split(`.`));let c=e.hours(parseInt(r??`00`,10)).add(e.minutes(parseInt(i??`00`,10))).add(e.seconds(parseInt(o??`00`,10))).add(e.milliseconds(parseInt(s??`00`,10)));return n===`local`&&(c=c.add(e.utcOffset)),c.valueOf()}static parseDateTimeString(t,n=`UTC`){if(!t.includes(`/`)&&!t.includes(`-`))return e.parseTimeString(t,n);if(t.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,3})?$/)!=null){let r=t,i=0;if(t.includes(`.`)){let e=t.split(`.`);r=e[0];let n=e[1]||`0`;i=parseInt(n.padEnd(3,`0`).slice(0,3),10)}let a=n===`local`?new Date(r.replace(`T`,` `)):new Date(`${r}Z`);return BigInt(a.getTime())*e.MILLISECOND.valueOf()+BigInt(i)*e.MILLISECOND.valueOf()}let r=new Date(t);return t.includes(`:`)||r.setUTCHours(0,0,0,0),new e(BigInt(r.getTime())*e.MILLISECOND.valueOf(),n).valueOf()}toISOString(t=`UTC`){if(t===`UTC`)return this.date().toISOString();let n=this.date(),r=new F(BigInt(n.getTimezoneOffset())*e.MINUTE.valueOf());return this.sub(r).date().toISOString()}timeString(e=!1,t=`UTC`){let n=this.toISOString(t);return e?n.slice(11,23):n.slice(11,19)}dateString(){let e=this.date();return`${e.toLocaleString(`default`,{month:`short`})} ${e.toLocaleString(`default`,{day:`numeric`})}`}static get utcOffset(){return new F(BigInt(new Date().getTimezoneOffset())*e.MINUTE.valueOf())}static since(t){return new e().span(t)}date(){return new Date(this.milliseconds)}equals(t){return this.valueOf()===new e(t).valueOf()}span(e){return this.range(e).span}range(e){return new R(this,e).makeValid()}spanRange(e){return this.range(this.add(e)).makeValid()}get isZero(){return this.valueOf()===0n}after(t){return this.valueOf()>new e(t).valueOf()}afterEq(t){return this.valueOf()>=new e(t).valueOf()}before(t){return this.valueOf()<new e(t).valueOf()}beforeEq(t){return this.valueOf()<=new e(t).valueOf()}add(t){return new e(k(this.valueOf(),new F(t).valueOf()))}sub(t){return new e(O(this.valueOf(),new F(t).valueOf()))}get hours(){return Number(this.valueOf())/Number(F.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(F.MINUTE.valueOf())}get days(){return Number(this.valueOf())/Number(F.DAY.valueOf())}get seconds(){return Number(this.valueOf())/Number(F.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(e.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(e.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get year(){return this.date().getUTCFullYear()}get localYear(){return this.date().getFullYear()}setYear(t){let n=this.date();return n.setUTCFullYear(t),new e(n)}setLocalYear(t){let n=this.date();return n.setFullYear(t),new e(n)}get month(){return this.date().getUTCMonth()}get localMonth(){return this.date().getMonth()}setMonth(t){let n=this.date();return n.setUTCMonth(t),new e(n)}setLocalMonth(t){let n=this.date();return n.setMonth(t),new e(n)}get day(){return this.date().getUTCDate()}get localDay(){return this.date().getDate()}setDay(t){let n=this.date();return n.setUTCDate(t),new e(n)}setLocalDay(t){let n=this.date();return n.setDate(t),new e(n)}get hour(){return this.date().getUTCHours()}get localHour(){return this.date().getHours()}setLocalHour(t){let n=this.date();return n.setHours(t),new e(n)}setHour(t){let n=this.date();return n.setUTCHours(t),new e(n)}get minute(){return this.date().getUTCMinutes()}get localMinute(){return this.date().getMinutes()}setMinute(t){let n=this.date();return n.setUTCMinutes(t),new e(n)}setLocalMinute(t){let n=this.date();return n.setMinutes(t),new e(n)}get second(){return this.date().getUTCSeconds()}get localSecond(){return this.date().getSeconds()}setSecond(t){let n=this.date();return n.setUTCSeconds(t),new e(n)}setLocalSecond(t){let n=this.date();return n.setSeconds(t),new e(n)}get millisecond(){return this.date().getUTCMilliseconds()}get localMillisecond(){return this.date().getMilliseconds()}setMillisecond(t){let n=this.date();return n.setUTCMilliseconds(t),new e(n)}setLocalMillisecond(t){let n=this.date();return n.setMilliseconds(t),new e(n)}toString(e=`ISO`,t=`UTC`){switch(e){case`ISODate`:return this.toISOString(t).slice(0,10);case`ISOTime`:return this.toISOString(t).slice(11,23);case`time`:return this.timeString(!1,t);case`preciseTime`:return this.timeString(!0,t);case`date`:return this.dateString();case`preciseDate`:return`${this.dateString()} ${this.timeString(!0,t)}`;case`dateTime`:return`${this.dateString()} ${this.timeString(!1,t)}`;default:return this.toISOString(t)}}remainder(e){return Tt(this,e)}get isToday(){return this.truncate(F.DAY).equals(e.now().truncate(F.DAY))}truncate(e){return this.sub(this.remainder(e))}formatBySpan(e){return e.greaterThanOrEqual(F.days(30))?`shortDate`:e.greaterThanOrEqual(F.DAY)?`dateTime`:e.greaterThanOrEqual(F.HOUR)?`time`:e.greaterThanOrEqual(F.SECOND)?`preciseTime`:`ISOTime`}static now(){return new e(new Date)}static max(...t){let n=e.MIN;for(let r of t){let t=new e(r);t.after(n)&&(n=t)}return n}static min(...t){let n=e.MAX;for(let r of t){let t=new e(r);t.before(n)&&(n=t)}return n}static nanoseconds(t,n=`UTC`){return new e(t,n)}static NANOSECOND=e.nanoseconds(1);static microseconds(t,n=`UTC`){return e.nanoseconds(t*1e3,n)}static MICROSECOND=e.microseconds(1);static milliseconds(t,n=`UTC`){return e.microseconds(t*1e3,n)}static MILLISECOND=e.milliseconds(1);static seconds(t,n=`UTC`){return e.milliseconds(t*1e3,n)}static SECOND=e.seconds(1);static minutes(t,n=`UTC`){return e.seconds(t*60,n)}static MINUTE=e.minutes(1);static hours(t,n=`UTC`){return e.minutes(t*60,n)}static HOUR=e.hours(1);static days(t,n=`UTC`){return e.hours(t*24,n)}static DAY=e.days(1);static MAX=new e(E);static MIN=new e(0);static ZERO=new e(0);static z=c.z.union([c.z.instanceof(e),c.z.object({value:c.z.bigint()}).transform(t=>new e(t.value)),c.z.string().transform(t=>new e(BigInt(t))),c.z.number().transform(t=>new e(t)),c.z.bigint().transform(t=>new e(t)),c.z.date().transform(t=>new e(t)),c.z.custom(e=>e instanceof F).transform(t=>new e(t)),wt.transform(t=>new e(t))]);static sort(e,t){return Number(e.valueOf()-t.valueOf())}},F=class e extends C{constructor(e){typeof e==`number`&&(e=Math.trunc(e.valueOf())),S(e)&&(e=e.value),super(BigInt(e.valueOf()))}static fromSeconds(t){return t instanceof e?t:t instanceof I?t.period:t instanceof P?new e(t):(S(t)&&(t=t.value),[`number`,`bigint`].includes(typeof t)?e.seconds(t):new e(t))}static fromMilliseconds(t){return t instanceof e?t:t instanceof I?t.period:t instanceof P?new e(t):(S(t)&&(t=t.value),[`number`,`bigint`].includes(typeof t)?e.milliseconds(t):new e(t))}valueOf(){return this.value}lessThan(t){return this.valueOf()<new e(t).valueOf()}greaterThan(t){return this.valueOf()>new e(t).valueOf()}lessThanOrEqual(t){return this.valueOf()<=new e(t).valueOf()}greaterThanOrEqual(t){return this.valueOf()>=new e(t).valueOf()}remainder(e){return Tt(this,e)}truncate(t){return new e(BigInt(Math.trunc(Number(this.valueOf()/t.valueOf())))*t.valueOf())}toString(t=`full`){if(t===`semantic`)return this.toSemanticString();let n=this.truncate(e.DAY),r=this.truncate(e.HOUR),i=this.truncate(e.MINUTE),a=this.truncate(e.SECOND),o=this.truncate(e.MILLISECOND),s=this.truncate(e.MICROSECOND),c=this.truncate(e.NANOSECOND),l=n,u=r.sub(n),d=i.sub(r),f=a.sub(i),p=o.sub(a),m=s.sub(o),h=c.sub(s),g=``;return l.isZero||(g+=`${l.days}d `),u.isZero||(g+=`${u.hours}h `),d.isZero||(g+=`${d.minutes}m `),f.isZero||(g+=`${f.seconds}s `),p.isZero||(g+=`${p.milliseconds}ms `),m.isZero||(g+=`${m.microseconds}µs `),h.isZero||(g+=`${h.nanoseconds}ns`),g.trim()}toSemanticString(){let t=new e(this.valueOf()<0n?-this.valueOf():this.valueOf()),n=this.valueOf()<0n;if(t.valueOf()===0n)return`0s`;if(t.lessThan(e.SECOND))return`< 1s`;let r=t.days,i=t.hours,a=t.minutes,o=t.seconds,s=Math.floor(r/Ct),c=Math.floor(r/N),l=Math.floor(r/7),u=Math.floor(r),d=Math.floor(i),f=Math.floor(a),p=Math.floor(o),m=n?`-`:``;if(s>=1){let e=`${s}y`;if(s<2){let t=Math.floor(r%Ct/N);t>0&&(e+=` ${t}mo`)}return m+e}if(l>=1&&r<N&&r%7==0){let e=`${l}w`,t=Math.floor(r%7),n=Math.floor(i-l*7*24);return l<2&&(t>0?e+=` ${t}d`:n>0&&n<24&&(e+=` ${n}h`)),m+e}if(c>=1){let e=`${c}mo`;if(c<3){let t=Math.floor(r%N);t>0&&(e+=` ${t}d`)}return m+e}if(l>=1){let e=`${l}w`,t=Math.floor(r%7),n=Math.floor(i-l*7*24);return l<2&&(t>0?e+=` ${t}d`:n>0&&n<24&&(e+=` ${n}h`)),m+e}if(u>=1){let e=`${u}d`,t=Math.floor(i-u*24);return u<2&&t>0&&(e+=` ${t}h`),m+e}if(d>=1){let e=`${d}h`;if(d<3){let t=Math.floor(a-d*60);t>0&&(e+=` ${t}m`)}return m+e}if(f>=1){let e=`${f}m`;if(f<5){let t=Math.floor(o-f*60);t>0&&(e+=` ${t}s`)}return m+e}return`${m}${p}s`}mult(t){return new e(A(this.valueOf(),t))}div(t){return new e(j(this.valueOf(),t))}get days(){return Number(this.valueOf())/Number(e.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(e.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(e.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(e.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(e.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(e.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get isZero(){return this.valueOf()===0n}equals(t){return this.valueOf()===new e(t).valueOf()}add(t){return new e(this.valueOf()+new e(t).valueOf())}sub(t){return new e(this.valueOf()-new e(t).valueOf())}abs(){let t=this.valueOf();return new e(t<0n?-t:t)}static nanoseconds(t=1){return new e(t)}static NANOSECOND=e.nanoseconds(1);static microseconds(t=1){return e.nanoseconds(A(t,1e3))}static MICROSECOND=e.microseconds(1);static milliseconds(t=1){return e.microseconds(A(t,1e3))}static MILLISECOND=e.milliseconds(1);static seconds(t=1){return e.milliseconds(A(t,1e3))}static SECOND=e.seconds(1);static minutes(t=1){return e.seconds(A(t,60))}static MINUTE=e.minutes(1);static hours(t){return e.minutes(A(t,60))}static HOUR=e.hours(1);static days(t){return e.hours(A(t,24))}static DAY=e.days(1);static MAX=new e(E);static MIN=new e(0);static ZERO=new e(0);static z=c.z.union([c.z.object({value:c.z.bigint()}).transform(t=>new e(t.value)),c.z.string().transform(t=>new e(BigInt(t))),c.z.number().transform(t=>new e(t)),c.z.bigint().transform(t=>new e(t)),c.z.instanceof(e),c.z.instanceof(P).transform(t=>new e(t)),c.z.custom(e=>e instanceof I).transform(t=>new e(t))])},I=class e extends C{constructor(e){S(e)&&(e=e.value),super(e.valueOf())}toString(){return`${this.valueOf()} Hz`}equals(t){return this.valueOf()===new e(t).valueOf()}get period(){return F.seconds(1/this.valueOf())}sampleCount(e){return new F(e).seconds*this.valueOf()}byteCount(e,t){return this.sampleCount(e)*new L(t).valueOf()}span(e){return F.seconds(e/this.valueOf())}byteSpan(e,t){return this.span(e.valueOf()/new L(t).valueOf())}add(t){return new e(k(this.valueOf(),new e(t).valueOf()))}sub(t){return new e(O(this.valueOf(),new e(t).valueOf()))}mult(t){return new e(A(this.valueOf(),t))}div(t){return new e(j(this.valueOf(),t))}static hz(t){return new e(t)}static khz(t){return e.hz(t*1e3)}static z=c.z.union([c.z.number().transform(t=>new e(t)),c.z.instanceof(e)])},L=class e extends C{constructor(e){S(e)&&(e=e.value),super(e.valueOf())}length(e){return e.valueOf()/this.valueOf()}size(e){return new B(e*this.valueOf())}add(t){return new e(k(this.valueOf(),new e(t).valueOf()))}sub(t){return new e(O(this.valueOf(),new e(t).valueOf()))}mult(t){return new e(A(this.valueOf(),t))}div(t){return new e(j(this.valueOf(),t))}static UNKNOWN=new e(0);static BIT128=new e(16);static BIT64=new e(8);static BIT32=new e(4);static BIT16=new e(2);static BIT8=new e(1);static z=c.z.union([c.z.number().transform(t=>new e(t)),c.z.instanceof(e)])},R=class e{start;end;constructor(e,t){typeof e==`object`&&`start`in e?(this.start=new P(e.start),this.end=new P(e.end)):(this.start=new P(e),this.end=new P(t))}get span(){return new F(this.end.valueOf()-this.start.valueOf())}get isValid(){return this.start.valueOf()<=this.end.valueOf()}makeValid(){return this.isValid?this:this.swap()}get isZero(){return this.start.isZero&&this.end.isZero}get numeric(){return{start:Number(this.start.valueOf()),end:Number(this.end.valueOf())}}swap(){return new e(this.end,this.start)}get numericBounds(){return{lower:Number(this.start.valueOf()),upper:Number(this.end.valueOf())}}equals(e,t=F.ZERO){if(t.isZero)return this.start.equals(e.start)&&this.end.equals(e.end);let n=this.start.sub(e.start).valueOf(),r=this.end.sub(e.end).valueOf();return n<0&&(n=-n),r<0&&(r=-r),n<=t.valueOf()&&r<=t.valueOf()}toString(){return`${this.start.toString()} - ${this.end.toString()}`}toPrettyString(){return`${this.start.toString(`preciseDate`)} - ${this.span.toString()}`}overlapsWith(e,t=F.ZERO){e=e.makeValid();let n=this.makeValid();if(this.equals(e))return!0;if(e.end.equals(n.start)||n.end.equals(e.start))return!1;let r=P.max(n.start,e.start),i=P.min(n.end,e.end);return i.before(r)?!1:new F(i.sub(r)).greaterThanOrEqual(t)}contains(t){return t instanceof e?this.contains(t.start)&&this.contains(t.end):this.start.beforeEq(t)&&this.end.after(t)}boundBy(t){let n=new e(this.start,this.end);return t.start.after(this.start)&&(n.start=t.start),t.start.after(this.end)&&(n.end=t.start),t.end.before(this.end)&&(n.end=t.end),t.end.before(this.start)&&(n.start=t.end),n}static max(...t){return new e(P.min(...t.map(e=>e.start)),P.max(...t.map(e=>e.end)))}static MAX=new e(P.MIN,P.MAX);static ZERO=new e(P.ZERO,P.ZERO);static z=c.z.union([c.z.object({start:P.z,end:P.z}).transform(t=>new e(t.start,t.end)),c.z.instanceof(e)]);static boundedZ=e.z.refine(({isValid:e})=>e,{message:`Time range start time must be before or equal to time range end time`}).refine(({end:e})=>e.valueOf()<=E,{message:`Time range end time must be less than or equal to the maximum value of an int64`}).refine(({start:e})=>e.valueOf()>=tt,{message:`Time range start time must be greater than or equal to the minimum value of an int64`});static sort(e,t){return P.sort(e.start,t.start)||P.sort(e.end,t.end)}static merge(...t){return e.max(...t.map(t=>new e(t).makeValid()))}},z=class e extends C{constructor(t){if(S(t)&&(t=t.value),t instanceof e||typeof t==`string`||typeof t.valueOf()==`string`)super(t.valueOf());else{let n=e.ARRAY_CONSTRUCTOR_DATA_TYPES.get(t.constructor.name);if(n==null)throw Error(`unable to find data type for ${t.toString()}`);super(n.valueOf())}}get Array(){let t=e.ARRAY_CONSTRUCTORS.get(this.toString());if(t==null)throw Error(`unable to find array constructor for ${this.valueOf()}`);return t}equals(e){return this.valueOf()===e.valueOf()}matches(...e){return e.some(e=>this.equals(e))}toString(t=!1){return t?e.SHORT_STRINGS.get(this.valueOf())??this.valueOf():this.valueOf()}get isVariable(){return this.equals(e.JSON)||this.equals(e.STRING)||this.equals(e.BYTES)}get isNumeric(){return!this.isVariable&&!this.equals(e.UUID)}get isInteger(){let e=this.toString();return e.startsWith(`int`)||e.startsWith(`uint`)}get isFloat(){return this.toString().startsWith(`float`)}get density(){let t=e.DENSITIES.get(this.toString());if(t==null)throw Error(`unable to find density for ${this.valueOf()}`);return t}get isUnsignedInteger(){return this.equals(e.UINT8)||this.equals(e.UINT16)||this.equals(e.UINT32)||this.equals(e.UINT64)}get isSignedInteger(){return this.equals(e.INT8)||this.equals(e.INT16)||this.equals(e.INT32)||this.equals(e.INT64)}canSafelyCastTo(t){return this.equals(t)?!0:!this.isNumeric||!t.isNumeric||this.isVariable||t.isVariable||this.isUnsignedInteger&&t.isSignedInteger?!1:this.isFloat?t.isFloat&&this.density.valueOf()<=t.density.valueOf():this.equals(e.INT32)&&t.equals(e.FLOAT64)||this.equals(e.INT8)&&t.equals(e.FLOAT32)?!0:this.isInteger&&t.isInteger?this.density.valueOf()<=t.density.valueOf()&&this.isUnsignedInteger===t.isUnsignedInteger:!1}canCastTo(e){return this.isNumeric&&e.isNumeric?!0:this.equals(e)}checkArray(e){return e.constructor===this.Array}get usesBigInt(){return e.BIG_INT_TYPES.some(e=>e.equals(this))}static UNKNOWN=new e(`unknown`);static FLOAT64=new e(`float64`);static FLOAT32=new e(`float32`);static INT64=new e(`int64`);static INT32=new e(`int32`);static INT16=new e(`int16`);static INT8=new e(`int8`);static UINT64=new e(`uint64`);static UINT32=new e(`uint32`);static UINT16=new e(`uint16`);static UINT8=new e(`uint8`);static TIMESTAMP=new e(`timestamp`);static UUID=new e(`uuid`);static STRING=new e(`string`);static JSON=new e(`json`);static BYTES=new e(`bytes`);static ARRAY_CONSTRUCTORS=new Map([[e.UINT8.toString(),Uint8Array],[e.UINT16.toString(),Uint16Array],[e.UINT32.toString(),Uint32Array],[e.UINT64.toString(),BigUint64Array],[e.FLOAT32.toString(),Float32Array],[e.FLOAT64.toString(),Float64Array],[e.INT8.toString(),Int8Array],[e.INT16.toString(),Int16Array],[e.INT32.toString(),Int32Array],[e.INT64.toString(),BigInt64Array],[e.TIMESTAMP.toString(),BigInt64Array],[e.STRING.toString(),Uint8Array],[e.JSON.toString(),Uint8Array],[e.UUID.toString(),Uint8Array],[e.BYTES.toString(),Uint8Array]]);static ARRAY_CONSTRUCTOR_DATA_TYPES=new Map([[Uint8Array.name,e.UINT8],[Uint16Array.name,e.UINT16],[Uint32Array.name,e.UINT32],[BigUint64Array.name,e.UINT64],[Float32Array.name,e.FLOAT32],[Float64Array.name,e.FLOAT64],[Int8Array.name,e.INT8],[Int16Array.name,e.INT16],[Int32Array.name,e.INT32],[BigInt64Array.name,e.INT64]]);static DENSITIES=new Map([[e.UINT8.toString(),L.BIT8],[e.UINT16.toString(),L.BIT16],[e.UINT32.toString(),L.BIT32],[e.UINT64.toString(),L.BIT64],[e.FLOAT32.toString(),L.BIT32],[e.FLOAT64.toString(),L.BIT64],[e.INT8.toString(),L.BIT8],[e.INT16.toString(),L.BIT16],[e.INT32.toString(),L.BIT32],[e.INT64.toString(),L.BIT64],[e.TIMESTAMP.toString(),L.BIT64],[e.STRING.toString(),L.UNKNOWN],[e.JSON.toString(),L.UNKNOWN],[e.UUID.toString(),L.BIT128],[e.BYTES.toString(),L.UNKNOWN]]);static ALL=[e.UNKNOWN,e.UINT8,e.UINT16,e.UINT32,e.UINT64,e.INT8,e.INT16,e.INT32,e.INT64,e.FLOAT32,e.FLOAT64,e.TIMESTAMP,e.UUID,e.STRING,e.JSON,e.BYTES];static SHORT_STRINGS=new Map([[e.UINT8.toString(),`u8`],[e.UINT16.toString(),`u16`],[e.UINT32.toString(),`u32`],[e.UINT64.toString(),`u64`],[e.INT8.toString(),`i8`],[e.INT16.toString(),`i16`],[e.INT32.toString(),`i32`],[e.INT64.toString(),`i64`],[e.FLOAT32.toString(),`f32`],[e.FLOAT64.toString(),`f64`],[e.TIMESTAMP.toString(),`ts`],[e.UUID.toString(),`uuid`],[e.STRING.toString(),`str`],[e.JSON.toString(),`json`],[e.BYTES.toString(),`bytes`]]);static BIG_INT_TYPES=[e.INT64,e.UINT64,e.TIMESTAMP];static z=c.z.union([c.z.string().transform(t=>new e(t)),c.z.instanceof(e)])},B=class e extends C{constructor(e){S(e)&&(e=e.value),super(e.valueOf())}largerThan(e){return S(e)&&(e=e.value),this.valueOf()>e.valueOf()}smallerThan(e){return S(e)&&(e=e.value),this.valueOf()<e.valueOf()}add(t){return S(t)&&(t=t.value),new e(k(this.valueOf(),t.valueOf()))}sub(t){return S(t)&&(t=t.value),new e(O(this.valueOf(),t.valueOf()))}mult(t){return new e(A(this.valueOf(),t))}div(t){return new e(j(this.valueOf(),t))}truncate(t){return new e(Math.trunc(this.valueOf()/new e(t).valueOf())*new e(t).valueOf())}remainder(t){return e.bytes(this.valueOf()%new e(t).valueOf())}get gigabytes(){return this.valueOf()/e.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/e.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/e.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/e.TERABYTE.valueOf()}toString(){let t=this.truncate(e.TERABYTE),n=this.truncate(e.GIGABYTE),r=this.truncate(e.MEGABYTE),i=this.truncate(e.KILOBYTE),a=this.truncate(e.BYTE),o=t,s=n.sub(t),c=r.sub(n),l=i.sub(r),u=a.sub(i),d=``;return o.isZero||(d+=`${o.terabytes}TB `),s.isZero||(d+=`${s.gigabytes}GB `),c.isZero||(d+=`${c.megabytes}MB `),l.isZero||(d+=`${l.kilobytes}KB `),(!u.isZero||d===``)&&(d+=`${u.valueOf()}B`),d.trim()}static bytes(t=1){return new e(t)}static BYTE=new e(1);static kilobytes(t=1){return e.bytes(new e(t).valueOf()*1e3)}static KILOBYTE=e.kilobytes(1);static megabytes(t=1){return e.kilobytes(new e(t).valueOf()*1e3)}static MEGABYTE=e.megabytes(1);static gigabytes(t=1){return e.megabytes(new e(t).valueOf()*1e3)}static GIGABYTE=e.gigabytes(1);static terabytes(t){return e.gigabytes(new e(t).valueOf()*1e3)}static TERABYTE=e.terabytes(1);static ZERO=new e(0);static z=c.z.union([c.z.number().transform(t=>new e(t)),c.z.instanceof(e)]);get isZero(){return this.valueOf()===0}};c.z.object({start:c.z.number(),end:c.z.number()}),c.z.union([c.z.instanceof(Uint8Array),c.z.instanceof(Uint16Array),c.z.instanceof(Uint32Array),c.z.instanceof(BigUint64Array),c.z.instanceof(Float32Array),c.z.instanceof(Float64Array),c.z.instanceof(Int8Array),c.z.instanceof(Int16Array),c.z.instanceof(Int32Array),c.z.instanceof(BigInt64Array)]);var Et=e=>{let t=typeof e;return t===`string`||t===`number`||t===`boolean`||t===`bigint`||e instanceof P||e instanceof F||e instanceof Date},Dt=(e,t,n,r=0)=>e.usesBigInt&&!t.usesBigInt?Number(n)-Number(r):!e.usesBigInt&&t.usesBigInt?BigInt(n.valueOf())-BigInt(r.valueOf()):O(n,r);R.z,P.z,F.z,I.z,B.z,z.z,R.boundedZ;var Ot=(e,t=!1)=>{let n=je(e)?`stringer`:typeof e,r;switch(n){case`string`:r=(e,t)=>e.localeCompare(t);break;case`stringer`:r=(e,t)=>e.toString().localeCompare(t.toString());break;case`number`:r=(e,t)=>Number(e)-Number(t);break;case`bigint`:r=(e,t)=>BigInt(e)-BigInt(t)>0n?1:-1;break;case`boolean`:r=(e,t)=>Number(e)-Number(t);break;case`undefined`:r=()=>0;break;default:return console.warn(`sortFunc: unknown type ${n}`),()=>-1}return t?kt(r):r},kt=e=>(t,n)=>e(n,t),At=(e,t=21)=>(n=t)=>{let r=``,i=n|0;for(;i--;)r+=e[Math.random()*e.length|0];return r},jt=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`,Mt=`0123456789${jt}`,Nt=At(jt,1),Pt=At(Mt,10),Ft=()=>`${Nt()}${Pt()}`,It=(e,t)=>n=>n instanceof t||typeof n==`object`&&!!n&&`discriminator`in n&&n.discriminator===e;c.z.object({x:lt.or(ft),y:ut.or(ft)});var Lt=c.z.object({x:lt,y:ut}),Rt=Object.freeze({x:`left`,y:`top`}),zt=Object.freeze({x:`right`,y:`top`}),Bt=Object.freeze({x:`left`,y:`bottom`}),Vt=Object.freeze({x:`right`,y:`bottom`}),Ht=Object.freeze({x:`center`,y:`center`}),Ut=Object.freeze({x:`center`,y:`top`}),Wt=Object.freeze({x:`center`,y:`bottom`}),Gt=Object.freeze({x:`right`,y:`center`}),Kt=Object.freeze({x:`left`,y:`center`});Object.freeze([Kt,Gt,Ut,Wt,Rt,zt,Bt,Vt,Ht]);var qt=(e,t)=>e.x===t.x&&e.y===t.y,Jt=e=>[e.x,e.y];c.z.enum([`top`,`right`,`bottom`,`left`]);var V=c.z.object({x:c.z.number(),y:c.z.number()}),Yt=c.z.union([c.z.number(),V,at,mt,ht,pt]),H=(e,t)=>{if(typeof e==`string`){if(t===void 0)throw Error(`The y coordinate must be given.`);return e===`x`?{x:t,y:0}:{x:0,y:t}}return typeof e==`number`?{x:e,y:t??e}:Array.isArray(e)?{x:e[0],y:e[1]}:`signedWidth`in e?{x:e.signedWidth,y:e.signedHeight}:`clientX`in e?{x:e.clientX,y:e.clientY}:`width`in e?{x:e.width,y:e.height}:{x:e.x,y:e.y}},U=Object.freeze({x:0,y:0});Object.freeze({x:1,y:1}),Object.freeze({x:1/0,y:1/0}),Object.freeze({x:NaN,y:NaN});var Xt=(e,t)=>{let n=H(e);return{x:n.x+t,y:n.y}},Zt=(e,t)=>{let n=H(e);return{x:n.x,y:n.y+t}},Qt=(e,t,n,...r)=>{if(typeof t==`string`){if(typeof n!=`number`)throw Error(`The value must be a number.`);return t===`x`?Xt(e,n):Zt(e,n)}if(typeof t==`object`&&`x`in t&&typeof t.x==`string`){let r=H(n),i=H(e);return t.x===`left`?r.x=-r.x:t.x===`center`&&(r.x=0),t.y===`top`?r.y=-r.y:t.y===`center`&&(r.y=0),{x:i.x+r.x,y:i.y+r.y}}return[e,t,n??U,...r].reduce((e,t)=>{let n=H(t);return{x:e.x+n.x,y:e.y+n.y}},U)},$t=c.z.union([c.z.number(),c.z.string()]);c.z.object({top:$t,left:$t,width:$t,height:$t}),c.z.object({left:c.z.number(),top:c.z.number(),right:c.z.number(),bottom:c.z.number()}),c.z.object({one:V,two:V,root:Lt});var W=(e,t,n=0,r=0,i)=>{let a={one:{...U},two:{...U},root:i??Rt};if(typeof e==`number`){if(typeof t!=`number`)throw Error(`Box constructor called with invalid arguments`);return a.one={x:e,y:t},a.two={x:a.one.x+n,y:a.one.y+r},a}return`one`in e&&`two`in e&&`root`in e?{...e,root:i??e.root}:(`getBoundingClientRect`in e&&(e=e.getBoundingClientRect()),`left`in e?(a.one={x:e.left,y:e.top},a.two={x:e.right,y:e.bottom},a):(a.one=e,t==null?a.two={x:a.one.x+n,y:a.one.y+r}:typeof t==`number`?a.two={x:a.one.x+t,y:a.one.y+n}:`width`in t?a.two={x:a.one.x+t.width,y:a.one.y+t.height}:`signedWidth`in t?a.two={x:a.one.x+t.signedWidth,y:a.one.y+t.signedHeight}:a.two=t,a))},en=(e,t)=>{let n=W(e);return{x:t.x===`center`?on(n).x:tn(n,t.x),y:t.y===`center`?on(n).y:tn(n,t.y)}},tn=(e,t)=>{let n=W(e),r=Jt(n.root).includes(t)?Math.min:Math.max;return ct.includes(t)?r(n.one.x,n.two.x):r(n.one.y,n.two.y)},nn=e=>{let t=W(e);return t.two.x-t.one.x},rn=e=>{let t=W(e);return t.two.y-t.one.y},an=e=>en(e,Rt),on=e=>Qt(an(e),{x:nn(e)/2,y:rn(e)/2}),sn=e=>{let t=W(e);return{lower:t.one.x,upper:t.two.x}},cn=e=>{let t=W(e);return{lower:t.one.y,upper:t.two.y}},ln=e=>typeof e!=`object`||!e?!1:`one`in e&&`two`in e&&`root`in e;c.z.union([mt,ht,V,at]);var un=(e,t,n)=>t!==void 0&&e<t?t:n!==void 0&&e>n?n:e;c.z.object({offset:Yt,scale:Yt}),c.z.object({offset:c.z.number(),scale:c.z.number()});var dn=e=>(t,n,r,i)=>n===`dimension`?[t,r]:[t,i?r-e:r+e],fn=e=>(t,n,r,i)=>[t,i?r/e:r*e],pn=e=>(t,n,r)=>{if(t===null)return[e,r];let{lower:i,upper:a}=t,{lower:o,upper:s}=e,c=a-i,l=s-o;return n===`dimension`?[e,l/c*r]:[e,(r-i)*(l/c)+o]},mn=e=>(t,n,r)=>[e,r],hn=()=>(e,t,n)=>{if(e===null)throw Error(`cannot invert without bounds`);if(t===`dimension`)return[e,n];let{lower:r,upper:i}=e;return[e,i-(n-r)]},gn=e=>(t,n,r)=>{let{lower:i,upper:a}=e;return r=un(r,i,a),[t,r]},_n=class e{ops=[];currBounds=null;currType=null;reversed=!1;constructor(){this.ops=[]}static translate(t){return new e().translate(t)}static magnify(t){return new e().magnify(t)}static scale(t,n){return new e().scale(t,n)}translate(e){let t=this.new(),n=dn(e);return n.type=`translate`,t.ops.push(n),t}magnify(e){let t=this.new(),n=fn(e);return n.type=`magnify`,t.ops.push(n),t}scale(e,t){let n=M(e,t),r=this.new(),i=pn(n);return i.type=`scale`,r.ops.push(i),r}clamp(e,t){let n=M(e,t),r=this.new(),i=gn(n);return i.type=`clamp`,r.ops.push(i),r}reBound(e,t){let n=M(e,t),r=this.new(),i=mn(n);return i.type=`re-bound`,r.ops.push(i),r}invert(){let e=hn();e.type=`invert`;let t=this.new();return t.ops.push(e),t}pos(e){return this.exec(`position`,e)}dim(e){return this.exec(`dimension`,e)}new(){let t=new e;return t.ops=this.ops.slice(),t.reversed=this.reversed,t}exec(e,t){return this.currBounds=null,this.ops.reduce(([t,n],r)=>r(t,e,n,this.reversed),[null,t])[1]}reverse(){let e=this.new();e.ops.reverse();let t=[];return e.ops.forEach((n,r)=>{if(n.type===`scale`||t.some(([e,t])=>r>=e&&r<=t))return;let i=e.ops.findIndex((e,t)=>e.type===`scale`&&t>r);i!==-1&&t.push([r,i])}),t.forEach(([t,n])=>{let r=e.ops.slice(t,n);r.unshift(e.ops[n]),e.ops.splice(t,n-t+1,...r)}),e.reversed=!e.reversed,e}get transform(){return{scale:this.dim(1),offset:this.pos(0)}}static IDENTITY=new e};(class e{x;y;currRoot;constructor(e=new _n,t=new _n,n=null){this.x=e,this.y=t,this.currRoot=n}static translate(t,n){return new e().translate(t,n)}static translateX(t){return new e().translateX(t)}static translateY(t){return new e().translateY(t)}static clamp(t){return new e().clamp(t)}static magnify(t){return new e().magnify(t)}static scale(t){return new e().scale(t)}static reBound(t){return new e().reBound(t)}translate(e,t){let n=H(e,t),r=this.copy();return r.x=this.x.translate(n.x),r.y=this.y.translate(n.y),r}translateX(e){let t=this.copy();return t.x=this.x.translate(e),t}translateY(e){let t=this.copy();return t.y=this.y.translate(e),t}magnify(e){let t=this.copy();return t.x=this.x.magnify(e.x),t.y=this.y.magnify(e.y),t}scale(e){let t=this.copy();if(ln(e)){let n=this.currRoot;return t.currRoot=e.root,n!=null&&!qt(n,e.root)&&(n.x!==e.root.x&&(t.x=t.x.invert()),n.y!==e.root.y&&(t.y=t.y.invert())),t.x=t.x.scale(sn(e)),t.y=t.y.scale(cn(e)),t}return t.x=t.x.scale(e.width),t.y=t.y.scale(e.height),t}reBound(e){let t=this.copy();return t.x=this.x.reBound(sn(e)),t.y=this.y.reBound(cn(e)),t}clamp(e){let t=this.copy();return t.x=this.x.clamp(sn(e)),t.y=this.y.clamp(cn(e)),t}copy(){let t=new e;return t.currRoot=this.currRoot,t.x=this.x,t.y=this.y,t}reverse(){let e=this.copy();return e.x=this.x.reverse(),e.y=this.y.reverse(),e}pos(e){return{x:this.x.pos(e.x),y:this.y.pos(e.y)}}dim(e){return{x:this.x.dim(e.x),y:this.y.dim(e.y)}}box(e){return W(this.pos(e.one),this.pos(e.two),0,0,this.currRoot??e.root)}get transform(){return{scale:this.dim({x:1,y:1}),offset:this.pos({x:0,y:0})}}static IDENTITY=new e}),V.extend({root:Lt,units:c.default.object({x:c.default.enum([`px`,`decimal`]),y:c.default.enum([`px`,`decimal`])})}).partial({root:!0,units:!0});var vn=c.z.enum([`static`,`dynamic`]),yn=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;function bn(e){return typeof e==`string`&&yn.test(e)}var G=[];for(let e=0;e<256;++e)G.push((e+256).toString(16).slice(1));function xn(e,t=0){return(G[e[t+0]]+G[e[t+1]]+G[e[t+2]]+G[e[t+3]]+`-`+G[e[t+4]]+G[e[t+5]]+`-`+G[e[t+6]]+G[e[t+7]]+`-`+G[e[t+8]]+G[e[t+9]]+`-`+G[e[t+10]]+G[e[t+11]]+G[e[t+12]]+G[e[t+13]]+G[e[t+14]]+G[e[t+15]]).toLowerCase()}function Sn(e,t=0){let n=xn(e,t);if(!bn(n))throw TypeError(`Stringified UUID is invalid`);return n}typeof crypto<`u`&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);var Cn=(e,t)=>Sn(e,t),K=-1,wn={[Symbol.iterator]:()=>wn,next:()=>({done:!0,value:void 0})},Tn=c.z.string().transform(e=>new Uint8Array(atob(e).split(``).map(e=>e.charCodeAt(0))).buffer),En=c.z.union([c.z.null(),c.z.undefined()]).transform(()=>new Uint8Array().buffer),q=4,Dn=(e,t)=>{if(e===`number`&&!t.isNumeric)throw Error(`cannot convert series of type ${t.toString()} to number`);if(e===`bigint`&&!t.usesBigInt)throw Error(`cannot convert series of type ${t.toString()} to bigint`)},On=`sy_x_telem_series`,kn=class e{key;discriminator=On;dataType;sampleOffset;gl;_data;timeRange=R.ZERO;alignment=0n;alignmentMultiple=1n;cachedMin;cachedMax;writePos=K;_refCount=0;cachedLength;_cachedIndexes;static crudeZ=c.z.object({timeRange:R.z.optional(),dataType:z.z,alignment:c.z.coerce.bigint().optional(),data:c.z.union([Tn,En,c.z.instanceof(ArrayBuffer),c.z.instanceof(Uint8Array)]),glBufferUsage:vn.default(`static`).optional()});static z=e.crudeZ.transform(t=>new e(t));constructor(e){An(e)&&(e={data:e}),e.data??=[];let{dataType:t,timeRange:n,sampleOffset:r=0,glBufferUsage:i=`static`,alignment:a=0n,alignmentMultiple:o=1n,key:s=Ft(),data:c}=e;if(jn(c)){let e=c;this.key=e.key,this.dataType=e.dataType,this.sampleOffset=e.sampleOffset,this.gl=e.gl,this._data=e._data,this.timeRange=e.timeRange,this.alignment=e.alignment,this.alignmentMultiple=e.alignmentMultiple,this.cachedMin=e.cachedMin,this.cachedMax=e.cachedMax,this.writePos=e.writePos,this._refCount=e._refCount,this.cachedLength=e.cachedLength;return}let l=Et(c),u=Array.isArray(c);if(t!=null)this.dataType=new z(t);else if(c instanceof ArrayBuffer)throw Error(`cannot infer data type from an ArrayBuffer instance when constructing a Series. Please provide a data type.`);else if(u||l){let e=c;if(!l){if(c.length===0)throw Error(`cannot infer data type from a zero length JS array when constructing a Series. Please provide a data type.`);e=c[0]}if(typeof e==`string`)this.dataType=z.STRING;else if(typeof e==`number`)this.dataType=z.FLOAT64;else if(typeof e==`bigint`)this.dataType=z.INT64;else if(typeof e==`boolean`)this.dataType=z.UINT8;else if(e instanceof P||e instanceof Date||e instanceof P)this.dataType=z.TIMESTAMP;else if(typeof e==`object`)this.dataType=z.JSON;else throw Error(`cannot infer data type of ${typeof e} when constructing a Series from a JS array`)}else this.dataType=new z(c);if(!u&&!l)this._data=c;else if(u&&c.length===0)this._data=new this.dataType.Array([]).buffer;else{let e=l?[c]:c,t=e[0];if((t instanceof P||t instanceof Date||t instanceof F)&&(e=e.map(e=>new P(e).valueOf())),this.dataType.equals(z.STRING)){this.cachedLength=e.length;let t=e.map(e=>new TextEncoder().encode(e)),n=t.reduce((e,t)=>e+q+t.byteLength,0),r=new ArrayBuffer(n),i=new DataView(r),a=new Uint8Array(r),o=0;for(let e of t)i.setUint32(o,e.byteLength,!0),o+=q,a.set(e,o),o+=e.byteLength;this._data=r}else if(this.dataType.equals(z.JSON)){this.cachedLength=e.length;let t=e.map(e=>new TextEncoder().encode(St.encodeString(e))),n=t.reduce((e,t)=>e+q+t.byteLength,0),r=new ArrayBuffer(n),i=new DataView(r),a=new Uint8Array(r),o=0;for(let e of t)i.setUint32(o,e.byteLength,!0),o+=q,a.set(e,o),o+=e.byteLength;this._data=r}else this.dataType.usesBigInt&&typeof t==`number`?this._data=new this.dataType.Array(e.map(e=>BigInt(Math.round(e)))).buffer:!this.dataType.usesBigInt&&typeof t==`bigint`?this._data=new this.dataType.Array(e.map(Number)).buffer:this._data=new this.dataType.Array(e).buffer}this.key=s,this.alignment=a,this.alignmentMultiple=o,this.sampleOffset=r??0,this.timeRange=n??R.ZERO,this.gl={control:null,buffer:null,prevBuffer:0,bufferUsage:i}}static alloc({capacity:t,dataType:n,...r}){if(t===0)throw Error(`[Series] - cannot allocate an array of length 0`);let i=new e({data:new new z(n).Array(t).buffer,dataType:n,...r});return i.writePos=0,i}get refCount(){return this._refCount}acquire(e){this._refCount++,e!=null&&this.updateGLBuffer(e)}release(){this._refCount--,this.refCount===0&&this.gl.control!=null?this.maybeGarbageCollectGLBuffer(this.gl.control):this.refCount<0&&console.warn(`cannot release a series with a negative reference count`)}write(e){if(!e.dataType.equals(this.dataType))throw Error(`buffer must be of the same type as this array`);return this.dataType.isVariable?this.writeVariable(e):this.writeFixed(e)}writeVariable(e){if(this.writePos===K)return 0;let t=this.byteCapacity.valueOf()-this.writePos,n=e.buffer,r=e.byteLength.valueOf(),i=new DataView(n),a=0,o=0;for(;a+q<=r;){let e=q+i.getUint32(a,!0);if(a+e>t)break;a+=e,o++}if(a===0)return 0;let s=e.subBytes(0,a);return this.writeToUnderlyingData(s),this.writePos+=a,this.cachedLength=(this.cachedLength??0)+o,this._cachedIndexes=void 0,o}writeFixed(e){if(this.writePos===K)return 0;let t=this.capacity-this.writePos,n=e.sub(0,t);return this.writeToUnderlyingData(n),this.cachedLength=void 0,this.maybeRecomputeMinMax(n),this.writePos+=n.length,n.length}writeToUnderlyingData(e){this.underlyingData.set(e.data,this.writePos)}get buffer(){return typeof this._data==`object`&&`buffer`in this._data?this._data.buffer:this._data}get underlyingData(){return new this.dataType.Array(this._data)}get data(){return this.writePos===K?this.underlyingData:new this.dataType.Array(this._data,0,this.writePos)}toStrings(){if(this.dataType.isVariable){let e=[],t=this.buffer,n=this.byteLength.valueOf(),r=new DataView(t),i=new TextDecoder,a=0;for(;a+q<=n;){let n=r.getUint32(a,!0);a+=q,e.push(i.decode(new Uint8Array(t,a,n))),a+=n}return e}return Array.from(this).map(e=>e.toString())}parseJSON(e){if(!this.dataType.equals(z.JSON))throw Error(`cannot parse non-JSON series as JSON`);return this.toStrings().map(t=>e.parse(St.decodeString(t)))}get byteCapacity(){return new B(this.underlyingData.byteLength)}get capacity(){return this.dataType.isVariable?this.byteCapacity.valueOf():this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===K?this.byteCapacity:this.dataType.isVariable?new B(this.writePos):this.dataType.density.size(this.writePos)}get length(){return this.cachedLength==null?this.dataType.isVariable?this.calculateCachedLength():this.writePos===K?this.byteCapacity.valueOf()/this.dataType.density.valueOf():this.writePos:this.cachedLength}calculateCachedLength(){if(!this.dataType.isVariable)throw Error(`cannot calculate length of a non-variable length data type`);let e=0,t=[],n=this.buffer,r=this.byteLength.valueOf(),i=new DataView(n),a=0;for(;a+q<=r;){let n=i.getUint32(a,!0);a+=q,t.push(a),a+=n,e++}return this._cachedIndexes=t,this.cachedLength=e,e}convert(t,n=0){if(this.dataType.equals(t))return this;let r=new t.Array(this.length);for(let e=0;e<this.length;e++)r[e]=Dt(this.dataType,t,this.data[e],n);return new e({data:r.buffer,dataType:t,timeRange:this.timeRange,sampleOffset:n,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment})}calcRawMax(){return this.length===0?-1/0:(this.dataType.equals(z.TIMESTAMP)?this.cachedMax=this.data[this.data.length-1]:(this.dataType.usesBigInt,this.cachedMax=this.data.reduce((e,t)=>e>t?e:t)),this.cachedMax)}get max(){return this.calcMax()}calcMax(){if(this.dataType.isVariable)throw Error(`cannot calculate maximum on a variable length data type`);return this.writePos===0?-1/0:(this.cachedMax??=this.calcRawMax(),k(this.cachedMax,this.sampleOffset))}calcRawMin(){return this.length===0?1/0:(this.dataType.equals(z.TIMESTAMP)?this.cachedMin=this.data[0]:(this.dataType.usesBigInt,this.cachedMin=this.data.reduce((e,t)=>e<t?e:t)),this.cachedMin)}get min(){return this.calcMin()}calcMin(){if(this.dataType.isVariable)throw Error(`cannot calculate minimum on a variable length data type`);return this.writePos===0?1/0:(this.cachedMin??=this.calcRawMin(),k(this.cachedMin,this.sampleOffset))}get bounds(){return M(Number(this.min),Number(this.max),{makeValid:!1})}maybeRecomputeMinMax(e){if(this.cachedMin!=null){let t=e.cachedMin??e.calcRawMin();t<this.cachedMin&&(this.cachedMin=t)}if(this.cachedMax!=null){let t=e.cachedMax??e.calcRawMax();t>this.cachedMax&&(this.cachedMax=t)}}atAlignment(e,t){let n=Number((e-this.alignment)/this.alignmentMultiple);if(n<0||n>=this.length){if(t===!0)throw Error(`[series] - no value at index ${n}`);return}return this.at(n,t)}at(e,t=!1){if(this.dataType.isVariable)return this.atVariable(e,t??!1);if(this.dataType.equals(z.UUID))return this.atUUID(e,t);e<0&&(e=this.length+e);let n=this.data[e];if(n==null){if(t===!0)throw Error(`[series] - no value at index ${e}`);return}return k(n,this.sampleOffset)}atUUID(e,t){e<0&&(e=this.length+e);let n=Cn(new Uint8Array(this.buffer,e*this.dataType.density.valueOf()));if(n==null){if(t)throw Error(`[series] - no value at index ${e}`);return}return n}atVariable(e,t){let n=0,r=0,i=this.buffer,a=new DataView(i);if(this._cachedIndexes!=null){if(e<0&&(e=this._cachedIndexes.length+e),e<0||e>=this._cachedIndexes.length){if(t)throw Error(`[series] - no value at index ${e}`);return}n=this._cachedIndexes[e],r=a.getUint32(n-q,!0)}else{e<0&&(e=this.length+e);let i=this.byteLength.valueOf(),o=0,s=!1;for(;o+q<=i;){let t=a.getUint32(o,!0);if(o+=q,e===0){n=o,r=t,s=!0;break}o+=t,e--}if(!s){if(t)throw Error(`[series] - no value at index ${e}`);return}}let o=new Uint8Array(i,n,r);return this.dataType.equals(z.STRING)?new TextDecoder().decode(o):ne(JSON.parse(new TextDecoder().decode(o)))}binarySearch(e){let t=0,n=this.length-1,r=Ot(e);for(;t<=n;){let i=Math.floor((t+n)/2),a=r(this.at(i,!0),e);if(a===0)return i;a<0?t=i+1:n=i-1}return t}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals(z.FLOAT32)&&!this.dataType.equals(z.UINT8))throw Error(`Only FLOAT32 and UINT8 arrays can be used in WebGL`);let{buffer:t,bufferUsage:n,prevBuffer:r}=this.gl;if(t??(this.gl.buffer=e.createBuffer()),this.writePos!==r)if(e.bindBuffer(e.ARRAY_BUFFER,this.gl.buffer),this.writePos!==K){r===0&&e.bufferData(e.ARRAY_BUFFER,this.byteCapacity.valueOf(),e.STATIC_DRAW);let t=this.dataType.density.size(r).valueOf(),n=this.underlyingData.slice(this.gl.prevBuffer,this.writePos);e.bufferSubData(e.ARRAY_BUFFER,t,n.buffer),this.gl.prevBuffer=this.writePos}else e.bufferData(e.ARRAY_BUFFER,this.buffer,n===`static`?e.STATIC_DRAW:e.DYNAMIC_DRAW),this.gl.prevBuffer=K}as(e){return Dn(e,this.dataType),this}get digest(){return{key:this.key,dataType:this.dataType.toString(),sampleOffset:this.sampleOffset,alignment:{lower:Ln(this.alignmentBounds.lower),upper:Ln(this.alignmentBounds.upper),multiple:this.alignmentMultiple},timeRange:this.timeRange.toString(),length:this.length,capacity:this.capacity}}get alignmentBounds(){return M(this.alignment,this.alignment+BigInt(this.length)*this.alignmentMultiple)}maybeGarbageCollectGLBuffer(e){this.gl.buffer!=null&&(e.deleteBuffer(this.gl.buffer),this.gl.buffer=null,this.gl.prevBuffer=0,this.gl.control=null)}get glBuffer(){if(this.gl.buffer==null)throw Error(`gl buffer not initialized`);return this.gl.prevBuffer!==this.writePos&&console.warn(`buffer not updated`),this.gl.buffer}[Symbol.iterator](){if(this.dataType.isVariable){let e=new Nn(this);return this.dataType.equals(z.JSON)?new Pn(e):e}return this.dataType.equals(z.UUID)?new Fn(this):new In(this)}slice(e,t){return this.sliceSub(!1,e,t)}sub(e,t){return this.sliceSub(!0,e,t)}subIterator(e,t){return new Mn(this,e,t??this.length)}subAlignmentIterator(e,t){let n=Math.ceil(Number(e-this.alignment)/Number(this.alignmentMultiple)),r=Math.ceil(Number(t-this.alignment)/Number(this.alignmentMultiple));return new Mn(this,n,r)}subBytes(t,n){return t>=0&&(n==null||n>=this.byteLength.valueOf())?this:new e({data:this.data.subarray(t,n),dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(t)})}sliceSub(t,n,r){if(n<=0&&(r==null||r>=this.length))return this;let i;return i=t?this.data.subarray(n,r):this.data.slice(n,r),new e({data:i,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(n)})}reAlign(t){return new e({data:this.buffer,dataType:this.dataType,timeRange:R.ZERO,sampleOffset:this.sampleOffset,glBufferUsage:`static`,alignment:t})}toString(){let e=`Series(${this.dataType.toString()} ${this.length} [`;if(this.length<=10)e+=Array.from(this).map(e=>e.toString());else{for(let t=0;t<5;t++)e+=`${this.at(t)?.toString()}`,e+=`,`;e+=`...,`;for(let t=-5;t<0;t++)e+=this.at(t)?.toString(),t<-1&&(e+=`,`)}return e+=`])`,e}},An=e=>e==null?!1:Array.isArray(e)||e instanceof ArrayBuffer||ArrayBuffer.isView(e)&&!(e instanceof DataView)||e instanceof kn?!0:Et(e),jn=It(On,kn),Mn=class{series;end;index;constructor(e,t,n){this.series=e;let r=M(0,e.length+1);this.end=_t(r,n),this.index=_t(r,t)}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}},Nn=class{series;byteOffset;decoder;view;constructor(e){if(!e.dataType.isVariable)throw Error(`cannot create a variable series iterator for a non-variable series`);this.series=e,this.byteOffset=0,this.decoder=new TextDecoder,this.view=new DataView(e.buffer)}next(){let e=this.series.byteLength.valueOf();if(this.byteOffset+q>e)return{done:!0,value:void 0};let t=this.view.getUint32(this.byteOffset,!0);this.byteOffset+=q;let n=this.decoder.decode(new Uint8Array(this.series.buffer,this.byteOffset,t));return this.byteOffset+=t,{done:!1,value:n}}},Pn=class e{wrapped;static schema=c.z.record(c.z.string(),c.z.unknown());constructor(e){this.wrapped=e}next(){let t=this.wrapped.next();return t.done===!0?{done:!0,value:void 0}:{done:!1,value:St.decodeString(t.value,e.schema)}}},Fn=class{series;index;data;density;constructor(e){if(!e.dataType.equals(z.UUID))throw Error(`cannot create a UUID series iterator for a non-UUID series`);this.series=e,this.index=0,this.data=new Uint8Array(e.buffer),this.density=z.UUID.density.valueOf()}next(){if(this.index>=this.series.length)return{done:!0,value:void 0};let e=Cn(this.data,this.index*this.density);return this.index++,{done:!1,value:e}}},In=class{series;index;constructor(e){this.series=e,this.index=0}next(){return this.index>=this.series.length?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}},Ln=e=>({domain:e>>32n,sample:e&4294967295n}),Rn=async e=>await new Promise(t=>setTimeout(t,F.fromMilliseconds(e).milliseconds)),zn=u({Breaker:()=>Bn,breakerConfigZ:()=>Vn}),Bn=class{config;retries;interval;constructor(e){this.config={baseInterval:new F(e?.baseInterval??F.seconds(1)),maxRetries:e?.maxRetries??5,scale:e?.scale??1,sleepFn:e?.sleepFn??Rn},this.retries=0,this.interval=new F(this.config.baseInterval)}async wait(){let{maxRetries:e,scale:t,sleepFn:n}=this.config;return this.retries>=e?!1:(await n(this.interval),this.interval=this.interval.mult(t),this.retries++,!0)}get retryMessage(){return`breaker triggered ${this.retries+1}/${this.config.maxRetries} times, retrying in ${this.interval.toString()}`}reset(){this.retries=0,this.interval=this.config.baseInterval}},Vn=c.z.object({baseInterval:F.z.optional(),maxRetries:c.z.number().optional(),scale:c.z.number().optional()}),Hn=c.z.string().regex(/^#?([0-9a-f]{6}|[0-9a-f]{8})$/i),J=vt,Un=c.z.number().min(0).max(1),Wn=c.z.tuple([J,J,J,Un]),Gn=c.z.tuple([J,J,J]),Kn=c.z.object({rgba255:Wn}),qn=c.z.object({r:J,g:J,b:J,a:Un}),Jn=c.z.number().min(0).max(360),Yn=c.z.number().min(0).max(100),Xn=c.z.number().min(0).max(100),Zn=c.z.tuple([Jn,Yn,Xn,Un]),Qn=c.z.union([Hn,Gn,Wn,Zn,Kn,qn]),$n=Qn.transform(e=>er(e)),er=(e,t=1)=>{if(e=Qn.parse(e),typeof e==`string`)return tr(e,t);if(Array.isArray(e)){if(e.length<3||e.length>4)throw Error(`Invalid color: [${e.join(`, `)}]`);return e.length===3?[...e,t]:e}return`a`in e&&`r`in e?[e.r,e.g,e.b,e.a]:e.rgba255},tr=(e,t=1)=>(e=Hn.parse(e),e=nr(e),[Y(e,0),Y(e,2),Y(e,4),e.length===8?Y(e,6)/255:t]),Y=(e,t)=>parseInt(e.slice(t,t+2),16),nr=e=>e.startsWith(`#`)?e.slice(1):e;er(`#000000`),er(`#ffffff`);var rr=c.z.object({key:c.z.string(),color:Qn,position:c.z.number(),switched:c.z.boolean().optional()});c.z.array(rr);var ir=c.z.object({key:c.z.string(),name:c.z.string(),color:$n});c.z.object({key:c.z.string(),name:c.z.string(),swatches:c.z.array(ir)});var ar=function(e){return e[e.exclusive=0]=`exclusive`,e[e.shared=1]=`shared`,e}({});c.z.enum(ar),c.z.object({key:c.z.string(),name:c.z.string(),group:c.z.uint32().optional()}),c.z.string().regex(/^(?:$|(?:\/(?:[^~/]|~0|~1)*)+)$/,`must be a valid JSON pointer (RFC 6901)`),c.z.union([c.z.string(),c.z.number(),c.z.boolean(),c.z.null()]),c.z.enum([`string`,`number`,`boolean`,`null`]),c.z.object({key:c.z.string(),value:c.z.string()});var or=c.z.uuid();c.z.object({key:or,name:c.z.string().min(1),color:$n}).partial({key:!0}),c.z.string().regex(/^\d+\.\d+\.\d+(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$/),c.z.enum([`standard`,`scientific`,`engineering`]);var sr=c.z.union([c.z.string(),c.z.number()]),cr=()=>c.z.record(sr,c.z.unknown());typeof process<`u`&&process.versions!=null&&process.versions.node!=null||typeof window>`u`||window.document;var lr=[`macOS`,`Windows`,`Linux`],ur=[`macos`,`windows`,`linux`],dr={macos:`macOS`,windows:`Windows`,linux:`Linux`};c.z.enum(lr).or(c.z.enum(ur).transform(e=>dr[e])),c.z.object({message:c.z.string().optional(),description:c.z.string().optional(),details:cr().optional()}),c.z.object({stack:c.z.string(),error:c.z.instanceof(Error)}).and(cr()),c.z.enum([`success`,`info`,`warning`,`error`,`loading`,`disabled`]),c.z.literal(`success`),c.z.literal(`info`),c.z.literal(`warning`),c.z.literal(`error`),c.z.literal(`loading`),c.z.literal(`disabled`);var fr=(...e)=>e.map(pr).join(``),pr=e=>(e.endsWith(`/`)||(e+=`/`),e.startsWith(`/`)&&(e=e.slice(1)),e),mr=e=>e.endsWith(`/`)?e.slice(0,-1):e,hr=(e,t=``)=>e===null?``:`?${Object.entries(e).filter(([,e])=>e==null?!1:Array.isArray(e)?e.length>0:!0).map(([e,n])=>`${t}${e}=${n}`).join(`&`)}`,gr=class e{protocol;host;port;path;constructor({host:e,port:t,protocol:n=``,pathPrefix:r=``}){this.protocol=n,this.host=e,this.port=t,this.path=pr(r)}replace(t){return new e({host:t.host??this.host,port:t.port??this.port,protocol:t.protocol??this.protocol,pathPrefix:t.pathPrefix??this.path})}child(t){return new e({...this,pathPrefix:fr(this.path,t)})}toString(){return mr(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}static UNKNOWN=new e({host:`unknown`,port:0})},X=class extends v.createTyped(`freighter`){},Z=class extends X.sub(`eof`){constructor(){super(`EOF`)}},Q=class extends X.sub(`stream_closed`){constructor(){super(`StreamClosed`)}},$=class extends X.sub(`unreachable`){url;constructor(e={}){let{message:t=`Unreachable`,url:n=gr.UNKNOWN}=e;super(t),this.url=n}};v.register({encode:e=>{if(!e.type.startsWith(X.TYPE))return null;if(Z.matches(e))return{type:Z.TYPE,data:`EOF`};if(Q.matches(e))return{type:Q.TYPE,data:`StreamClosed`};if($.matches(e))return{type:$.TYPE,data:`Unreachable`};throw Error(`Unknown error type: ${e.type}: ${e.message}`)},decode:e=>{if(!e.type.startsWith(X.TYPE))return null;switch(e.type){case Z.TYPE:return new Z;case Q.TYPE:return new Q;case $.TYPE:return new $;default:throw new v.Unknown(`Unknown error type: ${e.data}`)}}});var _r=class{middleware=[];use(...e){this.middleware.push(...e)}async executeMiddleware(e,t){let n=0,r=async e=>{if(n===this.middleware.length)return await t(e);let i=this.middleware[n];return n++,await i(e,r)};return await r(e)}},vr=`Content-Type`,yr=new Set([`ECONNREFUSED`,`ECONNRESET`,`ETIMEDOUT`,`EPIPE`,`UND_ERR_CONNECT_TIMEOUT`,`UND_ERR_SOCKET`]),br=e=>{let t=e?.cause?.code??e?.code??e?.errno;if(typeof t==`string`&&yr.has(t))return!0;if(e.name===`TypeError`){let t=String(e.message||``).toLowerCase();if(/load failed|failed to fetch|networkerror|network error/.test(t))return typeof navigator<`u`&&navigator.onLine,!0}return e?.name===`AbortError`||e?.code,!1},xr=400,Sr=class extends _r{endpoint;encoder;constructor(e,t,n=!1){return super(),this.endpoint=e.replace({protocol:n?`https`:`http`}),this.encoder=t,new Proxy(this,{get:(e,t,n)=>t===`endpoint`?this.endpoint:Reflect.get(e,t,n)})}get headers(){return{[vr]:this.encoder.contentType}}async send(e,t,n,r){let i=null,a=this.endpoint.child(e),o={};o.method=`POST`,o.body=this.encoder.encode(t,n);let[,s]=await this.executeMiddleware({target:a.toString(),protocol:this.endpoint.protocol,params:{},role:`client`},async e=>{let t={...e,params:{}};o.headers={...this.headers,...e.params};let n;try{n=await fetch(e.target,o)}catch(e){if(!(e instanceof Error))throw e;return[t,br(e)?new $({url:a}):e]}let s=await n.arrayBuffer();if(n?.ok)return r!=null&&(i=this.encoder.decode(s,r)),[t,null];try{if(n.status!==xr)return[t,Error(n.statusText)];let e=this.encoder.decode(s,v.payloadZ);return[t,v.decode(e)]}catch(e){return[t,Error(`[freighter] - failed to decode error: ${n.statusText}: ${e.message}`)]}});if(s!=null)return[null,s];if(i==null)throw Error(`Response must be defined`);return[i,null]}},Cr=(e,t)=>{class n{wrapped;constructor(e){this.wrapped=e}use(...e){this.wrapped.use(...e)}async send(e,n,r,i){let a=new zn.Breaker(t);do{let[t,o]=await this.wrapped.send(e,n,r,i);if(o==null)return[t,null];if(!$.matches(o))return[null,o];if(console.warn(`[freighter] ${a.retryMessage}`,o),!await a.wait())return[t,o]}while(!0)}}return new n(e)},wr=async(e,t,n,r,i)=>{let[a,o]=await e.send(t,n,r,i);if(o!=null)throw o;return a},Tr=c.z.object({type:c.z.enum([`data`,`close`,`open`]),payload:c.z.unknown(),error:c.z.optional(v.payloadZ)}),Er=class{codec;reqSchema;resSchema;ws;serverClosed;sendClosed;receiveDataQueue=[];receiveCallbacksQueue=[];constructor(e,t,n,r){this.codec=t,this.reqSchema=n,this.resSchema=r,this.ws=e,this.sendClosed=!1,this.serverClosed=null,this.listenForMessages()}async receiveOpenAck(){let e=await this.receiveMsg();if(e.type!==`open`){if(e.error==null)throw Error(`Message error must be defined`);return v.decode(e.error)}return null}send(e){if(this.serverClosed!=null)return new Z;if(this.sendClosed)throw new Q;return this.ws.send(this.codec.encode({type:`data`,payload:e})),null}async receive(){if(this.serverClosed!=null)return[null,this.serverClosed];let e=await this.receiveMsg();if(e.type===`close`){if(e.error==null||(this.serverClosed=v.decode(e.error),this.serverClosed==null))throw Error(`Message error must be defined`);return[null,this.serverClosed]}return[this.resSchema.parse(e.payload),null]}received(){return this.receiveDataQueue.length!==0}closeSend(){if(this.sendClosed||this.serverClosed!=null)return;let e={type:`close`};try{this.ws.send(this.codec.encode(e))}finally{this.sendClosed=!0}}async receiveMsg(){return this.receiveDataQueue.shift()??await new Promise((e,t)=>this.receiveCallbacksQueue.push({resolve:e,reject:t}))}addMessage(e){let t=this.receiveCallbacksQueue.shift();t==null?this.receiveDataQueue.push(e):t.resolve(e)}listenForMessages(){this.ws.onmessage=this.onMessage.bind(this),this.ws.onclose=this.onClose.bind(this)}onMessage(e){this.addMessage(this.codec.decode(e.data,Tr))}onClose(e){this.addMessage({type:`close`,error:{type:e.code===Or?Z.TYPE:Q.TYPE,data:``}})}},Dr=`freighterctx`,Or=1e3,kr=class e extends _r{baseUrl;encoder;secure;static MESSAGE_TYPE=`arraybuffer`;constructor(e,t,n=!1){super(),this.secure=n,this.baseUrl=e.replace({protocol:n?`wss`:`ws`}),this.encoder=t}withCodec(t){let n=new e(this.baseUrl,t,this.secure);return n.use(...this.middleware),n}async stream(t,n,r){let i,[,a]=await this.executeMiddleware({target:t,protocol:`websocket`,params:{},role:`client`},async a=>{let o=new WebSocket(this.buildURL(t,a)),s={...a,params:{}};o.binaryType=e.MESSAGE_TYPE;let c=await this.wrapSocket(o,n,r);return c instanceof Error?[s,c]:(i=c,[s,null])});if(a!=null)throw a;return i}buildURL(e,t){let n=hr({[vr]:this.encoder.contentType,...t.params},Dr);return this.baseUrl.child(e).toString()+n}async wrapSocket(e,t,n){return await new Promise(r=>{e.onopen=()=>{let i=new Er(e,this.encoder,t,n);i.receiveOpenAck().then(e=>{r(e??i)}).catch(e=>r(e))},e.onerror=e=>{r(Error(e.message))}})}};exports.EOF=Z,exports.HTTPClient=Sr,exports.StreamClosed=Q,exports.Unreachable=$,exports.WebSocketClient=kr,exports.sendRequired=wr,exports.unaryWithBreaker=Cr;