@synnaxlabs/freighter 0.23.0 → 0.25.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/alamos.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { Middleware } from './middleware';
2
1
  import { Instrumentation } from '@synnaxlabs/alamos';
2
+ import { Middleware } from './middleware';
3
3
 
4
4
  export declare const middleware: (instrumentation: Instrumentation) => Middleware;
5
5
  //# sourceMappingURL=alamos.d.ts.map
package/dist/errors.d.ts CHANGED
@@ -1,6 +1,14 @@
1
- import { z } from 'zod';
2
1
  import { URL } from '@synnaxlabs/x';
2
+ import { z } from 'zod';
3
3
 
4
+ /** Basic interface for an error or error type that can be matched against a candidate error */
5
+ export interface MatchableErrorType {
6
+ /**
7
+ * @returns a function that matches errors of the given type. Returns true if
8
+ * the provided instance of Error or a string message contains the provided error type.
9
+ */
10
+ matches: (e: string | Error | unknown) => boolean;
11
+ }
4
12
  export interface TypedError extends Error {
5
13
  discriminator: "FreighterError";
6
14
  /**
@@ -9,10 +17,16 @@ export interface TypedError extends Error {
9
17
  */
10
18
  type: string;
11
19
  }
20
+ /**
21
+ * @param type - the error type to match
22
+ * @returns a function that matches errors of the given type. Returns true if
23
+ * the provided instance of Error or a string message contains the provided error type.
24
+ */
25
+ export declare const errorMatcher: (type: string) => (e: string | Error | unknown) => boolean;
12
26
  export declare class BaseTypedError extends Error implements TypedError {
13
27
  readonly discriminator = "FreighterError";
14
28
  type: string;
15
- constructor(message: string, type: string);
29
+ constructor(message?: string);
16
30
  }
17
31
  type ErrorDecoder = (encoded: ErrorPayload) => Error | null;
18
32
  type ErrorEncoder = (error: TypedError) => ErrorPayload | null;
@@ -61,16 +75,21 @@ export declare const encodeError: (error: unknown) => ErrorPayload;
61
75
  */
62
76
  export declare const decodeError: (payload: ErrorPayload) => Error | null;
63
77
  export declare class UnknownError extends BaseTypedError implements TypedError {
78
+ type: string;
64
79
  constructor(message: string);
65
80
  }
66
81
  /** Thrown/returned when a stream closed normally. */
67
82
  export declare class EOF extends BaseTypedError implements TypedError {
68
83
  static readonly TYPE: string;
84
+ type: string;
85
+ static readonly matches: (e: string | Error | unknown) => boolean;
69
86
  constructor();
70
87
  }
71
88
  /** Thrown/returned when a stream is closed abnormally. */
72
89
  export declare class StreamClosed extends BaseTypedError implements TypedError {
73
90
  static readonly TYPE: string;
91
+ static readonly matches: (e: string | Error | unknown) => boolean;
92
+ type: string;
74
93
  constructor();
75
94
  }
