@synnaxlabs/pluto 0.33.1 → 0.33.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{Animated-CmYpn592.cjs → Animated-C7iWxEah.cjs} +1 -1
- package/dist/{Animated-BJ0Om9zo.js → Animated-VpxahF8t.js} +2 -2
- package/dist/{Item-CPt4Umh0.cjs → Item-C1_OE8IF.cjs} +1 -1
- package/dist/{Item-JN1-gBEw.js → Item-Dpra-3n6.js} +5 -5
- package/dist/{Keyboard-BwzZPKjx.cjs → Keyboard-BBOcinRN.cjs} +1 -1
- package/dist/{Keyboard-CBvQle7r.js → Keyboard-CpJQuX-J.js} +2 -2
- package/dist/LinePlot-Bwz2fEc0.cjs +34 -0
- package/dist/LinePlot-DHy70Cb7.js +6256 -0
- package/dist/{Link-my2OWRXu.js → Link-Ctlz9WUQ.js} +1 -1
- package/dist/{Link-mthAKDPf.cjs → Link-Cxj-3A6p.cjs} +1 -1
- package/dist/{List-C3bjnukf.cjs → List-CcTL6wlO.cjs} +1 -1
- package/dist/{List-B1BAwLaq.js → List-DF0kzXpr.js} +2 -2
- package/dist/{Pack-CxtceW7N.js → Pack-BAJwD-n2.js} +1 -1
- package/dist/{Pack-uflj5a28.cjs → Pack-DBtBeGnj.cjs} +1 -1
- package/dist/{Text-SLn1Qwzw.js → Text-D5o4o3OI.js} +5 -5
- package/dist/{Text-BvzGtwCB.cjs → Text-GGA7QNwA.cjs} +1 -1
- package/dist/{Toggle-CqrGlCW8.js → Toggle-CTjPdq8o.js} +953 -929
- package/dist/Toggle-Dim0E2D2.cjs +143 -0
- package/dist/{Video-DKosAU7v.cjs → Video-B3geSdOZ.cjs} +1 -1
- package/dist/{Video-o34bcpwh.js → Video-CXccd2Jl.js} +1 -1
- package/dist/{aggregator-CU9VgdUJ.cjs → aggregator-D6Mmsfj4.cjs} +21 -21
- package/dist/{aggregator-B36SA-20.js → aggregator-QFq5XDjf.js} +997 -961
- package/dist/align.cjs +1 -1
- package/dist/align.js +1 -1
- package/dist/button.cjs +1 -1
- package/dist/button.js +1 -1
- package/dist/color.cjs +1 -1
- package/dist/color.js +1 -1
- package/dist/{css-4MXuPP5v.cjs → css-CvXvQo39.cjs} +1 -1
- package/dist/{css-C8qHWSpT.js → css-DqBChhqm.js} +27 -5
- package/dist/css.cjs +1 -1
- package/dist/css.js +2 -2
- package/dist/dropdown.cjs +1 -1
- package/dist/dropdown.js +1 -1
- package/dist/ether.cjs +1 -1
- package/dist/ether.js +5 -5
- package/dist/{external-GxvuofB_.js → external-BNMsCMKL.js} +11 -11
- package/dist/{external-BLnPpmeS.cjs → external-BPnNv3RZ.cjs} +1 -1
- package/dist/{external-B5jyXhgU.cjs → external-BZpriFW_.cjs} +1 -1
- package/dist/{external-BvoBhRW8.cjs → external-Bksh4jhY.cjs} +1 -1
- package/dist/{external-euVgbl49.js → external-Bm3VKQxs.js} +4 -4
- package/dist/{external-D6YTf7Kx.cjs → external-C2YHV6Dz.cjs} +1 -1
- package/dist/{external-BT_oycNI.js → external-CI2s6wrc.js} +90 -88
- package/dist/external-CK8msIo3.js +96 -0
- package/dist/{external-DYwzKoQ6.js → external-CKp_fJJC.js} +2 -2
- package/dist/{external-Cb_NFNiX.cjs → external-CKuO-iHz.cjs} +1 -1
- package/dist/{external-Crturtt-.cjs → external-CUwDGrme.cjs} +1 -1
- package/dist/{external-B0o5Z8wI.js → external-CfOulkkd.js} +5 -5
- package/dist/{external-CPTY4-IY.cjs → external-ClRKAhnQ.cjs} +1 -1
- package/dist/{external-BKx-fjB8.js → external-Ct326ec4.js} +2 -2
- package/dist/{external-BTFW7AEo.js → external-DT1bMgJw.js} +2 -2
- package/dist/{external-C-xh9EwI.cjs → external-DYc6fMZC.cjs} +1 -1
- package/dist/external-Dhg4bEfF.cjs +1 -0
- package/dist/{external-Cewuz6Gm.js → external-DmLFwKtu.js} +4 -4
- package/dist/{external-DqwISR2q.js → external-DyAGPLil.js} +5 -5
- package/dist/{external-Cc1Bqjmm.js → external-EHlrAzYc.js} +1 -1
- package/dist/external-X9NMQ2Zh.cjs +1 -0
- package/dist/{external-CLKqHc4s.cjs → external-aTGyndBd.cjs} +1 -1
- package/dist/{external-BBGGwc9H.cjs → external-e143l3cy.cjs} +1 -1
- package/dist/{external-DVhxMa2A.js → external-mRJloDDi.js} +7 -7
- package/dist/header.cjs +1 -1
- package/dist/header.js +1 -1
- package/dist/index.cjs +33 -1
- package/dist/index.js +9765 -4790
- package/dist/input.cjs +1 -1
- package/dist/input.js +1 -1
- package/dist/list.cjs +1 -1
- package/dist/list.js +1 -1
- package/dist/menu.cjs +1 -1
- package/dist/menu.js +1 -1
- package/dist/src/color/Swatch/Swatch.d.ts +2 -1
- package/dist/src/color/Swatch/Swatch.d.ts.map +1 -1
- package/dist/src/text/core/types.d.ts +2 -0
- package/dist/src/text/core/types.d.ts.map +1 -1
- package/dist/src/theming/core/fontString.d.ts +7 -1
- package/dist/src/theming/core/fontString.d.ts.map +1 -1
- package/dist/src/vis/diagram/Diagram.d.ts +1 -0
- package/dist/src/vis/diagram/Diagram.d.ts.map +1 -1
- package/dist/src/vis/diagram/aether/Diagram.d.ts +0 -2
- package/dist/src/vis/diagram/aether/Diagram.d.ts.map +1 -1
- package/dist/src/vis/legend/Simple.d.ts.map +1 -1
- package/dist/src/vis/lineplot/aether/axis.d.ts.map +1 -1
- package/dist/src/vis/render/loop.d.ts +7 -4
- package/dist/src/vis/render/loop.d.ts.map +1 -1
- package/dist/src/vis/schematic/Forms.d.ts.map +1 -1
- package/dist/src/vis/schematic/Symbols.d.ts.map +1 -1
- package/dist/src/vis/schematic/primitives/Primitives.d.ts +2 -1
- package/dist/src/vis/schematic/primitives/Primitives.d.ts.map +1 -1
- package/dist/src/vis/value/aether/value.d.ts +11 -9
- package/dist/src/vis/value/aether/value.d.ts.map +1 -1
- package/dist/src/vis/value/use.d.ts +1 -0
- package/dist/src/vis/value/use.d.ts.map +1 -1
- package/dist/style.css +1 -1
- package/dist/tabs.cjs +1 -1
- package/dist/tabs.js +1 -1
- package/dist/text.cjs +1 -1
- package/dist/text.js +2 -2
- package/dist/theming.cjs +1 -1
- package/dist/theming.js +2 -2
- package/dist/tree.cjs +1 -1
- package/dist/tree.js +1 -1
- package/dist/triggers.cjs +1 -1
- package/dist/triggers.js +1 -1
- package/dist/{units-DbfWaeE2.cjs → units-6W_8ukD-.cjs} +1 -1
- package/dist/{units-CmWU_YzJ.js → units-BHSMvrYX.js} +1 -1
- package/dist/video.cjs +1 -1
- package/dist/video.js +1 -1
- package/package.json +3 -3
- package/dist/LinePlot-CgkhTRJT.js +0 -11256
- package/dist/LinePlot-oIHuM9Jz.cjs +0 -66
- package/dist/Toggle-GvJ5CkHq.cjs +0 -143
- package/dist/external-B7W7NBGN.cjs +0 -1
- package/dist/external-BQMz5fJB.cjs +0 -1
- package/dist/external-f7xyI5mJ.js +0 -94
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";var ac=Object.defineProperty;var oc=(t,e,n)=>e in t?ac(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var P=(t,e,n)=>oc(t,typeof e!="symbol"?e+"":e,n);const s=require("zod"),O=require("./css-
|
|
1
|
+
"use strict";var ac=Object.defineProperty;var oc=(t,e,n)=>e in t?ac(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var P=(t,e,n)=>oc(t,typeof e!="symbol"?e+"":e,n);const s=require("zod"),O=require("./css-CvXvQo39.cjs"),$s=require("react"),Yt=t=>t!=null&&typeof t=="object"&&!Array.isArray(t);var lc=Object.defineProperty,cc=(t,e,n)=>e in t?lc(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,qt=(t,e,n)=>cc(t,typeof e!="symbol"?e+"":e,n);let uc=class{constructor(){qt(this,"contentType","application/json"),qt(this,"decoder"),qt(this,"encoder"),this.decoder=new TextDecoder,this.encoder=new TextEncoder}encode(e){return this.encoder.encode(this.encodeString(e)).buffer}decode(e,n){return this.decodeString(this.decoder.decode(e),n)}decodeString(e,n){const r=JSON.parse(e),i=O.k(r);return n!=null?n.parse(i):i}encodeString(e){const n=O.v(e);return JSON.stringify(n,(r,i)=>ArrayBuffer.isView(i)?Array.from(i):Yt(i)&&"encode_value"in i?typeof i.value=="bigint"?i.value.toString():i.value:typeof i=="bigint"?i.toString():i)}static registerCustomType(){}},hc=class{constructor(){qt(this,"contentType","text/csv")}encode(e){const n=this.encodeString(e);return new TextEncoder().encode(n).buffer}decode(e,n){const r=new TextDecoder().decode(e);return this.decodeString(r,n)}encodeString(e){if(!Array.isArray(e)||e.length===0||!Yt(e[0]))throw new Error("Payload must be an array of objects");const n=Object.keys(e[0]),r=[n.join(",")];return e.forEach(i=>{const a=n.map(o=>JSON.stringify(i[o]??""));r.push(a.join(","))}),r.join(`
|
|
2
2
|
`)}decodeString(e,n){const[r,...i]=e.trim().split(`
|
|
3
|
-
`).map(c=>c.trim());if(r.length===0)return n!=null?n.parse({}):{};const a=r.split(",").map(c=>c.trim()),o={};return a.forEach(c=>{o[c]=[]}),i.forEach(c=>{const u=c.split(",").map(h=>h.trim());a.forEach((h,f)=>{const d=this.parseValue(u[f]);d!=null&&o[h].push(d)})}),n!=null?n.parse(o):o}parseValue(e){if(e==null||e.length===0)return null;const n=Number(e);return isNaN(n)?e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e:n}static registerCustomType(){}},gc=class{constructor(){Ft(this,"contentType","text/plain")}encode(e){return new TextEncoder().encode(e).buffer}decode(e,n){const r=new TextDecoder().decode(e);return n!=null?n.parse(r):r}};const On=new fc;new yc;new gc;const Qr=t=>[...new Set(t)],Ta=t=>t!=null&&typeof t=="object"&&"toString"in t,pc=t=>{if(Ta(t))return(t==null?void 0:t.toString().length)===0;switch(typeof t){case"string":return t.length===0;case"number":return t===0;case"bigint":return t===0n;case"boolean":return!t;case"undefined":return!0;case"object":return t===null}},or=(t,e=!1)=>{const n=Ta(t)?"stringer":typeof t;let r;switch(n){case"string":r=(i,a)=>i.localeCompare(a);break;case"stringer":r=(i,a)=>i.toString().localeCompare(a.toString());break;case"number":r=(i,a)=>Number(i)-Number(a);break;case"bigint":r=(i,a)=>BigInt(i)-BigInt(a)>0n?1:-1;break;case"boolean":r=(i,a)=>Number(i)-Number(a);break;case"undefined":r=()=>0;break;default:return console.warn(`sortFunc: unknown type ${n}`),()=>-1}return e?za(r):r},mc=(t,e,n)=>{const r=or(e[t],n);return(i,a)=>r(i[t],a[t])},wc=(t,e)=>t.length!==e.length?t.length-e.length:t.every((n,r)=>n===e[r])?0:-1,Sa=(t,e)=>{if(t.length!==e.length)return t.length-e.length;if(t.length===0)return 0;const n=or(t[0]),r=[...t].sort(n),i=[...e].sort(n);return r.every((a,o)=>a===i[o])?0:-1},bc=(t,e)=>{const n=Qr(t),r=Qr(e);return Sa(n,r)},vc=(t,e)=>t===e?0:t==="first"&&e==="last"?1:-1,za=t=>(e,n)=>t(n,e),ht=0,Tn=-1,Sn=1,Na=t=>t<ht,Ia=t=>t>ht,Oc=t=>t>=ht,Ea=t=>t===ht,Tc=(t,e)=>{const n=/([a-zA-Z]+)|(\d+)/g,r=t.replace(/[\s_.-]+/g,"").match(n),i=e.replace(/[\s_.-]+/g,"").match(n);if(!r||!i)return 0;for(let a=0;a<Math.min(r.length,i.length);a++){const o=r[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 r.length-i.length},Sc=Object.freeze(Object.defineProperty({__proto__:null,EQUAL:ht,GREATER_THAN:Sn,LESS_THAN:Tn,isEqualTo:Ea,isGreaterThan:Ia,isGreaterThanEqual:Oc,isLessThan:Na,newF:or,newFieldF:mc,order:vc,primitiveArrays:wc,reverseF:za,stringsWithNumbers:Tc,uniqueUnorderedPrimitiveArrays:bc,unorderedPrimitiveArrays:Sa},Symbol.toStringTag,{value:"Module"})),zc=(t,e)=>{let n=null;return e===0?t:(...r)=>{n!==null&&(clearTimeout(n),n=null),n=setTimeout(()=>t(...r),e)}},Nc=(t,e)=>{let n=null;return e===0?t:(...r)=>{n===null&&(n=setTimeout(()=>{t(...r),n=null},e))}},Aa=(t,e,n=".")=>{const r=t.split(n);return r.map((i,a)=>{const o=e(i,a,r);return o==null?null:typeof o=="string"?o:o.join(n)}).filter(i=>i!=null).join(n)},Rs=(t,e,n={optional:!1,separator:"."})=>{n.separator??(n.separator=".");const{optional:r,getter:i=(c,u)=>c[u]}=n,a=e.split(n.separator);if(a.length===1&&a[0]==="")return t;let o=t;for(const c of a){const u=i(o,c);if(u==null){if(r)return null;throw new Error(`Path ${e} does not exist. ${c} is null`)}o=u}return o},Ic=(t,e,n)=>{const r=e.split(".");let i=t;for(let a=0;a<r.length-1;a++){const o=r[a];i[o]==null&&(i[o]={}),i=i[o]}i[r[r.length-1]]=n},Ec=(t,e)=>{const n=e.split(".");let r=t;for(let i=0;i<n.length-1;i++){const a=n[i];if(r[a]==null)return;r=r[a]}if(Array.isArray(r)){const i=parseInt(n[n.length-1],10);if(isNaN(i))return;r.splice(i,1);return}delete r[n[n.length-1]]},Ac=(t,e)=>{const n=t.split(".");return e<0?n[n.length+e]:n[e]},kc=(t,e)=>{try{return Rs(t,e),!0}catch{return!1}},xc=(t,e)=>{if(e.length===0)return!0;const n=t.split("."),r=e.split(".");if(r.length>n.length)return!1;for(let i=0;i<r.length;i++){const a=n[i],o=r[i];if(o!=="*"&&a!==o)return!1}return!0},Cc=t=>JSON.parse(JSON.stringify(t)),$c=(t,...e)=>(e.forEach(n=>{let r=t;const i=n.split(".");i.forEach((a,o)=>{o===i.length-1?delete r[a]:a in r&&(r=r[a])})}),t),Rc=(t,e,n="")=>{const r={},i=(a,o,c)=>{if(typeof a!=typeof o||a===null||o===null){r[c]=[a,o];return}if(typeof a=="object"&&typeof o=="object")if(Array.isArray(a)&&Array.isArray(o)){if(a.length!==o.length){r[c]=[a,o];return}for(let u=0;u<a.length;u++)i(a[u],o[u],`${c}[${u}]`)}else new Set([...Object.keys(a),...Object.keys(o)]).forEach(u=>{i(a[u],o[u],c!==""?`${c}.${u}`:u)});else a!==o&&(r[c]=[a,o])};return i(t,e,n),r},es=(t,e)=>{const n=Array.isArray(t),r=Array.isArray(e);if(n!==r)return!1;if(n&&r){const o=t,c=e;if(o.length!==c.length)return!1;for(let u=0;u<o.length;u++)if(!es(o[u],c[u]))return!1;return!0}if(t==null||e==null||typeof t!="object"||typeof e!="object")return t===e;if("equals"in t)return t.equals(e);const i=Object.keys(t),a=Object.keys(e);if(i.length!==a.length)return!1;for(const o of i){const c=t[o],u=e[o];if(typeof c=="object"&&typeof u=="object"){if(!es(c,u))return!1}else if(c!==u)return!1}return!0},ka=(t,e)=>{if(typeof t!="object"||t==null)return t===e;const n=Object.keys(t),r=Object.keys(e);if(r.length>n.length)return!1;for(const i of r){const a=t[i],o=e[i];if(typeof a=="object"&&typeof o=="object"){if(!ka(a,o))return!1}else if(a!==o)return!1}return!0},ts=(t,...e)=>{if(e.length===0)return t;const n=e.shift();if(Yt(t)&&Yt(n))for(const r in n)try{Yt(n[r])?(r in t||Object.assign(t,{[r]:{}}),ts(t[r],n[r])):Object.assign(t,{[r]:n[r]})}catch(i){throw i instanceof TypeError?new TypeError(`.${r}: ${i.message}`):i}return ts(t,...e)},jc=(t,e,n)=>{const r=(i,a,o)=>{for(const c in a){const u=a[c];if(o!=null&&o.shape[c]){const h=o.shape[c].safeParse(u);h.success&&(i[c]=h.data)}else typeof u=="object"&&!Array.isArray(u)&&u!==null&&o&&o.shape&&o.shape[c]&&(i[c]||(i[c]={}),r(i[c],u,o.shape[c]))}return i};return r({...t},e,n)},xa=Object.freeze(Object.defineProperty({__proto__:null,copy:Cc,deleteD:$c,difference:Rc,element:Ac,equal:es,get:Rs,has:kc,override:ts,overrideValidItems:jc,partialEqual:ka,pathsMatch:xc,remove:Ec,set:Ic,transformPath:Aa},Symbol.toStringTag,{value:"Module"})),Ca=t=>Aa(t,(e,n,r)=>{const i=n===r.length-1,a=!isNaN(parseInt(e)),o=!isNaN(parseInt(r[n+1]));return a&&(e="element"),i||o?e:[e,"shape"]}),hi=(t,e)=>{if(t==null)return null;const n=t[e];return n==null&&typeof t=="object"&&"sourceType"in t?t.sourceType()[e]:n},Mc=(t,e,n)=>Rs(hi(t,"shape"),Ca(e),{...n,getter:hi}),Bc=(t,e)=>n=>{const r=e.find(i=>i.safeParse(n).success);return r==null?null:t(r.parse(n))},$a=s.z.bigint().or(s.z.string().transform(BigInt)),Dc=Object.freeze(Object.defineProperty({__proto__:null,bigInt:$a,getFieldSchema:Mc,getFieldSchemaPath:Ca,transformer:Bc},Symbol.toStringTag,{value:"Module"}));var Pc=Object.defineProperty,Uc=(t,e,n)=>e in t?Pc(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,y=(t,e,n)=>Uc(t,typeof e!="symbol"?e+"":e,n);let Lc=(t,e=21)=>(n=e)=>{let r="",i=n;for(;i--;)r+=t[Math.random()*t.length|0];return r};const _c="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",Ra=Lc(_c,11),ja=Object.freeze(Object.defineProperty({__proto__:null,id:Ra},Symbol.toStringTag,{value:"Module"})),Yc=s.z.enum(["static","dynamic"]),Ma=(t,e)=>{const n=new W(e);if(![Z.DAY,Z.HOUR,Z.MINUTE,Z.SECOND,Z.MILLISECOND,Z.MICROSECOND,Z.NANOSECOND].some(i=>i.equals(n)))throw new Error("Invalid argument for remainder. Must be an even TimeSpan or Timestamp");const r=t.valueOf()%n.valueOf();return t instanceof W?new W(r):new Z(r)},U=class S{constructor(e,n="UTC"){if(y(this,"value"),y(this,"encodeValue",!0),e==null)this.value=S.now().valueOf();else if(e instanceof Date)this.value=BigInt(e.getTime())*S.MILLISECOND.valueOf();else if(typeof e=="string")this.value=S.parseDateTimeString(e,n).valueOf();else if(Array.isArray(e))this.value=S.parseDate(e);else{let r=BigInt(0);e instanceof Number&&(e=e.valueOf()),n==="local"&&(r=S.utcOffset.valueOf()),typeof e=="number"&&(isFinite(e)?e=Math.trunc(e):(isNaN(e)&&(e=0),e===1/0?e=S.MAX:e=S.MIN)),this.value=BigInt(e.valueOf())+r}}static parseDate([e=1970,n=1,r=1]){const i=new Date(e,n-1,r,0,0,0,0);return new S(BigInt(i.getTime())*S.MILLISECOND.valueOf()).truncate(S.DAY).valueOf()}encode(){return this.value.toString()}valueOf(){return this.value}static parseTimeString(e,n="UTC"){const[r,i,a]=e.split(":");let o="00",c="00";a!=null&&([o,c]=a.split("."));let u=S.hours(parseInt(r??"00",10)).add(S.minutes(parseInt(i??"00",10))).add(S.seconds(parseInt(o??"00",10))).add(S.milliseconds(parseInt(c??"00",10)));return n==="local"&&(u=u.add(S.utcOffset)),u.valueOf()}static parseDateTimeString(e,n="UTC"){if(!e.includes("/")&&!e.includes("-"))return S.parseTimeString(e,n);const r=new Date(e);return e.includes(":")||r.setUTCHours(0,0,0,0),new S(BigInt(r.getTime())*S.MILLISECOND.valueOf(),n).valueOf()}fString(e="ISO",n="UTC"){switch(e){case"ISODate":return this.toISOString(n).slice(0,10);case"ISOTime":return this.toISOString(n).slice(11,23);case"time":return this.timeString(!1,n);case"preciseTime":return this.timeString(!0,n);case"date":return this.dateString();case"preciseDate":return`${this.dateString()} ${this.timeString(!0,n)}`;case"dateTime":return`${this.dateString()} ${this.timeString(!1,n)}`;default:return this.toISOString(n)}}toISOString(e="UTC"){return e==="UTC"?this.date().toISOString():this.sub(S.utcOffset).date().toISOString()}timeString(e=!1,n="UTC"){const r=this.toISOString(n);return e?r.slice(11,23):r.slice(11,19)}dateString(){const e=this.date(),n=e.toLocaleString("default",{month:"short"}),r=e.toLocaleString("default",{day:"numeric"});return`${n} ${r}`}static get utcOffset(){return new Z(BigInt(new Date().getTimezoneOffset())*S.MINUTE.valueOf())}static since(e){return new S().span(e)}date(){return new Date(this.milliseconds())}equals(e){return this.valueOf()===new S(e).valueOf()}span(e){return this.range(e).span}range(e){return new it(this,e).makeValid()}spanRange(e){return this.range(this.add(e)).makeValid()}get isZero(){return this.valueOf()===BigInt(0)}after(e){return this.valueOf()>new S(e).valueOf()}afterEq(e){return this.valueOf()>=new S(e).valueOf()}before(e){return this.valueOf()<new S(e).valueOf()}beforeEq(e){return this.valueOf()<=new S(e).valueOf()}add(e){return new S(this.valueOf()+BigInt(e.valueOf()))}sub(e){return new S(this.valueOf()-BigInt(e.valueOf()))}milliseconds(){return Number(this.valueOf())/Number(S.MILLISECOND.valueOf())}toString(){return this.date().toISOString()}remainder(e){return Ma(this,e)}get isToday(){return this.truncate(Z.DAY).equals(S.now().truncate(Z.DAY))}truncate(e){return this.sub(this.remainder(e))}static now(){return new S(new Date)}static max(...e){let n=S.MIN;for(const r of e){const i=new S(r);i.after(n)&&(n=i)}return n}static min(...e){let n=S.MAX;for(const r of e){const i=new S(r);i.before(n)&&(n=i)}return n}static nanoseconds(e){return new S(e)}static microseconds(e){return S.nanoseconds(e*1e3)}static milliseconds(e){return S.microseconds(e*1e3)}static seconds(e){return S.milliseconds(e*1e3)}static minutes(e){return S.seconds(e*60)}static hours(e){return S.minutes(e*60)}static days(e){return S.hours(e*24)}};y(U,"NANOSECOND",U.nanoseconds(1)),y(U,"MICROSECOND",U.microseconds(1)),y(U,"MILLISECOND",U.milliseconds(1)),y(U,"SECOND",U.seconds(1)),y(U,"MINUTE",U.minutes(1)),y(U,"HOUR",U.hours(1)),y(U,"DAY",U.days(1)),y(U,"MAX",new U((1n<<63n)-1n)),y(U,"MIN",new U(0)),y(U,"ZERO",new U(0)),y(U,"z",s.z.union([s.z.object({value:s.z.bigint()}).transform(t=>new U(t.value)),s.z.string().transform(t=>new U(BigInt(t))),s.z.instanceof(Number).transform(t=>new U(t)),s.z.number().transform(t=>new U(t)),s.z.instanceof(U)]));let W=U;const L=class I{constructor(e){y(this,"value"),y(this,"encodeValue",!0),typeof e=="number"&&(e=Math.trunc(e.valueOf())),this.value=BigInt(e.valueOf())}static fromSeconds(e){return e instanceof I?e:e instanceof ns?e.period:e instanceof W?new I(e):["number","bigint"].includes(typeof e)?I.seconds(e):new I(e)}static fromMilliseconds(e){return e instanceof I?e:e instanceof ns?e.period:e instanceof W?new I(e):["number","bigint"].includes(typeof e)?I.milliseconds(e):new I(e)}encode(){return this.value.toString()}valueOf(){return this.value}lessThan(e){return this.valueOf()<new I(e).valueOf()}greaterThan(e){return this.valueOf()>new I(e).valueOf()}lessThanOrEqual(e){return this.valueOf()<=new I(e).valueOf()}greaterThanOrEqual(e){return this.valueOf()>=new I(e).valueOf()}remainder(e){return Ma(this,e)}truncate(e){return new I(BigInt(Math.trunc(Number(this.valueOf()/e.valueOf())))*e.valueOf())}toString(){const e=this.truncate(I.DAY),n=this.truncate(I.HOUR),r=this.truncate(I.MINUTE),i=this.truncate(I.SECOND),a=this.truncate(I.MILLISECOND),o=this.truncate(I.MICROSECOND),c=this.truncate(I.NANOSECOND),u=e,h=n.sub(e),f=r.sub(n),d=i.sub(r),k=a.sub(i),D=o.sub(a),ie=c.sub(o);let M="";return u.isZero||(M+=`${u.days}d `),h.isZero||(M+=`${h.hours}h `),f.isZero||(M+=`${f.minutes}m `),d.isZero||(M+=`${d.seconds}s `),k.isZero||(M+=`${k.milliseconds}ms `),D.isZero||(M+=`${D.microseconds}µs `),ie.isZero||(M+=`${ie.nanoseconds}ns`),M.trim()}get days(){return Number(this.valueOf())/Number(I.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(I.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(I.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(I.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(I.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(I.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get isZero(){return this.valueOf()===BigInt(0)}equals(e){return this.valueOf()===new I(e).valueOf()}add(e){return new I(this.valueOf()+new I(e).valueOf())}sub(e){return new I(this.valueOf()-new I(e).valueOf())}static nanoseconds(e=1){return new I(e)}static microseconds(e=1){return I.nanoseconds(O.M(e,1e3))}static milliseconds(e=1){return I.microseconds(O.M(e,1e3))}static seconds(e=1){return I.milliseconds(O.M(e,1e3))}static minutes(e=1){return I.seconds(O.M(e,60))}static hours(e){return I.minutes(O.M(e,60))}static days(e){return I.hours(O.M(e,24))}};y(L,"NANOSECOND",L.nanoseconds(1)),y(L,"MICROSECOND",L.microseconds(1)),y(L,"MILLISECOND",L.milliseconds(1)),y(L,"SECOND",L.seconds(1)),y(L,"MINUTE",L.minutes(1)),y(L,"HOUR",L.hours(1)),y(L,"DAY",L.days(1)),y(L,"MAX",new L((1n<<63n)-1n)),y(L,"MIN",new L(0)),y(L,"ZERO",new L(0)),y(L,"z",s.z.union([s.z.object({value:s.z.bigint()}).transform(t=>new L(t.value)),s.z.string().transform(t=>new L(BigInt(t))),s.z.instanceof(Number).transform(t=>new L(t)),s.z.number().transform(t=>new L(t)),s.z.instanceof(L)]));let Z=L;const Tt=class zn extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new zn(e).valueOf()}get period(){return Z.seconds(1/this.valueOf())}sampleCount(e){return new Z(e).seconds*this.valueOf()}byteCount(e,n){return this.sampleCount(e)*new ce(n).valueOf()}span(e){return Z.seconds(e/this.valueOf())}byteSpan(e,n){return this.span(e.valueOf()/n.valueOf())}static hz(e){return new zn(e)}static khz(e){return zn.hz(e*1e3)}};y(Tt,"z",s.z.union([s.z.number().transform(t=>new Tt(t)),s.z.instanceof(Number).transform(t=>new Tt(t)),s.z.instanceof(Tt)]));let ns=Tt;const te=class extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}length(e){return e.valueOf()/this.valueOf()}size(e){return new Zt(e*this.valueOf())}};y(te,"UNKNOWN",new te(0)),y(te,"BIT128",new te(16)),y(te,"BIT64",new te(8)),y(te,"BIT32",new te(4)),y(te,"BIT16",new te(2)),y(te,"BIT8",new te(1)),y(te,"z",s.z.union([s.z.number().transform(t=>new te(t)),s.z.instanceof(Number).transform(t=>new te(t)),s.z.instanceof(te)]));let ce=te;const Se=class Nn{constructor(e,n){y(this,"start"),y(this,"end"),typeof e=="object"&&"start"in e?(this.start=new W(e.start),this.end=new W(e.end)):(this.start=new W(e),this.end=new W(n))}get span(){return new Z(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 Nn(this.end,this.start)}equals(e){return this.start.equals(e.start)&&this.end.equals(e.end)}toString(){return`${this.start.toString()} - ${this.end.toString()}`}toPrettyString(){return`${this.start.fString("preciseDate")} - ${this.span.toString()}`}overlapsWith(e,n=Z.ZERO){e=e.makeValid();const r=this.makeValid();if(this.equals(e))return!0;if(e.end.equals(r.start)||r.end.equals(e.start))return!1;const i=W.max(r.start,e.start),a=W.min(r.end,e.end);return a.before(i)?!1:new Z(a.sub(i)).greaterThanOrEqual(n)}roughlyEquals(e,n){let r=this.start.sub(e.start).valueOf(),i=this.end.sub(e.end).valueOf();return r<0&&(r=-r),i<0&&(i=-i),r<=n.valueOf()&&i<=n.valueOf()}contains(e){return e instanceof Nn?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const n=new Nn(this.start,this.end);return e.start.after(this.start)&&(n.start=e.start),e.start.after(this.end)&&(n.end=e.start),e.end.before(this.end)&&(n.end=e.end),e.end.before(this.start)&&(n.start=e.end),n}};y(Se,"MAX",new Se(W.MIN,W.MAX)),y(Se,"MIN",new Se(W.MAX,W.MIN)),y(Se,"ZERO",new Se(W.ZERO,W.ZERO)),y(Se,"z",s.z.union([s.z.object({start:W.z,end:W.z}).transform(t=>new Se(t.start,t.end)),s.z.instanceof(Se)]));let it=Se;const p=class ze extends String{constructor(e){if(e instanceof ze||typeof e=="string"||typeof e.valueOf()=="string"){super(e.valueOf());return}else{const n=ze.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);if(n!=null){super(n.valueOf());return}}throw super(ze.UNKNOWN.valueOf()),new Error(`unable to find data type for ${e.toString()}`)}get Array(){const e=ze.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(n=>this.equals(n))}toString(){return this.valueOf()}get isVariable(){return this.equals(ze.JSON)||this.equals(ze.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(ze.UUID)}get isInteger(){return this.toString().startsWith("int")}get isFloat(){return this.toString().startsWith("float")}get density(){const e=ze.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}canSafelyCastTo(e){return this.equals(e)?!0:this.isVariable&&!e.isVariable||!this.isVariable&&e.isVariable?!1:this.isFloat&&e.isInteger||this.isInteger&&e.isFloat?this.density.valueOf()<e.density.valueOf():this.isFloat&&e.isFloat||this.isInteger&&e.isInteger?this.density.valueOf()<=e.density.valueOf():!1}canCastTo(e){return this.isNumeric&&e.isNumeric?!0:this.equals(e)}checkArray(e){return e.constructor===this.Array}toJSON(){return this.toString()}get usesBigInt(){return ze.BIG_INT_TYPES.some(e=>e.equals(this))}};y(p,"UNKNOWN",new p("unknown")),y(p,"FLOAT64",new p("float64")),y(p,"FLOAT32",new p("float32")),y(p,"INT64",new p("int64")),y(p,"INT32",new p("int32")),y(p,"INT16",new p("int16")),y(p,"INT8",new p("int8")),y(p,"UINT64",new p("uint64")),y(p,"UINT32",new p("uint32")),y(p,"UINT16",new p("uint16")),y(p,"UINT8",new p("uint8")),y(p,"BOOLEAN",p.UINT8),y(p,"TIMESTAMP",new p("timestamp")),y(p,"UUID",new p("uuid")),y(p,"STRING",new p("string")),y(p,"JSON",new p("json")),y(p,"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]])),y(p,"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]])),y(p,"DENSITIES",new Map([[p.UINT8.toString(),ce.BIT8],[p.UINT16.toString(),ce.BIT16],[p.UINT32.toString(),ce.BIT32],[p.UINT64.toString(),ce.BIT64],[p.FLOAT32.toString(),ce.BIT32],[p.FLOAT64.toString(),ce.BIT64],[p.INT8.toString(),ce.BIT8],[p.INT16.toString(),ce.BIT16],[p.INT32.toString(),ce.BIT32],[p.INT64.toString(),ce.BIT64],[p.TIMESTAMP.toString(),ce.BIT64],[p.STRING.toString(),ce.UNKNOWN],[p.JSON.toString(),ce.UNKNOWN],[p.UUID.toString(),ce.BIT128]])),y(p,"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]),y(p,"BIG_INT_TYPES",[p.INT64,p.UINT64,p.TIMESTAMP]),y(p,"z",s.z.union([s.z.string().transform(t=>new p(t)),s.z.instanceof(p)]));let j=p;const ae=class J extends Number{constructor(e){super(e.valueOf())}largerThan(e){return this.valueOf()>e.valueOf()}smallerThan(e){return this.valueOf()<e.valueOf()}add(e){return J.bytes(this.valueOf()+e.valueOf())}sub(e){return J.bytes(this.valueOf()-e.valueOf())}truncate(e){return new J(Math.trunc(this.valueOf()/e.valueOf())*e.valueOf())}remainder(e){return J.bytes(this.valueOf()%e.valueOf())}get gigabytes(){return this.valueOf()/J.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/J.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/J.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/J.TERABYTE.valueOf()}toString(){const e=this.truncate(J.TERABYTE),n=this.truncate(J.GIGABYTE),r=this.truncate(J.MEGABYTE),i=this.truncate(J.KILOBYTE),a=this.truncate(J.BYTE),o=e,c=n.sub(e),u=r.sub(n),h=i.sub(r),f=a.sub(i);let d="";return o.isZero||(d+=`${o.terabytes}TB `),c.isZero||(d+=`${c.gigabytes}GB `),u.isZero||(d+=`${u.megabytes}MB `),h.isZero||(d+=`${h.kilobytes}KB `),(!f.isZero||d==="")&&(d+=`${f.valueOf()}B`),d.trim()}static bytes(e=1){return new J(e)}static kilobytes(e=1){return J.bytes(e.valueOf()*1e3)}static megabytes(e=1){return J.kilobytes(e.valueOf()*1e3)}static gigabytes(e=1){return J.megabytes(e.valueOf()*1e3)}static terabytes(e){return J.gigabytes(e.valueOf()*1e3)}get isZero(){return this.valueOf()===0}};y(ae,"BYTE",new ae(1)),y(ae,"KILOBYTE",ae.kilobytes(1)),y(ae,"MEGABYTE",ae.megabytes(1)),y(ae,"GIGABYTE",ae.gigabytes(1)),y(ae,"TERABYTE",ae.terabytes(1)),y(ae,"ZERO",new ae(0)),y(ae,"z",s.z.union([s.z.number().transform(t=>new ae(t)),s.z.instanceof(ae)]));let Zt=ae;const Fc=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)]),Ba=t=>{const e=typeof t;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||t instanceof W||t instanceof Z||t instanceof Date},qc=(t,e,n,r=0)=>t.usesBigInt&&!e.usesBigInt?Number(n)-Number(r):!t.usesBigInt&&e.usesBigInt?BigInt(n.valueOf())-BigInt(r.valueOf()):zt(n,-r).valueOf(),Vc=t=>t==null?!1:Array.isArray(t)||t instanceof ArrayBuffer||ArrayBuffer.isView(t)&&!(t instanceof DataView)||t instanceof Da?!0:Ba(t),Pe=-1,rs={[Symbol.iterator]:()=>rs,next:()=>({done:!0,value:void 0})},Wc=s.z.string().transform(t=>new Uint8Array(atob(t).split("").map(e=>e.charCodeAt(0))).buffer),Gc=s.z.union([s.z.null(),s.z.undefined()]).transform(()=>new Uint8Array().buffer),ss=10,St=class Ne{constructor(e){y(this,"key",""),y(this,"isSynnaxSeries",!0),y(this,"dataType"),y(this,"sampleOffset"),y(this,"gl"),y(this,"_data"),y(this,"_timeRange"),y(this,"alignment",0n),y(this,"_cachedMin"),y(this,"_cachedMax"),y(this,"writePos",Pe),y(this,"_refCount",0),y(this,"_cachedLength"),y(this,"_cachedIndexes"),Vc(e)&&(e={data:e});const{dataType:n,timeRange:r,sampleOffset:i=0,glBufferUsage:a="static",alignment:o=0n,key:c=Ra()}=e,u=e.data??[];if(u instanceof Ne||typeof u=="object"&&"isSynnaxSeries"in u&&u.isSynnaxSeries===!0){const d=u;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._cachedMin=d._cachedMin,this._cachedMax=d._cachedMax,this.writePos=d.writePos,this._refCount=d._refCount,this._cachedLength=d._cachedLength;return}const h=Ba(u),f=Array.isArray(u);if(n!=null)this.dataType=new j(n);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(f||h){let d=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.");d=u[0]}if(typeof d=="string")this.dataType=j.STRING;else if(typeof d=="number")this.dataType=j.FLOAT64;else if(typeof d=="bigint")this.dataType=j.INT64;else if(typeof d=="boolean")this.dataType=j.BOOLEAN;else if(d instanceof W||d instanceof Date||d instanceof W)this.dataType=j.TIMESTAMP;else if(typeof d=="object")this.dataType=j.JSON;else throw new Error(`cannot infer data type of ${typeof d} when constructing a Series from a JS array`)}else this.dataType=new j(u)}if(!f&&!h)this._data=u;else{let d=h?[u]:u;const k=d[0];(k instanceof W||k instanceof Date||k instanceof Z)&&(d=d.map(D=>new W(D).valueOf())),this.dataType.equals(j.STRING)?(this._cachedLength=d.length,this._data=new TextEncoder().encode(d.join(`
|
|
3
|
+
`).map(c=>c.trim());if(r.length===0)return n!=null?n.parse({}):{};const a=r.split(",").map(c=>c.trim()),o={};return a.forEach(c=>{o[c]=[]}),i.forEach(c=>{const u=c.split(",").map(h=>h.trim());a.forEach((h,f)=>{const d=this.parseValue(u[f]);d!=null&&o[h].push(d)})}),n!=null?n.parse(o):o}parseValue(e){if(e==null||e.length===0)return null;const n=Number(e);return isNaN(n)?e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e:n}static registerCustomType(){}},dc=class{constructor(){qt(this,"contentType","text/plain")}encode(e){return new TextEncoder().encode(e).buffer}decode(e,n){const r=new TextDecoder().decode(e);return n!=null?n.parse(r):r}};const On=new uc;new hc;new dc;const Qr=t=>[...new Set(t)],Ta=t=>t!=null&&typeof t=="object"&&"toString"in t,fc=t=>{if(Ta(t))return(t==null?void 0:t.toString().length)===0;switch(typeof t){case"string":return t.length===0;case"number":return t===0;case"bigint":return t===0n;case"boolean":return!t;case"undefined":return!0;case"object":return t===null}},or=(t,e=!1)=>{const n=Ta(t)?"stringer":typeof t;let r;switch(n){case"string":r=(i,a)=>i.localeCompare(a);break;case"stringer":r=(i,a)=>i.toString().localeCompare(a.toString());break;case"number":r=(i,a)=>Number(i)-Number(a);break;case"bigint":r=(i,a)=>BigInt(i)-BigInt(a)>0n?1:-1;break;case"boolean":r=(i,a)=>Number(i)-Number(a);break;case"undefined":r=()=>0;break;default:return console.warn(`sortFunc: unknown type ${n}`),()=>-1}return e?za(r):r},yc=(t,e,n)=>{const r=or(e[t],n);return(i,a)=>r(i[t],a[t])},gc=(t,e)=>t.length!==e.length?t.length-e.length:t.every((n,r)=>n===e[r])?0:-1,Sa=(t,e)=>{if(t.length!==e.length)return t.length-e.length;if(t.length===0)return 0;const n=or(t[0]),r=[...t].sort(n),i=[...e].sort(n);return r.every((a,o)=>a===i[o])?0:-1},pc=(t,e)=>{const n=Qr(t),r=Qr(e);return Sa(n,r)},mc=(t,e)=>t===e?0:t==="first"&&e==="last"?1:-1,za=t=>(e,n)=>t(n,e),ht=0,Tn=-1,Sn=1,Na=t=>t<ht,Ia=t=>t>ht,wc=t=>t>=ht,Ea=t=>t===ht,bc=(t,e)=>{const n=/([a-zA-Z]+)|(\d+)/g,r=t.replace(/[\s_.-]+/g,"").match(n),i=e.replace(/[\s_.-]+/g,"").match(n);if(!r||!i)return 0;for(let a=0;a<Math.min(r.length,i.length);a++){const o=r[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 r.length-i.length},vc=Object.freeze(Object.defineProperty({__proto__:null,EQUAL:ht,GREATER_THAN:Sn,LESS_THAN:Tn,isEqualTo:Ea,isGreaterThan:Ia,isGreaterThanEqual:wc,isLessThan:Na,newF:or,newFieldF:yc,order:mc,primitiveArrays:gc,reverseF:za,stringsWithNumbers:bc,uniqueUnorderedPrimitiveArrays:pc,unorderedPrimitiveArrays:Sa},Symbol.toStringTag,{value:"Module"})),Oc=(t,e)=>{let n=null;return e===0?t:(...r)=>{n!==null&&(clearTimeout(n),n=null),n=setTimeout(()=>t(...r),e)}},Tc=(t,e)=>{let n=null;return e===0?t:(...r)=>{n===null&&(n=setTimeout(()=>{t(...r),n=null},e))}},Aa=(t,e,n=".")=>{const r=t.split(n);return r.map((i,a)=>{const o=e(i,a,r);return o==null?null:typeof o=="string"?o:o.join(n)}).filter(i=>i!=null).join(n)},Rs=(t,e,n={optional:!1,separator:"."})=>{n.separator??(n.separator=".");const{optional:r,getter:i=(c,u)=>c[u]}=n,a=e.split(n.separator);if(a.length===1&&a[0]==="")return t;let o=t;for(const c of a){const u=i(o,c);if(u==null){if(r)return null;throw new Error(`Path ${e} does not exist. ${c} is null`)}o=u}return o},Sc=(t,e,n)=>{const r=e.split(".");let i=t;for(let a=0;a<r.length-1;a++){const o=r[a];i[o]==null&&(i[o]={}),i=i[o]}i[r[r.length-1]]=n},zc=(t,e)=>{const n=e.split(".");let r=t;for(let i=0;i<n.length-1;i++){const a=n[i];if(r[a]==null)return;r=r[a]}if(Array.isArray(r)){const i=parseInt(n[n.length-1],10);if(isNaN(i))return;r.splice(i,1);return}delete r[n[n.length-1]]},Nc=(t,e)=>{const n=t.split(".");return e<0?n[n.length+e]:n[e]},Ic=(t,e)=>{try{return Rs(t,e),!0}catch{return!1}},Ec=(t,e)=>{if(e.length===0)return!0;const n=t.split("."),r=e.split(".");if(r.length>n.length)return!1;for(let i=0;i<r.length;i++){const a=n[i],o=r[i];if(o!=="*"&&a!==o)return!1}return!0},Ac=t=>JSON.parse(JSON.stringify(t)),kc=(t,...e)=>(e.forEach(n=>{let r=t;const i=n.split(".");i.forEach((a,o)=>{o===i.length-1?delete r[a]:a in r&&(r=r[a])})}),t),xc=(t,e,n="")=>{const r={},i=(a,o,c)=>{if(typeof a!=typeof o||a===null||o===null){r[c]=[a,o];return}if(typeof a=="object"&&typeof o=="object")if(Array.isArray(a)&&Array.isArray(o)){if(a.length!==o.length){r[c]=[a,o];return}for(let u=0;u<a.length;u++)i(a[u],o[u],`${c}[${u}]`)}else new Set([...Object.keys(a),...Object.keys(o)]).forEach(u=>{i(a[u],o[u],c!==""?`${c}.${u}`:u)});else a!==o&&(r[c]=[a,o])};return i(t,e,n),r},es=(t,e)=>{const n=Array.isArray(t),r=Array.isArray(e);if(n!==r)return!1;if(n&&r){const o=t,c=e;if(o.length!==c.length)return!1;for(let u=0;u<o.length;u++)if(!es(o[u],c[u]))return!1;return!0}if(t==null||e==null||typeof t!="object"||typeof e!="object")return t===e;if("equals"in t)return t.equals(e);const i=Object.keys(t),a=Object.keys(e);if(i.length!==a.length)return!1;for(const o of i){const c=t[o],u=e[o];if(typeof c=="object"&&typeof u=="object"){if(!es(c,u))return!1}else if(c!==u)return!1}return!0},ka=(t,e)=>{if(typeof t!="object"||t==null)return t===e;const n=Object.keys(t),r=Object.keys(e);if(r.length>n.length)return!1;for(const i of r){const a=t[i],o=e[i];if(typeof a=="object"&&typeof o=="object"){if(!ka(a,o))return!1}else if(a!==o)return!1}return!0},ts=(t,...e)=>{if(e.length===0)return t;const n=e.shift();if(Yt(t)&&Yt(n))for(const r in n)try{Yt(n[r])?(r in t||Object.assign(t,{[r]:{}}),ts(t[r],n[r])):Object.assign(t,{[r]:n[r]})}catch(i){throw i instanceof TypeError?new TypeError(`.${r}: ${i.message}`):i}return ts(t,...e)},Cc=(t,e,n)=>{const r=(i,a,o)=>{for(const c in a){const u=a[c];if(o!=null&&o.shape[c]){const h=o.shape[c].safeParse(u);h.success&&(i[c]=h.data)}else typeof u=="object"&&!Array.isArray(u)&&u!==null&&o&&o.shape&&o.shape[c]&&(i[c]||(i[c]={}),r(i[c],u,o.shape[c]))}return i};return r({...t},e,n)},xa=Object.freeze(Object.defineProperty({__proto__:null,copy:Ac,deleteD:kc,difference:xc,element:Nc,equal:es,get:Rs,has:Ic,override:ts,overrideValidItems:Cc,partialEqual:ka,pathsMatch:Ec,remove:zc,set:Sc,transformPath:Aa},Symbol.toStringTag,{value:"Module"})),Ca=t=>Aa(t,(e,n,r)=>{const i=n===r.length-1,a=!isNaN(parseInt(e)),o=!isNaN(parseInt(r[n+1]));return a&&(e="element"),i||o?e:[e,"shape"]}),hi=(t,e)=>{if(t==null)return null;const n=t[e];return n==null&&typeof t=="object"&&"sourceType"in t?t.sourceType()[e]:n},$c=(t,e,n)=>Rs(hi(t,"shape"),Ca(e),{...n,getter:hi}),Rc=(t,e)=>n=>{const r=e.find(i=>i.safeParse(n).success);return r==null?null:t(r.parse(n))},$a=s.z.bigint().or(s.z.string().transform(BigInt)),jc=Object.freeze(Object.defineProperty({__proto__:null,bigInt:$a,getFieldSchema:$c,getFieldSchemaPath:Ca,transformer:Rc},Symbol.toStringTag,{value:"Module"}));var Bc=Object.defineProperty,Mc=(t,e,n)=>e in t?Bc(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,y=(t,e,n)=>Mc(t,typeof e!="symbol"?e+"":e,n);let Dc=(t,e=21)=>(n=e)=>{let r="",i=n;for(;i--;)r+=t[Math.random()*t.length|0];return r};const Pc="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",Ra=Dc(Pc,11),ja=Object.freeze(Object.defineProperty({__proto__:null,id:Ra},Symbol.toStringTag,{value:"Module"})),Uc=s.z.enum(["static","dynamic"]),Ba=(t,e)=>{const n=new W(e);if(![Z.DAY,Z.HOUR,Z.MINUTE,Z.SECOND,Z.MILLISECOND,Z.MICROSECOND,Z.NANOSECOND].some(i=>i.equals(n)))throw new Error("Invalid argument for remainder. Must be an even TimeSpan or Timestamp");const r=t.valueOf()%n.valueOf();return t instanceof W?new W(r):new Z(r)},U=class S{constructor(e,n="UTC"){if(y(this,"value"),y(this,"encodeValue",!0),e==null)this.value=S.now().valueOf();else if(e instanceof Date)this.value=BigInt(e.getTime())*S.MILLISECOND.valueOf();else if(typeof e=="string")this.value=S.parseDateTimeString(e,n).valueOf();else if(Array.isArray(e))this.value=S.parseDate(e);else{let r=BigInt(0);e instanceof Number&&(e=e.valueOf()),n==="local"&&(r=S.utcOffset.valueOf()),typeof e=="number"&&(isFinite(e)?e=Math.trunc(e):(isNaN(e)&&(e=0),e===1/0?e=S.MAX:e=S.MIN)),this.value=BigInt(e.valueOf())+r}}static parseDate([e=1970,n=1,r=1]){const i=new Date(e,n-1,r,0,0,0,0);return new S(BigInt(i.getTime())*S.MILLISECOND.valueOf()).truncate(S.DAY).valueOf()}encode(){return this.value.toString()}valueOf(){return this.value}static parseTimeString(e,n="UTC"){const[r,i,a]=e.split(":");let o="00",c="00";a!=null&&([o,c]=a.split("."));let u=S.hours(parseInt(r??"00",10)).add(S.minutes(parseInt(i??"00",10))).add(S.seconds(parseInt(o??"00",10))).add(S.milliseconds(parseInt(c??"00",10)));return n==="local"&&(u=u.add(S.utcOffset)),u.valueOf()}static parseDateTimeString(e,n="UTC"){if(!e.includes("/")&&!e.includes("-"))return S.parseTimeString(e,n);const r=new Date(e);return e.includes(":")||r.setUTCHours(0,0,0,0),new S(BigInt(r.getTime())*S.MILLISECOND.valueOf(),n).valueOf()}fString(e="ISO",n="UTC"){switch(e){case"ISODate":return this.toISOString(n).slice(0,10);case"ISOTime":return this.toISOString(n).slice(11,23);case"time":return this.timeString(!1,n);case"preciseTime":return this.timeString(!0,n);case"date":return this.dateString();case"preciseDate":return`${this.dateString()} ${this.timeString(!0,n)}`;case"dateTime":return`${this.dateString()} ${this.timeString(!1,n)}`;default:return this.toISOString(n)}}toISOString(e="UTC"){return e==="UTC"?this.date().toISOString():this.sub(S.utcOffset).date().toISOString()}timeString(e=!1,n="UTC"){const r=this.toISOString(n);return e?r.slice(11,23):r.slice(11,19)}dateString(){const e=this.date(),n=e.toLocaleString("default",{month:"short"}),r=e.toLocaleString("default",{day:"numeric"});return`${n} ${r}`}static get utcOffset(){return new Z(BigInt(new Date().getTimezoneOffset())*S.MINUTE.valueOf())}static since(e){return new S().span(e)}date(){return new Date(this.milliseconds())}equals(e){return this.valueOf()===new S(e).valueOf()}span(e){return this.range(e).span}range(e){return new it(this,e).makeValid()}spanRange(e){return this.range(this.add(e)).makeValid()}get isZero(){return this.valueOf()===BigInt(0)}after(e){return this.valueOf()>new S(e).valueOf()}afterEq(e){return this.valueOf()>=new S(e).valueOf()}before(e){return this.valueOf()<new S(e).valueOf()}beforeEq(e){return this.valueOf()<=new S(e).valueOf()}add(e){return new S(this.valueOf()+BigInt(e.valueOf()))}sub(e){return new S(this.valueOf()-BigInt(e.valueOf()))}milliseconds(){return Number(this.valueOf())/Number(S.MILLISECOND.valueOf())}toString(){return this.date().toISOString()}remainder(e){return Ba(this,e)}get isToday(){return this.truncate(Z.DAY).equals(S.now().truncate(Z.DAY))}truncate(e){return this.sub(this.remainder(e))}static now(){return new S(new Date)}static max(...e){let n=S.MIN;for(const r of e){const i=new S(r);i.after(n)&&(n=i)}return n}static min(...e){let n=S.MAX;for(const r of e){const i=new S(r);i.before(n)&&(n=i)}return n}static nanoseconds(e){return new S(e)}static microseconds(e){return S.nanoseconds(e*1e3)}static milliseconds(e){return S.microseconds(e*1e3)}static seconds(e){return S.milliseconds(e*1e3)}static minutes(e){return S.seconds(e*60)}static hours(e){return S.minutes(e*60)}static days(e){return S.hours(e*24)}};y(U,"NANOSECOND",U.nanoseconds(1)),y(U,"MICROSECOND",U.microseconds(1)),y(U,"MILLISECOND",U.milliseconds(1)),y(U,"SECOND",U.seconds(1)),y(U,"MINUTE",U.minutes(1)),y(U,"HOUR",U.hours(1)),y(U,"DAY",U.days(1)),y(U,"MAX",new U((1n<<63n)-1n)),y(U,"MIN",new U(0)),y(U,"ZERO",new U(0)),y(U,"z",s.z.union([s.z.object({value:s.z.bigint()}).transform(t=>new U(t.value)),s.z.string().transform(t=>new U(BigInt(t))),s.z.instanceof(Number).transform(t=>new U(t)),s.z.number().transform(t=>new U(t)),s.z.instanceof(U)]));let W=U;const L=class I{constructor(e){y(this,"value"),y(this,"encodeValue",!0),typeof e=="number"&&(e=Math.trunc(e.valueOf())),this.value=BigInt(e.valueOf())}static fromSeconds(e){return e instanceof I?e:e instanceof ns?e.period:e instanceof W?new I(e):["number","bigint"].includes(typeof e)?I.seconds(e):new I(e)}static fromMilliseconds(e){return e instanceof I?e:e instanceof ns?e.period:e instanceof W?new I(e):["number","bigint"].includes(typeof e)?I.milliseconds(e):new I(e)}encode(){return this.value.toString()}valueOf(){return this.value}lessThan(e){return this.valueOf()<new I(e).valueOf()}greaterThan(e){return this.valueOf()>new I(e).valueOf()}lessThanOrEqual(e){return this.valueOf()<=new I(e).valueOf()}greaterThanOrEqual(e){return this.valueOf()>=new I(e).valueOf()}remainder(e){return Ba(this,e)}truncate(e){return new I(BigInt(Math.trunc(Number(this.valueOf()/e.valueOf())))*e.valueOf())}toString(){const e=this.truncate(I.DAY),n=this.truncate(I.HOUR),r=this.truncate(I.MINUTE),i=this.truncate(I.SECOND),a=this.truncate(I.MILLISECOND),o=this.truncate(I.MICROSECOND),c=this.truncate(I.NANOSECOND),u=e,h=n.sub(e),f=r.sub(n),d=i.sub(r),k=a.sub(i),D=o.sub(a),ie=c.sub(o);let B="";return u.isZero||(B+=`${u.days}d `),h.isZero||(B+=`${h.hours}h `),f.isZero||(B+=`${f.minutes}m `),d.isZero||(B+=`${d.seconds}s `),k.isZero||(B+=`${k.milliseconds}ms `),D.isZero||(B+=`${D.microseconds}µs `),ie.isZero||(B+=`${ie.nanoseconds}ns`),B.trim()}get days(){return Number(this.valueOf())/Number(I.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(I.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(I.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(I.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(I.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(I.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get isZero(){return this.valueOf()===BigInt(0)}equals(e){return this.valueOf()===new I(e).valueOf()}add(e){return new I(this.valueOf()+new I(e).valueOf())}sub(e){return new I(this.valueOf()-new I(e).valueOf())}static nanoseconds(e=1){return new I(e)}static microseconds(e=1){return I.nanoseconds(O.M(e,1e3))}static milliseconds(e=1){return I.microseconds(O.M(e,1e3))}static seconds(e=1){return I.milliseconds(O.M(e,1e3))}static minutes(e=1){return I.seconds(O.M(e,60))}static hours(e){return I.minutes(O.M(e,60))}static days(e){return I.hours(O.M(e,24))}};y(L,"NANOSECOND",L.nanoseconds(1)),y(L,"MICROSECOND",L.microseconds(1)),y(L,"MILLISECOND",L.milliseconds(1)),y(L,"SECOND",L.seconds(1)),y(L,"MINUTE",L.minutes(1)),y(L,"HOUR",L.hours(1)),y(L,"DAY",L.days(1)),y(L,"MAX",new L((1n<<63n)-1n)),y(L,"MIN",new L(0)),y(L,"ZERO",new L(0)),y(L,"z",s.z.union([s.z.object({value:s.z.bigint()}).transform(t=>new L(t.value)),s.z.string().transform(t=>new L(BigInt(t))),s.z.instanceof(Number).transform(t=>new L(t)),s.z.number().transform(t=>new L(t)),s.z.instanceof(L)]));let Z=L;const Tt=class zn extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new zn(e).valueOf()}get period(){return Z.seconds(1/this.valueOf())}sampleCount(e){return new Z(e).seconds*this.valueOf()}byteCount(e,n){return this.sampleCount(e)*new ce(n).valueOf()}span(e){return Z.seconds(e/this.valueOf())}byteSpan(e,n){return this.span(e.valueOf()/n.valueOf())}static hz(e){return new zn(e)}static khz(e){return zn.hz(e*1e3)}};y(Tt,"z",s.z.union([s.z.number().transform(t=>new Tt(t)),s.z.instanceof(Number).transform(t=>new Tt(t)),s.z.instanceof(Tt)]));let ns=Tt;const te=class extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}length(e){return e.valueOf()/this.valueOf()}size(e){return new Zt(e*this.valueOf())}};y(te,"UNKNOWN",new te(0)),y(te,"BIT128",new te(16)),y(te,"BIT64",new te(8)),y(te,"BIT32",new te(4)),y(te,"BIT16",new te(2)),y(te,"BIT8",new te(1)),y(te,"z",s.z.union([s.z.number().transform(t=>new te(t)),s.z.instanceof(Number).transform(t=>new te(t)),s.z.instanceof(te)]));let ce=te;const Se=class Nn{constructor(e,n){y(this,"start"),y(this,"end"),typeof e=="object"&&"start"in e?(this.start=new W(e.start),this.end=new W(e.end)):(this.start=new W(e),this.end=new W(n))}get span(){return new Z(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 Nn(this.end,this.start)}equals(e){return this.start.equals(e.start)&&this.end.equals(e.end)}toString(){return`${this.start.toString()} - ${this.end.toString()}`}toPrettyString(){return`${this.start.fString("preciseDate")} - ${this.span.toString()}`}overlapsWith(e,n=Z.ZERO){e=e.makeValid();const r=this.makeValid();if(this.equals(e))return!0;if(e.end.equals(r.start)||r.end.equals(e.start))return!1;const i=W.max(r.start,e.start),a=W.min(r.end,e.end);return a.before(i)?!1:new Z(a.sub(i)).greaterThanOrEqual(n)}roughlyEquals(e,n){let r=this.start.sub(e.start).valueOf(),i=this.end.sub(e.end).valueOf();return r<0&&(r=-r),i<0&&(i=-i),r<=n.valueOf()&&i<=n.valueOf()}contains(e){return e instanceof Nn?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const n=new Nn(this.start,this.end);return e.start.after(this.start)&&(n.start=e.start),e.start.after(this.end)&&(n.end=e.start),e.end.before(this.end)&&(n.end=e.end),e.end.before(this.start)&&(n.start=e.end),n}};y(Se,"MAX",new Se(W.MIN,W.MAX)),y(Se,"MIN",new Se(W.MAX,W.MIN)),y(Se,"ZERO",new Se(W.ZERO,W.ZERO)),y(Se,"z",s.z.union([s.z.object({start:W.z,end:W.z}).transform(t=>new Se(t.start,t.end)),s.z.instanceof(Se)]));let it=Se;const p=class ze extends String{constructor(e){if(e instanceof ze||typeof e=="string"||typeof e.valueOf()=="string"){super(e.valueOf());return}else{const n=ze.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);if(n!=null){super(n.valueOf());return}}throw super(ze.UNKNOWN.valueOf()),new Error(`unable to find data type for ${e.toString()}`)}get Array(){const e=ze.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(n=>this.equals(n))}toString(){return this.valueOf()}get isVariable(){return this.equals(ze.JSON)||this.equals(ze.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(ze.UUID)}get isInteger(){return this.toString().startsWith("int")}get isFloat(){return this.toString().startsWith("float")}get density(){const e=ze.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}canSafelyCastTo(e){return this.equals(e)?!0:this.isVariable&&!e.isVariable||!this.isVariable&&e.isVariable?!1:this.isFloat&&e.isInteger||this.isInteger&&e.isFloat?this.density.valueOf()<e.density.valueOf():this.isFloat&&e.isFloat||this.isInteger&&e.isInteger?this.density.valueOf()<=e.density.valueOf():!1}canCastTo(e){return this.isNumeric&&e.isNumeric?!0:this.equals(e)}checkArray(e){return e.constructor===this.Array}toJSON(){return this.toString()}get usesBigInt(){return ze.BIG_INT_TYPES.some(e=>e.equals(this))}};y(p,"UNKNOWN",new p("unknown")),y(p,"FLOAT64",new p("float64")),y(p,"FLOAT32",new p("float32")),y(p,"INT64",new p("int64")),y(p,"INT32",new p("int32")),y(p,"INT16",new p("int16")),y(p,"INT8",new p("int8")),y(p,"UINT64",new p("uint64")),y(p,"UINT32",new p("uint32")),y(p,"UINT16",new p("uint16")),y(p,"UINT8",new p("uint8")),y(p,"BOOLEAN",p.UINT8),y(p,"TIMESTAMP",new p("timestamp")),y(p,"UUID",new p("uuid")),y(p,"STRING",new p("string")),y(p,"JSON",new p("json")),y(p,"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]])),y(p,"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]])),y(p,"DENSITIES",new Map([[p.UINT8.toString(),ce.BIT8],[p.UINT16.toString(),ce.BIT16],[p.UINT32.toString(),ce.BIT32],[p.UINT64.toString(),ce.BIT64],[p.FLOAT32.toString(),ce.BIT32],[p.FLOAT64.toString(),ce.BIT64],[p.INT8.toString(),ce.BIT8],[p.INT16.toString(),ce.BIT16],[p.INT32.toString(),ce.BIT32],[p.INT64.toString(),ce.BIT64],[p.TIMESTAMP.toString(),ce.BIT64],[p.STRING.toString(),ce.UNKNOWN],[p.JSON.toString(),ce.UNKNOWN],[p.UUID.toString(),ce.BIT128]])),y(p,"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]),y(p,"BIG_INT_TYPES",[p.INT64,p.UINT64,p.TIMESTAMP]),y(p,"z",s.z.union([s.z.string().transform(t=>new p(t)),s.z.instanceof(p)]));let j=p;const ae=class J extends Number{constructor(e){super(e.valueOf())}largerThan(e){return this.valueOf()>e.valueOf()}smallerThan(e){return this.valueOf()<e.valueOf()}add(e){return J.bytes(this.valueOf()+e.valueOf())}sub(e){return J.bytes(this.valueOf()-e.valueOf())}truncate(e){return new J(Math.trunc(this.valueOf()/e.valueOf())*e.valueOf())}remainder(e){return J.bytes(this.valueOf()%e.valueOf())}get gigabytes(){return this.valueOf()/J.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/J.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/J.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/J.TERABYTE.valueOf()}toString(){const e=this.truncate(J.TERABYTE),n=this.truncate(J.GIGABYTE),r=this.truncate(J.MEGABYTE),i=this.truncate(J.KILOBYTE),a=this.truncate(J.BYTE),o=e,c=n.sub(e),u=r.sub(n),h=i.sub(r),f=a.sub(i);let d="";return o.isZero||(d+=`${o.terabytes}TB `),c.isZero||(d+=`${c.gigabytes}GB `),u.isZero||(d+=`${u.megabytes}MB `),h.isZero||(d+=`${h.kilobytes}KB `),(!f.isZero||d==="")&&(d+=`${f.valueOf()}B`),d.trim()}static bytes(e=1){return new J(e)}static kilobytes(e=1){return J.bytes(e.valueOf()*1e3)}static megabytes(e=1){return J.kilobytes(e.valueOf()*1e3)}static gigabytes(e=1){return J.megabytes(e.valueOf()*1e3)}static terabytes(e){return J.gigabytes(e.valueOf()*1e3)}get isZero(){return this.valueOf()===0}};y(ae,"BYTE",new ae(1)),y(ae,"KILOBYTE",ae.kilobytes(1)),y(ae,"MEGABYTE",ae.megabytes(1)),y(ae,"GIGABYTE",ae.gigabytes(1)),y(ae,"TERABYTE",ae.terabytes(1)),y(ae,"ZERO",new ae(0)),y(ae,"z",s.z.union([s.z.number().transform(t=>new ae(t)),s.z.instanceof(ae)]));let Zt=ae;const Lc=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)]),Ma=t=>{const e=typeof t;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||t instanceof W||t instanceof Z||t instanceof Date},_c=(t,e,n,r=0)=>t.usesBigInt&&!e.usesBigInt?Number(n)-Number(r):!t.usesBigInt&&e.usesBigInt?BigInt(n.valueOf())-BigInt(r.valueOf()):zt(n,-r).valueOf(),Yc=t=>t==null?!1:Array.isArray(t)||t instanceof ArrayBuffer||ArrayBuffer.isView(t)&&!(t instanceof DataView)||t instanceof Da?!0:Ma(t),Pe=-1,rs={[Symbol.iterator]:()=>rs,next:()=>({done:!0,value:void 0})},qc=s.z.string().transform(t=>new Uint8Array(atob(t).split("").map(e=>e.charCodeAt(0))).buffer),Fc=s.z.union([s.z.null(),s.z.undefined()]).transform(()=>new Uint8Array().buffer),ss=10,St=class Ne{constructor(e){y(this,"key",""),y(this,"isSynnaxSeries",!0),y(this,"dataType"),y(this,"sampleOffset"),y(this,"gl"),y(this,"_data"),y(this,"_timeRange"),y(this,"alignment",0n),y(this,"_cachedMin"),y(this,"_cachedMax"),y(this,"writePos",Pe),y(this,"_refCount",0),y(this,"_cachedLength"),y(this,"_cachedIndexes"),Yc(e)&&(e={data:e});const{dataType:n,timeRange:r,sampleOffset:i=0,glBufferUsage:a="static",alignment:o=0n,key:c=Ra()}=e,u=e.data??[];if(u instanceof Ne||typeof u=="object"&&"isSynnaxSeries"in u&&u.isSynnaxSeries===!0){const d=u;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._cachedMin=d._cachedMin,this._cachedMax=d._cachedMax,this.writePos=d.writePos,this._refCount=d._refCount,this._cachedLength=d._cachedLength;return}const h=Ma(u),f=Array.isArray(u);if(n!=null)this.dataType=new j(n);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(f||h){let d=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.");d=u[0]}if(typeof d=="string")this.dataType=j.STRING;else if(typeof d=="number")this.dataType=j.FLOAT64;else if(typeof d=="bigint")this.dataType=j.INT64;else if(typeof d=="boolean")this.dataType=j.BOOLEAN;else if(d instanceof W||d instanceof Date||d instanceof W)this.dataType=j.TIMESTAMP;else if(typeof d=="object")this.dataType=j.JSON;else throw new Error(`cannot infer data type of ${typeof d} when constructing a Series from a JS array`)}else this.dataType=new j(u)}if(!f&&!h)this._data=u;else{let d=h?[u]:u;const k=d[0];(k instanceof W||k instanceof Date||k instanceof Z)&&(d=d.map(D=>new W(D).valueOf())),this.dataType.equals(j.STRING)?(this._cachedLength=d.length,this._data=new TextEncoder().encode(d.join(`
|
|
4
4
|
`)+`
|
|
5
5
|
`)):this.dataType.equals(j.JSON)?(this._cachedLength=d.length,this._data=new TextEncoder().encode(d.map(D=>On.encodeString(D)).join(`
|
|
6
6
|
`)+`
|
|
@@ -10,23 +10,23 @@
|
|
|
10
10
|
`)+`
|
|
11
11
|
`);return new Ne({data:r,dataType:j.JSON,timeRange:n})}acquire(e){this._refCount++,e!=null&&this.updateGLBuffer(e)}release(){if(this._refCount--,this._refCount===0&&this.gl.control!=null)this.maybeGarbageCollectGLBuffer(this.gl.control);else if(this._refCount<0)throw new Error("cannot release an array with a negative reference count")}write(e){if(!e.dataType.equals(this.dataType))throw new Error("buffer must be of the same type as this array");return this.dataType.isVariable?this.writeVariable(e):this.writeFixed(e)}writeVariable(e){if(this.writePos===Pe)return 0;const n=this.byteCapacity.valueOf()-this.writePos,r=e.subBytes(0,n);return this.writeToUnderlyingData(r),this.writePos+=r.byteLength.valueOf(),this._cachedLength!=null&&(this._cachedLength+=r.length,this.calculateCachedLength()),r.length}writeFixed(e){if(this.writePos===Pe)return 0;const n=this.capacity-this.writePos,r=e.sub(0,n);return this.writeToUnderlyingData(r),this._cachedLength=void 0,this.maybeRecomputeMinMax(r),this.writePos+=r.length,r.length}writeToUnderlyingData(e){this.underlyingData.set(e.data,this.writePos)}get buffer(){return this._data instanceof ArrayBuffer||this._data instanceof SharedArrayBuffer?this._data:this._data.buffer}get underlyingData(){return new this.dataType.Array(this._data)}get data(){return this.writePos===Pe?this.underlyingData:new this.dataType.Array(this._data,0,this.writePos)}toStrings(){if(!this.dataType.matches(j.STRING,j.UUID))throw new Error("cannot convert non-string series to strings");return new TextDecoder().decode(this.underlyingData).split(`
|
|
12
12
|
`).slice(0,-1)}toUUIDs(){if(!this.dataType.equals(j.UUID))throw new Error("cannot convert non-uuid series to uuids");const e=j.UUID.density.valueOf(),n=Array(this.length);for(let r=0;r<this.length;r++){const i=this.underlyingData.slice(r*e,(r+1)*e),a=Array.from(new Uint8Array(i),o=>o.toString(16).padStart(2,"0")).join("").replace(/(.{8})(.{4})(.{4})(.{4})(.{12})/,"$1-$2-$3-$4-$5");n[r]=a}return n}parseJSON(e){if(!this.dataType.equals(j.JSON))throw new Error("cannot convert non-string series to strings");return new TextDecoder().decode(this.underlyingData).split(`
|
|
13
|
-
`).slice(0,-1).map(n=>e.parse(On.decodeString(n)))}get timeRange(){if(this._timeRange==null)throw new Error("time range not set on series");return this._timeRange}get byteCapacity(){return new Zt(this.underlyingData.byteLength)}get capacity(){return this.dataType.isVariable?this.byteCapacity.valueOf():this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===Pe?this.byteCapacity:this.dataType.isVariable?new Zt(this.writePos):this.dataType.density.size(this.writePos)}get length(){return this._cachedLength!=null?this._cachedLength:this.dataType.isVariable?this.calculateCachedLength():this.writePos===Pe?this.data.length:this.writePos}calculateCachedLength(){if(!this.dataType.isVariable)throw new Error("cannot calculate length of a non-variable length data type");let e=0;const n=[0];return this.data.forEach((r,i)=>{r===ss&&(e++,n.push(i+1))}),this._cachedIndexes=n,this._cachedLength=e,e}convert(e,n=0){if(this.dataType.equals(e))return this;const r=new e.Array(this.length);for(let i=0;i<this.length;i++)r[i]=qc(this.dataType,e,this.data[i],n);return new Ne({data:r.buffer,dataType:e,timeRange:this._timeRange,sampleOffset:n,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment})}calcRawMax(){if(this.length===0)return-1/0;if(this.dataType.equals(j.TIMESTAMP))this._cachedMax=this.data[this.data.length-1];else if(this.dataType.usesBigInt){const e=this.data;this._cachedMax=e.reduce((n,r)=>n>r?n:r)}else{const e=this.data;this._cachedMax=e.reduce((n,r)=>n>r?n:r)}return this._cachedMax}get max(){if(this.dataType.isVariable)throw new Error("cannot calculate maximum on a variable length data type");return this.writePos===0?-1/0:(this._cachedMax==null&&(this._cachedMax=this.calcRawMax()),zt(this._cachedMax,this.sampleOffset))}calcRawMin(){if(this.length===0)return 1/0;if(this.dataType.equals(j.TIMESTAMP))this._cachedMin=this.data[0];else if(this.dataType.usesBigInt){const e=this.data;this._cachedMin=e.reduce((n,r)=>n<r?n:r)}else{const e=this.data;this._cachedMin=e.reduce((n,r)=>n<r?n:r)}return this._cachedMin}get min(){if(this.dataType.isVariable)throw new Error("cannot calculate minimum on a variable length data type");return this.writePos===0?1/0:(this._cachedMin==null&&(this._cachedMin=this.calcRawMin()),zt(this._cachedMin,this.sampleOffset))}get bounds(){return O.i(Number(this.min),Number(this.max))}maybeRecomputeMinMax(e){if(this._cachedMin!=null){const n=e._cachedMin??e.calcRawMin();n<this._cachedMin&&(this._cachedMin=n)}if(this._cachedMax!=null){const n=e._cachedMax??e.calcRawMax();n>this._cachedMax&&(this._cachedMax=n)}}enrich(){this.max,this.min}get range(){return zt(this.max,-this.min)}atAlignment(e,n){const r=Number(e-this.alignment);if(r<0||r>=this.length){if(n===!0)throw new Error(`[series] - no value at index ${r}`);return}return this.at(r,n)}at(e,n){if(this.dataType.isVariable)return this.atVariable(e,n??!1);e<0&&(e=this.length+e);const r=this.data[e];if(r==null){if(n===!0)throw new Error(`[series] - no value at index ${e}`);return}return zt(r,this.sampleOffset)}atVariable(e,n){let r=0,i=0;if(this._cachedIndexes!=null)r=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]===ss){if(e===0){i=o;break}r=o+1,e--}if(i===0&&(i=this.data.length),r>=i||e>0){if(n)throw new Error(`[series] - no value at index ${e}`);return}}const a=this.data.slice(r,i);return this.dataType.equals(j.STRING)?new TextDecoder().decode(a):O.k(JSON.parse(new TextDecoder().decode(a)))}binarySearch(e){let n=0,r=this.length-1;const i=or(e);for(;n<=r;){const a=Math.floor((n+r)/2),o=i(this.at(a,!0),e);if(o===0)return a;o<0?n=a+1:r=a-1}return n}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals(j.FLOAT32))throw new Error("Only FLOAT32 arrays can be used in WebGL");const{buffer:n,bufferUsage:r,prevBuffer:i}=this.gl;if(n==null&&(this.gl.buffer=e.createBuffer()),this.writePos!==i)if(e.bindBuffer(e.ARRAY_BUFFER,this.gl.buffer),this.writePos!==Pe){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.underlyingData,r==="static"?e.STATIC_DRAW:e.DYNAMIC_DRAW),this.gl.prevBuffer=Pe}as(e){if(e==="string"){if(!this.dataType.equals(j.STRING))throw new Error(`cannot convert series of type ${this.dataType.toString()} to string`);return this}if(e==="number"){if(!this.dataType.isNumeric)throw new Error(`cannot convert series of type ${this.dataType.toString()} to number`);return this}if(e==="bigint"){if(!this.dataType.equals(j.INT64))throw new Error(`cannot convert series of type ${this.dataType.toString()} to bigint`);return this}throw new Error(`cannot convert series to ${e}`)}get digest(){var e;return{key:this.key,dataType:this.dataType.toString(),sampleOffset:this.sampleOffset,alignment:this.alignmentBounds,timeRange:(e=this._timeRange)==null?void 0:e.toString(),length:this.length,capacity:this.capacity}}get memInfo(){return{key:this.key,length:this.length,byteLength:this.byteLength,glBuffer:this.gl.buffer!=null}}get alignmentBounds(){return O.i(this.alignment,this.alignment+BigInt(this.length))}maybeGarbageCollectGLBuffer(e){this.gl.buffer!=null&&(e.deleteBuffer(this.gl.buffer),this.gl.buffer=null,this.gl.prevBuffer=0,this.gl.control=null)}get glBuffer(){if(this.gl.buffer==null)throw new Error("gl buffer not initialized");return this.gl.prevBuffer!==this.writePos&&console.warn("buffer not updated"),this.gl.buffer}[Symbol.iterator](){if(this.dataType.isVariable){const e=new Zc(this);return this.dataType.equals(j.JSON)?new Kc(e):e}return new Jc(this)}slice(e,n){return this.sliceSub(!1,e,n)}sub(e,n){return this.sliceSub(!0,e,n)}subIterator(e,n){return new di(this,e,n??this.length)}subAlignmentIterator(e,n){return new di(this,Number(e-this.alignment),Number(n-this.alignment))}subBytes(e,n){if(e>=0&&(n==null||n>=this.byteLength.valueOf()))return this;const r=this.data.subarray(e,n);return new Ne({data:r,dataType:this.dataType,timeRange:this._timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(e)})}sliceSub(e,n,r){if(n<=0&&(r==null||r>=this.length))return this;let i;return e?i=this.data.subarray(n,r):i=this.data.slice(n,r),new Ne({data:i,dataType:this.dataType,timeRange:this._timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(n)})}reAlign(e){return new Ne({data:this.buffer,dataType:this.dataType,timeRange:it.ZERO,sampleOffset:this.sampleOffset,glBufferUsage:"static",alignment:e})}};y(St,"crudeZ",s.z.object({timeRange:it.z.optional(),dataType:j.z,alignment:$a.optional(),data:s.z.union([Wc,Gc,s.z.instanceof(ArrayBuffer)]),glBufferUsage:Yc.optional().default("static").optional()})),y(St,"z",St.crudeZ.transform(t=>new St(t)));let Da=St,di=class{constructor(e,n,r){y(this,"series"),y(this,"end"),y(this,"index"),this.series=e;const i=O.i(0,e.length);this.end=O.T(i,r),this.index=O.T(i,n)}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}[Symbol.iterator](){return this}},Zc=class{constructor(e){if(y(this,"series"),y(this,"index"),y(this,"decoder"),!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,n=this.series.data;for(;this.index<n.length&&n[this.index]!==ss;)this.index++;const r=this.index;return e===r?{done:!0,value:void 0}:(this.index++,{done:!1,value:this.decoder.decode(this.series.buffer.slice(e,r))})}[Symbol.iterator](){return this}};var fi,yi;let Kc=class{constructor(e){y(this,"wrapped"),y(this,fi,"JSONSeriesIterator"),this.wrapped=e}next(){const e=this.wrapped.next();return e.done===!0?{done:!0,value:void 0}:{done:!1,value:On.decodeString(e.value)}}[(yi=Symbol.iterator,fi=Symbol.toStringTag,yi)](){return this}};var gi,pi;let Jc=class{constructor(e){y(this,"series"),y(this,"index"),y(this,gi,"SeriesIterator"),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)}}[(pi=Symbol.iterator,gi=Symbol.toStringTag,pi)](){return this}};const zt=(t,e)=>typeof t=="bigint"&&typeof e=="bigint"||typeof t=="number"&&typeof e=="number"?t+e:e===0?t:t===0?e:Number(t)+Number(e);let Hc=class{constructor(e){if(y(this,"series"),e.length!==0){const n=e[0].dataType;for(let r=1;r<e.length;r++)if(!e[r].dataType.equals(n))throw new Error("[multi-series] - series must have the same data type")}this.series=e}as(e){if(!new j(e).equals(this.dataType))throw new Error(`cannot convert series of type ${this.dataType.toString()} to ${e.toString()}`);return this}get dataType(){return this.series.length===0?j.UNKNOWN:this.series[0].dataType}get timeRange(){return this.series.length===0?it.ZERO:new it(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?O.i(0n,0n):O.i(this.series[0].alignmentBounds.lower,this.series[this.series.length-1].alignmentBounds.upper)}push(e){this.series.push(e)}get length(){return this.series.reduce((e,n)=>e+n.length,0)}atAlignment(e,n){if(this.series.length===0){if(n)throw new Error(`[series] - no value at alignment ${e}`);return}for(const r of this.series)if(O.a(r.alignmentBounds,e))return r.atAlignment(e,n);if(n)throw new Error(`[series] - no value at alignment ${e}`)}at(e,n=!1){e<0&&(e=this.length+e);for(const r of this.series){if(e<r.length)return r.at(e,n);e-=r.length}if(n)throw new Error(`[series] - no value at index ${e}`)}subIterator(e,n){return new Ir(this,e,n??this.length)}subAlignmentIterator(e,n){if(e>=this.alignmentBounds.upper||n<=this.alignmentBounds.lower)return rs;let r=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)r+=o.length;else if(O.a(o.alignmentBounds,e)){r+=Number(e-o.alignment);break}}let i=0;for(let a=0;a<this.series.length;a++){const o=this.series[a];if(n<o.alignment)break;if(n>=o.alignmentBounds.upper)i+=o.length;else if(O.a(o.alignmentBounds,n)){i+=Number(n-o.alignment);break}}return new Ir(this,r,i)}subAlignmentSpanIterator(e,n){if(e>=this.alignmentBounds.upper)return rs;let r=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)r+=a.length;else if(O.a(a.alignmentBounds,e)){r+=Number(e-a.alignment);break}}return new Ir(this,r,r+n)}get byteLength(){return new Zt(this.series.reduce((e,n)=>e+n.byteLength.valueOf(),0))}get data(){const e=new this.dataType.Array(this.length);let n=0;for(const r of this.series)e.set(r.data,n),n+=r.length;return new this.dataType.Array(e)}traverseAlignment(e,n){const r=this.series.map(i=>i.alignmentBounds);return O.k$1(r,e,n)}distance(e,n){const r=this.series.map(i=>i.alignmentBounds);return O.U(r,e,n)}[Symbol.iterator](){return this.series.length===0?{next(){return{done:!0,value:void 0}}}:new Xc(this.series)}};var mi,wi;class Xc{constructor(e){y(this,"series"),y(this,"seriesIndex"),y(this,"internal"),y(this,mi,"MultiSeriesIterator"),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())}[(wi=Symbol.iterator,mi=Symbol.toStringTag,wi)](){return this}}let Ir=class{constructor(e,n,r){y(this,"series"),y(this,"index"),y(this,"end"),this.series=e,this.end=r,this.index=n}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}[Symbol.iterator](){return this}};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 Pa=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser",Qc=Pa(),Ua=["MacOS","Windows","Linux","Docker"],eu=s.z.enum(Ua);let Er;const tu=()=>{if(typeof window>"u")return;const t=window.navigator.userAgent.toLowerCase();if(t.includes("mac"))return"MacOS";if(t.includes("win"))return"Windows";if(t.includes("linux"))return"Linux"},nu=(t={})=>{const{force:e,default:n}=t;return e??Er??(Er=tu(),Er??n)},La=Object.freeze(Object.defineProperty({__proto__:null,OPERATING_SYSTEMS:Ua,RUNTIME:Qc,detect:Pa,getOS:nu,osZ:eu},Symbol.toStringTag,{value:"Module"})),ru=t=>Array.isArray(t)?t:[t],su=t=>Array.isArray(t)?t:t===null?[]:[t];var iu=Object.defineProperty,au=(t,e,n)=>e in t?iu(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Nt=(t,e,n)=>au(t,typeof e!="symbol"?e+"":e,n);const ou=(...t)=>t.map(_a).join(""),_a=t=>(t.endsWith("/")||(t+="/"),t.startsWith("/")&&(t=t.slice(1)),t),lu=t=>t.endsWith("/")?t.slice(0,-1):t,bi=class is{constructor({host:e,port:n,protocol:r="",pathPrefix:i=""}){Nt(this,"protocol"),Nt(this,"host"),Nt(this,"port"),Nt(this,"path"),this.protocol=r,this.host=e,this.port=n,this.path=_a(i)}replace(e){return new is({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new is({...this,pathPrefix:ou(this.path,e)})}toString(){return lu(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}};Nt(bi,"UNKNOWN",new bi({host:"unknown",port:0}));var cu=Object.defineProperty,uu=(t,e,n)=>e in t?cu(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Qn=(t,e,n)=>uu(t,typeof e!="symbol"?e+"":e,n);let hu=class{constructor(e){Qn(this,"sender"),Qn(this,"handlers"),this.sender=e,this.handlers=new Map}handle({data:e}){var n;const r=(n=this.handlers.get(e.type))==null?void 0:n.handler;r==null?console.warn(`No handler for ${e.type}`):r(e.payload)}route(e){const n=du(e,this.sender),r=new fu(n);return this.handlers.set(e,r),r}};const du=(t,e)=>(n,r)=>e({type:t,payload:n},r);let fu=class{constructor(e){Qn(this,"_send"),Qn(this,"handler"),this._send=e,this.handler=null}send(e,n=[]){this._send(e,n)}handle(e){this.handler=e}};var yu=Object.defineProperty,gu=(t,e,n)=>e in t?yu(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,In=(t,e,n)=>gu(t,typeof e!="symbol"?e+"":e,n);const Ge=class extends Number{};In(Ge,"Absolute",255),In(Ge,"Default",1),In(Ge,"z",s.z.union([s.z.instanceof(Ge),s.z.number().int().min(0).max(255).transform(t=>new Ge(t)),s.z.instanceof(Number).transform(t=>new Ge(t))]));let Ya=Ge;const Fa=s.z.object({name:s.z.string(),key:s.z.string()}),pu=t=>s.z.object({subject:Fa,resource:t,authority:Ya.z}),mu=(...t)=>e=>e.filter(n=>{let r=!1;return n.to!=null&&(r=t.includes(n.to.resource)),n.from!=null&&!r&&(r=t.includes(n.from.resource)),r}),wu=Object.freeze(Object.defineProperty({__proto__:null,Authority:Ya,filterTransfersByChannelKey:mu,stateZ:pu,subjectZ:Fa},Symbol.toStringTag,{value:"Module"})),qa=class It extends Error{constructor(){super(It.MESSAGE)}matches(e){return typeof e=="string"?e.includes(It.MESSAGE):e instanceof It||e.message.includes(It.MESSAGE)}};In(qa,"MESSAGE","canceled");let bu=qa;new bu;const vu=t=>t?-1:1,as=s.z.string().regex(/^\d+\.\d+\.\d+$/),nn=(t,e,n={})=>{n.checkMajor??(n.checkMajor=!0),n.checkMinor??(n.checkMinor=!0),n.checkPatch??(n.checkPatch=!0);const r=as.parse(t),i=as.parse(e),[a,o,c]=r.split(".").map(Number),[u,h,f]=i.split(".").map(Number);if(n.checkMajor){if(a<u)return Tn;if(a>u)return Sn}if(n.checkMinor){if(o<h)return Tn;if(o>h)return Sn}if(n.checkPatch){if(c<f)return Tn;if(c>f)return Sn}return ht},Ou=(t,e,n={})=>Ea(nn(t,e,n)),Va=(t,e,n={})=>Ia(nn(t,e,n)),Tu=(t,e,n={})=>Na(nn(t,e,n)),Su=({name:t,migrate:e})=>n=>{try{const r=e(n);return console.log(`${t} migrated: ${n.version} -> ${r.version}`),r}catch(r){throw console.log(`${t} failed to migrate from ${n.version}`),console.error(r),r}},zu=({name:t,migrations:e,targetSchema:n,defaultVersion:r,def:i})=>{const a=Object.keys(e).sort(nn).pop();if(a==null)return h=>{if(h.version==null&&(h.version=r),h.version!==i.version)return console.log(`${t} version ${h.version} is newer than latest version of ${i.version}.
|
|
13
|
+
`).slice(0,-1).map(n=>e.parse(On.decodeString(n)))}get timeRange(){if(this._timeRange==null)throw new Error("time range not set on series");return this._timeRange}get byteCapacity(){return new Zt(this.underlyingData.byteLength)}get capacity(){return this.dataType.isVariable?this.byteCapacity.valueOf():this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===Pe?this.byteCapacity:this.dataType.isVariable?new Zt(this.writePos):this.dataType.density.size(this.writePos)}get length(){return this._cachedLength!=null?this._cachedLength:this.dataType.isVariable?this.calculateCachedLength():this.writePos===Pe?this.data.length:this.writePos}calculateCachedLength(){if(!this.dataType.isVariable)throw new Error("cannot calculate length of a non-variable length data type");let e=0;const n=[0];return this.data.forEach((r,i)=>{r===ss&&(e++,n.push(i+1))}),this._cachedIndexes=n,this._cachedLength=e,e}convert(e,n=0){if(this.dataType.equals(e))return this;const r=new e.Array(this.length);for(let i=0;i<this.length;i++)r[i]=_c(this.dataType,e,this.data[i],n);return new Ne({data:r.buffer,dataType:e,timeRange:this._timeRange,sampleOffset:n,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment})}calcRawMax(){if(this.length===0)return-1/0;if(this.dataType.equals(j.TIMESTAMP))this._cachedMax=this.data[this.data.length-1];else if(this.dataType.usesBigInt){const e=this.data;this._cachedMax=e.reduce((n,r)=>n>r?n:r)}else{const e=this.data;this._cachedMax=e.reduce((n,r)=>n>r?n:r)}return this._cachedMax}get max(){if(this.dataType.isVariable)throw new Error("cannot calculate maximum on a variable length data type");return this.writePos===0?-1/0:(this._cachedMax==null&&(this._cachedMax=this.calcRawMax()),zt(this._cachedMax,this.sampleOffset))}calcRawMin(){if(this.length===0)return 1/0;if(this.dataType.equals(j.TIMESTAMP))this._cachedMin=this.data[0];else if(this.dataType.usesBigInt){const e=this.data;this._cachedMin=e.reduce((n,r)=>n<r?n:r)}else{const e=this.data;this._cachedMin=e.reduce((n,r)=>n<r?n:r)}return this._cachedMin}get min(){if(this.dataType.isVariable)throw new Error("cannot calculate minimum on a variable length data type");return this.writePos===0?1/0:(this._cachedMin==null&&(this._cachedMin=this.calcRawMin()),zt(this._cachedMin,this.sampleOffset))}get bounds(){return O.i(Number(this.min),Number(this.max))}maybeRecomputeMinMax(e){if(this._cachedMin!=null){const n=e._cachedMin??e.calcRawMin();n<this._cachedMin&&(this._cachedMin=n)}if(this._cachedMax!=null){const n=e._cachedMax??e.calcRawMax();n>this._cachedMax&&(this._cachedMax=n)}}enrich(){this.max,this.min}get range(){return zt(this.max,-this.min)}atAlignment(e,n){const r=Number(e-this.alignment);if(r<0||r>=this.length){if(n===!0)throw new Error(`[series] - no value at index ${r}`);return}return this.at(r,n)}at(e,n){if(this.dataType.isVariable)return this.atVariable(e,n??!1);e<0&&(e=this.length+e);const r=this.data[e];if(r==null){if(n===!0)throw new Error(`[series] - no value at index ${e}`);return}return zt(r,this.sampleOffset)}atVariable(e,n){let r=0,i=0;if(this._cachedIndexes!=null)r=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]===ss){if(e===0){i=o;break}r=o+1,e--}if(i===0&&(i=this.data.length),r>=i||e>0){if(n)throw new Error(`[series] - no value at index ${e}`);return}}const a=this.data.slice(r,i);return this.dataType.equals(j.STRING)?new TextDecoder().decode(a):O.k(JSON.parse(new TextDecoder().decode(a)))}binarySearch(e){let n=0,r=this.length-1;const i=or(e);for(;n<=r;){const a=Math.floor((n+r)/2),o=i(this.at(a,!0),e);if(o===0)return a;o<0?n=a+1:r=a-1}return n}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals(j.FLOAT32))throw new Error("Only FLOAT32 arrays can be used in WebGL");const{buffer:n,bufferUsage:r,prevBuffer:i}=this.gl;if(n==null&&(this.gl.buffer=e.createBuffer()),this.writePos!==i)if(e.bindBuffer(e.ARRAY_BUFFER,this.gl.buffer),this.writePos!==Pe){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.underlyingData,r==="static"?e.STATIC_DRAW:e.DYNAMIC_DRAW),this.gl.prevBuffer=Pe}as(e){if(e==="string"){if(!this.dataType.equals(j.STRING))throw new Error(`cannot convert series of type ${this.dataType.toString()} to string`);return this}if(e==="number"){if(!this.dataType.isNumeric)throw new Error(`cannot convert series of type ${this.dataType.toString()} to number`);return this}if(e==="bigint"){if(!this.dataType.equals(j.INT64))throw new Error(`cannot convert series of type ${this.dataType.toString()} to bigint`);return this}throw new Error(`cannot convert series to ${e}`)}get digest(){var e;return{key:this.key,dataType:this.dataType.toString(),sampleOffset:this.sampleOffset,alignment:this.alignmentBounds,timeRange:(e=this._timeRange)==null?void 0:e.toString(),length:this.length,capacity:this.capacity}}get memInfo(){return{key:this.key,length:this.length,byteLength:this.byteLength,glBuffer:this.gl.buffer!=null}}get alignmentBounds(){return O.i(this.alignment,this.alignment+BigInt(this.length))}maybeGarbageCollectGLBuffer(e){this.gl.buffer!=null&&(e.deleteBuffer(this.gl.buffer),this.gl.buffer=null,this.gl.prevBuffer=0,this.gl.control=null)}get glBuffer(){if(this.gl.buffer==null)throw new Error("gl buffer not initialized");return this.gl.prevBuffer!==this.writePos&&console.warn("buffer not updated"),this.gl.buffer}[Symbol.iterator](){if(this.dataType.isVariable){const e=new Vc(this);return this.dataType.equals(j.JSON)?new Wc(e):e}return new Gc(this)}slice(e,n){return this.sliceSub(!1,e,n)}sub(e,n){return this.sliceSub(!0,e,n)}subIterator(e,n){return new di(this,e,n??this.length)}subAlignmentIterator(e,n){return new di(this,Number(e-this.alignment),Number(n-this.alignment))}subBytes(e,n){if(e>=0&&(n==null||n>=this.byteLength.valueOf()))return this;const r=this.data.subarray(e,n);return new Ne({data:r,dataType:this.dataType,timeRange:this._timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(e)})}sliceSub(e,n,r){if(n<=0&&(r==null||r>=this.length))return this;let i;return e?i=this.data.subarray(n,r):i=this.data.slice(n,r),new Ne({data:i,dataType:this.dataType,timeRange:this._timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(n)})}reAlign(e){return new Ne({data:this.buffer,dataType:this.dataType,timeRange:it.ZERO,sampleOffset:this.sampleOffset,glBufferUsage:"static",alignment:e})}};y(St,"crudeZ",s.z.object({timeRange:it.z.optional(),dataType:j.z,alignment:$a.optional(),data:s.z.union([qc,Fc,s.z.instanceof(ArrayBuffer)]),glBufferUsage:Uc.optional().default("static").optional()})),y(St,"z",St.crudeZ.transform(t=>new St(t)));let Da=St,di=class{constructor(e,n,r){y(this,"series"),y(this,"end"),y(this,"index"),this.series=e;const i=O.i(0,e.length);this.end=O.T(i,r),this.index=O.T(i,n)}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}[Symbol.iterator](){return this}},Vc=class{constructor(e){if(y(this,"series"),y(this,"index"),y(this,"decoder"),!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,n=this.series.data;for(;this.index<n.length&&n[this.index]!==ss;)this.index++;const r=this.index;return e===r?{done:!0,value:void 0}:(this.index++,{done:!1,value:this.decoder.decode(this.series.buffer.slice(e,r))})}[Symbol.iterator](){return this}};var fi,yi;let Wc=class{constructor(e){y(this,"wrapped"),y(this,fi,"JSONSeriesIterator"),this.wrapped=e}next(){const e=this.wrapped.next();return e.done===!0?{done:!0,value:void 0}:{done:!1,value:On.decodeString(e.value)}}[(yi=Symbol.iterator,fi=Symbol.toStringTag,yi)](){return this}};var gi,pi;let Gc=class{constructor(e){y(this,"series"),y(this,"index"),y(this,gi,"SeriesIterator"),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)}}[(pi=Symbol.iterator,gi=Symbol.toStringTag,pi)](){return this}};const zt=(t,e)=>typeof t=="bigint"&&typeof e=="bigint"||typeof t=="number"&&typeof e=="number"?t+e:e===0?t:t===0?e:Number(t)+Number(e);let Zc=class{constructor(e){if(y(this,"series"),e.length!==0){const n=e[0].dataType;for(let r=1;r<e.length;r++)if(!e[r].dataType.equals(n))throw new Error("[multi-series] - series must have the same data type")}this.series=e}as(e){if(!new j(e).equals(this.dataType))throw new Error(`cannot convert series of type ${this.dataType.toString()} to ${e.toString()}`);return this}get dataType(){return this.series.length===0?j.UNKNOWN:this.series[0].dataType}get timeRange(){return this.series.length===0?it.ZERO:new it(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?O.i(0n,0n):O.i(this.series[0].alignmentBounds.lower,this.series[this.series.length-1].alignmentBounds.upper)}push(e){this.series.push(e)}get length(){return this.series.reduce((e,n)=>e+n.length,0)}atAlignment(e,n){if(this.series.length===0){if(n)throw new Error(`[series] - no value at alignment ${e}`);return}for(const r of this.series)if(O.a(r.alignmentBounds,e))return r.atAlignment(e,n);if(n)throw new Error(`[series] - no value at alignment ${e}`)}at(e,n=!1){e<0&&(e=this.length+e);for(const r of this.series){if(e<r.length)return r.at(e,n);e-=r.length}if(n)throw new Error(`[series] - no value at index ${e}`)}subIterator(e,n){return new Ir(this,e,n??this.length)}subAlignmentIterator(e,n){if(e>=this.alignmentBounds.upper||n<=this.alignmentBounds.lower)return rs;let r=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)r+=o.length;else if(O.a(o.alignmentBounds,e)){r+=Number(e-o.alignment);break}}let i=0;for(let a=0;a<this.series.length;a++){const o=this.series[a];if(n<o.alignment)break;if(n>=o.alignmentBounds.upper)i+=o.length;else if(O.a(o.alignmentBounds,n)){i+=Number(n-o.alignment);break}}return new Ir(this,r,i)}subAlignmentSpanIterator(e,n){if(e>=this.alignmentBounds.upper)return rs;let r=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)r+=a.length;else if(O.a(a.alignmentBounds,e)){r+=Number(e-a.alignment);break}}return new Ir(this,r,r+n)}get byteLength(){return new Zt(this.series.reduce((e,n)=>e+n.byteLength.valueOf(),0))}get data(){const e=new this.dataType.Array(this.length);let n=0;for(const r of this.series)e.set(r.data,n),n+=r.length;return new this.dataType.Array(e)}traverseAlignment(e,n){const r=this.series.map(i=>i.alignmentBounds);return O.k$1(r,e,n)}distance(e,n){const r=this.series.map(i=>i.alignmentBounds);return O.U(r,e,n)}[Symbol.iterator](){return this.series.length===0?{next(){return{done:!0,value:void 0}}}:new Kc(this.series)}};var mi,wi;class Kc{constructor(e){y(this,"series"),y(this,"seriesIndex"),y(this,"internal"),y(this,mi,"MultiSeriesIterator"),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())}[(wi=Symbol.iterator,mi=Symbol.toStringTag,wi)](){return this}}let Ir=class{constructor(e,n,r){y(this,"series"),y(this,"index"),y(this,"end"),this.series=e,this.end=r,this.index=n}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}[Symbol.iterator](){return this}};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 Pa=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser",Jc=Pa(),Ua=["MacOS","Windows","Linux","Docker"],Hc=s.z.enum(Ua);let Er;const Xc=()=>{if(typeof window>"u")return;const t=window.navigator.userAgent.toLowerCase();if(t.includes("mac"))return"MacOS";if(t.includes("win"))return"Windows";if(t.includes("linux"))return"Linux"},Qc=(t={})=>{const{force:e,default:n}=t;return e??Er??(Er=Xc(),Er??n)},La=Object.freeze(Object.defineProperty({__proto__:null,OPERATING_SYSTEMS:Ua,RUNTIME:Jc,detect:Pa,getOS:Qc,osZ:Hc},Symbol.toStringTag,{value:"Module"})),eu=t=>Array.isArray(t)?t:[t],tu=t=>Array.isArray(t)?t:t===null?[]:[t];var nu=Object.defineProperty,ru=(t,e,n)=>e in t?nu(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Nt=(t,e,n)=>ru(t,typeof e!="symbol"?e+"":e,n);const su=(...t)=>t.map(_a).join(""),_a=t=>(t.endsWith("/")||(t+="/"),t.startsWith("/")&&(t=t.slice(1)),t),iu=t=>t.endsWith("/")?t.slice(0,-1):t,bi=class is{constructor({host:e,port:n,protocol:r="",pathPrefix:i=""}){Nt(this,"protocol"),Nt(this,"host"),Nt(this,"port"),Nt(this,"path"),this.protocol=r,this.host=e,this.port=n,this.path=_a(i)}replace(e){return new is({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new is({...this,pathPrefix:su(this.path,e)})}toString(){return iu(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}};Nt(bi,"UNKNOWN",new bi({host:"unknown",port:0}));var au=Object.defineProperty,ou=(t,e,n)=>e in t?au(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Qn=(t,e,n)=>ou(t,typeof e!="symbol"?e+"":e,n);let lu=class{constructor(e){Qn(this,"sender"),Qn(this,"handlers"),this.sender=e,this.handlers=new Map}handle({data:e}){var n;const r=(n=this.handlers.get(e.type))==null?void 0:n.handler;r==null?console.warn(`No handler for ${e.type}`):r(e.payload)}route(e){const n=cu(e,this.sender),r=new uu(n);return this.handlers.set(e,r),r}};const cu=(t,e)=>(n,r)=>e({type:t,payload:n},r);let uu=class{constructor(e){Qn(this,"_send"),Qn(this,"handler"),this._send=e,this.handler=null}send(e,n=[]){this._send(e,n)}handle(e){this.handler=e}};var hu=Object.defineProperty,du=(t,e,n)=>e in t?hu(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,In=(t,e,n)=>du(t,typeof e!="symbol"?e+"":e,n);const Ge=class extends Number{};In(Ge,"Absolute",255),In(Ge,"Default",1),In(Ge,"z",s.z.union([s.z.instanceof(Ge),s.z.number().int().min(0).max(255).transform(t=>new Ge(t)),s.z.instanceof(Number).transform(t=>new Ge(t))]));let Ya=Ge;const qa=s.z.object({name:s.z.string(),key:s.z.string()}),fu=t=>s.z.object({subject:qa,resource:t,authority:Ya.z}),yu=(...t)=>e=>e.filter(n=>{let r=!1;return n.to!=null&&(r=t.includes(n.to.resource)),n.from!=null&&!r&&(r=t.includes(n.from.resource)),r}),gu=Object.freeze(Object.defineProperty({__proto__:null,Authority:Ya,filterTransfersByChannelKey:yu,stateZ:fu,subjectZ:qa},Symbol.toStringTag,{value:"Module"})),Fa=class It extends Error{constructor(){super(It.MESSAGE)}matches(e){return typeof e=="string"?e.includes(It.MESSAGE):e instanceof It||e.message.includes(It.MESSAGE)}};In(Fa,"MESSAGE","canceled");let pu=Fa;new pu;const mu=t=>t?-1:1,as=s.z.string().regex(/^\d+\.\d+\.\d+$/),nn=(t,e,n={})=>{n.checkMajor??(n.checkMajor=!0),n.checkMinor??(n.checkMinor=!0),n.checkPatch??(n.checkPatch=!0);const r=as.parse(t),i=as.parse(e),[a,o,c]=r.split(".").map(Number),[u,h,f]=i.split(".").map(Number);if(n.checkMajor){if(a<u)return Tn;if(a>u)return Sn}if(n.checkMinor){if(o<h)return Tn;if(o>h)return Sn}if(n.checkPatch){if(c<f)return Tn;if(c>f)return Sn}return ht},wu=(t,e,n={})=>Ea(nn(t,e,n)),Va=(t,e,n={})=>Ia(nn(t,e,n)),bu=(t,e,n={})=>Na(nn(t,e,n)),vu=({name:t,migrate:e})=>n=>{try{const r=e(n);return console.log(`${t} migrated: ${n.version} -> ${r.version}`),r}catch(r){throw console.log(`${t} failed to migrate from ${n.version}`),console.error(r),r}},Ou=({name:t,migrations:e,targetSchema:n,defaultVersion:r,def:i})=>{const a=Object.keys(e).sort(nn).pop();if(a==null)return h=>{if(h.version==null&&(h.version=r),h.version!==i.version)return console.log(`${t} version ${h.version} is newer than latest version of ${i.version}.
|
|
14
14
|
Returning default instead.
|
|
15
|
-
`),i;try{return n!=null?n.parse(h):h}catch(f){return console.log(`${t} failed to parse default. Exiting with default`),console.error(f),i}};const o=Object.keys(e).length;let c=!1;const u=h=>{try{if(o===0||Va(h.version,a))return console.log(c?`${t} ${h.version} now up to date`:`${t} version ${h.version} is up to date with target version ${i.version}`),h;const f=h.version,d=e[f],k=d(h);return c=!0,u(k)}catch(f){return console.log(`${t} failed to migrate from ${h.version} to ${a}`),console.error(f),i}};return h=>{try{if(h.version==null)if(r!=null)console.log(`${t} version is null. Setting version to default of ${r}`),h.version=r;else return console.log(`${t} version is null and no default version set. Exiting with default`),i;return u(h)}catch(f){return console.log(`${t} failed to parse final result. Exiting with default`),console.error(f),i}}},
|
|
15
|
+
`),i;try{return n!=null?n.parse(h):h}catch(f){return console.log(`${t} failed to parse default. Exiting with default`),console.error(f),i}};const o=Object.keys(e).length;let c=!1;const u=h=>{try{if(o===0||Va(h.version,a))return console.log(c?`${t} ${h.version} now up to date`:`${t} version ${h.version} is up to date with target version ${i.version}`),h;const f=h.version,d=e[f],k=d(h);return c=!0,u(k)}catch(f){return console.log(`${t} failed to migrate from ${h.version} to ${a}`),console.error(f),i}};return h=>{try{if(h.version==null)if(r!=null)console.log(`${t} version is null. Setting version to default of ${r}`),h.version=r;else return console.log(`${t} version is null and no default version set. Exiting with default`),i;return u(h)}catch(f){return console.log(`${t} failed to parse final result. Exiting with default`),console.error(f),i}}},Tu=Object.freeze(Object.defineProperty({__proto__:null,compareSemVer:nn,createMigration:vu,migrator:Ou,semVerNewer:Va,semVerOlder:bu,semVerZ:as,versionsEqual:wu},Symbol.toStringTag,{value:"Module"})),Su=t=>{if(t===void 0||typeof t=="string"||typeof t=="number")return t;if(t.toString===void 0)throw new Error("invalid renderer");return t.toString()},zu=t=>Array.isArray(t)?[...t]:typeof t=="object"&&t!==null?{...t}:t,js=t=>typeof t=="function",Bs=(t,e)=>js(t)?t(e):t,rn=t=>Wa(t)?t():t,Wa=t=>typeof t=="function",Ga=({initial:t,value:e,onChange:n})=>{const[r,i]=$s.useState(rn(e??t));return e!=null&&n!=null?[e,n]:[r,i]},Za=({initial:t,value:e,onChange:n})=>{const[r,i]=$s.useState(rn(e??t));return e!=null&&n!=null?[e,n]:[r,i]},Nu=(t,e)=>{const[n,r]=$s.useState(()=>{const i=localStorage.getItem(e);return i==null?rn(t):JSON.parse(i)});return[n,i=>{r(i),localStorage.setItem(e,JSON.stringify(i))}]},Iu=Object.freeze(Object.defineProperty({__proto__:null,executeInitialSetter:rn,executeSetter:Bs,isInitialSetter:Wa,isSetter:js,usePassthrough:Ga,usePersisted:Nu,usePurePassthrough:Za},Symbol.toStringTag,{value:"Module"})),Ka=["h1","h2","h3","h4","h5","p","small"],Eu=s.z.enum(Ka),Au={h1:"h2",h2:"h3",h3:"h4",h4:"h5",h5:"p",p:"small",small:"small"},ku=t=>Au[t],xu={h1:"h1",h2:"h1",h3:"h2",h4:"h3",h5:"h4",p:"h5",small:"p"},Cu=t=>xu[t],Ye=s.z.object({size:s.z.number(),weight:s.z.union([s.z.number(),s.z.string()]),lineHeight:s.z.number(),textTransform:s.z.string().optional()}),Ja={small:"small",medium:"p",large:"h5",huge:"h2"},$u={h1:"huge",h2:"huge",h3:"huge",h4:"large",h5:"small",p:"medium",small:"small"};let Ar=null;const Ru=()=>(Ar==null&&(Ar=document.createElement("canvas")),Ar),ju=(t,e,n)=>{if(La.RUNTIME==="node")return{width:0,height:0};n==null&&(n=Ru().getContext("2d")),n.font=e;const r=n.measureText(t);return{width:Math.trunc(Math.abs(r.actualBoundingBoxLeft)+Math.abs(r.actualBoundingBoxRight)),height:Math.trunc(Math.abs(r.actualBoundingBoxAscent)+Math.abs(r.actualBoundingBoxDescent))}},Bu=s.z.object({l0:O.Color.z,l1:O.Color.z,l2:O.Color.z,l3:O.Color.z,l4:O.Color.z,l5:O.Color.z,l6:O.Color.z,l7:O.Color.z,l8:O.Color.z,l9:O.Color.z,l10:O.Color.z}),we=(t,e)=>[t[0],t[1],e,t[3]],Mu=s.z.object({m2:O.Color.z,m1:O.Color.z,z:O.Color.z,p1:O.Color.z,p2:O.Color.z}),fn=Mu.or(O.Color.z.transform(t=>{const e=t.hsla;return{m2:new O.Color(O.fromHSLA(we(e,40))),m1:new O.Color(O.fromHSLA(we(e,45))),z:t,p1:new O.Color(O.fromHSLA(we(e,55))),p2:new O.Color(O.fromHSLA(we(e,65)))}})),Ha=s.z.object({name:s.z.string(),key:s.z.string(),colors:s.z.object({border:O.Color.z,primary:fn,gray:Bu,error:fn,secondary:fn,warning:fn,visualization:s.z.object({palettes:s.z.record(s.z.array(O.Color.z))}).optional().default({palettes:{}}),white:O.Color.z,black:O.Color.z,text:O.Color.z,textInverted:O.Color.z,textOnPrimary:O.Color.z.optional().default(O.ZERO),logo:s.z.string()}),sizes:s.z.object({base:s.z.number(),border:s.z.object({radius:s.z.number(),width:s.z.number()}),schematic:s.z.object({elementStrokeWidth:s.z.number()})}),typography:s.z.object({family:s.z.string(),codeFamily:s.z.string(),h1:Ye,h2:Ye,h3:Ye,h4:Ye,h5:Ye,p:Ye,small:Ye})}).transform(t=>((t.colors.textOnPrimary==null||t.colors.textOnPrimary.isZero)&&(t.colors.textOnPrimary=t.colors.primary.z.pickByContrast(t.colors.text,t.colors.textInverted)),t)),Du="'Inter Variable', sans-serif",Pu="'Geist Mono', monospace",Uu=6,pt=[357,91,55,1],mt=[58,100,50,1],Lu=["#FDFDFD","#FAFAFA","#F3F3F3","#EAEAEA","#D8D8D8","#ADADAD","#878787","#616161","#404040","#1C1C1C","#050505"],wt=Object.fromEntries(Lu.map((t,e)=>[`l${e}`,t])),os={key:"synnaxBase",name:"Synnax Base",colors:{primary:{m2:"#041B3D",m1:"#164FA0",z:"#3774D0",p1:"#5E94EE",p2:"#8AB8FF"},secondary:{m2:"#2D8F4E",m1:"#38B261",z:"#50C878",p1:"#73D393",p2:"#96DEAE"},gray:wt,border:wt.l3,error:{m2:O.fromHSLA(we(pt,30)),m1:O.fromHSLA(we(pt,40)),z:O.fromHSLA(pt),p1:O.fromHSLA(we(pt,65)),p2:O.fromHSLA(we(pt,77))},warning:{m2:O.fromHSLA(we(mt,30)),m1:O.fromHSLA(we(mt,40)),z:O.fromHSLA(mt),p1:O.fromHSLA(we(mt,65)),p2:O.fromHSLA(we(mt,75))},visualization:{palettes:{default:["#DC136C","#20A4F3","#7AC74F","#FFC43D","#FE5F55","#8075FF","#D90429","#f7aef8","#f18f01","#791e94","#279af1","#d9fff5","#ff6b6b","#52ffb8"]}},logo:"url(#synnax-linear-gradient)",white:"#FFFFFF",black:"#000000",text:wt.l9,textInverted:wt.l0,textOnPrimary:wt.l0},sizes:{base:Uu,border:{radius:3,width:1},schematic:{elementStrokeWidth:2}},typography:{family:Du,codeFamily:Pu,h1:{size:7,weight:"500",lineHeight:7*1.5},h2:{size:4.5,weight:"medium",lineHeight:4.5*1.5},h3:{size:3.5,weight:"medium",lineHeight:3.5*1.5},h4:{size:2.6666,weight:"medium",lineHeight:2.6666*1.5},h5:{size:2.333333,weight:450,lineHeight:2.333333*1.5},p:{size:2.1666666666,weight:"regular",lineHeight:2*1.5},small:{size:1.916666,weight:"regular",lineHeight:1.9166666*1.5}}},Xa=Object.freeze({...os,key:"synnaxLight",name:"Synnax Light"}),_u=["#020202","#0A0A0A","#131313","#1E1E1E","#2E2E2E","#444444","#646464","#8A8A8A","#AFAFAF","#D5D5D5","#FDFDFD"],bt=Object.fromEntries(_u.map((t,e)=>[`l${e}`,t])),Qa=Object.freeze({...os,key:"synnaxDark",name:"Synnax Dark",colors:{...os.colors,gray:bt,logo:"var(--pluto-text-color)",border:bt.l3,text:bt.l9,textInverted:bt.l0,textOnPrimary:bt.l10}}),Yu={synnaxDark:Qa,synnaxLight:Xa},qu=["small","medium","large","huge"],Fu=s.z.enum(qu),Vu=t=>Fu.safeParse(t).success,Wu=(t,{level:e,weight:n,code:r})=>{const{typography:i,sizes:{base:a}}=t,o=i[Vu(e)?Ja[e]:e].size,c=a*o,u=r?i.codeFamily:i.family,[h,f]=u.split(", ");return n!=null?` ${n} ${c}px ${h}, ${f}`:` ${c}px ${u}`};var Gu=Object.defineProperty,Zu=(t,e,n)=>e in t?Gu(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,l=(t,e,n)=>Zu(t,typeof e!="symbol"?e+"":e,n);const T=t=>Array.isArray(t)?t:[t];var Ku=Object.defineProperty,Ju=(t,e,n)=>e in t?Ku(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,M=(t,e,n)=>Ju(t,typeof e!="symbol"?e+"":e,n);const Hu=t=>{const e=t.replace(/_[a-z]/g,n=>n[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)},eo=t=>{const e=(n,r=ls)=>{if(typeof n=="string")return t(n);if(Array.isArray(n))return n.map(o=>e(o,r));if(!kr(n))return n;r=eh(r);const i={},a=n;return Object.keys(a).forEach(o=>{let c=a[o];const u=t(o);r.recursive&&(kr(c)?Oi(c,r.keepTypesOnRecursion)||(c=e(c,r)):r.recursiveInArray&&vi(c)&&(c=[...c].map(h=>{let f=h;return kr(h)?Oi(f,r.keepTypesOnRecursion)||(f=e(h,r)):vi(h)&&(f=e({key:h},r).key),f}))),i[u]=c}),i};return e},to=eo(Hu),Xu=t=>t.replace(/([a-z0-9])([A-Z])/g,(e,n,r)=>`${n}_${r.toLowerCase()}`),Qu=eo(Xu),ls={recursive:!0,recursiveInArray:!0,keepTypesOnRecursion:[Number,String,Uint8Array]},eh=(t=ls)=>(t.recursive==null?t=ls:t.recursiveInArray==null&&(t.recursiveInArray=!1),t),vi=t=>t!=null&&Array.isArray(t),kr=t=>t!=null&&typeof t=="object"&&!Array.isArray(t),Oi=(t,e)=>(e||[]).some(n=>t instanceof n),no=t=>t!=null&&typeof t=="object"&&!Array.isArray(t);var th=Object.defineProperty,nh=(t,e,n)=>e in t?th(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ft=(t,e,n)=>nh(t,typeof e!="symbol"?e+"":e,n);let rh=class{constructor(){Ft(this,"contentType","application/json"),Ft(this,"decoder"),Ft(this,"encoder"),this.decoder=new TextDecoder,this.encoder=new TextEncoder}encode(t){return this.encoder.encode(this.encodeString(t)).buffer}decode(t,e){return this.decodeString(this.decoder.decode(t),e)}decodeString(t,e){const n=JSON.parse(t),r=to(n);return e!=null?e.parse(r):r}encodeString(t){const e=Qu(t);return JSON.stringify(e,(n,r)=>ArrayBuffer.isView(r)?Array.from(r):no(r)&&"encode_value"in r?typeof r.value=="bigint"?r.value.toString():r.value:typeof r=="bigint"?r.toString():r)}static registerCustomType(){}},sh=class{constructor(){Ft(this,"contentType","text/csv")}encode(t){const e=this.encodeString(t);return new TextEncoder().encode(e).buffer}decode(t,e){const n=new TextDecoder().decode(t);return this.decodeString(n,e)}encodeString(t){if(!Array.isArray(t)||t.length===0||!no(t[0]))throw new Error("Payload must be an array of objects");const e=Object.keys(t[0]),n=[e.join(",")];return t.forEach(r=>{const i=e.map(a=>JSON.stringify(r[a]??""));n.push(i.join(","))}),n.join(`
|
|
16
16
|
`)}decodeString(t,e){const[n,...r]=t.trim().split(`
|
|
17
|
-
`).map(o=>o.trim());if(n.length===0)return e!=null?e.parse({}):{};const i=n.split(",").map(o=>o.trim()),a={};return i.forEach(o=>{a[o]=[]}),r.forEach(o=>{const c=o.split(",").map(u=>u.trim());i.forEach((u,h)=>{const f=this.parseValue(c[h]);f!=null&&a[u].push(f)})}),e!=null?e.parse(a):a}parseValue(t){if(t==null||t.length===0)return null;const e=Number(t);return isNaN(e)?t.startsWith('"')&&t.endsWith('"')?t.slice(1,-1):t:e}static registerCustomType(){}},sh=class{constructor(){qt(this,"contentType","text/plain")}encode(t){return new TextEncoder().encode(t).buffer}decode(t,e){const n=new TextDecoder().decode(t);return e!=null?e.parse(n):n}};const En=new nh;new rh;new sh;const lr=s.z.tuple([s.z.number(),s.z.number()]);s.z.tuple([s.z.bigint(),s.z.bigint()]);const ro=s.z.object({width:s.z.number(),height:s.z.number()}),ih=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()}),ah=["width","height"];s.z.enum(ah);const oh=["start","center","end"],lh=["signedWidth","signedHeight"];s.z.enum(lh);const er=s.z.object({x:s.z.number(),y:s.z.number()}),ch=s.z.object({clientX:s.z.number(),clientY:s.z.number()}),uh=["x","y"],so=s.z.enum(uh),io=["top","right","bottom","left"];s.z.enum(io);const hh=["left","right"],ao=s.z.enum(hh),dh=["top","bottom"],oo=s.z.enum(dh),lo=["center"],Ti=s.z.enum(lo),fh=[...io,...lo],co=s.z.enum(fh);s.z.enum(oh);const yh=["first","last"];s.z.enum(yh);const gh=s.z.object({lower:s.z.number(),upper:s.z.number()}),ph=s.z.object({lower:s.z.bigint(),upper:s.z.bigint()});s.z.union([gh,lr]);s.z.union([ph,lr]);s.z.union([so,co]);s.z.union([so,co,s.z.instanceof(String)]);const mh=t=>typeof t=="bigint"||t instanceof BigInt,et=(t,e)=>mh(t)?t.valueOf()*BigInt(e.valueOf()):t.valueOf()*Number(e.valueOf()),He=(t,e)=>{const n={};if(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 return Si(t);return Si(n)},Si=t=>t.lower>t.upper?{lower:t.upper,upper:t.lower}:t,zi=(t,e)=>{const n=He(t);return e<n.lower?n.lower:e>=n.upper?n.upper-(typeof n.upper=="number"?1:1n):e};s.z.object({x:ao.or(Ti),y:oo.or(Ti)});const wh=s.z.object({x:ao,y:oo}),bh=Object.freeze({x:"left",y:"top"}),vh=(t,e)=>t.x===e.x&&t.y===e.y,Ni=s.z.union([s.z.number(),er,lr,ro,ih,ch]),Oh=(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}},Ii=Object.freeze({x:0,y:0}),yn=s.z.union([s.z.number(),s.z.string()]);s.z.object({top:yn,left:yn,width:yn,height:yn});s.z.object({left:s.z.number(),top:s.z.number(),right:s.z.number(),bottom:s.z.number()});s.z.object({one:er,two:er,root:wh});const Bs=(t,e,n=0,r=0,i)=>{const a={one:{...Ii},two:{...Ii},root:i??bh};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+n,y:a.one.y+r},a}return"one"in t&&"two"in t&&"root"in t?{...t,root:i??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+n,y:a.one.y+r}:typeof e=="number"?a.two={x:a.one.x+e,y:a.one.y+n}:"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))},xr=t=>{const e=Bs(t);return{lower:e.one.x,upper:e.two.x}},Cr=t=>{const e=Bs(t);return{lower:e.one.y,upper:e.two.y}},Th=t=>typeof t!="object"||t==null?!1:"one"in t&&"two"in t&&"root"in t;var Sh=Object.defineProperty,zh=(t,e,n)=>e in t?Sh(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Me=(t,e,n)=>zh(t,typeof e!="symbol"?e+"":e,n);const Nh=(t,e,n)=>e!==void 0&&t<e?e:n!==void 0&&t>n?n:t;s.z.object({offset:Ni,scale:Ni});const Ih=t=>(e,n,r,i)=>n==="dimension"?[e,r]:[e,i?r-t:r+t],Eh=t=>(e,n,r,i)=>[e,i?r/t:r*t],Ah=t=>(e,n,r)=>{if(e===null)return[t,r];const{lower:i,upper:a}=e,{lower:o,upper:c}=t,u=a-i,h=c-o;if(n==="dimension")return[t,r*(h/u)];const f=(r-i)*(h/u)+o;return[t,f]},kh=t=>(e,n,r)=>[t,r],xh=()=>(t,e,n)=>{if(t===null)throw new Error("cannot invert without bounds");if(e==="dimension")return[t,n];const{lower:r,upper:i}=t;return[t,i-(n-r)]},Ch=t=>(e,n,r)=>{const{lower:i,upper:a}=t;return r=Nh(r,i,a),[e,r]},cs=class Et{constructor(){Me(this,"ops",[]),Me(this,"currBounds",null),Me(this,"currType",null),Me(this,"reversed",!1),this.ops=[]}static translate(e){return new Et().translate(e)}static magnify(e){return new Et().magnify(e)}static scale(e,n){return new Et().scale(e,n)}translate(e){const n=this.new(),r=Ih(e);return r.type="translate",n.ops.push(r),n}magnify(e){const n=this.new(),r=Eh(e);return r.type="magnify",n.ops.push(r),n}scale(e,n){const r=He(e,n),i=this.new(),a=Ah(r);return a.type="scale",i.ops.push(a),i}clamp(e,n){const r=He(e,n),i=this.new(),a=Ch(r);return a.type="clamp",i.ops.push(a),i}reBound(e,n){const r=He(e,n),i=this.new(),a=kh(r);return a.type="re-bound",i.ops.push(a),i}invert(){const e=xh();e.type="invert";const n=this.new();return n.ops.push(e),n}pos(e){return this.exec("position",e)}dim(e){return this.exec("dimension",e)}new(){const e=new Et;return e.ops=this.ops.slice(),e.reversed=this.reversed,e}exec(e,n){return this.currBounds=null,this.ops.reduce(([r,i],a)=>a(r,e,i,this.reversed),[null,n])[1]}reverse(){const e=this.new();e.ops.reverse();const n=[];return e.ops.forEach((r,i)=>{if(r.type==="scale"||n.some(([o,c])=>i>=o&&i<=c))return;const a=e.ops.findIndex((o,c)=>o.type==="scale"&&c>i);a!==-1&&n.push([i,a])}),n.forEach(([r,i])=>{const a=e.ops.slice(r,i);a.unshift(e.ops[i]),e.ops.splice(r,i-r+1,...a)}),e.reversed=!e.reversed,e}};Me(cs,"IDENTITY",new cs);let Ei=cs;const Ai=class Re{constructor(e=new Ei,n=new Ei,r=null){Me(this,"x"),Me(this,"y"),Me(this,"currRoot"),this.x=e,this.y=n,this.currRoot=r}static translate(e,n){return new Re().translate(e,n)}static translateX(e){return new Re().translateX(e)}static translateY(e){return new Re().translateY(e)}static clamp(e){return new Re().clamp(e)}static magnify(e){return new Re().magnify(e)}static scale(e){return new Re().scale(e)}static reBound(e){return new Re().reBound(e)}translate(e,n){const r=Oh(e,n),i=this.copy();return i.x=this.x.translate(r.x),i.y=this.y.translate(r.y),i}translateX(e){const n=this.copy();return n.x=this.x.translate(e),n}translateY(e){const n=this.copy();return n.y=this.y.translate(e),n}magnify(e){const n=this.copy();return n.x=this.x.magnify(e.x),n.y=this.y.magnify(e.y),n}scale(e){const n=this.copy();if(Th(e)){const r=this.currRoot;return n.currRoot=e.root,r!=null&&!vh(r,e.root)&&(r.x!==e.root.x&&(n.x=n.x.invert()),r.y!==e.root.y&&(n.y=n.y.invert())),n.x=n.x.scale(xr(e)),n.y=n.y.scale(Cr(e)),n}return n.x=n.x.scale(e.width),n.y=n.y.scale(e.height),n}reBound(e){const n=this.copy();return n.x=this.x.reBound(xr(e)),n.y=this.y.reBound(Cr(e)),n}clamp(e){const n=this.copy();return n.x=this.x.clamp(xr(e)),n.y=this.y.clamp(Cr(e)),n}copy(){const e=new Re;return e.currRoot=this.currRoot,e.x=this.x,e.y=this.y,e}reverse(){const e=this.copy();return e.x=this.x.reverse(),e.y=this.y.reverse(),e}pos(e){return{x:this.x.pos(e.x),y:this.y.pos(e.y)}}box(e){return Bs(this.pos(e.one),this.pos(e.two),0,0,this.currRoot??e.root)}};Me(Ai,"IDENTITY",new Ai);const $h=t=>t!=null&&typeof t=="object"&&"toString"in t,Rh=(t,e=!1)=>{const n=$h(t)?"stringer":typeof t;let r;switch(n){case"string":r=(i,a)=>i.localeCompare(a);break;case"stringer":r=(i,a)=>i.toString().localeCompare(a.toString());break;case"number":r=(i,a)=>Number(i)-Number(a);break;case"bigint":r=(i,a)=>BigInt(i)-BigInt(a)>0n?1:-1;break;case"boolean":r=(i,a)=>Number(i)-Number(a);break;case"undefined":r=()=>0;break;default:return console.warn(`sortFunc: unknown type ${n}`),()=>-1}return e?jh(r):r},jh=t=>(e,n)=>t(n,e),Mh=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()});s.z.union([ro,Mh,er,lr]);const Bh=s.z.bigint().or(s.z.string().transform(BigInt));var Dh=Object.defineProperty,Ph=(t,e,n)=>e in t?Dh(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,b=(t,e,n)=>Ph(t,typeof e!="symbol"?e+"":e,n);let Uh=(t,e=21)=>(n=e)=>{let r="",i=n;for(;i--;)r+=t[Math.random()*t.length|0];return r};const Lh="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",_h=Uh(Lh,11),Yh=s.z.enum(["static","dynamic"]),uo=(t,e)=>{const n=new G(e);if(![Q.DAY,Q.HOUR,Q.MINUTE,Q.SECOND,Q.MILLISECOND,Q.MICROSECOND,Q.NANOSECOND].some(i=>i.equals(n)))throw new Error("Invalid argument for remainder. Must be an even TimeSpan or Timestamp");const r=t.valueOf()%n.valueOf();return t instanceof G?new G(r):new Q(r)},_=class z{constructor(e,n="UTC"){if(b(this,"value"),b(this,"encodeValue",!0),e==null)this.value=z.now().valueOf();else if(e instanceof Date)this.value=BigInt(e.getTime())*z.MILLISECOND.valueOf();else if(typeof e=="string")this.value=z.parseDateTimeString(e,n).valueOf();else if(Array.isArray(e))this.value=z.parseDate(e);else{let r=BigInt(0);e instanceof Number&&(e=e.valueOf()),n==="local"&&(r=z.utcOffset.valueOf()),typeof e=="number"&&(isFinite(e)?e=Math.trunc(e):(isNaN(e)&&(e=0),e===1/0?e=z.MAX:e=z.MIN)),this.value=BigInt(e.valueOf())+r}}static parseDate([e=1970,n=1,r=1]){const i=new Date(e,n-1,r,0,0,0,0);return new z(BigInt(i.getTime())*z.MILLISECOND.valueOf()).truncate(z.DAY).valueOf()}encode(){return this.value.toString()}valueOf(){return this.value}static parseTimeString(e,n="UTC"){const[r,i,a]=e.split(":");let o="00",c="00";a!=null&&([o,c]=a.split("."));let u=z.hours(parseInt(r??"00",10)).add(z.minutes(parseInt(i??"00",10))).add(z.seconds(parseInt(o??"00",10))).add(z.milliseconds(parseInt(c??"00",10)));return n==="local"&&(u=u.add(z.utcOffset)),u.valueOf()}static parseDateTimeString(e,n="UTC"){if(!e.includes("/")&&!e.includes("-"))return z.parseTimeString(e,n);const r=new Date(e);return e.includes(":")||r.setUTCHours(0,0,0,0),new z(BigInt(r.getTime())*z.MILLISECOND.valueOf(),n).valueOf()}fString(e="ISO",n="UTC"){switch(e){case"ISODate":return this.toISOString(n).slice(0,10);case"ISOTime":return this.toISOString(n).slice(11,23);case"time":return this.timeString(!1,n);case"preciseTime":return this.timeString(!0,n);case"date":return this.dateString();case"preciseDate":return`${this.dateString()} ${this.timeString(!0,n)}`;case"dateTime":return`${this.dateString()} ${this.timeString(!1,n)}`;default:return this.toISOString(n)}}toISOString(e="UTC"){return e==="UTC"?this.date().toISOString():this.sub(z.utcOffset).date().toISOString()}timeString(e=!1,n="UTC"){const r=this.toISOString(n);return e?r.slice(11,23):r.slice(11,19)}dateString(){const e=this.date(),n=e.toLocaleString("default",{month:"short"}),r=e.toLocaleString("default",{day:"numeric"});return`${n} ${r}`}static get utcOffset(){return new Q(BigInt(new Date().getTimezoneOffset())*z.MINUTE.valueOf())}static since(e){return new z().span(e)}date(){return new Date(this.milliseconds())}equals(e){return this.valueOf()===new z(e).valueOf()}span(e){return this.range(e).span}range(e){return new Ds(this,e).makeValid()}spanRange(e){return this.range(this.add(e)).makeValid()}get isZero(){return this.valueOf()===BigInt(0)}after(e){return this.valueOf()>new z(e).valueOf()}afterEq(e){return this.valueOf()>=new z(e).valueOf()}before(e){return this.valueOf()<new z(e).valueOf()}beforeEq(e){return this.valueOf()<=new z(e).valueOf()}add(e){return new z(this.valueOf()+BigInt(e.valueOf()))}sub(e){return new z(this.valueOf()-BigInt(e.valueOf()))}milliseconds(){return Number(this.valueOf())/Number(z.MILLISECOND.valueOf())}toString(){return this.date().toISOString()}remainder(e){return uo(this,e)}get isToday(){return this.truncate(Q.DAY).equals(z.now().truncate(Q.DAY))}truncate(e){return this.sub(this.remainder(e))}static now(){return new z(new Date)}static max(...e){let n=z.MIN;for(const r of e){const i=new z(r);i.after(n)&&(n=i)}return n}static min(...e){let n=z.MAX;for(const r of e){const i=new z(r);i.before(n)&&(n=i)}return n}static nanoseconds(e){return new z(e)}static microseconds(e){return z.nanoseconds(e*1e3)}static milliseconds(e){return z.microseconds(e*1e3)}static seconds(e){return z.milliseconds(e*1e3)}static minutes(e){return z.seconds(e*60)}static hours(e){return z.minutes(e*60)}static days(e){return z.hours(e*24)}};b(_,"NANOSECOND",_.nanoseconds(1)),b(_,"MICROSECOND",_.microseconds(1)),b(_,"MILLISECOND",_.milliseconds(1)),b(_,"SECOND",_.seconds(1)),b(_,"MINUTE",_.minutes(1)),b(_,"HOUR",_.hours(1)),b(_,"DAY",_.days(1)),b(_,"MAX",new _((1n<<63n)-1n)),b(_,"MIN",new _(0)),b(_,"ZERO",new _(0)),b(_,"z",s.z.union([s.z.object({value:s.z.bigint()}).transform(t=>new _(t.value)),s.z.string().transform(t=>new _(BigInt(t))),s.z.instanceof(Number).transform(t=>new _(t)),s.z.number().transform(t=>new _(t)),s.z.instanceof(_)]));let G=_;const Y=class E{constructor(e){b(this,"value"),b(this,"encodeValue",!0),typeof e=="number"&&(e=Math.trunc(e.valueOf())),this.value=BigInt(e.valueOf())}static fromSeconds(e){return e instanceof E?e:e instanceof ki?e.period:e instanceof G?new E(e):["number","bigint"].includes(typeof e)?E.seconds(e):new E(e)}static fromMilliseconds(e){return e instanceof E?e:e instanceof ki?e.period:e instanceof G?new E(e):["number","bigint"].includes(typeof e)?E.milliseconds(e):new E(e)}encode(){return this.value.toString()}valueOf(){return this.value}lessThan(e){return this.valueOf()<new E(e).valueOf()}greaterThan(e){return this.valueOf()>new E(e).valueOf()}lessThanOrEqual(e){return this.valueOf()<=new E(e).valueOf()}greaterThanOrEqual(e){return this.valueOf()>=new E(e).valueOf()}remainder(e){return uo(this,e)}truncate(e){return new E(BigInt(Math.trunc(Number(this.valueOf()/e.valueOf())))*e.valueOf())}toString(){const e=this.truncate(E.DAY),n=this.truncate(E.HOUR),r=this.truncate(E.MINUTE),i=this.truncate(E.SECOND),a=this.truncate(E.MILLISECOND),o=this.truncate(E.MICROSECOND),c=this.truncate(E.NANOSECOND),u=e,h=n.sub(e),f=r.sub(n),d=i.sub(r),k=a.sub(i),D=o.sub(a),ie=c.sub(o);let M="";return u.isZero||(M+=`${u.days}d `),h.isZero||(M+=`${h.hours}h `),f.isZero||(M+=`${f.minutes}m `),d.isZero||(M+=`${d.seconds}s `),k.isZero||(M+=`${k.milliseconds}ms `),D.isZero||(M+=`${D.microseconds}µs `),ie.isZero||(M+=`${ie.nanoseconds}ns`),M.trim()}get days(){return Number(this.valueOf())/Number(E.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(E.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(E.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(E.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(E.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(E.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get isZero(){return this.valueOf()===BigInt(0)}equals(e){return this.valueOf()===new E(e).valueOf()}add(e){return new E(this.valueOf()+new E(e).valueOf())}sub(e){return new E(this.valueOf()-new E(e).valueOf())}static nanoseconds(e=1){return new E(e)}static microseconds(e=1){return E.nanoseconds(et(e,1e3))}static milliseconds(e=1){return E.microseconds(et(e,1e3))}static seconds(e=1){return E.milliseconds(et(e,1e3))}static minutes(e=1){return E.seconds(et(e,60))}static hours(e){return E.minutes(et(e,60))}static days(e){return E.hours(et(e,24))}};b(Y,"NANOSECOND",Y.nanoseconds(1)),b(Y,"MICROSECOND",Y.microseconds(1)),b(Y,"MILLISECOND",Y.milliseconds(1)),b(Y,"SECOND",Y.seconds(1)),b(Y,"MINUTE",Y.minutes(1)),b(Y,"HOUR",Y.hours(1)),b(Y,"DAY",Y.days(1)),b(Y,"MAX",new Y((1n<<63n)-1n)),b(Y,"MIN",new Y(0)),b(Y,"ZERO",new Y(0)),b(Y,"z",s.z.union([s.z.object({value:s.z.bigint()}).transform(t=>new Y(t.value)),s.z.string().transform(t=>new Y(BigInt(t))),s.z.instanceof(Number).transform(t=>new Y(t)),s.z.number().transform(t=>new Y(t)),s.z.instanceof(Y)]));let Q=Y;const At=class An extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new An(e).valueOf()}get period(){return Q.seconds(1/this.valueOf())}sampleCount(e){return new Q(e).seconds*this.valueOf()}byteCount(e,n){return this.sampleCount(e)*new ue(n).valueOf()}span(e){return Q.seconds(e/this.valueOf())}byteSpan(e,n){return this.span(e.valueOf()/n.valueOf())}static hz(e){return new An(e)}static khz(e){return An.hz(e*1e3)}};b(At,"z",s.z.union([s.z.number().transform(t=>new At(t)),s.z.instanceof(Number).transform(t=>new At(t)),s.z.instanceof(At)]));let ki=At;const ne=class extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}length(e){return e.valueOf()/this.valueOf()}size(e){return new us(e*this.valueOf())}};b(ne,"UNKNOWN",new ne(0)),b(ne,"BIT128",new ne(16)),b(ne,"BIT64",new ne(8)),b(ne,"BIT32",new ne(4)),b(ne,"BIT16",new ne(2)),b(ne,"BIT8",new ne(1)),b(ne,"z",s.z.union([s.z.number().transform(t=>new ne(t)),s.z.instanceof(Number).transform(t=>new ne(t)),s.z.instanceof(ne)]));let ue=ne;const Ie=class kn{constructor(e,n){b(this,"start"),b(this,"end"),typeof e=="object"&&"start"in e?(this.start=new G(e.start),this.end=new G(e.end)):(this.start=new G(e),this.end=new G(n))}get span(){return new Q(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 kn(this.end,this.start)}equals(e){return this.start.equals(e.start)&&this.end.equals(e.end)}toString(){return`${this.start.toString()} - ${this.end.toString()}`}toPrettyString(){return`${this.start.fString("preciseDate")} - ${this.span.toString()}`}overlapsWith(e,n=Q.ZERO){e=e.makeValid();const r=this.makeValid();if(this.equals(e))return!0;if(e.end.equals(r.start)||r.end.equals(e.start))return!1;const i=G.max(r.start,e.start),a=G.min(r.end,e.end);return a.before(i)?!1:new Q(a.sub(i)).greaterThanOrEqual(n)}roughlyEquals(e,n){let r=this.start.sub(e.start).valueOf(),i=this.end.sub(e.end).valueOf();return r<0&&(r=-r),i<0&&(i=-i),r<=n.valueOf()&&i<=n.valueOf()}contains(e){return e instanceof kn?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const n=new kn(this.start,this.end);return e.start.after(this.start)&&(n.start=e.start),e.start.after(this.end)&&(n.end=e.start),e.end.before(this.end)&&(n.end=e.end),e.end.before(this.start)&&(n.start=e.end),n}};b(Ie,"MAX",new Ie(G.MIN,G.MAX)),b(Ie,"MIN",new Ie(G.MAX,G.MIN)),b(Ie,"ZERO",new Ie(G.ZERO,G.ZERO)),b(Ie,"z",s.z.union([s.z.object({start:G.z,end:G.z}).transform(t=>new Ie(t.start,t.end)),s.z.instanceof(Ie)]));let Ds=Ie;const m=class Ee extends String{constructor(e){if(e instanceof Ee||typeof e=="string"||typeof e.valueOf()=="string"){super(e.valueOf());return}else{const n=Ee.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);if(n!=null){super(n.valueOf());return}}throw super(Ee.UNKNOWN.valueOf()),new Error(`unable to find data type for ${e.toString()}`)}get Array(){const e=Ee.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(n=>this.equals(n))}toString(){return this.valueOf()}get isVariable(){return this.equals(Ee.JSON)||this.equals(Ee.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(Ee.UUID)}get isInteger(){return this.toString().startsWith("int")}get isFloat(){return this.toString().startsWith("float")}get density(){const e=Ee.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}canSafelyCastTo(e){return this.equals(e)?!0:this.isVariable&&!e.isVariable||!this.isVariable&&e.isVariable?!1:this.isFloat&&e.isInteger||this.isInteger&&e.isFloat?this.density.valueOf()<e.density.valueOf():this.isFloat&&e.isFloat||this.isInteger&&e.isInteger?this.density.valueOf()<=e.density.valueOf():!1}canCastTo(e){return this.isNumeric&&e.isNumeric?!0:this.equals(e)}checkArray(e){return e.constructor===this.Array}toJSON(){return this.toString()}get usesBigInt(){return Ee.BIG_INT_TYPES.some(e=>e.equals(this))}};b(m,"UNKNOWN",new m("unknown")),b(m,"FLOAT64",new m("float64")),b(m,"FLOAT32",new m("float32")),b(m,"INT64",new m("int64")),b(m,"INT32",new m("int32")),b(m,"INT16",new m("int16")),b(m,"INT8",new m("int8")),b(m,"UINT64",new m("uint64")),b(m,"UINT32",new m("uint32")),b(m,"UINT16",new m("uint16")),b(m,"UINT8",new m("uint8")),b(m,"BOOLEAN",m.UINT8),b(m,"TIMESTAMP",new m("timestamp")),b(m,"UUID",new m("uuid")),b(m,"STRING",new m("string")),b(m,"JSON",new m("json")),b(m,"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]])),b(m,"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]])),b(m,"DENSITIES",new Map([[m.UINT8.toString(),ue.BIT8],[m.UINT16.toString(),ue.BIT16],[m.UINT32.toString(),ue.BIT32],[m.UINT64.toString(),ue.BIT64],[m.FLOAT32.toString(),ue.BIT32],[m.FLOAT64.toString(),ue.BIT64],[m.INT8.toString(),ue.BIT8],[m.INT16.toString(),ue.BIT16],[m.INT32.toString(),ue.BIT32],[m.INT64.toString(),ue.BIT64],[m.TIMESTAMP.toString(),ue.BIT64],[m.STRING.toString(),ue.UNKNOWN],[m.JSON.toString(),ue.UNKNOWN],[m.UUID.toString(),ue.BIT128]])),b(m,"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]),b(m,"BIG_INT_TYPES",[m.INT64,m.UINT64,m.TIMESTAMP]),b(m,"z",s.z.union([s.z.string().transform(t=>new m(t)),s.z.instanceof(m)]));let F=m;const oe=class H extends Number{constructor(e){super(e.valueOf())}largerThan(e){return this.valueOf()>e.valueOf()}smallerThan(e){return this.valueOf()<e.valueOf()}add(e){return H.bytes(this.valueOf()+e.valueOf())}sub(e){return H.bytes(this.valueOf()-e.valueOf())}truncate(e){return new H(Math.trunc(this.valueOf()/e.valueOf())*e.valueOf())}remainder(e){return H.bytes(this.valueOf()%e.valueOf())}get gigabytes(){return this.valueOf()/H.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/H.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/H.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/H.TERABYTE.valueOf()}toString(){const e=this.truncate(H.TERABYTE),n=this.truncate(H.GIGABYTE),r=this.truncate(H.MEGABYTE),i=this.truncate(H.KILOBYTE),a=this.truncate(H.BYTE),o=e,c=n.sub(e),u=r.sub(n),h=i.sub(r),f=a.sub(i);let d="";return o.isZero||(d+=`${o.terabytes}TB `),c.isZero||(d+=`${c.gigabytes}GB `),u.isZero||(d+=`${u.megabytes}MB `),h.isZero||(d+=`${h.kilobytes}KB `),(!f.isZero||d==="")&&(d+=`${f.valueOf()}B`),d.trim()}static bytes(e=1){return new H(e)}static kilobytes(e=1){return H.bytes(e.valueOf()*1e3)}static megabytes(e=1){return H.kilobytes(e.valueOf()*1e3)}static gigabytes(e=1){return H.megabytes(e.valueOf()*1e3)}static terabytes(e){return H.gigabytes(e.valueOf()*1e3)}get isZero(){return this.valueOf()===0}};b(oe,"BYTE",new oe(1)),b(oe,"KILOBYTE",oe.kilobytes(1)),b(oe,"MEGABYTE",oe.megabytes(1)),b(oe,"GIGABYTE",oe.gigabytes(1)),b(oe,"TERABYTE",oe.terabytes(1)),b(oe,"ZERO",new oe(0)),b(oe,"z",s.z.union([s.z.number().transform(t=>new oe(t)),s.z.instanceof(oe)]));let us=oe;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 ho=t=>{const e=typeof t;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||t instanceof G||t instanceof Q||t instanceof Date},Fh=(t,e,n,r=0)=>t.usesBigInt&&!e.usesBigInt?Number(n)-Number(r):!t.usesBigInt&&e.usesBigInt?BigInt(n.valueOf())-BigInt(r.valueOf()):xt(n,-r).valueOf(),qh=t=>t==null?!1:Array.isArray(t)||t instanceof ArrayBuffer||ArrayBuffer.isView(t)&&!(t instanceof DataView)||t instanceof Gh?!0:ho(t),Ue=-1,Vh=s.z.string().transform(t=>new Uint8Array(atob(t).split("").map(e=>e.charCodeAt(0))).buffer),Wh=s.z.union([s.z.null(),s.z.undefined()]).transform(()=>new Uint8Array().buffer),hs=10,kt=class Ae{constructor(e){b(this,"key",""),b(this,"isSynnaxSeries",!0),b(this,"dataType"),b(this,"sampleOffset"),b(this,"gl"),b(this,"_data"),b(this,"_timeRange"),b(this,"alignment",0n),b(this,"_cachedMin"),b(this,"_cachedMax"),b(this,"writePos",Ue),b(this,"_refCount",0),b(this,"_cachedLength"),b(this,"_cachedIndexes"),qh(e)&&(e={data:e});const{dataType:n,timeRange:r,sampleOffset:i=0,glBufferUsage:a="static",alignment:o=0n,key:c=_h()}=e,u=e.data??[];if(u instanceof Ae||typeof u=="object"&&"isSynnaxSeries"in u&&u.isSynnaxSeries===!0){const d=u;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._cachedMin=d._cachedMin,this._cachedMax=d._cachedMax,this.writePos=d.writePos,this._refCount=d._refCount,this._cachedLength=d._cachedLength;return}const h=ho(u),f=Array.isArray(u);if(n!=null)this.dataType=new F(n);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(f||h){let d=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.");d=u[0]}if(typeof d=="string")this.dataType=F.STRING;else if(typeof d=="number")this.dataType=F.FLOAT64;else if(typeof d=="bigint")this.dataType=F.INT64;else if(typeof d=="boolean")this.dataType=F.BOOLEAN;else if(d instanceof G||d instanceof Date||d instanceof G)this.dataType=F.TIMESTAMP;else if(typeof d=="object")this.dataType=F.JSON;else throw new Error(`cannot infer data type of ${typeof d} when constructing a Series from a JS array`)}else this.dataType=new F(u)}if(!f&&!h)this._data=u;else{let d=h?[u]:u;const k=d[0];(k instanceof G||k instanceof Date||k instanceof Q)&&(d=d.map(D=>new G(D).valueOf())),this.dataType.equals(F.STRING)?(this._cachedLength=d.length,this._data=new TextEncoder().encode(d.join(`
|
|
17
|
+
`).map(o=>o.trim());if(n.length===0)return e!=null?e.parse({}):{};const i=n.split(",").map(o=>o.trim()),a={};return i.forEach(o=>{a[o]=[]}),r.forEach(o=>{const c=o.split(",").map(u=>u.trim());i.forEach((u,h)=>{const f=this.parseValue(c[h]);f!=null&&a[u].push(f)})}),e!=null?e.parse(a):a}parseValue(t){if(t==null||t.length===0)return null;const e=Number(t);return isNaN(e)?t.startsWith('"')&&t.endsWith('"')?t.slice(1,-1):t:e}static registerCustomType(){}},ih=class{constructor(){Ft(this,"contentType","text/plain")}encode(t){return new TextEncoder().encode(t).buffer}decode(t,e){const n=new TextDecoder().decode(t);return e!=null?e.parse(n):n}};const En=new rh;new sh;new ih;const lr=s.z.tuple([s.z.number(),s.z.number()]);s.z.tuple([s.z.bigint(),s.z.bigint()]);const ro=s.z.object({width:s.z.number(),height:s.z.number()}),ah=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()}),oh=["width","height"];s.z.enum(oh);const lh=["start","center","end"],ch=["signedWidth","signedHeight"];s.z.enum(ch);const er=s.z.object({x:s.z.number(),y:s.z.number()}),uh=s.z.object({clientX:s.z.number(),clientY:s.z.number()}),hh=["x","y"],so=s.z.enum(hh),io=["top","right","bottom","left"];s.z.enum(io);const dh=["left","right"],ao=s.z.enum(dh),fh=["top","bottom"],oo=s.z.enum(fh),lo=["center"],Ti=s.z.enum(lo),yh=[...io,...lo],co=s.z.enum(yh);s.z.enum(lh);const gh=["first","last"];s.z.enum(gh);const ph=s.z.object({lower:s.z.number(),upper:s.z.number()}),mh=s.z.object({lower:s.z.bigint(),upper:s.z.bigint()});s.z.union([ph,lr]);s.z.union([mh,lr]);s.z.union([so,co]);s.z.union([so,co,s.z.instanceof(String)]);const wh=t=>typeof t=="bigint"||t instanceof BigInt,et=(t,e)=>wh(t)?t.valueOf()*BigInt(e.valueOf()):t.valueOf()*Number(e.valueOf()),He=(t,e)=>{const n={};if(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 return Si(t);return Si(n)},Si=t=>t.lower>t.upper?{lower:t.upper,upper:t.lower}:t,zi=(t,e)=>{const n=He(t);return e<n.lower?n.lower:e>=n.upper?n.upper-(typeof n.upper=="number"?1:1n):e};s.z.object({x:ao.or(Ti),y:oo.or(Ti)});const bh=s.z.object({x:ao,y:oo}),vh=Object.freeze({x:"left",y:"top"}),Oh=(t,e)=>t.x===e.x&&t.y===e.y,Ni=s.z.union([s.z.number(),er,lr,ro,ah,uh]),Th=(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}},Ii=Object.freeze({x:0,y:0}),yn=s.z.union([s.z.number(),s.z.string()]);s.z.object({top:yn,left:yn,width:yn,height:yn});s.z.object({left:s.z.number(),top:s.z.number(),right:s.z.number(),bottom:s.z.number()});s.z.object({one:er,two:er,root:bh});const Ms=(t,e,n=0,r=0,i)=>{const a={one:{...Ii},two:{...Ii},root:i??vh};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+n,y:a.one.y+r},a}return"one"in t&&"two"in t&&"root"in t?{...t,root:i??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+n,y:a.one.y+r}:typeof e=="number"?a.two={x:a.one.x+e,y:a.one.y+n}:"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))},xr=t=>{const e=Ms(t);return{lower:e.one.x,upper:e.two.x}},Cr=t=>{const e=Ms(t);return{lower:e.one.y,upper:e.two.y}},Sh=t=>typeof t!="object"||t==null?!1:"one"in t&&"two"in t&&"root"in t;var zh=Object.defineProperty,Nh=(t,e,n)=>e in t?zh(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Be=(t,e,n)=>Nh(t,typeof e!="symbol"?e+"":e,n);const Ih=(t,e,n)=>e!==void 0&&t<e?e:n!==void 0&&t>n?n:t;s.z.object({offset:Ni,scale:Ni});const Eh=t=>(e,n,r,i)=>n==="dimension"?[e,r]:[e,i?r-t:r+t],Ah=t=>(e,n,r,i)=>[e,i?r/t:r*t],kh=t=>(e,n,r)=>{if(e===null)return[t,r];const{lower:i,upper:a}=e,{lower:o,upper:c}=t,u=a-i,h=c-o;if(n==="dimension")return[t,r*(h/u)];const f=(r-i)*(h/u)+o;return[t,f]},xh=t=>(e,n,r)=>[t,r],Ch=()=>(t,e,n)=>{if(t===null)throw new Error("cannot invert without bounds");if(e==="dimension")return[t,n];const{lower:r,upper:i}=t;return[t,i-(n-r)]},$h=t=>(e,n,r)=>{const{lower:i,upper:a}=t;return r=Ih(r,i,a),[e,r]},cs=class Et{constructor(){Be(this,"ops",[]),Be(this,"currBounds",null),Be(this,"currType",null),Be(this,"reversed",!1),this.ops=[]}static translate(e){return new Et().translate(e)}static magnify(e){return new Et().magnify(e)}static scale(e,n){return new Et().scale(e,n)}translate(e){const n=this.new(),r=Eh(e);return r.type="translate",n.ops.push(r),n}magnify(e){const n=this.new(),r=Ah(e);return r.type="magnify",n.ops.push(r),n}scale(e,n){const r=He(e,n),i=this.new(),a=kh(r);return a.type="scale",i.ops.push(a),i}clamp(e,n){const r=He(e,n),i=this.new(),a=$h(r);return a.type="clamp",i.ops.push(a),i}reBound(e,n){const r=He(e,n),i=this.new(),a=xh(r);return a.type="re-bound",i.ops.push(a),i}invert(){const e=Ch();e.type="invert";const n=this.new();return n.ops.push(e),n}pos(e){return this.exec("position",e)}dim(e){return this.exec("dimension",e)}new(){const e=new Et;return e.ops=this.ops.slice(),e.reversed=this.reversed,e}exec(e,n){return this.currBounds=null,this.ops.reduce(([r,i],a)=>a(r,e,i,this.reversed),[null,n])[1]}reverse(){const e=this.new();e.ops.reverse();const n=[];return e.ops.forEach((r,i)=>{if(r.type==="scale"||n.some(([o,c])=>i>=o&&i<=c))return;const a=e.ops.findIndex((o,c)=>o.type==="scale"&&c>i);a!==-1&&n.push([i,a])}),n.forEach(([r,i])=>{const a=e.ops.slice(r,i);a.unshift(e.ops[i]),e.ops.splice(r,i-r+1,...a)}),e.reversed=!e.reversed,e}};Be(cs,"IDENTITY",new cs);let Ei=cs;const Ai=class Re{constructor(e=new Ei,n=new Ei,r=null){Be(this,"x"),Be(this,"y"),Be(this,"currRoot"),this.x=e,this.y=n,this.currRoot=r}static translate(e,n){return new Re().translate(e,n)}static translateX(e){return new Re().translateX(e)}static translateY(e){return new Re().translateY(e)}static clamp(e){return new Re().clamp(e)}static magnify(e){return new Re().magnify(e)}static scale(e){return new Re().scale(e)}static reBound(e){return new Re().reBound(e)}translate(e,n){const r=Th(e,n),i=this.copy();return i.x=this.x.translate(r.x),i.y=this.y.translate(r.y),i}translateX(e){const n=this.copy();return n.x=this.x.translate(e),n}translateY(e){const n=this.copy();return n.y=this.y.translate(e),n}magnify(e){const n=this.copy();return n.x=this.x.magnify(e.x),n.y=this.y.magnify(e.y),n}scale(e){const n=this.copy();if(Sh(e)){const r=this.currRoot;return n.currRoot=e.root,r!=null&&!Oh(r,e.root)&&(r.x!==e.root.x&&(n.x=n.x.invert()),r.y!==e.root.y&&(n.y=n.y.invert())),n.x=n.x.scale(xr(e)),n.y=n.y.scale(Cr(e)),n}return n.x=n.x.scale(e.width),n.y=n.y.scale(e.height),n}reBound(e){const n=this.copy();return n.x=this.x.reBound(xr(e)),n.y=this.y.reBound(Cr(e)),n}clamp(e){const n=this.copy();return n.x=this.x.clamp(xr(e)),n.y=this.y.clamp(Cr(e)),n}copy(){const e=new Re;return e.currRoot=this.currRoot,e.x=this.x,e.y=this.y,e}reverse(){const e=this.copy();return e.x=this.x.reverse(),e.y=this.y.reverse(),e}pos(e){return{x:this.x.pos(e.x),y:this.y.pos(e.y)}}box(e){return Ms(this.pos(e.one),this.pos(e.two),0,0,this.currRoot??e.root)}};Be(Ai,"IDENTITY",new Ai);const Rh=t=>t!=null&&typeof t=="object"&&"toString"in t,jh=(t,e=!1)=>{const n=Rh(t)?"stringer":typeof t;let r;switch(n){case"string":r=(i,a)=>i.localeCompare(a);break;case"stringer":r=(i,a)=>i.toString().localeCompare(a.toString());break;case"number":r=(i,a)=>Number(i)-Number(a);break;case"bigint":r=(i,a)=>BigInt(i)-BigInt(a)>0n?1:-1;break;case"boolean":r=(i,a)=>Number(i)-Number(a);break;case"undefined":r=()=>0;break;default:return console.warn(`sortFunc: unknown type ${n}`),()=>-1}return e?Bh(r):r},Bh=t=>(e,n)=>t(n,e),Mh=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()});s.z.union([ro,Mh,er,lr]);const Dh=s.z.bigint().or(s.z.string().transform(BigInt));var Ph=Object.defineProperty,Uh=(t,e,n)=>e in t?Ph(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,b=(t,e,n)=>Uh(t,typeof e!="symbol"?e+"":e,n);let Lh=(t,e=21)=>(n=e)=>{let r="",i=n;for(;i--;)r+=t[Math.random()*t.length|0];return r};const _h="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",Yh=Lh(_h,11),qh=s.z.enum(["static","dynamic"]),uo=(t,e)=>{const n=new G(e);if(![Q.DAY,Q.HOUR,Q.MINUTE,Q.SECOND,Q.MILLISECOND,Q.MICROSECOND,Q.NANOSECOND].some(i=>i.equals(n)))throw new Error("Invalid argument for remainder. Must be an even TimeSpan or Timestamp");const r=t.valueOf()%n.valueOf();return t instanceof G?new G(r):new Q(r)},_=class z{constructor(e,n="UTC"){if(b(this,"value"),b(this,"encodeValue",!0),e==null)this.value=z.now().valueOf();else if(e instanceof Date)this.value=BigInt(e.getTime())*z.MILLISECOND.valueOf();else if(typeof e=="string")this.value=z.parseDateTimeString(e,n).valueOf();else if(Array.isArray(e))this.value=z.parseDate(e);else{let r=BigInt(0);e instanceof Number&&(e=e.valueOf()),n==="local"&&(r=z.utcOffset.valueOf()),typeof e=="number"&&(isFinite(e)?e=Math.trunc(e):(isNaN(e)&&(e=0),e===1/0?e=z.MAX:e=z.MIN)),this.value=BigInt(e.valueOf())+r}}static parseDate([e=1970,n=1,r=1]){const i=new Date(e,n-1,r,0,0,0,0);return new z(BigInt(i.getTime())*z.MILLISECOND.valueOf()).truncate(z.DAY).valueOf()}encode(){return this.value.toString()}valueOf(){return this.value}static parseTimeString(e,n="UTC"){const[r,i,a]=e.split(":");let o="00",c="00";a!=null&&([o,c]=a.split("."));let u=z.hours(parseInt(r??"00",10)).add(z.minutes(parseInt(i??"00",10))).add(z.seconds(parseInt(o??"00",10))).add(z.milliseconds(parseInt(c??"00",10)));return n==="local"&&(u=u.add(z.utcOffset)),u.valueOf()}static parseDateTimeString(e,n="UTC"){if(!e.includes("/")&&!e.includes("-"))return z.parseTimeString(e,n);const r=new Date(e);return e.includes(":")||r.setUTCHours(0,0,0,0),new z(BigInt(r.getTime())*z.MILLISECOND.valueOf(),n).valueOf()}fString(e="ISO",n="UTC"){switch(e){case"ISODate":return this.toISOString(n).slice(0,10);case"ISOTime":return this.toISOString(n).slice(11,23);case"time":return this.timeString(!1,n);case"preciseTime":return this.timeString(!0,n);case"date":return this.dateString();case"preciseDate":return`${this.dateString()} ${this.timeString(!0,n)}`;case"dateTime":return`${this.dateString()} ${this.timeString(!1,n)}`;default:return this.toISOString(n)}}toISOString(e="UTC"){return e==="UTC"?this.date().toISOString():this.sub(z.utcOffset).date().toISOString()}timeString(e=!1,n="UTC"){const r=this.toISOString(n);return e?r.slice(11,23):r.slice(11,19)}dateString(){const e=this.date(),n=e.toLocaleString("default",{month:"short"}),r=e.toLocaleString("default",{day:"numeric"});return`${n} ${r}`}static get utcOffset(){return new Q(BigInt(new Date().getTimezoneOffset())*z.MINUTE.valueOf())}static since(e){return new z().span(e)}date(){return new Date(this.milliseconds())}equals(e){return this.valueOf()===new z(e).valueOf()}span(e){return this.range(e).span}range(e){return new Ds(this,e).makeValid()}spanRange(e){return this.range(this.add(e)).makeValid()}get isZero(){return this.valueOf()===BigInt(0)}after(e){return this.valueOf()>new z(e).valueOf()}afterEq(e){return this.valueOf()>=new z(e).valueOf()}before(e){return this.valueOf()<new z(e).valueOf()}beforeEq(e){return this.valueOf()<=new z(e).valueOf()}add(e){return new z(this.valueOf()+BigInt(e.valueOf()))}sub(e){return new z(this.valueOf()-BigInt(e.valueOf()))}milliseconds(){return Number(this.valueOf())/Number(z.MILLISECOND.valueOf())}toString(){return this.date().toISOString()}remainder(e){return uo(this,e)}get isToday(){return this.truncate(Q.DAY).equals(z.now().truncate(Q.DAY))}truncate(e){return this.sub(this.remainder(e))}static now(){return new z(new Date)}static max(...e){let n=z.MIN;for(const r of e){const i=new z(r);i.after(n)&&(n=i)}return n}static min(...e){let n=z.MAX;for(const r of e){const i=new z(r);i.before(n)&&(n=i)}return n}static nanoseconds(e){return new z(e)}static microseconds(e){return z.nanoseconds(e*1e3)}static milliseconds(e){return z.microseconds(e*1e3)}static seconds(e){return z.milliseconds(e*1e3)}static minutes(e){return z.seconds(e*60)}static hours(e){return z.minutes(e*60)}static days(e){return z.hours(e*24)}};b(_,"NANOSECOND",_.nanoseconds(1)),b(_,"MICROSECOND",_.microseconds(1)),b(_,"MILLISECOND",_.milliseconds(1)),b(_,"SECOND",_.seconds(1)),b(_,"MINUTE",_.minutes(1)),b(_,"HOUR",_.hours(1)),b(_,"DAY",_.days(1)),b(_,"MAX",new _((1n<<63n)-1n)),b(_,"MIN",new _(0)),b(_,"ZERO",new _(0)),b(_,"z",s.z.union([s.z.object({value:s.z.bigint()}).transform(t=>new _(t.value)),s.z.string().transform(t=>new _(BigInt(t))),s.z.instanceof(Number).transform(t=>new _(t)),s.z.number().transform(t=>new _(t)),s.z.instanceof(_)]));let G=_;const Y=class E{constructor(e){b(this,"value"),b(this,"encodeValue",!0),typeof e=="number"&&(e=Math.trunc(e.valueOf())),this.value=BigInt(e.valueOf())}static fromSeconds(e){return e instanceof E?e:e instanceof ki?e.period:e instanceof G?new E(e):["number","bigint"].includes(typeof e)?E.seconds(e):new E(e)}static fromMilliseconds(e){return e instanceof E?e:e instanceof ki?e.period:e instanceof G?new E(e):["number","bigint"].includes(typeof e)?E.milliseconds(e):new E(e)}encode(){return this.value.toString()}valueOf(){return this.value}lessThan(e){return this.valueOf()<new E(e).valueOf()}greaterThan(e){return this.valueOf()>new E(e).valueOf()}lessThanOrEqual(e){return this.valueOf()<=new E(e).valueOf()}greaterThanOrEqual(e){return this.valueOf()>=new E(e).valueOf()}remainder(e){return uo(this,e)}truncate(e){return new E(BigInt(Math.trunc(Number(this.valueOf()/e.valueOf())))*e.valueOf())}toString(){const e=this.truncate(E.DAY),n=this.truncate(E.HOUR),r=this.truncate(E.MINUTE),i=this.truncate(E.SECOND),a=this.truncate(E.MILLISECOND),o=this.truncate(E.MICROSECOND),c=this.truncate(E.NANOSECOND),u=e,h=n.sub(e),f=r.sub(n),d=i.sub(r),k=a.sub(i),D=o.sub(a),ie=c.sub(o);let B="";return u.isZero||(B+=`${u.days}d `),h.isZero||(B+=`${h.hours}h `),f.isZero||(B+=`${f.minutes}m `),d.isZero||(B+=`${d.seconds}s `),k.isZero||(B+=`${k.milliseconds}ms `),D.isZero||(B+=`${D.microseconds}µs `),ie.isZero||(B+=`${ie.nanoseconds}ns`),B.trim()}get days(){return Number(this.valueOf())/Number(E.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(E.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(E.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(E.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(E.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(E.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get isZero(){return this.valueOf()===BigInt(0)}equals(e){return this.valueOf()===new E(e).valueOf()}add(e){return new E(this.valueOf()+new E(e).valueOf())}sub(e){return new E(this.valueOf()-new E(e).valueOf())}static nanoseconds(e=1){return new E(e)}static microseconds(e=1){return E.nanoseconds(et(e,1e3))}static milliseconds(e=1){return E.microseconds(et(e,1e3))}static seconds(e=1){return E.milliseconds(et(e,1e3))}static minutes(e=1){return E.seconds(et(e,60))}static hours(e){return E.minutes(et(e,60))}static days(e){return E.hours(et(e,24))}};b(Y,"NANOSECOND",Y.nanoseconds(1)),b(Y,"MICROSECOND",Y.microseconds(1)),b(Y,"MILLISECOND",Y.milliseconds(1)),b(Y,"SECOND",Y.seconds(1)),b(Y,"MINUTE",Y.minutes(1)),b(Y,"HOUR",Y.hours(1)),b(Y,"DAY",Y.days(1)),b(Y,"MAX",new Y((1n<<63n)-1n)),b(Y,"MIN",new Y(0)),b(Y,"ZERO",new Y(0)),b(Y,"z",s.z.union([s.z.object({value:s.z.bigint()}).transform(t=>new Y(t.value)),s.z.string().transform(t=>new Y(BigInt(t))),s.z.instanceof(Number).transform(t=>new Y(t)),s.z.number().transform(t=>new Y(t)),s.z.instanceof(Y)]));let Q=Y;const At=class An extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new An(e).valueOf()}get period(){return Q.seconds(1/this.valueOf())}sampleCount(e){return new Q(e).seconds*this.valueOf()}byteCount(e,n){return this.sampleCount(e)*new ue(n).valueOf()}span(e){return Q.seconds(e/this.valueOf())}byteSpan(e,n){return this.span(e.valueOf()/n.valueOf())}static hz(e){return new An(e)}static khz(e){return An.hz(e*1e3)}};b(At,"z",s.z.union([s.z.number().transform(t=>new At(t)),s.z.instanceof(Number).transform(t=>new At(t)),s.z.instanceof(At)]));let ki=At;const ne=class extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}length(e){return e.valueOf()/this.valueOf()}size(e){return new us(e*this.valueOf())}};b(ne,"UNKNOWN",new ne(0)),b(ne,"BIT128",new ne(16)),b(ne,"BIT64",new ne(8)),b(ne,"BIT32",new ne(4)),b(ne,"BIT16",new ne(2)),b(ne,"BIT8",new ne(1)),b(ne,"z",s.z.union([s.z.number().transform(t=>new ne(t)),s.z.instanceof(Number).transform(t=>new ne(t)),s.z.instanceof(ne)]));let ue=ne;const Ie=class kn{constructor(e,n){b(this,"start"),b(this,"end"),typeof e=="object"&&"start"in e?(this.start=new G(e.start),this.end=new G(e.end)):(this.start=new G(e),this.end=new G(n))}get span(){return new Q(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 kn(this.end,this.start)}equals(e){return this.start.equals(e.start)&&this.end.equals(e.end)}toString(){return`${this.start.toString()} - ${this.end.toString()}`}toPrettyString(){return`${this.start.fString("preciseDate")} - ${this.span.toString()}`}overlapsWith(e,n=Q.ZERO){e=e.makeValid();const r=this.makeValid();if(this.equals(e))return!0;if(e.end.equals(r.start)||r.end.equals(e.start))return!1;const i=G.max(r.start,e.start),a=G.min(r.end,e.end);return a.before(i)?!1:new Q(a.sub(i)).greaterThanOrEqual(n)}roughlyEquals(e,n){let r=this.start.sub(e.start).valueOf(),i=this.end.sub(e.end).valueOf();return r<0&&(r=-r),i<0&&(i=-i),r<=n.valueOf()&&i<=n.valueOf()}contains(e){return e instanceof kn?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const n=new kn(this.start,this.end);return e.start.after(this.start)&&(n.start=e.start),e.start.after(this.end)&&(n.end=e.start),e.end.before(this.end)&&(n.end=e.end),e.end.before(this.start)&&(n.start=e.end),n}};b(Ie,"MAX",new Ie(G.MIN,G.MAX)),b(Ie,"MIN",new Ie(G.MAX,G.MIN)),b(Ie,"ZERO",new Ie(G.ZERO,G.ZERO)),b(Ie,"z",s.z.union([s.z.object({start:G.z,end:G.z}).transform(t=>new Ie(t.start,t.end)),s.z.instanceof(Ie)]));let Ds=Ie;const m=class Ee extends String{constructor(e){if(e instanceof Ee||typeof e=="string"||typeof e.valueOf()=="string"){super(e.valueOf());return}else{const n=Ee.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);if(n!=null){super(n.valueOf());return}}throw super(Ee.UNKNOWN.valueOf()),new Error(`unable to find data type for ${e.toString()}`)}get Array(){const e=Ee.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(n=>this.equals(n))}toString(){return this.valueOf()}get isVariable(){return this.equals(Ee.JSON)||this.equals(Ee.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(Ee.UUID)}get isInteger(){return this.toString().startsWith("int")}get isFloat(){return this.toString().startsWith("float")}get density(){const e=Ee.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}canSafelyCastTo(e){return this.equals(e)?!0:this.isVariable&&!e.isVariable||!this.isVariable&&e.isVariable?!1:this.isFloat&&e.isInteger||this.isInteger&&e.isFloat?this.density.valueOf()<e.density.valueOf():this.isFloat&&e.isFloat||this.isInteger&&e.isInteger?this.density.valueOf()<=e.density.valueOf():!1}canCastTo(e){return this.isNumeric&&e.isNumeric?!0:this.equals(e)}checkArray(e){return e.constructor===this.Array}toJSON(){return this.toString()}get usesBigInt(){return Ee.BIG_INT_TYPES.some(e=>e.equals(this))}};b(m,"UNKNOWN",new m("unknown")),b(m,"FLOAT64",new m("float64")),b(m,"FLOAT32",new m("float32")),b(m,"INT64",new m("int64")),b(m,"INT32",new m("int32")),b(m,"INT16",new m("int16")),b(m,"INT8",new m("int8")),b(m,"UINT64",new m("uint64")),b(m,"UINT32",new m("uint32")),b(m,"UINT16",new m("uint16")),b(m,"UINT8",new m("uint8")),b(m,"BOOLEAN",m.UINT8),b(m,"TIMESTAMP",new m("timestamp")),b(m,"UUID",new m("uuid")),b(m,"STRING",new m("string")),b(m,"JSON",new m("json")),b(m,"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]])),b(m,"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]])),b(m,"DENSITIES",new Map([[m.UINT8.toString(),ue.BIT8],[m.UINT16.toString(),ue.BIT16],[m.UINT32.toString(),ue.BIT32],[m.UINT64.toString(),ue.BIT64],[m.FLOAT32.toString(),ue.BIT32],[m.FLOAT64.toString(),ue.BIT64],[m.INT8.toString(),ue.BIT8],[m.INT16.toString(),ue.BIT16],[m.INT32.toString(),ue.BIT32],[m.INT64.toString(),ue.BIT64],[m.TIMESTAMP.toString(),ue.BIT64],[m.STRING.toString(),ue.UNKNOWN],[m.JSON.toString(),ue.UNKNOWN],[m.UUID.toString(),ue.BIT128]])),b(m,"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]),b(m,"BIG_INT_TYPES",[m.INT64,m.UINT64,m.TIMESTAMP]),b(m,"z",s.z.union([s.z.string().transform(t=>new m(t)),s.z.instanceof(m)]));let q=m;const oe=class H extends Number{constructor(e){super(e.valueOf())}largerThan(e){return this.valueOf()>e.valueOf()}smallerThan(e){return this.valueOf()<e.valueOf()}add(e){return H.bytes(this.valueOf()+e.valueOf())}sub(e){return H.bytes(this.valueOf()-e.valueOf())}truncate(e){return new H(Math.trunc(this.valueOf()/e.valueOf())*e.valueOf())}remainder(e){return H.bytes(this.valueOf()%e.valueOf())}get gigabytes(){return this.valueOf()/H.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/H.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/H.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/H.TERABYTE.valueOf()}toString(){const e=this.truncate(H.TERABYTE),n=this.truncate(H.GIGABYTE),r=this.truncate(H.MEGABYTE),i=this.truncate(H.KILOBYTE),a=this.truncate(H.BYTE),o=e,c=n.sub(e),u=r.sub(n),h=i.sub(r),f=a.sub(i);let d="";return o.isZero||(d+=`${o.terabytes}TB `),c.isZero||(d+=`${c.gigabytes}GB `),u.isZero||(d+=`${u.megabytes}MB `),h.isZero||(d+=`${h.kilobytes}KB `),(!f.isZero||d==="")&&(d+=`${f.valueOf()}B`),d.trim()}static bytes(e=1){return new H(e)}static kilobytes(e=1){return H.bytes(e.valueOf()*1e3)}static megabytes(e=1){return H.kilobytes(e.valueOf()*1e3)}static gigabytes(e=1){return H.megabytes(e.valueOf()*1e3)}static terabytes(e){return H.gigabytes(e.valueOf()*1e3)}get isZero(){return this.valueOf()===0}};b(oe,"BYTE",new oe(1)),b(oe,"KILOBYTE",oe.kilobytes(1)),b(oe,"MEGABYTE",oe.megabytes(1)),b(oe,"GIGABYTE",oe.gigabytes(1)),b(oe,"TERABYTE",oe.terabytes(1)),b(oe,"ZERO",new oe(0)),b(oe,"z",s.z.union([s.z.number().transform(t=>new oe(t)),s.z.instanceof(oe)]));let us=oe;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 ho=t=>{const e=typeof t;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||t instanceof G||t instanceof Q||t instanceof Date},Fh=(t,e,n,r=0)=>t.usesBigInt&&!e.usesBigInt?Number(n)-Number(r):!t.usesBigInt&&e.usesBigInt?BigInt(n.valueOf())-BigInt(r.valueOf()):xt(n,-r).valueOf(),Vh=t=>t==null?!1:Array.isArray(t)||t instanceof ArrayBuffer||ArrayBuffer.isView(t)&&!(t instanceof DataView)||t instanceof Zh?!0:ho(t),Ue=-1,Wh=s.z.string().transform(t=>new Uint8Array(atob(t).split("").map(e=>e.charCodeAt(0))).buffer),Gh=s.z.union([s.z.null(),s.z.undefined()]).transform(()=>new Uint8Array().buffer),hs=10,kt=class Ae{constructor(e){b(this,"key",""),b(this,"isSynnaxSeries",!0),b(this,"dataType"),b(this,"sampleOffset"),b(this,"gl"),b(this,"_data"),b(this,"_timeRange"),b(this,"alignment",0n),b(this,"_cachedMin"),b(this,"_cachedMax"),b(this,"writePos",Ue),b(this,"_refCount",0),b(this,"_cachedLength"),b(this,"_cachedIndexes"),Vh(e)&&(e={data:e});const{dataType:n,timeRange:r,sampleOffset:i=0,glBufferUsage:a="static",alignment:o=0n,key:c=Yh()}=e,u=e.data??[];if(u instanceof Ae||typeof u=="object"&&"isSynnaxSeries"in u&&u.isSynnaxSeries===!0){const d=u;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._cachedMin=d._cachedMin,this._cachedMax=d._cachedMax,this.writePos=d.writePos,this._refCount=d._refCount,this._cachedLength=d._cachedLength;return}const h=ho(u),f=Array.isArray(u);if(n!=null)this.dataType=new q(n);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(f||h){let d=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.");d=u[0]}if(typeof d=="string")this.dataType=q.STRING;else if(typeof d=="number")this.dataType=q.FLOAT64;else if(typeof d=="bigint")this.dataType=q.INT64;else if(typeof d=="boolean")this.dataType=q.BOOLEAN;else if(d instanceof G||d instanceof Date||d instanceof G)this.dataType=q.TIMESTAMP;else if(typeof d=="object")this.dataType=q.JSON;else throw new Error(`cannot infer data type of ${typeof d} when constructing a Series from a JS array`)}else this.dataType=new q(u)}if(!f&&!h)this._data=u;else{let d=h?[u]:u;const k=d[0];(k instanceof G||k instanceof Date||k instanceof Q)&&(d=d.map(D=>new G(D).valueOf())),this.dataType.equals(q.STRING)?(this._cachedLength=d.length,this._data=new TextEncoder().encode(d.join(`
|
|
18
18
|
`)+`
|
|
19
|
-
`)):this.dataType.equals(
|
|
19
|
+
`)):this.dataType.equals(q.JSON)?(this._cachedLength=d.length,this._data=new TextEncoder().encode(d.map(D=>En.encodeString(D)).join(`
|
|
20
20
|
`)+`
|
|
21
|
-
`)):this._data=new this.dataType.Array(d).buffer}this.key=c,this.alignment=o,this.sampleOffset=i??0,this._timeRange=r,this.gl={control:null,buffer:null,prevBuffer:0,bufferUsage:a}}static alloc({capacity:e,dataType:n,...r}){if(e===0)throw new Error("[Series] - cannot allocate an array of length 0");const i=new new
|
|
21
|
+
`)):this._data=new this.dataType.Array(d).buffer}this.key=c,this.alignment=o,this.sampleOffset=i??0,this._timeRange=r,this.gl={control:null,buffer:null,prevBuffer:0,bufferUsage:a}}static alloc({capacity:e,dataType:n,...r}){if(e===0)throw new Error("[Series] - cannot allocate an array of length 0");const i=new new q(n).Array(e),a=new Ae({data:i.buffer,dataType:n,...r});return a.writePos=0,a}static generateTimestamps(e,n,r){const i=r.spanRange(n.span(e)),a=new BigInt64Array(e);for(let o=0;o<e;o++)a[o]=BigInt(r.add(n.span(o)).valueOf());return new Ae({data:a,dataType:q.TIMESTAMP,timeRange:i})}get refCount(){return this._refCount}static fromStrings(e,n){const r=new TextEncoder().encode(e.join(`
|
|
22
22
|
`)+`
|
|
23
|
-
`);return new Ae({data:r,dataType:
|
|
23
|
+
`);return new Ae({data:r,dataType:q.STRING,timeRange:n})}static fromJSON(e,n){const r=new TextEncoder().encode(e.map(i=>En.encodeString(i)).join(`
|
|
24
24
|
`)+`
|
|
25
|
-
`);return new Ae({data:r,dataType:
|
|
26
|
-
`).slice(0,-1)}toUUIDs(){if(!this.dataType.equals(
|
|
27
|
-
`).slice(0,-1).map(n=>e.parse(En.decodeString(n)))}get timeRange(){if(this._timeRange==null)throw new Error("time range not set on series");return this._timeRange}get byteCapacity(){return new us(this.underlyingData.byteLength)}get capacity(){return this.dataType.isVariable?this.byteCapacity.valueOf():this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===Ue?this.byteCapacity:this.dataType.isVariable?new us(this.writePos):this.dataType.density.size(this.writePos)}get length(){return this._cachedLength!=null?this._cachedLength:this.dataType.isVariable?this.calculateCachedLength():this.writePos===Ue?this.data.length:this.writePos}calculateCachedLength(){if(!this.dataType.isVariable)throw new Error("cannot calculate length of a non-variable length data type");let e=0;const n=[0];return this.data.forEach((r,i)=>{r===hs&&(e++,n.push(i+1))}),this._cachedIndexes=n,this._cachedLength=e,e}convert(e,n=0){if(this.dataType.equals(e))return this;const r=new e.Array(this.length);for(let i=0;i<this.length;i++)r[i]=Fh(this.dataType,e,this.data[i],n);return new Ae({data:r.buffer,dataType:e,timeRange:this._timeRange,sampleOffset:n,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment})}calcRawMax(){if(this.length===0)return-1/0;if(this.dataType.equals(F.TIMESTAMP))this._cachedMax=this.data[this.data.length-1];else if(this.dataType.usesBigInt){const e=this.data;this._cachedMax=e.reduce((n,r)=>n>r?n:r)}else{const e=this.data;this._cachedMax=e.reduce((n,r)=>n>r?n:r)}return this._cachedMax}get max(){if(this.dataType.isVariable)throw new Error("cannot calculate maximum on a variable length data type");return this.writePos===0?-1/0:(this._cachedMax==null&&(this._cachedMax=this.calcRawMax()),xt(this._cachedMax,this.sampleOffset))}calcRawMin(){if(this.length===0)return 1/0;if(this.dataType.equals(F.TIMESTAMP))this._cachedMin=this.data[0];else if(this.dataType.usesBigInt){const e=this.data;this._cachedMin=e.reduce((n,r)=>n<r?n:r)}else{const e=this.data;this._cachedMin=e.reduce((n,r)=>n<r?n:r)}return this._cachedMin}get min(){if(this.dataType.isVariable)throw new Error("cannot calculate minimum on a variable length data type");return this.writePos===0?1/0:(this._cachedMin==null&&(this._cachedMin=this.calcRawMin()),xt(this._cachedMin,this.sampleOffset))}get bounds(){return He(Number(this.min),Number(this.max))}maybeRecomputeMinMax(e){if(this._cachedMin!=null){const n=e._cachedMin??e.calcRawMin();n<this._cachedMin&&(this._cachedMin=n)}if(this._cachedMax!=null){const n=e._cachedMax??e.calcRawMax();n>this._cachedMax&&(this._cachedMax=n)}}enrich(){this.max,this.min}get range(){return xt(this.max,-this.min)}atAlignment(e,n){const r=Number(e-this.alignment);if(r<0||r>=this.length){if(n===!0)throw new Error(`[series] - no value at index ${r}`);return}return this.at(r,n)}at(e,n){if(this.dataType.isVariable)return this.atVariable(e,n??!1);e<0&&(e=this.length+e);const r=this.data[e];if(r==null){if(n===!0)throw new Error(`[series] - no value at index ${e}`);return}return xt(r,this.sampleOffset)}atVariable(e,n){let r=0,i=0;if(this._cachedIndexes!=null)r=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]===hs){if(e===0){i=o;break}r=o+1,e--}if(i===0&&(i=this.data.length),r>=i||e>0){if(n)throw new Error(`[series] - no value at index ${e}`);return}}const a=this.data.slice(r,i);return this.dataType.equals(F.STRING)?new TextDecoder().decode(a):to(JSON.parse(new TextDecoder().decode(a)))}binarySearch(e){let n=0,r=this.length-1;const i=Rh(e);for(;n<=r;){const a=Math.floor((n+r)/2),o=i(this.at(a,!0),e);if(o===0)return a;o<0?n=a+1:r=a-1}return n}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals(F.FLOAT32))throw new Error("Only FLOAT32 arrays can be used in WebGL");const{buffer:n,bufferUsage:r,prevBuffer:i}=this.gl;if(n==null&&(this.gl.buffer=e.createBuffer()),this.writePos!==i)if(e.bindBuffer(e.ARRAY_BUFFER,this.gl.buffer),this.writePos!==Ue){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.underlyingData,r==="static"?e.STATIC_DRAW:e.DYNAMIC_DRAW),this.gl.prevBuffer=Ue}as(e){if(e==="string"){if(!this.dataType.equals(F.STRING))throw new Error(`cannot convert series of type ${this.dataType.toString()} to string`);return this}if(e==="number"){if(!this.dataType.isNumeric)throw new Error(`cannot convert series of type ${this.dataType.toString()} to number`);return this}if(e==="bigint"){if(!this.dataType.equals(F.INT64))throw new Error(`cannot convert series of type ${this.dataType.toString()} to bigint`);return this}throw new Error(`cannot convert series to ${e}`)}get digest(){var e;return{key:this.key,dataType:this.dataType.toString(),sampleOffset:this.sampleOffset,alignment:this.alignmentBounds,timeRange:(e=this._timeRange)==null?void 0:e.toString(),length:this.length,capacity:this.capacity}}get memInfo(){return{key:this.key,length:this.length,byteLength:this.byteLength,glBuffer:this.gl.buffer!=null}}get alignmentBounds(){return He(this.alignment,this.alignment+BigInt(this.length))}maybeGarbageCollectGLBuffer(e){this.gl.buffer!=null&&(e.deleteBuffer(this.gl.buffer),this.gl.buffer=null,this.gl.prevBuffer=0,this.gl.control=null)}get glBuffer(){if(this.gl.buffer==null)throw new Error("gl buffer not initialized");return this.gl.prevBuffer!==this.writePos&&console.warn("buffer not updated"),this.gl.buffer}[Symbol.iterator](){if(this.dataType.isVariable){const e=new Zh(this);return this.dataType.equals(F.JSON)?new Kh(e):e}return new Jh(this)}slice(e,n){return this.sliceSub(!1,e,n)}sub(e,n){return this.sliceSub(!0,e,n)}subIterator(e,n){return new xi(this,e,n??this.length)}subAlignmentIterator(e,n){return new xi(this,Number(e-this.alignment),Number(n-this.alignment))}subBytes(e,n){if(e>=0&&(n==null||n>=this.byteLength.valueOf()))return this;const r=this.data.subarray(e,n);return new Ae({data:r,dataType:this.dataType,timeRange:this._timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(e)})}sliceSub(e,n,r){if(n<=0&&(r==null||r>=this.length))return this;let i;return e?i=this.data.subarray(n,r):i=this.data.slice(n,r),new Ae({data:i,dataType:this.dataType,timeRange:this._timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(n)})}reAlign(e){return new Ae({data:this.buffer,dataType:this.dataType,timeRange:Ds.ZERO,sampleOffset:this.sampleOffset,glBufferUsage:"static",alignment:e})}};b(kt,"crudeZ",s.z.object({timeRange:Ds.z.optional(),dataType:F.z,alignment:Bh.optional(),data:s.z.union([Vh,Wh,s.z.instanceof(ArrayBuffer)]),glBufferUsage:Yh.optional().default("static").optional()})),b(kt,"z",kt.crudeZ.transform(t=>new kt(t)));let Gh=kt;class xi{constructor(e,n,r){b(this,"series"),b(this,"end"),b(this,"index"),this.series=e;const i=He(0,e.length);this.end=zi(i,r),this.index=zi(i,n)}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}[Symbol.iterator](){return this}}class Zh{constructor(e){if(b(this,"series"),b(this,"index"),b(this,"decoder"),!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,n=this.series.data;for(;this.index<n.length&&n[this.index]!==hs;)this.index++;const r=this.index;return e===r?{done:!0,value:void 0}:(this.index++,{done:!1,value:this.decoder.decode(this.series.buffer.slice(e,r))})}[Symbol.iterator](){return this}}var Ci,$i;class Kh{constructor(e){b(this,"wrapped"),b(this,Ci,"JSONSeriesIterator"),this.wrapped=e}next(){const e=this.wrapped.next();return e.done===!0?{done:!0,value:void 0}:{done:!1,value:En.decodeString(e.value)}}[($i=Symbol.iterator,Ci=Symbol.toStringTag,$i)](){return this}}var Ri,ji;class Jh{constructor(e){b(this,"series"),b(this,"index"),b(this,Ri,"SeriesIterator"),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)}}[(ji=Symbol.iterator,Ri=Symbol.toStringTag,ji)](){return this}}const xt=(t,e)=>typeof t=="bigint"&&typeof e=="bigint"||typeof t=="number"&&typeof e=="number"?t+e:e===0?t:t===0?e:Number(t)+Number(e);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 fo=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser",Hh=fo(),yo=["MacOS","Windows","Linux","Docker"],Xh=s.z.enum(yo);let $r;const Qh=()=>{if(typeof window>"u")return;const t=window.navigator.userAgent.toLowerCase();if(t.includes("mac"))return"MacOS";if(t.includes("win"))return"Windows";if(t.includes("linux"))return"Linux"},ed=(t={})=>{const{force:e,default:n}=t;return e??$r??($r=Qh(),$r??n)},go=Object.freeze(Object.defineProperty({__proto__:null,OPERATING_SYSTEMS:yo,RUNTIME:Hh,detect:fo,getOS:ed,osZ:Xh},Symbol.toStringTag,{value:"Module"}));var td=Object.defineProperty,nd=(t,e,n)=>e in t?td(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ct=(t,e,n)=>nd(t,typeof e!="symbol"?e+"":e,n);const rd=(...t)=>t.map(po).join(""),po=t=>(t.endsWith("/")||(t+="/"),t.startsWith("/")&&(t=t.slice(1)),t),sd=t=>t.endsWith("/")?t.slice(0,-1):t,id=(t,e="")=>t===null?"":"?"+Object.entries(t).filter(([,n])=>n==null?!1:Array.isArray(n)?n.length>0:!0).map(([n,r])=>`${e}${n}=${r}`).join("&"),ds=class fs{constructor({host:e,port:n,protocol:r="",pathPrefix:i=""}){Ct(this,"protocol"),Ct(this,"host"),Ct(this,"port"),Ct(this,"path"),this.protocol=r,this.host=e,this.port=n,this.path=po(i)}replace(e){return new fs({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new fs({...this,pathPrefix:rd(this.path,e)})}toString(){return sd(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}};Ct(ds,"UNKNOWN",new ds({host:"unknown",port:0}));let ad=ds;var od=Object.defineProperty,ld=(t,e,n)=>e in t?od(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,xn=(t,e,n)=>ld(t,typeof e!="symbol"?e+"":e,n);const tt=class extends Number{};xn(tt,"Absolute",255),xn(tt,"Default",1),xn(tt,"z",s.z.union([s.z.instanceof(tt),s.z.number().int().min(0).max(255).transform(t=>new tt(t)),s.z.instanceof(Number).transform(t=>new tt(t))]));s.z.object({name:s.z.string(),key:s.z.string()});const mo=class $t extends Error{constructor(){super($t.MESSAGE)}matches(e){return typeof e=="string"?e.includes($t.MESSAGE):e instanceof $t||e.message.includes($t.MESSAGE)}};xn(mo,"MESSAGE","canceled");let cd=mo;new cd;s.z.string().regex(/^\d+\.\d+\.\d+$/);const fe=t=>e=>e!=null&&typeof e=="object"&&"type"in e&&typeof e.type=="string"?e.type.includes(t):e instanceof Error?e.message.includes(t):typeof e!="string"?!1:e.includes(t);let Te=class extends Error{constructor(e){super(e),B(this,"discriminator","FreighterError"),B(this,"type","")}};const ud=t=>{if(t==null||typeof t!="object")return!1;const e=t;if(e.discriminator!=="FreighterError")return!1;if(!("type"in e))throw new Error(`Freighter error is missing its type property: ${JSON.stringify(e)}`);return!0},Mi="unknown",Bi="nil",hd="freighter",sn=s.z.object({type:s.z.string(),data:s.z.string()});class dd{constructor(){B(this,"providers",[])}register(e){this.providers.push(e)}encode(e){if(e==null)return{type:Bi,data:""};if(ud(e))for(const n of this.providers){const r=n.encode(e);if(r!=null)return r}return{type:Mi,data:JSON.stringify(e)}}decode(e){if(e==null||e.type===Bi)return null;if(e.type===Mi)return new Di(e.data);for(const n of this.providers){const r=n.decode(e);if(r!=null)return r}return new Di(e.data)}}const wo=new dd,bo=({encode:t,decode:e})=>wo.register({encode:t,decode:e}),Ps=t=>wo.decode(t);class Di extends Te{constructor(e){super(e),B(this,"type","unknown")}}const cr="freighter.",Cn=class vo extends Te{constructor(){super("EOF"),B(this,"type",vo.TYPE)}};B(Cn,"TYPE",cr+"eof"),B(Cn,"matches",fe(Cn.TYPE));let Fe=Cn;const $n=class Oo extends Te{constructor(){super("StreamClosed"),B(this,"type",Oo.TYPE)}};B($n,"TYPE",cr+"stream_closed"),B($n,"matches",fe($n.TYPE));let at=$n;const Rn=class To extends Te{constructor(e={}){const{message:n="Unreachable",url:r=ad.UNKNOWN}=e;super(n),B(this,"type",To.TYPE),B(this,"url"),this.url=r}};B(Rn,"TYPE",cr+"unreachable"),B(Rn,"matches",fe(Rn.TYPE));let Xe=Rn;const fd=t=>{if(!t.type.startsWith(hd))return null;if(Fe.matches(t))return{type:Fe.TYPE,data:"EOF"};if(at.matches(t))return{type:at.TYPE,data:"StreamClosed"};if(Xe.matches(t))return{type:Xe.TYPE,data:"Unreachable"};throw new Error(`Unknown error type: ${t.type}: ${t.message}`)},yd=t=>{if(!t.type.startsWith(cr))return null;switch(t.type){case Fe.TYPE:return new Fe;case at.TYPE:return new at;case Xe.TYPE:return new Xe;default:throw new Error(`Unknown error type: ${t.data}`)}};bo({encode:fd,decode:yd});let So=class{constructor(){B(this,"middleware",[])}use(...t){this.middleware.push(...t)}async executeMiddleware(t,e){let n=0;const r=async i=>{if(n===this.middleware.length)return await e(i);const a=this.middleware[n];return n++,await a(i,r)};return await r(t)}};const zo="Content-Type",Pi=t=>{if(go.RUNTIME!=="node")return fetch;const e=require("node-fetch");if(t==="http")return e;const n=require("https"),r=new n.Agent({rejectUnauthorized:!1});return async(i,a)=>await e(i,{...a,agent:r})};class gd extends So{constructor(e,n,r=!1){return super(),B(this,"endpoint"),B(this,"encoder"),B(this,"fetch"),this.endpoint=e.replace({protocol:r?"https":"http"}),this.encoder=n,this.fetch=Pi(this.endpoint.protocol),new Proxy(this,{get:(i,a,o)=>a==="endpoint"?this.endpoint:Reflect.get(i,a,o)})}get headers(){return{[zo]:this.encoder.contentType}}async send(e,n,r,i){n=r==null?void 0:r.parse(n);let a=null;const o=this.endpoint.child(e),c={};c.method="POST",c.body=this.encoder.encode(n??{});const[,u]=await this.executeMiddleware({target:o.toString(),protocol:this.endpoint.protocol,params:{},role:"client"},async h=>{const f={...h,params:{}};c.headers={...this.headers,...h.params};let d;try{d=await Pi(h.protocol)(h.target,c)}catch(D){let ie=D;return ie.message==="Load failed"&&(ie=new Xe({url:o})),[f,ie]}const k=await d.arrayBuffer();if(d!=null&&d.ok)return i!=null&&(a=this.encoder.decode(k,i)),[f,null];try{if(d.status!==400)return[f,new Error(d.statusText)];const D=this.encoder.decode(k,sn),ie=Ps(D);return[f,ie]}catch(D){return[f,new Error(`[freighter] - failed to decode error: ${d.statusText}: ${D.message}`)]}});return[a,u]}}const v=async(t,e,n,r,i)=>{const[a,o]=await t.send(e,n,r,i);if(o!=null)throw o;return a},pd=()=>go.RUNTIME!=="node"?t=>new WebSocket(t):t=>new(require("ws")).WebSocket(t,{rejectUnauthorized:!1}),md=s.z.object({type:s.z.union([s.z.literal("data"),s.z.literal("close")]),payload:s.z.unknown().optional(),error:s.z.optional(sn)});class wd{constructor(e,n,r,i){B(this,"encoder"),B(this,"reqSchema"),B(this,"resSchema"),B(this,"ws"),B(this,"serverClosed"),B(this,"sendClosed"),B(this,"receiveDataQueue",[]),B(this,"receiveCallbacksQueue",[]),this.encoder=n,this.reqSchema=r,this.resSchema=i,this.ws=e,this.sendClosed=!1,this.serverClosed=null,this.listenForMessages()}send(e){if(this.serverClosed!=null)return new Fe;if(this.sendClosed)throw new at;return this.ws.send(this.encoder.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");return this.serverClosed=Ps(e.error),[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.encoder.encode(e))}finally{this.sendClosed=!0}}async receiveMsg(){return this.receiveDataQueue.shift()??await new Promise((e,n)=>this.receiveCallbacksQueue.push({resolve:e,reject:n}))}addMessage(e){const n=this.receiveCallbacksQueue.shift();n!=null?n.resolve(e):this.receiveDataQueue.push(e)}listenForMessages(){this.ws.onmessage=e=>this.addMessage(this.encoder.decode(e.data,md)),this.ws.onclose=e=>this.addMessage({type:"close",error:{type:Sd(e)?Fe.TYPE:at.TYPE,data:""}})}}const bd="freighterctx",vd=1e3,Od=1001,Td=[vd,Od],Sd=t=>Td.includes(t.code),No=class Io extends So{constructor(e,n,r=!1){super(),B(this,"baseUrl"),B(this,"encoder"),this.baseUrl=e.replace({protocol:r?"wss":"ws"}),this.encoder=n}async stream(e,n,r){const i=pd();let a;const[,o]=await this.executeMiddleware({target:e,protocol:"websocket",params:{},role:"client"},async c=>{const u=i(this.buildURL(e,c)),h={...c,params:{}};u.binaryType=Io.MESSAGE_TYPE;const f=await this.wrapSocket(u,n,r);return f instanceof Error?[h,f]:(a=f,[h,null])});if(o!=null)throw o;return a}buildURL(e,n){const r=id({[zo]:this.encoder.contentType,...n.params},bd);return this.baseUrl.child(e).toString()+r}async wrapSocket(e,n,r){return await new Promise(i=>{e.onopen=()=>{i(new wd(e,this.encoder,n,r))},e.onerror=a=>{const o=a;i(new Error(o.message))}})}};B(No,"MESSAGE_TYPE","arraybuffer");let zd=No;const ys=s.z.union([s.z.literal("all"),s.z.literal("create"),s.z.literal("delete"),s.z.literal("retrieve"),s.z.literal("update")]),Nd=t=>{const e=t.replace(/_[a-z]/g,n=>n[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)},Eo=t=>{const e=(n,r=gs)=>{if(typeof n=="string")return t(n);if(Array.isArray(n))return n.map(o=>e(o,r));if(!Rr(n))return n;r=Ad(r);const i={},a=n;return Object.keys(a).forEach(o=>{let c=a[o];const u=t(o);r.recursive&&(Rr(c)?Li(c,r.keepTypesOnRecursion)||(c=e(c,r)):r.recursiveInArray&&Ui(c)&&(c=[...c].map(h=>{let f=h;return Rr(h)?Li(f,r.keepTypesOnRecursion)||(f=e(h,r)):Ui(h)&&(f=e({key:h},r).key),f}))),i[u]=c}),i};return e},Ao=Eo(Nd),Id=t=>t.replace(/([a-z0-9])([A-Z])/g,(e,n,r)=>`${n}_${r.toLowerCase()}`),Ed=Eo(Id),gs={recursive:!0,recursiveInArray:!0,keepTypesOnRecursion:[Number,String,Uint8Array]},Ad=(t=gs)=>(t.recursive==null?t=gs:t.recursiveInArray==null&&(t.recursiveInArray=!1),t),Ui=t=>t!=null&&Array.isArray(t),Rr=t=>t!=null&&typeof t=="object"&&!Array.isArray(t),Li=(t,e)=>(e||[]).some(n=>t instanceof n),Us=t=>t!=null&&typeof t=="object"&&!Array.isArray(t);var kd=Object.defineProperty,xd=(t,e,n)=>e in t?kd(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Vt=(t,e,n)=>xd(t,typeof e!="symbol"?e+"":e,n);let ko=class{constructor(){Vt(this,"contentType","application/json"),Vt(this,"decoder"),Vt(this,"encoder"),this.decoder=new TextDecoder,this.encoder=new TextEncoder}encode(t){return this.encoder.encode(this.encodeString(t)).buffer}decode(t,e){return this.decodeString(this.decoder.decode(t),e)}decodeString(t,e){const n=JSON.parse(t),r=Ao(n);return e!=null?e.parse(r):r}encodeString(t){const e=Ed(t);return JSON.stringify(e,(n,r)=>ArrayBuffer.isView(r)?Array.from(r):Us(r)&&"encode_value"in r?typeof r.value=="bigint"?r.value.toString():r.value:typeof r=="bigint"?r.toString():r)}static registerCustomType(){}},xo=class{constructor(){Vt(this,"contentType","text/csv")}encode(t){const e=this.encodeString(t);return new TextEncoder().encode(e).buffer}decode(t,e){const n=new TextDecoder().decode(t);return this.decodeString(n,e)}encodeString(t){if(!Array.isArray(t)||t.length===0||!Us(t[0]))throw new Error("Payload must be an array of objects");const e=Object.keys(t[0]),n=[e.join(",")];return t.forEach(r=>{const i=e.map(a=>JSON.stringify(r[a]??""));n.push(i.join(","))}),n.join(`
|
|
25
|
+
`);return new Ae({data:r,dataType:q.JSON,timeRange:n})}acquire(e){this._refCount++,e!=null&&this.updateGLBuffer(e)}release(){if(this._refCount--,this._refCount===0&&this.gl.control!=null)this.maybeGarbageCollectGLBuffer(this.gl.control);else if(this._refCount<0)throw new Error("cannot release an array 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===Ue)return 0;const n=this.byteCapacity.valueOf()-this.writePos,r=e.subBytes(0,n);return this.writeToUnderlyingData(r),this.writePos+=r.byteLength.valueOf(),this._cachedLength!=null&&(this._cachedLength+=r.length,this.calculateCachedLength()),r.length}writeFixed(e){if(this.writePos===Ue)return 0;const n=this.capacity-this.writePos,r=e.sub(0,n);return this.writeToUnderlyingData(r),this._cachedLength=void 0,this.maybeRecomputeMinMax(r),this.writePos+=r.length,r.length}writeToUnderlyingData(e){this.underlyingData.set(e.data,this.writePos)}get buffer(){return this._data instanceof ArrayBuffer||this._data instanceof SharedArrayBuffer?this._data:this._data.buffer}get underlyingData(){return new this.dataType.Array(this._data)}get data(){return this.writePos===Ue?this.underlyingData:new this.dataType.Array(this._data,0,this.writePos)}toStrings(){if(!this.dataType.matches(q.STRING,q.UUID))throw new Error("cannot convert non-string series to strings");return new TextDecoder().decode(this.underlyingData).split(`
|
|
26
|
+
`).slice(0,-1)}toUUIDs(){if(!this.dataType.equals(q.UUID))throw new Error("cannot convert non-uuid series to uuids");const e=q.UUID.density.valueOf(),n=Array(this.length);for(let r=0;r<this.length;r++){const i=this.underlyingData.slice(r*e,(r+1)*e),a=Array.from(new Uint8Array(i),o=>o.toString(16).padStart(2,"0")).join("").replace(/(.{8})(.{4})(.{4})(.{4})(.{12})/,"$1-$2-$3-$4-$5");n[r]=a}return n}parseJSON(e){if(!this.dataType.equals(q.JSON))throw new Error("cannot convert non-string series to strings");return new TextDecoder().decode(this.underlyingData).split(`
|
|
27
|
+
`).slice(0,-1).map(n=>e.parse(En.decodeString(n)))}get timeRange(){if(this._timeRange==null)throw new Error("time range not set on series");return this._timeRange}get byteCapacity(){return new us(this.underlyingData.byteLength)}get capacity(){return this.dataType.isVariable?this.byteCapacity.valueOf():this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===Ue?this.byteCapacity:this.dataType.isVariable?new us(this.writePos):this.dataType.density.size(this.writePos)}get length(){return this._cachedLength!=null?this._cachedLength:this.dataType.isVariable?this.calculateCachedLength():this.writePos===Ue?this.data.length:this.writePos}calculateCachedLength(){if(!this.dataType.isVariable)throw new Error("cannot calculate length of a non-variable length data type");let e=0;const n=[0];return this.data.forEach((r,i)=>{r===hs&&(e++,n.push(i+1))}),this._cachedIndexes=n,this._cachedLength=e,e}convert(e,n=0){if(this.dataType.equals(e))return this;const r=new e.Array(this.length);for(let i=0;i<this.length;i++)r[i]=Fh(this.dataType,e,this.data[i],n);return new Ae({data:r.buffer,dataType:e,timeRange:this._timeRange,sampleOffset:n,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment})}calcRawMax(){if(this.length===0)return-1/0;if(this.dataType.equals(q.TIMESTAMP))this._cachedMax=this.data[this.data.length-1];else if(this.dataType.usesBigInt){const e=this.data;this._cachedMax=e.reduce((n,r)=>n>r?n:r)}else{const e=this.data;this._cachedMax=e.reduce((n,r)=>n>r?n:r)}return this._cachedMax}get max(){if(this.dataType.isVariable)throw new Error("cannot calculate maximum on a variable length data type");return this.writePos===0?-1/0:(this._cachedMax==null&&(this._cachedMax=this.calcRawMax()),xt(this._cachedMax,this.sampleOffset))}calcRawMin(){if(this.length===0)return 1/0;if(this.dataType.equals(q.TIMESTAMP))this._cachedMin=this.data[0];else if(this.dataType.usesBigInt){const e=this.data;this._cachedMin=e.reduce((n,r)=>n<r?n:r)}else{const e=this.data;this._cachedMin=e.reduce((n,r)=>n<r?n:r)}return this._cachedMin}get min(){if(this.dataType.isVariable)throw new Error("cannot calculate minimum on a variable length data type");return this.writePos===0?1/0:(this._cachedMin==null&&(this._cachedMin=this.calcRawMin()),xt(this._cachedMin,this.sampleOffset))}get bounds(){return He(Number(this.min),Number(this.max))}maybeRecomputeMinMax(e){if(this._cachedMin!=null){const n=e._cachedMin??e.calcRawMin();n<this._cachedMin&&(this._cachedMin=n)}if(this._cachedMax!=null){const n=e._cachedMax??e.calcRawMax();n>this._cachedMax&&(this._cachedMax=n)}}enrich(){this.max,this.min}get range(){return xt(this.max,-this.min)}atAlignment(e,n){const r=Number(e-this.alignment);if(r<0||r>=this.length){if(n===!0)throw new Error(`[series] - no value at index ${r}`);return}return this.at(r,n)}at(e,n){if(this.dataType.isVariable)return this.atVariable(e,n??!1);e<0&&(e=this.length+e);const r=this.data[e];if(r==null){if(n===!0)throw new Error(`[series] - no value at index ${e}`);return}return xt(r,this.sampleOffset)}atVariable(e,n){let r=0,i=0;if(this._cachedIndexes!=null)r=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]===hs){if(e===0){i=o;break}r=o+1,e--}if(i===0&&(i=this.data.length),r>=i||e>0){if(n)throw new Error(`[series] - no value at index ${e}`);return}}const a=this.data.slice(r,i);return this.dataType.equals(q.STRING)?new TextDecoder().decode(a):to(JSON.parse(new TextDecoder().decode(a)))}binarySearch(e){let n=0,r=this.length-1;const i=jh(e);for(;n<=r;){const a=Math.floor((n+r)/2),o=i(this.at(a,!0),e);if(o===0)return a;o<0?n=a+1:r=a-1}return n}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals(q.FLOAT32))throw new Error("Only FLOAT32 arrays can be used in WebGL");const{buffer:n,bufferUsage:r,prevBuffer:i}=this.gl;if(n==null&&(this.gl.buffer=e.createBuffer()),this.writePos!==i)if(e.bindBuffer(e.ARRAY_BUFFER,this.gl.buffer),this.writePos!==Ue){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.underlyingData,r==="static"?e.STATIC_DRAW:e.DYNAMIC_DRAW),this.gl.prevBuffer=Ue}as(e){if(e==="string"){if(!this.dataType.equals(q.STRING))throw new Error(`cannot convert series of type ${this.dataType.toString()} to string`);return this}if(e==="number"){if(!this.dataType.isNumeric)throw new Error(`cannot convert series of type ${this.dataType.toString()} to number`);return this}if(e==="bigint"){if(!this.dataType.equals(q.INT64))throw new Error(`cannot convert series of type ${this.dataType.toString()} to bigint`);return this}throw new Error(`cannot convert series to ${e}`)}get digest(){var e;return{key:this.key,dataType:this.dataType.toString(),sampleOffset:this.sampleOffset,alignment:this.alignmentBounds,timeRange:(e=this._timeRange)==null?void 0:e.toString(),length:this.length,capacity:this.capacity}}get memInfo(){return{key:this.key,length:this.length,byteLength:this.byteLength,glBuffer:this.gl.buffer!=null}}get alignmentBounds(){return He(this.alignment,this.alignment+BigInt(this.length))}maybeGarbageCollectGLBuffer(e){this.gl.buffer!=null&&(e.deleteBuffer(this.gl.buffer),this.gl.buffer=null,this.gl.prevBuffer=0,this.gl.control=null)}get glBuffer(){if(this.gl.buffer==null)throw new Error("gl buffer not initialized");return this.gl.prevBuffer!==this.writePos&&console.warn("buffer not updated"),this.gl.buffer}[Symbol.iterator](){if(this.dataType.isVariable){const e=new Kh(this);return this.dataType.equals(q.JSON)?new Jh(e):e}return new Hh(this)}slice(e,n){return this.sliceSub(!1,e,n)}sub(e,n){return this.sliceSub(!0,e,n)}subIterator(e,n){return new xi(this,e,n??this.length)}subAlignmentIterator(e,n){return new xi(this,Number(e-this.alignment),Number(n-this.alignment))}subBytes(e,n){if(e>=0&&(n==null||n>=this.byteLength.valueOf()))return this;const r=this.data.subarray(e,n);return new Ae({data:r,dataType:this.dataType,timeRange:this._timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(e)})}sliceSub(e,n,r){if(n<=0&&(r==null||r>=this.length))return this;let i;return e?i=this.data.subarray(n,r):i=this.data.slice(n,r),new Ae({data:i,dataType:this.dataType,timeRange:this._timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(n)})}reAlign(e){return new Ae({data:this.buffer,dataType:this.dataType,timeRange:Ds.ZERO,sampleOffset:this.sampleOffset,glBufferUsage:"static",alignment:e})}};b(kt,"crudeZ",s.z.object({timeRange:Ds.z.optional(),dataType:q.z,alignment:Dh.optional(),data:s.z.union([Wh,Gh,s.z.instanceof(ArrayBuffer)]),glBufferUsage:qh.optional().default("static").optional()})),b(kt,"z",kt.crudeZ.transform(t=>new kt(t)));let Zh=kt;class xi{constructor(e,n,r){b(this,"series"),b(this,"end"),b(this,"index"),this.series=e;const i=He(0,e.length);this.end=zi(i,r),this.index=zi(i,n)}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}[Symbol.iterator](){return this}}class Kh{constructor(e){if(b(this,"series"),b(this,"index"),b(this,"decoder"),!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,n=this.series.data;for(;this.index<n.length&&n[this.index]!==hs;)this.index++;const r=this.index;return e===r?{done:!0,value:void 0}:(this.index++,{done:!1,value:this.decoder.decode(this.series.buffer.slice(e,r))})}[Symbol.iterator](){return this}}var Ci,$i;class Jh{constructor(e){b(this,"wrapped"),b(this,Ci,"JSONSeriesIterator"),this.wrapped=e}next(){const e=this.wrapped.next();return e.done===!0?{done:!0,value:void 0}:{done:!1,value:En.decodeString(e.value)}}[($i=Symbol.iterator,Ci=Symbol.toStringTag,$i)](){return this}}var Ri,ji;class Hh{constructor(e){b(this,"series"),b(this,"index"),b(this,Ri,"SeriesIterator"),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)}}[(ji=Symbol.iterator,Ri=Symbol.toStringTag,ji)](){return this}}const xt=(t,e)=>typeof t=="bigint"&&typeof e=="bigint"||typeof t=="number"&&typeof e=="number"?t+e:e===0?t:t===0?e:Number(t)+Number(e);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 fo=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser",Xh=fo(),yo=["MacOS","Windows","Linux","Docker"],Qh=s.z.enum(yo);let $r;const ed=()=>{if(typeof window>"u")return;const t=window.navigator.userAgent.toLowerCase();if(t.includes("mac"))return"MacOS";if(t.includes("win"))return"Windows";if(t.includes("linux"))return"Linux"},td=(t={})=>{const{force:e,default:n}=t;return e??$r??($r=ed(),$r??n)},go=Object.freeze(Object.defineProperty({__proto__:null,OPERATING_SYSTEMS:yo,RUNTIME:Xh,detect:fo,getOS:td,osZ:Qh},Symbol.toStringTag,{value:"Module"}));var nd=Object.defineProperty,rd=(t,e,n)=>e in t?nd(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Ct=(t,e,n)=>rd(t,typeof e!="symbol"?e+"":e,n);const sd=(...t)=>t.map(po).join(""),po=t=>(t.endsWith("/")||(t+="/"),t.startsWith("/")&&(t=t.slice(1)),t),id=t=>t.endsWith("/")?t.slice(0,-1):t,ad=(t,e="")=>t===null?"":"?"+Object.entries(t).filter(([,n])=>n==null?!1:Array.isArray(n)?n.length>0:!0).map(([n,r])=>`${e}${n}=${r}`).join("&"),ds=class fs{constructor({host:e,port:n,protocol:r="",pathPrefix:i=""}){Ct(this,"protocol"),Ct(this,"host"),Ct(this,"port"),Ct(this,"path"),this.protocol=r,this.host=e,this.port=n,this.path=po(i)}replace(e){return new fs({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new fs({...this,pathPrefix:sd(this.path,e)})}toString(){return id(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}};Ct(ds,"UNKNOWN",new ds({host:"unknown",port:0}));let od=ds;var ld=Object.defineProperty,cd=(t,e,n)=>e in t?ld(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,xn=(t,e,n)=>cd(t,typeof e!="symbol"?e+"":e,n);const tt=class extends Number{};xn(tt,"Absolute",255),xn(tt,"Default",1),xn(tt,"z",s.z.union([s.z.instanceof(tt),s.z.number().int().min(0).max(255).transform(t=>new tt(t)),s.z.instanceof(Number).transform(t=>new tt(t))]));s.z.object({name:s.z.string(),key:s.z.string()});const mo=class $t extends Error{constructor(){super($t.MESSAGE)}matches(e){return typeof e=="string"?e.includes($t.MESSAGE):e instanceof $t||e.message.includes($t.MESSAGE)}};xn(mo,"MESSAGE","canceled");let ud=mo;new ud;s.z.string().regex(/^\d+\.\d+\.\d+$/);const fe=t=>e=>e!=null&&typeof e=="object"&&"type"in e&&typeof e.type=="string"?e.type.includes(t):e instanceof Error?e.message.includes(t):typeof e!="string"?!1:e.includes(t);let Te=class extends Error{constructor(e){super(e),M(this,"discriminator","FreighterError"),M(this,"type","")}};const hd=t=>{if(t==null||typeof t!="object")return!1;const e=t;if(e.discriminator!=="FreighterError")return!1;if(!("type"in e))throw new Error(`Freighter error is missing its type property: ${JSON.stringify(e)}`);return!0},Bi="unknown",Mi="nil",dd="freighter",sn=s.z.object({type:s.z.string(),data:s.z.string()});class fd{constructor(){M(this,"providers",[])}register(e){this.providers.push(e)}encode(e){if(e==null)return{type:Mi,data:""};if(hd(e))for(const n of this.providers){const r=n.encode(e);if(r!=null)return r}return{type:Bi,data:JSON.stringify(e)}}decode(e){if(e==null||e.type===Mi)return null;if(e.type===Bi)return new Di(e.data);for(const n of this.providers){const r=n.decode(e);if(r!=null)return r}return new Di(e.data)}}const wo=new fd,bo=({encode:t,decode:e})=>wo.register({encode:t,decode:e}),Ps=t=>wo.decode(t);class Di extends Te{constructor(e){super(e),M(this,"type","unknown")}}const cr="freighter.",Cn=class vo extends Te{constructor(){super("EOF"),M(this,"type",vo.TYPE)}};M(Cn,"TYPE",cr+"eof"),M(Cn,"matches",fe(Cn.TYPE));let qe=Cn;const $n=class Oo extends Te{constructor(){super("StreamClosed"),M(this,"type",Oo.TYPE)}};M($n,"TYPE",cr+"stream_closed"),M($n,"matches",fe($n.TYPE));let at=$n;const Rn=class To extends Te{constructor(e={}){const{message:n="Unreachable",url:r=od.UNKNOWN}=e;super(n),M(this,"type",To.TYPE),M(this,"url"),this.url=r}};M(Rn,"TYPE",cr+"unreachable"),M(Rn,"matches",fe(Rn.TYPE));let Xe=Rn;const yd=t=>{if(!t.type.startsWith(dd))return null;if(qe.matches(t))return{type:qe.TYPE,data:"EOF"};if(at.matches(t))return{type:at.TYPE,data:"StreamClosed"};if(Xe.matches(t))return{type:Xe.TYPE,data:"Unreachable"};throw new Error(`Unknown error type: ${t.type}: ${t.message}`)},gd=t=>{if(!t.type.startsWith(cr))return null;switch(t.type){case qe.TYPE:return new qe;case at.TYPE:return new at;case Xe.TYPE:return new Xe;default:throw new Error(`Unknown error type: ${t.data}`)}};bo({encode:yd,decode:gd});let So=class{constructor(){M(this,"middleware",[])}use(...t){this.middleware.push(...t)}async executeMiddleware(t,e){let n=0;const r=async i=>{if(n===this.middleware.length)return await e(i);const a=this.middleware[n];return n++,await a(i,r)};return await r(t)}};const zo="Content-Type",Pi=t=>{if(go.RUNTIME!=="node")return fetch;const e=require("node-fetch");if(t==="http")return e;const n=require("https"),r=new n.Agent({rejectUnauthorized:!1});return async(i,a)=>await e(i,{...a,agent:r})};class pd extends So{constructor(e,n,r=!1){return super(),M(this,"endpoint"),M(this,"encoder"),M(this,"fetch"),this.endpoint=e.replace({protocol:r?"https":"http"}),this.encoder=n,this.fetch=Pi(this.endpoint.protocol),new Proxy(this,{get:(i,a,o)=>a==="endpoint"?this.endpoint:Reflect.get(i,a,o)})}get headers(){return{[zo]:this.encoder.contentType}}async send(e,n,r,i){n=r==null?void 0:r.parse(n);let a=null;const o=this.endpoint.child(e),c={};c.method="POST",c.body=this.encoder.encode(n??{});const[,u]=await this.executeMiddleware({target:o.toString(),protocol:this.endpoint.protocol,params:{},role:"client"},async h=>{const f={...h,params:{}};c.headers={...this.headers,...h.params};let d;try{d=await Pi(h.protocol)(h.target,c)}catch(D){let ie=D;return ie.message==="Load failed"&&(ie=new Xe({url:o})),[f,ie]}const k=await d.arrayBuffer();if(d!=null&&d.ok)return i!=null&&(a=this.encoder.decode(k,i)),[f,null];try{if(d.status!==400)return[f,new Error(d.statusText)];const D=this.encoder.decode(k,sn),ie=Ps(D);return[f,ie]}catch(D){return[f,new Error(`[freighter] - failed to decode error: ${d.statusText}: ${D.message}`)]}});return[a,u]}}const v=async(t,e,n,r,i)=>{const[a,o]=await t.send(e,n,r,i);if(o!=null)throw o;return a},md=()=>go.RUNTIME!=="node"?t=>new WebSocket(t):t=>new(require("ws")).WebSocket(t,{rejectUnauthorized:!1}),wd=s.z.object({type:s.z.union([s.z.literal("data"),s.z.literal("close")]),payload:s.z.unknown().optional(),error:s.z.optional(sn)});class bd{constructor(e,n,r,i){M(this,"encoder"),M(this,"reqSchema"),M(this,"resSchema"),M(this,"ws"),M(this,"serverClosed"),M(this,"sendClosed"),M(this,"receiveDataQueue",[]),M(this,"receiveCallbacksQueue",[]),this.encoder=n,this.reqSchema=r,this.resSchema=i,this.ws=e,this.sendClosed=!1,this.serverClosed=null,this.listenForMessages()}send(e){if(this.serverClosed!=null)return new qe;if(this.sendClosed)throw new at;return this.ws.send(this.encoder.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");return this.serverClosed=Ps(e.error),[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.encoder.encode(e))}finally{this.sendClosed=!0}}async receiveMsg(){return this.receiveDataQueue.shift()??await new Promise((e,n)=>this.receiveCallbacksQueue.push({resolve:e,reject:n}))}addMessage(e){const n=this.receiveCallbacksQueue.shift();n!=null?n.resolve(e):this.receiveDataQueue.push(e)}listenForMessages(){this.ws.onmessage=e=>this.addMessage(this.encoder.decode(e.data,wd)),this.ws.onclose=e=>this.addMessage({type:"close",error:{type:zd(e)?qe.TYPE:at.TYPE,data:""}})}}const vd="freighterctx",Od=1e3,Td=1001,Sd=[Od,Td],zd=t=>Sd.includes(t.code),No=class Io extends So{constructor(e,n,r=!1){super(),M(this,"baseUrl"),M(this,"encoder"),this.baseUrl=e.replace({protocol:r?"wss":"ws"}),this.encoder=n}async stream(e,n,r){const i=md();let a;const[,o]=await this.executeMiddleware({target:e,protocol:"websocket",params:{},role:"client"},async c=>{const u=i(this.buildURL(e,c)),h={...c,params:{}};u.binaryType=Io.MESSAGE_TYPE;const f=await this.wrapSocket(u,n,r);return f instanceof Error?[h,f]:(a=f,[h,null])});if(o!=null)throw o;return a}buildURL(e,n){const r=ad({[zo]:this.encoder.contentType,...n.params},vd);return this.baseUrl.child(e).toString()+r}async wrapSocket(e,n,r){return await new Promise(i=>{e.onopen=()=>{i(new bd(e,this.encoder,n,r))},e.onerror=a=>{const o=a;i(new Error(o.message))}})}};M(No,"MESSAGE_TYPE","arraybuffer");let Nd=No;const ys=s.z.union([s.z.literal("all"),s.z.literal("create"),s.z.literal("delete"),s.z.literal("retrieve"),s.z.literal("update")]),Id=t=>{const e=t.replace(/_[a-z]/g,n=>n[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)},Eo=t=>{const e=(n,r=gs)=>{if(typeof n=="string")return t(n);if(Array.isArray(n))return n.map(o=>e(o,r));if(!Rr(n))return n;r=kd(r);const i={},a=n;return Object.keys(a).forEach(o=>{let c=a[o];const u=t(o);r.recursive&&(Rr(c)?Li(c,r.keepTypesOnRecursion)||(c=e(c,r)):r.recursiveInArray&&Ui(c)&&(c=[...c].map(h=>{let f=h;return Rr(h)?Li(f,r.keepTypesOnRecursion)||(f=e(h,r)):Ui(h)&&(f=e({key:h},r).key),f}))),i[u]=c}),i};return e},Ao=Eo(Id),Ed=t=>t.replace(/([a-z0-9])([A-Z])/g,(e,n,r)=>`${n}_${r.toLowerCase()}`),Ad=Eo(Ed),gs={recursive:!0,recursiveInArray:!0,keepTypesOnRecursion:[Number,String,Uint8Array]},kd=(t=gs)=>(t.recursive==null?t=gs:t.recursiveInArray==null&&(t.recursiveInArray=!1),t),Ui=t=>t!=null&&Array.isArray(t),Rr=t=>t!=null&&typeof t=="object"&&!Array.isArray(t),Li=(t,e)=>(e||[]).some(n=>t instanceof n),Us=t=>t!=null&&typeof t=="object"&&!Array.isArray(t);var xd=Object.defineProperty,Cd=(t,e,n)=>e in t?xd(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Vt=(t,e,n)=>Cd(t,typeof e!="symbol"?e+"":e,n);let ko=class{constructor(){Vt(this,"contentType","application/json"),Vt(this,"decoder"),Vt(this,"encoder"),this.decoder=new TextDecoder,this.encoder=new TextEncoder}encode(t){return this.encoder.encode(this.encodeString(t)).buffer}decode(t,e){return this.decodeString(this.decoder.decode(t),e)}decodeString(t,e){const n=JSON.parse(t),r=Ao(n);return e!=null?e.parse(r):r}encodeString(t){const e=Ad(t);return JSON.stringify(e,(n,r)=>ArrayBuffer.isView(r)?Array.from(r):Us(r)&&"encode_value"in r?typeof r.value=="bigint"?r.value.toString():r.value:typeof r=="bigint"?r.toString():r)}static registerCustomType(){}},xo=class{constructor(){Vt(this,"contentType","text/csv")}encode(t){const e=this.encodeString(t);return new TextEncoder().encode(e).buffer}decode(t,e){const n=new TextDecoder().decode(t);return this.decodeString(n,e)}encodeString(t){if(!Array.isArray(t)||t.length===0||!Us(t[0]))throw new Error("Payload must be an array of objects");const e=Object.keys(t[0]),n=[e.join(",")];return t.forEach(r=>{const i=e.map(a=>JSON.stringify(r[a]??""));n.push(i.join(","))}),n.join(`
|
|
28
28
|
`)}decodeString(t,e){const[n,...r]=t.trim().split(`
|
|
29
|
-
`).map(o=>o.trim());if(n.length===0)return e!=null?e.parse({}):{};const i=n.split(",").map(o=>o.trim()),a={};return i.forEach(o=>{a[o]=[]}),r.forEach(o=>{const c=o.split(",").map(u=>u.trim());i.forEach((u,h)=>{const f=this.parseValue(c[h]);f!=null&&a[u].push(f)})}),e!=null?e.parse(a):a}parseValue(t){if(t==null||t.length===0)return null;const e=Number(t);return isNaN(e)?t.startsWith('"')&&t.endsWith('"')?t.slice(1,-1):t:e}static registerCustomType(){}},Co=class{constructor(){Vt(this,"contentType","text/plain")}encode(t){return new TextEncoder().encode(t).buffer}decode(t,e){const n=new TextDecoder().decode(t);return e!=null?e.parse(n):n}};const st=new ko,Cd=new xo,$d=new Co,Rd=[st],dt=Object.freeze(Object.defineProperty({__proto__:null,CSVCodec:xo,CSV_CODEC:Cd,ENCODERS:Rd,JSONCodec:ko,JSON_CODEC:st,TEXT_CODEC:$d,TextCodec:Co},Symbol.toStringTag,{value:"Module"})),ur=s.z.tuple([s.z.number(),s.z.number()]);s.z.tuple([s.z.bigint(),s.z.bigint()]);const $o=s.z.object({width:s.z.number(),height:s.z.number()}),jd=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()}),Md=["width","height"];s.z.enum(Md);const Bd=["start","center","end"],Dd=["signedWidth","signedHeight"];s.z.enum(Dd);const tr=s.z.object({x:s.z.number(),y:s.z.number()}),Pd=s.z.object({clientX:s.z.number(),clientY:s.z.number()}),Ud=["x","y"],Ro=s.z.enum(Ud),jo=["top","right","bottom","left"];s.z.enum(jo);const Ld=["left","right"],Mo=s.z.enum(Ld),_d=["top","bottom"],Bo=s.z.enum(_d),Do=["center"],_i=s.z.enum(Do),Yd=[...jo,...Do],Po=s.z.enum(Yd);s.z.enum(Bd);const Fd=["first","last"];s.z.enum(Fd);const qd=s.z.object({lower:s.z.number(),upper:s.z.number()}),Vd=s.z.object({lower:s.z.bigint(),upper:s.z.bigint()});s.z.union([qd,ur]);s.z.union([Vd,ur]);s.z.union([Ro,Po]);s.z.union([Ro,Po,s.z.instanceof(String)]);const ft=t=>typeof t=="bigint"||t instanceof BigInt,jr=(t,e)=>ft(t)?t.valueOf()-BigInt(e.valueOf().valueOf()):t.valueOf()-Number(e.valueOf()),Wd=(t,e)=>ft(t)?t.valueOf()+BigInt(e.valueOf().valueOf()):t+Number(e.valueOf()),Yi=(t,e)=>ft(t)?t===BigInt(e.valueOf().valueOf()):t===Number(e.valueOf()),Gd=(t,e)=>ft(t)?t.valueOf()<BigInt(e.valueOf())?t:BigInt(e.valueOf()):t.valueOf()<Number(e.valueOf())?t:Number(e.valueOf()),Zd=t=>ft(t)||t instanceof BigInt?t.valueOf()<0n?-t:t:t.valueOf()<0?-t:t,nt=(t,e)=>ft(t)?t.valueOf()*BigInt(e.valueOf()):t.valueOf()*Number(e.valueOf()),de=(t,e)=>{const n={};if(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 return Fi(t);return Fi(n)},Fi=t=>t.lower>t.upper?{lower:t.upper,upper:t.lower}:t,qi=(t,e)=>{const n=de(t);return e<n.lower?n.lower:e>=n.upper?n.upper-(typeof n.upper=="number"?1:1n):e},gn=(t,e)=>{const n=de(t);if(typeof e=="number"||typeof e=="bigint")return e>=n.lower&&e<n.upper;const r=de(e);return r.lower>=n.lower&&r.upper<=n.upper},Kd=(t,e,n)=>{const r=t.map(c=>de(c)),i=n>0?1:n<0?-1:0;if(i===0)return e;let a=n,o=e;for(;Yi(a,0)===!1;){const c=r.findIndex(u=>i>0?o>=u.lower&&o<u.upper:o>u.lower&&o<=u.upper);if(c!==-1){const u=r[c];let h;if(i>0?h=jr(u.upper,o):h=jr(o,u.lower),h>0){const f=Gd(Zd(a),h);if(o=Wd(o,i>0?f:-f),a=jr(a,i>0?f:-f),Yi(a,0))return o;continue}}if(i>0){const u=r.filter(h=>h.lower>o);if(u.length>0)o=u[0].lower;else return o}else{const u=r.filter(h=>h.upper<o);if(u.length>0)o=u[u.length-1].upper;else return o}}return o},Jd=(t,e,n)=>{const r=t.map(o=>de(o));if(e===n)return typeof e=="bigint"?0n:0;const i=e<n?de([e,n]):de([n,e]);let a=typeof e=="bigint"?0n:0;for(const o of r){const c=o.lower>i.lower?o.lower:i.lower,u=o.upper<i.upper?o.upper:i.upper;if(c<u){const h=u-c;a=a+h}}return a};s.z.object({x:Mo.or(_i),y:Bo.or(_i)});const Hd=s.z.object({x:Mo,y:Bo}),Xd=Object.freeze({x:"left",y:"top"}),Qd=(t,e)=>t.x===e.x&&t.y===e.y,Vi=s.z.union([s.z.number(),tr,ur,$o,jd,Pd]),ef=(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}},Wi=Object.freeze({x:0,y:0}),pn=s.z.union([s.z.number(),s.z.string()]);s.z.object({top:pn,left:pn,width:pn,height:pn});s.z.object({left:s.z.number(),top:s.z.number(),right:s.z.number(),bottom:s.z.number()});s.z.object({one:tr,two:tr,root:Hd});const Ls=(t,e,n=0,r=0,i)=>{const a={one:{...Wi},two:{...Wi},root:i??Xd};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+n,y:a.one.y+r},a}return"one"in t&&"two"in t&&"root"in t?{...t,root:i??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+n,y:a.one.y+r}:typeof e=="number"?a.two={x:a.one.x+e,y:a.one.y+n}:"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))},Mr=t=>{const e=Ls(t);return{lower:e.one.x,upper:e.two.x}},Br=t=>{const e=Ls(t);return{lower:e.one.y,upper:e.two.y}},tf=t=>typeof t!="object"||t==null?!1:"one"in t&&"two"in t&&"root"in t;var nf=Object.defineProperty,rf=(t,e,n)=>e in t?nf(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Be=(t,e,n)=>rf(t,typeof e!="symbol"?e+"":e,n);const sf=(t,e,n)=>e!==void 0&&t<e?e:n!==void 0&&t>n?n:t;s.z.object({offset:Vi,scale:Vi});const af=t=>(e,n,r,i)=>n==="dimension"?[e,r]:[e,i?r-t:r+t],of=t=>(e,n,r,i)=>[e,i?r/t:r*t],lf=t=>(e,n,r)=>{if(e===null)return[t,r];const{lower:i,upper:a}=e,{lower:o,upper:c}=t,u=a-i,h=c-o;if(n==="dimension")return[t,r*(h/u)];const f=(r-i)*(h/u)+o;return[t,f]},cf=t=>(e,n,r)=>[t,r],uf=()=>(t,e,n)=>{if(t===null)throw new Error("cannot invert without bounds");if(e==="dimension")return[t,n];const{lower:r,upper:i}=t;return[t,i-(n-r)]},hf=t=>(e,n,r)=>{const{lower:i,upper:a}=t;return r=sf(r,i,a),[e,r]},ps=class Rt{constructor(){Be(this,"ops",[]),Be(this,"currBounds",null),Be(this,"currType",null),Be(this,"reversed",!1),this.ops=[]}static translate(e){return new Rt().translate(e)}static magnify(e){return new Rt().magnify(e)}static scale(e,n){return new Rt().scale(e,n)}translate(e){const n=this.new(),r=af(e);return r.type="translate",n.ops.push(r),n}magnify(e){const n=this.new(),r=of(e);return r.type="magnify",n.ops.push(r),n}scale(e,n){const r=de(e,n),i=this.new(),a=lf(r);return a.type="scale",i.ops.push(a),i}clamp(e,n){const r=de(e,n),i=this.new(),a=hf(r);return a.type="clamp",i.ops.push(a),i}reBound(e,n){const r=de(e,n),i=this.new(),a=cf(r);return a.type="re-bound",i.ops.push(a),i}invert(){const e=uf();e.type="invert";const n=this.new();return n.ops.push(e),n}pos(e){return this.exec("position",e)}dim(e){return this.exec("dimension",e)}new(){const e=new Rt;return e.ops=this.ops.slice(),e.reversed=this.reversed,e}exec(e,n){return this.currBounds=null,this.ops.reduce(([r,i],a)=>a(r,e,i,this.reversed),[null,n])[1]}reverse(){const e=this.new();e.ops.reverse();const n=[];return e.ops.forEach((r,i)=>{if(r.type==="scale"||n.some(([o,c])=>i>=o&&i<=c))return;const a=e.ops.findIndex((o,c)=>o.type==="scale"&&c>i);a!==-1&&n.push([i,a])}),n.forEach(([r,i])=>{const a=e.ops.slice(r,i);a.unshift(e.ops[i]),e.ops.splice(r,i-r+1,...a)}),e.reversed=!e.reversed,e}};Be(ps,"IDENTITY",new ps);let Gi=ps;const Zi=class je{constructor(e=new Gi,n=new Gi,r=null){Be(this,"x"),Be(this,"y"),Be(this,"currRoot"),this.x=e,this.y=n,this.currRoot=r}static translate(e,n){return new je().translate(e,n)}static translateX(e){return new je().translateX(e)}static translateY(e){return new je().translateY(e)}static clamp(e){return new je().clamp(e)}static magnify(e){return new je().magnify(e)}static scale(e){return new je().scale(e)}static reBound(e){return new je().reBound(e)}translate(e,n){const r=ef(e,n),i=this.copy();return i.x=this.x.translate(r.x),i.y=this.y.translate(r.y),i}translateX(e){const n=this.copy();return n.x=this.x.translate(e),n}translateY(e){const n=this.copy();return n.y=this.y.translate(e),n}magnify(e){const n=this.copy();return n.x=this.x.magnify(e.x),n.y=this.y.magnify(e.y),n}scale(e){const n=this.copy();if(tf(e)){const r=this.currRoot;return n.currRoot=e.root,r!=null&&!Qd(r,e.root)&&(r.x!==e.root.x&&(n.x=n.x.invert()),r.y!==e.root.y&&(n.y=n.y.invert())),n.x=n.x.scale(Mr(e)),n.y=n.y.scale(Br(e)),n}return n.x=n.x.scale(e.width),n.y=n.y.scale(e.height),n}reBound(e){const n=this.copy();return n.x=this.x.reBound(Mr(e)),n.y=this.y.reBound(Br(e)),n}clamp(e){const n=this.copy();return n.x=this.x.clamp(Mr(e)),n.y=this.y.clamp(Br(e)),n}copy(){const e=new je;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)}}box(e){return Ls(this.pos(e.one),this.pos(e.two),0,0,this.currRoot??e.root)}};Be(Zi,"IDENTITY",new Zi);const Ki=t=>[...new Set(t)],df=t=>t!=null&&typeof t=="object"&&"toString"in t,ff=(t,e=!1)=>{const n=df(t)?"stringer":typeof t;let r;switch(n){case"string":r=(i,a)=>i.localeCompare(a);break;case"stringer":r=(i,a)=>i.toString().localeCompare(a.toString());break;case"number":r=(i,a)=>Number(i)-Number(a);break;case"bigint":r=(i,a)=>BigInt(i)-BigInt(a)>0n?1:-1;break;case"boolean":r=(i,a)=>Number(i)-Number(a);break;case"undefined":r=()=>0;break;default:return console.warn(`sortFunc: unknown type ${n}`),()=>-1}return e?yf(r):r},yf=t=>(e,n)=>t(n,e),hr=0,Dr=-1,Pr=1,gf=t=>t<hr,pf=t=>t>hr,mf=t=>t===hr,wf=(t,e)=>{let n=null;return e===0?t:(...r)=>{n!==null&&(clearTimeout(n),n=null),n=setTimeout(()=>t(...r),e)}},bf=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()});s.z.union([$o,bf,tr,ur]);const vf=s.z.bigint().or(s.z.string().transform(BigInt));var Of=Object.defineProperty,Tf=(t,e,n)=>e in t?Of(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,g=(t,e,n)=>Tf(t,typeof e!="symbol"?e+"":e,n);let Sf=(t,e=21)=>(n=e)=>{let r="",i=n;for(;i--;)r+=t[Math.random()*t.length|0];return r};const zf="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",Uo=Sf(zf,11),Nf=Object.freeze(Object.defineProperty({__proto__:null,id:Uo},Symbol.toStringTag,{value:"Module"})),If=s.z.enum(["static","dynamic"]),Lo=(t,e)=>{const n=new x(e);if(![$.DAY,$.HOUR,$.MINUTE,$.SECOND,$.MILLISECOND,$.MICROSECOND,$.NANOSECOND].some(i=>i.equals(n)))throw new Error("Invalid argument for remainder. Must be an even TimeSpan or Timestamp");const r=t.valueOf()%n.valueOf();return t instanceof x?new x(r):new $(r)},q=class N{constructor(e,n="UTC"){if(g(this,"value"),g(this,"encodeValue",!0),e==null)this.value=N.now().valueOf();else if(e instanceof Date)this.value=BigInt(e.getTime())*N.MILLISECOND.valueOf();else if(typeof e=="string")this.value=N.parseDateTimeString(e,n).valueOf();else if(Array.isArray(e))this.value=N.parseDate(e);else{let r=BigInt(0);e instanceof Number&&(e=e.valueOf()),n==="local"&&(r=N.utcOffset.valueOf()),typeof e=="number"&&(isFinite(e)?e=Math.trunc(e):(isNaN(e)&&(e=0),e===1/0?e=N.MAX:e=N.MIN)),this.value=BigInt(e.valueOf())+r}}static parseDate([e=1970,n=1,r=1]){const i=new Date(e,n-1,r,0,0,0,0);return new N(BigInt(i.getTime())*N.MILLISECOND.valueOf()).truncate(N.DAY).valueOf()}encode(){return this.value.toString()}valueOf(){return this.value}static parseTimeString(e,n="UTC"){const[r,i,a]=e.split(":");let o="00",c="00";a!=null&&([o,c]=a.split("."));let u=N.hours(parseInt(r??"00",10)).add(N.minutes(parseInt(i??"00",10))).add(N.seconds(parseInt(o??"00",10))).add(N.milliseconds(parseInt(c??"00",10)));return n==="local"&&(u=u.add(N.utcOffset)),u.valueOf()}static parseDateTimeString(e,n="UTC"){if(!e.includes("/")&&!e.includes("-"))return N.parseTimeString(e,n);const r=new Date(e);return e.includes(":")||r.setUTCHours(0,0,0,0),new N(BigInt(r.getTime())*N.MILLISECOND.valueOf(),n).valueOf()}fString(e="ISO",n="UTC"){switch(e){case"ISODate":return this.toISOString(n).slice(0,10);case"ISOTime":return this.toISOString(n).slice(11,23);case"time":return this.timeString(!1,n);case"preciseTime":return this.timeString(!0,n);case"date":return this.dateString();case"preciseDate":return`${this.dateString()} ${this.timeString(!0,n)}`;case"dateTime":return`${this.dateString()} ${this.timeString(!1,n)}`;default:return this.toISOString(n)}}toISOString(e="UTC"){return e==="UTC"?this.date().toISOString():this.sub(N.utcOffset).date().toISOString()}timeString(e=!1,n="UTC"){const r=this.toISOString(n);return e?r.slice(11,23):r.slice(11,19)}dateString(){const e=this.date(),n=e.toLocaleString("default",{month:"short"}),r=e.toLocaleString("default",{day:"numeric"});return`${n} ${r}`}static get utcOffset(){return new $(BigInt(new Date().getTimezoneOffset())*N.MINUTE.valueOf())}static since(e){return new N().span(e)}date(){return new Date(this.milliseconds())}equals(e){return this.valueOf()===new N(e).valueOf()}span(e){return this.range(e).span}range(e){return new se(this,e).makeValid()}spanRange(e){return this.range(this.add(e)).makeValid()}get isZero(){return this.valueOf()===BigInt(0)}after(e){return this.valueOf()>new N(e).valueOf()}afterEq(e){return this.valueOf()>=new N(e).valueOf()}before(e){return this.valueOf()<new N(e).valueOf()}beforeEq(e){return this.valueOf()<=new N(e).valueOf()}add(e){return new N(this.valueOf()+BigInt(e.valueOf()))}sub(e){return new N(this.valueOf()-BigInt(e.valueOf()))}milliseconds(){return Number(this.valueOf())/Number(N.MILLISECOND.valueOf())}toString(){return this.date().toISOString()}remainder(e){return Lo(this,e)}get isToday(){return this.truncate($.DAY).equals(N.now().truncate($.DAY))}truncate(e){return this.sub(this.remainder(e))}static now(){return new N(new Date)}static max(...e){let n=N.MIN;for(const r of e){const i=new N(r);i.after(n)&&(n=i)}return n}static min(...e){let n=N.MAX;for(const r of e){const i=new N(r);i.before(n)&&(n=i)}return n}static nanoseconds(e){return new N(e)}static microseconds(e){return N.nanoseconds(e*1e3)}static milliseconds(e){return N.microseconds(e*1e3)}static seconds(e){return N.milliseconds(e*1e3)}static minutes(e){return N.seconds(e*60)}static hours(e){return N.minutes(e*60)}static days(e){return N.hours(e*24)}};g(q,"NANOSECOND",q.nanoseconds(1)),g(q,"MICROSECOND",q.microseconds(1)),g(q,"MILLISECOND",q.milliseconds(1)),g(q,"SECOND",q.seconds(1)),g(q,"MINUTE",q.minutes(1)),g(q,"HOUR",q.hours(1)),g(q,"DAY",q.days(1)),g(q,"MAX",new q((1n<<63n)-1n)),g(q,"MIN",new q(0)),g(q,"ZERO",new q(0)),g(q,"z",s.z.union([s.z.object({value:s.z.bigint()}).transform(t=>new q(t.value)),s.z.string().transform(t=>new q(BigInt(t))),s.z.instanceof(Number).transform(t=>new q(t)),s.z.number().transform(t=>new q(t)),s.z.instanceof(q)]));let x=q;const V=class A{constructor(e){g(this,"value"),g(this,"encodeValue",!0),typeof e=="number"&&(e=Math.trunc(e.valueOf())),this.value=BigInt(e.valueOf())}static fromSeconds(e){return e instanceof A?e:e instanceof Kt?e.period:e instanceof x?new A(e):["number","bigint"].includes(typeof e)?A.seconds(e):new A(e)}static fromMilliseconds(e){return e instanceof A?e:e instanceof Kt?e.period:e instanceof x?new A(e):["number","bigint"].includes(typeof e)?A.milliseconds(e):new A(e)}encode(){return this.value.toString()}valueOf(){return this.value}lessThan(e){return this.valueOf()<new A(e).valueOf()}greaterThan(e){return this.valueOf()>new A(e).valueOf()}lessThanOrEqual(e){return this.valueOf()<=new A(e).valueOf()}greaterThanOrEqual(e){return this.valueOf()>=new A(e).valueOf()}remainder(e){return Lo(this,e)}truncate(e){return new A(BigInt(Math.trunc(Number(this.valueOf()/e.valueOf())))*e.valueOf())}toString(){const e=this.truncate(A.DAY),n=this.truncate(A.HOUR),r=this.truncate(A.MINUTE),i=this.truncate(A.SECOND),a=this.truncate(A.MILLISECOND),o=this.truncate(A.MICROSECOND),c=this.truncate(A.NANOSECOND),u=e,h=n.sub(e),f=r.sub(n),d=i.sub(r),k=a.sub(i),D=o.sub(a),ie=c.sub(o);let M="";return u.isZero||(M+=`${u.days}d `),h.isZero||(M+=`${h.hours}h `),f.isZero||(M+=`${f.minutes}m `),d.isZero||(M+=`${d.seconds}s `),k.isZero||(M+=`${k.milliseconds}ms `),D.isZero||(M+=`${D.microseconds}µs `),ie.isZero||(M+=`${ie.nanoseconds}ns`),M.trim()}get days(){return Number(this.valueOf())/Number(A.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(A.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(A.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(A.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(A.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(A.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get isZero(){return this.valueOf()===BigInt(0)}equals(e){return this.valueOf()===new A(e).valueOf()}add(e){return new A(this.valueOf()+new A(e).valueOf())}sub(e){return new A(this.valueOf()-new A(e).valueOf())}static nanoseconds(e=1){return new A(e)}static microseconds(e=1){return A.nanoseconds(nt(e,1e3))}static milliseconds(e=1){return A.microseconds(nt(e,1e3))}static seconds(e=1){return A.milliseconds(nt(e,1e3))}static minutes(e=1){return A.seconds(nt(e,60))}static hours(e){return A.minutes(nt(e,60))}static days(e){return A.hours(nt(e,24))}};g(V,"NANOSECOND",V.nanoseconds(1)),g(V,"MICROSECOND",V.microseconds(1)),g(V,"MILLISECOND",V.milliseconds(1)),g(V,"SECOND",V.seconds(1)),g(V,"MINUTE",V.minutes(1)),g(V,"HOUR",V.hours(1)),g(V,"DAY",V.days(1)),g(V,"MAX",new V((1n<<63n)-1n)),g(V,"MIN",new V(0)),g(V,"ZERO",new V(0)),g(V,"z",s.z.union([s.z.object({value:s.z.bigint()}).transform(t=>new V(t.value)),s.z.string().transform(t=>new V(BigInt(t))),s.z.instanceof(Number).transform(t=>new V(t)),s.z.number().transform(t=>new V(t)),s.z.instanceof(V)]));let $=V;const jt=class jn extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new jn(e).valueOf()}get period(){return $.seconds(1/this.valueOf())}sampleCount(e){return new $(e).seconds*this.valueOf()}byteCount(e,n){return this.sampleCount(e)*new he(n).valueOf()}span(e){return $.seconds(e/this.valueOf())}byteSpan(e,n){return this.span(e.valueOf()/n.valueOf())}static hz(e){return new jn(e)}static khz(e){return jn.hz(e*1e3)}};g(jt,"z",s.z.union([s.z.number().transform(t=>new jt(t)),s.z.instanceof(Number).transform(t=>new jt(t)),s.z.instanceof(jt)]));let Kt=jt;const re=class extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}length(e){return e.valueOf()/this.valueOf()}size(e){return new ot(e*this.valueOf())}};g(re,"UNKNOWN",new re(0)),g(re,"BIT128",new re(16)),g(re,"BIT64",new re(8)),g(re,"BIT32",new re(4)),g(re,"BIT16",new re(2)),g(re,"BIT8",new re(1)),g(re,"z",s.z.union([s.z.number().transform(t=>new re(t)),s.z.instanceof(Number).transform(t=>new re(t)),s.z.instanceof(re)]));let he=re;const ke=class Mn{constructor(e,n){g(this,"start"),g(this,"end"),typeof e=="object"&&"start"in e?(this.start=new x(e.start),this.end=new x(e.end)):(this.start=new x(e),this.end=new x(n))}get span(){return new $(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 Mn(this.end,this.start)}equals(e){return this.start.equals(e.start)&&this.end.equals(e.end)}toString(){return`${this.start.toString()} - ${this.end.toString()}`}toPrettyString(){return`${this.start.fString("preciseDate")} - ${this.span.toString()}`}overlapsWith(e,n=$.ZERO){e=e.makeValid();const r=this.makeValid();if(this.equals(e))return!0;if(e.end.equals(r.start)||r.end.equals(e.start))return!1;const i=x.max(r.start,e.start),a=x.min(r.end,e.end);return a.before(i)?!1:new $(a.sub(i)).greaterThanOrEqual(n)}roughlyEquals(e,n){let r=this.start.sub(e.start).valueOf(),i=this.end.sub(e.end).valueOf();return r<0&&(r=-r),i<0&&(i=-i),r<=n.valueOf()&&i<=n.valueOf()}contains(e){return e instanceof Mn?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const n=new Mn(this.start,this.end);return e.start.after(this.start)&&(n.start=e.start),e.start.after(this.end)&&(n.end=e.start),e.end.before(this.end)&&(n.end=e.end),e.end.before(this.start)&&(n.start=e.end),n}};g(ke,"MAX",new ke(x.MIN,x.MAX)),g(ke,"MIN",new ke(x.MAX,x.MIN)),g(ke,"ZERO",new ke(x.ZERO,x.ZERO)),g(ke,"z",s.z.union([s.z.object({start:x.z,end:x.z}).transform(t=>new ke(t.start,t.end)),s.z.instanceof(ke)]));let se=ke;const w=class xe extends String{constructor(e){if(e instanceof xe||typeof e=="string"||typeof e.valueOf()=="string"){super(e.valueOf());return}else{const n=xe.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);if(n!=null){super(n.valueOf());return}}throw super(xe.UNKNOWN.valueOf()),new Error(`unable to find data type for ${e.toString()}`)}get Array(){const e=xe.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(n=>this.equals(n))}toString(){return this.valueOf()}get isVariable(){return this.equals(xe.JSON)||this.equals(xe.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(xe.UUID)}get isInteger(){return this.toString().startsWith("int")}get isFloat(){return this.toString().startsWith("float")}get density(){const e=xe.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}canSafelyCastTo(e){return this.equals(e)?!0:this.isVariable&&!e.isVariable||!this.isVariable&&e.isVariable?!1:this.isFloat&&e.isInteger||this.isInteger&&e.isFloat?this.density.valueOf()<e.density.valueOf():this.isFloat&&e.isFloat||this.isInteger&&e.isInteger?this.density.valueOf()<=e.density.valueOf():!1}canCastTo(e){return this.isNumeric&&e.isNumeric?!0:this.equals(e)}checkArray(e){return e.constructor===this.Array}toJSON(){return this.toString()}get usesBigInt(){return xe.BIG_INT_TYPES.some(e=>e.equals(this))}};g(w,"UNKNOWN",new w("unknown")),g(w,"FLOAT64",new w("float64")),g(w,"FLOAT32",new w("float32")),g(w,"INT64",new w("int64")),g(w,"INT32",new w("int32")),g(w,"INT16",new w("int16")),g(w,"INT8",new w("int8")),g(w,"UINT64",new w("uint64")),g(w,"UINT32",new w("uint32")),g(w,"UINT16",new w("uint16")),g(w,"UINT8",new w("uint8")),g(w,"BOOLEAN",w.UINT8),g(w,"TIMESTAMP",new w("timestamp")),g(w,"UUID",new w("uuid")),g(w,"STRING",new w("string")),g(w,"JSON",new w("json")),g(w,"ARRAY_CONSTRUCTORS",new Map([[w.UINT8.toString(),Uint8Array],[w.UINT16.toString(),Uint16Array],[w.UINT32.toString(),Uint32Array],[w.UINT64.toString(),BigUint64Array],[w.FLOAT32.toString(),Float32Array],[w.FLOAT64.toString(),Float64Array],[w.INT8.toString(),Int8Array],[w.INT16.toString(),Int16Array],[w.INT32.toString(),Int32Array],[w.INT64.toString(),BigInt64Array],[w.TIMESTAMP.toString(),BigInt64Array],[w.STRING.toString(),Uint8Array],[w.JSON.toString(),Uint8Array],[w.UUID.toString(),Uint8Array]])),g(w,"ARRAY_CONSTRUCTOR_DATA_TYPES",new Map([[Uint8Array.name,w.UINT8],[Uint16Array.name,w.UINT16],[Uint32Array.name,w.UINT32],[BigUint64Array.name,w.UINT64],[Float32Array.name,w.FLOAT32],[Float64Array.name,w.FLOAT64],[Int8Array.name,w.INT8],[Int16Array.name,w.INT16],[Int32Array.name,w.INT32],[BigInt64Array.name,w.INT64]])),g(w,"DENSITIES",new Map([[w.UINT8.toString(),he.BIT8],[w.UINT16.toString(),he.BIT16],[w.UINT32.toString(),he.BIT32],[w.UINT64.toString(),he.BIT64],[w.FLOAT32.toString(),he.BIT32],[w.FLOAT64.toString(),he.BIT64],[w.INT8.toString(),he.BIT8],[w.INT16.toString(),he.BIT16],[w.INT32.toString(),he.BIT32],[w.INT64.toString(),he.BIT64],[w.TIMESTAMP.toString(),he.BIT64],[w.STRING.toString(),he.UNKNOWN],[w.JSON.toString(),he.UNKNOWN],[w.UUID.toString(),he.BIT128]])),g(w,"ALL",[w.UNKNOWN,w.FLOAT64,w.FLOAT32,w.INT64,w.INT32,w.INT16,w.INT8,w.UINT64,w.UINT32,w.UINT16,w.UINT8,w.TIMESTAMP,w.UUID,w.STRING,w.JSON]),g(w,"BIG_INT_TYPES",[w.INT64,w.UINT64,w.TIMESTAMP]),g(w,"z",s.z.union([s.z.string().transform(t=>new w(t)),s.z.instanceof(w)]));let C=w;const le=class X extends Number{constructor(e){super(e.valueOf())}largerThan(e){return this.valueOf()>e.valueOf()}smallerThan(e){return this.valueOf()<e.valueOf()}add(e){return X.bytes(this.valueOf()+e.valueOf())}sub(e){return X.bytes(this.valueOf()-e.valueOf())}truncate(e){return new X(Math.trunc(this.valueOf()/e.valueOf())*e.valueOf())}remainder(e){return X.bytes(this.valueOf()%e.valueOf())}get gigabytes(){return this.valueOf()/X.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/X.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/X.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/X.TERABYTE.valueOf()}toString(){const e=this.truncate(X.TERABYTE),n=this.truncate(X.GIGABYTE),r=this.truncate(X.MEGABYTE),i=this.truncate(X.KILOBYTE),a=this.truncate(X.BYTE),o=e,c=n.sub(e),u=r.sub(n),h=i.sub(r),f=a.sub(i);let d="";return o.isZero||(d+=`${o.terabytes}TB `),c.isZero||(d+=`${c.gigabytes}GB `),u.isZero||(d+=`${u.megabytes}MB `),h.isZero||(d+=`${h.kilobytes}KB `),(!f.isZero||d==="")&&(d+=`${f.valueOf()}B`),d.trim()}static bytes(e=1){return new X(e)}static kilobytes(e=1){return X.bytes(e.valueOf()*1e3)}static megabytes(e=1){return X.kilobytes(e.valueOf()*1e3)}static gigabytes(e=1){return X.megabytes(e.valueOf()*1e3)}static terabytes(e){return X.gigabytes(e.valueOf()*1e3)}get isZero(){return this.valueOf()===0}};g(le,"BYTE",new le(1)),g(le,"KILOBYTE",le.kilobytes(1)),g(le,"MEGABYTE",le.megabytes(1)),g(le,"GIGABYTE",le.gigabytes(1)),g(le,"TERABYTE",le.terabytes(1)),g(le,"ZERO",new le(0)),g(le,"z",s.z.union([s.z.number().transform(t=>new le(t)),s.z.instanceof(le)]));let ot=le;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 _o=t=>{const e=typeof t;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||t instanceof x||t instanceof $||t instanceof Date},Ef=(t,e,n,r=0)=>t.usesBigInt&&!e.usesBigInt?Number(n)-Number(r):!t.usesBigInt&&e.usesBigInt?BigInt(n.valueOf())-BigInt(r.valueOf()):Bt(n,-r).valueOf(),Af=t=>t==null?!1:Array.isArray(t)||t instanceof ArrayBuffer||ArrayBuffer.isView(t)&&!(t instanceof DataView)||t instanceof Ke?!0:_o(t),Le=-1,ms={[Symbol.iterator]:()=>ms,next:()=>({done:!0,value:void 0})},kf=s.z.string().transform(t=>new Uint8Array(atob(t).split("").map(e=>e.charCodeAt(0))).buffer),xf=s.z.union([s.z.null(),s.z.undefined()]).transform(()=>new Uint8Array().buffer),ws=10,Mt=class Ce{constructor(e){g(this,"key",""),g(this,"isSynnaxSeries",!0),g(this,"dataType"),g(this,"sampleOffset"),g(this,"gl"),g(this,"_data"),g(this,"_timeRange"),g(this,"alignment",0n),g(this,"_cachedMin"),g(this,"_cachedMax"),g(this,"writePos",Le),g(this,"_refCount",0),g(this,"_cachedLength"),g(this,"_cachedIndexes"),Af(e)&&(e={data:e});const{dataType:n,timeRange:r,sampleOffset:i=0,glBufferUsage:a="static",alignment:o=0n,key:c=Uo()}=e,u=e.data??[];if(u instanceof Ce||typeof u=="object"&&"isSynnaxSeries"in u&&u.isSynnaxSeries===!0){const d=u;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._cachedMin=d._cachedMin,this._cachedMax=d._cachedMax,this.writePos=d.writePos,this._refCount=d._refCount,this._cachedLength=d._cachedLength;return}const h=_o(u),f=Array.isArray(u);if(n!=null)this.dataType=new C(n);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(f||h){let d=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.");d=u[0]}if(typeof d=="string")this.dataType=C.STRING;else if(typeof d=="number")this.dataType=C.FLOAT64;else if(typeof d=="bigint")this.dataType=C.INT64;else if(typeof d=="boolean")this.dataType=C.BOOLEAN;else if(d instanceof x||d instanceof Date||d instanceof x)this.dataType=C.TIMESTAMP;else if(typeof d=="object")this.dataType=C.JSON;else throw new Error(`cannot infer data type of ${typeof d} when constructing a Series from a JS array`)}else this.dataType=new C(u)}if(!f&&!h)this._data=u;else{let d=h?[u]:u;const k=d[0];(k instanceof x||k instanceof Date||k instanceof $)&&(d=d.map(D=>new x(D).valueOf())),this.dataType.equals(C.STRING)?(this._cachedLength=d.length,this._data=new TextEncoder().encode(d.join(`
|
|
29
|
+
`).map(o=>o.trim());if(n.length===0)return e!=null?e.parse({}):{};const i=n.split(",").map(o=>o.trim()),a={};return i.forEach(o=>{a[o]=[]}),r.forEach(o=>{const c=o.split(",").map(u=>u.trim());i.forEach((u,h)=>{const f=this.parseValue(c[h]);f!=null&&a[u].push(f)})}),e!=null?e.parse(a):a}parseValue(t){if(t==null||t.length===0)return null;const e=Number(t);return isNaN(e)?t.startsWith('"')&&t.endsWith('"')?t.slice(1,-1):t:e}static registerCustomType(){}},Co=class{constructor(){Vt(this,"contentType","text/plain")}encode(t){return new TextEncoder().encode(t).buffer}decode(t,e){const n=new TextDecoder().decode(t);return e!=null?e.parse(n):n}};const st=new ko,$d=new xo,Rd=new Co,jd=[st],dt=Object.freeze(Object.defineProperty({__proto__:null,CSVCodec:xo,CSV_CODEC:$d,ENCODERS:jd,JSONCodec:ko,JSON_CODEC:st,TEXT_CODEC:Rd,TextCodec:Co},Symbol.toStringTag,{value:"Module"})),ur=s.z.tuple([s.z.number(),s.z.number()]);s.z.tuple([s.z.bigint(),s.z.bigint()]);const $o=s.z.object({width:s.z.number(),height:s.z.number()}),Bd=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()}),Md=["width","height"];s.z.enum(Md);const Dd=["start","center","end"],Pd=["signedWidth","signedHeight"];s.z.enum(Pd);const tr=s.z.object({x:s.z.number(),y:s.z.number()}),Ud=s.z.object({clientX:s.z.number(),clientY:s.z.number()}),Ld=["x","y"],Ro=s.z.enum(Ld),jo=["top","right","bottom","left"];s.z.enum(jo);const _d=["left","right"],Bo=s.z.enum(_d),Yd=["top","bottom"],Mo=s.z.enum(Yd),Do=["center"],_i=s.z.enum(Do),qd=[...jo,...Do],Po=s.z.enum(qd);s.z.enum(Dd);const Fd=["first","last"];s.z.enum(Fd);const Vd=s.z.object({lower:s.z.number(),upper:s.z.number()}),Wd=s.z.object({lower:s.z.bigint(),upper:s.z.bigint()});s.z.union([Vd,ur]);s.z.union([Wd,ur]);s.z.union([Ro,Po]);s.z.union([Ro,Po,s.z.instanceof(String)]);const ft=t=>typeof t=="bigint"||t instanceof BigInt,jr=(t,e)=>ft(t)?t.valueOf()-BigInt(e.valueOf().valueOf()):t.valueOf()-Number(e.valueOf()),Gd=(t,e)=>ft(t)?t.valueOf()+BigInt(e.valueOf().valueOf()):t+Number(e.valueOf()),Yi=(t,e)=>ft(t)?t===BigInt(e.valueOf().valueOf()):t===Number(e.valueOf()),Zd=(t,e)=>ft(t)?t.valueOf()<BigInt(e.valueOf())?t:BigInt(e.valueOf()):t.valueOf()<Number(e.valueOf())?t:Number(e.valueOf()),Kd=t=>ft(t)||t instanceof BigInt?t.valueOf()<0n?-t:t:t.valueOf()<0?-t:t,nt=(t,e)=>ft(t)?t.valueOf()*BigInt(e.valueOf()):t.valueOf()*Number(e.valueOf()),de=(t,e)=>{const n={};if(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 return qi(t);return qi(n)},qi=t=>t.lower>t.upper?{lower:t.upper,upper:t.lower}:t,Fi=(t,e)=>{const n=de(t);return e<n.lower?n.lower:e>=n.upper?n.upper-(typeof n.upper=="number"?1:1n):e},gn=(t,e)=>{const n=de(t);if(typeof e=="number"||typeof e=="bigint")return e>=n.lower&&e<n.upper;const r=de(e);return r.lower>=n.lower&&r.upper<=n.upper},Jd=(t,e,n)=>{const r=t.map(c=>de(c)),i=n>0?1:n<0?-1:0;if(i===0)return e;let a=n,o=e;for(;Yi(a,0)===!1;){const c=r.findIndex(u=>i>0?o>=u.lower&&o<u.upper:o>u.lower&&o<=u.upper);if(c!==-1){const u=r[c];let h;if(i>0?h=jr(u.upper,o):h=jr(o,u.lower),h>0){const f=Zd(Kd(a),h);if(o=Gd(o,i>0?f:-f),a=jr(a,i>0?f:-f),Yi(a,0))return o;continue}}if(i>0){const u=r.filter(h=>h.lower>o);if(u.length>0)o=u[0].lower;else return o}else{const u=r.filter(h=>h.upper<o);if(u.length>0)o=u[u.length-1].upper;else return o}}return o},Hd=(t,e,n)=>{const r=t.map(o=>de(o));if(e===n)return typeof e=="bigint"?0n:0;const i=e<n?de([e,n]):de([n,e]);let a=typeof e=="bigint"?0n:0;for(const o of r){const c=o.lower>i.lower?o.lower:i.lower,u=o.upper<i.upper?o.upper:i.upper;if(c<u){const h=u-c;a=a+h}}return a};s.z.object({x:Bo.or(_i),y:Mo.or(_i)});const Xd=s.z.object({x:Bo,y:Mo}),Qd=Object.freeze({x:"left",y:"top"}),ef=(t,e)=>t.x===e.x&&t.y===e.y,Vi=s.z.union([s.z.number(),tr,ur,$o,Bd,Ud]),tf=(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}},Wi=Object.freeze({x:0,y:0}),pn=s.z.union([s.z.number(),s.z.string()]);s.z.object({top:pn,left:pn,width:pn,height:pn});s.z.object({left:s.z.number(),top:s.z.number(),right:s.z.number(),bottom:s.z.number()});s.z.object({one:tr,two:tr,root:Xd});const Ls=(t,e,n=0,r=0,i)=>{const a={one:{...Wi},two:{...Wi},root:i??Qd};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+n,y:a.one.y+r},a}return"one"in t&&"two"in t&&"root"in t?{...t,root:i??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+n,y:a.one.y+r}:typeof e=="number"?a.two={x:a.one.x+e,y:a.one.y+n}:"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))},Br=t=>{const e=Ls(t);return{lower:e.one.x,upper:e.two.x}},Mr=t=>{const e=Ls(t);return{lower:e.one.y,upper:e.two.y}},nf=t=>typeof t!="object"||t==null?!1:"one"in t&&"two"in t&&"root"in t;var rf=Object.defineProperty,sf=(t,e,n)=>e in t?rf(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Me=(t,e,n)=>sf(t,typeof e!="symbol"?e+"":e,n);const af=(t,e,n)=>e!==void 0&&t<e?e:n!==void 0&&t>n?n:t;s.z.object({offset:Vi,scale:Vi});const of=t=>(e,n,r,i)=>n==="dimension"?[e,r]:[e,i?r-t:r+t],lf=t=>(e,n,r,i)=>[e,i?r/t:r*t],cf=t=>(e,n,r)=>{if(e===null)return[t,r];const{lower:i,upper:a}=e,{lower:o,upper:c}=t,u=a-i,h=c-o;if(n==="dimension")return[t,r*(h/u)];const f=(r-i)*(h/u)+o;return[t,f]},uf=t=>(e,n,r)=>[t,r],hf=()=>(t,e,n)=>{if(t===null)throw new Error("cannot invert without bounds");if(e==="dimension")return[t,n];const{lower:r,upper:i}=t;return[t,i-(n-r)]},df=t=>(e,n,r)=>{const{lower:i,upper:a}=t;return r=af(r,i,a),[e,r]},ps=class Rt{constructor(){Me(this,"ops",[]),Me(this,"currBounds",null),Me(this,"currType",null),Me(this,"reversed",!1),this.ops=[]}static translate(e){return new Rt().translate(e)}static magnify(e){return new Rt().magnify(e)}static scale(e,n){return new Rt().scale(e,n)}translate(e){const n=this.new(),r=of(e);return r.type="translate",n.ops.push(r),n}magnify(e){const n=this.new(),r=lf(e);return r.type="magnify",n.ops.push(r),n}scale(e,n){const r=de(e,n),i=this.new(),a=cf(r);return a.type="scale",i.ops.push(a),i}clamp(e,n){const r=de(e,n),i=this.new(),a=df(r);return a.type="clamp",i.ops.push(a),i}reBound(e,n){const r=de(e,n),i=this.new(),a=uf(r);return a.type="re-bound",i.ops.push(a),i}invert(){const e=hf();e.type="invert";const n=this.new();return n.ops.push(e),n}pos(e){return this.exec("position",e)}dim(e){return this.exec("dimension",e)}new(){const e=new Rt;return e.ops=this.ops.slice(),e.reversed=this.reversed,e}exec(e,n){return this.currBounds=null,this.ops.reduce(([r,i],a)=>a(r,e,i,this.reversed),[null,n])[1]}reverse(){const e=this.new();e.ops.reverse();const n=[];return e.ops.forEach((r,i)=>{if(r.type==="scale"||n.some(([o,c])=>i>=o&&i<=c))return;const a=e.ops.findIndex((o,c)=>o.type==="scale"&&c>i);a!==-1&&n.push([i,a])}),n.forEach(([r,i])=>{const a=e.ops.slice(r,i);a.unshift(e.ops[i]),e.ops.splice(r,i-r+1,...a)}),e.reversed=!e.reversed,e}};Me(ps,"IDENTITY",new ps);let Gi=ps;const Zi=class je{constructor(e=new Gi,n=new Gi,r=null){Me(this,"x"),Me(this,"y"),Me(this,"currRoot"),this.x=e,this.y=n,this.currRoot=r}static translate(e,n){return new je().translate(e,n)}static translateX(e){return new je().translateX(e)}static translateY(e){return new je().translateY(e)}static clamp(e){return new je().clamp(e)}static magnify(e){return new je().magnify(e)}static scale(e){return new je().scale(e)}static reBound(e){return new je().reBound(e)}translate(e,n){const r=tf(e,n),i=this.copy();return i.x=this.x.translate(r.x),i.y=this.y.translate(r.y),i}translateX(e){const n=this.copy();return n.x=this.x.translate(e),n}translateY(e){const n=this.copy();return n.y=this.y.translate(e),n}magnify(e){const n=this.copy();return n.x=this.x.magnify(e.x),n.y=this.y.magnify(e.y),n}scale(e){const n=this.copy();if(nf(e)){const r=this.currRoot;return n.currRoot=e.root,r!=null&&!ef(r,e.root)&&(r.x!==e.root.x&&(n.x=n.x.invert()),r.y!==e.root.y&&(n.y=n.y.invert())),n.x=n.x.scale(Br(e)),n.y=n.y.scale(Mr(e)),n}return n.x=n.x.scale(e.width),n.y=n.y.scale(e.height),n}reBound(e){const n=this.copy();return n.x=this.x.reBound(Br(e)),n.y=this.y.reBound(Mr(e)),n}clamp(e){const n=this.copy();return n.x=this.x.clamp(Br(e)),n.y=this.y.clamp(Mr(e)),n}copy(){const e=new je;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)}}box(e){return Ls(this.pos(e.one),this.pos(e.two),0,0,this.currRoot??e.root)}};Me(Zi,"IDENTITY",new Zi);const Ki=t=>[...new Set(t)],ff=t=>t!=null&&typeof t=="object"&&"toString"in t,yf=(t,e=!1)=>{const n=ff(t)?"stringer":typeof t;let r;switch(n){case"string":r=(i,a)=>i.localeCompare(a);break;case"stringer":r=(i,a)=>i.toString().localeCompare(a.toString());break;case"number":r=(i,a)=>Number(i)-Number(a);break;case"bigint":r=(i,a)=>BigInt(i)-BigInt(a)>0n?1:-1;break;case"boolean":r=(i,a)=>Number(i)-Number(a);break;case"undefined":r=()=>0;break;default:return console.warn(`sortFunc: unknown type ${n}`),()=>-1}return e?gf(r):r},gf=t=>(e,n)=>t(n,e),hr=0,Dr=-1,Pr=1,pf=t=>t<hr,mf=t=>t>hr,wf=t=>t===hr,bf=(t,e)=>{let n=null;return e===0?t:(...r)=>{n!==null&&(clearTimeout(n),n=null),n=setTimeout(()=>t(...r),e)}},vf=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()});s.z.union([$o,vf,tr,ur]);const Of=s.z.bigint().or(s.z.string().transform(BigInt));var Tf=Object.defineProperty,Sf=(t,e,n)=>e in t?Tf(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,g=(t,e,n)=>Sf(t,typeof e!="symbol"?e+"":e,n);let zf=(t,e=21)=>(n=e)=>{let r="",i=n;for(;i--;)r+=t[Math.random()*t.length|0];return r};const Nf="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",Uo=zf(Nf,11),If=Object.freeze(Object.defineProperty({__proto__:null,id:Uo},Symbol.toStringTag,{value:"Module"})),Ef=s.z.enum(["static","dynamic"]),Lo=(t,e)=>{const n=new x(e);if(![$.DAY,$.HOUR,$.MINUTE,$.SECOND,$.MILLISECOND,$.MICROSECOND,$.NANOSECOND].some(i=>i.equals(n)))throw new Error("Invalid argument for remainder. Must be an even TimeSpan or Timestamp");const r=t.valueOf()%n.valueOf();return t instanceof x?new x(r):new $(r)},F=class N{constructor(e,n="UTC"){if(g(this,"value"),g(this,"encodeValue",!0),e==null)this.value=N.now().valueOf();else if(e instanceof Date)this.value=BigInt(e.getTime())*N.MILLISECOND.valueOf();else if(typeof e=="string")this.value=N.parseDateTimeString(e,n).valueOf();else if(Array.isArray(e))this.value=N.parseDate(e);else{let r=BigInt(0);e instanceof Number&&(e=e.valueOf()),n==="local"&&(r=N.utcOffset.valueOf()),typeof e=="number"&&(isFinite(e)?e=Math.trunc(e):(isNaN(e)&&(e=0),e===1/0?e=N.MAX:e=N.MIN)),this.value=BigInt(e.valueOf())+r}}static parseDate([e=1970,n=1,r=1]){const i=new Date(e,n-1,r,0,0,0,0);return new N(BigInt(i.getTime())*N.MILLISECOND.valueOf()).truncate(N.DAY).valueOf()}encode(){return this.value.toString()}valueOf(){return this.value}static parseTimeString(e,n="UTC"){const[r,i,a]=e.split(":");let o="00",c="00";a!=null&&([o,c]=a.split("."));let u=N.hours(parseInt(r??"00",10)).add(N.minutes(parseInt(i??"00",10))).add(N.seconds(parseInt(o??"00",10))).add(N.milliseconds(parseInt(c??"00",10)));return n==="local"&&(u=u.add(N.utcOffset)),u.valueOf()}static parseDateTimeString(e,n="UTC"){if(!e.includes("/")&&!e.includes("-"))return N.parseTimeString(e,n);const r=new Date(e);return e.includes(":")||r.setUTCHours(0,0,0,0),new N(BigInt(r.getTime())*N.MILLISECOND.valueOf(),n).valueOf()}fString(e="ISO",n="UTC"){switch(e){case"ISODate":return this.toISOString(n).slice(0,10);case"ISOTime":return this.toISOString(n).slice(11,23);case"time":return this.timeString(!1,n);case"preciseTime":return this.timeString(!0,n);case"date":return this.dateString();case"preciseDate":return`${this.dateString()} ${this.timeString(!0,n)}`;case"dateTime":return`${this.dateString()} ${this.timeString(!1,n)}`;default:return this.toISOString(n)}}toISOString(e="UTC"){return e==="UTC"?this.date().toISOString():this.sub(N.utcOffset).date().toISOString()}timeString(e=!1,n="UTC"){const r=this.toISOString(n);return e?r.slice(11,23):r.slice(11,19)}dateString(){const e=this.date(),n=e.toLocaleString("default",{month:"short"}),r=e.toLocaleString("default",{day:"numeric"});return`${n} ${r}`}static get utcOffset(){return new $(BigInt(new Date().getTimezoneOffset())*N.MINUTE.valueOf())}static since(e){return new N().span(e)}date(){return new Date(this.milliseconds())}equals(e){return this.valueOf()===new N(e).valueOf()}span(e){return this.range(e).span}range(e){return new se(this,e).makeValid()}spanRange(e){return this.range(this.add(e)).makeValid()}get isZero(){return this.valueOf()===BigInt(0)}after(e){return this.valueOf()>new N(e).valueOf()}afterEq(e){return this.valueOf()>=new N(e).valueOf()}before(e){return this.valueOf()<new N(e).valueOf()}beforeEq(e){return this.valueOf()<=new N(e).valueOf()}add(e){return new N(this.valueOf()+BigInt(e.valueOf()))}sub(e){return new N(this.valueOf()-BigInt(e.valueOf()))}milliseconds(){return Number(this.valueOf())/Number(N.MILLISECOND.valueOf())}toString(){return this.date().toISOString()}remainder(e){return Lo(this,e)}get isToday(){return this.truncate($.DAY).equals(N.now().truncate($.DAY))}truncate(e){return this.sub(this.remainder(e))}static now(){return new N(new Date)}static max(...e){let n=N.MIN;for(const r of e){const i=new N(r);i.after(n)&&(n=i)}return n}static min(...e){let n=N.MAX;for(const r of e){const i=new N(r);i.before(n)&&(n=i)}return n}static nanoseconds(e){return new N(e)}static microseconds(e){return N.nanoseconds(e*1e3)}static milliseconds(e){return N.microseconds(e*1e3)}static seconds(e){return N.milliseconds(e*1e3)}static minutes(e){return N.seconds(e*60)}static hours(e){return N.minutes(e*60)}static days(e){return N.hours(e*24)}};g(F,"NANOSECOND",F.nanoseconds(1)),g(F,"MICROSECOND",F.microseconds(1)),g(F,"MILLISECOND",F.milliseconds(1)),g(F,"SECOND",F.seconds(1)),g(F,"MINUTE",F.minutes(1)),g(F,"HOUR",F.hours(1)),g(F,"DAY",F.days(1)),g(F,"MAX",new F((1n<<63n)-1n)),g(F,"MIN",new F(0)),g(F,"ZERO",new F(0)),g(F,"z",s.z.union([s.z.object({value:s.z.bigint()}).transform(t=>new F(t.value)),s.z.string().transform(t=>new F(BigInt(t))),s.z.instanceof(Number).transform(t=>new F(t)),s.z.number().transform(t=>new F(t)),s.z.instanceof(F)]));let x=F;const V=class A{constructor(e){g(this,"value"),g(this,"encodeValue",!0),typeof e=="number"&&(e=Math.trunc(e.valueOf())),this.value=BigInt(e.valueOf())}static fromSeconds(e){return e instanceof A?e:e instanceof Kt?e.period:e instanceof x?new A(e):["number","bigint"].includes(typeof e)?A.seconds(e):new A(e)}static fromMilliseconds(e){return e instanceof A?e:e instanceof Kt?e.period:e instanceof x?new A(e):["number","bigint"].includes(typeof e)?A.milliseconds(e):new A(e)}encode(){return this.value.toString()}valueOf(){return this.value}lessThan(e){return this.valueOf()<new A(e).valueOf()}greaterThan(e){return this.valueOf()>new A(e).valueOf()}lessThanOrEqual(e){return this.valueOf()<=new A(e).valueOf()}greaterThanOrEqual(e){return this.valueOf()>=new A(e).valueOf()}remainder(e){return Lo(this,e)}truncate(e){return new A(BigInt(Math.trunc(Number(this.valueOf()/e.valueOf())))*e.valueOf())}toString(){const e=this.truncate(A.DAY),n=this.truncate(A.HOUR),r=this.truncate(A.MINUTE),i=this.truncate(A.SECOND),a=this.truncate(A.MILLISECOND),o=this.truncate(A.MICROSECOND),c=this.truncate(A.NANOSECOND),u=e,h=n.sub(e),f=r.sub(n),d=i.sub(r),k=a.sub(i),D=o.sub(a),ie=c.sub(o);let B="";return u.isZero||(B+=`${u.days}d `),h.isZero||(B+=`${h.hours}h `),f.isZero||(B+=`${f.minutes}m `),d.isZero||(B+=`${d.seconds}s `),k.isZero||(B+=`${k.milliseconds}ms `),D.isZero||(B+=`${D.microseconds}µs `),ie.isZero||(B+=`${ie.nanoseconds}ns`),B.trim()}get days(){return Number(this.valueOf())/Number(A.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(A.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(A.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(A.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(A.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(A.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get isZero(){return this.valueOf()===BigInt(0)}equals(e){return this.valueOf()===new A(e).valueOf()}add(e){return new A(this.valueOf()+new A(e).valueOf())}sub(e){return new A(this.valueOf()-new A(e).valueOf())}static nanoseconds(e=1){return new A(e)}static microseconds(e=1){return A.nanoseconds(nt(e,1e3))}static milliseconds(e=1){return A.microseconds(nt(e,1e3))}static seconds(e=1){return A.milliseconds(nt(e,1e3))}static minutes(e=1){return A.seconds(nt(e,60))}static hours(e){return A.minutes(nt(e,60))}static days(e){return A.hours(nt(e,24))}};g(V,"NANOSECOND",V.nanoseconds(1)),g(V,"MICROSECOND",V.microseconds(1)),g(V,"MILLISECOND",V.milliseconds(1)),g(V,"SECOND",V.seconds(1)),g(V,"MINUTE",V.minutes(1)),g(V,"HOUR",V.hours(1)),g(V,"DAY",V.days(1)),g(V,"MAX",new V((1n<<63n)-1n)),g(V,"MIN",new V(0)),g(V,"ZERO",new V(0)),g(V,"z",s.z.union([s.z.object({value:s.z.bigint()}).transform(t=>new V(t.value)),s.z.string().transform(t=>new V(BigInt(t))),s.z.instanceof(Number).transform(t=>new V(t)),s.z.number().transform(t=>new V(t)),s.z.instanceof(V)]));let $=V;const jt=class jn extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new jn(e).valueOf()}get period(){return $.seconds(1/this.valueOf())}sampleCount(e){return new $(e).seconds*this.valueOf()}byteCount(e,n){return this.sampleCount(e)*new he(n).valueOf()}span(e){return $.seconds(e/this.valueOf())}byteSpan(e,n){return this.span(e.valueOf()/n.valueOf())}static hz(e){return new jn(e)}static khz(e){return jn.hz(e*1e3)}};g(jt,"z",s.z.union([s.z.number().transform(t=>new jt(t)),s.z.instanceof(Number).transform(t=>new jt(t)),s.z.instanceof(jt)]));let Kt=jt;const re=class extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}length(e){return e.valueOf()/this.valueOf()}size(e){return new ot(e*this.valueOf())}};g(re,"UNKNOWN",new re(0)),g(re,"BIT128",new re(16)),g(re,"BIT64",new re(8)),g(re,"BIT32",new re(4)),g(re,"BIT16",new re(2)),g(re,"BIT8",new re(1)),g(re,"z",s.z.union([s.z.number().transform(t=>new re(t)),s.z.instanceof(Number).transform(t=>new re(t)),s.z.instanceof(re)]));let he=re;const ke=class Bn{constructor(e,n){g(this,"start"),g(this,"end"),typeof e=="object"&&"start"in e?(this.start=new x(e.start),this.end=new x(e.end)):(this.start=new x(e),this.end=new x(n))}get span(){return new $(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 Bn(this.end,this.start)}equals(e){return this.start.equals(e.start)&&this.end.equals(e.end)}toString(){return`${this.start.toString()} - ${this.end.toString()}`}toPrettyString(){return`${this.start.fString("preciseDate")} - ${this.span.toString()}`}overlapsWith(e,n=$.ZERO){e=e.makeValid();const r=this.makeValid();if(this.equals(e))return!0;if(e.end.equals(r.start)||r.end.equals(e.start))return!1;const i=x.max(r.start,e.start),a=x.min(r.end,e.end);return a.before(i)?!1:new $(a.sub(i)).greaterThanOrEqual(n)}roughlyEquals(e,n){let r=this.start.sub(e.start).valueOf(),i=this.end.sub(e.end).valueOf();return r<0&&(r=-r),i<0&&(i=-i),r<=n.valueOf()&&i<=n.valueOf()}contains(e){return e instanceof Bn?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const n=new Bn(this.start,this.end);return e.start.after(this.start)&&(n.start=e.start),e.start.after(this.end)&&(n.end=e.start),e.end.before(this.end)&&(n.end=e.end),e.end.before(this.start)&&(n.start=e.end),n}};g(ke,"MAX",new ke(x.MIN,x.MAX)),g(ke,"MIN",new ke(x.MAX,x.MIN)),g(ke,"ZERO",new ke(x.ZERO,x.ZERO)),g(ke,"z",s.z.union([s.z.object({start:x.z,end:x.z}).transform(t=>new ke(t.start,t.end)),s.z.instanceof(ke)]));let se=ke;const w=class xe extends String{constructor(e){if(e instanceof xe||typeof e=="string"||typeof e.valueOf()=="string"){super(e.valueOf());return}else{const n=xe.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);if(n!=null){super(n.valueOf());return}}throw super(xe.UNKNOWN.valueOf()),new Error(`unable to find data type for ${e.toString()}`)}get Array(){const e=xe.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(n=>this.equals(n))}toString(){return this.valueOf()}get isVariable(){return this.equals(xe.JSON)||this.equals(xe.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(xe.UUID)}get isInteger(){return this.toString().startsWith("int")}get isFloat(){return this.toString().startsWith("float")}get density(){const e=xe.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}canSafelyCastTo(e){return this.equals(e)?!0:this.isVariable&&!e.isVariable||!this.isVariable&&e.isVariable?!1:this.isFloat&&e.isInteger||this.isInteger&&e.isFloat?this.density.valueOf()<e.density.valueOf():this.isFloat&&e.isFloat||this.isInteger&&e.isInteger?this.density.valueOf()<=e.density.valueOf():!1}canCastTo(e){return this.isNumeric&&e.isNumeric?!0:this.equals(e)}checkArray(e){return e.constructor===this.Array}toJSON(){return this.toString()}get usesBigInt(){return xe.BIG_INT_TYPES.some(e=>e.equals(this))}};g(w,"UNKNOWN",new w("unknown")),g(w,"FLOAT64",new w("float64")),g(w,"FLOAT32",new w("float32")),g(w,"INT64",new w("int64")),g(w,"INT32",new w("int32")),g(w,"INT16",new w("int16")),g(w,"INT8",new w("int8")),g(w,"UINT64",new w("uint64")),g(w,"UINT32",new w("uint32")),g(w,"UINT16",new w("uint16")),g(w,"UINT8",new w("uint8")),g(w,"BOOLEAN",w.UINT8),g(w,"TIMESTAMP",new w("timestamp")),g(w,"UUID",new w("uuid")),g(w,"STRING",new w("string")),g(w,"JSON",new w("json")),g(w,"ARRAY_CONSTRUCTORS",new Map([[w.UINT8.toString(),Uint8Array],[w.UINT16.toString(),Uint16Array],[w.UINT32.toString(),Uint32Array],[w.UINT64.toString(),BigUint64Array],[w.FLOAT32.toString(),Float32Array],[w.FLOAT64.toString(),Float64Array],[w.INT8.toString(),Int8Array],[w.INT16.toString(),Int16Array],[w.INT32.toString(),Int32Array],[w.INT64.toString(),BigInt64Array],[w.TIMESTAMP.toString(),BigInt64Array],[w.STRING.toString(),Uint8Array],[w.JSON.toString(),Uint8Array],[w.UUID.toString(),Uint8Array]])),g(w,"ARRAY_CONSTRUCTOR_DATA_TYPES",new Map([[Uint8Array.name,w.UINT8],[Uint16Array.name,w.UINT16],[Uint32Array.name,w.UINT32],[BigUint64Array.name,w.UINT64],[Float32Array.name,w.FLOAT32],[Float64Array.name,w.FLOAT64],[Int8Array.name,w.INT8],[Int16Array.name,w.INT16],[Int32Array.name,w.INT32],[BigInt64Array.name,w.INT64]])),g(w,"DENSITIES",new Map([[w.UINT8.toString(),he.BIT8],[w.UINT16.toString(),he.BIT16],[w.UINT32.toString(),he.BIT32],[w.UINT64.toString(),he.BIT64],[w.FLOAT32.toString(),he.BIT32],[w.FLOAT64.toString(),he.BIT64],[w.INT8.toString(),he.BIT8],[w.INT16.toString(),he.BIT16],[w.INT32.toString(),he.BIT32],[w.INT64.toString(),he.BIT64],[w.TIMESTAMP.toString(),he.BIT64],[w.STRING.toString(),he.UNKNOWN],[w.JSON.toString(),he.UNKNOWN],[w.UUID.toString(),he.BIT128]])),g(w,"ALL",[w.UNKNOWN,w.FLOAT64,w.FLOAT32,w.INT64,w.INT32,w.INT16,w.INT8,w.UINT64,w.UINT32,w.UINT16,w.UINT8,w.TIMESTAMP,w.UUID,w.STRING,w.JSON]),g(w,"BIG_INT_TYPES",[w.INT64,w.UINT64,w.TIMESTAMP]),g(w,"z",s.z.union([s.z.string().transform(t=>new w(t)),s.z.instanceof(w)]));let C=w;const le=class X extends Number{constructor(e){super(e.valueOf())}largerThan(e){return this.valueOf()>e.valueOf()}smallerThan(e){return this.valueOf()<e.valueOf()}add(e){return X.bytes(this.valueOf()+e.valueOf())}sub(e){return X.bytes(this.valueOf()-e.valueOf())}truncate(e){return new X(Math.trunc(this.valueOf()/e.valueOf())*e.valueOf())}remainder(e){return X.bytes(this.valueOf()%e.valueOf())}get gigabytes(){return this.valueOf()/X.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/X.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/X.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/X.TERABYTE.valueOf()}toString(){const e=this.truncate(X.TERABYTE),n=this.truncate(X.GIGABYTE),r=this.truncate(X.MEGABYTE),i=this.truncate(X.KILOBYTE),a=this.truncate(X.BYTE),o=e,c=n.sub(e),u=r.sub(n),h=i.sub(r),f=a.sub(i);let d="";return o.isZero||(d+=`${o.terabytes}TB `),c.isZero||(d+=`${c.gigabytes}GB `),u.isZero||(d+=`${u.megabytes}MB `),h.isZero||(d+=`${h.kilobytes}KB `),(!f.isZero||d==="")&&(d+=`${f.valueOf()}B`),d.trim()}static bytes(e=1){return new X(e)}static kilobytes(e=1){return X.bytes(e.valueOf()*1e3)}static megabytes(e=1){return X.kilobytes(e.valueOf()*1e3)}static gigabytes(e=1){return X.megabytes(e.valueOf()*1e3)}static terabytes(e){return X.gigabytes(e.valueOf()*1e3)}get isZero(){return this.valueOf()===0}};g(le,"BYTE",new le(1)),g(le,"KILOBYTE",le.kilobytes(1)),g(le,"MEGABYTE",le.megabytes(1)),g(le,"GIGABYTE",le.gigabytes(1)),g(le,"TERABYTE",le.terabytes(1)),g(le,"ZERO",new le(0)),g(le,"z",s.z.union([s.z.number().transform(t=>new le(t)),s.z.instanceof(le)]));let ot=le;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 _o=t=>{const e=typeof t;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||t instanceof x||t instanceof $||t instanceof Date},Af=(t,e,n,r=0)=>t.usesBigInt&&!e.usesBigInt?Number(n)-Number(r):!t.usesBigInt&&e.usesBigInt?BigInt(n.valueOf())-BigInt(r.valueOf()):Mt(n,-r).valueOf(),kf=t=>t==null?!1:Array.isArray(t)||t instanceof ArrayBuffer||ArrayBuffer.isView(t)&&!(t instanceof DataView)||t instanceof Ke?!0:_o(t),Le=-1,ms={[Symbol.iterator]:()=>ms,next:()=>({done:!0,value:void 0})},xf=s.z.string().transform(t=>new Uint8Array(atob(t).split("").map(e=>e.charCodeAt(0))).buffer),Cf=s.z.union([s.z.null(),s.z.undefined()]).transform(()=>new Uint8Array().buffer),ws=10,Bt=class Ce{constructor(e){g(this,"key",""),g(this,"isSynnaxSeries",!0),g(this,"dataType"),g(this,"sampleOffset"),g(this,"gl"),g(this,"_data"),g(this,"_timeRange"),g(this,"alignment",0n),g(this,"_cachedMin"),g(this,"_cachedMax"),g(this,"writePos",Le),g(this,"_refCount",0),g(this,"_cachedLength"),g(this,"_cachedIndexes"),kf(e)&&(e={data:e});const{dataType:n,timeRange:r,sampleOffset:i=0,glBufferUsage:a="static",alignment:o=0n,key:c=Uo()}=e,u=e.data??[];if(u instanceof Ce||typeof u=="object"&&"isSynnaxSeries"in u&&u.isSynnaxSeries===!0){const d=u;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._cachedMin=d._cachedMin,this._cachedMax=d._cachedMax,this.writePos=d.writePos,this._refCount=d._refCount,this._cachedLength=d._cachedLength;return}const h=_o(u),f=Array.isArray(u);if(n!=null)this.dataType=new C(n);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(f||h){let d=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.");d=u[0]}if(typeof d=="string")this.dataType=C.STRING;else if(typeof d=="number")this.dataType=C.FLOAT64;else if(typeof d=="bigint")this.dataType=C.INT64;else if(typeof d=="boolean")this.dataType=C.BOOLEAN;else if(d instanceof x||d instanceof Date||d instanceof x)this.dataType=C.TIMESTAMP;else if(typeof d=="object")this.dataType=C.JSON;else throw new Error(`cannot infer data type of ${typeof d} when constructing a Series from a JS array`)}else this.dataType=new C(u)}if(!f&&!h)this._data=u;else{let d=h?[u]:u;const k=d[0];(k instanceof x||k instanceof Date||k instanceof $)&&(d=d.map(D=>new x(D).valueOf())),this.dataType.equals(C.STRING)?(this._cachedLength=d.length,this._data=new TextEncoder().encode(d.join(`
|
|
30
30
|
`)+`
|
|
31
31
|
`)):this.dataType.equals(C.JSON)?(this._cachedLength=d.length,this._data=new TextEncoder().encode(d.map(D=>st.encodeString(D)).join(`
|
|
32
32
|
`)+`
|
|
@@ -36,20 +36,20 @@
|
|
|
36
36
|
`)+`
|
|
37
37
|
`);return new Ce({data:r,dataType:C.JSON,timeRange:n})}acquire(e){this._refCount++,e!=null&&this.updateGLBuffer(e)}release(){if(this._refCount--,this._refCount===0&&this.gl.control!=null)this.maybeGarbageCollectGLBuffer(this.gl.control);else if(this._refCount<0)throw new Error("cannot release an array 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===Le)return 0;const n=this.byteCapacity.valueOf()-this.writePos,r=e.subBytes(0,n);return this.writeToUnderlyingData(r),this.writePos+=r.byteLength.valueOf(),this._cachedLength!=null&&(this._cachedLength+=r.length,this.calculateCachedLength()),r.length}writeFixed(e){if(this.writePos===Le)return 0;const n=this.capacity-this.writePos,r=e.sub(0,n);return this.writeToUnderlyingData(r),this._cachedLength=void 0,this.maybeRecomputeMinMax(r),this.writePos+=r.length,r.length}writeToUnderlyingData(e){this.underlyingData.set(e.data,this.writePos)}get buffer(){return this._data instanceof ArrayBuffer||this._data instanceof SharedArrayBuffer?this._data:this._data.buffer}get underlyingData(){return new this.dataType.Array(this._data)}get data(){return this.writePos===Le?this.underlyingData:new this.dataType.Array(this._data,0,this.writePos)}toStrings(){if(!this.dataType.matches(C.STRING,C.UUID))throw new Error("cannot convert non-string series to strings");return new TextDecoder().decode(this.underlyingData).split(`
|
|
38
38
|
`).slice(0,-1)}toUUIDs(){if(!this.dataType.equals(C.UUID))throw new Error("cannot convert non-uuid series to uuids");const e=C.UUID.density.valueOf(),n=Array(this.length);for(let r=0;r<this.length;r++){const i=this.underlyingData.slice(r*e,(r+1)*e),a=Array.from(new Uint8Array(i),o=>o.toString(16).padStart(2,"0")).join("").replace(/(.{8})(.{4})(.{4})(.{4})(.{12})/,"$1-$2-$3-$4-$5");n[r]=a}return n}parseJSON(e){if(!this.dataType.equals(C.JSON))throw new Error("cannot convert non-string series to strings");return new TextDecoder().decode(this.underlyingData).split(`
|
|
39
|
-
`).slice(0,-1).map(n=>e.parse(st.decodeString(n)))}get timeRange(){if(this._timeRange==null)throw new Error("time range not set on series");return this._timeRange}get byteCapacity(){return new ot(this.underlyingData.byteLength)}get capacity(){return this.dataType.isVariable?this.byteCapacity.valueOf():this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===Le?this.byteCapacity:this.dataType.isVariable?new ot(this.writePos):this.dataType.density.size(this.writePos)}get length(){return this._cachedLength!=null?this._cachedLength:this.dataType.isVariable?this.calculateCachedLength():this.writePos===Le?this.data.length:this.writePos}calculateCachedLength(){if(!this.dataType.isVariable)throw new Error("cannot calculate length of a non-variable length data type");let e=0;const n=[0];return this.data.forEach((r,i)=>{r===ws&&(e++,n.push(i+1))}),this._cachedIndexes=n,this._cachedLength=e,e}convert(e,n=0){if(this.dataType.equals(e))return this;const r=new e.Array(this.length);for(let i=0;i<this.length;i++)r[i]=Ef(this.dataType,e,this.data[i],n);return new Ce({data:r.buffer,dataType:e,timeRange:this._timeRange,sampleOffset:n,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment})}calcRawMax(){if(this.length===0)return-1/0;if(this.dataType.equals(C.TIMESTAMP))this._cachedMax=this.data[this.data.length-1];else if(this.dataType.usesBigInt){const e=this.data;this._cachedMax=e.reduce((n,r)=>n>r?n:r)}else{const e=this.data;this._cachedMax=e.reduce((n,r)=>n>r?n:r)}return this._cachedMax}get max(){if(this.dataType.isVariable)throw new Error("cannot calculate maximum on a variable length data type");return this.writePos===0?-1/0:(this._cachedMax==null&&(this._cachedMax=this.calcRawMax()),Bt(this._cachedMax,this.sampleOffset))}calcRawMin(){if(this.length===0)return 1/0;if(this.dataType.equals(C.TIMESTAMP))this._cachedMin=this.data[0];else if(this.dataType.usesBigInt){const e=this.data;this._cachedMin=e.reduce((n,r)=>n<r?n:r)}else{const e=this.data;this._cachedMin=e.reduce((n,r)=>n<r?n:r)}return this._cachedMin}get min(){if(this.dataType.isVariable)throw new Error("cannot calculate minimum on a variable length data type");return this.writePos===0?1/0:(this._cachedMin==null&&(this._cachedMin=this.calcRawMin()),Bt(this._cachedMin,this.sampleOffset))}get bounds(){return de(Number(this.min),Number(this.max))}maybeRecomputeMinMax(e){if(this._cachedMin!=null){const n=e._cachedMin??e.calcRawMin();n<this._cachedMin&&(this._cachedMin=n)}if(this._cachedMax!=null){const n=e._cachedMax??e.calcRawMax();n>this._cachedMax&&(this._cachedMax=n)}}enrich(){this.max,this.min}get range(){return Bt(this.max,-this.min)}atAlignment(e,n){const r=Number(e-this.alignment);if(r<0||r>=this.length){if(n===!0)throw new Error(`[series] - no value at index ${r}`);return}return this.at(r,n)}at(e,n){if(this.dataType.isVariable)return this.atVariable(e,n??!1);e<0&&(e=this.length+e);const r=this.data[e];if(r==null){if(n===!0)throw new Error(`[series] - no value at index ${e}`);return}return Bt(r,this.sampleOffset)}atVariable(e,n){let r=0,i=0;if(this._cachedIndexes!=null)r=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]===ws){if(e===0){i=o;break}r=o+1,e--}if(i===0&&(i=this.data.length),r>=i||e>0){if(n)throw new Error(`[series] - no value at index ${e}`);return}}const a=this.data.slice(r,i);return this.dataType.equals(C.STRING)?new TextDecoder().decode(a):Ao(JSON.parse(new TextDecoder().decode(a)))}binarySearch(e){let n=0,r=this.length-1;const i=ff(e);for(;n<=r;){const a=Math.floor((n+r)/2),o=i(this.at(a,!0),e);if(o===0)return a;o<0?n=a+1:r=a-1}return n}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals(C.FLOAT32))throw new Error("Only FLOAT32 arrays can be used in WebGL");const{buffer:n,bufferUsage:r,prevBuffer:i}=this.gl;if(n==null&&(this.gl.buffer=e.createBuffer()),this.writePos!==i)if(e.bindBuffer(e.ARRAY_BUFFER,this.gl.buffer),this.writePos!==Le){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.underlyingData,r==="static"?e.STATIC_DRAW:e.DYNAMIC_DRAW),this.gl.prevBuffer=Le}as(e){if(e==="string"){if(!this.dataType.equals(C.STRING))throw new Error(`cannot convert series of type ${this.dataType.toString()} to string`);return this}if(e==="number"){if(!this.dataType.isNumeric)throw new Error(`cannot convert series of type ${this.dataType.toString()} to number`);return this}if(e==="bigint"){if(!this.dataType.equals(C.INT64))throw new Error(`cannot convert series of type ${this.dataType.toString()} to bigint`);return this}throw new Error(`cannot convert series to ${e}`)}get digest(){var e;return{key:this.key,dataType:this.dataType.toString(),sampleOffset:this.sampleOffset,alignment:this.alignmentBounds,timeRange:(e=this._timeRange)==null?void 0:e.toString(),length:this.length,capacity:this.capacity}}get memInfo(){return{key:this.key,length:this.length,byteLength:this.byteLength,glBuffer:this.gl.buffer!=null}}get alignmentBounds(){return de(this.alignment,this.alignment+BigInt(this.length))}maybeGarbageCollectGLBuffer(e){this.gl.buffer!=null&&(e.deleteBuffer(this.gl.buffer),this.gl.buffer=null,this.gl.prevBuffer=0,this.gl.control=null)}get glBuffer(){if(this.gl.buffer==null)throw new Error("gl buffer not initialized");return this.gl.prevBuffer!==this.writePos&&console.warn("buffer not updated"),this.gl.buffer}[Symbol.iterator](){if(this.dataType.isVariable){const e=new Cf(this);return this.dataType.equals(C.JSON)?new $f(e):e}return new Rf(this)}slice(e,n){return this.sliceSub(!1,e,n)}sub(e,n){return this.sliceSub(!0,e,n)}subIterator(e,n){return new Ji(this,e,n??this.length)}subAlignmentIterator(e,n){return new Ji(this,Number(e-this.alignment),Number(n-this.alignment))}subBytes(e,n){if(e>=0&&(n==null||n>=this.byteLength.valueOf()))return this;const r=this.data.subarray(e,n);return new Ce({data:r,dataType:this.dataType,timeRange:this._timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(e)})}sliceSub(e,n,r){if(n<=0&&(r==null||r>=this.length))return this;let i;return e?i=this.data.subarray(n,r):i=this.data.slice(n,r),new Ce({data:i,dataType:this.dataType,timeRange:this._timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(n)})}reAlign(e){return new Ce({data:this.buffer,dataType:this.dataType,timeRange:se.ZERO,sampleOffset:this.sampleOffset,glBufferUsage:"static",alignment:e})}};g(Mt,"crudeZ",s.z.object({timeRange:se.z.optional(),dataType:C.z,alignment:vf.optional(),data:s.z.union([kf,xf,s.z.instanceof(ArrayBuffer)]),glBufferUsage:If.optional().default("static").optional()})),g(Mt,"z",Mt.crudeZ.transform(t=>new Mt(t)));let Ke=Mt,Ji=class{constructor(t,e,n){g(this,"series"),g(this,"end"),g(this,"index"),this.series=t;const r=de(0,t.length);this.end=qi(r,n),this.index=qi(r,e)}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}[Symbol.iterator](){return this}};class Cf{constructor(e){if(g(this,"series"),g(this,"index"),g(this,"decoder"),!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,n=this.series.data;for(;this.index<n.length&&n[this.index]!==ws;)this.index++;const r=this.index;return e===r?{done:!0,value:void 0}:(this.index++,{done:!1,value:this.decoder.decode(this.series.buffer.slice(e,r))})}[Symbol.iterator](){return this}}var Hi,Xi;class $f{constructor(e){g(this,"wrapped"),g(this,Hi,"JSONSeriesIterator"),this.wrapped=e}next(){const e=this.wrapped.next();return e.done===!0?{done:!0,value:void 0}:{done:!1,value:st.decodeString(e.value)}}[(Xi=Symbol.iterator,Hi=Symbol.toStringTag,Xi)](){return this}}var Qi,ea;class Rf{constructor(e){g(this,"series"),g(this,"index"),g(this,Qi,"SeriesIterator"),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)}}[(ea=Symbol.iterator,Qi=Symbol.toStringTag,ea)](){return this}}const Bt=(t,e)=>typeof t=="bigint"&&typeof e=="bigint"||typeof t=="number"&&typeof e=="number"?t+e:e===0?t:t===0?e:Number(t)+Number(e);class jf{constructor(e){if(g(this,"series"),e.length!==0){const n=e[0].dataType;for(let r=1;r<e.length;r++)if(!e[r].dataType.equals(n))throw new Error("[multi-series] - series must have the same data type")}this.series=e}as(e){if(!new C(e).equals(this.dataType))throw new Error(`cannot convert series of type ${this.dataType.toString()} to ${e.toString()}`);return this}get dataType(){return this.series.length===0?C.UNKNOWN:this.series[0].dataType}get timeRange(){return this.series.length===0?se.ZERO:new se(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?de(0n,0n):de(this.series[0].alignmentBounds.lower,this.series[this.series.length-1].alignmentBounds.upper)}push(e){this.series.push(e)}get length(){return this.series.reduce((e,n)=>e+n.length,0)}atAlignment(e,n){if(this.series.length===0){if(n)throw new Error(`[series] - no value at alignment ${e}`);return}for(const r of this.series)if(gn(r.alignmentBounds,e))return r.atAlignment(e,n);if(n)throw new Error(`[series] - no value at alignment ${e}`)}at(e,n=!1){e<0&&(e=this.length+e);for(const r of this.series){if(e<r.length)return r.at(e,n);e-=r.length}if(n)throw new Error(`[series] - no value at index ${e}`)}subIterator(e,n){return new Ur(this,e,n??this.length)}subAlignmentIterator(e,n){if(e>=this.alignmentBounds.upper||n<=this.alignmentBounds.lower)return ms;let r=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)r+=o.length;else if(gn(o.alignmentBounds,e)){r+=Number(e-o.alignment);break}}let i=0;for(let a=0;a<this.series.length;a++){const o=this.series[a];if(n<o.alignment)break;if(n>=o.alignmentBounds.upper)i+=o.length;else if(gn(o.alignmentBounds,n)){i+=Number(n-o.alignment);break}}return new Ur(this,r,i)}subAlignmentSpanIterator(e,n){if(e>=this.alignmentBounds.upper)return ms;let r=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)r+=a.length;else if(gn(a.alignmentBounds,e)){r+=Number(e-a.alignment);break}}return new Ur(this,r,r+n)}get byteLength(){return new ot(this.series.reduce((e,n)=>e+n.byteLength.valueOf(),0))}get data(){const e=new this.dataType.Array(this.length);let n=0;for(const r of this.series)e.set(r.data,n),n+=r.length;return new this.dataType.Array(e)}traverseAlignment(e,n){const r=this.series.map(i=>i.alignmentBounds);return Kd(r,e,n)}distance(e,n){const r=this.series.map(i=>i.alignmentBounds);return Jd(r,e,n)}[Symbol.iterator](){return this.series.length===0?{next(){return{done:!0,value:void 0}}}:new Mf(this.series)}}var ta,na;class Mf{constructor(e){g(this,"series"),g(this,"seriesIndex"),g(this,"internal"),g(this,ta,"MultiSeriesIterator"),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())}[(na=Symbol.iterator,ta=Symbol.toStringTag,na)](){return this}}class Ur{constructor(e,n,r){g(this,"series"),g(this,"index"),g(this,"end"),this.series=e,this.end=r,this.index=n}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}[Symbol.iterator](){return this}}s.z.object({key:s.z.string(),value:s.z.string()});var Bf=Object.defineProperty,Df=(t,e,n)=>e in t?Bf(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Bn=(t,e,n)=>Df(t,typeof e!="symbol"?e+"":e,n);let Pf=class{constructor(t,e){Bn(this,"handlers"),Bn(this,"transform"),Bn(this,"closer"),this.transform=t,this.handlers=e??new Map}onChange(t){return this.handlers.set(t,null),()=>this.handlers.delete(t)}notify(t){let e=t;if(this.transform!=null){const[n,r]=this.transform(t);if(!r)return;e=n}this.handlers.forEach((n,r)=>r(e))}setCloser(t){this.closer=t}async close(){var t;return await((t=this.closer)==null?void 0:t.call(this))}},Uf=class{constructor(t){Bn(this,"handlers"),this.handlers=t??new Map}onChange(t){return this.handlers.set(t,null),()=>this.handlers.delete(t)}notify(t){this.handlers.forEach((e,n)=>n(t))}};const Qe=Object.freeze(Object.defineProperty({__proto__:null,BaseObserver:Uf,Observer:Pf},Symbol.toStringTag,{value:"Module"})),dr=s.z.record(s.z.union([s.z.number(),s.z.string(),s.z.symbol()]),s.z.unknown()),Lf=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser";Lf();const _f=["MacOS","Windows","Linux","Docker"];s.z.enum(_f);var Yf=Object.defineProperty,Ff=(t,e,n)=>e in t?Yf(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Dt=(t,e,n)=>Ff(t,typeof e!="symbol"?e+"":e,n);const qf=(...t)=>t.map(Yo).join(""),Yo=t=>(t.endsWith("/")||(t+="/"),t.startsWith("/")&&(t=t.slice(1)),t),Vf=t=>t.endsWith("/")?t.slice(0,-1):t,bs=class vs{constructor({host:e,port:n,protocol:r="",pathPrefix:i=""}){Dt(this,"protocol"),Dt(this,"host"),Dt(this,"port"),Dt(this,"path"),this.protocol=r,this.host=e,this.port=n,this.path=Yo(i)}replace(e){return new vs({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new vs({...this,pathPrefix:qf(this.path,e)})}toString(){return Vf(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}};Dt(bs,"UNKNOWN",new bs({host:"unknown",port:0}));let Wf=bs;var Gf=Object.defineProperty,Zf=(t,e,n)=>e in t?Gf(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Dn=(t,e,n)=>Zf(t,typeof e!="symbol"?e+"":e,n);const Ze=class extends Number{};Dn(Ze,"Absolute",255),Dn(Ze,"Default",1),Dn(Ze,"z",s.z.union([s.z.instanceof(Ze),s.z.number().int().min(0).max(255).transform(t=>new Ze(t)),s.z.instanceof(Number).transform(t=>new Ze(t))]));let Fo=Ze;const qo=s.z.object({name:s.z.string(),key:s.z.string()}),Kf=t=>s.z.object({subject:qo,resource:t,authority:Fo.z}),Jf=(...t)=>e=>e.filter(n=>{let r=!1;return n.to!=null&&(r=t.includes(n.to.resource)),n.from!=null&&!r&&(r=t.includes(n.from.resource)),r}),lt=Object.freeze(Object.defineProperty({__proto__:null,Authority:Fo,filterTransfersByChannelKey:Jf,stateZ:Kf,subjectZ:qo},Symbol.toStringTag,{value:"Module"})),Vo=class Pt extends Error{constructor(){super(Pt.MESSAGE)}matches(e){return typeof e=="string"?e.includes(Pt.MESSAGE):e instanceof Pt||e.message.includes(Pt.MESSAGE)}};Dn(Vo,"MESSAGE","canceled");let Hf=Vo;new Hf;const Os=s.z.string().regex(/^\d+\.\d+\.\d+$/),an=(t,e,n={})=>{n.checkMajor??(n.checkMajor=!0),n.checkMinor??(n.checkMinor=!0),n.checkPatch??(n.checkPatch=!0);const r=Os.parse(t),i=Os.parse(e),[a,o,c]=r.split(".").map(Number),[u,h,f]=i.split(".").map(Number);if(n.checkMajor){if(a<u)return Dr;if(a>u)return Pr}if(n.checkMinor){if(o<h)return Dr;if(o>h)return Pr}if(n.checkPatch){if(c<f)return Dr;if(c>f)return Pr}return hr},Xf=(t,e,n={})=>mf(an(t,e,n)),Wo=(t,e,n={})=>pf(an(t,e,n)),Qf=(t,e,n={})=>gf(an(t,e,n)),ey=({name:t,migrate:e})=>n=>{try{const r=e(n);return console.log(`${t} migrated: ${n.version} -> ${r.version}`),r}catch(r){throw console.log(`${t} failed to migrate from ${n.version}`),console.error(r),r}},ty=({name:t,migrations:e,targetSchema:n,defaultVersion:r,def:i})=>{const a=Object.keys(e).sort(an).pop();if(a==null)return h=>{if(h.version==null&&(h.version=r),h.version!==i.version)return console.log(`${t} version ${h.version} is newer than latest version of ${i.version}.
|
|
39
|
+
`).slice(0,-1).map(n=>e.parse(st.decodeString(n)))}get timeRange(){if(this._timeRange==null)throw new Error("time range not set on series");return this._timeRange}get byteCapacity(){return new ot(this.underlyingData.byteLength)}get capacity(){return this.dataType.isVariable?this.byteCapacity.valueOf():this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===Le?this.byteCapacity:this.dataType.isVariable?new ot(this.writePos):this.dataType.density.size(this.writePos)}get length(){return this._cachedLength!=null?this._cachedLength:this.dataType.isVariable?this.calculateCachedLength():this.writePos===Le?this.data.length:this.writePos}calculateCachedLength(){if(!this.dataType.isVariable)throw new Error("cannot calculate length of a non-variable length data type");let e=0;const n=[0];return this.data.forEach((r,i)=>{r===ws&&(e++,n.push(i+1))}),this._cachedIndexes=n,this._cachedLength=e,e}convert(e,n=0){if(this.dataType.equals(e))return this;const r=new e.Array(this.length);for(let i=0;i<this.length;i++)r[i]=Af(this.dataType,e,this.data[i],n);return new Ce({data:r.buffer,dataType:e,timeRange:this._timeRange,sampleOffset:n,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment})}calcRawMax(){if(this.length===0)return-1/0;if(this.dataType.equals(C.TIMESTAMP))this._cachedMax=this.data[this.data.length-1];else if(this.dataType.usesBigInt){const e=this.data;this._cachedMax=e.reduce((n,r)=>n>r?n:r)}else{const e=this.data;this._cachedMax=e.reduce((n,r)=>n>r?n:r)}return this._cachedMax}get max(){if(this.dataType.isVariable)throw new Error("cannot calculate maximum on a variable length data type");return this.writePos===0?-1/0:(this._cachedMax==null&&(this._cachedMax=this.calcRawMax()),Mt(this._cachedMax,this.sampleOffset))}calcRawMin(){if(this.length===0)return 1/0;if(this.dataType.equals(C.TIMESTAMP))this._cachedMin=this.data[0];else if(this.dataType.usesBigInt){const e=this.data;this._cachedMin=e.reduce((n,r)=>n<r?n:r)}else{const e=this.data;this._cachedMin=e.reduce((n,r)=>n<r?n:r)}return this._cachedMin}get min(){if(this.dataType.isVariable)throw new Error("cannot calculate minimum on a variable length data type");return this.writePos===0?1/0:(this._cachedMin==null&&(this._cachedMin=this.calcRawMin()),Mt(this._cachedMin,this.sampleOffset))}get bounds(){return de(Number(this.min),Number(this.max))}maybeRecomputeMinMax(e){if(this._cachedMin!=null){const n=e._cachedMin??e.calcRawMin();n<this._cachedMin&&(this._cachedMin=n)}if(this._cachedMax!=null){const n=e._cachedMax??e.calcRawMax();n>this._cachedMax&&(this._cachedMax=n)}}enrich(){this.max,this.min}get range(){return Mt(this.max,-this.min)}atAlignment(e,n){const r=Number(e-this.alignment);if(r<0||r>=this.length){if(n===!0)throw new Error(`[series] - no value at index ${r}`);return}return this.at(r,n)}at(e,n){if(this.dataType.isVariable)return this.atVariable(e,n??!1);e<0&&(e=this.length+e);const r=this.data[e];if(r==null){if(n===!0)throw new Error(`[series] - no value at index ${e}`);return}return Mt(r,this.sampleOffset)}atVariable(e,n){let r=0,i=0;if(this._cachedIndexes!=null)r=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]===ws){if(e===0){i=o;break}r=o+1,e--}if(i===0&&(i=this.data.length),r>=i||e>0){if(n)throw new Error(`[series] - no value at index ${e}`);return}}const a=this.data.slice(r,i);return this.dataType.equals(C.STRING)?new TextDecoder().decode(a):Ao(JSON.parse(new TextDecoder().decode(a)))}binarySearch(e){let n=0,r=this.length-1;const i=yf(e);for(;n<=r;){const a=Math.floor((n+r)/2),o=i(this.at(a,!0),e);if(o===0)return a;o<0?n=a+1:r=a-1}return n}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals(C.FLOAT32))throw new Error("Only FLOAT32 arrays can be used in WebGL");const{buffer:n,bufferUsage:r,prevBuffer:i}=this.gl;if(n==null&&(this.gl.buffer=e.createBuffer()),this.writePos!==i)if(e.bindBuffer(e.ARRAY_BUFFER,this.gl.buffer),this.writePos!==Le){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.underlyingData,r==="static"?e.STATIC_DRAW:e.DYNAMIC_DRAW),this.gl.prevBuffer=Le}as(e){if(e==="string"){if(!this.dataType.equals(C.STRING))throw new Error(`cannot convert series of type ${this.dataType.toString()} to string`);return this}if(e==="number"){if(!this.dataType.isNumeric)throw new Error(`cannot convert series of type ${this.dataType.toString()} to number`);return this}if(e==="bigint"){if(!this.dataType.equals(C.INT64))throw new Error(`cannot convert series of type ${this.dataType.toString()} to bigint`);return this}throw new Error(`cannot convert series to ${e}`)}get digest(){var e;return{key:this.key,dataType:this.dataType.toString(),sampleOffset:this.sampleOffset,alignment:this.alignmentBounds,timeRange:(e=this._timeRange)==null?void 0:e.toString(),length:this.length,capacity:this.capacity}}get memInfo(){return{key:this.key,length:this.length,byteLength:this.byteLength,glBuffer:this.gl.buffer!=null}}get alignmentBounds(){return de(this.alignment,this.alignment+BigInt(this.length))}maybeGarbageCollectGLBuffer(e){this.gl.buffer!=null&&(e.deleteBuffer(this.gl.buffer),this.gl.buffer=null,this.gl.prevBuffer=0,this.gl.control=null)}get glBuffer(){if(this.gl.buffer==null)throw new Error("gl buffer not initialized");return this.gl.prevBuffer!==this.writePos&&console.warn("buffer not updated"),this.gl.buffer}[Symbol.iterator](){if(this.dataType.isVariable){const e=new $f(this);return this.dataType.equals(C.JSON)?new Rf(e):e}return new jf(this)}slice(e,n){return this.sliceSub(!1,e,n)}sub(e,n){return this.sliceSub(!0,e,n)}subIterator(e,n){return new Ji(this,e,n??this.length)}subAlignmentIterator(e,n){return new Ji(this,Number(e-this.alignment),Number(n-this.alignment))}subBytes(e,n){if(e>=0&&(n==null||n>=this.byteLength.valueOf()))return this;const r=this.data.subarray(e,n);return new Ce({data:r,dataType:this.dataType,timeRange:this._timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(e)})}sliceSub(e,n,r){if(n<=0&&(r==null||r>=this.length))return this;let i;return e?i=this.data.subarray(n,r):i=this.data.slice(n,r),new Ce({data:i,dataType:this.dataType,timeRange:this._timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(n)})}reAlign(e){return new Ce({data:this.buffer,dataType:this.dataType,timeRange:se.ZERO,sampleOffset:this.sampleOffset,glBufferUsage:"static",alignment:e})}};g(Bt,"crudeZ",s.z.object({timeRange:se.z.optional(),dataType:C.z,alignment:Of.optional(),data:s.z.union([xf,Cf,s.z.instanceof(ArrayBuffer)]),glBufferUsage:Ef.optional().default("static").optional()})),g(Bt,"z",Bt.crudeZ.transform(t=>new Bt(t)));let Ke=Bt,Ji=class{constructor(t,e,n){g(this,"series"),g(this,"end"),g(this,"index"),this.series=t;const r=de(0,t.length);this.end=Fi(r,n),this.index=Fi(r,e)}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}[Symbol.iterator](){return this}};class $f{constructor(e){if(g(this,"series"),g(this,"index"),g(this,"decoder"),!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,n=this.series.data;for(;this.index<n.length&&n[this.index]!==ws;)this.index++;const r=this.index;return e===r?{done:!0,value:void 0}:(this.index++,{done:!1,value:this.decoder.decode(this.series.buffer.slice(e,r))})}[Symbol.iterator](){return this}}var Hi,Xi;class Rf{constructor(e){g(this,"wrapped"),g(this,Hi,"JSONSeriesIterator"),this.wrapped=e}next(){const e=this.wrapped.next();return e.done===!0?{done:!0,value:void 0}:{done:!1,value:st.decodeString(e.value)}}[(Xi=Symbol.iterator,Hi=Symbol.toStringTag,Xi)](){return this}}var Qi,ea;class jf{constructor(e){g(this,"series"),g(this,"index"),g(this,Qi,"SeriesIterator"),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)}}[(ea=Symbol.iterator,Qi=Symbol.toStringTag,ea)](){return this}}const Mt=(t,e)=>typeof t=="bigint"&&typeof e=="bigint"||typeof t=="number"&&typeof e=="number"?t+e:e===0?t:t===0?e:Number(t)+Number(e);class Bf{constructor(e){if(g(this,"series"),e.length!==0){const n=e[0].dataType;for(let r=1;r<e.length;r++)if(!e[r].dataType.equals(n))throw new Error("[multi-series] - series must have the same data type")}this.series=e}as(e){if(!new C(e).equals(this.dataType))throw new Error(`cannot convert series of type ${this.dataType.toString()} to ${e.toString()}`);return this}get dataType(){return this.series.length===0?C.UNKNOWN:this.series[0].dataType}get timeRange(){return this.series.length===0?se.ZERO:new se(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?de(0n,0n):de(this.series[0].alignmentBounds.lower,this.series[this.series.length-1].alignmentBounds.upper)}push(e){this.series.push(e)}get length(){return this.series.reduce((e,n)=>e+n.length,0)}atAlignment(e,n){if(this.series.length===0){if(n)throw new Error(`[series] - no value at alignment ${e}`);return}for(const r of this.series)if(gn(r.alignmentBounds,e))return r.atAlignment(e,n);if(n)throw new Error(`[series] - no value at alignment ${e}`)}at(e,n=!1){e<0&&(e=this.length+e);for(const r of this.series){if(e<r.length)return r.at(e,n);e-=r.length}if(n)throw new Error(`[series] - no value at index ${e}`)}subIterator(e,n){return new Ur(this,e,n??this.length)}subAlignmentIterator(e,n){if(e>=this.alignmentBounds.upper||n<=this.alignmentBounds.lower)return ms;let r=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)r+=o.length;else if(gn(o.alignmentBounds,e)){r+=Number(e-o.alignment);break}}let i=0;for(let a=0;a<this.series.length;a++){const o=this.series[a];if(n<o.alignment)break;if(n>=o.alignmentBounds.upper)i+=o.length;else if(gn(o.alignmentBounds,n)){i+=Number(n-o.alignment);break}}return new Ur(this,r,i)}subAlignmentSpanIterator(e,n){if(e>=this.alignmentBounds.upper)return ms;let r=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)r+=a.length;else if(gn(a.alignmentBounds,e)){r+=Number(e-a.alignment);break}}return new Ur(this,r,r+n)}get byteLength(){return new ot(this.series.reduce((e,n)=>e+n.byteLength.valueOf(),0))}get data(){const e=new this.dataType.Array(this.length);let n=0;for(const r of this.series)e.set(r.data,n),n+=r.length;return new this.dataType.Array(e)}traverseAlignment(e,n){const r=this.series.map(i=>i.alignmentBounds);return Jd(r,e,n)}distance(e,n){const r=this.series.map(i=>i.alignmentBounds);return Hd(r,e,n)}[Symbol.iterator](){return this.series.length===0?{next(){return{done:!0,value:void 0}}}:new Mf(this.series)}}var ta,na;class Mf{constructor(e){g(this,"series"),g(this,"seriesIndex"),g(this,"internal"),g(this,ta,"MultiSeriesIterator"),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())}[(na=Symbol.iterator,ta=Symbol.toStringTag,na)](){return this}}class Ur{constructor(e,n,r){g(this,"series"),g(this,"index"),g(this,"end"),this.series=e,this.end=r,this.index=n}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}[Symbol.iterator](){return this}}s.z.object({key:s.z.string(),value:s.z.string()});var Df=Object.defineProperty,Pf=(t,e,n)=>e in t?Df(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Mn=(t,e,n)=>Pf(t,typeof e!="symbol"?e+"":e,n);let Uf=class{constructor(t,e){Mn(this,"handlers"),Mn(this,"transform"),Mn(this,"closer"),this.transform=t,this.handlers=e??new Map}onChange(t){return this.handlers.set(t,null),()=>this.handlers.delete(t)}notify(t){let e=t;if(this.transform!=null){const[n,r]=this.transform(t);if(!r)return;e=n}this.handlers.forEach((n,r)=>r(e))}setCloser(t){this.closer=t}async close(){var t;return await((t=this.closer)==null?void 0:t.call(this))}},Lf=class{constructor(t){Mn(this,"handlers"),this.handlers=t??new Map}onChange(t){return this.handlers.set(t,null),()=>this.handlers.delete(t)}notify(t){this.handlers.forEach((e,n)=>n(t))}};const Qe=Object.freeze(Object.defineProperty({__proto__:null,BaseObserver:Lf,Observer:Uf},Symbol.toStringTag,{value:"Module"})),dr=s.z.record(s.z.union([s.z.number(),s.z.string(),s.z.symbol()]),s.z.unknown()),_f=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser";_f();const Yf=["MacOS","Windows","Linux","Docker"];s.z.enum(Yf);var qf=Object.defineProperty,Ff=(t,e,n)=>e in t?qf(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Dt=(t,e,n)=>Ff(t,typeof e!="symbol"?e+"":e,n);const Vf=(...t)=>t.map(Yo).join(""),Yo=t=>(t.endsWith("/")||(t+="/"),t.startsWith("/")&&(t=t.slice(1)),t),Wf=t=>t.endsWith("/")?t.slice(0,-1):t,bs=class vs{constructor({host:e,port:n,protocol:r="",pathPrefix:i=""}){Dt(this,"protocol"),Dt(this,"host"),Dt(this,"port"),Dt(this,"path"),this.protocol=r,this.host=e,this.port=n,this.path=Yo(i)}replace(e){return new vs({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new vs({...this,pathPrefix:Vf(this.path,e)})}toString(){return Wf(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}};Dt(bs,"UNKNOWN",new bs({host:"unknown",port:0}));let Gf=bs;var Zf=Object.defineProperty,Kf=(t,e,n)=>e in t?Zf(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,Dn=(t,e,n)=>Kf(t,typeof e!="symbol"?e+"":e,n);const Ze=class extends Number{};Dn(Ze,"Absolute",255),Dn(Ze,"Default",1),Dn(Ze,"z",s.z.union([s.z.instanceof(Ze),s.z.number().int().min(0).max(255).transform(t=>new Ze(t)),s.z.instanceof(Number).transform(t=>new Ze(t))]));let qo=Ze;const Fo=s.z.object({name:s.z.string(),key:s.z.string()}),Jf=t=>s.z.object({subject:Fo,resource:t,authority:qo.z}),Hf=(...t)=>e=>e.filter(n=>{let r=!1;return n.to!=null&&(r=t.includes(n.to.resource)),n.from!=null&&!r&&(r=t.includes(n.from.resource)),r}),lt=Object.freeze(Object.defineProperty({__proto__:null,Authority:qo,filterTransfersByChannelKey:Hf,stateZ:Jf,subjectZ:Fo},Symbol.toStringTag,{value:"Module"})),Vo=class Pt extends Error{constructor(){super(Pt.MESSAGE)}matches(e){return typeof e=="string"?e.includes(Pt.MESSAGE):e instanceof Pt||e.message.includes(Pt.MESSAGE)}};Dn(Vo,"MESSAGE","canceled");let Xf=Vo;new Xf;const Os=s.z.string().regex(/^\d+\.\d+\.\d+$/),an=(t,e,n={})=>{n.checkMajor??(n.checkMajor=!0),n.checkMinor??(n.checkMinor=!0),n.checkPatch??(n.checkPatch=!0);const r=Os.parse(t),i=Os.parse(e),[a,o,c]=r.split(".").map(Number),[u,h,f]=i.split(".").map(Number);if(n.checkMajor){if(a<u)return Dr;if(a>u)return Pr}if(n.checkMinor){if(o<h)return Dr;if(o>h)return Pr}if(n.checkPatch){if(c<f)return Dr;if(c>f)return Pr}return hr},Qf=(t,e,n={})=>wf(an(t,e,n)),Wo=(t,e,n={})=>mf(an(t,e,n)),ey=(t,e,n={})=>pf(an(t,e,n)),ty=({name:t,migrate:e})=>n=>{try{const r=e(n);return console.log(`${t} migrated: ${n.version} -> ${r.version}`),r}catch(r){throw console.log(`${t} failed to migrate from ${n.version}`),console.error(r),r}},ny=({name:t,migrations:e,targetSchema:n,defaultVersion:r,def:i})=>{const a=Object.keys(e).sort(an).pop();if(a==null)return h=>{if(h.version==null&&(h.version=r),h.version!==i.version)return console.log(`${t} version ${h.version} is newer than latest version of ${i.version}.
|
|
40
40
|
Returning default instead.
|
|
41
|
-
`),i;try{return n!=null?n.parse(h):h}catch(f){return console.log(`${t} failed to parse default. Exiting with default`),console.error(f),i}};const o=Object.keys(e).length;let c=!1;const u=h=>{try{if(o===0||Wo(h.version,a))return console.log(c?`${t} ${h.version} now up to date`:`${t} version ${h.version} is up to date with target version ${i.version}`),h;const f=h.version,d=e[f],k=d(h);return c=!0,u(k)}catch(f){return console.log(`${t} failed to migrate from ${h.version} to ${a}`),console.error(f),i}};return h=>{try{if(h.version==null)if(r!=null)console.log(`${t} version is null. Setting version to default of ${r}`),h.version=r;else return console.log(`${t} version is null and no default version set. Exiting with default`),i;return u(h)}catch(f){return console.log(`${t} failed to parse final result. Exiting with default`),console.error(f),i}}},ra=Object.freeze(Object.defineProperty({__proto__:null,compareSemVer:an,createMigration:
|
|
41
|
+
`),i;try{return n!=null?n.parse(h):h}catch(f){return console.log(`${t} failed to parse default. Exiting with default`),console.error(f),i}};const o=Object.keys(e).length;let c=!1;const u=h=>{try{if(o===0||Wo(h.version,a))return console.log(c?`${t} ${h.version} now up to date`:`${t} version ${h.version} is up to date with target version ${i.version}`),h;const f=h.version,d=e[f],k=d(h);return c=!0,u(k)}catch(f){return console.log(`${t} failed to migrate from ${h.version} to ${a}`),console.error(f),i}};return h=>{try{if(h.version==null)if(r!=null)console.log(`${t} version is null. Setting version to default of ${r}`),h.version=r;else return console.log(`${t} version is null and no default version set. Exiting with default`),i;return u(h)}catch(f){return console.log(`${t} failed to parse final result. Exiting with default`),console.error(f),i}}},ra=Object.freeze(Object.defineProperty({__proto__:null,compareSemVer:an,createMigration:ty,migrator:ny,semVerNewer:Wo,semVerOlder:ey,semVerZ:Os,versionsEqual:Qf},Symbol.toStringTag,{value:"Module"})),Fe="sy.",Pn=class Go extends Te{constructor(){super(...arguments),l(this,"type",Go.TYPE)}};l(Pn,"TYPE",Fe+"validation"),l(Pn,"matches",fe(Pn.TYPE));let K=Pn;const Un=class Zo extends K{constructor(e,n){super(e+": "+n),l(this,"type",Zo.TYPE),l(this,"field"),l(this,"message"),this.field=e,this.message=n}};l(Un,"TYPE",K.TYPE+".field"),l(Un,"matches",fe(Un.TYPE));let sa=Un;const Ln=class Ko extends Te{constructor(){super(...arguments),l(this,"type",Ko.TYPE)}};l(Ln,"TYPE",Fe+"auth"),l(Ln,"matches",fe(Ln.TYPE));let nr=Ln;const _n=class Jo extends nr{constructor(){super(...arguments),l(this,"type",Jo.TYPE)}};l(_n,"TYPE",nr.TYPE+".invalid-token"),l(_n,"matches",fe(_n.TYPE));let Ts=_n;const Yn=class Ho extends Te{constructor(e){super(`
|
|
42
42
|
Unexpected error encountered:
|
|
43
43
|
|
|
44
44
|
${e}
|
|
45
45
|
|
|
46
46
|
Please report this to the Synnax team.
|
|
47
|
-
`),l(this,"type",Ho.TYPE)}};l(Yn,"TYPE",qe+"unexpected"),l(Yn,"matches",fe(Yn.TYPE));let be=Yn;const Fn=class Xo extends Te{constructor(){super(...arguments),l(this,"type",Xo.TYPE)}};l(Fn,"TYPE",qe+"query"),l(Fn,"matches",fe(Fn.TYPE));let Oe=Fn;const qn=class Qo extends Oe{constructor(){super(...arguments),l(this,"type",Qo.TYPE)}};l(qn,"TYPE",Oe.TYPE+".not_found"),l(qn,"matches",fe(qn.TYPE));let ct=qn;const Vn=class el extends Oe{constructor(){super(...arguments),l(this,"type",el.TYPE)}};l(Vn,"TYPE",Oe.TYPE+".multiple_results"),l(Vn,"matches",fe(Vn.TYPE));let ut=Vn;const Wn=class tl extends Te{constructor(e,n){super(e),l(this,"type",tl.TYPE),l(this,"path"),this.path=n}};l(Wn,"TYPE",qe+"route"),l(Wn,"matches",fe(Wn.TYPE));let ia=Wn;const Gn=class nl extends Te{constructor(){super(...arguments),l(this,"type",nl.TYPE)}};l(Gn,"TYPE",qe+"control"),l(Gn,"matches",fe(Gn.TYPE));let rr=Gn;const Zn=class rl extends rr{constructor(){super(...arguments),l(this,"type",rl.TYPE)}};l(Zn,"TYPE",rr.TYPE+".unauthorized"),l(Zn,"matches",fe(Zn.TYPE));let aa=Zn;const Lr=class sl extends Te{constructor(){super(...arguments),l(this,"type",sl.TYPE)}};l(Lr,"TYPE",qe+"contiguity"),l(Lr,"matches",fe(Lr.TYPE));const ny=t=>{if(!t.type.startsWith(qe))return null;if(t.type.startsWith(K.TYPE)){if(t.type===sa.TYPE){const e=t.data.split(": ");return e.length<2?new K(t.data):new sa(e[0],e[1])}return new K(t.data)}return t.type.startsWith(nr.TYPE)?t.type.startsWith(Ts.TYPE)?new Ts(t.data):new nr(t.data):t.type.startsWith(be.TYPE)?new be(t.data):t.type.startsWith(Oe.TYPE)?t.type.startsWith(ct.TYPE)?new ct(t.data):t.type.startsWith(ut.TYPE)?new ut(t.data):new Oe(t.data):t.type.startsWith(rr.TYPE)?t.type.startsWith(aa.TYPE)?new aa(t.data):new rr(t.data):t.type.startsWith(ia.TYPE)?new ia(t.data,t.data):new be(t.data)},ry=()=>{throw new Error("Not implemented")};bo({encode:ry,decode:ny});const sy=async(t,e)=>{const[n,r]=await e(t);return r==null?[n,r]:r instanceof Xe?[n,new Xe({message:`Cannot reach cluster at ${r.url.host}:${r.url.port}`,url:r.url})]:[n,r]};class il{constructor(e,n){l(this,"key"),l(this,"name"),this.key=n,this.name=e}get ontologyID(){return new R({type:"group",key:this.key})}}const iy=s.z.string().uuid(),al=s.z.object({key:iy,name:s.z.string()}),fr=s.z.union([s.z.literal("label"),s.z.literal("log"),s.z.literal("allow_all"),s.z.literal("builtin"),s.z.literal("cluster"),s.z.literal("channel"),s.z.literal("node"),s.z.literal("group"),s.z.literal("range"),s.z.literal("framer"),s.z.literal("range-alias"),s.z.literal("user"),s.z.literal("workspace"),s.z.literal("schematic"),s.z.literal("lineplot"),s.z.literal("rack"),s.z.literal("device"),s.z.literal("task"),s.z.literal("policy")]),ge=s.z.object({type:fr,key:s.z.string()}),ay=s.z.string().transform(t=>{const[e,n]=t.split(":");return{type:fr.parse(e),key:n??""}}),Ut=s.z.union([ay,ge]),Kn=class ol{constructor(e){if(l(this,"type"),l(this,"key"),e instanceof ol){this.type=e.type,this.key=e.key;return}if(typeof e=="string"){const[n,r]=e.split(":");this.type=n,this.key=r??"";return}this.type=e.type,this.key=e.key}toString(){return`${this.type}:${this.key}`}isType(){return this.key===""}matchesType(e){return this.type===e&&this.isType()}get payload(){return{type:this.type,key:this.key}}};l(Kn,"z",s.z.union([s.z.instanceof(Kn),Ut.transform(t=>new Kn(t))]));let R=Kn;new R({type:"builtin",key:"root"});const oy=s.z.object({type:s.z.number()}),ly=s.z.object({type:fr,fields:s.z.record(oy)}),cy=s.z.object({id:R.z,name:s.z.string(),schema:ly.optional().nullable(),data:s.z.record(s.z.unknown()).optional().nullable()}).transform(t=>({key:t.id.toString(),...t}));s.z.object({from:R.z,type:s.z.string(),to:R.z});const oa=t=>{const[e,n,r]=t.split("->");return{from:new R(e),type:n,to:new R(r)}},uy=s.z.object({group:al}),hy=s.z.object({parent:ge,key:s.z.string().uuid().optional(),name:s.z.string()}),dy=s.z.object({key:s.z.string(),name:s.z.string()}),fy=s.z.object({keys:s.z.array(s.z.string())});var _e;let yy=(_e=class{constructor(t){l(this,"client"),this.client=t}async create(t,e,n){return(await v(this.client,_e.ENDPOINT,{parent:t,name:e,key:n},hy,uy)).group}async rename(t,e){await v(this.client,_e.ENDPOINT_RENAME,{key:t,name:e},dy,s.z.object({}))}async delete(t){await v(this.client,_e.ENDPOINT_DELETE,{keys:t},fy,s.z.object({}))}},l(_e,"ENDPOINT","/ontology/create-group"),l(_e,"ENDPOINT_RENAME","/ontology/rename-group"),l(_e,"ENDPOINT_DELETE","/ontology/delete-group"),_e),gy=class{constructor(t){l(this,"creator"),this.creator=new yy(t)}async create(t,e,n){return this.sugar(await this.creator.create(t,e,n))}async rename(t,e){return await this.creator.rename(t,e)}async delete(...t){return await this.creator.delete(t)}sugar(t){return new il(t.name,t.key)}};const _r={ADD_CHILDREN:"/ontology/add-children",REMOVE_CHILDREN:"/ontology/remove-children",MOVE_CHILDREN:"/ontology/move-children"},la=s.z.object({id:ge,children:ge.array()}),py=s.z.object({from:ge,to:ge,children:ge.array()});let my=class{constructor(t){l(this,"client"),this.client=t}async addChildren(t,...e){await v(this.client,_r.ADD_CHILDREN,{id:new R(t).payload,children:e.map(n=>new R(n).payload)},la,s.z.object({}))}async removeChildren(t,...e){await v(this.client,_r.REMOVE_CHILDREN,{id:new R(t).payload,children:e.map(n=>new R(n).payload)},la,s.z.object({}))}async moveChildren(t,e,...n){const r={from:new R(t).payload,to:new R(e).payload,children:n.map(i=>new R(i).payload)};await v(this.client,_r.MOVE_CHILDREN,r,py,s.z.object({}))}};const wy="/ontology/retrieve",by=s.z.object({ids:ge.array().optional(),children:s.z.boolean().optional(),parents:s.z.boolean().optional(),includeSchema:s.z.boolean().optional(),excludeFieldData:s.z.boolean().optional(),term:s.z.string().optional(),limit:s.z.number().optional(),offset:s.z.number().optional(),types:fr.array().optional()}),vy=s.z.object({resources:cy.array()}),Yr=t=>T(t).map(e=>new R(e).payload);let Oy=class{constructor(t,e){l(this,"type","ontology"),l(this,"groups"),l(this,"client"),l(this,"writer"),l(this,"framer"),this.client=t,this.writer=new my(t),this.groups=new gy(t),this.framer=e}async search(t,e){return await this.execRetrieve({term:t,...e})}async retrieve(t,e){const n=await this.execRetrieve({ids:Yr(t),...e});if(Array.isArray(t))return n;if(n.length===0)throw new Oe(`No resource found with ID ${t.toString()}`);return n[0]}async page(t,e,n){return await this.execRetrieve({offset:t,limit:e,...n})}async retrieveChildren(t,e){return await this.execRetrieve({ids:Yr(t),children:!0,...e})}async retrieveParents(t,e){return await this.execRetrieve({ids:Yr(t),parents:!0,...e})}async addChildren(t,...e){return await this.writer.addChildren(t,...e)}async removeChildren(t,...e){return await this.writer.removeChildren(t,...e)}async moveChildren(t,e,...n){return await this.writer.moveChildren(t,e,...n)}async openChangeTracker(){return await yr.open(this.framer,this)}async openDependentTracker(t){return await _s.open(t,this.framer,this)}newSearcherWithOptions(t){return{type:this.type,search:e=>this.search(e,t),retrieve:e=>this.retrieve(e,t),page:(e,n)=>this.page(e,n,t)}}async execRetrieve(t){const{resources:e}=await v(this.client,wy,t,by,vy);return e}};const ca="sy_ontology_resource_set",ua="sy_ontology_resource_delete",ha="sy_ontology_relationship_set",da="sy_ontology_relationship_delete";class yr{constructor(e,n){l(this,"relationships"),l(this,"resources"),l(this,"resourceObs"),l(this,"relationshipObs"),l(this,"streamer"),l(this,"client"),l(this,"closePromise"),this.relationshipObs=new Qe.Observer,this.relationships=this.relationshipObs,this.resourceObs=new Qe.Observer,this.resources=this.resourceObs,this.client=n,this.streamer=e,this.closePromise=this.start()}async close(){this.streamer.close(),await this.closePromise}async start(){for await(const e of this.streamer)await this.update(e)}async update(e){const n=await this.parseResourceSets(e),r=this.parseResourceDeletes(e);n.concat(r).length>0&&this.resourceObs.notify(n.concat(r));const i=this.parseRelationshipSets(e),a=this.parseRelationshipDeletes(e);i.concat(a).length>0&&this.relationshipObs.notify(i.concat(a))}parseRelationshipSets(e){const n=e.get(ha);return n.length===0?[]:Array.from(n.as("string")).map(r=>({variant:"set",key:oa(r),value:void 0}))}parseRelationshipDeletes(e){const n=e.get(da);return n.length===0?[]:Array.from(n.as("string")).map(r=>({variant:"delete",key:oa(r)}))}async parseResourceSets(e){const n=e.get(ca);if(n.length===0)return[];const r=Array.from(n.as("string")).map(i=>new R(i));try{return(await this.client.retrieve(r)).map(i=>({variant:"set",key:i.id,value:i}))}catch(i){if(i instanceof Oe)return[];throw i}}parseResourceDeletes(e){const n=e.get(ua);return n.length===0?[]:Array.from(n.as("string")).map(r=>({variant:"delete",key:new R(r)}))}static async open(e,n){const r=await e.openStreamer([ca,ua,ha,da]);return new yr(r,n)}}const fa=t=>t==="from"?"to":"from";class _s extends Qe.Observer{constructor({target:e,dependents:n,relationshipType:r="parent",relationshipDirection:i="from",resourceType:a},o,c){super(),l(this,"internal"),l(this,"target"),l(this,"relDir"),l(this,"resourceType"),l(this,"dependents"),l(this,"client"),l(this,"relType"),l(this,"handleResourceChange",u=>{this.dependents=this.dependents.map(h=>{const f=u.find(d=>d.key.toString()==h.id.toString());return f==null||f.variant==="delete"?h:f.value}),this.notify(this.dependents)}),l(this,"handleRelationshipChange",u=>{const h=u.filter(d=>d.variant==="delete"&&d.key[this.relDir].toString()===this.target.toString()&&(this.resourceType==null||d.key[fa(this.relDir)].type===this.resourceType));this.dependents=this.dependents.filter(d=>!h.some(k=>k.key.to.toString()===d.id.toString()&&k.key.type===this.relType));const f=u.filter(d=>d.variant==="set"&&d.key.type===this.relType&&d.key[this.relDir].toString()===this.target.toString()&&(this.resourceType==null||d.key[fa(this.relDir)].type===this.resourceType));if(f.length===0)return this.notify(this.dependents);this.client.retrieve(f.map(d=>d.key.to)).then(d=>{this.dependents=this.dependents.concat(d),this.notify(this.dependents)})}),this.resourceType=a,this.internal=o,this.target=e,this.dependents=n,this.resourceType!=null&&(this.dependents=this.dependents.filter(u=>u.id.type===this.resourceType)),this.client=c,this.relType=r,this.relDir=i,this.internal.resources.onChange(this.handleResourceChange),this.internal.relationships.onChange(this.handleRelationshipChange)}static async open(e,n,r){const i=await yr.open(n,r);return new _s(e,i,r)}async close(){await this.internal.close()}}const me=t=>s.z.union([s.z.null().transform(()=>[]),t.array()]),gr=s.z.string().uuid(),Ty=s.z.object({key:gr.optional(),subjects:Ut.array().or(Ut),objects:Ut.array().or(Ut),actions:ys.array().or(ys)}),Ys=s.z.object({key:gr,subjects:me(ge),objects:me(ge),actions:me(ys)}),Sy="allow_all";new R({type:Sy,key:""});const zy=s.z.object({keys:gr.array().optional(),subjects:ge.array().optional()}),Ny=s.z.object({policies:me(Ys)}),Iy="/access/policy/retrieve";let Ey=class{constructor(t){l(this,"client"),this.client=t}async retrieve(t){return(await v(this.client,Iy,t,zy,Ny)).policies}};const Ay=s.z.object({policies:Ys.partial({key:!0}).array()}),ky=s.z.object({policies:Ys.array()}),xy=s.z.object({keys:gr.array()}),Cy=s.z.object({}),$y="/access/policy/create",Ry="/access/policy/delete";let jy=class{constructor(t){l(this,"client"),this.client=t}async create(t){const e=Ty.array().parse(T(t)).map(n=>({objects:T(n.objects),actions:T(n.actions),subjects:T(n.subjects)}));return(await v(this.client,$y,{policies:e},Ay,ky)).policies}async delete(t){await v(this.client,Ry,{keys:T(t)},xy,Cy)}},My=class{constructor(t){l(this,"retriever"),l(this,"writer"),this.retriever=new Ey(t),this.writer=new jy(t)}async create(t){const e=Array.isArray(t),n=await this.writer.create(t);return e?n:n[0]}async retrieve(t){const e=Array.isArray(t),n=await this.retriever.retrieve({keys:T(t)});return e?n:n[0]}async retrieveFor(t){const e=T(t).map(n=>new R(n).payload);return await this.retriever.retrieve({subjects:e})}async delete(t){await this.writer.delete(t)}},By=class{constructor(t){l(this,"policy"),this.policy=new My(t)}};const Ve=s.z.number(),on=s.z.object({name:s.z.string(),key:s.z.number(),rate:Kt.z,dataType:C.z,leaseholder:s.z.number(),index:s.z.number(),isIndex:s.z.boolean(),internal:s.z.boolean(),virtual:s.z.boolean(),alias:s.z.string().optional()}),ll=on.extend({key:s.z.number().optional(),leaseholder:s.z.number().optional(),index:s.z.number().optional(),rate:Kt.z.optional().default(0),isIndex:s.z.boolean().optional(),internal:s.z.boolean().optional().default(!1),virtual:s.z.boolean().optional().default(!1)}),cl="channel",Dy=t=>new R({type:cl,key:t.toString()}),Py=new Error("request for lock canceled");var Uy=function(t,e,n,r){function i(a){return a instanceof n?a:new n(function(o){o(a)})}return new(n||(n=Promise))(function(a,o){function c(f){try{h(r.next(f))}catch(d){o(d)}}function u(f){try{h(r.throw(f))}catch(d){o(d)}}function h(f){f.done?a(f.value):i(f.value).then(c,u)}h((r=r.apply(t,e||[])).next())})};class Ly{constructor(e,n=Py){this._value=e,this._cancelError=n,this._queue=[],this._weightedWaiters=[]}acquire(e=1,n=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return new Promise((r,i)=>{const a={resolve:r,reject:i,weight:e,priority:n},o=ul(this._queue,c=>n<=c.priority);o===-1&&e<=this._value?this._dispatchItem(a):this._queue.splice(o+1,0,a)})}runExclusive(e){return Uy(this,arguments,void 0,function*(n,r=1,i=0){const[a,o]=yield this.acquire(r,i);try{return yield n(a)}finally{o()}})}waitForUnlock(e=1,n=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return this._couldLockImmediately(e,n)?Promise.resolve():new Promise(r=>{this._weightedWaiters[e-1]||(this._weightedWaiters[e-1]=[]),_y(this._weightedWaiters[e-1],{resolve:r,priority:n})})}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 n=this._value;this._value-=e.weight,e.resolve([n,this._newReleaser(e.weight)])}_newReleaser(e){let n=!1;return()=>{n||(n=!0,this.release(e))}}_drainUnlockWaiters(){if(this._queue.length===0)for(let e=this._value;e>0;e--){const n=this._weightedWaiters[e-1];n&&(n.forEach(r=>r.resolve()),this._weightedWaiters[e-1]=[])}else{const e=this._queue[0].priority;for(let n=this._value;n>0;n--){const r=this._weightedWaiters[n-1];if(!r)continue;const i=r.findIndex(a=>a.priority<=e);(i===-1?r:r.splice(0,i)).forEach(a=>a.resolve())}}}_couldLockImmediately(e,n){return(this._queue.length===0||this._queue[0].priority<n)&&e<=this._value}}function _y(t,e){const n=ul(t,r=>e.priority<=r.priority);t.splice(n+1,0,e)}function ul(t,e){for(let n=t.length-1;n>=0;n--)if(e(t[n]))return n;return-1}var Yy=function(t,e,n,r){function i(a){return a instanceof n?a:new n(function(o){o(a)})}return new(n||(n=Promise))(function(a,o){function c(f){try{h(r.next(f))}catch(d){o(d)}}function u(f){try{h(r.throw(f))}catch(d){o(d)}}function h(f){f.done?a(f.value):i(f.value).then(c,u)}h((r=r.apply(t,e||[])).next())})};class Fy{constructor(e){this._semaphore=new Ly(1,e)}acquire(){return Yy(this,arguments,void 0,function*(e=0){const[,n]=yield this._semaphore.acquire(1,e);return n})}runExclusive(e,n=0){return this._semaphore.runExclusive(()=>e(),1,n)}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 pr=(t,e,{convertNumericStrings:n=!0}={})=>{const r=!Array.isArray(t);let i=T(t);const a=i[0],o=typeof a;let c;return o==="string"&&n&&!isNaN(parseInt(a))&&"number"in e?(c=e.number,i=i.map(u=>parseInt(u))):c=e[o],{single:r,variant:c,normalized:i,actual:t}},mr=(t,e,n,r)=>{if(r){if(n.length===0)throw new ct(`${t} not found matching ${JSON.stringify(e)}`);if(n.length>1)throw new ut(`Expected one ${t} matching ${JSON.stringify(e)}, but found ${n.length}`)}},qy=s.z.object({leaseholder:s.z.number().optional(),keys:s.z.number().array().optional(),names:s.z.string().array().optional(),search:s.z.string().optional(),rangeKey:s.z.string().optional(),limit:s.z.number().optional(),offset:s.z.number().optional(),dataTypes:C.z.array().optional(),notDataTypes:C.z.array().optional(),virtual:s.z.boolean().optional(),isIndex:s.z.boolean().optional(),internal:s.z.boolean().optional()}),Vy=s.z.object({channels:me(on)}),De=t=>pr(t,{number:"keys",string:"names"}),hl=class dl{constructor(e){l(this,"client"),this.client=e}async search(e,n){return await this.execute({search:e,...n})}async retrieve(e,n){const r=De(e),{variant:i}=r;let{normalized:a}=r;return i==="keys"&&a.indexOf(0)!==-1&&(a=a.filter(o=>o!==0)),a.length===0?[]:await this.execute({[i]:a,...n})}async page(e,n,r){return await this.execute({offset:e,limit:n,...r})}async execute(e){const[n,r]=await this.client.send(dl.ENDPOINT,e,qy,Vy);if(r!=null)throw r;return n.channels}};l(hl,"ENDPOINT","/channel/retrieve");let Fs=hl;class qs{constructor(e){l(this,"cache"),l(this,"namesToKeys"),l(this,"wrapped"),this.cache=new Map,this.namesToKeys=new Map,this.wrapped=e}async search(e,n){return await this.wrapped.search(e,n)}async page(e,n,r){return await this.wrapped.page(e,n,r)}async retrieve(e,n){const{normalized:r}=pr(e,{string:"names",number:"keys"}),i=[],a=[];if(r.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,n);return this.set(o),i.concat(o)}delete(e){const{variant:n,normalized:r}=De(e);n==="names"?r.forEach(i=>{const a=this.namesToKeys.get(i);a!=null&&(a.forEach(o=>this.cache.delete(o)),this.namesToKeys.delete(i))}):r.forEach(i=>{const a=this.cache.get(i);a!=null&&(this.cache.delete(i),this.namesToKeys.delete(a.name))})}rename(e,n){e.forEach((r,i)=>{const a=n[i],o=this.cache.get(r);if(o==null)return;this.cache.delete(r);const c=this.namesToKeys.get(o.name);c!=null&&(c.delete(r),c.size===0&&this.namesToKeys.delete(o.name)),o.name=a,this.cache.set(r,o);const u=this.namesToKeys.get(a);u==null?this.namesToKeys.set(a,new Set([r])):u.add(r)})}set(e){e.forEach(n=>{this.cache.set(n.key,n);const r=this.namesToKeys.get(n.name);r==null?this.namesToKeys.set(n.name,new Set([n.key])):r.add(n.key)})}get(e){if(typeof e=="number"){const i=this.cache.get(e);return i==null?void 0:[i]}const n=this.namesToKeys.get(e);if(n==null)return;const r=[];if(n.forEach(i=>{const a=this.cache.get(i);a!=null&&r.push(a)}),r.length!==0)return r}}class fl{constructor(e,n){l(this,"mu",new Fy),l(this,"requests",new Map),l(this,"wrapped"),l(this,"debouncedRun"),this.wrapped=e,this.debouncedRun=wf(()=>{this.run()},n)}async search(e,n){return await this.wrapped.search(e,n)}async page(e,n,r){return await this.wrapped.page(e,n,r)}async retrieve(e){const{normalized:n,variant:r}=De(e);return r==="names"?await this.wrapped.retrieve(n):await new Promise((i,a)=>{this.mu.runExclusive(()=>{this.requests.set(n,{resolve:i,reject:a}),this.debouncedRun()})})}async run(){await this.mu.runExclusive(async()=>{const e=new Set;this.requests.forEach((n,r)=>r.forEach(i=>e.add(i)));try{const n=await this.wrapped.retrieve(Array.from(e));this.requests.forEach((r,i)=>r.resolve(n.filter(a=>i.includes(a.key))))}catch(n){this.requests.forEach(r=>r.reject(n))}finally{this.requests.clear()}})}}const yl=async(t,e)=>{const{normalized:n}=De(e),r=await t.retrieve(n),i=[];if(n.forEach(a=>{r.find(o=>o.name===a||o.key===a)==null&&i.push(a)}),i.length>0)throw new Oe(`Could not find channels: ${JSON.stringify(i)}`);return r};class gl{constructor({dataType:e,rate:n,name:r,leaseholder:i=0,key:a=0,isIndex:o=!1,index:c=0,internal:u=!1,virtual:h=!1,frameClient:f,alias:d}){l(this,"_frameClient"),l(this,"key"),l(this,"name"),l(this,"rate"),l(this,"dataType"),l(this,"leaseholder"),l(this,"index"),l(this,"isIndex"),l(this,"internal"),l(this,"alias"),l(this,"virtual"),this.key=a,this.name=r,this.rate=new Kt(n??0),this.dataType=new C(e),this.leaseholder=i,this.index=c,this.isIndex=o,this.internal=u,this.alias=d,this.virtual=h,this._frameClient=f??null}get framer(){if(this._frameClient==null)throw new K("cannot read from a channel that has not been created");return this._frameClient}get payload(){return on.parse({key:this.key,name:this.name,rate:this.rate.valueOf(),dataType:this.dataType.valueOf(),leaseholder:this.leaseholder,index:this.index,isIndex:this.isIndex,internal:this.internal})}get ontologyID(){return new R({type:"channel",key:this.key.toString()})}async read(e){return await this.framer.read(e,this.key)}async write(e,n){return await this.framer.write(e,this.key,n)}}const Wy="/channel/retrieve-group",Gy=s.z.object({}),Zy=s.z.object({group:al});let pl=class{constructor(t,e,n,r){l(this,"type","channel"),l(this,"frameClient"),l(this,"client"),l(this,"retriever"),l(this,"writer"),this.frameClient=t,this.retriever=e,this.client=n,this.writer=r}async create(t,e={}){const{retrieveIfNameExists:n=!1}=e,r=!Array.isArray(t);let i=T(t),a=[];if(n){const o=await this.retriever.retrieve(i.map(u=>u.name)),c=new Set(o.map(u=>u.name));i=i.filter(u=>!c.has(u.name)),a=this.sugar(o)}return a=a.concat(this.sugar(await this.writer.create(i))),r?a[0]:a}async retrieve(t,e){const n=!Array.isArray(t),r=this.sugar(await this.retriever.retrieve(t,e));return mr("channel",t,r,n),n?r[0]:r}async search(t,e){return this.sugar(await this.retriever.search(t,e))}async delete(t){const{normalized:e,variant:n}=De(t);return n==="keys"?await this.writer.delete({keys:e}):await this.writer.delete({names:e})}async rename(t,e){return await this.writer.rename(T(t),T(e))}newSearcherWithOptions(t){return{type:this.type,search:async e=>await this.search(e,t),retrieve:async e=>await this.retrieve(e,t),page:async(e,n)=>await this.page(e,n,t)}}async page(t,e,n){return this.sugar(await this.retriever.page(t,e,n))}createDebouncedBatchRetriever(t=10){return new qs(new fl(new Fs(this.client),t))}sugar(t){const{frameClient:e}=this;return t.map(n=>new gl({...n,frameClient:e}))}async retrieveGroup(){const t=await v(this.client,Wy,{},Gy,Zy);return new il(t.group.name,t.group.key)}};const Ky=s.z.object({channels:ll.array()}),Jy=s.z.object({channels:on.array()}),Hy=s.z.object({keys:Ve.array().optional(),names:s.z.string().array().optional()}),Xy=s.z.object({}),Qy=s.z.object({keys:Ve.array(),names:s.z.string().array()}),eg=s.z.object({}),tg="/channel/create",ng="/channel/delete",rg="/channel/rename";let ml=class{constructor(t,e){l(this,"client"),l(this,"cache"),this.client=t,this.cache=e}async create(t){const{channels:e}=await v(this.client,tg,{channels:t},Ky,Jy);return this.cache.set(e),e}async delete(t){await v(this.client,ng,t,Hy,Xy),t.keys!=null&&this.cache.delete(t.keys),t.names!=null&&this.cache.delete(t.names)}async rename(t,e){await v(this.client,rg,{keys:t,names:e},Qy,eg),this.cache.rename(t,e)}};const sg=Object.freeze(Object.defineProperty({__proto__:null,CacheRetriever:qs,Channel:gl,Client:pl,ClusterRetriever:Fs,DebouncedBatchRetriever:fl,ONTOLOGY_TYPE:cl,Writer:ml,analyzeChannelParams:De,keyZ:Ve,newPayload:ll,ontologyID:Dy,payload:on,retrieveRequired:yl},Symbol.toStringTag,{value:"Module"})),ln=s.z.string().uuid(),wr=s.z.object({key:ln,username:s.z.string().min(1),firstName:s.z.string().default(""),lastName:s.z.string().default(""),rootUser:s.z.boolean().default(!0)}),ig=wr.partial({key:!0,firstName:!0,lastName:!0}).omit({rootUser:!0}).extend({password:s.z.string().min(1)}),ag=s.z.object({keys:ln.array().optional(),usernames:s.z.string().array().optional()}),og=s.z.object({users:me(wr)}),lg="/user/retrieve";let cg=class{constructor(t){l(this,"client"),this.client=t}async retrieve(t){return(await v(this.client,lg,t,ag,og)).users}};const ug=s.z.object({users:ig.array()}),hg=s.z.object({users:wr.array()}),dg=s.z.object({key:ln,username:s.z.string().min(1)}),fg=s.z.object({}),yg=s.z.object({key:ln,firstName:s.z.string().optional(),lastName:s.z.string().optional()}),gg=s.z.object({}),pg=s.z.object({keys:ln.array()}),mg=s.z.object({}),wg="/user/create",bg="/user/change-username",vg="/user/rename",Og="/user/delete";let Tg=class{constructor(t){l(this,"client"),this.client=t}async create(t){return(await v(this.client,wg,{users:T(t)},ug,hg)).users}async changeUsername(t,e){await v(this.client,bg,{key:t,username:e},dg,fg)}async rename(t,e,n){await v(this.client,vg,{key:t,firstName:e,lastName:n},yg,gg)}async delete(t){await v(this.client,Og,{keys:T(t)},pg,mg)}},Sg=class{constructor(t){l(this,"reader"),l(this,"writer"),this.writer=new Tg(t),this.reader=new cg(t)}async create(t){const e=Array.isArray(t),n=await this.writer.create(t);return e?n:n[0]}async changeUsername(t,e){await this.writer.changeUsername(t,e)}async retrieve(t){const e=Array.isArray(t),n=await this.reader.retrieve({keys:T(t)});if(e)return n;if(n.length===0)throw new ct(`No user with key ${t} found`);if(n.length>1)throw new ut(`Multiple users found with key ${t}`);return n[0]}async retrieveByName(t){const e=Array.isArray(t),n=await this.reader.retrieve({usernames:T(t)});if(e)return n;if(n.length===0)throw new ct(`No user with username ${t} found`);if(n.length>1)throw new ut(`Multiple users found with username ${t}`);return n[0]}async rename(t,e,n){await this.writer.rename(t,e,n)}async delete(t){await this.writer.delete(t)}};const zg=s.z.object({username:s.z.string(),password:s.z.string()}),Ng=s.z.object({token:s.z.string(),user:wr}),ya="/auth/login",Ig=3,Eg="/auth/change-password",Ag=s.z.object({username:s.z.string(),password:s.z.string(),newPassword:s.z.string().min(1)}),kg=s.z.object({});let xg=class{constructor(t,e){l(this,"token"),l(this,"client"),l(this,"credentials"),l(this,"authenticating"),l(this,"authenticated"),l(this,"user"),l(this,"retryCount"),this.client=t,this.authenticated=!1,this.credentials=e,this.retryCount=0}async changePassword(t){if(!this.authenticated)throw new Error("Not authenticated");await v(this.client,Eg,{username:this.credentials.username,password:this.credentials.password,newPassword:t},Ag,kg),this.credentials.password=t}middleware(){const t=async(e,n)=>{if(!this.authenticated&&!e.target.endsWith(ya)){this.authenticating==null&&(this.authenticating=new Promise((o,c)=>{this.client.send(ya,this.credentials,zg,Ng).then(([u,h])=>{if(h!=null)return o(h);this.token=u==null?void 0:u.token,this.user=u==null?void 0:u.user,this.authenticated=!0,o(null)}).catch(c)}));const a=await this.authenticating;if(a!=null)return[e,a]}e.params.Authorization=`Bearer ${this.token}`;const[r,i]=await n(e);return Ts.matches(i)&&this.retryCount<Ig?(this.authenticated=!1,this.authenticating=void 0,this.retryCount+=1,t(e,n)):(this.retryCount=0,[r,i])};return t}};const Cg=["disconnected","connecting","connected","failed"],$g=s.z.enum(Cg),Rg=s.z.object({status:$g,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()}),jg=s.z.object({clusterKey:s.z.string(),nodeVersion:s.z.string().optional()}),wl={clusterKey:"",status:"disconnected",error:void 0,message:"Disconnected",clientServerCompatible:!1,clientVersion:"0.33.0"},ga=(t,e,n)=>{const r=n?"cluster":"client";return`Synnax cluster node version ${t!=null?t+" ":""}is too ${n?"old":"new"} for client version ${e}.
|
|
47
|
+
`),l(this,"type",Ho.TYPE)}};l(Yn,"TYPE",Fe+"unexpected"),l(Yn,"matches",fe(Yn.TYPE));let be=Yn;const qn=class Xo extends Te{constructor(){super(...arguments),l(this,"type",Xo.TYPE)}};l(qn,"TYPE",Fe+"query"),l(qn,"matches",fe(qn.TYPE));let Oe=qn;const Fn=class Qo extends Oe{constructor(){super(...arguments),l(this,"type",Qo.TYPE)}};l(Fn,"TYPE",Oe.TYPE+".not_found"),l(Fn,"matches",fe(Fn.TYPE));let ct=Fn;const Vn=class el extends Oe{constructor(){super(...arguments),l(this,"type",el.TYPE)}};l(Vn,"TYPE",Oe.TYPE+".multiple_results"),l(Vn,"matches",fe(Vn.TYPE));let ut=Vn;const Wn=class tl extends Te{constructor(e,n){super(e),l(this,"type",tl.TYPE),l(this,"path"),this.path=n}};l(Wn,"TYPE",Fe+"route"),l(Wn,"matches",fe(Wn.TYPE));let ia=Wn;const Gn=class nl extends Te{constructor(){super(...arguments),l(this,"type",nl.TYPE)}};l(Gn,"TYPE",Fe+"control"),l(Gn,"matches",fe(Gn.TYPE));let rr=Gn;const Zn=class rl extends rr{constructor(){super(...arguments),l(this,"type",rl.TYPE)}};l(Zn,"TYPE",rr.TYPE+".unauthorized"),l(Zn,"matches",fe(Zn.TYPE));let aa=Zn;const Lr=class sl extends Te{constructor(){super(...arguments),l(this,"type",sl.TYPE)}};l(Lr,"TYPE",Fe+"contiguity"),l(Lr,"matches",fe(Lr.TYPE));const ry=t=>{if(!t.type.startsWith(Fe))return null;if(t.type.startsWith(K.TYPE)){if(t.type===sa.TYPE){const e=t.data.split(": ");return e.length<2?new K(t.data):new sa(e[0],e[1])}return new K(t.data)}return t.type.startsWith(nr.TYPE)?t.type.startsWith(Ts.TYPE)?new Ts(t.data):new nr(t.data):t.type.startsWith(be.TYPE)?new be(t.data):t.type.startsWith(Oe.TYPE)?t.type.startsWith(ct.TYPE)?new ct(t.data):t.type.startsWith(ut.TYPE)?new ut(t.data):new Oe(t.data):t.type.startsWith(rr.TYPE)?t.type.startsWith(aa.TYPE)?new aa(t.data):new rr(t.data):t.type.startsWith(ia.TYPE)?new ia(t.data,t.data):new be(t.data)},sy=()=>{throw new Error("Not implemented")};bo({encode:sy,decode:ry});const iy=async(t,e)=>{const[n,r]=await e(t);return r==null?[n,r]:r instanceof Xe?[n,new Xe({message:`Cannot reach cluster at ${r.url.host}:${r.url.port}`,url:r.url})]:[n,r]};class il{constructor(e,n){l(this,"key"),l(this,"name"),this.key=n,this.name=e}get ontologyID(){return new R({type:"group",key:this.key})}}const ay=s.z.string().uuid(),al=s.z.object({key:ay,name:s.z.string()}),fr=s.z.union([s.z.literal("label"),s.z.literal("log"),s.z.literal("allow_all"),s.z.literal("builtin"),s.z.literal("cluster"),s.z.literal("channel"),s.z.literal("node"),s.z.literal("group"),s.z.literal("range"),s.z.literal("framer"),s.z.literal("range-alias"),s.z.literal("user"),s.z.literal("workspace"),s.z.literal("schematic"),s.z.literal("lineplot"),s.z.literal("rack"),s.z.literal("device"),s.z.literal("task"),s.z.literal("policy")]),ge=s.z.object({type:fr,key:s.z.string()}),oy=s.z.string().transform(t=>{const[e,n]=t.split(":");return{type:fr.parse(e),key:n??""}}),Ut=s.z.union([oy,ge]),Kn=class ol{constructor(e){if(l(this,"type"),l(this,"key"),e instanceof ol){this.type=e.type,this.key=e.key;return}if(typeof e=="string"){const[n,r]=e.split(":");this.type=n,this.key=r??"";return}this.type=e.type,this.key=e.key}toString(){return`${this.type}:${this.key}`}isType(){return this.key===""}matchesType(e){return this.type===e&&this.isType()}get payload(){return{type:this.type,key:this.key}}};l(Kn,"z",s.z.union([s.z.instanceof(Kn),Ut.transform(t=>new Kn(t))]));let R=Kn;new R({type:"builtin",key:"root"});const ly=s.z.object({type:s.z.number()}),cy=s.z.object({type:fr,fields:s.z.record(ly)}),uy=s.z.object({id:R.z,name:s.z.string(),schema:cy.optional().nullable(),data:s.z.record(s.z.unknown()).optional().nullable()}).transform(t=>({key:t.id.toString(),...t}));s.z.object({from:R.z,type:s.z.string(),to:R.z});const oa=t=>{const[e,n,r]=t.split("->");return{from:new R(e),type:n,to:new R(r)}},hy=s.z.object({group:al}),dy=s.z.object({parent:ge,key:s.z.string().uuid().optional(),name:s.z.string()}),fy=s.z.object({key:s.z.string(),name:s.z.string()}),yy=s.z.object({keys:s.z.array(s.z.string())});var _e;let gy=(_e=class{constructor(t){l(this,"client"),this.client=t}async create(t,e,n){return(await v(this.client,_e.ENDPOINT,{parent:t,name:e,key:n},dy,hy)).group}async rename(t,e){await v(this.client,_e.ENDPOINT_RENAME,{key:t,name:e},fy,s.z.object({}))}async delete(t){await v(this.client,_e.ENDPOINT_DELETE,{keys:t},yy,s.z.object({}))}},l(_e,"ENDPOINT","/ontology/create-group"),l(_e,"ENDPOINT_RENAME","/ontology/rename-group"),l(_e,"ENDPOINT_DELETE","/ontology/delete-group"),_e),py=class{constructor(t){l(this,"creator"),this.creator=new gy(t)}async create(t,e,n){return this.sugar(await this.creator.create(t,e,n))}async rename(t,e){return await this.creator.rename(t,e)}async delete(...t){return await this.creator.delete(t)}sugar(t){return new il(t.name,t.key)}};const _r={ADD_CHILDREN:"/ontology/add-children",REMOVE_CHILDREN:"/ontology/remove-children",MOVE_CHILDREN:"/ontology/move-children"},la=s.z.object({id:ge,children:ge.array()}),my=s.z.object({from:ge,to:ge,children:ge.array()});let wy=class{constructor(t){l(this,"client"),this.client=t}async addChildren(t,...e){await v(this.client,_r.ADD_CHILDREN,{id:new R(t).payload,children:e.map(n=>new R(n).payload)},la,s.z.object({}))}async removeChildren(t,...e){await v(this.client,_r.REMOVE_CHILDREN,{id:new R(t).payload,children:e.map(n=>new R(n).payload)},la,s.z.object({}))}async moveChildren(t,e,...n){const r={from:new R(t).payload,to:new R(e).payload,children:n.map(i=>new R(i).payload)};await v(this.client,_r.MOVE_CHILDREN,r,my,s.z.object({}))}};const by="/ontology/retrieve",vy=s.z.object({ids:ge.array().optional(),children:s.z.boolean().optional(),parents:s.z.boolean().optional(),includeSchema:s.z.boolean().optional(),excludeFieldData:s.z.boolean().optional(),term:s.z.string().optional(),limit:s.z.number().optional(),offset:s.z.number().optional(),types:fr.array().optional()}),Oy=s.z.object({resources:uy.array()}),Yr=t=>T(t).map(e=>new R(e).payload);let Ty=class{constructor(t,e){l(this,"type","ontology"),l(this,"groups"),l(this,"client"),l(this,"writer"),l(this,"framer"),this.client=t,this.writer=new wy(t),this.groups=new py(t),this.framer=e}async search(t,e){return await this.execRetrieve({term:t,...e})}async retrieve(t,e){const n=await this.execRetrieve({ids:Yr(t),...e});if(Array.isArray(t))return n;if(n.length===0)throw new Oe(`No resource found with ID ${t.toString()}`);return n[0]}async page(t,e,n){return await this.execRetrieve({offset:t,limit:e,...n})}async retrieveChildren(t,e){return await this.execRetrieve({ids:Yr(t),children:!0,...e})}async retrieveParents(t,e){return await this.execRetrieve({ids:Yr(t),parents:!0,...e})}async addChildren(t,...e){return await this.writer.addChildren(t,...e)}async removeChildren(t,...e){return await this.writer.removeChildren(t,...e)}async moveChildren(t,e,...n){return await this.writer.moveChildren(t,e,...n)}async openChangeTracker(){return await yr.open(this.framer,this)}async openDependentTracker(t){return await _s.open(t,this.framer,this)}newSearcherWithOptions(t){return{type:this.type,search:e=>this.search(e,t),retrieve:e=>this.retrieve(e,t),page:(e,n)=>this.page(e,n,t)}}async execRetrieve(t){const{resources:e}=await v(this.client,by,t,vy,Oy);return e}};const ca="sy_ontology_resource_set",ua="sy_ontology_resource_delete",ha="sy_ontology_relationship_set",da="sy_ontology_relationship_delete";class yr{constructor(e,n){l(this,"relationships"),l(this,"resources"),l(this,"resourceObs"),l(this,"relationshipObs"),l(this,"streamer"),l(this,"client"),l(this,"closePromise"),this.relationshipObs=new Qe.Observer,this.relationships=this.relationshipObs,this.resourceObs=new Qe.Observer,this.resources=this.resourceObs,this.client=n,this.streamer=e,this.closePromise=this.start()}async close(){this.streamer.close(),await this.closePromise}async start(){for await(const e of this.streamer)await this.update(e)}async update(e){const n=await this.parseResourceSets(e),r=this.parseResourceDeletes(e);n.concat(r).length>0&&this.resourceObs.notify(n.concat(r));const i=this.parseRelationshipSets(e),a=this.parseRelationshipDeletes(e);i.concat(a).length>0&&this.relationshipObs.notify(i.concat(a))}parseRelationshipSets(e){const n=e.get(ha);return n.length===0?[]:Array.from(n.as("string")).map(r=>({variant:"set",key:oa(r),value:void 0}))}parseRelationshipDeletes(e){const n=e.get(da);return n.length===0?[]:Array.from(n.as("string")).map(r=>({variant:"delete",key:oa(r)}))}async parseResourceSets(e){const n=e.get(ca);if(n.length===0)return[];const r=Array.from(n.as("string")).map(i=>new R(i));try{return(await this.client.retrieve(r)).map(i=>({variant:"set",key:i.id,value:i}))}catch(i){if(i instanceof Oe)return[];throw i}}parseResourceDeletes(e){const n=e.get(ua);return n.length===0?[]:Array.from(n.as("string")).map(r=>({variant:"delete",key:new R(r)}))}static async open(e,n){const r=await e.openStreamer([ca,ua,ha,da]);return new yr(r,n)}}const fa=t=>t==="from"?"to":"from";class _s extends Qe.Observer{constructor({target:e,dependents:n,relationshipType:r="parent",relationshipDirection:i="from",resourceType:a},o,c){super(),l(this,"internal"),l(this,"target"),l(this,"relDir"),l(this,"resourceType"),l(this,"dependents"),l(this,"client"),l(this,"relType"),l(this,"handleResourceChange",u=>{this.dependents=this.dependents.map(h=>{const f=u.find(d=>d.key.toString()==h.id.toString());return f==null||f.variant==="delete"?h:f.value}),this.notify(this.dependents)}),l(this,"handleRelationshipChange",u=>{const h=u.filter(d=>d.variant==="delete"&&d.key[this.relDir].toString()===this.target.toString()&&(this.resourceType==null||d.key[fa(this.relDir)].type===this.resourceType));this.dependents=this.dependents.filter(d=>!h.some(k=>k.key.to.toString()===d.id.toString()&&k.key.type===this.relType));const f=u.filter(d=>d.variant==="set"&&d.key.type===this.relType&&d.key[this.relDir].toString()===this.target.toString()&&(this.resourceType==null||d.key[fa(this.relDir)].type===this.resourceType));if(f.length===0)return this.notify(this.dependents);this.client.retrieve(f.map(d=>d.key.to)).then(d=>{this.dependents=this.dependents.concat(d),this.notify(this.dependents)})}),this.resourceType=a,this.internal=o,this.target=e,this.dependents=n,this.resourceType!=null&&(this.dependents=this.dependents.filter(u=>u.id.type===this.resourceType)),this.client=c,this.relType=r,this.relDir=i,this.internal.resources.onChange(this.handleResourceChange),this.internal.relationships.onChange(this.handleRelationshipChange)}static async open(e,n,r){const i=await yr.open(n,r);return new _s(e,i,r)}async close(){await this.internal.close()}}const me=t=>s.z.union([s.z.null().transform(()=>[]),t.array()]),gr=s.z.string().uuid(),Sy=s.z.object({key:gr.optional(),subjects:Ut.array().or(Ut),objects:Ut.array().or(Ut),actions:ys.array().or(ys)}),Ys=s.z.object({key:gr,subjects:me(ge),objects:me(ge),actions:me(ys)}),zy="allow_all";new R({type:zy,key:""});const Ny=s.z.object({keys:gr.array().optional(),subjects:ge.array().optional()}),Iy=s.z.object({policies:me(Ys)}),Ey="/access/policy/retrieve";let Ay=class{constructor(t){l(this,"client"),this.client=t}async retrieve(t){return(await v(this.client,Ey,t,Ny,Iy)).policies}};const ky=s.z.object({policies:Ys.partial({key:!0}).array()}),xy=s.z.object({policies:Ys.array()}),Cy=s.z.object({keys:gr.array()}),$y=s.z.object({}),Ry="/access/policy/create",jy="/access/policy/delete";let By=class{constructor(t){l(this,"client"),this.client=t}async create(t){const e=Sy.array().parse(T(t)).map(n=>({objects:T(n.objects),actions:T(n.actions),subjects:T(n.subjects)}));return(await v(this.client,Ry,{policies:e},ky,xy)).policies}async delete(t){await v(this.client,jy,{keys:T(t)},Cy,$y)}},My=class{constructor(t){l(this,"retriever"),l(this,"writer"),this.retriever=new Ay(t),this.writer=new By(t)}async create(t){const e=Array.isArray(t),n=await this.writer.create(t);return e?n:n[0]}async retrieve(t){const e=Array.isArray(t),n=await this.retriever.retrieve({keys:T(t)});return e?n:n[0]}async retrieveFor(t){const e=T(t).map(n=>new R(n).payload);return await this.retriever.retrieve({subjects:e})}async delete(t){await this.writer.delete(t)}},Dy=class{constructor(t){l(this,"policy"),this.policy=new My(t)}};const Ve=s.z.number(),on=s.z.object({name:s.z.string(),key:s.z.number(),rate:Kt.z,dataType:C.z,leaseholder:s.z.number(),index:s.z.number(),isIndex:s.z.boolean(),internal:s.z.boolean(),virtual:s.z.boolean(),alias:s.z.string().optional()}),ll=on.extend({key:s.z.number().optional(),leaseholder:s.z.number().optional(),index:s.z.number().optional(),rate:Kt.z.optional().default(0),isIndex:s.z.boolean().optional(),internal:s.z.boolean().optional().default(!1),virtual:s.z.boolean().optional().default(!1)}),cl="channel",Py=t=>new R({type:cl,key:t.toString()}),Uy=new Error("request for lock canceled");var Ly=function(t,e,n,r){function i(a){return a instanceof n?a:new n(function(o){o(a)})}return new(n||(n=Promise))(function(a,o){function c(f){try{h(r.next(f))}catch(d){o(d)}}function u(f){try{h(r.throw(f))}catch(d){o(d)}}function h(f){f.done?a(f.value):i(f.value).then(c,u)}h((r=r.apply(t,e||[])).next())})};class _y{constructor(e,n=Uy){this._value=e,this._cancelError=n,this._queue=[],this._weightedWaiters=[]}acquire(e=1,n=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return new Promise((r,i)=>{const a={resolve:r,reject:i,weight:e,priority:n},o=ul(this._queue,c=>n<=c.priority);o===-1&&e<=this._value?this._dispatchItem(a):this._queue.splice(o+1,0,a)})}runExclusive(e){return Ly(this,arguments,void 0,function*(n,r=1,i=0){const[a,o]=yield this.acquire(r,i);try{return yield n(a)}finally{o()}})}waitForUnlock(e=1,n=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return this._couldLockImmediately(e,n)?Promise.resolve():new Promise(r=>{this._weightedWaiters[e-1]||(this._weightedWaiters[e-1]=[]),Yy(this._weightedWaiters[e-1],{resolve:r,priority:n})})}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 n=this._value;this._value-=e.weight,e.resolve([n,this._newReleaser(e.weight)])}_newReleaser(e){let n=!1;return()=>{n||(n=!0,this.release(e))}}_drainUnlockWaiters(){if(this._queue.length===0)for(let e=this._value;e>0;e--){const n=this._weightedWaiters[e-1];n&&(n.forEach(r=>r.resolve()),this._weightedWaiters[e-1]=[])}else{const e=this._queue[0].priority;for(let n=this._value;n>0;n--){const r=this._weightedWaiters[n-1];if(!r)continue;const i=r.findIndex(a=>a.priority<=e);(i===-1?r:r.splice(0,i)).forEach(a=>a.resolve())}}}_couldLockImmediately(e,n){return(this._queue.length===0||this._queue[0].priority<n)&&e<=this._value}}function Yy(t,e){const n=ul(t,r=>e.priority<=r.priority);t.splice(n+1,0,e)}function ul(t,e){for(let n=t.length-1;n>=0;n--)if(e(t[n]))return n;return-1}var qy=function(t,e,n,r){function i(a){return a instanceof n?a:new n(function(o){o(a)})}return new(n||(n=Promise))(function(a,o){function c(f){try{h(r.next(f))}catch(d){o(d)}}function u(f){try{h(r.throw(f))}catch(d){o(d)}}function h(f){f.done?a(f.value):i(f.value).then(c,u)}h((r=r.apply(t,e||[])).next())})};class Fy{constructor(e){this._semaphore=new _y(1,e)}acquire(){return qy(this,arguments,void 0,function*(e=0){const[,n]=yield this._semaphore.acquire(1,e);return n})}runExclusive(e,n=0){return this._semaphore.runExclusive(()=>e(),1,n)}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 pr=(t,e,{convertNumericStrings:n=!0}={})=>{const r=!Array.isArray(t);let i=T(t);const a=i[0],o=typeof a;let c;return o==="string"&&n&&!isNaN(parseInt(a))&&"number"in e?(c=e.number,i=i.map(u=>parseInt(u))):c=e[o],{single:r,variant:c,normalized:i,actual:t}},mr=(t,e,n,r)=>{if(r){if(n.length===0)throw new ct(`${t} not found matching ${JSON.stringify(e)}`);if(n.length>1)throw new ut(`Expected one ${t} matching ${JSON.stringify(e)}, but found ${n.length}`)}},Vy=s.z.object({leaseholder:s.z.number().optional(),keys:s.z.number().array().optional(),names:s.z.string().array().optional(),search:s.z.string().optional(),rangeKey:s.z.string().optional(),limit:s.z.number().optional(),offset:s.z.number().optional(),dataTypes:C.z.array().optional(),notDataTypes:C.z.array().optional(),virtual:s.z.boolean().optional(),isIndex:s.z.boolean().optional(),internal:s.z.boolean().optional()}),Wy=s.z.object({channels:me(on)}),De=t=>pr(t,{number:"keys",string:"names"}),hl=class dl{constructor(e){l(this,"client"),this.client=e}async search(e,n){return await this.execute({search:e,...n})}async retrieve(e,n){const r=De(e),{variant:i}=r;let{normalized:a}=r;return i==="keys"&&a.indexOf(0)!==-1&&(a=a.filter(o=>o!==0)),a.length===0?[]:await this.execute({[i]:a,...n})}async page(e,n,r){return await this.execute({offset:e,limit:n,...r})}async execute(e){const[n,r]=await this.client.send(dl.ENDPOINT,e,Vy,Wy);if(r!=null)throw r;return n.channels}};l(hl,"ENDPOINT","/channel/retrieve");let qs=hl;class Fs{constructor(e){l(this,"cache"),l(this,"namesToKeys"),l(this,"wrapped"),this.cache=new Map,this.namesToKeys=new Map,this.wrapped=e}async search(e,n){return await this.wrapped.search(e,n)}async page(e,n,r){return await this.wrapped.page(e,n,r)}async retrieve(e,n){const{normalized:r}=pr(e,{string:"names",number:"keys"}),i=[],a=[];if(r.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,n);return this.set(o),i.concat(o)}delete(e){const{variant:n,normalized:r}=De(e);n==="names"?r.forEach(i=>{const a=this.namesToKeys.get(i);a!=null&&(a.forEach(o=>this.cache.delete(o)),this.namesToKeys.delete(i))}):r.forEach(i=>{const a=this.cache.get(i);a!=null&&(this.cache.delete(i),this.namesToKeys.delete(a.name))})}rename(e,n){e.forEach((r,i)=>{const a=n[i],o=this.cache.get(r);if(o==null)return;this.cache.delete(r);const c=this.namesToKeys.get(o.name);c!=null&&(c.delete(r),c.size===0&&this.namesToKeys.delete(o.name)),o.name=a,this.cache.set(r,o);const u=this.namesToKeys.get(a);u==null?this.namesToKeys.set(a,new Set([r])):u.add(r)})}set(e){e.forEach(n=>{this.cache.set(n.key,n);const r=this.namesToKeys.get(n.name);r==null?this.namesToKeys.set(n.name,new Set([n.key])):r.add(n.key)})}get(e){if(typeof e=="number"){const i=this.cache.get(e);return i==null?void 0:[i]}const n=this.namesToKeys.get(e);if(n==null)return;const r=[];if(n.forEach(i=>{const a=this.cache.get(i);a!=null&&r.push(a)}),r.length!==0)return r}}class fl{constructor(e,n){l(this,"mu",new Fy),l(this,"requests",new Map),l(this,"wrapped"),l(this,"debouncedRun"),this.wrapped=e,this.debouncedRun=bf(()=>{this.run()},n)}async search(e,n){return await this.wrapped.search(e,n)}async page(e,n,r){return await this.wrapped.page(e,n,r)}async retrieve(e){const{normalized:n,variant:r}=De(e);return r==="names"?await this.wrapped.retrieve(n):await new Promise((i,a)=>{this.mu.runExclusive(()=>{this.requests.set(n,{resolve:i,reject:a}),this.debouncedRun()})})}async run(){await this.mu.runExclusive(async()=>{const e=new Set;this.requests.forEach((n,r)=>r.forEach(i=>e.add(i)));try{const n=await this.wrapped.retrieve(Array.from(e));this.requests.forEach((r,i)=>r.resolve(n.filter(a=>i.includes(a.key))))}catch(n){this.requests.forEach(r=>r.reject(n))}finally{this.requests.clear()}})}}const yl=async(t,e)=>{const{normalized:n}=De(e),r=await t.retrieve(n),i=[];if(n.forEach(a=>{r.find(o=>o.name===a||o.key===a)==null&&i.push(a)}),i.length>0)throw new Oe(`Could not find channels: ${JSON.stringify(i)}`);return r};class gl{constructor({dataType:e,rate:n,name:r,leaseholder:i=0,key:a=0,isIndex:o=!1,index:c=0,internal:u=!1,virtual:h=!1,frameClient:f,alias:d}){l(this,"_frameClient"),l(this,"key"),l(this,"name"),l(this,"rate"),l(this,"dataType"),l(this,"leaseholder"),l(this,"index"),l(this,"isIndex"),l(this,"internal"),l(this,"alias"),l(this,"virtual"),this.key=a,this.name=r,this.rate=new Kt(n??0),this.dataType=new C(e),this.leaseholder=i,this.index=c,this.isIndex=o,this.internal=u,this.alias=d,this.virtual=h,this._frameClient=f??null}get framer(){if(this._frameClient==null)throw new K("cannot read from a channel that has not been created");return this._frameClient}get payload(){return on.parse({key:this.key,name:this.name,rate:this.rate.valueOf(),dataType:this.dataType.valueOf(),leaseholder:this.leaseholder,index:this.index,isIndex:this.isIndex,internal:this.internal})}get ontologyID(){return new R({type:"channel",key:this.key.toString()})}async read(e){return await this.framer.read(e,this.key)}async write(e,n){return await this.framer.write(e,this.key,n)}}const Gy="/channel/retrieve-group",Zy=s.z.object({}),Ky=s.z.object({group:al});let pl=class{constructor(t,e,n,r){l(this,"type","channel"),l(this,"frameClient"),l(this,"client"),l(this,"retriever"),l(this,"writer"),this.frameClient=t,this.retriever=e,this.client=n,this.writer=r}async create(t,e={}){const{retrieveIfNameExists:n=!1}=e,r=!Array.isArray(t);let i=T(t),a=[];if(n){const o=await this.retriever.retrieve(i.map(u=>u.name)),c=new Set(o.map(u=>u.name));i=i.filter(u=>!c.has(u.name)),a=this.sugar(o)}return a=a.concat(this.sugar(await this.writer.create(i))),r?a[0]:a}async retrieve(t,e){const n=!Array.isArray(t),r=this.sugar(await this.retriever.retrieve(t,e));return mr("channel",t,r,n),n?r[0]:r}async search(t,e){return this.sugar(await this.retriever.search(t,e))}async delete(t){const{normalized:e,variant:n}=De(t);return n==="keys"?await this.writer.delete({keys:e}):await this.writer.delete({names:e})}async rename(t,e){return await this.writer.rename(T(t),T(e))}newSearcherWithOptions(t){return{type:this.type,search:async e=>await this.search(e,t),retrieve:async e=>await this.retrieve(e,t),page:async(e,n)=>await this.page(e,n,t)}}async page(t,e,n){return this.sugar(await this.retriever.page(t,e,n))}createDebouncedBatchRetriever(t=10){return new Fs(new fl(new qs(this.client),t))}sugar(t){const{frameClient:e}=this;return t.map(n=>new gl({...n,frameClient:e}))}async retrieveGroup(){const t=await v(this.client,Gy,{},Zy,Ky);return new il(t.group.name,t.group.key)}};const Jy=s.z.object({channels:ll.array()}),Hy=s.z.object({channels:on.array()}),Xy=s.z.object({keys:Ve.array().optional(),names:s.z.string().array().optional()}),Qy=s.z.object({}),eg=s.z.object({keys:Ve.array(),names:s.z.string().array()}),tg=s.z.object({}),ng="/channel/create",rg="/channel/delete",sg="/channel/rename";let ml=class{constructor(t,e){l(this,"client"),l(this,"cache"),this.client=t,this.cache=e}async create(t){const{channels:e}=await v(this.client,ng,{channels:t},Jy,Hy);return this.cache.set(e),e}async delete(t){await v(this.client,rg,t,Xy,Qy),t.keys!=null&&this.cache.delete(t.keys),t.names!=null&&this.cache.delete(t.names)}async rename(t,e){await v(this.client,sg,{keys:t,names:e},eg,tg),this.cache.rename(t,e)}};const ig=Object.freeze(Object.defineProperty({__proto__:null,CacheRetriever:Fs,Channel:gl,Client:pl,ClusterRetriever:qs,DebouncedBatchRetriever:fl,ONTOLOGY_TYPE:cl,Writer:ml,analyzeChannelParams:De,keyZ:Ve,newPayload:ll,ontologyID:Py,payload:on,retrieveRequired:yl},Symbol.toStringTag,{value:"Module"})),ln=s.z.string().uuid(),wr=s.z.object({key:ln,username:s.z.string().min(1),firstName:s.z.string().default(""),lastName:s.z.string().default(""),rootUser:s.z.boolean().default(!0)}),ag=wr.partial({key:!0,firstName:!0,lastName:!0}).omit({rootUser:!0}).extend({password:s.z.string().min(1)}),og=s.z.object({keys:ln.array().optional(),usernames:s.z.string().array().optional()}),lg=s.z.object({users:me(wr)}),cg="/user/retrieve";let ug=class{constructor(t){l(this,"client"),this.client=t}async retrieve(t){return(await v(this.client,cg,t,og,lg)).users}};const hg=s.z.object({users:ag.array()}),dg=s.z.object({users:wr.array()}),fg=s.z.object({key:ln,username:s.z.string().min(1)}),yg=s.z.object({}),gg=s.z.object({key:ln,firstName:s.z.string().optional(),lastName:s.z.string().optional()}),pg=s.z.object({}),mg=s.z.object({keys:ln.array()}),wg=s.z.object({}),bg="/user/create",vg="/user/change-username",Og="/user/rename",Tg="/user/delete";let Sg=class{constructor(t){l(this,"client"),this.client=t}async create(t){return(await v(this.client,bg,{users:T(t)},hg,dg)).users}async changeUsername(t,e){await v(this.client,vg,{key:t,username:e},fg,yg)}async rename(t,e,n){await v(this.client,Og,{key:t,firstName:e,lastName:n},gg,pg)}async delete(t){await v(this.client,Tg,{keys:T(t)},mg,wg)}},zg=class{constructor(t){l(this,"reader"),l(this,"writer"),this.writer=new Sg(t),this.reader=new ug(t)}async create(t){const e=Array.isArray(t),n=await this.writer.create(t);return e?n:n[0]}async changeUsername(t,e){await this.writer.changeUsername(t,e)}async retrieve(t){const e=Array.isArray(t),n=await this.reader.retrieve({keys:T(t)});if(e)return n;if(n.length===0)throw new ct(`No user with key ${t} found`);if(n.length>1)throw new ut(`Multiple users found with key ${t}`);return n[0]}async retrieveByName(t){const e=Array.isArray(t),n=await this.reader.retrieve({usernames:T(t)});if(e)return n;if(n.length===0)throw new ct(`No user with username ${t} found`);if(n.length>1)throw new ut(`Multiple users found with username ${t}`);return n[0]}async rename(t,e,n){await this.writer.rename(t,e,n)}async delete(t){await this.writer.delete(t)}};const Ng=s.z.object({username:s.z.string(),password:s.z.string()}),Ig=s.z.object({token:s.z.string(),user:wr}),ya="/auth/login",Eg=3,Ag="/auth/change-password",kg=s.z.object({username:s.z.string(),password:s.z.string(),newPassword:s.z.string().min(1)}),xg=s.z.object({});let Cg=class{constructor(t,e){l(this,"token"),l(this,"client"),l(this,"credentials"),l(this,"authenticating"),l(this,"authenticated"),l(this,"user"),l(this,"retryCount"),this.client=t,this.authenticated=!1,this.credentials=e,this.retryCount=0}async changePassword(t){if(!this.authenticated)throw new Error("Not authenticated");await v(this.client,Ag,{username:this.credentials.username,password:this.credentials.password,newPassword:t},kg,xg),this.credentials.password=t}middleware(){const t=async(e,n)=>{if(!this.authenticated&&!e.target.endsWith(ya)){this.authenticating==null&&(this.authenticating=new Promise((o,c)=>{this.client.send(ya,this.credentials,Ng,Ig).then(([u,h])=>{if(h!=null)return o(h);this.token=u==null?void 0:u.token,this.user=u==null?void 0:u.user,this.authenticated=!0,o(null)}).catch(c)}));const a=await this.authenticating;if(a!=null)return[e,a]}e.params.Authorization=`Bearer ${this.token}`;const[r,i]=await n(e);return Ts.matches(i)&&this.retryCount<Eg?(this.authenticated=!1,this.authenticating=void 0,this.retryCount+=1,t(e,n)):(this.retryCount=0,[r,i])};return t}};const $g=["disconnected","connecting","connected","failed"],Rg=s.z.enum($g),jg=s.z.object({status:Rg,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()}),Bg=s.z.object({clusterKey:s.z.string(),nodeVersion:s.z.string().optional()}),wl={clusterKey:"",status:"disconnected",error:void 0,message:"Disconnected",clientServerCompatible:!1,clientVersion:"0.33.0"},ga=(t,e,n)=>{const r=n?"cluster":"client";return`Synnax cluster node version ${t!=null?t+" ":""}is too ${n?"old":"new"} for client version ${e}.
|
|
48
48
|
This may cause compatibility issues. We recommend updating the ${r}. For more information, see
|
|
49
|
-
https://docs.synnaxlabs.com/reference/typescript-client/troubleshooting#old-${r}-version`},Jn=class bl{constructor(e,n=$.seconds(30),r,i){l(this,"_state"),l(this,"pollFrequency",$.seconds(30)),l(this,"client"),l(this,"name"),l(this,"interval"),l(this,"clientVersion"),l(this,"onChangeHandlers",[]),l(this,"versionWarned",!1),this._state={...wl},this.client=e,this.pollFrequency=n,this.clientVersion=r,this.name=i,this.check(),this.startChecking()}stopChecking(){this.interval!=null&&clearInterval(this.interval)}async check(){var e;const n=this._state.status;try{const[r,i]=await this.client.send(bl.ENDPOINT,{},s.z.object({}),
|
|
50
|
-
Got ${n.length} ${r}s and ${e.length} series.`)};let ve=class rt{constructor(e=[],n=[]){if(l(this,"columns",[]),l(this,"series",[]),e instanceof rt){this.columns=e.columns,this.series=e.series;return}if(e instanceof Map){e.forEach((r,i)=>this.push(i,...T(r)));return}if(typeof e=="object"&&!Array.isArray(e)){if("keys"in e&&"series"in e){const r=e;r.series??(r.series=[]),r.keys??(r.keys=[]);const i=r.series.map(a=>
|
|
49
|
+
https://docs.synnaxlabs.com/reference/typescript-client/troubleshooting#old-${r}-version`},Jn=class bl{constructor(e,n=$.seconds(30),r,i){l(this,"_state"),l(this,"pollFrequency",$.seconds(30)),l(this,"client"),l(this,"name"),l(this,"interval"),l(this,"clientVersion"),l(this,"onChangeHandlers",[]),l(this,"versionWarned",!1),this._state={...wl},this.client=e,this.pollFrequency=n,this.clientVersion=r,this.name=i,this.check(),this.startChecking()}stopChecking(){this.interval!=null&&clearInterval(this.interval)}async check(){var e;const n=this._state.status;try{const[r,i]=await this.client.send(bl.ENDPOINT,{},s.z.object({}),Bg);if(i!=null)throw i;const a=r.nodeVersion,o=this.clientVersion,c=this.versionWarned;a==null?(this._state.clientServerCompatible=!1,c||(console.warn(ga(null,o,!0)),this.versionWarned=!0)):ra.versionsEqual(o,a,{checkMajor:!0,checkMinor:!0,checkPatch:!1})?this._state.clientServerCompatible=!0:(this._state.clientServerCompatible=!1,c||(console.warn(ga(a,o,ra.semVerNewer(o,a))),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=(e=this.state.error)==null?void 0:e.message}return this.onChangeHandlers.length>0&&n!==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)}};l(Jn,"ENDPOINT","/connectivity/check"),l(Jn,"DEFAULT",wl),l(Jn,"connectionStateZ",jg);let vl=Jn;const Mg=s.z.object({keys:Ve.array().optional(),bounds:se.z,names:s.z.string().array().optional()}),Dg=s.z.object({}),Pg="/frame/delete";class Ug{constructor(e){l(this,"client"),this.client=e}async delete(e){await v(this.client,Pg,e,Mg,Dg)}}const pa=t=>{const e=T(t);return e.length===0?null:typeof e[0]=="number"||!isNaN(parseInt(e[0]))?"key":"name"},ma=(t,e)=>{const n=T(t);if(n.length===e.length)return;const r=pa(t);throw pa===null?new K("[Frame] - channel keys or names must be provided when constructing a frame."):new K(`[Frame] - ${r}s and series must be the same length.
|
|
50
|
+
Got ${n.length} ${r}s and ${e.length} series.`)};let ve=class rt{constructor(e=[],n=[]){if(l(this,"columns",[]),l(this,"series",[]),e instanceof rt){this.columns=e.columns,this.series=e.series;return}if(e instanceof Map){e.forEach((r,i)=>this.push(i,...T(r)));return}if(typeof e=="object"&&!Array.isArray(e)){if("keys"in e&&"series"in e){const r=e;r.series??(r.series=[]),r.keys??(r.keys=[]);const i=r.series.map(a=>Lg(a));ma(r.keys,i),r.keys.forEach((a,o)=>this.push(a,i[o]))}else Object.entries(e).forEach(([r,i])=>{const a=parseInt(r);if(isNaN(a))this.push(r,...T(i));else return this.push(a,...T(i))});return}if(Array.isArray(e)||["string","number"].includes(typeof e)){const r=T(n),i=T(e);ma(i,r),r.forEach((a,o)=>this.push(i[o],a));return}throw new K(`[Frame] - invalid frame construction parameters. data parameter ust be a frame
|
|
51
51
|
payload, a list of lazy series, a lazy array, a map, or a record keyed by channel
|
|
52
|
-
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 be("colType is not key");return this.columns??[]}get uniqueKeys(){return Ki(this.keys)}get names(){if(this.colType==="key")throw new be("colType is not name");return this.columns??[]}get uniqueNames(){return Ki(this.names)}get uniqueColumns(){return this.colType==="key"?this.uniqueKeys:this.uniqueNames}toPayload(){return{series:this.series.map(e=>
|
|
52
|
+
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 be("colType is not key");return this.columns??[]}get uniqueKeys(){return Ki(this.keys)}get names(){if(this.colType==="key")throw new be("colType is not name");return this.columns??[]}get uniqueNames(){return Ki(this.names)}get uniqueColumns(){return this.colType==="key"?this.uniqueKeys:this.uniqueNames}toPayload(){return{series:this.series.map(e=>_g(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(n=>n.equals(e[0]))}timeRange(e){if(e==null){if(this.columns.length===0)return se.ZERO;const r=x.min(...this.series.map(a=>a.timeRange.start)),i=x.max(...this.series.map(a=>a.timeRange.end));return new se(r,i)}const n=this.get(e);return n==null?se.ZERO:n.timeRange}latest(){return this.at(-1)}get timeRanges(){return this.uniqueColumns.map(e=>this.timeRange(e))}get(e){return Array.isArray(e)?this.filter(n=>e.includes(n)):new Bf(this.series.filter((n,r)=>this.columns[r]===e))}push(e,...n){if(e instanceof rt){if(this.colType!==null&&e.colType!==this.colType)throw new K("keyVariant must match");this.series.push(...e.series),this.columns.push(...e.columns)}else{if(this.series.push(...n),typeof e=="string"&&this.colType==="key")throw new K("keyVariant must match");if(typeof e!="string"&&this.colType==="name")throw new K("keyVariant must match");this.columns.push(...Array.from({length:n.length},()=>e))}}concat(e){return new rt([...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 n=new rt;return this.forEach((r,i,a)=>n.push(...e(r,i,a))),n}forEach(e){this.columns.forEach((n,r)=>{const i=this.series[r];e(n,i,r)})}at(e,n=!1){const r={};return this.uniqueColumns.forEach(i=>{r[i]=this.get(i).at(e,n)}),r}filter(e){const n=new rt;return this.columns.forEach((r,i)=>{const a=this.series[i];e(r,a,i)&&n.push(r,a)}),n}get byteLength(){return new ot(this.series.reduce((e,n)=>e.add(n.byteLength),ot.ZERO))}get length(){return this.series.reduce((e,n)=>e+n.length,0)}};const Vs=s.z.object({keys:s.z.union([s.z.null().transform(()=>[]),s.z.number().array().optional().default([])]),series:s.z.union([s.z.null().transform(()=>[]),Ke.crudeZ.array().optional().default([])])}),Lg=t=>{const{dataType:e,data:n,timeRange:r,alignment:i}=t;return new Ke({data:n,dataType:e,timeRange:r,glBufferUsage:"static",alignment:i})},_g=t=>({timeRange:t._timeRange,dataType:t.dataType,data:new Uint8Array(t.data.buffer),alignment:t.alignment});class br{constructor(e){l(this,"adapter"),l(this,"retriever"),l(this,"keys"),this.retriever=e,this.adapter=null,this.keys=[]}static async open(e,n){const r=new br(e);return await r.update(n),r}async update(e){const{variant:n,normalized:r}=De(e);if(n==="keys"){this.adapter=null,this.keys=r;return}const i=await this.retriever.retrieve(r),a=new Map;this.adapter=a,r.forEach(o=>{const c=i.find(u=>u.name===o);if(c==null)throw new Error(`Channel ${o} not found`);a.set(c.key,c.name)}),this.keys=Array.from(this.adapter.keys())}adapt(e){if(this.adapter==null)return e;const n=this.adapter;return e.map((r,i)=>{if(typeof r=="number"){const a=n.get(r);if(a==null)throw new Error(`Channel ${r} not found`);return[a,i]}return[r,i]})}}class Ws{constructor(e){l(this,"adapter"),l(this,"retriever"),l(this,"keys"),this.retriever=e,this.adapter=null,this.keys=[]}static async open(e,n){const r=new Ws(e);return await r.update(n),r}async adaptObjectKeys(e){const n={};for(const[r,i]of Object.entries(e))n[await this.adaptToKey(r)]=i;return n}async update(e){const n=await yl(this.retriever,e);this.adapter=new Map(n.map(r=>[r.name,r.key])),this.keys=n.map(r=>r.key)}async fetchChannel(e){const n=await this.retriever.retrieve(e);if(n.length===0)throw new Error(`Channel ${e} not found`);return n[0]}async adaptToKey(e){return typeof e=="number"?e:(await this.fetchChannel(e)).key}async adapt(e,n){if(typeof e=="string"||typeof e=="number"){if(n==null)throw new K(`
|
|
53
53
|
Received a single channel name or key but no series.
|
|
54
54
|
`);if(Array.isArray(n)){if(n.some(u=>u instanceof Ke||Array.isArray(u)))throw new K(`
|
|
55
55
|
Received a single channel name or key but multiple series.
|
|
@@ -62,6 +62,6 @@
|
|
|
62
62
|
`);const f=new Ke({data:n[u],dataType:h.dataType});o.push(h.key),c.push(f)}return new ve(o,c)}if(e instanceof ve||e instanceof Map){const o=new ve(e);if(this.adapter==null)return o;let c=[];return c=o.columns.map(u=>{var h;const f=typeof u=="string"?(h=this.adapter)==null?void 0:h.get(u):u;if(f==null)throw new K(`
|
|
63
63
|
Channel ${u} was not provided in the list of channels when opening the writer
|
|
64
64
|
`);return f}),new ve(c,o.series)}const r=[],i=[],a=Object.entries(e);for(let o=0;o<a.length;o++){const[c,u]=a[o],h=await this.fetchChannel(c),f=new Ke({data:u,dataType:h.dataType});r.push(h.key),i.push(f)}return new ve(r,i)}}class Gs{constructor(e,n){l(this,"name"),l(this,"stream"),this.stream=n,this.name=e}async receive(){const[e,n]=await this.stream.receive();if(n!=null)throw n;return e}received(){return this.stream.received()}async closeAndAck(){for(this.stream.closeSend();;){const[e,n]=await this.stream.receive();if(e!=null&&console.warn(`${this.name} received unexpected response on closure.
|
|
65
|
-
Please report this error to the Synnax team. ${JSON.stringify(e)}`),n!=null){if(Fe.matches(n))return;throw n}}}closeSend(){this.stream.closeSend()}send(e){const n=this.stream.send(e);if(n!=null)throw n}}const wa=new $(-1);var Zs=(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))(Zs||{}),Ol=(t=>(t[t.None=0]="None",t[t.Ack=1]="Ack",t[t.Data=2]="Data",t))(Ol||{});const _g=s.z.object({command:s.z.nativeEnum(Zs),span:$.z.optional(),bounds:se.z.optional(),stamp:x.z.optional(),keys:s.z.number().array().optional(),chunkSize:s.z.number().optional()}),Yg=s.z.object({variant:s.z.nativeEnum(Ol),ack:s.z.boolean(),command:s.z.nativeEnum(Zs),error:sn.optional().nullable(),frame:Vs.optional()}),Tl=class Ss{constructor(e,n){l(this,"stream"),l(this,"adapter"),l(this,"value"),this.stream=new Gs("Iterator",e),this.value=new ve,this.adapter=n}static async _open(e,n,r,i,a={}){const o=await br.open(r,n),c=await i.stream(Ss.ENDPOINT,_g,Yg),u=new Ss(c,o);return await u.execute({command:0,keys:o.keys,bounds:new se(e),chunkSize:a.chunkSize??1e5}),u}async next(e=wa){return await this.execute({command:1,span:new $(e)})}async prev(e=wa){return await this.execute({command:2,span:new $(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 x(e)})}async seekGE(e){return await this.execute({command:6,stamp:new x(e)})}async valid(){return await this.execute({command:7})}async close(){await this.stream.closeAndAck()}[Symbol.asyncIterator](){return new qg(this)}async execute(e){for(this.stream.send(e),this.value=new ve;;){const n=await this.stream.receive();if(n.variant===1)return n.ack;this.value.push(this.adapter.adapt(new ve(n.frame)))}}};l(Tl,"ENDPOINT","/frame/iterate");let Fg=Tl;class qg{constructor(e){l(this,"iter"),l(this,"open",!1),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 Vg=s.z.object({keys:s.z.number().array(),downsampleFactor:s.z.number()}),Wg=s.z.object({frame:Vs,error:sn.optional().nullable()}),Gg="/frame/stream";class Ks{constructor(e,n){l(this,"stream"),l(this,"adapter"),l(this,"downsampleFactor"),this.stream=new Gs("Streamer",e),this.adapter=n,this.downsampleFactor=1}get keys(){return this.adapter.keys}static async _open(e,n,{channels:r,downsampleFactor:i}){const a=await br.open(e,r),o=await n.stream(Gg,Vg,Wg),c=new Ks(o,a);o.send({keys:a.keys,downsampleFactor:i??1});const[,u]=await o.receive();if(u!=null)throw u;return c}async next(){try{return{done:!1,value:await this.read()}}catch(e){if(Fe.matches(e))return{done:!0,value:void 0};throw e}}async read(){return this.adapter.adapt(new ve((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 vr extends Qe.Observer{constructor(e,n){super(n),l(this,"streamer"),l(this,"closePromise"),this.streamer=e,this.closePromise=this.stream()}async close(){this.streamer.close(),await this.closePromise}async stream(){for await(const e of this.streamer)this.notify(e)}}var Js=(t=>(t[t.Open=0]="Open",t[t.Write=1]="Write",t[t.Commit=2]="Commit",t[t.Error=3]="Error",t[t.SetAuthority=4]="SetAuthority",t))(Js||{}),Jt=(t=>(t[t.PersistStream=1]="PersistStream",t[t.Persist=2]="Persist",t[t.Stream=3]="Stream",t))(Jt||{});const Zg=t=>{switch(t){case"persist":return 2;case"stream":return 3;case"persistStream":return 1;default:if(typeof t=="number"&&t in Jt)return t;throw new Error(`invalid writer mode: ${t}`)}};new $(-1);const Kg=s.z.object({start:x.z.optional(),controlSubject:lt.subjectZ.optional(),keys:s.z.number().array().optional(),authorities:lt.Authority.z.array().optional(),mode:s.z.nativeEnum(Jt).optional(),errOnUnauthorized:s.z.boolean().optional(),enableAutoCommit:s.z.boolean().optional(),autoIndexPersistInterval:$.z.optional()}),Jg=s.z.object({command:s.z.nativeEnum(Js),config:Kg.optional(),frame:Vs.optional()}),Hg=s.z.object({ack:s.z.boolean(),command:s.z.nativeEnum(Js),error:sn.optional().nullable()});var vt;let Xg=(vt=class{constructor(t,e){l(this,"stream"),l(this,"adapter"),this.stream=new Gs("Writer",t),this.adapter=e}static async _open(t,e,{channels:n,start:r=x.now(),authorities:i=lt.Authority.Absolute,controlSubject:a,mode:o=1,errOnUnauthorized:c=!1,enableAutoCommit:u=!1,autoIndexPersistInterval:h=$.SECOND}){const f=await Ws.open(t,n),d=await e.stream(vt.ENDPOINT,Jg,Hg),k=new vt(d,f);return await k.execute({command:0,config:{start:new x(r),keys:f.keys,controlSubject:a,authorities:T(i),mode:Zg(o),errOnUnauthorized:c,enableAutoCommit:u,autoIndexPersistInterval:h}}),k}async write(t,e){const n=await this.adapter.adapt(t,e);return this.stream.send({command:1,frame:n.toPayload()}),!0}async setAuthority(t,e){let n={keys:[],authorities:[]};if(typeof t=="number"&&e==null)n={keys:[],authorities:[t]};else{let r;typeof t=="string"||typeof t=="number"?r={[t]:e}:r=t,r=await this.adapter.adaptObjectKeys(r),n={keys:Object.keys(r).map(i=>Number(i)),authorities:Object.values(r)}}return(await this.execute({command:4,config:n})).ack}async commit(){return this.errorAccumulated?!1:(await this.execute({command:2})).ack}async error(){this.stream.send({command:3});const t=await this.execute({command:3});return t.error!=null?Ps(t.error):null}async close(){await this.stream.closeAndAck()}async execute(t){for(this.stream.send(t);;){const e=await this.stream.receive();if(e.command===t.command)return e;console.warn("writer received unexpected response",e)}}get errorAccumulated(){return this.stream.received()}},l(vt,"ENDPOINT","/frame/write"),vt),Qg=class{constructor(t,e,n){l(this,"streamClient"),l(this,"retriever"),l(this,"deleter"),this.streamClient=t,this.retriever=n,this.deleter=new Pg(e)}async openIterator(t,e,n){return await Fg._open(t,e,this.retriever,this.streamClient,n)}async openWriter(t){return(Array.isArray(t)||typeof t!="object")&&(t={channels:t}),await Xg._open(this.retriever,this.streamClient,t)}async openStreamer(t){return(Array.isArray(t)||typeof t!="object")&&(t={channels:t,downsampleFactor:1}),await Ks._open(this.retriever,this.streamClient,t)}async write(t,e,n){if(n==null){const i=e,a=await this.openWriter({start:t,channels:Object.keys(i),mode:Jt.Persist});try{await a.write(i),await a.commit()}finally{await a.close()}return}const r=await this.openWriter({start:t,channels:e,mode:Jt.Persist,errOnUnauthorized:!0,enableAutoCommit:!0,autoIndexPersistInterval:$.MAX});try{await r.write(e,n)}finally{await r.close()}}async read(t,e){const{single:n}=De(e),r=await this.readFrame(t,e);return n?r.get(e):r}async readFrame(t,e){const n=await this.openIterator(t,e),r=new ve;try{for await(const i of n)r.push(i)}finally{await n.close()}return r}async delete(t,e){const{normalized:n,variant:r}=De(t);return r==="keys"?await this.deleter.delete({keys:n,bounds:e}):await this.deleter.delete({names:n,bounds:e})}};const ep=lt.Authority,tp=lt.stateZ(s.z.number()),np=t=>{var e,n;return t.to==null?`${(e=t.from)==null?void 0:e.resource} - ${(n=t.from)==null?void 0:n.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()})`};class Sl extends vr{constructor(e){super(e,n=>{const r=this.codec.decode(n.series[0].data);return this.merge(r),[r.transfers,!0]}),l(this,"states"),l(this,"codec"),this.states=new Map,this.codec=new dt.JSONCodec}subjects(){const e=new Map;return this.states.forEach(n=>e.set(n.subject.key,n.subject)),Array.from(e.values())}merge(e){e.transfers.forEach(n=>{n.from==null&&n.to==null&&console.warn("Invalid transfer: ",n),n.to==null?this.states.delete(n.from.resource):this.states.set(n.to.resource,n.to)})}}const rp="sy_node_1_control";let zl=class{constructor(t){l(this,"framer"),this.framer=t}async openStateTracker(){const t=await this.framer.openStreamer(rp);return new Sl(t)}};const sp=Object.freeze(Object.defineProperty({__proto__:null,Authority:ep,Client:zl,StateTracker:Sl,stateZ:tp,transferString:np},Symbol.toStringTag,{value:"Module"}));let ip=class{constructor(t,e,n){l(this,"tasks"),l(this,"racks"),l(this,"devices"),this.tasks=t,this.racks=e,this.devices=n}};const cn=s.z.number(),Hs=s.z.object({key:cn,name:s.z.string()}),ap=Hs.partial({key:!0}),Xs=s.z.string(),Or=s.z.object({key:Xs,rack:cn,name:s.z.string(),make:s.z.string(),model:s.z.string(),location:s.z.string(),configured:s.z.boolean().optional(),properties:s.z.record(s.z.unknown()).or(s.z.string().transform(t=>t===""?{}:dt.JSON_CODEC.decodeString(t)))}),op=Or.extend({properties:s.z.unknown().transform(t=>dt.JSON_CODEC.encodeString(t))}),yt=async(t,e,n,r)=>{const i=await t.openStreamer([e,n]),a=o=>{const c=[];return n!=null&&c.push(...o.get(n).series.flatMap(u=>r("delete",u))),e!=null&&c.push(...o.get(e).series.flatMap(u=>r("set",u))),[c,c.length>0]};return new vr(i,a)},lp="sy_device_set",cp="sy_device_delete",Fr="/hardware/device/retrieve",up="/hardware/device/create",hp="/hardware/device/delete",dp=s.z.object({devices:op.array()}),fp=s.z.object({devices:Or.array()}),yp=s.z.object({keys:Xs.array()}),gp=s.z.object({}),qr=s.z.object({search:s.z.string().optional(),limit:s.z.number().optional(),offset:s.z.number().optional(),keys:Xs.array().optional(),names:s.z.string().array().optional(),makes:s.z.string().array().optional()}),Vr=s.z.object({devices:me(Or)});let pp=class{constructor(t,e){l(this,"type","device"),l(this,"client"),l(this,"frameClient"),this.client=t,this.frameClient=e}async retrieve(t,e){const n=!Array.isArray(t),r=await v(this.client,Fr,{keys:T(t),...e},qr,Vr);return mr("Device",t,r.devices,n),n?r.devices[0]:r.devices}async search(t,e){return(await v(this.client,Fr,{search:t,...e},qr,Vr)).devices}async page(t,e,n){return(await v(this.client,Fr,{offset:t,limit:e,...n},qr,Vr)).devices}async create(t){const e=!Array.isArray(t),n=await v(this.client,up,{devices:T(t)},dp,fp);return e?n.devices[0]:n.devices}async delete(t){await v(this.client,hp,{keys:T(t)},yp,gp)}async openDeviceTracker(){return await yt(this.frameClient,lp,cp,mp)}newSearcherWithOptions(t){return{type:this.type,search:async e=>await this.search(e,t),retrieve:async e=>await this.retrieve(e,t),page:async(e,n)=>await this.page(e,n,t)}}};const mp=(t,e)=>t==="delete"?e.toStrings().map(n=>({variant:t,key:n,value:void 0})):e.parseJSON(Or).map(n=>({variant:t,key:n.key,value:n})),Wr="/hardware/rack/retrieve",wp="/hardware/rack/create",bp="/hardware/rack/delete",Gr=s.z.object({keys:cn.array().optional(),names:s.z.string().array().optional(),search:s.z.string().optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),Zr=s.z.object({racks:me(Hs)}),vp=s.z.object({racks:ap.array()}),Op=s.z.object({racks:Hs.array()}),Tp=s.z.object({keys:cn.array()}),Sp=s.z.object({});let zp=class{constructor(t,e,n){l(this,"type","rack"),l(this,"client"),l(this,"frameClient"),l(this,"tasks"),this.client=t,this.frameClient=e,this.tasks=n}async delete(t){await v(this.client,bp,{keys:T(t)},Tp,Sp)}async create(t){const e=!Array.isArray(t),n=await v(this.client,wp,{racks:T(t)},vp,Op),r=this.sugar(n.racks);return e?r[0]:r}async search(t){const e=await v(this.client,Wr,{search:t},Gr,Zr);return this.sugar(e.racks)}async page(t,e){const n=await v(this.client,Wr,{offset:t,limit:e},Gr,Zr);return this.sugar(n.racks)}async retrieve(t){const{variant:e,normalized:n,single:r}=pr(t,{string:"names",number:"keys"}),i=await v(this.client,Wr,{[e]:n},Gr,Zr),a=this.sugar(i.racks);return mr("Rack",t,a,r),r?a[0]:a}sugar(t){return t.map(({key:e,name:n})=>new Np(e,n,this.tasks))}};class Np{constructor(e,n,r){l(this,"key"),l(this,"name"),l(this,"tasks"),this.key=e,this.name=n,this.tasks=r}async listTasks(){return await this.tasks.retrieve(this.key)}async retrieveTaskByName(e){return await this.tasks.retrieveByName(e,this.key)}async createTask(e){return e.key=((BigInt(this.key)<<32n)+(BigInt(e.key??0)&0xffffffffn)).toString(),await this.tasks.create(e)}async deleteTask(e){await this.tasks.delete([e])}}const gt=s.z.union([s.z.string(),s.z.bigint().transform(t=>t.toString()),s.z.number().transform(t=>t.toString())]),sr=s.z.object({task:gt,variant:s.z.string(),key:s.z.string().optional(),details:s.z.record(s.z.unknown()).or(s.z.string().transform(t=>t===""?{}:JSON.parse(t))).or(s.z.array(s.z.unknown())).or(s.z.null())}),Tr=s.z.object({key:gt,name:s.z.string(),type:s.z.string(),internal:s.z.boolean().optional(),config:s.z.record(s.z.unknown()).or(s.z.string().transform(t=>t===""?{}:dt.JSON_CODEC.decodeString(t))),state:sr.optional().nullable(),snapshot:s.z.boolean().optional()}),Ip=Tr.omit({key:!0}).extend({key:gt.transform(t=>t.toString()).optional(),config:s.z.unknown().transform(t=>dt.JSON_CODEC.encodeString(t))});s.z.object({task:gt,type:s.z.string(),key:s.z.string(),args:s.z.record(s.z.unknown()).or(s.z.string().transform(t=>t===""?{}:JSON.parse(t)))});const Wt="sy_task_state",ba="sy_task_cmd",mn=new Error("Task not created");class Ep{constructor(e,n,r,i,a=!1,o=!1,c,u=null,h=null,f=null){l(this,"key"),l(this,"name"),l(this,"internal"),l(this,"type"),l(this,"config"),l(this,"snapshot"),l(this,"state"),l(this,"frameClient"),l(this,"ontologyClient"),l(this,"rangeClient"),this.key=e,this.name=n,this.type=r,this.config=i,this.internal=a,this.snapshot=o,c!==null&&(this.state=c),this.frameClient=u,this.ontologyClient=h,this.rangeClient=f}get payload(){return{key:this.key,name:this.name,type:this.type,config:this.config,state:this.state,internal:this.internal}}get ontologyID(){return new R({type:"task",key:this.key})}async executeCommand(e,n){if(this.frameClient==null)throw mn;const r=await this.frameClient.openWriter(ba),i=Nf.id();return await r.write(ba,[{task:this.key,type:e,key:i,args:n}]),await r.close(),i}async executeCommandSync(e,n,r){if(this.frameClient==null)throw mn;const i=await this.frameClient.openStreamer(Wt),a=await this.executeCommand(e,n);let o;const c=new Promise(u=>setTimeout(()=>u(!1),new $(r).milliseconds));for(;;){const u=await Promise.any([i.read(),c]);if(u===!1)throw new Error("Command timed out");const h=sr.safeParse(u.at(-1).sy_task_state);if(h.success){if(o=h.data,o.key===a)break}else console.error(h.error)}return i.close(),o}async openStateObserver(){if(this.frameClient==null)throw mn;return new vr(await this.frameClient.openStreamer(Wt),e=>{const n=e.get(Wt);if(n.length===0)return[null,!1];const r=sr.safeParse(n.at(-1));if(!r.success)return[null,!1];const i=r.data;return i.task!==this.key?[null,!1]:[i,!0]})}async snapshottedTo(){if(this.ontologyClient==null||this.rangeClient==null)throw mn;if(!this.snapshot)return null;const e=await this.ontologyClient.retrieveParents(this.ontologyID);return e.length==0?null:e[0]}}const Ap=s.z.object({rack:cn.optional(),keys:s.z.string().array().optional(),names:s.z.string().array().optional(),offset:s.z.number().optional(),limit:s.z.number().optional(),includeState:s.z.boolean().optional()}),kp=s.z.object({tasks:me(Tr)}),xp="/hardware/task/retrieve",Cp="/hardware/task/create",$p="/hardware/task/delete",Rp="/hardware/task/copy",jp=s.z.object({tasks:Ip.array()}),Mp=s.z.object({tasks:Tr.array()}),Bp=s.z.object({keys:gt.array()}),Dp=s.z.object({}),Pp=s.z.object({key:gt,name:s.z.string(),snapshot:s.z.boolean()}),Up=s.z.object({task:Tr});let Lp=class{constructor(t,e,n,r){l(this,"type","task"),l(this,"client"),l(this,"frameClient"),l(this,"ontologyClient"),l(this,"rangeClient"),this.client=t,this.frameClient=e,this.ontologyClient=n,this.rangeClient=r}async create(t){const e=!Array.isArray(t),n=await v(this.client,Cp,{tasks:T(t)},jp,Mp),r=this.sugar(n.tasks);return e?r[0]:r}async delete(t){await v(this.client,$p,{keys:T(t)},Bp,Dp)}async search(t){return await this.execRetrieve({keys:[t]})}async page(t,e){return await this.execRetrieve({offset:t,limit:e})}async list(t={}){return this.sugar(await this.execRetrieve(t))}async retrieve(t,e){const{single:n,normalized:r,variant:i}=pr(t,{number:"rack",string:"keys"},{convertNumericStrings:!1}),a={...e};i==="rack"?a.rack=t:a.keys=r;const o=await this.execRetrieve(a),c=this.sugar(o);return n&&i!=="rack"?c[0]:c}async copy(t,e,n){const r=await v(this.client,Rp,{key:t,name:e,snapshot:n},Pp,Up);return this.sugar([r.task])[0]}async retrieveByName(t,e){const n=await this.execRetrieve({names:[t],rack:e});return mr("Task",t,n,!0),this.sugar(n)[0]}async execRetrieve(t){return(await v(this.client,xp,t,Ap,kp)).tasks}sugar(t){return t.map(({key:e,name:n,type:r,config:i,state:a,internal:o,snapshot:c})=>new Ep(e,n,r,i,o,c,a,this.frameClient,this.ontologyClient,this.rangeClient))}async openTracker(){return await yt(this.frameClient,"sy_task_set","sy_task_delete",(t,e)=>Array.from(e).map(n=>({variant:t,key:n.toString(),value:n.toString()})))}async openStateObserver(){return new vr(await this.frameClient.openStreamer(Wt),t=>{const e=t.get(Wt);if(e.length===0)return[null,!1];const n=sr.safeParse(e.at(-1));return n.success?[n.data,!0]:[null,!1]})}};const un=s.z.string().uuid(),Sr=s.z.object({key:un,name:s.z.string().min(1),color:s.z.string()}),_p=s.z.object({keys:un.array().optional(),for:ge.optional(),search:s.z.string().optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),Yp=s.z.object({labels:me(Sr)});var wn;let Fp=(wn=class{constructor(t){l(this,"client"),this.client=t}async retrieve(t){const e=T(t);return await this.execute({keys:e})}async retrieveFor(t){return await this.execute({for:t})}async search(t){return await this.execute({search:t})}async page(t,e){return await this.execute({offset:t,limit:e})}async execute(t){const[e,n]=await this.client.send(wn.ENDPOINT,t,_p,Yp);if(n!=null)throw n;return e.labels}},l(wn,"ENDPOINT","/label/retrieve"),wn);const qp=Sr.extend({key:un.optional()}),Vp=s.z.object({labels:qp.array()}),Wp=s.z.object({labels:Sr.array()}),Gp=s.z.object({keys:un.array()}),Nl=s.z.object({id:ge,labels:un.array(),replace:s.z.boolean().optional()}),Zp=Nl.omit({replace:!0}),Kr=s.z.object({}),Kp="/label/create",Jp="/label/delete",Hp="/label/set",Xp="/label/remove";let Qp=class{constructor(t){l(this,"client"),this.client=t}async create(t){return(await v(this.client,Kp,{labels:T(t)},Vp,Wp)).labels}async delete(t){await v(this.client,Jp,{keys:T(t)},Gp,Kr)}async set(t,e,{replace:n}={}){await v(this.client,Hp,{id:t,labels:e,replace:n},Nl,Kr)}async remove(t,e){await v(this.client,Xp,{id:t,labels:e},Zp,Kr)}};const em="sy_label_set",tm="sy_label_delete";let nm=class{constructor(t,e,n){l(this,"type","label"),l(this,"retriever"),l(this,"writer"),l(this,"frameClient"),l(this,"ontology"),this.writer=new Qp(t),this.retriever=new Fp(t),this.frameClient=e,this.ontology=n}async search(t){return await this.retriever.search(t)}async retrieve(t){const e=Array.isArray(t),n=await this.retriever.retrieve(t);return e?n:n[0]}async retrieveFor(t){return await this.retriever.retrieveFor(new R(t))}async label(t,e,n={}){await this.writer.set(new R(t),e,n)}async removeLabels(t,e){await this.writer.remove(new R(t),e)}async page(t,e){return await this.retriever.page(t,e)}async create(t){const e=Array.isArray(t),n=await this.writer.create(t);return e?n:n[0]}async delete(t){await this.writer.delete(t)}async openChangeTracker(){return await yt(this.frameClient,em,tm,rm)}async trackLabelsOf(t){const e=new Qe.Observer,n=(await this.retrieveFor(t)).map(r=>({id:new R({key:r.key,type:"label"}),key:r.key,name:r.name,data:r}));return(await this.ontology.openDependentTracker({target:new R(t),dependents:n,relationshipType:"labeled_by"})).onChange(r=>e.notify(r.map(i=>{var a,o;return{key:i.id.key,color:(a=i.data)==null?void 0:a.color,name:(o=i.data)==null?void 0:o.name}}))),e}};const rm=(t,e)=>t==="delete"?e.toUUIDs().map(n=>({variant:t,key:n})):e.parseJSON(Sr).map(n=>({variant:t,key:n.key,value:n})),ye=s.z.string().uuid(),hn=s.z.object({key:ye,name:s.z.string().min(1),timeRange:se.z,color:s.z.string().optional()}),Il=hn.extend({key:s.z.string().uuid().optional()}),El=t=>{const e=T(t),n=e.length===0;let r=!1;return n||(r=ye.safeParse(e[0]).success),{single:!Array.isArray(t),variant:r?"keys":"names",normalized:e,actual:t,empty:n}},Al="range",kl="range-alias",sm=t=>new R({type:Al,key:t}),im=t=>new R({type:kl,key:t}),am="sy_range_alias_set",om="sy_range_alias_delete",lm=s.z.object({range:ye,aliases:s.z.string().array()}),cm=s.z.object({aliases:s.z.record(s.z.string(),Ve)}),um=s.z.object({range:ye,aliases:s.z.record(Ve.or(s.z.string()),s.z.string())}),hm=s.z.unknown(),dm=s.z.object({range:ye,channels:Ve.array()}),fm=s.z.unknown(),ym=s.z.object({range:ye}),gm=s.z.object({aliases:s.z.record(s.z.string(),s.z.string())}),Lt=class _t{constructor(e,n,r){l(this,"frameClient"),l(this,"cache",new Map),l(this,"client"),l(this,"rangeKey"),this.rangeKey=e,this.cache=new Map,this.client=r,this.frameClient=n}async resolve(e){const n=[],r=typeof e=="string",i={};if(r){const o=this.cache.get(e);if(o!=null)return o;n.push(e)}else e.forEach(o=>{const c=this.cache.get(o);c!=null?i[o]=c:n.push(o)});if(n.length===0)return i;const a=await v(this.client,_t.RESOLVE_ENDPOINT,{range:this.rangeKey,aliases:n},lm,cm);return Object.entries(a.aliases).forEach(([o,c])=>this.cache.set(o,c)),r?a.aliases[n[0]]:{...i,...a.aliases}}async set(e){await v(this.client,_t.SET_ENDPOINT,{range:this.rangeKey,aliases:e},um,hm)}async list(){return(await v(this.client,_t.LIST_ENDPOINT,{range:this.rangeKey},ym,gm)).aliases}async delete(e){await v(this.client,_t.DELETE_ENDPOINT,{range:this.rangeKey,channels:e},dm,fm)}async openChangeTracker(){return await yt(this.frameClient,am,om,bm(this.rangeKey))}};l(Lt,"SET_ENDPOINT","/range/alias/set"),l(Lt,"RESOLVE_ENDPOINT","/range/alias/resolve"),l(Lt,"LIST_ENDPOINT","/range/alias/list"),l(Lt,"DELETE_ENDPOINT","/range/alias/delete");let pm=Lt;const mm=s.z.object({range:ye,channel:Ve,alias:s.z.string()}),wm="---",bm=t=>(e,n)=>e==="delete"?n.toStrings().filter(r=>r.split(wm)[0]===t).map(r=>({variant:e,key:r,value:void 0})):n.parseJSON(mm).map(r=>({variant:e,key:r.alias,value:r})),vm=s.z.object({range:ye,keys:s.z.string().array()}),Qs=s.z.object({range:ye,key:s.z.string(),value:s.z.string()}),Om=s.z.object({pairs:me(Qs)}),Tm=s.z.object({range:ye,pairs:Qs.array()}),Sm=s.z.object({range:ye,keys:s.z.string().array()}),Hn=class Xn{constructor(e,n,r){l(this,"rangeKey"),l(this,"client"),l(this,"frameClient"),this.rangeKey=e,this.client=n,this.frameClient=r}async get(e){const n=await v(this.client,Xn.GET_ENDPOINT,{range:this.rangeKey,keys:T(e)},vm,Om);return typeof e=="string"?n.pairs[0].value:Object.fromEntries(n.pairs.map(r=>[r.key,r.value]))}async list(){return this.get([])}async set(e,n=""){let r;Us(e)?r=Object.entries(e).map(([i,a])=>({range:this.rangeKey,key:i,value:a})):r=[{range:this.rangeKey,key:e,value:n}],await v(this.client,Xn.SET_ENDPOINT,{range:this.rangeKey,pairs:r},Tm,s.z.unknown())}async delete(e){await v(this.client,Xn.DELETE_ENDPOINT,{range:this.rangeKey,keys:T(e)},Sm,s.z.unknown())}async openTracker(){return await yt(this.frameClient,"sy_range_kv_set","sy_range_kv_delete",(e,n)=>e==="delete"?n.toStrings().map(r=>{const[i,a]=r.split("<--->",2);return{variant:e,key:r,value:{range:i,key:a,value:""}}}):n.parseJSON(Qs).map(r=>({variant:e,key:`${r.range}${r.key}`,value:r})))}};l(Hn,"GET_ENDPOINT","/range/kv/get"),l(Hn,"SET_ENDPOINT","/range/kv/set"),l(Hn,"DELETE_ENDPOINT","/range/kv/delete");let zs=Hn;const Jr=t=>new R({type:"range",key:t});class xl{constructor(e,n=se.ZERO,r,i,a,o,c,u,h,f,d){l(this,"key"),l(this,"name"),l(this,"kv"),l(this,"timeRange"),l(this,"color"),l(this,"channels"),l(this,"aliaser"),l(this,"frameClient"),l(this,"labelClient"),l(this,"ontologyClient"),l(this,"rangeClient"),this.key=r,this.name=e,this.timeRange=n,this.frameClient=a,this.color=i,this.kv=o,this.aliaser=c,this.channels=u,this.labelClient=h,this.ontologyClient=f,this.rangeClient=d}get ontologyID(){return new R({key:this.key,type:"range"})}get payload(){return{key:this.key,name:this.name,timeRange:this.timeRange,color:this.color}}async setAlias(e,n){const r=await this.channels.retrieve(e);if(r.length===0)throw new Oe(`Channel ${e} does not exist`);await this.aliaser.set({[r[0].key]:n})}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 openAliasTracker(){return await this.aliaser.openChangeTracker()}async retrieveParent(){return this.rangeClient.retrieveParent(this.key)}async retrieveChildren(){const e=(await this.ontologyClient.retrieveChildren(this.ontologyID,{excludeFieldData:!0,types:["range"]})).map(n=>n.id.key);return await this.rangeClient.retrieve(e)}async read(e){return await this.frameClient.read(this.timeRange,e)}async labels(){return await this.labelClient.retrieveFor(Jr(this.key))}async addLabel(...e){await this.labelClient.label(Jr(this.key),e)}async removeLabel(...e){await this.labelClient.removeLabels(Jr(this.key),e)}async openChildRangeTracker(){const e=new Qe.Observer,n=(await this.retrieveChildren()).map(i=>{const a=new R({key:i.key,type:"range"});return{id:a,key:a.toString(),name:i.name,data:i.payload}}),r=await this.ontologyClient.openDependentTracker({target:this.ontologyID,dependents:n,resourceType:"range"});return r.onChange(i=>e.notify(this.rangeClient.resourcesToRanges(i))),e.setCloser(async()=>await r.close()),e}async openParentRangeTracker(){const e=new Qe.Observer,n=await this.retrieveParent();if(n==null)return null;const r=new R({key:n.key,type:"range"}),i={id:r,key:r.toString(),name:n.name,data:n.payload},a=await this.ontologyClient.openDependentTracker({target:this.ontologyID,dependents:[i],relationshipDirection:"to"});return a.onChange(o=>{const c=this.rangeClient.resourcesToRanges(o);if(c.length===0)return;const u=c[0];e.notify(u)}),e.setCloser(async()=>await a.close()),e}}const zm=s.z.object({keys:ye.array().optional(),names:s.z.array(s.z.string()).optional(),term:s.z.string().optional(),overlapsWith:se.z.optional(),limit:s.z.number().int().optional(),offset:s.z.number().int().optional()}),Nm="/range/retrieve",Im=s.z.object({ranges:me(hn)});let Cl=class{constructor(t,e,n,r,i,a){l(this,"type","range"),l(this,"frameClient"),l(this,"writer"),l(this,"unaryClient"),l(this,"channels"),l(this,"labelClient"),l(this,"ontologyClient"),this.frameClient=t,this.writer=e,this.unaryClient=n,this.channels=r,this.labelClient=i,this.ontologyClient=a}async create(t,e){const n=!Array.isArray(t),r=this.sugarMany(await this.writer.create(T(t),e));return n?r[0]:r}async rename(t,e){await this.writer.rename(t,e)}async delete(t){await this.writer.delete(T(t))}async search(t){return this.sugarMany(await this.execRetrieve({term:t}))}async page(t,e){return this.sugarMany(await this.execRetrieve({offset:t,limit:e}))}async retrieve(t){if(typeof t=="object"&&"start"in t)return await this.execRetrieve({overlapsWith:new se(t)});const{single:e,actual:n,variant:r,normalized:i,empty:a}=El(t);if(a)return[];const o=await this.execRetrieve({[r]:i});if(!e)return o;if(o.length===0)throw new ct(`range matching ${n} not found`);if(o.length>1)throw new ut(`multiple ranges matching ${n} found`);return o[0]}getKV(t){return new zs(t,this.unaryClient,this.frameClient)}async execRetrieve(t){const{ranges:e}=await v(this.unaryClient,Nm,t,zm,Im);return this.sugarMany(e)}async retrieveParent(t){const e=await this.ontologyClient.retrieveParents({key:t,type:"range"});if(e.length===0)return null;const n=e[0];return n.id.type!=="range"?null:await this.retrieve(n.id.key)}sugarOne(t){return new xl(t.name,t.timeRange,t.key,t.color,this.frameClient,new zs(t.key,this.unaryClient,this.frameClient),new pm(t.key,this.frameClient,this.unaryClient),this.channels,this.labelClient,this.ontologyClient,this)}sugarMany(t){return t.map(e=>this.sugarOne(e))}async openTracker(){return await yt(this.frameClient,"sy_range_set","sy_range_delete",(t,e)=>t==="delete"?e.toStrings().map(n=>({variant:t,key:n,value:void 0})):this.sugarMany(e.parseJSON(hn)).map(n=>({variant:t,key:n.key,value:n})))}resourcesToRanges(t){return t.map(e=>this.resourceToRange(e))}resourceToRange(t){var e,n,r;return this.sugarOne({key:t.id.key,name:(e=t.data)==null?void 0:e.name,timeRange:new se((n=t.data)==null?void 0:n.timeRange),color:(r=t.data)==null?void 0:r.color})}};const Em=s.z.object({ranges:hn.array()}),Am=s.z.object({parent:ge.optional(),ranges:Il.array()}),km=s.z.object({keys:ye.array()}),xm=s.z.object({}),Cm=s.z.object({key:ye,name:s.z.string()}),$m=s.z.object({}),Rm="/range/create",jm="/range/delete",Mm="/range/rename";let $l=class{constructor(t){l(this,"client"),this.client=t}async rename(t,e){await v(this.client,Mm,{key:t,name:e},Cm,$m)}async create(t,e){return(await v(this.client,Rm,{ranges:t,...e},Am,Em)).ranges}async delete(t){await v(this.client,jm,{keys:t},km,xm)}};const Bm=Object.freeze(Object.defineProperty({__proto__:null,ALIAS_ONTOLOGY_TYPE:kl,Client:Cl,KV:zs,ONTOLOGY_TYPE:Al,Range:xl,Writer:$l,analyzeParams:El,keyZ:ye,newPayloadZ:Il,payloadZ:hn,rangeAliasOntologyID:im,rangeOntologyID:sm},Symbol.toStringTag,{value:"Module"})),Dm="/api/v1/";class Pm{constructor(e,n=!1){l(this,"url"),l(this,"unary"),l(this,"stream"),l(this,"secure"),this.secure=n,this.url=e.child(Dm);const r=new dt.JSONCodec;this.unary=new gd(this.url,r,this.secure),this.stream=new zd(this.url,r,this.secure)}use(...e){this.unary.use(...e),this.stream.use(...e)}}const ei=s.z.string().uuid(),ti=s.z.object({key:s.z.string(),name:s.z.string(),data:dr.or(s.z.string().transform(t=>JSON.parse(t)))}),Um=s.z.object({keys:s.z.string().array()}),Lm=s.z.object({linePlots:ti.array()});let _m=class{constructor(t){l(this,"ENDPOINT","/workspace/lineplot/retrieve"),l(this,"client"),this.client=t}async retrieve(t){const e=T(t);return(await v(this.client,this.ENDPOINT,{keys:e},Um,Lm)).linePlots}};const We=s.z.string().uuid(),Rl=t=>JSON.parse(t),jl=s.z.object({name:s.z.string(),key:We,layout:dr.or(s.z.string().transform(t=>Rl(t)))}),Ml=jl.omit({layout:!0}).extend({layout:s.z.string().transform(t=>Rl(t))}),Ym=ti.partial({key:!0}).transform(t=>({...t,data:JSON.stringify(t.data)})),Fm=s.z.object({workspace:We,linePlots:Ym.array()}),qm=s.z.object({linePlots:ti.array()}),Vm=s.z.object({keys:ei.array()}),Wm=s.z.object({}),Gm=s.z.object({key:ei,name:s.z.string()}),Zm=s.z.object({}),Km=s.z.object({key:ei,data:s.z.string()}),Jm=s.z.object({}),Hm="/workspace/lineplot/create",Xm="/workspace/lineplot/delete",Qm="/workspace/lineplot/rename",ew="/workspace/lineplot/set-data";let tw=class{constructor(t){l(this,"client"),this.client=t}async create(t,e){const n={...e,data:JSON.stringify(e.data)};return(await v(this.client,Hm,{workspace:t,linePlots:[n]},Fm,qm)).linePlots[0]}async delete(t){const e=T(t);await v(this.client,Xm,{keys:e},Vm,Wm)}async rename(t,e){await v(this.client,Qm,{key:t,name:e},Gm,Zm)}async setData(t,e){await v(this.client,ew,{key:t,data:JSON.stringify(e)},Km,Jm)}},nw=class{constructor(t){l(this,"writer"),l(this,"retriever"),this.writer=new tw(t),this.retriever=new _m(t)}async create(t,e){return await this.writer.create(t,e)}async rename(t,e){await this.writer.rename(t,e)}async setData(t,e){await this.writer.setData(t,e)}async retrieve(t){const e=Array.isArray(t),n=await this.retriever.retrieve(t);return e?n:n[0]}async delete(t){await this.writer.delete(t)}};const ni=s.z.string().uuid(),rw=s.z.object({key:s.z.string(),name:s.z.string(),data:dr.or(s.z.string().transform(t=>JSON.parse(t)))}),Bl=s.z.object({key:s.z.string(),name:s.z.string(),data:s.z.string().transform(t=>JSON.parse(t))}),sw=s.z.object({keys:s.z.string().array()}),iw=s.z.object({logs:Bl.array()});let aw=class{constructor(t){l(this,"ENDPOINT","/workspace/log/retrieve"),l(this,"client"),this.client=t}async retrieve(t){return(await v(this.client,this.ENDPOINT,{keys:T(t)},sw,iw)).logs}};const ow=rw.partial({key:!0}).transform(t=>({...t,data:JSON.stringify(t.data)})),lw=s.z.object({workspace:We,logs:ow.array()}),cw=s.z.object({logs:Bl.array()}),uw=s.z.object({keys:ni.array()}),hw=s.z.object({}),dw=s.z.object({key:ni,name:s.z.string()}),fw=s.z.object({}),yw=s.z.object({key:ni,data:s.z.string()}),gw=s.z.object({}),pw="/workspace/log/create",mw="/workspace/log/delete",ww="/workspace/log/rename",bw="/workspace/log/set-data";let vw=class{constructor(t){l(this,"client"),this.client=t}async create(t,e){const n={...e,data:JSON.stringify(e.data)};return(await v(this.client,pw,{workspace:t,logs:[n]},lw,cw)).logs[0]}async delete(t){const e=T(t);await v(this.client,mw,{keys:e},uw,hw)}async rename(t,e){await v(this.client,ww,{key:t,name:e},dw,fw)}async setData(t,e){await v(this.client,bw,{key:t,data:JSON.stringify(e)},yw,gw)}},Ow=class{constructor(t){l(this,"writer"),l(this,"retriever"),this.writer=new vw(t),this.retriever=new aw(t)}async create(t,e){return await this.writer.create(t,e)}async rename(t,e){await this.writer.rename(t,e)}async setData(t,e){await this.writer.setData(t,e)}async retrieve(t){const e=Array.isArray(t),n=await this.retriever.retrieve(t);return e?n:n[0]}async delete(t){await this.writer.delete(t)}};const Tw=s.z.object({keys:We.array().optional(),search:s.z.string().optional(),author:s.z.string().uuid().optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),Sw=s.z.object({workspaces:me(Ml)});var bn;let zw=(bn=class{constructor(t){l(this,"client"),this.client=t}async retrieve(t){const e=T(t);return await this.execute({keys:e})}async retrieveByAuthor(t){return await this.execute({author:t})}async search(t){return await this.execute({search:t})}async page(t,e){return await this.execute({offset:t,limit:e})}async execute(t){return(await v(this.client,bn.ENDPOINT,t,Tw,Sw)).workspaces}},l(bn,"ENDPOINT","/workspace/retrieve"),bn);const zr=s.z.string().uuid(),Nw=s.z.object({key:s.z.string(),name:s.z.string(),data:dr.or(s.z.string().transform(t=>JSON.parse(t))),snapshot:s.z.boolean()}),ri=s.z.object({key:s.z.string(),name:s.z.string(),snapshot:s.z.boolean(),data:s.z.string().transform(t=>JSON.parse(t))}),Iw=s.z.object({keys:s.z.string().array()}),Ew=s.z.object({schematics:ri.array()});class Aw{constructor(e){l(this,"ENDPOINT","/workspace/schematic/retrieve"),l(this,"client"),this.client=e}async retrieve(e){return(await v(this.client,this.ENDPOINT,{keys:T(e)},Iw,Ew)).schematics}}const kw=Nw.partial({key:!0,snapshot:!0}).transform(t=>({...t,data:JSON.stringify(t.data)})),xw=s.z.object({workspace:We,schematics:kw.array()}),Cw=s.z.object({schematics:ri.array()}),$w=s.z.object({keys:zr.array()}),Rw=s.z.object({}),jw=s.z.object({key:zr,name:s.z.string()}),Mw=s.z.object({}),Bw=s.z.object({key:zr,data:s.z.string()}),Dw=s.z.object({}),Pw=s.z.object({key:zr,name:s.z.string(),snapshot:s.z.boolean()}),Uw=s.z.object({schematic:ri}),Lw="/workspace/schematic/create",_w="/workspace/schematic/delete",Yw="/workspace/schematic/rename",Fw="/workspace/schematic/set-data",qw="/workspace/schematic/copy";let Vw=class{constructor(t){l(this,"client"),this.client=t}async create(t,e){const n={...e,data:JSON.stringify(e.data)};return(await v(this.client,Lw,{workspace:t,schematics:[n]},xw,Cw)).schematics[0]}async copy(t,e,n){return(await v(this.client,qw,{key:t,name:e,snapshot:n},Pw,Uw)).schematic}async delete(t){const e=T(t);await v(this.client,_w,{keys:e},$w,Rw)}async rename(t,e){await v(this.client,Yw,{key:t,name:e},jw,Mw)}async setData(t,e){await v(this.client,Fw,{key:t,data:JSON.stringify(e)},Bw,Dw)}},Ww=class{constructor(t){l(this,"writer"),l(this,"retriever"),this.writer=new Vw(t),this.retriever=new Aw(t)}async create(t,e){return await this.writer.create(t,e)}async rename(t,e){await this.writer.rename(t,e)}async setData(t,e){await this.writer.setData(t,e)}async retrieve(t){const e=Array.isArray(t),n=await this.retriever.retrieve(t);return e?n:n[0]}async delete(t){await this.writer.delete(t)}async copy(t,e,n){return await this.writer.copy(t,e,n)}};const Gw=jl.partial({key:!0}).transform(t=>({...t,layout:JSON.stringify(t.layout)})),Zw=s.z.object({workspaces:Gw.array()}),Kw=s.z.object({workspaces:Ml.array()}),Jw=s.z.object({keys:We.array()}),Hw=s.z.object({}),Xw=s.z.object({key:We,name:s.z.string()}),Qw=s.z.object({}),eb=s.z.object({key:We,layout:s.z.string()}),tb=s.z.object({}),nb="/workspace/create",rb="/workspace/delete",sb="/workspace/rename",ib="/workspace/set-layout";class ab{constructor(e){l(this,"client"),this.client=e}async create(e){return(await v(this.client,nb,{workspaces:T(e)},Zw,Kw)).workspaces}async delete(e){await v(this.client,rb,{keys:T(e)},Jw,Hw)}async rename(e,n){await v(this.client,sb,{key:e,name:n},Xw,Qw)}async setLayout(e,n){await v(this.client,ib,{key:e,layout:JSON.stringify(n)},eb,tb)}}class ob{constructor(e){l(this,"type","workspace"),l(this,"schematic"),l(this,"linePlot"),l(this,"log"),l(this,"retriever"),l(this,"writer"),this.schematic=new Ww(e),this.linePlot=new nw(e),this.retriever=new zw(e),this.log=new Ow(e),this.writer=new ab(e)}async search(e){return await this.retriever.search(e)}async retrieveByAuthor(e){return await this.retriever.retrieveByAuthor(e)}async retrieve(e){const n=Array.isArray(e),r=await this.retriever.retrieve(e);return n?r:r[0]}async page(e,n){return await this.retriever.page(e,n)}async create(e){const n=Array.isArray(e),r=await this.writer.create(e);return n?r:r[0]}async rename(e,n){await this.writer.rename(e,n)}async setLayout(e,n){await this.writer.setLayout(e,n)}async delete(...e){await this.writer.delete(e)}}const Dl=s.z.object({host:s.z.string({required_error:"Host is required"}).min(1,"Host is required"),port:s.z.number({required_error:"Port is required"}).or(s.z.string({required_error:"Port is required"})),username:s.z.string().min(1,"Username is required"),password:s.z.string().min(1,"Password is required"),connectivityPollFrequency:$.z.default($.seconds(30)),secure:s.z.boolean().optional().default(!1),name:s.z.string().optional()});class Pl extends Qg{constructor(e){const n=Dl.parse(e),{host:r,port:i,username:a,password:o,connectivityPollFrequency:c,secure:u}=n,h=new Pm(new Wf({host:r,port:Number(i)}),u);h.use(sy);let f;a!=null&&o!=null&&(f=new xg(h.unary,{username:a,password:o}),h.use(f.middleware()));const d=new qs(new Fs(h.unary)),k=new ml(h.unary,d);super(h.stream,h.unary,d),l(this,"createdAt"),l(this,"props"),l(this,"ranges"),l(this,"channels"),l(this,"auth"),l(this,"user"),l(this,"access"),l(this,"connectivity"),l(this,"ontology"),l(this,"workspaces"),l(this,"labels"),l(this,"hardware"),l(this,"control"),l(this,"transport"),l(this,"clientVersion","0.33.0"),this.createdAt=x.now(),this.props=n,this.auth=f,this.transport=h,this.channels=new pl(this,d,h.unary,k),this.connectivity=new vl(h.unary,c,this.clientVersion,n.name),this.control=new zl(this),this.ontology=new Oy(h.unary,this);const D=new $l(this.transport.unary);this.labels=new nm(this.transport.unary,this,this.ontology),this.ranges=new Cl(this,D,this.transport.unary,d,this.labels,this.ontology),this.access=new By(this.transport.unary),this.user=new Sg(this.transport.unary),this.workspaces=new ob(this.transport.unary);const ie=new pp(this.transport.unary,this),M=new Lp(this.transport.unary,this,this.ontology,this.ranges),ic=new zp(this.transport.unary,this,M);this.hardware=new ip(M,ic,ie)}get key(){return this.createdAt.valueOf().toString()}close(){this.connectivity.stopChecking()}}l(Pl,"connectivity",vl);const lb=lt.Authority,Ns=(t,e,n="")=>{try{return t.parse(e)}catch(r){if(r instanceof s.z.ZodError){const i=r.errors.map(a=>a.path.length===0?a.message:`${a.path.join(".")}: ${a.message}`);throw new Error(`${n} - ${i.join(`
|
|
66
|
-
`)}`)}else throw r}};var cb=Object.defineProperty,ub=(t,e,n)=>e in t?cb(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,ee=(t,e,n)=>ub(t,typeof e!="symbol"?e+"":e,n);const Is=class Ul{constructor(e,n,r="",i=!1){ee(this,"_noop",!1),ee(this,"key"),ee(this,"path"),ee(this,"serviceName"),this.key=e,this.path=n,this.serviceName=r,this._noop=i}child(e){return new Ul(e,this.extendPath(e),this.serviceName,this.noop)}extendPath(e){return`${this.path}.${e}`}get noop(){return this._noop}};ee(Is,"NOOP",new Is("","",""));let si=Is;const Es=["debug","info","warn","error"],hb=t=>{const e=Es.indexOf(t);return({level:n})=>Es.indexOf(n)>=e},db=t=>{const{include:e,exclude:n}=t;return({path:r})=>!(e!=null&&!e.some(i=>r.startsWith(i))||n!=null&&n.some(i=>r.startsWith(i)))},As=class Ll{constructor(e={}){ee(this,"meta",si.NOOP),ee(this,"filters");const{filters:n=[]}=e;this.filters=n}filter(e){return!this.meta.noop&&this.filters.every(n=>n({key:this.meta.key,path:this.meta.path,level:e}))}child(e){const n=new Ll({filters:this.filters});return n.meta=e,n}debug(e,n,r=!1){!this.filter("debug")&&!r||(n==null?console.log("%cDEBUG","color: #8c00f0;",this.meta.path,e):console.log("%cDEBUG","color: #8c00f0;",this.meta.path,e,vn(n)))}info(e,n,r=!1){!this.filter("info")&&!r||(n==null?console.log("%cINFO","color: #005eff;",this.meta.path,e):console.log("%cINFO","color: #005eff;",this.meta.path,e,vn(n)))}warn(e,n,r=!1){!this.filter("warn")&&!r||(n==null?console.warn("WARN",this.meta.path,e):console.warn("WARN",this.meta.path,e,vn(n)))}error(e,n,r=!1){!this.filter("error")&&!r||(n==null?console.error("ERROR",this.meta.path,e):console.error("ERROR",this.meta.path,e,vn(n)))}};ee(As,"NOOP",new As);let _l=As;const vn=t=>typeof t=="function"?t():t;var fb=typeof globalThis=="object"?globalThis:typeof self=="object"?self:typeof window=="object"?window:typeof global=="object"?global:{},Je="1.9.0",va=/^(\d+)\.(\d+)\.(\d+)(-(.+))?$/;function yb(t){var e=new Set([t]),n=new Set,r=t.match(va);if(!r)return function(){return!1};var i={major:+r[1],minor:+r[2],patch:+r[3],prerelease:r[4]};if(i.prerelease!=null)return function(c){return c===t};function a(c){return n.add(c),!1}function o(c){return e.add(c),!0}return function(c){if(e.has(c))return!0;if(n.has(c))return!1;var u=c.match(va);if(!u)return a(c);var h={major:+u[1],minor:+u[2],patch:+u[3],prerelease:u[4]};return h.prerelease!=null||i.major!==h.major?a(c):i.major===0?i.minor===h.minor&&i.patch<=h.patch?o(c):a(c):i.minor<=h.minor?o(c):a(c)}}var gb=yb(Je),pb=Je.split(".")[0],Ht=Symbol.for("opentelemetry.js.api."+pb),Xt=fb;function ii(t,e,n,r){var i;r===void 0&&(r=!1);var a=Xt[Ht]=(i=Xt[Ht])!==null&&i!==void 0?i:{version:Je};if(!r&&a[t]){var o=new Error("@opentelemetry/api: Attempted duplicate registration of API: "+t);return n.error(o.stack||o.message),!1}if(a.version!==Je){var o=new Error("@opentelemetry/api: Registration of version v"+a.version+" for "+t+" does not match previously registered API v"+Je);return n.error(o.stack||o.message),!1}return a[t]=e,n.debug("@opentelemetry/api: Registered a global for "+t+" v"+Je+"."),!0}function Qt(t){var e,n,r=(e=Xt[Ht])===null||e===void 0?void 0:e.version;if(!(!r||!gb(r)))return(n=Xt[Ht])===null||n===void 0?void 0:n[t]}function ai(t,e){e.debug("@opentelemetry/api: Unregistering a global for "+t+" v"+Je+".");var n=Xt[Ht];n&&delete n[t]}var mb=function(t,e){var n=typeof Symbol=="function"&&t[Symbol.iterator];if(!n)return t;var r=n.call(t),i,a=[],o;try{for(;(e===void 0||e-- >0)&&!(i=r.next()).done;)a.push(i.value)}catch(c){o={error:c}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(o)throw o.error}}return a},wb=function(t,e,n){if(arguments.length===2)for(var r=0,i=e.length,a;r<i;r++)(a||!(r in e))&&(a||(a=Array.prototype.slice.call(e,0,r)),a[r]=e[r]);return t.concat(a||Array.prototype.slice.call(e))},bb=function(){function t(e){this._namespace=e.namespace||"DiagComponentLogger"}return t.prototype.debug=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return Ot("debug",this._namespace,e)},t.prototype.error=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return Ot("error",this._namespace,e)},t.prototype.info=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return Ot("info",this._namespace,e)},t.prototype.warn=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return Ot("warn",this._namespace,e)},t.prototype.verbose=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return Ot("verbose",this._namespace,e)},t}();function Ot(t,e,n){var r=Qt("diag");if(r)return n.unshift(e),r[t].apply(r,wb([],mb(n),!1))}var pe;(function(t){t[t.NONE=0]="NONE",t[t.ERROR=30]="ERROR",t[t.WARN=50]="WARN",t[t.INFO=60]="INFO",t[t.DEBUG=70]="DEBUG",t[t.VERBOSE=80]="VERBOSE",t[t.ALL=9999]="ALL"})(pe||(pe={}));function vb(t,e){t<pe.NONE?t=pe.NONE:t>pe.ALL&&(t=pe.ALL),e=e||{};function n(r,i){var a=e[r];return typeof a=="function"&&t>=i?a.bind(e):function(){}}return{error:n("error",pe.ERROR),warn:n("warn",pe.WARN),info:n("info",pe.INFO),debug:n("debug",pe.DEBUG),verbose:n("verbose",pe.VERBOSE)}}var Ob=function(t,e){var n=typeof Symbol=="function"&&t[Symbol.iterator];if(!n)return t;var r=n.call(t),i,a=[],o;try{for(;(e===void 0||e-- >0)&&!(i=r.next()).done;)a.push(i.value)}catch(c){o={error:c}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(o)throw o.error}}return a},Tb=function(t,e,n){if(arguments.length===2)for(var r=0,i=e.length,a;r<i;r++)(a||!(r in e))&&(a||(a=Array.prototype.slice.call(e,0,r)),a[r]=e[r]);return t.concat(a||Array.prototype.slice.call(e))},Sb="diag",en=function(){function t(){function e(i){return function(){for(var a=[],o=0;o<arguments.length;o++)a[o]=arguments[o];var c=Qt("diag");if(c)return c[i].apply(c,Tb([],Ob(a),!1))}}var n=this,r=function(i,a){var o,c,u;if(a===void 0&&(a={logLevel:pe.INFO}),i===n){var h=new Error("Cannot use diag as the logger for itself. Please use a DiagLogger implementation like ConsoleDiagLogger or a custom implementation");return n.error((o=h.stack)!==null&&o!==void 0?o:h.message),!1}typeof a=="number"&&(a={logLevel:a});var f=Qt("diag"),d=vb((c=a.logLevel)!==null&&c!==void 0?c:pe.INFO,i);if(f&&!a.suppressOverrideMessage){var k=(u=new Error().stack)!==null&&u!==void 0?u:"<failed to generate stacktrace>";f.warn("Current logger will be overwritten from "+k),d.warn("Current logger will overwrite one already registered from "+k)}return ii("diag",d,n,!0)};n.setLogger=r,n.disable=function(){ai(Sb,n)},n.createComponentLogger=function(i){return new bb(i)},n.verbose=e("verbose"),n.debug=e("debug"),n.info=e("info"),n.warn=e("warn"),n.error=e("error")}return t.instance=function(){return this._instance||(this._instance=new t),this._instance},t}(),zb=function(t,e){var n=typeof Symbol=="function"&&t[Symbol.iterator];if(!n)return t;var r=n.call(t),i,a=[],o;try{for(;(e===void 0||e-- >0)&&!(i=r.next()).done;)a.push(i.value)}catch(c){o={error:c}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(o)throw o.error}}return a},Nb=function(t){var e=typeof Symbol=="function"&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},Ib=function(){function t(e){this._entries=e?new Map(e):new Map}return t.prototype.getEntry=function(e){var n=this._entries.get(e);if(n)return Object.assign({},n)},t.prototype.getAllEntries=function(){return Array.from(this._entries.entries()).map(function(e){var n=zb(e,2),r=n[0],i=n[1];return[r,i]})},t.prototype.setEntry=function(e,n){var r=new t(this._entries);return r._entries.set(e,n),r},t.prototype.removeEntry=function(e){var n=new t(this._entries);return n._entries.delete(e),n},t.prototype.removeEntries=function(){for(var e,n,r=[],i=0;i<arguments.length;i++)r[i]=arguments[i];var a=new t(this._entries);try{for(var o=Nb(r),c=o.next();!c.done;c=o.next()){var u=c.value;a._entries.delete(u)}}catch(h){e={error:h}}finally{try{c&&!c.done&&(n=o.return)&&n.call(o)}finally{if(e)throw e.error}}return a},t.prototype.clear=function(){return new t},t}();en.instance();function Eb(t){return t===void 0&&(t={}),new Ib(new Map(Object.entries(t)))}function Ab(t){return Symbol.for(t)}var kb=function(){function t(e){var n=this;n._currentContext=e?new Map(e):new Map,n.getValue=function(r){return n._currentContext.get(r)},n.setValue=function(r,i){var a=new t(n._currentContext);return a._currentContext.set(r,i),a},n.deleteValue=function(r){var i=new t(n._currentContext);return i._currentContext.delete(r),i}}return t}(),xb=new kb,Cb={get:function(t,e){if(t!=null)return t[e]},keys:function(t){return t==null?[]:Object.keys(t)}},$b={set:function(t,e,n){t!=null&&(t[e]=n)}},Rb=function(t,e){var n=typeof Symbol=="function"&&t[Symbol.iterator];if(!n)return t;var r=n.call(t),i,a=[],o;try{for(;(e===void 0||e-- >0)&&!(i=r.next()).done;)a.push(i.value)}catch(c){o={error:c}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(o)throw o.error}}return a},jb=function(t,e,n){if(arguments.length===2)for(var r=0,i=e.length,a;r<i;r++)(a||!(r in e))&&(a||(a=Array.prototype.slice.call(e,0,r)),a[r]=e[r]);return t.concat(a||Array.prototype.slice.call(e))},Mb=function(){function t(){}return t.prototype.active=function(){return xb},t.prototype.with=function(e,n,r){for(var i=[],a=3;a<arguments.length;a++)i[a-3]=arguments[a];return n.call.apply(n,jb([r],Rb(i),!1))},t.prototype.bind=function(e,n){return n},t.prototype.enable=function(){return this},t.prototype.disable=function(){return this},t}(),Bb=function(t,e){var n=typeof Symbol=="function"&&t[Symbol.iterator];if(!n)return t;var r=n.call(t),i,a=[],o;try{for(;(e===void 0||e-- >0)&&!(i=r.next()).done;)a.push(i.value)}catch(c){o={error:c}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(o)throw o.error}}return a},Db=function(t,e,n){if(arguments.length===2)for(var r=0,i=e.length,a;r<i;r++)(a||!(r in e))&&(a||(a=Array.prototype.slice.call(e,0,r)),a[r]=e[r]);return t.concat(a||Array.prototype.slice.call(e))},Hr="context",Pb=new Mb,Yl=function(){function t(){}return t.getInstance=function(){return this._instance||(this._instance=new t),this._instance},t.prototype.setGlobalContextManager=function(e){return ii(Hr,e,en.instance())},t.prototype.active=function(){return this._getContextManager().active()},t.prototype.with=function(e,n,r){for(var i,a=[],o=3;o<arguments.length;o++)a[o-3]=arguments[o];return(i=this._getContextManager()).with.apply(i,Db([e,n,r],Bb(a),!1))},t.prototype.bind=function(e,n){return this._getContextManager().bind(e,n)},t.prototype._getContextManager=function(){return Qt(Hr)||Pb},t.prototype.disable=function(){this._getContextManager().disable(),ai(Hr,en.instance())},t}(),ks;(function(t){t[t.UNSET=0]="UNSET",t[t.OK=1]="OK",t[t.ERROR=2]="ERROR"})(ks||(ks={}));var Ub=Yl.getInstance(),Lb=function(){function t(){}return t.prototype.inject=function(e,n){},t.prototype.extract=function(e,n){return e},t.prototype.fields=function(){return[]},t}(),oi=Ab("OpenTelemetry Baggage Key");function Fl(t){return t.getValue(oi)||void 0}function _b(){return Fl(Yl.getInstance().active())}function Yb(t,e){return t.setValue(oi,e)}function Fb(t){return t.deleteValue(oi)}var Xr="propagation",qb=new Lb,Vb=function(){function t(){this.createBaggage=Eb,this.getBaggage=Fl,this.getActiveBaggage=_b,this.setBaggage=Yb,this.deleteBaggage=Fb}return t.getInstance=function(){return this._instance||(this._instance=new t),this._instance},t.prototype.setGlobalPropagator=function(e){return ii(Xr,e,en.instance())},t.prototype.inject=function(e,n,r){return r===void 0&&(r=$b),this._getGlobalPropagator().inject(e,n,r)},t.prototype.extract=function(e,n,r){return r===void 0&&(r=Cb),this._getGlobalPropagator().extract(e,n,r)},t.prototype.fields=function(){return this._getGlobalPropagator().fields()},t.prototype.disable=function(){ai(Xr,en.instance())},t.prototype._getGlobalPropagator=function(){return Qt(Xr)||qb},t}(),Wb=Vb.getInstance();const Oa=["bench","debug","prod"],Gb=t=>e=>Oa.indexOf(e)>=Oa.indexOf(t),xs=class ql{constructor(e,n=Gb("debug")){ee(this,"meta",si.NOOP),ee(this,"tracer"),ee(this,"filter"),this.tracer=e,this.filter=n}child(e){const n=new ql(this.tracer,this.filter);return n.meta=e,n}debug(e,n){return this.trace(e,"debug",n)}bench(e,n){return this.trace(e,"bench",n)}prod(e,n){return this.trace(e,"prod",n)}trace(e,n,r){return this.meta.noop||!this.filter(n)?r(new Gl(e)):this.tracer.startActiveSpan(e,i=>{const a=new Wl(e,i),o=r(a);return i.end(),o})}propagate(e){if(this.meta.noop)return;const n=Ub.active();Wb.inject(n,e,{set:(r,i,a)=>{r[i]=a}})}};ee(xs,"NOOP",new xs);let Vl=xs;class Wl{constructor(e,n){ee(this,"key"),ee(this,"otel"),this.key=e,this.otel=n}set(e,n){this.otel.setAttribute(e,n)}recordError(e){e!=null&&(this.otel.recordException(e),this.otel.setStatus({code:ks.ERROR}))}}class Gl{constructor(e){ee(this,"key"),this.key=e}set(){}recordError(e){}}const Cs=class Zl{constructor({key:e="",serviceName:n="",logger:r=_l.NOOP,tracer:i=Vl.NOOP,noop:a=!1,__meta:o}){ee(this,"meta"),ee(this,"T"),ee(this,"L"),this.meta=o??new si(e,e,n,a),this.T=i.child(this.meta),this.L=r.child(this.meta)}child(e){const n=this.meta.child(e);return new Zl({__meta:n,tracer:this.T,logger:this.L})}};ee(Cs,"NOOP",new Cs({noop:!0}));let li=Cs;const Zb=li.NOOP,Kl=Object.freeze(Object.defineProperty({__proto__:null,Instrumentation:li,LOG_LEVELS:Es,Logger:_l,NOOP:Zb,NoopSpan:Gl,Tracer:Vl,_Span:Wl,logLevelKeyFiler:db,logThresholdFilter:hb},Symbol.toStringTag,{value:"Module"})),Kb=new Error("request for lock canceled");var Jb=function(t,e,n,r){function i(a){return a instanceof n?a:new n(function(o){o(a)})}return new(n||(n=Promise))(function(a,o){function c(f){try{h(r.next(f))}catch(d){o(d)}}function u(f){try{h(r.throw(f))}catch(d){o(d)}}function h(f){f.done?a(f.value):i(f.value).then(c,u)}h((r=r.apply(t,e||[])).next())})};class Hb{constructor(e,n=Kb){this._value=e,this._cancelError=n,this._queue=[],this._weightedWaiters=[]}acquire(e=1,n=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return new Promise((r,i)=>{const a={resolve:r,reject:i,weight:e,priority:n},o=Jl(this._queue,c=>n<=c.priority);o===-1&&e<=this._value?this._dispatchItem(a):this._queue.splice(o+1,0,a)})}runExclusive(e){return Jb(this,arguments,void 0,function*(n,r=1,i=0){const[a,o]=yield this.acquire(r,i);try{return yield n(a)}finally{o()}})}waitForUnlock(e=1,n=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return this._couldLockImmediately(e,n)?Promise.resolve():new Promise(r=>{this._weightedWaiters[e-1]||(this._weightedWaiters[e-1]=[]),Xb(this._weightedWaiters[e-1],{resolve:r,priority:n})})}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 n=this._value;this._value-=e.weight,e.resolve([n,this._newReleaser(e.weight)])}_newReleaser(e){let n=!1;return()=>{n||(n=!0,this.release(e))}}_drainUnlockWaiters(){if(this._queue.length===0)for(let e=this._value;e>0;e--){const n=this._weightedWaiters[e-1];n&&(n.forEach(r=>r.resolve()),this._weightedWaiters[e-1]=[])}else{const e=this._queue[0].priority;for(let n=this._value;n>0;n--){const r=this._weightedWaiters[n-1];if(!r)continue;const i=r.findIndex(a=>a.priority<=e);(i===-1?r:r.splice(0,i)).forEach(a=>a.resolve())}}}_couldLockImmediately(e,n){return(this._queue.length===0||this._queue[0].priority<n)&&e<=this._value}}function Xb(t,e){const n=Jl(t,r=>e.priority<=r.priority);t.splice(n+1,0,e)}function Jl(t,e){for(let n=t.length-1;n>=0;n--)if(e(t[n]))return n;return-1}var Qb=function(t,e,n,r){function i(a){return a instanceof n?a:new n(function(o){o(a)})}return new(n||(n=Promise))(function(a,o){function c(f){try{h(r.next(f))}catch(d){o(d)}}function u(f){try{h(r.throw(f))}catch(d){o(d)}}function h(f){f.done?a(f.value):i(f.value).then(c,u)}h((r=r.apply(t,e||[])).next())})};class Hl{constructor(e){this._semaphore=new Hb(1,e)}acquire(){return Qb(this,arguments,void 0,function*(e=0){const[,n]=yield this._semaphore.acquire(1,e);return n})}runExclusive(e,n=0){return this._semaphore.runExclusive(()=>e(),1,n)}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()}}class Nr{constructor(e,n,r=new Map){P(this,"providers");P(this,"registry");P(this,"sender");P(this,"changedKeys");this.providers=r,this.registry=n,this.changedKeys=[],this.sender=e}propagateState(e,n,r=[]){this.sender.send({key:e,state:n},r)}copyAndMerge(e){const n=new Nr(this.sender,this.registry,new Map);return e==null||e.providers.forEach((r,i)=>n.providers.set(i,r)),this.providers.forEach((r,i)=>n.providers.set(i,r)),n.changedKeys=[],n}get changed(){return this.changedKeys.length>0}set(e,n,r=!0){this.providers.set(e,n),r&&this.changedKeys.push(e)}setIfNotHas(e,n){this.providers.has(e)||this.set(e,n)}async create(e){const n=this.registry[e.type];if(n==null)throw new Error(`[AetherRoot.create] - could not find component ${e.type}`);const r=new n(e);return await r.internalUpdate(e),r}getOptional(e){return this.providers.get(e)??null}has(e){return this.providers.has(e)}get(e){const n=this.getOptional(e);if(n==null)throw new Error(`[AetherRoot.get] - could not find provider ${e}`);return n}}class ci{constructor(e){P(this,"type");P(this,"key");P(this,"_ctx");P(this,"_internalState");P(this,"_state");P(this,"_prevState");P(this,"_deleted",!1);P(this,"instrumentation");P(this,"schema");this.type=e.type,this.key=e.path[0],this._ctx=e.ctx,this._internalState={},this.instrumentation=e.instrumentation.child(`${this.type}(${this.key})`)}get _schema(){if(this.schema==null)throw new K(`[AetherLeaf] - expected subclass to define component schema, but none was found.
|
|
67
|
-
Make sure to defne a property 'schema' on the class.`);return this.schema}setState(e){const n=
|
|
65
|
+
Please report this error to the Synnax team. ${JSON.stringify(e)}`),n!=null){if(qe.matches(n))return;throw n}}}closeSend(){this.stream.closeSend()}send(e){const n=this.stream.send(e);if(n!=null)throw n}}const wa=new $(-1);var Zs=(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))(Zs||{}),Ol=(t=>(t[t.None=0]="None",t[t.Ack=1]="Ack",t[t.Data=2]="Data",t))(Ol||{});const Yg=s.z.object({command:s.z.nativeEnum(Zs),span:$.z.optional(),bounds:se.z.optional(),stamp:x.z.optional(),keys:s.z.number().array().optional(),chunkSize:s.z.number().optional()}),qg=s.z.object({variant:s.z.nativeEnum(Ol),ack:s.z.boolean(),command:s.z.nativeEnum(Zs),error:sn.optional().nullable(),frame:Vs.optional()}),Tl=class Ss{constructor(e,n){l(this,"stream"),l(this,"adapter"),l(this,"value"),this.stream=new Gs("Iterator",e),this.value=new ve,this.adapter=n}static async _open(e,n,r,i,a={}){const o=await br.open(r,n),c=await i.stream(Ss.ENDPOINT,Yg,qg),u=new Ss(c,o);return await u.execute({command:0,keys:o.keys,bounds:new se(e),chunkSize:a.chunkSize??1e5}),u}async next(e=wa){return await this.execute({command:1,span:new $(e)})}async prev(e=wa){return await this.execute({command:2,span:new $(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 x(e)})}async seekGE(e){return await this.execute({command:6,stamp:new x(e)})}async valid(){return await this.execute({command:7})}async close(){await this.stream.closeAndAck()}[Symbol.asyncIterator](){return new Vg(this)}async execute(e){for(this.stream.send(e),this.value=new ve;;){const n=await this.stream.receive();if(n.variant===1)return n.ack;this.value.push(this.adapter.adapt(new ve(n.frame)))}}};l(Tl,"ENDPOINT","/frame/iterate");let Fg=Tl;class Vg{constructor(e){l(this,"iter"),l(this,"open",!1),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 Wg=s.z.object({keys:s.z.number().array(),downsampleFactor:s.z.number()}),Gg=s.z.object({frame:Vs,error:sn.optional().nullable()}),Zg="/frame/stream";class Ks{constructor(e,n){l(this,"stream"),l(this,"adapter"),l(this,"downsampleFactor"),this.stream=new Gs("Streamer",e),this.adapter=n,this.downsampleFactor=1}get keys(){return this.adapter.keys}static async _open(e,n,{channels:r,downsampleFactor:i}){const a=await br.open(e,r),o=await n.stream(Zg,Wg,Gg),c=new Ks(o,a);o.send({keys:a.keys,downsampleFactor:i??1});const[,u]=await o.receive();if(u!=null)throw u;return c}async next(){try{return{done:!1,value:await this.read()}}catch(e){if(qe.matches(e))return{done:!0,value:void 0};throw e}}async read(){return this.adapter.adapt(new ve((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 vr extends Qe.Observer{constructor(e,n){super(n),l(this,"streamer"),l(this,"closePromise"),this.streamer=e,this.closePromise=this.stream()}async close(){this.streamer.close(),await this.closePromise}async stream(){for await(const e of this.streamer)this.notify(e)}}var Js=(t=>(t[t.Open=0]="Open",t[t.Write=1]="Write",t[t.Commit=2]="Commit",t[t.Error=3]="Error",t[t.SetAuthority=4]="SetAuthority",t))(Js||{}),Jt=(t=>(t[t.PersistStream=1]="PersistStream",t[t.Persist=2]="Persist",t[t.Stream=3]="Stream",t))(Jt||{});const Kg=t=>{switch(t){case"persist":return 2;case"stream":return 3;case"persistStream":return 1;default:if(typeof t=="number"&&t in Jt)return t;throw new Error(`invalid writer mode: ${t}`)}};new $(-1);const Jg=s.z.object({start:x.z.optional(),controlSubject:lt.subjectZ.optional(),keys:s.z.number().array().optional(),authorities:lt.Authority.z.array().optional(),mode:s.z.nativeEnum(Jt).optional(),errOnUnauthorized:s.z.boolean().optional(),enableAutoCommit:s.z.boolean().optional(),autoIndexPersistInterval:$.z.optional()}),Hg=s.z.object({command:s.z.nativeEnum(Js),config:Jg.optional(),frame:Vs.optional()}),Xg=s.z.object({ack:s.z.boolean(),command:s.z.nativeEnum(Js),error:sn.optional().nullable()});var vt;let Qg=(vt=class{constructor(t,e){l(this,"stream"),l(this,"adapter"),this.stream=new Gs("Writer",t),this.adapter=e}static async _open(t,e,{channels:n,start:r=x.now(),authorities:i=lt.Authority.Absolute,controlSubject:a,mode:o=1,errOnUnauthorized:c=!1,enableAutoCommit:u=!1,autoIndexPersistInterval:h=$.SECOND}){const f=await Ws.open(t,n),d=await e.stream(vt.ENDPOINT,Hg,Xg),k=new vt(d,f);return await k.execute({command:0,config:{start:new x(r),keys:f.keys,controlSubject:a,authorities:T(i),mode:Kg(o),errOnUnauthorized:c,enableAutoCommit:u,autoIndexPersistInterval:h}}),k}async write(t,e){const n=await this.adapter.adapt(t,e);return this.stream.send({command:1,frame:n.toPayload()}),!0}async setAuthority(t,e){let n={keys:[],authorities:[]};if(typeof t=="number"&&e==null)n={keys:[],authorities:[t]};else{let r;typeof t=="string"||typeof t=="number"?r={[t]:e}:r=t,r=await this.adapter.adaptObjectKeys(r),n={keys:Object.keys(r).map(i=>Number(i)),authorities:Object.values(r)}}return(await this.execute({command:4,config:n})).ack}async commit(){return this.errorAccumulated?!1:(await this.execute({command:2})).ack}async error(){this.stream.send({command:3});const t=await this.execute({command:3});return t.error!=null?Ps(t.error):null}async close(){await this.stream.closeAndAck()}async execute(t){for(this.stream.send(t);;){const e=await this.stream.receive();if(e.command===t.command)return e;console.warn("writer received unexpected response",e)}}get errorAccumulated(){return this.stream.received()}},l(vt,"ENDPOINT","/frame/write"),vt),ep=class{constructor(t,e,n){l(this,"streamClient"),l(this,"retriever"),l(this,"deleter"),this.streamClient=t,this.retriever=n,this.deleter=new Ug(e)}async openIterator(t,e,n){return await Fg._open(t,e,this.retriever,this.streamClient,n)}async openWriter(t){return(Array.isArray(t)||typeof t!="object")&&(t={channels:t}),await Qg._open(this.retriever,this.streamClient,t)}async openStreamer(t){return(Array.isArray(t)||typeof t!="object")&&(t={channels:t,downsampleFactor:1}),await Ks._open(this.retriever,this.streamClient,t)}async write(t,e,n){if(n==null){const i=e,a=await this.openWriter({start:t,channels:Object.keys(i),mode:Jt.Persist});try{await a.write(i),await a.commit()}finally{await a.close()}return}const r=await this.openWriter({start:t,channels:e,mode:Jt.Persist,errOnUnauthorized:!0,enableAutoCommit:!0,autoIndexPersistInterval:$.MAX});try{await r.write(e,n)}finally{await r.close()}}async read(t,e){const{single:n}=De(e),r=await this.readFrame(t,e);return n?r.get(e):r}async readFrame(t,e){const n=await this.openIterator(t,e),r=new ve;try{for await(const i of n)r.push(i)}finally{await n.close()}return r}async delete(t,e){const{normalized:n,variant:r}=De(t);return r==="keys"?await this.deleter.delete({keys:n,bounds:e}):await this.deleter.delete({names:n,bounds:e})}};const tp=lt.Authority,np=lt.stateZ(s.z.number()),rp=t=>{var e,n;return t.to==null?`${(e=t.from)==null?void 0:e.resource} - ${(n=t.from)==null?void 0:n.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()})`};class Sl extends vr{constructor(e){super(e,n=>{const r=this.codec.decode(n.series[0].data);return this.merge(r),[r.transfers,!0]}),l(this,"states"),l(this,"codec"),this.states=new Map,this.codec=new dt.JSONCodec}subjects(){const e=new Map;return this.states.forEach(n=>e.set(n.subject.key,n.subject)),Array.from(e.values())}merge(e){e.transfers.forEach(n=>{n.from==null&&n.to==null&&console.warn("Invalid transfer: ",n),n.to==null?this.states.delete(n.from.resource):this.states.set(n.to.resource,n.to)})}}const sp="sy_node_1_control";let zl=class{constructor(t){l(this,"framer"),this.framer=t}async openStateTracker(){const t=await this.framer.openStreamer(sp);return new Sl(t)}};const ip=Object.freeze(Object.defineProperty({__proto__:null,Authority:tp,Client:zl,StateTracker:Sl,stateZ:np,transferString:rp},Symbol.toStringTag,{value:"Module"}));let ap=class{constructor(t,e,n){l(this,"tasks"),l(this,"racks"),l(this,"devices"),this.tasks=t,this.racks=e,this.devices=n}};const cn=s.z.number(),Hs=s.z.object({key:cn,name:s.z.string()}),op=Hs.partial({key:!0}),Xs=s.z.string(),Or=s.z.object({key:Xs,rack:cn,name:s.z.string(),make:s.z.string(),model:s.z.string(),location:s.z.string(),configured:s.z.boolean().optional(),properties:s.z.record(s.z.unknown()).or(s.z.string().transform(t=>t===""?{}:dt.JSON_CODEC.decodeString(t)))}),lp=Or.extend({properties:s.z.unknown().transform(t=>dt.JSON_CODEC.encodeString(t))}),yt=async(t,e,n,r)=>{const i=await t.openStreamer([e,n]),a=o=>{const c=[];return n!=null&&c.push(...o.get(n).series.flatMap(u=>r("delete",u))),e!=null&&c.push(...o.get(e).series.flatMap(u=>r("set",u))),[c,c.length>0]};return new vr(i,a)},cp="sy_device_set",up="sy_device_delete",qr="/hardware/device/retrieve",hp="/hardware/device/create",dp="/hardware/device/delete",fp=s.z.object({devices:lp.array()}),yp=s.z.object({devices:Or.array()}),gp=s.z.object({keys:Xs.array()}),pp=s.z.object({}),Fr=s.z.object({search:s.z.string().optional(),limit:s.z.number().optional(),offset:s.z.number().optional(),keys:Xs.array().optional(),names:s.z.string().array().optional(),makes:s.z.string().array().optional()}),Vr=s.z.object({devices:me(Or)});let mp=class{constructor(t,e){l(this,"type","device"),l(this,"client"),l(this,"frameClient"),this.client=t,this.frameClient=e}async retrieve(t,e){const n=!Array.isArray(t),r=await v(this.client,qr,{keys:T(t),...e},Fr,Vr);return mr("Device",t,r.devices,n),n?r.devices[0]:r.devices}async search(t,e){return(await v(this.client,qr,{search:t,...e},Fr,Vr)).devices}async page(t,e,n){return(await v(this.client,qr,{offset:t,limit:e,...n},Fr,Vr)).devices}async create(t){const e=!Array.isArray(t),n=await v(this.client,hp,{devices:T(t)},fp,yp);return e?n.devices[0]:n.devices}async delete(t){await v(this.client,dp,{keys:T(t)},gp,pp)}async openDeviceTracker(){return await yt(this.frameClient,cp,up,wp)}newSearcherWithOptions(t){return{type:this.type,search:async e=>await this.search(e,t),retrieve:async e=>await this.retrieve(e,t),page:async(e,n)=>await this.page(e,n,t)}}};const wp=(t,e)=>t==="delete"?e.toStrings().map(n=>({variant:t,key:n,value:void 0})):e.parseJSON(Or).map(n=>({variant:t,key:n.key,value:n})),Wr="/hardware/rack/retrieve",bp="/hardware/rack/create",vp="/hardware/rack/delete",Gr=s.z.object({keys:cn.array().optional(),names:s.z.string().array().optional(),search:s.z.string().optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),Zr=s.z.object({racks:me(Hs)}),Op=s.z.object({racks:op.array()}),Tp=s.z.object({racks:Hs.array()}),Sp=s.z.object({keys:cn.array()}),zp=s.z.object({});let Np=class{constructor(t,e,n){l(this,"type","rack"),l(this,"client"),l(this,"frameClient"),l(this,"tasks"),this.client=t,this.frameClient=e,this.tasks=n}async delete(t){await v(this.client,vp,{keys:T(t)},Sp,zp)}async create(t){const e=!Array.isArray(t),n=await v(this.client,bp,{racks:T(t)},Op,Tp),r=this.sugar(n.racks);return e?r[0]:r}async search(t){const e=await v(this.client,Wr,{search:t},Gr,Zr);return this.sugar(e.racks)}async page(t,e){const n=await v(this.client,Wr,{offset:t,limit:e},Gr,Zr);return this.sugar(n.racks)}async retrieve(t){const{variant:e,normalized:n,single:r}=pr(t,{string:"names",number:"keys"}),i=await v(this.client,Wr,{[e]:n},Gr,Zr),a=this.sugar(i.racks);return mr("Rack",t,a,r),r?a[0]:a}sugar(t){return t.map(({key:e,name:n})=>new Ip(e,n,this.tasks))}};class Ip{constructor(e,n,r){l(this,"key"),l(this,"name"),l(this,"tasks"),this.key=e,this.name=n,this.tasks=r}async listTasks(){return await this.tasks.retrieve(this.key)}async retrieveTaskByName(e){return await this.tasks.retrieveByName(e,this.key)}async createTask(e){return e.key=((BigInt(this.key)<<32n)+(BigInt(e.key??0)&0xffffffffn)).toString(),await this.tasks.create(e)}async deleteTask(e){await this.tasks.delete([e])}}const gt=s.z.union([s.z.string(),s.z.bigint().transform(t=>t.toString()),s.z.number().transform(t=>t.toString())]),sr=s.z.object({task:gt,variant:s.z.string(),key:s.z.string().optional(),details:s.z.record(s.z.unknown()).or(s.z.string().transform(t=>t===""?{}:JSON.parse(t))).or(s.z.array(s.z.unknown())).or(s.z.null())}),Tr=s.z.object({key:gt,name:s.z.string(),type:s.z.string(),internal:s.z.boolean().optional(),config:s.z.record(s.z.unknown()).or(s.z.string().transform(t=>t===""?{}:dt.JSON_CODEC.decodeString(t))),state:sr.optional().nullable(),snapshot:s.z.boolean().optional()}),Ep=Tr.omit({key:!0}).extend({key:gt.transform(t=>t.toString()).optional(),config:s.z.unknown().transform(t=>dt.JSON_CODEC.encodeString(t))});s.z.object({task:gt,type:s.z.string(),key:s.z.string(),args:s.z.record(s.z.unknown()).or(s.z.string().transform(t=>t===""?{}:JSON.parse(t)))});const Wt="sy_task_state",ba="sy_task_cmd",mn=new Error("Task not created");class Ap{constructor(e,n,r,i,a=!1,o=!1,c,u=null,h=null,f=null){l(this,"key"),l(this,"name"),l(this,"internal"),l(this,"type"),l(this,"config"),l(this,"snapshot"),l(this,"state"),l(this,"frameClient"),l(this,"ontologyClient"),l(this,"rangeClient"),this.key=e,this.name=n,this.type=r,this.config=i,this.internal=a,this.snapshot=o,c!==null&&(this.state=c),this.frameClient=u,this.ontologyClient=h,this.rangeClient=f}get payload(){return{key:this.key,name:this.name,type:this.type,config:this.config,state:this.state,internal:this.internal}}get ontologyID(){return new R({type:"task",key:this.key})}async executeCommand(e,n){if(this.frameClient==null)throw mn;const r=await this.frameClient.openWriter(ba),i=If.id();return await r.write(ba,[{task:this.key,type:e,key:i,args:n}]),await r.close(),i}async executeCommandSync(e,n,r){if(this.frameClient==null)throw mn;const i=await this.frameClient.openStreamer(Wt),a=await this.executeCommand(e,n);let o;const c=new Promise(u=>setTimeout(()=>u(!1),new $(r).milliseconds));for(;;){const u=await Promise.any([i.read(),c]);if(u===!1)throw new Error("Command timed out");const h=sr.safeParse(u.at(-1).sy_task_state);if(h.success){if(o=h.data,o.key===a)break}else console.error(h.error)}return i.close(),o}async openStateObserver(){if(this.frameClient==null)throw mn;return new vr(await this.frameClient.openStreamer(Wt),e=>{const n=e.get(Wt);if(n.length===0)return[null,!1];const r=sr.safeParse(n.at(-1));if(!r.success)return[null,!1];const i=r.data;return i.task!==this.key?[null,!1]:[i,!0]})}async snapshottedTo(){if(this.ontologyClient==null||this.rangeClient==null)throw mn;if(!this.snapshot)return null;const e=await this.ontologyClient.retrieveParents(this.ontologyID);return e.length==0?null:e[0]}}const kp=s.z.object({rack:cn.optional(),keys:s.z.string().array().optional(),names:s.z.string().array().optional(),offset:s.z.number().optional(),limit:s.z.number().optional(),includeState:s.z.boolean().optional()}),xp=s.z.object({tasks:me(Tr)}),Cp="/hardware/task/retrieve",$p="/hardware/task/create",Rp="/hardware/task/delete",jp="/hardware/task/copy",Bp=s.z.object({tasks:Ep.array()}),Mp=s.z.object({tasks:Tr.array()}),Dp=s.z.object({keys:gt.array()}),Pp=s.z.object({}),Up=s.z.object({key:gt,name:s.z.string(),snapshot:s.z.boolean()}),Lp=s.z.object({task:Tr});let _p=class{constructor(t,e,n,r){l(this,"type","task"),l(this,"client"),l(this,"frameClient"),l(this,"ontologyClient"),l(this,"rangeClient"),this.client=t,this.frameClient=e,this.ontologyClient=n,this.rangeClient=r}async create(t){const e=!Array.isArray(t),n=await v(this.client,$p,{tasks:T(t)},Bp,Mp),r=this.sugar(n.tasks);return e?r[0]:r}async delete(t){await v(this.client,Rp,{keys:T(t)},Dp,Pp)}async search(t){return await this.execRetrieve({keys:[t]})}async page(t,e){return await this.execRetrieve({offset:t,limit:e})}async list(t={}){return this.sugar(await this.execRetrieve(t))}async retrieve(t,e){const{single:n,normalized:r,variant:i}=pr(t,{number:"rack",string:"keys"},{convertNumericStrings:!1}),a={...e};i==="rack"?a.rack=t:a.keys=r;const o=await this.execRetrieve(a),c=this.sugar(o);return n&&i!=="rack"?c[0]:c}async copy(t,e,n){const r=await v(this.client,jp,{key:t,name:e,snapshot:n},Up,Lp);return this.sugar([r.task])[0]}async retrieveByName(t,e){const n=await this.execRetrieve({names:[t],rack:e});return mr("Task",t,n,!0),this.sugar(n)[0]}async execRetrieve(t){return(await v(this.client,Cp,t,kp,xp)).tasks}sugar(t){return t.map(({key:e,name:n,type:r,config:i,state:a,internal:o,snapshot:c})=>new Ap(e,n,r,i,o,c,a,this.frameClient,this.ontologyClient,this.rangeClient))}async openTracker(){return await yt(this.frameClient,"sy_task_set","sy_task_delete",(t,e)=>Array.from(e).map(n=>({variant:t,key:n.toString(),value:n.toString()})))}async openStateObserver(){return new vr(await this.frameClient.openStreamer(Wt),t=>{const e=t.get(Wt);if(e.length===0)return[null,!1];const n=sr.safeParse(e.at(-1));return n.success?[n.data,!0]:[null,!1]})}};const un=s.z.string().uuid(),Sr=s.z.object({key:un,name:s.z.string().min(1),color:s.z.string()}),Yp=s.z.object({keys:un.array().optional(),for:ge.optional(),search:s.z.string().optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),qp=s.z.object({labels:me(Sr)});var wn;let Fp=(wn=class{constructor(t){l(this,"client"),this.client=t}async retrieve(t){const e=T(t);return await this.execute({keys:e})}async retrieveFor(t){return await this.execute({for:t})}async search(t){return await this.execute({search:t})}async page(t,e){return await this.execute({offset:t,limit:e})}async execute(t){const[e,n]=await this.client.send(wn.ENDPOINT,t,Yp,qp);if(n!=null)throw n;return e.labels}},l(wn,"ENDPOINT","/label/retrieve"),wn);const Vp=Sr.extend({key:un.optional()}),Wp=s.z.object({labels:Vp.array()}),Gp=s.z.object({labels:Sr.array()}),Zp=s.z.object({keys:un.array()}),Nl=s.z.object({id:ge,labels:un.array(),replace:s.z.boolean().optional()}),Kp=Nl.omit({replace:!0}),Kr=s.z.object({}),Jp="/label/create",Hp="/label/delete",Xp="/label/set",Qp="/label/remove";let em=class{constructor(t){l(this,"client"),this.client=t}async create(t){return(await v(this.client,Jp,{labels:T(t)},Wp,Gp)).labels}async delete(t){await v(this.client,Hp,{keys:T(t)},Zp,Kr)}async set(t,e,{replace:n}={}){await v(this.client,Xp,{id:t,labels:e,replace:n},Nl,Kr)}async remove(t,e){await v(this.client,Qp,{id:t,labels:e},Kp,Kr)}};const tm="sy_label_set",nm="sy_label_delete";let rm=class{constructor(t,e,n){l(this,"type","label"),l(this,"retriever"),l(this,"writer"),l(this,"frameClient"),l(this,"ontology"),this.writer=new em(t),this.retriever=new Fp(t),this.frameClient=e,this.ontology=n}async search(t){return await this.retriever.search(t)}async retrieve(t){const e=Array.isArray(t),n=await this.retriever.retrieve(t);return e?n:n[0]}async retrieveFor(t){return await this.retriever.retrieveFor(new R(t))}async label(t,e,n={}){await this.writer.set(new R(t),e,n)}async removeLabels(t,e){await this.writer.remove(new R(t),e)}async page(t,e){return await this.retriever.page(t,e)}async create(t){const e=Array.isArray(t),n=await this.writer.create(t);return e?n:n[0]}async delete(t){await this.writer.delete(t)}async openChangeTracker(){return await yt(this.frameClient,tm,nm,sm)}async trackLabelsOf(t){const e=new Qe.Observer,n=(await this.retrieveFor(t)).map(r=>({id:new R({key:r.key,type:"label"}),key:r.key,name:r.name,data:r}));return(await this.ontology.openDependentTracker({target:new R(t),dependents:n,relationshipType:"labeled_by"})).onChange(r=>e.notify(r.map(i=>{var a,o;return{key:i.id.key,color:(a=i.data)==null?void 0:a.color,name:(o=i.data)==null?void 0:o.name}}))),e}};const sm=(t,e)=>t==="delete"?e.toUUIDs().map(n=>({variant:t,key:n})):e.parseJSON(Sr).map(n=>({variant:t,key:n.key,value:n})),ye=s.z.string().uuid(),hn=s.z.object({key:ye,name:s.z.string().min(1),timeRange:se.z,color:s.z.string().optional()}),Il=hn.extend({key:s.z.string().uuid().optional()}),El=t=>{const e=T(t),n=e.length===0;let r=!1;return n||(r=ye.safeParse(e[0]).success),{single:!Array.isArray(t),variant:r?"keys":"names",normalized:e,actual:t,empty:n}},Al="range",kl="range-alias",im=t=>new R({type:Al,key:t}),am=t=>new R({type:kl,key:t}),om="sy_range_alias_set",lm="sy_range_alias_delete",cm=s.z.object({range:ye,aliases:s.z.string().array()}),um=s.z.object({aliases:s.z.record(s.z.string(),Ve)}),hm=s.z.object({range:ye,aliases:s.z.record(Ve.or(s.z.string()),s.z.string())}),dm=s.z.unknown(),fm=s.z.object({range:ye,channels:Ve.array()}),ym=s.z.unknown(),gm=s.z.object({range:ye}),pm=s.z.object({aliases:s.z.record(s.z.string(),s.z.string())}),Lt=class _t{constructor(e,n,r){l(this,"frameClient"),l(this,"cache",new Map),l(this,"client"),l(this,"rangeKey"),this.rangeKey=e,this.cache=new Map,this.client=r,this.frameClient=n}async resolve(e){const n=[],r=typeof e=="string",i={};if(r){const o=this.cache.get(e);if(o!=null)return o;n.push(e)}else e.forEach(o=>{const c=this.cache.get(o);c!=null?i[o]=c:n.push(o)});if(n.length===0)return i;const a=await v(this.client,_t.RESOLVE_ENDPOINT,{range:this.rangeKey,aliases:n},cm,um);return Object.entries(a.aliases).forEach(([o,c])=>this.cache.set(o,c)),r?a.aliases[n[0]]:{...i,...a.aliases}}async set(e){await v(this.client,_t.SET_ENDPOINT,{range:this.rangeKey,aliases:e},hm,dm)}async list(){return(await v(this.client,_t.LIST_ENDPOINT,{range:this.rangeKey},gm,pm)).aliases}async delete(e){await v(this.client,_t.DELETE_ENDPOINT,{range:this.rangeKey,channels:e},fm,ym)}async openChangeTracker(){return await yt(this.frameClient,om,lm,vm(this.rangeKey))}};l(Lt,"SET_ENDPOINT","/range/alias/set"),l(Lt,"RESOLVE_ENDPOINT","/range/alias/resolve"),l(Lt,"LIST_ENDPOINT","/range/alias/list"),l(Lt,"DELETE_ENDPOINT","/range/alias/delete");let mm=Lt;const wm=s.z.object({range:ye,channel:Ve,alias:s.z.string()}),bm="---",vm=t=>(e,n)=>e==="delete"?n.toStrings().filter(r=>r.split(bm)[0]===t).map(r=>({variant:e,key:r,value:void 0})):n.parseJSON(wm).map(r=>({variant:e,key:r.alias,value:r})),Om=s.z.object({range:ye,keys:s.z.string().array()}),Qs=s.z.object({range:ye,key:s.z.string(),value:s.z.string()}),Tm=s.z.object({pairs:me(Qs)}),Sm=s.z.object({range:ye,pairs:Qs.array()}),zm=s.z.object({range:ye,keys:s.z.string().array()}),Hn=class Xn{constructor(e,n,r){l(this,"rangeKey"),l(this,"client"),l(this,"frameClient"),this.rangeKey=e,this.client=n,this.frameClient=r}async get(e){const n=await v(this.client,Xn.GET_ENDPOINT,{range:this.rangeKey,keys:T(e)},Om,Tm);return typeof e=="string"?n.pairs[0].value:Object.fromEntries(n.pairs.map(r=>[r.key,r.value]))}async list(){return this.get([])}async set(e,n=""){let r;Us(e)?r=Object.entries(e).map(([i,a])=>({range:this.rangeKey,key:i,value:a})):r=[{range:this.rangeKey,key:e,value:n}],await v(this.client,Xn.SET_ENDPOINT,{range:this.rangeKey,pairs:r},Sm,s.z.unknown())}async delete(e){await v(this.client,Xn.DELETE_ENDPOINT,{range:this.rangeKey,keys:T(e)},zm,s.z.unknown())}async openTracker(){return await yt(this.frameClient,"sy_range_kv_set","sy_range_kv_delete",(e,n)=>e==="delete"?n.toStrings().map(r=>{const[i,a]=r.split("<--->",2);return{variant:e,key:r,value:{range:i,key:a,value:""}}}):n.parseJSON(Qs).map(r=>({variant:e,key:`${r.range}${r.key}`,value:r})))}};l(Hn,"GET_ENDPOINT","/range/kv/get"),l(Hn,"SET_ENDPOINT","/range/kv/set"),l(Hn,"DELETE_ENDPOINT","/range/kv/delete");let zs=Hn;const Jr=t=>new R({type:"range",key:t});class xl{constructor(e,n=se.ZERO,r,i,a,o,c,u,h,f,d){l(this,"key"),l(this,"name"),l(this,"kv"),l(this,"timeRange"),l(this,"color"),l(this,"channels"),l(this,"aliaser"),l(this,"frameClient"),l(this,"labelClient"),l(this,"ontologyClient"),l(this,"rangeClient"),this.key=r,this.name=e,this.timeRange=n,this.frameClient=a,this.color=i,this.kv=o,this.aliaser=c,this.channels=u,this.labelClient=h,this.ontologyClient=f,this.rangeClient=d}get ontologyID(){return new R({key:this.key,type:"range"})}get payload(){return{key:this.key,name:this.name,timeRange:this.timeRange,color:this.color}}async setAlias(e,n){const r=await this.channels.retrieve(e);if(r.length===0)throw new Oe(`Channel ${e} does not exist`);await this.aliaser.set({[r[0].key]:n})}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 openAliasTracker(){return await this.aliaser.openChangeTracker()}async retrieveParent(){return this.rangeClient.retrieveParent(this.key)}async retrieveChildren(){const e=(await this.ontologyClient.retrieveChildren(this.ontologyID,{excludeFieldData:!0,types:["range"]})).map(n=>n.id.key);return await this.rangeClient.retrieve(e)}async read(e){return await this.frameClient.read(this.timeRange,e)}async labels(){return await this.labelClient.retrieveFor(Jr(this.key))}async addLabel(...e){await this.labelClient.label(Jr(this.key),e)}async removeLabel(...e){await this.labelClient.removeLabels(Jr(this.key),e)}async openChildRangeTracker(){const e=new Qe.Observer,n=(await this.retrieveChildren()).map(i=>{const a=new R({key:i.key,type:"range"});return{id:a,key:a.toString(),name:i.name,data:i.payload}}),r=await this.ontologyClient.openDependentTracker({target:this.ontologyID,dependents:n,resourceType:"range"});return r.onChange(i=>e.notify(this.rangeClient.resourcesToRanges(i))),e.setCloser(async()=>await r.close()),e}async openParentRangeTracker(){const e=new Qe.Observer,n=await this.retrieveParent();if(n==null)return null;const r=new R({key:n.key,type:"range"}),i={id:r,key:r.toString(),name:n.name,data:n.payload},a=await this.ontologyClient.openDependentTracker({target:this.ontologyID,dependents:[i],relationshipDirection:"to"});return a.onChange(o=>{const c=this.rangeClient.resourcesToRanges(o);if(c.length===0)return;const u=c[0];e.notify(u)}),e.setCloser(async()=>await a.close()),e}}const Nm=s.z.object({keys:ye.array().optional(),names:s.z.array(s.z.string()).optional(),term:s.z.string().optional(),overlapsWith:se.z.optional(),limit:s.z.number().int().optional(),offset:s.z.number().int().optional()}),Im="/range/retrieve",Em=s.z.object({ranges:me(hn)});let Cl=class{constructor(t,e,n,r,i,a){l(this,"type","range"),l(this,"frameClient"),l(this,"writer"),l(this,"unaryClient"),l(this,"channels"),l(this,"labelClient"),l(this,"ontologyClient"),this.frameClient=t,this.writer=e,this.unaryClient=n,this.channels=r,this.labelClient=i,this.ontologyClient=a}async create(t,e){const n=!Array.isArray(t),r=this.sugarMany(await this.writer.create(T(t),e));return n?r[0]:r}async rename(t,e){await this.writer.rename(t,e)}async delete(t){await this.writer.delete(T(t))}async search(t){return this.sugarMany(await this.execRetrieve({term:t}))}async page(t,e){return this.sugarMany(await this.execRetrieve({offset:t,limit:e}))}async retrieve(t){if(typeof t=="object"&&"start"in t)return await this.execRetrieve({overlapsWith:new se(t)});const{single:e,actual:n,variant:r,normalized:i,empty:a}=El(t);if(a)return[];const o=await this.execRetrieve({[r]:i});if(!e)return o;if(o.length===0)throw new ct(`range matching ${n} not found`);if(o.length>1)throw new ut(`multiple ranges matching ${n} found`);return o[0]}getKV(t){return new zs(t,this.unaryClient,this.frameClient)}async execRetrieve(t){const{ranges:e}=await v(this.unaryClient,Im,t,Nm,Em);return this.sugarMany(e)}async retrieveParent(t){const e=await this.ontologyClient.retrieveParents({key:t,type:"range"});if(e.length===0)return null;const n=e[0];return n.id.type!=="range"?null:await this.retrieve(n.id.key)}sugarOne(t){return new xl(t.name,t.timeRange,t.key,t.color,this.frameClient,new zs(t.key,this.unaryClient,this.frameClient),new mm(t.key,this.frameClient,this.unaryClient),this.channels,this.labelClient,this.ontologyClient,this)}sugarMany(t){return t.map(e=>this.sugarOne(e))}async openTracker(){return await yt(this.frameClient,"sy_range_set","sy_range_delete",(t,e)=>t==="delete"?e.toStrings().map(n=>({variant:t,key:n,value:void 0})):this.sugarMany(e.parseJSON(hn)).map(n=>({variant:t,key:n.key,value:n})))}resourcesToRanges(t){return t.map(e=>this.resourceToRange(e))}resourceToRange(t){var e,n,r;return this.sugarOne({key:t.id.key,name:(e=t.data)==null?void 0:e.name,timeRange:new se((n=t.data)==null?void 0:n.timeRange),color:(r=t.data)==null?void 0:r.color})}};const Am=s.z.object({ranges:hn.array()}),km=s.z.object({parent:ge.optional(),ranges:Il.array()}),xm=s.z.object({keys:ye.array()}),Cm=s.z.object({}),$m=s.z.object({key:ye,name:s.z.string()}),Rm=s.z.object({}),jm="/range/create",Bm="/range/delete",Mm="/range/rename";let $l=class{constructor(t){l(this,"client"),this.client=t}async rename(t,e){await v(this.client,Mm,{key:t,name:e},$m,Rm)}async create(t,e){return(await v(this.client,jm,{ranges:t,...e},km,Am)).ranges}async delete(t){await v(this.client,Bm,{keys:t},xm,Cm)}};const Dm=Object.freeze(Object.defineProperty({__proto__:null,ALIAS_ONTOLOGY_TYPE:kl,Client:Cl,KV:zs,ONTOLOGY_TYPE:Al,Range:xl,Writer:$l,analyzeParams:El,keyZ:ye,newPayloadZ:Il,payloadZ:hn,rangeAliasOntologyID:am,rangeOntologyID:im},Symbol.toStringTag,{value:"Module"})),Pm="/api/v1/";class Um{constructor(e,n=!1){l(this,"url"),l(this,"unary"),l(this,"stream"),l(this,"secure"),this.secure=n,this.url=e.child(Pm);const r=new dt.JSONCodec;this.unary=new pd(this.url,r,this.secure),this.stream=new Nd(this.url,r,this.secure)}use(...e){this.unary.use(...e),this.stream.use(...e)}}const ei=s.z.string().uuid(),ti=s.z.object({key:s.z.string(),name:s.z.string(),data:dr.or(s.z.string().transform(t=>JSON.parse(t)))}),Lm=s.z.object({keys:s.z.string().array()}),_m=s.z.object({linePlots:ti.array()});let Ym=class{constructor(t){l(this,"ENDPOINT","/workspace/lineplot/retrieve"),l(this,"client"),this.client=t}async retrieve(t){const e=T(t);return(await v(this.client,this.ENDPOINT,{keys:e},Lm,_m)).linePlots}};const We=s.z.string().uuid(),Rl=t=>JSON.parse(t),jl=s.z.object({name:s.z.string(),key:We,layout:dr.or(s.z.string().transform(t=>Rl(t)))}),Bl=jl.omit({layout:!0}).extend({layout:s.z.string().transform(t=>Rl(t))}),qm=ti.partial({key:!0}).transform(t=>({...t,data:JSON.stringify(t.data)})),Fm=s.z.object({workspace:We,linePlots:qm.array()}),Vm=s.z.object({linePlots:ti.array()}),Wm=s.z.object({keys:ei.array()}),Gm=s.z.object({}),Zm=s.z.object({key:ei,name:s.z.string()}),Km=s.z.object({}),Jm=s.z.object({key:ei,data:s.z.string()}),Hm=s.z.object({}),Xm="/workspace/lineplot/create",Qm="/workspace/lineplot/delete",ew="/workspace/lineplot/rename",tw="/workspace/lineplot/set-data";let nw=class{constructor(t){l(this,"client"),this.client=t}async create(t,e){const n={...e,data:JSON.stringify(e.data)};return(await v(this.client,Xm,{workspace:t,linePlots:[n]},Fm,Vm)).linePlots[0]}async delete(t){const e=T(t);await v(this.client,Qm,{keys:e},Wm,Gm)}async rename(t,e){await v(this.client,ew,{key:t,name:e},Zm,Km)}async setData(t,e){await v(this.client,tw,{key:t,data:JSON.stringify(e)},Jm,Hm)}},rw=class{constructor(t){l(this,"writer"),l(this,"retriever"),this.writer=new nw(t),this.retriever=new Ym(t)}async create(t,e){return await this.writer.create(t,e)}async rename(t,e){await this.writer.rename(t,e)}async setData(t,e){await this.writer.setData(t,e)}async retrieve(t){const e=Array.isArray(t),n=await this.retriever.retrieve(t);return e?n:n[0]}async delete(t){await this.writer.delete(t)}};const ni=s.z.string().uuid(),sw=s.z.object({key:s.z.string(),name:s.z.string(),data:dr.or(s.z.string().transform(t=>JSON.parse(t)))}),Ml=s.z.object({key:s.z.string(),name:s.z.string(),data:s.z.string().transform(t=>JSON.parse(t))}),iw=s.z.object({keys:s.z.string().array()}),aw=s.z.object({logs:Ml.array()});let ow=class{constructor(t){l(this,"ENDPOINT","/workspace/log/retrieve"),l(this,"client"),this.client=t}async retrieve(t){return(await v(this.client,this.ENDPOINT,{keys:T(t)},iw,aw)).logs}};const lw=sw.partial({key:!0}).transform(t=>({...t,data:JSON.stringify(t.data)})),cw=s.z.object({workspace:We,logs:lw.array()}),uw=s.z.object({logs:Ml.array()}),hw=s.z.object({keys:ni.array()}),dw=s.z.object({}),fw=s.z.object({key:ni,name:s.z.string()}),yw=s.z.object({}),gw=s.z.object({key:ni,data:s.z.string()}),pw=s.z.object({}),mw="/workspace/log/create",ww="/workspace/log/delete",bw="/workspace/log/rename",vw="/workspace/log/set-data";let Ow=class{constructor(t){l(this,"client"),this.client=t}async create(t,e){const n={...e,data:JSON.stringify(e.data)};return(await v(this.client,mw,{workspace:t,logs:[n]},cw,uw)).logs[0]}async delete(t){const e=T(t);await v(this.client,ww,{keys:e},hw,dw)}async rename(t,e){await v(this.client,bw,{key:t,name:e},fw,yw)}async setData(t,e){await v(this.client,vw,{key:t,data:JSON.stringify(e)},gw,pw)}},Tw=class{constructor(t){l(this,"writer"),l(this,"retriever"),this.writer=new Ow(t),this.retriever=new ow(t)}async create(t,e){return await this.writer.create(t,e)}async rename(t,e){await this.writer.rename(t,e)}async setData(t,e){await this.writer.setData(t,e)}async retrieve(t){const e=Array.isArray(t),n=await this.retriever.retrieve(t);return e?n:n[0]}async delete(t){await this.writer.delete(t)}};const Sw=s.z.object({keys:We.array().optional(),search:s.z.string().optional(),author:s.z.string().uuid().optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),zw=s.z.object({workspaces:me(Bl)});var bn;let Nw=(bn=class{constructor(t){l(this,"client"),this.client=t}async retrieve(t){const e=T(t);return await this.execute({keys:e})}async retrieveByAuthor(t){return await this.execute({author:t})}async search(t){return await this.execute({search:t})}async page(t,e){return await this.execute({offset:t,limit:e})}async execute(t){return(await v(this.client,bn.ENDPOINT,t,Sw,zw)).workspaces}},l(bn,"ENDPOINT","/workspace/retrieve"),bn);const zr=s.z.string().uuid(),Iw=s.z.object({key:s.z.string(),name:s.z.string(),data:dr.or(s.z.string().transform(t=>JSON.parse(t))),snapshot:s.z.boolean()}),ri=s.z.object({key:s.z.string(),name:s.z.string(),snapshot:s.z.boolean(),data:s.z.string().transform(t=>JSON.parse(t))}),Ew=s.z.object({keys:s.z.string().array()}),Aw=s.z.object({schematics:ri.array()});class kw{constructor(e){l(this,"ENDPOINT","/workspace/schematic/retrieve"),l(this,"client"),this.client=e}async retrieve(e){return(await v(this.client,this.ENDPOINT,{keys:T(e)},Ew,Aw)).schematics}}const xw=Iw.partial({key:!0,snapshot:!0}).transform(t=>({...t,data:JSON.stringify(t.data)})),Cw=s.z.object({workspace:We,schematics:xw.array()}),$w=s.z.object({schematics:ri.array()}),Rw=s.z.object({keys:zr.array()}),jw=s.z.object({}),Bw=s.z.object({key:zr,name:s.z.string()}),Mw=s.z.object({}),Dw=s.z.object({key:zr,data:s.z.string()}),Pw=s.z.object({}),Uw=s.z.object({key:zr,name:s.z.string(),snapshot:s.z.boolean()}),Lw=s.z.object({schematic:ri}),_w="/workspace/schematic/create",Yw="/workspace/schematic/delete",qw="/workspace/schematic/rename",Fw="/workspace/schematic/set-data",Vw="/workspace/schematic/copy";let Ww=class{constructor(t){l(this,"client"),this.client=t}async create(t,e){const n={...e,data:JSON.stringify(e.data)};return(await v(this.client,_w,{workspace:t,schematics:[n]},Cw,$w)).schematics[0]}async copy(t,e,n){return(await v(this.client,Vw,{key:t,name:e,snapshot:n},Uw,Lw)).schematic}async delete(t){const e=T(t);await v(this.client,Yw,{keys:e},Rw,jw)}async rename(t,e){await v(this.client,qw,{key:t,name:e},Bw,Mw)}async setData(t,e){await v(this.client,Fw,{key:t,data:JSON.stringify(e)},Dw,Pw)}},Gw=class{constructor(t){l(this,"writer"),l(this,"retriever"),this.writer=new Ww(t),this.retriever=new kw(t)}async create(t,e){return await this.writer.create(t,e)}async rename(t,e){await this.writer.rename(t,e)}async setData(t,e){await this.writer.setData(t,e)}async retrieve(t){const e=Array.isArray(t),n=await this.retriever.retrieve(t);return e?n:n[0]}async delete(t){await this.writer.delete(t)}async copy(t,e,n){return await this.writer.copy(t,e,n)}};const Zw=jl.partial({key:!0}).transform(t=>({...t,layout:JSON.stringify(t.layout)})),Kw=s.z.object({workspaces:Zw.array()}),Jw=s.z.object({workspaces:Bl.array()}),Hw=s.z.object({keys:We.array()}),Xw=s.z.object({}),Qw=s.z.object({key:We,name:s.z.string()}),eb=s.z.object({}),tb=s.z.object({key:We,layout:s.z.string()}),nb=s.z.object({}),rb="/workspace/create",sb="/workspace/delete",ib="/workspace/rename",ab="/workspace/set-layout";class ob{constructor(e){l(this,"client"),this.client=e}async create(e){return(await v(this.client,rb,{workspaces:T(e)},Kw,Jw)).workspaces}async delete(e){await v(this.client,sb,{keys:T(e)},Hw,Xw)}async rename(e,n){await v(this.client,ib,{key:e,name:n},Qw,eb)}async setLayout(e,n){await v(this.client,ab,{key:e,layout:JSON.stringify(n)},tb,nb)}}class lb{constructor(e){l(this,"type","workspace"),l(this,"schematic"),l(this,"linePlot"),l(this,"log"),l(this,"retriever"),l(this,"writer"),this.schematic=new Gw(e),this.linePlot=new rw(e),this.retriever=new Nw(e),this.log=new Tw(e),this.writer=new ob(e)}async search(e){return await this.retriever.search(e)}async retrieveByAuthor(e){return await this.retriever.retrieveByAuthor(e)}async retrieve(e){const n=Array.isArray(e),r=await this.retriever.retrieve(e);return n?r:r[0]}async page(e,n){return await this.retriever.page(e,n)}async create(e){const n=Array.isArray(e),r=await this.writer.create(e);return n?r:r[0]}async rename(e,n){await this.writer.rename(e,n)}async setLayout(e,n){await this.writer.setLayout(e,n)}async delete(...e){await this.writer.delete(e)}}const Dl=s.z.object({host:s.z.string({required_error:"Host is required"}).min(1,"Host is required"),port:s.z.number({required_error:"Port is required"}).or(s.z.string({required_error:"Port is required"})),username:s.z.string().min(1,"Username is required"),password:s.z.string().min(1,"Password is required"),connectivityPollFrequency:$.z.default($.seconds(30)),secure:s.z.boolean().optional().default(!1),name:s.z.string().optional()});class Pl extends ep{constructor(e){const n=Dl.parse(e),{host:r,port:i,username:a,password:o,connectivityPollFrequency:c,secure:u}=n,h=new Um(new Gf({host:r,port:Number(i)}),u);h.use(iy);let f;a!=null&&o!=null&&(f=new Cg(h.unary,{username:a,password:o}),h.use(f.middleware()));const d=new Fs(new qs(h.unary)),k=new ml(h.unary,d);super(h.stream,h.unary,d),l(this,"createdAt"),l(this,"props"),l(this,"ranges"),l(this,"channels"),l(this,"auth"),l(this,"user"),l(this,"access"),l(this,"connectivity"),l(this,"ontology"),l(this,"workspaces"),l(this,"labels"),l(this,"hardware"),l(this,"control"),l(this,"transport"),l(this,"clientVersion","0.33.0"),this.createdAt=x.now(),this.props=n,this.auth=f,this.transport=h,this.channels=new pl(this,d,h.unary,k),this.connectivity=new vl(h.unary,c,this.clientVersion,n.name),this.control=new zl(this),this.ontology=new Ty(h.unary,this);const D=new $l(this.transport.unary);this.labels=new rm(this.transport.unary,this,this.ontology),this.ranges=new Cl(this,D,this.transport.unary,d,this.labels,this.ontology),this.access=new Dy(this.transport.unary),this.user=new zg(this.transport.unary),this.workspaces=new lb(this.transport.unary);const ie=new mp(this.transport.unary,this),B=new _p(this.transport.unary,this,this.ontology,this.ranges),ic=new Np(this.transport.unary,this,B);this.hardware=new ap(B,ic,ie)}get key(){return this.createdAt.valueOf().toString()}close(){this.connectivity.stopChecking()}}l(Pl,"connectivity",vl);const cb=lt.Authority,Ns=(t,e,n="")=>{try{return t.parse(e)}catch(r){if(r instanceof s.z.ZodError){const i=r.errors.map(a=>a.path.length===0?a.message:`${a.path.join(".")}: ${a.message}`);throw new Error(`${n} - ${i.join(`
|
|
66
|
+
`)}`)}else throw r}};var ub=Object.defineProperty,hb=(t,e,n)=>e in t?ub(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n,ee=(t,e,n)=>hb(t,typeof e!="symbol"?e+"":e,n);const Is=class Ul{constructor(e,n,r="",i=!1){ee(this,"_noop",!1),ee(this,"key"),ee(this,"path"),ee(this,"serviceName"),this.key=e,this.path=n,this.serviceName=r,this._noop=i}child(e){return new Ul(e,this.extendPath(e),this.serviceName,this.noop)}extendPath(e){return`${this.path}.${e}`}get noop(){return this._noop}};ee(Is,"NOOP",new Is("","",""));let si=Is;const Es=["debug","info","warn","error"],db=t=>{const e=Es.indexOf(t);return({level:n})=>Es.indexOf(n)>=e},fb=t=>{const{include:e,exclude:n}=t;return({path:r})=>!(e!=null&&!e.some(i=>r.startsWith(i))||n!=null&&n.some(i=>r.startsWith(i)))},As=class Ll{constructor(e={}){ee(this,"meta",si.NOOP),ee(this,"filters");const{filters:n=[]}=e;this.filters=n}filter(e){return!this.meta.noop&&this.filters.every(n=>n({key:this.meta.key,path:this.meta.path,level:e}))}child(e){const n=new Ll({filters:this.filters});return n.meta=e,n}debug(e,n,r=!1){!this.filter("debug")&&!r||(n==null?console.log("%cDEBUG","color: #8c00f0;",this.meta.path,e):console.log("%cDEBUG","color: #8c00f0;",this.meta.path,e,vn(n)))}info(e,n,r=!1){!this.filter("info")&&!r||(n==null?console.log("%cINFO","color: #005eff;",this.meta.path,e):console.log("%cINFO","color: #005eff;",this.meta.path,e,vn(n)))}warn(e,n,r=!1){!this.filter("warn")&&!r||(n==null?console.warn("WARN",this.meta.path,e):console.warn("WARN",this.meta.path,e,vn(n)))}error(e,n,r=!1){!this.filter("error")&&!r||(n==null?console.error("ERROR",this.meta.path,e):console.error("ERROR",this.meta.path,e,vn(n)))}};ee(As,"NOOP",new As);let _l=As;const vn=t=>typeof t=="function"?t():t;var yb=typeof globalThis=="object"?globalThis:typeof self=="object"?self:typeof window=="object"?window:typeof global=="object"?global:{},Je="1.9.0",va=/^(\d+)\.(\d+)\.(\d+)(-(.+))?$/;function gb(t){var e=new Set([t]),n=new Set,r=t.match(va);if(!r)return function(){return!1};var i={major:+r[1],minor:+r[2],patch:+r[3],prerelease:r[4]};if(i.prerelease!=null)return function(c){return c===t};function a(c){return n.add(c),!1}function o(c){return e.add(c),!0}return function(c){if(e.has(c))return!0;if(n.has(c))return!1;var u=c.match(va);if(!u)return a(c);var h={major:+u[1],minor:+u[2],patch:+u[3],prerelease:u[4]};return h.prerelease!=null||i.major!==h.major?a(c):i.major===0?i.minor===h.minor&&i.patch<=h.patch?o(c):a(c):i.minor<=h.minor?o(c):a(c)}}var pb=gb(Je),mb=Je.split(".")[0],Ht=Symbol.for("opentelemetry.js.api."+mb),Xt=yb;function ii(t,e,n,r){var i;r===void 0&&(r=!1);var a=Xt[Ht]=(i=Xt[Ht])!==null&&i!==void 0?i:{version:Je};if(!r&&a[t]){var o=new Error("@opentelemetry/api: Attempted duplicate registration of API: "+t);return n.error(o.stack||o.message),!1}if(a.version!==Je){var o=new Error("@opentelemetry/api: Registration of version v"+a.version+" for "+t+" does not match previously registered API v"+Je);return n.error(o.stack||o.message),!1}return a[t]=e,n.debug("@opentelemetry/api: Registered a global for "+t+" v"+Je+"."),!0}function Qt(t){var e,n,r=(e=Xt[Ht])===null||e===void 0?void 0:e.version;if(!(!r||!pb(r)))return(n=Xt[Ht])===null||n===void 0?void 0:n[t]}function ai(t,e){e.debug("@opentelemetry/api: Unregistering a global for "+t+" v"+Je+".");var n=Xt[Ht];n&&delete n[t]}var wb=function(t,e){var n=typeof Symbol=="function"&&t[Symbol.iterator];if(!n)return t;var r=n.call(t),i,a=[],o;try{for(;(e===void 0||e-- >0)&&!(i=r.next()).done;)a.push(i.value)}catch(c){o={error:c}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(o)throw o.error}}return a},bb=function(t,e,n){if(arguments.length===2)for(var r=0,i=e.length,a;r<i;r++)(a||!(r in e))&&(a||(a=Array.prototype.slice.call(e,0,r)),a[r]=e[r]);return t.concat(a||Array.prototype.slice.call(e))},vb=function(){function t(e){this._namespace=e.namespace||"DiagComponentLogger"}return t.prototype.debug=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return Ot("debug",this._namespace,e)},t.prototype.error=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return Ot("error",this._namespace,e)},t.prototype.info=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return Ot("info",this._namespace,e)},t.prototype.warn=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return Ot("warn",this._namespace,e)},t.prototype.verbose=function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];return Ot("verbose",this._namespace,e)},t}();function Ot(t,e,n){var r=Qt("diag");if(r)return n.unshift(e),r[t].apply(r,bb([],wb(n),!1))}var pe;(function(t){t[t.NONE=0]="NONE",t[t.ERROR=30]="ERROR",t[t.WARN=50]="WARN",t[t.INFO=60]="INFO",t[t.DEBUG=70]="DEBUG",t[t.VERBOSE=80]="VERBOSE",t[t.ALL=9999]="ALL"})(pe||(pe={}));function Ob(t,e){t<pe.NONE?t=pe.NONE:t>pe.ALL&&(t=pe.ALL),e=e||{};function n(r,i){var a=e[r];return typeof a=="function"&&t>=i?a.bind(e):function(){}}return{error:n("error",pe.ERROR),warn:n("warn",pe.WARN),info:n("info",pe.INFO),debug:n("debug",pe.DEBUG),verbose:n("verbose",pe.VERBOSE)}}var Tb=function(t,e){var n=typeof Symbol=="function"&&t[Symbol.iterator];if(!n)return t;var r=n.call(t),i,a=[],o;try{for(;(e===void 0||e-- >0)&&!(i=r.next()).done;)a.push(i.value)}catch(c){o={error:c}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(o)throw o.error}}return a},Sb=function(t,e,n){if(arguments.length===2)for(var r=0,i=e.length,a;r<i;r++)(a||!(r in e))&&(a||(a=Array.prototype.slice.call(e,0,r)),a[r]=e[r]);return t.concat(a||Array.prototype.slice.call(e))},zb="diag",en=function(){function t(){function e(i){return function(){for(var a=[],o=0;o<arguments.length;o++)a[o]=arguments[o];var c=Qt("diag");if(c)return c[i].apply(c,Sb([],Tb(a),!1))}}var n=this,r=function(i,a){var o,c,u;if(a===void 0&&(a={logLevel:pe.INFO}),i===n){var h=new Error("Cannot use diag as the logger for itself. Please use a DiagLogger implementation like ConsoleDiagLogger or a custom implementation");return n.error((o=h.stack)!==null&&o!==void 0?o:h.message),!1}typeof a=="number"&&(a={logLevel:a});var f=Qt("diag"),d=Ob((c=a.logLevel)!==null&&c!==void 0?c:pe.INFO,i);if(f&&!a.suppressOverrideMessage){var k=(u=new Error().stack)!==null&&u!==void 0?u:"<failed to generate stacktrace>";f.warn("Current logger will be overwritten from "+k),d.warn("Current logger will overwrite one already registered from "+k)}return ii("diag",d,n,!0)};n.setLogger=r,n.disable=function(){ai(zb,n)},n.createComponentLogger=function(i){return new vb(i)},n.verbose=e("verbose"),n.debug=e("debug"),n.info=e("info"),n.warn=e("warn"),n.error=e("error")}return t.instance=function(){return this._instance||(this._instance=new t),this._instance},t}(),Nb=function(t,e){var n=typeof Symbol=="function"&&t[Symbol.iterator];if(!n)return t;var r=n.call(t),i,a=[],o;try{for(;(e===void 0||e-- >0)&&!(i=r.next()).done;)a.push(i.value)}catch(c){o={error:c}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(o)throw o.error}}return a},Ib=function(t){var e=typeof Symbol=="function"&&Symbol.iterator,n=e&&t[e],r=0;if(n)return n.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&r>=t.length&&(t=void 0),{value:t&&t[r++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},Eb=function(){function t(e){this._entries=e?new Map(e):new Map}return t.prototype.getEntry=function(e){var n=this._entries.get(e);if(n)return Object.assign({},n)},t.prototype.getAllEntries=function(){return Array.from(this._entries.entries()).map(function(e){var n=Nb(e,2),r=n[0],i=n[1];return[r,i]})},t.prototype.setEntry=function(e,n){var r=new t(this._entries);return r._entries.set(e,n),r},t.prototype.removeEntry=function(e){var n=new t(this._entries);return n._entries.delete(e),n},t.prototype.removeEntries=function(){for(var e,n,r=[],i=0;i<arguments.length;i++)r[i]=arguments[i];var a=new t(this._entries);try{for(var o=Ib(r),c=o.next();!c.done;c=o.next()){var u=c.value;a._entries.delete(u)}}catch(h){e={error:h}}finally{try{c&&!c.done&&(n=o.return)&&n.call(o)}finally{if(e)throw e.error}}return a},t.prototype.clear=function(){return new t},t}();en.instance();function Ab(t){return t===void 0&&(t={}),new Eb(new Map(Object.entries(t)))}function kb(t){return Symbol.for(t)}var xb=function(){function t(e){var n=this;n._currentContext=e?new Map(e):new Map,n.getValue=function(r){return n._currentContext.get(r)},n.setValue=function(r,i){var a=new t(n._currentContext);return a._currentContext.set(r,i),a},n.deleteValue=function(r){var i=new t(n._currentContext);return i._currentContext.delete(r),i}}return t}(),Cb=new xb,$b={get:function(t,e){if(t!=null)return t[e]},keys:function(t){return t==null?[]:Object.keys(t)}},Rb={set:function(t,e,n){t!=null&&(t[e]=n)}},jb=function(t,e){var n=typeof Symbol=="function"&&t[Symbol.iterator];if(!n)return t;var r=n.call(t),i,a=[],o;try{for(;(e===void 0||e-- >0)&&!(i=r.next()).done;)a.push(i.value)}catch(c){o={error:c}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(o)throw o.error}}return a},Bb=function(t,e,n){if(arguments.length===2)for(var r=0,i=e.length,a;r<i;r++)(a||!(r in e))&&(a||(a=Array.prototype.slice.call(e,0,r)),a[r]=e[r]);return t.concat(a||Array.prototype.slice.call(e))},Mb=function(){function t(){}return t.prototype.active=function(){return Cb},t.prototype.with=function(e,n,r){for(var i=[],a=3;a<arguments.length;a++)i[a-3]=arguments[a];return n.call.apply(n,Bb([r],jb(i),!1))},t.prototype.bind=function(e,n){return n},t.prototype.enable=function(){return this},t.prototype.disable=function(){return this},t}(),Db=function(t,e){var n=typeof Symbol=="function"&&t[Symbol.iterator];if(!n)return t;var r=n.call(t),i,a=[],o;try{for(;(e===void 0||e-- >0)&&!(i=r.next()).done;)a.push(i.value)}catch(c){o={error:c}}finally{try{i&&!i.done&&(n=r.return)&&n.call(r)}finally{if(o)throw o.error}}return a},Pb=function(t,e,n){if(arguments.length===2)for(var r=0,i=e.length,a;r<i;r++)(a||!(r in e))&&(a||(a=Array.prototype.slice.call(e,0,r)),a[r]=e[r]);return t.concat(a||Array.prototype.slice.call(e))},Hr="context",Ub=new Mb,Yl=function(){function t(){}return t.getInstance=function(){return this._instance||(this._instance=new t),this._instance},t.prototype.setGlobalContextManager=function(e){return ii(Hr,e,en.instance())},t.prototype.active=function(){return this._getContextManager().active()},t.prototype.with=function(e,n,r){for(var i,a=[],o=3;o<arguments.length;o++)a[o-3]=arguments[o];return(i=this._getContextManager()).with.apply(i,Pb([e,n,r],Db(a),!1))},t.prototype.bind=function(e,n){return this._getContextManager().bind(e,n)},t.prototype._getContextManager=function(){return Qt(Hr)||Ub},t.prototype.disable=function(){this._getContextManager().disable(),ai(Hr,en.instance())},t}(),ks;(function(t){t[t.UNSET=0]="UNSET",t[t.OK=1]="OK",t[t.ERROR=2]="ERROR"})(ks||(ks={}));var Lb=Yl.getInstance(),_b=function(){function t(){}return t.prototype.inject=function(e,n){},t.prototype.extract=function(e,n){return e},t.prototype.fields=function(){return[]},t}(),oi=kb("OpenTelemetry Baggage Key");function ql(t){return t.getValue(oi)||void 0}function Yb(){return ql(Yl.getInstance().active())}function qb(t,e){return t.setValue(oi,e)}function Fb(t){return t.deleteValue(oi)}var Xr="propagation",Vb=new _b,Wb=function(){function t(){this.createBaggage=Ab,this.getBaggage=ql,this.getActiveBaggage=Yb,this.setBaggage=qb,this.deleteBaggage=Fb}return t.getInstance=function(){return this._instance||(this._instance=new t),this._instance},t.prototype.setGlobalPropagator=function(e){return ii(Xr,e,en.instance())},t.prototype.inject=function(e,n,r){return r===void 0&&(r=Rb),this._getGlobalPropagator().inject(e,n,r)},t.prototype.extract=function(e,n,r){return r===void 0&&(r=$b),this._getGlobalPropagator().extract(e,n,r)},t.prototype.fields=function(){return this._getGlobalPropagator().fields()},t.prototype.disable=function(){ai(Xr,en.instance())},t.prototype._getGlobalPropagator=function(){return Qt(Xr)||Vb},t}(),Gb=Wb.getInstance();const Oa=["bench","debug","prod"],Zb=t=>e=>Oa.indexOf(e)>=Oa.indexOf(t),xs=class Fl{constructor(e,n=Zb("debug")){ee(this,"meta",si.NOOP),ee(this,"tracer"),ee(this,"filter"),this.tracer=e,this.filter=n}child(e){const n=new Fl(this.tracer,this.filter);return n.meta=e,n}debug(e,n){return this.trace(e,"debug",n)}bench(e,n){return this.trace(e,"bench",n)}prod(e,n){return this.trace(e,"prod",n)}trace(e,n,r){return this.meta.noop||!this.filter(n)?r(new Gl(e)):this.tracer.startActiveSpan(e,i=>{const a=new Wl(e,i),o=r(a);return i.end(),o})}propagate(e){if(this.meta.noop)return;const n=Lb.active();Gb.inject(n,e,{set:(r,i,a)=>{r[i]=a}})}};ee(xs,"NOOP",new xs);let Vl=xs;class Wl{constructor(e,n){ee(this,"key"),ee(this,"otel"),this.key=e,this.otel=n}set(e,n){this.otel.setAttribute(e,n)}recordError(e){e!=null&&(this.otel.recordException(e),this.otel.setStatus({code:ks.ERROR}))}}class Gl{constructor(e){ee(this,"key"),this.key=e}set(){}recordError(e){}}const Cs=class Zl{constructor({key:e="",serviceName:n="",logger:r=_l.NOOP,tracer:i=Vl.NOOP,noop:a=!1,__meta:o}){ee(this,"meta"),ee(this,"T"),ee(this,"L"),this.meta=o??new si(e,e,n,a),this.T=i.child(this.meta),this.L=r.child(this.meta)}child(e){const n=this.meta.child(e);return new Zl({__meta:n,tracer:this.T,logger:this.L})}};ee(Cs,"NOOP",new Cs({noop:!0}));let li=Cs;const Kb=li.NOOP,Kl=Object.freeze(Object.defineProperty({__proto__:null,Instrumentation:li,LOG_LEVELS:Es,Logger:_l,NOOP:Kb,NoopSpan:Gl,Tracer:Vl,_Span:Wl,logLevelKeyFiler:fb,logThresholdFilter:db},Symbol.toStringTag,{value:"Module"})),Jb=new Error("request for lock canceled");var Hb=function(t,e,n,r){function i(a){return a instanceof n?a:new n(function(o){o(a)})}return new(n||(n=Promise))(function(a,o){function c(f){try{h(r.next(f))}catch(d){o(d)}}function u(f){try{h(r.throw(f))}catch(d){o(d)}}function h(f){f.done?a(f.value):i(f.value).then(c,u)}h((r=r.apply(t,e||[])).next())})};class Xb{constructor(e,n=Jb){this._value=e,this._cancelError=n,this._queue=[],this._weightedWaiters=[]}acquire(e=1,n=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return new Promise((r,i)=>{const a={resolve:r,reject:i,weight:e,priority:n},o=Jl(this._queue,c=>n<=c.priority);o===-1&&e<=this._value?this._dispatchItem(a):this._queue.splice(o+1,0,a)})}runExclusive(e){return Hb(this,arguments,void 0,function*(n,r=1,i=0){const[a,o]=yield this.acquire(r,i);try{return yield n(a)}finally{o()}})}waitForUnlock(e=1,n=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return this._couldLockImmediately(e,n)?Promise.resolve():new Promise(r=>{this._weightedWaiters[e-1]||(this._weightedWaiters[e-1]=[]),Qb(this._weightedWaiters[e-1],{resolve:r,priority:n})})}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 n=this._value;this._value-=e.weight,e.resolve([n,this._newReleaser(e.weight)])}_newReleaser(e){let n=!1;return()=>{n||(n=!0,this.release(e))}}_drainUnlockWaiters(){if(this._queue.length===0)for(let e=this._value;e>0;e--){const n=this._weightedWaiters[e-1];n&&(n.forEach(r=>r.resolve()),this._weightedWaiters[e-1]=[])}else{const e=this._queue[0].priority;for(let n=this._value;n>0;n--){const r=this._weightedWaiters[n-1];if(!r)continue;const i=r.findIndex(a=>a.priority<=e);(i===-1?r:r.splice(0,i)).forEach(a=>a.resolve())}}}_couldLockImmediately(e,n){return(this._queue.length===0||this._queue[0].priority<n)&&e<=this._value}}function Qb(t,e){const n=Jl(t,r=>e.priority<=r.priority);t.splice(n+1,0,e)}function Jl(t,e){for(let n=t.length-1;n>=0;n--)if(e(t[n]))return n;return-1}var ev=function(t,e,n,r){function i(a){return a instanceof n?a:new n(function(o){o(a)})}return new(n||(n=Promise))(function(a,o){function c(f){try{h(r.next(f))}catch(d){o(d)}}function u(f){try{h(r.throw(f))}catch(d){o(d)}}function h(f){f.done?a(f.value):i(f.value).then(c,u)}h((r=r.apply(t,e||[])).next())})};class Hl{constructor(e){this._semaphore=new Xb(1,e)}acquire(){return ev(this,arguments,void 0,function*(e=0){const[,n]=yield this._semaphore.acquire(1,e);return n})}runExclusive(e,n=0){return this._semaphore.runExclusive(()=>e(),1,n)}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()}}class Nr{constructor(e,n,r=new Map){P(this,"providers");P(this,"registry");P(this,"sender");P(this,"changedKeys");this.providers=r,this.registry=n,this.changedKeys=[],this.sender=e}propagateState(e,n,r=[]){this.sender.send({key:e,state:n},r)}copyAndMerge(e){const n=new Nr(this.sender,this.registry,new Map);return e==null||e.providers.forEach((r,i)=>n.providers.set(i,r)),this.providers.forEach((r,i)=>n.providers.set(i,r)),n.changedKeys=[],n}get changed(){return this.changedKeys.length>0}set(e,n,r=!0){this.providers.set(e,n),r&&this.changedKeys.push(e)}setIfNotHas(e,n){this.providers.has(e)||this.set(e,n)}async create(e){const n=this.registry[e.type];if(n==null)throw new Error(`[AetherRoot.create] - could not find component ${e.type}`);const r=new n(e);return await r.internalUpdate(e),r}getOptional(e){return this.providers.get(e)??null}has(e){return this.providers.has(e)}get(e){const n=this.getOptional(e);if(n==null)throw new Error(`[AetherRoot.get] - could not find provider ${e}`);return n}}class ci{constructor(e){P(this,"type");P(this,"key");P(this,"_ctx");P(this,"_internalState");P(this,"_state");P(this,"_prevState");P(this,"_deleted",!1);P(this,"instrumentation");P(this,"schema");this.type=e.type,this.key=e.path[0],this._ctx=e.ctx,this._internalState={},this.instrumentation=e.instrumentation.child(`${this.type}(${this.key})`)}get _schema(){if(this.schema==null)throw new K(`[AetherLeaf] - expected subclass to define component schema, but none was found.
|
|
67
|
+
Make sure to defne a property 'schema' on the class.`);return this.schema}setState(e){const n=Bs(e,this._state);this._prevState={...this._state},this._state=Ns(this._schema,n,`${this.type}:${this.key}`),this.ctx.propagateState(this.key,n)}get ctx(){if(this._ctx==null)throw new be("context not defined");return this._ctx}get state(){if(this._state==null)throw new be("state not defined");return this._state}get internal(){return this._internalState}get prevState(){return this._prevState}get deleted(){return this._deleted}async internalUpdate({variant:e,path:n,ctx:r,state:i}){if(!this.deleted){if(this._ctx=r,e==="state"){this.validatePath(n);const a=Ns(this._schema,i,`${this.type}:${this.key}`);this._state!=null?this.instrumentation.L.debug("updating state",()=>({diff:xa.difference(this.state,a)})):this.instrumentation.L.debug("setting initial state",{state:i}),this._prevState=this._state??a,this._state=a}else this.instrumentation.L.debug("updating context");await this.afterUpdate()}}async internalDelete(e){this.validatePath(e),this._deleted=!0,await this.afterDelete()}beforeUpdate(){}async afterUpdate(){}async afterDelete(){}validatePath(e){if(e.length===0)throw new be(`[Leaf.setState] - ${this.type}:${this.key} received an empty path`);const n=e[e.length-1];if(e.length>1)throw new be(`[Leaf.setState] - ${this.type}:${this.key} received a subPath ${e.join(".")} but is a leaf`);if(n!==this.key)throw new be(`[Leaf.setState] - ${this.type}:${this.key} received a key ${n} but expected ${this.key}`)}}class dn extends ci{constructor(n){super(n);P(this,"_children");this._children=new Map}get children(){return Array.from(this._children.values())}async internalUpdate(n){const{variant:r,path:i}=n;if(r==="context")return this._ctx=n.ctx.copyAndMerge(this._ctx),await this.updateContext({...n,ctx:this.ctx});const[a,o]=this.getRequiredKey(i),c={...n,ctx:this.ctx};return o.length===0?await this.updateThis(a,c):await this.updateChild(o,c)}async updateContext(n){await super.internalUpdate(n);for(const r of this.children)await r.internalUpdate({...n,ctx:this.ctx,variant:"context"})}async updateChild(n,r){const i=n[0],a=this.getChild(i);if(a!=null)return await a.internalUpdate({...r,path:n});if(n.length>1)throw new Error(`[Composite.setState] - ${this.type}:${this.key} could not find child with key ${i} while updating `);this._children.set(i,await r.ctx.create({...r,path:n}))}async updateThis(n,r){const i=r.ctx.copyAndMerge(this._ctx);if(n!==this.key)throw new be(`[Composite.update] - ${this.type}:${this.key} received a key ${n} but expected ${this.key}`);if(await super.internalUpdate({...r,ctx:i}),!!i.changed){this.instrumentation.L.debug("context changed",{changedKeys:i.changedKeys});for(const a of this.children)await a.internalUpdate({...r,ctx:this.ctx,variant:"context"})}}async internalDelete(n){const[r,i]=this.getRequiredKey(n);if(i.length===0){if(r!==this.key)throw new Error(`[Composite.delete] - ${this.type}:${this.key} received a key ${r} but expected ${this.key}`);const o=this.children;this._children=new Map;for(const c of o)await c.internalDelete([c.key]);await super.internalDelete([this.key])}const a=this.getChild(i[0]);a!=null&&(i.length>1?await a.internalDelete(i):(this._children.delete(a.key),await a.internalDelete(i)))}getRequiredKey(n,r){const[i,...a]=n;if(i==null)throw new Error(`Composite ${this.type}:${this.key} received an empty path`+(r!=null?` for ${r}`:""));return[i,a]}getChild(n){return this._children.get(n)??null}childrenOfType(...n){return this.children.filter(r=>n.includes(r.type))}}const tv=s.z.object({}),$e=class $e extends dn{constructor({worker:n,registry:r,instrumentation:i=Kl.Instrumentation.NOOP}){const o={ctx:new Nr(n,r,new Map),...$e.ZERO_UPDATE,instrumentation:i};super(o);P(this,"wrap");P(this,"schema",$e.schema);P(this,"mu",new Hl);this.mu.runExclusive(async()=>await this.internalUpdate(o)),this.wrap=n,this.wrap.handle(c=>{this.mu.runExclusive(async()=>await this.handle(c))})}async handle(n){if(n.variant==="delete")await this.internalDelete(n.path);else{const r={...n,variant:"state",ctx:this.ctx,instrumentation:this.instrumentation};await this.internalUpdate(r)}}};P($e,"TYPE","root"),P($e,"KEY","root"),P($e,"ZERO_UPDATE",{path:[$e.KEY],type:$e.TYPE,variant:"state",state:{}}),P($e,"schema",tv);let ir=$e;const Xl=t=>new ir(t),nv=Object.freeze(Object.defineProperty({__proto__:null,Composite:dn,Context:Nr,Leaf:ci,Root:ir,render:Xl},Symbol.toStringTag,{value:"Module"})),Ql="pluto-theming-context",ec=s.z.object({name:s.z.string(),url:s.z.string()}),rv=s.z.object({theme:Ha,fontURLs:s.z.array(ec)}),Gt=class Gt extends dn{constructor(){super(...arguments);P(this,"schema",Gt.z)}async afterUpdate(){this.ctx.set(Ql,this.state.theme),await this.loadFonts()}async loadFonts(){await Promise.all(this.state.fontURLs.map(async({name:n,url:r})=>{const i=new FontFace(n,`url(${r})`);await i.load(),self.fonts.add(i)}))}};P(Gt,"TYPE","theming.Provider"),P(Gt,"z",rv);let tn=Gt;const sv=t=>t.get(Ql),iv={[tn.TYPE]:tn},tc=["success","error","warning","info","loading","disabled","secondary"],nc=s.z.enum(tc),rc=s.z.object({key:s.z.string(),variant:nc,message:s.z.string(),description:s.z.string().optional(),time:W.z,data:s.z.record(s.z.unknown()).optional()}),sc=s.z.object({statuses:rc.array()}),ui="status.aggregator";class ar extends dn{constructor(){super(...arguments);P(this,"schema",sc)}async afterUpdate(){this.ctx.set(ui,this)}add(n){this.setState(r=>({...r,statuses:[...r.statuses,{time:W.now(),key:ja.id(),...n}]}))}}P(ar,"TYPE","status.Aggregator");const av=t=>{const e=t.get(ui);return e.add.bind(e)},ov=t=>{const e=t.getOptional(ui);return e!=null?e.add.bind(e):()=>{}},lv={[ar.TYPE]:ar};exports.A=eu;exports.Aggregator=ar;exports.B=K;exports.B$1=li;exports.B$2=mu;exports.Bg=Dm;exports.Ce=be;exports.ComponentSizeLevels=Ja;exports.Composite=dn;exports.Ct=Zc;exports.E=it;exports.F=vc;exports.H=Tu;exports.I=x;exports.Kg=cb;exports.LEVELS=Ka;exports.Leaf=ci;exports.LevelComponentSizes=$u;exports.Lf=Pl;exports.Mutex=Hl;exports.N=jc;exports.Og=ip;exports.P=ns;exports.Provider=tn;exports.Q=Su;exports.REGISTRY=iv;exports.REGISTRY$1=lv;exports.Rt=ja;exports.SYNNAX_DARK=Qa;exports.SYNNAX_LIGHT=Xa;exports.SYNNAX_THEMES=Yu;exports.U=zu;exports.V=Da;exports.V$1=se;exports.VARIANTS=tc;exports.W=gu;exports.Zf=Dl;exports._=xa;exports.aether=nv;exports.aggregatorStateZ=sc;exports.b=ce;exports.dg=ig;exports.dimensions=ju;exports.downLevel=ku;exports.executeInitialSetter=rn;exports.executeSetter=Bs;exports.fontSpecZ=ec;exports.fontString=Wu;exports.g=j;exports.g$1=Kl;exports.isSetter=js;exports.k=$;exports.l=lu;exports.levelZ=Eu;exports.m=W;exports.n=Qr;exports.o=Oc;exports.o$1=tu;exports.prettyParse=Ns;exports.r=Tc;exports.re=Oe;exports.render=Xl;exports.specZ=Ye;exports.specZ$1=rc;exports.state=Iu;exports.themeZ=Ha;exports.upLevel=Cu;exports.use=sv;exports.useAggregate=av;exports.useOptionalAggregate=ov;exports.usePassthrough=Ga;exports.usePurePassthrough=Za;exports.variantZ=nc;exports.w=La;exports.w$1=fc;exports.x=Zt;exports.xt=Lc;exports.y=Z;
|