@synnaxlabs/client 0.45.1 → 0.46.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +7 -7
- package/dist/access/policy/client.d.ts +38 -26
- package/dist/access/policy/client.d.ts.map +1 -1
- package/dist/access/policy/payload.d.ts +22 -10
- package/dist/access/policy/payload.d.ts.map +1 -1
- package/dist/arc/client.d.ts +72 -0
- package/dist/arc/client.d.ts.map +1 -0
- package/dist/arc/external.d.ts +3 -0
- package/dist/arc/external.d.ts.map +1 -0
- package/dist/arc/index.d.ts +2 -0
- package/dist/arc/index.d.ts.map +1 -0
- package/dist/arc/payload.d.ts +155 -0
- package/dist/arc/payload.d.ts.map +1 -0
- package/dist/channel/client.d.ts +2 -3
- package/dist/channel/client.d.ts.map +1 -1
- package/dist/channel/payload.d.ts +23 -63
- package/dist/channel/payload.d.ts.map +1 -1
- package/dist/channel/retriever.d.ts.map +1 -1
- package/dist/client.cjs +44 -25
- package/dist/client.d.ts +5 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +7449 -4753
- package/dist/framer/client.d.ts +2 -2
- package/dist/framer/client.d.ts.map +1 -1
- package/dist/framer/deleter.d.ts +2 -2
- package/dist/framer/frame.d.ts +2 -2
- package/dist/framer/streamer.d.ts +42 -56
- package/dist/framer/streamer.d.ts.map +1 -1
- package/dist/framer/writer.d.ts +45 -43
- package/dist/framer/writer.d.ts.map +1 -1
- package/dist/hardware/device/client.d.ts +5 -6
- package/dist/hardware/device/client.d.ts.map +1 -1
- package/dist/hardware/device/payload.d.ts +83 -18
- package/dist/hardware/device/payload.d.ts.map +1 -1
- package/dist/hardware/rack/client.d.ts +4 -5
- package/dist/hardware/rack/client.d.ts.map +1 -1
- package/dist/hardware/rack/payload.d.ts +81 -17
- package/dist/hardware/rack/payload.d.ts.map +1 -1
- package/dist/hardware/task/client.d.ts +61 -12
- package/dist/hardware/task/client.d.ts.map +1 -1
- package/dist/hardware/task/payload.d.ts +18 -51
- package/dist/hardware/task/payload.d.ts.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/label/client.d.ts +14 -9
- package/dist/label/client.d.ts.map +1 -1
- package/dist/label/payload.d.ts +10 -11
- package/dist/label/payload.d.ts.map +1 -1
- package/dist/ontology/client.d.ts +7 -3
- package/dist/ontology/client.d.ts.map +1 -1
- package/dist/ontology/group/client.d.ts +45 -9
- package/dist/ontology/group/client.d.ts.map +1 -1
- package/dist/ontology/group/external.d.ts +0 -1
- package/dist/ontology/group/external.d.ts.map +1 -1
- package/dist/ontology/group/payload.d.ts +3 -1
- package/dist/ontology/group/payload.d.ts.map +1 -1
- package/dist/ontology/payload.d.ts +30 -17
- package/dist/ontology/payload.d.ts.map +1 -1
- package/dist/ontology/writer.d.ts +161 -0
- package/dist/ontology/writer.d.ts.map +1 -1
- package/dist/ranger/alias.d.ts +1 -1
- package/dist/ranger/alias.d.ts.map +1 -1
- package/dist/ranger/client.d.ts +9 -8
- package/dist/ranger/client.d.ts.map +1 -1
- package/dist/ranger/kv.d.ts.map +1 -1
- package/dist/ranger/payload.d.ts +5 -5
- package/dist/ranger/payload.d.ts.map +1 -1
- package/dist/ranger/writer.d.ts +6 -4
- package/dist/ranger/writer.d.ts.map +1 -1
- package/dist/status/client.d.ts +63 -0
- package/dist/status/client.d.ts.map +1 -0
- package/dist/status/external.d.ts +3 -0
- package/dist/status/external.d.ts.map +1 -0
- package/dist/status/index.d.ts +2 -0
- package/dist/status/index.d.ts.map +1 -0
- package/dist/status/payload.d.ts +32 -0
- package/dist/status/payload.d.ts.map +1 -0
- package/dist/status/status.spec.d.ts +2 -0
- package/dist/status/status.spec.d.ts.map +1 -0
- package/dist/user/client.d.ts.map +1 -1
- package/dist/user/retriever.d.ts.map +1 -1
- package/dist/workspace/client.d.ts +11 -6
- package/dist/workspace/client.d.ts.map +1 -1
- package/dist/workspace/lineplot/client.d.ts +28 -5
- package/dist/workspace/lineplot/client.d.ts.map +1 -1
- package/dist/workspace/lineplot/index.d.ts +1 -1
- package/dist/workspace/log/client.d.ts +28 -5
- package/dist/workspace/log/client.d.ts.map +1 -1
- package/dist/workspace/schematic/client.d.ts +35 -6
- package/dist/workspace/schematic/client.d.ts.map +1 -1
- package/dist/workspace/schematic/symbol/client.d.ts +6 -7
- package/dist/workspace/schematic/symbol/client.d.ts.map +1 -1
- package/dist/workspace/table/client.d.ts +28 -5
- package/dist/workspace/table/client.d.ts.map +1 -1
- package/examples/node/package-lock.json +30 -95
- package/examples/node/package.json +1 -1
- package/package.json +9 -9
- package/src/access/policy/client.ts +5 -6
- package/src/access/policy/payload.ts +4 -4
- package/src/access/policy/policy.spec.ts +4 -4
- package/src/arc/client.ts +117 -0
- package/src/{util/zod.ts → arc/external.ts} +2 -7
- package/src/arc/index.ts +10 -0
- package/src/arc/payload.ts +69 -0
- package/src/channel/client.ts +3 -4
- package/src/channel/payload.ts +4 -6
- package/src/channel/retriever.ts +2 -2
- package/src/client.ts +8 -2
- package/src/errors.spec.ts +1 -1
- package/src/framer/client.ts +4 -3
- package/src/framer/codec.spec.ts +1 -1
- package/src/hardware/device/client.ts +6 -8
- package/src/hardware/device/payload.ts +7 -6
- package/src/hardware/rack/client.ts +6 -8
- package/src/hardware/rack/payload.ts +2 -1
- package/src/hardware/task/client.ts +140 -100
- package/src/hardware/task/payload.ts +4 -4
- package/src/hardware/task/task.spec.ts +9 -2
- package/src/index.ts +3 -1
- package/src/label/client.ts +5 -8
- package/src/label/payload.ts +6 -11
- package/src/ontology/client.ts +3 -3
- package/src/ontology/group/client.ts +51 -18
- package/src/ontology/group/external.ts +0 -1
- package/src/ontology/group/group.spec.ts +6 -5
- package/src/ontology/group/payload.ts +5 -1
- package/src/ontology/ontology.spec.ts +88 -21
- package/src/ontology/payload.ts +15 -6
- package/src/ontology/writer.ts +3 -5
- package/src/ranger/alias.ts +2 -2
- package/src/ranger/client.ts +7 -3
- package/src/ranger/kv.ts +1 -2
- package/src/ranger/payload.ts +13 -1
- package/src/ranger/ranger.spec.ts +65 -1
- package/src/status/client.ts +129 -0
- package/src/status/external.ts +11 -0
- package/src/status/index.ts +10 -0
- package/src/status/payload.ts +35 -0
- package/src/status/status.spec.ts +352 -0
- package/src/user/client.ts +1 -2
- package/src/user/payload.ts +1 -1
- package/src/user/retriever.ts +2 -2
- package/src/user/user.spec.ts +41 -41
- package/src/workspace/client.ts +18 -15
- package/src/workspace/lineplot/client.ts +27 -13
- package/src/workspace/lineplot/index.ts +1 -1
- package/src/workspace/lineplot/lineplot.spec.ts +13 -10
- package/src/workspace/log/client.ts +26 -12
- package/src/workspace/log/log.spec.ts +13 -10
- package/src/workspace/payload.ts +1 -1
- package/src/workspace/schematic/client.ts +42 -17
- package/src/workspace/schematic/schematic.spec.ts +29 -25
- package/src/workspace/schematic/symbol/client.spec.ts +27 -24
- package/src/workspace/schematic/symbol/client.ts +6 -9
- package/src/workspace/table/client.ts +26 -12
- package/src/workspace/table/table.spec.ts +13 -10
- package/dist/ontology/group/group.d.ts +0 -10
- package/dist/ontology/group/group.d.ts.map +0 -1
- package/dist/ontology/group/writer.d.ts +0 -14
- package/dist/ontology/group/writer.d.ts.map +0 -1
- package/dist/util/zod.d.ts +0 -3
- package/dist/util/zod.d.ts.map +0 -1
- package/src/ontology/group/group.ts +0 -27
- package/src/ontology/group/writer.ts +0 -71
package/dist/client.cjs
CHANGED
|
@@ -1,44 +1,63 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("zod"),oc=r=>{const e=r.replace(/_[a-z]/g,t=>t[1].toUpperCase());return e.length>1&&e[0]===e[0].toUpperCase()&&e[1]===e[1].toUpperCase()||e.length===0?e:e[0].toLowerCase()+e.slice(1)},Ys=r=>{const e=(t,n=Kr)=>{if(typeof t=="string")return r(t);if(Array.isArray(t))return t.map(o=>e(o,n));if(!Rr(t))return t;n=hc(n);const i={},a=t;return"toJSON"in a&&typeof a.toJSON=="function"?e(a.toJSON(),n):(Object.keys(a).forEach(o=>{let c=a[o];const u=r(o);n.recursive&&(Rr(c)?ss(c)||(c=e(c,n)):n.recursiveInArray&&ns(c)&&(c=[...c].map(l=>{let h=l;return Rr(l)?ss(h)||(h=e(l,n)):ns(l)&&(h=e({key:l},n).key),h}))),i[u]=c}),i)};return e},Vs=Ys(oc),cc=r=>r.replace(/([a-z0-9])([A-Z])/g,(e,t,n)=>`${t}_${n.toLowerCase()}`),lc=Ys(cc),uc=[Number,String,Uint8Array],Kr={recursive:!0,recursiveInArray:!0},hc=(r=Kr)=>(r.recursive==null?r=Kr:r.recursiveInArray??=!1,r),ns=r=>r!=null&&Array.isArray(r),Rr=r=>r!=null&&typeof r=="object"&&!Array.isArray(r),ss=r=>uc.some(e=>r instanceof e);let fc=class{contentType="application/json";decoder;encoder;constructor(){this.decoder=new TextDecoder,this.encoder=new TextEncoder}encode(r){return this.encoder.encode(this.encodeString(r))}decode(r,e){return this.decodeString(this.decoder.decode(r),e)}decodeString(r,e){const t=JSON.parse(r),n=Vs(t);return e!=null?e.parse(n):n}encodeString(r){const e=lc(r);return JSON.stringify(e,(t,n)=>ArrayBuffer.isView(n)?Array.from(n):typeof n=="bigint"?n.toString():n)}};const Jr=new fc,X=r=>r!=null&&typeof r=="object"&&"value"in r;let rt=class{value;constructor(e){this.value=e}valueOf(){return this.value}toJSON(){return this.value}toString(){return this.value.toString()}};const dc=r=>r!=null&&typeof r=="object"&&"toString"in r,yc=(r,e=!1)=>{const t=dc(r)?"stringer":typeof r;let n;switch(t){case"string":n=(i,a)=>i.localeCompare(a);break;case"stringer":n=(i,a)=>i.toString().localeCompare(a.toString());break;case"number":n=(i,a)=>Number(i)-Number(a);break;case"bigint":n=(i,a)=>BigInt(i)-BigInt(a)>0n?1:-1;break;case"boolean":n=(i,a)=>Number(i)-Number(a);break;case"undefined":n=()=>0;break;default:return console.warn(`sortFunc: unknown type ${t}`),()=>-1}return e?gc(n):n},gc=r=>(e,t)=>r(t,e),ur=s.z.tuple([s.z.number(),s.z.number()]);s.z.tuple([s.z.bigint(),s.z.bigint()]);const Hs=s.z.object({width:s.z.number(),height:s.z.number()}),pc=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()}),mc=["width","height"];s.z.enum(mc);const wc=["start","center","end"],bc=["signedWidth","signedHeight"];s.z.enum(bc);const ir=s.z.object({x:s.z.number(),y:s.z.number()}),Tc=s.z.object({clientX:s.z.number(),clientY:s.z.number()}),vc=["x","y"],_s=s.z.enum(vc),Ws=["top","right","bottom","left"];s.z.enum(Ws);const Ec=["left","right"],Gs=s.z.enum(Ec),Nc=["top","bottom"],Ks=s.z.enum(Nc),Js=["center"],is=s.z.enum(Js),Oc=[...Ws,...Js],Xs=s.z.enum(Oc);s.z.enum(wc);const zc=["first","last"];s.z.enum(zc);const Sc=s.z.object({lower:s.z.number(),upper:s.z.number()}),Ac=s.z.object({lower:s.z.bigint(),upper:s.z.bigint()});s.z.union([Sc,ur]);s.z.union([Ac,ur]);s.z.enum([..._s.options,...Xs.options]);s.z.enum(["x","left","right"]);s.z.enum(["y","top","bottom"]);s.z.union([_s,Xs,s.z.instanceof(String)]);const hr=r=>(e,t)=>{if(typeof e=="bigint"){if($c(t))return r(e,BigInt(t));const n=r(Number(e),Number(t));return typeof n=="number"?BigInt(Math.round(n)):n}return r(Number(e),Number(t))},fr=hr((r,e)=>r-e),dr=hr((r,e)=>r+e),$c=r=>typeof r=="bigint"?!0:Number.isInteger(r),le=hr((r,e)=>r*e),yr=hr((r,e)=>r/e),De=(r,e,t)=>{const n={};if(typeof e=="object"&&(t=e,e=void 0),t={makeValid:!0,...t},typeof r=="number"||typeof r=="bigint")e!=null?(n.lower=r,n.upper=e):(n.lower=typeof r=="bigint"?0n:0,n.upper=r);else if(Array.isArray(r)){if(r.length!==2)throw new Error("bounds: expected array of length 2");[n.lower,n.upper]=r}else n.lower=r.lower,n.upper=r.upper;return t?.makeValid?Ic(n):n},Ic=r=>r.lower>r.upper?{lower:r.upper,upper:r.lower}:r,as=(r,e)=>{const t=De(r);return e<t.lower?t.lower:e>=t.upper?t.upper-(typeof t.upper=="number"?1:1n):e};s.z.object({x:Gs.or(is),y:Ks.or(is)});const kc=s.z.object({x:Gs,y:Ks}),xc=Object.freeze({x:"left",y:"top"}),Cc=(r,e)=>r.x===e.x&&r.y===e.y,os=s.z.union([s.z.number(),ir,ur,Hs,pc,Tc]),Rc=(r,e)=>{if(typeof r=="string"){if(e===void 0)throw new Error("The y coordinate must be given.");return r==="x"?{x:e,y:0}:{x:0,y:e}}return typeof r=="number"?{x:r,y:e??r}:Array.isArray(r)?{x:r[0],y:r[1]}:"signedWidth"in r?{x:r.signedWidth,y:r.signedHeight}:"clientX"in r?{x:r.clientX,y:r.clientY}:"width"in r?{x:r.width,y:r.height}:{x:r.x,y:r.y}},cs=Object.freeze({x:0,y:0}),_t=s.z.union([s.z.number(),s.z.string()]);s.z.object({top:_t,left:_t,width:_t,height:_t});s.z.object({left:s.z.number(),top:s.z.number(),right:s.z.number(),bottom:s.z.number()});s.z.object({one:ir,two:ir,root:kc});const Nn=(r,e,t=0,n=0,i)=>{const a={one:{...cs},two:{...cs},root:i??xc};if(typeof r=="number"){if(typeof e!="number")throw new Error("Box constructor called with invalid arguments");return a.one={x:r,y:e},a.two={x:a.one.x+t,y:a.one.y+n},a}return"one"in r&&"two"in r&&"root"in r?{...r,root:i??r.root}:("getBoundingClientRect"in r&&(r=r.getBoundingClientRect()),"left"in r?(a.one={x:r.left,y:r.top},a.two={x:r.right,y:r.bottom},a):(a.one=r,e==null?a.two={x:a.one.x+t,y:a.one.y+n}:typeof e=="number"?a.two={x:a.one.x+e,y:a.one.y+t}:"width"in e?a.two={x:a.one.x+e.width,y:a.one.y+e.height}:"signedWidth"in e?a.two={x:a.one.x+e.signedWidth,y:a.one.y+e.signedHeight}:a.two=e,a))},jr=r=>{const e=Nn(r);return{lower:e.one.x,upper:e.two.x}},Mr=r=>{const e=Nn(r);return{lower:e.one.y,upper:e.two.y}},jc=r=>typeof r!="object"||r==null?!1:"one"in r&&"two"in r&&"root"in r,Mc=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()});s.z.union([Hs,Mc,ir,ur]);const Uc=(r,e,t)=>e!==void 0&&r<e?e:t!==void 0&&r>t?t:r;s.z.object({offset:os,scale:os});s.z.object({offset:s.z.number(),scale:s.z.number()});const Dc=r=>(e,t,n,i)=>t==="dimension"?[e,n]:[e,i?n-r:n+r],Zc=r=>(e,t,n,i)=>[e,i?n/r:n*r],Pc=r=>(e,t,n)=>{if(e===null)return[r,n];const{lower:i,upper:a}=e,{lower:o,upper:c}=r,u=a-i,l=c-o;if(t==="dimension")return[r,n*(l/u)];const h=(n-i)*(l/u)+o;return[r,h]},Lc=r=>(e,t,n)=>[r,n],Bc=()=>(r,e,t)=>{if(r===null)throw new Error("cannot invert without bounds");if(e==="dimension")return[r,t];const{lower:n,upper:i}=r;return[r,i-(t-n)]},qc=r=>(e,t,n)=>{const{lower:i,upper:a}=r;return n=Uc(n,i,a),[e,n]};let ls=class Ve{ops=[];currBounds=null;currType=null;reversed=!1;constructor(){this.ops=[]}static translate(e){return new Ve().translate(e)}static magnify(e){return new Ve().magnify(e)}static scale(e,t){return new Ve().scale(e,t)}translate(e){const t=this.new(),n=Dc(e);return n.type="translate",t.ops.push(n),t}magnify(e){const t=this.new(),n=Zc(e);return n.type="magnify",t.ops.push(n),t}scale(e,t){const n=De(e,t),i=this.new(),a=Pc(n);return a.type="scale",i.ops.push(a),i}clamp(e,t){const n=De(e,t),i=this.new(),a=qc(n);return a.type="clamp",i.ops.push(a),i}reBound(e,t){const n=De(e,t),i=this.new(),a=Lc(n);return a.type="re-bound",i.ops.push(a),i}invert(){const e=Bc();e.type="invert";const t=this.new();return t.ops.push(e),t}pos(e){return this.exec("position",e)}dim(e){return this.exec("dimension",e)}new(){const e=new Ve;return e.ops=this.ops.slice(),e.reversed=this.reversed,e}exec(e,t){return this.currBounds=null,this.ops.reduce(([n,i],a)=>a(n,e,i,this.reversed),[null,t])[1]}reverse(){const e=this.new();e.ops.reverse();const t=[];return e.ops.forEach((n,i)=>{if(n.type==="scale"||t.some(([o,c])=>i>=o&&i<=c))return;const a=e.ops.findIndex((o,c)=>o.type==="scale"&&c>i);a!==-1&&t.push([i,a])}),t.forEach(([n,i])=>{const a=e.ops.slice(n,i);a.unshift(e.ops[i]),e.ops.splice(n,i-n+1,...a)}),e.reversed=!e.reversed,e}get transform(){return{scale:this.dim(1),offset:this.pos(0)}}static IDENTITY=new Ve};(class oe{x;y;currRoot;constructor(e=new ls,t=new ls,n=null){this.x=e,this.y=t,this.currRoot=n}static translate(e,t){return new oe().translate(e,t)}static translateX(e){return new oe().translateX(e)}static translateY(e){return new oe().translateY(e)}static clamp(e){return new oe().clamp(e)}static magnify(e){return new oe().magnify(e)}static scale(e){return new oe().scale(e)}static reBound(e){return new oe().reBound(e)}translate(e,t){const n=Rc(e,t),i=this.copy();return i.x=this.x.translate(n.x),i.y=this.y.translate(n.y),i}translateX(e){const t=this.copy();return t.x=this.x.translate(e),t}translateY(e){const t=this.copy();return t.y=this.y.translate(e),t}magnify(e){const t=this.copy();return t.x=this.x.magnify(e.x),t.y=this.y.magnify(e.y),t}scale(e){const t=this.copy();if(jc(e)){const n=this.currRoot;return t.currRoot=e.root,n!=null&&!Cc(n,e.root)&&(n.x!==e.root.x&&(t.x=t.x.invert()),n.y!==e.root.y&&(t.y=t.y.invert())),t.x=t.x.scale(jr(e)),t.y=t.y.scale(Mr(e)),t}return t.x=t.x.scale(e.width),t.y=t.y.scale(e.height),t}reBound(e){const t=this.copy();return t.x=this.x.reBound(jr(e)),t.y=this.y.reBound(Mr(e)),t}clamp(e){const t=this.copy();return t.x=this.x.clamp(jr(e)),t.y=this.y.clamp(Mr(e)),t}copy(){const e=new oe;return e.currRoot=this.currRoot,e.x=this.x,e.y=this.y,e}reverse(){const e=this.copy();return e.x=this.x.reverse(),e.y=this.y.reverse(),e}pos(e){return{x:this.x.pos(e.x),y:this.y.pos(e.y)}}dim(e){return{x:this.x.dim(e.x),y:this.y.dim(e.y)}}box(e){return Nn(this.pos(e.one),this.pos(e.two),0,0,this.currRoot??e.root)}get transform(){return{scale:this.dim({x:1,y:1}),offset:this.pos({x:0,y:0})}}static IDENTITY=new oe});let Qs=(r,e=21)=>(t=e)=>{let n="",i=t|0;for(;i--;)n+=r[Math.random()*r.length|0];return n};const ei="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",Fc=`0123456789${ei}`,Yc=11,Vc=Qs(ei,1),Hc=Qs(Fc,Yc-1),_c=()=>`${Vc()}${Hc()}`,Wc=(r,e)=>t=>t instanceof e||typeof t=="object"&&t!==null&&"discriminator"in t&&t.discriminator===r,Gc=s.z.enum(["static","dynamic"]),Kc=s.z.union([s.z.tuple([s.z.int()]),s.z.tuple([s.z.int(),s.z.int().min(1).max(12)]),s.z.tuple([s.z.int(),s.z.int().min(1).max(12),s.z.int().min(1).max(31)])]),ti=(r,e)=>{const t=new I(e);if(![A.DAY,A.HOUR,A.MINUTE,A.SECOND,A.MILLISECOND,A.MICROSECOND,A.NANOSECOND].some(i=>i.equals(t)))throw new Error("Invalid argument for remainder. Must be an even TimeSpan or Timestamp");const n=r.valueOf()%t.valueOf();return r instanceof I?new I(n):new A(n)};let I=class w extends rt{constructor(e,t="UTC"){if(e==null)super(w.now().valueOf());else if(e instanceof Date)super(BigInt(e.getTime())*w.MILLISECOND.valueOf());else if(typeof e=="string")super(w.parseDateTimeString(e,t).valueOf());else if(Array.isArray(e))super(w.parseDate(e));else{let n=0n;e instanceof Number&&(e=e.valueOf()),t==="local"&&(n=w.utcOffset.valueOf()),typeof e=="number"&&(isFinite(e)?e=Math.trunc(e):(isNaN(e)&&(e=0),e===1/0?e=w.MAX:e=w.MIN)),X(e)&&(e=e.value),super(BigInt(e.valueOf())+n)}}static parseDate([e=1970,t=1,n=1]){const i=new Date(e,t-1,n,0,0,0,0);return new w(BigInt(i.getTime())*w.MILLISECOND.valueOf()).truncate(w.DAY).valueOf()}valueOf(){return this.value}static parseTimeString(e,t="UTC"){const[n,i,a]=e.split(":");let o="00",c="00";a!=null&&([o,c]=a.split("."));let u=w.hours(parseInt(n??"00")).add(w.minutes(parseInt(i??"00"))).add(w.seconds(parseInt(o??"00"))).add(w.milliseconds(parseInt(c??"00")));return t==="local"&&(u=u.add(w.utcOffset)),u.valueOf()}static parseDateTimeString(e,t="UTC"){if(!e.includes("/")&&!e.includes("-"))return w.parseTimeString(e,t);const n=new Date(e);return e.includes(":")||n.setUTCHours(0,0,0,0),new w(BigInt(n.getTime())*w.MILLISECOND.valueOf(),t).valueOf()}fString(e="ISO",t="UTC"){switch(e){case"ISODate":return this.toISOString(t).slice(0,10);case"ISOTime":return this.toISOString(t).slice(11,23);case"time":return this.timeString(!1,t);case"preciseTime":return this.timeString(!0,t);case"date":return this.dateString();case"preciseDate":return`${this.dateString()} ${this.timeString(!0,t)}`;case"dateTime":return`${this.dateString()} ${this.timeString(!1,t)}`;default:return this.toISOString(t)}}toISOString(e="UTC"){return e==="UTC"?this.date().toISOString():this.sub(w.utcOffset).date().toISOString()}timeString(e=!1,t="UTC"){const n=this.toISOString(t);return e?n.slice(11,23):n.slice(11,19)}dateString(){const e=this.date(),t=e.toLocaleString("default",{month:"short"}),n=e.toLocaleString("default",{day:"numeric"});return`${t} ${n}`}static get utcOffset(){return new A(BigInt(new Date().getTimezoneOffset())*w.MINUTE.valueOf())}static since(e){return new w().span(e)}date(){return new Date(this.milliseconds)}equals(e){return this.valueOf()===new w(e).valueOf()}span(e){return this.range(e).span}range(e){return new dt(this,e).makeValid()}spanRange(e){return this.range(this.add(e)).makeValid()}get isZero(){return this.valueOf()===0n}after(e){return this.valueOf()>new w(e).valueOf()}afterEq(e){return this.valueOf()>=new w(e).valueOf()}before(e){return this.valueOf()<new w(e).valueOf()}beforeEq(e){return this.valueOf()<=new w(e).valueOf()}add(e){return new w(dr(this.valueOf(),new A(e).valueOf()))}sub(e){return new w(fr(this.valueOf(),new A(e).valueOf()))}get hours(){return Number(this.valueOf())/Number(A.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(A.MINUTE.valueOf())}get days(){return Number(this.valueOf())/Number(A.DAY.valueOf())}get seconds(){return Number(this.valueOf())/Number(A.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(w.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(w.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get year(){return this.date().getUTCFullYear()}setYear(e){const t=this.date();return t.setUTCFullYear(e),new w(t)}get month(){return this.date().getUTCMonth()}setMonth(e){const t=this.date();return t.setUTCMonth(e),new w(t)}get day(){return this.date().getUTCDate()}setDay(e){const t=this.date();return t.setUTCDate(e),new w(t)}get hour(){return this.date().getUTCHours()}get localHour(){return this.date().getHours()}setLocalHour(e){const t=this.date();return t.setHours(e),new w(t)}setHour(e){const t=this.date();return t.setUTCHours(e),new w(t)}get minute(){return this.date().getUTCMinutes()}setMinute(e){const t=this.date();return t.setUTCMinutes(e),new w(t)}get second(){return this.date().getUTCSeconds()}setSecond(e){const t=this.date();return t.setUTCSeconds(e),new w(t)}get millisecond(){return this.date().getUTCMilliseconds()}setMillisecond(e){const t=this.date();return t.setUTCMilliseconds(e),new w(t)}toString(){return this.date().toISOString()}remainder(e){return ti(this,e)}get isToday(){return this.truncate(A.DAY).equals(w.now().truncate(A.DAY))}truncate(e){return this.sub(this.remainder(e))}static now(){return new w(new Date)}static max(...e){let t=w.MIN;for(const n of e){const i=new w(n);i.after(t)&&(t=i)}return t}static min(...e){let t=w.MAX;for(const n of e){const i=new w(n);i.before(t)&&(t=i)}return t}static nanoseconds(e,t="UTC"){return new w(e,t)}static NANOSECOND=w.nanoseconds(1);static microseconds(e,t="UTC"){return w.nanoseconds(e*1e3,t)}static MICROSECOND=w.microseconds(1);static milliseconds(e,t="UTC"){return w.microseconds(e*1e3,t)}static MILLISECOND=w.milliseconds(1);static seconds(e,t="UTC"){return w.milliseconds(e*1e3,t)}static SECOND=w.seconds(1);static minutes(e,t="UTC"){return w.seconds(e*60,t)}static MINUTE=w.minutes(1);static hours(e,t="UTC"){return w.minutes(e*60,t)}static HOUR=w.hours(1);static days(e,t="UTC"){return w.hours(e*24,t)}static DAY=w.days(1);static MAX=new w((1n<<63n)-1n);static MIN=new w(0);static ZERO=new w(0);static z=s.z.union([s.z.instanceof(w),s.z.object({value:s.z.bigint()}).transform(e=>new w(e.value)),s.z.string().transform(e=>new w(BigInt(e))),s.z.number().transform(e=>new w(e)),s.z.bigint().transform(e=>new w(e)),s.z.date().transform(e=>new w(e)),s.z.custom(e=>e instanceof A).transform(e=>new w(e)),Kc.transform(e=>new w(e))]);static sort(e,t){return Number(e.valueOf()-t.valueOf())}},A=class b extends rt{constructor(e){typeof e=="number"&&(e=Math.trunc(e.valueOf())),X(e)&&(e=e.value),super(BigInt(e.valueOf()))}static fromSeconds(e){return e instanceof b?e:e instanceof Ur?e.period:e instanceof I?new b(e):(X(e)&&(e=e.value),["number","bigint"].includes(typeof e)?b.seconds(e):new b(e))}static fromMilliseconds(e){return e instanceof b?e:e instanceof Ur?e.period:e instanceof I?new b(e):(X(e)&&(e=e.value),["number","bigint"].includes(typeof e)?b.milliseconds(e):new b(e))}valueOf(){return this.value}lessThan(e){return this.valueOf()<new b(e).valueOf()}greaterThan(e){return this.valueOf()>new b(e).valueOf()}lessThanOrEqual(e){return this.valueOf()<=new b(e).valueOf()}greaterThanOrEqual(e){return this.valueOf()>=new b(e).valueOf()}remainder(e){return ti(this,e)}truncate(e){return new b(BigInt(Math.trunc(Number(this.valueOf()/e.valueOf())))*e.valueOf())}toString(){const e=this.truncate(b.DAY),t=this.truncate(b.HOUR),n=this.truncate(b.MINUTE),i=this.truncate(b.SECOND),a=this.truncate(b.MILLISECOND),o=this.truncate(b.MICROSECOND),c=this.truncate(b.NANOSECOND),u=e,l=t.sub(e),h=n.sub(t),y=i.sub(n),d=a.sub(i),N=o.sub(a),S=c.sub(o);let k="";return u.isZero||(k+=`${u.days}d `),l.isZero||(k+=`${l.hours}h `),h.isZero||(k+=`${h.minutes}m `),y.isZero||(k+=`${y.seconds}s `),d.isZero||(k+=`${d.milliseconds}ms `),N.isZero||(k+=`${N.microseconds}µs `),S.isZero||(k+=`${S.nanoseconds}ns`),k.trim()}mult(e){return new b(le(this.valueOf(),e))}div(e){return new b(yr(this.valueOf(),e))}get days(){return Number(this.valueOf())/Number(b.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(b.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(b.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(b.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(b.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(b.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get isZero(){return this.valueOf()===0n}equals(e){return this.valueOf()===new b(e).valueOf()}add(e){return new b(this.valueOf()+new b(e).valueOf())}sub(e){return new b(this.valueOf()-new b(e).valueOf())}static nanoseconds(e=1){return new b(e)}static NANOSECOND=b.nanoseconds(1);static microseconds(e=1){return b.nanoseconds(le(e,1e3))}static MICROSECOND=b.microseconds(1);static milliseconds(e=1){return b.microseconds(le(e,1e3))}static MILLISECOND=b.milliseconds(1);static seconds(e=1){return b.milliseconds(le(e,1e3))}static SECOND=b.seconds(1);static minutes(e=1){return b.seconds(le(e,60))}static MINUTE=b.minutes(1);static hours(e){return b.minutes(le(e,60))}static HOUR=b.hours(1);static days(e){return b.hours(le(e,24))}static DAY=b.days(1);static MAX=new b((1n<<63n)-1n);static MIN=new b(0);static ZERO=new b(0);static z=s.z.union([s.z.object({value:s.z.bigint()}).transform(e=>new b(e.value)),s.z.string().transform(e=>new b(BigInt(e))),s.z.number().transform(e=>new b(e)),s.z.bigint().transform(e=>new b(e)),s.z.instanceof(b),s.z.instanceof(I).transform(e=>new b(e)),s.z.custom(e=>e instanceof Ur).transform(e=>new b(e))])},Ur=class J extends rt{constructor(e){X(e)&&(e=e.value),super(e.valueOf())}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new J(e).valueOf()}get period(){return A.seconds(1/this.valueOf())}sampleCount(e){return new A(e).seconds*this.valueOf()}byteCount(e,t){return this.sampleCount(e)*new _(t).valueOf()}span(e){return A.seconds(e/this.valueOf())}byteSpan(e,t){return this.span(e.valueOf()/new _(t).valueOf())}add(e){return new J(dr(this.valueOf(),new J(e).valueOf()))}sub(e){return new J(fr(this.valueOf(),new J(e).valueOf()))}mult(e){return new J(le(this.valueOf(),e))}div(e){return new J(yr(this.valueOf(),e))}static hz(e){return new J(e)}static khz(e){return J.hz(e*1e3)}static z=s.z.union([s.z.number().transform(e=>new J(e)),s.z.instanceof(J)])},_=class G extends rt{constructor(e){X(e)&&(e=e.value),super(e.valueOf())}length(e){return e.valueOf()/this.valueOf()}size(e){return new Xr(e*this.valueOf())}add(e){return new G(dr(this.valueOf(),new G(e).valueOf()))}sub(e){return new G(fr(this.valueOf(),new G(e).valueOf()))}mult(e){return new G(le(this.valueOf(),e))}div(e){return new G(yr(this.valueOf(),e))}static UNKNOWN=new G(0);static BIT128=new G(16);static BIT64=new G(8);static BIT32=new G(4);static BIT16=new G(2);static BIT8=new G(1);static z=s.z.union([s.z.number().transform(e=>new G(e)),s.z.instanceof(G)])},dt=class re{start;end;constructor(e,t){typeof e=="object"&&"start"in e?(this.start=new I(e.start),this.end=new I(e.end)):(this.start=new I(e),this.end=new I(t))}get span(){return new A(this.end.valueOf()-this.start.valueOf())}get isValid(){return this.start.valueOf()<=this.end.valueOf()}makeValid(){return this.isValid?this:this.swap()}get isZero(){return this.span.isZero}get numeric(){return{start:Number(this.start.valueOf()),end:Number(this.end.valueOf())}}swap(){return new re(this.end,this.start)}get numericBounds(){return{lower:Number(this.start.valueOf()),upper:Number(this.end.valueOf())}}equals(e,t=A.ZERO){if(t.isZero)return this.start.equals(e.start)&&this.end.equals(e.end);let n=this.start.sub(e.start).valueOf(),i=this.end.sub(e.end).valueOf();return n<0&&(n=-n),i<0&&(i=-i),n<=t.valueOf()&&i<=t.valueOf()}toString(){return`${this.start.toString()} - ${this.end.toString()}`}toPrettyString(){return`${this.start.fString("preciseDate")} - ${this.span.toString()}`}overlapsWith(e,t=A.ZERO){e=e.makeValid();const n=this.makeValid();if(this.equals(e))return!0;if(e.end.equals(n.start)||n.end.equals(e.start))return!1;const i=I.max(n.start,e.start),a=I.min(n.end,e.end);return a.before(i)?!1:new A(a.sub(i)).greaterThanOrEqual(t)}contains(e){return e instanceof re?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const t=new re(this.start,this.end);return e.start.after(this.start)&&(t.start=e.start),e.start.after(this.end)&&(t.end=e.start),e.end.before(this.end)&&(t.end=e.end),e.end.before(this.start)&&(t.start=e.end),t}static max(...e){return new re(I.min(...e.map(t=>t.start)),I.max(...e.map(t=>t.end)))}static MAX=new re(I.MIN,I.MAX);static MIN=new re(I.MAX,I.MIN);static ZERO=new re(I.ZERO,I.ZERO);static z=s.z.union([s.z.object({start:I.z,end:I.z}).transform(e=>new re(e.start,e.end)),s.z.instanceof(re)]);static sort(e,t){return I.sort(e.start,t.start)||I.sort(e.end,t.end)}static simplify(e){return e.map(t=>t.makeValid()).sort((t,n)=>re.sort(t,n)).reduce((t,n)=>{if(n.isZero)return t;if(t.length===0)return t.push(n),t;const i=t[t.length-1];return i.overlapsWith(n)||i.end.equals(n.start)?i.end=I.max(i.end,n.end):t.push(n),t},[])}},U=class g extends rt{constructor(e){if(X(e)&&(e=e.value),e instanceof g||typeof e=="string"||typeof e.valueOf()=="string")super(e.valueOf());else{const t=g.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);if(t==null)throw new Error(`unable to find data type for ${e.toString()}`);super(t.valueOf())}}get Array(){const e=g.ARRAY_CONSTRUCTORS.get(this.toString());if(e==null)throw new Error(`unable to find array constructor for ${this.valueOf()}`);return e}equals(e){return this.valueOf()===e.valueOf()}matches(...e){return e.some(t=>this.equals(t))}toString(){return this.valueOf()}get isVariable(){return this.equals(g.JSON)||this.equals(g.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(g.UUID)}get isInteger(){const e=this.toString();return e.startsWith("int")||e.startsWith("uint")}get isFloat(){return this.toString().startsWith("float")}get density(){const e=g.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}get isUnsignedInteger(){return this.equals(g.UINT8)||this.equals(g.UINT16)||this.equals(g.UINT32)||this.equals(g.UINT64)}get isSignedInteger(){return this.equals(g.INT8)||this.equals(g.INT16)||this.equals(g.INT32)||this.equals(g.INT64)}canSafelyCastTo(e){return this.equals(e)?!0:!this.isNumeric||!e.isNumeric||this.isVariable||e.isVariable||this.isUnsignedInteger&&e.isSignedInteger?!1:this.isFloat?e.isFloat&&this.density.valueOf()<=e.density.valueOf():this.equals(g.INT32)&&e.equals(g.FLOAT64)||this.equals(g.INT8)&&e.equals(g.FLOAT32)?!0:this.isInteger&&e.isInteger?this.density.valueOf()<=e.density.valueOf()&&this.isUnsignedInteger===e.isUnsignedInteger:!1}canCastTo(e){return this.isNumeric&&e.isNumeric?!0:this.equals(e)}checkArray(e){return e.constructor===this.Array}get usesBigInt(){return g.BIG_INT_TYPES.some(e=>e.equals(this))}static UNKNOWN=new g("unknown");static FLOAT64=new g("float64");static FLOAT32=new g("float32");static INT64=new g("int64");static INT32=new g("int32");static INT16=new g("int16");static INT8=new g("int8");static UINT64=new g("uint64");static UINT32=new g("uint32");static UINT16=new g("uint16");static UINT8=new g("uint8");static BOOLEAN=this.UINT8;static TIMESTAMP=new g("timestamp");static UUID=new g("uuid");static STRING=new g("string");static JSON=new g("json");static ARRAY_CONSTRUCTORS=new Map([[g.UINT8.toString(),Uint8Array],[g.UINT16.toString(),Uint16Array],[g.UINT32.toString(),Uint32Array],[g.UINT64.toString(),BigUint64Array],[g.FLOAT32.toString(),Float32Array],[g.FLOAT64.toString(),Float64Array],[g.INT8.toString(),Int8Array],[g.INT16.toString(),Int16Array],[g.INT32.toString(),Int32Array],[g.INT64.toString(),BigInt64Array],[g.TIMESTAMP.toString(),BigInt64Array],[g.STRING.toString(),Uint8Array],[g.JSON.toString(),Uint8Array],[g.UUID.toString(),Uint8Array]]);static ARRAY_CONSTRUCTOR_DATA_TYPES=new Map([[Uint8Array.name,g.UINT8],[Uint16Array.name,g.UINT16],[Uint32Array.name,g.UINT32],[BigUint64Array.name,g.UINT64],[Float32Array.name,g.FLOAT32],[Float64Array.name,g.FLOAT64],[Int8Array.name,g.INT8],[Int16Array.name,g.INT16],[Int32Array.name,g.INT32],[BigInt64Array.name,g.INT64]]);static DENSITIES=new Map([[g.UINT8.toString(),_.BIT8],[g.UINT16.toString(),_.BIT16],[g.UINT32.toString(),_.BIT32],[g.UINT64.toString(),_.BIT64],[g.FLOAT32.toString(),_.BIT32],[g.FLOAT64.toString(),_.BIT64],[g.INT8.toString(),_.BIT8],[g.INT16.toString(),_.BIT16],[g.INT32.toString(),_.BIT32],[g.INT64.toString(),_.BIT64],[g.TIMESTAMP.toString(),_.BIT64],[g.STRING.toString(),_.UNKNOWN],[g.JSON.toString(),_.UNKNOWN],[g.UUID.toString(),_.BIT128]]);static ALL=[g.UNKNOWN,g.FLOAT64,g.FLOAT32,g.INT64,g.INT32,g.INT16,g.INT8,g.UINT64,g.UINT32,g.UINT16,g.UINT8,g.TIMESTAMP,g.UUID,g.STRING,g.JSON];static BIG_INT_TYPES=[g.INT64,g.UINT64,g.TIMESTAMP];static z=s.z.union([s.z.string().transform(e=>new g(e)),s.z.instanceof(g)])},Xr=class O extends rt{constructor(e){X(e)&&(e=e.value),super(e.valueOf())}largerThan(e){return X(e)&&(e=e.value),this.valueOf()>e.valueOf()}smallerThan(e){return X(e)&&(e=e.value),this.valueOf()<e.valueOf()}add(e){return X(e)&&(e=e.value),new O(dr(this.valueOf(),e.valueOf()))}sub(e){return X(e)&&(e=e.value),new O(fr(this.valueOf(),e.valueOf()))}mult(e){return new O(le(this.valueOf(),e))}div(e){return new O(yr(this.valueOf(),e))}truncate(e){return new O(Math.trunc(this.valueOf()/new O(e).valueOf())*new O(e).valueOf())}remainder(e){return O.bytes(this.valueOf()%new O(e).valueOf())}get gigabytes(){return this.valueOf()/O.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/O.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/O.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/O.TERABYTE.valueOf()}toString(){const e=this.truncate(O.TERABYTE),t=this.truncate(O.GIGABYTE),n=this.truncate(O.MEGABYTE),i=this.truncate(O.KILOBYTE),a=this.truncate(O.BYTE),o=e,c=t.sub(e),u=n.sub(t),l=i.sub(n),h=a.sub(i);let y="";return o.isZero||(y+=`${o.terabytes}TB `),c.isZero||(y+=`${c.gigabytes}GB `),u.isZero||(y+=`${u.megabytes}MB `),l.isZero||(y+=`${l.kilobytes}KB `),(!h.isZero||y==="")&&(y+=`${h.valueOf()}B`),y.trim()}static bytes(e=1){return new O(e)}static BYTE=new O(1);static kilobytes(e=1){return O.bytes(new O(e).valueOf()*1e3)}static KILOBYTE=O.kilobytes(1);static megabytes(e=1){return O.kilobytes(new O(e).valueOf()*1e3)}static MEGABYTE=O.megabytes(1);static gigabytes(e=1){return O.megabytes(new O(e).valueOf()*1e3)}static GIGABYTE=O.gigabytes(1);static terabytes(e){return O.gigabytes(new O(e).valueOf()*1e3)}static TERABYTE=O.terabytes(1);static ZERO=new O(0);static z=s.z.union([s.z.number().transform(e=>new O(e)),s.z.instanceof(O)]);get isZero(){return this.valueOf()===0}};s.z.union([s.z.instanceof(Uint8Array),s.z.instanceof(Uint16Array),s.z.instanceof(Uint32Array),s.z.instanceof(BigUint64Array),s.z.instanceof(Float32Array),s.z.instanceof(Float64Array),s.z.instanceof(Int8Array),s.z.instanceof(Int16Array),s.z.instanceof(Int32Array),s.z.instanceof(BigInt64Array)]);const ri=r=>{const e=typeof r;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||r instanceof I||r instanceof A||r instanceof Date},Jc=(r,e,t,n=0)=>r.usesBigInt&&!e.usesBigInt?Number(t)-Number(n):!r.usesBigInt&&e.usesBigInt?BigInt(t.valueOf())-BigInt(n.valueOf()):Xt(t,-n),Xt=(r,e)=>e==0?r:r==0?e:typeof r=="bigint"&&typeof e=="bigint"||typeof r=="number"&&typeof e=="number"?r+e:Number(r)+Number(e),Xc=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;function Qc(r){return typeof r=="string"&&Xc.test(r)}const q=[];for(let r=0;r<256;++r)q.push((r+256).toString(16).slice(1));function el(r,e=0){return(q[r[e+0]]+q[r[e+1]]+q[r[e+2]]+q[r[e+3]]+"-"+q[r[e+4]]+q[r[e+5]]+"-"+q[r[e+6]]+q[r[e+7]]+"-"+q[r[e+8]]+q[r[e+9]]+"-"+q[r[e+10]]+q[r[e+11]]+q[r[e+12]]+q[r[e+13]]+q[r[e+14]]+q[r[e+15]]).toLowerCase()}function tl(r,e=0){const t=el(r,e);if(!Qc(t))throw TypeError("Stringified UUID is invalid");return t}typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const ni=(r,e)=>tl(r,e),Ee=-1,rl=s.z.string().transform(r=>new Uint8Array(atob(r).split("").map(e=>e.charCodeAt(0))).buffer),nl=s.z.union([s.z.null(),s.z.undefined()]).transform(()=>new Uint8Array().buffer),Qr=10,sl=(r,e)=>{if(r==="number"&&!e.isNumeric)throw new Error(`cannot convert series of type ${e.toString()} to number`);if(r==="bigint"&&!e.usesBigInt)throw new Error(`cannot convert series of type ${e.toString()} to bigint`)},si="sy_x_telem_series";let ii=class Se{key;discriminator=si;dataType;sampleOffset;gl;_data;timeRange=dt.ZERO;alignment=0n;alignmentMultiple=1n;cachedMin;cachedMax;writePos=Ee;_refCount=0;cachedLength;_cachedIndexes;static crudeZ=s.z.object({timeRange:dt.z.optional(),dataType:U.z,alignment:s.z.coerce.bigint().optional(),data:s.z.union([rl,nl,s.z.instanceof(ArrayBuffer),s.z.instanceof(Uint8Array)]),glBufferUsage:Gc.optional().default("static").optional()});static z=Se.crudeZ.transform(e=>new Se(e));constructor(e){il(e)&&(e={data:e}),e.data??=[];const{dataType:t,timeRange:n,sampleOffset:i=0,glBufferUsage:a="static",alignment:o=0n,alignmentMultiple:c=1n,key:u=_c(),data:l}=e;if(al(l)){const d=l;this.key=d.key,this.dataType=d.dataType,this.sampleOffset=d.sampleOffset,this.gl=d.gl,this._data=d._data,this.timeRange=d.timeRange,this.alignment=d.alignment,this.alignmentMultiple=d.alignmentMultiple,this.cachedMin=d.cachedMin,this.cachedMax=d.cachedMax,this.writePos=d.writePos,this._refCount=d._refCount,this.cachedLength=d.cachedLength;return}const h=ri(l),y=Array.isArray(l);if(t!=null)this.dataType=new U(t);else{if(l instanceof ArrayBuffer)throw new Error("cannot infer data type from an ArrayBuffer instance when constructing a Series. Please provide a data type.");if(y||h){let d=l;if(!h){if(l.length===0)throw new Error("cannot infer data type from a zero length JS array when constructing a Series. Please provide a data type.");d=l[0]}if(typeof d=="string")this.dataType=U.STRING;else if(typeof d=="number")this.dataType=U.FLOAT64;else if(typeof d=="bigint")this.dataType=U.INT64;else if(typeof d=="boolean")this.dataType=U.BOOLEAN;else if(d instanceof I||d instanceof Date||d instanceof I)this.dataType=U.TIMESTAMP;else if(typeof d=="object")this.dataType=U.JSON;else throw new Error(`cannot infer data type of ${typeof d} when constructing a Series from a JS array`)}else this.dataType=new U(l)}if(!y&&!h)this._data=l;else if(y&&l.length===0)this._data=new this.dataType.Array([]).buffer;else{let d=h?[l]:l;const N=d[0];(N instanceof I||N instanceof Date||N instanceof A)&&(d=d.map(S=>new I(S).valueOf())),this.dataType.equals(U.STRING)?(this.cachedLength=d.length,this._data=new TextEncoder().encode(`${d.join(`
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("zod"),Al=t=>{const e=t.replace(/_[a-z]/g,r=>r[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)},ya=t=>{const e=(r,n=jn)=>{if(typeof r=="string")return t(r);if(Array.isArray(r))return r.map(o=>e(o,n));if(!gn(r))return r;n=Rl(n);const s={},a=r;return"toJSON"in a&&typeof a.toJSON=="function"?e(a.toJSON(),n):(Object.keys(a).forEach(o=>{let c=a[o];const l=t(o);n.recursive&&(gn(c)?ai(c)||(c=e(c,n)):n.recursiveInArray&&ii(c)&&(c=[...c].map(u=>{let h=u;return gn(u)?ai(h)||(h=e(u,n)):ii(u)&&(h=e({key:u},n).key),h}))),s[l]=c}),s)};return e},ma=ya(Al),xl=t=>t.replace(/([a-z0-9])([A-Z])/g,(e,r,n)=>`${r}_${n.toLowerCase()}`),Zl=ya(xl),Cl=[Number,String,Uint8Array],jn={recursive:!0,recursiveInArray:!0},Rl=(t=jn)=>(t.recursive==null?t=jn:t.recursiveInArray??=!1,t),ii=t=>t!=null&&Array.isArray(t),gn=t=>t!=null&&typeof t=="object"&&!Array.isArray(t),ai=t=>Cl.some(e=>t instanceof e);let _l=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,r){return this.decodeString(this.decoder.decode(e),r)}decodeString(e,r){const n=JSON.parse(e),s=ma(n);return r!=null?r.parse(s):s}encodeString(e){const r=Zl(e);return JSON.stringify(r,(n,s)=>ArrayBuffer.isView(s)?Array.from(s):typeof s=="bigint"?s.toString():s)}};const Mn=new _l,le=t=>t!=null&&typeof t=="object"&&"value"in t;let Et=class{value;constructor(e){this.value=e}valueOf(){return this.value}toJSON(){return this.value}toString(){return this.value.toString()}};const jl=t=>t!=null&&typeof t=="object"&&"toString"in t,Ml=(t,e=!1)=>{const r=jl(t)?"stringer":typeof t;let n;switch(r){case"string":n=(s,a)=>s.localeCompare(a);break;case"stringer":n=(s,a)=>s.toString().localeCompare(a.toString());break;case"number":n=(s,a)=>Number(s)-Number(a);break;case"bigint":n=(s,a)=>BigInt(s)-BigInt(a)>0n?1:-1;break;case"boolean":n=(s,a)=>Number(s)-Number(a);break;case"undefined":n=()=>0;break;default:return console.warn(`sortFunc: unknown type ${r}`),()=>-1}return e?Dl(n):n},Dl=t=>(e,r)=>t(r,e),Lr=i.z.tuple([i.z.number(),i.z.number()]);i.z.tuple([i.z.bigint(),i.z.bigint()]);const ga=i.z.object({width:i.z.number(),height:i.z.number()}),Pl=i.z.object({signedWidth:i.z.number(),signedHeight:i.z.number()}),Ul=["width","height"];i.z.enum(Ul);const Ll=["start","center","end"],Bl=["signedWidth","signedHeight"];i.z.enum(Bl);const Zr=i.z.object({x:i.z.number(),y:i.z.number()}),ql=i.z.object({clientX:i.z.number(),clientY:i.z.number()}),Fl=["x","y"],wa=i.z.enum(Fl),ba=["top","right","bottom","left"];i.z.enum(ba);const Vl=["left","right"],va=i.z.enum(Vl),Yl=["top","bottom"],Ta=i.z.enum(Yl),za=["center"],oi=i.z.enum(za),Wl=[...ba,...za],Ea=i.z.enum(Wl);i.z.enum(Ll);const Hl=["first","last"];i.z.enum(Hl);const Gl=i.z.object({lower:i.z.number(),upper:i.z.number()}),Jl=i.z.object({lower:i.z.bigint(),upper:i.z.bigint()});i.z.union([Gl,Lr]);i.z.union([Jl,Lr]);i.z.enum([...wa.options,...Ea.options]);i.z.enum(["x","left","right"]);i.z.enum(["y","top","bottom"]);i.z.union([wa,Ea,i.z.instanceof(String)]);const Br=t=>(e,r)=>{if(typeof e=="bigint"){if(Kl(r))return t(e,BigInt(r));const n=t(Number(e),Number(r));return typeof n=="number"?BigInt(Math.round(n)):n}return t(Number(e),Number(r))},qr=Br((t,e)=>t-e),Fr=Br((t,e)=>t+e),Kl=t=>typeof t=="bigint"?!0:Number.isInteger(t),$e=Br((t,e)=>t*e),Vr=Br((t,e)=>t/e),Qe=(t,e,r)=>{const n={};if(typeof e=="object"&&(r=e,e=void 0),r={makeValid:!0,...r},typeof t=="number"||typeof t=="bigint")e!=null?(n.lower=t,n.upper=e):(n.lower=typeof t=="bigint"?0n:0,n.upper=t);else if(Array.isArray(t)){if(t.length!==2)throw new Error("bounds: expected array of length 2");[n.lower,n.upper]=t}else n.lower=t.lower,n.upper=t.upper;return r?.makeValid?Xl(n):n},Xl=t=>t.lower>t.upper?{lower:t.upper,upper:t.lower}:t,ci=(t,e)=>{const r=Qe(t);return e<r.lower?r.lower:e>=r.upper?r.upper-(typeof r.upper=="number"?1:1n):e};i.z.object({x:va.or(oi),y:Ta.or(oi)});const Ql=i.z.object({x:va,y:Ta}),eh=Object.freeze({x:"left",y:"top"}),th=(t,e)=>t.x===e.x&&t.y===e.y,ui=i.z.union([i.z.number(),Zr,Lr,ga,Pl,ql]),rh=(t,e)=>{if(typeof t=="string"){if(e===void 0)throw new Error("The y coordinate must be given.");return t==="x"?{x:e,y:0}:{x:0,y:e}}return typeof t=="number"?{x:t,y:e??t}:Array.isArray(t)?{x:t[0],y:t[1]}:"signedWidth"in t?{x:t.signedWidth,y:t.signedHeight}:"clientX"in t?{x:t.clientX,y:t.clientY}:"width"in t?{x:t.width,y:t.height}:{x:t.x,y:t.y}},li=Object.freeze({x:0,y:0}),mr=i.z.union([i.z.number(),i.z.string()]);i.z.object({top:mr,left:mr,width:mr,height:mr});i.z.object({left:i.z.number(),top:i.z.number(),right:i.z.number(),bottom:i.z.number()});i.z.object({one:Zr,two:Zr,root:Ql});const ps=(t,e,r=0,n=0,s)=>{const a={one:{...li},two:{...li},root:s??eh};if(typeof t=="number"){if(typeof e!="number")throw new Error("Box constructor called with invalid arguments");return a.one={x:t,y:e},a.two={x:a.one.x+r,y:a.one.y+n},a}return"one"in t&&"two"in t&&"root"in t?{...t,root:s??t.root}:("getBoundingClientRect"in t&&(t=t.getBoundingClientRect()),"left"in t?(a.one={x:t.left,y:t.top},a.two={x:t.right,y:t.bottom},a):(a.one=t,e==null?a.two={x:a.one.x+r,y:a.one.y+n}:typeof e=="number"?a.two={x:a.one.x+e,y:a.one.y+r}:"width"in e?a.two={x:a.one.x+e.width,y:a.one.y+e.height}:"signedWidth"in e?a.two={x:a.one.x+e.signedWidth,y:a.one.y+e.signedHeight}:a.two=e,a))},wn=t=>{const e=ps(t);return{lower:e.one.x,upper:e.two.x}},bn=t=>{const e=ps(t);return{lower:e.one.y,upper:e.two.y}},nh=t=>typeof t!="object"||t==null?!1:"one"in t&&"two"in t&&"root"in t,sh=i.z.object({signedWidth:i.z.number(),signedHeight:i.z.number()});i.z.union([ga,sh,Zr,Lr]);const ih=(t,e,r)=>e!==void 0&&t<e?e:r!==void 0&&t>r?r:t;i.z.object({offset:ui,scale:ui});i.z.object({offset:i.z.number(),scale:i.z.number()});const ah=t=>(e,r,n,s)=>r==="dimension"?[e,n]:[e,s?n-t:n+t],oh=t=>(e,r,n,s)=>[e,s?n/t:n*t],ch=t=>(e,r,n)=>{if(e===null)return[t,n];const{lower:s,upper:a}=e,{lower:o,upper:c}=t,l=a-s,u=c-o;if(r==="dimension")return[t,n*(u/l)];const h=(n-s)*(u/l)+o;return[t,h]},uh=t=>(e,r,n)=>[t,n],lh=()=>(t,e,r)=>{if(t===null)throw new Error("cannot invert without bounds");if(e==="dimension")return[t,r];const{lower:n,upper:s}=t;return[t,s-(r-n)]},hh=t=>(e,r,n)=>{const{lower:s,upper:a}=t;return n=ih(n,s,a),[e,n]};let hi=class ut{ops=[];currBounds=null;currType=null;reversed=!1;constructor(){this.ops=[]}static translate(e){return new ut().translate(e)}static magnify(e){return new ut().magnify(e)}static scale(e,r){return new ut().scale(e,r)}translate(e){const r=this.new(),n=ah(e);return n.type="translate",r.ops.push(n),r}magnify(e){const r=this.new(),n=oh(e);return n.type="magnify",r.ops.push(n),r}scale(e,r){const n=Qe(e,r),s=this.new(),a=ch(n);return a.type="scale",s.ops.push(a),s}clamp(e,r){const n=Qe(e,r),s=this.new(),a=hh(n);return a.type="clamp",s.ops.push(a),s}reBound(e,r){const n=Qe(e,r),s=this.new(),a=uh(n);return a.type="re-bound",s.ops.push(a),s}invert(){const e=lh();e.type="invert";const r=this.new();return r.ops.push(e),r}pos(e){return this.exec("position",e)}dim(e){return this.exec("dimension",e)}new(){const e=new ut;return e.ops=this.ops.slice(),e.reversed=this.reversed,e}exec(e,r){return this.currBounds=null,this.ops.reduce(([n,s],a)=>a(n,e,s,this.reversed),[null,r])[1]}reverse(){const e=this.new();e.ops.reverse();const r=[];return e.ops.forEach((n,s)=>{if(n.type==="scale"||r.some(([o,c])=>s>=o&&s<=c))return;const a=e.ops.findIndex((o,c)=>o.type==="scale"&&c>s);a!==-1&&r.push([s,a])}),r.forEach(([n,s])=>{const a=e.ops.slice(n,s);a.unshift(e.ops[s]),e.ops.splice(n,s-n+1,...a)}),e.reversed=!e.reversed,e}get transform(){return{scale:this.dim(1),offset:this.pos(0)}}static IDENTITY=new ut};(class ze{x;y;currRoot;constructor(e=new hi,r=new hi,n=null){this.x=e,this.y=r,this.currRoot=n}static translate(e,r){return new ze().translate(e,r)}static translateX(e){return new ze().translateX(e)}static translateY(e){return new ze().translateY(e)}static clamp(e){return new ze().clamp(e)}static magnify(e){return new ze().magnify(e)}static scale(e){return new ze().scale(e)}static reBound(e){return new ze().reBound(e)}translate(e,r){const n=rh(e,r),s=this.copy();return s.x=this.x.translate(n.x),s.y=this.y.translate(n.y),s}translateX(e){const r=this.copy();return r.x=this.x.translate(e),r}translateY(e){const r=this.copy();return r.y=this.y.translate(e),r}magnify(e){const r=this.copy();return r.x=this.x.magnify(e.x),r.y=this.y.magnify(e.y),r}scale(e){const r=this.copy();if(nh(e)){const n=this.currRoot;return r.currRoot=e.root,n!=null&&!th(n,e.root)&&(n.x!==e.root.x&&(r.x=r.x.invert()),n.y!==e.root.y&&(r.y=r.y.invert())),r.x=r.x.scale(wn(e)),r.y=r.y.scale(bn(e)),r}return r.x=r.x.scale(e.width),r.y=r.y.scale(e.height),r}reBound(e){const r=this.copy();return r.x=this.x.reBound(wn(e)),r.y=this.y.reBound(bn(e)),r}clamp(e){const r=this.copy();return r.x=this.x.clamp(wn(e)),r.y=this.y.clamp(bn(e)),r}copy(){const e=new ze;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 ps(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 ze});let Na=(t,e=21)=>(r=e)=>{let n="",s=r|0;for(;s--;)n+=t[Math.random()*t.length|0];return n};const Oa="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",fh=`0123456789${Oa}`,dh=11,ph=Na(Oa,1),yh=Na(fh,dh-1),mh=()=>`${ph()}${yh()}`,gh=(t,e)=>r=>r instanceof e||typeof r=="object"&&r!==null&&"discriminator"in r&&r.discriminator===t,Dn=2n**63n-1n,wh=2**63-1,bh=i.z.enum(["static","dynamic"]),fi=365,gr=30,vh=i.z.union([i.z.tuple([i.z.int()]),i.z.tuple([i.z.int(),i.z.int().min(1).max(12)]),i.z.tuple([i.z.int(),i.z.int().min(1).max(12),i.z.int().min(1).max(31)])]),$a=(t,e)=>{const r=new _(e);if(![C.DAY,C.HOUR,C.MINUTE,C.SECOND,C.MILLISECOND,C.MICROSECOND,C.NANOSECOND].some(s=>s.equals(r)))throw new Error("Invalid argument for remainder. Must be an even TimeSpan or Timestamp");const n=t.valueOf()%r.valueOf();return t instanceof _?new _(n):new C(n)};let _=class E extends Et{constructor(e,r="UTC"){if(e==null)super(E.now().valueOf());else if(e instanceof Date)super(BigInt(e.getTime())*E.MILLISECOND.valueOf());else if(typeof e=="string")super(E.parseDateTimeString(e,r).valueOf());else if(Array.isArray(e))super(E.parseDate(e));else{let n=0n;e instanceof Number&&(e=e.valueOf()),r==="local"&&(n=E.utcOffset.valueOf()),typeof e=="number"&&(isFinite(e)?e===wh?e=Dn:e=Math.trunc(e):(isNaN(e)&&(e=0),e===1/0?e=E.MAX:e=E.MIN)),le(e)&&(e=e.value),super(BigInt(e.valueOf())+n)}}static parseDate([e=1970,r=1,n=1]){const s=new Date(e,r-1,n,0,0,0,0);return new E(BigInt(s.getTime())*E.MILLISECOND.valueOf()).truncate(E.DAY).valueOf()}valueOf(){return this.value}static parseTimeString(e,r="UTC"){const[n,s,a]=e.split(":");let o="00",c="00";a!=null&&([o,c]=a.split("."));let l=E.hours(parseInt(n??"00")).add(E.minutes(parseInt(s??"00"))).add(E.seconds(parseInt(o??"00"))).add(E.milliseconds(parseInt(c??"00")));return r==="local"&&(l=l.add(E.utcOffset)),l.valueOf()}static parseDateTimeString(e,r="UTC"){if(!e.includes("/")&&!e.includes("-"))return E.parseTimeString(e,r);const n=new Date(e);return e.includes(":")||n.setUTCHours(0,0,0,0),new E(BigInt(n.getTime())*E.MILLISECOND.valueOf(),r).valueOf()}toISOString(e="UTC"){return e==="UTC"?this.date().toISOString():this.sub(E.utcOffset).date().toISOString()}timeString(e=!1,r="UTC"){const n=this.toISOString(r);return e?n.slice(11,23):n.slice(11,19)}dateString(){const e=this.date(),r=e.toLocaleString("default",{month:"short"}),n=e.toLocaleString("default",{day:"numeric"});return`${r} ${n}`}static get utcOffset(){return new C(BigInt(new Date().getTimezoneOffset())*E.MINUTE.valueOf())}static since(e){return new E().span(e)}date(){return new Date(this.milliseconds)}equals(e){return this.valueOf()===new E(e).valueOf()}span(e){return this.range(e).span}range(e){return new Rt(this,e).makeValid()}spanRange(e){return this.range(this.add(e)).makeValid()}get isZero(){return this.valueOf()===0n}after(e){return this.valueOf()>new E(e).valueOf()}afterEq(e){return this.valueOf()>=new E(e).valueOf()}before(e){return this.valueOf()<new E(e).valueOf()}beforeEq(e){return this.valueOf()<=new E(e).valueOf()}add(e){return new E(Fr(this.valueOf(),new C(e).valueOf()))}sub(e){return new E(qr(this.valueOf(),new C(e).valueOf()))}get hours(){return Number(this.valueOf())/Number(C.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(C.MINUTE.valueOf())}get days(){return Number(this.valueOf())/Number(C.DAY.valueOf())}get seconds(){return Number(this.valueOf())/Number(C.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(E.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(E.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get year(){return this.date().getUTCFullYear()}setYear(e){const r=this.date();return r.setUTCFullYear(e),new E(r)}get month(){return this.date().getUTCMonth()}setMonth(e){const r=this.date();return r.setUTCMonth(e),new E(r)}get day(){return this.date().getUTCDate()}setDay(e){const r=this.date();return r.setUTCDate(e),new E(r)}get hour(){return this.date().getUTCHours()}get localHour(){return this.date().getHours()}setLocalHour(e){const r=this.date();return r.setHours(e),new E(r)}setHour(e){const r=this.date();return r.setUTCHours(e),new E(r)}get minute(){return this.date().getUTCMinutes()}setMinute(e){const r=this.date();return r.setUTCMinutes(e),new E(r)}get second(){return this.date().getUTCSeconds()}setSecond(e){const r=this.date();return r.setUTCSeconds(e),new E(r)}get millisecond(){return this.date().getUTCMilliseconds()}setMillisecond(e){const r=this.date();return r.setUTCMilliseconds(e),new E(r)}toString(e="ISO",r="UTC"){switch(e){case"ISODate":return this.toISOString(r).slice(0,10);case"ISOTime":return this.toISOString(r).slice(11,23);case"time":return this.timeString(!1,r);case"preciseTime":return this.timeString(!0,r);case"date":return this.dateString();case"preciseDate":return`${this.dateString()} ${this.timeString(!0,r)}`;case"dateTime":return`${this.dateString()} ${this.timeString(!1,r)}`;default:return this.toISOString(r)}}remainder(e){return $a(this,e)}get isToday(){return this.truncate(C.DAY).equals(E.now().truncate(C.DAY))}truncate(e){return this.sub(this.remainder(e))}static now(){return new E(new Date)}static max(...e){let r=E.MIN;for(const n of e){const s=new E(n);s.after(r)&&(r=s)}return r}static min(...e){let r=E.MAX;for(const n of e){const s=new E(n);s.before(r)&&(r=s)}return r}static nanoseconds(e,r="UTC"){return new E(e,r)}static NANOSECOND=E.nanoseconds(1);static microseconds(e,r="UTC"){return E.nanoseconds(e*1e3,r)}static MICROSECOND=E.microseconds(1);static milliseconds(e,r="UTC"){return E.microseconds(e*1e3,r)}static MILLISECOND=E.milliseconds(1);static seconds(e,r="UTC"){return E.milliseconds(e*1e3,r)}static SECOND=E.seconds(1);static minutes(e,r="UTC"){return E.seconds(e*60,r)}static MINUTE=E.minutes(1);static hours(e,r="UTC"){return E.minutes(e*60,r)}static HOUR=E.hours(1);static days(e,r="UTC"){return E.hours(e*24,r)}static DAY=E.days(1);static MAX=new E(Dn);static MIN=new E(0);static ZERO=new E(0);static z=i.z.union([i.z.instanceof(E),i.z.object({value:i.z.bigint()}).transform(e=>new E(e.value)),i.z.string().transform(e=>new E(BigInt(e))),i.z.number().transform(e=>new E(e)),i.z.bigint().transform(e=>new E(e)),i.z.date().transform(e=>new E(e)),i.z.custom(e=>e instanceof C).transform(e=>new E(e)),vh.transform(e=>new E(e))]);static sort(e,r){return Number(e.valueOf()-r.valueOf())}},C=class N extends Et{constructor(e){typeof e=="number"&&(e=Math.trunc(e.valueOf())),le(e)&&(e=e.value),super(BigInt(e.valueOf()))}static fromSeconds(e){return e instanceof N?e:e instanceof vn?e.period:e instanceof _?new N(e):(le(e)&&(e=e.value),["number","bigint"].includes(typeof e)?N.seconds(e):new N(e))}static fromMilliseconds(e){return e instanceof N?e:e instanceof vn?e.period:e instanceof _?new N(e):(le(e)&&(e=e.value),["number","bigint"].includes(typeof e)?N.milliseconds(e):new N(e))}valueOf(){return this.value}lessThan(e){return this.valueOf()<new N(e).valueOf()}greaterThan(e){return this.valueOf()>new N(e).valueOf()}lessThanOrEqual(e){return this.valueOf()<=new N(e).valueOf()}greaterThanOrEqual(e){return this.valueOf()>=new N(e).valueOf()}remainder(e){return $a(this,e)}truncate(e){return new N(BigInt(Math.trunc(Number(this.valueOf()/e.valueOf())))*e.valueOf())}toString(e="full"){if(e==="semantic")return this.toSemanticString();const r=this.truncate(N.DAY),n=this.truncate(N.HOUR),s=this.truncate(N.MINUTE),a=this.truncate(N.SECOND),o=this.truncate(N.MILLISECOND),c=this.truncate(N.MICROSECOND),l=this.truncate(N.NANOSECOND),u=r,h=n.sub(r),d=s.sub(n),f=a.sub(s),v=o.sub(a),S=c.sub(o),Z=l.sub(c);let b="";return u.isZero||(b+=`${u.days}d `),h.isZero||(b+=`${h.hours}h `),d.isZero||(b+=`${d.minutes}m `),f.isZero||(b+=`${f.seconds}s `),v.isZero||(b+=`${v.milliseconds}ms `),S.isZero||(b+=`${S.microseconds}µs `),Z.isZero||(b+=`${Z.nanoseconds}ns`),b.trim()}toSemanticString(){const e=this.valueOf()<0n?-this.valueOf():this.valueOf(),r=new N(e),n=this.valueOf()<0n;if(r.valueOf()===0n)return"0s";if(r.lessThan(N.SECOND))return"< 1s";const s=r.days,a=r.hours,o=r.minutes,c=r.seconds,l=Math.floor(s/fi),u=Math.floor(s/gr),h=Math.floor(s/7),d=Math.floor(s),f=Math.floor(a),v=Math.floor(o),S=Math.floor(c),Z=n?"-":"";if(l>=1){let b=`${l}y`;if(l<2){const z=Math.floor(s%fi/gr);z>0&&(b+=` ${z}mo`)}return Z+b}if(h>=1&&s<gr&&s%7===0){let b=`${h}w`;const z=Math.floor(s%7),k=Math.floor(a-h*7*24);return h<2&&(z>0?b+=` ${z}d`:k>0&&k<24&&(b+=` ${k}h`)),Z+b}if(u>=1){let b=`${u}mo`;if(u<3){const z=Math.floor(s%gr);z>0&&(b+=` ${z}d`)}return Z+b}if(h>=1){let b=`${h}w`;const z=Math.floor(s%7),k=Math.floor(a-h*7*24);return h<2&&(z>0?b+=` ${z}d`:k>0&&k<24&&(b+=` ${k}h`)),Z+b}if(d>=1){let b=`${d}d`;const z=Math.floor(a-d*24);return d<2&&z>0&&(b+=` ${z}h`),Z+b}if(f>=1){let b=`${f}h`;if(f<3){const z=Math.floor(o-f*60);z>0&&(b+=` ${z}m`)}return Z+b}if(v>=1){let b=`${v}m`;if(v<5){const z=Math.floor(c-v*60);z>0&&(b+=` ${z}s`)}return Z+b}return`${Z}${S}s`}mult(e){return new N($e(this.valueOf(),e))}div(e){return new N(Vr(this.valueOf(),e))}get days(){return Number(this.valueOf())/Number(N.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(N.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(N.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(N.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(N.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(N.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get isZero(){return this.valueOf()===0n}equals(e){return this.valueOf()===new N(e).valueOf()}add(e){return new N(this.valueOf()+new N(e).valueOf())}sub(e){return new N(this.valueOf()-new N(e).valueOf())}static nanoseconds(e=1){return new N(e)}static NANOSECOND=N.nanoseconds(1);static microseconds(e=1){return N.nanoseconds($e(e,1e3))}static MICROSECOND=N.microseconds(1);static milliseconds(e=1){return N.microseconds($e(e,1e3))}static MILLISECOND=N.milliseconds(1);static seconds(e=1){return N.milliseconds($e(e,1e3))}static SECOND=N.seconds(1);static minutes(e=1){return N.seconds($e(e,60))}static MINUTE=N.minutes(1);static hours(e){return N.minutes($e(e,60))}static HOUR=N.hours(1);static days(e){return N.hours($e(e,24))}static DAY=N.days(1);static MAX=new N(Dn);static MIN=new N(0);static ZERO=new N(0);static z=i.z.union([i.z.object({value:i.z.bigint()}).transform(e=>new N(e.value)),i.z.string().transform(e=>new N(BigInt(e))),i.z.number().transform(e=>new N(e)),i.z.bigint().transform(e=>new N(e)),i.z.instanceof(N),i.z.instanceof(_).transform(e=>new N(e)),i.z.custom(e=>e instanceof vn).transform(e=>new N(e))])},vn=class ue extends Et{constructor(e){le(e)&&(e=e.value),super(e.valueOf())}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new ue(e).valueOf()}get period(){return C.seconds(1/this.valueOf())}sampleCount(e){return new C(e).seconds*this.valueOf()}byteCount(e,r){return this.sampleCount(e)*new te(r).valueOf()}span(e){return C.seconds(e/this.valueOf())}byteSpan(e,r){return this.span(e.valueOf()/new te(r).valueOf())}add(e){return new ue(Fr(this.valueOf(),new ue(e).valueOf()))}sub(e){return new ue(qr(this.valueOf(),new ue(e).valueOf()))}mult(e){return new ue($e(this.valueOf(),e))}div(e){return new ue(Vr(this.valueOf(),e))}static hz(e){return new ue(e)}static khz(e){return ue.hz(e*1e3)}static z=i.z.union([i.z.number().transform(e=>new ue(e)),i.z.instanceof(ue)])},te=class ne extends Et{constructor(e){le(e)&&(e=e.value),super(e.valueOf())}length(e){return e.valueOf()/this.valueOf()}size(e){return new Pn(e*this.valueOf())}add(e){return new ne(Fr(this.valueOf(),new ne(e).valueOf()))}sub(e){return new ne(qr(this.valueOf(),new ne(e).valueOf()))}mult(e){return new ne($e(this.valueOf(),e))}div(e){return new ne(Vr(this.valueOf(),e))}static UNKNOWN=new ne(0);static BIT128=new ne(16);static BIT64=new ne(8);static BIT32=new ne(4);static BIT16=new ne(2);static BIT8=new ne(1);static z=i.z.union([i.z.number().transform(e=>new ne(e)),i.z.instanceof(ne)])},Rt=class Ee{start;end;constructor(e,r){typeof e=="object"&&"start"in e?(this.start=new _(e.start),this.end=new _(e.end)):(this.start=new _(e),this.end=new _(r))}get span(){return new C(this.end.valueOf()-this.start.valueOf())}get isValid(){return this.start.valueOf()<=this.end.valueOf()}makeValid(){return this.isValid?this:this.swap()}get isZero(){return this.start.isZero&&this.end.isZero}get numeric(){return{start:Number(this.start.valueOf()),end:Number(this.end.valueOf())}}swap(){return new Ee(this.end,this.start)}get numericBounds(){return{lower:Number(this.start.valueOf()),upper:Number(this.end.valueOf())}}equals(e,r=C.ZERO){if(r.isZero)return this.start.equals(e.start)&&this.end.equals(e.end);let n=this.start.sub(e.start).valueOf(),s=this.end.sub(e.end).valueOf();return n<0&&(n=-n),s<0&&(s=-s),n<=r.valueOf()&&s<=r.valueOf()}toString(){return`${this.start.toString()} - ${this.end.toString()}`}toPrettyString(){return`${this.start.toString("preciseDate")} - ${this.span.toString()}`}overlapsWith(e,r=C.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 s=_.max(n.start,e.start),a=_.min(n.end,e.end);return a.before(s)?!1:new C(a.sub(s)).greaterThanOrEqual(r)}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 r=new Ee(this.start,this.end);return e.start.after(this.start)&&(r.start=e.start),e.start.after(this.end)&&(r.end=e.start),e.end.before(this.end)&&(r.end=e.end),e.end.before(this.start)&&(r.start=e.end),r}static max(...e){return new Ee(_.min(...e.map(r=>r.start)),_.max(...e.map(r=>r.end)))}static MAX=new Ee(_.MIN,_.MAX);static ZERO=new Ee(_.ZERO,_.ZERO);static z=i.z.union([i.z.object({start:_.z,end:_.z}).transform(e=>new Ee(e.start,e.end)),i.z.instanceof(Ee)]);static sort(e,r){return _.sort(e.start,r.start)||_.sort(e.end,r.end)}static simplify(e){return e.map(r=>r.makeValid()).sort((r,n)=>Ee.sort(r,n)).reduce((r,n)=>{if(n.span.isZero)return r;if(r.length===0)return r.push(n),r;const s=r[r.length-1];return s.overlapsWith(n)||s.end.equals(n.start)?s.end=_.max(s.end,n.end):r.push(n),r},[])}},B=class m extends Et{constructor(e){if(le(e)&&(e=e.value),e instanceof m||typeof e=="string"||typeof e.valueOf()=="string")super(e.valueOf());else{const r=m.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);if(r==null)throw new Error(`unable to find data type for ${e.toString()}`);super(r.valueOf())}}get Array(){const e=m.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(r=>this.equals(r))}toString(e=!1){return e?m.SHORT_STRINGS.get(this.valueOf())??this.valueOf():this.valueOf()}get isVariable(){return this.equals(m.JSON)||this.equals(m.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(m.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=m.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}get isUnsignedInteger(){return this.equals(m.UINT8)||this.equals(m.UINT16)||this.equals(m.UINT32)||this.equals(m.UINT64)}get isSignedInteger(){return this.equals(m.INT8)||this.equals(m.INT16)||this.equals(m.INT32)||this.equals(m.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(m.INT32)&&e.equals(m.FLOAT64)||this.equals(m.INT8)&&e.equals(m.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 m.BIG_INT_TYPES.some(e=>e.equals(this))}static UNKNOWN=new m("unknown");static FLOAT64=new m("float64");static FLOAT32=new m("float32");static INT64=new m("int64");static INT32=new m("int32");static INT16=new m("int16");static INT8=new m("int8");static UINT64=new m("uint64");static UINT32=new m("uint32");static UINT16=new m("uint16");static UINT8=new m("uint8");static BOOLEAN=new m("boolean");static TIMESTAMP=new m("timestamp");static UUID=new m("uuid");static STRING=new m("string");static JSON=new m("json");static ARRAY_CONSTRUCTORS=new Map([[m.UINT8.toString(),Uint8Array],[m.UINT16.toString(),Uint16Array],[m.UINT32.toString(),Uint32Array],[m.UINT64.toString(),BigUint64Array],[m.FLOAT32.toString(),Float32Array],[m.FLOAT64.toString(),Float64Array],[m.INT8.toString(),Int8Array],[m.INT16.toString(),Int16Array],[m.INT32.toString(),Int32Array],[m.INT64.toString(),BigInt64Array],[m.TIMESTAMP.toString(),BigInt64Array],[m.STRING.toString(),Uint8Array],[m.JSON.toString(),Uint8Array],[m.UUID.toString(),Uint8Array]]);static ARRAY_CONSTRUCTOR_DATA_TYPES=new Map([[Uint8Array.name,m.UINT8],[Uint16Array.name,m.UINT16],[Uint32Array.name,m.UINT32],[BigUint64Array.name,m.UINT64],[Float32Array.name,m.FLOAT32],[Float64Array.name,m.FLOAT64],[Int8Array.name,m.INT8],[Int16Array.name,m.INT16],[Int32Array.name,m.INT32],[BigInt64Array.name,m.INT64]]);static DENSITIES=new Map([[m.UINT8.toString(),te.BIT8],[m.UINT16.toString(),te.BIT16],[m.UINT32.toString(),te.BIT32],[m.UINT64.toString(),te.BIT64],[m.FLOAT32.toString(),te.BIT32],[m.FLOAT64.toString(),te.BIT64],[m.INT8.toString(),te.BIT8],[m.INT16.toString(),te.BIT16],[m.INT32.toString(),te.BIT32],[m.INT64.toString(),te.BIT64],[m.TIMESTAMP.toString(),te.BIT64],[m.STRING.toString(),te.UNKNOWN],[m.JSON.toString(),te.UNKNOWN],[m.UUID.toString(),te.BIT128]]);static ALL=[m.UNKNOWN,m.FLOAT64,m.FLOAT32,m.INT64,m.INT32,m.INT16,m.INT8,m.UINT64,m.UINT32,m.UINT16,m.UINT8,m.TIMESTAMP,m.UUID,m.STRING,m.JSON];static SHORT_STRINGS=new Map([[m.UINT8.toString(),"u8"],[m.UINT16.toString(),"u16"],[m.UINT32.toString(),"u32"],[m.UINT64.toString(),"u64"],[m.INT8.toString(),"i8"],[m.INT16.toString(),"i16"],[m.INT32.toString(),"i32"],[m.INT64.toString(),"i64"],[m.FLOAT32.toString(),"f32"],[m.FLOAT64.toString(),"f64"],[m.BOOLEAN.toString(),"bool"],[m.TIMESTAMP.toString(),"ts"],[m.UUID.toString(),"uuid"],[m.STRING.toString(),"str"],[m.JSON.toString(),"json"]]);static BIG_INT_TYPES=[m.INT64,m.UINT64,m.TIMESTAMP];static z=i.z.union([i.z.string().transform(e=>new m(e)),i.z.instanceof(m)])},Pn=class A extends Et{constructor(e){le(e)&&(e=e.value),super(e.valueOf())}largerThan(e){return le(e)&&(e=e.value),this.valueOf()>e.valueOf()}smallerThan(e){return le(e)&&(e=e.value),this.valueOf()<e.valueOf()}add(e){return le(e)&&(e=e.value),new A(Fr(this.valueOf(),e.valueOf()))}sub(e){return le(e)&&(e=e.value),new A(qr(this.valueOf(),e.valueOf()))}mult(e){return new A($e(this.valueOf(),e))}div(e){return new A(Vr(this.valueOf(),e))}truncate(e){return new A(Math.trunc(this.valueOf()/new A(e).valueOf())*new A(e).valueOf())}remainder(e){return A.bytes(this.valueOf()%new A(e).valueOf())}get gigabytes(){return this.valueOf()/A.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/A.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/A.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/A.TERABYTE.valueOf()}toString(){const e=this.truncate(A.TERABYTE),r=this.truncate(A.GIGABYTE),n=this.truncate(A.MEGABYTE),s=this.truncate(A.KILOBYTE),a=this.truncate(A.BYTE),o=e,c=r.sub(e),l=n.sub(r),u=s.sub(n),h=a.sub(s);let d="";return o.isZero||(d+=`${o.terabytes}TB `),c.isZero||(d+=`${c.gigabytes}GB `),l.isZero||(d+=`${l.megabytes}MB `),u.isZero||(d+=`${u.kilobytes}KB `),(!h.isZero||d==="")&&(d+=`${h.valueOf()}B`),d.trim()}static bytes(e=1){return new A(e)}static BYTE=new A(1);static kilobytes(e=1){return A.bytes(new A(e).valueOf()*1e3)}static KILOBYTE=A.kilobytes(1);static megabytes(e=1){return A.kilobytes(new A(e).valueOf()*1e3)}static MEGABYTE=A.megabytes(1);static gigabytes(e=1){return A.megabytes(new A(e).valueOf()*1e3)}static GIGABYTE=A.gigabytes(1);static terabytes(e){return A.gigabytes(new A(e).valueOf()*1e3)}static TERABYTE=A.terabytes(1);static ZERO=new A(0);static z=i.z.union([i.z.number().transform(e=>new A(e)),i.z.instanceof(A)]);get isZero(){return this.valueOf()===0}};i.z.object({start:i.z.number(),end:i.z.number()});i.z.union([i.z.instanceof(Uint8Array),i.z.instanceof(Uint16Array),i.z.instanceof(Uint32Array),i.z.instanceof(BigUint64Array),i.z.instanceof(Float32Array),i.z.instanceof(Float64Array),i.z.instanceof(Int8Array),i.z.instanceof(Int16Array),i.z.instanceof(Int32Array),i.z.instanceof(BigInt64Array)]);const Sa=t=>{const e=typeof t;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||t instanceof _||t instanceof C||t instanceof Date},Th=(t,e,r,n=0)=>t.usesBigInt&&!e.usesBigInt?Number(r)-Number(n):!t.usesBigInt&&e.usesBigInt?BigInt(r.valueOf())-BigInt(n.valueOf()):$r(r,-n),$r=(t,e)=>e==0?t:t==0?e:typeof t=="bigint"&&typeof e=="bigint"||typeof t=="number"&&typeof e=="number"?t+e:Number(t)+Number(e),zh=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;function Eh(t){return typeof t=="string"&&zh.test(t)}const K=[];for(let t=0;t<256;++t)K.push((t+256).toString(16).slice(1));function Nh(t,e=0){return(K[t[e+0]]+K[t[e+1]]+K[t[e+2]]+K[t[e+3]]+"-"+K[t[e+4]]+K[t[e+5]]+"-"+K[t[e+6]]+K[t[e+7]]+"-"+K[t[e+8]]+K[t[e+9]]+"-"+K[t[e+10]]+K[t[e+11]]+K[t[e+12]]+K[t[e+13]]+K[t[e+14]]+K[t[e+15]]).toLowerCase()}function Oh(t,e=0){const r=Nh(t,e);if(!Eh(r))throw TypeError("Stringified UUID is invalid");return r}typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const Ia=(t,e)=>Oh(t,e),Re=-1,$h=i.z.string().transform(t=>new Uint8Array(atob(t).split("").map(e=>e.charCodeAt(0))).buffer),Sh=i.z.union([i.z.null(),i.z.undefined()]).transform(()=>new Uint8Array().buffer),Un=10,Ih=(t,e)=>{if(t==="number"&&!e.isNumeric)throw new Error(`cannot convert series of type ${e.toString()} to number`);if(t==="bigint"&&!e.usesBigInt)throw new Error(`cannot convert series of type ${e.toString()} to bigint`)},ka="sy_x_telem_series";let Aa=class De{key;discriminator=ka;dataType;sampleOffset;gl;_data;timeRange=Rt.ZERO;alignment=0n;alignmentMultiple=1n;cachedMin;cachedMax;writePos=Re;_refCount=0;cachedLength;_cachedIndexes;static crudeZ=i.z.object({timeRange:Rt.z.optional(),dataType:B.z,alignment:i.z.coerce.bigint().optional(),data:i.z.union([$h,Sh,i.z.instanceof(ArrayBuffer),i.z.instanceof(Uint8Array)]),glBufferUsage:bh.optional().default("static").optional()});static z=De.crudeZ.transform(e=>new De(e));constructor(e){kh(e)&&(e={data:e}),e.data??=[];const{dataType:r,timeRange:n,sampleOffset:s=0,glBufferUsage:a="static",alignment:o=0n,alignmentMultiple:c=1n,key:l=mh(),data:u}=e;if(Ah(u)){const f=u;this.key=f.key,this.dataType=f.dataType,this.sampleOffset=f.sampleOffset,this.gl=f.gl,this._data=f._data,this.timeRange=f.timeRange,this.alignment=f.alignment,this.alignmentMultiple=f.alignmentMultiple,this.cachedMin=f.cachedMin,this.cachedMax=f.cachedMax,this.writePos=f.writePos,this._refCount=f._refCount,this.cachedLength=f.cachedLength;return}const h=Sa(u),d=Array.isArray(u);if(r!=null)this.dataType=new B(r);else{if(u 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 f=u;if(!h){if(u.length===0)throw new Error("cannot infer data type from a zero length JS array when constructing a Series. Please provide a data type.");f=u[0]}if(typeof f=="string")this.dataType=B.STRING;else if(typeof f=="number")this.dataType=B.FLOAT64;else if(typeof f=="bigint")this.dataType=B.INT64;else if(typeof f=="boolean")this.dataType=B.BOOLEAN;else if(f instanceof _||f instanceof Date||f instanceof _)this.dataType=B.TIMESTAMP;else if(typeof f=="object")this.dataType=B.JSON;else throw new Error(`cannot infer data type of ${typeof f} when constructing a Series from a JS array`)}else this.dataType=new B(u)}if(!d&&!h)this._data=u;else if(d&&u.length===0)this._data=new this.dataType.Array([]).buffer;else{let f=h?[u]:u;const v=f[0];(v instanceof _||v instanceof Date||v instanceof C)&&(f=f.map(S=>new _(S).valueOf())),this.dataType.equals(B.STRING)?(this.cachedLength=f.length,this._data=new TextEncoder().encode(`${f.join(`
|
|
2
2
|
`)}
|
|
3
|
-
`).buffer):this.dataType.equals(
|
|
3
|
+
`).buffer):this.dataType.equals(B.JSON)?(this.cachedLength=f.length,this._data=new TextEncoder().encode(`${f.map(S=>Mn.encodeString(S)).join(`
|
|
4
4
|
`)}
|
|
5
|
-
`).buffer):this.dataType.usesBigInt&&typeof
|
|
6
|
-
`).slice(0,-1):Array.from(this).map(e=>e.toString())}parseJSON(e){if(!this.dataType.equals(U.JSON))throw new Error("cannot parse non-JSON series as JSON");return this.toStrings().map(t=>e.parse(Jr.decodeString(t)))}get byteCapacity(){return new Xr(this.underlyingData.byteLength)}get capacity(){return this.dataType.isVariable?this.byteCapacity.valueOf():this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===Ee?this.byteCapacity:this.dataType.isVariable?new Xr(this.writePos):this.dataType.density.size(this.writePos)}get length(){return this.cachedLength!=null?this.cachedLength:this.dataType.isVariable?this.calculateCachedLength():this.writePos===Ee?this.byteCapacity.valueOf()/this.dataType.density.valueOf():this.writePos}calculateCachedLength(){if(!this.dataType.isVariable)throw new Error("cannot calculate length of a non-variable length data type");let e=0;const t=[0];return this.data.forEach((n,i)=>{n===Qr&&(e++,t.push(i+1))}),this._cachedIndexes=t,this.cachedLength=e,e}convert(e,t=0){if(this.dataType.equals(e))return this;const n=new e.Array(this.length);for(let i=0;i<this.length;i++)n[i]=Jc(this.dataType,e,this.data[i],t);return new Se({data:n.buffer,dataType:e,timeRange:this.timeRange,sampleOffset:t,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment})}calcRawMax(){if(this.length===0)return-1/0;if(this.dataType.equals(U.TIMESTAMP))this.cachedMax=this.data[this.data.length-1];else if(this.dataType.usesBigInt){const e=this.data;this.cachedMax=e.reduce((t,n)=>t>n?t:n)}else{const e=this.data;this.cachedMax=e.reduce((t,n)=>t>n?t:n)}return this.cachedMax}get max(){return this.calcMax()}calcMax(){if(this.dataType.isVariable)throw new Error("cannot calculate maximum on a variable length data type");return this.writePos===0?-1/0:(this.cachedMax??=this.calcRawMax(),Xt(this.cachedMax,this.sampleOffset))}calcRawMin(){if(this.length===0)return 1/0;if(this.dataType.equals(U.TIMESTAMP))this.cachedMin=this.data[0];else if(this.dataType.usesBigInt){const e=this.data;this.cachedMin=e.reduce((t,n)=>t<n?t:n)}else{const e=this.data;this.cachedMin=e.reduce((t,n)=>t<n?t:n)}return this.cachedMin}get min(){return this.calcMin()}calcMin(){if(this.dataType.isVariable)throw new Error("cannot calculate minimum on a variable length data type");return this.writePos===0?1/0:(this.cachedMin??=this.calcRawMin(),Xt(this.cachedMin,this.sampleOffset))}get bounds(){return De(Number(this.min),Number(this.max),{makeValid:!1})}maybeRecomputeMinMax(e){if(this.cachedMin!=null){const t=e.cachedMin??e.calcRawMin();t<this.cachedMin&&(this.cachedMin=t)}if(this.cachedMax!=null){const t=e.cachedMax??e.calcRawMax();t>this.cachedMax&&(this.cachedMax=t)}}atAlignment(e,t){const n=Number((e-this.alignment)/this.alignmentMultiple);if(n<0||n>=this.length){if(t===!0)throw new Error(`[series] - no value at index ${n}`);return}return this.at(n,t)}at(e,t=!1){if(this.dataType.isVariable)return this.atVariable(e,t??!1);if(this.dataType.equals(U.UUID))return this.atUUID(e,t);e<0&&(e=this.length+e);const n=this.data[e];if(n==null){if(t===!0)throw new Error(`[series] - no value at index ${e}`);return}return Xt(n,this.sampleOffset)}atUUID(e,t){e<0&&(e=this.length+e);const n=ni(new Uint8Array(this.buffer,e*this.dataType.density.valueOf()));if(n==null){if(t)throw new Error(`[series] - no value at index ${e}`);return}return n}atVariable(e,t){let n=0,i=0;if(this._cachedIndexes!=null)n=this._cachedIndexes[e],i=this._cachedIndexes[e+1]-1;else{e<0&&(e=this.length+e);for(let o=0;o<this.data.length;o++)if(this.data[o]===Qr){if(e===0){i=o;break}n=o+1,e--}if(i===0&&(i=this.data.length),n>=i||e>0){if(t)throw new Error(`[series] - no value at index ${e}`);return}}const a=this.data.slice(n,i);return this.dataType.equals(U.STRING)?new TextDecoder().decode(a):Vs(JSON.parse(new TextDecoder().decode(a)))}binarySearch(e){let t=0,n=this.length-1;const i=yc(e);for(;t<=n;){const a=Math.floor((t+n)/2),o=i(this.at(a,!0),e);if(o===0)return a;o<0?t=a+1:n=a-1}return t}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals(U.FLOAT32)&&!this.dataType.equals(U.UINT8))throw new Error("Only FLOAT32 and UINT8 arrays can be used in WebGL");const{buffer:t,bufferUsage:n,prevBuffer:i}=this.gl;if(t==null&&(this.gl.buffer=e.createBuffer()),this.writePos!==i)if(e.bindBuffer(e.ARRAY_BUFFER,this.gl.buffer),this.writePos!==Ee){i===0&&e.bufferData(e.ARRAY_BUFFER,this.byteCapacity.valueOf(),e.STATIC_DRAW);const a=this.dataType.density.size(i).valueOf(),o=this.underlyingData.slice(this.gl.prevBuffer,this.writePos);e.bufferSubData(e.ARRAY_BUFFER,a,o.buffer),this.gl.prevBuffer=this.writePos}else e.bufferData(e.ARRAY_BUFFER,this.buffer,n==="static"?e.STATIC_DRAW:e.DYNAMIC_DRAW),this.gl.prevBuffer=Ee}as(e){return sl(e,this.dataType),this}get digest(){return{key:this.key,dataType:this.dataType.toString(),sampleOffset:this.sampleOffset,alignment:{lower:hs(this.alignmentBounds.lower),upper:hs(this.alignmentBounds.upper),multiple:this.alignmentMultiple},timeRange:this.timeRange.toString(),length:this.length,capacity:this.capacity}}get alignmentBounds(){return De(this.alignment,this.alignment+BigInt(this.length)*this.alignmentMultiple)}maybeGarbageCollectGLBuffer(e){this.gl.buffer!=null&&(e.deleteBuffer(this.gl.buffer),this.gl.buffer=null,this.gl.prevBuffer=0,this.gl.control=null)}get glBuffer(){if(this.gl.buffer==null)throw new Error("gl buffer not initialized");return this.gl.prevBuffer!==this.writePos&&console.warn("buffer not updated"),this.gl.buffer}[Symbol.iterator](){if(this.dataType.isVariable){const e=new ol(this);return this.dataType.equals(U.JSON)?new cl(e):e}return this.dataType.equals(U.UUID)?new ll(this):new ul(this)}slice(e,t){return this.sliceSub(!1,e,t)}sub(e,t){return this.sliceSub(!0,e,t)}subIterator(e,t){return new us(this,e,t??this.length)}subAlignmentIterator(e,t){const n=Math.ceil(Number(e-this.alignment)/Number(this.alignmentMultiple)),i=Math.ceil(Number(t-this.alignment)/Number(this.alignmentMultiple));return new us(this,n,i)}subBytes(e,t){if(e>=0&&(t==null||t>=this.byteLength.valueOf()))return this;const n=this.data.subarray(e,t);return new Se({data:n,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(e)})}sliceSub(e,t,n){if(t<=0&&(n==null||n>=this.length))return this;let i;return e?i=this.data.subarray(t,n):i=this.data.slice(t,n),new Se({data:i,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(t)})}reAlign(e){return new Se({data:this.buffer,dataType:this.dataType,timeRange:dt.ZERO,sampleOffset:this.sampleOffset,glBufferUsage:"static",alignment:e})}toString(){let e=`Series(${this.dataType.toString()} ${this.length} [`;if(this.length<=10)e+=Array.from(this).map(t=>t.toString());else{for(let t=0;t<5;t++)e+=`${this.at(t)?.toString()}`,e+=",";e+="...,";for(let t=-5;t<0;t++)e+=this.at(t)?.toString(),t<-1&&(e+=",")}return e+="])",e}};const il=r=>r==null?!1:Array.isArray(r)||r instanceof ArrayBuffer||ArrayBuffer.isView(r)&&!(r instanceof DataView)||r instanceof ii?!0:ri(r),al=Wc(si,ii);let us=class{series;end;index;constructor(r,e,t){this.series=r;const n=De(0,r.length+1);this.end=as(n,t),this.index=as(n,e)}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}};class ol{series;index;decoder;constructor(e){if(!e.dataType.isVariable)throw new Error("cannot create a variable series iterator for a non-variable series");this.series=e,this.index=0,this.decoder=new TextDecoder}next(){const e=this.index,t=this.series.data;for(;this.index<t.length&&t[this.index]!==Qr;)this.index++;const n=this.index;return e===n?{done:!0,value:void 0}:(this.index++,{done:!1,value:this.decoder.decode(this.series.buffer.slice(e,n))})}}let cl=class ai{wrapped;static schema=s.z.record(s.z.string(),s.z.unknown());constructor(e){this.wrapped=e}next(){const e=this.wrapped.next();return e.done===!0?{done:!0,value:void 0}:{done:!1,value:Jr.decodeString(e.value,ai.schema)}}},ll=class{series;index;data;density;constructor(r){if(!r.dataType.equals(U.UUID))throw new Error("cannot create a UUID series iterator for a non-UUID series");this.series=r,this.index=0,this.data=new Uint8Array(r.buffer),this.density=U.UUID.density.valueOf()}next(){if(this.index>=this.series.length)return{done:!0,value:void 0};const r=ni(this.data,this.index*this.density);return this.index++,{done:!1,value:r}}};class ul{series;index;constructor(e){this.series=e,this.index=0}next(){return this.index>=this.series.length?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}}const hs=r=>{const e=r>>32n,t=r&0xffffffffn;return{domain:e,sample:t}};s.z.object({key:s.z.string(),value:s.z.string()});s.z.record(s.z.union([s.z.number(),s.z.string(),s.z.symbol()]),s.z.unknown());const hl=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser";hl();const fl=["macOS","Windows","Linux"],dl=["macos","windows","linux"],yl={macos:"macOS",windows:"Windows",linux:"Linux"};s.z.enum(fl).or(s.z.enum(dl).transform(r=>yl[r]));const gl=(...r)=>r.map(oi).join(""),oi=r=>(r.endsWith("/")||(r+="/"),r.startsWith("/")&&(r=r.slice(1)),r),pl=r=>r.endsWith("/")?r.slice(0,-1):r,ml=(r,e="")=>r===null?"":`?${Object.entries(r).filter(([,t])=>t==null?!1:Array.isArray(t)?t.length>0:!0).map(([t,n])=>`${e}${t}=${n}`).join("&")}`;let wl=class Qt{protocol;host;port;path;constructor({host:e,port:t,protocol:n="",pathPrefix:i=""}){this.protocol=n,this.host=e,this.port=t,this.path=oi(i)}replace(e){return new Qt({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new Qt({...this,pathPrefix:gl(this.path,e)})}toString(){return pl(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}static UNKNOWN=new Qt({host:"unknown",port:0})};const bl=async r=>await new Promise(e=>setTimeout(e,A.fromMilliseconds(r).milliseconds));class Tl{config;retries;interval;constructor(e){this.config={baseInterval:new A(e?.baseInterval??A.seconds(1)),maxRetries:e?.maxRetries??5,scale:e?.scale??1,sleepFn:e?.sleepFn??bl},this.retries=0,this.interval=new A(this.config.baseInterval)}async wait(){const{maxRetries:e,scale:t,sleepFn:n}=this.config;return this.retries>=e?!1:(await n(this.interval),this.interval=this.interval.mult(t),this.retries++,!0)}get retryMessage(){return`breaker triggered ${this.retries+1}/${this.config.maxRetries} times, retrying in ${this.interval.toString()}`}reset(){this.retries=0,this.interval=this.config.baseInterval}}const vl=s.z.object({baseInterval:A.z.optional(),maxRetries:s.z.number().optional(),scale:s.z.number().optional()}),El=Object.freeze(Object.defineProperty({__proto__:null,Breaker:Tl,breakerConfigZ:vl},Symbol.toStringTag,{value:"Module"})),Nl=/^#?([0-9a-f]{6}|[0-9a-f]{8})$/i,ci=s.z.string().regex(Nl),Ke=s.z.number().min(0).max(255),li=s.z.number().min(0).max(1),ui=s.z.tuple([Ke,Ke,Ke,li]),Ol=s.z.tuple([Ke,Ke,Ke]),zl=s.z.object({rgba255:ui}),Sl=s.z.number().min(0).max(360),Al=s.z.number().min(0).max(100),$l=s.z.number().min(0).max(100),Il=s.z.tuple([Sl,Al,$l,li]),On=s.z.union([ci,Ol,ui,Il,zl]),kl=On.transform(r=>zn(r)),zn=(r,e=1)=>{if(r=On.parse(r),typeof r=="string")return xl(r,e);if(Array.isArray(r)){if(r.length<3||r.length>4)throw new Error(`Invalid color: [${r.join(", ")}]`);return r.length===3?[...r,e]:r}return r.rgba255},xl=(r,e=1)=>(r=ci.parse(r),r=Cl(r),[Wt(r,0),Wt(r,2),Wt(r,4),r.length===8?Wt(r,6)/255:e]),Wt=(r,e)=>parseInt(r.slice(e,e+2),16),Cl=r=>r.startsWith("#")?r.slice(1):r;zn("#000000");zn("#ffffff");const Rl=s.z.object({key:s.z.string(),color:On,position:s.z.number(),switched:s.z.boolean().optional()});s.z.array(Rl);const jl=s.z.object({key:s.z.string(),name:s.z.string(),color:kl});s.z.object({key:s.z.string(),name:s.z.string(),swatches:s.z.array(jl)});s.z.int().min(0).max(255);s.z.object({name:s.z.string(),key:s.z.string()});const Ml=r=>Object.getOwnPropertySymbols(globalThis).includes(r),Ul=(r,e)=>{const t=Symbol.for(r);if(!Ml(t)){const n=e();Object.defineProperty(globalThis,t,{value:n})}return()=>globalThis[t]},hi="sy_x_error",Dl=r=>e=>e!=null&&typeof e=="object"&&"type"in e&&typeof e.type=="string"?e.type.startsWith(r):e instanceof Error?e.message.startsWith(r):typeof e!="string"?!1:e.startsWith(r),Rt=r=>class yt extends Error{static discriminator=hi;discriminator=yt.discriminator;static TYPE=r;type=yt.TYPE;static matches=Dl(r);matches=yt.matches;constructor(t,n){super(t,n),this.name=yt.TYPE}static sub(t){return Rt(`${r}.${t}`)}},fi=r=>{if(r==null||typeof r!="object")return!1;const e=r;if(e.discriminator!==hi)return!1;if(!("type"in e))throw new Error(`X Error is missing its type property: ${JSON.stringify(e)}`);return!0},He="unknown",en="nil";class Zl{providers=[];register(e){this.providers.push(e)}encode(e){if(e==null)return{type:en,data:""};if(fi(e))for(const t of this.providers){const n=t.encode(e);if(n!=null)return n}if(e instanceof Error)return{type:He,data:e.message};if(typeof e=="string")return{type:He,data:e};try{return{type:He,data:JSON.stringify(e)}}catch{return{type:He,data:"unable to encode error information"}}}decode(e){if(e==null||e.type===en)return null;if(e.type===He)return new tn(e.data);for(const t of this.providers){const n=t.decode(e);if(n!=null)return n}return new tn(e.data)}}const Sn=Ul("synnax-error-registry",()=>new Zl),Pl=({encode:r,decode:e})=>Sn().register({encode:r,decode:e}),Ll=r=>Sn().encode(r),Bl=r=>r==null?null:Sn().decode(r);let tn=class extends Rt("unknown"){};const ql=s.z.object({type:s.z.string(),data:s.z.string()});class Fl extends Rt("canceled"){}class Yl extends Rt("not_implemented"){}const $e=Object.freeze(Object.defineProperty({__proto__:null,Canceled:Fl,NONE:en,NotImplemented:Yl,UNKNOWN:He,Unknown:tn,createTyped:Rt,decode:Bl,encode:Ll,isTyped:fi,payloadZ:ql,register:Pl},Symbol.toStringTag,{value:"Module"})),Vl=s.object({jsonrpc:s.literal("2.0"),method:s.string(),params:s.any().optional(),id:s.union([s.string(),s.number(),s.null()]).optional()}),di=s.object({jsonrpc:s.literal("2.0"),id:s.union([s.string(),s.number(),s.null()])}),Hl=di.extend({result:s.json()}),_l=di.extend({error:s.object({code:s.number().int(),message:s.string().optional(),data:s.json().optional()})}),Wl=s.union([Hl,_l]);s.union([Vl,Wl]);s.z.string().regex(/^\d+\.\d+\.\d+$/);const Gl=["standard","scientific","engineering"];s.z.enum(Gl);s.z.enum(["success","info","warning","error","loading","disabled"]);let jt=class extends $e.createTyped("freighter"){},ie=class extends jt.sub("eof"){constructor(){super("EOF")}},Qe=class extends jt.sub("stream_closed"){constructor(){super("StreamClosed")}},Ie=class extends jt.sub("unreachable"){url;constructor(e={}){const{message:t="Unreachable",url:n=wl.UNKNOWN}=e;super(t),this.url=n}};const Kl=r=>{if(!r.type.startsWith(jt.TYPE))return null;if(ie.matches(r))return{type:ie.TYPE,data:"EOF"};if(Qe.matches(r))return{type:Qe.TYPE,data:"StreamClosed"};if(Ie.matches(r))return{type:Ie.TYPE,data:"Unreachable"};throw new Error(`Unknown error type: ${r.type}: ${r.message}`)},Jl=r=>{if(!r.type.startsWith(jt.TYPE))return null;switch(r.type){case ie.TYPE:return new ie;case Qe.TYPE:return new Qe;case Ie.TYPE:return new Ie;default:throw new $e.Unknown(`Unknown error type: ${r.data}`)}};$e.register({encode:Kl,decode:Jl});class yi{middleware=[];use(...e){this.middleware.push(...e)}async executeMiddleware(e,t){let n=0;const i=async a=>{if(n===this.middleware.length)return await t(a);const o=this.middleware[n];return n++,await o(a,i)};return await i(e)}}const gi="Content-Type",Xl=new Set(["ECONNREFUSED","ECONNRESET","ETIMEDOUT","EPIPE","UND_ERR_CONNECT_TIMEOUT","UND_ERR_SOCKET"]),Ql=r=>{const e=r?.cause?.code??r?.code??r?.errno;if(typeof e=="string"&&Xl.has(e))return!0;if(r.name==="TypeError"){const t=String(r.message||"").toLowerCase();if(/load failed|failed to fetch|networkerror|network error/.test(t))return!0}return r?.name==="AbortError"||r?.code,!1},eu=400;class tu extends yi{endpoint;encoder;constructor(e,t,n=!1){return super(),this.endpoint=e.replace({protocol:n?"https":"http"}),this.encoder=t,new Proxy(this,{get:(i,a,o)=>a==="endpoint"?this.endpoint:Reflect.get(i,a,o)})}get headers(){return{[gi]:this.encoder.contentType}}async send(e,t,n,i){t=n?.parse(t);let a=null;const o=this.endpoint.child(e),c={};c.method="POST",c.body=this.encoder.encode(t??{});const[,u]=await this.executeMiddleware({target:o.toString(),protocol:this.endpoint.protocol,params:{},role:"client"},async l=>{const h={...l,params:{}};c.headers={...this.headers,...l.params};let y;try{y=await fetch(l.target,c)}catch(N){if(!(N instanceof Error))throw N;return[h,Ql(N)?new Ie({url:o}):N]}const d=await y.arrayBuffer();if(y?.ok)return i!=null&&(a=this.encoder.decode(d,i)),[h,null];try{if(y.status!==eu)return[h,new Error(y.statusText)];const N=this.encoder.decode(d,$e.payloadZ),S=$e.decode(N);return[h,S]}catch(N){return[h,new Error(`[freighter] - failed to decode error: ${y.statusText}: ${N.message}`)]}});if(u!=null)return[null,u];if(a==null)throw new Error("Response must be defined");return[a,null]}}const ru=(r,e)=>{class t{wrapped;constructor(i){this.wrapped=i}use(...i){this.wrapped.use(...i)}async send(i,a,o,c){const u=new El.Breaker(e);do{const[l,h]=await this.wrapped.send(i,a,o,c);if(h==null)return[l,null];if(!Ie.matches(h))return[null,h];if(console.warn(`[freighter] ${u.retryMessage}`,h),!await u.wait())return[l,h]}while(!0)}}return new t(r)},m=async(r,e,t,n,i)=>{const[a,o]=await r.send(e,t,n,i);if(o!=null)throw o;return a},nu=s.z.object({type:s.z.enum(["data","close","open"]),payload:s.z.unknown(),error:s.z.optional($e.payloadZ)});class su{codec;reqSchema;resSchema;ws;serverClosed;sendClosed;receiveDataQueue=[];receiveCallbacksQueue=[];constructor(e,t,n,i){this.codec=t,this.reqSchema=n,this.resSchema=i,this.ws=e,this.sendClosed=!1,this.serverClosed=null,this.listenForMessages()}async receiveOpenAck(){const e=await this.receiveMsg();if(e.type!=="open"){if(e.error==null)throw new Error("Message error must be defined");return $e.decode(e.error)}return null}send(e){if(this.serverClosed!=null)return new ie;if(this.sendClosed)throw new Qe;return this.ws.send(this.codec.encode({type:"data",payload:e})),null}async receive(){if(this.serverClosed!=null)return[null,this.serverClosed];const e=await this.receiveMsg();if(e.type==="close"){if(e.error==null)throw new Error("Message error must be defined");if(this.serverClosed=$e.decode(e.error),this.serverClosed==null)throw new Error("Message error must be defined");return[null,this.serverClosed]}return[this.resSchema.parse(e.payload),null]}received(){return this.receiveDataQueue.length!==0}closeSend(){if(this.sendClosed||this.serverClosed!=null)return;const e={type:"close"};try{this.ws.send(this.codec.encode(e))}finally{this.sendClosed=!0}}async receiveMsg(){return this.receiveDataQueue.shift()??await new Promise((t,n)=>this.receiveCallbacksQueue.push({resolve:t,reject:n}))}addMessage(e){const t=this.receiveCallbacksQueue.shift();t!=null?t.resolve(e):this.receiveDataQueue.push(e)}listenForMessages(){this.ws.onmessage=this.onMessage.bind(this),this.ws.onclose=this.onClose.bind(this)}onMessage(e){this.addMessage(this.codec.decode(e.data,nu))}onClose(e){this.addMessage({type:"close",error:{type:e.code===au?ie.TYPE:Qe.TYPE,data:""}})}}const iu="freighterctx",au=1e3;class ar extends yi{baseUrl;encoder;secure;static MESSAGE_TYPE="arraybuffer";constructor(e,t,n=!1){super(),this.secure=n,this.baseUrl=e.replace({protocol:n?"wss":"ws"}),this.encoder=t}withCodec(e){const t=new ar(this.baseUrl,e,this.secure);return t.use(...this.middleware),t}async stream(e,t,n){let i;const[,a]=await this.executeMiddleware({target:e,protocol:"websocket",params:{},role:"client"},async o=>{const c=new WebSocket(this.buildURL(e,o)),u={...o,params:{}};c.binaryType=ar.MESSAGE_TYPE;const l=await this.wrapSocket(c,t,n);return l instanceof Error?[u,l]:(i=l,[u,null])});if(a!=null)throw a;return i}buildURL(e,t){const n=ml({[gi]:this.encoder.contentType,...t.params},iu);return this.baseUrl.child(e).toString()+n}async wrapSocket(e,t,n){return await new Promise(i=>{e.onopen=()=>{const a=new su(e,this.encoder,t,n);a.receiveOpenAck().then(o=>{o!=null?i(o):i(a)}).catch(o=>i(o))},e.onerror=a=>{const o=a;i(new Error(o.message))}})}}const ou=r=>Array.isArray(r)?r:r==null?[]:[r],v=Object.freeze(Object.defineProperty({__proto__:null,toArray:ou},Symbol.toStringTag,{value:"Module"})),cu=r=>{const e=r.replace(/_[a-z]/g,t=>t[1].toUpperCase());return e.length>1&&e[0]===e[0].toUpperCase()&&e[1]===e[1].toUpperCase()||e.length===0?e:e[0].toLowerCase()+e.slice(1)},gr=r=>{const e=(t,n=rn)=>{if(typeof t=="string")return r(t);if(Array.isArray(t))return t.map(o=>e(o,n));if(!Dr(t))return t;n=hu(n);const i={},a=t;return"toJSON"in a&&typeof a.toJSON=="function"?e(a.toJSON(),n):(Object.keys(a).forEach(o=>{let c=a[o];const u=r(o);n.recursive&&(Dr(c)?ds(c)||(c=e(c,n)):n.recursiveInArray&&fs(c)&&(c=[...c].map(l=>{let h=l;return Dr(l)?ds(h)||(h=e(l,n)):fs(l)&&(h=e({key:l},n).key),h}))),i[u]=c}),i)};return e},An=gr(cu),lu=r=>r.replace(/([a-z0-9])([A-Z])/g,(e,t,n)=>`${t}_${n.toLowerCase()}`),pi=gr(lu),mi=r=>r.length===0?r:r[0].toUpperCase()+r.slice(1),uu=[Number,String,Uint8Array],rn={recursive:!0,recursiveInArray:!0},hu=(r=rn)=>(r.recursive==null?r=rn:r.recursiveInArray??=!1,r),fs=r=>r!=null&&Array.isArray(r),Dr=r=>r!=null&&typeof r=="object"&&!Array.isArray(r),ds=r=>uu.some(e=>r instanceof e),fu=r=>r.replace(/\s+/g,"-").replace(/([a-z0-9])([A-Z])/g,(e,t,n)=>`${t}-${n.toLowerCase()}`).toLowerCase(),du=gr(fu),yu=r=>{if(r.length===0)return r;let e=r.replace(/[_-]/g," ");return e=e.replace(/([a-z0-9])([A-Z])/g,(t,n,i)=>`${n} ${i}`),e=e.replace(/([A-Z]+)([A-Z][a-z])/g,(t,n,i)=>`${n} ${i}`),e=e.replace(/\s+/g," ").trim(),e=e.replace(/\b\w/g,t=>t.toUpperCase()),e},gu=gr(yu),pu=Object.freeze(Object.defineProperty({__proto__:null,camelToSnake:pi,capitalize:mi,snakeToCamel:An,toKebab:du,toProperNoun:gu},Symbol.toStringTag,{value:"Module"})),wi=r=>r!=null&&typeof r=="object"&&!Array.isArray(r);let bi=class{contentType="application/json";decoder;encoder;constructor(){this.decoder=new TextDecoder,this.encoder=new TextEncoder}encode(e){return this.encoder.encode(this.encodeString(e))}decode(e,t){return this.decodeString(this.decoder.decode(e),t)}decodeString(e,t){const n=JSON.parse(e),i=An(n);return t!=null?t.parse(i):i}encodeString(e){const t=pi(e);return JSON.stringify(t,(n,i)=>ArrayBuffer.isView(i)?Array.from(i):typeof i=="bigint"?i.toString():i)}},Ti=class{contentType="text/csv";encode(e){const t=this.encodeString(e);return new TextEncoder().encode(t)}decode(e,t){const n=new TextDecoder().decode(e);return this.decodeString(n,t)}encodeString(e){if(!Array.isArray(e)||e.length===0||!wi(e[0]))throw new Error("Payload must be an array of objects");const t=Object.keys(e[0]),n=[t.join(",")];return e.forEach(i=>{const a=t.map(o=>JSON.stringify(i[o]??""));n.push(a.join(","))}),n.join(`
|
|
7
|
-
`)}decodeString(e,
|
|
8
|
-
`).map(c=>c.trim());if(n.length===0)return t!=null?t.parse({}):{};const a=n.split(",").map(c=>c.trim()),o={};return a.forEach(c=>{o[c]=[]}),i.forEach(c=>{const u=c.split(",").map(l=>l.trim());a.forEach((l,h)=>{const y=this.parseValue(u[h]);y!=null&&o[l].push(y)})}),t!=null?t.parse(o):o}parseValue(e){if(e==null||e.length===0)return null;const t=Number(e);return isNaN(t)?e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e:t}},vi=class{contentType="text/plain";encode(e){if(typeof e!="string")throw new Error("TextCodec.encode payload must be a string");return new TextEncoder().encode(e)}decode(e,t){const n=new TextDecoder().decode(e);return t!=null?t.parse(n):n}};const Tt=new bi,mu=new Ti,wu=new vi,bu=[Tt],Be=Object.freeze(Object.defineProperty({__proto__:null,CSVCodec:Ti,CSV_CODEC:mu,ENCODERS:bu,JSONCodec:bi,JSON_CODEC:Tt,TEXT_CODEC:wu,TextCodec:vi},Symbol.toStringTag,{value:"Module"})),nn=r=>[...new Set(r)],Tu=(r,e,t=!0)=>{const n=new Map;return r.forEach(i=>{const a=e(i);if(n.has(a)){if(t)return;n.delete(a)}n.set(a,i)}),Array.from(n.values())},ys=Object.freeze(Object.defineProperty({__proto__:null,by:Tu,unique:nn},Symbol.toStringTag,{value:"Module"})),Q=r=>r!=null&&typeof r=="object"&&"value"in r;let nt=class{value;constructor(e){this.value=e}valueOf(){return this.value}toJSON(){return this.value}toString(){return this.value.toString()}};const vu=r=>r!=null&&typeof r=="object"&&"toString"in r,pr=(r,e=!1)=>{const t=vu(r)?"stringer":typeof r;let n;switch(t){case"string":n=(i,a)=>i.localeCompare(a);break;case"stringer":n=(i,a)=>i.toString().localeCompare(a.toString());break;case"number":n=(i,a)=>Number(i)-Number(a);break;case"bigint":n=(i,a)=>BigInt(i)-BigInt(a)>0n?1:-1;break;case"boolean":n=(i,a)=>Number(i)-Number(a);break;case"undefined":n=()=>0;break;default:return console.warn(`sortFunc: unknown type ${t}`),()=>-1}return e?Ni(n):n},Eu=(r,e,t)=>{const n=pr(e[r],t);return(i,a)=>n(i[r],a[r])},Nu=(r,e)=>r.length!==e.length?r.length-e.length:r.every((t,n)=>t===e[n])?0:-1,Ei=(r,e)=>{if(r.length!==e.length)return r.length-e.length;if(r.length===0)return 0;const t=pr(r[0]),n=[...r].sort(t),i=[...e].sort(t);return n.every((a,o)=>a===i[o])?0:-1},Ou=(r,e)=>{const t=nn(r),n=nn(e);return Ei(t,n)},zu=(r,e)=>r===e?0:r==="first"&&e==="last"?1:-1,Ni=r=>(e,t)=>r(t,e),st=0,er=-1,tr=1,Oi=r=>r<st,zi=r=>r>st,Su=r=>r>=st,Si=r=>r===st,Au=(r,e)=>{const t=/([a-zA-Z]+)|(\d+)/g,n=r.replace(/[\s_.-]+/g,"").match(t),i=e.replace(/[\s_.-]+/g,"").match(t);if(!n||!i)return 0;for(let a=0;a<Math.min(n.length,i.length);a++){const o=n[a],c=i[a];if(isNaN(Number(o))&&isNaN(Number(c))){const u=o.localeCompare(c);if(u!==0)return u}else if(!isNaN(Number(o))&&!isNaN(Number(c))){const u=Number(o)-Number(c);if(u!==0)return u}else return isNaN(Number(o))?-1:1}return n.length-i.length},gs=Object.freeze(Object.defineProperty({__proto__:null,EQUAL:st,GREATER_THAN:tr,LESS_THAN:er,isEqualTo:Si,isGreaterThan:zi,isGreaterThanEqual:Su,isLessThan:Oi,newF:pr,newFieldF:Eu,order:zu,primitiveArrays:Nu,reverseF:Ni,stringsWithNumbers:Au,uniqueUnorderedPrimitiveArrays:Ou,unorderedPrimitiveArrays:Ei},Symbol.toStringTag,{value:"Module"})),mr=s.z.tuple([s.z.number(),s.z.number()]);s.z.tuple([s.z.bigint(),s.z.bigint()]);const Ai=s.z.object({width:s.z.number(),height:s.z.number()}),$u=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()}),Iu=["width","height"];s.z.enum(Iu);const ku=["start","center","end"],xu=["signedWidth","signedHeight"];s.z.enum(xu);const vt=s.z.object({x:s.z.number(),y:s.z.number()}),$i=s.z.object({clientX:s.z.number(),clientY:s.z.number()}),Ii=["x","y"],ki=s.z.enum(Ii),$n=["top","right","bottom","left"],Cu=s.z.enum($n),xi=["left","right"],In=s.z.enum(xi),Ci=["top","bottom"],kn=s.z.enum(Ci),xn=["center"],sn=s.z.enum(xn),Ru=[...$n,...xn],Cn=s.z.enum(Ru);s.z.enum(ku);const ju=["first","last"];s.z.enum(ju);const Mu=s.z.object({lower:s.z.number(),upper:s.z.number()}),Uu=s.z.object({lower:s.z.bigint(),upper:s.z.bigint()});s.z.union([Mu,mr]);s.z.union([Uu,mr]);s.z.enum([...ki.options,...Cn.options]);s.z.enum(["x","left","right"]);s.z.enum(["y","top","bottom"]);const Du=s.z.union([ki,Cn,s.z.instanceof(String)]),Mt=r=>(e,t)=>{if(typeof e=="bigint"){if(an(t))return r(e,BigInt(t));const n=r(Number(e),Number(t));return typeof n=="number"?BigInt(Math.round(n)):n}return r(Number(e),Number(t))},Ze=Mt((r,e)=>r-e),Ut=Mt((r,e)=>r+e),ps=(r,e)=>{const t=typeof r=="bigint",n=typeof e=="bigint";return t&&n?r===e:t&&an(e)?r===BigInt(e):n&&an(r)?e===BigInt(r):r===e},Zu=Mt((r,e)=>r<=e?r:e),an=r=>typeof r=="bigint"?!0:Number.isInteger(r),Pu=r=>typeof r=="bigint"?r<0n?-r:r:r<0?-r:r,ue=Mt((r,e)=>r*e),wr=Mt((r,e)=>r/e),V=(r,e,t)=>{const n={};if(typeof e=="object"&&(t=e,e=void 0),t={makeValid:!0,...t},typeof r=="number"||typeof r=="bigint")e!=null?(n.lower=r,n.upper=e):(n.lower=typeof r=="bigint"?0n:0,n.upper=r);else if(Array.isArray(r)){if(r.length!==2)throw new Error("bounds: expected array of length 2");[n.lower,n.upper]=r}else n.lower=r.lower,n.upper=r.upper;return t?.makeValid?Lu(n):n},Lu=r=>r.lower>r.upper?{lower:r.upper,upper:r.lower}:r,ms=(r,e)=>{const t=V(r);return e<t.lower?t.lower:e>=t.upper?t.upper-(typeof t.upper=="number"?1:1n):e},Gt=(r,e)=>{const t=V(r);if(typeof e=="number"||typeof e=="bigint")return e>=t.lower&&e<t.upper;const n=V(e);return n.lower>=t.lower&&n.upper<=t.upper},Bu=r=>({lower:Math.min(...r.map(e=>V(e).lower)),upper:Math.max(...r.map(e=>V(e).upper))}),qu=(r,e,t)=>{const n=r.map(c=>V(c)),i=t>0?1:t<0?-1:0;if(i===0)return e;let a=t,o=e;for(;ps(a,0)===!1;){const c=n.findIndex(u=>i>0?o>=u.lower&&o<u.upper:o>u.lower&&o<=u.upper);if(c!==-1){const u=n[c];let l;if(i>0?l=Ze(u.upper,o):l=Ze(o,u.lower),l>0){const h=Zu(Pu(a),l);if(o=Ut(o,i>0?h:-h),a=Ze(a,i>0?h:-h),ps(a,0))return o;continue}}if(i>0){const u=n.filter(l=>l.lower>o);if(u.length>0)o=u[0].lower;else return o}else{const u=n.filter(l=>l.upper<o);if(u.length>0)o=u[u.length-1].upper;else return o}}return o},Fu=(r,e,t)=>{const n=r.map(o=>V(o));if(e===t)return typeof e=="bigint"?0n:0;const i=e<t?V([e,t]):V([t,e]);let a=typeof e=="bigint"?0n:0;for(const o of n){const c=o.lower>i.lower?o.lower:i.lower,u=o.upper<i.upper?o.upper:i.upper;if(c<u){const l=u-c;a=a+l}}return a},Yu=In,Vu=kn,Hu=sn,_u={top:"bottom",right:"left",bottom:"top",left:"right",center:"center"},Wu={top:"left",right:"top",bottom:"right",left:"bottom",center:"center"},Gu=Du,ke=r=>r instanceof String||!Ii.includes(r)?r:r==="x"?"left":"top",Ku=r=>_u[ke(r)],Ju=r=>Wu[ke(r)],Et=r=>{const e=ke(r);return e==="top"||e==="bottom"?"y":"x"},Xu=s.z.object({x:In.or(sn),y:kn.or(sn)}),Ri=s.z.object({x:In,y:kn}),Rn=Object.freeze({x:"left",y:"top"}),ji=Object.freeze({x:"right",y:"top"}),Mi=Object.freeze({x:"left",y:"bottom"}),Ui=Object.freeze({x:"right",y:"bottom"}),jn=Object.freeze({x:"center",y:"center"}),Di=Object.freeze({x:"center",y:"top"}),Zi=Object.freeze({x:"center",y:"bottom"}),Pi=Object.freeze({x:"right",y:"center"}),Li=Object.freeze({x:"left",y:"center"}),Qu=Object.freeze([Li,Pi,Di,Zi,Rn,ji,Mi,Ui,jn]),Bi=(r,e)=>r.x===e.x&&r.y===e.y,eh=(r,e)=>{if(typeof e=="object"){let t=!0;return"x"in e&&(r.x===e.x||(t=!1)),"y"in e&&(r.y===e.y||(t=!1)),t}return r.x===e||r.y===e},th=r=>[r.x,r.y],rr=r=>Et(ke(r))==="x",rh=r=>Et(ke(r))==="y",nh=r=>`${r.x}${mi(r.y)}`,sh=(r,e)=>{let t,n;if(typeof r=="object"&&"x"in r?(t=r.x,n=r.y):(t=ke(r),n=ke(e??r)),Et(t)===Et(n)&&t!=="center"&&n!=="center")throw new Error(`[XYLocation] - encountered two locations with the same direction: ${t.toString()} - ${n.toString()}`);const i={...jn};return t==="center"?rr(n)?[i.x,i.y]=[n,t]:[i.x,i.y]=[t,n]:n==="center"?rr(t)?[i.x,i.y]=[t,n]:[i.x,i.y]=[n,t]:rr(t)?[i.x,i.y]=[t,n]:[i.x,i.y]=[n,t],i},ih=Object.freeze(Object.defineProperty({__proto__:null,BOTTOM_CENTER:Zi,BOTTOM_LEFT:Mi,BOTTOM_RIGHT:Ui,CENTER:jn,CENTER_LEFT:Li,CENTER_LOCATIONS:xn,CENTER_RIGHT:Pi,OUTER_LOCATIONS:$n,TOP_CENTER:Di,TOP_LEFT:Rn,TOP_RIGHT:ji,XY_LOCATIONS:Qu,X_LOCATIONS:xi,Y_LOCATIONS:Ci,center:Hu,construct:ke,constructXY:sh,corner:Ri,crude:Gu,direction:Et,isX:rr,isY:rh,location:Cn,outer:Cu,rotate90:Ju,swap:Ku,x:Yu,xy:Xu,xyCouple:th,xyEquals:Bi,xyMatches:eh,xyToString:nh,y:Vu},Symbol.toStringTag,{value:"Module"})),on=s.z.union([s.z.number(),vt,mr,Ai,$u,$i]),R=(r,e)=>{if(typeof r=="string"){if(e===void 0)throw new Error("The y coordinate must be given.");return r==="x"?{x:e,y:0}:{x:0,y:e}}return typeof r=="number"?{x:r,y:e??r}:Array.isArray(r)?{x:r[0],y:r[1]}:"signedWidth"in r?{x:r.signedWidth,y:r.signedHeight}:"clientX"in r?{x:r.clientX,y:r.clientY}:"width"in r?{x:r.width,y:r.height}:{x:r.x,y:r.y}},Le=Object.freeze({x:0,y:0}),ah=Object.freeze({x:1,y:1}),oh=Object.freeze({x:1/0,y:1/0}),ch=Object.freeze({x:NaN,y:NaN}),qi=(r,e,t=0)=>{const n=R(r),i=R(e);return t===0?n.x===i.x&&n.y===i.y:Math.abs(n.x-i.x)<=t&&Math.abs(n.y-i.y)<=t},lh=r=>qi(r,Le),Mn=(r,e,t)=>{const n=R(r),i=R(e,t);return{x:n.x*i.x,y:n.y*i.y}},Fi=(r,e)=>{const t=R(r);return{x:t.x+e,y:t.y}},Yi=(r,e)=>{const t=R(r);return{x:t.x,y:t.y+e}},Vi=(r,e,t,...n)=>{if(typeof e=="string"){if(typeof t!="number")throw new Error("The value must be a number.");return e==="x"?Fi(r,t):Yi(r,t)}if(typeof e=="object"&&"x"in e&&typeof e.x=="string"){const i=R(t),a=R(r);return e.x==="left"?i.x=-i.x:e.x==="center"&&(i.x=0),e.y==="top"?i.y=-i.y:e.y==="center"&&(i.y=0),{x:a.x+i.x,y:a.y+i.y}}return[r,e,t??Le,...n].reduce((i,a)=>{const o=R(a);return{x:i.x+o.x,y:i.y+o.y}},Le)},uh=(r,e,t)=>{const n=R(r);return e==="x"?{x:t,y:n.y}:{x:n.x,y:t}},hh=(r,e)=>{const t=R(r),n=R(e);return Math.sqrt((t.x-n.x)**2+(t.y-n.y)**2)},fh=(r,e)=>{const t=R(r),n=R(e);return{x:n.x-t.x,y:n.y-t.y}},dh=r=>{const e=R(r);return Number.isNaN(e.x)||Number.isNaN(e.y)},yh=r=>{const e=R(r);return Number.isFinite(e.x)&&Number.isFinite(e.y)},gh=r=>{const e=R(r);return[e.x,e.y]},ph=r=>{const e=R(r);return{left:e.x,top:e.y}},mh=(r,e=0)=>{const t=R(r);return{x:Number(t.x.toFixed(e)),y:Number(t.y.toFixed(e))}},gt=(r,e)=>{const t=R(r),n=R(e);return{x:t.x-n.x,y:t.y-n.y}},pt=r=>{const e=R(r),t=Math.hypot(e.x,e.y);return t===0?{x:0,y:0}:{x:-e.y/t,y:e.x/t}},Hi=r=>{const e=R(r),t=Math.hypot(e.x,e.y);return t===0?{x:0,y:0}:{x:e.x/t,y:e.y/t}},_i=(...r)=>{const e=r.reduce((t,n)=>Vi(t,n),Le);return Mn(e,1/r.length)},wh=(r,e)=>{const t=[];for(let n=0;n<r.length;n++){const i=r[n];let a,o,c,u;if(n===0){const l=r[n+1],h=gt(l,i);o=pt(h),c=o,u=e}else if(n===r.length-1){const l=r[n-1],h=gt(i,l);a=pt(h),c=a,u=e}else{const l=r[n-1],h=r[n+1],y=gt(i,l),d=gt(h,i);a=pt(y),o=pt(d);const N=Math.acos((y.x*d.x+y.y*d.y)/(Math.hypot(y.x,y.y)*Math.hypot(d.x,d.y))),S=Math.sin(N/2);S===0?u=e:u=e/S,c=Hi(_i(a,o))}t.push(Mn(c,u))}return t},bh=r=>{const e=R(r);return{x:e.y,y:e.x}},Th=r=>{const e=R(r);return{x:Math.round(e.x),y:Math.round(e.y)}},Wi=Object.freeze(Object.defineProperty({__proto__:null,INFINITY:oh,NAN:ch,ONE:ah,ZERO:Le,average:_i,calculateMiters:wh,clientXY:$i,construct:R,couple:gh,crudeZ:on,css:ph,distance:hh,equals:qi,isFinite:yh,isNan:dh,isZero:lh,normal:pt,normalize:Hi,round:Th,scale:Mn,set:uh,sub:gt,swap:bh,translate:Vi,translateX:Fi,translateY:Yi,translation:fh,truncate:mh,xy:vt},Symbol.toStringTag,{value:"Module"})),Kt=s.z.union([s.z.number(),s.z.string()]);s.z.object({top:Kt,left:Kt,width:Kt,height:Kt});s.z.object({left:s.z.number(),top:s.z.number(),right:s.z.number(),bottom:s.z.number()});s.z.object({one:vt,two:vt,root:Ri});const Un=(r,e,t=0,n=0,i)=>{const a={one:{...Le},two:{...Le},root:i??Rn};if(typeof r=="number"){if(typeof e!="number")throw new Error("Box constructor called with invalid arguments");return a.one={x:r,y:e},a.two={x:a.one.x+t,y:a.one.y+n},a}return"one"in r&&"two"in r&&"root"in r?{...r,root:i??r.root}:("getBoundingClientRect"in r&&(r=r.getBoundingClientRect()),"left"in r?(a.one={x:r.left,y:r.top},a.two={x:r.right,y:r.bottom},a):(a.one=r,e==null?a.two={x:a.one.x+t,y:a.one.y+n}:typeof e=="number"?a.two={x:a.one.x+e,y:a.one.y+t}:"width"in e?a.two={x:a.one.x+e.width,y:a.one.y+e.height}:"signedWidth"in e?a.two={x:a.one.x+e.signedWidth,y:a.one.y+e.signedHeight}:a.two=e,a))},Zr=r=>{const e=Un(r);return{lower:e.one.x,upper:e.two.x}},Pr=r=>{const e=Un(r);return{lower:e.one.y,upper:e.two.y}},vh=r=>typeof r!="object"||r==null?!1:"one"in r&&"two"in r&&"root"in r,Eh=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()});s.z.union([Ai,Eh,vt,mr]);const Nh=(r,e,t)=>e!==void 0&&r<e?e:t!==void 0&&r>t?t:r;s.z.object({offset:on,scale:on});s.z.object({offset:s.z.number(),scale:s.z.number()});const Oh=r=>(e,t,n,i)=>t==="dimension"?[e,n]:[e,i?n-r:n+r],zh=r=>(e,t,n,i)=>[e,i?n/r:n*r],Sh=r=>(e,t,n)=>{if(e===null)return[r,n];const{lower:i,upper:a}=e,{lower:o,upper:c}=r,u=a-i,l=c-o;if(t==="dimension")return[r,n*(l/u)];const h=(n-i)*(l/u)+o;return[r,h]},Ah=r=>(e,t,n)=>[r,n],$h=()=>(r,e,t)=>{if(r===null)throw new Error("cannot invert without bounds");if(e==="dimension")return[r,t];const{lower:n,upper:i}=r;return[r,i-(t-n)]},Ih=r=>(e,t,n)=>{const{lower:i,upper:a}=r;return n=Nh(n,i,a),[e,n]};let ws=class _e{ops=[];currBounds=null;currType=null;reversed=!1;constructor(){this.ops=[]}static translate(e){return new _e().translate(e)}static magnify(e){return new _e().magnify(e)}static scale(e,t){return new _e().scale(e,t)}translate(e){const t=this.new(),n=Oh(e);return n.type="translate",t.ops.push(n),t}magnify(e){const t=this.new(),n=zh(e);return n.type="magnify",t.ops.push(n),t}scale(e,t){const n=V(e,t),i=this.new(),a=Sh(n);return a.type="scale",i.ops.push(a),i}clamp(e,t){const n=V(e,t),i=this.new(),a=Ih(n);return a.type="clamp",i.ops.push(a),i}reBound(e,t){const n=V(e,t),i=this.new(),a=Ah(n);return a.type="re-bound",i.ops.push(a),i}invert(){const e=$h();e.type="invert";const t=this.new();return t.ops.push(e),t}pos(e){return this.exec("position",e)}dim(e){return this.exec("dimension",e)}new(){const e=new _e;return e.ops=this.ops.slice(),e.reversed=this.reversed,e}exec(e,t){return this.currBounds=null,this.ops.reduce(([n,i],a)=>a(n,e,i,this.reversed),[null,t])[1]}reverse(){const e=this.new();e.ops.reverse();const t=[];return e.ops.forEach((n,i)=>{if(n.type==="scale"||t.some(([o,c])=>i>=o&&i<=c))return;const a=e.ops.findIndex((o,c)=>o.type==="scale"&&c>i);a!==-1&&t.push([i,a])}),t.forEach(([n,i])=>{const a=e.ops.slice(n,i);a.unshift(e.ops[i]),e.ops.splice(n,i-n+1,...a)}),e.reversed=!e.reversed,e}get transform(){return{scale:this.dim(1),offset:this.pos(0)}}static IDENTITY=new _e},Lb=class ce{x;y;currRoot;constructor(e=new ws,t=new ws,n=null){this.x=e,this.y=t,this.currRoot=n}static translate(e,t){return new ce().translate(e,t)}static translateX(e){return new ce().translateX(e)}static translateY(e){return new ce().translateY(e)}static clamp(e){return new ce().clamp(e)}static magnify(e){return new ce().magnify(e)}static scale(e){return new ce().scale(e)}static reBound(e){return new ce().reBound(e)}translate(e,t){const n=R(e,t),i=this.copy();return i.x=this.x.translate(n.x),i.y=this.y.translate(n.y),i}translateX(e){const t=this.copy();return t.x=this.x.translate(e),t}translateY(e){const t=this.copy();return t.y=this.y.translate(e),t}magnify(e){const t=this.copy();return t.x=this.x.magnify(e.x),t.y=this.y.magnify(e.y),t}scale(e){const t=this.copy();if(vh(e)){const n=this.currRoot;return t.currRoot=e.root,n!=null&&!Bi(n,e.root)&&(n.x!==e.root.x&&(t.x=t.x.invert()),n.y!==e.root.y&&(t.y=t.y.invert())),t.x=t.x.scale(Zr(e)),t.y=t.y.scale(Pr(e)),t}return t.x=t.x.scale(e.width),t.y=t.y.scale(e.height),t}reBound(e){const t=this.copy();return t.x=this.x.reBound(Zr(e)),t.y=this.y.reBound(Pr(e)),t}clamp(e){const t=this.copy();return t.x=this.x.clamp(Zr(e)),t.y=this.y.clamp(Pr(e)),t}copy(){const e=new ce;return e.currRoot=this.currRoot,e.x=this.x,e.y=this.y,e}reverse(){const e=this.copy();return e.x=this.x.reverse(),e.y=this.y.reverse(),e}pos(e){return{x:this.x.pos(e.x),y:this.y.pos(e.y)}}dim(e){return{x:this.x.dim(e.x),y:this.y.dim(e.y)}}box(e){return Un(this.pos(e.one),this.pos(e.two),0,0,this.currRoot??e.root)}get transform(){return{scale:this.dim({x:1,y:1}),offset:this.pos({x:0,y:0})}}static IDENTITY=new ce},Gi=(r,e=21)=>(t=e)=>{let n="",i=t|0;for(;i--;)n+=r[Math.random()*r.length|0];return n};const Ki="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",kh=`0123456789${Ki}`,Ji=11,xh=Gi(Ki,1),Ch=Gi(kh,Ji-1),Dn=()=>`${xh()}${Ch()}`,Rh=Object.freeze(Object.defineProperty({__proto__:null,LENGTH:Ji,create:Dn},Symbol.toStringTag,{value:"Module"})),jh=(r,e)=>t=>t instanceof e||typeof t=="object"&&t!==null&&"discriminator"in t&&t.discriminator===r,Mh=s.z.enum(["static","dynamic"]),Uh=s.z.union([s.z.tuple([s.z.int()]),s.z.tuple([s.z.int(),s.z.int().min(1).max(12)]),s.z.tuple([s.z.int(),s.z.int().min(1).max(12),s.z.int().min(1).max(31)])]),Xi=(r,e)=>{const t=new f(e);if(![E.DAY,E.HOUR,E.MINUTE,E.SECOND,E.MILLISECOND,E.MICROSECOND,E.NANOSECOND].some(i=>i.equals(t)))throw new Error("Invalid argument for remainder. Must be an even TimeSpan or Timestamp");const n=r.valueOf()%t.valueOf();return r instanceof f?new f(n):new E(n)};class f extends nt{constructor(e,t="UTC"){if(e==null)super(f.now().valueOf());else if(e instanceof Date)super(BigInt(e.getTime())*f.MILLISECOND.valueOf());else if(typeof e=="string")super(f.parseDateTimeString(e,t).valueOf());else if(Array.isArray(e))super(f.parseDate(e));else{let n=0n;e instanceof Number&&(e=e.valueOf()),t==="local"&&(n=f.utcOffset.valueOf()),typeof e=="number"&&(isFinite(e)?e=Math.trunc(e):(isNaN(e)&&(e=0),e===1/0?e=f.MAX:e=f.MIN)),Q(e)&&(e=e.value),super(BigInt(e.valueOf())+n)}}static parseDate([e=1970,t=1,n=1]){const i=new Date(e,t-1,n,0,0,0,0);return new f(BigInt(i.getTime())*f.MILLISECOND.valueOf()).truncate(f.DAY).valueOf()}valueOf(){return this.value}static parseTimeString(e,t="UTC"){const[n,i,a]=e.split(":");let o="00",c="00";a!=null&&([o,c]=a.split("."));let u=f.hours(parseInt(n??"00")).add(f.minutes(parseInt(i??"00"))).add(f.seconds(parseInt(o??"00"))).add(f.milliseconds(parseInt(c??"00")));return t==="local"&&(u=u.add(f.utcOffset)),u.valueOf()}static parseDateTimeString(e,t="UTC"){if(!e.includes("/")&&!e.includes("-"))return f.parseTimeString(e,t);const n=new Date(e);return e.includes(":")||n.setUTCHours(0,0,0,0),new f(BigInt(n.getTime())*f.MILLISECOND.valueOf(),t).valueOf()}fString(e="ISO",t="UTC"){switch(e){case"ISODate":return this.toISOString(t).slice(0,10);case"ISOTime":return this.toISOString(t).slice(11,23);case"time":return this.timeString(!1,t);case"preciseTime":return this.timeString(!0,t);case"date":return this.dateString();case"preciseDate":return`${this.dateString()} ${this.timeString(!0,t)}`;case"dateTime":return`${this.dateString()} ${this.timeString(!1,t)}`;default:return this.toISOString(t)}}toISOString(e="UTC"){return e==="UTC"?this.date().toISOString():this.sub(f.utcOffset).date().toISOString()}timeString(e=!1,t="UTC"){const n=this.toISOString(t);return e?n.slice(11,23):n.slice(11,19)}dateString(){const e=this.date(),t=e.toLocaleString("default",{month:"short"}),n=e.toLocaleString("default",{day:"numeric"});return`${t} ${n}`}static get utcOffset(){return new E(BigInt(new Date().getTimezoneOffset())*f.MINUTE.valueOf())}static since(e){return new f().span(e)}date(){return new Date(this.milliseconds)}equals(e){return this.valueOf()===new f(e).valueOf()}span(e){return this.range(e).span}range(e){return new M(this,e).makeValid()}spanRange(e){return this.range(this.add(e)).makeValid()}get isZero(){return this.valueOf()===0n}after(e){return this.valueOf()>new f(e).valueOf()}afterEq(e){return this.valueOf()>=new f(e).valueOf()}before(e){return this.valueOf()<new f(e).valueOf()}beforeEq(e){return this.valueOf()<=new f(e).valueOf()}add(e){return new f(Ut(this.valueOf(),new E(e).valueOf()))}sub(e){return new f(Ze(this.valueOf(),new E(e).valueOf()))}get hours(){return Number(this.valueOf())/Number(E.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(E.MINUTE.valueOf())}get days(){return Number(this.valueOf())/Number(E.DAY.valueOf())}get seconds(){return Number(this.valueOf())/Number(E.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(f.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(f.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get year(){return this.date().getUTCFullYear()}setYear(e){const t=this.date();return t.setUTCFullYear(e),new f(t)}get month(){return this.date().getUTCMonth()}setMonth(e){const t=this.date();return t.setUTCMonth(e),new f(t)}get day(){return this.date().getUTCDate()}setDay(e){const t=this.date();return t.setUTCDate(e),new f(t)}get hour(){return this.date().getUTCHours()}get localHour(){return this.date().getHours()}setLocalHour(e){const t=this.date();return t.setHours(e),new f(t)}setHour(e){const t=this.date();return t.setUTCHours(e),new f(t)}get minute(){return this.date().getUTCMinutes()}setMinute(e){const t=this.date();return t.setUTCMinutes(e),new f(t)}get second(){return this.date().getUTCSeconds()}setSecond(e){const t=this.date();return t.setUTCSeconds(e),new f(t)}get millisecond(){return this.date().getUTCMilliseconds()}setMillisecond(e){const t=this.date();return t.setUTCMilliseconds(e),new f(t)}toString(){return this.date().toISOString()}remainder(e){return Xi(this,e)}get isToday(){return this.truncate(E.DAY).equals(f.now().truncate(E.DAY))}truncate(e){return this.sub(this.remainder(e))}static now(){return new f(new Date)}static max(...e){let t=f.MIN;for(const n of e){const i=new f(n);i.after(t)&&(t=i)}return t}static min(...e){let t=f.MAX;for(const n of e){const i=new f(n);i.before(t)&&(t=i)}return t}static nanoseconds(e,t="UTC"){return new f(e,t)}static NANOSECOND=f.nanoseconds(1);static microseconds(e,t="UTC"){return f.nanoseconds(e*1e3,t)}static MICROSECOND=f.microseconds(1);static milliseconds(e,t="UTC"){return f.microseconds(e*1e3,t)}static MILLISECOND=f.milliseconds(1);static seconds(e,t="UTC"){return f.milliseconds(e*1e3,t)}static SECOND=f.seconds(1);static minutes(e,t="UTC"){return f.seconds(e*60,t)}static MINUTE=f.minutes(1);static hours(e,t="UTC"){return f.minutes(e*60,t)}static HOUR=f.hours(1);static days(e,t="UTC"){return f.hours(e*24,t)}static DAY=f.days(1);static MAX=new f((1n<<63n)-1n);static MIN=new f(0);static ZERO=new f(0);static z=s.z.union([s.z.instanceof(f),s.z.object({value:s.z.bigint()}).transform(e=>new f(e.value)),s.z.string().transform(e=>new f(BigInt(e))),s.z.number().transform(e=>new f(e)),s.z.bigint().transform(e=>new f(e)),s.z.date().transform(e=>new f(e)),s.z.custom(e=>e instanceof E).transform(e=>new f(e)),Uh.transform(e=>new f(e))]);static sort(e,t){return Number(e.valueOf()-t.valueOf())}}let E=class T extends nt{constructor(e){typeof e=="number"&&(e=Math.trunc(e.valueOf())),Q(e)&&(e=e.value),super(BigInt(e.valueOf()))}static fromSeconds(e){return e instanceof T?e:e instanceof W?e.period:e instanceof f?new T(e):(Q(e)&&(e=e.value),["number","bigint"].includes(typeof e)?T.seconds(e):new T(e))}static fromMilliseconds(e){return e instanceof T?e:e instanceof W?e.period:e instanceof f?new T(e):(Q(e)&&(e=e.value),["number","bigint"].includes(typeof e)?T.milliseconds(e):new T(e))}valueOf(){return this.value}lessThan(e){return this.valueOf()<new T(e).valueOf()}greaterThan(e){return this.valueOf()>new T(e).valueOf()}lessThanOrEqual(e){return this.valueOf()<=new T(e).valueOf()}greaterThanOrEqual(e){return this.valueOf()>=new T(e).valueOf()}remainder(e){return Xi(this,e)}truncate(e){return new T(BigInt(Math.trunc(Number(this.valueOf()/e.valueOf())))*e.valueOf())}toString(){const e=this.truncate(T.DAY),t=this.truncate(T.HOUR),n=this.truncate(T.MINUTE),i=this.truncate(T.SECOND),a=this.truncate(T.MILLISECOND),o=this.truncate(T.MICROSECOND),c=this.truncate(T.NANOSECOND),u=e,l=t.sub(e),h=n.sub(t),y=i.sub(n),d=a.sub(i),N=o.sub(a),S=c.sub(o);let k="";return u.isZero||(k+=`${u.days}d `),l.isZero||(k+=`${l.hours}h `),h.isZero||(k+=`${h.minutes}m `),y.isZero||(k+=`${y.seconds}s `),d.isZero||(k+=`${d.milliseconds}ms `),N.isZero||(k+=`${N.microseconds}µs `),S.isZero||(k+=`${S.nanoseconds}ns`),k.trim()}mult(e){return new T(ue(this.valueOf(),e))}div(e){return new T(wr(this.valueOf(),e))}get days(){return Number(this.valueOf())/Number(T.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(T.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(T.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(T.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(T.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(T.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get isZero(){return this.valueOf()===0n}equals(e){return this.valueOf()===new T(e).valueOf()}add(e){return new T(this.valueOf()+new T(e).valueOf())}sub(e){return new T(this.valueOf()-new T(e).valueOf())}static nanoseconds(e=1){return new T(e)}static NANOSECOND=T.nanoseconds(1);static microseconds(e=1){return T.nanoseconds(ue(e,1e3))}static MICROSECOND=T.microseconds(1);static milliseconds(e=1){return T.microseconds(ue(e,1e3))}static MILLISECOND=T.milliseconds(1);static seconds(e=1){return T.milliseconds(ue(e,1e3))}static SECOND=T.seconds(1);static minutes(e=1){return T.seconds(ue(e,60))}static MINUTE=T.minutes(1);static hours(e){return T.minutes(ue(e,60))}static HOUR=T.hours(1);static days(e){return T.hours(ue(e,24))}static DAY=T.days(1);static MAX=new T((1n<<63n)-1n);static MIN=new T(0);static ZERO=new T(0);static z=s.z.union([s.z.object({value:s.z.bigint()}).transform(e=>new T(e.value)),s.z.string().transform(e=>new T(BigInt(e))),s.z.number().transform(e=>new T(e)),s.z.bigint().transform(e=>new T(e)),s.z.instanceof(T),s.z.instanceof(f).transform(e=>new T(e)),s.z.custom(e=>e instanceof W).transform(e=>new T(e))])};class W extends nt{constructor(e){Q(e)&&(e=e.value),super(e.valueOf())}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new W(e).valueOf()}get period(){return E.seconds(1/this.valueOf())}sampleCount(e){return new E(e).seconds*this.valueOf()}byteCount(e,t){return this.sampleCount(e)*new Y(t).valueOf()}span(e){return E.seconds(e/this.valueOf())}byteSpan(e,t){return this.span(e.valueOf()/new Y(t).valueOf())}add(e){return new W(Ut(this.valueOf(),new W(e).valueOf()))}sub(e){return new W(Ze(this.valueOf(),new W(e).valueOf()))}mult(e){return new W(ue(this.valueOf(),e))}div(e){return new W(wr(this.valueOf(),e))}static hz(e){return new W(e)}static khz(e){return W.hz(e*1e3)}static z=s.z.union([s.z.number().transform(e=>new W(e)),s.z.instanceof(W)])}let Y=class K extends nt{constructor(e){Q(e)&&(e=e.value),super(e.valueOf())}length(e){return e.valueOf()/this.valueOf()}size(e){return new et(e*this.valueOf())}add(e){return new K(Ut(this.valueOf(),new K(e).valueOf()))}sub(e){return new K(Ze(this.valueOf(),new K(e).valueOf()))}mult(e){return new K(ue(this.valueOf(),e))}div(e){return new K(wr(this.valueOf(),e))}static UNKNOWN=new K(0);static BIT128=new K(16);static BIT64=new K(8);static BIT32=new K(4);static BIT16=new K(2);static BIT8=new K(1);static z=s.z.union([s.z.number().transform(e=>new K(e)),s.z.instanceof(K)])},M=class ne{start;end;constructor(e,t){typeof e=="object"&&"start"in e?(this.start=new f(e.start),this.end=new f(e.end)):(this.start=new f(e),this.end=new f(t))}get span(){return new E(this.end.valueOf()-this.start.valueOf())}get isValid(){return this.start.valueOf()<=this.end.valueOf()}makeValid(){return this.isValid?this:this.swap()}get isZero(){return this.span.isZero}get numeric(){return{start:Number(this.start.valueOf()),end:Number(this.end.valueOf())}}swap(){return new ne(this.end,this.start)}get numericBounds(){return{lower:Number(this.start.valueOf()),upper:Number(this.end.valueOf())}}equals(e,t=E.ZERO){if(t.isZero)return this.start.equals(e.start)&&this.end.equals(e.end);let n=this.start.sub(e.start).valueOf(),i=this.end.sub(e.end).valueOf();return n<0&&(n=-n),i<0&&(i=-i),n<=t.valueOf()&&i<=t.valueOf()}toString(){return`${this.start.toString()} - ${this.end.toString()}`}toPrettyString(){return`${this.start.fString("preciseDate")} - ${this.span.toString()}`}overlapsWith(e,t=E.ZERO){e=e.makeValid();const n=this.makeValid();if(this.equals(e))return!0;if(e.end.equals(n.start)||n.end.equals(e.start))return!1;const i=f.max(n.start,e.start),a=f.min(n.end,e.end);return a.before(i)?!1:new E(a.sub(i)).greaterThanOrEqual(t)}contains(e){return e instanceof ne?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const t=new ne(this.start,this.end);return e.start.after(this.start)&&(t.start=e.start),e.start.after(this.end)&&(t.end=e.start),e.end.before(this.end)&&(t.end=e.end),e.end.before(this.start)&&(t.start=e.end),t}static max(...e){return new ne(f.min(...e.map(t=>t.start)),f.max(...e.map(t=>t.end)))}static MAX=new ne(f.MIN,f.MAX);static MIN=new ne(f.MAX,f.MIN);static ZERO=new ne(f.ZERO,f.ZERO);static z=s.z.union([s.z.object({start:f.z,end:f.z}).transform(e=>new ne(e.start,e.end)),s.z.instanceof(ne)]);static sort(e,t){return f.sort(e.start,t.start)||f.sort(e.end,t.end)}static simplify(e){return e.map(t=>t.makeValid()).sort((t,n)=>ne.sort(t,n)).reduce((t,n)=>{if(n.isZero)return t;if(t.length===0)return t.push(n),t;const i=t[t.length-1];return i.overlapsWith(n)||i.end.equals(n.start)?i.end=f.max(i.end,n.end):t.push(n),t},[])}},$=class p extends nt{constructor(e){if(Q(e)&&(e=e.value),e instanceof p||typeof e=="string"||typeof e.valueOf()=="string")super(e.valueOf());else{const t=p.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);if(t==null)throw new Error(`unable to find data type for ${e.toString()}`);super(t.valueOf())}}get Array(){const e=p.ARRAY_CONSTRUCTORS.get(this.toString());if(e==null)throw new Error(`unable to find array constructor for ${this.valueOf()}`);return e}equals(e){return this.valueOf()===e.valueOf()}matches(...e){return e.some(t=>this.equals(t))}toString(){return this.valueOf()}get isVariable(){return this.equals(p.JSON)||this.equals(p.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(p.UUID)}get isInteger(){const e=this.toString();return e.startsWith("int")||e.startsWith("uint")}get isFloat(){return this.toString().startsWith("float")}get density(){const e=p.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}get isUnsignedInteger(){return this.equals(p.UINT8)||this.equals(p.UINT16)||this.equals(p.UINT32)||this.equals(p.UINT64)}get isSignedInteger(){return this.equals(p.INT8)||this.equals(p.INT16)||this.equals(p.INT32)||this.equals(p.INT64)}canSafelyCastTo(e){return this.equals(e)?!0:!this.isNumeric||!e.isNumeric||this.isVariable||e.isVariable||this.isUnsignedInteger&&e.isSignedInteger?!1:this.isFloat?e.isFloat&&this.density.valueOf()<=e.density.valueOf():this.equals(p.INT32)&&e.equals(p.FLOAT64)||this.equals(p.INT8)&&e.equals(p.FLOAT32)?!0:this.isInteger&&e.isInteger?this.density.valueOf()<=e.density.valueOf()&&this.isUnsignedInteger===e.isUnsignedInteger:!1}canCastTo(e){return this.isNumeric&&e.isNumeric?!0:this.equals(e)}checkArray(e){return e.constructor===this.Array}get usesBigInt(){return p.BIG_INT_TYPES.some(e=>e.equals(this))}static UNKNOWN=new p("unknown");static FLOAT64=new p("float64");static FLOAT32=new p("float32");static INT64=new p("int64");static INT32=new p("int32");static INT16=new p("int16");static INT8=new p("int8");static UINT64=new p("uint64");static UINT32=new p("uint32");static UINT16=new p("uint16");static UINT8=new p("uint8");static BOOLEAN=this.UINT8;static TIMESTAMP=new p("timestamp");static UUID=new p("uuid");static STRING=new p("string");static JSON=new p("json");static ARRAY_CONSTRUCTORS=new Map([[p.UINT8.toString(),Uint8Array],[p.UINT16.toString(),Uint16Array],[p.UINT32.toString(),Uint32Array],[p.UINT64.toString(),BigUint64Array],[p.FLOAT32.toString(),Float32Array],[p.FLOAT64.toString(),Float64Array],[p.INT8.toString(),Int8Array],[p.INT16.toString(),Int16Array],[p.INT32.toString(),Int32Array],[p.INT64.toString(),BigInt64Array],[p.TIMESTAMP.toString(),BigInt64Array],[p.STRING.toString(),Uint8Array],[p.JSON.toString(),Uint8Array],[p.UUID.toString(),Uint8Array]]);static ARRAY_CONSTRUCTOR_DATA_TYPES=new Map([[Uint8Array.name,p.UINT8],[Uint16Array.name,p.UINT16],[Uint32Array.name,p.UINT32],[BigUint64Array.name,p.UINT64],[Float32Array.name,p.FLOAT32],[Float64Array.name,p.FLOAT64],[Int8Array.name,p.INT8],[Int16Array.name,p.INT16],[Int32Array.name,p.INT32],[BigInt64Array.name,p.INT64]]);static DENSITIES=new Map([[p.UINT8.toString(),Y.BIT8],[p.UINT16.toString(),Y.BIT16],[p.UINT32.toString(),Y.BIT32],[p.UINT64.toString(),Y.BIT64],[p.FLOAT32.toString(),Y.BIT32],[p.FLOAT64.toString(),Y.BIT64],[p.INT8.toString(),Y.BIT8],[p.INT16.toString(),Y.BIT16],[p.INT32.toString(),Y.BIT32],[p.INT64.toString(),Y.BIT64],[p.TIMESTAMP.toString(),Y.BIT64],[p.STRING.toString(),Y.UNKNOWN],[p.JSON.toString(),Y.UNKNOWN],[p.UUID.toString(),Y.BIT128]]);static ALL=[p.UNKNOWN,p.FLOAT64,p.FLOAT32,p.INT64,p.INT32,p.INT16,p.INT8,p.UINT64,p.UINT32,p.UINT16,p.UINT8,p.TIMESTAMP,p.UUID,p.STRING,p.JSON];static BIG_INT_TYPES=[p.INT64,p.UINT64,p.TIMESTAMP];static z=s.z.union([s.z.string().transform(e=>new p(e)),s.z.instanceof(p)])},et=class z extends nt{constructor(e){Q(e)&&(e=e.value),super(e.valueOf())}largerThan(e){return Q(e)&&(e=e.value),this.valueOf()>e.valueOf()}smallerThan(e){return Q(e)&&(e=e.value),this.valueOf()<e.valueOf()}add(e){return Q(e)&&(e=e.value),new z(Ut(this.valueOf(),e.valueOf()))}sub(e){return Q(e)&&(e=e.value),new z(Ze(this.valueOf(),e.valueOf()))}mult(e){return new z(ue(this.valueOf(),e))}div(e){return new z(wr(this.valueOf(),e))}truncate(e){return new z(Math.trunc(this.valueOf()/new z(e).valueOf())*new z(e).valueOf())}remainder(e){return z.bytes(this.valueOf()%new z(e).valueOf())}get gigabytes(){return this.valueOf()/z.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/z.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/z.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/z.TERABYTE.valueOf()}toString(){const e=this.truncate(z.TERABYTE),t=this.truncate(z.GIGABYTE),n=this.truncate(z.MEGABYTE),i=this.truncate(z.KILOBYTE),a=this.truncate(z.BYTE),o=e,c=t.sub(e),u=n.sub(t),l=i.sub(n),h=a.sub(i);let y="";return o.isZero||(y+=`${o.terabytes}TB `),c.isZero||(y+=`${c.gigabytes}GB `),u.isZero||(y+=`${u.megabytes}MB `),l.isZero||(y+=`${l.kilobytes}KB `),(!h.isZero||y==="")&&(y+=`${h.valueOf()}B`),y.trim()}static bytes(e=1){return new z(e)}static BYTE=new z(1);static kilobytes(e=1){return z.bytes(new z(e).valueOf()*1e3)}static KILOBYTE=z.kilobytes(1);static megabytes(e=1){return z.kilobytes(new z(e).valueOf()*1e3)}static MEGABYTE=z.megabytes(1);static gigabytes(e=1){return z.megabytes(new z(e).valueOf()*1e3)}static GIGABYTE=z.gigabytes(1);static terabytes(e){return z.gigabytes(new z(e).valueOf()*1e3)}static TERABYTE=z.terabytes(1);static ZERO=new z(0);static z=s.z.union([s.z.number().transform(e=>new z(e)),s.z.instanceof(z)]);get isZero(){return this.valueOf()===0}};s.z.union([s.z.instanceof(Uint8Array),s.z.instanceof(Uint16Array),s.z.instanceof(Uint32Array),s.z.instanceof(BigUint64Array),s.z.instanceof(Float32Array),s.z.instanceof(Float64Array),s.z.instanceof(Int8Array),s.z.instanceof(Int16Array),s.z.instanceof(Int32Array),s.z.instanceof(BigInt64Array)]);const Qi=r=>{const e=typeof r;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||r instanceof f||r instanceof E||r instanceof Date},Dh=(r,e,t,n=0)=>r.usesBigInt&&!e.usesBigInt?Number(t)-Number(n):!r.usesBigInt&&e.usesBigInt?BigInt(t.valueOf())-BigInt(n.valueOf()):nr(t,-n),nr=(r,e)=>e==0?r:r==0?e:typeof r=="bigint"&&typeof e=="bigint"||typeof r=="number"&&typeof e=="number"?r+e:Number(r)+Number(e),Zh=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;function Ph(r){return typeof r=="string"&&Zh.test(r)}const F=[];for(let r=0;r<256;++r)F.push((r+256).toString(16).slice(1));function Lh(r,e=0){return(F[r[e+0]]+F[r[e+1]]+F[r[e+2]]+F[r[e+3]]+"-"+F[r[e+4]]+F[r[e+5]]+"-"+F[r[e+6]]+F[r[e+7]]+"-"+F[r[e+8]]+F[r[e+9]]+"-"+F[r[e+10]]+F[r[e+11]]+F[r[e+12]]+F[r[e+13]]+F[r[e+14]]+F[r[e+15]]).toLowerCase()}function Bh(r,e=0){const t=Lh(r,e);if(!Ph(t))throw TypeError("Stringified UUID is invalid");return t}typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const ea=(r,e)=>Bh(r,e),Ne=-1,cn={[Symbol.iterator]:()=>cn,next:()=>({done:!0,value:void 0})},qh=s.z.string().transform(r=>new Uint8Array(atob(r).split("").map(e=>e.charCodeAt(0))).buffer),Fh=s.z.union([s.z.null(),s.z.undefined()]).transform(()=>new Uint8Array().buffer),ln=10,ta=(r,e)=>{if(r==="number"&&!e.isNumeric)throw new Error(`cannot convert series of type ${e.toString()} to number`);if(r==="bigint"&&!e.usesBigInt)throw new Error(`cannot convert series of type ${e.toString()} to bigint`)},ra="sy_x_telem_series";let ge=class Ae{key;discriminator=ra;dataType;sampleOffset;gl;_data;timeRange=M.ZERO;alignment=0n;alignmentMultiple=1n;cachedMin;cachedMax;writePos=Ne;_refCount=0;cachedLength;_cachedIndexes;static crudeZ=s.z.object({timeRange:M.z.optional(),dataType:$.z,alignment:s.z.coerce.bigint().optional(),data:s.z.union([qh,Fh,s.z.instanceof(ArrayBuffer),s.z.instanceof(Uint8Array)]),glBufferUsage:Mh.optional().default("static").optional()});static z=Ae.crudeZ.transform(e=>new Ae(e));constructor(e){Yh(e)&&(e={data:e}),e.data??=[];const{dataType:t,timeRange:n,sampleOffset:i=0,glBufferUsage:a="static",alignment:o=0n,alignmentMultiple:c=1n,key:u=Dn(),data:l}=e;if(na(l)){const d=l;this.key=d.key,this.dataType=d.dataType,this.sampleOffset=d.sampleOffset,this.gl=d.gl,this._data=d._data,this.timeRange=d.timeRange,this.alignment=d.alignment,this.alignmentMultiple=d.alignmentMultiple,this.cachedMin=d.cachedMin,this.cachedMax=d.cachedMax,this.writePos=d.writePos,this._refCount=d._refCount,this.cachedLength=d.cachedLength;return}const h=Qi(l),y=Array.isArray(l);if(t!=null)this.dataType=new $(t);else{if(l instanceof ArrayBuffer)throw new Error("cannot infer data type from an ArrayBuffer instance when constructing a Series. Please provide a data type.");if(y||h){let d=l;if(!h){if(l.length===0)throw new Error("cannot infer data type from a zero length JS array when constructing a Series. Please provide a data type.");d=l[0]}if(typeof d=="string")this.dataType=$.STRING;else if(typeof d=="number")this.dataType=$.FLOAT64;else if(typeof d=="bigint")this.dataType=$.INT64;else if(typeof d=="boolean")this.dataType=$.BOOLEAN;else if(d instanceof f||d instanceof Date||d instanceof f)this.dataType=$.TIMESTAMP;else if(typeof d=="object")this.dataType=$.JSON;else throw new Error(`cannot infer data type of ${typeof d} when constructing a Series from a JS array`)}else this.dataType=new $(l)}if(!y&&!h)this._data=l;else if(y&&l.length===0)this._data=new this.dataType.Array([]).buffer;else{let d=h?[l]:l;const N=d[0];(N instanceof f||N instanceof Date||N instanceof E)&&(d=d.map(S=>new f(S).valueOf())),this.dataType.equals($.STRING)?(this.cachedLength=d.length,this._data=new TextEncoder().encode(`${d.join(`
|
|
5
|
+
`).buffer):this.dataType.usesBigInt&&typeof v=="number"?this._data=new this.dataType.Array(f.map(S=>BigInt(Math.round(S)))).buffer:!this.dataType.usesBigInt&&typeof v=="bigint"?this._data=new this.dataType.Array(f.map(Number)).buffer:this._data=new this.dataType.Array(f).buffer}this.key=l,this.alignment=o,this.alignmentMultiple=c,this.sampleOffset=s??0,this.timeRange=n??Rt.ZERO,this.gl={control:null,buffer:null,prevBuffer:0,bufferUsage:a}}static alloc({capacity:e,dataType:r,...n}){if(e===0)throw new Error("[Series] - cannot allocate an array of length 0");const s=new new B(r).Array(e),a=new De({data:s.buffer,dataType:r,...n});return a.writePos=0,a}get refCount(){return this._refCount}acquire(e){this._refCount++,e!=null&&this.updateGLBuffer(e)}release(){this._refCount--,this.refCount===0&&this.gl.control!=null?this.maybeGarbageCollectGLBuffer(this.gl.control):this.refCount<0&&console.warn("cannot release a series with a negative reference count")}write(e){if(!e.dataType.equals(this.dataType))throw new Error("buffer must be of the same type as this array");return this.dataType.isVariable?this.writeVariable(e):this.writeFixed(e)}writeVariable(e){if(this.writePos===Re)return 0;const r=this.byteCapacity.valueOf()-this.writePos,n=e.subBytes(0,r);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===Re)return 0;const r=this.capacity-this.writePos,n=e.sub(0,r);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===Re?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(B.JSON))throw new Error("cannot parse non-JSON series as JSON");return this.toStrings().map(r=>e.parse(Mn.decodeString(r)))}get byteCapacity(){return new Pn(this.underlyingData.byteLength)}get capacity(){return this.dataType.isVariable?this.byteCapacity.valueOf():this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===Re?this.byteCapacity:this.dataType.isVariable?new Pn(this.writePos):this.dataType.density.size(this.writePos)}get length(){return this.cachedLength!=null?this.cachedLength:this.dataType.isVariable?this.calculateCachedLength():this.writePos===Re?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 r=[0];return this.data.forEach((n,s)=>{n===Un&&(e++,r.push(s+1))}),this._cachedIndexes=r,this.cachedLength=e,e}convert(e,r=0){if(this.dataType.equals(e))return this;const n=new e.Array(this.length);for(let s=0;s<this.length;s++)n[s]=Th(this.dataType,e,this.data[s],r);return new De({data:n.buffer,dataType:e,timeRange:this.timeRange,sampleOffset:r,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment})}calcRawMax(){if(this.length===0)return-1/0;if(this.dataType.equals(B.TIMESTAMP))this.cachedMax=this.data[this.data.length-1];else if(this.dataType.usesBigInt){const e=this.data;this.cachedMax=e.reduce((r,n)=>r>n?r:n)}else{const e=this.data;this.cachedMax=e.reduce((r,n)=>r>n?r: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(),$r(this.cachedMax,this.sampleOffset))}calcRawMin(){if(this.length===0)return 1/0;if(this.dataType.equals(B.TIMESTAMP))this.cachedMin=this.data[0];else if(this.dataType.usesBigInt){const e=this.data;this.cachedMin=e.reduce((r,n)=>r<n?r:n)}else{const e=this.data;this.cachedMin=e.reduce((r,n)=>r<n?r: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(),$r(this.cachedMin,this.sampleOffset))}get bounds(){return Qe(Number(this.min),Number(this.max),{makeValid:!1})}maybeRecomputeMinMax(e){if(this.cachedMin!=null){const r=e.cachedMin??e.calcRawMin();r<this.cachedMin&&(this.cachedMin=r)}if(this.cachedMax!=null){const r=e.cachedMax??e.calcRawMax();r>this.cachedMax&&(this.cachedMax=r)}}atAlignment(e,r){const n=Number((e-this.alignment)/this.alignmentMultiple);if(n<0||n>=this.length){if(r===!0)throw new Error(`[series] - no value at index ${n}`);return}return this.at(n,r)}at(e,r=!1){if(this.dataType.isVariable)return this.atVariable(e,r??!1);if(this.dataType.equals(B.UUID))return this.atUUID(e,r);e<0&&(e=this.length+e);const n=this.data[e];if(n==null){if(r===!0)throw new Error(`[series] - no value at index ${e}`);return}return $r(n,this.sampleOffset)}atUUID(e,r){e<0&&(e=this.length+e);const n=Ia(new Uint8Array(this.buffer,e*this.dataType.density.valueOf()));if(n==null){if(r)throw new Error(`[series] - no value at index ${e}`);return}return n}atVariable(e,r){let n=0,s=0;if(this._cachedIndexes!=null)n=this._cachedIndexes[e],s=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]===Un){if(e===0){s=o;break}n=o+1,e--}if(s===0&&(s=this.data.length),n>=s||e>0){if(r)throw new Error(`[series] - no value at index ${e}`);return}}const a=this.data.slice(n,s);return this.dataType.equals(B.STRING)?new TextDecoder().decode(a):ma(JSON.parse(new TextDecoder().decode(a)))}binarySearch(e){let r=0,n=this.length-1;const s=Ml(e);for(;r<=n;){const a=Math.floor((r+n)/2),o=s(this.at(a,!0),e);if(o===0)return a;o<0?r=a+1:n=a-1}return r}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals(B.FLOAT32)&&!this.dataType.equals(B.UINT8))throw new Error("Only FLOAT32 and UINT8 arrays can be used in WebGL");const{buffer:r,bufferUsage:n,prevBuffer:s}=this.gl;if(r==null&&(this.gl.buffer=e.createBuffer()),this.writePos!==s)if(e.bindBuffer(e.ARRAY_BUFFER,this.gl.buffer),this.writePos!==Re){s===0&&e.bufferData(e.ARRAY_BUFFER,this.byteCapacity.valueOf(),e.STATIC_DRAW);const a=this.dataType.density.size(s).valueOf(),o=this.underlyingData.slice(this.gl.prevBuffer,this.writePos);e.bufferSubData(e.ARRAY_BUFFER,a,o.buffer),this.gl.prevBuffer=this.writePos}else e.bufferData(e.ARRAY_BUFFER,this.buffer,n==="static"?e.STATIC_DRAW:e.DYNAMIC_DRAW),this.gl.prevBuffer=Re}as(e){return Ih(e,this.dataType),this}get digest(){return{key:this.key,dataType:this.dataType.toString(),sampleOffset:this.sampleOffset,alignment:{lower:pi(this.alignmentBounds.lower),upper:pi(this.alignmentBounds.upper),multiple:this.alignmentMultiple},timeRange:this.timeRange.toString(),length:this.length,capacity:this.capacity}}get alignmentBounds(){return Qe(this.alignment,this.alignment+BigInt(this.length)*this.alignmentMultiple)}maybeGarbageCollectGLBuffer(e){this.gl.buffer!=null&&(e.deleteBuffer(this.gl.buffer),this.gl.buffer=null,this.gl.prevBuffer=0,this.gl.control=null)}get glBuffer(){if(this.gl.buffer==null)throw new Error("gl buffer not initialized");return this.gl.prevBuffer!==this.writePos&&console.warn("buffer not updated"),this.gl.buffer}[Symbol.iterator](){if(this.dataType.isVariable){const e=new xh(this);return this.dataType.equals(B.JSON)?new ys(e):e}return this.dataType.equals(B.UUID)?new Zh(this):new Ch(this)}slice(e,r){return this.sliceSub(!1,e,r)}sub(e,r){return this.sliceSub(!0,e,r)}subIterator(e,r){return new di(this,e,r??this.length)}subAlignmentIterator(e,r){const n=Math.ceil(Number(e-this.alignment)/Number(this.alignmentMultiple)),s=Math.ceil(Number(r-this.alignment)/Number(this.alignmentMultiple));return new di(this,n,s)}subBytes(e,r){if(e>=0&&(r==null||r>=this.byteLength.valueOf()))return this;const n=this.data.subarray(e,r);return new De({data:n,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(e)})}sliceSub(e,r,n){if(r<=0&&(n==null||n>=this.length))return this;let s;return e?s=this.data.subarray(r,n):s=this.data.slice(r,n),new De({data:s,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(r)})}reAlign(e){return new De({data:this.buffer,dataType:this.dataType,timeRange:Rt.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(r=>r.toString());else{for(let r=0;r<5;r++)e+=`${this.at(r)?.toString()}`,e+=",";e+="...,";for(let r=-5;r<0;r++)e+=this.at(r)?.toString(),r<-1&&(e+=",")}return e+="])",e}};const kh=t=>t==null?!1:Array.isArray(t)||t instanceof ArrayBuffer||ArrayBuffer.isView(t)&&!(t instanceof DataView)||t instanceof Aa?!0:Sa(t),Ah=gh(ka,Aa);class di{series;end;index;constructor(e,r,n){this.series=e;const s=Qe(0,e.length+1);this.end=ci(s,n),this.index=ci(s,r)}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}}let xh=class{series;index;decoder;constructor(t){if(!t.dataType.isVariable)throw new Error("cannot create a variable series iterator for a non-variable series");this.series=t,this.index=0,this.decoder=new TextDecoder}next(){const t=this.index,e=this.series.data;for(;this.index<e.length&&e[this.index]!==Un;)this.index++;const r=this.index;return t===r?{done:!0,value:void 0}:(this.index++,{done:!1,value:this.decoder.decode(this.series.buffer.slice(t,r))})}};class ys{wrapped;static schema=i.z.record(i.z.string(),i.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:Mn.decodeString(e.value,ys.schema)}}}class Zh{series;index;data;density;constructor(e){if(!e.dataType.equals(B.UUID))throw new Error("cannot create a UUID series iterator for a non-UUID series");this.series=e,this.index=0,this.data=new Uint8Array(e.buffer),this.density=B.UUID.density.valueOf()}next(){if(this.index>=this.series.length)return{done:!0,value:void 0};const e=Ia(this.data,this.index*this.density);return this.index++,{done:!1,value:e}}}let Ch=class{series;index;constructor(t){this.series=t,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 pi=t=>{const e=t>>32n,r=t&0xffffffffn;return{domain:e,sample:r}};i.z.object({key:i.z.string(),value:i.z.string()});i.z.record(i.z.union([i.z.number(),i.z.string(),i.z.symbol()]),i.z.unknown());const Rh=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser";Rh();const _h=["macOS","Windows","Linux"],jh=["macos","windows","linux"],Mh={macos:"macOS",windows:"Windows",linux:"Linux"};i.z.enum(_h).or(i.z.enum(jh).transform(t=>Mh[t]));const Dh=(...t)=>t.map(xa).join(""),xa=t=>(t.endsWith("/")||(t+="/"),t.startsWith("/")&&(t=t.slice(1)),t),Ph=t=>t.endsWith("/")?t.slice(0,-1):t,Uh=(t,e="")=>t===null?"":`?${Object.entries(t).filter(([,r])=>r==null?!1:Array.isArray(r)?r.length>0:!0).map(([r,n])=>`${e}${r}=${n}`).join("&")}`;let Lh=class Sr{protocol;host;port;path;constructor({host:e,port:r,protocol:n="",pathPrefix:s=""}){this.protocol=n,this.host=e,this.port=r,this.path=xa(s)}replace(e){return new Sr({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new Sr({...this,pathPrefix:Dh(this.path,e)})}toString(){return Ph(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}static UNKNOWN=new Sr({host:"unknown",port:0})};const Bh=async t=>await new Promise(e=>setTimeout(e,C.fromMilliseconds(t).milliseconds));class qh{config;retries;interval;constructor(e){this.config={baseInterval:new C(e?.baseInterval??C.seconds(1)),maxRetries:e?.maxRetries??5,scale:e?.scale??1,sleepFn:e?.sleepFn??Bh},this.retries=0,this.interval=new C(this.config.baseInterval)}async wait(){const{maxRetries:e,scale:r,sleepFn:n}=this.config;return this.retries>=e?!1:(await n(this.interval),this.interval=this.interval.mult(r),this.retries++,!0)}get retryMessage(){return`breaker triggered ${this.retries+1}/${this.config.maxRetries} times, retrying in ${this.interval.toString()}`}reset(){this.retries=0,this.interval=this.config.baseInterval}}const Fh=i.z.object({baseInterval:C.z.optional(),maxRetries:i.z.number().optional(),scale:i.z.number().optional()}),Vh=Object.freeze(Object.defineProperty({__proto__:null,Breaker:qh,breakerConfigZ:Fh},Symbol.toStringTag,{value:"Module"})),Yh=/^#?([0-9a-f]{6}|[0-9a-f]{8})$/i,Za=i.z.string().regex(Yh),yt=i.z.number().min(0).max(255),Ca=i.z.number().min(0).max(1),Ra=i.z.tuple([yt,yt,yt,Ca]),Wh=i.z.tuple([yt,yt,yt]),Hh=i.z.object({rgba255:Ra}),Gh=i.z.number().min(0).max(360),Jh=i.z.number().min(0).max(100),Kh=i.z.number().min(0).max(100),Xh=i.z.tuple([Gh,Jh,Kh,Ca]),ms=i.z.union([Za,Wh,Ra,Xh,Hh]),Qh=ms.transform(t=>gs(t)),gs=(t,e=1)=>{if(t=ms.parse(t),typeof t=="string")return ef(t,e);if(Array.isArray(t)){if(t.length<3||t.length>4)throw new Error(`Invalid color: [${t.join(", ")}]`);return t.length===3?[...t,e]:t}return t.rgba255},ef=(t,e=1)=>(t=Za.parse(t),t=tf(t),[wr(t,0),wr(t,2),wr(t,4),t.length===8?wr(t,6)/255:e]),wr=(t,e)=>parseInt(t.slice(e,e+2),16),tf=t=>t.startsWith("#")?t.slice(1):t;gs("#000000");gs("#ffffff");const rf=i.z.object({key:i.z.string(),color:ms,position:i.z.number(),switched:i.z.boolean().optional()});i.z.array(rf);const nf=i.z.object({key:i.z.string(),name:i.z.string(),color:Qh});i.z.object({key:i.z.string(),name:i.z.string(),swatches:i.z.array(nf)});i.z.int().min(0).max(255);i.z.object({name:i.z.string(),key:i.z.string()});const sf=t=>Object.getOwnPropertySymbols(globalThis).includes(t),af=(t,e)=>{const r=Symbol.for(t);if(!sf(r)){const n=e();Object.defineProperty(globalThis,r,{value:n})}return()=>globalThis[r]},_a="sy_x_error",of=t=>e=>e!=null&&typeof e=="object"&&"type"in e&&typeof e.type=="string"?e.type.startsWith(t):e instanceof Error?e.message.startsWith(t):typeof e!="string"?!1:e.startsWith(t),rr=t=>class _t extends Error{static discriminator=_a;discriminator=_t.discriminator;static TYPE=t;type=_t.TYPE;static matches=of(t);matches=_t.matches;constructor(r,n){super(r,n),this.name=_t.TYPE}static sub(r){return rr(`${t}.${r}`)}},ja=t=>{if(t==null||typeof t!="object")return!1;const e=t;if(e.discriminator!==_a)return!1;if(!("type"in e))throw new Error(`X Error is missing its type property: ${JSON.stringify(e)}`);return!0},lt="unknown",Ln="nil";class cf{providers=[];register(e){this.providers.push(e)}encode(e){if(e==null)return{type:Ln,data:""};if(ja(e))for(const r of this.providers){const n=r.encode(e);if(n!=null)return n}if(e instanceof Error)return{type:lt,data:e.message};if(typeof e=="string")return{type:lt,data:e};try{return{type:lt,data:JSON.stringify(e)}}catch{return{type:lt,data:"unable to encode error information"}}}decode(e){if(e==null||e.type===Ln)return null;if(e.type===lt)return new Bn(e.data);for(const r of this.providers){const n=r.decode(e);if(n!=null)return n}return new Bn(e.data)}}const ws=af("synnax-error-registry",()=>new cf),uf=({encode:t,decode:e})=>ws().register({encode:t,decode:e}),lf=t=>ws().encode(t),hf=t=>t==null?null:ws().decode(t);let Bn=class extends rr("unknown"){};const ff=i.z.object({type:i.z.string(),data:i.z.string()});class df extends rr("canceled"){}class pf extends rr("not_implemented"){}const Le=Object.freeze(Object.defineProperty({__proto__:null,Canceled:df,NONE:Ln,NotImplemented:pf,UNKNOWN:lt,Unknown:Bn,createTyped:rr,decode:hf,encode:lf,isTyped:ja,payloadZ:ff,register:uf},Symbol.toStringTag,{value:"Module"})),yf=i.object({jsonrpc:i.literal("2.0"),method:i.string(),params:i.any().optional(),id:i.union([i.string(),i.number(),i.null()]).optional()}),Ma=i.object({jsonrpc:i.literal("2.0"),id:i.union([i.string(),i.number(),i.null()])}),mf=Ma.extend({result:i.json()}),gf=Ma.extend({error:i.object({code:i.number().int(),message:i.string().optional(),data:i.json().optional()})}),wf=i.union([mf,gf]);i.union([yf,wf]);const bf=i.uuid();i.object({key:bf,name:i.string().min(1),color:i.string()});i.z.string().regex(/^\d+\.\d+\.\d+$/);const vf=["standard","scientific","engineering"];i.z.enum(vf);i.z.enum(["success","info","warning","error","loading","disabled"]);i.z.object({stack:i.z.string()});let nr=class extends Le.createTyped("freighter"){},we=class extends nr.sub("eof"){constructor(){super("EOF")}},bt=class extends nr.sub("stream_closed"){constructor(){super("StreamClosed")}},Be=class extends nr.sub("unreachable"){url;constructor(e={}){const{message:r="Unreachable",url:n=Lh.UNKNOWN}=e;super(r),this.url=n}};const Tf=t=>{if(!t.type.startsWith(nr.TYPE))return null;if(we.matches(t))return{type:we.TYPE,data:"EOF"};if(bt.matches(t))return{type:bt.TYPE,data:"StreamClosed"};if(Be.matches(t))return{type:Be.TYPE,data:"Unreachable"};throw new Error(`Unknown error type: ${t.type}: ${t.message}`)},zf=t=>{if(!t.type.startsWith(nr.TYPE))return null;switch(t.type){case we.TYPE:return new we;case bt.TYPE:return new bt;case Be.TYPE:return new Be;default:throw new Le.Unknown(`Unknown error type: ${t.data}`)}};Le.register({encode:Tf,decode:zf});let Da=class{middleware=[];use(...e){this.middleware.push(...e)}async executeMiddleware(e,r){let n=0;const s=async a=>{if(n===this.middleware.length)return await r(a);const o=this.middleware[n];return n++,await o(a,s)};return await s(e)}};const Pa="Content-Type",Ef=new Set(["ECONNREFUSED","ECONNRESET","ETIMEDOUT","EPIPE","UND_ERR_CONNECT_TIMEOUT","UND_ERR_SOCKET"]),Nf=t=>{const e=t?.cause?.code??t?.code??t?.errno;if(typeof e=="string"&&Ef.has(e))return!0;if(t.name==="TypeError"){const r=String(t.message||"").toLowerCase();if(/load failed|failed to fetch|networkerror|network error/.test(r))return!0}return t?.name==="AbortError"||t?.code,!1},Of=400;let $f=class extends Da{endpoint;encoder;constructor(e,r,n=!1){return super(),this.endpoint=e.replace({protocol:n?"https":"http"}),this.encoder=r,new Proxy(this,{get:(s,a,o)=>a==="endpoint"?this.endpoint:Reflect.get(s,a,o)})}get headers(){return{[Pa]:this.encoder.contentType}}async send(e,r,n,s){r=n?.parse(r);let a=null;const o=this.endpoint.child(e),c={};c.method="POST",c.body=this.encoder.encode(r??{});const[,l]=await this.executeMiddleware({target:o.toString(),protocol:this.endpoint.protocol,params:{},role:"client"},async u=>{const h={...u,params:{}};c.headers={...this.headers,...u.params};let d;try{d=await fetch(u.target,c)}catch(v){if(!(v instanceof Error))throw v;return[h,Nf(v)?new Be({url:o}):v]}const f=await d.arrayBuffer();if(d?.ok)return s!=null&&(a=this.encoder.decode(f,s)),[h,null];try{if(d.status!==Of)return[h,new Error(d.statusText)];const v=this.encoder.decode(f,Le.payloadZ),S=Le.decode(v);return[h,S]}catch(v){return[h,new Error(`[freighter] - failed to decode error: ${d.statusText}: ${v.message}`)]}});if(l!=null)return[null,l];if(a==null)throw new Error("Response must be defined");return[a,null]}};const Sf=(t,e)=>{class r{wrapped;constructor(s){this.wrapped=s}use(...s){this.wrapped.use(...s)}async send(s,a,o,c){const l=new Vh.Breaker(e);do{const[u,h]=await this.wrapped.send(s,a,o,c);if(h==null)return[u,null];if(!Be.matches(h))return[null,h];if(console.warn(`[freighter] ${l.retryMessage}`,h),!await l.wait())return[u,h]}while(!0)}}return new r(t)},w=async(t,e,r,n,s)=>{const[a,o]=await t.send(e,r,n,s);if(o!=null)throw o;return a},If=i.z.object({type:i.z.enum(["data","close","open"]),payload:i.z.unknown(),error:i.z.optional(Le.payloadZ)});class kf{codec;reqSchema;resSchema;ws;serverClosed;sendClosed;receiveDataQueue=[];receiveCallbacksQueue=[];constructor(e,r,n,s){this.codec=r,this.reqSchema=n,this.resSchema=s,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 Le.decode(e.error)}return null}send(e){if(this.serverClosed!=null)return new we;if(this.sendClosed)throw new bt;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=Le.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((r,n)=>this.receiveCallbacksQueue.push({resolve:r,reject:n}))}addMessage(e){const r=this.receiveCallbacksQueue.shift();r!=null?r.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,If))}onClose(e){this.addMessage({type:"close",error:{type:e.code===xf?we.TYPE:bt.TYPE,data:""}})}}const Af="freighterctx",xf=1e3;let Zf=class qn extends Da{baseUrl;encoder;secure;static MESSAGE_TYPE="arraybuffer";constructor(e,r,n=!1){super(),this.secure=n,this.baseUrl=e.replace({protocol:n?"wss":"ws"}),this.encoder=r}withCodec(e){const r=new qn(this.baseUrl,e,this.secure);return r.use(...this.middleware),r}async stream(e,r,n){let s;const[,a]=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=qn.MESSAGE_TYPE;const u=await this.wrapSocket(c,r,n);return u instanceof Error?[l,u]:(s=u,[l,null])});if(a!=null)throw a;return s}buildURL(e,r){const n=Uh({[Pa]:this.encoder.contentType,...r.params},Af);return this.baseUrl.child(e).toString()+n}async wrapSocket(e,r,n){return await new Promise(s=>{e.onopen=()=>{const a=new kf(e,this.encoder,r,n);a.receiveOpenAck().then(o=>{o!=null?s(o):s(a)}).catch(o=>s(o))},e.onerror=a=>{const o=a;s(new Error(o.message))}})}};const Ua=t=>i.union([i.union([i.null(),i.undefined()]).transform(()=>[]),t.array()]),Cf=t=>Array.isArray(t)?t:t==null?[]:[t],La=(t,e)=>{if(Array.isArray(e))return e.reduce((s,a)=>La(s,a),t??[]);if(t==null)return[e];const r=t.findIndex(s=>s==e),n=[...t];return r===-1?n.push(e):n[r]=e,n},Rf=((t,e)=>{if(t!=null)return Array.isArray(e)?t.filter(r=>!e.includes(r)):t.filter(r=>r!=e)}),Ba=(t,e)=>{if(Array.isArray(e))return e.reduce((s,a)=>Ba(s,a),t??[]);if(t==null)return[e];const r=t.findIndex(s=>s.key===e.key),n=[...t];return r===-1?n.push(e):n[r]=e,n},_f=((t,e)=>{if(t!=null)return Array.isArray(e)?t.filter(r=>!e.includes(r.key)):t.filter(r=>r.key!==e)}),T=Object.freeze(Object.defineProperty({__proto__:null,nullableZ:Ua,remove:Rf,removeKeyed:_f,toArray:Cf,upsert:La,upsertKeyed:Ba},Symbol.toStringTag,{value:"Module"})),jf=t=>{const e=t.replace(/_[a-z]/g,r=>r[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)},Yr=t=>{const e=(r,n=Fn)=>{if(typeof r=="string")return t(r);if(Array.isArray(r))return r.map(o=>e(o,n));if(!Tn(r))return r;n=Pf(n);const s={},a=r;return"toJSON"in a&&typeof a.toJSON=="function"?e(a.toJSON(),n):(Object.keys(a).forEach(o=>{let c=a[o];const l=t(o);n.recursive&&(Tn(c)?mi(c)||(c=e(c,n)):n.recursiveInArray&&yi(c)&&(c=[...c].map(u=>{let h=u;return Tn(u)?mi(h)||(h=e(u,n)):yi(u)&&(h=e({key:u},n).key),h}))),s[l]=c}),s)};return e},bs=Yr(jf),Mf=t=>t.replace(/([a-z0-9])([A-Z])/g,(e,r,n)=>`${r}_${n.toLowerCase()}`),qa=Yr(Mf),Fa=t=>t.length===0?t:t[0].toUpperCase()+t.slice(1),Df=[Number,String,Uint8Array],Fn={recursive:!0,recursiveInArray:!0},Pf=(t=Fn)=>(t.recursive==null?t=Fn:t.recursiveInArray??=!1,t),yi=t=>t!=null&&Array.isArray(t),Tn=t=>t!=null&&typeof t=="object"&&!Array.isArray(t),mi=t=>Df.some(e=>t instanceof e),Uf=t=>t.replace(/[\s_]+/g,"-").replace(/([a-z0-9])([A-Z])/g,(e,r,n)=>`${r}-${n.toLowerCase()}`).toLowerCase(),Lf=Yr(Uf),Bf=t=>{if(t.length===0)return t;let e=t.replace(/[_-]/g," ");return e=e.replace(/([a-z0-9])([A-Z])/g,(r,n,s)=>`${n} ${s}`),e=e.replace(/([A-Z]+)([A-Z][a-z])/g,(r,n,s)=>`${n} ${s}`),e=e.replace(/\s+/g," ").trim(),e=e.replace(/\b\w/g,r=>r.toUpperCase()),e},qf=Yr(Bf),Ff=Object.freeze(Object.defineProperty({__proto__:null,camelToSnake:qa,capitalize:Fa,snakeToCamel:bs,toKebab:Lf,toProperNoun:qf},Symbol.toStringTag,{value:"Module"})),Va=t=>t!=null&&typeof t=="object"&&!Array.isArray(t);let Ya=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,r){return this.decodeString(this.decoder.decode(e),r)}decodeString(e,r){const n=JSON.parse(e),s=bs(n);return r!=null?r.parse(s):s}encodeString(e){const r=qa(e);return JSON.stringify(r,(n,s)=>ArrayBuffer.isView(s)?Array.from(s):typeof s=="bigint"?s.toString():s)}},Wa=class{contentType="text/csv";encode(e){const r=this.encodeString(e);return new TextEncoder().encode(r)}decode(e,r){const n=new TextDecoder().decode(e);return this.decodeString(n,r)}encodeString(e){if(!Array.isArray(e)||e.length===0||!Va(e[0]))throw new Error("Payload must be an array of objects");const r=Object.keys(e[0]),n=[r.join(",")];return e.forEach(s=>{const a=r.map(o=>JSON.stringify(s[o]??""));n.push(a.join(","))}),n.join(`
|
|
7
|
+
`)}decodeString(e,r){const[n,...s]=e.trim().split(`
|
|
8
|
+
`).map(c=>c.trim());if(n.length===0)return r!=null?r.parse({}):{};const a=n.split(",").map(c=>c.trim()),o={};return a.forEach(c=>{o[c]=[]}),s.forEach(c=>{const l=c.split(",").map(u=>u.trim());a.forEach((u,h)=>{const d=this.parseValue(l[h]);d!=null&&o[u].push(d)})}),r!=null?r.parse(o):o}parseValue(e){if(e==null||e.length===0)return null;const r=Number(e);return isNaN(r)?e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e:r}},Ha=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,r){const n=new TextDecoder().decode(e);return r!=null?r.parse(n):n}};const Bt=new Ya,Vf=new Wa,Yf=new Ha,Wf=[Bt],st=Object.freeze(Object.defineProperty({__proto__:null,CSVCodec:Wa,CSV_CODEC:Vf,ENCODERS:Wf,JSONCodec:Ya,JSON_CODEC:Bt,TEXT_CODEC:Yf,TextCodec:Ha},Symbol.toStringTag,{value:"Module"})),Vn=t=>[...new Set(t)],Hf=(t,e,r=!0)=>{const n=new Map;return t.forEach(s=>{const a=e(s);if(n.has(a)){if(r)return;n.delete(a)}n.set(a,s)}),Array.from(n.values())},gi=Object.freeze(Object.defineProperty({__proto__:null,by:Hf,unique:Vn},Symbol.toStringTag,{value:"Module"})),he=t=>t!=null&&typeof t=="object"&&"value"in t;let Nt=class{value;constructor(e){this.value=e}valueOf(){return this.value}toJSON(){return this.value}toString(){return this.value.toString()}};const Gf=t=>t!=null&&typeof t=="object"&&"toString"in t,Wr=(t,e=!1)=>{const r=Gf(t)?"stringer":typeof t;let n;switch(r){case"string":n=(s,a)=>s.localeCompare(a);break;case"stringer":n=(s,a)=>s.toString().localeCompare(a.toString());break;case"number":n=(s,a)=>Number(s)-Number(a);break;case"bigint":n=(s,a)=>BigInt(s)-BigInt(a)>0n?1:-1;break;case"boolean":n=(s,a)=>Number(s)-Number(a);break;case"undefined":n=()=>0;break;default:return console.warn(`sortFunc: unknown type ${r}`),()=>-1}return e?Ja(n):n},Jf=(t,e,r)=>{const n=Wr(e[t],r);return(s,a)=>n(s[t],a[t])},Kf=(t,e)=>t.length!==e.length?t.length-e.length:t.every((r,n)=>r===e[n])?0:-1,Ga=(t,e)=>{if(t.length!==e.length)return t.length-e.length;if(t.length===0)return 0;const r=Wr(t[0]),n=[...t].sort(r),s=[...e].sort(r);return n.every((a,o)=>a===s[o])?0:-1},Xf=(t,e)=>{const r=Vn(t),n=Vn(e);return Ga(r,n)},Qf=(t,e)=>t===e?0:t==="first"&&e==="last"?1:-1,Ja=t=>(e,r)=>t(r,e),Ot=0,Ir=-1,kr=1,Ka=t=>t<Ot,Xa=t=>t>Ot,ed=t=>t>=Ot,Qa=t=>t===Ot,td=(t,e)=>{const r=/([a-zA-Z]+)|(\d+)/g,n=t.replace(/[\s_.-]+/g,"").match(r),s=e.replace(/[\s_.-]+/g,"").match(r);if(!n||!s)return 0;for(let a=0;a<Math.min(n.length,s.length);a++){const o=n[a],c=s[a];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-s.length},wi=Object.freeze(Object.defineProperty({__proto__:null,EQUAL:Ot,GREATER_THAN:kr,LESS_THAN:Ir,isEqualTo:Qa,isGreaterThan:Xa,isGreaterThanEqual:ed,isLessThan:Ka,newF:Wr,newFieldF:Jf,order:Qf,primitiveArrays:Kf,reverseF:Ja,stringsWithNumbers:td,uniqueUnorderedPrimitiveArrays:Xf,unorderedPrimitiveArrays:Ga},Symbol.toStringTag,{value:"Module"})),Hr=i.z.tuple([i.z.number(),i.z.number()]);i.z.tuple([i.z.bigint(),i.z.bigint()]);const eo=i.z.object({width:i.z.number(),height:i.z.number()}),rd=i.z.object({signedWidth:i.z.number(),signedHeight:i.z.number()}),nd=["width","height"];i.z.enum(nd);const sd=["start","center","end"],id=["signedWidth","signedHeight"];i.z.enum(id);const qt=i.z.object({x:i.z.number(),y:i.z.number()}),to=i.z.object({clientX:i.z.number(),clientY:i.z.number()}),ro=["x","y"],no=i.z.enum(ro),vs=["top","right","bottom","left"],ad=i.z.enum(vs),so=["left","right"],Ts=i.z.enum(so),io=["top","bottom"],zs=i.z.enum(io),Es=["center"],Yn=i.z.enum(Es),od=[...vs,...Es],Ns=i.z.enum(od);i.z.enum(sd);const cd=["first","last"];i.z.enum(cd);const ud=i.z.object({lower:i.z.number(),upper:i.z.number()}),ld=i.z.object({lower:i.z.bigint(),upper:i.z.bigint()});i.z.union([ud,Hr]);i.z.union([ld,Hr]);i.z.enum([...no.options,...Ns.options]);i.z.enum(["x","left","right"]);i.z.enum(["y","top","bottom"]);const hd=i.z.union([no,Ns,i.z.instanceof(String)]),$t=t=>(e,r)=>{if(typeof e=="bigint"){if(Cr(r))return t(e,BigInt(r));const n=t(Number(e),Number(r));return typeof n=="number"?BigInt(Math.round(n)):n}return t(Number(e),Number(r))},Ue=$t((t,e)=>t-e),St=$t((t,e)=>t+e),fd=(t,e,r=1e-4)=>Math.abs(t-e)<r,Wn=(t,e)=>{const r=typeof t=="bigint",n=typeof e=="bigint";return r&&n?t===e:r&&Cr(e)?t===BigInt(e):n&&Cr(t)?e===BigInt(t):t===e},dd=t=>{const e=10**Math.floor(Math.log10(t));return Math.round(t/e)*e},ao=$t((t,e)=>t<=e?t:e),Cr=t=>typeof t=="bigint"?!0:Number.isInteger(t),pd=$t((t,e)=>t>=e?t:e),oo=t=>typeof t=="bigint"?t<0n?-t:t:t<0?-t:t,me=$t((t,e)=>t*e),sr=$t((t,e)=>t/e),J=(t,e,r)=>{const n={};if(typeof e=="object"&&(r=e,e=void 0),r={makeValid:!0,...r},typeof t=="number"||typeof t=="bigint")e!=null?(n.lower=t,n.upper=e):(n.lower=typeof t=="bigint"?0n:0,n.upper=t);else if(Array.isArray(t)){if(t.length!==2)throw new Error("bounds: expected array of length 2");[n.lower,n.upper]=t}else n.lower=t.lower,n.upper=t.upper;return r?.makeValid?yd(n):n},yd=t=>t.lower>t.upper?{lower:t.upper,upper:t.lower}:t,bi=(t,e)=>{const r=J(t);return e<r.lower?r.lower:e>=r.upper?r.upper-(typeof r.upper=="number"?1:1n):e},br=(t,e)=>{const r=J(t);if(typeof e=="number"||typeof e=="bigint")return e>=r.lower&&e<r.upper;const n=J(e);return n.lower>=r.lower&&n.upper<=r.upper},md=t=>{const e=J(t);return e.upper-e.lower},gd=t=>({lower:Math.min(...t.map(e=>J(e).lower)),upper:Math.max(...t.map(e=>J(e).upper))}),wd=(t,e,r)=>{const n=t.map(c=>J(c)),s=r>0?1:r<0?-1:0;if(s===0)return e;let a=r,o=e;for(;Wn(a,0)===!1;){const c=n.findIndex(l=>s>0?o>=l.lower&&o<l.upper:o>l.lower&&o<=l.upper);if(c!==-1){const l=n[c];let u;if(s>0?u=Ue(l.upper,o):u=Ue(o,l.lower),u>0){const h=ao(oo(a),u);if(o=St(o,s>0?h:-h),a=Ue(a,s>0?h:-h),Wn(a,0))return o;continue}}if(s>0){const l=n.filter(u=>u.lower>o);if(l.length>0)o=l[0].lower;else return o}else{const l=n.filter(u=>u.upper<o);if(l.length>0)o=l[l.length-1].upper;else return o}}return o},bd=(t,e,r)=>{const n=t.map(o=>J(o));if(e===r)return typeof e=="bigint"?0n:0;const s=e<r?J([e,r]):J([r,e]);let a=typeof e=="bigint"?0n:0;for(const o of n){const c=o.lower>s.lower?o.lower:s.lower,l=o.upper<s.upper?o.upper:s.upper;if(c<l){const u=l-c;a=a+u}}return a},vd=Ts,Td=zs,zd=Yn,Ed={top:"bottom",right:"left",bottom:"top",left:"right",center:"center"},Nd={top:"left",right:"top",bottom:"right",left:"bottom",center:"center"},Od=hd,qe=t=>t instanceof String||!ro.includes(t)?t:t==="x"?"left":"top",$d=t=>Ed[qe(t)],Sd=t=>Nd[qe(t)],Ft=t=>{const e=qe(t);return e==="top"||e==="bottom"?"y":"x"},Id=i.z.object({x:Ts.or(Yn),y:zs.or(Yn)}),co=i.z.object({x:Ts,y:zs}),Os=Object.freeze({x:"left",y:"top"}),uo=Object.freeze({x:"right",y:"top"}),lo=Object.freeze({x:"left",y:"bottom"}),ho=Object.freeze({x:"right",y:"bottom"}),$s=Object.freeze({x:"center",y:"center"}),fo=Object.freeze({x:"center",y:"top"}),po=Object.freeze({x:"center",y:"bottom"}),yo=Object.freeze({x:"right",y:"center"}),mo=Object.freeze({x:"left",y:"center"}),kd=Object.freeze([mo,yo,fo,po,Os,uo,lo,ho,$s]),go=(t,e)=>t.x===e.x&&t.y===e.y,Ad=(t,e)=>{if(typeof e=="object"){let r=!0;return"x"in e&&(t.x===e.x||(r=!1)),"y"in e&&(t.y===e.y||(r=!1)),r}return t.x===e||t.y===e},xd=t=>[t.x,t.y],Ar=t=>Ft(qe(t))==="x",Zd=t=>Ft(qe(t))==="y",Cd=t=>`${t.x}${Fa(t.y)}`,Rd=(t,e)=>{let r,n;if(typeof t=="object"&&"x"in t?(r=t.x,n=t.y):(r=qe(t),n=qe(e??t)),Ft(r)===Ft(n)&&r!=="center"&&n!=="center")throw new Error(`[XYLocation] - encountered two locations with the same direction: ${r.toString()} - ${n.toString()}`);const s={...$s};return r==="center"?Ar(n)?[s.x,s.y]=[n,r]:[s.x,s.y]=[r,n]:n==="center"?Ar(r)?[s.x,s.y]=[r,n]:[s.x,s.y]=[n,r]:Ar(r)?[s.x,s.y]=[r,n]:[s.x,s.y]=[n,r],s},_d=Object.freeze(Object.defineProperty({__proto__:null,BOTTOM_CENTER:po,BOTTOM_LEFT:lo,BOTTOM_RIGHT:ho,CENTER:$s,CENTER_LEFT:mo,CENTER_LOCATIONS:Es,CENTER_RIGHT:yo,OUTER_LOCATIONS:vs,TOP_CENTER:fo,TOP_LEFT:Os,TOP_RIGHT:uo,XY_LOCATIONS:kd,X_LOCATIONS:so,Y_LOCATIONS:io,center:zd,construct:qe,constructXY:Rd,corner:co,crude:Od,direction:Ft,isX:Ar,isY:Zd,location:Ns,outer:ad,rotate90:Sd,swap:$d,x:vd,xy:Id,xyCouple:xd,xyEquals:go,xyMatches:Ad,xyToString:Cd,y:Td},Symbol.toStringTag,{value:"Module"})),Hn=i.z.union([i.z.number(),qt,Hr,eo,rd,to]),M=(t,e)=>{if(typeof t=="string"){if(e===void 0)throw new Error("The y coordinate must be given.");return t==="x"?{x:e,y:0}:{x:0,y:e}}return typeof t=="number"?{x:t,y:e??t}:Array.isArray(t)?{x:t[0],y:t[1]}:"signedWidth"in t?{x:t.signedWidth,y:t.signedHeight}:"clientX"in t?{x:t.clientX,y:t.clientY}:"width"in t?{x:t.width,y:t.height}:{x:t.x,y:t.y}},tt=Object.freeze({x:0,y:0}),jd=Object.freeze({x:1,y:1}),Md=Object.freeze({x:1/0,y:1/0}),Dd=Object.freeze({x:NaN,y:NaN}),wo=(t,e,r=0)=>{const n=M(t),s=M(e);return r===0?n.x===s.x&&n.y===s.y:Math.abs(n.x-s.x)<=r&&Math.abs(n.y-s.y)<=r},Pd=t=>wo(t,tt),Ss=(t,e,r)=>{const n=M(t),s=M(e,r);return{x:n.x*s.x,y:n.y*s.y}},bo=(t,e)=>{const r=M(t);return{x:r.x+e,y:r.y}},vo=(t,e)=>{const r=M(t);return{x:r.x,y:r.y+e}},To=(t,e,r,...n)=>{if(typeof e=="string"){if(typeof r!="number")throw new Error("The value must be a number.");return e==="x"?bo(t,r):vo(t,r)}if(typeof e=="object"&&"x"in e&&typeof e.x=="string"){const s=M(r),a=M(t);return e.x==="left"?s.x=-s.x:e.x==="center"&&(s.x=0),e.y==="top"?s.y=-s.y:e.y==="center"&&(s.y=0),{x:a.x+s.x,y:a.y+s.y}}return[t,e,r??tt,...n].reduce((s,a)=>{const o=M(a);return{x:s.x+o.x,y:s.y+o.y}},tt)},Ud=(t,e,r)=>{const n=M(t);return e==="x"?{x:r,y:n.y}:{x:n.x,y:r}},Ld=(t,e)=>{const r=M(t),n=M(e);return Math.sqrt((r.x-n.x)**2+(r.y-n.y)**2)},Bd=(t,e)=>{const r=M(t),n=M(e);return{x:n.x-r.x,y:n.y-r.y}},qd=t=>{const e=M(t);return Number.isNaN(e.x)||Number.isNaN(e.y)},Fd=t=>{const e=M(t);return Number.isFinite(e.x)&&Number.isFinite(e.y)},Vd=t=>{const e=M(t);return[e.x,e.y]},Yd=t=>{const e=M(t);return{left:e.x,top:e.y}},Wd=(t,e=0)=>{const r=M(t);return{x:Number(r.x.toFixed(e)),y:Number(r.y.toFixed(e))}},jt=(t,e)=>{const r=M(t),n=M(e);return{x:r.x-n.x,y:r.y-n.y}},Mt=t=>{const e=M(t),r=Math.hypot(e.x,e.y);return r===0?{x:0,y:0}:{x:-e.y/r,y:e.x/r}},zo=t=>{const e=M(t),r=Math.hypot(e.x,e.y);return r===0?{x:0,y:0}:{x:e.x/r,y:e.y/r}},Eo=(...t)=>{const e=t.reduce((r,n)=>To(r,n),tt);return Ss(e,1/t.length)},Hd=(t,e)=>{const r=[];for(let n=0;n<t.length;n++){const s=t[n];let a,o,c,l;if(n===0){const u=t[n+1],h=jt(u,s);o=Mt(h),c=o,l=e}else if(n===t.length-1){const u=t[n-1],h=jt(s,u);a=Mt(h),c=a,l=e}else{const u=t[n-1],h=t[n+1],d=jt(s,u),f=jt(h,s);a=Mt(d),o=Mt(f);const v=Math.acos((d.x*f.x+d.y*f.y)/(Math.hypot(d.x,d.y)*Math.hypot(f.x,f.y))),S=Math.sin(v/2);S===0?l=e:l=e/S,c=zo(Eo(a,o))}r.push(Ss(c,l))}return r},Gd=t=>{const e=M(t);return{x:e.y,y:e.x}},Jd=t=>{const e=M(t);return{x:Math.round(e.x),y:Math.round(e.y)}},Kd=t=>{const e=M(t);return{x:1/e.x,y:1/e.y}},Is=Object.freeze(Object.defineProperty({__proto__:null,INFINITY:Md,NAN:Dd,ONE:jd,ZERO:tt,average:Eo,calculateMiters:Hd,clientXY:to,construct:M,couple:Vd,crudeZ:Hn,css:Yd,distance:Ld,equals:wo,isFinite:Fd,isNan:qd,isZero:Pd,normal:Mt,normalize:zo,reciprocal:Kd,round:Jd,scale:Ss,set:Ud,sub:jt,swap:Gd,translate:To,translateX:bo,translateY:vo,translation:Bd,truncate:Wd,xy:qt},Symbol.toStringTag,{value:"Module"})),vr=i.z.union([i.z.number(),i.z.string()]);i.z.object({top:vr,left:vr,width:vr,height:vr});i.z.object({left:i.z.number(),top:i.z.number(),right:i.z.number(),bottom:i.z.number()});i.z.object({one:qt,two:qt,root:co});const ks=(t,e,r=0,n=0,s)=>{const a={one:{...tt},two:{...tt},root:s??Os};if(typeof t=="number"){if(typeof e!="number")throw new Error("Box constructor called with invalid arguments");return a.one={x:t,y:e},a.two={x:a.one.x+r,y:a.one.y+n},a}return"one"in t&&"two"in t&&"root"in t?{...t,root:s??t.root}:("getBoundingClientRect"in t&&(t=t.getBoundingClientRect()),"left"in t?(a.one={x:t.left,y:t.top},a.two={x:t.right,y:t.bottom},a):(a.one=t,e==null?a.two={x:a.one.x+r,y:a.one.y+n}:typeof e=="number"?a.two={x:a.one.x+e,y:a.one.y+r}:"width"in e?a.two={x:a.one.x+e.width,y:a.one.y+e.height}:"signedWidth"in e?a.two={x:a.one.x+e.signedWidth,y:a.one.y+e.signedHeight}:a.two=e,a))},zn=t=>{const e=ks(t);return{lower:e.one.x,upper:e.two.x}},En=t=>{const e=ks(t);return{lower:e.one.y,upper:e.two.y}},Xd=t=>typeof t!="object"||t==null?!1:"one"in t&&"two"in t&&"root"in t,Qd=i.z.object({signedWidth:i.z.number(),signedHeight:i.z.number()});i.z.union([eo,Qd,qt,Hr]);const ep=(t,e,r)=>e!==void 0&&t<e?e:r!==void 0&&t>r?r:t;i.z.object({offset:Hn,scale:Hn});i.z.object({offset:i.z.number(),scale:i.z.number()});const tp=t=>(e,r,n,s)=>r==="dimension"?[e,n]:[e,s?n-t:n+t],rp=t=>(e,r,n,s)=>[e,s?n/t:n*t],np=t=>(e,r,n)=>{if(e===null)return[t,n];const{lower:s,upper:a}=e,{lower:o,upper:c}=t,l=a-s,u=c-o;if(r==="dimension")return[t,n*(u/l)];const h=(n-s)*(u/l)+o;return[t,h]},sp=t=>(e,r,n)=>[t,n],ip=()=>(t,e,r)=>{if(t===null)throw new Error("cannot invert without bounds");if(e==="dimension")return[t,r];const{lower:n,upper:s}=t;return[t,s-(r-n)]},ap=t=>(e,r,n)=>{const{lower:s,upper:a}=t;return n=ep(n,s,a),[e,n]};let vi=class ht{ops=[];currBounds=null;currType=null;reversed=!1;constructor(){this.ops=[]}static translate(e){return new ht().translate(e)}static magnify(e){return new ht().magnify(e)}static scale(e,r){return new ht().scale(e,r)}translate(e){const r=this.new(),n=tp(e);return n.type="translate",r.ops.push(n),r}magnify(e){const r=this.new(),n=rp(e);return n.type="magnify",r.ops.push(n),r}scale(e,r){const n=J(e,r),s=this.new(),a=np(n);return a.type="scale",s.ops.push(a),s}clamp(e,r){const n=J(e,r),s=this.new(),a=ap(n);return a.type="clamp",s.ops.push(a),s}reBound(e,r){const n=J(e,r),s=this.new(),a=sp(n);return a.type="re-bound",s.ops.push(a),s}invert(){const e=ip();e.type="invert";const r=this.new();return r.ops.push(e),r}pos(e){return this.exec("position",e)}dim(e){return this.exec("dimension",e)}new(){const e=new ht;return e.ops=this.ops.slice(),e.reversed=this.reversed,e}exec(e,r){return this.currBounds=null,this.ops.reduce(([n,s],a)=>a(n,e,s,this.reversed),[null,r])[1]}reverse(){const e=this.new();e.ops.reverse();const r=[];return e.ops.forEach((n,s)=>{if(n.type==="scale"||r.some(([o,c])=>s>=o&&s<=c))return;const a=e.ops.findIndex((o,c)=>o.type==="scale"&&c>s);a!==-1&&r.push([s,a])}),r.forEach(([n,s])=>{const a=e.ops.slice(n,s);a.unshift(e.ops[s]),e.ops.splice(n,s-n+1,...a)}),e.reversed=!e.reversed,e}get transform(){return{scale:this.dim(1),offset:this.pos(0)}}static IDENTITY=new ht},ES=class Ne{x;y;currRoot;constructor(e=new vi,r=new vi,n=null){this.x=e,this.y=r,this.currRoot=n}static translate(e,r){return new Ne().translate(e,r)}static translateX(e){return new Ne().translateX(e)}static translateY(e){return new Ne().translateY(e)}static clamp(e){return new Ne().clamp(e)}static magnify(e){return new Ne().magnify(e)}static scale(e){return new Ne().scale(e)}static reBound(e){return new Ne().reBound(e)}translate(e,r){const n=M(e,r),s=this.copy();return s.x=this.x.translate(n.x),s.y=this.y.translate(n.y),s}translateX(e){const r=this.copy();return r.x=this.x.translate(e),r}translateY(e){const r=this.copy();return r.y=this.y.translate(e),r}magnify(e){const r=this.copy();return r.x=this.x.magnify(e.x),r.y=this.y.magnify(e.y),r}scale(e){const r=this.copy();if(Xd(e)){const n=this.currRoot;return r.currRoot=e.root,n!=null&&!go(n,e.root)&&(n.x!==e.root.x&&(r.x=r.x.invert()),n.y!==e.root.y&&(r.y=r.y.invert())),r.x=r.x.scale(zn(e)),r.y=r.y.scale(En(e)),r}return r.x=r.x.scale(e.width),r.y=r.y.scale(e.height),r}reBound(e){const r=this.copy();return r.x=this.x.reBound(zn(e)),r.y=this.y.reBound(En(e)),r}clamp(e){const r=this.copy();return r.x=this.x.clamp(zn(e)),r.y=this.y.clamp(En(e)),r}copy(){const e=new Ne;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 ks(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 Ne},No=(t,e=21)=>(r=e)=>{let n="",s=r|0;for(;s--;)n+=t[Math.random()*t.length|0];return n};const Oo="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",op=`0123456789${Oo}`,$o=11,cp=No(Oo,1),up=No(op,$o-1),As=()=>`${cp()}${up()}`,lp=Object.freeze(Object.defineProperty({__proto__:null,LENGTH:$o,create:As},Symbol.toStringTag,{value:"Module"})),hp=(t,e)=>r=>r instanceof e||typeof r=="object"&&r!==null&&"discriminator"in r&&r.discriminator===t,fp=2**8-1,dp=2**16-1,pp=2**32-1,yp=2n**64n-1n,mp=2**64-1,gp=-128,wp=2**7-1,bp=-32768,vp=2**15-1,Tp=-2147483648,zp=2**31-1,Ep=-(2n**63n),Rr=2n**63n-1n,Np=-9223372036854776e3,So=2**63-1,Op=i.z.enum(["static","dynamic"]),Ti=365,Tr=30,$p=i.z.union([i.z.tuple([i.z.int()]),i.z.tuple([i.z.int(),i.z.int().min(1).max(12)]),i.z.tuple([i.z.int(),i.z.int().min(1).max(12),i.z.int().min(1).max(31)])]),Io=(t,e)=>{const r=new p(e);if(![I.DAY,I.HOUR,I.MINUTE,I.SECOND,I.MILLISECOND,I.MICROSECOND,I.NANOSECOND].some(s=>s.equals(r)))throw new Error("Invalid argument for remainder. Must be an even TimeSpan or Timestamp");const n=t.valueOf()%r.valueOf();return t instanceof p?new p(n):new I(n)};class p extends Nt{constructor(e,r="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,r).valueOf());else if(Array.isArray(e))super(p.parseDate(e));else{let n=0n;e instanceof Number&&(e=e.valueOf()),r==="local"&&(n=p.utcOffset.valueOf()),typeof e=="number"&&(isFinite(e)?e===So?e=Rr:e=Math.trunc(e):(isNaN(e)&&(e=0),e===1/0?e=p.MAX:e=p.MIN)),he(e)&&(e=e.value),super(BigInt(e.valueOf())+n)}}static parseDate([e=1970,r=1,n=1]){const s=new Date(e,r-1,n,0,0,0,0);return new p(BigInt(s.getTime())*p.MILLISECOND.valueOf()).truncate(p.DAY).valueOf()}valueOf(){return this.value}static parseTimeString(e,r="UTC"){const[n,s,a]=e.split(":");let o="00",c="00";a!=null&&([o,c]=a.split("."));let l=p.hours(parseInt(n??"00")).add(p.minutes(parseInt(s??"00"))).add(p.seconds(parseInt(o??"00"))).add(p.milliseconds(parseInt(c??"00")));return r==="local"&&(l=l.add(p.utcOffset)),l.valueOf()}static parseDateTimeString(e,r="UTC"){if(!e.includes("/")&&!e.includes("-"))return p.parseTimeString(e,r);const n=new Date(e);return e.includes(":")||n.setUTCHours(0,0,0,0),new p(BigInt(n.getTime())*p.MILLISECOND.valueOf(),r).valueOf()}toISOString(e="UTC"){return e==="UTC"?this.date().toISOString():this.sub(p.utcOffset).date().toISOString()}timeString(e=!1,r="UTC"){const n=this.toISOString(r);return e?n.slice(11,23):n.slice(11,19)}dateString(){const e=this.date(),r=e.toLocaleString("default",{month:"short"}),n=e.toLocaleString("default",{day:"numeric"});return`${r} ${n}`}static get utcOffset(){return new I(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 P(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(St(this.valueOf(),new I(e).valueOf()))}sub(e){return new p(Ue(this.valueOf(),new I(e).valueOf()))}get hours(){return Number(this.valueOf())/Number(I.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(I.MINUTE.valueOf())}get days(){return Number(this.valueOf())/Number(I.DAY.valueOf())}get seconds(){return Number(this.valueOf())/Number(I.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 r=this.date();return r.setUTCFullYear(e),new p(r)}get month(){return this.date().getUTCMonth()}setMonth(e){const r=this.date();return r.setUTCMonth(e),new p(r)}get day(){return this.date().getUTCDate()}setDay(e){const r=this.date();return r.setUTCDate(e),new p(r)}get hour(){return this.date().getUTCHours()}get localHour(){return this.date().getHours()}setLocalHour(e){const r=this.date();return r.setHours(e),new p(r)}setHour(e){const r=this.date();return r.setUTCHours(e),new p(r)}get minute(){return this.date().getUTCMinutes()}setMinute(e){const r=this.date();return r.setUTCMinutes(e),new p(r)}get second(){return this.date().getUTCSeconds()}setSecond(e){const r=this.date();return r.setUTCSeconds(e),new p(r)}get millisecond(){return this.date().getUTCMilliseconds()}setMillisecond(e){const r=this.date();return r.setUTCMilliseconds(e),new p(r)}toString(e="ISO",r="UTC"){switch(e){case"ISODate":return this.toISOString(r).slice(0,10);case"ISOTime":return this.toISOString(r).slice(11,23);case"time":return this.timeString(!1,r);case"preciseTime":return this.timeString(!0,r);case"date":return this.dateString();case"preciseDate":return`${this.dateString()} ${this.timeString(!0,r)}`;case"dateTime":return`${this.dateString()} ${this.timeString(!1,r)}`;default:return this.toISOString(r)}}remainder(e){return Io(this,e)}get isToday(){return this.truncate(I.DAY).equals(p.now().truncate(I.DAY))}truncate(e){return this.sub(this.remainder(e))}static now(){return new p(new Date)}static max(...e){let r=p.MIN;for(const n of e){const s=new p(n);s.after(r)&&(r=s)}return r}static min(...e){let r=p.MAX;for(const n of e){const s=new p(n);s.before(r)&&(r=s)}return r}static nanoseconds(e,r="UTC"){return new p(e,r)}static NANOSECOND=p.nanoseconds(1);static microseconds(e,r="UTC"){return p.nanoseconds(e*1e3,r)}static MICROSECOND=p.microseconds(1);static milliseconds(e,r="UTC"){return p.microseconds(e*1e3,r)}static MILLISECOND=p.milliseconds(1);static seconds(e,r="UTC"){return p.milliseconds(e*1e3,r)}static SECOND=p.seconds(1);static minutes(e,r="UTC"){return p.seconds(e*60,r)}static MINUTE=p.minutes(1);static hours(e,r="UTC"){return p.minutes(e*60,r)}static HOUR=p.hours(1);static days(e,r="UTC"){return p.hours(e*24,r)}static DAY=p.days(1);static MAX=new p(Rr);static MIN=new p(0);static ZERO=new p(0);static z=i.z.union([i.z.instanceof(p),i.z.object({value:i.z.bigint()}).transform(e=>new p(e.value)),i.z.string().transform(e=>new p(BigInt(e))),i.z.number().transform(e=>new p(e)),i.z.bigint().transform(e=>new p(e)),i.z.date().transform(e=>new p(e)),i.z.custom(e=>e instanceof I).transform(e=>new p(e)),$p.transform(e=>new p(e))]);static sort(e,r){return Number(e.valueOf()-r.valueOf())}}let I=class O extends Nt{constructor(e){typeof e=="number"&&(e=Math.trunc(e.valueOf())),he(e)&&(e=e.value),super(BigInt(e.valueOf()))}static fromSeconds(e){return e instanceof O?e:e instanceof re?e.period:e instanceof p?new O(e):(he(e)&&(e=e.value),["number","bigint"].includes(typeof e)?O.seconds(e):new O(e))}static fromMilliseconds(e){return e instanceof O?e:e instanceof re?e.period:e instanceof p?new O(e):(he(e)&&(e=e.value),["number","bigint"].includes(typeof e)?O.milliseconds(e):new O(e))}valueOf(){return this.value}lessThan(e){return this.valueOf()<new O(e).valueOf()}greaterThan(e){return this.valueOf()>new O(e).valueOf()}lessThanOrEqual(e){return this.valueOf()<=new O(e).valueOf()}greaterThanOrEqual(e){return this.valueOf()>=new O(e).valueOf()}remainder(e){return Io(this,e)}truncate(e){return new O(BigInt(Math.trunc(Number(this.valueOf()/e.valueOf())))*e.valueOf())}toString(e="full"){if(e==="semantic")return this.toSemanticString();const r=this.truncate(O.DAY),n=this.truncate(O.HOUR),s=this.truncate(O.MINUTE),a=this.truncate(O.SECOND),o=this.truncate(O.MILLISECOND),c=this.truncate(O.MICROSECOND),l=this.truncate(O.NANOSECOND),u=r,h=n.sub(r),d=s.sub(n),f=a.sub(s),v=o.sub(a),S=c.sub(o),Z=l.sub(c);let b="";return u.isZero||(b+=`${u.days}d `),h.isZero||(b+=`${h.hours}h `),d.isZero||(b+=`${d.minutes}m `),f.isZero||(b+=`${f.seconds}s `),v.isZero||(b+=`${v.milliseconds}ms `),S.isZero||(b+=`${S.microseconds}µs `),Z.isZero||(b+=`${Z.nanoseconds}ns`),b.trim()}toSemanticString(){const e=this.valueOf()<0n?-this.valueOf():this.valueOf(),r=new O(e),n=this.valueOf()<0n;if(r.valueOf()===0n)return"0s";if(r.lessThan(O.SECOND))return"< 1s";const s=r.days,a=r.hours,o=r.minutes,c=r.seconds,l=Math.floor(s/Ti),u=Math.floor(s/Tr),h=Math.floor(s/7),d=Math.floor(s),f=Math.floor(a),v=Math.floor(o),S=Math.floor(c),Z=n?"-":"";if(l>=1){let b=`${l}y`;if(l<2){const z=Math.floor(s%Ti/Tr);z>0&&(b+=` ${z}mo`)}return Z+b}if(h>=1&&s<Tr&&s%7===0){let b=`${h}w`;const z=Math.floor(s%7),k=Math.floor(a-h*7*24);return h<2&&(z>0?b+=` ${z}d`:k>0&&k<24&&(b+=` ${k}h`)),Z+b}if(u>=1){let b=`${u}mo`;if(u<3){const z=Math.floor(s%Tr);z>0&&(b+=` ${z}d`)}return Z+b}if(h>=1){let b=`${h}w`;const z=Math.floor(s%7),k=Math.floor(a-h*7*24);return h<2&&(z>0?b+=` ${z}d`:k>0&&k<24&&(b+=` ${k}h`)),Z+b}if(d>=1){let b=`${d}d`;const z=Math.floor(a-d*24);return d<2&&z>0&&(b+=` ${z}h`),Z+b}if(f>=1){let b=`${f}h`;if(f<3){const z=Math.floor(o-f*60);z>0&&(b+=` ${z}m`)}return Z+b}if(v>=1){let b=`${v}m`;if(v<5){const z=Math.floor(c-v*60);z>0&&(b+=` ${z}s`)}return Z+b}return`${Z}${S}s`}mult(e){return new O(me(this.valueOf(),e))}div(e){return new O(sr(this.valueOf(),e))}get days(){return Number(this.valueOf())/Number(O.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(O.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(O.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(O.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(O.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(O.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get isZero(){return this.valueOf()===0n}equals(e){return this.valueOf()===new O(e).valueOf()}add(e){return new O(this.valueOf()+new O(e).valueOf())}sub(e){return new O(this.valueOf()-new O(e).valueOf())}static nanoseconds(e=1){return new O(e)}static NANOSECOND=O.nanoseconds(1);static microseconds(e=1){return O.nanoseconds(me(e,1e3))}static MICROSECOND=O.microseconds(1);static milliseconds(e=1){return O.microseconds(me(e,1e3))}static MILLISECOND=O.milliseconds(1);static seconds(e=1){return O.milliseconds(me(e,1e3))}static SECOND=O.seconds(1);static minutes(e=1){return O.seconds(me(e,60))}static MINUTE=O.minutes(1);static hours(e){return O.minutes(me(e,60))}static HOUR=O.hours(1);static days(e){return O.hours(me(e,24))}static DAY=O.days(1);static MAX=new O(Rr);static MIN=new O(0);static ZERO=new O(0);static z=i.z.union([i.z.object({value:i.z.bigint()}).transform(e=>new O(e.value)),i.z.string().transform(e=>new O(BigInt(e))),i.z.number().transform(e=>new O(e)),i.z.bigint().transform(e=>new O(e)),i.z.instanceof(O),i.z.instanceof(p).transform(e=>new O(e)),i.z.custom(e=>e instanceof re).transform(e=>new O(e))])};class re extends Nt{constructor(e){he(e)&&(e=e.value),super(e.valueOf())}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new re(e).valueOf()}get period(){return I.seconds(1/this.valueOf())}sampleCount(e){return new I(e).seconds*this.valueOf()}byteCount(e,r){return this.sampleCount(e)*new Q(r).valueOf()}span(e){return I.seconds(e/this.valueOf())}byteSpan(e,r){return this.span(e.valueOf()/new Q(r).valueOf())}add(e){return new re(St(this.valueOf(),new re(e).valueOf()))}sub(e){return new re(Ue(this.valueOf(),new re(e).valueOf()))}mult(e){return new re(me(this.valueOf(),e))}div(e){return new re(sr(this.valueOf(),e))}static hz(e){return new re(e)}static khz(e){return re.hz(e*1e3)}static z=i.z.union([i.z.number().transform(e=>new re(e)),i.z.instanceof(re)])}let Q=class se extends Nt{constructor(e){he(e)&&(e=e.value),super(e.valueOf())}length(e){return e.valueOf()/this.valueOf()}size(e){return new vt(e*this.valueOf())}add(e){return new se(St(this.valueOf(),new se(e).valueOf()))}sub(e){return new se(Ue(this.valueOf(),new se(e).valueOf()))}mult(e){return new se(me(this.valueOf(),e))}div(e){return new se(sr(this.valueOf(),e))}static UNKNOWN=new se(0);static BIT128=new se(16);static BIT64=new se(8);static BIT32=new se(4);static BIT16=new se(2);static BIT8=new se(1);static z=i.z.union([i.z.number().transform(e=>new se(e)),i.z.instanceof(se)])},P=class Oe{start;end;constructor(e,r){typeof e=="object"&&"start"in e?(this.start=new p(e.start),this.end=new p(e.end)):(this.start=new p(e),this.end=new p(r))}get span(){return new I(this.end.valueOf()-this.start.valueOf())}get isValid(){return this.start.valueOf()<=this.end.valueOf()}makeValid(){return this.isValid?this:this.swap()}get isZero(){return this.start.isZero&&this.end.isZero}get numeric(){return{start:Number(this.start.valueOf()),end:Number(this.end.valueOf())}}swap(){return new Oe(this.end,this.start)}get numericBounds(){return{lower:Number(this.start.valueOf()),upper:Number(this.end.valueOf())}}equals(e,r=I.ZERO){if(r.isZero)return this.start.equals(e.start)&&this.end.equals(e.end);let n=this.start.sub(e.start).valueOf(),s=this.end.sub(e.end).valueOf();return n<0&&(n=-n),s<0&&(s=-s),n<=r.valueOf()&&s<=r.valueOf()}toString(){return`${this.start.toString()} - ${this.end.toString()}`}toPrettyString(){return`${this.start.toString("preciseDate")} - ${this.span.toString()}`}overlapsWith(e,r=I.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 s=p.max(n.start,e.start),a=p.min(n.end,e.end);return a.before(s)?!1:new I(a.sub(s)).greaterThanOrEqual(r)}contains(e){return e instanceof Oe?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const r=new Oe(this.start,this.end);return e.start.after(this.start)&&(r.start=e.start),e.start.after(this.end)&&(r.end=e.start),e.end.before(this.end)&&(r.end=e.end),e.end.before(this.start)&&(r.start=e.end),r}static max(...e){return new Oe(p.min(...e.map(r=>r.start)),p.max(...e.map(r=>r.end)))}static MAX=new Oe(p.MIN,p.MAX);static ZERO=new Oe(p.ZERO,p.ZERO);static z=i.z.union([i.z.object({start:p.z,end:p.z}).transform(e=>new Oe(e.start,e.end)),i.z.instanceof(Oe)]);static sort(e,r){return p.sort(e.start,r.start)||p.sort(e.end,r.end)}static simplify(e){return e.map(r=>r.makeValid()).sort((r,n)=>Oe.sort(r,n)).reduce((r,n)=>{if(n.span.isZero)return r;if(r.length===0)return r.push(n),r;const s=r[r.length-1];return s.overlapsWith(n)||s.end.equals(n.start)?s.end=p.max(s.end,n.end):r.push(n),r},[])}},R=class g extends Nt{constructor(e){if(he(e)&&(e=e.value),e instanceof g||typeof e=="string"||typeof e.valueOf()=="string")super(e.valueOf());else{const r=g.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);if(r==null)throw new Error(`unable to find data type for ${e.toString()}`);super(r.valueOf())}}get Array(){const e=g.ARRAY_CONSTRUCTORS.get(this.toString());if(e==null)throw new Error(`unable to find array constructor for ${this.valueOf()}`);return e}equals(e){return this.valueOf()===e.valueOf()}matches(...e){return e.some(r=>this.equals(r))}toString(e=!1){return e?g.SHORT_STRINGS.get(this.valueOf())??this.valueOf():this.valueOf()}get isVariable(){return this.equals(g.JSON)||this.equals(g.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(g.UUID)}get isInteger(){const e=this.toString();return e.startsWith("int")||e.startsWith("uint")}get isFloat(){return this.toString().startsWith("float")}get density(){const e=g.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}get isUnsignedInteger(){return this.equals(g.UINT8)||this.equals(g.UINT16)||this.equals(g.UINT32)||this.equals(g.UINT64)}get isSignedInteger(){return this.equals(g.INT8)||this.equals(g.INT16)||this.equals(g.INT32)||this.equals(g.INT64)}canSafelyCastTo(e){return this.equals(e)?!0:!this.isNumeric||!e.isNumeric||this.isVariable||e.isVariable||this.isUnsignedInteger&&e.isSignedInteger?!1:this.isFloat?e.isFloat&&this.density.valueOf()<=e.density.valueOf():this.equals(g.INT32)&&e.equals(g.FLOAT64)||this.equals(g.INT8)&&e.equals(g.FLOAT32)?!0:this.isInteger&&e.isInteger?this.density.valueOf()<=e.density.valueOf()&&this.isUnsignedInteger===e.isUnsignedInteger:!1}canCastTo(e){return this.isNumeric&&e.isNumeric?!0:this.equals(e)}checkArray(e){return e.constructor===this.Array}get usesBigInt(){return g.BIG_INT_TYPES.some(e=>e.equals(this))}static UNKNOWN=new g("unknown");static FLOAT64=new g("float64");static FLOAT32=new g("float32");static INT64=new g("int64");static INT32=new g("int32");static INT16=new g("int16");static INT8=new g("int8");static UINT64=new g("uint64");static UINT32=new g("uint32");static UINT16=new g("uint16");static UINT8=new g("uint8");static BOOLEAN=new g("boolean");static TIMESTAMP=new g("timestamp");static UUID=new g("uuid");static STRING=new g("string");static JSON=new g("json");static ARRAY_CONSTRUCTORS=new Map([[g.UINT8.toString(),Uint8Array],[g.UINT16.toString(),Uint16Array],[g.UINT32.toString(),Uint32Array],[g.UINT64.toString(),BigUint64Array],[g.FLOAT32.toString(),Float32Array],[g.FLOAT64.toString(),Float64Array],[g.INT8.toString(),Int8Array],[g.INT16.toString(),Int16Array],[g.INT32.toString(),Int32Array],[g.INT64.toString(),BigInt64Array],[g.TIMESTAMP.toString(),BigInt64Array],[g.STRING.toString(),Uint8Array],[g.JSON.toString(),Uint8Array],[g.UUID.toString(),Uint8Array]]);static ARRAY_CONSTRUCTOR_DATA_TYPES=new Map([[Uint8Array.name,g.UINT8],[Uint16Array.name,g.UINT16],[Uint32Array.name,g.UINT32],[BigUint64Array.name,g.UINT64],[Float32Array.name,g.FLOAT32],[Float64Array.name,g.FLOAT64],[Int8Array.name,g.INT8],[Int16Array.name,g.INT16],[Int32Array.name,g.INT32],[BigInt64Array.name,g.INT64]]);static DENSITIES=new Map([[g.UINT8.toString(),Q.BIT8],[g.UINT16.toString(),Q.BIT16],[g.UINT32.toString(),Q.BIT32],[g.UINT64.toString(),Q.BIT64],[g.FLOAT32.toString(),Q.BIT32],[g.FLOAT64.toString(),Q.BIT64],[g.INT8.toString(),Q.BIT8],[g.INT16.toString(),Q.BIT16],[g.INT32.toString(),Q.BIT32],[g.INT64.toString(),Q.BIT64],[g.TIMESTAMP.toString(),Q.BIT64],[g.STRING.toString(),Q.UNKNOWN],[g.JSON.toString(),Q.UNKNOWN],[g.UUID.toString(),Q.BIT128]]);static ALL=[g.UNKNOWN,g.FLOAT64,g.FLOAT32,g.INT64,g.INT32,g.INT16,g.INT8,g.UINT64,g.UINT32,g.UINT16,g.UINT8,g.TIMESTAMP,g.UUID,g.STRING,g.JSON];static SHORT_STRINGS=new Map([[g.UINT8.toString(),"u8"],[g.UINT16.toString(),"u16"],[g.UINT32.toString(),"u32"],[g.UINT64.toString(),"u64"],[g.INT8.toString(),"i8"],[g.INT16.toString(),"i16"],[g.INT32.toString(),"i32"],[g.INT64.toString(),"i64"],[g.FLOAT32.toString(),"f32"],[g.FLOAT64.toString(),"f64"],[g.BOOLEAN.toString(),"bool"],[g.TIMESTAMP.toString(),"ts"],[g.UUID.toString(),"uuid"],[g.STRING.toString(),"str"],[g.JSON.toString(),"json"]]);static BIG_INT_TYPES=[g.INT64,g.UINT64,g.TIMESTAMP];static z=i.z.union([i.z.string().transform(e=>new g(e)),i.z.instanceof(g)])},vt=class x extends Nt{constructor(e){he(e)&&(e=e.value),super(e.valueOf())}largerThan(e){return he(e)&&(e=e.value),this.valueOf()>e.valueOf()}smallerThan(e){return he(e)&&(e=e.value),this.valueOf()<e.valueOf()}add(e){return he(e)&&(e=e.value),new x(St(this.valueOf(),e.valueOf()))}sub(e){return he(e)&&(e=e.value),new x(Ue(this.valueOf(),e.valueOf()))}mult(e){return new x(me(this.valueOf(),e))}div(e){return new x(sr(this.valueOf(),e))}truncate(e){return new x(Math.trunc(this.valueOf()/new x(e).valueOf())*new x(e).valueOf())}remainder(e){return x.bytes(this.valueOf()%new x(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),r=this.truncate(x.GIGABYTE),n=this.truncate(x.MEGABYTE),s=this.truncate(x.KILOBYTE),a=this.truncate(x.BYTE),o=e,c=r.sub(e),l=n.sub(r),u=s.sub(n),h=a.sub(s);let d="";return o.isZero||(d+=`${o.terabytes}TB `),c.isZero||(d+=`${c.gigabytes}GB `),l.isZero||(d+=`${l.megabytes}MB `),u.isZero||(d+=`${u.kilobytes}KB `),(!h.isZero||d==="")&&(d+=`${h.valueOf()}B`),d.trim()}static bytes(e=1){return new x(e)}static BYTE=new x(1);static kilobytes(e=1){return x.bytes(new x(e).valueOf()*1e3)}static KILOBYTE=x.kilobytes(1);static megabytes(e=1){return x.kilobytes(new x(e).valueOf()*1e3)}static MEGABYTE=x.megabytes(1);static gigabytes(e=1){return x.megabytes(new x(e).valueOf()*1e3)}static GIGABYTE=x.gigabytes(1);static terabytes(e){return x.gigabytes(new x(e).valueOf()*1e3)}static TERABYTE=x.terabytes(1);static ZERO=new x(0);static z=i.z.union([i.z.number().transform(e=>new x(e)),i.z.instanceof(x)]);get isZero(){return this.valueOf()===0}};i.z.object({start:i.z.number(),end:i.z.number()});i.z.union([i.z.instanceof(Uint8Array),i.z.instanceof(Uint16Array),i.z.instanceof(Uint32Array),i.z.instanceof(BigUint64Array),i.z.instanceof(Float32Array),i.z.instanceof(Float64Array),i.z.instanceof(Int8Array),i.z.instanceof(Int16Array),i.z.instanceof(Int32Array),i.z.instanceof(BigInt64Array)]);const ko=t=>{const e=typeof t;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||t instanceof p||t instanceof I||t instanceof Date},Sp=(t,e,r,n=0)=>t.usesBigInt&&!e.usesBigInt?Number(r)-Number(n):!t.usesBigInt&&e.usesBigInt?BigInt(r.valueOf())-BigInt(n.valueOf()):xr(r,-n),xr=(t,e)=>e==0?t:t==0?e:typeof t=="bigint"&&typeof e=="bigint"||typeof t=="number"&&typeof e=="number"?t+e:Number(t)+Number(e),Ip=/^(?:[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 kp(t){return typeof t=="string"&&Ip.test(t)}const X=[];for(let t=0;t<256;++t)X.push((t+256).toString(16).slice(1));function Ap(t,e=0){return(X[t[e+0]]+X[t[e+1]]+X[t[e+2]]+X[t[e+3]]+"-"+X[t[e+4]]+X[t[e+5]]+"-"+X[t[e+6]]+X[t[e+7]]+"-"+X[t[e+8]]+X[t[e+9]]+"-"+X[t[e+10]]+X[t[e+11]]+X[t[e+12]]+X[t[e+13]]+X[t[e+14]]+X[t[e+15]]).toLowerCase()}function xp(t,e=0){const r=Ap(t,e);if(!kp(r))throw TypeError("Stringified UUID is invalid");return r}typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto);const Ao=(t,e)=>xp(t,e),_e=-1,Gn={[Symbol.iterator]:()=>Gn,next:()=>({done:!0,value:void 0})},Zp=i.z.string().transform(t=>new Uint8Array(atob(t).split("").map(e=>e.charCodeAt(0))).buffer),Cp=i.z.union([i.z.null(),i.z.undefined()]).transform(()=>new Uint8Array().buffer),Jn=10,xo=(t,e)=>{if(t==="number"&&!e.isNumeric)throw new Error(`cannot convert series of type ${e.toString()} to number`);if(t==="bigint"&&!e.usesBigInt)throw new Error(`cannot convert series of type ${e.toString()} to bigint`)},Zo="sy_x_telem_series";let Ae=class Pe{key;discriminator=Zo;dataType;sampleOffset;gl;_data;timeRange=P.ZERO;alignment=0n;alignmentMultiple=1n;cachedMin;cachedMax;writePos=_e;_refCount=0;cachedLength;_cachedIndexes;static crudeZ=i.z.object({timeRange:P.z.optional(),dataType:R.z,alignment:i.z.coerce.bigint().optional(),data:i.z.union([Zp,Cp,i.z.instanceof(ArrayBuffer),i.z.instanceof(Uint8Array)]),glBufferUsage:Op.optional().default("static").optional()});static z=Pe.crudeZ.transform(e=>new Pe(e));constructor(e){Rp(e)&&(e={data:e}),e.data??=[];const{dataType:r,timeRange:n,sampleOffset:s=0,glBufferUsage:a="static",alignment:o=0n,alignmentMultiple:c=1n,key:l=As(),data:u}=e;if(Co(u)){const f=u;this.key=f.key,this.dataType=f.dataType,this.sampleOffset=f.sampleOffset,this.gl=f.gl,this._data=f._data,this.timeRange=f.timeRange,this.alignment=f.alignment,this.alignmentMultiple=f.alignmentMultiple,this.cachedMin=f.cachedMin,this.cachedMax=f.cachedMax,this.writePos=f.writePos,this._refCount=f._refCount,this.cachedLength=f.cachedLength;return}const h=ko(u),d=Array.isArray(u);if(r!=null)this.dataType=new R(r);else{if(u 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 f=u;if(!h){if(u.length===0)throw new Error("cannot infer data type from a zero length JS array when constructing a Series. Please provide a data type.");f=u[0]}if(typeof f=="string")this.dataType=R.STRING;else if(typeof f=="number")this.dataType=R.FLOAT64;else if(typeof f=="bigint")this.dataType=R.INT64;else if(typeof f=="boolean")this.dataType=R.BOOLEAN;else if(f instanceof p||f instanceof Date||f instanceof p)this.dataType=R.TIMESTAMP;else if(typeof f=="object")this.dataType=R.JSON;else throw new Error(`cannot infer data type of ${typeof f} when constructing a Series from a JS array`)}else this.dataType=new R(u)}if(!d&&!h)this._data=u;else if(d&&u.length===0)this._data=new this.dataType.Array([]).buffer;else{let f=h?[u]:u;const v=f[0];(v instanceof p||v instanceof Date||v instanceof I)&&(f=f.map(S=>new p(S).valueOf())),this.dataType.equals(R.STRING)?(this.cachedLength=f.length,this._data=new TextEncoder().encode(`${f.join(`
|
|
9
9
|
`)}
|
|
10
|
-
`).buffer):this.dataType.equals(
|
|
10
|
+
`).buffer):this.dataType.equals(R.JSON)?(this.cachedLength=f.length,this._data=new TextEncoder().encode(`${f.map(S=>Bt.encodeString(S)).join(`
|
|
11
11
|
`)}
|
|
12
|
-
`).buffer):this.dataType.usesBigInt&&typeof
|
|
13
|
-
`).slice(0,-1):Array.from(this).map(e=>e.toString())}parseJSON(e){if(!this.dataType.equals($.JSON))throw new Error("cannot parse non-JSON series as JSON");return this.toStrings().map(t=>e.parse(Tt.decodeString(t)))}get byteCapacity(){return new et(this.underlyingData.byteLength)}get capacity(){return this.dataType.isVariable?this.byteCapacity.valueOf():this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===Ne?this.byteCapacity:this.dataType.isVariable?new et(this.writePos):this.dataType.density.size(this.writePos)}get length(){return this.cachedLength!=null?this.cachedLength:this.dataType.isVariable?this.calculateCachedLength():this.writePos===Ne?this.byteCapacity.valueOf()/this.dataType.density.valueOf():this.writePos}calculateCachedLength(){if(!this.dataType.isVariable)throw new Error("cannot calculate length of a non-variable length data type");let e=0;const t=[0];return this.data.forEach((n,i)=>{n===ln&&(e++,t.push(i+1))}),this._cachedIndexes=t,this.cachedLength=e,e}convert(e,t=0){if(this.dataType.equals(e))return this;const n=new e.Array(this.length);for(let i=0;i<this.length;i++)n[i]=Dh(this.dataType,e,this.data[i],t);return new Ae({data:n.buffer,dataType:e,timeRange:this.timeRange,sampleOffset:t,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment})}calcRawMax(){if(this.length===0)return-1/0;if(this.dataType.equals($.TIMESTAMP))this.cachedMax=this.data[this.data.length-1];else if(this.dataType.usesBigInt){const e=this.data;this.cachedMax=e.reduce((t,n)=>t>n?t:n)}else{const e=this.data;this.cachedMax=e.reduce((t,n)=>t>n?t:n)}return this.cachedMax}get max(){return this.calcMax()}calcMax(){if(this.dataType.isVariable)throw new Error("cannot calculate maximum on a variable length data type");return this.writePos===0?-1/0:(this.cachedMax??=this.calcRawMax(),nr(this.cachedMax,this.sampleOffset))}calcRawMin(){if(this.length===0)return 1/0;if(this.dataType.equals($.TIMESTAMP))this.cachedMin=this.data[0];else if(this.dataType.usesBigInt){const e=this.data;this.cachedMin=e.reduce((t,n)=>t<n?t:n)}else{const e=this.data;this.cachedMin=e.reduce((t,n)=>t<n?t:n)}return this.cachedMin}get min(){return this.calcMin()}calcMin(){if(this.dataType.isVariable)throw new Error("cannot calculate minimum on a variable length data type");return this.writePos===0?1/0:(this.cachedMin??=this.calcRawMin(),nr(this.cachedMin,this.sampleOffset))}get bounds(){return V(Number(this.min),Number(this.max),{makeValid:!1})}maybeRecomputeMinMax(e){if(this.cachedMin!=null){const t=e.cachedMin??e.calcRawMin();t<this.cachedMin&&(this.cachedMin=t)}if(this.cachedMax!=null){const t=e.cachedMax??e.calcRawMax();t>this.cachedMax&&(this.cachedMax=t)}}atAlignment(e,t){const n=Number((e-this.alignment)/this.alignmentMultiple);if(n<0||n>=this.length){if(t===!0)throw new Error(`[series] - no value at index ${n}`);return}return this.at(n,t)}at(e,t=!1){if(this.dataType.isVariable)return this.atVariable(e,t??!1);if(this.dataType.equals($.UUID))return this.atUUID(e,t);e<0&&(e=this.length+e);const n=this.data[e];if(n==null){if(t===!0)throw new Error(`[series] - no value at index ${e}`);return}return nr(n,this.sampleOffset)}atUUID(e,t){e<0&&(e=this.length+e);const n=ea(new Uint8Array(this.buffer,e*this.dataType.density.valueOf()));if(n==null){if(t)throw new Error(`[series] - no value at index ${e}`);return}return n}atVariable(e,t){let n=0,i=0;if(this._cachedIndexes!=null)n=this._cachedIndexes[e],i=this._cachedIndexes[e+1]-1;else{e<0&&(e=this.length+e);for(let o=0;o<this.data.length;o++)if(this.data[o]===ln){if(e===0){i=o;break}n=o+1,e--}if(i===0&&(i=this.data.length),n>=i||e>0){if(t)throw new Error(`[series] - no value at index ${e}`);return}}const a=this.data.slice(n,i);return this.dataType.equals($.STRING)?new TextDecoder().decode(a):An(JSON.parse(new TextDecoder().decode(a)))}binarySearch(e){let t=0,n=this.length-1;const i=pr(e);for(;t<=n;){const a=Math.floor((t+n)/2),o=i(this.at(a,!0),e);if(o===0)return a;o<0?t=a+1:n=a-1}return t}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals($.FLOAT32)&&!this.dataType.equals($.UINT8))throw new Error("Only FLOAT32 and UINT8 arrays can be used in WebGL");const{buffer:t,bufferUsage:n,prevBuffer:i}=this.gl;if(t==null&&(this.gl.buffer=e.createBuffer()),this.writePos!==i)if(e.bindBuffer(e.ARRAY_BUFFER,this.gl.buffer),this.writePos!==Ne){i===0&&e.bufferData(e.ARRAY_BUFFER,this.byteCapacity.valueOf(),e.STATIC_DRAW);const a=this.dataType.density.size(i).valueOf(),o=this.underlyingData.slice(this.gl.prevBuffer,this.writePos);e.bufferSubData(e.ARRAY_BUFFER,a,o.buffer),this.gl.prevBuffer=this.writePos}else e.bufferData(e.ARRAY_BUFFER,this.buffer,n==="static"?e.STATIC_DRAW:e.DYNAMIC_DRAW),this.gl.prevBuffer=Ne}as(e){return ta(e,this.dataType),this}get digest(){return{key:this.key,dataType:this.dataType.toString(),sampleOffset:this.sampleOffset,alignment:{lower:Ts(this.alignmentBounds.lower),upper:Ts(this.alignmentBounds.upper),multiple:this.alignmentMultiple},timeRange:this.timeRange.toString(),length:this.length,capacity:this.capacity}}get alignmentBounds(){return V(this.alignment,this.alignment+BigInt(this.length)*this.alignmentMultiple)}maybeGarbageCollectGLBuffer(e){this.gl.buffer!=null&&(e.deleteBuffer(this.gl.buffer),this.gl.buffer=null,this.gl.prevBuffer=0,this.gl.control=null)}get glBuffer(){if(this.gl.buffer==null)throw new Error("gl buffer not initialized");return this.gl.prevBuffer!==this.writePos&&console.warn("buffer not updated"),this.gl.buffer}[Symbol.iterator](){if(this.dataType.isVariable){const e=new Vh(this);return this.dataType.equals($.JSON)?new Hh(e):e}return this.dataType.equals($.UUID)?new _h(this):new Wh(this)}slice(e,t){return this.sliceSub(!1,e,t)}sub(e,t){return this.sliceSub(!0,e,t)}subIterator(e,t){return new bs(this,e,t??this.length)}subAlignmentIterator(e,t){const n=Math.ceil(Number(e-this.alignment)/Number(this.alignmentMultiple)),i=Math.ceil(Number(t-this.alignment)/Number(this.alignmentMultiple));return new bs(this,n,i)}subBytes(e,t){if(e>=0&&(t==null||t>=this.byteLength.valueOf()))return this;const n=this.data.subarray(e,t);return new Ae({data:n,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(e)})}sliceSub(e,t,n){if(t<=0&&(n==null||n>=this.length))return this;let i;return e?i=this.data.subarray(t,n):i=this.data.slice(t,n),new Ae({data:i,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(t)})}reAlign(e){return new Ae({data:this.buffer,dataType:this.dataType,timeRange:M.ZERO,sampleOffset:this.sampleOffset,glBufferUsage:"static",alignment:e})}toString(){let e=`Series(${this.dataType.toString()} ${this.length} [`;if(this.length<=10)e+=Array.from(this).map(t=>t.toString());else{for(let t=0;t<5;t++)e+=`${this.at(t)?.toString()}`,e+=",";e+="...,";for(let t=-5;t<0;t++)e+=this.at(t)?.toString(),t<-1&&(e+=",")}return e+="])",e}};const Yh=r=>r==null?!1:Array.isArray(r)||r instanceof ArrayBuffer||ArrayBuffer.isView(r)&&!(r instanceof DataView)||r instanceof ge?!0:Qi(r),na=jh(ra,ge);let bs=class{series;end;index;constructor(e,t,n){this.series=e;const i=V(0,e.length+1);this.end=ms(i,n),this.index=ms(i,t)}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}},Vh=class{series;index;decoder;constructor(e){if(!e.dataType.isVariable)throw new Error("cannot create a variable series iterator for a non-variable series");this.series=e,this.index=0,this.decoder=new TextDecoder}next(){const e=this.index,t=this.series.data;for(;this.index<t.length&&t[this.index]!==ln;)this.index++;const n=this.index;return e===n?{done:!0,value:void 0}:(this.index++,{done:!1,value:this.decoder.decode(this.series.buffer.slice(e,n))})}},Hh=class sa{wrapped;static schema=s.z.record(s.z.string(),s.z.unknown());constructor(e){this.wrapped=e}next(){const e=this.wrapped.next();return e.done===!0?{done:!0,value:void 0}:{done:!1,value:Tt.decodeString(e.value,sa.schema)}}},_h=class{series;index;data;density;constructor(e){if(!e.dataType.equals($.UUID))throw new Error("cannot create a UUID series iterator for a non-UUID series");this.series=e,this.index=0,this.data=new Uint8Array(e.buffer),this.density=$.UUID.density.valueOf()}next(){if(this.index>=this.series.length)return{done:!0,value:void 0};const e=ea(this.data,this.index*this.density);return this.index++,{done:!1,value:e}}},Wh=class{series;index;constructor(e){this.series=e,this.index=0}next(){return this.index>=this.series.length?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}};class ia{series;constructor(e=[]){if(e.length!==0){const t=e[0].dataType;for(let n=1;n<e.length;n++)if(!e[n].dataType.equals(t))throw new Error("[multi-series] - series must have the same data type")}this.series=e}as(e){return ta(e,this.dataType),this}get dataType(){return this.series.length===0?$.UNKNOWN:this.series[0].dataType}get timeRange(){return this.series.length===0?M.ZERO:new M(this.series[0].timeRange.start,this.series[this.series.length-1].timeRange.end)}get alignment(){return this.series.length===0?0n:this.series[0].alignment}get alignmentBounds(){return this.series.length===0?V(0n,0n):V(this.series[0].alignmentBounds.lower,this.series[this.series.length-1].alignmentBounds.upper)}push(e){const t=()=>new Error(`cannot push a ${e.dataType.toString()} series to a ${this.dataType.toString()} multi-series`),n=e.dataType.equals(this.dataType);if(na(e)){if(this.series.length!==0&&!n)throw t();this.series.push(e)}else{if(this.series.length!==0&&e.series.length!==0&&!n)throw t();this.series.push(...e.series)}}get length(){return this.series.reduce((e,t)=>e+t.length,0)}atAlignment(e,t){for(const n of this.series)if(Gt(n.alignmentBounds,e))return n.atAlignment(e,t);if(t)throw new Error(`[series] - no value at alignment ${e}`)}at(e,t=!1){e<0&&(e=this.length+e);for(const n of this.series){if(e<n.length)return n.at(e,t);e-=n.length}if(t)throw new Error(`[series] - no value at index ${e}`)}subIterator(e,t){return new Lr(this,e,t??this.length)}subAlignmentIterator(e,t){if(e>=this.alignmentBounds.upper||t<=this.alignmentBounds.lower)return cn;let n=0;for(let a=0;a<this.series.length;a++){const o=this.series[a];if(e<o.alignment)break;if(e>=o.alignmentBounds.upper)n+=o.length;else if(Gt(o.alignmentBounds,e)){n+=Math.ceil(Number(e-o.alignment)/Number(o.alignmentMultiple));break}}let i=0;for(let a=0;a<this.series.length;a++){const o=this.series[a];if(t<o.alignment)break;if(t>=o.alignmentBounds.upper)i+=o.length;else if(Gt(o.alignmentBounds,t)){i+=Math.ceil(Number(t-o.alignment)/Number(o.alignmentMultiple));break}}return new Lr(this,n,i)}subAlignmentSpanIterator(e,t){if(e>=this.alignmentBounds.upper)return cn;t=Math.min(t,Number(this.distance(e,this.alignmentBounds.upper)));let n=0;for(let i=0;i<this.series.length;i++){const a=this.series[i];if(e<a.alignment)break;if(e>=a.alignmentBounds.upper)n+=a.length;else if(Gt(a.alignmentBounds,e)){n+=Number(e-a.alignment);break}}return new Lr(this,n,n+t)}updateGLBuffer(e){this.series.forEach(t=>t.updateGLBuffer(e))}get bounds(){return Bu(this.series.map(e=>e.bounds))}get byteLength(){return new et(this.series.reduce((e,t)=>e+t.byteLength.valueOf(),0))}get data(){const e=new this.dataType.Array(this.length);let t=0;for(const n of this.series)e.set(n.data,t),t+=n.length;return new this.dataType.Array(e.buffer)}traverseAlignment(e,t){const n=this.series.map(i=>i.alignmentBounds);return qu(n,e,t)}acquire(e){this.series.forEach(t=>t.acquire(e))}release(){this.series.forEach(e=>e.release())}distance(e,t){const n=this.series.map(i=>i.alignmentBounds);return Fu(n,e,t)}parseJSON(e){if(!this.dataType.equals($.JSON))throw new Error("cannot parse non-JSON series as JSON");return this.series.flatMap(t=>t.parseJSON(e))}[Symbol.iterator](){return this.series.length===0?{next(){return{done:!0,value:void 0}}}:new Gh(this.series)}toStrings(){return this.series.flatMap(e=>e.toStrings())}}let Gh=class{series;seriesIndex;internal;constructor(e){this.series=e,this.seriesIndex=0,this.internal=e[0][Symbol.iterator]()}next(){const e=this.internal.next();return e.done===!1?e:this.seriesIndex===this.series.length-1?{done:!0,value:void 0}:(this.internal=this.series[++this.seriesIndex][Symbol.iterator](),this.next())}[Symbol.iterator](){return this}},Lr=class{series;index;end;constructor(e,t,n){this.series=e,this.end=n,this.index=t}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}[Symbol.iterator](){return this}};const Ts=r=>{const e=r>>32n,t=r&0xffffffffn;return{domain:e,sample:t}},Kh=(r,e)=>{let t=null;return e===0?r:(...n)=>{t!==null&&(clearTimeout(t),t=null),t=setTimeout(()=>r(...n),e)}},un=".",Jh=(r,e,t=un)=>{const n=r.split(t);return n.map((i,a)=>{const o=e(i,a,n);return o==null?null:typeof o=="string"?o:o.join(t)}).filter(i=>i!=null).join(t)},Xh=(r,e)=>{if(!Array.isArray(r))return r[e];const t=r[e];if(t!=null||r.length==0)return t;const n=r[0];if(typeof n=="object"&&"key"in n)return r.find(i=>i.key===e)},Qh=(r,e,t={optional:!1})=>{const{optional:n,getter:i=Xh}=t;if(e==="")return r;const a=e.split(un);if(a.length===1){const c=i(r,a[0]);if(c===void 0){if(n)return null;throw new Error(`Path ${e} does not exist. ${a[0]} is undefined`)}return c}const o=(c,u)=>{if(u>=a.length)return c;for(let l=a.length-u;l>=1;l--){const h=a.slice(u,u+l).join(un),y=i(c,h);if(y!==void 0){if(u+l===a.length)return y;if(y===null){if(n)return null;throw new Error(`Path ${e} does not exist. ${h} is null`)}return o(y,u+l)}}if(n)return null;throw new Error(`Path ${e} does not exist. ${a[u]} is undefined`)};return o(r,0)};s.z.object({key:s.z.string(),value:s.z.string()});let ef=class{handlers;transform;closer;constructor(e,t){this.transform=e,this.handlers=t??new Map}onChange(e){return this.handlers.set(e,null),()=>this.handlers.delete(e)}notify(e){let t=e;if(this.transform!=null){const[n,i]=this.transform(e);if(!i)return;t=n}this.handlers.forEach((n,i)=>i(t))}setCloser(e){this.closer=e}async close(){return await this.closer?.()}},tf=class{handlers;constructor(e){this.handlers=e??new Map}onChange(e){return this.handlers.set(e,null),()=>this.handlers.delete(e)}notify(e){this.handlers.forEach((t,n)=>n(e))}};const rf=Object.freeze(Object.defineProperty({__proto__:null,BaseObserver:tf,Observer:ef},Symbol.toStringTag,{value:"Module"})),nf=s.z.record(s.z.union([s.z.number(),s.z.string(),s.z.symbol()]),s.z.unknown()),Zn=r=>Object.entries(r),sf=(r,e)=>Object.fromEntries(Zn(r).map(([t,n])=>[t,e(n,t)])),af=r=>Object.fromEntries(Zn(r).filter(([e,t])=>t!==void 0)),of=(r,...e)=>{const t={...r};for(const n of e)delete t[n];return t},we=Object.freeze(Object.defineProperty({__proto__:null,entries:Zn,map:sf,omit:of,purgeUndefined:af,unknownZ:nf},Symbol.toStringTag,{value:"Module"})),cf=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser";cf();const lf=["macOS","Windows","Linux"],uf=["macos","windows","linux"],hf={macos:"macOS",windows:"Windows",linux:"Linux"};s.z.enum(lf).or(s.z.enum(uf).transform(r=>hf[r]));const ff=(...r)=>r.map(aa).join(""),aa=r=>(r.endsWith("/")||(r+="/"),r.startsWith("/")&&(r=r.slice(1)),r),df=r=>r.endsWith("/")?r.slice(0,-1):r;class wt{protocol;host;port;path;constructor({host:e,port:t,protocol:n="",pathPrefix:i=""}){this.protocol=n,this.host=e,this.port=t,this.path=aa(i)}replace(e){return new wt({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new wt({...this,pathPrefix:ff(this.path,e)})}toString(){return df(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}static UNKNOWN=new wt({host:"unknown",port:0})}const yf=r=>r.nullable().transform(e=>e===null?void 0:e).optional(),gf=r=>s.array(r).or(r.transform(e=>[e])),oa=r=>Jh(r,(e,t,n)=>{const i=t===n.length-1,a=!isNaN(parseInt(e)),o=!isNaN(parseInt(n[t+1]));return a&&(e="element"),i||o?e:[e,"shape"]}),vs=(r,e)=>{if(r==null)return null;const t=r[e];return t==null&&typeof r=="object"&&"sourceType"in r?r.sourceType()[e]:t},pf=(r,e,t)=>e===""?r:Qh(vs(r,"shape"),oa(e),{...t,getter:vs}),bt=Object.freeze(Object.defineProperty({__proto__:null,getFieldSchema:pf,getFieldSchemaPath:oa,nullToUndefined:yf,toArray:gf},Symbol.toStringTag,{value:"Module"})),mf=async r=>await new Promise(e=>setTimeout(e,E.fromMilliseconds(r).milliseconds));class wf{config;retries;interval;constructor(e){this.config={baseInterval:new E(e?.baseInterval??E.seconds(1)),maxRetries:e?.maxRetries??5,scale:e?.scale??1,sleepFn:e?.sleepFn??mf},this.retries=0,this.interval=new E(this.config.baseInterval)}async wait(){const{maxRetries:e,scale:t,sleepFn:n}=this.config;return this.retries>=e?!1:(await n(this.interval),this.interval=this.interval.mult(t),this.retries++,!0)}get retryMessage(){return`breaker triggered ${this.retries+1}/${this.config.maxRetries} times, retrying in ${this.interval.toString()}`}reset(){this.retries=0,this.interval=this.config.baseInterval}}const bf=s.z.object({baseInterval:E.z.optional(),maxRetries:s.z.number().optional(),scale:s.z.number().optional()}),ca=Object.freeze(Object.defineProperty({__proto__:null,Breaker:wf,breakerConfigZ:bf},Symbol.toStringTag,{value:"Module"})),Tf=/^#?([0-9a-f]{6}|[0-9a-f]{8})$/i,la=s.z.string().regex(Tf),Je=s.z.number().min(0).max(255),ua=s.z.number().min(0).max(1),ha=s.z.tuple([Je,Je,Je,ua]),vf=s.z.tuple([Je,Je,Je]),Ef=s.z.object({rgba255:ha}),Nf=s.z.number().min(0).max(360),Of=s.z.number().min(0).max(100),zf=s.z.number().min(0).max(100),Sf=s.z.tuple([Nf,Of,zf,ua]),Pn=s.z.union([la,vf,ha,Sf,Ef]),Af=Pn.transform(r=>Ln(r)),Ln=(r,e=1)=>{if(r=Pn.parse(r),typeof r=="string")return $f(r,e);if(Array.isArray(r)){if(r.length<3||r.length>4)throw new Error(`Invalid color: [${r.join(", ")}]`);return r.length===3?[...r,e]:r}return r.rgba255},$f=(r,e=1)=>(r=la.parse(r),r=If(r),[Jt(r,0),Jt(r,2),Jt(r,4),r.length===8?Jt(r,6)/255:e]),Jt=(r,e)=>parseInt(r.slice(e,e+2),16),If=r=>r.startsWith("#")?r.slice(1):r;Ln("#000000");Ln("#ffffff");const kf=s.z.object({key:s.z.string(),color:Pn,position:s.z.number(),switched:s.z.boolean().optional()});s.z.array(kf);const xf=s.z.object({key:s.z.string(),name:s.z.string(),color:Af});s.z.object({key:s.z.string(),name:s.z.string(),swatches:s.z.array(xf)});const fa=s.z.int().min(0).max(255),da=255,ya=0,Cf={lower:ya,upper:da+1},ga=s.z.object({name:s.z.string(),key:s.z.string()}),Nt=r=>s.z.object({subject:ga,resource:r,authority:fa}),Rf=(...r)=>e=>e.filter(t=>{let n=!1;return t.to!=null&&(n=r.includes(t.to.resource)),t.from!=null&&!n&&(n=r.includes(t.from.resource)),n}),pa=r=>s.z.object({from:Nt(r),to:s.z.null()}),ma=r=>s.z.object({from:s.z.null(),to:Nt(r)}),jf=r=>s.z.union([pa(r),ma(r),s.z.object({from:Nt(r),to:Nt(r)})]),te=Object.freeze(Object.defineProperty({__proto__:null,ABSOLUTE_AUTHORITY:da,AUTHORITY_BOUNDS:Cf,ZERO_AUTHORITY:ya,acquireZ:ma,authorityZ:fa,filterTransfersByChannelKey:Rf,releaseZ:pa,stateZ:Nt,subjectZ:ga,transferZ:jf},Symbol.toStringTag,{value:"Module"})),Mf=r=>Object.getOwnPropertySymbols(globalThis).includes(r),Uf=(r,e)=>{const t=Symbol.for(r);if(!Mf(t)){const n=e();Object.defineProperty(globalThis,t,{value:n})}return()=>globalThis[t]},wa="sy_x_error",Df=r=>e=>e!=null&&typeof e=="object"&&"type"in e&&typeof e.type=="string"?e.type.startsWith(r):e instanceof Error?e.message.startsWith(r):typeof e!="string"?!1:e.startsWith(r),Dt=r=>class mt extends Error{static discriminator=wa;discriminator=mt.discriminator;static TYPE=r;type=mt.TYPE;static matches=Df(r);matches=mt.matches;constructor(t,n){super(t,n),this.name=mt.TYPE}static sub(t){return Dt(`${r}.${t}`)}},ba=r=>{if(r==null||typeof r!="object")return!1;const e=r;if(e.discriminator!==wa)return!1;if(!("type"in e))throw new Error(`X Error is missing its type property: ${JSON.stringify(e)}`);return!0},We="unknown",hn="nil";class Zf{providers=[];register(e){this.providers.push(e)}encode(e){if(e==null)return{type:hn,data:""};if(ba(e))for(const t of this.providers){const n=t.encode(e);if(n!=null)return n}if(e instanceof Error)return{type:We,data:e.message};if(typeof e=="string")return{type:We,data:e};try{return{type:We,data:JSON.stringify(e)}}catch{return{type:We,data:"unable to encode error information"}}}decode(e){if(e==null||e.type===hn)return null;if(e.type===We)return new fn(e.data);for(const t of this.providers){const n=t.decode(e);if(n!=null)return n}return new fn(e.data)}}const Bn=Uf("synnax-error-registry",()=>new Zf),Pf=({encode:r,decode:e})=>Bn().register({encode:r,decode:e}),Lf=r=>Bn().encode(r),Bf=r=>r==null?null:Bn().decode(r);class fn extends Dt("unknown"){}const qf=s.z.object({type:s.z.string(),data:s.z.string()});class Ff extends Dt("canceled"){}class Yf extends Dt("not_implemented"){}const me=Object.freeze(Object.defineProperty({__proto__:null,Canceled:Ff,NONE:hn,NotImplemented:Yf,UNKNOWN:We,Unknown:fn,createTyped:Dt,decode:Bf,encode:Lf,isTyped:ba,payloadZ:qf,register:Pf},Symbol.toStringTag,{value:"Module"})),Vf=s.object({jsonrpc:s.literal("2.0"),method:s.string(),params:s.any().optional(),id:s.union([s.string(),s.number(),s.null()]).optional()}),Ta=s.object({jsonrpc:s.literal("2.0"),id:s.union([s.string(),s.number(),s.null()])}),Hf=Ta.extend({result:s.json()}),_f=Ta.extend({error:s.object({code:s.number().int(),message:s.string().optional(),data:s.json().optional()})}),Wf=s.union([Hf,_f]);s.union([Vf,Wf]);const dn=s.z.string().regex(/^\d+\.\d+\.\d+$/),Zt=(r,e,t={})=>{t.checkMajor??=!0,t.checkMinor??=!0,t.checkPatch??=!0;const n=dn.parse(r),i=dn.parse(e),[a,o,c]=n.split(".").map(Number),[u,l,h]=i.split(".").map(Number);if(t.checkMajor){if(a<u)return er;if(a>u)return tr}if(t.checkMinor){if(o<l)return er;if(o>l)return tr}if(t.checkPatch){if(c<h)return er;if(c>h)return tr}return st},Gf=(r,e,t={})=>Si(Zt(r,e,t)),va=(r,e,t={})=>zi(Zt(r,e,t)),Kf=(r,e,t={})=>Oi(Zt(r,e,t)),Jf=({name:r,migrate:e})=>t=>{try{const n=e(t);return console.log(`${r} migrated: ${t.version} -> ${n.version}`),n}catch(n){throw console.log(`${r} failed to migrate from ${t.version}`),console.error(n),n}},Xf=({name:r,migrations:e,targetSchema:t,defaultVersion:n,def:i})=>{const a=Object.keys(e).sort(Zt).pop();if(a==null)return l=>{if(l.version??=n,l.version!==i.version)return console.log(`${r} version ${l.version} is newer than latest version of ${i.version}.
|
|
12
|
+
`).buffer):this.dataType.usesBigInt&&typeof v=="number"?this._data=new this.dataType.Array(f.map(S=>BigInt(Math.round(S)))).buffer:!this.dataType.usesBigInt&&typeof v=="bigint"?this._data=new this.dataType.Array(f.map(Number)).buffer:this._data=new this.dataType.Array(f).buffer}this.key=l,this.alignment=o,this.alignmentMultiple=c,this.sampleOffset=s??0,this.timeRange=n??P.ZERO,this.gl={control:null,buffer:null,prevBuffer:0,bufferUsage:a}}static alloc({capacity:e,dataType:r,...n}){if(e===0)throw new Error("[Series] - cannot allocate an array of length 0");const s=new new R(r).Array(e),a=new Pe({data:s.buffer,dataType:r,...n});return a.writePos=0,a}get refCount(){return this._refCount}acquire(e){this._refCount++,e!=null&&this.updateGLBuffer(e)}release(){this._refCount--,this.refCount===0&&this.gl.control!=null?this.maybeGarbageCollectGLBuffer(this.gl.control):this.refCount<0&&console.warn("cannot release a series with a negative reference count")}write(e){if(!e.dataType.equals(this.dataType))throw new Error("buffer must be of the same type as this array");return this.dataType.isVariable?this.writeVariable(e):this.writeFixed(e)}writeVariable(e){if(this.writePos===_e)return 0;const r=this.byteCapacity.valueOf()-this.writePos,n=e.subBytes(0,r);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===_e)return 0;const r=this.capacity-this.writePos,n=e.sub(0,r);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===_e?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(R.JSON))throw new Error("cannot parse non-JSON series as JSON");return this.toStrings().map(r=>e.parse(Bt.decodeString(r)))}get byteCapacity(){return new vt(this.underlyingData.byteLength)}get capacity(){return this.dataType.isVariable?this.byteCapacity.valueOf():this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===_e?this.byteCapacity:this.dataType.isVariable?new vt(this.writePos):this.dataType.density.size(this.writePos)}get length(){return this.cachedLength!=null?this.cachedLength:this.dataType.isVariable?this.calculateCachedLength():this.writePos===_e?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 r=[0];return this.data.forEach((n,s)=>{n===Jn&&(e++,r.push(s+1))}),this._cachedIndexes=r,this.cachedLength=e,e}convert(e,r=0){if(this.dataType.equals(e))return this;const n=new e.Array(this.length);for(let s=0;s<this.length;s++)n[s]=Sp(this.dataType,e,this.data[s],r);return new Pe({data:n.buffer,dataType:e,timeRange:this.timeRange,sampleOffset:r,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment})}calcRawMax(){if(this.length===0)return-1/0;if(this.dataType.equals(R.TIMESTAMP))this.cachedMax=this.data[this.data.length-1];else if(this.dataType.usesBigInt){const e=this.data;this.cachedMax=e.reduce((r,n)=>r>n?r:n)}else{const e=this.data;this.cachedMax=e.reduce((r,n)=>r>n?r: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(),xr(this.cachedMax,this.sampleOffset))}calcRawMin(){if(this.length===0)return 1/0;if(this.dataType.equals(R.TIMESTAMP))this.cachedMin=this.data[0];else if(this.dataType.usesBigInt){const e=this.data;this.cachedMin=e.reduce((r,n)=>r<n?r:n)}else{const e=this.data;this.cachedMin=e.reduce((r,n)=>r<n?r: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(),xr(this.cachedMin,this.sampleOffset))}get bounds(){return J(Number(this.min),Number(this.max),{makeValid:!1})}maybeRecomputeMinMax(e){if(this.cachedMin!=null){const r=e.cachedMin??e.calcRawMin();r<this.cachedMin&&(this.cachedMin=r)}if(this.cachedMax!=null){const r=e.cachedMax??e.calcRawMax();r>this.cachedMax&&(this.cachedMax=r)}}atAlignment(e,r){const n=Number((e-this.alignment)/this.alignmentMultiple);if(n<0||n>=this.length){if(r===!0)throw new Error(`[series] - no value at index ${n}`);return}return this.at(n,r)}at(e,r=!1){if(this.dataType.isVariable)return this.atVariable(e,r??!1);if(this.dataType.equals(R.UUID))return this.atUUID(e,r);e<0&&(e=this.length+e);const n=this.data[e];if(n==null){if(r===!0)throw new Error(`[series] - no value at index ${e}`);return}return xr(n,this.sampleOffset)}atUUID(e,r){e<0&&(e=this.length+e);const n=Ao(new Uint8Array(this.buffer,e*this.dataType.density.valueOf()));if(n==null){if(r)throw new Error(`[series] - no value at index ${e}`);return}return n}atVariable(e,r){let n=0,s=0;if(this._cachedIndexes!=null)n=this._cachedIndexes[e],s=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]===Jn){if(e===0){s=o;break}n=o+1,e--}if(s===0&&(s=this.data.length),n>=s||e>0){if(r)throw new Error(`[series] - no value at index ${e}`);return}}const a=this.data.slice(n,s);return this.dataType.equals(R.STRING)?new TextDecoder().decode(a):bs(JSON.parse(new TextDecoder().decode(a)))}binarySearch(e){let r=0,n=this.length-1;const s=Wr(e);for(;r<=n;){const a=Math.floor((r+n)/2),o=s(this.at(a,!0),e);if(o===0)return a;o<0?r=a+1:n=a-1}return r}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals(R.FLOAT32)&&!this.dataType.equals(R.UINT8))throw new Error("Only FLOAT32 and UINT8 arrays can be used in WebGL");const{buffer:r,bufferUsage:n,prevBuffer:s}=this.gl;if(r==null&&(this.gl.buffer=e.createBuffer()),this.writePos!==s)if(e.bindBuffer(e.ARRAY_BUFFER,this.gl.buffer),this.writePos!==_e){s===0&&e.bufferData(e.ARRAY_BUFFER,this.byteCapacity.valueOf(),e.STATIC_DRAW);const a=this.dataType.density.size(s).valueOf(),o=this.underlyingData.slice(this.gl.prevBuffer,this.writePos);e.bufferSubData(e.ARRAY_BUFFER,a,o.buffer),this.gl.prevBuffer=this.writePos}else e.bufferData(e.ARRAY_BUFFER,this.buffer,n==="static"?e.STATIC_DRAW:e.DYNAMIC_DRAW),this.gl.prevBuffer=_e}as(e){return xo(e,this.dataType),this}get digest(){return{key:this.key,dataType:this.dataType.toString(),sampleOffset:this.sampleOffset,alignment:{lower:Ei(this.alignmentBounds.lower),upper:Ei(this.alignmentBounds.upper),multiple:this.alignmentMultiple},timeRange:this.timeRange.toString(),length:this.length,capacity:this.capacity}}get alignmentBounds(){return J(this.alignment,this.alignment+BigInt(this.length)*this.alignmentMultiple)}maybeGarbageCollectGLBuffer(e){this.gl.buffer!=null&&(e.deleteBuffer(this.gl.buffer),this.gl.buffer=null,this.gl.prevBuffer=0,this.gl.control=null)}get glBuffer(){if(this.gl.buffer==null)throw new Error("gl buffer not initialized");return this.gl.prevBuffer!==this.writePos&&console.warn("buffer not updated"),this.gl.buffer}[Symbol.iterator](){if(this.dataType.isVariable){const e=new _p(this);return this.dataType.equals(R.JSON)?new jp(e):e}return this.dataType.equals(R.UUID)?new Mp(this):new Dp(this)}slice(e,r){return this.sliceSub(!1,e,r)}sub(e,r){return this.sliceSub(!0,e,r)}subIterator(e,r){return new zi(this,e,r??this.length)}subAlignmentIterator(e,r){const n=Math.ceil(Number(e-this.alignment)/Number(this.alignmentMultiple)),s=Math.ceil(Number(r-this.alignment)/Number(this.alignmentMultiple));return new zi(this,n,s)}subBytes(e,r){if(e>=0&&(r==null||r>=this.byteLength.valueOf()))return this;const n=this.data.subarray(e,r);return new Pe({data:n,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(e)})}sliceSub(e,r,n){if(r<=0&&(n==null||n>=this.length))return this;let s;return e?s=this.data.subarray(r,n):s=this.data.slice(r,n),new Pe({data:s,dataType:this.dataType,timeRange:this.timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(r)})}reAlign(e){return new Pe({data:this.buffer,dataType:this.dataType,timeRange:P.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(r=>r.toString());else{for(let r=0;r<5;r++)e+=`${this.at(r)?.toString()}`,e+=",";e+="...,";for(let r=-5;r<0;r++)e+=this.at(r)?.toString(),r<-1&&(e+=",")}return e+="])",e}};const Rp=t=>t==null?!1:Array.isArray(t)||t instanceof ArrayBuffer||ArrayBuffer.isView(t)&&!(t instanceof DataView)||t instanceof Ae?!0:ko(t),Co=hp(Zo,Ae);class zi{series;end;index;constructor(e,r,n){this.series=e;const s=J(0,e.length+1);this.end=bi(s,n),this.index=bi(s,r)}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}}let _p=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,r=this.series.data;for(;this.index<r.length&&r[this.index]!==Jn;)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))})}},jp=class Ro{wrapped;static schema=i.z.record(i.z.string(),i.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:Bt.decodeString(e.value,Ro.schema)}}};class Mp{series;index;data;density;constructor(e){if(!e.dataType.equals(R.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=R.UUID.density.valueOf()}next(){if(this.index>=this.series.length)return{done:!0,value:void 0};const e=Ao(this.data,this.index*this.density);return this.index++,{done:!1,value:e}}}let Dp=class{series;index;constructor(e){this.series=e,this.index=0}next(){return this.index>=this.series.length?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}};class _o{series;constructor(e=[]){if(e.length!==0){const r=e[0].dataType;for(let n=1;n<e.length;n++)if(!e[n].dataType.equals(r))throw new Error("[multi-series] - series must have the same data type")}this.series=e}as(e){return xo(e,this.dataType),this}get dataType(){return this.series.length===0?R.UNKNOWN:this.series[0].dataType}get timeRange(){return this.series.length===0?P.ZERO:new P(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?J(0n,0n):J(this.series[0].alignmentBounds.lower,this.series[this.series.length-1].alignmentBounds.upper)}push(e){const r=()=>new Error(`cannot push a ${e.dataType.toString()} series to a ${this.dataType.toString()} multi-series`),n=e.dataType.equals(this.dataType);if(Co(e)){if(this.series.length!==0&&!n)throw r();this.series.push(e)}else{if(this.series.length!==0&&e.series.length!==0&&!n)throw r();this.series.push(...e.series)}}get length(){return this.series.reduce((e,r)=>e+r.length,0)}atAlignment(e,r){for(const n of this.series)if(br(n.alignmentBounds,e))return n.atAlignment(e,r);if(r)throw new Error(`[series] - no value at alignment ${e}`)}at(e,r=!1){e<0&&(e=this.length+e);for(const n of this.series){if(e<n.length)return n.at(e,r);e-=n.length}if(r)throw new Error(`[series] - no value at index ${e}`)}subIterator(e,r){return new Nn(this,e,r??this.length)}subAlignmentIterator(e,r){if(e>=this.alignmentBounds.upper||r<=this.alignmentBounds.lower)return Gn;let n=0;for(let a=0;a<this.series.length;a++){const o=this.series[a];if(e<o.alignment)break;if(e>=o.alignmentBounds.upper)n+=o.length;else if(br(o.alignmentBounds,e)){n+=Math.ceil(Number(e-o.alignment)/Number(o.alignmentMultiple));break}}let s=0;for(let a=0;a<this.series.length;a++){const o=this.series[a];if(r<o.alignment)break;if(r>=o.alignmentBounds.upper)s+=o.length;else if(br(o.alignmentBounds,r)){s+=Math.ceil(Number(r-o.alignment)/Number(o.alignmentMultiple));break}}return new Nn(this,n,s)}subAlignmentSpanIterator(e,r){if(e>=this.alignmentBounds.upper)return Gn;r=Math.min(r,Number(this.distance(e,this.alignmentBounds.upper)));let n=0;for(let s=0;s<this.series.length;s++){const a=this.series[s];if(e<a.alignment)break;if(e>=a.alignmentBounds.upper)n+=a.length;else if(br(a.alignmentBounds,e)){n+=Number(e-a.alignment);break}}return new Nn(this,n,n+r)}updateGLBuffer(e){this.series.forEach(r=>r.updateGLBuffer(e))}get bounds(){return gd(this.series.map(e=>e.bounds))}get byteLength(){return new vt(this.series.reduce((e,r)=>e+r.byteLength.valueOf(),0))}get data(){const e=new this.dataType.Array(this.length);let r=0;for(const n of this.series)e.set(n.data,r),r+=n.length;return new this.dataType.Array(e.buffer)}traverseAlignment(e,r){const n=this.series.map(s=>s.alignmentBounds);return wd(n,e,r)}acquire(e){this.series.forEach(r=>r.acquire(e))}release(){this.series.forEach(e=>e.release())}distance(e,r){const n=this.series.map(s=>s.alignmentBounds);return bd(n,e,r)}parseJSON(e){if(!this.dataType.equals(R.JSON))throw new Error("cannot parse non-JSON series as JSON");return this.series.flatMap(r=>r.parseJSON(e))}[Symbol.iterator](){return this.series.length===0?{next(){return{done:!0,value:void 0}}}:new Pp(this.series)}toStrings(){return this.series.flatMap(e=>e.toStrings())}}class Pp{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 Nn{series;index;end;constructor(e,r,n){this.series=e,this.end=n,this.index=r}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 Ei=t=>{const e=t>>32n,r=t&0xffffffffn;return{domain:e,sample:r}},Up=(t,e)=>{let r=null;return e===0?t:(...n)=>{r!==null&&(clearTimeout(r),r=null),r=setTimeout(()=>t(...n),e)}},Lp=(t,e,r=".")=>{const n=t.split(r);return n.map((s,a)=>{const o=e(s,a,n);return o==null?null:typeof o=="string"?o:o.join(r)}).filter(s=>s!=null).join(r)},Bp=(t,e)=>{if(!Array.isArray(t))return t[e];const r=t[e];if(r!=null||t.length==0)return r;const n=t[0];if(typeof n=="object"&&"key"in n)return t.find(s=>s.key===e)},qp=((t,e,r={optional:!1})=>{const{optional:n,getter:s=Bp}=r;if(e==="")return t;const a=e.split(".");if(a.length===1){const c=s(t,a[0]);if(c===void 0){if(n)return null;throw new Error(`Path ${e} does not exist. ${a[0]} is undefined`)}return c}const o=(c,l)=>{if(l>=a.length)return c;for(let u=a.length-l;u>=1;u--){const h=a.slice(l,l+u).join("."),d=s(c,h);if(d!==void 0){if(l+u===a.length)return d;if(d===null){if(n)return null;throw new Error(`Path ${e} does not exist. ${h} is null`)}return o(d,l+u)}}if(n)return null;throw new Error(`Path ${e} does not exist. ${a[l]} is undefined`)};return o(t,0)});i.z.object({key:i.z.string(),value:i.z.string()});let Fp=class{handlers;transform;closer;constructor(e,r){this.transform=e,this.handlers=r??new Map}onChange(e){return this.handlers.set(e,null),()=>this.handlers.delete(e)}notify(e){let r=e;if(this.transform!=null){const[n,s]=this.transform(e);if(!s)return;r=n}this.handlers.forEach((n,s)=>s(r))}setCloser(e){this.closer=e}async close(){return await this.closer?.()}},Vp=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((r,n)=>n(e))}};const Yp=Object.freeze(Object.defineProperty({__proto__:null,BaseObserver:Vp,Observer:Fp},Symbol.toStringTag,{value:"Module"})),Wp=i.z.record(i.z.union([i.z.number(),i.z.string(),i.z.symbol()]),i.z.unknown()),xs=t=>Object.entries(t),Hp=(t,e)=>Object.fromEntries(xs(t).map(([r,n])=>[r,e(n,r)])),Gp=t=>Object.fromEntries(xs(t).filter(([e,r])=>r!==void 0)),Jp=(t,...e)=>{const r={...t};for(const n of e)delete r[n];return r},be=Object.freeze(Object.defineProperty({__proto__:null,entries:xs,map:Hp,omit:Jp,purgeUndefined:Gp,unknownZ:Wp},Symbol.toStringTag,{value:"Module"})),Kp=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser";Kp();const Xp=["macOS","Windows","Linux"],Qp=["macos","windows","linux"],ey={macos:"macOS",windows:"Windows",linux:"Linux"};i.z.enum(Xp).or(i.z.enum(Qp).transform(t=>ey[t]));const ty=(...t)=>t.map(jo).join(""),jo=t=>(t.endsWith("/")||(t+="/"),t.startsWith("/")&&(t=t.slice(1)),t),ry=t=>t.endsWith("/")?t.slice(0,-1):t;class Ut{protocol;host;port;path;constructor({host:e,port:r,protocol:n="",pathPrefix:s=""}){this.protocol=n,this.host=e,this.port=r,this.path=jo(s)}replace(e){return new Ut({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new Ut({...this,pathPrefix:ty(this.path,e)})}toString(){return ry(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}static UNKNOWN=new Ut({host:"unknown",port:0})}const ny=t=>t.nullable().transform(e=>e===null?void 0:e).optional(),sy=t=>i.array(t).or(t.transform(e=>[e])),Mo=t=>Lp(t,(e,r,n)=>{const s=r===n.length-1,a=!isNaN(parseInt(e)),o=!isNaN(parseInt(n[r+1]));return a&&(e="element"),s||o?e:[e,"shape"]}),Ni=(t,e)=>{if(t==null)return null;const r=t[e];return r==null&&typeof t=="object"&&"sourceType"in t?t.sourceType()[e]:r},iy=((t,e,r)=>e===""?t:qp(Ni(t,"shape"),Mo(e),{...r,getter:Ni})),Lt=Object.freeze(Object.defineProperty({__proto__:null,getFieldSchema:iy,getFieldSchemaPath:Mo,nullToUndefined:ny,toArray:sy},Symbol.toStringTag,{value:"Module"})),ay=2,oy=3,cy=2,uy=(t,e)=>{if(Number.isNaN(t)||!Number.isFinite(t))return t;const r=md(e);if(r==0)return t;let n;r>=1e3?n=ay:r>=1?n=oy:n=Math.ceil(-Math.log10(r))+cy;const s=10**n;return Math.round(t*s)/s},Kn=Object.freeze(Object.defineProperty({__proto__:null,MAX_INT16:vp,MAX_INT32:zp,MAX_INT64:Rr,MAX_INT64_NUMBER:So,MAX_INT8:wp,MAX_UINT16:dp,MAX_UINT32:pp,MAX_UINT64:yp,MAX_UINT64_NUMBER:mp,MAX_UINT8:fp,MIN_INT16:bp,MIN_INT32:Tp,MIN_INT64:Ep,MIN_INT64_NUMBER:Np,MIN_INT8:gp,abs:oo,add:St,closeTo:fd,div:sr,equal:Wn,isInteger:Cr,max:pd,min:ao,mult:me,roundBySpan:uy,roundToNearestMagnitude:dd,sub:Ue},Symbol.toStringTag,{value:"Module"})),ly=async t=>await new Promise(e=>setTimeout(e,I.fromMilliseconds(t).milliseconds));class hy{config;retries;interval;constructor(e){this.config={baseInterval:new I(e?.baseInterval??I.seconds(1)),maxRetries:e?.maxRetries??5,scale:e?.scale??1,sleepFn:e?.sleepFn??ly},this.retries=0,this.interval=new I(this.config.baseInterval)}async wait(){const{maxRetries:e,scale:r,sleepFn:n}=this.config;return this.retries>=e?!1:(await n(this.interval),this.interval=this.interval.mult(r),this.retries++,!0)}get retryMessage(){return`breaker triggered ${this.retries+1}/${this.config.maxRetries} times, retrying in ${this.interval.toString()}`}reset(){this.retries=0,this.interval=this.config.baseInterval}}const fy=i.z.object({baseInterval:I.z.optional(),maxRetries:i.z.number().optional(),scale:i.z.number().optional()}),Do=Object.freeze(Object.defineProperty({__proto__:null,Breaker:hy,breakerConfigZ:fy},Symbol.toStringTag,{value:"Module"})),dy=/^#?([0-9a-f]{6}|[0-9a-f]{8})$/i,Po=i.z.string().regex(dy),mt=i.z.number().min(0).max(255),Uo=i.z.number().min(0).max(1),Lo=i.z.tuple([mt,mt,mt,Uo]),py=i.z.tuple([mt,mt,mt]),yy=i.z.object({rgba255:Lo}),my=i.z.number().min(0).max(360),gy=i.z.number().min(0).max(100),wy=i.z.number().min(0).max(100),by=i.z.tuple([my,gy,wy,Uo]),Zs=i.z.union([Po,py,Lo,by,yy]),vy=Zs.transform(t=>Cs(t)),Cs=(t,e=1)=>{if(t=Zs.parse(t),typeof t=="string")return Ty(t,e);if(Array.isArray(t)){if(t.length<3||t.length>4)throw new Error(`Invalid color: [${t.join(", ")}]`);return t.length===3?[...t,e]:t}return t.rgba255},Ty=(t,e=1)=>(t=Po.parse(t),t=zy(t),[zr(t,0),zr(t,2),zr(t,4),t.length===8?zr(t,6)/255:e]),zr=(t,e)=>parseInt(t.slice(e,e+2),16),zy=t=>t.startsWith("#")?t.slice(1):t;Cs("#000000");Cs("#ffffff");const Ey=i.z.object({key:i.z.string(),color:Zs,position:i.z.number(),switched:i.z.boolean().optional()});i.z.array(Ey);const Ny=i.z.object({key:i.z.string(),name:i.z.string(),color:vy});i.z.object({key:i.z.string(),name:i.z.string(),swatches:i.z.array(Ny)});const Bo=i.z.int().min(0).max(255),qo=255,Fo=0,Oy={lower:Fo,upper:qo+1},Vo=i.z.object({name:i.z.string(),key:i.z.string()}),Vt=t=>i.z.object({subject:Vo,resource:t,authority:Bo}),$y=(...t)=>e=>e.filter(r=>{let n=!1;return r.to!=null&&(n=t.includes(r.to.resource)),r.from!=null&&!n&&(n=t.includes(r.from.resource)),n}),Yo=t=>i.z.object({from:Vt(t),to:i.z.null()}),Wo=t=>i.z.object({from:i.z.null(),to:Vt(t)}),Sy=t=>i.z.union([Yo(t),Wo(t),i.z.object({from:Vt(t),to:Vt(t)})]),fe=Object.freeze(Object.defineProperty({__proto__:null,ABSOLUTE_AUTHORITY:qo,AUTHORITY_BOUNDS:Oy,ZERO_AUTHORITY:Fo,acquireZ:Wo,authorityZ:Bo,filterTransfersByChannelKey:$y,releaseZ:Yo,stateZ:Vt,subjectZ:Vo,transferZ:Sy},Symbol.toStringTag,{value:"Module"})),Iy=t=>Object.getOwnPropertySymbols(globalThis).includes(t),ky=(t,e)=>{const r=Symbol.for(t);if(!Iy(r)){const n=e();Object.defineProperty(globalThis,r,{value:n})}return()=>globalThis[r]},Ho="sy_x_error",Ay=t=>e=>e!=null&&typeof e=="object"&&"type"in e&&typeof e.type=="string"?e.type.startsWith(t):e instanceof Error?e.message.startsWith(t):typeof e!="string"?!1:e.startsWith(t),ir=t=>class Dt extends Error{static discriminator=Ho;discriminator=Dt.discriminator;static TYPE=t;type=Dt.TYPE;static matches=Ay(t);matches=Dt.matches;constructor(r,n){super(r,n),this.name=Dt.TYPE}static sub(r){return ir(`${t}.${r}`)}},Go=t=>{if(t==null||typeof t!="object")return!1;const e=t;if(e.discriminator!==Ho)return!1;if(!("type"in e))throw new Error(`X Error is missing its type property: ${JSON.stringify(e)}`);return!0},ft="unknown",Xn="nil";class xy{providers=[];register(e){this.providers.push(e)}encode(e){if(e==null)return{type:Xn,data:""};if(Go(e))for(const r of this.providers){const n=r.encode(e);if(n!=null)return n}if(e instanceof Error)return{type:ft,data:e.message};if(typeof e=="string")return{type:ft,data:e};try{return{type:ft,data:JSON.stringify(e)}}catch{return{type:ft,data:"unable to encode error information"}}}decode(e){if(e==null||e.type===Xn)return null;if(e.type===ft)return new Qn(e.data);for(const r of this.providers){const n=r.decode(e);if(n!=null)return n}return new Qn(e.data)}}const Rs=ky("synnax-error-registry",()=>new xy),Zy=({encode:t,decode:e})=>Rs().register({encode:t,decode:e}),Cy=t=>Rs().encode(t),Ry=t=>t==null?null:Rs().decode(t);class Qn extends ir("unknown"){}const _y=i.z.object({type:i.z.string(),data:i.z.string()});class jy extends ir("canceled"){}class My extends ir("not_implemented"){}const Ze=Object.freeze(Object.defineProperty({__proto__:null,Canceled:jy,NONE:Xn,NotImplemented:My,UNKNOWN:ft,Unknown:Qn,createTyped:ir,decode:Ry,encode:Cy,isTyped:Go,payloadZ:_y,register:Zy},Symbol.toStringTag,{value:"Module"})),Dy=i.object({jsonrpc:i.literal("2.0"),method:i.string(),params:i.any().optional(),id:i.union([i.string(),i.number(),i.null()]).optional()}),Jo=i.object({jsonrpc:i.literal("2.0"),id:i.union([i.string(),i.number(),i.null()])}),Py=Jo.extend({result:i.json()}),Uy=Jo.extend({error:i.object({code:i.number().int(),message:i.string().optional(),data:i.json().optional()})}),Ly=i.union([Py,Uy]);i.union([Dy,Ly]);const Ko=i.uuid(),Xo=i.object({key:Ko,name:i.string().min(1),color:i.string()}),Qo=Object.freeze(Object.defineProperty({__proto__:null,keyZ:Ko,labelZ:Xo},Symbol.toStringTag,{value:"Module"})),es=i.z.string().regex(/^\d+\.\d+\.\d+$/),ar=((t,e,r={})=>{r.checkMajor??=!0,r.checkMinor??=!0,r.checkPatch??=!0;const n=es.parse(t),s=es.parse(e),[a,o,c]=n.split(".").map(Number),[l,u,h]=s.split(".").map(Number);if(r.checkMajor){if(a<l)return Ir;if(a>l)return kr}if(r.checkMinor){if(o<u)return Ir;if(o>u)return kr}if(r.checkPatch){if(c<h)return Ir;if(c>h)return kr}return Ot}),By=(t,e,r={})=>Qa(ar(t,e,r)),ec=(t,e,r={})=>Xa(ar(t,e,r)),qy=(t,e,r={})=>Ka(ar(t,e,r)),Fy=({name:t,migrate:e})=>r=>{try{const n=e(r);return console.log(`${t} migrated: ${r.version} -> ${n.version}`),n}catch(n){throw console.log(`${t} failed to migrate from ${r.version}`),console.error(n),n}},Vy=({name:t,migrations:e,targetSchema:r,defaultVersion:n,def:s})=>{const a=Object.keys(e).sort(ar).pop();if(a==null)return u=>{if(u.version??=n,u.version!==s.version)return console.log(`${t} version ${u.version} is newer than latest version of ${s.version}.
|
|
14
14
|
Returning default instead.
|
|
15
|
-
`),
|
|
15
|
+
`),s;try{return r!=null?r.parse(u):u}catch(h){return console.log(`${t} failed to parse default. Exiting with default`),console.error(h),s}};const o=Object.keys(e).length;let c=!1;const l=u=>{try{if(o===0||ec(u.version,a))return console.log(c?`${t} ${u.version} now up to date`:`${t} version ${u.version} is up to date with target version ${s.version}`),u;const h=u.version,d=e[h],f=d(u);return c=!0,l(f)}catch(h){return console.log(`${t} failed to migrate from ${u.version} to ${a}`),console.error(h),s}};return u=>{try{if(u.version==null)if(n!=null)console.log(`${t} version is null. Setting version to default of ${n}`),u.version=n;else return console.log(`${t} version is null and no default version set. Exiting with default`),s;return l(u)}catch(h){return console.log(`${t} failed to parse final result. Exiting with default`),console.error(h),s}}},Oi=Object.freeze(Object.defineProperty({__proto__:null,compareSemVer:ar,createMigration:Fy,migrator:Vy,semVerNewer:ec,semVerOlder:qy,semVerZ:es,versionsEqual:By},Symbol.toStringTag,{value:"Module"})),Yy=["standard","scientific","engineering"];i.z.enum(Yy);const tc=i.z.enum(["success","info","warning","error","loading","disabled"]),Wy=t=>i.z.object({key:i.z.string(),name:i.z.string().default(""),variant:tc,message:i.z.string(),description:i.z.string().optional(),time:p.z,labels:Ua(Xo).optional(),details:t??i.z.unknown().optional()}),Hy=i.z.object({stack:i.z.string()}),Gy=(t,e)=>{if(!(t instanceof Error))throw t;return rc({variant:"error",message:e??t.message,description:e!=null?t.message:void 0,details:{stack:t.stack??""}})},rc=t=>({key:As(),time:p.now(),name:"",...t}),Jy=(t,e=[])=>{if(t!=null)return Array.isArray(e)?e.includes(t)?t:void 0:e===t?t:void 0},Ky=(t,e=[])=>{if(t!=null)return Array.isArray(e)?e.includes(t)?void 0:t:e===t?void 0:t},It=Object.freeze(Object.defineProperty({__proto__:null,create:rc,exceptionDetailsSchema:Hy,fromException:Gy,keepVariants:Jy,removeVariants:Ky,statusZ:Wy,variantZ:tc},Symbol.toStringTag,{value:"Module"})),Xy=(t,e="")=>{if(typeof t=="string")return t;const r=t.length;return r===0?e:r===1?t[0]:r===2?`${t[0]} and ${t[1]}`:`${t.slice(0,-1).join(", ")}, and ${t[r-1]}`},Qy=t=>{const e=t.split(" "),r=new Set,n=e.map(o=>o.charAt(0).toLowerCase()).join("");r.add(n.replace(/-/g,"_")),r.add(n.replace(/(.)(.)/g,"$1_$2").replace(/-/g,"_"));const s=/\d+/g;t.match(s)&&e.forEach((o,c)=>{if(s.test(o)){const l=e.map((u,h)=>h!==c?u.charAt(0).toLowerCase():u).join("");r.add(l.replace(/-/g,"_")),r.add(l.replace(/(.)(.)/g,"$1_$2").replace(/-/g,"_"))}});const a=e.map(o=>(o.length>3?o.substring(0,3):o).toLowerCase());return r.add(a.join("").replace(/-/g,"_")),r.add(a.join("_").replace(/-/g,"_")),Array.from(r).filter(o=>o.length>=2&&o.length<=12&&!/^\d/.test(o))},em=(t,e)=>t.startsWith(e)?t.slice(e.length):t,tm=t=>t.length===0?t:t[t.length-1]==="y"?`${t.slice(0,-1)}ies`:t[t.length-1]==="s"||t[t.length-1]==="x"||t[t.length-1]==="z"||t.endsWith("ch")||t.endsWith("sh")?`${t}es`:`${t}s`,ts=Object.freeze(Object.defineProperty({__proto__:null,createShortIdentifiers:Qy,naturalLanguageJoin:Xy,pluralName:tm,trimPrefix:em},Symbol.toStringTag,{value:"Module"})),nc="all",sc="create",ic="delete",ac="retrieve",oc="update",_r=i.z.enum([nc,sc,ic,ac,oc]);class Se extends Ze.createTyped("sy"){}class Y extends Se.sub("validation"){}class Yt extends Y.sub("path"){path;error;static encodedSchema=i.z.object({path:i.z.string().array(),error:Ze.payloadZ});constructor(e,r){const n=T.toArray(e);super(`${n.join(".")}: ${r.message}`),this.path=n.flatMap(s=>s.split(".")),this.error=r}static decode(e){const r=Yt.encodedSchema.parse(JSON.parse(e.data));return new Yt(r.path,Ze.decode(r.error))}}class Wt extends Se.sub("auth"){}class rs extends Wt.sub("invalid_token"){}class ns extends Wt.sub("expired_token"){}class gt extends Se.sub("unexpected"){constructor(e){super(`
|
|
16
16
|
Unexpected error encountered:
|
|
17
17
|
|
|
18
18
|
${e}
|
|
19
19
|
|
|
20
20
|
Please report this to the Synnax team.
|
|
21
|
-
`)}}class xe extends he.sub("query"){}class St extends xe.sub("not_found"){}class At extends xe.sub("multiple_results"){}class mn extends he.sub("route"){path;constructor(e,t){super(e),this.path=t}}class wn extends he.sub("control"){}class Ns extends wn.sub("unauthorized"){}class od extends he.sub("disconnected"){constructor(e="Operation failed because no cluster is connected."){super(e)}}class cd extends he.sub("contiguity"){}const ld=r=>r.type.startsWith(he.TYPE)?r.type.startsWith(Z.TYPE)?r.type===Ot.TYPE?Ot.decode(r):new Z(r.data):r.type.startsWith(zt.TYPE)?r.type.startsWith(gn.TYPE)?new gn(r.data):r.type.startsWith(pn.TYPE)?new pn(r.data):new zt(r.data):r.type.startsWith(Xe.TYPE)?new Xe(r.data):r.type.startsWith(xe.TYPE)?r.type.startsWith(St.TYPE)?new St(r.data):r.type.startsWith(At.TYPE)?new At(r.data):new xe(r.data):r.type.startsWith(wn.TYPE)?r.type.startsWith(Ns.TYPE)?new Ns(r.data):new wn(r.data):r.type.startsWith(mn.TYPE)?new mn(r.data,r.data):new Xe(r.data):null,ud=()=>{throw new me.NotImplemented};me.register({encode:ud,decode:ld});const hd=async(r,e)=>{const[t,n]=await e(r);return n==null?[t,n]:n instanceof Ie?[t,new Ie({message:`Cannot reach cluster at ${n.url.host}:${n.url.port}`,url:n.url})]:[t,n]};class qn{key;name;constructor(e,t){this.key=t,this.name=e}get ontologyID(){return Ia(this.key)}}const Ia=r=>({type:"group",key:r}),Lt=s.z.uuid(),br=s.z.string(),Tr=s.z.object({key:Lt,name:br}),ka="builtin",fd="cluster",dd="node",vr=s.z.enum(["label","log","allow_all","builtin","cluster","channel","node","group","range","framer","range-alias","user","workspace","schematic","lineplot","rack","device","task","policy","table","schematic_symbol"]),yd=s.z.string().transform(r=>{const[e,t]=r.split(":");return{type:vr.parse(e),key:t??""}}),C=s.z.object({type:vr,key:s.z.string()}).or(yd),gd={type:ka,key:"root"},$t=r=>`${r.type}:${r.key}`,pd=(r,e)=>r.type===e.type&&r.key===e.key,xa=r=>{const e=v.toArray(r);return e.length===0?[]:typeof e[0]=="object"&&"id"in e[0]?e.map(({id:t})=>t):e.map(t=>C.parse(t))},Ca=s.z.object({id:C,name:s.z.string(),data:we.unknownZ.optional().nullable()}).transform(r=>({key:$t(r.id),...r})),md=r=>r==="to"?"from":"to",wd=s.z.object({from:C,type:s.z.string(),to:C}).or(s.z.string().transform(r=>{const[e,t,n]=r.split("->");return{from:C.parse(e),type:t,to:C.parse(n)}})),bd=r=>`${$t(r.from)}->${r.type}->${$t(r.to)}`,Td="parent",vd=(r,e)=>!(e.type!=null&&e.type!==r.type||e.from?.type!=null&&e.from.type!==r.from.type||e.to?.type!=null&&e.to.type!==r.to.type||e.from?.key!=null&&e.from.key!==r.from.key||e.to?.key!=null&&e.to.key!==r.to.key),Ed=s.z.object({group:Tr}),Nd=s.z.object({parent:C,key:Lt.optional(),name:br}),Od=s.z.object({key:Lt,name:br}),zd=s.z.object({keys:s.z.array(Lt)});let Sd=class sr{static CREATE_ENDPOINT="/ontology/create-group";static RENAME_ENDPOINT="/ontology/rename-group";static DELETE_ENDPOINT="/ontology/delete-group";client;constructor(e){this.client=e}async create(e,t,n){return(await m(this.client,sr.CREATE_ENDPOINT,{parent:e,name:t,key:n},Nd,Ed)).group}async rename(e,t){await m(this.client,sr.RENAME_ENDPOINT,{key:e,name:t},Od,s.z.object({}))}async delete(e){await m(this.client,sr.DELETE_ENDPOINT,{keys:e},zd,s.z.object({}))}};const Ad="sy_group_set",$d="sy_group_delete";let Ra=class{creator;constructor(e){this.creator=new Sd(e)}async create(e,t,n){return this.sugar(await this.creator.create(e,t,n))}async rename(e,t){return await this.creator.rename(e,t)}async delete(...e){return await this.creator.delete(e)}sugar(e){return new qn(e.name,e.key)}};const Id=Object.freeze(Object.defineProperty({__proto__:null,Client:Ra,DELETE_CHANNEL_NAME:$d,Group:qn,SET_CHANNEL_NAME:Ad,groupZ:Tr,keyZ:Lt,nameZ:br,ontologyID:Ia},Symbol.toStringTag,{value:"Module"})),kd="/ontology/add-children",xd="/ontology/remove-children",Cd="/ontology/move-children",Os=s.z.object({id:C,children:C.array()}),Rd=s.z.object({from:C,to:C,children:C.array()}),Br=s.z.object({});let jd=class{client;constructor(e){this.client=e}async addChildren(e,...t){await m(this.client,kd,{id:e,children:t},Os,Br)}async removeChildren(e,...t){await m(this.client,xd,{id:e,children:t},Os,Br)}async moveChildren(e,t,...n){await m(this.client,Cd,{from:e,to:t,children:n},Rd,Br)}};const Md="/ontology/retrieve",Ud=s.z.object({ids:C.array().optional(),children:s.z.boolean().optional(),parents:s.z.boolean().optional(),excludeFieldData:s.z.boolean().optional(),searchTerm:s.z.string().optional(),limit:s.z.number().optional(),offset:s.z.number().optional(),types:vr.array().optional()}),Dd=s.z.object({resources:Ca.array()});let ja=class{type="ontology";groups;client;writer;framer;constructor(e,t){this.client=e,this.writer=new jd(e),this.groups=new Ra(e),this.framer=t}async retrieve(e,t){if(!Array.isArray(e)&&typeof e=="object"&&!("key"in e))return this.execRetrieve(e);const n=xa(e),i=await this.execRetrieve({ids:n,...t});if(Array.isArray(e))return i;if(i.length===0)throw new xe(`No resource found with ID ${yn.naturalLanguageJoin(n.map(a=>$t(a)))}`);return i[0]}async retrieveChildren(e,t){return await this.execRetrieve({ids:v.toArray(e),children:!0,...t})}async retrieveParents(e,t){return await this.execRetrieve({ids:v.toArray(e),parents:!0,...t})}async addChildren(e,...t){return await this.writer.addChildren(e,...t)}async removeChildren(e,...t){return await this.writer.removeChildren(e,...t)}async moveChildren(e,t,...n){return await this.writer.moveChildren(e,t,...n)}async execRetrieve(e){const{resources:t}=await m(this.client,Md,e,Ud,Dd);return t}};const Zd="sy_ontology_resource_set",Pd="sy_ontology_resource_delete",Ld="sy_ontology_relationship_set",Bd="sy_ontology_relationship_delete",qd=Object.freeze(Object.defineProperty({__proto__:null,BUILTIN_TYPE:ka,CLUSTER_TYPE:fd,Client:ja,NODE_TYPE:dd,PARENT_OF_RELATIONSHIP_TYPE:Td,RELATIONSHIP_DELETE_CHANNEL_NAME:Bd,RELATIONSHIP_SET_CHANNEL_NAME:Ld,RESOURCE_DELETE_CHANNEL_NAME:Pd,RESOURCE_SET_CHANNEL_NAME:Zd,ROOT_ID:gd,idToString:$t,idZ:C,idsEqual:pd,matchRelationship:vd,oppositeRelationshipDirection:md,parseIDs:xa,relationshipToString:bd,relationshipZ:wd,resourceTypeZ:vr,resourceZ:Ca},Symbol.toStringTag,{value:"Module"})),L=r=>s.z.union([s.z.union([s.z.null(),s.z.undefined()]).transform(()=>[]),r.array()]),it=s.z.uuid(),Er=s.z.object({key:it,subjects:L(C),objects:L(C),actions:L(or)}),Ma=s.z.object({key:it.optional(),subjects:C.array().or(C),objects:C.array().or(C),actions:or.array().or(or)}),Fd=s.z.object({keys:it.array().optional(),subjects:C.array().optional()}),Yd=s.z.object({key:it}).transform(({key:r})=>({keys:[r]})),Vd=s.z.union([s.z.object({for:C}).transform(({for:r})=>({subjects:[r]})),s.z.object({for:C.array()}).transform(({for:r})=>({subjects:r})),Fd]),Hd=s.z.union([Yd,Vd]),_d=s.z.object({policies:L(Er)}),Wd=s.z.object({policies:Er.partial({key:!0}).array()}),Gd=s.z.object({policies:Er.array()}),Kd=s.z.object({keys:it.array()}),Jd=s.z.object({}),Xd="/access/policy/retrieve",Qd="/access/policy/create",ey="/access/policy/delete";let Ua=class{client;constructor(e){this.client=e}async create(e){const t=Array.isArray(e),i=Ma.array().parse(v.toArray(e)).map(o=>({objects:v.toArray(o.objects),actions:v.toArray(o.actions),subjects:v.toArray(o.subjects)})),a=await m(this.client,Qd,{policies:i},Wd,Gd);return t?a.policies:a.policies[0]}async retrieve(e){const t="key"in e,n=await m(this.client,Xd,e,Hd,_d);return t?n.policies[0]:n.policies}async delete(e){await m(this.client,ey,{keys:v.toArray(e)},Kd,Jd)}};const ty=r=>({type:"policy",key:r}),ry={type:"allow_all",key:""},ny=Object.freeze(Object.defineProperty({__proto__:null,ALLOW_ALL_ONTOLOGY_ID:ry,Client:Ua,keyZ:it,newZ:Ma,ontologyID:ty,policyZ:Er},Symbol.toStringTag,{value:"Module"}));let Da=class{policy;constructor(e){this.policy=new Ua(e)}};const sy=Object.freeze(Object.defineProperty({__proto__:null,ALL_ACTION:Oa,CREATE_ACTION:za,Client:Da,DELETE_ACTION:Sa,RETRIEVE_ACTION:Aa,UPDATE_ACTION:$a,actionZ:or},Symbol.toStringTag,{value:"Module"})),zs="Channel key must be a valid uint32.",j=s.z.uint32().or(s.z.string().refine(r=>!isNaN(Number(r)),{message:zs}).transform(Number).refine(r=>r<2**32-1,{message:zs})),pe=s.z.string(),Za=Pt.statusZ(),at=s.z.object({name:pe,key:j,dataType:$.z,leaseholder:s.z.number(),index:j,isIndex:s.z.boolean(),internal:s.z.boolean(),virtual:s.z.boolean(),alias:s.z.string().optional(),expression:s.z.string().default(""),requires:L(j),status:Za.optional()}),Pa=at.extend({key:j.optional(),leaseholder:s.z.number().optional(),index:j.optional(),isIndex:s.z.boolean().optional(),internal:s.z.boolean().optional().default(!1),virtual:s.z.boolean().optional().default(!1),expression:s.z.string().optional().default(""),requires:L(j).optional().default([])}),qe=s.z.union([bt.toArray(j),bt.toArray(pe),bt.toArray(at).transform(r=>r.map(e=>e.key))]),iy=new Error("request for lock canceled");var ay=function(r,e,t,n){function i(a){return a instanceof t?a:new t(function(o){o(a)})}return new(t||(t=Promise))(function(a,o){function c(h){try{l(n.next(h))}catch(y){o(y)}}function u(h){try{l(n.throw(h))}catch(y){o(y)}}function l(h){h.done?a(h.value):i(h.value).then(c,u)}l((n=n.apply(r,e||[])).next())})};class oy{constructor(e,t=iy){this._value=e,this._cancelError=t,this._queue=[],this._weightedWaiters=[]}acquire(e=1,t=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return new Promise((n,i)=>{const a={resolve:n,reject:i,weight:e,priority:t},o=La(this._queue,c=>t<=c.priority);o===-1&&e<=this._value?this._dispatchItem(a):this._queue.splice(o+1,0,a)})}runExclusive(e){return ay(this,arguments,void 0,function*(t,n=1,i=0){const[a,o]=yield this.acquire(n,i);try{return yield t(a)}finally{o()}})}waitForUnlock(e=1,t=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return this._couldLockImmediately(e,t)?Promise.resolve():new Promise(n=>{this._weightedWaiters[e-1]||(this._weightedWaiters[e-1]=[]),cy(this._weightedWaiters[e-1],{resolve:n,priority:t})})}isLocked(){return this._value<=0}getValue(){return this._value}setValue(e){this._value=e,this._dispatchQueue()}release(e=1){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);this._value+=e,this._dispatchQueue()}cancel(){this._queue.forEach(e=>e.reject(this._cancelError)),this._queue=[]}_dispatchQueue(){for(this._drainUnlockWaiters();this._queue.length>0&&this._queue[0].weight<=this._value;)this._dispatchItem(this._queue.shift()),this._drainUnlockWaiters()}_dispatchItem(e){const t=this._value;this._value-=e.weight,e.resolve([t,this._newReleaser(e.weight)])}_newReleaser(e){let t=!1;return()=>{t||(t=!0,this.release(e))}}_drainUnlockWaiters(){if(this._queue.length===0)for(let e=this._value;e>0;e--){const t=this._weightedWaiters[e-1];t&&(t.forEach(n=>n.resolve()),this._weightedWaiters[e-1]=[])}else{const e=this._queue[0].priority;for(let t=this._value;t>0;t--){const n=this._weightedWaiters[t-1];if(!n)continue;const i=n.findIndex(a=>a.priority<=e);(i===-1?n:n.splice(0,i)).forEach(a=>a.resolve())}}}_couldLockImmediately(e,t){return(this._queue.length===0||this._queue[0].priority<t)&&e<=this._value}}function cy(r,e){const t=La(r,n=>e.priority<=n.priority);r.splice(t+1,0,e)}function La(r,e){for(let t=r.length-1;t>=0;t--)if(e(r[t]))return t;return-1}var ly=function(r,e,t,n){function i(a){return a instanceof t?a:new t(function(o){o(a)})}return new(t||(t=Promise))(function(a,o){function c(h){try{l(n.next(h))}catch(y){o(y)}}function u(h){try{l(n.throw(h))}catch(y){o(y)}}function l(h){h.done?a(h.value):i(h.value).then(c,u)}l((n=n.apply(r,e||[])).next())})};class uy{constructor(e){this._semaphore=new oy(1,e)}acquire(){return ly(this,arguments,void 0,function*(e=0){const[,t]=yield this._semaphore.acquire(1,e);return t})}runExclusive(e,t=0){return this._semaphore.runExclusive(()=>e(),1,t)}isLocked(){return this._semaphore.isLocked()}waitForUnlock(e=0){return this._semaphore.waitForUnlock(1,e)}release(){this._semaphore.isLocked()&&this._semaphore.release()}cancel(){return this._semaphore.cancel()}}const hy=(r,e,{convertNumericStrings:t=!0}={})=>{const n=!Array.isArray(r);let i=v.toArray(r);const a=i[0],o=typeof a;let c;return o==="string"&&t&&!isNaN(parseInt(a))&&"number"in e?(c=e.number,i=i.map(u=>parseInt(u))):c=e[o],{single:n,variant:c,normalized:i,actual:r}},Fe=(r,e,t,n)=>{if(n){if(t.length===0)throw new St(`${r} not found matching ${JSON.stringify(e)}`);if(t.length>1)throw new At(`Expected one ${r} matching ${JSON.stringify(e)}, but found ${t.length}`)}},fy=s.z.object({leaseholder:s.z.number().optional(),keys:j.array().optional(),names:s.z.string().array().optional(),searchTerm:s.z.string().optional(),rangeKey:s.z.string().optional(),limit:s.z.number().optional(),offset:s.z.number().optional(),dataTypes:$.z.array().optional(),notDataTypes:$.z.array().optional(),virtual:s.z.boolean().optional(),isIndex:s.z.boolean().optional(),internal:s.z.boolean().optional(),calculated:s.z.boolean().optional()}),dy=s.z.object({channels:L(at)}),se=r=>(Array.isArray(r)&&r.length>0&&typeof r[0]=="object"?r=r.map(e=>e.key):typeof r=="object"&&"key"in r&&(r=[r.key]),hy(r,{number:"keys",string:"names"}));class Bt{static ENDPOINT="/channel/retrieve";client;constructor(e){this.client=e}async retrieve(e,t){if(!Array.isArray(e)&&typeof e=="object")return await this.execute(e);const n=se(e),{variant:i}=n;let{normalized:a}=n;return i==="keys"&&a.indexOf(0)!==-1&&(a=a.filter(o=>o!==0)),a.length===0?[]:await this.execute({[i]:a,...t})}async execute(e){const[t,n]=await this.client.send(Bt.ENDPOINT,e,fy,dy);if(n!=null)throw n;return t.channels}}class Fn{cache;namesToKeys;wrapped;constructor(e){this.cache=new Map,this.namesToKeys=new Map,this.wrapped=e}async retrieve(e,t){if(!Array.isArray(e)&&typeof e=="object")return await this.wrapped.retrieve(e);const{normalized:n}=se(e),i=[],a=[];if(n.forEach(c=>{const u=this.get(c);u!=null?i.push(...u):a.push(c)}),a.length===0)return i;const o=await this.wrapped.retrieve(a,t);return this.set(o),i.concat(o)}delete(e){const{variant:t,normalized:n}=se(e);t==="names"?n.forEach(i=>{const a=this.namesToKeys.get(i);a!=null&&(a.forEach(o=>this.cache.delete(o)),this.namesToKeys.delete(i))}):n.forEach(i=>{const a=this.cache.get(i);a!=null&&(this.cache.delete(i),this.namesToKeys.delete(a.name))})}rename(e,t){e.forEach((n,i)=>{const a=t[i],o=this.cache.get(n);if(o==null)return;this.cache.delete(n);const c=this.namesToKeys.get(o.name);c!=null&&(c.delete(n),c.size===0&&this.namesToKeys.delete(o.name)),o.name=a,this.cache.set(n,o);const u=this.namesToKeys.get(a);u==null?this.namesToKeys.set(a,new Set([n])):u.add(n)})}set(e){e.forEach(t=>{this.cache.set(t.key,t);const n=this.namesToKeys.get(t.name);n==null?this.namesToKeys.set(t.name,new Set([t.key])):n.add(t.key)})}get(e){if(typeof e=="number"){const i=this.cache.get(e);return i==null?void 0:[i]}const t=this.namesToKeys.get(e);if(t==null)return;const n=[];if(t.forEach(i=>{const a=this.cache.get(i);a!=null&&n.push(a)}),n.length!==0)return n}}class Ba{mu=new uy;requests=new Map;wrapped;debouncedRun;constructor(e,t){this.wrapped=e,this.debouncedRun=Kh(()=>{this.run()},t)}async retrieve(e){if(!Array.isArray(e)&&typeof e=="object")return await this.wrapped.retrieve(e);const{normalized:t,variant:n}=se(e);return n==="names"?await this.wrapped.retrieve(t):await new Promise((a,o)=>{this.mu.runExclusive(()=>{this.requests.set(t,{resolve:a,reject:o}),this.debouncedRun()})})}async run(){await this.mu.runExclusive(async()=>{const e=new Set;this.requests.forEach((t,n)=>n.forEach(i=>e.add(i)));try{const t=await this.wrapped.retrieve(Array.from(e));this.requests.forEach((n,i)=>n.resolve(t.filter(a=>i.includes(a.key))))}catch(t){this.requests.forEach(n=>n.reject(t))}finally{this.requests.clear()}})}}const qa=async(r,e)=>{const{normalized:t}=se(e),n=await r.retrieve(t),i=[];if(t.forEach(a=>{n.find(o=>o.name===a||o.key===a)==null&&i.push(a)}),i.length>0)throw new xe(`Could not find channels: ${JSON.stringify(i)}`);return n},yy="sy_channel_set",gy="sy_channel_delete";class cr{_frameClient;key;name;dataType;leaseholder;index;isIndex;internal;alias;virtual;expression;requires;status;constructor({dataType:e,name:t,leaseholder:n=0,key:i=0,isIndex:a=!1,index:o=0,internal:c=!1,virtual:u=!1,frameClient:l,alias:h,status:y,expression:d="",requires:N=[]}){this.key=j.parse(i),this.name=t,this.dataType=new $(e),this.leaseholder=n,this.index=j.parse(o),this.isIndex=a,this.internal=c,this.alias=h,this.virtual=u,this.expression=d,this.requires=j.array().parse(N??[]),y!=null&&(this.status=Pt.create(y)),this._frameClient=l??null}get framer(){if(this._frameClient==null)throw new Z("cannot read from a channel that has not been created");return this._frameClient}get payload(){return at.parse({key:this.key,name:this.name,dataType:this.dataType.valueOf(),leaseholder:this.leaseholder,index:this.index,isIndex:this.isIndex,internal:this.internal,virtual:this.virtual,expression:this.expression,requires:this.requires,status:this.status})}get isCalculated(){return It(this.payload)}get ontologyID(){return Va(this.key)}async read(e){return await this.framer.read(e,this.key)}async write(e,t){return await this.framer.write(e,this.key,t)}}const py="sy_calculation_status",my="/channel/retrieve-group",wy=s.z.object({}),by=s.z.object({group:Tr});let Fa=class{type="channel";frameClient;client;retriever;writer;constructor(e,t,n,i){this.frameClient=e,this.retriever=t,this.client=n,this.writer=i}async create(e,t={}){const{retrieveIfNameExists:n=!1}=t,i=!Array.isArray(e);let a=v.toArray(e),o=[];if(n){const c=await this.retriever.retrieve(a.map(l=>l.name)),u=new Set(c.map(l=>l.name));a=a.filter(l=>!u.has(l.name)),o=this.sugar(c)}return o=o.concat(this.sugar(await this.writer.create(a))),i?o[0]:o}async retrieve(e,t){if(typeof e=="object"&&!Array.isArray(e))return this.sugar(await this.retriever.retrieve(e));const n=!Array.isArray(e),i=this.sugar(await this.retriever.retrieve(e,t));return Fe("channel",e,i,n),n?i[0]:i}async delete(e){const{normalized:t,variant:n}=se(e);return n==="keys"?await this.writer.delete({keys:t}):await this.writer.delete({names:t})}async rename(e,t){return await this.writer.rename(v.toArray(e),v.toArray(t))}createDebouncedBatchRetriever(e=10){return new Fn(new Ba(new Bt(this.client),e))}sugar(e){const{frameClient:t}=this;return Array.isArray(e)?e.map(n=>new cr({...n,frameClient:t})):new cr({...e,frameClient:t})}async retrieveGroup(){const e=await m(this.client,my,{},wy,by);return new qn(e.group.name,e.group.key)}};const It=({virtual:r,expression:e})=>r&&e!=="",Ya=async(r,e)=>{if(!It(e))return e.index;for(const t of e.requires){const n=await r(t);if(n==null)return null;if(!n.virtual)return n.index}for(const t of e.requires){const n=await r(t);if(n==null)return null;if(It(n)){const i=await Ya(r,n);if(i!=null)return i}}return null},Va=r=>({type:"channel",key:r.toString()}),Ty=s.z.object({channels:Pa.array()}),vy=s.z.object({channels:at.array()}),Ey=s.z.object({keys:j.array().optional(),names:pe.array().optional()}),Ny=s.z.object({}),Oy=s.z.object({keys:j.array(),names:pe.array()}),zy=s.z.object({}),Sy="/channel/create",Ay="/channel/delete",$y="/channel/rename";let Ha=class{client;cache;constructor(e,t){this.client=e,this.cache=t}async create(e){const{channels:t}=await m(this.client,Sy,{channels:e.map(n=>({...n,dataType:n.dataType}))},Ty,vy);return this.cache.set(t),t}async delete(e){const t=j.array().parse(e.keys??[]);await m(this.client,Ay,e,Ey,Ny),t.length>0&&this.cache.delete(t),e.names!=null&&this.cache.delete(e.names)}async rename(e,t){await m(this.client,$y,{keys:e,names:t},Oy,zy),this.cache.rename(e,t)}};const Iy=Object.freeze(Object.defineProperty({__proto__:null,CALCULATION_STATUS_CHANNEL_NAME:py,CacheRetriever:Fn,Channel:cr,Client:Fa,ClusterRetriever:Bt,DELETE_CHANNEL_NAME:gy,DebouncedBatchRetriever:Ba,SET_CHANNEL_NAME:yy,Writer:Ha,analyzeParams:se,isCalculated:It,keyZ:j,nameZ:pe,newZ:Pa,ontologyID:Va,paramsZ:qe,payloadZ:at,resolveCalculatedIndex:Ya,retrieveRequired:qa,statusZ:Za},Symbol.toStringTag,{value:"Module"})),Ce=s.z.uuid(),qt=s.z.object({key:Ce,username:s.z.string().min(1),firstName:s.z.string().default(""),lastName:s.z.string().default(""),rootUser:s.z.boolean().default(!0)}),_a=qt.partial({key:!0,firstName:!0,lastName:!0}).omit({rootUser:!0}).extend({password:s.z.string().min(1)}),ky=s.z.object({keys:Ce.array().optional(),usernames:s.z.string().array().optional()}),xy=s.z.object({key:Ce}).transform(({key:r})=>({keys:[r]})),Cy=s.z.object({username:s.z.string()}).transform(({username:r})=>({usernames:[r]})),Ry=s.z.object({usernames:s.z.string().array()}).transform(({usernames:r})=>({usernames:r})),jy=s.z.union([xy,Cy,Ry,ky]),My=s.z.object({users:L(qt)}),Uy=s.z.object({users:_a.array()}),Dy=s.z.object({users:qt.array()}),Zy=s.z.object({key:Ce,username:s.z.string().min(1)}),Py=s.z.object({}),Ly=s.z.object({key:Ce,firstName:s.z.string().optional(),lastName:s.z.string().optional()}),By=s.z.object({}),qy=s.z.object({keys:Ce.array()}),Fy=s.z.object({}),Yy="/user/retrieve",Vy="/user/create",Hy="/user/change-username",_y="/user/rename",Wy="/user/delete";let Wa=class{client;constructor(e){this.client=e}async create(e){const t=Array.isArray(e),n=await m(this.client,Vy,{users:v.toArray(e)},Uy,Dy);return t?n.users:n.users[0]}async changeUsername(e,t){await m(this.client,Hy,{key:e,username:t},Zy,Py)}async retrieve(e){const t="key"in e||"username"in e,n=await m(this.client,Yy,e,jy,My);if(!t)return n.users;if(n.users.length===0){const i="key"in e?`key ${e.key}`:`username ${e.username}`;throw new St(`No user with ${i} found`)}if(n.users.length>1){const i="key"in e?`key ${e.key}`:`username ${e.username}`;throw new At(`Multiple users found with ${i}`)}return n.users[0]}async rename(e,t,n){await m(this.client,_y,{key:e,firstName:t,lastName:n},Ly,By)}async delete(e){await m(this.client,Wy,{keys:v.toArray(e)},qy,Fy)}};const Gy=r=>({type:"user",key:r}),Ky=Object.freeze(Object.defineProperty({__proto__:null,Client:Wa,keyZ:Ce,newZ:_a,ontologyID:Gy,userZ:qt},Symbol.toStringTag,{value:"Module"})),Jy=s.z.object({username:s.z.string(),password:s.z.string()}),Xy=s.z.object({token:s.z.string(),user:qt}),Ss="/auth/login",Qy=3,eg="/auth/change-password",tg=s.z.object({username:s.z.string(),password:s.z.string(),newPassword:s.z.string().min(1)}),rg=s.z.object({}),ng=[gn,pn];let sg=class{token;client;credentials;authenticating;authenticated;user;retryCount;constructor(e,t){this.client=e,this.authenticated=!1,this.credentials=t,this.retryCount=0}async changePassword(e){if(!this.authenticated)throw new Error("Not authenticated");await m(this.client,eg,{username:this.credentials.username,password:this.credentials.password,newPassword:e},tg,rg),this.credentials.password=e}middleware(){const e=async(t,n)=>{if(!this.authenticated&&!t.target.endsWith(Ss)){this.authenticating??=new Promise((c,u)=>{this.client.send(Ss,this.credentials,Jy,Xy).then(([l,h])=>{if(h!=null)return c(h);this.token=l?.token,this.user=l?.user,this.authenticated=!0,c(null)}).catch(u)});const o=await this.authenticating;if(o!=null)return[t,o]}t.params.Authorization=`Bearer ${this.token}`;const[i,a]=await n(t);return ng.some(o=>o.matches(a))&&this.retryCount<Qy?(this.authenticated=!1,this.authenticating=void 0,this.retryCount+=1,e(t,n)):(this.retryCount=0,[i,a])};return e}};const Ga=s.z.enum(["disconnected","connecting","connected","failed"]),Ka=s.z.object({status:Ga,error:s.z.instanceof(Error).optional(),message:s.z.string().optional(),clusterKey:s.z.string(),clientVersion:s.z.string(),clientServerCompatible:s.z.boolean(),nodeVersion:s.z.string().optional()}),ig=s.z.object({clusterKey:s.z.string(),nodeVersion:s.z.string().optional()}),As={clusterKey:"",status:"disconnected",error:void 0,message:"Disconnected",clientServerCompatible:!1,clientVersion:"0.45.1"},$s=(r,e,t)=>{const n=t?"cluster":"client";return`Synnax cluster node version ${r!=null?`${r} `:""}is too ${t?"old":"new"} for client version ${e}.
|
|
21
|
+
`)}}class Fe extends Se.sub("query"){}class Ht extends Fe.sub("not_found"){}class Gt extends Fe.sub("multiple_results"){}class ss extends Se.sub("route"){path;constructor(e,r){super(e),this.path=r}}class is extends Se.sub("control"){}class $i extends is.sub("unauthorized"){}class rm extends Se.sub("disconnected"){constructor(e="Operation failed because no cluster is connected."){super(e)}}class nm extends Se.sub("contiguity"){}const sm=t=>t.type.startsWith(Se.TYPE)?t.type.startsWith(Y.TYPE)?t.type===Yt.TYPE?Yt.decode(t):new Y(t.data):t.type.startsWith(Wt.TYPE)?t.type.startsWith(rs.TYPE)?new rs(t.data):t.type.startsWith(ns.TYPE)?new ns(t.data):new Wt(t.data):t.type.startsWith(gt.TYPE)?new gt(t.data):t.type.startsWith(Fe.TYPE)?t.type.startsWith(Ht.TYPE)?new Ht(t.data):t.type.startsWith(Gt.TYPE)?new Gt(t.data):new Fe(t.data):t.type.startsWith(is.TYPE)?t.type.startsWith($i.TYPE)?new $i(t.data):new is(t.data):t.type.startsWith(ss.TYPE)?new ss(t.data,t.data):new gt(t.data):null,im=()=>{throw new Ze.NotImplemented};Ze.register({encode:im,decode:sm});const am=async(t,e)=>{const[r,n]=await e(t);return n==null?[r,n]:n instanceof Be?[r,new Be({message:`Cannot reach cluster at ${n.url.host}:${n.url.port}`,url:n.url})]:[r,n]},or=i.z.uuid(),cc=i.z.string(),Gr=i.z.object({key:or,name:cc}),om=t=>({type:"group",key:t}),Jr=i.z.enum(["label","log","allow_all","builtin","cluster","channel","node","group","range","framer","range-alias","user","workspace","schematic","lineplot","rack","device","task","policy","table","arc","schematic_symbol","status"]),uc=i.z.string().transform(t=>{const[e,r]=t.split(":");return{type:Jr.parse(e),key:r??""}}),j=i.z.object({type:Jr,key:i.z.string()}).or(uc),cm={type:"builtin",key:"root"},Tt=(t=>(typeof t=="string"&&(t=uc.parse(t)),Array.isArray(t)?t.map(e=>Tt(e)):`${t.type}:${t.key}`)),um=(t,e)=>t.type===e.type&&t.key===e.key,lc=t=>{const e=T.toArray(t);return e.length===0?[]:typeof e[0]=="object"&&"id"in e[0]?e.map(({id:r})=>r):e.map(r=>j.parse(r))},hc=i.z.object({id:j,name:i.z.string(),data:be.unknownZ.optional().nullable()}).transform(t=>({key:Tt(t.id),...t})),lm=t=>t==="to"?"from":"to",hm=i.z.object({from:j,type:i.z.string(),to:j}).or(i.z.string().transform(t=>{const[e,r,n]=t.split("->");return{from:j.parse(e),type:r,to:j.parse(n)}})),fm=t=>`${Tt(t.from)}->${t.type}->${Tt(t.to)}`,dm="parent",pm=(t,e)=>!(e.type!=null&&e.type!==t.type||e.from?.type!=null&&e.from.type!==t.from.type||e.to?.type!=null&&e.to.type!==t.to.type||e.from?.key!=null&&e.from.key!==t.from.key||e.to?.key!=null&&e.to.key!==t.to.key),ym="sy_group_set",mm="sy_group_delete",gm=i.object({group:Gr}),wm=i.object({parent:j,key:or.optional(),name:i.string()}),bm=i.object({key:or,name:i.string()}),vm=i.object({keys:i.array(or)}),Tm="/ontology/create-group",zm="/ontology/rename-group",Em="/ontology/delete-group";let fc=class{client;constructor(e){this.client=e}async create(e){return(await w(this.client,Tm,e,wm,gm)).group}async rename(e,r){await w(this.client,zm,{key:e,name:r},bm,i.object({}))}async delete(e){await w(this.client,Em,{keys:T.toArray(e)},vm,i.object({}))}};const Nm=Object.freeze(Object.defineProperty({__proto__:null,Client:fc,DELETE_CHANNEL_NAME:mm,SET_CHANNEL_NAME:ym,groupZ:Gr,keyZ:or,nameZ:cc,ontologyID:om},Symbol.toStringTag,{value:"Module"})),Om="/ontology/add-children",$m="/ontology/remove-children",Sm="/ontology/move-children",Si=i.z.object({id:j,children:j.array()}),Im=i.z.object({from:j,to:j,children:j.array()}),On=i.z.object({});let km=class{client;constructor(e){this.client=e}async addChildren(e,...r){await w(this.client,Om,{id:e,children:r},Si,On)}async removeChildren(e,...r){await w(this.client,$m,{id:e,children:r},Si,On)}async moveChildren(e,r,...n){await w(this.client,Sm,{from:e,to:r,children:n},Im,On)}};const Am="/ontology/retrieve",xm=i.z.object({ids:j.array().optional(),children:i.z.boolean().optional(),parents:i.z.boolean().optional(),excludeFieldData:i.z.boolean().optional(),searchTerm:i.z.string().optional(),limit:i.z.number().optional(),offset:i.z.number().optional(),types:Jr.array().optional()}),Zm=i.z.object({resources:hc.array()});let dc=class{type="ontology";groups;client;writer;framer;constructor(e,r){this.client=e,this.writer=new km(e),this.groups=new fc(e),this.framer=r}async retrieve(e,r){if(!Array.isArray(e)&&typeof e=="object"&&!("key"in e))return this.execRetrieve(e);const n=lc(e),s=await this.execRetrieve({ids:n,...r});if(Array.isArray(e))return s;if(s.length===0)throw new Fe(`No resource found with ID ${ts.naturalLanguageJoin(n.map(a=>Tt(a)))}`);return s[0]}async retrieveChildren(e,r){return await this.execRetrieve({ids:T.toArray(e),children:!0,...r})}async retrieveParents(e,r){return await this.execRetrieve({ids:T.toArray(e),parents:!0,...r})}async addChildren(e,...r){return await this.writer.addChildren(e,...r)}async removeChildren(e,...r){return await this.writer.removeChildren(e,...r)}async moveChildren(e,r,...n){return await this.writer.moveChildren(e,r,...n)}async execRetrieve(e){const{resources:r}=await w(this.client,Am,e,xm,Zm);return r}};const Cm="sy_ontology_resource_set",Rm="sy_ontology_resource_delete",_m="sy_ontology_relationship_set",jm="sy_ontology_relationship_delete",Mm=Object.freeze(Object.defineProperty({__proto__:null,Client:dc,PARENT_OF_RELATIONSHIP_TYPE:dm,RELATIONSHIP_DELETE_CHANNEL_NAME:jm,RELATIONSHIP_SET_CHANNEL_NAME:_m,RESOURCE_DELETE_CHANNEL_NAME:Rm,RESOURCE_SET_CHANNEL_NAME:Cm,ROOT_ID:cm,idToString:Tt,idZ:j,idsEqual:um,matchRelationship:pm,oppositeRelationshipDirection:lm,parseIDs:lc,relationshipToString:fm,relationshipZ:hm,resourceTypeZ:Jr,resourceZ:hc},Symbol.toStringTag,{value:"Module"})),kt=i.z.uuid(),Kr=i.z.object({key:kt,subjects:T.nullableZ(j),objects:T.nullableZ(j),actions:T.nullableZ(_r)}),pc=i.z.object({key:kt.optional(),subjects:j.array().or(j),objects:j.array().or(j),actions:_r.array().or(_r)}),Dm=i.z.object({keys:kt.array().optional(),subjects:j.array().optional()}),Pm=i.z.object({key:kt}).transform(({key:t})=>({keys:[t]})),Um=i.z.union([i.z.object({for:j}).transform(({for:t})=>({subjects:[t]})),i.z.object({for:j.array()}).transform(({for:t})=>({subjects:t})),Dm]),Lm=i.z.union([Pm,Um]),Bm=i.z.object({policies:T.nullableZ(Kr)}),qm=i.z.object({policies:Kr.partial({key:!0}).array()}),Fm=i.z.object({policies:Kr.array()}),Vm=i.z.object({keys:kt.array()}),Ym=i.z.object({}),Wm="/access/policy/retrieve",Hm="/access/policy/create",Gm="/access/policy/delete";let yc=class{client;constructor(e){this.client=e}async create(e){const r=Array.isArray(e),s=pc.array().parse(T.toArray(e)).map(o=>({objects:T.toArray(o.objects),actions:T.toArray(o.actions),subjects:T.toArray(o.subjects)})),a=await w(this.client,Hm,{policies:s},qm,Fm);return r?a.policies:a.policies[0]}async retrieve(e){const r="key"in e,n=await w(this.client,Wm,e,Lm,Bm);return r?n.policies[0]:n.policies}async delete(e){await w(this.client,Gm,{keys:T.toArray(e)},Vm,Ym)}};const Jm=t=>({type:"policy",key:t}),Km={type:"allow_all",key:""},Xm=Object.freeze(Object.defineProperty({__proto__:null,ALLOW_ALL_ONTOLOGY_ID:Km,Client:yc,keyZ:kt,newZ:pc,ontologyID:Jm,policyZ:Kr},Symbol.toStringTag,{value:"Module"}));let mc=class{policy;constructor(e){this.policy=new yc(e)}};const Qm=Object.freeze(Object.defineProperty({__proto__:null,ALL_ACTION:nc,CREATE_ACTION:sc,Client:mc,DELETE_ACTION:ic,RETRIEVE_ACTION:ac,UPDATE_ACTION:oc,actionZ:_r},Symbol.toStringTag,{value:"Module"}));function y(t,e,r){function n(c,l){var u;Object.defineProperty(c,"_zod",{value:c._zod??{},enumerable:!1}),(u=c._zod).traits??(u.traits=new Set),c._zod.traits.add(t),e(c,l);for(const h in o.prototype)h in c||Object.defineProperty(c,h,{value:o.prototype[h].bind(c)});c._zod.constr=o,c._zod.def=l}const s=r?.Parent??Object;class a extends s{}Object.defineProperty(a,"name",{value:t});function o(c){var l;const u=r?.Parent?new a:this;n(u,c),(l=u._zod).deferred??(l.deferred=[]);for(const h of u._zod.deferred)h();return u}return Object.defineProperty(o,"init",{value:n}),Object.defineProperty(o,Symbol.hasInstance,{value:c=>r?.Parent&&c instanceof r.Parent?!0:c?._zod?.traits?.has(t)}),Object.defineProperty(o,"name",{value:t}),o}class wt extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class gc extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name="ZodEncodeError"}}const wc={};function rt(t){return wc}function eg(t){const e=Object.values(t).filter(n=>typeof n=="number");return Object.entries(t).filter(([n,s])=>e.indexOf(+n)===-1).map(([n,s])=>s)}function as(t,e){return typeof e=="bigint"?e.toString():e}function _s(t){return{get value(){{const e=t();return Object.defineProperty(this,"value",{value:e}),e}}}}function js(t){return t==null}function Ms(t){const e=t.startsWith("^")?1:0,r=t.endsWith("$")?t.length-1:t.length;return t.slice(e,r)}function tg(t,e){const r=(t.toString().split(".")[1]||"").length,n=e.toString();let s=(n.split(".")[1]||"").length;if(s===0&&/\d?e-\d?/.test(n)){const l=n.match(/\d?e-(\d?)/);l?.[1]&&(s=Number.parseInt(l[1]))}const a=r>s?r:s,o=Number.parseInt(t.toFixed(a).replace(".","")),c=Number.parseInt(e.toFixed(a).replace(".",""));return o%c/10**a}const Ii=Symbol("evaluating");function U(t,e,r){let n;Object.defineProperty(t,e,{get(){if(n!==Ii)return n===void 0&&(n=Ii,n=r()),n},set(s){Object.defineProperty(t,e,{value:s})},configurable:!0})}function rg(t){return Object.create(Object.getPrototypeOf(t),Object.getOwnPropertyDescriptors(t))}function Ve(t,e,r){Object.defineProperty(t,e,{value:r,writable:!0,enumerable:!0,configurable:!0})}function At(...t){const e={};for(const r of t){const n=Object.getOwnPropertyDescriptors(r);Object.assign(e,n)}return Object.defineProperties({},e)}function ki(t){return JSON.stringify(t)}const bc="captureStackTrace"in Error?Error.captureStackTrace:(...t)=>{};function jr(t){return typeof t=="object"&&t!==null&&!Array.isArray(t)}const ng=_s(()=>{if(typeof navigator<"u"&&navigator?.userAgent?.includes("Cloudflare"))return!1;try{const t=Function;return new t(""),!0}catch{return!1}});function Jt(t){if(jr(t)===!1)return!1;const e=t.constructor;if(e===void 0)return!0;const r=e.prototype;return!(jr(r)===!1||Object.prototype.hasOwnProperty.call(r,"isPrototypeOf")===!1)}function vc(t){return Jt(t)?{...t}:Array.isArray(t)?[...t]:t}const sg=new Set(["string","number","symbol"]);function Xr(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Ye(t,e,r){const n=new t._zod.constr(e??t._zod.def);return(!e||r?.parent)&&(n._zod.parent=t),n}function $(t){const e=t;if(!e)return{};if(typeof e=="string")return{error:()=>e};if(e?.message!==void 0){if(e?.error!==void 0)throw new Error("Cannot specify both `message` and `error` params");e.error=e.message}return delete e.message,typeof e.error=="string"?{...e,error:()=>e.error}:e}function ig(t){return Object.keys(t).filter(e=>t[e]._zod.optin==="optional"&&t[e]._zod.optout==="optional")}const ag={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function og(t,e){const r=t._zod.def,n=At(t._zod.def,{get shape(){const s={};for(const a in e){if(!(a in r.shape))throw new Error(`Unrecognized key: "${a}"`);e[a]&&(s[a]=r.shape[a])}return Ve(this,"shape",s),s},checks:[]});return Ye(t,n)}function cg(t,e){const r=t._zod.def,n=At(t._zod.def,{get shape(){const s={...t._zod.def.shape};for(const a in e){if(!(a in r.shape))throw new Error(`Unrecognized key: "${a}"`);e[a]&&delete s[a]}return Ve(this,"shape",s),s},checks:[]});return Ye(t,n)}function ug(t,e){if(!Jt(e))throw new Error("Invalid input to extend: expected a plain object");const r=t._zod.def.checks;if(r&&r.length>0)throw new Error("Object schemas containing refinements cannot be extended. Use `.safeExtend()` instead.");const s=At(t._zod.def,{get shape(){const a={...t._zod.def.shape,...e};return Ve(this,"shape",a),a},checks:[]});return Ye(t,s)}function lg(t,e){if(!Jt(e))throw new Error("Invalid input to safeExtend: expected a plain object");const r={...t._zod.def,get shape(){const n={...t._zod.def.shape,...e};return Ve(this,"shape",n),n},checks:t._zod.def.checks};return Ye(t,r)}function hg(t,e){const r=At(t._zod.def,{get shape(){const n={...t._zod.def.shape,...e._zod.def.shape};return Ve(this,"shape",n),n},get catchall(){return e._zod.def.catchall},checks:[]});return Ye(t,r)}function fg(t,e,r){const n=At(e._zod.def,{get shape(){const s=e._zod.def.shape,a={...s};if(r)for(const o in r){if(!(o in s))throw new Error(`Unrecognized key: "${o}"`);r[o]&&(a[o]=t?new t({type:"optional",innerType:s[o]}):s[o])}else for(const o in s)a[o]=t?new t({type:"optional",innerType:s[o]}):s[o];return Ve(this,"shape",a),a},checks:[]});return Ye(e,n)}function dg(t,e,r){const n=At(e._zod.def,{get shape(){const s=e._zod.def.shape,a={...s};if(r)for(const o in r){if(!(o in a))throw new Error(`Unrecognized key: "${o}"`);r[o]&&(a[o]=new t({type:"nonoptional",innerType:s[o]}))}else for(const o in s)a[o]=new t({type:"nonoptional",innerType:s[o]});return Ve(this,"shape",a),a},checks:[]});return Ye(e,n)}function dt(t,e=0){if(t.aborted===!0)return!0;for(let r=e;r<t.issues.length;r++)if(t.issues[r]?.continue!==!0)return!0;return!1}function Tc(t,e){return e.map(r=>{var n;return(n=r).path??(n.path=[]),r.path.unshift(t),r})}function Er(t){return typeof t=="string"?t:t?.message}function nt(t,e,r){const n={...t,path:t.path??[]};if(!t.message){const s=Er(t.inst?._zod.def?.error?.(t))??Er(e?.error?.(t))??Er(r.customError?.(t))??Er(r.localeError?.(t))??"Invalid input";n.message=s}return delete n.inst,delete n.continue,e?.reportInput||delete n.input,n}function Ds(t){return Array.isArray(t)?"array":typeof t=="string"?"string":"unknown"}function Kt(...t){const[e,r,n]=t;return typeof e=="string"?{message:e,code:"custom",input:r,inst:n}:{...e}}const zc=(t,e)=>{t.name="$ZodError",Object.defineProperty(t,"_zod",{value:t._zod,enumerable:!1}),Object.defineProperty(t,"issues",{value:e,enumerable:!1}),t.message=JSON.stringify(e,as,2),Object.defineProperty(t,"toString",{value:()=>t.message,enumerable:!1})},Ec=y("$ZodError",zc),Nc=y("$ZodError",zc,{Parent:Error});function pg(t,e=r=>r.message){const r={},n=[];for(const s of t.issues)s.path.length>0?(r[s.path[0]]=r[s.path[0]]||[],r[s.path[0]].push(e(s))):n.push(e(s));return{formErrors:n,fieldErrors:r}}function yg(t,e){const r=e||function(a){return a.message},n={_errors:[]},s=a=>{for(const o of a.issues)if(o.code==="invalid_union"&&o.errors.length)o.errors.map(c=>s({issues:c}));else if(o.code==="invalid_key")s({issues:o.issues});else if(o.code==="invalid_element")s({issues:o.issues});else if(o.path.length===0)n._errors.push(r(o));else{let c=n,l=0;for(;l<o.path.length;){const u=o.path[l];l===o.path.length-1?(c[u]=c[u]||{_errors:[]},c[u]._errors.push(r(o))):c[u]=c[u]||{_errors:[]},c=c[u],l++}}};return s(t),n}const Ps=t=>(e,r,n,s)=>{const a=n?Object.assign(n,{async:!1}):{async:!1},o=e._zod.run({value:r,issues:[]},a);if(o instanceof Promise)throw new wt;if(o.issues.length){const c=new(s?.Err??t)(o.issues.map(l=>nt(l,a,rt())));throw bc(c,s?.callee),c}return o.value},Us=t=>async(e,r,n,s)=>{const a=n?Object.assign(n,{async:!0}):{async:!0};let o=e._zod.run({value:r,issues:[]},a);if(o instanceof Promise&&(o=await o),o.issues.length){const c=new(s?.Err??t)(o.issues.map(l=>nt(l,a,rt())));throw bc(c,s?.callee),c}return o.value},Qr=t=>(e,r,n)=>{const s=n?{...n,async:!1}:{async:!1},a=e._zod.run({value:r,issues:[]},s);if(a instanceof Promise)throw new wt;return a.issues.length?{success:!1,error:new(t??Ec)(a.issues.map(o=>nt(o,s,rt())))}:{success:!0,data:a.value}},mg=Qr(Nc),en=t=>async(e,r,n)=>{const s=n?Object.assign(n,{async:!0}):{async:!0};let a=e._zod.run({value:r,issues:[]},s);return a instanceof Promise&&(a=await a),a.issues.length?{success:!1,error:new t(a.issues.map(o=>nt(o,s,rt())))}:{success:!0,data:a.value}},gg=en(Nc),wg=t=>(e,r,n)=>{const s=n?Object.assign(n,{direction:"backward"}):{direction:"backward"};return Ps(t)(e,r,s)},bg=t=>(e,r,n)=>Ps(t)(e,r,n),vg=t=>async(e,r,n)=>{const s=n?Object.assign(n,{direction:"backward"}):{direction:"backward"};return Us(t)(e,r,s)},Tg=t=>async(e,r,n)=>Us(t)(e,r,n),zg=t=>(e,r,n)=>{const s=n?Object.assign(n,{direction:"backward"}):{direction:"backward"};return Qr(t)(e,r,s)},Eg=t=>(e,r,n)=>Qr(t)(e,r,n),Ng=t=>async(e,r,n)=>{const s=n?Object.assign(n,{direction:"backward"}):{direction:"backward"};return en(t)(e,r,s)},Og=t=>async(e,r,n)=>en(t)(e,r,n),$g=/^[cC][^\s-]{8,}$/,Sg=/^[0-9a-z]+$/,Ig=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,kg=/^[0-9a-vA-V]{20}$/,Ag=/^[A-Za-z0-9]{27}$/,xg=/^[a-zA-Z0-9_-]{21}$/,Zg=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,Cg=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,Ai=t=>t?new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${t}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,Rg=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,_g="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";function jg(){return new RegExp(_g,"u")}const Mg=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,Dg=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,Pg=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,Ug=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Lg=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,Oc=/^[A-Za-z0-9_-]*$/,Bg=/^(?=.{1,253}\.?$)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[-0-9a-zA-Z]{0,61}[0-9a-zA-Z])?)*\.?$/,qg=/^\+(?:[0-9]){6,14}[0-9]$/,$c="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))",Fg=new RegExp(`^${$c}$`);function Sc(t){const e="(?:[01]\\d|2[0-3]):[0-5]\\d";return typeof t.precision=="number"?t.precision===-1?`${e}`:t.precision===0?`${e}:[0-5]\\d`:`${e}:[0-5]\\d\\.\\d{${t.precision}}`:`${e}(?::[0-5]\\d(?:\\.\\d+)?)?`}function Vg(t){return new RegExp(`^${Sc(t)}$`)}function Yg(t){const e=Sc({precision:t.precision}),r=["Z"];t.local&&r.push(""),t.offset&&r.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");const n=`${e}(?:${r.join("|")})`;return new RegExp(`^${$c}T(?:${n})$`)}const Wg=t=>{const e=t?`[\\s\\S]{${t?.minimum??0},${t?.maximum??""}}`:"[\\s\\S]*";return new RegExp(`^${e}$`)},Hg=/^-?\d+$/,Gg=/^-?\d+(?:\.\d+)?/,Jg=/^(?:true|false)$/i,Kg=/^[^A-Z]*$/,Xg=/^[^a-z]*$/,ae=y("$ZodCheck",(t,e)=>{var r;t._zod??(t._zod={}),t._zod.def=e,(r=t._zod).onattach??(r.onattach=[])}),Ic={number:"number",bigint:"bigint",object:"date"},kc=y("$ZodCheckLessThan",(t,e)=>{ae.init(t,e);const r=Ic[typeof e.value];t._zod.onattach.push(n=>{const s=n._zod.bag,a=(e.inclusive?s.maximum:s.exclusiveMaximum)??Number.POSITIVE_INFINITY;e.value<a&&(e.inclusive?s.maximum=e.value:s.exclusiveMaximum=e.value)}),t._zod.check=n=>{(e.inclusive?n.value<=e.value:n.value<e.value)||n.issues.push({origin:r,code:"too_big",maximum:e.value,input:n.value,inclusive:e.inclusive,inst:t,continue:!e.abort})}}),Ac=y("$ZodCheckGreaterThan",(t,e)=>{ae.init(t,e);const r=Ic[typeof e.value];t._zod.onattach.push(n=>{const s=n._zod.bag,a=(e.inclusive?s.minimum:s.exclusiveMinimum)??Number.NEGATIVE_INFINITY;e.value>a&&(e.inclusive?s.minimum=e.value:s.exclusiveMinimum=e.value)}),t._zod.check=n=>{(e.inclusive?n.value>=e.value:n.value>e.value)||n.issues.push({origin:r,code:"too_small",minimum:e.value,input:n.value,inclusive:e.inclusive,inst:t,continue:!e.abort})}}),Qg=y("$ZodCheckMultipleOf",(t,e)=>{ae.init(t,e),t._zod.onattach.push(r=>{var n;(n=r._zod.bag).multipleOf??(n.multipleOf=e.value)}),t._zod.check=r=>{if(typeof r.value!=typeof e.value)throw new Error("Cannot mix number and bigint in multiple_of check.");(typeof r.value=="bigint"?r.value%e.value===BigInt(0):tg(r.value,e.value)===0)||r.issues.push({origin:typeof r.value,code:"not_multiple_of",divisor:e.value,input:r.value,inst:t,continue:!e.abort})}}),ew=y("$ZodCheckNumberFormat",(t,e)=>{ae.init(t,e),e.format=e.format||"float64";const r=e.format?.includes("int"),n=r?"int":"number",[s,a]=ag[e.format];t._zod.onattach.push(o=>{const c=o._zod.bag;c.format=e.format,c.minimum=s,c.maximum=a,r&&(c.pattern=Hg)}),t._zod.check=o=>{const c=o.value;if(r){if(!Number.isInteger(c)){o.issues.push({expected:n,format:e.format,code:"invalid_type",continue:!1,input:c,inst:t});return}if(!Number.isSafeInteger(c)){c>0?o.issues.push({input:c,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:t,origin:n,continue:!e.abort}):o.issues.push({input:c,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:t,origin:n,continue:!e.abort});return}}c<s&&o.issues.push({origin:"number",input:c,code:"too_small",minimum:s,inclusive:!0,inst:t,continue:!e.abort}),c>a&&o.issues.push({origin:"number",input:c,code:"too_big",maximum:a,inst:t})}}),tw=y("$ZodCheckMaxLength",(t,e)=>{var r;ae.init(t,e),(r=t._zod.def).when??(r.when=n=>{const s=n.value;return!js(s)&&s.length!==void 0}),t._zod.onattach.push(n=>{const s=n._zod.bag.maximum??Number.POSITIVE_INFINITY;e.maximum<s&&(n._zod.bag.maximum=e.maximum)}),t._zod.check=n=>{const s=n.value;if(s.length<=e.maximum)return;const o=Ds(s);n.issues.push({origin:o,code:"too_big",maximum:e.maximum,inclusive:!0,input:s,inst:t,continue:!e.abort})}}),rw=y("$ZodCheckMinLength",(t,e)=>{var r;ae.init(t,e),(r=t._zod.def).when??(r.when=n=>{const s=n.value;return!js(s)&&s.length!==void 0}),t._zod.onattach.push(n=>{const s=n._zod.bag.minimum??Number.NEGATIVE_INFINITY;e.minimum>s&&(n._zod.bag.minimum=e.minimum)}),t._zod.check=n=>{const s=n.value;if(s.length>=e.minimum)return;const o=Ds(s);n.issues.push({origin:o,code:"too_small",minimum:e.minimum,inclusive:!0,input:s,inst:t,continue:!e.abort})}}),nw=y("$ZodCheckLengthEquals",(t,e)=>{var r;ae.init(t,e),(r=t._zod.def).when??(r.when=n=>{const s=n.value;return!js(s)&&s.length!==void 0}),t._zod.onattach.push(n=>{const s=n._zod.bag;s.minimum=e.length,s.maximum=e.length,s.length=e.length}),t._zod.check=n=>{const s=n.value,a=s.length;if(a===e.length)return;const o=Ds(s),c=a>e.length;n.issues.push({origin:o,...c?{code:"too_big",maximum:e.length}:{code:"too_small",minimum:e.length},inclusive:!0,exact:!0,input:n.value,inst:t,continue:!e.abort})}}),tn=y("$ZodCheckStringFormat",(t,e)=>{var r,n;ae.init(t,e),t._zod.onattach.push(s=>{const a=s._zod.bag;a.format=e.format,e.pattern&&(a.patterns??(a.patterns=new Set),a.patterns.add(e.pattern))}),e.pattern?(r=t._zod).check??(r.check=s=>{e.pattern.lastIndex=0,!e.pattern.test(s.value)&&s.issues.push({origin:"string",code:"invalid_format",format:e.format,input:s.value,...e.pattern?{pattern:e.pattern.toString()}:{},inst:t,continue:!e.abort})}):(n=t._zod).check??(n.check=()=>{})}),sw=y("$ZodCheckRegex",(t,e)=>{tn.init(t,e),t._zod.check=r=>{e.pattern.lastIndex=0,!e.pattern.test(r.value)&&r.issues.push({origin:"string",code:"invalid_format",format:"regex",input:r.value,pattern:e.pattern.toString(),inst:t,continue:!e.abort})}}),iw=y("$ZodCheckLowerCase",(t,e)=>{e.pattern??(e.pattern=Kg),tn.init(t,e)}),aw=y("$ZodCheckUpperCase",(t,e)=>{e.pattern??(e.pattern=Xg),tn.init(t,e)}),ow=y("$ZodCheckIncludes",(t,e)=>{ae.init(t,e);const r=Xr(e.includes),n=new RegExp(typeof e.position=="number"?`^.{${e.position}}${r}`:r);e.pattern=n,t._zod.onattach.push(s=>{const a=s._zod.bag;a.patterns??(a.patterns=new Set),a.patterns.add(n)}),t._zod.check=s=>{s.value.includes(e.includes,e.position)||s.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:e.includes,input:s.value,inst:t,continue:!e.abort})}}),cw=y("$ZodCheckStartsWith",(t,e)=>{ae.init(t,e);const r=new RegExp(`^${Xr(e.prefix)}.*`);e.pattern??(e.pattern=r),t._zod.onattach.push(n=>{const s=n._zod.bag;s.patterns??(s.patterns=new Set),s.patterns.add(r)}),t._zod.check=n=>{n.value.startsWith(e.prefix)||n.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:e.prefix,input:n.value,inst:t,continue:!e.abort})}}),uw=y("$ZodCheckEndsWith",(t,e)=>{ae.init(t,e);const r=new RegExp(`.*${Xr(e.suffix)}$`);e.pattern??(e.pattern=r),t._zod.onattach.push(n=>{const s=n._zod.bag;s.patterns??(s.patterns=new Set),s.patterns.add(r)}),t._zod.check=n=>{n.value.endsWith(e.suffix)||n.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:e.suffix,input:n.value,inst:t,continue:!e.abort})}}),lw=y("$ZodCheckOverwrite",(t,e)=>{ae.init(t,e),t._zod.check=r=>{r.value=e.tx(r.value)}});class hw{constructor(e=[]){this.content=[],this.indent=0,this&&(this.args=e)}indented(e){this.indent+=1,e(this),this.indent-=1}write(e){if(typeof e=="function"){e(this,{execution:"sync"}),e(this,{execution:"async"});return}const n=e.split(`
|
|
22
|
+
`).filter(o=>o),s=Math.min(...n.map(o=>o.length-o.trimStart().length)),a=n.map(o=>o.slice(s)).map(o=>" ".repeat(this.indent*2)+o);for(const o of a)this.content.push(o)}compile(){const e=Function,r=this?.args,s=[...(this?.content??[""]).map(a=>` ${a}`)];return new e(...r,s.join(`
|
|
23
|
+
`))}}const fw={major:4,minor:1,patch:8},F=y("$ZodType",(t,e)=>{var r;t??(t={}),t._zod.def=e,t._zod.bag=t._zod.bag||{},t._zod.version=fw;const n=[...t._zod.def.checks??[]];t._zod.traits.has("$ZodCheck")&&n.unshift(t);for(const s of n)for(const a of s._zod.onattach)a(t);if(n.length===0)(r=t._zod).deferred??(r.deferred=[]),t._zod.deferred?.push(()=>{t._zod.run=t._zod.parse});else{const s=(o,c,l)=>{let u=dt(o),h;for(const d of c){if(d._zod.def.when){if(!d._zod.def.when(o))continue}else if(u)continue;const f=o.issues.length,v=d._zod.check(o);if(v instanceof Promise&&l?.async===!1)throw new wt;if(h||v instanceof Promise)h=(h??Promise.resolve()).then(async()=>{await v,o.issues.length!==f&&(u||(u=dt(o,f)))});else{if(o.issues.length===f)continue;u||(u=dt(o,f))}}return h?h.then(()=>o):o},a=(o,c,l)=>{if(dt(o))return o.aborted=!0,o;const u=s(c,n,l);if(u instanceof Promise){if(l.async===!1)throw new wt;return u.then(h=>t._zod.parse(h,l))}return t._zod.parse(u,l)};t._zod.run=(o,c)=>{if(c.skipChecks)return t._zod.parse(o,c);if(c.direction==="backward"){const u=t._zod.parse({value:o.value,issues:[]},{...c,skipChecks:!0});return u instanceof Promise?u.then(h=>a(h,o,c)):a(u,o,c)}const l=t._zod.parse(o,c);if(l instanceof Promise){if(c.async===!1)throw new wt;return l.then(u=>s(u,n,c))}return s(l,n,c)}}t["~standard"]={validate:s=>{try{const a=mg(t,s);return a.success?{value:a.data}:{issues:a.error?.issues}}catch{return gg(t,s).then(o=>o.success?{value:o.data}:{issues:o.error?.issues})}},vendor:"zod",version:1}}),Ls=y("$ZodString",(t,e)=>{F.init(t,e),t._zod.pattern=[...t?._zod.bag?.patterns??[]].pop()??Wg(t._zod.bag),t._zod.parse=(r,n)=>{if(e.coerce)try{r.value=String(r.value)}catch{}return typeof r.value=="string"||r.issues.push({expected:"string",code:"invalid_type",input:r.value,inst:t}),r}}),L=y("$ZodStringFormat",(t,e)=>{tn.init(t,e),Ls.init(t,e)}),dw=y("$ZodGUID",(t,e)=>{e.pattern??(e.pattern=Cg),L.init(t,e)}),pw=y("$ZodUUID",(t,e)=>{if(e.version){const n={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[e.version];if(n===void 0)throw new Error(`Invalid UUID version: "${e.version}"`);e.pattern??(e.pattern=Ai(n))}else e.pattern??(e.pattern=Ai());L.init(t,e)}),yw=y("$ZodEmail",(t,e)=>{e.pattern??(e.pattern=Rg),L.init(t,e)}),mw=y("$ZodURL",(t,e)=>{L.init(t,e),t._zod.check=r=>{try{const n=r.value.trim(),s=new URL(n);e.hostname&&(e.hostname.lastIndex=0,e.hostname.test(s.hostname)||r.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:Bg.source,input:r.value,inst:t,continue:!e.abort})),e.protocol&&(e.protocol.lastIndex=0,e.protocol.test(s.protocol.endsWith(":")?s.protocol.slice(0,-1):s.protocol)||r.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:e.protocol.source,input:r.value,inst:t,continue:!e.abort})),e.normalize?r.value=s.href:r.value=n;return}catch{r.issues.push({code:"invalid_format",format:"url",input:r.value,inst:t,continue:!e.abort})}}}),gw=y("$ZodEmoji",(t,e)=>{e.pattern??(e.pattern=jg()),L.init(t,e)}),ww=y("$ZodNanoID",(t,e)=>{e.pattern??(e.pattern=xg),L.init(t,e)}),bw=y("$ZodCUID",(t,e)=>{e.pattern??(e.pattern=$g),L.init(t,e)}),vw=y("$ZodCUID2",(t,e)=>{e.pattern??(e.pattern=Sg),L.init(t,e)}),Tw=y("$ZodULID",(t,e)=>{e.pattern??(e.pattern=Ig),L.init(t,e)}),zw=y("$ZodXID",(t,e)=>{e.pattern??(e.pattern=kg),L.init(t,e)}),Ew=y("$ZodKSUID",(t,e)=>{e.pattern??(e.pattern=Ag),L.init(t,e)}),Nw=y("$ZodISODateTime",(t,e)=>{e.pattern??(e.pattern=Yg(e)),L.init(t,e)}),Ow=y("$ZodISODate",(t,e)=>{e.pattern??(e.pattern=Fg),L.init(t,e)}),$w=y("$ZodISOTime",(t,e)=>{e.pattern??(e.pattern=Vg(e)),L.init(t,e)}),Sw=y("$ZodISODuration",(t,e)=>{e.pattern??(e.pattern=Zg),L.init(t,e)}),Iw=y("$ZodIPv4",(t,e)=>{e.pattern??(e.pattern=Mg),L.init(t,e),t._zod.onattach.push(r=>{const n=r._zod.bag;n.format="ipv4"})}),kw=y("$ZodIPv6",(t,e)=>{e.pattern??(e.pattern=Dg),L.init(t,e),t._zod.onattach.push(r=>{const n=r._zod.bag;n.format="ipv6"}),t._zod.check=r=>{try{new URL(`http://[${r.value}]`)}catch{r.issues.push({code:"invalid_format",format:"ipv6",input:r.value,inst:t,continue:!e.abort})}}}),Aw=y("$ZodCIDRv4",(t,e)=>{e.pattern??(e.pattern=Pg),L.init(t,e)}),xw=y("$ZodCIDRv6",(t,e)=>{e.pattern??(e.pattern=Ug),L.init(t,e),t._zod.check=r=>{const n=r.value.split("/");try{if(n.length!==2)throw new Error;const[s,a]=n;if(!a)throw new Error;const o=Number(a);if(`${o}`!==a)throw new Error;if(o<0||o>128)throw new Error;new URL(`http://[${s}]`)}catch{r.issues.push({code:"invalid_format",format:"cidrv6",input:r.value,inst:t,continue:!e.abort})}}});function xc(t){if(t==="")return!0;if(t.length%4!==0)return!1;try{return atob(t),!0}catch{return!1}}const Zw=y("$ZodBase64",(t,e)=>{e.pattern??(e.pattern=Lg),L.init(t,e),t._zod.onattach.push(r=>{r._zod.bag.contentEncoding="base64"}),t._zod.check=r=>{xc(r.value)||r.issues.push({code:"invalid_format",format:"base64",input:r.value,inst:t,continue:!e.abort})}});function Cw(t){if(!Oc.test(t))return!1;const e=t.replace(/[-_]/g,n=>n==="-"?"+":"/"),r=e.padEnd(Math.ceil(e.length/4)*4,"=");return xc(r)}const Rw=y("$ZodBase64URL",(t,e)=>{e.pattern??(e.pattern=Oc),L.init(t,e),t._zod.onattach.push(r=>{r._zod.bag.contentEncoding="base64url"}),t._zod.check=r=>{Cw(r.value)||r.issues.push({code:"invalid_format",format:"base64url",input:r.value,inst:t,continue:!e.abort})}}),_w=y("$ZodE164",(t,e)=>{e.pattern??(e.pattern=qg),L.init(t,e)});function jw(t,e=null){try{const r=t.split(".");if(r.length!==3)return!1;const[n]=r;if(!n)return!1;const s=JSON.parse(atob(n));return!("typ"in s&&s?.typ!=="JWT"||!s.alg||e&&(!("alg"in s)||s.alg!==e))}catch{return!1}}const Mw=y("$ZodJWT",(t,e)=>{L.init(t,e),t._zod.check=r=>{jw(r.value,e.alg)||r.issues.push({code:"invalid_format",format:"jwt",input:r.value,inst:t,continue:!e.abort})}}),Zc=y("$ZodNumber",(t,e)=>{F.init(t,e),t._zod.pattern=t._zod.bag.pattern??Gg,t._zod.parse=(r,n)=>{if(e.coerce)try{r.value=Number(r.value)}catch{}const s=r.value;if(typeof s=="number"&&!Number.isNaN(s)&&Number.isFinite(s))return r;const a=typeof s=="number"?Number.isNaN(s)?"NaN":Number.isFinite(s)?void 0:"Infinity":void 0;return r.issues.push({expected:"number",code:"invalid_type",input:s,inst:t,...a?{received:a}:{}}),r}}),Dw=y("$ZodNumber",(t,e)=>{ew.init(t,e),Zc.init(t,e)}),Pw=y("$ZodBoolean",(t,e)=>{F.init(t,e),t._zod.pattern=Jg,t._zod.parse=(r,n)=>{if(e.coerce)try{r.value=!!r.value}catch{}const s=r.value;return typeof s=="boolean"||r.issues.push({expected:"boolean",code:"invalid_type",input:s,inst:t}),r}}),Uw=y("$ZodUnknown",(t,e)=>{F.init(t,e),t._zod.parse=r=>r}),Lw=y("$ZodNever",(t,e)=>{F.init(t,e),t._zod.parse=(r,n)=>(r.issues.push({expected:"never",code:"invalid_type",input:r.value,inst:t}),r)});function xi(t,e,r){t.issues.length&&e.issues.push(...Tc(r,t.issues)),e.value[r]=t.value}const Bw=y("$ZodArray",(t,e)=>{F.init(t,e),t._zod.parse=(r,n)=>{const s=r.value;if(!Array.isArray(s))return r.issues.push({expected:"array",code:"invalid_type",input:s,inst:t}),r;r.value=Array(s.length);const a=[];for(let o=0;o<s.length;o++){const c=s[o],l=e.element._zod.run({value:c,issues:[]},n);l instanceof Promise?a.push(l.then(u=>xi(u,r,o))):xi(l,r,o)}return a.length?Promise.all(a).then(()=>r):r}});function Mr(t,e,r,n){t.issues.length&&e.issues.push(...Tc(r,t.issues)),t.value===void 0?r in n&&(e.value[r]=void 0):e.value[r]=t.value}function Cc(t){const e=Object.keys(t.shape);for(const n of e)if(!t.shape?.[n]?._zod?.traits?.has("$ZodType"))throw new Error(`Invalid element at key "${n}": expected a Zod schema`);const r=ig(t.shape);return{...t,keys:e,keySet:new Set(e),numKeys:e.length,optionalKeys:new Set(r)}}function Rc(t,e,r,n,s,a){const o=[],c=s.keySet,l=s.catchall._zod,u=l.def.type;for(const h of Object.keys(e)){if(c.has(h))continue;if(u==="never"){o.push(h);continue}const d=l.run({value:e[h],issues:[]},n);d instanceof Promise?t.push(d.then(f=>Mr(f,r,h,e))):Mr(d,r,h,e)}return o.length&&r.issues.push({code:"unrecognized_keys",keys:o,input:e,inst:a}),t.length?Promise.all(t).then(()=>r):r}const qw=y("$ZodObject",(t,e)=>{F.init(t,e);const r=_s(()=>Cc(e));U(t._zod,"propValues",()=>{const o=e.shape,c={};for(const l in o){const u=o[l]._zod;if(u.values){c[l]??(c[l]=new Set);for(const h of u.values)c[l].add(h)}}return c});const n=jr,s=e.catchall;let a;t._zod.parse=(o,c)=>{a??(a=r.value);const l=o.value;if(!n(l))return o.issues.push({expected:"object",code:"invalid_type",input:l,inst:t}),o;o.value={};const u=[],h=a.shape;for(const d of a.keys){const v=h[d]._zod.run({value:l[d],issues:[]},c);v instanceof Promise?u.push(v.then(S=>Mr(S,o,d,l))):Mr(v,o,d,l)}return s?Rc(u,l,o,c,r.value,t):u.length?Promise.all(u).then(()=>o):o}}),Fw=y("$ZodObjectJIT",(t,e)=>{qw.init(t,e);const r=t._zod.parse,n=_s(()=>Cc(e)),s=f=>{const v=new hw(["shape","payload","ctx"]),S=n.value,Z=G=>{const V=ki(G);return`shape[${V}]._zod.run({ value: input[${V}], issues: [] }, ctx)`};v.write("const input = payload.value;");const b=Object.create(null);let z=0;for(const G of S.keys)b[G]=`key_${z++}`;v.write("const newResult = {};");for(const G of S.keys){const V=b[G],ye=ki(G);v.write(`const ${V} = ${Z(G)};`),v.write(`
|
|
24
|
+
if (${V}.issues.length) {
|
|
25
|
+
payload.issues = payload.issues.concat(${V}.issues.map(iss => ({
|
|
26
|
+
...iss,
|
|
27
|
+
path: iss.path ? [${ye}, ...iss.path] : [${ye}]
|
|
28
|
+
})));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
if (${V}.value === undefined) {
|
|
33
|
+
if (${ye} in input) {
|
|
34
|
+
newResult[${ye}] = undefined;
|
|
35
|
+
}
|
|
36
|
+
} else {
|
|
37
|
+
newResult[${ye}] = ${V}.value;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
`)}v.write("payload.value = newResult;"),v.write("return payload;");const k=v.compile();return(G,V)=>k(f,G,V)};let a;const o=jr,c=!wc.jitless,u=c&&ng.value,h=e.catchall;let d;t._zod.parse=(f,v)=>{d??(d=n.value);const S=f.value;return o(S)?c&&u&&v?.async===!1&&v.jitless!==!0?(a||(a=s(e.shape)),f=a(f,v),h?Rc([],S,f,v,d,t):f):r(f,v):(f.issues.push({expected:"object",code:"invalid_type",input:S,inst:t}),f)}});function Zi(t,e,r,n){for(const a of t)if(a.issues.length===0)return e.value=a.value,e;const s=t.filter(a=>!dt(a));return s.length===1?(e.value=s[0].value,s[0]):(e.issues.push({code:"invalid_union",input:e.value,inst:r,errors:t.map(a=>a.issues.map(o=>nt(o,n,rt())))}),e)}const Vw=y("$ZodUnion",(t,e)=>{F.init(t,e),U(t._zod,"optin",()=>e.options.some(s=>s._zod.optin==="optional")?"optional":void 0),U(t._zod,"optout",()=>e.options.some(s=>s._zod.optout==="optional")?"optional":void 0),U(t._zod,"values",()=>{if(e.options.every(s=>s._zod.values))return new Set(e.options.flatMap(s=>Array.from(s._zod.values)))}),U(t._zod,"pattern",()=>{if(e.options.every(s=>s._zod.pattern)){const s=e.options.map(a=>a._zod.pattern);return new RegExp(`^(${s.map(a=>Ms(a.source)).join("|")})$`)}});const r=e.options.length===1,n=e.options[0]._zod.run;t._zod.parse=(s,a)=>{if(r)return n(s,a);let o=!1;const c=[];for(const l of e.options){const u=l._zod.run({value:s.value,issues:[]},a);if(u instanceof Promise)c.push(u),o=!0;else{if(u.issues.length===0)return u;c.push(u)}}return o?Promise.all(c).then(l=>Zi(l,s,t,a)):Zi(c,s,t,a)}}),Yw=y("$ZodIntersection",(t,e)=>{F.init(t,e),t._zod.parse=(r,n)=>{const s=r.value,a=e.left._zod.run({value:s,issues:[]},n),o=e.right._zod.run({value:s,issues:[]},n);return a instanceof Promise||o instanceof Promise?Promise.all([a,o]).then(([l,u])=>Ci(r,l,u)):Ci(r,a,o)}});function os(t,e){if(t===e)return{valid:!0,data:t};if(t instanceof Date&&e instanceof Date&&+t==+e)return{valid:!0,data:t};if(Jt(t)&&Jt(e)){const r=Object.keys(e),n=Object.keys(t).filter(a=>r.indexOf(a)!==-1),s={...t,...e};for(const a of n){const o=os(t[a],e[a]);if(!o.valid)return{valid:!1,mergeErrorPath:[a,...o.mergeErrorPath]};s[a]=o.data}return{valid:!0,data:s}}if(Array.isArray(t)&&Array.isArray(e)){if(t.length!==e.length)return{valid:!1,mergeErrorPath:[]};const r=[];for(let n=0;n<t.length;n++){const s=t[n],a=e[n],o=os(s,a);if(!o.valid)return{valid:!1,mergeErrorPath:[n,...o.mergeErrorPath]};r.push(o.data)}return{valid:!0,data:r}}return{valid:!1,mergeErrorPath:[]}}function Ci(t,e,r){if(e.issues.length&&t.issues.push(...e.issues),r.issues.length&&t.issues.push(...r.issues),dt(t))return t;const n=os(e.value,r.value);if(!n.valid)throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(n.mergeErrorPath)}`);return t.value=n.data,t}const Ww=y("$ZodEnum",(t,e)=>{F.init(t,e);const r=eg(e.entries),n=new Set(r);t._zod.values=n,t._zod.pattern=new RegExp(`^(${r.filter(s=>sg.has(typeof s)).map(s=>typeof s=="string"?Xr(s):s.toString()).join("|")})$`),t._zod.parse=(s,a)=>{const o=s.value;return n.has(o)||s.issues.push({code:"invalid_value",values:r,input:o,inst:t}),s}}),Hw=y("$ZodTransform",(t,e)=>{F.init(t,e),t._zod.parse=(r,n)=>{if(n.direction==="backward")throw new gc(t.constructor.name);const s=e.transform(r.value,r);if(n.async)return(s instanceof Promise?s:Promise.resolve(s)).then(o=>(r.value=o,r));if(s instanceof Promise)throw new wt;return r.value=s,r}});function Ri(t,e){return t.issues.length&&e===void 0?{issues:[],value:void 0}:t}const Gw=y("$ZodOptional",(t,e)=>{F.init(t,e),t._zod.optin="optional",t._zod.optout="optional",U(t._zod,"values",()=>e.innerType._zod.values?new Set([...e.innerType._zod.values,void 0]):void 0),U(t._zod,"pattern",()=>{const r=e.innerType._zod.pattern;return r?new RegExp(`^(${Ms(r.source)})?$`):void 0}),t._zod.parse=(r,n)=>{if(e.innerType._zod.optin==="optional"){const s=e.innerType._zod.run(r,n);return s instanceof Promise?s.then(a=>Ri(a,r.value)):Ri(s,r.value)}return r.value===void 0?r:e.innerType._zod.run(r,n)}}),Jw=y("$ZodNullable",(t,e)=>{F.init(t,e),U(t._zod,"optin",()=>e.innerType._zod.optin),U(t._zod,"optout",()=>e.innerType._zod.optout),U(t._zod,"pattern",()=>{const r=e.innerType._zod.pattern;return r?new RegExp(`^(${Ms(r.source)}|null)$`):void 0}),U(t._zod,"values",()=>e.innerType._zod.values?new Set([...e.innerType._zod.values,null]):void 0),t._zod.parse=(r,n)=>r.value===null?r:e.innerType._zod.run(r,n)}),Kw=y("$ZodDefault",(t,e)=>{F.init(t,e),t._zod.optin="optional",U(t._zod,"values",()=>e.innerType._zod.values),t._zod.parse=(r,n)=>{if(n.direction==="backward")return e.innerType._zod.run(r,n);if(r.value===void 0)return r.value=e.defaultValue,r;const s=e.innerType._zod.run(r,n);return s instanceof Promise?s.then(a=>_i(a,e)):_i(s,e)}});function _i(t,e){return t.value===void 0&&(t.value=e.defaultValue),t}const Xw=y("$ZodPrefault",(t,e)=>{F.init(t,e),t._zod.optin="optional",U(t._zod,"values",()=>e.innerType._zod.values),t._zod.parse=(r,n)=>(n.direction==="backward"||r.value===void 0&&(r.value=e.defaultValue),e.innerType._zod.run(r,n))}),Qw=y("$ZodNonOptional",(t,e)=>{F.init(t,e),U(t._zod,"values",()=>{const r=e.innerType._zod.values;return r?new Set([...r].filter(n=>n!==void 0)):void 0}),t._zod.parse=(r,n)=>{const s=e.innerType._zod.run(r,n);return s instanceof Promise?s.then(a=>ji(a,t)):ji(s,t)}});function ji(t,e){return!t.issues.length&&t.value===void 0&&t.issues.push({code:"invalid_type",expected:"nonoptional",input:t.value,inst:e}),t}const eb=y("$ZodCatch",(t,e)=>{F.init(t,e),U(t._zod,"optin",()=>e.innerType._zod.optin),U(t._zod,"optout",()=>e.innerType._zod.optout),U(t._zod,"values",()=>e.innerType._zod.values),t._zod.parse=(r,n)=>{if(n.direction==="backward")return e.innerType._zod.run(r,n);const s=e.innerType._zod.run(r,n);return s instanceof Promise?s.then(a=>(r.value=a.value,a.issues.length&&(r.value=e.catchValue({...r,error:{issues:a.issues.map(o=>nt(o,n,rt()))},input:r.value}),r.issues=[]),r)):(r.value=s.value,s.issues.length&&(r.value=e.catchValue({...r,error:{issues:s.issues.map(a=>nt(a,n,rt()))},input:r.value}),r.issues=[]),r)}}),tb=y("$ZodPipe",(t,e)=>{F.init(t,e),U(t._zod,"values",()=>e.in._zod.values),U(t._zod,"optin",()=>e.in._zod.optin),U(t._zod,"optout",()=>e.out._zod.optout),U(t._zod,"propValues",()=>e.in._zod.propValues),t._zod.parse=(r,n)=>{if(n.direction==="backward"){const a=e.out._zod.run(r,n);return a instanceof Promise?a.then(o=>Nr(o,e.in,n)):Nr(a,e.in,n)}const s=e.in._zod.run(r,n);return s instanceof Promise?s.then(a=>Nr(a,e.out,n)):Nr(s,e.out,n)}});function Nr(t,e,r){return t.issues.length?(t.aborted=!0,t):e._zod.run({value:t.value,issues:t.issues},r)}const rb=y("$ZodReadonly",(t,e)=>{F.init(t,e),U(t._zod,"propValues",()=>e.innerType._zod.propValues),U(t._zod,"values",()=>e.innerType._zod.values),U(t._zod,"optin",()=>e.innerType._zod.optin),U(t._zod,"optout",()=>e.innerType._zod.optout),t._zod.parse=(r,n)=>{if(n.direction==="backward")return e.innerType._zod.run(r,n);const s=e.innerType._zod.run(r,n);return s instanceof Promise?s.then(Mi):Mi(s)}});function Mi(t){return t.value=Object.freeze(t.value),t}const nb=y("$ZodCustom",(t,e)=>{ae.init(t,e),F.init(t,e),t._zod.parse=(r,n)=>r,t._zod.check=r=>{const n=r.value,s=e.fn(n);if(s instanceof Promise)return s.then(a=>Di(a,r,n,t));Di(s,r,n,t)}});function Di(t,e,r,n){if(!t){const s={code:"custom",input:r,inst:n,path:[...n._zod.def.path??[]],continue:!n._zod.def.abort};n._zod.def.params&&(s.params=n._zod.def.params),e.issues.push(Kt(s))}}class sb{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...r){const n=r[0];if(this._map.set(e,n),n&&typeof n=="object"&&"id"in n){if(this._idmap.has(n.id))throw new Error(`ID ${n.id} already exists in the registry`);this._idmap.set(n.id,e)}return this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(e){const r=this._map.get(e);return r&&typeof r=="object"&&"id"in r&&this._idmap.delete(r.id),this._map.delete(e),this}get(e){const r=e._zod.parent;if(r){const n={...this.get(r)??{}};delete n.id;const s={...n,...this._map.get(e)};return Object.keys(s).length?s:void 0}return this._map.get(e)}has(e){return this._map.has(e)}}function ib(){return new sb}const Or=ib();function ab(t,e){return new t({type:"string",...$(e)})}function ob(t,e){return new t({type:"string",format:"email",check:"string_format",abort:!1,...$(e)})}function Pi(t,e){return new t({type:"string",format:"guid",check:"string_format",abort:!1,...$(e)})}function _c(t,e){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,...$(e)})}function cb(t,e){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...$(e)})}function ub(t,e){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...$(e)})}function lb(t,e){return new t({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...$(e)})}function hb(t,e){return new t({type:"string",format:"url",check:"string_format",abort:!1,...$(e)})}function fb(t,e){return new t({type:"string",format:"emoji",check:"string_format",abort:!1,...$(e)})}function db(t,e){return new t({type:"string",format:"nanoid",check:"string_format",abort:!1,...$(e)})}function pb(t,e){return new t({type:"string",format:"cuid",check:"string_format",abort:!1,...$(e)})}function yb(t,e){return new t({type:"string",format:"cuid2",check:"string_format",abort:!1,...$(e)})}function mb(t,e){return new t({type:"string",format:"ulid",check:"string_format",abort:!1,...$(e)})}function gb(t,e){return new t({type:"string",format:"xid",check:"string_format",abort:!1,...$(e)})}function wb(t,e){return new t({type:"string",format:"ksuid",check:"string_format",abort:!1,...$(e)})}function bb(t,e){return new t({type:"string",format:"ipv4",check:"string_format",abort:!1,...$(e)})}function vb(t,e){return new t({type:"string",format:"ipv6",check:"string_format",abort:!1,...$(e)})}function Tb(t,e){return new t({type:"string",format:"cidrv4",check:"string_format",abort:!1,...$(e)})}function zb(t,e){return new t({type:"string",format:"cidrv6",check:"string_format",abort:!1,...$(e)})}function Eb(t,e){return new t({type:"string",format:"base64",check:"string_format",abort:!1,...$(e)})}function Nb(t,e){return new t({type:"string",format:"base64url",check:"string_format",abort:!1,...$(e)})}function Ob(t,e){return new t({type:"string",format:"e164",check:"string_format",abort:!1,...$(e)})}function $b(t,e){return new t({type:"string",format:"jwt",check:"string_format",abort:!1,...$(e)})}function Sb(t,e){return new t({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...$(e)})}function Ib(t,e){return new t({type:"string",format:"date",check:"string_format",...$(e)})}function kb(t,e){return new t({type:"string",format:"time",check:"string_format",precision:null,...$(e)})}function Ab(t,e){return new t({type:"string",format:"duration",check:"string_format",...$(e)})}function xb(t,e){return new t({type:"number",checks:[],...$(e)})}function Zb(t,e){return new t({type:"number",check:"number_format",abort:!1,format:"safeint",...$(e)})}function Cb(t,e){return new t({type:"boolean",...$(e)})}function Rb(t){return new t({type:"unknown"})}function _b(t,e){return new t({type:"never",...$(e)})}function Ui(t,e){return new kc({check:"less_than",...$(e),value:t,inclusive:!1})}function $n(t,e){return new kc({check:"less_than",...$(e),value:t,inclusive:!0})}function Li(t,e){return new Ac({check:"greater_than",...$(e),value:t,inclusive:!1})}function Sn(t,e){return new Ac({check:"greater_than",...$(e),value:t,inclusive:!0})}function Bi(t,e){return new Qg({check:"multiple_of",...$(e),value:t})}function jc(t,e){return new tw({check:"max_length",...$(e),maximum:t})}function Dr(t,e){return new rw({check:"min_length",...$(e),minimum:t})}function Mc(t,e){return new nw({check:"length_equals",...$(e),length:t})}function jb(t,e){return new sw({check:"string_format",format:"regex",...$(e),pattern:t})}function Mb(t){return new iw({check:"string_format",format:"lowercase",...$(t)})}function Db(t){return new aw({check:"string_format",format:"uppercase",...$(t)})}function Pb(t,e){return new ow({check:"string_format",format:"includes",...$(e),includes:t})}function Ub(t,e){return new cw({check:"string_format",format:"starts_with",...$(e),prefix:t})}function Lb(t,e){return new uw({check:"string_format",format:"ends_with",...$(e),suffix:t})}function cr(t){return new lw({check:"overwrite",tx:t})}function Bb(t){return cr(e=>e.normalize(t))}function qb(){return cr(t=>t.trim())}function Fb(){return cr(t=>t.toLowerCase())}function Vb(){return cr(t=>t.toUpperCase())}function Yb(t,e,r){return new t({type:"array",element:e,...$(r)})}function Wb(t,e,r){return new t({type:"custom",check:"custom",fn:e,...$(r)})}function Hb(t){const e=Gb(r=>(r.addIssue=n=>{if(typeof n=="string")r.issues.push(Kt(n,r.value,e._zod.def));else{const s=n;s.fatal&&(s.continue=!1),s.code??(s.code="custom"),s.input??(s.input=r.value),s.inst??(s.inst=e),s.continue??(s.continue=!e._zod.def.abort),r.issues.push(Kt(s))}},t(r.value,r)));return e}function Gb(t,e){const r=new ae({check:"custom",...$(e)});return r._zod.check=t,r}const Jb=y("ZodISODateTime",(t,e)=>{Nw.init(t,e),q.init(t,e)});function Kb(t){return Sb(Jb,t)}const Xb=y("ZodISODate",(t,e)=>{Ow.init(t,e),q.init(t,e)});function Qb(t){return Ib(Xb,t)}const ev=y("ZodISOTime",(t,e)=>{$w.init(t,e),q.init(t,e)});function tv(t){return kb(ev,t)}const rv=y("ZodISODuration",(t,e)=>{Sw.init(t,e),q.init(t,e)});function nv(t){return Ab(rv,t)}const sv=(t,e)=>{Ec.init(t,e),t.name="ZodError",Object.defineProperties(t,{format:{value:r=>yg(t,r)},flatten:{value:r=>pg(t,r)},addIssue:{value:r=>{t.issues.push(r),t.message=JSON.stringify(t.issues,as,2)}},addIssues:{value:r=>{t.issues.push(...r),t.message=JSON.stringify(t.issues,as,2)}},isEmpty:{get(){return t.issues.length===0}}})},pe=y("ZodError",sv,{Parent:Error}),iv=Ps(pe),av=Us(pe),ov=Qr(pe),cv=en(pe),uv=wg(pe),lv=bg(pe),hv=vg(pe),fv=Tg(pe),dv=zg(pe),pv=Eg(pe),yv=Ng(pe),mv=Og(pe),H=y("ZodType",(t,e)=>(F.init(t,e),t.def=e,t.type=e.type,Object.defineProperty(t,"_def",{value:e}),t.check=(...r)=>t.clone({...e,checks:[...e.checks??[],...r.map(n=>typeof n=="function"?{_zod:{check:n,def:{check:"custom"},onattach:[]}}:n)]}),t.clone=(r,n)=>Ye(t,r,n),t.brand=()=>t,t.register=((r,n)=>(r.add(t,n),t)),t.parse=(r,n)=>iv(t,r,n,{callee:t.parse}),t.safeParse=(r,n)=>ov(t,r,n),t.parseAsync=async(r,n)=>av(t,r,n,{callee:t.parseAsync}),t.safeParseAsync=async(r,n)=>cv(t,r,n),t.spa=t.safeParseAsync,t.encode=(r,n)=>uv(t,r,n),t.decode=(r,n)=>lv(t,r,n),t.encodeAsync=async(r,n)=>hv(t,r,n),t.decodeAsync=async(r,n)=>fv(t,r,n),t.safeEncode=(r,n)=>dv(t,r,n),t.safeDecode=(r,n)=>pv(t,r,n),t.safeEncodeAsync=async(r,n)=>yv(t,r,n),t.safeDecodeAsync=async(r,n)=>mv(t,r,n),t.refine=(r,n)=>t.check(cT(r,n)),t.superRefine=r=>t.check(uT(r)),t.overwrite=r=>t.check(cr(r)),t.optional=()=>Wi(t),t.nullable=()=>Hi(t),t.nullish=()=>Wi(Hi(t)),t.nonoptional=r=>tT(t,r),t.array=()=>Bv(t),t.or=r=>Bs([t,r]),t.and=r=>Yv(t,r),t.transform=r=>Gi(t,Gv(r)),t.default=r=>Xv(t,r),t.prefault=r=>eT(t,r),t.catch=r=>nT(t,r),t.pipe=r=>Gi(t,r),t.readonly=()=>aT(t),t.describe=r=>{const n=t.clone();return Or.add(n,{description:r}),n},Object.defineProperty(t,"description",{get(){return Or.get(t)?.description},configurable:!0}),t.meta=(...r)=>{if(r.length===0)return Or.get(t);const n=t.clone();return Or.add(n,r[0]),n},t.isOptional=()=>t.safeParse(void 0).success,t.isNullable=()=>t.safeParse(null).success,t)),Dc=y("_ZodString",(t,e)=>{Ls.init(t,e),H.init(t,e);const r=t._zod.bag;t.format=r.format??null,t.minLength=r.minimum??null,t.maxLength=r.maximum??null,t.regex=(...n)=>t.check(jb(...n)),t.includes=(...n)=>t.check(Pb(...n)),t.startsWith=(...n)=>t.check(Ub(...n)),t.endsWith=(...n)=>t.check(Lb(...n)),t.min=(...n)=>t.check(Dr(...n)),t.max=(...n)=>t.check(jc(...n)),t.length=(...n)=>t.check(Mc(...n)),t.nonempty=(...n)=>t.check(Dr(1,...n)),t.lowercase=n=>t.check(Mb(n)),t.uppercase=n=>t.check(Db(n)),t.trim=()=>t.check(qb()),t.normalize=(...n)=>t.check(Bb(...n)),t.toLowerCase=()=>t.check(Fb()),t.toUpperCase=()=>t.check(Vb())}),gv=y("ZodString",(t,e)=>{Ls.init(t,e),Dc.init(t,e),t.email=r=>t.check(ob(wv,r)),t.url=r=>t.check(hb(vv,r)),t.jwt=r=>t.check($b(_v,r)),t.emoji=r=>t.check(fb(Tv,r)),t.guid=r=>t.check(Pi(qi,r)),t.uuid=r=>t.check(_c(Pt,r)),t.uuidv4=r=>t.check(cb(Pt,r)),t.uuidv6=r=>t.check(ub(Pt,r)),t.uuidv7=r=>t.check(lb(Pt,r)),t.nanoid=r=>t.check(db(zv,r)),t.guid=r=>t.check(Pi(qi,r)),t.cuid=r=>t.check(pb(Ev,r)),t.cuid2=r=>t.check(yb(Nv,r)),t.ulid=r=>t.check(mb(Ov,r)),t.base64=r=>t.check(Eb(Zv,r)),t.base64url=r=>t.check(Nb(Cv,r)),t.xid=r=>t.check(gb($v,r)),t.ksuid=r=>t.check(wb(Sv,r)),t.ipv4=r=>t.check(bb(Iv,r)),t.ipv6=r=>t.check(vb(kv,r)),t.cidrv4=r=>t.check(Tb(Av,r)),t.cidrv6=r=>t.check(zb(xv,r)),t.e164=r=>t.check(Ob(Rv,r)),t.datetime=r=>t.check(Kb(r)),t.date=r=>t.check(Qb(r)),t.time=r=>t.check(tv(r)),t.duration=r=>t.check(nv(r))});function de(t){return ab(gv,t)}const q=y("ZodStringFormat",(t,e)=>{L.init(t,e),Dc.init(t,e)}),wv=y("ZodEmail",(t,e)=>{yw.init(t,e),q.init(t,e)}),qi=y("ZodGUID",(t,e)=>{dw.init(t,e),q.init(t,e)}),Pt=y("ZodUUID",(t,e)=>{pw.init(t,e),q.init(t,e)});function bv(t){return _c(Pt,t)}const vv=y("ZodURL",(t,e)=>{mw.init(t,e),q.init(t,e)}),Tv=y("ZodEmoji",(t,e)=>{gw.init(t,e),q.init(t,e)}),zv=y("ZodNanoID",(t,e)=>{ww.init(t,e),q.init(t,e)}),Ev=y("ZodCUID",(t,e)=>{bw.init(t,e),q.init(t,e)}),Nv=y("ZodCUID2",(t,e)=>{vw.init(t,e),q.init(t,e)}),Ov=y("ZodULID",(t,e)=>{Tw.init(t,e),q.init(t,e)}),$v=y("ZodXID",(t,e)=>{zw.init(t,e),q.init(t,e)}),Sv=y("ZodKSUID",(t,e)=>{Ew.init(t,e),q.init(t,e)}),Iv=y("ZodIPv4",(t,e)=>{Iw.init(t,e),q.init(t,e)}),kv=y("ZodIPv6",(t,e)=>{kw.init(t,e),q.init(t,e)}),Av=y("ZodCIDRv4",(t,e)=>{Aw.init(t,e),q.init(t,e)}),xv=y("ZodCIDRv6",(t,e)=>{xw.init(t,e),q.init(t,e)}),Zv=y("ZodBase64",(t,e)=>{Zw.init(t,e),q.init(t,e)}),Cv=y("ZodBase64URL",(t,e)=>{Rw.init(t,e),q.init(t,e)}),Rv=y("ZodE164",(t,e)=>{_w.init(t,e),q.init(t,e)}),_v=y("ZodJWT",(t,e)=>{Mw.init(t,e),q.init(t,e)}),Pc=y("ZodNumber",(t,e)=>{Zc.init(t,e),H.init(t,e),t.gt=(n,s)=>t.check(Li(n,s)),t.gte=(n,s)=>t.check(Sn(n,s)),t.min=(n,s)=>t.check(Sn(n,s)),t.lt=(n,s)=>t.check(Ui(n,s)),t.lte=(n,s)=>t.check($n(n,s)),t.max=(n,s)=>t.check($n(n,s)),t.int=n=>t.check(Vi(n)),t.safe=n=>t.check(Vi(n)),t.positive=n=>t.check(Li(0,n)),t.nonnegative=n=>t.check(Sn(0,n)),t.negative=n=>t.check(Ui(0,n)),t.nonpositive=n=>t.check($n(0,n)),t.multipleOf=(n,s)=>t.check(Bi(n,s)),t.step=(n,s)=>t.check(Bi(n,s)),t.finite=()=>t;const r=t._zod.bag;t.minValue=Math.max(r.minimum??Number.NEGATIVE_INFINITY,r.exclusiveMinimum??Number.NEGATIVE_INFINITY)??null,t.maxValue=Math.min(r.maximum??Number.POSITIVE_INFINITY,r.exclusiveMaximum??Number.POSITIVE_INFINITY)??null,t.isInt=(r.format??"").includes("int")||Number.isSafeInteger(r.multipleOf??.5),t.isFinite=!0,t.format=r.format??null});function Fi(t){return xb(Pc,t)}const jv=y("ZodNumberFormat",(t,e)=>{Dw.init(t,e),Pc.init(t,e)});function Vi(t){return Zb(jv,t)}const Mv=y("ZodBoolean",(t,e)=>{Pw.init(t,e),H.init(t,e)});function rn(t){return Cb(Mv,t)}const Dv=y("ZodUnknown",(t,e)=>{Uw.init(t,e),H.init(t,e)});function Yi(){return Rb(Dv)}const Pv=y("ZodNever",(t,e)=>{Lw.init(t,e),H.init(t,e)});function Uv(t){return _b(Pv,t)}const Lv=y("ZodArray",(t,e)=>{Bw.init(t,e),H.init(t,e),t.element=e.element,t.min=(r,n)=>t.check(Dr(r,n)),t.nonempty=r=>t.check(Dr(1,r)),t.max=(r,n)=>t.check(jc(r,n)),t.length=(r,n)=>t.check(Mc(r,n)),t.unwrap=()=>t.element});function Bv(t,e){return Yb(Lv,t,e)}const qv=y("ZodObject",(t,e)=>{Fw.init(t,e),H.init(t,e),U(t,"shape",()=>e.shape),t.keyof=()=>Wv(Object.keys(t._zod.def.shape)),t.catchall=r=>t.clone({...t._zod.def,catchall:r}),t.passthrough=()=>t.clone({...t._zod.def,catchall:Yi()}),t.loose=()=>t.clone({...t._zod.def,catchall:Yi()}),t.strict=()=>t.clone({...t._zod.def,catchall:Uv()}),t.strip=()=>t.clone({...t._zod.def,catchall:void 0}),t.extend=r=>ug(t,r),t.safeExtend=r=>lg(t,r),t.merge=r=>hg(t,r),t.pick=r=>og(t,r),t.omit=r=>cg(t,r),t.partial=(...r)=>fg(Uc,t,r[0]),t.required=(...r)=>dg(Lc,t,r[0])});function ie(t,e){const r={type:"object",get shape(){return Ve(this,"shape",t?rg(t):{}),this.shape},...$(e)};return new qv(r)}const Fv=y("ZodUnion",(t,e)=>{Vw.init(t,e),H.init(t,e),t.options=e.options});function Bs(t,e){return new Fv({type:"union",options:t,...$(e)})}const Vv=y("ZodIntersection",(t,e)=>{Yw.init(t,e),H.init(t,e)});function Yv(t,e){return new Vv({type:"intersection",left:t,right:e})}const cs=y("ZodEnum",(t,e)=>{Ww.init(t,e),H.init(t,e),t.enum=e.entries,t.options=Object.values(e.entries);const r=new Set(Object.keys(e.entries));t.extract=(n,s)=>{const a={};for(const o of n)if(r.has(o))a[o]=e.entries[o];else throw new Error(`Key ${o} not found in enum`);return new cs({...e,checks:[],...$(s),entries:a})},t.exclude=(n,s)=>{const a={...e.entries};for(const o of n)if(r.has(o))delete a[o];else throw new Error(`Key ${o} not found in enum`);return new cs({...e,checks:[],...$(s),entries:a})}});function Wv(t,e){const r=Array.isArray(t)?Object.fromEntries(t.map(n=>[n,n])):t;return new cs({type:"enum",entries:r,...$(e)})}const Hv=y("ZodTransform",(t,e)=>{Hw.init(t,e),H.init(t,e),t._zod.parse=(r,n)=>{if(n.direction==="backward")throw new gc(t.constructor.name);r.addIssue=a=>{if(typeof a=="string")r.issues.push(Kt(a,r.value,e));else{const o=a;o.fatal&&(o.continue=!1),o.code??(o.code="custom"),o.input??(o.input=r.value),o.inst??(o.inst=t),r.issues.push(Kt(o))}};const s=e.transform(r.value,r);return s instanceof Promise?s.then(a=>(r.value=a,r)):(r.value=s,r)}});function Gv(t){return new Hv({type:"transform",transform:t})}const Uc=y("ZodOptional",(t,e)=>{Gw.init(t,e),H.init(t,e),t.unwrap=()=>t._zod.def.innerType});function Wi(t){return new Uc({type:"optional",innerType:t})}const Jv=y("ZodNullable",(t,e)=>{Jw.init(t,e),H.init(t,e),t.unwrap=()=>t._zod.def.innerType});function Hi(t){return new Jv({type:"nullable",innerType:t})}const Kv=y("ZodDefault",(t,e)=>{Kw.init(t,e),H.init(t,e),t.unwrap=()=>t._zod.def.innerType,t.removeDefault=t.unwrap});function Xv(t,e){return new Kv({type:"default",innerType:t,get defaultValue(){return typeof e=="function"?e():vc(e)}})}const Qv=y("ZodPrefault",(t,e)=>{Xw.init(t,e),H.init(t,e),t.unwrap=()=>t._zod.def.innerType});function eT(t,e){return new Qv({type:"prefault",innerType:t,get defaultValue(){return typeof e=="function"?e():vc(e)}})}const Lc=y("ZodNonOptional",(t,e)=>{Qw.init(t,e),H.init(t,e),t.unwrap=()=>t._zod.def.innerType});function tT(t,e){return new Lc({type:"nonoptional",innerType:t,...$(e)})}const rT=y("ZodCatch",(t,e)=>{eb.init(t,e),H.init(t,e),t.unwrap=()=>t._zod.def.innerType,t.removeCatch=t.unwrap});function nT(t,e){return new rT({type:"catch",innerType:t,catchValue:typeof e=="function"?e:()=>e})}const sT=y("ZodPipe",(t,e)=>{tb.init(t,e),H.init(t,e),t.in=e.in,t.out=e.out});function Gi(t,e){return new sT({type:"pipe",in:t,out:e})}const iT=y("ZodReadonly",(t,e)=>{rb.init(t,e),H.init(t,e),t.unwrap=()=>t._zod.def.innerType});function aT(t){return new iT({type:"readonly",innerType:t})}const oT=y("ZodCustom",(t,e)=>{nb.init(t,e),H.init(t,e)});function cT(t,e={}){return Wb(oT,t,e)}function uT(t){return Hb(t)}const Ie=t=>t?JSON.parse(t):{},qs=ie({key:de(),type:de(),config:be.unknownZ.or(de().transform(Ie)),source:de().optional()}),Bc=qs.extend({position:Is.xy}),us=ie({param:de(),node:de()}),Fs=ie({source:us,target:us}),lT=ie({nodes:qs.array(),edges:Fs.array()}),qc=ie({nodes:Bc.array(),edges:Fs.array()}),Fc=ie({raw:de()}),ur=bv(),nn=ie({key:ur,name:de(),graph:qc,text:Fc,deploy:rn(),version:de()}),Vc=nn.partial({key:!0}),Yc="arc",hT=(t,e,{convertNumericStrings:r=!0}={})=>{const n=!Array.isArray(t);let s=T.toArray(t);const a=s[0],o=typeof a;let c;return o==="string"&&r&&!isNaN(parseInt(a))&&"number"in e?(c=e.number,s=s.map(l=>parseInt(l))):c=e[o],{single:n,variant:c,normalized:s,actual:t}},ce=(t,e,r,n)=>{if(n){if(r.length===0)throw new Ht(`${t} not found matching ${JSON.stringify(e)}`);if(r.length>1)throw new Gt(`Expected one ${t} matching ${JSON.stringify(e)}, but found ${r.length}`)}},fT="/arc/retrieve",dT="/arc/create",pT="/arc/delete",yT=ie({keys:ur.array().optional(),names:de().array().optional(),searchTerm:de().optional(),limit:Fi().optional(),offset:Fi().optional(),includeStatus:rn().optional()}),mT=ie({arcs:Vc.array()}),gT=ie({keys:ur.array()}),wT=ie({arcs:T.nullableZ(nn)}),bT=ie({arcs:nn.array()}),vT=ie({}),TT=ie({key:ur,includeStatus:rn().optional()}).transform(({key:t,includeStatus:e})=>({keys:[t],includeStatus:e})),zT=ie({name:de(),includeStatus:rn().optional()}).transform(({name:t,includeStatus:e})=>({names:[t],includeStatus:e})),Wc=Bs([TT,zT]),ET=Bs([Wc,yT]);let Hc=class{client;constructor(e){this.client=e}async create(e){const r=Array.isArray(e),n=await w(this.client,dT,{arcs:T.toArray(e)},mT,bT);return r?n.arcs:n.arcs[0]}async retrieve(e){const r="key"in e||"name"in e,n=await w(this.client,fT,e,ET,wT);return ce("Arc",e,n.arcs,r),r?n.arcs[0]:n.arcs}async delete(e){await w(this.client,pT,{keys:T.toArray(e)},gT,vT)}};const NT=t=>({type:Yc,key:t}),OT=Object.freeze(Object.defineProperty({__proto__:null,Client:Hc,ONTOLOGY_TYPE:Yc,arcZ:nn,edgeZ:Fs,graphNodeZ:Bc,graphZ:qc,handleZ:us,irNodeZ:qs,irZ:lT,keyZ:ur,newZ:Vc,ontologyID:NT,singleRetrieveArgsZ:Wc,textZ:Fc},Symbol.toStringTag,{value:"Module"})),Ji="Channel key must be a valid uint32.",D=i.z.uint32().or(i.z.string().refine(t=>!isNaN(Number(t)),{message:Ji}).transform(Number).refine(t=>t<Kn.MAX_UINT32,{message:Ji})),xe=i.z.string(),Gc=It.statusZ(),xt=i.z.object({name:xe,key:D,dataType:R.z,leaseholder:i.z.number(),index:D,isIndex:i.z.boolean(),internal:i.z.boolean(),virtual:i.z.boolean(),alias:i.z.string().optional(),expression:i.z.string().default(""),requires:T.nullableZ(D),status:Gc.optional()}),Jc=xt.extend({key:D.optional(),leaseholder:i.z.number().optional(),index:D.optional(),isIndex:i.z.boolean().optional(),internal:i.z.boolean().optional().default(!1),virtual:i.z.boolean().optional().default(!1),expression:i.z.string().optional().default(""),requires:T.nullableZ(D).optional().default([])}),it=i.z.union([Lt.toArray(D),Lt.toArray(xe),Lt.toArray(xt).transform(t=>t.map(e=>e.key))]),$T=new Error("request for lock canceled");var ST=function(t,e,r,n){function s(a){return a instanceof r?a:new r(function(o){o(a)})}return new(r||(r=Promise))(function(a,o){function c(h){try{u(n.next(h))}catch(d){o(d)}}function l(h){try{u(n.throw(h))}catch(d){o(d)}}function u(h){h.done?a(h.value):s(h.value).then(c,l)}u((n=n.apply(t,e||[])).next())})};class IT{constructor(e,r=$T){this._value=e,this._cancelError=r,this._queue=[],this._weightedWaiters=[]}acquire(e=1,r=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return new Promise((n,s)=>{const a={resolve:n,reject:s,weight:e,priority:r},o=Kc(this._queue,c=>r<=c.priority);o===-1&&e<=this._value?this._dispatchItem(a):this._queue.splice(o+1,0,a)})}runExclusive(e){return ST(this,arguments,void 0,function*(r,n=1,s=0){const[a,o]=yield this.acquire(n,s);try{return yield r(a)}finally{o()}})}waitForUnlock(e=1,r=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return this._couldLockImmediately(e,r)?Promise.resolve():new Promise(n=>{this._weightedWaiters[e-1]||(this._weightedWaiters[e-1]=[]),kT(this._weightedWaiters[e-1],{resolve:n,priority:r})})}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 r=this._value;this._value-=e.weight,e.resolve([r,this._newReleaser(e.weight)])}_newReleaser(e){let r=!1;return()=>{r||(r=!0,this.release(e))}}_drainUnlockWaiters(){if(this._queue.length===0)for(let e=this._value;e>0;e--){const r=this._weightedWaiters[e-1];r&&(r.forEach(n=>n.resolve()),this._weightedWaiters[e-1]=[])}else{const e=this._queue[0].priority;for(let r=this._value;r>0;r--){const n=this._weightedWaiters[r-1];if(!n)continue;const s=n.findIndex(a=>a.priority<=e);(s===-1?n:n.splice(0,s)).forEach((a=>a.resolve()))}}}_couldLockImmediately(e,r){return(this._queue.length===0||this._queue[0].priority<r)&&e<=this._value}}function kT(t,e){const r=Kc(t,n=>e.priority<=n.priority);t.splice(r+1,0,e)}function Kc(t,e){for(let r=t.length-1;r>=0;r--)if(e(t[r]))return r;return-1}var AT=function(t,e,r,n){function s(a){return a instanceof r?a:new r(function(o){o(a)})}return new(r||(r=Promise))(function(a,o){function c(h){try{u(n.next(h))}catch(d){o(d)}}function l(h){try{u(n.throw(h))}catch(d){o(d)}}function u(h){h.done?a(h.value):s(h.value).then(c,l)}u((n=n.apply(t,e||[])).next())})};class xT{constructor(e){this._semaphore=new IT(1,e)}acquire(){return AT(this,arguments,void 0,function*(e=0){const[,r]=yield this._semaphore.acquire(1,e);return r})}runExclusive(e,r=0){return this._semaphore.runExclusive(()=>e(),1,r)}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 ZT=i.z.object({leaseholder:i.z.number().optional(),keys:D.array().optional(),names:i.z.string().array().optional(),searchTerm:i.z.string().optional(),rangeKey:i.z.string().optional(),limit:i.z.number().optional(),offset:i.z.number().optional(),dataTypes:R.z.array().optional(),notDataTypes:R.z.array().optional(),virtual:i.z.boolean().optional(),isIndex:i.z.boolean().optional(),internal:i.z.boolean().optional(),calculated:i.z.boolean().optional()}),CT=i.z.object({channels:T.nullableZ(xt)}),ge=t=>(Array.isArray(t)&&t.length>0&&typeof t[0]=="object"?t=t.map(e=>e.key):typeof t=="object"&&"key"in t&&(t=[t.key]),hT(t,{number:"keys",string:"names"}));class lr{static ENDPOINT="/channel/retrieve";client;constructor(e){this.client=e}async retrieve(e,r){if(!Array.isArray(e)&&typeof e=="object")return await this.execute(e);const n=ge(e),{variant:s}=n;let{normalized:a}=n;return s==="keys"&&a.indexOf(0)!==-1&&(a=a.filter(o=>o!==0)),a.length===0?[]:await this.execute({[s]:a,...r})}async execute(e){const[r,n]=await this.client.send(lr.ENDPOINT,e,ZT,CT);if(n!=null)throw n;return r.channels}}class Vs{cache;namesToKeys;wrapped;constructor(e){this.cache=new Map,this.namesToKeys=new Map,this.wrapped=e}async retrieve(e,r){if(!Array.isArray(e)&&typeof e=="object")return await this.wrapped.retrieve(e);const{normalized:n}=ge(e),s=[],a=[];if(n.forEach(c=>{const l=this.get(c);l!=null?s.push(...l):a.push(c)}),a.length===0)return s;const o=await this.wrapped.retrieve(a,r);return this.set(o),s.concat(o)}delete(e){const{variant:r,normalized:n}=ge(e);r==="names"?n.forEach(s=>{const a=this.namesToKeys.get(s);a!=null&&(a.forEach(o=>this.cache.delete(o)),this.namesToKeys.delete(s))}):n.forEach(s=>{const a=this.cache.get(s);a!=null&&(this.cache.delete(s),this.namesToKeys.delete(a.name))})}rename(e,r){e.forEach((n,s)=>{const a=r[s],o=this.cache.get(n);if(o==null)return;this.cache.delete(n);const c=this.namesToKeys.get(o.name);c!=null&&(c.delete(n),c.size===0&&this.namesToKeys.delete(o.name)),o.name=a,this.cache.set(n,o);const l=this.namesToKeys.get(a);l==null?this.namesToKeys.set(a,new Set([n])):l.add(n)})}set(e){e.forEach(r=>{this.cache.set(r.key,r);const n=this.namesToKeys.get(r.name);n==null?this.namesToKeys.set(r.name,new Set([r.key])):n.add(r.key)})}get(e){if(typeof e=="number"){const s=this.cache.get(e);return s==null?void 0:[s]}const r=this.namesToKeys.get(e);if(r==null)return;const n=[];if(r.forEach(s=>{const a=this.cache.get(s);a!=null&&n.push(a)}),n.length!==0)return n}}class Xc{mu=new xT;requests=new Map;wrapped;debouncedRun;constructor(e,r){this.wrapped=e,this.debouncedRun=Up(()=>{this.run()},r)}async retrieve(e){if(!Array.isArray(e)&&typeof e=="object")return await this.wrapped.retrieve(e);const{normalized:r,variant:n}=ge(e);return n==="names"?await this.wrapped.retrieve(r):await new Promise((a,o)=>{this.mu.runExclusive(()=>{this.requests.set(r,{resolve:a,reject:o}),this.debouncedRun()})})}async run(){await this.mu.runExclusive(async()=>{const e=new Set;this.requests.forEach((r,n)=>n.forEach(s=>e.add(s)));try{const r=await this.wrapped.retrieve(Array.from(e));this.requests.forEach((n,s)=>n.resolve(r.filter(a=>s.includes(a.key))))}catch(r){this.requests.forEach(n=>n.reject(r))}finally{this.requests.clear()}})}}const Qc=async(t,e)=>{const{normalized:r}=ge(e),n=await t.retrieve(r),s=[];if(r.forEach(a=>{n.find(o=>o.name===a||o.key===a)==null&&s.push(a)}),s.length>0)throw new Fe(`Could not find channels: ${JSON.stringify(s)}`);return n},RT="sy_channel_set",_T="sy_channel_delete";class Pr{_frameClient;key;name;dataType;leaseholder;index;isIndex;internal;alias;virtual;expression;requires;status;constructor({dataType:e,name:r,leaseholder:n=0,key:s=0,isIndex:a=!1,index:o=0,internal:c=!1,virtual:l=!1,frameClient:u,alias:h,status:d,expression:f="",requires:v=[]}){this.key=D.parse(s),this.name=r,this.dataType=new R(e),this.leaseholder=n,this.index=D.parse(o),this.isIndex=a,this.internal=c,this.alias=h,this.virtual=l,this.expression=f,this.requires=D.array().parse(v??[]),d!=null&&(this.status=It.create(d)),this._frameClient=u??null}get framer(){if(this._frameClient==null)throw new Y("cannot read from a channel that has not been created");return this._frameClient}get payload(){return xt.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 Xt(this.payload)}get ontologyID(){return ru(this.key)}async read(e){return await this.framer.read(e,this.key)}async write(e,r){return await this.framer.write(e,this.key,r)}}const jT="sy_calculation_status",MT="/channel/retrieve-group",DT=i.z.object({}),PT=i.z.object({group:Gr});let eu=class{frameClient;client;retriever;writer;constructor(e,r,n,s){this.frameClient=e,this.retriever=r,this.client=n,this.writer=s}async create(e,r={}){const{retrieveIfNameExists:n=!1}=r,s=!Array.isArray(e);let a=T.toArray(e),o=[];if(n){const c=await this.retriever.retrieve(a.map(u=>u.name)),l=new Set(c.map(u=>u.name));a=a.filter(u=>!l.has(u.name)),o=this.sugar(c)}return o=o.concat(this.sugar(await this.writer.create(a))),s?o[0]:o}async retrieve(e,r){if(typeof e=="object"&&!Array.isArray(e))return this.sugar(await this.retriever.retrieve(e));const n=!Array.isArray(e),s=this.sugar(await this.retriever.retrieve(e,r));return ce("channel",e,s,n),n?s[0]:s}async delete(e){const{normalized:r,variant:n}=ge(e);return n==="keys"?await this.writer.delete({keys:r}):await this.writer.delete({names:r})}async rename(e,r){return await this.writer.rename(T.toArray(e),T.toArray(r))}createDebouncedBatchRetriever(e=10){return new Vs(new Xc(new lr(this.client),e))}sugar(e){const{frameClient:r}=this;return Array.isArray(e)?e.map(n=>new Pr({...n,frameClient:r})):new Pr({...e,frameClient:r})}async retrieveGroup(){return(await w(this.client,MT,{},DT,PT)).group}};const Xt=({virtual:t,expression:e})=>t&&e!=="",tu=async(t,e)=>{if(!Xt(e))return e.index;for(const r of e.requires){const n=await t(r);if(n==null)return null;if(!n.virtual)return n.index}for(const r of e.requires){const n=await t(r);if(n==null)return null;if(Xt(n)){const s=await tu(t,n);if(s!=null)return s}}return null},ru=t=>({type:"channel",key:t.toString()}),UT=i.z.object({channels:Jc.array()}),LT=i.z.object({channels:xt.array()}),BT=i.z.object({keys:D.array().optional(),names:xe.array().optional()}),qT=i.z.object({}),FT=i.z.object({keys:D.array(),names:xe.array()}),VT=i.z.object({}),YT="/channel/create",WT="/channel/delete",HT="/channel/rename";let nu=class{client;cache;constructor(e,r){this.client=e,this.cache=r}async create(e){const{channels:r}=await w(this.client,YT,{channels:e.map(n=>({...n,dataType:n.dataType}))},UT,LT);return this.cache.set(r),r}async delete(e){const r=D.array().parse(e.keys??[]);await w(this.client,WT,e,BT,qT),r.length>0&&this.cache.delete(r),e.names!=null&&this.cache.delete(e.names)}async rename(e,r){await w(this.client,HT,{keys:e,names:r},FT,VT),this.cache.rename(e,r)}};const GT=Object.freeze(Object.defineProperty({__proto__:null,CALCULATION_STATUS_CHANNEL_NAME:jT,CacheRetriever:Vs,Channel:Pr,Client:eu,ClusterRetriever:lr,DELETE_CHANNEL_NAME:_T,DebouncedBatchRetriever:Xc,SET_CHANNEL_NAME:RT,Writer:nu,analyzeParams:ge,isCalculated:Xt,keyZ:D,nameZ:xe,newZ:Jc,ontologyID:ru,paramsZ:it,payloadZ:xt,resolveCalculatedIndex:tu,retrieveRequired:Qc,statusZ:Gc},Symbol.toStringTag,{value:"Module"})),We=i.z.uuid(),hr=i.z.object({key:We,username:i.z.string().min(1,"Username is required"),firstName:i.z.string().default(""),lastName:i.z.string().default(""),rootUser:i.z.boolean().default(!0)}),su=hr.partial({key:!0,firstName:!0,lastName:!0}).omit({rootUser:!0}).extend({password:i.z.string().min(1)}),JT=i.z.object({keys:We.array().optional(),usernames:i.z.string().array().optional()}),KT=i.z.object({key:We}).transform(({key:t})=>({keys:[t]})),XT=i.z.object({username:i.z.string()}).transform(({username:t})=>({usernames:[t]})),QT=i.z.object({usernames:i.z.string().array()}).transform(({usernames:t})=>({usernames:t})),ez=i.z.union([KT,XT,QT,JT]),tz=i.z.object({users:T.nullableZ(hr)}),rz=i.z.object({users:su.array()}),nz=i.z.object({users:hr.array()}),sz=i.z.object({key:We,username:i.z.string().min(1)}),iz=i.z.object({}),az=i.z.object({key:We,firstName:i.z.string().optional(),lastName:i.z.string().optional()}),oz=i.z.object({}),cz=i.z.object({keys:We.array()}),uz=i.z.object({}),lz="/user/retrieve",hz="/user/create",fz="/user/change-username",dz="/user/rename",pz="/user/delete";let iu=class{client;constructor(e){this.client=e}async create(e){const r=Array.isArray(e),n=await w(this.client,hz,{users:T.toArray(e)},rz,nz);return r?n.users:n.users[0]}async changeUsername(e,r){await w(this.client,fz,{key:e,username:r},sz,iz)}async retrieve(e){const r="key"in e||"username"in e,n=await w(this.client,lz,e,ez,tz);if(!r)return n.users;if(n.users.length===0){const s="key"in e?`key ${e.key}`:`username ${e.username}`;throw new Ht(`No user with ${s} found`)}if(n.users.length>1){const s="key"in e?`key ${e.key}`:`username ${e.username}`;throw new Gt(`Multiple users found with ${s}`)}return n.users[0]}async rename(e,r,n){await w(this.client,dz,{key:e,firstName:r,lastName:n},az,oz)}async delete(e){await w(this.client,pz,{keys:T.toArray(e)},cz,uz)}};const yz=t=>({type:"user",key:t}),mz=Object.freeze(Object.defineProperty({__proto__:null,Client:iu,keyZ:We,newZ:su,ontologyID:yz,userZ:hr},Symbol.toStringTag,{value:"Module"})),gz=i.z.object({username:i.z.string(),password:i.z.string()}),wz=i.z.object({token:i.z.string(),user:hr}),Ki="/auth/login",bz=3,vz="/auth/change-password",Tz=i.z.object({username:i.z.string(),password:i.z.string(),newPassword:i.z.string().min(1)}),zz=i.z.object({}),Ez=[rs,ns];let Nz=class{token;client;credentials;authenticating;authenticated;user;retryCount;constructor(e,r){this.client=e,this.authenticated=!1,this.credentials=r,this.retryCount=0}async changePassword(e){if(!this.authenticated)throw new Error("Not authenticated");await w(this.client,vz,{username:this.credentials.username,password:this.credentials.password,newPassword:e},Tz,zz),this.credentials.password=e}middleware(){const e=async(r,n)=>{if(!this.authenticated&&!r.target.endsWith(Ki)){this.authenticating??=new Promise((c,l)=>{this.client.send(Ki,this.credentials,gz,wz).then(([u,h])=>{if(h!=null)return c(h);this.token=u?.token,this.user=u?.user,this.authenticated=!0,c(null)}).catch(l)});const o=await this.authenticating;if(o!=null)return[r,o]}r.params.Authorization=`Bearer ${this.token}`;const[s,a]=await n(r);return Ez.some(o=>o.matches(a))&&this.retryCount<bz?(this.authenticated=!1,this.authenticating=void 0,this.retryCount+=1,e(r,n)):(this.retryCount=0,[s,a])};return e}};const au=i.z.enum(["disconnected","connecting","connected","failed"]),ou=i.z.object({status:au,error:i.z.instanceof(Error).optional(),message:i.z.string().optional(),clusterKey:i.z.string(),clientVersion:i.z.string(),clientServerCompatible:i.z.boolean(),nodeVersion:i.z.string().optional()}),Oz=i.z.object({clusterKey:i.z.string(),nodeVersion:i.z.string().optional()}),Xi={clusterKey:"",status:"disconnected",error:void 0,message:"Disconnected",clientServerCompatible:!1,clientVersion:"0.46.0"},Qi=(t,e,r)=>{const n=r?"cluster":"client";return`Synnax cluster node version ${t!=null?`${t} `:""}is too ${r?"old":"new"} for client version ${e}.
|
|
22
41
|
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 ${
|
|
42
|
+
https://docs.synnaxlabs.com/reference/typescript-client/troubleshooting#old-${n}-version`};class Qt{static ENDPOINT="/connectivity/check";static DEFAULT=Xi;_state;pollFrequency=I.seconds(30);client;name;interval;clientVersion;onChangeHandlers=[];static connectionStateZ=ou;versionWarned=!1;constructor(e,r=I.seconds(30),n,s){this._state={...Xi},this.client=e,this.pollFrequency=r,this.clientVersion=n,this.name=s,this.check(),this.startChecking()}stopChecking(){this.interval!=null&&clearInterval(this.interval)}async check(){const e=this._state.status;try{const[r,n]=await this.client.send(Qt.ENDPOINT,{},i.z.object({}),Oz);if(n!=null)throw n;const s=r.nodeVersion,a=this.clientVersion,o=this.versionWarned;s==null?(this._state.clientServerCompatible=!1,o||(console.warn(Qi(null,a,!0)),this.versionWarned=!0)):Oi.versionsEqual(a,s,{checkMajor:!0,checkMinor:!0,checkPatch:!1})?this._state.clientServerCompatible=!0:(this._state.clientServerCompatible=!1,o||(console.warn(Qi(s,a,Oi.semVerNewer(a,s))),this.versionWarned=!0)),this._state.status="connected",this._state.message=`Connected to ${this.name??"cluster"}`,this._state.clusterKey=r.clusterKey,this._state.nodeVersion=r.nodeVersion,this._state.clientVersion=this.clientVersion}catch(r){this._state.status="failed",this._state.error=r,this._state.message=this.state.error?.message}return this.onChangeHandlers.length>0&&e!==this._state.status&&this.onChangeHandlers.forEach(r=>r(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 $z=Object.freeze(Object.defineProperty({__proto__:null,Checker:Qt,stateZ:ou,statusZ:au},Symbol.toStringTag,{value:"Module"})),Sz=i.z.object({keys:D.array().optional(),bounds:P.z,names:xe.array().optional()}),Iz=i.z.object({}),kz="/frame/delete";class Az{client;constructor(e){this.client=e}async delete(e){await w(this.client,kz,e,Sz,Iz)}}const ea=t=>{const e=T.toArray(t);return e.length===0?null:typeof e[0]=="number"||!isNaN(parseInt(e[0]))?"key":"name"},ta=(t,e)=>{const r=T.toArray(t);if(r.length===e.length)return;const n=ea(t);throw ea===null?new Y("[Frame] - channel keys or names must be provided when constructing a frame."):new Y(`[Frame] - ${n}s and series must be the same length.
|
|
43
|
+
Got ${r.length} ${n}s and ${e.length} series.`)};class W{columns=[];series=[];constructor(e=[],r=[]){if(e instanceof W){this.columns=e.columns,this.series=e.series;return}if(e instanceof Map){e.forEach((s,a)=>this.push(a,...T.toArray(s)));return}if(typeof e=="object"&&!Array.isArray(e)){if("keys"in e&&"series"in e){const s=e;s.series??=[],s.keys??=[];const a=s.series.map(o=>cu(o));ta(s.keys,a),s.keys.forEach((o,c)=>this.push(o,a[c]))}else Object.entries(e).forEach(([s,a])=>{const o=parseInt(s);if(!isNaN(o))return this.push(o,...T.toArray(a));this.push(s,...T.toArray(a))});return}if(Array.isArray(e)||["string","number"].includes(typeof e)){const s=T.toArray(r),a=T.toArray(e);ta(a,s),s.forEach((o,c)=>this.push(a[c],o));return}throw new Y(`[Frame] - invalid frame construction parameters. data parameter ust be a frame
|
|
25
44
|
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
|
|
27
|
-
`;return this.uniqueColumns.forEach(
|
|
28
|
-
`}),e+="}",e}}const
|
|
45
|
+
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 gt("colType is not key");return this.columns??[]}get uniqueKeys(){return gi.unique(this.keys)}get names(){if(this.colType==="key")throw new gt("colType is not name");return this.columns??[]}get uniqueNames(){return gi.unique(this.names)}get uniqueColumns(){return this.colType==="key"?this.uniqueKeys:this.uniqueNames}toPayload(){return{series:this.series.map(e=>uu(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(r=>r.equals(e[0]))}timeRange(e){if(e==null){if(this.columns.length===0)return P.ZERO;const n=p.min(...this.series.map(a=>a.timeRange.start)),s=p.max(...this.series.map(a=>a.timeRange.end));return new P(n,s)}const r=this.get(e);return r==null?P.ZERO:r.timeRange}latest(){return this.at(-1)}get timeRanges(){return this.uniqueColumns.map(e=>this.timeRange(e))}get(e){return Array.isArray(e)?this.filter(r=>e.includes(r)):new _o(this.series.filter((r,n)=>this.columns[n]===e))}push(e,...r){if(e instanceof W){if(this.colType!==null&&e.colType!==this.colType)throw new Y("keyVariant must match");this.series.push(...e.series),this.columns.push(...e.columns)}else{if(this.series.push(...r),typeof e=="string"&&this.colType==="key")throw new Y("keyVariant must match");if(typeof e!="string"&&this.colType==="name")throw new Y("keyVariant must match");this.columns.push(...Array.from({length:r.length},()=>e))}}concat(e){return new W([...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 r=new W;return this.forEach((n,s,a)=>r.push(...e(n,s,a))),r}forEach(e){this.columns.forEach((r,n)=>{const s=this.series[n];e(r,s,n)})}at(e,r=!1){const n={};return this.uniqueColumns.forEach(s=>{n[s]=this.get(s).at(e,r)}),n}filter(e){const r=new W;return this.columns.forEach((n,s)=>{const a=this.series[s];e(n,a,s)&&r.push(n,a)}),r}get byteLength(){return new vt(this.series.reduce((e,r)=>e.add(r.byteLength),vt.ZERO))}get digest(){const e={};return this.keys.forEach((r,n)=>{const s=this.series[n].digest;r in e?e[r].push(s):e[r]=[s]}),e}get length(){return this.series.reduce((e,r)=>e+r.length,0)}toString(){let e=`Frame{
|
|
46
|
+
`;return this.uniqueColumns.forEach(r=>{e+=` ${r}: ${this.get(r).series.map(n=>n.toString()).join(",")}
|
|
47
|
+
`}),e+="}",e}}const sn=i.z.object({keys:i.z.union([i.z.null().transform(()=>[]),i.z.number().array().optional().default([])]),series:i.z.union([i.z.null().transform(()=>[]),Ae.crudeZ.array().optional().default([])])}),cu=t=>{const{dataType:e,data:r,timeRange:n,alignment:s}=t;return new Ae({data:r,dataType:e,timeRange:n,glBufferUsage:"static",alignment:s})},uu=t=>({timeRange:t.timeRange,dataType:t.dataType,data:new Uint8Array(t.data.buffer),alignment:t.alignment});var zt=(t=>(t[t.Open=0]="Open",t[t.Write=1]="Write",t[t.Commit=2]="Commit",t[t.SetAuthority=3]="SetAuthority",t))(zt||{}),er=(t=>(t[t.PersistStream=1]="PersistStream",t[t.Persist=2]="Persist",t[t.Stream=3]="Stream",t))(er||{});const xz=new I(-1);class ls extends Se.sub("writer_closed"){constructor(){super("WriterClosed")}}const Zz=i.z.enum(er).or(i.z.enum(["persist","stream","persistStream"]).transform(t=>{switch(t){case"persist":return 2;case"stream":return 3;case"persistStream":return 1}})),lu=i.z.object({start:p.z.optional(),controlSubject:fe.subjectZ.optional(),authorities:i.z.union([fe.authorityZ.transform(t=>[t]),fe.authorityZ.array()]).default([fe.ABSOLUTE_AUTHORITY]),mode:Zz.default(1),errOnUnauthorized:i.z.boolean().default(!1),enableAutoCommit:i.z.boolean().default(!1),autoIndexPersistInterval:I.z.default(I.SECOND),useHighPerformanceCodec:i.z.boolean().default(!0)}),Cz=lu.extend({keys:D.array().optional()}),ra=lu.extend({channels:it}),hu=ra.or(it.transform(t=>ra.parse({channels:t,start:p.now()}))),Rz=i.z.object({command:i.z.enum(zt),config:Cz.optional(),frame:sn.optional(),buffer:i.z.instanceof(Uint8Array).optional()}),_z=i.z.object({command:i.z.enum(zt),end:p.z,err:Ze.payloadZ.optional()}),jz=i.z.tuple([i.z.union([i.z.record(D.or(xe),fe.authorityZ),D.or(xe),fe.authorityZ]),fe.authorityZ.optional()]).transform(([t,e])=>{if(fe.authorityZ.safeParse(t).success)return{keys:[],authorities:[t]};if(D.or(xe).safeParse(t).success){if(e==null)throw new Error("authority is required when setting authority for a single channel");return{keys:[t],authorities:[e]}}const r=t;return{keys:Object.keys(r),authorities:Object.values(r)}});let fu=class hs{static ENDPOINT="/frame/write";stream;adapter;closeErr=null;constructor(e,r){this.stream=e,this.adapter=r}static async _open(e,r,n){const s=hu.parse(n),a=await Ws.open(e,s.channels);s.useHighPerformanceCodec&&(r=r.withCodec(new Bz(a.codec)));const o=await r.stream(hs.ENDPOINT,Rz,_z),c=new hs(o,a);return await c.execute({command:0,config:{...s,keys:a.keys}}),c}async write(e,r){if(this.closeErr!=null)throw this.closeErr;if(this.stream.received())return await this.close();const n=await this.adapter.adapt(e,r);this.stream.send({command:1,frame:n.toPayload()})}async setAuthority(e,r){if(this.closeErr!=null)throw this.closeErr;const n=jz.parse([e,r]),s={keys:await this.adapter.adaptParams(n.keys),authorities:n.authorities};await this.execute({command:3,config:s})}async commit(){if(this.closeErr!=null)throw this.closeErr;return this.stream.received()?(await this.closeInternal(null),p.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(ls.matches(this.closeErr))return null;throw this.closeErr}const[r,n]=await this.stream.receive();n!=null?this.closeErr=we.matches(n)?new ls:n:this.closeErr=Ze.decode(r?.err)}}async execute(e){const r=this.stream.send(e);for(r!=null&&await this.closeInternal(r);;){const[n,s]=await this.stream.receive();s!=null&&await this.closeInternal(s);const a=Ze.decode(n?.err);if(a!=null&&await this.closeInternal(a),n?.command==e.command)return n}}};const na=t=>t.data.byteLength/t.dataType.density.valueOf(),Mz=t=>{const{keys:e,series:r}=t;e.forEach((n,s)=>{r[s].key=n}),r.sort((n,s)=>n.key-s.key),e.sort((n,s)=>n-s),r.forEach(n=>delete n.key)},sa=5,ia=4,aa=3,oa=2,ca=1,ua=0,Te=R.TIMESTAMP.density.valueOf(),je=8,Me=4,In=4,kn=4,Dz=1;class du{contentType="application/sy-framer";states=new Map;currState;seqNum=0;constructor(e=[],r=[]){(e.length>0||r.length>0)&&this.update(e,r)}update(e,r){this.seqNum++;const n={keys:e,keyDataTypes:new Map,hasVariableDataTypes:!1};e.forEach((s,a)=>{const o=r[a];n.keyDataTypes.set(s,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 Y(`
|
|
29
48
|
The codec has not been updated with a list of channels and data types.
|
|
30
49
|
Please call the update method before calling ${e}.
|
|
31
|
-
`)}encode(e,
|
|
50
|
+
`)}encode(e,r=0){this.throwIfNotUpdated("encode");let n=e;e!=null&&typeof e=="object"&&"toPayload"in e&&(n=e.toPayload()),Mz(n);let s=-1,a,o,c,l=r+Dz+kn,u=!this.currState?.hasVariableDataTypes,h=!0,d=!0,f=!0,v=!0,S=!0;n.keys.length!==this.currState?.keys.length&&(f=!1,l+=n.keys.length*In),n.series.forEach((k,G)=>{const V=na(k),ye=n.keys[G],Je=this.currState?.keyDataTypes.get(ye);if(Je==null)throw new Y(`Channel ${ye} was not provided in the list of channels when opening the writer`);if(!Je.equals(k.dataType))throw new Y(`Series data type of ${k.dataType.toString()} does not match the data type of ${Je.toString()} for channel ${ye}`);if(l+=k.data.byteLength,s===-1){s=V,a=k.timeRange?.start,o=k.timeRange?.end,c=BigInt(k.alignment??0n);return}s!==V&&(u=!1),(a?.valueOf()!==k.timeRange?.start.valueOf()||o?.valueOf()!==k.timeRange?.end.valueOf())&&(h=!1),c!==BigInt(k.alignment??0)&&(v=!1)}),d=h&&a==null&&o==null,S=v&&(c===void 0||c===0n),u?l+=Me:l+=n.keys.length*Me,d||(h?l+=Te*2:l+=n.keys.length*Te*2),S||(v?l+=je:l+=n.keys.length*je);const Z=new Uint8Array(l),b=new DataView(Z.buffer);let z=r;return Z[z]=Number(S)<<sa|Number(v)<<ia|Number(u)<<aa|Number(h)<<oa|Number(d)<<ca|Number(f)<<ua,z++,b.setUint32(z,this.seqNum,!0),z+=kn,u&&(b.setUint32(z,s,!0),z+=Me),h&&!d&&(b.setBigUint64(z,a?.valueOf()??0n,!0),b.setBigUint64(z,o?.valueOf()??0n,!0),z+=Te*2),v&&!S&&(b.setBigUint64(z,c??0n,!0),z+=je),n.series.forEach((k,G)=>{if(f||(b.setUint32(z,n.keys[G],!0),z+=In),!u){let V=k.data.byteLength;k.dataType.isVariable||(V=na(k)),b.setUint32(z,V,!0),z+=Me}Z.set(new Uint8Array(k.data),z),z+=k.data.byteLength,!h&&!d&&(b.setBigUint64(z,k.timeRange?.start.valueOf()??0n,!0),b.setBigUint64(z,k.timeRange?.end.valueOf()??0n,!0),z+=Te*2),!v&&!S&&(b.setBigUint64(z,k.alignment??0n,!0),z+=je)}),Z}decode(e,r=0){this.throwIfNotUpdated("decode");const n=e instanceof Uint8Array?e:new Uint8Array(e),s={keys:[],series:[]};let a=r,o=0,c=0,l,u,h;const d=new DataView(n.buffer,n.byteOffset,n.byteLength),f=!!(n[a]>>sa&1),v=!!(n[a]>>ia&1),S=!!(n[a]>>aa&1),Z=!!(n[a]>>oa&1),b=!!(n[a]>>ca&1),z=!!(n[a]>>ua&1);a++;const k=d.getUint32(a,!0);a+=kn;const G=this.states.get(k);if(G==null)return s;if(S){if(a+Me>d.byteLength)return s;o=d.getUint32(a,!0),a+=Me}if(Z&&!b){if(a+Te>d.byteLength)return s;l=new p(d.getBigUint64(a,!0)),a+=Te,u=new p(d.getBigUint64(a,!0)),a+=Te}if(v&&!f){if(a+je>d.byteLength)return s;h=d.getBigUint64(a,!0),a+=je}return z&&(s.keys=[...G.keys]),G.keys.forEach((V,ye)=>{if(!z){if(a>=d.byteLength||d.getUint32(a,!0)!==V)return;a+=In,s.keys.push(V)}const Je=G.keyDataTypes.get(V);if(c=0,S)c=o;else{if(a+Me>d.byteLength)return;c=d.getUint32(a,!0),a+=Me}let yr=c;if(Je.isVariable||(yr*=Je.density.valueOf()),a+yr>d.byteLength){s.keys.splice(ye,1);return}const Ke={dataType:Je,data:n.slice(a,a+yr).buffer};if(a+=yr,!Z&&!b){if(a+Te*2>d.byteLength)return;const si=d.getBigUint64(a,!0);a+=Te;const kl=d.getBigUint64(a,!0);a+=Te,Ke.timeRange=new P({start:si,end:kl})}else b?Ke.timeRange=new P({start:0n,end:0n}):Ke.timeRange=new P({start:l?.valueOf()??0n,end:u?.valueOf()??0n});if(!v&&!f){if(a+je>d.byteLength)return;h=d.getBigUint64(a,!0),a+=je,Ke.alignment=h}else f?Ke.alignment=0n:Ke.alignment=h;s.series.push(Ke)}),s}}const Ys=254,Pz=new Uint8Array([Ys]),Uz=255,Lz=new Uint8Array([Uz]),pu="application/sy-framer";class Bz{contentType=pu;base;lowPerfCodec;constructor(e){this.base=e,this.lowPerfCodec=st.JSON_CODEC}encode(e){const r=e;if(r.type=="close"||r.payload?.command!=zt.Write){const s=this.lowPerfCodec.encode(r),a=new Uint8Array({length:s.byteLength+1});return a.set(Pz,0),a.set(new Uint8Array(s),1),a}const n=this.base.encode(r.payload?.frame,1);return n.set(Lz,0),n}decode(e,r){if(new DataView(e instanceof Uint8Array?e.buffer:e).getUint8(0)===Ys)return this.lowPerfCodec.decode(e.slice(1),r);const a={type:"data"},o=this.base.decode(e,1);return a.payload={command:zt.Write,frame:o},a}}class qz{contentType=pu;base;lowPerfCodec;constructor(e){this.base=e,this.lowPerfCodec=st.JSON_CODEC}encode(e){return this.lowPerfCodec.encode(e)}decode(e,r){return new DataView(e instanceof Uint8Array?e.buffer:e).getUint8(0)===Ys?this.lowPerfCodec.decode(e.slice(1),r):{type:"data",payload:{frame:this.base.decode(e,1)}}}}class an{adapter;retriever;keys;codec;constructor(e){this.retriever=e,this.adapter=null,this.keys=[],this.codec=new du}static async open(e,r){const n=new an(e);return await n.update(r),n}async update(e){const{variant:r,normalized:n}=ge(e),s=await this.retriever.retrieve(n),a=s.map(c=>c.key);if(wi.uniqueUnorderedPrimitiveArrays(this.keys,a)===wi.EQUAL)return!1;if(this.codec.update(a,s.map(c=>c.dataType)),r==="keys")return this.adapter=null,this.keys=n,!0;const o=new Map;return this.adapter=o,n.forEach(c=>{const l=s.find(u=>u.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 r=this.adapter;return e.map((n,s)=>{if(typeof n=="number"){const a=r.get(n);if(a==null)throw new Error(`Channel ${n} not found`);return[a,s]}return[n,s]})}}class Ws{adapter;retriever;keys;codec;constructor(e){this.retriever=e,this.adapter=null,this.keys=[],this.codec=new du}static async open(e,r){const n=new Ws(e);return await n.update(r),n}async adaptParams(e){const r=it.parse(e);return await Promise.all(r.map(async s=>await this.adaptToKey(s)))}async update(e){const r=await Qc(this.retriever,e),n=r.map(u=>u.key),s=new Set(this.keys),a=new Set(n),o=!a.isSubsetOf(s),c=!s.isSubsetOf(a);return o||c?(this.adapter=new Map(r.map(u=>[u.name,u.key])),this.keys=n,this.codec.update(this.keys,r.map(u=>u.dataType)),!0):!1}async fetchChannel(e){const r=await this.retriever.retrieve(e);if(r.length===0)throw new Error(`Channel ${JSON.stringify(e)} not found`);return r[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,r){if(typeof e=="string"||typeof e=="number"){if(r==null)throw new Y(`
|
|
32
51
|
Received a single channel name or key but no series.
|
|
33
|
-
`);if(Array.isArray(
|
|
52
|
+
`);if(Array.isArray(r)){if(r.some(l=>l instanceof Ae||Array.isArray(l)))throw new Y(`
|
|
34
53
|
Received a single channel name or key but multiple series.
|
|
35
|
-
`);
|
|
54
|
+
`);r=r}const o=await this.fetchChannel(e),c=new Ae({data:r,dataType:o.dataType});return new W(o.key,c)}if(Array.isArray(e)){if(r==null)throw new Y(`
|
|
36
55
|
Received an array of channel names or keys but no series.
|
|
37
|
-
`);if(!Array.isArray(
|
|
56
|
+
`);if(!Array.isArray(r))throw new Y(`
|
|
38
57
|
Received an array of channel names or keys but no array of series.
|
|
39
|
-
`);const o=[],c=[];for(let
|
|
58
|
+
`);const o=[],c=[];for(let l=0;l<e.length;l++){const u=await this.fetchChannel(e[l]);if(l>=r.length)throw new Y(`
|
|
40
59
|
Received an array of channel names or keys but not enough series.
|
|
41
|
-
`);const h=new
|
|
42
|
-
Channel ${
|
|
43
|
-
`);return
|
|
44
|
-
Please report this error to the Synnax team.`),t!=null){if(ie.matches(t))return;throw t}}}closeSend(){this.stream.closeSend()}send(e){const t=this.stream.send(e);if(t!=null)throw t}}const lr=new E(-1);var Hn=(r=>(r[r.Open=0]="Open",r[r.Next=1]="Next",r[r.Prev=2]="Prev",r[r.SeekFirst=3]="SeekFirst",r[r.SeekLast=4]="SeekLast",r[r.SeekLE=5]="SeekLE",r[r.SeekGE=6]="SeekGE",r[r.Valid=7]="Valid",r[r.Error=8]="Error",r))(Hn||{}),io=(r=>(r[r.None=0]="None",r[r.Ack=1]="Ack",r[r.Data=2]="Data",r))(io||{});const Og=s.z.object({command:s.z.enum(Hn),span:E.z.optional(),bounds:M.z.optional(),stamp:f.z.optional(),keys:j.array().optional(),chunkSize:s.z.number().optional()}),zg=s.z.object({variant:s.z.enum(io),ack:s.z.boolean(),command:s.z.enum(Hn),error:me.payloadZ.optional().nullable(),frame:Nr.optional()});class Ct{static ENDPOINT="/frame/iterate";stream;adapter;value;constructor(e,t){this.stream=new so("Iterator",e),this.value=new P,this.adapter=t}static async _open(e,t,n,i,a={}){const o=await Or.open(n,t),c=await i.stream(Ct.ENDPOINT,Og,zg),u=new Ct(c,o);return await u.execute({command:0,keys:o.keys,bounds:new M(e),chunkSize:a.chunkSize??1e5}),u}async next(e=lr){return await this.execute({command:1,span:new E(e)})}async prev(e=lr){return await this.execute({command:2,span:new E(e)})}async seekFirst(){return await this.execute({command:3})}async seekLast(){return await this.execute({command:4})}async seekLE(e){return await this.execute({command:5,stamp:new f(e)})}async seekGE(e){return await this.execute({command:6,stamp:new f(e)})}async valid(){return await this.execute({command:7})}async close(){await this.stream.closeAndAck()}[Symbol.asyncIterator](){return new Sg(this)}async execute(e){for(this.stream.send(e),this.value=new P;;){const t=await this.stream.receive();if(t.variant===1)return t.ack;this.value.push(this.adapter.adapt(new P(t.frame)))}}}class Sg{iter;open=!1;constructor(e){this.iter=e}async next(){try{let e=!0;return this.open||(await this.iter.seekFirst()||(e=!1),this.open=!0),await this.iter.next()||(e=!1),e||await this.iter.close(),{done:!e,value:this.iter.value}}catch(e){throw await this.iter.close(),e}}}const Ag=s.z.object({keys:s.z.number().array(),downsampleFactor:s.z.number()}),$g=s.z.object({frame:Nr}),Ig="/frame/stream",Ps=s.z.object({channels:qe,downsampleFactor:s.z.number().optional().default(1),useHighPerformanceCodec:s.z.boolean().optional().default(!0)}),_n=Ps.or(qe.transform(r=>Ps.parse({channels:r}))),ao=(r,e)=>async t=>{const n=_n.parse(t),i=await Or.open(r,n.channels);n.useHighPerformanceCodec&&(e=e.withCodec(new Ng(i.codec)));const a=await e.stream(Ig,Ag,$g),o=new kg(a,i);a.send({keys:i.keys,downsampleFactor:n.downsampleFactor??1});const[,c]=await a.receive();if(c!=null)throw c;return o},oo=async(r,e,t)=>await ao(r,e)(t);class kg{stream;adapter;downsampleFactor;constructor(e,t){this.stream=new so("Streamer",e),this.adapter=t,this.downsampleFactor=1}get keys(){return this.adapter.keys}async next(){try{return{done:!1,value:await this.read()}}catch(e){if(ie.matches(e))return{done:!0,value:void 0};throw e}}async read(){return this.adapter.adapt(new P((await this.stream.receive()).frame))}async update(e){await this.adapter.update(e)&&this.stream.send({keys:this.adapter.keys,downsampleFactor:this.downsampleFactor})}close(){this.stream.closeSend()}[Symbol.asyncIterator](){return this}}class zr{wrapped_=null;breaker;opener;config;constructor(e,t,n={}){this.opener=e,this.config=_n.parse(t);const{maxRetries:i=5e3,baseInterval:a=E.seconds(1),scale:o=1}=n??{};this.breaker=new ca.Breaker({maxRetries:i,baseInterval:a,scale:o})}static async open(e,t,n){const i=new zr(e,t,n);return await i.runStreamer(),i}async runStreamer(){for(;;)try{this.wrapped_!=null&&this.wrapped_.close(),this.wrapped_=await this.opener(this.config),this.breaker.reset();return}catch(e){if(this.wrapped_=null,!await this.breaker.wait())throw e;console.error("failed to open streamer",e);continue}}get wrapped(){if(this.wrapped_==null)throw new Error("stream closed");return this.wrapped_}async update(e){this.config.channels=qe.parse(e);try{await this.wrapped.update(e)}catch{return await this.runStreamer(),await this.update(e)}}async next(){try{return{done:!1,value:await this.read()}}catch(e){if(ie.matches(e))return{done:!0,value:void 0};throw e}}async read(){try{const e=await this.wrapped.read();return this.breaker.reset(),e}catch(e){if(ie.matches(e))throw e;return await this.runStreamer(),await this.read()}}close(){this.wrapped.close()}get keys(){return this.wrapped.keys}[Symbol.asyncIterator](){return this}}class co extends rf.Observer{streamer;closePromise;constructor(e,t){super(t),this.streamer=e,this.closePromise=this.stream()}async update(e){await this.streamer.update(e)}async close(){this.streamer.close(),await this.closePromise}async stream(){for await(const e of this.streamer)this.notify(e)}}const xg=r=>({type:"framer",key:r.toString()});let lo=class{streamClient;retriever;deleter;constructor(e,t,n){this.streamClient=e,this.retriever=n,this.deleter=new ug(t)}async openIterator(e,t,n){return await Ct._open(e,t,this.retriever,this.streamClient,n)}async openWriter(e){return await to._open(this.retriever,this.streamClient,e)}async openStreamer(e){return await oo(this.retriever,this.streamClient,e)}async write(e,t,n){if(n==null){const a=t,o=await this.openWriter({start:e,channels:Object.keys(a),mode:xt.Persist,errOnUnauthorized:!0,enableAutoCommit:!0,autoIndexPersistInterval:E.MAX});return await o.write(a),await o.close()}const i=await this.openWriter({start:e,channels:t,mode:xt.Persist,errOnUnauthorized:!0,enableAutoCommit:!0,autoIndexPersistInterval:E.MAX});await i.write(t,n),await i.close()}async read(e,t){const{single:n}=se(t),i=await this.readFrame(e,t);return n?i.get(t):i}async readFrame(e,t){const n=await this.openIterator(e,t),i=new P;try{for await(const a of n)i.push(a)}finally{await n.close()}return i}async readLatest(e,t=1){const{single:n}=se(e),i=await this.readLatestNFrame(e,t);return n?i.get(e):i}async readLatestNFrame(e,t){const n=await this.openIterator(M.MAX,e,{chunkSize:t}),i=new P;if(t>0)try{await n.seekLast(),await n.prev(lr),i.push(n.value)}finally{await n.close()}return i}async delete(e,t){const{normalized:n,variant:i}=se(e);return i==="keys"?await this.deleter.delete({keys:n,bounds:t}):await this.deleter.delete({names:n,bounds:t})}};const Cg=Object.freeze(Object.defineProperty({__proto__:null,ALWAYS_INDEX_PERSIST_ON_AUTO_COMMIT:hg,AUTO_SPAN:lr,Client:lo,Frame:P,HardenedStreamer:zr,Iterator:Ct,ObservableStreamer:co,Writer:to,WriterClosedError:bn,WriterCommand:tt,WriterMode:xt,createStreamOpener:ao,frameZ:Nr,ontologyID:xg,openStreamer:oo,seriesFromPayload:Ja,seriesToPayload:Xa,streamerConfigZ:_n,writerConfigZ:eo},Symbol.toStringTag,{value:"Module"})),Rg=te.ABSOLUTE_AUTHORITY,jg=te.ZERO_AUTHORITY,Mg=te.stateZ(s.z.number()),Ug=r=>r.to==null?`${r.from?.resource} - ${r.from?.subject.name} -> released`:r.from==null?`${r.to.resource} - released -> ${r.to.subject.name} (${r.to.authority.toString()})`:`${r.to.resource} - ${r.from.subject.name} -> ${r.to.subject.name} (${r.to.authority.toString()})`,Dg=s.z.object({transfers:s.z.array(te.transferZ(j))});class uo extends co{states;codec;constructor(e){super(e,t=>{const n=this.codec.decode(t.series[0].buffer,Dg);return this.merge(n),[n.transfers,!0]}),this.states=new Map,this.codec=new Be.JSONCodec}subjects(){const e=new Map;return this.states.forEach(t=>e.set(t.subject.key,t.subject)),Array.from(e.values())}merge(e){e.transfers.forEach(t=>{t.from==null&&t.to==null&&console.warn("Invalid transfer: ",t),t.to==null?this.states.delete(t.from.resource):this.states.set(t.to.resource,t.to)})}}const ho="sy_node_1_control";let fo=class{framer;constructor(e){this.framer=e}async openStateTracker(){const e=await zr.open(async t=>await this.framer.openStreamer(t),ho);return new uo(e)}};const Zg=Object.freeze(Object.defineProperty({__proto__:null,ABSOLUTE_AUTHORITY:Rg,CONTROL_STATE_CHANNEL_NAME:ho,Client:fo,StateTracker:uo,ZERO_AUTHORITY:jg,stateZ:Mg,transferString:Ug},Symbol.toStringTag,{value:"Module"}));let yo=class{tasks;racks;devices;constructor(e,t,n){this.tasks=e,this.racks=t,this.devices=n}};const Pg=Object.freeze(Object.defineProperty({__proto__:null,Client:yo},Symbol.toStringTag,{value:"Module"})),fe=s.z.uint32(),go=Pt.statusZ(s.z.object({rack:fe})),Sr=s.z.object({key:fe,name:s.z.string(),status:bt.nullToUndefined(go)}),po=Sr.partial({key:!0}),mo=r=>r?Be.JSON_CODEC.decodeString(r,we.unknownZ):{},ot=s.z.string(),wo=Pt.statusZ(s.z.object({rack:fe,device:ot})),Ar=s.z.object({key:ot,rack:fe,name:s.z.string(),make:s.z.string(),model:s.z.string(),location:s.z.string(),configured:s.z.boolean().optional(),properties:we.unknownZ.or(s.z.string().transform(mo)),status:bt.nullToUndefined(wo)}),bo=Ar.extend({properties:s.z.unknown().transform(r=>Be.JSON_CODEC.encodeString(r))}),Lg="sy_device_set",Bg="sy_device_delete",qg="sy_device_status",Fg="/hardware/device/retrieve",Yg="/hardware/device/create",Vg="/hardware/device/delete",Hg=s.z.object({devices:bo.array()}),_g=s.z.object({devices:Ar.array()}),Wg=s.z.object({keys:ot.array()}),Gg=s.z.object({}),Kg=s.z.object({keys:ot.array().optional(),names:s.z.string().array().optional(),makes:s.z.string().array().optional(),models:s.z.string().array().optional(),locations:s.z.string().array().optional(),racks:fe.array().optional(),searchTerm:s.z.string().optional(),limit:s.z.number().optional(),offset:s.z.number().optional(),includeStatus:s.z.boolean().optional()}),Jg=s.z.object({devices:L(Ar)}),Xg=s.z.object({key:ot,includeStatus:s.z.boolean().optional()}).transform(({key:r,includeStatus:e})=>({keys:[r],includeStatus:e})),Qg=s.z.union([Xg,Kg]);let To=class{type="device";client;constructor(e){this.client=e}async retrieve(e){const t=typeof e=="object"&&"key"in e,n=await m(this.client,Fg,e,Qg,Jg);Fe("Device",e,n.devices,t);const i=n.devices;return t?i[0]:i}async create(e){const t=!Array.isArray(e),i=(await m(this.client,Yg,{devices:v.toArray(e)},Hg,_g)).devices;return t?i[0]:i}async delete(e){await m(this.client,Vg,{keys:v.toArray(e)},Wg,Gg)}};const ep=r=>({type:"device",key:r}),tp=Object.freeze(Object.defineProperty({__proto__:null,Client:To,DELETE_CHANNEL_NAME:Bg,SET_CHANNEL_NAME:Lg,STATUS_CHANNEL_NAME:qg,deviceZ:Ar,keyZ:ot,newZ:bo,ontologyID:ep,statusZ:wo},Symbol.toStringTag,{value:"Module"})),rp="/hardware/rack/retrieve",np="/hardware/rack/create",sp="/hardware/rack/delete",ip="sy_rack_status",ap="sy_rack_set",op="sy_rack_delete",cp=s.z.object({keys:fe.array().optional(),names:s.z.string().array().optional(),searchTerm:s.z.string().optional(),embedded:s.z.boolean().optional(),hostIsNode:s.z.boolean().optional(),limit:s.z.number().optional(),offset:s.z.number().optional(),includeStatus:s.z.boolean().optional()}),lp=s.z.object({racks:L(Sr)}),up=s.z.union([s.z.object({key:fe,includeStatus:s.z.boolean().optional()}).transform(({key:r,includeStatus:e})=>({keys:[r],includeStatus:e})),s.z.object({name:s.z.string(),includeStatus:s.z.boolean().optional()}).transform(({name:r,includeStatus:e})=>({names:[r],includeStatus:e}))]),hp=cp,fp=s.z.union([up,hp]),dp=s.z.object({racks:po.array()}),yp=s.z.object({racks:Sr.array()}),gp=s.z.object({keys:fe.array()}),pp=s.z.object({});let vo=class{type="rack";client;tasks;constructor(e,t){this.client=e,this.tasks=t}async delete(e){await m(this.client,sp,{keys:v.toArray(e)},gp,pp)}async create(e){const t=!Array.isArray(e),n=await m(this.client,np,{racks:v.toArray(e)},dp,yp),i=this.sugar(n.racks);return t?i[0]:i}async retrieve(e){const t="key"in e||"name"in e,n=await m(this.client,rp,e,fp,lp),i=this.sugar(n.racks);return Fe("Rack",e,i,t),t?i[0]:i}sugar(e){const t=!Array.isArray(e),n=v.toArray(e).map(({key:i,name:a,status:o})=>new Eo(i,a,this.tasks,o));return t?n[0]:n}};class Eo{key;name;status;tasks;constructor(e,t,n,i){this.key=e,this.name=t,this.tasks=n,this.status=i}async listTasks(){return await this.tasks.retrieve({rack:this.key})}async createTask(e,t){return e.key=((BigInt(this.key)<<32n)+(BigInt(e.key??0)&0xffffffffn)).toString(),await this.tasks.create(e,t)}async deleteTask(e){await this.tasks.delete([e])}get payload(){return{key:this.key,name:this.name,status:this.status}}}const mp=r=>({type:"rack",key:r.toString()}),wp=Object.freeze(Object.defineProperty({__proto__:null,Client:vo,DELETE_CHANNEL_NAME:op,Rack:Eo,SET_CHANNEL_NAME:ap,STATUS_CHANNEL_NAME:ip,keyZ:fe,newZ:po,ontologyID:mp,rackZ:Sr,statusZ:go},Symbol.toStringTag,{value:"Module"})),be=r=>r?JSON.parse(r):{},Te=s.z.union([s.z.string(),s.z.bigint().transform(r=>r.toString()),s.z.number().transform(r=>r.toString())]),No=r=>s.z.object({task:Te,running:s.z.boolean(),data:r}),Wn=r=>Pt.statusZ(No(r)),Ft=(r={typeSchema:s.z.string(),configSchema:s.z.unknown(),statusDataSchema:s.z.unknown()})=>s.z.object({key:Te,name:s.z.string(),type:r.typeSchema,internal:s.z.boolean().optional(),config:s.z.string().transform(mo).or(r.configSchema),status:Wn(r.statusDataSchema).optional().nullable(),snapshot:s.z.boolean().optional()}),Oo=r=>Ft(r).omit({key:!0}).extend({key:Te.transform(e=>e.toString()).optional(),config:s.z.unknown().transform(e=>Be.JSON_CODEC.encodeString(e))}),bp=s.z.object({task:Te,type:s.z.string(),key:s.z.string(),args:we.unknownZ.or(s.z.string().transform(be)).or(s.z.array(s.z.unknown())).or(s.z.null()).optional()}),Tp=r=>Number(BigInt(r)>>32n),vn="sy_task_status",En="sy_task_cmd",vp="sy_task_set",Ep="sy_task_delete",Ue=new Error("Task not created"),zo=async(r,e)=>{const t=await e.retrieveParents(Gn(r));return t.length===0?null:t[0]};class So{key;name;internal;type;snapshot;config;status;schemas;frameClient_;ontologyClient_;rangeClient_;get frameClient(){if(this.frameClient_==null)throw Ue;return this.frameClient_}get ontologyClient(){if(this.ontologyClient_==null)throw Ue;return this.ontologyClient_}get rangeClient(){if(this.rangeClient_==null)throw Ue;return this.rangeClient_}constructor({key:e,type:t,name:n,config:i,internal:a=!1,snapshot:o=!1,status:c},u,l,h,y){this.key=e,this.name=n,this.type=t,this.config=i,this.schemas=u??{typeSchema:s.z.string(),configSchema:s.z.unknown(),statusDataSchema:s.z.unknown()},this.internal=a,this.snapshot=o,this.status=c,this.frameClient_=l,this.ontologyClient_=h,this.rangeClient_=y}get payload(){return{key:this.key,name:this.name,type:this.type,config:this.config,status:this.status,internal:this.internal}}get ontologyID(){return Gn(this.key)}async executeCommand(e,t){return await $o(this.frameClient,this.key,e,t)}async executeCommandSync(e,t,n){return await Io(this.frameClient,this.key,e,t,this.name,this.schemas?.statusDataSchema,n)}async snapshottedTo(){if(this.ontologyClient==null||this.rangeClient==null)throw Ue;return this.snapshot?await zo(this.key,this.ontologyClient):null}}const Np=s.z.object({rack:fe.optional(),keys:Te.array().optional(),names:s.z.string().array().optional(),types:s.z.string().array().optional(),includeStatus:s.z.boolean().optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),Op=s.z.union([s.z.object({key:Te,includeStatus:s.z.boolean().optional()}).transform(({key:r,includeStatus:e})=>({keys:[r],includeStatus:e})),s.z.object({name:s.z.string(),includeStatus:s.z.boolean().optional()}).transform(({name:r,includeStatus:e})=>({names:[r],includeStatus:e}))]),zp=Np,Sp=s.z.union([Op,zp]),Ap=r=>s.z.object({tasks:L(Ft(r))}),$p="/hardware/task/retrieve",Ip="/hardware/task/create",kp="/hardware/task/delete",xp="/hardware/task/copy",Cp=r=>s.z.object({tasks:Oo(r).array()}),Rp=r=>s.z.object({tasks:Ft(r).array()}),jp=s.z.object({keys:Te.array()}),Mp=s.z.object({}),Up=s.z.object({key:Te,name:s.z.string(),snapshot:s.z.boolean()}),Dp=r=>s.z.object({task:Ft(r)});let Ao=class{type="task";client;frameClient;ontologyClient;rangeClient;constructor(e,t,n,i){this.client=e,this.frameClient=t,this.ontologyClient=n,this.rangeClient=i}async create(e,t){const n=!Array.isArray(e),i=Cp(t),a=Rp(t),o=await m(this.client,Ip,{tasks:v.toArray(e)},i,a),c=this.sugar(o.tasks,t);return n?c[0]:c}async delete(e){await m(this.client,kp,{keys:v.toArray(e)},jp,Mp)}async retrieve({schemas:e,...t}){const n="key"in t||"name"in t,a=(await m(this.client,$p,t,Sp,Ap(e))).tasks,o=this.sugar(a,e);return Fe("Task",t,o,n),n?o[0]:o}async copy(e,t,n){const i=Dp(),a=await m(this.client,xp,{key:e,name:t,snapshot:n},Up,i);return this.sugar(a.task)}async retrieveSnapshottedTo(e){if(this.ontologyClient==null)throw Ue;return await zo(e,this.ontologyClient)}sugar(e,t){const n=!Array.isArray(e),i=v.toArray(e).map(({key:a,name:o,type:c,config:u,status:l,internal:h,snapshot:y})=>new So({key:a,name:o,type:c,config:u,internal:h,snapshot:y,status:l},t,this.frameClient,this.ontologyClient,this.rangeClient));return n?i[0]:i}async executeCommand(e,t,n){if(Array.isArray(e))return await Kn(this.frameClient,e);if(t==null)throw new Error("Type is required");return await $o(this.frameClient,e,t,n)}async executeCommandSync(e,t,n,i,a,o=s.z.unknown()){if(Array.isArray(e)){const u=async()=>(await this.retrieve({keys:e.map(h=>h.task)})).map(h=>h.name);return await ko(this.frameClient,e,t,o,u)}const c=async()=>(await this.retrieve({key:e})).name;return await Io(this.frameClient,e,t,n,a??c,o,i)}};const Gn=r=>({type:"task",key:r}),$o=async(r,e,t,n)=>(await Kn(r,[{args:n,task:e,type:t}]))[0],Kn=async(r,e)=>{if(r==null)throw Ue;const t=await r.openWriter(En),n=e.map(i=>({...i,key:Rh.create()}));return await t.write(En,n),await t.close(),n.map(i=>i.key)},Io=async(r,e,t,n,i,a,o)=>(await ko(r,[{args:o,task:e,type:t}],n,a,i))[0],ko=async(r,e,t,n,i)=>{if(r==null)throw Ue;const a=await r.openStreamer(vn),o=await Kn(r,e),c=new E(t);let u=[],l;const h=new Promise((y,d)=>{l=setTimeout(()=>{(async()=>{const N=e.map(S=>S.task);d(await Zp("command",i,c,N))})()},c.milliseconds)});try{for(;;){const y=await Promise.race([a.read(),h]),d=Wn(n).parse(y.at(-1)[vn]);if(o.includes(d.key)&&(u=[...u.filter(N=>N.key!==d.key),d],u.length===o.length))return u}}finally{clearTimeout(l),a.close()}},Zp=async(r,e,t,n)=>{const i=pu.capitalize(r),a=t.toString();try{let o;typeof e=="string"?o=[e]:Array.isArray(e)?o=e:o=v.toArray(await e());const c=yn.naturalLanguageJoin(o);return new Error(`${i} command to ${c} timed out after ${a}`)}catch(o){return console.error("Failed to retrieve task name for timeout error:",o),new Error(`${i} command to task with key ${yn.naturalLanguageJoin(n)} timed out after ${a}`)}},Pp=Object.freeze(Object.defineProperty({__proto__:null,COMMAND_CHANNEL_NAME:En,Client:Ao,DELETE_CHANNEL_NAME:Ep,SET_CHANNEL_NAME:vp,STATUS_CHANNEL_NAME:vn,Task:So,commandZ:bp,keyZ:Te,newZ:Oo,ontologyID:Gn,rackKey:Tp,statusDetailsZ:No,statusZ:Wn,taskZ:Ft},Symbol.toStringTag,{value:"Module"})),Re=s.z.uuid(),Yt=s.z.object({key:Re,name:s.z.string().min(1),color:s.z.string()}),Lp="labeled_by",Bp="sy_label_set",qp="sy_label_delete",xo=Yt.extend({key:Re.optional()}),Fp=s.object({labels:xo.array()}),Yp=s.object({labels:Yt.array()}),Vp=s.object({keys:Re.array()}),Co=s.object({id:C,labels:Re.array(),replace:s.boolean().optional()}),Hp=Co.omit({replace:!0}),Yr=s.object({}),_p="/label/create",Wp="/label/delete",Gp="/label/set",Kp="/label/remove",Jp="/label/retrieve",Xp=s.object({keys:Re.array().optional(),for:C.optional(),searchTerm:s.string().optional(),offset:s.number().optional(),limit:s.number().optional()}),Qp=s.object({key:Re}).transform(({key:r})=>({keys:[r]})),em=s.union([Qp,Xp]),tm=s.object({labels:L(Yt)});let Ro=class{type="label";client;constructor(e){this.client=e}async retrieve(e){const t="key"in e,n=await m(this.client,Jp,e,em,tm);return Fe("Label",e,n.labels,t),t?n.labels[0]:n.labels}async label(e,t,n={}){await m(this.client,Gp,{id:e,labels:t,replace:n.replace},Co,Yr)}async remove(e,t){await m(this.client,Kp,{id:e,labels:t},Hp,Yr)}async create(e){const t=Array.isArray(e),n=await m(this.client,_p,{labels:v.toArray(e)},Fp,Yp);return t?n.labels:n.labels[0]}async delete(e){await m(this.client,Wp,{keys:v.toArray(e)},Vp,Yr)}};const rm=r=>({type:"label",key:r}),nm=Object.freeze(Object.defineProperty({__proto__:null,Client:Ro,DELETE_CHANNEL_NAME:qp,LABELED_BY_ONTOLOGY_RELATIONSHIP_TYPE:Lp,SET_CHANNEL_NAME:Bp,keyZ:Re,labelZ:Yt,newZ:xo,ontologyID:rm},Symbol.toStringTag,{value:"Module"})),H=s.z.uuid(),Jn=s.z.string().min(1),Vt=s.z.object({key:H,name:Jn,timeRange:M.z,color:s.z.string().optional(),labels:Yt.array().or(s.z.null().transform(()=>{})).optional(),get parent(){return Vt.optional().nullable().transform(r=>r===void 0?null:r)}}),jo=Vt.omit({parent:!0,labels:!0}).partial({key:!0}),sm="sy_range_alias_set",im="sy_range_alias_delete",am=s.z.object({range:H,aliases:s.z.string().array()}),om=s.z.object({aliases:s.z.record(s.z.string(),j)}),cm=s.z.object({range:H,aliases:s.z.record(j,s.z.string())}),lm=s.z.unknown(),um=s.z.object({range:H,channels:j.array()}),hm=s.z.unknown(),fm=s.z.object({range:H}),dm=s.z.object({aliases:s.z.record(s.z.string(),s.z.string())}),ym=s.z.object({range:H,channels:j.array()}),gm=s.z.object({aliases:s.z.record(s.z.string(),s.z.string())});class ee{static SET_ENDPOINT="/range/alias/set";static RESOLVE_ENDPOINT="/range/alias/resolve";static LIST_ENDPOINT="/range/alias/list";static RETRIEVE_ENDPOINT="/range/alias/retrieve";static DELETE_ENDPOINT="/range/alias/delete";frameClient;cache=new Map;client;rangeKey;constructor(e,t,n){this.rangeKey=e,this.cache=new Map,this.client=n,this.frameClient=t}async resolve(e){const t=[],n=typeof e=="string",i={};if(n){const o=this.cache.get(e);if(o!=null)return o;t.push(e)}else e.forEach(o=>{const c=this.cache.get(o);c!=null?i[o]=c:t.push(o)});if(t.length===0)return i;const a=await m(this.client,ee.RESOLVE_ENDPOINT,{range:this.rangeKey,aliases:t},am,om);return Object.entries(a.aliases).forEach(([o,c])=>this.cache.set(o,c)),n?a.aliases[t[0]]:{...i,...a.aliases}}async set(e){await m(this.client,ee.SET_ENDPOINT,{range:this.rangeKey,aliases:e},cm,lm)}async list(){return(await m(this.client,ee.LIST_ENDPOINT,{range:this.rangeKey},fm,dm)).aliases}async retrieve(e){const t=typeof e=="number",n=await m(this.client,ee.RETRIEVE_ENDPOINT,{range:this.rangeKey,channels:v.toArray(e)},ym,gm);return t?n.aliases[e]:n.aliases}async delete(e){await m(this.client,ee.DELETE_ENDPOINT,{range:this.rangeKey,channels:e},um,hm)}}const pm=s.z.object({alias:s.z.string().optional(),channel:j,range:H}),Mo="---",mm=r=>`${r.range}${Mo}${r.channel}`,wm=r=>{const[e,t]=r.split(Mo);return{range:e,channel:Number(t)}},bm="sy_range_kv_set",Tm="sy_range_kv_delete",Xn=s.z.object({range:H,key:s.z.string(),value:s.z.string()}),vm=({range:r,key:e})=>`${r}<--->${e}`,Em=s.z.object({range:H,keys:s.z.string().array()}),Nm=s.z.object({pairs:L(Xn)}),Om=s.z.object({range:H,pairs:Xn.array()}),zm=s.z.object({range:H,keys:s.z.string().array()});class Pe{static GET_ENDPOINT="/range/kv/get";static SET_ENDPOINT="/range/kv/set";static DELETE_ENDPOINT="/range/kv/delete";rangeKey;client;constructor(e,t){this.rangeKey=e,this.client=t}async get(e){const t=await m(this.client,Pe.GET_ENDPOINT,{range:this.rangeKey,keys:v.toArray(e)},Em,Nm);return typeof e=="string"?t.pairs[0].value:Object.fromEntries(t.pairs.map(n=>[n.key,n.value]))}async list(){return this.get([])}async set(e,t=""){let n;wi(e)?n=Object.entries(e).map(([i,a])=>({range:this.rangeKey,key:i,value:a})):n=[{range:this.rangeKey,key:e,value:t}],await m(this.client,Pe.SET_ENDPOINT,{range:this.rangeKey,pairs:n},Om,s.z.unknown())}async delete(e){await m(this.client,Pe.DELETE_ENDPOINT,{range:this.rangeKey,keys:v.toArray(e)},zm,s.z.unknown())}}const Sm="sy_range_set",Am="sy_range_delete";class Uo{key;name;kv;timeRange;color;parent;labels;channels;aliaser;frameClient;labelClient;ontologyClient;rangeClient;constructor({name:e,timeRange:t=M.ZERO,key:n,color:i,parent:a,labels:o},{frameClient:c,kv:u,aliaser:l,channels:h,labelClient:y,ontologyClient:d,rangeClient:N}){this.key=n,this.name=e,this.timeRange=t,this.parent=a,this.labels=o,this.frameClient=c,this.color=i,this.kv=u,this.aliaser=l,this.channels=h,this.labelClient=y,this.ontologyClient=d,this.rangeClient=N}get ontologyID(){return Ge(this.key)}get payload(){let e=null;return this.parent!=null&&("payload"in this.parent?e=this.parent.payload:e=this.parent),{key:this.key,name:this.name,timeRange:this.timeRange,color:this.color,labels:this.labels,parent:e}}async setAlias(e,t){const n=await this.channels.retrieve(e);if(n.length===0)throw new xe(`Channel ${e} does not exist`);await this.aliaser.set({[n[0].key]:t})}async deleteAlias(...e){await this.aliaser.delete(e)}async listAliases(){return await this.aliaser.list()}async resolveAlias(e){return await this.aliaser.resolve(e)}async retrieveParent(){return this.rangeClient.retrieveParent(this.key)}async retrieveChildren(){const e=(await this.ontologyClient.retrieveChildren(this.ontologyID,{excludeFieldData:!0,types:["range"]})).map(t=>t.id.key);return await this.rangeClient.retrieve(e)}async read(e){return await this.frameClient.read(this.timeRange,e)}async retrieveLabels(){return await this.labelClient.retrieve({for:Ge(this.key)})}async addLabel(...e){await this.labelClient.label(Ge(this.key),e)}async removeLabel(...e){await this.labelClient.remove(Ge(this.key),e)}static sort(e,t){return M.sort(e.timeRange,t.timeRange)}}const $m=s.z.object({keys:H.array().optional(),names:s.z.array(s.z.string()).optional(),searchTerm:s.z.string().optional(),overlapsWith:M.z.optional(),limit:s.z.number().int().optional(),offset:s.z.number().int().optional(),hasLabels:Re.array().optional(),includeLabels:s.z.boolean().optional(),includeParent:s.z.boolean().optional()}),Im=$m.or(H.array().transform(r=>({keys:r}))).or(H.transform(r=>({keys:[r]}))).or(s.z.string().transform(r=>({names:[r]}))).or(s.z.string().array().transform(r=>({names:r}))).or(M.z.transform(r=>({overlapsWith:r}))),km="/range/retrieve",xm=s.z.object({ranges:L(Vt)});let Do=class{type="range";frameClient;writer;unaryClient;channels;labelClient;ontologyClient;constructor(e,t,n,i,a,o){this.frameClient=e,this.writer=t,this.unaryClient=n,this.channels=i,this.labelClient=a,this.ontologyClient=o}async create(e,t){const n=!Array.isArray(e),i=this.sugarMany(await this.writer.create(v.toArray(e),t));return n?i[0]:i}async rename(e,t){await this.writer.rename(e,t)}async delete(e){await this.writer.delete(v.toArray(e))}async retrieve(e){const t=typeof e=="string",{ranges:n}=await m(this.unaryClient,km,e,Im,xm);return Fe("Range",e,n,t),t?this.sugarMany(n)[0]:this.sugarMany(n)}getKV(e){return new Pe(e,this.unaryClient)}async retrieveParent(e){const t=await this.ontologyClient.retrieveParents(Ge(e));if(t.length===0)return null;const n=t[0];return n.id.type!=="range"?null:await this.retrieve(n.id.key)}sugarOntologyResource(e){return this.sugarOne(Zo(e))}async retrieveAlias(e,t){return await new ee(e,this.frameClient,this.unaryClient).retrieve(t)}async retrieveAliases(e,t){return await new ee(e,this.frameClient,this.unaryClient).retrieve(t)}async listAliases(e){return await new ee(e,this.frameClient,this.unaryClient).list()}async setAlias(e,t,n){await new ee(e,this.frameClient,this.unaryClient).set({[t]:n})}sugarOne(e){return new Uo(e,{frameClient:this.frameClient,kv:new Pe(e.key,this.unaryClient),aliaser:new ee(e.key,this.frameClient,this.unaryClient),channels:this.channels,labelClient:this.labelClient,ontologyClient:this.ontologyClient,rangeClient:this})}sugarMany(e){return e.map(t=>this.sugarOne(t))}resourceToRange(e){return this.sugarOne({key:e.id.key,name:e.data?.name,timeRange:new M(e.data?.timeRange),color:e.data?.color,labels:[],parent:null})}};const Ge=r=>({type:"range",key:r}),Cm=r=>({type:"range-alias",key:r}),Zo=({data:r,id:{key:e},name:t})=>{const n=M.z.parse(r?.timeRange);return{key:e,name:t,timeRange:n,color:typeof r?.color=="string"?r.color:void 0,labels:[],parent:null}},Rm=s.z.object({ranges:Vt.array()}),jm=s.z.object({parent:C.optional(),ranges:jo.array()}),Mm=s.z.object({keys:H.array()}),Um=s.z.object({}),Dm=s.z.object({key:H,name:Jn}),Zm=s.z.object({}),Pm="/range/create",Lm="/range/delete",Bm="/range/rename";class Po{client;constructor(e){this.client=e}async rename(e,t){await m(this.client,Bm,{key:e,name:t},Dm,Zm)}async create(e,t){return(await m(this.client,Pm,{ranges:e,...t},jm,Rm)).ranges}async delete(e){await m(this.client,Lm,{keys:e},Mm,Um)}}const qm=Object.freeze(Object.defineProperty({__proto__:null,Aliaser:ee,Client:Do,DELETE_ALIAS_CHANNEL_NAME:im,DELETE_CHANNEL_NAME:Am,KV:Pe,KV_DELETE_CHANNEL:Tm,KV_SET_CHANNEL:bm,Range:Uo,SET_ALIAS_CHANNEL_NAME:sm,SET_CHANNEL_NAME:Sm,Writer:Po,aliasKey:mm,aliasOntologyID:Cm,aliasZ:pm,convertOntologyResourceToPayload:Zo,decodeDeleteAliasChange:wm,keyZ:H,kvPairKey:vm,kvPairZ:Xn,nameZ:Jn,newZ:jo,ontologyID:Ge,payloadZ:Vt},Symbol.toStringTag,{value:"Module"})),Fm="/api/v1/";class Ym{url;unary;stream;secure;constructor(e,t={},n=!1){this.secure=n,this.url=e.child(Fm);const i=new Be.JSONCodec;this.unary=ru(new tu(this.url,i,this.secure),t),this.stream=new ar(this.url,i,this.secure)}use(...e){this.unary.use(...e),this.stream.use(...e)}}const ct=s.z.uuid(),$r=s.z.object({key:ct,name:s.z.string(),data:we.unknownZ.or(s.z.string().transform(be))}),Lo=$r.partial({key:!0}).transform(r=>({...r,data:JSON.stringify(r.data)})),de=s.z.uuid(),Ir=s.z.object({key:de,name:s.z.string(),layout:we.unknownZ.or(s.z.string().transform(be))}),Bo=Ir.partial({key:!0}).transform(r=>({...r,layout:JSON.stringify(r.layout)})),qo=Ir.omit({layout:!0}).extend({layout:s.z.string().transform(be)}),Vm="/workspace/lineplot/retrieve",Hm="/workspace/lineplot/create",_m="/workspace/lineplot/rename",Wm="/workspace/lineplot/set-data",Gm="/workspace/lineplot/delete",Km=s.z.object({keys:ct.array()}),Jm=s.z.object({workspace:de,linePlots:Lo.array()}),Xm=s.z.object({key:ct,name:s.z.string()}),Qm=s.z.object({key:ct,data:s.z.string()}),ew=s.z.object({keys:ct.array()}),tw=s.z.object({linePlots:L($r)}),rw=s.z.object({linePlots:$r.array()}),Vr=s.z.object({});let Fo=class{client;constructor(e){this.client=e}async create(e,t){const n=Array.isArray(t),i=await m(this.client,Hm,{workspace:e,linePlots:v.toArray(t)},Jm,rw);return n?i.linePlots:i.linePlots[0]}async rename(e,t){await m(this.client,_m,{key:e,name:t},Xm,Vr)}async setData(e,t){await m(this.client,Wm,{key:e,data:JSON.stringify(t)},Qm,Vr)}async retrieve(e){const t=Array.isArray(e),n=await m(this.client,Vm,{keys:v.toArray(e)},Km,tw);return t?n.linePlots:n.linePlots[0]}async delete(e){await m(this.client,Gm,{keys:v.toArray(e)},ew,Vr)}};const nw=r=>({type:"lineplot",key:r}),sw=Object.freeze(Object.defineProperty({__proto__:null,Client:Fo,keyZ:ct,linePlotZ:$r,newZ:Lo,ontologyID:nw},Symbol.toStringTag,{value:"Module"})),lt=s.z.uuid(),kr=s.z.object({key:lt,name:s.z.string(),data:we.unknownZ.or(s.z.string().transform(be))}),Yo=kr.partial({key:!0}).transform(r=>({...r,data:JSON.stringify(r.data)})),iw="/workspace/log/retrieve",aw="/workspace/log/create",ow="/workspace/log/rename",cw="/workspace/log/set-data",lw="/workspace/log/delete",uw=s.z.object({keys:lt.array()}),hw=s.z.object({workspace:de,logs:Yo.array()}),fw=s.z.object({key:lt,name:s.z.string()}),dw=s.z.object({key:lt,data:s.z.string()}),yw=s.z.object({keys:lt.array()}),gw=s.z.object({logs:kr.array()}),pw=s.z.object({logs:kr.array()}),Hr=s.z.object({});let Vo=class{client;constructor(e){this.client=e}async create(e,t){const n=Array.isArray(t),i=await m(this.client,aw,{workspace:e,logs:v.toArray(t)},hw,pw);return n?i.logs:i.logs[0]}async rename(e,t){await m(this.client,ow,{key:e,name:t},fw,Hr)}async setData(e,t){await m(this.client,cw,{key:e,data:JSON.stringify(t)},dw,Hr)}async retrieve(e){const t=Array.isArray(e),n=await m(this.client,iw,{keys:v.toArray(e)},uw,gw);return t?n.logs:n.logs[0]}async delete(e){await m(this.client,lw,{keys:v.toArray(e)},yw,Hr)}};const mw=r=>({type:"log",key:r}),ww=Object.freeze(Object.defineProperty({__proto__:null,Client:Vo,keyZ:lt,logZ:kr,newZ:Yo,ontologyID:mw},Symbol.toStringTag,{value:"Module"})),Ye=s.z.uuid(),xr=s.z.object({key:Ye,name:s.z.string(),data:we.unknownZ.or(s.z.string().transform(be)),snapshot:s.z.boolean()}),Ho=xr.partial({key:!0,snapshot:!0}).transform(r=>({...r,data:JSON.stringify(r.data)})),Qn=xr.extend({data:s.z.string().transform(be)}),ut=s.z.uuid(),_o=s.z.object({key:s.z.string(),name:s.z.string(),selectors:s.z.string().array().default([]),strokeColor:s.z.string().optional(),fillColor:s.z.string().optional()}),Wo=s.z.object({key:s.z.string(),name:s.z.string(),regions:_o.array()}),Go=s.z.object({key:s.z.string(),position:Wi.xy,orientation:ih.outer}),bw=s.z.object({zoom:s.z.number().positive().default(1),position:Wi.xy}),Ko=s.z.object({svg:s.z.string().min(1,"SVG is required"),states:Wo.array(),variant:s.z.string().min(1,"Variant is required"),handles:Go.array(),scale:s.z.number().positive().default(1),scaleStroke:s.z.boolean().default(!1),previewViewport:bw.default({zoom:1,position:{x:0,y:0}})}),Cr=s.z.object({key:ut,version:s.z.literal(1).optional().default(1),name:s.z.string().min(1,"Name is required"),data:Ko}),Jo=Cr.partial({key:!0}),Tw="/workspace/schematic/symbol/retrieve",vw="/workspace/schematic/symbol/create",Ew="/workspace/schematic/symbol/rename",Nw="/workspace/schematic/symbol/delete",Ow="/workspace/schematic/symbol/retrieve_group",zw=s.z.object({symbols:Jo.array(),parent:C}),Sw=s.z.object({key:ut,name:s.z.string()}),Aw=s.z.object({keys:ut.array()}),$w=s.z.object({keys:ut.array().optional(),searchTerm:s.z.string().optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),Iw=s.z.object({key:ut}).transform(({key:r})=>({keys:[r]})),kw=s.z.union([Iw,$w]),xw=s.z.object({symbols:L(Cr)}),Cw=s.z.object({symbols:Cr.array()}),Ls=s.z.object({}),Rw=s.z.object({}),jw=s.z.object({group:Tr}),Mw="sy_schematic_symbol_set",Uw="sy_schematic_symbol_delete";let Xo=class{client;constructor(e){this.client=e}async create(e){const t="symbols"in e,n=t?e.symbols:[e],i=await m(this.client,vw,{symbols:n,parent:e.parent},zw,Cw);return t?i.symbols:i.symbols[0]}async rename(e,t){await m(this.client,Ew,{key:e,name:t},Sw,Ls)}async retrieve(e){const t="key"in e,n=await m(this.client,Tw,e,kw,xw);return Fe("Schematic Symbol",e,n.symbols,t),t?n.symbols[0]:n.symbols}async delete(e){await m(this.client,Nw,{keys:v.toArray(e)},Aw,Ls)}async retrieveGroup(){return(await m(this.client,Ow,{},Rw,jw)).group}};const Dw=r=>({type:"schematic_symbol",key:r}),Zw=Object.freeze(Object.defineProperty({__proto__:null,Client:Xo,DELETE_CHANNEL_NAME:Uw,SET_CHANNEL_NAME:Mw,handleZ:Go,keyZ:ut,newZ:Jo,ontologyID:Dw,regionZ:_o,specZ:Ko,stateZ:Wo,symbolZ:Cr},Symbol.toStringTag,{value:"Module"})),Pw="/workspace/schematic/retrieve",Lw="/workspace/schematic/create",Bw="/workspace/schematic/rename",qw="/workspace/schematic/set-data",Fw="/workspace/schematic/delete",Yw="/workspace/schematic/copy",Vw=s.z.object({keys:Ye.array()}),Hw=s.z.object({workspace:de,schematics:Ho.array()}),_w=s.z.object({key:Ye,name:s.z.string()}),Ww=s.z.object({key:Ye,data:s.z.string()}),Gw=s.z.object({keys:Ye.array()}),Kw=s.z.object({key:Ye,name:s.z.string(),snapshot:s.z.boolean()}),Jw=s.z.object({schematics:L(Qn)}),Xw=s.z.object({schematics:Qn.array()}),Qw=s.z.object({schematic:xr}),_r=s.z.object({});let Qo=class{symbols;client;constructor(e){this.client=e,this.symbols=new Xo(e)}async create(e,t){const n=Array.isArray(t),i=await m(this.client,Lw,{workspace:e,schematics:v.toArray(t)},Hw,Xw);return n?i.schematics:i.schematics[0]}async rename(e,t){await m(this.client,Bw,{key:e,name:t},_w,_r)}async setData(e,t){await m(this.client,qw,{key:e,data:JSON.stringify(t)},Ww,_r)}async retrieve(e){const t=Array.isArray(e),n=await m(this.client,Pw,{keys:v.toArray(e)},Vw,Jw);return t?n.schematics:n.schematics[0]}async delete(e){await m(this.client,Fw,{keys:v.toArray(e)},Gw,_r)}async copy(e,t,n){return(await m(this.client,Yw,{key:e,name:t,snapshot:n},Kw,Qw)).schematic}};const eb=r=>({type:"schematic",key:r}),tb=Object.freeze(Object.defineProperty({__proto__:null,Client:Qo,keyZ:Ye,newZ:Ho,ontologyID:eb,remoteZ:Qn,schematicZ:xr,symbol:Zw},Symbol.toStringTag,{value:"Module"})),ht=s.z.uuid(),es=s.z.object({key:ht,name:s.z.string(),data:we.unknownZ.or(s.z.string().transform(be))}),ec=es.partial({key:!0}).transform(r=>({...r,data:JSON.stringify(r.data)})),ts=es.extend({data:s.z.string().transform(be)}),rb="/workspace/table/retrieve",nb="/workspace/table/create",sb="/workspace/table/rename",ib="/workspace/table/set-data",ab="/workspace/table/delete",ob=s.z.object({keys:ht.array()}),cb=s.z.object({workspace:de,tables:ec.array()}),lb=s.z.object({key:ht,name:s.z.string()}),ub=s.z.object({key:ht,data:s.z.string()}),hb=s.z.object({keys:ht.array()}),fb=s.z.object({tables:ts.array()}),db=s.z.object({tables:ts.array()}),Wr=s.z.object({});let tc=class{client;constructor(e){this.client=e}async create(e,t){const n=Array.isArray(t),i=await m(this.client,nb,{workspace:e,tables:v.toArray(t)},cb,db);return n?i.tables:i.tables[0]}async rename(e,t){await m(this.client,sb,{key:e,name:t},lb,Wr)}async setData(e,t){await m(this.client,ib,{key:e,data:JSON.stringify(t)},ub,Wr)}async retrieve(e){const t=Array.isArray(e),n=await m(this.client,rb,{keys:v.toArray(e)},ob,fb);return t?n.tables:n.tables[0]}async delete(e){await m(this.client,ab,{keys:v.toArray(e)},hb,Wr)}};const yb=r=>({type:"table",key:r}),gb=Object.freeze(Object.defineProperty({__proto__:null,Client:tc,keyZ:ht,newZ:ec,ontologyID:yb,remoteZ:ts,tableZ:es},Symbol.toStringTag,{value:"Module"})),Bs="/workspace/retrieve",pb="/workspace/create",mb="/workspace/rename",wb="/workspace/set-layout",bb="/workspace/delete",qs=s.z.object({keys:de.array().optional(),searchTerm:s.z.string().optional(),author:Ce.optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),Tb=s.z.object({workspaces:Bo.array()}),vb=s.z.object({key:de,name:s.z.string()}),Eb=s.z.object({key:de,layout:s.z.string()}),Nb=s.z.object({keys:de.array()}),Fs=s.z.object({workspaces:L(Ir)}),Ob=s.z.object({workspaces:qo.array()}),Gr=s.z.object({}),zb="sy_workspace_set",Sb="sy_workspace_delete";class rc{type="workspace";schematic;linePlot;log;table;client;constructor(e){this.client=e,this.schematic=new Qo(e),this.linePlot=new Fo(e),this.log=new Vo(e),this.table=new tc(e)}async create(e){const t=Array.isArray(e),n=await m(this.client,pb,{workspaces:v.toArray(e)},Tb,Ob);return t?n.workspaces:n.workspaces[0]}async rename(e,t){await m(this.client,mb,{key:e,name:t},vb,Gr)}async setLayout(e,t){await m(this.client,wb,{key:e,layout:JSON.stringify(t)},Eb,Gr)}async retrieve(e){let t;const n=typeof e!="string";typeof e=="string"||Array.isArray(e)?t={keys:v.toArray(e)}:t=e;const i=await m(this.client,Bs,t,qs,Fs);return n?i.workspaces:i.workspaces[0]}async retrieveByAuthor(e){return(await m(this.client,Bs,{author:e},qs,Fs)).workspaces}async delete(e){await m(this.client,bb,{keys:v.toArray(e)},Nb,Gr)}}const Ab=r=>({type:"workspace",key:r}),$b=Object.freeze(Object.defineProperty({__proto__:null,Client:rc,DELETE_CHANNEL_NAME:Sb,SET_CHANNEL_NAME:zb,keyZ:de,newZ:Bo,ontologyID:Ab,remoteZ:qo,workspaceZ:Ir},Symbol.toStringTag,{value:"Module"})),nc=s.z.object({host:s.z.string({error:"Host is required"}).min(1,"Host is required"),port:s.z.number({error:"Port is required"}).or(s.z.string({error:"Port is required"})),username:s.z.string().min(1,"Username is required"),password:s.z.string().min(1,"Password is required"),connectivityPollFrequency:E.z.default(E.seconds(30)),secure:s.z.boolean().optional().default(!1),name:s.z.string().optional(),retry:ca.breakerConfigZ.optional()});class sc extends lo{createdAt;props;ranges;channels;auth;user;access;connectivity;ontology;workspaces;labels;hardware;control;static connectivity=kt;transport;clientVersion="0.45.1";constructor(e){const t=nc.parse(e),{host:n,port:i,username:a,password:o,connectivityPollFrequency:c,secure:u,retry:l}=t,h=new Ym(new wt({host:n,port:Number(i)}),l,u);h.use(hd);let y;a!=null&&o!=null&&(y=new sg(h.unary,{username:a,password:o}),h.use(y.middleware()));const d=new Fn(new Bt(h.unary)),N=new Ha(h.unary,d);super(h.stream,h.unary,d),this.createdAt=f.now(),this.props=t,this.auth=y,this.transport=h,this.channels=new Fa(this,d,h.unary,N),this.connectivity=new kt(h.unary,c,this.clientVersion,t.name),this.control=new fo(this),this.ontology=new ja(h.unary,this);const S=new Po(this.transport.unary);this.labels=new Ro(this.transport.unary),this.ranges=new Do(this,S,this.transport.unary,d,this.labels,this.ontology),this.access=new Da(this.transport.unary),this.user=new Wa(this.transport.unary),this.workspaces=new rc(this.transport.unary);const k=new To(this.transport.unary),B=new Ao(this.transport.unary,this,this.ontology,this.ranges),x=new vo(this.transport.unary,B);this.hardware=new yo(B,x,k)}get key(){return this.createdAt.valueOf().toString()}close(){this.connectivity.stopChecking()}}const ic={host:"localhost",port:9090,username:"synnax",password:"seldon",retry:{maxRetries:4,baseInterval:E.seconds(1),scale:1.5}},Ib=r=>new sc({...ic,...r});exports.AuthError=zt;exports.Channel=cr;exports.ContiguityError=cd;exports.DataType=$;exports.Density=Y;exports.DisconnectedError=od;exports.Frame=P;exports.MultiSeries=ia;exports.MultipleFoundError=At;exports.NotFoundError=St;exports.QueryError=xe;exports.Rate=W;exports.RouteError=mn;exports.Series=ge;exports.Synnax=sc;exports.TEST_CLIENT_PROPS=ic;exports.TimeRange=M;exports.TimeSpan=E;exports.TimeStamp=f;exports.UnexpectedError=Xe;exports.ValidationError=Z;exports.access=sy;exports.channel=Iy;exports.connection=ag;exports.control=Zg;exports.createTestClient=Ib;exports.device=tp;exports.framer=Cg;exports.group=Id;exports.hardware=Pg;exports.isCalculated=It;exports.label=nm;exports.linePlot=sw;exports.log=ww;exports.ontology=qd;exports.policy=ny;exports.rack=wp;exports.ranger=qm;exports.schematic=tb;exports.synnaxPropsZ=nc;exports.table=gb;exports.task=Pp;exports.user=Ky;exports.workspace=$b;
|
|
60
|
+
`);const h=new Ae({data:r[l],dataType:u.dataType});o.push(u.key),c.push(h)}return new W(o,c)}if(e instanceof W||e instanceof Map){const o=new W(e);if(this.adapter==null)return o;const c=o.columns.map(l=>{const u=typeof l=="string"?this.adapter?.get(l):l;if(u==null)throw new Y(`
|
|
61
|
+
Channel ${l} was not provided in the list of channels when opening the writer
|
|
62
|
+
`);return u});return new W(c,o.series)}const n=[],s=[],a=Object.entries(e);for(let o=0;o<a.length;o++){const[c,l]=a[o],u=await this.fetchChannel(c),h=new Ae({data:l,dataType:u.dataType});n.push(u.key),s.push(h)}return new W(n,s)}}class yu{name;stream;constructor(e,r){this.stream=r,this.name=e}async receive(){const[e,r]=await this.stream.receive();if(r!=null)throw r;return e}received(){return this.stream.received()}async closeAndAck(){for(this.stream.closeSend();;){const[e,r]=await this.stream.receive();if(e!=null&&console.warn(`${this.name} received unexpected response on ${JSON.stringify(e)} closure.
|
|
63
|
+
Please report this error to the Synnax team.`),r!=null){if(we.matches(r))return;throw r}}}closeSend(){this.stream.closeSend()}send(e){const r=this.stream.send(e);if(r!=null)throw r}}const Ur=new I(-1);var Hs=(t=>(t[t.Open=0]="Open",t[t.Next=1]="Next",t[t.Prev=2]="Prev",t[t.SeekFirst=3]="SeekFirst",t[t.SeekLast=4]="SeekLast",t[t.SeekLE=5]="SeekLE",t[t.SeekGE=6]="SeekGE",t[t.Valid=7]="Valid",t[t.Error=8]="Error",t))(Hs||{}),mu=(t=>(t[t.None=0]="None",t[t.Ack=1]="Ack",t[t.Data=2]="Data",t))(mu||{});const Fz=i.z.object({command:i.z.enum(Hs),span:I.z.optional(),bounds:P.z.optional(),stamp:p.z.optional(),keys:D.array().optional(),chunkSize:i.z.number().optional()}),Vz=i.z.object({variant:i.z.enum(mu),ack:i.z.boolean(),command:i.z.enum(Hs),error:Ze.payloadZ.optional().nullable(),frame:sn.optional()});class tr{static ENDPOINT="/frame/iterate";stream;adapter;value;constructor(e,r){this.stream=new yu("Iterator",e),this.value=new W,this.adapter=r}static async _open(e,r,n,s,a={}){const o=await an.open(n,r),c=await s.stream(tr.ENDPOINT,Fz,Vz),l=new tr(c,o);return await l.execute({command:0,keys:o.keys,bounds:new P(e),chunkSize:a.chunkSize??1e5}),l}async next(e=Ur){return await this.execute({command:1,span:new I(e)})}async prev(e=Ur){return await this.execute({command:2,span:new I(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 p(e)})}async seekGE(e){return await this.execute({command:6,stamp:new p(e)})}async valid(){return await this.execute({command:7})}async close(){await this.stream.closeAndAck()}[Symbol.asyncIterator](){return new Yz(this)}async execute(e){for(this.stream.send(e),this.value=new W;;){const r=await this.stream.receive();if(r.variant===1)return r.ack;this.value.push(this.adapter.adapt(new W(r.frame)))}}}class Yz{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 Wz=i.z.object({keys:i.z.number().array(),downsampleFactor:i.z.number()}),Hz=i.z.object({frame:sn}),Gz="/frame/stream",la=i.z.object({channels:it,downsampleFactor:i.z.number().optional().default(1),useHighPerformanceCodec:i.z.boolean().optional().default(!0)}),Gs=la.or(it.transform(t=>la.parse({channels:t}))),gu=(t,e)=>async r=>{const n=Gs.parse(r),s=await an.open(t,n.channels);n.useHighPerformanceCodec&&(e=e.withCodec(new qz(s.codec)));const a=await e.stream(Gz,Wz,Hz),o=new Jz(a,s);a.send({keys:s.keys,downsampleFactor:n.downsampleFactor??1});const[,c]=await a.receive();if(c!=null)throw c;return o},wu=async(t,e,r)=>await gu(t,e)(r);class Jz{stream;adapter;downsampleFactor;constructor(e,r){this.stream=new yu("Streamer",e),this.adapter=r,this.downsampleFactor=1}get keys(){return this.adapter.keys}async next(){try{return{done:!1,value:await this.read()}}catch(e){if(we.matches(e))return{done:!0,value:void 0};throw e}}async read(){return this.adapter.adapt(new W((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 on{wrapped_=null;breaker;opener;config;constructor(e,r,n={}){this.opener=e,this.config=Gs.parse(r);const{maxRetries:s=5e3,baseInterval:a=I.seconds(1),scale:o=1}=n??{};this.breaker=new Do.Breaker({maxRetries:s,baseInterval:a,scale:o})}static async open(e,r,n){const s=new on(e,r,n);return await s.runStreamer(),s}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=it.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(we.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(we.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 bu extends Yp.Observer{streamer;closePromise;constructor(e,r){super(r),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 Kz=t=>({type:"framer",key:t.toString()});let vu=class{streamClient;retriever;deleter;constructor(e,r,n){this.streamClient=e,this.retriever=n,this.deleter=new Az(r)}async openIterator(e,r,n){return await tr._open(e,r,this.retriever,this.streamClient,n)}async openWriter(e){return await fu._open(this.retriever,this.streamClient,e)}async openStreamer(e){return await wu(this.retriever,this.streamClient,e)}async write(e,r,n){if(n==null){const a=r,o=await this.openWriter({start:e,channels:Object.keys(a),mode:er.Persist,errOnUnauthorized:!0,enableAutoCommit:!0,autoIndexPersistInterval:I.MAX});return await o.write(a),await o.close()}const s=await this.openWriter({start:e,channels:r,mode:er.Persist,errOnUnauthorized:!0,enableAutoCommit:!0,autoIndexPersistInterval:I.MAX});await s.write(r,n),await s.close()}async read(e,r){const{single:n}=ge(r),s=await this.readFrame(e,r);return n?s.get(r):s}async readFrame(e,r){const n=await this.openIterator(e,r),s=new W;try{for await(const a of n)s.push(a)}finally{await n.close()}return s}async readLatest(e,r=1){const{single:n}=ge(e),s=await this.readLatestNFrame(e,r);return n?s.get(e):s}async readLatestNFrame(e,r){const n=await this.openIterator(P.MAX,e,{chunkSize:r}),s=new W;if(r>0)try{await n.seekLast(),await n.prev(Ur),s.push(n.value)}finally{await n.close()}return s}async delete(e,r){const{normalized:n,variant:s}=ge(e),a=new P(r);return s==="keys"?await this.deleter.delete({keys:n,bounds:a}):await this.deleter.delete({names:n,bounds:a})}};const Xz=Object.freeze(Object.defineProperty({__proto__:null,ALWAYS_INDEX_PERSIST_ON_AUTO_COMMIT:xz,AUTO_SPAN:Ur,Client:vu,Frame:W,HardenedStreamer:on,Iterator:tr,ObservableStreamer:bu,Writer:fu,WriterClosedError:ls,WriterCommand:zt,WriterMode:er,createStreamOpener:gu,frameZ:sn,ontologyID:Kz,openStreamer:wu,seriesFromPayload:cu,seriesToPayload:uu,streamerConfigZ:Gs,writerConfigZ:hu},Symbol.toStringTag,{value:"Module"})),Qz=fe.ABSOLUTE_AUTHORITY,eE=fe.ZERO_AUTHORITY,tE=fe.stateZ(i.z.number()),rE=t=>t.to==null?`${t.from?.resource} - ${t.from?.subject.name} -> released`:t.from==null?`${t.to.resource} - released -> ${t.to.subject.name} (${t.to.authority.toString()})`:`${t.to.resource} - ${t.from.subject.name} -> ${t.to.subject.name} (${t.to.authority.toString()})`,nE=i.z.object({transfers:i.z.array(fe.transferZ(D))});class Tu extends bu{states;codec;constructor(e){super(e,r=>{const n=this.codec.decode(r.series[0].buffer,nE);return this.merge(n),[n.transfers,!0]}),this.states=new Map,this.codec=new st.JSONCodec}subjects(){const e=new Map;return this.states.forEach(r=>e.set(r.subject.key,r.subject)),Array.from(e.values())}merge(e){e.transfers.forEach(r=>{r.from==null&&r.to==null&&console.warn("Invalid transfer: ",r),r.to==null?this.states.delete(r.from.resource):this.states.set(r.to.resource,r.to)})}}const zu="sy_node_1_control";let Eu=class{framer;constructor(e){this.framer=e}async openStateTracker(){const e=await on.open(async r=>await this.framer.openStreamer(r),zu);return new Tu(e)}};const sE=Object.freeze(Object.defineProperty({__proto__:null,ABSOLUTE_AUTHORITY:Qz,CONTROL_STATE_CHANNEL_NAME:zu,Client:Eu,StateTracker:Tu,ZERO_AUTHORITY:eE,stateZ:tE,transferString:rE},Symbol.toStringTag,{value:"Module"}));let Nu=class{tasks;racks;devices;constructor(e,r,n){this.tasks=e,this.racks=r,this.devices=n}};const iE=Object.freeze(Object.defineProperty({__proto__:null,Client:Nu},Symbol.toStringTag,{value:"Module"})),ve=i.z.uint32(),Ou=i.z.object({rack:ve}),$u=It.statusZ(Ou),cn=i.z.object({key:ve,name:i.z.string(),status:Lt.nullToUndefined($u)}),Su=cn.partial({key:!0}),Iu=t=>t?st.JSON_CODEC.decodeString(t,be.unknownZ):{},Zt=i.z.string(),ku=i.z.object({rack:ve,device:Zt}),Au=It.statusZ(ku),un=i.z.object({key:Zt,rack:ve.min(1,"Must select a location to connect from"),name:i.z.string().min(1,"Name is required"),make:i.z.string().min(1,"Make is required"),model:i.z.string().min(1,"Model is required"),location:i.z.string().min(1,"Location is required"),configured:i.z.boolean().optional(),properties:be.unknownZ.or(i.z.string().transform(Iu)),status:Lt.nullToUndefined(Au)}),xu=un.extend({properties:i.z.unknown().transform(t=>st.JSON_CODEC.encodeString(t))}),aE="sy_device_set",oE="sy_device_delete",cE="sy_device_status",uE="/hardware/device/retrieve",lE="/hardware/device/create",hE="/hardware/device/delete",fE=i.z.object({devices:xu.array()}),dE=i.z.object({devices:un.array()}),pE=i.z.object({keys:Zt.array()}),yE=i.z.object({}),mE=i.z.object({keys:Zt.array().optional(),names:i.z.string().array().optional(),makes:i.z.string().array().optional(),models:i.z.string().array().optional(),locations:i.z.string().array().optional(),racks:ve.array().optional(),searchTerm:i.z.string().optional(),limit:i.z.number().optional(),offset:i.z.number().optional(),includeStatus:i.z.boolean().optional()}),gE=i.z.object({devices:T.nullableZ(un)}),wE=i.z.object({key:Zt,includeStatus:i.z.boolean().optional()}).transform(({key:t,includeStatus:e})=>({keys:[t],includeStatus:e})),bE=i.z.union([wE,mE]);let Zu=class{client;constructor(e){this.client=e}async retrieve(e){const r=typeof e=="object"&&"key"in e,n=await w(this.client,uE,e,bE,gE);ce("Device",e,n.devices,r);const s=n.devices;return r?s[0]:s}async create(e){const r=!Array.isArray(e),s=(await w(this.client,lE,{devices:T.toArray(e)},fE,dE)).devices;return r?s[0]:s}async delete(e){await w(this.client,hE,{keys:T.toArray(e)},pE,yE)}};const vE=t=>({type:"device",key:t}),TE=Object.freeze(Object.defineProperty({__proto__:null,Client:Zu,DELETE_CHANNEL_NAME:oE,SET_CHANNEL_NAME:aE,STATUS_CHANNEL_NAME:cE,deviceZ:un,keyZ:Zt,newZ:xu,ontologyID:vE,statusDetailsSchema:ku,statusZ:Au},Symbol.toStringTag,{value:"Module"})),zE="/hardware/rack/retrieve",EE="/hardware/rack/create",NE="/hardware/rack/delete",OE="sy_rack_status",$E="sy_rack_set",SE="sy_rack_delete",IE=i.z.object({keys:ve.array().optional(),names:i.z.string().array().optional(),searchTerm:i.z.string().optional(),embedded:i.z.boolean().optional(),hostIsNode:i.z.boolean().optional(),limit:i.z.number().optional(),offset:i.z.number().optional(),includeStatus:i.z.boolean().optional()}),kE=i.z.object({racks:T.nullableZ(cn)}),AE=i.z.union([i.z.object({key:ve,includeStatus:i.z.boolean().optional()}).transform(({key:t,includeStatus:e})=>({keys:[t],includeStatus:e})),i.z.object({name:i.z.string(),includeStatus:i.z.boolean().optional()}).transform(({name:t,includeStatus:e})=>({names:[t],includeStatus:e}))]),xE=IE,ZE=i.z.union([AE,xE]),CE=i.z.object({racks:Su.array()}),RE=i.z.object({racks:cn.array()}),_E=i.z.object({keys:ve.array()}),jE=i.z.object({});let Cu=class{client;tasks;constructor(e,r){this.client=e,this.tasks=r}async delete(e){await w(this.client,NE,{keys:T.toArray(e)},_E,jE)}async create(e){const r=!Array.isArray(e),n=await w(this.client,EE,{racks:T.toArray(e)},CE,RE),s=this.sugar(n.racks);return r?s[0]:s}async retrieve(e){const r="key"in e||"name"in e,n=await w(this.client,zE,e,ZE,kE),s=this.sugar(n.racks);return ce("Rack",e,s,r),r?s[0]:s}sugar(e){const r=!Array.isArray(e),n=T.toArray(e).map(({key:s,name:a,status:o})=>new Ru(s,a,this.tasks,o));return r?n[0]:n}};class Ru{key;name;status;tasks;constructor(e,r,n,s){this.key=e,this.name=r,this.tasks=n,this.status=s}async listTasks(){return await this.tasks.retrieve({rack:this.key})}async createTask(e,r){return e.key=((BigInt(this.key)<<32n)+(BigInt(e.key??0)&0xffffffffn)).toString(),await this.tasks.create(e,r)}async deleteTask(e){await this.tasks.delete([e])}get payload(){return{key:this.key,name:this.name,status:this.status}}}const ME=t=>({type:"rack",key:t.toString()}),DE=Object.freeze(Object.defineProperty({__proto__:null,Client:Cu,DELETE_CHANNEL_NAME:SE,Rack:Ru,SET_CHANNEL_NAME:$E,STATUS_CHANNEL_NAME:OE,keyZ:ve,newZ:Su,ontologyID:ME,rackZ:cn,statusDetailsSchema:Ou,statusZ:$u},Symbol.toStringTag,{value:"Module"})),Ce=i.z.union([i.z.string(),i.z.bigint().transform(t=>t.toString()),i.z.number().transform(t=>t.toString())]),_u=t=>i.z.object({task:Ce,running:i.z.boolean(),data:t}),Js=t=>It.statusZ(_u(t)),fr=(t={typeSchema:i.z.string(),configSchema:i.z.unknown(),statusDataSchema:i.z.unknown()})=>i.z.object({key:Ce,name:i.z.string(),type:t.typeSchema,internal:i.z.boolean().optional(),config:i.z.string().transform(Iu).or(t.configSchema),status:Js(t.statusDataSchema).optional().nullable(),snapshot:i.z.boolean().optional()}),ju=t=>fr(t).omit({key:!0}).extend({key:Ce.transform(e=>e.toString()).optional(),config:i.z.unknown().transform(e=>st.JSON_CODEC.encodeString(e))}),PE=i.z.object({task:Ce,type:i.z.string(),key:i.z.string(),args:be.unknownZ.or(i.z.string().transform(Ie)).or(i.z.array(i.z.unknown())).or(i.z.null()).optional()}),UE=t=>Number(BigInt(t)>>32n),fs="sy_task_status",ds="sy_task_cmd",LE="sy_task_set",BE="sy_task_delete",Xe=new Error("Task not created"),Mu=async(t,e)=>{const r=await e.retrieveParents(Ks(t));return r.length===0?null:r[0]};class Du{key;name;internal;type;snapshot;config;status;schemas;frameClient_;ontologyClient_;rangeClient_;get frameClient(){if(this.frameClient_==null)throw Xe;return this.frameClient_}get ontologyClient(){if(this.ontologyClient_==null)throw Xe;return this.ontologyClient_}get rangeClient(){if(this.rangeClient_==null)throw Xe;return this.rangeClient_}constructor({key:e,type:r,name:n,config:s,internal:a=!1,snapshot:o=!1,status:c},l,u,h,d){this.key=e,this.name=n,this.type=r,this.config=s,this.schemas=l??{typeSchema:i.z.string(),configSchema:i.z.unknown(),statusDataSchema:i.z.unknown()},this.internal=a,this.snapshot=o,this.status=c,this.frameClient_=u,this.ontologyClient_=h,this.rangeClient_=d}get payload(){return{key:this.key,name:this.name,type:this.type,config:this.config,status:this.status,internal:this.internal}}get ontologyID(){return Ks(this.key)}async executeCommand(e){return await Lu({...e,frameClient:this.frameClient,task:this.key})}async executeCommandSync(e){return await Bu({...e,frameClient:this.frameClient,task:this.key,name:this.name,statusDataZ:this.schemas?.statusDataSchema})}async snapshottedTo(){if(this.ontologyClient==null||this.rangeClient==null)throw Xe;return this.snapshot?await Mu(this.key,this.ontologyClient):null}}const qE=i.z.object({rack:ve.optional(),keys:Ce.array().optional(),names:i.z.string().array().optional(),types:i.z.string().array().optional(),includeStatus:i.z.boolean().optional(),searchTerm:i.z.string().optional(),offset:i.z.number().optional(),limit:i.z.number().optional()}),Pu=i.z.union([i.z.object({key:Ce,includeStatus:i.z.boolean().optional()}).transform(({key:t,includeStatus:e})=>({keys:[t],includeStatus:e})),i.z.object({name:i.z.string(),includeStatus:i.z.boolean().optional()}).transform(({name:t,includeStatus:e})=>({names:[t],includeStatus:e})),i.z.object({type:i.z.string(),rack:ve.optional()}).transform(({type:t,rack:e})=>({types:[t],rack:e}))]),FE=qE,VE=i.z.union([Pu,FE]),YE=t=>i.z.object({tasks:T.nullableZ(fr(t))}),WE="/hardware/task/retrieve",HE="/hardware/task/create",GE="/hardware/task/delete",JE="/hardware/task/copy",KE=t=>i.z.object({tasks:ju(t).array()}),XE=t=>i.z.object({tasks:fr(t).array()}),QE=i.z.object({keys:Ce.array()}),eN=i.z.object({}),tN=i.z.object({key:Ce,name:i.z.string(),snapshot:i.z.boolean()}),rN=t=>i.z.object({task:fr(t)});let Uu=class{type="task";client;frameClient;ontologyClient;rangeClient;constructor(e,r,n,s){this.client=e,this.frameClient=r,this.ontologyClient=n,this.rangeClient=s}async create(e,r){const n=!Array.isArray(e),s=KE(r),a=XE(r),o=await w(this.client,HE,{tasks:T.toArray(e)},s,a),c=this.sugar(o.tasks,r);return n?c[0]:c}async delete(e){await w(this.client,GE,{keys:T.toArray(e)},QE,eN)}async retrieve({schemas:e,...r}){const n=Pu.safeParse(r).success,a=(await w(this.client,WE,r,VE,YE(e))).tasks,o=this.sugar(a,e);return ce("Task",r,o,n),n?o[0]:o}async copy(e,r,n){const s=rN(),a=await w(this.client,JE,{key:e,name:r,snapshot:n},tN,s);return this.sugar(a.task)}async retrieveSnapshottedTo(e){if(this.ontologyClient==null)throw Xe;return await Mu(e,this.ontologyClient)}sugar(e,r){const n=!Array.isArray(e),s=T.toArray(e).map(({key:a,name:o,type:c,config:l,status:u,internal:h,snapshot:d})=>new Du({key:a,name:o,type:c,config:l,internal:h,snapshot:d,status:u},r,this.frameClient,this.ontologyClient,this.rangeClient));return n?s[0]:s}async executeCommand(e){return"commands"in e?await Xs({...e,frameClient:this.frameClient}):await Lu({...e,frameClient:this.frameClient})}async executeCommandSync(e){if("commands"in e){const n=async()=>{const{commands:s}=e;return(await this.retrieve({keys:s.map(o=>o.task)})).map(o=>o.name)};return await qu({...e,frameClient:this.frameClient,name:n})}const r=async()=>{const{task:n}=e;return(await this.retrieve({key:n})).name};return await Bu({frameClient:this.frameClient,name:r,...e})}};const Ks=t=>({type:"task",key:t}),Lu=async({frameClient:t,task:e,type:r,args:n})=>(await Xs({frameClient:t,commands:[{args:n,task:e,type:r}]}))[0],Xs=async({frameClient:t,commands:e})=>{if(t==null)throw Xe;const r=await t.openWriter(ds),n=e.map(s=>({...s,key:lp.create()}));return await r.write(ds,n),await r.close(),n.map(s=>s.key)},Bu=async({frameClient:t,task:e,type:r,timeout:n,name:s,statusDataZ:a,args:o})=>(await qu({frameClient:t,commands:[{args:o,task:e,type:r}],timeout:n,statusDataZ:a,name:s}))[0],qu=async({frameClient:t,commands:e,timeout:r=I.seconds(10),statusDataZ:n,name:s})=>{if(t==null)throw Xe;const a=await t.openStreamer(fs),o=await Xs({frameClient:t,commands:e}),c=new I(r);let l=[],u;const h=new Promise((d,f)=>{u=setTimeout(()=>{(async()=>{const v=e.map(S=>S.task);f(await nN("command",s,c,v))})()},c.milliseconds)});try{for(;;){const d=await Promise.race([a.read(),h]),f=Js(n).parse(d.at(-1)[fs]);if(o.includes(f.key)&&(l=[...l.filter(v=>v.key!==f.key),f],l.length===o.length))return l}}finally{clearTimeout(u),a.close()}},nN=async(t,e,r,n)=>{const s=Ff.capitalize(t),a=r.toString();try{let o;typeof e=="string"?o=[e]:Array.isArray(e)?o=e:o=T.toArray(await e());const c=ts.naturalLanguageJoin(o);return new Error(`${s} command to ${c} timed out after ${a}`)}catch(o){return console.error("Failed to retrieve task name for timeout error:",o),new Error(`${s} command to task with key ${ts.naturalLanguageJoin(n)} timed out after ${a}`)}},sN=Object.freeze(Object.defineProperty({__proto__:null,COMMAND_CHANNEL_NAME:ds,Client:Uu,DELETE_CHANNEL_NAME:BE,SET_CHANNEL_NAME:LE,STATUS_CHANNEL_NAME:fs,Task:Du,commandZ:PE,keyZ:Ce,newZ:ju,ontologyID:Ks,rackKey:UE,statusDetailsZ:_u,statusZ:Js,taskZ:fr},Symbol.toStringTag,{value:"Module"})),He=Qo.keyZ,dr=Qo.labelZ,iN="labeled_by",aN="sy_label_set",oN="sy_label_delete",Fu=dr.extend({key:He.optional()}),cN=i.object({labels:Fu.array()}),uN=i.object({labels:dr.array()}),lN=i.object({keys:He.array()}),Vu=i.object({id:j,labels:He.array(),replace:i.boolean().optional()}),hN=Vu.omit({replace:!0}),An=i.object({}),fN="/label/create",dN="/label/delete",pN="/label/set",yN="/label/remove",mN="/label/retrieve",gN=i.object({keys:He.array().optional(),for:j.optional(),searchTerm:i.string().optional(),offset:i.number().optional(),limit:i.number().optional()}),wN=i.object({key:He}).transform(({key:t})=>({keys:[t]})),bN=i.union([wN,gN]),vN=i.object({labels:T.nullableZ(dr)});let Yu=class{type="label";client;constructor(e){this.client=e}async retrieve(e){const r="key"in e,n=await w(this.client,mN,e,bN,vN);return ce("Label",e,n.labels,r),r?n.labels[0]:n.labels}async label(e,r,n={}){await w(this.client,pN,{id:e,labels:r,replace:n.replace},Vu,An)}async remove(e,r){await w(this.client,yN,{id:e,labels:r},hN,An)}async create(e){const r=Array.isArray(e),n=await w(this.client,fN,{labels:T.toArray(e)},cN,uN);return r?n.labels:n.labels[0]}async delete(e){await w(this.client,dN,{keys:T.toArray(e)},lN,An)}};const TN=t=>({type:"label",key:t}),zN=Object.freeze(Object.defineProperty({__proto__:null,Client:Yu,DELETE_CHANNEL_NAME:oN,LABELED_BY_ONTOLOGY_RELATIONSHIP_TYPE:iN,SET_CHANNEL_NAME:aN,keyZ:He,labelZ:dr,newZ:Fu,ontologyID:TN},Symbol.toStringTag,{value:"Module"})),ee=i.z.uuid(),Qs=i.z.string().min(1),pr=i.z.object({key:ee,name:Qs,timeRange:P.z.refine(({isValid:t})=>t,{error:"Time range start time must be before or equal to time range end time"}).refine(({end:t})=>t.valueOf()<=Kn.MAX_INT64,{error:"Time range end time must be less than or equal to the maximum value of an int64"}).refine(({start:t})=>t.valueOf()>=Kn.MIN_INT64,{error:"Time range start time must be greater than or equal to the minimum value of an int64"}),color:i.z.string().optional(),labels:dr.array().or(i.z.null().transform(()=>{})).optional(),get parent(){return pr.optional().nullable().transform(t=>t===void 0?null:t)}}),Wu=pr.omit({parent:!0,labels:!0}).partial({key:!0}),EN="sy_range_alias_set",NN="sy_range_alias_delete",ON=i.z.object({range:ee,aliases:i.z.string().array()}),$N=i.z.object({aliases:i.z.record(i.z.string(),D)}),SN=i.z.object({range:ee,aliases:i.z.record(D,i.z.string())}),IN=i.z.unknown(),kN=i.z.object({range:ee,channels:D.array()}),AN=i.z.unknown(),xN=i.z.object({range:ee}),ZN=i.z.object({aliases:i.z.record(i.z.string(),i.z.string())}),CN=i.z.object({range:ee,channels:D.array()}),RN=i.z.object({aliases:i.z.record(i.z.string(),i.z.string())});class oe{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,r,n){this.rangeKey=e,this.cache=new Map,this.client=n,this.frameClient=r}async resolve(e){const r=[],n=typeof e=="string",s={};if(n){const o=this.cache.get(e);if(o!=null)return o;r.push(e)}else e.forEach(o=>{const c=this.cache.get(o);c!=null?s[o]=c:r.push(o)});if(r.length===0)return s;const a=await w(this.client,oe.RESOLVE_ENDPOINT,{range:this.rangeKey,aliases:r},ON,$N);return Object.entries(a.aliases).forEach(([o,c])=>this.cache.set(o,c)),n?a.aliases[r[0]]:{...s,...a.aliases}}async set(e){await w(this.client,oe.SET_ENDPOINT,{range:this.rangeKey,aliases:e},SN,IN)}async list(){return(await w(this.client,oe.LIST_ENDPOINT,{range:this.rangeKey},xN,ZN)).aliases}async retrieve(e){const r=typeof e=="number",n=await w(this.client,oe.RETRIEVE_ENDPOINT,{range:this.rangeKey,channels:T.toArray(e)},CN,RN);return r?n.aliases[e]:n.aliases}async delete(e){await w(this.client,oe.DELETE_ENDPOINT,{range:this.rangeKey,channels:T.toArray(e)},kN,AN)}}const _N=i.z.object({alias:i.z.string().optional(),channel:D,range:ee}),Hu="---",jN=t=>`${t.range}${Hu}${t.channel}`,MN=t=>{const[e,r]=t.split(Hu);return{range:e,channel:Number(r)}},DN="sy_range_kv_set",PN="sy_range_kv_delete",ei=i.z.object({range:ee,key:i.z.string(),value:i.z.string()}),UN=({range:t,key:e})=>`${t}<--->${e}`,LN=i.z.object({range:ee,keys:i.z.string().array()}),BN=i.z.object({pairs:T.nullableZ(ei)}),qN=i.z.object({range:ee,pairs:ei.array()}),FN=i.z.object({range:ee,keys:i.z.string().array()});class et{static GET_ENDPOINT="/range/kv/get";static SET_ENDPOINT="/range/kv/set";static DELETE_ENDPOINT="/range/kv/delete";rangeKey;client;constructor(e,r){this.rangeKey=e,this.client=r}async get(e){const r=await w(this.client,et.GET_ENDPOINT,{range:this.rangeKey,keys:T.toArray(e)},LN,BN);return typeof e=="string"?r.pairs[0].value:Object.fromEntries(r.pairs.map(n=>[n.key,n.value]))}async list(){return this.get([])}async set(e,r=""){let n;Va(e)?n=Object.entries(e).map(([s,a])=>({range:this.rangeKey,key:s,value:a})):n=[{range:this.rangeKey,key:e,value:r}],await w(this.client,et.SET_ENDPOINT,{range:this.rangeKey,pairs:n},qN,i.z.unknown())}async delete(e){await w(this.client,et.DELETE_ENDPOINT,{range:this.rangeKey,keys:T.toArray(e)},FN,i.z.unknown())}}const VN="sy_range_set",YN="sy_range_delete";class Gu{key;name;kv;timeRange;color;parent;labels;channels;aliaser;frameClient;labelClient;ontologyClient;rangeClient;constructor({name:e,timeRange:r=P.ZERO,key:n,color:s,parent:a,labels:o},{frameClient:c,kv:l,aliaser:u,channels:h,labelClient:d,ontologyClient:f,rangeClient:v}){this.key=n,this.name=e,this.timeRange=r,this.parent=a,this.labels=o,this.frameClient=c,this.color=s,this.kv=l,this.aliaser=u,this.channels=h,this.labelClient=d,this.ontologyClient=f,this.rangeClient=v}get ontologyID(){return pt(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,r){const n=await this.channels.retrieve(e);if(n.length===0)throw new Fe(`Channel ${e} does not exist`);await this.aliaser.set({[n[0].key]:r})}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(r=>r.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:pt(this.key)})}async addLabel(...e){await this.labelClient.label(pt(this.key),e)}async removeLabel(...e){await this.labelClient.remove(pt(this.key),e)}static sort(e,r){return P.sort(e.timeRange,r.timeRange)}}const WN=i.z.object({keys:ee.array().optional(),names:i.z.array(i.z.string()).optional(),searchTerm:i.z.string().optional(),overlapsWith:P.z.optional(),limit:i.z.number().int().optional(),offset:i.z.number().int().optional(),hasLabels:He.array().optional(),includeLabels:i.z.boolean().optional(),includeParent:i.z.boolean().optional()}),HN=WN.or(ee.array().transform(t=>({keys:t}))).or(ee.transform(t=>({keys:[t]}))).or(i.z.string().transform(t=>({names:[t]}))).or(i.z.string().array().transform(t=>({names:t}))).or(P.z.transform(t=>({overlapsWith:t}))),GN="/range/retrieve",JN=i.z.object({ranges:T.nullableZ(pr)});let Ju=class{type="range";frameClient;writer;unaryClient;channels;labelClient;ontologyClient;constructor(e,r,n,s,a,o){this.frameClient=e,this.writer=r,this.unaryClient=n,this.channels=s,this.labelClient=a,this.ontologyClient=o}async create(e,r){const n=!Array.isArray(e),s=this.sugarMany(await this.writer.create(T.toArray(e),r));return n?s[0]:s}async rename(e,r){await this.writer.rename(e,r)}async delete(e){await this.writer.delete(T.toArray(e))}async retrieve(e){const r=typeof e=="string",{ranges:n}=await w(this.unaryClient,GN,e,HN,JN);return ce("Range",e,n,r),r?this.sugarMany(n)[0]:this.sugarMany(n)}getKV(e){return new et(e,this.unaryClient)}async retrieveParent(e){const r=await this.ontologyClient.retrieveParents(pt(e));if(r.length===0)return null;const n=r[0];return n.id.type!=="range"?null:await this.retrieve(n.id.key)}sugarOntologyResource(e){return this.sugarOne(Ku(e))}async retrieveAlias(e,r){return await new oe(e,this.frameClient,this.unaryClient).retrieve(r)}async retrieveAliases(e,r){return await new oe(e,this.frameClient,this.unaryClient).retrieve(r)}async listAliases(e){return await new oe(e,this.frameClient,this.unaryClient).list()}async setAlias(e,r,n){await new oe(e,this.frameClient,this.unaryClient).set({[r]:n})}async deleteAlias(e,r){await new oe(e,this.frameClient,this.unaryClient).delete(r)}sugarOne(e){return new Gu(e,{frameClient:this.frameClient,kv:new et(e.key,this.unaryClient),aliaser:new oe(e.key,this.frameClient,this.unaryClient),channels:this.channels,labelClient:this.labelClient,ontologyClient:this.ontologyClient,rangeClient:this})}sugarMany(e){return e.map(r=>this.sugarOne(r))}resourceToRange(e){return this.sugarOne({key:e.id.key,name:e.data?.name,timeRange:new P(e.data?.timeRange),color:e.data?.color,labels:[],parent:null})}};const pt=t=>({type:"range",key:t}),KN=t=>({type:"range-alias",key:t}),Ku=({data:t,id:{key:e},name:r})=>{const n=P.z.parse(t?.timeRange);return{key:e,name:r,timeRange:n,color:typeof t?.color=="string"?t.color:void 0,labels:[],parent:null}},XN=i.z.object({ranges:pr.array()}),QN=i.z.object({parent:j.optional(),ranges:Wu.array()}),eO=i.z.object({keys:ee.array()}),tO=i.z.object({}),rO=i.z.object({key:ee,name:Qs}),nO=i.z.object({}),sO="/range/create",iO="/range/delete",aO="/range/rename";class Xu{client;constructor(e){this.client=e}async rename(e,r){await w(this.client,aO,{key:e,name:r},rO,nO)}async create(e,r){return(await w(this.client,sO,{ranges:e,...r},QN,XN)).ranges}async delete(e){await w(this.client,iO,{keys:e},eO,tO)}}const oO=Object.freeze(Object.defineProperty({__proto__:null,Aliaser:oe,Client:Ju,DELETE_ALIAS_CHANNEL_NAME:NN,DELETE_CHANNEL_NAME:YN,KV:et,KV_DELETE_CHANNEL:PN,KV_SET_CHANNEL:DN,Range:Gu,SET_ALIAS_CHANNEL_NAME:EN,SET_CHANNEL_NAME:VN,Writer:Xu,aliasKey:jN,aliasOntologyID:KN,aliasZ:_N,convertOntologyResourceToPayload:Ku,decodeDeleteAliasChange:MN,keyZ:ee,kvPairKey:UN,kvPairZ:ei,nameZ:Qs,newZ:Wu,ontologyID:pt,payloadZ:pr},Symbol.toStringTag,{value:"Module"})),ln=i.z.string(),hn=It.statusZ,Qu=t=>hn(t).omit({labels:!0}).partial({key:!0}),cO="sy_status_set",uO="sy_status_delete",lO=t=>({type:"status",key:t}),hO=t=>i.object({parent:j.optional(),statuses:Qu(t).array()}),fO=t=>i.object({statuses:hn(t).array()}),dO=i.object({keys:ln.array()}),pO=i.object({}),yO="/status/set",mO="/status/delete",gO="/status/retrieve",wO=i.object({keys:ln.array().optional(),searchTerm:i.string().optional(),offset:i.number().optional(),limit:i.number().optional(),includeLabels:i.boolean().optional(),hasLabels:He.array().optional()}),bO=i.object({key:ln,includeLabels:i.boolean().optional()}).transform(({key:t,includeLabels:e})=>({keys:[t],includeLabels:e})),vO=i.union([bO,wO]),TO=t=>i.object({statuses:T.nullableZ(hn(t))});let el=class{type="status";client;constructor(e){this.client=e}async retrieve(e){const r="key"in e,n=await w(this.client,gO,e,vO,TO(e.detailsSchema));ce("Status",e,n.statuses,r);const s=n.statuses;return r?s[0]:s}async set(e,r={}){const n=Array.isArray(e),a=(await w(this.client,yO,{statuses:T.toArray(e),parent:r.parent},hO(r.detailsSchema),fO(r.detailsSchema))).statuses;return n?a:a[0]}async delete(e){await w(this.client,mO,{keys:T.toArray(e)},dO,pO)}};const zO=Object.freeze(Object.defineProperty({__proto__:null,Client:el,DELETE_CHANNEL_NAME:uO,SET_CHANNEL_NAME:cO,keyZ:ln,newZ:Qu,ontologyID:lO,statusZ:hn},Symbol.toStringTag,{value:"Module"})),EO="/api/v1/";class NO{url;unary;stream;secure;constructor(e,r={},n=!1){this.secure=n,this.url=e.child(EO);const s=new st.JSONCodec;this.unary=Sf(new $f(this.url,s,this.secure),r),this.stream=new Zf(this.url,s,this.secure)}use(...e){this.unary.use(...e),this.stream.use(...e)}}const at=i.z.uuid(),fn=i.z.object({key:at,name:i.z.string(),data:be.unknownZ.or(i.z.string().transform(Ie))}),tl=fn.partial({key:!0}).transform(t=>({...t,data:JSON.stringify(t.data)})),ke=i.z.uuid(),dn=i.z.object({key:ke,name:i.z.string().min(1,"Name is required"),layout:be.unknownZ.or(i.z.string().transform(Ie))}),rl=dn.partial({key:!0}).transform(t=>({...t,layout:JSON.stringify(t.layout)})),nl=dn.omit({layout:!0}).extend({layout:i.z.string().transform(Ie)}),OO="/workspace/lineplot/retrieve",$O="/workspace/lineplot/create",SO="/workspace/lineplot/rename",IO="/workspace/lineplot/set-data",kO="/workspace/lineplot/delete",AO=i.z.object({key:at,name:i.z.string()}),xO=i.z.object({key:at,data:i.z.string()}),ZO=i.z.object({keys:at.array()}),CO=i.z.object({keys:at.array()}),sl=i.z.object({key:at}).transform(({key:t})=>({keys:[t]})),il=i.z.union([sl,CO]),RO=i.z.object({linePlots:T.nullableZ(fn)}),_O=i.z.object({workspace:ke,linePlots:tl.array()}),jO=i.z.object({linePlots:fn.array()}),xn=i.z.object({});let al=class{client;constructor(e){this.client=e}async create(e,r){const n=Array.isArray(r),s=await w(this.client,$O,{workspace:e,linePlots:T.toArray(r)},_O,jO);return n?s.linePlots:s.linePlots[0]}async rename(e,r){await w(this.client,SO,{key:e,name:r},AO,xn)}async setData(e,r){await w(this.client,IO,{key:e,data:JSON.stringify(r)},xO,xn)}async retrieve(e){const r=sl.safeParse(e).success,n=await w(this.client,OO,e,il,RO);return ce("LinePlot",e,n.linePlots,r),r?n.linePlots[0]:n.linePlots}async delete(e){await w(this.client,kO,{keys:T.toArray(e)},ZO,xn)}};const MO=t=>({type:"lineplot",key:t}),DO=Object.freeze(Object.defineProperty({__proto__:null,Client:al,keyZ:at,linePlotZ:fn,newZ:tl,ontologyID:MO,retrieveArgsZ:il},Symbol.toStringTag,{value:"Module"})),ot=i.z.uuid(),pn=i.z.object({key:ot,name:i.z.string(),data:be.unknownZ.or(i.z.string().transform(Ie))}),ol=pn.partial({key:!0}).transform(t=>({...t,data:JSON.stringify(t.data)})),PO="/workspace/log/retrieve",UO="/workspace/log/create",LO="/workspace/log/rename",BO="/workspace/log/set-data",qO="/workspace/log/delete",FO=i.z.object({key:ot,name:i.z.string()}),VO=i.z.object({key:ot,data:i.z.string()}),YO=i.z.object({keys:ot.array()}),WO=i.z.object({keys:ot.array()}),cl=i.z.object({key:ot}).transform(({key:t})=>({keys:[t]})),ul=i.z.union([cl,WO]),HO=i.z.object({logs:T.nullableZ(pn)}),GO=i.z.object({workspace:ke,logs:ol.array()}),JO=i.z.object({logs:pn.array()}),Zn=i.z.object({});let ll=class{client;constructor(e){this.client=e}async create(e,r){const n=Array.isArray(r),s=await w(this.client,UO,{workspace:e,logs:T.toArray(r)},GO,JO);return n?s.logs:s.logs[0]}async rename(e,r){await w(this.client,LO,{key:e,name:r},FO,Zn)}async setData(e,r){await w(this.client,BO,{key:e,data:JSON.stringify(r)},VO,Zn)}async retrieve(e){const r=cl.safeParse(e).success,n=await w(this.client,PO,e,ul,HO);return ce("Log",e,n.logs,r),r?n.logs[0]:n.logs}async delete(e){await w(this.client,qO,{keys:T.toArray(e)},YO,Zn)}};const KO=t=>({type:"log",key:t}),XO=Object.freeze(Object.defineProperty({__proto__:null,Client:ll,keyZ:ot,logZ:pn,newZ:ol,ontologyID:KO,retrieveArgsZ:ul},Symbol.toStringTag,{value:"Module"})),Ge=i.z.uuid(),yn=i.z.object({key:Ge,name:i.z.string(),data:be.unknownZ.or(i.z.string().transform(Ie)),snapshot:i.z.boolean()}),hl=yn.partial({key:!0,snapshot:!0}).transform(t=>({...t,data:JSON.stringify(t.data)})),ti=yn.extend({data:i.z.string().transform(Ie)}),Ct=i.z.uuid(),fl=i.z.object({key:i.z.string(),name:i.z.string(),selectors:i.z.string().array().default([]),strokeColor:i.z.string().optional(),fillColor:i.z.string().optional()}),dl=i.z.object({key:i.z.string(),name:i.z.string(),regions:fl.array()}),pl=i.z.object({key:i.z.string(),position:Is.xy,orientation:_d.outer}),QO=i.z.object({zoom:i.z.number().positive().default(1),position:Is.xy}),yl=i.z.object({svg:i.z.string().min(1,"SVG is required"),states:dl.array(),variant:i.z.string().min(1,"Variant is required"),handles:pl.array(),scale:i.z.number().positive().default(1),scaleStroke:i.z.boolean().default(!1),previewViewport:QO.default({zoom:1,position:{x:0,y:0}})}),mn=i.z.object({key:Ct,version:i.z.literal(1).optional().default(1),name:i.z.string().min(1,"Name is required"),data:yl}),ml=mn.partial({key:!0}),e$="/workspace/schematic/symbol/retrieve",t$="/workspace/schematic/symbol/create",r$="/workspace/schematic/symbol/rename",n$="/workspace/schematic/symbol/delete",s$="/workspace/schematic/symbol/retrieve_group",i$=i.z.object({symbols:ml.array(),parent:j}),a$=i.z.object({key:Ct,name:i.z.string()}),o$=i.z.object({keys:Ct.array()}),c$=i.z.object({keys:Ct.array().optional(),searchTerm:i.z.string().optional(),offset:i.z.number().optional(),limit:i.z.number().optional()}),u$=i.z.object({key:Ct}).transform(({key:t})=>({keys:[t]})),l$=i.z.union([u$,c$]),h$=i.z.object({symbols:T.nullableZ(mn)}),f$=i.z.object({symbols:mn.array()}),ha=i.z.object({}),d$=i.z.object({}),p$=i.z.object({group:Gr}),y$="sy_schematic_symbol_set",m$="sy_schematic_symbol_delete";let gl=class{client;constructor(e){this.client=e}async create(e){const r="symbols"in e,n=r?e.symbols:[e],s=await w(this.client,t$,{symbols:n,parent:e.parent},i$,f$);return r?s.symbols:s.symbols[0]}async rename(e,r){await w(this.client,r$,{key:e,name:r},a$,ha)}async retrieve(e){const r="key"in e,n=await w(this.client,e$,e,l$,h$);return ce("Schematic Symbol",e,n.symbols,r),r?n.symbols[0]:n.symbols}async delete(e){await w(this.client,n$,{keys:T.toArray(e)},o$,ha)}async retrieveGroup(){return(await w(this.client,s$,{},d$,p$)).group}};const g$=t=>({type:"schematic_symbol",key:t}),w$=Object.freeze(Object.defineProperty({__proto__:null,Client:gl,DELETE_CHANNEL_NAME:m$,SET_CHANNEL_NAME:y$,handleZ:pl,keyZ:Ct,newZ:ml,ontologyID:g$,regionZ:fl,specZ:yl,stateZ:dl,symbolZ:mn},Symbol.toStringTag,{value:"Module"})),b$="/workspace/schematic/retrieve",v$="/workspace/schematic/create",T$="/workspace/schematic/rename",z$="/workspace/schematic/set-data",E$="/workspace/schematic/delete",N$="/workspace/schematic/copy",O$=i.z.object({key:Ge,name:i.z.string()}),$$=i.z.object({key:Ge,data:i.z.string()}),S$=i.z.object({keys:Ge.array()}),I$=i.z.object({key:Ge,name:i.z.string(),snapshot:i.z.boolean()}),k$=i.z.object({keys:Ge.array()}),wl=i.z.object({key:Ge}).transform(({key:t})=>({keys:[t]})),bl=i.z.union([wl,k$]),A$=i.z.object({schematics:T.nullableZ(ti)}),x$=i.z.object({workspace:ke,schematics:hl.array()}),Z$=i.z.object({schematics:ti.array()}),C$=i.z.object({schematic:yn}),Cn=i.z.object({});let vl=class{symbols;client;constructor(e){this.client=e,this.symbols=new gl(e)}async create(e,r){const n=Array.isArray(r),s=await w(this.client,v$,{workspace:e,schematics:T.toArray(r)},x$,Z$);return n?s.schematics:s.schematics[0]}async rename(e,r){await w(this.client,T$,{key:e,name:r},O$,Cn)}async setData(e,r){await w(this.client,z$,{key:e,data:JSON.stringify(r)},$$,Cn)}async retrieve(e){const r=wl.safeParse(e).success,n=await w(this.client,b$,e,bl,A$);return ce("Schematic",e,n.schematics,r),r?n.schematics[0]:n.schematics}async delete(e){await w(this.client,E$,{keys:T.toArray(e)},S$,Cn)}async copy(e){return(await w(this.client,N$,e,I$,C$)).schematic}};const R$=t=>({type:"schematic",key:t}),_$=Object.freeze(Object.defineProperty({__proto__:null,Client:vl,keyZ:Ge,newZ:hl,ontologyID:R$,remoteZ:ti,retrieveArgsZ:bl,schematicZ:yn,symbol:w$},Symbol.toStringTag,{value:"Module"})),ct=i.z.uuid(),ri=i.z.object({key:ct,name:i.z.string(),data:be.unknownZ.or(i.z.string().transform(Ie))}),Tl=ri.partial({key:!0}).transform(t=>({...t,data:JSON.stringify(t.data)})),ni=ri.extend({data:i.z.string().transform(Ie)}),j$="/workspace/table/retrieve",M$="/workspace/table/create",D$="/workspace/table/rename",P$="/workspace/table/set-data",U$="/workspace/table/delete",L$=i.z.object({key:ct,name:i.z.string()}),B$=i.z.object({key:ct,data:i.z.string()}),q$=i.z.object({keys:ct.array()}),F$=i.z.object({keys:ct.array()}),zl=i.z.object({key:ct}).transform(({key:t})=>({keys:[t]})),El=i.z.union([zl,F$]),V$=i.z.object({tables:T.nullableZ(ni)}),Y$=i.z.object({workspace:ke,tables:Tl.array()}),W$=i.z.object({tables:ni.array()}),Rn=i.z.object({});let Nl=class{client;constructor(e){this.client=e}async create(e,r){const n=Array.isArray(r),s=await w(this.client,M$,{workspace:e,tables:T.toArray(r)},Y$,W$);return n?s.tables:s.tables[0]}async rename(e,r){await w(this.client,D$,{key:e,name:r},L$,Rn)}async setData(e,r){await w(this.client,P$,{key:e,data:JSON.stringify(r)},B$,Rn)}async retrieve(e){const r=zl.safeParse(e).success,n=await w(this.client,j$,e,El,V$);return ce("Table",e,n.tables,r),r?n.tables[0]:n.tables}async delete(e){await w(this.client,U$,{keys:T.toArray(e)},q$,Rn)}};const H$=t=>({type:"table",key:t}),G$=Object.freeze(Object.defineProperty({__proto__:null,Client:Nl,keyZ:ct,newZ:Tl,ontologyID:H$,remoteZ:ni,retrieveArgsZ:El,tableZ:ri},Symbol.toStringTag,{value:"Module"})),fa="/workspace/retrieve",J$="/workspace/create",K$="/workspace/rename",X$="/workspace/set-layout",Q$="/workspace/delete",da=i.z.object({keys:ke.array().optional(),searchTerm:i.z.string().optional(),author:We.optional(),offset:i.z.number().optional(),limit:i.z.number().optional()}),eS=i.z.object({workspaces:rl.array()}),tS=i.z.object({key:ke,name:i.z.string()}),rS=i.z.object({key:ke,layout:be.unknownZ.transform(t=>JSON.stringify(t))}),nS=i.z.object({keys:ke.array()}),pa=i.z.object({workspaces:T.nullableZ(dn)}),sS=i.z.object({workspaces:nl.array()}),_n=i.z.object({}),iS="sy_workspace_set",aS="sy_workspace_delete";class Ol{schematics;lineplots;logs;tables;client;constructor(e){this.client=e,this.schematics=new vl(e),this.lineplots=new al(e),this.logs=new ll(e),this.tables=new Nl(e)}async create(e){const r=Array.isArray(e),n=await w(this.client,J$,{workspaces:T.toArray(e)},eS,sS);return r?n.workspaces:n.workspaces[0]}async rename(e,r){await w(this.client,K$,{key:e,name:r},tS,_n)}async setLayout(e,r){await w(this.client,X$,{key:e,layout:r},rS,_n)}async retrieve(e){let r;const n=typeof e!="string";typeof e=="string"||Array.isArray(e)?r={keys:T.toArray(e)}:r=e;const s=await w(this.client,fa,r,da,pa);return n?s.workspaces:s.workspaces[0]}async retrieveByAuthor(e){return(await w(this.client,fa,{author:e},da,pa)).workspaces}async delete(e){await w(this.client,Q$,{keys:T.toArray(e)},nS,_n)}}const oS=t=>({type:"workspace",key:t}),cS=Object.freeze(Object.defineProperty({__proto__:null,Client:Ol,DELETE_CHANNEL_NAME:aS,SET_CHANNEL_NAME:iS,keyZ:ke,newZ:rl,ontologyID:oS,remoteZ:nl,workspaceZ:dn},Symbol.toStringTag,{value:"Module"})),$l=i.z.object({host:i.z.string({error:"Host is required"}).min(1,"Host is required"),port:i.z.number({error:"Port is required"}).or(i.z.string({error:"Port is required"})),username:i.z.string().min(1,"Username is required"),password:i.z.string().min(1,"Password is required"),connectivityPollFrequency:I.z.default(I.seconds(30)),secure:i.z.boolean().optional().default(!1),name:i.z.string().optional(),retry:Do.breakerConfigZ.optional()});class Sl extends vu{createdAt;props;ranges;channels;auth;users;access;connectivity;ontology;workspaces;labels;statuses;hardware;control;arcs;static connectivity=Qt;transport;clientVersion="0.46.0";constructor(e){const r=$l.parse(e),{host:n,port:s,username:a,password:o,connectivityPollFrequency:c,secure:l,retry:u}=r,h=new NO(new Ut({host:n,port:Number(s)}),u,l);h.use(am);let d;a!=null&&o!=null&&(d=new Nz(h.unary,{username:a,password:o}),h.use(d.middleware()));const f=new Vs(new lr(h.unary)),v=new nu(h.unary,f);super(h.stream,h.unary,f),this.createdAt=p.now(),this.props=r,this.auth=d,this.transport=h,this.channels=new eu(this,f,h.unary,v),this.connectivity=new Qt(h.unary,c,this.clientVersion,r.name),this.control=new Eu(this),this.ontology=new dc(h.unary,this);const S=new Xu(this.transport.unary);this.labels=new Yu(this.transport.unary),this.statuses=new el(this.transport.unary),this.ranges=new Ju(this,S,this.transport.unary,f,this.labels,this.ontology),this.access=new mc(this.transport.unary),this.users=new iu(this.transport.unary),this.workspaces=new Ol(this.transport.unary);const Z=new Zu(this.transport.unary),b=new Uu(this.transport.unary,this,this.ontology,this.ranges),z=new Cu(this.transport.unary,b);this.hardware=new Nu(b,z,Z),this.arcs=new Hc(this.transport.unary)}get key(){return this.createdAt.valueOf().toString()}close(){this.connectivity.stopChecking()}}const Il={host:"localhost",port:9090,username:"synnax",password:"seldon",retry:{maxRetries:4,baseInterval:I.seconds(1),scale:1.5}},uS=t=>new Sl({...Il,...t});exports.AuthError=Wt;exports.Channel=Pr;exports.ContiguityError=nm;exports.DataType=R;exports.Density=Q;exports.DisconnectedError=rm;exports.Frame=W;exports.MultiSeries=_o;exports.MultipleFoundError=Gt;exports.NotFoundError=Ht;exports.QueryError=Fe;exports.Rate=re;exports.RouteError=ss;exports.Series=Ae;exports.Synnax=Sl;exports.TEST_CLIENT_PROPS=Il;exports.TimeRange=P;exports.TimeSpan=I;exports.TimeStamp=p;exports.UnexpectedError=gt;exports.ValidationError=Y;exports.access=Qm;exports.arc=OT;exports.channel=GT;exports.connection=$z;exports.control=sE;exports.createTestClient=uS;exports.device=TE;exports.framer=Xz;exports.group=Nm;exports.hardware=iE;exports.isCalculated=Xt;exports.label=zN;exports.lineplot=DO;exports.log=XO;exports.ontology=Mm;exports.policy=Xm;exports.rack=DE;exports.ranger=oO;exports.schematic=_$;exports.status=zO;exports.synnaxPropsZ=$l;exports.table=G$;exports.task=sN;exports.user=mz;exports.workspace=cS;
|