@synnaxlabs/freighter 0.33.0 → 0.35.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.
package/dist/errors.d.ts CHANGED
@@ -25,7 +25,6 @@ export declare const errorMatcher: (type: string) => (e: string | Error | unknow
25
25
  export declare class BaseTypedError extends Error implements TypedError {
26
26
  readonly discriminator = "FreighterError";
27
27
  type: string;
28
- constructor(message?: string);
29
28
  }
30
29
  type ErrorDecoder = (encoded: ErrorPayload) => Error | null;
31
30
  type ErrorEncoder = (error: TypedError) => ErrorPayload | null;
@@ -75,18 +74,17 @@ export declare const encodeError: (error: unknown) => ErrorPayload;
75
74
  export declare const decodeError: (payload: ErrorPayload) => Error | null;
76
75
  export declare class UnknownError extends BaseTypedError implements TypedError {
77
76
  type: string;
78
- constructor(message: string);
79
77
  }
80
78
  /** Thrown/returned when a stream closed normally. */
81
79
  export declare class EOF extends BaseTypedError implements TypedError {
82
- static readonly TYPE: string;
80
+ static readonly TYPE = "freighter.eof";
83
81
  type: string;
84
82
  static readonly matches: (e: string | Error | unknown) => boolean;
85
83
  constructor();
86
84
  }
87
85
  /** Thrown/returned when a stream is closed abnormally. */
88
86
  export declare class StreamClosed extends BaseTypedError implements TypedError {
89
- static readonly TYPE: string;
87
+ static readonly TYPE = "freighter.stream_closed";
90
88
  static readonly matches: (e: string | Error | unknown) => boolean;
91
89
  type: string;
92
90
  constructor();
@@ -97,7 +95,7 @@ export interface UnreachableArgs {
97
95
  }
98
96
  /** Thrown when a target is unreachable. */
99
97
  export declare class Unreachable extends BaseTypedError implements TypedError {
100
- static readonly TYPE: string;
98
+ static readonly TYPE = "freighter.unreachable";
101
99
  type: string;
102
100
  static readonly matches: (e: string | Error | unknown) => boolean;
103
101
  url: URL;
@@ -1 +1 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,+FAA+F;AAC/F,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,OAAO,EAAE,CAAC,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,OAAO,KAAK,OAAO,CAAC;CACnD;AAED,MAAM,WAAW,UAAW,SAAQ,KAAK;IACvC,aAAa,EAAE,gBAAgB,CAAC;IAChC;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;GAIG;AACH,eAAO,MAAM,YAAY,SAChB,MAAM,SACT,MAAM,GAAG,KAAK,GAAG,OAAO,KAAG,OAM9B,CAAC;AAEJ,qBAAa,cAAe,SAAQ,KAAM,YAAW,UAAU;IAC7D,QAAQ,CAAC,aAAa,oBAAoB;IAC1C,IAAI,EAAE,MAAM,CAAM;gBAEN,OAAO,CAAC,EAAE,MAAM;CAG7B;AAED,KAAK,YAAY,GAAG,CAAC,OAAO,EAAE,YAAY,KAAK,KAAK,GAAG,IAAI,CAAC;AAC5D,KAAK,YAAY,GAAG,CAAC,KAAK,EAAE,UAAU,KAAK,YAAY,GAAG,IAAI,CAAC;AAE/D,eAAO,MAAM,YAAY,UAAW,OAAO,KAAG,KAAK,IAAI,UAStD,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,CAAC,QAAQ,MAAM,UAAU,KAAK,GAAG,IAAI,KAAG,CAUvE,CAAC;AAEF,eAAO,MAAM,OAAO,YAAY,CAAC;AACjC,eAAO,MAAM,IAAI,QAAQ,CAAC;AAC1B,eAAO,MAAM,SAAS,cAAc,CAAC;AAErC,eAAO,MAAM,MAAM;;;;;;;;;EAAmD,CAAC;AAEvE,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,MAAM,CAAC,CAAC;AAsClD;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,wBAGvB;IACD,MAAM,EAAE,YAAY,CAAC;IACrB,MAAM,EAAE,YAAY,CAAC;CACtB,KAAG,IAA6C,CAAC;AAElD;;;;;GAKG;AACH,eAAO,MAAM,WAAW,UAAW,OAAO,KAAG,YAE5C,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,YAAa,YAAY,KAAG,KAAK,GAAG,IAE3D,CAAC;AAEF,qBAAa,YAAa,SAAQ,cAAe,YAAW,UAAU;IACpE,IAAI,SAAa;gBACL,OAAO,EAAE,MAAM;CAG5B;AAID,qDAAqD;AACrD,qBAAa,GAAI,SAAQ,cAAe,YAAW,UAAU;IAC3D,MAAM,CAAC,QAAQ,CAAC,IAAI,SAAgC;IACpD,IAAI,SAAY;IAChB,MAAM,CAAC,QAAQ,CAAC,OAAO,MA1InB,MAAM,GAAG,KAAK,GAAG,OAAO,KAAG,OAAO,CA0IW;;CAKlD;AAED,0DAA0D;AAC1D,qBAAa,YAAa,SAAQ,cAAe,YAAW,UAAU;IACpE,MAAM,CAAC,QAAQ,CAAC,IAAI,SAA0C;IAC9D,MAAM,CAAC,QAAQ,CAAC,OAAO,MApJnB,MAAM,GAAG,KAAK,GAAG,OAAO,KAAG,OAAO,CAoJoB;IAC1D,IAAI,SAAqB;;CAK1B;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,GAAG,CAAC;CACX;AAED,2CAA2C;AAC3C,qBAAa,WAAY,SAAQ,cAAe,YAAW,UAAU;IACnE,MAAM,CAAC,QAAQ,CAAC,IAAI,SAAwC;IAC5D,IAAI,SAAoB;IACxB,MAAM,CAAC,QAAQ,CAAC,OAAO,MArKnB,MAAM,GAAG,KAAK,GAAG,OAAO,KAAG,OAAO,CAqKmB;IACzD,GAAG,EAAE,GAAG,CAAC;gBAEG,IAAI,GAAE,eAAoB;CAKvC"}
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;AACpC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,+FAA+F;AAC/F,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,OAAO,EAAE,CAAC,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,OAAO,KAAK,OAAO,CAAC;CACnD;AAED,MAAM,WAAW,UAAW,SAAQ,KAAK;IACvC,aAAa,EAAE,gBAAgB,CAAC;IAChC;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;;GAIG;AACH,eAAO,MAAM,YAAY,SAChB,MAAM,SACT,MAAM,GAAG,KAAK,GAAG,OAAO,KAAG,OAM9B,CAAC;AAEJ,qBAAa,cAAe,SAAQ,KAAM,YAAW,UAAU;IAC7D,QAAQ,CAAC,aAAa,oBAAoB;IAC1C,IAAI,EAAE,MAAM,CAAM;CACnB;AAED,KAAK,YAAY,GAAG,CAAC,OAAO,EAAE,YAAY,KAAK,KAAK,GAAG,IAAI,CAAC;AAC5D,KAAK,YAAY,GAAG,CAAC,KAAK,EAAE,UAAU,KAAK,YAAY,GAAG,IAAI,CAAC;AAE/D,eAAO,MAAM,YAAY,UAAW,OAAO,KAAG,KAAK,IAAI,UAStD,CAAC;AAEF,eAAO,MAAM,eAAe,GAAI,CAAC,QAAQ,MAAM,UAAU,KAAK,GAAG,IAAI,KAAG,CAUvE,CAAC;AAEF,eAAO,MAAM,OAAO,YAAY,CAAC;AACjC,eAAO,MAAM,IAAI,QAAQ,CAAC;AAC1B,eAAO,MAAM,SAAS,cAAc,CAAC;AAErC,eAAO,MAAM,MAAM;;;;;;;;;EAAmD,CAAC;AAEvE,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,MAAM,CAAC,CAAC;AAqClD;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,wBAGvB;IACD,MAAM,EAAE,YAAY,CAAC;IACrB,MAAM,EAAE,YAAY,CAAC;CACtB,KAAG,IAA6C,CAAC;AAElD;;;;;GAKG;AACH,eAAO,MAAM,WAAW,UAAW,OAAO,KAAG,YAAsC,CAAC;AAEpF;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,YAAa,YAAY,KAAG,KAAK,GAAG,IAClC,CAAC;AAE3B,qBAAa,YAAa,SAAQ,cAAe,YAAW,UAAU;IACpE,IAAI,SAAa;CAClB;AAID,qDAAqD;AACrD,qBAAa,GAAI,SAAQ,cAAe,YAAW,UAAU;IAC3D,MAAM,CAAC,QAAQ,CAAC,IAAI,mBAAgC;IACpD,IAAI,SAAY;IAChB,MAAM,CAAC,QAAQ,CAAC,OAAO,MA/HnB,MAAM,GAAG,KAAK,GAAG,OAAO,KAAG,OAAO,CA+HW;;CAKlD;AAED,0DAA0D;AAC1D,qBAAa,YAAa,SAAQ,cAAe,YAAW,UAAU;IACpE,MAAM,CAAC,QAAQ,CAAC,IAAI,6BAA0C;IAC9D,MAAM,CAAC,QAAQ,CAAC,OAAO,MAzInB,MAAM,GAAG,KAAK,GAAG,OAAO,KAAG,OAAO,CAyIoB;IAC1D,IAAI,SAAqB;;CAK1B;AAED,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,GAAG,CAAC;CACX;AAED,2CAA2C;AAC3C,qBAAa,WAAY,SAAQ,cAAe,YAAW,UAAU;IACnE,MAAM,CAAC,QAAQ,CAAC,IAAI,2BAAwC;IAC5D,IAAI,SAAoB;IACxB,MAAM,CAAC,QAAQ,CAAC,OAAO,MA1JnB,MAAM,GAAG,KAAK,GAAG,OAAO,KAAG,OAAO,CA0JmB;IACzD,GAAG,EAAE,GAAG,CAAC;gBAEG,IAAI,GAAE,eAAoB;CAKvC"}
@@ -1,13 +1,13 @@
1
- "use strict";var ht=Object.defineProperty;var dt=(r,e,t)=>e in r?ht(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var p=(r,e,t)=>dt(r,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("zod"),ft=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)},We=r=>{const e=(t,n=ge)=>{if(typeof t=="string")return r(t);if(Array.isArray(t))return t.map(c=>e(c,n));if(!le(t))return t;n=yt(n);const s={},a=t;return Object.keys(a).forEach(c=>{let d=a[c];const f=r(c);n.recursive&&(le(d)?Ae(d,n.keepTypesOnRecursion)||(d=e(d,n)):n.recursiveInArray&&Ee(d)&&(d=[...d].map(y=>{let T=y;return le(y)?Ae(T,n.keepTypesOnRecursion)||(T=e(y,n)):Ee(y)&&(T=e({key:y},n).key),T}))),s[f]=d}),s};return e},Ve=We(ft),gt=r=>r.replace(/([a-z0-9])([A-Z])/g,(e,t,n)=>`${t}_${n.toLowerCase()}`),pt=We(gt),ge={recursive:!0,recursiveInArray:!0,keepTypesOnRecursion:[Number,String,Uint8Array]},yt=(r=ge)=>(r.recursive==null?r=ge:r.recursiveInArray==null&&(r.recursiveInArray=!1),r),Ee=r=>r!=null&&Array.isArray(r),le=r=>r!=null&&typeof r=="object"&&!Array.isArray(r),Ae=(r,e)=>(e||[]).some(t=>r instanceof t),Ze=r=>r!=null&&typeof r=="object"&&!Array.isArray(r);var mt=Object.defineProperty,wt=(r,e,t)=>e in r?mt(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,Q=(r,e,t)=>wt(r,typeof e!="symbol"?e+"":e,t);let bt=class{constructor(){Q(this,"contentType","application/json"),Q(this,"decoder"),Q(this,"encoder"),this.decoder=new TextDecoder,this.encoder=new TextEncoder}encode(e){return this.encoder.encode(this.encodeString(e)).buffer}decode(e,t){return this.decodeString(this.decoder.decode(e),t)}decodeString(e,t){const n=JSON.parse(e),s=Ve(n);return t!=null?t.parse(s):s}encodeString(e){const t=pt(e);return JSON.stringify(t,(n,s)=>ArrayBuffer.isView(s)?Array.from(s):Ze(s)&&"encode_value"in s?typeof s.value=="bigint"?s.value.toString():s.value:typeof s=="bigint"?s.toString():s)}static registerCustomType(){}},Tt=class{constructor(){Q(this,"contentType","text/csv")}encode(e){const t=this.encodeString(e);return new TextEncoder().encode(t).buffer}decode(e,t){const n=new TextDecoder().decode(e);return this.decodeString(n,t)}encodeString(e){if(!Array.isArray(e)||e.length===0||!Ze(e[0]))throw new Error("Payload must be an array of objects");const t=Object.keys(e[0]),n=[t.join(",")];return e.forEach(s=>{const a=t.map(c=>JSON.stringify(s[c]??""));n.push(a.join(","))}),n.join(`
1
+ "use strict";var ht=Object.defineProperty;var dt=(r,e,t)=>e in r?ht(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var p=(r,e,t)=>dt(r,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("zod"),ft=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)},We=r=>{const e=(t,n=ge)=>{if(typeof t=="string")return r(t);if(Array.isArray(t))return t.map(c=>e(c,n));if(!le(t))return t;n=yt(n);const s={},a=t;return Object.keys(a).forEach(c=>{let d=a[c];const f=r(c);n.recursive&&(le(d)?Ae(d,n.keepTypesOnRecursion)||(d=e(d,n)):n.recursiveInArray&&Ee(d)&&(d=[...d].map(y=>{let T=y;return le(y)?Ae(T,n.keepTypesOnRecursion)||(T=e(y,n)):Ee(y)&&(T=e({key:y},n).key),T}))),s[f]=d}),s};return e},Ve=We(ft),gt=r=>r.replace(/([a-z0-9])([A-Z])/g,(e,t,n)=>`${t}_${n.toLowerCase()}`),pt=We(gt),ge={recursive:!0,recursiveInArray:!0,keepTypesOnRecursion:[Number,String,Uint8Array]},yt=(r=ge)=>(r.recursive==null?r=ge:r.recursiveInArray??(r.recursiveInArray=!1),r),Ee=r=>r!=null&&Array.isArray(r),le=r=>r!=null&&typeof r=="object"&&!Array.isArray(r),Ae=(r,e)=>(e||[]).some(t=>r instanceof t),Ze=r=>r!=null&&typeof r=="object"&&!Array.isArray(r);var mt=Object.defineProperty,wt=(r,e,t)=>e in r?mt(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,Q=(r,e,t)=>wt(r,typeof e!="symbol"?e+"":e,t);let bt=class{constructor(){Q(this,"contentType","application/json"),Q(this,"decoder"),Q(this,"encoder"),this.decoder=new TextDecoder,this.encoder=new TextEncoder}encode(e){return this.encoder.encode(this.encodeString(e)).buffer}decode(e,t){return this.decodeString(this.decoder.decode(e),t)}decodeString(e,t){const n=JSON.parse(e),s=Ve(n);return t!=null?t.parse(s):s}encodeString(e){const t=pt(e);return JSON.stringify(t,(n,s)=>ArrayBuffer.isView(s)?Array.from(s):Ze(s)&&"encode_value"in s?typeof s.value=="bigint"?s.value.toString():s.value:typeof s=="bigint"?s.toString():s)}static registerCustomType(){}},Tt=class{constructor(){Q(this,"contentType","text/csv")}encode(e){const t=this.encodeString(e);return new TextEncoder().encode(t).buffer}decode(e,t){const n=new TextDecoder().decode(e);return this.decodeString(n,t)}encodeString(e){if(!Array.isArray(e)||e.length===0||!Ze(e[0]))throw new Error("Payload must be an array of objects");const t=Object.keys(e[0]),n=[t.join(",")];return e.forEach(s=>{const a=t.map(c=>JSON.stringify(s[c]??""));n.push(a.join(","))}),n.join(`
2
2
  `)}decodeString(e,t){const[n,...s]=e.trim().split(`
3
- `).map(d=>d.trim());if(n.length===0)return t!=null?t.parse({}):{};const a=n.split(",").map(d=>d.trim()),c={};return a.forEach(d=>{c[d]=[]}),s.forEach(d=>{const f=d.split(",").map(y=>y.trim());a.forEach((y,T)=>{const l=this.parseValue(f[T]);l!=null&&c[y].push(l)})}),t!=null?t.parse(c):c}parseValue(e){if(e==null||e.length===0)return null;const t=Number(e);return isNaN(t)?e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e:t}static registerCustomType(){}},Ot=class{constructor(){Q(this,"contentType","text/plain")}encode(e){return new TextEncoder().encode(e).buffer}decode(e,t){const n=new TextDecoder().decode(e);return t!=null?t.parse(n):n}};const te=new bt;new Tt;new Ot;const oe=i.z.tuple([i.z.number(),i.z.number()]);i.z.tuple([i.z.bigint(),i.z.bigint()]);const Je=i.z.object({width:i.z.number(),height:i.z.number()}),vt=i.z.object({signedWidth:i.z.number(),signedHeight:i.z.number()}),St=["width","height"];i.z.enum(St);const It=["start","center","end"],Nt=["signedWidth","signedHeight"];i.z.enum(Nt);const ie=i.z.object({x:i.z.number(),y:i.z.number()}),Et=i.z.object({clientX:i.z.number(),clientY:i.z.number()}),At=["x","y"],He=i.z.enum(At),Ke=["top","right","bottom","left"];i.z.enum(Ke);const xt=["left","right"],Xe=i.z.enum(xt),zt=["top","bottom"],Qe=i.z.enum(zt),_e=["center"],xe=i.z.enum(_e),Mt=[...Ke,..._e],et=i.z.enum(Mt);i.z.enum(It);const Bt=["first","last"];i.z.enum(Bt);const Rt=i.z.object({lower:i.z.number(),upper:i.z.number()}),$t=i.z.object({lower:i.z.bigint(),upper:i.z.bigint()});i.z.union([Rt,oe]);i.z.union([$t,oe]);i.z.union([He,et]);i.z.union([He,et,i.z.instanceof(String)]);const Ut=r=>typeof r=="bigint"||r instanceof BigInt,j=(r,e)=>Ut(r)?r.valueOf()*BigInt(e.valueOf()):r.valueOf()*Number(e.valueOf()),k=(r,e)=>{const t={};if(typeof r=="number"||typeof r=="bigint")e!=null?(t.lower=r,t.upper=e):(t.lower=typeof r=="bigint"?0n:0,t.upper=r);else if(Array.isArray(r)){if(r.length!==2)throw new Error("bounds: expected array of length 2");[t.lower,t.upper]=r}else return ze(r);return ze(t)},ze=r=>r.lower>r.upper?{lower:r.upper,upper:r.lower}:r,Me=(r,e)=>{const t=k(r);return e<t.lower?t.lower:e>=t.upper?t.upper-(typeof t.upper=="number"?1:1n):e};i.z.object({x:Xe.or(xe),y:Qe.or(xe)});const Ct=i.z.object({x:Xe,y:Qe}),Dt=Object.freeze({x:"left",y:"top"}),Pt=(r,e)=>r.x===e.x&&r.y===e.y,Be=i.z.union([i.z.number(),ie,oe,Je,vt,Et]),Lt=(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}},Re=Object.freeze({x:0,y:0}),ee=i.z.union([i.z.number(),i.z.string()]);i.z.object({top:ee,left:ee,width:ee,height:ee});i.z.object({left:i.z.number(),top:i.z.number(),right:i.z.number(),bottom:i.z.number()});i.z.object({one:ie,two:ie,root:Ct});const Oe=(r,e,t=0,n=0,s)=>{const a={one:{...Re},two:{...Re},root:s??Dt};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:s??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))},he=r=>{const e=Oe(r);return{lower:e.one.x,upper:e.two.x}},de=r=>{const e=Oe(r);return{lower:e.one.y,upper:e.two.y}},Yt=r=>typeof r!="object"||r==null?!1:"one"in r&&"two"in r&&"root"in r;var kt=Object.defineProperty,jt=(r,e,t)=>e in r?kt(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,C=(r,e,t)=>jt(r,typeof e!="symbol"?e+"":e,t);const Ft=(r,e,t)=>e!==void 0&&r<e?e:t!==void 0&&r>t?t:r;i.z.object({offset:Be,scale:Be});const qt=r=>(e,t,n,s)=>t==="dimension"?[e,n]:[e,s?n-r:n+r],Gt=r=>(e,t,n,s)=>[e,s?n/r:n*r],Wt=r=>(e,t,n)=>{if(e===null)return[r,n];const{lower:s,upper:a}=e,{lower:c,upper:d}=r,f=a-s,y=d-c;if(t==="dimension")return[r,n*(y/f)];const T=(n-s)*(y/f)+c;return[r,T]},Vt=r=>(e,t,n)=>[r,n],Zt=()=>(r,e,t)=>{if(r===null)throw new Error("cannot invert without bounds");if(e==="dimension")return[r,t];const{lower:n,upper:s}=r;return[r,s-(t-n)]},Jt=r=>(e,t,n)=>{const{lower:s,upper:a}=r;return n=Ft(n,s,a),[e,n]},pe=class V{constructor(){C(this,"ops",[]),C(this,"currBounds",null),C(this,"currType",null),C(this,"reversed",!1),this.ops=[]}static translate(e){return new V().translate(e)}static magnify(e){return new V().magnify(e)}static scale(e,t){return new V().scale(e,t)}translate(e){const t=this.new(),n=qt(e);return n.type="translate",t.ops.push(n),t}magnify(e){const t=this.new(),n=Gt(e);return n.type="magnify",t.ops.push(n),t}scale(e,t){const n=k(e,t),s=this.new(),a=Wt(n);return a.type="scale",s.ops.push(a),s}clamp(e,t){const n=k(e,t),s=this.new(),a=Jt(n);return a.type="clamp",s.ops.push(a),s}reBound(e,t){const n=k(e,t),s=this.new(),a=Vt(n);return a.type="re-bound",s.ops.push(a),s}invert(){const e=Zt();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 V;return e.ops=this.ops.slice(),e.reversed=this.reversed,e}exec(e,t){return this.currBounds=null,this.ops.reduce(([n,s],a)=>a(n,e,s,this.reversed),[null,t])[1]}reverse(){const e=this.new();e.ops.reverse();const t=[];return e.ops.forEach((n,s)=>{if(n.type==="scale"||t.some(([c,d])=>s>=c&&s<=d))return;const a=e.ops.findIndex((c,d)=>c.type==="scale"&&d>s);a!==-1&&t.push([s,a])}),t.forEach(([n,s])=>{const a=e.ops.slice(n,s);a.unshift(e.ops[s]),e.ops.splice(n,s-n+1,...a)}),e.reversed=!e.reversed,e}};C(pe,"IDENTITY",new pe);let $e=pe;const Ue=class U{constructor(e=new $e,t=new $e,n=null){C(this,"x"),C(this,"y"),C(this,"currRoot"),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=Lt(e,t),s=this.copy();return s.x=this.x.translate(n.x),s.y=this.y.translate(n.y),s}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(Yt(e)){const n=this.currRoot;return t.currRoot=e.root,n!=null&&!Pt(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(he(e)),t.y=t.y.scale(de(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(he(e)),t.y=this.y.reBound(de(e)),t}clamp(e){const t=this.copy();return t.x=this.x.clamp(he(e)),t.y=this.y.clamp(de(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)}}box(e){return Oe(this.pos(e.one),this.pos(e.two),0,0,this.currRoot??e.root)}};C(Ue,"IDENTITY",new Ue);const Ht=r=>r!=null&&typeof r=="object"&&"toString"in r,Kt=(r,e=!1)=>{const t=Ht(r)?"stringer":typeof r;let n;switch(t){case"string":n=(s,a)=>s.localeCompare(a);break;case"stringer":n=(s,a)=>s.toString().localeCompare(a.toString());break;case"number":n=(s,a)=>Number(s)-Number(a);break;case"bigint":n=(s,a)=>BigInt(s)-BigInt(a)>0n?1:-1;break;case"boolean":n=(s,a)=>Number(s)-Number(a);break;case"undefined":n=()=>0;break;default:return console.warn(`sortFunc: unknown type ${t}`),()=>-1}return e?Xt(n):n},Xt=r=>(e,t)=>r(t,e),Qt=i.z.object({signedWidth:i.z.number(),signedHeight:i.z.number()});i.z.union([Je,Qt,ie,oe]);const _t=i.z.bigint().or(i.z.string().transform(BigInt));var er=Object.defineProperty,tr=(r,e,t)=>e in r?er(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,u=(r,e,t)=>tr(r,typeof e!="symbol"?e+"":e,t);let rr=(r,e=21)=>(t=e)=>{let n="",s=t;for(;s--;)n+=r[Math.random()*r.length|0];return n};const nr="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",sr=rr(nr,11),ir=i.z.enum(["static","dynamic"]),tt=(r,e)=>{const t=new O(e);if(![S.DAY,S.HOUR,S.MINUTE,S.SECOND,S.MILLISECOND,S.MICROSECOND,S.NANOSECOND].some(s=>s.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 O?new O(n):new S(n)},m=class h{constructor(e,t="UTC"){if(u(this,"value"),u(this,"encodeValue",!0),e==null)this.value=h.now().valueOf();else if(e instanceof Date)this.value=BigInt(e.getTime())*h.MILLISECOND.valueOf();else if(typeof e=="string")this.value=h.parseDateTimeString(e,t).valueOf();else if(Array.isArray(e))this.value=h.parseDate(e);else{let n=BigInt(0);e instanceof Number&&(e=e.valueOf()),t==="local"&&(n=h.utcOffset.valueOf()),typeof e=="number"&&(isFinite(e)?e=Math.trunc(e):(isNaN(e)&&(e=0),e===1/0?e=h.MAX:e=h.MIN)),this.value=BigInt(e.valueOf())+n}}static parseDate([e=1970,t=1,n=1]){const s=new Date(e,t-1,n,0,0,0,0);return new h(BigInt(s.getTime())*h.MILLISECOND.valueOf()).truncate(h.DAY).valueOf()}encode(){return this.value.toString()}valueOf(){return this.value}static parseTimeString(e,t="UTC"){const[n,s,a]=e.split(":");let c="00",d="00";a!=null&&([c,d]=a.split("."));let f=h.hours(parseInt(n??"00",10)).add(h.minutes(parseInt(s??"00",10))).add(h.seconds(parseInt(c??"00",10))).add(h.milliseconds(parseInt(d??"00",10)));return t==="local"&&(f=f.add(h.utcOffset)),f.valueOf()}static parseDateTimeString(e,t="UTC"){if(!e.includes("/")&&!e.includes("-"))return h.parseTimeString(e,t);const n=new Date(e);return e.includes(":")||n.setUTCHours(0,0,0,0),new h(BigInt(n.getTime())*h.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(h.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 S(BigInt(new Date().getTimezoneOffset())*h.MINUTE.valueOf())}static since(e){return new h().span(e)}date(){return new Date(this.milliseconds())}equals(e){return this.valueOf()===new h(e).valueOf()}span(e){return this.range(e).span}range(e){return new ve(this,e).makeValid()}spanRange(e){return this.range(this.add(e)).makeValid()}get isZero(){return this.valueOf()===BigInt(0)}after(e){return this.valueOf()>new h(e).valueOf()}afterEq(e){return this.valueOf()>=new h(e).valueOf()}before(e){return this.valueOf()<new h(e).valueOf()}beforeEq(e){return this.valueOf()<=new h(e).valueOf()}add(e){return new h(this.valueOf()+BigInt(e.valueOf()))}sub(e){return new h(this.valueOf()-BigInt(e.valueOf()))}milliseconds(){return Number(this.valueOf())/Number(h.MILLISECOND.valueOf())}toString(){return this.date().toISOString()}remainder(e){return tt(this,e)}get isToday(){return this.truncate(S.DAY).equals(h.now().truncate(S.DAY))}truncate(e){return this.sub(this.remainder(e))}static now(){return new h(new Date)}static max(...e){let t=h.MIN;for(const n of e){const s=new h(n);s.after(t)&&(t=s)}return t}static min(...e){let t=h.MAX;for(const n of e){const s=new h(n);s.before(t)&&(t=s)}return t}static nanoseconds(e){return new h(e)}static microseconds(e){return h.nanoseconds(e*1e3)}static milliseconds(e){return h.microseconds(e*1e3)}static seconds(e){return h.milliseconds(e*1e3)}static minutes(e){return h.seconds(e*60)}static hours(e){return h.minutes(e*60)}static days(e){return h.hours(e*24)}};u(m,"NANOSECOND",m.nanoseconds(1)),u(m,"MICROSECOND",m.microseconds(1)),u(m,"MILLISECOND",m.milliseconds(1)),u(m,"SECOND",m.seconds(1)),u(m,"MINUTE",m.minutes(1)),u(m,"HOUR",m.hours(1)),u(m,"DAY",m.days(1)),u(m,"MAX",new m((1n<<63n)-1n)),u(m,"MIN",new m(0)),u(m,"ZERO",new m(0)),u(m,"z",i.z.union([i.z.object({value:i.z.bigint()}).transform(r=>new m(r.value)),i.z.string().transform(r=>new m(BigInt(r))),i.z.instanceof(Number).transform(r=>new m(r)),i.z.number().transform(r=>new m(r)),i.z.instanceof(m)]));let O=m;const w=class g{constructor(e){u(this,"value"),u(this,"encodeValue",!0),typeof e=="number"&&(e=Math.trunc(e.valueOf())),this.value=BigInt(e.valueOf())}static fromSeconds(e){return e instanceof g?e:e instanceof Ce?e.period:e instanceof O?new g(e):["number","bigint"].includes(typeof e)?g.seconds(e):new g(e)}static fromMilliseconds(e){return e instanceof g?e:e instanceof Ce?e.period:e instanceof O?new g(e):["number","bigint"].includes(typeof e)?g.milliseconds(e):new g(e)}encode(){return this.value.toString()}valueOf(){return this.value}lessThan(e){return this.valueOf()<new g(e).valueOf()}greaterThan(e){return this.valueOf()>new g(e).valueOf()}lessThanOrEqual(e){return this.valueOf()<=new g(e).valueOf()}greaterThanOrEqual(e){return this.valueOf()>=new g(e).valueOf()}remainder(e){return tt(this,e)}truncate(e){return new g(BigInt(Math.trunc(Number(this.valueOf()/e.valueOf())))*e.valueOf())}toString(){const e=this.truncate(g.DAY),t=this.truncate(g.HOUR),n=this.truncate(g.MINUTE),s=this.truncate(g.SECOND),a=this.truncate(g.MILLISECOND),c=this.truncate(g.MICROSECOND),d=this.truncate(g.NANOSECOND),f=e,y=t.sub(e),T=n.sub(t),l=s.sub(n),E=a.sub(s),R=c.sub(a),$=d.sub(c);let x="";return f.isZero||(x+=`${f.days}d `),y.isZero||(x+=`${y.hours}h `),T.isZero||(x+=`${T.minutes}m `),l.isZero||(x+=`${l.seconds}s `),E.isZero||(x+=`${E.milliseconds}ms `),R.isZero||(x+=`${R.microseconds}µs `),$.isZero||(x+=`${$.nanoseconds}ns`),x.trim()}get days(){return Number(this.valueOf())/Number(g.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(g.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(g.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(g.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(g.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(g.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get isZero(){return this.valueOf()===BigInt(0)}equals(e){return this.valueOf()===new g(e).valueOf()}add(e){return new g(this.valueOf()+new g(e).valueOf())}sub(e){return new g(this.valueOf()-new g(e).valueOf())}static nanoseconds(e=1){return new g(e)}static microseconds(e=1){return g.nanoseconds(j(e,1e3))}static milliseconds(e=1){return g.microseconds(j(e,1e3))}static seconds(e=1){return g.milliseconds(j(e,1e3))}static minutes(e=1){return g.seconds(j(e,60))}static hours(e){return g.minutes(j(e,60))}static days(e){return g.hours(j(e,24))}};u(w,"NANOSECOND",w.nanoseconds(1)),u(w,"MICROSECOND",w.microseconds(1)),u(w,"MILLISECOND",w.milliseconds(1)),u(w,"SECOND",w.seconds(1)),u(w,"MINUTE",w.minutes(1)),u(w,"HOUR",w.hours(1)),u(w,"DAY",w.days(1)),u(w,"MAX",new w((1n<<63n)-1n)),u(w,"MIN",new w(0)),u(w,"ZERO",new w(0)),u(w,"z",i.z.union([i.z.object({value:i.z.bigint()}).transform(r=>new w(r.value)),i.z.string().transform(r=>new w(BigInt(r))),i.z.instanceof(Number).transform(r=>new w(r)),i.z.number().transform(r=>new w(r)),i.z.instanceof(w)]));let S=w;const Z=class re extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new re(e).valueOf()}get period(){return S.seconds(1/this.valueOf())}sampleCount(e){return new S(e).seconds*this.valueOf()}byteCount(e,t){return this.sampleCount(e)*new A(t).valueOf()}span(e){return S.seconds(e/this.valueOf())}byteSpan(e,t){return this.span(e.valueOf()/t.valueOf())}static hz(e){return new re(e)}static khz(e){return re.hz(e*1e3)}};u(Z,"z",i.z.union([i.z.number().transform(r=>new Z(r)),i.z.instanceof(Number).transform(r=>new Z(r)),i.z.instanceof(Z)]));let Ce=Z;const I=class extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}length(e){return e.valueOf()/this.valueOf()}size(e){return new ye(e*this.valueOf())}};u(I,"UNKNOWN",new I(0)),u(I,"BIT128",new I(16)),u(I,"BIT64",new I(8)),u(I,"BIT32",new I(4)),u(I,"BIT16",new I(2)),u(I,"BIT8",new I(1)),u(I,"z",i.z.union([i.z.number().transform(r=>new I(r)),i.z.instanceof(Number).transform(r=>new I(r)),i.z.instanceof(I)]));let A=I;const z=class ne{constructor(e,t){u(this,"start"),u(this,"end"),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 S(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 ne(this.end,this.start)}equals(e){return this.start.equals(e.start)&&this.end.equals(e.end)}toString(){return`${this.start.toString()} - ${this.end.toString()}`}toPrettyString(){return`${this.start.fString("preciseDate")} - ${this.span.toString()}`}overlapsWith(e,t=S.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 s=O.max(n.start,e.start),a=O.min(n.end,e.end);return a.before(s)?!1:new S(a.sub(s)).greaterThanOrEqual(t)}roughlyEquals(e,t){let n=this.start.sub(e.start).valueOf(),s=this.end.sub(e.end).valueOf();return n<0&&(n=-n),s<0&&(s=-s),n<=t.valueOf()&&s<=t.valueOf()}contains(e){return e instanceof ne?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const t=new ne(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}};u(z,"MAX",new z(O.MIN,O.MAX)),u(z,"MIN",new z(O.MAX,O.MIN)),u(z,"ZERO",new z(O.ZERO,O.ZERO)),u(z,"z",i.z.union([i.z.object({start:O.z,end:O.z}).transform(r=>new z(r.start,r.end)),i.z.instanceof(z)]));let ve=z;const o=class M extends String{constructor(e){if(e instanceof M||typeof e=="string"||typeof e.valueOf()=="string"){super(e.valueOf());return}else{const t=M.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);if(t!=null){super(t.valueOf());return}}throw super(M.UNKNOWN.valueOf()),new Error(`unable to find data type for ${e.toString()}`)}get Array(){const e=M.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(M.JSON)||this.equals(M.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(M.UUID)}get isInteger(){return this.toString().startsWith("int")}get isFloat(){return this.toString().startsWith("float")}get density(){const e=M.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}canSafelyCastTo(e){return this.equals(e)?!0:this.isVariable&&!e.isVariable||!this.isVariable&&e.isVariable?!1:this.isFloat&&e.isInteger||this.isInteger&&e.isFloat?this.density.valueOf()<e.density.valueOf():this.isFloat&&e.isFloat||this.isInteger&&e.isInteger?this.density.valueOf()<=e.density.valueOf():!1}canCastTo(e){return this.isNumeric&&e.isNumeric?!0:this.equals(e)}checkArray(e){return e.constructor===this.Array}toJSON(){return this.toString()}get usesBigInt(){return M.BIG_INT_TYPES.some(e=>e.equals(this))}};u(o,"UNKNOWN",new o("unknown")),u(o,"FLOAT64",new o("float64")),u(o,"FLOAT32",new o("float32")),u(o,"INT64",new o("int64")),u(o,"INT32",new o("int32")),u(o,"INT16",new o("int16")),u(o,"INT8",new o("int8")),u(o,"UINT64",new o("uint64")),u(o,"UINT32",new o("uint32")),u(o,"UINT16",new o("uint16")),u(o,"UINT8",new o("uint8")),u(o,"BOOLEAN",o.UINT8),u(o,"TIMESTAMP",new o("timestamp")),u(o,"UUID",new o("uuid")),u(o,"STRING",new o("string")),u(o,"JSON",new o("json")),u(o,"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]])),u(o,"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]])),u(o,"DENSITIES",new Map([[o.UINT8.toString(),A.BIT8],[o.UINT16.toString(),A.BIT16],[o.UINT32.toString(),A.BIT32],[o.UINT64.toString(),A.BIT64],[o.FLOAT32.toString(),A.BIT32],[o.FLOAT64.toString(),A.BIT64],[o.INT8.toString(),A.BIT8],[o.INT16.toString(),A.BIT16],[o.INT32.toString(),A.BIT32],[o.INT64.toString(),A.BIT64],[o.TIMESTAMP.toString(),A.BIT64],[o.STRING.toString(),A.UNKNOWN],[o.JSON.toString(),A.UNKNOWN],[o.UUID.toString(),A.BIT128]])),u(o,"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]),u(o,"BIG_INT_TYPES",[o.INT64,o.UINT64,o.TIMESTAMP]),u(o,"z",i.z.union([i.z.string().transform(r=>new o(r)),i.z.instanceof(o)]));let b=o;const N=class v extends Number{constructor(e){super(e.valueOf())}largerThan(e){return this.valueOf()>e.valueOf()}smallerThan(e){return this.valueOf()<e.valueOf()}add(e){return v.bytes(this.valueOf()+e.valueOf())}sub(e){return v.bytes(this.valueOf()-e.valueOf())}truncate(e){return new v(Math.trunc(this.valueOf()/e.valueOf())*e.valueOf())}remainder(e){return v.bytes(this.valueOf()%e.valueOf())}get gigabytes(){return this.valueOf()/v.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/v.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/v.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/v.TERABYTE.valueOf()}toString(){const e=this.truncate(v.TERABYTE),t=this.truncate(v.GIGABYTE),n=this.truncate(v.MEGABYTE),s=this.truncate(v.KILOBYTE),a=this.truncate(v.BYTE),c=e,d=t.sub(e),f=n.sub(t),y=s.sub(n),T=a.sub(s);let l="";return c.isZero||(l+=`${c.terabytes}TB `),d.isZero||(l+=`${d.gigabytes}GB `),f.isZero||(l+=`${f.megabytes}MB `),y.isZero||(l+=`${y.kilobytes}KB `),(!T.isZero||l==="")&&(l+=`${T.valueOf()}B`),l.trim()}static bytes(e=1){return new v(e)}static kilobytes(e=1){return v.bytes(e.valueOf()*1e3)}static megabytes(e=1){return v.kilobytes(e.valueOf()*1e3)}static gigabytes(e=1){return v.megabytes(e.valueOf()*1e3)}static terabytes(e){return v.gigabytes(e.valueOf()*1e3)}get isZero(){return this.valueOf()===0}};u(N,"BYTE",new N(1)),u(N,"KILOBYTE",N.kilobytes(1)),u(N,"MEGABYTE",N.megabytes(1)),u(N,"GIGABYTE",N.gigabytes(1)),u(N,"TERABYTE",N.terabytes(1)),u(N,"ZERO",new N(0)),u(N,"z",i.z.union([i.z.number().transform(r=>new N(r)),i.z.instanceof(N)]));let ye=N;i.z.union([i.z.instanceof(Uint8Array),i.z.instanceof(Uint16Array),i.z.instanceof(Uint32Array),i.z.instanceof(BigUint64Array),i.z.instanceof(Float32Array),i.z.instanceof(Float64Array),i.z.instanceof(Int8Array),i.z.instanceof(Int16Array),i.z.instanceof(Int32Array),i.z.instanceof(BigInt64Array)]);const rt=r=>{const e=typeof r;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||r instanceof O||r instanceof S||r instanceof Date},ar=(r,e,t,n=0)=>r.usesBigInt&&!e.usesBigInt?Number(t)-Number(n):!r.usesBigInt&&e.usesBigInt?BigInt(t.valueOf())-BigInt(n.valueOf()):H(t,-n).valueOf(),or=r=>r==null?!1:Array.isArray(r)||r instanceof ArrayBuffer||ArrayBuffer.isView(r)&&!(r instanceof DataView)||r instanceof lr?!0:rt(r),L=-1,ur=i.z.string().transform(r=>new Uint8Array(atob(r).split("").map(e=>e.charCodeAt(0))).buffer),cr=i.z.union([i.z.null(),i.z.undefined()]).transform(()=>new Uint8Array().buffer),me=10,J=class B{constructor(e){u(this,"key",""),u(this,"isSynnaxSeries",!0),u(this,"dataType"),u(this,"sampleOffset"),u(this,"gl"),u(this,"_data"),u(this,"_timeRange"),u(this,"alignment",0n),u(this,"_cachedMin"),u(this,"_cachedMax"),u(this,"writePos",L),u(this,"_refCount",0),u(this,"_cachedLength"),u(this,"_cachedIndexes"),or(e)&&(e={data:e});const{dataType:t,timeRange:n,sampleOffset:s=0,glBufferUsage:a="static",alignment:c=0n,key:d=sr()}=e,f=e.data??[];if(f instanceof B||typeof f=="object"&&"isSynnaxSeries"in f&&f.isSynnaxSeries===!0){const l=f;this.key=l.key,this.dataType=l.dataType,this.sampleOffset=l.sampleOffset,this.gl=l.gl,this._data=l._data,this._timeRange=l._timeRange,this.alignment=l.alignment,this._cachedMin=l._cachedMin,this._cachedMax=l._cachedMax,this.writePos=l.writePos,this._refCount=l._refCount,this._cachedLength=l._cachedLength;return}const y=rt(f),T=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(T||y){let l=f;if(!y){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.");l=f[0]}if(typeof l=="string")this.dataType=b.STRING;else if(typeof l=="number")this.dataType=b.FLOAT64;else if(typeof l=="bigint")this.dataType=b.INT64;else if(typeof l=="boolean")this.dataType=b.BOOLEAN;else if(l instanceof O||l instanceof Date||l instanceof O)this.dataType=b.TIMESTAMP;else if(typeof l=="object")this.dataType=b.JSON;else throw new Error(`cannot infer data type of ${typeof l} when constructing a Series from a JS array`)}else this.dataType=new b(f)}if(!T&&!y)this._data=f;else{let l=y?[f]:f;const E=l[0];(E instanceof O||E instanceof Date||E instanceof S)&&(l=l.map(R=>new O(R).valueOf())),this.dataType.equals(b.STRING)?(this._cachedLength=l.length,this._data=new TextEncoder().encode(l.join(`
4
- `)+`
5
- `)):this.dataType.equals(b.JSON)?(this._cachedLength=l.length,this._data=new TextEncoder().encode(l.map(R=>te.encodeString(R)).join(`
6
- `)+`
7
- `)):this._data=new this.dataType.Array(l).buffer}this.key=d,this.alignment=c,this.sampleOffset=s??0,this._timeRange=n,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 s=new new b(t).Array(e),a=new B({data:s.buffer,dataType:t,...n});return a.writePos=0,a}static generateTimestamps(e,t,n){const s=n.spanRange(t.span(e)),a=new BigInt64Array(e);for(let c=0;c<e;c++)a[c]=BigInt(n.add(t.span(c)).valueOf());return new B({data:a,dataType:b.TIMESTAMP,timeRange:s})}get refCount(){return this._refCount}static fromStrings(e,t){const n=new TextEncoder().encode(e.join(`
8
- `)+`
9
- `);return new B({data:n,dataType:b.STRING,timeRange:t})}static fromJSON(e,t){const n=new TextEncoder().encode(e.map(s=>te.encodeString(s)).join(`
10
- `)+`
11
- `);return new B({data:n,dataType:b.JSON,timeRange:t})}acquire(e){this._refCount++,e!=null&&this.updateGLBuffer(e)}release(){if(this._refCount--,this._refCount===0&&this.gl.control!=null)this.maybeGarbageCollectGLBuffer(this.gl.control);else if(this._refCount<0)throw new Error("cannot release an array 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===L)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===L)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 this._data instanceof ArrayBuffer||this._data instanceof SharedArrayBuffer?this._data:this._data.buffer}get underlyingData(){return new this.dataType.Array(this._data)}get data(){return this.writePos===L?this.underlyingData:new this.dataType.Array(this._data,0,this.writePos)}toStrings(){if(!this.dataType.matches(b.STRING,b.UUID))throw new Error("cannot convert non-string series to strings");return new TextDecoder().decode(this.underlyingData).split(`
3
+ `).map(d=>d.trim());if(n.length===0)return t!=null?t.parse({}):{};const a=n.split(",").map(d=>d.trim()),c={};return a.forEach(d=>{c[d]=[]}),s.forEach(d=>{const f=d.split(",").map(y=>y.trim());a.forEach((y,T)=>{const l=this.parseValue(f[T]);l!=null&&c[y].push(l)})}),t!=null?t.parse(c):c}parseValue(e){if(e==null||e.length===0)return null;const t=Number(e);return isNaN(t)?e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e:t}static registerCustomType(){}},Ot=class{constructor(){Q(this,"contentType","text/plain")}encode(e){return new TextEncoder().encode(e).buffer}decode(e,t){const n=new TextDecoder().decode(e);return t!=null?t.parse(n):n}};const te=new bt;new Tt;new Ot;const oe=i.z.tuple([i.z.number(),i.z.number()]);i.z.tuple([i.z.bigint(),i.z.bigint()]);const Je=i.z.object({width:i.z.number(),height:i.z.number()}),vt=i.z.object({signedWidth:i.z.number(),signedHeight:i.z.number()}),St=["width","height"];i.z.enum(St);const It=["start","center","end"],Nt=["signedWidth","signedHeight"];i.z.enum(Nt);const ie=i.z.object({x:i.z.number(),y:i.z.number()}),Et=i.z.object({clientX:i.z.number(),clientY:i.z.number()}),At=["x","y"],He=i.z.enum(At),Xe=["top","right","bottom","left"];i.z.enum(Xe);const xt=["left","right"],Ke=i.z.enum(xt),zt=["top","bottom"],Qe=i.z.enum(zt),_e=["center"],xe=i.z.enum(_e),Mt=[...Xe,..._e],et=i.z.enum(Mt);i.z.enum(It);const $t=["first","last"];i.z.enum($t);const Bt=i.z.object({lower:i.z.number(),upper:i.z.number()}),Rt=i.z.object({lower:i.z.bigint(),upper:i.z.bigint()});i.z.union([Bt,oe]);i.z.union([Rt,oe]);i.z.union([He,et]);i.z.union([He,et,i.z.instanceof(String)]);const Ut=r=>typeof r=="bigint"||r instanceof BigInt,j=(r,e)=>Ut(r)?r.valueOf()*BigInt(e.valueOf()):r.valueOf()*Number(e.valueOf()),k=(r,e)=>{const t={};if(typeof r=="number"||typeof r=="bigint")e!=null?(t.lower=r,t.upper=e):(t.lower=typeof r=="bigint"?0n:0,t.upper=r);else if(Array.isArray(r)){if(r.length!==2)throw new Error("bounds: expected array of length 2");[t.lower,t.upper]=r}else return ze(r);return ze(t)},ze=r=>r.lower>r.upper?{lower:r.upper,upper:r.lower}:r,Me=(r,e)=>{const t=k(r);return e<t.lower?t.lower:e>=t.upper?t.upper-(typeof t.upper=="number"?1:1n):e};i.z.object({x:Ke.or(xe),y:Qe.or(xe)});const Ct=i.z.object({x:Ke,y:Qe}),Dt=Object.freeze({x:"left",y:"top"}),Pt=(r,e)=>r.x===e.x&&r.y===e.y,$e=i.z.union([i.z.number(),ie,oe,Je,vt,Et]),Lt=(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}},Be=Object.freeze({x:0,y:0}),ee=i.z.union([i.z.number(),i.z.string()]);i.z.object({top:ee,left:ee,width:ee,height:ee});i.z.object({left:i.z.number(),top:i.z.number(),right:i.z.number(),bottom:i.z.number()});i.z.object({one:ie,two:ie,root:Ct});const Oe=(r,e,t=0,n=0,s)=>{const a={one:{...Be},two:{...Be},root:s??Dt};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:s??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))},he=r=>{const e=Oe(r);return{lower:e.one.x,upper:e.two.x}},de=r=>{const e=Oe(r);return{lower:e.one.y,upper:e.two.y}},Yt=r=>typeof r!="object"||r==null?!1:"one"in r&&"two"in r&&"root"in r;var kt=Object.defineProperty,jt=(r,e,t)=>e in r?kt(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,C=(r,e,t)=>jt(r,typeof e!="symbol"?e+"":e,t);const Ft=(r,e,t)=>e!==void 0&&r<e?e:t!==void 0&&r>t?t:r;i.z.object({offset:$e,scale:$e});i.z.object({offset:i.z.number(),scale:i.z.number()});const qt=r=>(e,t,n,s)=>t==="dimension"?[e,n]:[e,s?n-r:n+r],Gt=r=>(e,t,n,s)=>[e,s?n/r:n*r],Wt=r=>(e,t,n)=>{if(e===null)return[r,n];const{lower:s,upper:a}=e,{lower:c,upper:d}=r,f=a-s,y=d-c;if(t==="dimension")return[r,n*(y/f)];const T=(n-s)*(y/f)+c;return[r,T]},Vt=r=>(e,t,n)=>[r,n],Zt=()=>(r,e,t)=>{if(r===null)throw new Error("cannot invert without bounds");if(e==="dimension")return[r,t];const{lower:n,upper:s}=r;return[r,s-(t-n)]},Jt=r=>(e,t,n)=>{const{lower:s,upper:a}=r;return n=Ft(n,s,a),[e,n]},pe=class V{constructor(){C(this,"ops",[]),C(this,"currBounds",null),C(this,"currType",null),C(this,"reversed",!1),this.ops=[]}static translate(e){return new V().translate(e)}static magnify(e){return new V().magnify(e)}static scale(e,t){return new V().scale(e,t)}translate(e){const t=this.new(),n=qt(e);return n.type="translate",t.ops.push(n),t}magnify(e){const t=this.new(),n=Gt(e);return n.type="magnify",t.ops.push(n),t}scale(e,t){const n=k(e,t),s=this.new(),a=Wt(n);return a.type="scale",s.ops.push(a),s}clamp(e,t){const n=k(e,t),s=this.new(),a=Jt(n);return a.type="clamp",s.ops.push(a),s}reBound(e,t){const n=k(e,t),s=this.new(),a=Vt(n);return a.type="re-bound",s.ops.push(a),s}invert(){const e=Zt();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 V;return e.ops=this.ops.slice(),e.reversed=this.reversed,e}exec(e,t){return this.currBounds=null,this.ops.reduce(([n,s],a)=>a(n,e,s,this.reversed),[null,t])[1]}reverse(){const e=this.new();e.ops.reverse();const t=[];return e.ops.forEach((n,s)=>{if(n.type==="scale"||t.some(([c,d])=>s>=c&&s<=d))return;const a=e.ops.findIndex((c,d)=>c.type==="scale"&&d>s);a!==-1&&t.push([s,a])}),t.forEach(([n,s])=>{const a=e.ops.slice(n,s);a.unshift(e.ops[s]),e.ops.splice(n,s-n+1,...a)}),e.reversed=!e.reversed,e}get transform(){return{scale:this.dim(1),offset:this.pos(0)}}};C(pe,"IDENTITY",new pe);let Re=pe;const Ue=class U{constructor(e=new Re,t=new Re,n=null){C(this,"x"),C(this,"y"),C(this,"currRoot"),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=Lt(e,t),s=this.copy();return s.x=this.x.translate(n.x),s.y=this.y.translate(n.y),s}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(Yt(e)){const n=this.currRoot;return t.currRoot=e.root,n!=null&&!Pt(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(he(e)),t.y=t.y.scale(de(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(he(e)),t.y=this.y.reBound(de(e)),t}clamp(e){const t=this.copy();return t.x=this.x.clamp(he(e)),t.y=this.y.clamp(de(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 Oe(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})}}};C(Ue,"IDENTITY",new Ue);const Ht=r=>r!=null&&typeof r=="object"&&"toString"in r,Xt=(r,e=!1)=>{const t=Ht(r)?"stringer":typeof r;let n;switch(t){case"string":n=(s,a)=>s.localeCompare(a);break;case"stringer":n=(s,a)=>s.toString().localeCompare(a.toString());break;case"number":n=(s,a)=>Number(s)-Number(a);break;case"bigint":n=(s,a)=>BigInt(s)-BigInt(a)>0n?1:-1;break;case"boolean":n=(s,a)=>Number(s)-Number(a);break;case"undefined":n=()=>0;break;default:return console.warn(`sortFunc: unknown type ${t}`),()=>-1}return e?Kt(n):n},Kt=r=>(e,t)=>r(t,e),Qt=i.z.object({signedWidth:i.z.number(),signedHeight:i.z.number()});i.z.union([Je,Qt,ie,oe]);const _t=i.z.bigint().or(i.z.string().transform(BigInt));var er=Object.defineProperty,tr=(r,e,t)=>e in r?er(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,u=(r,e,t)=>tr(r,typeof e!="symbol"?e+"":e,t);let rr=(r,e=21)=>(t=e)=>{let n="",s=t;for(;s--;)n+=r[Math.random()*r.length|0];return n};const nr="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",sr=rr(nr,11),ir=i.z.enum(["static","dynamic"]),tt=(r,e)=>{const t=new O(e);if(![S.DAY,S.HOUR,S.MINUTE,S.SECOND,S.MILLISECOND,S.MICROSECOND,S.NANOSECOND].some(s=>s.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 O?new O(n):new S(n)},m=class h{constructor(e,t="UTC"){if(u(this,"value"),u(this,"encodeValue",!0),e==null)this.value=h.now().valueOf();else if(e instanceof Date)this.value=BigInt(e.getTime())*h.MILLISECOND.valueOf();else if(typeof e=="string")this.value=h.parseDateTimeString(e,t).valueOf();else if(Array.isArray(e))this.value=h.parseDate(e);else{let n=BigInt(0);e instanceof Number&&(e=e.valueOf()),t==="local"&&(n=h.utcOffset.valueOf()),typeof e=="number"&&(isFinite(e)?e=Math.trunc(e):(isNaN(e)&&(e=0),e===1/0?e=h.MAX:e=h.MIN)),this.value=BigInt(e.valueOf())+n}}static parseDate([e=1970,t=1,n=1]){const s=new Date(e,t-1,n,0,0,0,0);return new h(BigInt(s.getTime())*h.MILLISECOND.valueOf()).truncate(h.DAY).valueOf()}encode(){return this.value.toString()}valueOf(){return this.value}static parseTimeString(e,t="UTC"){const[n,s,a]=e.split(":");let c="00",d="00";a!=null&&([c,d]=a.split("."));let f=h.hours(parseInt(n??"00")).add(h.minutes(parseInt(s??"00"))).add(h.seconds(parseInt(c??"00"))).add(h.milliseconds(parseInt(d??"00")));return t==="local"&&(f=f.add(h.utcOffset)),f.valueOf()}static parseDateTimeString(e,t="UTC"){if(!e.includes("/")&&!e.includes("-"))return h.parseTimeString(e,t);const n=new Date(e);return e.includes(":")||n.setUTCHours(0,0,0,0),new h(BigInt(n.getTime())*h.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(h.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 S(BigInt(new Date().getTimezoneOffset())*h.MINUTE.valueOf())}static since(e){return new h().span(e)}date(){return new Date(this.milliseconds())}equals(e){return this.valueOf()===new h(e).valueOf()}span(e){return this.range(e).span}range(e){return new ve(this,e).makeValid()}spanRange(e){return this.range(this.add(e)).makeValid()}get isZero(){return this.valueOf()===BigInt(0)}after(e){return this.valueOf()>new h(e).valueOf()}afterEq(e){return this.valueOf()>=new h(e).valueOf()}before(e){return this.valueOf()<new h(e).valueOf()}beforeEq(e){return this.valueOf()<=new h(e).valueOf()}add(e){return new h(this.valueOf()+BigInt(e.valueOf()))}sub(e){return new h(this.valueOf()-BigInt(e.valueOf()))}milliseconds(){return Number(this.valueOf())/Number(h.MILLISECOND.valueOf())}toString(){return this.date().toISOString()}remainder(e){return tt(this,e)}get isToday(){return this.truncate(S.DAY).equals(h.now().truncate(S.DAY))}truncate(e){return this.sub(this.remainder(e))}static now(){return new h(new Date)}static max(...e){let t=h.MIN;for(const n of e){const s=new h(n);s.after(t)&&(t=s)}return t}static min(...e){let t=h.MAX;for(const n of e){const s=new h(n);s.before(t)&&(t=s)}return t}static nanoseconds(e){return new h(e)}static microseconds(e){return h.nanoseconds(e*1e3)}static milliseconds(e){return h.microseconds(e*1e3)}static seconds(e){return h.milliseconds(e*1e3)}static minutes(e){return h.seconds(e*60)}static hours(e){return h.minutes(e*60)}static days(e){return h.hours(e*24)}};u(m,"NANOSECOND",m.nanoseconds(1)),u(m,"MICROSECOND",m.microseconds(1)),u(m,"MILLISECOND",m.milliseconds(1)),u(m,"SECOND",m.seconds(1)),u(m,"MINUTE",m.minutes(1)),u(m,"HOUR",m.hours(1)),u(m,"DAY",m.days(1)),u(m,"MAX",new m((1n<<63n)-1n)),u(m,"MIN",new m(0)),u(m,"ZERO",new m(0)),u(m,"z",i.z.union([i.z.object({value:i.z.bigint()}).transform(r=>new m(r.value)),i.z.string().transform(r=>new m(BigInt(r))),i.z.instanceof(Number).transform(r=>new m(r)),i.z.number().transform(r=>new m(r)),i.z.instanceof(m)]));let O=m;const w=class g{constructor(e){u(this,"value"),u(this,"encodeValue",!0),typeof e=="number"&&(e=Math.trunc(e.valueOf())),this.value=BigInt(e.valueOf())}static fromSeconds(e){return e instanceof g?e:e instanceof Ce?e.period:e instanceof O?new g(e):["number","bigint"].includes(typeof e)?g.seconds(e):new g(e)}static fromMilliseconds(e){return e instanceof g?e:e instanceof Ce?e.period:e instanceof O?new g(e):["number","bigint"].includes(typeof e)?g.milliseconds(e):new g(e)}encode(){return this.value.toString()}valueOf(){return this.value}lessThan(e){return this.valueOf()<new g(e).valueOf()}greaterThan(e){return this.valueOf()>new g(e).valueOf()}lessThanOrEqual(e){return this.valueOf()<=new g(e).valueOf()}greaterThanOrEqual(e){return this.valueOf()>=new g(e).valueOf()}remainder(e){return tt(this,e)}truncate(e){return new g(BigInt(Math.trunc(Number(this.valueOf()/e.valueOf())))*e.valueOf())}toString(){const e=this.truncate(g.DAY),t=this.truncate(g.HOUR),n=this.truncate(g.MINUTE),s=this.truncate(g.SECOND),a=this.truncate(g.MILLISECOND),c=this.truncate(g.MICROSECOND),d=this.truncate(g.NANOSECOND),f=e,y=t.sub(e),T=n.sub(t),l=s.sub(n),E=a.sub(s),B=c.sub(a),R=d.sub(c);let x="";return f.isZero||(x+=`${f.days}d `),y.isZero||(x+=`${y.hours}h `),T.isZero||(x+=`${T.minutes}m `),l.isZero||(x+=`${l.seconds}s `),E.isZero||(x+=`${E.milliseconds}ms `),B.isZero||(x+=`${B.microseconds}µs `),R.isZero||(x+=`${R.nanoseconds}ns`),x.trim()}get days(){return Number(this.valueOf())/Number(g.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(g.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(g.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(g.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(g.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(g.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get isZero(){return this.valueOf()===BigInt(0)}equals(e){return this.valueOf()===new g(e).valueOf()}add(e){return new g(this.valueOf()+new g(e).valueOf())}sub(e){return new g(this.valueOf()-new g(e).valueOf())}static nanoseconds(e=1){return new g(e)}static microseconds(e=1){return g.nanoseconds(j(e,1e3))}static milliseconds(e=1){return g.microseconds(j(e,1e3))}static seconds(e=1){return g.milliseconds(j(e,1e3))}static minutes(e=1){return g.seconds(j(e,60))}static hours(e){return g.minutes(j(e,60))}static days(e){return g.hours(j(e,24))}};u(w,"NANOSECOND",w.nanoseconds(1)),u(w,"MICROSECOND",w.microseconds(1)),u(w,"MILLISECOND",w.milliseconds(1)),u(w,"SECOND",w.seconds(1)),u(w,"MINUTE",w.minutes(1)),u(w,"HOUR",w.hours(1)),u(w,"DAY",w.days(1)),u(w,"MAX",new w((1n<<63n)-1n)),u(w,"MIN",new w(0)),u(w,"ZERO",new w(0)),u(w,"z",i.z.union([i.z.object({value:i.z.bigint()}).transform(r=>new w(r.value)),i.z.string().transform(r=>new w(BigInt(r))),i.z.instanceof(Number).transform(r=>new w(r)),i.z.number().transform(r=>new w(r)),i.z.instanceof(w)]));let S=w;const Z=class re extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new re(e).valueOf()}get period(){return S.seconds(1/this.valueOf())}sampleCount(e){return new S(e).seconds*this.valueOf()}byteCount(e,t){return this.sampleCount(e)*new A(t).valueOf()}span(e){return S.seconds(e/this.valueOf())}byteSpan(e,t){return this.span(e.valueOf()/t.valueOf())}static hz(e){return new re(e)}static khz(e){return re.hz(e*1e3)}};u(Z,"z",i.z.union([i.z.number().transform(r=>new Z(r)),i.z.instanceof(Number).transform(r=>new Z(r)),i.z.instanceof(Z)]));let Ce=Z;const I=class extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}length(e){return e.valueOf()/this.valueOf()}size(e){return new ye(e*this.valueOf())}};u(I,"UNKNOWN",new I(0)),u(I,"BIT128",new I(16)),u(I,"BIT64",new I(8)),u(I,"BIT32",new I(4)),u(I,"BIT16",new I(2)),u(I,"BIT8",new I(1)),u(I,"z",i.z.union([i.z.number().transform(r=>new I(r)),i.z.instanceof(Number).transform(r=>new I(r)),i.z.instanceof(I)]));let A=I;const z=class ne{constructor(e,t){u(this,"start"),u(this,"end"),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 S(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 ne(this.end,this.start)}equals(e){return this.start.equals(e.start)&&this.end.equals(e.end)}toString(){return`${this.start.toString()} - ${this.end.toString()}`}toPrettyString(){return`${this.start.fString("preciseDate")} - ${this.span.toString()}`}overlapsWith(e,t=S.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 s=O.max(n.start,e.start),a=O.min(n.end,e.end);return a.before(s)?!1:new S(a.sub(s)).greaterThanOrEqual(t)}roughlyEquals(e,t){let n=this.start.sub(e.start).valueOf(),s=this.end.sub(e.end).valueOf();return n<0&&(n=-n),s<0&&(s=-s),n<=t.valueOf()&&s<=t.valueOf()}contains(e){return e instanceof ne?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const t=new ne(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}};u(z,"MAX",new z(O.MIN,O.MAX)),u(z,"MIN",new z(O.MAX,O.MIN)),u(z,"ZERO",new z(O.ZERO,O.ZERO)),u(z,"z",i.z.union([i.z.object({start:O.z,end:O.z}).transform(r=>new z(r.start,r.end)),i.z.instanceof(z)]));let ve=z;const o=class M extends String{constructor(e){if(e instanceof M||typeof e=="string"||typeof e.valueOf()=="string"){super(e.valueOf());return}const t=M.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);if(t!=null){super(t.valueOf());return}throw super(M.UNKNOWN.valueOf()),new Error(`unable to find data type for ${e.toString()}`)}get Array(){const e=M.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(M.JSON)||this.equals(M.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(M.UUID)}get isInteger(){return this.toString().startsWith("int")}get isFloat(){return this.toString().startsWith("float")}get density(){const e=M.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}canSafelyCastTo(e){return this.equals(e)?!0:this.isVariable&&!e.isVariable||!this.isVariable&&e.isVariable?!1:this.isFloat&&e.isInteger||this.isInteger&&e.isFloat?this.density.valueOf()<e.density.valueOf():this.isFloat&&e.isFloat||this.isInteger&&e.isInteger?this.density.valueOf()<=e.density.valueOf():!1}canCastTo(e){return this.isNumeric&&e.isNumeric?!0:this.equals(e)}checkArray(e){return e.constructor===this.Array}toJSON(){return this.toString()}get usesBigInt(){return M.BIG_INT_TYPES.some(e=>e.equals(this))}};u(o,"UNKNOWN",new o("unknown")),u(o,"FLOAT64",new o("float64")),u(o,"FLOAT32",new o("float32")),u(o,"INT64",new o("int64")),u(o,"INT32",new o("int32")),u(o,"INT16",new o("int16")),u(o,"INT8",new o("int8")),u(o,"UINT64",new o("uint64")),u(o,"UINT32",new o("uint32")),u(o,"UINT16",new o("uint16")),u(o,"UINT8",new o("uint8")),u(o,"BOOLEAN",o.UINT8),u(o,"TIMESTAMP",new o("timestamp")),u(o,"UUID",new o("uuid")),u(o,"STRING",new o("string")),u(o,"JSON",new o("json")),u(o,"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]])),u(o,"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]])),u(o,"DENSITIES",new Map([[o.UINT8.toString(),A.BIT8],[o.UINT16.toString(),A.BIT16],[o.UINT32.toString(),A.BIT32],[o.UINT64.toString(),A.BIT64],[o.FLOAT32.toString(),A.BIT32],[o.FLOAT64.toString(),A.BIT64],[o.INT8.toString(),A.BIT8],[o.INT16.toString(),A.BIT16],[o.INT32.toString(),A.BIT32],[o.INT64.toString(),A.BIT64],[o.TIMESTAMP.toString(),A.BIT64],[o.STRING.toString(),A.UNKNOWN],[o.JSON.toString(),A.UNKNOWN],[o.UUID.toString(),A.BIT128]])),u(o,"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]),u(o,"BIG_INT_TYPES",[o.INT64,o.UINT64,o.TIMESTAMP]),u(o,"z",i.z.union([i.z.string().transform(r=>new o(r)),i.z.instanceof(o)]));let b=o;const N=class v extends Number{constructor(e){super(e.valueOf())}largerThan(e){return this.valueOf()>e.valueOf()}smallerThan(e){return this.valueOf()<e.valueOf()}add(e){return v.bytes(this.valueOf()+e.valueOf())}sub(e){return v.bytes(this.valueOf()-e.valueOf())}truncate(e){return new v(Math.trunc(this.valueOf()/e.valueOf())*e.valueOf())}remainder(e){return v.bytes(this.valueOf()%e.valueOf())}get gigabytes(){return this.valueOf()/v.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/v.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/v.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/v.TERABYTE.valueOf()}toString(){const e=this.truncate(v.TERABYTE),t=this.truncate(v.GIGABYTE),n=this.truncate(v.MEGABYTE),s=this.truncate(v.KILOBYTE),a=this.truncate(v.BYTE),c=e,d=t.sub(e),f=n.sub(t),y=s.sub(n),T=a.sub(s);let l="";return c.isZero||(l+=`${c.terabytes}TB `),d.isZero||(l+=`${d.gigabytes}GB `),f.isZero||(l+=`${f.megabytes}MB `),y.isZero||(l+=`${y.kilobytes}KB `),(!T.isZero||l==="")&&(l+=`${T.valueOf()}B`),l.trim()}static bytes(e=1){return new v(e)}static kilobytes(e=1){return v.bytes(e.valueOf()*1e3)}static megabytes(e=1){return v.kilobytes(e.valueOf()*1e3)}static gigabytes(e=1){return v.megabytes(e.valueOf()*1e3)}static terabytes(e){return v.gigabytes(e.valueOf()*1e3)}get isZero(){return this.valueOf()===0}};u(N,"BYTE",new N(1)),u(N,"KILOBYTE",N.kilobytes(1)),u(N,"MEGABYTE",N.megabytes(1)),u(N,"GIGABYTE",N.gigabytes(1)),u(N,"TERABYTE",N.terabytes(1)),u(N,"ZERO",new N(0)),u(N,"z",i.z.union([i.z.number().transform(r=>new N(r)),i.z.instanceof(N)]));let ye=N;i.z.union([i.z.instanceof(Uint8Array),i.z.instanceof(Uint16Array),i.z.instanceof(Uint32Array),i.z.instanceof(BigUint64Array),i.z.instanceof(Float32Array),i.z.instanceof(Float64Array),i.z.instanceof(Int8Array),i.z.instanceof(Int16Array),i.z.instanceof(Int32Array),i.z.instanceof(BigInt64Array)]);const rt=r=>{const e=typeof r;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||r instanceof O||r instanceof S||r instanceof Date},ar=(r,e,t,n=0)=>r.usesBigInt&&!e.usesBigInt?Number(t)-Number(n):!r.usesBigInt&&e.usesBigInt?BigInt(t.valueOf())-BigInt(n.valueOf()):H(t,-n).valueOf(),or=r=>r==null?!1:Array.isArray(r)||r instanceof ArrayBuffer||ArrayBuffer.isView(r)&&!(r instanceof DataView)||r instanceof lr?!0:rt(r),L=-1,ur=i.z.string().transform(r=>new Uint8Array(atob(r).split("").map(e=>e.charCodeAt(0))).buffer),cr=i.z.union([i.z.null(),i.z.undefined()]).transform(()=>new Uint8Array().buffer),me=10,J=class ${constructor(e){u(this,"key",""),u(this,"isSynnaxSeries",!0),u(this,"dataType"),u(this,"sampleOffset"),u(this,"gl"),u(this,"_data"),u(this,"_timeRange"),u(this,"alignment",0n),u(this,"_cachedMin"),u(this,"_cachedMax"),u(this,"writePos",L),u(this,"_refCount",0),u(this,"_cachedLength"),u(this,"_cachedIndexes"),or(e)&&(e={data:e});const{dataType:t,timeRange:n,sampleOffset:s=0,glBufferUsage:a="static",alignment:c=0n,key:d=sr()}=e,f=e.data??[];if(f instanceof $||typeof f=="object"&&"isSynnaxSeries"in f&&f.isSynnaxSeries===!0){const l=f;this.key=l.key,this.dataType=l.dataType,this.sampleOffset=l.sampleOffset,this.gl=l.gl,this._data=l._data,this._timeRange=l._timeRange,this.alignment=l.alignment,this._cachedMin=l._cachedMin,this._cachedMax=l._cachedMax,this.writePos=l.writePos,this._refCount=l._refCount,this._cachedLength=l._cachedLength;return}const y=rt(f),T=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(T||y){let l=f;if(!y){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.");l=f[0]}if(typeof l=="string")this.dataType=b.STRING;else if(typeof l=="number")this.dataType=b.FLOAT64;else if(typeof l=="bigint")this.dataType=b.INT64;else if(typeof l=="boolean")this.dataType=b.BOOLEAN;else if(l instanceof O||l instanceof Date||l instanceof O)this.dataType=b.TIMESTAMP;else if(typeof l=="object")this.dataType=b.JSON;else throw new Error(`cannot infer data type of ${typeof l} when constructing a Series from a JS array`)}else this.dataType=new b(f)}if(!T&&!y)this._data=f;else{let l=y?[f]:f;const E=l[0];(E instanceof O||E instanceof Date||E instanceof S)&&(l=l.map(B=>new O(B).valueOf())),this.dataType.equals(b.STRING)?(this._cachedLength=l.length,this._data=new TextEncoder().encode(`${l.join(`
4
+ `)}
5
+ `)):this.dataType.equals(b.JSON)?(this._cachedLength=l.length,this._data=new TextEncoder().encode(`${l.map(B=>te.encodeString(B)).join(`
6
+ `)}
7
+ `)):this._data=new this.dataType.Array(l).buffer}this.key=d,this.alignment=c,this.sampleOffset=s??0,this._timeRange=n,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 s=new new b(t).Array(e),a=new $({data:s.buffer,dataType:t,...n});return a.writePos=0,a}static generateTimestamps(e,t,n){const s=n.spanRange(t.span(e)),a=new BigInt64Array(e);for(let c=0;c<e;c++)a[c]=BigInt(n.add(t.span(c)).valueOf());return new $({data:a,dataType:b.TIMESTAMP,timeRange:s})}get refCount(){return this._refCount}static fromStrings(e,t){const n=new TextEncoder().encode(`${e.join(`
8
+ `)}
9
+ `);return new $({data:n,dataType:b.STRING,timeRange:t})}static fromJSON(e,t){const n=new TextEncoder().encode(`${e.map(s=>te.encodeString(s)).join(`
10
+ `)}
11
+ `);return new $({data:n,dataType:b.JSON,timeRange:t})}acquire(e){this._refCount++,e!=null&&this.updateGLBuffer(e)}release(){if(this._refCount--,this._refCount===0&&this.gl.control!=null)this.maybeGarbageCollectGLBuffer(this.gl.control);else if(this._refCount<0)throw new Error("cannot release an array 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===L)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===L)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 this._data instanceof ArrayBuffer||this._data instanceof SharedArrayBuffer?this._data:this._data.buffer}get underlyingData(){return new this.dataType.Array(this._data)}get data(){return this.writePos===L?this.underlyingData:new this.dataType.Array(this._data,0,this.writePos)}toStrings(){if(!this.dataType.matches(b.STRING,b.UUID))throw new Error("cannot convert non-string series to strings");return new TextDecoder().decode(this.underlyingData).split(`
12
12
  `).slice(0,-1)}toUUIDs(){if(!this.dataType.equals(b.UUID))throw new Error("cannot convert non-uuid series to uuids");const e=b.UUID.density.valueOf(),t=Array(this.length);for(let n=0;n<this.length;n++){const s=this.underlyingData.slice(n*e,(n+1)*e),a=Array.from(new Uint8Array(s),c=>c.toString(16).padStart(2,"0")).join("").replace(/(.{8})(.{4})(.{4})(.{4})(.{12})/,"$1-$2-$3-$4-$5");t[n]=a}return t}parseJSON(e){if(!this.dataType.equals(b.JSON))throw new Error("cannot convert non-string series to strings");return new TextDecoder().decode(this.underlyingData).split(`
13
- `).slice(0,-1).map(t=>e.parse(te.decodeString(t)))}get timeRange(){if(this._timeRange==null)throw new Error("time range not set on series");return this._timeRange}get byteCapacity(){return new ye(this.underlyingData.byteLength)}get capacity(){return this.dataType.isVariable?this.byteCapacity.valueOf():this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===L?this.byteCapacity:this.dataType.isVariable?new ye(this.writePos):this.dataType.density.size(this.writePos)}get length(){return this._cachedLength!=null?this._cachedLength:this.dataType.isVariable?this.calculateCachedLength():this.writePos===L?this.data.length: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,s)=>{n===me&&(e++,t.push(s+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 s=0;s<this.length;s++)n[s]=ar(this.dataType,e,this.data[s],t);return new B({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(){if(this.dataType.isVariable)throw new Error("cannot calculate maximum on a variable length data type");return this.writePos===0?-1/0:(this._cachedMax==null&&(this._cachedMax=this.calcRawMax()),H(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(){if(this.dataType.isVariable)throw new Error("cannot calculate minimum on a variable length data type");return this.writePos===0?1/0:(this._cachedMin==null&&(this._cachedMin=this.calcRawMin()),H(this._cachedMin,this.sampleOffset))}get bounds(){return k(Number(this.min),Number(this.max))}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)}}enrich(){this.max,this.min}get range(){return H(this.max,-this.min)}atAlignment(e,t){const n=Number(e-this.alignment);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){if(this.dataType.isVariable)return this.atVariable(e,t??!1);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 H(n,this.sampleOffset)}atVariable(e,t){let n=0,s=0;if(this._cachedIndexes!=null)n=this._cachedIndexes[e],s=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]===me){if(e===0){s=c;break}n=c+1,e--}if(s===0&&(s=this.data.length),n>=s||e>0){if(t)throw new Error(`[series] - no value at index ${e}`);return}}const a=this.data.slice(n,s);return this.dataType.equals(b.STRING)?new TextDecoder().decode(a):Ve(JSON.parse(new TextDecoder().decode(a)))}binarySearch(e){let t=0,n=this.length-1;const s=Kt(e);for(;t<=n;){const a=Math.floor((t+n)/2),c=s(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))throw new Error("Only FLOAT32 arrays can be used in WebGL");const{buffer:t,bufferUsage:n,prevBuffer:s}=this.gl;if(t==null&&(this.gl.buffer=e.createBuffer()),this.writePos!==s)if(e.bindBuffer(e.ARRAY_BUFFER,this.gl.buffer),this.writePos!==L){s===0&&e.bufferData(e.ARRAY_BUFFER,this.byteCapacity.valueOf(),e.STATIC_DRAW);const a=this.dataType.density.size(s).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.underlyingData,n==="static"?e.STATIC_DRAW:e.DYNAMIC_DRAW),this.gl.prevBuffer=L}as(e){if(e==="string"){if(!this.dataType.equals(b.STRING))throw new Error(`cannot convert series of type ${this.dataType.toString()} to string`);return this}if(e==="number"){if(!this.dataType.isNumeric)throw new Error(`cannot convert series of type ${this.dataType.toString()} to number`);return this}if(e==="bigint"){if(!this.dataType.equals(b.INT64))throw new Error(`cannot convert series of type ${this.dataType.toString()} to bigint`);return this}throw new Error(`cannot convert series to ${e}`)}get digest(){var e;return{key:this.key,dataType:this.dataType.toString(),sampleOffset:this.sampleOffset,alignment:this.alignmentBounds,timeRange:(e=this._timeRange)==null?void 0:e.toString(),length:this.length,capacity:this.capacity}}get memInfo(){return{key:this.key,length:this.length,byteLength:this.byteLength,glBuffer:this.gl.buffer!=null}}get alignmentBounds(){return k(this.alignment,this.alignment+BigInt(this.length))}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 hr(this);return this.dataType.equals(b.JSON)?new dr(e):e}return new fr(this)}slice(e,t){return this.sliceSub(!1,e,t)}sub(e,t){return this.sliceSub(!0,e,t)}subIterator(e,t){return new De(this,e,t??this.length)}subAlignmentIterator(e,t){return new De(this,Number(e-this.alignment),Number(t-this.alignment))}subBytes(e,t){if(e>=0&&(t==null||t>=this.byteLength.valueOf()))return this;const n=this.data.subarray(e,t);return new B({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 s;return e?s=this.data.subarray(t,n):s=this.data.slice(t,n),new B({data:s,dataType:this.dataType,timeRange:this._timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(t)})}reAlign(e){return new B({data:this.buffer,dataType:this.dataType,timeRange:ve.ZERO,sampleOffset:this.sampleOffset,glBufferUsage:"static",alignment:e})}};u(J,"crudeZ",i.z.object({timeRange:ve.z.optional(),dataType:b.z,alignment:_t.optional(),data:i.z.union([ur,cr,i.z.instanceof(ArrayBuffer)]),glBufferUsage:ir.optional().default("static").optional()})),u(J,"z",J.crudeZ.transform(r=>new J(r)));let lr=J;class De{constructor(e,t,n){u(this,"series"),u(this,"end"),u(this,"index"),this.series=e;const s=k(0,e.length);this.end=Me(s,n),this.index=Me(s,t)}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}[Symbol.iterator](){return this}}class hr{constructor(e){if(u(this,"series"),u(this,"index"),u(this,"decoder"),!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]!==me;)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))})}[Symbol.iterator](){return this}}var Pe,Le;class dr{constructor(e){u(this,"wrapped"),u(this,Pe,"JSONSeriesIterator"),this.wrapped=e}next(){const e=this.wrapped.next();return e.done===!0?{done:!0,value:void 0}:{done:!1,value:te.decodeString(e.value)}}[(Le=Symbol.iterator,Pe=Symbol.toStringTag,Le)](){return this}}var Ye,ke;class fr{constructor(e){u(this,"series"),u(this,"index"),u(this,Ye,"SeriesIterator"),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)}}[(ke=Symbol.iterator,Ye=Symbol.toStringTag,ke)](){return this}}const H=(r,e)=>typeof r=="bigint"&&typeof e=="bigint"||typeof r=="number"&&typeof e=="number"?r+e:e===0?r:r===0?e:Number(r)+Number(e);i.z.object({key:i.z.string(),value:i.z.string()});i.z.record(i.z.union([i.z.number(),i.z.string(),i.z.symbol()]),i.z.unknown());const nt=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser",gr=nt(),st=["MacOS","Windows","Linux","Docker"],pr=i.z.enum(st);let fe;const yr=()=>{if(typeof window>"u")return;const r=window.navigator.userAgent.toLowerCase();if(r.includes("mac"))return"MacOS";if(r.includes("win"))return"Windows";if(r.includes("linux"))return"Linux"},mr=(r={})=>{const{force:e,default:t}=r;return e??fe??(fe=yr(),fe??t)},it=Object.freeze(Object.defineProperty({__proto__:null,OPERATING_SYSTEMS:st,RUNTIME:gr,detect:nt,getOS:mr,osZ:pr},Symbol.toStringTag,{value:"Module"}));var wr=Object.defineProperty,br=(r,e,t)=>e in r?wr(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,K=(r,e,t)=>br(r,typeof e!="symbol"?e+"":e,t);const Tr=(...r)=>r.map(at).join(""),at=r=>(r.endsWith("/")||(r+="/"),r.startsWith("/")&&(r=r.slice(1)),r),Or=r=>r.endsWith("/")?r.slice(0,-1):r,vr=(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("&"),we=class be{constructor({host:e,port:t,protocol:n="",pathPrefix:s=""}){K(this,"protocol"),K(this,"host"),K(this,"port"),K(this,"path"),this.protocol=n,this.host=e,this.port=t,this.path=at(s)}replace(e){return new be({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new be({...this,pathPrefix:Tr(this.path,e)})}toString(){return Or(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}};K(we,"UNKNOWN",new we({host:"unknown",port:0}));let Sr=we;var Ir=Object.defineProperty,Nr=(r,e,t)=>e in r?Ir(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,se=(r,e,t)=>Nr(r,typeof e!="symbol"?e+"":e,t);const F=class extends Number{};se(F,"Absolute",255),se(F,"Default",1),se(F,"z",i.z.union([i.z.instanceof(F),i.z.number().int().min(0).max(255).transform(r=>new F(r)),i.z.instanceof(Number).transform(r=>new F(r))]));i.z.object({name:i.z.string(),key:i.z.string()});const ot=class X extends Error{constructor(){super(X.MESSAGE)}matches(e){return typeof e=="string"?e.includes(X.MESSAGE):e instanceof X||e.message.includes(X.MESSAGE)}};se(ot,"MESSAGE","canceled");let Er=ot;new Er;i.z.string().regex(/^\d+\.\d+\.\d+$/);const ue=r=>e=>e!=null&&typeof e=="object"&&"type"in e&&typeof e.type=="string"?e.type.includes(r):e instanceof Error?e.message.includes(r):typeof e!="string"?!1:e.includes(r);class _ extends Error{constructor(t){super(t);p(this,"discriminator","FreighterError");p(this,"type","")}}const Ar=r=>{if(r==null||typeof r!="object")return!1;const e=r;if(e.discriminator!=="FreighterError")return!1;if(!("type"in e))throw new Error(`Freighter error is missing its type property: ${JSON.stringify(e)}`);return!0},je="unknown",Fe="nil",xr="freighter",Se=i.z.object({type:i.z.string(),data:i.z.string()});class zr{constructor(){p(this,"providers",[])}register(e){this.providers.push(e)}encode(e){if(e==null)return{type:Fe,data:""};if(Ar(e))for(const t of this.providers){const n=t.encode(e);if(n!=null)return n}return{type:je,data:JSON.stringify(e)}}decode(e){if(e==null||e.type===Fe)return null;if(e.type===je)return new qe(e.data);for(const t of this.providers){const n=t.decode(e);if(n!=null)return n}return new qe(e.data)}}const Ie=new zr,ut=({encode:r,decode:e})=>Ie.register({encode:r,decode:e}),Mr=r=>Ie.encode(r),Ne=r=>Ie.decode(r);class qe extends _{constructor(t){super(t);p(this,"type","unknown")}}const ce="freighter.",q=class q extends _{constructor(){super("EOF");p(this,"type",q.TYPE)}};p(q,"TYPE",ce+"eof"),p(q,"matches",ue(q.TYPE));let D=q;const G=class G extends _{constructor(){super("StreamClosed");p(this,"type",G.TYPE)}};p(G,"TYPE",ce+"stream_closed"),p(G,"matches",ue(G.TYPE));let P=G;const W=class W extends _{constructor(t={}){const{message:n="Unreachable",url:s=Sr.UNKNOWN}=t;super(n);p(this,"type",W.TYPE);p(this,"url");this.url=s}};p(W,"TYPE",ce+"unreachable"),p(W,"matches",ue(W.TYPE));let Y=W;const Br=r=>{if(!r.type.startsWith(xr))return null;if(D.matches(r))return{type:D.TYPE,data:"EOF"};if(P.matches(r))return{type:P.TYPE,data:"StreamClosed"};if(Y.matches(r))return{type:Y.TYPE,data:"Unreachable"};throw new Error(`Unknown error type: ${r.type}: ${r.message}`)},Rr=r=>{if(!r.type.startsWith(ce))return null;switch(r.type){case D.TYPE:return new D;case P.TYPE:return new P;case Y.TYPE:return new Y;default:throw new Error(`Unknown error type: ${r.data}`)}};ut({encode:Br,decode:Rr});class ct{constructor(){p(this,"middleware",[])}use(...e){this.middleware.push(...e)}async executeMiddleware(e,t){let n=0;const s=async a=>{if(n===this.middleware.length)return await t(a);const c=this.middleware[n];return n++,await c(a,s)};return await s(e)}}const lt="Content-Type",Ge=r=>{if(it.RUNTIME!=="node")return fetch;const e=require("node-fetch");if(r==="http")return e;const t=require("https"),n=new t.Agent({rejectUnauthorized:!1});return async(s,a)=>await e(s,{...a,agent:n})};class $r extends ct{constructor(t,n,s=!1){super();p(this,"endpoint");p(this,"encoder");p(this,"fetch");return this.endpoint=t.replace({protocol:s?"https":"http"}),this.encoder=n,this.fetch=Ge(this.endpoint.protocol),new Proxy(this,{get:(a,c,d)=>c==="endpoint"?this.endpoint:Reflect.get(a,c,d)})}get headers(){return{[lt]:this.encoder.contentType}}async send(t,n,s,a){n=s==null?void 0:s.parse(n);let c=null;const d=this.endpoint.child(t),f={};f.method="POST",f.body=this.encoder.encode(n??{});const[,y]=await this.executeMiddleware({target:d.toString(),protocol:this.endpoint.protocol,params:{},role:"client"},async T=>{const l={...T,params:{}};f.headers={...this.headers,...T.params};let E;try{E=await Ge(T.protocol)(T.target,f)}catch($){let x=$;return x.message==="Load failed"&&(x=new Y({url:d})),[l,x]}const R=await E.arrayBuffer();if(E!=null&&E.ok)return a!=null&&(c=this.encoder.decode(R,a)),[l,null];try{if(E.status!==400)return[l,new Error(E.statusText)];const $=this.encoder.decode(R,Se),x=Ne($);return[l,x]}catch($){return[l,new Error(`[freighter] - failed to decode error: ${E.statusText}: ${$.message}`)]}});return[c,y]}}const Ur=async(r,e,t,n,s)=>{const[a,c]=await r.send(e,t,n,s);if(c!=null)throw c;return a},Cr=()=>it.RUNTIME!=="node"?r=>new WebSocket(r):r=>new(require("ws")).WebSocket(r,{rejectUnauthorized:!1}),Dr=i.z.object({type:i.z.union([i.z.literal("data"),i.z.literal("close")]),payload:i.z.unknown().optional(),error:i.z.optional(Se)});class Pr{constructor(e,t,n,s){p(this,"encoder");p(this,"reqSchema");p(this,"resSchema");p(this,"ws");p(this,"serverClosed");p(this,"sendClosed");p(this,"receiveDataQueue",[]);p(this,"receiveCallbacksQueue",[]);this.encoder=t,this.reqSchema=n,this.resSchema=s,this.ws=e,this.sendClosed=!1,this.serverClosed=null,this.listenForMessages()}send(e){if(this.serverClosed!=null)return new D;if(this.sendClosed)throw new P;return this.ws.send(this.encoder.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");return this.serverClosed=Ne(e.error),[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.encoder.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=e=>this.addMessage(this.encoder.decode(e.data,Dr)),this.ws.onclose=e=>this.addMessage({type:"close",error:{type:Fr(e)?D.TYPE:P.TYPE,data:""}})}}const Lr="freighterctx",Yr=1e3,kr=1001,jr=[Yr,kr],Fr=r=>jr.includes(r.code),ae=class ae extends ct{constructor(t,n,s=!1){super();p(this,"baseUrl");p(this,"encoder");this.baseUrl=t.replace({protocol:s?"wss":"ws"}),this.encoder=n}async stream(t,n,s){const a=Cr();let c;const[,d]=await this.executeMiddleware({target:t,protocol:"websocket",params:{},role:"client"},async f=>{const y=a(this.buildURL(t,f)),T={...f,params:{}};y.binaryType=ae.MESSAGE_TYPE;const l=await this.wrapSocket(y,n,s);return l instanceof Error?[T,l]:(c=l,[T,null])});if(d!=null)throw d;return c}buildURL(t,n){const s=vr({[lt]:this.encoder.contentType,...n.params},Lr);return this.baseUrl.child(t).toString()+s}async wrapSocket(t,n,s){return await new Promise(a=>{t.onopen=()=>{a(new Pr(t,this.encoder,n,s))},t.onerror=c=>{const d=c;a(new Error(d.message))}})}};p(ae,"MESSAGE_TYPE","arraybuffer");let Te=ae;exports.BaseTypedError=_;exports.EOF=D;exports.HTTPClient=$r;exports.StreamClosed=P;exports.Unreachable=Y;exports.WebSocketClient=Te;exports.decodeError=Ne;exports.encodeError=Mr;exports.errorMatcher=ue;exports.errorZ=Se;exports.registerError=ut;exports.sendRequired=Ur;
13
+ `).slice(0,-1).map(t=>e.parse(te.decodeString(t)))}get timeRange(){if(this._timeRange==null)throw new Error("time range not set on series");return this._timeRange}get byteCapacity(){return new ye(this.underlyingData.byteLength)}get capacity(){return this.dataType.isVariable?this.byteCapacity.valueOf():this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===L?this.byteCapacity:this.dataType.isVariable?new ye(this.writePos):this.dataType.density.size(this.writePos)}get length(){return this._cachedLength!=null?this._cachedLength:this.dataType.isVariable?this.calculateCachedLength():this.writePos===L?this.data.length: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,s)=>{n===me&&(e++,t.push(s+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 s=0;s<this.length;s++)n[s]=ar(this.dataType,e,this.data[s],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(){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._cachedMax=this.calcRawMax()),H(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(){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._cachedMin=this.calcRawMin()),H(this._cachedMin,this.sampleOffset))}get bounds(){return k(Number(this.min),Number(this.max))}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)}}enrich(){this.max,this.min}get range(){return H(this.max,-this.min)}atAlignment(e,t){const n=Number(e-this.alignment);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){if(this.dataType.isVariable)return this.atVariable(e,t??!1);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 H(n,this.sampleOffset)}atVariable(e,t){let n=0,s=0;if(this._cachedIndexes!=null)n=this._cachedIndexes[e],s=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]===me){if(e===0){s=c;break}n=c+1,e--}if(s===0&&(s=this.data.length),n>=s||e>0){if(t)throw new Error(`[series] - no value at index ${e}`);return}}const a=this.data.slice(n,s);return this.dataType.equals(b.STRING)?new TextDecoder().decode(a):Ve(JSON.parse(new TextDecoder().decode(a)))}binarySearch(e){let t=0,n=this.length-1;const s=Xt(e);for(;t<=n;){const a=Math.floor((t+n)/2),c=s(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))throw new Error("Only FLOAT32 arrays can be used in WebGL");const{buffer:t,bufferUsage:n,prevBuffer:s}=this.gl;if(t==null&&(this.gl.buffer=e.createBuffer()),this.writePos!==s)if(e.bindBuffer(e.ARRAY_BUFFER,this.gl.buffer),this.writePos!==L){s===0&&e.bufferData(e.ARRAY_BUFFER,this.byteCapacity.valueOf(),e.STATIC_DRAW);const a=this.dataType.density.size(s).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.underlyingData,n==="static"?e.STATIC_DRAW:e.DYNAMIC_DRAW),this.gl.prevBuffer=L}as(e){if(e==="string"){if(!this.dataType.equals(b.STRING))throw new Error(`cannot convert series of type ${this.dataType.toString()} to string`);return this}if(e==="number"){if(!this.dataType.isNumeric)throw new Error(`cannot convert series of type ${this.dataType.toString()} to number`);return this}if(e==="bigint"){if(!this.dataType.equals(b.INT64))throw new Error(`cannot convert series of type ${this.dataType.toString()} to bigint`);return this}throw new Error(`cannot convert series to ${e}`)}get digest(){var e;return{key:this.key,dataType:this.dataType.toString(),sampleOffset:this.sampleOffset,alignment:this.alignmentBounds,timeRange:(e=this._timeRange)==null?void 0:e.toString(),length:this.length,capacity:this.capacity}}get memInfo(){return{key:this.key,length:this.length,byteLength:this.byteLength,glBuffer:this.gl.buffer!=null}}get alignmentBounds(){return k(this.alignment,this.alignment+BigInt(this.length))}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 hr(this);return this.dataType.equals(b.JSON)?new dr(e):e}return new fr(this)}slice(e,t){return this.sliceSub(!1,e,t)}sub(e,t){return this.sliceSub(!0,e,t)}subIterator(e,t){return new De(this,e,t??this.length)}subAlignmentIterator(e,t){return new De(this,Number(e-this.alignment),Number(t-this.alignment))}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 s;return e?s=this.data.subarray(t,n):s=this.data.slice(t,n),new $({data:s,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:ve.ZERO,sampleOffset:this.sampleOffset,glBufferUsage:"static",alignment:e})}};u(J,"crudeZ",i.z.object({timeRange:ve.z.optional(),dataType:b.z,alignment:_t.optional(),data:i.z.union([ur,cr,i.z.instanceof(ArrayBuffer)]),glBufferUsage:ir.optional().default("static").optional()})),u(J,"z",J.crudeZ.transform(r=>new J(r)));let lr=J;class De{constructor(e,t,n){u(this,"series"),u(this,"end"),u(this,"index"),this.series=e;const s=k(0,e.length);this.end=Me(s,n),this.index=Me(s,t)}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}[Symbol.iterator](){return this}}class hr{constructor(e){if(u(this,"series"),u(this,"index"),u(this,"decoder"),!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]!==me;)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))})}[Symbol.iterator](){return this}}var Pe,Le;class dr{constructor(e){u(this,"wrapped"),u(this,Pe,"JSONSeriesIterator"),this.wrapped=e}next(){const e=this.wrapped.next();return e.done===!0?{done:!0,value:void 0}:{done:!1,value:te.decodeString(e.value)}}[(Le=Symbol.iterator,Pe=Symbol.toStringTag,Le)](){return this}}var Ye,ke;class fr{constructor(e){u(this,"series"),u(this,"index"),u(this,Ye,"SeriesIterator"),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)}}[(ke=Symbol.iterator,Ye=Symbol.toStringTag,ke)](){return this}}const H=(r,e)=>typeof r=="bigint"&&typeof e=="bigint"||typeof r=="number"&&typeof e=="number"?r+e:e===0?r:r===0?e:Number(r)+Number(e);i.z.object({key:i.z.string(),value:i.z.string()});i.z.record(i.z.union([i.z.number(),i.z.string(),i.z.symbol()]),i.z.unknown());const nt=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser",gr=nt(),st=["MacOS","Windows","Linux","Docker"],pr=i.z.enum(st);let fe;const yr=()=>{if(typeof window>"u")return;const r=window.navigator.userAgent.toLowerCase();if(r.includes("mac"))return"MacOS";if(r.includes("win"))return"Windows";if(r.includes("linux"))return"Linux"},mr=(r={})=>{const{force:e,default:t}=r;return e??fe??(fe=yr(),fe??t)},it=Object.freeze(Object.defineProperty({__proto__:null,OPERATING_SYSTEMS:st,RUNTIME:gr,detect:nt,getOS:mr,osZ:pr},Symbol.toStringTag,{value:"Module"}));var wr=Object.defineProperty,br=(r,e,t)=>e in r?wr(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,X=(r,e,t)=>br(r,typeof e!="symbol"?e+"":e,t);const Tr=(...r)=>r.map(at).join(""),at=r=>(r.endsWith("/")||(r+="/"),r.startsWith("/")&&(r=r.slice(1)),r),Or=r=>r.endsWith("/")?r.slice(0,-1):r,vr=(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("&")}`,we=class be{constructor({host:e,port:t,protocol:n="",pathPrefix:s=""}){X(this,"protocol"),X(this,"host"),X(this,"port"),X(this,"path"),this.protocol=n,this.host=e,this.port=t,this.path=at(s)}replace(e){return new be({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new be({...this,pathPrefix:Tr(this.path,e)})}toString(){return Or(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}};X(we,"UNKNOWN",new we({host:"unknown",port:0}));let Sr=we;var Ir=Object.defineProperty,Nr=(r,e,t)=>e in r?Ir(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,se=(r,e,t)=>Nr(r,typeof e!="symbol"?e+"":e,t);const F=class extends Number{};se(F,"Absolute",255),se(F,"Default",1),se(F,"z",i.z.union([i.z.instanceof(F),i.z.number().int().min(0).max(255).transform(r=>new F(r)),i.z.instanceof(Number).transform(r=>new F(r))]));i.z.object({name:i.z.string(),key:i.z.string()});const ot=class K extends Error{constructor(){super(K.MESSAGE)}matches(e){return typeof e=="string"?e.includes(K.MESSAGE):e instanceof K||e.message.includes(K.MESSAGE)}};se(ot,"MESSAGE","canceled");let Er=ot;new Er;i.z.string().regex(/^\d+\.\d+\.\d+$/);const ue=r=>e=>e!=null&&typeof e=="object"&&"type"in e&&typeof e.type=="string"?e.type.includes(r):e instanceof Error?e.message.includes(r):typeof e!="string"?!1:e.includes(r);class _ extends Error{constructor(){super(...arguments);p(this,"discriminator","FreighterError");p(this,"type","")}}const Ar=r=>{if(r==null||typeof r!="object")return!1;const e=r;if(e.discriminator!=="FreighterError")return!1;if(!("type"in e))throw new Error(`Freighter error is missing its type property: ${JSON.stringify(e)}`);return!0},je="unknown",Fe="nil",xr="freighter",Se=i.z.object({type:i.z.string(),data:i.z.string()});class zr{constructor(){p(this,"providers",[])}register(e){this.providers.push(e)}encode(e){if(e==null)return{type:Fe,data:""};if(Ar(e))for(const t of this.providers){const n=t.encode(e);if(n!=null)return n}return{type:je,data:JSON.stringify(e)}}decode(e){if(e==null||e.type===Fe)return null;if(e.type===je)return new qe(e.data);for(const t of this.providers){const n=t.decode(e);if(n!=null)return n}return new qe(e.data)}}const Ie=new zr,ut=({encode:r,decode:e})=>Ie.register({encode:r,decode:e}),Mr=r=>Ie.encode(r),Ne=r=>Ie.decode(r);class qe extends _{constructor(){super(...arguments);p(this,"type","unknown")}}const ce="freighter.",q=class q extends _{constructor(){super("EOF");p(this,"type",q.TYPE)}};p(q,"TYPE",`${ce}eof`),p(q,"matches",ue(q.TYPE));let D=q;const G=class G extends _{constructor(){super("StreamClosed");p(this,"type",G.TYPE)}};p(G,"TYPE",`${ce}stream_closed`),p(G,"matches",ue(G.TYPE));let P=G;const W=class W extends _{constructor(t={}){const{message:n="Unreachable",url:s=Sr.UNKNOWN}=t;super(n);p(this,"type",W.TYPE);p(this,"url");this.url=s}};p(W,"TYPE",`${ce}unreachable`),p(W,"matches",ue(W.TYPE));let Y=W;const $r=r=>{if(!r.type.startsWith(xr))return null;if(D.matches(r))return{type:D.TYPE,data:"EOF"};if(P.matches(r))return{type:P.TYPE,data:"StreamClosed"};if(Y.matches(r))return{type:Y.TYPE,data:"Unreachable"};throw new Error(`Unknown error type: ${r.type}: ${r.message}`)},Br=r=>{if(!r.type.startsWith(ce))return null;switch(r.type){case D.TYPE:return new D;case P.TYPE:return new P;case Y.TYPE:return new Y;default:throw new Error(`Unknown error type: ${r.data}`)}};ut({encode:$r,decode:Br});class ct{constructor(){p(this,"middleware",[])}use(...e){this.middleware.push(...e)}async executeMiddleware(e,t){let n=0;const s=async a=>{if(n===this.middleware.length)return await t(a);const c=this.middleware[n];return n++,await c(a,s)};return await s(e)}}const lt="Content-Type",Ge=r=>{if(it.RUNTIME!=="node")return fetch;const e=require("node-fetch");if(r==="http")return e;const t=require("https"),n=new t.Agent({rejectUnauthorized:!1});return async(s,a)=>await e(s,{...a,agent:n})};class Rr extends ct{constructor(t,n,s=!1){super();p(this,"endpoint");p(this,"encoder");p(this,"fetch");return this.endpoint=t.replace({protocol:s?"https":"http"}),this.encoder=n,this.fetch=Ge(this.endpoint.protocol),new Proxy(this,{get:(a,c,d)=>c==="endpoint"?this.endpoint:Reflect.get(a,c,d)})}get headers(){return{[lt]:this.encoder.contentType}}async send(t,n,s,a){n=s==null?void 0:s.parse(n);let c=null;const d=this.endpoint.child(t),f={};f.method="POST",f.body=this.encoder.encode(n??{});const[,y]=await this.executeMiddleware({target:d.toString(),protocol:this.endpoint.protocol,params:{},role:"client"},async T=>{const l={...T,params:{}};f.headers={...this.headers,...T.params};let E;try{E=await Ge(T.protocol)(T.target,f)}catch(R){let x=R;return x.message==="Load failed"&&(x=new Y({url:d})),[l,x]}const B=await E.arrayBuffer();if(E!=null&&E.ok)return a!=null&&(c=this.encoder.decode(B,a)),[l,null];try{if(E.status!==400)return[l,new Error(E.statusText)];const R=this.encoder.decode(B,Se),x=Ne(R);return[l,x]}catch(R){return[l,new Error(`[freighter] - failed to decode error: ${E.statusText}: ${R.message}`)]}});return[c,y]}}const Ur=async(r,e,t,n,s)=>{const[a,c]=await r.send(e,t,n,s);if(c!=null)throw c;return a},Cr=()=>it.RUNTIME!=="node"?r=>new WebSocket(r):r=>new(require("ws")).WebSocket(r,{rejectUnauthorized:!1}),Dr=i.z.object({type:i.z.union([i.z.literal("data"),i.z.literal("close")]),payload:i.z.unknown().optional(),error:i.z.optional(Se)});class Pr{constructor(e,t,n,s){p(this,"encoder");p(this,"reqSchema");p(this,"resSchema");p(this,"ws");p(this,"serverClosed");p(this,"sendClosed");p(this,"receiveDataQueue",[]);p(this,"receiveCallbacksQueue",[]);this.encoder=t,this.reqSchema=n,this.resSchema=s,this.ws=e,this.sendClosed=!1,this.serverClosed=null,this.listenForMessages()}send(e){if(this.serverClosed!=null)return new D;if(this.sendClosed)throw new P;return this.ws.send(this.encoder.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");return this.serverClosed=Ne(e.error),[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.encoder.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=e=>this.addMessage(this.encoder.decode(e.data,Dr)),this.ws.onclose=e=>this.addMessage({type:"close",error:{type:Fr(e)?D.TYPE:P.TYPE,data:""}})}}const Lr="freighterctx",Yr=1e3,kr=1001,jr=[Yr,kr],Fr=r=>jr.includes(r.code),ae=class ae extends ct{constructor(t,n,s=!1){super();p(this,"baseUrl");p(this,"encoder");this.baseUrl=t.replace({protocol:s?"wss":"ws"}),this.encoder=n}async stream(t,n,s){const a=Cr();let c;const[,d]=await this.executeMiddleware({target:t,protocol:"websocket",params:{},role:"client"},async f=>{const y=a(this.buildURL(t,f)),T={...f,params:{}};y.binaryType=ae.MESSAGE_TYPE;const l=await this.wrapSocket(y,n,s);return l instanceof Error?[T,l]:(c=l,[T,null])});if(d!=null)throw d;return c}buildURL(t,n){const s=vr({[lt]:this.encoder.contentType,...n.params},Lr);return this.baseUrl.child(t).toString()+s}async wrapSocket(t,n,s){return await new Promise(a=>{t.onopen=()=>{a(new Pr(t,this.encoder,n,s))},t.onerror=c=>{const d=c;a(new Error(d.message))}})}};p(ae,"MESSAGE_TYPE","arraybuffer");let Te=ae;exports.BaseTypedError=_;exports.EOF=D;exports.HTTPClient=Rr;exports.StreamClosed=P;exports.Unreachable=Y;exports.WebSocketClient=Te;exports.decodeError=Ne;exports.encodeError=Mr;exports.errorMatcher=ue;exports.errorZ=Se;exports.registerError=ut;exports.sendRequired=Ur;
package/dist/freighter.js CHANGED
@@ -22,11 +22,15 @@ const ft = (r) => {
22
22
  }), s;
