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