@synnaxlabs/freighter 0.53.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,17 +1,21 @@
1
1
 
2
- > @synnaxlabs/freighter@0.53.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 v7.3.1 building client environment for production...
7
- transforming...
8
- ✓ 7 modules transformed.
6
+ vite v8.0.8 building client environment for production...
7
+ 
9
8
  rendering chunks...
10
9
  
11
10
  [vite:dts] Start generate declaration files...
12
- computing gzip size...
13
- dist/freighter.js 117.69 kB │ gzip: 27.50 kB
14
- [vite:dts] Declaration files built in 1692ms.
11
+ [vite:dts] Declaration files built in 1755ms.
15
12
  
16
- dist/freighter.cjs 57.60 kB │ gzip: 17.05 kB
17
- ✓ built in 2.06s
13
+ computing gzip size...
14
+ dist/freighter.js 86.57 kB gzip: 23.27 kB
15
+
16
+ 
17
+ rendering chunks...
18
+ computing gzip size...
19
+ dist/freighter.cjs 70.52 kB │ gzip: 21.29 kB
20
+
21
+ ✓ built in 2.01s
@@ -1,6 +1,11 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("zod"),Ke=r=>{const e=r.replace(/_[a-z]/g,t=>t[1].toUpperCase());return e.length>1&&e[0]===e[0].toUpperCase()&&e[1]===e[1].toUpperCase()||e.length===0?e:e[0].toLowerCase()+e.slice(1)},Ne=r=>{const e=(t,n=se)=>{if(typeof t=="string")return r(t);if(Array.isArray(t))return t.map(c=>e(c,n));if(!te(t))return t;n=et(n);const i={},o=t;return"toJSON"in o&&typeof o.toJSON=="function"?e(o.toJSON(),n):(Object.keys(o).forEach(c=>{let f=o[c];const w=r(c);n.recursive&&(te(f)?pe(f)||(f=e(f,n)):n.recursiveInArray&&ye(f)&&(f=[...f].map(h=>{let g=h;return te(h)?pe(g)||(g=e(h,n)):ye(h)&&(g=e({key:h},n).key),g}))),i[w]=f}),i)};return e},Ee=Ne(Ke),Xe=r=>r.replace(/([a-z0-9])([A-Z])/g,(e,t,n)=>`${t}_${n.toLowerCase()}`),Qe=Ne(Xe),_e=[Number,String,Uint8Array],se={recursive:!0,recursiveInArray:!0},et=(r=se)=>(r.recursive==null?r=se:r.recursiveInArray??=!1,r),ye=r=>r!=null&&Array.isArray(r),te=r=>r!=null&&typeof r=="object"&&!Array.isArray(r),pe=r=>_e.some(e=>r instanceof e);class tt{contentType="application/json";decoder;encoder;constructor(){this.decoder=new TextDecoder,this.encoder=new TextEncoder}encode(e){return this.encoder.encode(this.encodeString(e))}decode(e,t){return this.decodeString(this.decoder.decode(e),t)}decodeString(e,t){const n=JSON.parse(e),i=Ee(n);return t!=null?t.parse(i):i}encodeString(e){const t=Qe(e);return JSON.stringify(t,(n,i)=>ArrayBuffer.isView(i)?Array.from(i):typeof i=="bigint"?i.toString():i)}}const ie=new tt,E=r=>r!=null&&typeof r=="object"&&"value"in r;class F{value;constructor(e){this.value=e}valueOf(){return this.value}toJSON(){return this.value}toString(){return this.value.toString()}}const rt=r=>r!=null&&typeof r=="object"&&"toString"in r,nt=(r,e=!1)=>{const t=rt(r)?"stringer":typeof r;let n;switch(t){case"string":n=(i,o)=>i.localeCompare(o);break;case"stringer":n=(i,o)=>i.toString().localeCompare(o.toString());break;case"number":n=(i,o)=>Number(i)-Number(o);break;case"bigint":n=(i,o)=>BigInt(i)-BigInt(o)>0n?1:-1;break;case"boolean":n=(i,o)=>Number(i)-Number(o);break;case"undefined":n=()=>0;break;default:return console.warn(`sortFunc: unknown type ${t}`),()=>-1}return e?st(n):n},st=r=>(e,t)=>r(t,e);let ze=(r,e=21)=>(t=e)=>{let n="",i=t|0;for(;i--;)n+=r[Math.random()*r.length|0];return n};const xe="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",it=`0123456789${xe}`,at=11,ot=ze(xe,1),ut=ze(it,at-1),lt=()=>`${ot()}${ut()}`,ct=(r,e)=>t=>t instanceof e||typeof t=="object"&&t!==null&&"discriminator"in t&&t.discriminator===r,ht=2**12-1,ae=2n**63n-1n,dt=2**63-1,_=r=>(e,t)=>{if(typeof e=="bigint"){if(ft(t))return r(e,BigInt(t));const n=r(Number(e),Number(t));return typeof n=="number"?BigInt(Math.round(n)):n}return r(Number(e),Number(t))},G=_((r,e)=>r-e),L=_((r,e)=>r+e),ft=r=>typeof r=="bigint"?!0:Number.isInteger(r),M=_((r,e)=>r*e),ee=_((r,e)=>r/e),Me=s.z.tuple([s.z.number(),s.z.number()]),Ue=s.z.object({width:s.z.number(),height:s.z.number()}),gt=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()}),mt=["start","center","end"],W=s.z.object({x:s.z.number(),y:s.z.number()}),yt=s.z.object({clientX:s.z.number(),clientY:s.z.number()}),pt=["x","y"],Ae=s.z.enum(pt),Ce=["top","right","bottom","left"];s.z.enum(Ce);const wt=["left","right"],Be=s.z.enum(wt),bt=["top","bottom"],De=s.z.enum(bt),Re=["center"],we=s.z.enum(Re),Ot=[...Ce,...Re],Le=s.z.enum(Ot);s.z.enum(mt);const Tt=["first","last"];s.z.enum(Tt);s.z.object({lower:s.z.number(),upper:s.z.number()});s.z.enum([...Ae.options,...Le.options]);s.z.union([Ae,Le,s.z.instanceof(String)]);const $=(r,e,t)=>{const n={};if(typeof e=="object"&&(t=e,e=void 0),t={makeValid:!0,...t},typeof r=="number"||typeof r=="bigint")e!=null?(n.lower=r,n.upper=e):(n.lower=typeof r=="bigint"?0n:0,n.upper=r);else if(Array.isArray(r)){if(r.length!==2)throw new Error("bounds: expected array of length 2");[n.lower,n.upper]=r}else n.lower=r.lower,n.upper=r.upper;return t?.makeValid?vt(n):n},vt=r=>r.lower>r.upper?{lower:r.upper,upper:r.lower}:r,be=(r,e)=>{const t=$(r);return e<t.lower?t.lower:e>=t.upper?t.upper-(typeof t.upper=="number"?1:1n):e};s.z.object({x:Be.or(we),y:De.or(we)});const $e=s.z.object({x:Be,y:De}),St=Object.freeze({x:"left",y:"top"}),It=(r,e)=>r.x===e.x&&r.y===e.y,Oe=s.z.union([s.z.number(),W,Me,Ue,gt,yt]),Nt=(r,e)=>{if(typeof r=="string"){if(e===void 0)throw new Error("The y coordinate must be given.");return r==="x"?{x:e,y:0}:{x:0,y:e}}return typeof r=="number"?{x:r,y:e??r}:Array.isArray(r)?{x:r[0],y:r[1]}:"signedWidth"in r?{x:r.signedWidth,y:r.signedHeight}:"clientX"in r?{x:r.clientX,y:r.clientY}:"width"in r?{x:r.width,y:r.height}:{x:r.x,y:r.y}},Te=Object.freeze({x:0,y:0}),J=s.z.union([s.z.number(),s.z.string()]);s.z.object({top:J,left:J,width:J,height:J});s.z.object({left:s.z.number(),top:s.z.number(),right:s.z.number(),bottom:s.z.number()});s.z.object({one:W,two:W,root:$e});const ce=(r,e,t=0,n=0,i)=>{const o={one:{...Te},two:{...Te},root:i??St};if(typeof r=="number"){if(typeof e!="number")throw new Error("Box constructor called with invalid arguments");return o.one={x:r,y:e},o.two={x:o.one.x+t,y:o.one.y+n},o}return"one"in r&&"two"in r&&"root"in r?{...r,root:i??r.root}:("getBoundingClientRect"in r&&(r=r.getBoundingClientRect()),"left"in r?(o.one={x:r.left,y:r.top},o.two={x:r.right,y:r.bottom},o):(o.one=r,e==null?o.two={x:o.one.x+t,y:o.one.y+n}:typeof e=="number"?o.two={x:o.one.x+e,y:o.one.y+t}:"width"in e?o.two={x:o.one.x+e.width,y:o.one.y+e.height}:"signedWidth"in e?o.two={x:o.one.x+e.signedWidth,y:o.one.y+e.signedHeight}:o.two=e,o))},re=r=>{const e=ce(r);return{lower:e.one.x,upper:e.two.x}},ne=r=>{const e=ce(r);return{lower:e.one.y,upper:e.two.y}},Et=r=>typeof r!="object"||r==null?!1:"one"in r&&"two"in r&&"root"in r,zt=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()});s.z.union([Ue,zt,W,Me]);const xt=(r,e,t)=>e!==void 0&&r<e?e:t!==void 0&&r>t?t:r;s.z.object({offset:Oe,scale:Oe});s.z.object({offset:s.z.number(),scale:s.z.number()});const Mt=r=>(e,t,n,i)=>t==="dimension"?[e,n]:[e,i?n-r:n+r],Ut=r=>(e,t,n,i)=>[e,i?n/r:n*r],At=r=>(e,t,n)=>{if(e===null)return[r,n];const{lower:i,upper:o}=e,{lower:c,upper:f}=r,w=o-i,h=f-c;if(t==="dimension")return[r,n*(h/w)];const g=(n-i)*(h/w)+c;return[r,g]},Ct=r=>(e,t,n)=>[r,n],Bt=()=>(r,e,t)=>{if(r===null)throw new Error("cannot invert without bounds");if(e==="dimension")return[r,t];const{lower:n,upper:i}=r;return[r,i-(t-n)]},Dt=r=>(e,t,n)=>{const{lower:i,upper:o}=r;return n=xt(n,i,o),[e,n]};class B{ops=[];currBounds=null;currType=null;reversed=!1;constructor(){this.ops=[]}static translate(e){return new B().translate(e)}static magnify(e){return new B().magnify(e)}static scale(e,t){return new B().scale(e,t)}translate(e){const t=this.new(),n=Mt(e);return n.type="translate",t.ops.push(n),t}magnify(e){const t=this.new(),n=Ut(e);return n.type="magnify",t.ops.push(n),t}scale(e,t){const n=$(e,t),i=this.new(),o=At(n);return o.type="scale",i.ops.push(o),i}clamp(e,t){const n=$(e,t),i=this.new(),o=Dt(n);return o.type="clamp",i.ops.push(o),i}reBound(e,t){const n=$(e,t),i=this.new(),o=Ct(n);return o.type="re-bound",i.ops.push(o),i}invert(){const e=Bt();e.type="invert";const t=this.new();return t.ops.push(e),t}pos(e){return this.exec("position",e)}dim(e){return this.exec("dimension",e)}new(){const e=new B;return e.ops=this.ops.slice(),e.reversed=this.reversed,e}exec(e,t){return this.currBounds=null,this.ops.reduce(([n,i],o)=>o(n,e,i,this.reversed),[null,t])[1]}reverse(){const e=this.new();e.ops.reverse();const t=[];return e.ops.forEach((n,i)=>{if(n.type==="scale"||t.some(([c,f])=>i>=c&&i<=f))return;const o=e.ops.findIndex((c,f)=>c.type==="scale"&&f>i);o!==-1&&t.push([i,o])}),t.forEach(([n,i])=>{const o=e.ops.slice(n,i);o.unshift(e.ops[i]),e.ops.splice(n,i-n+1,...o)}),e.reversed=!e.reversed,e}get transform(){return{scale:this.dim(1),offset:this.pos(0)}}static IDENTITY=new B}class x{x;y;currRoot;constructor(e=new B,t=new B,n=null){this.x=e,this.y=t,this.currRoot=n}static translate(e,t){return new x().translate(e,t)}static translateX(e){return new x().translateX(e)}static translateY(e){return new x().translateY(e)}static clamp(e){return new x().clamp(e)}static magnify(e){return new x().magnify(e)}static scale(e){return new x().scale(e)}static reBound(e){return new x().reBound(e)}translate(e,t){const n=Nt(e,t),i=this.copy();return i.x=this.x.translate(n.x),i.y=this.y.translate(n.y),i}translateX(e){const t=this.copy();return t.x=this.x.translate(e),t}translateY(e){const t=this.copy();return t.y=this.y.translate(e),t}magnify(e){const t=this.copy();return t.x=this.x.magnify(e.x),t.y=this.y.magnify(e.y),t}scale(e){const t=this.copy();if(Et(e)){const n=this.currRoot;return t.currRoot=e.root,n!=null&&!It(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(re(e)),t.y=t.y.scale(ne(e)),t}return t.x=t.x.scale(e.width),t.y=t.y.scale(e.height),t}reBound(e){const t=this.copy();return t.x=this.x.reBound(re(e)),t.y=this.y.reBound(ne(e)),t}clamp(e){const t=this.copy();return t.x=this.x.clamp(re(e)),t.y=this.y.clamp(ne(e)),t}copy(){const e=new x;return e.currRoot=this.currRoot,e.x=this.x,e.y=this.y,e}reverse(){const 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 ce(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 x}const Rt=W.extend({root:$e,units:s.object({x:s.enum(["px","decimal"]),y:s.enum(["px","decimal"])})});Rt.partial({root:!0,units:!0});const Lt=s.z.enum(["static","dynamic"]),ve=365,K=30,$t=s.z.union([s.z.tuple([s.z.int()]),s.z.tuple([s.z.int(),s.z.int().min(1).max(12)]),s.z.tuple([s.z.int(),s.z.int().min(1).max(12),s.z.int().min(1).max(31)])]),Pe=(r,e)=>{const t=new u(e);if(![l.DAY,l.HOUR,l.MINUTE,l.SECOND,l.MILLISECOND,l.MICROSECOND,l.NANOSECOND].some(i=>i.equals(t)))throw new Error("Invalid argument for remainder. Must be an even TimeSpan or Timestamp");const n=r.valueOf()%t.valueOf();return r instanceof u?new u(n):new l(n)};class u extends F{constructor(e,t="UTC"){if(e==null)super(u.now().valueOf());else if(e instanceof Date)super(BigInt(e.getTime())*u.MILLISECOND.valueOf());else if(typeof e=="string")super(u.parseDateTimeString(e,t).valueOf());else if(Array.isArray(e))super(u.parseDate(e));else{let n=0n;e instanceof Number&&(e=e.valueOf()),t==="local"&&(n=u.utcOffset.valueOf()),typeof e=="number"&&(isFinite(e)?e===dt?e=ae:e=Math.trunc(e):(isNaN(e)&&(e=0),e===1/0?e=u.MAX:e=u.MIN)),E(e)&&(e=e.value),super(BigInt(e.valueOf())+n)}}static parseDate([e=1970,t=1,n=1]){const i=new Date(e,t-1,n,0,0,0,0);return new u(BigInt(i.getTime())*u.MILLISECOND.valueOf()).truncate(u.DAY).valueOf()}valueOf(){return this.value}static parseTimeString(e,t="UTC"){const[n,i,o]=e.split(":");let c="00",f="00";o!=null&&([c,f]=o.split("."));let w=u.hours(parseInt(n??"00")).add(u.minutes(parseInt(i??"00"))).add(u.seconds(parseInt(c??"00"))).add(u.milliseconds(parseInt(f??"00")));return t==="local"&&(w=w.add(u.utcOffset)),w.valueOf()}static parseDateTimeString(e,t="UTC"){if(!e.includes("/")&&!e.includes("-"))return u.parseTimeString(e,t);if(e.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,3})?$/)!=null){let i=e,o=0;if(e.includes(".")){const h=e.split(".");i=h[0];const g=h[1]||"0";o=parseInt(g.padEnd(3,"0").slice(0,3))}const c=t==="local"?new Date(i.replace("T"," ")):new Date(`${i}Z`),f=BigInt(c.getTime())*u.MILLISECOND.valueOf(),w=BigInt(o)*u.MILLISECOND.valueOf();return f+w}const n=new Date(e);return e.includes(":")||n.setUTCHours(0,0,0,0),new u(BigInt(n.getTime())*u.MILLISECOND.valueOf(),t).valueOf()}toISOString(e="UTC"){if(e==="UTC")return this.date().toISOString();const t=this.date(),n=new l(BigInt(t.getTimezoneOffset())*u.MINUTE.valueOf());return this.sub(n).date().toISOString()}timeString(e=!1,t="UTC"){const n=this.toISOString(t);return e?n.slice(11,23):n.slice(11,19)}dateString(){const e=this.date(),t=e.toLocaleString("default",{month:"short"}),n=e.toLocaleString("default",{day:"numeric"});return`${t} ${n}`}static get utcOffset(){return new l(BigInt(new Date().getTimezoneOffset())*u.MINUTE.valueOf())}static since(e){return new u().span(e)}date(){return new Date(this.milliseconds)}equals(e){return this.valueOf()===new u(e).valueOf()}span(e){return this.range(e).span}range(e){return new S(this,e).makeValid()}spanRange(e){return this.range(this.add(e)).makeValid()}get isZero(){return this.valueOf()===0n}after(e){return this.valueOf()>new u(e).valueOf()}afterEq(e){return this.valueOf()>=new u(e).valueOf()}before(e){return this.valueOf()<new u(e).valueOf()}beforeEq(e){return this.valueOf()<=new u(e).valueOf()}add(e){return new u(L(this.valueOf(),new l(e).valueOf()))}sub(e){return new u(G(this.valueOf(),new l(e).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(u.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(u.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get year(){return this.date().getUTCFullYear()}get localYear(){return this.date().getFullYear()}setYear(e){const t=this.date();return t.setUTCFullYear(e),new u(t)}setLocalYear(e){const t=this.date();return t.setFullYear(e),new u(t)}get month(){return this.date().getUTCMonth()}get localMonth(){return this.date().getMonth()}setMonth(e){const t=this.date();return t.setUTCMonth(e),new u(t)}setLocalMonth(e){const t=this.date();return t.setMonth(e),new u(t)}get day(){return this.date().getUTCDate()}get localDay(){return this.date().getDate()}setDay(e){const t=this.date();return t.setUTCDate(e),new u(t)}setLocalDay(e){const t=this.date();return t.setDate(e),new u(t)}get hour(){return this.date().getUTCHours()}get localHour(){return this.date().getHours()}setLocalHour(e){const t=this.date();return t.setHours(e),new u(t)}setHour(e){const t=this.date();return t.setUTCHours(e),new u(t)}get minute(){return this.date().getUTCMinutes()}get localMinute(){return this.date().getMinutes()}setMinute(e){const t=this.date();return t.setUTCMinutes(e),new u(t)}setLocalMinute(e){const t=this.date();return t.setMinutes(e),new u(t)}get second(){return this.date().getUTCSeconds()}get localSecond(){return this.date().getSeconds()}setSecond(e){const t=this.date();return t.setUTCSeconds(e),new u(t)}setLocalSecond(e){const t=this.date();return t.setSeconds(e),new u(t)}get millisecond(){return this.date().getUTCMilliseconds()}get localMillisecond(){return this.date().getMilliseconds()}setMillisecond(e){const t=this.date();return t.setUTCMilliseconds(e),new u(t)}setLocalMillisecond(e){const t=this.date();return t.setMilliseconds(e),new u(t)}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 Pe(this,e)}get isToday(){return this.truncate(l.DAY).equals(u.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 u(new Date)}static max(...e){let t=u.MIN;for(const n of e){const i=new u(n);i.after(t)&&(t=i)}return t}static min(...e){let t=u.MAX;for(const n of e){const i=new u(n);i.before(t)&&(t=i)}return t}static nanoseconds(e,t="UTC"){return new u(e,t)}static NANOSECOND=u.nanoseconds(1);static microseconds(e,t="UTC"){return u.nanoseconds(e*1e3,t)}static MICROSECOND=u.microseconds(1);static milliseconds(e,t="UTC"){return u.microseconds(e*1e3,t)}static MILLISECOND=u.milliseconds(1);static seconds(e,t="UTC"){return u.milliseconds(e*1e3,t)}static SECOND=u.seconds(1);static minutes(e,t="UTC"){return u.seconds(e*60,t)}static MINUTE=u.minutes(1);static hours(e,t="UTC"){return u.minutes(e*60,t)}static HOUR=u.hours(1);static days(e,t="UTC"){return u.hours(e*24,t)}static DAY=u.days(1);static MAX=new u(ae);static MIN=new u(0);static ZERO=new u(0);static z=s.z.union([s.z.instanceof(u),s.z.object({value:s.z.bigint()}).transform(e=>new u(e.value)),s.z.string().transform(e=>new u(BigInt(e))),s.z.number().transform(e=>new u(e)),s.z.bigint().transform(e=>new u(e)),s.z.date().transform(e=>new u(e)),s.z.custom(e=>e instanceof l).transform(e=>new u(e)),$t.transform(e=>new u(e))]);static sort(e,t){return Number(e.valueOf()-t.valueOf())}}class l extends F{constructor(e){typeof e=="number"&&(e=Math.trunc(e.valueOf())),E(e)&&(e=e.value),super(BigInt(e.valueOf()))}static fromSeconds(e){return e instanceof l?e:e instanceof I?e.period:e instanceof u?new l(e):(E(e)&&(e=e.value),["number","bigint"].includes(typeof e)?l.seconds(e):new l(e))}static fromMilliseconds(e){return e instanceof l?e:e instanceof I?e.period:e instanceof u?new l(e):(E(e)&&(e=e.value),["number","bigint"].includes(typeof e)?l.milliseconds(e):new l(e))}valueOf(){return this.value}lessThan(e){return this.valueOf()<new l(e).valueOf()}greaterThan(e){return this.valueOf()>new l(e).valueOf()}lessThanOrEqual(e){return this.valueOf()<=new l(e).valueOf()}greaterThanOrEqual(e){return this.valueOf()>=new l(e).valueOf()}remainder(e){return Pe(this,e)}truncate(e){return new l(BigInt(Math.trunc(Number(this.valueOf()/e.valueOf())))*e.valueOf())}toString(e="full"){if(e==="semantic")return this.toSemanticString();const t=this.truncate(l.DAY),n=this.truncate(l.HOUR),i=this.truncate(l.MINUTE),o=this.truncate(l.SECOND),c=this.truncate(l.MILLISECOND),f=this.truncate(l.MICROSECOND),w=this.truncate(l.NANOSECOND),h=t,g=n.sub(t),b=i.sub(n),d=o.sub(i),O=c.sub(o),N=f.sub(c),z=w.sub(f);let p="";return h.isZero||(p+=`${h.days}d `),g.isZero||(p+=`${g.hours}h `),b.isZero||(p+=`${b.minutes}m `),d.isZero||(p+=`${d.seconds}s `),O.isZero||(p+=`${O.milliseconds}ms `),N.isZero||(p+=`${N.microseconds}µs `),z.isZero||(p+=`${z.nanoseconds}ns`),p.trim()}toSemanticString(){const e=this.valueOf()<0n?-this.valueOf():this.valueOf(),t=new l(e),n=this.valueOf()<0n;if(t.valueOf()===0n)return"0s";if(t.lessThan(l.SECOND))return"< 1s";const i=t.days,o=t.hours,c=t.minutes,f=t.seconds,w=Math.floor(i/ve),h=Math.floor(i/K),g=Math.floor(i/7),b=Math.floor(i),d=Math.floor(o),O=Math.floor(c),N=Math.floor(f),z=n?"-":"";if(w>=1){let p=`${w}y`;if(w<2){const T=Math.floor(i%ve/K);T>0&&(p+=` ${T}mo`)}return z+p}if(g>=1&&i<K&&i%7===0){let p=`${g}w`;const T=Math.floor(i%7),R=Math.floor(o-g*7*24);return g<2&&(T>0?p+=` ${T}d`:R>0&&R<24&&(p+=` ${R}h`)),z+p}if(h>=1){let p=`${h}mo`;if(h<3){const T=Math.floor(i%K);T>0&&(p+=` ${T}d`)}return z+p}if(g>=1){let p=`${g}w`;const T=Math.floor(i%7),R=Math.floor(o-g*7*24);return g<2&&(T>0?p+=` ${T}d`:R>0&&R<24&&(p+=` ${R}h`)),z+p}if(b>=1){let p=`${b}d`;const T=Math.floor(o-b*24);return b<2&&T>0&&(p+=` ${T}h`),z+p}if(d>=1){let p=`${d}h`;if(d<3){const T=Math.floor(c-d*60);T>0&&(p+=` ${T}m`)}return z+p}if(O>=1){let p=`${O}m`;if(O<5){const T=Math.floor(f-O*60);T>0&&(p+=` ${T}s`)}return z+p}return`${z}${N}s`}mult(e){return new l(M(this.valueOf(),e))}div(e){return new l(ee(this.valueOf(),e))}get days(){return Number(this.valueOf())/Number(l.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(l.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(l.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(l.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(l.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(l.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get isZero(){return this.valueOf()===0n}equals(e){return this.valueOf()===new l(e).valueOf()}add(e){return new l(this.valueOf()+new l(e).valueOf())}sub(e){return new l(this.valueOf()-new l(e).valueOf())}static nanoseconds(e=1){return new l(e)}static NANOSECOND=l.nanoseconds(1);static microseconds(e=1){return l.nanoseconds(M(e,1e3))}static MICROSECOND=l.microseconds(1);static milliseconds(e=1){return l.microseconds(M(e,1e3))}static MILLISECOND=l.milliseconds(1);static seconds(e=1){return l.milliseconds(M(e,1e3))}static SECOND=l.seconds(1);static minutes(e=1){return l.seconds(M(e,60))}static MINUTE=l.minutes(1);static hours(e){return l.minutes(M(e,60))}static HOUR=l.hours(1);static days(e){return l.hours(M(e,24))}static DAY=l.days(1);static MAX=new l(ae);static MIN=new l(0);static ZERO=new l(0);static z=s.z.union([s.z.object({value:s.z.bigint()}).transform(e=>new l(e.value)),s.z.string().transform(e=>new l(BigInt(e))),s.z.number().transform(e=>new l(e)),s.z.bigint().transform(e=>new l(e)),s.z.instanceof(l),s.z.instanceof(u).transform(e=>new l(e)),s.z.custom(e=>e instanceof I).transform(e=>new l(e))])}class I extends F{constructor(e){E(e)&&(e=e.value),super(e.valueOf())}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new I(e).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 y(t).valueOf()}span(e){return l.seconds(e/this.valueOf())}byteSpan(e,t){return this.span(e.valueOf()/new y(t).valueOf())}add(e){return new I(L(this.valueOf(),new I(e).valueOf()))}sub(e){return new I(G(this.valueOf(),new I(e).valueOf()))}mult(e){return new I(M(this.valueOf(),e))}div(e){return new I(ee(this.valueOf(),e))}static hz(e){return new I(e)}static khz(e){return I.hz(e*1e3)}static z=s.z.union([s.z.number().transform(e=>new I(e)),s.z.instanceof(I)])}class y extends F{constructor(e){E(e)&&(e=e.value),super(e.valueOf())}length(e){return e.valueOf()/this.valueOf()}size(e){return new m(e*this.valueOf())}add(e){return new y(L(this.valueOf(),new y(e).valueOf()))}sub(e){return new y(G(this.valueOf(),new y(e).valueOf()))}mult(e){return new y(M(this.valueOf(),e))}div(e){return new y(ee(this.valueOf(),e))}static UNKNOWN=new y(0);static BIT128=new y(16);static BIT64=new y(8);static BIT32=new y(4);static BIT16=new y(2);static BIT8=new y(1);static z=s.z.union([s.z.number().transform(e=>new y(e)),s.z.instanceof(y)])}class S{start;end;constructor(e,t){typeof e=="object"&&"start"in e?(this.start=new u(e.start),this.end=new u(e.end)):(this.start=new u(e),this.end=new u(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 S(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(),i=this.end.sub(e.end).valueOf();return n<0&&(n=-n),i<0&&(i=-i),n<=t.valueOf()&&i<=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();const n=this.makeValid();if(this.equals(e))return!0;if(e.end.equals(n.start)||n.end.equals(e.start))return!1;const i=u.max(n.start,e.start),o=u.min(n.end,e.end);return o.before(i)?!1:new l(o.sub(i)).greaterThanOrEqual(t)}contains(e){return e instanceof S?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const t=new S(this.start,this.end);return e.start.after(this.start)&&(t.start=e.start),e.start.after(this.end)&&(t.end=e.start),e.end.before(this.end)&&(t.end=e.end),e.end.before(this.start)&&(t.start=e.end),t}static max(...e){return new S(u.min(...e.map(t=>t.start)),u.max(...e.map(t=>t.end)))}static MAX=new S(u.MIN,u.MAX);static ZERO=new S(u.ZERO,u.ZERO);static z=s.z.union([s.z.object({start:u.z,end:u.z}).transform(e=>new S(e.start,e.end)),s.z.instanceof(S)]);static sort(e,t){return u.sort(e.start,t.start)||u.sort(e.end,t.end)}static merge(...e){return S.max(...e.map(t=>new S(t).makeValid()))}}class a extends F{constructor(e){if(E(e)&&(e=e.value),e instanceof a||typeof e=="string"||typeof e.valueOf()=="string")super(e.valueOf());else{const t=a.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);if(t==null)throw new Error(`unable to find data type for ${e.toString()}`);super(t.valueOf())}}get Array(){const e=a.ARRAY_CONSTRUCTORS.get(this.toString());if(e==null)throw new Error(`unable to find array constructor for ${this.valueOf()}`);return e}equals(e){return this.valueOf()===e.valueOf()}matches(...e){return e.some(t=>this.equals(t))}toString(e=!1){return e?a.SHORT_STRINGS.get(this.valueOf())??this.valueOf():this.valueOf()}get isVariable(){return this.equals(a.JSON)||this.equals(a.STRING)||this.equals(a.BYTES)}get isNumeric(){return!this.isVariable&&!this.equals(a.UUID)}get isInteger(){const e=this.toString();return e.startsWith("int")||e.startsWith("uint")}get isFloat(){return this.toString().startsWith("float")}get density(){const e=a.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}get isUnsignedInteger(){return this.equals(a.UINT8)||this.equals(a.UINT16)||this.equals(a.UINT32)||this.equals(a.UINT64)}get isSignedInteger(){return this.equals(a.INT8)||this.equals(a.INT16)||this.equals(a.INT32)||this.equals(a.INT64)}canSafelyCastTo(e){return this.equals(e)?!0:!this.isNumeric||!e.isNumeric||this.isVariable||e.isVariable||this.isUnsignedInteger&&e.isSignedInteger?!1:this.isFloat?e.isFloat&&this.density.valueOf()<=e.density.valueOf():this.equals(a.INT32)&&e.equals(a.FLOAT64)||this.equals(a.INT8)&&e.equals(a.FLOAT32)?!0:this.isInteger&&e.isInteger?this.density.valueOf()<=e.density.valueOf()&&this.isUnsignedInteger===e.isUnsignedInteger:!1}canCastTo(e){return this.isNumeric&&e.isNumeric?!0:this.equals(e)}checkArray(e){return e.constructor===this.Array}get usesBigInt(){return a.BIG_INT_TYPES.some(e=>e.equals(this))}static UNKNOWN=new a("unknown");static FLOAT64=new a("float64");static FLOAT32=new a("float32");static INT64=new a("int64");static INT32=new a("int32");static INT16=new a("int16");static INT8=new a("int8");static UINT64=new a("uint64");static UINT32=new a("uint32");static UINT16=new a("uint16");static UINT8=new a("uint8");static TIMESTAMP=new a("timestamp");static UUID=new a("uuid");static STRING=new a("string");static JSON=new a("json");static BYTES=new a("bytes");static ARRAY_CONSTRUCTORS=new Map([[a.UINT8.toString(),Uint8Array],[a.UINT16.toString(),Uint16Array],[a.UINT32.toString(),Uint32Array],[a.UINT64.toString(),BigUint64Array],[a.FLOAT32.toString(),Float32Array],[a.FLOAT64.toString(),Float64Array],[a.INT8.toString(),Int8Array],[a.INT16.toString(),Int16Array],[a.INT32.toString(),Int32Array],[a.INT64.toString(),BigInt64Array],[a.TIMESTAMP.toString(),BigInt64Array],[a.STRING.toString(),Uint8Array],[a.JSON.toString(),Uint8Array],[a.UUID.toString(),Uint8Array],[a.BYTES.toString(),Uint8Array]]);static ARRAY_CONSTRUCTOR_DATA_TYPES=new Map([[Uint8Array.name,a.UINT8],[Uint16Array.name,a.UINT16],[Uint32Array.name,a.UINT32],[BigUint64Array.name,a.UINT64],[Float32Array.name,a.FLOAT32],[Float64Array.name,a.FLOAT64],[Int8Array.name,a.INT8],[Int16Array.name,a.INT16],[Int32Array.name,a.INT32],[BigInt64Array.name,a.INT64]]);static DENSITIES=new Map([[a.UINT8.toString(),y.BIT8],[a.UINT16.toString(),y.BIT16],[a.UINT32.toString(),y.BIT32],[a.UINT64.toString(),y.BIT64],[a.FLOAT32.toString(),y.BIT32],[a.FLOAT64.toString(),y.BIT64],[a.INT8.toString(),y.BIT8],[a.INT16.toString(),y.BIT16],[a.INT32.toString(),y.BIT32],[a.INT64.toString(),y.BIT64],[a.TIMESTAMP.toString(),y.BIT64],[a.STRING.toString(),y.UNKNOWN],[a.JSON.toString(),y.UNKNOWN],[a.UUID.toString(),y.BIT128],[a.BYTES.toString(),y.UNKNOWN]]);static ALL=[a.UNKNOWN,a.UINT8,a.UINT16,a.UINT32,a.UINT64,a.INT8,a.INT16,a.INT32,a.INT64,a.FLOAT32,a.FLOAT64,a.TIMESTAMP,a.UUID,a.STRING,a.JSON,a.BYTES];static SHORT_STRINGS=new Map([[a.UINT8.toString(),"u8"],[a.UINT16.toString(),"u16"],[a.UINT32.toString(),"u32"],[a.UINT64.toString(),"u64"],[a.INT8.toString(),"i8"],[a.INT16.toString(),"i16"],[a.INT32.toString(),"i32"],[a.INT64.toString(),"i64"],[a.FLOAT32.toString(),"f32"],[a.FLOAT64.toString(),"f64"],[a.TIMESTAMP.toString(),"ts"],[a.UUID.toString(),"uuid"],[a.STRING.toString(),"str"],[a.JSON.toString(),"json"],[a.BYTES.toString(),"bytes"]]);static BIG_INT_TYPES=[a.INT64,a.UINT64,a.TIMESTAMP];static z=s.z.union([s.z.string().transform(e=>new a(e)),s.z.instanceof(a)])}class m extends F{constructor(e){E(e)&&(e=e.value),super(e.valueOf())}largerThan(e){return E(e)&&(e=e.value),this.valueOf()>e.valueOf()}smallerThan(e){return E(e)&&(e=e.value),this.valueOf()<e.valueOf()}add(e){return E(e)&&(e=e.value),new m(L(this.valueOf(),e.valueOf()))}sub(e){return E(e)&&(e=e.value),new m(G(this.valueOf(),e.valueOf()))}mult(e){return new m(M(this.valueOf(),e))}div(e){return new m(ee(this.valueOf(),e))}truncate(e){return new m(Math.trunc(this.valueOf()/new m(e).valueOf())*new m(e).valueOf())}remainder(e){return m.bytes(this.valueOf()%new m(e).valueOf())}get gigabytes(){return this.valueOf()/m.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/m.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/m.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/m.TERABYTE.valueOf()}toString(){const e=this.truncate(m.TERABYTE),t=this.truncate(m.GIGABYTE),n=this.truncate(m.MEGABYTE),i=this.truncate(m.KILOBYTE),o=this.truncate(m.BYTE),c=e,f=t.sub(e),w=n.sub(t),h=i.sub(n),g=o.sub(i);let b="";return c.isZero||(b+=`${c.terabytes}TB `),f.isZero||(b+=`${f.gigabytes}GB `),w.isZero||(b+=`${w.megabytes}MB `),h.isZero||(b+=`${h.kilobytes}KB `),(!g.isZero||b==="")&&(b+=`${g.valueOf()}B`),b.trim()}static bytes(e=1){return new m(e)}static BYTE=new m(1);static kilobytes(e=1){return m.bytes(new m(e).valueOf()*1e3)}static KILOBYTE=m.kilobytes(1);static megabytes(e=1){return m.kilobytes(new m(e).valueOf()*1e3)}static MEGABYTE=m.megabytes(1);static gigabytes(e=1){return m.megabytes(new m(e).valueOf()*1e3)}static GIGABYTE=m.gigabytes(1);static terabytes(e){return m.gigabytes(new m(e).valueOf()*1e3)}static TERABYTE=m.terabytes(1);static ZERO=new m(0);static z=s.z.union([s.z.number().transform(e=>new m(e)),s.z.instanceof(m)]);get isZero(){return this.valueOf()===0}}s.z.object({start:s.z.number(),end:s.z.number()});s.z.union([s.z.instanceof(Uint8Array),s.z.instanceof(Uint16Array),s.z.instanceof(Uint32Array),s.z.instanceof(BigUint64Array),s.z.instanceof(Float32Array),s.z.instanceof(Float64Array),s.z.instanceof(Int8Array),s.z.instanceof(Int16Array),s.z.instanceof(Int32Array),s.z.instanceof(BigInt64Array)]);const ke=r=>{const e=typeof r;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||r instanceof u||r instanceof l||r instanceof Date},Pt=(r,e,t,n=0)=>r.usesBigInt&&!e.usesBigInt?Number(t)-Number(n):!r.usesBigInt&&e.usesBigInt?BigInt(t.valueOf())-BigInt(n.valueOf()):G(t,n),kt=/^(?:[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 Yt(r){return typeof r=="string"&&kt.test(r)}const v=[];for(let r=0;r<256;++r)v.push((r+256).toString(16).slice(1));function jt(r,e=0){return(v[r[e+0]]+v[r[e+1]]+v[r[e+2]]+v[r[e+3]]+"-"+v[r[e+4]]+v[r[e+5]]+"-"+v[r[e+6]]+v[r[e+7]]+"-"+v[r[e+8]]+v[r[e+9]]+"-"+v[r[e+10]]+v[r[e+11]]+v[r[e+12]]+v[r[e+13]]+v[r[e+14]]+v[r[e+15]]).toLowerCase()}function Ft(r,e=0){const t=jt(r,e);if(!Yt(t))throw TypeError("Stringified UUID is invalid");return t}typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const Ye=(r,e)=>Ft(r,e),C=-1,qt=s.z.string().transform(r=>new Uint8Array(atob(r).split("").map(e=>e.charCodeAt(0))).buffer),Zt=s.z.union([s.z.null(),s.z.undefined()]).transform(()=>new Uint8Array().buffer),oe=10,Wt=(r,e)=>{if(r==="number"&&!e.isNumeric)throw new Error(`cannot convert series of type ${e.toString()} to number`);if(r==="bigint"&&!e.usesBigInt)throw new Error(`cannot convert series of type ${e.toString()} to bigint`)},je="sy_x_telem_series";class U{key;discriminator=je;dataType;sampleOffset;gl;_data;timeRange=S.ZERO;alignment=0n;alignmentMultiple=1n;cachedMin;cachedMax;writePos=C;_refCount=0;cachedLength;_cachedIndexes;static crudeZ=s.z.object({timeRange:S.z.optional(),dataType:a.z,alignment:s.z.coerce.bigint().optional(),data:s.z.union([qt,Zt,s.z.instanceof(ArrayBuffer),s.z.instanceof(Uint8Array)]),glBufferUsage:Lt.default("static").optional()});static z=U.crudeZ.transform(e=>new U(e));constructor(e){Gt(e)&&(e={data:e}),e.data??=[];const{dataType:t,timeRange:n,sampleOffset:i=0,glBufferUsage:o="static",alignment:c=0n,alignmentMultiple:f=1n,key:w=lt(),data:h}=e;if(Vt(h)){const d=h;this.key=d.key,this.dataType=d.dataType,this.sampleOffset=d.sampleOffset,this.gl=d.gl,this._data=d._data,this.timeRange=d.timeRange,this.alignment=d.alignment,this.alignmentMultiple=d.alignmentMultiple,this.cachedMin=d.cachedMin,this.cachedMax=d.cachedMax,this.writePos=d.writePos,this._refCount=d._refCount,this.cachedLength=d.cachedLength;return}const g=ke(h),b=Array.isArray(h);if(t!=null)this.dataType=new a(t);else{if(h instanceof ArrayBuffer)throw new Error("cannot infer data type from an ArrayBuffer instance when constructing a Series. Please provide a data type.");if(b||g){let d=h;if(!g){if(h.length===0)throw new Error("cannot infer data type from a zero length JS array when constructing a Series. Please provide a data type.");d=h[0]}if(typeof d=="string")this.dataType=a.STRING;else if(typeof d=="number")this.dataType=a.FLOAT64;else if(typeof d=="bigint")this.dataType=a.INT64;else if(typeof d=="boolean")this.dataType=a.UINT8;else if(d instanceof u||d instanceof Date||d instanceof u)this.dataType=a.TIMESTAMP;else if(typeof d=="object")this.dataType=a.JSON;else throw new Error(`cannot infer data type of ${typeof d} when constructing a Series from a JS array`)}else this.dataType=new a(h)}if(!b&&!g)this._data=h;else if(b&&h.length===0)this._data=new this.dataType.Array([]).buffer;else{let d=g?[h]:h;const O=d[0];(O instanceof u||O instanceof Date||O instanceof l)&&(d=d.map(N=>new u(N).valueOf())),this.dataType.equals(a.STRING)?(this.cachedLength=d.length,this._data=new TextEncoder().encode(`${d.join(`
2
- `)}
3
- `).buffer):this.dataType.equals(a.JSON)?(this.cachedLength=d.length,this._data=new TextEncoder().encode(`${d.map(N=>ie.encodeString(N)).join(`
4
- `)}
5
- `).buffer):this.dataType.usesBigInt&&typeof O=="number"?this._data=new this.dataType.Array(d.map(N=>BigInt(Math.round(N)))).buffer:!this.dataType.usesBigInt&&typeof O=="bigint"?this._data=new this.dataType.Array(d.map(Number)).buffer:this._data=new this.dataType.Array(d).buffer}this.key=w,this.alignment=c,this.alignmentMultiple=f,this.sampleOffset=i??0,this.timeRange=n??S.ZERO,this.gl={control:null,buffer:null,prevBuffer:0,bufferUsage:o}}static alloc({capacity:e,dataType:t,...n}){if(e===0)throw new Error("[Series] - cannot allocate an array of length 0");const i=new new a(t).Array(e),o=new U({data:i.buffer,dataType:t,...n});return o.writePos=0,o}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 new 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===C)return 0;const 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===C)return 0;const 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===C?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(a.JSON))throw new Error("cannot parse non-JSON series as JSON");return this.toStrings().map(t=>e.parse(ie.decodeString(t)))}get byteCapacity(){return new m(this.underlyingData.byteLength)}get capacity(){return this.dataType.isVariable?this.byteCapacity.valueOf():this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===C?this.byteCapacity:this.dataType.isVariable?new m(this.writePos):this.dataType.density.size(this.writePos)}get length(){return this.cachedLength!=null?this.cachedLength:this.dataType.isVariable?this.calculateCachedLength():this.writePos===C?this.byteCapacity.valueOf()/this.dataType.density.valueOf():this.writePos}calculateCachedLength(){if(!this.dataType.isVariable)throw new Error("cannot calculate length of a non-variable length data type");let e=0;const t=[0];return this.data.forEach((n,i)=>{n===oe&&(e++,t.push(i+1))}),this._cachedIndexes=t,this.cachedLength=e,e}convert(e,t=0){if(this.dataType.equals(e))return this;const n=new e.Array(this.length);for(let i=0;i<this.length;i++)n[i]=Pt(this.dataType,e,this.data[i],t);return new U({data:n.buffer,dataType:e,timeRange:this.timeRange,sampleOffset:t,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment})}calcRawMax(){if(this.length===0)return-1/0;if(this.dataType.equals(a.TIMESTAMP))this.cachedMax=this.data[this.data.length-1];else if(this.dataType.usesBigInt){const e=this.data;this.cachedMax=e.reduce((t,n)=>t>n?t:n)}else{const e=this.data;this.cachedMax=e.reduce((t,n)=>t>n?t:n)}return this.cachedMax}get max(){return this.calcMax()}calcMax(){if(this.dataType.isVariable)throw new Error("cannot calculate maximum on a variable length data type");return this.writePos===0?-1/0:(this.cachedMax??=this.calcRawMax(),L(this.cachedMax,this.sampleOffset))}calcRawMin(){if(this.length===0)return 1/0;if(this.dataType.equals(a.TIMESTAMP))this.cachedMin=this.data[0];else if(this.dataType.usesBigInt){const e=this.data;this.cachedMin=e.reduce((t,n)=>t<n?t:n)}else{const e=this.data;this.cachedMin=e.reduce((t,n)=>t<n?t:n)}return this.cachedMin}get min(){return this.calcMin()}calcMin(){if(this.dataType.isVariable)throw new Error("cannot calculate minimum on a variable length data type");return this.writePos===0?1/0:(this.cachedMin??=this.calcRawMin(),L(this.cachedMin,this.sampleOffset))}get bounds(){return $(Number(this.min),Number(this.max),{makeValid:!1})}maybeRecomputeMinMax(e){if(this.cachedMin!=null){const t=e.cachedMin??e.calcRawMin();t<this.cachedMin&&(this.cachedMin=t)}if(this.cachedMax!=null){const t=e.cachedMax??e.calcRawMax();t>this.cachedMax&&(this.cachedMax=t)}}atAlignment(e,t){const n=Number((e-this.alignment)/this.alignmentMultiple);if(n<0||n>=this.length){if(t===!0)throw new 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(a.UUID))return this.atUUID(e,t);e<0&&(e=this.length+e);const n=this.data[e];if(n==null){if(t===!0)throw new Error(`[series] - no value at index ${e}`);return}return L(n,this.sampleOffset)}atUUID(e,t){e<0&&(e=this.length+e);const n=Ye(new Uint8Array(this.buffer,e*this.dataType.density.valueOf()));if(n==null){if(t)throw new Error(`[series] - no value at index ${e}`);return}return n}atVariable(e,t){let n=0,i=0;if(this._cachedIndexes!=null)n=this._cachedIndexes[e],i=this._cachedIndexes[e+1]-1;else{e<0&&(e=this.length+e);for(let c=0;c<this.data.length;c++)if(this.data[c]===oe){if(e===0){i=c;break}n=c+1,e--}if(i===0&&(i=this.data.length),n>=i||e>0){if(t)throw new Error(`[series] - no value at index ${e}`);return}}const o=this.data.slice(n,i);return this.dataType.equals(a.STRING)?new TextDecoder().decode(o):Ee(JSON.parse(new TextDecoder().decode(o)))}binarySearch(e){let t=0,n=this.length-1;const i=nt(e);for(;t<=n;){const o=Math.floor((t+n)/2),c=i(this.at(o,!0),e);if(c===0)return o;c<0?t=o+1:n=o-1}return t}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals(a.FLOAT32)&&!this.dataType.equals(a.UINT8))throw new Error("Only FLOAT32 and UINT8 arrays can be used in WebGL");const{buffer:t,bufferUsage:n,prevBuffer:i}=this.gl;if(t==null&&(this.gl.buffer=e.createBuffer()),this.writePos!==i)if(e.bindBuffer(e.ARRAY_BUFFER,this.gl.buffer),this.writePos!==C){i===0&&e.bufferData(e.ARRAY_BUFFER,this.byteCapacity.valueOf(),e.STATIC_DRAW);const o=this.dataType.density.size(i).valueOf(),c=this.underlyingData.slice(this.gl.prevBuffer,this.writePos);e.bufferSubData(e.ARRAY_BUFFER,o,c.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=C}as(e){return Wt(e,this.dataType),this}get digest(){return{key:this.key,dataType:this.dataType.toString(),sampleOffset:this.sampleOffset,alignment:{lower:Ie(this.alignmentBounds.lower),upper:Ie(this.alignmentBounds.upper),multiple:this.alignmentMultiple},timeRange:this.timeRange.toString(),length:this.length,capacity:this.capacity}}get alignmentBounds(){return $(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 new 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){const e=new Ht(this);return this.dataType.equals(a.JSON)?new he(e):e}return this.dataType.equals(a.UUID)?new Jt(this):new Kt(this)}slice(e,t){return this.sliceSub(!1,e,t)}sub(e,t){return this.sliceSub(!0,e,t)}subIterator(e,t){return new Se(this,e,t??this.length)}subAlignmentIterator(e,t){const n=Math.ceil(Number(e-this.alignment)/Number(this.alignmentMultiple)),i=Math.ceil(Number(t-this.alignment)/Number(this.alignmentMultiple));return new Se(this,n,i)}subBytes(e,t){if(e>=0&&(t==null||t>=this.byteLength.valueOf()))return this;const n=this.data.subarray(e,t);return new U({data:n,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(e)})}sliceSub(e,t,n){if(t<=0&&(n==null||n>=this.length))return this;let i;return e?i=this.data.subarray(t,n):i=this.data.slice(t,n),new U({data:i,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(t)})}reAlign(e){return new U({data:this.buffer,dataType:this.dataType,timeRange:S.ZERO,sampleOffset:this.sampleOffset,glBufferUsage:"static",alignment:e})}toString(){let e=`Series(${this.dataType.toString()} ${this.length} [`;if(this.length<=10)e+=Array.from(this).map(t=>t.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}}const Gt=r=>r==null?!1:Array.isArray(r)||r instanceof ArrayBuffer||ArrayBuffer.isView(r)&&!(r instanceof DataView)||r instanceof U?!0:ke(r),Vt=ct(je,U);class Se{series;end;index;constructor(e,t,n){this.series=e;const i=$(0,e.length+1);this.end=be(i,n),this.index=be(i,t)}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}}class Ht{series;index;decoder;constructor(e){if(!e.dataType.isVariable)throw new Error("cannot create a variable series iterator for a non-variable series");this.series=e,this.index=0,this.decoder=new TextDecoder}next(){const e=this.index,t=this.series.data;for(;this.index<t.length&&t[this.index]!==oe;)this.index++;const 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))})}}class he{wrapped;static schema=s.z.record(s.z.string(),s.z.unknown());constructor(e){this.wrapped=e}next(){const e=this.wrapped.next();return e.done===!0?{done:!0,value:void 0}:{done:!1,value:ie.decodeString(e.value,he.schema)}}}class Jt{series;index;data;density;constructor(e){if(!e.dataType.equals(a.UUID))throw new 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=a.UUID.density.valueOf()}next(){if(this.index>=this.series.length)return{done:!0,value:void 0};const e=Ye(this.data,this.index*this.density);return this.index++,{done:!1,value:e}}}class Kt{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)}}}const Ie=r=>{const e=r>>32n,t=r&0xffffffffn;return{domain:e,sample:t}},Xt=async r=>await new Promise(e=>setTimeout(e,l.fromMilliseconds(r).milliseconds));class Qt{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??Xt},this.retries=0,this.interval=new l(this.config.baseInterval)}async wait(){const{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}}const _t=s.z.object({baseInterval:l.z.optional(),maxRetries:s.z.number().optional(),scale:s.z.number().optional()}),er=Object.freeze(Object.defineProperty({__proto__:null,Breaker:Qt,breakerConfigZ:_t},Symbol.toStringTag,{value:"Module"})),tr=/^#?([0-9a-f]{6}|[0-9a-f]{8})$/i,Fe=s.z.string().regex(tr),A=s.z.number().min(0).max(255),de=s.z.number().min(0).max(1),qe=s.z.tuple([A,A,A,de]),rr=s.z.tuple([A,A,A]),nr=s.z.object({rgba255:qe}),sr=s.z.object({r:A,g:A,b:A,a:de}),ir=s.z.number().min(0).max(360),ar=s.z.number().min(0).max(100),or=s.z.number().min(0).max(100),ur=s.z.tuple([ir,ar,or,de]),fe=s.z.union([Fe,rr,qe,ur,nr,sr]),Ze=fe.transform(r=>ge(r)),ge=(r,e=1)=>{if(r=fe.parse(r),typeof r=="string")return lr(r,e);if(Array.isArray(r)){if(r.length<3||r.length>4)throw new Error(`Invalid color: [${r.join(", ")}]`);return r.length===3?[...r,e]:r}return"a"in r&&"r"in r?[r.r,r.g,r.b,r.a]:r.rgba255},lr=(r,e=1)=>(r=Fe.parse(r),r=cr(r),[X(r,0),X(r,2),X(r,4),r.length===8?X(r,6)/255:e]),X=(r,e)=>parseInt(r.slice(e,e+2),16),cr=r=>r.startsWith("#")?r.slice(1):r;ge("#000000");ge("#ffffff");const hr=s.z.object({key:s.z.string(),color:fe,position:s.z.number(),switched:s.z.boolean().optional()});s.z.array(hr);const dr=s.z.object({key:s.z.string(),name:s.z.string(),color:Ze});s.z.object({key:s.z.string(),name:s.z.string(),swatches:s.z.array(dr)});s.z.int().min(0).max(255);s.z.object({name:s.z.string(),key:s.z.string()});const fr=r=>Object.getOwnPropertySymbols(globalThis).includes(r),gr=(r,e)=>{const t=Symbol.for(r);if(!fr(t)){const n=e();Object.defineProperty(globalThis,t,{value:n})}return()=>globalThis[t]},We="sy_x_error",mr=r=>e=>e!=null&&typeof e=="object"&&"type"in e&&typeof e.type=="string"?e.type.startsWith(r):e instanceof Error?e.message.startsWith(r):typeof e!="string"?!1:e.startsWith(r),V=r=>class q extends Error{static discriminator=We;discriminator=q.discriminator;static TYPE=r;type=q.TYPE;static matches=mr(r);matches=q.matches;constructor(t,n){super(t,n),this.name=q.TYPE}static sub(t){return V(`${r}.${t}`)}},Ge=r=>{if(r==null||typeof r!="object")return!1;const e=r;if(e.discriminator!==We)return!1;if(!("type"in e))throw new Error(`X Error is missing its type property: ${JSON.stringify(e)}`);return!0},j="unknown",ue="nil";class yr{providers=[];register(e){this.providers.push(e)}encode(e){if(e==null)return{type:ue,data:""};if(Ge(e))for(const t of this.providers){const n=t.encode(e);if(n!=null)return n}if(e instanceof Error)return{type:j,data:e.message};if(typeof e=="string")return{type:j,data:e};try{return{type:j,data:JSON.stringify(e)}}catch{return{type:j,data:"unable to encode error information"}}}decode(e){if(e==null||e.type===ue)return null;if(e.type===j)return new le(e.data);for(const t of this.providers){const n=t.decode(e);if(n!=null)return n}return new le(e.data)}}const me=gr("synnax-error-registry",()=>new yr),pr=({encode:r,decode:e})=>me().register({encode:r,decode:e}),wr=r=>me().encode(r),br=r=>r==null?null:me().decode(r);class le extends V("unknown"){}const Or=s.z.object({type:s.z.string(),data:s.z.string()});class Tr extends V("canceled"){}class vr extends V("not_implemented"){}const D=Object.freeze(Object.defineProperty({__proto__:null,Canceled:Tr,NONE:ue,NotImplemented:vr,UNKNOWN:j,Unknown:le,createTyped:V,decode:br,encode:wr,isTyped:Ge,payloadZ:Or,register:pr},Symbol.toStringTag,{value:"Module"}));s.z.string().regex(/^(?:$|(?:\/(?:[^~/]|~0|~1)*)+)$/,"must be a valid JSON pointer (RFC 6901)");s.z.union([s.z.string(),s.z.number(),s.z.boolean(),s.z.null()]);s.z.enum(["string","number","boolean","null"]);s.z.object({key:s.z.string(),value:s.z.string()});const Sr=s.uuid();s.object({key:Sr,name:s.string().min(1),color:Ze});s.z.string().regex(/^\d+\.\d+\.\d+(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$/);const Ir=["standard","scientific","engineering"];s.z.enum(Ir);const Nr=s.z.union([s.z.string(),s.z.number()]);s.z.record(Nr,s.z.unknown());const Er=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser";Er();const zr=["macOS","Windows","Linux"],xr=["macos","windows","linux"],Mr={macos:"macOS",windows:"Windows",linux:"Linux"};s.z.enum(zr).or(s.z.enum(xr).transform(r=>Mr[r]));s.z.enum(["success","info","warning","error","loading","disabled"]);s.z.object({stack:s.z.string(),error:s.z.instanceof(Error)});const Ur=(...r)=>r.map(Ve).join(""),Ve=r=>(r.endsWith("/")||(r+="/"),r.startsWith("/")&&(r=r.slice(1)),r),Ar=r=>r.endsWith("/")?r.slice(0,-1):r,Cr=(r,e="")=>r===null?"":`?${Object.entries(r).filter(([,t])=>t==null?!1:Array.isArray(t)?t.length>0:!0).map(([t,n])=>`${e}${t}=${n}`).join("&")}`;class Z{protocol;host;port;path;constructor({host:e,port:t,protocol:n="",pathPrefix:i=""}){this.protocol=n,this.host=e,this.port=t,this.path=Ve(i)}replace(e){return new Z({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new Z({...this,pathPrefix:Ur(this.path,e)})}toString(){return Ar(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}static UNKNOWN=new Z({host:"unknown",port:0})}s.z.int().min(0).max(ht);class H extends D.createTyped("freighter"){}class P extends H.sub("eof"){constructor(){super("EOF")}}class k extends H.sub("stream_closed"){constructor(){super("StreamClosed")}}class Y extends H.sub("unreachable"){url;constructor(e={}){const{message:t="Unreachable",url:n=Z.UNKNOWN}=e;super(t),this.url=n}}const Br=r=>{if(!r.type.startsWith(H.TYPE))return null;if(P.matches(r))return{type:P.TYPE,data:"EOF"};if(k.matches(r))return{type:k.TYPE,data:"StreamClosed"};if(Y.matches(r))return{type:Y.TYPE,data:"Unreachable"};throw new Error(`Unknown error type: ${r.type}: ${r.message}`)},Dr=r=>{if(!r.type.startsWith(H.TYPE))return null;switch(r.type){case P.TYPE:return new P;case k.TYPE:return new k;case Y.TYPE:return new Y;default:throw new D.Unknown(`Unknown error type: ${r.data}`)}};D.register({encode:Br,decode:Dr});class He{middleware=[];use(...e){this.middleware.push(...e)}async executeMiddleware(e,t){let n=0;const i=async o=>{if(n===this.middleware.length)return await t(o);const c=this.middleware[n];return n++,await c(o,i)};return await i(e)}}const Je="Content-Type",Rr=new Set(["ECONNREFUSED","ECONNRESET","ETIMEDOUT","EPIPE","UND_ERR_CONNECT_TIMEOUT","UND_ERR_SOCKET"]),Lr=r=>{const e=r?.cause?.code??r?.code??r?.errno;if(typeof e=="string"&&Rr.has(e))return!0;if(r.name==="TypeError"){const t=String(r.message||"").toLowerCase();if(/load failed|failed to fetch|networkerror|network error/.test(t))return typeof navigator<"u"&&navigator.onLine===!1,!0}return r?.name==="AbortError"||r?.code==="ABORT_ERR",!1},$r=400;class Pr extends He{endpoint;encoder;constructor(e,t,n=!1){return super(),this.endpoint=e.replace({protocol:n?"https":"http"}),this.encoder=t,new Proxy(this,{get:(i,o,c)=>o==="endpoint"?this.endpoint:Reflect.get(i,o,c)})}get headers(){return{[Je]:this.encoder.contentType}}async send(e,t,n,i){t=n?.parse(t);let o=null;const c=this.endpoint.child(e),f={};f.method="POST",f.body=this.encoder.encode(t??{});const[,w]=await this.executeMiddleware({target:c.toString(),protocol:this.endpoint.protocol,params:{},role:"client"},async h=>{const g={...h,params:{}};f.headers={...this.headers,...h.params};let b;try{b=await fetch(h.target,f)}catch(O){if(!(O instanceof Error))throw O;return[g,Lr(O)?new Y({url:c}):O]}const d=await b.arrayBuffer();if(b?.ok)return i!=null&&(o=this.encoder.decode(d,i)),[g,null];try{if(b.status!==$r)return[g,new Error(b.statusText)];const O=this.encoder.decode(d,D.payloadZ),N=D.decode(O);return[g,N]}catch(O){return[g,new Error(`[freighter] - failed to decode error: ${b.statusText}: ${O.message}`)]}});if(w!=null)return[null,w];if(o==null)throw new Error("Response must be defined");return[o,null]}}const kr=(r,e)=>{class t{wrapped;constructor(i){this.wrapped=i}use(...i){this.wrapped.use(...i)}async send(i,o,c,f){const w=new er.Breaker(e);do{const[h,g]=await this.wrapped.send(i,o,c,f);if(g==null)return[h,null];if(!Y.matches(g))return[null,g];if(console.warn(`[freighter] ${w.retryMessage}`,g),!await w.wait())return[h,g]}while(!0)}}return new t(r)},Yr=async(r,e,t,n,i)=>{const[o,c]=await r.send(e,t,n,i);if(c!=null)throw c;return o},jr=s.z.object({type:s.z.enum(["data","close","open"]),payload:s.z.unknown(),error:s.z.optional(D.payloadZ)});class Fr{codec;reqSchema;resSchema;ws;serverClosed;sendClosed;receiveDataQueue=[];receiveCallbacksQueue=[];constructor(e,t,n,i){this.codec=t,this.reqSchema=n,this.resSchema=i,this.ws=e,this.sendClosed=!1,this.serverClosed=null,this.listenForMessages()}async receiveOpenAck(){const e=await this.receiveMsg();if(e.type!=="open"){if(e.error==null)throw new Error("Message error must be defined");return D.decode(e.error)}return null}send(e){if(this.serverClosed!=null)return new P;if(this.sendClosed)throw new k;return this.ws.send(this.codec.encode({type:"data",payload:e})),null}async receive(){if(this.serverClosed!=null)return[null,this.serverClosed];const e=await this.receiveMsg();if(e.type==="close"){if(e.error==null)throw new Error("Message error must be defined");if(this.serverClosed=D.decode(e.error),this.serverClosed==null)throw new 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;const e={type:"close"};try{this.ws.send(this.codec.encode(e))}finally{this.sendClosed=!0}}async receiveMsg(){const e=this.receiveDataQueue.shift();return e??await new Promise((t,n)=>this.receiveCallbacksQueue.push({resolve:t,reject:n}))}addMessage(e){const t=this.receiveCallbacksQueue.shift();t!=null?t.resolve(e):this.receiveDataQueue.push(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,jr))}onClose(e){this.addMessage({type:"close",error:{type:e.code===Zr?P.TYPE:k.TYPE,data:""}})}}const qr="freighterctx",Zr=1e3;class Q extends He{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(e){const t=new Q(this.baseUrl,e,this.secure);return t.use(...this.middleware),t}async stream(e,t,n){let i;const[,o]=await this.executeMiddleware({target:e,protocol:"websocket",params:{},role:"client"},async c=>{const f=new WebSocket(this.buildURL(e,c)),w={...c,params:{}};f.binaryType=Q.MESSAGE_TYPE;const h=await this.wrapSocket(f,t,n);return h instanceof Error?[w,h]:(i=h,[w,null])});if(o!=null)throw o;return i}buildURL(e,t){const n=Cr({[Je]:this.encoder.contentType,...t.params},qr);return this.baseUrl.child(e).toString()+n}async wrapSocket(e,t,n){return await new Promise(i=>{e.onopen=()=>{const o=new Fr(e,this.encoder,t,n);o.receiveOpenAck().then(c=>{c!=null?i(c):i(o)}).catch(c=>i(c))},e.onerror=o=>{const c=o;i(new Error(c.message))}})}}exports.EOF=P;exports.HTTPClient=Pr;exports.StreamClosed=k;exports.Unreachable=Y;exports.WebSocketClient=Q;exports.sendRequired=Yr;exports.unaryWithBreaker=kr;
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(`
10
+ `)}decodeString(e,t){let[n,...r]=e.trim().split(`
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;