23
23
  };
24
24
  return e;
25
- }, We = qe(ft), dt = (r) => r.replace(/([a-z0-9])([A-Z])/g, (e, t, n) => `${t}_${n.toLowerCase()}`), gt = qe(dt), de = {
25
+ }, We = qe(ft), dt = (r) => (
26
+ // Don't convert the first character and don't convert a character that is after a
27
+ // non-alphanumeric character
28
+ r.replace(/([a-z0-9])([A-Z])/g, (e, t, n) => `${t}_${n.toLowerCase()}`)
29
+ ), gt = qe(dt), de = {
26
30
  recursive: !0,
27
31
  recursiveInArray: !0,
28
32
  keepTypesOnRecursion: [Number, String, Uint8Array]
29
- }, pt = (r = de) => (r.recursive == null ? r = de : r.recursiveInArray == null && (r.recursiveInArray = !1), r), Se = (r) => r != null && Array.isArray(r), ce = (r) => r != null && typeof r == "object" && !Array.isArray(r), Ie = (r, e) => (e || []).some((t) => r instanceof t), Ve = (r) => r != null && typeof r == "object" && !Array.isArray(r);
33
+ }, pt = (r = de) => (r.recursive == null ? r = de : r.recursiveInArray ?? (r.recursiveInArray = !1), r), Se = (r) => r != null && Array.isArray(r), ce = (r) => r != null && typeof r == "object" && !Array.isArray(r), Ie = (r, e) => (e || []).some((t) => r instanceof t), Ve = (r) => r != null && typeof r == "object" && !Array.isArray(r);
30
34
  var yt = Object.defineProperty, mt = (r, e, t) => e in r ? yt(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, Q = (r, e, t) => mt(r, typeof e != "symbol" ? e + "" : e, t);
31
35
  let wt = class {
32
36
  constructor() {
@@ -119,12 +123,12 @@ const St = ["start", "center", "end"], It = ["signedWidth", "signedHeight"];
119
123
  i.enum(It);
120
124
  const se = i.object({ x: i.number(), y: i.number() }), Nt = i.object({ clientX: i.number(), clientY: i.number() }), Et = ["x", "y"], Ze = i.enum(Et), Je = ["top", "right", "bottom", "left"];
121
125
  i.enum(Je);
122
- const At = ["left", "right"], He = i.enum(At), xt = ["top", "bottom"], Ke = i.enum(xt), Xe = ["center"], Ne = i.enum(Xe), Mt = [...Je, ...Xe], Qe = i.enum(Mt);
126
+ const At = ["left", "right"], He = i.enum(At), xt = ["top", "bottom"], Xe = i.enum(xt), Ke = ["center"], Ne = i.enum(Ke), Mt = [...Je, ...Ke], Qe = i.enum(Mt);
123
127
  i.enum(St);
124
- const Bt = ["first", "last"];
125
- i.enum(Bt);
126
- const $t = i.object({ lower: i.number(), upper: i.number() }), Rt = i.object({ lower: i.bigint(), upper: i.bigint() });
127
- i.union([$t, ae]);
128
+ const $t = ["first", "last"];
129
+ i.enum($t);
130
+ const Bt = i.object({ lower: i.number(), upper: i.number() }), Rt = i.object({ lower: i.bigint(), upper: i.bigint() });
131
+ i.union([Bt, ae]);
128
132
  i.union([Rt, ae]);
129
133
  i.union([Ze, Qe]);
130
134
  i.union([Ze, Qe, i.instanceof(String)]);
@@ -143,9 +147,9 @@ const Ut = (r) => typeof r == "bigint" || r instanceof BigInt, F = (r, e) => Ut(
143
147
  };
144
148
  i.object({
145
149
  x: He.or(Ne),
146
- y: Ke.or(Ne)
150
+ y: Xe.or(Ne)
147
151
  });
148
- const Ct = i.object({ x: He, y: Ke }), Dt = Object.freeze({ x: "left", y: "top" }), Pt = (r, e) => r.x === e.x && r.y === e.y, xe = i.union([
152
+ const Ct = i.object({ x: He, y: Xe }), Dt = Object.freeze({ x: "left", y: "top" }), Pt = (r, e) => r.x === e.x && r.y === e.y, xe = i.union([
149
153
  i.number(),
150
154
  se,
151
155
  ae,
@@ -204,6 +208,7 @@ const be = (r, e, t = 0, n = 0, s) => {
204
208
  var kt = Object.defineProperty, jt = (r, e, t) => e in r ? kt(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, D = (r, e, t) => jt(r, typeof e != "symbol" ? e + "" : e, t);
205
209
  const Ft = (r, e, t) => e !== void 0 && r < e ? e : t !== void 0 && r > t ? t : r;
206
210
  i.object({ offset: xe, scale: xe });
211
+ i.object({ offset: i.number(), scale: i.number() });
207
212
  const Gt = (r) => (e, t, n, s) => t === "dimension" ? [e, n] : [
208
213
  e,
209
214
  s ? n - r : n + r
@@ -228,19 +233,41 @@ const Gt = (r) => (e, t, n, s) => t === "dimension" ? [e, n] : [
228
233
  constructor() {
229
234
  D(this, "ops", []), D(this, "currBounds", null), D(this, "currType", null), D(this, "reversed", !1), this.ops = [];
230
235
  }
236
+ /**
237
+ * @returns a new scale with a translation as its first operation. Any number provided
238
+ * to the {@link pos} operation on the scale will be translated by the specified value.
239
+ * @param value - The amount to translate by.
240
+ */
231
241
  static translate(e) {
232
242
  return new z().translate(e);
233
243
  }
244
+ /**
245
+ * @returns a new scale with a magnification as its first operation. Any number provided
246
+ * to the {@link pos} or {@link dim} operation will be multiplied by the specified value.
247
+ * @param value - The amount to translate by.
248
+ */
234
249
  static magnify(e) {
235
250
  return new z().magnify(e);
236
251
  }
237
252
  static scale(e, t) {
238
253
  return new z().scale(e, t);
239
254
  }
255
+ /**
256
+ * @returns a copy of the scale with a translation as its next operation. Any
257
+ * number provided to the {@link pos} method on the scale will be translated by the
258
+ * specified value.
259
+ * @param value - The amount to translate by.
260
+ */
240
261
  translate(e) {
241
262
  const t = this.new(), n = Gt(e);
242
263
  return n.type = "translate", t.ops.push(n), t;
243
264
  }
265
+ /**
266
+ * @returns a copy of the scale with a translation as its next operation. Any number
267
+ * provided to the {@link pos} or {@link dim} method on the scale will be multiplied
268
+ * by the specified value.
269
+ * @param value - The amount to magnify by.
270
+ */
244
271
  magnify(e) {
245
272
  const t = this.new(), n = qt(e);
246
273
  return n.type = "magnify", t.ops.push(n), t;
@@ -293,11 +320,14 @@ const Gt = (r) => (e, t, n, s) => t === "dimension" ? [e, n] : [
293
320
  a.unshift(e.ops[s]), e.ops.splice(n, s - n + 1, ...a);
294
321
  }), e.reversed = !e.reversed, e;
295
322
  }
323
+ get transform() {
324
+ return { scale: this.dim(1), offset: this.pos(0) };
325
+ }
296
326
  };
297
327
  D(ge, "IDENTITY", new ge());
298
- let Be = ge;
299
- const $e = class C {
300
- constructor(e = new Be(), t = new Be(), n = null) {
328
+ let $e = ge;
329
+ const Be = class C {
330
+ constructor(e = new $e(), t = new $e(), n = null) {
301
331
  D(this, "x"), D(this, "y"), D(this, "currRoot"), this.x = e, this.y = t, this.currRoot = n;
302
332
  }
303
333
  static translate(e, t) {
@@ -364,6 +394,9 @@ const $e = class C {
364
394
  pos(e) {
365
395
  return { x: this.x.pos(e.x), y: this.y.pos(e.y) };
366
396
  }
397
+ dim(e) {
398
+ return { x: this.x.dim(e.x), y: this.y.dim(e.y) };
399
+ }
367
400
  box(e) {
368
401
  return be(
369
402
  this.pos(e.one),
@@ -373,8 +406,14 @@ const $e = class C {
373
406
  this.currRoot ?? e.root
374
407
  );
375
408
  }
409
+ get transform() {
410
+ return {
411
+ scale: this.dim({ x: 1, y: 1 }),
412
+ offset: this.pos({ x: 0, y: 0 })
413
+ };
414
+ }
376
415
  };
377
- D($e, "IDENTITY", new $e());
416
+ D(Be, "IDENTITY", new Be());
378
417
  const Jt = (r) => r != null && typeof r == "object" && "toString" in r, Ht = (r, e = !1) => {
379
418
  const t = Jt(r) ? "stringer" : typeof r;
380
419
  let n;
@@ -400,9 +439,9 @@ const Jt = (r) => r != null && typeof r == "object" && "toString" in r, Ht = (r,
400
439
  default:
401
440
  return console.warn(`sortFunc: unknown type ${t}`), () => -1;
402
441
  }
403
- return e ? Kt(n) : n;
404
- }, Kt = (r) => (e, t) => r(t, e), Xt = i.object({ signedWidth: i.number(), signedHeight: i.number() });
405
- i.union([ze, Xt, se, ae]);
442
+ return e ? Xt(n) : n;
443
+ }, Xt = (r) => (e, t) => r(t, e), Kt = i.object({ signedWidth: i.number(), signedHeight: i.number() });
444
+ i.union([ze, Kt, se, ae]);
406
445
  const Qt = i.bigint().or(i.string().transform(BigInt));
407
446
  var _t = Object.defineProperty, er = (r, e, t) => e in r ? _t(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, u = (r, e, t) => er(r, typeof e != "symbol" ? e + "" : e, t);
408
447
  let tr = (r, e = 21) => (t = e) => {
@@ -454,7 +493,7 @@ const rr = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", nr
454
493
  const [n, s, a] = e.split(":");
455
494
  let c = "00", f = "00";
456
495
  a != null && ([c, f] = a.split("."));
457
- let d = h.hours(parseInt(n ?? "00", 10)).add(h.minutes(parseInt(s ?? "00", 10))).add(h.seconds(parseInt(c ?? "00", 10))).add(h.milliseconds(parseInt(f ?? "00", 10)));
496
+ let d = h.hours(parseInt(n ?? "00")).add(h.minutes(parseInt(s ?? "00"))).add(h.seconds(parseInt(c ?? "00"))).add(h.milliseconds(parseInt(f ?? "00")));
458
497
  return t === "local" && (d = d.add(h.utcOffset)), d.valueOf();
459
498
  }
460
499
  static parseDateTimeString(e, t = "UTC") {
@@ -1120,25 +1159,24 @@ u(M, "z", i.union([
1120
1159
  i.instanceof(M)
1121
1160
  ]));
1122
1161
  let Te = M;
1123
- const o = class B extends String {
1162
+ const o = class $ extends String {
1124
1163
  constructor(e) {
1125
- if (e instanceof B || typeof e == "string" || typeof e.valueOf() == "string") {
1164
+ if (e instanceof $ || typeof e == "string" || typeof e.valueOf() == "string") {
1126
1165
  super(e.valueOf());
1127
1166
  return;
1128
- } else {
1129
- const t = B.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);
1130
- if (t != null) {
1131
- super(t.valueOf());
1132
- return;
1133
- }
1134
1167
  }
1135
- throw super(B.UNKNOWN.valueOf()), new Error(`unable to find data type for ${e.toString()}`);
1168
+ const t = $.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);
1169
+ if (t != null) {
1170
+ super(t.valueOf());
1171
+ return;
1172
+ }
1173
+ throw super($.UNKNOWN.valueOf()), new Error(`unable to find data type for ${e.toString()}`);
1136
1174
  }
1137
1175
  /**
1138
1176
  * @returns the TypedArray constructor for the DataType.
1139
1177
  */
1140
1178
  get Array() {
1141
- const e = B.ARRAY_CONSTRUCTORS.get(this.toString());
1179
+ const e = $.ARRAY_CONSTRUCTORS.get(this.toString());
1142
1180
  if (e == null)
1143
1181
  throw new Error(`unable to find array constructor for ${this.valueOf()}`);
1144
1182
  return e;
@@ -1160,10 +1198,10 @@ const o = class B extends String {
1160
1198
  return this.valueOf();
1161
1199
  }
1162
1200
  get isVariable() {
1163
- return this.equals(B.JSON) || this.equals(B.STRING);
1201
+ return this.equals($.JSON) || this.equals($.STRING);
1164
1202
  }
1165
1203
  get isNumeric() {
1166
- return !this.isVariable && !this.equals(B.UUID);
1204
+ return !this.isVariable && !this.equals($.UUID);
1167
1205
  }
1168
1206
  get isInteger() {
1169
1207
  return this.toString().startsWith("int");
@@ -1172,7 +1210,7 @@ const o = class B extends String {
1172
1210
  return this.toString().startsWith("float");
1173
1211
  }
1174
1212
  get density() {
1175
- const e = B.DENSITIES.get(this.toString());
1213
+ const e = $.DENSITIES.get(this.toString());
1176
1214
  if (e == null) throw new Error(`unable to find density for ${this.valueOf()}`);
1177
1215
  return e;
1178
1216
  }
@@ -1197,7 +1235,7 @@ const o = class B extends String {
1197
1235
  return this.toString();
1198
1236
  }
1199
1237
  get usesBigInt() {
1200
- return B.BIG_INT_TYPES.some((e) => e.equals(this));
1238
+ return $.BIG_INT_TYPES.some((e) => e.equals(this));
1201
1239
  }
1202
1240
  };
1203
1241
  u(o, "UNKNOWN", new o("unknown")), /** Represents a 64-bit floating point value. */
@@ -1401,7 +1439,7 @@ const et = (r) => {
1401
1439
  (r) => new Uint8Array(
1402
1440
  atob(r).split("").map((e) => e.charCodeAt(0))
1403
1441
  ).buffer
1404
- ), ur = i.union([i.null(), i.undefined()]).transform(() => new Uint8Array().buffer), ye = 10, J = class $ {
1442
+ ), ur = i.union([i.null(), i.undefined()]).transform(() => new Uint8Array().buffer), ye = 10, J = class B {
1405
1443
  constructor(e) {
1406
1444
  u(this, "key", ""), u(this, "isSynnaxSeries", !0), u(this, "dataType"), u(this, "sampleOffset"), u(this, "gl"), u(this, "_data"), u(this, "_timeRange"), u(this, "alignment", 0n), u(this, "_cachedMin"), u(this, "_cachedMax"), u(this, "writePos", P), u(this, "_refCount", 0), u(this, "_cachedLength"), u(this, "_cachedIndexes"), ar(e) && (e = { data: e });
1407
1445
  const {
@@ -1412,7 +1450,7 @@ const et = (r) => {
1412
1450
  alignment: c = 0n,
1413
1451
  key: f = nr()
1414
1452
  } = e, d = e.data ?? [];
1415
- if (d instanceof $ || typeof d == "object" && "isSynnaxSeries" in d && d.isSynnaxSeries === !0) {
1453
+ if (d instanceof B || typeof d == "object" && "isSynnaxSeries" in d && d.isSynnaxSeries === !0) {
1416
1454
  const l = d;
1417
1455
  this.key = l.key, this.dataType = l.dataType, this.sampleOffset = l.sampleOffset, this.gl = l.gl, this._data = l._data, this._timeRange = l._timeRange, this.alignment = l.alignment, this._cachedMin = l._cachedMin, this._cachedMax = l._cachedMax, this.writePos = l.writePos, this._refCount = l._refCount, this._cachedLength = l._cachedLength;
1418
1456
  return;
@@ -1450,11 +1488,11 @@ const et = (r) => {
1450
1488
  else {
1451
1489
  let l = y ? [d] : d;
1452
1490
  const E = l[0];
1453
- (E instanceof O || E instanceof Date || E instanceof S) && (l = l.map((R) => new O(R).valueOf())), this.dataType.equals(b.STRING) ? (this._cachedLength = l.length, this._data = new TextEncoder().encode(l.join(`
1454
- `) + `
1491
+ (E instanceof O || E instanceof Date || E instanceof S) && (l = l.map((R) => new O(R).valueOf())), this.dataType.equals(b.STRING) ? (this._cachedLength = l.length, this._data = new TextEncoder().encode(`${l.join(`
1492
+ `)}
1455
1493
  `)) : this.dataType.equals(b.JSON) ? (this._cachedLength = l.length, this._data = new TextEncoder().encode(
1456
- l.map((R) => ee.encodeString(R)).join(`
1457
- `) + `
1494
+ `${l.map((R) => ee.encodeString(R)).join(`
1495
+ `)}
1458
1496
  `
1459
1497
  )) : this._data = new this.dataType.Array(l).buffer;
1460
1498
  }
@@ -1468,7 +1506,7 @@ const et = (r) => {
1468
1506
  static alloc({ capacity: e, dataType: t, ...n }) {
1469
1507
  if (e === 0)
1470
1508
  throw new Error("[Series] - cannot allocate an array of length 0");
1471
- const s = new new b(t).Array(e), a = new $({
1509
+ const s = new new b(t).Array(e), a = new B({
1472
1510
  data: s.buffer,
1473
1511
  dataType: t,
1474
1512
  ...n
@@ -1479,24 +1517,24 @@ const et = (r) => {
1479
1517
  const s = n.spanRange(t.span(e)), a = new BigInt64Array(e);
1480
1518
  for (let c = 0; c < e; c++)
1481
1519
  a[c] = BigInt(n.add(t.span(c)).valueOf());
1482
- return new $({ data: a, dataType: b.TIMESTAMP, timeRange: s });
1520
+ return new B({ data: a, dataType: b.TIMESTAMP, timeRange: s });
1483
1521
  }
1484
1522
  get refCount() {
1485
1523
  return this._refCount;
1486
1524
  }
1487
1525
  static fromStrings(e, t) {
1488
- const n = new TextEncoder().encode(e.join(`
1489
- `) + `
1526
+ const n = new TextEncoder().encode(`${e.join(`
1527
+ `)}
1490
1528
  `);
1491
- return new $({ data: n, dataType: b.STRING, timeRange: t });
1529
+ return new B({ data: n, dataType: b.STRING, timeRange: t });
1492
1530
  }
1493
1531
  static fromJSON(e, t) {
1494
1532
  const n = new TextEncoder().encode(
1495
- e.map((s) => ee.encodeString(s)).join(`
1496
- `) + `
1533
+ `${e.map((s) => ee.encodeString(s)).join(`
1534
+ `)}
1497
1535
  `
1498
1536
  );
1499
- return new $({ data: n, dataType: b.JSON, timeRange: t });
1537
+ return new B({ data: n, dataType: b.JSON, timeRange: t });
1500
1538
  }
1501
1539
  acquire(e) {
1502
1540
  this._refCount++, e != null && this.updateGLBuffer(e);
@@ -1613,7 +1651,7 @@ const et = (r) => {
1613
1651
  const n = new e.Array(this.length);
1614
1652
  for (let s = 0; s < this.length; s++)
1615
1653
  n[s] = ir(this.dataType, e, this.data[s], t);
1616
- return new $({
1654
+ return new B({
1617
1655
  data: n.buffer,
1618
1656
  dataType: e,
1619
1657
  timeRange: this._timeRange,
@@ -1639,12 +1677,11 @@ const et = (r) => {
1639
1677
  get max() {
1640
1678
  if (this.dataType.isVariable)
1641
1679
  throw new Error("cannot calculate maximum on a variable length data type");
1642
- return this.writePos === 0 ? -1 / 0 : (this._cachedMax == null && (this._cachedMax = this.calcRawMax()), H(this._cachedMax, this.sampleOffset));
1680
+ return this.writePos === 0 ? -1 / 0 : (this._cachedMax ?? (this._cachedMax = this.calcRawMax()), H(this._cachedMax, this.sampleOffset));
1643
1681
  }
1644
1682
  calcRawMin() {
1645
1683
  if (this.length === 0) return 1 / 0;
1646
- if (this.dataType.equals(b.TIMESTAMP))
1647
- this._cachedMin = this.data[0];
1684
+ if (this.dataType.equals(b.TIMESTAMP)) this._cachedMin = this.data[0];
1648
1685
  else if (this.dataType.usesBigInt) {
1649
1686
  const e = this.data;
1650
1687
  this._cachedMin = e.reduce((t, n) => t < n ? t : n);
@@ -1658,7 +1695,7 @@ const et = (r) => {
1658
1695
  get min() {
1659
1696
  if (this.dataType.isVariable)
1660
1697
  throw new Error("cannot calculate minimum on a variable length data type");
1661
- return this.writePos === 0 ? 1 / 0 : (this._cachedMin == null && (this._cachedMin = this.calcRawMin()), H(this._cachedMin, this.sampleOffset));
1698
+ return this.writePos === 0 ? 1 / 0 : (this._cachedMin ?? (this._cachedMin = this.calcRawMin()), H(this._cachedMin, this.sampleOffset));
1662
1699
  }
1663
1700
  /** @returns the bounds of this array. */
1664
1701
  get bounds() {
@@ -1833,7 +1870,7 @@ const et = (r) => {
1833
1870
  subBytes(e, t) {
1834
1871
  if (e >= 0 && (t == null || t >= this.byteLength.valueOf())) return this;
1835
1872
  const n = this.data.subarray(e, t);
1836
- return new $({
1873
+ return new B({
1837
1874
  data: n,
1838
1875
  dataType: this.dataType,
1839
1876
  timeRange: this._timeRange,
@@ -1845,7 +1882,7 @@ const et = (r) => {
1845
1882
  sliceSub(e, t, n) {
1846
1883
  if (t <= 0 && (n == null || n >= this.length)) return this;
1847
1884
  let s;
1848
- return e ? s = this.data.subarray(t, n) : s = this.data.slice(t, n), new $({
1885
+ return e ? s = this.data.subarray(t, n) : s = this.data.slice(t, n), new B({
1849
1886
  data: s,
1850
1887
  dataType: this.dataType,
1851
1888
  timeRange: this._timeRange,
@@ -1855,7 +1892,7 @@ const et = (r) => {
1855
1892
  });
1856
1893
  }
1857
1894
  reAlign(e) {
1858
- return new $({
1895
+ return new B({
1859
1896
  data: this.buffer,
1860
1897
  dataType: this.dataType,
1861
1898
  timeRange: Te.ZERO,
@@ -1963,8 +2000,8 @@ const pr = () => {
1963
2000
  getOS: yr,
1964
2001
  osZ: gr
1965
2002
  }, Symbol.toStringTag, { value: "Module" }));
1966
- var mr = Object.defineProperty, wr = (r, e, t) => e in r ? mr(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, K = (r, e, t) => wr(r, typeof e != "symbol" ? e + "" : e, t);
1967
- const br = (...r) => r.map(st).join(""), st = (r) => (r.endsWith("/") || (r += "/"), r.startsWith("/") && (r = r.slice(1)), r), Tr = (r) => r.endsWith("/") ? r.slice(0, -1) : r, Or = (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("&"), me = class we {
2003
+ var mr = Object.defineProperty, wr = (r, e, t) => e in r ? mr(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, X = (r, e, t) => wr(r, typeof e != "symbol" ? e + "" : e, t);
2004
+ const br = (...r) => r.map(st).join(""), st = (r) => (r.endsWith("/") || (r += "/"), r.startsWith("/") && (r = r.slice(1)), r), Tr = (r) => r.endsWith("/") ? r.slice(0, -1) : r, Or = (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("&")}`, me = class we {
1968
2005
  /**
1969
2006
  * @param host - The hostname or IP address of the server.
1970
2007
  * @param port - The port number of the server.
@@ -1972,7 +2009,7 @@ const br = (...r) => r.map(st).join(""), st = (r) => (r.endsWith("/") || (r += "
1972
2009
  * @param pathPrefix - A path prefix to use for all requests. Defaults to "".
1973
2010
  */
1974
2011
  constructor({ host: e, port: t, protocol: n = "", pathPrefix: s = "" }) {
1975
- K(this, "protocol"), K(this, "host"), K(this, "port"), K(this, "path"), this.protocol = n, this.host = e, this.port = t, this.path = st(s);
2012
+ X(this, "protocol"), X(this, "host"), X(this, "port"), X(this, "path"), this.protocol = n, this.host = e, this.port = t, this.path = st(s);
1976
2013
  }
1977
2014
  /**
1978
2015
  * Replaces creates a new URL with the specified properties replaced.
@@ -2005,7 +2042,7 @@ const br = (...r) => r.map(st).join(""), st = (r) => (r.endsWith("/") || (r += "
2005
2042
  );
2006
2043
  }
2007
2044
  };
2008
- K(me, "UNKNOWN", new me({ host: "unknown", port: 0 }));
2045
+ X(me, "UNKNOWN", new me({ host: "unknown", port: 0 }));
2009
2046
  let vr = me;
2010
2047
  var Sr = Object.defineProperty, Ir = (r, e, t) => e in r ? Sr(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, ne = (r, e, t) => Ir(r, typeof e != "symbol" ? e + "" : e, t);
2011
2048
  const G = class extends Number {
@@ -2019,13 +2056,13 @@ i.object({
2019
2056
  name: i.string(),
2020
2057
  key: i.string()
2021
2058
  });
2022
- const it = class X extends Error {
2059
+ const it = class K extends Error {
2023
2060
  constructor() {
2024
- super(X.MESSAGE);
2061
+ super(K.MESSAGE);
2025
2062
  }
2026
2063
  /** Returns true if the error or message is a cancellation error" */
2027
2064
  matches(e) {
2028
- return typeof e == "string" ? e.includes(X.MESSAGE) : e instanceof X || e.message.includes(X.MESSAGE);
2065
+ return typeof e == "string" ? e.includes(K.MESSAGE) : e instanceof K || e.message.includes(K.MESSAGE);
2029
2066
  }
2030
2067
  };
2031
2068
  ne(it, "MESSAGE", "canceled");
@@ -2034,8 +2071,8 @@ new Nr();
2034
2071
  i.string().regex(/^\d+\.\d+\.\d+$/);
2035
2072
  const Oe = (r) => (e) => e != null && typeof e == "object" && "type" in e && typeof e.type == "string" ? e.type.includes(r) : e instanceof Error ? e.message.includes(r) : typeof e != "string" ? !1 : e.includes(r);
2036
2073
  class oe extends Error {
2037
- constructor(t) {
2038
- super(t);
2074
+ constructor() {
2075
+ super(...arguments);
2039
2076
  p(this, "discriminator", "FreighterError");
2040
2077
  p(this, "type", "");
2041
2078
  }
@@ -2081,8 +2118,8 @@ const ve = new xr(), Mr = ({
2081
2118
  decode: e
2082
2119
  }) => ve.register({ encode: r, decode: e }), Zr = (r) => ve.encode(r), ot = (r) => ve.decode(r);
2083
2120
  class je extends oe {
2084
- constructor(t) {
2085
- super(t);
2121
+ constructor() {
2122
+ super(...arguments);
2086
2123
  p(this, "type", "unknown");
2087
2124
  }
2088
2125
  }
@@ -2092,7 +2129,7 @@ const ue = "freighter.", q = class q extends oe {
2092
2129
  p(this, "type", q.TYPE);
2093
2130
  }
2094
2131
  };
2095
- p(q, "TYPE", ue + "eof"), p(q, "matches", Oe(q.TYPE));
2132
+ p(q, "TYPE", `${ue}eof`), p(q, "matches", Oe(q.TYPE));
2096
2133
  let L = q;
2097
2134
  const W = class W extends oe {
2098
2135
  constructor() {
@@ -2100,7 +2137,7 @@ const W = class W extends oe {
2100
2137
  p(this, "type", W.TYPE);
2101
2138
  }
2102
2139
  };
2103
- p(W, "TYPE", ue + "stream_closed"), p(W, "matches", Oe(W.TYPE));
2140
+ p(W, "TYPE", `${ue}stream_closed`), p(W, "matches", Oe(W.TYPE));
2104
2141
  let Y = W;
2105
2142
  const V = class V extends oe {
2106
2143
  constructor(t = {}) {
@@ -2111,9 +2148,9 @@ const V = class V extends oe {
2111
2148
  this.url = s;
2112
2149
  }
2113
2150
  };
2114
- p(V, "TYPE", ue + "unreachable"), p(V, "matches", Oe(V.TYPE));
2151
+ p(V, "TYPE", `${ue}unreachable`), p(V, "matches", Oe(V.TYPE));
2115
2152
  let j = V;
2116
- const Br = (r) => {
2153
+ const $r = (r) => {
2117
2154
  if (!r.type.startsWith(Ar)) return null;
2118
2155
  if (L.matches(r)) return { type: L.TYPE, data: "EOF" };
2119
2156
  if (Y.matches(r))
@@ -2121,7 +2158,7 @@ const Br = (r) => {
2121
2158
  if (j.matches(r))
2122
2159
  return { type: j.TYPE, data: "Unreachable" };
2123
2160
  throw new Error(`Unknown error type: ${r.type}: ${r.message}`);
2124
- }, $r = (r) => {
2161
+ }, Br = (r) => {
2125
2162
  if (!r.type.startsWith(ue)) return null;
2126
2163
  switch (r.type) {
2127
2164
  case L.TYPE:
@@ -2135,8 +2172,8 @@ const Br = (r) => {
2135
2172
  }
2136
2173
  };
2137
2174
  Mr({
2138
- encode: Br,
2139
- decode: $r
2175
+ encode: $r,
2176
+ decode: Br
2140
2177
  });
2141
2178
  class ut {
2142
2179
  constructor() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synnaxlabs/freighter",
3
- "version": "0.33.0",
3
+ "version": "0.35.0",
4
4
  "type": "module",
5
5
  "description": "a modular transport abstraction",
6
6
  "repository": "https://github.com/synnaxlabs/synnax/tree/main/freighter/ts",
@@ -17,17 +17,18 @@
17
17
  "node-fetch": "^2.7.0",
18
18
  "ws": "^8.18.0",
19
19
  "zod": "^3.23.8",
20
- "@synnaxlabs/alamos": "0.33.0",
21
- "@synnaxlabs/x": "0.33.0"
20
+ "@synnaxlabs/x": "0.35.0",
21
+ "@synnaxlabs/alamos": "0.35.0"
22
22
  },
23
23
  "devDependencies": {
24
24
  "@types/node": "^22.7.5",
25
- "@vitest/coverage-v8": "^2.1.2",
25
+ "@vitest/coverage-v8": "^2.1.4",
26
+ "eslint": "^9.12.0",
26
27
  "typescript": "^5.6.3",
27
- "vite": "^5.4.8",
28
- "vitest": "^2.1.2",
29
- "@synnaxlabs/tsconfig": "0.0.2",
28
+ "vite": "^5.4.10",
29
+ "vitest": "^2.1.4",
30
30
  "@synnaxlabs/vite-plugin": "0.0.1",
31
+ "@synnaxlabs/tsconfig": "0.0.2",
31
32
  "eslint-config-synnaxlabs": "0.0.1"
32
33
  },
33
34
  "main": "dist/freighter.cjs",
@@ -38,7 +39,7 @@
38
39
  "watch": "tsc --noEmit && vite build --watch",
39
40
  "test": "vitest",
40
41
  "cov": "vitest --coverage",
41
- "lint": "eslint \"src/**/*.ts*\"",
42
- "fix": "eslint \"src/**/*.ts*\" --fix"
42
+ "lint": "eslint --cache",
43
+ "fix": "eslint --cache --fix"
43
44
  }
44
45
  }
@@ -29,9 +29,6 @@ import {
29
29
 
30
30
  class MyCustomError extends BaseTypedError {
31
31
  type = "MyCustomError";
32
- constructor(message: string) {
33
- super(message);
34
- }
35
32
  }
36
33
 
37
34
  const myCustomErrorEncoder = (error: MyCustomError): ErrorPayload | null => {
@@ -39,9 +36,8 @@ const myCustomErrorEncoder = (error: MyCustomError): ErrorPayload | null => {
39
36
  return { type: "MyCustomError", data: error.message };
40
37
  };
41
38
 
42
- const myCustomErrorDecoder = (encoded: ErrorPayload): TypedError => {
43
- return new MyCustomError(encoded.data);
44
- };
39
+ const myCustomErrorDecoder = (encoded: ErrorPayload): TypedError =>
40
+ new MyCustomError(encoded.data);
45
41
 
46
42
  describe("errors", () => {
47
43
  test("isTypedError", () => {
package/src/errors.ts CHANGED
@@ -46,10 +46,6 @@ export const errorMatcher =
46
46
  export class BaseTypedError extends Error implements TypedError {
47
47
  readonly discriminator = "FreighterError";
48
48
  type: string = "";
49
-
50
- constructor(message?: string) {
51
- super(message);
52
- }
53
49
  }
54
50
 
55
51
  type ErrorDecoder = (encoded: ErrorPayload) => Error | null;
@@ -100,12 +96,11 @@ class Registry {
100
96
 
101
97
  encode(error: unknown): ErrorPayload {
102
98
  if (error == null) return { type: NONE, data: "" };
103
- if (isTypedError(error)) {
99
+ if (isTypedError(error))
104
100
  for (const provider of this.providers) {
105
101
  const payload = provider.encode(error);
106
102
  if (payload != null) return payload;
107
103
  }
108
- }
109
104
  return { type: UNKNOWN, data: JSON.stringify(error) };
110
105
  }
111
106
 
@@ -144,9 +139,7 @@ export const registerError = ({
144
139
  * @param error - The error to encode.
145
140
  * @returns The encoded error.
146
141
  */
147
- export const encodeError = (error: unknown): ErrorPayload => {
148
- return REGISTRY.encode(error);
149
- };
142
+ export const encodeError = (error: unknown): ErrorPayload => REGISTRY.encode(error);
150
143
 
151
144
  /**
152
145
  * Decodes an error payload into an exception. If a custom decoder can be found
@@ -156,22 +149,18 @@ export const encodeError = (error: unknown): ErrorPayload => {
156
149
  * @param payload - The encoded error payload.
157
150
  * @returns The decoded error.
158
151
  */
159
- export const decodeError = (payload: ErrorPayload): Error | null => {
160
- return REGISTRY.decode(payload);
161
- };
152
+ export const decodeError = (payload: ErrorPayload): Error | null =>
153
+ REGISTRY.decode(payload);
162
154
 
163
155
  export class UnknownError extends BaseTypedError implements TypedError {
164
156
  type = "unknown";
165
- constructor(message: string) {
166
- super(message);
167
- }
168
157
  }
169
158
 
170
159
  const FREIGHTER_ERROR_TYPE = "freighter.";
171
160
 
172
161
  /** Thrown/returned when a stream closed normally. */
173
162
  export class EOF extends BaseTypedError implements TypedError {
174
- static readonly TYPE = FREIGHTER_ERROR_TYPE + "eof";
163
+ static readonly TYPE = `${FREIGHTER_ERROR_TYPE}eof`;
175
164
  type = EOF.TYPE;
176
165
  static readonly matches = errorMatcher(EOF.TYPE);
177
166
 
@@ -182,7 +171,7 @@ export class EOF extends BaseTypedError implements TypedError {
182
171
 
183
172
  /** Thrown/returned when a stream is closed abnormally. */
184
173
  export class StreamClosed extends BaseTypedError implements TypedError {
185
- static readonly TYPE = FREIGHTER_ERROR_TYPE + "stream_closed";
174
+ static readonly TYPE = `${FREIGHTER_ERROR_TYPE}stream_closed`;
186
175
  static readonly matches = errorMatcher(StreamClosed.TYPE);
187
176
  type = StreamClosed.TYPE;
188
177
 
@@ -198,7 +187,7 @@ export interface UnreachableArgs {
198
187
 
199
188
  /** Thrown when a target is unreachable. */
200
189
  export class Unreachable extends BaseTypedError implements TypedError {
201
- static readonly TYPE = FREIGHTER_ERROR_TYPE + "unreachable";
190
+ static readonly TYPE = `${FREIGHTER_ERROR_TYPE}unreachable`;
202
191
  type = Unreachable.TYPE;
203
192
  static readonly matches = errorMatcher(Unreachable.TYPE);
204
193
  url: URL;
@@ -44,16 +44,15 @@ class MyCustomError extends BaseTypedError {
44
44
  }
45
45
 
46
46
  const encodeTestError = (err: TypedError): ErrorPayload => {
47
- if (!(err instanceof MyCustomError)) {
48
- throw new Error("Unexpected error type");
49
- }
47
+ if (!(err instanceof MyCustomError)) throw new Error("Unexpected error type");
48
+
50
49
  return { type: "integration.error", data: `${err.code},${err.message}` };
51
50
  };
52
51
 
53
52
  const decodeTestError = (encoded: ErrorPayload): TypedError | null => {
54
53
  if (encoded.type !== "integration.error") return null;
55
54
  const [code, message] = encoded.data.split(",");
56
- return new MyCustomError(message, parseInt(code, 10));
55
+ return new MyCustomError(message, parseInt(code));
57
56
  };
58
57
 
59
58
  registerError({