@synnaxlabs/freighter 0.49.0 โ 0.52.3
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 +9 -9
- package/dist/eslint.config.d.ts +2 -2
- package/dist/eslint.config.d.ts.map +1 -1
- package/dist/freighter.cjs +4 -4
- package/dist/freighter.js +300 -330
- package/dist/src/stream.d.ts.map +1 -1
- package/dist/src/websocket.d.ts.map +1 -1
- package/eslint.config.ts +3 -3
- package/package.json +11 -10
- package/src/alamos.ts +1 -1
- package/src/errors.spec.ts +1 -1
- package/src/errors.ts +1 -1
- package/src/http.spec.ts +1 -1
- package/src/http.ts +1 -1
- package/src/index.ts +1 -1
- package/src/middleware.ts +1 -1
- package/src/stream.ts +2 -3
- package/src/transport.ts +1 -1
- package/src/unary.ts +1 -1
- package/src/websocket.spec.ts +1 -1
- package/src/websocket.ts +5 -4
- package/vite.config.ts +1 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
|
|
2
|
-
> @synnaxlabs/freighter@0.
|
|
2
|
+
> @synnaxlabs/freighter@0.52.3 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.3.1 [32mbuilding client environment for production...[36m[39m
|
|
7
7
|
transforming...
|
|
8
8
|
[32mโ[39m 7 modules transformed.
|
|
9
9
|
rendering chunks...
|
|
10
|
-
|
|
11
|
-
[vite:dts] Start generate declaration files
|
|
10
|
+
[32m
|
|
11
|
+
[36m[vite:dts][32m Start generate declaration files...[39m
|
|
12
12
|
computing gzip size...
|
|
13
|
-
[2mdist/[22m[36mfreighter.js [39m[1m[
|
|
14
|
-
[vite:dts] Declaration files built in
|
|
15
|
-
|
|
16
|
-
[2mdist/[22m[36mfreighter.cjs [39m[1m[
|
|
17
|
-
[32mโ built in 2.
|
|
13
|
+
[2mdist/[22m[36mfreighter.js [39m[1m[2m114.70 kB[22m[1m[22m[2m โ gzip: 27.14 kB[22m
|
|
14
|
+
[32m[36m[vite:dts][32m Declaration files built in 1684ms.
|
|
15
|
+
[39m
|
|
16
|
+
[2mdist/[22m[36mfreighter.cjs [39m[1m[2m56.51 kB[22m[1m[22m[2m โ gzip: 16.87 kB[22m
|
|
17
|
+
[32mโ built in 2.09s[39m
|
package/dist/eslint.config.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { default as
|
|
2
|
-
export default
|
|
1
|
+
import { default as cfg } from '@synnaxlabs/eslint-config';
|
|
2
|
+
export default cfg;
|
|
3
3
|
//# sourceMappingURL=eslint.config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eslint.config.d.ts","sourceRoot":"","sources":["../eslint.config.ts"],"names":[],"mappings":"AASA,OAAO,
|
|
1
|
+
{"version":3,"file":"eslint.config.d.ts","sourceRoot":"","sources":["../eslint.config.ts"],"names":[],"mappings":"AASA,OAAO,GAAG,MAAM,2BAA2B,CAAC;AAE5C,eAAe,GAAG,CAAC"}
|
package/dist/freighter.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("zod"),Ke=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)},Ie=r=>{const e=(t,n=se)=>{if(typeof t=="string")return r(t);if(Array.isArray(t))return t.map(c=>e(c,n));if(!te(t))return t;n=et(n);const i={},o=t;return"toJSON"in o&&typeof o.toJSON=="function"?e(o.toJSON(),n):(Object.keys(o).forEach(c=>{let f=o[c];const w=r(c);n.recursive&&(te(f)?ye(f)||(f=e(f,n)):n.recursiveInArray&&me(f)&&(f=[...f].map(h=>{let g=h;return te(h)?ye(g)||(g=e(h,n)):me(h)&&(g=e({key:h},n).key),g}))),i[w]=f}),i)};return e},Ne=Ie(Ke),Xe=r=>r.replace(/([a-z0-9])([A-Z])/g,(e,t,n)=>`${t}_${n.toLowerCase()}`),Qe=Ie(Xe),_e=[Number,String,Uint8Array],se={recursive:!0,recursiveInArray:!0},et=(r=se)=>(r.recursive==null?r=se:r.recursiveInArray??=!1,r),me=r=>r!=null&&Array.isArray(r),te=r=>r!=null&&typeof r=="object"&&!Array.isArray(r),ye=r=>_e.some(e=>r instanceof e);class tt{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=Ne(n);return t!=null?t.parse(i):i}encodeString(e){const t=Qe(e);return JSON.stringify(t,(n,i)=>ArrayBuffer.isView(i)?Array.from(i):typeof i=="bigint"?i.toString():i)}}const ie=new tt,E=r=>r!=null&&typeof r=="object"&&"value"in r;class q{value;constructor(e){this.value=e}valueOf(){return this.value}toJSON(){return this.value}toString(){return this.value.toString()}}const rt=r=>r!=null&&typeof r=="object"&&"toString"in r,nt=(r,e=!1)=>{const t=rt(r)?"stringer":typeof r;let n;switch(t){case"string":n=(i,o)=>i.localeCompare(o);break;case"stringer":n=(i,o)=>i.toString().localeCompare(o.toString());break;case"number":n=(i,o)=>Number(i)-Number(o);break;case"bigint":n=(i,o)=>BigInt(i)-BigInt(o)>0n?1:-1;break;case"boolean":n=(i,o)=>Number(i)-Number(o);break;case"undefined":n=()=>0;break;default:return console.warn(`sortFunc: unknown type ${t}`),()=>-1}return e?st(n):n},st=r=>(e,t)=>r(t,e);let Ee=(r,e=21)=>(t=e)=>{let n="",i=t|0;for(;i--;)n+=r[Math.random()*r.length|0];return n};const ze="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",it=`0123456789${ze}`,at=11,ot=Ee(ze,1),ut=Ee(it,at-1),lt=()=>`${ot()}${ut()}`,ct=(r,e)=>t=>t instanceof e||typeof t=="object"&&t!==null&&"discriminator"in t&&t.discriminator===r,ht=2**12-1,ae=2n**63n-1n,dt=2**63-1,_=r=>(e,t)=>{if(typeof e=="bigint"){if(ft(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))},G=_((r,e)=>r-e),D=_((r,e)=>r+e),ft=r=>typeof r=="bigint"?!0:Number.isInteger(r),x=_((r,e)=>r*e),ee=_((r,e)=>r/e),Ae=s.z.tuple([s.z.number(),s.z.number()]),xe=s.z.object({width:s.z.number(),height:s.z.number()}),gt=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()}),mt=["start","center","end"],Z=s.z.object({x:s.z.number(),y:s.z.number()}),yt=s.z.object({clientX:s.z.number(),clientY:s.z.number()}),pt=["x","y"],Ue=s.z.enum(pt),Me=["top","right","bottom","left"];s.z.enum(Me);const wt=["left","right"],Ce=s.z.enum(wt),bt=["top","bottom"],Be=s.z.enum(bt),Re=["center"],pe=s.z.enum(Re),Ot=[...Me,...Re],De=s.z.enum(Ot);s.z.enum(mt);const Tt=["first","last"];s.z.enum(Tt);s.z.object({lower:s.z.number(),upper:s.z.number()});s.z.enum([...Ue.options,...De.options]);s.z.union([Ue,De,s.z.instanceof(String)]);const L=(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?vt(n):n},vt=r=>r.lower>r.upper?{lower:r.upper,upper:r.lower}:r,we=(r,e)=>{const t=L(r);return e<t.lower?t.lower:e>=t.upper?t.upper-(typeof t.upper=="number"?1:1n):e};s.z.object({x:Ce.or(pe),y:Be.or(pe)});const Le=s.z.object({x:Ce,y:Be}),St=Object.freeze({x:"left",y:"top"}),It=(r,e)=>r.x===e.x&&r.y===e.y,be=s.z.union([s.z.number(),Z,Ae,xe,gt,yt]),Nt=(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}},Oe=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:Z,two:Z,root:Le});const ce=(r,e,t=0,n=0,i)=>{const o={one:{...Oe},two:{...Oe},root:i??St};if(typeof r=="number"){if(typeof e!="number")throw new Error("Box constructor called with invalid arguments");return o.one={x:r,y:e},o.two={x:o.one.x+t,y:o.one.y+n},o}return"one"in r&&"two"in r&&"root"in r?{...r,root:i??r.root}:("getBoundingClientRect"in r&&(r=r.getBoundingClientRect()),"left"in r?(o.one={x:r.left,y:r.top},o.two={x:r.right,y:r.bottom},o):(o.one=r,e==null?o.two={x:o.one.x+t,y:o.one.y+n}:typeof e=="number"?o.two={x:o.one.x+e,y:o.one.y+t}:"width"in e?o.two={x:o.one.x+e.width,y:o.one.y+e.height}:"signedWidth"in e?o.two={x:o.one.x+e.signedWidth,y:o.one.y+e.signedHeight}:o.two=e,o))},re=r=>{const e=ce(r);return{lower:e.one.x,upper:e.two.x}},ne=r=>{const e=ce(r);return{lower:e.one.y,upper:e.two.y}},Et=r=>typeof r!="object"||r==null?!1:"one"in r&&"two"in r&&"root"in r,zt=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()});s.z.union([xe,zt,Z,Ae]);const At=(r,e,t)=>e!==void 0&&r<e?e:t!==void 0&&r>t?t:r;s.z.object({offset:be,scale:be});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],Ut=r=>(e,t,n,i)=>[e,i?n/r:n*r],Mt=r=>(e,t,n)=>{if(e===null)return[r,n];const{lower:i,upper:o}=e,{lower:c,upper:f}=r,w=o-i,h=f-c;if(t==="dimension")return[r,n*(h/w)];const g=(n-i)*(h/w)+c;return[r,g]},Ct=r=>(e,t,n)=>[r,n],Bt=()=>(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)]},Rt=r=>(e,t,n)=>{const{lower:i,upper:o}=r;return n=At(n,i,o),[e,n]};class C{ops=[];currBounds=null;currType=null;reversed=!1;constructor(){this.ops=[]}static translate(e){return new C().translate(e)}static magnify(e){return new C().magnify(e)}static scale(e,t){return new C().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=Ut(e);return n.type="magnify",t.ops.push(n),t}scale(e,t){const n=L(e,t),i=this.new(),o=Mt(n);return o.type="scale",i.ops.push(o),i}clamp(e,t){const n=L(e,t),i=this.new(),o=Rt(n);return o.type="clamp",i.ops.push(o),i}reBound(e,t){const n=L(e,t),i=this.new(),o=Ct(n);return o.type="re-bound",i.ops.push(o),i}invert(){const e=Bt();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 C;return e.ops=this.ops.slice(),e.reversed=this.reversed,e}exec(e,t){return this.currBounds=null,this.ops.reduce(([n,i],o)=>o(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,f])=>i>=c&&i<=f))return;const o=e.ops.findIndex((c,f)=>c.type==="scale"&&f>i);o!==-1&&t.push([i,o])}),t.forEach(([n,i])=>{const o=e.ops.slice(n,i);o.unshift(e.ops[i]),e.ops.splice(n,i-n+1,...o)}),e.reversed=!e.reversed,e}get transform(){return{scale:this.dim(1),offset:this.pos(0)}}static IDENTITY=new C}class A{x;y;currRoot;constructor(e=new C,t=new C,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=Nt(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(Et(e)){const n=this.currRoot;return t.currRoot=e.root,n!=null&&!It(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(re(e)),t.y=t.y.scale(ne(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(re(e)),t.y=this.y.reBound(ne(e)),t}clamp(e){const t=this.copy();return t.x=this.x.clamp(re(e)),t.y=this.y.clamp(ne(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 ce(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}const Dt=Z.extend({root:Le,units:s.object({x:s.enum(["px","decimal"]),y:s.enum(["px","decimal"])})});Dt.partial({root:!0,units:!0});const Lt=s.z.enum(["static","dynamic"]),Te=365,K=30,$t=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)])]),$e=(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 q{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===dt?e=ae: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())+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,o]=e.split(":");let c="00",f="00";o!=null&&([c,f]=o.split("."));let w=u.hours(parseInt(n??"00")).add(u.minutes(parseInt(i??"00"))).add(u.seconds(parseInt(c??"00"))).add(u.milliseconds(parseInt(f??"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,o=0;if(e.includes(".")){const h=e.split(".");i=h[0];const g=h[1]||"0";o=parseInt(g.padEnd(3,"0").slice(0,3))}const c=t==="local"?new Date(i.replace("T"," ")):new Date(`${i}Z`),f=BigInt(c.getTime())*u.MILLISECOND.valueOf(),w=BigInt(o)*u.MILLISECOND.valueOf();return f+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 I(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(D(this.valueOf(),new l(e).valueOf()))}sub(e){return new u(G(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 $e(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(ae);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)),$t.transform(e=>new u(e))]);static sort(e,t){return Number(e.valueOf()-t.valueOf())}}class l extends q{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 S?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 S?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 $e(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),o=this.truncate(l.SECOND),c=this.truncate(l.MILLISECOND),f=this.truncate(l.MICROSECOND),w=this.truncate(l.NANOSECOND),h=t,g=n.sub(t),b=i.sub(n),d=o.sub(i),O=c.sub(o),N=f.sub(c),z=w.sub(f);let y="";return h.isZero||(y+=`${h.days}d `),g.isZero||(y+=`${g.hours}h `),b.isZero||(y+=`${b.minutes}m `),d.isZero||(y+=`${d.seconds}s `),O.isZero||(y+=`${O.milliseconds}ms `),N.isZero||(y+=`${N.microseconds}ยตs `),z.isZero||(y+=`${z.nanoseconds}ns`),y.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,o=t.hours,c=t.minutes,f=t.seconds,w=Math.floor(i/Te),h=Math.floor(i/K),g=Math.floor(i/7),b=Math.floor(i),d=Math.floor(o),O=Math.floor(c),N=Math.floor(f),z=n?"-":"";if(w>=1){let y=`${w}y`;if(w<2){const T=Math.floor(i%Te/K);T>0&&(y+=` ${T}mo`)}return z+y}if(g>=1&&i<K&&i%7===0){let y=`${g}w`;const T=Math.floor(i%7),R=Math.floor(o-g*7*24);return g<2&&(T>0?y+=` ${T}d`:R>0&&R<24&&(y+=` ${R}h`)),z+y}if(h>=1){let y=`${h}mo`;if(h<3){const T=Math.floor(i%K);T>0&&(y+=` ${T}d`)}return z+y}if(g>=1){let y=`${g}w`;const T=Math.floor(i%7),R=Math.floor(o-g*7*24);return g<2&&(T>0?y+=` ${T}d`:R>0&&R<24&&(y+=` ${R}h`)),z+y}if(b>=1){let y=`${b}d`;const T=Math.floor(o-b*24);return b<2&&T>0&&(y+=` ${T}h`),z+y}if(d>=1){let y=`${d}h`;if(d<3){const T=Math.floor(c-d*60);T>0&&(y+=` ${T}m`)}return z+y}if(O>=1){let y=`${O}m`;if(O<5){const T=Math.floor(f-O*60);T>0&&(y+=` ${T}s`)}return z+y}return`${z}${N}s`}mult(e){return new l(x(this.valueOf(),e))}div(e){return new l(ee(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(x(e,1e3))}static MICROSECOND=l.microseconds(1);static milliseconds(e=1){return l.microseconds(x(e,1e3))}static MILLISECOND=l.milliseconds(1);static seconds(e=1){return l.milliseconds(x(e,1e3))}static SECOND=l.seconds(1);static minutes(e=1){return l.seconds(x(e,60))}static MINUTE=l.minutes(1);static hours(e){return l.minutes(x(e,60))}static HOUR=l.hours(1);static days(e){return l.hours(x(e,24))}static DAY=l.days(1);static MAX=new l(ae);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 S).transform(e=>new l(e))])}class S extends q{constructor(e){E(e)&&(e=e.value),super(e.valueOf())}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new S(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 p(t).valueOf()}span(e){return l.seconds(e/this.valueOf())}byteSpan(e,t){return this.span(e.valueOf()/new p(t).valueOf())}add(e){return new S(D(this.valueOf(),new S(e).valueOf()))}sub(e){return new S(G(this.valueOf(),new S(e).valueOf()))}mult(e){return new S(x(this.valueOf(),e))}div(e){return new S(ee(this.valueOf(),e))}static hz(e){return new S(e)}static khz(e){return S.hz(e*1e3)}static z=s.z.union([s.z.number().transform(e=>new S(e)),s.z.instanceof(S)])}class p extends q{constructor(e){E(e)&&(e=e.value),super(e.valueOf())}length(e){return e.valueOf()/this.valueOf()}size(e){return new m(e*this.valueOf())}add(e){return new p(D(this.valueOf(),new p(e).valueOf()))}sub(e){return new p(G(this.valueOf(),new p(e).valueOf()))}mult(e){return new p(x(this.valueOf(),e))}div(e){return new p(ee(this.valueOf(),e))}static UNKNOWN=new p(0);static BIT128=new p(16);static BIT64=new p(8);static BIT32=new p(4);static BIT16=new p(2);static BIT8=new p(1);static z=s.z.union([s.z.number().transform(e=>new p(e)),s.z.instanceof(p)])}class I{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 I(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),o=u.min(n.end,e.end);return o.before(i)?!1:new l(o.sub(i)).greaterThanOrEqual(t)}contains(e){return e instanceof I?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const t=new I(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 I(u.min(...e.map(t=>t.start)),u.max(...e.map(t=>t.end)))}static MAX=new I(u.MIN,u.MAX);static ZERO=new I(u.ZERO,u.ZERO);static z=s.z.union([s.z.object({start:u.z,end:u.z}).transform(e=>new I(e.start,e.end)),s.z.instanceof(I)]);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)=>I.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},[])}}class a extends q{constructor(e){if(E(e)&&(e=e.value),e instanceof a||typeof e=="string"||typeof e.valueOf()=="string")super(e.valueOf());else{const t=a.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);if(t==null)throw new Error(`unable to find data type for ${e.toString()}`);super(t.valueOf())}}get Array(){const e=a.ARRAY_CONSTRUCTORS.get(this.toString());if(e==null)throw new Error(`unable to find array constructor for ${this.valueOf()}`);return e}equals(e){return this.valueOf()===e.valueOf()}matches(...e){return e.some(t=>this.equals(t))}toString(e=!1){return e?a.SHORT_STRINGS.get(this.valueOf())??this.valueOf():this.valueOf()}get isVariable(){return this.equals(a.JSON)||this.equals(a.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(a.UUID)}get isInteger(){const e=this.toString();return e.startsWith("int")||e.startsWith("uint")}get isFloat(){return this.toString().startsWith("float")}get density(){const e=a.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}get isUnsignedInteger(){return this.equals(a.UINT8)||this.equals(a.UINT16)||this.equals(a.UINT32)||this.equals(a.UINT64)}get isSignedInteger(){return this.equals(a.INT8)||this.equals(a.INT16)||this.equals(a.INT32)||this.equals(a.INT64)}canSafelyCastTo(e){return this.equals(e)?!0:!this.isNumeric||!e.isNumeric||this.isVariable||e.isVariable||this.isUnsignedInteger&&e.isSignedInteger?!1:this.isFloat?e.isFloat&&this.density.valueOf()<=e.density.valueOf():this.equals(a.INT32)&&e.equals(a.FLOAT64)||this.equals(a.INT8)&&e.equals(a.FLOAT32)?!0:this.isInteger&&e.isInteger?this.density.valueOf()<=e.density.valueOf()&&this.isUnsignedInteger===e.isUnsignedInteger:!1}canCastTo(e){return this.isNumeric&&e.isNumeric?!0:this.equals(e)}checkArray(e){return e.constructor===this.Array}get usesBigInt(){return a.BIG_INT_TYPES.some(e=>e.equals(this))}static UNKNOWN=new a("unknown");static FLOAT64=new a("float64");static FLOAT32=new a("float32");static INT64=new a("int64");static INT32=new a("int32");static INT16=new a("int16");static INT8=new a("int8");static UINT64=new a("uint64");static UINT32=new a("uint32");static UINT16=new a("uint16");static UINT8=new a("uint8");static BOOLEAN=new a("boolean");static TIMESTAMP=new a("timestamp");static UUID=new a("uuid");static STRING=new a("string");static JSON=new a("json");static ARRAY_CONSTRUCTORS=new Map([[a.UINT8.toString(),Uint8Array],[a.UINT16.toString(),Uint16Array],[a.UINT32.toString(),Uint32Array],[a.UINT64.toString(),BigUint64Array],[a.FLOAT32.toString(),Float32Array],[a.FLOAT64.toString(),Float64Array],[a.INT8.toString(),Int8Array],[a.INT16.toString(),Int16Array],[a.INT32.toString(),Int32Array],[a.INT64.toString(),BigInt64Array],[a.TIMESTAMP.toString(),BigInt64Array],[a.STRING.toString(),Uint8Array],[a.JSON.toString(),Uint8Array],[a.UUID.toString(),Uint8Array]]);static ARRAY_CONSTRUCTOR_DATA_TYPES=new Map([[Uint8Array.name,a.UINT8],[Uint16Array.name,a.UINT16],[Uint32Array.name,a.UINT32],[BigUint64Array.name,a.UINT64],[Float32Array.name,a.FLOAT32],[Float64Array.name,a.FLOAT64],[Int8Array.name,a.INT8],[Int16Array.name,a.INT16],[Int32Array.name,a.INT32],[BigInt64Array.name,a.INT64]]);static DENSITIES=new Map([[a.UINT8.toString(),p.BIT8],[a.UINT16.toString(),p.BIT16],[a.UINT32.toString(),p.BIT32],[a.UINT64.toString(),p.BIT64],[a.FLOAT32.toString(),p.BIT32],[a.FLOAT64.toString(),p.BIT64],[a.INT8.toString(),p.BIT8],[a.INT16.toString(),p.BIT16],[a.INT32.toString(),p.BIT32],[a.INT64.toString(),p.BIT64],[a.TIMESTAMP.toString(),p.BIT64],[a.STRING.toString(),p.UNKNOWN],[a.JSON.toString(),p.UNKNOWN],[a.UUID.toString(),p.BIT128]]);static ALL=[a.UNKNOWN,a.FLOAT64,a.FLOAT32,a.INT64,a.INT32,a.INT16,a.INT8,a.UINT64,a.UINT32,a.UINT16,a.UINT8,a.TIMESTAMP,a.UUID,a.STRING,a.JSON];static SHORT_STRINGS=new Map([[a.UINT8.toString(),"u8"],[a.UINT16.toString(),"u16"],[a.UINT32.toString(),"u32"],[a.UINT64.toString(),"u64"],[a.INT8.toString(),"i8"],[a.INT16.toString(),"i16"],[a.INT32.toString(),"i32"],[a.INT64.toString(),"i64"],[a.FLOAT32.toString(),"f32"],[a.FLOAT64.toString(),"f64"],[a.BOOLEAN.toString(),"bool"],[a.TIMESTAMP.toString(),"ts"],[a.UUID.toString(),"uuid"],[a.STRING.toString(),"str"],[a.JSON.toString(),"json"]]);static BIG_INT_TYPES=[a.INT64,a.UINT64,a.TIMESTAMP];static z=s.z.union([s.z.string().transform(e=>new a(e)),s.z.instanceof(a)])}class m extends q{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 m(D(this.valueOf(),e.valueOf()))}sub(e){return E(e)&&(e=e.value),new m(G(this.valueOf(),e.valueOf()))}mult(e){return new m(x(this.valueOf(),e))}div(e){return new m(ee(this.valueOf(),e))}truncate(e){return new m(Math.trunc(this.valueOf()/new m(e).valueOf())*new m(e).valueOf())}remainder(e){return m.bytes(this.valueOf()%new m(e).valueOf())}get gigabytes(){return this.valueOf()/m.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/m.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/m.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/m.TERABYTE.valueOf()}toString(){const e=this.truncate(m.TERABYTE),t=this.truncate(m.GIGABYTE),n=this.truncate(m.MEGABYTE),i=this.truncate(m.KILOBYTE),o=this.truncate(m.BYTE),c=e,f=t.sub(e),w=n.sub(t),h=i.sub(n),g=o.sub(i);let b="";return c.isZero||(b+=`${c.terabytes}TB `),f.isZero||(b+=`${f.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 m(e)}static BYTE=new m(1);static kilobytes(e=1){return m.bytes(new m(e).valueOf()*1e3)}static KILOBYTE=m.kilobytes(1);static megabytes(e=1){return m.kilobytes(new m(e).valueOf()*1e3)}static MEGABYTE=m.megabytes(1);static gigabytes(e=1){return m.megabytes(new m(e).valueOf()*1e3)}static GIGABYTE=m.gigabytes(1);static terabytes(e){return m.gigabytes(new m(e).valueOf()*1e3)}static TERABYTE=m.terabytes(1);static ZERO=new m(0);static z=s.z.union([s.z.number().transform(e=>new m(e)),s.z.instanceof(m)]);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},kt=(r,e,t,n=0)=>r.usesBigInt&&!e.usesBigInt?Number(t)-Number(n):!r.usesBigInt&&e.usesBigInt?BigInt(t.valueOf())-BigInt(n.valueOf()):G(t,n),Pt=/^(?:[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 jt(r){return typeof r=="string"&&Pt.test(r)}const v=[];for(let r=0;r<256;++r)v.push((r+256).toString(16).slice(1));function Yt(r,e=0){return(v[r[e+0]]+v[r[e+1]]+v[r[e+2]]+v[r[e+3]]+"-"+v[r[e+4]]+v[r[e+5]]+"-"+v[r[e+6]]+v[r[e+7]]+"-"+v[r[e+8]]+v[r[e+9]]+"-"+v[r[e+10]]+v[r[e+11]]+v[r[e+12]]+v[r[e+13]]+v[r[e+14]]+v[r[e+15]]).toLowerCase()}function qt(r,e=0){const t=Yt(r,e);if(!jt(t))throw TypeError("Stringified UUID is invalid");return t}typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const Pe=(r,e)=>qt(r,e),M=-1,Ft=s.z.string().transform(r=>new Uint8Array(atob(r).split("").map(e=>e.charCodeAt(0))).buffer),Wt=s.z.union([s.z.null(),s.z.undefined()]).transform(()=>new Uint8Array().buffer),oe=10,Zt=(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`)},je="sy_x_telem_series";class U{key;discriminator=je;dataType;sampleOffset;gl;_data;timeRange=I.ZERO;alignment=0n;alignmentMultiple=1n;cachedMin;cachedMax;writePos=M;_refCount=0;cachedLength;_cachedIndexes;static crudeZ=s.z.object({timeRange:I.z.optional(),dataType:a.z,alignment:s.z.coerce.bigint().optional(),data:s.z.union([Ft,Wt,s.z.instanceof(ArrayBuffer),s.z.instanceof(Uint8Array)]),glBufferUsage:Lt.default("static").optional()});static z=U.crudeZ.transform(e=>new U(e));constructor(e){Gt(e)&&(e={data:e}),e.data??=[];const{dataType:t,timeRange:n,sampleOffset:i=0,glBufferUsage:o="static",alignment:c=0n,alignmentMultiple:f=1n,key:w=lt(),data:h}=e;if(Vt(h)){const d=h;this.key=d.key,this.dataType=d.dataType,this.sampleOffset=d.sampleOffset,this.gl=d.gl,this._data=d._data,this.timeRange=d.timeRange,this.alignment=d.alignment,this.alignmentMultiple=d.alignmentMultiple,this.cachedMin=d.cachedMin,this.cachedMax=d.cachedMax,this.writePos=d.writePos,this._refCount=d._refCount,this.cachedLength=d.cachedLength;return}const g=ke(h),b=Array.isArray(h);if(t!=null)this.dataType=new a(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 d=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.");d=h[0]}if(typeof d=="string")this.dataType=a.STRING;else if(typeof d=="number")this.dataType=a.FLOAT64;else if(typeof d=="bigint")this.dataType=a.INT64;else if(typeof d=="boolean")this.dataType=a.BOOLEAN;else if(d instanceof u||d instanceof Date||d instanceof u)this.dataType=a.TIMESTAMP;else if(typeof d=="object")this.dataType=a.JSON;else throw new Error(`cannot infer data type of ${typeof d} when constructing a Series from a JS array`)}else this.dataType=new a(h)}if(!b&&!g)this._data=h;else if(b&&h.length===0)this._data=new this.dataType.Array([]).buffer;else{let d=g?[h]:h;const O=d[0];(O instanceof u||O instanceof Date||O instanceof l)&&(d=d.map(N=>new u(N).valueOf())),this.dataType.equals(a.STRING)?(this.cachedLength=d.length,this._data=new TextEncoder().encode(`${d.join(`
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("zod"),Xe=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)},Ne=r=>{const e=(t,n=se)=>{if(typeof t=="string")return r(t);if(Array.isArray(t))return t.map(c=>e(c,n));if(!te(t))return t;n=et(n);const i={},o=t;return"toJSON"in o&&typeof o.toJSON=="function"?e(o.toJSON(),n):(Object.keys(o).forEach(c=>{let d=o[c];const w=r(c);n.recursive&&(te(d)?pe(d)||(d=e(d,n)):n.recursiveInArray&&ye(d)&&(d=[...d].map(h=>{let g=h;return te(h)?pe(g)||(g=e(h,n)):ye(h)&&(g=e({key:h},n).key),g}))),i[w]=d}),i)};return e},Ee=Ne(Xe),Ke=r=>r.replace(/([a-z0-9])([A-Z])/g,(e,t,n)=>`${t}_${n.toLowerCase()}`),Qe=Ne(Ke),_e=[Number,String,Uint8Array],se={recursive:!0,recursiveInArray:!0},et=(r=se)=>(r.recursive==null?r=se:r.recursiveInArray??=!1,r),ye=r=>r!=null&&Array.isArray(r),te=r=>r!=null&&typeof r=="object"&&!Array.isArray(r),pe=r=>_e.some(e=>r instanceof e);class tt{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=Ee(n);return t!=null?t.parse(i):i}encodeString(e){const t=Qe(e);return JSON.stringify(t,(n,i)=>ArrayBuffer.isView(i)?Array.from(i):typeof i=="bigint"?i.toString():i)}}const ie=new tt,E=r=>r!=null&&typeof r=="object"&&"value"in r;class q{value;constructor(e){this.value=e}valueOf(){return this.value}toJSON(){return this.value}toString(){return this.value.toString()}}const rt=r=>r!=null&&typeof r=="object"&&"toString"in r,nt=(r,e=!1)=>{const t=rt(r)?"stringer":typeof r;let n;switch(t){case"string":n=(i,o)=>i.localeCompare(o);break;case"stringer":n=(i,o)=>i.toString().localeCompare(o.toString());break;case"number":n=(i,o)=>Number(i)-Number(o);break;case"bigint":n=(i,o)=>BigInt(i)-BigInt(o)>0n?1:-1;break;case"boolean":n=(i,o)=>Number(i)-Number(o);break;case"undefined":n=()=>0;break;default:return console.warn(`sortFunc: unknown type ${t}`),()=>-1}return e?st(n):n},st=r=>(e,t)=>r(t,e);let ze=(r,e=21)=>(t=e)=>{let n="",i=t|0;for(;i--;)n+=r[Math.random()*r.length|0];return n};const xe="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",it=`0123456789${xe}`,at=11,ot=ze(xe,1),ut=ze(it,at-1),lt=()=>`${ot()}${ut()}`,ct=(r,e)=>t=>t instanceof e||typeof t=="object"&&t!==null&&"discriminator"in t&&t.discriminator===r,ht=2**12-1,ae=2n**63n-1n,ft=2**63-1,_=r=>(e,t)=>{if(typeof e=="bigint"){if(dt(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))},W=_((r,e)=>r-e),$=_((r,e)=>r+e),dt=r=>typeof r=="bigint"?!0:Number.isInteger(r),U=_((r,e)=>r*e),ee=_((r,e)=>r/e),Ue=s.z.tuple([s.z.number(),s.z.number()]),Ae=s.z.object({width:s.z.number(),height:s.z.number()}),gt=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()}),mt=["start","center","end"],G=s.z.object({x:s.z.number(),y:s.z.number()}),yt=s.z.object({clientX:s.z.number(),clientY:s.z.number()}),pt=["x","y"],Me=s.z.enum(pt),Ce=["top","right","bottom","left"];s.z.enum(Ce);const wt=["left","right"],Be=s.z.enum(wt),bt=["top","bottom"],Re=s.z.enum(bt),De=["center"],we=s.z.enum(De),Tt=[...Ce,...De],$e=s.z.enum(Tt);s.z.enum(mt);const Ot=["first","last"];s.z.enum(Ot);s.z.object({lower:s.z.number(),upper:s.z.number()});s.z.enum([...Me.options,...$e.options]);s.z.union([Me,$e,s.z.instanceof(String)]);const L=(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?vt(n):n},vt=r=>r.lower>r.upper?{lower:r.upper,upper:r.lower}:r,be=(r,e)=>{const t=L(r);return e<t.lower?t.lower:e>=t.upper?t.upper-(typeof t.upper=="number"?1:1n):e};s.z.object({x:Be.or(we),y:Re.or(we)});const Le=s.z.object({x:Be,y:Re}),St=Object.freeze({x:"left",y:"top"}),It=(r,e)=>r.x===e.x&&r.y===e.y,Te=s.z.union([s.z.number(),G,Ue,Ae,gt,yt]),Nt=(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}},Oe=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:G,two:G,root:Le});const ce=(r,e,t=0,n=0,i)=>{const o={one:{...Oe},two:{...Oe},root:i??St};if(typeof r=="number"){if(typeof e!="number")throw new Error("Box constructor called with invalid arguments");return o.one={x:r,y:e},o.two={x:o.one.x+t,y:o.one.y+n},o}return"one"in r&&"two"in r&&"root"in r?{...r,root:i??r.root}:("getBoundingClientRect"in r&&(r=r.getBoundingClientRect()),"left"in r?(o.one={x:r.left,y:r.top},o.two={x:r.right,y:r.bottom},o):(o.one=r,e==null?o.two={x:o.one.x+t,y:o.one.y+n}:typeof e=="number"?o.two={x:o.one.x+e,y:o.one.y+t}:"width"in e?o.two={x:o.one.x+e.width,y:o.one.y+e.height}:"signedWidth"in e?o.two={x:o.one.x+e.signedWidth,y:o.one.y+e.signedHeight}:o.two=e,o))},re=r=>{const e=ce(r);return{lower:e.one.x,upper:e.two.x}},ne=r=>{const e=ce(r);return{lower:e.one.y,upper:e.two.y}},Et=r=>typeof r!="object"||r==null?!1:"one"in r&&"two"in r&&"root"in r,zt=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()});s.z.union([Ae,zt,G,Ue]);const xt=(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 Ut=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],Mt=r=>(e,t,n)=>{if(e===null)return[r,n];const{lower:i,upper:o}=e,{lower:c,upper:d}=r,w=o-i,h=d-c;if(t==="dimension")return[r,n*(h/w)];const g=(n-i)*(h/w)+c;return[r,g]},Ct=r=>(e,t,n)=>[r,n],Bt=()=>(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)]},Rt=r=>(e,t,n)=>{const{lower:i,upper:o}=r;return n=xt(n,i,o),[e,n]};class B{ops=[];currBounds=null;currType=null;reversed=!1;constructor(){this.ops=[]}static translate(e){return new B().translate(e)}static magnify(e){return new B().magnify(e)}static scale(e,t){return new B().scale(e,t)}translate(e){const t=this.new(),n=Ut(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=L(e,t),i=this.new(),o=Mt(n);return o.type="scale",i.ops.push(o),i}clamp(e,t){const n=L(e,t),i=this.new(),o=Rt(n);return o.type="clamp",i.ops.push(o),i}reBound(e,t){const n=L(e,t),i=this.new(),o=Ct(n);return o.type="re-bound",i.ops.push(o),i}invert(){const e=Bt();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 B;return e.ops=this.ops.slice(),e.reversed=this.reversed,e}exec(e,t){return this.currBounds=null,this.ops.reduce(([n,i],o)=>o(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 o=e.ops.findIndex((c,d)=>c.type==="scale"&&d>i);o!==-1&&t.push([i,o])}),t.forEach(([n,i])=>{const o=e.ops.slice(n,i);o.unshift(e.ops[i]),e.ops.splice(n,i-n+1,...o)}),e.reversed=!e.reversed,e}get transform(){return{scale:this.dim(1),offset:this.pos(0)}}static IDENTITY=new B}class x{x;y;currRoot;constructor(e=new B,t=new B,n=null){this.x=e,this.y=t,this.currRoot=n}static translate(e,t){return new x().translate(e,t)}static translateX(e){return new x().translateX(e)}static translateY(e){return new x().translateY(e)}static clamp(e){return new x().clamp(e)}static magnify(e){return new x().magnify(e)}static scale(e){return new x().scale(e)}static reBound(e){return new x().reBound(e)}translate(e,t){const n=Nt(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(Et(e)){const n=this.currRoot;return t.currRoot=e.root,n!=null&&!It(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(re(e)),t.y=t.y.scale(ne(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(re(e)),t.y=this.y.reBound(ne(e)),t}clamp(e){const t=this.copy();return t.x=this.x.clamp(re(e)),t.y=this.y.clamp(ne(e)),t}copy(){const e=new x;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 ce(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 x}const Dt=G.extend({root:Le,units:s.object({x:s.enum(["px","decimal"]),y:s.enum(["px","decimal"])})});Dt.partial({root:!0,units:!0});const $t=s.z.enum(["static","dynamic"]),ve=365,X=30,Lt=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)])]),ke=(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 q{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===ft?e=ae: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())+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,o]=e.split(":");let c="00",d="00";o!=null&&([c,d]=o.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,o=0;if(e.includes(".")){const h=e.split(".");i=h[0];const g=h[1]||"0";o=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(o)*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 S(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($(this.valueOf(),new l(e).valueOf()))}sub(e){return new u(W(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 ke(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(ae);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)),Lt.transform(e=>new u(e))]);static sort(e,t){return Number(e.valueOf()-t.valueOf())}}class l extends q{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 I?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 I?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 ke(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),o=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=o.sub(i),T=c.sub(o),N=d.sub(c),z=w.sub(d);let y="";return h.isZero||(y+=`${h.days}d `),g.isZero||(y+=`${g.hours}h `),b.isZero||(y+=`${b.minutes}m `),f.isZero||(y+=`${f.seconds}s `),T.isZero||(y+=`${T.milliseconds}ms `),N.isZero||(y+=`${N.microseconds}ยตs `),z.isZero||(y+=`${z.nanoseconds}ns`),y.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,o=t.hours,c=t.minutes,d=t.seconds,w=Math.floor(i/ve),h=Math.floor(i/X),g=Math.floor(i/7),b=Math.floor(i),f=Math.floor(o),T=Math.floor(c),N=Math.floor(d),z=n?"-":"";if(w>=1){let y=`${w}y`;if(w<2){const O=Math.floor(i%ve/X);O>0&&(y+=` ${O}mo`)}return z+y}if(g>=1&&i<X&&i%7===0){let y=`${g}w`;const O=Math.floor(i%7),D=Math.floor(o-g*7*24);return g<2&&(O>0?y+=` ${O}d`:D>0&&D<24&&(y+=` ${D}h`)),z+y}if(h>=1){let y=`${h}mo`;if(h<3){const O=Math.floor(i%X);O>0&&(y+=` ${O}d`)}return z+y}if(g>=1){let y=`${g}w`;const O=Math.floor(i%7),D=Math.floor(o-g*7*24);return g<2&&(O>0?y+=` ${O}d`:D>0&&D<24&&(y+=` ${D}h`)),z+y}if(b>=1){let y=`${b}d`;const O=Math.floor(o-b*24);return b<2&&O>0&&(y+=` ${O}h`),z+y}if(f>=1){let y=`${f}h`;if(f<3){const O=Math.floor(c-f*60);O>0&&(y+=` ${O}m`)}return z+y}if(T>=1){let y=`${T}m`;if(T<5){const O=Math.floor(d-T*60);O>0&&(y+=` ${O}s`)}return z+y}return`${z}${N}s`}mult(e){return new l(U(this.valueOf(),e))}div(e){return new l(ee(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(ae);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 q{constructor(e){E(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 p(t).valueOf()}span(e){return l.seconds(e/this.valueOf())}byteSpan(e,t){return this.span(e.valueOf()/new p(t).valueOf())}add(e){return new I($(this.valueOf(),new I(e).valueOf()))}sub(e){return new I(W(this.valueOf(),new I(e).valueOf()))}mult(e){return new I(U(this.valueOf(),e))}div(e){return new I(ee(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 p extends q{constructor(e){E(e)&&(e=e.value),super(e.valueOf())}length(e){return e.valueOf()/this.valueOf()}size(e){return new m(e*this.valueOf())}add(e){return new p($(this.valueOf(),new p(e).valueOf()))}sub(e){return new p(W(this.valueOf(),new p(e).valueOf()))}mult(e){return new p(U(this.valueOf(),e))}div(e){return new p(ee(this.valueOf(),e))}static UNKNOWN=new p(0);static BIT128=new p(16);static BIT64=new p(8);static BIT32=new p(4);static BIT16=new p(2);static BIT8=new p(1);static z=s.z.union([s.z.number().transform(e=>new p(e)),s.z.instanceof(p)])}class S{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 S(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),o=u.min(n.end,e.end);return o.before(i)?!1:new l(o.sub(i)).greaterThanOrEqual(t)}contains(e){return e instanceof S?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const t=new S(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 S(u.min(...e.map(t=>t.start)),u.max(...e.map(t=>t.end)))}static MAX=new S(u.MIN,u.MAX);static ZERO=new S(u.ZERO,u.ZERO);static z=s.z.union([s.z.object({start:u.z,end:u.z}).transform(e=>new S(e.start,e.end)),s.z.instanceof(S)]);static sort(e,t){return u.sort(e.start,t.start)||u.sort(e.end,t.end)}static merge(...e){return S.max(...e.map(t=>new S(t).makeValid()))}}class a extends q{constructor(e){if(E(e)&&(e=e.value),e instanceof a||typeof e=="string"||typeof e.valueOf()=="string")super(e.valueOf());else{const t=a.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);if(t==null)throw new Error(`unable to find data type for ${e.toString()}`);super(t.valueOf())}}get Array(){const e=a.ARRAY_CONSTRUCTORS.get(this.toString());if(e==null)throw new Error(`unable to find array constructor for ${this.valueOf()}`);return e}equals(e){return this.valueOf()===e.valueOf()}matches(...e){return e.some(t=>this.equals(t))}toString(e=!1){return e?a.SHORT_STRINGS.get(this.valueOf())??this.valueOf():this.valueOf()}get isVariable(){return this.equals(a.JSON)||this.equals(a.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(a.UUID)}get isInteger(){const e=this.toString();return e.startsWith("int")||e.startsWith("uint")}get isFloat(){return this.toString().startsWith("float")}get density(){const e=a.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}get isUnsignedInteger(){return this.equals(a.UINT8)||this.equals(a.UINT16)||this.equals(a.UINT32)||this.equals(a.UINT64)}get isSignedInteger(){return this.equals(a.INT8)||this.equals(a.INT16)||this.equals(a.INT32)||this.equals(a.INT64)}canSafelyCastTo(e){return this.equals(e)?!0:!this.isNumeric||!e.isNumeric||this.isVariable||e.isVariable||this.isUnsignedInteger&&e.isSignedInteger?!1:this.isFloat?e.isFloat&&this.density.valueOf()<=e.density.valueOf():this.equals(a.INT32)&&e.equals(a.FLOAT64)||this.equals(a.INT8)&&e.equals(a.FLOAT32)?!0:this.isInteger&&e.isInteger?this.density.valueOf()<=e.density.valueOf()&&this.isUnsignedInteger===e.isUnsignedInteger:!1}canCastTo(e){return this.isNumeric&&e.isNumeric?!0:this.equals(e)}checkArray(e){return e.constructor===this.Array}get usesBigInt(){return a.BIG_INT_TYPES.some(e=>e.equals(this))}static UNKNOWN=new a("unknown");static FLOAT64=new a("float64");static FLOAT32=new a("float32");static INT64=new a("int64");static INT32=new a("int32");static INT16=new a("int16");static INT8=new a("int8");static UINT64=new a("uint64");static UINT32=new a("uint32");static UINT16=new a("uint16");static UINT8=new a("uint8");static BOOLEAN=new a("boolean");static TIMESTAMP=new a("timestamp");static UUID=new a("uuid");static STRING=new a("string");static JSON=new a("json");static ARRAY_CONSTRUCTORS=new Map([[a.UINT8.toString(),Uint8Array],[a.UINT16.toString(),Uint16Array],[a.UINT32.toString(),Uint32Array],[a.UINT64.toString(),BigUint64Array],[a.FLOAT32.toString(),Float32Array],[a.FLOAT64.toString(),Float64Array],[a.INT8.toString(),Int8Array],[a.INT16.toString(),Int16Array],[a.INT32.toString(),Int32Array],[a.INT64.toString(),BigInt64Array],[a.TIMESTAMP.toString(),BigInt64Array],[a.STRING.toString(),Uint8Array],[a.JSON.toString(),Uint8Array],[a.UUID.toString(),Uint8Array]]);static ARRAY_CONSTRUCTOR_DATA_TYPES=new Map([[Uint8Array.name,a.UINT8],[Uint16Array.name,a.UINT16],[Uint32Array.name,a.UINT32],[BigUint64Array.name,a.UINT64],[Float32Array.name,a.FLOAT32],[Float64Array.name,a.FLOAT64],[Int8Array.name,a.INT8],[Int16Array.name,a.INT16],[Int32Array.name,a.INT32],[BigInt64Array.name,a.INT64]]);static DENSITIES=new Map([[a.UINT8.toString(),p.BIT8],[a.UINT16.toString(),p.BIT16],[a.UINT32.toString(),p.BIT32],[a.UINT64.toString(),p.BIT64],[a.FLOAT32.toString(),p.BIT32],[a.FLOAT64.toString(),p.BIT64],[a.INT8.toString(),p.BIT8],[a.INT16.toString(),p.BIT16],[a.INT32.toString(),p.BIT32],[a.INT64.toString(),p.BIT64],[a.TIMESTAMP.toString(),p.BIT64],[a.STRING.toString(),p.UNKNOWN],[a.JSON.toString(),p.UNKNOWN],[a.UUID.toString(),p.BIT128]]);static ALL=[a.UNKNOWN,a.FLOAT64,a.FLOAT32,a.INT64,a.INT32,a.INT16,a.INT8,a.UINT64,a.UINT32,a.UINT16,a.UINT8,a.TIMESTAMP,a.UUID,a.STRING,a.JSON];static SHORT_STRINGS=new Map([[a.UINT8.toString(),"u8"],[a.UINT16.toString(),"u16"],[a.UINT32.toString(),"u32"],[a.UINT64.toString(),"u64"],[a.INT8.toString(),"i8"],[a.INT16.toString(),"i16"],[a.INT32.toString(),"i32"],[a.INT64.toString(),"i64"],[a.FLOAT32.toString(),"f32"],[a.FLOAT64.toString(),"f64"],[a.BOOLEAN.toString(),"bool"],[a.TIMESTAMP.toString(),"ts"],[a.UUID.toString(),"uuid"],[a.STRING.toString(),"str"],[a.JSON.toString(),"json"]]);static BIG_INT_TYPES=[a.INT64,a.UINT64,a.TIMESTAMP];static z=s.z.union([s.z.string().transform(e=>new a(e)),s.z.instanceof(a)])}class m extends q{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 m($(this.valueOf(),e.valueOf()))}sub(e){return E(e)&&(e=e.value),new m(W(this.valueOf(),e.valueOf()))}mult(e){return new m(U(this.valueOf(),e))}div(e){return new m(ee(this.valueOf(),e))}truncate(e){return new m(Math.trunc(this.valueOf()/new m(e).valueOf())*new m(e).valueOf())}remainder(e){return m.bytes(this.valueOf()%new m(e).valueOf())}get gigabytes(){return this.valueOf()/m.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/m.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/m.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/m.TERABYTE.valueOf()}toString(){const e=this.truncate(m.TERABYTE),t=this.truncate(m.GIGABYTE),n=this.truncate(m.MEGABYTE),i=this.truncate(m.KILOBYTE),o=this.truncate(m.BYTE),c=e,d=t.sub(e),w=n.sub(t),h=i.sub(n),g=o.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 m(e)}static BYTE=new m(1);static kilobytes(e=1){return m.bytes(new m(e).valueOf()*1e3)}static KILOBYTE=m.kilobytes(1);static megabytes(e=1){return m.kilobytes(new m(e).valueOf()*1e3)}static MEGABYTE=m.megabytes(1);static gigabytes(e=1){return m.megabytes(new m(e).valueOf()*1e3)}static GIGABYTE=m.gigabytes(1);static terabytes(e){return m.gigabytes(new m(e).valueOf()*1e3)}static TERABYTE=m.terabytes(1);static ZERO=new m(0);static z=s.z.union([s.z.number().transform(e=>new m(e)),s.z.instanceof(m)]);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 Pe=r=>{const e=typeof r;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||r instanceof u||r instanceof l||r instanceof Date},kt=(r,e,t,n=0)=>r.usesBigInt&&!e.usesBigInt?Number(t)-Number(n):!r.usesBigInt&&e.usesBigInt?BigInt(t.valueOf())-BigInt(n.valueOf()):W(t,n),Pt=/^(?:[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 jt(r){return typeof r=="string"&&Pt.test(r)}const v=[];for(let r=0;r<256;++r)v.push((r+256).toString(16).slice(1));function Yt(r,e=0){return(v[r[e+0]]+v[r[e+1]]+v[r[e+2]]+v[r[e+3]]+"-"+v[r[e+4]]+v[r[e+5]]+"-"+v[r[e+6]]+v[r[e+7]]+"-"+v[r[e+8]]+v[r[e+9]]+"-"+v[r[e+10]]+v[r[e+11]]+v[r[e+12]]+v[r[e+13]]+v[r[e+14]]+v[r[e+15]]).toLowerCase()}function qt(r,e=0){const t=Yt(r,e);if(!jt(t))throw TypeError("Stringified UUID is invalid");return t}typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const je=(r,e)=>qt(r,e),C=-1,Ft=s.z.string().transform(r=>new Uint8Array(atob(r).split("").map(e=>e.charCodeAt(0))).buffer),Zt=s.z.union([s.z.null(),s.z.undefined()]).transform(()=>new Uint8Array().buffer),oe=10,Gt=(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`)},Ye="sy_x_telem_series";class A{key;discriminator=Ye;dataType;sampleOffset;gl;_data;timeRange=S.ZERO;alignment=0n;alignmentMultiple=1n;cachedMin;cachedMax;writePos=C;_refCount=0;cachedLength;_cachedIndexes;static crudeZ=s.z.object({timeRange:S.z.optional(),dataType:a.z,alignment:s.z.coerce.bigint().optional(),data:s.z.union([Ft,Zt,s.z.instanceof(ArrayBuffer),s.z.instanceof(Uint8Array)]),glBufferUsage:$t.default("static").optional()});static z=A.crudeZ.transform(e=>new A(e));constructor(e){Wt(e)&&(e={data:e}),e.data??=[];const{dataType:t,timeRange:n,sampleOffset:i=0,glBufferUsage:o="static",alignment:c=0n,alignmentMultiple:d=1n,key:w=lt(),data:h}=e;if(Vt(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=Pe(h),b=Array.isArray(h);if(t!=null)this.dataType=new a(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=a.STRING;else if(typeof f=="number")this.dataType=a.FLOAT64;else if(typeof f=="bigint")this.dataType=a.INT64;else if(typeof f=="boolean")this.dataType=a.BOOLEAN;else if(f instanceof u||f instanceof Date||f instanceof u)this.dataType=a.TIMESTAMP;else if(typeof f=="object")this.dataType=a.JSON;else throw new Error(`cannot infer data type of ${typeof f} when constructing a Series from a JS array`)}else this.dataType=new a(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(N=>new u(N).valueOf())),this.dataType.equals(a.STRING)?(this.cachedLength=f.length,this._data=new TextEncoder().encode(`${f.join(`
|
|
2
2
|
`)}
|
|
3
|
-
`).buffer):this.dataType.equals(a.JSON)?(this.cachedLength=
|
|
3
|
+
`).buffer):this.dataType.equals(a.JSON)?(this.cachedLength=f.length,this._data=new TextEncoder().encode(`${f.map(N=>ie.encodeString(N)).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(a.JSON))throw new Error("cannot parse non-JSON series as JSON");return this.toStrings().map(t=>e.parse(ie.decodeString(t)))}get byteCapacity(){return new m(this.underlyingData.byteLength)}get capacity(){return this.dataType.isVariable?this.byteCapacity.valueOf():this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===M?this.byteCapacity:this.dataType.isVariable?new m(this.writePos):this.dataType.density.size(this.writePos)}get length(){return this.cachedLength!=null?this.cachedLength:this.dataType.isVariable?this.calculateCachedLength():this.writePos===M?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===oe&&(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]=kt(this.dataType,e,this.data[i],t);return new U({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(a.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(),D(this.cachedMax,this.sampleOffset))}calcRawMin(){if(this.length===0)return 1/0;if(this.dataType.equals(a.TIMESTAMP))this.cachedMin=this.data[0];else if(this.dataType.usesBigInt){const e=this.data;this.cachedMin=e.reduce((t,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(),D(this.cachedMin,this.sampleOffset))}get bounds(){return L(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(a.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 D(n,this.sampleOffset)}atUUID(e,t){e<0&&(e=this.length+e);const n=Pe(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]===oe){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 o=this.data.slice(n,i);return this.dataType.equals(a.STRING)?new TextDecoder().decode(o):Ne(JSON.parse(new TextDecoder().decode(o)))}binarySearch(e){let t=0,n=this.length-1;const i=nt(e);for(;t<=n;){const o=Math.floor((t+n)/2),c=i(this.at(o,!0),e);if(c===0)return o;c<0?t=o+1:n=o-1}return t}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals(a.FLOAT32)&&!this.dataType.equals(a.UINT8))throw new Error("Only FLOAT32 and UINT8 arrays can be used in WebGL");const{buffer:t,bufferUsage: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!==M){i===0&&e.bufferData(e.ARRAY_BUFFER,this.byteCapacity.valueOf(),e.STATIC_DRAW);const o=this.dataType.density.size(i).valueOf(),c=this.underlyingData.slice(this.gl.prevBuffer,this.writePos);e.bufferSubData(e.ARRAY_BUFFER,o,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=M}as(e){return Zt(e,this.dataType),this}get digest(){return{key:this.key,dataType:this.dataType.toString(),sampleOffset:this.sampleOffset,alignment:{lower:Se(this.alignmentBounds.lower),upper:Se(this.alignmentBounds.upper),multiple:this.alignmentMultiple},timeRange:this.timeRange.toString(),length:this.length,capacity:this.capacity}}get alignmentBounds(){return L(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 Ht(this);return this.dataType.equals(a.JSON)?new he(e):e}return this.dataType.equals(a.UUID)?new Jt(this):new Kt(this)}slice(e,t){return this.sliceSub(!1,e,t)}sub(e,t){return this.sliceSub(!0,e,t)}subIterator(e,t){return new ve(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 ve(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 U({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 U({data:i,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(t)})}reAlign(e){return new U({data:this.buffer,dataType:this.dataType,timeRange:I.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 Gt=r=>r==null?!1:Array.isArray(r)||r instanceof ArrayBuffer||ArrayBuffer.isView(r)&&!(r instanceof DataView)||r instanceof U?!0:ke(r),Vt=ct(je,U);class ve{series;end;index;constructor(e,t,n){this.series=e;const i=L(0,e.length+1);this.end=we(i,n),this.index=we(i,t)}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}}class Ht{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]!==oe;)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))})}}class he{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:ie.decodeString(e.value,he.schema)}}}class Jt{series;index;data;density;constructor(e){if(!e.dataType.equals(a.UUID))throw new Error("cannot create a UUID series iterator for a non-UUID series");this.series=e,this.index=0,this.data=new Uint8Array(e.buffer),this.density=a.UUID.density.valueOf()}next(){if(this.index>=this.series.length)return{done:!0,value:void 0};const e=Pe(this.data,this.index*this.density);return this.index++,{done:!1,value:e}}}class Kt{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 Se=r=>{const e=r>>32n,t=r&0xffffffffn;return{domain:e,sample:t}},Xt=async r=>await new Promise(e=>setTimeout(e,l.fromMilliseconds(r).milliseconds));class Qt{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??Xt},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 _t=s.z.object({baseInterval:l.z.optional(),maxRetries:s.z.number().optional(),scale:s.z.number().optional()}),er=Object.freeze(Object.defineProperty({__proto__:null,Breaker:Qt,breakerConfigZ:_t},Symbol.toStringTag,{value:"Module"})),tr=/^#?([0-9a-f]{6}|[0-9a-f]{8})$/i,Ye=s.z.string().regex(tr),Y=s.z.number().min(0).max(255),qe=s.z.number().min(0).max(1),Fe=s.z.tuple([Y,Y,Y,qe]),rr=s.z.tuple([Y,Y,Y]),nr=s.z.object({rgba255:Fe}),sr=s.z.number().min(0).max(360),ir=s.z.number().min(0).max(100),ar=s.z.number().min(0).max(100),or=s.z.tuple([sr,ir,ar,qe]),de=s.z.union([Ye,rr,Fe,or,nr]),ur=de.transform(r=>fe(r)),fe=(r,e=1)=>{if(r=de.parse(r),typeof r=="string")return lr(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},lr=(r,e=1)=>(r=Ye.parse(r),r=cr(r),[X(r,0),X(r,2),X(r,4),r.length===8?X(r,6)/255:e]),X=(r,e)=>parseInt(r.slice(e,e+2),16),cr=r=>r.startsWith("#")?r.slice(1):r;fe("#000000");fe("#ffffff");const hr=s.z.object({key:s.z.string(),color:de,position:s.z.number(),switched:s.z.boolean().optional()});s.z.array(hr);const dr=s.z.object({key:s.z.string(),name:s.z.string(),color:ur});s.z.object({key:s.z.string(),name:s.z.string(),swatches:s.z.array(dr)});s.z.int().min(0).max(255);s.z.object({name:s.z.string(),key:s.z.string()});const fr=r=>Object.getOwnPropertySymbols(globalThis).includes(r),gr=(r,e)=>{const t=Symbol.for(r);if(!fr(t)){const n=e();Object.defineProperty(globalThis,t,{value:n})}return()=>globalThis[t]},We="sy_x_error",mr=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),V=r=>class F extends Error{static discriminator=We;discriminator=F.discriminator;static TYPE=r;type=F.TYPE;static matches=mr(r);matches=F.matches;constructor(t,n){super(t,n),this.name=F.TYPE}static sub(t){return V(`${r}.${t}`)}},Ze=r=>{if(r==null||typeof r!="object")return!1;const e=r;if(e.discriminator!==We)return!1;if(!("type"in e))throw new Error(`X Error is missing its type property: ${JSON.stringify(e)}`);return!0},j="unknown",ue="nil";class yr{providers=[];register(e){this.providers.push(e)}encode(e){if(e==null)return{type:ue,data:""};if(Ze(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===ue)return null;if(e.type===j)return new le(e.data);for(const t of this.providers){const n=t.decode(e);if(n!=null)return n}return new le(e.data)}}const ge=gr("synnax-error-registry",()=>new yr),pr=({encode:r,decode:e})=>ge().register({encode:r,decode:e}),wr=r=>ge().encode(r),br=r=>r==null?null:ge().decode(r);class le extends V("unknown"){}const Or=s.z.object({type:s.z.string(),data:s.z.string()});class Tr extends V("canceled"){}class vr extends V("not_implemented"){}const B=Object.freeze(Object.defineProperty({__proto__:null,Canceled:Tr,NONE:ue,NotImplemented:vr,UNKNOWN:j,Unknown:le,createTyped:V,decode:br,encode:wr,isTyped:Ze,payloadZ:Or,register:pr},Symbol.toStringTag,{value:"Module"})),Sr=s.object({jsonrpc:s.literal("2.0"),method:s.string(),params:s.any().optional(),id:s.union([s.string(),s.number(),s.null()]).optional()}),Ge=s.object({jsonrpc:s.literal("2.0"),id:s.union([s.string(),s.number(),s.null()])}),Ir=Ge.extend({result:s.json()}),Nr=Ge.extend({error:s.object({code:s.number().int(),message:s.string().optional(),data:s.json().optional()})}),Er=s.union([Ir,Nr]);s.union([Sr,Er]);s.z.object({key:s.z.string(),value:s.z.string()});const zr=s.uuid();s.object({key:zr,name:s.string().min(1),color:s.string()});s.z.string().regex(/^\d+\.\d+\.\d+(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$/);const Ar=["standard","scientific","engineering"];s.z.enum(Ar);s.z.record(s.z.union([s.z.number(),s.z.string(),s.z.symbol()]),s.z.unknown());const xr=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser";xr();const Ur=["macOS","Windows","Linux"],Mr=["macos","windows","linux"],Cr={macos:"macOS",windows:"Windows",linux:"Linux"};s.z.enum(Ur).or(s.z.enum(Mr).transform(r=>Cr[r]));s.z.enum(["success","info","warning","error","loading","disabled"]);s.z.object({stack:s.z.string(),error:s.z.instanceof(Error)});const Br=(...r)=>r.map(Ve).join(""),Ve=r=>(r.endsWith("/")||(r+="/"),r.startsWith("/")&&(r=r.slice(1)),r),Rr=r=>r.endsWith("/")?r.slice(0,-1):r,Dr=(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=Ve(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:Br(this.path,e)})}toString(){return Rr(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}static UNKNOWN=new W({host:"unknown",port:0})}s.z.int().min(0).max(ht);class H extends B.createTyped("freighter"){}class $ extends H.sub("eof"){constructor(){super("EOF")}}class k extends H.sub("stream_closed"){constructor(){super("StreamClosed")}}class P extends H.sub("unreachable"){url;constructor(e={}){const{message:t="Unreachable",url:n=W.UNKNOWN}=e;super(t),this.url=n}}const Lr=r=>{if(!r.type.startsWith(H.TYPE))return null;if($.matches(r))return{type:$.TYPE,data:"EOF"};if(k.matches(r))return{type:k.TYPE,data:"StreamClosed"};if(P.matches(r))return{type:P.TYPE,data:"Unreachable"};throw new Error(`Unknown error type: ${r.type}: ${r.message}`)},$r=r=>{if(!r.type.startsWith(H.TYPE))return null;switch(r.type){case $.TYPE:return new $;case k.TYPE:return new k;case P.TYPE:return new P;default:throw new B.Unknown(`Unknown error type: ${r.data}`)}};B.register({encode:Lr,decode:$r});class He{middleware=[];use(...e){this.middleware.push(...e)}async executeMiddleware(e,t){let n=0;const i=async o=>{if(n===this.middleware.length)return await t(o);const c=this.middleware[n];return n++,await c(o,i)};return await i(e)}}const Je="Content-Type",kr=new Set(["ECONNREFUSED","ECONNRESET","ETIMEDOUT","EPIPE","UND_ERR_CONNECT_TIMEOUT","UND_ERR_SOCKET"]),Pr=r=>{const e=r?.cause?.code??r?.code??r?.errno;if(typeof e=="string"&&kr.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},jr=400;class Yr extends He{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,o,c)=>o==="endpoint"?this.endpoint:Reflect.get(i,o,c)})}get headers(){return{[Je]:this.encoder.contentType}}async send(e,t,n,i){t=n?.parse(t);let o=null;const c=this.endpoint.child(e),f={};f.method="POST",f.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:{}};f.headers={...this.headers,...h.params};let b;try{b=await fetch(h.target,f)}catch(O){if(!(O instanceof Error))throw O;return[g,Pr(O)?new P({url:c}):O]}const d=await b.arrayBuffer();if(b?.ok)return i!=null&&(o=this.encoder.decode(d,i)),[g,null];try{if(b.status!==jr)return[g,new Error(b.statusText)];const O=this.encoder.decode(d,B.payloadZ),N=B.decode(O);return[g,N]}catch(O){return[g,new Error(`[freighter] - failed to decode error: ${b.statusText}: ${O.message}`)]}});if(w!=null)return[null,w];if(o==null)throw new Error("Response must be defined");return[o,null]}}const qr=(r,e)=>{class t{wrapped;constructor(i){this.wrapped=i}use(...i){this.wrapped.use(...i)}async send(i,o,c,f){const w=new er.Breaker(e);do{const[h,g]=await this.wrapped.send(i,o,c,f);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)},Fr=async(r,e,t,n,i)=>{const[o,c]=await r.send(e,t,n,i);if(c!=null)throw c;return o},Wr=s.z.object({type:s.z.enum(["data","close","open"]),payload:s.z.unknown(),error:s.z.optional(B.payloadZ)});class Zr{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 B.decode(e.error)}return null}send(e){if(this.serverClosed!=null)return new $;if(this.sendClosed)throw new k;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,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,Wr))}onClose(e){this.addMessage({type:"close",error:{type:e.code===Vr?$.TYPE:k.TYPE,data:""}})}}const Gr="freighterctx",Vr=1e3;class Q extends He{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[,o]=await this.executeMiddleware({target:e,protocol:"websocket",params:{},role:"client"},async c=>{const f=new WebSocket(this.buildURL(e,c)),w={...c,params:{}};f.binaryType=Q.MESSAGE_TYPE;const h=await this.wrapSocket(f,t,n);return h instanceof Error?[w,h]:(i=h,[w,null])});if(o!=null)throw o;return i}buildURL(e,t){const n=Dr({[Je]:this.encoder.contentType,...t.params},Gr);return this.baseUrl.child(e).toString()+n}async wrapSocket(e,t,n){return await new Promise(i=>{e.onopen=()=>{const o=new Zr(e,this.encoder,t,n);o.receiveOpenAck().then(c=>{c!=null?i(c):i(o)}).catch(c=>i(c))},e.onerror=o=>{const c=o;i(new Error(c.message))}})}}exports.EOF=$;exports.HTTPClient=Yr;exports.StreamClosed=k;exports.Unreachable=P;exports.WebSocketClient=Q;exports.sendRequired=Fr;exports.unaryWithBreaker=qr;
|
|
5
|
+
`).buffer):this.dataType.usesBigInt&&typeof T=="number"?this._data=new this.dataType.Array(f.map(N=>BigInt(Math.round(N)))).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??S.ZERO,this.gl={control:null,buffer:null,prevBuffer:0,bufferUsage:o}}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 a(t).Array(e),o=new A({data:i.buffer,dataType:t,...n});return o.writePos=0,o}get refCount(){return this._refCount}acquire(e){this._refCount++,e!=null&&this.updateGLBuffer(e)}release(){this._refCount--,this.refCount===0&&this.gl.control!=null?this.maybeGarbageCollectGLBuffer(this.gl.control):this.refCount<0&&console.warn("cannot release a series with a negative reference count")}write(e){if(!e.dataType.equals(this.dataType))throw new Error("buffer must be of the same type as this array");return this.dataType.isVariable?this.writeVariable(e):this.writeFixed(e)}writeVariable(e){if(this.writePos===C)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===C)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===C?this.underlyingData:new this.dataType.Array(this._data,0,this.writePos)}toStrings(){return this.dataType.isVariable?new TextDecoder().decode(this.underlyingData).split(`
|
|
6
|
+
`).slice(0,-1):Array.from(this).map(e=>e.toString())}parseJSON(e){if(!this.dataType.equals(a.JSON))throw new Error("cannot parse non-JSON series as JSON");return this.toStrings().map(t=>e.parse(ie.decodeString(t)))}get byteCapacity(){return new m(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 m(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((n,i)=>{n===oe&&(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]=kt(this.dataType,e,this.data[i],t);return new A({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(a.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(),$(this.cachedMax,this.sampleOffset))}calcRawMin(){if(this.length===0)return 1/0;if(this.dataType.equals(a.TIMESTAMP))this.cachedMin=this.data[0];else if(this.dataType.usesBigInt){const e=this.data;this.cachedMin=e.reduce((t,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(),$(this.cachedMin,this.sampleOffset))}get bounds(){return L(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(a.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 $(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]===oe){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 o=this.data.slice(n,i);return this.dataType.equals(a.STRING)?new TextDecoder().decode(o):Ee(JSON.parse(new TextDecoder().decode(o)))}binarySearch(e){let t=0,n=this.length-1;const i=nt(e);for(;t<=n;){const o=Math.floor((t+n)/2),c=i(this.at(o,!0),e);if(c===0)return o;c<0?t=o+1:n=o-1}return t}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals(a.FLOAT32)&&!this.dataType.equals(a.UINT8))throw new Error("Only FLOAT32 and UINT8 arrays can be used in WebGL");const{buffer:t,bufferUsage: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!==C){i===0&&e.bufferData(e.ARRAY_BUFFER,this.byteCapacity.valueOf(),e.STATIC_DRAW);const o=this.dataType.density.size(i).valueOf(),c=this.underlyingData.slice(this.gl.prevBuffer,this.writePos);e.bufferSubData(e.ARRAY_BUFFER,o,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=C}as(e){return Gt(e,this.dataType),this}get digest(){return{key:this.key,dataType:this.dataType.toString(),sampleOffset:this.sampleOffset,alignment:{lower:Ie(this.alignmentBounds.lower),upper:Ie(this.alignmentBounds.upper),multiple:this.alignmentMultiple},timeRange:this.timeRange.toString(),length:this.length,capacity:this.capacity}}get alignmentBounds(){return L(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 Ht(this);return this.dataType.equals(a.JSON)?new he(e):e}return this.dataType.equals(a.UUID)?new Jt(this):new Xt(this)}slice(e,t){return this.sliceSub(!1,e,t)}sub(e,t){return this.sliceSub(!0,e,t)}subIterator(e,t){return new Se(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 Se(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 A({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 A({data:i,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(t)})}reAlign(e){return new A({data:this.buffer,dataType:this.dataType,timeRange:S.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 Wt=r=>r==null?!1:Array.isArray(r)||r instanceof ArrayBuffer||ArrayBuffer.isView(r)&&!(r instanceof DataView)||r instanceof A?!0:Pe(r),Vt=ct(Ye,A);class Se{series;end;index;constructor(e,t,n){this.series=e;const i=L(0,e.length+1);this.end=be(i,n),this.index=be(i,t)}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}}class Ht{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]!==oe;)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))})}}class he{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:ie.decodeString(e.value,he.schema)}}}class Jt{series;index;data;density;constructor(e){if(!e.dataType.equals(a.UUID))throw new Error("cannot create a UUID series iterator for a non-UUID series");this.series=e,this.index=0,this.data=new Uint8Array(e.buffer),this.density=a.UUID.density.valueOf()}next(){if(this.index>=this.series.length)return{done:!0,value:void 0};const e=je(this.data,this.index*this.density);return this.index++,{done:!1,value:e}}}class Xt{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 Ie=r=>{const e=r>>32n,t=r&0xffffffffn;return{domain:e,sample:t}},Kt=async r=>await new Promise(e=>setTimeout(e,l.fromMilliseconds(r).milliseconds));class Qt{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??Kt},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 _t=s.z.object({baseInterval:l.z.optional(),maxRetries:s.z.number().optional(),scale:s.z.number().optional()}),er=Object.freeze(Object.defineProperty({__proto__:null,Breaker:Qt,breakerConfigZ:_t},Symbol.toStringTag,{value:"Module"})),tr=/^#?([0-9a-f]{6}|[0-9a-f]{8})$/i,qe=s.z.string().regex(tr),M=s.z.number().min(0).max(255),fe=s.z.number().min(0).max(1),Fe=s.z.tuple([M,M,M,fe]),rr=s.z.tuple([M,M,M]),nr=s.z.object({rgba255:Fe}),sr=s.z.object({r:M,g:M,b:M,a:fe}),ir=s.z.number().min(0).max(360),ar=s.z.number().min(0).max(100),or=s.z.number().min(0).max(100),ur=s.z.tuple([ir,ar,or,fe]),de=s.z.union([qe,rr,Fe,ur,nr,sr]),Ze=de.transform(r=>ge(r)),ge=(r,e=1)=>{if(r=de.parse(r),typeof r=="string")return lr(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"a"in r&&"r"in r?[r.r,r.g,r.b,r.a]:r.rgba255},lr=(r,e=1)=>(r=qe.parse(r),r=cr(r),[K(r,0),K(r,2),K(r,4),r.length===8?K(r,6)/255:e]),K=(r,e)=>parseInt(r.slice(e,e+2),16),cr=r=>r.startsWith("#")?r.slice(1):r;ge("#000000");ge("#ffffff");const hr=s.z.object({key:s.z.string(),color:de,position:s.z.number(),switched:s.z.boolean().optional()});s.z.array(hr);const fr=s.z.object({key:s.z.string(),name:s.z.string(),color:Ze});s.z.object({key:s.z.string(),name:s.z.string(),swatches:s.z.array(fr)});s.z.int().min(0).max(255);s.z.object({name:s.z.string(),key:s.z.string()});const dr=r=>Object.getOwnPropertySymbols(globalThis).includes(r),gr=(r,e)=>{const t=Symbol.for(r);if(!dr(t)){const n=e();Object.defineProperty(globalThis,t,{value:n})}return()=>globalThis[t]},Ge="sy_x_error",mr=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),V=r=>class F extends Error{static discriminator=Ge;discriminator=F.discriminator;static TYPE=r;type=F.TYPE;static matches=mr(r);matches=F.matches;constructor(t,n){super(t,n),this.name=F.TYPE}static sub(t){return V(`${r}.${t}`)}},We=r=>{if(r==null||typeof r!="object")return!1;const e=r;if(e.discriminator!==Ge)return!1;if(!("type"in e))throw new Error(`X Error is missing its type property: ${JSON.stringify(e)}`);return!0},Y="unknown",ue="nil";class yr{providers=[];register(e){this.providers.push(e)}encode(e){if(e==null)return{type:ue,data:""};if(We(e))for(const t of this.providers){const n=t.encode(e);if(n!=null)return n}if(e instanceof Error)return{type:Y,data:e.message};if(typeof e=="string")return{type:Y,data:e};try{return{type:Y,data:JSON.stringify(e)}}catch{return{type:Y,data:"unable to encode error information"}}}decode(e){if(e==null||e.type===ue)return null;if(e.type===Y)return new le(e.data);for(const t of this.providers){const n=t.decode(e);if(n!=null)return n}return new le(e.data)}}const me=gr("synnax-error-registry",()=>new yr),pr=({encode:r,decode:e})=>me().register({encode:r,decode:e}),wr=r=>me().encode(r),br=r=>r==null?null:me().decode(r);class le extends V("unknown"){}const Tr=s.z.object({type:s.z.string(),data:s.z.string()});class Or extends V("canceled"){}class vr extends V("not_implemented"){}const R=Object.freeze(Object.defineProperty({__proto__:null,Canceled:Or,NONE:ue,NotImplemented:vr,UNKNOWN:Y,Unknown:le,createTyped:V,decode:br,encode:wr,isTyped:We,payloadZ:Tr,register:pr},Symbol.toStringTag,{value:"Module"}));s.z.object({key:s.z.string(),value:s.z.string()});const Sr=s.uuid();s.object({key:Sr,name:s.string().min(1),color:Ze});s.z.string().regex(/^\d+\.\d+\.\d+(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$/);const Ir=["standard","scientific","engineering"];s.z.enum(Ir);const Nr=s.z.union([s.z.string(),s.z.number()]);s.z.record(Nr,s.z.unknown());const Er=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser";Er();const zr=["macOS","Windows","Linux"],xr=["macos","windows","linux"],Ur={macos:"macOS",windows:"Windows",linux:"Linux"};s.z.enum(zr).or(s.z.enum(xr).transform(r=>Ur[r]));s.z.enum(["success","info","warning","error","loading","disabled"]);s.z.object({stack:s.z.string(),error:s.z.instanceof(Error)});const Ar=(...r)=>r.map(Ve).join(""),Ve=r=>(r.endsWith("/")||(r+="/"),r.startsWith("/")&&(r=r.slice(1)),r),Mr=r=>r.endsWith("/")?r.slice(0,-1):r,Cr=(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 Z{protocol;host;port;path;constructor({host:e,port:t,protocol:n="",pathPrefix:i=""}){this.protocol=n,this.host=e,this.port=t,this.path=Ve(i)}replace(e){return new Z({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new Z({...this,pathPrefix:Ar(this.path,e)})}toString(){return Mr(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}static UNKNOWN=new Z({host:"unknown",port:0})}s.z.int().min(0).max(ht);class H extends R.createTyped("freighter"){}class k extends H.sub("eof"){constructor(){super("EOF")}}class P extends H.sub("stream_closed"){constructor(){super("StreamClosed")}}class j extends H.sub("unreachable"){url;constructor(e={}){const{message:t="Unreachable",url:n=Z.UNKNOWN}=e;super(t),this.url=n}}const Br=r=>{if(!r.type.startsWith(H.TYPE))return null;if(k.matches(r))return{type:k.TYPE,data:"EOF"};if(P.matches(r))return{type:P.TYPE,data:"StreamClosed"};if(j.matches(r))return{type:j.TYPE,data:"Unreachable"};throw new Error(`Unknown error type: ${r.type}: ${r.message}`)},Rr=r=>{if(!r.type.startsWith(H.TYPE))return null;switch(r.type){case k.TYPE:return new k;case P.TYPE:return new P;case j.TYPE:return new j;default:throw new R.Unknown(`Unknown error type: ${r.data}`)}};R.register({encode:Br,decode:Rr});class He{middleware=[];use(...e){this.middleware.push(...e)}async executeMiddleware(e,t){let n=0;const i=async o=>{if(n===this.middleware.length)return await t(o);const c=this.middleware[n];return n++,await c(o,i)};return await i(e)}}const Je="Content-Type",Dr=new Set(["ECONNREFUSED","ECONNRESET","ETIMEDOUT","EPIPE","UND_ERR_CONNECT_TIMEOUT","UND_ERR_SOCKET"]),$r=r=>{const e=r?.cause?.code??r?.code??r?.errno;if(typeof e=="string"&&Dr.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},Lr=400;class kr extends He{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,o,c)=>o==="endpoint"?this.endpoint:Reflect.get(i,o,c)})}get headers(){return{[Je]:this.encoder.contentType}}async send(e,t,n,i){t=n?.parse(t);let o=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,$r(T)?new j({url:c}):T]}const f=await b.arrayBuffer();if(b?.ok)return i!=null&&(o=this.encoder.decode(f,i)),[g,null];try{if(b.status!==Lr)return[g,new Error(b.statusText)];const T=this.encoder.decode(f,R.payloadZ),N=R.decode(T);return[g,N]}catch(T){return[g,new Error(`[freighter] - failed to decode error: ${b.statusText}: ${T.message}`)]}});if(w!=null)return[null,w];if(o==null)throw new Error("Response must be defined");return[o,null]}}const Pr=(r,e)=>{class t{wrapped;constructor(i){this.wrapped=i}use(...i){this.wrapped.use(...i)}async send(i,o,c,d){const w=new er.Breaker(e);do{const[h,g]=await this.wrapped.send(i,o,c,d);if(g==null)return[h,null];if(!j.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[o,c]=await r.send(e,t,n,i);if(c!=null)throw c;return o},Yr=s.z.object({type:s.z.enum(["data","close","open"]),payload:s.z.unknown(),error:s.z.optional(R.payloadZ)});class qr{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 R.decode(e.error)}return null}send(e){if(this.serverClosed!=null)return new k;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=R.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,Yr))}onClose(e){this.addMessage({type:"close",error:{type:e.code===Zr?k.TYPE:P.TYPE,data:""}})}}const Fr="freighterctx",Zr=1e3;class Q extends He{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[,o]=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(o!=null)throw o;return i}buildURL(e,t){const n=Cr({[Je]:this.encoder.contentType,...t.params},Fr);return this.baseUrl.child(e).toString()+n}async wrapSocket(e,t,n){return await new Promise(i=>{e.onopen=()=>{const o=new qr(e,this.encoder,t,n);o.receiveOpenAck().then(c=>{c!=null?i(c):i(o)}).catch(c=>i(c))},e.onerror=o=>{const c=o;i(new Error(c.message))}})}}exports.EOF=k;exports.HTTPClient=kr;exports.StreamClosed=P;exports.Unreachable=j;exports.WebSocketClient=Q;exports.sendRequired=jr;exports.unaryWithBreaker=Pr;
|