@synnaxlabs/freighter 0.45.1 → 0.47.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.
Files changed (42) hide show
  1. package/.turbo/turbo-build.log +17 -0
  2. package/dist/eslint.config.d.ts +3 -0
  3. package/dist/eslint.config.d.ts.map +1 -0
  4. package/dist/freighter.cjs +4 -4
  5. package/dist/freighter.js +780 -691
  6. package/dist/src/alamos.d.ts.map +1 -0
  7. package/dist/src/errors.d.ts.map +1 -0
  8. package/dist/{errors.spec.d.ts.map → src/errors.spec.d.ts.map} +1 -1
  9. package/dist/src/http.d.ts.map +1 -0
  10. package/dist/{http.spec.d.ts.map → src/http.spec.d.ts.map} +1 -1
  11. package/dist/src/index.d.ts.map +1 -0
  12. package/dist/src/middleware.d.ts.map +1 -0
  13. package/dist/src/stream.d.ts.map +1 -0
  14. package/dist/src/transport.d.ts.map +1 -0
  15. package/dist/src/unary.d.ts.map +1 -0
  16. package/dist/src/websocket.d.ts.map +1 -0
  17. package/dist/{websocket.spec.d.ts.map → src/websocket.spec.d.ts.map} +1 -1
  18. package/package.json +11 -11
  19. package/src/http.ts +1 -1
  20. package/tsconfig.json +1 -1
  21. package/dist/alamos.d.ts.map +0 -1
  22. package/dist/errors.d.ts.map +0 -1
  23. package/dist/http.d.ts.map +0 -1
  24. package/dist/index.d.ts.map +0 -1
  25. package/dist/middleware.d.ts.map +0 -1
  26. package/dist/stream.d.ts.map +0 -1
  27. package/dist/transport.d.ts.map +0 -1
  28. package/dist/unary.d.ts.map +0 -1
  29. package/dist/websocket.d.ts.map +0 -1
  30. /package/dist/{alamos.d.ts → src/alamos.d.ts} +0 -0
  31. /package/dist/{errors.d.ts → src/errors.d.ts} +0 -0
  32. /package/dist/{errors.spec.d.ts → src/errors.spec.d.ts} +0 -0
  33. /package/dist/{http.d.ts → src/http.d.ts} +0 -0
  34. /package/dist/{http.spec.d.ts → src/http.spec.d.ts} +0 -0
  35. /package/dist/{index.d.ts → src/index.d.ts} +0 -0
  36. /package/dist/{middleware.d.ts → src/middleware.d.ts} +0 -0
  37. /package/dist/{stream.d.ts → src/stream.d.ts} +0 -0
  38. /package/dist/{transport.d.ts → src/transport.d.ts} +0 -0
  39. /package/dist/{unary.d.ts → src/unary.d.ts} +0 -0
  40. /package/dist/{websocket.d.ts → src/websocket.d.ts} +0 -0
  41. /package/dist/{websocket.spec.d.ts → src/websocket.spec.d.ts} +0 -0
  42. /package/{eslint.config.js → eslint.config.ts} +0 -0
