@synnaxlabs/freighter 0.23.0 → 0.24.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 +22 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/freighter.cjs +3 -1
- package/dist/freighter.js +699 -636
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/errors.spec.ts +4 -2
- package/src/errors.ts +41 -11
- package/src/index.ts +2 -1
- package/src/websocket.spec.ts +2 -1
package/dist/errors.d.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { URL } from '@synnaxlabs/x';
|
|
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
|
|
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: 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: 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: unknown) => boolean;
|
|
83
104
|
url: URL;
|
|
84
105
|
constructor(args?: UnreachableArgs);
|
|
85
106
|
}
|
package/dist/errors.d.ts.map
CHANGED
|
@@ -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,
|
|
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,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;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,0BAA0B;;CAKlD;AAED,0DAA0D;AAC1D,qBAAa,YAAa,SAAQ,cAAe,YAAW,UAAU;IACpE,MAAM,CAAC,QAAQ,CAAC,IAAI,SAA0C;IAC9D,MAAM,CAAC,QAAQ,CAAC,OAAO,0BAAmC;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,0BAAkC;IACzD,GAAG,EAAE,GAAG,CAAC;gBAEG,IAAI,GAAE,eAAoB;CAKvC"}
|
package/dist/freighter.cjs
CHANGED
|
@@ -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 Mt=Object.defineProperty;var Rt=(t,e,r)=>e in t?Mt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var y=(t,e,r)=>(Rt(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={},de={};Object.defineProperty(de,"__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-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()}):""}de.default=Dt;var he={};Object.defineProperty(he,"__esModule",{value:!0});function kt(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():""}he.default=kt;var pe={};Object.defineProperty(pe,"__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-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()}):""}pe.default=Bt;var Ee={};Object.defineProperty(Ee,"__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():""}Ee.default=Pt;var Ce={};Object.defineProperty(Ce,"__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():""}Ce.default=Lt;var $e={};Object.defineProperty($e,"__esModule",{value:!0});function Yt(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():""}$e.default=Yt;var xe={};Object.defineProperty(xe,"__esModule",{value:!0});function Zt(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)}xe.default=Zt;var je={};Object.defineProperty(je,"__esModule",{value:!0});function Vt(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}):""}je.default=Vt;var ye={};Object.defineProperty(ye,"__esModule",{value:!0});function Kt(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():""}ye.default=Kt;var Ue={},K={};(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})}})(K);var 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],o=0,c=a.length;o<c;o++,s++)n[s]=a[o];return n};Object.defineProperty(Ue,"__esModule",{value:!0});var U=K;function re(t,e){if(e===void 0&&(e=U.DefaultOption),!U.isValidObject(t))return null;e=U.validateOptions(e);var r={};return Object.keys(t).forEach(function(n){var s=t[n],a=n.toLowerCase();e.recursive&&(U.isValidObject(s)?U.belongToTypes(s,e.keepTypesOnRecursion)||(s=re(s,e)):e.recursiveInArray&&U.isArrayObject(s)&&(s=Ft(s).map(function(o){var c=o;if(U.isValidObject(o))U.belongToTypes(c,e.keepTypesOnRecursion)||(c=re(o,e));else if(U.isArrayObject(o)){var h=re({key:o},e);c=h.key}return c}))),r[a]=s}),r}Ue.default=re;var Me={},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],o=0,c=a.length;o<c;o++,s++)n[s]=a[o];return n};Object.defineProperty(Me,"__esModule",{value:!0});var M=K;function ne(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.toUpperCase();e.recursive&&(M.isValidObject(s)?M.belongToTypes(s,e.keepTypesOnRecursion)||(s=ne(s,e)):e.recursiveInArray&&M.isArrayObject(s)&&(s=Wt(s).map(function(o){var c=o;if(M.isValidObject(o))M.belongToTypes(c,e.keepTypesOnRecursion)||(c=ne(o,e));else if(M.isArrayObject(o)){var h=ne({key:o},e);c=h.key}return c}))),r[a]=s}),r}Me.default=ne;var Re={},qt=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],o=0,c=a.length;o<c;o++,s++)n[s]=a[o];return n};Object.defineProperty(Re,"__esModule",{value:!0});var R=K,Gt=de;function se(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=Gt.default(n);e.recursive&&(R.isValidObject(s)?R.belongToTypes(s,e.keepTypesOnRecursion)||(s=se(s,e)):e.recursiveInArray&&R.isArrayObject(s)&&(s=qt(s).map(function(o){var c=o;if(R.isValidObject(o))R.belongToTypes(c,e.keepTypesOnRecursion)||(c=se(o,e));else if(R.isArrayObject(o)){var h=se({key:o},e);c=h.key}return c}))),r[a]=s}),r}Re.default=se;var De={},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],o=0,c=a.length;o<c;o++,s++)n[s]=a[o];return n};Object.defineProperty(De,"__esModule",{value:!0});var D=K,Xt=he;function ie(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=Xt.default(n);e.recursive&&(D.isValidObject(s)?D.belongToTypes(s,e.keepTypesOnRecursion)||(s=ie(s,e)):e.recursiveInArray&&D.isArrayObject(s)&&(s=Ht(s).map(function(o){var c=o;if(D.isValidObject(o))D.belongToTypes(c,e.keepTypesOnRecursion)||(c=ie(o,e));else if(D.isArrayObject(o)){var h=ie({key:o},e);c=h.key}return c}))),r[a]=s}),r}De.default=ie;var ke={},Jt=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],o=0,c=a.length;o<c;o++,s++)n[s]=a[o];return n};Object.defineProperty(ke,"__esModule",{value:!0});var k=K,Qt=pe;function ae(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=Qt.default(n);e.recursive&&(k.isValidObject(s)?k.belongToTypes(s,e.keepTypesOnRecursion)||(s=ae(s,e)):e.recursiveInArray&&k.isArrayObject(s)&&(s=Jt(s).map(function(o){var c=o;if(k.isValidObject(o))k.belongToTypes(c,e.keepTypesOnRecursion)||(c=ae(o,e));else if(k.isArrayObject(o)){var h=ae({key:o},e);c=h.key}return c}))),r[a]=s}),r}ke.default=ae;var Be={},_t=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],o=0,c=a.length;o<c;o++,s++)n[s]=a[o];return n};Object.defineProperty(Be,"__esModule",{value:!0});var B=K,er=ye;function oe(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=er.default(n);e.recursive&&(B.isValidObject(s)?B.belongToTypes(s,e.keepTypesOnRecursion)||(s=oe(s,e)):e.recursiveInArray&&B.isArrayObject(s)&&(s=_t(s).map(function(o){var c=o;if(B.isValidObject(o))B.belongToTypes(c,e.keepTypesOnRecursion)||(c=oe(o,e));else if(B.isArrayObject(o)){var h=oe({key:o},e);c=h.key}return c}))),r[a]=s}),r}Be.default=oe;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 _e=de;d.toCamelCase=_e.default;var et=he;d.toSnakeCase=et.default;var tt=pe;d.toPascalCase=tt.default;var rt=Ee;d.toDotCase=rt.default;var nt=Ce;d.toPathCase=nt.default;var st=$e;d.toTextCase=st.default;var it=xe;d.toSentenceCase=it.default;var at=je;d.toHeaderCase=at.default;var ot=ye;d.toKebabCase=ot.default;var ut=Ue;d.lowerKeys=ut.default;var ct=Me;d.upperKeys=ct.default;var lt=Re;d.camelKeys=lt.default;var ft=De;d.snakeKeys=ft.default;var dt=ke;d.pascalKeys=dt.default;var ht=Be;d.kebabKeys=ht.default;var pt=function(t){return String(t||"").toLowerCase()};d.toLowerCase=pt;var yt=function(t){return String(t||"").toUpperCase()};d.toUpperCase=yt;var tr={toCamelCase:_e.default,toSnakeCase:et.default,toPascalCase:tt.default,toDotCase:rt.default,toPathCase:nt.default,toTextCase:st.default,toSentenceCase:it.default,toHeaderCase:at.default,toKebabCase:ot.default,toUpperCase:yt,toLowerCase:pt,lowerKeys:ut.default,upperKeys:ct.default,camelKeys:lt.default,snakeKeys:ft.default,pascalKeys:dt.default,kebabKeys:ht.default};d.default=tr;var gt=d;const vt={recursive:!0,recursiveInArray:!0,keepTypesOnRecursion:[Number,String,Uint8Array]},rr=t=>gt.snakeKeys(t,vt),nr=t=>gt.camelKeys(t,vt),Ot=t=>t!=null&&typeof t=="object"&&!Array.isArray(t);var sr=Object.defineProperty,ir=(t,e,r)=>e in t?sr(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Q=(t,e,r)=>(ir(t,typeof e!="symbol"?e+"":e,r),r);let ar=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,r){return this.decodeString(this.decoder.decode(e),r)}decodeString(e,r){const n=nr(JSON.parse(e));return r!=null?r.parse(n):n}encodeString(e){return JSON.stringify(rr(e),(r,n)=>ArrayBuffer.isView(n)?Array.from(n):Ot(n)&&"encode_value"in n?typeof n.value=="bigint"?n.value.toString():n.value:typeof n=="bigint"?n.toString():n)}static registerCustomType(){}},or=class{constructor(){Q(this,"contentType","text/csv")}encode(e){const r=this.encodeString(e);return new TextEncoder().encode(r).buffer}decode(e,r){const n=new TextDecoder().decode(e);return this.decodeString(n,r)}encodeString(e){if(!Array.isArray(e)||e.length===0||!Ot(e[0]))throw new Error("Payload must be an array of objects");const r=Object.keys(e[0]),n=[r.join(",")];return e.forEach(s=>{const a=r.map(o=>JSON.stringify(s[o]??""));n.push(a.join(","))}),n.join(`
|
|
2
|
+
`)}decodeString(e,r){const[n,...s]=e.trim().split(`
|
|
3
|
+
`).map(c=>c.trim());if(n.length===0)return r!=null?r.parse({}):{};const a=n.split(",").map(c=>c.trim()),o={};return a.forEach(c=>{o[c]=[]}),s.forEach(c=>{const h=c.split(",").map(m=>m.trim());a.forEach((m,b)=>{const O=this.parseValue(h[b]);O!=null&&o[m].push(O)})}),r!=null?r.parse(o):o}parseValue(e){if(e==null||e.length===0)return null;const r=Number(e);return isNaN(r)?e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e:r}static registerCustomType(){}},ur=class{constructor(){Q(this,"contentType","text/plain")}encode(e){return new TextEncoder().encode(e).buffer}decode(e,r){const n=new TextDecoder().decode(e);return r!=null?r.parse(n):n}};new ar;new or;new ur;const ge=i.z.tuple([i.z.number(),i.z.number()]);i.z.tuple([i.z.bigint(),i.z.bigint()]);const wt=i.z.object({width:i.z.number(),height:i.z.number()}),cr=i.z.object({signedWidth:i.z.number(),signedHeight:i.z.number()}),lr=["width","height"];i.z.enum(lr);const fr=["start","center","end"],dr=["signedWidth","signedHeight"];i.z.enum(dr);const le=i.z.object({x:i.z.number(),y:i.z.number()}),hr=i.z.object({clientX:i.z.number(),clientY:i.z.number()}),pr=["x","y"],mt=i.z.enum(pr),bt=["top","right","bottom","left"];i.z.enum(bt);const yr=["left","right"],Tt=i.z.enum(yr),gr=["top","bottom"],St=i.z.enum(gr),At=["center"],Ve=i.z.enum(At),vr=[...bt,...At],It=i.z.enum(vr);i.z.enum(fr);const Or=["first","last"];i.z.enum(Or);const wr=i.z.object({lower:i.z.number(),upper:i.z.number()}),mr=i.z.object({lower:i.z.bigint(),upper:i.z.bigint()});i.z.union([wr,ge]);i.z.union([mr,ge]);i.z.union([mt,It]);i.z.union([mt,It,i.z.instanceof(String)]);const we=(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 Ke(t);return Ke(r)},Ke=t=>t.lower>t.upper?{lower:t.upper,upper:t.lower}:t;i.z.object({x:Tt.or(Ve),y:St.or(Ve)});const br=i.z.object({x:Tt,y:St}),Tr=Object.freeze({x:"left",y:"top"}),Sr=(t,e)=>t.x===e.x&&t.y===e.y,Fe=i.z.union([i.z.number(),le,ge,wt,cr,hr]),Ar=(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}},We=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:le,two:le,root:br});const Pe=(t,e,r=0,n=0,s)=>{const a={one:{...We},two:{...We},root:s??Tr};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))},me=t=>{const e=Pe(t);return{lower:e.one.x,upper:e.two.x}},be=t=>{const e=Pe(t);return{lower:e.one.y,upper:e.two.y}},Ir=t=>typeof t!="object"||t==null?!1:"one"in t&&"two"in t&&"root"in t;var Nr=Object.defineProperty,zr=(t,e,r)=>e in t?Nr(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,L=(t,e,r)=>(zr(t,typeof e!="symbol"?e+"":e,r),r);const Er=(t,e,r)=>(e!=null&&(t=Math.max(t,e)),r!=null&&(t=Math.min(t,r)),t);i.z.object({offset:Fe,scale:Fe});const Cr=t=>(e,r,n,s)=>r==="dimension"?[e,n]:[e,s?n-t:n+t],$r=t=>(e,r,n,s)=>[e,s?n/t:n*t],xr=t=>(e,r,n)=>{if(e===null)return[t,n];const{lower:s,upper:a}=e,{lower:o,upper:c}=t,h=a-s,m=c-o;if(r==="dimension")return[t,n*(m/h)];const b=(n-s)*(m/h)+o;return[t,b]},jr=t=>(e,r,n)=>[t,n],Ur=()=>(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)]},Mr=t=>(e,r,n)=>{const{lower:s,upper:a}=t;return n=Er(n,s,a),[e,n]},Ae=class X{constructor(){L(this,"ops",[]),L(this,"currBounds",null),L(this,"currType",null),L(this,"reversed",!1),this.ops=[]}static translate(e){return new X().translate(e)}static magnify(e){return new X().magnify(e)}static scale(e,r){return new X().scale(e,r)}translate(e){const r=this.new(),n=Cr(e);return n.type="translate",r.ops.push(n),r}magnify(e){const r=this.new(),n=$r(e);return n.type="magnify",r.ops.push(n),r}scale(e,r){const n=we(e,r),s=this.new(),a=xr(n);return a.type="scale",s.ops.push(a),s}clamp(e,r){const n=we(e,r),s=this.new(),a=Mr(n);return a.type="clamp",s.ops.push(a),s}reBound(e,r){const n=we(e,r),s=this.new(),a=jr(n);return a.type="re-bound",s.ops.push(a),s}invert(){const e=Ur();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 X;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(([o,c])=>s>=o&&s<=c))return;const a=e.ops.findIndex((o,c)=>o.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}};L(Ae,"IDENTITY",new Ae);let qe=Ae;const Ge=class P{constructor(e=new qe,r=new qe,n=null){L(this,"x"),L(this,"y"),L(this,"currRoot"),this.x=e,this.y=r,this.currRoot=n}static translate(e,r){return new P().translate(e,r)}static translateX(e){return new P().translateX(e)}static translateY(e){return new P().translateY(e)}static clamp(e){return new P().clamp(e)}static magnify(e){return new P().magnify(e)}static scale(e){return new P().scale(e)}static reBound(e){return new P().reBound(e)}translate(e,r){const n=Ar(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(Ir(e)){const n=this.currRoot;return r.currRoot=e.root,n!=null&&!Sr(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(me(e)),r.y=r.y.scale(be(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(me(e)),r.y=this.y.reBound(be(e)),r}clamp(e){const r=this.copy();return r.x=this.x.clamp(me(e)),r.y=this.y.clamp(be(e)),r}copy(){const e=new P;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 Pe(this.pos(e.one),this.pos(e.two),0,0,this.currRoot??e.root)}};L(Ge,"IDENTITY",new Ge);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",Rr=Nt(),zt=["MacOS","Windows","Linux","Docker"],Dr=i.z.enum(zt);let Te;const kr=()=>{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"},Br=(t={})=>{const{force:e,default:r}=t;return e??Te??(Te=kr(),Te??r)},Et=Object.freeze(Object.defineProperty({__proto__:null,OPERATING_SYSTEMS:zt,RUNTIME:Rr,detect:Nt,getOS:Br,osZ:Dr},Symbol.toStringTag,{value:"Module"})),Pr=i.z.object({signedWidth:i.z.number(),signedHeight:i.z.number()});i.z.union([wt,Pr,le,ge]);var Lr=Object.defineProperty,Yr=(t,e,r)=>e in t?Lr(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,l=(t,e,r)=>(Yr(t,typeof e!="symbol"?e+"":e,r),r);const Ct=(t,e)=>{const r=new S(e);if(![A.DAY,A.HOUR,A.MINUTE,A.SECOND,A.MILLISECOND,A.MICROSECOND,A.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 S?new S(n):new A(n)},g=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 o="00",c="00";a!=null&&([o,c]=a.split("."));let h=f.hours(parseInt(n??"00",10)).add(f.minutes(parseInt(s??"00",10))).add(f.seconds(parseInt(o??"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 A(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 Zr(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 Ct(this,e)}get isToday(){return this.truncate(A.DAY).equals(f.now().truncate(A.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(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 S=g;const v=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 Ct(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),o=this.truncate(p.MICROSECOND),c=this.truncate(p.NANOSECOND),h=e,m=r.sub(e),b=n.sub(r),O=s.sub(n),C=a.sub(s),H=o.sub(a),j=c.sub(o);let z="";return h.isZero||(z+=`${h.days}d `),m.isZero||(z+=`${m.hours}h `),b.isZero||(z+=`${b.minutes}m `),O.isZero||(z+=`${O.seconds}s `),C.isZero||(z+=`${C.milliseconds}ms `),H.isZero||(z+=`${H.microseconds}µs `),j.isZero||(z+=`${j.nanoseconds}ns`),z.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(v,"NANOSECOND",v.nanoseconds(1)),l(v,"MICROSECOND",v.microseconds(1)),l(v,"MILLISECOND",v.milliseconds(1)),l(v,"SECOND",v.seconds(1)),l(v,"MINUTE",v.minutes(1)),l(v,"HOUR",v.hours(1)),l(v,"DAY",v.days(1)),l(v,"MAX",new v((1n<<63n)-1n)),l(v,"MIN",new v(0)),l(v,"ZERO",new v(0)),l(v,"z",i.z.union([i.z.object({value:i.z.bigint()}).transform(t=>new v(t.value)),i.z.string().transform(t=>new v(BigInt(t))),i.z.instanceof(Number).transform(t=>new v(t)),i.z.number().transform(t=>new v(t)),i.z.instanceof(v)]));let A=v;const te=class ue extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new ue(e).valueOf()}get period(){return A.seconds(1/this.valueOf())}sampleCount(e){return new A(e).seconds*this.valueOf()}byteCount(e,r){return this.sampleCount(e)*new N(r).valueOf()}span(e){return A.seconds(e/this.valueOf())}byteSpan(e,r){return this.span(e.valueOf()/r.valueOf())}static hz(e){return new ue(e)}static khz(e){return ue.hz(e*1e3)}};l(te,"z",i.z.union([i.z.number().transform(t=>new te(t)),i.z.instanceof(Number).transform(t=>new te(t)),i.z.instanceof(te)]));const T=class extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}length(e){return e.valueOf()/this.valueOf()}size(e){return new Vr(e*this.valueOf())}};l(T,"UNKNOWN",new T(0)),l(T,"BIT128",new T(16)),l(T,"BIT64",new T(8)),l(T,"BIT32",new T(4)),l(T,"BIT16",new T(2)),l(T,"BIT8",new T(1)),l(T,"z",i.z.union([i.z.number().transform(t=>new T(t)),i.z.instanceof(Number).transform(t=>new T(t)),i.z.instanceof(T)]));let N=T;const $=class ce{constructor(e,r){l(this,"start"),l(this,"end"),typeof e=="object"&&"start"in e?(this.start=new S(e.start),this.end=new S(e.end)):(this.start=new S(e),this.end=new S(r))}get span(){return new A(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 ce(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=A.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=S.max(n.start,e.start),a=S.min(n.end,e.end);return a.before(s)?!1:new A(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 ce?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const r=new ce(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 $(S.MIN,S.MAX)),l($,"MIN",new $(S.MAX,S.MIN)),l($,"ZERO",new $(S.ZERO,S.ZERO)),l($,"z",i.z.union([i.z.object({start:S.z,end:S.z}).transform(t=>new $(t.start,t.end)),i.z.instanceof($)]));let Zr=$;const u=class x extends String{constructor(e){if(e instanceof x||typeof e=="string"||typeof e.valueOf()=="string"){super(e.valueOf());return}else{const r=x.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);if(r!=null){super(r.valueOf());return}}throw super(x.UNKNOWN.valueOf()),new Error(`unable to find data type for ${e.toString()}`)}get Array(){const e=x.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(x.JSON)||this.equals(x.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(x.UUID)}get isInteger(){return this.toString().startsWith("int")}get isFloat(){return this.toString().startsWith("float")}get density(){const e=x.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 x.BIG_INT_TYPES.some(e=>e.equals(this))}};l(u,"UNKNOWN",new u("unknown")),l(u,"FLOAT64",new u("float64")),l(u,"FLOAT32",new u("float32")),l(u,"INT64",new u("int64")),l(u,"INT32",new u("int32")),l(u,"INT16",new u("int16")),l(u,"INT8",new u("int8")),l(u,"UINT64",new u("uint64")),l(u,"UINT32",new u("uint32")),l(u,"UINT16",new u("uint16")),l(u,"UINT8",new u("uint8")),l(u,"BOOLEAN",u.UINT8),l(u,"TIMESTAMP",new u("timestamp")),l(u,"UUID",new u("uuid")),l(u,"STRING",new u("string")),l(u,"JSON",new u("json")),l(u,"ARRAY_CONSTRUCTORS",new Map([[u.UINT8.toString(),Uint8Array],[u.UINT16.toString(),Uint16Array],[u.UINT32.toString(),Uint32Array],[u.UINT64.toString(),BigUint64Array],[u.FLOAT32.toString(),Float32Array],[u.FLOAT64.toString(),Float64Array],[u.INT8.toString(),Int8Array],[u.INT16.toString(),Int16Array],[u.INT32.toString(),Int32Array],[u.INT64.toString(),BigInt64Array],[u.TIMESTAMP.toString(),BigInt64Array],[u.STRING.toString(),Uint8Array],[u.JSON.toString(),Uint8Array],[u.UUID.toString(),Uint8Array]])),l(u,"ARRAY_CONSTRUCTOR_DATA_TYPES",new Map([[Uint8Array.name,u.UINT8],[Uint16Array.name,u.UINT16],[Uint32Array.name,u.UINT32],[BigUint64Array.name,u.UINT64],[Float32Array.name,u.FLOAT32],[Float64Array.name,u.FLOAT64],[Int8Array.name,u.INT8],[Int16Array.name,u.INT16],[Int32Array.name,u.INT32],[BigInt64Array.name,u.INT64]])),l(u,"DENSITIES",new Map([[u.UINT8.toString(),N.BIT8],[u.UINT16.toString(),N.BIT16],[u.UINT32.toString(),N.BIT32],[u.UINT64.toString(),N.BIT64],[u.FLOAT32.toString(),N.BIT32],[u.FLOAT64.toString(),N.BIT64],[u.INT8.toString(),N.BIT8],[u.INT16.toString(),N.BIT16],[u.INT32.toString(),N.BIT32],[u.INT64.toString(),N.BIT64],[u.TIMESTAMP.toString(),N.BIT64],[u.STRING.toString(),N.UNKNOWN],[u.JSON.toString(),N.UNKNOWN],[u.UUID.toString(),N.BIT128]])),l(u,"ALL",[u.UNKNOWN,u.FLOAT64,u.FLOAT32,u.INT64,u.INT32,u.INT16,u.INT8,u.UINT64,u.UINT32,u.UINT16,u.UINT8,u.TIMESTAMP,u.UUID,u.STRING,u.JSON]),l(u,"BIG_INT_TYPES",[u.INT64,u.UINT64,u.TIMESTAMP]),l(u,"z",i.z.union([i.z.string().transform(t=>new u(t)),i.z.instanceof(u)]));const I=class w extends Number{constructor(e){super(e.valueOf())}largerThan(e){return this.valueOf()>e.valueOf()}smallerThan(e){return this.valueOf()<e.valueOf()}add(e){return w.bytes(this.valueOf()+e.valueOf())}sub(e){return w.bytes(this.valueOf()-e.valueOf())}truncate(e){return new w(Math.trunc(this.valueOf()/e.valueOf())*e.valueOf())}remainder(e){return w.bytes(this.valueOf()%e.valueOf())}get gigabytes(){return this.valueOf()/w.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/w.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/w.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/w.TERABYTE.valueOf()}toString(){const e=this.truncate(w.TERABYTE),r=this.truncate(w.GIGABYTE),n=this.truncate(w.MEGABYTE),s=this.truncate(w.KILOBYTE),a=this.truncate(w.BYTE),o=e,c=r.sub(e),h=n.sub(r),m=s.sub(n),b=a.sub(s);let O="";return o.isZero||(O+=`${o.terabytes}TB `),c.isZero||(O+=`${c.gigabytes}GB `),h.isZero||(O+=`${h.megabytes}MB `),m.isZero||(O+=`${m.kilobytes}KB `),(!b.isZero||O==="")&&(O+=`${b.valueOf()}B`),O.trim()}static bytes(e=1){return new w(e)}static kilobytes(e=1){return w.bytes(e.valueOf()*1e3)}static megabytes(e=1){return w.kilobytes(e.valueOf()*1e3)}static gigabytes(e=1){return w.megabytes(e.valueOf()*1e3)}static terabytes(e){return w.gigabytes(e.valueOf()*1e3)}get isZero(){return this.valueOf()===0}};l(I,"BYTE",new I(1)),l(I,"KILOBYTE",I.kilobytes(1)),l(I,"MEGABYTE",I.megabytes(1)),l(I,"GIGABYTE",I.gigabytes(1)),l(I,"TERABYTE",I.terabytes(1)),l(I,"ZERO",new I(0)),l(I,"z",i.z.union([i.z.number().transform(t=>new I(t)),i.z.instanceof(I)]));let Vr=I;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 Kr=Object.defineProperty,Fr=(t,e,r)=>e in t?Kr(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,J=(t,e,r)=>(Fr(t,typeof e!="symbol"?e+"":e,r),r);const Wr=(...t)=>t.map($t).join(""),$t=t=>(t.endsWith("/")||(t+="/"),t.startsWith("/")&&(t=t.slice(1)),t),qr=t=>t.endsWith("/")?t.slice(0,-1):t,Gr=(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("&"),Ie=class Ne{constructor({host:e,port:r,protocol:n="",pathPrefix:s=""}){J(this,"protocol"),J(this,"host"),J(this,"port"),J(this,"path"),this.protocol=n,this.host=e,this.port=r,this.path=$t(s)}replace(e){return new Ne({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new Ne({...this,pathPrefix:Wr(this.path,e)})}toString(){return qr(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}};J(Ie,"UNKNOWN",new Ie({host:"unknown",port:0}));let Hr=Ie;var Xr=Object.defineProperty,Jr=(t,e,r)=>e in t?Xr(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Se=(t,e,r)=>(Jr(t,typeof e!="symbol"?e+"":e,r),r);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(t=>new F(t)),i.z.instanceof(Number).transform(t=>new F(t))]));i.z.object({name:i.z.string(),key:i.z.string()});i.z.string().regex(/^\d+\.\d+\.\d+$/);const ve=t=>e=>e!=null&&typeof e=="object"&&"type"in e&&typeof e.type=="string"?e.type.includes(t):e instanceof Error?e.message.includes(t):typeof e!="string"?!1:e.includes(t);class _ extends Error{constructor(r){super(r);y(this,"discriminator","FreighterError");y(this,"type","")}}const Qr=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},He="unknown",Xe="nil",_r="freighter",Le=i.z.object({type:i.z.string(),data:i.z.string()});class en{constructor(){y(this,"providers",[])}register(e){this.providers.push(e)}encode(e){if(e==null)return{type:Xe,data:""};if(Qr(e))for(const r of this.providers){const n=r.encode(e);if(n!=null)return n}return{type:He,data:JSON.stringify(e)}}decode(e){if(e==null||e.type===Xe)return null;if(e.type===He)return new Je(e.data);for(const r of this.providers){const n=r.decode(e);if(n!=null)return n}return new Je(e.data)}}const Ye=new en,xt=({encode:t,decode:e})=>Ye.register({encode:t,decode:e}),tn=t=>Ye.encode(t),Ze=t=>Ye.decode(t);class Je extends _{constructor(r){super(r);y(this,"type","unknown")}}const Oe="freighter.",W=class W extends _{constructor(){super("EOF");y(this,"type",W.TYPE)}};y(W,"TYPE",Oe+"eof"),y(W,"matches",ve(W.TYPE));let Y=W;const q=class q extends _{constructor(){super("StreamClosed");y(this,"type",q.TYPE)}};y(q,"TYPE",Oe+"stream_closed"),y(q,"matches",ve(q.TYPE));let Z=q;const G=class G extends _{constructor(r={}){const{message:n="Unreachable",url:s=Hr.UNKNOWN}=r;super(n);y(this,"type",G.TYPE);y(this,"url");this.url=s}};y(G,"TYPE",Oe+"unreachable"),y(G,"matches",ve(G.TYPE));let V=G;const rn=t=>{if(!t.type.startsWith(_r))return null;if(Y.matches(t))return{type:Y.TYPE,data:"EOF"};if(Z.matches(t))return{type:Z.TYPE,data:"StreamClosed"};if(V.matches(t))return{type:V.TYPE,data:"Unreachable"};throw new Error(`Unknown error type: ${t.type}: ${t.message}`)},nn=t=>{if(!t.type.startsWith(Oe))return null;switch(t.type){case Y.TYPE:return new Y;case Z.TYPE:return new Z;case V.TYPE:return new V;default:throw new Error(`Unknown error type: ${t.data}`)}};xt({encode:rn,decode:nn});class jt{constructor(){y(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 o=this.middleware[n];return n++,await o(a,s)};return await s(e)}}const Ut="Content-Type",Qe=t=>{if(Et.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 sn extends jt{constructor(r,n,s=!1){super();y(this,"endpoint");y(this,"encoder");y(this,"fetch");return this.endpoint=r.replace({protocol:s?"https":"http"}),this.encoder=n,this.fetch=Qe(this.endpoint.protocol),new Proxy(this,{get:(a,o,c)=>o==="endpoint"?this.endpoint:Reflect.get(a,o,c)})}get headers(){return{[Ut]:this.encoder.contentType}}async send(r,n,s,a){n=s==null?void 0:s.parse(n);let o=null;const c=this.endpoint.child(r),h={};h.method="POST",h.body=this.encoder.encode(n??{});const[,m]=await this.executeMiddleware({target:c.toString(),protocol:this.endpoint.protocol,params:{},role:"client"},async b=>{const O={...b,params:{}};h.headers={...this.headers,...b.params};let C;try{C=await Qe(b.protocol)(b.target,h)}catch(j){let z=j;return z.message==="Load failed"&&(z=new V({url:c})),[O,z]}const H=await C.arrayBuffer();if(C!=null&&C.ok)return a!=null&&(o=this.encoder.decode(H,a)),[O,null];try{if(C.status!==400)return[O,new Error(C.statusText)];const j=this.encoder.decode(H,Le),z=Ze(j);return[O,z]}catch(j){return[O,new Error(`[freighter] - failed to decode error: ${C.statusText}: ${j.message}`)]}});return[o,m]}}const an=async(t,e,r,n,s)=>{const[a,o]=await t.send(e,r,n,s);if(o!=null)throw o;return a},on=()=>Et.RUNTIME!=="node"?t=>new WebSocket(t):t=>new(require("ws")).WebSocket(t,{rejectUnauthorized:!1}),un=i.z.object({type:i.z.union([i.z.literal("data"),i.z.literal("close")]),payload:i.z.unknown().optional(),error:i.z.optional(Le)});class cn{constructor(e,r,n,s){y(this,"encoder");y(this,"reqSchema");y(this,"resSchema");y(this,"ws");y(this,"serverClosed");y(this,"sendClosed");y(this,"receiveDataQueue",[]);y(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 Y;if(this.sendClosed)throw new Z;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=Ze(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,un)),this.ws.onclose=e=>this.addMessage({type:"close",error:{type:pn(e)?Y.TYPE:Z.TYPE,data:""}})}}const ln="freighterctx",fn=1e3,dn=1001,hn=[fn,dn],pn=t=>hn.includes(t.code),fe=class fe extends jt{constructor(r,n,s=!1){super();y(this,"baseUrl");y(this,"encoder");this.baseUrl=r.replace({protocol:s?"wss":"ws"}),this.encoder=n}async stream(r,n,s){const a=on();let o;const[,c]=await this.executeMiddleware({target:r,protocol:"websocket",params:{},role:"client"},async h=>{const m=a(this.buildURL(r,h)),b={...h,params:{}};m.binaryType=fe.MESSAGE_TYPE;const O=await this.wrapSocket(m,n,s);return O instanceof Error?[b,O]:(o=O,[b,null])});if(c!=null)throw c;return o}buildURL(r,n){const s=Gr({[Ut]:this.encoder.contentType,...n.params},ln);return this.baseUrl.child(r).toString()+s}async wrapSocket(r,n,s){return await new Promise(a=>{r.onopen=()=>{a(new cn(r,this.encoder,n,s))},r.onerror=o=>{const c=o;a(new Error(c.message))}})}};y(fe,"MESSAGE_TYPE","arraybuffer");let ze=fe;exports.BaseTypedError=_;exports.EOF=Y;exports.HTTPClient=sn;exports.StreamClosed=Z;exports.Unreachable=V;exports.WebSocketClient=ze;exports.decodeError=Ze;exports.encodeError=tn;exports.errorMatcher=ve;exports.errorZ=Le;exports.registerError=xt;exports.sendRequired=an;
|