@synnaxlabs/client 0.45.0 → 0.45.1
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 +5 -5
- package/dist/client.cjs +13 -13
- package/dist/client.js +2005 -1990
- package/package.json +4 -4
package/dist/client.cjs
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("zod"),ac=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)},Fs=r=>{const e=(t,n=Kr)=>{if(typeof t=="string")return r(t);if(Array.isArray(t))return t.map(o=>e(o,n));if(!Rr(t))return t;n=uc(n);const i={},a=t;return"toJSON"in a&&typeof a.toJSON=="function"?e(a.toJSON(),n):(Object.keys(a).forEach(o=>{let c=a[o];const u=r(o);n.recursive&&(Rr(c)?ns(c)||(c=e(c,n)):n.recursiveInArray&&rs(c)&&(c=[...c].map(l=>{let h=l;return Rr(l)?ns(h)||(h=e(l,n)):rs(l)&&(h=e({key:l},n).key),h}))),i[u]=c}),i)};return e},Ys=Fs(ac),oc=r=>r.replace(/([a-z0-9])([A-Z])/g,(e,t,n)=>`${t}_${n.toLowerCase()}`),cc=Fs(oc),lc=[Number,String,Uint8Array],Kr={recursive:!0,recursiveInArray:!0},uc=(r=Kr)=>(r.recursive==null?r=Kr:r.recursiveInArray??=!1,r),rs=r=>r!=null&&Array.isArray(r),Rr=r=>r!=null&&typeof r=="object"&&!Array.isArray(r),ns=r=>lc.some(e=>r instanceof e);let hc=class{contentType="application/json";decoder;encoder;constructor(){this.decoder=new TextDecoder,this.encoder=new TextEncoder}encode(r){return this.encoder.encode(this.encodeString(r))}decode(r,e){return this.decodeString(this.decoder.decode(r),e)}decodeString(r,e){const t=JSON.parse(r),n=Ys(t);return e!=null?e.parse(n):n}encodeString(r){const e=cc(r);return JSON.stringify(e,(t,n)=>ArrayBuffer.isView(n)?Array.from(n):typeof n=="bigint"?n.toString():n)}};const Jr=new hc,X=r=>r!=null&&typeof r=="object"&&"value"in r;let rt=class{value;constructor(e){this.value=e}valueOf(){return this.value}toJSON(){return this.value}toString(){return this.value.toString()}};const fc=r=>r!=null&&typeof r=="object"&&"toString"in r,dc=(r,e=!1)=>{const t=fc(r)?"stringer":typeof r;let n;switch(t){case"string":n=(i,a)=>i.localeCompare(a);break;case"stringer":n=(i,a)=>i.toString().localeCompare(a.toString());break;case"number":n=(i,a)=>Number(i)-Number(a);break;case"bigint":n=(i,a)=>BigInt(i)-BigInt(a)>0n?1:-1;break;case"boolean":n=(i,a)=>Number(i)-Number(a);break;case"undefined":n=()=>0;break;default:return console.warn(`sortFunc: unknown type ${t}`),()=>-1}return e?yc(n):n},yc=r=>(e,t)=>r(t,e),ur=s.z.tuple([s.z.number(),s.z.number()]);s.z.tuple([s.z.bigint(),s.z.bigint()]);const Vs=s.z.object({width:s.z.number(),height:s.z.number()}),gc=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()}),pc=["width","height"];s.z.enum(pc);const mc=["start","center","end"],wc=["signedWidth","signedHeight"];s.z.enum(wc);const ir=s.z.object({x:s.z.number(),y:s.z.number()}),bc=s.z.object({clientX:s.z.number(),clientY:s.z.number()}),Tc=["x","y"],Hs=s.z.enum(Tc),_s=["top","right","bottom","left"];s.z.enum(_s);const vc=["left","right"],Ws=s.z.enum(vc),Ec=["top","bottom"],Gs=s.z.enum(Ec),Ks=["center"],ss=s.z.enum(Ks),Nc=[..._s,...Ks],Js=s.z.enum(Nc);s.z.enum(mc);const Oc=["first","last"];s.z.enum(Oc);const zc=s.z.object({lower:s.z.number(),upper:s.z.number()}),Sc=s.z.object({lower:s.z.bigint(),upper:s.z.bigint()});s.z.union([zc,ur]);s.z.union([Sc,ur]);s.z.enum([...Hs.options,...Js.options]);s.z.enum(["x","left","right"]);s.z.enum(["y","top","bottom"]);s.z.union([Hs,Js,s.z.instanceof(String)]);const hr=r=>(e,t)=>{if(typeof e=="bigint"){if(Ac(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))},fr=hr((r,e)=>r-e),dr=hr((r,e)=>r+e),Ac=r=>typeof r=="bigint"?!0:Number.isInteger(r),le=hr((r,e)=>r*e),yr=hr((r,e)=>r/e),De=(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?$c(n):n},$c=r=>r.lower>r.upper?{lower:r.upper,upper:r.lower}:r,is=(r,e)=>{const t=De(r);return e<t.lower?t.lower:e>=t.upper?t.upper-(typeof t.upper=="number"?1:1n):e};s.z.object({x:Ws.or(ss),y:Gs.or(ss)});const Ic=s.z.object({x:Ws,y:Gs}),kc=Object.freeze({x:"left",y:"top"}),xc=(r,e)=>r.x===e.x&&r.y===e.y,as=s.z.union([s.z.number(),ir,ur,Vs,gc,bc]),Cc=(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}},os=Object.freeze({x:0,y:0}),_t=s.z.union([s.z.number(),s.z.string()]);s.z.object({top:_t,left:_t,width:_t,height:_t});s.z.object({left:s.z.number(),top:s.z.number(),right:s.z.number(),bottom:s.z.number()});s.z.object({one:ir,two:ir,root:Ic});const En=(r,e,t=0,n=0,i)=>{const a={one:{...os},two:{...os},root:i??kc};if(typeof r=="number"){if(typeof e!="number")throw new Error("Box constructor called with invalid arguments");return a.one={x:r,y:e},a.two={x:a.one.x+t,y:a.one.y+n},a}return"one"in r&&"two"in r&&"root"in r?{...r,root:i??r.root}:("getBoundingClientRect"in r&&(r=r.getBoundingClientRect()),"left"in r?(a.one={x:r.left,y:r.top},a.two={x:r.right,y:r.bottom},a):(a.one=r,e==null?a.two={x:a.one.x+t,y:a.one.y+n}:typeof e=="number"?a.two={x:a.one.x+e,y:a.one.y+t}:"width"in e?a.two={x:a.one.x+e.width,y:a.one.y+e.height}:"signedWidth"in e?a.two={x:a.one.x+e.signedWidth,y:a.one.y+e.signedHeight}:a.two=e,a))},jr=r=>{const e=En(r);return{lower:e.one.x,upper:e.two.x}},Mr=r=>{const e=En(r);return{lower:e.one.y,upper:e.two.y}},Rc=r=>typeof r!="object"||r==null?!1:"one"in r&&"two"in r&&"root"in r,jc=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()});s.z.union([Vs,jc,ir,ur]);const Mc=(r,e,t)=>e!==void 0&&r<e?e:t!==void 0&&r>t?t:r;s.z.object({offset:as,scale:as});s.z.object({offset:s.z.number(),scale:s.z.number()});const Uc=r=>(e,t,n,i)=>t==="dimension"?[e,n]:[e,i?n-r:n+r],Dc=r=>(e,t,n,i)=>[e,i?n/r:n*r],Zc=r=>(e,t,n)=>{if(e===null)return[r,n];const{lower:i,upper:a}=e,{lower:o,upper:c}=r,u=a-i,l=c-o;if(t==="dimension")return[r,n*(l/u)];const h=(n-i)*(l/u)+o;return[r,h]},Pc=r=>(e,t,n)=>[r,n],Lc=()=>(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)]},Bc=r=>(e,t,n)=>{const{lower:i,upper:a}=r;return n=Mc(n,i,a),[e,n]};let cs=class Ve{ops=[];currBounds=null;currType=null;reversed=!1;constructor(){this.ops=[]}static translate(e){return new Ve().translate(e)}static magnify(e){return new Ve().magnify(e)}static scale(e,t){return new Ve().scale(e,t)}translate(e){const t=this.new(),n=Uc(e);return n.type="translate",t.ops.push(n),t}magnify(e){const t=this.new(),n=Dc(e);return n.type="magnify",t.ops.push(n),t}scale(e,t){const n=De(e,t),i=this.new(),a=Zc(n);return a.type="scale",i.ops.push(a),i}clamp(e,t){const n=De(e,t),i=this.new(),a=Bc(n);return a.type="clamp",i.ops.push(a),i}reBound(e,t){const n=De(e,t),i=this.new(),a=Pc(n);return a.type="re-bound",i.ops.push(a),i}invert(){const e=Lc();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 Ve;return e.ops=this.ops.slice(),e.reversed=this.reversed,e}exec(e,t){return this.currBounds=null,this.ops.reduce(([n,i],a)=>a(n,e,i,this.reversed),[null,t])[1]}reverse(){const e=this.new();e.ops.reverse();const t=[];return e.ops.forEach((n,i)=>{if(n.type==="scale"||t.some(([o,c])=>i>=o&&i<=c))return;const a=e.ops.findIndex((o,c)=>o.type==="scale"&&c>i);a!==-1&&t.push([i,a])}),t.forEach(([n,i])=>{const a=e.ops.slice(n,i);a.unshift(e.ops[i]),e.ops.splice(n,i-n+1,...a)}),e.reversed=!e.reversed,e}get transform(){return{scale:this.dim(1),offset:this.pos(0)}}static IDENTITY=new Ve};(class oe{x;y;currRoot;constructor(e=new cs,t=new cs,n=null){this.x=e,this.y=t,this.currRoot=n}static translate(e,t){return new oe().translate(e,t)}static translateX(e){return new oe().translateX(e)}static translateY(e){return new oe().translateY(e)}static clamp(e){return new oe().clamp(e)}static magnify(e){return new oe().magnify(e)}static scale(e){return new oe().scale(e)}static reBound(e){return new oe().reBound(e)}translate(e,t){const n=Cc(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(Rc(e)){const n=this.currRoot;return t.currRoot=e.root,n!=null&&!xc(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(jr(e)),t.y=t.y.scale(Mr(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(jr(e)),t.y=this.y.reBound(Mr(e)),t}clamp(e){const t=this.copy();return t.x=this.x.clamp(jr(e)),t.y=this.y.clamp(Mr(e)),t}copy(){const e=new oe;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 En(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 oe});let Xs=(r,e=21)=>(t=e)=>{let n="",i=t|0;for(;i--;)n+=r[Math.random()*r.length|0];return n};const Qs="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",qc=`0123456789${Qs}`,Fc=11,Yc=Xs(Qs,1),Vc=Xs(qc,Fc-1),Hc=()=>`${Yc()}${Vc()}`,_c=(r,e)=>t=>t instanceof e||typeof t=="object"&&t!==null&&"discriminator"in t&&t.discriminator===r,Wc=s.z.enum(["static","dynamic"]),Gc=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)])]),ei=(r,e)=>{const t=new I(e);if(![A.DAY,A.HOUR,A.MINUTE,A.SECOND,A.MILLISECOND,A.MICROSECOND,A.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 I?new I(n):new A(n)};let I=class w extends rt{constructor(e,t="UTC"){if(e==null)super(w.now().valueOf());else if(e instanceof Date)super(BigInt(e.getTime())*w.MILLISECOND.valueOf());else if(typeof e=="string")super(w.parseDateTimeString(e,t).valueOf());else if(Array.isArray(e))super(w.parseDate(e));else{let n=0n;e instanceof Number&&(e=e.valueOf()),t==="local"&&(n=w.utcOffset.valueOf()),typeof e=="number"&&(isFinite(e)?e=Math.trunc(e):(isNaN(e)&&(e=0),e===1/0?e=w.MAX:e=w.MIN)),X(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 w(BigInt(i.getTime())*w.MILLISECOND.valueOf()).truncate(w.DAY).valueOf()}valueOf(){return this.value}static parseTimeString(e,t="UTC"){const[n,i,a]=e.split(":");let o="00",c="00";a!=null&&([o,c]=a.split("."));let u=w.hours(parseInt(n??"00")).add(w.minutes(parseInt(i??"00"))).add(w.seconds(parseInt(o??"00"))).add(w.milliseconds(parseInt(c??"00")));return t==="local"&&(u=u.add(w.utcOffset)),u.valueOf()}static parseDateTimeString(e,t="UTC"){if(!e.includes("/")&&!e.includes("-"))return w.parseTimeString(e,t);const n=new Date(e);return e.includes(":")||n.setUTCHours(0,0,0,0),new w(BigInt(n.getTime())*w.MILLISECOND.valueOf(),t).valueOf()}fString(e="ISO",t="UTC"){switch(e){case"ISODate":return this.toISOString(t).slice(0,10);case"ISOTime":return this.toISOString(t).slice(11,23);case"time":return this.timeString(!1,t);case"preciseTime":return this.timeString(!0,t);case"date":return this.dateString();case"preciseDate":return`${this.dateString()} ${this.timeString(!0,t)}`;case"dateTime":return`${this.dateString()} ${this.timeString(!1,t)}`;default:return this.toISOString(t)}}toISOString(e="UTC"){return e==="UTC"?this.date().toISOString():this.sub(w.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 A(BigInt(new Date().getTimezoneOffset())*w.MINUTE.valueOf())}static since(e){return new w().span(e)}date(){return new Date(this.milliseconds)}equals(e){return this.valueOf()===new w(e).valueOf()}span(e){return this.range(e).span}range(e){return new dt(this,e).makeValid()}spanRange(e){return this.range(this.add(e)).makeValid()}get isZero(){return this.valueOf()===0n}after(e){return this.valueOf()>new w(e).valueOf()}afterEq(e){return this.valueOf()>=new w(e).valueOf()}before(e){return this.valueOf()<new w(e).valueOf()}beforeEq(e){return this.valueOf()<=new w(e).valueOf()}add(e){return new w(dr(this.valueOf(),new A(e).valueOf()))}sub(e){return new w(fr(this.valueOf(),new A(e).valueOf()))}get hours(){return Number(this.valueOf())/Number(A.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(A.MINUTE.valueOf())}get days(){return Number(this.valueOf())/Number(A.DAY.valueOf())}get seconds(){return Number(this.valueOf())/Number(A.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(w.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(w.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 w(t)}get month(){return this.date().getUTCMonth()}setMonth(e){const t=this.date();return t.setUTCMonth(e),new w(t)}get day(){return this.date().getUTCDate()}setDay(e){const t=this.date();return t.setUTCDate(e),new w(t)}get hour(){return this.date().getUTCHours()}get localHour(){return this.date().getHours()}setLocalHour(e){const t=this.date();return t.setHours(e),new w(t)}setHour(e){const t=this.date();return t.setUTCHours(e),new w(t)}get minute(){return this.date().getUTCMinutes()}setMinute(e){const t=this.date();return t.setUTCMinutes(e),new w(t)}get second(){return this.date().getUTCSeconds()}setSecond(e){const t=this.date();return t.setUTCSeconds(e),new w(t)}get millisecond(){return this.date().getUTCMilliseconds()}setMillisecond(e){const t=this.date();return t.setUTCMilliseconds(e),new w(t)}toString(){return this.date().toISOString()}remainder(e){return ei(this,e)}get isToday(){return this.truncate(A.DAY).equals(w.now().truncate(A.DAY))}truncate(e){return this.sub(this.remainder(e))}static now(){return new w(new Date)}static max(...e){let t=w.MIN;for(const n of e){const i=new w(n);i.after(t)&&(t=i)}return t}static min(...e){let t=w.MAX;for(const n of e){const i=new w(n);i.before(t)&&(t=i)}return t}static nanoseconds(e,t="UTC"){return new w(e,t)}static NANOSECOND=w.nanoseconds(1);static microseconds(e,t="UTC"){return w.nanoseconds(e*1e3,t)}static MICROSECOND=w.microseconds(1);static milliseconds(e,t="UTC"){return w.microseconds(e*1e3,t)}static MILLISECOND=w.milliseconds(1);static seconds(e,t="UTC"){return w.milliseconds(e*1e3,t)}static SECOND=w.seconds(1);static minutes(e,t="UTC"){return w.seconds(e*60,t)}static MINUTE=w.minutes(1);static hours(e,t="UTC"){return w.minutes(e*60,t)}static HOUR=w.hours(1);static days(e,t="UTC"){return w.hours(e*24,t)}static DAY=w.days(1);static MAX=new w((1n<<63n)-1n);static MIN=new w(0);static ZERO=new w(0);static z=s.z.union([s.z.instanceof(w),s.z.object({value:s.z.bigint()}).transform(e=>new w(e.value)),s.z.string().transform(e=>new w(BigInt(e))),s.z.number().transform(e=>new w(e)),s.z.bigint().transform(e=>new w(e)),s.z.date().transform(e=>new w(e)),s.z.custom(e=>e instanceof A).transform(e=>new w(e)),Gc.transform(e=>new w(e))]);static sort(e,t){return Number(e.valueOf()-t.valueOf())}},A=class b extends rt{constructor(e){typeof e=="number"&&(e=Math.trunc(e.valueOf())),X(e)&&(e=e.value),super(BigInt(e.valueOf()))}static fromSeconds(e){return e instanceof b?e:e instanceof Ur?e.period:e instanceof I?new b(e):(X(e)&&(e=e.value),["number","bigint"].includes(typeof e)?b.seconds(e):new b(e))}static fromMilliseconds(e){return e instanceof b?e:e instanceof Ur?e.period:e instanceof I?new b(e):(X(e)&&(e=e.value),["number","bigint"].includes(typeof e)?b.milliseconds(e):new b(e))}valueOf(){return this.value}lessThan(e){return this.valueOf()<new b(e).valueOf()}greaterThan(e){return this.valueOf()>new b(e).valueOf()}lessThanOrEqual(e){return this.valueOf()<=new b(e).valueOf()}greaterThanOrEqual(e){return this.valueOf()>=new b(e).valueOf()}remainder(e){return ei(this,e)}truncate(e){return new b(BigInt(Math.trunc(Number(this.valueOf()/e.valueOf())))*e.valueOf())}toString(){const e=this.truncate(b.DAY),t=this.truncate(b.HOUR),n=this.truncate(b.MINUTE),i=this.truncate(b.SECOND),a=this.truncate(b.MILLISECOND),o=this.truncate(b.MICROSECOND),c=this.truncate(b.NANOSECOND),u=e,l=t.sub(e),h=n.sub(t),y=i.sub(n),d=a.sub(i),N=o.sub(a),S=c.sub(o);let k="";return u.isZero||(k+=`${u.days}d `),l.isZero||(k+=`${l.hours}h `),h.isZero||(k+=`${h.minutes}m `),y.isZero||(k+=`${y.seconds}s `),d.isZero||(k+=`${d.milliseconds}ms `),N.isZero||(k+=`${N.microseconds}µs `),S.isZero||(k+=`${S.nanoseconds}ns`),k.trim()}mult(e){return new b(le(this.valueOf(),e))}div(e){return new b(yr(this.valueOf(),e))}get days(){return Number(this.valueOf())/Number(b.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(b.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(b.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(b.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(b.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(b.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get isZero(){return this.valueOf()===0n}equals(e){return this.valueOf()===new b(e).valueOf()}add(e){return new b(this.valueOf()+new b(e).valueOf())}sub(e){return new b(this.valueOf()-new b(e).valueOf())}static nanoseconds(e=1){return new b(e)}static NANOSECOND=b.nanoseconds(1);static microseconds(e=1){return b.nanoseconds(le(e,1e3))}static MICROSECOND=b.microseconds(1);static milliseconds(e=1){return b.microseconds(le(e,1e3))}static MILLISECOND=b.milliseconds(1);static seconds(e=1){return b.milliseconds(le(e,1e3))}static SECOND=b.seconds(1);static minutes(e=1){return b.seconds(le(e,60))}static MINUTE=b.minutes(1);static hours(e){return b.minutes(le(e,60))}static HOUR=b.hours(1);static days(e){return b.hours(le(e,24))}static DAY=b.days(1);static MAX=new b((1n<<63n)-1n);static MIN=new b(0);static ZERO=new b(0);static z=s.z.union([s.z.object({value:s.z.bigint()}).transform(e=>new b(e.value)),s.z.string().transform(e=>new b(BigInt(e))),s.z.number().transform(e=>new b(e)),s.z.bigint().transform(e=>new b(e)),s.z.instanceof(b),s.z.instanceof(I).transform(e=>new b(e)),s.z.custom(e=>e instanceof Ur).transform(e=>new b(e))])},Ur=class J extends rt{constructor(e){X(e)&&(e=e.value),super(e.valueOf())}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new J(e).valueOf()}get period(){return A.seconds(1/this.valueOf())}sampleCount(e){return new A(e).seconds*this.valueOf()}byteCount(e,t){return this.sampleCount(e)*new _(t).valueOf()}span(e){return A.seconds(e/this.valueOf())}byteSpan(e,t){return this.span(e.valueOf()/new _(t).valueOf())}add(e){return new J(dr(this.valueOf(),new J(e).valueOf()))}sub(e){return new J(fr(this.valueOf(),new J(e).valueOf()))}mult(e){return new J(le(this.valueOf(),e))}div(e){return new J(yr(this.valueOf(),e))}static hz(e){return new J(e)}static khz(e){return J.hz(e*1e3)}static z=s.z.union([s.z.number().transform(e=>new J(e)),s.z.instanceof(J)])},_=class G extends rt{constructor(e){X(e)&&(e=e.value),super(e.valueOf())}length(e){return e.valueOf()/this.valueOf()}size(e){return new Xr(e*this.valueOf())}add(e){return new G(dr(this.valueOf(),new G(e).valueOf()))}sub(e){return new G(fr(this.valueOf(),new G(e).valueOf()))}mult(e){return new G(le(this.valueOf(),e))}div(e){return new G(yr(this.valueOf(),e))}static UNKNOWN=new G(0);static BIT128=new G(16);static BIT64=new G(8);static BIT32=new G(4);static BIT16=new G(2);static BIT8=new G(1);static z=s.z.union([s.z.number().transform(e=>new G(e)),s.z.instanceof(G)])},dt=class re{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 A(this.end.valueOf()-this.start.valueOf())}get isValid(){return this.start.valueOf()<=this.end.valueOf()}makeValid(){return this.isValid?this:this.swap()}get isZero(){return this.span.isZero}get numeric(){return{start:Number(this.start.valueOf()),end:Number(this.end.valueOf())}}swap(){return new re(this.end,this.start)}get numericBounds(){return{lower:Number(this.start.valueOf()),upper:Number(this.end.valueOf())}}equals(e,t=A.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.fString("preciseDate")} - ${this.span.toString()}`}overlapsWith(e,t=A.ZERO){e=e.makeValid();const n=this.makeValid();if(this.equals(e))return!0;if(e.end.equals(n.start)||n.end.equals(e.start))return!1;const i=I.max(n.start,e.start),a=I.min(n.end,e.end);return a.before(i)?!1:new A(a.sub(i)).greaterThanOrEqual(t)}contains(e){return e instanceof re?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const t=new re(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 re(I.min(...e.map(t=>t.start)),I.max(...e.map(t=>t.end)))}static MAX=new re(I.MIN,I.MAX);static MIN=new re(I.MAX,I.MIN);static ZERO=new re(I.ZERO,I.ZERO);static z=s.z.union([s.z.object({start:I.z,end:I.z}).transform(e=>new re(e.start,e.end)),s.z.instanceof(re)]);static sort(e,t){return I.sort(e.start,t.start)||I.sort(e.end,t.end)}static simplify(e){return e.map(t=>t.makeValid()).sort((t,n)=>re.sort(t,n)).reduce((t,n)=>{if(n.isZero)return t;if(t.length===0)return t.push(n),t;const i=t[t.length-1];return i.overlapsWith(n)||i.end.equals(n.start)?i.end=I.max(i.end,n.end):t.push(n),t},[])}},U=class g extends rt{constructor(e){if(X(e)&&(e=e.value),e instanceof g||typeof e=="string"||typeof e.valueOf()=="string")super(e.valueOf());else{const t=g.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=g.ARRAY_CONSTRUCTORS.get(this.toString());if(e==null)throw new Error(`unable to find array constructor for ${this.valueOf()}`);return e}equals(e){return this.valueOf()===e.valueOf()}matches(...e){return e.some(t=>this.equals(t))}toString(){return this.valueOf()}get isVariable(){return this.equals(g.JSON)||this.equals(g.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(g.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=g.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}get isUnsignedInteger(){return this.equals(g.UINT8)||this.equals(g.UINT16)||this.equals(g.UINT32)||this.equals(g.UINT64)}get isSignedInteger(){return this.equals(g.INT8)||this.equals(g.INT16)||this.equals(g.INT32)||this.equals(g.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(g.INT32)&&e.equals(g.FLOAT64)||this.equals(g.INT8)&&e.equals(g.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 g.BIG_INT_TYPES.some(e=>e.equals(this))}static UNKNOWN=new g("unknown");static FLOAT64=new g("float64");static FLOAT32=new g("float32");static INT64=new g("int64");static INT32=new g("int32");static INT16=new g("int16");static INT8=new g("int8");static UINT64=new g("uint64");static UINT32=new g("uint32");static UINT16=new g("uint16");static UINT8=new g("uint8");static BOOLEAN=this.UINT8;static TIMESTAMP=new g("timestamp");static UUID=new g("uuid");static STRING=new g("string");static JSON=new g("json");static ARRAY_CONSTRUCTORS=new Map([[g.UINT8.toString(),Uint8Array],[g.UINT16.toString(),Uint16Array],[g.UINT32.toString(),Uint32Array],[g.UINT64.toString(),BigUint64Array],[g.FLOAT32.toString(),Float32Array],[g.FLOAT64.toString(),Float64Array],[g.INT8.toString(),Int8Array],[g.INT16.toString(),Int16Array],[g.INT32.toString(),Int32Array],[g.INT64.toString(),BigInt64Array],[g.TIMESTAMP.toString(),BigInt64Array],[g.STRING.toString(),Uint8Array],[g.JSON.toString(),Uint8Array],[g.UUID.toString(),Uint8Array]]);static ARRAY_CONSTRUCTOR_DATA_TYPES=new Map([[Uint8Array.name,g.UINT8],[Uint16Array.name,g.UINT16],[Uint32Array.name,g.UINT32],[BigUint64Array.name,g.UINT64],[Float32Array.name,g.FLOAT32],[Float64Array.name,g.FLOAT64],[Int8Array.name,g.INT8],[Int16Array.name,g.INT16],[Int32Array.name,g.INT32],[BigInt64Array.name,g.INT64]]);static DENSITIES=new Map([[g.UINT8.toString(),_.BIT8],[g.UINT16.toString(),_.BIT16],[g.UINT32.toString(),_.BIT32],[g.UINT64.toString(),_.BIT64],[g.FLOAT32.toString(),_.BIT32],[g.FLOAT64.toString(),_.BIT64],[g.INT8.toString(),_.BIT8],[g.INT16.toString(),_.BIT16],[g.INT32.toString(),_.BIT32],[g.INT64.toString(),_.BIT64],[g.TIMESTAMP.toString(),_.BIT64],[g.STRING.toString(),_.UNKNOWN],[g.JSON.toString(),_.UNKNOWN],[g.UUID.toString(),_.BIT128]]);static ALL=[g.UNKNOWN,g.FLOAT64,g.FLOAT32,g.INT64,g.INT32,g.INT16,g.INT8,g.UINT64,g.UINT32,g.UINT16,g.UINT8,g.TIMESTAMP,g.UUID,g.STRING,g.JSON];static BIG_INT_TYPES=[g.INT64,g.UINT64,g.TIMESTAMP];static z=s.z.union([s.z.string().transform(e=>new g(e)),s.z.instanceof(g)])},Xr=class O extends rt{constructor(e){X(e)&&(e=e.value),super(e.valueOf())}largerThan(e){return X(e)&&(e=e.value),this.valueOf()>e.valueOf()}smallerThan(e){return X(e)&&(e=e.value),this.valueOf()<e.valueOf()}add(e){return X(e)&&(e=e.value),new O(dr(this.valueOf(),e.valueOf()))}sub(e){return X(e)&&(e=e.value),new O(fr(this.valueOf(),e.valueOf()))}mult(e){return new O(le(this.valueOf(),e))}div(e){return new O(yr(this.valueOf(),e))}truncate(e){return new O(Math.trunc(this.valueOf()/new O(e).valueOf())*new O(e).valueOf())}remainder(e){return O.bytes(this.valueOf()%new O(e).valueOf())}get gigabytes(){return this.valueOf()/O.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/O.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/O.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/O.TERABYTE.valueOf()}toString(){const e=this.truncate(O.TERABYTE),t=this.truncate(O.GIGABYTE),n=this.truncate(O.MEGABYTE),i=this.truncate(O.KILOBYTE),a=this.truncate(O.BYTE),o=e,c=t.sub(e),u=n.sub(t),l=i.sub(n),h=a.sub(i);let y="";return o.isZero||(y+=`${o.terabytes}TB `),c.isZero||(y+=`${c.gigabytes}GB `),u.isZero||(y+=`${u.megabytes}MB `),l.isZero||(y+=`${l.kilobytes}KB `),(!h.isZero||y==="")&&(y+=`${h.valueOf()}B`),y.trim()}static bytes(e=1){return new O(e)}static BYTE=new O(1);static kilobytes(e=1){return O.bytes(new O(e).valueOf()*1e3)}static KILOBYTE=O.kilobytes(1);static megabytes(e=1){return O.kilobytes(new O(e).valueOf()*1e3)}static MEGABYTE=O.megabytes(1);static gigabytes(e=1){return O.megabytes(new O(e).valueOf()*1e3)}static GIGABYTE=O.gigabytes(1);static terabytes(e){return O.gigabytes(new O(e).valueOf()*1e3)}static TERABYTE=O.terabytes(1);static ZERO=new O(0);static z=s.z.union([s.z.number().transform(e=>new O(e)),s.z.instanceof(O)]);get isZero(){return this.valueOf()===0}};s.z.union([s.z.instanceof(Uint8Array),s.z.instanceof(Uint16Array),s.z.instanceof(Uint32Array),s.z.instanceof(BigUint64Array),s.z.instanceof(Float32Array),s.z.instanceof(Float64Array),s.z.instanceof(Int8Array),s.z.instanceof(Int16Array),s.z.instanceof(Int32Array),s.z.instanceof(BigInt64Array)]);const ti=r=>{const e=typeof r;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||r instanceof I||r instanceof A||r instanceof Date},Kc=(r,e,t,n=0)=>r.usesBigInt&&!e.usesBigInt?Number(t)-Number(n):!r.usesBigInt&&e.usesBigInt?BigInt(t.valueOf())-BigInt(n.valueOf()):Xt(t,-n),Xt=(r,e)=>e==0?r:r==0?e:typeof r=="bigint"&&typeof e=="bigint"||typeof r=="number"&&typeof e=="number"?r+e:Number(r)+Number(e),Jc=/^(?:[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 Xc(r){return typeof r=="string"&&Jc.test(r)}const q=[];for(let r=0;r<256;++r)q.push((r+256).toString(16).slice(1));function Qc(r,e=0){return(q[r[e+0]]+q[r[e+1]]+q[r[e+2]]+q[r[e+3]]+"-"+q[r[e+4]]+q[r[e+5]]+"-"+q[r[e+6]]+q[r[e+7]]+"-"+q[r[e+8]]+q[r[e+9]]+"-"+q[r[e+10]]+q[r[e+11]]+q[r[e+12]]+q[r[e+13]]+q[r[e+14]]+q[r[e+15]]).toLowerCase()}function el(r,e=0){const t=Qc(r,e);if(!Xc(t))throw TypeError("Stringified UUID is invalid");return t}typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const ri=(r,e)=>el(r,e),Ee=-1,tl=s.z.string().transform(r=>new Uint8Array(atob(r).split("").map(e=>e.charCodeAt(0))).buffer),rl=s.z.union([s.z.null(),s.z.undefined()]).transform(()=>new Uint8Array().buffer),Qr=10,nl=(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`)},ni="sy_x_telem_series";let si=class Se{key;discriminator=ni;dataType;sampleOffset;gl;_data;timeRange=dt.ZERO;alignment=0n;alignmentMultiple=1n;cachedMin;cachedMax;writePos=Ee;_refCount=0;cachedLength;_cachedIndexes;static crudeZ=s.z.object({timeRange:dt.z.optional(),dataType:U.z,alignment:s.z.coerce.bigint().optional(),data:s.z.union([tl,rl,s.z.instanceof(ArrayBuffer),s.z.instanceof(Uint8Array)]),glBufferUsage:Wc.optional().default("static").optional()});static z=Se.crudeZ.transform(e=>new Se(e));constructor(e){sl(e)&&(e={data:e}),e.data??=[];const{dataType:t,timeRange:n,sampleOffset:i=0,glBufferUsage:a="static",alignment:o=0n,alignmentMultiple:c=1n,key:u=Hc(),data:l}=e;if(il(l)){const d=l;this.key=d.key,this.dataType=d.dataType,this.sampleOffset=d.sampleOffset,this.gl=d.gl,this._data=d._data,this.timeRange=d.timeRange,this.alignment=d.alignment,this.alignmentMultiple=d.alignmentMultiple,this.cachedMin=d.cachedMin,this.cachedMax=d.cachedMax,this.writePos=d.writePos,this._refCount=d._refCount,this.cachedLength=d.cachedLength;return}const h=ti(l),y=Array.isArray(l);if(t!=null)this.dataType=new U(t);else{if(l instanceof ArrayBuffer)throw new Error("cannot infer data type from an ArrayBuffer instance when constructing a Series. Please provide a data type.");if(y||h){let d=l;if(!h){if(l.length===0)throw new Error("cannot infer data type from a zero length JS array when constructing a Series. Please provide a data type.");d=l[0]}if(typeof d=="string")this.dataType=U.STRING;else if(typeof d=="number")this.dataType=U.FLOAT64;else if(typeof d=="bigint")this.dataType=U.INT64;else if(typeof d=="boolean")this.dataType=U.BOOLEAN;else if(d instanceof I||d instanceof Date||d instanceof I)this.dataType=U.TIMESTAMP;else if(typeof d=="object")this.dataType=U.JSON;else throw new Error(`cannot infer data type of ${typeof d} when constructing a Series from a JS array`)}else this.dataType=new U(l)}if(!y&&!h)this._data=l;else if(y&&l.length===0)this._data=new this.dataType.Array([]).buffer;else{let d=h?[l]:l;const N=d[0];(N instanceof I||N instanceof Date||N instanceof A)&&(d=d.map(S=>new I(S).valueOf())),this.dataType.equals(U.STRING)?(this.cachedLength=d.length,this._data=new TextEncoder().encode(`${d.join(`
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("zod"),oc=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)},Ys=r=>{const e=(t,n=Kr)=>{if(typeof t=="string")return r(t);if(Array.isArray(t))return t.map(o=>e(o,n));if(!Rr(t))return t;n=hc(n);const i={},a=t;return"toJSON"in a&&typeof a.toJSON=="function"?e(a.toJSON(),n):(Object.keys(a).forEach(o=>{let c=a[o];const u=r(o);n.recursive&&(Rr(c)?ss(c)||(c=e(c,n)):n.recursiveInArray&&ns(c)&&(c=[...c].map(l=>{let h=l;return Rr(l)?ss(h)||(h=e(l,n)):ns(l)&&(h=e({key:l},n).key),h}))),i[u]=c}),i)};return e},Vs=Ys(oc),cc=r=>r.replace(/([a-z0-9])([A-Z])/g,(e,t,n)=>`${t}_${n.toLowerCase()}`),lc=Ys(cc),uc=[Number,String,Uint8Array],Kr={recursive:!0,recursiveInArray:!0},hc=(r=Kr)=>(r.recursive==null?r=Kr:r.recursiveInArray??=!1,r),ns=r=>r!=null&&Array.isArray(r),Rr=r=>r!=null&&typeof r=="object"&&!Array.isArray(r),ss=r=>uc.some(e=>r instanceof e);let fc=class{contentType="application/json";decoder;encoder;constructor(){this.decoder=new TextDecoder,this.encoder=new TextEncoder}encode(r){return this.encoder.encode(this.encodeString(r))}decode(r,e){return this.decodeString(this.decoder.decode(r),e)}decodeString(r,e){const t=JSON.parse(r),n=Vs(t);return e!=null?e.parse(n):n}encodeString(r){const e=lc(r);return JSON.stringify(e,(t,n)=>ArrayBuffer.isView(n)?Array.from(n):typeof n=="bigint"?n.toString():n)}};const Jr=new fc,X=r=>r!=null&&typeof r=="object"&&"value"in r;let rt=class{value;constructor(e){this.value=e}valueOf(){return this.value}toJSON(){return this.value}toString(){return this.value.toString()}};const dc=r=>r!=null&&typeof r=="object"&&"toString"in r,yc=(r,e=!1)=>{const t=dc(r)?"stringer":typeof r;let n;switch(t){case"string":n=(i,a)=>i.localeCompare(a);break;case"stringer":n=(i,a)=>i.toString().localeCompare(a.toString());break;case"number":n=(i,a)=>Number(i)-Number(a);break;case"bigint":n=(i,a)=>BigInt(i)-BigInt(a)>0n?1:-1;break;case"boolean":n=(i,a)=>Number(i)-Number(a);break;case"undefined":n=()=>0;break;default:return console.warn(`sortFunc: unknown type ${t}`),()=>-1}return e?gc(n):n},gc=r=>(e,t)=>r(t,e),ur=s.z.tuple([s.z.number(),s.z.number()]);s.z.tuple([s.z.bigint(),s.z.bigint()]);const Hs=s.z.object({width:s.z.number(),height:s.z.number()}),pc=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()}),mc=["width","height"];s.z.enum(mc);const wc=["start","center","end"],bc=["signedWidth","signedHeight"];s.z.enum(bc);const ir=s.z.object({x:s.z.number(),y:s.z.number()}),Tc=s.z.object({clientX:s.z.number(),clientY:s.z.number()}),vc=["x","y"],_s=s.z.enum(vc),Ws=["top","right","bottom","left"];s.z.enum(Ws);const Ec=["left","right"],Gs=s.z.enum(Ec),Nc=["top","bottom"],Ks=s.z.enum(Nc),Js=["center"],is=s.z.enum(Js),Oc=[...Ws,...Js],Xs=s.z.enum(Oc);s.z.enum(wc);const zc=["first","last"];s.z.enum(zc);const Sc=s.z.object({lower:s.z.number(),upper:s.z.number()}),Ac=s.z.object({lower:s.z.bigint(),upper:s.z.bigint()});s.z.union([Sc,ur]);s.z.union([Ac,ur]);s.z.enum([..._s.options,...Xs.options]);s.z.enum(["x","left","right"]);s.z.enum(["y","top","bottom"]);s.z.union([_s,Xs,s.z.instanceof(String)]);const hr=r=>(e,t)=>{if(typeof e=="bigint"){if($c(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))},fr=hr((r,e)=>r-e),dr=hr((r,e)=>r+e),$c=r=>typeof r=="bigint"?!0:Number.isInteger(r),le=hr((r,e)=>r*e),yr=hr((r,e)=>r/e),De=(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?Ic(n):n},Ic=r=>r.lower>r.upper?{lower:r.upper,upper:r.lower}:r,as=(r,e)=>{const t=De(r);return e<t.lower?t.lower:e>=t.upper?t.upper-(typeof t.upper=="number"?1:1n):e};s.z.object({x:Gs.or(is),y:Ks.or(is)});const kc=s.z.object({x:Gs,y:Ks}),xc=Object.freeze({x:"left",y:"top"}),Cc=(r,e)=>r.x===e.x&&r.y===e.y,os=s.z.union([s.z.number(),ir,ur,Hs,pc,Tc]),Rc=(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}},cs=Object.freeze({x:0,y:0}),_t=s.z.union([s.z.number(),s.z.string()]);s.z.object({top:_t,left:_t,width:_t,height:_t});s.z.object({left:s.z.number(),top:s.z.number(),right:s.z.number(),bottom:s.z.number()});s.z.object({one:ir,two:ir,root:kc});const Nn=(r,e,t=0,n=0,i)=>{const a={one:{...cs},two:{...cs},root:i??xc};if(typeof r=="number"){if(typeof e!="number")throw new Error("Box constructor called with invalid arguments");return a.one={x:r,y:e},a.two={x:a.one.x+t,y:a.one.y+n},a}return"one"in r&&"two"in r&&"root"in r?{...r,root:i??r.root}:("getBoundingClientRect"in r&&(r=r.getBoundingClientRect()),"left"in r?(a.one={x:r.left,y:r.top},a.two={x:r.right,y:r.bottom},a):(a.one=r,e==null?a.two={x:a.one.x+t,y:a.one.y+n}:typeof e=="number"?a.two={x:a.one.x+e,y:a.one.y+t}:"width"in e?a.two={x:a.one.x+e.width,y:a.one.y+e.height}:"signedWidth"in e?a.two={x:a.one.x+e.signedWidth,y:a.one.y+e.signedHeight}:a.two=e,a))},jr=r=>{const e=Nn(r);return{lower:e.one.x,upper:e.two.x}},Mr=r=>{const e=Nn(r);return{lower:e.one.y,upper:e.two.y}},jc=r=>typeof r!="object"||r==null?!1:"one"in r&&"two"in r&&"root"in r,Mc=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()});s.z.union([Hs,Mc,ir,ur]);const Uc=(r,e,t)=>e!==void 0&&r<e?e:t!==void 0&&r>t?t:r;s.z.object({offset:os,scale:os});s.z.object({offset:s.z.number(),scale:s.z.number()});const Dc=r=>(e,t,n,i)=>t==="dimension"?[e,n]:[e,i?n-r:n+r],Zc=r=>(e,t,n,i)=>[e,i?n/r:n*r],Pc=r=>(e,t,n)=>{if(e===null)return[r,n];const{lower:i,upper:a}=e,{lower:o,upper:c}=r,u=a-i,l=c-o;if(t==="dimension")return[r,n*(l/u)];const h=(n-i)*(l/u)+o;return[r,h]},Lc=r=>(e,t,n)=>[r,n],Bc=()=>(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)]},qc=r=>(e,t,n)=>{const{lower:i,upper:a}=r;return n=Uc(n,i,a),[e,n]};let ls=class Ve{ops=[];currBounds=null;currType=null;reversed=!1;constructor(){this.ops=[]}static translate(e){return new Ve().translate(e)}static magnify(e){return new Ve().magnify(e)}static scale(e,t){return new Ve().scale(e,t)}translate(e){const t=this.new(),n=Dc(e);return n.type="translate",t.ops.push(n),t}magnify(e){const t=this.new(),n=Zc(e);return n.type="magnify",t.ops.push(n),t}scale(e,t){const n=De(e,t),i=this.new(),a=Pc(n);return a.type="scale",i.ops.push(a),i}clamp(e,t){const n=De(e,t),i=this.new(),a=qc(n);return a.type="clamp",i.ops.push(a),i}reBound(e,t){const n=De(e,t),i=this.new(),a=Lc(n);return a.type="re-bound",i.ops.push(a),i}invert(){const e=Bc();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 Ve;return e.ops=this.ops.slice(),e.reversed=this.reversed,e}exec(e,t){return this.currBounds=null,this.ops.reduce(([n,i],a)=>a(n,e,i,this.reversed),[null,t])[1]}reverse(){const e=this.new();e.ops.reverse();const t=[];return e.ops.forEach((n,i)=>{if(n.type==="scale"||t.some(([o,c])=>i>=o&&i<=c))return;const a=e.ops.findIndex((o,c)=>o.type==="scale"&&c>i);a!==-1&&t.push([i,a])}),t.forEach(([n,i])=>{const a=e.ops.slice(n,i);a.unshift(e.ops[i]),e.ops.splice(n,i-n+1,...a)}),e.reversed=!e.reversed,e}get transform(){return{scale:this.dim(1),offset:this.pos(0)}}static IDENTITY=new Ve};(class oe{x;y;currRoot;constructor(e=new ls,t=new ls,n=null){this.x=e,this.y=t,this.currRoot=n}static translate(e,t){return new oe().translate(e,t)}static translateX(e){return new oe().translateX(e)}static translateY(e){return new oe().translateY(e)}static clamp(e){return new oe().clamp(e)}static magnify(e){return new oe().magnify(e)}static scale(e){return new oe().scale(e)}static reBound(e){return new oe().reBound(e)}translate(e,t){const n=Rc(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(jc(e)){const n=this.currRoot;return t.currRoot=e.root,n!=null&&!Cc(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(jr(e)),t.y=t.y.scale(Mr(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(jr(e)),t.y=this.y.reBound(Mr(e)),t}clamp(e){const t=this.copy();return t.x=this.x.clamp(jr(e)),t.y=this.y.clamp(Mr(e)),t}copy(){const e=new oe;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 Nn(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 oe});let Qs=(r,e=21)=>(t=e)=>{let n="",i=t|0;for(;i--;)n+=r[Math.random()*r.length|0];return n};const ei="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",Fc=`0123456789${ei}`,Yc=11,Vc=Qs(ei,1),Hc=Qs(Fc,Yc-1),_c=()=>`${Vc()}${Hc()}`,Wc=(r,e)=>t=>t instanceof e||typeof t=="object"&&t!==null&&"discriminator"in t&&t.discriminator===r,Gc=s.z.enum(["static","dynamic"]),Kc=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)])]),ti=(r,e)=>{const t=new I(e);if(![A.DAY,A.HOUR,A.MINUTE,A.SECOND,A.MILLISECOND,A.MICROSECOND,A.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 I?new I(n):new A(n)};let I=class w extends rt{constructor(e,t="UTC"){if(e==null)super(w.now().valueOf());else if(e instanceof Date)super(BigInt(e.getTime())*w.MILLISECOND.valueOf());else if(typeof e=="string")super(w.parseDateTimeString(e,t).valueOf());else if(Array.isArray(e))super(w.parseDate(e));else{let n=0n;e instanceof Number&&(e=e.valueOf()),t==="local"&&(n=w.utcOffset.valueOf()),typeof e=="number"&&(isFinite(e)?e=Math.trunc(e):(isNaN(e)&&(e=0),e===1/0?e=w.MAX:e=w.MIN)),X(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 w(BigInt(i.getTime())*w.MILLISECOND.valueOf()).truncate(w.DAY).valueOf()}valueOf(){return this.value}static parseTimeString(e,t="UTC"){const[n,i,a]=e.split(":");let o="00",c="00";a!=null&&([o,c]=a.split("."));let u=w.hours(parseInt(n??"00")).add(w.minutes(parseInt(i??"00"))).add(w.seconds(parseInt(o??"00"))).add(w.milliseconds(parseInt(c??"00")));return t==="local"&&(u=u.add(w.utcOffset)),u.valueOf()}static parseDateTimeString(e,t="UTC"){if(!e.includes("/")&&!e.includes("-"))return w.parseTimeString(e,t);const n=new Date(e);return e.includes(":")||n.setUTCHours(0,0,0,0),new w(BigInt(n.getTime())*w.MILLISECOND.valueOf(),t).valueOf()}fString(e="ISO",t="UTC"){switch(e){case"ISODate":return this.toISOString(t).slice(0,10);case"ISOTime":return this.toISOString(t).slice(11,23);case"time":return this.timeString(!1,t);case"preciseTime":return this.timeString(!0,t);case"date":return this.dateString();case"preciseDate":return`${this.dateString()} ${this.timeString(!0,t)}`;case"dateTime":return`${this.dateString()} ${this.timeString(!1,t)}`;default:return this.toISOString(t)}}toISOString(e="UTC"){return e==="UTC"?this.date().toISOString():this.sub(w.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 A(BigInt(new Date().getTimezoneOffset())*w.MINUTE.valueOf())}static since(e){return new w().span(e)}date(){return new Date(this.milliseconds)}equals(e){return this.valueOf()===new w(e).valueOf()}span(e){return this.range(e).span}range(e){return new dt(this,e).makeValid()}spanRange(e){return this.range(this.add(e)).makeValid()}get isZero(){return this.valueOf()===0n}after(e){return this.valueOf()>new w(e).valueOf()}afterEq(e){return this.valueOf()>=new w(e).valueOf()}before(e){return this.valueOf()<new w(e).valueOf()}beforeEq(e){return this.valueOf()<=new w(e).valueOf()}add(e){return new w(dr(this.valueOf(),new A(e).valueOf()))}sub(e){return new w(fr(this.valueOf(),new A(e).valueOf()))}get hours(){return Number(this.valueOf())/Number(A.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(A.MINUTE.valueOf())}get days(){return Number(this.valueOf())/Number(A.DAY.valueOf())}get seconds(){return Number(this.valueOf())/Number(A.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(w.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(w.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 w(t)}get month(){return this.date().getUTCMonth()}setMonth(e){const t=this.date();return t.setUTCMonth(e),new w(t)}get day(){return this.date().getUTCDate()}setDay(e){const t=this.date();return t.setUTCDate(e),new w(t)}get hour(){return this.date().getUTCHours()}get localHour(){return this.date().getHours()}setLocalHour(e){const t=this.date();return t.setHours(e),new w(t)}setHour(e){const t=this.date();return t.setUTCHours(e),new w(t)}get minute(){return this.date().getUTCMinutes()}setMinute(e){const t=this.date();return t.setUTCMinutes(e),new w(t)}get second(){return this.date().getUTCSeconds()}setSecond(e){const t=this.date();return t.setUTCSeconds(e),new w(t)}get millisecond(){return this.date().getUTCMilliseconds()}setMillisecond(e){const t=this.date();return t.setUTCMilliseconds(e),new w(t)}toString(){return this.date().toISOString()}remainder(e){return ti(this,e)}get isToday(){return this.truncate(A.DAY).equals(w.now().truncate(A.DAY))}truncate(e){return this.sub(this.remainder(e))}static now(){return new w(new Date)}static max(...e){let t=w.MIN;for(const n of e){const i=new w(n);i.after(t)&&(t=i)}return t}static min(...e){let t=w.MAX;for(const n of e){const i=new w(n);i.before(t)&&(t=i)}return t}static nanoseconds(e,t="UTC"){return new w(e,t)}static NANOSECOND=w.nanoseconds(1);static microseconds(e,t="UTC"){return w.nanoseconds(e*1e3,t)}static MICROSECOND=w.microseconds(1);static milliseconds(e,t="UTC"){return w.microseconds(e*1e3,t)}static MILLISECOND=w.milliseconds(1);static seconds(e,t="UTC"){return w.milliseconds(e*1e3,t)}static SECOND=w.seconds(1);static minutes(e,t="UTC"){return w.seconds(e*60,t)}static MINUTE=w.minutes(1);static hours(e,t="UTC"){return w.minutes(e*60,t)}static HOUR=w.hours(1);static days(e,t="UTC"){return w.hours(e*24,t)}static DAY=w.days(1);static MAX=new w((1n<<63n)-1n);static MIN=new w(0);static ZERO=new w(0);static z=s.z.union([s.z.instanceof(w),s.z.object({value:s.z.bigint()}).transform(e=>new w(e.value)),s.z.string().transform(e=>new w(BigInt(e))),s.z.number().transform(e=>new w(e)),s.z.bigint().transform(e=>new w(e)),s.z.date().transform(e=>new w(e)),s.z.custom(e=>e instanceof A).transform(e=>new w(e)),Kc.transform(e=>new w(e))]);static sort(e,t){return Number(e.valueOf()-t.valueOf())}},A=class b extends rt{constructor(e){typeof e=="number"&&(e=Math.trunc(e.valueOf())),X(e)&&(e=e.value),super(BigInt(e.valueOf()))}static fromSeconds(e){return e instanceof b?e:e instanceof Ur?e.period:e instanceof I?new b(e):(X(e)&&(e=e.value),["number","bigint"].includes(typeof e)?b.seconds(e):new b(e))}static fromMilliseconds(e){return e instanceof b?e:e instanceof Ur?e.period:e instanceof I?new b(e):(X(e)&&(e=e.value),["number","bigint"].includes(typeof e)?b.milliseconds(e):new b(e))}valueOf(){return this.value}lessThan(e){return this.valueOf()<new b(e).valueOf()}greaterThan(e){return this.valueOf()>new b(e).valueOf()}lessThanOrEqual(e){return this.valueOf()<=new b(e).valueOf()}greaterThanOrEqual(e){return this.valueOf()>=new b(e).valueOf()}remainder(e){return ti(this,e)}truncate(e){return new b(BigInt(Math.trunc(Number(this.valueOf()/e.valueOf())))*e.valueOf())}toString(){const e=this.truncate(b.DAY),t=this.truncate(b.HOUR),n=this.truncate(b.MINUTE),i=this.truncate(b.SECOND),a=this.truncate(b.MILLISECOND),o=this.truncate(b.MICROSECOND),c=this.truncate(b.NANOSECOND),u=e,l=t.sub(e),h=n.sub(t),y=i.sub(n),d=a.sub(i),N=o.sub(a),S=c.sub(o);let k="";return u.isZero||(k+=`${u.days}d `),l.isZero||(k+=`${l.hours}h `),h.isZero||(k+=`${h.minutes}m `),y.isZero||(k+=`${y.seconds}s `),d.isZero||(k+=`${d.milliseconds}ms `),N.isZero||(k+=`${N.microseconds}µs `),S.isZero||(k+=`${S.nanoseconds}ns`),k.trim()}mult(e){return new b(le(this.valueOf(),e))}div(e){return new b(yr(this.valueOf(),e))}get days(){return Number(this.valueOf())/Number(b.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(b.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(b.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(b.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(b.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(b.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get isZero(){return this.valueOf()===0n}equals(e){return this.valueOf()===new b(e).valueOf()}add(e){return new b(this.valueOf()+new b(e).valueOf())}sub(e){return new b(this.valueOf()-new b(e).valueOf())}static nanoseconds(e=1){return new b(e)}static NANOSECOND=b.nanoseconds(1);static microseconds(e=1){return b.nanoseconds(le(e,1e3))}static MICROSECOND=b.microseconds(1);static milliseconds(e=1){return b.microseconds(le(e,1e3))}static MILLISECOND=b.milliseconds(1);static seconds(e=1){return b.milliseconds(le(e,1e3))}static SECOND=b.seconds(1);static minutes(e=1){return b.seconds(le(e,60))}static MINUTE=b.minutes(1);static hours(e){return b.minutes(le(e,60))}static HOUR=b.hours(1);static days(e){return b.hours(le(e,24))}static DAY=b.days(1);static MAX=new b((1n<<63n)-1n);static MIN=new b(0);static ZERO=new b(0);static z=s.z.union([s.z.object({value:s.z.bigint()}).transform(e=>new b(e.value)),s.z.string().transform(e=>new b(BigInt(e))),s.z.number().transform(e=>new b(e)),s.z.bigint().transform(e=>new b(e)),s.z.instanceof(b),s.z.instanceof(I).transform(e=>new b(e)),s.z.custom(e=>e instanceof Ur).transform(e=>new b(e))])},Ur=class J extends rt{constructor(e){X(e)&&(e=e.value),super(e.valueOf())}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new J(e).valueOf()}get period(){return A.seconds(1/this.valueOf())}sampleCount(e){return new A(e).seconds*this.valueOf()}byteCount(e,t){return this.sampleCount(e)*new _(t).valueOf()}span(e){return A.seconds(e/this.valueOf())}byteSpan(e,t){return this.span(e.valueOf()/new _(t).valueOf())}add(e){return new J(dr(this.valueOf(),new J(e).valueOf()))}sub(e){return new J(fr(this.valueOf(),new J(e).valueOf()))}mult(e){return new J(le(this.valueOf(),e))}div(e){return new J(yr(this.valueOf(),e))}static hz(e){return new J(e)}static khz(e){return J.hz(e*1e3)}static z=s.z.union([s.z.number().transform(e=>new J(e)),s.z.instanceof(J)])},_=class G extends rt{constructor(e){X(e)&&(e=e.value),super(e.valueOf())}length(e){return e.valueOf()/this.valueOf()}size(e){return new Xr(e*this.valueOf())}add(e){return new G(dr(this.valueOf(),new G(e).valueOf()))}sub(e){return new G(fr(this.valueOf(),new G(e).valueOf()))}mult(e){return new G(le(this.valueOf(),e))}div(e){return new G(yr(this.valueOf(),e))}static UNKNOWN=new G(0);static BIT128=new G(16);static BIT64=new G(8);static BIT32=new G(4);static BIT16=new G(2);static BIT8=new G(1);static z=s.z.union([s.z.number().transform(e=>new G(e)),s.z.instanceof(G)])},dt=class re{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 A(this.end.valueOf()-this.start.valueOf())}get isValid(){return this.start.valueOf()<=this.end.valueOf()}makeValid(){return this.isValid?this:this.swap()}get isZero(){return this.span.isZero}get numeric(){return{start:Number(this.start.valueOf()),end:Number(this.end.valueOf())}}swap(){return new re(this.end,this.start)}get numericBounds(){return{lower:Number(this.start.valueOf()),upper:Number(this.end.valueOf())}}equals(e,t=A.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.fString("preciseDate")} - ${this.span.toString()}`}overlapsWith(e,t=A.ZERO){e=e.makeValid();const n=this.makeValid();if(this.equals(e))return!0;if(e.end.equals(n.start)||n.end.equals(e.start))return!1;const i=I.max(n.start,e.start),a=I.min(n.end,e.end);return a.before(i)?!1:new A(a.sub(i)).greaterThanOrEqual(t)}contains(e){return e instanceof re?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const t=new re(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 re(I.min(...e.map(t=>t.start)),I.max(...e.map(t=>t.end)))}static MAX=new re(I.MIN,I.MAX);static MIN=new re(I.MAX,I.MIN);static ZERO=new re(I.ZERO,I.ZERO);static z=s.z.union([s.z.object({start:I.z,end:I.z}).transform(e=>new re(e.start,e.end)),s.z.instanceof(re)]);static sort(e,t){return I.sort(e.start,t.start)||I.sort(e.end,t.end)}static simplify(e){return e.map(t=>t.makeValid()).sort((t,n)=>re.sort(t,n)).reduce((t,n)=>{if(n.isZero)return t;if(t.length===0)return t.push(n),t;const i=t[t.length-1];return i.overlapsWith(n)||i.end.equals(n.start)?i.end=I.max(i.end,n.end):t.push(n),t},[])}},U=class g extends rt{constructor(e){if(X(e)&&(e=e.value),e instanceof g||typeof e=="string"||typeof e.valueOf()=="string")super(e.valueOf());else{const t=g.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=g.ARRAY_CONSTRUCTORS.get(this.toString());if(e==null)throw new Error(`unable to find array constructor for ${this.valueOf()}`);return e}equals(e){return this.valueOf()===e.valueOf()}matches(...e){return e.some(t=>this.equals(t))}toString(){return this.valueOf()}get isVariable(){return this.equals(g.JSON)||this.equals(g.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(g.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=g.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}get isUnsignedInteger(){return this.equals(g.UINT8)||this.equals(g.UINT16)||this.equals(g.UINT32)||this.equals(g.UINT64)}get isSignedInteger(){return this.equals(g.INT8)||this.equals(g.INT16)||this.equals(g.INT32)||this.equals(g.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(g.INT32)&&e.equals(g.FLOAT64)||this.equals(g.INT8)&&e.equals(g.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 g.BIG_INT_TYPES.some(e=>e.equals(this))}static UNKNOWN=new g("unknown");static FLOAT64=new g("float64");static FLOAT32=new g("float32");static INT64=new g("int64");static INT32=new g("int32");static INT16=new g("int16");static INT8=new g("int8");static UINT64=new g("uint64");static UINT32=new g("uint32");static UINT16=new g("uint16");static UINT8=new g("uint8");static BOOLEAN=this.UINT8;static TIMESTAMP=new g("timestamp");static UUID=new g("uuid");static STRING=new g("string");static JSON=new g("json");static ARRAY_CONSTRUCTORS=new Map([[g.UINT8.toString(),Uint8Array],[g.UINT16.toString(),Uint16Array],[g.UINT32.toString(),Uint32Array],[g.UINT64.toString(),BigUint64Array],[g.FLOAT32.toString(),Float32Array],[g.FLOAT64.toString(),Float64Array],[g.INT8.toString(),Int8Array],[g.INT16.toString(),Int16Array],[g.INT32.toString(),Int32Array],[g.INT64.toString(),BigInt64Array],[g.TIMESTAMP.toString(),BigInt64Array],[g.STRING.toString(),Uint8Array],[g.JSON.toString(),Uint8Array],[g.UUID.toString(),Uint8Array]]);static ARRAY_CONSTRUCTOR_DATA_TYPES=new Map([[Uint8Array.name,g.UINT8],[Uint16Array.name,g.UINT16],[Uint32Array.name,g.UINT32],[BigUint64Array.name,g.UINT64],[Float32Array.name,g.FLOAT32],[Float64Array.name,g.FLOAT64],[Int8Array.name,g.INT8],[Int16Array.name,g.INT16],[Int32Array.name,g.INT32],[BigInt64Array.name,g.INT64]]);static DENSITIES=new Map([[g.UINT8.toString(),_.BIT8],[g.UINT16.toString(),_.BIT16],[g.UINT32.toString(),_.BIT32],[g.UINT64.toString(),_.BIT64],[g.FLOAT32.toString(),_.BIT32],[g.FLOAT64.toString(),_.BIT64],[g.INT8.toString(),_.BIT8],[g.INT16.toString(),_.BIT16],[g.INT32.toString(),_.BIT32],[g.INT64.toString(),_.BIT64],[g.TIMESTAMP.toString(),_.BIT64],[g.STRING.toString(),_.UNKNOWN],[g.JSON.toString(),_.UNKNOWN],[g.UUID.toString(),_.BIT128]]);static ALL=[g.UNKNOWN,g.FLOAT64,g.FLOAT32,g.INT64,g.INT32,g.INT16,g.INT8,g.UINT64,g.UINT32,g.UINT16,g.UINT8,g.TIMESTAMP,g.UUID,g.STRING,g.JSON];static BIG_INT_TYPES=[g.INT64,g.UINT64,g.TIMESTAMP];static z=s.z.union([s.z.string().transform(e=>new g(e)),s.z.instanceof(g)])},Xr=class O extends rt{constructor(e){X(e)&&(e=e.value),super(e.valueOf())}largerThan(e){return X(e)&&(e=e.value),this.valueOf()>e.valueOf()}smallerThan(e){return X(e)&&(e=e.value),this.valueOf()<e.valueOf()}add(e){return X(e)&&(e=e.value),new O(dr(this.valueOf(),e.valueOf()))}sub(e){return X(e)&&(e=e.value),new O(fr(this.valueOf(),e.valueOf()))}mult(e){return new O(le(this.valueOf(),e))}div(e){return new O(yr(this.valueOf(),e))}truncate(e){return new O(Math.trunc(this.valueOf()/new O(e).valueOf())*new O(e).valueOf())}remainder(e){return O.bytes(this.valueOf()%new O(e).valueOf())}get gigabytes(){return this.valueOf()/O.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/O.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/O.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/O.TERABYTE.valueOf()}toString(){const e=this.truncate(O.TERABYTE),t=this.truncate(O.GIGABYTE),n=this.truncate(O.MEGABYTE),i=this.truncate(O.KILOBYTE),a=this.truncate(O.BYTE),o=e,c=t.sub(e),u=n.sub(t),l=i.sub(n),h=a.sub(i);let y="";return o.isZero||(y+=`${o.terabytes}TB `),c.isZero||(y+=`${c.gigabytes}GB `),u.isZero||(y+=`${u.megabytes}MB `),l.isZero||(y+=`${l.kilobytes}KB `),(!h.isZero||y==="")&&(y+=`${h.valueOf()}B`),y.trim()}static bytes(e=1){return new O(e)}static BYTE=new O(1);static kilobytes(e=1){return O.bytes(new O(e).valueOf()*1e3)}static KILOBYTE=O.kilobytes(1);static megabytes(e=1){return O.kilobytes(new O(e).valueOf()*1e3)}static MEGABYTE=O.megabytes(1);static gigabytes(e=1){return O.megabytes(new O(e).valueOf()*1e3)}static GIGABYTE=O.gigabytes(1);static terabytes(e){return O.gigabytes(new O(e).valueOf()*1e3)}static TERABYTE=O.terabytes(1);static ZERO=new O(0);static z=s.z.union([s.z.number().transform(e=>new O(e)),s.z.instanceof(O)]);get isZero(){return this.valueOf()===0}};s.z.union([s.z.instanceof(Uint8Array),s.z.instanceof(Uint16Array),s.z.instanceof(Uint32Array),s.z.instanceof(BigUint64Array),s.z.instanceof(Float32Array),s.z.instanceof(Float64Array),s.z.instanceof(Int8Array),s.z.instanceof(Int16Array),s.z.instanceof(Int32Array),s.z.instanceof(BigInt64Array)]);const ri=r=>{const e=typeof r;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||r instanceof I||r instanceof A||r instanceof Date},Jc=(r,e,t,n=0)=>r.usesBigInt&&!e.usesBigInt?Number(t)-Number(n):!r.usesBigInt&&e.usesBigInt?BigInt(t.valueOf())-BigInt(n.valueOf()):Xt(t,-n),Xt=(r,e)=>e==0?r:r==0?e:typeof r=="bigint"&&typeof e=="bigint"||typeof r=="number"&&typeof e=="number"?r+e:Number(r)+Number(e),Xc=/^(?:[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 Qc(r){return typeof r=="string"&&Xc.test(r)}const q=[];for(let r=0;r<256;++r)q.push((r+256).toString(16).slice(1));function el(r,e=0){return(q[r[e+0]]+q[r[e+1]]+q[r[e+2]]+q[r[e+3]]+"-"+q[r[e+4]]+q[r[e+5]]+"-"+q[r[e+6]]+q[r[e+7]]+"-"+q[r[e+8]]+q[r[e+9]]+"-"+q[r[e+10]]+q[r[e+11]]+q[r[e+12]]+q[r[e+13]]+q[r[e+14]]+q[r[e+15]]).toLowerCase()}function tl(r,e=0){const t=el(r,e);if(!Qc(t))throw TypeError("Stringified UUID is invalid");return t}typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const ni=(r,e)=>tl(r,e),Ee=-1,rl=s.z.string().transform(r=>new Uint8Array(atob(r).split("").map(e=>e.charCodeAt(0))).buffer),nl=s.z.union([s.z.null(),s.z.undefined()]).transform(()=>new Uint8Array().buffer),Qr=10,sl=(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`)},si="sy_x_telem_series";let ii=class Se{key;discriminator=si;dataType;sampleOffset;gl;_data;timeRange=dt.ZERO;alignment=0n;alignmentMultiple=1n;cachedMin;cachedMax;writePos=Ee;_refCount=0;cachedLength;_cachedIndexes;static crudeZ=s.z.object({timeRange:dt.z.optional(),dataType:U.z,alignment:s.z.coerce.bigint().optional(),data:s.z.union([rl,nl,s.z.instanceof(ArrayBuffer),s.z.instanceof(Uint8Array)]),glBufferUsage:Gc.optional().default("static").optional()});static z=Se.crudeZ.transform(e=>new Se(e));constructor(e){il(e)&&(e={data:e}),e.data??=[];const{dataType:t,timeRange:n,sampleOffset:i=0,glBufferUsage:a="static",alignment:o=0n,alignmentMultiple:c=1n,key:u=_c(),data:l}=e;if(al(l)){const d=l;this.key=d.key,this.dataType=d.dataType,this.sampleOffset=d.sampleOffset,this.gl=d.gl,this._data=d._data,this.timeRange=d.timeRange,this.alignment=d.alignment,this.alignmentMultiple=d.alignmentMultiple,this.cachedMin=d.cachedMin,this.cachedMax=d.cachedMax,this.writePos=d.writePos,this._refCount=d._refCount,this.cachedLength=d.cachedLength;return}const h=ri(l),y=Array.isArray(l);if(t!=null)this.dataType=new U(t);else{if(l instanceof ArrayBuffer)throw new Error("cannot infer data type from an ArrayBuffer instance when constructing a Series. Please provide a data type.");if(y||h){let d=l;if(!h){if(l.length===0)throw new Error("cannot infer data type from a zero length JS array when constructing a Series. Please provide a data type.");d=l[0]}if(typeof d=="string")this.dataType=U.STRING;else if(typeof d=="number")this.dataType=U.FLOAT64;else if(typeof d=="bigint")this.dataType=U.INT64;else if(typeof d=="boolean")this.dataType=U.BOOLEAN;else if(d instanceof I||d instanceof Date||d instanceof I)this.dataType=U.TIMESTAMP;else if(typeof d=="object")this.dataType=U.JSON;else throw new Error(`cannot infer data type of ${typeof d} when constructing a Series from a JS array`)}else this.dataType=new U(l)}if(!y&&!h)this._data=l;else if(y&&l.length===0)this._data=new this.dataType.Array([]).buffer;else{let d=h?[l]:l;const N=d[0];(N instanceof I||N instanceof Date||N instanceof A)&&(d=d.map(S=>new I(S).valueOf())),this.dataType.equals(U.STRING)?(this.cachedLength=d.length,this._data=new TextEncoder().encode(`${d.join(`
|
|
2
2
|
`)}
|
|
3
3
|
`).buffer):this.dataType.equals(U.JSON)?(this.cachedLength=d.length,this._data=new TextEncoder().encode(`${d.map(S=>Jr.encodeString(S)).join(`
|
|
4
4
|
`)}
|
|
5
5
|
`).buffer):this.dataType.usesBigInt&&typeof N=="number"?this._data=new this.dataType.Array(d.map(S=>BigInt(Math.round(S)))).buffer:!this.dataType.usesBigInt&&typeof N=="bigint"?this._data=new this.dataType.Array(d.map(Number)).buffer:this._data=new this.dataType.Array(d).buffer}this.key=u,this.alignment=o,this.alignmentMultiple=c,this.sampleOffset=i??0,this.timeRange=n??dt.ZERO,this.gl={control:null,buffer:null,prevBuffer:0,bufferUsage:a}}static alloc({capacity:e,dataType:t,...n}){if(e===0)throw new Error("[Series] - cannot allocate an array of length 0");const i=new new U(t).Array(e),a=new Se({data:i.buffer,dataType:t,...n});return a.writePos=0,a}get refCount(){return this._refCount}acquire(e){this._refCount++,e!=null&&this.updateGLBuffer(e)}release(){this._refCount--,this.refCount===0&&this.gl.control!=null?this.maybeGarbageCollectGLBuffer(this.gl.control):this.refCount<0&&console.warn("cannot release a series with a negative reference count")}write(e){if(!e.dataType.equals(this.dataType))throw new Error("buffer must be of the same type as this array");return this.dataType.isVariable?this.writeVariable(e):this.writeFixed(e)}writeVariable(e){if(this.writePos===Ee)return 0;const t=this.byteCapacity.valueOf()-this.writePos,n=e.subBytes(0,t);return this.writeToUnderlyingData(n),this.writePos+=n.byteLength.valueOf(),this.cachedLength!=null&&(this.cachedLength+=n.length,this.calculateCachedLength()),n.length}writeFixed(e){if(this.writePos===Ee)return 0;const t=this.capacity-this.writePos,n=e.sub(0,t);return this.writeToUnderlyingData(n),this.cachedLength=void 0,this.maybeRecomputeMinMax(n),this.writePos+=n.length,n.length}writeToUnderlyingData(e){this.underlyingData.set(e.data,this.writePos)}get buffer(){return typeof this._data=="object"&&"buffer"in this._data?this._data.buffer:this._data}get underlyingData(){return new this.dataType.Array(this._data)}get data(){return this.writePos===Ee?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(U.JSON))throw new Error("cannot parse non-JSON series as JSON");return this.toStrings().map(t=>e.parse(Jr.decodeString(t)))}get byteCapacity(){return new Xr(this.underlyingData.byteLength)}get capacity(){return this.dataType.isVariable?this.byteCapacity.valueOf():this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===Ee?this.byteCapacity:this.dataType.isVariable?new Xr(this.writePos):this.dataType.density.size(this.writePos)}get length(){return this.cachedLength!=null?this.cachedLength:this.dataType.isVariable?this.calculateCachedLength():this.writePos===Ee?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===Qr&&(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]=Kc(this.dataType,e,this.data[i],t);return new Se({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(U.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(),Xt(this.cachedMax,this.sampleOffset))}calcRawMin(){if(this.length===0)return 1/0;if(this.dataType.equals(U.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(),Xt(this.cachedMin,this.sampleOffset))}get bounds(){return De(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(U.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 Xt(n,this.sampleOffset)}atUUID(e,t){e<0&&(e=this.length+e);const n=ri(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 o=0;o<this.data.length;o++)if(this.data[o]===Qr){if(e===0){i=o;break}n=o+1,e--}if(i===0&&(i=this.data.length),n>=i||e>0){if(t)throw new Error(`[series] - no value at index ${e}`);return}}const a=this.data.slice(n,i);return this.dataType.equals(U.STRING)?new TextDecoder().decode(a):Ys(JSON.parse(new TextDecoder().decode(a)))}binarySearch(e){let t=0,n=this.length-1;const i=dc(e);for(;t<=n;){const a=Math.floor((t+n)/2),o=i(this.at(a,!0),e);if(o===0)return a;o<0?t=a+1:n=a-1}return t}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals(U.FLOAT32)&&!this.dataType.equals(U.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!==Ee){i===0&&e.bufferData(e.ARRAY_BUFFER,this.byteCapacity.valueOf(),e.STATIC_DRAW);const a=this.dataType.density.size(i).valueOf(),o=this.underlyingData.slice(this.gl.prevBuffer,this.writePos);e.bufferSubData(e.ARRAY_BUFFER,a,o.buffer),this.gl.prevBuffer=this.writePos}else e.bufferData(e.ARRAY_BUFFER,this.buffer,n==="static"?e.STATIC_DRAW:e.DYNAMIC_DRAW),this.gl.prevBuffer=Ee}as(e){return nl(e,this.dataType),this}get digest(){return{key:this.key,dataType:this.dataType.toString(),sampleOffset:this.sampleOffset,alignment:{lower:us(this.alignmentBounds.lower),upper:us(this.alignmentBounds.upper),multiple:this.alignmentMultiple},timeRange:this.timeRange.toString(),length:this.length,capacity:this.capacity}}get alignmentBounds(){return De(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 al(this);return this.dataType.equals(U.JSON)?new ol(e):e}return this.dataType.equals(U.UUID)?new cl(this):new ll(this)}slice(e,t){return this.sliceSub(!1,e,t)}sub(e,t){return this.sliceSub(!0,e,t)}subIterator(e,t){return new ls(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 ls(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 Se({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 Se({data:i,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(t)})}reAlign(e){return new Se({data:this.buffer,dataType:this.dataType,timeRange:dt.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 sl=r=>r==null?!1:Array.isArray(r)||r instanceof ArrayBuffer||ArrayBuffer.isView(r)&&!(r instanceof DataView)||r instanceof si?!0:ti(r),il=_c(ni,si);let ls=class{series;end;index;constructor(r,e,t){this.series=r;const n=De(0,r.length+1);this.end=is(n,t),this.index=is(n,e)}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}};class al{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]!==Qr;)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))})}}let ol=class ii{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:Jr.decodeString(e.value,ii.schema)}}},cl=class{series;index;data;density;constructor(r){if(!r.dataType.equals(U.UUID))throw new Error("cannot create a UUID series iterator for a non-UUID series");this.series=r,this.index=0,this.data=new Uint8Array(r.buffer),this.density=U.UUID.density.valueOf()}next(){if(this.index>=this.series.length)return{done:!0,value:void 0};const r=ri(this.data,this.index*this.density);return this.index++,{done:!1,value:r}}};class ll{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 us=r=>{const e=r>>32n,t=r&0xffffffffn;return{domain:e,sample:t}};s.z.object({key:s.z.string(),value:s.z.string()});s.z.record(s.z.union([s.z.number(),s.z.string(),s.z.symbol()]),s.z.unknown());const ul=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser";ul();const hl=["macOS","Windows","Linux"],fl=["macos","windows","linux"],dl={macos:"macOS",windows:"Windows",linux:"Linux"};s.z.enum(hl).or(s.z.enum(fl).transform(r=>dl[r]));const yl=(...r)=>r.map(ai).join(""),ai=r=>(r.endsWith("/")||(r+="/"),r.startsWith("/")&&(r=r.slice(1)),r),gl=r=>r.endsWith("/")?r.slice(0,-1):r,pl=(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("&")}`;let ml=class Qt{protocol;host;port;path;constructor({host:e,port:t,protocol:n="",pathPrefix:i=""}){this.protocol=n,this.host=e,this.port=t,this.path=ai(i)}replace(e){return new Qt({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new Qt({...this,pathPrefix:yl(this.path,e)})}toString(){return gl(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}static UNKNOWN=new Qt({host:"unknown",port:0})};const wl=async r=>await new Promise(e=>setTimeout(e,A.fromMilliseconds(r).milliseconds));class bl{config;retries;interval;constructor(e){this.config={baseInterval:new A(e?.baseInterval??A.seconds(1)),maxRetries:e?.maxRetries??5,scale:e?.scale??1,sleepFn:e?.sleepFn??wl},this.retries=0,this.interval=new A(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 Tl=s.z.object({baseInterval:A.z.optional(),maxRetries:s.z.number().optional(),scale:s.z.number().optional()}),vl=Object.freeze(Object.defineProperty({__proto__:null,Breaker:bl,breakerConfigZ:Tl},Symbol.toStringTag,{value:"Module"})),El=/^#?([0-9a-f]{6}|[0-9a-f]{8})$/i,oi=s.z.string().regex(El),Ke=s.z.number().min(0).max(255),ci=s.z.number().min(0).max(1),li=s.z.tuple([Ke,Ke,Ke,ci]),Nl=s.z.tuple([Ke,Ke,Ke]),Ol=s.z.object({rgba255:li}),zl=s.z.number().min(0).max(360),Sl=s.z.number().min(0).max(100),Al=s.z.number().min(0).max(100),$l=s.z.tuple([zl,Sl,Al,ci]),Nn=s.z.union([oi,Nl,li,$l,Ol]),Il=Nn.transform(r=>On(r)),On=(r,e=1)=>{if(r=Nn.parse(r),typeof r=="string")return kl(r,e);if(Array.isArray(r)){if(r.length<3||r.length>4)throw new Error(`Invalid color: [${r.join(", ")}]`);return r.length===3?[...r,e]:r}return r.rgba255},kl=(r,e=1)=>(r=oi.parse(r),r=xl(r),[Wt(r,0),Wt(r,2),Wt(r,4),r.length===8?Wt(r,6)/255:e]),Wt=(r,e)=>parseInt(r.slice(e,e+2),16),xl=r=>r.startsWith("#")?r.slice(1):r;On("#000000");On("#ffffff");const Cl=s.z.object({key:s.z.string(),color:Nn,position:s.z.number(),switched:s.z.boolean().optional()});s.z.array(Cl);const Rl=s.z.object({key:s.z.string(),name:s.z.string(),color:Il});s.z.object({key:s.z.string(),name:s.z.string(),swatches:s.z.array(Rl)});s.z.int().min(0).max(255);s.z.object({name:s.z.string(),key:s.z.string()});const jl=r=>Object.getOwnPropertySymbols(globalThis).includes(r),Ml=(r,e)=>{const t=Symbol.for(r);if(!jl(t)){const n=e();Object.defineProperty(globalThis,t,{value:n})}return()=>globalThis[t]},ui="sy_x_error",Ul=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),Rt=r=>class yt extends Error{static discriminator=ui;discriminator=yt.discriminator;static TYPE=r;type=yt.TYPE;static matches=Ul(r);matches=yt.matches;constructor(t,n){super(t,n),this.name=yt.TYPE}static sub(t){return Rt(`${r}.${t}`)}},hi=r=>{if(r==null||typeof r!="object")return!1;const e=r;if(e.discriminator!==ui)return!1;if(!("type"in e))throw new Error(`X Error is missing its type property: ${JSON.stringify(e)}`);return!0},He="unknown",en="nil";class Dl{providers=[];register(e){this.providers.push(e)}encode(e){if(e==null)return{type:en,data:""};if(hi(e))for(const t of this.providers){const n=t.encode(e);if(n!=null)return n}if(e instanceof Error)return{type:He,data:e.message};if(typeof e=="string")return{type:He,data:e};try{return{type:He,data:JSON.stringify(e)}}catch{return{type:He,data:"unable to encode error information"}}}decode(e){if(e==null||e.type===en)return null;if(e.type===He)return new tn(e.data);for(const t of this.providers){const n=t.decode(e);if(n!=null)return n}return new tn(e.data)}}const zn=Ml("synnax-error-registry",()=>new Dl),Zl=({encode:r,decode:e})=>zn().register({encode:r,decode:e}),Pl=r=>zn().encode(r),Ll=r=>r==null?null:zn().decode(r);let tn=class extends Rt("unknown"){};const Bl=s.z.object({type:s.z.string(),data:s.z.string()});class ql extends Rt("canceled"){}class Fl extends Rt("not_implemented"){}const $e=Object.freeze(Object.defineProperty({__proto__:null,Canceled:ql,NONE:en,NotImplemented:Fl,UNKNOWN:He,Unknown:tn,createTyped:Rt,decode:Ll,encode:Pl,isTyped:hi,payloadZ:Bl,register:Zl},Symbol.toStringTag,{value:"Module"})),Yl=s.object({jsonrpc:s.literal("2.0"),method:s.string(),params:s.any().optional(),id:s.union([s.string(),s.number(),s.null()]).optional()}),fi=s.object({jsonrpc:s.literal("2.0"),id:s.union([s.string(),s.number(),s.null()])}),Vl=fi.extend({result:s.json()}),Hl=fi.extend({error:s.object({code:s.number().int(),message:s.string().optional(),data:s.json().optional()})}),_l=s.union([Vl,Hl]);s.union([Yl,_l]);s.z.string().regex(/^\d+\.\d+\.\d+$/);const Wl=["standard","scientific","engineering"];s.z.enum(Wl);s.z.enum(["success","info","warning","error","loading","disabled"]);let jt=class extends $e.createTyped("freighter"){},ie=class extends jt.sub("eof"){constructor(){super("EOF")}},Qe=class extends jt.sub("stream_closed"){constructor(){super("StreamClosed")}},Ie=class extends jt.sub("unreachable"){url;constructor(e={}){const{message:t="Unreachable",url:n=ml.UNKNOWN}=e;super(t),this.url=n}};const Gl=r=>{if(!r.type.startsWith(jt.TYPE))return null;if(ie.matches(r))return{type:ie.TYPE,data:"EOF"};if(Qe.matches(r))return{type:Qe.TYPE,data:"StreamClosed"};if(Ie.matches(r))return{type:Ie.TYPE,data:"Unreachable"};throw new Error(`Unknown error type: ${r.type}: ${r.message}`)},Kl=r=>{if(!r.type.startsWith(jt.TYPE))return null;switch(r.type){case ie.TYPE:return new ie;case Qe.TYPE:return new Qe;case Ie.TYPE:return new Ie;default:throw new $e.Unknown(`Unknown error type: ${r.data}`)}};$e.register({encode:Gl,decode:Kl});class di{middleware=[];use(...e){this.middleware.push(...e)}async executeMiddleware(e,t){let n=0;const i=async a=>{if(n===this.middleware.length)return await t(a);const o=this.middleware[n];return n++,await o(a,i)};return await i(e)}}const yi="Content-Type",Jl=new Set(["ECONNREFUSED","ECONNRESET","ETIMEDOUT","EPIPE","UND_ERR_CONNECT_TIMEOUT","UND_ERR_SOCKET"]),Xl=r=>{const e=r?.cause?.code??r?.code??r?.errno;if(typeof e=="string"&&Jl.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!0}return r?.name==="AbortError"||r?.code,!1},Ql=400;class eu extends di{endpoint;encoder;constructor(e,t,n=!1){return super(),this.endpoint=e.replace({protocol:n?"https":"http"}),this.encoder=t,new Proxy(this,{get:(i,a,o)=>a==="endpoint"?this.endpoint:Reflect.get(i,a,o)})}get headers(){return{[yi]:this.encoder.contentType}}async send(e,t,n,i){t=n?.parse(t);let a=null;const o=this.endpoint.child(e),c={};c.method="POST",c.body=this.encoder.encode(t??{});const[,u]=await this.executeMiddleware({target:o.toString(),protocol:this.endpoint.protocol,params:{},role:"client"},async l=>{const h={...l,params:{}};c.headers={...this.headers,...l.params};let y;try{y=await fetch(l.target,c)}catch(N){if(!(N instanceof Error))throw N;return[h,Xl(N)?new Ie({url:o}):N]}const d=await y.arrayBuffer();if(y?.ok)return i!=null&&(a=this.encoder.decode(d,i)),[h,null];try{if(y.status!==Ql)return[h,new Error(y.statusText)];const N=this.encoder.decode(d,$e.payloadZ),S=$e.decode(N);return[h,S]}catch(N){return[h,new Error(`[freighter] - failed to decode error: ${y.statusText}: ${N.message}`)]}});if(u!=null)return[null,u];if(a==null)throw new Error("Response must be defined");return[a,null]}}const tu=(r,e)=>{class t{wrapped;constructor(i){this.wrapped=i}use(...i){this.wrapped.use(...i)}async send(i,a,o,c){const u=new vl.Breaker(e);do{const[l,h]=await this.wrapped.send(i,a,o,c);if(h==null)return[l,null];if(!Ie.matches(h))return[null,h];if(console.warn(`[freighter] ${u.retryMessage}`,h),!await u.wait())return[l,h]}while(!0)}}return new t(r)},m=async(r,e,t,n,i)=>{const[a,o]=await r.send(e,t,n,i);if(o!=null)throw o;return a},ru=s.z.object({type:s.z.enum(["data","close","open"]),payload:s.z.unknown(),error:s.z.optional($e.payloadZ)});class nu{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 $e.decode(e.error)}return null}send(e){if(this.serverClosed!=null)return new ie;if(this.sendClosed)throw new Qe;return this.ws.send(this.codec.encode({type:"data",payload:e})),null}async receive(){if(this.serverClosed!=null)return[null,this.serverClosed];const e=await this.receiveMsg();if(e.type==="close"){if(e.error==null)throw new Error("Message error must be defined");if(this.serverClosed=$e.decode(e.error),this.serverClosed==null)throw new Error("Message error must be defined");return[null,this.serverClosed]}return[this.resSchema.parse(e.payload),null]}received(){return this.receiveDataQueue.length!==0}closeSend(){if(this.sendClosed||this.serverClosed!=null)return;const e={type:"close"};try{this.ws.send(this.codec.encode(e))}finally{this.sendClosed=!0}}async receiveMsg(){return this.receiveDataQueue.shift()??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,ru))}onClose(e){this.addMessage({type:"close",error:{type:e.code===iu?ie.TYPE:Qe.TYPE,data:""}})}}const su="freighterctx",iu=1e3;class ar extends di{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 ar(this.baseUrl,e,this.secure);return t.use(...this.middleware),t}async stream(e,t,n){let i;const[,a]=await this.executeMiddleware({target:e,protocol:"websocket",params:{},role:"client"},async o=>{const c=new WebSocket(this.buildURL(e,o)),u={...o,params:{}};c.binaryType=ar.MESSAGE_TYPE;const l=await this.wrapSocket(c,t,n);return l instanceof Error?[u,l]:(i=l,[u,null])});if(a!=null)throw a;return i}buildURL(e,t){const n=pl({[yi]:this.encoder.contentType,...t.params},su);return this.baseUrl.child(e).toString()+n}async wrapSocket(e,t,n){return await new Promise(i=>{e.onopen=()=>{const a=new nu(e,this.encoder,t,n);a.receiveOpenAck().then(o=>{o!=null?i(o):i(a)}).catch(o=>i(o))},e.onerror=a=>{const o=a;i(new Error(o.message))}})}}const au=r=>Array.isArray(r)?r:r==null?[]:[r],v=Object.freeze(Object.defineProperty({__proto__:null,toArray:au},Symbol.toStringTag,{value:"Module"})),ou=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)},gr=r=>{const e=(t,n=rn)=>{if(typeof t=="string")return r(t);if(Array.isArray(t))return t.map(o=>e(o,n));if(!Dr(t))return t;n=uu(n);const i={},a=t;return"toJSON"in a&&typeof a.toJSON=="function"?e(a.toJSON(),n):(Object.keys(a).forEach(o=>{let c=a[o];const u=r(o);n.recursive&&(Dr(c)?fs(c)||(c=e(c,n)):n.recursiveInArray&&hs(c)&&(c=[...c].map(l=>{let h=l;return Dr(l)?fs(h)||(h=e(l,n)):hs(l)&&(h=e({key:l},n).key),h}))),i[u]=c}),i)};return e},Sn=gr(ou),cu=r=>r.replace(/([a-z0-9])([A-Z])/g,(e,t,n)=>`${t}_${n.toLowerCase()}`),gi=gr(cu),pi=r=>r.length===0?r:r[0].toUpperCase()+r.slice(1),lu=[Number,String,Uint8Array],rn={recursive:!0,recursiveInArray:!0},uu=(r=rn)=>(r.recursive==null?r=rn:r.recursiveInArray??=!1,r),hs=r=>r!=null&&Array.isArray(r),Dr=r=>r!=null&&typeof r=="object"&&!Array.isArray(r),fs=r=>lu.some(e=>r instanceof e),hu=r=>r.replace(/\s+/g,"-").replace(/([a-z0-9])([A-Z])/g,(e,t,n)=>`${t}-${n.toLowerCase()}`).toLowerCase(),fu=gr(hu),du=r=>{if(r.length===0)return r;let e=r.replace(/[_-]/g," ");return e=e.replace(/([a-z0-9])([A-Z])/g,(t,n,i)=>`${n} ${i}`),e=e.replace(/([A-Z]+)([A-Z][a-z])/g,(t,n,i)=>`${n} ${i}`),e=e.replace(/\s+/g," ").trim(),e=e.replace(/\b\w/g,t=>t.toUpperCase()),e},yu=gr(du),gu=Object.freeze(Object.defineProperty({__proto__:null,camelToSnake:gi,capitalize:pi,snakeToCamel:Sn,toKebab:fu,toProperNoun:yu},Symbol.toStringTag,{value:"Module"})),mi=r=>r!=null&&typeof r=="object"&&!Array.isArray(r);let wi=class{contentType="application/json";decoder;encoder;constructor(){this.decoder=new TextDecoder,this.encoder=new TextEncoder}encode(e){return this.encoder.encode(this.encodeString(e))}decode(e,t){return this.decodeString(this.decoder.decode(e),t)}decodeString(e,t){const n=JSON.parse(e),i=Sn(n);return t!=null?t.parse(i):i}encodeString(e){const t=gi(e);return JSON.stringify(t,(n,i)=>ArrayBuffer.isView(i)?Array.from(i):typeof i=="bigint"?i.toString():i)}},bi=class{contentType="text/csv";encode(e){const t=this.encodeString(e);return new TextEncoder().encode(t)}decode(e,t){const n=new TextDecoder().decode(e);return this.decodeString(n,t)}encodeString(e){if(!Array.isArray(e)||e.length===0||!mi(e[0]))throw new Error("Payload must be an array of objects");const t=Object.keys(e[0]),n=[t.join(",")];return e.forEach(i=>{const a=t.map(o=>JSON.stringify(i[o]??""));n.push(a.join(","))}),n.join(`
|
|
6
|
+
`).slice(0,-1):Array.from(this).map(e=>e.toString())}parseJSON(e){if(!this.dataType.equals(U.JSON))throw new Error("cannot parse non-JSON series as JSON");return this.toStrings().map(t=>e.parse(Jr.decodeString(t)))}get byteCapacity(){return new Xr(this.underlyingData.byteLength)}get capacity(){return this.dataType.isVariable?this.byteCapacity.valueOf():this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===Ee?this.byteCapacity:this.dataType.isVariable?new Xr(this.writePos):this.dataType.density.size(this.writePos)}get length(){return this.cachedLength!=null?this.cachedLength:this.dataType.isVariable?this.calculateCachedLength():this.writePos===Ee?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===Qr&&(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]=Jc(this.dataType,e,this.data[i],t);return new Se({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(U.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(),Xt(this.cachedMax,this.sampleOffset))}calcRawMin(){if(this.length===0)return 1/0;if(this.dataType.equals(U.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(),Xt(this.cachedMin,this.sampleOffset))}get bounds(){return De(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(U.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 Xt(n,this.sampleOffset)}atUUID(e,t){e<0&&(e=this.length+e);const n=ni(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 o=0;o<this.data.length;o++)if(this.data[o]===Qr){if(e===0){i=o;break}n=o+1,e--}if(i===0&&(i=this.data.length),n>=i||e>0){if(t)throw new Error(`[series] - no value at index ${e}`);return}}const a=this.data.slice(n,i);return this.dataType.equals(U.STRING)?new TextDecoder().decode(a):Vs(JSON.parse(new TextDecoder().decode(a)))}binarySearch(e){let t=0,n=this.length-1;const i=yc(e);for(;t<=n;){const a=Math.floor((t+n)/2),o=i(this.at(a,!0),e);if(o===0)return a;o<0?t=a+1:n=a-1}return t}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals(U.FLOAT32)&&!this.dataType.equals(U.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!==Ee){i===0&&e.bufferData(e.ARRAY_BUFFER,this.byteCapacity.valueOf(),e.STATIC_DRAW);const a=this.dataType.density.size(i).valueOf(),o=this.underlyingData.slice(this.gl.prevBuffer,this.writePos);e.bufferSubData(e.ARRAY_BUFFER,a,o.buffer),this.gl.prevBuffer=this.writePos}else e.bufferData(e.ARRAY_BUFFER,this.buffer,n==="static"?e.STATIC_DRAW:e.DYNAMIC_DRAW),this.gl.prevBuffer=Ee}as(e){return sl(e,this.dataType),this}get digest(){return{key:this.key,dataType:this.dataType.toString(),sampleOffset:this.sampleOffset,alignment:{lower:hs(this.alignmentBounds.lower),upper:hs(this.alignmentBounds.upper),multiple:this.alignmentMultiple},timeRange:this.timeRange.toString(),length:this.length,capacity:this.capacity}}get alignmentBounds(){return De(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 ol(this);return this.dataType.equals(U.JSON)?new cl(e):e}return this.dataType.equals(U.UUID)?new ll(this):new ul(this)}slice(e,t){return this.sliceSub(!1,e,t)}sub(e,t){return this.sliceSub(!0,e,t)}subIterator(e,t){return new us(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 us(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 Se({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 Se({data:i,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(t)})}reAlign(e){return new Se({data:this.buffer,dataType:this.dataType,timeRange:dt.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 il=r=>r==null?!1:Array.isArray(r)||r instanceof ArrayBuffer||ArrayBuffer.isView(r)&&!(r instanceof DataView)||r instanceof ii?!0:ri(r),al=Wc(si,ii);let us=class{series;end;index;constructor(r,e,t){this.series=r;const n=De(0,r.length+1);this.end=as(n,t),this.index=as(n,e)}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}};class ol{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]!==Qr;)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))})}}let cl=class ai{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:Jr.decodeString(e.value,ai.schema)}}},ll=class{series;index;data;density;constructor(r){if(!r.dataType.equals(U.UUID))throw new Error("cannot create a UUID series iterator for a non-UUID series");this.series=r,this.index=0,this.data=new Uint8Array(r.buffer),this.density=U.UUID.density.valueOf()}next(){if(this.index>=this.series.length)return{done:!0,value:void 0};const r=ni(this.data,this.index*this.density);return this.index++,{done:!1,value:r}}};class ul{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 hs=r=>{const e=r>>32n,t=r&0xffffffffn;return{domain:e,sample:t}};s.z.object({key:s.z.string(),value:s.z.string()});s.z.record(s.z.union([s.z.number(),s.z.string(),s.z.symbol()]),s.z.unknown());const hl=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser";hl();const fl=["macOS","Windows","Linux"],dl=["macos","windows","linux"],yl={macos:"macOS",windows:"Windows",linux:"Linux"};s.z.enum(fl).or(s.z.enum(dl).transform(r=>yl[r]));const gl=(...r)=>r.map(oi).join(""),oi=r=>(r.endsWith("/")||(r+="/"),r.startsWith("/")&&(r=r.slice(1)),r),pl=r=>r.endsWith("/")?r.slice(0,-1):r,ml=(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("&")}`;let wl=class Qt{protocol;host;port;path;constructor({host:e,port:t,protocol:n="",pathPrefix:i=""}){this.protocol=n,this.host=e,this.port=t,this.path=oi(i)}replace(e){return new Qt({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new Qt({...this,pathPrefix:gl(this.path,e)})}toString(){return pl(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}static UNKNOWN=new Qt({host:"unknown",port:0})};const bl=async r=>await new Promise(e=>setTimeout(e,A.fromMilliseconds(r).milliseconds));class Tl{config;retries;interval;constructor(e){this.config={baseInterval:new A(e?.baseInterval??A.seconds(1)),maxRetries:e?.maxRetries??5,scale:e?.scale??1,sleepFn:e?.sleepFn??bl},this.retries=0,this.interval=new A(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 vl=s.z.object({baseInterval:A.z.optional(),maxRetries:s.z.number().optional(),scale:s.z.number().optional()}),El=Object.freeze(Object.defineProperty({__proto__:null,Breaker:Tl,breakerConfigZ:vl},Symbol.toStringTag,{value:"Module"})),Nl=/^#?([0-9a-f]{6}|[0-9a-f]{8})$/i,ci=s.z.string().regex(Nl),Ke=s.z.number().min(0).max(255),li=s.z.number().min(0).max(1),ui=s.z.tuple([Ke,Ke,Ke,li]),Ol=s.z.tuple([Ke,Ke,Ke]),zl=s.z.object({rgba255:ui}),Sl=s.z.number().min(0).max(360),Al=s.z.number().min(0).max(100),$l=s.z.number().min(0).max(100),Il=s.z.tuple([Sl,Al,$l,li]),On=s.z.union([ci,Ol,ui,Il,zl]),kl=On.transform(r=>zn(r)),zn=(r,e=1)=>{if(r=On.parse(r),typeof r=="string")return xl(r,e);if(Array.isArray(r)){if(r.length<3||r.length>4)throw new Error(`Invalid color: [${r.join(", ")}]`);return r.length===3?[...r,e]:r}return r.rgba255},xl=(r,e=1)=>(r=ci.parse(r),r=Cl(r),[Wt(r,0),Wt(r,2),Wt(r,4),r.length===8?Wt(r,6)/255:e]),Wt=(r,e)=>parseInt(r.slice(e,e+2),16),Cl=r=>r.startsWith("#")?r.slice(1):r;zn("#000000");zn("#ffffff");const Rl=s.z.object({key:s.z.string(),color:On,position:s.z.number(),switched:s.z.boolean().optional()});s.z.array(Rl);const jl=s.z.object({key:s.z.string(),name:s.z.string(),color:kl});s.z.object({key:s.z.string(),name:s.z.string(),swatches:s.z.array(jl)});s.z.int().min(0).max(255);s.z.object({name:s.z.string(),key:s.z.string()});const Ml=r=>Object.getOwnPropertySymbols(globalThis).includes(r),Ul=(r,e)=>{const t=Symbol.for(r);if(!Ml(t)){const n=e();Object.defineProperty(globalThis,t,{value:n})}return()=>globalThis[t]},hi="sy_x_error",Dl=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),Rt=r=>class yt extends Error{static discriminator=hi;discriminator=yt.discriminator;static TYPE=r;type=yt.TYPE;static matches=Dl(r);matches=yt.matches;constructor(t,n){super(t,n),this.name=yt.TYPE}static sub(t){return Rt(`${r}.${t}`)}},fi=r=>{if(r==null||typeof r!="object")return!1;const e=r;if(e.discriminator!==hi)return!1;if(!("type"in e))throw new Error(`X Error is missing its type property: ${JSON.stringify(e)}`);return!0},He="unknown",en="nil";class Zl{providers=[];register(e){this.providers.push(e)}encode(e){if(e==null)return{type:en,data:""};if(fi(e))for(const t of this.providers){const n=t.encode(e);if(n!=null)return n}if(e instanceof Error)return{type:He,data:e.message};if(typeof e=="string")return{type:He,data:e};try{return{type:He,data:JSON.stringify(e)}}catch{return{type:He,data:"unable to encode error information"}}}decode(e){if(e==null||e.type===en)return null;if(e.type===He)return new tn(e.data);for(const t of this.providers){const n=t.decode(e);if(n!=null)return n}return new tn(e.data)}}const Sn=Ul("synnax-error-registry",()=>new Zl),Pl=({encode:r,decode:e})=>Sn().register({encode:r,decode:e}),Ll=r=>Sn().encode(r),Bl=r=>r==null?null:Sn().decode(r);let tn=class extends Rt("unknown"){};const ql=s.z.object({type:s.z.string(),data:s.z.string()});class Fl extends Rt("canceled"){}class Yl extends Rt("not_implemented"){}const $e=Object.freeze(Object.defineProperty({__proto__:null,Canceled:Fl,NONE:en,NotImplemented:Yl,UNKNOWN:He,Unknown:tn,createTyped:Rt,decode:Bl,encode:Ll,isTyped:fi,payloadZ:ql,register:Pl},Symbol.toStringTag,{value:"Module"})),Vl=s.object({jsonrpc:s.literal("2.0"),method:s.string(),params:s.any().optional(),id:s.union([s.string(),s.number(),s.null()]).optional()}),di=s.object({jsonrpc:s.literal("2.0"),id:s.union([s.string(),s.number(),s.null()])}),Hl=di.extend({result:s.json()}),_l=di.extend({error:s.object({code:s.number().int(),message:s.string().optional(),data:s.json().optional()})}),Wl=s.union([Hl,_l]);s.union([Vl,Wl]);s.z.string().regex(/^\d+\.\d+\.\d+$/);const Gl=["standard","scientific","engineering"];s.z.enum(Gl);s.z.enum(["success","info","warning","error","loading","disabled"]);let jt=class extends $e.createTyped("freighter"){},ie=class extends jt.sub("eof"){constructor(){super("EOF")}},Qe=class extends jt.sub("stream_closed"){constructor(){super("StreamClosed")}},Ie=class extends jt.sub("unreachable"){url;constructor(e={}){const{message:t="Unreachable",url:n=wl.UNKNOWN}=e;super(t),this.url=n}};const Kl=r=>{if(!r.type.startsWith(jt.TYPE))return null;if(ie.matches(r))return{type:ie.TYPE,data:"EOF"};if(Qe.matches(r))return{type:Qe.TYPE,data:"StreamClosed"};if(Ie.matches(r))return{type:Ie.TYPE,data:"Unreachable"};throw new Error(`Unknown error type: ${r.type}: ${r.message}`)},Jl=r=>{if(!r.type.startsWith(jt.TYPE))return null;switch(r.type){case ie.TYPE:return new ie;case Qe.TYPE:return new Qe;case Ie.TYPE:return new Ie;default:throw new $e.Unknown(`Unknown error type: ${r.data}`)}};$e.register({encode:Kl,decode:Jl});class yi{middleware=[];use(...e){this.middleware.push(...e)}async executeMiddleware(e,t){let n=0;const i=async a=>{if(n===this.middleware.length)return await t(a);const o=this.middleware[n];return n++,await o(a,i)};return await i(e)}}const gi="Content-Type",Xl=new Set(["ECONNREFUSED","ECONNRESET","ETIMEDOUT","EPIPE","UND_ERR_CONNECT_TIMEOUT","UND_ERR_SOCKET"]),Ql=r=>{const e=r?.cause?.code??r?.code??r?.errno;if(typeof e=="string"&&Xl.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!0}return r?.name==="AbortError"||r?.code,!1},eu=400;class tu extends yi{endpoint;encoder;constructor(e,t,n=!1){return super(),this.endpoint=e.replace({protocol:n?"https":"http"}),this.encoder=t,new Proxy(this,{get:(i,a,o)=>a==="endpoint"?this.endpoint:Reflect.get(i,a,o)})}get headers(){return{[gi]:this.encoder.contentType}}async send(e,t,n,i){t=n?.parse(t);let a=null;const o=this.endpoint.child(e),c={};c.method="POST",c.body=this.encoder.encode(t??{});const[,u]=await this.executeMiddleware({target:o.toString(),protocol:this.endpoint.protocol,params:{},role:"client"},async l=>{const h={...l,params:{}};c.headers={...this.headers,...l.params};let y;try{y=await fetch(l.target,c)}catch(N){if(!(N instanceof Error))throw N;return[h,Ql(N)?new Ie({url:o}):N]}const d=await y.arrayBuffer();if(y?.ok)return i!=null&&(a=this.encoder.decode(d,i)),[h,null];try{if(y.status!==eu)return[h,new Error(y.statusText)];const N=this.encoder.decode(d,$e.payloadZ),S=$e.decode(N);return[h,S]}catch(N){return[h,new Error(`[freighter] - failed to decode error: ${y.statusText}: ${N.message}`)]}});if(u!=null)return[null,u];if(a==null)throw new Error("Response must be defined");return[a,null]}}const ru=(r,e)=>{class t{wrapped;constructor(i){this.wrapped=i}use(...i){this.wrapped.use(...i)}async send(i,a,o,c){const u=new El.Breaker(e);do{const[l,h]=await this.wrapped.send(i,a,o,c);if(h==null)return[l,null];if(!Ie.matches(h))return[null,h];if(console.warn(`[freighter] ${u.retryMessage}`,h),!await u.wait())return[l,h]}while(!0)}}return new t(r)},m=async(r,e,t,n,i)=>{const[a,o]=await r.send(e,t,n,i);if(o!=null)throw o;return a},nu=s.z.object({type:s.z.enum(["data","close","open"]),payload:s.z.unknown(),error:s.z.optional($e.payloadZ)});class su{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 $e.decode(e.error)}return null}send(e){if(this.serverClosed!=null)return new ie;if(this.sendClosed)throw new Qe;return this.ws.send(this.codec.encode({type:"data",payload:e})),null}async receive(){if(this.serverClosed!=null)return[null,this.serverClosed];const e=await this.receiveMsg();if(e.type==="close"){if(e.error==null)throw new Error("Message error must be defined");if(this.serverClosed=$e.decode(e.error),this.serverClosed==null)throw new Error("Message error must be defined");return[null,this.serverClosed]}return[this.resSchema.parse(e.payload),null]}received(){return this.receiveDataQueue.length!==0}closeSend(){if(this.sendClosed||this.serverClosed!=null)return;const e={type:"close"};try{this.ws.send(this.codec.encode(e))}finally{this.sendClosed=!0}}async receiveMsg(){return this.receiveDataQueue.shift()??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,nu))}onClose(e){this.addMessage({type:"close",error:{type:e.code===au?ie.TYPE:Qe.TYPE,data:""}})}}const iu="freighterctx",au=1e3;class ar extends yi{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 ar(this.baseUrl,e,this.secure);return t.use(...this.middleware),t}async stream(e,t,n){let i;const[,a]=await this.executeMiddleware({target:e,protocol:"websocket",params:{},role:"client"},async o=>{const c=new WebSocket(this.buildURL(e,o)),u={...o,params:{}};c.binaryType=ar.MESSAGE_TYPE;const l=await this.wrapSocket(c,t,n);return l instanceof Error?[u,l]:(i=l,[u,null])});if(a!=null)throw a;return i}buildURL(e,t){const n=ml({[gi]:this.encoder.contentType,...t.params},iu);return this.baseUrl.child(e).toString()+n}async wrapSocket(e,t,n){return await new Promise(i=>{e.onopen=()=>{const a=new su(e,this.encoder,t,n);a.receiveOpenAck().then(o=>{o!=null?i(o):i(a)}).catch(o=>i(o))},e.onerror=a=>{const o=a;i(new Error(o.message))}})}}const ou=r=>Array.isArray(r)?r:r==null?[]:[r],v=Object.freeze(Object.defineProperty({__proto__:null,toArray:ou},Symbol.toStringTag,{value:"Module"})),cu=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)},gr=r=>{const e=(t,n=rn)=>{if(typeof t=="string")return r(t);if(Array.isArray(t))return t.map(o=>e(o,n));if(!Dr(t))return t;n=hu(n);const i={},a=t;return"toJSON"in a&&typeof a.toJSON=="function"?e(a.toJSON(),n):(Object.keys(a).forEach(o=>{let c=a[o];const u=r(o);n.recursive&&(Dr(c)?ds(c)||(c=e(c,n)):n.recursiveInArray&&fs(c)&&(c=[...c].map(l=>{let h=l;return Dr(l)?ds(h)||(h=e(l,n)):fs(l)&&(h=e({key:l},n).key),h}))),i[u]=c}),i)};return e},An=gr(cu),lu=r=>r.replace(/([a-z0-9])([A-Z])/g,(e,t,n)=>`${t}_${n.toLowerCase()}`),pi=gr(lu),mi=r=>r.length===0?r:r[0].toUpperCase()+r.slice(1),uu=[Number,String,Uint8Array],rn={recursive:!0,recursiveInArray:!0},hu=(r=rn)=>(r.recursive==null?r=rn:r.recursiveInArray??=!1,r),fs=r=>r!=null&&Array.isArray(r),Dr=r=>r!=null&&typeof r=="object"&&!Array.isArray(r),ds=r=>uu.some(e=>r instanceof e),fu=r=>r.replace(/\s+/g,"-").replace(/([a-z0-9])([A-Z])/g,(e,t,n)=>`${t}-${n.toLowerCase()}`).toLowerCase(),du=gr(fu),yu=r=>{if(r.length===0)return r;let e=r.replace(/[_-]/g," ");return e=e.replace(/([a-z0-9])([A-Z])/g,(t,n,i)=>`${n} ${i}`),e=e.replace(/([A-Z]+)([A-Z][a-z])/g,(t,n,i)=>`${n} ${i}`),e=e.replace(/\s+/g," ").trim(),e=e.replace(/\b\w/g,t=>t.toUpperCase()),e},gu=gr(yu),pu=Object.freeze(Object.defineProperty({__proto__:null,camelToSnake:pi,capitalize:mi,snakeToCamel:An,toKebab:du,toProperNoun:gu},Symbol.toStringTag,{value:"Module"})),wi=r=>r!=null&&typeof r=="object"&&!Array.isArray(r);let bi=class{contentType="application/json";decoder;encoder;constructor(){this.decoder=new TextDecoder,this.encoder=new TextEncoder}encode(e){return this.encoder.encode(this.encodeString(e))}decode(e,t){return this.decodeString(this.decoder.decode(e),t)}decodeString(e,t){const n=JSON.parse(e),i=An(n);return t!=null?t.parse(i):i}encodeString(e){const t=pi(e);return JSON.stringify(t,(n,i)=>ArrayBuffer.isView(i)?Array.from(i):typeof i=="bigint"?i.toString():i)}},Ti=class{contentType="text/csv";encode(e){const t=this.encodeString(e);return new TextEncoder().encode(t)}decode(e,t){const n=new TextDecoder().decode(e);return this.decodeString(n,t)}encodeString(e){if(!Array.isArray(e)||e.length===0||!wi(e[0]))throw new Error("Payload must be an array of objects");const t=Object.keys(e[0]),n=[t.join(",")];return e.forEach(i=>{const a=t.map(o=>JSON.stringify(i[o]??""));n.push(a.join(","))}),n.join(`
|
|
7
7
|
`)}decodeString(e,t){const[n,...i]=e.trim().split(`
|
|
8
|
-
`).map(c=>c.trim());if(n.length===0)return t!=null?t.parse({}):{};const a=n.split(",").map(c=>c.trim()),o={};return a.forEach(c=>{o[c]=[]}),i.forEach(c=>{const u=c.split(",").map(l=>l.trim());a.forEach((l,h)=>{const y=this.parseValue(u[h]);y!=null&&o[l].push(y)})}),t!=null?t.parse(o):o}parseValue(e){if(e==null||e.length===0)return null;const t=Number(e);return isNaN(t)?e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e:t}},Ti=class{contentType="text/plain";encode(e){if(typeof e!="string")throw new Error("TextCodec.encode payload must be a string");return new TextEncoder().encode(e)}decode(e,t){const n=new TextDecoder().decode(e);return t!=null?t.parse(n):n}};const Tt=new wi,pu=new bi,mu=new Ti,wu=[Tt],Be=Object.freeze(Object.defineProperty({__proto__:null,CSVCodec:bi,CSV_CODEC:pu,ENCODERS:wu,JSONCodec:wi,JSON_CODEC:Tt,TEXT_CODEC:mu,TextCodec:Ti},Symbol.toStringTag,{value:"Module"})),nn=r=>[...new Set(r)],bu=(r,e,t=!0)=>{const n=new Map;return r.forEach(i=>{const a=e(i);if(n.has(a)){if(t)return;n.delete(a)}n.set(a,i)}),Array.from(n.values())},ds=Object.freeze(Object.defineProperty({__proto__:null,by:bu,unique:nn},Symbol.toStringTag,{value:"Module"})),Q=r=>r!=null&&typeof r=="object"&&"value"in r;let nt=class{value;constructor(e){this.value=e}valueOf(){return this.value}toJSON(){return this.value}toString(){return this.value.toString()}};const Tu=r=>r!=null&&typeof r=="object"&&"toString"in r,pr=(r,e=!1)=>{const t=Tu(r)?"stringer":typeof r;let n;switch(t){case"string":n=(i,a)=>i.localeCompare(a);break;case"stringer":n=(i,a)=>i.toString().localeCompare(a.toString());break;case"number":n=(i,a)=>Number(i)-Number(a);break;case"bigint":n=(i,a)=>BigInt(i)-BigInt(a)>0n?1:-1;break;case"boolean":n=(i,a)=>Number(i)-Number(a);break;case"undefined":n=()=>0;break;default:return console.warn(`sortFunc: unknown type ${t}`),()=>-1}return e?Ei(n):n},vu=(r,e,t)=>{const n=pr(e[r],t);return(i,a)=>n(i[r],a[r])},Eu=(r,e)=>r.length!==e.length?r.length-e.length:r.every((t,n)=>t===e[n])?0:-1,vi=(r,e)=>{if(r.length!==e.length)return r.length-e.length;if(r.length===0)return 0;const t=pr(r[0]),n=[...r].sort(t),i=[...e].sort(t);return n.every((a,o)=>a===i[o])?0:-1},Nu=(r,e)=>{const t=nn(r),n=nn(e);return vi(t,n)},Ou=(r,e)=>r===e?0:r==="first"&&e==="last"?1:-1,Ei=r=>(e,t)=>r(t,e),st=0,er=-1,tr=1,Ni=r=>r<st,Oi=r=>r>st,zu=r=>r>=st,zi=r=>r===st,Su=(r,e)=>{const t=/([a-zA-Z]+)|(\d+)/g,n=r.replace(/[\s_.-]+/g,"").match(t),i=e.replace(/[\s_.-]+/g,"").match(t);if(!n||!i)return 0;for(let a=0;a<Math.min(n.length,i.length);a++){const o=n[a],c=i[a];if(isNaN(Number(o))&&isNaN(Number(c))){const u=o.localeCompare(c);if(u!==0)return u}else if(!isNaN(Number(o))&&!isNaN(Number(c))){const u=Number(o)-Number(c);if(u!==0)return u}else return isNaN(Number(o))?-1:1}return n.length-i.length},ys=Object.freeze(Object.defineProperty({__proto__:null,EQUAL:st,GREATER_THAN:tr,LESS_THAN:er,isEqualTo:zi,isGreaterThan:Oi,isGreaterThanEqual:zu,isLessThan:Ni,newF:pr,newFieldF:vu,order:Ou,primitiveArrays:Eu,reverseF:Ei,stringsWithNumbers:Su,uniqueUnorderedPrimitiveArrays:Nu,unorderedPrimitiveArrays:vi},Symbol.toStringTag,{value:"Module"})),mr=s.z.tuple([s.z.number(),s.z.number()]);s.z.tuple([s.z.bigint(),s.z.bigint()]);const Si=s.z.object({width:s.z.number(),height:s.z.number()}),Au=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()}),$u=["width","height"];s.z.enum($u);const Iu=["start","center","end"],ku=["signedWidth","signedHeight"];s.z.enum(ku);const vt=s.z.object({x:s.z.number(),y:s.z.number()}),Ai=s.z.object({clientX:s.z.number(),clientY:s.z.number()}),$i=["x","y"],Ii=s.z.enum($i),An=["top","right","bottom","left"],xu=s.z.enum(An),ki=["left","right"],$n=s.z.enum(ki),xi=["top","bottom"],In=s.z.enum(xi),kn=["center"],sn=s.z.enum(kn),Cu=[...An,...kn],xn=s.z.enum(Cu);s.z.enum(Iu);const Ru=["first","last"];s.z.enum(Ru);const ju=s.z.object({lower:s.z.number(),upper:s.z.number()}),Mu=s.z.object({lower:s.z.bigint(),upper:s.z.bigint()});s.z.union([ju,mr]);s.z.union([Mu,mr]);s.z.enum([...Ii.options,...xn.options]);s.z.enum(["x","left","right"]);s.z.enum(["y","top","bottom"]);const Uu=s.z.union([Ii,xn,s.z.instanceof(String)]),Mt=r=>(e,t)=>{if(typeof e=="bigint"){if(an(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))},Ze=Mt((r,e)=>r-e),Ut=Mt((r,e)=>r+e),gs=(r,e)=>{const t=typeof r=="bigint",n=typeof e=="bigint";return t&&n?r===e:t&&an(e)?r===BigInt(e):n&&an(r)?e===BigInt(r):r===e},Du=Mt((r,e)=>r<=e?r:e),an=r=>typeof r=="bigint"?!0:Number.isInteger(r),Zu=r=>typeof r=="bigint"?r<0n?-r:r:r<0?-r:r,ue=Mt((r,e)=>r*e),wr=Mt((r,e)=>r/e),V=(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?Pu(n):n},Pu=r=>r.lower>r.upper?{lower:r.upper,upper:r.lower}:r,ps=(r,e)=>{const t=V(r);return e<t.lower?t.lower:e>=t.upper?t.upper-(typeof t.upper=="number"?1:1n):e},Gt=(r,e)=>{const t=V(r);if(typeof e=="number"||typeof e=="bigint")return e>=t.lower&&e<t.upper;const n=V(e);return n.lower>=t.lower&&n.upper<=t.upper},Lu=r=>({lower:Math.min(...r.map(e=>V(e).lower)),upper:Math.max(...r.map(e=>V(e).upper))}),Bu=(r,e,t)=>{const n=r.map(c=>V(c)),i=t>0?1:t<0?-1:0;if(i===0)return e;let a=t,o=e;for(;gs(a,0)===!1;){const c=n.findIndex(u=>i>0?o>=u.lower&&o<u.upper:o>u.lower&&o<=u.upper);if(c!==-1){const u=n[c];let l;if(i>0?l=Ze(u.upper,o):l=Ze(o,u.lower),l>0){const h=Du(Zu(a),l);if(o=Ut(o,i>0?h:-h),a=Ze(a,i>0?h:-h),gs(a,0))return o;continue}}if(i>0){const u=n.filter(l=>l.lower>o);if(u.length>0)o=u[0].lower;else return o}else{const u=n.filter(l=>l.upper<o);if(u.length>0)o=u[u.length-1].upper;else return o}}return o},qu=(r,e,t)=>{const n=r.map(o=>V(o));if(e===t)return typeof e=="bigint"?0n:0;const i=e<t?V([e,t]):V([t,e]);let a=typeof e=="bigint"?0n:0;for(const o of n){const c=o.lower>i.lower?o.lower:i.lower,u=o.upper<i.upper?o.upper:i.upper;if(c<u){const l=u-c;a=a+l}}return a},Fu=$n,Yu=In,Vu=sn,Hu={top:"bottom",right:"left",bottom:"top",left:"right",center:"center"},_u={top:"left",right:"top",bottom:"right",left:"bottom",center:"center"},Wu=Uu,ke=r=>r instanceof String||!$i.includes(r)?r:r==="x"?"left":"top",Gu=r=>Hu[ke(r)],Ku=r=>_u[ke(r)],Et=r=>{const e=ke(r);return e==="top"||e==="bottom"?"y":"x"},Ju=s.z.object({x:$n.or(sn),y:In.or(sn)}),Ci=s.z.object({x:$n,y:In}),Cn=Object.freeze({x:"left",y:"top"}),Ri=Object.freeze({x:"right",y:"top"}),ji=Object.freeze({x:"left",y:"bottom"}),Mi=Object.freeze({x:"right",y:"bottom"}),Rn=Object.freeze({x:"center",y:"center"}),Ui=Object.freeze({x:"center",y:"top"}),Di=Object.freeze({x:"center",y:"bottom"}),Zi=Object.freeze({x:"right",y:"center"}),Pi=Object.freeze({x:"left",y:"center"}),Xu=Object.freeze([Pi,Zi,Ui,Di,Cn,Ri,ji,Mi,Rn]),Li=(r,e)=>r.x===e.x&&r.y===e.y,Qu=(r,e)=>{if(typeof e=="object"){let t=!0;return"x"in e&&(r.x===e.x||(t=!1)),"y"in e&&(r.y===e.y||(t=!1)),t}return r.x===e||r.y===e},eh=r=>[r.x,r.y],rr=r=>Et(ke(r))==="x",th=r=>Et(ke(r))==="y",rh=r=>`${r.x}${pi(r.y)}`,nh=(r,e)=>{let t,n;if(typeof r=="object"&&"x"in r?(t=r.x,n=r.y):(t=ke(r),n=ke(e??r)),Et(t)===Et(n)&&t!=="center"&&n!=="center")throw new Error(`[XYLocation] - encountered two locations with the same direction: ${t.toString()} - ${n.toString()}`);const i={...Rn};return t==="center"?rr(n)?[i.x,i.y]=[n,t]:[i.x,i.y]=[t,n]:n==="center"?rr(t)?[i.x,i.y]=[t,n]:[i.x,i.y]=[n,t]:rr(t)?[i.x,i.y]=[t,n]:[i.x,i.y]=[n,t],i},sh=Object.freeze(Object.defineProperty({__proto__:null,BOTTOM_CENTER:Di,BOTTOM_LEFT:ji,BOTTOM_RIGHT:Mi,CENTER:Rn,CENTER_LEFT:Pi,CENTER_LOCATIONS:kn,CENTER_RIGHT:Zi,OUTER_LOCATIONS:An,TOP_CENTER:Ui,TOP_LEFT:Cn,TOP_RIGHT:Ri,XY_LOCATIONS:Xu,X_LOCATIONS:ki,Y_LOCATIONS:xi,center:Vu,construct:ke,constructXY:nh,corner:Ci,crude:Wu,direction:Et,isX:rr,isY:th,location:xn,outer:xu,rotate90:Ku,swap:Gu,x:Fu,xy:Ju,xyCouple:eh,xyEquals:Li,xyMatches:Qu,xyToString:rh,y:Yu},Symbol.toStringTag,{value:"Module"})),on=s.z.union([s.z.number(),vt,mr,Si,Au,Ai]),R=(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}},Le=Object.freeze({x:0,y:0}),ih=Object.freeze({x:1,y:1}),ah=Object.freeze({x:1/0,y:1/0}),oh=Object.freeze({x:NaN,y:NaN}),Bi=(r,e,t=0)=>{const n=R(r),i=R(e);return t===0?n.x===i.x&&n.y===i.y:Math.abs(n.x-i.x)<=t&&Math.abs(n.y-i.y)<=t},ch=r=>Bi(r,Le),jn=(r,e,t)=>{const n=R(r),i=R(e,t);return{x:n.x*i.x,y:n.y*i.y}},qi=(r,e)=>{const t=R(r);return{x:t.x+e,y:t.y}},Fi=(r,e)=>{const t=R(r);return{x:t.x,y:t.y+e}},Yi=(r,e,t,...n)=>{if(typeof e=="string"){if(typeof t!="number")throw new Error("The value must be a number.");return e==="x"?qi(r,t):Fi(r,t)}if(typeof e=="object"&&"x"in e&&typeof e.x=="string"){const i=R(t),a=R(r);return e.x==="left"?i.x=-i.x:e.x==="center"&&(i.x=0),e.y==="top"?i.y=-i.y:e.y==="center"&&(i.y=0),{x:a.x+i.x,y:a.y+i.y}}return[r,e,t??Le,...n].reduce((i,a)=>{const o=R(a);return{x:i.x+o.x,y:i.y+o.y}},Le)},lh=(r,e,t)=>{const n=R(r);return e==="x"?{x:t,y:n.y}:{x:n.x,y:t}},uh=(r,e)=>{const t=R(r),n=R(e);return Math.sqrt((t.x-n.x)**2+(t.y-n.y)**2)},hh=(r,e)=>{const t=R(r),n=R(e);return{x:n.x-t.x,y:n.y-t.y}},fh=r=>{const e=R(r);return Number.isNaN(e.x)||Number.isNaN(e.y)},dh=r=>{const e=R(r);return Number.isFinite(e.x)&&Number.isFinite(e.y)},yh=r=>{const e=R(r);return[e.x,e.y]},gh=r=>{const e=R(r);return{left:e.x,top:e.y}},ph=(r,e=0)=>{const t=R(r);return{x:Number(t.x.toFixed(e)),y:Number(t.y.toFixed(e))}},gt=(r,e)=>{const t=R(r),n=R(e);return{x:t.x-n.x,y:t.y-n.y}},pt=r=>{const e=R(r),t=Math.hypot(e.x,e.y);return t===0?{x:0,y:0}:{x:-e.y/t,y:e.x/t}},Vi=r=>{const e=R(r),t=Math.hypot(e.x,e.y);return t===0?{x:0,y:0}:{x:e.x/t,y:e.y/t}},Hi=(...r)=>{const e=r.reduce((t,n)=>Yi(t,n),Le);return jn(e,1/r.length)},mh=(r,e)=>{const t=[];for(let n=0;n<r.length;n++){const i=r[n];let a,o,c,u;if(n===0){const l=r[n+1],h=gt(l,i);o=pt(h),c=o,u=e}else if(n===r.length-1){const l=r[n-1],h=gt(i,l);a=pt(h),c=a,u=e}else{const l=r[n-1],h=r[n+1],y=gt(i,l),d=gt(h,i);a=pt(y),o=pt(d);const N=Math.acos((y.x*d.x+y.y*d.y)/(Math.hypot(y.x,y.y)*Math.hypot(d.x,d.y))),S=Math.sin(N/2);S===0?u=e:u=e/S,c=Vi(Hi(a,o))}t.push(jn(c,u))}return t},wh=r=>{const e=R(r);return{x:e.y,y:e.x}},bh=r=>{const e=R(r);return{x:Math.round(e.x),y:Math.round(e.y)}},_i=Object.freeze(Object.defineProperty({__proto__:null,INFINITY:ah,NAN:oh,ONE:ih,ZERO:Le,average:Hi,calculateMiters:mh,clientXY:Ai,construct:R,couple:yh,crudeZ:on,css:gh,distance:uh,equals:Bi,isFinite:dh,isNan:fh,isZero:ch,normal:pt,normalize:Vi,round:bh,scale:jn,set:lh,sub:gt,swap:wh,translate:Yi,translateX:qi,translateY:Fi,translation:hh,truncate:ph,xy:vt},Symbol.toStringTag,{value:"Module"})),Kt=s.z.union([s.z.number(),s.z.string()]);s.z.object({top:Kt,left:Kt,width:Kt,height:Kt});s.z.object({left:s.z.number(),top:s.z.number(),right:s.z.number(),bottom:s.z.number()});s.z.object({one:vt,two:vt,root:Ci});const Mn=(r,e,t=0,n=0,i)=>{const a={one:{...Le},two:{...Le},root:i??Cn};if(typeof r=="number"){if(typeof e!="number")throw new Error("Box constructor called with invalid arguments");return a.one={x:r,y:e},a.two={x:a.one.x+t,y:a.one.y+n},a}return"one"in r&&"two"in r&&"root"in r?{...r,root:i??r.root}:("getBoundingClientRect"in r&&(r=r.getBoundingClientRect()),"left"in r?(a.one={x:r.left,y:r.top},a.two={x:r.right,y:r.bottom},a):(a.one=r,e==null?a.two={x:a.one.x+t,y:a.one.y+n}:typeof e=="number"?a.two={x:a.one.x+e,y:a.one.y+t}:"width"in e?a.two={x:a.one.x+e.width,y:a.one.y+e.height}:"signedWidth"in e?a.two={x:a.one.x+e.signedWidth,y:a.one.y+e.signedHeight}:a.two=e,a))},Zr=r=>{const e=Mn(r);return{lower:e.one.x,upper:e.two.x}},Pr=r=>{const e=Mn(r);return{lower:e.one.y,upper:e.two.y}},Th=r=>typeof r!="object"||r==null?!1:"one"in r&&"two"in r&&"root"in r,vh=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()});s.z.union([Si,vh,vt,mr]);const Eh=(r,e,t)=>e!==void 0&&r<e?e:t!==void 0&&r>t?t:r;s.z.object({offset:on,scale:on});s.z.object({offset:s.z.number(),scale:s.z.number()});const Nh=r=>(e,t,n,i)=>t==="dimension"?[e,n]:[e,i?n-r:n+r],Oh=r=>(e,t,n,i)=>[e,i?n/r:n*r],zh=r=>(e,t,n)=>{if(e===null)return[r,n];const{lower:i,upper:a}=e,{lower:o,upper:c}=r,u=a-i,l=c-o;if(t==="dimension")return[r,n*(l/u)];const h=(n-i)*(l/u)+o;return[r,h]},Sh=r=>(e,t,n)=>[r,n],Ah=()=>(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)]},$h=r=>(e,t,n)=>{const{lower:i,upper:a}=r;return n=Eh(n,i,a),[e,n]};let ms=class _e{ops=[];currBounds=null;currType=null;reversed=!1;constructor(){this.ops=[]}static translate(e){return new _e().translate(e)}static magnify(e){return new _e().magnify(e)}static scale(e,t){return new _e().scale(e,t)}translate(e){const t=this.new(),n=Nh(e);return n.type="translate",t.ops.push(n),t}magnify(e){const t=this.new(),n=Oh(e);return n.type="magnify",t.ops.push(n),t}scale(e,t){const n=V(e,t),i=this.new(),a=zh(n);return a.type="scale",i.ops.push(a),i}clamp(e,t){const n=V(e,t),i=this.new(),a=$h(n);return a.type="clamp",i.ops.push(a),i}reBound(e,t){const n=V(e,t),i=this.new(),a=Sh(n);return a.type="re-bound",i.ops.push(a),i}invert(){const e=Ah();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 _e;return e.ops=this.ops.slice(),e.reversed=this.reversed,e}exec(e,t){return this.currBounds=null,this.ops.reduce(([n,i],a)=>a(n,e,i,this.reversed),[null,t])[1]}reverse(){const e=this.new();e.ops.reverse();const t=[];return e.ops.forEach((n,i)=>{if(n.type==="scale"||t.some(([o,c])=>i>=o&&i<=c))return;const a=e.ops.findIndex((o,c)=>o.type==="scale"&&c>i);a!==-1&&t.push([i,a])}),t.forEach(([n,i])=>{const a=e.ops.slice(n,i);a.unshift(e.ops[i]),e.ops.splice(n,i-n+1,...a)}),e.reversed=!e.reversed,e}get transform(){return{scale:this.dim(1),offset:this.pos(0)}}static IDENTITY=new _e},Pb=class ce{x;y;currRoot;constructor(e=new ms,t=new ms,n=null){this.x=e,this.y=t,this.currRoot=n}static translate(e,t){return new ce().translate(e,t)}static translateX(e){return new ce().translateX(e)}static translateY(e){return new ce().translateY(e)}static clamp(e){return new ce().clamp(e)}static magnify(e){return new ce().magnify(e)}static scale(e){return new ce().scale(e)}static reBound(e){return new ce().reBound(e)}translate(e,t){const n=R(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(Th(e)){const n=this.currRoot;return t.currRoot=e.root,n!=null&&!Li(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(Zr(e)),t.y=t.y.scale(Pr(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(Zr(e)),t.y=this.y.reBound(Pr(e)),t}clamp(e){const t=this.copy();return t.x=this.x.clamp(Zr(e)),t.y=this.y.clamp(Pr(e)),t}copy(){const e=new ce;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 Mn(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 ce},Wi=(r,e=21)=>(t=e)=>{let n="",i=t|0;for(;i--;)n+=r[Math.random()*r.length|0];return n};const Gi="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",Ih=`0123456789${Gi}`,Ki=11,kh=Wi(Gi,1),xh=Wi(Ih,Ki-1),Un=()=>`${kh()}${xh()}`,Ch=Object.freeze(Object.defineProperty({__proto__:null,LENGTH:Ki,create:Un},Symbol.toStringTag,{value:"Module"})),Rh=(r,e)=>t=>t instanceof e||typeof t=="object"&&t!==null&&"discriminator"in t&&t.discriminator===r,jh=s.z.enum(["static","dynamic"]),Mh=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)])]),Ji=(r,e)=>{const t=new f(e);if(![E.DAY,E.HOUR,E.MINUTE,E.SECOND,E.MILLISECOND,E.MICROSECOND,E.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 f?new f(n):new E(n)};class f extends nt{constructor(e,t="UTC"){if(e==null)super(f.now().valueOf());else if(e instanceof Date)super(BigInt(e.getTime())*f.MILLISECOND.valueOf());else if(typeof e=="string")super(f.parseDateTimeString(e,t).valueOf());else if(Array.isArray(e))super(f.parseDate(e));else{let n=0n;e instanceof Number&&(e=e.valueOf()),t==="local"&&(n=f.utcOffset.valueOf()),typeof e=="number"&&(isFinite(e)?e=Math.trunc(e):(isNaN(e)&&(e=0),e===1/0?e=f.MAX:e=f.MIN)),Q(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 f(BigInt(i.getTime())*f.MILLISECOND.valueOf()).truncate(f.DAY).valueOf()}valueOf(){return this.value}static parseTimeString(e,t="UTC"){const[n,i,a]=e.split(":");let o="00",c="00";a!=null&&([o,c]=a.split("."));let u=f.hours(parseInt(n??"00")).add(f.minutes(parseInt(i??"00"))).add(f.seconds(parseInt(o??"00"))).add(f.milliseconds(parseInt(c??"00")));return t==="local"&&(u=u.add(f.utcOffset)),u.valueOf()}static parseDateTimeString(e,t="UTC"){if(!e.includes("/")&&!e.includes("-"))return f.parseTimeString(e,t);const n=new Date(e);return e.includes(":")||n.setUTCHours(0,0,0,0),new f(BigInt(n.getTime())*f.MILLISECOND.valueOf(),t).valueOf()}fString(e="ISO",t="UTC"){switch(e){case"ISODate":return this.toISOString(t).slice(0,10);case"ISOTime":return this.toISOString(t).slice(11,23);case"time":return this.timeString(!1,t);case"preciseTime":return this.timeString(!0,t);case"date":return this.dateString();case"preciseDate":return`${this.dateString()} ${this.timeString(!0,t)}`;case"dateTime":return`${this.dateString()} ${this.timeString(!1,t)}`;default:return this.toISOString(t)}}toISOString(e="UTC"){return e==="UTC"?this.date().toISOString():this.sub(f.utcOffset).date().toISOString()}timeString(e=!1,t="UTC"){const 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 E(BigInt(new Date().getTimezoneOffset())*f.MINUTE.valueOf())}static since(e){return new f().span(e)}date(){return new Date(this.milliseconds)}equals(e){return this.valueOf()===new f(e).valueOf()}span(e){return this.range(e).span}range(e){return new M(this,e).makeValid()}spanRange(e){return this.range(this.add(e)).makeValid()}get isZero(){return this.valueOf()===0n}after(e){return this.valueOf()>new f(e).valueOf()}afterEq(e){return this.valueOf()>=new f(e).valueOf()}before(e){return this.valueOf()<new f(e).valueOf()}beforeEq(e){return this.valueOf()<=new f(e).valueOf()}add(e){return new f(Ut(this.valueOf(),new E(e).valueOf()))}sub(e){return new f(Ze(this.valueOf(),new E(e).valueOf()))}get hours(){return Number(this.valueOf())/Number(E.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(E.MINUTE.valueOf())}get days(){return Number(this.valueOf())/Number(E.DAY.valueOf())}get seconds(){return Number(this.valueOf())/Number(E.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(f.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(f.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get year(){return this.date().getUTCFullYear()}setYear(e){const t=this.date();return t.setUTCFullYear(e),new f(t)}get month(){return this.date().getUTCMonth()}setMonth(e){const t=this.date();return t.setUTCMonth(e),new f(t)}get day(){return this.date().getUTCDate()}setDay(e){const t=this.date();return t.setUTCDate(e),new f(t)}get hour(){return this.date().getUTCHours()}get localHour(){return this.date().getHours()}setLocalHour(e){const t=this.date();return t.setHours(e),new f(t)}setHour(e){const t=this.date();return t.setUTCHours(e),new f(t)}get minute(){return this.date().getUTCMinutes()}setMinute(e){const t=this.date();return t.setUTCMinutes(e),new f(t)}get second(){return this.date().getUTCSeconds()}setSecond(e){const t=this.date();return t.setUTCSeconds(e),new f(t)}get millisecond(){return this.date().getUTCMilliseconds()}setMillisecond(e){const t=this.date();return t.setUTCMilliseconds(e),new f(t)}toString(){return this.date().toISOString()}remainder(e){return Ji(this,e)}get isToday(){return this.truncate(E.DAY).equals(f.now().truncate(E.DAY))}truncate(e){return this.sub(this.remainder(e))}static now(){return new f(new Date)}static max(...e){let t=f.MIN;for(const n of e){const i=new f(n);i.after(t)&&(t=i)}return t}static min(...e){let t=f.MAX;for(const n of e){const i=new f(n);i.before(t)&&(t=i)}return t}static nanoseconds(e,t="UTC"){return new f(e,t)}static NANOSECOND=f.nanoseconds(1);static microseconds(e,t="UTC"){return f.nanoseconds(e*1e3,t)}static MICROSECOND=f.microseconds(1);static milliseconds(e,t="UTC"){return f.microseconds(e*1e3,t)}static MILLISECOND=f.milliseconds(1);static seconds(e,t="UTC"){return f.milliseconds(e*1e3,t)}static SECOND=f.seconds(1);static minutes(e,t="UTC"){return f.seconds(e*60,t)}static MINUTE=f.minutes(1);static hours(e,t="UTC"){return f.minutes(e*60,t)}static HOUR=f.hours(1);static days(e,t="UTC"){return f.hours(e*24,t)}static DAY=f.days(1);static MAX=new f((1n<<63n)-1n);static MIN=new f(0);static ZERO=new f(0);static z=s.z.union([s.z.instanceof(f),s.z.object({value:s.z.bigint()}).transform(e=>new f(e.value)),s.z.string().transform(e=>new f(BigInt(e))),s.z.number().transform(e=>new f(e)),s.z.bigint().transform(e=>new f(e)),s.z.date().transform(e=>new f(e)),s.z.custom(e=>e instanceof E).transform(e=>new f(e)),Mh.transform(e=>new f(e))]);static sort(e,t){return Number(e.valueOf()-t.valueOf())}}let E=class T extends nt{constructor(e){typeof e=="number"&&(e=Math.trunc(e.valueOf())),Q(e)&&(e=e.value),super(BigInt(e.valueOf()))}static fromSeconds(e){return e instanceof T?e:e instanceof W?e.period:e instanceof f?new T(e):(Q(e)&&(e=e.value),["number","bigint"].includes(typeof e)?T.seconds(e):new T(e))}static fromMilliseconds(e){return e instanceof T?e:e instanceof W?e.period:e instanceof f?new T(e):(Q(e)&&(e=e.value),["number","bigint"].includes(typeof e)?T.milliseconds(e):new T(e))}valueOf(){return this.value}lessThan(e){return this.valueOf()<new T(e).valueOf()}greaterThan(e){return this.valueOf()>new T(e).valueOf()}lessThanOrEqual(e){return this.valueOf()<=new T(e).valueOf()}greaterThanOrEqual(e){return this.valueOf()>=new T(e).valueOf()}remainder(e){return Ji(this,e)}truncate(e){return new T(BigInt(Math.trunc(Number(this.valueOf()/e.valueOf())))*e.valueOf())}toString(){const e=this.truncate(T.DAY),t=this.truncate(T.HOUR),n=this.truncate(T.MINUTE),i=this.truncate(T.SECOND),a=this.truncate(T.MILLISECOND),o=this.truncate(T.MICROSECOND),c=this.truncate(T.NANOSECOND),u=e,l=t.sub(e),h=n.sub(t),y=i.sub(n),d=a.sub(i),N=o.sub(a),S=c.sub(o);let k="";return u.isZero||(k+=`${u.days}d `),l.isZero||(k+=`${l.hours}h `),h.isZero||(k+=`${h.minutes}m `),y.isZero||(k+=`${y.seconds}s `),d.isZero||(k+=`${d.milliseconds}ms `),N.isZero||(k+=`${N.microseconds}µs `),S.isZero||(k+=`${S.nanoseconds}ns`),k.trim()}mult(e){return new T(ue(this.valueOf(),e))}div(e){return new T(wr(this.valueOf(),e))}get days(){return Number(this.valueOf())/Number(T.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(T.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(T.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(T.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(T.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(T.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get isZero(){return this.valueOf()===0n}equals(e){return this.valueOf()===new T(e).valueOf()}add(e){return new T(this.valueOf()+new T(e).valueOf())}sub(e){return new T(this.valueOf()-new T(e).valueOf())}static nanoseconds(e=1){return new T(e)}static NANOSECOND=T.nanoseconds(1);static microseconds(e=1){return T.nanoseconds(ue(e,1e3))}static MICROSECOND=T.microseconds(1);static milliseconds(e=1){return T.microseconds(ue(e,1e3))}static MILLISECOND=T.milliseconds(1);static seconds(e=1){return T.milliseconds(ue(e,1e3))}static SECOND=T.seconds(1);static minutes(e=1){return T.seconds(ue(e,60))}static MINUTE=T.minutes(1);static hours(e){return T.minutes(ue(e,60))}static HOUR=T.hours(1);static days(e){return T.hours(ue(e,24))}static DAY=T.days(1);static MAX=new T((1n<<63n)-1n);static MIN=new T(0);static ZERO=new T(0);static z=s.z.union([s.z.object({value:s.z.bigint()}).transform(e=>new T(e.value)),s.z.string().transform(e=>new T(BigInt(e))),s.z.number().transform(e=>new T(e)),s.z.bigint().transform(e=>new T(e)),s.z.instanceof(T),s.z.instanceof(f).transform(e=>new T(e)),s.z.custom(e=>e instanceof W).transform(e=>new T(e))])};class W extends nt{constructor(e){Q(e)&&(e=e.value),super(e.valueOf())}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new W(e).valueOf()}get period(){return E.seconds(1/this.valueOf())}sampleCount(e){return new E(e).seconds*this.valueOf()}byteCount(e,t){return this.sampleCount(e)*new Y(t).valueOf()}span(e){return E.seconds(e/this.valueOf())}byteSpan(e,t){return this.span(e.valueOf()/new Y(t).valueOf())}add(e){return new W(Ut(this.valueOf(),new W(e).valueOf()))}sub(e){return new W(Ze(this.valueOf(),new W(e).valueOf()))}mult(e){return new W(ue(this.valueOf(),e))}div(e){return new W(wr(this.valueOf(),e))}static hz(e){return new W(e)}static khz(e){return W.hz(e*1e3)}static z=s.z.union([s.z.number().transform(e=>new W(e)),s.z.instanceof(W)])}let Y=class K extends nt{constructor(e){Q(e)&&(e=e.value),super(e.valueOf())}length(e){return e.valueOf()/this.valueOf()}size(e){return new et(e*this.valueOf())}add(e){return new K(Ut(this.valueOf(),new K(e).valueOf()))}sub(e){return new K(Ze(this.valueOf(),new K(e).valueOf()))}mult(e){return new K(ue(this.valueOf(),e))}div(e){return new K(wr(this.valueOf(),e))}static UNKNOWN=new K(0);static BIT128=new K(16);static BIT64=new K(8);static BIT32=new K(4);static BIT16=new K(2);static BIT8=new K(1);static z=s.z.union([s.z.number().transform(e=>new K(e)),s.z.instanceof(K)])},M=class ne{start;end;constructor(e,t){typeof e=="object"&&"start"in e?(this.start=new f(e.start),this.end=new f(e.end)):(this.start=new f(e),this.end=new f(t))}get span(){return new E(this.end.valueOf()-this.start.valueOf())}get isValid(){return this.start.valueOf()<=this.end.valueOf()}makeValid(){return this.isValid?this:this.swap()}get isZero(){return this.span.isZero}get numeric(){return{start:Number(this.start.valueOf()),end:Number(this.end.valueOf())}}swap(){return new ne(this.end,this.start)}get numericBounds(){return{lower:Number(this.start.valueOf()),upper:Number(this.end.valueOf())}}equals(e,t=E.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.fString("preciseDate")} - ${this.span.toString()}`}overlapsWith(e,t=E.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=f.max(n.start,e.start),a=f.min(n.end,e.end);return a.before(i)?!1:new E(a.sub(i)).greaterThanOrEqual(t)}contains(e){return e instanceof ne?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const t=new ne(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 ne(f.min(...e.map(t=>t.start)),f.max(...e.map(t=>t.end)))}static MAX=new ne(f.MIN,f.MAX);static MIN=new ne(f.MAX,f.MIN);static ZERO=new ne(f.ZERO,f.ZERO);static z=s.z.union([s.z.object({start:f.z,end:f.z}).transform(e=>new ne(e.start,e.end)),s.z.instanceof(ne)]);static sort(e,t){return f.sort(e.start,t.start)||f.sort(e.end,t.end)}static simplify(e){return e.map(t=>t.makeValid()).sort((t,n)=>ne.sort(t,n)).reduce((t,n)=>{if(n.isZero)return t;if(t.length===0)return t.push(n),t;const i=t[t.length-1];return i.overlapsWith(n)||i.end.equals(n.start)?i.end=f.max(i.end,n.end):t.push(n),t},[])}},$=class p extends nt{constructor(e){if(Q(e)&&(e=e.value),e instanceof p||typeof e=="string"||typeof e.valueOf()=="string")super(e.valueOf());else{const t=p.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=p.ARRAY_CONSTRUCTORS.get(this.toString());if(e==null)throw new Error(`unable to find array constructor for ${this.valueOf()}`);return e}equals(e){return this.valueOf()===e.valueOf()}matches(...e){return e.some(t=>this.equals(t))}toString(){return this.valueOf()}get isVariable(){return this.equals(p.JSON)||this.equals(p.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(p.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=p.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}get isUnsignedInteger(){return this.equals(p.UINT8)||this.equals(p.UINT16)||this.equals(p.UINT32)||this.equals(p.UINT64)}get isSignedInteger(){return this.equals(p.INT8)||this.equals(p.INT16)||this.equals(p.INT32)||this.equals(p.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(p.INT32)&&e.equals(p.FLOAT64)||this.equals(p.INT8)&&e.equals(p.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 p.BIG_INT_TYPES.some(e=>e.equals(this))}static UNKNOWN=new p("unknown");static FLOAT64=new p("float64");static FLOAT32=new p("float32");static INT64=new p("int64");static INT32=new p("int32");static INT16=new p("int16");static INT8=new p("int8");static UINT64=new p("uint64");static UINT32=new p("uint32");static UINT16=new p("uint16");static UINT8=new p("uint8");static BOOLEAN=this.UINT8;static TIMESTAMP=new p("timestamp");static UUID=new p("uuid");static STRING=new p("string");static JSON=new p("json");static ARRAY_CONSTRUCTORS=new Map([[p.UINT8.toString(),Uint8Array],[p.UINT16.toString(),Uint16Array],[p.UINT32.toString(),Uint32Array],[p.UINT64.toString(),BigUint64Array],[p.FLOAT32.toString(),Float32Array],[p.FLOAT64.toString(),Float64Array],[p.INT8.toString(),Int8Array],[p.INT16.toString(),Int16Array],[p.INT32.toString(),Int32Array],[p.INT64.toString(),BigInt64Array],[p.TIMESTAMP.toString(),BigInt64Array],[p.STRING.toString(),Uint8Array],[p.JSON.toString(),Uint8Array],[p.UUID.toString(),Uint8Array]]);static ARRAY_CONSTRUCTOR_DATA_TYPES=new Map([[Uint8Array.name,p.UINT8],[Uint16Array.name,p.UINT16],[Uint32Array.name,p.UINT32],[BigUint64Array.name,p.UINT64],[Float32Array.name,p.FLOAT32],[Float64Array.name,p.FLOAT64],[Int8Array.name,p.INT8],[Int16Array.name,p.INT16],[Int32Array.name,p.INT32],[BigInt64Array.name,p.INT64]]);static DENSITIES=new Map([[p.UINT8.toString(),Y.BIT8],[p.UINT16.toString(),Y.BIT16],[p.UINT32.toString(),Y.BIT32],[p.UINT64.toString(),Y.BIT64],[p.FLOAT32.toString(),Y.BIT32],[p.FLOAT64.toString(),Y.BIT64],[p.INT8.toString(),Y.BIT8],[p.INT16.toString(),Y.BIT16],[p.INT32.toString(),Y.BIT32],[p.INT64.toString(),Y.BIT64],[p.TIMESTAMP.toString(),Y.BIT64],[p.STRING.toString(),Y.UNKNOWN],[p.JSON.toString(),Y.UNKNOWN],[p.UUID.toString(),Y.BIT128]]);static ALL=[p.UNKNOWN,p.FLOAT64,p.FLOAT32,p.INT64,p.INT32,p.INT16,p.INT8,p.UINT64,p.UINT32,p.UINT16,p.UINT8,p.TIMESTAMP,p.UUID,p.STRING,p.JSON];static BIG_INT_TYPES=[p.INT64,p.UINT64,p.TIMESTAMP];static z=s.z.union([s.z.string().transform(e=>new p(e)),s.z.instanceof(p)])},et=class z extends nt{constructor(e){Q(e)&&(e=e.value),super(e.valueOf())}largerThan(e){return Q(e)&&(e=e.value),this.valueOf()>e.valueOf()}smallerThan(e){return Q(e)&&(e=e.value),this.valueOf()<e.valueOf()}add(e){return Q(e)&&(e=e.value),new z(Ut(this.valueOf(),e.valueOf()))}sub(e){return Q(e)&&(e=e.value),new z(Ze(this.valueOf(),e.valueOf()))}mult(e){return new z(ue(this.valueOf(),e))}div(e){return new z(wr(this.valueOf(),e))}truncate(e){return new z(Math.trunc(this.valueOf()/new z(e).valueOf())*new z(e).valueOf())}remainder(e){return z.bytes(this.valueOf()%new z(e).valueOf())}get gigabytes(){return this.valueOf()/z.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/z.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/z.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/z.TERABYTE.valueOf()}toString(){const e=this.truncate(z.TERABYTE),t=this.truncate(z.GIGABYTE),n=this.truncate(z.MEGABYTE),i=this.truncate(z.KILOBYTE),a=this.truncate(z.BYTE),o=e,c=t.sub(e),u=n.sub(t),l=i.sub(n),h=a.sub(i);let y="";return o.isZero||(y+=`${o.terabytes}TB `),c.isZero||(y+=`${c.gigabytes}GB `),u.isZero||(y+=`${u.megabytes}MB `),l.isZero||(y+=`${l.kilobytes}KB `),(!h.isZero||y==="")&&(y+=`${h.valueOf()}B`),y.trim()}static bytes(e=1){return new z(e)}static BYTE=new z(1);static kilobytes(e=1){return z.bytes(new z(e).valueOf()*1e3)}static KILOBYTE=z.kilobytes(1);static megabytes(e=1){return z.kilobytes(new z(e).valueOf()*1e3)}static MEGABYTE=z.megabytes(1);static gigabytes(e=1){return z.megabytes(new z(e).valueOf()*1e3)}static GIGABYTE=z.gigabytes(1);static terabytes(e){return z.gigabytes(new z(e).valueOf()*1e3)}static TERABYTE=z.terabytes(1);static ZERO=new z(0);static z=s.z.union([s.z.number().transform(e=>new z(e)),s.z.instanceof(z)]);get isZero(){return this.valueOf()===0}};s.z.union([s.z.instanceof(Uint8Array),s.z.instanceof(Uint16Array),s.z.instanceof(Uint32Array),s.z.instanceof(BigUint64Array),s.z.instanceof(Float32Array),s.z.instanceof(Float64Array),s.z.instanceof(Int8Array),s.z.instanceof(Int16Array),s.z.instanceof(Int32Array),s.z.instanceof(BigInt64Array)]);const Xi=r=>{const e=typeof r;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||r instanceof f||r instanceof E||r instanceof Date},Uh=(r,e,t,n=0)=>r.usesBigInt&&!e.usesBigInt?Number(t)-Number(n):!r.usesBigInt&&e.usesBigInt?BigInt(t.valueOf())-BigInt(n.valueOf()):nr(t,-n),nr=(r,e)=>e==0?r:r==0?e:typeof r=="bigint"&&typeof e=="bigint"||typeof r=="number"&&typeof e=="number"?r+e:Number(r)+Number(e),Dh=/^(?:[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 Zh(r){return typeof r=="string"&&Dh.test(r)}const F=[];for(let r=0;r<256;++r)F.push((r+256).toString(16).slice(1));function Ph(r,e=0){return(F[r[e+0]]+F[r[e+1]]+F[r[e+2]]+F[r[e+3]]+"-"+F[r[e+4]]+F[r[e+5]]+"-"+F[r[e+6]]+F[r[e+7]]+"-"+F[r[e+8]]+F[r[e+9]]+"-"+F[r[e+10]]+F[r[e+11]]+F[r[e+12]]+F[r[e+13]]+F[r[e+14]]+F[r[e+15]]).toLowerCase()}function Lh(r,e=0){const t=Ph(r,e);if(!Zh(t))throw TypeError("Stringified UUID is invalid");return t}typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const Qi=(r,e)=>Lh(r,e),Ne=-1,cn={[Symbol.iterator]:()=>cn,next:()=>({done:!0,value:void 0})},Bh=s.z.string().transform(r=>new Uint8Array(atob(r).split("").map(e=>e.charCodeAt(0))).buffer),qh=s.z.union([s.z.null(),s.z.undefined()]).transform(()=>new Uint8Array().buffer),ln=10,ea=(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`)},ta="sy_x_telem_series";let ge=class Ae{key;discriminator=ta;dataType;sampleOffset;gl;_data;timeRange=M.ZERO;alignment=0n;alignmentMultiple=1n;cachedMin;cachedMax;writePos=Ne;_refCount=0;cachedLength;_cachedIndexes;static crudeZ=s.z.object({timeRange:M.z.optional(),dataType:$.z,alignment:s.z.coerce.bigint().optional(),data:s.z.union([Bh,qh,s.z.instanceof(ArrayBuffer),s.z.instanceof(Uint8Array)]),glBufferUsage:jh.optional().default("static").optional()});static z=Ae.crudeZ.transform(e=>new Ae(e));constructor(e){Fh(e)&&(e={data:e}),e.data??=[];const{dataType:t,timeRange:n,sampleOffset:i=0,glBufferUsage:a="static",alignment:o=0n,alignmentMultiple:c=1n,key:u=Un(),data:l}=e;if(ra(l)){const d=l;this.key=d.key,this.dataType=d.dataType,this.sampleOffset=d.sampleOffset,this.gl=d.gl,this._data=d._data,this.timeRange=d.timeRange,this.alignment=d.alignment,this.alignmentMultiple=d.alignmentMultiple,this.cachedMin=d.cachedMin,this.cachedMax=d.cachedMax,this.writePos=d.writePos,this._refCount=d._refCount,this.cachedLength=d.cachedLength;return}const h=Xi(l),y=Array.isArray(l);if(t!=null)this.dataType=new $(t);else{if(l instanceof ArrayBuffer)throw new Error("cannot infer data type from an ArrayBuffer instance when constructing a Series. Please provide a data type.");if(y||h){let d=l;if(!h){if(l.length===0)throw new Error("cannot infer data type from a zero length JS array when constructing a Series. Please provide a data type.");d=l[0]}if(typeof d=="string")this.dataType=$.STRING;else if(typeof d=="number")this.dataType=$.FLOAT64;else if(typeof d=="bigint")this.dataType=$.INT64;else if(typeof d=="boolean")this.dataType=$.BOOLEAN;else if(d instanceof f||d instanceof Date||d instanceof f)this.dataType=$.TIMESTAMP;else if(typeof d=="object")this.dataType=$.JSON;else throw new Error(`cannot infer data type of ${typeof d} when constructing a Series from a JS array`)}else this.dataType=new $(l)}if(!y&&!h)this._data=l;else if(y&&l.length===0)this._data=new this.dataType.Array([]).buffer;else{let d=h?[l]:l;const N=d[0];(N instanceof f||N instanceof Date||N instanceof E)&&(d=d.map(S=>new f(S).valueOf())),this.dataType.equals($.STRING)?(this.cachedLength=d.length,this._data=new TextEncoder().encode(`${d.join(`
|
|
8
|
+
`).map(c=>c.trim());if(n.length===0)return t!=null?t.parse({}):{};const a=n.split(",").map(c=>c.trim()),o={};return a.forEach(c=>{o[c]=[]}),i.forEach(c=>{const u=c.split(",").map(l=>l.trim());a.forEach((l,h)=>{const y=this.parseValue(u[h]);y!=null&&o[l].push(y)})}),t!=null?t.parse(o):o}parseValue(e){if(e==null||e.length===0)return null;const t=Number(e);return isNaN(t)?e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e:t}},vi=class{contentType="text/plain";encode(e){if(typeof e!="string")throw new Error("TextCodec.encode payload must be a string");return new TextEncoder().encode(e)}decode(e,t){const n=new TextDecoder().decode(e);return t!=null?t.parse(n):n}};const Tt=new bi,mu=new Ti,wu=new vi,bu=[Tt],Be=Object.freeze(Object.defineProperty({__proto__:null,CSVCodec:Ti,CSV_CODEC:mu,ENCODERS:bu,JSONCodec:bi,JSON_CODEC:Tt,TEXT_CODEC:wu,TextCodec:vi},Symbol.toStringTag,{value:"Module"})),nn=r=>[...new Set(r)],Tu=(r,e,t=!0)=>{const n=new Map;return r.forEach(i=>{const a=e(i);if(n.has(a)){if(t)return;n.delete(a)}n.set(a,i)}),Array.from(n.values())},ys=Object.freeze(Object.defineProperty({__proto__:null,by:Tu,unique:nn},Symbol.toStringTag,{value:"Module"})),Q=r=>r!=null&&typeof r=="object"&&"value"in r;let nt=class{value;constructor(e){this.value=e}valueOf(){return this.value}toJSON(){return this.value}toString(){return this.value.toString()}};const vu=r=>r!=null&&typeof r=="object"&&"toString"in r,pr=(r,e=!1)=>{const t=vu(r)?"stringer":typeof r;let n;switch(t){case"string":n=(i,a)=>i.localeCompare(a);break;case"stringer":n=(i,a)=>i.toString().localeCompare(a.toString());break;case"number":n=(i,a)=>Number(i)-Number(a);break;case"bigint":n=(i,a)=>BigInt(i)-BigInt(a)>0n?1:-1;break;case"boolean":n=(i,a)=>Number(i)-Number(a);break;case"undefined":n=()=>0;break;default:return console.warn(`sortFunc: unknown type ${t}`),()=>-1}return e?Ni(n):n},Eu=(r,e,t)=>{const n=pr(e[r],t);return(i,a)=>n(i[r],a[r])},Nu=(r,e)=>r.length!==e.length?r.length-e.length:r.every((t,n)=>t===e[n])?0:-1,Ei=(r,e)=>{if(r.length!==e.length)return r.length-e.length;if(r.length===0)return 0;const t=pr(r[0]),n=[...r].sort(t),i=[...e].sort(t);return n.every((a,o)=>a===i[o])?0:-1},Ou=(r,e)=>{const t=nn(r),n=nn(e);return Ei(t,n)},zu=(r,e)=>r===e?0:r==="first"&&e==="last"?1:-1,Ni=r=>(e,t)=>r(t,e),st=0,er=-1,tr=1,Oi=r=>r<st,zi=r=>r>st,Su=r=>r>=st,Si=r=>r===st,Au=(r,e)=>{const t=/([a-zA-Z]+)|(\d+)/g,n=r.replace(/[\s_.-]+/g,"").match(t),i=e.replace(/[\s_.-]+/g,"").match(t);if(!n||!i)return 0;for(let a=0;a<Math.min(n.length,i.length);a++){const o=n[a],c=i[a];if(isNaN(Number(o))&&isNaN(Number(c))){const u=o.localeCompare(c);if(u!==0)return u}else if(!isNaN(Number(o))&&!isNaN(Number(c))){const u=Number(o)-Number(c);if(u!==0)return u}else return isNaN(Number(o))?-1:1}return n.length-i.length},gs=Object.freeze(Object.defineProperty({__proto__:null,EQUAL:st,GREATER_THAN:tr,LESS_THAN:er,isEqualTo:Si,isGreaterThan:zi,isGreaterThanEqual:Su,isLessThan:Oi,newF:pr,newFieldF:Eu,order:zu,primitiveArrays:Nu,reverseF:Ni,stringsWithNumbers:Au,uniqueUnorderedPrimitiveArrays:Ou,unorderedPrimitiveArrays:Ei},Symbol.toStringTag,{value:"Module"})),mr=s.z.tuple([s.z.number(),s.z.number()]);s.z.tuple([s.z.bigint(),s.z.bigint()]);const Ai=s.z.object({width:s.z.number(),height:s.z.number()}),$u=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()}),Iu=["width","height"];s.z.enum(Iu);const ku=["start","center","end"],xu=["signedWidth","signedHeight"];s.z.enum(xu);const vt=s.z.object({x:s.z.number(),y:s.z.number()}),$i=s.z.object({clientX:s.z.number(),clientY:s.z.number()}),Ii=["x","y"],ki=s.z.enum(Ii),$n=["top","right","bottom","left"],Cu=s.z.enum($n),xi=["left","right"],In=s.z.enum(xi),Ci=["top","bottom"],kn=s.z.enum(Ci),xn=["center"],sn=s.z.enum(xn),Ru=[...$n,...xn],Cn=s.z.enum(Ru);s.z.enum(ku);const ju=["first","last"];s.z.enum(ju);const Mu=s.z.object({lower:s.z.number(),upper:s.z.number()}),Uu=s.z.object({lower:s.z.bigint(),upper:s.z.bigint()});s.z.union([Mu,mr]);s.z.union([Uu,mr]);s.z.enum([...ki.options,...Cn.options]);s.z.enum(["x","left","right"]);s.z.enum(["y","top","bottom"]);const Du=s.z.union([ki,Cn,s.z.instanceof(String)]),Mt=r=>(e,t)=>{if(typeof e=="bigint"){if(an(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))},Ze=Mt((r,e)=>r-e),Ut=Mt((r,e)=>r+e),ps=(r,e)=>{const t=typeof r=="bigint",n=typeof e=="bigint";return t&&n?r===e:t&&an(e)?r===BigInt(e):n&&an(r)?e===BigInt(r):r===e},Zu=Mt((r,e)=>r<=e?r:e),an=r=>typeof r=="bigint"?!0:Number.isInteger(r),Pu=r=>typeof r=="bigint"?r<0n?-r:r:r<0?-r:r,ue=Mt((r,e)=>r*e),wr=Mt((r,e)=>r/e),V=(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?Lu(n):n},Lu=r=>r.lower>r.upper?{lower:r.upper,upper:r.lower}:r,ms=(r,e)=>{const t=V(r);return e<t.lower?t.lower:e>=t.upper?t.upper-(typeof t.upper=="number"?1:1n):e},Gt=(r,e)=>{const t=V(r);if(typeof e=="number"||typeof e=="bigint")return e>=t.lower&&e<t.upper;const n=V(e);return n.lower>=t.lower&&n.upper<=t.upper},Bu=r=>({lower:Math.min(...r.map(e=>V(e).lower)),upper:Math.max(...r.map(e=>V(e).upper))}),qu=(r,e,t)=>{const n=r.map(c=>V(c)),i=t>0?1:t<0?-1:0;if(i===0)return e;let a=t,o=e;for(;ps(a,0)===!1;){const c=n.findIndex(u=>i>0?o>=u.lower&&o<u.upper:o>u.lower&&o<=u.upper);if(c!==-1){const u=n[c];let l;if(i>0?l=Ze(u.upper,o):l=Ze(o,u.lower),l>0){const h=Zu(Pu(a),l);if(o=Ut(o,i>0?h:-h),a=Ze(a,i>0?h:-h),ps(a,0))return o;continue}}if(i>0){const u=n.filter(l=>l.lower>o);if(u.length>0)o=u[0].lower;else return o}else{const u=n.filter(l=>l.upper<o);if(u.length>0)o=u[u.length-1].upper;else return o}}return o},Fu=(r,e,t)=>{const n=r.map(o=>V(o));if(e===t)return typeof e=="bigint"?0n:0;const i=e<t?V([e,t]):V([t,e]);let a=typeof e=="bigint"?0n:0;for(const o of n){const c=o.lower>i.lower?o.lower:i.lower,u=o.upper<i.upper?o.upper:i.upper;if(c<u){const l=u-c;a=a+l}}return a},Yu=In,Vu=kn,Hu=sn,_u={top:"bottom",right:"left",bottom:"top",left:"right",center:"center"},Wu={top:"left",right:"top",bottom:"right",left:"bottom",center:"center"},Gu=Du,ke=r=>r instanceof String||!Ii.includes(r)?r:r==="x"?"left":"top",Ku=r=>_u[ke(r)],Ju=r=>Wu[ke(r)],Et=r=>{const e=ke(r);return e==="top"||e==="bottom"?"y":"x"},Xu=s.z.object({x:In.or(sn),y:kn.or(sn)}),Ri=s.z.object({x:In,y:kn}),Rn=Object.freeze({x:"left",y:"top"}),ji=Object.freeze({x:"right",y:"top"}),Mi=Object.freeze({x:"left",y:"bottom"}),Ui=Object.freeze({x:"right",y:"bottom"}),jn=Object.freeze({x:"center",y:"center"}),Di=Object.freeze({x:"center",y:"top"}),Zi=Object.freeze({x:"center",y:"bottom"}),Pi=Object.freeze({x:"right",y:"center"}),Li=Object.freeze({x:"left",y:"center"}),Qu=Object.freeze([Li,Pi,Di,Zi,Rn,ji,Mi,Ui,jn]),Bi=(r,e)=>r.x===e.x&&r.y===e.y,eh=(r,e)=>{if(typeof e=="object"){let t=!0;return"x"in e&&(r.x===e.x||(t=!1)),"y"in e&&(r.y===e.y||(t=!1)),t}return r.x===e||r.y===e},th=r=>[r.x,r.y],rr=r=>Et(ke(r))==="x",rh=r=>Et(ke(r))==="y",nh=r=>`${r.x}${mi(r.y)}`,sh=(r,e)=>{let t,n;if(typeof r=="object"&&"x"in r?(t=r.x,n=r.y):(t=ke(r),n=ke(e??r)),Et(t)===Et(n)&&t!=="center"&&n!=="center")throw new Error(`[XYLocation] - encountered two locations with the same direction: ${t.toString()} - ${n.toString()}`);const i={...jn};return t==="center"?rr(n)?[i.x,i.y]=[n,t]:[i.x,i.y]=[t,n]:n==="center"?rr(t)?[i.x,i.y]=[t,n]:[i.x,i.y]=[n,t]:rr(t)?[i.x,i.y]=[t,n]:[i.x,i.y]=[n,t],i},ih=Object.freeze(Object.defineProperty({__proto__:null,BOTTOM_CENTER:Zi,BOTTOM_LEFT:Mi,BOTTOM_RIGHT:Ui,CENTER:jn,CENTER_LEFT:Li,CENTER_LOCATIONS:xn,CENTER_RIGHT:Pi,OUTER_LOCATIONS:$n,TOP_CENTER:Di,TOP_LEFT:Rn,TOP_RIGHT:ji,XY_LOCATIONS:Qu,X_LOCATIONS:xi,Y_LOCATIONS:Ci,center:Hu,construct:ke,constructXY:sh,corner:Ri,crude:Gu,direction:Et,isX:rr,isY:rh,location:Cn,outer:Cu,rotate90:Ju,swap:Ku,x:Yu,xy:Xu,xyCouple:th,xyEquals:Bi,xyMatches:eh,xyToString:nh,y:Vu},Symbol.toStringTag,{value:"Module"})),on=s.z.union([s.z.number(),vt,mr,Ai,$u,$i]),R=(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}},Le=Object.freeze({x:0,y:0}),ah=Object.freeze({x:1,y:1}),oh=Object.freeze({x:1/0,y:1/0}),ch=Object.freeze({x:NaN,y:NaN}),qi=(r,e,t=0)=>{const n=R(r),i=R(e);return t===0?n.x===i.x&&n.y===i.y:Math.abs(n.x-i.x)<=t&&Math.abs(n.y-i.y)<=t},lh=r=>qi(r,Le),Mn=(r,e,t)=>{const n=R(r),i=R(e,t);return{x:n.x*i.x,y:n.y*i.y}},Fi=(r,e)=>{const t=R(r);return{x:t.x+e,y:t.y}},Yi=(r,e)=>{const t=R(r);return{x:t.x,y:t.y+e}},Vi=(r,e,t,...n)=>{if(typeof e=="string"){if(typeof t!="number")throw new Error("The value must be a number.");return e==="x"?Fi(r,t):Yi(r,t)}if(typeof e=="object"&&"x"in e&&typeof e.x=="string"){const i=R(t),a=R(r);return e.x==="left"?i.x=-i.x:e.x==="center"&&(i.x=0),e.y==="top"?i.y=-i.y:e.y==="center"&&(i.y=0),{x:a.x+i.x,y:a.y+i.y}}return[r,e,t??Le,...n].reduce((i,a)=>{const o=R(a);return{x:i.x+o.x,y:i.y+o.y}},Le)},uh=(r,e,t)=>{const n=R(r);return e==="x"?{x:t,y:n.y}:{x:n.x,y:t}},hh=(r,e)=>{const t=R(r),n=R(e);return Math.sqrt((t.x-n.x)**2+(t.y-n.y)**2)},fh=(r,e)=>{const t=R(r),n=R(e);return{x:n.x-t.x,y:n.y-t.y}},dh=r=>{const e=R(r);return Number.isNaN(e.x)||Number.isNaN(e.y)},yh=r=>{const e=R(r);return Number.isFinite(e.x)&&Number.isFinite(e.y)},gh=r=>{const e=R(r);return[e.x,e.y]},ph=r=>{const e=R(r);return{left:e.x,top:e.y}},mh=(r,e=0)=>{const t=R(r);return{x:Number(t.x.toFixed(e)),y:Number(t.y.toFixed(e))}},gt=(r,e)=>{const t=R(r),n=R(e);return{x:t.x-n.x,y:t.y-n.y}},pt=r=>{const e=R(r),t=Math.hypot(e.x,e.y);return t===0?{x:0,y:0}:{x:-e.y/t,y:e.x/t}},Hi=r=>{const e=R(r),t=Math.hypot(e.x,e.y);return t===0?{x:0,y:0}:{x:e.x/t,y:e.y/t}},_i=(...r)=>{const e=r.reduce((t,n)=>Vi(t,n),Le);return Mn(e,1/r.length)},wh=(r,e)=>{const t=[];for(let n=0;n<r.length;n++){const i=r[n];let a,o,c,u;if(n===0){const l=r[n+1],h=gt(l,i);o=pt(h),c=o,u=e}else if(n===r.length-1){const l=r[n-1],h=gt(i,l);a=pt(h),c=a,u=e}else{const l=r[n-1],h=r[n+1],y=gt(i,l),d=gt(h,i);a=pt(y),o=pt(d);const N=Math.acos((y.x*d.x+y.y*d.y)/(Math.hypot(y.x,y.y)*Math.hypot(d.x,d.y))),S=Math.sin(N/2);S===0?u=e:u=e/S,c=Hi(_i(a,o))}t.push(Mn(c,u))}return t},bh=r=>{const e=R(r);return{x:e.y,y:e.x}},Th=r=>{const e=R(r);return{x:Math.round(e.x),y:Math.round(e.y)}},Wi=Object.freeze(Object.defineProperty({__proto__:null,INFINITY:oh,NAN:ch,ONE:ah,ZERO:Le,average:_i,calculateMiters:wh,clientXY:$i,construct:R,couple:gh,crudeZ:on,css:ph,distance:hh,equals:qi,isFinite:yh,isNan:dh,isZero:lh,normal:pt,normalize:Hi,round:Th,scale:Mn,set:uh,sub:gt,swap:bh,translate:Vi,translateX:Fi,translateY:Yi,translation:fh,truncate:mh,xy:vt},Symbol.toStringTag,{value:"Module"})),Kt=s.z.union([s.z.number(),s.z.string()]);s.z.object({top:Kt,left:Kt,width:Kt,height:Kt});s.z.object({left:s.z.number(),top:s.z.number(),right:s.z.number(),bottom:s.z.number()});s.z.object({one:vt,two:vt,root:Ri});const Un=(r,e,t=0,n=0,i)=>{const a={one:{...Le},two:{...Le},root:i??Rn};if(typeof r=="number"){if(typeof e!="number")throw new Error("Box constructor called with invalid arguments");return a.one={x:r,y:e},a.two={x:a.one.x+t,y:a.one.y+n},a}return"one"in r&&"two"in r&&"root"in r?{...r,root:i??r.root}:("getBoundingClientRect"in r&&(r=r.getBoundingClientRect()),"left"in r?(a.one={x:r.left,y:r.top},a.two={x:r.right,y:r.bottom},a):(a.one=r,e==null?a.two={x:a.one.x+t,y:a.one.y+n}:typeof e=="number"?a.two={x:a.one.x+e,y:a.one.y+t}:"width"in e?a.two={x:a.one.x+e.width,y:a.one.y+e.height}:"signedWidth"in e?a.two={x:a.one.x+e.signedWidth,y:a.one.y+e.signedHeight}:a.two=e,a))},Zr=r=>{const e=Un(r);return{lower:e.one.x,upper:e.two.x}},Pr=r=>{const e=Un(r);return{lower:e.one.y,upper:e.two.y}},vh=r=>typeof r!="object"||r==null?!1:"one"in r&&"two"in r&&"root"in r,Eh=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()});s.z.union([Ai,Eh,vt,mr]);const Nh=(r,e,t)=>e!==void 0&&r<e?e:t!==void 0&&r>t?t:r;s.z.object({offset:on,scale:on});s.z.object({offset:s.z.number(),scale:s.z.number()});const Oh=r=>(e,t,n,i)=>t==="dimension"?[e,n]:[e,i?n-r:n+r],zh=r=>(e,t,n,i)=>[e,i?n/r:n*r],Sh=r=>(e,t,n)=>{if(e===null)return[r,n];const{lower:i,upper:a}=e,{lower:o,upper:c}=r,u=a-i,l=c-o;if(t==="dimension")return[r,n*(l/u)];const h=(n-i)*(l/u)+o;return[r,h]},Ah=r=>(e,t,n)=>[r,n],$h=()=>(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)]},Ih=r=>(e,t,n)=>{const{lower:i,upper:a}=r;return n=Nh(n,i,a),[e,n]};let ws=class _e{ops=[];currBounds=null;currType=null;reversed=!1;constructor(){this.ops=[]}static translate(e){return new _e().translate(e)}static magnify(e){return new _e().magnify(e)}static scale(e,t){return new _e().scale(e,t)}translate(e){const t=this.new(),n=Oh(e);return n.type="translate",t.ops.push(n),t}magnify(e){const t=this.new(),n=zh(e);return n.type="magnify",t.ops.push(n),t}scale(e,t){const n=V(e,t),i=this.new(),a=Sh(n);return a.type="scale",i.ops.push(a),i}clamp(e,t){const n=V(e,t),i=this.new(),a=Ih(n);return a.type="clamp",i.ops.push(a),i}reBound(e,t){const n=V(e,t),i=this.new(),a=Ah(n);return a.type="re-bound",i.ops.push(a),i}invert(){const e=$h();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 _e;return e.ops=this.ops.slice(),e.reversed=this.reversed,e}exec(e,t){return this.currBounds=null,this.ops.reduce(([n,i],a)=>a(n,e,i,this.reversed),[null,t])[1]}reverse(){const e=this.new();e.ops.reverse();const t=[];return e.ops.forEach((n,i)=>{if(n.type==="scale"||t.some(([o,c])=>i>=o&&i<=c))return;const a=e.ops.findIndex((o,c)=>o.type==="scale"&&c>i);a!==-1&&t.push([i,a])}),t.forEach(([n,i])=>{const a=e.ops.slice(n,i);a.unshift(e.ops[i]),e.ops.splice(n,i-n+1,...a)}),e.reversed=!e.reversed,e}get transform(){return{scale:this.dim(1),offset:this.pos(0)}}static IDENTITY=new _e},Lb=class ce{x;y;currRoot;constructor(e=new ws,t=new ws,n=null){this.x=e,this.y=t,this.currRoot=n}static translate(e,t){return new ce().translate(e,t)}static translateX(e){return new ce().translateX(e)}static translateY(e){return new ce().translateY(e)}static clamp(e){return new ce().clamp(e)}static magnify(e){return new ce().magnify(e)}static scale(e){return new ce().scale(e)}static reBound(e){return new ce().reBound(e)}translate(e,t){const n=R(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(vh(e)){const n=this.currRoot;return t.currRoot=e.root,n!=null&&!Bi(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(Zr(e)),t.y=t.y.scale(Pr(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(Zr(e)),t.y=this.y.reBound(Pr(e)),t}clamp(e){const t=this.copy();return t.x=this.x.clamp(Zr(e)),t.y=this.y.clamp(Pr(e)),t}copy(){const e=new ce;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 Un(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 ce},Gi=(r,e=21)=>(t=e)=>{let n="",i=t|0;for(;i--;)n+=r[Math.random()*r.length|0];return n};const Ki="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",kh=`0123456789${Ki}`,Ji=11,xh=Gi(Ki,1),Ch=Gi(kh,Ji-1),Dn=()=>`${xh()}${Ch()}`,Rh=Object.freeze(Object.defineProperty({__proto__:null,LENGTH:Ji,create:Dn},Symbol.toStringTag,{value:"Module"})),jh=(r,e)=>t=>t instanceof e||typeof t=="object"&&t!==null&&"discriminator"in t&&t.discriminator===r,Mh=s.z.enum(["static","dynamic"]),Uh=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)])]),Xi=(r,e)=>{const t=new f(e);if(![E.DAY,E.HOUR,E.MINUTE,E.SECOND,E.MILLISECOND,E.MICROSECOND,E.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 f?new f(n):new E(n)};class f extends nt{constructor(e,t="UTC"){if(e==null)super(f.now().valueOf());else if(e instanceof Date)super(BigInt(e.getTime())*f.MILLISECOND.valueOf());else if(typeof e=="string")super(f.parseDateTimeString(e,t).valueOf());else if(Array.isArray(e))super(f.parseDate(e));else{let n=0n;e instanceof Number&&(e=e.valueOf()),t==="local"&&(n=f.utcOffset.valueOf()),typeof e=="number"&&(isFinite(e)?e=Math.trunc(e):(isNaN(e)&&(e=0),e===1/0?e=f.MAX:e=f.MIN)),Q(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 f(BigInt(i.getTime())*f.MILLISECOND.valueOf()).truncate(f.DAY).valueOf()}valueOf(){return this.value}static parseTimeString(e,t="UTC"){const[n,i,a]=e.split(":");let o="00",c="00";a!=null&&([o,c]=a.split("."));let u=f.hours(parseInt(n??"00")).add(f.minutes(parseInt(i??"00"))).add(f.seconds(parseInt(o??"00"))).add(f.milliseconds(parseInt(c??"00")));return t==="local"&&(u=u.add(f.utcOffset)),u.valueOf()}static parseDateTimeString(e,t="UTC"){if(!e.includes("/")&&!e.includes("-"))return f.parseTimeString(e,t);const n=new Date(e);return e.includes(":")||n.setUTCHours(0,0,0,0),new f(BigInt(n.getTime())*f.MILLISECOND.valueOf(),t).valueOf()}fString(e="ISO",t="UTC"){switch(e){case"ISODate":return this.toISOString(t).slice(0,10);case"ISOTime":return this.toISOString(t).slice(11,23);case"time":return this.timeString(!1,t);case"preciseTime":return this.timeString(!0,t);case"date":return this.dateString();case"preciseDate":return`${this.dateString()} ${this.timeString(!0,t)}`;case"dateTime":return`${this.dateString()} ${this.timeString(!1,t)}`;default:return this.toISOString(t)}}toISOString(e="UTC"){return e==="UTC"?this.date().toISOString():this.sub(f.utcOffset).date().toISOString()}timeString(e=!1,t="UTC"){const 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 E(BigInt(new Date().getTimezoneOffset())*f.MINUTE.valueOf())}static since(e){return new f().span(e)}date(){return new Date(this.milliseconds)}equals(e){return this.valueOf()===new f(e).valueOf()}span(e){return this.range(e).span}range(e){return new M(this,e).makeValid()}spanRange(e){return this.range(this.add(e)).makeValid()}get isZero(){return this.valueOf()===0n}after(e){return this.valueOf()>new f(e).valueOf()}afterEq(e){return this.valueOf()>=new f(e).valueOf()}before(e){return this.valueOf()<new f(e).valueOf()}beforeEq(e){return this.valueOf()<=new f(e).valueOf()}add(e){return new f(Ut(this.valueOf(),new E(e).valueOf()))}sub(e){return new f(Ze(this.valueOf(),new E(e).valueOf()))}get hours(){return Number(this.valueOf())/Number(E.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(E.MINUTE.valueOf())}get days(){return Number(this.valueOf())/Number(E.DAY.valueOf())}get seconds(){return Number(this.valueOf())/Number(E.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(f.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(f.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get year(){return this.date().getUTCFullYear()}setYear(e){const t=this.date();return t.setUTCFullYear(e),new f(t)}get month(){return this.date().getUTCMonth()}setMonth(e){const t=this.date();return t.setUTCMonth(e),new f(t)}get day(){return this.date().getUTCDate()}setDay(e){const t=this.date();return t.setUTCDate(e),new f(t)}get hour(){return this.date().getUTCHours()}get localHour(){return this.date().getHours()}setLocalHour(e){const t=this.date();return t.setHours(e),new f(t)}setHour(e){const t=this.date();return t.setUTCHours(e),new f(t)}get minute(){return this.date().getUTCMinutes()}setMinute(e){const t=this.date();return t.setUTCMinutes(e),new f(t)}get second(){return this.date().getUTCSeconds()}setSecond(e){const t=this.date();return t.setUTCSeconds(e),new f(t)}get millisecond(){return this.date().getUTCMilliseconds()}setMillisecond(e){const t=this.date();return t.setUTCMilliseconds(e),new f(t)}toString(){return this.date().toISOString()}remainder(e){return Xi(this,e)}get isToday(){return this.truncate(E.DAY).equals(f.now().truncate(E.DAY))}truncate(e){return this.sub(this.remainder(e))}static now(){return new f(new Date)}static max(...e){let t=f.MIN;for(const n of e){const i=new f(n);i.after(t)&&(t=i)}return t}static min(...e){let t=f.MAX;for(const n of e){const i=new f(n);i.before(t)&&(t=i)}return t}static nanoseconds(e,t="UTC"){return new f(e,t)}static NANOSECOND=f.nanoseconds(1);static microseconds(e,t="UTC"){return f.nanoseconds(e*1e3,t)}static MICROSECOND=f.microseconds(1);static milliseconds(e,t="UTC"){return f.microseconds(e*1e3,t)}static MILLISECOND=f.milliseconds(1);static seconds(e,t="UTC"){return f.milliseconds(e*1e3,t)}static SECOND=f.seconds(1);static minutes(e,t="UTC"){return f.seconds(e*60,t)}static MINUTE=f.minutes(1);static hours(e,t="UTC"){return f.minutes(e*60,t)}static HOUR=f.hours(1);static days(e,t="UTC"){return f.hours(e*24,t)}static DAY=f.days(1);static MAX=new f((1n<<63n)-1n);static MIN=new f(0);static ZERO=new f(0);static z=s.z.union([s.z.instanceof(f),s.z.object({value:s.z.bigint()}).transform(e=>new f(e.value)),s.z.string().transform(e=>new f(BigInt(e))),s.z.number().transform(e=>new f(e)),s.z.bigint().transform(e=>new f(e)),s.z.date().transform(e=>new f(e)),s.z.custom(e=>e instanceof E).transform(e=>new f(e)),Uh.transform(e=>new f(e))]);static sort(e,t){return Number(e.valueOf()-t.valueOf())}}let E=class T extends nt{constructor(e){typeof e=="number"&&(e=Math.trunc(e.valueOf())),Q(e)&&(e=e.value),super(BigInt(e.valueOf()))}static fromSeconds(e){return e instanceof T?e:e instanceof W?e.period:e instanceof f?new T(e):(Q(e)&&(e=e.value),["number","bigint"].includes(typeof e)?T.seconds(e):new T(e))}static fromMilliseconds(e){return e instanceof T?e:e instanceof W?e.period:e instanceof f?new T(e):(Q(e)&&(e=e.value),["number","bigint"].includes(typeof e)?T.milliseconds(e):new T(e))}valueOf(){return this.value}lessThan(e){return this.valueOf()<new T(e).valueOf()}greaterThan(e){return this.valueOf()>new T(e).valueOf()}lessThanOrEqual(e){return this.valueOf()<=new T(e).valueOf()}greaterThanOrEqual(e){return this.valueOf()>=new T(e).valueOf()}remainder(e){return Xi(this,e)}truncate(e){return new T(BigInt(Math.trunc(Number(this.valueOf()/e.valueOf())))*e.valueOf())}toString(){const e=this.truncate(T.DAY),t=this.truncate(T.HOUR),n=this.truncate(T.MINUTE),i=this.truncate(T.SECOND),a=this.truncate(T.MILLISECOND),o=this.truncate(T.MICROSECOND),c=this.truncate(T.NANOSECOND),u=e,l=t.sub(e),h=n.sub(t),y=i.sub(n),d=a.sub(i),N=o.sub(a),S=c.sub(o);let k="";return u.isZero||(k+=`${u.days}d `),l.isZero||(k+=`${l.hours}h `),h.isZero||(k+=`${h.minutes}m `),y.isZero||(k+=`${y.seconds}s `),d.isZero||(k+=`${d.milliseconds}ms `),N.isZero||(k+=`${N.microseconds}µs `),S.isZero||(k+=`${S.nanoseconds}ns`),k.trim()}mult(e){return new T(ue(this.valueOf(),e))}div(e){return new T(wr(this.valueOf(),e))}get days(){return Number(this.valueOf())/Number(T.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(T.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(T.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(T.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(T.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(T.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get isZero(){return this.valueOf()===0n}equals(e){return this.valueOf()===new T(e).valueOf()}add(e){return new T(this.valueOf()+new T(e).valueOf())}sub(e){return new T(this.valueOf()-new T(e).valueOf())}static nanoseconds(e=1){return new T(e)}static NANOSECOND=T.nanoseconds(1);static microseconds(e=1){return T.nanoseconds(ue(e,1e3))}static MICROSECOND=T.microseconds(1);static milliseconds(e=1){return T.microseconds(ue(e,1e3))}static MILLISECOND=T.milliseconds(1);static seconds(e=1){return T.milliseconds(ue(e,1e3))}static SECOND=T.seconds(1);static minutes(e=1){return T.seconds(ue(e,60))}static MINUTE=T.minutes(1);static hours(e){return T.minutes(ue(e,60))}static HOUR=T.hours(1);static days(e){return T.hours(ue(e,24))}static DAY=T.days(1);static MAX=new T((1n<<63n)-1n);static MIN=new T(0);static ZERO=new T(0);static z=s.z.union([s.z.object({value:s.z.bigint()}).transform(e=>new T(e.value)),s.z.string().transform(e=>new T(BigInt(e))),s.z.number().transform(e=>new T(e)),s.z.bigint().transform(e=>new T(e)),s.z.instanceof(T),s.z.instanceof(f).transform(e=>new T(e)),s.z.custom(e=>e instanceof W).transform(e=>new T(e))])};class W extends nt{constructor(e){Q(e)&&(e=e.value),super(e.valueOf())}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new W(e).valueOf()}get period(){return E.seconds(1/this.valueOf())}sampleCount(e){return new E(e).seconds*this.valueOf()}byteCount(e,t){return this.sampleCount(e)*new Y(t).valueOf()}span(e){return E.seconds(e/this.valueOf())}byteSpan(e,t){return this.span(e.valueOf()/new Y(t).valueOf())}add(e){return new W(Ut(this.valueOf(),new W(e).valueOf()))}sub(e){return new W(Ze(this.valueOf(),new W(e).valueOf()))}mult(e){return new W(ue(this.valueOf(),e))}div(e){return new W(wr(this.valueOf(),e))}static hz(e){return new W(e)}static khz(e){return W.hz(e*1e3)}static z=s.z.union([s.z.number().transform(e=>new W(e)),s.z.instanceof(W)])}let Y=class K extends nt{constructor(e){Q(e)&&(e=e.value),super(e.valueOf())}length(e){return e.valueOf()/this.valueOf()}size(e){return new et(e*this.valueOf())}add(e){return new K(Ut(this.valueOf(),new K(e).valueOf()))}sub(e){return new K(Ze(this.valueOf(),new K(e).valueOf()))}mult(e){return new K(ue(this.valueOf(),e))}div(e){return new K(wr(this.valueOf(),e))}static UNKNOWN=new K(0);static BIT128=new K(16);static BIT64=new K(8);static BIT32=new K(4);static BIT16=new K(2);static BIT8=new K(1);static z=s.z.union([s.z.number().transform(e=>new K(e)),s.z.instanceof(K)])},M=class ne{start;end;constructor(e,t){typeof e=="object"&&"start"in e?(this.start=new f(e.start),this.end=new f(e.end)):(this.start=new f(e),this.end=new f(t))}get span(){return new E(this.end.valueOf()-this.start.valueOf())}get isValid(){return this.start.valueOf()<=this.end.valueOf()}makeValid(){return this.isValid?this:this.swap()}get isZero(){return this.span.isZero}get numeric(){return{start:Number(this.start.valueOf()),end:Number(this.end.valueOf())}}swap(){return new ne(this.end,this.start)}get numericBounds(){return{lower:Number(this.start.valueOf()),upper:Number(this.end.valueOf())}}equals(e,t=E.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.fString("preciseDate")} - ${this.span.toString()}`}overlapsWith(e,t=E.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=f.max(n.start,e.start),a=f.min(n.end,e.end);return a.before(i)?!1:new E(a.sub(i)).greaterThanOrEqual(t)}contains(e){return e instanceof ne?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const t=new ne(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 ne(f.min(...e.map(t=>t.start)),f.max(...e.map(t=>t.end)))}static MAX=new ne(f.MIN,f.MAX);static MIN=new ne(f.MAX,f.MIN);static ZERO=new ne(f.ZERO,f.ZERO);static z=s.z.union([s.z.object({start:f.z,end:f.z}).transform(e=>new ne(e.start,e.end)),s.z.instanceof(ne)]);static sort(e,t){return f.sort(e.start,t.start)||f.sort(e.end,t.end)}static simplify(e){return e.map(t=>t.makeValid()).sort((t,n)=>ne.sort(t,n)).reduce((t,n)=>{if(n.isZero)return t;if(t.length===0)return t.push(n),t;const i=t[t.length-1];return i.overlapsWith(n)||i.end.equals(n.start)?i.end=f.max(i.end,n.end):t.push(n),t},[])}},$=class p extends nt{constructor(e){if(Q(e)&&(e=e.value),e instanceof p||typeof e=="string"||typeof e.valueOf()=="string")super(e.valueOf());else{const t=p.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=p.ARRAY_CONSTRUCTORS.get(this.toString());if(e==null)throw new Error(`unable to find array constructor for ${this.valueOf()}`);return e}equals(e){return this.valueOf()===e.valueOf()}matches(...e){return e.some(t=>this.equals(t))}toString(){return this.valueOf()}get isVariable(){return this.equals(p.JSON)||this.equals(p.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(p.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=p.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}get isUnsignedInteger(){return this.equals(p.UINT8)||this.equals(p.UINT16)||this.equals(p.UINT32)||this.equals(p.UINT64)}get isSignedInteger(){return this.equals(p.INT8)||this.equals(p.INT16)||this.equals(p.INT32)||this.equals(p.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(p.INT32)&&e.equals(p.FLOAT64)||this.equals(p.INT8)&&e.equals(p.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 p.BIG_INT_TYPES.some(e=>e.equals(this))}static UNKNOWN=new p("unknown");static FLOAT64=new p("float64");static FLOAT32=new p("float32");static INT64=new p("int64");static INT32=new p("int32");static INT16=new p("int16");static INT8=new p("int8");static UINT64=new p("uint64");static UINT32=new p("uint32");static UINT16=new p("uint16");static UINT8=new p("uint8");static BOOLEAN=this.UINT8;static TIMESTAMP=new p("timestamp");static UUID=new p("uuid");static STRING=new p("string");static JSON=new p("json");static ARRAY_CONSTRUCTORS=new Map([[p.UINT8.toString(),Uint8Array],[p.UINT16.toString(),Uint16Array],[p.UINT32.toString(),Uint32Array],[p.UINT64.toString(),BigUint64Array],[p.FLOAT32.toString(),Float32Array],[p.FLOAT64.toString(),Float64Array],[p.INT8.toString(),Int8Array],[p.INT16.toString(),Int16Array],[p.INT32.toString(),Int32Array],[p.INT64.toString(),BigInt64Array],[p.TIMESTAMP.toString(),BigInt64Array],[p.STRING.toString(),Uint8Array],[p.JSON.toString(),Uint8Array],[p.UUID.toString(),Uint8Array]]);static ARRAY_CONSTRUCTOR_DATA_TYPES=new Map([[Uint8Array.name,p.UINT8],[Uint16Array.name,p.UINT16],[Uint32Array.name,p.UINT32],[BigUint64Array.name,p.UINT64],[Float32Array.name,p.FLOAT32],[Float64Array.name,p.FLOAT64],[Int8Array.name,p.INT8],[Int16Array.name,p.INT16],[Int32Array.name,p.INT32],[BigInt64Array.name,p.INT64]]);static DENSITIES=new Map([[p.UINT8.toString(),Y.BIT8],[p.UINT16.toString(),Y.BIT16],[p.UINT32.toString(),Y.BIT32],[p.UINT64.toString(),Y.BIT64],[p.FLOAT32.toString(),Y.BIT32],[p.FLOAT64.toString(),Y.BIT64],[p.INT8.toString(),Y.BIT8],[p.INT16.toString(),Y.BIT16],[p.INT32.toString(),Y.BIT32],[p.INT64.toString(),Y.BIT64],[p.TIMESTAMP.toString(),Y.BIT64],[p.STRING.toString(),Y.UNKNOWN],[p.JSON.toString(),Y.UNKNOWN],[p.UUID.toString(),Y.BIT128]]);static ALL=[p.UNKNOWN,p.FLOAT64,p.FLOAT32,p.INT64,p.INT32,p.INT16,p.INT8,p.UINT64,p.UINT32,p.UINT16,p.UINT8,p.TIMESTAMP,p.UUID,p.STRING,p.JSON];static BIG_INT_TYPES=[p.INT64,p.UINT64,p.TIMESTAMP];static z=s.z.union([s.z.string().transform(e=>new p(e)),s.z.instanceof(p)])},et=class z extends nt{constructor(e){Q(e)&&(e=e.value),super(e.valueOf())}largerThan(e){return Q(e)&&(e=e.value),this.valueOf()>e.valueOf()}smallerThan(e){return Q(e)&&(e=e.value),this.valueOf()<e.valueOf()}add(e){return Q(e)&&(e=e.value),new z(Ut(this.valueOf(),e.valueOf()))}sub(e){return Q(e)&&(e=e.value),new z(Ze(this.valueOf(),e.valueOf()))}mult(e){return new z(ue(this.valueOf(),e))}div(e){return new z(wr(this.valueOf(),e))}truncate(e){return new z(Math.trunc(this.valueOf()/new z(e).valueOf())*new z(e).valueOf())}remainder(e){return z.bytes(this.valueOf()%new z(e).valueOf())}get gigabytes(){return this.valueOf()/z.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/z.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/z.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/z.TERABYTE.valueOf()}toString(){const e=this.truncate(z.TERABYTE),t=this.truncate(z.GIGABYTE),n=this.truncate(z.MEGABYTE),i=this.truncate(z.KILOBYTE),a=this.truncate(z.BYTE),o=e,c=t.sub(e),u=n.sub(t),l=i.sub(n),h=a.sub(i);let y="";return o.isZero||(y+=`${o.terabytes}TB `),c.isZero||(y+=`${c.gigabytes}GB `),u.isZero||(y+=`${u.megabytes}MB `),l.isZero||(y+=`${l.kilobytes}KB `),(!h.isZero||y==="")&&(y+=`${h.valueOf()}B`),y.trim()}static bytes(e=1){return new z(e)}static BYTE=new z(1);static kilobytes(e=1){return z.bytes(new z(e).valueOf()*1e3)}static KILOBYTE=z.kilobytes(1);static megabytes(e=1){return z.kilobytes(new z(e).valueOf()*1e3)}static MEGABYTE=z.megabytes(1);static gigabytes(e=1){return z.megabytes(new z(e).valueOf()*1e3)}static GIGABYTE=z.gigabytes(1);static terabytes(e){return z.gigabytes(new z(e).valueOf()*1e3)}static TERABYTE=z.terabytes(1);static ZERO=new z(0);static z=s.z.union([s.z.number().transform(e=>new z(e)),s.z.instanceof(z)]);get isZero(){return this.valueOf()===0}};s.z.union([s.z.instanceof(Uint8Array),s.z.instanceof(Uint16Array),s.z.instanceof(Uint32Array),s.z.instanceof(BigUint64Array),s.z.instanceof(Float32Array),s.z.instanceof(Float64Array),s.z.instanceof(Int8Array),s.z.instanceof(Int16Array),s.z.instanceof(Int32Array),s.z.instanceof(BigInt64Array)]);const Qi=r=>{const e=typeof r;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||r instanceof f||r instanceof E||r instanceof Date},Dh=(r,e,t,n=0)=>r.usesBigInt&&!e.usesBigInt?Number(t)-Number(n):!r.usesBigInt&&e.usesBigInt?BigInt(t.valueOf())-BigInt(n.valueOf()):nr(t,-n),nr=(r,e)=>e==0?r:r==0?e:typeof r=="bigint"&&typeof e=="bigint"||typeof r=="number"&&typeof e=="number"?r+e:Number(r)+Number(e),Zh=/^(?:[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 Ph(r){return typeof r=="string"&&Zh.test(r)}const F=[];for(let r=0;r<256;++r)F.push((r+256).toString(16).slice(1));function Lh(r,e=0){return(F[r[e+0]]+F[r[e+1]]+F[r[e+2]]+F[r[e+3]]+"-"+F[r[e+4]]+F[r[e+5]]+"-"+F[r[e+6]]+F[r[e+7]]+"-"+F[r[e+8]]+F[r[e+9]]+"-"+F[r[e+10]]+F[r[e+11]]+F[r[e+12]]+F[r[e+13]]+F[r[e+14]]+F[r[e+15]]).toLowerCase()}function Bh(r,e=0){const t=Lh(r,e);if(!Ph(t))throw TypeError("Stringified UUID is invalid");return t}typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const ea=(r,e)=>Bh(r,e),Ne=-1,cn={[Symbol.iterator]:()=>cn,next:()=>({done:!0,value:void 0})},qh=s.z.string().transform(r=>new Uint8Array(atob(r).split("").map(e=>e.charCodeAt(0))).buffer),Fh=s.z.union([s.z.null(),s.z.undefined()]).transform(()=>new Uint8Array().buffer),ln=10,ta=(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`)},ra="sy_x_telem_series";let ge=class Ae{key;discriminator=ra;dataType;sampleOffset;gl;_data;timeRange=M.ZERO;alignment=0n;alignmentMultiple=1n;cachedMin;cachedMax;writePos=Ne;_refCount=0;cachedLength;_cachedIndexes;static crudeZ=s.z.object({timeRange:M.z.optional(),dataType:$.z,alignment:s.z.coerce.bigint().optional(),data:s.z.union([qh,Fh,s.z.instanceof(ArrayBuffer),s.z.instanceof(Uint8Array)]),glBufferUsage:Mh.optional().default("static").optional()});static z=Ae.crudeZ.transform(e=>new Ae(e));constructor(e){Yh(e)&&(e={data:e}),e.data??=[];const{dataType:t,timeRange:n,sampleOffset:i=0,glBufferUsage:a="static",alignment:o=0n,alignmentMultiple:c=1n,key:u=Dn(),data:l}=e;if(na(l)){const d=l;this.key=d.key,this.dataType=d.dataType,this.sampleOffset=d.sampleOffset,this.gl=d.gl,this._data=d._data,this.timeRange=d.timeRange,this.alignment=d.alignment,this.alignmentMultiple=d.alignmentMultiple,this.cachedMin=d.cachedMin,this.cachedMax=d.cachedMax,this.writePos=d.writePos,this._refCount=d._refCount,this.cachedLength=d.cachedLength;return}const h=Qi(l),y=Array.isArray(l);if(t!=null)this.dataType=new $(t);else{if(l instanceof ArrayBuffer)throw new Error("cannot infer data type from an ArrayBuffer instance when constructing a Series. Please provide a data type.");if(y||h){let d=l;if(!h){if(l.length===0)throw new Error("cannot infer data type from a zero length JS array when constructing a Series. Please provide a data type.");d=l[0]}if(typeof d=="string")this.dataType=$.STRING;else if(typeof d=="number")this.dataType=$.FLOAT64;else if(typeof d=="bigint")this.dataType=$.INT64;else if(typeof d=="boolean")this.dataType=$.BOOLEAN;else if(d instanceof f||d instanceof Date||d instanceof f)this.dataType=$.TIMESTAMP;else if(typeof d=="object")this.dataType=$.JSON;else throw new Error(`cannot infer data type of ${typeof d} when constructing a Series from a JS array`)}else this.dataType=new $(l)}if(!y&&!h)this._data=l;else if(y&&l.length===0)this._data=new this.dataType.Array([]).buffer;else{let d=h?[l]:l;const N=d[0];(N instanceof f||N instanceof Date||N instanceof E)&&(d=d.map(S=>new f(S).valueOf())),this.dataType.equals($.STRING)?(this.cachedLength=d.length,this._data=new TextEncoder().encode(`${d.join(`
|
|
9
9
|
`)}
|
|
10
10
|
`).buffer):this.dataType.equals($.JSON)?(this.cachedLength=d.length,this._data=new TextEncoder().encode(`${d.map(S=>Tt.encodeString(S)).join(`
|
|
11
11
|
`)}
|
|
12
12
|
`).buffer):this.dataType.usesBigInt&&typeof N=="number"?this._data=new this.dataType.Array(d.map(S=>BigInt(Math.round(S)))).buffer:!this.dataType.usesBigInt&&typeof N=="bigint"?this._data=new this.dataType.Array(d.map(Number)).buffer:this._data=new this.dataType.Array(d).buffer}this.key=u,this.alignment=o,this.alignmentMultiple=c,this.sampleOffset=i??0,this.timeRange=n??M.ZERO,this.gl={control:null,buffer:null,prevBuffer:0,bufferUsage:a}}static alloc({capacity:e,dataType:t,...n}){if(e===0)throw new Error("[Series] - cannot allocate an array of length 0");const i=new new $(t).Array(e),a=new Ae({data:i.buffer,dataType:t,...n});return a.writePos=0,a}get refCount(){return this._refCount}acquire(e){this._refCount++,e!=null&&this.updateGLBuffer(e)}release(){this._refCount--,this.refCount===0&&this.gl.control!=null?this.maybeGarbageCollectGLBuffer(this.gl.control):this.refCount<0&&console.warn("cannot release a series with a negative reference count")}write(e){if(!e.dataType.equals(this.dataType))throw new Error("buffer must be of the same type as this array");return this.dataType.isVariable?this.writeVariable(e):this.writeFixed(e)}writeVariable(e){if(this.writePos===Ne)return 0;const t=this.byteCapacity.valueOf()-this.writePos,n=e.subBytes(0,t);return this.writeToUnderlyingData(n),this.writePos+=n.byteLength.valueOf(),this.cachedLength!=null&&(this.cachedLength+=n.length,this.calculateCachedLength()),n.length}writeFixed(e){if(this.writePos===Ne)return 0;const t=this.capacity-this.writePos,n=e.sub(0,t);return this.writeToUnderlyingData(n),this.cachedLength=void 0,this.maybeRecomputeMinMax(n),this.writePos+=n.length,n.length}writeToUnderlyingData(e){this.underlyingData.set(e.data,this.writePos)}get buffer(){return typeof this._data=="object"&&"buffer"in this._data?this._data.buffer:this._data}get underlyingData(){return new this.dataType.Array(this._data)}get data(){return this.writePos===Ne?this.underlyingData:new this.dataType.Array(this._data,0,this.writePos)}toStrings(){return this.dataType.isVariable?new TextDecoder().decode(this.underlyingData).split(`
|
|
13
|
-
`).slice(0,-1):Array.from(this).map(e=>e.toString())}parseJSON(e){if(!this.dataType.equals($.JSON))throw new Error("cannot parse non-JSON series as JSON");return this.toStrings().map(t=>e.parse(Tt.decodeString(t)))}get byteCapacity(){return new et(this.underlyingData.byteLength)}get capacity(){return this.dataType.isVariable?this.byteCapacity.valueOf():this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===Ne?this.byteCapacity:this.dataType.isVariable?new et(this.writePos):this.dataType.density.size(this.writePos)}get length(){return this.cachedLength!=null?this.cachedLength:this.dataType.isVariable?this.calculateCachedLength():this.writePos===Ne?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===ln&&(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]=Uh(this.dataType,e,this.data[i],t);return new Ae({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($.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(),nr(this.cachedMax,this.sampleOffset))}calcRawMin(){if(this.length===0)return 1/0;if(this.dataType.equals($.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(),nr(this.cachedMin,this.sampleOffset))}get bounds(){return V(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($.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 nr(n,this.sampleOffset)}atUUID(e,t){e<0&&(e=this.length+e);const n=Qi(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 o=0;o<this.data.length;o++)if(this.data[o]===ln){if(e===0){i=o;break}n=o+1,e--}if(i===0&&(i=this.data.length),n>=i||e>0){if(t)throw new Error(`[series] - no value at index ${e}`);return}}const a=this.data.slice(n,i);return this.dataType.equals($.STRING)?new TextDecoder().decode(a):Sn(JSON.parse(new TextDecoder().decode(a)))}binarySearch(e){let t=0,n=this.length-1;const i=pr(e);for(;t<=n;){const a=Math.floor((t+n)/2),o=i(this.at(a,!0),e);if(o===0)return a;o<0?t=a+1:n=a-1}return t}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals($.FLOAT32)&&!this.dataType.equals($.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!==Ne){i===0&&e.bufferData(e.ARRAY_BUFFER,this.byteCapacity.valueOf(),e.STATIC_DRAW);const a=this.dataType.density.size(i).valueOf(),o=this.underlyingData.slice(this.gl.prevBuffer,this.writePos);e.bufferSubData(e.ARRAY_BUFFER,a,o.buffer),this.gl.prevBuffer=this.writePos}else e.bufferData(e.ARRAY_BUFFER,this.buffer,n==="static"?e.STATIC_DRAW:e.DYNAMIC_DRAW),this.gl.prevBuffer=Ne}as(e){return ea(e,this.dataType),this}get digest(){return{key:this.key,dataType:this.dataType.toString(),sampleOffset:this.sampleOffset,alignment:{lower:bs(this.alignmentBounds.lower),upper:bs(this.alignmentBounds.upper),multiple:this.alignmentMultiple},timeRange:this.timeRange.toString(),length:this.length,capacity:this.capacity}}get alignmentBounds(){return V(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 Yh(this);return this.dataType.equals($.JSON)?new Vh(e):e}return this.dataType.equals($.UUID)?new Hh(this):new _h(this)}slice(e,t){return this.sliceSub(!1,e,t)}sub(e,t){return this.sliceSub(!0,e,t)}subIterator(e,t){return new ws(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 ws(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 Ae({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 Ae({data:i,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(t)})}reAlign(e){return new Ae({data:this.buffer,dataType:this.dataType,timeRange:M.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 Fh=r=>r==null?!1:Array.isArray(r)||r instanceof ArrayBuffer||ArrayBuffer.isView(r)&&!(r instanceof DataView)||r instanceof ge?!0:Xi(r),ra=Rh(ta,ge);let ws=class{series;end;index;constructor(e,t,n){this.series=e;const i=V(0,e.length+1);this.end=ps(i,n),this.index=ps(i,t)}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}},Yh=class{series;index;decoder;constructor(e){if(!e.dataType.isVariable)throw new Error("cannot create a variable series iterator for a non-variable series");this.series=e,this.index=0,this.decoder=new TextDecoder}next(){const e=this.index,t=this.series.data;for(;this.index<t.length&&t[this.index]!==ln;)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))})}},Vh=class na{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:Tt.decodeString(e.value,na.schema)}}},Hh=class{series;index;data;density;constructor(e){if(!e.dataType.equals($.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=$.UUID.density.valueOf()}next(){if(this.index>=this.series.length)return{done:!0,value:void 0};const e=Qi(this.data,this.index*this.density);return this.index++,{done:!1,value:e}}},_h=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)}}};class sa{series;constructor(e=[]){if(e.length!==0){const t=e[0].dataType;for(let n=1;n<e.length;n++)if(!e[n].dataType.equals(t))throw new Error("[multi-series] - series must have the same data type")}this.series=e}as(e){return ea(e,this.dataType),this}get dataType(){return this.series.length===0?$.UNKNOWN:this.series[0].dataType}get timeRange(){return this.series.length===0?M.ZERO:new M(this.series[0].timeRange.start,this.series[this.series.length-1].timeRange.end)}get alignment(){return this.series.length===0?0n:this.series[0].alignment}get alignmentBounds(){return this.series.length===0?V(0n,0n):V(this.series[0].alignmentBounds.lower,this.series[this.series.length-1].alignmentBounds.upper)}push(e){const t=()=>new Error(`cannot push a ${e.dataType.toString()} series to a ${this.dataType.toString()} multi-series`),n=e.dataType.equals(this.dataType);if(ra(e)){if(this.series.length!==0&&!n)throw t();this.series.push(e)}else{if(this.series.length!==0&&e.series.length!==0&&!n)throw t();this.series.push(...e.series)}}get length(){return this.series.reduce((e,t)=>e+t.length,0)}atAlignment(e,t){for(const n of this.series)if(Gt(n.alignmentBounds,e))return n.atAlignment(e,t);if(t)throw new Error(`[series] - no value at alignment ${e}`)}at(e,t=!1){e<0&&(e=this.length+e);for(const n of this.series){if(e<n.length)return n.at(e,t);e-=n.length}if(t)throw new Error(`[series] - no value at index ${e}`)}subIterator(e,t){return new Lr(this,e,t??this.length)}subAlignmentIterator(e,t){if(e>=this.alignmentBounds.upper||t<=this.alignmentBounds.lower)return cn;let n=0;for(let a=0;a<this.series.length;a++){const o=this.series[a];if(e<o.alignment)break;if(e>=o.alignmentBounds.upper)n+=o.length;else if(Gt(o.alignmentBounds,e)){n+=Math.ceil(Number(e-o.alignment)/Number(o.alignmentMultiple));break}}let i=0;for(let a=0;a<this.series.length;a++){const o=this.series[a];if(t<o.alignment)break;if(t>=o.alignmentBounds.upper)i+=o.length;else if(Gt(o.alignmentBounds,t)){i+=Math.ceil(Number(t-o.alignment)/Number(o.alignmentMultiple));break}}return new Lr(this,n,i)}subAlignmentSpanIterator(e,t){if(e>=this.alignmentBounds.upper)return cn;t=Math.min(t,Number(this.distance(e,this.alignmentBounds.upper)));let n=0;for(let i=0;i<this.series.length;i++){const a=this.series[i];if(e<a.alignment)break;if(e>=a.alignmentBounds.upper)n+=a.length;else if(Gt(a.alignmentBounds,e)){n+=Number(e-a.alignment);break}}return new Lr(this,n,n+t)}updateGLBuffer(e){this.series.forEach(t=>t.updateGLBuffer(e))}get bounds(){return Lu(this.series.map(e=>e.bounds))}get byteLength(){return new et(this.series.reduce((e,t)=>e+t.byteLength.valueOf(),0))}get data(){const e=new this.dataType.Array(this.length);let t=0;for(const n of this.series)e.set(n.data,t),t+=n.length;return new this.dataType.Array(e.buffer)}traverseAlignment(e,t){const n=this.series.map(i=>i.alignmentBounds);return Bu(n,e,t)}acquire(e){this.series.forEach(t=>t.acquire(e))}release(){this.series.forEach(e=>e.release())}distance(e,t){const n=this.series.map(i=>i.alignmentBounds);return qu(n,e,t)}parseJSON(e){if(!this.dataType.equals($.JSON))throw new Error("cannot parse non-JSON series as JSON");return this.series.flatMap(t=>t.parseJSON(e))}[Symbol.iterator](){return this.series.length===0?{next(){return{done:!0,value:void 0}}}:new Wh(this.series)}toStrings(){return this.series.flatMap(e=>e.toStrings())}}let Wh=class{series;seriesIndex;internal;constructor(e){this.series=e,this.seriesIndex=0,this.internal=e[0][Symbol.iterator]()}next(){const e=this.internal.next();return e.done===!1?e:this.seriesIndex===this.series.length-1?{done:!0,value:void 0}:(this.internal=this.series[++this.seriesIndex][Symbol.iterator](),this.next())}[Symbol.iterator](){return this}},Lr=class{series;index;end;constructor(e,t,n){this.series=e,this.end=n,this.index=t}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}[Symbol.iterator](){return this}};const bs=r=>{const e=r>>32n,t=r&0xffffffffn;return{domain:e,sample:t}},Gh=(r,e)=>{let t=null;return e===0?r:(...n)=>{t!==null&&(clearTimeout(t),t=null),t=setTimeout(()=>r(...n),e)}},Kh=(r,e,t=".")=>{const n=r.split(t);return n.map((i,a)=>{const o=e(i,a,n);return o==null?null:typeof o=="string"?o:o.join(t)}).filter(i=>i!=null).join(t)},Jh=(r,e)=>{if(!Array.isArray(r))return r[e];const t=r[e];if(t!=null||r.length==0)return t;const n=r[0];if(typeof n=="object"&&"key"in n)return r.find(i=>i.key===e)},Xh=(r,e,t={optional:!1,separator:"."})=>{t.separator??=".";const{optional:n,getter:i=Jh}=t,a=e.split(t.separator);if(a.length===1&&a[0]==="")return r;let o=r;for(const c of a){const u=i(o,c);if(u==null){if(n)return null;throw new Error(`Path ${e} does not exist. ${c} is null`)}o=u}return o};s.z.object({key:s.z.string(),value:s.z.string()});let Qh=class{handlers;transform;closer;constructor(e,t){this.transform=e,this.handlers=t??new Map}onChange(e){return this.handlers.set(e,null),()=>this.handlers.delete(e)}notify(e){let t=e;if(this.transform!=null){const[n,i]=this.transform(e);if(!i)return;t=n}this.handlers.forEach((n,i)=>i(t))}setCloser(e){this.closer=e}async close(){return await this.closer?.()}},ef=class{handlers;constructor(e){this.handlers=e??new Map}onChange(e){return this.handlers.set(e,null),()=>this.handlers.delete(e)}notify(e){this.handlers.forEach((t,n)=>n(e))}};const tf=Object.freeze(Object.defineProperty({__proto__:null,BaseObserver:ef,Observer:Qh},Symbol.toStringTag,{value:"Module"})),rf=s.z.record(s.z.union([s.z.number(),s.z.string(),s.z.symbol()]),s.z.unknown()),Dn=r=>Object.entries(r),nf=(r,e)=>Object.fromEntries(Dn(r).map(([t,n])=>[t,e(n,t)])),sf=r=>Object.fromEntries(Dn(r).filter(([e,t])=>t!==void 0)),af=(r,...e)=>{const t={...r};for(const n of e)delete t[n];return t},we=Object.freeze(Object.defineProperty({__proto__:null,entries:Dn,map:nf,omit:af,purgeUndefined:sf,unknownZ:rf},Symbol.toStringTag,{value:"Module"})),of=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser";of();const cf=["macOS","Windows","Linux"],lf=["macos","windows","linux"],uf={macos:"macOS",windows:"Windows",linux:"Linux"};s.z.enum(cf).or(s.z.enum(lf).transform(r=>uf[r]));const hf=(...r)=>r.map(ia).join(""),ia=r=>(r.endsWith("/")||(r+="/"),r.startsWith("/")&&(r=r.slice(1)),r),ff=r=>r.endsWith("/")?r.slice(0,-1):r;class wt{protocol;host;port;path;constructor({host:e,port:t,protocol:n="",pathPrefix:i=""}){this.protocol=n,this.host=e,this.port=t,this.path=ia(i)}replace(e){return new wt({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new wt({...this,pathPrefix:hf(this.path,e)})}toString(){return ff(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}static UNKNOWN=new wt({host:"unknown",port:0})}const df=r=>r.nullable().transform(e=>e===null?void 0:e).optional(),yf=r=>s.array(r).or(r.transform(e=>[e])),aa=r=>Kh(r,(e,t,n)=>{const i=t===n.length-1,a=!isNaN(parseInt(e)),o=!isNaN(parseInt(n[t+1]));return a&&(e="element"),i||o?e:[e,"shape"]}),Ts=(r,e)=>{if(r==null)return null;const t=r[e];return t==null&&typeof r=="object"&&"sourceType"in r?r.sourceType()[e]:t},gf=(r,e,t)=>e===""?r:Xh(Ts(r,"shape"),aa(e),{...t,getter:Ts}),bt=Object.freeze(Object.defineProperty({__proto__:null,getFieldSchema:gf,getFieldSchemaPath:aa,nullToUndefined:df,toArray:yf},Symbol.toStringTag,{value:"Module"})),pf=async r=>await new Promise(e=>setTimeout(e,E.fromMilliseconds(r).milliseconds));class mf{config;retries;interval;constructor(e){this.config={baseInterval:new E(e?.baseInterval??E.seconds(1)),maxRetries:e?.maxRetries??5,scale:e?.scale??1,sleepFn:e?.sleepFn??pf},this.retries=0,this.interval=new E(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 wf=s.z.object({baseInterval:E.z.optional(),maxRetries:s.z.number().optional(),scale:s.z.number().optional()}),oa=Object.freeze(Object.defineProperty({__proto__:null,Breaker:mf,breakerConfigZ:wf},Symbol.toStringTag,{value:"Module"})),bf=/^#?([0-9a-f]{6}|[0-9a-f]{8})$/i,ca=s.z.string().regex(bf),Je=s.z.number().min(0).max(255),la=s.z.number().min(0).max(1),ua=s.z.tuple([Je,Je,Je,la]),Tf=s.z.tuple([Je,Je,Je]),vf=s.z.object({rgba255:ua}),Ef=s.z.number().min(0).max(360),Nf=s.z.number().min(0).max(100),Of=s.z.number().min(0).max(100),zf=s.z.tuple([Ef,Nf,Of,la]),Zn=s.z.union([ca,Tf,ua,zf,vf]),Sf=Zn.transform(r=>Pn(r)),Pn=(r,e=1)=>{if(r=Zn.parse(r),typeof r=="string")return Af(r,e);if(Array.isArray(r)){if(r.length<3||r.length>4)throw new Error(`Invalid color: [${r.join(", ")}]`);return r.length===3?[...r,e]:r}return r.rgba255},Af=(r,e=1)=>(r=ca.parse(r),r=$f(r),[Jt(r,0),Jt(r,2),Jt(r,4),r.length===8?Jt(r,6)/255:e]),Jt=(r,e)=>parseInt(r.slice(e,e+2),16),$f=r=>r.startsWith("#")?r.slice(1):r;Pn("#000000");Pn("#ffffff");const If=s.z.object({key:s.z.string(),color:Zn,position:s.z.number(),switched:s.z.boolean().optional()});s.z.array(If);const kf=s.z.object({key:s.z.string(),name:s.z.string(),color:Sf});s.z.object({key:s.z.string(),name:s.z.string(),swatches:s.z.array(kf)});const ha=s.z.int().min(0).max(255),fa=255,da=0,xf={lower:da,upper:fa+1},ya=s.z.object({name:s.z.string(),key:s.z.string()}),Nt=r=>s.z.object({subject:ya,resource:r,authority:ha}),Cf=(...r)=>e=>e.filter(t=>{let n=!1;return t.to!=null&&(n=r.includes(t.to.resource)),t.from!=null&&!n&&(n=r.includes(t.from.resource)),n}),ga=r=>s.z.object({from:Nt(r),to:s.z.null()}),pa=r=>s.z.object({from:s.z.null(),to:Nt(r)}),Rf=r=>s.z.union([ga(r),pa(r),s.z.object({from:Nt(r),to:Nt(r)})]),te=Object.freeze(Object.defineProperty({__proto__:null,ABSOLUTE_AUTHORITY:fa,AUTHORITY_BOUNDS:xf,ZERO_AUTHORITY:da,acquireZ:pa,authorityZ:ha,filterTransfersByChannelKey:Cf,releaseZ:ga,stateZ:Nt,subjectZ:ya,transferZ:Rf},Symbol.toStringTag,{value:"Module"})),jf=r=>Object.getOwnPropertySymbols(globalThis).includes(r),Mf=(r,e)=>{const t=Symbol.for(r);if(!jf(t)){const n=e();Object.defineProperty(globalThis,t,{value:n})}return()=>globalThis[t]},ma="sy_x_error",Uf=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),Dt=r=>class mt extends Error{static discriminator=ma;discriminator=mt.discriminator;static TYPE=r;type=mt.TYPE;static matches=Uf(r);matches=mt.matches;constructor(t,n){super(t,n),this.name=mt.TYPE}static sub(t){return Dt(`${r}.${t}`)}},wa=r=>{if(r==null||typeof r!="object")return!1;const e=r;if(e.discriminator!==ma)return!1;if(!("type"in e))throw new Error(`X Error is missing its type property: ${JSON.stringify(e)}`);return!0},We="unknown",un="nil";class Df{providers=[];register(e){this.providers.push(e)}encode(e){if(e==null)return{type:un,data:""};if(wa(e))for(const t of this.providers){const n=t.encode(e);if(n!=null)return n}if(e instanceof Error)return{type:We,data:e.message};if(typeof e=="string")return{type:We,data:e};try{return{type:We,data:JSON.stringify(e)}}catch{return{type:We,data:"unable to encode error information"}}}decode(e){if(e==null||e.type===un)return null;if(e.type===We)return new hn(e.data);for(const t of this.providers){const n=t.decode(e);if(n!=null)return n}return new hn(e.data)}}const Ln=Mf("synnax-error-registry",()=>new Df),Zf=({encode:r,decode:e})=>Ln().register({encode:r,decode:e}),Pf=r=>Ln().encode(r),Lf=r=>r==null?null:Ln().decode(r);class hn extends Dt("unknown"){}const Bf=s.z.object({type:s.z.string(),data:s.z.string()});class qf extends Dt("canceled"){}class Ff extends Dt("not_implemented"){}const me=Object.freeze(Object.defineProperty({__proto__:null,Canceled:qf,NONE:un,NotImplemented:Ff,UNKNOWN:We,Unknown:hn,createTyped:Dt,decode:Lf,encode:Pf,isTyped:wa,payloadZ:Bf,register:Zf},Symbol.toStringTag,{value:"Module"})),Yf=s.object({jsonrpc:s.literal("2.0"),method:s.string(),params:s.any().optional(),id:s.union([s.string(),s.number(),s.null()]).optional()}),ba=s.object({jsonrpc:s.literal("2.0"),id:s.union([s.string(),s.number(),s.null()])}),Vf=ba.extend({result:s.json()}),Hf=ba.extend({error:s.object({code:s.number().int(),message:s.string().optional(),data:s.json().optional()})}),_f=s.union([Vf,Hf]);s.union([Yf,_f]);const fn=s.z.string().regex(/^\d+\.\d+\.\d+$/),Zt=(r,e,t={})=>{t.checkMajor??=!0,t.checkMinor??=!0,t.checkPatch??=!0;const n=fn.parse(r),i=fn.parse(e),[a,o,c]=n.split(".").map(Number),[u,l,h]=i.split(".").map(Number);if(t.checkMajor){if(a<u)return er;if(a>u)return tr}if(t.checkMinor){if(o<l)return er;if(o>l)return tr}if(t.checkPatch){if(c<h)return er;if(c>h)return tr}return st},Wf=(r,e,t={})=>zi(Zt(r,e,t)),Ta=(r,e,t={})=>Oi(Zt(r,e,t)),Gf=(r,e,t={})=>Ni(Zt(r,e,t)),Kf=({name:r,migrate:e})=>t=>{try{const n=e(t);return console.log(`${r} migrated: ${t.version} -> ${n.version}`),n}catch(n){throw console.log(`${r} failed to migrate from ${t.version}`),console.error(n),n}},Jf=({name:r,migrations:e,targetSchema:t,defaultVersion:n,def:i})=>{const a=Object.keys(e).sort(Zt).pop();if(a==null)return l=>{if(l.version??=n,l.version!==i.version)return console.log(`${r} version ${l.version} is newer than latest version of ${i.version}.
|
|
13
|
+
`).slice(0,-1):Array.from(this).map(e=>e.toString())}parseJSON(e){if(!this.dataType.equals($.JSON))throw new Error("cannot parse non-JSON series as JSON");return this.toStrings().map(t=>e.parse(Tt.decodeString(t)))}get byteCapacity(){return new et(this.underlyingData.byteLength)}get capacity(){return this.dataType.isVariable?this.byteCapacity.valueOf():this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===Ne?this.byteCapacity:this.dataType.isVariable?new et(this.writePos):this.dataType.density.size(this.writePos)}get length(){return this.cachedLength!=null?this.cachedLength:this.dataType.isVariable?this.calculateCachedLength():this.writePos===Ne?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===ln&&(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]=Dh(this.dataType,e,this.data[i],t);return new Ae({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($.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(),nr(this.cachedMax,this.sampleOffset))}calcRawMin(){if(this.length===0)return 1/0;if(this.dataType.equals($.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(),nr(this.cachedMin,this.sampleOffset))}get bounds(){return V(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($.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 nr(n,this.sampleOffset)}atUUID(e,t){e<0&&(e=this.length+e);const n=ea(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 o=0;o<this.data.length;o++)if(this.data[o]===ln){if(e===0){i=o;break}n=o+1,e--}if(i===0&&(i=this.data.length),n>=i||e>0){if(t)throw new Error(`[series] - no value at index ${e}`);return}}const a=this.data.slice(n,i);return this.dataType.equals($.STRING)?new TextDecoder().decode(a):An(JSON.parse(new TextDecoder().decode(a)))}binarySearch(e){let t=0,n=this.length-1;const i=pr(e);for(;t<=n;){const a=Math.floor((t+n)/2),o=i(this.at(a,!0),e);if(o===0)return a;o<0?t=a+1:n=a-1}return t}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals($.FLOAT32)&&!this.dataType.equals($.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!==Ne){i===0&&e.bufferData(e.ARRAY_BUFFER,this.byteCapacity.valueOf(),e.STATIC_DRAW);const a=this.dataType.density.size(i).valueOf(),o=this.underlyingData.slice(this.gl.prevBuffer,this.writePos);e.bufferSubData(e.ARRAY_BUFFER,a,o.buffer),this.gl.prevBuffer=this.writePos}else e.bufferData(e.ARRAY_BUFFER,this.buffer,n==="static"?e.STATIC_DRAW:e.DYNAMIC_DRAW),this.gl.prevBuffer=Ne}as(e){return ta(e,this.dataType),this}get digest(){return{key:this.key,dataType:this.dataType.toString(),sampleOffset:this.sampleOffset,alignment:{lower:Ts(this.alignmentBounds.lower),upper:Ts(this.alignmentBounds.upper),multiple:this.alignmentMultiple},timeRange:this.timeRange.toString(),length:this.length,capacity:this.capacity}}get alignmentBounds(){return V(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 Vh(this);return this.dataType.equals($.JSON)?new Hh(e):e}return this.dataType.equals($.UUID)?new _h(this):new Wh(this)}slice(e,t){return this.sliceSub(!1,e,t)}sub(e,t){return this.sliceSub(!0,e,t)}subIterator(e,t){return new bs(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 bs(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 Ae({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 Ae({data:i,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(t)})}reAlign(e){return new Ae({data:this.buffer,dataType:this.dataType,timeRange:M.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 Yh=r=>r==null?!1:Array.isArray(r)||r instanceof ArrayBuffer||ArrayBuffer.isView(r)&&!(r instanceof DataView)||r instanceof ge?!0:Qi(r),na=jh(ra,ge);let bs=class{series;end;index;constructor(e,t,n){this.series=e;const i=V(0,e.length+1);this.end=ms(i,n),this.index=ms(i,t)}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}},Vh=class{series;index;decoder;constructor(e){if(!e.dataType.isVariable)throw new Error("cannot create a variable series iterator for a non-variable series");this.series=e,this.index=0,this.decoder=new TextDecoder}next(){const e=this.index,t=this.series.data;for(;this.index<t.length&&t[this.index]!==ln;)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))})}},Hh=class sa{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:Tt.decodeString(e.value,sa.schema)}}},_h=class{series;index;data;density;constructor(e){if(!e.dataType.equals($.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=$.UUID.density.valueOf()}next(){if(this.index>=this.series.length)return{done:!0,value:void 0};const e=ea(this.data,this.index*this.density);return this.index++,{done:!1,value:e}}},Wh=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)}}};class ia{series;constructor(e=[]){if(e.length!==0){const t=e[0].dataType;for(let n=1;n<e.length;n++)if(!e[n].dataType.equals(t))throw new Error("[multi-series] - series must have the same data type")}this.series=e}as(e){return ta(e,this.dataType),this}get dataType(){return this.series.length===0?$.UNKNOWN:this.series[0].dataType}get timeRange(){return this.series.length===0?M.ZERO:new M(this.series[0].timeRange.start,this.series[this.series.length-1].timeRange.end)}get alignment(){return this.series.length===0?0n:this.series[0].alignment}get alignmentBounds(){return this.series.length===0?V(0n,0n):V(this.series[0].alignmentBounds.lower,this.series[this.series.length-1].alignmentBounds.upper)}push(e){const t=()=>new Error(`cannot push a ${e.dataType.toString()} series to a ${this.dataType.toString()} multi-series`),n=e.dataType.equals(this.dataType);if(na(e)){if(this.series.length!==0&&!n)throw t();this.series.push(e)}else{if(this.series.length!==0&&e.series.length!==0&&!n)throw t();this.series.push(...e.series)}}get length(){return this.series.reduce((e,t)=>e+t.length,0)}atAlignment(e,t){for(const n of this.series)if(Gt(n.alignmentBounds,e))return n.atAlignment(e,t);if(t)throw new Error(`[series] - no value at alignment ${e}`)}at(e,t=!1){e<0&&(e=this.length+e);for(const n of this.series){if(e<n.length)return n.at(e,t);e-=n.length}if(t)throw new Error(`[series] - no value at index ${e}`)}subIterator(e,t){return new Lr(this,e,t??this.length)}subAlignmentIterator(e,t){if(e>=this.alignmentBounds.upper||t<=this.alignmentBounds.lower)return cn;let n=0;for(let a=0;a<this.series.length;a++){const o=this.series[a];if(e<o.alignment)break;if(e>=o.alignmentBounds.upper)n+=o.length;else if(Gt(o.alignmentBounds,e)){n+=Math.ceil(Number(e-o.alignment)/Number(o.alignmentMultiple));break}}let i=0;for(let a=0;a<this.series.length;a++){const o=this.series[a];if(t<o.alignment)break;if(t>=o.alignmentBounds.upper)i+=o.length;else if(Gt(o.alignmentBounds,t)){i+=Math.ceil(Number(t-o.alignment)/Number(o.alignmentMultiple));break}}return new Lr(this,n,i)}subAlignmentSpanIterator(e,t){if(e>=this.alignmentBounds.upper)return cn;t=Math.min(t,Number(this.distance(e,this.alignmentBounds.upper)));let n=0;for(let i=0;i<this.series.length;i++){const a=this.series[i];if(e<a.alignment)break;if(e>=a.alignmentBounds.upper)n+=a.length;else if(Gt(a.alignmentBounds,e)){n+=Number(e-a.alignment);break}}return new Lr(this,n,n+t)}updateGLBuffer(e){this.series.forEach(t=>t.updateGLBuffer(e))}get bounds(){return Bu(this.series.map(e=>e.bounds))}get byteLength(){return new et(this.series.reduce((e,t)=>e+t.byteLength.valueOf(),0))}get data(){const e=new this.dataType.Array(this.length);let t=0;for(const n of this.series)e.set(n.data,t),t+=n.length;return new this.dataType.Array(e.buffer)}traverseAlignment(e,t){const n=this.series.map(i=>i.alignmentBounds);return qu(n,e,t)}acquire(e){this.series.forEach(t=>t.acquire(e))}release(){this.series.forEach(e=>e.release())}distance(e,t){const n=this.series.map(i=>i.alignmentBounds);return Fu(n,e,t)}parseJSON(e){if(!this.dataType.equals($.JSON))throw new Error("cannot parse non-JSON series as JSON");return this.series.flatMap(t=>t.parseJSON(e))}[Symbol.iterator](){return this.series.length===0?{next(){return{done:!0,value:void 0}}}:new Gh(this.series)}toStrings(){return this.series.flatMap(e=>e.toStrings())}}let Gh=class{series;seriesIndex;internal;constructor(e){this.series=e,this.seriesIndex=0,this.internal=e[0][Symbol.iterator]()}next(){const e=this.internal.next();return e.done===!1?e:this.seriesIndex===this.series.length-1?{done:!0,value:void 0}:(this.internal=this.series[++this.seriesIndex][Symbol.iterator](),this.next())}[Symbol.iterator](){return this}},Lr=class{series;index;end;constructor(e,t,n){this.series=e,this.end=n,this.index=t}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}[Symbol.iterator](){return this}};const Ts=r=>{const e=r>>32n,t=r&0xffffffffn;return{domain:e,sample:t}},Kh=(r,e)=>{let t=null;return e===0?r:(...n)=>{t!==null&&(clearTimeout(t),t=null),t=setTimeout(()=>r(...n),e)}},un=".",Jh=(r,e,t=un)=>{const n=r.split(t);return n.map((i,a)=>{const o=e(i,a,n);return o==null?null:typeof o=="string"?o:o.join(t)}).filter(i=>i!=null).join(t)},Xh=(r,e)=>{if(!Array.isArray(r))return r[e];const t=r[e];if(t!=null||r.length==0)return t;const n=r[0];if(typeof n=="object"&&"key"in n)return r.find(i=>i.key===e)},Qh=(r,e,t={optional:!1})=>{const{optional:n,getter:i=Xh}=t;if(e==="")return r;const a=e.split(un);if(a.length===1){const c=i(r,a[0]);if(c===void 0){if(n)return null;throw new Error(`Path ${e} does not exist. ${a[0]} is undefined`)}return c}const o=(c,u)=>{if(u>=a.length)return c;for(let l=a.length-u;l>=1;l--){const h=a.slice(u,u+l).join(un),y=i(c,h);if(y!==void 0){if(u+l===a.length)return y;if(y===null){if(n)return null;throw new Error(`Path ${e} does not exist. ${h} is null`)}return o(y,u+l)}}if(n)return null;throw new Error(`Path ${e} does not exist. ${a[u]} is undefined`)};return o(r,0)};s.z.object({key:s.z.string(),value:s.z.string()});let ef=class{handlers;transform;closer;constructor(e,t){this.transform=e,this.handlers=t??new Map}onChange(e){return this.handlers.set(e,null),()=>this.handlers.delete(e)}notify(e){let t=e;if(this.transform!=null){const[n,i]=this.transform(e);if(!i)return;t=n}this.handlers.forEach((n,i)=>i(t))}setCloser(e){this.closer=e}async close(){return await this.closer?.()}},tf=class{handlers;constructor(e){this.handlers=e??new Map}onChange(e){return this.handlers.set(e,null),()=>this.handlers.delete(e)}notify(e){this.handlers.forEach((t,n)=>n(e))}};const rf=Object.freeze(Object.defineProperty({__proto__:null,BaseObserver:tf,Observer:ef},Symbol.toStringTag,{value:"Module"})),nf=s.z.record(s.z.union([s.z.number(),s.z.string(),s.z.symbol()]),s.z.unknown()),Zn=r=>Object.entries(r),sf=(r,e)=>Object.fromEntries(Zn(r).map(([t,n])=>[t,e(n,t)])),af=r=>Object.fromEntries(Zn(r).filter(([e,t])=>t!==void 0)),of=(r,...e)=>{const t={...r};for(const n of e)delete t[n];return t},we=Object.freeze(Object.defineProperty({__proto__:null,entries:Zn,map:sf,omit:of,purgeUndefined:af,unknownZ:nf},Symbol.toStringTag,{value:"Module"})),cf=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser";cf();const lf=["macOS","Windows","Linux"],uf=["macos","windows","linux"],hf={macos:"macOS",windows:"Windows",linux:"Linux"};s.z.enum(lf).or(s.z.enum(uf).transform(r=>hf[r]));const ff=(...r)=>r.map(aa).join(""),aa=r=>(r.endsWith("/")||(r+="/"),r.startsWith("/")&&(r=r.slice(1)),r),df=r=>r.endsWith("/")?r.slice(0,-1):r;class wt{protocol;host;port;path;constructor({host:e,port:t,protocol:n="",pathPrefix:i=""}){this.protocol=n,this.host=e,this.port=t,this.path=aa(i)}replace(e){return new wt({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new wt({...this,pathPrefix:ff(this.path,e)})}toString(){return df(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}static UNKNOWN=new wt({host:"unknown",port:0})}const yf=r=>r.nullable().transform(e=>e===null?void 0:e).optional(),gf=r=>s.array(r).or(r.transform(e=>[e])),oa=r=>Jh(r,(e,t,n)=>{const i=t===n.length-1,a=!isNaN(parseInt(e)),o=!isNaN(parseInt(n[t+1]));return a&&(e="element"),i||o?e:[e,"shape"]}),vs=(r,e)=>{if(r==null)return null;const t=r[e];return t==null&&typeof r=="object"&&"sourceType"in r?r.sourceType()[e]:t},pf=(r,e,t)=>e===""?r:Qh(vs(r,"shape"),oa(e),{...t,getter:vs}),bt=Object.freeze(Object.defineProperty({__proto__:null,getFieldSchema:pf,getFieldSchemaPath:oa,nullToUndefined:yf,toArray:gf},Symbol.toStringTag,{value:"Module"})),mf=async r=>await new Promise(e=>setTimeout(e,E.fromMilliseconds(r).milliseconds));class wf{config;retries;interval;constructor(e){this.config={baseInterval:new E(e?.baseInterval??E.seconds(1)),maxRetries:e?.maxRetries??5,scale:e?.scale??1,sleepFn:e?.sleepFn??mf},this.retries=0,this.interval=new E(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 bf=s.z.object({baseInterval:E.z.optional(),maxRetries:s.z.number().optional(),scale:s.z.number().optional()}),ca=Object.freeze(Object.defineProperty({__proto__:null,Breaker:wf,breakerConfigZ:bf},Symbol.toStringTag,{value:"Module"})),Tf=/^#?([0-9a-f]{6}|[0-9a-f]{8})$/i,la=s.z.string().regex(Tf),Je=s.z.number().min(0).max(255),ua=s.z.number().min(0).max(1),ha=s.z.tuple([Je,Je,Je,ua]),vf=s.z.tuple([Je,Je,Je]),Ef=s.z.object({rgba255:ha}),Nf=s.z.number().min(0).max(360),Of=s.z.number().min(0).max(100),zf=s.z.number().min(0).max(100),Sf=s.z.tuple([Nf,Of,zf,ua]),Pn=s.z.union([la,vf,ha,Sf,Ef]),Af=Pn.transform(r=>Ln(r)),Ln=(r,e=1)=>{if(r=Pn.parse(r),typeof r=="string")return $f(r,e);if(Array.isArray(r)){if(r.length<3||r.length>4)throw new Error(`Invalid color: [${r.join(", ")}]`);return r.length===3?[...r,e]:r}return r.rgba255},$f=(r,e=1)=>(r=la.parse(r),r=If(r),[Jt(r,0),Jt(r,2),Jt(r,4),r.length===8?Jt(r,6)/255:e]),Jt=(r,e)=>parseInt(r.slice(e,e+2),16),If=r=>r.startsWith("#")?r.slice(1):r;Ln("#000000");Ln("#ffffff");const kf=s.z.object({key:s.z.string(),color:Pn,position:s.z.number(),switched:s.z.boolean().optional()});s.z.array(kf);const xf=s.z.object({key:s.z.string(),name:s.z.string(),color:Af});s.z.object({key:s.z.string(),name:s.z.string(),swatches:s.z.array(xf)});const fa=s.z.int().min(0).max(255),da=255,ya=0,Cf={lower:ya,upper:da+1},ga=s.z.object({name:s.z.string(),key:s.z.string()}),Nt=r=>s.z.object({subject:ga,resource:r,authority:fa}),Rf=(...r)=>e=>e.filter(t=>{let n=!1;return t.to!=null&&(n=r.includes(t.to.resource)),t.from!=null&&!n&&(n=r.includes(t.from.resource)),n}),pa=r=>s.z.object({from:Nt(r),to:s.z.null()}),ma=r=>s.z.object({from:s.z.null(),to:Nt(r)}),jf=r=>s.z.union([pa(r),ma(r),s.z.object({from:Nt(r),to:Nt(r)})]),te=Object.freeze(Object.defineProperty({__proto__:null,ABSOLUTE_AUTHORITY:da,AUTHORITY_BOUNDS:Cf,ZERO_AUTHORITY:ya,acquireZ:ma,authorityZ:fa,filterTransfersByChannelKey:Rf,releaseZ:pa,stateZ:Nt,subjectZ:ga,transferZ:jf},Symbol.toStringTag,{value:"Module"})),Mf=r=>Object.getOwnPropertySymbols(globalThis).includes(r),Uf=(r,e)=>{const t=Symbol.for(r);if(!Mf(t)){const n=e();Object.defineProperty(globalThis,t,{value:n})}return()=>globalThis[t]},wa="sy_x_error",Df=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),Dt=r=>class mt extends Error{static discriminator=wa;discriminator=mt.discriminator;static TYPE=r;type=mt.TYPE;static matches=Df(r);matches=mt.matches;constructor(t,n){super(t,n),this.name=mt.TYPE}static sub(t){return Dt(`${r}.${t}`)}},ba=r=>{if(r==null||typeof r!="object")return!1;const e=r;if(e.discriminator!==wa)return!1;if(!("type"in e))throw new Error(`X Error is missing its type property: ${JSON.stringify(e)}`);return!0},We="unknown",hn="nil";class Zf{providers=[];register(e){this.providers.push(e)}encode(e){if(e==null)return{type:hn,data:""};if(ba(e))for(const t of this.providers){const n=t.encode(e);if(n!=null)return n}if(e instanceof Error)return{type:We,data:e.message};if(typeof e=="string")return{type:We,data:e};try{return{type:We,data:JSON.stringify(e)}}catch{return{type:We,data:"unable to encode error information"}}}decode(e){if(e==null||e.type===hn)return null;if(e.type===We)return new fn(e.data);for(const t of this.providers){const n=t.decode(e);if(n!=null)return n}return new fn(e.data)}}const Bn=Uf("synnax-error-registry",()=>new Zf),Pf=({encode:r,decode:e})=>Bn().register({encode:r,decode:e}),Lf=r=>Bn().encode(r),Bf=r=>r==null?null:Bn().decode(r);class fn extends Dt("unknown"){}const qf=s.z.object({type:s.z.string(),data:s.z.string()});class Ff extends Dt("canceled"){}class Yf extends Dt("not_implemented"){}const me=Object.freeze(Object.defineProperty({__proto__:null,Canceled:Ff,NONE:hn,NotImplemented:Yf,UNKNOWN:We,Unknown:fn,createTyped:Dt,decode:Bf,encode:Lf,isTyped:ba,payloadZ:qf,register:Pf},Symbol.toStringTag,{value:"Module"})),Vf=s.object({jsonrpc:s.literal("2.0"),method:s.string(),params:s.any().optional(),id:s.union([s.string(),s.number(),s.null()]).optional()}),Ta=s.object({jsonrpc:s.literal("2.0"),id:s.union([s.string(),s.number(),s.null()])}),Hf=Ta.extend({result:s.json()}),_f=Ta.extend({error:s.object({code:s.number().int(),message:s.string().optional(),data:s.json().optional()})}),Wf=s.union([Hf,_f]);s.union([Vf,Wf]);const dn=s.z.string().regex(/^\d+\.\d+\.\d+$/),Zt=(r,e,t={})=>{t.checkMajor??=!0,t.checkMinor??=!0,t.checkPatch??=!0;const n=dn.parse(r),i=dn.parse(e),[a,o,c]=n.split(".").map(Number),[u,l,h]=i.split(".").map(Number);if(t.checkMajor){if(a<u)return er;if(a>u)return tr}if(t.checkMinor){if(o<l)return er;if(o>l)return tr}if(t.checkPatch){if(c<h)return er;if(c>h)return tr}return st},Gf=(r,e,t={})=>Si(Zt(r,e,t)),va=(r,e,t={})=>zi(Zt(r,e,t)),Kf=(r,e,t={})=>Oi(Zt(r,e,t)),Jf=({name:r,migrate:e})=>t=>{try{const n=e(t);return console.log(`${r} migrated: ${t.version} -> ${n.version}`),n}catch(n){throw console.log(`${r} failed to migrate from ${t.version}`),console.error(n),n}},Xf=({name:r,migrations:e,targetSchema:t,defaultVersion:n,def:i})=>{const a=Object.keys(e).sort(Zt).pop();if(a==null)return l=>{if(l.version??=n,l.version!==i.version)return console.log(`${r} version ${l.version} is newer than latest version of ${i.version}.
|
|
14
14
|
Returning default instead.
|
|
15
|
-
`),i;try{return t!=null?t.parse(l):l}catch(h){return console.log(`${r} failed to parse default. Exiting with default`),console.error(h),i}};const o=Object.keys(e).length;let c=!1;const u=l=>{try{if(o===0||
|
|
15
|
+
`),i;try{return t!=null?t.parse(l):l}catch(h){return console.log(`${r} failed to parse default. Exiting with default`),console.error(h),i}};const o=Object.keys(e).length;let c=!1;const u=l=>{try{if(o===0||va(l.version,a))return console.log(c?`${r} ${l.version} now up to date`:`${r} version ${l.version} is up to date with target version ${i.version}`),l;const h=l.version,y=e[h],d=y(l);return c=!0,u(d)}catch(h){return console.log(`${r} failed to migrate from ${l.version} to ${a}`),console.error(h),i}};return l=>{try{if(l.version==null)if(n!=null)console.log(`${r} version is null. Setting version to default of ${n}`),l.version=n;else return console.log(`${r} version is null and no default version set. Exiting with default`),i;return u(l)}catch(h){return console.log(`${r} failed to parse final result. Exiting with default`),console.error(h),i}}},Es=Object.freeze(Object.defineProperty({__proto__:null,compareSemVer:Zt,createMigration:Jf,migrator:Xf,semVerNewer:va,semVerOlder:Kf,semVerZ:dn,versionsEqual:Gf},Symbol.toStringTag,{value:"Module"})),Qf=["standard","scientific","engineering"];s.z.enum(Qf);const Ea=s.z.enum(["success","info","warning","error","loading","disabled"]),ed=r=>s.z.object({key:s.z.string(),variant:Ea,message:s.z.string(),description:s.z.string().optional(),time:f.z,details:r??s.z.unknown().optional()}),td=(r,e)=>{if(!(r instanceof Error))throw r;return Na({variant:"error",message:e??r.message,description:e!=null?r.message:void 0,details:{stack:r.stack??""}})},Na=r=>({key:Dn(),time:f.now(),...r}),rd=(r,e=[])=>{if(r!=null)return Array.isArray(e)?e.includes(r)?r:void 0:e===r?r:void 0},nd=(r,e=[])=>{if(r!=null)return Array.isArray(e)?e.includes(r)?void 0:r:e===r?void 0:r},Pt=Object.freeze(Object.defineProperty({__proto__:null,create:Na,fromException:td,keepVariants:rd,removeVariants:nd,statusZ:ed,variantZ:Ea},Symbol.toStringTag,{value:"Module"})),sd=(r,e="")=>{if(typeof r=="string")return r;const t=r.length;return t===0?e:t===1?r[0]:t===2?`${r[0]} and ${r[1]}`:`${r.slice(0,-1).join(", ")}, and ${r[t-1]}`},id=r=>{const e=r.split(" "),t=new Set,n=e.map(o=>o.charAt(0).toLowerCase()).join("");t.add(n.replace(/-/g,"_")),t.add(n.replace(/(.)(.)/g,"$1_$2").replace(/-/g,"_"));const i=/\d+/g;r.match(i)&&e.forEach((o,c)=>{if(i.test(o)){const u=e.map((l,h)=>h!==c?l.charAt(0).toLowerCase():l).join("");t.add(u.replace(/-/g,"_")),t.add(u.replace(/(.)(.)/g,"$1_$2").replace(/-/g,"_"))}});const a=e.map(o=>(o.length>3?o.substring(0,3):o).toLowerCase());return t.add(a.join("").replace(/-/g,"_")),t.add(a.join("_").replace(/-/g,"_")),Array.from(t).filter(o=>o.length>=2&&o.length<=12&&!/^\d/.test(o))},ad=(r,e)=>r.startsWith(e)?r.slice(e.length):r,yn=Object.freeze(Object.defineProperty({__proto__:null,createShortIdentifiers:id,naturalLanguageJoin:sd,trimPrefix:ad},Symbol.toStringTag,{value:"Module"})),Oa="all",za="create",Sa="delete",Aa="retrieve",$a="update",or=s.z.enum([Oa,za,Sa,Aa,$a]);class he extends me.createTyped("sy"){}class Z extends he.sub("validation"){}class Ot extends Z.sub("path"){path;error;static encodedSchema=s.z.object({path:s.z.string().array(),error:me.payloadZ});constructor(e,t){const n=v.toArray(e);super(`${n.join(".")}: ${t.message}`),this.path=n.flatMap(i=>i.split(".")),this.error=t}static decode(e){const t=Ot.encodedSchema.parse(JSON.parse(e.data));return new Ot(t.path,me.decode(t.error))}}class zt extends he.sub("auth"){}class gn extends zt.sub("invalid_token"){}class pn extends zt.sub("expired_token"){}class Xe extends he.sub("unexpected"){constructor(e){super(`
|
|
16
16
|
Unexpected error encountered:
|
|
17
17
|
|
|
18
18
|
${e}
|
|
19
19
|
|
|
20
20
|
Please report this to the Synnax team.
|
|
21
|
-
`)}}class xe extends he.sub("query"){}class St extends xe.sub("not_found"){}class At extends xe.sub("multiple_results"){}class pn extends he.sub("route"){path;constructor(e,t){super(e),this.path=t}}class mn extends he.sub("control"){}class Es extends mn.sub("unauthorized"){}class ad extends he.sub("disconnected"){constructor(e="Operation failed because no cluster is connected."){super(e)}}class od extends he.sub("contiguity"){}const cd=r=>r.type.startsWith(he.TYPE)?r.type.startsWith(Z.TYPE)?r.type===Ot.TYPE?Ot.decode(r):new Z(r.data):r.type.startsWith(zt.TYPE)?r.type.startsWith(yn.TYPE)?new yn(r.data):r.type.startsWith(gn.TYPE)?new gn(r.data):new zt(r.data):r.type.startsWith(Xe.TYPE)?new Xe(r.data):r.type.startsWith(xe.TYPE)?r.type.startsWith(St.TYPE)?new St(r.data):r.type.startsWith(At.TYPE)?new At(r.data):new xe(r.data):r.type.startsWith(mn.TYPE)?r.type.startsWith(Es.TYPE)?new Es(r.data):new mn(r.data):r.type.startsWith(pn.TYPE)?new pn(r.data,r.data):new Xe(r.data):null,ld=()=>{throw new me.NotImplemented};me.register({encode:ld,decode:cd});const ud=async(r,e)=>{const[t,n]=await e(r);return n==null?[t,n]:n instanceof Ie?[t,new Ie({message:`Cannot reach cluster at ${n.url.host}:${n.url.port}`,url:n.url})]:[t,n]};class Bn{key;name;constructor(e,t){this.key=t,this.name=e}get ontologyID(){return $a(this.key)}}const $a=r=>({type:"group",key:r}),Lt=s.z.uuid(),br=s.z.string(),Tr=s.z.object({key:Lt,name:br}),Ia="builtin",hd="cluster",fd="node",vr=s.z.enum(["label","log","allow_all","builtin","cluster","channel","node","group","range","framer","range-alias","user","workspace","schematic","lineplot","rack","device","task","policy","table","schematic_symbol"]),dd=s.z.string().transform(r=>{const[e,t]=r.split(":");return{type:vr.parse(e),key:t??""}}),C=s.z.object({type:vr,key:s.z.string()}).or(dd),yd={type:Ia,key:"root"},$t=r=>`${r.type}:${r.key}`,gd=(r,e)=>r.type===e.type&&r.key===e.key,ka=r=>{const e=v.toArray(r);return e.length===0?[]:typeof e[0]=="object"&&"id"in e[0]?e.map(({id:t})=>t):e.map(t=>C.parse(t))},xa=s.z.object({id:C,name:s.z.string(),data:we.unknownZ.optional().nullable()}).transform(r=>({key:$t(r.id),...r})),pd=r=>r==="to"?"from":"to",md=s.z.object({from:C,type:s.z.string(),to:C}).or(s.z.string().transform(r=>{const[e,t,n]=r.split("->");return{from:C.parse(e),type:t,to:C.parse(n)}})),wd=r=>`${$t(r.from)}->${r.type}->${$t(r.to)}`,bd="parent",Td=(r,e)=>!(e.type!=null&&e.type!==r.type||e.from?.type!=null&&e.from.type!==r.from.type||e.to?.type!=null&&e.to.type!==r.to.type||e.from?.key!=null&&e.from.key!==r.from.key||e.to?.key!=null&&e.to.key!==r.to.key),vd=s.z.object({group:Tr}),Ed=s.z.object({parent:C,key:Lt.optional(),name:br}),Nd=s.z.object({key:Lt,name:br}),Od=s.z.object({keys:s.z.array(Lt)});let zd=class sr{static CREATE_ENDPOINT="/ontology/create-group";static RENAME_ENDPOINT="/ontology/rename-group";static DELETE_ENDPOINT="/ontology/delete-group";client;constructor(e){this.client=e}async create(e,t,n){return(await m(this.client,sr.CREATE_ENDPOINT,{parent:e,name:t,key:n},Ed,vd)).group}async rename(e,t){await m(this.client,sr.RENAME_ENDPOINT,{key:e,name:t},Nd,s.z.object({}))}async delete(e){await m(this.client,sr.DELETE_ENDPOINT,{keys:e},Od,s.z.object({}))}};const Sd="sy_group_set",Ad="sy_group_delete";let Ca=class{creator;constructor(e){this.creator=new zd(e)}async create(e,t,n){return this.sugar(await this.creator.create(e,t,n))}async rename(e,t){return await this.creator.rename(e,t)}async delete(...e){return await this.creator.delete(e)}sugar(e){return new Bn(e.name,e.key)}};const $d=Object.freeze(Object.defineProperty({__proto__:null,Client:Ca,DELETE_CHANNEL_NAME:Ad,Group:Bn,SET_CHANNEL_NAME:Sd,groupZ:Tr,keyZ:Lt,nameZ:br,ontologyID:$a},Symbol.toStringTag,{value:"Module"})),Id="/ontology/add-children",kd="/ontology/remove-children",xd="/ontology/move-children",Ns=s.z.object({id:C,children:C.array()}),Cd=s.z.object({from:C,to:C,children:C.array()}),Br=s.z.object({});let Rd=class{client;constructor(e){this.client=e}async addChildren(e,...t){await m(this.client,Id,{id:e,children:t},Ns,Br)}async removeChildren(e,...t){await m(this.client,kd,{id:e,children:t},Ns,Br)}async moveChildren(e,t,...n){await m(this.client,xd,{from:e,to:t,children:n},Cd,Br)}};const jd="/ontology/retrieve",Md=s.z.object({ids:C.array().optional(),children:s.z.boolean().optional(),parents:s.z.boolean().optional(),excludeFieldData:s.z.boolean().optional(),searchTerm:s.z.string().optional(),limit:s.z.number().optional(),offset:s.z.number().optional(),types:vr.array().optional()}),Ud=s.z.object({resources:xa.array()});let Ra=class{type="ontology";groups;client;writer;framer;constructor(e,t){this.client=e,this.writer=new Rd(e),this.groups=new Ca(e),this.framer=t}async retrieve(e,t){if(!Array.isArray(e)&&typeof e=="object"&&!("key"in e))return this.execRetrieve(e);const n=ka(e),i=await this.execRetrieve({ids:n,...t});if(Array.isArray(e))return i;if(i.length===0)throw new xe(`No resource found with ID ${dn.naturalLanguageJoin(n.map(a=>$t(a)))}`);return i[0]}async retrieveChildren(e,t){return await this.execRetrieve({ids:v.toArray(e),children:!0,...t})}async retrieveParents(e,t){return await this.execRetrieve({ids:v.toArray(e),parents:!0,...t})}async addChildren(e,...t){return await this.writer.addChildren(e,...t)}async removeChildren(e,...t){return await this.writer.removeChildren(e,...t)}async moveChildren(e,t,...n){return await this.writer.moveChildren(e,t,...n)}async execRetrieve(e){const{resources:t}=await m(this.client,jd,e,Md,Ud);return t}};const Dd="sy_ontology_resource_set",Zd="sy_ontology_resource_delete",Pd="sy_ontology_relationship_set",Ld="sy_ontology_relationship_delete",Bd=Object.freeze(Object.defineProperty({__proto__:null,BUILTIN_TYPE:Ia,CLUSTER_TYPE:hd,Client:Ra,NODE_TYPE:fd,PARENT_OF_RELATIONSHIP_TYPE:bd,RELATIONSHIP_DELETE_CHANNEL_NAME:Ld,RELATIONSHIP_SET_CHANNEL_NAME:Pd,RESOURCE_DELETE_CHANNEL_NAME:Zd,RESOURCE_SET_CHANNEL_NAME:Dd,ROOT_ID:yd,idToString:$t,idZ:C,idsEqual:gd,matchRelationship:Td,oppositeRelationshipDirection:pd,parseIDs:ka,relationshipToString:wd,relationshipZ:md,resourceTypeZ:vr,resourceZ:xa},Symbol.toStringTag,{value:"Module"})),L=r=>s.z.union([s.z.union([s.z.null(),s.z.undefined()]).transform(()=>[]),r.array()]),it=s.z.uuid(),Er=s.z.object({key:it,subjects:L(C),objects:L(C),actions:L(or)}),ja=s.z.object({key:it.optional(),subjects:C.array().or(C),objects:C.array().or(C),actions:or.array().or(or)}),qd=s.z.object({keys:it.array().optional(),subjects:C.array().optional()}),Fd=s.z.object({key:it}).transform(({key:r})=>({keys:[r]})),Yd=s.z.union([s.z.object({for:C}).transform(({for:r})=>({subjects:[r]})),s.z.object({for:C.array()}).transform(({for:r})=>({subjects:r})),qd]),Vd=s.z.union([Fd,Yd]),Hd=s.z.object({policies:L(Er)}),_d=s.z.object({policies:Er.partial({key:!0}).array()}),Wd=s.z.object({policies:Er.array()}),Gd=s.z.object({keys:it.array()}),Kd=s.z.object({}),Jd="/access/policy/retrieve",Xd="/access/policy/create",Qd="/access/policy/delete";let Ma=class{client;constructor(e){this.client=e}async create(e){const t=Array.isArray(e),i=ja.array().parse(v.toArray(e)).map(o=>({objects:v.toArray(o.objects),actions:v.toArray(o.actions),subjects:v.toArray(o.subjects)})),a=await m(this.client,Xd,{policies:i},_d,Wd);return t?a.policies:a.policies[0]}async retrieve(e){const t="key"in e,n=await m(this.client,Jd,e,Vd,Hd);return t?n.policies[0]:n.policies}async delete(e){await m(this.client,Qd,{keys:v.toArray(e)},Gd,Kd)}};const ey=r=>({type:"policy",key:r}),ty={type:"allow_all",key:""},ry=Object.freeze(Object.defineProperty({__proto__:null,ALLOW_ALL_ONTOLOGY_ID:ty,Client:Ma,keyZ:it,newZ:ja,ontologyID:ey,policyZ:Er},Symbol.toStringTag,{value:"Module"}));let Ua=class{policy;constructor(e){this.policy=new Ma(e)}};const ny=Object.freeze(Object.defineProperty({__proto__:null,ALL_ACTION:Na,CREATE_ACTION:Oa,Client:Ua,DELETE_ACTION:za,RETRIEVE_ACTION:Sa,UPDATE_ACTION:Aa,actionZ:or},Symbol.toStringTag,{value:"Module"})),Os="Channel key must be a valid uint32.",j=s.z.uint32().or(s.z.string().refine(r=>!isNaN(Number(r)),{message:Os}).transform(Number).refine(r=>r<2**32-1,{message:Os})),pe=s.z.string(),Da=Pt.statusZ(),at=s.z.object({name:pe,key:j,dataType:$.z,leaseholder:s.z.number(),index:j,isIndex:s.z.boolean(),internal:s.z.boolean(),virtual:s.z.boolean(),alias:s.z.string().optional(),expression:s.z.string().default(""),requires:L(j),status:Da.optional()}),Za=at.extend({key:j.optional(),leaseholder:s.z.number().optional(),index:j.optional(),isIndex:s.z.boolean().optional(),internal:s.z.boolean().optional().default(!1),virtual:s.z.boolean().optional().default(!1),expression:s.z.string().optional().default(""),requires:L(j).optional().default([])}),qe=s.z.union([bt.toArray(j),bt.toArray(pe),bt.toArray(at).transform(r=>r.map(e=>e.key))]),sy=new Error("request for lock canceled");var iy=function(r,e,t,n){function i(a){return a instanceof t?a:new t(function(o){o(a)})}return new(t||(t=Promise))(function(a,o){function c(h){try{l(n.next(h))}catch(y){o(y)}}function u(h){try{l(n.throw(h))}catch(y){o(y)}}function l(h){h.done?a(h.value):i(h.value).then(c,u)}l((n=n.apply(r,e||[])).next())})};class ay{constructor(e,t=sy){this._value=e,this._cancelError=t,this._queue=[],this._weightedWaiters=[]}acquire(e=1,t=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return new Promise((n,i)=>{const a={resolve:n,reject:i,weight:e,priority:t},o=Pa(this._queue,c=>t<=c.priority);o===-1&&e<=this._value?this._dispatchItem(a):this._queue.splice(o+1,0,a)})}runExclusive(e){return iy(this,arguments,void 0,function*(t,n=1,i=0){const[a,o]=yield this.acquire(n,i);try{return yield t(a)}finally{o()}})}waitForUnlock(e=1,t=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return this._couldLockImmediately(e,t)?Promise.resolve():new Promise(n=>{this._weightedWaiters[e-1]||(this._weightedWaiters[e-1]=[]),oy(this._weightedWaiters[e-1],{resolve:n,priority:t})})}isLocked(){return this._value<=0}getValue(){return this._value}setValue(e){this._value=e,this._dispatchQueue()}release(e=1){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);this._value+=e,this._dispatchQueue()}cancel(){this._queue.forEach(e=>e.reject(this._cancelError)),this._queue=[]}_dispatchQueue(){for(this._drainUnlockWaiters();this._queue.length>0&&this._queue[0].weight<=this._value;)this._dispatchItem(this._queue.shift()),this._drainUnlockWaiters()}_dispatchItem(e){const t=this._value;this._value-=e.weight,e.resolve([t,this._newReleaser(e.weight)])}_newReleaser(e){let t=!1;return()=>{t||(t=!0,this.release(e))}}_drainUnlockWaiters(){if(this._queue.length===0)for(let e=this._value;e>0;e--){const t=this._weightedWaiters[e-1];t&&(t.forEach(n=>n.resolve()),this._weightedWaiters[e-1]=[])}else{const e=this._queue[0].priority;for(let t=this._value;t>0;t--){const n=this._weightedWaiters[t-1];if(!n)continue;const i=n.findIndex(a=>a.priority<=e);(i===-1?n:n.splice(0,i)).forEach(a=>a.resolve())}}}_couldLockImmediately(e,t){return(this._queue.length===0||this._queue[0].priority<t)&&e<=this._value}}function oy(r,e){const t=Pa(r,n=>e.priority<=n.priority);r.splice(t+1,0,e)}function Pa(r,e){for(let t=r.length-1;t>=0;t--)if(e(r[t]))return t;return-1}var cy=function(r,e,t,n){function i(a){return a instanceof t?a:new t(function(o){o(a)})}return new(t||(t=Promise))(function(a,o){function c(h){try{l(n.next(h))}catch(y){o(y)}}function u(h){try{l(n.throw(h))}catch(y){o(y)}}function l(h){h.done?a(h.value):i(h.value).then(c,u)}l((n=n.apply(r,e||[])).next())})};class ly{constructor(e){this._semaphore=new ay(1,e)}acquire(){return cy(this,arguments,void 0,function*(e=0){const[,t]=yield this._semaphore.acquire(1,e);return t})}runExclusive(e,t=0){return this._semaphore.runExclusive(()=>e(),1,t)}isLocked(){return this._semaphore.isLocked()}waitForUnlock(e=0){return this._semaphore.waitForUnlock(1,e)}release(){this._semaphore.isLocked()&&this._semaphore.release()}cancel(){return this._semaphore.cancel()}}const uy=(r,e,{convertNumericStrings:t=!0}={})=>{const n=!Array.isArray(r);let i=v.toArray(r);const a=i[0],o=typeof a;let c;return o==="string"&&t&&!isNaN(parseInt(a))&&"number"in e?(c=e.number,i=i.map(u=>parseInt(u))):c=e[o],{single:n,variant:c,normalized:i,actual:r}},Fe=(r,e,t,n)=>{if(n){if(t.length===0)throw new St(`${r} not found matching ${JSON.stringify(e)}`);if(t.length>1)throw new At(`Expected one ${r} matching ${JSON.stringify(e)}, but found ${t.length}`)}},hy=s.z.object({leaseholder:s.z.number().optional(),keys:j.array().optional(),names:s.z.string().array().optional(),searchTerm:s.z.string().optional(),rangeKey:s.z.string().optional(),limit:s.z.number().optional(),offset:s.z.number().optional(),dataTypes:$.z.array().optional(),notDataTypes:$.z.array().optional(),virtual:s.z.boolean().optional(),isIndex:s.z.boolean().optional(),internal:s.z.boolean().optional(),calculated:s.z.boolean().optional()}),fy=s.z.object({channels:L(at)}),se=r=>(Array.isArray(r)&&r.length>0&&typeof r[0]=="object"?r=r.map(e=>e.key):typeof r=="object"&&"key"in r&&(r=[r.key]),uy(r,{number:"keys",string:"names"}));class Bt{static ENDPOINT="/channel/retrieve";client;constructor(e){this.client=e}async retrieve(e,t){if(!Array.isArray(e)&&typeof e=="object")return await this.execute(e);const n=se(e),{variant:i}=n;let{normalized:a}=n;return i==="keys"&&a.indexOf(0)!==-1&&(a=a.filter(o=>o!==0)),a.length===0?[]:await this.execute({[i]:a,...t})}async execute(e){const[t,n]=await this.client.send(Bt.ENDPOINT,e,hy,fy);if(n!=null)throw n;return t.channels}}class qn{cache;namesToKeys;wrapped;constructor(e){this.cache=new Map,this.namesToKeys=new Map,this.wrapped=e}async retrieve(e,t){if(!Array.isArray(e)&&typeof e=="object")return await this.wrapped.retrieve(e);const{normalized:n}=se(e),i=[],a=[];if(n.forEach(c=>{const u=this.get(c);u!=null?i.push(...u):a.push(c)}),a.length===0)return i;const o=await this.wrapped.retrieve(a,t);return this.set(o),i.concat(o)}delete(e){const{variant:t,normalized:n}=se(e);t==="names"?n.forEach(i=>{const a=this.namesToKeys.get(i);a!=null&&(a.forEach(o=>this.cache.delete(o)),this.namesToKeys.delete(i))}):n.forEach(i=>{const a=this.cache.get(i);a!=null&&(this.cache.delete(i),this.namesToKeys.delete(a.name))})}rename(e,t){e.forEach((n,i)=>{const a=t[i],o=this.cache.get(n);if(o==null)return;this.cache.delete(n);const c=this.namesToKeys.get(o.name);c!=null&&(c.delete(n),c.size===0&&this.namesToKeys.delete(o.name)),o.name=a,this.cache.set(n,o);const u=this.namesToKeys.get(a);u==null?this.namesToKeys.set(a,new Set([n])):u.add(n)})}set(e){e.forEach(t=>{this.cache.set(t.key,t);const n=this.namesToKeys.get(t.name);n==null?this.namesToKeys.set(t.name,new Set([t.key])):n.add(t.key)})}get(e){if(typeof e=="number"){const i=this.cache.get(e);return i==null?void 0:[i]}const t=this.namesToKeys.get(e);if(t==null)return;const n=[];if(t.forEach(i=>{const a=this.cache.get(i);a!=null&&n.push(a)}),n.length!==0)return n}}class La{mu=new ly;requests=new Map;wrapped;debouncedRun;constructor(e,t){this.wrapped=e,this.debouncedRun=Gh(()=>{this.run()},t)}async retrieve(e){if(!Array.isArray(e)&&typeof e=="object")return await this.wrapped.retrieve(e);const{normalized:t,variant:n}=se(e);return n==="names"?await this.wrapped.retrieve(t):await new Promise((a,o)=>{this.mu.runExclusive(()=>{this.requests.set(t,{resolve:a,reject:o}),this.debouncedRun()})})}async run(){await this.mu.runExclusive(async()=>{const e=new Set;this.requests.forEach((t,n)=>n.forEach(i=>e.add(i)));try{const t=await this.wrapped.retrieve(Array.from(e));this.requests.forEach((n,i)=>n.resolve(t.filter(a=>i.includes(a.key))))}catch(t){this.requests.forEach(n=>n.reject(t))}finally{this.requests.clear()}})}}const Ba=async(r,e)=>{const{normalized:t}=se(e),n=await r.retrieve(t),i=[];if(t.forEach(a=>{n.find(o=>o.name===a||o.key===a)==null&&i.push(a)}),i.length>0)throw new xe(`Could not find channels: ${JSON.stringify(i)}`);return n},dy="sy_channel_set",yy="sy_channel_delete";class cr{_frameClient;key;name;dataType;leaseholder;index;isIndex;internal;alias;virtual;expression;requires;status;constructor({dataType:e,name:t,leaseholder:n=0,key:i=0,isIndex:a=!1,index:o=0,internal:c=!1,virtual:u=!1,frameClient:l,alias:h,status:y,expression:d="",requires:N=[]}){this.key=j.parse(i),this.name=t,this.dataType=new $(e),this.leaseholder=n,this.index=j.parse(o),this.isIndex=a,this.internal=c,this.alias=h,this.virtual=u,this.expression=d,this.requires=j.array().parse(N??[]),y!=null&&(this.status=Pt.create(y)),this._frameClient=l??null}get framer(){if(this._frameClient==null)throw new Z("cannot read from a channel that has not been created");return this._frameClient}get payload(){return at.parse({key:this.key,name:this.name,dataType:this.dataType.valueOf(),leaseholder:this.leaseholder,index:this.index,isIndex:this.isIndex,internal:this.internal,virtual:this.virtual,expression:this.expression,requires:this.requires,status:this.status})}get isCalculated(){return It(this.payload)}get ontologyID(){return Ya(this.key)}async read(e){return await this.framer.read(e,this.key)}async write(e,t){return await this.framer.write(e,this.key,t)}}const gy="sy_calculation_status",py="/channel/retrieve-group",my=s.z.object({}),wy=s.z.object({group:Tr});let qa=class{type="channel";frameClient;client;retriever;writer;constructor(e,t,n,i){this.frameClient=e,this.retriever=t,this.client=n,this.writer=i}async create(e,t={}){const{retrieveIfNameExists:n=!1}=t,i=!Array.isArray(e);let a=v.toArray(e),o=[];if(n){const c=await this.retriever.retrieve(a.map(l=>l.name)),u=new Set(c.map(l=>l.name));a=a.filter(l=>!u.has(l.name)),o=this.sugar(c)}return o=o.concat(this.sugar(await this.writer.create(a))),i?o[0]:o}async retrieve(e,t){if(typeof e=="object"&&!Array.isArray(e))return this.sugar(await this.retriever.retrieve(e));const n=!Array.isArray(e),i=this.sugar(await this.retriever.retrieve(e,t));return Fe("channel",e,i,n),n?i[0]:i}async delete(e){const{normalized:t,variant:n}=se(e);return n==="keys"?await this.writer.delete({keys:t}):await this.writer.delete({names:t})}async rename(e,t){return await this.writer.rename(v.toArray(e),v.toArray(t))}createDebouncedBatchRetriever(e=10){return new qn(new La(new Bt(this.client),e))}sugar(e){const{frameClient:t}=this;return Array.isArray(e)?e.map(n=>new cr({...n,frameClient:t})):new cr({...e,frameClient:t})}async retrieveGroup(){const e=await m(this.client,py,{},my,wy);return new Bn(e.group.name,e.group.key)}};const It=({virtual:r,expression:e})=>r&&e!=="",Fa=async(r,e)=>{if(!It(e))return e.index;for(const t of e.requires){const n=await r(t);if(n==null)return null;if(!n.virtual)return n.index}for(const t of e.requires){const n=await r(t);if(n==null)return null;if(It(n)){const i=await Fa(r,n);if(i!=null)return i}}return null},Ya=r=>({type:"channel",key:r.toString()}),by=s.z.object({channels:Za.array()}),Ty=s.z.object({channels:at.array()}),vy=s.z.object({keys:j.array().optional(),names:pe.array().optional()}),Ey=s.z.object({}),Ny=s.z.object({keys:j.array(),names:pe.array()}),Oy=s.z.object({}),zy="/channel/create",Sy="/channel/delete",Ay="/channel/rename";let Va=class{client;cache;constructor(e,t){this.client=e,this.cache=t}async create(e){const{channels:t}=await m(this.client,zy,{channels:e.map(n=>({...n,dataType:n.dataType}))},by,Ty);return this.cache.set(t),t}async delete(e){const t=j.array().parse(e.keys??[]);await m(this.client,Sy,e,vy,Ey),t.length>0&&this.cache.delete(t),e.names!=null&&this.cache.delete(e.names)}async rename(e,t){await m(this.client,Ay,{keys:e,names:t},Ny,Oy),this.cache.rename(e,t)}};const $y=Object.freeze(Object.defineProperty({__proto__:null,CALCULATION_STATUS_CHANNEL_NAME:gy,CacheRetriever:qn,Channel:cr,Client:qa,ClusterRetriever:Bt,DELETE_CHANNEL_NAME:yy,DebouncedBatchRetriever:La,SET_CHANNEL_NAME:dy,Writer:Va,analyzeParams:se,isCalculated:It,keyZ:j,nameZ:pe,newZ:Za,ontologyID:Ya,paramsZ:qe,payloadZ:at,resolveCalculatedIndex:Fa,retrieveRequired:Ba,statusZ:Da},Symbol.toStringTag,{value:"Module"})),Ce=s.z.uuid(),qt=s.z.object({key:Ce,username:s.z.string().min(1),firstName:s.z.string().default(""),lastName:s.z.string().default(""),rootUser:s.z.boolean().default(!0)}),Ha=qt.partial({key:!0,firstName:!0,lastName:!0}).omit({rootUser:!0}).extend({password:s.z.string().min(1)}),Iy=s.z.object({keys:Ce.array().optional(),usernames:s.z.string().array().optional()}),ky=s.z.object({key:Ce}).transform(({key:r})=>({keys:[r]})),xy=s.z.object({username:s.z.string()}).transform(({username:r})=>({usernames:[r]})),Cy=s.z.object({usernames:s.z.string().array()}).transform(({usernames:r})=>({usernames:r})),Ry=s.z.union([ky,xy,Cy,Iy]),jy=s.z.object({users:L(qt)}),My=s.z.object({users:Ha.array()}),Uy=s.z.object({users:qt.array()}),Dy=s.z.object({key:Ce,username:s.z.string().min(1)}),Zy=s.z.object({}),Py=s.z.object({key:Ce,firstName:s.z.string().optional(),lastName:s.z.string().optional()}),Ly=s.z.object({}),By=s.z.object({keys:Ce.array()}),qy=s.z.object({}),Fy="/user/retrieve",Yy="/user/create",Vy="/user/change-username",Hy="/user/rename",_y="/user/delete";let _a=class{client;constructor(e){this.client=e}async create(e){const t=Array.isArray(e),n=await m(this.client,Yy,{users:v.toArray(e)},My,Uy);return t?n.users:n.users[0]}async changeUsername(e,t){await m(this.client,Vy,{key:e,username:t},Dy,Zy)}async retrieve(e){const t="key"in e||"username"in e,n=await m(this.client,Fy,e,Ry,jy);if(!t)return n.users;if(n.users.length===0){const i="key"in e?`key ${e.key}`:`username ${e.username}`;throw new St(`No user with ${i} found`)}if(n.users.length>1){const i="key"in e?`key ${e.key}`:`username ${e.username}`;throw new At(`Multiple users found with ${i}`)}return n.users[0]}async rename(e,t,n){await m(this.client,Hy,{key:e,firstName:t,lastName:n},Py,Ly)}async delete(e){await m(this.client,_y,{keys:v.toArray(e)},By,qy)}};const Wy=r=>({type:"user",key:r}),Gy=Object.freeze(Object.defineProperty({__proto__:null,Client:_a,keyZ:Ce,newZ:Ha,ontologyID:Wy,userZ:qt},Symbol.toStringTag,{value:"Module"})),Ky=s.z.object({username:s.z.string(),password:s.z.string()}),Jy=s.z.object({token:s.z.string(),user:qt}),zs="/auth/login",Xy=3,Qy="/auth/change-password",eg=s.z.object({username:s.z.string(),password:s.z.string(),newPassword:s.z.string().min(1)}),tg=s.z.object({}),rg=[yn,gn];let ng=class{token;client;credentials;authenticating;authenticated;user;retryCount;constructor(e,t){this.client=e,this.authenticated=!1,this.credentials=t,this.retryCount=0}async changePassword(e){if(!this.authenticated)throw new Error("Not authenticated");await m(this.client,Qy,{username:this.credentials.username,password:this.credentials.password,newPassword:e},eg,tg),this.credentials.password=e}middleware(){const e=async(t,n)=>{if(!this.authenticated&&!t.target.endsWith(zs)){this.authenticating??=new Promise((c,u)=>{this.client.send(zs,this.credentials,Ky,Jy).then(([l,h])=>{if(h!=null)return c(h);this.token=l?.token,this.user=l?.user,this.authenticated=!0,c(null)}).catch(u)});const o=await this.authenticating;if(o!=null)return[t,o]}t.params.Authorization=`Bearer ${this.token}`;const[i,a]=await n(t);return rg.some(o=>o.matches(a))&&this.retryCount<Xy?(this.authenticated=!1,this.authenticating=void 0,this.retryCount+=1,e(t,n)):(this.retryCount=0,[i,a])};return e}};const Wa=s.z.enum(["disconnected","connecting","connected","failed"]),Ga=s.z.object({status:Wa,error:s.z.instanceof(Error).optional(),message:s.z.string().optional(),clusterKey:s.z.string(),clientVersion:s.z.string(),clientServerCompatible:s.z.boolean(),nodeVersion:s.z.string().optional()}),sg=s.z.object({clusterKey:s.z.string(),nodeVersion:s.z.string().optional()}),Ss={clusterKey:"",status:"disconnected",error:void 0,message:"Disconnected",clientServerCompatible:!1,clientVersion:"0.45.0"},As=(r,e,t)=>{const n=t?"cluster":"client";return`Synnax cluster node version ${r!=null?`${r} `:""}is too ${t?"old":"new"} for client version ${e}.
|
|
21
|
+
`)}}class xe extends he.sub("query"){}class St extends xe.sub("not_found"){}class At extends xe.sub("multiple_results"){}class mn extends he.sub("route"){path;constructor(e,t){super(e),this.path=t}}class wn extends he.sub("control"){}class Ns extends wn.sub("unauthorized"){}class od extends he.sub("disconnected"){constructor(e="Operation failed because no cluster is connected."){super(e)}}class cd extends he.sub("contiguity"){}const ld=r=>r.type.startsWith(he.TYPE)?r.type.startsWith(Z.TYPE)?r.type===Ot.TYPE?Ot.decode(r):new Z(r.data):r.type.startsWith(zt.TYPE)?r.type.startsWith(gn.TYPE)?new gn(r.data):r.type.startsWith(pn.TYPE)?new pn(r.data):new zt(r.data):r.type.startsWith(Xe.TYPE)?new Xe(r.data):r.type.startsWith(xe.TYPE)?r.type.startsWith(St.TYPE)?new St(r.data):r.type.startsWith(At.TYPE)?new At(r.data):new xe(r.data):r.type.startsWith(wn.TYPE)?r.type.startsWith(Ns.TYPE)?new Ns(r.data):new wn(r.data):r.type.startsWith(mn.TYPE)?new mn(r.data,r.data):new Xe(r.data):null,ud=()=>{throw new me.NotImplemented};me.register({encode:ud,decode:ld});const hd=async(r,e)=>{const[t,n]=await e(r);return n==null?[t,n]:n instanceof Ie?[t,new Ie({message:`Cannot reach cluster at ${n.url.host}:${n.url.port}`,url:n.url})]:[t,n]};class qn{key;name;constructor(e,t){this.key=t,this.name=e}get ontologyID(){return Ia(this.key)}}const Ia=r=>({type:"group",key:r}),Lt=s.z.uuid(),br=s.z.string(),Tr=s.z.object({key:Lt,name:br}),ka="builtin",fd="cluster",dd="node",vr=s.z.enum(["label","log","allow_all","builtin","cluster","channel","node","group","range","framer","range-alias","user","workspace","schematic","lineplot","rack","device","task","policy","table","schematic_symbol"]),yd=s.z.string().transform(r=>{const[e,t]=r.split(":");return{type:vr.parse(e),key:t??""}}),C=s.z.object({type:vr,key:s.z.string()}).or(yd),gd={type:ka,key:"root"},$t=r=>`${r.type}:${r.key}`,pd=(r,e)=>r.type===e.type&&r.key===e.key,xa=r=>{const e=v.toArray(r);return e.length===0?[]:typeof e[0]=="object"&&"id"in e[0]?e.map(({id:t})=>t):e.map(t=>C.parse(t))},Ca=s.z.object({id:C,name:s.z.string(),data:we.unknownZ.optional().nullable()}).transform(r=>({key:$t(r.id),...r})),md=r=>r==="to"?"from":"to",wd=s.z.object({from:C,type:s.z.string(),to:C}).or(s.z.string().transform(r=>{const[e,t,n]=r.split("->");return{from:C.parse(e),type:t,to:C.parse(n)}})),bd=r=>`${$t(r.from)}->${r.type}->${$t(r.to)}`,Td="parent",vd=(r,e)=>!(e.type!=null&&e.type!==r.type||e.from?.type!=null&&e.from.type!==r.from.type||e.to?.type!=null&&e.to.type!==r.to.type||e.from?.key!=null&&e.from.key!==r.from.key||e.to?.key!=null&&e.to.key!==r.to.key),Ed=s.z.object({group:Tr}),Nd=s.z.object({parent:C,key:Lt.optional(),name:br}),Od=s.z.object({key:Lt,name:br}),zd=s.z.object({keys:s.z.array(Lt)});let Sd=class sr{static CREATE_ENDPOINT="/ontology/create-group";static RENAME_ENDPOINT="/ontology/rename-group";static DELETE_ENDPOINT="/ontology/delete-group";client;constructor(e){this.client=e}async create(e,t,n){return(await m(this.client,sr.CREATE_ENDPOINT,{parent:e,name:t,key:n},Nd,Ed)).group}async rename(e,t){await m(this.client,sr.RENAME_ENDPOINT,{key:e,name:t},Od,s.z.object({}))}async delete(e){await m(this.client,sr.DELETE_ENDPOINT,{keys:e},zd,s.z.object({}))}};const Ad="sy_group_set",$d="sy_group_delete";let Ra=class{creator;constructor(e){this.creator=new Sd(e)}async create(e,t,n){return this.sugar(await this.creator.create(e,t,n))}async rename(e,t){return await this.creator.rename(e,t)}async delete(...e){return await this.creator.delete(e)}sugar(e){return new qn(e.name,e.key)}};const Id=Object.freeze(Object.defineProperty({__proto__:null,Client:Ra,DELETE_CHANNEL_NAME:$d,Group:qn,SET_CHANNEL_NAME:Ad,groupZ:Tr,keyZ:Lt,nameZ:br,ontologyID:Ia},Symbol.toStringTag,{value:"Module"})),kd="/ontology/add-children",xd="/ontology/remove-children",Cd="/ontology/move-children",Os=s.z.object({id:C,children:C.array()}),Rd=s.z.object({from:C,to:C,children:C.array()}),Br=s.z.object({});let jd=class{client;constructor(e){this.client=e}async addChildren(e,...t){await m(this.client,kd,{id:e,children:t},Os,Br)}async removeChildren(e,...t){await m(this.client,xd,{id:e,children:t},Os,Br)}async moveChildren(e,t,...n){await m(this.client,Cd,{from:e,to:t,children:n},Rd,Br)}};const Md="/ontology/retrieve",Ud=s.z.object({ids:C.array().optional(),children:s.z.boolean().optional(),parents:s.z.boolean().optional(),excludeFieldData:s.z.boolean().optional(),searchTerm:s.z.string().optional(),limit:s.z.number().optional(),offset:s.z.number().optional(),types:vr.array().optional()}),Dd=s.z.object({resources:Ca.array()});let ja=class{type="ontology";groups;client;writer;framer;constructor(e,t){this.client=e,this.writer=new jd(e),this.groups=new Ra(e),this.framer=t}async retrieve(e,t){if(!Array.isArray(e)&&typeof e=="object"&&!("key"in e))return this.execRetrieve(e);const n=xa(e),i=await this.execRetrieve({ids:n,...t});if(Array.isArray(e))return i;if(i.length===0)throw new xe(`No resource found with ID ${yn.naturalLanguageJoin(n.map(a=>$t(a)))}`);return i[0]}async retrieveChildren(e,t){return await this.execRetrieve({ids:v.toArray(e),children:!0,...t})}async retrieveParents(e,t){return await this.execRetrieve({ids:v.toArray(e),parents:!0,...t})}async addChildren(e,...t){return await this.writer.addChildren(e,...t)}async removeChildren(e,...t){return await this.writer.removeChildren(e,...t)}async moveChildren(e,t,...n){return await this.writer.moveChildren(e,t,...n)}async execRetrieve(e){const{resources:t}=await m(this.client,Md,e,Ud,Dd);return t}};const Zd="sy_ontology_resource_set",Pd="sy_ontology_resource_delete",Ld="sy_ontology_relationship_set",Bd="sy_ontology_relationship_delete",qd=Object.freeze(Object.defineProperty({__proto__:null,BUILTIN_TYPE:ka,CLUSTER_TYPE:fd,Client:ja,NODE_TYPE:dd,PARENT_OF_RELATIONSHIP_TYPE:Td,RELATIONSHIP_DELETE_CHANNEL_NAME:Bd,RELATIONSHIP_SET_CHANNEL_NAME:Ld,RESOURCE_DELETE_CHANNEL_NAME:Pd,RESOURCE_SET_CHANNEL_NAME:Zd,ROOT_ID:gd,idToString:$t,idZ:C,idsEqual:pd,matchRelationship:vd,oppositeRelationshipDirection:md,parseIDs:xa,relationshipToString:bd,relationshipZ:wd,resourceTypeZ:vr,resourceZ:Ca},Symbol.toStringTag,{value:"Module"})),L=r=>s.z.union([s.z.union([s.z.null(),s.z.undefined()]).transform(()=>[]),r.array()]),it=s.z.uuid(),Er=s.z.object({key:it,subjects:L(C),objects:L(C),actions:L(or)}),Ma=s.z.object({key:it.optional(),subjects:C.array().or(C),objects:C.array().or(C),actions:or.array().or(or)}),Fd=s.z.object({keys:it.array().optional(),subjects:C.array().optional()}),Yd=s.z.object({key:it}).transform(({key:r})=>({keys:[r]})),Vd=s.z.union([s.z.object({for:C}).transform(({for:r})=>({subjects:[r]})),s.z.object({for:C.array()}).transform(({for:r})=>({subjects:r})),Fd]),Hd=s.z.union([Yd,Vd]),_d=s.z.object({policies:L(Er)}),Wd=s.z.object({policies:Er.partial({key:!0}).array()}),Gd=s.z.object({policies:Er.array()}),Kd=s.z.object({keys:it.array()}),Jd=s.z.object({}),Xd="/access/policy/retrieve",Qd="/access/policy/create",ey="/access/policy/delete";let Ua=class{client;constructor(e){this.client=e}async create(e){const t=Array.isArray(e),i=Ma.array().parse(v.toArray(e)).map(o=>({objects:v.toArray(o.objects),actions:v.toArray(o.actions),subjects:v.toArray(o.subjects)})),a=await m(this.client,Qd,{policies:i},Wd,Gd);return t?a.policies:a.policies[0]}async retrieve(e){const t="key"in e,n=await m(this.client,Xd,e,Hd,_d);return t?n.policies[0]:n.policies}async delete(e){await m(this.client,ey,{keys:v.toArray(e)},Kd,Jd)}};const ty=r=>({type:"policy",key:r}),ry={type:"allow_all",key:""},ny=Object.freeze(Object.defineProperty({__proto__:null,ALLOW_ALL_ONTOLOGY_ID:ry,Client:Ua,keyZ:it,newZ:Ma,ontologyID:ty,policyZ:Er},Symbol.toStringTag,{value:"Module"}));let Da=class{policy;constructor(e){this.policy=new Ua(e)}};const sy=Object.freeze(Object.defineProperty({__proto__:null,ALL_ACTION:Oa,CREATE_ACTION:za,Client:Da,DELETE_ACTION:Sa,RETRIEVE_ACTION:Aa,UPDATE_ACTION:$a,actionZ:or},Symbol.toStringTag,{value:"Module"})),zs="Channel key must be a valid uint32.",j=s.z.uint32().or(s.z.string().refine(r=>!isNaN(Number(r)),{message:zs}).transform(Number).refine(r=>r<2**32-1,{message:zs})),pe=s.z.string(),Za=Pt.statusZ(),at=s.z.object({name:pe,key:j,dataType:$.z,leaseholder:s.z.number(),index:j,isIndex:s.z.boolean(),internal:s.z.boolean(),virtual:s.z.boolean(),alias:s.z.string().optional(),expression:s.z.string().default(""),requires:L(j),status:Za.optional()}),Pa=at.extend({key:j.optional(),leaseholder:s.z.number().optional(),index:j.optional(),isIndex:s.z.boolean().optional(),internal:s.z.boolean().optional().default(!1),virtual:s.z.boolean().optional().default(!1),expression:s.z.string().optional().default(""),requires:L(j).optional().default([])}),qe=s.z.union([bt.toArray(j),bt.toArray(pe),bt.toArray(at).transform(r=>r.map(e=>e.key))]),iy=new Error("request for lock canceled");var ay=function(r,e,t,n){function i(a){return a instanceof t?a:new t(function(o){o(a)})}return new(t||(t=Promise))(function(a,o){function c(h){try{l(n.next(h))}catch(y){o(y)}}function u(h){try{l(n.throw(h))}catch(y){o(y)}}function l(h){h.done?a(h.value):i(h.value).then(c,u)}l((n=n.apply(r,e||[])).next())})};class oy{constructor(e,t=iy){this._value=e,this._cancelError=t,this._queue=[],this._weightedWaiters=[]}acquire(e=1,t=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return new Promise((n,i)=>{const a={resolve:n,reject:i,weight:e,priority:t},o=La(this._queue,c=>t<=c.priority);o===-1&&e<=this._value?this._dispatchItem(a):this._queue.splice(o+1,0,a)})}runExclusive(e){return ay(this,arguments,void 0,function*(t,n=1,i=0){const[a,o]=yield this.acquire(n,i);try{return yield t(a)}finally{o()}})}waitForUnlock(e=1,t=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return this._couldLockImmediately(e,t)?Promise.resolve():new Promise(n=>{this._weightedWaiters[e-1]||(this._weightedWaiters[e-1]=[]),cy(this._weightedWaiters[e-1],{resolve:n,priority:t})})}isLocked(){return this._value<=0}getValue(){return this._value}setValue(e){this._value=e,this._dispatchQueue()}release(e=1){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);this._value+=e,this._dispatchQueue()}cancel(){this._queue.forEach(e=>e.reject(this._cancelError)),this._queue=[]}_dispatchQueue(){for(this._drainUnlockWaiters();this._queue.length>0&&this._queue[0].weight<=this._value;)this._dispatchItem(this._queue.shift()),this._drainUnlockWaiters()}_dispatchItem(e){const t=this._value;this._value-=e.weight,e.resolve([t,this._newReleaser(e.weight)])}_newReleaser(e){let t=!1;return()=>{t||(t=!0,this.release(e))}}_drainUnlockWaiters(){if(this._queue.length===0)for(let e=this._value;e>0;e--){const t=this._weightedWaiters[e-1];t&&(t.forEach(n=>n.resolve()),this._weightedWaiters[e-1]=[])}else{const e=this._queue[0].priority;for(let t=this._value;t>0;t--){const n=this._weightedWaiters[t-1];if(!n)continue;const i=n.findIndex(a=>a.priority<=e);(i===-1?n:n.splice(0,i)).forEach(a=>a.resolve())}}}_couldLockImmediately(e,t){return(this._queue.length===0||this._queue[0].priority<t)&&e<=this._value}}function cy(r,e){const t=La(r,n=>e.priority<=n.priority);r.splice(t+1,0,e)}function La(r,e){for(let t=r.length-1;t>=0;t--)if(e(r[t]))return t;return-1}var ly=function(r,e,t,n){function i(a){return a instanceof t?a:new t(function(o){o(a)})}return new(t||(t=Promise))(function(a,o){function c(h){try{l(n.next(h))}catch(y){o(y)}}function u(h){try{l(n.throw(h))}catch(y){o(y)}}function l(h){h.done?a(h.value):i(h.value).then(c,u)}l((n=n.apply(r,e||[])).next())})};class uy{constructor(e){this._semaphore=new oy(1,e)}acquire(){return ly(this,arguments,void 0,function*(e=0){const[,t]=yield this._semaphore.acquire(1,e);return t})}runExclusive(e,t=0){return this._semaphore.runExclusive(()=>e(),1,t)}isLocked(){return this._semaphore.isLocked()}waitForUnlock(e=0){return this._semaphore.waitForUnlock(1,e)}release(){this._semaphore.isLocked()&&this._semaphore.release()}cancel(){return this._semaphore.cancel()}}const hy=(r,e,{convertNumericStrings:t=!0}={})=>{const n=!Array.isArray(r);let i=v.toArray(r);const a=i[0],o=typeof a;let c;return o==="string"&&t&&!isNaN(parseInt(a))&&"number"in e?(c=e.number,i=i.map(u=>parseInt(u))):c=e[o],{single:n,variant:c,normalized:i,actual:r}},Fe=(r,e,t,n)=>{if(n){if(t.length===0)throw new St(`${r} not found matching ${JSON.stringify(e)}`);if(t.length>1)throw new At(`Expected one ${r} matching ${JSON.stringify(e)}, but found ${t.length}`)}},fy=s.z.object({leaseholder:s.z.number().optional(),keys:j.array().optional(),names:s.z.string().array().optional(),searchTerm:s.z.string().optional(),rangeKey:s.z.string().optional(),limit:s.z.number().optional(),offset:s.z.number().optional(),dataTypes:$.z.array().optional(),notDataTypes:$.z.array().optional(),virtual:s.z.boolean().optional(),isIndex:s.z.boolean().optional(),internal:s.z.boolean().optional(),calculated:s.z.boolean().optional()}),dy=s.z.object({channels:L(at)}),se=r=>(Array.isArray(r)&&r.length>0&&typeof r[0]=="object"?r=r.map(e=>e.key):typeof r=="object"&&"key"in r&&(r=[r.key]),hy(r,{number:"keys",string:"names"}));class Bt{static ENDPOINT="/channel/retrieve";client;constructor(e){this.client=e}async retrieve(e,t){if(!Array.isArray(e)&&typeof e=="object")return await this.execute(e);const n=se(e),{variant:i}=n;let{normalized:a}=n;return i==="keys"&&a.indexOf(0)!==-1&&(a=a.filter(o=>o!==0)),a.length===0?[]:await this.execute({[i]:a,...t})}async execute(e){const[t,n]=await this.client.send(Bt.ENDPOINT,e,fy,dy);if(n!=null)throw n;return t.channels}}class Fn{cache;namesToKeys;wrapped;constructor(e){this.cache=new Map,this.namesToKeys=new Map,this.wrapped=e}async retrieve(e,t){if(!Array.isArray(e)&&typeof e=="object")return await this.wrapped.retrieve(e);const{normalized:n}=se(e),i=[],a=[];if(n.forEach(c=>{const u=this.get(c);u!=null?i.push(...u):a.push(c)}),a.length===0)return i;const o=await this.wrapped.retrieve(a,t);return this.set(o),i.concat(o)}delete(e){const{variant:t,normalized:n}=se(e);t==="names"?n.forEach(i=>{const a=this.namesToKeys.get(i);a!=null&&(a.forEach(o=>this.cache.delete(o)),this.namesToKeys.delete(i))}):n.forEach(i=>{const a=this.cache.get(i);a!=null&&(this.cache.delete(i),this.namesToKeys.delete(a.name))})}rename(e,t){e.forEach((n,i)=>{const a=t[i],o=this.cache.get(n);if(o==null)return;this.cache.delete(n);const c=this.namesToKeys.get(o.name);c!=null&&(c.delete(n),c.size===0&&this.namesToKeys.delete(o.name)),o.name=a,this.cache.set(n,o);const u=this.namesToKeys.get(a);u==null?this.namesToKeys.set(a,new Set([n])):u.add(n)})}set(e){e.forEach(t=>{this.cache.set(t.key,t);const n=this.namesToKeys.get(t.name);n==null?this.namesToKeys.set(t.name,new Set([t.key])):n.add(t.key)})}get(e){if(typeof e=="number"){const i=this.cache.get(e);return i==null?void 0:[i]}const t=this.namesToKeys.get(e);if(t==null)return;const n=[];if(t.forEach(i=>{const a=this.cache.get(i);a!=null&&n.push(a)}),n.length!==0)return n}}class Ba{mu=new uy;requests=new Map;wrapped;debouncedRun;constructor(e,t){this.wrapped=e,this.debouncedRun=Kh(()=>{this.run()},t)}async retrieve(e){if(!Array.isArray(e)&&typeof e=="object")return await this.wrapped.retrieve(e);const{normalized:t,variant:n}=se(e);return n==="names"?await this.wrapped.retrieve(t):await new Promise((a,o)=>{this.mu.runExclusive(()=>{this.requests.set(t,{resolve:a,reject:o}),this.debouncedRun()})})}async run(){await this.mu.runExclusive(async()=>{const e=new Set;this.requests.forEach((t,n)=>n.forEach(i=>e.add(i)));try{const t=await this.wrapped.retrieve(Array.from(e));this.requests.forEach((n,i)=>n.resolve(t.filter(a=>i.includes(a.key))))}catch(t){this.requests.forEach(n=>n.reject(t))}finally{this.requests.clear()}})}}const qa=async(r,e)=>{const{normalized:t}=se(e),n=await r.retrieve(t),i=[];if(t.forEach(a=>{n.find(o=>o.name===a||o.key===a)==null&&i.push(a)}),i.length>0)throw new xe(`Could not find channels: ${JSON.stringify(i)}`);return n},yy="sy_channel_set",gy="sy_channel_delete";class cr{_frameClient;key;name;dataType;leaseholder;index;isIndex;internal;alias;virtual;expression;requires;status;constructor({dataType:e,name:t,leaseholder:n=0,key:i=0,isIndex:a=!1,index:o=0,internal:c=!1,virtual:u=!1,frameClient:l,alias:h,status:y,expression:d="",requires:N=[]}){this.key=j.parse(i),this.name=t,this.dataType=new $(e),this.leaseholder=n,this.index=j.parse(o),this.isIndex=a,this.internal=c,this.alias=h,this.virtual=u,this.expression=d,this.requires=j.array().parse(N??[]),y!=null&&(this.status=Pt.create(y)),this._frameClient=l??null}get framer(){if(this._frameClient==null)throw new Z("cannot read from a channel that has not been created");return this._frameClient}get payload(){return at.parse({key:this.key,name:this.name,dataType:this.dataType.valueOf(),leaseholder:this.leaseholder,index:this.index,isIndex:this.isIndex,internal:this.internal,virtual:this.virtual,expression:this.expression,requires:this.requires,status:this.status})}get isCalculated(){return It(this.payload)}get ontologyID(){return Va(this.key)}async read(e){return await this.framer.read(e,this.key)}async write(e,t){return await this.framer.write(e,this.key,t)}}const py="sy_calculation_status",my="/channel/retrieve-group",wy=s.z.object({}),by=s.z.object({group:Tr});let Fa=class{type="channel";frameClient;client;retriever;writer;constructor(e,t,n,i){this.frameClient=e,this.retriever=t,this.client=n,this.writer=i}async create(e,t={}){const{retrieveIfNameExists:n=!1}=t,i=!Array.isArray(e);let a=v.toArray(e),o=[];if(n){const c=await this.retriever.retrieve(a.map(l=>l.name)),u=new Set(c.map(l=>l.name));a=a.filter(l=>!u.has(l.name)),o=this.sugar(c)}return o=o.concat(this.sugar(await this.writer.create(a))),i?o[0]:o}async retrieve(e,t){if(typeof e=="object"&&!Array.isArray(e))return this.sugar(await this.retriever.retrieve(e));const n=!Array.isArray(e),i=this.sugar(await this.retriever.retrieve(e,t));return Fe("channel",e,i,n),n?i[0]:i}async delete(e){const{normalized:t,variant:n}=se(e);return n==="keys"?await this.writer.delete({keys:t}):await this.writer.delete({names:t})}async rename(e,t){return await this.writer.rename(v.toArray(e),v.toArray(t))}createDebouncedBatchRetriever(e=10){return new Fn(new Ba(new Bt(this.client),e))}sugar(e){const{frameClient:t}=this;return Array.isArray(e)?e.map(n=>new cr({...n,frameClient:t})):new cr({...e,frameClient:t})}async retrieveGroup(){const e=await m(this.client,my,{},wy,by);return new qn(e.group.name,e.group.key)}};const It=({virtual:r,expression:e})=>r&&e!=="",Ya=async(r,e)=>{if(!It(e))return e.index;for(const t of e.requires){const n=await r(t);if(n==null)return null;if(!n.virtual)return n.index}for(const t of e.requires){const n=await r(t);if(n==null)return null;if(It(n)){const i=await Ya(r,n);if(i!=null)return i}}return null},Va=r=>({type:"channel",key:r.toString()}),Ty=s.z.object({channels:Pa.array()}),vy=s.z.object({channels:at.array()}),Ey=s.z.object({keys:j.array().optional(),names:pe.array().optional()}),Ny=s.z.object({}),Oy=s.z.object({keys:j.array(),names:pe.array()}),zy=s.z.object({}),Sy="/channel/create",Ay="/channel/delete",$y="/channel/rename";let Ha=class{client;cache;constructor(e,t){this.client=e,this.cache=t}async create(e){const{channels:t}=await m(this.client,Sy,{channels:e.map(n=>({...n,dataType:n.dataType}))},Ty,vy);return this.cache.set(t),t}async delete(e){const t=j.array().parse(e.keys??[]);await m(this.client,Ay,e,Ey,Ny),t.length>0&&this.cache.delete(t),e.names!=null&&this.cache.delete(e.names)}async rename(e,t){await m(this.client,$y,{keys:e,names:t},Oy,zy),this.cache.rename(e,t)}};const Iy=Object.freeze(Object.defineProperty({__proto__:null,CALCULATION_STATUS_CHANNEL_NAME:py,CacheRetriever:Fn,Channel:cr,Client:Fa,ClusterRetriever:Bt,DELETE_CHANNEL_NAME:gy,DebouncedBatchRetriever:Ba,SET_CHANNEL_NAME:yy,Writer:Ha,analyzeParams:se,isCalculated:It,keyZ:j,nameZ:pe,newZ:Pa,ontologyID:Va,paramsZ:qe,payloadZ:at,resolveCalculatedIndex:Ya,retrieveRequired:qa,statusZ:Za},Symbol.toStringTag,{value:"Module"})),Ce=s.z.uuid(),qt=s.z.object({key:Ce,username:s.z.string().min(1),firstName:s.z.string().default(""),lastName:s.z.string().default(""),rootUser:s.z.boolean().default(!0)}),_a=qt.partial({key:!0,firstName:!0,lastName:!0}).omit({rootUser:!0}).extend({password:s.z.string().min(1)}),ky=s.z.object({keys:Ce.array().optional(),usernames:s.z.string().array().optional()}),xy=s.z.object({key:Ce}).transform(({key:r})=>({keys:[r]})),Cy=s.z.object({username:s.z.string()}).transform(({username:r})=>({usernames:[r]})),Ry=s.z.object({usernames:s.z.string().array()}).transform(({usernames:r})=>({usernames:r})),jy=s.z.union([xy,Cy,Ry,ky]),My=s.z.object({users:L(qt)}),Uy=s.z.object({users:_a.array()}),Dy=s.z.object({users:qt.array()}),Zy=s.z.object({key:Ce,username:s.z.string().min(1)}),Py=s.z.object({}),Ly=s.z.object({key:Ce,firstName:s.z.string().optional(),lastName:s.z.string().optional()}),By=s.z.object({}),qy=s.z.object({keys:Ce.array()}),Fy=s.z.object({}),Yy="/user/retrieve",Vy="/user/create",Hy="/user/change-username",_y="/user/rename",Wy="/user/delete";let Wa=class{client;constructor(e){this.client=e}async create(e){const t=Array.isArray(e),n=await m(this.client,Vy,{users:v.toArray(e)},Uy,Dy);return t?n.users:n.users[0]}async changeUsername(e,t){await m(this.client,Hy,{key:e,username:t},Zy,Py)}async retrieve(e){const t="key"in e||"username"in e,n=await m(this.client,Yy,e,jy,My);if(!t)return n.users;if(n.users.length===0){const i="key"in e?`key ${e.key}`:`username ${e.username}`;throw new St(`No user with ${i} found`)}if(n.users.length>1){const i="key"in e?`key ${e.key}`:`username ${e.username}`;throw new At(`Multiple users found with ${i}`)}return n.users[0]}async rename(e,t,n){await m(this.client,_y,{key:e,firstName:t,lastName:n},Ly,By)}async delete(e){await m(this.client,Wy,{keys:v.toArray(e)},qy,Fy)}};const Gy=r=>({type:"user",key:r}),Ky=Object.freeze(Object.defineProperty({__proto__:null,Client:Wa,keyZ:Ce,newZ:_a,ontologyID:Gy,userZ:qt},Symbol.toStringTag,{value:"Module"})),Jy=s.z.object({username:s.z.string(),password:s.z.string()}),Xy=s.z.object({token:s.z.string(),user:qt}),Ss="/auth/login",Qy=3,eg="/auth/change-password",tg=s.z.object({username:s.z.string(),password:s.z.string(),newPassword:s.z.string().min(1)}),rg=s.z.object({}),ng=[gn,pn];let sg=class{token;client;credentials;authenticating;authenticated;user;retryCount;constructor(e,t){this.client=e,this.authenticated=!1,this.credentials=t,this.retryCount=0}async changePassword(e){if(!this.authenticated)throw new Error("Not authenticated");await m(this.client,eg,{username:this.credentials.username,password:this.credentials.password,newPassword:e},tg,rg),this.credentials.password=e}middleware(){const e=async(t,n)=>{if(!this.authenticated&&!t.target.endsWith(Ss)){this.authenticating??=new Promise((c,u)=>{this.client.send(Ss,this.credentials,Jy,Xy).then(([l,h])=>{if(h!=null)return c(h);this.token=l?.token,this.user=l?.user,this.authenticated=!0,c(null)}).catch(u)});const o=await this.authenticating;if(o!=null)return[t,o]}t.params.Authorization=`Bearer ${this.token}`;const[i,a]=await n(t);return ng.some(o=>o.matches(a))&&this.retryCount<Qy?(this.authenticated=!1,this.authenticating=void 0,this.retryCount+=1,e(t,n)):(this.retryCount=0,[i,a])};return e}};const Ga=s.z.enum(["disconnected","connecting","connected","failed"]),Ka=s.z.object({status:Ga,error:s.z.instanceof(Error).optional(),message:s.z.string().optional(),clusterKey:s.z.string(),clientVersion:s.z.string(),clientServerCompatible:s.z.boolean(),nodeVersion:s.z.string().optional()}),ig=s.z.object({clusterKey:s.z.string(),nodeVersion:s.z.string().optional()}),As={clusterKey:"",status:"disconnected",error:void 0,message:"Disconnected",clientServerCompatible:!1,clientVersion:"0.45.1"},$s=(r,e,t)=>{const n=t?"cluster":"client";return`Synnax cluster node version ${r!=null?`${r} `:""}is too ${t?"old":"new"} for client version ${e}.
|
|
22
22
|
This may cause compatibility issues. We recommend updating the ${n}. For more information, see
|
|
23
|
-
https://docs.synnaxlabs.com/reference/typescript-client/troubleshooting#old-${n}-version`};class kt{static ENDPOINT="/connectivity/check";static DEFAULT=
|
|
24
|
-
Got ${t.length} ${n}s and ${e.length} series.`)};class P{columns=[];series=[];constructor(e=[],t=[]){if(e instanceof P){this.columns=e.columns,this.series=e.series;return}if(e instanceof Map){e.forEach((i,a)=>this.push(a,...v.toArray(i)));return}if(typeof e=="object"&&!Array.isArray(e)){if("keys"in e&&"series"in e){const i=e;i.series??=[],i.keys??=[];const a=i.series.map(o=>
|
|
23
|
+
https://docs.synnaxlabs.com/reference/typescript-client/troubleshooting#old-${n}-version`};class kt{static ENDPOINT="/connectivity/check";static DEFAULT=As;_state;pollFrequency=E.seconds(30);client;name;interval;clientVersion;onChangeHandlers=[];static connectionStateZ=Ka;versionWarned=!1;constructor(e,t=E.seconds(30),n,i){this._state={...As},this.client=e,this.pollFrequency=t,this.clientVersion=n,this.name=i,this.check(),this.startChecking()}stopChecking(){this.interval!=null&&clearInterval(this.interval)}async check(){const e=this._state.status;try{const[t,n]=await this.client.send(kt.ENDPOINT,{},s.z.object({}),ig);if(n!=null)throw n;const i=t.nodeVersion,a=this.clientVersion,o=this.versionWarned;i==null?(this._state.clientServerCompatible=!1,o||(console.warn($s(null,a,!0)),this.versionWarned=!0)):Es.versionsEqual(a,i,{checkMajor:!0,checkMinor:!0,checkPatch:!1})?this._state.clientServerCompatible=!0:(this._state.clientServerCompatible=!1,o||(console.warn($s(i,a,Es.semVerNewer(a,i))),this.versionWarned=!0)),this._state.status="connected",this._state.message=`Connected to ${this.name??"cluster"}`,this._state.clusterKey=t.clusterKey,this._state.nodeVersion=t.nodeVersion,this._state.clientVersion=this.clientVersion}catch(t){this._state.status="failed",this._state.error=t,this._state.message=this.state.error?.message}return this.onChangeHandlers.length>0&&e!==this._state.status&&this.onChangeHandlers.forEach(t=>t(this.state)),this.state}get state(){return{...this._state}}onChange(e){this.onChangeHandlers.push(e)}startChecking(){this.interval=setInterval(()=>{this.check()},this.pollFrequency.milliseconds)}}const ag=Object.freeze(Object.defineProperty({__proto__:null,Checker:kt,stateZ:Ka,statusZ:Ga},Symbol.toStringTag,{value:"Module"})),og=s.z.object({keys:j.array().optional(),bounds:M.z,names:pe.array().optional()}),cg=s.z.object({}),lg="/frame/delete";class ug{client;constructor(e){this.client=e}async delete(e){await m(this.client,lg,e,og,cg)}}const Is=r=>{const e=v.toArray(r);return e.length===0?null:typeof e[0]=="number"||!isNaN(parseInt(e[0]))?"key":"name"},ks=(r,e)=>{const t=v.toArray(r);if(t.length===e.length)return;const n=Is(r);throw Is===null?new Z("[Frame] - channel keys or names must be provided when constructing a frame."):new Z(`[Frame] - ${n}s and series must be the same length.
|
|
24
|
+
Got ${t.length} ${n}s and ${e.length} series.`)};class P{columns=[];series=[];constructor(e=[],t=[]){if(e instanceof P){this.columns=e.columns,this.series=e.series;return}if(e instanceof Map){e.forEach((i,a)=>this.push(a,...v.toArray(i)));return}if(typeof e=="object"&&!Array.isArray(e)){if("keys"in e&&"series"in e){const i=e;i.series??=[],i.keys??=[];const a=i.series.map(o=>Ja(o));ks(i.keys,a),i.keys.forEach((o,c)=>this.push(o,a[c]))}else Object.entries(e).forEach(([i,a])=>{const o=parseInt(i);if(!isNaN(o))return this.push(o,...v.toArray(a));this.push(i,...v.toArray(a))});return}if(Array.isArray(e)||["string","number"].includes(typeof e)){const i=v.toArray(t),a=v.toArray(e);ks(a,i),i.forEach((o,c)=>this.push(a[c],o));return}throw new Z(`[Frame] - invalid frame construction parameters. data parameter ust be a frame
|
|
25
25
|
payload, a list of lazy series, a lazy array, a map, or a record keyed by channel
|
|
26
|
-
name. keys parameter must be a set of channel keys or channel names.`)}get colType(){return this.columns.length===0?null:typeof this.columns[0]=="string"?"name":"key"}get keys(){if(this.colType==="name")throw new Xe("colType is not key");return this.columns??[]}get uniqueKeys(){return
|
|
26
|
+
name. keys parameter must be a set of channel keys or channel names.`)}get colType(){return this.columns.length===0?null:typeof this.columns[0]=="string"?"name":"key"}get keys(){if(this.colType==="name")throw new Xe("colType is not key");return this.columns??[]}get uniqueKeys(){return ys.unique(this.keys)}get names(){if(this.colType==="key")throw new Xe("colType is not name");return this.columns??[]}get uniqueNames(){return ys.unique(this.names)}get uniqueColumns(){return this.colType==="key"?this.uniqueKeys:this.uniqueNames}toPayload(){return{series:this.series.map(e=>Xa(e)),keys:[...this.keys]}}get isVertical(){return this.uniqueColumns.length===this.columns.length}get isHorizontal(){return this.uniqueColumns.length===1}get isSquare(){return this.isHorizontal&&this.isVertical}get isWeaklyAligned(){if(this.columns.length<=1)return!0;const e=this.timeRanges;return e.every(t=>t.equals(e[0]))}timeRange(e){if(e==null){if(this.columns.length===0)return M.ZERO;const n=f.min(...this.series.map(a=>a.timeRange.start)),i=f.max(...this.series.map(a=>a.timeRange.end));return new M(n,i)}const t=this.get(e);return t==null?M.ZERO:t.timeRange}latest(){return this.at(-1)}get timeRanges(){return this.uniqueColumns.map(e=>this.timeRange(e))}get(e){return Array.isArray(e)?this.filter(t=>e.includes(t)):new ia(this.series.filter((t,n)=>this.columns[n]===e))}push(e,...t){if(e instanceof P){if(this.colType!==null&&e.colType!==this.colType)throw new Z("keyVariant must match");this.series.push(...e.series),this.columns.push(...e.columns)}else{if(this.series.push(...t),typeof e=="string"&&this.colType==="key")throw new Z("keyVariant must match");if(typeof e!="string"&&this.colType==="name")throw new Z("keyVariant must match");this.columns.push(...Array.from({length:t.length},()=>e))}}concat(e){return new P([...this.columns,...e.columns],[...this.series,...e.series])}has(e){return typeof e=="string"&&this.colType==="key"||typeof e=="number"&&this.colType==="name"?!1:this.columns.includes(e)}map(e){const t=new P;return this.forEach((n,i,a)=>t.push(...e(n,i,a))),t}forEach(e){this.columns.forEach((t,n)=>{const i=this.series[n];e(t,i,n)})}at(e,t=!1){const n={};return this.uniqueColumns.forEach(i=>{n[i]=this.get(i).at(e,t)}),n}filter(e){const t=new P;return this.columns.forEach((n,i)=>{const a=this.series[i];e(n,a,i)&&t.push(n,a)}),t}get byteLength(){return new et(this.series.reduce((e,t)=>e.add(t.byteLength),et.ZERO))}get digest(){const e={};return this.keys.forEach((t,n)=>{const i=this.series[n].digest;t in e?e[t].push(i):e[t]=[i]}),e}get length(){return this.series.reduce((e,t)=>e+t.length,0)}toString(){let e=`Frame{
|
|
27
27
|
`;return this.uniqueColumns.forEach(t=>{e+=` ${t}: ${this.get(t).series.map(n=>n.toString()).join(",")}
|
|
28
|
-
`}),e+="}",e}}const Nr=s.z.object({keys:s.z.union([s.z.null().transform(()=>[]),s.z.number().array().optional().default([])]),series:s.z.union([s.z.null().transform(()=>[]),ge.crudeZ.array().optional().default([])])}),
|
|
28
|
+
`}),e+="}",e}}const Nr=s.z.object({keys:s.z.union([s.z.null().transform(()=>[]),s.z.number().array().optional().default([])]),series:s.z.union([s.z.null().transform(()=>[]),ge.crudeZ.array().optional().default([])])}),Ja=r=>{const{dataType:e,data:t,timeRange:n,alignment:i}=r;return new ge({data:t,dataType:e,timeRange:n,glBufferUsage:"static",alignment:i})},Xa=r=>({timeRange:r.timeRange,dataType:r.dataType,data:new Uint8Array(r.data.buffer),alignment:r.alignment});var tt=(r=>(r[r.Open=0]="Open",r[r.Write=1]="Write",r[r.Commit=2]="Commit",r[r.SetAuthority=3]="SetAuthority",r))(tt||{}),xt=(r=>(r[r.PersistStream=1]="PersistStream",r[r.Persist=2]="Persist",r[r.Stream=3]="Stream",r))(xt||{});const hg=new E(-1);class bn extends he.sub("writer_closed"){constructor(){super("WriterClosed")}}const fg=s.z.enum(xt).or(s.z.enum(["persist","stream","persistStream"]).transform(r=>{switch(r){case"persist":return 2;case"stream":return 3;case"persistStream":return 1}})),Qa=s.z.object({start:f.z.optional(),controlSubject:te.subjectZ.optional(),authorities:s.z.union([te.authorityZ.transform(r=>[r]),te.authorityZ.array()]).default([te.ABSOLUTE_AUTHORITY]),mode:fg.default(1),errOnUnauthorized:s.z.boolean().default(!1),enableAutoCommit:s.z.boolean().default(!1),autoIndexPersistInterval:E.z.default(E.SECOND),useHighPerformanceCodec:s.z.boolean().default(!0)}),dg=Qa.extend({keys:j.array().optional()}),xs=Qa.extend({channels:qe}),eo=xs.or(qe.transform(r=>xs.parse({channels:r,start:f.now()}))),yg=s.z.object({command:s.z.enum(tt),config:dg.optional(),frame:Nr.optional(),buffer:s.z.instanceof(Uint8Array).optional()}),gg=s.z.object({command:s.z.enum(tt),end:f.z,err:me.payloadZ.optional()}),pg=s.z.tuple([s.z.union([s.z.record(j.or(pe),te.authorityZ),j.or(pe),te.authorityZ]),te.authorityZ.optional()]).transform(([r,e])=>{if(te.authorityZ.safeParse(r).success)return{keys:[],authorities:[r]};if(j.or(pe).safeParse(r).success){if(e==null)throw new Error("authority is required when setting authority for a single channel");return{keys:[r],authorities:[e]}}const t=r;return{keys:Object.keys(t),authorities:Object.values(t)}});let to=class Tn{static ENDPOINT="/frame/write";stream;adapter;closeErr=null;constructor(e,t){this.stream=e,this.adapter=t}static async _open(e,t,n){const i=eo.parse(n),a=await Vn.open(e,i.channels);i.useHighPerformanceCodec&&(t=t.withCodec(new Eg(a.codec)));const o=await t.stream(Tn.ENDPOINT,yg,gg),c=new Tn(o,a);return await c.execute({command:0,config:{...i,keys:a.keys}}),c}async write(e,t){if(this.closeErr!=null)throw this.closeErr;if(this.stream.received())return await this.close();const n=await this.adapter.adapt(e,t);this.stream.send({command:1,frame:n.toPayload()})}async setAuthority(e,t){if(this.closeErr!=null)throw this.closeErr;const n=pg.parse([e,t]),i={keys:await this.adapter.adaptParams(n.keys),authorities:n.authorities};await this.execute({command:3,config:i})}async commit(){if(this.closeErr!=null)throw this.closeErr;return this.stream.received()?(await this.closeInternal(null),f.ZERO):(await this.execute({command:2})).end}async close(){await this.closeInternal(null)}async closeInternal(e){if(this.closeErr!=null)throw this.closeErr;for(this.closeErr=e,this.stream.closeSend();;){if(this.closeErr!=null){if(bn.matches(this.closeErr))return null;throw this.closeErr}const[t,n]=await this.stream.receive();n!=null?this.closeErr=ie.matches(n)?new bn:n:this.closeErr=me.decode(t?.err)}}async execute(e){const t=this.stream.send(e);for(t!=null&&await this.closeInternal(t);;){const[n,i]=await this.stream.receive();i!=null&&await this.closeInternal(i);const a=me.decode(n?.err);if(a!=null&&await this.closeInternal(a),n?.command==e.command)return n}}};const Cs=r=>r.data.byteLength/r.dataType.density.valueOf(),mg=r=>{const{keys:e,series:t}=r;e.forEach((n,i)=>{t[i].key=n}),t.sort((n,i)=>n.key-i.key),e.sort((n,i)=>n-i),t.forEach(n=>delete n.key)},Rs=5,js=4,Ms=3,Us=2,Ds=1,Zs=0,ae=$.TIMESTAMP.density.valueOf(),Oe=8,ze=4,qr=4,Fr=4,wg=1;class ro{contentType="application/sy-framer";states=new Map;currState;seqNum=0;constructor(e=[],t=[]){(e.length>0||t.length>0)&&this.update(e,t)}update(e,t){this.seqNum++;const n={keys:e,keyDataTypes:new Map,hasVariableDataTypes:!1};e.forEach((i,a)=>{const o=t[a];n.keyDataTypes.set(i,o),o.isVariable&&(n.hasVariableDataTypes=!0)}),n.keys.sort(),this.states.set(this.seqNum,n),this.currState=n}throwIfNotUpdated(e){if(this.seqNum<1)throw new Z(`
|
|
29
29
|
The codec has not been updated with a list of channels and data types.
|
|
30
30
|
Please call the update method before calling ${e}.
|
|
31
|
-
`)}encode(e,t=0){this.throwIfNotUpdated("encode");let n=e;e!=null&&typeof e=="object"&&"toPayload"in e&&(n=e.toPayload()),
|
|
31
|
+
`)}encode(e,t=0){this.throwIfNotUpdated("encode");let n=e;e!=null&&typeof e=="object"&&"toPayload"in e&&(n=e.toPayload()),mg(n);let i=-1,a,o,c,u=t+wg+Fr,l=!this.currState?.hasVariableDataTypes,h=!0,y=!0,d=!0,N=!0,S=!0;n.keys.length!==this.currState?.keys.length&&(d=!1,u+=n.keys.length*qr),n.series.forEach((D,ve)=>{const ye=Cs(D),ft=n.keys[ve],je=this.currState?.keyDataTypes.get(ft);if(je==null)throw new Z(`Channel ${ft} was not provided in the list of channels when opening the writer`);if(!je.equals(D.dataType))throw new Z(`Series data type of ${D.dataType.toString()} does not match the data type of ${je.toString()} for channel ${ft}`);if(u+=D.data.byteLength,i===-1){i=ye,a=D.timeRange?.start,o=D.timeRange?.end,c=BigInt(D.alignment??0n);return}i!==ye&&(l=!1),(a?.valueOf()!==D.timeRange?.start.valueOf()||o?.valueOf()!==D.timeRange?.end.valueOf())&&(h=!1),c!==BigInt(D.alignment??0)&&(N=!1)}),y=h&&a==null&&o==null,S=N&&(c===void 0||c===0n),l?u+=ze:u+=n.keys.length*ze,y||(h?u+=ae*2:u+=n.keys.length*ae*2),S||(N?u+=Oe:u+=n.keys.length*Oe);const k=new Uint8Array(u),B=new DataView(k.buffer);let x=t;return k[x]=Number(S)<<Rs|Number(N)<<js|Number(l)<<Ms|Number(h)<<Us|Number(y)<<Ds|Number(d)<<Zs,x++,B.setUint32(x,this.seqNum,!0),x+=Fr,l&&(B.setUint32(x,i,!0),x+=ze),h&&!y&&(B.setBigUint64(x,a?.valueOf()??0n,!0),B.setBigUint64(x,o?.valueOf()??0n,!0),x+=ae*2),N&&!S&&(B.setBigUint64(x,c??0n,!0),x+=Oe),n.series.forEach((D,ve)=>{if(d||(B.setUint32(x,n.keys[ve],!0),x+=qr),!l){let ye=D.data.byteLength;D.dataType.isVariable||(ye=Cs(D)),B.setUint32(x,ye,!0),x+=ze}k.set(new Uint8Array(D.data),x),x+=D.data.byteLength,!h&&!y&&(B.setBigUint64(x,D.timeRange?.start.valueOf()??0n,!0),B.setBigUint64(x,D.timeRange?.end.valueOf()??0n,!0),x+=ae*2),!N&&!S&&(B.setBigUint64(x,D.alignment??0n,!0),x+=Oe)}),k}decode(e,t=0){this.throwIfNotUpdated("decode");const n=e instanceof Uint8Array?e:new Uint8Array(e),i={keys:[],series:[]};let a=t,o=0,c=0,u,l,h;const y=new DataView(n.buffer,n.byteOffset,n.byteLength),d=!!(n[a]>>Rs&1),N=!!(n[a]>>js&1),S=!!(n[a]>>Ms&1),k=!!(n[a]>>Us&1),B=!!(n[a]>>Ds&1),x=!!(n[a]>>Zs&1);a++;const D=y.getUint32(a,!0);a+=Fr;const ve=this.states.get(D);if(ve==null)return i;if(S){if(a+ze>y.byteLength)return i;o=y.getUint32(a,!0),a+=ze}if(k&&!B){if(a+ae>y.byteLength)return i;u=new f(y.getBigUint64(a,!0)),a+=ae,l=new f(y.getBigUint64(a,!0)),a+=ae}if(N&&!d){if(a+Oe>y.byteLength)return i;h=y.getBigUint64(a,!0),a+=Oe}return x&&(i.keys=[...ve.keys]),ve.keys.forEach((ye,ft)=>{if(!x){if(a>=y.byteLength||y.getUint32(a,!0)!==ye)return;a+=qr,i.keys.push(ye)}const je=ve.keyDataTypes.get(ye);if(c=0,S)c=o;else{if(a+ze>y.byteLength)return;c=y.getUint32(a,!0),a+=ze}let Ht=c;if(je.isVariable||(Ht*=je.density.valueOf()),a+Ht>y.byteLength){i.keys.splice(ft,1);return}const Me={dataType:je,data:n.slice(a,a+Ht).buffer};if(a+=Ht,!k&&!B){if(a+ae*2>y.byteLength)return;const rs=y.getBigUint64(a,!0);a+=ae;const ac=y.getBigUint64(a,!0);a+=ae,Me.timeRange=new M({start:rs,end:ac})}else B?Me.timeRange=new M({start:0n,end:0n}):Me.timeRange=new M({start:u?.valueOf()??0n,end:l?.valueOf()??0n});if(!N&&!d){if(a+Oe>y.byteLength)return;h=y.getBigUint64(a,!0),a+=Oe,Me.alignment=h}else d?Me.alignment=0n:Me.alignment=h;i.series.push(Me)}),i}}const Yn=254,bg=new Uint8Array([Yn]),Tg=255,vg=new Uint8Array([Tg]),no="application/sy-framer";class Eg{contentType=no;base;lowPerfCodec;constructor(e){this.base=e,this.lowPerfCodec=Be.JSON_CODEC}encode(e){const t=e;if(t.type=="close"||t.payload?.command!=tt.Write){const i=this.lowPerfCodec.encode(t),a=new Uint8Array({length:i.byteLength+1});return a.set(bg,0),a.set(new Uint8Array(i),1),a}const n=this.base.encode(t.payload?.frame,1);return n.set(vg,0),n}decode(e,t){if(new DataView(e instanceof Uint8Array?e.buffer:e).getUint8(0)===Yn)return this.lowPerfCodec.decode(e.slice(1),t);const a={type:"data"},o=this.base.decode(e,1);return a.payload={command:tt.Write,frame:o},a}}class Ng{contentType=no;base;lowPerfCodec;constructor(e){this.base=e,this.lowPerfCodec=Be.JSON_CODEC}encode(e){return this.lowPerfCodec.encode(e)}decode(e,t){return new DataView(e instanceof Uint8Array?e.buffer:e).getUint8(0)===Yn?this.lowPerfCodec.decode(e.slice(1),t):{type:"data",payload:{frame:this.base.decode(e,1)}}}}class Or{adapter;retriever;keys;codec;constructor(e){this.retriever=e,this.adapter=null,this.keys=[],this.codec=new ro}static async open(e,t){const n=new Or(e);return await n.update(t),n}async update(e){const{variant:t,normalized:n}=se(e),i=await this.retriever.retrieve(n),a=i.map(c=>c.key);if(gs.uniqueUnorderedPrimitiveArrays(this.keys,a)===gs.EQUAL)return!1;if(this.codec.update(a,i.map(c=>c.dataType)),t==="keys")return this.adapter=null,this.keys=n,!0;const o=new Map;return this.adapter=o,n.forEach(c=>{const u=i.find(l=>l.name===c);if(u==null)throw new Error(`Channel ${c} not found`);o.set(u.key,u.name)}),this.keys=Array.from(this.adapter.keys()),!0}adapt(e){if(this.adapter==null)return e;const t=this.adapter;return e.map((n,i)=>{if(typeof n=="number"){const a=t.get(n);if(a==null)throw new Error(`Channel ${n} not found`);return[a,i]}return[n,i]})}}class Vn{adapter;retriever;keys;codec;constructor(e){this.retriever=e,this.adapter=null,this.keys=[],this.codec=new ro}static async open(e,t){const n=new Vn(e);return await n.update(t),n}async adaptParams(e){const t=qe.parse(e);return await Promise.all(t.map(async i=>await this.adaptToKey(i)))}async update(e){const t=await qa(this.retriever,e),n=t.map(l=>l.key),i=new Set(this.keys),a=new Set(n),o=!a.isSubsetOf(i),c=!i.isSubsetOf(a);return o||c?(this.adapter=new Map(t.map(l=>[l.name,l.key])),this.keys=n,this.codec.update(this.keys,t.map(l=>l.dataType)),!0):!1}async fetchChannel(e){const t=await this.retriever.retrieve(e);if(t.length===0)throw new Error(`Channel ${JSON.stringify(e)} not found`);return t[0]}async adaptToKey(e){return typeof e=="number"?e:(await this.fetchChannel(e)).key}encode(e){return this.codec.encode(e.toPayload())}async adapt(e,t){if(typeof e=="string"||typeof e=="number"){if(t==null)throw new Z(`
|
|
32
32
|
Received a single channel name or key but no series.
|
|
33
33
|
`);if(Array.isArray(t)){if(t.some(u=>u instanceof ge||Array.isArray(u)))throw new Z(`
|
|
34
34
|
Received a single channel name or key but multiple series.
|
|
@@ -40,5 +40,5 @@
|
|
|
40
40
|
Received an array of channel names or keys but not enough series.
|
|
41
41
|
`);const h=new ge({data:t[u],dataType:l.dataType});o.push(l.key),c.push(h)}return new P(o,c)}if(e instanceof P||e instanceof Map){const o=new P(e);if(this.adapter==null)return o;const c=o.columns.map(u=>{const l=typeof u=="string"?this.adapter?.get(u):u;if(l==null)throw new Z(`
|
|
42
42
|
Channel ${u} was not provided in the list of channels when opening the writer
|
|
43
|
-
`);return l});return new P(c,o.series)}const n=[],i=[],a=Object.entries(e);for(let o=0;o<a.length;o++){const[c,u]=a[o],l=await this.fetchChannel(c),h=new ge({data:u,dataType:l.dataType});n.push(l.key),i.push(h)}return new P(n,i)}}class
|
|
44
|
-
Please report this error to the Synnax team.`),t!=null){if(ie.matches(t))return;throw t}}}closeSend(){this.stream.closeSend()}send(e){const t=this.stream.send(e);if(t!=null)throw t}}const lr=new E(-1);var Vn=(r=>(r[r.Open=0]="Open",r[r.Next=1]="Next",r[r.Prev=2]="Prev",r[r.SeekFirst=3]="SeekFirst",r[r.SeekLast=4]="SeekLast",r[r.SeekLE=5]="SeekLE",r[r.SeekGE=6]="SeekGE",r[r.Valid=7]="Valid",r[r.Error=8]="Error",r))(Vn||{}),so=(r=>(r[r.None=0]="None",r[r.Ack=1]="Ack",r[r.Data=2]="Data",r))(so||{});const Ng=s.z.object({command:s.z.enum(Vn),span:E.z.optional(),bounds:M.z.optional(),stamp:f.z.optional(),keys:j.array().optional(),chunkSize:s.z.number().optional()}),Og=s.z.object({variant:s.z.enum(so),ack:s.z.boolean(),command:s.z.enum(Vn),error:me.payloadZ.optional().nullable(),frame:Nr.optional()});class Ct{static ENDPOINT="/frame/iterate";stream;adapter;value;constructor(e,t){this.stream=new no("Iterator",e),this.value=new P,this.adapter=t}static async _open(e,t,n,i,a={}){const o=await Or.open(n,t),c=await i.stream(Ct.ENDPOINT,Ng,Og),u=new Ct(c,o);return await u.execute({command:0,keys:o.keys,bounds:new M(e),chunkSize:a.chunkSize??1e5}),u}async next(e=lr){return await this.execute({command:1,span:new E(e)})}async prev(e=lr){return await this.execute({command:2,span:new E(e)})}async seekFirst(){return await this.execute({command:3})}async seekLast(){return await this.execute({command:4})}async seekLE(e){return await this.execute({command:5,stamp:new f(e)})}async seekGE(e){return await this.execute({command:6,stamp:new f(e)})}async valid(){return await this.execute({command:7})}async close(){await this.stream.closeAndAck()}[Symbol.asyncIterator](){return new zg(this)}async execute(e){for(this.stream.send(e),this.value=new P;;){const t=await this.stream.receive();if(t.variant===1)return t.ack;this.value.push(this.adapter.adapt(new P(t.frame)))}}}class zg{iter;open=!1;constructor(e){this.iter=e}async next(){try{let e=!0;return this.open||(await this.iter.seekFirst()||(e=!1),this.open=!0),await this.iter.next()||(e=!1),e||await this.iter.close(),{done:!e,value:this.iter.value}}catch(e){throw await this.iter.close(),e}}}const Sg=s.z.object({keys:s.z.number().array(),downsampleFactor:s.z.number()}),Ag=s.z.object({frame:Nr}),$g="/frame/stream",Zs=s.z.object({channels:qe,downsampleFactor:s.z.number().optional().default(1),useHighPerformanceCodec:s.z.boolean().optional().default(!0)}),Hn=Zs.or(qe.transform(r=>Zs.parse({channels:r}))),io=(r,e)=>async t=>{const n=Hn.parse(t),i=await Or.open(r,n.channels);n.useHighPerformanceCodec&&(e=e.withCodec(new Eg(i.codec)));const a=await e.stream($g,Sg,Ag),o=new Ig(a,i);a.send({keys:i.keys,downsampleFactor:n.downsampleFactor??1});const[,c]=await a.receive();if(c!=null)throw c;return o},ao=async(r,e,t)=>await io(r,e)(t);class Ig{stream;adapter;downsampleFactor;constructor(e,t){this.stream=new no("Streamer",e),this.adapter=t,this.downsampleFactor=1}get keys(){return this.adapter.keys}async next(){try{return{done:!1,value:await this.read()}}catch(e){if(ie.matches(e))return{done:!0,value:void 0};throw e}}async read(){return this.adapter.adapt(new P((await this.stream.receive()).frame))}async update(e){await this.adapter.update(e)&&this.stream.send({keys:this.adapter.keys,downsampleFactor:this.downsampleFactor})}close(){this.stream.closeSend()}[Symbol.asyncIterator](){return this}}class zr{wrapped_=null;breaker;opener;config;constructor(e,t,n={}){this.opener=e,this.config=Hn.parse(t);const{maxRetries:i=5e3,baseInterval:a=E.seconds(1),scale:o=1}=n??{};this.breaker=new oa.Breaker({maxRetries:i,baseInterval:a,scale:o})}static async open(e,t,n){const i=new zr(e,t,n);return await i.runStreamer(),i}async runStreamer(){for(;;)try{this.wrapped_!=null&&this.wrapped_.close(),this.wrapped_=await this.opener(this.config),this.breaker.reset();return}catch(e){if(this.wrapped_=null,!await this.breaker.wait())throw e;console.error("failed to open streamer",e);continue}}get wrapped(){if(this.wrapped_==null)throw new Error("stream closed");return this.wrapped_}async update(e){this.config.channels=qe.parse(e);try{await this.wrapped.update(e)}catch{return await this.runStreamer(),await this.update(e)}}async next(){try{return{done:!1,value:await this.read()}}catch(e){if(ie.matches(e))return{done:!0,value:void 0};throw e}}async read(){try{const e=await this.wrapped.read();return this.breaker.reset(),e}catch(e){if(ie.matches(e))throw e;return await this.runStreamer(),await this.read()}}close(){this.wrapped.close()}get keys(){return this.wrapped.keys}[Symbol.asyncIterator](){return this}}class oo extends tf.Observer{streamer;closePromise;constructor(e,t){super(t),this.streamer=e,this.closePromise=this.stream()}async update(e){await this.streamer.update(e)}async close(){this.streamer.close(),await this.closePromise}async stream(){for await(const e of this.streamer)this.notify(e)}}const kg=r=>({type:"framer",key:r.toString()});let co=class{streamClient;retriever;deleter;constructor(e,t,n){this.streamClient=e,this.retriever=n,this.deleter=new lg(t)}async openIterator(e,t,n){return await Ct._open(e,t,this.retriever,this.streamClient,n)}async openWriter(e){return await eo._open(this.retriever,this.streamClient,e)}async openStreamer(e){return await ao(this.retriever,this.streamClient,e)}async write(e,t,n){if(n==null){const a=t,o=await this.openWriter({start:e,channels:Object.keys(a),mode:xt.Persist,errOnUnauthorized:!0,enableAutoCommit:!0,autoIndexPersistInterval:E.MAX});return await o.write(a),await o.close()}const i=await this.openWriter({start:e,channels:t,mode:xt.Persist,errOnUnauthorized:!0,enableAutoCommit:!0,autoIndexPersistInterval:E.MAX});await i.write(t,n),await i.close()}async read(e,t){const{single:n}=se(t),i=await this.readFrame(e,t);return n?i.get(t):i}async readFrame(e,t){const n=await this.openIterator(e,t),i=new P;try{for await(const a of n)i.push(a)}finally{await n.close()}return i}async readLatest(e,t=1){const{single:n}=se(e),i=await this.readLatestNFrame(e,t);return n?i.get(e):i}async readLatestNFrame(e,t){const n=await this.openIterator(M.MAX,e,{chunkSize:t}),i=new P;if(t>0)try{await n.seekLast(),await n.prev(lr),i.push(n.value)}finally{await n.close()}return i}async delete(e,t){const{normalized:n,variant:i}=se(e);return i==="keys"?await this.deleter.delete({keys:n,bounds:t}):await this.deleter.delete({names:n,bounds:t})}};const xg=Object.freeze(Object.defineProperty({__proto__:null,ALWAYS_INDEX_PERSIST_ON_AUTO_COMMIT:ug,AUTO_SPAN:lr,Client:co,Frame:P,HardenedStreamer:zr,Iterator:Ct,ObservableStreamer:oo,Writer:eo,WriterClosedError:wn,WriterCommand:tt,WriterMode:xt,createStreamOpener:io,frameZ:Nr,ontologyID:kg,openStreamer:ao,seriesFromPayload:Ka,seriesToPayload:Ja,streamerConfigZ:Hn,writerConfigZ:Qa},Symbol.toStringTag,{value:"Module"})),Cg=te.ABSOLUTE_AUTHORITY,Rg=te.ZERO_AUTHORITY,jg=te.stateZ(s.z.number()),Mg=r=>r.to==null?`${r.from?.resource} - ${r.from?.subject.name} -> released`:r.from==null?`${r.to.resource} - released -> ${r.to.subject.name} (${r.to.authority.toString()})`:`${r.to.resource} - ${r.from.subject.name} -> ${r.to.subject.name} (${r.to.authority.toString()})`,Ug=s.z.object({transfers:s.z.array(te.transferZ(j))});class lo extends oo{states;codec;constructor(e){super(e,t=>{const n=this.codec.decode(t.series[0].buffer,Ug);return this.merge(n),[n.transfers,!0]}),this.states=new Map,this.codec=new Be.JSONCodec}subjects(){const e=new Map;return this.states.forEach(t=>e.set(t.subject.key,t.subject)),Array.from(e.values())}merge(e){e.transfers.forEach(t=>{t.from==null&&t.to==null&&console.warn("Invalid transfer: ",t),t.to==null?this.states.delete(t.from.resource):this.states.set(t.to.resource,t.to)})}}const uo="sy_node_1_control";let ho=class{framer;constructor(e){this.framer=e}async openStateTracker(){const e=await zr.open(async t=>await this.framer.openStreamer(t),uo);return new lo(e)}};const Dg=Object.freeze(Object.defineProperty({__proto__:null,ABSOLUTE_AUTHORITY:Cg,CONTROL_STATE_CHANNEL_NAME:uo,Client:ho,StateTracker:lo,ZERO_AUTHORITY:Rg,stateZ:jg,transferString:Mg},Symbol.toStringTag,{value:"Module"}));let fo=class{tasks;racks;devices;constructor(e,t,n){this.tasks=e,this.racks=t,this.devices=n}};const Zg=Object.freeze(Object.defineProperty({__proto__:null,Client:fo},Symbol.toStringTag,{value:"Module"})),fe=s.z.uint32(),yo=Pt.statusZ(s.z.object({rack:fe})),Sr=s.z.object({key:fe,name:s.z.string(),status:bt.nullToUndefined(yo)}),go=Sr.partial({key:!0}),po=r=>r?Be.JSON_CODEC.decodeString(r,we.unknownZ):{},ot=s.z.string(),mo=Pt.statusZ(s.z.object({rack:fe,device:ot})),Ar=s.z.object({key:ot,rack:fe,name:s.z.string(),make:s.z.string(),model:s.z.string(),location:s.z.string(),configured:s.z.boolean().optional(),properties:we.unknownZ.or(s.z.string().transform(po)),status:bt.nullToUndefined(mo)}),wo=Ar.extend({properties:s.z.unknown().transform(r=>Be.JSON_CODEC.encodeString(r))}),Pg="sy_device_set",Lg="sy_device_delete",Bg="sy_device_status",qg="/hardware/device/retrieve",Fg="/hardware/device/create",Yg="/hardware/device/delete",Vg=s.z.object({devices:wo.array()}),Hg=s.z.object({devices:Ar.array()}),_g=s.z.object({keys:ot.array()}),Wg=s.z.object({}),Gg=s.z.object({keys:ot.array().optional(),names:s.z.string().array().optional(),makes:s.z.string().array().optional(),models:s.z.string().array().optional(),locations:s.z.string().array().optional(),racks:fe.array().optional(),searchTerm:s.z.string().optional(),limit:s.z.number().optional(),offset:s.z.number().optional(),includeStatus:s.z.boolean().optional()}),Kg=s.z.object({devices:L(Ar)}),Jg=s.z.object({key:ot,includeStatus:s.z.boolean().optional()}).transform(({key:r,includeStatus:e})=>({keys:[r],includeStatus:e})),Xg=s.z.union([Jg,Gg]);let bo=class{type="device";client;constructor(e){this.client=e}async retrieve(e){const t=typeof e=="object"&&"key"in e,n=await m(this.client,qg,e,Xg,Kg);Fe("Device",e,n.devices,t);const i=n.devices;return t?i[0]:i}async create(e){const t=!Array.isArray(e),i=(await m(this.client,Fg,{devices:v.toArray(e)},Vg,Hg)).devices;return t?i[0]:i}async delete(e){await m(this.client,Yg,{keys:v.toArray(e)},_g,Wg)}};const Qg=r=>({type:"device",key:r}),ep=Object.freeze(Object.defineProperty({__proto__:null,Client:bo,DELETE_CHANNEL_NAME:Lg,SET_CHANNEL_NAME:Pg,STATUS_CHANNEL_NAME:Bg,deviceZ:Ar,keyZ:ot,newZ:wo,ontologyID:Qg,statusZ:mo},Symbol.toStringTag,{value:"Module"})),tp="/hardware/rack/retrieve",rp="/hardware/rack/create",np="/hardware/rack/delete",sp="sy_rack_status",ip="sy_rack_set",ap="sy_rack_delete",op=s.z.object({keys:fe.array().optional(),names:s.z.string().array().optional(),searchTerm:s.z.string().optional(),embedded:s.z.boolean().optional(),hostIsNode:s.z.boolean().optional(),limit:s.z.number().optional(),offset:s.z.number().optional(),includeStatus:s.z.boolean().optional()}),cp=s.z.object({racks:L(Sr)}),lp=s.z.union([s.z.object({key:fe,includeStatus:s.z.boolean().optional()}).transform(({key:r,includeStatus:e})=>({keys:[r],includeStatus:e})),s.z.object({name:s.z.string(),includeStatus:s.z.boolean().optional()}).transform(({name:r,includeStatus:e})=>({names:[r],includeStatus:e}))]),up=op,hp=s.z.union([lp,up]),fp=s.z.object({racks:go.array()}),dp=s.z.object({racks:Sr.array()}),yp=s.z.object({keys:fe.array()}),gp=s.z.object({});let To=class{type="rack";client;tasks;constructor(e,t){this.client=e,this.tasks=t}async delete(e){await m(this.client,np,{keys:v.toArray(e)},yp,gp)}async create(e){const t=!Array.isArray(e),n=await m(this.client,rp,{racks:v.toArray(e)},fp,dp),i=this.sugar(n.racks);return t?i[0]:i}async retrieve(e){const t="key"in e||"name"in e,n=await m(this.client,tp,e,hp,cp),i=this.sugar(n.racks);return Fe("Rack",e,i,t),t?i[0]:i}sugar(e){const t=!Array.isArray(e),n=v.toArray(e).map(({key:i,name:a,status:o})=>new vo(i,a,this.tasks,o));return t?n[0]:n}};class vo{key;name;status;tasks;constructor(e,t,n,i){this.key=e,this.name=t,this.tasks=n,this.status=i}async listTasks(){return await this.tasks.retrieve({rack:this.key})}async createTask(e,t){return e.key=((BigInt(this.key)<<32n)+(BigInt(e.key??0)&0xffffffffn)).toString(),await this.tasks.create(e,t)}async deleteTask(e){await this.tasks.delete([e])}get payload(){return{key:this.key,name:this.name,status:this.status}}}const pp=r=>({type:"rack",key:r.toString()}),mp=Object.freeze(Object.defineProperty({__proto__:null,Client:To,DELETE_CHANNEL_NAME:ap,Rack:vo,SET_CHANNEL_NAME:ip,STATUS_CHANNEL_NAME:sp,keyZ:fe,newZ:go,ontologyID:pp,rackZ:Sr,statusZ:yo},Symbol.toStringTag,{value:"Module"})),be=r=>r?JSON.parse(r):{},Te=s.z.union([s.z.string(),s.z.bigint().transform(r=>r.toString()),s.z.number().transform(r=>r.toString())]),Eo=r=>s.z.object({task:Te,running:s.z.boolean(),data:r}),_n=r=>Pt.statusZ(Eo(r)),Ft=(r={typeSchema:s.z.string(),configSchema:s.z.unknown(),statusDataSchema:s.z.unknown()})=>s.z.object({key:Te,name:s.z.string(),type:r.typeSchema,internal:s.z.boolean().optional(),config:s.z.string().transform(po).or(r.configSchema),status:_n(r.statusDataSchema).optional().nullable(),snapshot:s.z.boolean().optional()}),No=r=>Ft(r).omit({key:!0}).extend({key:Te.transform(e=>e.toString()).optional(),config:s.z.unknown().transform(e=>Be.JSON_CODEC.encodeString(e))}),wp=s.z.object({task:Te,type:s.z.string(),key:s.z.string(),args:we.unknownZ.or(s.z.string().transform(be)).or(s.z.array(s.z.unknown())).or(s.z.null()).optional()}),bp=r=>Number(BigInt(r)>>32n),Tn="sy_task_status",vn="sy_task_cmd",Tp="sy_task_set",vp="sy_task_delete",Ue=new Error("Task not created"),Oo=async(r,e)=>{const t=await e.retrieveParents(Wn(r));return t.length===0?null:t[0]};class zo{key;name;internal;type;snapshot;config;status;schemas;frameClient_;ontologyClient_;rangeClient_;get frameClient(){if(this.frameClient_==null)throw Ue;return this.frameClient_}get ontologyClient(){if(this.ontologyClient_==null)throw Ue;return this.ontologyClient_}get rangeClient(){if(this.rangeClient_==null)throw Ue;return this.rangeClient_}constructor({key:e,type:t,name:n,config:i,internal:a=!1,snapshot:o=!1,status:c},u,l,h,y){this.key=e,this.name=n,this.type=t,this.config=i,this.schemas=u??{typeSchema:s.z.string(),configSchema:s.z.unknown(),statusDataSchema:s.z.unknown()},this.internal=a,this.snapshot=o,this.status=c,this.frameClient_=l,this.ontologyClient_=h,this.rangeClient_=y}get payload(){return{key:this.key,name:this.name,type:this.type,config:this.config,status:this.status,internal:this.internal}}get ontologyID(){return Wn(this.key)}async executeCommand(e,t){return await Ao(this.frameClient,this.key,e,t)}async executeCommandSync(e,t,n){return await $o(this.frameClient,this.key,e,t,this.name,this.schemas?.statusDataSchema,n)}async snapshottedTo(){if(this.ontologyClient==null||this.rangeClient==null)throw Ue;return this.snapshot?await Oo(this.key,this.ontologyClient):null}}const Ep=s.z.object({rack:fe.optional(),keys:Te.array().optional(),names:s.z.string().array().optional(),types:s.z.string().array().optional(),includeStatus:s.z.boolean().optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),Np=s.z.union([s.z.object({key:Te,includeStatus:s.z.boolean().optional()}).transform(({key:r,includeStatus:e})=>({keys:[r],includeStatus:e})),s.z.object({name:s.z.string(),includeStatus:s.z.boolean().optional()}).transform(({name:r,includeStatus:e})=>({names:[r],includeStatus:e}))]),Op=Ep,zp=s.z.union([Np,Op]),Sp=r=>s.z.object({tasks:L(Ft(r))}),Ap="/hardware/task/retrieve",$p="/hardware/task/create",Ip="/hardware/task/delete",kp="/hardware/task/copy",xp=r=>s.z.object({tasks:No(r).array()}),Cp=r=>s.z.object({tasks:Ft(r).array()}),Rp=s.z.object({keys:Te.array()}),jp=s.z.object({}),Mp=s.z.object({key:Te,name:s.z.string(),snapshot:s.z.boolean()}),Up=r=>s.z.object({task:Ft(r)});let So=class{type="task";client;frameClient;ontologyClient;rangeClient;constructor(e,t,n,i){this.client=e,this.frameClient=t,this.ontologyClient=n,this.rangeClient=i}async create(e,t){const n=!Array.isArray(e),i=xp(t),a=Cp(t),o=await m(this.client,$p,{tasks:v.toArray(e)},i,a),c=this.sugar(o.tasks,t);return n?c[0]:c}async delete(e){await m(this.client,Ip,{keys:v.toArray(e)},Rp,jp)}async retrieve({schemas:e,...t}){const n="key"in t||"name"in t,a=(await m(this.client,Ap,t,zp,Sp(e))).tasks,o=this.sugar(a,e);return Fe("Task",t,o,n),n?o[0]:o}async copy(e,t,n){const i=Up(),a=await m(this.client,kp,{key:e,name:t,snapshot:n},Mp,i);return this.sugar(a.task)}async retrieveSnapshottedTo(e){if(this.ontologyClient==null)throw Ue;return await Oo(e,this.ontologyClient)}sugar(e,t){const n=!Array.isArray(e),i=v.toArray(e).map(({key:a,name:o,type:c,config:u,status:l,internal:h,snapshot:y})=>new zo({key:a,name:o,type:c,config:u,internal:h,snapshot:y,status:l},t,this.frameClient,this.ontologyClient,this.rangeClient));return n?i[0]:i}async executeCommand(e,t,n){if(Array.isArray(e))return await Gn(this.frameClient,e);if(t==null)throw new Error("Type is required");return await Ao(this.frameClient,e,t,n)}async executeCommandSync(e,t,n,i,a,o=s.z.unknown()){if(Array.isArray(e)){const u=async()=>(await this.retrieve({keys:e.map(h=>h.task)})).map(h=>h.name);return await Io(this.frameClient,e,t,o,u)}const c=async()=>(await this.retrieve({key:e})).name;return await $o(this.frameClient,e,t,n,a??c,o,i)}};const Wn=r=>({type:"task",key:r}),Ao=async(r,e,t,n)=>(await Gn(r,[{args:n,task:e,type:t}]))[0],Gn=async(r,e)=>{if(r==null)throw Ue;const t=await r.openWriter(vn),n=e.map(i=>({...i,key:Ch.create()}));return await t.write(vn,n),await t.close(),n.map(i=>i.key)},$o=async(r,e,t,n,i,a,o)=>(await Io(r,[{args:o,task:e,type:t}],n,a,i))[0],Io=async(r,e,t,n,i)=>{if(r==null)throw Ue;const a=await r.openStreamer(Tn),o=await Gn(r,e),c=new E(t);let u=[],l;const h=new Promise((y,d)=>{l=setTimeout(()=>{(async()=>{const N=e.map(S=>S.task);d(await Dp("command",i,c,N))})()},c.milliseconds)});try{for(;;){const y=await Promise.race([a.read(),h]),d=_n(n).parse(y.at(-1)[Tn]);if(o.includes(d.key)&&(u=[...u.filter(N=>N.key!==d.key),d],u.length===o.length))return u}}finally{clearTimeout(l),a.close()}},Dp=async(r,e,t,n)=>{const i=gu.capitalize(r),a=t.toString();try{let o;typeof e=="string"?o=[e]:Array.isArray(e)?o=e:o=v.toArray(await e());const c=dn.naturalLanguageJoin(o);return new Error(`${i} command to ${c} timed out after ${a}`)}catch(o){return console.error("Failed to retrieve task name for timeout error:",o),new Error(`${i} command to task with key ${dn.naturalLanguageJoin(n)} timed out after ${a}`)}},Zp=Object.freeze(Object.defineProperty({__proto__:null,COMMAND_CHANNEL_NAME:vn,Client:So,DELETE_CHANNEL_NAME:vp,SET_CHANNEL_NAME:Tp,STATUS_CHANNEL_NAME:Tn,Task:zo,commandZ:wp,keyZ:Te,newZ:No,ontologyID:Wn,rackKey:bp,statusDetailsZ:Eo,statusZ:_n,taskZ:Ft},Symbol.toStringTag,{value:"Module"})),Re=s.z.uuid(),Yt=s.z.object({key:Re,name:s.z.string().min(1),color:s.z.string()}),Pp="labeled_by",Lp="sy_label_set",Bp="sy_label_delete",ko=Yt.extend({key:Re.optional()}),qp=s.object({labels:ko.array()}),Fp=s.object({labels:Yt.array()}),Yp=s.object({keys:Re.array()}),xo=s.object({id:C,labels:Re.array(),replace:s.boolean().optional()}),Vp=xo.omit({replace:!0}),Yr=s.object({}),Hp="/label/create",_p="/label/delete",Wp="/label/set",Gp="/label/remove",Kp="/label/retrieve",Jp=s.object({keys:Re.array().optional(),for:C.optional(),searchTerm:s.string().optional(),offset:s.number().optional(),limit:s.number().optional()}),Xp=s.object({key:Re}).transform(({key:r})=>({keys:[r]})),Qp=s.union([Xp,Jp]),em=s.object({labels:L(Yt)});let Co=class{type="label";client;constructor(e){this.client=e}async retrieve(e){const t="key"in e,n=await m(this.client,Kp,e,Qp,em);return Fe("Label",e,n.labels,t),t?n.labels[0]:n.labels}async label(e,t,n={}){await m(this.client,Wp,{id:e,labels:t,replace:n.replace},xo,Yr)}async remove(e,t){await m(this.client,Gp,{id:e,labels:t},Vp,Yr)}async create(e){const t=Array.isArray(e),n=await m(this.client,Hp,{labels:v.toArray(e)},qp,Fp);return t?n.labels:n.labels[0]}async delete(e){await m(this.client,_p,{keys:v.toArray(e)},Yp,Yr)}};const tm=r=>({type:"label",key:r}),rm=Object.freeze(Object.defineProperty({__proto__:null,Client:Co,DELETE_CHANNEL_NAME:Bp,LABELED_BY_ONTOLOGY_RELATIONSHIP_TYPE:Pp,SET_CHANNEL_NAME:Lp,keyZ:Re,labelZ:Yt,newZ:ko,ontologyID:tm},Symbol.toStringTag,{value:"Module"})),H=s.z.uuid(),Kn=s.z.string().min(1),Vt=s.z.object({key:H,name:Kn,timeRange:M.z,color:s.z.string().optional(),labels:Yt.array().or(s.z.null().transform(()=>{})).optional(),get parent(){return Vt.optional().nullable().transform(r=>r===void 0?null:r)}}),Ro=Vt.omit({parent:!0,labels:!0}).partial({key:!0}),nm="sy_range_alias_set",sm="sy_range_alias_delete",im=s.z.object({range:H,aliases:s.z.string().array()}),am=s.z.object({aliases:s.z.record(s.z.string(),j)}),om=s.z.object({range:H,aliases:s.z.record(j,s.z.string())}),cm=s.z.unknown(),lm=s.z.object({range:H,channels:j.array()}),um=s.z.unknown(),hm=s.z.object({range:H}),fm=s.z.object({aliases:s.z.record(s.z.string(),s.z.string())}),dm=s.z.object({range:H,channels:j.array()}),ym=s.z.object({aliases:s.z.record(s.z.string(),s.z.string())});class ee{static SET_ENDPOINT="/range/alias/set";static RESOLVE_ENDPOINT="/range/alias/resolve";static LIST_ENDPOINT="/range/alias/list";static RETRIEVE_ENDPOINT="/range/alias/retrieve";static DELETE_ENDPOINT="/range/alias/delete";frameClient;cache=new Map;client;rangeKey;constructor(e,t,n){this.rangeKey=e,this.cache=new Map,this.client=n,this.frameClient=t}async resolve(e){const t=[],n=typeof e=="string",i={};if(n){const o=this.cache.get(e);if(o!=null)return o;t.push(e)}else e.forEach(o=>{const c=this.cache.get(o);c!=null?i[o]=c:t.push(o)});if(t.length===0)return i;const a=await m(this.client,ee.RESOLVE_ENDPOINT,{range:this.rangeKey,aliases:t},im,am);return Object.entries(a.aliases).forEach(([o,c])=>this.cache.set(o,c)),n?a.aliases[t[0]]:{...i,...a.aliases}}async set(e){await m(this.client,ee.SET_ENDPOINT,{range:this.rangeKey,aliases:e},om,cm)}async list(){return(await m(this.client,ee.LIST_ENDPOINT,{range:this.rangeKey},hm,fm)).aliases}async retrieve(e){const t=typeof e=="number",n=await m(this.client,ee.RETRIEVE_ENDPOINT,{range:this.rangeKey,channels:v.toArray(e)},dm,ym);return t?n.aliases[e]:n.aliases}async delete(e){await m(this.client,ee.DELETE_ENDPOINT,{range:this.rangeKey,channels:e},lm,um)}}const gm=s.z.object({alias:s.z.string().optional(),channel:j,range:H}),jo="---",pm=r=>`${r.range}${jo}${r.channel}`,mm=r=>{const[e,t]=r.split(jo);return{range:e,channel:Number(t)}},wm="sy_range_kv_set",bm="sy_range_kv_delete",Jn=s.z.object({range:H,key:s.z.string(),value:s.z.string()}),Tm=({range:r,key:e})=>`${r}<--->${e}`,vm=s.z.object({range:H,keys:s.z.string().array()}),Em=s.z.object({pairs:L(Jn)}),Nm=s.z.object({range:H,pairs:Jn.array()}),Om=s.z.object({range:H,keys:s.z.string().array()});class Pe{static GET_ENDPOINT="/range/kv/get";static SET_ENDPOINT="/range/kv/set";static DELETE_ENDPOINT="/range/kv/delete";rangeKey;client;constructor(e,t){this.rangeKey=e,this.client=t}async get(e){const t=await m(this.client,Pe.GET_ENDPOINT,{range:this.rangeKey,keys:v.toArray(e)},vm,Em);return typeof e=="string"?t.pairs[0].value:Object.fromEntries(t.pairs.map(n=>[n.key,n.value]))}async list(){return this.get([])}async set(e,t=""){let n;mi(e)?n=Object.entries(e).map(([i,a])=>({range:this.rangeKey,key:i,value:a})):n=[{range:this.rangeKey,key:e,value:t}],await m(this.client,Pe.SET_ENDPOINT,{range:this.rangeKey,pairs:n},Nm,s.z.unknown())}async delete(e){await m(this.client,Pe.DELETE_ENDPOINT,{range:this.rangeKey,keys:v.toArray(e)},Om,s.z.unknown())}}const zm="sy_range_set",Sm="sy_range_delete";class Mo{key;name;kv;timeRange;color;parent;labels;channels;aliaser;frameClient;labelClient;ontologyClient;rangeClient;constructor({name:e,timeRange:t=M.ZERO,key:n,color:i,parent:a,labels:o},{frameClient:c,kv:u,aliaser:l,channels:h,labelClient:y,ontologyClient:d,rangeClient:N}){this.key=n,this.name=e,this.timeRange=t,this.parent=a,this.labels=o,this.frameClient=c,this.color=i,this.kv=u,this.aliaser=l,this.channels=h,this.labelClient=y,this.ontologyClient=d,this.rangeClient=N}get ontologyID(){return Ge(this.key)}get payload(){let e=null;return this.parent!=null&&("payload"in this.parent?e=this.parent.payload:e=this.parent),{key:this.key,name:this.name,timeRange:this.timeRange,color:this.color,labels:this.labels,parent:e}}async setAlias(e,t){const n=await this.channels.retrieve(e);if(n.length===0)throw new xe(`Channel ${e} does not exist`);await this.aliaser.set({[n[0].key]:t})}async deleteAlias(...e){await this.aliaser.delete(e)}async listAliases(){return await this.aliaser.list()}async resolveAlias(e){return await this.aliaser.resolve(e)}async retrieveParent(){return this.rangeClient.retrieveParent(this.key)}async retrieveChildren(){const e=(await this.ontologyClient.retrieveChildren(this.ontologyID,{excludeFieldData:!0,types:["range"]})).map(t=>t.id.key);return await this.rangeClient.retrieve(e)}async read(e){return await this.frameClient.read(this.timeRange,e)}async retrieveLabels(){return await this.labelClient.retrieve({for:Ge(this.key)})}async addLabel(...e){await this.labelClient.label(Ge(this.key),e)}async removeLabel(...e){await this.labelClient.remove(Ge(this.key),e)}static sort(e,t){return M.sort(e.timeRange,t.timeRange)}}const Am=s.z.object({keys:H.array().optional(),names:s.z.array(s.z.string()).optional(),searchTerm:s.z.string().optional(),overlapsWith:M.z.optional(),limit:s.z.number().int().optional(),offset:s.z.number().int().optional(),hasLabels:Re.array().optional(),includeLabels:s.z.boolean().optional(),includeParent:s.z.boolean().optional()}),$m=Am.or(H.array().transform(r=>({keys:r}))).or(H.transform(r=>({keys:[r]}))).or(s.z.string().transform(r=>({names:[r]}))).or(s.z.string().array().transform(r=>({names:r}))).or(M.z.transform(r=>({overlapsWith:r}))),Im="/range/retrieve",km=s.z.object({ranges:L(Vt)});let Uo=class{type="range";frameClient;writer;unaryClient;channels;labelClient;ontologyClient;constructor(e,t,n,i,a,o){this.frameClient=e,this.writer=t,this.unaryClient=n,this.channels=i,this.labelClient=a,this.ontologyClient=o}async create(e,t){const n=!Array.isArray(e),i=this.sugarMany(await this.writer.create(v.toArray(e),t));return n?i[0]:i}async rename(e,t){await this.writer.rename(e,t)}async delete(e){await this.writer.delete(v.toArray(e))}async retrieve(e){const t=typeof e=="string",{ranges:n}=await m(this.unaryClient,Im,e,$m,km);return Fe("Range",e,n,t),t?this.sugarMany(n)[0]:this.sugarMany(n)}getKV(e){return new Pe(e,this.unaryClient)}async retrieveParent(e){const t=await this.ontologyClient.retrieveParents(Ge(e));if(t.length===0)return null;const n=t[0];return n.id.type!=="range"?null:await this.retrieve(n.id.key)}sugarOntologyResource(e){return this.sugarOne(Do(e))}async retrieveAlias(e,t){return await new ee(e,this.frameClient,this.unaryClient).retrieve(t)}async retrieveAliases(e,t){return await new ee(e,this.frameClient,this.unaryClient).retrieve(t)}async listAliases(e){return await new ee(e,this.frameClient,this.unaryClient).list()}async setAlias(e,t,n){await new ee(e,this.frameClient,this.unaryClient).set({[t]:n})}sugarOne(e){return new Mo(e,{frameClient:this.frameClient,kv:new Pe(e.key,this.unaryClient),aliaser:new ee(e.key,this.frameClient,this.unaryClient),channels:this.channels,labelClient:this.labelClient,ontologyClient:this.ontologyClient,rangeClient:this})}sugarMany(e){return e.map(t=>this.sugarOne(t))}resourceToRange(e){return this.sugarOne({key:e.id.key,name:e.data?.name,timeRange:new M(e.data?.timeRange),color:e.data?.color,labels:[],parent:null})}};const Ge=r=>({type:"range",key:r}),xm=r=>({type:"range-alias",key:r}),Do=({data:r,id:{key:e},name:t})=>{const n=M.z.parse(r?.timeRange);return{key:e,name:t,timeRange:n,color:typeof r?.color=="string"?r.color:void 0,labels:[],parent:null}},Cm=s.z.object({ranges:Vt.array()}),Rm=s.z.object({parent:C.optional(),ranges:Ro.array()}),jm=s.z.object({keys:H.array()}),Mm=s.z.object({}),Um=s.z.object({key:H,name:Kn}),Dm=s.z.object({}),Zm="/range/create",Pm="/range/delete",Lm="/range/rename";class Zo{client;constructor(e){this.client=e}async rename(e,t){await m(this.client,Lm,{key:e,name:t},Um,Dm)}async create(e,t){return(await m(this.client,Zm,{ranges:e,...t},Rm,Cm)).ranges}async delete(e){await m(this.client,Pm,{keys:e},jm,Mm)}}const Bm=Object.freeze(Object.defineProperty({__proto__:null,Aliaser:ee,Client:Uo,DELETE_ALIAS_CHANNEL_NAME:sm,DELETE_CHANNEL_NAME:Sm,KV:Pe,KV_DELETE_CHANNEL:bm,KV_SET_CHANNEL:wm,Range:Mo,SET_ALIAS_CHANNEL_NAME:nm,SET_CHANNEL_NAME:zm,Writer:Zo,aliasKey:pm,aliasOntologyID:xm,aliasZ:gm,convertOntologyResourceToPayload:Do,decodeDeleteAliasChange:mm,keyZ:H,kvPairKey:Tm,kvPairZ:Jn,nameZ:Kn,newZ:Ro,ontologyID:Ge,payloadZ:Vt},Symbol.toStringTag,{value:"Module"})),qm="/api/v1/";class Fm{url;unary;stream;secure;constructor(e,t={},n=!1){this.secure=n,this.url=e.child(qm);const i=new Be.JSONCodec;this.unary=tu(new eu(this.url,i,this.secure),t),this.stream=new ar(this.url,i,this.secure)}use(...e){this.unary.use(...e),this.stream.use(...e)}}const ct=s.z.uuid(),$r=s.z.object({key:ct,name:s.z.string(),data:we.unknownZ.or(s.z.string().transform(be))}),Po=$r.partial({key:!0}).transform(r=>({...r,data:JSON.stringify(r.data)})),de=s.z.uuid(),Ir=s.z.object({key:de,name:s.z.string(),layout:we.unknownZ.or(s.z.string().transform(be))}),Lo=Ir.partial({key:!0}).transform(r=>({...r,layout:JSON.stringify(r.layout)})),Bo=Ir.omit({layout:!0}).extend({layout:s.z.string().transform(be)}),Ym="/workspace/lineplot/retrieve",Vm="/workspace/lineplot/create",Hm="/workspace/lineplot/rename",_m="/workspace/lineplot/set-data",Wm="/workspace/lineplot/delete",Gm=s.z.object({keys:ct.array()}),Km=s.z.object({workspace:de,linePlots:Po.array()}),Jm=s.z.object({key:ct,name:s.z.string()}),Xm=s.z.object({key:ct,data:s.z.string()}),Qm=s.z.object({keys:ct.array()}),ew=s.z.object({linePlots:L($r)}),tw=s.z.object({linePlots:$r.array()}),Vr=s.z.object({});let qo=class{client;constructor(e){this.client=e}async create(e,t){const n=Array.isArray(t),i=await m(this.client,Vm,{workspace:e,linePlots:v.toArray(t)},Km,tw);return n?i.linePlots:i.linePlots[0]}async rename(e,t){await m(this.client,Hm,{key:e,name:t},Jm,Vr)}async setData(e,t){await m(this.client,_m,{key:e,data:JSON.stringify(t)},Xm,Vr)}async retrieve(e){const t=Array.isArray(e),n=await m(this.client,Ym,{keys:v.toArray(e)},Gm,ew);return t?n.linePlots:n.linePlots[0]}async delete(e){await m(this.client,Wm,{keys:v.toArray(e)},Qm,Vr)}};const rw=r=>({type:"lineplot",key:r}),nw=Object.freeze(Object.defineProperty({__proto__:null,Client:qo,keyZ:ct,linePlotZ:$r,newZ:Po,ontologyID:rw},Symbol.toStringTag,{value:"Module"})),lt=s.z.uuid(),kr=s.z.object({key:lt,name:s.z.string(),data:we.unknownZ.or(s.z.string().transform(be))}),Fo=kr.partial({key:!0}).transform(r=>({...r,data:JSON.stringify(r.data)})),sw="/workspace/log/retrieve",iw="/workspace/log/create",aw="/workspace/log/rename",ow="/workspace/log/set-data",cw="/workspace/log/delete",lw=s.z.object({keys:lt.array()}),uw=s.z.object({workspace:de,logs:Fo.array()}),hw=s.z.object({key:lt,name:s.z.string()}),fw=s.z.object({key:lt,data:s.z.string()}),dw=s.z.object({keys:lt.array()}),yw=s.z.object({logs:kr.array()}),gw=s.z.object({logs:kr.array()}),Hr=s.z.object({});let Yo=class{client;constructor(e){this.client=e}async create(e,t){const n=Array.isArray(t),i=await m(this.client,iw,{workspace:e,logs:v.toArray(t)},uw,gw);return n?i.logs:i.logs[0]}async rename(e,t){await m(this.client,aw,{key:e,name:t},hw,Hr)}async setData(e,t){await m(this.client,ow,{key:e,data:JSON.stringify(t)},fw,Hr)}async retrieve(e){const t=Array.isArray(e),n=await m(this.client,sw,{keys:v.toArray(e)},lw,yw);return t?n.logs:n.logs[0]}async delete(e){await m(this.client,cw,{keys:v.toArray(e)},dw,Hr)}};const pw=r=>({type:"log",key:r}),mw=Object.freeze(Object.defineProperty({__proto__:null,Client:Yo,keyZ:lt,logZ:kr,newZ:Fo,ontologyID:pw},Symbol.toStringTag,{value:"Module"})),Ye=s.z.uuid(),xr=s.z.object({key:Ye,name:s.z.string(),data:we.unknownZ.or(s.z.string().transform(be)),snapshot:s.z.boolean()}),Vo=xr.partial({key:!0,snapshot:!0}).transform(r=>({...r,data:JSON.stringify(r.data)})),Xn=xr.extend({data:s.z.string().transform(be)}),ut=s.z.uuid(),Ho=s.z.object({key:s.z.string(),name:s.z.string(),selectors:s.z.string().array().default([]),strokeColor:s.z.string().optional(),fillColor:s.z.string().optional()}),_o=s.z.object({key:s.z.string(),name:s.z.string(),regions:Ho.array()}),Wo=s.z.object({key:s.z.string(),position:_i.xy,orientation:sh.outer}),ww=s.z.object({zoom:s.z.number().positive().default(1),position:_i.xy}),Go=s.z.object({svg:s.z.string().min(1,"SVG is required"),states:_o.array(),variant:s.z.string().min(1,"Variant is required"),handles:Wo.array(),scale:s.z.number().positive().default(1),scaleStroke:s.z.boolean().default(!1),previewViewport:ww.default({zoom:1,position:{x:0,y:0}})}),Cr=s.z.object({key:ut,version:s.z.literal(1).optional().default(1),name:s.z.string().min(1,"Name is required"),data:Go}),Ko=Cr.partial({key:!0}),bw="/workspace/schematic/symbol/retrieve",Tw="/workspace/schematic/symbol/create",vw="/workspace/schematic/symbol/rename",Ew="/workspace/schematic/symbol/delete",Nw="/workspace/schematic/symbol/retrieve_group",Ow=s.z.object({symbols:Ko.array(),parent:C}),zw=s.z.object({key:ut,name:s.z.string()}),Sw=s.z.object({keys:ut.array()}),Aw=s.z.object({keys:ut.array().optional(),searchTerm:s.z.string().optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),$w=s.z.object({key:ut}).transform(({key:r})=>({keys:[r]})),Iw=s.z.union([$w,Aw]),kw=s.z.object({symbols:L(Cr)}),xw=s.z.object({symbols:Cr.array()}),Ps=s.z.object({}),Cw=s.z.object({}),Rw=s.z.object({group:Tr}),jw="sy_schematic_symbol_set",Mw="sy_schematic_symbol_delete";let Jo=class{client;constructor(e){this.client=e}async create(e){const t="symbols"in e,n=t?e.symbols:[e],i=await m(this.client,Tw,{symbols:n,parent:e.parent},Ow,xw);return t?i.symbols:i.symbols[0]}async rename(e,t){await m(this.client,vw,{key:e,name:t},zw,Ps)}async retrieve(e){const t="key"in e,n=await m(this.client,bw,e,Iw,kw);return Fe("Schematic Symbol",e,n.symbols,t),t?n.symbols[0]:n.symbols}async delete(e){await m(this.client,Ew,{keys:v.toArray(e)},Sw,Ps)}async retrieveGroup(){return(await m(this.client,Nw,{},Cw,Rw)).group}};const Uw=r=>({type:"schematic_symbol",key:r}),Dw=Object.freeze(Object.defineProperty({__proto__:null,Client:Jo,DELETE_CHANNEL_NAME:Mw,SET_CHANNEL_NAME:jw,handleZ:Wo,keyZ:ut,newZ:Ko,ontologyID:Uw,regionZ:Ho,specZ:Go,stateZ:_o,symbolZ:Cr},Symbol.toStringTag,{value:"Module"})),Zw="/workspace/schematic/retrieve",Pw="/workspace/schematic/create",Lw="/workspace/schematic/rename",Bw="/workspace/schematic/set-data",qw="/workspace/schematic/delete",Fw="/workspace/schematic/copy",Yw=s.z.object({keys:Ye.array()}),Vw=s.z.object({workspace:de,schematics:Vo.array()}),Hw=s.z.object({key:Ye,name:s.z.string()}),_w=s.z.object({key:Ye,data:s.z.string()}),Ww=s.z.object({keys:Ye.array()}),Gw=s.z.object({key:Ye,name:s.z.string(),snapshot:s.z.boolean()}),Kw=s.z.object({schematics:L(Xn)}),Jw=s.z.object({schematics:Xn.array()}),Xw=s.z.object({schematic:xr}),_r=s.z.object({});let Xo=class{symbols;client;constructor(e){this.client=e,this.symbols=new Jo(e)}async create(e,t){const n=Array.isArray(t),i=await m(this.client,Pw,{workspace:e,schematics:v.toArray(t)},Vw,Jw);return n?i.schematics:i.schematics[0]}async rename(e,t){await m(this.client,Lw,{key:e,name:t},Hw,_r)}async setData(e,t){await m(this.client,Bw,{key:e,data:JSON.stringify(t)},_w,_r)}async retrieve(e){const t=Array.isArray(e),n=await m(this.client,Zw,{keys:v.toArray(e)},Yw,Kw);return t?n.schematics:n.schematics[0]}async delete(e){await m(this.client,qw,{keys:v.toArray(e)},Ww,_r)}async copy(e,t,n){return(await m(this.client,Fw,{key:e,name:t,snapshot:n},Gw,Xw)).schematic}};const Qw=r=>({type:"schematic",key:r}),eb=Object.freeze(Object.defineProperty({__proto__:null,Client:Xo,keyZ:Ye,newZ:Vo,ontologyID:Qw,remoteZ:Xn,schematicZ:xr,symbol:Dw},Symbol.toStringTag,{value:"Module"})),ht=s.z.uuid(),Qn=s.z.object({key:ht,name:s.z.string(),data:we.unknownZ.or(s.z.string().transform(be))}),Qo=Qn.partial({key:!0}).transform(r=>({...r,data:JSON.stringify(r.data)})),es=Qn.extend({data:s.z.string().transform(be)}),tb="/workspace/table/retrieve",rb="/workspace/table/create",nb="/workspace/table/rename",sb="/workspace/table/set-data",ib="/workspace/table/delete",ab=s.z.object({keys:ht.array()}),ob=s.z.object({workspace:de,tables:Qo.array()}),cb=s.z.object({key:ht,name:s.z.string()}),lb=s.z.object({key:ht,data:s.z.string()}),ub=s.z.object({keys:ht.array()}),hb=s.z.object({tables:es.array()}),fb=s.z.object({tables:es.array()}),Wr=s.z.object({});let ec=class{client;constructor(e){this.client=e}async create(e,t){const n=Array.isArray(t),i=await m(this.client,rb,{workspace:e,tables:v.toArray(t)},ob,fb);return n?i.tables:i.tables[0]}async rename(e,t){await m(this.client,nb,{key:e,name:t},cb,Wr)}async setData(e,t){await m(this.client,sb,{key:e,data:JSON.stringify(t)},lb,Wr)}async retrieve(e){const t=Array.isArray(e),n=await m(this.client,tb,{keys:v.toArray(e)},ab,hb);return t?n.tables:n.tables[0]}async delete(e){await m(this.client,ib,{keys:v.toArray(e)},ub,Wr)}};const db=r=>({type:"table",key:r}),yb=Object.freeze(Object.defineProperty({__proto__:null,Client:ec,keyZ:ht,newZ:Qo,ontologyID:db,remoteZ:es,tableZ:Qn},Symbol.toStringTag,{value:"Module"})),Ls="/workspace/retrieve",gb="/workspace/create",pb="/workspace/rename",mb="/workspace/set-layout",wb="/workspace/delete",Bs=s.z.object({keys:de.array().optional(),searchTerm:s.z.string().optional(),author:Ce.optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),bb=s.z.object({workspaces:Lo.array()}),Tb=s.z.object({key:de,name:s.z.string()}),vb=s.z.object({key:de,layout:s.z.string()}),Eb=s.z.object({keys:de.array()}),qs=s.z.object({workspaces:L(Ir)}),Nb=s.z.object({workspaces:Bo.array()}),Gr=s.z.object({}),Ob="sy_workspace_set",zb="sy_workspace_delete";class tc{type="workspace";schematic;linePlot;log;table;client;constructor(e){this.client=e,this.schematic=new Xo(e),this.linePlot=new qo(e),this.log=new Yo(e),this.table=new ec(e)}async create(e){const t=Array.isArray(e),n=await m(this.client,gb,{workspaces:v.toArray(e)},bb,Nb);return t?n.workspaces:n.workspaces[0]}async rename(e,t){await m(this.client,pb,{key:e,name:t},Tb,Gr)}async setLayout(e,t){await m(this.client,mb,{key:e,layout:JSON.stringify(t)},vb,Gr)}async retrieve(e){let t;const n=typeof e!="string";typeof e=="string"||Array.isArray(e)?t={keys:v.toArray(e)}:t=e;const i=await m(this.client,Ls,t,Bs,qs);return n?i.workspaces:i.workspaces[0]}async retrieveByAuthor(e){return(await m(this.client,Ls,{author:e},Bs,qs)).workspaces}async delete(e){await m(this.client,wb,{keys:v.toArray(e)},Eb,Gr)}}const Sb=r=>({type:"workspace",key:r}),Ab=Object.freeze(Object.defineProperty({__proto__:null,Client:tc,DELETE_CHANNEL_NAME:zb,SET_CHANNEL_NAME:Ob,keyZ:de,newZ:Lo,ontologyID:Sb,remoteZ:Bo,workspaceZ:Ir},Symbol.toStringTag,{value:"Module"})),rc=s.z.object({host:s.z.string({error:"Host is required"}).min(1,"Host is required"),port:s.z.number({error:"Port is required"}).or(s.z.string({error:"Port is required"})),username:s.z.string().min(1,"Username is required"),password:s.z.string().min(1,"Password is required"),connectivityPollFrequency:E.z.default(E.seconds(30)),secure:s.z.boolean().optional().default(!1),name:s.z.string().optional(),retry:oa.breakerConfigZ.optional()});class nc extends co{createdAt;props;ranges;channels;auth;user;access;connectivity;ontology;workspaces;labels;hardware;control;static connectivity=kt;transport;clientVersion="0.45.0";constructor(e){const t=rc.parse(e),{host:n,port:i,username:a,password:o,connectivityPollFrequency:c,secure:u,retry:l}=t,h=new Fm(new wt({host:n,port:Number(i)}),l,u);h.use(ud);let y;a!=null&&o!=null&&(y=new ng(h.unary,{username:a,password:o}),h.use(y.middleware()));const d=new qn(new Bt(h.unary)),N=new Va(h.unary,d);super(h.stream,h.unary,d),this.createdAt=f.now(),this.props=t,this.auth=y,this.transport=h,this.channels=new qa(this,d,h.unary,N),this.connectivity=new kt(h.unary,c,this.clientVersion,t.name),this.control=new ho(this),this.ontology=new Ra(h.unary,this);const S=new Zo(this.transport.unary);this.labels=new Co(this.transport.unary),this.ranges=new Uo(this,S,this.transport.unary,d,this.labels,this.ontology),this.access=new Ua(this.transport.unary),this.user=new _a(this.transport.unary),this.workspaces=new tc(this.transport.unary);const k=new bo(this.transport.unary),B=new So(this.transport.unary,this,this.ontology,this.ranges),x=new To(this.transport.unary,B);this.hardware=new fo(B,x,k)}get key(){return this.createdAt.valueOf().toString()}close(){this.connectivity.stopChecking()}}const sc={host:"localhost",port:9090,username:"synnax",password:"seldon",retry:{maxRetries:4,baseInterval:E.seconds(1),scale:1.5}},$b=r=>new nc({...sc,...r});exports.AuthError=zt;exports.Channel=cr;exports.ContiguityError=od;exports.DataType=$;exports.Density=Y;exports.DisconnectedError=ad;exports.Frame=P;exports.MultiSeries=sa;exports.MultipleFoundError=At;exports.NotFoundError=St;exports.QueryError=xe;exports.Rate=W;exports.RouteError=pn;exports.Series=ge;exports.Synnax=nc;exports.TEST_CLIENT_PROPS=sc;exports.TimeRange=M;exports.TimeSpan=E;exports.TimeStamp=f;exports.UnexpectedError=Xe;exports.ValidationError=Z;exports.access=ny;exports.channel=$y;exports.connection=ig;exports.control=Dg;exports.createTestClient=$b;exports.device=ep;exports.framer=xg;exports.group=$d;exports.hardware=Zg;exports.isCalculated=It;exports.label=rm;exports.linePlot=nw;exports.log=mw;exports.ontology=Bd;exports.policy=ry;exports.rack=mp;exports.ranger=Bm;exports.schematic=eb;exports.synnaxPropsZ=rc;exports.table=yb;exports.task=Zp;exports.user=Gy;exports.workspace=Ab;
|
|
43
|
+
`);return l});return new P(c,o.series)}const n=[],i=[],a=Object.entries(e);for(let o=0;o<a.length;o++){const[c,u]=a[o],l=await this.fetchChannel(c),h=new ge({data:u,dataType:l.dataType});n.push(l.key),i.push(h)}return new P(n,i)}}class so{name;stream;constructor(e,t){this.stream=t,this.name=e}async receive(){const[e,t]=await this.stream.receive();if(t!=null)throw t;return e}received(){return this.stream.received()}async closeAndAck(){for(this.stream.closeSend();;){const[e,t]=await this.stream.receive();if(e!=null&&console.warn(`${this.name} received unexpected response on ${JSON.stringify(e)} closure.
|
|
44
|
+
Please report this error to the Synnax team.`),t!=null){if(ie.matches(t))return;throw t}}}closeSend(){this.stream.closeSend()}send(e){const t=this.stream.send(e);if(t!=null)throw t}}const lr=new E(-1);var Hn=(r=>(r[r.Open=0]="Open",r[r.Next=1]="Next",r[r.Prev=2]="Prev",r[r.SeekFirst=3]="SeekFirst",r[r.SeekLast=4]="SeekLast",r[r.SeekLE=5]="SeekLE",r[r.SeekGE=6]="SeekGE",r[r.Valid=7]="Valid",r[r.Error=8]="Error",r))(Hn||{}),io=(r=>(r[r.None=0]="None",r[r.Ack=1]="Ack",r[r.Data=2]="Data",r))(io||{});const Og=s.z.object({command:s.z.enum(Hn),span:E.z.optional(),bounds:M.z.optional(),stamp:f.z.optional(),keys:j.array().optional(),chunkSize:s.z.number().optional()}),zg=s.z.object({variant:s.z.enum(io),ack:s.z.boolean(),command:s.z.enum(Hn),error:me.payloadZ.optional().nullable(),frame:Nr.optional()});class Ct{static ENDPOINT="/frame/iterate";stream;adapter;value;constructor(e,t){this.stream=new so("Iterator",e),this.value=new P,this.adapter=t}static async _open(e,t,n,i,a={}){const o=await Or.open(n,t),c=await i.stream(Ct.ENDPOINT,Og,zg),u=new Ct(c,o);return await u.execute({command:0,keys:o.keys,bounds:new M(e),chunkSize:a.chunkSize??1e5}),u}async next(e=lr){return await this.execute({command:1,span:new E(e)})}async prev(e=lr){return await this.execute({command:2,span:new E(e)})}async seekFirst(){return await this.execute({command:3})}async seekLast(){return await this.execute({command:4})}async seekLE(e){return await this.execute({command:5,stamp:new f(e)})}async seekGE(e){return await this.execute({command:6,stamp:new f(e)})}async valid(){return await this.execute({command:7})}async close(){await this.stream.closeAndAck()}[Symbol.asyncIterator](){return new Sg(this)}async execute(e){for(this.stream.send(e),this.value=new P;;){const t=await this.stream.receive();if(t.variant===1)return t.ack;this.value.push(this.adapter.adapt(new P(t.frame)))}}}class Sg{iter;open=!1;constructor(e){this.iter=e}async next(){try{let e=!0;return this.open||(await this.iter.seekFirst()||(e=!1),this.open=!0),await this.iter.next()||(e=!1),e||await this.iter.close(),{done:!e,value:this.iter.value}}catch(e){throw await this.iter.close(),e}}}const Ag=s.z.object({keys:s.z.number().array(),downsampleFactor:s.z.number()}),$g=s.z.object({frame:Nr}),Ig="/frame/stream",Ps=s.z.object({channels:qe,downsampleFactor:s.z.number().optional().default(1),useHighPerformanceCodec:s.z.boolean().optional().default(!0)}),_n=Ps.or(qe.transform(r=>Ps.parse({channels:r}))),ao=(r,e)=>async t=>{const n=_n.parse(t),i=await Or.open(r,n.channels);n.useHighPerformanceCodec&&(e=e.withCodec(new Ng(i.codec)));const a=await e.stream(Ig,Ag,$g),o=new kg(a,i);a.send({keys:i.keys,downsampleFactor:n.downsampleFactor??1});const[,c]=await a.receive();if(c!=null)throw c;return o},oo=async(r,e,t)=>await ao(r,e)(t);class kg{stream;adapter;downsampleFactor;constructor(e,t){this.stream=new so("Streamer",e),this.adapter=t,this.downsampleFactor=1}get keys(){return this.adapter.keys}async next(){try{return{done:!1,value:await this.read()}}catch(e){if(ie.matches(e))return{done:!0,value:void 0};throw e}}async read(){return this.adapter.adapt(new P((await this.stream.receive()).frame))}async update(e){await this.adapter.update(e)&&this.stream.send({keys:this.adapter.keys,downsampleFactor:this.downsampleFactor})}close(){this.stream.closeSend()}[Symbol.asyncIterator](){return this}}class zr{wrapped_=null;breaker;opener;config;constructor(e,t,n={}){this.opener=e,this.config=_n.parse(t);const{maxRetries:i=5e3,baseInterval:a=E.seconds(1),scale:o=1}=n??{};this.breaker=new ca.Breaker({maxRetries:i,baseInterval:a,scale:o})}static async open(e,t,n){const i=new zr(e,t,n);return await i.runStreamer(),i}async runStreamer(){for(;;)try{this.wrapped_!=null&&this.wrapped_.close(),this.wrapped_=await this.opener(this.config),this.breaker.reset();return}catch(e){if(this.wrapped_=null,!await this.breaker.wait())throw e;console.error("failed to open streamer",e);continue}}get wrapped(){if(this.wrapped_==null)throw new Error("stream closed");return this.wrapped_}async update(e){this.config.channels=qe.parse(e);try{await this.wrapped.update(e)}catch{return await this.runStreamer(),await this.update(e)}}async next(){try{return{done:!1,value:await this.read()}}catch(e){if(ie.matches(e))return{done:!0,value:void 0};throw e}}async read(){try{const e=await this.wrapped.read();return this.breaker.reset(),e}catch(e){if(ie.matches(e))throw e;return await this.runStreamer(),await this.read()}}close(){this.wrapped.close()}get keys(){return this.wrapped.keys}[Symbol.asyncIterator](){return this}}class co extends rf.Observer{streamer;closePromise;constructor(e,t){super(t),this.streamer=e,this.closePromise=this.stream()}async update(e){await this.streamer.update(e)}async close(){this.streamer.close(),await this.closePromise}async stream(){for await(const e of this.streamer)this.notify(e)}}const xg=r=>({type:"framer",key:r.toString()});let lo=class{streamClient;retriever;deleter;constructor(e,t,n){this.streamClient=e,this.retriever=n,this.deleter=new ug(t)}async openIterator(e,t,n){return await Ct._open(e,t,this.retriever,this.streamClient,n)}async openWriter(e){return await to._open(this.retriever,this.streamClient,e)}async openStreamer(e){return await oo(this.retriever,this.streamClient,e)}async write(e,t,n){if(n==null){const a=t,o=await this.openWriter({start:e,channels:Object.keys(a),mode:xt.Persist,errOnUnauthorized:!0,enableAutoCommit:!0,autoIndexPersistInterval:E.MAX});return await o.write(a),await o.close()}const i=await this.openWriter({start:e,channels:t,mode:xt.Persist,errOnUnauthorized:!0,enableAutoCommit:!0,autoIndexPersistInterval:E.MAX});await i.write(t,n),await i.close()}async read(e,t){const{single:n}=se(t),i=await this.readFrame(e,t);return n?i.get(t):i}async readFrame(e,t){const n=await this.openIterator(e,t),i=new P;try{for await(const a of n)i.push(a)}finally{await n.close()}return i}async readLatest(e,t=1){const{single:n}=se(e),i=await this.readLatestNFrame(e,t);return n?i.get(e):i}async readLatestNFrame(e,t){const n=await this.openIterator(M.MAX,e,{chunkSize:t}),i=new P;if(t>0)try{await n.seekLast(),await n.prev(lr),i.push(n.value)}finally{await n.close()}return i}async delete(e,t){const{normalized:n,variant:i}=se(e);return i==="keys"?await this.deleter.delete({keys:n,bounds:t}):await this.deleter.delete({names:n,bounds:t})}};const Cg=Object.freeze(Object.defineProperty({__proto__:null,ALWAYS_INDEX_PERSIST_ON_AUTO_COMMIT:hg,AUTO_SPAN:lr,Client:lo,Frame:P,HardenedStreamer:zr,Iterator:Ct,ObservableStreamer:co,Writer:to,WriterClosedError:bn,WriterCommand:tt,WriterMode:xt,createStreamOpener:ao,frameZ:Nr,ontologyID:xg,openStreamer:oo,seriesFromPayload:Ja,seriesToPayload:Xa,streamerConfigZ:_n,writerConfigZ:eo},Symbol.toStringTag,{value:"Module"})),Rg=te.ABSOLUTE_AUTHORITY,jg=te.ZERO_AUTHORITY,Mg=te.stateZ(s.z.number()),Ug=r=>r.to==null?`${r.from?.resource} - ${r.from?.subject.name} -> released`:r.from==null?`${r.to.resource} - released -> ${r.to.subject.name} (${r.to.authority.toString()})`:`${r.to.resource} - ${r.from.subject.name} -> ${r.to.subject.name} (${r.to.authority.toString()})`,Dg=s.z.object({transfers:s.z.array(te.transferZ(j))});class uo extends co{states;codec;constructor(e){super(e,t=>{const n=this.codec.decode(t.series[0].buffer,Dg);return this.merge(n),[n.transfers,!0]}),this.states=new Map,this.codec=new Be.JSONCodec}subjects(){const e=new Map;return this.states.forEach(t=>e.set(t.subject.key,t.subject)),Array.from(e.values())}merge(e){e.transfers.forEach(t=>{t.from==null&&t.to==null&&console.warn("Invalid transfer: ",t),t.to==null?this.states.delete(t.from.resource):this.states.set(t.to.resource,t.to)})}}const ho="sy_node_1_control";let fo=class{framer;constructor(e){this.framer=e}async openStateTracker(){const e=await zr.open(async t=>await this.framer.openStreamer(t),ho);return new uo(e)}};const Zg=Object.freeze(Object.defineProperty({__proto__:null,ABSOLUTE_AUTHORITY:Rg,CONTROL_STATE_CHANNEL_NAME:ho,Client:fo,StateTracker:uo,ZERO_AUTHORITY:jg,stateZ:Mg,transferString:Ug},Symbol.toStringTag,{value:"Module"}));let yo=class{tasks;racks;devices;constructor(e,t,n){this.tasks=e,this.racks=t,this.devices=n}};const Pg=Object.freeze(Object.defineProperty({__proto__:null,Client:yo},Symbol.toStringTag,{value:"Module"})),fe=s.z.uint32(),go=Pt.statusZ(s.z.object({rack:fe})),Sr=s.z.object({key:fe,name:s.z.string(),status:bt.nullToUndefined(go)}),po=Sr.partial({key:!0}),mo=r=>r?Be.JSON_CODEC.decodeString(r,we.unknownZ):{},ot=s.z.string(),wo=Pt.statusZ(s.z.object({rack:fe,device:ot})),Ar=s.z.object({key:ot,rack:fe,name:s.z.string(),make:s.z.string(),model:s.z.string(),location:s.z.string(),configured:s.z.boolean().optional(),properties:we.unknownZ.or(s.z.string().transform(mo)),status:bt.nullToUndefined(wo)}),bo=Ar.extend({properties:s.z.unknown().transform(r=>Be.JSON_CODEC.encodeString(r))}),Lg="sy_device_set",Bg="sy_device_delete",qg="sy_device_status",Fg="/hardware/device/retrieve",Yg="/hardware/device/create",Vg="/hardware/device/delete",Hg=s.z.object({devices:bo.array()}),_g=s.z.object({devices:Ar.array()}),Wg=s.z.object({keys:ot.array()}),Gg=s.z.object({}),Kg=s.z.object({keys:ot.array().optional(),names:s.z.string().array().optional(),makes:s.z.string().array().optional(),models:s.z.string().array().optional(),locations:s.z.string().array().optional(),racks:fe.array().optional(),searchTerm:s.z.string().optional(),limit:s.z.number().optional(),offset:s.z.number().optional(),includeStatus:s.z.boolean().optional()}),Jg=s.z.object({devices:L(Ar)}),Xg=s.z.object({key:ot,includeStatus:s.z.boolean().optional()}).transform(({key:r,includeStatus:e})=>({keys:[r],includeStatus:e})),Qg=s.z.union([Xg,Kg]);let To=class{type="device";client;constructor(e){this.client=e}async retrieve(e){const t=typeof e=="object"&&"key"in e,n=await m(this.client,Fg,e,Qg,Jg);Fe("Device",e,n.devices,t);const i=n.devices;return t?i[0]:i}async create(e){const t=!Array.isArray(e),i=(await m(this.client,Yg,{devices:v.toArray(e)},Hg,_g)).devices;return t?i[0]:i}async delete(e){await m(this.client,Vg,{keys:v.toArray(e)},Wg,Gg)}};const ep=r=>({type:"device",key:r}),tp=Object.freeze(Object.defineProperty({__proto__:null,Client:To,DELETE_CHANNEL_NAME:Bg,SET_CHANNEL_NAME:Lg,STATUS_CHANNEL_NAME:qg,deviceZ:Ar,keyZ:ot,newZ:bo,ontologyID:ep,statusZ:wo},Symbol.toStringTag,{value:"Module"})),rp="/hardware/rack/retrieve",np="/hardware/rack/create",sp="/hardware/rack/delete",ip="sy_rack_status",ap="sy_rack_set",op="sy_rack_delete",cp=s.z.object({keys:fe.array().optional(),names:s.z.string().array().optional(),searchTerm:s.z.string().optional(),embedded:s.z.boolean().optional(),hostIsNode:s.z.boolean().optional(),limit:s.z.number().optional(),offset:s.z.number().optional(),includeStatus:s.z.boolean().optional()}),lp=s.z.object({racks:L(Sr)}),up=s.z.union([s.z.object({key:fe,includeStatus:s.z.boolean().optional()}).transform(({key:r,includeStatus:e})=>({keys:[r],includeStatus:e})),s.z.object({name:s.z.string(),includeStatus:s.z.boolean().optional()}).transform(({name:r,includeStatus:e})=>({names:[r],includeStatus:e}))]),hp=cp,fp=s.z.union([up,hp]),dp=s.z.object({racks:po.array()}),yp=s.z.object({racks:Sr.array()}),gp=s.z.object({keys:fe.array()}),pp=s.z.object({});let vo=class{type="rack";client;tasks;constructor(e,t){this.client=e,this.tasks=t}async delete(e){await m(this.client,sp,{keys:v.toArray(e)},gp,pp)}async create(e){const t=!Array.isArray(e),n=await m(this.client,np,{racks:v.toArray(e)},dp,yp),i=this.sugar(n.racks);return t?i[0]:i}async retrieve(e){const t="key"in e||"name"in e,n=await m(this.client,rp,e,fp,lp),i=this.sugar(n.racks);return Fe("Rack",e,i,t),t?i[0]:i}sugar(e){const t=!Array.isArray(e),n=v.toArray(e).map(({key:i,name:a,status:o})=>new Eo(i,a,this.tasks,o));return t?n[0]:n}};class Eo{key;name;status;tasks;constructor(e,t,n,i){this.key=e,this.name=t,this.tasks=n,this.status=i}async listTasks(){return await this.tasks.retrieve({rack:this.key})}async createTask(e,t){return e.key=((BigInt(this.key)<<32n)+(BigInt(e.key??0)&0xffffffffn)).toString(),await this.tasks.create(e,t)}async deleteTask(e){await this.tasks.delete([e])}get payload(){return{key:this.key,name:this.name,status:this.status}}}const mp=r=>({type:"rack",key:r.toString()}),wp=Object.freeze(Object.defineProperty({__proto__:null,Client:vo,DELETE_CHANNEL_NAME:op,Rack:Eo,SET_CHANNEL_NAME:ap,STATUS_CHANNEL_NAME:ip,keyZ:fe,newZ:po,ontologyID:mp,rackZ:Sr,statusZ:go},Symbol.toStringTag,{value:"Module"})),be=r=>r?JSON.parse(r):{},Te=s.z.union([s.z.string(),s.z.bigint().transform(r=>r.toString()),s.z.number().transform(r=>r.toString())]),No=r=>s.z.object({task:Te,running:s.z.boolean(),data:r}),Wn=r=>Pt.statusZ(No(r)),Ft=(r={typeSchema:s.z.string(),configSchema:s.z.unknown(),statusDataSchema:s.z.unknown()})=>s.z.object({key:Te,name:s.z.string(),type:r.typeSchema,internal:s.z.boolean().optional(),config:s.z.string().transform(mo).or(r.configSchema),status:Wn(r.statusDataSchema).optional().nullable(),snapshot:s.z.boolean().optional()}),Oo=r=>Ft(r).omit({key:!0}).extend({key:Te.transform(e=>e.toString()).optional(),config:s.z.unknown().transform(e=>Be.JSON_CODEC.encodeString(e))}),bp=s.z.object({task:Te,type:s.z.string(),key:s.z.string(),args:we.unknownZ.or(s.z.string().transform(be)).or(s.z.array(s.z.unknown())).or(s.z.null()).optional()}),Tp=r=>Number(BigInt(r)>>32n),vn="sy_task_status",En="sy_task_cmd",vp="sy_task_set",Ep="sy_task_delete",Ue=new Error("Task not created"),zo=async(r,e)=>{const t=await e.retrieveParents(Gn(r));return t.length===0?null:t[0]};class So{key;name;internal;type;snapshot;config;status;schemas;frameClient_;ontologyClient_;rangeClient_;get frameClient(){if(this.frameClient_==null)throw Ue;return this.frameClient_}get ontologyClient(){if(this.ontologyClient_==null)throw Ue;return this.ontologyClient_}get rangeClient(){if(this.rangeClient_==null)throw Ue;return this.rangeClient_}constructor({key:e,type:t,name:n,config:i,internal:a=!1,snapshot:o=!1,status:c},u,l,h,y){this.key=e,this.name=n,this.type=t,this.config=i,this.schemas=u??{typeSchema:s.z.string(),configSchema:s.z.unknown(),statusDataSchema:s.z.unknown()},this.internal=a,this.snapshot=o,this.status=c,this.frameClient_=l,this.ontologyClient_=h,this.rangeClient_=y}get payload(){return{key:this.key,name:this.name,type:this.type,config:this.config,status:this.status,internal:this.internal}}get ontologyID(){return Gn(this.key)}async executeCommand(e,t){return await $o(this.frameClient,this.key,e,t)}async executeCommandSync(e,t,n){return await Io(this.frameClient,this.key,e,t,this.name,this.schemas?.statusDataSchema,n)}async snapshottedTo(){if(this.ontologyClient==null||this.rangeClient==null)throw Ue;return this.snapshot?await zo(this.key,this.ontologyClient):null}}const Np=s.z.object({rack:fe.optional(),keys:Te.array().optional(),names:s.z.string().array().optional(),types:s.z.string().array().optional(),includeStatus:s.z.boolean().optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),Op=s.z.union([s.z.object({key:Te,includeStatus:s.z.boolean().optional()}).transform(({key:r,includeStatus:e})=>({keys:[r],includeStatus:e})),s.z.object({name:s.z.string(),includeStatus:s.z.boolean().optional()}).transform(({name:r,includeStatus:e})=>({names:[r],includeStatus:e}))]),zp=Np,Sp=s.z.union([Op,zp]),Ap=r=>s.z.object({tasks:L(Ft(r))}),$p="/hardware/task/retrieve",Ip="/hardware/task/create",kp="/hardware/task/delete",xp="/hardware/task/copy",Cp=r=>s.z.object({tasks:Oo(r).array()}),Rp=r=>s.z.object({tasks:Ft(r).array()}),jp=s.z.object({keys:Te.array()}),Mp=s.z.object({}),Up=s.z.object({key:Te,name:s.z.string(),snapshot:s.z.boolean()}),Dp=r=>s.z.object({task:Ft(r)});let Ao=class{type="task";client;frameClient;ontologyClient;rangeClient;constructor(e,t,n,i){this.client=e,this.frameClient=t,this.ontologyClient=n,this.rangeClient=i}async create(e,t){const n=!Array.isArray(e),i=Cp(t),a=Rp(t),o=await m(this.client,Ip,{tasks:v.toArray(e)},i,a),c=this.sugar(o.tasks,t);return n?c[0]:c}async delete(e){await m(this.client,kp,{keys:v.toArray(e)},jp,Mp)}async retrieve({schemas:e,...t}){const n="key"in t||"name"in t,a=(await m(this.client,$p,t,Sp,Ap(e))).tasks,o=this.sugar(a,e);return Fe("Task",t,o,n),n?o[0]:o}async copy(e,t,n){const i=Dp(),a=await m(this.client,xp,{key:e,name:t,snapshot:n},Up,i);return this.sugar(a.task)}async retrieveSnapshottedTo(e){if(this.ontologyClient==null)throw Ue;return await zo(e,this.ontologyClient)}sugar(e,t){const n=!Array.isArray(e),i=v.toArray(e).map(({key:a,name:o,type:c,config:u,status:l,internal:h,snapshot:y})=>new So({key:a,name:o,type:c,config:u,internal:h,snapshot:y,status:l},t,this.frameClient,this.ontologyClient,this.rangeClient));return n?i[0]:i}async executeCommand(e,t,n){if(Array.isArray(e))return await Kn(this.frameClient,e);if(t==null)throw new Error("Type is required");return await $o(this.frameClient,e,t,n)}async executeCommandSync(e,t,n,i,a,o=s.z.unknown()){if(Array.isArray(e)){const u=async()=>(await this.retrieve({keys:e.map(h=>h.task)})).map(h=>h.name);return await ko(this.frameClient,e,t,o,u)}const c=async()=>(await this.retrieve({key:e})).name;return await Io(this.frameClient,e,t,n,a??c,o,i)}};const Gn=r=>({type:"task",key:r}),$o=async(r,e,t,n)=>(await Kn(r,[{args:n,task:e,type:t}]))[0],Kn=async(r,e)=>{if(r==null)throw Ue;const t=await r.openWriter(En),n=e.map(i=>({...i,key:Rh.create()}));return await t.write(En,n),await t.close(),n.map(i=>i.key)},Io=async(r,e,t,n,i,a,o)=>(await ko(r,[{args:o,task:e,type:t}],n,a,i))[0],ko=async(r,e,t,n,i)=>{if(r==null)throw Ue;const a=await r.openStreamer(vn),o=await Kn(r,e),c=new E(t);let u=[],l;const h=new Promise((y,d)=>{l=setTimeout(()=>{(async()=>{const N=e.map(S=>S.task);d(await Zp("command",i,c,N))})()},c.milliseconds)});try{for(;;){const y=await Promise.race([a.read(),h]),d=Wn(n).parse(y.at(-1)[vn]);if(o.includes(d.key)&&(u=[...u.filter(N=>N.key!==d.key),d],u.length===o.length))return u}}finally{clearTimeout(l),a.close()}},Zp=async(r,e,t,n)=>{const i=pu.capitalize(r),a=t.toString();try{let o;typeof e=="string"?o=[e]:Array.isArray(e)?o=e:o=v.toArray(await e());const c=yn.naturalLanguageJoin(o);return new Error(`${i} command to ${c} timed out after ${a}`)}catch(o){return console.error("Failed to retrieve task name for timeout error:",o),new Error(`${i} command to task with key ${yn.naturalLanguageJoin(n)} timed out after ${a}`)}},Pp=Object.freeze(Object.defineProperty({__proto__:null,COMMAND_CHANNEL_NAME:En,Client:Ao,DELETE_CHANNEL_NAME:Ep,SET_CHANNEL_NAME:vp,STATUS_CHANNEL_NAME:vn,Task:So,commandZ:bp,keyZ:Te,newZ:Oo,ontologyID:Gn,rackKey:Tp,statusDetailsZ:No,statusZ:Wn,taskZ:Ft},Symbol.toStringTag,{value:"Module"})),Re=s.z.uuid(),Yt=s.z.object({key:Re,name:s.z.string().min(1),color:s.z.string()}),Lp="labeled_by",Bp="sy_label_set",qp="sy_label_delete",xo=Yt.extend({key:Re.optional()}),Fp=s.object({labels:xo.array()}),Yp=s.object({labels:Yt.array()}),Vp=s.object({keys:Re.array()}),Co=s.object({id:C,labels:Re.array(),replace:s.boolean().optional()}),Hp=Co.omit({replace:!0}),Yr=s.object({}),_p="/label/create",Wp="/label/delete",Gp="/label/set",Kp="/label/remove",Jp="/label/retrieve",Xp=s.object({keys:Re.array().optional(),for:C.optional(),searchTerm:s.string().optional(),offset:s.number().optional(),limit:s.number().optional()}),Qp=s.object({key:Re}).transform(({key:r})=>({keys:[r]})),em=s.union([Qp,Xp]),tm=s.object({labels:L(Yt)});let Ro=class{type="label";client;constructor(e){this.client=e}async retrieve(e){const t="key"in e,n=await m(this.client,Jp,e,em,tm);return Fe("Label",e,n.labels,t),t?n.labels[0]:n.labels}async label(e,t,n={}){await m(this.client,Gp,{id:e,labels:t,replace:n.replace},Co,Yr)}async remove(e,t){await m(this.client,Kp,{id:e,labels:t},Hp,Yr)}async create(e){const t=Array.isArray(e),n=await m(this.client,_p,{labels:v.toArray(e)},Fp,Yp);return t?n.labels:n.labels[0]}async delete(e){await m(this.client,Wp,{keys:v.toArray(e)},Vp,Yr)}};const rm=r=>({type:"label",key:r}),nm=Object.freeze(Object.defineProperty({__proto__:null,Client:Ro,DELETE_CHANNEL_NAME:qp,LABELED_BY_ONTOLOGY_RELATIONSHIP_TYPE:Lp,SET_CHANNEL_NAME:Bp,keyZ:Re,labelZ:Yt,newZ:xo,ontologyID:rm},Symbol.toStringTag,{value:"Module"})),H=s.z.uuid(),Jn=s.z.string().min(1),Vt=s.z.object({key:H,name:Jn,timeRange:M.z,color:s.z.string().optional(),labels:Yt.array().or(s.z.null().transform(()=>{})).optional(),get parent(){return Vt.optional().nullable().transform(r=>r===void 0?null:r)}}),jo=Vt.omit({parent:!0,labels:!0}).partial({key:!0}),sm="sy_range_alias_set",im="sy_range_alias_delete",am=s.z.object({range:H,aliases:s.z.string().array()}),om=s.z.object({aliases:s.z.record(s.z.string(),j)}),cm=s.z.object({range:H,aliases:s.z.record(j,s.z.string())}),lm=s.z.unknown(),um=s.z.object({range:H,channels:j.array()}),hm=s.z.unknown(),fm=s.z.object({range:H}),dm=s.z.object({aliases:s.z.record(s.z.string(),s.z.string())}),ym=s.z.object({range:H,channels:j.array()}),gm=s.z.object({aliases:s.z.record(s.z.string(),s.z.string())});class ee{static SET_ENDPOINT="/range/alias/set";static RESOLVE_ENDPOINT="/range/alias/resolve";static LIST_ENDPOINT="/range/alias/list";static RETRIEVE_ENDPOINT="/range/alias/retrieve";static DELETE_ENDPOINT="/range/alias/delete";frameClient;cache=new Map;client;rangeKey;constructor(e,t,n){this.rangeKey=e,this.cache=new Map,this.client=n,this.frameClient=t}async resolve(e){const t=[],n=typeof e=="string",i={};if(n){const o=this.cache.get(e);if(o!=null)return o;t.push(e)}else e.forEach(o=>{const c=this.cache.get(o);c!=null?i[o]=c:t.push(o)});if(t.length===0)return i;const a=await m(this.client,ee.RESOLVE_ENDPOINT,{range:this.rangeKey,aliases:t},am,om);return Object.entries(a.aliases).forEach(([o,c])=>this.cache.set(o,c)),n?a.aliases[t[0]]:{...i,...a.aliases}}async set(e){await m(this.client,ee.SET_ENDPOINT,{range:this.rangeKey,aliases:e},cm,lm)}async list(){return(await m(this.client,ee.LIST_ENDPOINT,{range:this.rangeKey},fm,dm)).aliases}async retrieve(e){const t=typeof e=="number",n=await m(this.client,ee.RETRIEVE_ENDPOINT,{range:this.rangeKey,channels:v.toArray(e)},ym,gm);return t?n.aliases[e]:n.aliases}async delete(e){await m(this.client,ee.DELETE_ENDPOINT,{range:this.rangeKey,channels:e},um,hm)}}const pm=s.z.object({alias:s.z.string().optional(),channel:j,range:H}),Mo="---",mm=r=>`${r.range}${Mo}${r.channel}`,wm=r=>{const[e,t]=r.split(Mo);return{range:e,channel:Number(t)}},bm="sy_range_kv_set",Tm="sy_range_kv_delete",Xn=s.z.object({range:H,key:s.z.string(),value:s.z.string()}),vm=({range:r,key:e})=>`${r}<--->${e}`,Em=s.z.object({range:H,keys:s.z.string().array()}),Nm=s.z.object({pairs:L(Xn)}),Om=s.z.object({range:H,pairs:Xn.array()}),zm=s.z.object({range:H,keys:s.z.string().array()});class Pe{static GET_ENDPOINT="/range/kv/get";static SET_ENDPOINT="/range/kv/set";static DELETE_ENDPOINT="/range/kv/delete";rangeKey;client;constructor(e,t){this.rangeKey=e,this.client=t}async get(e){const t=await m(this.client,Pe.GET_ENDPOINT,{range:this.rangeKey,keys:v.toArray(e)},Em,Nm);return typeof e=="string"?t.pairs[0].value:Object.fromEntries(t.pairs.map(n=>[n.key,n.value]))}async list(){return this.get([])}async set(e,t=""){let n;wi(e)?n=Object.entries(e).map(([i,a])=>({range:this.rangeKey,key:i,value:a})):n=[{range:this.rangeKey,key:e,value:t}],await m(this.client,Pe.SET_ENDPOINT,{range:this.rangeKey,pairs:n},Om,s.z.unknown())}async delete(e){await m(this.client,Pe.DELETE_ENDPOINT,{range:this.rangeKey,keys:v.toArray(e)},zm,s.z.unknown())}}const Sm="sy_range_set",Am="sy_range_delete";class Uo{key;name;kv;timeRange;color;parent;labels;channels;aliaser;frameClient;labelClient;ontologyClient;rangeClient;constructor({name:e,timeRange:t=M.ZERO,key:n,color:i,parent:a,labels:o},{frameClient:c,kv:u,aliaser:l,channels:h,labelClient:y,ontologyClient:d,rangeClient:N}){this.key=n,this.name=e,this.timeRange=t,this.parent=a,this.labels=o,this.frameClient=c,this.color=i,this.kv=u,this.aliaser=l,this.channels=h,this.labelClient=y,this.ontologyClient=d,this.rangeClient=N}get ontologyID(){return Ge(this.key)}get payload(){let e=null;return this.parent!=null&&("payload"in this.parent?e=this.parent.payload:e=this.parent),{key:this.key,name:this.name,timeRange:this.timeRange,color:this.color,labels:this.labels,parent:e}}async setAlias(e,t){const n=await this.channels.retrieve(e);if(n.length===0)throw new xe(`Channel ${e} does not exist`);await this.aliaser.set({[n[0].key]:t})}async deleteAlias(...e){await this.aliaser.delete(e)}async listAliases(){return await this.aliaser.list()}async resolveAlias(e){return await this.aliaser.resolve(e)}async retrieveParent(){return this.rangeClient.retrieveParent(this.key)}async retrieveChildren(){const e=(await this.ontologyClient.retrieveChildren(this.ontologyID,{excludeFieldData:!0,types:["range"]})).map(t=>t.id.key);return await this.rangeClient.retrieve(e)}async read(e){return await this.frameClient.read(this.timeRange,e)}async retrieveLabels(){return await this.labelClient.retrieve({for:Ge(this.key)})}async addLabel(...e){await this.labelClient.label(Ge(this.key),e)}async removeLabel(...e){await this.labelClient.remove(Ge(this.key),e)}static sort(e,t){return M.sort(e.timeRange,t.timeRange)}}const $m=s.z.object({keys:H.array().optional(),names:s.z.array(s.z.string()).optional(),searchTerm:s.z.string().optional(),overlapsWith:M.z.optional(),limit:s.z.number().int().optional(),offset:s.z.number().int().optional(),hasLabels:Re.array().optional(),includeLabels:s.z.boolean().optional(),includeParent:s.z.boolean().optional()}),Im=$m.or(H.array().transform(r=>({keys:r}))).or(H.transform(r=>({keys:[r]}))).or(s.z.string().transform(r=>({names:[r]}))).or(s.z.string().array().transform(r=>({names:r}))).or(M.z.transform(r=>({overlapsWith:r}))),km="/range/retrieve",xm=s.z.object({ranges:L(Vt)});let Do=class{type="range";frameClient;writer;unaryClient;channels;labelClient;ontologyClient;constructor(e,t,n,i,a,o){this.frameClient=e,this.writer=t,this.unaryClient=n,this.channels=i,this.labelClient=a,this.ontologyClient=o}async create(e,t){const n=!Array.isArray(e),i=this.sugarMany(await this.writer.create(v.toArray(e),t));return n?i[0]:i}async rename(e,t){await this.writer.rename(e,t)}async delete(e){await this.writer.delete(v.toArray(e))}async retrieve(e){const t=typeof e=="string",{ranges:n}=await m(this.unaryClient,km,e,Im,xm);return Fe("Range",e,n,t),t?this.sugarMany(n)[0]:this.sugarMany(n)}getKV(e){return new Pe(e,this.unaryClient)}async retrieveParent(e){const t=await this.ontologyClient.retrieveParents(Ge(e));if(t.length===0)return null;const n=t[0];return n.id.type!=="range"?null:await this.retrieve(n.id.key)}sugarOntologyResource(e){return this.sugarOne(Zo(e))}async retrieveAlias(e,t){return await new ee(e,this.frameClient,this.unaryClient).retrieve(t)}async retrieveAliases(e,t){return await new ee(e,this.frameClient,this.unaryClient).retrieve(t)}async listAliases(e){return await new ee(e,this.frameClient,this.unaryClient).list()}async setAlias(e,t,n){await new ee(e,this.frameClient,this.unaryClient).set({[t]:n})}sugarOne(e){return new Uo(e,{frameClient:this.frameClient,kv:new Pe(e.key,this.unaryClient),aliaser:new ee(e.key,this.frameClient,this.unaryClient),channels:this.channels,labelClient:this.labelClient,ontologyClient:this.ontologyClient,rangeClient:this})}sugarMany(e){return e.map(t=>this.sugarOne(t))}resourceToRange(e){return this.sugarOne({key:e.id.key,name:e.data?.name,timeRange:new M(e.data?.timeRange),color:e.data?.color,labels:[],parent:null})}};const Ge=r=>({type:"range",key:r}),Cm=r=>({type:"range-alias",key:r}),Zo=({data:r,id:{key:e},name:t})=>{const n=M.z.parse(r?.timeRange);return{key:e,name:t,timeRange:n,color:typeof r?.color=="string"?r.color:void 0,labels:[],parent:null}},Rm=s.z.object({ranges:Vt.array()}),jm=s.z.object({parent:C.optional(),ranges:jo.array()}),Mm=s.z.object({keys:H.array()}),Um=s.z.object({}),Dm=s.z.object({key:H,name:Jn}),Zm=s.z.object({}),Pm="/range/create",Lm="/range/delete",Bm="/range/rename";class Po{client;constructor(e){this.client=e}async rename(e,t){await m(this.client,Bm,{key:e,name:t},Dm,Zm)}async create(e,t){return(await m(this.client,Pm,{ranges:e,...t},jm,Rm)).ranges}async delete(e){await m(this.client,Lm,{keys:e},Mm,Um)}}const qm=Object.freeze(Object.defineProperty({__proto__:null,Aliaser:ee,Client:Do,DELETE_ALIAS_CHANNEL_NAME:im,DELETE_CHANNEL_NAME:Am,KV:Pe,KV_DELETE_CHANNEL:Tm,KV_SET_CHANNEL:bm,Range:Uo,SET_ALIAS_CHANNEL_NAME:sm,SET_CHANNEL_NAME:Sm,Writer:Po,aliasKey:mm,aliasOntologyID:Cm,aliasZ:pm,convertOntologyResourceToPayload:Zo,decodeDeleteAliasChange:wm,keyZ:H,kvPairKey:vm,kvPairZ:Xn,nameZ:Jn,newZ:jo,ontologyID:Ge,payloadZ:Vt},Symbol.toStringTag,{value:"Module"})),Fm="/api/v1/";class Ym{url;unary;stream;secure;constructor(e,t={},n=!1){this.secure=n,this.url=e.child(Fm);const i=new Be.JSONCodec;this.unary=ru(new tu(this.url,i,this.secure),t),this.stream=new ar(this.url,i,this.secure)}use(...e){this.unary.use(...e),this.stream.use(...e)}}const ct=s.z.uuid(),$r=s.z.object({key:ct,name:s.z.string(),data:we.unknownZ.or(s.z.string().transform(be))}),Lo=$r.partial({key:!0}).transform(r=>({...r,data:JSON.stringify(r.data)})),de=s.z.uuid(),Ir=s.z.object({key:de,name:s.z.string(),layout:we.unknownZ.or(s.z.string().transform(be))}),Bo=Ir.partial({key:!0}).transform(r=>({...r,layout:JSON.stringify(r.layout)})),qo=Ir.omit({layout:!0}).extend({layout:s.z.string().transform(be)}),Vm="/workspace/lineplot/retrieve",Hm="/workspace/lineplot/create",_m="/workspace/lineplot/rename",Wm="/workspace/lineplot/set-data",Gm="/workspace/lineplot/delete",Km=s.z.object({keys:ct.array()}),Jm=s.z.object({workspace:de,linePlots:Lo.array()}),Xm=s.z.object({key:ct,name:s.z.string()}),Qm=s.z.object({key:ct,data:s.z.string()}),ew=s.z.object({keys:ct.array()}),tw=s.z.object({linePlots:L($r)}),rw=s.z.object({linePlots:$r.array()}),Vr=s.z.object({});let Fo=class{client;constructor(e){this.client=e}async create(e,t){const n=Array.isArray(t),i=await m(this.client,Hm,{workspace:e,linePlots:v.toArray(t)},Jm,rw);return n?i.linePlots:i.linePlots[0]}async rename(e,t){await m(this.client,_m,{key:e,name:t},Xm,Vr)}async setData(e,t){await m(this.client,Wm,{key:e,data:JSON.stringify(t)},Qm,Vr)}async retrieve(e){const t=Array.isArray(e),n=await m(this.client,Vm,{keys:v.toArray(e)},Km,tw);return t?n.linePlots:n.linePlots[0]}async delete(e){await m(this.client,Gm,{keys:v.toArray(e)},ew,Vr)}};const nw=r=>({type:"lineplot",key:r}),sw=Object.freeze(Object.defineProperty({__proto__:null,Client:Fo,keyZ:ct,linePlotZ:$r,newZ:Lo,ontologyID:nw},Symbol.toStringTag,{value:"Module"})),lt=s.z.uuid(),kr=s.z.object({key:lt,name:s.z.string(),data:we.unknownZ.or(s.z.string().transform(be))}),Yo=kr.partial({key:!0}).transform(r=>({...r,data:JSON.stringify(r.data)})),iw="/workspace/log/retrieve",aw="/workspace/log/create",ow="/workspace/log/rename",cw="/workspace/log/set-data",lw="/workspace/log/delete",uw=s.z.object({keys:lt.array()}),hw=s.z.object({workspace:de,logs:Yo.array()}),fw=s.z.object({key:lt,name:s.z.string()}),dw=s.z.object({key:lt,data:s.z.string()}),yw=s.z.object({keys:lt.array()}),gw=s.z.object({logs:kr.array()}),pw=s.z.object({logs:kr.array()}),Hr=s.z.object({});let Vo=class{client;constructor(e){this.client=e}async create(e,t){const n=Array.isArray(t),i=await m(this.client,aw,{workspace:e,logs:v.toArray(t)},hw,pw);return n?i.logs:i.logs[0]}async rename(e,t){await m(this.client,ow,{key:e,name:t},fw,Hr)}async setData(e,t){await m(this.client,cw,{key:e,data:JSON.stringify(t)},dw,Hr)}async retrieve(e){const t=Array.isArray(e),n=await m(this.client,iw,{keys:v.toArray(e)},uw,gw);return t?n.logs:n.logs[0]}async delete(e){await m(this.client,lw,{keys:v.toArray(e)},yw,Hr)}};const mw=r=>({type:"log",key:r}),ww=Object.freeze(Object.defineProperty({__proto__:null,Client:Vo,keyZ:lt,logZ:kr,newZ:Yo,ontologyID:mw},Symbol.toStringTag,{value:"Module"})),Ye=s.z.uuid(),xr=s.z.object({key:Ye,name:s.z.string(),data:we.unknownZ.or(s.z.string().transform(be)),snapshot:s.z.boolean()}),Ho=xr.partial({key:!0,snapshot:!0}).transform(r=>({...r,data:JSON.stringify(r.data)})),Qn=xr.extend({data:s.z.string().transform(be)}),ut=s.z.uuid(),_o=s.z.object({key:s.z.string(),name:s.z.string(),selectors:s.z.string().array().default([]),strokeColor:s.z.string().optional(),fillColor:s.z.string().optional()}),Wo=s.z.object({key:s.z.string(),name:s.z.string(),regions:_o.array()}),Go=s.z.object({key:s.z.string(),position:Wi.xy,orientation:ih.outer}),bw=s.z.object({zoom:s.z.number().positive().default(1),position:Wi.xy}),Ko=s.z.object({svg:s.z.string().min(1,"SVG is required"),states:Wo.array(),variant:s.z.string().min(1,"Variant is required"),handles:Go.array(),scale:s.z.number().positive().default(1),scaleStroke:s.z.boolean().default(!1),previewViewport:bw.default({zoom:1,position:{x:0,y:0}})}),Cr=s.z.object({key:ut,version:s.z.literal(1).optional().default(1),name:s.z.string().min(1,"Name is required"),data:Ko}),Jo=Cr.partial({key:!0}),Tw="/workspace/schematic/symbol/retrieve",vw="/workspace/schematic/symbol/create",Ew="/workspace/schematic/symbol/rename",Nw="/workspace/schematic/symbol/delete",Ow="/workspace/schematic/symbol/retrieve_group",zw=s.z.object({symbols:Jo.array(),parent:C}),Sw=s.z.object({key:ut,name:s.z.string()}),Aw=s.z.object({keys:ut.array()}),$w=s.z.object({keys:ut.array().optional(),searchTerm:s.z.string().optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),Iw=s.z.object({key:ut}).transform(({key:r})=>({keys:[r]})),kw=s.z.union([Iw,$w]),xw=s.z.object({symbols:L(Cr)}),Cw=s.z.object({symbols:Cr.array()}),Ls=s.z.object({}),Rw=s.z.object({}),jw=s.z.object({group:Tr}),Mw="sy_schematic_symbol_set",Uw="sy_schematic_symbol_delete";let Xo=class{client;constructor(e){this.client=e}async create(e){const t="symbols"in e,n=t?e.symbols:[e],i=await m(this.client,vw,{symbols:n,parent:e.parent},zw,Cw);return t?i.symbols:i.symbols[0]}async rename(e,t){await m(this.client,Ew,{key:e,name:t},Sw,Ls)}async retrieve(e){const t="key"in e,n=await m(this.client,Tw,e,kw,xw);return Fe("Schematic Symbol",e,n.symbols,t),t?n.symbols[0]:n.symbols}async delete(e){await m(this.client,Nw,{keys:v.toArray(e)},Aw,Ls)}async retrieveGroup(){return(await m(this.client,Ow,{},Rw,jw)).group}};const Dw=r=>({type:"schematic_symbol",key:r}),Zw=Object.freeze(Object.defineProperty({__proto__:null,Client:Xo,DELETE_CHANNEL_NAME:Uw,SET_CHANNEL_NAME:Mw,handleZ:Go,keyZ:ut,newZ:Jo,ontologyID:Dw,regionZ:_o,specZ:Ko,stateZ:Wo,symbolZ:Cr},Symbol.toStringTag,{value:"Module"})),Pw="/workspace/schematic/retrieve",Lw="/workspace/schematic/create",Bw="/workspace/schematic/rename",qw="/workspace/schematic/set-data",Fw="/workspace/schematic/delete",Yw="/workspace/schematic/copy",Vw=s.z.object({keys:Ye.array()}),Hw=s.z.object({workspace:de,schematics:Ho.array()}),_w=s.z.object({key:Ye,name:s.z.string()}),Ww=s.z.object({key:Ye,data:s.z.string()}),Gw=s.z.object({keys:Ye.array()}),Kw=s.z.object({key:Ye,name:s.z.string(),snapshot:s.z.boolean()}),Jw=s.z.object({schematics:L(Qn)}),Xw=s.z.object({schematics:Qn.array()}),Qw=s.z.object({schematic:xr}),_r=s.z.object({});let Qo=class{symbols;client;constructor(e){this.client=e,this.symbols=new Xo(e)}async create(e,t){const n=Array.isArray(t),i=await m(this.client,Lw,{workspace:e,schematics:v.toArray(t)},Hw,Xw);return n?i.schematics:i.schematics[0]}async rename(e,t){await m(this.client,Bw,{key:e,name:t},_w,_r)}async setData(e,t){await m(this.client,qw,{key:e,data:JSON.stringify(t)},Ww,_r)}async retrieve(e){const t=Array.isArray(e),n=await m(this.client,Pw,{keys:v.toArray(e)},Vw,Jw);return t?n.schematics:n.schematics[0]}async delete(e){await m(this.client,Fw,{keys:v.toArray(e)},Gw,_r)}async copy(e,t,n){return(await m(this.client,Yw,{key:e,name:t,snapshot:n},Kw,Qw)).schematic}};const eb=r=>({type:"schematic",key:r}),tb=Object.freeze(Object.defineProperty({__proto__:null,Client:Qo,keyZ:Ye,newZ:Ho,ontologyID:eb,remoteZ:Qn,schematicZ:xr,symbol:Zw},Symbol.toStringTag,{value:"Module"})),ht=s.z.uuid(),es=s.z.object({key:ht,name:s.z.string(),data:we.unknownZ.or(s.z.string().transform(be))}),ec=es.partial({key:!0}).transform(r=>({...r,data:JSON.stringify(r.data)})),ts=es.extend({data:s.z.string().transform(be)}),rb="/workspace/table/retrieve",nb="/workspace/table/create",sb="/workspace/table/rename",ib="/workspace/table/set-data",ab="/workspace/table/delete",ob=s.z.object({keys:ht.array()}),cb=s.z.object({workspace:de,tables:ec.array()}),lb=s.z.object({key:ht,name:s.z.string()}),ub=s.z.object({key:ht,data:s.z.string()}),hb=s.z.object({keys:ht.array()}),fb=s.z.object({tables:ts.array()}),db=s.z.object({tables:ts.array()}),Wr=s.z.object({});let tc=class{client;constructor(e){this.client=e}async create(e,t){const n=Array.isArray(t),i=await m(this.client,nb,{workspace:e,tables:v.toArray(t)},cb,db);return n?i.tables:i.tables[0]}async rename(e,t){await m(this.client,sb,{key:e,name:t},lb,Wr)}async setData(e,t){await m(this.client,ib,{key:e,data:JSON.stringify(t)},ub,Wr)}async retrieve(e){const t=Array.isArray(e),n=await m(this.client,rb,{keys:v.toArray(e)},ob,fb);return t?n.tables:n.tables[0]}async delete(e){await m(this.client,ab,{keys:v.toArray(e)},hb,Wr)}};const yb=r=>({type:"table",key:r}),gb=Object.freeze(Object.defineProperty({__proto__:null,Client:tc,keyZ:ht,newZ:ec,ontologyID:yb,remoteZ:ts,tableZ:es},Symbol.toStringTag,{value:"Module"})),Bs="/workspace/retrieve",pb="/workspace/create",mb="/workspace/rename",wb="/workspace/set-layout",bb="/workspace/delete",qs=s.z.object({keys:de.array().optional(),searchTerm:s.z.string().optional(),author:Ce.optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),Tb=s.z.object({workspaces:Bo.array()}),vb=s.z.object({key:de,name:s.z.string()}),Eb=s.z.object({key:de,layout:s.z.string()}),Nb=s.z.object({keys:de.array()}),Fs=s.z.object({workspaces:L(Ir)}),Ob=s.z.object({workspaces:qo.array()}),Gr=s.z.object({}),zb="sy_workspace_set",Sb="sy_workspace_delete";class rc{type="workspace";schematic;linePlot;log;table;client;constructor(e){this.client=e,this.schematic=new Qo(e),this.linePlot=new Fo(e),this.log=new Vo(e),this.table=new tc(e)}async create(e){const t=Array.isArray(e),n=await m(this.client,pb,{workspaces:v.toArray(e)},Tb,Ob);return t?n.workspaces:n.workspaces[0]}async rename(e,t){await m(this.client,mb,{key:e,name:t},vb,Gr)}async setLayout(e,t){await m(this.client,wb,{key:e,layout:JSON.stringify(t)},Eb,Gr)}async retrieve(e){let t;const n=typeof e!="string";typeof e=="string"||Array.isArray(e)?t={keys:v.toArray(e)}:t=e;const i=await m(this.client,Bs,t,qs,Fs);return n?i.workspaces:i.workspaces[0]}async retrieveByAuthor(e){return(await m(this.client,Bs,{author:e},qs,Fs)).workspaces}async delete(e){await m(this.client,bb,{keys:v.toArray(e)},Nb,Gr)}}const Ab=r=>({type:"workspace",key:r}),$b=Object.freeze(Object.defineProperty({__proto__:null,Client:rc,DELETE_CHANNEL_NAME:Sb,SET_CHANNEL_NAME:zb,keyZ:de,newZ:Bo,ontologyID:Ab,remoteZ:qo,workspaceZ:Ir},Symbol.toStringTag,{value:"Module"})),nc=s.z.object({host:s.z.string({error:"Host is required"}).min(1,"Host is required"),port:s.z.number({error:"Port is required"}).or(s.z.string({error:"Port is required"})),username:s.z.string().min(1,"Username is required"),password:s.z.string().min(1,"Password is required"),connectivityPollFrequency:E.z.default(E.seconds(30)),secure:s.z.boolean().optional().default(!1),name:s.z.string().optional(),retry:ca.breakerConfigZ.optional()});class sc extends lo{createdAt;props;ranges;channels;auth;user;access;connectivity;ontology;workspaces;labels;hardware;control;static connectivity=kt;transport;clientVersion="0.45.1";constructor(e){const t=nc.parse(e),{host:n,port:i,username:a,password:o,connectivityPollFrequency:c,secure:u,retry:l}=t,h=new Ym(new wt({host:n,port:Number(i)}),l,u);h.use(hd);let y;a!=null&&o!=null&&(y=new sg(h.unary,{username:a,password:o}),h.use(y.middleware()));const d=new Fn(new Bt(h.unary)),N=new Ha(h.unary,d);super(h.stream,h.unary,d),this.createdAt=f.now(),this.props=t,this.auth=y,this.transport=h,this.channels=new Fa(this,d,h.unary,N),this.connectivity=new kt(h.unary,c,this.clientVersion,t.name),this.control=new fo(this),this.ontology=new ja(h.unary,this);const S=new Po(this.transport.unary);this.labels=new Ro(this.transport.unary),this.ranges=new Do(this,S,this.transport.unary,d,this.labels,this.ontology),this.access=new Da(this.transport.unary),this.user=new Wa(this.transport.unary),this.workspaces=new rc(this.transport.unary);const k=new To(this.transport.unary),B=new Ao(this.transport.unary,this,this.ontology,this.ranges),x=new vo(this.transport.unary,B);this.hardware=new yo(B,x,k)}get key(){return this.createdAt.valueOf().toString()}close(){this.connectivity.stopChecking()}}const ic={host:"localhost",port:9090,username:"synnax",password:"seldon",retry:{maxRetries:4,baseInterval:E.seconds(1),scale:1.5}},Ib=r=>new sc({...ic,...r});exports.AuthError=zt;exports.Channel=cr;exports.ContiguityError=cd;exports.DataType=$;exports.Density=Y;exports.DisconnectedError=od;exports.Frame=P;exports.MultiSeries=ia;exports.MultipleFoundError=At;exports.NotFoundError=St;exports.QueryError=xe;exports.Rate=W;exports.RouteError=mn;exports.Series=ge;exports.Synnax=sc;exports.TEST_CLIENT_PROPS=ic;exports.TimeRange=M;exports.TimeSpan=E;exports.TimeStamp=f;exports.UnexpectedError=Xe;exports.ValidationError=Z;exports.access=sy;exports.channel=Iy;exports.connection=ag;exports.control=Zg;exports.createTestClient=Ib;exports.device=tp;exports.framer=Cg;exports.group=Id;exports.hardware=Pg;exports.isCalculated=It;exports.label=nm;exports.linePlot=sw;exports.log=ww;exports.ontology=qd;exports.policy=ny;exports.rack=wp;exports.ranger=qm;exports.schematic=tb;exports.synnaxPropsZ=nc;exports.table=gb;exports.task=Pp;exports.user=Ky;exports.workspace=$b;
|