76
95
  export interface UnreachableArgs {
@@ -80,6 +99,8 @@ export interface UnreachableArgs {
80
99
  /** Thrown when a target is unreachable. */
81
100
  export declare class Unreachable extends BaseTypedError implements TypedError {
82
101
  static readonly TYPE: string;
102
+ type: string;
103
+ static readonly matches: (e: string | Error | unknown) => boolean;
83
104
  url: URL;
84
105
  constructor(args?: UnreachableArgs);
85
106
  }
@@ -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,MAAM,WAAW,UAAW,SAAQ,KAAK;IACvC,aAAa,EAAE,gBAAgB,CAAC;IAChC;;;OAGG;IACH,IAAI,EAAE,MAAM,CAAC;CACd;AAED,qBAAa,cAAe,SAAQ,KAAM,YAAW,UAAU;IAC7D,QAAQ,CAAC,aAAa,oBAAoB;IAC1C,IAAI,EAAE,MAAM,CAAC;gBAED,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM;CAI1C;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,wBAS1C,CAAC;AAEF,eAAO,MAAM,eAAe,YAAa,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;gBACxD,OAAO,EAAE,MAAM;CAG5B;AAID,qDAAqD;AACrD,qBAAa,GAAI,SAAQ,cAAe,YAAW,UAAU;IAC3D,MAAM,CAAC,QAAQ,CAAC,IAAI,SAAgC;;CAKrD;AAED,0DAA0D;AAC1D,qBAAa,YAAa,SAAQ,cAAe,YAAW,UAAU;IACpE,MAAM,CAAC,QAAQ,CAAC,IAAI,SAA0C;;CAK/D;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,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;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 +1,3 @@
1
- "use strict";var $t=Object.defineProperty;var Ut=(t,e,r)=>e in t?$t(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var v=(t,e,r)=>(Ut(t,typeof e!="symbol"?e+"":e,r),r);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("zod");var E=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{},d={},ue={};Object.defineProperty(ue,"__esModule",{value:!0});function xt(t){return t===void 0&&(t=""),t?String(t).replace(/^[^A-Za-z0-9]*|[^A-Za-z0-9]*$/g,"").replace(/[^A-Za-z0-9]+/g,"$").replace(/([a-z])([A-Z])/g,function(e,r,n){return r+"$"+n}).toLowerCase().replace(/(\$)(\w)/g,function(e,r,n){return n.toUpperCase()}):""}ue.default=xt;var le={};Object.defineProperty(le,"__esModule",{value:!0});function Mt(t){return t===void 0&&(t=""),t?String(t).replace(/^[^A-Za-z0-9]*|[^A-Za-z0-9]*$/g,"").replace(/([a-z])([A-Z])/g,function(e,r,n){return r+"_"+n.toLowerCase()}).replace(/[^A-Za-z0-9]+|_+/g,"_").toLowerCase():""}le.default=Mt;var ce={};Object.defineProperty(ce,"__esModule",{value:!0});function jt(t){return t===void 0&&(t=""),t?String(t).replace(/^[^A-Za-z0-9]*|[^A-Za-z0-9]*$/g,"$").replace(/[^A-Za-z0-9]+/g,"$").replace(/([a-z])([A-Z])/g,function(e,r,n){return r+"$"+n}).toLowerCase().replace(/(\$)(\w?)/g,function(e,r,n){return n.toUpperCase()}):""}ce.default=jt;var Ne={};Object.defineProperty(Ne,"__esModule",{value:!0});function Rt(t){return t===void 0&&(t=""),t?String(t).replace(/^[^A-Za-z0-9]*|[^A-Za-z0-9]*$/g,"").replace(/([a-z])([A-Z])/g,function(e,r,n){return r+"_"+n.toLowerCase()}).replace(/[^A-Za-z0-9]+|_+/g,".").toLowerCase():""}Ne.default=Rt;var ze={};Object.defineProperty(ze,"__esModule",{value:!0});function Bt(t){return t===void 0&&(t=""),t?String(t).replace(/^[^A-Za-z0-9]*|[^A-Za-z0-9]*$/g,"").replace(/([a-z])([A-Z])/g,function(e,r,n){return r+"_"+n.toLowerCase()}).replace(/[^A-Za-z0-9]+|_+/g,"/").toLowerCase():""}ze.default=Bt;var Ee={};Object.defineProperty(Ee,"__esModule",{value:!0});function Dt(t){return t===void 0&&(t=""),t?String(t).replace(/^[^A-Za-z0-9]*|[^A-Za-z0-9]*$/g,"").replace(/([a-z])([A-Z])/g,function(e,r,n){return r+"_"+n.toLowerCase()}).replace(/[^A-Za-z0-9]+|_+/g," ").toLowerCase():""}Ee.default=Dt;var Ce={};Object.defineProperty(Ce,"__esModule",{value:!0});function kt(t){if(t===void 0&&(t=""),!t)return"";var e=String(t).replace(/^[^A-Za-z0-9]*|[^A-Za-z0-9]*$/g,"").replace(/([a-z])([A-Z])/g,function(r,n,s){return n+"_"+s.toLowerCase()}).replace(/[^A-Za-z0-9]+|_+/g," ").toLowerCase();return e.charAt(0).toUpperCase()+e.slice(1)}Ce.default=kt;var $e={};Object.defineProperty($e,"__esModule",{value:!0});function Lt(t){return t===void 0&&(t=""),t?String(t).replace(/^[^A-Za-z0-9]*|[^A-Za-z0-9]*$/g,"").replace(/([a-z])([A-Z])/g,function(e,r,n){return r+"_"+n.toLowerCase()}).replace(/[^A-Za-z0-9]+|_+/g," ").toLowerCase().replace(/( ?)(\w+)( ?)/g,function(e,r,n,s){return r+n.charAt(0).toUpperCase()+n.slice(1)+s}):""}$e.default=Lt;var fe={};Object.defineProperty(fe,"__esModule",{value:!0});function Pt(t){return t===void 0&&(t=""),t?String(t).replace(/^[^A-Za-z0-9]*|[^A-Za-z0-9]*$/g,"").replace(/([a-z])([A-Z])/g,function(e,r,n){return r+"_"+n.toLowerCase()}).replace(/[^A-Za-z0-9]+|_+/g,"-").toLowerCase():""}fe.default=Pt;var Ue={},V={};(function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.belongToTypes=t.isValidObject=t.isArrayObject=t.validateOptions=t.DefaultOption=void 0,t.DefaultOption={recursive:!1,recursiveInArray:!1,keepTypesOnRecursion:[]},t.validateOptions=function(e){return e===void 0&&(e=t.DefaultOption),e.recursive==null?e=t.DefaultOption:e.recursiveInArray==null&&(e.recursiveInArray=!1),e},t.isArrayObject=function(e){return e!=null&&Array.isArray(e)},t.isValidObject=function(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)},t.belongToTypes=function(e,r){return(r||[]).some(function(n){return e instanceof n})}})(V);var Zt=E&&E.__spreadArrays||function(){for(var t=0,e=0,r=arguments.length;e<r;e++)t+=arguments[e].length;for(var n=Array(t),s=0,e=0;e<r;e++)for(var a=arguments[e],u=0,c=a.length;u<c;u++,s++)n[s]=a[u];return n};Object.defineProperty(Ue,"__esModule",{value:!0});var M=V;function Q(t,e){if(e===void 0&&(e=M.DefaultOption),!M.isValidObject(t))return null;e=M.validateOptions(e);var r={};return Object.keys(t).forEach(function(n){var s=t[n],a=n.toLowerCase();e.recursive&&(M.isValidObject(s)?M.belongToTypes(s,e.keepTypesOnRecursion)||(s=Q(s,e)):e.recursiveInArray&&M.isArrayObject(s)&&(s=Zt(s).map(function(u){var c=u;if(M.isValidObject(u))M.belongToTypes(c,e.keepTypesOnRecursion)||(c=Q(u,e));else if(M.isArrayObject(u)){var h=Q({key:u},e);c=h.key}return c}))),r[a]=s}),r}Ue.default=Q;var xe={},Yt=E&&E.__spreadArrays||function(){for(var t=0,e=0,r=arguments.length;e<r;e++)t+=arguments[e].length;for(var n=Array(t),s=0,e=0;e<r;e++)for(var a=arguments[e],u=0,c=a.length;u<c;u++,s++)n[s]=a[u];return n};Object.defineProperty(xe,"__esModule",{value:!0});var j=V;function _(t,e){if(e===void 0&&(e=j.DefaultOption),!j.isValidObject(t))return null;e=j.validateOptions(e);var r={};return Object.keys(t).forEach(function(n){var s=t[n],a=n.toUpperCase();e.recursive&&(j.isValidObject(s)?j.belongToTypes(s,e.keepTypesOnRecursion)||(s=_(s,e)):e.recursiveInArray&&j.isArrayObject(s)&&(s=Yt(s).map(function(u){var c=u;if(j.isValidObject(u))j.belongToTypes(c,e.keepTypesOnRecursion)||(c=_(u,e));else if(j.isArrayObject(u)){var h=_({key:u},e);c=h.key}return c}))),r[a]=s}),r}xe.default=_;var Me={},Kt=E&&E.__spreadArrays||function(){for(var t=0,e=0,r=arguments.length;e<r;e++)t+=arguments[e].length;for(var n=Array(t),s=0,e=0;e<r;e++)for(var a=arguments[e],u=0,c=a.length;u<c;u++,s++)n[s]=a[u];return n};Object.defineProperty(Me,"__esModule",{value:!0});var R=V,Vt=ue;function ee(t,e){if(e===void 0&&(e=R.DefaultOption),!R.isValidObject(t))return null;e=R.validateOptions(e);var r={};return Object.keys(t).forEach(function(n){var s=t[n],a=Vt.default(n);e.recursive&&(R.isValidObject(s)?R.belongToTypes(s,e.keepTypesOnRecursion)||(s=ee(s,e)):e.recursiveInArray&&R.isArrayObject(s)&&(s=Kt(s).map(function(u){var c=u;if(R.isValidObject(u))R.belongToTypes(c,e.keepTypesOnRecursion)||(c=ee(u,e));else if(R.isArrayObject(u)){var h=ee({key:u},e);c=h.key}return c}))),r[a]=s}),r}Me.default=ee;var je={},Ft=E&&E.__spreadArrays||function(){for(var t=0,e=0,r=arguments.length;e<r;e++)t+=arguments[e].length;for(var n=Array(t),s=0,e=0;e<r;e++)for(var a=arguments[e],u=0,c=a.length;u<c;u++,s++)n[s]=a[u];return n};Object.defineProperty(je,"__esModule",{value:!0});var B=V,qt=le;function te(t,e){if(e===void 0&&(e=B.DefaultOption),!B.isValidObject(t))return null;e=B.validateOptions(e);var r={};return Object.keys(t).forEach(function(n){var s=t[n],a=qt.default(n);e.recursive&&(B.isValidObject(s)?B.belongToTypes(s,e.keepTypesOnRecursion)||(s=te(s,e)):e.recursiveInArray&&B.isArrayObject(s)&&(s=Ft(s).map(function(u){var c=u;if(B.isValidObject(u))B.belongToTypes(c,e.keepTypesOnRecursion)||(c=te(u,e));else if(B.isArrayObject(u)){var h=te({key:u},e);c=h.key}return c}))),r[a]=s}),r}je.default=te;var Re={},Wt=E&&E.__spreadArrays||function(){for(var t=0,e=0,r=arguments.length;e<r;e++)t+=arguments[e].length;for(var n=Array(t),s=0,e=0;e<r;e++)for(var a=arguments[e],u=0,c=a.length;u<c;u++,s++)n[s]=a[u];return n};Object.defineProperty(Re,"__esModule",{value:!0});var D=V,Gt=ce;function re(t,e){if(e===void 0&&(e=D.DefaultOption),!D.isValidObject(t))return null;e=D.validateOptions(e);var r={};return Object.keys(t).forEach(function(n){var s=t[n],a=Gt.default(n);e.recursive&&(D.isValidObject(s)?D.belongToTypes(s,e.keepTypesOnRecursion)||(s=re(s,e)):e.recursiveInArray&&D.isArrayObject(s)&&(s=Wt(s).map(function(u){var c=u;if(D.isValidObject(u))D.belongToTypes(c,e.keepTypesOnRecursion)||(c=re(u,e));else if(D.isArrayObject(u)){var h=re({key:u},e);c=h.key}return c}))),r[a]=s}),r}Re.default=re;var Be={},Ht=E&&E.__spreadArrays||function(){for(var t=0,e=0,r=arguments.length;e<r;e++)t+=arguments[e].length;for(var n=Array(t),s=0,e=0;e<r;e++)for(var a=arguments[e],u=0,c=a.length;u<c;u++,s++)n[s]=a[u];return n};Object.defineProperty(Be,"__esModule",{value:!0});var k=V,Xt=fe;function ne(t,e){if(e===void 0&&(e=k.DefaultOption),!k.isValidObject(t))return null;e=k.validateOptions(e);var r={};return Object.keys(t).forEach(function(n){var s=t[n],a=Xt.default(n);e.recursive&&(k.isValidObject(s)?k.belongToTypes(s,e.keepTypesOnRecursion)||(s=ne(s,e)):e.recursiveInArray&&k.isArrayObject(s)&&(s=Ht(s).map(function(u){var c=u;if(k.isValidObject(u))k.belongToTypes(c,e.keepTypesOnRecursion)||(c=ne(u,e));else if(k.isArrayObject(u)){var h=ne({key:u},e);c=h.key}return c}))),r[a]=s}),r}Be.default=ne;Object.defineProperty(d,"__esModule",{value:!0});d.kebabKeys=d.pascalKeys=d.snakeKeys=d.camelKeys=d.upperKeys=d.lowerKeys=d.toLowerCase=d.toUpperCase=d.toKebabCase=d.toHeaderCase=d.toSentenceCase=d.toTextCase=d.toPathCase=d.toDotCase=d.toPascalCase=d.toSnakeCase=d.toCamelCase=void 0;var Xe=ue;d.toCamelCase=Xe.default;var Je=le;d.toSnakeCase=Je.default;var Qe=ce;d.toPascalCase=Qe.default;var _e=Ne;d.toDotCase=_e.default;var et=ze;d.toPathCase=et.default;var tt=Ee;d.toTextCase=tt.default;var rt=Ce;d.toSentenceCase=rt.default;var nt=$e;d.toHeaderCase=nt.default;var st=fe;d.toKebabCase=st.default;var it=Ue;d.lowerKeys=it.default;var at=xe;d.upperKeys=at.default;var ot=Me;d.camelKeys=ot.default;var ut=je;d.snakeKeys=ut.default;var lt=Re;d.pascalKeys=lt.default;var ct=Be;d.kebabKeys=ct.default;var ft=function(t){return String(t||"").toLowerCase()};d.toLowerCase=ft;var dt=function(t){return String(t||"").toUpperCase()};d.toUpperCase=dt;var Jt={toCamelCase:Xe.default,toSnakeCase:Je.default,toPascalCase:Qe.default,toDotCase:_e.default,toPathCase:et.default,toTextCase:tt.default,toSentenceCase:rt.default,toHeaderCase:nt.default,toKebabCase:st.default,toUpperCase:dt,toLowerCase:ft,lowerKeys:it.default,upperKeys:at.default,camelKeys:ot.default,snakeKeys:ut.default,pascalKeys:lt.default,kebabKeys:ct.default};d.default=Jt;var ht=d;const pt={recursive:!0,recursiveInArray:!0,keepTypesOnRecursion:[Number,String,Uint8Array]},Qt=t=>ht.snakeKeys(t,pt),_t=t=>ht.camelKeys(t,pt),er=t=>t!=null&&typeof t=="object"&&!Array.isArray(t);var tr=Object.defineProperty,rr=(t,e,r)=>e in t?tr(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,ye=(t,e,r)=>(rr(t,typeof e!="symbol"?e+"":e,r),r);let nr=class{constructor(){ye(this,"contentType","application/json"),ye(this,"decoder"),ye(this,"encoder"),this.decoder=new TextDecoder,this.encoder=new TextEncoder}encode(e){return this.encoder.encode(this.encodeString(e)).buffer}decode(e,r){return this.decodeString(this.decoder.decode(e),r)}decodeString(e,r){const n=_t(JSON.parse(e));return r!=null?r.parse(n):n}encodeString(e){return JSON.stringify(Qt(e),(r,n)=>ArrayBuffer.isView(n)?Array.from(n):er(n)&&"encode_value"in n?typeof n.value=="bigint"?n.value.toString():n.value:typeof n=="bigint"?n.toString():n)}static registerCustomType(){}};new nr;const de=i.z.tuple([i.z.number(),i.z.number()]);i.z.tuple([i.z.bigint(),i.z.bigint()]);const yt=i.z.object({width:i.z.number(),height:i.z.number()}),sr=i.z.object({signedWidth:i.z.number(),signedHeight:i.z.number()}),ir=["width","height"];i.z.enum(ir);const ar=["start","center","end"],or=["signedWidth","signedHeight"];i.z.enum(or);const ae=i.z.object({x:i.z.number(),y:i.z.number()}),ur=i.z.object({clientX:i.z.number(),clientY:i.z.number()}),lr=["x","y"],gt=i.z.enum(lr),vt=["top","right","bottom","left"];i.z.enum(vt);const cr=["left","right"],Ot=i.z.enum(cr),fr=["top","bottom"],bt=i.z.enum(fr),wt=["center"],Ze=i.z.enum(wt),dr=[...vt,...wt],mt=i.z.enum(dr);i.z.enum(ar);const hr=["first","last"];i.z.enum(hr);const pr=i.z.object({lower:i.z.number(),upper:i.z.number()}),yr=i.z.object({lower:i.z.bigint(),upper:i.z.bigint()});i.z.union([pr,de]);i.z.union([yr,de]);i.z.union([gt,mt]);i.z.union([gt,mt,i.z.instanceof(String)]);const ge=(t,e)=>{const r={};if(typeof t=="number"||typeof t=="bigint")e!=null?(r.lower=t,r.upper=e):(r.lower=typeof t=="bigint"?0n:0,r.upper=t);else if(Array.isArray(t)){if(t.length!==2)throw new Error("bounds: expected array of length 2");[r.lower,r.upper]=t}else return Ye(t);return Ye(r)},Ye=t=>t.lower>t.upper?{lower:t.upper,upper:t.lower}:t;i.z.object({x:Ot.or(Ze),y:bt.or(Ze)});const gr=i.z.object({x:Ot,y:bt}),vr=Object.freeze({x:"left",y:"top"}),Or=(t,e)=>t.x===e.x&&t.y===e.y,Ke=i.z.union([i.z.number(),ae,de,yt,sr,ur]),br=(t,e)=>{if(typeof t=="string"){if(e===void 0)throw new Error("The y coordinate must be given.");return t==="x"?{x:e,y:0}:{x:0,y:e}}return typeof t=="number"?{x:t,y:e??t}:Array.isArray(t)?{x:t[0],y:t[1]}:"signedWidth"in t?{x:t.signedWidth,y:t.signedHeight}:"clientX"in t?{x:t.clientX,y:t.clientY}:"width"in t?{x:t.width,y:t.height}:{x:t.x,y:t.y}},Ve=Object.freeze({x:0,y:0}),X=i.z.union([i.z.number(),i.z.string()]);i.z.object({top:X,left:X,width:X,height:X});i.z.object({left:i.z.number(),top:i.z.number(),right:i.z.number(),bottom:i.z.number()});i.z.object({one:ae,two:ae,root:gr});const De=(t,e,r=0,n=0,s)=>{const a={one:{...Ve},two:{...Ve},root:s??vr};if(typeof t=="number"){if(typeof e!="number")throw new Error("Box constructor called with invalid arguments");return a.one={x:t,y:e},a.two={x:a.one.x+r,y:a.one.y+n},a}return"one"in t&&"two"in t&&"root"in t?{...t,root:s??t.root}:("getBoundingClientRect"in t&&(t=t.getBoundingClientRect()),"left"in t?(a.one={x:t.left,y:t.top},a.two={x:t.right,y:t.bottom},a):(a.one=t,e==null?a.two={x:a.one.x+r,y:a.one.y+n}:typeof e=="number"?a.two={x:a.one.x+e,y:a.one.y+r}:"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))},ve=t=>{const e=De(t);return{lower:e.one.x,upper:e.two.x}},Oe=t=>{const e=De(t);return{lower:e.one.y,upper:e.two.y}},wr=t=>typeof t!="object"||t==null?!1:"one"in t&&"two"in t&&"root"in t;var mr=Object.defineProperty,Tr=(t,e,r)=>e in t?mr(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,P=(t,e,r)=>(Tr(t,typeof e!="symbol"?e+"":e,r),r);const Sr=(t,e,r)=>(e!=null&&(t=Math.max(t,e)),r!=null&&(t=Math.min(t,r)),t);i.z.object({offset:Ke,scale:Ke});const Ar=t=>(e,r,n,s)=>r==="dimension"?[e,n]:[e,s?n-t:n+t],Ir=t=>(e,r,n,s)=>[e,s?n/t:n*t],Nr=t=>(e,r,n)=>{if(e===null)return[t,n];const{lower:s,upper:a}=e,{lower:u,upper:c}=t,h=a-s,z=c-u;if(r==="dimension")return[t,n*(z/h)];const A=(n-s)*(z/h)+u;return[t,A]},zr=t=>(e,r,n)=>[t,n],Er=()=>(t,e,r)=>{if(t===null)throw new Error("cannot invert without bounds");if(e==="dimension")return[t,r];const{lower:n,upper:s}=t;return[t,s-(r-n)]},Cr=t=>(e,r,n)=>{const{lower:s,upper:a}=t;return n=Sr(n,s,a),[e,n]},me=class W{constructor(){P(this,"ops",[]),P(this,"currBounds",null),P(this,"currType",null),P(this,"reversed",!1),this.ops=[]}static translate(e){return new W().translate(e)}static magnify(e){return new W().magnify(e)}static scale(e,r){return new W().scale(e,r)}translate(e){const r=this.new(),n=Ar(e);return n.type="translate",r.ops.push(n),r}magnify(e){const r=this.new(),n=Ir(e);return n.type="magnify",r.ops.push(n),r}scale(e,r){const n=ge(e,r),s=this.new(),a=Nr(n);return a.type="scale",s.ops.push(a),s}clamp(e,r){const n=ge(e,r),s=this.new(),a=Cr(n);return a.type="clamp",s.ops.push(a),s}reBound(e,r){const n=ge(e,r),s=this.new(),a=zr(n);return a.type="re-bound",s.ops.push(a),s}invert(){const e=Er();e.type="invert";const r=this.new();return r.ops.push(e),r}pos(e){return this.exec("position",e)}dim(e){return this.exec("dimension",e)}new(){const e=new W;return e.ops=this.ops.slice(),e.reversed=this.reversed,e}exec(e,r){return this.currBounds=null,this.ops.reduce(([n,s],a)=>a(n,e,s,this.reversed),[null,r])[1]}reverse(){const e=this.new();e.ops.reverse();const r=[];return e.ops.forEach((n,s)=>{if(n.type==="scale"||r.some(([u,c])=>s>=u&&s<=c))return;const a=e.ops.findIndex((u,c)=>u.type==="scale"&&c>s);a!==-1&&r.push([s,a])}),r.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}};P(me,"IDENTITY",new me);let Fe=me;const qe=class L{constructor(e=new Fe,r=new Fe,n=null){P(this,"x"),P(this,"y"),P(this,"currRoot"),this.x=e,this.y=r,this.currRoot=n}static translate(e,r){return new L().translate(e,r)}static translateX(e){return new L().translateX(e)}static translateY(e){return new L().translateY(e)}static clamp(e){return new L().clamp(e)}static magnify(e){return new L().magnify(e)}static scale(e){return new L().scale(e)}static reBound(e){return new L().reBound(e)}translate(e,r){const n=br(e,r),s=this.copy();return s.x=this.x.translate(n.x),s.y=this.y.translate(n.y),s}translateX(e){const r=this.copy();return r.x=this.x.translate(e),r}translateY(e){const r=this.copy();return r.y=this.y.translate(e),r}magnify(e){const r=this.copy();return r.x=this.x.magnify(e.x),r.y=this.y.magnify(e.y),r}scale(e){const r=this.copy();if(wr(e)){const n=this.currRoot;return r.currRoot=e.root,n!=null&&!Or(n,e.root)&&(n.x!==e.root.x&&(r.x=r.x.invert()),n.y!==e.root.y&&(r.y=r.y.invert())),r.x=r.x.scale(ve(e)),r.y=r.y.scale(Oe(e)),r}return r.x=r.x.scale(e.width),r.y=r.y.scale(e.height),r}reBound(e){const r=this.copy();return r.x=this.x.reBound(ve(e)),r.y=this.y.reBound(Oe(e)),r}clamp(e){const r=this.copy();return r.x=this.x.clamp(ve(e)),r.y=this.y.clamp(Oe(e)),r}copy(){const e=new L;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 De(this.pos(e.one),this.pos(e.two),0,0,this.currRoot??e.root)}};P(qe,"IDENTITY",new qe);i.z.record(i.z.union([i.z.number(),i.z.string(),i.z.symbol()]),i.z.unknown());const Tt=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser",$r=Tt(),St=["MacOS","Windows","Linux","Docker"],Ur=i.z.enum(St);let be;const xr=()=>{if(typeof window>"u")return;const t=window.navigator.userAgent.toLowerCase();if(t.includes("mac"))return"MacOS";if(t.includes("win"))return"Windows";if(t.includes("linux"))return"Linux"},Mr=(t={})=>{const{force:e,default:r}=t;return e??be??(be=xr(),be??r)},At=Object.freeze(Object.defineProperty({__proto__:null,OPERATING_SYSTEMS:St,RUNTIME:$r,detect:Tt,getOS:Mr,osZ:Ur},Symbol.toStringTag,{value:"Module"})),jr=i.z.object({signedWidth:i.z.number(),signedHeight:i.z.number()});i.z.union([yt,jr,ae,de]);var Rr=Object.defineProperty,Br=(t,e,r)=>e in t?Rr(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,l=(t,e,r)=>(Br(t,typeof e!="symbol"?e+"":e,r),r);const It=(t,e)=>{const r=new m(e);if(![T.DAY,T.HOUR,T.MINUTE,T.SECOND,T.MILLISECOND,T.MICROSECOND,T.NANOSECOND].some(s=>s.equals(r)))throw new Error("Invalid argument for remainder. Must be an even TimeSpan or Timestamp");const n=t.valueOf()%r.valueOf();return t instanceof m?new m(n):new T(n)},y=class f{constructor(e,r="UTC"){if(l(this,"value"),l(this,"encodeValue",!0),e==null)this.value=f.now().valueOf();else if(e instanceof Date)this.value=BigInt(e.getTime())*f.MILLISECOND.valueOf();else if(typeof e=="string")this.value=f.parseDateTimeString(e,r).valueOf();else if(Array.isArray(e))this.value=f.parseDate(e);else{let n=BigInt(0);e instanceof Number&&(e=e.valueOf()),r==="local"&&(n=f.utcOffset.valueOf()),typeof e=="number"&&(isFinite(e)?e=Math.trunc(e):(isNaN(e)&&(e=0),e===1/0?e=f.MAX:e=f.MIN)),this.value=BigInt(e.valueOf())+n}}static parseDate([e=1970,r=1,n=1]){const s=new Date(e,r-1,n,0,0,0,0);return new f(BigInt(s.getTime())*f.MILLISECOND.valueOf()).truncate(f.DAY).valueOf()}encode(){return this.value.toString()}valueOf(){return this.value}static parseTimeString(e,r="UTC"){const[n,s,a]=e.split(":");let u="00",c="00";a!=null&&([u,c]=a.split("."));let h=f.hours(parseInt(n??"00",10)).add(f.minutes(parseInt(s??"00",10))).add(f.seconds(parseInt(u??"00",10))).add(f.milliseconds(parseInt(c??"00",10)));return r==="local"&&(h=h.add(f.utcOffset)),h.valueOf()}static parseDateTimeString(e,r="UTC"){if(!e.includes("/")&&!e.includes("-"))return f.parseTimeString(e,r);const n=new Date(e);return e.includes(":")||n.setUTCHours(0,0,0,0),new f(BigInt(n.getTime())*f.MILLISECOND.valueOf(),r).valueOf()}fString(e="ISO",r="UTC"){switch(e){case"ISODate":return this.toISOString(r).slice(0,10);case"ISOTime":return this.toISOString(r).slice(11,23);case"time":return this.timeString(!1,r);case"preciseTime":return this.timeString(!0,r);case"date":return this.dateString();case"preciseDate":return`${this.dateString()} ${this.timeString(!0,r)}`;case"dateTime":return`${this.dateString()} ${this.timeString(!1,r)}`;default:return this.toISOString(r)}}toISOString(e="UTC"){return e==="UTC"?this.date().toISOString():this.sub(f.utcOffset).date().toISOString()}timeString(e=!1,r="UTC"){const n=this.toISOString(r);return e?n.slice(11,23):n.slice(11,19)}dateString(){const e=this.date(),r=e.toLocaleString("default",{month:"short"}),n=e.toLocaleString("default",{day:"numeric"});return`${r} ${n}`}static get utcOffset(){return new T(BigInt(new Date().getTimezoneOffset())*f.MINUTE.valueOf())}static since(e){return new f().span(e)}date(){return new Date(this.milliseconds())}equals(e){return this.valueOf()===new f(e).valueOf()}span(e){return this.range(e).span}range(e){return new Dr(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 f(e).valueOf()}afterEq(e){return this.valueOf()>=new f(e).valueOf()}before(e){return this.valueOf()<new f(e).valueOf()}beforeEq(e){return this.valueOf()<=new f(e).valueOf()}add(e){return new f(this.valueOf()+BigInt(e.valueOf()))}sub(e){return new f(this.valueOf()-BigInt(e.valueOf()))}milliseconds(){return Number(this.valueOf())/Number(f.MILLISECOND.valueOf())}toString(){return this.date().toISOString()}remainder(e){return It(this,e)}get isToday(){return this.truncate(T.DAY).equals(f.now().truncate(T.DAY))}truncate(e){return this.sub(this.remainder(e))}static now(){return new f(new Date)}static max(...e){let r=f.MIN;for(const n of e){const s=new f(n);s.after(r)&&(r=s)}return r}static min(...e){let r=f.MAX;for(const n of e){const s=new f(n);s.before(r)&&(r=s)}return r}static nanoseconds(e){return new f(e)}static microseconds(e){return f.nanoseconds(e*1e3)}static milliseconds(e){return f.microseconds(e*1e3)}static seconds(e){return f.milliseconds(e*1e3)}static minutes(e){return f.seconds(e*60)}static hours(e){return f.minutes(e*60)}static days(e){return f.hours(e*24)}};l(y,"NANOSECOND",y.nanoseconds(1)),l(y,"MICROSECOND",y.microseconds(1)),l(y,"MILLISECOND",y.milliseconds(1)),l(y,"SECOND",y.seconds(1)),l(y,"MINUTE",y.minutes(1)),l(y,"HOUR",y.hours(1)),l(y,"DAY",y.days(1)),l(y,"MAX",new y((1n<<63n)-1n)),l(y,"MIN",new y(0)),l(y,"ZERO",new y(0)),l(y,"z",i.z.union([i.z.object({value:i.z.bigint()}).transform(t=>new y(t.value)),i.z.string().transform(t=>new y(BigInt(t))),i.z.instanceof(Number).transform(t=>new y(t)),i.z.number().transform(t=>new y(t)),i.z.instanceof(y)]));let m=y;const g=class p{constructor(e){l(this,"value"),l(this,"encodeValue",!0),typeof e=="number"&&(e=Math.trunc(e.valueOf())),this.value=BigInt(e.valueOf())}encode(){return this.value.toString()}valueOf(){return this.value}lessThan(e){return this.valueOf()<new p(e).valueOf()}greaterThan(e){return this.valueOf()>new p(e).valueOf()}lessThanOrEqual(e){return this.valueOf()<=new p(e).valueOf()}greaterThanOrEqual(e){return this.valueOf()>=new p(e).valueOf()}remainder(e){return It(this,e)}truncate(e){return new p(BigInt(Math.trunc(Number(this.valueOf()/e.valueOf())))*e.valueOf())}toString(){const e=this.truncate(p.DAY),r=this.truncate(p.HOUR),n=this.truncate(p.MINUTE),s=this.truncate(p.SECOND),a=this.truncate(p.MILLISECOND),u=this.truncate(p.MICROSECOND),c=this.truncate(p.NANOSECOND),h=e,z=r.sub(e),A=n.sub(r),O=s.sub(n),C=a.sub(s),q=u.sub(a),x=c.sub(u);let N="";return h.isZero||(N+=`${h.days}d `),z.isZero||(N+=`${z.hours}h `),A.isZero||(N+=`${A.minutes}m `),O.isZero||(N+=`${O.seconds}s `),C.isZero||(N+=`${C.milliseconds}ms `),q.isZero||(N+=`${q.microseconds}µs `),x.isZero||(N+=`${x.nanoseconds}ns`),N.trim()}get days(){return Number(this.valueOf())/Number(p.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(p.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(p.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(p.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(p.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(p.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get isZero(){return this.valueOf()===BigInt(0)}equals(e){return this.valueOf()===new p(e).valueOf()}add(e){return new p(this.valueOf()+new p(e).valueOf())}sub(e){return new p(this.valueOf()-new p(e).valueOf())}static nanoseconds(e=1){return new p(e)}static microseconds(e=1){return p.nanoseconds(e*1e3)}static milliseconds(e=1){return p.microseconds(e*1e3)}static seconds(e=1){return p.milliseconds(e*1e3)}static minutes(e){return p.seconds(e.valueOf()*60)}static hours(e){return p.minutes(e*60)}static days(e){return p.hours(e*24)}};l(g,"NANOSECOND",g.nanoseconds(1)),l(g,"MICROSECOND",g.microseconds(1)),l(g,"MILLISECOND",g.milliseconds(1)),l(g,"SECOND",g.seconds(1)),l(g,"MINUTE",g.minutes(1)),l(g,"HOUR",g.hours(1)),l(g,"DAY",g.days(1)),l(g,"MAX",new g((1n<<63n)-1n)),l(g,"MIN",new g(0)),l(g,"ZERO",new g(0)),l(g,"z",i.z.union([i.z.object({value:i.z.bigint()}).transform(t=>new g(t.value)),i.z.string().transform(t=>new g(BigInt(t))),i.z.instanceof(Number).transform(t=>new g(t)),i.z.number().transform(t=>new g(t)),i.z.instanceof(g)]));let T=g;const J=class se extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new se(e).valueOf()}get period(){return T.seconds(1/this.valueOf())}sampleCount(e){return new T(e).seconds*this.valueOf()}byteCount(e,r){return this.sampleCount(e)*new I(r).valueOf()}span(e){return T.seconds(e/this.valueOf())}byteSpan(e,r){return this.span(e.valueOf()/r.valueOf())}static hz(e){return new se(e)}static khz(e){return se.hz(e*1e3)}};l(J,"z",i.z.union([i.z.number().transform(t=>new J(t)),i.z.instanceof(Number).transform(t=>new J(t)),i.z.instanceof(J)]));const w=class extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}length(e){return e.valueOf()/this.valueOf()}size(e){return new kr(e*this.valueOf())}};l(w,"UNKNOWN",new w(0)),l(w,"BIT128",new w(16)),l(w,"BIT64",new w(8)),l(w,"BIT32",new w(4)),l(w,"BIT16",new w(2)),l(w,"BIT8",new w(1)),l(w,"z",i.z.union([i.z.number().transform(t=>new w(t)),i.z.instanceof(Number).transform(t=>new w(t)),i.z.instanceof(w)]));let I=w;const $=class ie{constructor(e,r){l(this,"start"),l(this,"end"),typeof e=="object"&&"start"in e?(this.start=new m(e.start),this.end=new m(e.end)):(this.start=new m(e),this.end=new m(r))}get span(){return new T(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}swap(){return new ie(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,r=T.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=m.max(n.start,e.start),a=m.min(n.end,e.end);return a.before(s)?!1:new T(a.sub(s)).greaterThanOrEqual(r)}roughlyEquals(e,r){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<=r.valueOf()&&s<=r.valueOf()}contains(e){return e instanceof ie?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const r=new ie(this.start,this.end);return e.start.after(this.start)&&(r.start=e.start),e.start.after(this.end)&&(r.end=e.start),e.end.before(this.end)&&(r.end=e.end),e.end.before(this.start)&&(r.start=e.end),r}};l($,"MAX",new $(m.MIN,m.MAX)),l($,"MIN",new $(m.MAX,m.MIN)),l($,"ZERO",new $(m.ZERO,m.ZERO)),l($,"z",i.z.union([i.z.object({start:m.z,end:m.z}).transform(t=>new $(t.start,t.end)),i.z.instanceof($)]));let Dr=$;const o=class U extends String{constructor(e){if(e instanceof U||typeof e=="string"||typeof e.valueOf()=="string"){super(e.valueOf());return}else{const r=U.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);if(r!=null){super(r.valueOf());return}}throw super(U.UNKNOWN.valueOf()),new Error(`unable to find data type for ${e.toString()}`)}get Array(){const e=U.ARRAY_CONSTRUCTORS.get(this.toString());if(e==null)throw new Error(`unable to find array constructor for ${this.valueOf()}`);return e}equals(e){return this.valueOf()===e.valueOf()}toString(){return this.valueOf()}get isVariable(){return this.equals(U.JSON)||this.equals(U.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(U.UUID)}get isInteger(){return this.toString().startsWith("int")}get isFloat(){return this.toString().startsWith("float")}get density(){const e=U.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}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 U.BIG_INT_TYPES.some(e=>e.equals(this))}};l(o,"UNKNOWN",new o("unknown")),l(o,"FLOAT64",new o("float64")),l(o,"FLOAT32",new o("float32")),l(o,"INT64",new o("int64")),l(o,"INT32",new o("int32")),l(o,"INT16",new o("int16")),l(o,"INT8",new o("int8")),l(o,"UINT64",new o("uint64")),l(o,"UINT32",new o("uint32")),l(o,"UINT16",new o("uint16")),l(o,"UINT8",new o("uint8")),l(o,"BOOLEAN",o.UINT8),l(o,"TIMESTAMP",new o("timestamp")),l(o,"UUID",new o("uuid")),l(o,"STRING",new o("string")),l(o,"JSON",new o("json")),l(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]])),l(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]])),l(o,"DENSITIES",new Map([[o.UINT8.toString(),I.BIT8],[o.UINT16.toString(),I.BIT16],[o.UINT32.toString(),I.BIT32],[o.UINT64.toString(),I.BIT64],[o.FLOAT32.toString(),I.BIT32],[o.FLOAT64.toString(),I.BIT64],[o.INT8.toString(),I.BIT8],[o.INT16.toString(),I.BIT16],[o.INT32.toString(),I.BIT32],[o.INT64.toString(),I.BIT64],[o.TIMESTAMP.toString(),I.BIT64],[o.STRING.toString(),I.UNKNOWN],[o.JSON.toString(),I.UNKNOWN],[o.UUID.toString(),I.BIT128]])),l(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]),l(o,"BIG_INT_TYPES",[o.INT64,o.UINT64,o.TIMESTAMP]),l(o,"z",i.z.union([i.z.string().transform(t=>new o(t)),i.z.instanceof(o)]));const S=class b extends Number{constructor(e){super(e.valueOf())}largerThan(e){return this.valueOf()>e.valueOf()}smallerThan(e){return this.valueOf()<e.valueOf()}add(e){return b.bytes(this.valueOf()+e.valueOf())}sub(e){return b.bytes(this.valueOf()-e.valueOf())}truncate(e){return new b(Math.trunc(this.valueOf()/e.valueOf())*e.valueOf())}remainder(e){return b.bytes(this.valueOf()%e.valueOf())}get gigabytes(){return this.valueOf()/b.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/b.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/b.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/b.TERABYTE.valueOf()}toString(){const e=this.truncate(b.TERABYTE),r=this.truncate(b.GIGABYTE),n=this.truncate(b.MEGABYTE),s=this.truncate(b.KILOBYTE),a=this.truncate(b.BYTE),u=e,c=r.sub(e),h=n.sub(r),z=s.sub(n),A=a.sub(s);let O="";return u.isZero||(O+=`${u.terabytes}TB `),c.isZero||(O+=`${c.gigabytes}GB `),h.isZero||(O+=`${h.megabytes}MB `),z.isZero||(O+=`${z.kilobytes}KB `),(!A.isZero||O==="")&&(O+=`${A.valueOf()}B`),O.trim()}static bytes(e=1){return new b(e)}static kilobytes(e=1){return b.bytes(e.valueOf()*1e3)}static megabytes(e=1){return b.kilobytes(e.valueOf()*1e3)}static gigabytes(e=1){return b.megabytes(e.valueOf()*1e3)}static terabytes(e){return b.gigabytes(e.valueOf()*1e3)}get isZero(){return this.valueOf()===0}};l(S,"BYTE",new S(1)),l(S,"KILOBYTE",S.kilobytes(1)),l(S,"MEGABYTE",S.megabytes(1)),l(S,"GIGABYTE",S.gigabytes(1)),l(S,"TERABYTE",S.terabytes(1)),l(S,"ZERO",new S(0)),l(S,"z",i.z.union([i.z.number().transform(t=>new S(t)),i.z.instanceof(S)]));let kr=S;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)]);var Lr=Object.defineProperty,Pr=(t,e,r)=>e in t?Lr(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,G=(t,e,r)=>(Pr(t,typeof e!="symbol"?e+"":e,r),r);const Zr=(...t)=>t.map(Nt).join(""),Nt=t=>(t.endsWith("/")||(t+="/"),t.startsWith("/")&&(t=t.slice(1)),t),Yr=t=>t.endsWith("/")?t.slice(0,-1):t,Kr=(t,e="")=>t===null?"":"?"+Object.entries(t).filter(([,r])=>r==null?!1:Array.isArray(r)?r.length>0:!0).map(([r,n])=>`${e}${r}=${n}`).join("&"),Te=class Se{constructor({host:e,port:r,protocol:n="",pathPrefix:s=""}){G(this,"protocol"),G(this,"host"),G(this,"port"),G(this,"path"),this.protocol=n,this.host=e,this.port=r,this.path=Nt(s)}replace(e){return new Se({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new Se({...this,pathPrefix:Zr(this.path,e)})}toString(){return Yr(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}};G(Te,"UNKNOWN",new Te({host:"unknown",port:0}));let Vr=Te;var Fr=Object.defineProperty,qr=(t,e,r)=>e in t?Fr(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,we=(t,e,r)=>(qr(t,typeof e!="symbol"?e+"":e,r),r);const F=class extends Number{};we(F,"Absolute",255),we(F,"Default",1),we(F,"z",i.z.union([i.z.instanceof(F),i.z.number().int().min(0).max(255).transform(t=>new F(t)),i.z.instanceof(Number).transform(t=>new F(t))]));i.z.object({name:i.z.string(),key:i.z.string()});const Wr=i.z.string().regex(/^\d+\.\d+\.\d+$/);i.z.object({version:Wr});class H extends Error{constructor(r,n){super(r);v(this,"discriminator","FreighterError");v(this,"type");this.type=n}}const Gr=t=>{if(t==null||typeof t!="object")return!1;const e=t;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},Ae="unknown",We="nil",he="freighter",ke=i.z.object({type:i.z.string(),data:i.z.string()});class Hr{constructor(){v(this,"providers",[])}register(e){this.providers.push(e)}encode(e){if(e==null)return{type:We,data:""};if(Gr(e))for(const r of this.providers){const n=r.encode(e);if(n!=null)return n}return{type:Ae,data:JSON.stringify(e)}}decode(e){if(e==null||e.type===We)return null;if(e.type===Ae)return new Ge(e.data);for(const r of this.providers){const n=r.decode(e);if(n!=null)return n}return new Ge(e.data)}}const Le=new Hr,zt=({encode:t,decode:e})=>Le.register({encode:t,decode:e}),Xr=t=>Le.encode(t),Pe=t=>Le.decode(t);class Ge extends H{constructor(e){super(e,Ae)}}const pe="freighter.";class Z extends H{constructor(){super("EOF",he)}}v(Z,"TYPE",pe+"eof");class Y extends H{constructor(){super("StreamClosed",he)}}v(Y,"TYPE",pe+"stream_closed");class K extends H{constructor(r={}){const{message:n="Unreachable",url:s=Vr.UNKNOWN}=r;super(n,he);v(this,"url");this.url=s}}v(K,"TYPE",pe+"unreachable");const Jr=t=>{if(t.type!==he)return null;if(t instanceof Z)return{type:Z.TYPE,data:"EOF"};if(t instanceof Y)return{type:Y.TYPE,data:"StreamClosed"};if(t instanceof K)return{type:K.TYPE,data:"Unreachable"};throw new Error(`Unknown error type: ${t.type}: ${t.message}`)},Qr=t=>{if(!t.type.startsWith(pe))return null;switch(t.type){case Z.TYPE:return new Z;case Y.TYPE:return new Y;case K.TYPE:return new K;default:throw new Error(`Unknown error type: ${t.data}`)}};zt({encode:Jr,decode:Qr});class Et{constructor(){v(this,"middleware",[])}use(...e){this.middleware.push(...e)}async executeMiddleware(e,r){let n=0;const s=async a=>{if(n===this.middleware.length)return await r(a);const u=this.middleware[n];return n++,await u(a,s)};return await s(e)}}const Ct="Content-Type",He=t=>{if(At.RUNTIME!=="node")return fetch;const e=require("node-fetch");if(t==="http")return e;const r=require("https"),n=new r.Agent({rejectUnauthorized:!1});return async(s,a)=>await e(s,{...a,agent:n})};class _r extends Et{constructor(r,n,s=!1){super();v(this,"endpoint");v(this,"encoder");v(this,"fetch");return this.endpoint=r.replace({protocol:s?"https":"http"}),this.encoder=n,this.fetch=He(this.endpoint.protocol),new Proxy(this,{get:(a,u,c)=>u==="endpoint"?this.endpoint:Reflect.get(a,u,c)})}get headers(){return{[Ct]:this.encoder.contentType}}async send(r,n,s,a){n=s==null?void 0:s.parse(n);let u=null;const c=this.endpoint.child(r),h={};h.method="POST",h.body=this.encoder.encode(n??{});const[,z]=await this.executeMiddleware({target:c.toString(),protocol:this.endpoint.protocol,params:{},role:"client"},async A=>{const O={...A,params:{}};h.headers={...this.headers,...A.params};let C;try{C=await He(A.protocol)(A.target,h)}catch(x){let N=x;return N.message==="Load failed"&&(N=new K({url:c})),[O,N]}const q=await C.arrayBuffer();if(C!=null&&C.ok)return a!=null&&(u=this.encoder.decode(q,a)),[O,null];try{if(C.status!==400)return[O,new Error(C.statusText)];const x=this.encoder.decode(q,ke),N=Pe(x);return[O,N]}catch(x){return[O,new Error(`[freighter] - failed to decode error: ${C.statusText}: ${x.message}`)]}});return[u,z]}}const en=async(t,e,r,n,s)=>{const[a,u]=await t.send(e,r,n,s);if(u!=null)throw u;return a},tn=()=>At.RUNTIME!=="node"?t=>new WebSocket(t):t=>new(require("ws")).WebSocket(t,{rejectUnauthorized:!1}),rn=i.z.object({type:i.z.union([i.z.literal("data"),i.z.literal("close")]),payload:i.z.unknown().optional(),error:i.z.optional(ke)});class nn{constructor(e,r,n,s){v(this,"encoder");v(this,"reqSchema");v(this,"resSchema");v(this,"ws");v(this,"serverClosed");v(this,"sendClosed");v(this,"receiveDataQueue",[]);v(this,"receiveCallbacksQueue",[]);this.encoder=r,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 Z;if(this.sendClosed)throw new Y;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=Pe(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((r,n)=>this.receiveCallbacksQueue.push({resolve:r,reject:n}))}addMessage(e){const r=this.receiveCallbacksQueue.shift();r!=null?r.resolve(e):this.receiveDataQueue.push(e)}listenForMessages(){this.ws.onmessage=e=>this.addMessage(this.encoder.decode(e.data,rn)),this.ws.onclose=e=>this.addMessage({type:"close",error:{type:ln(e)?Z.TYPE:Y.TYPE,data:""}})}}const sn="freighterctx",an=1e3,on=1001,un=[an,on],ln=t=>un.includes(t.code),oe=class oe extends Et{constructor(r,n,s=!1){super();v(this,"baseUrl");v(this,"encoder");this.baseUrl=r.replace({protocol:s?"wss":"ws"}),this.encoder=n}async stream(r,n,s){const a=tn();let u;const[,c]=await this.executeMiddleware({target:r,protocol:"websocket",params:{},role:"client"},async h=>{const z=a(this.buildURL(r,h)),A={...h,params:{}};z.binaryType=oe.MESSAGE_TYPE;const O=await this.wrapSocket(z,n,s);return O instanceof Error?[A,O]:(u=O,[A,null])});if(c!=null)throw c;return u}buildURL(r,n){const s=Kr({[Ct]:this.encoder.contentType,...n.params},sn);return this.baseUrl.child(r).toString()+s}async wrapSocket(r,n,s){return await new Promise(a=>{r.onopen=()=>{a(new nn(r,this.encoder,n,s))},r.onerror=u=>{const c=u;a(new Error(c.message))}})}};v(oe,"MESSAGE_TYPE","arraybuffer");let Ie=oe;exports.BaseTypedError=H;exports.EOF=Z;exports.HTTPClient=_r;exports.StreamClosed=Y;exports.Unreachable=K;exports.WebSocketClient=Ie;exports.decodeError=Pe;exports.encodeError=Xr;exports.errorZ=ke;exports.registerError=zt;exports.sendRequired=en;
1
+ "use strict";var Ze=Object.defineProperty;var He=(r,e,t)=>e in r?Ze(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var f=(r,e,t)=>He(r,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("zod"),Ve=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:e[0].toLowerCase()+e.slice(1)},Ae=r=>{const e=(t,n=ae)=>{if(typeof t=="string")return r(t);if(Array.isArray(t))return t.map(a=>e(a,n));if(!re(t))return null;n=Qe(n);const i={};return Object.keys(t).forEach(a=>{let c=t[a];const h=r(a);n.recursive&&(re(c)?we(c,n.keepTypesOnRecursion)||(c=e(c,n)):n.recursiveInArray&&ge(c)&&(c=[...c].map(p=>{let m=p;return re(p)?we(m,n.keepTypesOnRecursion)||(m=e(p,n)):ge(p)&&(m=e({key:p},n).key),m}))),i[h]=c}),i};return e},Ke=Ae(Ve),Xe=r=>r.replace(/([a-z0-9])([A-Z])/g,(e,t,n)=>`${t}_${n.toLowerCase()}`),Je=Ae(Xe),ae={recursive:!0,recursiveInArray:!0,keepTypesOnRecursion:[Number,String,Uint8Array]},Qe=(r=ae)=>(r.recursive==null?r=ae:r.recursiveInArray==null&&(r.recursiveInArray=!1),r),ge=r=>r!=null&&Array.isArray(r),re=r=>r!=null&&typeof r=="object"&&!Array.isArray(r),we=(r,e)=>(e||[]).some(t=>r instanceof t),$e=r=>r!=null&&typeof r=="object"&&!Array.isArray(r);var _e=Object.defineProperty,et=(r,e,t)=>e in r?_e(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,G=(r,e,t)=>et(r,typeof e!="symbol"?e+"":e,t);let tt=class{constructor(){G(this,"contentType","application/json"),G(this,"decoder"),G(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),i=Ke(n);return t!=null?t.parse(i):i}encodeString(e){const t=Je(e);return JSON.stringify(t,(n,i)=>ArrayBuffer.isView(i)?Array.from(i):$e(i)&&"encode_value"in i?typeof i.value=="bigint"?i.value.toString():i.value:typeof i=="bigint"?i.toString():i)}static registerCustomType(){}},rt=class{constructor(){G(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||!$e(e[0]))throw new Error("Payload must be an array of objects");const t=Object.keys(e[0]),n=[t.join(",")];return e.forEach(i=>{const a=t.map(c=>JSON.stringify(i[c]??""));n.push(a.join(","))}),n.join(`
2
+ `)}decodeString(e,t){const[n,...i]=e.trim().split(`
3
+ `).map(h=>h.trim());if(n.length===0)return t!=null?t.parse({}):{};const a=n.split(",").map(h=>h.trim()),c={};return a.forEach(h=>{c[h]=[]}),i.forEach(h=>{const p=h.split(",").map(m=>m.trim());a.forEach((m,v)=>{const w=this.parseValue(p[v]);w!=null&&c[m].push(w)})}),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(){}},nt=class{constructor(){G(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}};new tt;new rt;new nt;const _=s.z.tuple([s.z.number(),s.z.number()]);s.z.tuple([s.z.bigint(),s.z.bigint()]);const xe=s.z.object({width:s.z.number(),height:s.z.number()}),st=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()}),it=["width","height"];s.z.enum(it);const ot=["start","center","end"],at=["signedWidth","signedHeight"];s.z.enum(at);const J=s.z.object({x:s.z.number(),y:s.z.number()}),ut=s.z.object({clientX:s.z.number(),clientY:s.z.number()}),ct=["x","y"],Ue=s.z.enum(ct),Me=["top","right","bottom","left"];s.z.enum(Me);const lt=["left","right"],Ce=s.z.enum(lt),ht=["top","bottom"],Be=s.z.enum(ht),Re=["center"],me=s.z.enum(Re),dt=[...Me,...Re],De=s.z.enum(dt);s.z.enum(ot);const ft=["first","last"];s.z.enum(ft);const pt=s.z.object({lower:s.z.number(),upper:s.z.number()}),yt=s.z.object({lower:s.z.bigint(),upper:s.z.bigint()});s.z.union([pt,_]);s.z.union([yt,_]);s.z.union([Ue,De]);s.z.union([Ue,De,s.z.instanceof(String)]);const ne=(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 Oe(r);return Oe(t)},Oe=r=>r.lower>r.upper?{lower:r.upper,upper:r.lower}:r;s.z.object({x:Ce.or(me),y:Be.or(me)});const gt=s.z.object({x:Ce,y:Be}),wt=Object.freeze({x:"left",y:"top"}),mt=(r,e)=>r.x===e.x&&r.y===e.y,ve=s.z.union([s.z.number(),J,_,xe,st,ut]),Ot=(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}),Z=s.z.union([s.z.number(),s.z.string()]);s.z.object({top:Z,left:Z,width:Z,height:Z});s.z.object({left:s.z.number(),top:s.z.number(),right:s.z.number(),bottom:s.z.number()});s.z.object({one:J,two:J,root:gt});const de=(r,e,t=0,n=0,i)=>{const a={one:{...be},two:{...be},root:i??wt};if(typeof r=="number"){if(typeof e!="number")throw new Error("Box constructor called with invalid arguments");return a.one={x:r,y:e},a.two={x:a.one.x+t,y:a.one.y+n},a}return"one"in r&&"two"in r&&"root"in r?{...r,root:i??r.root}:("getBoundingClientRect"in r&&(r=r.getBoundingClientRect()),"left"in r?(a.one={x:r.left,y:r.top},a.two={x:r.right,y:r.bottom},a):(a.one=r,e==null?a.two={x:a.one.x+t,y:a.one.y+n}:typeof e=="number"?a.two={x:a.one.x+e,y:a.one.y+t}:"width"in e?a.two={x:a.one.x+e.width,y:a.one.y+e.height}:"signedWidth"in e?a.two={x:a.one.x+e.signedWidth,y:a.one.y+e.signedHeight}:a.two=e,a))},se=r=>{const e=de(r);return{lower:e.one.x,upper:e.two.x}},ie=r=>{const e=de(r);return{lower:e.one.y,upper:e.two.y}},vt=r=>typeof r!="object"||r==null?!1:"one"in r&&"two"in r&&"root"in r;var bt=Object.defineProperty,Tt=(r,e,t)=>e in r?bt(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,M=(r,e,t)=>Tt(r,typeof e!="symbol"?e+"":e,t);const St=(r,e,t)=>e!==void 0&&r<e?e:t!==void 0&&r>t?t:r;s.z.object({offset:ve,scale:ve});const It=r=>(e,t,n,i)=>t==="dimension"?[e,n]:[e,i?n-r:n+r],Nt=r=>(e,t,n,i)=>[e,i?n/r:n*r],Et=r=>(e,t,n)=>{if(e===null)return[r,n];const{lower:i,upper:a}=e,{lower:c,upper:h}=r,p=a-i,m=h-c;if(t==="dimension")return[r,n*(m/p)];const v=(n-i)*(m/p)+c;return[r,v]},zt=r=>(e,t,n)=>[r,n],At=()=>(r,e,t)=>{if(r===null)throw new Error("cannot invert without bounds");if(e==="dimension")return[r,t];const{lower:n,upper:i}=r;return[r,i-(t-n)]},$t=r=>(e,t,n)=>{const{lower:i,upper:a}=r;return n=St(n,i,a),[e,n]},ue=class k{constructor(){M(this,"ops",[]),M(this,"currBounds",null),M(this,"currType",null),M(this,"reversed",!1),this.ops=[]}static translate(e){return new k().translate(e)}static magnify(e){return new k().magnify(e)}static scale(e,t){return new k().scale(e,t)}translate(e){const t=this.new(),n=It(e);return n.type="translate",t.ops.push(n),t}magnify(e){const t=this.new(),n=Nt(e);return n.type="magnify",t.ops.push(n),t}scale(e,t){const n=ne(e,t),i=this.new(),a=Et(n);return a.type="scale",i.ops.push(a),i}clamp(e,t){const n=ne(e,t),i=this.new(),a=$t(n);return a.type="clamp",i.ops.push(a),i}reBound(e,t){const n=ne(e,t),i=this.new(),a=zt(n);return a.type="re-bound",i.ops.push(a),i}invert(){const e=At();e.type="invert";const t=this.new();return t.ops.push(e),t}pos(e){return this.exec("position",e)}dim(e){return this.exec("dimension",e)}new(){const e=new k;return e.ops=this.ops.slice(),e.reversed=this.reversed,e}exec(e,t){return this.currBounds=null,this.ops.reduce(([n,i],a)=>a(n,e,i,this.reversed),[null,t])[1]}reverse(){const e=this.new();e.ops.reverse();const t=[];return e.ops.forEach((n,i)=>{if(n.type==="scale"||t.some(([c,h])=>i>=c&&i<=h))return;const a=e.ops.findIndex((c,h)=>c.type==="scale"&&h>i);a!==-1&&t.push([i,a])}),t.forEach(([n,i])=>{const a=e.ops.slice(n,i);a.unshift(e.ops[i]),e.ops.splice(n,i-n+1,...a)}),e.reversed=!e.reversed,e}};M(ue,"IDENTITY",new ue);let Te=ue;const Se=class U{constructor(e=new Te,t=new Te,n=null){M(this,"x"),M(this,"y"),M(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=Ot(e,t),i=this.copy();return i.x=this.x.translate(n.x),i.y=this.y.translate(n.y),i}translateX(e){const t=this.copy();return t.x=this.x.translate(e),t}translateY(e){const t=this.copy();return t.y=this.y.translate(e),t}magnify(e){const t=this.copy();return t.x=this.x.magnify(e.x),t.y=this.y.magnify(e.y),t}scale(e){const t=this.copy();if(vt(e)){const n=this.currRoot;return t.currRoot=e.root,n!=null&&!mt(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(se(e)),t.y=t.y.scale(ie(e)),t}return t.x=t.x.scale(e.width),t.y=t.y.scale(e.height),t}reBound(e){const t=this.copy();return t.x=this.x.reBound(se(e)),t.y=this.y.reBound(ie(e)),t}clamp(e){const t=this.copy();return t.x=this.x.clamp(se(e)),t.y=this.y.clamp(ie(e)),t}copy(){const e=new 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 de(this.pos(e.one),this.pos(e.two),0,0,this.currRoot??e.root)}};M(Se,"IDENTITY",new Se);const xt=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()});s.z.union([xe,xt,J,_]);var Ut=Object.defineProperty,Mt=(r,e,t)=>e in r?Ut(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,u=(r,e,t)=>Mt(r,typeof e!="symbol"?e+"":e,t);const Ye=(r,e)=>{const t=new T(e);if(![S.DAY,S.HOUR,S.MINUTE,S.SECOND,S.MILLISECOND,S.MICROSECOND,S.NANOSECOND].some(i=>i.equals(t)))throw new Error("Invalid argument for remainder. Must be an even TimeSpan or Timestamp");const n=r.valueOf()%t.valueOf();return r instanceof T?new T(n):new S(n)},y=class l{constructor(e,t="UTC"){if(u(this,"value"),u(this,"encodeValue",!0),e==null)this.value=l.now().valueOf();else if(e instanceof Date)this.value=BigInt(e.getTime())*l.MILLISECOND.valueOf();else if(typeof e=="string")this.value=l.parseDateTimeString(e,t).valueOf();else if(Array.isArray(e))this.value=l.parseDate(e);else{let n=BigInt(0);e instanceof Number&&(e=e.valueOf()),t==="local"&&(n=l.utcOffset.valueOf()),typeof e=="number"&&(isFinite(e)?e=Math.trunc(e):(isNaN(e)&&(e=0),e===1/0?e=l.MAX:e=l.MIN)),this.value=BigInt(e.valueOf())+n}}static parseDate([e=1970,t=1,n=1]){const i=new Date(e,t-1,n,0,0,0,0);return new l(BigInt(i.getTime())*l.MILLISECOND.valueOf()).truncate(l.DAY).valueOf()}encode(){return this.value.toString()}valueOf(){return this.value}static parseTimeString(e,t="UTC"){const[n,i,a]=e.split(":");let c="00",h="00";a!=null&&([c,h]=a.split("."));let p=l.hours(parseInt(n??"00",10)).add(l.minutes(parseInt(i??"00",10))).add(l.seconds(parseInt(c??"00",10))).add(l.milliseconds(parseInt(h??"00",10)));return t==="local"&&(p=p.add(l.utcOffset)),p.valueOf()}static parseDateTimeString(e,t="UTC"){if(!e.includes("/")&&!e.includes("-"))return l.parseTimeString(e,t);const n=new Date(e);return e.includes(":")||n.setUTCHours(0,0,0,0),new l(BigInt(n.getTime())*l.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(l.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())*l.MINUTE.valueOf())}static since(e){return new l().span(e)}date(){return new Date(this.milliseconds())}equals(e){return this.valueOf()===new l(e).valueOf()}span(e){return this.range(e).span}range(e){return new Ct(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 l(e).valueOf()}afterEq(e){return this.valueOf()>=new l(e).valueOf()}before(e){return this.valueOf()<new l(e).valueOf()}beforeEq(e){return this.valueOf()<=new l(e).valueOf()}add(e){return new l(this.valueOf()+BigInt(e.valueOf()))}sub(e){return new l(this.valueOf()-BigInt(e.valueOf()))}milliseconds(){return Number(this.valueOf())/Number(l.MILLISECOND.valueOf())}toString(){return this.date().toISOString()}remainder(e){return Ye(this,e)}get isToday(){return this.truncate(S.DAY).equals(l.now().truncate(S.DAY))}truncate(e){return this.sub(this.remainder(e))}static now(){return new l(new Date)}static max(...e){let t=l.MIN;for(const n of e){const i=new l(n);i.after(t)&&(t=i)}return t}static min(...e){let t=l.MAX;for(const n of e){const i=new l(n);i.before(t)&&(t=i)}return t}static nanoseconds(e){return new l(e)}static microseconds(e){return l.nanoseconds(e*1e3)}static milliseconds(e){return l.microseconds(e*1e3)}static seconds(e){return l.milliseconds(e*1e3)}static minutes(e){return l.seconds(e*60)}static hours(e){return l.minutes(e*60)}static days(e){return l.hours(e*24)}};u(y,"NANOSECOND",y.nanoseconds(1)),u(y,"MICROSECOND",y.microseconds(1)),u(y,"MILLISECOND",y.milliseconds(1)),u(y,"SECOND",y.seconds(1)),u(y,"MINUTE",y.minutes(1)),u(y,"HOUR",y.hours(1)),u(y,"DAY",y.days(1)),u(y,"MAX",new y((1n<<63n)-1n)),u(y,"MIN",new y(0)),u(y,"ZERO",new y(0)),u(y,"z",s.z.union([s.z.object({value:s.z.bigint()}).transform(r=>new y(r.value)),s.z.string().transform(r=>new y(BigInt(r))),s.z.instanceof(Number).transform(r=>new y(r)),s.z.number().transform(r=>new y(r)),s.z.instanceof(y)]));let T=y;const g=class d{constructor(e){u(this,"value"),u(this,"encodeValue",!0),typeof e=="number"&&(e=Math.trunc(e.valueOf())),this.value=BigInt(e.valueOf())}encode(){return this.value.toString()}valueOf(){return this.value}lessThan(e){return this.valueOf()<new d(e).valueOf()}greaterThan(e){return this.valueOf()>new d(e).valueOf()}lessThanOrEqual(e){return this.valueOf()<=new d(e).valueOf()}greaterThanOrEqual(e){return this.valueOf()>=new d(e).valueOf()}remainder(e){return Ye(this,e)}truncate(e){return new d(BigInt(Math.trunc(Number(this.valueOf()/e.valueOf())))*e.valueOf())}toString(){const e=this.truncate(d.DAY),t=this.truncate(d.HOUR),n=this.truncate(d.MINUTE),i=this.truncate(d.SECOND),a=this.truncate(d.MILLISECOND),c=this.truncate(d.MICROSECOND),h=this.truncate(d.NANOSECOND),p=e,m=t.sub(e),v=n.sub(t),w=i.sub(n),z=a.sub(i),j=c.sub(a),x=h.sub(c);let E="";return p.isZero||(E+=`${p.days}d `),m.isZero||(E+=`${m.hours}h `),v.isZero||(E+=`${v.minutes}m `),w.isZero||(E+=`${w.seconds}s `),z.isZero||(E+=`${z.milliseconds}ms `),j.isZero||(E+=`${j.microseconds}µs `),x.isZero||(E+=`${x.nanoseconds}ns`),E.trim()}get days(){return Number(this.valueOf())/Number(d.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(d.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(d.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(d.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(d.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(d.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get isZero(){return this.valueOf()===BigInt(0)}equals(e){return this.valueOf()===new d(e).valueOf()}add(e){return new d(this.valueOf()+new d(e).valueOf())}sub(e){return new d(this.valueOf()-new d(e).valueOf())}static nanoseconds(e=1){return new d(e)}static microseconds(e=1){return d.nanoseconds(e*1e3)}static milliseconds(e=1){return d.microseconds(e*1e3)}static seconds(e=1){return d.milliseconds(e*1e3)}static minutes(e){return d.seconds(e.valueOf()*60)}static hours(e){return d.minutes(e*60)}static days(e){return d.hours(e*24)}};u(g,"NANOSECOND",g.nanoseconds(1)),u(g,"MICROSECOND",g.microseconds(1)),u(g,"MILLISECOND",g.milliseconds(1)),u(g,"SECOND",g.seconds(1)),u(g,"MINUTE",g.minutes(1)),u(g,"HOUR",g.hours(1)),u(g,"DAY",g.days(1)),u(g,"MAX",new g((1n<<63n)-1n)),u(g,"MIN",new g(0)),u(g,"ZERO",new g(0)),u(g,"z",s.z.union([s.z.object({value:s.z.bigint()}).transform(r=>new g(r.value)),s.z.string().transform(r=>new g(BigInt(r))),s.z.instanceof(Number).transform(r=>new g(r)),s.z.number().transform(r=>new g(r)),s.z.instanceof(g)]));let S=g;const H=class V extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new V(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 N(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 V(e)}static khz(e){return V.hz(e*1e3)}};u(H,"z",s.z.union([s.z.number().transform(r=>new H(r)),s.z.instanceof(Number).transform(r=>new H(r)),s.z.instanceof(H)]));const b=class extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}length(e){return e.valueOf()/this.valueOf()}size(e){return new Bt(e*this.valueOf())}};u(b,"UNKNOWN",new b(0)),u(b,"BIT128",new b(16)),u(b,"BIT64",new b(8)),u(b,"BIT32",new b(4)),u(b,"BIT16",new b(2)),u(b,"BIT8",new b(1)),u(b,"z",s.z.union([s.z.number().transform(r=>new b(r)),s.z.instanceof(Number).transform(r=>new b(r)),s.z.instanceof(b)]));let N=b;const A=class K{constructor(e,t){u(this,"start"),u(this,"end"),typeof e=="object"&&"start"in e?(this.start=new T(e.start),this.end=new T(e.end)):(this.start=new T(e),this.end=new T(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}swap(){return new K(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 i=T.max(n.start,e.start),a=T.min(n.end,e.end);return a.before(i)?!1:new S(a.sub(i)).greaterThanOrEqual(t)}roughlyEquals(e,t){let n=this.start.sub(e.start).valueOf(),i=this.end.sub(e.end).valueOf();return n<0&&(n=-n),i<0&&(i=-i),n<=t.valueOf()&&i<=t.valueOf()}contains(e){return e instanceof K?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const t=new K(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(A,"MAX",new A(T.MIN,T.MAX)),u(A,"MIN",new A(T.MAX,T.MIN)),u(A,"ZERO",new A(T.ZERO,T.ZERO)),u(A,"z",s.z.union([s.z.object({start:T.z,end:T.z}).transform(r=>new A(r.start,r.end)),s.z.instanceof(A)]));let Ct=A;const o=class $ extends String{constructor(e){if(e instanceof $||typeof e=="string"||typeof e.valueOf()=="string"){super(e.valueOf());return}else{const t=$.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);if(t!=null){super(t.valueOf());return}}throw super($.UNKNOWN.valueOf()),new Error(`unable to find data type for ${e.toString()}`)}get Array(){const e=$.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()}toString(){return this.valueOf()}get isVariable(){return this.equals($.JSON)||this.equals($.STRING)}get isNumeric(){return!this.isVariable&&!this.equals($.UUID)}get isInteger(){return this.toString().startsWith("int")}get isFloat(){return this.toString().startsWith("float")}get density(){const e=$.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 $.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(),N.BIT8],[o.UINT16.toString(),N.BIT16],[o.UINT32.toString(),N.BIT32],[o.UINT64.toString(),N.BIT64],[o.FLOAT32.toString(),N.BIT32],[o.FLOAT64.toString(),N.BIT64],[o.INT8.toString(),N.BIT8],[o.INT16.toString(),N.BIT16],[o.INT32.toString(),N.BIT32],[o.INT64.toString(),N.BIT64],[o.TIMESTAMP.toString(),N.BIT64],[o.STRING.toString(),N.UNKNOWN],[o.JSON.toString(),N.UNKNOWN],[o.UUID.toString(),N.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",s.z.union([s.z.string().transform(r=>new o(r)),s.z.instanceof(o)]));const I=class O extends Number{constructor(e){super(e.valueOf())}largerThan(e){return this.valueOf()>e.valueOf()}smallerThan(e){return this.valueOf()<e.valueOf()}add(e){return O.bytes(this.valueOf()+e.valueOf())}sub(e){return O.bytes(this.valueOf()-e.valueOf())}truncate(e){return new O(Math.trunc(this.valueOf()/e.valueOf())*e.valueOf())}remainder(e){return O.bytes(this.valueOf()%e.valueOf())}get gigabytes(){return this.valueOf()/O.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/O.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/O.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/O.TERABYTE.valueOf()}toString(){const e=this.truncate(O.TERABYTE),t=this.truncate(O.GIGABYTE),n=this.truncate(O.MEGABYTE),i=this.truncate(O.KILOBYTE),a=this.truncate(O.BYTE),c=e,h=t.sub(e),p=n.sub(t),m=i.sub(n),v=a.sub(i);let w="";return c.isZero||(w+=`${c.terabytes}TB `),h.isZero||(w+=`${h.gigabytes}GB `),p.isZero||(w+=`${p.megabytes}MB `),m.isZero||(w+=`${m.kilobytes}KB `),(!v.isZero||w==="")&&(w+=`${v.valueOf()}B`),w.trim()}static bytes(e=1){return new O(e)}static kilobytes(e=1){return O.bytes(e.valueOf()*1e3)}static megabytes(e=1){return O.kilobytes(e.valueOf()*1e3)}static gigabytes(e=1){return O.megabytes(e.valueOf()*1e3)}static terabytes(e){return O.gigabytes(e.valueOf()*1e3)}get isZero(){return this.valueOf()===0}};u(I,"BYTE",new I(1)),u(I,"KILOBYTE",I.kilobytes(1)),u(I,"MEGABYTE",I.megabytes(1)),u(I,"GIGABYTE",I.gigabytes(1)),u(I,"TERABYTE",I.terabytes(1)),u(I,"ZERO",new I(0)),u(I,"z",s.z.union([s.z.number().transform(r=>new I(r)),s.z.instanceof(I)]));let Bt=I;s.z.union([s.z.instanceof(Uint8Array),s.z.instanceof(Uint16Array),s.z.instanceof(Uint32Array),s.z.instanceof(BigUint64Array),s.z.instanceof(Float32Array),s.z.instanceof(Float64Array),s.z.instanceof(Int8Array),s.z.instanceof(Int16Array),s.z.instanceof(Int32Array),s.z.instanceof(BigInt64Array)]);s.z.record(s.z.union([s.z.number(),s.z.string(),s.z.symbol()]),s.z.unknown());const Pe=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser",Rt=Pe(),Le=["MacOS","Windows","Linux","Docker"],Dt=s.z.enum(Le);let oe;const Yt=()=>{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"},Pt=(r={})=>{const{force:e,default:t}=r;return e??oe??(oe=Yt(),oe??t)},je=Object.freeze(Object.defineProperty({__proto__:null,OPERATING_SYSTEMS:Le,RUNTIME:Rt,detect:Pe,getOS:Pt,osZ:Dt},Symbol.toStringTag,{value:"Module"}));var Lt=Object.defineProperty,jt=(r,e,t)=>e in r?Lt(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,W=(r,e,t)=>jt(r,typeof e!="symbol"?e+"":e,t);const kt=(...r)=>r.map(ke).join(""),ke=r=>(r.endsWith("/")||(r+="/"),r.startsWith("/")&&(r=r.slice(1)),r),Wt=r=>r.endsWith("/")?r.slice(0,-1):r,Ft=(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("&"),ce=class le{constructor({host:e,port:t,protocol:n="",pathPrefix:i=""}){W(this,"protocol"),W(this,"host"),W(this,"port"),W(this,"path"),this.protocol=n,this.host=e,this.port=t,this.path=ke(i)}replace(e){return new le({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new le({...this,pathPrefix:kt(this.path,e)})}toString(){return Wt(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}};W(ce,"UNKNOWN",new ce({host:"unknown",port:0}));let Gt=ce;var qt=Object.defineProperty,Zt=(r,e,t)=>e in r?qt(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,X=(r,e,t)=>Zt(r,typeof e!="symbol"?e+"":e,t);const D=class extends Number{};X(D,"Absolute",255),X(D,"Default",1),X(D,"z",s.z.union([s.z.instanceof(D),s.z.number().int().min(0).max(255).transform(r=>new D(r)),s.z.instanceof(Number).transform(r=>new D(r))]));s.z.object({name:s.z.string(),key:s.z.string()});const We=class F extends Error{constructor(){super(F.MESSAGE)}matches(e){return typeof e=="string"?e.includes(F.MESSAGE):e instanceof F||e.message.includes(F.MESSAGE)}};X(We,"MESSAGE","canceled");let Ht=We;new Ht;s.z.string().regex(/^\d+\.\d+\.\d+$/);const ee=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 q extends Error{constructor(t){super(t);f(this,"discriminator","FreighterError");f(this,"type","")}}const Vt=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},Ie="unknown",Ne="nil",Kt="freighter",fe=s.z.object({type:s.z.string(),data:s.z.string()});class Xt{constructor(){f(this,"providers",[])}register(e){this.providers.push(e)}encode(e){if(e==null)return{type:Ne,data:""};if(Vt(e))for(const t of this.providers){const n=t.encode(e);if(n!=null)return n}return{type:Ie,data:JSON.stringify(e)}}decode(e){if(e==null||e.type===Ne)return null;if(e.type===Ie)return new Ee(e.data);for(const t of this.providers){const n=t.decode(e);if(n!=null)return n}return new Ee(e.data)}}const pe=new Xt,Fe=({encode:r,decode:e})=>pe.register({encode:r,decode:e}),Jt=r=>pe.encode(r),ye=r=>pe.decode(r);class Ee extends q{constructor(t){super(t);f(this,"type","unknown")}}const te="freighter.",Y=class Y extends q{constructor(){super("EOF");f(this,"type",Y.TYPE)}};f(Y,"TYPE",te+"eof"),f(Y,"matches",ee(Y.TYPE));let C=Y;const P=class P extends q{constructor(){super("StreamClosed");f(this,"type",P.TYPE)}};f(P,"TYPE",te+"stream_closed"),f(P,"matches",ee(P.TYPE));let B=P;const L=class L extends q{constructor(t={}){const{message:n="Unreachable",url:i=Gt.UNKNOWN}=t;super(n);f(this,"type",L.TYPE);f(this,"url");this.url=i}};f(L,"TYPE",te+"unreachable"),f(L,"matches",ee(L.TYPE));let R=L;const Qt=r=>{if(!r.type.startsWith(Kt))return null;if(C.matches(r))return{type:C.TYPE,data:"EOF"};if(B.matches(r))return{type:B.TYPE,data:"StreamClosed"};if(R.matches(r))return{type:R.TYPE,data:"Unreachable"};throw new Error(`Unknown error type: ${r.type}: ${r.message}`)},_t=r=>{if(!r.type.startsWith(te))return null;switch(r.type){case C.TYPE:return new C;case B.TYPE:return new B;case R.TYPE:return new R;default:throw new Error(`Unknown error type: ${r.data}`)}};Fe({encode:Qt,decode:_t});class Ge{constructor(){f(this,"middleware",[])}use(...e){this.middleware.push(...e)}async executeMiddleware(e,t){let n=0;const i=async a=>{if(n===this.middleware.length)return await t(a);const c=this.middleware[n];return n++,await c(a,i)};return await i(e)}}const qe="Content-Type",ze=r=>{if(je.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(i,a)=>await e(i,{...a,agent:n})};class er extends Ge{constructor(t,n,i=!1){super();f(this,"endpoint");f(this,"encoder");f(this,"fetch");return this.endpoint=t.replace({protocol:i?"https":"http"}),this.encoder=n,this.fetch=ze(this.endpoint.protocol),new Proxy(this,{get:(a,c,h)=>c==="endpoint"?this.endpoint:Reflect.get(a,c,h)})}get headers(){return{[qe]:this.encoder.contentType}}async send(t,n,i,a){n=i==null?void 0:i.parse(n);let c=null;const h=this.endpoint.child(t),p={};p.method="POST",p.body=this.encoder.encode(n??{});const[,m]=await this.executeMiddleware({target:h.toString(),protocol:this.endpoint.protocol,params:{},role:"client"},async v=>{const w={...v,params:{}};p.headers={...this.headers,...v.params};let z;try{z=await ze(v.protocol)(v.target,p)}catch(x){let E=x;return E.message==="Load failed"&&(E=new R({url:h})),[w,E]}const j=await z.arrayBuffer();if(z!=null&&z.ok)return a!=null&&(c=this.encoder.decode(j,a)),[w,null];try{if(z.status!==400)return[w,new Error(z.statusText)];const x=this.encoder.decode(j,fe),E=ye(x);return[w,E]}catch(x){return[w,new Error(`[freighter] - failed to decode error: ${z.statusText}: ${x.message}`)]}});return[c,m]}}const tr=async(r,e,t,n,i)=>{const[a,c]=await r.send(e,t,n,i);if(c!=null)throw c;return a},rr=()=>je.RUNTIME!=="node"?r=>new WebSocket(r):r=>new(require("ws")).WebSocket(r,{rejectUnauthorized:!1}),nr=s.z.object({type:s.z.union([s.z.literal("data"),s.z.literal("close")]),payload:s.z.unknown().optional(),error:s.z.optional(fe)});class sr{constructor(e,t,n,i){f(this,"encoder");f(this,"reqSchema");f(this,"resSchema");f(this,"ws");f(this,"serverClosed");f(this,"sendClosed");f(this,"receiveDataQueue",[]);f(this,"receiveCallbacksQueue",[]);this.encoder=t,this.reqSchema=n,this.resSchema=i,this.ws=e,this.sendClosed=!1,this.serverClosed=null,this.listenForMessages()}send(e){if(this.serverClosed!=null)return new C;if(this.sendClosed)throw new B;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=ye(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,nr)),this.ws.onclose=e=>this.addMessage({type:"close",error:{type:cr(e)?C.TYPE:B.TYPE,data:""}})}}const ir="freighterctx",or=1e3,ar=1001,ur=[or,ar],cr=r=>ur.includes(r.code),Q=class Q extends Ge{constructor(t,n,i=!1){super();f(this,"baseUrl");f(this,"encoder");this.baseUrl=t.replace({protocol:i?"wss":"ws"}),this.encoder=n}async stream(t,n,i){const a=rr();let c;const[,h]=await this.executeMiddleware({target:t,protocol:"websocket",params:{},role:"client"},async p=>{const m=a(this.buildURL(t,p)),v={...p,params:{}};m.binaryType=Q.MESSAGE_TYPE;const w=await this.wrapSocket(m,n,i);return w instanceof Error?[v,w]:(c=w,[v,null])});if(h!=null)throw h;return c}buildURL(t,n){const i=Ft({[qe]:this.encoder.contentType,...n.params},ir);return this.baseUrl.child(t).toString()+i}async wrapSocket(t,n,i){return await new Promise(a=>{t.onopen=()=>{a(new sr(t,this.encoder,n,i))},t.onerror=c=>{const h=c;a(new Error(h.message))}})}};f(Q,"MESSAGE_TYPE","arraybuffer");let he=Q;exports.BaseTypedError=q;exports.EOF=C;exports.HTTPClient=er;exports.StreamClosed=B;exports.Unreachable=R;exports.WebSocketClient=he;exports.decodeError=ye;exports.encodeError=Jt;exports.errorMatcher=ee;exports.errorZ=fe;exports.registerError=Fe;exports.sendRequired=tr;