@@ -0,0 +1,17 @@
1
+
2
+ > @synnaxlabs/freighter@0.47.0 build /home/runner/work/synnax/synnax/freighter/ts
3
+ > tsc --noEmit && vite build
4
+
5
+  Synnax - Production mode
6
+ vite v7.1.5 building for production...
7
+ transforming...
8
+ ✓ 36 modules transformed.
9
+ rendering chunks...
10
+
11
+ [vite:dts] Start generate declaration files...
12
+ computing gzip size...
13
+ dist/freighter.js 114.73 kB │ gzip: 27.14 kB
14
+ [vite:dts] Declaration files built in 1717ms.
15
+
16
+ dist/freighter.cjs 56.81 kB │ gzip: 16.87 kB
17
+ ✓ built in 2.09s
@@ -0,0 +1,3 @@
1
+ import { default as synnaxConfig } from 'eslint-config-synnaxlabs';
2
+ export default synnaxConfig;
3
+ //# sourceMappingURL=eslint.config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eslint.config.d.ts","sourceRoot":"","sources":["../eslint.config.ts"],"names":[],"mappings":"AASA,OAAO,YAAY,MAAM,0BAA0B,CAAC;AAEpD,eAAe,YAAY,CAAC"}
@@ -1,6 +1,6 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("zod"),Ke=n=>{const e=n.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=n=>{const e=(t,r=ae)=>{if(typeof t=="string")return n(t);if(Array.isArray(t))return t.map(c=>e(c,r));if(!re(t))return t;r=tt(r);const i={},a=t;return"toJSON"in a&&typeof a.toJSON=="function"?e(a.toJSON(),r):(Object.keys(a).forEach(c=>{let g=a[c];const y=n(c);r.recursive&&(re(g)?ye(g)||(g=e(g,r)):r.recursiveInArray&&me(g)&&(g=[...g].map(f=>{let m=f;return re(f)?ye(m)||(m=e(f,r)):me(f)&&(m=e({key:f},r).key),m}))),i[y]=g}),i)};return e},ze=Ne(Ke),Qe=n=>n.replace(/([a-z0-9])([A-Z])/g,(e,t,r)=>`${t}_${r.toLowerCase()}`),_e=Ne(Qe),et=[Number,String,Uint8Array],ae={recursive:!0,recursiveInArray:!0},tt=(n=ae)=>(n.recursive==null?n=ae:n.recursiveInArray??=!1,n),me=n=>n!=null&&Array.isArray(n),re=n=>n!=null&&typeof n=="object"&&!Array.isArray(n),ye=n=>et.some(e=>n instanceof e);let nt=class{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 r=JSON.parse(e),i=ze(r);return t!=null?t.parse(i):i}encodeString(e){const t=_e(e);return JSON.stringify(t,(r,i)=>ArrayBuffer.isView(i)?Array.from(i):typeof i=="bigint"?i.toString():i)}};const oe=new nt,N=n=>n!=null&&typeof n=="object"&&"value"in n;let Y=class{value;constructor(e){this.value=e}valueOf(){return this.value}toJSON(){return this.value}toString(){return this.value.toString()}};const rt=n=>n!=null&&typeof n=="object"&&"toString"in n,st=(n,e=!1)=>{const t=rt(n)?"stringer":typeof n;let r;switch(t){case"string":r=(i,a)=>i.localeCompare(a);break;case"stringer":r=(i,a)=>i.toString().localeCompare(a.toString());break;case"number":r=(i,a)=>Number(i)-Number(a);break;case"bigint":r=(i,a)=>BigInt(i)-BigInt(a)>0n?1:-1;break;case"boolean":r=(i,a)=>Number(i)-Number(a);break;case"undefined":r=()=>0;break;default:return console.warn(`sortFunc: unknown type ${t}`),()=>-1}return e?it(r):r},it=n=>(e,t)=>n(t,e),Q=s.z.tuple([s.z.number(),s.z.number()]);s.z.tuple([s.z.bigint(),s.z.bigint()]);const Ee=s.z.object({width:s.z.number(),height:s.z.number()}),at=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()}),ot=["width","height"];s.z.enum(ot);const ut=["start","center","end"],lt=["signedWidth","signedHeight"];s.z.enum(lt);const X=s.z.object({x:s.z.number(),y:s.z.number()}),ct=s.z.object({clientX:s.z.number(),clientY:s.z.number()}),ht=["x","y"],xe=s.z.enum(ht),Ae=["top","right","bottom","left"];s.z.enum(Ae);const ft=["left","right"],Ue=s.z.enum(ft),dt=["top","bottom"],Me=s.z.enum(dt),Ce=["center"],we=s.z.enum(Ce),gt=[...Ae,...Ce],$e=s.z.enum(gt);s.z.enum(ut);const pt=["first","last"];s.z.enum(pt);const mt=s.z.object({lower:s.z.number(),upper:s.z.number()}),yt=s.z.object({lower:s.z.bigint(),upper:s.z.bigint()});s.z.union([mt,Q]);s.z.union([yt,Q]);s.z.enum([...xe.options,...$e.options]);s.z.enum(["x","left","right"]);s.z.enum(["y","top","bottom"]);s.z.union([xe,$e,s.z.instanceof(String)]);const _=n=>(e,t)=>{if(typeof e=="bigint"){if(wt(t))return n(e,BigInt(t));const r=n(Number(e),Number(t));return typeof r=="number"?BigInt(Math.round(r)):r}return n(Number(e),Number(t))},ee=_((n,e)=>n-e),te=_((n,e)=>n+e),wt=n=>typeof n=="bigint"?!0:Number.isInteger(n),A=_((n,e)=>n*e),ne=_((n,e)=>n/e),B=(n,e,t)=>{const r={};if(typeof e=="object"&&(t=e,e=void 0),t={makeValid:!0,...t},typeof n=="number"||typeof n=="bigint")e!=null?(r.lower=n,r.upper=e):(r.lower=typeof n=="bigint"?0n:0,r.upper=n);else if(Array.isArray(n)){if(n.length!==2)throw new Error("bounds: expected array of length 2");[r.lower,r.upper]=n}else r.lower=n.lower,r.upper=n.upper;return t?.makeValid?bt(r):r},bt=n=>n.lower>n.upper?{lower:n.upper,upper:n.lower}:n,be=(n,e)=>{const t=B(n);return e<t.lower?t.lower:e>=t.upper?t.upper-(typeof t.upper=="number"?1:1n):e};s.z.object({x:Ue.or(we),y:Me.or(we)});const Ot=s.z.object({x:Ue,y:Me}),Tt=Object.freeze({x:"left",y:"top"}),vt=(n,e)=>n.x===e.x&&n.y===e.y,Oe=s.z.union([s.z.number(),X,Q,Ee,at,ct]),It=(n,e)=>{if(typeof n=="string"){if(e===void 0)throw new Error("The y coordinate must be given.");return n==="x"?{x:e,y:0}:{x:0,y:e}}return typeof n=="number"?{x:n,y:e??n}:Array.isArray(n)?{x:n[0],y:n[1]}:"signedWidth"in n?{x:n.signedWidth,y:n.signedHeight}:"clientX"in n?{x:n.clientX,y:n.clientY}:"width"in n?{x:n.width,y:n.height}:{x:n.x,y:n.y}},Te=Object.freeze({x:0,y:0}),G=s.z.union([s.z.number(),s.z.string()]);s.z.object({top:G,left:G,width:G,height:G});s.z.object({left:s.z.number(),top:s.z.number(),right:s.z.number(),bottom:s.z.number()});s.z.object({one:X,two:X,root:Ot});const fe=(n,e,t=0,r=0,i)=>{const a={one:{...Te},two:{...Te},root:i??Tt};if(typeof n=="number"){if(typeof e!="number")throw new Error("Box constructor called with invalid arguments");return a.one={x:n,y:e},a.two={x:a.one.x+t,y:a.one.y+r},a}return"one"in n&&"two"in n&&"root"in n?{...n,root:i??n.root}:("getBoundingClientRect"in n&&(n=n.getBoundingClientRect()),"left"in n?(a.one={x:n.left,y:n.top},a.two={x:n.right,y:n.bottom},a):(a.one=n,e==null?a.two={x:a.one.x+t,y:a.one.y+r}:typeof e=="number"?a.two={x:a.one.x+e,y:a.one.y+t}:"width"in e?a.two={x:a.one.x+e.width,y:a.one.y+e.height}:"signedWidth"in e?a.two={x:a.one.x+e.signedWidth,y:a.one.y+e.signedHeight}:a.two=e,a))},se=n=>{const e=fe(n);return{lower:e.one.x,upper:e.two.x}},ie=n=>{const e=fe(n);return{lower:e.one.y,upper:e.two.y}},St=n=>typeof n!="object"||n==null?!1:"one"in n&&"two"in n&&"root"in n,Nt=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()});s.z.union([Ee,Nt,X,Q]);const zt=(n,e,t)=>e!==void 0&&n<e?e:t!==void 0&&n>t?t:n;s.z.object({offset:Oe,scale:Oe});s.z.object({offset:s.z.number(),scale:s.z.number()});const Et=n=>(e,t,r,i)=>t==="dimension"?[e,r]:[e,i?r-n:r+n],xt=n=>(e,t,r,i)=>[e,i?r/n:r*n],At=n=>(e,t,r)=>{if(e===null)return[n,r];const{lower:i,upper:a}=e,{lower:c,upper:g}=n,y=a-i,f=g-c;if(t==="dimension")return[n,r*(f/y)];const m=(r-i)*(f/y)+c;return[n,m]},Ut=n=>(e,t,r)=>[n,r],Mt=()=>(n,e,t)=>{if(n===null)throw new Error("cannot invert without bounds");if(e==="dimension")return[n,t];const{lower:r,upper:i}=n;return[n,i-(t-r)]},Ct=n=>(e,t,r)=>{const{lower:i,upper:a}=n;return r=zt(r,i,a),[e,r]};let ve=class k{ops=[];currBounds=null;currType=null;reversed=!1;constructor(){this.ops=[]}static translate(e){return new k().translate(e)}static magnify(e){return new k().magnify(e)}static scale(e,t){return new k().scale(e,t)}translate(e){const t=this.new(),r=Et(e);return r.type="translate",t.ops.push(r),t}magnify(e){const t=this.new(),r=xt(e);return r.type="magnify",t.ops.push(r),t}scale(e,t){const r=B(e,t),i=this.new(),a=At(r);return a.type="scale",i.ops.push(a),i}clamp(e,t){const r=B(e,t),i=this.new(),a=Ct(r);return a.type="clamp",i.ops.push(a),i}reBound(e,t){const r=B(e,t),i=this.new(),a=Ut(r);return a.type="re-bound",i.ops.push(a),i}invert(){const e=Mt();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 k;return e.ops=this.ops.slice(),e.reversed=this.reversed,e}exec(e,t){return this.currBounds=null,this.ops.reduce(([r,i],a)=>a(r,e,i,this.reversed),[null,t])[1]}reverse(){const e=this.new();e.ops.reverse();const t=[];return e.ops.forEach((r,i)=>{if(r.type==="scale"||t.some(([c,g])=>i>=c&&i<=g))return;const a=e.ops.findIndex((c,g)=>c.type==="scale"&&g>i);a!==-1&&t.push([i,a])}),t.forEach(([r,i])=>{const a=e.ops.slice(r,i);a.unshift(e.ops[i]),e.ops.splice(r,i-r+1,...a)}),e.reversed=!e.reversed,e}get transform(){return{scale:this.dim(1),offset:this.pos(0)}}static IDENTITY=new k},er=class x{x;y;currRoot;constructor(e=new ve,t=new ve,r=null){this.x=e,this.y=t,this.currRoot=r}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 r=It(e,t),i=this.copy();return i.x=this.x.translate(r.x),i.y=this.y.translate(r.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(St(e)){const r=this.currRoot;return t.currRoot=e.root,r!=null&&!vt(r,e.root)&&(r.x!==e.root.x&&(t.x=t.x.invert()),r.y!==e.root.y&&(t.y=t.y.invert())),t.x=t.x.scale(se(e)),t.y=t.y.scale(ie(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(se(e)),t.y=this.y.reBound(ie(e)),t}clamp(e){const t=this.copy();return t.x=this.x.clamp(se(e)),t.y=this.y.clamp(ie(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 fe(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},Be=(n,e=21)=>(t=e)=>{let r="",i=t|0;for(;i--;)r+=n[Math.random()*n.length|0];return r};const Re="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",$t=`0123456789${Re}`,Bt=11,Rt=Be(Re,1),Dt=Be($t,Bt-1),Lt=()=>`${Rt()}${Dt()}`,kt=(n,e)=>t=>t instanceof e||typeof t=="object"&&t!==null&&"discriminator"in t&&t.discriminator===n,Pt=s.z.enum(["static","dynamic"]),jt=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)])]),De=(n,e)=>{const t=new o(e);if(![p.DAY,p.HOUR,p.MINUTE,p.SECOND,p.MILLISECOND,p.MICROSECOND,p.NANOSECOND].some(i=>i.equals(t)))throw new Error("Invalid argument for remainder. Must be an even TimeSpan or Timestamp");const r=n.valueOf()%t.valueOf();return n instanceof o?new o(r):new p(r)};class o extends Y{constructor(e,t="UTC"){if(e==null)super(o.now().valueOf());else if(e instanceof Date)super(BigInt(e.getTime())*o.MILLISECOND.valueOf());else if(typeof e=="string")super(o.parseDateTimeString(e,t).valueOf());else if(Array.isArray(e))super(o.parseDate(e));else{let r=0n;e instanceof Number&&(e=e.valueOf()),t==="local"&&(r=o.utcOffset.valueOf()),typeof e=="number"&&(isFinite(e)?e=Math.trunc(e):(isNaN(e)&&(e=0),e===1/0?e=o.MAX:e=o.MIN)),N(e)&&(e=e.value),super(BigInt(e.valueOf())+r)}}static parseDate([e=1970,t=1,r=1]){const i=new Date(e,t-1,r,0,0,0,0);return new o(BigInt(i.getTime())*o.MILLISECOND.valueOf()).truncate(o.DAY).valueOf()}valueOf(){return this.value}static parseTimeString(e,t="UTC"){const[r,i,a]=e.split(":");let c="00",g="00";a!=null&&([c,g]=a.split("."));let y=o.hours(parseInt(r??"00")).add(o.minutes(parseInt(i??"00"))).add(o.seconds(parseInt(c??"00"))).add(o.milliseconds(parseInt(g??"00")));return t==="local"&&(y=y.add(o.utcOffset)),y.valueOf()}static parseDateTimeString(e,t="UTC"){if(!e.includes("/")&&!e.includes("-"))return o.parseTimeString(e,t);const r=new Date(e);return e.includes(":")||r.setUTCHours(0,0,0,0),new o(BigInt(r.getTime())*o.MILLISECOND.valueOf(),t).valueOf()}fString(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)}}toISOString(e="UTC"){return e==="UTC"?this.date().toISOString():this.sub(o.utcOffset).date().toISOString()}timeString(e=!1,t="UTC"){const r=this.toISOString(t);return e?r.slice(11,23):r.slice(11,19)}dateString(){const e=this.date(),t=e.toLocaleString("default",{month:"short"}),r=e.toLocaleString("default",{day:"numeric"});return`${t} ${r}`}static get utcOffset(){return new p(BigInt(new Date().getTimezoneOffset())*o.MINUTE.valueOf())}static since(e){return new o().span(e)}date(){return new Date(this.milliseconds)}equals(e){return this.valueOf()===new o(e).valueOf()}span(e){return this.range(e).span}range(e){return new q(this,e).makeValid()}spanRange(e){return this.range(this.add(e)).makeValid()}get isZero(){return this.valueOf()===0n}after(e){return this.valueOf()>new o(e).valueOf()}afterEq(e){return this.valueOf()>=new o(e).valueOf()}before(e){return this.valueOf()<new o(e).valueOf()}beforeEq(e){return this.valueOf()<=new o(e).valueOf()}add(e){return new o(te(this.valueOf(),new p(e).valueOf()))}sub(e){return new o(ee(this.valueOf(),new p(e).valueOf()))}get hours(){return Number(this.valueOf())/Number(p.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(p.MINUTE.valueOf())}get days(){return Number(this.valueOf())/Number(p.DAY.valueOf())}get seconds(){return Number(this.valueOf())/Number(p.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(o.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(o.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get year(){return this.date().getUTCFullYear()}setYear(e){const t=this.date();return t.setUTCFullYear(e),new o(t)}get month(){return this.date().getUTCMonth()}setMonth(e){const t=this.date();return t.setUTCMonth(e),new o(t)}get day(){return this.date().getUTCDate()}setDay(e){const t=this.date();return t.setUTCDate(e),new o(t)}get hour(){return this.date().getUTCHours()}get localHour(){return this.date().getHours()}setLocalHour(e){const t=this.date();return t.setHours(e),new o(t)}setHour(e){const t=this.date();return t.setUTCHours(e),new o(t)}get minute(){return this.date().getUTCMinutes()}setMinute(e){const t=this.date();return t.setUTCMinutes(e),new o(t)}get second(){return this.date().getUTCSeconds()}setSecond(e){const t=this.date();return t.setUTCSeconds(e),new o(t)}get millisecond(){return this.date().getUTCMilliseconds()}setMillisecond(e){const t=this.date();return t.setUTCMilliseconds(e),new o(t)}toString(){return this.date().toISOString()}remainder(e){return De(this,e)}get isToday(){return this.truncate(p.DAY).equals(o.now().truncate(p.DAY))}truncate(e){return this.sub(this.remainder(e))}static now(){return new o(new Date)}static max(...e){let t=o.MIN;for(const r of e){const i=new o(r);i.after(t)&&(t=i)}return t}static min(...e){let t=o.MAX;for(const r of e){const i=new o(r);i.before(t)&&(t=i)}return t}static nanoseconds(e,t="UTC"){return new o(e,t)}static NANOSECOND=o.nanoseconds(1);static microseconds(e,t="UTC"){return o.nanoseconds(e*1e3,t)}static MICROSECOND=o.microseconds(1);static milliseconds(e,t="UTC"){return o.microseconds(e*1e3,t)}static MILLISECOND=o.milliseconds(1);static seconds(e,t="UTC"){return o.milliseconds(e*1e3,t)}static SECOND=o.seconds(1);static minutes(e,t="UTC"){return o.seconds(e*60,t)}static MINUTE=o.minutes(1);static hours(e,t="UTC"){return o.minutes(e*60,t)}static HOUR=o.hours(1);static days(e,t="UTC"){return o.hours(e*24,t)}static DAY=o.days(1);static MAX=new o((1n<<63n)-1n);static MIN=new o(0);static ZERO=new o(0);static z=s.z.union([s.z.instanceof(o),s.z.object({value:s.z.bigint()}).transform(e=>new o(e.value)),s.z.string().transform(e=>new o(BigInt(e))),s.z.number().transform(e=>new o(e)),s.z.bigint().transform(e=>new o(e)),s.z.date().transform(e=>new o(e)),s.z.custom(e=>e instanceof p).transform(e=>new o(e)),jt.transform(e=>new o(e))]);static sort(e,t){return Number(e.valueOf()-t.valueOf())}}let p=class l extends Y{constructor(e){typeof e=="number"&&(e=Math.trunc(e.valueOf())),N(e)&&(e=e.value),super(BigInt(e.valueOf()))}static fromSeconds(e){return e instanceof l?e:e instanceof S?e.period:e instanceof o?new l(e):(N(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 S?e.period:e instanceof o?new l(e):(N(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 De(this,e)}truncate(e){return new l(BigInt(Math.trunc(Number(this.valueOf()/e.valueOf())))*e.valueOf())}toString(){const e=this.truncate(l.DAY),t=this.truncate(l.HOUR),r=this.truncate(l.MINUTE),i=this.truncate(l.SECOND),a=this.truncate(l.MILLISECOND),c=this.truncate(l.MICROSECOND),g=this.truncate(l.NANOSECOND),y=e,f=t.sub(e),m=r.sub(t),b=i.sub(r),h=a.sub(i),O=c.sub(a),E=g.sub(c);let U="";return y.isZero||(U+=`${y.days}d `),f.isZero||(U+=`${f.hours}h `),m.isZero||(U+=`${m.minutes}m `),b.isZero||(U+=`${b.seconds}s `),h.isZero||(U+=`${h.milliseconds}ms `),O.isZero||(U+=`${O.microseconds}µs `),E.isZero||(U+=`${E.nanoseconds}ns`),U.trim()}mult(e){return new l(A(this.valueOf(),e))}div(e){return new l(ne(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(A(e,1e3))}static MICROSECOND=l.microseconds(1);static milliseconds(e=1){return l.microseconds(A(e,1e3))}static MILLISECOND=l.milliseconds(1);static seconds(e=1){return l.milliseconds(A(e,1e3))}static SECOND=l.seconds(1);static minutes(e=1){return l.seconds(A(e,60))}static MINUTE=l.minutes(1);static hours(e){return l.minutes(A(e,60))}static HOUR=l.hours(1);static days(e){return l.hours(A(e,24))}static DAY=l.days(1);static MAX=new l((1n<<63n)-1n);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(o).transform(e=>new l(e)),s.z.custom(e=>e instanceof S).transform(e=>new l(e))])};class S extends Y{constructor(e){N(e)&&(e=e.value),super(e.valueOf())}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new S(e).valueOf()}get period(){return p.seconds(1/this.valueOf())}sampleCount(e){return new p(e).seconds*this.valueOf()}byteCount(e,t){return this.sampleCount(e)*new v(t).valueOf()}span(e){return p.seconds(e/this.valueOf())}byteSpan(e,t){return this.span(e.valueOf()/new v(t).valueOf())}add(e){return new S(te(this.valueOf(),new S(e).valueOf()))}sub(e){return new S(ee(this.valueOf(),new S(e).valueOf()))}mult(e){return new S(A(this.valueOf(),e))}div(e){return new S(ne(this.valueOf(),e))}static hz(e){return new S(e)}static khz(e){return S.hz(e*1e3)}static z=s.z.union([s.z.number().transform(e=>new S(e)),s.z.instanceof(S)])}let v=class I extends Y{constructor(e){N(e)&&(e=e.value),super(e.valueOf())}length(e){return e.valueOf()/this.valueOf()}size(e){return new ue(e*this.valueOf())}add(e){return new I(te(this.valueOf(),new I(e).valueOf()))}sub(e){return new I(ee(this.valueOf(),new I(e).valueOf()))}mult(e){return new I(A(this.valueOf(),e))}div(e){return new I(ne(this.valueOf(),e))}static UNKNOWN=new I(0);static BIT128=new I(16);static BIT64=new I(8);static BIT32=new I(4);static BIT16=new I(2);static BIT8=new I(1);static z=s.z.union([s.z.number().transform(e=>new I(e)),s.z.instanceof(I)])},q=class z{start;end;constructor(e,t){typeof e=="object"&&"start"in e?(this.start=new o(e.start),this.end=new o(e.end)):(this.start=new o(e),this.end=new o(t))}get span(){return new p(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.span.isZero}get numeric(){return{start:Number(this.start.valueOf()),end:Number(this.end.valueOf())}}swap(){return new z(this.end,this.start)}get numericBounds(){return{lower:Number(this.start.valueOf()),upper:Number(this.end.valueOf())}}equals(e,t=p.ZERO){if(t.isZero)return this.start.equals(e.start)&&this.end.equals(e.end);let r=this.start.sub(e.start).valueOf(),i=this.end.sub(e.end).valueOf();return r<0&&(r=-r),i<0&&(i=-i),r<=t.valueOf()&&i<=t.valueOf()}toString(){return`${this.start.toString()} - ${this.end.toString()}`}toPrettyString(){return`${this.start.fString("preciseDate")} - ${this.span.toString()}`}overlapsWith(e,t=p.ZERO){e=e.makeValid();const r=this.makeValid();if(this.equals(e))return!0;if(e.end.equals(r.start)||r.end.equals(e.start))return!1;const i=o.max(r.start,e.start),a=o.min(r.end,e.end);return a.before(i)?!1:new p(a.sub(i)).greaterThanOrEqual(t)}contains(e){return e instanceof z?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const t=new z(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 z(o.min(...e.map(t=>t.start)),o.max(...e.map(t=>t.end)))}static MAX=new z(o.MIN,o.MAX);static MIN=new z(o.MAX,o.MIN);static ZERO=new z(o.ZERO,o.ZERO);static z=s.z.union([s.z.object({start:o.z,end:o.z}).transform(e=>new z(e.start,e.end)),s.z.instanceof(z)]);static sort(e,t){return o.sort(e.start,t.start)||o.sort(e.end,t.end)}static simplify(e){return e.map(t=>t.makeValid()).sort((t,r)=>z.sort(t,r)).reduce((t,r)=>{if(r.isZero)return t;if(t.length===0)return t.push(r),t;const i=t[t.length-1];return i.overlapsWith(r)||i.end.equals(r.start)?i.end=o.max(i.end,r.end):t.push(r),t},[])}},w=class u extends Y{constructor(e){if(N(e)&&(e=e.value),e instanceof u||typeof e=="string"||typeof e.valueOf()=="string")super(e.valueOf());else{const t=u.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=u.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(){return this.valueOf()}get isVariable(){return this.equals(u.JSON)||this.equals(u.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(u.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=u.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}get isUnsignedInteger(){return this.equals(u.UINT8)||this.equals(u.UINT16)||this.equals(u.UINT32)||this.equals(u.UINT64)}get isSignedInteger(){return this.equals(u.INT8)||this.equals(u.INT16)||this.equals(u.INT32)||this.equals(u.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(u.INT32)&&e.equals(u.FLOAT64)||this.equals(u.INT8)&&e.equals(u.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 u.BIG_INT_TYPES.some(e=>e.equals(this))}static UNKNOWN=new u("unknown");static FLOAT64=new u("float64");static FLOAT32=new u("float32");static INT64=new u("int64");static INT32=new u("int32");static INT16=new u("int16");static INT8=new u("int8");static UINT64=new u("uint64");static UINT32=new u("uint32");static UINT16=new u("uint16");static UINT8=new u("uint8");static BOOLEAN=this.UINT8;static TIMESTAMP=new u("timestamp");static UUID=new u("uuid");static STRING=new u("string");static JSON=new u("json");static ARRAY_CONSTRUCTORS=new Map([[u.UINT8.toString(),Uint8Array],[u.UINT16.toString(),Uint16Array],[u.UINT32.toString(),Uint32Array],[u.UINT64.toString(),BigUint64Array],[u.FLOAT32.toString(),Float32Array],[u.FLOAT64.toString(),Float64Array],[u.INT8.toString(),Int8Array],[u.INT16.toString(),Int16Array],[u.INT32.toString(),Int32Array],[u.INT64.toString(),BigInt64Array],[u.TIMESTAMP.toString(),BigInt64Array],[u.STRING.toString(),Uint8Array],[u.JSON.toString(),Uint8Array],[u.UUID.toString(),Uint8Array]]);static ARRAY_CONSTRUCTOR_DATA_TYPES=new Map([[Uint8Array.name,u.UINT8],[Uint16Array.name,u.UINT16],[Uint32Array.name,u.UINT32],[BigUint64Array.name,u.UINT64],[Float32Array.name,u.FLOAT32],[Float64Array.name,u.FLOAT64],[Int8Array.name,u.INT8],[Int16Array.name,u.INT16],[Int32Array.name,u.INT32],[BigInt64Array.name,u.INT64]]);static DENSITIES=new Map([[u.UINT8.toString(),v.BIT8],[u.UINT16.toString(),v.BIT16],[u.UINT32.toString(),v.BIT32],[u.UINT64.toString(),v.BIT64],[u.FLOAT32.toString(),v.BIT32],[u.FLOAT64.toString(),v.BIT64],[u.INT8.toString(),v.BIT8],[u.INT16.toString(),v.BIT16],[u.INT32.toString(),v.BIT32],[u.INT64.toString(),v.BIT64],[u.TIMESTAMP.toString(),v.BIT64],[u.STRING.toString(),v.UNKNOWN],[u.JSON.toString(),v.UNKNOWN],[u.UUID.toString(),v.BIT128]]);static ALL=[u.UNKNOWN,u.FLOAT64,u.FLOAT32,u.INT64,u.INT32,u.INT16,u.INT8,u.UINT64,u.UINT32,u.UINT16,u.UINT8,u.TIMESTAMP,u.UUID,u.STRING,u.JSON];static BIG_INT_TYPES=[u.INT64,u.UINT64,u.TIMESTAMP];static z=s.z.union([s.z.string().transform(e=>new u(e)),s.z.instanceof(u)])},ue=class d extends Y{constructor(e){N(e)&&(e=e.value),super(e.valueOf())}largerThan(e){return N(e)&&(e=e.value),this.valueOf()>e.valueOf()}smallerThan(e){return N(e)&&(e=e.value),this.valueOf()<e.valueOf()}add(e){return N(e)&&(e=e.value),new d(te(this.valueOf(),e.valueOf()))}sub(e){return N(e)&&(e=e.value),new d(ee(this.valueOf(),e.valueOf()))}mult(e){return new d(A(this.valueOf(),e))}div(e){return new d(ne(this.valueOf(),e))}truncate(e){return new d(Math.trunc(this.valueOf()/new d(e).valueOf())*new d(e).valueOf())}remainder(e){return d.bytes(this.valueOf()%new d(e).valueOf())}get gigabytes(){return this.valueOf()/d.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/d.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/d.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/d.TERABYTE.valueOf()}toString(){const e=this.truncate(d.TERABYTE),t=this.truncate(d.GIGABYTE),r=this.truncate(d.MEGABYTE),i=this.truncate(d.KILOBYTE),a=this.truncate(d.BYTE),c=e,g=t.sub(e),y=r.sub(t),f=i.sub(r),m=a.sub(i);let b="";return c.isZero||(b+=`${c.terabytes}TB `),g.isZero||(b+=`${g.gigabytes}GB `),y.isZero||(b+=`${y.megabytes}MB `),f.isZero||(b+=`${f.kilobytes}KB `),(!m.isZero||b==="")&&(b+=`${m.valueOf()}B`),b.trim()}static bytes(e=1){return new d(e)}static BYTE=new d(1);static kilobytes(e=1){return d.bytes(new d(e).valueOf()*1e3)}static KILOBYTE=d.kilobytes(1);static megabytes(e=1){return d.kilobytes(new d(e).valueOf()*1e3)}static MEGABYTE=d.megabytes(1);static gigabytes(e=1){return d.megabytes(new d(e).valueOf()*1e3)}static GIGABYTE=d.gigabytes(1);static terabytes(e){return d.gigabytes(new d(e).valueOf()*1e3)}static TERABYTE=d.terabytes(1);static ZERO=new d(0);static z=s.z.union([s.z.number().transform(e=>new d(e)),s.z.instanceof(d)]);get isZero(){return this.valueOf()===0}};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 Le=n=>{const e=typeof n;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||n instanceof o||n instanceof p||n instanceof Date},Yt=(n,e,t,r=0)=>n.usesBigInt&&!e.usesBigInt?Number(t)-Number(r):!n.usesBigInt&&e.usesBigInt?BigInt(t.valueOf())-BigInt(r.valueOf()):J(t,-r),J=(n,e)=>e==0?n:n==0?e:typeof n=="bigint"&&typeof e=="bigint"||typeof n=="number"&&typeof e=="number"?n+e:Number(n)+Number(e),qt=/^(?:[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 Ft(n){return typeof n=="string"&&qt.test(n)}const T=[];for(let n=0;n<256;++n)T.push((n+256).toString(16).slice(1));function Wt(n,e=0){return(T[n[e+0]]+T[n[e+1]]+T[n[e+2]]+T[n[e+3]]+"-"+T[n[e+4]]+T[n[e+5]]+"-"+T[n[e+6]]+T[n[e+7]]+"-"+T[n[e+8]]+T[n[e+9]]+"-"+T[n[e+10]]+T[n[e+11]]+T[n[e+12]]+T[n[e+13]]+T[n[e+14]]+T[n[e+15]]).toLowerCase()}function Zt(n,e=0){const t=Wt(n,e);if(!Ft(t))throw TypeError("Stringified UUID is invalid");return t}typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const ke=(n,e)=>Zt(n,e),M=-1,Vt=s.z.string().transform(n=>new Uint8Array(atob(n).split("").map(e=>e.charCodeAt(0))).buffer),Gt=s.z.union([s.z.null(),s.z.undefined()]).transform(()=>new Uint8Array().buffer),le=10,Ht=(n,e)=>{if(n==="number"&&!e.isNumeric)throw new Error(`cannot convert series of type ${e.toString()} to number`);if(n==="bigint"&&!e.usesBigInt)throw new Error(`cannot convert series of type ${e.toString()} to bigint`)},Pe="sy_x_telem_series";let je=class C{key;discriminator=Pe;dataType;sampleOffset;gl;_data;timeRange=q.ZERO;alignment=0n;alignmentMultiple=1n;cachedMin;cachedMax;writePos=M;_refCount=0;cachedLength;_cachedIndexes;static crudeZ=s.z.object({timeRange:q.z.optional(),dataType:w.z,alignment:s.z.coerce.bigint().optional(),data:s.z.union([Vt,Gt,s.z.instanceof(ArrayBuffer),s.z.instanceof(Uint8Array)]),glBufferUsage:Pt.optional().default("static").optional()});static z=C.crudeZ.transform(e=>new C(e));constructor(e){Jt(e)&&(e={data:e}),e.data??=[];const{dataType:t,timeRange:r,sampleOffset:i=0,glBufferUsage:a="static",alignment:c=0n,alignmentMultiple:g=1n,key:y=Lt(),data:f}=e;if(Xt(f)){const h=f;this.key=h.key,this.dataType=h.dataType,this.sampleOffset=h.sampleOffset,this.gl=h.gl,this._data=h._data,this.timeRange=h.timeRange,this.alignment=h.alignment,this.alignmentMultiple=h.alignmentMultiple,this.cachedMin=h.cachedMin,this.cachedMax=h.cachedMax,this.writePos=h.writePos,this._refCount=h._refCount,this.cachedLength=h.cachedLength;return}const m=Le(f),b=Array.isArray(f);if(t!=null)this.dataType=new w(t);else{if(f instanceof ArrayBuffer)throw new Error("cannot infer data type from an ArrayBuffer instance when constructing a Series. Please provide a data type.");if(b||m){let h=f;if(!m){if(f.length===0)throw new Error("cannot infer data type from a zero length JS array when constructing a Series. Please provide a data type.");h=f[0]}if(typeof h=="string")this.dataType=w.STRING;else if(typeof h=="number")this.dataType=w.FLOAT64;else if(typeof h=="bigint")this.dataType=w.INT64;else if(typeof h=="boolean")this.dataType=w.BOOLEAN;else if(h instanceof o||h instanceof Date||h instanceof o)this.dataType=w.TIMESTAMP;else if(typeof h=="object")this.dataType=w.JSON;else throw new Error(`cannot infer data type of ${typeof h} when constructing a Series from a JS array`)}else this.dataType=new w(f)}if(!b&&!m)this._data=f;else if(b&&f.length===0)this._data=new this.dataType.Array([]).buffer;else{let h=m?[f]:f;const O=h[0];(O instanceof o||O instanceof Date||O instanceof p)&&(h=h.map(E=>new o(E).valueOf())),this.dataType.equals(w.STRING)?(this.cachedLength=h.length,this._data=new TextEncoder().encode(`${h.join(`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("zod"),et=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)},Ae=r=>{const e=(t,n=ue)=>{if(typeof t=="string")return r(t);if(Array.isArray(t))return t.map(c=>e(c,n));if(!ie(t))return t;n=st(n);const i={},a=t;return"toJSON"in a&&typeof a.toJSON=="function"?e(a.toJSON(),n):(Object.keys(a).forEach(c=>{let d=a[c];const y=r(c);n.recursive&&(ie(d)?Oe(d)||(d=e(d,n)):n.recursiveInArray&&be(d)&&(d=[...d].map(f=>{let g=f;return ie(f)?Oe(g)||(g=e(f,n)):be(f)&&(g=e({key:f},n).key),g}))),i[y]=d}),i)};return e},Ue=Ae(et),tt=r=>r.replace(/([a-z0-9])([A-Z])/g,(e,t,n)=>`${t}_${n.toLowerCase()}`),rt=Ae(tt),nt=[Number,String,Uint8Array],ue={recursive:!0,recursiveInArray:!0},st=(r=ue)=>(r.recursive==null?r=ue:r.recursiveInArray??=!1,r),be=r=>r!=null&&Array.isArray(r),ie=r=>r!=null&&typeof r=="object"&&!Array.isArray(r),Oe=r=>nt.some(e=>r instanceof e);let it=class{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=Ue(n);return t!=null?t.parse(i):i}encodeString(e){const t=rt(e);return JSON.stringify(t,(n,i)=>ArrayBuffer.isView(i)?Array.from(i):typeof i=="bigint"?i.toString():i)}};const le=new it,x=r=>r!=null&&typeof r=="object"&&"value"in r;let F=class{value;constructor(e){this.value=e}valueOf(){return this.value}toJSON(){return this.value}toString(){return this.value.toString()}};const at=r=>r!=null&&typeof r=="object"&&"toString"in r,ot=(r,e=!1)=>{const t=at(r)?"stringer":typeof r;let n;switch(t){case"string":n=(i,a)=>i.localeCompare(a);break;case"stringer":n=(i,a)=>i.toString().localeCompare(a.toString());break;case"number":n=(i,a)=>Number(i)-Number(a);break;case"bigint":n=(i,a)=>BigInt(i)-BigInt(a)>0n?1:-1;break;case"boolean":n=(i,a)=>Number(i)-Number(a);break;case"undefined":n=()=>0;break;default:return console.warn(`sortFunc: unknown type ${t}`),()=>-1}return e?ut(n):n},ut=r=>(e,t)=>r(t,e),ee=s.z.tuple([s.z.number(),s.z.number()]);s.z.tuple([s.z.bigint(),s.z.bigint()]);const Me=s.z.object({width:s.z.number(),height:s.z.number()}),lt=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()}),ct=["width","height"];s.z.enum(ct);const ht=["start","center","end"],ft=["signedWidth","signedHeight"];s.z.enum(ft);const Q=s.z.object({x:s.z.number(),y:s.z.number()}),dt=s.z.object({clientX:s.z.number(),clientY:s.z.number()}),gt=["x","y"],$e=s.z.enum(gt),Ce=["top","right","bottom","left"];s.z.enum(Ce);const pt=["left","right"],Be=s.z.enum(pt),mt=["top","bottom"],Re=s.z.enum(mt),De=["center"],Te=s.z.enum(De),yt=[...Ce,...De],Le=s.z.enum(yt);s.z.enum(ht);const wt=["first","last"];s.z.enum(wt);const bt=s.z.object({lower:s.z.number(),upper:s.z.number()}),Ot=s.z.object({lower:s.z.bigint(),upper:s.z.bigint()});s.z.union([bt,ee]);s.z.union([Ot,ee]);s.z.enum([...$e.options,...Le.options]);s.z.enum(["x","left","right"]);s.z.enum(["y","top","bottom"]);s.z.union([$e,Le,s.z.instanceof(String)]);const te=r=>(e,t)=>{if(typeof e=="bigint"){if(Tt(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))},re=te((r,e)=>r-e),ne=te((r,e)=>r+e),Tt=r=>typeof r=="bigint"?!0:Number.isInteger(r),M=te((r,e)=>r*e),se=te((r,e)=>r/e),D=(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,ve=(r,e)=>{const t=D(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(Te),y:Re.or(Te)});const St=s.z.object({x:Be,y:Re}),It=Object.freeze({x:"left",y:"top"}),Nt=(r,e)=>r.x===e.x&&r.y===e.y,Se=s.z.union([s.z.number(),Q,ee,Me,lt,dt]),zt=(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}},Ie=Object.freeze({x:0,y:0}),H=s.z.union([s.z.number(),s.z.string()]);s.z.object({top:H,left:H,width:H,height:H});s.z.object({left:s.z.number(),top:s.z.number(),right:s.z.number(),bottom:s.z.number()});s.z.object({one:Q,two:Q,root:St});const pe=(r,e,t=0,n=0,i)=>{const a={one:{...Ie},two:{...Ie},root:i??It};if(typeof r=="number"){if(typeof e!="number")throw new Error("Box constructor called with invalid arguments");return a.one={x:r,y:e},a.two={x:a.one.x+t,y:a.one.y+n},a}return"one"in r&&"two"in r&&"root"in r?{...r,root:i??r.root}:("getBoundingClientRect"in r&&(r=r.getBoundingClientRect()),"left"in r?(a.one={x:r.left,y:r.top},a.two={x:r.right,y:r.bottom},a):(a.one=r,e==null?a.two={x:a.one.x+t,y:a.one.y+n}:typeof e=="number"?a.two={x:a.one.x+e,y:a.one.y+t}:"width"in e?a.two={x:a.one.x+e.width,y:a.one.y+e.height}:"signedWidth"in e?a.two={x:a.one.x+e.signedWidth,y:a.one.y+e.signedHeight}:a.two=e,a))},ae=r=>{const e=pe(r);return{lower:e.one.x,upper:e.two.x}},oe=r=>{const e=pe(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,xt=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()});s.z.union([Me,xt,Q,ee]);const At=(r,e,t)=>e!==void 0&&r<e?e:t!==void 0&&r>t?t:r;s.z.object({offset:Se,scale:Se});s.z.object({offset:s.z.number(),scale:s.z.number()});const Ut=r=>(e,t,n,i)=>t==="dimension"?[e,n]:[e,i?n-r:n+r],Mt=r=>(e,t,n,i)=>[e,i?n/r:n*r],$t=r=>(e,t,n)=>{if(e===null)return[r,n];const{lower:i,upper:a}=e,{lower:c,upper:d}=r,y=a-i,f=d-c;if(t==="dimension")return[r,n*(f/y)];const g=(n-i)*(f/y)+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)]},Rt=r=>(e,t,n)=>{const{lower:i,upper:a}=r;return n=At(n,i,a),[e,n]};let Ne=class j{ops=[];currBounds=null;currType=null;reversed=!1;constructor(){this.ops=[]}static translate(e){return new j().translate(e)}static magnify(e){return new j().magnify(e)}static scale(e,t){return new j().scale(e,t)}translate(e){const t=this.new(),n=Ut(e);return n.type="translate",t.ops.push(n),t}magnify(e){const t=this.new(),n=Mt(e);return n.type="magnify",t.ops.push(n),t}scale(e,t){const n=D(e,t),i=this.new(),a=$t(n);return a.type="scale",i.ops.push(a),i}clamp(e,t){const n=D(e,t),i=this.new(),a=Rt(n);return a.type="clamp",i.ops.push(a),i}reBound(e,t){const n=D(e,t),i=this.new(),a=Ct(n);return a.type="re-bound",i.ops.push(a),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 j;return e.ops=this.ops.slice(),e.reversed=this.reversed,e}exec(e,t){return this.currBounds=null,this.ops.reduce(([n,i],a)=>a(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,d])=>i>=c&&i<=d))return;const a=e.ops.findIndex((c,d)=>c.type==="scale"&&d>i);a!==-1&&t.push([i,a])}),t.forEach(([n,i])=>{const a=e.ops.slice(n,i);a.unshift(e.ops[i]),e.ops.splice(n,i-n+1,...a)}),e.reversed=!e.reversed,e}get transform(){return{scale:this.dim(1),offset:this.pos(0)}}static IDENTITY=new j},sn=class U{x;y;currRoot;constructor(e=new Ne,t=new Ne,n=null){this.x=e,this.y=t,this.currRoot=n}static translate(e,t){return new U().translate(e,t)}static translateX(e){return new U().translateX(e)}static translateY(e){return new U().translateY(e)}static clamp(e){return new U().clamp(e)}static magnify(e){return new U().magnify(e)}static scale(e){return new U().scale(e)}static reBound(e){return new U().reBound(e)}translate(e,t){const n=zt(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&&!Nt(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(ae(e)),t.y=t.y.scale(oe(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(ae(e)),t.y=this.y.reBound(oe(e)),t}clamp(e){const t=this.copy();return t.x=this.x.clamp(ae(e)),t.y=this.y.clamp(oe(e)),t}copy(){const e=new U;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 pe(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 U},Pe=(r,e=21)=>(t=e)=>{let n="",i=t|0;for(;i--;)n+=r[Math.random()*r.length|0];return n};const ke="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",Dt=`0123456789${ke}`,Lt=11,Pt=Pe(ke,1),kt=Pe(Dt,Lt-1),jt=()=>`${Pt()}${kt()}`,Yt=(r,e)=>t=>t instanceof e||typeof t=="object"&&t!==null&&"discriminator"in t&&t.discriminator===r,qt=s.z.enum(["static","dynamic"]),ce=2n**63n-1n,Ft=2**63-1,ze=365,J=30,Wt=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)])]),je=(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===Ft?e=ce:e=Math.trunc(e):(isNaN(e)&&(e=0),e===1/0?e=u.MAX:e=u.MIN)),x(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,a]=e.split(":");let c="00",d="00";a!=null&&([c,d]=a.split("."));let y=u.hours(parseInt(n??"00")).add(u.minutes(parseInt(i??"00"))).add(u.seconds(parseInt(c??"00"))).add(u.milliseconds(parseInt(d??"00")));return t==="local"&&(y=y.add(u.utcOffset)),y.valueOf()}static parseDateTimeString(e,t="UTC"){if(!e.includes("/")&&!e.includes("-"))return u.parseTimeString(e,t);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"){return e==="UTC"?this.date().toISOString():this.sub(u.utcOffset).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 z(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(ne(this.valueOf(),new l(e).valueOf()))}sub(e){return new u(re(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()}setYear(e){const t=this.date();return t.setUTCFullYear(e),new u(t)}get month(){return this.date().getUTCMonth()}setMonth(e){const t=this.date();return t.setUTCMonth(e),new u(t)}get day(){return this.date().getUTCDate()}setDay(e){const t=this.date();return t.setUTCDate(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()}setMinute(e){const t=this.date();return t.setUTCMinutes(e),new u(t)}get second(){return this.date().getUTCSeconds()}setSecond(e){const t=this.date();return t.setUTCSeconds(e),new u(t)}get millisecond(){return this.date().getUTCMilliseconds()}setMillisecond(e){const t=this.date();return t.setUTCMilliseconds(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 je(this,e)}get isToday(){return this.truncate(l.DAY).equals(u.now().truncate(l.DAY))}truncate(e){return this.sub(this.remainder(e))}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(ce);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)),Wt.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())),x(e)&&(e=e.value),super(BigInt(e.valueOf()))}static fromSeconds(e){return e instanceof l?e:e instanceof N?e.period:e instanceof u?new l(e):(x(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 N?e.period:e instanceof u?new l(e):(x(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 je(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),a=this.truncate(l.SECOND),c=this.truncate(l.MILLISECOND),d=this.truncate(l.MICROSECOND),y=this.truncate(l.NANOSECOND),f=t,g=n.sub(t),w=i.sub(n),h=a.sub(i),O=c.sub(a),E=d.sub(c),A=y.sub(d);let m="";return f.isZero||(m+=`${f.days}d `),g.isZero||(m+=`${g.hours}h `),w.isZero||(m+=`${w.minutes}m `),h.isZero||(m+=`${h.seconds}s `),O.isZero||(m+=`${O.milliseconds}ms `),E.isZero||(m+=`${E.microseconds}µs `),A.isZero||(m+=`${A.nanoseconds}ns`),m.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,a=t.hours,c=t.minutes,d=t.seconds,y=Math.floor(i/ze),f=Math.floor(i/J),g=Math.floor(i/7),w=Math.floor(i),h=Math.floor(a),O=Math.floor(c),E=Math.floor(d),A=n?"-":"";if(y>=1){let m=`${y}y`;if(y<2){const T=Math.floor(i%ze/J);T>0&&(m+=` ${T}mo`)}return A+m}if(g>=1&&i<J&&i%7===0){let m=`${g}w`;const T=Math.floor(i%7),R=Math.floor(a-g*7*24);return g<2&&(T>0?m+=` ${T}d`:R>0&&R<24&&(m+=` ${R}h`)),A+m}if(f>=1){let m=`${f}mo`;if(f<3){const T=Math.floor(i%J);T>0&&(m+=` ${T}d`)}return A+m}if(g>=1){let m=`${g}w`;const T=Math.floor(i%7),R=Math.floor(a-g*7*24);return g<2&&(T>0?m+=` ${T}d`:R>0&&R<24&&(m+=` ${R}h`)),A+m}if(w>=1){let m=`${w}d`;const T=Math.floor(a-w*24);return w<2&&T>0&&(m+=` ${T}h`),A+m}if(h>=1){let m=`${h}h`;if(h<3){const T=Math.floor(c-h*60);T>0&&(m+=` ${T}m`)}return A+m}if(O>=1){let m=`${O}m`;if(O<5){const T=Math.floor(d-O*60);T>0&&(m+=` ${T}s`)}return A+m}return`${A}${E}s`}mult(e){return new l(M(this.valueOf(),e))}div(e){return new l(se(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(ce);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 N).transform(e=>new l(e))])}class N extends F{constructor(e){x(e)&&(e=e.value),super(e.valueOf())}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new N(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 S(t).valueOf()}span(e){return l.seconds(e/this.valueOf())}byteSpan(e,t){return this.span(e.valueOf()/new S(t).valueOf())}add(e){return new N(ne(this.valueOf(),new N(e).valueOf()))}sub(e){return new N(re(this.valueOf(),new N(e).valueOf()))}mult(e){return new N(M(this.valueOf(),e))}div(e){return new N(se(this.valueOf(),e))}static hz(e){return new N(e)}static khz(e){return N.hz(e*1e3)}static z=s.z.union([s.z.number().transform(e=>new N(e)),s.z.instanceof(N)])}let S=class I extends F{constructor(e){x(e)&&(e=e.value),super(e.valueOf())}length(e){return e.valueOf()/this.valueOf()}size(e){return new he(e*this.valueOf())}add(e){return new I(ne(this.valueOf(),new I(e).valueOf()))}sub(e){return new I(re(this.valueOf(),new I(e).valueOf()))}mult(e){return new I(M(this.valueOf(),e))}div(e){return new I(se(this.valueOf(),e))}static UNKNOWN=new I(0);static BIT128=new I(16);static BIT64=new I(8);static BIT32=new I(4);static BIT16=new I(2);static BIT8=new I(1);static z=s.z.union([s.z.number().transform(e=>new I(e)),s.z.instanceof(I)])};class z{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 z(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),a=u.min(n.end,e.end);return a.before(i)?!1:new l(a.sub(i)).greaterThanOrEqual(t)}contains(e){return e instanceof z?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const t=new z(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 z(u.min(...e.map(t=>t.start)),u.max(...e.map(t=>t.end)))}static MAX=new z(u.MIN,u.MAX);static ZERO=new z(u.ZERO,u.ZERO);static z=s.z.union([s.z.object({start:u.z,end:u.z}).transform(e=>new z(e.start,e.end)),s.z.instanceof(z)]);static sort(e,t){return u.sort(e.start,t.start)||u.sort(e.end,t.end)}static simplify(e){return e.map(t=>t.makeValid()).sort((t,n)=>z.sort(t,n)).reduce((t,n)=>{if(n.span.isZero)return t;if(t.length===0)return t.push(n),t;const i=t[t.length-1];return i.overlapsWith(n)||i.end.equals(n.start)?i.end=u.max(i.end,n.end):t.push(n),t},[])}}let b=class o extends F{constructor(e){if(x(e)&&(e=e.value),e instanceof o||typeof e=="string"||typeof e.valueOf()=="string")super(e.valueOf());else{const t=o.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=o.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?o.SHORT_STRINGS.get(this.valueOf())??this.valueOf():this.valueOf()}get isVariable(){return this.equals(o.JSON)||this.equals(o.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(o.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=o.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}get isUnsignedInteger(){return this.equals(o.UINT8)||this.equals(o.UINT16)||this.equals(o.UINT32)||this.equals(o.UINT64)}get isSignedInteger(){return this.equals(o.INT8)||this.equals(o.INT16)||this.equals(o.INT32)||this.equals(o.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(o.INT32)&&e.equals(o.FLOAT64)||this.equals(o.INT8)&&e.equals(o.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 o.BIG_INT_TYPES.some(e=>e.equals(this))}static UNKNOWN=new o("unknown");static FLOAT64=new o("float64");static FLOAT32=new o("float32");static INT64=new o("int64");static INT32=new o("int32");static INT16=new o("int16");static INT8=new o("int8");static UINT64=new o("uint64");static UINT32=new o("uint32");static UINT16=new o("uint16");static UINT8=new o("uint8");static BOOLEAN=new o("boolean");static TIMESTAMP=new o("timestamp");static UUID=new o("uuid");static STRING=new o("string");static JSON=new o("json");static ARRAY_CONSTRUCTORS=new Map([[o.UINT8.toString(),Uint8Array],[o.UINT16.toString(),Uint16Array],[o.UINT32.toString(),Uint32Array],[o.UINT64.toString(),BigUint64Array],[o.FLOAT32.toString(),Float32Array],[o.FLOAT64.toString(),Float64Array],[o.INT8.toString(),Int8Array],[o.INT16.toString(),Int16Array],[o.INT32.toString(),Int32Array],[o.INT64.toString(),BigInt64Array],[o.TIMESTAMP.toString(),BigInt64Array],[o.STRING.toString(),Uint8Array],[o.JSON.toString(),Uint8Array],[o.UUID.toString(),Uint8Array]]);static ARRAY_CONSTRUCTOR_DATA_TYPES=new Map([[Uint8Array.name,o.UINT8],[Uint16Array.name,o.UINT16],[Uint32Array.name,o.UINT32],[BigUint64Array.name,o.UINT64],[Float32Array.name,o.FLOAT32],[Float64Array.name,o.FLOAT64],[Int8Array.name,o.INT8],[Int16Array.name,o.INT16],[Int32Array.name,o.INT32],[BigInt64Array.name,o.INT64]]);static DENSITIES=new Map([[o.UINT8.toString(),S.BIT8],[o.UINT16.toString(),S.BIT16],[o.UINT32.toString(),S.BIT32],[o.UINT64.toString(),S.BIT64],[o.FLOAT32.toString(),S.BIT32],[o.FLOAT64.toString(),S.BIT64],[o.INT8.toString(),S.BIT8],[o.INT16.toString(),S.BIT16],[o.INT32.toString(),S.BIT32],[o.INT64.toString(),S.BIT64],[o.TIMESTAMP.toString(),S.BIT64],[o.STRING.toString(),S.UNKNOWN],[o.JSON.toString(),S.UNKNOWN],[o.UUID.toString(),S.BIT128]]);static ALL=[o.UNKNOWN,o.FLOAT64,o.FLOAT32,o.INT64,o.INT32,o.INT16,o.INT8,o.UINT64,o.UINT32,o.UINT16,o.UINT8,o.TIMESTAMP,o.UUID,o.STRING,o.JSON];static SHORT_STRINGS=new Map([[o.UINT8.toString(),"u8"],[o.UINT16.toString(),"u16"],[o.UINT32.toString(),"u32"],[o.UINT64.toString(),"u64"],[o.INT8.toString(),"i8"],[o.INT16.toString(),"i16"],[o.INT32.toString(),"i32"],[o.INT64.toString(),"i64"],[o.FLOAT32.toString(),"f32"],[o.FLOAT64.toString(),"f64"],[o.BOOLEAN.toString(),"bool"],[o.TIMESTAMP.toString(),"ts"],[o.UUID.toString(),"uuid"],[o.STRING.toString(),"str"],[o.JSON.toString(),"json"]]);static BIG_INT_TYPES=[o.INT64,o.UINT64,o.TIMESTAMP];static z=s.z.union([s.z.string().transform(e=>new o(e)),s.z.instanceof(o)])},he=class p extends F{constructor(e){x(e)&&(e=e.value),super(e.valueOf())}largerThan(e){return x(e)&&(e=e.value),this.valueOf()>e.valueOf()}smallerThan(e){return x(e)&&(e=e.value),this.valueOf()<e.valueOf()}add(e){return x(e)&&(e=e.value),new p(ne(this.valueOf(),e.valueOf()))}sub(e){return x(e)&&(e=e.value),new p(re(this.valueOf(),e.valueOf()))}mult(e){return new p(M(this.valueOf(),e))}div(e){return new p(se(this.valueOf(),e))}truncate(e){return new p(Math.trunc(this.valueOf()/new p(e).valueOf())*new p(e).valueOf())}remainder(e){return p.bytes(this.valueOf()%new p(e).valueOf())}get gigabytes(){return this.valueOf()/p.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/p.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/p.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/p.TERABYTE.valueOf()}toString(){const e=this.truncate(p.TERABYTE),t=this.truncate(p.GIGABYTE),n=this.truncate(p.MEGABYTE),i=this.truncate(p.KILOBYTE),a=this.truncate(p.BYTE),c=e,d=t.sub(e),y=n.sub(t),f=i.sub(n),g=a.sub(i);let w="";return c.isZero||(w+=`${c.terabytes}TB `),d.isZero||(w+=`${d.gigabytes}GB `),y.isZero||(w+=`${y.megabytes}MB `),f.isZero||(w+=`${f.kilobytes}KB `),(!g.isZero||w==="")&&(w+=`${g.valueOf()}B`),w.trim()}static bytes(e=1){return new p(e)}static BYTE=new p(1);static kilobytes(e=1){return p.bytes(new p(e).valueOf()*1e3)}static KILOBYTE=p.kilobytes(1);static megabytes(e=1){return p.kilobytes(new p(e).valueOf()*1e3)}static MEGABYTE=p.megabytes(1);static gigabytes(e=1){return p.megabytes(new p(e).valueOf()*1e3)}static GIGABYTE=p.gigabytes(1);static terabytes(e){return p.gigabytes(new p(e).valueOf()*1e3)}static TERABYTE=p.terabytes(1);static ZERO=new p(0);static z=s.z.union([s.z.number().transform(e=>new p(e)),s.z.instanceof(p)]);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 Ye=r=>{const e=typeof r;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||r instanceof u||r instanceof l||r instanceof Date},Zt=(r,e,t,n=0)=>r.usesBigInt&&!e.usesBigInt?Number(t)-Number(n):!r.usesBigInt&&e.usesBigInt?BigInt(t.valueOf())-BigInt(n.valueOf()):X(t,-n),X=(r,e)=>e==0?r:r==0?e:typeof r=="bigint"&&typeof e=="bigint"||typeof r=="number"&&typeof e=="number"?r+e:Number(r)+Number(e),Gt=/^(?:[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 Vt(r){return typeof r=="string"&&Gt.test(r)}const v=[];for(let r=0;r<256;++r)v.push((r+256).toString(16).slice(1));function Ht(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 Jt(r,e=0){const t=Ht(r,e);if(!Vt(t))throw TypeError("Stringified UUID is invalid");return t}typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const qe=(r,e)=>Jt(r,e),C=-1,Kt=s.z.string().transform(r=>new Uint8Array(atob(r).split("").map(e=>e.charCodeAt(0))).buffer),Xt=s.z.union([s.z.null(),s.z.undefined()]).transform(()=>new Uint8Array().buffer),fe=10,Qt=(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`)},Fe="sy_x_telem_series";class ${key;discriminator=Fe;dataType;sampleOffset;gl;_data;timeRange=z.ZERO;alignment=0n;alignmentMultiple=1n;cachedMin;cachedMax;writePos=C;_refCount=0;cachedLength;_cachedIndexes;static crudeZ=s.z.object({timeRange:z.z.optional(),dataType:b.z,alignment:s.z.coerce.bigint().optional(),data:s.z.union([Kt,Xt,s.z.instanceof(ArrayBuffer),s.z.instanceof(Uint8Array)]),glBufferUsage:qt.optional().default("static").optional()});static z=$.crudeZ.transform(e=>new $(e));constructor(e){_t(e)&&(e={data:e}),e.data??=[];const{dataType:t,timeRange:n,sampleOffset:i=0,glBufferUsage:a="static",alignment:c=0n,alignmentMultiple:d=1n,key:y=jt(),data:f}=e;if(er(f)){const h=f;this.key=h.key,this.dataType=h.dataType,this.sampleOffset=h.sampleOffset,this.gl=h.gl,this._data=h._data,this.timeRange=h.timeRange,this.alignment=h.alignment,this.alignmentMultiple=h.alignmentMultiple,this.cachedMin=h.cachedMin,this.cachedMax=h.cachedMax,this.writePos=h.writePos,this._refCount=h._refCount,this.cachedLength=h.cachedLength;return}const g=Ye(f),w=Array.isArray(f);if(t!=null)this.dataType=new b(t);else{if(f instanceof ArrayBuffer)throw new Error("cannot infer data type from an ArrayBuffer instance when constructing a Series. Please provide a data type.");if(w||g){let h=f;if(!g){if(f.length===0)throw new Error("cannot infer data type from a zero length JS array when constructing a Series. Please provide a data type.");h=f[0]}if(typeof h=="string")this.dataType=b.STRING;else if(typeof h=="number")this.dataType=b.FLOAT64;else if(typeof h=="bigint")this.dataType=b.INT64;else if(typeof h=="boolean")this.dataType=b.BOOLEAN;else if(h instanceof u||h instanceof Date||h instanceof u)this.dataType=b.TIMESTAMP;else if(typeof h=="object")this.dataType=b.JSON;else throw new Error(`cannot infer data type of ${typeof h} when constructing a Series from a JS array`)}else this.dataType=new b(f)}if(!w&&!g)this._data=f;else if(w&&f.length===0)this._data=new this.dataType.Array([]).buffer;else{let h=g?[f]:f;const O=h[0];(O instanceof u||O instanceof Date||O instanceof l)&&(h=h.map(E=>new u(E).valueOf())),this.dataType.equals(b.STRING)?(this.cachedLength=h.length,this._data=new TextEncoder().encode(`${h.join(`
2
2
  `)}
3
- `).buffer):this.dataType.equals(w.JSON)?(this.cachedLength=h.length,this._data=new TextEncoder().encode(`${h.map(E=>oe.encodeString(E)).join(`
3
+ `).buffer):this.dataType.equals(b.JSON)?(this.cachedLength=h.length,this._data=new TextEncoder().encode(`${h.map(E=>le.encodeString(E)).join(`
4
4
  `)}
5
- `).buffer):this.dataType.usesBigInt&&typeof O=="number"?this._data=new this.dataType.Array(h.map(E=>BigInt(Math.round(E)))).buffer:!this.dataType.usesBigInt&&typeof O=="bigint"?this._data=new this.dataType.Array(h.map(Number)).buffer:this._data=new this.dataType.Array(h).buffer}this.key=y,this.alignment=c,this.alignmentMultiple=g,this.sampleOffset=i??0,this.timeRange=r??q.ZERO,this.gl={control:null,buffer:null,prevBuffer:0,bufferUsage:a}}static alloc({capacity:e,dataType:t,...r}){if(e===0)throw new Error("[Series] - cannot allocate an array of length 0");const i=new new w(t).Array(e),a=new C({data:i.buffer,dataType:t,...r});return a.writePos=0,a}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===M)return 0;const t=this.byteCapacity.valueOf()-this.writePos,r=e.subBytes(0,t);return this.writeToUnderlyingData(r),this.writePos+=r.byteLength.valueOf(),this.cachedLength!=null&&(this.cachedLength+=r.length,this.calculateCachedLength()),r.length}writeFixed(e){if(this.writePos===M)return 0;const t=this.capacity-this.writePos,r=e.sub(0,t);return this.writeToUnderlyingData(r),this.cachedLength=void 0,this.maybeRecomputeMinMax(r),this.writePos+=r.length,r.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===M?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(w.JSON))throw new Error("cannot parse non-JSON series as JSON");return this.toStrings().map(t=>e.parse(oe.decodeString(t)))}get byteCapacity(){return new ue(this.underlyingData.byteLength)}get capacity(){return this.dataType.isVariable?this.byteCapacity.valueOf():this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===M?this.byteCapacity:this.dataType.isVariable?new ue(this.writePos):this.dataType.density.size(this.writePos)}get length(){return this.cachedLength!=null?this.cachedLength:this.dataType.isVariable?this.calculateCachedLength():this.writePos===M?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((r,i)=>{r===le&&(e++,t.push(i+1))}),this._cachedIndexes=t,this.cachedLength=e,e}convert(e,t=0){if(this.dataType.equals(e))return this;const r=new e.Array(this.length);for(let i=0;i<this.length;i++)r[i]=Yt(this.dataType,e,this.data[i],t);return new C({data:r.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(w.TIMESTAMP))this.cachedMax=this.data[this.data.length-1];else if(this.dataType.usesBigInt){const e=this.data;this.cachedMax=e.reduce((t,r)=>t>r?t:r)}else{const e=this.data;this.cachedMax=e.reduce((t,r)=>t>r?t:r)}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(),J(this.cachedMax,this.sampleOffset))}calcRawMin(){if(this.length===0)return 1/0;if(this.dataType.equals(w.TIMESTAMP))this.cachedMin=this.data[0];else if(this.dataType.usesBigInt){const e=this.data;this.cachedMin=e.reduce((t,r)=>t<r?t:r)}else{const e=this.data;this.cachedMin=e.reduce((t,r)=>t<r?t:r)}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(),J(this.cachedMin,this.sampleOffset))}get bounds(){return B(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 r=Number((e-this.alignment)/this.alignmentMultiple);if(r<0||r>=this.length){if(t===!0)throw new Error(`[series] - no value at index ${r}`);return}return this.at(r,t)}at(e,t=!1){if(this.dataType.isVariable)return this.atVariable(e,t??!1);if(this.dataType.equals(w.UUID))return this.atUUID(e,t);e<0&&(e=this.length+e);const r=this.data[e];if(r==null){if(t===!0)throw new Error(`[series] - no value at index ${e}`);return}return J(r,this.sampleOffset)}atUUID(e,t){e<0&&(e=this.length+e);const r=ke(new Uint8Array(this.buffer,e*this.dataType.density.valueOf()));if(r==null){if(t)throw new Error(`[series] - no value at index ${e}`);return}return r}atVariable(e,t){let r=0,i=0;if(this._cachedIndexes!=null)r=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]===le){if(e===0){i=c;break}r=c+1,e--}if(i===0&&(i=this.data.length),r>=i||e>0){if(t)throw new Error(`[series] - no value at index ${e}`);return}}const a=this.data.slice(r,i);return this.dataType.equals(w.STRING)?new TextDecoder().decode(a):ze(JSON.parse(new TextDecoder().decode(a)))}binarySearch(e){let t=0,r=this.length-1;const i=st(e);for(;t<=r;){const a=Math.floor((t+r)/2),c=i(this.at(a,!0),e);if(c===0)return a;c<0?t=a+1:r=a-1}return t}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals(w.FLOAT32)&&!this.dataType.equals(w.UINT8))throw new Error("Only FLOAT32 and UINT8 arrays can be used in WebGL");const{buffer:t,bufferUsage:r,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!==M){i===0&&e.bufferData(e.ARRAY_BUFFER,this.byteCapacity.valueOf(),e.STATIC_DRAW);const a=this.dataType.density.size(i).valueOf(),c=this.underlyingData.slice(this.gl.prevBuffer,this.writePos);e.bufferSubData(e.ARRAY_BUFFER,a,c.buffer),this.gl.prevBuffer=this.writePos}else e.bufferData(e.ARRAY_BUFFER,this.buffer,r==="static"?e.STATIC_DRAW:e.DYNAMIC_DRAW),this.gl.prevBuffer=M}as(e){return Ht(e,this.dataType),this}get digest(){return{key:this.key,dataType:this.dataType.toString(),sampleOffset:this.sampleOffset,alignment:{lower:Se(this.alignmentBounds.lower),upper:Se(this.alignmentBounds.upper),multiple:this.alignmentMultiple},timeRange:this.timeRange.toString(),length:this.length,capacity:this.capacity}}get alignmentBounds(){return B(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 Kt(this);return this.dataType.equals(w.JSON)?new Qt(e):e}return this.dataType.equals(w.UUID)?new _t(this):new en(this)}slice(e,t){return this.sliceSub(!1,e,t)}sub(e,t){return this.sliceSub(!0,e,t)}subIterator(e,t){return new Ie(this,e,t??this.length)}subAlignmentIterator(e,t){const r=Math.ceil(Number(e-this.alignment)/Number(this.alignmentMultiple)),i=Math.ceil(Number(t-this.alignment)/Number(this.alignmentMultiple));return new Ie(this,r,i)}subBytes(e,t){if(e>=0&&(t==null||t>=this.byteLength.valueOf()))return this;const r=this.data.subarray(e,t);return new C({data:r,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(e)})}sliceSub(e,t,r){if(t<=0&&(r==null||r>=this.length))return this;let i;return e?i=this.data.subarray(t,r):i=this.data.slice(t,r),new C({data:i,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(t)})}reAlign(e){return new C({data:this.buffer,dataType:this.dataType,timeRange:q.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 Jt=n=>n==null?!1:Array.isArray(n)||n instanceof ArrayBuffer||ArrayBuffer.isView(n)&&!(n instanceof DataView)||n instanceof je?!0:Le(n),Xt=kt(Pe,je);let Ie=class{series;end;index;constructor(e,t,r){this.series=e;const i=B(0,e.length+1);this.end=be(i,r),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 Kt{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]!==le;)this.index++;const r=this.index;return e===r?{done:!0,value:void 0}:(this.index++,{done:!1,value:this.decoder.decode(this.series.buffer.slice(e,r))})}}let Qt=class Ye{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:oe.decodeString(e.value,Ye.schema)}}},_t=class{series;index;data;density;constructor(e){if(!e.dataType.equals(w.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=w.UUID.density.valueOf()}next(){if(this.index>=this.series.length)return{done:!0,value:void 0};const e=ke(this.data,this.index*this.density);return this.index++,{done:!1,value:e}}};class en{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 Se=n=>{const e=n>>32n,t=n&0xffffffffn;return{domain:e,sample:t}};s.z.object({key:s.z.string(),value:s.z.string()});s.z.record(s.z.union([s.z.number(),s.z.string(),s.z.symbol()]),s.z.unknown());const tn=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser";tn();const nn=["macOS","Windows","Linux"],rn=["macos","windows","linux"],sn={macos:"macOS",windows:"Windows",linux:"Linux"};s.z.enum(nn).or(s.z.enum(rn).transform(n=>sn[n]));const an=(...n)=>n.map(qe).join(""),qe=n=>(n.endsWith("/")||(n+="/"),n.startsWith("/")&&(n=n.slice(1)),n),on=n=>n.endsWith("/")?n.slice(0,-1):n,un=(n,e="")=>n===null?"":`?${Object.entries(n).filter(([,t])=>t==null?!1:Array.isArray(t)?t.length>0:!0).map(([t,r])=>`${e}${t}=${r}`).join("&")}`;class W{protocol;host;port;path;constructor({host:e,port:t,protocol:r="",pathPrefix:i=""}){this.protocol=r,this.host=e,this.port=t,this.path=qe(i)}replace(e){return new W({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new W({...this,pathPrefix:an(this.path,e)})}toString(){return on(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}static UNKNOWN=new W({host:"unknown",port:0})}const ln=async n=>await new Promise(e=>setTimeout(e,p.fromMilliseconds(n).milliseconds));class cn{config;retries;interval;constructor(e){this.config={baseInterval:new p(e?.baseInterval??p.seconds(1)),maxRetries:e?.maxRetries??5,scale:e?.scale??1,sleepFn:e?.sleepFn??ln},this.retries=0,this.interval=new p(this.config.baseInterval)}async wait(){const{maxRetries:e,scale:t,sleepFn:r}=this.config;return this.retries>=e?!1:(await r(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 hn=s.z.object({baseInterval:p.z.optional(),maxRetries:s.z.number().optional(),scale:s.z.number().optional()}),fn=Object.freeze(Object.defineProperty({__proto__:null,Breaker:cn,breakerConfigZ:hn},Symbol.toStringTag,{value:"Module"})),dn=/^#?([0-9a-f]{6}|[0-9a-f]{8})$/i,Fe=s.z.string().regex(dn),j=s.z.number().min(0).max(255),We=s.z.number().min(0).max(1),Ze=s.z.tuple([j,j,j,We]),gn=s.z.tuple([j,j,j]),pn=s.z.object({rgba255:Ze}),mn=s.z.number().min(0).max(360),yn=s.z.number().min(0).max(100),wn=s.z.number().min(0).max(100),bn=s.z.tuple([mn,yn,wn,We]),de=s.z.union([Fe,gn,Ze,bn,pn]),On=de.transform(n=>ge(n)),ge=(n,e=1)=>{if(n=de.parse(n),typeof n=="string")return Tn(n,e);if(Array.isArray(n)){if(n.length<3||n.length>4)throw new Error(`Invalid color: [${n.join(", ")}]`);return n.length===3?[...n,e]:n}return n.rgba255},Tn=(n,e=1)=>(n=Fe.parse(n),n=vn(n),[H(n,0),H(n,2),H(n,4),n.length===8?H(n,6)/255:e]),H=(n,e)=>parseInt(n.slice(e,e+2),16),vn=n=>n.startsWith("#")?n.slice(1):n;ge("#000000");ge("#ffffff");const In=s.z.object({key:s.z.string(),color:de,position:s.z.number(),switched:s.z.boolean().optional()});s.z.array(In);const Sn=s.z.object({key:s.z.string(),name:s.z.string(),color:On});s.z.object({key:s.z.string(),name:s.z.string(),swatches:s.z.array(Sn)});s.z.int().min(0).max(255);s.z.object({name:s.z.string(),key:s.z.string()});const Nn=n=>Object.getOwnPropertySymbols(globalThis).includes(n),zn=(n,e)=>{const t=Symbol.for(n);if(!Nn(t)){const r=e();Object.defineProperty(globalThis,t,{value:r})}return()=>globalThis[t]},Ve="sy_x_error",En=n=>e=>e!=null&&typeof e=="object"&&"type"in e&&typeof e.type=="string"?e.type.startsWith(n):e instanceof Error?e.message.startsWith(n):typeof e!="string"?!1:e.startsWith(n),Z=n=>class F extends Error{static discriminator=Ve;discriminator=F.discriminator;static TYPE=n;type=F.TYPE;static matches=En(n);matches=F.matches;constructor(t,r){super(t,r),this.name=F.TYPE}static sub(t){return Z(`${n}.${t}`)}},Ge=n=>{if(n==null||typeof n!="object")return!1;const e=n;if(e.discriminator!==Ve)return!1;if(!("type"in e))throw new Error(`X Error is missing its type property: ${JSON.stringify(e)}`);return!0},P="unknown",ce="nil";class xn{providers=[];register(e){this.providers.push(e)}encode(e){if(e==null)return{type:ce,data:""};if(Ge(e))for(const t of this.providers){const r=t.encode(e);if(r!=null)return r}if(e instanceof Error)return{type:P,data:e.message};if(typeof e=="string")return{type:P,data:e};try{return{type:P,data:JSON.stringify(e)}}catch{return{type:P,data:"unable to encode error information"}}}decode(e){if(e==null||e.type===ce)return null;if(e.type===P)return new he(e.data);for(const t of this.providers){const r=t.decode(e);if(r!=null)return r}return new he(e.data)}}const pe=zn("synnax-error-registry",()=>new xn),An=({encode:n,decode:e})=>pe().register({encode:n,decode:e}),Un=n=>pe().encode(n),Mn=n=>n==null?null:pe().decode(n);class he extends Z("unknown"){}const Cn=s.z.object({type:s.z.string(),data:s.z.string()});class $n extends Z("canceled"){}class Bn extends Z("not_implemented"){}const $=Object.freeze(Object.defineProperty({__proto__:null,Canceled:$n,NONE:ce,NotImplemented:Bn,UNKNOWN:P,Unknown:he,createTyped:Z,decode:Mn,encode:Un,isTyped:Ge,payloadZ:Cn,register:An},Symbol.toStringTag,{value:"Module"})),Rn=s.object({jsonrpc:s.literal("2.0"),method:s.string(),params:s.any().optional(),id:s.union([s.string(),s.number(),s.null()]).optional()}),He=s.object({jsonrpc:s.literal("2.0"),id:s.union([s.string(),s.number(),s.null()])}),Dn=He.extend({result:s.json()}),Ln=He.extend({error:s.object({code:s.number().int(),message:s.string().optional(),data:s.json().optional()})}),kn=s.union([Dn,Ln]);s.union([Rn,kn]);s.z.string().regex(/^\d+\.\d+\.\d+$/);const Pn=["standard","scientific","engineering"];s.z.enum(Pn);s.z.enum(["success","info","warning","error","loading","disabled"]);class V extends $.createTyped("freighter"){}class R extends V.sub("eof"){constructor(){super("EOF")}}class D extends V.sub("stream_closed"){constructor(){super("StreamClosed")}}class L extends V.sub("unreachable"){url;constructor(e={}){const{message:t="Unreachable",url:r=W.UNKNOWN}=e;super(t),this.url=r}}const jn=n=>{if(!n.type.startsWith(V.TYPE))return null;if(R.matches(n))return{type:R.TYPE,data:"EOF"};if(D.matches(n))return{type:D.TYPE,data:"StreamClosed"};if(L.matches(n))return{type:L.TYPE,data:"Unreachable"};throw new Error(`Unknown error type: ${n.type}: ${n.message}`)},Yn=n=>{if(!n.type.startsWith(V.TYPE))return null;switch(n.type){case R.TYPE:return new R;case D.TYPE:return new D;case L.TYPE:return new L;default:throw new $.Unknown(`Unknown error type: ${n.data}`)}};$.register({encode:jn,decode:Yn});class Je{middleware=[];use(...e){this.middleware.push(...e)}async executeMiddleware(e,t){let r=0;const i=async a=>{if(r===this.middleware.length)return await t(a);const c=this.middleware[r];return r++,await c(a,i)};return await i(e)}}const Xe="Content-Type",qn=new Set(["ECONNREFUSED","ECONNRESET","ETIMEDOUT","EPIPE","UND_ERR_CONNECT_TIMEOUT","UND_ERR_SOCKET"]),Fn=n=>{const e=n?.cause?.code??n?.code??n?.errno;if(typeof e=="string"&&qn.has(e))return!0;if(n.name==="TypeError"){const t=String(n.message||"").toLowerCase();if(/load failed|failed to fetch|networkerror|network error/.test(t))return typeof navigator<"u"&&navigator.onLine===!1,!0}return n?.name==="AbortError"||n?.code==="ABORT_ERR",!1},Wn=400;class Zn extends Je{endpoint;encoder;constructor(e,t,r=!1){return super(),this.endpoint=e.replace({protocol:r?"https":"http"}),this.encoder=t,new Proxy(this,{get:(i,a,c)=>a==="endpoint"?this.endpoint:Reflect.get(i,a,c)})}get headers(){return{[Xe]:this.encoder.contentType}}async send(e,t,r,i){t=r?.parse(t);let a=null;const c=this.endpoint.child(e),g={};g.method="POST",g.body=this.encoder.encode(t??{});const[,y]=await this.executeMiddleware({target:c.toString(),protocol:this.endpoint.protocol,params:{},role:"client"},async f=>{const m={...f,params:{}};g.headers={...this.headers,...f.params};let b;try{b=await fetch(f.target,g)}catch(O){if(!(O instanceof Error))throw O;return[m,Fn(O)?new L({url:c}):O]}const h=await b.arrayBuffer();if(b?.ok)return i!=null&&(a=this.encoder.decode(h,i)),[m,null];try{if(b.status!==Wn)return[m,new Error(b.statusText)];const O=this.encoder.decode(h,$.payloadZ),E=$.decode(O);return[m,E]}catch(O){return[m,new Error(`[freighter] - failed to decode error: ${b.statusText}: ${O.message}`)]}});if(y!=null)return[null,y];if(a==null)throw new Error("Response must be defined");return[a,null]}}const Vn=(n,e)=>{class t{wrapped;constructor(i){this.wrapped=i}use(...i){this.wrapped.use(...i)}async send(i,a,c,g){const y=new fn.Breaker(e);do{const[f,m]=await this.wrapped.send(i,a,c,g);if(m==null)return[f,null];if(!L.matches(m))return[null,m];if(console.warn(`[freighter] ${y.retryMessage}`,m),!await y.wait())return[f,m]}while(!0)}}return new t(n)},Gn=async(n,e,t,r,i)=>{const[a,c]=await n.send(e,t,r,i);if(c!=null)throw c;return a},Hn=s.z.object({type:s.z.enum(["data","close","open"]),payload:s.z.unknown(),error:s.z.optional($.payloadZ)});class Jn{codec;reqSchema;resSchema;ws;serverClosed;sendClosed;receiveDataQueue=[];receiveCallbacksQueue=[];constructor(e,t,r,i){this.codec=t,this.reqSchema=r,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 $.decode(e.error)}return null}send(e){if(this.serverClosed!=null)return new R;if(this.sendClosed)throw new D;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=$.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,r)=>this.receiveCallbacksQueue.push({resolve:t,reject:r}))}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,Hn))}onClose(e){this.addMessage({type:"close",error:{type:e.code===Kn?R.TYPE:D.TYPE,data:""}})}}const Xn="freighterctx",Kn=1e3;class K extends Je{baseUrl;encoder;secure;static MESSAGE_TYPE="arraybuffer";constructor(e,t,r=!1){super(),this.secure=r,this.baseUrl=e.replace({protocol:r?"wss":"ws"}),this.encoder=t}withCodec(e){const t=new K(this.baseUrl,e,this.secure);return t.use(...this.middleware),t}async stream(e,t,r){let i;const[,a]=await this.executeMiddleware({target:e,protocol:"websocket",params:{},role:"client"},async c=>{const g=new WebSocket(this.buildURL(e,c)),y={...c,params:{}};g.binaryType=K.MESSAGE_TYPE;const f=await this.wrapSocket(g,t,r);return f instanceof Error?[y,f]:(i=f,[y,null])});if(a!=null)throw a;return i}buildURL(e,t){const r=un({[Xe]:this.encoder.contentType,...t.params},Xn);return this.baseUrl.child(e).toString()+r}async wrapSocket(e,t,r){return await new Promise(i=>{e.onopen=()=>{const a=new Jn(e,this.encoder,t,r);a.receiveOpenAck().then(c=>{c!=null?i(c):i(a)}).catch(c=>i(c))},e.onerror=a=>{const c=a;i(new Error(c.message))}})}}exports.EOF=R;exports.HTTPClient=Zn;exports.StreamClosed=D;exports.Unreachable=L;exports.WebSocketClient=K;exports.sendRequired=Gn;exports.unaryWithBreaker=Vn;
5
+ `).buffer):this.dataType.usesBigInt&&typeof O=="number"?this._data=new this.dataType.Array(h.map(E=>BigInt(Math.round(E)))).buffer:!this.dataType.usesBigInt&&typeof O=="bigint"?this._data=new this.dataType.Array(h.map(Number)).buffer:this._data=new this.dataType.Array(h).buffer}this.key=y,this.alignment=c,this.alignmentMultiple=d,this.sampleOffset=i??0,this.timeRange=n??z.ZERO,this.gl={control:null,buffer:null,prevBuffer:0,bufferUsage:a}}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 b(t).Array(e),a=new $({data:i.buffer,dataType:t,...n});return a.writePos=0,a}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(b.JSON))throw new Error("cannot parse non-JSON series as JSON");return this.toStrings().map(t=>e.parse(le.decodeString(t)))}get byteCapacity(){return new he(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 he(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===fe&&(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]=Zt(this.dataType,e,this.data[i],t);return new $({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(b.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(),X(this.cachedMax,this.sampleOffset))}calcRawMin(){if(this.length===0)return 1/0;if(this.dataType.equals(b.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(),X(this.cachedMin,this.sampleOffset))}get bounds(){return D(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(b.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 X(n,this.sampleOffset)}atUUID(e,t){e<0&&(e=this.length+e);const n=qe(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]===fe){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 a=this.data.slice(n,i);return this.dataType.equals(b.STRING)?new TextDecoder().decode(a):Ue(JSON.parse(new TextDecoder().decode(a)))}binarySearch(e){let t=0,n=this.length-1;const i=ot(e);for(;t<=n;){const a=Math.floor((t+n)/2),c=i(this.at(a,!0),e);if(c===0)return a;c<0?t=a+1:n=a-1}return t}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals(b.FLOAT32)&&!this.dataType.equals(b.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 a=this.dataType.density.size(i).valueOf(),c=this.underlyingData.slice(this.gl.prevBuffer,this.writePos);e.bufferSubData(e.ARRAY_BUFFER,a,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 Qt(e,this.dataType),this}get digest(){return{key:this.key,dataType:this.dataType.toString(),sampleOffset:this.sampleOffset,alignment:{lower:xe(this.alignmentBounds.lower),upper:xe(this.alignmentBounds.upper),multiple:this.alignmentMultiple},timeRange:this.timeRange.toString(),length:this.length,capacity:this.capacity}}get alignmentBounds(){return D(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 tr(this);return this.dataType.equals(b.JSON)?new rr(e):e}return this.dataType.equals(b.UUID)?new nr(this):new sr(this)}slice(e,t){return this.sliceSub(!1,e,t)}sub(e,t){return this.sliceSub(!0,e,t)}subIterator(e,t){return new Ee(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 Ee(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 $({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 $({data:i,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(t)})}reAlign(e){return new $({data:this.buffer,dataType:this.dataType,timeRange:z.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 _t=r=>r==null?!1:Array.isArray(r)||r instanceof ArrayBuffer||ArrayBuffer.isView(r)&&!(r instanceof DataView)||r instanceof $?!0:Ye(r),er=Yt(Fe,$);class Ee{series;end;index;constructor(e,t,n){this.series=e;const i=D(0,e.length+1);this.end=ve(i,n),this.index=ve(i,t)}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}}class tr{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]!==fe;)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))})}}let rr=class We{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:le.decodeString(e.value,We.schema)}}};class nr{series;index;data;density;constructor(e){if(!e.dataType.equals(b.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=b.UUID.density.valueOf()}next(){if(this.index>=this.series.length)return{done:!0,value:void 0};const e=qe(this.data,this.index*this.density);return this.index++,{done:!1,value:e}}}let sr=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)}}};const xe=r=>{const e=r>>32n,t=r&0xffffffffn;return{domain:e,sample:t}};s.z.object({key:s.z.string(),value:s.z.string()});s.z.record(s.z.union([s.z.number(),s.z.string(),s.z.symbol()]),s.z.unknown());const ir=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser";ir();const ar=["macOS","Windows","Linux"],or=["macos","windows","linux"],ur={macos:"macOS",windows:"Windows",linux:"Linux"};s.z.enum(ar).or(s.z.enum(or).transform(r=>ur[r]));const lr=(...r)=>r.map(Ze).join(""),Ze=r=>(r.endsWith("/")||(r+="/"),r.startsWith("/")&&(r=r.slice(1)),r),cr=r=>r.endsWith("/")?r.slice(0,-1):r,hr=(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=Ze(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:lr(this.path,e)})}toString(){return cr(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}static UNKNOWN=new Z({host:"unknown",port:0})}const fr=async r=>await new Promise(e=>setTimeout(e,l.fromMilliseconds(r).milliseconds));class dr{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??fr},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 gr=s.z.object({baseInterval:l.z.optional(),maxRetries:s.z.number().optional(),scale:s.z.number().optional()}),pr=Object.freeze(Object.defineProperty({__proto__:null,Breaker:dr,breakerConfigZ:gr},Symbol.toStringTag,{value:"Module"})),mr=/^#?([0-9a-f]{6}|[0-9a-f]{8})$/i,Ge=s.z.string().regex(mr),q=s.z.number().min(0).max(255),Ve=s.z.number().min(0).max(1),He=s.z.tuple([q,q,q,Ve]),yr=s.z.tuple([q,q,q]),wr=s.z.object({rgba255:He}),br=s.z.number().min(0).max(360),Or=s.z.number().min(0).max(100),Tr=s.z.number().min(0).max(100),vr=s.z.tuple([br,Or,Tr,Ve]),me=s.z.union([Ge,yr,He,vr,wr]),Sr=me.transform(r=>ye(r)),ye=(r,e=1)=>{if(r=me.parse(r),typeof r=="string")return Ir(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 r.rgba255},Ir=(r,e=1)=>(r=Ge.parse(r),r=Nr(r),[K(r,0),K(r,2),K(r,4),r.length===8?K(r,6)/255:e]),K=(r,e)=>parseInt(r.slice(e,e+2),16),Nr=r=>r.startsWith("#")?r.slice(1):r;ye("#000000");ye("#ffffff");const zr=s.z.object({key:s.z.string(),color:me,position:s.z.number(),switched:s.z.boolean().optional()});s.z.array(zr);const Er=s.z.object({key:s.z.string(),name:s.z.string(),color:Sr});s.z.object({key:s.z.string(),name:s.z.string(),swatches:s.z.array(Er)});s.z.int().min(0).max(255);s.z.object({name:s.z.string(),key:s.z.string()});const xr=r=>Object.getOwnPropertySymbols(globalThis).includes(r),Ar=(r,e)=>{const t=Symbol.for(r);if(!xr(t)){const n=e();Object.defineProperty(globalThis,t,{value:n})}return()=>globalThis[t]},Je="sy_x_error",Ur=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),G=r=>class W extends Error{static discriminator=Je;discriminator=W.discriminator;static TYPE=r;type=W.TYPE;static matches=Ur(r);matches=W.matches;constructor(t,n){super(t,n),this.name=W.TYPE}static sub(t){return G(`${r}.${t}`)}},Ke=r=>{if(r==null||typeof r!="object")return!1;const e=r;if(e.discriminator!==Je)return!1;if(!("type"in e))throw new Error(`X Error is missing its type property: ${JSON.stringify(e)}`);return!0},Y="unknown",de="nil";class Mr{providers=[];register(e){this.providers.push(e)}encode(e){if(e==null)return{type:de,data:""};if(Ke(e))for(const t of this.providers){const n=t.encode(e);if(n!=null)return n}if(e instanceof Error)return{type:Y,data:e.message};if(typeof e=="string")return{type:Y,data:e};try{return{type:Y,data:JSON.stringify(e)}}catch{return{type:Y,data:"unable to encode error information"}}}decode(e){if(e==null||e.type===de)return null;if(e.type===Y)return new ge(e.data);for(const t of this.providers){const n=t.decode(e);if(n!=null)return n}return new ge(e.data)}}const we=Ar("synnax-error-registry",()=>new Mr),$r=({encode:r,decode:e})=>we().register({encode:r,decode:e}),Cr=r=>we().encode(r),Br=r=>r==null?null:we().decode(r);class ge extends G("unknown"){}const Rr=s.z.object({type:s.z.string(),data:s.z.string()});class Dr extends G("canceled"){}class Lr extends G("not_implemented"){}const B=Object.freeze(Object.defineProperty({__proto__:null,Canceled:Dr,NONE:de,NotImplemented:Lr,UNKNOWN:Y,Unknown:ge,createTyped:G,decode:Br,encode:Cr,isTyped:Ke,payloadZ:Rr,register:$r},Symbol.toStringTag,{value:"Module"})),Pr=s.object({jsonrpc:s.literal("2.0"),method:s.string(),params:s.any().optional(),id:s.union([s.string(),s.number(),s.null()]).optional()}),Xe=s.object({jsonrpc:s.literal("2.0"),id:s.union([s.string(),s.number(),s.null()])}),kr=Xe.extend({result:s.json()}),jr=Xe.extend({error:s.object({code:s.number().int(),message:s.string().optional(),data:s.json().optional()})}),Yr=s.union([kr,jr]);s.union([Pr,Yr]);const qr=s.uuid();s.object({key:qr,name:s.string().min(1),color:s.string()});s.z.string().regex(/^\d+\.\d+\.\d+$/);const Fr=["standard","scientific","engineering"];s.z.enum(Fr);s.z.enum(["success","info","warning","error","loading","disabled"]);s.z.object({stack:s.z.string(),error:s.z.instanceof(Error)});class V extends B.createTyped("freighter"){}class L extends V.sub("eof"){constructor(){super("EOF")}}class P extends V.sub("stream_closed"){constructor(){super("StreamClosed")}}class k extends V.sub("unreachable"){url;constructor(e={}){const{message:t="Unreachable",url:n=Z.UNKNOWN}=e;super(t),this.url=n}}const Wr=r=>{if(!r.type.startsWith(V.TYPE))return null;if(L.matches(r))return{type:L.TYPE,data:"EOF"};if(P.matches(r))return{type:P.TYPE,data:"StreamClosed"};if(k.matches(r))return{type:k.TYPE,data:"Unreachable"};throw new Error(`Unknown error type: ${r.type}: ${r.message}`)},Zr=r=>{if(!r.type.startsWith(V.TYPE))return null;switch(r.type){case L.TYPE:return new L;case P.TYPE:return new P;case k.TYPE:return new k;default:throw new B.Unknown(`Unknown error type: ${r.data}`)}};B.register({encode:Wr,decode:Zr});class Qe{middleware=[];use(...e){this.middleware.push(...e)}async executeMiddleware(e,t){let n=0;const i=async a=>{if(n===this.middleware.length)return await t(a);const c=this.middleware[n];return n++,await c(a,i)};return await i(e)}}const _e="Content-Type",Gr=new Set(["ECONNREFUSED","ECONNRESET","ETIMEDOUT","EPIPE","UND_ERR_CONNECT_TIMEOUT","UND_ERR_SOCKET"]),Vr=r=>{const e=r?.cause?.code??r?.code??r?.errno;if(typeof e=="string"&&Gr.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},Hr=400;class Jr extends Qe{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,a,c)=>a==="endpoint"?this.endpoint:Reflect.get(i,a,c)})}get headers(){return{[_e]:this.encoder.contentType}}async send(e,t,n,i){t=n?.parse(t);let a=null;const c=this.endpoint.child(e),d={};d.method="POST",d.body=this.encoder.encode(t??{});const[,y]=await this.executeMiddleware({target:c.toString(),protocol:this.endpoint.protocol,params:{},role:"client"},async f=>{const g={...f,params:{}};d.headers={...this.headers,...f.params};let w;try{w=await fetch(f.target,d)}catch(O){if(!(O instanceof Error))throw O;return[g,Vr(O)?new k({url:c}):O]}const h=await w.arrayBuffer();if(w?.ok)return i!=null&&(a=this.encoder.decode(h,i)),[g,null];try{if(w.status!==Hr)return[g,new Error(w.statusText)];const O=this.encoder.decode(h,B.payloadZ),E=B.decode(O);return[g,E]}catch(O){return[g,new Error(`[freighter] - failed to decode error: ${w.statusText}: ${O.message}`)]}});if(y!=null)return[null,y];if(a==null)throw new Error("Response must be defined");return[a,null]}}const Kr=(r,e)=>{class t{wrapped;constructor(i){this.wrapped=i}use(...i){this.wrapped.use(...i)}async send(i,a,c,d){const y=new pr.Breaker(e);do{const[f,g]=await this.wrapped.send(i,a,c,d);if(g==null)return[f,null];if(!k.matches(g))return[null,g];if(console.warn(`[freighter] ${y.retryMessage}`,g),!await y.wait())return[f,g]}while(!0)}}return new t(r)},Xr=async(r,e,t,n,i)=>{const[a,c]=await r.send(e,t,n,i);if(c!=null)throw c;return a},Qr=s.z.object({type:s.z.enum(["data","close","open"]),payload:s.z.unknown(),error:s.z.optional(B.payloadZ)});class _r{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 B.decode(e.error)}return null}send(e){if(this.serverClosed!=null)return new L;if(this.sendClosed)throw new P;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=B.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,Qr))}onClose(e){this.addMessage({type:"close",error:{type:e.code===tn?L.TYPE:P.TYPE,data:""}})}}const en="freighterctx",tn=1e3;class _ extends Qe{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 _(this.baseUrl,e,this.secure);return t.use(...this.middleware),t}async stream(e,t,n){let i;const[,a]=await this.executeMiddleware({target:e,protocol:"websocket",params:{},role:"client"},async c=>{const d=new WebSocket(this.buildURL(e,c)),y={...c,params:{}};d.binaryType=_.MESSAGE_TYPE;const f=await this.wrapSocket(d,t,n);return f instanceof Error?[y,f]:(i=f,[y,null])});if(a!=null)throw a;return i}buildURL(e,t){const n=hr({[_e]:this.encoder.contentType,...t.params},en);return this.baseUrl.child(e).toString()+n}async wrapSocket(e,t,n){return await new Promise(i=>{e.onopen=()=>{const a=new _r(e,this.encoder,t,n);a.receiveOpenAck().then(c=>{c!=null?i(c):i(a)}).catch(c=>i(c))},e.onerror=a=>{const c=a;i(new Error(c.message))}})}}exports.EOF=L;exports.HTTPClient=Jr;exports.StreamClosed=P;exports.Unreachable=k;exports.WebSocketClient=_;exports.sendRequired=Xr;exports.unaryWithBreaker=Kr;