@synnaxlabs/freighter 0.42.3 → 0.44.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/.vscode/settings.json +2 -2
- package/dist/errors.d.ts +5 -5
- package/dist/errors.d.ts.map +1 -1
- package/dist/freighter.cjs +4 -11
- package/dist/freighter.js +1693 -2237
- package/dist/http.d.ts +1 -2
- package/dist/http.d.ts.map +1 -1
- package/dist/stream.d.ts +7 -7
- package/dist/stream.d.ts.map +1 -1
- package/dist/unary.d.ts +3 -3
- package/dist/unary.d.ts.map +1 -1
- package/dist/websocket.d.ts +1 -1
- package/dist/websocket.d.ts.map +1 -1
- package/eslint.config.js +1 -1
- package/package.json +15 -16
- package/src/alamos.ts +3 -3
- package/src/errors.ts +5 -5
- package/src/http.spec.ts +22 -0
- package/src/http.ts +15 -28
- package/src/stream.ts +7 -7
- package/src/unary.ts +10 -13
- package/src/websocket.ts +8 -20
- package/tsconfig.json +1 -1
- package/README.md +0 -3
package/.vscode/settings.json
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
}
|
|
2
|
+
"vitest.disableWorkspaceWarning": true
|
|
3
|
+
}
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
import { errors, URL } from '@synnaxlabs/x';
|
|
2
2
|
declare const FreighterError_base: errors.TypedClass;
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Base class for all freighter-specific errors
|
|
5
5
|
*/
|
|
6
6
|
export declare class FreighterError extends FreighterError_base {
|
|
7
7
|
}
|
|
8
8
|
declare const EOF_base: errors.TypedClass;
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* Error thrown when reaching the end of a file or stream
|
|
11
11
|
*/
|
|
12
12
|
export declare class EOF extends EOF_base {
|
|
13
13
|
constructor();
|
|
14
14
|
}
|
|
15
15
|
declare const StreamClosed_base: errors.TypedClass;
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
17
|
+
* Error thrown when attempting to operate on a closed stream
|
|
18
18
|
*/
|
|
19
19
|
export declare class StreamClosed extends StreamClosed_base {
|
|
20
20
|
constructor();
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
|
-
*
|
|
23
|
+
* Arguments for constructing an Unreachable error
|
|
24
24
|
*/
|
|
25
25
|
export interface UnreachableArgs {
|
|
26
26
|
message?: string;
|
|
27
27
|
url?: URL;
|
|
28
28
|
}
|
|
29
29
|
declare const Unreachable_base: errors.TypedClass;
|
|
30
|
-
/**
|
|
30
|
+
/** Thrown when a network target is unreachable. */
|
|
31
31
|
export declare class Unreachable extends Unreachable_base {
|
|
32
32
|
url: URL;
|
|
33
33
|
constructor(args?: UnreachableArgs);
|
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,MAAM,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;;AAE5C;;GAEG;AACH,qBAAa,cAAe,SAAQ,mBAA+B;CAAG;;AAEtE;;GAEG;AACH,qBAAa,GAAI,SAAQ,QAAyB;;CAIjD;;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,iBAAmC;;CAIpE;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,GAAG,CAAC;CACX;;AAED,
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,eAAe,CAAC;;AAE5C;;GAEG;AACH,qBAAa,cAAe,SAAQ,mBAA+B;CAAG;;AAEtE;;GAEG;AACH,qBAAa,GAAI,SAAQ,QAAyB;;CAIjD;;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,iBAAmC;;CAIpE;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,GAAG,CAAC;CACX;;AAED,mDAAmD;AACnD,qBAAa,WAAY,SAAQ,gBAAiC;IAChE,GAAG,EAAE,GAAG,CAAC;gBAEG,IAAI,GAAE,eAAoB;CAKvC"}
|
package/dist/freighter.cjs
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
"use strict";var Dt=Object.defineProperty;var kt=(s,e,t)=>e in s?Dt(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var S=(s,e,t)=>kt(s,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("zod"),Lt=s=>{const e=s.replace(/_[a-z]/g,t=>t[1].toUpperCase());return e.length>1&&e[0]===e[0].toUpperCase()&&e[1]===e[1].toUpperCase()||e.length===0?e:e[0].toLowerCase()+e.slice(1)},ot=s=>{const e=(t,r=Se)=>{if(typeof t=="string")return s(t);if(Array.isArray(t))return t.map(o=>e(o,r));if(!me(t))return t;r=jt(r);const n={},a=t;return Object.keys(a).forEach(o=>{let c=a[o];const d=s(o);r.recursive&&(me(c)?qe(c,r.keepTypesOnRecursion)||(c=e(c,r)):r.recursiveInArray&&We(c)&&(c=[...c].map(p=>{let y=p;return me(p)?qe(y,r.keepTypesOnRecursion)||(y=e(p,r)):We(p)&&(y=e({key:p},r).key),y}))),n[d]=c}),n};return e},Re=ot(Lt),Pt=s=>s.replace(/([a-z0-9])([A-Z])/g,(e,t,r)=>`${t}_${r.toLowerCase()}`),ht=ot(Pt),Se={recursive:!0,recursiveInArray:!0,keepTypesOnRecursion:[Number,String,Uint8Array]},jt=(s=Se)=>(s.recursive==null?s=Se:s.recursiveInArray??(s.recursiveInArray=!1),s),We=s=>s!=null&&Array.isArray(s),me=s=>s!=null&&typeof s=="object"&&!Array.isArray(s),qe=(s,e)=>(e||[]).some(t=>s instanceof t),De=s=>s!=null&&typeof s=="object"&&!Array.isArray(s);var Ft=Object.defineProperty,Yt=(s,e,t)=>e in s?Ft(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,H=(s,e,t)=>Yt(s,typeof e!="symbol"?e+"":e,t);function Wt(s){const e=s.length;let t=0,r=0;for(;r<e;){let n=s.charCodeAt(r++);if((n&4294967168)===0){t++;continue}else if((n&4294965248)===0)t+=2;else{if(n>=55296&&n<=56319&&r<e){const a=s.charCodeAt(r);(a&64512)===56320&&(++r,n=((n&1023)<<10)+(a&1023)+65536)}(n&4294901760)===0?t+=3:t+=4}}return t}function qt(s,e,t){const r=s.length;let n=t,a=0;for(;a<r;){let o=s.charCodeAt(a++);if((o&4294967168)===0){e[n++]=o;continue}else if((o&4294965248)===0)e[n++]=o>>6&31|192;else{if(o>=55296&&o<=56319&&a<r){const c=s.charCodeAt(a);(c&64512)===56320&&(++a,o=((o&1023)<<10)+(c&1023)+65536)}(o&4294901760)===0?(e[n++]=o>>12&15|224,e[n++]=o>>6&63|128):(e[n++]=o>>18&7|240,e[n++]=o>>12&63|128,e[n++]=o>>6&63|128)}e[n++]=o&63|128}}const Vt=new TextEncoder,Zt=50;function Ht(s,e,t){Vt.encodeInto(s,e.subarray(t))}function Gt(s,e,t){s.length>Zt?Ht(s,e,t):qt(s,e,t)}const Kt=4096;function ut(s,e,t){let r=e;const n=r+t,a=[];let o="";for(;r<n;){const c=s[r++];if((c&128)===0)a.push(c);else if((c&224)===192){const d=s[r++]&63;a.push((c&31)<<6|d)}else if((c&240)===224){const d=s[r++]&63,p=s[r++]&63;a.push((c&31)<<12|d<<6|p)}else if((c&248)===240){const d=s[r++]&63,p=s[r++]&63,y=s[r++]&63;let l=(c&7)<<18|d<<12|p<<6|y;l>65535&&(l-=65536,a.push(l>>>10&1023|55296),l=56320|l&1023),a.push(l)}else a.push(c);a.length>=Kt&&(o+=String.fromCharCode(...a),a.length=0)}return a.length>0&&(o+=String.fromCharCode(...a)),o}const Jt=new TextDecoder,Xt=200;function Qt(s,e,t){const r=s.subarray(e,e+t);return Jt.decode(r)}function _t(s,e,t){return t>Xt?Qt(s,e,t):ut(s,e,t)}let ue=class{constructor(e,t){this.type=e,this.data=t}},M=class Ie extends Error{constructor(e){super(e);const t=Object.create(Ie.prototype);Object.setPrototypeOf(this,t),Object.defineProperty(this,"name",{configurable:!0,enumerable:!1,value:Ie.name})}};const K=4294967295;function es(s,e,t){const r=t/4294967296,n=t;s.setUint32(e,r),s.setUint32(e+4,n)}function ct(s,e,t){const r=Math.floor(t/4294967296),n=t;s.setUint32(e,r),s.setUint32(e+4,n)}function lt(s,e){const t=s.getInt32(e),r=s.getUint32(e+4);return t*4294967296+r}function ts(s,e){const t=s.getUint32(e),r=s.getUint32(e+4);return t*4294967296+r}const ss=-1,rs=4294967296-1,ns=17179869184-1;function is({sec:s,nsec:e}){if(s>=0&&e>=0&&s<=ns)if(e===0&&s<=rs){const t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,s),t}else{const t=s/4294967296,r=s&4294967295,n=new Uint8Array(8),a=new DataView(n.buffer);return a.setUint32(0,e<<2|t&3),a.setUint32(4,r),n}else{const t=new Uint8Array(12),r=new DataView(t.buffer);return r.setUint32(0,e),ct(r,4,s),t}}function as(s){const e=s.getTime(),t=Math.floor(e/1e3),r=(e-t*1e3)*1e6,n=Math.floor(r/1e9);return{sec:t+n,nsec:r-n*1e9}}function os(s){if(s instanceof Date){const e=as(s);return is(e)}else return null}function hs(s){const e=new DataView(s.buffer,s.byteOffset,s.byteLength);switch(s.byteLength){case 4:return{sec:e.getUint32(0),nsec:0};case 8:{const t=e.getUint32(0),r=e.getUint32(4),n=(t&3)*4294967296+r,a=t>>>2;return{sec:n,nsec:a}}case 12:{const t=lt(e,4),r=e.getUint32(0);return{sec:t,nsec:r}}default:throw new M(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${s.length}`)}}function us(s){const e=hs(s);return new Date(e.sec*1e3+e.nsec/1e6)}const cs={type:ss,encode:os,decode:us};let oe=class{constructor(){this.builtInEncoders=[],this.builtInDecoders=[],this.encoders=[],this.decoders=[],this.register(cs)}register({type:e,encode:t,decode:r}){if(e>=0)this.encoders[e]=t,this.decoders[e]=r;else{const n=-1-e;this.builtInEncoders[n]=t,this.builtInDecoders[n]=r}}tryToEncode(e,t){for(let r=0;r<this.builtInEncoders.length;r++){const n=this.builtInEncoders[r];if(n!=null){const a=n(e,t);if(a!=null){const o=-1-r;return new ue(o,a)}}}for(let r=0;r<this.encoders.length;r++){const n=this.encoders[r];if(n!=null){const a=n(e,t);if(a!=null){const o=r;return new ue(o,a)}}}return e instanceof ue?e:null}decode(e,t,r){const n=t<0?this.builtInDecoders[-1-t]:this.decoders[t];return n?n(e,t,r):new ue(t,e)}};oe.defaultCodec=new oe;function ls(s){return s instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&s instanceof SharedArrayBuffer}function Ue(s){return s instanceof Uint8Array?s:ArrayBuffer.isView(s)?new Uint8Array(s.buffer,s.byteOffset,s.byteLength):ls(s)?new Uint8Array(s):Uint8Array.from(s)}const ds=100,fs=2048;let gs=class dt{constructor(e){this.entered=!1,this.extensionCodec=(e==null?void 0:e.extensionCodec)??oe.defaultCodec,this.context=e==null?void 0:e.context,this.useBigInt64=(e==null?void 0:e.useBigInt64)??!1,this.maxDepth=(e==null?void 0:e.maxDepth)??ds,this.initialBufferSize=(e==null?void 0:e.initialBufferSize)??fs,this.sortKeys=(e==null?void 0:e.sortKeys)??!1,this.forceFloat32=(e==null?void 0:e.forceFloat32)??!1,this.ignoreUndefined=(e==null?void 0:e.ignoreUndefined)??!1,this.forceIntegerToFloat=(e==null?void 0:e.forceIntegerToFloat)??!1,this.pos=0,this.view=new DataView(new ArrayBuffer(this.initialBufferSize)),this.bytes=new Uint8Array(this.view.buffer)}clone(){return new dt({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,maxDepth:this.maxDepth,initialBufferSize:this.initialBufferSize,sortKeys:this.sortKeys,forceFloat32:this.forceFloat32,ignoreUndefined:this.ignoreUndefined,forceIntegerToFloat:this.forceIntegerToFloat})}reinitializeState(){this.pos=0}encodeSharedRef(e){if(this.entered)return this.clone().encodeSharedRef(e);try{return this.entered=!0,this.reinitializeState(),this.doEncode(e,1),this.bytes.subarray(0,this.pos)}finally{this.entered=!1}}encode(e){if(this.entered)return this.clone().encode(e);try{return this.entered=!0,this.reinitializeState(),this.doEncode(e,1),this.bytes.slice(0,this.pos)}finally{this.entered=!1}}doEncode(e,t){if(t>this.maxDepth)throw new Error(`Too deep objects in depth ${t}`);e==null?this.encodeNil():typeof e=="boolean"?this.encodeBoolean(e):typeof e=="number"?this.forceIntegerToFloat?this.encodeNumberAsFloat(e):this.encodeNumber(e):typeof e=="string"?this.encodeString(e):this.useBigInt64&&typeof e=="bigint"?this.encodeBigInt64(e):this.encodeObject(e,t)}ensureBufferSizeToWrite(e){const t=this.pos+e;this.view.byteLength<t&&this.resizeBuffer(t*2)}resizeBuffer(e){const t=new ArrayBuffer(e),r=new Uint8Array(t),n=new DataView(t);r.set(this.bytes),this.view=n,this.bytes=r}encodeNil(){this.writeU8(192)}encodeBoolean(e){e===!1?this.writeU8(194):this.writeU8(195)}encodeNumber(e){!this.forceIntegerToFloat&&Number.isSafeInteger(e)?e>=0?e<128?this.writeU8(e):e<256?(this.writeU8(204),this.writeU8(e)):e<65536?(this.writeU8(205),this.writeU16(e)):e<4294967296?(this.writeU8(206),this.writeU32(e)):this.useBigInt64?this.encodeNumberAsFloat(e):(this.writeU8(207),this.writeU64(e)):e>=-32?this.writeU8(224|e+32):e>=-128?(this.writeU8(208),this.writeI8(e)):e>=-32768?(this.writeU8(209),this.writeI16(e)):e>=-2147483648?(this.writeU8(210),this.writeI32(e)):this.useBigInt64?this.encodeNumberAsFloat(e):(this.writeU8(211),this.writeI64(e)):this.encodeNumberAsFloat(e)}encodeNumberAsFloat(e){this.forceFloat32?(this.writeU8(202),this.writeF32(e)):(this.writeU8(203),this.writeF64(e))}encodeBigInt64(e){e>=BigInt(0)?(this.writeU8(207),this.writeBigUint64(e)):(this.writeU8(211),this.writeBigInt64(e))}writeStringHeader(e){if(e<32)this.writeU8(160+e);else if(e<256)this.writeU8(217),this.writeU8(e);else if(e<65536)this.writeU8(218),this.writeU16(e);else if(e<4294967296)this.writeU8(219),this.writeU32(e);else throw new Error(`Too long string: ${e} bytes in UTF-8`)}encodeString(e){const t=Wt(e);this.ensureBufferSizeToWrite(5+t),this.writeStringHeader(t),Gt(e,this.bytes,this.pos),this.pos+=t}encodeObject(e,t){const r=this.extensionCodec.tryToEncode(e,this.context);if(r!=null)this.encodeExtension(r);else if(Array.isArray(e))this.encodeArray(e,t);else if(ArrayBuffer.isView(e))this.encodeBinary(e);else if(typeof e=="object")this.encodeMap(e,t);else throw new Error(`Unrecognized object: ${Object.prototype.toString.apply(e)}`)}encodeBinary(e){const t=e.byteLength;if(t<256)this.writeU8(196),this.writeU8(t);else if(t<65536)this.writeU8(197),this.writeU16(t);else if(t<4294967296)this.writeU8(198),this.writeU32(t);else throw new Error(`Too large binary: ${t}`);const r=Ue(e);this.writeU8a(r)}encodeArray(e,t){const r=e.length;if(r<16)this.writeU8(144+r);else if(r<65536)this.writeU8(220),this.writeU16(r);else if(r<4294967296)this.writeU8(221),this.writeU32(r);else throw new Error(`Too large array: ${r}`);for(const n of e)this.doEncode(n,t+1)}countWithoutUndefined(e,t){let r=0;for(const n of t)e[n]!==void 0&&r++;return r}encodeMap(e,t){const r=Object.keys(e);this.sortKeys&&r.sort();const n=this.ignoreUndefined?this.countWithoutUndefined(e,r):r.length;if(n<16)this.writeU8(128+n);else if(n<65536)this.writeU8(222),this.writeU16(n);else if(n<4294967296)this.writeU8(223),this.writeU32(n);else throw new Error(`Too large map object: ${n}`);for(const a of r){const o=e[a];this.ignoreUndefined&&o===void 0||(this.encodeString(a),this.doEncode(o,t+1))}}encodeExtension(e){if(typeof e.data=="function"){const r=e.data(this.pos+6),n=r.length;if(n>=4294967296)throw new Error(`Too large extension object: ${n}`);this.writeU8(201),this.writeU32(n),this.writeI8(e.type),this.writeU8a(r);return}const t=e.data.length;if(t===1)this.writeU8(212);else if(t===2)this.writeU8(213);else if(t===4)this.writeU8(214);else if(t===8)this.writeU8(215);else if(t===16)this.writeU8(216);else if(t<256)this.writeU8(199),this.writeU8(t);else if(t<65536)this.writeU8(200),this.writeU16(t);else if(t<4294967296)this.writeU8(201),this.writeU32(t);else throw new Error(`Too large extension object: ${t}`);this.writeI8(e.type),this.writeU8a(e.data)}writeU8(e){this.ensureBufferSizeToWrite(1),this.view.setUint8(this.pos,e),this.pos++}writeU8a(e){const t=e.length;this.ensureBufferSizeToWrite(t),this.bytes.set(e,this.pos),this.pos+=t}writeI8(e){this.ensureBufferSizeToWrite(1),this.view.setInt8(this.pos,e),this.pos++}writeU16(e){this.ensureBufferSizeToWrite(2),this.view.setUint16(this.pos,e),this.pos+=2}writeI16(e){this.ensureBufferSizeToWrite(2),this.view.setInt16(this.pos,e),this.pos+=2}writeU32(e){this.ensureBufferSizeToWrite(4),this.view.setUint32(this.pos,e),this.pos+=4}writeI32(e){this.ensureBufferSizeToWrite(4),this.view.setInt32(this.pos,e),this.pos+=4}writeF32(e){this.ensureBufferSizeToWrite(4),this.view.setFloat32(this.pos,e),this.pos+=4}writeF64(e){this.ensureBufferSizeToWrite(8),this.view.setFloat64(this.pos,e),this.pos+=8}writeU64(e){this.ensureBufferSizeToWrite(8),es(this.view,this.pos,e),this.pos+=8}writeI64(e){this.ensureBufferSizeToWrite(8),ct(this.view,this.pos,e),this.pos+=8}writeBigUint64(e){this.ensureBufferSizeToWrite(8),this.view.setBigUint64(this.pos,e),this.pos+=8}writeBigInt64(e){this.ensureBufferSizeToWrite(8),this.view.setBigInt64(this.pos,e),this.pos+=8}};function X(s,e){return new gs(e).encodeSharedRef(s)}function be(s){return`${s<0?"-":""}0x${Math.abs(s).toString(16).padStart(2,"0")}`}const ps=16,ys=16;class ws{constructor(e=ps,t=ys){this.hit=0,this.miss=0,this.maxKeyLength=e,this.maxLengthPerKey=t,this.caches=[];for(let r=0;r<this.maxKeyLength;r++)this.caches.push([])}canBeCached(e){return e>0&&e<=this.maxKeyLength}find(e,t,r){const n=this.caches[r-1];e:for(const a of n){const o=a.bytes;for(let c=0;c<r;c++)if(o[c]!==e[t+c])continue e;return a.str}return null}store(e,t){const r=this.caches[e.length-1],n={bytes:e,str:t};r.length>=this.maxLengthPerKey?r[Math.random()*r.length|0]=n:r.push(n)}decode(e,t,r){const n=this.find(e,t,r);if(n!=null)return this.hit++,n;this.miss++;const a=ut(e,t,r),o=Uint8Array.prototype.slice.call(e,t,t+r);return this.store(o,a),a}}const xe="array",ne="map_key",ft="map_value",ms=s=>{if(typeof s=="string"||typeof s=="number")return s;throw new M("The type of key must be string or number but "+typeof s)};class bs{constructor(){this.stack=[],this.stackHeadPosition=-1}get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState(e){const t=this.getUninitializedStateFromPool();t.type=xe,t.position=0,t.size=e,t.array=new Array(e)}pushMapState(e){const t=this.getUninitializedStateFromPool();t.type=ne,t.readCount=0,t.size=e,t.map={}}getUninitializedStateFromPool(){if(this.stackHeadPosition++,this.stackHeadPosition===this.stack.length){const e={type:void 0,size:0,array:void 0,position:0,readCount:0,map:void 0,key:null};this.stack.push(e)}return this.stack[this.stackHeadPosition]}release(e){if(this.stack[this.stackHeadPosition]!==e)throw new Error("Invalid stack state. Released state is not on top of the stack.");if(e.type===xe){const t=e;t.size=0,t.array=void 0,t.position=0,t.type=void 0}if(e.type===ne||e.type===ft){const t=e;t.size=0,t.map=void 0,t.readCount=0,t.type=void 0}this.stackHeadPosition--}reset(){this.stack.length=0,this.stackHeadPosition=-1}}const J=-1,ke=new DataView(new ArrayBuffer(0)),vs=new Uint8Array(ke.buffer);try{ke.getInt8(0)}catch(s){if(!(s instanceof RangeError))throw new Error("This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access")}const Ve=new RangeError("Insufficient data"),Ts=new ws;let Os=class gt{constructor(e){this.totalPos=0,this.pos=0,this.view=ke,this.bytes=vs,this.headByte=J,this.stack=new bs,this.entered=!1,this.extensionCodec=(e==null?void 0:e.extensionCodec)??oe.defaultCodec,this.context=e==null?void 0:e.context,this.useBigInt64=(e==null?void 0:e.useBigInt64)??!1,this.rawStrings=(e==null?void 0:e.rawStrings)??!1,this.maxStrLength=(e==null?void 0:e.maxStrLength)??K,this.maxBinLength=(e==null?void 0:e.maxBinLength)??K,this.maxArrayLength=(e==null?void 0:e.maxArrayLength)??K,this.maxMapLength=(e==null?void 0:e.maxMapLength)??K,this.maxExtLength=(e==null?void 0:e.maxExtLength)??K,this.keyDecoder=(e==null?void 0:e.keyDecoder)!==void 0?e.keyDecoder:Ts,this.mapKeyConverter=(e==null?void 0:e.mapKeyConverter)??ms}clone(){return new gt({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,rawStrings:this.rawStrings,maxStrLength:this.maxStrLength,maxBinLength:this.maxBinLength,maxArrayLength:this.maxArrayLength,maxMapLength:this.maxMapLength,maxExtLength:this.maxExtLength,keyDecoder:this.keyDecoder})}reinitializeState(){this.totalPos=0,this.headByte=J,this.stack.reset()}setBuffer(e){const t=Ue(e);this.bytes=t,this.view=new DataView(t.buffer,t.byteOffset,t.byteLength),this.pos=0}appendBuffer(e){if(this.headByte===J&&!this.hasRemaining(1))this.setBuffer(e);else{const t=this.bytes.subarray(this.pos),r=Ue(e),n=new Uint8Array(t.length+r.length);n.set(t),n.set(r,t.length),this.setBuffer(n)}}hasRemaining(e){return this.view.byteLength-this.pos>=e}createExtraByteError(e){const{view:t,pos:r}=this;return new RangeError(`Extra ${t.byteLength-r} of ${t.byteLength} byte(s) found at buffer[${e}]`)}decode(e){if(this.entered)return this.clone().decode(e);try{this.entered=!0,this.reinitializeState(),this.setBuffer(e);const t=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return t}finally{this.entered=!1}}*decodeMulti(e){if(this.entered){yield*this.clone().decodeMulti(e);return}try{for(this.entered=!0,this.reinitializeState(),this.setBuffer(e);this.hasRemaining(1);)yield this.doDecodeSync()}finally{this.entered=!1}}async decodeAsync(e){if(this.entered)return this.clone().decodeAsync(e);try{this.entered=!0;let t=!1,r;for await(const c of e){if(t)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(c);try{r=this.doDecodeSync(),t=!0}catch(d){if(!(d instanceof RangeError))throw d}this.totalPos+=this.pos}if(t){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return r}const{headByte:n,pos:a,totalPos:o}=this;throw new RangeError(`Insufficient data in parsing ${be(n)} at ${o} (${a} in the current buffer)`)}finally{this.entered=!1}}decodeArrayStream(e){return this.decodeMultiAsync(e,!0)}decodeStream(e){return this.decodeMultiAsync(e,!1)}async*decodeMultiAsync(e,t){if(this.entered){yield*this.clone().decodeMultiAsync(e,t);return}try{this.entered=!0;let r=t,n=-1;for await(const a of e){if(t&&n===0)throw this.createExtraByteError(this.totalPos);this.appendBuffer(a),r&&(n=this.readArraySize(),r=!1,this.complete());try{for(;yield this.doDecodeSync(),--n!==0;);}catch(o){if(!(o instanceof RangeError))throw o}this.totalPos+=this.pos}}finally{this.entered=!1}}doDecodeSync(){e:for(;;){const e=this.readHeadByte();let t;if(e>=224)t=e-256;else if(e<192)if(e<128)t=e;else if(e<144){const n=e-128;if(n!==0){this.pushMapState(n),this.complete();continue e}else t={}}else if(e<160){const n=e-144;if(n!==0){this.pushArrayState(n),this.complete();continue e}else t=[]}else{const n=e-160;t=this.decodeString(n,0)}else if(e===192)t=null;else if(e===194)t=!1;else if(e===195)t=!0;else if(e===202)t=this.readF32();else if(e===203)t=this.readF64();else if(e===204)t=this.readU8();else if(e===205)t=this.readU16();else if(e===206)t=this.readU32();else if(e===207)this.useBigInt64?t=this.readU64AsBigInt():t=this.readU64();else if(e===208)t=this.readI8();else if(e===209)t=this.readI16();else if(e===210)t=this.readI32();else if(e===211)this.useBigInt64?t=this.readI64AsBigInt():t=this.readI64();else if(e===217){const n=this.lookU8();t=this.decodeString(n,1)}else if(e===218){const n=this.lookU16();t=this.decodeString(n,2)}else if(e===219){const n=this.lookU32();t=this.decodeString(n,4)}else if(e===220){const n=this.readU16();if(n!==0){this.pushArrayState(n),this.complete();continue e}else t=[]}else if(e===221){const n=this.readU32();if(n!==0){this.pushArrayState(n),this.complete();continue e}else t=[]}else if(e===222){const n=this.readU16();if(n!==0){this.pushMapState(n),this.complete();continue e}else t={}}else if(e===223){const n=this.readU32();if(n!==0){this.pushMapState(n),this.complete();continue e}else t={}}else if(e===196){const n=this.lookU8();t=this.decodeBinary(n,1)}else if(e===197){const n=this.lookU16();t=this.decodeBinary(n,2)}else if(e===198){const n=this.lookU32();t=this.decodeBinary(n,4)}else if(e===212)t=this.decodeExtension(1,0);else if(e===213)t=this.decodeExtension(2,0);else if(e===214)t=this.decodeExtension(4,0);else if(e===215)t=this.decodeExtension(8,0);else if(e===216)t=this.decodeExtension(16,0);else if(e===199){const n=this.lookU8();t=this.decodeExtension(n,1)}else if(e===200){const n=this.lookU16();t=this.decodeExtension(n,2)}else if(e===201){const n=this.lookU32();t=this.decodeExtension(n,4)}else throw new M(`Unrecognized type byte: ${be(e)}`);this.complete();const r=this.stack;for(;r.length>0;){const n=r.top();if(n.type===xe)if(n.array[n.position]=t,n.position++,n.position===n.size)t=n.array,r.release(n);else continue e;else if(n.type===ne){if(t==="__proto__")throw new M("The key __proto__ is not allowed");n.key=this.mapKeyConverter(t),n.type=ft;continue e}else if(n.map[n.key]=t,n.readCount++,n.readCount===n.size)t=n.map,r.release(n);else{n.key=null,n.type=ne;continue e}}return t}}readHeadByte(){return this.headByte===J&&(this.headByte=this.readU8()),this.headByte}complete(){this.headByte=J}readArraySize(){const e=this.readHeadByte();switch(e){case 220:return this.readU16();case 221:return this.readU32();default:{if(e<160)return e-144;throw new M(`Unrecognized array type byte: ${be(e)}`)}}}pushMapState(e){if(e>this.maxMapLength)throw new M(`Max length exceeded: map length (${e}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState(e)}pushArrayState(e){if(e>this.maxArrayLength)throw new M(`Max length exceeded: array length (${e}) > maxArrayLength (${this.maxArrayLength})`);this.stack.pushArrayState(e)}decodeString(e,t){return!this.rawStrings||this.stateIsMapKey()?this.decodeUtf8String(e,t):this.decodeBinary(e,t)}decodeUtf8String(e,t){var r;if(e>this.maxStrLength)throw new M(`Max length exceeded: UTF-8 byte length (${e}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+t+e)throw Ve;const n=this.pos+t;let a;return this.stateIsMapKey()&&(r=this.keyDecoder)!=null&&r.canBeCached(e)?a=this.keyDecoder.decode(this.bytes,n,e):a=_t(this.bytes,n,e),this.pos+=t+e,a}stateIsMapKey(){return this.stack.length>0?this.stack.top().type===ne:!1}decodeBinary(e,t){if(e>this.maxBinLength)throw new M(`Max length exceeded: bin length (${e}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining(e+t))throw Ve;const r=this.pos+t,n=this.bytes.subarray(r,r+e);return this.pos+=t+e,n}decodeExtension(e,t){if(e>this.maxExtLength)throw new M(`Max length exceeded: ext length (${e}) > maxExtLength (${this.maxExtLength})`);const r=this.view.getInt8(this.pos+t),n=this.decodeBinary(e,t+1);return this.extensionCodec.decode(n,r,this.context)}lookU8(){return this.view.getUint8(this.pos)}lookU16(){return this.view.getUint16(this.pos)}lookU32(){return this.view.getUint32(this.pos)}readU8(){const e=this.view.getUint8(this.pos);return this.pos++,e}readI8(){const e=this.view.getInt8(this.pos);return this.pos++,e}readU16(){const e=this.view.getUint16(this.pos);return this.pos+=2,e}readI16(){const e=this.view.getInt16(this.pos);return this.pos+=2,e}readU32(){const e=this.view.getUint32(this.pos);return this.pos+=4,e}readI32(){const e=this.view.getInt32(this.pos);return this.pos+=4,e}readU64(){const e=ts(this.view,this.pos);return this.pos+=8,e}readI64(){const e=lt(this.view,this.pos);return this.pos+=8,e}readU64AsBigInt(){const e=this.view.getBigUint64(this.pos);return this.pos+=8,e}readI64AsBigInt(){const e=this.view.getBigInt64(this.pos);return this.pos+=8,e}readF32(){const e=this.view.getFloat32(this.pos);return this.pos+=4,e}readF64(){const e=this.view.getFloat64(this.pos);return this.pos+=8,e}};function pt(s,e){return new Os(e).decode(s)}let Ss=class{constructor(){H(this,"contentType","application/json"),H(this,"decoder"),H(this,"encoder"),this.decoder=new TextDecoder,this.encoder=new TextEncoder}encode(e){return this.encoder.encode(this.encodeString(e))}decode(e,t){return this.decodeString(this.decoder.decode(e),t)}decodeString(e,t){const r=JSON.parse(e),n=Re(r);return t!=null?t.parse(n):n}encodeString(e){const t=ht(e);return JSON.stringify(t,(r,n)=>ArrayBuffer.isView(n)?Array.from(n):De(n)&&"encode_value"in n?typeof n.value=="bigint"?n.value.toString():n.value:typeof n=="bigint"?n.toString():n)}static registerCustomType(){}},Is=class{constructor(){H(this,"contentType","text/csv")}encode(e){const t=this.encodeString(e);return new TextEncoder().encode(t)}decode(e,t){const r=new TextDecoder().decode(e);return this.decodeString(r,t)}encodeString(e){if(!Array.isArray(e)||e.length===0||!De(e[0]))throw new Error("Payload must be an array of objects");const t=Object.keys(e[0]),r=[t.join(",")];return e.forEach(n=>{const a=t.map(o=>JSON.stringify(n[o]??""));r.push(a.join(","))}),r.join(`
|
|
2
|
-
`)}decodeString(e,t){const[r,...n]=e.trim().split(`
|
|
3
|
-
`).map(c=>c.trim());if(r.length===0)return t!=null?t.parse({}):{};const a=r.split(",").map(c=>c.trim()),o={};return a.forEach(c=>{o[c]=[]}),n.forEach(c=>{const d=c.split(",").map(p=>p.trim());a.forEach((p,y)=>{const l=this.parseValue(d[y]);l!=null&&o[p].push(l)})}),t!=null?t.parse(o):o}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(){}},Us=class{constructor(){H(this,"contentType","text/plain")}encode(e){return new TextEncoder().encode(e)}decode(e,t){const r=new TextDecoder().decode(e);return t!=null?t.parse(r):r}};const P=new oe;P.register({type:0,encode:s=>{if(ArrayBuffer.isView(s)){const e=Array.from(s);return X(e,{extensionCodec:P})}return De(s)&&"encode_value"in s?typeof s.value=="bigint"?X(s.value.toString(),{extensionCodec:P}):X(s.value,{extensionCodec:P}):typeof s=="bigint"?X(s.toString(),{extensionCodec:P}):null},decode:s=>pt(s,{extensionCodec:P})});let xs=class{constructor(){H(this,"contentType","application/msgpack")}encode(e){const t=ht(e);return X(t,{extensionCodec:P}).slice()}decode(e,t){const r=pt(e,{extensionCodec:P}),n=Re(r);return t!=null?t.parse(n):n}static registerCustomType(){}};const de=new Ss;new Is;new Us;new xs;const Ns=s=>s!=null&&typeof s=="object"&&"toString"in s,Es=(s,e=!1)=>{const t=Ns(s)?"stringer":typeof s;let r;switch(t){case"string":r=(n,a)=>n.localeCompare(a);break;case"stringer":r=(n,a)=>n.toString().localeCompare(a.toString());break;case"number":r=(n,a)=>Number(n)-Number(a);break;case"bigint":r=(n,a)=>BigInt(n)-BigInt(a)>0n?1:-1;break;case"boolean":r=(n,a)=>Number(n)-Number(a);break;case"undefined":r=()=>0;break;default:return console.warn(`sortFunc: unknown type ${t}`),()=>-1}return e?zs(r):r},zs=s=>(e,t)=>s(t,e),ye=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()}),As=i.z.object({signedWidth:i.z.number(),signedHeight:i.z.number()}),Bs=["width","height"];i.z.enum(Bs);const $s=["start","center","end"],Ms=["signedWidth","signedHeight"];i.z.enum(Ms);const ge=i.z.object({x:i.z.number(),y:i.z.number()}),Cs=i.z.object({clientX:i.z.number(),clientY:i.z.number()}),Rs=["x","y"],wt=i.z.enum(Rs),mt=["top","right","bottom","left"];i.z.enum(mt);const Ds=["left","right"],bt=i.z.enum(Ds),ks=["top","bottom"],vt=i.z.enum(ks),Tt=["center"],Ze=i.z.enum(Tt),Ls=[...mt,...Tt],Ot=i.z.enum(Ls);i.z.enum($s);const Ps=["first","last"];i.z.enum(Ps);const js=i.z.object({lower:i.z.number(),upper:i.z.number()}),Fs=i.z.object({lower:i.z.bigint(),upper:i.z.bigint()});i.z.union([js,ye]);i.z.union([Fs,ye]);i.z.enum([...wt.options,...Ot.options]);i.z.union([wt,Ot,i.z.instanceof(String)]);const Ys=s=>typeof s=="bigint"||s instanceof BigInt,V=(s,e)=>Ys(s)?s.valueOf()*BigInt(e.valueOf()):s.valueOf()*Number(e.valueOf()),F=(s,e)=>{const t={};if(typeof s=="number"||typeof s=="bigint")e!=null?(t.lower=s,t.upper=e):(t.lower=typeof s=="bigint"?0n:0,t.upper=s);else if(Array.isArray(s)){if(s.length!==2)throw new Error("bounds: expected array of length 2");[t.lower,t.upper]=s}else return He(s);return He(t)},He=s=>s.lower>s.upper?{lower:s.upper,upper:s.lower}:s,Ge=(s,e)=>{const t=F(s);return e<t.lower?t.lower:e>=t.upper?t.upper-(typeof t.upper=="number"?1:1n):e};i.z.object({x:bt.or(Ze),y:vt.or(Ze)});const Ws=i.z.object({x:bt,y:vt}),qs=Object.freeze({x:"left",y:"top"}),Vs=(s,e)=>s.x===e.x&&s.y===e.y,Ke=i.z.union([i.z.number(),ge,ye,yt,As,Cs]),Zs=(s,e)=>{if(typeof s=="string"){if(e===void 0)throw new Error("The y coordinate must be given.");return s==="x"?{x:e,y:0}:{x:0,y:e}}return typeof s=="number"?{x:s,y:e??s}:Array.isArray(s)?{x:s[0],y:s[1]}:"signedWidth"in s?{x:s.signedWidth,y:s.signedHeight}:"clientX"in s?{x:s.clientX,y:s.clientY}:"width"in s?{x:s.width,y:s.height}:{x:s.x,y:s.y}},Je=Object.freeze({x:0,y:0}),ce=i.z.union([i.z.number(),i.z.string()]);i.z.object({top:ce,left:ce,width:ce,height:ce});i.z.object({left:i.z.number(),top:i.z.number(),right:i.z.number(),bottom:i.z.number()});i.z.object({one:ge,two:ge,root:Ws});const Le=(s,e,t=0,r=0,n)=>{const a={one:{...Je},two:{...Je},root:n??qs};if(typeof s=="number"){if(typeof e!="number")throw new Error("Box constructor called with invalid arguments");return a.one={x:s,y:e},a.two={x:a.one.x+t,y:a.one.y+r},a}return"one"in s&&"two"in s&&"root"in s?{...s,root:n??s.root}:("getBoundingClientRect"in s&&(s=s.getBoundingClientRect()),"left"in s?(a.one={x:s.left,y:s.top},a.two={x:s.right,y:s.bottom},a):(a.one=s,e==null?a.two={x:a.one.x+t,y:a.one.y+r}:typeof e=="number"?a.two={x:a.one.x+e,y:a.one.y+t}:"width"in e?a.two={x:a.one.x+e.width,y:a.one.y+e.height}:"signedWidth"in e?a.two={x:a.one.x+e.signedWidth,y:a.one.y+e.signedHeight}:a.two=e,a))},ve=s=>{const e=Le(s);return{lower:e.one.x,upper:e.two.x}},Te=s=>{const e=Le(s);return{lower:e.one.y,upper:e.two.y}},Hs=s=>typeof s!="object"||s==null?!1:"one"in s&&"two"in s&&"root"in s,Gs=i.z.object({signedWidth:i.z.number(),signedHeight:i.z.number()});i.z.union([yt,Gs,ge,ye]);var Ks=Object.defineProperty,Js=(s,e,t)=>e in s?Ks(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,k=(s,e,t)=>Js(s,typeof e!="symbol"?e+"":e,t);const Xs=(s,e,t)=>e!==void 0&&s<e?e:t!==void 0&&s>t?t:s;i.z.object({offset:Ke,scale:Ke});i.z.object({offset:i.z.number(),scale:i.z.number()});const Qs=s=>(e,t,r,n)=>t==="dimension"?[e,r]:[e,n?r-s:r+s],_s=s=>(e,t,r,n)=>[e,n?r/s:r*s],er=s=>(e,t,r)=>{if(e===null)return[s,r];const{lower:n,upper:a}=e,{lower:o,upper:c}=s,d=a-n,p=c-o;if(t==="dimension")return[s,r*(p/d)];const y=(r-n)*(p/d)+o;return[s,y]},tr=s=>(e,t,r)=>[s,r],sr=()=>(s,e,t)=>{if(s===null)throw new Error("cannot invert without bounds");if(e==="dimension")return[s,t];const{lower:r,upper:n}=s;return[s,n-(t-r)]},rr=s=>(e,t,r)=>{const{lower:n,upper:a}=s;return r=Xs(r,n,a),[e,r]},Ne=class Q{constructor(){k(this,"ops",[]),k(this,"currBounds",null),k(this,"currType",null),k(this,"reversed",!1),this.ops=[]}static translate(e){return new Q().translate(e)}static magnify(e){return new Q().magnify(e)}static scale(e,t){return new Q().scale(e,t)}translate(e){const t=this.new(),r=Qs(e);return r.type="translate",t.ops.push(r),t}magnify(e){const t=this.new(),r=_s(e);return r.type="magnify",t.ops.push(r),t}scale(e,t){const r=F(e,t),n=this.new(),a=er(r);return a.type="scale",n.ops.push(a),n}clamp(e,t){const r=F(e,t),n=this.new(),a=rr(r);return a.type="clamp",n.ops.push(a),n}reBound(e,t){const r=F(e,t),n=this.new(),a=tr(r);return a.type="re-bound",n.ops.push(a),n}invert(){const e=sr();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 Q;return e.ops=this.ops.slice(),e.reversed=this.reversed,e}exec(e,t){return this.currBounds=null,this.ops.reduce(([r,n],a)=>a(r,e,n,this.reversed),[null,t])[1]}reverse(){const e=this.new();e.ops.reverse();const t=[];return e.ops.forEach((r,n)=>{if(r.type==="scale"||t.some(([o,c])=>n>=o&&n<=c))return;const a=e.ops.findIndex((o,c)=>o.type==="scale"&&c>n);a!==-1&&t.push([n,a])}),t.forEach(([r,n])=>{const a=e.ops.slice(r,n);a.unshift(e.ops[n]),e.ops.splice(r,n-r+1,...a)}),e.reversed=!e.reversed,e}get transform(){return{scale:this.dim(1),offset:this.pos(0)}}};k(Ne,"IDENTITY",new Ne);let Xe=Ne;const Qe=class D{constructor(e=new Xe,t=new Xe,r=null){k(this,"x"),k(this,"y"),k(this,"currRoot"),this.x=e,this.y=t,this.currRoot=r}static translate(e,t){return new D().translate(e,t)}static translateX(e){return new D().translateX(e)}static translateY(e){return new D().translateY(e)}static clamp(e){return new D().clamp(e)}static magnify(e){return new D().magnify(e)}static scale(e){return new D().scale(e)}static reBound(e){return new D().reBound(e)}translate(e,t){const r=Zs(e,t),n=this.copy();return n.x=this.x.translate(r.x),n.y=this.y.translate(r.y),n}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(Hs(e)){const r=this.currRoot;return t.currRoot=e.root,r!=null&&!Vs(r,e.root)&&(r.x!==e.root.x&&(t.x=t.x.invert()),r.y!==e.root.y&&(t.y=t.y.invert())),t.x=t.x.scale(ve(e)),t.y=t.y.scale(Te(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(ve(e)),t.y=this.y.reBound(Te(e)),t}clamp(e){const t=this.copy();return t.x=this.x.clamp(ve(e)),t.y=this.y.clamp(Te(e)),t}copy(){const e=new D;return e.currRoot=this.currRoot,e.x=this.x,e.y=this.y,e}reverse(){const e=this.copy();return e.x=this.x.reverse(),e.y=this.y.reverse(),e}pos(e){return{x:this.x.pos(e.x),y:this.y.pos(e.y)}}dim(e){return{x:this.x.dim(e.x),y:this.y.dim(e.y)}}box(e){return Le(this.pos(e.one),this.pos(e.two),0,0,this.currRoot??e.root)}get transform(){return{scale:this.dim({x:1,y:1}),offset:this.pos({x:0,y:0})}}};k(Qe,"IDENTITY",new Qe);var nr=Object.defineProperty,ir=(s,e,t)=>e in s?nr(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,h=(s,e,t)=>ir(s,typeof e!="symbol"?e+"":e,t);let ar=(s,e=21)=>(t=e)=>{let r="",n=t|0;for(;n--;)r+=s[Math.random()*s.length|0];return r};const or="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",hr=ar(or,11),ur=()=>hr(),cr=i.z.enum(["static","dynamic"]),St=(s,e)=>{const t=new T(e);if(![w.DAY,w.HOUR,w.MINUTE,w.SECOND,w.MILLISECOND,w.MICROSECOND,w.NANOSECOND].some(n=>n.equals(t)))throw new Error("Invalid argument for remainder. Must be an even TimeSpan or Timestamp");const r=s.valueOf()%t.valueOf();return s instanceof T?new T(r):new w(r)},m=class f{constructor(e,t="UTC"){if(h(this,"value"),h(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,t).valueOf();else if(Array.isArray(e))this.value=f.parseDate(e);else{let r=BigInt(0);e instanceof Number&&(e=e.valueOf()),t==="local"&&(r=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())+r}}static parseDate([e=1970,t=1,r=1]){const n=new Date(e,t-1,r,0,0,0,0);return new f(BigInt(n.getTime())*f.MILLISECOND.valueOf()).truncate(f.DAY).valueOf()}valueOf(){return this.value}static parseTimeString(e,t="UTC"){const[r,n,a]=e.split(":");let o="00",c="00";a!=null&&([o,c]=a.split("."));let d=f.hours(parseInt(r??"00")).add(f.minutes(parseInt(n??"00"))).add(f.seconds(parseInt(o??"00"))).add(f.milliseconds(parseInt(c??"00")));return t==="local"&&(d=d.add(f.utcOffset)),d.valueOf()}static parseDateTimeString(e,t="UTC"){if(!e.includes("/")&&!e.includes("-"))return f.parseTimeString(e,t);const r=new Date(e);return e.includes(":")||r.setUTCHours(0,0,0,0),new f(BigInt(r.getTime())*f.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(f.utcOffset).date().toISOString()}timeString(e=!1,t="UTC"){const r=this.toISOString(t);return e?r.slice(11,23):r.slice(11,19)}dateString(){const e=this.date(),t=e.toLocaleString("default",{month:"short"}),r=e.toLocaleString("default",{day:"numeric"});return`${t} ${r}`}static get utcOffset(){return new w(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 ie(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()))}get hours(){return Number(this.valueOf())/Number(w.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(w.MINUTE.valueOf())}get days(){return Number(this.valueOf())/Number(w.DAY.valueOf())}get seconds(){return Number(this.valueOf())/Number(w.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(f.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(f.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get year(){return this.date().getFullYear()}setYear(e){const t=this.date();return t.setFullYear(e),new f(t)}get month(){return this.date().getUTCMonth()}setMonth(e){const t=this.date();return t.setUTCMonth(e),new f(t)}get day(){return this.date().getUTCDate()}setDay(e){const t=this.date();return t.setUTCDate(e),new f(t)}get hour(){return this.date().getUTCHours()}setHour(e){const t=this.date();return t.setUTCHours(e),new f(t,"UTC")}get minute(){return this.date().getMinutes()}setMinute(e){const t=this.date();return t.setUTCMinutes(e),new f(t)}get second(){return this.date().getSeconds()}setSecond(e){const t=this.date();return t.setUTCSeconds(e),new f(t)}get millisecond(){return this.date().getMilliseconds()}setMillisecond(e){const t=this.date();return t.setMilliseconds(e),new f(t)}toString(){return this.date().toISOString()}remainder(e){return St(this,e)}get isToday(){return this.truncate(w.DAY).equals(f.now().truncate(w.DAY))}truncate(e){return this.sub(this.remainder(e))}static now(){return new f(new Date)}static max(...e){let t=f.MIN;for(const r of e){const n=new f(r);n.after(t)&&(t=n)}return t}static min(...e){let t=f.MAX;for(const r of e){const n=new f(r);n.before(t)&&(t=n)}return t}static nanoseconds(e,t="UTC"){return new f(e,t)}static microseconds(e,t="UTC"){return f.nanoseconds(e*1e3,t)}static milliseconds(e,t="UTC"){return f.microseconds(e*1e3,t)}static seconds(e,t="UTC"){return f.milliseconds(e*1e3,t)}static minutes(e,t="UTC"){return f.seconds(e*60,t)}static hours(e,t="UTC"){return f.minutes(e*60,t)}static days(e,t="UTC"){return f.hours(e*24,t)}};h(m,"NANOSECOND",m.nanoseconds(1)),h(m,"MICROSECOND",m.microseconds(1)),h(m,"MILLISECOND",m.milliseconds(1)),h(m,"SECOND",m.seconds(1)),h(m,"MINUTE",m.minutes(1)),h(m,"HOUR",m.hours(1)),h(m,"DAY",m.days(1)),h(m,"MAX",new m((1n<<63n)-1n)),h(m,"MIN",new m(0)),h(m,"ZERO",new m(0)),h(m,"z",i.z.union([i.z.object({value:i.z.bigint()}).transform(s=>new m(s.value)),i.z.string().transform(s=>new m(BigInt(s))),i.z.instanceof(Number).transform(s=>new m(s)),i.z.number().transform(s=>new m(s)),i.z.instanceof(m)]));let T=m;const b=class g{constructor(e){h(this,"value"),h(this,"encodeValue",!0),typeof e=="number"&&(e=Math.trunc(e.valueOf())),this.value=BigInt(e.valueOf())}static fromSeconds(e){return e instanceof g?e:e instanceof _e?e.period:e instanceof T?new g(e):["number","bigint"].includes(typeof e)?g.seconds(e):new g(e)}static fromMilliseconds(e){return e instanceof g?e:e instanceof _e?e.period:e instanceof T?new g(e):["number","bigint"].includes(typeof e)?g.milliseconds(e):new g(e)}encode(){return this.value.toString()}valueOf(){return this.value}lessThan(e){return this.valueOf()<new g(e).valueOf()}greaterThan(e){return this.valueOf()>new g(e).valueOf()}lessThanOrEqual(e){return this.valueOf()<=new g(e).valueOf()}greaterThanOrEqual(e){return this.valueOf()>=new g(e).valueOf()}remainder(e){return St(this,e)}truncate(e){return new g(BigInt(Math.trunc(Number(this.valueOf()/e.valueOf())))*e.valueOf())}toString(){const e=this.truncate(g.DAY),t=this.truncate(g.HOUR),r=this.truncate(g.MINUTE),n=this.truncate(g.SECOND),a=this.truncate(g.MILLISECOND),o=this.truncate(g.MICROSECOND),c=this.truncate(g.NANOSECOND),d=e,p=t.sub(e),y=r.sub(t),l=n.sub(r),U=a.sub(n),A=o.sub(a),R=c.sub(o);let z="";return d.isZero||(z+=`${d.days}d `),p.isZero||(z+=`${p.hours}h `),y.isZero||(z+=`${y.minutes}m `),l.isZero||(z+=`${l.seconds}s `),U.isZero||(z+=`${U.milliseconds}ms `),A.isZero||(z+=`${A.microseconds}µs `),R.isZero||(z+=`${R.nanoseconds}ns`),z.trim()}mult(e){return new g(this.valueOf()*BigInt(e))}get days(){return Number(this.valueOf())/Number(g.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(g.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(g.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(g.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(g.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(g.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get isZero(){return this.valueOf()===BigInt(0)}equals(e){return this.valueOf()===new g(e).valueOf()}add(e){return new g(this.valueOf()+new g(e).valueOf())}sub(e){return new g(this.valueOf()-new g(e).valueOf())}static nanoseconds(e=1){return new g(e)}static microseconds(e=1){return g.nanoseconds(V(e,1e3))}static milliseconds(e=1){return g.microseconds(V(e,1e3))}static seconds(e=1){return g.milliseconds(V(e,1e3))}static minutes(e=1){return g.seconds(V(e,60))}static hours(e){return g.minutes(V(e,60))}static days(e){return g.hours(V(e,24))}};h(b,"NANOSECOND",b.nanoseconds(1)),h(b,"MICROSECOND",b.microseconds(1)),h(b,"MILLISECOND",b.milliseconds(1)),h(b,"SECOND",b.seconds(1)),h(b,"MINUTE",b.minutes(1)),h(b,"HOUR",b.hours(1)),h(b,"DAY",b.days(1)),h(b,"MAX",new b((1n<<63n)-1n)),h(b,"MIN",new b(0)),h(b,"ZERO",new b(0)),h(b,"z",i.z.union([i.z.object({value:i.z.bigint()}).transform(s=>new b(s.value)),i.z.string().transform(s=>new b(BigInt(s))),i.z.instanceof(Number).transform(s=>new b(s)),i.z.number().transform(s=>new b(s)),i.z.instanceof(b)]));let w=b;const _=class fe extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new fe(e).valueOf()}get period(){return w.seconds(1/this.valueOf())}sampleCount(e){return new w(e).seconds*this.valueOf()}byteCount(e,t){return this.sampleCount(e)*new E(t).valueOf()}span(e){return w.seconds(e/this.valueOf())}byteSpan(e,t){return this.span(e.valueOf()/t.valueOf())}static hz(e){return new fe(e)}static khz(e){return fe.hz(e*1e3)}};h(_,"z",i.z.union([i.z.number().transform(s=>new _(s)),i.z.instanceof(Number).transform(s=>new _(s)),i.z.instanceof(_)]));let _e=_;const x=class extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}length(e){return e.valueOf()/this.valueOf()}size(e){return new Ee(e*this.valueOf())}};h(x,"UNKNOWN",new x(0)),h(x,"BIT128",new x(16)),h(x,"BIT64",new x(8)),h(x,"BIT32",new x(4)),h(x,"BIT16",new x(2)),h(x,"BIT8",new x(1)),h(x,"z",i.z.union([i.z.number().transform(s=>new x(s)),i.z.instanceof(Number).transform(s=>new x(s)),i.z.instanceof(x)]));let E=x;const B=class ee{constructor(e,t){h(this,"start"),h(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 w(this.end.valueOf()-this.start.valueOf())}get isValid(){return this.start.valueOf()<=this.end.valueOf()}makeValid(){return this.isValid?this:this.swap()}get isZero(){return this.span.isZero}get numeric(){return{start:Number(this.start.valueOf()),end:Number(this.end.valueOf())}}swap(){return new ee(this.end,this.start)}get numericBounds(){return{lower:Number(this.start.valueOf()),upper:Number(this.end.valueOf())}}equals(e,t=w.ZERO){if(t.isZero)return this.start.equals(e.start)&&this.end.equals(e.end);let r=this.start.sub(e.start).valueOf(),n=this.end.sub(e.end).valueOf();return r<0&&(r=-r),n<0&&(n=-n),r<=t.valueOf()&&n<=t.valueOf()}toString(){return`${this.start.toString()} - ${this.end.toString()}`}toPrettyString(){return`${this.start.fString("preciseDate")} - ${this.span.toString()}`}overlapsWith(e,t=w.ZERO){e=e.makeValid();const r=this.makeValid();if(this.equals(e))return!0;if(e.end.equals(r.start)||r.end.equals(e.start))return!1;const n=T.max(r.start,e.start),a=T.min(r.end,e.end);return a.before(n)?!1:new w(a.sub(n)).greaterThanOrEqual(t)}contains(e){return e instanceof ee?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const t=new ee(this.start,this.end);return e.start.after(this.start)&&(t.start=e.start),e.start.after(this.end)&&(t.end=e.start),e.end.before(this.end)&&(t.end=e.end),e.end.before(this.start)&&(t.start=e.end),t}static max(...e){return new ee(T.min(...e.map(t=>t.start)),T.max(...e.map(t=>t.end)))}};h(B,"MAX",new B(T.MIN,T.MAX)),h(B,"MIN",new B(T.MAX,T.MIN)),h(B,"ZERO",new B(T.ZERO,T.ZERO)),h(B,"z",i.z.union([i.z.object({start:T.z,end:T.z}).transform(s=>new B(s.start,s.end)),i.z.instanceof(B)]));let ie=B;const u=class O{constructor(e){if(h(this,"value"),h(this,"encodeValue",!0),e instanceof O||typeof e=="string"||typeof e.valueOf()=="string"){this.value=e.valueOf();return}const t=O.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);if(t!=null){this.value=t.valueOf();return}throw this.value=O.UNKNOWN.valueOf(),new Error(`unable to find data type for ${e.toString()}`)}valueOf(){return this.value}get Array(){const e=O.ARRAY_CONSTRUCTORS.get(this.toString());if(e==null)throw new Error(`unable to find array constructor for ${this.valueOf()}`);return e}equals(e){return this.valueOf()===e.valueOf()}matches(...e){return e.some(t=>this.equals(t))}toString(){return this.valueOf()}get isVariable(){return this.equals(O.JSON)||this.equals(O.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(O.UUID)}get isInteger(){const e=this.toString();return e.startsWith("int")||e.startsWith("uint")}get isFloat(){return this.toString().startsWith("float")}get density(){const e=O.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}get isUnsigned(){return this.equals(O.UINT8)||this.equals(O.UINT16)||this.equals(O.UINT32)||this.equals(O.UINT64)}get isSigned(){return this.equals(O.INT8)||this.equals(O.INT16)||this.equals(O.INT32)||this.equals(O.INT64)}canSafelyCastTo(e){return this.equals(e)?!0:!this.isNumeric||!e.isNumeric||this.isVariable||e.isVariable||this.isUnsigned&&e.isSigned?!1:this.isFloat?e.isFloat&&this.density.valueOf()<=e.density.valueOf():this.equals(O.INT32)&&e.equals(O.FLOAT64)||this.equals(O.INT8)&&e.equals(O.FLOAT32)?!0:this.isInteger&&e.isInteger?this.density.valueOf()<=e.density.valueOf()&&this.isUnsigned===e.isUnsigned:!1}canCastTo(e){return this.isNumeric&&e.isNumeric?!0:this.equals(e)}toJSON(){return this.toString()}get usesBigInt(){return O.BIG_INT_TYPES.some(e=>e.equals(this))}};h(u,"UNKNOWN",new u("unknown")),h(u,"FLOAT64",new u("float64")),h(u,"FLOAT32",new u("float32")),h(u,"INT64",new u("int64")),h(u,"INT32",new u("int32")),h(u,"INT16",new u("int16")),h(u,"INT8",new u("int8")),h(u,"UINT64",new u("uint64")),h(u,"UINT32",new u("uint32")),h(u,"UINT16",new u("uint16")),h(u,"UINT8",new u("uint8")),h(u,"BOOLEAN",u.UINT8),h(u,"TIMESTAMP",new u("timestamp")),h(u,"UUID",new u("uuid")),h(u,"STRING",new u("string")),h(u,"JSON",new u("json")),h(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]])),h(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]])),h(u,"DENSITIES",new Map([[u.UINT8.toString(),E.BIT8],[u.UINT16.toString(),E.BIT16],[u.UINT32.toString(),E.BIT32],[u.UINT64.toString(),E.BIT64],[u.FLOAT32.toString(),E.BIT32],[u.FLOAT64.toString(),E.BIT64],[u.INT8.toString(),E.BIT8],[u.INT16.toString(),E.BIT16],[u.INT32.toString(),E.BIT32],[u.INT64.toString(),E.BIT64],[u.TIMESTAMP.toString(),E.BIT64],[u.STRING.toString(),E.UNKNOWN],[u.JSON.toString(),E.UNKNOWN],[u.UUID.toString(),E.BIT128]])),h(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]),h(u,"BIG_INT_TYPES",[u.INT64,u.UINT64,u.TIMESTAMP]),h(u,"z",i.z.union([i.z.string().transform(s=>new u(s)),i.z.instanceof(u)]));let v=u;const N=class I extends Number{constructor(e){super(e.valueOf())}largerThan(e){return this.valueOf()>e.valueOf()}smallerThan(e){return this.valueOf()<e.valueOf()}add(e){return I.bytes(this.valueOf()+e.valueOf())}sub(e){return I.bytes(this.valueOf()-e.valueOf())}truncate(e){return new I(Math.trunc(this.valueOf()/e.valueOf())*e.valueOf())}remainder(e){return I.bytes(this.valueOf()%e.valueOf())}get gigabytes(){return this.valueOf()/I.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/I.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/I.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/I.TERABYTE.valueOf()}toString(){const e=this.truncate(I.TERABYTE),t=this.truncate(I.GIGABYTE),r=this.truncate(I.MEGABYTE),n=this.truncate(I.KILOBYTE),a=this.truncate(I.BYTE),o=e,c=t.sub(e),d=r.sub(t),p=n.sub(r),y=a.sub(n);let l="";return o.isZero||(l+=`${o.terabytes}TB `),c.isZero||(l+=`${c.gigabytes}GB `),d.isZero||(l+=`${d.megabytes}MB `),p.isZero||(l+=`${p.kilobytes}KB `),(!y.isZero||l==="")&&(l+=`${y.valueOf()}B`),l.trim()}static bytes(e=1){return new I(e)}static kilobytes(e=1){return I.bytes(e.valueOf()*1e3)}static megabytes(e=1){return I.kilobytes(e.valueOf()*1e3)}static gigabytes(e=1){return I.megabytes(e.valueOf()*1e3)}static terabytes(e){return I.gigabytes(e.valueOf()*1e3)}get isZero(){return this.valueOf()===0}};h(N,"BYTE",new N(1)),h(N,"KILOBYTE",N.kilobytes(1)),h(N,"MEGABYTE",N.megabytes(1)),h(N,"GIGABYTE",N.gigabytes(1)),h(N,"TERABYTE",N.terabytes(1)),h(N,"ZERO",new N(0)),h(N,"z",i.z.union([i.z.number().transform(s=>new N(s)),i.z.instanceof(N)]));let Ee=N;i.z.union([i.z.instanceof(Uint8Array),i.z.instanceof(Uint16Array),i.z.instanceof(Uint32Array),i.z.instanceof(BigUint64Array),i.z.instanceof(Float32Array),i.z.instanceof(Float64Array),i.z.instanceof(Int8Array),i.z.instanceof(Int16Array),i.z.instanceof(Int32Array),i.z.instanceof(BigInt64Array)]);const It=s=>{const e=typeof s;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||s instanceof T||s instanceof w||s instanceof Date},lr=(s,e,t,r=0)=>s.usesBigInt&&!e.usesBigInt?Number(t)-Number(r):!s.usesBigInt&&e.usesBigInt?BigInt(t.valueOf())-BigInt(r.valueOf()):te(t,-r).valueOf(),te=(s,e)=>e==0?s:s==0?e:typeof s=="bigint"&&typeof e=="bigint"||typeof s=="number"&&typeof e=="number"?s+e:Number(s)+Number(e),dr=s=>s==null?!1:Array.isArray(s)||s instanceof ArrayBuffer||ArrayBuffer.isView(s)&&!(s instanceof DataView)||s instanceof yr?!0:It(s),L=-1,fr=i.z.string().transform(s=>new Uint8Array(atob(s).split("").map(e=>e.charCodeAt(0))).buffer),gr=i.z.union([i.z.null(),i.z.undefined()]).transform(()=>new Uint8Array().buffer),ze=10,pr=(s,e)=>{if(s==="string"&&!e.isVariable)throw new Error(`cannot convert series of type ${e.toString()} to string`);if(s==="number"&&!e.isNumeric)throw new Error(`cannot convert series of type ${e.toString()} to number`);if(s==="bigint"&&!e.usesBigInt)throw new Error(`cannot convert series of type ${e.toString()} to bigint`)},se=class ${constructor(e){h(this,"key",""),h(this,"isSynnaxSeries",!0),h(this,"dataType"),h(this,"sampleOffset"),h(this,"gl"),h(this,"_data"),h(this,"timeRange",ie.ZERO),h(this,"alignment",0n),h(this,"_cachedMin"),h(this,"_cachedMax"),h(this,"writePos",L),h(this,"_refCount",0),h(this,"_cachedLength"),h(this,"_cachedIndexes"),dr(e)&&(e={data:e});const{dataType:t,timeRange:r,sampleOffset:n=0,glBufferUsage:a="static",alignment:o=0n,key:c=ur()}=e,d=e.data??[];if(d instanceof $||typeof d=="object"&&"isSynnaxSeries"in d&&d.isSynnaxSeries===!0){const l=d;this.key=l.key,this.dataType=l.dataType,this.sampleOffset=l.sampleOffset,this.gl=l.gl,this._data=l._data,this.timeRange=l.timeRange,this.alignment=l.alignment,this._cachedMin=l._cachedMin,this._cachedMax=l._cachedMax,this.writePos=l.writePos,this._refCount=l._refCount,this._cachedLength=l._cachedLength;return}const p=It(d),y=Array.isArray(d);if(t!=null)this.dataType=new v(t);else{if(d instanceof ArrayBuffer)throw new Error("cannot infer data type from an ArrayBuffer instance when constructing a Series. Please provide a data type.");if(y||p){let l=d;if(!p){if(d.length===0)throw new Error("cannot infer data type from a zero length JS array when constructing a Series. Please provide a data type.");l=d[0]}if(typeof l=="string")this.dataType=v.STRING;else if(typeof l=="number")this.dataType=v.FLOAT64;else if(typeof l=="bigint")this.dataType=v.INT64;else if(typeof l=="boolean")this.dataType=v.BOOLEAN;else if(l instanceof T||l instanceof Date||l instanceof T)this.dataType=v.TIMESTAMP;else if(typeof l=="object")this.dataType=v.JSON;else throw new Error(`cannot infer data type of ${typeof l} when constructing a Series from a JS array`)}else this.dataType=new v(d)}if(!y&&!p)this._data=d;else{let l=p?[d]:d;const U=l[0];(U instanceof T||U instanceof Date||U instanceof w)&&(l=l.map(A=>new T(A).valueOf())),this.dataType.equals(v.STRING)?(this._cachedLength=l.length,this._data=new TextEncoder().encode(`${l.join(`
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("zod"),Ye=n=>{const e=n.replace(/_[a-z]/g,t=>t[1].toUpperCase());return e.length>1&&e[0]===e[0].toUpperCase()&&e[1]===e[1].toUpperCase()||e.length===0?e:e[0].toLowerCase()+e.slice(1)},be=n=>{const e=(t,r=_)=>{if(typeof t=="string")return n(t);if(Array.isArray(t))return t.map(l=>e(l,r));if(!X(t))return t;r=Ze(r);const i={},o=t;return"toJSON"in o&&typeof o.toJSON=="function"?e(o.toJSON(),r):(Object.keys(o).forEach(l=>{let d=o[l];const f=n(l);r.recursive&&(X(d)?le(d)||(d=e(d,r)):r.recursiveInArray&&ce(d)&&(d=[...d].map(g=>{let m=g;return X(g)?le(m)||(m=e(g,r)):ce(g)&&(m=e({key:g},r).key),m}))),i[f]=d}),i)};return e},Te=be(Ye),qe=n=>n.replace(/([a-z0-9])([A-Z])/g,(e,t,r)=>`${t}_${r.toLowerCase()}`),Fe=be(qe),We=[Number,String,Uint8Array],_={recursive:!0,recursiveInArray:!0},Ze=(n=_)=>(n.recursive==null?n=_:n.recursiveInArray??=!1,n),ce=n=>n!=null&&Array.isArray(n),X=n=>n!=null&&typeof n=="object"&&!Array.isArray(n),le=n=>We.some(e=>n instanceof e);let Ve=class{contentType="application/json";decoder;encoder;constructor(){this.decoder=new TextDecoder,this.encoder=new TextEncoder}encode(e){return this.encoder.encode(this.encodeString(e))}decode(e,t){return this.decodeString(this.decoder.decode(e),t)}decodeString(e,t){const r=JSON.parse(e),i=Te(r);return t!=null?t.parse(i):i}encodeString(e){const t=Fe(e);return JSON.stringify(t,(r,i)=>ArrayBuffer.isView(i)?Array.from(i):typeof i=="bigint"?i.toString():i)}};const ee=new Ve;let P=class{value;constructor(e){this.value=e}valueOf(){return this.value}toJSON(){return this.value}toString(){return this.value.toString()}};const Ge=n=>n!=null&&typeof n=="object"&&"toString"in n,Je=(n,e=!1)=>{const t=Ge(n)?"stringer":typeof n;let r;switch(t){case"string":r=(i,o)=>i.localeCompare(o);break;case"stringer":r=(i,o)=>i.toString().localeCompare(o.toString());break;case"number":r=(i,o)=>Number(i)-Number(o);break;case"bigint":r=(i,o)=>BigInt(i)-BigInt(o)>0n?1:-1;break;case"boolean":r=(i,o)=>Number(i)-Number(o);break;case"undefined":r=()=>0;break;default:return console.warn(`sortFunc: unknown type ${t}`),()=>-1}return e?He(r):r},He=n=>(e,t)=>n(t,e),H=s.z.tuple([s.z.number(),s.z.number()]);s.z.tuple([s.z.bigint(),s.z.bigint()]);const Oe=s.z.object({width:s.z.number(),height:s.z.number()}),Xe=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()}),Ke=["width","height"];s.z.enum(Ke);const Qe=["start","center","end"],_e=["signedWidth","signedHeight"];s.z.enum(_e);const G=s.z.object({x:s.z.number(),y:s.z.number()}),et=s.z.object({clientX:s.z.number(),clientY:s.z.number()}),tt=["x","y"],ve=s.z.enum(tt),Ie=["top","right","bottom","left"];s.z.enum(Ie);const nt=["left","right"],Se=s.z.enum(nt),rt=["top","bottom"],Ne=s.z.enum(rt),ze=["center"],he=s.z.enum(ze),st=[...Ie,...ze],xe=s.z.enum(st);s.z.enum(Qe);const it=["first","last"];s.z.enum(it);const at=s.z.object({lower:s.z.number(),upper:s.z.number()}),ot=s.z.object({lower:s.z.bigint(),upper:s.z.bigint()});s.z.union([at,H]);s.z.union([ot,H]);s.z.enum([...ve.options,...xe.options]);s.z.union([ve,xe,s.z.instanceof(String)]);const B=(n,e)=>typeof n=="bigint"?n*BigInt(e):n*Number(e),A=(n,e,t)=>{const r={};if(typeof e=="object"&&(t=e,e=void 0),t={makeValid:!0,...t},typeof n=="number"||typeof n=="bigint")e!=null?(r.lower=n,r.upper=e):(r.lower=typeof n=="bigint"?0n:0,r.upper=n);else if(Array.isArray(n)){if(n.length!==2)throw new Error("bounds: expected array of length 2");[r.lower,r.upper]=n}else r.lower=n.lower,r.upper=n.upper;return t?.makeValid?ut(r):r},ut=n=>n.lower>n.upper?{lower:n.upper,upper:n.lower}:n,fe=(n,e)=>{const t=A(n);return e<t.lower?t.lower:e>=t.upper?t.upper-(typeof t.upper=="number"?1:1n):e};s.z.object({x:Se.or(he),y:Ne.or(he)});const ct=s.z.object({x:Se,y:Ne}),lt=Object.freeze({x:"left",y:"top"}),ht=(n,e)=>n.x===e.x&&n.y===e.y,de=s.z.union([s.z.number(),G,H,Oe,Xe,et]),ft=(n,e)=>{if(typeof n=="string"){if(e===void 0)throw new Error("The y coordinate must be given.");return n==="x"?{x:e,y:0}:{x:0,y:e}}return typeof n=="number"?{x:n,y:e??n}:Array.isArray(n)?{x:n[0],y:n[1]}:"signedWidth"in n?{x:n.signedWidth,y:n.signedHeight}:"clientX"in n?{x:n.clientX,y:n.clientY}:"width"in n?{x:n.width,y:n.height}:{x:n.x,y:n.y}},ge=Object.freeze({x:0,y:0}),W=s.z.union([s.z.number(),s.z.string()]);s.z.object({top:W,left:W,width:W,height:W});s.z.object({left:s.z.number(),top:s.z.number(),right:s.z.number(),bottom:s.z.number()});s.z.object({one:G,two:G,root:ct});const se=(n,e,t=0,r=0,i)=>{const o={one:{...ge},two:{...ge},root:i??lt};if(typeof n=="number"){if(typeof e!="number")throw new Error("Box constructor called with invalid arguments");return o.one={x:n,y:e},o.two={x:o.one.x+t,y:o.one.y+r},o}return"one"in n&&"two"in n&&"root"in n?{...n,root:i??n.root}:("getBoundingClientRect"in n&&(n=n.getBoundingClientRect()),"left"in n?(o.one={x:n.left,y:n.top},o.two={x:n.right,y:n.bottom},o):(o.one=n,e==null?o.two={x:o.one.x+t,y:o.one.y+r}:typeof e=="number"?o.two={x:o.one.x+e,y:o.one.y+t}:"width"in e?o.two={x:o.one.x+e.width,y:o.one.y+e.height}:"signedWidth"in e?o.two={x:o.one.x+e.signedWidth,y:o.one.y+e.signedHeight}:o.two=e,o))},K=n=>{const e=se(n);return{lower:e.one.x,upper:e.two.x}},Q=n=>{const e=se(n);return{lower:e.one.y,upper:e.two.y}},dt=n=>typeof n!="object"||n==null?!1:"one"in n&&"two"in n&&"root"in n,gt=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()});s.z.union([Oe,gt,G,H]);const pt=(n,e,t)=>e!==void 0&&n<e?e:t!==void 0&&n>t?t:n;s.z.object({offset:de,scale:de});s.z.object({offset:s.z.number(),scale:s.z.number()});const yt=n=>(e,t,r,i)=>t==="dimension"?[e,r]:[e,i?r-n:r+n],mt=n=>(e,t,r,i)=>[e,i?r/n:r*n],wt=n=>(e,t,r)=>{if(e===null)return[n,r];const{lower:i,upper:o}=e,{lower:l,upper:d}=n,f=o-i,g=d-l;if(t==="dimension")return[n,r*(g/f)];const m=(r-i)*(g/f)+l;return[n,m]},bt=n=>(e,t,r)=>[n,r],Tt=()=>(n,e,t)=>{if(n===null)throw new Error("cannot invert without bounds");if(e==="dimension")return[n,t];const{lower:r,upper:i}=n;return[n,i-(t-r)]},Ot=n=>(e,t,r)=>{const{lower:i,upper:o}=n;return r=pt(r,i,o),[e,r]};let pe=class ${ops=[];currBounds=null;currType=null;reversed=!1;constructor(){this.ops=[]}static translate(e){return new $().translate(e)}static magnify(e){return new $().magnify(e)}static scale(e,t){return new $().scale(e,t)}translate(e){const t=this.new(),r=yt(e);return r.type="translate",t.ops.push(r),t}magnify(e){const t=this.new(),r=mt(e);return r.type="magnify",t.ops.push(r),t}scale(e,t){const r=A(e,t),i=this.new(),o=wt(r);return o.type="scale",i.ops.push(o),i}clamp(e,t){const r=A(e,t),i=this.new(),o=Ot(r);return o.type="clamp",i.ops.push(o),i}reBound(e,t){const r=A(e,t),i=this.new(),o=bt(r);return o.type="re-bound",i.ops.push(o),i}invert(){const e=Tt();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 $;return e.ops=this.ops.slice(),e.reversed=this.reversed,e}exec(e,t){return this.currBounds=null,this.ops.reduce(([r,i],o)=>o(r,e,i,this.reversed),[null,t])[1]}reverse(){const e=this.new();e.ops.reverse();const t=[];return e.ops.forEach((r,i)=>{if(r.type==="scale"||t.some(([l,d])=>i>=l&&i<=d))return;const o=e.ops.findIndex((l,d)=>l.type==="scale"&&d>i);o!==-1&&t.push([i,o])}),t.forEach(([r,i])=>{const o=e.ops.slice(r,i);o.unshift(e.ops[i]),e.ops.splice(r,i-r+1,...o)}),e.reversed=!e.reversed,e}get transform(){return{scale:this.dim(1),offset:this.pos(0)}}static IDENTITY=new $},Yn=class I{x;y;currRoot;constructor(e=new pe,t=new pe,r=null){this.x=e,this.y=t,this.currRoot=r}static translate(e,t){return new I().translate(e,t)}static translateX(e){return new I().translateX(e)}static translateY(e){return new I().translateY(e)}static clamp(e){return new I().clamp(e)}static magnify(e){return new I().magnify(e)}static scale(e){return new I().scale(e)}static reBound(e){return new I().reBound(e)}translate(e,t){const r=ft(e,t),i=this.copy();return i.x=this.x.translate(r.x),i.y=this.y.translate(r.y),i}translateX(e){const t=this.copy();return t.x=this.x.translate(e),t}translateY(e){const t=this.copy();return t.y=this.y.translate(e),t}magnify(e){const t=this.copy();return t.x=this.x.magnify(e.x),t.y=this.y.magnify(e.y),t}scale(e){const t=this.copy();if(dt(e)){const r=this.currRoot;return t.currRoot=e.root,r!=null&&!ht(r,e.root)&&(r.x!==e.root.x&&(t.x=t.x.invert()),r.y!==e.root.y&&(t.y=t.y.invert())),t.x=t.x.scale(K(e)),t.y=t.y.scale(Q(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(K(e)),t.y=this.y.reBound(Q(e)),t}clamp(e){const t=this.copy();return t.x=this.x.clamp(K(e)),t.y=this.y.clamp(Q(e)),t}copy(){const e=new I;return e.currRoot=this.currRoot,e.x=this.x,e.y=this.y,e}reverse(){const e=this.copy();return e.x=this.x.reverse(),e.y=this.y.reverse(),e}pos(e){return{x:this.x.pos(e.x),y:this.y.pos(e.y)}}dim(e){return{x:this.x.dim(e.x),y:this.y.dim(e.y)}}box(e){return se(this.pos(e.one),this.pos(e.two),0,0,this.currRoot??e.root)}get transform(){return{scale:this.dim({x:1,y:1}),offset:this.pos({x:0,y:0})}}static IDENTITY=new I},vt=(n,e=21)=>(t=e)=>{let r="",i=t|0;for(;i--;)r+=n[Math.random()*n.length|0];return r};const It="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",St=11,Nt=vt(It,St),zt=()=>Nt(),xt=(n,e)=>t=>t instanceof e||typeof t=="object"&&t!==null&&"discriminator"in t&&t.discriminator===n,Et=s.z.enum(["static","dynamic"]),At=s.z.union([s.z.tuple([s.z.int()]),s.z.tuple([s.z.int(),s.z.int().min(1).max(12)]),s.z.tuple([s.z.int(),s.z.int().min(1).max(12),s.z.int().min(1).max(31)])]),Ee=(n,e)=>{const t=new y(e);if(![u.DAY,u.HOUR,u.MINUTE,u.SECOND,u.MILLISECOND,u.MICROSECOND,u.NANOSECOND].some(i=>i.equals(t)))throw new Error("Invalid argument for remainder. Must be an even TimeSpan or Timestamp");const r=n.valueOf()%t.valueOf();return n instanceof y?new y(r):new u(r)};let y=class c extends P{constructor(e,t="UTC"){if(e==null)super(c.now().valueOf());else if(e instanceof Date)super(BigInt(e.getTime())*c.MILLISECOND.valueOf());else if(typeof e=="string")super(c.parseDateTimeString(e,t).valueOf());else if(Array.isArray(e))super(c.parseDate(e));else{let r=0n;e instanceof Number&&(e=e.valueOf()),t==="local"&&(r=c.utcOffset.valueOf()),typeof e=="number"&&(isFinite(e)?e=Math.trunc(e):(isNaN(e)&&(e=0),e===1/0?e=c.MAX:e=c.MIN)),super(BigInt(e.valueOf())+r)}}static parseDate([e=1970,t=1,r=1]){const i=new Date(e,t-1,r,0,0,0,0);return new c(BigInt(i.getTime())*c.MILLISECOND.valueOf()).truncate(c.DAY).valueOf()}valueOf(){return this.value}static parseTimeString(e,t="UTC"){const[r,i,o]=e.split(":");let l="00",d="00";o!=null&&([l,d]=o.split("."));let f=c.hours(parseInt(r??"00")).add(c.minutes(parseInt(i??"00"))).add(c.seconds(parseInt(l??"00"))).add(c.milliseconds(parseInt(d??"00")));return t==="local"&&(f=f.add(c.utcOffset)),f.valueOf()}static parseDateTimeString(e,t="UTC"){if(!e.includes("/")&&!e.includes("-"))return c.parseTimeString(e,t);const r=new Date(e);return e.includes(":")||r.setUTCHours(0,0,0,0),new c(BigInt(r.getTime())*c.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(c.utcOffset).date().toISOString()}timeString(e=!1,t="UTC"){const r=this.toISOString(t);return e?r.slice(11,23):r.slice(11,19)}dateString(){const e=this.date(),t=e.toLocaleString("default",{month:"short"}),r=e.toLocaleString("default",{day:"numeric"});return`${t} ${r}`}static get utcOffset(){return new u(BigInt(new Date().getTimezoneOffset())*c.MINUTE.valueOf())}static since(e){return new c().span(e)}date(){return new Date(this.milliseconds)}equals(e){return this.valueOf()===new c(e).valueOf()}span(e){return this.range(e).span}range(e){return new O(this,e).makeValid()}spanRange(e){return this.range(this.add(e)).makeValid()}get isZero(){return this.valueOf()===0n}after(e){return this.valueOf()>new c(e).valueOf()}afterEq(e){return this.valueOf()>=new c(e).valueOf()}before(e){return this.valueOf()<new c(e).valueOf()}beforeEq(e){return this.valueOf()<=new c(e).valueOf()}add(e){return new c(this.valueOf()+BigInt(e.valueOf()))}sub(e){return new c(this.valueOf()-BigInt(e.valueOf()))}get hours(){return Number(this.valueOf())/Number(u.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(u.MINUTE.valueOf())}get days(){return Number(this.valueOf())/Number(u.DAY.valueOf())}get seconds(){return Number(this.valueOf())/Number(u.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(c.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(c.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get year(){return this.date().getUTCFullYear()}setYear(e){const t=this.date();return t.setUTCFullYear(e),new c(t)}get month(){return this.date().getUTCMonth()}setMonth(e){const t=this.date();return t.setUTCMonth(e),new c(t)}get day(){return this.date().getUTCDate()}setDay(e){const t=this.date();return t.setUTCDate(e),new c(t)}get hour(){return this.date().getUTCHours()}setHour(e){const t=this.date();return t.setUTCHours(e),new c(t,"UTC")}get minute(){return this.date().getUTCMinutes()}setMinute(e){const t=this.date();return t.setUTCMinutes(e),new c(t)}get second(){return this.date().getUTCSeconds()}setSecond(e){const t=this.date();return t.setUTCSeconds(e),new c(t)}get millisecond(){return this.date().getUTCMilliseconds()}setMillisecond(e){const t=this.date();return t.setUTCMilliseconds(e),new c(t)}toString(){return this.date().toISOString()}remainder(e){return Ee(this,e)}get isToday(){return this.truncate(u.DAY).equals(c.now().truncate(u.DAY))}truncate(e){return this.sub(this.remainder(e))}static now(){return new c(new Date)}static max(...e){let t=c.MIN;for(const r of e){const i=new c(r);i.after(t)&&(t=i)}return t}static min(...e){let t=c.MAX;for(const r of e){const i=new c(r);i.before(t)&&(t=i)}return t}static nanoseconds(e,t="UTC"){return new c(e,t)}static NANOSECOND=c.nanoseconds(1);static microseconds(e,t="UTC"){return c.nanoseconds(e*1e3,t)}static MICROSECOND=c.microseconds(1);static milliseconds(e,t="UTC"){return c.microseconds(e*1e3,t)}static MILLISECOND=c.milliseconds(1);static seconds(e,t="UTC"){return c.milliseconds(e*1e3,t)}static SECOND=c.seconds(1);static minutes(e,t="UTC"){return c.seconds(e*60,t)}static MINUTE=c.minutes(1);static hours(e,t="UTC"){return c.minutes(e*60,t)}static HOUR=c.hours(1);static days(e,t="UTC"){return c.hours(e*24,t)}static DAY=c.days(1);static MAX=new c((1n<<63n)-1n);static MIN=new c(0);static ZERO=new c(0);static z=s.z.union([s.z.instanceof(c),s.z.object({value:s.z.bigint()}).transform(e=>new c(e.value)),s.z.string().transform(e=>new c(BigInt(e))),s.z.number().transform(e=>new c(e)),s.z.bigint().transform(e=>new c(e)),s.z.date().transform(e=>new c(e)),s.z.custom(e=>e instanceof u).transform(e=>new c(e)),At.transform(e=>new c(e))]);static sort(e,t){return Number(e.valueOf()-t.valueOf())}};class u extends P{constructor(e){typeof e=="number"&&(e=Math.trunc(e.valueOf())),super(BigInt(e.valueOf()))}static fromSeconds(e){return e instanceof u?e:e instanceof ye?e.period:e instanceof y?new u(e):["number","bigint"].includes(typeof e)?u.seconds(e):new u(e)}static fromMilliseconds(e){return e instanceof u?e:e instanceof ye?e.period:e instanceof y?new u(e):["number","bigint"].includes(typeof e)?u.milliseconds(e):new u(e)}valueOf(){return this.value}lessThan(e){return this.valueOf()<new u(e).valueOf()}greaterThan(e){return this.valueOf()>new u(e).valueOf()}lessThanOrEqual(e){return this.valueOf()<=new u(e).valueOf()}greaterThanOrEqual(e){return this.valueOf()>=new u(e).valueOf()}remainder(e){return Ee(this,e)}truncate(e){return new u(BigInt(Math.trunc(Number(this.valueOf()/e.valueOf())))*e.valueOf())}toString(){const e=this.truncate(u.DAY),t=this.truncate(u.HOUR),r=this.truncate(u.MINUTE),i=this.truncate(u.SECOND),o=this.truncate(u.MILLISECOND),l=this.truncate(u.MICROSECOND),d=this.truncate(u.NANOSECOND),f=e,g=t.sub(e),m=r.sub(t),h=i.sub(r),v=o.sub(i),w=l.sub(o),F=d.sub(l);let z="";return f.isZero||(z+=`${f.days}d `),g.isZero||(z+=`${g.hours}h `),m.isZero||(z+=`${m.minutes}m `),h.isZero||(z+=`${h.seconds}s `),v.isZero||(z+=`${v.milliseconds}ms `),w.isZero||(z+=`${w.microseconds}µs `),F.isZero||(z+=`${F.nanoseconds}ns`),z.trim()}mult(e){return new u(this.valueOf()*BigInt(e))}get days(){return Number(this.valueOf())/Number(u.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(u.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(u.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(u.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(u.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(u.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get isZero(){return this.valueOf()===0n}equals(e){return this.valueOf()===new u(e).valueOf()}add(e){return new u(this.valueOf()+new u(e).valueOf())}sub(e){return new u(this.valueOf()-new u(e).valueOf())}static nanoseconds(e=1){return new u(e)}static NANOSECOND=u.nanoseconds(1);static microseconds(e=1){return u.nanoseconds(B(e,1e3))}static MICROSECOND=u.microseconds(1);static milliseconds(e=1){return u.microseconds(B(e,1e3))}static MILLISECOND=u.milliseconds(1);static seconds(e=1){return u.milliseconds(B(e,1e3))}static SECOND=u.seconds(1);static minutes(e=1){return u.seconds(B(e,60))}static MINUTE=u.minutes(1);static hours(e){return u.minutes(B(e,60))}static HOUR=u.hours(1);static days(e){return u.hours(B(e,24))}static DAY=u.days(1);static MAX=new u((1n<<63n)-1n);static MIN=new u(0);static ZERO=new u(0);static z=s.z.union([s.z.object({value:s.z.bigint()}).transform(e=>new u(e.value)),s.z.string().transform(e=>new u(BigInt(e))),s.z.number().transform(e=>new u(e)),s.z.instanceof(u)])}let ye=class R extends P{constructor(e){super(e.valueOf())}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new R(e).valueOf()}get period(){return u.seconds(1/this.valueOf())}sampleCount(e){return new u(e).seconds*this.valueOf()}byteCount(e,t){return this.sampleCount(e)*new T(t).valueOf()}span(e){return u.seconds(e/this.valueOf())}byteSpan(e,t){return this.span(e.valueOf()/t.valueOf())}static hz(e){return new R(e)}static khz(e){return R.hz(e*1e3)}static z=s.z.union([s.z.number().transform(e=>new R(e)),s.z.instanceof(R)])},T=class N extends P{constructor(e){super(e.valueOf())}length(e){return e.valueOf()/this.valueOf()}size(e){return new p(e*this.valueOf())}static UNKNOWN=new N(0);static BIT128=new N(16);static BIT64=new N(8);static BIT32=new N(4);static BIT16=new N(2);static BIT8=new N(1);static z=s.z.union([s.z.number().transform(e=>new N(e)),s.z.instanceof(N)])};class O{start;end;constructor(e,t){typeof e=="object"&&"start"in e?(this.start=new y(e.start),this.end=new y(e.end)):(this.start=new y(e),this.end=new y(t))}get span(){return new u(this.end.valueOf()-this.start.valueOf())}get isValid(){return this.start.valueOf()<=this.end.valueOf()}makeValid(){return this.isValid?this:this.swap()}get isZero(){return this.span.isZero}get numeric(){return{start:Number(this.start.valueOf()),end:Number(this.end.valueOf())}}swap(){return new O(this.end,this.start)}get numericBounds(){return{lower:Number(this.start.valueOf()),upper:Number(this.end.valueOf())}}equals(e,t=u.ZERO){if(t.isZero)return this.start.equals(e.start)&&this.end.equals(e.end);let r=this.start.sub(e.start).valueOf(),i=this.end.sub(e.end).valueOf();return r<0&&(r=-r),i<0&&(i=-i),r<=t.valueOf()&&i<=t.valueOf()}toString(){return`${this.start.toString()} - ${this.end.toString()}`}toPrettyString(){return`${this.start.fString("preciseDate")} - ${this.span.toString()}`}overlapsWith(e,t=u.ZERO){e=e.makeValid();const r=this.makeValid();if(this.equals(e))return!0;if(e.end.equals(r.start)||r.end.equals(e.start))return!1;const i=y.max(r.start,e.start),o=y.min(r.end,e.end);return o.before(i)?!1:new u(o.sub(i)).greaterThanOrEqual(t)}contains(e){return e instanceof O?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const t=new O(this.start,this.end);return e.start.after(this.start)&&(t.start=e.start),e.start.after(this.end)&&(t.end=e.start),e.end.before(this.end)&&(t.end=e.end),e.end.before(this.start)&&(t.start=e.end),t}static max(...e){return new O(y.min(...e.map(t=>t.start)),y.max(...e.map(t=>t.end)))}static MAX=new O(y.MIN,y.MAX);static MIN=new O(y.MAX,y.MIN);static ZERO=new O(y.ZERO,y.ZERO);static z=s.z.union([s.z.object({start:y.z,end:y.z}).transform(e=>new O(e.start,e.end)),s.z.instanceof(O)]);static sort(e,t){return y.sort(e.start,t.start)||y.sort(e.end,t.end)}}class a extends P{constructor(e){if(e instanceof a||typeof e=="string"||typeof e.valueOf()=="string")super(e.valueOf());else{const t=a.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);if(t==null)throw new Error(`unable to find data type for ${e.toString()}`);super(t.valueOf())}}get Array(){const e=a.ARRAY_CONSTRUCTORS.get(this.toString());if(e==null)throw new Error(`unable to find array constructor for ${this.valueOf()}`);return e}equals(e){return this.valueOf()===e.valueOf()}matches(...e){return e.some(t=>this.equals(t))}toString(){return this.valueOf()}get isVariable(){return this.equals(a.JSON)||this.equals(a.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(a.UUID)}get isInteger(){const e=this.toString();return e.startsWith("int")||e.startsWith("uint")}get isFloat(){return this.toString().startsWith("float")}get density(){const e=a.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}get isUnsignedInteger(){return this.equals(a.UINT8)||this.equals(a.UINT16)||this.equals(a.UINT32)||this.equals(a.UINT64)}get isSignedInteger(){return this.equals(a.INT8)||this.equals(a.INT16)||this.equals(a.INT32)||this.equals(a.INT64)}canSafelyCastTo(e){return this.equals(e)?!0:!this.isNumeric||!e.isNumeric||this.isVariable||e.isVariable||this.isUnsignedInteger&&e.isSignedInteger?!1:this.isFloat?e.isFloat&&this.density.valueOf()<=e.density.valueOf():this.equals(a.INT32)&&e.equals(a.FLOAT64)||this.equals(a.INT8)&&e.equals(a.FLOAT32)?!0:this.isInteger&&e.isInteger?this.density.valueOf()<=e.density.valueOf()&&this.isUnsignedInteger===e.isUnsignedInteger:!1}canCastTo(e){return this.isNumeric&&e.isNumeric?!0:this.equals(e)}checkArray(e){return e.constructor===this.Array}get usesBigInt(){return a.BIG_INT_TYPES.some(e=>e.equals(this))}static UNKNOWN=new a("unknown");static FLOAT64=new a("float64");static FLOAT32=new a("float32");static INT64=new a("int64");static INT32=new a("int32");static INT16=new a("int16");static INT8=new a("int8");static UINT64=new a("uint64");static UINT32=new a("uint32");static UINT16=new a("uint16");static UINT8=new a("uint8");static BOOLEAN=this.UINT8;static TIMESTAMP=new a("timestamp");static UUID=new a("uuid");static STRING=new a("string");static JSON=new a("json");static ARRAY_CONSTRUCTORS=new Map([[a.UINT8.toString(),Uint8Array],[a.UINT16.toString(),Uint16Array],[a.UINT32.toString(),Uint32Array],[a.UINT64.toString(),BigUint64Array],[a.FLOAT32.toString(),Float32Array],[a.FLOAT64.toString(),Float64Array],[a.INT8.toString(),Int8Array],[a.INT16.toString(),Int16Array],[a.INT32.toString(),Int32Array],[a.INT64.toString(),BigInt64Array],[a.TIMESTAMP.toString(),BigInt64Array],[a.STRING.toString(),Uint8Array],[a.JSON.toString(),Uint8Array],[a.UUID.toString(),Uint8Array]]);static ARRAY_CONSTRUCTOR_DATA_TYPES=new Map([[Uint8Array.name,a.UINT8],[Uint16Array.name,a.UINT16],[Uint32Array.name,a.UINT32],[BigUint64Array.name,a.UINT64],[Float32Array.name,a.FLOAT32],[Float64Array.name,a.FLOAT64],[Int8Array.name,a.INT8],[Int16Array.name,a.INT16],[Int32Array.name,a.INT32],[BigInt64Array.name,a.INT64]]);static DENSITIES=new Map([[a.UINT8.toString(),T.BIT8],[a.UINT16.toString(),T.BIT16],[a.UINT32.toString(),T.BIT32],[a.UINT64.toString(),T.BIT64],[a.FLOAT32.toString(),T.BIT32],[a.FLOAT64.toString(),T.BIT64],[a.INT8.toString(),T.BIT8],[a.INT16.toString(),T.BIT16],[a.INT32.toString(),T.BIT32],[a.INT64.toString(),T.BIT64],[a.TIMESTAMP.toString(),T.BIT64],[a.STRING.toString(),T.UNKNOWN],[a.JSON.toString(),T.UNKNOWN],[a.UUID.toString(),T.BIT128]]);static ALL=[a.UNKNOWN,a.FLOAT64,a.FLOAT32,a.INT64,a.INT32,a.INT16,a.INT8,a.UINT64,a.UINT32,a.UINT16,a.UINT8,a.TIMESTAMP,a.UUID,a.STRING,a.JSON];static BIG_INT_TYPES=[a.INT64,a.UINT64,a.TIMESTAMP];static z=s.z.union([s.z.string().transform(e=>new a(e)),s.z.instanceof(a)])}class p extends P{constructor(e){super(e.valueOf())}largerThan(e){return this.valueOf()>e.valueOf()}smallerThan(e){return this.valueOf()<e.valueOf()}add(e){return p.bytes(this.valueOf()+e.valueOf())}sub(e){return p.bytes(this.valueOf()-e.valueOf())}truncate(e){return new p(Math.trunc(this.valueOf()/e.valueOf())*e.valueOf())}remainder(e){return p.bytes(this.valueOf()%e.valueOf())}get gigabytes(){return this.valueOf()/p.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/p.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/p.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/p.TERABYTE.valueOf()}toString(){const e=this.truncate(p.TERABYTE),t=this.truncate(p.GIGABYTE),r=this.truncate(p.MEGABYTE),i=this.truncate(p.KILOBYTE),o=this.truncate(p.BYTE),l=e,d=t.sub(e),f=r.sub(t),g=i.sub(r),m=o.sub(i);let h="";return l.isZero||(h+=`${l.terabytes}TB `),d.isZero||(h+=`${d.gigabytes}GB `),f.isZero||(h+=`${f.megabytes}MB `),g.isZero||(h+=`${g.kilobytes}KB `),(!m.isZero||h==="")&&(h+=`${m.valueOf()}B`),h.trim()}static bytes(e=1){return new p(e)}static BYTE=new p(1);static kilobytes(e=1){return p.bytes(e.valueOf()*1e3)}static KILOBYTE=p.kilobytes(1);static megabytes(e=1){return p.kilobytes(e.valueOf()*1e3)}static MEGABYTE=p.megabytes(1);static gigabytes(e=1){return p.megabytes(e.valueOf()*1e3)}static GIGABYTE=p.gigabytes(1);static terabytes(e){return p.gigabytes(e.valueOf()*1e3)}static TERABYTE=p.terabytes(1);static ZERO=new p(0);static z=s.z.union([s.z.number().transform(e=>new p(e)),s.z.instanceof(p)]);get isZero(){return this.valueOf()===0}}s.z.union([s.z.instanceof(Uint8Array),s.z.instanceof(Uint16Array),s.z.instanceof(Uint32Array),s.z.instanceof(BigUint64Array),s.z.instanceof(Float32Array),s.z.instanceof(Float64Array),s.z.instanceof(Int8Array),s.z.instanceof(Int16Array),s.z.instanceof(Int32Array),s.z.instanceof(BigInt64Array)]);const Ae=n=>{const e=typeof n;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||n instanceof y||n instanceof u||n instanceof Date},Ut=(n,e,t,r=0)=>n.usesBigInt&&!e.usesBigInt?Number(t)-Number(r):!n.usesBigInt&&e.usesBigInt?BigInt(t.valueOf())-BigInt(r.valueOf()):V(t,-r),V=(n,e)=>e==0?n:n==0?e:typeof n=="bigint"&&typeof e=="bigint"||typeof n=="number"&&typeof e=="number"?n+e:Number(n)+Number(e),Ct=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;function Mt(n){return typeof n=="string"&&Ct.test(n)}const b=[];for(let n=0;n<256;++n)b.push((n+256).toString(16).slice(1));function Bt(n,e=0){return(b[n[e+0]]+b[n[e+1]]+b[n[e+2]]+b[n[e+3]]+"-"+b[n[e+4]]+b[n[e+5]]+"-"+b[n[e+6]]+b[n[e+7]]+"-"+b[n[e+8]]+b[n[e+9]]+"-"+b[n[e+10]]+b[n[e+11]]+b[n[e+12]]+b[n[e+13]]+b[n[e+14]]+b[n[e+15]]).toLowerCase()}function $t(n,e=0){const t=Bt(n,e);if(!Mt(t))throw TypeError("Stringified UUID is invalid");return t}typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const Ue=(n,e)=>$t(n,e),x=-1,Rt=s.z.string().transform(n=>new Uint8Array(atob(n).split("").map(e=>e.charCodeAt(0))).buffer),Dt=s.z.union([s.z.null(),s.z.undefined()]).transform(()=>new Uint8Array().buffer),te=10,Lt=(n,e)=>{if(n==="number"&&!e.isNumeric)throw new Error(`cannot convert series of type ${e.toString()} to number`);if(n==="bigint"&&!e.usesBigInt)throw new Error(`cannot convert series of type ${e.toString()} to bigint`)},Ce="sy_x_telem_series";class S{key;discriminator=Ce;dataType;sampleOffset;gl;_data;timeRange=O.ZERO;alignment=0n;cachedMin;cachedMax;writePos=x;_refCount=0;cachedLength;_cachedIndexes;static crudeZ=s.z.object({timeRange:O.z.optional(),dataType:a.z,alignment:s.z.coerce.bigint().optional(),data:s.z.union([Rt,Dt,s.z.instanceof(ArrayBuffer),s.z.instanceof(Uint8Array)]),glBufferUsage:Et.optional().default("static").optional()});static z=S.crudeZ.transform(e=>new S(e));constructor(e){Pt(e)&&(e={data:e}),e.data??=[];const{dataType:t,timeRange:r,sampleOffset:i=0,glBufferUsage:o="static",alignment:l=0n,key:d=zt(),data:f}=e;if(kt(f)){const h=f;this.key=h.key,this.dataType=h.dataType,this.sampleOffset=h.sampleOffset,this.gl=h.gl,this._data=h._data,this.timeRange=h.timeRange,this.alignment=h.alignment,this.cachedMin=h.cachedMin,this.cachedMax=h.cachedMax,this.writePos=h.writePos,this._refCount=h._refCount,this.cachedLength=h.cachedLength;return}const g=Ae(f),m=Array.isArray(f);if(t!=null)this.dataType=new a(t);else{if(f instanceof ArrayBuffer)throw new Error("cannot infer data type from an ArrayBuffer instance when constructing a Series. Please provide a data type.");if(m||g){let h=f;if(!g){if(f.length===0)throw new Error("cannot infer data type from a zero length JS array when constructing a Series. Please provide a data type.");h=f[0]}if(typeof h=="string")this.dataType=a.STRING;else if(typeof h=="number")this.dataType=a.FLOAT64;else if(typeof h=="bigint")this.dataType=a.INT64;else if(typeof h=="boolean")this.dataType=a.BOOLEAN;else if(h instanceof y||h instanceof Date||h instanceof y)this.dataType=a.TIMESTAMP;else if(typeof h=="object")this.dataType=a.JSON;else throw new Error(`cannot infer data type of ${typeof h} when constructing a Series from a JS array`)}else this.dataType=new a(f)}if(!m&&!g)this._data=f;else if(m&&f.length===0)this._data=new this.dataType.Array([]).buffer;else{let h=g?[f]:f;const v=h[0];(v instanceof y||v instanceof Date||v instanceof u)&&(h=h.map(w=>new y(w).valueOf())),this.dataType.equals(a.STRING)?(this.cachedLength=h.length,this._data=new TextEncoder().encode(`${h.join(`
|
|
4
2
|
`)}
|
|
5
|
-
`).buffer):this.dataType.equals(
|
|
3
|
+
`).buffer):this.dataType.equals(a.JSON)?(this.cachedLength=h.length,this._data=new TextEncoder().encode(`${h.map(w=>ee.encodeString(w)).join(`
|
|
6
4
|
`)}
|
|
7
|
-
`).buffer):this.dataType.usesBigInt&&typeof
|
|
8
|
-
`)}
|
|
9
|
-
`);return new $({data:r,dataType:v.STRING,timeRange:t})}static fromJSON(e,t){const r=new TextEncoder().encode(`${e.map(n=>de.encodeString(n)).join(`
|
|
10
|
-
`)}
|
|
11
|
-
`);return new $({data:r,dataType:v.JSON,timeRange:t})}acquire(e){this._refCount++,e!=null&&this.updateGLBuffer(e)}release(){if(this._refCount<=0){console.warn("attempted to release a series with a negative reference count");return}this._refCount--,this._refCount===0&&this.gl.control!=null&&this.maybeGarbageCollectGLBuffer(this.gl.control)}write(e){if(!e.dataType.equals(this.dataType))throw new Error("buffer must be of the same type as this array");return this.dataType.isVariable?this.writeVariable(e):this.writeFixed(e)}writeVariable(e){if(this.writePos===L)return 0;const t=this.byteCapacity.valueOf()-this.writePos,r=e.subBytes(0,t);return this.writeToUnderlyingData(r),this.writePos+=r.byteLength.valueOf(),this._cachedLength!=null&&(this._cachedLength+=r.length,this.calculateCachedLength()),r.length}writeFixed(e){if(this.writePos===L)return 0;const t=this.capacity-this.writePos,r=e.sub(0,t);return this.writeToUnderlyingData(r),this._cachedLength=void 0,this.maybeRecomputeMinMax(r),this.writePos+=r.length,r.length}writeToUnderlyingData(e){this.underlyingData.set(e.data,this.writePos)}get buffer(){return typeof this._data=="object"&&"buffer"in this._data?this._data.buffer:this._data}get underlyingData(){return new this.dataType.Array(this._data)}get data(){return this.writePos===L?this.underlyingData:new this.dataType.Array(this._data,0,this.writePos)}toStrings(){if(!this.dataType.matches(v.STRING,v.UUID))throw new Error("cannot convert non-string series to strings");return new TextDecoder().decode(this.underlyingData).split(`
|
|
12
|
-
`).slice(0,-1)}toUUIDs(){if(!this.dataType.equals(v.UUID))throw new Error("cannot convert non-uuid series to uuids");const e=v.UUID.density.valueOf(),t=Array(this.length);for(let r=0;r<this.length;r++){const n=this.underlyingData.slice(r*e,(r+1)*e),a=Array.from(new Uint8Array(n.buffer),o=>o.toString(16).padStart(2,"0")).join("").replace(/(.{8})(.{4})(.{4})(.{4})(.{12})/,"$1-$2-$3-$4-$5");t[r]=a}return t}parseJSON(e){if(!this.dataType.equals(v.JSON))throw new Error("cannot parse non-JSON series as JSON");return new TextDecoder().decode(this.underlyingData).split(`
|
|
13
|
-
`).slice(0,-1).map(t=>e.parse(de.decodeString(t)))}get byteCapacity(){return new Ee(this.underlyingData.byteLength)}get capacity(){return this.dataType.isVariable?this.byteCapacity.valueOf():this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===L?this.byteCapacity:this.dataType.isVariable?new Ee(this.writePos):this.dataType.density.size(this.writePos)}get length(){return this._cachedLength!=null?this._cachedLength:this.dataType.isVariable?this.calculateCachedLength():this.writePos===L?this.data.length:this.writePos}calculateCachedLength(){if(!this.dataType.isVariable)throw new Error("cannot calculate length of a non-variable length data type");let e=0;const t=[0];return this.data.forEach((r,n)=>{r===ze&&(e++,t.push(n+1))}),this._cachedIndexes=t,this._cachedLength=e,e}convert(e,t=0){if(this.dataType.equals(e))return this;const r=new e.Array(this.length);for(let n=0;n<this.length;n++)r[n]=lr(this.dataType,e,this.data[n],t);return new $({data:r.buffer,dataType:e,timeRange:this.timeRange,sampleOffset:t,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment})}calcRawMax(){if(this.length===0)return-1/0;if(this.dataType.equals(v.TIMESTAMP))this._cachedMax=this.data[this.data.length-1];else if(this.dataType.usesBigInt){const e=this.data;this._cachedMax=e.reduce((t,r)=>t>r?t:r)}else{const e=this.data;this._cachedMax=e.reduce((t,r)=>t>r?t:r)}return this._cachedMax}get max(){if(this.dataType.isVariable)throw new Error("cannot calculate maximum on a variable length data type");return this.writePos===0?-1/0:(this._cachedMax??(this._cachedMax=this.calcRawMax()),te(this._cachedMax,this.sampleOffset))}calcRawMin(){if(this.length===0)return 1/0;if(this.dataType.equals(v.TIMESTAMP))this._cachedMin=this.data[0];else if(this.dataType.usesBigInt){const e=this.data;this._cachedMin=e.reduce((t,r)=>t<r?t:r)}else{const e=this.data;this._cachedMin=e.reduce((t,r)=>t<r?t:r)}return this._cachedMin}get min(){if(this.dataType.isVariable)throw new Error("cannot calculate minimum on a variable length data type");return this.writePos===0?1/0:(this._cachedMin??(this._cachedMin=this.calcRawMin()),te(this._cachedMin,this.sampleOffset))}get bounds(){return F(Number(this.min),Number(this.max))}maybeRecomputeMinMax(e){if(this._cachedMin!=null){const t=e._cachedMin??e.calcRawMin();t<this._cachedMin&&(this._cachedMin=t)}if(this._cachedMax!=null){const t=e._cachedMax??e.calcRawMax();t>this._cachedMax&&(this._cachedMax=t)}}enrich(){this.max,this.min}get range(){return te(this.max,-this.min)}atAlignment(e,t){const r=Number(e-this.alignment);if(r<0||r>=this.length){if(t===!0)throw new Error(`[series] - no value at index ${r}`);return}return this.at(r,t)}at(e,t){if(this.dataType.isVariable)return this.atVariable(e,t??!1);e<0&&(e=this.length+e);const r=this.data[e];if(r==null){if(t===!0)throw new Error(`[series] - no value at index ${e}`);return}return te(r,this.sampleOffset)}atVariable(e,t){let r=0,n=0;if(this._cachedIndexes!=null)r=this._cachedIndexes[e],n=this._cachedIndexes[e+1]-1;else{e<0&&(e=this.length+e);for(let o=0;o<this.data.length;o++)if(this.data[o]===ze){if(e===0){n=o;break}r=o+1,e--}if(n===0&&(n=this.data.length),r>=n||e>0){if(t)throw new Error(`[series] - no value at index ${e}`);return}}const a=this.data.slice(r,n);return this.dataType.equals(v.STRING)?new TextDecoder().decode(a):Re(JSON.parse(new TextDecoder().decode(a)))}binarySearch(e){let t=0,r=this.length-1;const n=Es(e);for(;t<=r;){const a=Math.floor((t+r)/2),o=n(this.at(a,!0),e);if(o===0)return a;o<0?t=a+1:r=a-1}return t}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals(v.FLOAT32)&&!this.dataType.equals(v.UINT8))throw new Error("Only FLOAT32 and UINT8 arrays can be used in WebGL");const{buffer:t,bufferUsage:r,prevBuffer:n}=this.gl;if(t==null&&(this.gl.buffer=e.createBuffer()),this.writePos!==n)if(e.bindBuffer(e.ARRAY_BUFFER,this.gl.buffer),this.writePos!==L){n===0&&e.bufferData(e.ARRAY_BUFFER,this.byteCapacity.valueOf(),e.STATIC_DRAW);const a=this.dataType.density.size(n).valueOf(),o=this.underlyingData.slice(this.gl.prevBuffer,this.writePos);e.bufferSubData(e.ARRAY_BUFFER,a,o.buffer),this.gl.prevBuffer=this.writePos}else e.bufferData(e.ARRAY_BUFFER,this.buffer,r==="static"?e.STATIC_DRAW:e.DYNAMIC_DRAW),this.gl.prevBuffer=L}as(e){return pr(e,this.dataType),this}get digest(){var e;return{key:this.key,dataType:this.dataType.toString(),sampleOffset:this.sampleOffset,alignment:{lower:it(this.alignmentBounds.lower),upper:it(this.alignmentBounds.upper)},timeRange:(e=this.timeRange)==null?void 0:e.toString(),length:this.length,capacity:this.capacity}}get memInfo(){return{key:this.key,length:this.length,byteLength:this.byteLength,glBuffer:this.gl.buffer!=null}}get alignmentBounds(){return F(this.alignment,this.alignment+BigInt(this.length))}maybeGarbageCollectGLBuffer(e){this.gl.buffer!=null&&(e.deleteBuffer(this.gl.buffer),this.gl.buffer=null,this.gl.prevBuffer=0,this.gl.control=null)}get glBuffer(){if(this.gl.buffer==null)throw new Error("gl buffer not initialized");return this.gl.prevBuffer!==this.writePos&&console.warn("buffer not updated"),this.gl.buffer}[Symbol.iterator](){if(this.dataType.isVariable){const e=new wr(this);return this.dataType.equals(v.JSON)?new mr(e):e}return new br(this)}slice(e,t){return this.sliceSub(!1,e,t)}sub(e,t){return this.sliceSub(!0,e,t)}subIterator(e,t){return new et(this,e,t??this.length)}subAlignmentIterator(e,t){return new et(this,Number(e-this.alignment),Number(t-this.alignment))}subBytes(e,t){if(e>=0&&(t==null||t>=this.byteLength.valueOf()))return this;const r=this.data.subarray(e,t);return new $({data:r,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(e)})}sliceSub(e,t,r){if(t<=0&&(r==null||r>=this.length))return this;let n;return e?n=this.data.subarray(t,r):n=this.data.slice(t,r),new $({data:n,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(t)})}reAlign(e){return new $({data:this.buffer,dataType:this.dataType,timeRange:ie.ZERO,sampleOffset:this.sampleOffset,glBufferUsage:"static",alignment:e})}toString(){var e,t;let r=`${this.dataType.toString()} ${this.length} [`;if(this.length<=10)r+=Array.from(this).map(n=>n.toString());else{for(let n=0;n<5;n++)r+=`${(e=this.at(n))==null?void 0:e.toString()}`,n<4&&(r+=",");r+="...";for(let n=-5;n<0;n++)r+=(t=this.at(n))==null?void 0:t.toString(),n<-1&&(r+=",")}return r+="]",r}};h(se,"crudeZ",i.z.object({timeRange:ie.z.optional(),dataType:v.z,alignment:i.z.coerce.bigint().optional(),data:i.z.union([fr,gr,i.z.instanceof(ArrayBuffer),i.z.instanceof(Uint8Array)]),glBufferUsage:cr.optional().default("static").optional()})),h(se,"z",se.crudeZ.transform(s=>new se(s)));let yr=se,et=class{constructor(e,t,r){h(this,"series"),h(this,"end"),h(this,"index"),this.series=e;const n=F(0,e.length);this.end=Ge(n,r),this.index=Ge(n,t)}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}[Symbol.iterator](){return this}};class wr{constructor(e){if(h(this,"series"),h(this,"index"),h(this,"decoder"),!e.dataType.isVariable)throw new Error("cannot create a variable series iterator for a non-variable series");this.series=e,this.index=0,this.decoder=new TextDecoder}next(){const e=this.index,t=this.series.data;for(;this.index<t.length&&t[this.index]!==ze;)this.index++;const r=this.index;return e===r?{done:!0,value:void 0}:(this.index++,{done:!1,value:this.decoder.decode(this.series.buffer.slice(e,r))})}[Symbol.iterator](){return this}}var tt,st;const Ut=class xt{constructor(e){h(this,"wrapped"),h(this,tt,"JSONSeriesIterator"),this.wrapped=e}next(){const e=this.wrapped.next();return e.done===!0?{done:!0,value:void 0}:{done:!1,value:de.decodeString(e.value,xt.SCHEMA)}}[(st=Symbol.iterator,tt=Symbol.toStringTag,st)](){return this}};h(Ut,"SCHEMA",i.z.record(i.z.string(),i.z.unknown()));let mr=Ut;var rt,nt;class br{constructor(e){h(this,"series"),h(this,"index"),h(this,rt,"SeriesIterator"),this.series=e,this.index=0}next(){return this.index>=this.series.length?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}[(nt=Symbol.iterator,rt=Symbol.toStringTag,nt)](){return this}}const it=s=>{const e=s>>32n,t=s&0xffffffffn;return{domain:e,sample:t}};i.z.object({key:i.z.string(),value:i.z.string()});i.z.record(i.z.union([i.z.number(),i.z.string(),i.z.symbol()]),i.z.unknown());const Nt=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser",vr=Nt(),Et=["macOS","Windows","Linux"],Tr=["macos","windows","linux"],Or={macos:"macOS",windows:"Windows",linux:"Linux"},Sr=i.z.enum(Et).or(i.z.enum(Tr).transform(s=>Or[s])),Ir=()=>{if(typeof window>"u")return;const s=window.navigator.userAgent.toLowerCase();if(s.includes("mac"))return"macOS";if(s.includes("win"))return"Windows";if(s.includes("linux"))return"Linux"};let Oe;const Ur=(s={})=>{const{force:e,default:t}=s;return e??Oe??(Oe=Ir(),Oe??t)},zt=Object.freeze(Object.defineProperty({__proto__:null,OPERATING_SYSTEMS:Et,RUNTIME:vr,detect:Nt,getOS:Ur,osZ:Sr},Symbol.toStringTag,{value:"Module"}));var xr=Object.defineProperty,Nr=(s,e,t)=>e in s?xr(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,re=(s,e,t)=>Nr(s,typeof e!="symbol"?e+"":e,t);const Er=(...s)=>s.map(At).join(""),At=s=>(s.endsWith("/")||(s+="/"),s.startsWith("/")&&(s=s.slice(1)),s),zr=s=>s.endsWith("/")?s.slice(0,-1):s,Ar=(s,e="")=>s===null?"":`?${Object.entries(s).filter(([,t])=>t==null?!1:Array.isArray(t)?t.length>0:!0).map(([t,r])=>`${e}${t}=${r}`).join("&")}`,Ae=class Be{constructor({host:e,port:t,protocol:r="",pathPrefix:n=""}){re(this,"protocol"),re(this,"host"),re(this,"port"),re(this,"path"),this.protocol=r,this.host=e,this.port=t,this.path=At(n)}replace(e){return new Be({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new Be({...this,pathPrefix:Er(this.path,e)})}toString(){return zr(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}};re(Ae,"UNKNOWN",new Ae({host:"unknown",port:0}));let Br=Ae;const $r=-128,Mr=127;i.z.number().int().min($r).max(Mr);const Cr=-32768,Rr=32767;i.z.number().int().min(Cr).max(Rr);const Dr=-2147483648,kr=2147483647;i.z.number().int().min(Dr).max(kr);const Lr=-9223372036854775808n,Pr=9223372036854775807n;i.z.bigint().min(Lr).max(Pr);const jr=255;i.z.number().int().min(0).max(jr);const Fr=65535;i.z.number().int().min(0).max(Fr);const Yr=4294967295;i.z.number().int().min(0).max(Yr);const Wr=18446744073709551615n;i.z.bigint().min(0n).max(Wr);var qr=Object.defineProperty,Vr=(s,e,t)=>e in s?qr(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t,C=(s,e,t)=>Vr(s,typeof e!="symbol"?e+"":e,t);const Zr=async s=>await new Promise(e=>setTimeout(e,w.fromMilliseconds(s).milliseconds));class Hr{constructor(e){C(this,"config"),C(this,"retries"),C(this,"interval"),this.config={baseInterval:new w((e==null?void 0:e.baseInterval)??w.seconds(1)),maxRetries:(e==null?void 0:e.maxRetries)??5,scale:(e==null?void 0:e.scale)??1,sleepFn:(e==null?void 0:e.sleepFn)??Zr},this.retries=0,this.interval=new w(this.config.baseInterval)}async wait(){const{maxRetries:e,scale:t,sleepFn:r}=this.config;return this.retries>=e?!1:(await r(this.interval),this.interval=this.interval.mult(t),this.retries++,!0)}reset(){this.retries=0,this.interval=this.config.baseInterval}}const Gr=i.z.object({baseInterval:w.z.optional(),maxRetries:i.z.number().optional(),scale:i.z.number().optional()}),Kr=Object.freeze(Object.defineProperty({__proto__:null,Breaker:Hr,breakerConfig:Gr},Symbol.toStringTag,{value:"Module"})),Jr=/^#?([0-9a-f]{6}|[0-9a-f]{8})$/i,Pe=i.z.string().regex(Jr),G=i.z.number().min(0).max(255),Xr=i.z.number().min(0).max(1),je=i.z.tuple([G,G,G,Xr]),Bt=i.z.tuple([G,G,G]),$t=i.z.object({rgba255:je}),Fe=(s,e=1)=>{if(typeof s=="string")return _r(s,e);if(Array.isArray(s)){if(s.length<3||s.length>4)throw new Error(`Invalid color: [${s.join(", ")}]`);return s.length===3?[...s,e]:s}if(typeof s=="object"&&"rgba255"in s)return s.rgba255;throw new Error(`Invalid color: ${JSON.stringify(s)}`)},Qr=i.z.union([Pe,je,Bt,$t]).transform(s=>Fe(s)),_r=(s,e=1)=>{if(!Pe.safeParse(s).success)throw new Error(`Invalid hex color: ${s}`);return s=en(s),[le(s,0),le(s,2),le(s,4),s.length===8?le(s,6)/255:e]},le=(s,e)=>parseInt(s.slice(e,e+2),16),en=s=>s.startsWith("#")?s.slice(1):s,tn=i.z.union([Pe,je,i.z.string(),Bt,$t]);Fe("#000000");Fe("#ffffff");const sn=i.z.object({key:i.z.string(),color:tn,position:i.z.number(),switched:i.z.boolean().optional()});i.z.array(sn);const rn=i.z.object({key:i.z.string(),name:i.z.string(),color:Qr});i.z.object({key:i.z.string(),name:i.z.string(),swatches:i.z.array(rn)});const nn=i.z.number().int().min(0).max(255),an=i.z.object({name:i.z.string(),key:i.z.string()}),pe=s=>i.z.object({subject:an,resource:s,authority:nn}),on=i.z.object({from:pe(i.z.any()),to:i.z.null()}),hn=i.z.object({from:i.z.null(),to:pe(i.z.any())});i.z.union([on,hn,i.z.object({from:pe(i.z.any()),to:pe(i.z.any())})]);const un=s=>Object.getOwnPropertySymbols(globalThis).includes(s),cn=(s,e)=>{const t=Symbol.for(s);if(!un(t)){const r=e();Object.defineProperty(globalThis,t,{value:r})}return()=>globalThis[t]},ln=s=>e=>e!=null&&typeof e=="object"&&"type"in e&&typeof e.type=="string"?e.type.startsWith(s):e instanceof Error?e.message.startsWith(s):typeof e!="string"?!1:e.startsWith(s),we=s=>{var e;return e=class extends Error{constructor(t,r){super(t,r),C(this,"discriminator",e.discriminator),C(this,"type",e.TYPE),C(this,"matches",e.matches),this.name=e.TYPE}static sub(t){return we(`${s}.${t}`)}},C(e,"discriminator","FreighterError"),C(e,"TYPE",s),C(e,"matches",ln(s)),e},Mt=s=>{if(s==null||typeof s!="object")return!1;const e=s;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},Z="unknown",$e="nil";class dn{constructor(){C(this,"providers",[])}register(e){this.providers.push(e)}encode(e){if(e==null)return{type:$e,data:""};if(Mt(e))for(const t of this.providers){const r=t.encode(e);if(r!=null)return r}if(e instanceof Error)return{type:Z,data:e.message};if(typeof e=="string")return{type:Z,data:e};try{return{type:Z,data:JSON.stringify(e)}}catch{return{type:Z,data:"unable to encode error information"}}}decode(e){if(e==null||e.type===$e)return null;if(e.type===Z)return new Me(e.data);for(const t of this.providers){const r=t.decode(e);if(r!=null)return r}return new Me(e.data)}}const Ye=cn("synnax-error-registry",()=>new dn),fn=({encode:s,decode:e})=>Ye().register({encode:s,decode:e}),gn=s=>Ye().encode(s),pn=s=>s==null?null:Ye().decode(s);class Me extends we("unknown"){}const yn=i.z.object({type:i.z.string(),data:i.z.string()});class wn extends we("canceled"){}const j=Object.freeze(Object.defineProperty({__proto__:null,Canceled:wn,NONE:$e,UNKNOWN:Z,Unknown:Me,createTyped:we,decode:pn,encode:gn,isTyped:Mt,payloadZ:yn,register:fn},Symbol.toStringTag,{value:"Module"}));i.object({jsonrpc:i.string(),id:i.number().optional(),method:i.string().optional(),params:i.unknown().optional(),result:i.unknown().optional()});i.z.string().regex(/^\d+\.\d+\.\d+$/);const mn=["standard","scientific","engineering"];i.z.enum(mn);class he extends j.createTyped("freighter"){}class Y extends he.sub("eof"){constructor(){super("EOF")}}class W extends he.sub("stream_closed"){constructor(){super("StreamClosed")}}class q extends he.sub("unreachable"){constructor(t={}){const{message:r="Unreachable",url:n=Br.UNKNOWN}=t;super(r);S(this,"url");this.url=n}}const bn=s=>{if(!s.type.startsWith(he.TYPE))return null;if(Y.matches(s))return{type:Y.TYPE,data:"EOF"};if(W.matches(s))return{type:W.TYPE,data:"StreamClosed"};if(q.matches(s))return{type:q.TYPE,data:"Unreachable"};throw new Error(`Unknown error type: ${s.type}: ${s.message}`)},vn=s=>{if(!s.type.startsWith(he.TYPE))return null;switch(s.type){case Y.TYPE:return new Y;case W.TYPE:return new W;case q.TYPE:return new q;default:throw new j.Unknown(`Unknown error type: ${s.data}`)}};j.register({encode:bn,decode:vn});class Ct{constructor(){S(this,"middleware",[])}use(...e){this.middleware.push(...e)}async executeMiddleware(e,t){let r=0;const n=async a=>{if(r===this.middleware.length)return await t(a);const o=this.middleware[r];return r++,await o(a,n)};return await n(e)}}const Rt="Content-Type",at=s=>{if(zt.RUNTIME!=="node")return fetch;const e=require("node-fetch");if(s==="http")return e;const t=require("https"),r=new t.Agent({rejectUnauthorized:!1});return async(n,a)=>await e(n,{...a,agent:r})},Tn=s=>"code"in s&&s.code==="ECONNREFUSED"||s.message.toLowerCase().includes("load failed"),On=400;class Sn extends Ct{constructor(t,r,n=!1){super();S(this,"endpoint");S(this,"encoder");S(this,"fetch");return this.endpoint=t.replace({protocol:n?"https":"http"}),this.encoder=r,this.fetch=at(this.endpoint.protocol),new Proxy(this,{get:(a,o,c)=>o==="endpoint"?this.endpoint:Reflect.get(a,o,c)})}get headers(){return{[Rt]:this.encoder.contentType}}async send(t,r,n,a){r=n==null?void 0:n.parse(r);let o=null;const c=this.endpoint.child(t),d={};d.method="POST",d.body=this.encoder.encode(r??{});const[,p]=await this.executeMiddleware({target:c.toString(),protocol:this.endpoint.protocol,params:{},role:"client"},async y=>{const l={...y,params:{}};d.headers={...this.headers,...y.params};let U;try{U=await at(y.protocol)(y.target,d)}catch(R){let z=R;return Tn(z)&&(z=new q({url:c})),[l,z]}const A=new Uint8Array(await(await U.blob()).arrayBuffer());if(U!=null&&U.ok)return a!=null&&(o=this.encoder.decode(A,a)),[l,null];try{if(U.status!==On)return[l,new Error(U.statusText)];const R=this.encoder.decode(A,j.payloadZ),z=j.decode(R);return[l,z]}catch(R){return[l,new Error(`[freighter] - failed to decode error: ${U.statusText}: ${R.message}`)]}});return p!=null?[null,p]:[o,null]}}const In=(s,e)=>{class t{constructor(n){S(this,"wrapped");this.wrapped=n}use(...n){this.wrapped.use(...n)}async send(n,a,o,c){const d=new Kr.Breaker(e);do{const[p,y]=await this.wrapped.send(n,a,o,c);if(y==null)return[p,null];if(!q.matches(y))return[null,y];if(!await d.wait())return[p,y]}while(!0)}}return new t(s)},Un=async(s,e,t,r,n)=>{const[a,o]=await s.send(e,t,r,n);if(o!=null)throw o;return a},xn=()=>zt.RUNTIME!=="node"?s=>new WebSocket(s):s=>new(require("ws")).WebSocket(s,{rejectUnauthorized:!1}),Nn=i.z.object({type:i.z.enum(["data","close","open"]),payload:i.z.unknown(),error:i.z.optional(j.payloadZ)});class En{constructor(e,t,r,n){S(this,"codec");S(this,"reqSchema");S(this,"resSchema");S(this,"ws");S(this,"serverClosed");S(this,"sendClosed");S(this,"receiveDataQueue",[]);S(this,"receiveCallbacksQueue",[]);this.codec=t,this.reqSchema=r,this.resSchema=n,this.ws=e,this.sendClosed=!1,this.serverClosed=null,this.listenForMessages()}async receiveOpenAck(){const e=await this.receiveMsg();if(e.type!=="open"){if(e.error==null)throw new Error("Message error must be defined");return j.decode(e.error)}return null}send(e){if(this.serverClosed!=null)return new Y;if(this.sendClosed)throw new W;return this.ws.send(this.codec.encode({type:"data",payload:e})),null}async receive(){if(this.serverClosed!=null)return[null,this.serverClosed];const e=await this.receiveMsg();if(e.type==="close"){if(e.error==null)throw new Error("Message error must be defined");return this.serverClosed=j.decode(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.codec.encode(e))}finally{this.sendClosed=!0}}async receiveMsg(){const e=this.receiveDataQueue.shift();return e??await new Promise((t,r)=>this.receiveCallbacksQueue.push({resolve:t,reject:r}))}addMessage(e){const t=this.receiveCallbacksQueue.shift();t!=null?t.resolve(e):this.receiveDataQueue.push(e)}listenForMessages(){this.ws.onmessage=this.onMessage.bind(this),this.ws.onclose=this.onClose.bind(this)}onMessage(e){this.addMessage(this.codec.decode(e.data,Nn))}onClose(e){this.addMessage({type:"close",error:{type:e.code===An?Y.TYPE:W.TYPE,data:""}})}}const zn="freighterctx",An=1e3,ae=class ae extends Ct{constructor(t,r,n=!1){super();S(this,"baseUrl");S(this,"encoder");S(this,"secure");this.secure=n,this.baseUrl=t.replace({protocol:n?"wss":"ws"}),this.encoder=r}withCodec(t){const r=new ae(this.baseUrl,t,this.secure);return r.use(...this.middleware),r}async stream(t,r,n){const a=xn();let o;const[,c]=await this.executeMiddleware({target:t,protocol:"websocket",params:{},role:"client"},async d=>{const p=a(this.buildURL(t,d)),y={...d,params:{}};p.binaryType=ae.MESSAGE_TYPE;const l=await this.wrapSocket(p,r,n);return l instanceof Error?[y,l]:(o=l,[y,null])});if(c!=null)throw c;return o}buildURL(t,r){const n=Ar({[Rt]:this.encoder.contentType,...r.params},zn);return this.baseUrl.child(t).toString()+n}async wrapSocket(t,r,n){return await new Promise(a=>{t.onopen=()=>{const o=new En(t,this.encoder,r,n);o.receiveOpenAck().then(c=>{c!=null?a(c):a(o)}).catch(c=>a(c))},t.onerror=o=>{const c=o;a(new Error(c.message))}})}};S(ae,"MESSAGE_TYPE","arraybuffer");let Ce=ae;exports.EOF=Y;exports.HTTPClient=Sn;exports.StreamClosed=W;exports.Unreachable=q;exports.WebSocketClient=Ce;exports.sendRequired=Un;exports.unaryWithBreaker=In;
|
|
5
|
+
`).buffer):this.dataType.usesBigInt&&typeof v=="number"?this._data=new this.dataType.Array(h.map(w=>BigInt(Math.round(w)))).buffer:!this.dataType.usesBigInt&&typeof v=="bigint"?this._data=new this.dataType.Array(h.map(Number)).buffer:this._data=new this.dataType.Array(h).buffer}this.key=d,this.alignment=l,this.sampleOffset=i??0,this.timeRange=r??O.ZERO,this.gl={control:null,buffer:null,prevBuffer:0,bufferUsage:o}}static alloc({capacity:e,dataType:t,...r}){if(e===0)throw new Error("[Series] - cannot allocate an array of length 0");const i=new new a(t).Array(e),o=new S({data:i.buffer,dataType:t,...r});return o.writePos=0,o}get refCount(){return this._refCount}acquire(e){this._refCount++,e!=null&&this.updateGLBuffer(e)}release(){this._refCount--,this.refCount===0&&this.gl.control!=null?this.maybeGarbageCollectGLBuffer(this.gl.control):this.refCount<0&&console.warn("cannot release a series with a negative reference count")}write(e){if(!e.dataType.equals(this.dataType))throw new Error("buffer must be of the same type as this array");return this.dataType.isVariable?this.writeVariable(e):this.writeFixed(e)}writeVariable(e){if(this.writePos===x)return 0;const t=this.byteCapacity.valueOf()-this.writePos,r=e.subBytes(0,t);return this.writeToUnderlyingData(r),this.writePos+=r.byteLength.valueOf(),this.cachedLength!=null&&(this.cachedLength+=r.length,this.calculateCachedLength()),r.length}writeFixed(e){if(this.writePos===x)return 0;const t=this.capacity-this.writePos,r=e.sub(0,t);return this.writeToUnderlyingData(r),this.cachedLength=void 0,this.maybeRecomputeMinMax(r),this.writePos+=r.length,r.length}writeToUnderlyingData(e){this.underlyingData.set(e.data,this.writePos)}get buffer(){return typeof this._data=="object"&&"buffer"in this._data?this._data.buffer:this._data}get underlyingData(){return new this.dataType.Array(this._data)}get data(){return this.writePos===x?this.underlyingData:new this.dataType.Array(this._data,0,this.writePos)}toStrings(){return this.dataType.isVariable?new TextDecoder().decode(this.underlyingData).split(`
|
|
6
|
+
`).slice(0,-1):Array.from(this).map(e=>e.toString())}parseJSON(e){if(!this.dataType.equals(a.JSON))throw new Error("cannot parse non-JSON series as JSON");return this.toStrings().map(t=>e.parse(ee.decodeString(t)))}get byteCapacity(){return new p(this.underlyingData.byteLength)}get capacity(){return this.dataType.isVariable?this.byteCapacity.valueOf():this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===x?this.byteCapacity:this.dataType.isVariable?new p(this.writePos):this.dataType.density.size(this.writePos)}get length(){return this.cachedLength!=null?this.cachedLength:this.dataType.isVariable?this.calculateCachedLength():this.writePos===x?this.byteCapacity.valueOf()/this.dataType.density.valueOf():this.writePos}calculateCachedLength(){if(!this.dataType.isVariable)throw new Error("cannot calculate length of a non-variable length data type");let e=0;const t=[0];return this.data.forEach((r,i)=>{r===te&&(e++,t.push(i+1))}),this._cachedIndexes=t,this.cachedLength=e,e}convert(e,t=0){if(this.dataType.equals(e))return this;const r=new e.Array(this.length);for(let i=0;i<this.length;i++)r[i]=Ut(this.dataType,e,this.data[i],t);return new S({data:r.buffer,dataType:e,timeRange:this.timeRange,sampleOffset:t,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment})}calcRawMax(){if(this.length===0)return-1/0;if(this.dataType.equals(a.TIMESTAMP))this.cachedMax=this.data[this.data.length-1];else if(this.dataType.usesBigInt){const e=this.data;this.cachedMax=e.reduce((t,r)=>t>r?t:r)}else{const e=this.data;this.cachedMax=e.reduce((t,r)=>t>r?t:r)}return this.cachedMax}get max(){return this.calcMax()}calcMax(){if(this.dataType.isVariable)throw new Error("cannot calculate maximum on a variable length data type");return this.writePos===0?-1/0:(this.cachedMax??=this.calcRawMax(),V(this.cachedMax,this.sampleOffset))}calcRawMin(){if(this.length===0)return 1/0;if(this.dataType.equals(a.TIMESTAMP))this.cachedMin=this.data[0];else if(this.dataType.usesBigInt){const e=this.data;this.cachedMin=e.reduce((t,r)=>t<r?t:r)}else{const e=this.data;this.cachedMin=e.reduce((t,r)=>t<r?t:r)}return this.cachedMin}get min(){return this.calcMin()}calcMin(){if(this.dataType.isVariable)throw new Error("cannot calculate minimum on a variable length data type");return this.writePos===0?1/0:(this.cachedMin??=this.calcRawMin(),V(this.cachedMin,this.sampleOffset))}get bounds(){return A(Number(this.min),Number(this.max),{makeValid:!1})}maybeRecomputeMinMax(e){if(this.cachedMin!=null){const t=e.cachedMin??e.calcRawMin();t<this.cachedMin&&(this.cachedMin=t)}if(this.cachedMax!=null){const t=e.cachedMax??e.calcRawMax();t>this.cachedMax&&(this.cachedMax=t)}}atAlignment(e,t){const r=Number(e-this.alignment);if(r<0||r>=this.length){if(t===!0)throw new Error(`[series] - no value at index ${r}`);return}return this.at(r,t)}at(e,t=!1){if(this.dataType.isVariable)return this.atVariable(e,t??!1);if(this.dataType.equals(a.UUID))return this.atUUID(e,t);e<0&&(e=this.length+e);const r=this.data[e];if(r==null){if(t===!0)throw new Error(`[series] - no value at index ${e}`);return}return V(r,this.sampleOffset)}atUUID(e,t){e<0&&(e=this.length+e);const r=Ue(new Uint8Array(this.buffer,e*this.dataType.density.valueOf()));if(r==null){if(t)throw new Error(`[series] - no value at index ${e}`);return}return r}atVariable(e,t){let r=0,i=0;if(this._cachedIndexes!=null)r=this._cachedIndexes[e],i=this._cachedIndexes[e+1]-1;else{e<0&&(e=this.length+e);for(let l=0;l<this.data.length;l++)if(this.data[l]===te){if(e===0){i=l;break}r=l+1,e--}if(i===0&&(i=this.data.length),r>=i||e>0){if(t)throw new Error(`[series] - no value at index ${e}`);return}}const o=this.data.slice(r,i);return this.dataType.equals(a.STRING)?new TextDecoder().decode(o):Te(JSON.parse(new TextDecoder().decode(o)))}binarySearch(e){let t=0,r=this.length-1;const i=Je(e);for(;t<=r;){const o=Math.floor((t+r)/2),l=i(this.at(o,!0),e);if(l===0)return o;l<0?t=o+1:r=o-1}return t}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals(a.FLOAT32)&&!this.dataType.equals(a.UINT8))throw new Error("Only FLOAT32 and UINT8 arrays can be used in WebGL");const{buffer:t,bufferUsage:r,prevBuffer:i}=this.gl;if(t==null&&(this.gl.buffer=e.createBuffer()),this.writePos!==i)if(e.bindBuffer(e.ARRAY_BUFFER,this.gl.buffer),this.writePos!==x){i===0&&e.bufferData(e.ARRAY_BUFFER,this.byteCapacity.valueOf(),e.STATIC_DRAW);const o=this.dataType.density.size(i).valueOf(),l=this.underlyingData.slice(this.gl.prevBuffer,this.writePos);e.bufferSubData(e.ARRAY_BUFFER,o,l.buffer),this.gl.prevBuffer=this.writePos}else e.bufferData(e.ARRAY_BUFFER,this.buffer,r==="static"?e.STATIC_DRAW:e.DYNAMIC_DRAW),this.gl.prevBuffer=x}as(e){return Lt(e,this.dataType),this}get digest(){return{key:this.key,dataType:this.dataType.toString(),sampleOffset:this.sampleOffset,alignment:{lower:we(this.alignmentBounds.lower),upper:we(this.alignmentBounds.upper)},timeRange:this.timeRange.toString(),length:this.length,capacity:this.capacity}}get alignmentBounds(){return A(this.alignment,this.alignment+BigInt(this.length))}maybeGarbageCollectGLBuffer(e){this.gl.buffer!=null&&(e.deleteBuffer(this.gl.buffer),this.gl.buffer=null,this.gl.prevBuffer=0,this.gl.control=null)}get glBuffer(){if(this.gl.buffer==null)throw new Error("gl buffer not initialized");return this.gl.prevBuffer!==this.writePos&&console.warn("buffer not updated"),this.gl.buffer}[Symbol.iterator](){if(this.dataType.isVariable){const e=new jt(this);return this.dataType.equals(a.JSON)?new ie(e):e}return this.dataType.equals(a.UUID)?new Yt(this):new qt(this)}slice(e,t){return this.sliceSub(!1,e,t)}sub(e,t){return this.sliceSub(!0,e,t)}subIterator(e,t){return new me(this,e,t??this.length)}subAlignmentIterator(e,t){return new me(this,Number(e-this.alignment),Number(t-this.alignment))}subBytes(e,t){if(e>=0&&(t==null||t>=this.byteLength.valueOf()))return this;const r=this.data.subarray(e,t);return new S({data:r,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(e)})}sliceSub(e,t,r){if(t<=0&&(r==null||r>=this.length))return this;let i;return e?i=this.data.subarray(t,r):i=this.data.slice(t,r),new S({data:i,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(t)})}reAlign(e){return new S({data:this.buffer,dataType:this.dataType,timeRange:O.ZERO,sampleOffset:this.sampleOffset,glBufferUsage:"static",alignment:e})}toString(){let e=`Series(${this.dataType.toString()} ${this.length} [`;if(this.length<=10)e+=Array.from(this).map(t=>t.toString());else{for(let t=0;t<5;t++)e+=`${this.at(t)?.toString()}`,e+=",";e+="...,";for(let t=-5;t<0;t++)e+=this.at(t)?.toString(),t<-1&&(e+=",")}return e+="])",e}}const Pt=n=>n==null?!1:Array.isArray(n)||n instanceof ArrayBuffer||ArrayBuffer.isView(n)&&!(n instanceof DataView)||n instanceof S?!0:Ae(n),kt=xt(Ce,S);let me=class{series;end;index;constructor(e,t,r){this.series=e;const i=A(0,e.length);this.end=fe(i,r),this.index=fe(i,t)}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}},jt=class{series;index;decoder;constructor(e){if(!e.dataType.isVariable)throw new Error("cannot create a variable series iterator for a non-variable series");this.series=e,this.index=0,this.decoder=new TextDecoder}next(){const e=this.index,t=this.series.data;for(;this.index<t.length&&t[this.index]!==te;)this.index++;const r=this.index;return e===r?{done:!0,value:void 0}:(this.index++,{done:!1,value:this.decoder.decode(this.series.buffer.slice(e,r))})}};class ie{wrapped;static schema=s.z.record(s.z.string(),s.z.unknown());constructor(e){this.wrapped=e}next(){const e=this.wrapped.next();return e.done===!0?{done:!0,value:void 0}:{done:!1,value:ee.decodeString(e.value,ie.schema)}}}class Yt{series;index;data;density;constructor(e){if(!e.dataType.equals(a.UUID))throw new Error("cannot create a UUID series iterator for a non-UUID series");this.series=e,this.index=0,this.data=new Uint8Array(e.buffer),this.density=a.UUID.density.valueOf()}next(){if(this.index>=this.series.length)return{done:!0,value:void 0};const e=Ue(this.data,this.index*this.density);return this.index++,{done:!1,value:e}}}class qt{series;index;constructor(e){this.series=e,this.index=0}next(){return this.index>=this.series.length?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}}const we=n=>{const e=n>>32n,t=n&0xffffffffn;return{domain:e,sample:t}};s.z.object({key:s.z.string(),value:s.z.string()});s.z.record(s.z.union([s.z.number(),s.z.string(),s.z.symbol()]),s.z.unknown());const Ft=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser";Ft();const Wt=["macOS","Windows","Linux"],Zt=["macos","windows","linux"],Vt={macos:"macOS",windows:"Windows",linux:"Linux"};s.z.enum(Wt).or(s.z.enum(Zt).transform(n=>Vt[n]));const Gt=(...n)=>n.map(Me).join(""),Me=n=>(n.endsWith("/")||(n+="/"),n.startsWith("/")&&(n=n.slice(1)),n),Jt=n=>n.endsWith("/")?n.slice(0,-1):n,Ht=(n,e="")=>n===null?"":`?${Object.entries(n).filter(([,t])=>t==null?!1:Array.isArray(t)?t.length>0:!0).map(([t,r])=>`${e}${t}=${r}`).join("&")}`;class j{protocol;host;port;path;constructor({host:e,port:t,protocol:r="",pathPrefix:i=""}){this.protocol=r,this.host=e,this.port=t,this.path=Me(i)}replace(e){return new j({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new j({...this,pathPrefix:Gt(this.path,e)})}toString(){return Jt(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}static UNKNOWN=new j({host:"unknown",port:0})}const Xt=async n=>await new Promise(e=>setTimeout(e,u.fromMilliseconds(n).milliseconds));class Kt{config;retries;interval;constructor(e){this.config={baseInterval:new u(e?.baseInterval??u.seconds(1)),maxRetries:e?.maxRetries??5,scale:e?.scale??1,sleepFn:e?.sleepFn??Xt},this.retries=0,this.interval=new u(this.config.baseInterval)}async wait(){const{maxRetries:e,scale:t,sleepFn:r}=this.config;return this.retries>=e?!1:(await r(this.interval),this.interval=this.interval.mult(t),this.retries++,!0)}reset(){this.retries=0,this.interval=this.config.baseInterval}}const Qt=s.z.object({baseInterval:u.z.optional(),maxRetries:s.z.number().optional(),scale:s.z.number().optional()}),_t=Object.freeze(Object.defineProperty({__proto__:null,Breaker:Kt,breakerConfigZ:Qt},Symbol.toStringTag,{value:"Module"})),en=/^#?([0-9a-f]{6}|[0-9a-f]{8})$/i,Be=s.z.string().regex(en),L=s.z.number().min(0).max(255),$e=s.z.number().min(0).max(1),Re=s.z.tuple([L,L,L,$e]),tn=s.z.tuple([L,L,L]),nn=s.z.object({rgba255:Re}),rn=s.z.number().min(0).max(360),sn=s.z.number().min(0).max(100),an=s.z.number().min(0).max(100),on=s.z.tuple([rn,sn,an,$e]),ae=s.z.union([Be,tn,Re,on,nn]),un=ae.transform(n=>oe(n)),oe=(n,e=1)=>{if(n=ae.parse(n),typeof n=="string")return cn(n,e);if(Array.isArray(n)){if(n.length<3||n.length>4)throw new Error(`Invalid color: [${n.join(", ")}]`);return n.length===3?[...n,e]:n}return n.rgba255},cn=(n,e=1)=>(n=Be.parse(n),n=ln(n),[Z(n,0),Z(n,2),Z(n,4),n.length===8?Z(n,6)/255:e]),Z=(n,e)=>parseInt(n.slice(e,e+2),16),ln=n=>n.startsWith("#")?n.slice(1):n;oe("#000000");oe("#ffffff");const hn=s.z.object({key:s.z.string(),color:ae,position:s.z.number(),switched:s.z.boolean().optional()});s.z.array(hn);const fn=s.z.object({key:s.z.string(),name:s.z.string(),color:un});s.z.object({key:s.z.string(),name:s.z.string(),swatches:s.z.array(fn)});s.z.int().min(0).max(255);s.z.object({name:s.z.string(),key:s.z.string()});const dn=n=>Object.getOwnPropertySymbols(globalThis).includes(n),gn=(n,e)=>{const t=Symbol.for(n);if(!dn(t)){const r=e();Object.defineProperty(globalThis,t,{value:r})}return()=>globalThis[t]},De="sy_x_error",pn=n=>e=>e!=null&&typeof e=="object"&&"type"in e&&typeof e.type=="string"?e.type.startsWith(n):e instanceof Error?e.message.startsWith(n):typeof e!="string"?!1:e.startsWith(n),Y=n=>class k extends Error{static discriminator=De;discriminator=k.discriminator;static TYPE=n;type=k.TYPE;static matches=pn(n);matches=k.matches;constructor(t,r){super(t,r),this.name=k.TYPE}static sub(t){return Y(`${n}.${t}`)}},Le=n=>{if(n==null||typeof n!="object")return!1;const e=n;if(e.discriminator!==De)return!1;if(!("type"in e))throw new Error(`X Error is missing its type property: ${JSON.stringify(e)}`);return!0},D="unknown",ne="nil";class yn{providers=[];register(e){this.providers.push(e)}encode(e){if(e==null)return{type:ne,data:""};if(Le(e))for(const t of this.providers){const r=t.encode(e);if(r!=null)return r}if(e instanceof Error)return{type:D,data:e.message};if(typeof e=="string")return{type:D,data:e};try{return{type:D,data:JSON.stringify(e)}}catch{return{type:D,data:"unable to encode error information"}}}decode(e){if(e==null||e.type===ne)return null;if(e.type===D)return new re(e.data);for(const t of this.providers){const r=t.decode(e);if(r!=null)return r}return new re(e.data)}}const ue=gn("synnax-error-registry",()=>new yn),mn=({encode:n,decode:e})=>ue().register({encode:n,decode:e}),wn=n=>ue().encode(n),bn=n=>n==null?null:ue().decode(n);class re extends Y("unknown"){}const Tn=s.z.object({type:s.z.string(),data:s.z.string()});class On extends Y("canceled"){}class vn extends Y("not_implemented"){}const E=Object.freeze(Object.defineProperty({__proto__:null,Canceled:On,NONE:ne,NotImplemented:vn,UNKNOWN:D,Unknown:re,createTyped:Y,decode:bn,encode:wn,isTyped:Le,payloadZ:Tn,register:mn},Symbol.toStringTag,{value:"Module"})),In=s.object({jsonrpc:s.literal("2.0"),method:s.string(),params:s.any().optional(),id:s.union([s.string(),s.number(),s.null()]).optional()}),Pe=s.object({jsonrpc:s.literal("2.0"),id:s.union([s.string(),s.number(),s.null()])}),Sn=Pe.extend({result:s.json()}),Nn=Pe.extend({error:s.object({code:s.number().int(),message:s.string().optional(),data:s.json().optional()})}),zn=s.union([Sn,Nn]);s.union([In,zn]);s.z.string().regex(/^\d+\.\d+\.\d+$/);const xn=["standard","scientific","engineering"];s.z.enum(xn);s.z.enum(["success","info","warning","error","loading","disabled"]);class q extends E.createTyped("freighter"){}class U extends q.sub("eof"){constructor(){super("EOF")}}class C extends q.sub("stream_closed"){constructor(){super("StreamClosed")}}class M extends q.sub("unreachable"){url;constructor(e={}){const{message:t="Unreachable",url:r=j.UNKNOWN}=e;super(t),this.url=r}}const En=n=>{if(!n.type.startsWith(q.TYPE))return null;if(U.matches(n))return{type:U.TYPE,data:"EOF"};if(C.matches(n))return{type:C.TYPE,data:"StreamClosed"};if(M.matches(n))return{type:M.TYPE,data:"Unreachable"};throw new Error(`Unknown error type: ${n.type}: ${n.message}`)},An=n=>{if(!n.type.startsWith(q.TYPE))return null;switch(n.type){case U.TYPE:return new U;case C.TYPE:return new C;case M.TYPE:return new M;default:throw new E.Unknown(`Unknown error type: ${n.data}`)}};E.register({encode:En,decode:An});class ke{middleware=[];use(...e){this.middleware.push(...e)}async executeMiddleware(e,t){let r=0;const i=async o=>{if(r===this.middleware.length)return await t(o);const l=this.middleware[r];return r++,await l(o,i)};return await i(e)}}const je="Content-Type",Un=n=>typeof n.cause=="object"&&n.cause!==null&&"code"in n.cause&&n.cause.code==="ECONNREFUSED",Cn=400;class Mn extends ke{endpoint;encoder;constructor(e,t,r=!1){return super(),this.endpoint=e.replace({protocol:r?"https":"http"}),this.encoder=t,new Proxy(this,{get:(i,o,l)=>o==="endpoint"?this.endpoint:Reflect.get(i,o,l)})}get headers(){return{[je]:this.encoder.contentType}}async send(e,t,r,i){t=r?.parse(t);let o=null;const l=this.endpoint.child(e),d={};d.method="POST",d.body=this.encoder.encode(t??{});const[,f]=await this.executeMiddleware({target:l.toString(),protocol:this.endpoint.protocol,params:{},role:"client"},async g=>{const m={...g,params:{}};d.headers={...this.headers,...g.params};let h;try{h=await fetch(g.target,d)}catch(w){if(!(w instanceof Error))throw w;return[m,Un(w)?new M({url:l}):w]}const v=await h.arrayBuffer();if(h?.ok)return i!=null&&(o=this.encoder.decode(v,i)),[m,null];try{if(h.status!==Cn)return[m,new Error(h.statusText)];const w=this.encoder.decode(v,E.payloadZ),F=E.decode(w);return[m,F]}catch(w){return[m,new Error(`[freighter] - failed to decode error: ${h.statusText}: ${w.message}`)]}});if(f!=null)return[null,f];if(o==null)throw new Error("Response must be defined");return[o,null]}}const Bn=(n,e)=>{class t{wrapped;constructor(i){this.wrapped=i}use(...i){this.wrapped.use(...i)}async send(i,o,l,d){const f=new _t.Breaker(e);do{const[g,m]=await this.wrapped.send(i,o,l,d);if(m==null)return[g,null];if(!M.matches(m))return[null,m];if(!await f.wait())return[g,m]}while(!0)}}return new t(n)},$n=async(n,e,t,r,i)=>{const[o,l]=await n.send(e,t,r,i);if(l!=null)throw l;return o},Rn=s.z.object({type:s.z.enum(["data","close","open"]),payload:s.z.unknown(),error:s.z.optional(E.payloadZ)});class Dn{codec;reqSchema;resSchema;ws;serverClosed;sendClosed;receiveDataQueue=[];receiveCallbacksQueue=[];constructor(e,t,r,i){this.codec=t,this.reqSchema=r,this.resSchema=i,this.ws=e,this.sendClosed=!1,this.serverClosed=null,this.listenForMessages()}async receiveOpenAck(){const e=await this.receiveMsg();if(e.type!=="open"){if(e.error==null)throw new Error("Message error must be defined");return E.decode(e.error)}return null}send(e){if(this.serverClosed!=null)return new U;if(this.sendClosed)throw new C;return this.ws.send(this.codec.encode({type:"data",payload:e})),null}async receive(){if(this.serverClosed!=null)return[null,this.serverClosed];const e=await this.receiveMsg();if(e.type==="close"){if(e.error==null)throw new Error("Message error must be defined");if(this.serverClosed=E.decode(e.error),this.serverClosed==null)throw new Error("Message error must be defined");return[null,this.serverClosed]}return[this.resSchema.parse(e.payload),null]}received(){return this.receiveDataQueue.length!==0}closeSend(){if(this.sendClosed||this.serverClosed!=null)return;const e={type:"close"};try{this.ws.send(this.codec.encode(e))}finally{this.sendClosed=!0}}async receiveMsg(){const e=this.receiveDataQueue.shift();return e??await new Promise((t,r)=>this.receiveCallbacksQueue.push({resolve:t,reject:r}))}addMessage(e){const t=this.receiveCallbacksQueue.shift();t!=null?t.resolve(e):this.receiveDataQueue.push(e)}listenForMessages(){this.ws.onmessage=this.onMessage.bind(this),this.ws.onclose=this.onClose.bind(this)}onMessage(e){this.addMessage(this.codec.decode(e.data,Rn))}onClose(e){this.addMessage({type:"close",error:{type:e.code===Pn?U.TYPE:C.TYPE,data:""}})}}const Ln="freighterctx",Pn=1e3;class J extends ke{baseUrl;encoder;secure;static MESSAGE_TYPE="arraybuffer";constructor(e,t,r=!1){super(),this.secure=r,this.baseUrl=e.replace({protocol:r?"wss":"ws"}),this.encoder=t}withCodec(e){const t=new J(this.baseUrl,e,this.secure);return t.use(...this.middleware),t}async stream(e,t,r){let i;const[,o]=await this.executeMiddleware({target:e,protocol:"websocket",params:{},role:"client"},async l=>{const d=new WebSocket(this.buildURL(e,l)),f={...l,params:{}};d.binaryType=J.MESSAGE_TYPE;const g=await this.wrapSocket(d,t,r);return g instanceof Error?[f,g]:(i=g,[f,null])});if(o!=null)throw o;return i}buildURL(e,t){const r=Ht({[je]:this.encoder.contentType,...t.params},Ln);return this.baseUrl.child(e).toString()+r}async wrapSocket(e,t,r){return await new Promise(i=>{e.onopen=()=>{const o=new Dn(e,this.encoder,t,r);o.receiveOpenAck().then(l=>{l!=null?i(l):i(o)}).catch(l=>i(l))},e.onerror=o=>{const l=o;i(new Error(l.message))}})}}exports.EOF=U;exports.HTTPClient=Mn;exports.StreamClosed=C;exports.Unreachable=M;exports.WebSocketClient=J;exports.sendRequired=$n;exports.unaryWithBreaker=Bn;
|