@synnaxlabs/freighter 0.52.3 â 0.54.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +13 -9
- package/dist/freighter.cjs +6 -6
- package/dist/freighter.js +2622 -3388
- package/dist/src/http.d.ts.map +1 -1
- package/package.json +11 -11
- package/src/http.ts +1 -2
- package/src/websocket.spec.ts +1 -1
- package/tsconfig.json +1 -6
- package/vite.config.ts +10 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
|
|
2
|
-
> @synnaxlabs/freighter@0.
|
|
2
|
+
> @synnaxlabs/freighter@0.54.0 build /home/runner/work/synnax/synnax/freighter/ts
|
|
3
3
|
> tsc --noEmit && vite build
|
|
4
4
|
|
|
5
5
|
[34m Synnax - Production mode[0m
|
|
6
|
-
[36mvite
|
|
7
|
-
|
|
8
|
-
[32mâ[39m 7 modules transformed.
|
|
6
|
+
[36mvite v8.0.3 [32mbuilding client environment for production...[36m[39m
|
|
7
|
+
[2K
|
|
9
8
|
rendering chunks...
|
|
10
9
|
[32m
|
|
11
10
|
[36m[vite:dts][32m Start generate declaration files...[39m
|
|
12
|
-
|
|
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.
|
|
11
|
+
[32m[36m[vite:dts][32m Declaration files built in 1747ms.
|
|
15
12
|
[39m
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
computing gzip size...
|
|
14
|
+
dist/freighter.js 76.93 kB â gzip: 20.39 kB
|
|
15
|
+
|
|
16
|
+
[2K
|
|
17
|
+
rendering chunks...
|
|
18
|
+
computing gzip size...
|
|
19
|
+
dist/freighter.cjs 63.19 kB â gzip: 18.78 kB
|
|
20
|
+
|
|
21
|
+
[32mâ built in 1.95s[39m
|
package/dist/freighter.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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
|
-
`)}
|
|
3
|
-
`).buffer):this.dataType.equals(a.JSON)?(this.cachedLength=f.length,this._data=new TextEncoder().encode(`${f.map(N=>ie.encodeString(N)).join(`
|
|
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===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;
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`zod`);c=s(c);var l=Object.defineProperty,u=(e,t)=>{let n={};for(var r in e)l(n,r,{get:e[r],enumerable:!0});return t||l(n,Symbol.toStringTag,{value:`Module`}),n},d=(e,t)=>{if(Array.isArray(t))return t.reduce((e,t)=>d(e,t),e??[]);if(e==null)return[t];let n=e.findIndex(e=>e==t),r=[...e];return n===-1?r.push(t):r[n]=t,r},f=(e,t)=>{if(Array.isArray(t))return t.reduce((e,t)=>f(e,t),e??[]);if(e==null)return[t];let n=e.findIndex(e=>e.key===t.key),r=[...e];return n===-1?r.push(t):r[n]=t,r},p=`synnax.caseconv.preserveCase`,m=e=>{if(typeof e!=`object`||!e)return!1;if(p in e)return!0;let t=e._zod?.def;return t==null?!1:t.innerType&&m(t.innerType)?!0:t.type===`union`&&Array.isArray(t.options)?t.options.some(m):t.type===`pipe`?m(t.in)||m(t.out):!1},h=e=>{if(e==null)return;let t=e._zod?.def;if(t?.type===`array`&&t.element!=null)return t.element;if(t?.type===`union`&&Array.isArray(t.options))for(let e of t.options){let t=h(e);if(t!=null)return t}},g=e=>{if(e==null)return null;let t=e;if(t.shape!=null)return t.shape;if(typeof t.sourceType==`function`){let e=t.sourceType();if(e?.shape!=null)return e.shape}let n=t._zod?.def;if(n==null)return null;if(n.innerType!=null)return g(n.innerType);if(n.type===`union`&&Array.isArray(n.options))for(let e of n.options){let t=g(e);if(t!=null)return t}return n.type===`pipe`?g(n.in)??g(n.out):null},ee=e=>{if(e.length===0)return e;let t=e.indexOf(`_`)===-1?e:e.replace(/_[a-z]/g,e=>e[1].toUpperCase()),n=t.charCodeAt(0);return n<65||n>90||t.length>1&&t.charCodeAt(1)>=65&&t.charCodeAt(1)<=90?t:String.fromCharCode(n+32)+t.slice(1)},te=e=>{let t=(n,r=ie)=>{if(typeof n==`string`)return e(n);if(Array.isArray(n)){let e=h(r.schema),i={recursive:r.recursive,recursiveInArray:r.recursiveInArray,schema:e};return n.map(e=>t(e,i))}if(!_(n)||r.schema!=null&&m(r.schema))return n;let i=r.recursive??!0,a=r.recursiveInArray??i,o=r.schema,s={},c=n;if(`toJSON`in c&&typeof c.toJSON==`function`)return t(c.toJSON(),r);let l=g(o),u={recursive:i,recursiveInArray:a,schema:void 0},d=Object.keys(c);for(let n=0;n<d.length;n++){let r=d[n],o=c[r],f=e(r),p=l==null?void 0:l[r]??l[f]??void 0;i&&(_(o)?ae(o)||(u.schema=p,o=t(o,u)):a&&Array.isArray(o)&&(u.schema=h(p),o=o.map(e=>{if(_(e)){if(!ae(e))return t(e,u)}else if(Array.isArray(e))return t({key:e},u).key;return e}))),s[f]=o}return s};return t},ne=te(ee),re=te(e=>e.replace(/([a-z0-9])([A-Z])/g,(e,t,n)=>`${t}_${n.toLowerCase()}`)),ie={recursive:!0,recursiveInArray:!0,schema:void 0},_=e=>typeof e==`object`&&!!e&&!Array.isArray(e),ae=e=>e instanceof Uint8Array||e instanceof Number||e instanceof String,v=e=>typeof e==`object`&&!!e&&!Array.isArray(e),oe=class{contentType=`application/json`;decoder;encoder;constructor(){this.decoder=new TextDecoder,this.encoder=new TextEncoder}encode(e,t){return this.encoder.encode(this.encodeString(e,t))}decode(e,t){return this.decodeString(this.decoder.decode(e),t)}decodeString(e,t){let n=ne(JSON.parse(e),{schema:t});return t==null?n:t.parse(n)}encodeString(e,t){let n=re((t==null?e:t.parse(e))??{},{schema:t});return JSON.stringify(n,(e,t)=>ArrayBuffer.isView(t)?Array.from(t):typeof t==`bigint`?t.toString():t)}},se=class{contentType=`text/csv`;encode(e){let t=this.encodeString(e);return new TextEncoder().encode(t)}decode(e,t){let n=new TextDecoder().decode(e);return this.decodeString(n,t)}encodeString(e){if(!Array.isArray(e)||e.length===0||!v(e[0]))throw Error(`Payload must be an array of objects`);let t=Object.keys(e[0]),n=[t.join(`,`)];return e.forEach(e=>{let r=t.map(t=>JSON.stringify(e[t]??``));n.push(r.join(`,`))}),n.join(`
|
|
2
|
+
`)}decodeString(e,t){let[n,...r]=e.trim().split(`
|
|
3
|
+
`).map(e=>e.trim());if(n.length===0)return t==null?{}:t.parse({});let i=n.split(`,`).map(e=>e.trim()),a={};return i.forEach(e=>{a[e]=[]}),r.forEach(e=>{let t=e.split(`,`).map(e=>e.trim());i.forEach((e,n)=>{let r=this.parseValue(t[n]);r!=null&&a[e].push(r)})}),t==null?a:t.parse(a)}parseValue(e){if(e==null||e.length===0)return null;let t=Number(e);return isNaN(t)?e.startsWith(`"`)&&e.endsWith(`"`)?e.slice(1,-1):e:t}},ce=class{contentType=`text/plain`;encode(e){if(typeof e!=`string`)throw Error(`TextCodec.encode payload must be a string`);return new TextEncoder().encode(e)}decode(e,t){let n=new TextDecoder().decode(e);return t==null?n:t.parse(n)}},le=new oe;new se,new ce;var y=e=>typeof e==`object`&&!!e&&`value`in e,b=class{value;constructor(e){this.value=e}valueOf(){return this.value}toJSON(){return this.value}toString(){return this.value.toString()}},ue=e=>typeof e==`object`&&!!e&&`toString`in e,de=(e,t=!1)=>{let n=ue(e)?`stringer`:typeof e,r;switch(n){case`string`:r=(e,t)=>e.localeCompare(t);break;case`stringer`:r=(e,t)=>e.toString().localeCompare(t.toString());break;case`number`:r=(e,t)=>Number(e)-Number(t);break;case`bigint`:r=(e,t)=>BigInt(e)-BigInt(t)>0n?1:-1;break;case`boolean`:r=(e,t)=>Number(e)-Number(t);break;case`undefined`:r=()=>0;break;default:return console.warn(`sortFunc: unknown type ${n}`),()=>-1}return t?fe(r):r},fe=e=>(t,n)=>e(n,t),pe=(e,t=21)=>(n=t)=>{let r=``,i=n|0;for(;i--;)r+=e[Math.random()*e.length|0];return r},me=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz`,he=`0123456789${me}`,ge=pe(me,1),_e=pe(he,10),ve=()=>`${ge()}${_e()}`,ye=(e,t)=>n=>n instanceof t||typeof n==`object`&&!!n&&`discriminator`in n&&n.discriminator===e,be=2**12-1,xe=2**16-1,Se=2**20-1,Ce=-128,we=-(2**15),Te=2**15-1,Ee=-(2n**63n),x=2n**63n-1n,De=-(2**63),Oe=2**63-1,S=e=>(t,n)=>{if(typeof t==`bigint`){if(ke(n))return e(t,BigInt(n));let r=e(Number(t),Number(n));return typeof r==`number`?BigInt(Math.round(r)):r}return e(Number(t),Number(n))},C=S((e,t)=>e-t),w=S((e,t)=>e+t),ke=e=>typeof e==`bigint`?!0:Number.isInteger(e),T=S((e,t)=>e*t),E=S((e,t)=>e/t),Ae=c.z.tuple([c.z.number(),c.z.number()]),je=c.z.enum([`x`,`y`]),D=[`top`,`right`,`bottom`,`left`];c.z.enum(D);var Me=[`left`,`right`],Ne=c.z.enum(Me),Pe=c.z.enum([`top`,`bottom`]),O=[`center`],Fe=c.z.enum(O);c.z.enum([`top`,`right`,`bottom`,`left`,`center`]),c.z.enum([`start`,`center`,`end`]),c.z.enum([`first`,`last`]);var Ie=c.z.object({clientX:c.z.number(),clientY:c.z.number()}),Le=c.z.object({width:c.z.number(),height:c.z.number()}),Re=c.z.object({signedWidth:c.z.number(),signedHeight:c.z.number()});c.z.object({lower:c.z.number(),upper:c.z.number()}),c.z.enum([`x`,`y`,...D,...O]),c.z.union([je,c.z.enum([...D,...O]),c.z.instanceof(String)]);var k=(e,t,n)=>{let r={};if(typeof t==`object`&&(n=t,t=void 0),n={makeValid:!0,...n},typeof e==`number`||typeof e==`bigint`)t==null?(r.lower=typeof e==`bigint`?0n:0,r.upper=e):(r.lower=e,r.upper=t);else if(Array.isArray(e)){if(e.length!==2)throw Error(`bounds: expected array of length 2`);[r.lower,r.upper]=e}else r.lower=e.lower,r.upper=e.upper;return n?.makeValid?ze(r):r};Object.freeze({lower:0,upper:0}),Object.freeze({lower:-1/0,upper:1/0}),Object.freeze({lower:0,upper:1}),Object.freeze({lower:-1,upper:1});var ze=e=>e.lower>e.upper?{lower:e.upper,upper:e.lower}:e,Be=(e,t)=>{let n=k(e);return t<n.lower?n.lower:t>=n.upper?n.upper-(typeof n.upper==`number`?1:1n):t};c.z.object({x:Ne.or(Fe),y:Pe.or(Fe)});var Ve=c.z.object({x:Ne,y:Pe}),He=Object.freeze({x:`left`,y:`top`}),Ue=Object.freeze({x:`right`,y:`top`}),We=Object.freeze({x:`left`,y:`bottom`}),Ge=Object.freeze({x:`right`,y:`bottom`}),Ke=Object.freeze({x:`center`,y:`center`}),qe=Object.freeze({x:`center`,y:`top`}),Je=Object.freeze({x:`center`,y:`bottom`}),Ye=Object.freeze({x:`right`,y:`center`}),Xe=Object.freeze({x:`left`,y:`center`});Object.freeze([Xe,Ye,qe,Je,He,Ue,We,Ge,Ke]);var Ze=(e,t)=>e.x===t.x&&e.y===t.y,Qe=e=>[e.x,e.y];c.z.enum([`top`,`right`,`bottom`,`left`]);var A=c.z.object({x:c.z.number(),y:c.z.number()}),$e=c.z.union([c.z.number(),A,Ae,Le,Re,Ie]),j=(e,t)=>{if(typeof e==`string`){if(t===void 0)throw Error(`The y coordinate must be given.`);return e===`x`?{x:t,y:0}:{x:0,y:t}}return typeof e==`number`?{x:e,y:t??e}:Array.isArray(e)?{x:e[0],y:e[1]}:`signedWidth`in e?{x:e.signedWidth,y:e.signedHeight}:`clientX`in e?{x:e.clientX,y:e.clientY}:`width`in e?{x:e.width,y:e.height}:{x:e.x,y:e.y}},M=Object.freeze({x:0,y:0});Object.freeze({x:1,y:1}),Object.freeze({x:1/0,y:1/0}),Object.freeze({x:NaN,y:NaN});var et=(e,t)=>{let n=j(e);return{x:n.x+t,y:n.y}},tt=(e,t)=>{let n=j(e);return{x:n.x,y:n.y+t}},nt=(e,t,n,...r)=>{if(typeof t==`string`){if(typeof n!=`number`)throw Error(`The value must be a number.`);return t===`x`?et(e,n):tt(e,n)}if(typeof t==`object`&&`x`in t&&typeof t.x==`string`){let r=j(n),i=j(e);return t.x===`left`?r.x=-r.x:t.x===`center`&&(r.x=0),t.y===`top`?r.y=-r.y:t.y===`center`&&(r.y=0),{x:i.x+r.x,y:i.y+r.y}}return[e,t,n??M,...r].reduce((e,t)=>{let n=j(t);return{x:e.x+n.x,y:e.y+n.y}},M)},N=c.z.union([c.z.number(),c.z.string()]);c.z.object({top:N,left:N,width:N,height:N}),c.z.object({left:c.z.number(),top:c.z.number(),right:c.z.number(),bottom:c.z.number()}),c.z.object({one:A,two:A,root:Ve});var P=(e,t,n=0,r=0,i)=>{let a={one:{...M},two:{...M},root:i??He};if(typeof e==`number`){if(typeof t!=`number`)throw Error(`Box constructor called with invalid arguments`);return a.one={x:e,y:t},a.two={x:a.one.x+n,y:a.one.y+r},a}return`one`in e&&`two`in e&&`root`in e?{...e,root:i??e.root}:(`getBoundingClientRect`in e&&(e=e.getBoundingClientRect()),`left`in e?(a.one={x:e.left,y:e.top},a.two={x:e.right,y:e.bottom},a):(a.one=e,t==null?a.two={x:a.one.x+n,y:a.one.y+r}:typeof t==`number`?a.two={x:a.one.x+t,y:a.one.y+n}:`width`in t?a.two={x:a.one.x+t.width,y:a.one.y+t.height}:`signedWidth`in t?a.two={x:a.one.x+t.signedWidth,y:a.one.y+t.signedHeight}:a.two=t,a))},rt=(e,t)=>{let n=P(e);return{x:t.x===`center`?ct(n).x:it(n,t.x),y:t.y===`center`?ct(n).y:it(n,t.y)}},it=(e,t)=>{let n=P(e),r=Qe(n.root).includes(t)?Math.min:Math.max;return Me.includes(t)?r(n.one.x,n.two.x):r(n.one.y,n.two.y)},at=e=>{let t=P(e);return t.two.x-t.one.x},ot=e=>{let t=P(e);return t.two.y-t.one.y},st=e=>rt(e,He),ct=e=>nt(st(e),{x:at(e)/2,y:ot(e)/2}),lt=e=>{let t=P(e);return{lower:t.one.x,upper:t.two.x}},ut=e=>{let t=P(e);return{lower:t.one.y,upper:t.two.y}},dt=e=>typeof e!=`object`||!e?!1:`one`in e&&`two`in e&&`root`in e;c.z.union([Le,Re,A,Ae]);var ft=(e,t,n)=>t!==void 0&&e<t?t:n!==void 0&&e>n?n:e;c.z.object({offset:$e,scale:$e}),c.z.object({offset:c.z.number(),scale:c.z.number()});var pt=e=>(t,n,r,i)=>n===`dimension`?[t,r]:[t,i?r-e:r+e],mt=e=>(t,n,r,i)=>[t,i?r/e:r*e],ht=e=>(t,n,r)=>{if(t===null)return[e,r];let{lower:i,upper:a}=t,{lower:o,upper:s}=e,c=a-i,l=s-o;return n===`dimension`?[e,l/c*r]:[e,(r-i)*(l/c)+o]},gt=e=>(t,n,r)=>[e,r],_t=()=>(e,t,n)=>{if(e===null)throw Error(`cannot invert without bounds`);if(t===`dimension`)return[e,n];let{lower:r,upper:i}=e;return[e,i-(n-r)]},vt=e=>(t,n,r)=>{let{lower:i,upper:a}=e;return r=ft(r,i,a),[t,r]},yt=class e{ops=[];currBounds=null;currType=null;reversed=!1;constructor(){this.ops=[]}static translate(t){return new e().translate(t)}static magnify(t){return new e().magnify(t)}static scale(t,n){return new e().scale(t,n)}translate(e){let t=this.new(),n=pt(e);return n.type=`translate`,t.ops.push(n),t}magnify(e){let t=this.new(),n=mt(e);return n.type=`magnify`,t.ops.push(n),t}scale(e,t){let n=k(e,t),r=this.new(),i=ht(n);return i.type=`scale`,r.ops.push(i),r}clamp(e,t){let n=k(e,t),r=this.new(),i=vt(n);return i.type=`clamp`,r.ops.push(i),r}reBound(e,t){let n=k(e,t),r=this.new(),i=gt(n);return i.type=`re-bound`,r.ops.push(i),r}invert(){let e=_t();e.type=`invert`;let t=this.new();return t.ops.push(e),t}pos(e){return this.exec(`position`,e)}dim(e){return this.exec(`dimension`,e)}new(){let t=new e;return t.ops=this.ops.slice(),t.reversed=this.reversed,t}exec(e,t){return this.currBounds=null,this.ops.reduce(([t,n],r)=>r(t,e,n,this.reversed),[null,t])[1]}reverse(){let e=this.new();e.ops.reverse();let t=[];return e.ops.forEach((n,r)=>{if(n.type===`scale`||t.some(([e,t])=>r>=e&&r<=t))return;let i=e.ops.findIndex((e,t)=>e.type===`scale`&&t>r);i!==-1&&t.push([r,i])}),t.forEach(([t,n])=>{let r=e.ops.slice(t,n);r.unshift(e.ops[n]),e.ops.splice(t,n-t+1,...r)}),e.reversed=!e.reversed,e}get transform(){return{scale:this.dim(1),offset:this.pos(0)}}static IDENTITY=new e};(class e{x;y;currRoot;constructor(e=new yt,t=new yt,n=null){this.x=e,this.y=t,this.currRoot=n}static translate(t,n){return new e().translate(t,n)}static translateX(t){return new e().translateX(t)}static translateY(t){return new e().translateY(t)}static clamp(t){return new e().clamp(t)}static magnify(t){return new e().magnify(t)}static scale(t){return new e().scale(t)}static reBound(t){return new e().reBound(t)}translate(e,t){let n=j(e,t),r=this.copy();return r.x=this.x.translate(n.x),r.y=this.y.translate(n.y),r}translateX(e){let t=this.copy();return t.x=this.x.translate(e),t}translateY(e){let t=this.copy();return t.y=this.y.translate(e),t}magnify(e){let t=this.copy();return t.x=this.x.magnify(e.x),t.y=this.y.magnify(e.y),t}scale(e){let t=this.copy();if(dt(e)){let n=this.currRoot;return t.currRoot=e.root,n!=null&&!Ze(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(lt(e)),t.y=t.y.scale(ut(e)),t}return t.x=t.x.scale(e.width),t.y=t.y.scale(e.height),t}reBound(e){let t=this.copy();return t.x=this.x.reBound(lt(e)),t.y=this.y.reBound(ut(e)),t}clamp(e){let t=this.copy();return t.x=this.x.clamp(lt(e)),t.y=this.y.clamp(ut(e)),t}copy(){let t=new e;return t.currRoot=this.currRoot,t.x=this.x,t.y=this.y,t}reverse(){let 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 P(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 e}),A.extend({root:Ve,units:c.default.object({x:c.default.enum([`px`,`decimal`]),y:c.default.enum([`px`,`decimal`])})}).partial({root:!0,units:!0});var bt=c.z.enum([`static`,`dynamic`]),xt=365,F=30,St=c.z.union([c.z.tuple([c.z.int()]),c.z.tuple([c.z.int(),c.z.int().min(1).max(12)]),c.z.tuple([c.z.int(),c.z.int().min(1).max(12),c.z.int().min(1).max(31)])]),Ct=(e,t)=>{let n=new I(t);if(![L.DAY,L.HOUR,L.MINUTE,L.SECOND,L.MILLISECOND,L.MICROSECOND,L.NANOSECOND].some(e=>e.equals(n)))throw Error(`Invalid argument for remainder. Must be an even TimeSpan or Timestamp`);let r=e.valueOf()%n.valueOf();return e instanceof I?new I(r):new L(r)},I=class e extends b{constructor(t,n=`UTC`){if(t==null)super(e.now().valueOf());else if(t instanceof Date)super(BigInt(t.getTime())*e.MILLISECOND.valueOf());else if(typeof t==`string`)super(e.parseDateTimeString(t,n).valueOf());else if(Array.isArray(t))super(e.parseDate(t));else{let r=0n;t instanceof Number&&(t=t.valueOf()),n===`local`&&(r=e.utcOffset.valueOf()),typeof t==`number`&&(isFinite(t)?t=t===Oe?x:Math.trunc(t):(isNaN(t)&&(t=0),t=t===1/0?e.MAX:e.MIN)),y(t)&&(t=t.value),super(BigInt(t.valueOf())+r)}}static parseDate([t=1970,n=1,r=1]){let i=new Date(t,n-1,r,0,0,0,0);return new e(BigInt(i.getTime())*e.MILLISECOND.valueOf()).truncate(e.DAY).valueOf()}valueOf(){return this.value}static parseTimeString(t,n=`UTC`){let[r,i,a]=t.split(`:`),o=`00`,s=`00`;a!=null&&([o,s]=a.split(`.`));let c=e.hours(parseInt(r??`00`,10)).add(e.minutes(parseInt(i??`00`,10))).add(e.seconds(parseInt(o??`00`,10))).add(e.milliseconds(parseInt(s??`00`,10)));return n===`local`&&(c=c.add(e.utcOffset)),c.valueOf()}static parseDateTimeString(t,n=`UTC`){if(!t.includes(`/`)&&!t.includes(`-`))return e.parseTimeString(t,n);if(t.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,3})?$/)!=null){let r=t,i=0;if(t.includes(`.`)){let e=t.split(`.`);r=e[0];let n=e[1]||`0`;i=parseInt(n.padEnd(3,`0`).slice(0,3),10)}let a=n===`local`?new Date(r.replace(`T`,` `)):new Date(`${r}Z`);return BigInt(a.getTime())*e.MILLISECOND.valueOf()+BigInt(i)*e.MILLISECOND.valueOf()}let r=new Date(t);return t.includes(`:`)||r.setUTCHours(0,0,0,0),new e(BigInt(r.getTime())*e.MILLISECOND.valueOf(),n).valueOf()}toISOString(t=`UTC`){if(t===`UTC`)return this.date().toISOString();let n=this.date(),r=new L(BigInt(n.getTimezoneOffset())*e.MINUTE.valueOf());return this.sub(r).date().toISOString()}timeString(e=!1,t=`UTC`){let n=this.toISOString(t);return e?n.slice(11,23):n.slice(11,19)}dateString(){let e=this.date();return`${e.toLocaleString(`default`,{month:`short`})} ${e.toLocaleString(`default`,{day:`numeric`})}`}static get utcOffset(){return new L(BigInt(new Date().getTimezoneOffset())*e.MINUTE.valueOf())}static since(t){return new e().span(t)}date(){return new Date(this.milliseconds)}equals(t){return this.valueOf()===new e(t).valueOf()}span(e){return this.range(e).span}range(e){return new B(this,e).makeValid()}spanRange(e){return this.range(this.add(e)).makeValid()}get isZero(){return this.valueOf()===0n}after(t){return this.valueOf()>new e(t).valueOf()}afterEq(t){return this.valueOf()>=new e(t).valueOf()}before(t){return this.valueOf()<new e(t).valueOf()}beforeEq(t){return this.valueOf()<=new e(t).valueOf()}add(t){return new e(w(this.valueOf(),new L(t).valueOf()))}sub(t){return new e(C(this.valueOf(),new L(t).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(e.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(e.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get year(){return this.date().getUTCFullYear()}get localYear(){return this.date().getFullYear()}setYear(t){let n=this.date();return n.setUTCFullYear(t),new e(n)}setLocalYear(t){let n=this.date();return n.setFullYear(t),new e(n)}get month(){return this.date().getUTCMonth()}get localMonth(){return this.date().getMonth()}setMonth(t){let n=this.date();return n.setUTCMonth(t),new e(n)}setLocalMonth(t){let n=this.date();return n.setMonth(t),new e(n)}get day(){return this.date().getUTCDate()}get localDay(){return this.date().getDate()}setDay(t){let n=this.date();return n.setUTCDate(t),new e(n)}setLocalDay(t){let n=this.date();return n.setDate(t),new e(n)}get hour(){return this.date().getUTCHours()}get localHour(){return this.date().getHours()}setLocalHour(t){let n=this.date();return n.setHours(t),new e(n)}setHour(t){let n=this.date();return n.setUTCHours(t),new e(n)}get minute(){return this.date().getUTCMinutes()}get localMinute(){return this.date().getMinutes()}setMinute(t){let n=this.date();return n.setUTCMinutes(t),new e(n)}setLocalMinute(t){let n=this.date();return n.setMinutes(t),new e(n)}get second(){return this.date().getUTCSeconds()}get localSecond(){return this.date().getSeconds()}setSecond(t){let n=this.date();return n.setUTCSeconds(t),new e(n)}setLocalSecond(t){let n=this.date();return n.setSeconds(t),new e(n)}get millisecond(){return this.date().getUTCMilliseconds()}get localMillisecond(){return this.date().getMilliseconds()}setMillisecond(t){let n=this.date();return n.setUTCMilliseconds(t),new e(n)}setLocalMillisecond(t){let n=this.date();return n.setMilliseconds(t),new e(n)}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 Ct(this,e)}get isToday(){return this.truncate(L.DAY).equals(e.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 e(new Date)}static max(...t){let n=e.MIN;for(let r of t){let t=new e(r);t.after(n)&&(n=t)}return n}static min(...t){let n=e.MAX;for(let r of t){let t=new e(r);t.before(n)&&(n=t)}return n}static nanoseconds(t,n=`UTC`){return new e(t,n)}static NANOSECOND=e.nanoseconds(1);static microseconds(t,n=`UTC`){return e.nanoseconds(t*1e3,n)}static MICROSECOND=e.microseconds(1);static milliseconds(t,n=`UTC`){return e.microseconds(t*1e3,n)}static MILLISECOND=e.milliseconds(1);static seconds(t,n=`UTC`){return e.milliseconds(t*1e3,n)}static SECOND=e.seconds(1);static minutes(t,n=`UTC`){return e.seconds(t*60,n)}static MINUTE=e.minutes(1);static hours(t,n=`UTC`){return e.minutes(t*60,n)}static HOUR=e.hours(1);static days(t,n=`UTC`){return e.hours(t*24,n)}static DAY=e.days(1);static MAX=new e(x);static MIN=new e(0);static ZERO=new e(0);static z=c.z.union([c.z.instanceof(e),c.z.object({value:c.z.bigint()}).transform(t=>new e(t.value)),c.z.string().transform(t=>new e(BigInt(t))),c.z.number().transform(t=>new e(t)),c.z.bigint().transform(t=>new e(t)),c.z.date().transform(t=>new e(t)),c.z.custom(e=>e instanceof L).transform(t=>new e(t)),St.transform(t=>new e(t))]);static sort(e,t){return Number(e.valueOf()-t.valueOf())}},L=class e extends b{constructor(e){typeof e==`number`&&(e=Math.trunc(e.valueOf())),y(e)&&(e=e.value),super(BigInt(e.valueOf()))}static fromSeconds(t){return t instanceof e?t:t instanceof R?t.period:t instanceof I?new e(t):(y(t)&&(t=t.value),[`number`,`bigint`].includes(typeof t)?e.seconds(t):new e(t))}static fromMilliseconds(t){return t instanceof e?t:t instanceof R?t.period:t instanceof I?new e(t):(y(t)&&(t=t.value),[`number`,`bigint`].includes(typeof t)?e.milliseconds(t):new e(t))}valueOf(){return this.value}lessThan(t){return this.valueOf()<new e(t).valueOf()}greaterThan(t){return this.valueOf()>new e(t).valueOf()}lessThanOrEqual(t){return this.valueOf()<=new e(t).valueOf()}greaterThanOrEqual(t){return this.valueOf()>=new e(t).valueOf()}remainder(e){return Ct(this,e)}truncate(t){return new e(BigInt(Math.trunc(Number(this.valueOf()/t.valueOf())))*t.valueOf())}toString(t=`full`){if(t===`semantic`)return this.toSemanticString();let n=this.truncate(e.DAY),r=this.truncate(e.HOUR),i=this.truncate(e.MINUTE),a=this.truncate(e.SECOND),o=this.truncate(e.MILLISECOND),s=this.truncate(e.MICROSECOND),c=this.truncate(e.NANOSECOND),l=n,u=r.sub(n),d=i.sub(r),f=a.sub(i),p=o.sub(a),m=s.sub(o),h=c.sub(s),g=``;return l.isZero||(g+=`${l.days}d `),u.isZero||(g+=`${u.hours}h `),d.isZero||(g+=`${d.minutes}m `),f.isZero||(g+=`${f.seconds}s `),p.isZero||(g+=`${p.milliseconds}ms `),m.isZero||(g+=`${m.microseconds}µs `),h.isZero||(g+=`${h.nanoseconds}ns`),g.trim()}toSemanticString(){let t=new e(this.valueOf()<0n?-this.valueOf():this.valueOf()),n=this.valueOf()<0n;if(t.valueOf()===0n)return`0s`;if(t.lessThan(e.SECOND))return`< 1s`;let r=t.days,i=t.hours,a=t.minutes,o=t.seconds,s=Math.floor(r/xt),c=Math.floor(r/F),l=Math.floor(r/7),u=Math.floor(r),d=Math.floor(i),f=Math.floor(a),p=Math.floor(o),m=n?`-`:``;if(s>=1){let e=`${s}y`;if(s<2){let t=Math.floor(r%xt/F);t>0&&(e+=` ${t}mo`)}return m+e}if(l>=1&&r<F&&r%7==0){let e=`${l}w`,t=Math.floor(r%7),n=Math.floor(i-l*7*24);return l<2&&(t>0?e+=` ${t}d`:n>0&&n<24&&(e+=` ${n}h`)),m+e}if(c>=1){let e=`${c}mo`;if(c<3){let t=Math.floor(r%F);t>0&&(e+=` ${t}d`)}return m+e}if(l>=1){let e=`${l}w`,t=Math.floor(r%7),n=Math.floor(i-l*7*24);return l<2&&(t>0?e+=` ${t}d`:n>0&&n<24&&(e+=` ${n}h`)),m+e}if(u>=1){let e=`${u}d`,t=Math.floor(i-u*24);return u<2&&t>0&&(e+=` ${t}h`),m+e}if(d>=1){let e=`${d}h`;if(d<3){let t=Math.floor(a-d*60);t>0&&(e+=` ${t}m`)}return m+e}if(f>=1){let e=`${f}m`;if(f<5){let t=Math.floor(o-f*60);t>0&&(e+=` ${t}s`)}return m+e}return`${m}${p}s`}mult(t){return new e(T(this.valueOf(),t))}div(t){return new e(E(this.valueOf(),t))}get days(){return Number(this.valueOf())/Number(e.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(e.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(e.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(e.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(e.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(e.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get isZero(){return this.valueOf()===0n}equals(t){return this.valueOf()===new e(t).valueOf()}add(t){return new e(this.valueOf()+new e(t).valueOf())}sub(t){return new e(this.valueOf()-new e(t).valueOf())}static nanoseconds(t=1){return new e(t)}static NANOSECOND=e.nanoseconds(1);static microseconds(t=1){return e.nanoseconds(T(t,1e3))}static MICROSECOND=e.microseconds(1);static milliseconds(t=1){return e.microseconds(T(t,1e3))}static MILLISECOND=e.milliseconds(1);static seconds(t=1){return e.milliseconds(T(t,1e3))}static SECOND=e.seconds(1);static minutes(t=1){return e.seconds(T(t,60))}static MINUTE=e.minutes(1);static hours(t){return e.minutes(T(t,60))}static HOUR=e.hours(1);static days(t){return e.hours(T(t,24))}static DAY=e.days(1);static MAX=new e(x);static MIN=new e(0);static ZERO=new e(0);static z=c.z.union([c.z.object({value:c.z.bigint()}).transform(t=>new e(t.value)),c.z.string().transform(t=>new e(BigInt(t))),c.z.number().transform(t=>new e(t)),c.z.bigint().transform(t=>new e(t)),c.z.instanceof(e),c.z.instanceof(I).transform(t=>new e(t)),c.z.custom(e=>e instanceof R).transform(t=>new e(t))])},R=class e extends b{constructor(e){y(e)&&(e=e.value),super(e.valueOf())}toString(){return`${this.valueOf()} Hz`}equals(t){return this.valueOf()===new e(t).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 z(t).valueOf()}span(e){return L.seconds(e/this.valueOf())}byteSpan(e,t){return this.span(e.valueOf()/new z(t).valueOf())}add(t){return new e(w(this.valueOf(),new e(t).valueOf()))}sub(t){return new e(C(this.valueOf(),new e(t).valueOf()))}mult(t){return new e(T(this.valueOf(),t))}div(t){return new e(E(this.valueOf(),t))}static hz(t){return new e(t)}static khz(t){return e.hz(t*1e3)}static z=c.z.union([c.z.number().transform(t=>new e(t)),c.z.instanceof(e)])},z=class e extends b{constructor(e){y(e)&&(e=e.value),super(e.valueOf())}length(e){return e.valueOf()/this.valueOf()}size(e){return new H(e*this.valueOf())}add(t){return new e(w(this.valueOf(),new e(t).valueOf()))}sub(t){return new e(C(this.valueOf(),new e(t).valueOf()))}mult(t){return new e(T(this.valueOf(),t))}div(t){return new e(E(this.valueOf(),t))}static UNKNOWN=new e(0);static BIT128=new e(16);static BIT64=new e(8);static BIT32=new e(4);static BIT16=new e(2);static BIT8=new e(1);static z=c.z.union([c.z.number().transform(t=>new e(t)),c.z.instanceof(e)])},B=class e{start;end;constructor(e,t){typeof e==`object`&&`start`in e?(this.start=new I(e.start),this.end=new I(e.end)):(this.start=new I(e),this.end=new I(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 e(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(),r=this.end.sub(e.end).valueOf();return n<0&&(n=-n),r<0&&(r=-r),n<=t.valueOf()&&r<=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();let n=this.makeValid();if(this.equals(e))return!0;if(e.end.equals(n.start)||n.end.equals(e.start))return!1;let r=I.max(n.start,e.start),i=I.min(n.end,e.end);return i.before(r)?!1:new L(i.sub(r)).greaterThanOrEqual(t)}contains(t){return t instanceof e?this.contains(t.start)&&this.contains(t.end):this.start.beforeEq(t)&&this.end.after(t)}boundBy(t){let n=new e(this.start,this.end);return t.start.after(this.start)&&(n.start=t.start),t.start.after(this.end)&&(n.end=t.start),t.end.before(this.end)&&(n.end=t.end),t.end.before(this.start)&&(n.start=t.end),n}static max(...t){return new e(I.min(...t.map(e=>e.start)),I.max(...t.map(e=>e.end)))}static MAX=new e(I.MIN,I.MAX);static ZERO=new e(I.ZERO,I.ZERO);static z=c.z.union([c.z.object({start:I.z,end:I.z}).transform(t=>new e(t.start,t.end)),c.z.instanceof(e)]);static boundedZ=e.z.refine(({isValid:e})=>e,{message:`Time range start time must be before or equal to time range end time`}).refine(({end:e})=>e.valueOf()<=x,{message:`Time range end time must be less than or equal to the maximum value of an int64`}).refine(({start:e})=>e.valueOf()>=Ee,{message:`Time range start time must be greater than or equal to the minimum value of an int64`});static sort(e,t){return I.sort(e.start,t.start)||I.sort(e.end,t.end)}static merge(...t){return e.max(...t.map(t=>new e(t).makeValid()))}},V=class e extends b{constructor(t){if(y(t)&&(t=t.value),t instanceof e||typeof t==`string`||typeof t.valueOf()==`string`)super(t.valueOf());else{let n=e.ARRAY_CONSTRUCTOR_DATA_TYPES.get(t.constructor.name);if(n==null)throw Error(`unable to find data type for ${t.toString()}`);super(n.valueOf())}}get Array(){let t=e.ARRAY_CONSTRUCTORS.get(this.toString());if(t==null)throw Error(`unable to find array constructor for ${this.valueOf()}`);return t}equals(e){return this.valueOf()===e.valueOf()}matches(...e){return e.some(e=>this.equals(e))}toString(t=!1){return t?e.SHORT_STRINGS.get(this.valueOf())??this.valueOf():this.valueOf()}get isVariable(){return this.equals(e.JSON)||this.equals(e.STRING)||this.equals(e.BYTES)}get isNumeric(){return!this.isVariable&&!this.equals(e.UUID)}get isInteger(){let e=this.toString();return e.startsWith(`int`)||e.startsWith(`uint`)}get isFloat(){return this.toString().startsWith(`float`)}get density(){let t=e.DENSITIES.get(this.toString());if(t==null)throw Error(`unable to find density for ${this.valueOf()}`);return t}get isUnsignedInteger(){return this.equals(e.UINT8)||this.equals(e.UINT16)||this.equals(e.UINT32)||this.equals(e.UINT64)}get isSignedInteger(){return this.equals(e.INT8)||this.equals(e.INT16)||this.equals(e.INT32)||this.equals(e.INT64)}canSafelyCastTo(t){return this.equals(t)?!0:!this.isNumeric||!t.isNumeric||this.isVariable||t.isVariable||this.isUnsignedInteger&&t.isSignedInteger?!1:this.isFloat?t.isFloat&&this.density.valueOf()<=t.density.valueOf():this.equals(e.INT32)&&t.equals(e.FLOAT64)||this.equals(e.INT8)&&t.equals(e.FLOAT32)?!0:this.isInteger&&t.isInteger?this.density.valueOf()<=t.density.valueOf()&&this.isUnsignedInteger===t.isUnsignedInteger:!1}canCastTo(e){return this.isNumeric&&e.isNumeric?!0:this.equals(e)}checkArray(e){return e.constructor===this.Array}get usesBigInt(){return e.BIG_INT_TYPES.some(e=>e.equals(this))}static UNKNOWN=new e(`unknown`);static FLOAT64=new e(`float64`);static FLOAT32=new e(`float32`);static INT64=new e(`int64`);static INT32=new e(`int32`);static INT16=new e(`int16`);static INT8=new e(`int8`);static UINT64=new e(`uint64`);static UINT32=new e(`uint32`);static UINT16=new e(`uint16`);static UINT8=new e(`uint8`);static TIMESTAMP=new e(`timestamp`);static UUID=new e(`uuid`);static STRING=new e(`string`);static JSON=new e(`json`);static BYTES=new e(`bytes`);static ARRAY_CONSTRUCTORS=new Map([[e.UINT8.toString(),Uint8Array],[e.UINT16.toString(),Uint16Array],[e.UINT32.toString(),Uint32Array],[e.UINT64.toString(),BigUint64Array],[e.FLOAT32.toString(),Float32Array],[e.FLOAT64.toString(),Float64Array],[e.INT8.toString(),Int8Array],[e.INT16.toString(),Int16Array],[e.INT32.toString(),Int32Array],[e.INT64.toString(),BigInt64Array],[e.TIMESTAMP.toString(),BigInt64Array],[e.STRING.toString(),Uint8Array],[e.JSON.toString(),Uint8Array],[e.UUID.toString(),Uint8Array],[e.BYTES.toString(),Uint8Array]]);static ARRAY_CONSTRUCTOR_DATA_TYPES=new Map([[Uint8Array.name,e.UINT8],[Uint16Array.name,e.UINT16],[Uint32Array.name,e.UINT32],[BigUint64Array.name,e.UINT64],[Float32Array.name,e.FLOAT32],[Float64Array.name,e.FLOAT64],[Int8Array.name,e.INT8],[Int16Array.name,e.INT16],[Int32Array.name,e.INT32],[BigInt64Array.name,e.INT64]]);static DENSITIES=new Map([[e.UINT8.toString(),z.BIT8],[e.UINT16.toString(),z.BIT16],[e.UINT32.toString(),z.BIT32],[e.UINT64.toString(),z.BIT64],[e.FLOAT32.toString(),z.BIT32],[e.FLOAT64.toString(),z.BIT64],[e.INT8.toString(),z.BIT8],[e.INT16.toString(),z.BIT16],[e.INT32.toString(),z.BIT32],[e.INT64.toString(),z.BIT64],[e.TIMESTAMP.toString(),z.BIT64],[e.STRING.toString(),z.UNKNOWN],[e.JSON.toString(),z.UNKNOWN],[e.UUID.toString(),z.BIT128],[e.BYTES.toString(),z.UNKNOWN]]);static ALL=[e.UNKNOWN,e.UINT8,e.UINT16,e.UINT32,e.UINT64,e.INT8,e.INT16,e.INT32,e.INT64,e.FLOAT32,e.FLOAT64,e.TIMESTAMP,e.UUID,e.STRING,e.JSON,e.BYTES];static SHORT_STRINGS=new Map([[e.UINT8.toString(),`u8`],[e.UINT16.toString(),`u16`],[e.UINT32.toString(),`u32`],[e.UINT64.toString(),`u64`],[e.INT8.toString(),`i8`],[e.INT16.toString(),`i16`],[e.INT32.toString(),`i32`],[e.INT64.toString(),`i64`],[e.FLOAT32.toString(),`f32`],[e.FLOAT64.toString(),`f64`],[e.TIMESTAMP.toString(),`ts`],[e.UUID.toString(),`uuid`],[e.STRING.toString(),`str`],[e.JSON.toString(),`json`],[e.BYTES.toString(),`bytes`]]);static BIG_INT_TYPES=[e.INT64,e.UINT64,e.TIMESTAMP];static z=c.z.union([c.z.string().transform(t=>new e(t)),c.z.instanceof(e)])},H=class e extends b{constructor(e){y(e)&&(e=e.value),super(e.valueOf())}largerThan(e){return y(e)&&(e=e.value),this.valueOf()>e.valueOf()}smallerThan(e){return y(e)&&(e=e.value),this.valueOf()<e.valueOf()}add(t){return y(t)&&(t=t.value),new e(w(this.valueOf(),t.valueOf()))}sub(t){return y(t)&&(t=t.value),new e(C(this.valueOf(),t.valueOf()))}mult(t){return new e(T(this.valueOf(),t))}div(t){return new e(E(this.valueOf(),t))}truncate(t){return new e(Math.trunc(this.valueOf()/new e(t).valueOf())*new e(t).valueOf())}remainder(t){return e.bytes(this.valueOf()%new e(t).valueOf())}get gigabytes(){return this.valueOf()/e.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/e.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/e.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/e.TERABYTE.valueOf()}toString(){let t=this.truncate(e.TERABYTE),n=this.truncate(e.GIGABYTE),r=this.truncate(e.MEGABYTE),i=this.truncate(e.KILOBYTE),a=this.truncate(e.BYTE),o=t,s=n.sub(t),c=r.sub(n),l=i.sub(r),u=a.sub(i),d=``;return o.isZero||(d+=`${o.terabytes}TB `),s.isZero||(d+=`${s.gigabytes}GB `),c.isZero||(d+=`${c.megabytes}MB `),l.isZero||(d+=`${l.kilobytes}KB `),(!u.isZero||d===``)&&(d+=`${u.valueOf()}B`),d.trim()}static bytes(t=1){return new e(t)}static BYTE=new e(1);static kilobytes(t=1){return e.bytes(new e(t).valueOf()*1e3)}static KILOBYTE=e.kilobytes(1);static megabytes(t=1){return e.kilobytes(new e(t).valueOf()*1e3)}static MEGABYTE=e.megabytes(1);static gigabytes(t=1){return e.megabytes(new e(t).valueOf()*1e3)}static GIGABYTE=e.gigabytes(1);static terabytes(t){return e.gigabytes(new e(t).valueOf()*1e3)}static TERABYTE=e.terabytes(1);static ZERO=new e(0);static z=c.z.union([c.z.number().transform(t=>new e(t)),c.z.instanceof(e)]);get isZero(){return this.valueOf()===0}};c.z.object({start:c.z.number(),end:c.z.number()}),c.z.union([c.z.instanceof(Uint8Array),c.z.instanceof(Uint16Array),c.z.instanceof(Uint32Array),c.z.instanceof(BigUint64Array),c.z.instanceof(Float32Array),c.z.instanceof(Float64Array),c.z.instanceof(Int8Array),c.z.instanceof(Int16Array),c.z.instanceof(Int32Array),c.z.instanceof(BigInt64Array)]);var wt=e=>{let t=typeof e;return t===`string`||t===`number`||t===`boolean`||t===`bigint`||e instanceof I||e instanceof L||e instanceof Date},Tt=(e,t,n,r=0)=>e.usesBigInt&&!t.usesBigInt?Number(n)-Number(r):!e.usesBigInt&&t.usesBigInt?BigInt(n.valueOf())-BigInt(r.valueOf()):C(n,r);B.z,I.z,L.z,R.z,H.z,V.z,B.boundedZ;var Et=/^(?:[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 Dt(e){return typeof e==`string`&&Et.test(e)}var U=[];for(let e=0;e<256;++e)U.push((e+256).toString(16).slice(1));function Ot(e,t=0){return(U[e[t+0]]+U[e[t+1]]+U[e[t+2]]+U[e[t+3]]+`-`+U[e[t+4]]+U[e[t+5]]+`-`+U[e[t+6]]+U[e[t+7]]+`-`+U[e[t+8]]+U[e[t+9]]+`-`+U[e[t+10]]+U[e[t+11]]+U[e[t+12]]+U[e[t+13]]+U[e[t+14]]+U[e[t+15]]).toLowerCase()}function kt(e,t=0){let n=Ot(e,t);if(!Dt(n))throw TypeError(`Stringified UUID is invalid`);return n}typeof crypto<`u`&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);var At=(e,t)=>kt(e,t),W=-1,jt={[Symbol.iterator]:()=>jt,next:()=>({done:!0,value:void 0})},Mt=c.z.string().transform(e=>new Uint8Array(atob(e).split(``).map(e=>e.charCodeAt(0))).buffer),Nt=c.z.union([c.z.null(),c.z.undefined()]).transform(()=>new Uint8Array().buffer),Pt=10,Ft=(e,t)=>{if(e===`number`&&!t.isNumeric)throw Error(`cannot convert series of type ${t.toString()} to number`);if(e===`bigint`&&!t.usesBigInt)throw Error(`cannot convert series of type ${t.toString()} to bigint`)},It=`sy_x_telem_series`,Lt=class e{key;discriminator=It;dataType;sampleOffset;gl;_data;timeRange=B.ZERO;alignment=0n;alignmentMultiple=1n;cachedMin;cachedMax;writePos=W;_refCount=0;cachedLength;_cachedIndexes;static crudeZ=c.z.object({timeRange:B.z.optional(),dataType:V.z,alignment:c.z.coerce.bigint().optional(),data:c.z.union([Mt,Nt,c.z.instanceof(ArrayBuffer),c.z.instanceof(Uint8Array)]),glBufferUsage:bt.default(`static`).optional()});static z=e.crudeZ.transform(t=>new e(t));constructor(e){Rt(e)&&(e={data:e}),e.data??=[];let{dataType:t,timeRange:n,sampleOffset:r=0,glBufferUsage:i=`static`,alignment:a=0n,alignmentMultiple:o=1n,key:s=ve(),data:c}=e;if(zt(c)){let e=c;this.key=e.key,this.dataType=e.dataType,this.sampleOffset=e.sampleOffset,this.gl=e.gl,this._data=e._data,this.timeRange=e.timeRange,this.alignment=e.alignment,this.alignmentMultiple=e.alignmentMultiple,this.cachedMin=e.cachedMin,this.cachedMax=e.cachedMax,this.writePos=e.writePos,this._refCount=e._refCount,this.cachedLength=e.cachedLength;return}let l=wt(c),u=Array.isArray(c);if(t!=null)this.dataType=new V(t);else if(c instanceof ArrayBuffer)throw Error(`cannot infer data type from an ArrayBuffer instance when constructing a Series. Please provide a data type.`);else if(u||l){let e=c;if(!l){if(c.length===0)throw Error(`cannot infer data type from a zero length JS array when constructing a Series. Please provide a data type.`);e=c[0]}if(typeof e==`string`)this.dataType=V.STRING;else if(typeof e==`number`)this.dataType=V.FLOAT64;else if(typeof e==`bigint`)this.dataType=V.INT64;else if(typeof e==`boolean`)this.dataType=V.UINT8;else if(e instanceof I||e instanceof Date||e instanceof I)this.dataType=V.TIMESTAMP;else if(typeof e==`object`)this.dataType=V.JSON;else throw Error(`cannot infer data type of ${typeof e} when constructing a Series from a JS array`)}else this.dataType=new V(c);if(!u&&!l)this._data=c;else if(u&&c.length===0)this._data=new this.dataType.Array([]).buffer;else{let e=l?[c]:c,t=e[0];(t instanceof I||t instanceof Date||t instanceof L)&&(e=e.map(e=>new I(e).valueOf())),this.dataType.equals(V.STRING)?(this.cachedLength=e.length,this._data=new TextEncoder().encode(`${e.join(`
|
|
4
|
+
`)}\n`).buffer):this.dataType.equals(V.JSON)?(this.cachedLength=e.length,this._data=new TextEncoder().encode(`${e.map(e=>le.encodeString(e)).join(`
|
|
5
|
+
`)}\n`).buffer):this.dataType.usesBigInt&&typeof t==`number`?this._data=new this.dataType.Array(e.map(e=>BigInt(Math.round(e)))).buffer:!this.dataType.usesBigInt&&typeof t==`bigint`?this._data=new this.dataType.Array(e.map(Number)).buffer:this._data=new this.dataType.Array(e).buffer}this.key=s,this.alignment=a,this.alignmentMultiple=o,this.sampleOffset=r??0,this.timeRange=n??B.ZERO,this.gl={control:null,buffer:null,prevBuffer:0,bufferUsage:i}}static alloc({capacity:t,dataType:n,...r}){if(t===0)throw Error(`[Series] - cannot allocate an array of length 0`);let i=new e({data:new new V(n).Array(t).buffer,dataType:n,...r});return i.writePos=0,i}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 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===W)return 0;let 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===W)return 0;let 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===W?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(V.JSON))throw Error(`cannot parse non-JSON series as JSON`);return this.toStrings().map(t=>e.parse(le.decodeString(t)))}get byteCapacity(){return new H(this.underlyingData.byteLength)}get capacity(){return this.dataType.isVariable?this.byteCapacity.valueOf():this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===W?this.byteCapacity:this.dataType.isVariable?new H(this.writePos):this.dataType.density.size(this.writePos)}get length(){return this.cachedLength==null?this.dataType.isVariable?this.calculateCachedLength():this.writePos===W?this.byteCapacity.valueOf()/this.dataType.density.valueOf():this.writePos:this.cachedLength}calculateCachedLength(){if(!this.dataType.isVariable)throw Error(`cannot calculate length of a non-variable length data type`);let e=0,t=[0];return this.data.forEach((n,r)=>{n===Pt&&(e++,t.push(r+1))}),this._cachedIndexes=t,this.cachedLength=e,e}convert(t,n=0){if(this.dataType.equals(t))return this;let r=new t.Array(this.length);for(let e=0;e<this.length;e++)r[e]=Tt(this.dataType,t,this.data[e],n);return new e({data:r.buffer,dataType:t,timeRange:this.timeRange,sampleOffset:n,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment})}calcRawMax(){return this.length===0?-1/0:(this.dataType.equals(V.TIMESTAMP)?this.cachedMax=this.data[this.data.length-1]:(this.dataType.usesBigInt,this.cachedMax=this.data.reduce((e,t)=>e>t?e:t)),this.cachedMax)}get max(){return this.calcMax()}calcMax(){if(this.dataType.isVariable)throw Error(`cannot calculate maximum on a variable length data type`);return this.writePos===0?-1/0:(this.cachedMax??=this.calcRawMax(),w(this.cachedMax,this.sampleOffset))}calcRawMin(){return this.length===0?1/0:(this.dataType.equals(V.TIMESTAMP)?this.cachedMin=this.data[0]:(this.dataType.usesBigInt,this.cachedMin=this.data.reduce((e,t)=>e<t?e:t)),this.cachedMin)}get min(){return this.calcMin()}calcMin(){if(this.dataType.isVariable)throw Error(`cannot calculate minimum on a variable length data type`);return this.writePos===0?1/0:(this.cachedMin??=this.calcRawMin(),w(this.cachedMin,this.sampleOffset))}get bounds(){return k(Number(this.min),Number(this.max),{makeValid:!1})}maybeRecomputeMinMax(e){if(this.cachedMin!=null){let t=e.cachedMin??e.calcRawMin();t<this.cachedMin&&(this.cachedMin=t)}if(this.cachedMax!=null){let t=e.cachedMax??e.calcRawMax();t>this.cachedMax&&(this.cachedMax=t)}}atAlignment(e,t){let n=Number((e-this.alignment)/this.alignmentMultiple);if(n<0||n>=this.length){if(t===!0)throw 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(V.UUID))return this.atUUID(e,t);e<0&&(e=this.length+e);let n=this.data[e];if(n==null){if(t===!0)throw Error(`[series] - no value at index ${e}`);return}return w(n,this.sampleOffset)}atUUID(e,t){e<0&&(e=this.length+e);let n=At(new Uint8Array(this.buffer,e*this.dataType.density.valueOf()));if(n==null){if(t)throw Error(`[series] - no value at index ${e}`);return}return n}atVariable(e,t){let n=0,r=0;if(this._cachedIndexes!=null)n=this._cachedIndexes[e],r=this._cachedIndexes[e+1]-1;else{e<0&&(e=this.length+e);for(let t=0;t<this.data.length;t++)if(this.data[t]===Pt){if(e===0){r=t;break}n=t+1,e--}if(r===0&&(r=this.data.length),n>=r||e>0){if(t)throw Error(`[series] - no value at index ${e}`);return}}let i=this.data.slice(n,r);return this.dataType.equals(V.STRING)?new TextDecoder().decode(i):ne(JSON.parse(new TextDecoder().decode(i)))}binarySearch(e){let t=0,n=this.length-1,r=de(e);for(;t<=n;){let i=Math.floor((t+n)/2),a=r(this.at(i,!0),e);if(a===0)return i;a<0?t=i+1:n=i-1}return t}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals(V.FLOAT32)&&!this.dataType.equals(V.UINT8))throw Error(`Only FLOAT32 and UINT8 arrays can be used in WebGL`);let{buffer:t,bufferUsage:n,prevBuffer:r}=this.gl;if(t??(this.gl.buffer=e.createBuffer()),this.writePos!==r)if(e.bindBuffer(e.ARRAY_BUFFER,this.gl.buffer),this.writePos!==W){r===0&&e.bufferData(e.ARRAY_BUFFER,this.byteCapacity.valueOf(),e.STATIC_DRAW);let t=this.dataType.density.size(r).valueOf(),n=this.underlyingData.slice(this.gl.prevBuffer,this.writePos);e.bufferSubData(e.ARRAY_BUFFER,t,n.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=W}as(e){return Ft(e,this.dataType),this}get digest(){return{key:this.key,dataType:this.dataType.toString(),sampleOffset:this.sampleOffset,alignment:{lower:Gt(this.alignmentBounds.lower),upper:Gt(this.alignmentBounds.upper),multiple:this.alignmentMultiple},timeRange:this.timeRange.toString(),length:this.length,capacity:this.capacity}}get alignmentBounds(){return k(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 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){let e=new Vt(this);return this.dataType.equals(V.JSON)?new Ht(e):e}return this.dataType.equals(V.UUID)?new Ut(this):new Wt(this)}slice(e,t){return this.sliceSub(!1,e,t)}sub(e,t){return this.sliceSub(!0,e,t)}subIterator(e,t){return new Bt(this,e,t??this.length)}subAlignmentIterator(e,t){let n=Math.ceil(Number(e-this.alignment)/Number(this.alignmentMultiple)),r=Math.ceil(Number(t-this.alignment)/Number(this.alignmentMultiple));return new Bt(this,n,r)}subBytes(t,n){return t>=0&&(n==null||n>=this.byteLength.valueOf())?this:new e({data:this.data.subarray(t,n),dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(t)})}sliceSub(t,n,r){if(n<=0&&(r==null||r>=this.length))return this;let i;return i=t?this.data.subarray(n,r):this.data.slice(n,r),new e({data:i,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(n)})}reAlign(t){return new e({data:this.buffer,dataType:this.dataType,timeRange:B.ZERO,sampleOffset:this.sampleOffset,glBufferUsage:`static`,alignment:t})}toString(){let e=`Series(${this.dataType.toString()} ${this.length} [`;if(this.length<=10)e+=Array.from(this).map(e=>e.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}},Rt=e=>e==null?!1:Array.isArray(e)||e instanceof ArrayBuffer||ArrayBuffer.isView(e)&&!(e instanceof DataView)||e instanceof Lt?!0:wt(e),zt=ye(It,Lt),Bt=class{series;end;index;constructor(e,t,n){this.series=e;let r=k(0,e.length+1);this.end=Be(r,n),this.index=Be(r,t)}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}},Vt=class{series;index;decoder;constructor(e){if(!e.dataType.isVariable)throw Error(`cannot create a variable series iterator for a non-variable series`);this.series=e,this.index=0,this.decoder=new TextDecoder}next(){let e=this.index,t=this.series.data;for(;this.index<t.length&&t[this.index]!==Pt;)this.index++;let 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))})}},Ht=class e{wrapped;static schema=c.z.record(c.z.string(),c.z.unknown());constructor(e){this.wrapped=e}next(){let t=this.wrapped.next();return t.done===!0?{done:!0,value:void 0}:{done:!1,value:le.decodeString(t.value,e.schema)}}},Ut=class{series;index;data;density;constructor(e){if(!e.dataType.equals(V.UUID))throw 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=V.UUID.density.valueOf()}next(){if(this.index>=this.series.length)return{done:!0,value:void 0};let e=At(this.data,this.index*this.density);return this.index++,{done:!1,value:e}}},Wt=class{series;index;constructor(e){this.series=e,this.index=0}next(){return this.index>=this.series.length?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}},Gt=e=>({domain:e>>32n,sample:e&4294967295n}),Kt=async e=>await new Promise(t=>setTimeout(t,L.fromMilliseconds(e).milliseconds)),qt=u({Breaker:()=>Jt,breakerConfigZ:()=>Yt}),Jt=class{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(){let{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}},Yt=c.z.object({baseInterval:L.z.optional(),maxRetries:c.z.number().optional(),scale:c.z.number().optional()});c.z.int().min(Ce).max(127),c.z.int().min(we).max(Te),c.z.int().min(De).max(Oe);var Xt=c.z.int().min(0).max(255);c.z.int().min(0).max(be),c.z.int().min(0).max(xe),c.z.int().min(0).max(Se);var Zt=(e,t)=>{let n=Array.isArray(e),r=Array.isArray(t);if(n!==r)return!1;if(n&&r){let n=e,r=t;if(n.length!==r.length)return!1;for(let e=0;e<n.length;e++)if(!Zt(n[e],r[e]))return!1;return!0}if(e==null||t==null||typeof e!=`object`||typeof t!=`object`)return e===t;if(`equals`in e)return e.equals(t);let i=Object.keys(e),a=Object.keys(t);if(i.length!==a.length)return!1;for(let n of i){let r=e[n],i=t[n];if(typeof r==`object`&&typeof i==`object`){if(!Zt(r,i))return!1}else if(r!==i)return!1}return!0},Qt=(e,t)=>{if(typeof e!=`object`||!e)return e===t;let n=Object.keys(e),r=Object.keys(t);if(r.length>n.length)return!1;for(let n of r){let r=e[n],i=t[n];if(typeof r==`object`&&typeof i==`object`){if(!Qt(r,i))return!1}else if(r!==i)return!1}return!0},$t=(e,...t)=>{if(t.length===0)return e;let n=t.shift();if(v(e)&&v(n))for(let t in n)try{v(n[t])?(t in e||Object.assign(e,{[t]:{}}),$t(e[t],n[t])):Object.assign(e,{[t]:n[t]})}catch(e){throw e instanceof TypeError?TypeError(`.${t}: ${e.message}`,{cause:e}):e}return $t(e,...t)},en=c.z.string().regex(/^#?([0-9a-f]{6}|[0-9a-f]{8})$/i),G=Xt,tn=c.z.number().min(0).max(1),nn=c.z.tuple([G,G,G,tn]),rn=c.z.tuple([G,G,G]),an=c.z.object({rgba255:nn}),on=c.z.object({r:G,g:G,b:G,a:tn}),sn=c.z.number().min(0).max(360),cn=c.z.number().min(0).max(100),ln=c.z.number().min(0).max(100),un=c.z.tuple([sn,cn,ln,tn]),dn=c.z.union([en,rn,nn,un,an,on]),fn=dn.transform(e=>pn(e)),pn=(e,t=1)=>{if(e=dn.parse(e),typeof e==`string`)return mn(e,t);if(Array.isArray(e)){if(e.length<3||e.length>4)throw Error(`Invalid color: [${e.join(`, `)}]`);return e.length===3?[...e,t]:e}return`a`in e&&`r`in e?[e.r,e.g,e.b,e.a]:e.rgba255},mn=(e,t=1)=>(e=en.parse(e),e=hn(e),[K(e,0),K(e,2),K(e,4),e.length===8?K(e,6)/255:t]),K=(e,t)=>parseInt(e.slice(t,t+2),16),hn=e=>e.startsWith(`#`)?e.slice(1):e;pn(`#000000`),pn(`#ffffff`);var gn=c.z.object({key:c.z.string(),color:dn,position:c.z.number(),switched:c.z.boolean().optional()});c.z.array(gn);var _n=c.z.object({key:c.z.string(),name:c.z.string(),color:fn});c.z.object({key:c.z.string(),name:c.z.string(),swatches:c.z.array(_n)});var vn=function(e){return e[e.exclusive=0]=`exclusive`,e[e.shared=1]=`shared`,e}({});c.z.enum(vn),c.z.object({key:c.z.string(),name:c.z.string(),group:c.z.uint32().optional()});var yn=e=>Object.getOwnPropertySymbols(globalThis).includes(e),bn=(e,t)=>{let n=Symbol.for(e);if(!yn(n)){let e=t();Object.defineProperty(globalThis,n,{value:e})}return()=>globalThis[n]},q=u({Canceled:()=>jn,NONE:()=>`nil`,NotImplemented:()=>Mn,UNKNOWN:()=>Y,Unknown:()=>kn,createTyped:()=>J,decode:()=>On,encode:()=>Dn,isTyped:()=>Cn,payloadZ:()=>An,register:()=>En}),xn=`sy_x_error`,Sn=e=>t=>typeof t==`object`&&t&&`type`in t&&typeof t.type==`string`?t.type.startsWith(e):t instanceof Error?t.message.startsWith(e):typeof t==`string`?t.startsWith(e):!1,J=e=>class t extends Error{static discriminator=xn;discriminator=t.discriminator;static TYPE=e;type=t.TYPE;static matches=Sn(e);matches=t.matches;constructor(e,n){super(e,n),this.name=t.TYPE}static sub(t){return J(`${e}.${t}`)}},Cn=e=>{if(typeof e!=`object`||!e)return!1;let t=e;if(t.discriminator!==xn)return!1;if(!(`type`in t))throw Error(`X Error is missing its type property: ${JSON.stringify(t)}`);return!0},Y=`unknown`,wn=class{providers=[];register(e){this.providers.push(e)}encode(e){if(e==null)return{type:`nil`,data:``};if(Cn(e))for(let t of this.providers){let 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===`nil`)return null;if(e.type===`unknown`)return new kn(e.data);for(let t of this.providers){let n=t.decode(e);if(n!=null)return n}return new kn(e.data)}},Tn=bn(`synnax-error-registry`,()=>new wn),En=({encode:e,decode:t})=>Tn().register({encode:e,decode:t}),Dn=e=>Tn().encode(e),On=e=>e==null?null:Tn().decode(e),kn=class extends J(`unknown`){},An=c.z.object({type:c.z.string(),data:c.z.string()}),jn=class extends J(`canceled`){},Mn=class extends J(`not_implemented`){};c.z.string().regex(/^(?:$|(?:\/(?:[^~/]|~0|~1)*)+)$/,`must be a valid JSON pointer (RFC 6901)`),c.z.union([c.z.string(),c.z.number(),c.z.boolean(),c.z.null()]),c.z.enum([`string`,`number`,`boolean`,`null`]),c.z.object({key:c.z.string(),value:c.z.string()});var Nn=c.z.uuid();c.z.object({key:Nn,name:c.z.string().min(1),color:fn}).partial({key:!0}),c.z.string().regex(/^\d+\.\d+\.\d+(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$/),c.z.enum([`standard`,`scientific`,`engineering`]),c.z.union([c.z.string(),c.z.number()]),typeof process<`u`&&process.versions!=null&&process.versions.node!=null||typeof window>`u`||window.document;var Pn=[`macOS`,`Windows`,`Linux`],Fn=[`macos`,`windows`,`linux`],In={macos:`macOS`,windows:`Windows`,linux:`Linux`};c.z.enum(Pn).or(c.z.enum(Fn).transform(e=>In[e])),c.z.object({stack:c.z.string(),error:c.z.instanceof(Error)}),c.z.enum([`success`,`info`,`warning`,`error`,`loading`,`disabled`]),c.z.literal(`success`),c.z.literal(`info`),c.z.literal(`warning`),c.z.literal(`error`),c.z.literal(`loading`),c.z.literal(`disabled`);var Ln=(...e)=>e.map(Rn).join(``),Rn=e=>(e.endsWith(`/`)||(e+=`/`),e.startsWith(`/`)&&(e=e.slice(1)),e),zn=e=>e.endsWith(`/`)?e.slice(0,-1):e,Bn=(e,t=``)=>e===null?``:`?${Object.entries(e).filter(([,e])=>e==null?!1:Array.isArray(e)?e.length>0:!0).map(([e,n])=>`${t}${e}=${n}`).join(`&`)}`,Vn=class e{protocol;host;port;path;constructor({host:e,port:t,protocol:n=``,pathPrefix:r=``}){this.protocol=n,this.host=e,this.port=t,this.path=Rn(r)}replace(t){return new e({host:t.host??this.host,port:t.port??this.port,protocol:t.protocol??this.protocol,pathPrefix:t.pathPrefix??this.path})}child(t){return new e({...this,pathPrefix:Ln(this.path,t)})}toString(){return zn(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}static UNKNOWN=new e({host:`unknown`,port:0})},X=class extends q.createTyped(`freighter`){},Z=class extends X.sub(`eof`){constructor(){super(`EOF`)}},Q=class extends X.sub(`stream_closed`){constructor(){super(`StreamClosed`)}},$=class extends X.sub(`unreachable`){url;constructor(e={}){let{message:t=`Unreachable`,url:n=Vn.UNKNOWN}=e;super(t),this.url=n}};q.register({encode:e=>{if(!e.type.startsWith(X.TYPE))return null;if(Z.matches(e))return{type:Z.TYPE,data:`EOF`};if(Q.matches(e))return{type:Q.TYPE,data:`StreamClosed`};if($.matches(e))return{type:$.TYPE,data:`Unreachable`};throw Error(`Unknown error type: ${e.type}: ${e.message}`)},decode:e=>{if(!e.type.startsWith(X.TYPE))return null;switch(e.type){case Z.TYPE:return new Z;case Q.TYPE:return new Q;case $.TYPE:return new $;default:throw new q.Unknown(`Unknown error type: ${e.data}`)}}});var Hn=class{middleware=[];use(...e){this.middleware.push(...e)}async executeMiddleware(e,t){let n=0,r=async e=>{if(n===this.middleware.length)return await t(e);let i=this.middleware[n];return n++,await i(e,r)};return await r(e)}},Un=`Content-Type`,Wn=new Set([`ECONNREFUSED`,`ECONNRESET`,`ETIMEDOUT`,`EPIPE`,`UND_ERR_CONNECT_TIMEOUT`,`UND_ERR_SOCKET`]),Gn=e=>{let t=e?.cause?.code??e?.code??e?.errno;if(typeof t==`string`&&Wn.has(t))return!0;if(e.name===`TypeError`){let t=String(e.message||``).toLowerCase();if(/load failed|failed to fetch|networkerror|network error/.test(t))return typeof navigator<`u`&&navigator.onLine,!0}return e?.name===`AbortError`||e?.code,!1},Kn=400,qn=class extends Hn{endpoint;encoder;constructor(e,t,n=!1){return super(),this.endpoint=e.replace({protocol:n?`https`:`http`}),this.encoder=t,new Proxy(this,{get:(e,t,n)=>t===`endpoint`?this.endpoint:Reflect.get(e,t,n)})}get headers(){return{[Un]:this.encoder.contentType}}async send(e,t,n,r){let i=null,a=this.endpoint.child(e),o={};o.method=`POST`,o.body=this.encoder.encode(t,n);let[,s]=await this.executeMiddleware({target:a.toString(),protocol:this.endpoint.protocol,params:{},role:`client`},async e=>{let t={...e,params:{}};o.headers={...this.headers,...e.params};let n;try{n=await fetch(e.target,o)}catch(e){if(!(e instanceof Error))throw e;return[t,Gn(e)?new $({url:a}):e]}let s=await n.arrayBuffer();if(n?.ok)return r!=null&&(i=this.encoder.decode(s,r)),[t,null];try{if(n.status!==Kn)return[t,Error(n.statusText)];let e=this.encoder.decode(s,q.payloadZ);return[t,q.decode(e)]}catch(e){return[t,Error(`[freighter] - failed to decode error: ${n.statusText}: ${e.message}`)]}});if(s!=null)return[null,s];if(i==null)throw Error(`Response must be defined`);return[i,null]}},Jn=(e,t)=>{class n{wrapped;constructor(e){this.wrapped=e}use(...e){this.wrapped.use(...e)}async send(e,n,r,i){let a=new qt.Breaker(t);do{let[t,o]=await this.wrapped.send(e,n,r,i);if(o==null)return[t,null];if(!$.matches(o))return[null,o];if(console.warn(`[freighter] ${a.retryMessage}`,o),!await a.wait())return[t,o]}while(!0)}}return new n(e)},Yn=async(e,t,n,r,i)=>{let[a,o]=await e.send(t,n,r,i);if(o!=null)throw o;return a},Xn=c.z.object({type:c.z.enum([`data`,`close`,`open`]),payload:c.z.unknown(),error:c.z.optional(q.payloadZ)}),Zn=class{codec;reqSchema;resSchema;ws;serverClosed;sendClosed;receiveDataQueue=[];receiveCallbacksQueue=[];constructor(e,t,n,r){this.codec=t,this.reqSchema=n,this.resSchema=r,this.ws=e,this.sendClosed=!1,this.serverClosed=null,this.listenForMessages()}async receiveOpenAck(){let e=await this.receiveMsg();if(e.type!==`open`){if(e.error==null)throw Error(`Message error must be defined`);return q.decode(e.error)}return null}send(e){if(this.serverClosed!=null)return new Z;if(this.sendClosed)throw new Q;return this.ws.send(this.codec.encode({type:`data`,payload:e})),null}async receive(){if(this.serverClosed!=null)return[null,this.serverClosed];let e=await this.receiveMsg();if(e.type===`close`){if(e.error==null||(this.serverClosed=q.decode(e.error),this.serverClosed==null))throw 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;let e={type:`close`};try{this.ws.send(this.codec.encode(e))}finally{this.sendClosed=!0}}async receiveMsg(){return this.receiveDataQueue.shift()??await new Promise((e,t)=>this.receiveCallbacksQueue.push({resolve:e,reject:t}))}addMessage(e){let t=this.receiveCallbacksQueue.shift();t==null?this.receiveDataQueue.push(e):t.resolve(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,Xn))}onClose(e){this.addMessage({type:`close`,error:{type:e.code===$n?Z.TYPE:Q.TYPE,data:``}})}},Qn=`freighterctx`,$n=1e3,er=class e extends Hn{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(t){let n=new e(this.baseUrl,t,this.secure);return n.use(...this.middleware),n}async stream(t,n,r){let i,[,a]=await this.executeMiddleware({target:t,protocol:`websocket`,params:{},role:`client`},async a=>{let o=new WebSocket(this.buildURL(t,a)),s={...a,params:{}};o.binaryType=e.MESSAGE_TYPE;let c=await this.wrapSocket(o,n,r);return c instanceof Error?[s,c]:(i=c,[s,null])});if(a!=null)throw a;return i}buildURL(e,t){let n=Bn({[Un]:this.encoder.contentType,...t.params},Qn);return this.baseUrl.child(e).toString()+n}async wrapSocket(e,t,n){return await new Promise(r=>{e.onopen=()=>{let i=new Zn(e,this.encoder,t,n);i.receiveOpenAck().then(e=>{r(e??i)}).catch(e=>r(e))},e.onerror=e=>{r(Error(e.message))}})}};exports.EOF=Z,exports.HTTPClient=qn,exports.StreamClosed=Q,exports.Unreachable=$,exports.WebSocketClient=er,exports.sendRequired=Yn,exports.unaryWithBreaker=Jn;
|