@synnaxlabs/client 0.44.1 → 0.44.2
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/channel/client.d.ts +11 -4
- package/dist/channel/client.d.ts.map +1 -1
- package/dist/channel/payload.d.ts +86 -14
- package/dist/channel/payload.d.ts.map +1 -1
- package/dist/channel/writer.d.ts.map +1 -1
- package/dist/client.cjs +20 -20
- package/dist/client.js +1803 -1764
- package/dist/framer/streamer.d.ts +96 -0
- package/dist/framer/streamer.d.ts.map +1 -1
- package/dist/framer/writer.d.ts +80 -0
- package/dist/framer/writer.d.ts.map +1 -1
- package/dist/hardware/device/payload.d.ts +4 -4
- package/dist/hardware/rack/payload.d.ts +4 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/ontology/payload.d.ts +1 -0
- package/dist/ontology/payload.d.ts.map +1 -1
- package/dist/ranger/alias.d.ts +5 -1
- package/dist/ranger/alias.d.ts.map +1 -1
- package/dist/ranger/client.d.ts +5 -1
- package/dist/ranger/client.d.ts.map +1 -1
- package/dist/ranger/external.d.ts +1 -1
- package/dist/ranger/external.d.ts.map +1 -1
- package/dist/ranger/kv.d.ts +1 -0
- package/dist/ranger/kv.d.ts.map +1 -1
- package/dist/ranger/payload.d.ts +3 -7
- package/dist/ranger/payload.d.ts.map +1 -1
- package/dist/ranger/writer.d.ts +1 -1
- package/dist/testutil/client.d.ts +1 -1
- package/dist/testutil/client.d.ts.map +1 -1
- package/dist/workspace/payload.d.ts +1 -1
- package/package.json +2 -2
- package/src/access/policy/policy.spec.ts +3 -3
- package/src/channel/channel.spec.ts +2 -2
- package/src/channel/client.ts +21 -5
- package/src/channel/payload.ts +4 -4
- package/src/channel/writer.ts +4 -1
- package/src/control/state.spec.ts +2 -2
- package/src/errors.spec.ts +2 -2
- package/src/framer/adapter.spec.ts +2 -2
- package/src/framer/client.spec.ts +2 -2
- package/src/framer/deleter.spec.ts +2 -2
- package/src/framer/iterator.spec.ts +2 -2
- package/src/framer/streamer.spec.ts +2 -2
- package/src/framer/writer.spec.ts +3 -2
- package/src/hardware/device/device.spec.ts +2 -2
- package/src/hardware/rack/rack.spec.ts +2 -2
- package/src/hardware/task/task.spec.ts +2 -2
- package/src/index.ts +1 -1
- package/src/label/label.spec.ts +2 -2
- package/src/ontology/group/group.spec.ts +2 -2
- package/src/ontology/ontology.spec.ts +2 -2
- package/src/ontology/payload.ts +3 -0
- package/src/ranger/alias.ts +27 -1
- package/src/ranger/client.ts +30 -3
- package/src/ranger/external.ts +1 -9
- package/src/ranger/kv.ts +3 -0
- package/src/ranger/payload.ts +4 -2
- package/src/ranger/ranger.spec.ts +3 -3
- package/src/testutil/client.ts +1 -1
- package/src/user/user.spec.ts +2 -2
- package/src/workspace/lineplot/lineplot.spec.ts +2 -2
- package/src/workspace/log/log.spec.ts +2 -2
- package/src/workspace/schematic/schematic.spec.ts +2 -2
- package/src/workspace/table/table.spec.ts +2 -2
- package/src/workspace/workspace.spec.ts +2 -2
package/dist/client.cjs
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("zod"),Qi=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=Nr)=>{if(typeof t=="string")return r(t);if(Array.isArray(t))return t.map(o=>e(o,n));if(!or(t))return t;n=no(n);const a={},i=t;return"toJSON"in i&&typeof i.toJSON=="function"?e(i.toJSON(),n):(Object.keys(i).forEach(o=>{let c=i[o];const l=r(o);n.recursive&&(or(c)?Sn(c)||(c=e(c,n)):n.recursiveInArray&&zn(c)&&(c=[...c].map(h=>{let d=h;return or(h)?Sn(d)||(d=e(h,n)):zn(h)&&(d=e({key:h},n).key),d}))),a[l]=c}),a)};return e},gs=ys(Qi),eo=r=>r.replace(/([a-z0-9])([A-Z])/g,(e,t,n)=>`${t}_${n.toLowerCase()}`),to=ys(eo),ro=[Number,String,Uint8Array],Nr={recursive:!0,recursiveInArray:!0},no=(r=Nr)=>(r.recursive==null?r=Nr:r.recursiveInArray??=!1,r),zn=r=>r!=null&&Array.isArray(r),or=r=>r!=null&&typeof r=="object"&&!Array.isArray(r),Sn=r=>ro.some(e=>r instanceof e);let so=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=gs(t);return e!=null?e.parse(n):n}encodeString(r){const e=to(r);return JSON.stringify(e,(t,n)=>ArrayBuffer.isView(n)?Array.from(n):typeof n=="bigint"?n.toString():n)}};const zr=new so;let _e=class{value;constructor(e){this.value=e}valueOf(){return this.value}toJSON(){return this.value}toString(){return this.value.toString()}};const ao=r=>r!=null&&typeof r=="object"&&"toString"in r,io=(r,e=!1)=>{const t=ao(r)?"stringer":typeof r;let n;switch(t){case"string":n=(a,i)=>a.localeCompare(i);break;case"stringer":n=(a,i)=>a.toString().localeCompare(i.toString());break;case"number":n=(a,i)=>Number(a)-Number(i);break;case"bigint":n=(a,i)=>BigInt(a)-BigInt(i)>0n?1:-1;break;case"boolean":n=(a,i)=>Number(a)-Number(i);break;case"undefined":n=()=>0;break;default:return console.warn(`sortFunc: unknown type ${t}`),()=>-1}return e?oo(n):n},oo=r=>(e,t)=>r(t,e),Vt=s.z.tuple([s.z.number(),s.z.number()]);s.z.tuple([s.z.bigint(),s.z.bigint()]);const ps=s.z.object({width:s.z.number(),height:s.z.number()}),co=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()}),lo=["width","height"];s.z.enum(lo);const uo=["start","center","end"],ho=["signedWidth","signedHeight"];s.z.enum(ho);const Bt=s.z.object({x:s.z.number(),y:s.z.number()}),fo=s.z.object({clientX:s.z.number(),clientY:s.z.number()}),yo=["x","y"],ms=s.z.enum(yo),ws=["top","right","bottom","left"];s.z.enum(ws);const go=["left","right"],bs=s.z.enum(go),po=["top","bottom"],Ts=s.z.enum(po),vs=["center"],In=s.z.enum(vs),mo=[...ws,...vs],Es=s.z.enum(mo);s.z.enum(uo);const wo=["first","last"];s.z.enum(wo);const bo=s.z.object({lower:s.z.number(),upper:s.z.number()}),To=s.z.object({lower:s.z.bigint(),upper:s.z.bigint()});s.z.union([bo,Vt]);s.z.union([To,Vt]);s.z.enum([...ms.options,...Es.options]);s.z.union([ms,Es,s.z.instanceof(String)]);const xe=(r,e)=>typeof r=="bigint"?r*BigInt(e):r*Number(e),Ie=(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?vo(n):n},vo=r=>r.lower>r.upper?{lower:r.upper,upper:r.lower}:r,An=(r,e)=>{const t=Ie(r);return e<t.lower?t.lower:e>=t.upper?t.upper-(typeof t.upper=="number"?1:1n):e};s.z.object({x:bs.or(In),y:Ts.or(In)});const Eo=s.z.object({x:bs,y:Ts}),Oo=Object.freeze({x:"left",y:"top"}),No=(r,e)=>r.x===e.x&&r.y===e.y,$n=s.z.union([s.z.number(),Bt,Vt,ps,co,fo]),zo=(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}},kn=Object.freeze({x:0,y:0}),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:Bt,two:Bt,root:Eo});const _r=(r,e,t=0,n=0,a)=>{const i={one:{...kn},two:{...kn},root:a??Oo};if(typeof r=="number"){if(typeof e!="number")throw new Error("Box constructor called with invalid arguments");return i.one={x:r,y:e},i.two={x:i.one.x+t,y:i.one.y+n},i}return"one"in r&&"two"in r&&"root"in r?{...r,root:a??r.root}:("getBoundingClientRect"in r&&(r=r.getBoundingClientRect()),"left"in r?(i.one={x:r.left,y:r.top},i.two={x:r.right,y:r.bottom},i):(i.one=r,e==null?i.two={x:i.one.x+t,y:i.one.y+n}:typeof e=="number"?i.two={x:i.one.x+e,y:i.one.y+t}:"width"in e?i.two={x:i.one.x+e.width,y:i.one.y+e.height}:"signedWidth"in e?i.two={x:i.one.x+e.signedWidth,y:i.one.y+e.signedHeight}:i.two=e,i))},cr=r=>{const e=_r(r);return{lower:e.one.x,upper:e.two.x}},lr=r=>{const e=_r(r);return{lower:e.one.y,upper:e.two.y}},So=r=>typeof r!="object"||r==null?!1:"one"in r&&"two"in r&&"root"in r,Io=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()});s.z.union([ps,Io,Bt,Vt]);const Ao=(r,e,t)=>e!==void 0&&r<e?e:t!==void 0&&r>t?t:r;s.z.object({offset:$n,scale:$n});s.z.object({offset:s.z.number(),scale:s.z.number()});const $o=r=>(e,t,n,a)=>t==="dimension"?[e,n]:[e,a?n-r:n+r],ko=r=>(e,t,n,a)=>[e,a?n/r:n*r],Co=r=>(e,t,n)=>{if(e===null)return[r,n];const{lower:a,upper:i}=e,{lower:o,upper:c}=r,l=i-a,h=c-o;if(t==="dimension")return[r,n*(h/l)];const d=(n-a)*(h/l)+o;return[r,d]},xo=r=>(e,t,n)=>[r,n],Ro=()=>(r,e,t)=>{if(r===null)throw new Error("cannot invert without bounds");if(e==="dimension")return[r,t];const{lower:n,upper:a}=r;return[r,a-(t-n)]},jo=r=>(e,t,n)=>{const{lower:a,upper:i}=r;return n=Ao(n,a,i),[e,n]};let Cn=class je{ops=[];currBounds=null;currType=null;reversed=!1;constructor(){this.ops=[]}static translate(e){return new je().translate(e)}static magnify(e){return new je().magnify(e)}static scale(e,t){return new je().scale(e,t)}translate(e){const t=this.new(),n=$o(e);return n.type="translate",t.ops.push(n),t}magnify(e){const t=this.new(),n=ko(e);return n.type="magnify",t.ops.push(n),t}scale(e,t){const n=Ie(e,t),a=this.new(),i=Co(n);return i.type="scale",a.ops.push(i),a}clamp(e,t){const n=Ie(e,t),a=this.new(),i=jo(n);return i.type="clamp",a.ops.push(i),a}reBound(e,t){const n=Ie(e,t),a=this.new(),i=xo(n);return i.type="re-bound",a.ops.push(i),a}invert(){const e=Ro();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 je;return e.ops=this.ops.slice(),e.reversed=this.reversed,e}exec(e,t){return this.currBounds=null,this.ops.reduce(([n,a],i)=>i(n,e,a,this.reversed),[null,t])[1]}reverse(){const e=this.new();e.ops.reverse();const t=[];return e.ops.forEach((n,a)=>{if(n.type==="scale"||t.some(([o,c])=>a>=o&&a<=c))return;const i=e.ops.findIndex((o,c)=>o.type==="scale"&&c>a);i!==-1&&t.push([a,i])}),t.forEach(([n,a])=>{const i=e.ops.slice(n,a);i.unshift(e.ops[a]),e.ops.splice(n,a-n+1,...i)}),e.reversed=!e.reversed,e}get transform(){return{scale:this.dim(1),offset:this.pos(0)}}static IDENTITY=new je};(class Q{x;y;currRoot;constructor(e=new Cn,t=new Cn,n=null){this.x=e,this.y=t,this.currRoot=n}static translate(e,t){return new Q().translate(e,t)}static translateX(e){return new Q().translateX(e)}static translateY(e){return new Q().translateY(e)}static clamp(e){return new Q().clamp(e)}static magnify(e){return new Q().magnify(e)}static scale(e){return new Q().scale(e)}static reBound(e){return new Q().reBound(e)}translate(e,t){const n=zo(e,t),a=this.copy();return a.x=this.x.translate(n.x),a.y=this.y.translate(n.y),a}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(So(e)){const n=this.currRoot;return t.currRoot=e.root,n!=null&&!No(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(cr(e)),t.y=t.y.scale(lr(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(cr(e)),t.y=this.y.reBound(lr(e)),t}clamp(e){const t=this.copy();return t.x=this.x.clamp(cr(e)),t.y=this.y.clamp(lr(e)),t}copy(){const e=new Q;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 _r(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 Q});let Uo=(r,e=21)=>(t=e)=>{let n="",a=t|0;for(;a--;)n+=r[Math.random()*r.length|0];return n};const Do="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",Mo=11,Zo=Uo(Do,Mo),Po=()=>Zo(),Lo=(r,e)=>t=>t instanceof e||typeof t=="object"&&t!==null&&"discriminator"in t&&t.discriminator===r,Bo=s.z.enum(["static","dynamic"]),qo=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)])]),Os=(r,e)=>{const t=new $(e);if(![A.DAY,A.HOUR,A.MINUTE,A.SECOND,A.MILLISECOND,A.MICROSECOND,A.NANOSECOND].some(a=>a.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 $?new $(n):new A(n)};let $=class p extends _e{constructor(e,t="UTC"){if(e==null)super(p.now().valueOf());else if(e instanceof Date)super(BigInt(e.getTime())*p.MILLISECOND.valueOf());else if(typeof e=="string")super(p.parseDateTimeString(e,t).valueOf());else if(Array.isArray(e))super(p.parseDate(e));else{let n=0n;e instanceof Number&&(e=e.valueOf()),t==="local"&&(n=p.utcOffset.valueOf()),typeof e=="number"&&(isFinite(e)?e=Math.trunc(e):(isNaN(e)&&(e=0),e===1/0?e=p.MAX:e=p.MIN)),super(BigInt(e.valueOf())+n)}}static parseDate([e=1970,t=1,n=1]){const a=new Date(e,t-1,n,0,0,0,0);return new p(BigInt(a.getTime())*p.MILLISECOND.valueOf()).truncate(p.DAY).valueOf()}valueOf(){return this.value}static parseTimeString(e,t="UTC"){const[n,a,i]=e.split(":");let o="00",c="00";i!=null&&([o,c]=i.split("."));let l=p.hours(parseInt(n??"00")).add(p.minutes(parseInt(a??"00"))).add(p.seconds(parseInt(o??"00"))).add(p.milliseconds(parseInt(c??"00")));return t==="local"&&(l=l.add(p.utcOffset)),l.valueOf()}static parseDateTimeString(e,t="UTC"){if(!e.includes("/")&&!e.includes("-"))return p.parseTimeString(e,t);const n=new Date(e);return e.includes(":")||n.setUTCHours(0,0,0,0),new p(BigInt(n.getTime())*p.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(p.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())*p.MINUTE.valueOf())}static since(e){return new p().span(e)}date(){return new Date(this.milliseconds)}equals(e){return this.valueOf()===new p(e).valueOf()}span(e){return this.range(e).span}range(e){return new st(this,e).makeValid()}spanRange(e){return this.range(this.add(e)).makeValid()}get isZero(){return this.valueOf()===0n}after(e){return this.valueOf()>new p(e).valueOf()}afterEq(e){return this.valueOf()>=new p(e).valueOf()}before(e){return this.valueOf()<new p(e).valueOf()}beforeEq(e){return this.valueOf()<=new p(e).valueOf()}add(e){return new p(this.valueOf()+BigInt(e.valueOf()))}sub(e){return new p(this.valueOf()-BigInt(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(p.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(p.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 p(t)}get month(){return this.date().getUTCMonth()}setMonth(e){const t=this.date();return t.setUTCMonth(e),new p(t)}get day(){return this.date().getUTCDate()}setDay(e){const t=this.date();return t.setUTCDate(e),new p(t)}get hour(){return this.date().getUTCHours()}setHour(e){const t=this.date();return t.setUTCHours(e),new p(t,"UTC")}get minute(){return this.date().getUTCMinutes()}setMinute(e){const t=this.date();return t.setUTCMinutes(e),new p(t)}get second(){return this.date().getUTCSeconds()}setSecond(e){const t=this.date();return t.setUTCSeconds(e),new p(t)}get millisecond(){return this.date().getUTCMilliseconds()}setMillisecond(e){const t=this.date();return t.setUTCMilliseconds(e),new p(t)}toString(){return this.date().toISOString()}remainder(e){return Os(this,e)}get isToday(){return this.truncate(A.DAY).equals(p.now().truncate(A.DAY))}truncate(e){return this.sub(this.remainder(e))}static now(){return new p(new Date)}static max(...e){let t=p.MIN;for(const n of e){const a=new p(n);a.after(t)&&(t=a)}return t}static min(...e){let t=p.MAX;for(const n of e){const a=new p(n);a.before(t)&&(t=a)}return t}static nanoseconds(e,t="UTC"){return new p(e,t)}static NANOSECOND=p.nanoseconds(1);static microseconds(e,t="UTC"){return p.nanoseconds(e*1e3,t)}static MICROSECOND=p.microseconds(1);static milliseconds(e,t="UTC"){return p.microseconds(e*1e3,t)}static MILLISECOND=p.milliseconds(1);static seconds(e,t="UTC"){return p.milliseconds(e*1e3,t)}static SECOND=p.seconds(1);static minutes(e,t="UTC"){return p.seconds(e*60,t)}static MINUTE=p.minutes(1);static hours(e,t="UTC"){return p.minutes(e*60,t)}static HOUR=p.hours(1);static days(e,t="UTC"){return p.hours(e*24,t)}static DAY=p.days(1);static MAX=new p((1n<<63n)-1n);static MIN=new p(0);static ZERO=new p(0);static z=s.z.union([s.z.instanceof(p),s.z.object({value:s.z.bigint()}).transform(e=>new p(e.value)),s.z.string().transform(e=>new p(BigInt(e))),s.z.number().transform(e=>new p(e)),s.z.bigint().transform(e=>new p(e)),s.z.date().transform(e=>new p(e)),s.z.custom(e=>e instanceof A).transform(e=>new p(e)),qo.transform(e=>new p(e))]);static sort(e,t){return Number(e.valueOf()-t.valueOf())}},A=class w extends _e{constructor(e){typeof e=="number"&&(e=Math.trunc(e.valueOf())),super(BigInt(e.valueOf()))}static fromSeconds(e){return e instanceof w?e:e instanceof xn?e.period:e instanceof $?new w(e):["number","bigint"].includes(typeof e)?w.seconds(e):new w(e)}static fromMilliseconds(e){return e instanceof w?e:e instanceof xn?e.period:e instanceof $?new w(e):["number","bigint"].includes(typeof e)?w.milliseconds(e):new w(e)}valueOf(){return this.value}lessThan(e){return this.valueOf()<new w(e).valueOf()}greaterThan(e){return this.valueOf()>new w(e).valueOf()}lessThanOrEqual(e){return this.valueOf()<=new w(e).valueOf()}greaterThanOrEqual(e){return this.valueOf()>=new w(e).valueOf()}remainder(e){return Os(this,e)}truncate(e){return new w(BigInt(Math.trunc(Number(this.valueOf()/e.valueOf())))*e.valueOf())}toString(){const e=this.truncate(w.DAY),t=this.truncate(w.HOUR),n=this.truncate(w.MINUTE),a=this.truncate(w.SECOND),i=this.truncate(w.MILLISECOND),o=this.truncate(w.MICROSECOND),c=this.truncate(w.NANOSECOND),l=e,h=t.sub(e),d=n.sub(t),u=a.sub(n),N=i.sub(a),E=o.sub(i),P=c.sub(o);let k="";return l.isZero||(k+=`${l.days}d `),h.isZero||(k+=`${h.hours}h `),d.isZero||(k+=`${d.minutes}m `),u.isZero||(k+=`${u.seconds}s `),N.isZero||(k+=`${N.milliseconds}ms `),E.isZero||(k+=`${E.microseconds}µs `),P.isZero||(k+=`${P.nanoseconds}ns`),k.trim()}mult(e){return new w(this.valueOf()*BigInt(e))}get days(){return Number(this.valueOf())/Number(w.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(w.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(w.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(w.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 isZero(){return this.valueOf()===0n}equals(e){return this.valueOf()===new w(e).valueOf()}add(e){return new w(this.valueOf()+new w(e).valueOf())}sub(e){return new w(this.valueOf()-new w(e).valueOf())}static nanoseconds(e=1){return new w(e)}static NANOSECOND=w.nanoseconds(1);static microseconds(e=1){return w.nanoseconds(xe(e,1e3))}static MICROSECOND=w.microseconds(1);static milliseconds(e=1){return w.microseconds(xe(e,1e3))}static MILLISECOND=w.milliseconds(1);static seconds(e=1){return w.milliseconds(xe(e,1e3))}static SECOND=w.seconds(1);static minutes(e=1){return w.seconds(xe(e,60))}static MINUTE=w.minutes(1);static hours(e){return w.minutes(xe(e,60))}static HOUR=w.hours(1);static days(e){return w.hours(xe(e,24))}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.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.instanceof(w)])},xn=class Ue extends _e{constructor(e){super(e.valueOf())}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new Ue(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 H(t).valueOf()}span(e){return A.seconds(e/this.valueOf())}byteSpan(e,t){return this.span(e.valueOf()/t.valueOf())}static hz(e){return new Ue(e)}static khz(e){return Ue.hz(e*1e3)}static z=s.z.union([s.z.number().transform(e=>new Ue(e)),s.z.instanceof(Ue)])},H=class ie extends _e{constructor(e){super(e.valueOf())}length(e){return e.valueOf()/this.valueOf()}size(e){return new Sr(e*this.valueOf())}static UNKNOWN=new ie(0);static BIT128=new ie(16);static BIT64=new ie(8);static BIT32=new ie(4);static BIT16=new ie(2);static BIT8=new ie(1);static z=s.z.union([s.z.number().transform(e=>new ie(e)),s.z.instanceof(ie)])},st=class ee{start;end;constructor(e,t){typeof e=="object"&&"start"in e?(this.start=new $(e.start),this.end=new $(e.end)):(this.start=new $(e),this.end=new $(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 ee(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(),a=this.end.sub(e.end).valueOf();return n<0&&(n=-n),a<0&&(a=-a),n<=t.valueOf()&&a<=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 a=$.max(n.start,e.start),i=$.min(n.end,e.end);return i.before(a)?!1:new A(i.sub(a)).greaterThanOrEqual(t)}contains(e){return e instanceof ee?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const t=new ee(this.start,this.end);return e.start.after(this.start)&&(t.start=e.start),e.start.after(this.end)&&(t.end=e.start),e.end.before(this.end)&&(t.end=e.end),e.end.before(this.start)&&(t.start=e.end),t}static max(...e){return new ee($.min(...e.map(t=>t.start)),$.max(...e.map(t=>t.end)))}static MAX=new ee($.MIN,$.MAX);static MIN=new ee($.MAX,$.MIN);static ZERO=new ee($.ZERO,$.ZERO);static z=s.z.union([s.z.object({start:$.z,end:$.z}).transform(e=>new ee(e.start,e.end)),s.z.instanceof(ee)]);static sort(e,t){return $.sort(e.start,t.start)||$.sort(e.end,t.end)}},j=class f extends _e{constructor(e){if(e instanceof f||typeof e=="string"||typeof e.valueOf()=="string")super(e.valueOf());else{const t=f.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=f.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(f.JSON)||this.equals(f.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(f.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=f.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}get isUnsignedInteger(){return this.equals(f.UINT8)||this.equals(f.UINT16)||this.equals(f.UINT32)||this.equals(f.UINT64)}get isSignedInteger(){return this.equals(f.INT8)||this.equals(f.INT16)||this.equals(f.INT32)||this.equals(f.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(f.INT32)&&e.equals(f.FLOAT64)||this.equals(f.INT8)&&e.equals(f.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 f.BIG_INT_TYPES.some(e=>e.equals(this))}static UNKNOWN=new f("unknown");static FLOAT64=new f("float64");static FLOAT32=new f("float32");static INT64=new f("int64");static INT32=new f("int32");static INT16=new f("int16");static INT8=new f("int8");static UINT64=new f("uint64");static UINT32=new f("uint32");static UINT16=new f("uint16");static UINT8=new f("uint8");static BOOLEAN=this.UINT8;static TIMESTAMP=new f("timestamp");static UUID=new f("uuid");static STRING=new f("string");static JSON=new f("json");static ARRAY_CONSTRUCTORS=new Map([[f.UINT8.toString(),Uint8Array],[f.UINT16.toString(),Uint16Array],[f.UINT32.toString(),Uint32Array],[f.UINT64.toString(),BigUint64Array],[f.FLOAT32.toString(),Float32Array],[f.FLOAT64.toString(),Float64Array],[f.INT8.toString(),Int8Array],[f.INT16.toString(),Int16Array],[f.INT32.toString(),Int32Array],[f.INT64.toString(),BigInt64Array],[f.TIMESTAMP.toString(),BigInt64Array],[f.STRING.toString(),Uint8Array],[f.JSON.toString(),Uint8Array],[f.UUID.toString(),Uint8Array]]);static ARRAY_CONSTRUCTOR_DATA_TYPES=new Map([[Uint8Array.name,f.UINT8],[Uint16Array.name,f.UINT16],[Uint32Array.name,f.UINT32],[BigUint64Array.name,f.UINT64],[Float32Array.name,f.FLOAT32],[Float64Array.name,f.FLOAT64],[Int8Array.name,f.INT8],[Int16Array.name,f.INT16],[Int32Array.name,f.INT32],[BigInt64Array.name,f.INT64]]);static DENSITIES=new Map([[f.UINT8.toString(),H.BIT8],[f.UINT16.toString(),H.BIT16],[f.UINT32.toString(),H.BIT32],[f.UINT64.toString(),H.BIT64],[f.FLOAT32.toString(),H.BIT32],[f.FLOAT64.toString(),H.BIT64],[f.INT8.toString(),H.BIT8],[f.INT16.toString(),H.BIT16],[f.INT32.toString(),H.BIT32],[f.INT64.toString(),H.BIT64],[f.TIMESTAMP.toString(),H.BIT64],[f.STRING.toString(),H.UNKNOWN],[f.JSON.toString(),H.UNKNOWN],[f.UUID.toString(),H.BIT128]]);static ALL=[f.UNKNOWN,f.FLOAT64,f.FLOAT32,f.INT64,f.INT32,f.INT16,f.INT8,f.UINT64,f.UINT32,f.UINT16,f.UINT8,f.TIMESTAMP,f.UUID,f.STRING,f.JSON];static BIG_INT_TYPES=[f.INT64,f.UINT64,f.TIMESTAMP];static z=s.z.union([s.z.string().transform(e=>new f(e)),s.z.instanceof(f)])},Sr=class x extends _e{constructor(e){super(e.valueOf())}largerThan(e){return this.valueOf()>e.valueOf()}smallerThan(e){return this.valueOf()<e.valueOf()}add(e){return x.bytes(this.valueOf()+e.valueOf())}sub(e){return x.bytes(this.valueOf()-e.valueOf())}truncate(e){return new x(Math.trunc(this.valueOf()/e.valueOf())*e.valueOf())}remainder(e){return x.bytes(this.valueOf()%e.valueOf())}get gigabytes(){return this.valueOf()/x.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/x.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/x.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/x.TERABYTE.valueOf()}toString(){const e=this.truncate(x.TERABYTE),t=this.truncate(x.GIGABYTE),n=this.truncate(x.MEGABYTE),a=this.truncate(x.KILOBYTE),i=this.truncate(x.BYTE),o=e,c=t.sub(e),l=n.sub(t),h=a.sub(n),d=i.sub(a);let u="";return o.isZero||(u+=`${o.terabytes}TB `),c.isZero||(u+=`${c.gigabytes}GB `),l.isZero||(u+=`${l.megabytes}MB `),h.isZero||(u+=`${h.kilobytes}KB `),(!d.isZero||u==="")&&(u+=`${d.valueOf()}B`),u.trim()}static bytes(e=1){return new x(e)}static BYTE=new x(1);static kilobytes(e=1){return x.bytes(e.valueOf()*1e3)}static KILOBYTE=x.kilobytes(1);static megabytes(e=1){return x.kilobytes(e.valueOf()*1e3)}static MEGABYTE=x.megabytes(1);static gigabytes(e=1){return x.megabytes(e.valueOf()*1e3)}static GIGABYTE=x.gigabytes(1);static terabytes(e){return x.gigabytes(e.valueOf()*1e3)}static TERABYTE=x.terabytes(1);static ZERO=new x(0);static z=s.z.union([s.z.number().transform(e=>new x(e)),s.z.instanceof(x)]);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 Ns=r=>{const e=typeof r;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||r instanceof $||r instanceof A||r instanceof Date},Fo=(r,e,t,n=0)=>r.usesBigInt&&!e.usesBigInt?Number(t)-Number(n):!r.usesBigInt&&e.usesBigInt?BigInt(t.valueOf())-BigInt(n.valueOf()):Ut(t,-n),Ut=(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),Yo=/^(?:[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 Vo(r){return typeof r=="string"&&Yo.test(r)}const q=[];for(let r=0;r<256;++r)q.push((r+256).toString(16).slice(1));function Wo(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 _o(r,e=0){const t=Wo(r,e);if(!Vo(t))throw TypeError("Stringified UUID is invalid");return t}typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const zs=(r,e)=>_o(r,e),ye=-1,Ho=s.z.string().transform(r=>new Uint8Array(atob(r).split("").map(e=>e.charCodeAt(0))).buffer),Go=s.z.union([s.z.null(),s.z.undefined()]).transform(()=>new Uint8Array().buffer),Ir=10,Jo=(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`)},Ss="sy_x_telem_series";let Is=class we{key;discriminator=Ss;dataType;sampleOffset;gl;_data;timeRange=st.ZERO;alignment=0n;cachedMin;cachedMax;writePos=ye;_refCount=0;cachedLength;_cachedIndexes;static crudeZ=s.z.object({timeRange:st.z.optional(),dataType:j.z,alignment:s.z.coerce.bigint().optional(),data:s.z.union([Ho,Go,s.z.instanceof(ArrayBuffer),s.z.instanceof(Uint8Array)]),glBufferUsage:Bo.optional().default("static").optional()});static z=we.crudeZ.transform(e=>new we(e));constructor(e){Ko(e)&&(e={data:e}),e.data??=[];const{dataType:t,timeRange:n,sampleOffset:a=0,glBufferUsage:i="static",alignment:o=0n,key:c=Po(),data:l}=e;if(Xo(l)){const u=l;this.key=u.key,this.dataType=u.dataType,this.sampleOffset=u.sampleOffset,this.gl=u.gl,this._data=u._data,this.timeRange=u.timeRange,this.alignment=u.alignment,this.cachedMin=u.cachedMin,this.cachedMax=u.cachedMax,this.writePos=u.writePos,this._refCount=u._refCount,this.cachedLength=u.cachedLength;return}const h=Ns(l),d=Array.isArray(l);if(t!=null)this.dataType=new j(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(d||h){let u=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.");u=l[0]}if(typeof u=="string")this.dataType=j.STRING;else if(typeof u=="number")this.dataType=j.FLOAT64;else if(typeof u=="bigint")this.dataType=j.INT64;else if(typeof u=="boolean")this.dataType=j.BOOLEAN;else if(u instanceof $||u instanceof Date||u instanceof $)this.dataType=j.TIMESTAMP;else if(typeof u=="object")this.dataType=j.JSON;else throw new Error(`cannot infer data type of ${typeof u} when constructing a Series from a JS array`)}else this.dataType=new j(l)}if(!d&&!h)this._data=l;else if(d&&l.length===0)this._data=new this.dataType.Array([]).buffer;else{let u=h?[l]:l;const N=u[0];(N instanceof $||N instanceof Date||N instanceof A)&&(u=u.map(E=>new $(E).valueOf())),this.dataType.equals(j.STRING)?(this.cachedLength=u.length,this._data=new TextEncoder().encode(`${u.join(`
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("zod"),to=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=Sr)=>{if(typeof t=="string")return r(t);if(Array.isArray(t))return t.map(o=>e(o,n));if(!lr(t))return t;n=ao(n);const a={},i=t;return"toJSON"in i&&typeof i.toJSON=="function"?e(i.toJSON(),n):(Object.keys(i).forEach(o=>{let c=i[o];const l=r(o);n.recursive&&(lr(c)?Sn(c)||(c=e(c,n)):n.recursiveInArray&&zn(c)&&(c=[...c].map(h=>{let d=h;return lr(h)?Sn(d)||(d=e(h,n)):zn(h)&&(d=e({key:h},n).key),d}))),a[l]=c}),a)};return e},gs=ys(to),ro=r=>r.replace(/([a-z0-9])([A-Z])/g,(e,t,n)=>`${t}_${n.toLowerCase()}`),no=ys(ro),so=[Number,String,Uint8Array],Sr={recursive:!0,recursiveInArray:!0},ao=(r=Sr)=>(r.recursive==null?r=Sr:r.recursiveInArray??=!1,r),zn=r=>r!=null&&Array.isArray(r),lr=r=>r!=null&&typeof r=="object"&&!Array.isArray(r),Sn=r=>so.some(e=>r instanceof e);let io=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=gs(t);return e!=null?e.parse(n):n}encodeString(r){const e=no(r);return JSON.stringify(e,(t,n)=>ArrayBuffer.isView(n)?Array.from(n):typeof n=="bigint"?n.toString():n)}};const Ir=new io;let _e=class{value;constructor(e){this.value=e}valueOf(){return this.value}toJSON(){return this.value}toString(){return this.value.toString()}};const oo=r=>r!=null&&typeof r=="object"&&"toString"in r,co=(r,e=!1)=>{const t=oo(r)?"stringer":typeof r;let n;switch(t){case"string":n=(a,i)=>a.localeCompare(i);break;case"stringer":n=(a,i)=>a.toString().localeCompare(i.toString());break;case"number":n=(a,i)=>Number(a)-Number(i);break;case"bigint":n=(a,i)=>BigInt(a)-BigInt(i)>0n?1:-1;break;case"boolean":n=(a,i)=>Number(a)-Number(i);break;case"undefined":n=()=>0;break;default:return console.warn(`sortFunc: unknown type ${t}`),()=>-1}return e?lo(n):n},lo=r=>(e,t)=>r(t,e),Ht=s.z.tuple([s.z.number(),s.z.number()]);s.z.tuple([s.z.bigint(),s.z.bigint()]);const ps=s.z.object({width:s.z.number(),height:s.z.number()}),uo=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()}),ho=["width","height"];s.z.enum(ho);const fo=["start","center","end"],yo=["signedWidth","signedHeight"];s.z.enum(yo);const Ft=s.z.object({x:s.z.number(),y:s.z.number()}),go=s.z.object({clientX:s.z.number(),clientY:s.z.number()}),po=["x","y"],ms=s.z.enum(po),ws=["top","right","bottom","left"];s.z.enum(ws);const mo=["left","right"],bs=s.z.enum(mo),wo=["top","bottom"],Ts=s.z.enum(wo),vs=["center"],In=s.z.enum(vs),bo=[...ws,...vs],Es=s.z.enum(bo);s.z.enum(fo);const To=["first","last"];s.z.enum(To);const vo=s.z.object({lower:s.z.number(),upper:s.z.number()}),Eo=s.z.object({lower:s.z.bigint(),upper:s.z.bigint()});s.z.union([vo,Ht]);s.z.union([Eo,Ht]);s.z.enum([...ms.options,...Es.options]);s.z.union([ms,Es,s.z.instanceof(String)]);const Re=(r,e)=>typeof r=="bigint"?r*BigInt(e):r*Number(e),Ae=(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?Oo(n):n},Oo=r=>r.lower>r.upper?{lower:r.upper,upper:r.lower}:r,An=(r,e)=>{const t=Ae(r);return e<t.lower?t.lower:e>=t.upper?t.upper-(typeof t.upper=="number"?1:1n):e};s.z.object({x:bs.or(In),y:Ts.or(In)});const No=s.z.object({x:bs,y:Ts}),zo=Object.freeze({x:"left",y:"top"}),So=(r,e)=>r.x===e.x&&r.y===e.y,$n=s.z.union([s.z.number(),Ft,Ht,ps,uo,go]),Io=(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}},kn=Object.freeze({x:0,y:0}),xt=s.z.union([s.z.number(),s.z.string()]);s.z.object({top:xt,left:xt,width:xt,height:xt});s.z.object({left:s.z.number(),top:s.z.number(),right:s.z.number(),bottom:s.z.number()});s.z.object({one:Ft,two:Ft,root:No});const Gr=(r,e,t=0,n=0,a)=>{const i={one:{...kn},two:{...kn},root:a??zo};if(typeof r=="number"){if(typeof e!="number")throw new Error("Box constructor called with invalid arguments");return i.one={x:r,y:e},i.two={x:i.one.x+t,y:i.one.y+n},i}return"one"in r&&"two"in r&&"root"in r?{...r,root:a??r.root}:("getBoundingClientRect"in r&&(r=r.getBoundingClientRect()),"left"in r?(i.one={x:r.left,y:r.top},i.two={x:r.right,y:r.bottom},i):(i.one=r,e==null?i.two={x:i.one.x+t,y:i.one.y+n}:typeof e=="number"?i.two={x:i.one.x+e,y:i.one.y+t}:"width"in e?i.two={x:i.one.x+e.width,y:i.one.y+e.height}:"signedWidth"in e?i.two={x:i.one.x+e.signedWidth,y:i.one.y+e.signedHeight}:i.two=e,i))},ur=r=>{const e=Gr(r);return{lower:e.one.x,upper:e.two.x}},hr=r=>{const e=Gr(r);return{lower:e.one.y,upper:e.two.y}},Ao=r=>typeof r!="object"||r==null?!1:"one"in r&&"two"in r&&"root"in r,$o=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()});s.z.union([ps,$o,Ft,Ht]);const ko=(r,e,t)=>e!==void 0&&r<e?e:t!==void 0&&r>t?t:r;s.z.object({offset:$n,scale:$n});s.z.object({offset:s.z.number(),scale:s.z.number()});const Co=r=>(e,t,n,a)=>t==="dimension"?[e,n]:[e,a?n-r:n+r],xo=r=>(e,t,n,a)=>[e,a?n/r:n*r],Ro=r=>(e,t,n)=>{if(e===null)return[r,n];const{lower:a,upper:i}=e,{lower:o,upper:c}=r,l=i-a,h=c-o;if(t==="dimension")return[r,n*(h/l)];const d=(n-a)*(h/l)+o;return[r,d]},jo=r=>(e,t,n)=>[r,n],Uo=()=>(r,e,t)=>{if(r===null)throw new Error("cannot invert without bounds");if(e==="dimension")return[r,t];const{lower:n,upper:a}=r;return[r,a-(t-n)]},Do=r=>(e,t,n)=>{const{lower:a,upper:i}=r;return n=ko(n,a,i),[e,n]};let Cn=class Ue{ops=[];currBounds=null;currType=null;reversed=!1;constructor(){this.ops=[]}static translate(e){return new Ue().translate(e)}static magnify(e){return new Ue().magnify(e)}static scale(e,t){return new Ue().scale(e,t)}translate(e){const t=this.new(),n=Co(e);return n.type="translate",t.ops.push(n),t}magnify(e){const t=this.new(),n=xo(e);return n.type="magnify",t.ops.push(n),t}scale(e,t){const n=Ae(e,t),a=this.new(),i=Ro(n);return i.type="scale",a.ops.push(i),a}clamp(e,t){const n=Ae(e,t),a=this.new(),i=Do(n);return i.type="clamp",a.ops.push(i),a}reBound(e,t){const n=Ae(e,t),a=this.new(),i=jo(n);return i.type="re-bound",a.ops.push(i),a}invert(){const e=Uo();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 Ue;return e.ops=this.ops.slice(),e.reversed=this.reversed,e}exec(e,t){return this.currBounds=null,this.ops.reduce(([n,a],i)=>i(n,e,a,this.reversed),[null,t])[1]}reverse(){const e=this.new();e.ops.reverse();const t=[];return e.ops.forEach((n,a)=>{if(n.type==="scale"||t.some(([o,c])=>a>=o&&a<=c))return;const i=e.ops.findIndex((o,c)=>o.type==="scale"&&c>a);i!==-1&&t.push([a,i])}),t.forEach(([n,a])=>{const i=e.ops.slice(n,a);i.unshift(e.ops[a]),e.ops.splice(n,a-n+1,...i)}),e.reversed=!e.reversed,e}get transform(){return{scale:this.dim(1),offset:this.pos(0)}}static IDENTITY=new Ue};(class ee{x;y;currRoot;constructor(e=new Cn,t=new Cn,n=null){this.x=e,this.y=t,this.currRoot=n}static translate(e,t){return new ee().translate(e,t)}static translateX(e){return new ee().translateX(e)}static translateY(e){return new ee().translateY(e)}static clamp(e){return new ee().clamp(e)}static magnify(e){return new ee().magnify(e)}static scale(e){return new ee().scale(e)}static reBound(e){return new ee().reBound(e)}translate(e,t){const n=Io(e,t),a=this.copy();return a.x=this.x.translate(n.x),a.y=this.y.translate(n.y),a}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(Ao(e)){const n=this.currRoot;return t.currRoot=e.root,n!=null&&!So(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(ur(e)),t.y=t.y.scale(hr(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(ur(e)),t.y=this.y.reBound(hr(e)),t}clamp(e){const t=this.copy();return t.x=this.x.clamp(ur(e)),t.y=this.y.clamp(hr(e)),t}copy(){const e=new ee;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 Gr(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 ee});let Mo=(r,e=21)=>(t=e)=>{let n="",a=t|0;for(;a--;)n+=r[Math.random()*r.length|0];return n};const Zo="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",Po=11,Lo=Mo(Zo,Po),Bo=()=>Lo(),qo=(r,e)=>t=>t instanceof e||typeof t=="object"&&t!==null&&"discriminator"in t&&t.discriminator===r,Fo=s.z.enum(["static","dynamic"]),Yo=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)])]),Os=(r,e)=>{const t=new $(e);if(![A.DAY,A.HOUR,A.MINUTE,A.SECOND,A.MILLISECOND,A.MICROSECOND,A.NANOSECOND].some(a=>a.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 $?new $(n):new A(n)};let $=class p extends _e{constructor(e,t="UTC"){if(e==null)super(p.now().valueOf());else if(e instanceof Date)super(BigInt(e.getTime())*p.MILLISECOND.valueOf());else if(typeof e=="string")super(p.parseDateTimeString(e,t).valueOf());else if(Array.isArray(e))super(p.parseDate(e));else{let n=0n;e instanceof Number&&(e=e.valueOf()),t==="local"&&(n=p.utcOffset.valueOf()),typeof e=="number"&&(isFinite(e)?e=Math.trunc(e):(isNaN(e)&&(e=0),e===1/0?e=p.MAX:e=p.MIN)),super(BigInt(e.valueOf())+n)}}static parseDate([e=1970,t=1,n=1]){const a=new Date(e,t-1,n,0,0,0,0);return new p(BigInt(a.getTime())*p.MILLISECOND.valueOf()).truncate(p.DAY).valueOf()}valueOf(){return this.value}static parseTimeString(e,t="UTC"){const[n,a,i]=e.split(":");let o="00",c="00";i!=null&&([o,c]=i.split("."));let l=p.hours(parseInt(n??"00")).add(p.minutes(parseInt(a??"00"))).add(p.seconds(parseInt(o??"00"))).add(p.milliseconds(parseInt(c??"00")));return t==="local"&&(l=l.add(p.utcOffset)),l.valueOf()}static parseDateTimeString(e,t="UTC"){if(!e.includes("/")&&!e.includes("-"))return p.parseTimeString(e,t);const n=new Date(e);return e.includes(":")||n.setUTCHours(0,0,0,0),new p(BigInt(n.getTime())*p.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(p.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())*p.MINUTE.valueOf())}static since(e){return new p().span(e)}date(){return new Date(this.milliseconds)}equals(e){return this.valueOf()===new p(e).valueOf()}span(e){return this.range(e).span}range(e){return new st(this,e).makeValid()}spanRange(e){return this.range(this.add(e)).makeValid()}get isZero(){return this.valueOf()===0n}after(e){return this.valueOf()>new p(e).valueOf()}afterEq(e){return this.valueOf()>=new p(e).valueOf()}before(e){return this.valueOf()<new p(e).valueOf()}beforeEq(e){return this.valueOf()<=new p(e).valueOf()}add(e){return new p(this.valueOf()+BigInt(e.valueOf()))}sub(e){return new p(this.valueOf()-BigInt(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(p.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(p.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 p(t)}get month(){return this.date().getUTCMonth()}setMonth(e){const t=this.date();return t.setUTCMonth(e),new p(t)}get day(){return this.date().getUTCDate()}setDay(e){const t=this.date();return t.setUTCDate(e),new p(t)}get hour(){return this.date().getUTCHours()}setHour(e){const t=this.date();return t.setUTCHours(e),new p(t,"UTC")}get minute(){return this.date().getUTCMinutes()}setMinute(e){const t=this.date();return t.setUTCMinutes(e),new p(t)}get second(){return this.date().getUTCSeconds()}setSecond(e){const t=this.date();return t.setUTCSeconds(e),new p(t)}get millisecond(){return this.date().getUTCMilliseconds()}setMillisecond(e){const t=this.date();return t.setUTCMilliseconds(e),new p(t)}toString(){return this.date().toISOString()}remainder(e){return Os(this,e)}get isToday(){return this.truncate(A.DAY).equals(p.now().truncate(A.DAY))}truncate(e){return this.sub(this.remainder(e))}static now(){return new p(new Date)}static max(...e){let t=p.MIN;for(const n of e){const a=new p(n);a.after(t)&&(t=a)}return t}static min(...e){let t=p.MAX;for(const n of e){const a=new p(n);a.before(t)&&(t=a)}return t}static nanoseconds(e,t="UTC"){return new p(e,t)}static NANOSECOND=p.nanoseconds(1);static microseconds(e,t="UTC"){return p.nanoseconds(e*1e3,t)}static MICROSECOND=p.microseconds(1);static milliseconds(e,t="UTC"){return p.microseconds(e*1e3,t)}static MILLISECOND=p.milliseconds(1);static seconds(e,t="UTC"){return p.milliseconds(e*1e3,t)}static SECOND=p.seconds(1);static minutes(e,t="UTC"){return p.seconds(e*60,t)}static MINUTE=p.minutes(1);static hours(e,t="UTC"){return p.minutes(e*60,t)}static HOUR=p.hours(1);static days(e,t="UTC"){return p.hours(e*24,t)}static DAY=p.days(1);static MAX=new p((1n<<63n)-1n);static MIN=new p(0);static ZERO=new p(0);static z=s.z.union([s.z.instanceof(p),s.z.object({value:s.z.bigint()}).transform(e=>new p(e.value)),s.z.string().transform(e=>new p(BigInt(e))),s.z.number().transform(e=>new p(e)),s.z.bigint().transform(e=>new p(e)),s.z.date().transform(e=>new p(e)),s.z.custom(e=>e instanceof A).transform(e=>new p(e)),Yo.transform(e=>new p(e))]);static sort(e,t){return Number(e.valueOf()-t.valueOf())}},A=class w extends _e{constructor(e){typeof e=="number"&&(e=Math.trunc(e.valueOf())),super(BigInt(e.valueOf()))}static fromSeconds(e){return e instanceof w?e:e instanceof xn?e.period:e instanceof $?new w(e):["number","bigint"].includes(typeof e)?w.seconds(e):new w(e)}static fromMilliseconds(e){return e instanceof w?e:e instanceof xn?e.period:e instanceof $?new w(e):["number","bigint"].includes(typeof e)?w.milliseconds(e):new w(e)}valueOf(){return this.value}lessThan(e){return this.valueOf()<new w(e).valueOf()}greaterThan(e){return this.valueOf()>new w(e).valueOf()}lessThanOrEqual(e){return this.valueOf()<=new w(e).valueOf()}greaterThanOrEqual(e){return this.valueOf()>=new w(e).valueOf()}remainder(e){return Os(this,e)}truncate(e){return new w(BigInt(Math.trunc(Number(this.valueOf()/e.valueOf())))*e.valueOf())}toString(){const e=this.truncate(w.DAY),t=this.truncate(w.HOUR),n=this.truncate(w.MINUTE),a=this.truncate(w.SECOND),i=this.truncate(w.MILLISECOND),o=this.truncate(w.MICROSECOND),c=this.truncate(w.NANOSECOND),l=e,h=t.sub(e),d=n.sub(t),u=a.sub(n),N=i.sub(a),v=o.sub(i),P=c.sub(o);let k="";return l.isZero||(k+=`${l.days}d `),h.isZero||(k+=`${h.hours}h `),d.isZero||(k+=`${d.minutes}m `),u.isZero||(k+=`${u.seconds}s `),N.isZero||(k+=`${N.milliseconds}ms `),v.isZero||(k+=`${v.microseconds}µs `),P.isZero||(k+=`${P.nanoseconds}ns`),k.trim()}mult(e){return new w(this.valueOf()*BigInt(e))}get days(){return Number(this.valueOf())/Number(w.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(w.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(w.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(w.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 isZero(){return this.valueOf()===0n}equals(e){return this.valueOf()===new w(e).valueOf()}add(e){return new w(this.valueOf()+new w(e).valueOf())}sub(e){return new w(this.valueOf()-new w(e).valueOf())}static nanoseconds(e=1){return new w(e)}static NANOSECOND=w.nanoseconds(1);static microseconds(e=1){return w.nanoseconds(Re(e,1e3))}static MICROSECOND=w.microseconds(1);static milliseconds(e=1){return w.microseconds(Re(e,1e3))}static MILLISECOND=w.milliseconds(1);static seconds(e=1){return w.milliseconds(Re(e,1e3))}static SECOND=w.seconds(1);static minutes(e=1){return w.seconds(Re(e,60))}static MINUTE=w.minutes(1);static hours(e){return w.minutes(Re(e,60))}static HOUR=w.hours(1);static days(e){return w.hours(Re(e,24))}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.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.instanceof(w)])},xn=class De extends _e{constructor(e){super(e.valueOf())}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new De(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 H(t).valueOf()}span(e){return A.seconds(e/this.valueOf())}byteSpan(e,t){return this.span(e.valueOf()/t.valueOf())}static hz(e){return new De(e)}static khz(e){return De.hz(e*1e3)}static z=s.z.union([s.z.number().transform(e=>new De(e)),s.z.instanceof(De)])},H=class oe extends _e{constructor(e){super(e.valueOf())}length(e){return e.valueOf()/this.valueOf()}size(e){return new Ar(e*this.valueOf())}static UNKNOWN=new oe(0);static BIT128=new oe(16);static BIT64=new oe(8);static BIT32=new oe(4);static BIT16=new oe(2);static BIT8=new oe(1);static z=s.z.union([s.z.number().transform(e=>new oe(e)),s.z.instanceof(oe)])},st=class te{start;end;constructor(e,t){typeof e=="object"&&"start"in e?(this.start=new $(e.start),this.end=new $(e.end)):(this.start=new $(e),this.end=new $(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 te(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(),a=this.end.sub(e.end).valueOf();return n<0&&(n=-n),a<0&&(a=-a),n<=t.valueOf()&&a<=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 a=$.max(n.start,e.start),i=$.min(n.end,e.end);return i.before(a)?!1:new A(i.sub(a)).greaterThanOrEqual(t)}contains(e){return e instanceof te?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const t=new te(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 te($.min(...e.map(t=>t.start)),$.max(...e.map(t=>t.end)))}static MAX=new te($.MIN,$.MAX);static MIN=new te($.MAX,$.MIN);static ZERO=new te($.ZERO,$.ZERO);static z=s.z.union([s.z.object({start:$.z,end:$.z}).transform(e=>new te(e.start,e.end)),s.z.instanceof(te)]);static sort(e,t){return $.sort(e.start,t.start)||$.sort(e.end,t.end)}},j=class f extends _e{constructor(e){if(e instanceof f||typeof e=="string"||typeof e.valueOf()=="string")super(e.valueOf());else{const t=f.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=f.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(f.JSON)||this.equals(f.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(f.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=f.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}get isUnsignedInteger(){return this.equals(f.UINT8)||this.equals(f.UINT16)||this.equals(f.UINT32)||this.equals(f.UINT64)}get isSignedInteger(){return this.equals(f.INT8)||this.equals(f.INT16)||this.equals(f.INT32)||this.equals(f.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(f.INT32)&&e.equals(f.FLOAT64)||this.equals(f.INT8)&&e.equals(f.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 f.BIG_INT_TYPES.some(e=>e.equals(this))}static UNKNOWN=new f("unknown");static FLOAT64=new f("float64");static FLOAT32=new f("float32");static INT64=new f("int64");static INT32=new f("int32");static INT16=new f("int16");static INT8=new f("int8");static UINT64=new f("uint64");static UINT32=new f("uint32");static UINT16=new f("uint16");static UINT8=new f("uint8");static BOOLEAN=this.UINT8;static TIMESTAMP=new f("timestamp");static UUID=new f("uuid");static STRING=new f("string");static JSON=new f("json");static ARRAY_CONSTRUCTORS=new Map([[f.UINT8.toString(),Uint8Array],[f.UINT16.toString(),Uint16Array],[f.UINT32.toString(),Uint32Array],[f.UINT64.toString(),BigUint64Array],[f.FLOAT32.toString(),Float32Array],[f.FLOAT64.toString(),Float64Array],[f.INT8.toString(),Int8Array],[f.INT16.toString(),Int16Array],[f.INT32.toString(),Int32Array],[f.INT64.toString(),BigInt64Array],[f.TIMESTAMP.toString(),BigInt64Array],[f.STRING.toString(),Uint8Array],[f.JSON.toString(),Uint8Array],[f.UUID.toString(),Uint8Array]]);static ARRAY_CONSTRUCTOR_DATA_TYPES=new Map([[Uint8Array.name,f.UINT8],[Uint16Array.name,f.UINT16],[Uint32Array.name,f.UINT32],[BigUint64Array.name,f.UINT64],[Float32Array.name,f.FLOAT32],[Float64Array.name,f.FLOAT64],[Int8Array.name,f.INT8],[Int16Array.name,f.INT16],[Int32Array.name,f.INT32],[BigInt64Array.name,f.INT64]]);static DENSITIES=new Map([[f.UINT8.toString(),H.BIT8],[f.UINT16.toString(),H.BIT16],[f.UINT32.toString(),H.BIT32],[f.UINT64.toString(),H.BIT64],[f.FLOAT32.toString(),H.BIT32],[f.FLOAT64.toString(),H.BIT64],[f.INT8.toString(),H.BIT8],[f.INT16.toString(),H.BIT16],[f.INT32.toString(),H.BIT32],[f.INT64.toString(),H.BIT64],[f.TIMESTAMP.toString(),H.BIT64],[f.STRING.toString(),H.UNKNOWN],[f.JSON.toString(),H.UNKNOWN],[f.UUID.toString(),H.BIT128]]);static ALL=[f.UNKNOWN,f.FLOAT64,f.FLOAT32,f.INT64,f.INT32,f.INT16,f.INT8,f.UINT64,f.UINT32,f.UINT16,f.UINT8,f.TIMESTAMP,f.UUID,f.STRING,f.JSON];static BIG_INT_TYPES=[f.INT64,f.UINT64,f.TIMESTAMP];static z=s.z.union([s.z.string().transform(e=>new f(e)),s.z.instanceof(f)])},Ar=class x extends _e{constructor(e){super(e.valueOf())}largerThan(e){return this.valueOf()>e.valueOf()}smallerThan(e){return this.valueOf()<e.valueOf()}add(e){return x.bytes(this.valueOf()+e.valueOf())}sub(e){return x.bytes(this.valueOf()-e.valueOf())}truncate(e){return new x(Math.trunc(this.valueOf()/e.valueOf())*e.valueOf())}remainder(e){return x.bytes(this.valueOf()%e.valueOf())}get gigabytes(){return this.valueOf()/x.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/x.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/x.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/x.TERABYTE.valueOf()}toString(){const e=this.truncate(x.TERABYTE),t=this.truncate(x.GIGABYTE),n=this.truncate(x.MEGABYTE),a=this.truncate(x.KILOBYTE),i=this.truncate(x.BYTE),o=e,c=t.sub(e),l=n.sub(t),h=a.sub(n),d=i.sub(a);let u="";return o.isZero||(u+=`${o.terabytes}TB `),c.isZero||(u+=`${c.gigabytes}GB `),l.isZero||(u+=`${l.megabytes}MB `),h.isZero||(u+=`${h.kilobytes}KB `),(!d.isZero||u==="")&&(u+=`${d.valueOf()}B`),u.trim()}static bytes(e=1){return new x(e)}static BYTE=new x(1);static kilobytes(e=1){return x.bytes(e.valueOf()*1e3)}static KILOBYTE=x.kilobytes(1);static megabytes(e=1){return x.kilobytes(e.valueOf()*1e3)}static MEGABYTE=x.megabytes(1);static gigabytes(e=1){return x.megabytes(e.valueOf()*1e3)}static GIGABYTE=x.gigabytes(1);static terabytes(e){return x.gigabytes(e.valueOf()*1e3)}static TERABYTE=x.terabytes(1);static ZERO=new x(0);static z=s.z.union([s.z.number().transform(e=>new x(e)),s.z.instanceof(x)]);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 Ns=r=>{const e=typeof r;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||r instanceof $||r instanceof A||r instanceof Date},Vo=(r,e,t,n=0)=>r.usesBigInt&&!e.usesBigInt?Number(t)-Number(n):!r.usesBigInt&&e.usesBigInt?BigInt(t.valueOf())-BigInt(n.valueOf()):Mt(t,-n),Mt=(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),Wo=/^(?:[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 _o(r){return typeof r=="string"&&Wo.test(r)}const B=[];for(let r=0;r<256;++r)B.push((r+256).toString(16).slice(1));function Ho(r,e=0){return(B[r[e+0]]+B[r[e+1]]+B[r[e+2]]+B[r[e+3]]+"-"+B[r[e+4]]+B[r[e+5]]+"-"+B[r[e+6]]+B[r[e+7]]+"-"+B[r[e+8]]+B[r[e+9]]+"-"+B[r[e+10]]+B[r[e+11]]+B[r[e+12]]+B[r[e+13]]+B[r[e+14]]+B[r[e+15]]).toLowerCase()}function Go(r,e=0){const t=Ho(r,e);if(!_o(t))throw TypeError("Stringified UUID is invalid");return t}typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const zs=(r,e)=>Go(r,e),ge=-1,Ko=s.z.string().transform(r=>new Uint8Array(atob(r).split("").map(e=>e.charCodeAt(0))).buffer),Jo=s.z.union([s.z.null(),s.z.undefined()]).transform(()=>new Uint8Array().buffer),$r=10,Xo=(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`)},Ss="sy_x_telem_series";let Is=class be{key;discriminator=Ss;dataType;sampleOffset;gl;_data;timeRange=st.ZERO;alignment=0n;cachedMin;cachedMax;writePos=ge;_refCount=0;cachedLength;_cachedIndexes;static crudeZ=s.z.object({timeRange:st.z.optional(),dataType:j.z,alignment:s.z.coerce.bigint().optional(),data:s.z.union([Ko,Jo,s.z.instanceof(ArrayBuffer),s.z.instanceof(Uint8Array)]),glBufferUsage:Fo.optional().default("static").optional()});static z=be.crudeZ.transform(e=>new be(e));constructor(e){Qo(e)&&(e={data:e}),e.data??=[];const{dataType:t,timeRange:n,sampleOffset:a=0,glBufferUsage:i="static",alignment:o=0n,key:c=Bo(),data:l}=e;if(ec(l)){const u=l;this.key=u.key,this.dataType=u.dataType,this.sampleOffset=u.sampleOffset,this.gl=u.gl,this._data=u._data,this.timeRange=u.timeRange,this.alignment=u.alignment,this.cachedMin=u.cachedMin,this.cachedMax=u.cachedMax,this.writePos=u.writePos,this._refCount=u._refCount,this.cachedLength=u.cachedLength;return}const h=Ns(l),d=Array.isArray(l);if(t!=null)this.dataType=new j(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(d||h){let u=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.");u=l[0]}if(typeof u=="string")this.dataType=j.STRING;else if(typeof u=="number")this.dataType=j.FLOAT64;else if(typeof u=="bigint")this.dataType=j.INT64;else if(typeof u=="boolean")this.dataType=j.BOOLEAN;else if(u instanceof $||u instanceof Date||u instanceof $)this.dataType=j.TIMESTAMP;else if(typeof u=="object")this.dataType=j.JSON;else throw new Error(`cannot infer data type of ${typeof u} when constructing a Series from a JS array`)}else this.dataType=new j(l)}if(!d&&!h)this._data=l;else if(d&&l.length===0)this._data=new this.dataType.Array([]).buffer;else{let u=h?[l]:l;const N=u[0];(N instanceof $||N instanceof Date||N instanceof A)&&(u=u.map(v=>new $(v).valueOf())),this.dataType.equals(j.STRING)?(this.cachedLength=u.length,this._data=new TextEncoder().encode(`${u.join(`
|
|
2
2
|
`)}
|
|
3
|
-
`).buffer):this.dataType.equals(j.JSON)?(this.cachedLength=u.length,this._data=new TextEncoder().encode(`${u.map(
|
|
3
|
+
`).buffer):this.dataType.equals(j.JSON)?(this.cachedLength=u.length,this._data=new TextEncoder().encode(`${u.map(v=>Ir.encodeString(v)).join(`
|
|
4
4
|
`)}
|
|
5
|
-
`).buffer):this.dataType.usesBigInt&&typeof N=="number"?this._data=new this.dataType.Array(u.map(
|
|
6
|
-
`).slice(0,-1):Array.from(this).map(e=>e.toString())}parseJSON(e){if(!this.dataType.equals(j.JSON))throw new Error("cannot parse non-JSON series as JSON");return this.toStrings().map(t=>e.parse(zr.decodeString(t)))}get byteCapacity(){return new Sr(this.underlyingData.byteLength)}get capacity(){return this.dataType.isVariable?this.byteCapacity.valueOf():this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===ye?this.byteCapacity:this.dataType.isVariable?new Sr(this.writePos):this.dataType.density.size(this.writePos)}get length(){return this.cachedLength!=null?this.cachedLength:this.dataType.isVariable?this.calculateCachedLength():this.writePos===ye?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,a)=>{n===Ir&&(e++,t.push(a+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 a=0;a<this.length;a++)n[a]=Fo(this.dataType,e,this.data[a],t);return new we({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(j.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(),Ut(this.cachedMax,this.sampleOffset))}calcRawMin(){if(this.length===0)return 1/0;if(this.dataType.equals(j.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(),Ut(this.cachedMin,this.sampleOffset))}get bounds(){return Ie(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);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(j.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 Ut(n,this.sampleOffset)}atUUID(e,t){e<0&&(e=this.length+e);const n=zs(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,a=0;if(this._cachedIndexes!=null)n=this._cachedIndexes[e],a=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]===Ir){if(e===0){a=o;break}n=o+1,e--}if(a===0&&(a=this.data.length),n>=a||e>0){if(t)throw new Error(`[series] - no value at index ${e}`);return}}const i=this.data.slice(n,a);return this.dataType.equals(j.STRING)?new TextDecoder().decode(i):gs(JSON.parse(new TextDecoder().decode(i)))}binarySearch(e){let t=0,n=this.length-1;const a=io(e);for(;t<=n;){const i=Math.floor((t+n)/2),o=a(this.at(i,!0),e);if(o===0)return i;o<0?t=i+1:n=i-1}return t}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals(j.FLOAT32)&&!this.dataType.equals(j.UINT8))throw new Error("Only FLOAT32 and UINT8 arrays can be used in WebGL");const{buffer:t,bufferUsage:n,prevBuffer:a}=this.gl;if(t==null&&(this.gl.buffer=e.createBuffer()),this.writePos!==a)if(e.bindBuffer(e.ARRAY_BUFFER,this.gl.buffer),this.writePos!==ye){a===0&&e.bufferData(e.ARRAY_BUFFER,this.byteCapacity.valueOf(),e.STATIC_DRAW);const i=this.dataType.density.size(a).valueOf(),o=this.underlyingData.slice(this.gl.prevBuffer,this.writePos);e.bufferSubData(e.ARRAY_BUFFER,i,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=ye}as(e){return Jo(e,this.dataType),this}get digest(){return{key:this.key,dataType:this.dataType.toString(),sampleOffset:this.sampleOffset,alignment:{lower:jn(this.alignmentBounds.lower),upper:jn(this.alignmentBounds.upper)},timeRange:this.timeRange.toString(),length:this.length,capacity:this.capacity}}get alignmentBounds(){return Ie(this.alignment,this.alignment+BigInt(this.length))}maybeGarbageCollectGLBuffer(e){this.gl.buffer!=null&&(e.deleteBuffer(this.gl.buffer),this.gl.buffer=null,this.gl.prevBuffer=0,this.gl.control=null)}get glBuffer(){if(this.gl.buffer==null)throw new Error("gl buffer not initialized");return this.gl.prevBuffer!==this.writePos&&console.warn("buffer not updated"),this.gl.buffer}[Symbol.iterator](){if(this.dataType.isVariable){const e=new Qo(this);return this.dataType.equals(j.JSON)?new ec(e):e}return this.dataType.equals(j.UUID)?new tc(this):new rc(this)}slice(e,t){return this.sliceSub(!1,e,t)}sub(e,t){return this.sliceSub(!0,e,t)}subIterator(e,t){return new Rn(this,e,t??this.length)}subAlignmentIterator(e,t){return new Rn(this,Number(e-this.alignment),Number(t-this.alignment))}subBytes(e,t){if(e>=0&&(t==null||t>=this.byteLength.valueOf()))return this;const n=this.data.subarray(e,t);return new we({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 a;return e?a=this.data.subarray(t,n):a=this.data.slice(t,n),new we({data:a,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(t)})}reAlign(e){return new we({data:this.buffer,dataType:this.dataType,timeRange:st.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 Ko=r=>r==null?!1:Array.isArray(r)||r instanceof ArrayBuffer||ArrayBuffer.isView(r)&&!(r instanceof DataView)||r instanceof Is?!0:Ns(r),Xo=Lo(Ss,Is);let Rn=class{series;end;index;constructor(r,e,t){this.series=r;const n=Ie(0,r.length);this.end=An(n,t),this.index=An(n,e)}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}},Qo=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]!==Ir;)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))})}},ec=class As{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:zr.decodeString(e.value,As.schema)}}};class tc{series;index;data;density;constructor(e){if(!e.dataType.equals(j.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=j.UUID.density.valueOf()}next(){if(this.index>=this.series.length)return{done:!0,value:void 0};const e=zs(this.data,this.index*this.density);return this.index++,{done:!1,value:e}}}let rc=class{series;index;constructor(e){this.series=e,this.index=0}next(){return this.index>=this.series.length?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}};const jn=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 nc=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser";nc();const sc=["macOS","Windows","Linux"],ac=["macos","windows","linux"],ic={macos:"macOS",windows:"Windows",linux:"Linux"};s.z.enum(sc).or(s.z.enum(ac).transform(r=>ic[r]));const oc=(...r)=>r.map($s).join(""),$s=r=>(r.endsWith("/")||(r+="/"),r.startsWith("/")&&(r=r.slice(1)),r),cc=r=>r.endsWith("/")?r.slice(0,-1):r,lc=(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 uc=class Dt{protocol;host;port;path;constructor({host:e,port:t,protocol:n="",pathPrefix:a=""}){this.protocol=n,this.host=e,this.port=t,this.path=$s(a)}replace(e){return new Dt({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new Dt({...this,pathPrefix:oc(this.path,e)})}toString(){return cc(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}static UNKNOWN=new Dt({host:"unknown",port:0})};const hc=async r=>await new Promise(e=>setTimeout(e,A.fromMilliseconds(r).milliseconds));class dc{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??hc},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)}reset(){this.retries=0,this.interval=this.config.baseInterval}}const fc=s.z.object({baseInterval:A.z.optional(),maxRetries:s.z.number().optional(),scale:s.z.number().optional()}),yc=Object.freeze(Object.defineProperty({__proto__:null,Breaker:dc,breakerConfigZ:fc},Symbol.toStringTag,{value:"Module"})),gc=/^#?([0-9a-f]{6}|[0-9a-f]{8})$/i,ks=s.z.string().regex(gc),qe=s.z.number().min(0).max(255),Cs=s.z.number().min(0).max(1),xs=s.z.tuple([qe,qe,qe,Cs]),pc=s.z.tuple([qe,qe,qe]),mc=s.z.object({rgba255:xs}),wc=s.z.number().min(0).max(360),bc=s.z.number().min(0).max(100),Tc=s.z.number().min(0).max(100),vc=s.z.tuple([wc,bc,Tc,Cs]),Hr=s.z.union([ks,pc,xs,vc,mc]),Ec=Hr.transform(r=>Gr(r)),Gr=(r,e=1)=>{if(r=Hr.parse(r),typeof r=="string")return Oc(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},Oc=(r,e=1)=>(r=ks.parse(r),r=Nc(r),[Ct(r,0),Ct(r,2),Ct(r,4),r.length===8?Ct(r,6)/255:e]),Ct=(r,e)=>parseInt(r.slice(e,e+2),16),Nc=r=>r.startsWith("#")?r.slice(1):r;Gr("#000000");Gr("#ffffff");const zc=s.z.object({key:s.z.string(),color:Hr,position:s.z.number(),switched:s.z.boolean().optional()});s.z.array(zc);const Sc=s.z.object({key:s.z.string(),name:s.z.string(),color:Ec});s.z.object({key:s.z.string(),name:s.z.string(),swatches:s.z.array(Sc)});s.z.int().min(0).max(255);s.z.object({name:s.z.string(),key:s.z.string()});const Ic=r=>Object.getOwnPropertySymbols(globalThis).includes(r),Ac=(r,e)=>{const t=Symbol.for(r);if(!Ic(t)){const n=e();Object.defineProperty(globalThis,t,{value:n})}return()=>globalThis[t]},Rs="sy_x_error",$c=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),bt=r=>class at extends Error{static discriminator=Rs;discriminator=at.discriminator;static TYPE=r;type=at.TYPE;static matches=$c(r);matches=at.matches;constructor(t,n){super(t,n),this.name=at.TYPE}static sub(t){return bt(`${r}.${t}`)}},js=r=>{if(r==null||typeof r!="object")return!1;const e=r;if(e.discriminator!==Rs)return!1;if(!("type"in e))throw new Error(`X Error is missing its type property: ${JSON.stringify(e)}`);return!0},De="unknown",Ar="nil";class kc{providers=[];register(e){this.providers.push(e)}encode(e){if(e==null)return{type:Ar,data:""};if(js(e))for(const t of this.providers){const n=t.encode(e);if(n!=null)return n}if(e instanceof Error)return{type:De,data:e.message};if(typeof e=="string")return{type:De,data:e};try{return{type:De,data:JSON.stringify(e)}}catch{return{type:De,data:"unable to encode error information"}}}decode(e){if(e==null||e.type===Ar)return null;if(e.type===De)return new $r(e.data);for(const t of this.providers){const n=t.decode(e);if(n!=null)return n}return new $r(e.data)}}const Jr=Ac("synnax-error-registry",()=>new kc),Cc=({encode:r,decode:e})=>Jr().register({encode:r,decode:e}),xc=r=>Jr().encode(r),Rc=r=>r==null?null:Jr().decode(r);let $r=class extends bt("unknown"){};const jc=s.z.object({type:s.z.string(),data:s.z.string()});class Uc extends bt("canceled"){}class Dc extends bt("not_implemented"){}const be=Object.freeze(Object.defineProperty({__proto__:null,Canceled:Uc,NONE:Ar,NotImplemented:Dc,UNKNOWN:De,Unknown:$r,createTyped:bt,decode:Rc,encode:xc,isTyped:js,payloadZ:jc,register:Cc},Symbol.toStringTag,{value:"Module"})),Mc=s.object({jsonrpc:s.literal("2.0"),method:s.string(),params:s.any().optional(),id:s.union([s.string(),s.number(),s.null()]).optional()}),Us=s.object({jsonrpc:s.literal("2.0"),id:s.union([s.string(),s.number(),s.null()])}),Zc=Us.extend({result:s.json()}),Pc=Us.extend({error:s.object({code:s.number().int(),message:s.string().optional(),data:s.json().optional()})}),Lc=s.union([Zc,Pc]);s.union([Mc,Lc]);s.z.string().regex(/^\d+\.\d+\.\d+$/);const Bc=["standard","scientific","engineering"];s.z.enum(Bc);s.z.enum(["success","info","warning","error","loading","disabled"]);let Tt=class extends be.createTyped("freighter"){},K=class extends Tt.sub("eof"){constructor(){super("EOF")}},Ve=class extends Tt.sub("stream_closed"){constructor(){super("StreamClosed")}},Te=class extends Tt.sub("unreachable"){url;constructor(e={}){const{message:t="Unreachable",url:n=uc.UNKNOWN}=e;super(t),this.url=n}};const qc=r=>{if(!r.type.startsWith(Tt.TYPE))return null;if(K.matches(r))return{type:K.TYPE,data:"EOF"};if(Ve.matches(r))return{type:Ve.TYPE,data:"StreamClosed"};if(Te.matches(r))return{type:Te.TYPE,data:"Unreachable"};throw new Error(`Unknown error type: ${r.type}: ${r.message}`)},Fc=r=>{if(!r.type.startsWith(Tt.TYPE))return null;switch(r.type){case K.TYPE:return new K;case Ve.TYPE:return new Ve;case Te.TYPE:return new Te;default:throw new be.Unknown(`Unknown error type: ${r.data}`)}};be.register({encode:qc,decode:Fc});class Ds{middleware=[];use(...e){this.middleware.push(...e)}async executeMiddleware(e,t){let n=0;const a=async i=>{if(n===this.middleware.length)return await t(i);const o=this.middleware[n];return n++,await o(i,a)};return await a(e)}}const Ms="Content-Type",Yc=r=>typeof r.cause=="object"&&r.cause!==null&&"code"in r.cause&&r.cause.code==="ECONNREFUSED",Vc=400;class Wc extends Ds{endpoint;encoder;constructor(e,t,n=!1){return super(),this.endpoint=e.replace({protocol:n?"https":"http"}),this.encoder=t,new Proxy(this,{get:(a,i,o)=>i==="endpoint"?this.endpoint:Reflect.get(a,i,o)})}get headers(){return{[Ms]:this.encoder.contentType}}async send(e,t,n,a){t=n?.parse(t);let i=null;const o=this.endpoint.child(e),c={};c.method="POST",c.body=this.encoder.encode(t??{});const[,l]=await this.executeMiddleware({target:o.toString(),protocol:this.endpoint.protocol,params:{},role:"client"},async h=>{const d={...h,params:{}};c.headers={...this.headers,...h.params};let u;try{u=await fetch(h.target,c)}catch(E){if(!(E instanceof Error))throw E;return[d,Yc(E)?new Te({url:o}):E]}const N=await u.arrayBuffer();if(u?.ok)return a!=null&&(i=this.encoder.decode(N,a)),[d,null];try{if(u.status!==Vc)return[d,new Error(u.statusText)];const E=this.encoder.decode(N,be.payloadZ),P=be.decode(E);return[d,P]}catch(E){return[d,new Error(`[freighter] - failed to decode error: ${u.statusText}: ${E.message}`)]}});if(l!=null)return[null,l];if(i==null)throw new Error("Response must be defined");return[i,null]}}const _c=(r,e)=>{class t{wrapped;constructor(a){this.wrapped=a}use(...a){this.wrapped.use(...a)}async send(a,i,o,c){const l=new yc.Breaker(e);do{const[h,d]=await this.wrapped.send(a,i,o,c);if(d==null)return[h,null];if(!Te.matches(d))return[null,d];if(!await l.wait())return[h,d]}while(!0)}}return new t(r)},g=async(r,e,t,n,a)=>{const[i,o]=await r.send(e,t,n,a);if(o!=null)throw o;return i},Hc=s.z.object({type:s.z.enum(["data","close","open"]),payload:s.z.unknown(),error:s.z.optional(be.payloadZ)});class Gc{codec;reqSchema;resSchema;ws;serverClosed;sendClosed;receiveDataQueue=[];receiveCallbacksQueue=[];constructor(e,t,n,a){this.codec=t,this.reqSchema=n,this.resSchema=a,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 be.decode(e.error)}return null}send(e){if(this.serverClosed!=null)return new K;if(this.sendClosed)throw new Ve;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=be.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,Hc))}onClose(e){this.addMessage({type:"close",error:{type:e.code===Kc?K.TYPE:Ve.TYPE,data:""}})}}const Jc="freighterctx",Kc=1e3;let Xc=class kr extends Ds{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 kr(this.baseUrl,e,this.secure);return t.use(...this.middleware),t}async stream(e,t,n){let a;const[,i]=await this.executeMiddleware({target:e,protocol:"websocket",params:{},role:"client"},async o=>{const c=new WebSocket(this.buildURL(e,o)),l={...o,params:{}};c.binaryType=kr.MESSAGE_TYPE;const h=await this.wrapSocket(c,t,n);return h instanceof Error?[l,h]:(a=h,[l,null])});if(i!=null)throw i;return a}buildURL(e,t){const n=lc({[Ms]:this.encoder.contentType,...t.params},Jc);return this.baseUrl.child(e).toString()+n}async wrapSocket(e,t,n){return await new Promise(a=>{e.onopen=()=>{const i=new Gc(e,this.encoder,t,n);i.receiveOpenAck().then(o=>{o!=null?a(o):a(i)}).catch(o=>a(o))},e.onerror=i=>{const o=i;a(new Error(o.message))}})}};const Qc=r=>Array.isArray(r)?r:r==null?[]:[r],T=Object.freeze(Object.defineProperty({__proto__:null,toArray:Qc},Symbol.toStringTag,{value:"Module"})),el=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)},Kr=r=>{const e=(t,n=Cr)=>{if(typeof t=="string")return r(t);if(Array.isArray(t))return t.map(o=>e(o,n));if(!ur(t))return t;n=sl(n);const a={},i=t;return"toJSON"in i&&typeof i.toJSON=="function"?e(i.toJSON(),n):(Object.keys(i).forEach(o=>{let c=i[o];const l=r(o);n.recursive&&(ur(c)?Dn(c)||(c=e(c,n)):n.recursiveInArray&&Un(c)&&(c=[...c].map(h=>{let d=h;return ur(h)?Dn(d)||(d=e(h,n)):Un(h)&&(d=e({key:h},n).key),d}))),a[l]=c}),a)};return e},Xr=Kr(el),tl=r=>r.replace(/([a-z0-9])([A-Z])/g,(e,t,n)=>`${t}_${n.toLowerCase()}`),Zs=Kr(tl),rl=r=>r.length===0?r:r[0].toUpperCase()+r.slice(1),nl=[Number,String,Uint8Array],Cr={recursive:!0,recursiveInArray:!0},sl=(r=Cr)=>(r.recursive==null?r=Cr:r.recursiveInArray??=!1,r),Un=r=>r!=null&&Array.isArray(r),ur=r=>r!=null&&typeof r=="object"&&!Array.isArray(r),Dn=r=>nl.some(e=>r instanceof e),al=r=>r.replace(/\s+/g,"-").replace(/([a-z0-9])([A-Z])/g,(e,t,n)=>`${t}-${n.toLowerCase()}`).toLowerCase(),il=Kr(al),ol=Object.freeze(Object.defineProperty({__proto__:null,camelToSnake:Zs,capitalize:rl,snakeToCamel:Xr,toKebab:il},Symbol.toStringTag,{value:"Module"})),Ps=r=>r!=null&&typeof r=="object"&&!Array.isArray(r);let Ls=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),a=Xr(n);return t!=null?t.parse(a):a}encodeString(e){const t=Zs(e);return JSON.stringify(t,(n,a)=>ArrayBuffer.isView(a)?Array.from(a):typeof a=="bigint"?a.toString():a)}},Bs=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||!Ps(e[0]))throw new Error("Payload must be an array of objects");const t=Object.keys(e[0]),n=[t.join(",")];return e.forEach(a=>{const i=t.map(o=>JSON.stringify(a[o]??""));n.push(i.join(","))}),n.join(`
|
|
5
|
+
`).buffer):this.dataType.usesBigInt&&typeof N=="number"?this._data=new this.dataType.Array(u.map(v=>BigInt(Math.round(v)))).buffer:!this.dataType.usesBigInt&&typeof N=="bigint"?this._data=new this.dataType.Array(u.map(Number)).buffer:this._data=new this.dataType.Array(u).buffer}this.key=c,this.alignment=o,this.sampleOffset=a??0,this.timeRange=n??st.ZERO,this.gl={control:null,buffer:null,prevBuffer:0,bufferUsage:i}}static alloc({capacity:e,dataType:t,...n}){if(e===0)throw new Error("[Series] - cannot allocate an array of length 0");const a=new new j(t).Array(e),i=new be({data:a.buffer,dataType:t,...n});return i.writePos=0,i}get refCount(){return this._refCount}acquire(e){this._refCount++,e!=null&&this.updateGLBuffer(e)}release(){this._refCount--,this.refCount===0&&this.gl.control!=null?this.maybeGarbageCollectGLBuffer(this.gl.control):this.refCount<0&&console.warn("cannot release a series with a negative reference count")}write(e){if(!e.dataType.equals(this.dataType))throw 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===ge)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===ge)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===ge?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(j.JSON))throw new Error("cannot parse non-JSON series as JSON");return this.toStrings().map(t=>e.parse(Ir.decodeString(t)))}get byteCapacity(){return new Ar(this.underlyingData.byteLength)}get capacity(){return this.dataType.isVariable?this.byteCapacity.valueOf():this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===ge?this.byteCapacity:this.dataType.isVariable?new Ar(this.writePos):this.dataType.density.size(this.writePos)}get length(){return this.cachedLength!=null?this.cachedLength:this.dataType.isVariable?this.calculateCachedLength():this.writePos===ge?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,a)=>{n===$r&&(e++,t.push(a+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 a=0;a<this.length;a++)n[a]=Vo(this.dataType,e,this.data[a],t);return new be({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(j.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(),Mt(this.cachedMax,this.sampleOffset))}calcRawMin(){if(this.length===0)return 1/0;if(this.dataType.equals(j.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(),Mt(this.cachedMin,this.sampleOffset))}get bounds(){return Ae(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);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(j.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 Mt(n,this.sampleOffset)}atUUID(e,t){e<0&&(e=this.length+e);const n=zs(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,a=0;if(this._cachedIndexes!=null)n=this._cachedIndexes[e],a=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]===$r){if(e===0){a=o;break}n=o+1,e--}if(a===0&&(a=this.data.length),n>=a||e>0){if(t)throw new Error(`[series] - no value at index ${e}`);return}}const i=this.data.slice(n,a);return this.dataType.equals(j.STRING)?new TextDecoder().decode(i):gs(JSON.parse(new TextDecoder().decode(i)))}binarySearch(e){let t=0,n=this.length-1;const a=co(e);for(;t<=n;){const i=Math.floor((t+n)/2),o=a(this.at(i,!0),e);if(o===0)return i;o<0?t=i+1:n=i-1}return t}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals(j.FLOAT32)&&!this.dataType.equals(j.UINT8))throw new Error("Only FLOAT32 and UINT8 arrays can be used in WebGL");const{buffer:t,bufferUsage:n,prevBuffer:a}=this.gl;if(t==null&&(this.gl.buffer=e.createBuffer()),this.writePos!==a)if(e.bindBuffer(e.ARRAY_BUFFER,this.gl.buffer),this.writePos!==ge){a===0&&e.bufferData(e.ARRAY_BUFFER,this.byteCapacity.valueOf(),e.STATIC_DRAW);const i=this.dataType.density.size(a).valueOf(),o=this.underlyingData.slice(this.gl.prevBuffer,this.writePos);e.bufferSubData(e.ARRAY_BUFFER,i,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=ge}as(e){return Xo(e,this.dataType),this}get digest(){return{key:this.key,dataType:this.dataType.toString(),sampleOffset:this.sampleOffset,alignment:{lower:jn(this.alignmentBounds.lower),upper:jn(this.alignmentBounds.upper)},timeRange:this.timeRange.toString(),length:this.length,capacity:this.capacity}}get alignmentBounds(){return Ae(this.alignment,this.alignment+BigInt(this.length))}maybeGarbageCollectGLBuffer(e){this.gl.buffer!=null&&(e.deleteBuffer(this.gl.buffer),this.gl.buffer=null,this.gl.prevBuffer=0,this.gl.control=null)}get glBuffer(){if(this.gl.buffer==null)throw new Error("gl buffer not initialized");return this.gl.prevBuffer!==this.writePos&&console.warn("buffer not updated"),this.gl.buffer}[Symbol.iterator](){if(this.dataType.isVariable){const e=new tc(this);return this.dataType.equals(j.JSON)?new rc(e):e}return this.dataType.equals(j.UUID)?new nc(this):new sc(this)}slice(e,t){return this.sliceSub(!1,e,t)}sub(e,t){return this.sliceSub(!0,e,t)}subIterator(e,t){return new Rn(this,e,t??this.length)}subAlignmentIterator(e,t){return new Rn(this,Number(e-this.alignment),Number(t-this.alignment))}subBytes(e,t){if(e>=0&&(t==null||t>=this.byteLength.valueOf()))return this;const n=this.data.subarray(e,t);return new be({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 a;return e?a=this.data.subarray(t,n):a=this.data.slice(t,n),new be({data:a,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(t)})}reAlign(e){return new be({data:this.buffer,dataType:this.dataType,timeRange:st.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 Qo=r=>r==null?!1:Array.isArray(r)||r instanceof ArrayBuffer||ArrayBuffer.isView(r)&&!(r instanceof DataView)||r instanceof Is?!0:Ns(r),ec=qo(Ss,Is);let Rn=class{series;end;index;constructor(r,e,t){this.series=r;const n=Ae(0,r.length);this.end=An(n,t),this.index=An(n,e)}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}},tc=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]!==$r;)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))})}},rc=class As{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:Ir.decodeString(e.value,As.schema)}}};class nc{series;index;data;density;constructor(e){if(!e.dataType.equals(j.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=j.UUID.density.valueOf()}next(){if(this.index>=this.series.length)return{done:!0,value:void 0};const e=zs(this.data,this.index*this.density);return this.index++,{done:!1,value:e}}}let sc=class{series;index;constructor(e){this.series=e,this.index=0}next(){return this.index>=this.series.length?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}};const jn=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 ac=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser";ac();const ic=["macOS","Windows","Linux"],oc=["macos","windows","linux"],cc={macos:"macOS",windows:"Windows",linux:"Linux"};s.z.enum(ic).or(s.z.enum(oc).transform(r=>cc[r]));const lc=(...r)=>r.map($s).join(""),$s=r=>(r.endsWith("/")||(r+="/"),r.startsWith("/")&&(r=r.slice(1)),r),uc=r=>r.endsWith("/")?r.slice(0,-1):r,hc=(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 dc=class Zt{protocol;host;port;path;constructor({host:e,port:t,protocol:n="",pathPrefix:a=""}){this.protocol=n,this.host=e,this.port=t,this.path=$s(a)}replace(e){return new Zt({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new Zt({...this,pathPrefix:lc(this.path,e)})}toString(){return uc(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}static UNKNOWN=new Zt({host:"unknown",port:0})};const fc=async r=>await new Promise(e=>setTimeout(e,A.fromMilliseconds(r).milliseconds));class yc{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??fc},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)}reset(){this.retries=0,this.interval=this.config.baseInterval}}const gc=s.z.object({baseInterval:A.z.optional(),maxRetries:s.z.number().optional(),scale:s.z.number().optional()}),pc=Object.freeze(Object.defineProperty({__proto__:null,Breaker:yc,breakerConfigZ:gc},Symbol.toStringTag,{value:"Module"})),mc=/^#?([0-9a-f]{6}|[0-9a-f]{8})$/i,ks=s.z.string().regex(mc),qe=s.z.number().min(0).max(255),Cs=s.z.number().min(0).max(1),xs=s.z.tuple([qe,qe,qe,Cs]),wc=s.z.tuple([qe,qe,qe]),bc=s.z.object({rgba255:xs}),Tc=s.z.number().min(0).max(360),vc=s.z.number().min(0).max(100),Ec=s.z.number().min(0).max(100),Oc=s.z.tuple([Tc,vc,Ec,Cs]),Kr=s.z.union([ks,wc,xs,Oc,bc]),Nc=Kr.transform(r=>Jr(r)),Jr=(r,e=1)=>{if(r=Kr.parse(r),typeof r=="string")return zc(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},zc=(r,e=1)=>(r=ks.parse(r),r=Sc(r),[Rt(r,0),Rt(r,2),Rt(r,4),r.length===8?Rt(r,6)/255:e]),Rt=(r,e)=>parseInt(r.slice(e,e+2),16),Sc=r=>r.startsWith("#")?r.slice(1):r;Jr("#000000");Jr("#ffffff");const Ic=s.z.object({key:s.z.string(),color:Kr,position:s.z.number(),switched:s.z.boolean().optional()});s.z.array(Ic);const Ac=s.z.object({key:s.z.string(),name:s.z.string(),color:Nc});s.z.object({key:s.z.string(),name:s.z.string(),swatches:s.z.array(Ac)});s.z.int().min(0).max(255);s.z.object({name:s.z.string(),key:s.z.string()});const $c=r=>Object.getOwnPropertySymbols(globalThis).includes(r),kc=(r,e)=>{const t=Symbol.for(r);if(!$c(t)){const n=e();Object.defineProperty(globalThis,t,{value:n})}return()=>globalThis[t]},Rs="sy_x_error",Cc=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),Tt=r=>class at extends Error{static discriminator=Rs;discriminator=at.discriminator;static TYPE=r;type=at.TYPE;static matches=Cc(r);matches=at.matches;constructor(t,n){super(t,n),this.name=at.TYPE}static sub(t){return Tt(`${r}.${t}`)}},js=r=>{if(r==null||typeof r!="object")return!1;const e=r;if(e.discriminator!==Rs)return!1;if(!("type"in e))throw new Error(`X Error is missing its type property: ${JSON.stringify(e)}`);return!0},Me="unknown",kr="nil";class xc{providers=[];register(e){this.providers.push(e)}encode(e){if(e==null)return{type:kr,data:""};if(js(e))for(const t of this.providers){const n=t.encode(e);if(n!=null)return n}if(e instanceof Error)return{type:Me,data:e.message};if(typeof e=="string")return{type:Me,data:e};try{return{type:Me,data:JSON.stringify(e)}}catch{return{type:Me,data:"unable to encode error information"}}}decode(e){if(e==null||e.type===kr)return null;if(e.type===Me)return new Cr(e.data);for(const t of this.providers){const n=t.decode(e);if(n!=null)return n}return new Cr(e.data)}}const Xr=kc("synnax-error-registry",()=>new xc),Rc=({encode:r,decode:e})=>Xr().register({encode:r,decode:e}),jc=r=>Xr().encode(r),Uc=r=>r==null?null:Xr().decode(r);let Cr=class extends Tt("unknown"){};const Dc=s.z.object({type:s.z.string(),data:s.z.string()});class Mc extends Tt("canceled"){}class Zc extends Tt("not_implemented"){}const Te=Object.freeze(Object.defineProperty({__proto__:null,Canceled:Mc,NONE:kr,NotImplemented:Zc,UNKNOWN:Me,Unknown:Cr,createTyped:Tt,decode:Uc,encode:jc,isTyped:js,payloadZ:Dc,register:Rc},Symbol.toStringTag,{value:"Module"})),Pc=s.object({jsonrpc:s.literal("2.0"),method:s.string(),params:s.any().optional(),id:s.union([s.string(),s.number(),s.null()]).optional()}),Us=s.object({jsonrpc:s.literal("2.0"),id:s.union([s.string(),s.number(),s.null()])}),Lc=Us.extend({result:s.json()}),Bc=Us.extend({error:s.object({code:s.number().int(),message:s.string().optional(),data:s.json().optional()})}),qc=s.union([Lc,Bc]);s.union([Pc,qc]);s.z.string().regex(/^\d+\.\d+\.\d+$/);const Fc=["standard","scientific","engineering"];s.z.enum(Fc);s.z.enum(["success","info","warning","error","loading","disabled"]);let vt=class extends Te.createTyped("freighter"){},X=class extends vt.sub("eof"){constructor(){super("EOF")}},Ve=class extends vt.sub("stream_closed"){constructor(){super("StreamClosed")}},ve=class extends vt.sub("unreachable"){url;constructor(e={}){const{message:t="Unreachable",url:n=dc.UNKNOWN}=e;super(t),this.url=n}};const Yc=r=>{if(!r.type.startsWith(vt.TYPE))return null;if(X.matches(r))return{type:X.TYPE,data:"EOF"};if(Ve.matches(r))return{type:Ve.TYPE,data:"StreamClosed"};if(ve.matches(r))return{type:ve.TYPE,data:"Unreachable"};throw new Error(`Unknown error type: ${r.type}: ${r.message}`)},Vc=r=>{if(!r.type.startsWith(vt.TYPE))return null;switch(r.type){case X.TYPE:return new X;case Ve.TYPE:return new Ve;case ve.TYPE:return new ve;default:throw new Te.Unknown(`Unknown error type: ${r.data}`)}};Te.register({encode:Yc,decode:Vc});class Ds{middleware=[];use(...e){this.middleware.push(...e)}async executeMiddleware(e,t){let n=0;const a=async i=>{if(n===this.middleware.length)return await t(i);const o=this.middleware[n];return n++,await o(i,a)};return await a(e)}}const Ms="Content-Type",Wc=r=>typeof r.cause=="object"&&r.cause!==null&&"code"in r.cause&&r.cause.code==="ECONNREFUSED",_c=400;class Hc extends Ds{endpoint;encoder;constructor(e,t,n=!1){return super(),this.endpoint=e.replace({protocol:n?"https":"http"}),this.encoder=t,new Proxy(this,{get:(a,i,o)=>i==="endpoint"?this.endpoint:Reflect.get(a,i,o)})}get headers(){return{[Ms]:this.encoder.contentType}}async send(e,t,n,a){t=n?.parse(t);let i=null;const o=this.endpoint.child(e),c={};c.method="POST",c.body=this.encoder.encode(t??{});const[,l]=await this.executeMiddleware({target:o.toString(),protocol:this.endpoint.protocol,params:{},role:"client"},async h=>{const d={...h,params:{}};c.headers={...this.headers,...h.params};let u;try{u=await fetch(h.target,c)}catch(v){if(!(v instanceof Error))throw v;return[d,Wc(v)?new ve({url:o}):v]}const N=await u.arrayBuffer();if(u?.ok)return a!=null&&(i=this.encoder.decode(N,a)),[d,null];try{if(u.status!==_c)return[d,new Error(u.statusText)];const v=this.encoder.decode(N,Te.payloadZ),P=Te.decode(v);return[d,P]}catch(v){return[d,new Error(`[freighter] - failed to decode error: ${u.statusText}: ${v.message}`)]}});if(l!=null)return[null,l];if(i==null)throw new Error("Response must be defined");return[i,null]}}const Gc=(r,e)=>{class t{wrapped;constructor(a){this.wrapped=a}use(...a){this.wrapped.use(...a)}async send(a,i,o,c){const l=new pc.Breaker(e);do{const[h,d]=await this.wrapped.send(a,i,o,c);if(d==null)return[h,null];if(!ve.matches(d))return[null,d];if(!await l.wait())return[h,d]}while(!0)}}return new t(r)},g=async(r,e,t,n,a)=>{const[i,o]=await r.send(e,t,n,a);if(o!=null)throw o;return i},Kc=s.z.object({type:s.z.enum(["data","close","open"]),payload:s.z.unknown(),error:s.z.optional(Te.payloadZ)});class Jc{codec;reqSchema;resSchema;ws;serverClosed;sendClosed;receiveDataQueue=[];receiveCallbacksQueue=[];constructor(e,t,n,a){this.codec=t,this.reqSchema=n,this.resSchema=a,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 Te.decode(e.error)}return null}send(e){if(this.serverClosed!=null)return new X;if(this.sendClosed)throw new Ve;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=Te.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,Kc))}onClose(e){this.addMessage({type:"close",error:{type:e.code===Qc?X.TYPE:Ve.TYPE,data:""}})}}const Xc="freighterctx",Qc=1e3;let el=class xr extends Ds{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 xr(this.baseUrl,e,this.secure);return t.use(...this.middleware),t}async stream(e,t,n){let a;const[,i]=await this.executeMiddleware({target:e,protocol:"websocket",params:{},role:"client"},async o=>{const c=new WebSocket(this.buildURL(e,o)),l={...o,params:{}};c.binaryType=xr.MESSAGE_TYPE;const h=await this.wrapSocket(c,t,n);return h instanceof Error?[l,h]:(a=h,[l,null])});if(i!=null)throw i;return a}buildURL(e,t){const n=hc({[Ms]:this.encoder.contentType,...t.params},Xc);return this.baseUrl.child(e).toString()+n}async wrapSocket(e,t,n){return await new Promise(a=>{e.onopen=()=>{const i=new Jc(e,this.encoder,t,n);i.receiveOpenAck().then(o=>{o!=null?a(o):a(i)}).catch(o=>a(o))},e.onerror=i=>{const o=i;a(new Error(o.message))}})}};const tl=r=>Array.isArray(r)?r:r==null?[]:[r],T=Object.freeze(Object.defineProperty({__proto__:null,toArray:tl},Symbol.toStringTag,{value:"Module"})),rl=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)},Qr=r=>{const e=(t,n=Rr)=>{if(typeof t=="string")return r(t);if(Array.isArray(t))return t.map(o=>e(o,n));if(!dr(t))return t;n=il(n);const a={},i=t;return"toJSON"in i&&typeof i.toJSON=="function"?e(i.toJSON(),n):(Object.keys(i).forEach(o=>{let c=i[o];const l=r(o);n.recursive&&(dr(c)?Dn(c)||(c=e(c,n)):n.recursiveInArray&&Un(c)&&(c=[...c].map(h=>{let d=h;return dr(h)?Dn(d)||(d=e(h,n)):Un(h)&&(d=e({key:h},n).key),d}))),a[l]=c}),a)};return e},en=Qr(rl),nl=r=>r.replace(/([a-z0-9])([A-Z])/g,(e,t,n)=>`${t}_${n.toLowerCase()}`),Zs=Qr(nl),sl=r=>r.length===0?r:r[0].toUpperCase()+r.slice(1),al=[Number,String,Uint8Array],Rr={recursive:!0,recursiveInArray:!0},il=(r=Rr)=>(r.recursive==null?r=Rr:r.recursiveInArray??=!1,r),Un=r=>r!=null&&Array.isArray(r),dr=r=>r!=null&&typeof r=="object"&&!Array.isArray(r),Dn=r=>al.some(e=>r instanceof e),ol=r=>r.replace(/\s+/g,"-").replace(/([a-z0-9])([A-Z])/g,(e,t,n)=>`${t}-${n.toLowerCase()}`).toLowerCase(),cl=Qr(ol),ll=Object.freeze(Object.defineProperty({__proto__:null,camelToSnake:Zs,capitalize:sl,snakeToCamel:en,toKebab:cl},Symbol.toStringTag,{value:"Module"})),Ps=r=>r!=null&&typeof r=="object"&&!Array.isArray(r);let Ls=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),a=en(n);return t!=null?t.parse(a):a}encodeString(e){const t=Zs(e);return JSON.stringify(t,(n,a)=>ArrayBuffer.isView(a)?Array.from(a):typeof a=="bigint"?a.toString():a)}},Bs=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||!Ps(e[0]))throw new Error("Payload must be an array of objects");const t=Object.keys(e[0]),n=[t.join(",")];return e.forEach(a=>{const i=t.map(o=>JSON.stringify(a[o]??""));n.push(i.join(","))}),n.join(`
|
|
7
7
|
`)}decodeString(e,t){const[n,...a]=e.trim().split(`
|
|
8
|
-
`).map(c=>c.trim());if(n.length===0)return t!=null?t.parse({}):{};const i=n.split(",").map(c=>c.trim()),o={};return i.forEach(c=>{o[c]=[]}),a.forEach(c=>{const l=c.split(",").map(h=>h.trim());i.forEach((h,d)=>{const u=this.parseValue(l[d]);u!=null&&o[h].push(u)})}),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}},qs=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 lt=new Ls,cl=new Bs,ll=new qs,ul=[lt],$e=Object.freeze(Object.defineProperty({__proto__:null,CSVCodec:Bs,CSV_CODEC:cl,ENCODERS:ul,JSONCodec:Ls,JSON_CODEC:lt,TEXT_CODEC:ll,TextCodec:qs},Symbol.toStringTag,{value:"Module"})),xr=r=>[...new Set(r)],hl=(r,e,t=!0)=>{const n=new Map;return r.forEach(a=>{const i=e(a);if(n.has(i)){if(t)return;n.delete(i)}n.set(i,a)}),Array.from(n.values())},Mn=Object.freeze(Object.defineProperty({__proto__:null,by:hl,unique:xr},Symbol.toStringTag,{value:"Module"}));let He=class{value;constructor(e){this.value=e}valueOf(){return this.value}toJSON(){return this.value}toString(){return this.value.toString()}};const dl=r=>r!=null&&typeof r=="object"&&"toString"in r,Wt=(r,e=!1)=>{const t=dl(r)?"stringer":typeof r;let n;switch(t){case"string":n=(a,i)=>a.localeCompare(i);break;case"stringer":n=(a,i)=>a.toString().localeCompare(i.toString());break;case"number":n=(a,i)=>Number(a)-Number(i);break;case"bigint":n=(a,i)=>BigInt(a)-BigInt(i)>0n?1:-1;break;case"boolean":n=(a,i)=>Number(a)-Number(i);break;case"undefined":n=()=>0;break;default:return console.warn(`sortFunc: unknown type ${t}`),()=>-1}return e?Ys(n):n},fl=(r,e,t)=>{const n=Wt(e[r],t);return(a,i)=>n(a[r],i[r])},yl=(r,e)=>r.length!==e.length?r.length-e.length:r.every((t,n)=>t===e[n])?0:-1,Fs=(r,e)=>{if(r.length!==e.length)return r.length-e.length;if(r.length===0)return 0;const t=Wt(r[0]),n=[...r].sort(t),a=[...e].sort(t);return n.every((i,o)=>i===a[o])?0:-1},gl=(r,e)=>{const t=xr(r),n=xr(e);return Fs(t,n)},pl=(r,e)=>r===e?0:r==="first"&&e==="last"?1:-1,Ys=r=>(e,t)=>r(t,e),Ge=0,Mt=-1,Zt=1,Vs=r=>r<Ge,Ws=r=>r>Ge,ml=r=>r>=Ge,_s=r=>r===Ge,wl=(r,e)=>{const t=/([a-zA-Z]+)|(\d+)/g,n=r.replace(/[\s_.-]+/g,"").match(t),a=e.replace(/[\s_.-]+/g,"").match(t);if(!n||!a)return 0;for(let i=0;i<Math.min(n.length,a.length);i++){const o=n[i],c=a[i];if(isNaN(Number(o))&&isNaN(Number(c))){const l=o.localeCompare(c);if(l!==0)return l}else if(!isNaN(Number(o))&&!isNaN(Number(c))){const l=Number(o)-Number(c);if(l!==0)return l}else return isNaN(Number(o))?-1:1}return n.length-a.length},Zn=Object.freeze(Object.defineProperty({__proto__:null,EQUAL:Ge,GREATER_THAN:Zt,LESS_THAN:Mt,isEqualTo:_s,isGreaterThan:Ws,isGreaterThanEqual:ml,isLessThan:Vs,newF:Wt,newFieldF:fl,order:pl,primitiveArrays:yl,reverseF:Ys,stringsWithNumbers:wl,uniqueUnorderedPrimitiveArrays:gl,unorderedPrimitiveArrays:Fs},Symbol.toStringTag,{value:"Module"})),_t=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()}),bl=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()}),Tl=["width","height"];s.z.enum(Tl);const vl=["start","center","end"],El=["signedWidth","signedHeight"];s.z.enum(El);const qt=s.z.object({x:s.z.number(),y:s.z.number()}),Ol=s.z.object({clientX:s.z.number(),clientY:s.z.number()}),Nl=["x","y"],Gs=s.z.enum(Nl),Js=["top","right","bottom","left"];s.z.enum(Js);const zl=["left","right"],Ks=s.z.enum(zl),Sl=["top","bottom"],Xs=s.z.enum(Sl),Qs=["center"],Pn=s.z.enum(Qs),Il=[...Js,...Qs],ea=s.z.enum(Il);s.z.enum(vl);const Al=["first","last"];s.z.enum(Al);const $l=s.z.object({lower:s.z.number(),upper:s.z.number()}),kl=s.z.object({lower:s.z.bigint(),upper:s.z.bigint()});s.z.union([$l,_t]);s.z.union([kl,_t]);s.z.enum([...Gs.options,...ea.options]);s.z.union([Gs,ea,s.z.instanceof(String)]);const hr=(r,e)=>typeof r=="bigint"?r-BigInt(e):r-Number(e),Cl=(r,e)=>typeof r=="bigint"?r+BigInt(e):r+Number(e),Ln=(r,e)=>typeof r=="bigint"?r===BigInt(e):r===Number(e),xl=(r,e)=>r<=e?r:typeof r=="bigint"?r<=e?r:BigInt(e):r<=e?r:Number(e),Rl=r=>r<0?-r:r,Re=(r,e)=>typeof r=="bigint"?r*BigInt(e):r*Number(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?jl(n):n},jl=r=>r.lower>r.upper?{lower:r.upper,upper:r.lower}:r,Bn=(r,e)=>{const t=V(r);return e<t.lower?t.lower:e>=t.upper?t.upper-(typeof t.upper=="number"?1:1n):e},xt=(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},Ul=r=>({lower:Math.min(...r.map(e=>V(e).lower)),upper:Math.max(...r.map(e=>V(e).upper))}),Dl=(r,e,t)=>{const n=r.map(c=>V(c)),a=t>0?1:t<0?-1:0;if(a===0)return e;let i=t,o=e;for(;Ln(i,0)===!1;){const c=n.findIndex(l=>a>0?o>=l.lower&&o<l.upper:o>l.lower&&o<=l.upper);if(c!==-1){const l=n[c];let h;if(a>0?h=hr(l.upper,o):h=hr(o,l.lower),h>0){const d=xl(Rl(i),h);if(o=Cl(o,a>0?d:-d),i=hr(i,a>0?d:-d),Ln(i,0))return o;continue}}if(a>0){const l=n.filter(h=>h.lower>o);if(l.length>0)o=l[0].lower;else return o}else{const l=n.filter(h=>h.upper<o);if(l.length>0)o=l[l.length-1].upper;else return o}}return o},Ml=(r,e,t)=>{const n=r.map(o=>V(o));if(e===t)return typeof e=="bigint"?0n:0;const a=e<t?V([e,t]):V([t,e]);let i=typeof e=="bigint"?0n:0;for(const o of n){const c=o.lower>a.lower?o.lower:a.lower,l=o.upper<a.upper?o.upper:a.upper;if(c<l){const h=l-c;i=i+h}}return i};s.z.object({x:Ks.or(Pn),y:Xs.or(Pn)});const Zl=s.z.object({x:Ks,y:Xs}),Pl=Object.freeze({x:"left",y:"top"}),Ll=(r,e)=>r.x===e.x&&r.y===e.y,qn=s.z.union([s.z.number(),qt,_t,Hs,bl,Ol]),Bl=(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}},Fn=Object.freeze({x:0,y:0}),Rt=s.z.union([s.z.number(),s.z.string()]);s.z.object({top:Rt,left:Rt,width:Rt,height:Rt});s.z.object({left:s.z.number(),top:s.z.number(),right:s.z.number(),bottom:s.z.number()});s.z.object({one:qt,two:qt,root:Zl});const Qr=(r,e,t=0,n=0,a)=>{const i={one:{...Fn},two:{...Fn},root:a??Pl};if(typeof r=="number"){if(typeof e!="number")throw new Error("Box constructor called with invalid arguments");return i.one={x:r,y:e},i.two={x:i.one.x+t,y:i.one.y+n},i}return"one"in r&&"two"in r&&"root"in r?{...r,root:a??r.root}:("getBoundingClientRect"in r&&(r=r.getBoundingClientRect()),"left"in r?(i.one={x:r.left,y:r.top},i.two={x:r.right,y:r.bottom},i):(i.one=r,e==null?i.two={x:i.one.x+t,y:i.one.y+n}:typeof e=="number"?i.two={x:i.one.x+e,y:i.one.y+t}:"width"in e?i.two={x:i.one.x+e.width,y:i.one.y+e.height}:"signedWidth"in e?i.two={x:i.one.x+e.signedWidth,y:i.one.y+e.signedHeight}:i.two=e,i))},dr=r=>{const e=Qr(r);return{lower:e.one.x,upper:e.two.x}},fr=r=>{const e=Qr(r);return{lower:e.one.y,upper:e.two.y}},ql=r=>typeof r!="object"||r==null?!1:"one"in r&&"two"in r&&"root"in r,Fl=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()});s.z.union([Hs,Fl,qt,_t]);const Yl=(r,e,t)=>e!==void 0&&r<e?e:t!==void 0&&r>t?t:r;s.z.object({offset:qn,scale:qn});s.z.object({offset:s.z.number(),scale:s.z.number()});const Vl=r=>(e,t,n,a)=>t==="dimension"?[e,n]:[e,a?n-r:n+r],Wl=r=>(e,t,n,a)=>[e,a?n/r:n*r],_l=r=>(e,t,n)=>{if(e===null)return[r,n];const{lower:a,upper:i}=e,{lower:o,upper:c}=r,l=i-a,h=c-o;if(t==="dimension")return[r,n*(h/l)];const d=(n-a)*(h/l)+o;return[r,d]},Hl=r=>(e,t,n)=>[r,n],Gl=()=>(r,e,t)=>{if(r===null)throw new Error("cannot invert without bounds");if(e==="dimension")return[r,t];const{lower:n,upper:a}=r;return[r,a-(t-n)]},Jl=r=>(e,t,n)=>{const{lower:a,upper:i}=r;return n=Yl(n,a,i),[e,n]};let Yn=class Me{ops=[];currBounds=null;currType=null;reversed=!1;constructor(){this.ops=[]}static translate(e){return new Me().translate(e)}static magnify(e){return new Me().magnify(e)}static scale(e,t){return new Me().scale(e,t)}translate(e){const t=this.new(),n=Vl(e);return n.type="translate",t.ops.push(n),t}magnify(e){const t=this.new(),n=Wl(e);return n.type="magnify",t.ops.push(n),t}scale(e,t){const n=V(e,t),a=this.new(),i=_l(n);return i.type="scale",a.ops.push(i),a}clamp(e,t){const n=V(e,t),a=this.new(),i=Jl(n);return i.type="clamp",a.ops.push(i),a}reBound(e,t){const n=V(e,t),a=this.new(),i=Hl(n);return i.type="re-bound",a.ops.push(i),a}invert(){const e=Gl();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 Me;return e.ops=this.ops.slice(),e.reversed=this.reversed,e}exec(e,t){return this.currBounds=null,this.ops.reduce(([n,a],i)=>i(n,e,a,this.reversed),[null,t])[1]}reverse(){const e=this.new();e.ops.reverse();const t=[];return e.ops.forEach((n,a)=>{if(n.type==="scale"||t.some(([o,c])=>a>=o&&a<=c))return;const i=e.ops.findIndex((o,c)=>o.type==="scale"&&c>a);i!==-1&&t.push([a,i])}),t.forEach(([n,a])=>{const i=e.ops.slice(n,a);i.unshift(e.ops[a]),e.ops.splice(n,a-n+1,...i)}),e.reversed=!e.reversed,e}get transform(){return{scale:this.dim(1),offset:this.pos(0)}}static IDENTITY=new Me},Um=class te{x;y;currRoot;constructor(e=new Yn,t=new Yn,n=null){this.x=e,this.y=t,this.currRoot=n}static translate(e,t){return new te().translate(e,t)}static translateX(e){return new te().translateX(e)}static translateY(e){return new te().translateY(e)}static clamp(e){return new te().clamp(e)}static magnify(e){return new te().magnify(e)}static scale(e){return new te().scale(e)}static reBound(e){return new te().reBound(e)}translate(e,t){const n=Bl(e,t),a=this.copy();return a.x=this.x.translate(n.x),a.y=this.y.translate(n.y),a}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(ql(e)){const n=this.currRoot;return t.currRoot=e.root,n!=null&&!Ll(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(dr(e)),t.y=t.y.scale(fr(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(dr(e)),t.y=this.y.reBound(fr(e)),t}clamp(e){const t=this.copy();return t.x=this.x.clamp(dr(e)),t.y=this.y.clamp(fr(e)),t}copy(){const e=new te;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 Qr(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 te},Kl=(r,e=21)=>(t=e)=>{let n="",a=t|0;for(;a--;)n+=r[Math.random()*r.length|0];return n};const Xl="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",ta=11,Ql=Kl(Xl,ta),en=()=>Ql(),eu=Object.freeze(Object.defineProperty({__proto__:null,LENGTH:ta,create:en},Symbol.toStringTag,{value:"Module"})),tu=(r,e)=>t=>t instanceof e||typeof t=="object"&&t!==null&&"discriminator"in t&&t.discriminator===r,ru=s.z.enum(["static","dynamic"]),nu=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)])]),ra=(r,e)=>{const t=new O(e);if(![v.DAY,v.HOUR,v.MINUTE,v.SECOND,v.MILLISECOND,v.MICROSECOND,v.NANOSECOND].some(a=>a.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 O?new O(n):new v(n)};let O=class m extends He{constructor(e,t="UTC"){if(e==null)super(m.now().valueOf());else if(e instanceof Date)super(BigInt(e.getTime())*m.MILLISECOND.valueOf());else if(typeof e=="string")super(m.parseDateTimeString(e,t).valueOf());else if(Array.isArray(e))super(m.parseDate(e));else{let n=0n;e instanceof Number&&(e=e.valueOf()),t==="local"&&(n=m.utcOffset.valueOf()),typeof e=="number"&&(isFinite(e)?e=Math.trunc(e):(isNaN(e)&&(e=0),e===1/0?e=m.MAX:e=m.MIN)),super(BigInt(e.valueOf())+n)}}static parseDate([e=1970,t=1,n=1]){const a=new Date(e,t-1,n,0,0,0,0);return new m(BigInt(a.getTime())*m.MILLISECOND.valueOf()).truncate(m.DAY).valueOf()}valueOf(){return this.value}static parseTimeString(e,t="UTC"){const[n,a,i]=e.split(":");let o="00",c="00";i!=null&&([o,c]=i.split("."));let l=m.hours(parseInt(n??"00")).add(m.minutes(parseInt(a??"00"))).add(m.seconds(parseInt(o??"00"))).add(m.milliseconds(parseInt(c??"00")));return t==="local"&&(l=l.add(m.utcOffset)),l.valueOf()}static parseDateTimeString(e,t="UTC"){if(!e.includes("/")&&!e.includes("-"))return m.parseTimeString(e,t);const n=new Date(e);return e.includes(":")||n.setUTCHours(0,0,0,0),new m(BigInt(n.getTime())*m.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(m.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 v(BigInt(new Date().getTimezoneOffset())*m.MINUTE.valueOf())}static since(e){return new m().span(e)}date(){return new Date(this.milliseconds)}equals(e){return this.valueOf()===new m(e).valueOf()}span(e){return this.range(e).span}range(e){return new z(this,e).makeValid()}spanRange(e){return this.range(this.add(e)).makeValid()}get isZero(){return this.valueOf()===0n}after(e){return this.valueOf()>new m(e).valueOf()}afterEq(e){return this.valueOf()>=new m(e).valueOf()}before(e){return this.valueOf()<new m(e).valueOf()}beforeEq(e){return this.valueOf()<=new m(e).valueOf()}add(e){return new m(this.valueOf()+BigInt(e.valueOf()))}sub(e){return new m(this.valueOf()-BigInt(e.valueOf()))}get hours(){return Number(this.valueOf())/Number(v.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(v.MINUTE.valueOf())}get days(){return Number(this.valueOf())/Number(v.DAY.valueOf())}get seconds(){return Number(this.valueOf())/Number(v.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(m.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(m.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 m(t)}get month(){return this.date().getUTCMonth()}setMonth(e){const t=this.date();return t.setUTCMonth(e),new m(t)}get day(){return this.date().getUTCDate()}setDay(e){const t=this.date();return t.setUTCDate(e),new m(t)}get hour(){return this.date().getUTCHours()}setHour(e){const t=this.date();return t.setUTCHours(e),new m(t,"UTC")}get minute(){return this.date().getUTCMinutes()}setMinute(e){const t=this.date();return t.setUTCMinutes(e),new m(t)}get second(){return this.date().getUTCSeconds()}setSecond(e){const t=this.date();return t.setUTCSeconds(e),new m(t)}get millisecond(){return this.date().getUTCMilliseconds()}setMillisecond(e){const t=this.date();return t.setUTCMilliseconds(e),new m(t)}toString(){return this.date().toISOString()}remainder(e){return ra(this,e)}get isToday(){return this.truncate(v.DAY).equals(m.now().truncate(v.DAY))}truncate(e){return this.sub(this.remainder(e))}static now(){return new m(new Date)}static max(...e){let t=m.MIN;for(const n of e){const a=new m(n);a.after(t)&&(t=a)}return t}static min(...e){let t=m.MAX;for(const n of e){const a=new m(n);a.before(t)&&(t=a)}return t}static nanoseconds(e,t="UTC"){return new m(e,t)}static NANOSECOND=m.nanoseconds(1);static microseconds(e,t="UTC"){return m.nanoseconds(e*1e3,t)}static MICROSECOND=m.microseconds(1);static milliseconds(e,t="UTC"){return m.microseconds(e*1e3,t)}static MILLISECOND=m.milliseconds(1);static seconds(e,t="UTC"){return m.milliseconds(e*1e3,t)}static SECOND=m.seconds(1);static minutes(e,t="UTC"){return m.seconds(e*60,t)}static MINUTE=m.minutes(1);static hours(e,t="UTC"){return m.minutes(e*60,t)}static HOUR=m.hours(1);static days(e,t="UTC"){return m.hours(e*24,t)}static DAY=m.days(1);static MAX=new m((1n<<63n)-1n);static MIN=new m(0);static ZERO=new m(0);static z=s.z.union([s.z.instanceof(m),s.z.object({value:s.z.bigint()}).transform(e=>new m(e.value)),s.z.string().transform(e=>new m(BigInt(e))),s.z.number().transform(e=>new m(e)),s.z.bigint().transform(e=>new m(e)),s.z.date().transform(e=>new m(e)),s.z.custom(e=>e instanceof v).transform(e=>new m(e)),nu.transform(e=>new m(e))]);static sort(e,t){return Number(e.valueOf()-t.valueOf())}},v=class b extends He{constructor(e){typeof e=="number"&&(e=Math.trunc(e.valueOf())),super(BigInt(e.valueOf()))}static fromSeconds(e){return e instanceof b?e:e instanceof Rr?e.period:e instanceof O?new b(e):["number","bigint"].includes(typeof e)?b.seconds(e):new b(e)}static fromMilliseconds(e){return e instanceof b?e:e instanceof Rr?e.period:e instanceof O?new b(e):["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 ra(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),a=this.truncate(b.SECOND),i=this.truncate(b.MILLISECOND),o=this.truncate(b.MICROSECOND),c=this.truncate(b.NANOSECOND),l=e,h=t.sub(e),d=n.sub(t),u=a.sub(n),N=i.sub(a),E=o.sub(i),P=c.sub(o);let k="";return l.isZero||(k+=`${l.days}d `),h.isZero||(k+=`${h.hours}h `),d.isZero||(k+=`${d.minutes}m `),u.isZero||(k+=`${u.seconds}s `),N.isZero||(k+=`${N.milliseconds}ms `),E.isZero||(k+=`${E.microseconds}µs `),P.isZero||(k+=`${P.nanoseconds}ns`),k.trim()}mult(e){return new b(this.valueOf()*BigInt(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(Re(e,1e3))}static MICROSECOND=b.microseconds(1);static milliseconds(e=1){return b.microseconds(Re(e,1e3))}static MILLISECOND=b.milliseconds(1);static seconds(e=1){return b.milliseconds(Re(e,1e3))}static SECOND=b.seconds(1);static minutes(e=1){return b.seconds(Re(e,60))}static MINUTE=b.minutes(1);static hours(e){return b.minutes(Re(e,60))}static HOUR=b.hours(1);static days(e){return b.hours(Re(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.instanceof(b)])},Rr=class Ze extends He{constructor(e){super(e.valueOf())}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new Ze(e).valueOf()}get period(){return v.seconds(1/this.valueOf())}sampleCount(e){return new v(e).seconds*this.valueOf()}byteCount(e,t){return this.sampleCount(e)*new W(t).valueOf()}span(e){return v.seconds(e/this.valueOf())}byteSpan(e,t){return this.span(e.valueOf()/t.valueOf())}static hz(e){return new Ze(e)}static khz(e){return Ze.hz(e*1e3)}static z=s.z.union([s.z.number().transform(e=>new Ze(e)),s.z.instanceof(Ze)])},W=class oe extends He{constructor(e){super(e.valueOf())}length(e){return e.valueOf()/this.valueOf()}size(e){return new S(e*this.valueOf())}static UNKNOWN=new oe(0);static BIT128=new oe(16);static BIT64=new oe(8);static BIT32=new oe(4);static BIT16=new oe(2);static BIT8=new oe(1);static z=s.z.union([s.z.number().transform(e=>new oe(e)),s.z.instanceof(oe)])};class z{start;end;constructor(e,t){typeof e=="object"&&"start"in e?(this.start=new O(e.start),this.end=new O(e.end)):(this.start=new O(e),this.end=new O(t))}get span(){return new v(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 z(this.end,this.start)}get numericBounds(){return{lower:Number(this.start.valueOf()),upper:Number(this.end.valueOf())}}equals(e,t=v.ZERO){if(t.isZero)return this.start.equals(e.start)&&this.end.equals(e.end);let n=this.start.sub(e.start).valueOf(),a=this.end.sub(e.end).valueOf();return n<0&&(n=-n),a<0&&(a=-a),n<=t.valueOf()&&a<=t.valueOf()}toString(){return`${this.start.toString()} - ${this.end.toString()}`}toPrettyString(){return`${this.start.fString("preciseDate")} - ${this.span.toString()}`}overlapsWith(e,t=v.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 a=O.max(n.start,e.start),i=O.min(n.end,e.end);return i.before(a)?!1:new v(i.sub(a)).greaterThanOrEqual(t)}contains(e){return e instanceof z?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const t=new z(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 z(O.min(...e.map(t=>t.start)),O.max(...e.map(t=>t.end)))}static MAX=new z(O.MIN,O.MAX);static MIN=new z(O.MAX,O.MIN);static ZERO=new z(O.ZERO,O.ZERO);static z=s.z.union([s.z.object({start:O.z,end:O.z}).transform(e=>new z(e.start,e.end)),s.z.instanceof(z)]);static sort(e,t){return O.sort(e.start,t.start)||O.sort(e.end,t.end)}}let I=class y extends He{constructor(e){if(e instanceof y||typeof e=="string"||typeof e.valueOf()=="string")super(e.valueOf());else{const t=y.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=y.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(y.JSON)||this.equals(y.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(y.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=y.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}get isUnsignedInteger(){return this.equals(y.UINT8)||this.equals(y.UINT16)||this.equals(y.UINT32)||this.equals(y.UINT64)}get isSignedInteger(){return this.equals(y.INT8)||this.equals(y.INT16)||this.equals(y.INT32)||this.equals(y.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(y.INT32)&&e.equals(y.FLOAT64)||this.equals(y.INT8)&&e.equals(y.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 y.BIG_INT_TYPES.some(e=>e.equals(this))}static UNKNOWN=new y("unknown");static FLOAT64=new y("float64");static FLOAT32=new y("float32");static INT64=new y("int64");static INT32=new y("int32");static INT16=new y("int16");static INT8=new y("int8");static UINT64=new y("uint64");static UINT32=new y("uint32");static UINT16=new y("uint16");static UINT8=new y("uint8");static BOOLEAN=this.UINT8;static TIMESTAMP=new y("timestamp");static UUID=new y("uuid");static STRING=new y("string");static JSON=new y("json");static ARRAY_CONSTRUCTORS=new Map([[y.UINT8.toString(),Uint8Array],[y.UINT16.toString(),Uint16Array],[y.UINT32.toString(),Uint32Array],[y.UINT64.toString(),BigUint64Array],[y.FLOAT32.toString(),Float32Array],[y.FLOAT64.toString(),Float64Array],[y.INT8.toString(),Int8Array],[y.INT16.toString(),Int16Array],[y.INT32.toString(),Int32Array],[y.INT64.toString(),BigInt64Array],[y.TIMESTAMP.toString(),BigInt64Array],[y.STRING.toString(),Uint8Array],[y.JSON.toString(),Uint8Array],[y.UUID.toString(),Uint8Array]]);static ARRAY_CONSTRUCTOR_DATA_TYPES=new Map([[Uint8Array.name,y.UINT8],[Uint16Array.name,y.UINT16],[Uint32Array.name,y.UINT32],[BigUint64Array.name,y.UINT64],[Float32Array.name,y.FLOAT32],[Float64Array.name,y.FLOAT64],[Int8Array.name,y.INT8],[Int16Array.name,y.INT16],[Int32Array.name,y.INT32],[BigInt64Array.name,y.INT64]]);static DENSITIES=new Map([[y.UINT8.toString(),W.BIT8],[y.UINT16.toString(),W.BIT16],[y.UINT32.toString(),W.BIT32],[y.UINT64.toString(),W.BIT64],[y.FLOAT32.toString(),W.BIT32],[y.FLOAT64.toString(),W.BIT64],[y.INT8.toString(),W.BIT8],[y.INT16.toString(),W.BIT16],[y.INT32.toString(),W.BIT32],[y.INT64.toString(),W.BIT64],[y.TIMESTAMP.toString(),W.BIT64],[y.STRING.toString(),W.UNKNOWN],[y.JSON.toString(),W.UNKNOWN],[y.UUID.toString(),W.BIT128]]);static ALL=[y.UNKNOWN,y.FLOAT64,y.FLOAT32,y.INT64,y.INT32,y.INT16,y.INT8,y.UINT64,y.UINT32,y.UINT16,y.UINT8,y.TIMESTAMP,y.UUID,y.STRING,y.JSON];static BIG_INT_TYPES=[y.INT64,y.UINT64,y.TIMESTAMP];static z=s.z.union([s.z.string().transform(e=>new y(e)),s.z.instanceof(y)])};class S extends He{constructor(e){super(e.valueOf())}largerThan(e){return this.valueOf()>e.valueOf()}smallerThan(e){return this.valueOf()<e.valueOf()}add(e){return S.bytes(this.valueOf()+e.valueOf())}sub(e){return S.bytes(this.valueOf()-e.valueOf())}truncate(e){return new S(Math.trunc(this.valueOf()/e.valueOf())*e.valueOf())}remainder(e){return S.bytes(this.valueOf()%e.valueOf())}get gigabytes(){return this.valueOf()/S.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/S.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/S.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/S.TERABYTE.valueOf()}toString(){const e=this.truncate(S.TERABYTE),t=this.truncate(S.GIGABYTE),n=this.truncate(S.MEGABYTE),a=this.truncate(S.KILOBYTE),i=this.truncate(S.BYTE),o=e,c=t.sub(e),l=n.sub(t),h=a.sub(n),d=i.sub(a);let u="";return o.isZero||(u+=`${o.terabytes}TB `),c.isZero||(u+=`${c.gigabytes}GB `),l.isZero||(u+=`${l.megabytes}MB `),h.isZero||(u+=`${h.kilobytes}KB `),(!d.isZero||u==="")&&(u+=`${d.valueOf()}B`),u.trim()}static bytes(e=1){return new S(e)}static BYTE=new S(1);static kilobytes(e=1){return S.bytes(e.valueOf()*1e3)}static KILOBYTE=S.kilobytes(1);static megabytes(e=1){return S.kilobytes(e.valueOf()*1e3)}static MEGABYTE=S.megabytes(1);static gigabytes(e=1){return S.megabytes(e.valueOf()*1e3)}static GIGABYTE=S.gigabytes(1);static terabytes(e){return S.gigabytes(e.valueOf()*1e3)}static TERABYTE=S.terabytes(1);static ZERO=new S(0);static z=s.z.union([s.z.number().transform(e=>new S(e)),s.z.instanceof(S)]);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 na=r=>{const e=typeof r;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||r instanceof O||r instanceof v||r instanceof Date},su=(r,e,t,n=0)=>r.usesBigInt&&!e.usesBigInt?Number(t)-Number(n):!r.usesBigInt&&e.usesBigInt?BigInt(t.valueOf())-BigInt(n.valueOf()):Pt(t,-n),Pt=(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),au=/^(?:[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 iu(r){return typeof r=="string"&&au.test(r)}const F=[];for(let r=0;r<256;++r)F.push((r+256).toString(16).slice(1));function ou(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 cu(r,e=0){const t=ou(r,e);if(!iu(t))throw TypeError("Stringified UUID is invalid");return t}typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const sa=(r,e)=>cu(r,e),ge=-1,jr={[Symbol.iterator]:()=>jr,next:()=>({done:!0,value:void 0})},lu=s.z.string().transform(r=>new Uint8Array(atob(r).split("").map(e=>e.charCodeAt(0))).buffer),uu=s.z.union([s.z.null(),s.z.undefined()]).transform(()=>new Uint8Array().buffer),Ur=10,aa=(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`)},ia="sy_x_telem_series";class Y{key;discriminator=ia;dataType;sampleOffset;gl;_data;timeRange=z.ZERO;alignment=0n;cachedMin;cachedMax;writePos=ge;_refCount=0;cachedLength;_cachedIndexes;static crudeZ=s.z.object({timeRange:z.z.optional(),dataType:I.z,alignment:s.z.coerce.bigint().optional(),data:s.z.union([lu,uu,s.z.instanceof(ArrayBuffer),s.z.instanceof(Uint8Array)]),glBufferUsage:ru.optional().default("static").optional()});static z=Y.crudeZ.transform(e=>new Y(e));constructor(e){hu(e)&&(e={data:e}),e.data??=[];const{dataType:t,timeRange:n,sampleOffset:a=0,glBufferUsage:i="static",alignment:o=0n,key:c=en(),data:l}=e;if(oa(l)){const u=l;this.key=u.key,this.dataType=u.dataType,this.sampleOffset=u.sampleOffset,this.gl=u.gl,this._data=u._data,this.timeRange=u.timeRange,this.alignment=u.alignment,this.cachedMin=u.cachedMin,this.cachedMax=u.cachedMax,this.writePos=u.writePos,this._refCount=u._refCount,this.cachedLength=u.cachedLength;return}const h=na(l),d=Array.isArray(l);if(t!=null)this.dataType=new I(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(d||h){let u=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.");u=l[0]}if(typeof u=="string")this.dataType=I.STRING;else if(typeof u=="number")this.dataType=I.FLOAT64;else if(typeof u=="bigint")this.dataType=I.INT64;else if(typeof u=="boolean")this.dataType=I.BOOLEAN;else if(u instanceof O||u instanceof Date||u instanceof O)this.dataType=I.TIMESTAMP;else if(typeof u=="object")this.dataType=I.JSON;else throw new Error(`cannot infer data type of ${typeof u} when constructing a Series from a JS array`)}else this.dataType=new I(l)}if(!d&&!h)this._data=l;else if(d&&l.length===0)this._data=new this.dataType.Array([]).buffer;else{let u=h?[l]:l;const N=u[0];(N instanceof O||N instanceof Date||N instanceof v)&&(u=u.map(E=>new O(E).valueOf())),this.dataType.equals(I.STRING)?(this.cachedLength=u.length,this._data=new TextEncoder().encode(`${u.join(`
|
|
8
|
+
`).map(c=>c.trim());if(n.length===0)return t!=null?t.parse({}):{};const i=n.split(",").map(c=>c.trim()),o={};return i.forEach(c=>{o[c]=[]}),a.forEach(c=>{const l=c.split(",").map(h=>h.trim());i.forEach((h,d)=>{const u=this.parseValue(l[d]);u!=null&&o[h].push(u)})}),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}},qs=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 lt=new Ls,ul=new Bs,hl=new qs,dl=[lt],ke=Object.freeze(Object.defineProperty({__proto__:null,CSVCodec:Bs,CSV_CODEC:ul,ENCODERS:dl,JSONCodec:Ls,JSON_CODEC:lt,TEXT_CODEC:hl,TextCodec:qs},Symbol.toStringTag,{value:"Module"})),jr=r=>[...new Set(r)],fl=(r,e,t=!0)=>{const n=new Map;return r.forEach(a=>{const i=e(a);if(n.has(i)){if(t)return;n.delete(i)}n.set(i,a)}),Array.from(n.values())},Mn=Object.freeze(Object.defineProperty({__proto__:null,by:fl,unique:jr},Symbol.toStringTag,{value:"Module"}));class He{value;constructor(e){this.value=e}valueOf(){return this.value}toJSON(){return this.value}toString(){return this.value.toString()}}const yl=r=>r!=null&&typeof r=="object"&&"toString"in r,Gt=(r,e=!1)=>{const t=yl(r)?"stringer":typeof r;let n;switch(t){case"string":n=(a,i)=>a.localeCompare(i);break;case"stringer":n=(a,i)=>a.toString().localeCompare(i.toString());break;case"number":n=(a,i)=>Number(a)-Number(i);break;case"bigint":n=(a,i)=>BigInt(a)-BigInt(i)>0n?1:-1;break;case"boolean":n=(a,i)=>Number(a)-Number(i);break;case"undefined":n=()=>0;break;default:return console.warn(`sortFunc: unknown type ${t}`),()=>-1}return e?Ys(n):n},gl=(r,e,t)=>{const n=Gt(e[r],t);return(a,i)=>n(a[r],i[r])},pl=(r,e)=>r.length!==e.length?r.length-e.length:r.every((t,n)=>t===e[n])?0:-1,Fs=(r,e)=>{if(r.length!==e.length)return r.length-e.length;if(r.length===0)return 0;const t=Gt(r[0]),n=[...r].sort(t),a=[...e].sort(t);return n.every((i,o)=>i===a[o])?0:-1},ml=(r,e)=>{const t=jr(r),n=jr(e);return Fs(t,n)},wl=(r,e)=>r===e?0:r==="first"&&e==="last"?1:-1,Ys=r=>(e,t)=>r(t,e),Ge=0,Pt=-1,Lt=1,Vs=r=>r<Ge,Ws=r=>r>Ge,bl=r=>r>=Ge,_s=r=>r===Ge,Tl=(r,e)=>{const t=/([a-zA-Z]+)|(\d+)/g,n=r.replace(/[\s_.-]+/g,"").match(t),a=e.replace(/[\s_.-]+/g,"").match(t);if(!n||!a)return 0;for(let i=0;i<Math.min(n.length,a.length);i++){const o=n[i],c=a[i];if(isNaN(Number(o))&&isNaN(Number(c))){const l=o.localeCompare(c);if(l!==0)return l}else if(!isNaN(Number(o))&&!isNaN(Number(c))){const l=Number(o)-Number(c);if(l!==0)return l}else return isNaN(Number(o))?-1:1}return n.length-a.length},Zn=Object.freeze(Object.defineProperty({__proto__:null,EQUAL:Ge,GREATER_THAN:Lt,LESS_THAN:Pt,isEqualTo:_s,isGreaterThan:Ws,isGreaterThanEqual:bl,isLessThan:Vs,newF:Gt,newFieldF:gl,order:wl,primitiveArrays:pl,reverseF:Ys,stringsWithNumbers:Tl,uniqueUnorderedPrimitiveArrays:ml,unorderedPrimitiveArrays:Fs},Symbol.toStringTag,{value:"Module"})),Kt=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()}),vl=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()}),El=["width","height"];s.z.enum(El);const Ol=["start","center","end"],Nl=["signedWidth","signedHeight"];s.z.enum(Nl);const Yt=s.z.object({x:s.z.number(),y:s.z.number()}),zl=s.z.object({clientX:s.z.number(),clientY:s.z.number()}),Sl=["x","y"],Gs=s.z.enum(Sl),Ks=["top","right","bottom","left"];s.z.enum(Ks);const Il=["left","right"],Js=s.z.enum(Il),Al=["top","bottom"],Xs=s.z.enum(Al),Qs=["center"],Pn=s.z.enum(Qs),$l=[...Ks,...Qs],ea=s.z.enum($l);s.z.enum(Ol);const kl=["first","last"];s.z.enum(kl);const Cl=s.z.object({lower:s.z.number(),upper:s.z.number()}),xl=s.z.object({lower:s.z.bigint(),upper:s.z.bigint()});s.z.union([Cl,Kt]);s.z.union([xl,Kt]);s.z.enum([...Gs.options,...ea.options]);s.z.union([Gs,ea,s.z.instanceof(String)]);const fr=(r,e)=>typeof r=="bigint"?r-BigInt(e):r-Number(e),Rl=(r,e)=>typeof r=="bigint"?r+BigInt(e):r+Number(e),Ln=(r,e)=>typeof r=="bigint"?r===BigInt(e):r===Number(e),jl=(r,e)=>r<=e?r:typeof r=="bigint"?r<=e?r:BigInt(e):r<=e?r:Number(e),Ul=r=>r<0?-r:r,je=(r,e)=>typeof r=="bigint"?r*BigInt(e):r*Number(e),Y=(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?Dl(n):n},Dl=r=>r.lower>r.upper?{lower:r.upper,upper:r.lower}:r,Bn=(r,e)=>{const t=Y(r);return e<t.lower?t.lower:e>=t.upper?t.upper-(typeof t.upper=="number"?1:1n):e},jt=(r,e)=>{const t=Y(r);if(typeof e=="number"||typeof e=="bigint")return e>=t.lower&&e<t.upper;const n=Y(e);return n.lower>=t.lower&&n.upper<=t.upper},Ml=r=>({lower:Math.min(...r.map(e=>Y(e).lower)),upper:Math.max(...r.map(e=>Y(e).upper))}),Zl=(r,e,t)=>{const n=r.map(c=>Y(c)),a=t>0?1:t<0?-1:0;if(a===0)return e;let i=t,o=e;for(;Ln(i,0)===!1;){const c=n.findIndex(l=>a>0?o>=l.lower&&o<l.upper:o>l.lower&&o<=l.upper);if(c!==-1){const l=n[c];let h;if(a>0?h=fr(l.upper,o):h=fr(o,l.lower),h>0){const d=jl(Ul(i),h);if(o=Rl(o,a>0?d:-d),i=fr(i,a>0?d:-d),Ln(i,0))return o;continue}}if(a>0){const l=n.filter(h=>h.lower>o);if(l.length>0)o=l[0].lower;else return o}else{const l=n.filter(h=>h.upper<o);if(l.length>0)o=l[l.length-1].upper;else return o}}return o},Pl=(r,e,t)=>{const n=r.map(o=>Y(o));if(e===t)return typeof e=="bigint"?0n:0;const a=e<t?Y([e,t]):Y([t,e]);let i=typeof e=="bigint"?0n:0;for(const o of n){const c=o.lower>a.lower?o.lower:a.lower,l=o.upper<a.upper?o.upper:a.upper;if(c<l){const h=l-c;i=i+h}}return i};s.z.object({x:Js.or(Pn),y:Xs.or(Pn)});const Ll=s.z.object({x:Js,y:Xs}),Bl=Object.freeze({x:"left",y:"top"}),ql=(r,e)=>r.x===e.x&&r.y===e.y,qn=s.z.union([s.z.number(),Yt,Kt,Hs,vl,zl]),Fl=(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}},Fn=Object.freeze({x:0,y:0}),Ut=s.z.union([s.z.number(),s.z.string()]);s.z.object({top:Ut,left:Ut,width:Ut,height:Ut});s.z.object({left:s.z.number(),top:s.z.number(),right:s.z.number(),bottom:s.z.number()});s.z.object({one:Yt,two:Yt,root:Ll});const tn=(r,e,t=0,n=0,a)=>{const i={one:{...Fn},two:{...Fn},root:a??Bl};if(typeof r=="number"){if(typeof e!="number")throw new Error("Box constructor called with invalid arguments");return i.one={x:r,y:e},i.two={x:i.one.x+t,y:i.one.y+n},i}return"one"in r&&"two"in r&&"root"in r?{...r,root:a??r.root}:("getBoundingClientRect"in r&&(r=r.getBoundingClientRect()),"left"in r?(i.one={x:r.left,y:r.top},i.two={x:r.right,y:r.bottom},i):(i.one=r,e==null?i.two={x:i.one.x+t,y:i.one.y+n}:typeof e=="number"?i.two={x:i.one.x+e,y:i.one.y+t}:"width"in e?i.two={x:i.one.x+e.width,y:i.one.y+e.height}:"signedWidth"in e?i.two={x:i.one.x+e.signedWidth,y:i.one.y+e.signedHeight}:i.two=e,i))},yr=r=>{const e=tn(r);return{lower:e.one.x,upper:e.two.x}},gr=r=>{const e=tn(r);return{lower:e.one.y,upper:e.two.y}},Yl=r=>typeof r!="object"||r==null?!1:"one"in r&&"two"in r&&"root"in r,Vl=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()});s.z.union([Hs,Vl,Yt,Kt]);const Wl=(r,e,t)=>e!==void 0&&r<e?e:t!==void 0&&r>t?t:r;s.z.object({offset:qn,scale:qn});s.z.object({offset:s.z.number(),scale:s.z.number()});const _l=r=>(e,t,n,a)=>t==="dimension"?[e,n]:[e,a?n-r:n+r],Hl=r=>(e,t,n,a)=>[e,a?n/r:n*r],Gl=r=>(e,t,n)=>{if(e===null)return[r,n];const{lower:a,upper:i}=e,{lower:o,upper:c}=r,l=i-a,h=c-o;if(t==="dimension")return[r,n*(h/l)];const d=(n-a)*(h/l)+o;return[r,d]},Kl=r=>(e,t,n)=>[r,n],Jl=()=>(r,e,t)=>{if(r===null)throw new Error("cannot invert without bounds");if(e==="dimension")return[r,t];const{lower:n,upper:a}=r;return[r,a-(t-n)]},Xl=r=>(e,t,n)=>{const{lower:a,upper:i}=r;return n=Wl(n,a,i),[e,n]};let Yn=class Ze{ops=[];currBounds=null;currType=null;reversed=!1;constructor(){this.ops=[]}static translate(e){return new Ze().translate(e)}static magnify(e){return new Ze().magnify(e)}static scale(e,t){return new Ze().scale(e,t)}translate(e){const t=this.new(),n=_l(e);return n.type="translate",t.ops.push(n),t}magnify(e){const t=this.new(),n=Hl(e);return n.type="magnify",t.ops.push(n),t}scale(e,t){const n=Y(e,t),a=this.new(),i=Gl(n);return i.type="scale",a.ops.push(i),a}clamp(e,t){const n=Y(e,t),a=this.new(),i=Xl(n);return i.type="clamp",a.ops.push(i),a}reBound(e,t){const n=Y(e,t),a=this.new(),i=Kl(n);return i.type="re-bound",a.ops.push(i),a}invert(){const e=Jl();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 Ze;return e.ops=this.ops.slice(),e.reversed=this.reversed,e}exec(e,t){return this.currBounds=null,this.ops.reduce(([n,a],i)=>i(n,e,a,this.reversed),[null,t])[1]}reverse(){const e=this.new();e.ops.reverse();const t=[];return e.ops.forEach((n,a)=>{if(n.type==="scale"||t.some(([o,c])=>a>=o&&a<=c))return;const i=e.ops.findIndex((o,c)=>o.type==="scale"&&c>a);i!==-1&&t.push([a,i])}),t.forEach(([n,a])=>{const i=e.ops.slice(n,a);i.unshift(e.ops[a]),e.ops.splice(n,a-n+1,...i)}),e.reversed=!e.reversed,e}get transform(){return{scale:this.dim(1),offset:this.pos(0)}}static IDENTITY=new Ze},Pm=class re{x;y;currRoot;constructor(e=new Yn,t=new Yn,n=null){this.x=e,this.y=t,this.currRoot=n}static translate(e,t){return new re().translate(e,t)}static translateX(e){return new re().translateX(e)}static translateY(e){return new re().translateY(e)}static clamp(e){return new re().clamp(e)}static magnify(e){return new re().magnify(e)}static scale(e){return new re().scale(e)}static reBound(e){return new re().reBound(e)}translate(e,t){const n=Fl(e,t),a=this.copy();return a.x=this.x.translate(n.x),a.y=this.y.translate(n.y),a}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(Yl(e)){const n=this.currRoot;return t.currRoot=e.root,n!=null&&!ql(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(yr(e)),t.y=t.y.scale(gr(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(yr(e)),t.y=this.y.reBound(gr(e)),t}clamp(e){const t=this.copy();return t.x=this.x.clamp(yr(e)),t.y=this.y.clamp(gr(e)),t}copy(){const e=new re;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 tn(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 re},Ql=(r,e=21)=>(t=e)=>{let n="",a=t|0;for(;a--;)n+=r[Math.random()*r.length|0];return n};const eu="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",ta=11,tu=Ql(eu,ta),rn=()=>tu(),ru=Object.freeze(Object.defineProperty({__proto__:null,LENGTH:ta,create:rn},Symbol.toStringTag,{value:"Module"})),nu=(r,e)=>t=>t instanceof e||typeof t=="object"&&t!==null&&"discriminator"in t&&t.discriminator===r,su=s.z.enum(["static","dynamic"]),au=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)])]),ra=(r,e)=>{const t=new O(e);if(![E.DAY,E.HOUR,E.MINUTE,E.SECOND,E.MILLISECOND,E.MICROSECOND,E.NANOSECOND].some(a=>a.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 O?new O(n):new E(n)};let O=class m extends He{constructor(e,t="UTC"){if(e==null)super(m.now().valueOf());else if(e instanceof Date)super(BigInt(e.getTime())*m.MILLISECOND.valueOf());else if(typeof e=="string")super(m.parseDateTimeString(e,t).valueOf());else if(Array.isArray(e))super(m.parseDate(e));else{let n=0n;e instanceof Number&&(e=e.valueOf()),t==="local"&&(n=m.utcOffset.valueOf()),typeof e=="number"&&(isFinite(e)?e=Math.trunc(e):(isNaN(e)&&(e=0),e===1/0?e=m.MAX:e=m.MIN)),super(BigInt(e.valueOf())+n)}}static parseDate([e=1970,t=1,n=1]){const a=new Date(e,t-1,n,0,0,0,0);return new m(BigInt(a.getTime())*m.MILLISECOND.valueOf()).truncate(m.DAY).valueOf()}valueOf(){return this.value}static parseTimeString(e,t="UTC"){const[n,a,i]=e.split(":");let o="00",c="00";i!=null&&([o,c]=i.split("."));let l=m.hours(parseInt(n??"00")).add(m.minutes(parseInt(a??"00"))).add(m.seconds(parseInt(o??"00"))).add(m.milliseconds(parseInt(c??"00")));return t==="local"&&(l=l.add(m.utcOffset)),l.valueOf()}static parseDateTimeString(e,t="UTC"){if(!e.includes("/")&&!e.includes("-"))return m.parseTimeString(e,t);const n=new Date(e);return e.includes(":")||n.setUTCHours(0,0,0,0),new m(BigInt(n.getTime())*m.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(m.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())*m.MINUTE.valueOf())}static since(e){return new m().span(e)}date(){return new Date(this.milliseconds)}equals(e){return this.valueOf()===new m(e).valueOf()}span(e){return this.range(e).span}range(e){return new z(this,e).makeValid()}spanRange(e){return this.range(this.add(e)).makeValid()}get isZero(){return this.valueOf()===0n}after(e){return this.valueOf()>new m(e).valueOf()}afterEq(e){return this.valueOf()>=new m(e).valueOf()}before(e){return this.valueOf()<new m(e).valueOf()}beforeEq(e){return this.valueOf()<=new m(e).valueOf()}add(e){return new m(this.valueOf()+BigInt(e.valueOf()))}sub(e){return new m(this.valueOf()-BigInt(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(m.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(m.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 m(t)}get month(){return this.date().getUTCMonth()}setMonth(e){const t=this.date();return t.setUTCMonth(e),new m(t)}get day(){return this.date().getUTCDate()}setDay(e){const t=this.date();return t.setUTCDate(e),new m(t)}get hour(){return this.date().getUTCHours()}setHour(e){const t=this.date();return t.setUTCHours(e),new m(t,"UTC")}get minute(){return this.date().getUTCMinutes()}setMinute(e){const t=this.date();return t.setUTCMinutes(e),new m(t)}get second(){return this.date().getUTCSeconds()}setSecond(e){const t=this.date();return t.setUTCSeconds(e),new m(t)}get millisecond(){return this.date().getUTCMilliseconds()}setMillisecond(e){const t=this.date();return t.setUTCMilliseconds(e),new m(t)}toString(){return this.date().toISOString()}remainder(e){return ra(this,e)}get isToday(){return this.truncate(E.DAY).equals(m.now().truncate(E.DAY))}truncate(e){return this.sub(this.remainder(e))}static now(){return new m(new Date)}static max(...e){let t=m.MIN;for(const n of e){const a=new m(n);a.after(t)&&(t=a)}return t}static min(...e){let t=m.MAX;for(const n of e){const a=new m(n);a.before(t)&&(t=a)}return t}static nanoseconds(e,t="UTC"){return new m(e,t)}static NANOSECOND=m.nanoseconds(1);static microseconds(e,t="UTC"){return m.nanoseconds(e*1e3,t)}static MICROSECOND=m.microseconds(1);static milliseconds(e,t="UTC"){return m.microseconds(e*1e3,t)}static MILLISECOND=m.milliseconds(1);static seconds(e,t="UTC"){return m.milliseconds(e*1e3,t)}static SECOND=m.seconds(1);static minutes(e,t="UTC"){return m.seconds(e*60,t)}static MINUTE=m.minutes(1);static hours(e,t="UTC"){return m.minutes(e*60,t)}static HOUR=m.hours(1);static days(e,t="UTC"){return m.hours(e*24,t)}static DAY=m.days(1);static MAX=new m((1n<<63n)-1n);static MIN=new m(0);static ZERO=new m(0);static z=s.z.union([s.z.instanceof(m),s.z.object({value:s.z.bigint()}).transform(e=>new m(e.value)),s.z.string().transform(e=>new m(BigInt(e))),s.z.number().transform(e=>new m(e)),s.z.bigint().transform(e=>new m(e)),s.z.date().transform(e=>new m(e)),s.z.custom(e=>e instanceof E).transform(e=>new m(e)),au.transform(e=>new m(e))]);static sort(e,t){return Number(e.valueOf()-t.valueOf())}},E=class b extends He{constructor(e){typeof e=="number"&&(e=Math.trunc(e.valueOf())),super(BigInt(e.valueOf()))}static fromSeconds(e){return e instanceof b?e:e instanceof Ur?e.period:e instanceof O?new b(e):["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 O?new b(e):["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 ra(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),a=this.truncate(b.SECOND),i=this.truncate(b.MILLISECOND),o=this.truncate(b.MICROSECOND),c=this.truncate(b.NANOSECOND),l=e,h=t.sub(e),d=n.sub(t),u=a.sub(n),N=i.sub(a),v=o.sub(i),P=c.sub(o);let k="";return l.isZero||(k+=`${l.days}d `),h.isZero||(k+=`${h.hours}h `),d.isZero||(k+=`${d.minutes}m `),u.isZero||(k+=`${u.seconds}s `),N.isZero||(k+=`${N.milliseconds}ms `),v.isZero||(k+=`${v.microseconds}µs `),P.isZero||(k+=`${P.nanoseconds}ns`),k.trim()}mult(e){return new b(this.valueOf()*BigInt(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(je(e,1e3))}static MICROSECOND=b.microseconds(1);static milliseconds(e=1){return b.microseconds(je(e,1e3))}static MILLISECOND=b.milliseconds(1);static seconds(e=1){return b.milliseconds(je(e,1e3))}static SECOND=b.seconds(1);static minutes(e=1){return b.seconds(je(e,60))}static MINUTE=b.minutes(1);static hours(e){return b.minutes(je(e,60))}static HOUR=b.hours(1);static days(e){return b.hours(je(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.instanceof(b)])},Ur=class Pe extends He{constructor(e){super(e.valueOf())}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new Pe(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 _(t).valueOf()}span(e){return E.seconds(e/this.valueOf())}byteSpan(e,t){return this.span(e.valueOf()/t.valueOf())}static hz(e){return new Pe(e)}static khz(e){return Pe.hz(e*1e3)}static z=s.z.union([s.z.number().transform(e=>new Pe(e)),s.z.instanceof(Pe)])},_=class ce extends He{constructor(e){super(e.valueOf())}length(e){return e.valueOf()/this.valueOf()}size(e){return new S(e*this.valueOf())}static UNKNOWN=new ce(0);static BIT128=new ce(16);static BIT64=new ce(8);static BIT32=new ce(4);static BIT16=new ce(2);static BIT8=new ce(1);static z=s.z.union([s.z.number().transform(e=>new ce(e)),s.z.instanceof(ce)])};class z{start;end;constructor(e,t){typeof e=="object"&&"start"in e?(this.start=new O(e.start),this.end=new O(e.end)):(this.start=new O(e),this.end=new O(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 z(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(),a=this.end.sub(e.end).valueOf();return n<0&&(n=-n),a<0&&(a=-a),n<=t.valueOf()&&a<=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 a=O.max(n.start,e.start),i=O.min(n.end,e.end);return i.before(a)?!1:new E(i.sub(a)).greaterThanOrEqual(t)}contains(e){return e instanceof z?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const t=new z(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 z(O.min(...e.map(t=>t.start)),O.max(...e.map(t=>t.end)))}static MAX=new z(O.MIN,O.MAX);static MIN=new z(O.MAX,O.MIN);static ZERO=new z(O.ZERO,O.ZERO);static z=s.z.union([s.z.object({start:O.z,end:O.z}).transform(e=>new z(e.start,e.end)),s.z.instanceof(z)]);static sort(e,t){return O.sort(e.start,t.start)||O.sort(e.end,t.end)}}let I=class y extends He{constructor(e){if(e instanceof y||typeof e=="string"||typeof e.valueOf()=="string")super(e.valueOf());else{const t=y.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=y.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(y.JSON)||this.equals(y.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(y.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=y.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}get isUnsignedInteger(){return this.equals(y.UINT8)||this.equals(y.UINT16)||this.equals(y.UINT32)||this.equals(y.UINT64)}get isSignedInteger(){return this.equals(y.INT8)||this.equals(y.INT16)||this.equals(y.INT32)||this.equals(y.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(y.INT32)&&e.equals(y.FLOAT64)||this.equals(y.INT8)&&e.equals(y.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 y.BIG_INT_TYPES.some(e=>e.equals(this))}static UNKNOWN=new y("unknown");static FLOAT64=new y("float64");static FLOAT32=new y("float32");static INT64=new y("int64");static INT32=new y("int32");static INT16=new y("int16");static INT8=new y("int8");static UINT64=new y("uint64");static UINT32=new y("uint32");static UINT16=new y("uint16");static UINT8=new y("uint8");static BOOLEAN=this.UINT8;static TIMESTAMP=new y("timestamp");static UUID=new y("uuid");static STRING=new y("string");static JSON=new y("json");static ARRAY_CONSTRUCTORS=new Map([[y.UINT8.toString(),Uint8Array],[y.UINT16.toString(),Uint16Array],[y.UINT32.toString(),Uint32Array],[y.UINT64.toString(),BigUint64Array],[y.FLOAT32.toString(),Float32Array],[y.FLOAT64.toString(),Float64Array],[y.INT8.toString(),Int8Array],[y.INT16.toString(),Int16Array],[y.INT32.toString(),Int32Array],[y.INT64.toString(),BigInt64Array],[y.TIMESTAMP.toString(),BigInt64Array],[y.STRING.toString(),Uint8Array],[y.JSON.toString(),Uint8Array],[y.UUID.toString(),Uint8Array]]);static ARRAY_CONSTRUCTOR_DATA_TYPES=new Map([[Uint8Array.name,y.UINT8],[Uint16Array.name,y.UINT16],[Uint32Array.name,y.UINT32],[BigUint64Array.name,y.UINT64],[Float32Array.name,y.FLOAT32],[Float64Array.name,y.FLOAT64],[Int8Array.name,y.INT8],[Int16Array.name,y.INT16],[Int32Array.name,y.INT32],[BigInt64Array.name,y.INT64]]);static DENSITIES=new Map([[y.UINT8.toString(),_.BIT8],[y.UINT16.toString(),_.BIT16],[y.UINT32.toString(),_.BIT32],[y.UINT64.toString(),_.BIT64],[y.FLOAT32.toString(),_.BIT32],[y.FLOAT64.toString(),_.BIT64],[y.INT8.toString(),_.BIT8],[y.INT16.toString(),_.BIT16],[y.INT32.toString(),_.BIT32],[y.INT64.toString(),_.BIT64],[y.TIMESTAMP.toString(),_.BIT64],[y.STRING.toString(),_.UNKNOWN],[y.JSON.toString(),_.UNKNOWN],[y.UUID.toString(),_.BIT128]]);static ALL=[y.UNKNOWN,y.FLOAT64,y.FLOAT32,y.INT64,y.INT32,y.INT16,y.INT8,y.UINT64,y.UINT32,y.UINT16,y.UINT8,y.TIMESTAMP,y.UUID,y.STRING,y.JSON];static BIG_INT_TYPES=[y.INT64,y.UINT64,y.TIMESTAMP];static z=s.z.union([s.z.string().transform(e=>new y(e)),s.z.instanceof(y)])};class S extends He{constructor(e){super(e.valueOf())}largerThan(e){return this.valueOf()>e.valueOf()}smallerThan(e){return this.valueOf()<e.valueOf()}add(e){return S.bytes(this.valueOf()+e.valueOf())}sub(e){return S.bytes(this.valueOf()-e.valueOf())}truncate(e){return new S(Math.trunc(this.valueOf()/e.valueOf())*e.valueOf())}remainder(e){return S.bytes(this.valueOf()%e.valueOf())}get gigabytes(){return this.valueOf()/S.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/S.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/S.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/S.TERABYTE.valueOf()}toString(){const e=this.truncate(S.TERABYTE),t=this.truncate(S.GIGABYTE),n=this.truncate(S.MEGABYTE),a=this.truncate(S.KILOBYTE),i=this.truncate(S.BYTE),o=e,c=t.sub(e),l=n.sub(t),h=a.sub(n),d=i.sub(a);let u="";return o.isZero||(u+=`${o.terabytes}TB `),c.isZero||(u+=`${c.gigabytes}GB `),l.isZero||(u+=`${l.megabytes}MB `),h.isZero||(u+=`${h.kilobytes}KB `),(!d.isZero||u==="")&&(u+=`${d.valueOf()}B`),u.trim()}static bytes(e=1){return new S(e)}static BYTE=new S(1);static kilobytes(e=1){return S.bytes(e.valueOf()*1e3)}static KILOBYTE=S.kilobytes(1);static megabytes(e=1){return S.kilobytes(e.valueOf()*1e3)}static MEGABYTE=S.megabytes(1);static gigabytes(e=1){return S.megabytes(e.valueOf()*1e3)}static GIGABYTE=S.gigabytes(1);static terabytes(e){return S.gigabytes(e.valueOf()*1e3)}static TERABYTE=S.terabytes(1);static ZERO=new S(0);static z=s.z.union([s.z.number().transform(e=>new S(e)),s.z.instanceof(S)]);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 na=r=>{const e=typeof r;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||r instanceof O||r instanceof E||r instanceof Date},iu=(r,e,t,n=0)=>r.usesBigInt&&!e.usesBigInt?Number(t)-Number(n):!r.usesBigInt&&e.usesBigInt?BigInt(t.valueOf())-BigInt(n.valueOf()):Bt(t,-n),Bt=(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),ou=/^(?:[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 cu(r){return typeof r=="string"&&ou.test(r)}const q=[];for(let r=0;r<256;++r)q.push((r+256).toString(16).slice(1));function lu(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 uu(r,e=0){const t=lu(r,e);if(!cu(t))throw TypeError("Stringified UUID is invalid");return t}typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const sa=(r,e)=>uu(r,e),pe=-1,Dr={[Symbol.iterator]:()=>Dr,next:()=>({done:!0,value:void 0})},hu=s.z.string().transform(r=>new Uint8Array(atob(r).split("").map(e=>e.charCodeAt(0))).buffer),du=s.z.union([s.z.null(),s.z.undefined()]).transform(()=>new Uint8Array().buffer),Mr=10,aa=(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`)},ia="sy_x_telem_series";class F{key;discriminator=ia;dataType;sampleOffset;gl;_data;timeRange=z.ZERO;alignment=0n;cachedMin;cachedMax;writePos=pe;_refCount=0;cachedLength;_cachedIndexes;static crudeZ=s.z.object({timeRange:z.z.optional(),dataType:I.z,alignment:s.z.coerce.bigint().optional(),data:s.z.union([hu,du,s.z.instanceof(ArrayBuffer),s.z.instanceof(Uint8Array)]),glBufferUsage:su.optional().default("static").optional()});static z=F.crudeZ.transform(e=>new F(e));constructor(e){fu(e)&&(e={data:e}),e.data??=[];const{dataType:t,timeRange:n,sampleOffset:a=0,glBufferUsage:i="static",alignment:o=0n,key:c=rn(),data:l}=e;if(oa(l)){const u=l;this.key=u.key,this.dataType=u.dataType,this.sampleOffset=u.sampleOffset,this.gl=u.gl,this._data=u._data,this.timeRange=u.timeRange,this.alignment=u.alignment,this.cachedMin=u.cachedMin,this.cachedMax=u.cachedMax,this.writePos=u.writePos,this._refCount=u._refCount,this.cachedLength=u.cachedLength;return}const h=na(l),d=Array.isArray(l);if(t!=null)this.dataType=new I(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(d||h){let u=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.");u=l[0]}if(typeof u=="string")this.dataType=I.STRING;else if(typeof u=="number")this.dataType=I.FLOAT64;else if(typeof u=="bigint")this.dataType=I.INT64;else if(typeof u=="boolean")this.dataType=I.BOOLEAN;else if(u instanceof O||u instanceof Date||u instanceof O)this.dataType=I.TIMESTAMP;else if(typeof u=="object")this.dataType=I.JSON;else throw new Error(`cannot infer data type of ${typeof u} when constructing a Series from a JS array`)}else this.dataType=new I(l)}if(!d&&!h)this._data=l;else if(d&&l.length===0)this._data=new this.dataType.Array([]).buffer;else{let u=h?[l]:l;const N=u[0];(N instanceof O||N instanceof Date||N instanceof E)&&(u=u.map(v=>new O(v).valueOf())),this.dataType.equals(I.STRING)?(this.cachedLength=u.length,this._data=new TextEncoder().encode(`${u.join(`
|
|
9
9
|
`)}
|
|
10
|
-
`).buffer):this.dataType.equals(I.JSON)?(this.cachedLength=u.length,this._data=new TextEncoder().encode(`${u.map(
|
|
10
|
+
`).buffer):this.dataType.equals(I.JSON)?(this.cachedLength=u.length,this._data=new TextEncoder().encode(`${u.map(v=>lt.encodeString(v)).join(`
|
|
11
11
|
`)}
|
|
12
|
-
`).buffer):this.dataType.usesBigInt&&typeof N=="number"?this._data=new this.dataType.Array(u.map(
|
|
13
|
-
`).slice(0,-1):Array.from(this).map(e=>e.toString())}parseJSON(e){if(!this.dataType.equals(I.JSON))throw new Error("cannot parse non-JSON series as JSON");return this.toStrings().map(t=>e.parse(lt.decodeString(t)))}get byteCapacity(){return new S(this.underlyingData.byteLength)}get capacity(){return this.dataType.isVariable?this.byteCapacity.valueOf():this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===ge?this.byteCapacity:this.dataType.isVariable?new S(this.writePos):this.dataType.density.size(this.writePos)}get length(){return this.cachedLength!=null?this.cachedLength:this.dataType.isVariable?this.calculateCachedLength():this.writePos===ge?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,a)=>{n===Ur&&(e++,t.push(a+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 a=0;a<this.length;a++)n[a]=su(this.dataType,e,this.data[a],t);return new Y({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(I.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(),Pt(this.cachedMax,this.sampleOffset))}calcRawMin(){if(this.length===0)return 1/0;if(this.dataType.equals(I.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(),Pt(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);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(I.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 Pt(n,this.sampleOffset)}atUUID(e,t){e<0&&(e=this.length+e);const n=sa(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,a=0;if(this._cachedIndexes!=null)n=this._cachedIndexes[e],a=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]===Ur){if(e===0){a=o;break}n=o+1,e--}if(a===0&&(a=this.data.length),n>=a||e>0){if(t)throw new Error(`[series] - no value at index ${e}`);return}}const i=this.data.slice(n,a);return this.dataType.equals(I.STRING)?new TextDecoder().decode(i):Xr(JSON.parse(new TextDecoder().decode(i)))}binarySearch(e){let t=0,n=this.length-1;const a=Wt(e);for(;t<=n;){const i=Math.floor((t+n)/2),o=a(this.at(i,!0),e);if(o===0)return i;o<0?t=i+1:n=i-1}return t}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals(I.FLOAT32)&&!this.dataType.equals(I.UINT8))throw new Error("Only FLOAT32 and UINT8 arrays can be used in WebGL");const{buffer:t,bufferUsage:n,prevBuffer:a}=this.gl;if(t==null&&(this.gl.buffer=e.createBuffer()),this.writePos!==a)if(e.bindBuffer(e.ARRAY_BUFFER,this.gl.buffer),this.writePos!==ge){a===0&&e.bufferData(e.ARRAY_BUFFER,this.byteCapacity.valueOf(),e.STATIC_DRAW);const i=this.dataType.density.size(a).valueOf(),o=this.underlyingData.slice(this.gl.prevBuffer,this.writePos);e.bufferSubData(e.ARRAY_BUFFER,i,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=ge}as(e){return aa(e,this.dataType),this}get digest(){return{key:this.key,dataType:this.dataType.toString(),sampleOffset:this.sampleOffset,alignment:{lower:Wn(this.alignmentBounds.lower),upper:Wn(this.alignmentBounds.upper)},timeRange:this.timeRange.toString(),length:this.length,capacity:this.capacity}}get alignmentBounds(){return V(this.alignment,this.alignment+BigInt(this.length))}maybeGarbageCollectGLBuffer(e){this.gl.buffer!=null&&(e.deleteBuffer(this.gl.buffer),this.gl.buffer=null,this.gl.prevBuffer=0,this.gl.control=null)}get glBuffer(){if(this.gl.buffer==null)throw new Error("gl buffer not initialized");return this.gl.prevBuffer!==this.writePos&&console.warn("buffer not updated"),this.gl.buffer}[Symbol.iterator](){if(this.dataType.isVariable){const e=new du(this);return this.dataType.equals(I.JSON)?new tn(e):e}return this.dataType.equals(I.UUID)?new fu(this):new yu(this)}slice(e,t){return this.sliceSub(!1,e,t)}sub(e,t){return this.sliceSub(!0,e,t)}subIterator(e,t){return new Vn(this,e,t??this.length)}subAlignmentIterator(e,t){return new Vn(this,Number(e-this.alignment),Number(t-this.alignment))}subBytes(e,t){if(e>=0&&(t==null||t>=this.byteLength.valueOf()))return this;const n=this.data.subarray(e,t);return new Y({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 a;return e?a=this.data.subarray(t,n):a=this.data.slice(t,n),new Y({data:a,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(t)})}reAlign(e){return new Y({data:this.buffer,dataType:this.dataType,timeRange:z.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 hu=r=>r==null?!1:Array.isArray(r)||r instanceof ArrayBuffer||ArrayBuffer.isView(r)&&!(r instanceof DataView)||r instanceof Y?!0:na(r),oa=tu(ia,Y);let Vn=class{series;end;index;constructor(e,t,n){this.series=e;const a=V(0,e.length);this.end=Bn(a,n),this.index=Bn(a,t)}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}},du=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]!==Ur;)this.index++;const n=this.index;return e===n?{done:!0,value:void 0}:(this.index++,{done:!1,value:this.decoder.decode(this.series.buffer.slice(e,n))})}};class tn{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:lt.decodeString(e.value,tn.schema)}}}class fu{series;index;data;density;constructor(e){if(!e.dataType.equals(I.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=I.UUID.density.valueOf()}next(){if(this.index>=this.series.length)return{done:!0,value:void 0};const e=sa(this.data,this.index*this.density);return this.index++,{done:!1,value:e}}}class yu{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 ca{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 aa(e,this.dataType),this}get dataType(){return this.series.length===0?I.UNKNOWN:this.series[0].dataType}get timeRange(){return this.series.length===0?z.ZERO:new z(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(oa(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(xt(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 yr(this,e,t??this.length)}subAlignmentIterator(e,t){if(e>=this.alignmentBounds.upper||t<=this.alignmentBounds.lower)return jr;let n=0;for(let i=0;i<this.series.length;i++){const o=this.series[i];if(e<o.alignment)break;if(e>=o.alignmentBounds.upper)n+=o.length;else if(xt(o.alignmentBounds,e)){n+=Number(e-o.alignment);break}}let a=0;for(let i=0;i<this.series.length;i++){const o=this.series[i];if(t<o.alignment)break;if(t>=o.alignmentBounds.upper)a+=o.length;else if(xt(o.alignmentBounds,t)){a+=Number(t-o.alignment);break}}return new yr(this,n,a)}subAlignmentSpanIterator(e,t){if(e>=this.alignmentBounds.upper)return jr;t=Math.min(t,Number(this.distance(e,this.alignmentBounds.upper)));let n=0;for(let a=0;a<this.series.length;a++){const i=this.series[a];if(e<i.alignment)break;if(e>=i.alignmentBounds.upper)n+=i.length;else if(xt(i.alignmentBounds,e)){n+=Number(e-i.alignment);break}}return new yr(this,n,n+t)}updateGLBuffer(e){this.series.forEach(t=>t.updateGLBuffer(e))}get bounds(){return Ul(this.series.map(e=>e.bounds))}get byteLength(){return new S(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(a=>a.alignmentBounds);return Dl(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(a=>a.alignmentBounds);return Ml(n,e,t)}parseJSON(e){if(!this.dataType.equals(I.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 gu(this.series)}toStrings(){return this.series.flatMap(e=>e.toStrings())}}let gu=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}};class yr{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 Wn=r=>{const e=r>>32n,t=r&0xffffffffn;return{domain:e,sample:t}},pu=(r,e)=>{let t=null;return e===0?r:(...n)=>{t!==null&&(clearTimeout(t),t=null),t=setTimeout(()=>r(...n),e)}},mu=(r,e,t=".")=>{const n=r.split(t);return n.map((a,i)=>{const o=e(a,i,n);return o==null?null:typeof o=="string"?o:o.join(t)}).filter(a=>a!=null).join(t)},wu=(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(a=>a.key===e)},bu=(r,e,t={optional:!1,separator:"."})=>{t.separator??=".";const{optional:n,getter:a=wu}=t,i=e.split(t.separator);if(i.length===1&&i[0]==="")return r;let o=r;for(const c of i){const l=a(o,c);if(l==null){if(n)return null;throw new Error(`Path ${e} does not exist. ${c} is null`)}o=l}return o};s.z.object({key:s.z.string(),value:s.z.string()});class Tu{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,a]=this.transform(e);if(!a)return;t=n}this.handlers.forEach((n,a)=>a(t))}setCloser(e){this.closer=e}async close(){return await this.closer?.()}}let vu=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 Eu=Object.freeze(Object.defineProperty({__proto__:null,BaseObserver:vu,Observer:Tu},Symbol.toStringTag,{value:"Module"})),Ou=s.z.record(s.z.union([s.z.number(),s.z.string(),s.z.symbol()]),s.z.unknown()),rn=r=>Object.entries(r),Nu=(r,e)=>Object.fromEntries(rn(r).map(([t,n])=>[t,e(n,t)])),zu=r=>Object.fromEntries(rn(r).filter(([e,t])=>t!==void 0)),ue=Object.freeze(Object.defineProperty({__proto__:null,entries:rn,map:Nu,purgeUndefined:zu,unknownZ:Ou},Symbol.toStringTag,{value:"Module"})),Su=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser";Su();const Iu=["macOS","Windows","Linux"],Au=["macos","windows","linux"],$u={macos:"macOS",windows:"Windows",linux:"Linux"};s.z.enum(Iu).or(s.z.enum(Au).transform(r=>$u[r]));const ku=(...r)=>r.map(la).join(""),la=r=>(r.endsWith("/")||(r+="/"),r.startsWith("/")&&(r=r.slice(1)),r),Cu=r=>r.endsWith("/")?r.slice(0,-1):r;class ot{protocol;host;port;path;constructor({host:e,port:t,protocol:n="",pathPrefix:a=""}){this.protocol=n,this.host=e,this.port=t,this.path=la(a)}replace(e){return new ot({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new ot({...this,pathPrefix:ku(this.path,e)})}toString(){return Cu(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}static UNKNOWN=new ot({host:"unknown",port:0})}const xu=r=>r.nullable().transform(e=>e===null?void 0:e).optional(),Ru=r=>s.array(r).or(r.transform(e=>[e])),ua=r=>mu(r,(e,t,n)=>{const a=t===n.length-1,i=!isNaN(parseInt(e)),o=!isNaN(parseInt(n[t+1]));return i&&(e="element"),a||o?e:[e,"shape"]}),_n=(r,e)=>{if(r==null)return null;const t=r[e];return t==null&&typeof r=="object"&&"sourceType"in r?r.sourceType()[e]:t},ju=(r,e,t)=>bu(_n(r,"shape"),ua(e),{...t,getter:_n}),ct=Object.freeze(Object.defineProperty({__proto__:null,getFieldSchema:ju,getFieldSchemaPath:ua,nullToUndefined:xu,toArray:Ru},Symbol.toStringTag,{value:"Module"})),Uu=async r=>await new Promise(e=>setTimeout(e,v.fromMilliseconds(r).milliseconds));class Du{config;retries;interval;constructor(e){this.config={baseInterval:new v(e?.baseInterval??v.seconds(1)),maxRetries:e?.maxRetries??5,scale:e?.scale??1,sleepFn:e?.sleepFn??Uu},this.retries=0,this.interval=new v(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)}reset(){this.retries=0,this.interval=this.config.baseInterval}}const Mu=s.z.object({baseInterval:v.z.optional(),maxRetries:s.z.number().optional(),scale:s.z.number().optional()}),ha=Object.freeze(Object.defineProperty({__proto__:null,Breaker:Du,breakerConfigZ:Mu},Symbol.toStringTag,{value:"Module"})),Zu=/^#?([0-9a-f]{6}|[0-9a-f]{8})$/i,da=s.z.string().regex(Zu),Fe=s.z.number().min(0).max(255),fa=s.z.number().min(0).max(1),ya=s.z.tuple([Fe,Fe,Fe,fa]),Pu=s.z.tuple([Fe,Fe,Fe]),Lu=s.z.object({rgba255:ya}),Bu=s.z.number().min(0).max(360),qu=s.z.number().min(0).max(100),Fu=s.z.number().min(0).max(100),Yu=s.z.tuple([Bu,qu,Fu,fa]),nn=s.z.union([da,Pu,ya,Yu,Lu]),Vu=nn.transform(r=>sn(r)),sn=(r,e=1)=>{if(r=nn.parse(r),typeof r=="string")return Wu(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},Wu=(r,e=1)=>(r=da.parse(r),r=_u(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),_u=r=>r.startsWith("#")?r.slice(1):r;sn("#000000");sn("#ffffff");const Hu=s.z.object({key:s.z.string(),color:nn,position:s.z.number(),switched:s.z.boolean().optional()});s.z.array(Hu);const Gu=s.z.object({key:s.z.string(),name:s.z.string(),color:Vu});s.z.object({key:s.z.string(),name:s.z.string(),swatches:s.z.array(Gu)});const ga=s.z.int().min(0).max(255),pa=255,ma=0,Ju={lower:ma,upper:pa+1},wa=s.z.object({name:s.z.string(),key:s.z.string()}),ut=r=>s.z.object({subject:wa,resource:r,authority:ga}),Ku=(...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}),ba=r=>s.z.object({from:ut(r),to:s.z.null()}),Ta=r=>s.z.object({from:s.z.null(),to:ut(r)}),Xu=r=>s.z.union([ba(r),Ta(r),s.z.object({from:ut(r),to:ut(r)})]),G=Object.freeze(Object.defineProperty({__proto__:null,ABSOLUTE_AUTHORITY:pa,AUTHORITY_BOUNDS:Ju,ZERO_AUTHORITY:ma,acquireZ:Ta,authorityZ:ga,filterTransfersByChannelKey:Ku,releaseZ:ba,stateZ:ut,subjectZ:wa,transferZ:Xu},Symbol.toStringTag,{value:"Module"})),Qu=r=>Object.getOwnPropertySymbols(globalThis).includes(r),eh=(r,e)=>{const t=Symbol.for(r);if(!Qu(t)){const n=e();Object.defineProperty(globalThis,t,{value:n})}return()=>globalThis[t]},va="sy_x_error",th=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),vt=r=>class it extends Error{static discriminator=va;discriminator=it.discriminator;static TYPE=r;type=it.TYPE;static matches=th(r);matches=it.matches;constructor(t,n){super(t,n),this.name=it.TYPE}static sub(t){return vt(`${r}.${t}`)}},Ea=r=>{if(r==null||typeof r!="object")return!1;const e=r;if(e.discriminator!==va)return!1;if(!("type"in e))throw new Error(`X Error is missing its type property: ${JSON.stringify(e)}`);return!0},Pe="unknown",Dr="nil";class rh{providers=[];register(e){this.providers.push(e)}encode(e){if(e==null)return{type:Dr,data:""};if(Ea(e))for(const t of this.providers){const n=t.encode(e);if(n!=null)return n}if(e instanceof Error)return{type:Pe,data:e.message};if(typeof e=="string")return{type:Pe,data:e};try{return{type:Pe,data:JSON.stringify(e)}}catch{return{type:Pe,data:"unable to encode error information"}}}decode(e){if(e==null||e.type===Dr)return null;if(e.type===Pe)return new Mr(e.data);for(const t of this.providers){const n=t.decode(e);if(n!=null)return n}return new Mr(e.data)}}const an=eh("synnax-error-registry",()=>new rh),nh=({encode:r,decode:e})=>an().register({encode:r,decode:e}),sh=r=>an().encode(r),ah=r=>r==null?null:an().decode(r);class Mr extends vt("unknown"){}const ih=s.z.object({type:s.z.string(),data:s.z.string()});class oh extends vt("canceled"){}class ch extends vt("not_implemented"){}const le=Object.freeze(Object.defineProperty({__proto__:null,Canceled:oh,NONE:Dr,NotImplemented:ch,UNKNOWN:Pe,Unknown:Mr,createTyped:vt,decode:ah,encode:sh,isTyped:Ea,payloadZ:ih,register:nh},Symbol.toStringTag,{value:"Module"})),lh=s.object({jsonrpc:s.literal("2.0"),method:s.string(),params:s.any().optional(),id:s.union([s.string(),s.number(),s.null()]).optional()}),Oa=s.object({jsonrpc:s.literal("2.0"),id:s.union([s.string(),s.number(),s.null()])}),uh=Oa.extend({result:s.json()}),hh=Oa.extend({error:s.object({code:s.number().int(),message:s.string().optional(),data:s.json().optional()})}),dh=s.union([uh,hh]);s.union([lh,dh]);const Zr=s.z.string().regex(/^\d+\.\d+\.\d+$/),Et=(r,e,t={})=>{t.checkMajor??=!0,t.checkMinor??=!0,t.checkPatch??=!0;const n=Zr.parse(r),a=Zr.parse(e),[i,o,c]=n.split(".").map(Number),[l,h,d]=a.split(".").map(Number);if(t.checkMajor){if(i<l)return Mt;if(i>l)return Zt}if(t.checkMinor){if(o<h)return Mt;if(o>h)return Zt}if(t.checkPatch){if(c<d)return Mt;if(c>d)return Zt}return Ge},fh=(r,e,t={})=>_s(Et(r,e,t)),Na=(r,e,t={})=>Ws(Et(r,e,t)),yh=(r,e,t={})=>Vs(Et(r,e,t)),gh=({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}},ph=({name:r,migrations:e,targetSchema:t,defaultVersion:n,def:a})=>{const i=Object.keys(e).sort(Et).pop();if(i==null)return h=>{if(h.version??=n,h.version!==a.version)return console.log(`${r} version ${h.version} is newer than latest version of ${a.version}.
|
|
12
|
+
`).buffer):this.dataType.usesBigInt&&typeof N=="number"?this._data=new this.dataType.Array(u.map(v=>BigInt(Math.round(v)))).buffer:!this.dataType.usesBigInt&&typeof N=="bigint"?this._data=new this.dataType.Array(u.map(Number)).buffer:this._data=new this.dataType.Array(u).buffer}this.key=c,this.alignment=o,this.sampleOffset=a??0,this.timeRange=n??z.ZERO,this.gl={control:null,buffer:null,prevBuffer:0,bufferUsage:i}}static alloc({capacity:e,dataType:t,...n}){if(e===0)throw new Error("[Series] - cannot allocate an array of length 0");const a=new new I(t).Array(e),i=new F({data:a.buffer,dataType:t,...n});return i.writePos=0,i}get refCount(){return this._refCount}acquire(e){this._refCount++,e!=null&&this.updateGLBuffer(e)}release(){this._refCount--,this.refCount===0&&this.gl.control!=null?this.maybeGarbageCollectGLBuffer(this.gl.control):this.refCount<0&&console.warn("cannot release a series with a negative reference count")}write(e){if(!e.dataType.equals(this.dataType))throw 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===pe)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===pe)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===pe?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(I.JSON))throw new Error("cannot parse non-JSON series as JSON");return this.toStrings().map(t=>e.parse(lt.decodeString(t)))}get byteCapacity(){return new S(this.underlyingData.byteLength)}get capacity(){return this.dataType.isVariable?this.byteCapacity.valueOf():this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===pe?this.byteCapacity:this.dataType.isVariable?new S(this.writePos):this.dataType.density.size(this.writePos)}get length(){return this.cachedLength!=null?this.cachedLength:this.dataType.isVariable?this.calculateCachedLength():this.writePos===pe?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,a)=>{n===Mr&&(e++,t.push(a+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 a=0;a<this.length;a++)n[a]=iu(this.dataType,e,this.data[a],t);return new F({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(I.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(),Bt(this.cachedMax,this.sampleOffset))}calcRawMin(){if(this.length===0)return 1/0;if(this.dataType.equals(I.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(),Bt(this.cachedMin,this.sampleOffset))}get bounds(){return Y(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);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(I.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 Bt(n,this.sampleOffset)}atUUID(e,t){e<0&&(e=this.length+e);const n=sa(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,a=0;if(this._cachedIndexes!=null)n=this._cachedIndexes[e],a=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]===Mr){if(e===0){a=o;break}n=o+1,e--}if(a===0&&(a=this.data.length),n>=a||e>0){if(t)throw new Error(`[series] - no value at index ${e}`);return}}const i=this.data.slice(n,a);return this.dataType.equals(I.STRING)?new TextDecoder().decode(i):en(JSON.parse(new TextDecoder().decode(i)))}binarySearch(e){let t=0,n=this.length-1;const a=Gt(e);for(;t<=n;){const i=Math.floor((t+n)/2),o=a(this.at(i,!0),e);if(o===0)return i;o<0?t=i+1:n=i-1}return t}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals(I.FLOAT32)&&!this.dataType.equals(I.UINT8))throw new Error("Only FLOAT32 and UINT8 arrays can be used in WebGL");const{buffer:t,bufferUsage:n,prevBuffer:a}=this.gl;if(t==null&&(this.gl.buffer=e.createBuffer()),this.writePos!==a)if(e.bindBuffer(e.ARRAY_BUFFER,this.gl.buffer),this.writePos!==pe){a===0&&e.bufferData(e.ARRAY_BUFFER,this.byteCapacity.valueOf(),e.STATIC_DRAW);const i=this.dataType.density.size(a).valueOf(),o=this.underlyingData.slice(this.gl.prevBuffer,this.writePos);e.bufferSubData(e.ARRAY_BUFFER,i,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=pe}as(e){return aa(e,this.dataType),this}get digest(){return{key:this.key,dataType:this.dataType.toString(),sampleOffset:this.sampleOffset,alignment:{lower:Wn(this.alignmentBounds.lower),upper:Wn(this.alignmentBounds.upper)},timeRange:this.timeRange.toString(),length:this.length,capacity:this.capacity}}get alignmentBounds(){return Y(this.alignment,this.alignment+BigInt(this.length))}maybeGarbageCollectGLBuffer(e){this.gl.buffer!=null&&(e.deleteBuffer(this.gl.buffer),this.gl.buffer=null,this.gl.prevBuffer=0,this.gl.control=null)}get glBuffer(){if(this.gl.buffer==null)throw new Error("gl buffer not initialized");return this.gl.prevBuffer!==this.writePos&&console.warn("buffer not updated"),this.gl.buffer}[Symbol.iterator](){if(this.dataType.isVariable){const e=new yu(this);return this.dataType.equals(I.JSON)?new nn(e):e}return this.dataType.equals(I.UUID)?new gu(this):new pu(this)}slice(e,t){return this.sliceSub(!1,e,t)}sub(e,t){return this.sliceSub(!0,e,t)}subIterator(e,t){return new Vn(this,e,t??this.length)}subAlignmentIterator(e,t){return new Vn(this,Number(e-this.alignment),Number(t-this.alignment))}subBytes(e,t){if(e>=0&&(t==null||t>=this.byteLength.valueOf()))return this;const n=this.data.subarray(e,t);return new F({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 a;return e?a=this.data.subarray(t,n):a=this.data.slice(t,n),new F({data:a,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(t)})}reAlign(e){return new F({data:this.buffer,dataType:this.dataType,timeRange:z.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 fu=r=>r==null?!1:Array.isArray(r)||r instanceof ArrayBuffer||ArrayBuffer.isView(r)&&!(r instanceof DataView)||r instanceof F?!0:na(r),oa=nu(ia,F);let Vn=class{series;end;index;constructor(e,t,n){this.series=e;const a=Y(0,e.length);this.end=Bn(a,n),this.index=Bn(a,t)}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}},yu=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]!==Mr;)this.index++;const n=this.index;return e===n?{done:!0,value:void 0}:(this.index++,{done:!1,value:this.decoder.decode(this.series.buffer.slice(e,n))})}};class nn{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:lt.decodeString(e.value,nn.schema)}}}class gu{series;index;data;density;constructor(e){if(!e.dataType.equals(I.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=I.UUID.density.valueOf()}next(){if(this.index>=this.series.length)return{done:!0,value:void 0};const e=sa(this.data,this.index*this.density);return this.index++,{done:!1,value:e}}}class pu{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 ca{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 aa(e,this.dataType),this}get dataType(){return this.series.length===0?I.UNKNOWN:this.series[0].dataType}get timeRange(){return this.series.length===0?z.ZERO:new z(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?Y(0n,0n):Y(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(oa(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(jt(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 pr(this,e,t??this.length)}subAlignmentIterator(e,t){if(e>=this.alignmentBounds.upper||t<=this.alignmentBounds.lower)return Dr;let n=0;for(let i=0;i<this.series.length;i++){const o=this.series[i];if(e<o.alignment)break;if(e>=o.alignmentBounds.upper)n+=o.length;else if(jt(o.alignmentBounds,e)){n+=Number(e-o.alignment);break}}let a=0;for(let i=0;i<this.series.length;i++){const o=this.series[i];if(t<o.alignment)break;if(t>=o.alignmentBounds.upper)a+=o.length;else if(jt(o.alignmentBounds,t)){a+=Number(t-o.alignment);break}}return new pr(this,n,a)}subAlignmentSpanIterator(e,t){if(e>=this.alignmentBounds.upper)return Dr;t=Math.min(t,Number(this.distance(e,this.alignmentBounds.upper)));let n=0;for(let a=0;a<this.series.length;a++){const i=this.series[a];if(e<i.alignment)break;if(e>=i.alignmentBounds.upper)n+=i.length;else if(jt(i.alignmentBounds,e)){n+=Number(e-i.alignment);break}}return new pr(this,n,n+t)}updateGLBuffer(e){this.series.forEach(t=>t.updateGLBuffer(e))}get bounds(){return Ml(this.series.map(e=>e.bounds))}get byteLength(){return new S(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(a=>a.alignmentBounds);return Zl(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(a=>a.alignmentBounds);return Pl(n,e,t)}parseJSON(e){if(!this.dataType.equals(I.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 mu(this.series)}toStrings(){return this.series.flatMap(e=>e.toStrings())}}let mu=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}};class pr{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 Wn=r=>{const e=r>>32n,t=r&0xffffffffn;return{domain:e,sample:t}},wu=(r,e)=>{let t=null;return e===0?r:(...n)=>{t!==null&&(clearTimeout(t),t=null),t=setTimeout(()=>r(...n),e)}},bu=(r,e,t=".")=>{const n=r.split(t);return n.map((a,i)=>{const o=e(a,i,n);return o==null?null:typeof o=="string"?o:o.join(t)}).filter(a=>a!=null).join(t)},Tu=(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(a=>a.key===e)},vu=(r,e,t={optional:!1,separator:"."})=>{t.separator??=".";const{optional:n,getter:a=Tu}=t,i=e.split(t.separator);if(i.length===1&&i[0]==="")return r;let o=r;for(const c of i){const l=a(o,c);if(l==null){if(n)return null;throw new Error(`Path ${e} does not exist. ${c} is null`)}o=l}return o};s.z.object({key:s.z.string(),value:s.z.string()});class Eu{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,a]=this.transform(e);if(!a)return;t=n}this.handlers.forEach((n,a)=>a(t))}setCloser(e){this.closer=e}async close(){return await this.closer?.()}}let Ou=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 Nu=Object.freeze(Object.defineProperty({__proto__:null,BaseObserver:Ou,Observer:Eu},Symbol.toStringTag,{value:"Module"})),zu=s.z.record(s.z.union([s.z.number(),s.z.string(),s.z.symbol()]),s.z.unknown()),sn=r=>Object.entries(r),Su=(r,e)=>Object.fromEntries(sn(r).map(([t,n])=>[t,e(n,t)])),Iu=r=>Object.fromEntries(sn(r).filter(([e,t])=>t!==void 0)),he=Object.freeze(Object.defineProperty({__proto__:null,entries:sn,map:Su,purgeUndefined:Iu,unknownZ:zu},Symbol.toStringTag,{value:"Module"})),Au=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser";Au();const $u=["macOS","Windows","Linux"],ku=["macos","windows","linux"],Cu={macos:"macOS",windows:"Windows",linux:"Linux"};s.z.enum($u).or(s.z.enum(ku).transform(r=>Cu[r]));const xu=(...r)=>r.map(la).join(""),la=r=>(r.endsWith("/")||(r+="/"),r.startsWith("/")&&(r=r.slice(1)),r),Ru=r=>r.endsWith("/")?r.slice(0,-1):r;class ot{protocol;host;port;path;constructor({host:e,port:t,protocol:n="",pathPrefix:a=""}){this.protocol=n,this.host=e,this.port=t,this.path=la(a)}replace(e){return new ot({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new ot({...this,pathPrefix:xu(this.path,e)})}toString(){return Ru(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}static UNKNOWN=new ot({host:"unknown",port:0})}const ju=r=>r.nullable().transform(e=>e===null?void 0:e).optional(),Uu=r=>s.array(r).or(r.transform(e=>[e])),ua=r=>bu(r,(e,t,n)=>{const a=t===n.length-1,i=!isNaN(parseInt(e)),o=!isNaN(parseInt(n[t+1]));return i&&(e="element"),a||o?e:[e,"shape"]}),_n=(r,e)=>{if(r==null)return null;const t=r[e];return t==null&&typeof r=="object"&&"sourceType"in r?r.sourceType()[e]:t},Du=(r,e,t)=>vu(_n(r,"shape"),ua(e),{...t,getter:_n}),ct=Object.freeze(Object.defineProperty({__proto__:null,getFieldSchema:Du,getFieldSchemaPath:ua,nullToUndefined:ju,toArray:Uu},Symbol.toStringTag,{value:"Module"})),Mu=async r=>await new Promise(e=>setTimeout(e,E.fromMilliseconds(r).milliseconds));class Zu{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??Mu},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)}reset(){this.retries=0,this.interval=this.config.baseInterval}}const Pu=s.z.object({baseInterval:E.z.optional(),maxRetries:s.z.number().optional(),scale:s.z.number().optional()}),ha=Object.freeze(Object.defineProperty({__proto__:null,Breaker:Zu,breakerConfigZ:Pu},Symbol.toStringTag,{value:"Module"})),Lu=/^#?([0-9a-f]{6}|[0-9a-f]{8})$/i,da=s.z.string().regex(Lu),Fe=s.z.number().min(0).max(255),fa=s.z.number().min(0).max(1),ya=s.z.tuple([Fe,Fe,Fe,fa]),Bu=s.z.tuple([Fe,Fe,Fe]),qu=s.z.object({rgba255:ya}),Fu=s.z.number().min(0).max(360),Yu=s.z.number().min(0).max(100),Vu=s.z.number().min(0).max(100),Wu=s.z.tuple([Fu,Yu,Vu,fa]),an=s.z.union([da,Bu,ya,Wu,qu]),_u=an.transform(r=>on(r)),on=(r,e=1)=>{if(r=an.parse(r),typeof r=="string")return Hu(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},Hu=(r,e=1)=>(r=da.parse(r),r=Gu(r),[Dt(r,0),Dt(r,2),Dt(r,4),r.length===8?Dt(r,6)/255:e]),Dt=(r,e)=>parseInt(r.slice(e,e+2),16),Gu=r=>r.startsWith("#")?r.slice(1):r;on("#000000");on("#ffffff");const Ku=s.z.object({key:s.z.string(),color:an,position:s.z.number(),switched:s.z.boolean().optional()});s.z.array(Ku);const Ju=s.z.object({key:s.z.string(),name:s.z.string(),color:_u});s.z.object({key:s.z.string(),name:s.z.string(),swatches:s.z.array(Ju)});const ga=s.z.int().min(0).max(255),pa=255,ma=0,Xu={lower:ma,upper:pa+1},wa=s.z.object({name:s.z.string(),key:s.z.string()}),ut=r=>s.z.object({subject:wa,resource:r,authority:ga}),Qu=(...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}),ba=r=>s.z.object({from:ut(r),to:s.z.null()}),Ta=r=>s.z.object({from:s.z.null(),to:ut(r)}),eh=r=>s.z.union([ba(r),Ta(r),s.z.object({from:ut(r),to:ut(r)})]),K=Object.freeze(Object.defineProperty({__proto__:null,ABSOLUTE_AUTHORITY:pa,AUTHORITY_BOUNDS:Xu,ZERO_AUTHORITY:ma,acquireZ:Ta,authorityZ:ga,filterTransfersByChannelKey:Qu,releaseZ:ba,stateZ:ut,subjectZ:wa,transferZ:eh},Symbol.toStringTag,{value:"Module"})),th=r=>Object.getOwnPropertySymbols(globalThis).includes(r),rh=(r,e)=>{const t=Symbol.for(r);if(!th(t)){const n=e();Object.defineProperty(globalThis,t,{value:n})}return()=>globalThis[t]},va="sy_x_error",nh=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),Et=r=>class it extends Error{static discriminator=va;discriminator=it.discriminator;static TYPE=r;type=it.TYPE;static matches=nh(r);matches=it.matches;constructor(t,n){super(t,n),this.name=it.TYPE}static sub(t){return Et(`${r}.${t}`)}},Ea=r=>{if(r==null||typeof r!="object")return!1;const e=r;if(e.discriminator!==va)return!1;if(!("type"in e))throw new Error(`X Error is missing its type property: ${JSON.stringify(e)}`);return!0},Le="unknown",Zr="nil";class sh{providers=[];register(e){this.providers.push(e)}encode(e){if(e==null)return{type:Zr,data:""};if(Ea(e))for(const t of this.providers){const n=t.encode(e);if(n!=null)return n}if(e instanceof Error)return{type:Le,data:e.message};if(typeof e=="string")return{type:Le,data:e};try{return{type:Le,data:JSON.stringify(e)}}catch{return{type:Le,data:"unable to encode error information"}}}decode(e){if(e==null||e.type===Zr)return null;if(e.type===Le)return new Pr(e.data);for(const t of this.providers){const n=t.decode(e);if(n!=null)return n}return new Pr(e.data)}}const cn=rh("synnax-error-registry",()=>new sh),ah=({encode:r,decode:e})=>cn().register({encode:r,decode:e}),ih=r=>cn().encode(r),oh=r=>r==null?null:cn().decode(r);class Pr extends Et("unknown"){}const ch=s.z.object({type:s.z.string(),data:s.z.string()});class lh extends Et("canceled"){}class uh extends Et("not_implemented"){}const ue=Object.freeze(Object.defineProperty({__proto__:null,Canceled:lh,NONE:Zr,NotImplemented:uh,UNKNOWN:Le,Unknown:Pr,createTyped:Et,decode:oh,encode:ih,isTyped:Ea,payloadZ:ch,register:ah},Symbol.toStringTag,{value:"Module"})),hh=s.object({jsonrpc:s.literal("2.0"),method:s.string(),params:s.any().optional(),id:s.union([s.string(),s.number(),s.null()]).optional()}),Oa=s.object({jsonrpc:s.literal("2.0"),id:s.union([s.string(),s.number(),s.null()])}),dh=Oa.extend({result:s.json()}),fh=Oa.extend({error:s.object({code:s.number().int(),message:s.string().optional(),data:s.json().optional()})}),yh=s.union([dh,fh]);s.union([hh,yh]);const Lr=s.z.string().regex(/^\d+\.\d+\.\d+$/),Ot=(r,e,t={})=>{t.checkMajor??=!0,t.checkMinor??=!0,t.checkPatch??=!0;const n=Lr.parse(r),a=Lr.parse(e),[i,o,c]=n.split(".").map(Number),[l,h,d]=a.split(".").map(Number);if(t.checkMajor){if(i<l)return Pt;if(i>l)return Lt}if(t.checkMinor){if(o<h)return Pt;if(o>h)return Lt}if(t.checkPatch){if(c<d)return Pt;if(c>d)return Lt}return Ge},gh=(r,e,t={})=>_s(Ot(r,e,t)),Na=(r,e,t={})=>Ws(Ot(r,e,t)),ph=(r,e,t={})=>Vs(Ot(r,e,t)),mh=({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}},wh=({name:r,migrations:e,targetSchema:t,defaultVersion:n,def:a})=>{const i=Object.keys(e).sort(Ot).pop();if(i==null)return h=>{if(h.version??=n,h.version!==a.version)return console.log(`${r} version ${h.version} is newer than latest version of ${a.version}.
|
|
14
14
|
Returning default instead.
|
|
15
|
-
`),a;try{return t!=null?t.parse(h):h}catch(d){return console.log(`${r} failed to parse default. Exiting with default`),console.error(d),a}};const o=Object.keys(e).length;let c=!1;const l=h=>{try{if(o===0||Na(h.version,i))return console.log(c?`${r} ${h.version} now up to date`:`${r} version ${h.version} is up to date with target version ${a.version}`),h;const d=h.version,u=e[d],N=u(h);return c=!0,l(N)}catch(d){return console.log(`${r} failed to migrate from ${h.version} to ${i}`),console.error(d),a}};return h=>{try{if(h.version==null)if(n!=null)console.log(`${r} version is null. Setting version to default of ${n}`),h.version=n;else return console.log(`${r} version is null and no default version set. Exiting with default`),a;return l(h)}catch(d){return console.log(`${r} failed to parse final result. Exiting with default`),console.error(d),a}}},Hn=Object.freeze(Object.defineProperty({__proto__:null,compareSemVer:
|
|
15
|
+
`),a;try{return t!=null?t.parse(h):h}catch(d){return console.log(`${r} failed to parse default. Exiting with default`),console.error(d),a}};const o=Object.keys(e).length;let c=!1;const l=h=>{try{if(o===0||Na(h.version,i))return console.log(c?`${r} ${h.version} now up to date`:`${r} version ${h.version} is up to date with target version ${a.version}`),h;const d=h.version,u=e[d],N=u(h);return c=!0,l(N)}catch(d){return console.log(`${r} failed to migrate from ${h.version} to ${i}`),console.error(d),a}};return h=>{try{if(h.version==null)if(n!=null)console.log(`${r} version is null. Setting version to default of ${n}`),h.version=n;else return console.log(`${r} version is null and no default version set. Exiting with default`),a;return l(h)}catch(d){return console.log(`${r} failed to parse final result. Exiting with default`),console.error(d),a}}},Hn=Object.freeze(Object.defineProperty({__proto__:null,compareSemVer:Ot,createMigration:mh,migrator:wh,semVerNewer:Na,semVerOlder:ph,semVerZ:Lr,versionsEqual:gh},Symbol.toStringTag,{value:"Module"})),bh=["standard","scientific","engineering"];s.z.enum(bh);const za=s.z.enum(["success","info","warning","error","loading","disabled"]),Th=r=>s.z.object({key:s.z.string(),variant:za,message:s.z.string(),description:s.z.string().optional(),time:O.z,details:r??s.z.unknown().optional()}),vh=(r,e)=>{if(!(r instanceof Error))throw r;return Sa({variant:"error",message:e??r.message,description:e!=null?r.message:void 0,details:{stack:r.stack??""}})},Sa=r=>({key:rn(),time:O.now(),...r}),Nt=Object.freeze(Object.defineProperty({__proto__:null,create:Sa,fromException:vh,statusZ:Th,variantZ:za},Symbol.toStringTag,{value:"Module"})),Eh=(r,e="")=>{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]}`},Oh=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 a=/\d+/g;r.match(a)&&e.forEach((o,c)=>{if(a.test(o)){const l=e.map((h,d)=>d!==c?h.charAt(0).toLowerCase():h).join("");t.add(l.replace(/-/g,"_")),t.add(l.replace(/(.)(.)/g,"$1_$2").replace(/-/g,"_"))}});const i=e.map(o=>(o.length>3?o.substring(0,3):o).toLowerCase());return t.add(i.join("").replace(/-/g,"_")),t.add(i.join("_").replace(/-/g,"_")),Array.from(t).filter(o=>o.length>=2&&o.length<=12&&!/^\d/.test(o))},Nh=(r,e)=>r.startsWith(e)?r.slice(e.length):r,zh=Object.freeze(Object.defineProperty({__proto__:null,createShortIdentifiers:Oh,naturalLanguageJoin:Eh,trimPrefix:Nh},Symbol.toStringTag,{value:"Module"})),Ia="all",Aa="create",$a="delete",ka="retrieve",Ca="update",Vt=s.z.enum([Ia,Aa,$a,ka,Ca]);class ne extends ue.createTyped("sy"){}class M extends ne.sub("validation"){}class ht extends M.sub("path"){path;error;static encodedSchema=s.z.object({path:s.z.string().array(),error:ue.payloadZ});constructor(e,t){const n=T.toArray(e);super(`${n.join(".")}: ${t.message}`),this.path=n.flatMap(a=>a.split(".")),this.error=t}static decode(e){const t=ht.encodedSchema.parse(JSON.parse(e.data));return new ht(t.path,ue.decode(t.error))}}class dt extends ne.sub("auth"){}class Br extends dt.sub("invalid_token"){}class qr extends dt.sub("expired_token"){}class Ye extends ne.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 ve extends re.sub("query"){}class ft extends ve.sub("not_found"){}class yt extends ve.sub("multiple_results"){}class Br extends re.sub("route"){path;constructor(e,t){super(e),this.path=t}}class qr extends re.sub("control"){}class Gn extends qr.sub("unauthorized"){}class Nh extends re.sub("disconnected"){constructor(e="Operation failed because no cluster is connected."){super(e)}}class zh extends re.sub("contiguity"){}const Sh=r=>r.type.startsWith(re.TYPE)?r.type.startsWith(M.TYPE)?r.type===ht.TYPE?ht.decode(r):new M(r.data):r.type.startsWith(dt.TYPE)?r.type.startsWith(Pr.TYPE)?new Pr(r.data):r.type.startsWith(Lr.TYPE)?new Lr(r.data):new dt(r.data):r.type.startsWith(Ye.TYPE)?new Ye(r.data):r.type.startsWith(ve.TYPE)?r.type.startsWith(ft.TYPE)?new ft(r.data):r.type.startsWith(yt.TYPE)?new yt(r.data):new ve(r.data):r.type.startsWith(qr.TYPE)?r.type.startsWith(Gn.TYPE)?new Gn(r.data):new qr(r.data):r.type.startsWith(Br.TYPE)?new Br(r.data,r.data):new Ye(r.data):null,Ih=()=>{throw new le.NotImplemented};le.register({encode:Ih,decode:Sh});const Ah=async(r,e)=>{const[t,n]=await e(r);return n==null?[t,n]:n instanceof Te?[t,new Te({message:`Cannot reach cluster at ${n.url.host}:${n.url.port}`,url:n.url})]:[t,n]};class on{key;name;constructor(e,t){this.key=t,this.name=e}get ontologyID(){return xa(this.key)}}const xa=r=>({type:"group",key:r}),Ot=s.z.uuid(),Gt=s.z.string(),cn=s.z.object({key:Ot,name:Gt}),Ra="builtin",$h="cluster",kh="node",Jt=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"]),Ch=s.z.string().transform(r=>{const[e,t]=r.split(":");return{type:Jt.parse(e),key:t??""}}),R=s.z.object({type:Jt,key:s.z.string()}).or(Ch),xh={type:Ra,key:"root"},ln=r=>`${r.type}:${r.key}`,Rh=(r,e)=>r.type===e.type&&r.key===e.key,ja=r=>{const e=T.toArray(r);return e.length===0?[]:typeof e[0]=="object"&&"id"in e[0]?e.map(({id:t})=>t):e.map(t=>R.parse(t))},Ua=s.z.object({id:R,name:s.z.string(),data:ue.unknownZ.optional().nullable()}).transform(r=>({key:ln(r.id),...r})),jh=r=>r==="to"?"from":"to",Uh=s.z.object({from:R,type:s.z.string(),to:R}).or(s.z.string().transform(r=>{const[e,t,n]=r.split("->");return{from:R.parse(e),type:t,to:R.parse(n)}})),Dh="parent",Mh=(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),Zh=s.z.object({group:cn}),Ph=s.z.object({parent:R,key:Ot.optional(),name:Gt}),Lh=s.z.object({key:Ot,name:Gt}),Bh=s.z.object({keys:s.z.array(Ot)});let qh=class Lt{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 g(this.client,Lt.CREATE_ENDPOINT,{parent:e,name:t,key:n},Ph,Zh)).group}async rename(e,t){await g(this.client,Lt.RENAME_ENDPOINT,{key:e,name:t},Lh,s.z.object({}))}async delete(e){await g(this.client,Lt.DELETE_ENDPOINT,{keys:e},Bh,s.z.object({}))}},Da=class{creator;constructor(e){this.creator=new qh(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 on(e.name,e.key)}};const Fh=Object.freeze(Object.defineProperty({__proto__:null,Client:Da,Group:on,groupZ:cn,keyZ:Ot,nameZ:Gt,ontologyID:xa},Symbol.toStringTag,{value:"Module"})),Yh="/ontology/add-children",Vh="/ontology/remove-children",Wh="/ontology/move-children",Jn=s.z.object({id:R,children:R.array()}),_h=s.z.object({from:R,to:R,children:R.array()}),gr=s.z.object({});let Hh=class{client;constructor(e){this.client=e}async addChildren(e,...t){await g(this.client,Yh,{id:e,children:t},Jn,gr)}async removeChildren(e,...t){await g(this.client,Vh,{id:e,children:t},Jn,gr)}async moveChildren(e,t,...n){await g(this.client,Wh,{from:e,to:t,children:n},_h,gr)}};const Gh="/ontology/retrieve",Jh=s.z.object({ids:R.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:Jt.array().optional()}),Kh=s.z.object({resources:Ua.array()});let Ma=class{type="ontology";groups;client;writer;framer;constructor(e,t){this.client=e,this.writer=new Hh(e),this.groups=new Da(e),this.framer=t}async retrieve(e,t){if(!Array.isArray(e)&&typeof e=="object"&&!("key"in e))return this.execRetrieve(e);const n=ja(e),a=await this.execRetrieve({ids:n,...t});if(Array.isArray(e))return a;if(a.length===0)throw new ve(`No resource found with ID ${Oh.naturalLanguageJoin(n.map(i=>ln(i)))}`);return a[0]}async retrieveChildren(e,t){return await this.execRetrieve({ids:T.toArray(e),children:!0,...t})}async retrieveParents(e,t){return await this.execRetrieve({ids:T.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 g(this.client,Gh,e,Jh,Kh);return t}};const Xh="sy_ontology_resource_set",Qh="sy_ontology_resource_delete",ed="sy_ontology_relationship_set",td="sy_ontology_relationship_delete",rd=Object.freeze(Object.defineProperty({__proto__:null,BUILTIN_TYPE:Ra,CLUSTER_TYPE:$h,Client:Ma,NODE_TYPE:kh,PARENT_OF_RELATIONSHIP_TYPE:Dh,RELATIONSHIP_DELETE_CHANNEL_NAME:td,RELATIONSHIP_SET_CHANNEL_NAME:ed,RESOURCE_DELETE_CHANNEL_NAME:Qh,RESOURCE_SET_CHANNEL_NAME:Xh,ROOT_ID:xh,idToString:ln,idZ:R,idsEqual:Rh,matchRelationship:Mh,oppositeRelationshipDirection:jh,parseIDs:ja,relationshipZ:Uh,resourceTypeZ:Jt,resourceZ:Ua},Symbol.toStringTag,{value:"Module"})),L=r=>s.z.union([s.z.union([s.z.null(),s.z.undefined()]).transform(()=>[]),r.array()]),Je=s.z.uuid(),Kt=s.z.object({key:Je,subjects:L(R),objects:L(R),actions:L(Ft)}),Za=s.z.object({key:Je.optional(),subjects:R.array().or(R),objects:R.array().or(R),actions:Ft.array().or(Ft)}),nd=s.z.object({keys:Je.array().optional(),subjects:R.array().optional()}),sd=s.z.object({key:Je}).transform(({key:r})=>({keys:[r]})),ad=s.z.union([s.z.object({for:R}).transform(({for:r})=>({subjects:[r]})),s.z.object({for:R.array()}).transform(({for:r})=>({subjects:r})),nd]),id=s.z.union([sd,ad]),od=s.z.object({policies:L(Kt)}),cd=s.z.object({policies:Kt.partial({key:!0}).array()}),ld=s.z.object({policies:Kt.array()}),ud=s.z.object({keys:Je.array()}),hd=s.z.object({}),dd="/access/policy/retrieve",fd="/access/policy/create",yd="/access/policy/delete";let Pa=class{client;constructor(e){this.client=e}async create(e){const t=Array.isArray(e),a=Za.array().parse(T.toArray(e)).map(o=>({objects:T.toArray(o.objects),actions:T.toArray(o.actions),subjects:T.toArray(o.subjects)})),i=await g(this.client,fd,{policies:a},cd,ld);return t?i.policies:i.policies[0]}async retrieve(e){const t="key"in e,n=await g(this.client,dd,e,id,od);return t?n.policies[0]:n.policies}async delete(e){await g(this.client,yd,{keys:T.toArray(e)},ud,hd)}};const gd=r=>({type:"policy",key:r}),pd={type:"allow_all",key:""},md=Object.freeze(Object.defineProperty({__proto__:null,ALLOW_ALL_ONTOLOGY_ID:pd,Client:Pa,keyZ:Je,newZ:Za,ontologyID:gd,policyZ:Kt},Symbol.toStringTag,{value:"Module"}));let La=class{policy;constructor(e){this.policy=new Pa(e)}};const wd=Object.freeze(Object.defineProperty({__proto__:null,ALL_ACTION:Ia,CREATE_ACTION:Aa,Client:La,DELETE_ACTION:$a,RETRIEVE_ACTION:ka,UPDATE_ACTION:Ca,actionZ:Ft},Symbol.toStringTag,{value:"Module"})),U=s.z.number(),ce=s.z.string(),Ke=s.z.object({name:ce,key:U,dataType:I.z,leaseholder:s.z.number(),index:U,isIndex:s.z.boolean(),internal:s.z.boolean(),virtual:s.z.boolean(),alias:s.z.string().optional(),expression:s.z.string().default(""),requires:L(U)}),Ba=Ke.extend({key:U.optional(),leaseholder:s.z.number().optional(),index:U.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(U).optional().default([])}),bd=Ht.statusZ(),ke=s.z.union([ct.toArray(U),ct.toArray(ce),ct.toArray(Ke).transform(r=>r.map(e=>e.key))]),Td=new Error("request for lock canceled");var vd=function(r,e,t,n){function a(i){return i instanceof t?i:new t(function(o){o(i)})}return new(t||(t=Promise))(function(i,o){function c(d){try{h(n.next(d))}catch(u){o(u)}}function l(d){try{h(n.throw(d))}catch(u){o(u)}}function h(d){d.done?i(d.value):a(d.value).then(c,l)}h((n=n.apply(r,e||[])).next())})};class Ed{constructor(e,t=Td){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,a)=>{const i={resolve:n,reject:a,weight:e,priority:t},o=qa(this._queue,c=>t<=c.priority);o===-1&&e<=this._value?this._dispatchItem(i):this._queue.splice(o+1,0,i)})}runExclusive(e){return vd(this,arguments,void 0,function*(t,n=1,a=0){const[i,o]=yield this.acquire(n,a);try{return yield t(i)}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]=[]),Od(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 a=n.findIndex(i=>i.priority<=e);(a===-1?n:n.splice(0,a)).forEach(i=>i.resolve())}}}_couldLockImmediately(e,t){return(this._queue.length===0||this._queue[0].priority<t)&&e<=this._value}}function Od(r,e){const t=qa(r,n=>e.priority<=n.priority);r.splice(t+1,0,e)}function qa(r,e){for(let t=r.length-1;t>=0;t--)if(e(r[t]))return t;return-1}var Nd=function(r,e,t,n){function a(i){return i instanceof t?i:new t(function(o){o(i)})}return new(t||(t=Promise))(function(i,o){function c(d){try{h(n.next(d))}catch(u){o(u)}}function l(d){try{h(n.throw(d))}catch(u){o(u)}}function h(d){d.done?i(d.value):a(d.value).then(c,l)}h((n=n.apply(r,e||[])).next())})};class zd{constructor(e){this._semaphore=new Ed(1,e)}acquire(){return Nd(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 Sd=(r,e,{convertNumericStrings:t=!0}={})=>{const n=!Array.isArray(r);let a=T.toArray(r);const i=a[0],o=typeof i;let c;return o==="string"&&t&&!isNaN(parseInt(i))&&"number"in e?(c=e.number,a=a.map(l=>parseInt(l))):c=e[o],{single:n,variant:c,normalized:a,actual:r}},Xe=(r,e,t,n)=>{if(n){if(t.length===0)throw new ft(`${r} not found matching ${JSON.stringify(e)}`);if(t.length>1)throw new yt(`Expected one ${r} matching ${JSON.stringify(e)}, but found ${t.length}`)}},Id=s.z.object({leaseholder:s.z.number().optional(),keys:U.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:I.z.array().optional(),notDataTypes:I.z.array().optional(),virtual:s.z.boolean().optional(),isIndex:s.z.boolean().optional(),internal:s.z.boolean().optional(),calculated:s.z.boolean().optional()}),Ad=s.z.object({channels:L(Ke)}),J=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]),Sd(r,{number:"keys",string:"names"}));class Nt{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=J(e),{variant:a}=n;let{normalized:i}=n;return a==="keys"&&i.indexOf(0)!==-1&&(i=i.filter(o=>o!==0)),i.length===0?[]:await this.execute({[a]:i,...t})}async execute(e){const[t,n]=await this.client.send(Nt.ENDPOINT,e,Id,Ad);if(n!=null)throw n;return t.channels}}class un{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}=J(e),a=[],i=[];if(n.forEach(c=>{const l=this.get(c);l!=null?a.push(...l):i.push(c)}),i.length===0)return a;const o=await this.wrapped.retrieve(i,t);return this.set(o),a.concat(o)}delete(e){const{variant:t,normalized:n}=J(e);t==="names"?n.forEach(a=>{const i=this.namesToKeys.get(a);i!=null&&(i.forEach(o=>this.cache.delete(o)),this.namesToKeys.delete(a))}):n.forEach(a=>{const i=this.cache.get(a);i!=null&&(this.cache.delete(a),this.namesToKeys.delete(i.name))})}rename(e,t){e.forEach((n,a)=>{const i=t[a],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=i,this.cache.set(n,o);const l=this.namesToKeys.get(i);l==null?this.namesToKeys.set(i,new Set([n])):l.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 a=this.cache.get(e);return a==null?void 0:[a]}const t=this.namesToKeys.get(e);if(t==null)return;const n=[];if(t.forEach(a=>{const i=this.cache.get(a);i!=null&&n.push(i)}),n.length!==0)return n}}class Fa{mu=new zd;requests=new Map;wrapped;debouncedRun;constructor(e,t){this.wrapped=e,this.debouncedRun=pu(()=>{this.run()},t)}async retrieve(e){if(!Array.isArray(e)&&typeof e=="object")return await this.wrapped.retrieve(e);const{normalized:t,variant:n}=J(e);return n==="names"?await this.wrapped.retrieve(t):await new Promise((i,o)=>{this.mu.runExclusive(()=>{this.requests.set(t,{resolve:i,reject:o}),this.debouncedRun()})})}async run(){await this.mu.runExclusive(async()=>{const e=new Set;this.requests.forEach((t,n)=>n.forEach(a=>e.add(a)));try{const t=await this.wrapped.retrieve(Array.from(e));this.requests.forEach((n,a)=>n.resolve(t.filter(i=>a.includes(i.key))))}catch(t){this.requests.forEach(n=>n.reject(t))}finally{this.requests.clear()}})}}const Ya=async(r,e)=>{const{normalized:t}=J(e),n=await r.retrieve(t),a=[];if(t.forEach(i=>{n.find(o=>o.name===i||o.key===i)==null&&a.push(i)}),a.length>0)throw new ve(`Could not find channels: ${JSON.stringify(a)}`);return n},$d="sy_channel_set",kd="sy_channel_delete";class hn{_frameClient;key;name;dataType;leaseholder;index;isIndex;internal;alias;virtual;expression;requires;constructor({dataType:e,name:t,leaseholder:n=0,key:a=0,isIndex:i=!1,index:o=0,internal:c=!1,virtual:l=!1,frameClient:h,alias:d,expression:u="",requires:N=[]}){this.key=a,this.name=t,this.dataType=new I(e),this.leaseholder=n,this.index=o,this.isIndex=i,this.internal=c,this.alias=d,this.virtual=l,this.expression=u,this.requires=N??[],this._frameClient=h??null}get framer(){if(this._frameClient==null)throw new M("cannot read from a channel that has not been created");return this._frameClient}get payload(){return Ke.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})}get isCalculated(){return gt(this.payload)}get ontologyID(){return _a(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 Cd="sy_calculation_status",xd="/channel/retrieve-group",Rd=s.z.object({}),jd=s.z.object({group:cn});let Va=class{type="channel";frameClient;client;retriever;writer;constructor(e,t,n,a){this.frameClient=e,this.retriever=t,this.client=n,this.writer=a}async create(e,t={}){const{retrieveIfNameExists:n=!1}=t,a=!Array.isArray(e);let i=T.toArray(e),o=[];if(n){const c=await this.retriever.retrieve(i.map(h=>h.name)),l=new Set(c.map(h=>h.name));i=i.filter(h=>!l.has(h.name)),o=this.sugar(c)}return o=o.concat(this.sugar(await this.writer.create(i))),a?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),a=this.sugar(await this.retriever.retrieve(e,t));return Xe("channel",e,a,n),n?a[0]:a}async delete(e){const{normalized:t,variant:n}=J(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(T.toArray(e),T.toArray(t))}createDebouncedBatchRetriever(e=10){return new un(new Fa(new Nt(this.client),e))}sugar(e){const{frameClient:t}=this;return e.map(n=>new hn({...n,frameClient:t}))}async retrieveGroup(){const e=await g(this.client,xd,{},Rd,jd);return new on(e.group.name,e.group.key)}};const gt=({virtual:r,expression:e})=>r&&e!=="",Wa=async(r,e)=>{if(!gt(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(gt(n)){const a=await Wa(r,n);if(a!=null)return a}}return null},_a=r=>({type:"channel",key:r.toString()}),Ud=s.z.object({channels:Ba.array()}),Dd=s.z.object({channels:Ke.array()}),Md=s.z.object({keys:U.array().optional(),names:ce.array().optional()}),Zd=s.z.object({}),Pd=s.z.object({keys:U.array(),names:ce.array()}),Ld=s.z.object({}),Bd="/channel/create",qd="/channel/delete",Fd="/channel/rename";let Ha=class{client;cache;constructor(e,t){this.client=e,this.cache=t}async create(e){const{channels:t}=await g(this.client,Bd,{channels:e.map(n=>({...n,dataType:n.dataType}))},Ud,Dd);return this.cache.set(t),t}async delete(e){await g(this.client,qd,e,Md,Zd),e.keys!=null&&this.cache.delete(e.keys),e.names!=null&&this.cache.delete(e.names)}async rename(e,t){await g(this.client,Fd,{keys:e,names:t},Pd,Ld),this.cache.rename(e,t)}};const Yd=Object.freeze(Object.defineProperty({__proto__:null,CALCULATION_STATUS_CHANNEL_NAME:Cd,CacheRetriever:un,Channel:hn,Client:Va,ClusterRetriever:Nt,DELETE_CHANNEL_NAME:kd,DebouncedBatchRetriever:Fa,SET_CHANNEL_NAME:$d,Writer:Ha,analyzeParams:J,calculationStatusZ:bd,isCalculated:gt,keyZ:U,nameZ:ce,newZ:Ba,ontologyID:_a,paramsZ:ke,payloadZ:Ke,resolveCalculatedIndex:Wa,retrieveRequired:Ya},Symbol.toStringTag,{value:"Module"})),Ee=s.z.uuid(),zt=s.z.object({key:Ee,username:s.z.string().min(1),firstName:s.z.string().default(""),lastName:s.z.string().default(""),rootUser:s.z.boolean().default(!0)}),Ga=zt.partial({key:!0,firstName:!0,lastName:!0}).omit({rootUser:!0}).extend({password:s.z.string().min(1)}),Vd=s.z.object({keys:Ee.array().optional(),usernames:s.z.string().array().optional()}),Wd=s.z.object({key:Ee}).transform(({key:r})=>({keys:[r]})),_d=s.z.object({username:s.z.string()}).transform(({username:r})=>({usernames:[r]})),Hd=s.z.object({usernames:s.z.string().array()}).transform(({usernames:r})=>({usernames:r})),Gd=s.z.union([Wd,_d,Hd,Vd]),Jd=s.z.object({users:L(zt)}),Kd=s.z.object({users:Ga.array()}),Xd=s.z.object({users:zt.array()}),Qd=s.z.object({key:Ee,username:s.z.string().min(1)}),ef=s.z.object({}),tf=s.z.object({key:Ee,firstName:s.z.string().optional(),lastName:s.z.string().optional()}),rf=s.z.object({}),nf=s.z.object({keys:Ee.array()}),sf=s.z.object({}),af="/user/retrieve",of="/user/create",cf="/user/change-username",lf="/user/rename",uf="/user/delete";let Ja=class{client;constructor(e){this.client=e}async create(e){const t=Array.isArray(e),n=await g(this.client,of,{users:T.toArray(e)},Kd,Xd);return t?n.users:n.users[0]}async changeUsername(e,t){await g(this.client,cf,{key:e,username:t},Qd,ef)}async retrieve(e){const t="key"in e||"username"in e,n=await g(this.client,af,e,Gd,Jd);if(!t)return n.users;if(n.users.length===0){const a="key"in e?`key ${e.key}`:`username ${e.username}`;throw new ft(`No user with ${a} found`)}if(n.users.length>1){const a="key"in e?`key ${e.key}`:`username ${e.username}`;throw new yt(`Multiple users found with ${a}`)}return n.users[0]}async rename(e,t,n){await g(this.client,lf,{key:e,firstName:t,lastName:n},tf,rf)}async delete(e){await g(this.client,uf,{keys:T.toArray(e)},nf,sf)}};const hf=r=>({type:"user",key:r}),df=Object.freeze(Object.defineProperty({__proto__:null,Client:Ja,keyZ:Ee,newZ:Ga,ontologyID:hf,userZ:zt},Symbol.toStringTag,{value:"Module"})),ff=s.z.object({username:s.z.string(),password:s.z.string()}),yf=s.z.object({token:s.z.string(),user:zt}),Kn="/auth/login",gf=3,pf="/auth/change-password",mf=s.z.object({username:s.z.string(),password:s.z.string(),newPassword:s.z.string().min(1)}),wf=s.z.object({}),bf=[Pr,Lr];let Tf=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 g(this.client,pf,{username:this.credentials.username,password:this.credentials.password,newPassword:e},mf,wf),this.credentials.password=e}middleware(){const e=async(t,n)=>{if(!this.authenticated&&!t.target.endsWith(Kn)){this.authenticating??=new Promise((c,l)=>{this.client.send(Kn,this.credentials,ff,yf).then(([h,d])=>{if(d!=null)return c(d);this.token=h?.token,this.user=h?.user,this.authenticated=!0,c(null)}).catch(l)});const o=await this.authenticating;if(o!=null)return[t,o]}t.params.Authorization=`Bearer ${this.token}`;const[a,i]=await n(t);return bf.some(o=>o.matches(i))&&this.retryCount<gf?(this.authenticated=!1,this.authenticating=void 0,this.retryCount+=1,e(t,n)):(this.retryCount=0,[a,i])};return e}};const Ka=s.z.enum(["disconnected","connecting","connected","failed"]),Xa=s.z.object({status:Ka,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()}),vf=s.z.object({clusterKey:s.z.string(),nodeVersion:s.z.string().optional()}),Xn={clusterKey:"",status:"disconnected",error:void 0,message:"Disconnected",clientServerCompatible:!1,clientVersion:"0.44.1"},Qn=(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 Ee extends ne.sub("query"){}class ft extends Ee.sub("not_found"){}class yt extends Ee.sub("multiple_results"){}class Fr extends ne.sub("route"){path;constructor(e,t){super(e),this.path=t}}class Yr extends ne.sub("control"){}class Gn extends Yr.sub("unauthorized"){}class Sh extends ne.sub("disconnected"){constructor(e="Operation failed because no cluster is connected."){super(e)}}class Ih extends ne.sub("contiguity"){}const Ah=r=>r.type.startsWith(ne.TYPE)?r.type.startsWith(M.TYPE)?r.type===ht.TYPE?ht.decode(r):new M(r.data):r.type.startsWith(dt.TYPE)?r.type.startsWith(Br.TYPE)?new Br(r.data):r.type.startsWith(qr.TYPE)?new qr(r.data):new dt(r.data):r.type.startsWith(Ye.TYPE)?new Ye(r.data):r.type.startsWith(Ee.TYPE)?r.type.startsWith(ft.TYPE)?new ft(r.data):r.type.startsWith(yt.TYPE)?new yt(r.data):new Ee(r.data):r.type.startsWith(Yr.TYPE)?r.type.startsWith(Gn.TYPE)?new Gn(r.data):new Yr(r.data):r.type.startsWith(Fr.TYPE)?new Fr(r.data,r.data):new Ye(r.data):null,$h=()=>{throw new ue.NotImplemented};ue.register({encode:$h,decode:Ah});const kh=async(r,e)=>{const[t,n]=await e(r);return n==null?[t,n]:n instanceof ve?[t,new ve({message:`Cannot reach cluster at ${n.url.host}:${n.url.port}`,url:n.url})]:[t,n]};class ln{key;name;constructor(e,t){this.key=t,this.name=e}get ontologyID(){return xa(this.key)}}const xa=r=>({type:"group",key:r}),zt=s.z.uuid(),Jt=s.z.string(),un=s.z.object({key:zt,name:Jt}),Ra="builtin",Ch="cluster",xh="node",Xt=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"]),Rh=s.z.string().transform(r=>{const[e,t]=r.split(":");return{type:Xt.parse(e),key:t??""}}),R=s.z.object({type:Xt,key:s.z.string()}).or(Rh),jh={type:Ra,key:"root"},gt=r=>`${r.type}:${r.key}`,Uh=(r,e)=>r.type===e.type&&r.key===e.key,ja=r=>{const e=T.toArray(r);return e.length===0?[]:typeof e[0]=="object"&&"id"in e[0]?e.map(({id:t})=>t):e.map(t=>R.parse(t))},Ua=s.z.object({id:R,name:s.z.string(),data:he.unknownZ.optional().nullable()}).transform(r=>({key:gt(r.id),...r})),Dh=r=>r==="to"?"from":"to",Mh=s.z.object({from:R,type:s.z.string(),to:R}).or(s.z.string().transform(r=>{const[e,t,n]=r.split("->");return{from:R.parse(e),type:t,to:R.parse(n)}})),Zh=r=>`${gt(r.from)}->${r.type}->${gt(r.to)}`,Ph="parent",Lh=(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),Bh=s.z.object({group:un}),qh=s.z.object({parent:R,key:zt.optional(),name:Jt}),Fh=s.z.object({key:zt,name:Jt}),Yh=s.z.object({keys:s.z.array(zt)});let Vh=class qt{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 g(this.client,qt.CREATE_ENDPOINT,{parent:e,name:t,key:n},qh,Bh)).group}async rename(e,t){await g(this.client,qt.RENAME_ENDPOINT,{key:e,name:t},Fh,s.z.object({}))}async delete(e){await g(this.client,qt.DELETE_ENDPOINT,{keys:e},Yh,s.z.object({}))}},Da=class{creator;constructor(e){this.creator=new Vh(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 ln(e.name,e.key)}};const Wh=Object.freeze(Object.defineProperty({__proto__:null,Client:Da,Group:ln,groupZ:un,keyZ:zt,nameZ:Jt,ontologyID:xa},Symbol.toStringTag,{value:"Module"})),_h="/ontology/add-children",Hh="/ontology/remove-children",Gh="/ontology/move-children",Kn=s.z.object({id:R,children:R.array()}),Kh=s.z.object({from:R,to:R,children:R.array()}),mr=s.z.object({});let Jh=class{client;constructor(e){this.client=e}async addChildren(e,...t){await g(this.client,_h,{id:e,children:t},Kn,mr)}async removeChildren(e,...t){await g(this.client,Hh,{id:e,children:t},Kn,mr)}async moveChildren(e,t,...n){await g(this.client,Gh,{from:e,to:t,children:n},Kh,mr)}};const Xh="/ontology/retrieve",Qh=s.z.object({ids:R.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:Xt.array().optional()}),ed=s.z.object({resources:Ua.array()});let Ma=class{type="ontology";groups;client;writer;framer;constructor(e,t){this.client=e,this.writer=new Jh(e),this.groups=new Da(e),this.framer=t}async retrieve(e,t){if(!Array.isArray(e)&&typeof e=="object"&&!("key"in e))return this.execRetrieve(e);const n=ja(e),a=await this.execRetrieve({ids:n,...t});if(Array.isArray(e))return a;if(a.length===0)throw new Ee(`No resource found with ID ${zh.naturalLanguageJoin(n.map(i=>gt(i)))}`);return a[0]}async retrieveChildren(e,t){return await this.execRetrieve({ids:T.toArray(e),children:!0,...t})}async retrieveParents(e,t){return await this.execRetrieve({ids:T.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 g(this.client,Xh,e,Qh,ed);return t}};const td="sy_ontology_resource_set",rd="sy_ontology_resource_delete",nd="sy_ontology_relationship_set",sd="sy_ontology_relationship_delete",ad=Object.freeze(Object.defineProperty({__proto__:null,BUILTIN_TYPE:Ra,CLUSTER_TYPE:Ch,Client:Ma,NODE_TYPE:xh,PARENT_OF_RELATIONSHIP_TYPE:Ph,RELATIONSHIP_DELETE_CHANNEL_NAME:sd,RELATIONSHIP_SET_CHANNEL_NAME:nd,RESOURCE_DELETE_CHANNEL_NAME:rd,RESOURCE_SET_CHANNEL_NAME:td,ROOT_ID:jh,idToString:gt,idZ:R,idsEqual:Uh,matchRelationship:Lh,oppositeRelationshipDirection:Dh,parseIDs:ja,relationshipToString:Zh,relationshipZ:Mh,resourceTypeZ:Xt,resourceZ:Ua},Symbol.toStringTag,{value:"Module"})),V=r=>s.z.union([s.z.union([s.z.null(),s.z.undefined()]).transform(()=>[]),r.array()]),Ke=s.z.uuid(),Qt=s.z.object({key:Ke,subjects:V(R),objects:V(R),actions:V(Vt)}),Za=s.z.object({key:Ke.optional(),subjects:R.array().or(R),objects:R.array().or(R),actions:Vt.array().or(Vt)}),id=s.z.object({keys:Ke.array().optional(),subjects:R.array().optional()}),od=s.z.object({key:Ke}).transform(({key:r})=>({keys:[r]})),cd=s.z.union([s.z.object({for:R}).transform(({for:r})=>({subjects:[r]})),s.z.object({for:R.array()}).transform(({for:r})=>({subjects:r})),id]),ld=s.z.union([od,cd]),ud=s.z.object({policies:V(Qt)}),hd=s.z.object({policies:Qt.partial({key:!0}).array()}),dd=s.z.object({policies:Qt.array()}),fd=s.z.object({keys:Ke.array()}),yd=s.z.object({}),gd="/access/policy/retrieve",pd="/access/policy/create",md="/access/policy/delete";let Pa=class{client;constructor(e){this.client=e}async create(e){const t=Array.isArray(e),a=Za.array().parse(T.toArray(e)).map(o=>({objects:T.toArray(o.objects),actions:T.toArray(o.actions),subjects:T.toArray(o.subjects)})),i=await g(this.client,pd,{policies:a},hd,dd);return t?i.policies:i.policies[0]}async retrieve(e){const t="key"in e,n=await g(this.client,gd,e,ld,ud);return t?n.policies[0]:n.policies}async delete(e){await g(this.client,md,{keys:T.toArray(e)},fd,yd)}};const wd=r=>({type:"policy",key:r}),bd={type:"allow_all",key:""},Td=Object.freeze(Object.defineProperty({__proto__:null,ALLOW_ALL_ONTOLOGY_ID:bd,Client:Pa,keyZ:Ke,newZ:Za,ontologyID:wd,policyZ:Qt},Symbol.toStringTag,{value:"Module"}));let La=class{policy;constructor(e){this.policy=new Pa(e)}};const vd=Object.freeze(Object.defineProperty({__proto__:null,ALL_ACTION:Ia,CREATE_ACTION:Aa,Client:La,DELETE_ACTION:$a,RETRIEVE_ACTION:ka,UPDATE_ACTION:Ca,actionZ:Vt},Symbol.toStringTag,{value:"Module"})),U=s.z.number(),le=s.z.string(),Ba=Nt.statusZ(),Je=s.z.object({name:le,key:U,dataType:I.z,leaseholder:s.z.number(),index:U,isIndex:s.z.boolean(),internal:s.z.boolean(),virtual:s.z.boolean(),alias:s.z.string().optional(),expression:s.z.string().default(""),requires:V(U),status:Ba.optional()}),qa=Je.extend({key:U.optional(),leaseholder:s.z.number().optional(),index:U.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:V(U).optional().default([])}),Ce=s.z.union([ct.toArray(U),ct.toArray(le),ct.toArray(Je).transform(r=>r.map(e=>e.key))]),Ed=new Error("request for lock canceled");var Od=function(r,e,t,n){function a(i){return i instanceof t?i:new t(function(o){o(i)})}return new(t||(t=Promise))(function(i,o){function c(d){try{h(n.next(d))}catch(u){o(u)}}function l(d){try{h(n.throw(d))}catch(u){o(u)}}function h(d){d.done?i(d.value):a(d.value).then(c,l)}h((n=n.apply(r,e||[])).next())})};class Nd{constructor(e,t=Ed){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,a)=>{const i={resolve:n,reject:a,weight:e,priority:t},o=Fa(this._queue,c=>t<=c.priority);o===-1&&e<=this._value?this._dispatchItem(i):this._queue.splice(o+1,0,i)})}runExclusive(e){return Od(this,arguments,void 0,function*(t,n=1,a=0){const[i,o]=yield this.acquire(n,a);try{return yield t(i)}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]=[]),zd(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 a=n.findIndex(i=>i.priority<=e);(a===-1?n:n.splice(0,a)).forEach(i=>i.resolve())}}}_couldLockImmediately(e,t){return(this._queue.length===0||this._queue[0].priority<t)&&e<=this._value}}function zd(r,e){const t=Fa(r,n=>e.priority<=n.priority);r.splice(t+1,0,e)}function Fa(r,e){for(let t=r.length-1;t>=0;t--)if(e(r[t]))return t;return-1}var Sd=function(r,e,t,n){function a(i){return i instanceof t?i:new t(function(o){o(i)})}return new(t||(t=Promise))(function(i,o){function c(d){try{h(n.next(d))}catch(u){o(u)}}function l(d){try{h(n.throw(d))}catch(u){o(u)}}function h(d){d.done?i(d.value):a(d.value).then(c,l)}h((n=n.apply(r,e||[])).next())})};class Id{constructor(e){this._semaphore=new Nd(1,e)}acquire(){return Sd(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 Ad=(r,e,{convertNumericStrings:t=!0}={})=>{const n=!Array.isArray(r);let a=T.toArray(r);const i=a[0],o=typeof i;let c;return o==="string"&&t&&!isNaN(parseInt(i))&&"number"in e?(c=e.number,a=a.map(l=>parseInt(l))):c=e[o],{single:n,variant:c,normalized:a,actual:r}},Xe=(r,e,t,n)=>{if(n){if(t.length===0)throw new ft(`${r} not found matching ${JSON.stringify(e)}`);if(t.length>1)throw new yt(`Expected one ${r} matching ${JSON.stringify(e)}, but found ${t.length}`)}},$d=s.z.object({leaseholder:s.z.number().optional(),keys:U.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:I.z.array().optional(),notDataTypes:I.z.array().optional(),virtual:s.z.boolean().optional(),isIndex:s.z.boolean().optional(),internal:s.z.boolean().optional(),calculated:s.z.boolean().optional()}),kd=s.z.object({channels:V(Je)}),J=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]),Ad(r,{number:"keys",string:"names"}));class St{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=J(e),{variant:a}=n;let{normalized:i}=n;return a==="keys"&&i.indexOf(0)!==-1&&(i=i.filter(o=>o!==0)),i.length===0?[]:await this.execute({[a]:i,...t})}async execute(e){const[t,n]=await this.client.send(St.ENDPOINT,e,$d,kd);if(n!=null)throw n;return t.channels}}class hn{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}=J(e),a=[],i=[];if(n.forEach(c=>{const l=this.get(c);l!=null?a.push(...l):i.push(c)}),i.length===0)return a;const o=await this.wrapped.retrieve(i,t);return this.set(o),a.concat(o)}delete(e){const{variant:t,normalized:n}=J(e);t==="names"?n.forEach(a=>{const i=this.namesToKeys.get(a);i!=null&&(i.forEach(o=>this.cache.delete(o)),this.namesToKeys.delete(a))}):n.forEach(a=>{const i=this.cache.get(a);i!=null&&(this.cache.delete(a),this.namesToKeys.delete(i.name))})}rename(e,t){e.forEach((n,a)=>{const i=t[a],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=i,this.cache.set(n,o);const l=this.namesToKeys.get(i);l==null?this.namesToKeys.set(i,new Set([n])):l.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 a=this.cache.get(e);return a==null?void 0:[a]}const t=this.namesToKeys.get(e);if(t==null)return;const n=[];if(t.forEach(a=>{const i=this.cache.get(a);i!=null&&n.push(i)}),n.length!==0)return n}}class Ya{mu=new Id;requests=new Map;wrapped;debouncedRun;constructor(e,t){this.wrapped=e,this.debouncedRun=wu(()=>{this.run()},t)}async retrieve(e){if(!Array.isArray(e)&&typeof e=="object")return await this.wrapped.retrieve(e);const{normalized:t,variant:n}=J(e);return n==="names"?await this.wrapped.retrieve(t):await new Promise((i,o)=>{this.mu.runExclusive(()=>{this.requests.set(t,{resolve:i,reject:o}),this.debouncedRun()})})}async run(){await this.mu.runExclusive(async()=>{const e=new Set;this.requests.forEach((t,n)=>n.forEach(a=>e.add(a)));try{const t=await this.wrapped.retrieve(Array.from(e));this.requests.forEach((n,a)=>n.resolve(t.filter(i=>a.includes(i.key))))}catch(t){this.requests.forEach(n=>n.reject(t))}finally{this.requests.clear()}})}}const Va=async(r,e)=>{const{normalized:t}=J(e),n=await r.retrieve(t),a=[];if(t.forEach(i=>{n.find(o=>o.name===i||o.key===i)==null&&a.push(i)}),a.length>0)throw new Ee(`Could not find channels: ${JSON.stringify(a)}`);return n},Cd="sy_channel_set",xd="sy_channel_delete";class Wt{_frameClient;key;name;dataType;leaseholder;index;isIndex;internal;alias;virtual;expression;requires;status;constructor({dataType:e,name:t,leaseholder:n=0,key:a=0,isIndex:i=!1,index:o=0,internal:c=!1,virtual:l=!1,frameClient:h,alias:d,status:u,expression:N="",requires:v=[]}){this.key=a,this.name=t,this.dataType=new I(e),this.leaseholder=n,this.index=o,this.isIndex=i,this.internal=c,this.alias=d,this.virtual=l,this.expression=N,this.requires=v??[],u!=null&&(this.status=Nt.create(u)),this._frameClient=h??null}get framer(){if(this._frameClient==null)throw new M("cannot read from a channel that has not been created");return this._frameClient}get payload(){return Je.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 pt(this.payload)}get ontologyID(){return Ha(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 Rd="sy_calculation_status",jd="/channel/retrieve-group",Ud=s.z.object({}),Dd=s.z.object({group:un});let Wa=class{type="channel";frameClient;client;retriever;writer;constructor(e,t,n,a){this.frameClient=e,this.retriever=t,this.client=n,this.writer=a}async create(e,t={}){const{retrieveIfNameExists:n=!1}=t,a=!Array.isArray(e);let i=T.toArray(e),o=[];if(n){const c=await this.retriever.retrieve(i.map(h=>h.name)),l=new Set(c.map(h=>h.name));i=i.filter(h=>!l.has(h.name)),o=this.sugar(c)}return o=o.concat(this.sugar(await this.writer.create(i))),a?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),a=this.sugar(await this.retriever.retrieve(e,t));return Xe("channel",e,a,n),n?a[0]:a}async delete(e){const{normalized:t,variant:n}=J(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(T.toArray(e),T.toArray(t))}createDebouncedBatchRetriever(e=10){return new hn(new Ya(new St(this.client),e))}sugar(e){const{frameClient:t}=this;return Array.isArray(e)?e.map(n=>new Wt({...n,frameClient:t})):new Wt({...e,frameClient:t})}async retrieveGroup(){const e=await g(this.client,jd,{},Ud,Dd);return new ln(e.group.name,e.group.key)}};const pt=({virtual:r,expression:e})=>r&&e!=="",_a=async(r,e)=>{if(!pt(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(pt(n)){const a=await _a(r,n);if(a!=null)return a}}return null},Ha=r=>({type:"channel",key:r.toString()}),Md=s.z.object({channels:qa.array()}),Zd=s.z.object({channels:Je.array()}),Pd=s.z.object({keys:U.array().optional(),names:le.array().optional()}),Ld=s.z.object({}),Bd=s.z.object({keys:U.array(),names:le.array()}),qd=s.z.object({}),Fd="/channel/create",Yd="/channel/delete",Vd="/channel/rename";let Ga=class{client;cache;constructor(e,t){this.client=e,this.cache=t}async create(e){const{channels:t}=await g(this.client,Fd,{channels:e.map(n=>({...n,dataType:n.dataType}))},Md,Zd);return this.cache.set(t),t}async delete(e){await g(this.client,Yd,e,Pd,Ld),e.keys!=null&&this.cache.delete(e.keys),e.names!=null&&this.cache.delete(e.names)}async rename(e,t){await g(this.client,Vd,{keys:e,names:t},Bd,qd),this.cache.rename(e,t)}};const Wd=Object.freeze(Object.defineProperty({__proto__:null,CALCULATION_STATUS_CHANNEL_NAME:Rd,CacheRetriever:hn,Channel:Wt,Client:Wa,ClusterRetriever:St,DELETE_CHANNEL_NAME:xd,DebouncedBatchRetriever:Ya,SET_CHANNEL_NAME:Cd,Writer:Ga,analyzeParams:J,isCalculated:pt,keyZ:U,nameZ:le,newZ:qa,ontologyID:Ha,paramsZ:Ce,payloadZ:Je,resolveCalculatedIndex:_a,retrieveRequired:Va,statusZ:Ba},Symbol.toStringTag,{value:"Module"})),Oe=s.z.uuid(),It=s.z.object({key:Oe,username:s.z.string().min(1),firstName:s.z.string().default(""),lastName:s.z.string().default(""),rootUser:s.z.boolean().default(!0)}),Ka=It.partial({key:!0,firstName:!0,lastName:!0}).omit({rootUser:!0}).extend({password:s.z.string().min(1)}),_d=s.z.object({keys:Oe.array().optional(),usernames:s.z.string().array().optional()}),Hd=s.z.object({key:Oe}).transform(({key:r})=>({keys:[r]})),Gd=s.z.object({username:s.z.string()}).transform(({username:r})=>({usernames:[r]})),Kd=s.z.object({usernames:s.z.string().array()}).transform(({usernames:r})=>({usernames:r})),Jd=s.z.union([Hd,Gd,Kd,_d]),Xd=s.z.object({users:V(It)}),Qd=s.z.object({users:Ka.array()}),ef=s.z.object({users:It.array()}),tf=s.z.object({key:Oe,username:s.z.string().min(1)}),rf=s.z.object({}),nf=s.z.object({key:Oe,firstName:s.z.string().optional(),lastName:s.z.string().optional()}),sf=s.z.object({}),af=s.z.object({keys:Oe.array()}),of=s.z.object({}),cf="/user/retrieve",lf="/user/create",uf="/user/change-username",hf="/user/rename",df="/user/delete";let Ja=class{client;constructor(e){this.client=e}async create(e){const t=Array.isArray(e),n=await g(this.client,lf,{users:T.toArray(e)},Qd,ef);return t?n.users:n.users[0]}async changeUsername(e,t){await g(this.client,uf,{key:e,username:t},tf,rf)}async retrieve(e){const t="key"in e||"username"in e,n=await g(this.client,cf,e,Jd,Xd);if(!t)return n.users;if(n.users.length===0){const a="key"in e?`key ${e.key}`:`username ${e.username}`;throw new ft(`No user with ${a} found`)}if(n.users.length>1){const a="key"in e?`key ${e.key}`:`username ${e.username}`;throw new yt(`Multiple users found with ${a}`)}return n.users[0]}async rename(e,t,n){await g(this.client,hf,{key:e,firstName:t,lastName:n},nf,sf)}async delete(e){await g(this.client,df,{keys:T.toArray(e)},af,of)}};const ff=r=>({type:"user",key:r}),yf=Object.freeze(Object.defineProperty({__proto__:null,Client:Ja,keyZ:Oe,newZ:Ka,ontologyID:ff,userZ:It},Symbol.toStringTag,{value:"Module"})),gf=s.z.object({username:s.z.string(),password:s.z.string()}),pf=s.z.object({token:s.z.string(),user:It}),Jn="/auth/login",mf=3,wf="/auth/change-password",bf=s.z.object({username:s.z.string(),password:s.z.string(),newPassword:s.z.string().min(1)}),Tf=s.z.object({}),vf=[Br,qr];let Ef=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 g(this.client,wf,{username:this.credentials.username,password:this.credentials.password,newPassword:e},bf,Tf),this.credentials.password=e}middleware(){const e=async(t,n)=>{if(!this.authenticated&&!t.target.endsWith(Jn)){this.authenticating??=new Promise((c,l)=>{this.client.send(Jn,this.credentials,gf,pf).then(([h,d])=>{if(d!=null)return c(d);this.token=h?.token,this.user=h?.user,this.authenticated=!0,c(null)}).catch(l)});const o=await this.authenticating;if(o!=null)return[t,o]}t.params.Authorization=`Bearer ${this.token}`;const[a,i]=await n(t);return vf.some(o=>o.matches(i))&&this.retryCount<mf?(this.authenticated=!1,this.authenticating=void 0,this.retryCount+=1,e(t,n)):(this.retryCount=0,[a,i])};return e}};const Xa=s.z.enum(["disconnected","connecting","connected","failed"]),Qa=s.z.object({status:Xa,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()}),Of=s.z.object({clusterKey:s.z.string(),nodeVersion:s.z.string().optional()}),Xn={clusterKey:"",status:"disconnected",error:void 0,message:"Disconnected",clientServerCompatible:!1,clientVersion:"0.44.2"},Qn=(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
|
|
24
|
-
Got ${t.length} ${n}s and ${e.length} series.`)};class Z{columns=[];series=[];constructor(e=[],t=[]){if(e instanceof Z){this.columns=e.columns,this.series=e.series;return}if(e instanceof Map){e.forEach((a,i)=>this.push(i,...T.toArray(a)));return}if(typeof e=="object"&&!Array.isArray(e)){if("keys"in e&&"series"in e){const a=e;a.series??=[],a.keys??=[];const i=a.series.map(o=>
|
|
23
|
+
https://docs.synnaxlabs.com/reference/typescript-client/troubleshooting#old-${n}-version`};class mt{static ENDPOINT="/connectivity/check";static DEFAULT=Xn;_state;pollFrequency=E.seconds(30);client;name;interval;clientVersion;onChangeHandlers=[];static connectionStateZ=Qa;versionWarned=!1;constructor(e,t=E.seconds(30),n,a){this._state={...Xn},this.client=e,this.pollFrequency=t,this.clientVersion=n,this.name=a,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(mt.ENDPOINT,{},s.z.object({}),Of);if(n!=null)throw n;const a=t.nodeVersion,i=this.clientVersion,o=this.versionWarned;a==null?(this._state.clientServerCompatible=!1,o||(console.warn(Qn(null,i,!0)),this.versionWarned=!0)):Hn.versionsEqual(i,a,{checkMajor:!0,checkMinor:!0,checkPatch:!1})?this._state.clientServerCompatible=!0:(this._state.clientServerCompatible=!1,o||(console.warn(Qn(a,i,Hn.semVerNewer(i,a))),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 Nf=Object.freeze(Object.defineProperty({__proto__:null,Checker:mt,stateZ:Qa,statusZ:Xa},Symbol.toStringTag,{value:"Module"})),zf=s.z.object({keys:U.array().optional(),bounds:z.z,names:le.array().optional()}),Sf=s.z.object({}),If="/frame/delete";class Af{client;constructor(e){this.client=e}async delete(e){await g(this.client,If,e,zf,Sf)}}const es=r=>{const e=T.toArray(r);return e.length===0?null:typeof e[0]=="number"||!isNaN(parseInt(e[0]))?"key":"name"},ts=(r,e)=>{const t=T.toArray(r);if(t.length===e.length)return;const n=es(r);throw es===null?new M("[Frame] - channel keys or names must be provided when constructing a frame."):new M(`[Frame] - ${n}s and series must be the same length.
|
|
24
|
+
Got ${t.length} ${n}s and ${e.length} series.`)};class Z{columns=[];series=[];constructor(e=[],t=[]){if(e instanceof Z){this.columns=e.columns,this.series=e.series;return}if(e instanceof Map){e.forEach((a,i)=>this.push(i,...T.toArray(a)));return}if(typeof e=="object"&&!Array.isArray(e)){if("keys"in e&&"series"in e){const a=e;a.series??=[],a.keys??=[];const i=a.series.map(o=>ei(o));ts(a.keys,i),a.keys.forEach((o,c)=>this.push(o,i[c]))}else Object.entries(e).forEach(([a,i])=>{const o=parseInt(a);if(!isNaN(o))return this.push(o,...T.toArray(i));this.push(a,...T.toArray(i))});return}if(Array.isArray(e)||["string","number"].includes(typeof e)){const a=T.toArray(t),i=T.toArray(e);ts(i,a),a.forEach((o,c)=>this.push(i[c],o));return}throw new M(`[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 Ye("colType is not key");return this.columns??[]}get uniqueKeys(){return Mn.unique(this.keys)}get names(){if(this.colType==="key")throw new Ye("colType is not name");return this.columns??[]}get uniqueNames(){return Mn.unique(this.names)}get uniqueColumns(){return this.colType==="key"?this.uniqueKeys:this.uniqueNames}toPayload(){return{series:this.series.map(e=>
|
|
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 Ye("colType is not key");return this.columns??[]}get uniqueKeys(){return Mn.unique(this.keys)}get names(){if(this.colType==="key")throw new Ye("colType is not name");return this.columns??[]}get uniqueNames(){return Mn.unique(this.names)}get uniqueColumns(){return this.colType==="key"?this.uniqueKeys:this.uniqueNames}toPayload(){return{series:this.series.map(e=>ti(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 z.ZERO;const n=O.min(...this.series.map(i=>i.timeRange.start)),a=O.max(...this.series.map(i=>i.timeRange.end));return new z(n,a)}const t=this.get(e);return t==null?z.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 ca(this.series.filter((t,n)=>this.columns[n]===e))}push(e,...t){if(e instanceof Z){if(this.colType!==null&&e.colType!==this.colType)throw new M("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 M("keyVariant must match");if(typeof e!="string"&&this.colType==="name")throw new M("keyVariant must match");this.columns.push(...Array.from({length:t.length},()=>e))}}concat(e){return new Z([...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 Z;return this.forEach((n,a,i)=>t.push(...e(n,a,i))),t}forEach(e){this.columns.forEach((t,n)=>{const a=this.series[n];e(t,a,n)})}at(e,t=!1){const n={};return this.uniqueColumns.forEach(a=>{n[a]=this.get(a).at(e,t)}),n}filter(e){const t=new Z;return this.columns.forEach((n,a)=>{const i=this.series[a];e(n,i,a)&&t.push(n,i)}),t}get byteLength(){return new S(this.series.reduce((e,t)=>e.add(t.byteLength),S.ZERO))}get digest(){const e={};return this.keys.forEach((t,n)=>{const a=this.series[n].digest;t in e?e[t].push(a):e[t]=[a]}),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
|
|
28
|
+
`}),e+="}",e}}const er=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(()=>[]),F.crudeZ.array().optional().default([])])}),ei=r=>{const{dataType:e,data:t,timeRange:n,alignment:a}=r;return new F({data:t,dataType:e,timeRange:n,glBufferUsage:"static",alignment:a})},ti=r=>({timeRange:r.timeRange,dataType:r.dataType,data:new Uint8Array(r.data.buffer),alignment:r.alignment});var We=(r=>(r[r.Open=0]="Open",r[r.Write=1]="Write",r[r.Commit=2]="Commit",r[r.SetAuthority=3]="SetAuthority",r))(We||{}),wt=(r=>(r[r.PersistStream=1]="PersistStream",r[r.Persist=2]="Persist",r[r.Stream=3]="Stream",r))(wt||{});const $f=new E(-1);class Vr extends ne.sub("writer_closed"){constructor(){super("WriterClosed")}}const kf=s.z.enum(wt).or(s.z.enum(["persist","stream","persistStream"]).transform(r=>{switch(r){case"persist":return 2;case"stream":return 3;case"persistStream":return 1}})),ri=s.z.object({start:O.z.optional(),controlSubject:K.subjectZ.optional(),authorities:s.z.union([K.authorityZ.transform(r=>[r]),K.authorityZ.array()]).default([K.ABSOLUTE_AUTHORITY]),mode:kf.default(1),errOnUnauthorized:s.z.boolean().default(!1),enableAutoCommit:s.z.boolean().default(!1),autoIndexPersistInterval:E.z.default(E.SECOND),useExperimentalCodec:s.z.boolean().default(!1)}),Cf=ri.extend({keys:U.array().optional()}),rs=ri.extend({channels:Ce}),ni=rs.or(Ce.transform(r=>rs.parse({channels:r,start:O.now()}))),xf=s.z.object({command:s.z.enum(We),config:Cf.optional(),frame:er.optional(),buffer:s.z.instanceof(Uint8Array).optional()}),Rf=s.z.object({command:s.z.enum(We),end:O.z,err:ue.payloadZ.optional()}),jf=s.z.tuple([s.z.union([s.z.record(U.or(le),K.authorityZ),U.or(le),K.authorityZ]),K.authorityZ.optional()]).transform(([r,e])=>{if(K.authorityZ.safeParse(r).success)return{keys:[],authorities:[r]};if(U.or(le).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 si=class Wr{static ENDPOINT="/frame/write";stream;adapter;closeErr=null;constructor(e,t){this.stream=e,this.adapter=t}static async _open(e,t,n){const a=ni.parse(n),i=await fn.open(e,a.channels);a.useExperimentalCodec&&(t=t.withCodec(new Lf(i.codec)));const o=await t.stream(Wr.ENDPOINT,xf,Rf),c=new Wr(o,i);return await c.execute({command:0,config:{...a,keys:i.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=jf.parse([e,t]),a={keys:await this.adapter.adaptParams(n.keys),authorities:n.authorities};await this.execute({command:3,config:a})}async commit(){if(this.closeErr!=null)throw this.closeErr;return this.stream.received()?(await this.closeInternal(null),O.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(Vr.matches(this.closeErr))return null;throw this.closeErr}const[t,n]=await this.stream.receive();n!=null?this.closeErr=X.matches(n)?new Vr:n:this.closeErr=ue.decode(t?.err)}}async execute(e){const t=this.stream.send(e);for(t!=null&&await this.closeInternal(t);;){const[n,a]=await this.stream.receive();a!=null&&await this.closeInternal(a);const i=ue.decode(n?.err);if(i!=null&&await this.closeInternal(i),n?.command==e.command)return n}}};const ns=r=>r.data.byteLength/r.dataType.density.valueOf(),Uf=r=>{const{keys:e,series:t}=r;e.forEach((n,a)=>{t[a].key=n}),t.sort((n,a)=>n.key-a.key),e.sort((n,a)=>n-a),t.forEach(n=>delete n.key)},ss=5,as=4,is=3,os=2,cs=1,ls=0,Q=I.TIMESTAMP.density.valueOf(),me=8,we=4,wr=4,br=4,Df=1;class ai{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((a,i)=>{const o=t[i];n.keyDataTypes.set(a,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 M(`
|
|
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()),Uf(n);let a=-1,i,o,c,l=t+Df+br,h=!this.currState?.hasVariableDataTypes,d=!0,u=!0,N=!0,v=!0,P=!0;n.keys.length!==this.currState?.keys.length&&(N=!1,l+=n.keys.length*wr),n.series.forEach((D,ye)=>{const ie=ns(D),nt=n.keys[ye],ze=this.currState?.keyDataTypes.get(nt);if(ze==null)throw new M(`Channel ${nt} was not provided in the list of channels when opening the writer`);if(!ze.equals(D.dataType))throw new M(`Series data type of ${D.dataType.toString()} does not match the data type of ${ze.toString()} for channel ${nt}`);if(l+=D.data.byteLength,a===-1){a=ie,i=D.timeRange?.start,o=D.timeRange?.end,c=BigInt(D.alignment??0n);return}a!==ie&&(h=!1),(i?.valueOf()!==D.timeRange?.start.valueOf()||o?.valueOf()!==D.timeRange?.end.valueOf())&&(d=!1),c!==BigInt(D.alignment??0)&&(v=!1)}),u=d&&i==null&&o==null,P=v&&(c===void 0||c===0n),h?l+=we:l+=n.keys.length*we,u||(d?l+=Q*2:l+=n.keys.length*Q*2),P||(v?l+=me:l+=n.keys.length*me);const k=new Uint8Array(l),L=new DataView(k.buffer);let C=t;return k[C]=Number(P)<<ss|Number(v)<<as|Number(h)<<is|Number(d)<<os|Number(u)<<cs|Number(N)<<ls,C++,L.setUint32(C,this.seqNum,!0),C+=br,h&&(L.setUint32(C,a,!0),C+=we),d&&!u&&(L.setBigUint64(C,i?.valueOf()??0n,!0),L.setBigUint64(C,o?.valueOf()??0n,!0),C+=Q*2),v&&!P&&(L.setBigUint64(C,c??0n,!0),C+=me),n.series.forEach((D,ye)=>{if(N||(L.setUint32(C,n.keys[ye],!0),C+=wr),!h){let ie=D.data.byteLength;D.dataType.isVariable||(ie=ns(D)),L.setUint32(C,ie,!0),C+=we}k.set(new Uint8Array(D.data),C),C+=D.data.byteLength,!d&&!u&&(L.setBigUint64(C,D.timeRange?.start.valueOf()??0n,!0),L.setBigUint64(C,D.timeRange?.end.valueOf()??0n,!0),C+=Q*2),!v&&!P&&(L.setBigUint64(C,D.alignment??0n,!0),C+=me)}),k}decode(e,t=0){this.throwIfNotUpdated("decode");const n=e instanceof Uint8Array?e:new Uint8Array(e),a={keys:[],series:[]};let i=t,o=0,c=0,l,h,d;const u=new DataView(n.buffer,n.byteOffset,n.byteLength),N=!!(n[i]>>ss&1),v=!!(n[i]>>as&1),P=!!(n[i]>>is&1),k=!!(n[i]>>os&1),L=!!(n[i]>>cs&1),C=!!(n[i]>>ls&1);i++;const D=u.getUint32(i,!0);i+=br;const ye=this.states.get(D);if(ye==null)return a;if(P){if(i+we>u.byteLength)return a;o=u.getUint32(i,!0),i+=we}if(k&&!L){if(i+Q>u.byteLength)return a;l=new O(u.getBigUint64(i,!0)),i+=Q,h=new O(u.getBigUint64(i,!0)),i+=Q}if(v&&!N){if(i+me>u.byteLength)return a;d=u.getBigUint64(i,!0),i+=me}return C&&(a.keys=[...ye.keys]),ye.keys.forEach((ie,nt)=>{if(!C){if(i>=u.byteLength||u.getUint32(i,!0)!==ie)return;i+=wr,a.keys.push(ie)}const ze=ye.keyDataTypes.get(ie);if(c=0,P)c=o;else{if(i+we>u.byteLength)return;c=u.getUint32(i,!0),i+=we}let Ct=c;if(ze.isVariable||(Ct*=ze.density.valueOf()),i+Ct>u.byteLength){a.keys.splice(nt,1);return}const Se={dataType:ze,data:n.slice(i,i+Ct).buffer};if(i+=Ct,!k&&!L){if(i+Q*2>u.byteLength)return;const Nn=u.getBigUint64(i,!0);i+=Q;const eo=u.getBigUint64(i,!0);i+=Q,Se.timeRange=new z({start:Nn,end:eo})}else L?Se.timeRange=new z({start:0n,end:0n}):Se.timeRange=new z({start:l?.valueOf()??0n,end:h?.valueOf()??0n});if(!v&&!N){if(i+me>u.byteLength)return;d=u.getBigUint64(i,!0),i+=me,Se.alignment=d}else N?Se.alignment=0n:Se.alignment=d;a.series.push(Se)}),a}}const dn=254,Mf=new Uint8Array([dn]),Zf=255,Pf=new Uint8Array([Zf]),ii="application/sy-framer";class Lf{contentType=ii;base;lowPerfCodec;constructor(e){this.base=e,this.lowPerfCodec=ke.JSON_CODEC}encode(e){const t=e;if(t.type=="close"||t.payload?.command!=We.Write){const a=this.lowPerfCodec.encode(t),i=new Uint8Array({length:a.byteLength+1});return i.set(Mf,0),i.set(new Uint8Array(a),1),i}const n=this.base.encode(t.payload?.frame,1);return n.set(Pf,0),n}decode(e,t){if(new DataView(e instanceof Uint8Array?e.buffer:e).getUint8(0)===dn)return this.lowPerfCodec.decode(e.slice(1),t);const i={type:"data"},o=this.base.decode(e,1);return i.payload={command:We.Write,frame:o},i}}class Bf{contentType=ii;base;lowPerfCodec;constructor(e){this.base=e,this.lowPerfCodec=ke.JSON_CODEC}encode(e){return this.lowPerfCodec.encode(e)}decode(e,t){return new DataView(e instanceof Uint8Array?e.buffer:e).getUint8(0)===dn?this.lowPerfCodec.decode(e.slice(1),t):{type:"data",payload:{frame:this.base.decode(e,1)}}}}class tr{adapter;retriever;keys;codec;constructor(e){this.retriever=e,this.adapter=null,this.keys=[],this.codec=new ai}static async open(e,t){const n=new tr(e);return await n.update(t),n}async update(e){const{variant:t,normalized:n}=J(e),a=await this.retriever.retrieve(n),i=a.map(c=>c.key);if(Zn.uniqueUnorderedPrimitiveArrays(this.keys,i)===Zn.EQUAL)return!1;if(this.codec.update(i,a.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 l=a.find(h=>h.name===c);if(l==null)throw new Error(`Channel ${c} not found`);o.set(l.key,l.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,a)=>{if(typeof n=="number"){const i=t.get(n);if(i==null)throw new Error(`Channel ${n} not found`);return[i,a]}return[n,a]})}}class fn{adapter;retriever;keys;codec;constructor(e){this.retriever=e,this.adapter=null,this.keys=[],this.codec=new ai}static async open(e,t){const n=new fn(e);return await n.update(t),n}async adaptParams(e){const t=Ce.parse(e);return await Promise.all(t.map(async a=>await this.adaptToKey(a)))}async update(e){const t=await Va(this.retriever,e),n=t.map(h=>h.key),a=new Set(this.keys),i=new Set(n),o=!i.isSubsetOf(a),c=!a.isSubsetOf(i);return o||c?(this.adapter=new Map(t.map(h=>[h.name,h.key])),this.keys=n,this.codec.update(this.keys,t.map(h=>h.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 M(`
|
|
32
32
|
Received a single channel name or key but no series.
|
|
33
|
-
`);if(Array.isArray(t)){if(t.some(l=>l instanceof
|
|
33
|
+
`);if(Array.isArray(t)){if(t.some(l=>l instanceof F||Array.isArray(l)))throw new M(`
|
|
34
34
|
Received a single channel name or key but multiple series.
|
|
35
|
-
`);t=t}const o=await this.fetchChannel(e),c=new
|
|
35
|
+
`);t=t}const o=await this.fetchChannel(e),c=new F({data:t,dataType:o.dataType});return new Z(o.key,c)}if(Array.isArray(e)){if(t==null)throw new M(`
|
|
36
36
|
Received an array of channel names or keys but no series.
|
|
37
37
|
`);if(!Array.isArray(t))throw new M(`
|
|
38
38
|
Received an array of channel names or keys but no array of series.
|
|
39
39
|
`);const o=[],c=[];for(let l=0;l<e.length;l++){const h=await this.fetchChannel(e[l]);if(l>=t.length)throw new M(`
|
|
40
40
|
Received an array of channel names or keys but not enough series.
|
|
41
|
-
`);const d=new
|
|
41
|
+
`);const d=new F({data:t[l],dataType:h.dataType});o.push(h.key),c.push(d)}return new Z(o,c)}if(e instanceof Z||e instanceof Map){const o=new Z(e);if(this.adapter==null)return o;const c=o.columns.map(l=>{const h=typeof l=="string"?this.adapter?.get(l):l;if(h==null)throw new M(`
|
|
42
42
|
Channel ${l} was not provided in the list of channels when opening the writer
|
|
43
|
-
`);return h});return new Z(c,o.series)}const n=[],a=[],i=Object.entries(e);for(let o=0;o<i.length;o++){const[c,l]=i[o],h=await this.fetchChannel(c),d=new
|
|
44
|
-
Please report this error to the Synnax team.`),t!=null){if(K.matches(t))return;throw t}}}closeSend(){this.stream.closeSend()}send(e){const t=this.stream.send(e);if(t!=null)throw t}}const Yt=new v(-1);var yn=(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))(yn||{}),oi=(r=>(r[r.None=0]="None",r[r.Ack=1]="Ack",r[r.Data=2]="Data",r))(oi||{});const Lf=s.z.object({command:s.z.enum(yn),span:v.z.optional(),bounds:z.z.optional(),stamp:O.z.optional(),keys:U.array().optional(),chunkSize:s.z.number().optional()}),Bf=s.z.object({variant:s.z.enum(oi),ack:s.z.boolean(),command:s.z.enum(yn),error:le.payloadZ.optional().nullable(),frame:Xt.optional()});class wt{static ENDPOINT="/frame/iterate";stream;adapter;value;constructor(e,t){this.stream=new ii("Iterator",e),this.value=new Z,this.adapter=t}static async _open(e,t,n,a,i={}){const o=await Qt.open(n,t),c=await a.stream(wt.ENDPOINT,Lf,Bf),l=new wt(c,o);return await l.execute({command:0,keys:o.keys,bounds:new z(e),chunkSize:i.chunkSize??1e5}),l}async next(e=Yt){return await this.execute({command:1,span:new v(e)})}async prev(e=Yt){return await this.execute({command:2,span:new v(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 O(e)})}async seekGE(e){return await this.execute({command:6,stamp:new O(e)})}async valid(){return await this.execute({command:7})}async close(){await this.stream.closeAndAck()}[Symbol.asyncIterator](){return new qf(this)}async execute(e){for(this.stream.send(e),this.value=new Z;;){const t=await this.stream.receive();if(t.variant===1)return t.ack;this.value.push(this.adapter.adapt(new Z(t.frame)))}}}class qf{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 Ff=s.z.object({keys:s.z.number().array(),downsampleFactor:s.z.number()}),Yf=s.z.object({frame:Xt}),Vf="/frame/stream",us=s.z.object({channels:ke,downsampleFactor:s.z.number().optional().default(1),useExperimentalCodec:s.z.boolean().optional().default(!1)}),gn=us.or(ke.transform(r=>us.parse({channels:r}))),ci=(r,e)=>async t=>{const n=gn.parse(t),a=await Qt.open(r,n.channels);n.useExperimentalCodec&&(e=e.withCodec(new Pf(a.codec)));const i=await e.stream(Vf,Ff,Yf),o=new Wf(i,a);i.send({keys:a.keys,downsampleFactor:n.downsampleFactor??1});const[,c]=await i.receive();if(c!=null)throw c;return o},li=async(r,e,t)=>await ci(r,e)(t);class Wf{stream;adapter;downsampleFactor;constructor(e,t){this.stream=new ii("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(K.matches(e))return{done:!0,value:void 0};throw e}}async read(){return this.adapter.adapt(new Z((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 er{wrapped_=null;breaker;opener;config;constructor(e,t,n={}){this.opener=e,this.config=gn.parse(t);const{maxRetries:a=5e3,baseInterval:i=v.seconds(1),scale:o=1}=n??{};this.breaker=new ha.Breaker({maxRetries:a,baseInterval:i,scale:o})}static async open(e,t,n){const a=new er(e,t,n);return await a.runStreamer(),a}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=ke.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(K.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(K.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 ui extends Eu.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 _f=r=>({type:"framer",key:r.toString()});let hi=class{streamClient;retriever;deleter;constructor(e,t,n){this.streamClient=e,this.retriever=n,this.deleter=new Sf(t)}async openIterator(e,t,n){return await wt._open(e,t,this.retriever,this.streamClient,n)}async openWriter(e){return await ni._open(this.retriever,this.streamClient,e)}async openStreamer(e){return await li(this.retriever,this.streamClient,e)}async write(e,t,n){if(n==null){const i=t,o=await this.openWriter({start:e,channels:Object.keys(i),mode:mt.Persist,errOnUnauthorized:!0,enableAutoCommit:!0,autoIndexPersistInterval:v.MAX});return await o.write(i),await o.close()}const a=await this.openWriter({start:e,channels:t,mode:mt.Persist,errOnUnauthorized:!0,enableAutoCommit:!0,autoIndexPersistInterval:v.MAX});await a.write(t,n),await a.close()}async read(e,t){const{single:n}=J(t),a=await this.readFrame(e,t);return n?a.get(t):a}async readFrame(e,t){const n=await this.openIterator(e,t),a=new Z;try{for await(const i of n)a.push(i)}finally{await n.close()}return a}async readLatest(e,t=1){const{single:n}=J(e),a=await this.readLatestNFrame(e,t);return n?a.get(e):a}async readLatestNFrame(e,t){const n=await this.openIterator(z.MAX,e,{chunkSize:t}),a=new Z;if(t>0)try{await n.seekLast(),await n.prev(Yt),a.push(n.value)}finally{await n.close()}return a}async delete(e,t){const{normalized:n,variant:a}=J(e);return a==="keys"?await this.deleter.delete({keys:n,bounds:t}):await this.deleter.delete({names:n,bounds:t})}};const Hf=Object.freeze(Object.defineProperty({__proto__:null,ALWAYS_INDEX_PERSIST_ON_AUTO_COMMIT:If,AUTO_SPAN:Yt,Client:hi,Frame:Z,HardenedStreamer:er,Iterator:wt,ObservableStreamer:ui,Writer:ni,WriterClosedError:Fr,WriterCommand:We,WriterMode:mt,createStreamOpener:ci,frameZ:Xt,ontologyID:_f,openStreamer:li,seriesFromPayload:Qa,seriesToPayload:ei,streamerConfigZ:gn,writerConfigZ:ri},Symbol.toStringTag,{value:"Module"})),Gf=G.ABSOLUTE_AUTHORITY,Jf=G.ZERO_AUTHORITY,Kf=G.stateZ(s.z.number()),Xf=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()})`,Qf=s.z.object({transfers:s.z.array(G.transferZ(U))});class di extends ui{states;codec;constructor(e){super(e,t=>{const n=this.codec.decode(t.series[0].buffer,Qf);return this.merge(n),[n.transfers,!0]}),this.states=new Map,this.codec=new $e.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 fi="sy_node_1_control";let yi=class{framer;constructor(e){this.framer=e}async openStateTracker(){const e=await er.open(async t=>await this.framer.openStreamer(t),fi);return new di(e)}};const ey=Object.freeze(Object.defineProperty({__proto__:null,ABSOLUTE_AUTHORITY:Gf,CONTROL_STATE_CHANNEL_NAME:fi,Client:yi,StateTracker:di,ZERO_AUTHORITY:Jf,stateZ:Kf,transferString:Xf},Symbol.toStringTag,{value:"Module"}));let gi=class{tasks;racks;devices;constructor(e,t,n){this.tasks=e,this.racks=t,this.devices=n}};const ty=Object.freeze(Object.defineProperty({__proto__:null,Client:gi},Symbol.toStringTag,{value:"Module"})),ne=s.z.uint32(),pi=Ht.statusZ(s.z.object({rack:ne})),tr=s.z.object({key:ne,name:s.z.string(),status:ct.nullToUndefined(pi)}),mi=tr.partial({key:!0}),wi=r=>r?$e.JSON_CODEC.decodeString(r,ue.unknownZ):{},Qe=s.z.string(),bi=Ht.statusZ(s.z.object({rack:ne,device:Qe})),rr=s.z.object({key:Qe,rack:ne,name:s.z.string(),make:s.z.string(),model:s.z.string(),location:s.z.string(),configured:s.z.boolean().optional(),properties:ue.unknownZ.or(s.z.string().transform(wi)),status:ct.nullToUndefined(bi)}),Ti=rr.extend({properties:s.z.unknown().transform(r=>$e.JSON_CODEC.encodeString(r))}),ry="sy_device_set",ny="sy_device_delete",sy="sy_device_status",ay="/hardware/device/retrieve",iy="/hardware/device/create",oy="/hardware/device/delete",cy=s.z.object({devices:Ti.array()}),ly=s.z.object({devices:rr.array()}),uy=s.z.object({keys:Qe.array()}),hy=s.z.object({}),dy=s.z.object({keys:Qe.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:ne.array().optional(),searchTerm:s.z.string().optional(),limit:s.z.number().optional(),offset:s.z.number().optional(),includeStatus:s.z.boolean().optional()}),fy=s.z.object({devices:L(rr)}),yy=s.z.object({key:Qe,includeStatus:s.z.boolean().optional()}).transform(({key:r,includeStatus:e})=>({keys:[r],includeStatus:e})),gy=s.z.union([yy,dy]);let vi=class{type="device";client;constructor(e){this.client=e}async retrieve(e){const t=typeof e=="object"&&"key"in e,n=await g(this.client,ay,e,gy,fy);Xe("Device",e,n.devices,t);const a=n.devices;return t?a[0]:a}async create(e){const t=!Array.isArray(e),a=(await g(this.client,iy,{devices:T.toArray(e)},cy,ly)).devices;return t?a[0]:a}async delete(e){await g(this.client,oy,{keys:T.toArray(e)},uy,hy)}};const py=r=>({type:"device",key:r}),my=Object.freeze(Object.defineProperty({__proto__:null,Client:vi,DELETE_CHANNEL_NAME:ny,SET_CHANNEL_NAME:ry,STATUS_CHANNEL_NAME:sy,deviceZ:rr,keyZ:Qe,newZ:Ti,ontologyID:py,statusZ:bi},Symbol.toStringTag,{value:"Module"})),wy="/hardware/rack/retrieve",by="/hardware/rack/create",Ty="/hardware/rack/delete",vy="sy_rack_status",Ey="sy_rack_set",Oy="sy_rack_delete",Ny=s.z.object({keys:ne.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()}),zy=s.z.object({racks:L(tr)}),Sy=s.z.union([s.z.object({key:ne,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}))]),Iy=Ny,Ay=s.z.union([Sy,Iy]),$y=s.z.object({racks:mi.array()}),ky=s.z.object({racks:tr.array()}),Cy=s.z.object({keys:ne.array()}),xy=s.z.object({});let Ei=class{type="rack";client;tasks;constructor(e,t){this.client=e,this.tasks=t}async delete(e){await g(this.client,Ty,{keys:T.toArray(e)},Cy,xy)}async create(e){const t=!Array.isArray(e),n=await g(this.client,by,{racks:T.toArray(e)},$y,ky),a=this.sugar(n.racks);return t?a[0]:a}async retrieve(e){const t="key"in e||"name"in e,n=await g(this.client,wy,e,Ay,zy),a=this.sugar(n.racks);return Xe("Rack",e,a,t),t?a[0]:a}sugar(e){const t=!Array.isArray(e),n=T.toArray(e).map(({key:a,name:i,status:o})=>new Oi(a,i,this.tasks,o));return t?n[0]:n}};class Oi{key;name;status;tasks;constructor(e,t,n,a){this.key=e,this.name=t,this.tasks=n,this.status=a}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 Ry=r=>({type:"rack",key:r.toString()}),jy=Object.freeze(Object.defineProperty({__proto__:null,Client:Ei,DELETE_CHANNEL_NAME:Oy,Rack:Oi,SET_CHANNEL_NAME:Ey,STATUS_CHANNEL_NAME:vy,keyZ:ne,newZ:mi,ontologyID:Ry,rackZ:tr,statusZ:pi},Symbol.toStringTag,{value:"Module"})),he=r=>r?JSON.parse(r):{},de=s.z.union([s.z.string(),s.z.bigint().transform(r=>r.toString()),s.z.number().transform(r=>r.toString())]),Ni=r=>s.z.object({task:de,running:s.z.boolean(),data:r}),pn=r=>Ht.statusZ(Ni(r)),St=(r={typeSchema:s.z.string(),configSchema:s.z.unknown(),statusDataSchema:s.z.unknown()})=>s.z.object({key:de,name:s.z.string(),type:r.typeSchema,internal:s.z.boolean().optional(),config:s.z.string().transform(wi).or(r.configSchema),status:pn(r.statusDataSchema).optional().nullable(),snapshot:s.z.boolean().optional()}),zi=r=>St(r).omit({key:!0}).extend({key:de.transform(e=>e.toString()).optional(),config:s.z.unknown().transform(e=>$e.JSON_CODEC.encodeString(e))}),Uy=s.z.object({task:de,type:s.z.string(),key:s.z.string(),args:ue.unknownZ.or(s.z.string().transform(he)).or(s.z.array(s.z.unknown())).or(s.z.null()).optional()}),Dy=r=>Number(BigInt(r)>>32n),Vr="sy_task_status",Wr="sy_task_cmd",My="sy_task_set",Zy="sy_task_delete",Se=new Error("Task not created"),Si=async(r,e)=>{const t=await e.retrieveParents(mn(r));return t.length===0?null:t[0]};class Ii{key;name;internal;type;snapshot;config;status;schemas;frameClient_;ontologyClient_;rangeClient_;get frameClient(){if(this.frameClient_==null)throw Se;return this.frameClient_}get ontologyClient(){if(this.ontologyClient_==null)throw Se;return this.ontologyClient_}get rangeClient(){if(this.rangeClient_==null)throw Se;return this.rangeClient_}constructor({key:e,type:t,name:n,config:a,internal:i=!1,snapshot:o=!1,status:c},l,h,d,u){this.key=e,this.name=n,this.type=t,this.config=a,this.schemas=l??{typeSchema:s.z.string(),configSchema:s.z.unknown(),statusDataSchema:s.z.unknown()},this.internal=i,this.snapshot=o,this.status=c,this.frameClient_=h,this.ontologyClient_=d,this.rangeClient_=u}get payload(){return{key:this.key,name:this.name,type:this.type,config:this.config,status:this.status,internal:this.internal}}get ontologyID(){return mn(this.key)}async executeCommand(e,t){return await wn(this.frameClient,this.key,e,t)}async executeCommandSync(e,t,n){return await $i(this.frameClient,this.key,e,t,this.name,this.schemas?.statusDataSchema,n)}async snapshottedTo(){if(this.ontologyClient==null||this.rangeClient==null)throw Se;return this.snapshot?await Si(this.key,this.ontologyClient):null}}const Py=s.z.object({rack:ne.optional(),keys:de.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()}),Ly=s.z.union([s.z.object({key:de,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}))]),By=Py,qy=s.z.union([Ly,By]),Fy=r=>s.z.object({tasks:L(St(r))}),Yy="/hardware/task/retrieve",Vy="/hardware/task/create",Wy="/hardware/task/delete",_y="/hardware/task/copy",Hy=r=>s.z.object({tasks:zi(r).array()}),Gy=r=>s.z.object({tasks:St(r).array()}),Jy=s.z.object({keys:de.array()}),Ky=s.z.object({}),Xy=s.z.object({key:de,name:s.z.string(),snapshot:s.z.boolean()}),Qy=r=>s.z.object({task:St(r)});let Ai=class{type="task";client;frameClient;ontologyClient;rangeClient;constructor(e,t,n,a){this.client=e,this.frameClient=t,this.ontologyClient=n,this.rangeClient=a}async create(e,t){const n=!Array.isArray(e),a=Hy(t),i=Gy(t),o=await g(this.client,Vy,{tasks:T.toArray(e)},a,i),c=this.sugar(o.tasks,t);return n?c[0]:c}async delete(e){await g(this.client,Wy,{keys:T.toArray(e)},Jy,Ky)}async retrieve({schemas:e,...t}){const n="key"in t||"name"in t,i=(await g(this.client,Yy,t,qy,Fy(e))).tasks,o=this.sugar(i,e);return Xe("Task",t,o,n),n?o[0]:o}async copy(e,t,n){const a=Qy(),i=await g(this.client,_y,{key:e,name:t,snapshot:n},Xy,a);return this.sugar(i.task)}async retrieveSnapshottedTo(e){if(this.ontologyClient==null)throw Se;return await Si(e,this.ontologyClient)}sugar(e,t){const n=!Array.isArray(e),a=T.toArray(e).map(({key:i,name:o,type:c,config:l,status:h,internal:d,snapshot:u})=>new Ii({key:i,name:o,type:c,config:l,internal:d,snapshot:u,status:h},t,this.frameClient,this.ontologyClient,this.rangeClient));return n?a[0]:a}async executeCommand(e,t,n){return await wn(this.frameClient,e,t,n)}async executeCommandSync(e,t,n,a,i,o=s.z.unknown()){const c=async()=>(await this.retrieve({key:e})).name;return await $i(this.frameClient,e,t,n,i??c,o,a)}};const mn=r=>({type:"task",key:r}),wn=async(r,e,t,n)=>{if(r==null)throw Se;const a=eu.create(),i=await r.openWriter(Wr);return await i.write(Wr,[{args:n,key:a,task:e,type:t}]),await i.close(),a},$i=async(r,e,t,n,a,i,o)=>{if(r==null)throw Se;const c=await r.openStreamer(Vr),l=await wn(r,e,t,o),h=new v(n);let d;const u=new Promise((N,E)=>{d=setTimeout(()=>{(async()=>E(await eg(t,a,h,e)))()},h.milliseconds)});try{for(;;){const N=await Promise.race([c.read(),u]),E=pn(i).parse(N.at(-1)[Vr]);if(E.key===l)return E}}finally{clearTimeout(d),c.close()}},eg=async(r,e,t,n)=>{const a=ol.capitalize(r),i=t.toString();try{const o=typeof e=="string"?e:await e();return new Error(`${a} command to ${o} timed out after ${i}`)}catch(o){return console.error("Failed to retrieve task name for timeout error:",o),new Error(`${a} command to task with key ${n} timed out after ${i}`)}},tg=Object.freeze(Object.defineProperty({__proto__:null,COMMAND_CHANNEL_NAME:Wr,Client:Ai,DELETE_CHANNEL_NAME:Zy,SET_CHANNEL_NAME:My,STATUS_CHANNEL_NAME:Vr,Task:Ii,commandZ:Uy,keyZ:de,newZ:zi,ontologyID:mn,rackKey:Dy,statusDetailsZ:Ni,statusZ:pn,taskZ:St},Symbol.toStringTag,{value:"Module"})),Oe=s.z.uuid(),It=s.z.object({key:Oe,name:s.z.string().min(1),color:s.z.string()}),rg="labeled_by",ng="sy_label_set",sg="sy_label_delete",ki=It.extend({key:Oe.optional()}),ag=s.object({labels:ki.array()}),ig=s.object({labels:It.array()}),og=s.object({keys:Oe.array()}),Ci=s.object({id:R,labels:Oe.array(),replace:s.boolean().optional()}),cg=Ci.omit({replace:!0}),wr=s.object({}),lg="/label/create",ug="/label/delete",hg="/label/set",dg="/label/remove",fg="/label/retrieve",yg=s.object({keys:Oe.array().optional(),for:R.optional(),searchTerm:s.string().optional(),offset:s.number().optional(),limit:s.number().optional()}),gg=s.object({key:Oe}).transform(({key:r})=>({keys:[r]})),pg=s.union([gg,yg]),mg=s.object({labels:L(It)});let xi=class{type="label";client;constructor(e){this.client=e}async retrieve(e){const t="key"in e,n=await g(this.client,fg,e,pg,mg);return Xe("Label",e,n.labels,t),t?n.labels[0]:n.labels}async label(e,t,n={}){await g(this.client,hg,{id:e,labels:t,replace:n.replace},Ci,wr)}async remove(e,t){await g(this.client,dg,{id:e,labels:t},cg,wr)}async create(e){const t=Array.isArray(e),n=await g(this.client,lg,{labels:T.toArray(e)},ag,ig);return t?n.labels:n.labels[0]}async delete(e){await g(this.client,ug,{keys:T.toArray(e)},og,wr)}};const wg=r=>({type:"label",key:r}),bg=Object.freeze(Object.defineProperty({__proto__:null,Client:xi,DELETE_CHANNEL_NAME:sg,LABELED_BY_ONTOLOGY_RELATIONSHIP_TYPE:rg,SET_CHANNEL_NAME:ng,keyZ:Oe,labelZ:It,newZ:ki,ontologyID:wg},Symbol.toStringTag,{value:"Module"})),_=s.z.uuid(),bn=s.z.string().min(1),At=s.z.object({key:_,name:bn,timeRange:z.z,color:s.z.string().optional(),labels:L(It),get parent(){return At.optional().nullable().transform(r=>r===void 0?null:r)}}),Ri=At.omit({parent:!0,labels:!0}).partial({key:!0}),Tg="sy_range_alias_set",vg="sy_range_alias_delete",Eg=s.z.object({range:_,aliases:s.z.string().array()}),Og=s.z.object({aliases:s.z.record(s.z.string(),U)}),Ng=s.z.object({range:_,aliases:s.z.record(U.or(s.z.string()),s.z.string())}),zg=s.z.unknown(),Sg=s.z.object({range:_,channels:U.array()}),Ig=s.z.unknown(),Ag=s.z.object({range:_}),$g=s.z.object({aliases:s.z.record(s.z.string(),s.z.string())});class Le{static SET_ENDPOINT="/range/alias/set";static RESOLVE_ENDPOINT="/range/alias/resolve";static LIST_ENDPOINT="/range/alias/list";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",a={};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?a[o]=c:t.push(o)});if(t.length===0)return a;const i=await g(this.client,Le.RESOLVE_ENDPOINT,{range:this.rangeKey,aliases:t},Eg,Og);return Object.entries(i.aliases).forEach(([o,c])=>this.cache.set(o,c)),n?i.aliases[t[0]]:{...a,...i.aliases}}async set(e){await g(this.client,Le.SET_ENDPOINT,{range:this.rangeKey,aliases:e},Ng,zg)}async list(){return(await g(this.client,Le.LIST_ENDPOINT,{range:this.rangeKey},Ag,$g)).aliases}async delete(e){await g(this.client,Le.DELETE_ENDPOINT,{range:this.rangeKey,channels:e},Sg,Ig)}}const kg=s.z.object({alias:s.z.string(),channel:U,range:_}),Cg="---",xg=r=>{const[e,t]=r.split(Cg);return{range:e,channel:Number(t)}},Rg="sy_range_kv_set",jg="sy_range_kv_delete",Tn=s.z.object({range:_,key:s.z.string(),value:s.z.string()}),Ug=s.z.object({range:_,keys:s.z.string().array()}),Dg=s.z.object({pairs:L(Tn)}),Mg=s.z.object({range:_,pairs:Tn.array()}),Zg=s.z.object({range:_,keys:s.z.string().array()});class Ae{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 g(this.client,Ae.GET_ENDPOINT,{range:this.rangeKey,keys:T.toArray(e)},Ug,Dg);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;Ps(e)?n=Object.entries(e).map(([a,i])=>({range:this.rangeKey,key:a,value:i})):n=[{range:this.rangeKey,key:e,value:t}],await g(this.client,Ae.SET_ENDPOINT,{range:this.rangeKey,pairs:n},Mg,s.z.unknown())}async delete(e){await g(this.client,Ae.DELETE_ENDPOINT,{range:this.rangeKey,keys:T.toArray(e)},Zg,s.z.unknown())}}const Pg="sy_range_set",Lg="sy_range_delete";class ji{key;name;kv;timeRange;color;parent;labels;channels;aliaser;frameClient;labelClient;ontologyClient;rangeClient;constructor({name:e,timeRange:t=z.ZERO,key:n,color:a,parent:i,labels:o=[]},{frameClient:c,kv:l,aliaser:h,channels:d,labelClient:u,ontologyClient:N,rangeClient:E}){this.key=n,this.name=e,this.timeRange=t,this.parent=i,this.labels=o,this.frameClient=c,this.color=a,this.kv=l,this.aliaser=h,this.channels=d,this.labelClient=u,this.ontologyClient=N,this.rangeClient=E}get ontologyID(){return Be(this.key)}get payload(){return{key:this.key,name:this.name,timeRange:this.timeRange,color:this.color,labels:this.labels,parent:this.parent}}async setAlias(e,t){const n=await this.channels.retrieve(e);if(n.length===0)throw new ve(`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:Be(this.key)})}async addLabel(...e){await this.labelClient.label(Be(this.key),e)}async removeLabel(...e){await this.labelClient.remove(Be(this.key),e)}static sort(e,t){return z.sort(e.timeRange,t.timeRange)}}const Bg=s.z.object({keys:_.array().optional(),names:s.z.array(s.z.string()).optional(),searchTerm:s.z.string().optional(),overlapsWith:z.z.optional(),limit:s.z.number().int().optional(),offset:s.z.number().int().optional(),hasLabels:Oe.array().optional(),includeLabels:s.z.boolean().optional(),includeParent:s.z.boolean().optional()}),qg=Bg.or(_.array().transform(r=>({keys:r}))).or(_.transform(r=>({keys:[r]}))).or(s.z.string().transform(r=>({names:[r]}))).or(s.z.string().array().transform(r=>({names:r}))).or(z.z.transform(r=>({overlapsWith:r}))),Fg="/range/retrieve",Yg=s.z.object({ranges:L(At)});let Ui=class{type="range";frameClient;writer;unaryClient;channels;labelClient;ontologyClient;constructor(e,t,n,a,i,o){this.frameClient=e,this.writer=t,this.unaryClient=n,this.channels=a,this.labelClient=i,this.ontologyClient=o}async create(e,t){const n=!Array.isArray(e),a=this.sugarMany(await this.writer.create(T.toArray(e),t));return n?a[0]:a}async rename(e,t){await this.writer.rename(e,t)}async delete(e){await this.writer.delete(T.toArray(e))}async retrieve(e){const t=typeof e=="string",{ranges:n}=await g(this.unaryClient,Fg,e,qg,Yg);return Xe("Range",e,n,t),t?this.sugarMany(n)[0]:this.sugarMany(n)}getKV(e){return new Ae(e,this.unaryClient)}async retrieveParent(e){const t=await this.ontologyClient.retrieveParents(Be(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(Di(e))}sugarOne(e){return new ji(e,{frameClient:this.frameClient,kv:new Ae(e.key,this.unaryClient),aliaser:new Le(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 z(e.data?.timeRange),color:e.data?.color,labels:[],parent:null})}};const Be=r=>({type:"range",key:r}),Vg=r=>({type:"range-alias",key:r}),Di=({data:r,id:{key:e},name:t})=>{const n=z.z.parse(r?.timeRange);return{key:e,name:t,timeRange:n,color:typeof r?.color=="string"?r.color:void 0,labels:[],parent:null}},Wg=s.z.object({ranges:At.array()}),_g=s.z.object({parent:R.optional(),ranges:Ri.array()}),Hg=s.z.object({keys:_.array()}),Gg=s.z.object({}),Jg=s.z.object({key:_,name:bn}),Kg=s.z.object({}),Xg="/range/create",Qg="/range/delete",ep="/range/rename";class Mi{client;constructor(e){this.client=e}async rename(e,t){await g(this.client,ep,{key:e,name:t},Jg,Kg)}async create(e,t){return(await g(this.client,Xg,{ranges:e,...t},_g,Wg)).ranges}async delete(e){await g(this.client,Qg,{keys:e},Hg,Gg)}}const tp=Object.freeze(Object.defineProperty({__proto__:null,Client:Ui,DELETE_ALIAS_CHANNEL_NAME:vg,DELETE_CHANNEL_NAME:Lg,KV:Ae,KV_DELETE_CHANNEL:jg,KV_SET_CHANNEL:Rg,Range:ji,SET_ALIAS_CHANNEL_NAME:Tg,SET_CHANNEL_NAME:Pg,Writer:Mi,aliasOntologyID:Vg,aliasZ:kg,convertOntologyResourceToPayload:Di,decodeDeleteAliasChange:xg,keyZ:_,kvPairZ:Tn,nameZ:bn,newZ:Ri,ontologyID:Be,payloadZ:At},Symbol.toStringTag,{value:"Module"})),rp="/api/v1/";class np{url;unary;stream;secure;constructor(e,t={},n=!1){this.secure=n,this.url=e.child(rp);const a=new $e.JSONCodec;this.unary=_c(new Wc(this.url,a,this.secure),t),this.stream=new Xc(this.url,a,this.secure)}use(...e){this.unary.use(...e),this.stream.use(...e)}}const et=s.z.uuid(),nr=s.z.object({key:et,name:s.z.string(),data:ue.unknownZ.or(s.z.string().transform(he))}),Zi=nr.partial({key:!0}).transform(r=>({...r,data:JSON.stringify(r.data)})),se=s.z.uuid(),sr=s.z.object({key:se,name:s.z.string(),layout:ue.unknownZ.or(s.z.string().transform(he))}),Pi=sr.partial({key:!0}).transform(r=>({...r,layout:JSON.stringify(r.layout)})),Li=sr.omit({layout:!0}).extend({layout:s.z.string().transform(he)}),sp="/workspace/lineplot/retrieve",ap="/workspace/lineplot/create",ip="/workspace/lineplot/rename",op="/workspace/lineplot/set-data",cp="/workspace/lineplot/delete",lp=s.z.object({keys:et.array()}),up=s.z.object({workspace:se,linePlots:Zi.array()}),hp=s.z.object({key:et,name:s.z.string()}),dp=s.z.object({key:et,data:s.z.string()}),fp=s.z.object({keys:et.array()}),yp=s.z.object({linePlots:L(nr)}),gp=s.z.object({linePlots:nr.array()}),br=s.z.object({});let Bi=class{client;constructor(e){this.client=e}async create(e,t){const n=Array.isArray(t),a=await g(this.client,ap,{workspace:e,linePlots:T.toArray(t)},up,gp);return n?a.linePlots:a.linePlots[0]}async rename(e,t){await g(this.client,ip,{key:e,name:t},hp,br)}async setData(e,t){await g(this.client,op,{key:e,data:JSON.stringify(t)},dp,br)}async retrieve(e){const t=Array.isArray(e),n=await g(this.client,sp,{keys:T.toArray(e)},lp,yp);return t?n.linePlots:n.linePlots[0]}async delete(e){await g(this.client,cp,{keys:T.toArray(e)},fp,br)}};const pp=r=>({type:"lineplot",key:r}),mp=Object.freeze(Object.defineProperty({__proto__:null,Client:Bi,keyZ:et,linePlotZ:nr,newZ:Zi,ontologyID:pp},Symbol.toStringTag,{value:"Module"})),tt=s.z.uuid(),ar=s.z.object({key:tt,name:s.z.string(),data:ue.unknownZ.or(s.z.string().transform(he))}),qi=ar.partial({key:!0}).transform(r=>({...r,data:JSON.stringify(r.data)})),wp="/workspace/log/retrieve",bp="/workspace/log/create",Tp="/workspace/log/rename",vp="/workspace/log/set-data",Ep="/workspace/log/delete",Op=s.z.object({keys:tt.array()}),Np=s.z.object({workspace:se,logs:qi.array()}),zp=s.z.object({key:tt,name:s.z.string()}),Sp=s.z.object({key:tt,data:s.z.string()}),Ip=s.z.object({keys:tt.array()}),Ap=s.z.object({logs:ar.array()}),$p=s.z.object({logs:ar.array()}),Tr=s.z.object({});let Fi=class{client;constructor(e){this.client=e}async create(e,t){const n=Array.isArray(t),a=await g(this.client,bp,{workspace:e,logs:T.toArray(t)},Np,$p);return n?a.logs:a.logs[0]}async rename(e,t){await g(this.client,Tp,{key:e,name:t},zp,Tr)}async setData(e,t){await g(this.client,vp,{key:e,data:JSON.stringify(t)},Sp,Tr)}async retrieve(e){const t=Array.isArray(e),n=await g(this.client,wp,{keys:T.toArray(e)},Op,Ap);return t?n.logs:n.logs[0]}async delete(e){await g(this.client,Ep,{keys:T.toArray(e)},Ip,Tr)}};const kp=r=>({type:"log",key:r}),Cp=Object.freeze(Object.defineProperty({__proto__:null,Client:Fi,keyZ:tt,logZ:ar,newZ:qi,ontologyID:kp},Symbol.toStringTag,{value:"Module"})),Ce=s.z.uuid(),ir=s.z.object({key:Ce,name:s.z.string(),data:ue.unknownZ.or(s.z.string().transform(he)),snapshot:s.z.boolean()}),Yi=ir.partial({key:!0,snapshot:!0}).transform(r=>({...r,data:JSON.stringify(r.data)})),vn=ir.extend({data:s.z.string().transform(he)}),xp="/workspace/schematic/retrieve",Rp="/workspace/schematic/create",jp="/workspace/schematic/rename",Up="/workspace/schematic/set-data",Dp="/workspace/schematic/delete",Mp="/workspace/schematic/copy",Zp=s.z.object({keys:Ce.array()}),Pp=s.z.object({workspace:se,schematics:Yi.array()}),Lp=s.z.object({key:Ce,name:s.z.string()}),Bp=s.z.object({key:Ce,data:s.z.string()}),qp=s.z.object({keys:Ce.array()}),Fp=s.z.object({key:Ce,name:s.z.string(),snapshot:s.z.boolean()}),Yp=s.z.object({schematics:L(vn)}),Vp=s.z.object({schematics:vn.array()}),Wp=s.z.object({schematic:ir}),vr=s.z.object({});let Vi=class{client;constructor(e){this.client=e}async create(e,t){const n=Array.isArray(t),a=await g(this.client,Rp,{workspace:e,schematics:T.toArray(t)},Pp,Vp);return n?a.schematics:a.schematics[0]}async rename(e,t){await g(this.client,jp,{key:e,name:t},Lp,vr)}async setData(e,t){await g(this.client,Up,{key:e,data:JSON.stringify(t)},Bp,vr)}async retrieve(e){const t=Array.isArray(e),n=await g(this.client,xp,{keys:T.toArray(e)},Zp,Yp);return t?n.schematics:n.schematics[0]}async delete(e){await g(this.client,Dp,{keys:T.toArray(e)},qp,vr)}async copy(e,t,n){return(await g(this.client,Mp,{key:e,name:t,snapshot:n},Fp,Wp)).schematic}};const _p=r=>({type:"schematic",key:r}),Hp=Object.freeze(Object.defineProperty({__proto__:null,Client:Vi,keyZ:Ce,newZ:Yi,ontologyID:_p,remoteZ:vn,schematicZ:ir},Symbol.toStringTag,{value:"Module"})),rt=s.z.uuid(),En=s.z.object({key:rt,name:s.z.string(),data:ue.unknownZ.or(s.z.string().transform(he))}),Wi=En.partial({key:!0}).transform(r=>({...r,data:JSON.stringify(r.data)})),On=En.extend({data:s.z.string().transform(he)}),Gp="/workspace/table/retrieve",Jp="/workspace/table/create",Kp="/workspace/table/rename",Xp="/workspace/table/set-data",Qp="/workspace/table/delete",em=s.z.object({keys:rt.array()}),tm=s.z.object({workspace:se,tables:Wi.array()}),rm=s.z.object({key:rt,name:s.z.string()}),nm=s.z.object({key:rt,data:s.z.string()}),sm=s.z.object({keys:rt.array()}),am=s.z.object({tables:On.array()}),im=s.z.object({tables:On.array()}),Er=s.z.object({});let _i=class{client;constructor(e){this.client=e}async create(e,t){const n=Array.isArray(t),a=await g(this.client,Jp,{workspace:e,tables:T.toArray(t)},tm,im);return n?a.tables:a.tables[0]}async rename(e,t){await g(this.client,Kp,{key:e,name:t},rm,Er)}async setData(e,t){await g(this.client,Xp,{key:e,data:JSON.stringify(t)},nm,Er)}async retrieve(e){const t=Array.isArray(e),n=await g(this.client,Gp,{keys:T.toArray(e)},em,am);return t?n.tables:n.tables[0]}async delete(e){await g(this.client,Qp,{keys:T.toArray(e)},sm,Er)}};const om=r=>({type:"table",key:r}),cm=Object.freeze(Object.defineProperty({__proto__:null,Client:_i,keyZ:rt,newZ:Wi,ontologyID:om,remoteZ:On,tableZ:En},Symbol.toStringTag,{value:"Module"})),hs="/workspace/retrieve",lm="/workspace/create",um="/workspace/rename",hm="/workspace/set-layout",dm="/workspace/delete",ds=s.z.object({keys:se.array().optional(),searchTerm:s.z.string().optional(),author:Ee.optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),fm=s.z.object({workspaces:Pi.array()}),ym=s.z.object({key:se,name:s.z.string()}),gm=s.z.object({key:se,layout:s.z.string()}),pm=s.z.object({keys:se.array()}),fs=s.z.object({workspaces:L(sr)}),mm=s.z.object({workspaces:Li.array()}),Or=s.z.object({}),wm="sy_workspace_set",bm="sy_workspace_delete";class Hi{type="workspace";schematic;linePlot;log;table;client;constructor(e){this.client=e,this.schematic=new Vi(e),this.linePlot=new Bi(e),this.log=new Fi(e),this.table=new _i(e)}async create(e){const t=Array.isArray(e),n=await g(this.client,lm,{workspaces:T.toArray(e)},fm,mm);return t?n.workspaces:n.workspaces[0]}async rename(e,t){await g(this.client,um,{key:e,name:t},ym,Or)}async setLayout(e,t){await g(this.client,hm,{key:e,layout:JSON.stringify(t)},gm,Or)}async retrieve(e){let t;const n=typeof e!="string";typeof e=="string"||Array.isArray(e)?t={keys:T.toArray(e)}:t=e;const a=await g(this.client,hs,t,ds,fs);return n?a.workspaces:a.workspaces[0]}async retrieveByAuthor(e){return(await g(this.client,hs,{author:e},ds,fs)).workspaces}async delete(e){await g(this.client,dm,{keys:T.toArray(e)},pm,Or)}}const Tm=r=>({type:"workspace",key:r}),vm=Object.freeze(Object.defineProperty({__proto__:null,Client:Hi,DELETE_CHANNEL_NAME:bm,SET_CHANNEL_NAME:wm,keyZ:se,newZ:Pi,ontologyID:Tm,remoteZ:Li,workspaceZ:sr},Symbol.toStringTag,{value:"Module"})),Gi=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:v.z.default(v.seconds(30)),secure:s.z.boolean().optional().default(!1),name:s.z.string().optional(),retry:ha.breakerConfigZ.optional()});class Ji extends hi{createdAt;props;ranges;channels;auth;user;access;connectivity;ontology;workspaces;labels;hardware;control;static connectivity=pt;transport;clientVersion="0.44.1";constructor(e){const t=Gi.parse(e),{host:n,port:a,username:i,password:o,connectivityPollFrequency:c,secure:l,retry:h}=t,d=new np(new ot({host:n,port:Number(a)}),h,l);d.use(Ah);let u;i!=null&&o!=null&&(u=new Tf(d.unary,{username:i,password:o}),d.use(u.middleware()));const N=new un(new Nt(d.unary)),E=new Ha(d.unary,N);super(d.stream,d.unary,N),this.createdAt=O.now(),this.props=t,this.auth=u,this.transport=d,this.channels=new Va(this,N,d.unary,E),this.connectivity=new pt(d.unary,c,this.clientVersion,t.name),this.control=new yi(this),this.ontology=new Ma(d.unary,this);const P=new Mi(this.transport.unary);this.labels=new xi(this.transport.unary),this.ranges=new Ui(this,P,this.transport.unary,N,this.labels,this.ontology),this.access=new La(this.transport.unary),this.user=new Ja(this.transport.unary),this.workspaces=new Hi(this.transport.unary);const k=new vi(this.transport.unary),B=new Ai(this.transport.unary,this,this.ontology,this.ranges),C=new Ei(this.transport.unary,B);this.hardware=new gi(B,C,k)}get key(){return this.createdAt.valueOf().toString()}close(){this.connectivity.stopChecking()}}const Ki={host:"localhost",port:9090,username:"synnax",password:"seldon"},Em=r=>new Ji({...Ki,...r});exports.AuthError=dt;exports.Channel=hn;exports.ContiguityError=zh;exports.DataType=I;exports.Density=W;exports.DisconnectedError=Nh;exports.Frame=Z;exports.MultiSeries=ca;exports.MultipleFoundError=yt;exports.NotFoundError=ft;exports.QueryError=ve;exports.Rate=Rr;exports.RouteError=Br;exports.Series=Y;exports.Synnax=Ji;exports.TEST_CLIENT_PROPS=Ki;exports.TimeRange=z;exports.TimeSpan=v;exports.TimeStamp=O;exports.UnexpectedError=Ye;exports.ValidationError=M;exports.access=wd;exports.channel=Yd;exports.connection=Ef;exports.control=ey;exports.device=my;exports.framer=Hf;exports.group=Fh;exports.hardware=ty;exports.isCalculated=gt;exports.label=bg;exports.linePlot=mp;exports.log=Cp;exports.newTestClient=Em;exports.ontology=rd;exports.policy=md;exports.rack=jy;exports.ranger=tp;exports.schematic=Hp;exports.synnaxPropsZ=Gi;exports.table=cm;exports.task=tg;exports.user=df;exports.workspace=vm;
|
|
43
|
+
`);return h});return new Z(c,o.series)}const n=[],a=[],i=Object.entries(e);for(let o=0;o<i.length;o++){const[c,l]=i[o],h=await this.fetchChannel(c),d=new F({data:l,dataType:h.dataType});n.push(h.key),a.push(d)}return new Z(n,a)}}class oi{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(X.matches(t))return;throw t}}}closeSend(){this.stream.closeSend()}send(e){const t=this.stream.send(e);if(t!=null)throw t}}const _t=new E(-1);var yn=(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))(yn||{}),ci=(r=>(r[r.None=0]="None",r[r.Ack=1]="Ack",r[r.Data=2]="Data",r))(ci||{});const qf=s.z.object({command:s.z.enum(yn),span:E.z.optional(),bounds:z.z.optional(),stamp:O.z.optional(),keys:U.array().optional(),chunkSize:s.z.number().optional()}),Ff=s.z.object({variant:s.z.enum(ci),ack:s.z.boolean(),command:s.z.enum(yn),error:ue.payloadZ.optional().nullable(),frame:er.optional()});class bt{static ENDPOINT="/frame/iterate";stream;adapter;value;constructor(e,t){this.stream=new oi("Iterator",e),this.value=new Z,this.adapter=t}static async _open(e,t,n,a,i={}){const o=await tr.open(n,t),c=await a.stream(bt.ENDPOINT,qf,Ff),l=new bt(c,o);return await l.execute({command:0,keys:o.keys,bounds:new z(e),chunkSize:i.chunkSize??1e5}),l}async next(e=_t){return await this.execute({command:1,span:new E(e)})}async prev(e=_t){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 O(e)})}async seekGE(e){return await this.execute({command:6,stamp:new O(e)})}async valid(){return await this.execute({command:7})}async close(){await this.stream.closeAndAck()}[Symbol.asyncIterator](){return new Yf(this)}async execute(e){for(this.stream.send(e),this.value=new Z;;){const t=await this.stream.receive();if(t.variant===1)return t.ack;this.value.push(this.adapter.adapt(new Z(t.frame)))}}}class Yf{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 Vf=s.z.object({keys:s.z.number().array(),downsampleFactor:s.z.number()}),Wf=s.z.object({frame:er}),_f="/frame/stream",us=s.z.object({channels:Ce,downsampleFactor:s.z.number().optional().default(1),useExperimentalCodec:s.z.boolean().optional().default(!1)}),gn=us.or(Ce.transform(r=>us.parse({channels:r}))),li=(r,e)=>async t=>{const n=gn.parse(t),a=await tr.open(r,n.channels);n.useExperimentalCodec&&(e=e.withCodec(new Bf(a.codec)));const i=await e.stream(_f,Vf,Wf),o=new Hf(i,a);i.send({keys:a.keys,downsampleFactor:n.downsampleFactor??1});const[,c]=await i.receive();if(c!=null)throw c;return o},ui=async(r,e,t)=>await li(r,e)(t);class Hf{stream;adapter;downsampleFactor;constructor(e,t){this.stream=new oi("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(X.matches(e))return{done:!0,value:void 0};throw e}}async read(){return this.adapter.adapt(new Z((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 rr{wrapped_=null;breaker;opener;config;constructor(e,t,n={}){this.opener=e,this.config=gn.parse(t);const{maxRetries:a=5e3,baseInterval:i=E.seconds(1),scale:o=1}=n??{};this.breaker=new ha.Breaker({maxRetries:a,baseInterval:i,scale:o})}static async open(e,t,n){const a=new rr(e,t,n);return await a.runStreamer(),a}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=Ce.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(X.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(X.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 hi extends Nu.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 Gf=r=>({type:"framer",key:r.toString()});let di=class{streamClient;retriever;deleter;constructor(e,t,n){this.streamClient=e,this.retriever=n,this.deleter=new Af(t)}async openIterator(e,t,n){return await bt._open(e,t,this.retriever,this.streamClient,n)}async openWriter(e){return await si._open(this.retriever,this.streamClient,e)}async openStreamer(e){return await ui(this.retriever,this.streamClient,e)}async write(e,t,n){if(n==null){const i=t,o=await this.openWriter({start:e,channels:Object.keys(i),mode:wt.Persist,errOnUnauthorized:!0,enableAutoCommit:!0,autoIndexPersistInterval:E.MAX});return await o.write(i),await o.close()}const a=await this.openWriter({start:e,channels:t,mode:wt.Persist,errOnUnauthorized:!0,enableAutoCommit:!0,autoIndexPersistInterval:E.MAX});await a.write(t,n),await a.close()}async read(e,t){const{single:n}=J(t),a=await this.readFrame(e,t);return n?a.get(t):a}async readFrame(e,t){const n=await this.openIterator(e,t),a=new Z;try{for await(const i of n)a.push(i)}finally{await n.close()}return a}async readLatest(e,t=1){const{single:n}=J(e),a=await this.readLatestNFrame(e,t);return n?a.get(e):a}async readLatestNFrame(e,t){const n=await this.openIterator(z.MAX,e,{chunkSize:t}),a=new Z;if(t>0)try{await n.seekLast(),await n.prev(_t),a.push(n.value)}finally{await n.close()}return a}async delete(e,t){const{normalized:n,variant:a}=J(e);return a==="keys"?await this.deleter.delete({keys:n,bounds:t}):await this.deleter.delete({names:n,bounds:t})}};const Kf=Object.freeze(Object.defineProperty({__proto__:null,ALWAYS_INDEX_PERSIST_ON_AUTO_COMMIT:$f,AUTO_SPAN:_t,Client:di,Frame:Z,HardenedStreamer:rr,Iterator:bt,ObservableStreamer:hi,Writer:si,WriterClosedError:Vr,WriterCommand:We,WriterMode:wt,createStreamOpener:li,frameZ:er,ontologyID:Gf,openStreamer:ui,seriesFromPayload:ei,seriesToPayload:ti,streamerConfigZ:gn,writerConfigZ:ni},Symbol.toStringTag,{value:"Module"})),Jf=K.ABSOLUTE_AUTHORITY,Xf=K.ZERO_AUTHORITY,Qf=K.stateZ(s.z.number()),ey=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()})`,ty=s.z.object({transfers:s.z.array(K.transferZ(U))});class fi extends hi{states;codec;constructor(e){super(e,t=>{const n=this.codec.decode(t.series[0].buffer,ty);return this.merge(n),[n.transfers,!0]}),this.states=new Map,this.codec=new ke.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 yi="sy_node_1_control";let gi=class{framer;constructor(e){this.framer=e}async openStateTracker(){const e=await rr.open(async t=>await this.framer.openStreamer(t),yi);return new fi(e)}};const ry=Object.freeze(Object.defineProperty({__proto__:null,ABSOLUTE_AUTHORITY:Jf,CONTROL_STATE_CHANNEL_NAME:yi,Client:gi,StateTracker:fi,ZERO_AUTHORITY:Xf,stateZ:Qf,transferString:ey},Symbol.toStringTag,{value:"Module"}));let pi=class{tasks;racks;devices;constructor(e,t,n){this.tasks=e,this.racks=t,this.devices=n}};const ny=Object.freeze(Object.defineProperty({__proto__:null,Client:pi},Symbol.toStringTag,{value:"Module"})),se=s.z.uint32(),mi=Nt.statusZ(s.z.object({rack:se})),nr=s.z.object({key:se,name:s.z.string(),status:ct.nullToUndefined(mi)}),wi=nr.partial({key:!0}),bi=r=>r?ke.JSON_CODEC.decodeString(r,he.unknownZ):{},Qe=s.z.string(),Ti=Nt.statusZ(s.z.object({rack:se,device:Qe})),sr=s.z.object({key:Qe,rack:se,name:s.z.string(),make:s.z.string(),model:s.z.string(),location:s.z.string(),configured:s.z.boolean().optional(),properties:he.unknownZ.or(s.z.string().transform(bi)),status:ct.nullToUndefined(Ti)}),vi=sr.extend({properties:s.z.unknown().transform(r=>ke.JSON_CODEC.encodeString(r))}),sy="sy_device_set",ay="sy_device_delete",iy="sy_device_status",oy="/hardware/device/retrieve",cy="/hardware/device/create",ly="/hardware/device/delete",uy=s.z.object({devices:vi.array()}),hy=s.z.object({devices:sr.array()}),dy=s.z.object({keys:Qe.array()}),fy=s.z.object({}),yy=s.z.object({keys:Qe.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:se.array().optional(),searchTerm:s.z.string().optional(),limit:s.z.number().optional(),offset:s.z.number().optional(),includeStatus:s.z.boolean().optional()}),gy=s.z.object({devices:V(sr)}),py=s.z.object({key:Qe,includeStatus:s.z.boolean().optional()}).transform(({key:r,includeStatus:e})=>({keys:[r],includeStatus:e})),my=s.z.union([py,yy]);let Ei=class{type="device";client;constructor(e){this.client=e}async retrieve(e){const t=typeof e=="object"&&"key"in e,n=await g(this.client,oy,e,my,gy);Xe("Device",e,n.devices,t);const a=n.devices;return t?a[0]:a}async create(e){const t=!Array.isArray(e),a=(await g(this.client,cy,{devices:T.toArray(e)},uy,hy)).devices;return t?a[0]:a}async delete(e){await g(this.client,ly,{keys:T.toArray(e)},dy,fy)}};const wy=r=>({type:"device",key:r}),by=Object.freeze(Object.defineProperty({__proto__:null,Client:Ei,DELETE_CHANNEL_NAME:ay,SET_CHANNEL_NAME:sy,STATUS_CHANNEL_NAME:iy,deviceZ:sr,keyZ:Qe,newZ:vi,ontologyID:wy,statusZ:Ti},Symbol.toStringTag,{value:"Module"})),Ty="/hardware/rack/retrieve",vy="/hardware/rack/create",Ey="/hardware/rack/delete",Oy="sy_rack_status",Ny="sy_rack_set",zy="sy_rack_delete",Sy=s.z.object({keys:se.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()}),Iy=s.z.object({racks:V(nr)}),Ay=s.z.union([s.z.object({key:se,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}))]),$y=Sy,ky=s.z.union([Ay,$y]),Cy=s.z.object({racks:wi.array()}),xy=s.z.object({racks:nr.array()}),Ry=s.z.object({keys:se.array()}),jy=s.z.object({});let Oi=class{type="rack";client;tasks;constructor(e,t){this.client=e,this.tasks=t}async delete(e){await g(this.client,Ey,{keys:T.toArray(e)},Ry,jy)}async create(e){const t=!Array.isArray(e),n=await g(this.client,vy,{racks:T.toArray(e)},Cy,xy),a=this.sugar(n.racks);return t?a[0]:a}async retrieve(e){const t="key"in e||"name"in e,n=await g(this.client,Ty,e,ky,Iy),a=this.sugar(n.racks);return Xe("Rack",e,a,t),t?a[0]:a}sugar(e){const t=!Array.isArray(e),n=T.toArray(e).map(({key:a,name:i,status:o})=>new Ni(a,i,this.tasks,o));return t?n[0]:n}};class Ni{key;name;status;tasks;constructor(e,t,n,a){this.key=e,this.name=t,this.tasks=n,this.status=a}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 Uy=r=>({type:"rack",key:r.toString()}),Dy=Object.freeze(Object.defineProperty({__proto__:null,Client:Oi,DELETE_CHANNEL_NAME:zy,Rack:Ni,SET_CHANNEL_NAME:Ny,STATUS_CHANNEL_NAME:Oy,keyZ:se,newZ:wi,ontologyID:Uy,rackZ:nr,statusZ:mi},Symbol.toStringTag,{value:"Module"})),de=r=>r?JSON.parse(r):{},fe=s.z.union([s.z.string(),s.z.bigint().transform(r=>r.toString()),s.z.number().transform(r=>r.toString())]),zi=r=>s.z.object({task:fe,running:s.z.boolean(),data:r}),pn=r=>Nt.statusZ(zi(r)),At=(r={typeSchema:s.z.string(),configSchema:s.z.unknown(),statusDataSchema:s.z.unknown()})=>s.z.object({key:fe,name:s.z.string(),type:r.typeSchema,internal:s.z.boolean().optional(),config:s.z.string().transform(bi).or(r.configSchema),status:pn(r.statusDataSchema).optional().nullable(),snapshot:s.z.boolean().optional()}),Si=r=>At(r).omit({key:!0}).extend({key:fe.transform(e=>e.toString()).optional(),config:s.z.unknown().transform(e=>ke.JSON_CODEC.encodeString(e))}),My=s.z.object({task:fe,type:s.z.string(),key:s.z.string(),args:he.unknownZ.or(s.z.string().transform(de)).or(s.z.array(s.z.unknown())).or(s.z.null()).optional()}),Zy=r=>Number(BigInt(r)>>32n),_r="sy_task_status",Hr="sy_task_cmd",Py="sy_task_set",Ly="sy_task_delete",Ie=new Error("Task not created"),Ii=async(r,e)=>{const t=await e.retrieveParents(mn(r));return t.length===0?null:t[0]};class Ai{key;name;internal;type;snapshot;config;status;schemas;frameClient_;ontologyClient_;rangeClient_;get frameClient(){if(this.frameClient_==null)throw Ie;return this.frameClient_}get ontologyClient(){if(this.ontologyClient_==null)throw Ie;return this.ontologyClient_}get rangeClient(){if(this.rangeClient_==null)throw Ie;return this.rangeClient_}constructor({key:e,type:t,name:n,config:a,internal:i=!1,snapshot:o=!1,status:c},l,h,d,u){this.key=e,this.name=n,this.type=t,this.config=a,this.schemas=l??{typeSchema:s.z.string(),configSchema:s.z.unknown(),statusDataSchema:s.z.unknown()},this.internal=i,this.snapshot=o,this.status=c,this.frameClient_=h,this.ontologyClient_=d,this.rangeClient_=u}get payload(){return{key:this.key,name:this.name,type:this.type,config:this.config,status:this.status,internal:this.internal}}get ontologyID(){return mn(this.key)}async executeCommand(e,t){return await wn(this.frameClient,this.key,e,t)}async executeCommandSync(e,t,n){return await ki(this.frameClient,this.key,e,t,this.name,this.schemas?.statusDataSchema,n)}async snapshottedTo(){if(this.ontologyClient==null||this.rangeClient==null)throw Ie;return this.snapshot?await Ii(this.key,this.ontologyClient):null}}const By=s.z.object({rack:se.optional(),keys:fe.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()}),qy=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}))]),Fy=By,Yy=s.z.union([qy,Fy]),Vy=r=>s.z.object({tasks:V(At(r))}),Wy="/hardware/task/retrieve",_y="/hardware/task/create",Hy="/hardware/task/delete",Gy="/hardware/task/copy",Ky=r=>s.z.object({tasks:Si(r).array()}),Jy=r=>s.z.object({tasks:At(r).array()}),Xy=s.z.object({keys:fe.array()}),Qy=s.z.object({}),eg=s.z.object({key:fe,name:s.z.string(),snapshot:s.z.boolean()}),tg=r=>s.z.object({task:At(r)});let $i=class{type="task";client;frameClient;ontologyClient;rangeClient;constructor(e,t,n,a){this.client=e,this.frameClient=t,this.ontologyClient=n,this.rangeClient=a}async create(e,t){const n=!Array.isArray(e),a=Ky(t),i=Jy(t),o=await g(this.client,_y,{tasks:T.toArray(e)},a,i),c=this.sugar(o.tasks,t);return n?c[0]:c}async delete(e){await g(this.client,Hy,{keys:T.toArray(e)},Xy,Qy)}async retrieve({schemas:e,...t}){const n="key"in t||"name"in t,i=(await g(this.client,Wy,t,Yy,Vy(e))).tasks,o=this.sugar(i,e);return Xe("Task",t,o,n),n?o[0]:o}async copy(e,t,n){const a=tg(),i=await g(this.client,Gy,{key:e,name:t,snapshot:n},eg,a);return this.sugar(i.task)}async retrieveSnapshottedTo(e){if(this.ontologyClient==null)throw Ie;return await Ii(e,this.ontologyClient)}sugar(e,t){const n=!Array.isArray(e),a=T.toArray(e).map(({key:i,name:o,type:c,config:l,status:h,internal:d,snapshot:u})=>new Ai({key:i,name:o,type:c,config:l,internal:d,snapshot:u,status:h},t,this.frameClient,this.ontologyClient,this.rangeClient));return n?a[0]:a}async executeCommand(e,t,n){return await wn(this.frameClient,e,t,n)}async executeCommandSync(e,t,n,a,i,o=s.z.unknown()){const c=async()=>(await this.retrieve({key:e})).name;return await ki(this.frameClient,e,t,n,i??c,o,a)}};const mn=r=>({type:"task",key:r}),wn=async(r,e,t,n)=>{if(r==null)throw Ie;const a=ru.create(),i=await r.openWriter(Hr);return await i.write(Hr,[{args:n,key:a,task:e,type:t}]),await i.close(),a},ki=async(r,e,t,n,a,i,o)=>{if(r==null)throw Ie;const c=await r.openStreamer(_r),l=await wn(r,e,t,o),h=new E(n);let d;const u=new Promise((N,v)=>{d=setTimeout(()=>{(async()=>v(await rg(t,a,h,e)))()},h.milliseconds)});try{for(;;){const N=await Promise.race([c.read(),u]),v=pn(i).parse(N.at(-1)[_r]);if(v.key===l)return v}}finally{clearTimeout(d),c.close()}},rg=async(r,e,t,n)=>{const a=ll.capitalize(r),i=t.toString();try{const o=typeof e=="string"?e:await e();return new Error(`${a} command to ${o} timed out after ${i}`)}catch(o){return console.error("Failed to retrieve task name for timeout error:",o),new Error(`${a} command to task with key ${n} timed out after ${i}`)}},ng=Object.freeze(Object.defineProperty({__proto__:null,COMMAND_CHANNEL_NAME:Hr,Client:$i,DELETE_CHANNEL_NAME:Ly,SET_CHANNEL_NAME:Py,STATUS_CHANNEL_NAME:_r,Task:Ai,commandZ:My,keyZ:fe,newZ:Si,ontologyID:mn,rackKey:Zy,statusDetailsZ:zi,statusZ:pn,taskZ:At},Symbol.toStringTag,{value:"Module"})),Ne=s.z.uuid(),$t=s.z.object({key:Ne,name:s.z.string().min(1),color:s.z.string()}),sg="labeled_by",ag="sy_label_set",ig="sy_label_delete",Ci=$t.extend({key:Ne.optional()}),og=s.object({labels:Ci.array()}),cg=s.object({labels:$t.array()}),lg=s.object({keys:Ne.array()}),xi=s.object({id:R,labels:Ne.array(),replace:s.boolean().optional()}),ug=xi.omit({replace:!0}),Tr=s.object({}),hg="/label/create",dg="/label/delete",fg="/label/set",yg="/label/remove",gg="/label/retrieve",pg=s.object({keys:Ne.array().optional(),for:R.optional(),searchTerm:s.string().optional(),offset:s.number().optional(),limit:s.number().optional()}),mg=s.object({key:Ne}).transform(({key:r})=>({keys:[r]})),wg=s.union([mg,pg]),bg=s.object({labels:V($t)});let Ri=class{type="label";client;constructor(e){this.client=e}async retrieve(e){const t="key"in e,n=await g(this.client,gg,e,wg,bg);return Xe("Label",e,n.labels,t),t?n.labels[0]:n.labels}async label(e,t,n={}){await g(this.client,fg,{id:e,labels:t,replace:n.replace},xi,Tr)}async remove(e,t){await g(this.client,yg,{id:e,labels:t},ug,Tr)}async create(e){const t=Array.isArray(e),n=await g(this.client,hg,{labels:T.toArray(e)},og,cg);return t?n.labels:n.labels[0]}async delete(e){await g(this.client,dg,{keys:T.toArray(e)},lg,Tr)}};const Tg=r=>({type:"label",key:r}),vg=Object.freeze(Object.defineProperty({__proto__:null,Client:Ri,DELETE_CHANNEL_NAME:ig,LABELED_BY_ONTOLOGY_RELATIONSHIP_TYPE:sg,SET_CHANNEL_NAME:ag,keyZ:Ne,labelZ:$t,newZ:Ci,ontologyID:Tg},Symbol.toStringTag,{value:"Module"})),W=s.z.uuid(),bn=s.z.string().min(1),kt=s.z.object({key:W,name:bn,timeRange:z.z,color:s.z.string().optional(),labels:$t.array().or(s.z.null().transform(()=>{})).optional(),get parent(){return kt.optional().nullable().transform(r=>r===void 0?null:r)}}),ji=kt.omit({parent:!0,labels:!0}).partial({key:!0}),Eg="sy_range_alias_set",Og="sy_range_alias_delete",Ng=s.z.object({range:W,aliases:s.z.string().array()}),zg=s.z.object({aliases:s.z.record(s.z.string(),U)}),Sg=s.z.object({range:W,aliases:s.z.record(U.or(s.z.string()),s.z.string())}),Ig=s.z.unknown(),Ag=s.z.object({range:W,channels:U.array()}),$g=s.z.unknown(),kg=s.z.object({range:W}),Cg=s.z.object({aliases:s.z.record(s.z.string(),s.z.string())}),xg=s.z.object({range:W,channels:U.array()}),Rg=s.z.object({aliases:s.z.record(s.z.string(),s.z.string())});class G{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",a={};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?a[o]=c:t.push(o)});if(t.length===0)return a;const i=await g(this.client,G.RESOLVE_ENDPOINT,{range:this.rangeKey,aliases:t},Ng,zg);return Object.entries(i.aliases).forEach(([o,c])=>this.cache.set(o,c)),n?i.aliases[t[0]]:{...a,...i.aliases}}async set(e){await g(this.client,G.SET_ENDPOINT,{range:this.rangeKey,aliases:e},Sg,Ig)}async list(){return(await g(this.client,G.LIST_ENDPOINT,{range:this.rangeKey},kg,Cg)).aliases}async retrieve(e){const t=typeof e=="number",n=await g(this.client,G.RETRIEVE_ENDPOINT,{range:this.rangeKey,channels:T.toArray(e)},xg,Rg);return t?n.aliases[e]:n.aliases}async delete(e){await g(this.client,G.DELETE_ENDPOINT,{range:this.rangeKey,channels:e},Ag,$g)}}const jg=s.z.object({alias:s.z.string().optional(),channel:U,range:W}),Ui="---",Ug=r=>`${r.range}${Ui}${r.channel}`,Dg=r=>{const[e,t]=r.split(Ui);return{range:e,channel:Number(t)}},Mg="sy_range_kv_set",Zg="sy_range_kv_delete",Tn=s.z.object({range:W,key:s.z.string(),value:s.z.string()}),Pg=({range:r,key:e})=>`${r}<--->${e}`,Lg=s.z.object({range:W,keys:s.z.string().array()}),Bg=s.z.object({pairs:V(Tn)}),qg=s.z.object({range:W,pairs:Tn.array()}),Fg=s.z.object({range:W,keys:s.z.string().array()});class $e{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 g(this.client,$e.GET_ENDPOINT,{range:this.rangeKey,keys:T.toArray(e)},Lg,Bg);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;Ps(e)?n=Object.entries(e).map(([a,i])=>({range:this.rangeKey,key:a,value:i})):n=[{range:this.rangeKey,key:e,value:t}],await g(this.client,$e.SET_ENDPOINT,{range:this.rangeKey,pairs:n},qg,s.z.unknown())}async delete(e){await g(this.client,$e.DELETE_ENDPOINT,{range:this.rangeKey,keys:T.toArray(e)},Fg,s.z.unknown())}}const Yg="sy_range_set",Vg="sy_range_delete";class Di{key;name;kv;timeRange;color;parent;labels;channels;aliaser;frameClient;labelClient;ontologyClient;rangeClient;constructor({name:e,timeRange:t=z.ZERO,key:n,color:a,parent:i,labels:o},{frameClient:c,kv:l,aliaser:h,channels:d,labelClient:u,ontologyClient:N,rangeClient:v}){this.key=n,this.name=e,this.timeRange=t,this.parent=i,this.labels=o,this.frameClient=c,this.color=a,this.kv=l,this.aliaser=h,this.channels=d,this.labelClient=u,this.ontologyClient=N,this.rangeClient=v}get ontologyID(){return Be(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 Ee(`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:Be(this.key)})}async addLabel(...e){await this.labelClient.label(Be(this.key),e)}async removeLabel(...e){await this.labelClient.remove(Be(this.key),e)}static sort(e,t){return z.sort(e.timeRange,t.timeRange)}}const Wg=s.z.object({keys:W.array().optional(),names:s.z.array(s.z.string()).optional(),searchTerm:s.z.string().optional(),overlapsWith:z.z.optional(),limit:s.z.number().int().optional(),offset:s.z.number().int().optional(),hasLabels:Ne.array().optional(),includeLabels:s.z.boolean().optional(),includeParent:s.z.boolean().optional()}),_g=Wg.or(W.array().transform(r=>({keys:r}))).or(W.transform(r=>({keys:[r]}))).or(s.z.string().transform(r=>({names:[r]}))).or(s.z.string().array().transform(r=>({names:r}))).or(z.z.transform(r=>({overlapsWith:r}))),Hg="/range/retrieve",Gg=s.z.object({ranges:V(kt)});let Mi=class{type="range";frameClient;writer;unaryClient;channels;labelClient;ontologyClient;constructor(e,t,n,a,i,o){this.frameClient=e,this.writer=t,this.unaryClient=n,this.channels=a,this.labelClient=i,this.ontologyClient=o}async create(e,t){const n=!Array.isArray(e),a=this.sugarMany(await this.writer.create(T.toArray(e),t));return n?a[0]:a}async rename(e,t){await this.writer.rename(e,t)}async delete(e){await this.writer.delete(T.toArray(e))}async retrieve(e){const t=typeof e=="string",{ranges:n}=await g(this.unaryClient,Hg,e,_g,Gg);return Xe("Range",e,n,t),t?this.sugarMany(n)[0]:this.sugarMany(n)}getKV(e){return new $e(e,this.unaryClient)}async retrieveParent(e){const t=await this.ontologyClient.retrieveParents(Be(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(Zi(e))}async retrieveAlias(e,t){return await new G(e,this.frameClient,this.unaryClient).retrieve(t)}async retrieveAliases(e,t){return await new G(e,this.frameClient,this.unaryClient).retrieve(t)}async listAliases(e){return await new G(e,this.frameClient,this.unaryClient).list()}async setAlias(e,t,n){await new G(e,this.frameClient,this.unaryClient).set({[t]:n})}sugarOne(e){return new Di(e,{frameClient:this.frameClient,kv:new $e(e.key,this.unaryClient),aliaser:new G(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 z(e.data?.timeRange),color:e.data?.color,labels:[],parent:null})}};const Be=r=>({type:"range",key:r}),Kg=r=>({type:"range-alias",key:r}),Zi=({data:r,id:{key:e},name:t})=>{const n=z.z.parse(r?.timeRange);return{key:e,name:t,timeRange:n,color:typeof r?.color=="string"?r.color:void 0,labels:[],parent:null}},Jg=s.z.object({ranges:kt.array()}),Xg=s.z.object({parent:R.optional(),ranges:ji.array()}),Qg=s.z.object({keys:W.array()}),ep=s.z.object({}),tp=s.z.object({key:W,name:bn}),rp=s.z.object({}),np="/range/create",sp="/range/delete",ap="/range/rename";class Pi{client;constructor(e){this.client=e}async rename(e,t){await g(this.client,ap,{key:e,name:t},tp,rp)}async create(e,t){return(await g(this.client,np,{ranges:e,...t},Xg,Jg)).ranges}async delete(e){await g(this.client,sp,{keys:e},Qg,ep)}}const ip=Object.freeze(Object.defineProperty({__proto__:null,Aliaser:G,Client:Mi,DELETE_ALIAS_CHANNEL_NAME:Og,DELETE_CHANNEL_NAME:Vg,KV:$e,KV_DELETE_CHANNEL:Zg,KV_SET_CHANNEL:Mg,Range:Di,SET_ALIAS_CHANNEL_NAME:Eg,SET_CHANNEL_NAME:Yg,Writer:Pi,aliasKey:Ug,aliasOntologyID:Kg,aliasZ:jg,convertOntologyResourceToPayload:Zi,decodeDeleteAliasChange:Dg,keyZ:W,kvPairKey:Pg,kvPairZ:Tn,nameZ:bn,newZ:ji,ontologyID:Be,payloadZ:kt},Symbol.toStringTag,{value:"Module"})),op="/api/v1/";class cp{url;unary;stream;secure;constructor(e,t={},n=!1){this.secure=n,this.url=e.child(op);const a=new ke.JSONCodec;this.unary=Gc(new Hc(this.url,a,this.secure),t),this.stream=new el(this.url,a,this.secure)}use(...e){this.unary.use(...e),this.stream.use(...e)}}const et=s.z.uuid(),ar=s.z.object({key:et,name:s.z.string(),data:he.unknownZ.or(s.z.string().transform(de))}),Li=ar.partial({key:!0}).transform(r=>({...r,data:JSON.stringify(r.data)})),ae=s.z.uuid(),ir=s.z.object({key:ae,name:s.z.string(),layout:he.unknownZ.or(s.z.string().transform(de))}),Bi=ir.partial({key:!0}).transform(r=>({...r,layout:JSON.stringify(r.layout)})),qi=ir.omit({layout:!0}).extend({layout:s.z.string().transform(de)}),lp="/workspace/lineplot/retrieve",up="/workspace/lineplot/create",hp="/workspace/lineplot/rename",dp="/workspace/lineplot/set-data",fp="/workspace/lineplot/delete",yp=s.z.object({keys:et.array()}),gp=s.z.object({workspace:ae,linePlots:Li.array()}),pp=s.z.object({key:et,name:s.z.string()}),mp=s.z.object({key:et,data:s.z.string()}),wp=s.z.object({keys:et.array()}),bp=s.z.object({linePlots:V(ar)}),Tp=s.z.object({linePlots:ar.array()}),vr=s.z.object({});let Fi=class{client;constructor(e){this.client=e}async create(e,t){const n=Array.isArray(t),a=await g(this.client,up,{workspace:e,linePlots:T.toArray(t)},gp,Tp);return n?a.linePlots:a.linePlots[0]}async rename(e,t){await g(this.client,hp,{key:e,name:t},pp,vr)}async setData(e,t){await g(this.client,dp,{key:e,data:JSON.stringify(t)},mp,vr)}async retrieve(e){const t=Array.isArray(e),n=await g(this.client,lp,{keys:T.toArray(e)},yp,bp);return t?n.linePlots:n.linePlots[0]}async delete(e){await g(this.client,fp,{keys:T.toArray(e)},wp,vr)}};const vp=r=>({type:"lineplot",key:r}),Ep=Object.freeze(Object.defineProperty({__proto__:null,Client:Fi,keyZ:et,linePlotZ:ar,newZ:Li,ontologyID:vp},Symbol.toStringTag,{value:"Module"})),tt=s.z.uuid(),or=s.z.object({key:tt,name:s.z.string(),data:he.unknownZ.or(s.z.string().transform(de))}),Yi=or.partial({key:!0}).transform(r=>({...r,data:JSON.stringify(r.data)})),Op="/workspace/log/retrieve",Np="/workspace/log/create",zp="/workspace/log/rename",Sp="/workspace/log/set-data",Ip="/workspace/log/delete",Ap=s.z.object({keys:tt.array()}),$p=s.z.object({workspace:ae,logs:Yi.array()}),kp=s.z.object({key:tt,name:s.z.string()}),Cp=s.z.object({key:tt,data:s.z.string()}),xp=s.z.object({keys:tt.array()}),Rp=s.z.object({logs:or.array()}),jp=s.z.object({logs:or.array()}),Er=s.z.object({});let Vi=class{client;constructor(e){this.client=e}async create(e,t){const n=Array.isArray(t),a=await g(this.client,Np,{workspace:e,logs:T.toArray(t)},$p,jp);return n?a.logs:a.logs[0]}async rename(e,t){await g(this.client,zp,{key:e,name:t},kp,Er)}async setData(e,t){await g(this.client,Sp,{key:e,data:JSON.stringify(t)},Cp,Er)}async retrieve(e){const t=Array.isArray(e),n=await g(this.client,Op,{keys:T.toArray(e)},Ap,Rp);return t?n.logs:n.logs[0]}async delete(e){await g(this.client,Ip,{keys:T.toArray(e)},xp,Er)}};const Up=r=>({type:"log",key:r}),Dp=Object.freeze(Object.defineProperty({__proto__:null,Client:Vi,keyZ:tt,logZ:or,newZ:Yi,ontologyID:Up},Symbol.toStringTag,{value:"Module"})),xe=s.z.uuid(),cr=s.z.object({key:xe,name:s.z.string(),data:he.unknownZ.or(s.z.string().transform(de)),snapshot:s.z.boolean()}),Wi=cr.partial({key:!0,snapshot:!0}).transform(r=>({...r,data:JSON.stringify(r.data)})),vn=cr.extend({data:s.z.string().transform(de)}),Mp="/workspace/schematic/retrieve",Zp="/workspace/schematic/create",Pp="/workspace/schematic/rename",Lp="/workspace/schematic/set-data",Bp="/workspace/schematic/delete",qp="/workspace/schematic/copy",Fp=s.z.object({keys:xe.array()}),Yp=s.z.object({workspace:ae,schematics:Wi.array()}),Vp=s.z.object({key:xe,name:s.z.string()}),Wp=s.z.object({key:xe,data:s.z.string()}),_p=s.z.object({keys:xe.array()}),Hp=s.z.object({key:xe,name:s.z.string(),snapshot:s.z.boolean()}),Gp=s.z.object({schematics:V(vn)}),Kp=s.z.object({schematics:vn.array()}),Jp=s.z.object({schematic:cr}),Or=s.z.object({});let _i=class{client;constructor(e){this.client=e}async create(e,t){const n=Array.isArray(t),a=await g(this.client,Zp,{workspace:e,schematics:T.toArray(t)},Yp,Kp);return n?a.schematics:a.schematics[0]}async rename(e,t){await g(this.client,Pp,{key:e,name:t},Vp,Or)}async setData(e,t){await g(this.client,Lp,{key:e,data:JSON.stringify(t)},Wp,Or)}async retrieve(e){const t=Array.isArray(e),n=await g(this.client,Mp,{keys:T.toArray(e)},Fp,Gp);return t?n.schematics:n.schematics[0]}async delete(e){await g(this.client,Bp,{keys:T.toArray(e)},_p,Or)}async copy(e,t,n){return(await g(this.client,qp,{key:e,name:t,snapshot:n},Hp,Jp)).schematic}};const Xp=r=>({type:"schematic",key:r}),Qp=Object.freeze(Object.defineProperty({__proto__:null,Client:_i,keyZ:xe,newZ:Wi,ontologyID:Xp,remoteZ:vn,schematicZ:cr},Symbol.toStringTag,{value:"Module"})),rt=s.z.uuid(),En=s.z.object({key:rt,name:s.z.string(),data:he.unknownZ.or(s.z.string().transform(de))}),Hi=En.partial({key:!0}).transform(r=>({...r,data:JSON.stringify(r.data)})),On=En.extend({data:s.z.string().transform(de)}),em="/workspace/table/retrieve",tm="/workspace/table/create",rm="/workspace/table/rename",nm="/workspace/table/set-data",sm="/workspace/table/delete",am=s.z.object({keys:rt.array()}),im=s.z.object({workspace:ae,tables:Hi.array()}),om=s.z.object({key:rt,name:s.z.string()}),cm=s.z.object({key:rt,data:s.z.string()}),lm=s.z.object({keys:rt.array()}),um=s.z.object({tables:On.array()}),hm=s.z.object({tables:On.array()}),Nr=s.z.object({});let Gi=class{client;constructor(e){this.client=e}async create(e,t){const n=Array.isArray(t),a=await g(this.client,tm,{workspace:e,tables:T.toArray(t)},im,hm);return n?a.tables:a.tables[0]}async rename(e,t){await g(this.client,rm,{key:e,name:t},om,Nr)}async setData(e,t){await g(this.client,nm,{key:e,data:JSON.stringify(t)},cm,Nr)}async retrieve(e){const t=Array.isArray(e),n=await g(this.client,em,{keys:T.toArray(e)},am,um);return t?n.tables:n.tables[0]}async delete(e){await g(this.client,sm,{keys:T.toArray(e)},lm,Nr)}};const dm=r=>({type:"table",key:r}),fm=Object.freeze(Object.defineProperty({__proto__:null,Client:Gi,keyZ:rt,newZ:Hi,ontologyID:dm,remoteZ:On,tableZ:En},Symbol.toStringTag,{value:"Module"})),hs="/workspace/retrieve",ym="/workspace/create",gm="/workspace/rename",pm="/workspace/set-layout",mm="/workspace/delete",ds=s.z.object({keys:ae.array().optional(),searchTerm:s.z.string().optional(),author:Oe.optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),wm=s.z.object({workspaces:Bi.array()}),bm=s.z.object({key:ae,name:s.z.string()}),Tm=s.z.object({key:ae,layout:s.z.string()}),vm=s.z.object({keys:ae.array()}),fs=s.z.object({workspaces:V(ir)}),Em=s.z.object({workspaces:qi.array()}),zr=s.z.object({}),Om="sy_workspace_set",Nm="sy_workspace_delete";class Ki{type="workspace";schematic;linePlot;log;table;client;constructor(e){this.client=e,this.schematic=new _i(e),this.linePlot=new Fi(e),this.log=new Vi(e),this.table=new Gi(e)}async create(e){const t=Array.isArray(e),n=await g(this.client,ym,{workspaces:T.toArray(e)},wm,Em);return t?n.workspaces:n.workspaces[0]}async rename(e,t){await g(this.client,gm,{key:e,name:t},bm,zr)}async setLayout(e,t){await g(this.client,pm,{key:e,layout:JSON.stringify(t)},Tm,zr)}async retrieve(e){let t;const n=typeof e!="string";typeof e=="string"||Array.isArray(e)?t={keys:T.toArray(e)}:t=e;const a=await g(this.client,hs,t,ds,fs);return n?a.workspaces:a.workspaces[0]}async retrieveByAuthor(e){return(await g(this.client,hs,{author:e},ds,fs)).workspaces}async delete(e){await g(this.client,mm,{keys:T.toArray(e)},vm,zr)}}const zm=r=>({type:"workspace",key:r}),Sm=Object.freeze(Object.defineProperty({__proto__:null,Client:Ki,DELETE_CHANNEL_NAME:Nm,SET_CHANNEL_NAME:Om,keyZ:ae,newZ:Bi,ontologyID:zm,remoteZ:qi,workspaceZ:ir},Symbol.toStringTag,{value:"Module"})),Ji=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:ha.breakerConfigZ.optional()});class Xi extends di{createdAt;props;ranges;channels;auth;user;access;connectivity;ontology;workspaces;labels;hardware;control;static connectivity=mt;transport;clientVersion="0.44.2";constructor(e){const t=Ji.parse(e),{host:n,port:a,username:i,password:o,connectivityPollFrequency:c,secure:l,retry:h}=t,d=new cp(new ot({host:n,port:Number(a)}),h,l);d.use(kh);let u;i!=null&&o!=null&&(u=new Ef(d.unary,{username:i,password:o}),d.use(u.middleware()));const N=new hn(new St(d.unary)),v=new Ga(d.unary,N);super(d.stream,d.unary,N),this.createdAt=O.now(),this.props=t,this.auth=u,this.transport=d,this.channels=new Wa(this,N,d.unary,v),this.connectivity=new mt(d.unary,c,this.clientVersion,t.name),this.control=new gi(this),this.ontology=new Ma(d.unary,this);const P=new Pi(this.transport.unary);this.labels=new Ri(this.transport.unary),this.ranges=new Mi(this,P,this.transport.unary,N,this.labels,this.ontology),this.access=new La(this.transport.unary),this.user=new Ja(this.transport.unary),this.workspaces=new Ki(this.transport.unary);const k=new Ei(this.transport.unary),L=new $i(this.transport.unary,this,this.ontology,this.ranges),C=new Oi(this.transport.unary,L);this.hardware=new pi(L,C,k)}get key(){return this.createdAt.valueOf().toString()}close(){this.connectivity.stopChecking()}}const Qi={host:"localhost",port:9090,username:"synnax",password:"seldon"},Im=r=>new Xi({...Qi,...r});exports.AuthError=dt;exports.Channel=Wt;exports.ContiguityError=Ih;exports.DataType=I;exports.Density=_;exports.DisconnectedError=Sh;exports.Frame=Z;exports.MultiSeries=ca;exports.MultipleFoundError=yt;exports.NotFoundError=ft;exports.QueryError=Ee;exports.Rate=Ur;exports.RouteError=Fr;exports.Series=F;exports.Synnax=Xi;exports.TEST_CLIENT_PROPS=Qi;exports.TimeRange=z;exports.TimeSpan=E;exports.TimeStamp=O;exports.UnexpectedError=Ye;exports.ValidationError=M;exports.access=vd;exports.channel=Wd;exports.connection=Nf;exports.control=ry;exports.createTestClient=Im;exports.device=by;exports.framer=Kf;exports.group=Wh;exports.hardware=ny;exports.isCalculated=pt;exports.label=vg;exports.linePlot=Ep;exports.log=Dp;exports.ontology=ad;exports.policy=Td;exports.rack=Dy;exports.ranger=ip;exports.schematic=Qp;exports.synnaxPropsZ=Ji;exports.table=fm;exports.task=ng;exports.user=yf;exports.workspace=Sm;
|