@synnaxlabs/client 0.39.0 → 0.40.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +5 -5
- package/dist/client.cjs +2 -2
- package/dist/client.js +111 -110
- package/dist/hardware/device/client.d.ts +4 -1
- package/dist/hardware/device/client.d.ts.map +1 -1
- package/dist/hardware/device/payload.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/hardware/device/client.ts +5 -2
- package/src/hardware/device/device.spec.ts +42 -0
- package/src/hardware/device/payload.ts +1 -0
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @synnaxlabs/client@0.
|
|
2
|
+
> @synnaxlabs/client@0.40.0 build /home/runner/work/synnax/synnax/client/ts
|
|
3
3
|
> tsc --noEmit && vite build
|
|
4
4
|
|
|
5
5
|
[34m Synnax - Production mode[0m
|
|
@@ -10,8 +10,8 @@ rendering chunks...
|
|
|
10
10
|
|
|
11
11
|
[vite:dts] Start generate declaration files...
|
|
12
12
|
computing gzip size...
|
|
13
|
-
[2mdist/[22m[36mclient.js [39m[1m[2m304.
|
|
14
|
-
[vite:dts] Declaration files built in
|
|
13
|
+
[2mdist/[22m[36mclient.js [39m[1m[2m304.64 kB[22m[1m[22m[2m │ gzip: 71.03 kB[22m
|
|
14
|
+
[vite:dts] Declaration files built in 4547ms.
|
|
15
15
|
|
|
16
|
-
[2mdist/[22m[36mclient.cjs [39m[1m[2m193.
|
|
17
|
-
[32m✓ built in 5.
|
|
16
|
+
[2mdist/[22m[36mclient.cjs [39m[1m[2m193.93 kB[22m[1m[22m[2m │ gzip: 53.22 kB[22m
|
|
17
|
+
[32m✓ built in 5.51s[39m
|
package/dist/client.cjs
CHANGED
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
`);c(this,"type",Xe.TYPE)}};c(Xe,"TYPE",`${Pe}unexpected`),c(Xe,"matches",Q(Xe.TYPE));let xe=Xe;const Qe=class Qe extends oe{constructor(){super(...arguments);c(this,"type",Qe.TYPE)}};c(Qe,"TYPE",`${Pe}query`),c(Qe,"matches",Q(Qe.TYPE));let ie=Qe;const et=class et extends ie{constructor(){super(...arguments);c(this,"type",et.TYPE)}};c(et,"TYPE",`${ie.TYPE}.not_found`),c(et,"matches",Q(et.TYPE));let Oe=et;const tt=class tt extends ie{constructor(){super(...arguments);c(this,"type",tt.TYPE)}};c(tt,"TYPE",`${ie.TYPE}.multiple_results`),c(tt,"matches",Q(tt.TYPE));let Ne=tt;const rt=class rt extends oe{constructor(t,n){super(t);c(this,"type",rt.TYPE);c(this,"path");this.path=n}};c(rt,"TYPE",`${Pe}route`),c(rt,"matches",Q(rt.TYPE));let _t=rt;const nt=class nt extends oe{constructor(){super(...arguments);c(this,"type",nt.TYPE)}};c(nt,"TYPE",`${Pe}control`),c(nt,"matches",Q(nt.TYPE));let ft=nt;const st=class st extends ft{constructor(){super(...arguments);c(this,"type",st.TYPE)}};c(st,"TYPE",`${ft.TYPE}.unauthorized`),c(st,"matches",Q(st.TYPE));let kr=st;const it=class it extends oe{constructor(){super(...arguments);c(this,"type",it.TYPE)}};c(it,"TYPE",`${Pe}contiguity`),c(it,"matches",Q(it.TYPE));let Ln=it;const Wh=r=>{if(!r.type.startsWith(Pe))return null;if(r.type.startsWith(U.TYPE)){if(r.type===$r.TYPE){const e=r.data.split(": ");return e.length<2?new U(r.data):new $r(e[0],e[1])}return new U(r.data)}return r.type.startsWith(ve.TYPE)?r.type.startsWith(Ut.TYPE)?new Ut(r.data):r.type.startsWith(Lt.TYPE)?new Lt(r.data):new ve(r.data):r.type.startsWith(xe.TYPE)?new xe(r.data):r.type.startsWith(ie.TYPE)?r.type.startsWith(Oe.TYPE)?new Oe(r.data):r.type.startsWith(Ne.TYPE)?new Ne(r.data):new ie(r.data):r.type.startsWith(ft.TYPE)?r.type.startsWith(kr.TYPE)?new kr(r.data):new ft(r.data):r.type.startsWith(_t.TYPE)?new _t(r.data,r.data):new xe(r.data)},Fh=()=>{throw new Error("Not implemented")};Zi({encode:Fh,decode:Wh});const Gh=async(r,e)=>{const[t,n]=await e(r);return n==null?[t,n]:n instanceof Ce?[t,new Ce({message:`Cannot reach cluster at ${n.url.host}:${n.url.port}`,url:n.url})]:[t,n]},gt=s.z.string().uuid(),Br=s.z.string(),Hn=s.z.object({key:gt,name:Br}),Vh=r=>{const e=b(r);if(e.length===0)throw new Error("No groups specified");const t=gt.safeParse(e[0]).success;return{single:!Array.isArray(r),variant:t?"keys":"names",normalized:e,actual:r}},Xn="group",V=r=>s.z.union([s.z.union([s.z.null(),s.z.undefined()]).transform(()=>[]),r.array()]),J=s.z.number(),Xt=s.z.string(),Qt=s.z.object({name:Xt,key:J,rate:ut.z,dataType:I.z,leaseholder:s.z.number(),index:J,isIndex:s.z.boolean(),internal:s.z.boolean(),virtual:s.z.boolean(),alias:s.z.string().optional(),expression:s.z.string().default(""),requires:V(J)}),Ta=Qt.extend({key:J.optional(),leaseholder:s.z.number().optional(),index:J.optional(),rate:ut.z.optional().default(0),isIndex:s.z.boolean().optional(),internal:s.z.boolean().optional().default(!1),virtual:s.z.boolean().optional().default(!1),expression:s.z.string().optional().default(""),requires:V(J).optional().default([])}),Zr="channel",Qn="framer",ui=r=>{const e=b(r);return e.length===0?null:typeof e[0]=="number"||!isNaN(parseInt(e[0]))?"key":"name"},hi=(r,e)=>{const t=b(r);if(t.length===e.length)return;const n=ui(r);throw ui===null?new U("[Frame] - channel keys or names must be provided when constructing a frame."):new U(`[Frame] - ${n}s and series must be the same length.
|
|
34
34
|
Got ${t.length} ${n}s and ${e.length} series.`)};class Y{constructor(e=[],t=[]){c(this,"columns",[]);c(this,"series",[]);if(e instanceof Y){this.columns=e.columns,this.series=e.series;return}if(e instanceof Map){e.forEach((i,a)=>this.push(a,...b(i)));return}if(typeof e=="object"&&!Array.isArray(e)){if("keys"in e&&"series"in e){const i=e;i.series??(i.series=[]),i.keys??(i.keys=[]);const a=i.series.map(o=>va(o));hi(i.keys,a),i.keys.forEach((o,l)=>this.push(o,a[l]))}else Object.entries(e).forEach(([i,a])=>{const o=parseInt(i);if(!isNaN(o))return this.push(o,...b(a));this.push(i,...b(a))});return}if(Array.isArray(e)||["string","number"].includes(typeof e)){const i=b(t),a=b(e);hi(a,i),i.forEach((o,l)=>this.push(a[l],o));return}throw new U(`[Frame] - invalid frame construction parameters. data parameter ust be a frame
|
|
35
35
|
payload, a list of lazy series, a lazy array, a map, or a record keyed by channel
|
|
36
|
-
name. keys parameter must be a set of channel keys or channel names.`)}get colType(){return this.columns.length===0?null:typeof this.columns[0]=="string"?"name":"key"}get keys(){if(this.colType==="name")throw new xe("colType is not key");return this.columns??[]}get uniqueKeys(){return Ws.unique(this.keys)}get names(){if(this.colType==="key")throw new xe("colType is not name");return this.columns??[]}get uniqueNames(){return Ws.unique(this.names)}get uniqueColumns(){return this.colType==="key"?this.uniqueKeys:this.uniqueNames}toPayload(){return{series:this.series.map(e=>Oa(e)),keys:this.keys}}get isVertical(){return this.uniqueColumns.length===this.columns.length}get isHorizontal(){return this.uniqueColumns.length===1}get isSquare(){return this.isHorizontal&&this.isVertical}get isWeaklyAligned(){if(this.columns.length<=1)return!0;const e=this.timeRanges;return e.every(t=>t.equals(e[0]))}timeRange(e){if(e==null){if(this.columns.length===0)return G.ZERO;const n=$.min(...this.series.map(a=>a.timeRange.start)),i=$.max(...this.series.map(a=>a.timeRange.end));return new G(n,i)}const t=this.get(e);return t==null?G.ZERO:t.timeRange}latest(){return this.at(-1)}get timeRanges(){return this.uniqueColumns.map(e=>this.timeRange(e))}get(e){return Array.isArray(e)?this.filter(t=>e.includes(t)):new fa(this.series.filter((t,n)=>this.columns[n]===e))}push(e,...t){if(e instanceof Y){if(this.colType!==null&&e.colType!==this.colType)throw new U("keyVariant must match");this.series.push(...e.series),this.columns.push(...e.columns)}else{if(this.series.push(...t),typeof e=="string"&&this.colType==="key")throw new U("keyVariant must match");if(typeof e!="string"&&this.colType==="name")throw new U("keyVariant must match");this.columns.push(...Array.from({length:t.length},()=>e))}}concat(e){return new Y([...this.columns,...e.columns],[...this.series,...e.series])}has(e){return typeof e=="string"&&this.colType==="key"||typeof e=="number"&&this.colType==="name"?!1:this.columns.includes(e)}map(e){const t=new Y;return this.forEach((n,i,a)=>t.push(...e(n,i,a))),t}forEach(e){this.columns.forEach((t,n)=>{const i=this.series[n];e(t,i,n)})}at(e,t=!1){const n={};return this.uniqueColumns.forEach(i=>{n[i]=this.get(i).at(e,t)}),n}filter(e){const t=new Y;return this.columns.forEach((n,i)=>{const a=this.series[i];e(n,a,i)&&t.push(n,a)}),t}get byteLength(){return new ht(this.series.reduce((e,t)=>e.add(t.byteLength),ht.ZERO))}get digest(){const e={};return this.keys.forEach((t,n)=>{const i=this.series[n].digest;t in e?e[t].push(i):e[t]=[i]}),e}get length(){return this.series.reduce((e,t)=>e+t.length,0)}}const Ur=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([])])}),va=r=>{const{dataType:e,data:t,timeRange:n,alignment:i}=r;return new ke({data:t,dataType:e,timeRange:n,glBufferUsage:"static",alignment:i})},Oa=r=>({timeRange:r._timeRange,dataType:r.dataType,data:new Uint8Array(r.data.buffer),alignment:r.alignment}),mt=$h.uint32,Lr=s.z.object({key:mt,name:s.z.string()}),Na=Lr.partial({key:!0}),_r="rack",Ea=r=>r?Jt.JSON_CODEC.decodeString(r):{},qr=s.z.string(),er=s.z.object({key:qr,rack:mt,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(Ea))}),za=er.extend({properties:s.z.unknown().transform(r=>Jt.JSON_CODEC.encodeString(r))}),Yr="device",ye=r=>r?JSON.parse(r):{},je=s.z.union([s.z.string(),s.z.bigint().transform(r=>r.toString()),s.z.number().transform(r=>r.toString())]),Sa=s.z.enum(["info","success","error","warning"]),qt=s.z.object({task:je,variant:Sa,key:s.z.string().optional(),details:s.z.record(s.z.unknown()).or(s.z.string().transform(ye)).or(s.z.array(s.z.unknown())).or(s.z.null())}),tr=s.z.object({key:je,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(Ea)),state:qt.optional().nullable(),snapshot:s.z.boolean().optional()}),Ia=tr.omit({key:!0}).extend({key:je.transform(r=>r.toString()).optional(),config:s.z.unknown().transform(r=>Jt.JSON_CODEC.encodeString(r))}),es=s.z.object({task:je,type:s.z.string(),key:s.z.string(),args:s.z.record(s.z.unknown()).or(s.z.string().transform(ye)).or(s.z.array(s.z.unknown())).or(s.z.null()).optional()}),Wr="task",Jh=r=>Number(BigInt(r)>>32n),wt=s.z.string().uuid(),rr=s.z.object({key:wt,name:s.z.string().min(1),color:s.z.string()}),ts="label",ne=s.z.string().uuid(),rs=s.z.string().min(1),nr=s.z.object({key:ne,name:rs,timeRange:G.z,color:s.z.string().optional()}),$a=nr.partial({key:!0}),ka=r=>{const e=b(r),t=e.length===0;let n=!1;return t||(n=ne.safeParse(e[0]).success),{single:!Array.isArray(r),variant:n?"keys":"names",normalized:e,actual:r,empty:t}},ns="range",ss="range-alias",Ze=s.z.string().uuid(),sr=s.z.object({key:Ze,username:s.z.string().min(1),firstName:s.z.string().default(""),lastName:s.z.string().default(""),rootUser:s.z.boolean().default(!0)}),Aa=sr.partial({key:!0,firstName:!0,lastName:!0}).omit({rootUser:!0}).extend({password:s.z.string().min(1)}),is="user",bt=s.z.string().uuid(),Fr=s.z.object({key:bt,name:s.z.string(),data:Kt.or(s.z.string().transform(ye))}),xa=Fr.partial({key:!0}).transform(r=>({...r,data:JSON.stringify(r.data)})),as="lineplot",Tt=s.z.string().uuid(),Gr=s.z.object({key:Tt,name:s.z.string(),data:Kt.or(s.z.string().transform(ye))}),Ra=Gr.partial({key:!0}).transform(r=>({...r,data:JSON.stringify(r.data)})),os="log",pe=s.z.string().uuid(),Vr=s.z.object({key:pe,name:s.z.string(),layout:Kt.or(s.z.string().transform(ye))}),Jr="workspace",Ca=Vr.partial({key:!0}).transform(r=>({...r,layout:JSON.stringify(r.layout)})),Pa=Vr.omit({layout:!0}).extend({layout:s.z.string().transform(ye)}),Ue=s.z.string().uuid(),Kr=s.z.object({key:Ue,name:s.z.string(),data:Kt.or(s.z.string().transform(ye)),snapshot:s.z.boolean()}),ja=Kr.partial({key:!0,snapshot:!0}).transform(r=>({...r,data:JSON.stringify(r.data)})),cs=Kr.extend({data:s.z.string().transform(ye)}),ls="schematic",vt=s.z.string().uuid(),us=s.z.object({key:vt,name:s.z.string(),data:Kt.or(s.z.string().transform(ye))}),Da=us.partial({key:!0}).transform(r=>({...r,data:JSON.stringify(r.data)})),hs=us.extend({data:s.z.string().transform(ye)}),ds="table",fs="builtin",Ma="cluster",Ba="node",ir=s.z.enum([ts,os,Fn,fs,Ma,Zr,Ba,Xn,ns,Qn,ss,is,Jr,ls,as,_r,Yr,Wr,Wn,ds]),re=s.z.object({type:ir,key:s.z.string()}),Za=s.z.string().transform(r=>{const[e,t]=r.split(":");return{type:ir.parse(e),key:t??""}}),We=s.z.union([Za,re]),at=class at{constructor(e){c(this,"type");c(this,"key");if(e instanceof at){this.type=e.type,this.key=e.key;return}if(typeof e=="string"){const[t,n]=e.split(":");this.type=t,this.key=n??"";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}}};c(at,"z",s.z.union([s.z.instanceof(at),We.transform(e=>new at(e))]));let O=at;const Kh=new O({type:fs,key:"root"}),Ua=s.z.object({type:s.z.number()}),La=s.z.object({type:ir,fields:s.z.record(Ua)}),_a=s.z.object({id:O.z,name:s.z.string(),schema:La.optional().nullable(),data:s.z.record(s.z.unknown()).optional().nullable()}).transform(r=>({key:r.id.toString(),...r})),Hh="to",Xh="from",Qh=s.z.object({from:O.z,type:s.z.string(),to:O.z}),_n=r=>{const[e,t,n]=r.split("->");return{from:new O(e),type:t,to:new O(n)}};class ys{constructor(e,t){c(this,"key");c(this,"name");this.key=t,this.name=e}get ontologyID(){return qa(this.key)}}const qa=r=>new O({type:Xn,key:r}),ed=s.z.object({group:Hn}),td=s.z.object({parent:re,key:gt.optional(),name:Br}),rd=s.z.object({key:gt,name:Br}),nd=s.z.object({keys:s.z.array(gt)});var ae;let sd=(ae=class{constructor(e){c(this,"client");this.client=e}async create(e,t,n){return(await w(this.client,ae.CREATE_ENDPOINT,{parent:e,name:t,key:n},td,ed)).group}async rename(e,t){await w(this.client,ae.RENAME_ENDPOINT,{key:e,name:t},rd,s.z.object({}))}async delete(e){await w(this.client,ae.DELETE_ENDPOINT,{keys:e},nd,s.z.object({}))}},c(ae,"CREATE_ENDPOINT","/ontology/create-group"),c(ae,"RENAME_ENDPOINT","/ontology/rename-group"),c(ae,"DELETE_ENDPOINT","/ontology/delete-group"),ae),Ya=class{constructor(e){c(this,"creator");this.creator=new sd(e)}async create(e,t,n){return this.sugar(await this.creator.create(e,t,n))}async rename(e,t){return await this.creator.rename(e,t)}async delete(...e){return await this.creator.delete(e)}sugar(e){return new ys(e.name,e.key)}};const id=Object.freeze(Object.defineProperty({__proto__:null,Client:Ya,Group:ys,ONTOLOGY_TYPE:Xn,analyzeParams:Vh,groupZ:Hn,keyZ:gt,nameZ:Br,ontologyID:qa},Symbol.toStringTag,{value:"Module"})),ad="/ontology/add-children",od="/ontology/remove-children",cd="/ontology/move-children",di=s.z.object({id:re,children:re.array()}),ld=s.z.object({from:re,to:re,children:re.array()}),pn=s.z.object({});let ud=class{constructor(e){c(this,"client");this.client=e}async addChildren(e,...t){await w(this.client,ad,{id:new O(e).payload,children:t.map(n=>new O(n).payload)},di,pn)}async removeChildren(e,...t){await w(this.client,od,{id:new O(e).payload,children:t.map(n=>new O(n).payload)},di,pn)}async moveChildren(e,t,...n){const i={from:new O(e).payload,to:new O(t).payload,children:n.map(a=>new O(a).payload)};await w(this.client,cd,i,ld,pn)}};const hd="/ontology/retrieve",dd=s.z.object({ids:re.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:ir.array().optional()}),fd=s.z.object({resources:_a.array()}),Nr=r=>b(r).map(e=>new O(e).payload);let Wa=class{constructor(e,t){c(this,"type","ontology");c(this,"groups");c(this,"client");c(this,"writer");c(this,"framer");this.client=e,this.writer=new ud(e),this.groups=new Ya(e),this.framer=t}async search(e,t){return await this.execRetrieve({term:e,...t})}async retrieve(e,t){const n=await this.execRetrieve({ids:Nr(e),...t});if(Array.isArray(e))return n;if(n.length===0)throw new ie(`No resource found with ID ${Yh.naturalLanguageJoin(b(e).map(i=>new O(i).toString()))}`);return n[0]}async page(e,t,n){return await this.execRetrieve({offset:e,limit:t,...n})}async retrieveChildren(e,t){return await this.execRetrieve({ids:Nr(e),children:!0,...t})}async retrieveParents(e,t){return await this.execRetrieve({ids:Nr(e),parents:!0,...t})}async addChildren(e,...t){return await this.writer.addChildren(e,...t)}async removeChildren(e,...t){return await this.writer.removeChildren(e,...t)}async moveChildren(e,t,...n){return await this.writer.moveChildren(e,t,...n)}async openChangeTracker(){return await ar.open(this.framer,this)}async openDependentTracker(e){return await Hr.open(e,this.framer,this)}newSearcherWithOptions(e){return{type:this.type,search:t=>this.search(t,e),retrieve:t=>this.retrieve(t,e),page:(t,n)=>this.page(t,n,e)}}async execRetrieve(e){const{resources:t}=await w(this.client,hd,e,dd,fd);return t}};const fi="sy_ontology_resource_set",yi="sy_ontology_resource_delete",pi="sy_ontology_relationship_set",gi="sy_ontology_relationship_delete";class ar{constructor(e,t){c(this,"relationships");c(this,"resources");c(this,"resourceObs");c(this,"relationshipObs");c(this,"streamer");c(this,"client");c(this,"closePromise");this.relationshipObs=new Me.Observer,this.relationships=this.relationshipObs,this.resourceObs=new Me.Observer,this.resources=this.resourceObs,this.client=t,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 t=await this.parseResourceSets(e),n=this.parseResourceDeletes(e);t.concat(n).length>0&&this.resourceObs.notify(t.concat(n));const a=this.parseRelationshipSets(e),o=this.parseRelationshipDeletes(e);a.concat(o).length>0&&this.relationshipObs.notify(a.concat(o))}parseRelationshipSets(e){const t=e.get(pi);return t.length===0?[]:Array.from(t.as("string")).map(n=>({variant:"set",key:_n(n),value:void 0}))}parseRelationshipDeletes(e){const t=e.get(gi);return t.length===0?[]:Array.from(t.as("string")).map(n=>({variant:"delete",key:_n(n)}))}async parseResourceSets(e){const t=e.get(fi);if(t.length===0)return[];const n=Array.from(t.as("string")).map(i=>new O(i));try{return(await this.client.retrieve(n)).map(a=>({variant:"set",key:a.id,value:a}))}catch(i){if(i instanceof ie)return[];throw i}}parseResourceDeletes(e){const t=e.get(yi);return t.length===0?[]:Array.from(t.as("string")).map(n=>({variant:"delete",key:new O(n)}))}static async open(e,t){const n=await e.openStreamer([fi,yi,pi,gi]);return new ar(n,t)}}const mi=r=>r==="from"?"to":"from";class Hr extends Me.Observer{constructor({target:t,dependents:n,relationshipType:i="parent",relationshipDirection:a="from",resourceType:o},l,u){super();c(this,"internal");c(this,"target");c(this,"relDir");c(this,"resourceType");c(this,"dependents");c(this,"client");c(this,"relType");c(this,"handleResourceChange",t=>{this.dependents=this.dependents.map(n=>{const i=t.find(a=>a.key.toString()==n.id.toString());return i==null||i.variant==="delete"?n:i.value}),this.notify(this.dependents)});c(this,"handleRelationshipChange",t=>{const n=t.filter(a=>a.variant==="delete"&&a.key[this.relDir].toString()===this.target.toString()&&(this.resourceType==null||a.key[mi(this.relDir)].type===this.resourceType));this.dependents=this.dependents.filter(a=>!n.some(o=>o.key.to.toString()===a.id.toString()&&o.key.type===this.relType));const i=t.filter(a=>a.variant==="set"&&a.key.type===this.relType&&a.key[this.relDir].toString()===this.target.toString()&&(this.resourceType==null||a.key[mi(this.relDir)].type===this.resourceType));if(i.length===0)return this.notify(this.dependents);this.client.retrieve(i.map(a=>a.key.to)).then(a=>{this.dependents=this.dependents.concat(a),this.notify(this.dependents)}).catch(console.error)});this.resourceType=o,this.internal=l,this.target=t,this.dependents=n,this.resourceType!=null&&(this.dependents=this.dependents.filter(h=>h.id.type===this.resourceType)),this.client=u,this.relType=i,this.relDir=a,this.internal.resources.onChange(this.handleResourceChange),this.internal.relationships.onChange(this.handleRelationshipChange)}static async open(t,n,i){const a=await ar.open(n,i);return new Hr(t,a,i)}async close(){await this.internal.close()}}const yd=Object.freeze(Object.defineProperty({__proto__:null,BUILTIN_TYPE:fs,CLUSTER_TYPE:Ma,ChangeTracker:ar,Client:Wa,DependentTracker:Hr,FROM_RELATIONSHIP_DIRECTION:Xh,ID:O,NODE_TYPE:Ba,ROOT_ID:Kh,TO_RELATIONSHIP_DIRECTION:Hh,crudeIDZ:We,idZ:re,parseIDs:Nr,parseRelationship:_n,relationshipSchemaZ:Qh,resourceTypeZ:ir,resourceZ:_a,schemaFieldZ:Ua,schemaZ:La,stringIDZ:Za},Symbol.toStringTag,{value:"Module"})),or=s.z.string().uuid(),Xr=s.z.object({key:or,subjects:V(re),objects:V(re),actions:V(Sr)}),Fa=s.z.object({key:or.optional(),subjects:We.array().or(We),objects:We.array().or(We),actions:Sr.array().or(Sr)}),pd=s.z.object({keys:or.array().optional(),subjects:re.array().optional()}),gd=s.z.object({policies:V(Xr)}),md="/access/policy/retrieve";let wd=class{constructor(e){c(this,"client");this.client=e}async retrieve(e){return(await w(this.client,md,e,pd,gd)).policies}};const bd=s.z.object({policies:Xr.partial({key:!0}).array()}),Td=s.z.object({policies:Xr.array()}),vd=s.z.object({keys:or.array()}),Od=s.z.object({}),Nd="/access/policy/create",Ed="/access/policy/delete";let zd=class{constructor(e){c(this,"client");this.client=e}async create(e){const n=Fa.array().parse(b(e)).map(a=>({objects:b(a.objects),actions:b(a.actions),subjects:b(a.subjects)}));return(await w(this.client,Nd,{policies:n},bd,Td)).policies}async delete(e){await w(this.client,Ed,{keys:b(e)},vd,Od)}},Ga=class{constructor(e){c(this,"retriever");c(this,"writer");this.retriever=new wd(e),this.writer=new zd(e)}async create(e){const t=Array.isArray(e),n=await this.writer.create(e);return t?n:n[0]}async retrieve(e){const t=Array.isArray(e),n=await this.retriever.retrieve({keys:b(e)});return t?n:n[0]}async retrieveFor(e){const t=b(e).map(n=>new O(n).payload);return await this.retriever.retrieve({subjects:t})}async delete(e){await this.writer.delete(e)}};const Sd=r=>new O({type:Wn,key:r}),Id=new O({type:Fn,key:""}),$d=Object.freeze(Object.defineProperty({__proto__:null,ALLOW_ALL_ONTOLOGY_ID:Id,ALLOW_ALL_ONTOLOGY_TYPE:Fn,Client:Ga,ONTOLOGY_TYPE:Wn,keyZ:or,newZ:Fa,ontologyID:Sd,policyZ:Xr},Symbol.toStringTag,{value:"Module"}));let Va=class{constructor(e){c(this,"policy");this.policy=new Ga(e)}};const kd=Object.freeze(Object.defineProperty({__proto__:null,ALL_ACTION:Gi,CREATE_ACTION:Vi,Client:Va,DELETE_ACTION:Ji,RETRIEVE_ACTION:Ki,UPDATE_ACTION:Hi,actionZ:Sr},Symbol.toStringTag,{value:"Module"})),Ad=new Error("request for lock canceled");var xd=function(r,e,t,n){function i(a){return a instanceof t?a:new t(function(o){o(a)})}return new(t||(t=Promise))(function(a,o){function l(f){try{h(n.next(f))}catch(d){o(d)}}function u(f){try{h(n.throw(f))}catch(d){o(d)}}function h(f){f.done?a(f.value):i(f.value).then(l,u)}h((n=n.apply(r,e||[])).next())})};class Rd{constructor(e,t=Ad){this._value=e,this._cancelError=t,this._queue=[],this._weightedWaiters=[]}acquire(e=1,t=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return new Promise((n,i)=>{const a={resolve:n,reject:i,weight:e,priority:t},o=Ja(this._queue,l=>t<=l.priority);o===-1&&e<=this._value?this._dispatchItem(a):this._queue.splice(o+1,0,a)})}runExclusive(e){return xd(this,arguments,void 0,function*(t,n=1,i=0){const[a,o]=yield this.acquire(n,i);try{return yield t(a)}finally{o()}})}waitForUnlock(e=1,t=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return this._couldLockImmediately(e,t)?Promise.resolve():new Promise(n=>{this._weightedWaiters[e-1]||(this._weightedWaiters[e-1]=[]),Cd(this._weightedWaiters[e-1],{resolve:n,priority:t})})}isLocked(){return this._value<=0}getValue(){return this._value}setValue(e){this._value=e,this._dispatchQueue()}release(e=1){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);this._value+=e,this._dispatchQueue()}cancel(){this._queue.forEach(e=>e.reject(this._cancelError)),this._queue=[]}_dispatchQueue(){for(this._drainUnlockWaiters();this._queue.length>0&&this._queue[0].weight<=this._value;)this._dispatchItem(this._queue.shift()),this._drainUnlockWaiters()}_dispatchItem(e){const t=this._value;this._value-=e.weight,e.resolve([t,this._newReleaser(e.weight)])}_newReleaser(e){let t=!1;return()=>{t||(t=!0,this.release(e))}}_drainUnlockWaiters(){if(this._queue.length===0)for(let e=this._value;e>0;e--){const t=this._weightedWaiters[e-1];t&&(t.forEach(n=>n.resolve()),this._weightedWaiters[e-1]=[])}else{const e=this._queue[0].priority;for(let t=this._value;t>0;t--){const n=this._weightedWaiters[t-1];if(!n)continue;const i=n.findIndex(a=>a.priority<=e);(i===-1?n:n.splice(0,i)).forEach(a=>a.resolve())}}}_couldLockImmediately(e,t){return(this._queue.length===0||this._queue[0].priority<t)&&e<=this._value}}function Cd(r,e){const t=Ja(r,n=>e.priority<=n.priority);r.splice(t+1,0,e)}function Ja(r,e){for(let t=r.length-1;t>=0;t--)if(e(r[t]))return t;return-1}var Pd=function(r,e,t,n){function i(a){return a instanceof t?a:new t(function(o){o(a)})}return new(t||(t=Promise))(function(a,o){function l(f){try{h(n.next(f))}catch(d){o(d)}}function u(f){try{h(n.throw(f))}catch(d){o(d)}}function h(f){f.done?a(f.value):i(f.value).then(l,u)}h((n=n.apply(r,e||[])).next())})};class jd{constructor(e){this._semaphore=new Rd(1,e)}acquire(){return Pd(this,arguments,void 0,function*(e=0){const[,t]=yield this._semaphore.acquire(1,e);return t})}runExclusive(e,t=0){return this._semaphore.runExclusive(()=>e(),1,t)}isLocked(){return this._semaphore.isLocked()}waitForUnlock(e=0){return this._semaphore.waitForUnlock(1,e)}release(){this._semaphore.isLocked()&&this._semaphore.release()}cancel(){return this._semaphore.cancel()}}const Qr=(r,e,{convertNumericStrings:t=!0}={})=>{const n=!Array.isArray(r);let i=b(r);const a=i[0],o=typeof a;let l;return o==="string"&&t&&!isNaN(parseInt(a))&&"number"in e?(l=e.number,i=i.map(u=>parseInt(u))):l=e[o],{single:n,variant:l,normalized:i,actual:r}},en=(r,e,t,n)=>{if(n){if(t.length===0)throw new Oe(`${r} not found matching ${JSON.stringify(e)}`);if(t.length>1)throw new Ne(`Expected one ${r} matching ${JSON.stringify(e)}, but found ${t.length}`)}},Dd=s.z.object({leaseholder:s.z.number().optional(),keys:J.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:I.z.array().optional(),notDataTypes:I.z.array().optional(),virtual:s.z.boolean().optional(),isIndex:s.z.boolean().optional(),internal:s.z.boolean().optional()}),Md=s.z.object({channels:V(Qt)}),Ee=r=>Qr(r,{number:"keys",string:"names"}),Rr=class Rr{constructor(e){c(this,"client");this.client=e}async search(e,t){return await this.execute({search:e,...t})}async retrieve(e,t){const n=Ee(e),{variant:i}=n;let{normalized:a}=n;return i==="keys"&&a.indexOf(0)!==-1&&(a=a.filter(o=>o!==0)),a.length===0?[]:await this.execute({[i]:a,...t})}async page(e,t,n){return await this.execute({offset:e,limit:t,...n})}async execute(e){const[t,n]=await this.client.send(Rr.ENDPOINT,e,Dd,Md);if(n!=null)throw n;return t.channels}};c(Rr,"ENDPOINT","/channel/retrieve");let Yt=Rr;class ps{constructor(e){c(this,"cache");c(this,"namesToKeys");c(this,"wrapped");this.cache=new Map,this.namesToKeys=new Map,this.wrapped=e}async search(e,t){return await this.wrapped.search(e,t)}async page(e,t,n){return await this.wrapped.page(e,t,n)}async retrieve(e,t){const{normalized:n}=Qr(e,{string:"names",number:"keys"}),i=[],a=[];if(n.forEach(l=>{const u=this.get(l);u!=null?i.push(...u):a.push(l)}),a.length===0)return i;const o=await this.wrapped.retrieve(a,t);return this.set(o),i.concat(o)}delete(e){const{variant:t,normalized:n}=Ee(e);t==="names"?n.forEach(i=>{const a=this.namesToKeys.get(i);a!=null&&(a.forEach(o=>this.cache.delete(o)),this.namesToKeys.delete(i))}):n.forEach(i=>{const a=this.cache.get(i);a!=null&&(this.cache.delete(i),this.namesToKeys.delete(a.name))})}rename(e,t){e.forEach((n,i)=>{const a=t[i],o=this.cache.get(n);if(o==null)return;this.cache.delete(n);const l=this.namesToKeys.get(o.name);l!=null&&(l.delete(n),l.size===0&&this.namesToKeys.delete(o.name)),o.name=a,this.cache.set(n,o);const u=this.namesToKeys.get(a);u==null?this.namesToKeys.set(a,new Set([n])):u.add(n)})}set(e){e.forEach(t=>{this.cache.set(t.key,t);const n=this.namesToKeys.get(t.name);n==null?this.namesToKeys.set(t.name,new Set([t.key])):n.add(t.key)})}get(e){if(typeof e=="number"){const i=this.cache.get(e);return i==null?void 0:[i]}const t=this.namesToKeys.get(e);if(t==null)return;const n=[];if(t.forEach(i=>{const a=this.cache.get(i);a!=null&&n.push(a)}),n.length!==0)return n}}class Ka{constructor(e,t){c(this,"mu",new jd);c(this,"requests",new Map);c(this,"wrapped");c(this,"debouncedRun");this.wrapped=e,this.debouncedRun=Wu(()=>{this.run()},t)}async search(e,t){return await this.wrapped.search(e,t)}async page(e,t,n){return await this.wrapped.page(e,t,n)}async retrieve(e){const{normalized:t,variant:n}=Ee(e);return n==="names"?await this.wrapped.retrieve(t):await new Promise((a,o)=>{this.mu.runExclusive(()=>{this.requests.set(t,{resolve:a,reject:o}),this.debouncedRun()})})}async run(){await this.mu.runExclusive(async()=>{const e=new Set;this.requests.forEach((t,n)=>n.forEach(i=>e.add(i)));try{const t=await this.wrapped.retrieve(Array.from(e));this.requests.forEach((n,i)=>n.resolve(t.filter(a=>i.includes(a.key))))}catch(t){this.requests.forEach(n=>n.reject(t))}finally{this.requests.clear()}})}}const Ha=async(r,e)=>{const{normalized:t}=Ee(e),n=await r.retrieve(t),i=[];if(t.forEach(a=>{n.find(o=>o.name===a||o.key===a)==null&&i.push(a)}),i.length>0)throw new ie(`Could not find channels: ${JSON.stringify(i)}`);return n};class gs{constructor({dataType:e,rate:t,name:n,leaseholder:i=0,key:a=0,isIndex:o=!1,index:l=0,internal:u=!1,virtual:h=!1,frameClient:f,alias:d,expression:k="",requires:S=[]}){c(this,"_frameClient");c(this,"key");c(this,"name");c(this,"rate");c(this,"dataType");c(this,"leaseholder");c(this,"index");c(this,"isIndex");c(this,"internal");c(this,"alias");c(this,"virtual");c(this,"expression");c(this,"requires");this.key=a,this.name=n,this.rate=new ut(t??0),this.dataType=new I(e),this.leaseholder=i,this.index=l,this.isIndex=o,this.internal=u,this.alias=d,this.virtual=h,this.expression=k,this.requires=S??[],this._frameClient=f??null}get framer(){if(this._frameClient==null)throw new U("cannot read from a channel that has not been created");return this._frameClient}get payload(){return Qt.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,virtual:this.virtual,expression:this.expression,requires:this.requires})}get isCalculated(){return Wt(this.payload)}get ontologyID(){return eo(this.key)}async read(e){return await this.framer.read(e,this.key)}async write(e,t){return await this.framer.write(e,this.key,t)}}const Bd="/channel/retrieve-group",Zd=s.z.object({}),Ud=s.z.object({group:Hn});let Xa=class{constructor(e,t,n,i){c(this,"type",Zr);c(this,"frameClient");c(this,"client");c(this,"retriever");c(this,"writer");this.frameClient=e,this.retriever=t,this.client=n,this.writer=i}async create(e,t={}){const{retrieveIfNameExists:n=!1}=t,i=!Array.isArray(e);let a=b(e),o=[];if(n){const l=await this.retriever.retrieve(a.map(h=>h.name)),u=new Set(l.map(h=>h.name));a=a.filter(h=>!u.has(h.name)),o=this.sugar(l)}return o=o.concat(this.sugar(await this.writer.create(a))),i?o[0]:o}async retrieve(e,t){const n=!Array.isArray(e),i=this.sugar(await this.retriever.retrieve(e,t));return en("channel",e,i,n),n?i[0]:i}async search(e,t){return this.sugar(await this.retriever.search(e,t))}async delete(e){const{normalized:t,variant:n}=Ee(e);return n==="keys"?await this.writer.delete({keys:t}):await this.writer.delete({names:t})}async rename(e,t){return await this.writer.rename(b(e),b(t))}newSearcherWithOptions(e){return{type:this.type,search:async t=>await this.search(t,e),retrieve:async t=>await this.retrieve(t,e),page:async(t,n)=>await this.page(t,n,e)}}async page(e,t,n){return this.sugar(await this.retriever.page(e,t,n))}createDebouncedBatchRetriever(e=10){return new ps(new Ka(new Yt(this.client),e))}sugar(e){const{frameClient:t}=this;return e.map(n=>new gs({...n,frameClient:t}))}async retrieveGroup(){const e=await w(this.client,Bd,{},Zd,Ud);return new ys(e.group.name,e.group.key)}};const Wt=({virtual:r,expression:e})=>r&&e!=="",Qa=async(r,e)=>{if(!Wt(e))return e.index;for(const t of e.requires){const n=await r(t);if(n==null)return null;if(!n.virtual)return n.index}for(const t of e.requires){const n=await r(t);if(n==null)return null;if(Wt(n)){const i=await Qa(r,n);if(i!=null)return i}}return null},eo=r=>new O({type:Zr,key:r.toString()}),Ld=s.z.object({channels:Ta.array()}),_d=s.z.object({channels:Qt.array()}),qd=s.z.object({keys:J.array().optional(),names:Xt.array().optional()}),Yd=s.z.object({}),Wd=s.z.object({keys:J.array(),names:Xt.array()}),Fd=s.z.object({}),Gd="/channel/create",Vd="/channel/delete",Jd="/channel/rename";let to=class{constructor(e,t){c(this,"client");c(this,"cache");this.client=e,this.cache=t}async create(e){const{channels:t}=await w(this.client,Gd,{channels:e},Ld,_d);return this.cache.set(t),t}async delete(e){await w(this.client,Vd,e,qd,Yd),e.keys!=null&&this.cache.delete(e.keys),e.names!=null&&this.cache.delete(e.names)}async rename(e,t){await w(this.client,Jd,{keys:e,names:t},Wd,Fd),this.cache.rename(e,t)}};const Kd=Object.freeze(Object.defineProperty({__proto__:null,CacheRetriever:ps,Channel:gs,Client:Xa,ClusterRetriever:Yt,DebouncedBatchRetriever:Ka,ONTOLOGY_TYPE:Zr,Writer:to,analyzeParams:Ee,channelZ:Qt,isCalculated:Wt,keyZ:J,nameZ:Xt,newZ:Ta,ontologyID:eo,resolveCalculatedIndex:Qa,retrieveRequired:Ha},Symbol.toStringTag,{value:"Module"})),Hd=s.z.object({keys:Ze.array().optional(),usernames:s.z.string().array().optional()}),Xd=s.z.object({users:V(sr)}),Qd="/user/retrieve";let ef=class{constructor(e){c(this,"client");this.client=e}async retrieve(e){return(await w(this.client,Qd,e,Hd,Xd)).users}};const tf=s.z.object({users:Aa.array()}),rf=s.z.object({users:sr.array()}),nf=s.z.object({key:Ze,username:s.z.string().min(1)}),sf=s.z.object({}),af=s.z.object({key:Ze,firstName:s.z.string().optional(),lastName:s.z.string().optional()}),of=s.z.object({}),cf=s.z.object({keys:Ze.array()}),lf=s.z.object({}),uf="/user/create",hf="/user/change-username",df="/user/rename",ff="/user/delete";let yf=class{constructor(e){c(this,"client");this.client=e}async create(e){return(await w(this.client,uf,{users:b(e)},tf,rf)).users}async changeUsername(e,t){await w(this.client,hf,{key:e,username:t},nf,sf)}async rename(e,t,n){await w(this.client,df,{key:e,firstName:t,lastName:n},af,of)}async delete(e){await w(this.client,ff,{keys:b(e)},cf,lf)}},ro=class{constructor(e){c(this,"reader");c(this,"writer");this.writer=new yf(e),this.reader=new ef(e)}async create(e){const t=Array.isArray(e),n=await this.writer.create(e);return t?n:n[0]}async changeUsername(e,t){await this.writer.changeUsername(e,t)}async retrieve(e){const t=Array.isArray(e),n=await this.reader.retrieve({keys:b(e)});if(t)return n;if(n.length===0)throw new Oe(`No user with key ${e} found`);if(n.length>1)throw new Ne(`Multiple users found with key ${e}`);return n[0]}async retrieveByName(e){const t=Array.isArray(e),n=await this.reader.retrieve({usernames:b(e)});if(t)return n;if(n.length===0)throw new Oe(`No user with username ${e} found`);if(n.length>1)throw new Ne(`Multiple users found with username ${e}`);return n[0]}async rename(e,t,n){await this.writer.rename(e,t,n)}async delete(e){await this.writer.delete(e)}};const pf=r=>new O({type:is,key:r}),gf=Object.freeze(Object.defineProperty({__proto__:null,Client:ro,ONTOLOGY_TYPE:is,keyZ:Ze,newZ:Aa,ontologyID:pf,userZ:sr},Symbol.toStringTag,{value:"Module"})),mf=s.z.object({username:s.z.string(),password:s.z.string()}),wf=s.z.object({token:s.z.string(),user:sr}),wi="/auth/login",bf=3,Tf="/auth/change-password",vf=s.z.object({username:s.z.string(),password:s.z.string(),newPassword:s.z.string().min(1)}),Of=s.z.object({}),Nf=[Ut,Lt];let Ef=class{constructor(e,t){c(this,"token");c(this,"client");c(this,"credentials");c(this,"authenticating");c(this,"authenticated");c(this,"user");c(this,"retryCount");this.client=e,this.authenticated=!1,this.credentials=t,this.retryCount=0}async changePassword(e){if(!this.authenticated)throw new Error("Not authenticated");await w(this.client,Tf,{username:this.credentials.username,password:this.credentials.password,newPassword:e},vf,Of),this.credentials.password=e}middleware(){const e=async(t,n)=>{if(!this.authenticated&&!t.target.endsWith(wi)){this.authenticating??(this.authenticating=new Promise((l,u)=>{this.client.send(wi,this.credentials,mf,wf).then(([h,f])=>{if(f!=null)return l(f);this.token=h==null?void 0:h.token,this.user=h==null?void 0:h.user,this.authenticated=!0,l(null)}).catch(u)}));const o=await this.authenticating;if(o!=null)return[t,o]}t.params.Authorization=`Bearer ${this.token}`;const[i,a]=await n(t);return Nf.some(o=>o.matches(a))&&this.retryCount<bf?(this.authenticated=!1,this.authenticating=void 0,this.retryCount+=1,e(t,n)):(this.retryCount=0,[i,a])};return e}};const no=s.z.enum(["disconnected","connecting","connected","failed"]),so=s.z.object({status:no,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()}),zf=s.z.object({clusterKey:s.z.string(),nodeVersion:s.z.string().optional()}),bi={clusterKey:"",status:"disconnected",error:void 0,message:"Disconnected",clientServerCompatible:!1,clientVersion:"0.39.0"},Ti=(r,e,t)=>{const n=t?"cluster":"client";return`Synnax cluster node version ${r!=null?`${r} `:""}is too ${t?"old":"new"} for client version ${e}.
|
|
36
|
+
name. keys parameter must be a set of channel keys or channel names.`)}get colType(){return this.columns.length===0?null:typeof this.columns[0]=="string"?"name":"key"}get keys(){if(this.colType==="name")throw new xe("colType is not key");return this.columns??[]}get uniqueKeys(){return Ws.unique(this.keys)}get names(){if(this.colType==="key")throw new xe("colType is not name");return this.columns??[]}get uniqueNames(){return Ws.unique(this.names)}get uniqueColumns(){return this.colType==="key"?this.uniqueKeys:this.uniqueNames}toPayload(){return{series:this.series.map(e=>Oa(e)),keys:this.keys}}get isVertical(){return this.uniqueColumns.length===this.columns.length}get isHorizontal(){return this.uniqueColumns.length===1}get isSquare(){return this.isHorizontal&&this.isVertical}get isWeaklyAligned(){if(this.columns.length<=1)return!0;const e=this.timeRanges;return e.every(t=>t.equals(e[0]))}timeRange(e){if(e==null){if(this.columns.length===0)return G.ZERO;const n=$.min(...this.series.map(a=>a.timeRange.start)),i=$.max(...this.series.map(a=>a.timeRange.end));return new G(n,i)}const t=this.get(e);return t==null?G.ZERO:t.timeRange}latest(){return this.at(-1)}get timeRanges(){return this.uniqueColumns.map(e=>this.timeRange(e))}get(e){return Array.isArray(e)?this.filter(t=>e.includes(t)):new fa(this.series.filter((t,n)=>this.columns[n]===e))}push(e,...t){if(e instanceof Y){if(this.colType!==null&&e.colType!==this.colType)throw new U("keyVariant must match");this.series.push(...e.series),this.columns.push(...e.columns)}else{if(this.series.push(...t),typeof e=="string"&&this.colType==="key")throw new U("keyVariant must match");if(typeof e!="string"&&this.colType==="name")throw new U("keyVariant must match");this.columns.push(...Array.from({length:t.length},()=>e))}}concat(e){return new Y([...this.columns,...e.columns],[...this.series,...e.series])}has(e){return typeof e=="string"&&this.colType==="key"||typeof e=="number"&&this.colType==="name"?!1:this.columns.includes(e)}map(e){const t=new Y;return this.forEach((n,i,a)=>t.push(...e(n,i,a))),t}forEach(e){this.columns.forEach((t,n)=>{const i=this.series[n];e(t,i,n)})}at(e,t=!1){const n={};return this.uniqueColumns.forEach(i=>{n[i]=this.get(i).at(e,t)}),n}filter(e){const t=new Y;return this.columns.forEach((n,i)=>{const a=this.series[i];e(n,a,i)&&t.push(n,a)}),t}get byteLength(){return new ht(this.series.reduce((e,t)=>e.add(t.byteLength),ht.ZERO))}get digest(){const e={};return this.keys.forEach((t,n)=>{const i=this.series[n].digest;t in e?e[t].push(i):e[t]=[i]}),e}get length(){return this.series.reduce((e,t)=>e+t.length,0)}}const Ur=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([])])}),va=r=>{const{dataType:e,data:t,timeRange:n,alignment:i}=r;return new ke({data:t,dataType:e,timeRange:n,glBufferUsage:"static",alignment:i})},Oa=r=>({timeRange:r._timeRange,dataType:r.dataType,data:new Uint8Array(r.data.buffer),alignment:r.alignment}),mt=$h.uint32,Lr=s.z.object({key:mt,name:s.z.string()}),Na=Lr.partial({key:!0}),_r="rack",Ea=r=>r?Jt.JSON_CODEC.decodeString(r):{},qr=s.z.string(),er=s.z.object({key:qr,rack:mt,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(Ea))}),za=er.extend({properties:s.z.unknown().transform(r=>Jt.JSON_CODEC.encodeString(r))}),Yr="device",ye=r=>r?JSON.parse(r):{},je=s.z.union([s.z.string(),s.z.bigint().transform(r=>r.toString()),s.z.number().transform(r=>r.toString())]),Sa=s.z.enum(["info","success","error","warning"]),qt=s.z.object({task:je,variant:Sa,key:s.z.string().optional(),details:s.z.record(s.z.unknown()).or(s.z.string().transform(ye)).or(s.z.array(s.z.unknown())).or(s.z.null())}),tr=s.z.object({key:je,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(Ea)),state:qt.optional().nullable(),snapshot:s.z.boolean().optional()}),Ia=tr.omit({key:!0}).extend({key:je.transform(r=>r.toString()).optional(),config:s.z.unknown().transform(r=>Jt.JSON_CODEC.encodeString(r))}),es=s.z.object({task:je,type:s.z.string(),key:s.z.string(),args:s.z.record(s.z.unknown()).or(s.z.string().transform(ye)).or(s.z.array(s.z.unknown())).or(s.z.null()).optional()}),Wr="task",Jh=r=>Number(BigInt(r)>>32n),wt=s.z.string().uuid(),rr=s.z.object({key:wt,name:s.z.string().min(1),color:s.z.string()}),ts="label",ne=s.z.string().uuid(),rs=s.z.string().min(1),nr=s.z.object({key:ne,name:rs,timeRange:G.z,color:s.z.string().optional()}),$a=nr.partial({key:!0}),ka=r=>{const e=b(r),t=e.length===0;let n=!1;return t||(n=ne.safeParse(e[0]).success),{single:!Array.isArray(r),variant:n?"keys":"names",normalized:e,actual:r,empty:t}},ns="range",ss="range-alias",Ze=s.z.string().uuid(),sr=s.z.object({key:Ze,username:s.z.string().min(1),firstName:s.z.string().default(""),lastName:s.z.string().default(""),rootUser:s.z.boolean().default(!0)}),Aa=sr.partial({key:!0,firstName:!0,lastName:!0}).omit({rootUser:!0}).extend({password:s.z.string().min(1)}),is="user",bt=s.z.string().uuid(),Fr=s.z.object({key:bt,name:s.z.string(),data:Kt.or(s.z.string().transform(ye))}),xa=Fr.partial({key:!0}).transform(r=>({...r,data:JSON.stringify(r.data)})),as="lineplot",Tt=s.z.string().uuid(),Gr=s.z.object({key:Tt,name:s.z.string(),data:Kt.or(s.z.string().transform(ye))}),Ra=Gr.partial({key:!0}).transform(r=>({...r,data:JSON.stringify(r.data)})),os="log",pe=s.z.string().uuid(),Vr=s.z.object({key:pe,name:s.z.string(),layout:Kt.or(s.z.string().transform(ye))}),Jr="workspace",Ca=Vr.partial({key:!0}).transform(r=>({...r,layout:JSON.stringify(r.layout)})),Pa=Vr.omit({layout:!0}).extend({layout:s.z.string().transform(ye)}),Ue=s.z.string().uuid(),Kr=s.z.object({key:Ue,name:s.z.string(),data:Kt.or(s.z.string().transform(ye)),snapshot:s.z.boolean()}),ja=Kr.partial({key:!0,snapshot:!0}).transform(r=>({...r,data:JSON.stringify(r.data)})),cs=Kr.extend({data:s.z.string().transform(ye)}),ls="schematic",vt=s.z.string().uuid(),us=s.z.object({key:vt,name:s.z.string(),data:Kt.or(s.z.string().transform(ye))}),Da=us.partial({key:!0}).transform(r=>({...r,data:JSON.stringify(r.data)})),hs=us.extend({data:s.z.string().transform(ye)}),ds="table",fs="builtin",Ma="cluster",Ba="node",ir=s.z.enum([ts,os,Fn,fs,Ma,Zr,Ba,Xn,ns,Qn,ss,is,Jr,ls,as,_r,Yr,Wr,Wn,ds]),re=s.z.object({type:ir,key:s.z.string()}),Za=s.z.string().transform(r=>{const[e,t]=r.split(":");return{type:ir.parse(e),key:t??""}}),We=s.z.union([Za,re]),at=class at{constructor(e){c(this,"type");c(this,"key");if(e instanceof at){this.type=e.type,this.key=e.key;return}if(typeof e=="string"){const[t,n]=e.split(":");this.type=t,this.key=n??"";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}}};c(at,"z",s.z.union([s.z.instanceof(at),We.transform(e=>new at(e))]));let O=at;const Kh=new O({type:fs,key:"root"}),Ua=s.z.object({type:s.z.number()}),La=s.z.object({type:ir,fields:s.z.record(Ua)}),_a=s.z.object({id:O.z,name:s.z.string(),schema:La.optional().nullable(),data:s.z.record(s.z.unknown()).optional().nullable()}).transform(r=>({key:r.id.toString(),...r})),Hh="to",Xh="from",Qh=s.z.object({from:O.z,type:s.z.string(),to:O.z}),_n=r=>{const[e,t,n]=r.split("->");return{from:new O(e),type:t,to:new O(n)}};class ys{constructor(e,t){c(this,"key");c(this,"name");this.key=t,this.name=e}get ontologyID(){return qa(this.key)}}const qa=r=>new O({type:Xn,key:r}),ed=s.z.object({group:Hn}),td=s.z.object({parent:re,key:gt.optional(),name:Br}),rd=s.z.object({key:gt,name:Br}),nd=s.z.object({keys:s.z.array(gt)});var ae;let sd=(ae=class{constructor(e){c(this,"client");this.client=e}async create(e,t,n){return(await w(this.client,ae.CREATE_ENDPOINT,{parent:e,name:t,key:n},td,ed)).group}async rename(e,t){await w(this.client,ae.RENAME_ENDPOINT,{key:e,name:t},rd,s.z.object({}))}async delete(e){await w(this.client,ae.DELETE_ENDPOINT,{keys:e},nd,s.z.object({}))}},c(ae,"CREATE_ENDPOINT","/ontology/create-group"),c(ae,"RENAME_ENDPOINT","/ontology/rename-group"),c(ae,"DELETE_ENDPOINT","/ontology/delete-group"),ae),Ya=class{constructor(e){c(this,"creator");this.creator=new sd(e)}async create(e,t,n){return this.sugar(await this.creator.create(e,t,n))}async rename(e,t){return await this.creator.rename(e,t)}async delete(...e){return await this.creator.delete(e)}sugar(e){return new ys(e.name,e.key)}};const id=Object.freeze(Object.defineProperty({__proto__:null,Client:Ya,Group:ys,ONTOLOGY_TYPE:Xn,analyzeParams:Vh,groupZ:Hn,keyZ:gt,nameZ:Br,ontologyID:qa},Symbol.toStringTag,{value:"Module"})),ad="/ontology/add-children",od="/ontology/remove-children",cd="/ontology/move-children",di=s.z.object({id:re,children:re.array()}),ld=s.z.object({from:re,to:re,children:re.array()}),pn=s.z.object({});let ud=class{constructor(e){c(this,"client");this.client=e}async addChildren(e,...t){await w(this.client,ad,{id:new O(e).payload,children:t.map(n=>new O(n).payload)},di,pn)}async removeChildren(e,...t){await w(this.client,od,{id:new O(e).payload,children:t.map(n=>new O(n).payload)},di,pn)}async moveChildren(e,t,...n){const i={from:new O(e).payload,to:new O(t).payload,children:n.map(a=>new O(a).payload)};await w(this.client,cd,i,ld,pn)}};const hd="/ontology/retrieve",dd=s.z.object({ids:re.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:ir.array().optional()}),fd=s.z.object({resources:_a.array()}),Nr=r=>b(r).map(e=>new O(e).payload);let Wa=class{constructor(e,t){c(this,"type","ontology");c(this,"groups");c(this,"client");c(this,"writer");c(this,"framer");this.client=e,this.writer=new ud(e),this.groups=new Ya(e),this.framer=t}async search(e,t){return await this.execRetrieve({term:e,...t})}async retrieve(e,t){const n=await this.execRetrieve({ids:Nr(e),...t});if(Array.isArray(e))return n;if(n.length===0)throw new ie(`No resource found with ID ${Yh.naturalLanguageJoin(b(e).map(i=>new O(i).toString()))}`);return n[0]}async page(e,t,n){return await this.execRetrieve({offset:e,limit:t,...n})}async retrieveChildren(e,t){return await this.execRetrieve({ids:Nr(e),children:!0,...t})}async retrieveParents(e,t){return await this.execRetrieve({ids:Nr(e),parents:!0,...t})}async addChildren(e,...t){return await this.writer.addChildren(e,...t)}async removeChildren(e,...t){return await this.writer.removeChildren(e,...t)}async moveChildren(e,t,...n){return await this.writer.moveChildren(e,t,...n)}async openChangeTracker(){return await ar.open(this.framer,this)}async openDependentTracker(e){return await Hr.open(e,this.framer,this)}newSearcherWithOptions(e){return{type:this.type,search:t=>this.search(t,e),retrieve:t=>this.retrieve(t,e),page:(t,n)=>this.page(t,n,e)}}async execRetrieve(e){const{resources:t}=await w(this.client,hd,e,dd,fd);return t}};const fi="sy_ontology_resource_set",yi="sy_ontology_resource_delete",pi="sy_ontology_relationship_set",gi="sy_ontology_relationship_delete";class ar{constructor(e,t){c(this,"relationships");c(this,"resources");c(this,"resourceObs");c(this,"relationshipObs");c(this,"streamer");c(this,"client");c(this,"closePromise");this.relationshipObs=new Me.Observer,this.relationships=this.relationshipObs,this.resourceObs=new Me.Observer,this.resources=this.resourceObs,this.client=t,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 t=await this.parseResourceSets(e),n=this.parseResourceDeletes(e);t.concat(n).length>0&&this.resourceObs.notify(t.concat(n));const a=this.parseRelationshipSets(e),o=this.parseRelationshipDeletes(e);a.concat(o).length>0&&this.relationshipObs.notify(a.concat(o))}parseRelationshipSets(e){const t=e.get(pi);return t.length===0?[]:Array.from(t.as("string")).map(n=>({variant:"set",key:_n(n),value:void 0}))}parseRelationshipDeletes(e){const t=e.get(gi);return t.length===0?[]:Array.from(t.as("string")).map(n=>({variant:"delete",key:_n(n)}))}async parseResourceSets(e){const t=e.get(fi);if(t.length===0)return[];const n=Array.from(t.as("string")).map(i=>new O(i));try{return(await this.client.retrieve(n)).map(a=>({variant:"set",key:a.id,value:a}))}catch(i){if(i instanceof ie)return[];throw i}}parseResourceDeletes(e){const t=e.get(yi);return t.length===0?[]:Array.from(t.as("string")).map(n=>({variant:"delete",key:new O(n)}))}static async open(e,t){const n=await e.openStreamer([fi,yi,pi,gi]);return new ar(n,t)}}const mi=r=>r==="from"?"to":"from";class Hr extends Me.Observer{constructor({target:t,dependents:n,relationshipType:i="parent",relationshipDirection:a="from",resourceType:o},l,u){super();c(this,"internal");c(this,"target");c(this,"relDir");c(this,"resourceType");c(this,"dependents");c(this,"client");c(this,"relType");c(this,"handleResourceChange",t=>{this.dependents=this.dependents.map(n=>{const i=t.find(a=>a.key.toString()==n.id.toString());return i==null||i.variant==="delete"?n:i.value}),this.notify(this.dependents)});c(this,"handleRelationshipChange",t=>{const n=t.filter(a=>a.variant==="delete"&&a.key[this.relDir].toString()===this.target.toString()&&(this.resourceType==null||a.key[mi(this.relDir)].type===this.resourceType));this.dependents=this.dependents.filter(a=>!n.some(o=>o.key.to.toString()===a.id.toString()&&o.key.type===this.relType));const i=t.filter(a=>a.variant==="set"&&a.key.type===this.relType&&a.key[this.relDir].toString()===this.target.toString()&&(this.resourceType==null||a.key[mi(this.relDir)].type===this.resourceType));if(i.length===0)return this.notify(this.dependents);this.client.retrieve(i.map(a=>a.key.to)).then(a=>{this.dependents=this.dependents.concat(a),this.notify(this.dependents)}).catch(console.error)});this.resourceType=o,this.internal=l,this.target=t,this.dependents=n,this.resourceType!=null&&(this.dependents=this.dependents.filter(h=>h.id.type===this.resourceType)),this.client=u,this.relType=i,this.relDir=a,this.internal.resources.onChange(this.handleResourceChange),this.internal.relationships.onChange(this.handleRelationshipChange)}static async open(t,n,i){const a=await ar.open(n,i);return new Hr(t,a,i)}async close(){await this.internal.close()}}const yd=Object.freeze(Object.defineProperty({__proto__:null,BUILTIN_TYPE:fs,CLUSTER_TYPE:Ma,ChangeTracker:ar,Client:Wa,DependentTracker:Hr,FROM_RELATIONSHIP_DIRECTION:Xh,ID:O,NODE_TYPE:Ba,ROOT_ID:Kh,TO_RELATIONSHIP_DIRECTION:Hh,crudeIDZ:We,idZ:re,parseIDs:Nr,parseRelationship:_n,relationshipSchemaZ:Qh,resourceTypeZ:ir,resourceZ:_a,schemaFieldZ:Ua,schemaZ:La,stringIDZ:Za},Symbol.toStringTag,{value:"Module"})),or=s.z.string().uuid(),Xr=s.z.object({key:or,subjects:V(re),objects:V(re),actions:V(Sr)}),Fa=s.z.object({key:or.optional(),subjects:We.array().or(We),objects:We.array().or(We),actions:Sr.array().or(Sr)}),pd=s.z.object({keys:or.array().optional(),subjects:re.array().optional()}),gd=s.z.object({policies:V(Xr)}),md="/access/policy/retrieve";let wd=class{constructor(e){c(this,"client");this.client=e}async retrieve(e){return(await w(this.client,md,e,pd,gd)).policies}};const bd=s.z.object({policies:Xr.partial({key:!0}).array()}),Td=s.z.object({policies:Xr.array()}),vd=s.z.object({keys:or.array()}),Od=s.z.object({}),Nd="/access/policy/create",Ed="/access/policy/delete";let zd=class{constructor(e){c(this,"client");this.client=e}async create(e){const n=Fa.array().parse(b(e)).map(a=>({objects:b(a.objects),actions:b(a.actions),subjects:b(a.subjects)}));return(await w(this.client,Nd,{policies:n},bd,Td)).policies}async delete(e){await w(this.client,Ed,{keys:b(e)},vd,Od)}},Ga=class{constructor(e){c(this,"retriever");c(this,"writer");this.retriever=new wd(e),this.writer=new zd(e)}async create(e){const t=Array.isArray(e),n=await this.writer.create(e);return t?n:n[0]}async retrieve(e){const t=Array.isArray(e),n=await this.retriever.retrieve({keys:b(e)});return t?n:n[0]}async retrieveFor(e){const t=b(e).map(n=>new O(n).payload);return await this.retriever.retrieve({subjects:t})}async delete(e){await this.writer.delete(e)}};const Sd=r=>new O({type:Wn,key:r}),Id=new O({type:Fn,key:""}),$d=Object.freeze(Object.defineProperty({__proto__:null,ALLOW_ALL_ONTOLOGY_ID:Id,ALLOW_ALL_ONTOLOGY_TYPE:Fn,Client:Ga,ONTOLOGY_TYPE:Wn,keyZ:or,newZ:Fa,ontologyID:Sd,policyZ:Xr},Symbol.toStringTag,{value:"Module"}));let Va=class{constructor(e){c(this,"policy");this.policy=new Ga(e)}};const kd=Object.freeze(Object.defineProperty({__proto__:null,ALL_ACTION:Gi,CREATE_ACTION:Vi,Client:Va,DELETE_ACTION:Ji,RETRIEVE_ACTION:Ki,UPDATE_ACTION:Hi,actionZ:Sr},Symbol.toStringTag,{value:"Module"})),Ad=new Error("request for lock canceled");var xd=function(r,e,t,n){function i(a){return a instanceof t?a:new t(function(o){o(a)})}return new(t||(t=Promise))(function(a,o){function l(f){try{h(n.next(f))}catch(d){o(d)}}function u(f){try{h(n.throw(f))}catch(d){o(d)}}function h(f){f.done?a(f.value):i(f.value).then(l,u)}h((n=n.apply(r,e||[])).next())})};class Rd{constructor(e,t=Ad){this._value=e,this._cancelError=t,this._queue=[],this._weightedWaiters=[]}acquire(e=1,t=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return new Promise((n,i)=>{const a={resolve:n,reject:i,weight:e,priority:t},o=Ja(this._queue,l=>t<=l.priority);o===-1&&e<=this._value?this._dispatchItem(a):this._queue.splice(o+1,0,a)})}runExclusive(e){return xd(this,arguments,void 0,function*(t,n=1,i=0){const[a,o]=yield this.acquire(n,i);try{return yield t(a)}finally{o()}})}waitForUnlock(e=1,t=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return this._couldLockImmediately(e,t)?Promise.resolve():new Promise(n=>{this._weightedWaiters[e-1]||(this._weightedWaiters[e-1]=[]),Cd(this._weightedWaiters[e-1],{resolve:n,priority:t})})}isLocked(){return this._value<=0}getValue(){return this._value}setValue(e){this._value=e,this._dispatchQueue()}release(e=1){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);this._value+=e,this._dispatchQueue()}cancel(){this._queue.forEach(e=>e.reject(this._cancelError)),this._queue=[]}_dispatchQueue(){for(this._drainUnlockWaiters();this._queue.length>0&&this._queue[0].weight<=this._value;)this._dispatchItem(this._queue.shift()),this._drainUnlockWaiters()}_dispatchItem(e){const t=this._value;this._value-=e.weight,e.resolve([t,this._newReleaser(e.weight)])}_newReleaser(e){let t=!1;return()=>{t||(t=!0,this.release(e))}}_drainUnlockWaiters(){if(this._queue.length===0)for(let e=this._value;e>0;e--){const t=this._weightedWaiters[e-1];t&&(t.forEach(n=>n.resolve()),this._weightedWaiters[e-1]=[])}else{const e=this._queue[0].priority;for(let t=this._value;t>0;t--){const n=this._weightedWaiters[t-1];if(!n)continue;const i=n.findIndex(a=>a.priority<=e);(i===-1?n:n.splice(0,i)).forEach(a=>a.resolve())}}}_couldLockImmediately(e,t){return(this._queue.length===0||this._queue[0].priority<t)&&e<=this._value}}function Cd(r,e){const t=Ja(r,n=>e.priority<=n.priority);r.splice(t+1,0,e)}function Ja(r,e){for(let t=r.length-1;t>=0;t--)if(e(r[t]))return t;return-1}var Pd=function(r,e,t,n){function i(a){return a instanceof t?a:new t(function(o){o(a)})}return new(t||(t=Promise))(function(a,o){function l(f){try{h(n.next(f))}catch(d){o(d)}}function u(f){try{h(n.throw(f))}catch(d){o(d)}}function h(f){f.done?a(f.value):i(f.value).then(l,u)}h((n=n.apply(r,e||[])).next())})};class jd{constructor(e){this._semaphore=new Rd(1,e)}acquire(){return Pd(this,arguments,void 0,function*(e=0){const[,t]=yield this._semaphore.acquire(1,e);return t})}runExclusive(e,t=0){return this._semaphore.runExclusive(()=>e(),1,t)}isLocked(){return this._semaphore.isLocked()}waitForUnlock(e=0){return this._semaphore.waitForUnlock(1,e)}release(){this._semaphore.isLocked()&&this._semaphore.release()}cancel(){return this._semaphore.cancel()}}const Qr=(r,e,{convertNumericStrings:t=!0}={})=>{const n=!Array.isArray(r);let i=b(r);const a=i[0],o=typeof a;let l;return o==="string"&&t&&!isNaN(parseInt(a))&&"number"in e?(l=e.number,i=i.map(u=>parseInt(u))):l=e[o],{single:n,variant:l,normalized:i,actual:r}},en=(r,e,t,n)=>{if(n){if(t.length===0)throw new Oe(`${r} not found matching ${JSON.stringify(e)}`);if(t.length>1)throw new Ne(`Expected one ${r} matching ${JSON.stringify(e)}, but found ${t.length}`)}},Dd=s.z.object({leaseholder:s.z.number().optional(),keys:J.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:I.z.array().optional(),notDataTypes:I.z.array().optional(),virtual:s.z.boolean().optional(),isIndex:s.z.boolean().optional(),internal:s.z.boolean().optional()}),Md=s.z.object({channels:V(Qt)}),Ee=r=>Qr(r,{number:"keys",string:"names"}),Rr=class Rr{constructor(e){c(this,"client");this.client=e}async search(e,t){return await this.execute({search:e,...t})}async retrieve(e,t){const n=Ee(e),{variant:i}=n;let{normalized:a}=n;return i==="keys"&&a.indexOf(0)!==-1&&(a=a.filter(o=>o!==0)),a.length===0?[]:await this.execute({[i]:a,...t})}async page(e,t,n){return await this.execute({offset:e,limit:t,...n})}async execute(e){const[t,n]=await this.client.send(Rr.ENDPOINT,e,Dd,Md);if(n!=null)throw n;return t.channels}};c(Rr,"ENDPOINT","/channel/retrieve");let Yt=Rr;class ps{constructor(e){c(this,"cache");c(this,"namesToKeys");c(this,"wrapped");this.cache=new Map,this.namesToKeys=new Map,this.wrapped=e}async search(e,t){return await this.wrapped.search(e,t)}async page(e,t,n){return await this.wrapped.page(e,t,n)}async retrieve(e,t){const{normalized:n}=Qr(e,{string:"names",number:"keys"}),i=[],a=[];if(n.forEach(l=>{const u=this.get(l);u!=null?i.push(...u):a.push(l)}),a.length===0)return i;const o=await this.wrapped.retrieve(a,t);return this.set(o),i.concat(o)}delete(e){const{variant:t,normalized:n}=Ee(e);t==="names"?n.forEach(i=>{const a=this.namesToKeys.get(i);a!=null&&(a.forEach(o=>this.cache.delete(o)),this.namesToKeys.delete(i))}):n.forEach(i=>{const a=this.cache.get(i);a!=null&&(this.cache.delete(i),this.namesToKeys.delete(a.name))})}rename(e,t){e.forEach((n,i)=>{const a=t[i],o=this.cache.get(n);if(o==null)return;this.cache.delete(n);const l=this.namesToKeys.get(o.name);l!=null&&(l.delete(n),l.size===0&&this.namesToKeys.delete(o.name)),o.name=a,this.cache.set(n,o);const u=this.namesToKeys.get(a);u==null?this.namesToKeys.set(a,new Set([n])):u.add(n)})}set(e){e.forEach(t=>{this.cache.set(t.key,t);const n=this.namesToKeys.get(t.name);n==null?this.namesToKeys.set(t.name,new Set([t.key])):n.add(t.key)})}get(e){if(typeof e=="number"){const i=this.cache.get(e);return i==null?void 0:[i]}const t=this.namesToKeys.get(e);if(t==null)return;const n=[];if(t.forEach(i=>{const a=this.cache.get(i);a!=null&&n.push(a)}),n.length!==0)return n}}class Ka{constructor(e,t){c(this,"mu",new jd);c(this,"requests",new Map);c(this,"wrapped");c(this,"debouncedRun");this.wrapped=e,this.debouncedRun=Wu(()=>{this.run()},t)}async search(e,t){return await this.wrapped.search(e,t)}async page(e,t,n){return await this.wrapped.page(e,t,n)}async retrieve(e){const{normalized:t,variant:n}=Ee(e);return n==="names"?await this.wrapped.retrieve(t):await new Promise((a,o)=>{this.mu.runExclusive(()=>{this.requests.set(t,{resolve:a,reject:o}),this.debouncedRun()})})}async run(){await this.mu.runExclusive(async()=>{const e=new Set;this.requests.forEach((t,n)=>n.forEach(i=>e.add(i)));try{const t=await this.wrapped.retrieve(Array.from(e));this.requests.forEach((n,i)=>n.resolve(t.filter(a=>i.includes(a.key))))}catch(t){this.requests.forEach(n=>n.reject(t))}finally{this.requests.clear()}})}}const Ha=async(r,e)=>{const{normalized:t}=Ee(e),n=await r.retrieve(t),i=[];if(t.forEach(a=>{n.find(o=>o.name===a||o.key===a)==null&&i.push(a)}),i.length>0)throw new ie(`Could not find channels: ${JSON.stringify(i)}`);return n};class gs{constructor({dataType:e,rate:t,name:n,leaseholder:i=0,key:a=0,isIndex:o=!1,index:l=0,internal:u=!1,virtual:h=!1,frameClient:f,alias:d,expression:k="",requires:S=[]}){c(this,"_frameClient");c(this,"key");c(this,"name");c(this,"rate");c(this,"dataType");c(this,"leaseholder");c(this,"index");c(this,"isIndex");c(this,"internal");c(this,"alias");c(this,"virtual");c(this,"expression");c(this,"requires");this.key=a,this.name=n,this.rate=new ut(t??0),this.dataType=new I(e),this.leaseholder=i,this.index=l,this.isIndex=o,this.internal=u,this.alias=d,this.virtual=h,this.expression=k,this.requires=S??[],this._frameClient=f??null}get framer(){if(this._frameClient==null)throw new U("cannot read from a channel that has not been created");return this._frameClient}get payload(){return Qt.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,virtual:this.virtual,expression:this.expression,requires:this.requires})}get isCalculated(){return Wt(this.payload)}get ontologyID(){return eo(this.key)}async read(e){return await this.framer.read(e,this.key)}async write(e,t){return await this.framer.write(e,this.key,t)}}const Bd="/channel/retrieve-group",Zd=s.z.object({}),Ud=s.z.object({group:Hn});let Xa=class{constructor(e,t,n,i){c(this,"type",Zr);c(this,"frameClient");c(this,"client");c(this,"retriever");c(this,"writer");this.frameClient=e,this.retriever=t,this.client=n,this.writer=i}async create(e,t={}){const{retrieveIfNameExists:n=!1}=t,i=!Array.isArray(e);let a=b(e),o=[];if(n){const l=await this.retriever.retrieve(a.map(h=>h.name)),u=new Set(l.map(h=>h.name));a=a.filter(h=>!u.has(h.name)),o=this.sugar(l)}return o=o.concat(this.sugar(await this.writer.create(a))),i?o[0]:o}async retrieve(e,t){const n=!Array.isArray(e),i=this.sugar(await this.retriever.retrieve(e,t));return en("channel",e,i,n),n?i[0]:i}async search(e,t){return this.sugar(await this.retriever.search(e,t))}async delete(e){const{normalized:t,variant:n}=Ee(e);return n==="keys"?await this.writer.delete({keys:t}):await this.writer.delete({names:t})}async rename(e,t){return await this.writer.rename(b(e),b(t))}newSearcherWithOptions(e){return{type:this.type,search:async t=>await this.search(t,e),retrieve:async t=>await this.retrieve(t,e),page:async(t,n)=>await this.page(t,n,e)}}async page(e,t,n){return this.sugar(await this.retriever.page(e,t,n))}createDebouncedBatchRetriever(e=10){return new ps(new Ka(new Yt(this.client),e))}sugar(e){const{frameClient:t}=this;return e.map(n=>new gs({...n,frameClient:t}))}async retrieveGroup(){const e=await w(this.client,Bd,{},Zd,Ud);return new ys(e.group.name,e.group.key)}};const Wt=({virtual:r,expression:e})=>r&&e!=="",Qa=async(r,e)=>{if(!Wt(e))return e.index;for(const t of e.requires){const n=await r(t);if(n==null)return null;if(!n.virtual)return n.index}for(const t of e.requires){const n=await r(t);if(n==null)return null;if(Wt(n)){const i=await Qa(r,n);if(i!=null)return i}}return null},eo=r=>new O({type:Zr,key:r.toString()}),Ld=s.z.object({channels:Ta.array()}),_d=s.z.object({channels:Qt.array()}),qd=s.z.object({keys:J.array().optional(),names:Xt.array().optional()}),Yd=s.z.object({}),Wd=s.z.object({keys:J.array(),names:Xt.array()}),Fd=s.z.object({}),Gd="/channel/create",Vd="/channel/delete",Jd="/channel/rename";let to=class{constructor(e,t){c(this,"client");c(this,"cache");this.client=e,this.cache=t}async create(e){const{channels:t}=await w(this.client,Gd,{channels:e},Ld,_d);return this.cache.set(t),t}async delete(e){await w(this.client,Vd,e,qd,Yd),e.keys!=null&&this.cache.delete(e.keys),e.names!=null&&this.cache.delete(e.names)}async rename(e,t){await w(this.client,Jd,{keys:e,names:t},Wd,Fd),this.cache.rename(e,t)}};const Kd=Object.freeze(Object.defineProperty({__proto__:null,CacheRetriever:ps,Channel:gs,Client:Xa,ClusterRetriever:Yt,DebouncedBatchRetriever:Ka,ONTOLOGY_TYPE:Zr,Writer:to,analyzeParams:Ee,channelZ:Qt,isCalculated:Wt,keyZ:J,nameZ:Xt,newZ:Ta,ontologyID:eo,resolveCalculatedIndex:Qa,retrieveRequired:Ha},Symbol.toStringTag,{value:"Module"})),Hd=s.z.object({keys:Ze.array().optional(),usernames:s.z.string().array().optional()}),Xd=s.z.object({users:V(sr)}),Qd="/user/retrieve";let ef=class{constructor(e){c(this,"client");this.client=e}async retrieve(e){return(await w(this.client,Qd,e,Hd,Xd)).users}};const tf=s.z.object({users:Aa.array()}),rf=s.z.object({users:sr.array()}),nf=s.z.object({key:Ze,username:s.z.string().min(1)}),sf=s.z.object({}),af=s.z.object({key:Ze,firstName:s.z.string().optional(),lastName:s.z.string().optional()}),of=s.z.object({}),cf=s.z.object({keys:Ze.array()}),lf=s.z.object({}),uf="/user/create",hf="/user/change-username",df="/user/rename",ff="/user/delete";let yf=class{constructor(e){c(this,"client");this.client=e}async create(e){return(await w(this.client,uf,{users:b(e)},tf,rf)).users}async changeUsername(e,t){await w(this.client,hf,{key:e,username:t},nf,sf)}async rename(e,t,n){await w(this.client,df,{key:e,firstName:t,lastName:n},af,of)}async delete(e){await w(this.client,ff,{keys:b(e)},cf,lf)}},ro=class{constructor(e){c(this,"reader");c(this,"writer");this.writer=new yf(e),this.reader=new ef(e)}async create(e){const t=Array.isArray(e),n=await this.writer.create(e);return t?n:n[0]}async changeUsername(e,t){await this.writer.changeUsername(e,t)}async retrieve(e){const t=Array.isArray(e),n=await this.reader.retrieve({keys:b(e)});if(t)return n;if(n.length===0)throw new Oe(`No user with key ${e} found`);if(n.length>1)throw new Ne(`Multiple users found with key ${e}`);return n[0]}async retrieveByName(e){const t=Array.isArray(e),n=await this.reader.retrieve({usernames:b(e)});if(t)return n;if(n.length===0)throw new Oe(`No user with username ${e} found`);if(n.length>1)throw new Ne(`Multiple users found with username ${e}`);return n[0]}async rename(e,t,n){await this.writer.rename(e,t,n)}async delete(e){await this.writer.delete(e)}};const pf=r=>new O({type:is,key:r}),gf=Object.freeze(Object.defineProperty({__proto__:null,Client:ro,ONTOLOGY_TYPE:is,keyZ:Ze,newZ:Aa,ontologyID:pf,userZ:sr},Symbol.toStringTag,{value:"Module"})),mf=s.z.object({username:s.z.string(),password:s.z.string()}),wf=s.z.object({token:s.z.string(),user:sr}),wi="/auth/login",bf=3,Tf="/auth/change-password",vf=s.z.object({username:s.z.string(),password:s.z.string(),newPassword:s.z.string().min(1)}),Of=s.z.object({}),Nf=[Ut,Lt];let Ef=class{constructor(e,t){c(this,"token");c(this,"client");c(this,"credentials");c(this,"authenticating");c(this,"authenticated");c(this,"user");c(this,"retryCount");this.client=e,this.authenticated=!1,this.credentials=t,this.retryCount=0}async changePassword(e){if(!this.authenticated)throw new Error("Not authenticated");await w(this.client,Tf,{username:this.credentials.username,password:this.credentials.password,newPassword:e},vf,Of),this.credentials.password=e}middleware(){const e=async(t,n)=>{if(!this.authenticated&&!t.target.endsWith(wi)){this.authenticating??(this.authenticating=new Promise((l,u)=>{this.client.send(wi,this.credentials,mf,wf).then(([h,f])=>{if(f!=null)return l(f);this.token=h==null?void 0:h.token,this.user=h==null?void 0:h.user,this.authenticated=!0,l(null)}).catch(u)}));const o=await this.authenticating;if(o!=null)return[t,o]}t.params.Authorization=`Bearer ${this.token}`;const[i,a]=await n(t);return Nf.some(o=>o.matches(a))&&this.retryCount<bf?(this.authenticated=!1,this.authenticating=void 0,this.retryCount+=1,e(t,n)):(this.retryCount=0,[i,a])};return e}};const no=s.z.enum(["disconnected","connecting","connected","failed"]),so=s.z.object({status:no,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()}),zf=s.z.object({clusterKey:s.z.string(),nodeVersion:s.z.string().optional()}),bi={clusterKey:"",status:"disconnected",error:void 0,message:"Disconnected",clientServerCompatible:!1,clientVersion:"0.40.0"},Ti=(r,e,t)=>{const n=t?"cluster":"client";return`Synnax cluster node version ${r!=null?`${r} `:""}is too ${t?"old":"new"} for client version ${e}.
|
|
37
37
|
This may cause compatibility issues. We recommend updating the ${n}. For more information, see
|
|
38
38
|
https://docs.synnaxlabs.com/reference/typescript-client/troubleshooting#old-${n}-version`},ot=class ot{constructor(e,t=N.seconds(30),n,i){c(this,"_state");c(this,"pollFrequency",N.seconds(30));c(this,"client");c(this,"name");c(this,"interval");c(this,"clientVersion");c(this,"onChangeHandlers",[]);c(this,"versionWarned",!1);this._state={...bi},this.client=e,this.pollFrequency=t,this.clientVersion=n,this.name=i,this.check(),this.startChecking()}stopChecking(){this.interval!=null&&clearInterval(this.interval)}async check(){var t;const e=this._state.status;try{const[n,i]=await this.client.send(ot.ENDPOINT,{},s.z.object({}),zf);if(i!=null)throw i;const a=n.nodeVersion,o=this.clientVersion,l=this.versionWarned;a==null?(this._state.clientServerCompatible=!1,l||(console.warn(Ti(null,o,!0)),this.versionWarned=!0)):li.versionsEqual(o,a,{checkMajor:!0,checkMinor:!0,checkPatch:!1})?this._state.clientServerCompatible=!0:(this._state.clientServerCompatible=!1,l||(console.warn(Ti(a,o,li.semVerNewer(o,a))),this.versionWarned=!0)),this._state.status="connected",this._state.message=`Connected to ${this.name??"cluster"}`,this._state.clusterKey=n.clusterKey,this._state.nodeVersion=n.nodeVersion,this._state.clientVersion=this.clientVersion}catch(n){this._state.status="failed",this._state.error=n,this._state.message=(t=this.state.error)==null?void 0:t.message}return this.onChangeHandlers.length>0&&e!==this._state.status&&this.onChangeHandlers.forEach(n=>n(this.state)),this.state}get state(){return{...this._state}}onChange(e){this.onChangeHandlers.push(e)}startChecking(){this.interval=setInterval(()=>{this.check()},this.pollFrequency.milliseconds)}};c(ot,"ENDPOINT","/connectivity/check"),c(ot,"DEFAULT",bi),c(ot,"connectionStateZ",so);let Ft=ot;const Sf=Object.freeze(Object.defineProperty({__proto__:null,Checker:Ft,stateZ:so,statusZ:no},Symbol.toStringTag,{value:"Module"})),If=s.z.object({keys:J.array().optional(),bounds:G.z,names:Xt.array().optional()}),$f=s.z.object({}),kf="/frame/delete";class Af{constructor(e){c(this,"client");this.client=e}async delete(e){await w(this.client,kf,e,If,$f)}}class tn{constructor(e){c(this,"adapter");c(this,"retriever");c(this,"keys");this.retriever=e,this.adapter=null,this.keys=[]}static async open(e,t){const n=new tn(e);return await n.update(t),n}async update(e){const{variant:t,normalized:n}=Ee(e);if(t==="keys"){this.adapter=null,this.keys=n;return}const i=await this.retriever.retrieve(n),a=new Map;this.adapter=a,n.forEach(o=>{const l=i.find(u=>u.name===o);if(l==null)throw new Error(`Channel ${o} not found`);a.set(l.key,l.name)}),this.keys=Array.from(this.adapter.keys())}adapt(e){if(this.adapter==null)return e;const t=this.adapter;return e.map((n,i)=>{if(typeof n=="number"){const a=t.get(n);if(a==null)throw new Error(`Channel ${n} not found`);return[a,i]}return[n,i]})}}class ms{constructor(e){c(this,"adapter");c(this,"retriever");c(this,"keys");this.retriever=e,this.adapter=null,this.keys=[]}static async open(e,t){const n=new ms(e);return await n.update(t),n}async adaptObjectKeys(e){const t={};for(const[n,i]of Object.entries(e))t[await this.adaptToKey(n)]=i;return t}async update(e){const t=await Ha(this.retriever,e);this.adapter=new Map(t.map(n=>[n.name,n.key])),this.keys=t.map(n=>n.key)}async fetchChannel(e){const t=await this.retriever.retrieve(e);if(t.length===0)throw new Error(`Channel ${e} not found`);return t[0]}async adaptToKey(e){return typeof e=="number"?e:(await this.fetchChannel(e)).key}async adapt(e,t){if(typeof e=="string"||typeof e=="number"){if(t==null)throw new U(`
|
|
39
39
|
Received a single channel name or key but no series.
|
|
@@ -48,4 +48,4 @@
|
|
|
48
48
|
`);const f=new ke({data:t[u],dataType:h.dataType});o.push(h.key),l.push(f)}return new Y(o,l)}if(e instanceof Y||e instanceof Map){const o=new Y(e);if(this.adapter==null)return o;const l=o.columns.map(u=>{var f;const h=typeof u=="string"?(f=this.adapter)==null?void 0:f.get(u):u;if(h==null)throw new U(`
|
|
49
49
|
Channel ${u} was not provided in the list of channels when opening the writer
|
|
50
50
|
`);return h});return new Y(l,o.series)}const n=[],i=[],a=Object.entries(e);for(let o=0;o<a.length;o++){const[l,u]=a[o],h=await this.fetchChannel(l),f=new ke({data:u,dataType:h.dataType});n.push(h.key),i.push(f)}return new Y(n,i)}}class ws{constructor(e,t){c(this,"name");c(this,"stream");this.stream=t,this.name=e}async receive(){const[e,t]=await this.stream.receive();if(t!=null)throw t;return e}received(){return this.stream.received()}async closeAndAck(){for(this.stream.closeSend();;){const[e,t]=await this.stream.receive();if(e!=null&&console.warn(`${this.name} received unexpected response on closure.
|
|
51
|
-
Please report this error to the Synnax team. ${JSON.stringify(e)}`),t!=null){if(Re.matches(t))return;throw t}}}closeSend(){this.stream.closeSend()}send(e){const t=this.stream.send(e);if(t!=null)throw t}}const qn=new N(-1);var bs=(r=>(r[r.Open=0]="Open",r[r.Next=1]="Next",r[r.Prev=2]="Prev",r[r.SeekFirst=3]="SeekFirst",r[r.SeekLast=4]="SeekLast",r[r.SeekLE=5]="SeekLE",r[r.SeekGE=6]="SeekGE",r[r.Valid=7]="Valid",r[r.Error=8]="Error",r))(bs||{}),io=(r=>(r[r.None=0]="None",r[r.Ack=1]="Ack",r[r.Data=2]="Data",r))(io||{});const xf=s.z.object({command:s.z.nativeEnum(bs),span:N.z.optional(),bounds:G.z.optional(),stamp:$.z.optional(),keys:J.array().optional(),chunkSize:s.z.number().optional()}),Rf=s.z.object({variant:s.z.nativeEnum(io),ack:s.z.boolean(),command:s.z.nativeEnum(bs),error:Vt.optional().nullable(),frame:Ur.optional()}),Zt=class Zt{constructor(e,t){c(this,"stream");c(this,"adapter");c(this,"value");this.stream=new ws("Iterator",e),this.value=new Y,this.adapter=t}static async _open(e,t,n,i,a={}){const o=await tn.open(n,t),l=await i.stream(Zt.ENDPOINT,xf,Rf),u=new Zt(l,o);return await u.execute({command:0,keys:o.keys,bounds:new G(e),chunkSize:a.chunkSize??1e5}),u}async next(e=qn){return await this.execute({command:1,span:new N(e)})}async prev(e=qn){return await this.execute({command:2,span:new N(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 $(e)})}async seekGE(e){return await this.execute({command:6,stamp:new $(e)})}async valid(){return await this.execute({command:7})}async close(){await this.stream.closeAndAck()}[Symbol.asyncIterator](){return new Cf(this)}async execute(e){for(this.stream.send(e),this.value=new Y;;){const t=await this.stream.receive();if(t.variant===1)return t.ack;this.value.push(this.adapter.adapt(new Y(t.frame)))}}};c(Zt,"ENDPOINT","/frame/iterate");let Ar=Zt;class Cf{constructor(e){c(this,"iter");c(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 Pf=s.z.object({keys:s.z.number().array(),downsampleFactor:s.z.number()}),jf=s.z.object({frame:Ur,error:Vt.optional().nullable()}),Df="/frame/stream";class rn{constructor(e,t){c(this,"stream");c(this,"adapter");c(this,"downsampleFactor");this.stream=new ws("Streamer",e),this.adapter=t,this.downsampleFactor=1}get keys(){return this.adapter.keys}static async _open(e,t,{channels:n,downsampleFactor:i}){const a=await tn.open(e,n),o=await t.stream(Df,Pf,jf),l=new rn(o,a);o.send({keys:a.keys,downsampleFactor:i??1});const[,u]=await o.receive();if(u!=null)throw u;return l}async next(){try{return{done:!1,value:await this.read()}}catch(e){if(Re.matches(e))return{done:!0,value:void 0};throw e}}async read(){return this.adapter.adapt(new Y((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 Be extends Me.Observer{constructor(t,n){super(n);c(this,"streamer");c(this,"closePromise");this.streamer=t,this.closePromise=this.stream()}async close(){this.streamer.close(),await this.closePromise}async stream(){for await(const t of this.streamer)this.notify(t)}}var Ts=(r=>(r[r.Open=0]="Open",r[r.Write=1]="Write",r[r.Commit=2]="Commit",r[r.Error=3]="Error",r[r.SetAuthority=4]="SetAuthority",r))(Ts||{}),yt=(r=>(r[r.PersistStream=1]="PersistStream",r[r.Persist=2]="Persist",r[r.Stream=3]="Stream",r))(yt||{});const Mf=r=>{switch(r){case"persist":return 2;case"stream":return 3;case"persistStream":return 1;default:if(typeof r=="number"&&r in yt)return r;throw new Error(`invalid writer mode: ${r}`)}},Bf=new N(-1),Zf=s.z.object({start:$.z.optional(),controlSubject:dt.subjectZ.optional(),keys:J.array().optional(),authorities:dt.Authority.z.array().optional(),mode:s.z.nativeEnum(yt).optional(),errOnUnauthorized:s.z.boolean().optional(),enableAutoCommit:s.z.boolean().optional(),autoIndexPersistInterval:N.z.optional()}),Uf=s.z.object({command:s.z.nativeEnum(Ts),config:Zf.optional(),frame:Ur.optional()}),Lf=s.z.object({ack:s.z.boolean(),command:s.z.nativeEnum(Ts),error:Vt.optional().nullable()});var Ae;let ao=(Ae=class{constructor(e,t){c(this,"stream");c(this,"adapter");c(this,"errAccumulated",!1);this.stream=new ws("Writer",e),this.adapter=t}static async _open(e,t,{channels:n,start:i=$.now(),authorities:a=dt.Authority.ABSOLUTE,controlSubject:o,mode:l=1,errOnUnauthorized:u=!1,enableAutoCommit:h=!1,autoIndexPersistInterval:f=N.SECOND}){const d=await ms.open(e,n),k=await t.stream(Ae.ENDPOINT,Uf,Lf),S=new Ae(k,d);return await S.execute({command:0,config:{start:new $(i),keys:d.keys,controlSubject:o,authorities:b(a),mode:Mf(l),errOnUnauthorized:u,enableAutoCommit:h,autoIndexPersistInterval:f}}),S}async checkForAccumulatedError(){if(!this.errAccumulated&&this.stream.received())for(this.errAccumulated=!0;this.stream.received();)await this.stream.receive();return this.errAccumulated}async write(e,t){if(await this.checkForAccumulatedError())return!1;const n=await this.adapter.adapt(e,t);return this.stream.send({command:1,frame:n.toPayload()}),!0}async setAuthority(e,t){if(await this.checkForAccumulatedError())return!1;let n;if(typeof e=="number"&&t==null)n={keys:[],authorities:[e]};else{let a;typeof e=="string"||typeof e=="number"?a={[e]:t}:a=e,a=await this.adapter.adaptObjectKeys(a),n={keys:Object.keys(a).map(o=>Number(o)),authorities:Object.values(a)}}return(await this.execute({command:4,config:n})).ack}async commit(){return await this.checkForAccumulatedError()?!1:(await this.execute({command:2})).ack}async error(){const e=await this.execute({command:3});return e.error!=null?zr(e.error):null}async close(){await this.stream.closeAndAck()}async execute(e){for(this.stream.send(e);;){const t=await this.stream.receive();if(t.command===e.command)return t;console.warn("writer received unexpected response",t)}}get errorAccumulated(){return this.stream.received()}},c(Ae,"ENDPOINT","/frame/write"),Ae);const _f=r=>new O({type:Qn,key:r.toString()});let oo=class{constructor(e,t,n){c(this,"streamClient");c(this,"retriever");c(this,"deleter");this.streamClient=e,this.retriever=n,this.deleter=new Af(t)}async openIterator(e,t,n){return await Ar._open(e,t,this.retriever,this.streamClient,n)}async openWriter(e){return(Array.isArray(e)||typeof e!="object")&&(e={channels:e}),await ao._open(this.retriever,this.streamClient,e)}async openStreamer(e){return(Array.isArray(e)||typeof e!="object")&&(e={channels:e,downsampleFactor:1}),await rn._open(this.retriever,this.streamClient,e)}async write(e,t,n){if(n==null){const a=t,o=await this.openWriter({start:e,channels:Object.keys(a),mode:yt.Persist});try{await o.write(a),await o.commit()}finally{await o.close()}return}const i=await this.openWriter({start:e,channels:t,mode:yt.Persist,errOnUnauthorized:!0,enableAutoCommit:!0,autoIndexPersistInterval:N.MAX});try{await i.write(t,n)}finally{await i.close()}}async read(e,t){const{single:n}=Ee(t),i=await this.readFrame(e,t);return n?i.get(t):i}async readFrame(e,t){const n=await this.openIterator(e,t),i=new Y;try{for await(const a of n)i.push(a)}finally{await n.close()}return i}async delete(e,t){const{normalized:n,variant:i}=Ee(e);return i==="keys"?await this.deleter.delete({keys:n,bounds:t}):await this.deleter.delete({names:n,bounds:t})}};const qf=Object.freeze(Object.defineProperty({__proto__:null,ALWAYS_INDEX_PERSIST_ON_AUTO_COMMIT:Bf,AUTO_SPAN:qn,Client:oo,Frame:Y,Iterator:Ar,ONTOLOGY_TYPE:Qn,ObservableStreamer:Be,Streamer:rn,Writer:ao,WriterMode:yt,frameZ:Ur,ontologyID:_f,seriesFromPayload:va,seriesToPayload:Oa},Symbol.toStringTag,{value:"Module"})),Yf=dt.Authority,Wf=dt.stateZ(s.z.number()),Ff=r=>{var e,t;return r.to==null?`${(e=r.from)==null?void 0:e.resource} - ${(t=r.from)==null?void 0:t.subject.name} -> released`:r.from==null?`${r.to.resource} - released -> ${r.to.subject.name} (${r.to.authority.toString()})`:`${r.to.resource} - ${r.from.subject.name} -> ${r.to.subject.name} (${r.to.authority.toString()})`};class co extends Be{constructor(t){super(t,n=>{const i=this.codec.decode(n.series[0].buffer);return this.merge(i),[i.transfers,!0]});c(this,"states");c(this,"codec");this.states=new Map,this.codec=new Jt.JSONCodec}subjects(){const t=new Map;return this.states.forEach(n=>t.set(n.subject.key,n.subject)),Array.from(t.values())}merge(t){t.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 Gf="sy_node_1_control";let lo=class{constructor(e){c(this,"framer");this.framer=e}async openStateTracker(){const e=await this.framer.openStreamer(Gf);return new co(e)}};const Vf=Object.freeze(Object.defineProperty({__proto__:null,Authority:Yf,Client:lo,StateTracker:co,stateZ:Wf,transferString:Ff},Symbol.toStringTag,{value:"Module"}));let uo=class{constructor(e,t,n){c(this,"tasks");c(this,"racks");c(this,"devices");this.tasks=e,this.racks=t,this.devices=n}};const Jf=Object.freeze(Object.defineProperty({__proto__:null,Client:uo},Symbol.toStringTag,{value:"Module"})),Le=async(r,e,t,n)=>{const i=await r.openStreamer([e,t]),a=o=>{const l=[];return t!=null&&l.push(...o.get(t).series.flatMap(u=>n("delete",u))),e!=null&&l.push(...o.get(e).series.flatMap(u=>n("set",u))),[l,l.length>0]};return new Be(i,a)},Kf=Object.freeze(Object.defineProperty({__proto__:null,openObservable:Le},Symbol.toStringTag,{value:"Module"})),Hf="sy_device_set",Xf="sy_device_delete",gn="/hardware/device/retrieve",Qf="/hardware/device/create",ey="/hardware/device/delete",ty=s.z.object({devices:za.array()}),ry=s.z.object({devices:er.array()}),ny=s.z.object({keys:qr.array()}),sy=s.z.object({}),mn=s.z.object({search:s.z.string().optional(),limit:s.z.number().optional(),offset:s.z.number().optional(),keys:qr.array().optional(),names:s.z.string().array().optional(),makes:s.z.string().array().optional()}),wn=s.z.object({devices:V(er)});let ho=class{constructor(e,t){c(this,"type",Yr);c(this,"client");c(this,"frameClient");this.client=e,this.frameClient=t}async retrieve(e,t){const n=!Array.isArray(e),i=await w(this.client,gn,{keys:b(e),...t},mn,wn);return en("Device",e,i.devices,n),n?i.devices[0]:i.devices}async search(e,t){return(await w(this.client,gn,{search:e,...t},mn,wn)).devices}async page(e,t,n){return(await w(this.client,gn,{offset:e,limit:t,...n},mn,wn)).devices}async create(e){const t=!Array.isArray(e),n=await w(this.client,Qf,{devices:b(e)},ty,ry);return t?n.devices[0]:n.devices}async delete(e){await w(this.client,ey,{keys:b(e)},ny,sy)}async openDeviceTracker(){return await Le(this.frameClient,Hf,Xf,iy)}newSearcherWithOptions(e){return{type:this.type,search:async t=>await this.search(t,e),retrieve:async t=>await this.retrieve(t,e),page:async(t,n)=>await this.page(t,n,e)}}};const iy=(r,e)=>r==="delete"?e.toStrings().map(t=>({variant:r,key:t,value:void 0})):e.parseJSON(er).map(t=>({variant:r,key:t.key,value:t})),ay=r=>new O({type:Yr,key:r}),oy=Object.freeze(Object.defineProperty({__proto__:null,Client:ho,ONTOLOGY_TYPE:Yr,deviceZ:er,keyZ:qr,newZ:za,ontologyID:ay},Symbol.toStringTag,{value:"Module"})),bn="/hardware/rack/retrieve",cy="/hardware/rack/create",ly="/hardware/rack/delete",Tn=s.z.object({keys:mt.array().optional(),names:s.z.string().array().optional(),search:s.z.string().optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),vn=s.z.object({racks:V(Lr)}),uy=s.z.object({racks:Na.array()}),hy=s.z.object({racks:Lr.array()}),dy=s.z.object({keys:mt.array()}),fy=s.z.object({});let fo=class{constructor(e,t){c(this,"type",_r);c(this,"client");c(this,"tasks");this.client=e,this.tasks=t}async delete(e){await w(this.client,ly,{keys:b(e)},dy,fy)}async create(e){const t=!Array.isArray(e),n=await w(this.client,cy,{racks:b(e)},uy,hy),i=this.sugar(n.racks);return t?i[0]:i}async search(e){const t=await w(this.client,bn,{search:e},Tn,vn);return this.sugar(t.racks)}async page(e,t){const n=await w(this.client,bn,{offset:e,limit:t},Tn,vn);return this.sugar(n.racks)}async retrieve(e){const{variant:t,normalized:n,single:i}=Qr(e,{string:"names",number:"keys"}),a=await w(this.client,bn,{[t]:n},Tn,vn),o=this.sugar(a.racks);return en("Rack",e,o,i),i?o[0]:o}sugar(e){return e.map(({key:t,name:n})=>new yo(t,n,this.tasks))}};class yo{constructor(e,t,n){c(this,"key");c(this,"name");c(this,"tasks");this.key=e,this.name=t,this.tasks=n}async listTasks(){return await this.tasks.retrieve(this.key)}async retrieveTaskByName(e){return await this.tasks.retrieveByName(e,this.key)}async retrieveTaskByType(e){return await this.tasks.retrieveByType(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 yy=r=>new O({type:_r,key:r.toString()}),py=Object.freeze(Object.defineProperty({__proto__:null,Client:fo,ONTOLOGY_TYPE:_r,Rack:yo,keyZ:mt,newZ:Na,ontologyID:yy,rackZ:Lr},Symbol.toStringTag,{value:"Module"})),Bt="sy_task_state",Fe="sy_task_cmd",gy="sy_task_set",my="sy_task_delete",Ye=new Error("Task not created"),po=async(r,e)=>{const t=await e.retrieveParents(r);return t.length===0?null:t[0]};class go{constructor(e,t,n,i,a=!1,o=!1,l,u=null,h=null,f=null){c(this,"key");c(this,"name");c(this,"internal");c(this,"type");c(this,"config");c(this,"snapshot");c(this,"state");c(this,"frameClient");c(this,"ontologyClient");c(this,"rangeClient");this.key=e,this.name=t,this.type=n,this.config=i,this.internal=a,this.snapshot=o,l!==null&&(this.state=l),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 wo(this.key)}async executeCommand(e,t){if(this.frameClient==null)throw Ye;const n=await this.frameClient.openWriter(Fe),i=Pu.create();return await n.write(Fe,[{task:this.key,type:e,key:i,args:t}]),await n.close(),i}async executeCommandSync(e,t,n){if(this.frameClient==null)throw Ye;const i=await this.frameClient.openStreamer(Bt),a=await this.executeCommand(e,t);let o;const l=new Promise(u=>setTimeout(()=>u(!1),new N(n).milliseconds));for(;;){const u=await Promise.any([i.read(),l]);if(u===!1)throw new Error("Command timed out");const h=qt.safeParse(u.at(-1).sy_task_state);if(h.success){if(o=h.data,o.key===a)break}else throw h.error}return i.close(),o}async openStateObserver(){if(this.frameClient==null)throw Ye;return new Be(await this.frameClient.openStreamer(Bt),e=>{const t=e.get(Bt);if(t.length===0)return[null,!1];const n=qt.safeParse(t.at(-1));if(!n.success)return console.error(n.error),[null,!1];const i=n.data;return i.task!==this.key?[null,!1]:[i,!0]})}async openCommandObserver(){if(this.frameClient==null)throw Ye;return new Be(await this.frameClient.openStreamer(Fe),e=>{const t=e.get(Fe);if(t.length===0)return[null,!1];const n=es.safeParse(t.at(-1));if(!n.success)return console.error(n.error),[null,!1];const i=n.data;return i.task!==this.key?[null,!1]:[i,!0]})}async snapshottedTo(){if(this.ontologyClient==null||this.rangeClient==null)throw Ye;return this.snapshot?await po(this.key,this.ontologyClient):null}}const wy=s.z.object({rack:mt.optional(),keys:je.array().optional(),names:s.z.string().array().optional(),types:s.z.string().array().optional(),includeState:s.z.boolean().optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),by=s.z.object({tasks:V(tr)}),Ty="/hardware/task/retrieve",vy="/hardware/task/create",Oy="/hardware/task/delete",Ny="/hardware/task/copy",Ey=s.z.object({tasks:Ia.array()}),zy=s.z.object({tasks:tr.array()}),Sy=s.z.object({keys:je.array()}),Iy=s.z.object({}),$y=s.z.object({key:je,name:s.z.string(),snapshot:s.z.boolean()}),ky=s.z.object({task:tr});let mo=class{constructor(e,t,n,i){c(this,"type",Wr);c(this,"client");c(this,"frameClient");c(this,"ontologyClient");c(this,"rangeClient");this.client=e,this.frameClient=t,this.ontologyClient=n,this.rangeClient=i}async create(e){const t=!Array.isArray(e),n=await w(this.client,vy,{tasks:b(e)},Ey,zy),i=this.sugar(n.tasks);return t?i[0]:i}async delete(e){await w(this.client,Oy,{keys:b(e)},Sy,Iy)}async search(e){return await this.execRetrieve({keys:[e]})}async page(e,t){return await this.execRetrieve({offset:e,limit:t})}async list(e={}){return this.sugar(await this.execRetrieve(e))}async retrieve(e,t){const{single:n,normalized:i,variant:a}=Qr(e,{number:"rack",string:"keys"},{convertNumericStrings:!1}),o={...t};a==="rack"?o.rack=e:o.keys=i;const l=await this.execRetrieve(o),u=this.sugar(l);return n&&a!=="rack"?u[0]:u}async copy(e,t,n){const i=await w(this.client,Ny,{key:e,name:t,snapshot:n},$y,ky);return this.sugar([i.task])[0]}async retrieveByName(e,t){const n=await this.execRetrieve({names:[e],rack:t});return en("Task",e,n,!0),this.sugar(n)[0]}async retrieveByType(e,t){const n=await this.execRetrieve({types:[e],rack:t});return this.sugar(n)}async retrieveSnapshottedTo(e){if(this.ontologyClient==null)throw Ye;return await po(e,this.ontologyClient)}async execRetrieve(e){return(await w(this.client,Ty,e,wy,by)).tasks}sugar(e){const t=!Array.isArray(e),n=b(e).map(({key:i,name:a,type:o,config:l,state:u,internal:h,snapshot:f})=>new go(i,a,o,l,h,f,u,this.frameClient,this.ontologyClient,this.rangeClient));return t?n[0]:n}async openTracker(){return await Le(this.frameClient,gy,my,(e,t)=>Array.from(t).map(n=>({variant:e,key:n.toString(),value:n.toString()})))}async openStateObserver(){return new Be(await this.frameClient.openStreamer(Bt),e=>{const t=e.get(Bt);if(t.length===0)return[null,!1];const n=qt.safeParse(t.at(-1));return n.success?[n.data,!0]:(console.error(n.error),[null,!1])})}async openCommandObserver(){return new Be(await this.frameClient.openStreamer(Fe),e=>{const t=e.get(Fe);if(t.length===0)return[null,!1];const n=es.safeParse(t.at(-1));return n.success?[n.data,!0]:(console.error(n.error),[null,!1])})}};const wo=r=>new O({type:Wr,key:r}),Ay=Object.freeze(Object.defineProperty({__proto__:null,Client:mo,ONTOLOGY_TYPE:Wr,Task:go,commandZ:es,getRackKey:Jh,keyZ:je,newZ:Ia,ontologyID:wo,stateZ:qt,statusZ:Sa,taskZ:tr},Symbol.toStringTag,{value:"Module"})),xy=s.z.object({keys:wt.array().optional(),for:re.optional(),search:s.z.string().optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),Ry=s.z.object({labels:V(rr)}),Cr=class Cr{constructor(e){c(this,"client");this.client=e}async retrieve(e){return await this.execute({keys:b(e)})}async retrieveFor(e){return await this.execute({for:e})}async search(e){return await this.execute({search:e})}async page(e,t){return await this.execute({offset:e,limit:t})}async execute(e){const[t,n]=await this.client.send(Cr.ENDPOINT,e,xy,Ry);if(n!=null)throw n;return t.labels}};c(Cr,"ENDPOINT","/label/retrieve");let xr=Cr;const bo=rr.extend({key:wt.optional()}),Cy=s.z.object({labels:bo.array()}),Py=s.z.object({labels:rr.array()}),jy=s.z.object({keys:wt.array()}),To=s.z.object({id:re,labels:wt.array(),replace:s.z.boolean().optional()}),Dy=To.omit({replace:!0}),On=s.z.object({}),My="/label/create",By="/label/delete",Zy="/label/set",Uy="/label/remove";let vo=class{constructor(e){c(this,"client");this.client=e}async create(e){return(await w(this.client,My,{labels:b(e)},Cy,Py)).labels}async delete(e){await w(this.client,By,{keys:b(e)},jy,On)}async set(e,t,{replace:n}={}){await w(this.client,Zy,{id:e,labels:t,replace:n},To,On)}async remove(e,t){await w(this.client,Uy,{id:e,labels:t},Dy,On)}};const Ly="sy_label_set",_y="sy_label_delete";let Oo=class{constructor(e,t,n){c(this,"type","label");c(this,"retriever");c(this,"writer");c(this,"frameClient");c(this,"ontology");this.writer=new vo(e),this.retriever=new xr(e),this.frameClient=t,this.ontology=n}async search(e){return await this.retriever.search(e)}async retrieve(e){const t=Array.isArray(e),n=await this.retriever.retrieve(e);return t?n:n[0]}async retrieveFor(e){return await this.retriever.retrieveFor(new O(e))}async label(e,t,n={}){await this.writer.set(new O(e),t,n)}async removeLabels(e,t){await this.writer.remove(new O(e),t)}async page(e,t){return await this.retriever.page(e,t)}async create(e){const t=Array.isArray(e),n=await this.writer.create(e);return t?n:n[0]}async delete(e){await this.writer.delete(e)}async openChangeTracker(){return await Le(this.frameClient,Ly,_y,qy)}async trackLabelsOf(e){const t=new Me.Observer,n=(await this.retrieveFor(e)).map(a=>({id:No(a.key),key:a.key,name:a.name,data:a}));return(await this.ontology.openDependentTracker({target:new O(e),dependents:n,relationshipType:"labeled_by"})).onChange(a=>t.notify(a.map(o=>{var l,u;return{key:o.id.key,color:(l=o.data)==null?void 0:l.color,name:(u=o.data)==null?void 0:u.name}}))),t}};const qy=(r,e)=>r==="delete"?e.toUUIDs().map(t=>({variant:r,key:t})):e.parseJSON(rr).map(t=>({variant:r,key:t.key,value:t})),No=r=>new O({type:ts,key:r}),Yy=Object.freeze(Object.defineProperty({__proto__:null,Client:Oo,ONTOLOGY_TYPE:ts,Retriever:xr,Writer:vo,keyZ:wt,labelZ:rr,newZ:bo,ontologyID:No},Symbol.toStringTag,{value:"Module"})),Wy="sy_range_alias_set",Fy="sy_range_alias_delete",Gy=s.z.object({range:ne,aliases:s.z.string().array()}),Vy=s.z.object({aliases:s.z.record(s.z.string(),J)}),Jy=s.z.object({range:ne,aliases:s.z.record(J.or(s.z.string()),s.z.string())}),Ky=s.z.unknown(),Hy=s.z.object({range:ne,channels:J.array()}),Xy=s.z.unknown(),Qy=s.z.object({range:ne}),ep=s.z.object({aliases:s.z.record(s.z.string(),s.z.string())}),fe=class fe{constructor(e,t,n){c(this,"frameClient");c(this,"cache",new Map);c(this,"client");c(this,"rangeKey");this.rangeKey=e,this.cache=new Map,this.client=n,this.frameClient=t}async resolve(e){const t=[],n=typeof e=="string",i={};if(n){const o=this.cache.get(e);if(o!=null)return o;t.push(e)}else e.forEach(o=>{const l=this.cache.get(o);l!=null?i[o]=l:t.push(o)});if(t.length===0)return i;const a=await w(this.client,fe.RESOLVE_ENDPOINT,{range:this.rangeKey,aliases:t},Gy,Vy);return Object.entries(a.aliases).forEach(([o,l])=>this.cache.set(o,l)),n?a.aliases[t[0]]:{...i,...a.aliases}}async set(e){await w(this.client,fe.SET_ENDPOINT,{range:this.rangeKey,aliases:e},Jy,Ky)}async list(){return(await w(this.client,fe.LIST_ENDPOINT,{range:this.rangeKey},Qy,ep)).aliases}async delete(e){await w(this.client,fe.DELETE_ENDPOINT,{range:this.rangeKey,channels:e},Hy,Xy)}async openChangeTracker(){return await Le(this.frameClient,Wy,Fy,np(this.rangeKey))}};c(fe,"SET_ENDPOINT","/range/alias/set"),c(fe,"RESOLVE_ENDPOINT","/range/alias/resolve"),c(fe,"LIST_ENDPOINT","/range/alias/list"),c(fe,"DELETE_ENDPOINT","/range/alias/delete");let Yn=fe;const tp=s.z.object({range:ne,channel:J,alias:s.z.string()}),rp="---",np=r=>(e,t)=>e==="delete"?t.toStrings().filter(n=>n.split(rp)[0]===r).map(n=>({variant:e,key:n,value:void 0})):t.parseJSON(tp).map(n=>({variant:e,key:n.alias,value:n})),vs=s.z.object({range:ne,key:s.z.string(),value:s.z.string()}),sp=s.z.object({range:ne,keys:s.z.string().array()}),ip=s.z.object({pairs:V(vs)}),ap=s.z.object({range:ne,pairs:vs.array()}),op=s.z.object({range:ne,keys:s.z.string().array()}),$e=class $e{constructor(e,t,n){c(this,"rangeKey");c(this,"client");c(this,"frameClient");this.rangeKey=e,this.client=t,this.frameClient=n}async get(e){const t=await w(this.client,$e.GET_ENDPOINT,{range:this.rangeKey,keys:b(e)},sp,ip);return typeof e=="string"?t.pairs[0].value:Object.fromEntries(t.pairs.map(n=>[n.key,n.value]))}async list(){return this.get([])}async set(e,t=""){let n;Jn(e)?n=Object.entries(e).map(([i,a])=>({range:this.rangeKey,key:i,value:a})):n=[{range:this.rangeKey,key:e,value:t}],await w(this.client,$e.SET_ENDPOINT,{range:this.rangeKey,pairs:n},ap,s.z.unknown())}async delete(e){await w(this.client,$e.DELETE_ENDPOINT,{range:this.rangeKey,keys:b(e)},op,s.z.unknown())}async openTracker(){return await Le(this.frameClient,"sy_range_kv_set","sy_range_kv_delete",(e,t)=>e==="delete"?t.toStrings().map(n=>{const[i,a]=n.split("<--->",2);return{variant:e,key:n,value:{range:i,key:a,value:""}}}):t.parseJSON(vs).map(n=>({variant:e,key:`${n.range}${n.key}`,value:n})))}};c($e,"GET_ENDPOINT","/range/kv/get"),c($e,"SET_ENDPOINT","/range/kv/set"),c($e,"DELETE_ENDPOINT","/range/kv/delete");let Gt=$e;class Eo{constructor(e,t=G.ZERO,n,i,a,o,l,u,h,f,d){c(this,"key");c(this,"name");c(this,"kv");c(this,"timeRange");c(this,"color");c(this,"channels");c(this,"aliaser");c(this,"frameClient");c(this,"labelClient");c(this,"ontologyClient");c(this,"rangeClient");this.key=n,this.name=e,this.timeRange=t,this.frameClient=a,this.color=i,this.kv=o,this.aliaser=l,this.channels=u,this.labelClient=h,this.ontologyClient=f,this.rangeClient=d}get ontologyID(){return Ie(this.key)}get payload(){return{key:this.key,name:this.name,timeRange:this.timeRange,color:this.color}}async setAlias(e,t){const n=await this.channels.retrieve(e);if(n.length===0)throw new ie(`Channel ${e} does not exist`);await this.aliaser.set({[n[0].key]:t})}async deleteAlias(...e){await this.aliaser.delete(e)}async listAliases(){return await this.aliaser.list()}async resolveAlias(e){return await this.aliaser.resolve(e)}async 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(t=>t.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(Ie(this.key))}async addLabel(...e){await this.labelClient.label(Ie(this.key),e)}async removeLabel(...e){await this.labelClient.removeLabels(Ie(this.key),e)}async openChildRangeTracker(){const e=new Me.Observer,t=(await this.retrieveChildren()).map(i=>{const a=Ie(i.key);return{id:a,key:a.toString(),name:i.name,data:i.payload}}),n=await this.ontologyClient.openDependentTracker({target:this.ontologyID,dependents:t,resourceType:"range"});return n.onChange(i=>e.notify(this.rangeClient.resourcesToRanges(i))),e.setCloser(async()=>await n.close()),e}async openParentRangeTracker(){const e=new Me.Observer,t=await this.retrieveParent();if(t==null)return null;const n=Ie(t.key),i={id:n,key:n.toString(),name:t.name,data:t.payload},a=await this.ontologyClient.openDependentTracker({target:this.ontologyID,dependents:[i],relationshipDirection:"to"});return a.onChange(o=>{const l=this.rangeClient.resourcesToRanges(o);if(l.length===0)return;const u=l[0];e.notify(u)}),e.setCloser(async()=>await a.close()),e}}const cp=(r,e)=>Du(r.timeRange,e.timeRange),lp=s.z.object({keys:ne.array().optional(),names:s.z.array(s.z.string()).optional(),term:s.z.string().optional(),overlapsWith:G.z.optional(),limit:s.z.number().int().optional(),offset:s.z.number().int().optional()}),up="/range/retrieve",hp=s.z.object({ranges:V(nr)});let zo=class{constructor(e,t,n,i,a,o){c(this,"type","range");c(this,"frameClient");c(this,"writer");c(this,"unaryClient");c(this,"channels");c(this,"labelClient");c(this,"ontologyClient");this.frameClient=e,this.writer=t,this.unaryClient=n,this.channels=i,this.labelClient=a,this.ontologyClient=o}async create(e,t){const n=!Array.isArray(e),i=this.sugarMany(await this.writer.create(b(e),t));return n?i[0]:i}async rename(e,t){await this.writer.rename(e,t)}async delete(e){await this.writer.delete(b(e))}async search(e){return this.sugarMany(await this.execRetrieve({term:e}))}async page(e,t){return this.sugarMany(await this.execRetrieve({offset:e,limit:t}))}async retrieve(e){if(typeof e=="object"&&"start"in e)return await this.execRetrieve({overlapsWith:new G(e)});const{single:t,actual:n,variant:i,normalized:a,empty:o}=ka(e);if(o)return[];const l=await this.execRetrieve({[i]:a});if(!t)return l;if(l.length===0)throw new Oe(`range matching ${n} not found`);if(l.length>1)throw new Ne(`multiple ranges matching ${n} found`);return l[0]}getKV(e){return new Gt(e,this.unaryClient,this.frameClient)}async execRetrieve(e){const{ranges:t}=await w(this.unaryClient,up,e,lp,hp);return this.sugarMany(t)}async retrieveParent(e){const t=await this.ontologyClient.retrieveParents(Ie(e));if(t.length===0)return null;const n=t[0];return n.id.type!=="range"?null:await this.retrieve(n.id.key)}sugarOne(e){return new Eo(e.name,e.timeRange,e.key,e.color,this.frameClient,new Gt(e.key,this.unaryClient,this.frameClient),new Yn(e.key,this.frameClient,this.unaryClient),this.channels,this.labelClient,this.ontologyClient,this)}sugarMany(e){return e.map(t=>this.sugarOne(t))}async openTracker(){return await Le(this.frameClient,"sy_range_set","sy_range_delete",(e,t)=>e==="delete"?t.toStrings().map(i=>({variant:e,key:i,value:void 0})):this.sugarMany(t.parseJSON(nr)).map(i=>({variant:e,key:i.key,value:i})))}resourcesToRanges(e){return e.map(t=>this.resourceToRange(t))}resourceToRange(e){var t,n,i;return this.sugarOne({key:e.id.key,name:(t=e.data)==null?void 0:t.name,timeRange:new G((n=e.data)==null?void 0:n.timeRange),color:(i=e.data)==null?void 0:i.color})}};const Ie=r=>new O({type:ns,key:r}),dp=r=>new O({type:ss,key:r}),fp=s.z.object({ranges:nr.array()}),yp=s.z.object({parent:re.optional(),ranges:$a.array()}),pp=s.z.object({keys:ne.array()}),gp=s.z.object({}),mp=s.z.object({key:ne,name:rs}),wp=s.z.object({}),bp="/range/create",Tp="/range/delete",vp="/range/rename";class So{constructor(e){c(this,"client");this.client=e}async rename(e,t){await w(this.client,vp,{key:e,name:t},mp,wp)}async create(e,t){return(await w(this.client,bp,{ranges:e,...t},yp,fp)).ranges}async delete(e){await w(this.client,Tp,{keys:e},pp,gp)}}const Op=Object.freeze(Object.defineProperty({__proto__:null,ALIAS_ONTOLOGY_TYPE:ss,Client:zo,KV:Gt,ONTOLOGY_TYPE:ns,Range:Eo,Writer:So,aliasOntologyID:dp,analyzeParams:ka,keyZ:ne,nameZ:rs,newZ:$a,ontologyID:Ie,payloadZ:nr,sort:cp},Symbol.toStringTag,{value:"Module"})),Np="/api/v1/";class Ep{constructor(e,t={},n=!1){c(this,"url");c(this,"unary");c(this,"stream");c(this,"secure");this.secure=n,this.url=e.child(Np);const i=new Jt.JSONCodec;this.unary=El(new Nl(this.url,i,this.secure),t),this.stream=new Cl(this.url,i,this.secure)}use(...e){this.unary.use(...e),this.stream.use(...e)}}const zp="/workspace/lineplot/retrieve",Sp="/workspace/lineplot/create",Ip="/workspace/lineplot/rename",$p="/workspace/lineplot/set-data",kp="/workspace/lineplot/delete",Ap=s.z.object({keys:bt.array()}),xp=s.z.object({workspace:pe,linePlots:xa.array()}),Rp=s.z.object({key:bt,name:s.z.string()}),Cp=s.z.object({key:bt,data:s.z.string()}),Pp=s.z.object({keys:bt.array()}),jp=s.z.object({linePlots:V(Fr)}),Dp=s.z.object({linePlots:Fr.array()}),Nn=s.z.object({});let Io=class{constructor(e){c(this,"client");this.client=e}async create(e,t){const n=Array.isArray(t),i=await w(this.client,Sp,{workspace:e,linePlots:b(t)},xp,Dp);return n?i.linePlots:i.linePlots[0]}async rename(e,t){await w(this.client,Ip,{key:e,name:t},Rp,Nn)}async setData(e,t){await w(this.client,$p,{key:e,data:JSON.stringify(t)},Cp,Nn)}async retrieve(e){const t=Array.isArray(e),n=await w(this.client,zp,{keys:b(e)},Ap,jp);return t?n.linePlots:n.linePlots[0]}async delete(e){await w(this.client,kp,{keys:b(e)},Pp,Nn)}};const Mp=r=>new O({type:as,key:r}),Bp=Object.freeze(Object.defineProperty({__proto__:null,Client:Io,ONTOLOGY_TYPE:as,keyZ:bt,linePlotZ:Fr,newZ:xa,ontologyID:Mp},Symbol.toStringTag,{value:"Module"})),Zp="/workspace/log/retrieve",Up="/workspace/log/create",Lp="/workspace/log/rename",_p="/workspace/log/set-data",qp="/workspace/log/delete",Yp=s.z.object({keys:Tt.array()}),Wp=s.z.object({workspace:pe,logs:Ra.array()}),Fp=s.z.object({key:Tt,name:s.z.string()}),Gp=s.z.object({key:Tt,data:s.z.string()}),Vp=s.z.object({keys:Tt.array()}),Jp=s.z.object({logs:Gr.array()}),Kp=s.z.object({logs:Gr.array()}),En=s.z.object({});let $o=class{constructor(e){c(this,"client");this.client=e}async create(e,t){const n=Array.isArray(t),i=await w(this.client,Up,{workspace:e,logs:b(t)},Wp,Kp);return n?i.logs:i.logs[0]}async rename(e,t){await w(this.client,Lp,{key:e,name:t},Fp,En)}async setData(e,t){await w(this.client,_p,{key:e,data:JSON.stringify(t)},Gp,En)}async retrieve(e){const t=Array.isArray(e),n=await w(this.client,Zp,{keys:b(e)},Yp,Jp);return t?n.logs:n.logs[0]}async delete(e){await w(this.client,qp,{keys:b(e)},Vp,En)}};const Hp=r=>new O({type:os,key:r}),Xp=Object.freeze(Object.defineProperty({__proto__:null,Client:$o,ONTOLOGY_TYPE:os,keyZ:Tt,logZ:Gr,newZ:Ra,ontologyID:Hp},Symbol.toStringTag,{value:"Module"})),Qp="/workspace/schematic/retrieve",eg="/workspace/schematic/create",tg="/workspace/schematic/rename",rg="/workspace/schematic/set-data",ng="/workspace/schematic/delete",sg="/workspace/schematic/copy",ig=s.z.object({keys:Ue.array()}),ag=s.z.object({workspace:pe,schematics:ja.array()}),og=s.z.object({key:Ue,name:s.z.string()}),cg=s.z.object({key:Ue,data:s.z.string()}),lg=s.z.object({keys:Ue.array()}),ug=s.z.object({key:Ue,name:s.z.string(),snapshot:s.z.boolean()}),hg=s.z.object({schematics:V(cs)}),dg=s.z.object({schematics:cs.array()}),fg=s.z.object({schematic:Kr}),zn=s.z.object({});let ko=class{constructor(e){c(this,"client");this.client=e}async create(e,t){const n=Array.isArray(t),i=await w(this.client,eg,{workspace:e,schematics:b(t)},ag,dg);return n?i.schematics:i.schematics[0]}async rename(e,t){await w(this.client,tg,{key:e,name:t},og,zn)}async setData(e,t){await w(this.client,rg,{key:e,data:JSON.stringify(t)},cg,zn)}async retrieve(e){const t=Array.isArray(e),n=await w(this.client,Qp,{keys:b(e)},ig,hg);return t?n.schematics:n.schematics[0]}async delete(e){await w(this.client,ng,{keys:b(e)},lg,zn)}async copy(e,t,n){return(await w(this.client,sg,{key:e,name:t,snapshot:n},ug,fg)).schematic}};const yg=r=>new O({type:ls,key:r}),pg=Object.freeze(Object.defineProperty({__proto__:null,Client:ko,ONTOLOGY_TYPE:ls,keyZ:Ue,newZ:ja,ontologyID:yg,remoteZ:cs,schematicZ:Kr},Symbol.toStringTag,{value:"Module"})),gg="/workspace/table/retrieve",mg="/workspace/table/create",wg="/workspace/table/rename",bg="/workspace/table/set-data",Tg="/workspace/table/delete",vg=s.z.object({keys:vt.array()}),Og=s.z.object({workspace:pe,tables:Da.array()}),Ng=s.z.object({key:vt,name:s.z.string()}),Eg=s.z.object({key:vt,data:s.z.string()}),zg=s.z.object({keys:vt.array()}),Sg=s.z.object({tables:hs.array()}),Ig=s.z.object({tables:hs.array()}),Sn=s.z.object({});let Ao=class{constructor(e){c(this,"client");this.client=e}async create(e,t){const n=Array.isArray(t),i=await w(this.client,mg,{workspace:e,tables:b(t)},Og,Ig);return n?i.tables:i.tables[0]}async rename(e,t){await w(this.client,wg,{key:e,name:t},Ng,Sn)}async setData(e,t){await w(this.client,bg,{key:e,data:JSON.stringify(t)},Eg,Sn)}async retrieve(e){const t=Array.isArray(e),n=await w(this.client,gg,{keys:b(e)},vg,Sg);return t?n.tables:n.tables[0]}async delete(e){await w(this.client,Tg,{keys:b(e)},zg,Sn)}};const $g=r=>new O({type:ds,key:r}),kg=Object.freeze(Object.defineProperty({__proto__:null,Client:Ao,ONTOLOGY_TYPE:ds,keyZ:vt,newZ:Da,ontologyID:$g,remoteZ:hs,tableZ:us},Symbol.toStringTag,{value:"Module"})),hr="/workspace/retrieve",Ag="/workspace/create",xg="/workspace/rename",Rg="/workspace/set-layout",Cg="/workspace/delete",dr=s.z.object({keys:pe.array().optional(),search:s.z.string().optional(),author:Ze.optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),Pg=s.z.object({workspaces:Ca.array()}),jg=s.z.object({key:pe,name:s.z.string()}),Dg=s.z.object({key:pe,layout:s.z.string()}),Mg=s.z.object({keys:pe.array()}),fr=s.z.object({workspaces:V(Vr)}),Bg=s.z.object({workspaces:Pa.array()}),In=s.z.object({});class xo{constructor(e){c(this,"type",Jr);c(this,"schematic");c(this,"linePlot");c(this,"log");c(this,"table");c(this,"client");this.client=e,this.schematic=new ko(e),this.linePlot=new Io(e),this.log=new $o(e),this.table=new Ao(e)}async create(e){const t=Array.isArray(e),n=await w(this.client,Ag,{workspaces:b(e)},Pg,Bg);return t?n.workspaces:n.workspaces[0]}async rename(e,t){await w(this.client,xg,{key:e,name:t},jg,In)}async setLayout(e,t){await w(this.client,Rg,{key:e,layout:JSON.stringify(t)},Dg,In)}async retrieve(e){const t=Array.isArray(e),n=await w(this.client,hr,{keys:b(e)},dr,fr);return t?n.workspaces:n.workspaces[0]}async retrieveByAuthor(e){return(await w(this.client,hr,{author:e},dr,fr)).workspaces}async search(e){return(await w(this.client,hr,{search:e},dr,fr)).workspaces}async page(e,t){return(await w(this.client,hr,{offset:e,limit:t},dr,fr)).workspaces}async delete(e){await w(this.client,Cg,{keys:b(e)},Mg,In)}}const Zg=r=>new O({type:Jr,key:r}),Ug=Object.freeze(Object.defineProperty({__proto__:null,Client:xo,ONTOLOGY_TYPE:Jr,keyZ:pe,newZ:Ca,ontologyID:Zg,remoteZ:Pa,workspaceZ:Vr},Symbol.toStringTag,{value:"Module"})),Ro=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:N.z.default(N.seconds(30)),secure:s.z.boolean().optional().default(!1),name:s.z.string().optional(),retry:Ph.breakerConfig.optional()});class Co extends oo{constructor(t){const n=Ro.parse(t),{host:i,port:a,username:o,password:l,connectivityPollFrequency:u,secure:h,retry:f}=n,d=new Ep(new ah({host:i,port:Number(a)}),f,h);d.use(Gh);let k;o!=null&&l!=null&&(k=new Ef(d.unary,{username:o,password:l}),d.use(k.middleware()));const S=new ps(new Yt(d.unary)),se=new to(d.unary,S);super(d.stream,d.unary,S);c(this,"createdAt");c(this,"props");c(this,"ranges");c(this,"channels");c(this,"auth");c(this,"user");c(this,"access");c(this,"connectivity");c(this,"ontology");c(this,"workspaces");c(this,"labels");c(this,"hardware");c(this,"control");c(this,"transport");c(this,"clientVersion","0.39.0");this.createdAt=$.now(),this.props=n,this.auth=k,this.transport=d,this.channels=new Xa(this,S,d.unary,se),this.connectivity=new Ft(d.unary,u,this.clientVersion,n.name),this.control=new lo(this),this.ontology=new Wa(d.unary,this);const L=new So(this.transport.unary);this.labels=new Oo(this.transport.unary,this,this.ontology),this.ranges=new zo(this,L,this.transport.unary,S,this.labels,this.ontology),this.access=new Va(this.transport.unary),this.user=new ro(this.transport.unary),this.workspaces=new xo(this.transport.unary);const Po=new ho(this.transport.unary,this),Os=new mo(this.transport.unary,this,this.ontology,this.ranges),jo=new fo(this.transport.unary,Os);this.hardware=new uo(Os,jo,Po)}get key(){return this.createdAt.valueOf().toString()}close(){this.connectivity.stopChecking()}}c(Co,"connectivity",Ft);const Lg=dt.Authority;exports.AuthError=ve;exports.Authority=Lg;exports.Channel=gs;exports.ContiguityError=Ln;exports.DataType=I;exports.Density=X;exports.Frame=Y;exports.MultiSeries=fa;exports.MultipleFoundError=Ne;exports.NotFoundError=Oe;exports.QueryError=ie;exports.Rate=ut;exports.RouteError=_t;exports.Series=ke;exports.Synnax=Co;exports.TimeRange=G;exports.TimeSpan=N;exports.TimeStamp=$;exports.UnexpectedError=xe;exports.ValidationError=U;exports.access=kd;exports.channel=Kd;exports.connection=Sf;exports.control=Vf;exports.device=oy;exports.framer=qf;exports.group=id;exports.hardware=Jf;exports.isCalculated=Wt;exports.label=Yy;exports.linePlot=Bp;exports.log=Xp;exports.ontology=yd;exports.policy=$d;exports.rack=py;exports.ranger=Op;exports.schematic=pg;exports.signals=Kf;exports.synnaxPropsZ=Ro;exports.table=kg;exports.task=Ay;exports.user=gf;exports.workspace=Ug;
|
|
51
|
+
Please report this error to the Synnax team. ${JSON.stringify(e)}`),t!=null){if(Re.matches(t))return;throw t}}}closeSend(){this.stream.closeSend()}send(e){const t=this.stream.send(e);if(t!=null)throw t}}const qn=new N(-1);var bs=(r=>(r[r.Open=0]="Open",r[r.Next=1]="Next",r[r.Prev=2]="Prev",r[r.SeekFirst=3]="SeekFirst",r[r.SeekLast=4]="SeekLast",r[r.SeekLE=5]="SeekLE",r[r.SeekGE=6]="SeekGE",r[r.Valid=7]="Valid",r[r.Error=8]="Error",r))(bs||{}),io=(r=>(r[r.None=0]="None",r[r.Ack=1]="Ack",r[r.Data=2]="Data",r))(io||{});const xf=s.z.object({command:s.z.nativeEnum(bs),span:N.z.optional(),bounds:G.z.optional(),stamp:$.z.optional(),keys:J.array().optional(),chunkSize:s.z.number().optional()}),Rf=s.z.object({variant:s.z.nativeEnum(io),ack:s.z.boolean(),command:s.z.nativeEnum(bs),error:Vt.optional().nullable(),frame:Ur.optional()}),Zt=class Zt{constructor(e,t){c(this,"stream");c(this,"adapter");c(this,"value");this.stream=new ws("Iterator",e),this.value=new Y,this.adapter=t}static async _open(e,t,n,i,a={}){const o=await tn.open(n,t),l=await i.stream(Zt.ENDPOINT,xf,Rf),u=new Zt(l,o);return await u.execute({command:0,keys:o.keys,bounds:new G(e),chunkSize:a.chunkSize??1e5}),u}async next(e=qn){return await this.execute({command:1,span:new N(e)})}async prev(e=qn){return await this.execute({command:2,span:new N(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 $(e)})}async seekGE(e){return await this.execute({command:6,stamp:new $(e)})}async valid(){return await this.execute({command:7})}async close(){await this.stream.closeAndAck()}[Symbol.asyncIterator](){return new Cf(this)}async execute(e){for(this.stream.send(e),this.value=new Y;;){const t=await this.stream.receive();if(t.variant===1)return t.ack;this.value.push(this.adapter.adapt(new Y(t.frame)))}}};c(Zt,"ENDPOINT","/frame/iterate");let Ar=Zt;class Cf{constructor(e){c(this,"iter");c(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 Pf=s.z.object({keys:s.z.number().array(),downsampleFactor:s.z.number()}),jf=s.z.object({frame:Ur,error:Vt.optional().nullable()}),Df="/frame/stream";class rn{constructor(e,t){c(this,"stream");c(this,"adapter");c(this,"downsampleFactor");this.stream=new ws("Streamer",e),this.adapter=t,this.downsampleFactor=1}get keys(){return this.adapter.keys}static async _open(e,t,{channels:n,downsampleFactor:i}){const a=await tn.open(e,n),o=await t.stream(Df,Pf,jf),l=new rn(o,a);o.send({keys:a.keys,downsampleFactor:i??1});const[,u]=await o.receive();if(u!=null)throw u;return l}async next(){try{return{done:!1,value:await this.read()}}catch(e){if(Re.matches(e))return{done:!0,value:void 0};throw e}}async read(){return this.adapter.adapt(new Y((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 Be extends Me.Observer{constructor(t,n){super(n);c(this,"streamer");c(this,"closePromise");this.streamer=t,this.closePromise=this.stream()}async close(){this.streamer.close(),await this.closePromise}async stream(){for await(const t of this.streamer)this.notify(t)}}var Ts=(r=>(r[r.Open=0]="Open",r[r.Write=1]="Write",r[r.Commit=2]="Commit",r[r.Error=3]="Error",r[r.SetAuthority=4]="SetAuthority",r))(Ts||{}),yt=(r=>(r[r.PersistStream=1]="PersistStream",r[r.Persist=2]="Persist",r[r.Stream=3]="Stream",r))(yt||{});const Mf=r=>{switch(r){case"persist":return 2;case"stream":return 3;case"persistStream":return 1;default:if(typeof r=="number"&&r in yt)return r;throw new Error(`invalid writer mode: ${r}`)}},Bf=new N(-1),Zf=s.z.object({start:$.z.optional(),controlSubject:dt.subjectZ.optional(),keys:J.array().optional(),authorities:dt.Authority.z.array().optional(),mode:s.z.nativeEnum(yt).optional(),errOnUnauthorized:s.z.boolean().optional(),enableAutoCommit:s.z.boolean().optional(),autoIndexPersistInterval:N.z.optional()}),Uf=s.z.object({command:s.z.nativeEnum(Ts),config:Zf.optional(),frame:Ur.optional()}),Lf=s.z.object({ack:s.z.boolean(),command:s.z.nativeEnum(Ts),error:Vt.optional().nullable()});var Ae;let ao=(Ae=class{constructor(e,t){c(this,"stream");c(this,"adapter");c(this,"errAccumulated",!1);this.stream=new ws("Writer",e),this.adapter=t}static async _open(e,t,{channels:n,start:i=$.now(),authorities:a=dt.Authority.ABSOLUTE,controlSubject:o,mode:l=1,errOnUnauthorized:u=!1,enableAutoCommit:h=!1,autoIndexPersistInterval:f=N.SECOND}){const d=await ms.open(e,n),k=await t.stream(Ae.ENDPOINT,Uf,Lf),S=new Ae(k,d);return await S.execute({command:0,config:{start:new $(i),keys:d.keys,controlSubject:o,authorities:b(a),mode:Mf(l),errOnUnauthorized:u,enableAutoCommit:h,autoIndexPersistInterval:f}}),S}async checkForAccumulatedError(){if(!this.errAccumulated&&this.stream.received())for(this.errAccumulated=!0;this.stream.received();)await this.stream.receive();return this.errAccumulated}async write(e,t){if(await this.checkForAccumulatedError())return!1;const n=await this.adapter.adapt(e,t);return this.stream.send({command:1,frame:n.toPayload()}),!0}async setAuthority(e,t){if(await this.checkForAccumulatedError())return!1;let n;if(typeof e=="number"&&t==null)n={keys:[],authorities:[e]};else{let a;typeof e=="string"||typeof e=="number"?a={[e]:t}:a=e,a=await this.adapter.adaptObjectKeys(a),n={keys:Object.keys(a).map(o=>Number(o)),authorities:Object.values(a)}}return(await this.execute({command:4,config:n})).ack}async commit(){return await this.checkForAccumulatedError()?!1:(await this.execute({command:2})).ack}async error(){const e=await this.execute({command:3});return e.error!=null?zr(e.error):null}async close(){await this.stream.closeAndAck()}async execute(e){for(this.stream.send(e);;){const t=await this.stream.receive();if(t.command===e.command)return t;console.warn("writer received unexpected response",t)}}get errorAccumulated(){return this.stream.received()}},c(Ae,"ENDPOINT","/frame/write"),Ae);const _f=r=>new O({type:Qn,key:r.toString()});let oo=class{constructor(e,t,n){c(this,"streamClient");c(this,"retriever");c(this,"deleter");this.streamClient=e,this.retriever=n,this.deleter=new Af(t)}async openIterator(e,t,n){return await Ar._open(e,t,this.retriever,this.streamClient,n)}async openWriter(e){return(Array.isArray(e)||typeof e!="object")&&(e={channels:e}),await ao._open(this.retriever,this.streamClient,e)}async openStreamer(e){return(Array.isArray(e)||typeof e!="object")&&(e={channels:e,downsampleFactor:1}),await rn._open(this.retriever,this.streamClient,e)}async write(e,t,n){if(n==null){const a=t,o=await this.openWriter({start:e,channels:Object.keys(a),mode:yt.Persist});try{await o.write(a),await o.commit()}finally{await o.close()}return}const i=await this.openWriter({start:e,channels:t,mode:yt.Persist,errOnUnauthorized:!0,enableAutoCommit:!0,autoIndexPersistInterval:N.MAX});try{await i.write(t,n)}finally{await i.close()}}async read(e,t){const{single:n}=Ee(t),i=await this.readFrame(e,t);return n?i.get(t):i}async readFrame(e,t){const n=await this.openIterator(e,t),i=new Y;try{for await(const a of n)i.push(a)}finally{await n.close()}return i}async delete(e,t){const{normalized:n,variant:i}=Ee(e);return i==="keys"?await this.deleter.delete({keys:n,bounds:t}):await this.deleter.delete({names:n,bounds:t})}};const qf=Object.freeze(Object.defineProperty({__proto__:null,ALWAYS_INDEX_PERSIST_ON_AUTO_COMMIT:Bf,AUTO_SPAN:qn,Client:oo,Frame:Y,Iterator:Ar,ONTOLOGY_TYPE:Qn,ObservableStreamer:Be,Streamer:rn,Writer:ao,WriterMode:yt,frameZ:Ur,ontologyID:_f,seriesFromPayload:va,seriesToPayload:Oa},Symbol.toStringTag,{value:"Module"})),Yf=dt.Authority,Wf=dt.stateZ(s.z.number()),Ff=r=>{var e,t;return r.to==null?`${(e=r.from)==null?void 0:e.resource} - ${(t=r.from)==null?void 0:t.subject.name} -> released`:r.from==null?`${r.to.resource} - released -> ${r.to.subject.name} (${r.to.authority.toString()})`:`${r.to.resource} - ${r.from.subject.name} -> ${r.to.subject.name} (${r.to.authority.toString()})`};class co extends Be{constructor(t){super(t,n=>{const i=this.codec.decode(n.series[0].buffer);return this.merge(i),[i.transfers,!0]});c(this,"states");c(this,"codec");this.states=new Map,this.codec=new Jt.JSONCodec}subjects(){const t=new Map;return this.states.forEach(n=>t.set(n.subject.key,n.subject)),Array.from(t.values())}merge(t){t.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 Gf="sy_node_1_control";let lo=class{constructor(e){c(this,"framer");this.framer=e}async openStateTracker(){const e=await this.framer.openStreamer(Gf);return new co(e)}};const Vf=Object.freeze(Object.defineProperty({__proto__:null,Authority:Yf,Client:lo,StateTracker:co,stateZ:Wf,transferString:Ff},Symbol.toStringTag,{value:"Module"}));let uo=class{constructor(e,t,n){c(this,"tasks");c(this,"racks");c(this,"devices");this.tasks=e,this.racks=t,this.devices=n}};const Jf=Object.freeze(Object.defineProperty({__proto__:null,Client:uo},Symbol.toStringTag,{value:"Module"})),Le=async(r,e,t,n)=>{const i=await r.openStreamer([e,t]),a=o=>{const l=[];return t!=null&&l.push(...o.get(t).series.flatMap(u=>n("delete",u))),e!=null&&l.push(...o.get(e).series.flatMap(u=>n("set",u))),[l,l.length>0]};return new Be(i,a)},Kf=Object.freeze(Object.defineProperty({__proto__:null,openObservable:Le},Symbol.toStringTag,{value:"Module"})),Hf="sy_device_set",Xf="sy_device_delete",gn="/hardware/device/retrieve",Qf="/hardware/device/create",ey="/hardware/device/delete",ty=s.z.object({devices:za.array()}),ry=s.z.object({devices:er.array()}),ny=s.z.object({keys:qr.array()}),sy=s.z.object({}),mn=s.z.object({search:s.z.string().optional(),limit:s.z.number().optional(),offset:s.z.number().optional(),keys:qr.array().optional(),names:s.z.string().array().optional(),makes:s.z.string().array().optional(),ignoreNotFound:s.z.boolean().optional()}),wn=s.z.object({devices:V(er)});let ho=class{constructor(e,t){c(this,"type",Yr);c(this,"client");c(this,"frameClient");this.client=e,this.frameClient=t}async retrieve(e,t){const n=!Array.isArray(e),i=await w(this.client,gn,{keys:b(e),...t},mn,wn);return en("Device",e,i.devices,n),n?i.devices[0]:i.devices}async search(e,t){return(await w(this.client,gn,{search:e,...t},mn,wn)).devices}async page(e,t,n){return(await w(this.client,gn,{offset:e,limit:t,...n},mn,wn)).devices}async create(e){const t=!Array.isArray(e),n=await w(this.client,Qf,{devices:b(e)},ty,ry);return t?n.devices[0]:n.devices}async delete(e){await w(this.client,ey,{keys:b(e)},ny,sy)}async openDeviceTracker(){return await Le(this.frameClient,Hf,Xf,iy)}newSearcherWithOptions(e){return{type:this.type,search:async t=>await this.search(t,e),retrieve:async t=>await this.retrieve(t,e),page:async(t,n)=>await this.page(t,n,e)}}};const iy=(r,e)=>r==="delete"?e.toStrings().map(t=>({variant:r,key:t,value:void 0})):e.parseJSON(er).map(t=>({variant:r,key:t.key,value:t})),ay=r=>new O({type:Yr,key:r}),oy=Object.freeze(Object.defineProperty({__proto__:null,Client:ho,ONTOLOGY_TYPE:Yr,deviceZ:er,keyZ:qr,newZ:za,ontologyID:ay},Symbol.toStringTag,{value:"Module"})),bn="/hardware/rack/retrieve",cy="/hardware/rack/create",ly="/hardware/rack/delete",Tn=s.z.object({keys:mt.array().optional(),names:s.z.string().array().optional(),search:s.z.string().optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),vn=s.z.object({racks:V(Lr)}),uy=s.z.object({racks:Na.array()}),hy=s.z.object({racks:Lr.array()}),dy=s.z.object({keys:mt.array()}),fy=s.z.object({});let fo=class{constructor(e,t){c(this,"type",_r);c(this,"client");c(this,"tasks");this.client=e,this.tasks=t}async delete(e){await w(this.client,ly,{keys:b(e)},dy,fy)}async create(e){const t=!Array.isArray(e),n=await w(this.client,cy,{racks:b(e)},uy,hy),i=this.sugar(n.racks);return t?i[0]:i}async search(e){const t=await w(this.client,bn,{search:e},Tn,vn);return this.sugar(t.racks)}async page(e,t){const n=await w(this.client,bn,{offset:e,limit:t},Tn,vn);return this.sugar(n.racks)}async retrieve(e){const{variant:t,normalized:n,single:i}=Qr(e,{string:"names",number:"keys"}),a=await w(this.client,bn,{[t]:n},Tn,vn),o=this.sugar(a.racks);return en("Rack",e,o,i),i?o[0]:o}sugar(e){return e.map(({key:t,name:n})=>new yo(t,n,this.tasks))}};class yo{constructor(e,t,n){c(this,"key");c(this,"name");c(this,"tasks");this.key=e,this.name=t,this.tasks=n}async listTasks(){return await this.tasks.retrieve(this.key)}async retrieveTaskByName(e){return await this.tasks.retrieveByName(e,this.key)}async retrieveTaskByType(e){return await this.tasks.retrieveByType(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 yy=r=>new O({type:_r,key:r.toString()}),py=Object.freeze(Object.defineProperty({__proto__:null,Client:fo,ONTOLOGY_TYPE:_r,Rack:yo,keyZ:mt,newZ:Na,ontologyID:yy,rackZ:Lr},Symbol.toStringTag,{value:"Module"})),Bt="sy_task_state",Fe="sy_task_cmd",gy="sy_task_set",my="sy_task_delete",Ye=new Error("Task not created"),po=async(r,e)=>{const t=await e.retrieveParents(r);return t.length===0?null:t[0]};class go{constructor(e,t,n,i,a=!1,o=!1,l,u=null,h=null,f=null){c(this,"key");c(this,"name");c(this,"internal");c(this,"type");c(this,"config");c(this,"snapshot");c(this,"state");c(this,"frameClient");c(this,"ontologyClient");c(this,"rangeClient");this.key=e,this.name=t,this.type=n,this.config=i,this.internal=a,this.snapshot=o,l!==null&&(this.state=l),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 wo(this.key)}async executeCommand(e,t){if(this.frameClient==null)throw Ye;const n=await this.frameClient.openWriter(Fe),i=Pu.create();return await n.write(Fe,[{task:this.key,type:e,key:i,args:t}]),await n.close(),i}async executeCommandSync(e,t,n){if(this.frameClient==null)throw Ye;const i=await this.frameClient.openStreamer(Bt),a=await this.executeCommand(e,t);let o;const l=new Promise(u=>setTimeout(()=>u(!1),new N(n).milliseconds));for(;;){const u=await Promise.any([i.read(),l]);if(u===!1)throw new Error("Command timed out");const h=qt.safeParse(u.at(-1).sy_task_state);if(h.success){if(o=h.data,o.key===a)break}else throw h.error}return i.close(),o}async openStateObserver(){if(this.frameClient==null)throw Ye;return new Be(await this.frameClient.openStreamer(Bt),e=>{const t=e.get(Bt);if(t.length===0)return[null,!1];const n=qt.safeParse(t.at(-1));if(!n.success)return console.error(n.error),[null,!1];const i=n.data;return i.task!==this.key?[null,!1]:[i,!0]})}async openCommandObserver(){if(this.frameClient==null)throw Ye;return new Be(await this.frameClient.openStreamer(Fe),e=>{const t=e.get(Fe);if(t.length===0)return[null,!1];const n=es.safeParse(t.at(-1));if(!n.success)return console.error(n.error),[null,!1];const i=n.data;return i.task!==this.key?[null,!1]:[i,!0]})}async snapshottedTo(){if(this.ontologyClient==null||this.rangeClient==null)throw Ye;return this.snapshot?await po(this.key,this.ontologyClient):null}}const wy=s.z.object({rack:mt.optional(),keys:je.array().optional(),names:s.z.string().array().optional(),types:s.z.string().array().optional(),includeState:s.z.boolean().optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),by=s.z.object({tasks:V(tr)}),Ty="/hardware/task/retrieve",vy="/hardware/task/create",Oy="/hardware/task/delete",Ny="/hardware/task/copy",Ey=s.z.object({tasks:Ia.array()}),zy=s.z.object({tasks:tr.array()}),Sy=s.z.object({keys:je.array()}),Iy=s.z.object({}),$y=s.z.object({key:je,name:s.z.string(),snapshot:s.z.boolean()}),ky=s.z.object({task:tr});let mo=class{constructor(e,t,n,i){c(this,"type",Wr);c(this,"client");c(this,"frameClient");c(this,"ontologyClient");c(this,"rangeClient");this.client=e,this.frameClient=t,this.ontologyClient=n,this.rangeClient=i}async create(e){const t=!Array.isArray(e),n=await w(this.client,vy,{tasks:b(e)},Ey,zy),i=this.sugar(n.tasks);return t?i[0]:i}async delete(e){await w(this.client,Oy,{keys:b(e)},Sy,Iy)}async search(e){return await this.execRetrieve({keys:[e]})}async page(e,t){return await this.execRetrieve({offset:e,limit:t})}async list(e={}){return this.sugar(await this.execRetrieve(e))}async retrieve(e,t){const{single:n,normalized:i,variant:a}=Qr(e,{number:"rack",string:"keys"},{convertNumericStrings:!1}),o={...t};a==="rack"?o.rack=e:o.keys=i;const l=await this.execRetrieve(o),u=this.sugar(l);return n&&a!=="rack"?u[0]:u}async copy(e,t,n){const i=await w(this.client,Ny,{key:e,name:t,snapshot:n},$y,ky);return this.sugar([i.task])[0]}async retrieveByName(e,t){const n=await this.execRetrieve({names:[e],rack:t});return en("Task",e,n,!0),this.sugar(n)[0]}async retrieveByType(e,t){const n=await this.execRetrieve({types:[e],rack:t});return this.sugar(n)}async retrieveSnapshottedTo(e){if(this.ontologyClient==null)throw Ye;return await po(e,this.ontologyClient)}async execRetrieve(e){return(await w(this.client,Ty,e,wy,by)).tasks}sugar(e){const t=!Array.isArray(e),n=b(e).map(({key:i,name:a,type:o,config:l,state:u,internal:h,snapshot:f})=>new go(i,a,o,l,h,f,u,this.frameClient,this.ontologyClient,this.rangeClient));return t?n[0]:n}async openTracker(){return await Le(this.frameClient,gy,my,(e,t)=>Array.from(t).map(n=>({variant:e,key:n.toString(),value:n.toString()})))}async openStateObserver(){return new Be(await this.frameClient.openStreamer(Bt),e=>{const t=e.get(Bt);if(t.length===0)return[null,!1];const n=qt.safeParse(t.at(-1));return n.success?[n.data,!0]:(console.error(n.error),[null,!1])})}async openCommandObserver(){return new Be(await this.frameClient.openStreamer(Fe),e=>{const t=e.get(Fe);if(t.length===0)return[null,!1];const n=es.safeParse(t.at(-1));return n.success?[n.data,!0]:(console.error(n.error),[null,!1])})}};const wo=r=>new O({type:Wr,key:r}),Ay=Object.freeze(Object.defineProperty({__proto__:null,Client:mo,ONTOLOGY_TYPE:Wr,Task:go,commandZ:es,getRackKey:Jh,keyZ:je,newZ:Ia,ontologyID:wo,stateZ:qt,statusZ:Sa,taskZ:tr},Symbol.toStringTag,{value:"Module"})),xy=s.z.object({keys:wt.array().optional(),for:re.optional(),search:s.z.string().optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),Ry=s.z.object({labels:V(rr)}),Cr=class Cr{constructor(e){c(this,"client");this.client=e}async retrieve(e){return await this.execute({keys:b(e)})}async retrieveFor(e){return await this.execute({for:e})}async search(e){return await this.execute({search:e})}async page(e,t){return await this.execute({offset:e,limit:t})}async execute(e){const[t,n]=await this.client.send(Cr.ENDPOINT,e,xy,Ry);if(n!=null)throw n;return t.labels}};c(Cr,"ENDPOINT","/label/retrieve");let xr=Cr;const bo=rr.extend({key:wt.optional()}),Cy=s.z.object({labels:bo.array()}),Py=s.z.object({labels:rr.array()}),jy=s.z.object({keys:wt.array()}),To=s.z.object({id:re,labels:wt.array(),replace:s.z.boolean().optional()}),Dy=To.omit({replace:!0}),On=s.z.object({}),My="/label/create",By="/label/delete",Zy="/label/set",Uy="/label/remove";let vo=class{constructor(e){c(this,"client");this.client=e}async create(e){return(await w(this.client,My,{labels:b(e)},Cy,Py)).labels}async delete(e){await w(this.client,By,{keys:b(e)},jy,On)}async set(e,t,{replace:n}={}){await w(this.client,Zy,{id:e,labels:t,replace:n},To,On)}async remove(e,t){await w(this.client,Uy,{id:e,labels:t},Dy,On)}};const Ly="sy_label_set",_y="sy_label_delete";let Oo=class{constructor(e,t,n){c(this,"type","label");c(this,"retriever");c(this,"writer");c(this,"frameClient");c(this,"ontology");this.writer=new vo(e),this.retriever=new xr(e),this.frameClient=t,this.ontology=n}async search(e){return await this.retriever.search(e)}async retrieve(e){const t=Array.isArray(e),n=await this.retriever.retrieve(e);return t?n:n[0]}async retrieveFor(e){return await this.retriever.retrieveFor(new O(e))}async label(e,t,n={}){await this.writer.set(new O(e),t,n)}async removeLabels(e,t){await this.writer.remove(new O(e),t)}async page(e,t){return await this.retriever.page(e,t)}async create(e){const t=Array.isArray(e),n=await this.writer.create(e);return t?n:n[0]}async delete(e){await this.writer.delete(e)}async openChangeTracker(){return await Le(this.frameClient,Ly,_y,qy)}async trackLabelsOf(e){const t=new Me.Observer,n=(await this.retrieveFor(e)).map(a=>({id:No(a.key),key:a.key,name:a.name,data:a}));return(await this.ontology.openDependentTracker({target:new O(e),dependents:n,relationshipType:"labeled_by"})).onChange(a=>t.notify(a.map(o=>{var l,u;return{key:o.id.key,color:(l=o.data)==null?void 0:l.color,name:(u=o.data)==null?void 0:u.name}}))),t}};const qy=(r,e)=>r==="delete"?e.toUUIDs().map(t=>({variant:r,key:t})):e.parseJSON(rr).map(t=>({variant:r,key:t.key,value:t})),No=r=>new O({type:ts,key:r}),Yy=Object.freeze(Object.defineProperty({__proto__:null,Client:Oo,ONTOLOGY_TYPE:ts,Retriever:xr,Writer:vo,keyZ:wt,labelZ:rr,newZ:bo,ontologyID:No},Symbol.toStringTag,{value:"Module"})),Wy="sy_range_alias_set",Fy="sy_range_alias_delete",Gy=s.z.object({range:ne,aliases:s.z.string().array()}),Vy=s.z.object({aliases:s.z.record(s.z.string(),J)}),Jy=s.z.object({range:ne,aliases:s.z.record(J.or(s.z.string()),s.z.string())}),Ky=s.z.unknown(),Hy=s.z.object({range:ne,channels:J.array()}),Xy=s.z.unknown(),Qy=s.z.object({range:ne}),ep=s.z.object({aliases:s.z.record(s.z.string(),s.z.string())}),fe=class fe{constructor(e,t,n){c(this,"frameClient");c(this,"cache",new Map);c(this,"client");c(this,"rangeKey");this.rangeKey=e,this.cache=new Map,this.client=n,this.frameClient=t}async resolve(e){const t=[],n=typeof e=="string",i={};if(n){const o=this.cache.get(e);if(o!=null)return o;t.push(e)}else e.forEach(o=>{const l=this.cache.get(o);l!=null?i[o]=l:t.push(o)});if(t.length===0)return i;const a=await w(this.client,fe.RESOLVE_ENDPOINT,{range:this.rangeKey,aliases:t},Gy,Vy);return Object.entries(a.aliases).forEach(([o,l])=>this.cache.set(o,l)),n?a.aliases[t[0]]:{...i,...a.aliases}}async set(e){await w(this.client,fe.SET_ENDPOINT,{range:this.rangeKey,aliases:e},Jy,Ky)}async list(){return(await w(this.client,fe.LIST_ENDPOINT,{range:this.rangeKey},Qy,ep)).aliases}async delete(e){await w(this.client,fe.DELETE_ENDPOINT,{range:this.rangeKey,channels:e},Hy,Xy)}async openChangeTracker(){return await Le(this.frameClient,Wy,Fy,np(this.rangeKey))}};c(fe,"SET_ENDPOINT","/range/alias/set"),c(fe,"RESOLVE_ENDPOINT","/range/alias/resolve"),c(fe,"LIST_ENDPOINT","/range/alias/list"),c(fe,"DELETE_ENDPOINT","/range/alias/delete");let Yn=fe;const tp=s.z.object({range:ne,channel:J,alias:s.z.string()}),rp="---",np=r=>(e,t)=>e==="delete"?t.toStrings().filter(n=>n.split(rp)[0]===r).map(n=>({variant:e,key:n,value:void 0})):t.parseJSON(tp).map(n=>({variant:e,key:n.alias,value:n})),vs=s.z.object({range:ne,key:s.z.string(),value:s.z.string()}),sp=s.z.object({range:ne,keys:s.z.string().array()}),ip=s.z.object({pairs:V(vs)}),ap=s.z.object({range:ne,pairs:vs.array()}),op=s.z.object({range:ne,keys:s.z.string().array()}),$e=class $e{constructor(e,t,n){c(this,"rangeKey");c(this,"client");c(this,"frameClient");this.rangeKey=e,this.client=t,this.frameClient=n}async get(e){const t=await w(this.client,$e.GET_ENDPOINT,{range:this.rangeKey,keys:b(e)},sp,ip);return typeof e=="string"?t.pairs[0].value:Object.fromEntries(t.pairs.map(n=>[n.key,n.value]))}async list(){return this.get([])}async set(e,t=""){let n;Jn(e)?n=Object.entries(e).map(([i,a])=>({range:this.rangeKey,key:i,value:a})):n=[{range:this.rangeKey,key:e,value:t}],await w(this.client,$e.SET_ENDPOINT,{range:this.rangeKey,pairs:n},ap,s.z.unknown())}async delete(e){await w(this.client,$e.DELETE_ENDPOINT,{range:this.rangeKey,keys:b(e)},op,s.z.unknown())}async openTracker(){return await Le(this.frameClient,"sy_range_kv_set","sy_range_kv_delete",(e,t)=>e==="delete"?t.toStrings().map(n=>{const[i,a]=n.split("<--->",2);return{variant:e,key:n,value:{range:i,key:a,value:""}}}):t.parseJSON(vs).map(n=>({variant:e,key:`${n.range}${n.key}`,value:n})))}};c($e,"GET_ENDPOINT","/range/kv/get"),c($e,"SET_ENDPOINT","/range/kv/set"),c($e,"DELETE_ENDPOINT","/range/kv/delete");let Gt=$e;class Eo{constructor(e,t=G.ZERO,n,i,a,o,l,u,h,f,d){c(this,"key");c(this,"name");c(this,"kv");c(this,"timeRange");c(this,"color");c(this,"channels");c(this,"aliaser");c(this,"frameClient");c(this,"labelClient");c(this,"ontologyClient");c(this,"rangeClient");this.key=n,this.name=e,this.timeRange=t,this.frameClient=a,this.color=i,this.kv=o,this.aliaser=l,this.channels=u,this.labelClient=h,this.ontologyClient=f,this.rangeClient=d}get ontologyID(){return Ie(this.key)}get payload(){return{key:this.key,name:this.name,timeRange:this.timeRange,color:this.color}}async setAlias(e,t){const n=await this.channels.retrieve(e);if(n.length===0)throw new ie(`Channel ${e} does not exist`);await this.aliaser.set({[n[0].key]:t})}async deleteAlias(...e){await this.aliaser.delete(e)}async listAliases(){return await this.aliaser.list()}async resolveAlias(e){return await this.aliaser.resolve(e)}async 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(t=>t.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(Ie(this.key))}async addLabel(...e){await this.labelClient.label(Ie(this.key),e)}async removeLabel(...e){await this.labelClient.removeLabels(Ie(this.key),e)}async openChildRangeTracker(){const e=new Me.Observer,t=(await this.retrieveChildren()).map(i=>{const a=Ie(i.key);return{id:a,key:a.toString(),name:i.name,data:i.payload}}),n=await this.ontologyClient.openDependentTracker({target:this.ontologyID,dependents:t,resourceType:"range"});return n.onChange(i=>e.notify(this.rangeClient.resourcesToRanges(i))),e.setCloser(async()=>await n.close()),e}async openParentRangeTracker(){const e=new Me.Observer,t=await this.retrieveParent();if(t==null)return null;const n=Ie(t.key),i={id:n,key:n.toString(),name:t.name,data:t.payload},a=await this.ontologyClient.openDependentTracker({target:this.ontologyID,dependents:[i],relationshipDirection:"to"});return a.onChange(o=>{const l=this.rangeClient.resourcesToRanges(o);if(l.length===0)return;const u=l[0];e.notify(u)}),e.setCloser(async()=>await a.close()),e}}const cp=(r,e)=>Du(r.timeRange,e.timeRange),lp=s.z.object({keys:ne.array().optional(),names:s.z.array(s.z.string()).optional(),term:s.z.string().optional(),overlapsWith:G.z.optional(),limit:s.z.number().int().optional(),offset:s.z.number().int().optional()}),up="/range/retrieve",hp=s.z.object({ranges:V(nr)});let zo=class{constructor(e,t,n,i,a,o){c(this,"type","range");c(this,"frameClient");c(this,"writer");c(this,"unaryClient");c(this,"channels");c(this,"labelClient");c(this,"ontologyClient");this.frameClient=e,this.writer=t,this.unaryClient=n,this.channels=i,this.labelClient=a,this.ontologyClient=o}async create(e,t){const n=!Array.isArray(e),i=this.sugarMany(await this.writer.create(b(e),t));return n?i[0]:i}async rename(e,t){await this.writer.rename(e,t)}async delete(e){await this.writer.delete(b(e))}async search(e){return this.sugarMany(await this.execRetrieve({term:e}))}async page(e,t){return this.sugarMany(await this.execRetrieve({offset:e,limit:t}))}async retrieve(e){if(typeof e=="object"&&"start"in e)return await this.execRetrieve({overlapsWith:new G(e)});const{single:t,actual:n,variant:i,normalized:a,empty:o}=ka(e);if(o)return[];const l=await this.execRetrieve({[i]:a});if(!t)return l;if(l.length===0)throw new Oe(`range matching ${n} not found`);if(l.length>1)throw new Ne(`multiple ranges matching ${n} found`);return l[0]}getKV(e){return new Gt(e,this.unaryClient,this.frameClient)}async execRetrieve(e){const{ranges:t}=await w(this.unaryClient,up,e,lp,hp);return this.sugarMany(t)}async retrieveParent(e){const t=await this.ontologyClient.retrieveParents(Ie(e));if(t.length===0)return null;const n=t[0];return n.id.type!=="range"?null:await this.retrieve(n.id.key)}sugarOne(e){return new Eo(e.name,e.timeRange,e.key,e.color,this.frameClient,new Gt(e.key,this.unaryClient,this.frameClient),new Yn(e.key,this.frameClient,this.unaryClient),this.channels,this.labelClient,this.ontologyClient,this)}sugarMany(e){return e.map(t=>this.sugarOne(t))}async openTracker(){return await Le(this.frameClient,"sy_range_set","sy_range_delete",(e,t)=>e==="delete"?t.toStrings().map(i=>({variant:e,key:i,value:void 0})):this.sugarMany(t.parseJSON(nr)).map(i=>({variant:e,key:i.key,value:i})))}resourcesToRanges(e){return e.map(t=>this.resourceToRange(t))}resourceToRange(e){var t,n,i;return this.sugarOne({key:e.id.key,name:(t=e.data)==null?void 0:t.name,timeRange:new G((n=e.data)==null?void 0:n.timeRange),color:(i=e.data)==null?void 0:i.color})}};const Ie=r=>new O({type:ns,key:r}),dp=r=>new O({type:ss,key:r}),fp=s.z.object({ranges:nr.array()}),yp=s.z.object({parent:re.optional(),ranges:$a.array()}),pp=s.z.object({keys:ne.array()}),gp=s.z.object({}),mp=s.z.object({key:ne,name:rs}),wp=s.z.object({}),bp="/range/create",Tp="/range/delete",vp="/range/rename";class So{constructor(e){c(this,"client");this.client=e}async rename(e,t){await w(this.client,vp,{key:e,name:t},mp,wp)}async create(e,t){return(await w(this.client,bp,{ranges:e,...t},yp,fp)).ranges}async delete(e){await w(this.client,Tp,{keys:e},pp,gp)}}const Op=Object.freeze(Object.defineProperty({__proto__:null,ALIAS_ONTOLOGY_TYPE:ss,Client:zo,KV:Gt,ONTOLOGY_TYPE:ns,Range:Eo,Writer:So,aliasOntologyID:dp,analyzeParams:ka,keyZ:ne,nameZ:rs,newZ:$a,ontologyID:Ie,payloadZ:nr,sort:cp},Symbol.toStringTag,{value:"Module"})),Np="/api/v1/";class Ep{constructor(e,t={},n=!1){c(this,"url");c(this,"unary");c(this,"stream");c(this,"secure");this.secure=n,this.url=e.child(Np);const i=new Jt.JSONCodec;this.unary=El(new Nl(this.url,i,this.secure),t),this.stream=new Cl(this.url,i,this.secure)}use(...e){this.unary.use(...e),this.stream.use(...e)}}const zp="/workspace/lineplot/retrieve",Sp="/workspace/lineplot/create",Ip="/workspace/lineplot/rename",$p="/workspace/lineplot/set-data",kp="/workspace/lineplot/delete",Ap=s.z.object({keys:bt.array()}),xp=s.z.object({workspace:pe,linePlots:xa.array()}),Rp=s.z.object({key:bt,name:s.z.string()}),Cp=s.z.object({key:bt,data:s.z.string()}),Pp=s.z.object({keys:bt.array()}),jp=s.z.object({linePlots:V(Fr)}),Dp=s.z.object({linePlots:Fr.array()}),Nn=s.z.object({});let Io=class{constructor(e){c(this,"client");this.client=e}async create(e,t){const n=Array.isArray(t),i=await w(this.client,Sp,{workspace:e,linePlots:b(t)},xp,Dp);return n?i.linePlots:i.linePlots[0]}async rename(e,t){await w(this.client,Ip,{key:e,name:t},Rp,Nn)}async setData(e,t){await w(this.client,$p,{key:e,data:JSON.stringify(t)},Cp,Nn)}async retrieve(e){const t=Array.isArray(e),n=await w(this.client,zp,{keys:b(e)},Ap,jp);return t?n.linePlots:n.linePlots[0]}async delete(e){await w(this.client,kp,{keys:b(e)},Pp,Nn)}};const Mp=r=>new O({type:as,key:r}),Bp=Object.freeze(Object.defineProperty({__proto__:null,Client:Io,ONTOLOGY_TYPE:as,keyZ:bt,linePlotZ:Fr,newZ:xa,ontologyID:Mp},Symbol.toStringTag,{value:"Module"})),Zp="/workspace/log/retrieve",Up="/workspace/log/create",Lp="/workspace/log/rename",_p="/workspace/log/set-data",qp="/workspace/log/delete",Yp=s.z.object({keys:Tt.array()}),Wp=s.z.object({workspace:pe,logs:Ra.array()}),Fp=s.z.object({key:Tt,name:s.z.string()}),Gp=s.z.object({key:Tt,data:s.z.string()}),Vp=s.z.object({keys:Tt.array()}),Jp=s.z.object({logs:Gr.array()}),Kp=s.z.object({logs:Gr.array()}),En=s.z.object({});let $o=class{constructor(e){c(this,"client");this.client=e}async create(e,t){const n=Array.isArray(t),i=await w(this.client,Up,{workspace:e,logs:b(t)},Wp,Kp);return n?i.logs:i.logs[0]}async rename(e,t){await w(this.client,Lp,{key:e,name:t},Fp,En)}async setData(e,t){await w(this.client,_p,{key:e,data:JSON.stringify(t)},Gp,En)}async retrieve(e){const t=Array.isArray(e),n=await w(this.client,Zp,{keys:b(e)},Yp,Jp);return t?n.logs:n.logs[0]}async delete(e){await w(this.client,qp,{keys:b(e)},Vp,En)}};const Hp=r=>new O({type:os,key:r}),Xp=Object.freeze(Object.defineProperty({__proto__:null,Client:$o,ONTOLOGY_TYPE:os,keyZ:Tt,logZ:Gr,newZ:Ra,ontologyID:Hp},Symbol.toStringTag,{value:"Module"})),Qp="/workspace/schematic/retrieve",eg="/workspace/schematic/create",tg="/workspace/schematic/rename",rg="/workspace/schematic/set-data",ng="/workspace/schematic/delete",sg="/workspace/schematic/copy",ig=s.z.object({keys:Ue.array()}),ag=s.z.object({workspace:pe,schematics:ja.array()}),og=s.z.object({key:Ue,name:s.z.string()}),cg=s.z.object({key:Ue,data:s.z.string()}),lg=s.z.object({keys:Ue.array()}),ug=s.z.object({key:Ue,name:s.z.string(),snapshot:s.z.boolean()}),hg=s.z.object({schematics:V(cs)}),dg=s.z.object({schematics:cs.array()}),fg=s.z.object({schematic:Kr}),zn=s.z.object({});let ko=class{constructor(e){c(this,"client");this.client=e}async create(e,t){const n=Array.isArray(t),i=await w(this.client,eg,{workspace:e,schematics:b(t)},ag,dg);return n?i.schematics:i.schematics[0]}async rename(e,t){await w(this.client,tg,{key:e,name:t},og,zn)}async setData(e,t){await w(this.client,rg,{key:e,data:JSON.stringify(t)},cg,zn)}async retrieve(e){const t=Array.isArray(e),n=await w(this.client,Qp,{keys:b(e)},ig,hg);return t?n.schematics:n.schematics[0]}async delete(e){await w(this.client,ng,{keys:b(e)},lg,zn)}async copy(e,t,n){return(await w(this.client,sg,{key:e,name:t,snapshot:n},ug,fg)).schematic}};const yg=r=>new O({type:ls,key:r}),pg=Object.freeze(Object.defineProperty({__proto__:null,Client:ko,ONTOLOGY_TYPE:ls,keyZ:Ue,newZ:ja,ontologyID:yg,remoteZ:cs,schematicZ:Kr},Symbol.toStringTag,{value:"Module"})),gg="/workspace/table/retrieve",mg="/workspace/table/create",wg="/workspace/table/rename",bg="/workspace/table/set-data",Tg="/workspace/table/delete",vg=s.z.object({keys:vt.array()}),Og=s.z.object({workspace:pe,tables:Da.array()}),Ng=s.z.object({key:vt,name:s.z.string()}),Eg=s.z.object({key:vt,data:s.z.string()}),zg=s.z.object({keys:vt.array()}),Sg=s.z.object({tables:hs.array()}),Ig=s.z.object({tables:hs.array()}),Sn=s.z.object({});let Ao=class{constructor(e){c(this,"client");this.client=e}async create(e,t){const n=Array.isArray(t),i=await w(this.client,mg,{workspace:e,tables:b(t)},Og,Ig);return n?i.tables:i.tables[0]}async rename(e,t){await w(this.client,wg,{key:e,name:t},Ng,Sn)}async setData(e,t){await w(this.client,bg,{key:e,data:JSON.stringify(t)},Eg,Sn)}async retrieve(e){const t=Array.isArray(e),n=await w(this.client,gg,{keys:b(e)},vg,Sg);return t?n.tables:n.tables[0]}async delete(e){await w(this.client,Tg,{keys:b(e)},zg,Sn)}};const $g=r=>new O({type:ds,key:r}),kg=Object.freeze(Object.defineProperty({__proto__:null,Client:Ao,ONTOLOGY_TYPE:ds,keyZ:vt,newZ:Da,ontologyID:$g,remoteZ:hs,tableZ:us},Symbol.toStringTag,{value:"Module"})),hr="/workspace/retrieve",Ag="/workspace/create",xg="/workspace/rename",Rg="/workspace/set-layout",Cg="/workspace/delete",dr=s.z.object({keys:pe.array().optional(),search:s.z.string().optional(),author:Ze.optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),Pg=s.z.object({workspaces:Ca.array()}),jg=s.z.object({key:pe,name:s.z.string()}),Dg=s.z.object({key:pe,layout:s.z.string()}),Mg=s.z.object({keys:pe.array()}),fr=s.z.object({workspaces:V(Vr)}),Bg=s.z.object({workspaces:Pa.array()}),In=s.z.object({});class xo{constructor(e){c(this,"type",Jr);c(this,"schematic");c(this,"linePlot");c(this,"log");c(this,"table");c(this,"client");this.client=e,this.schematic=new ko(e),this.linePlot=new Io(e),this.log=new $o(e),this.table=new Ao(e)}async create(e){const t=Array.isArray(e),n=await w(this.client,Ag,{workspaces:b(e)},Pg,Bg);return t?n.workspaces:n.workspaces[0]}async rename(e,t){await w(this.client,xg,{key:e,name:t},jg,In)}async setLayout(e,t){await w(this.client,Rg,{key:e,layout:JSON.stringify(t)},Dg,In)}async retrieve(e){const t=Array.isArray(e),n=await w(this.client,hr,{keys:b(e)},dr,fr);return t?n.workspaces:n.workspaces[0]}async retrieveByAuthor(e){return(await w(this.client,hr,{author:e},dr,fr)).workspaces}async search(e){return(await w(this.client,hr,{search:e},dr,fr)).workspaces}async page(e,t){return(await w(this.client,hr,{offset:e,limit:t},dr,fr)).workspaces}async delete(e){await w(this.client,Cg,{keys:b(e)},Mg,In)}}const Zg=r=>new O({type:Jr,key:r}),Ug=Object.freeze(Object.defineProperty({__proto__:null,Client:xo,ONTOLOGY_TYPE:Jr,keyZ:pe,newZ:Ca,ontologyID:Zg,remoteZ:Pa,workspaceZ:Vr},Symbol.toStringTag,{value:"Module"})),Ro=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:N.z.default(N.seconds(30)),secure:s.z.boolean().optional().default(!1),name:s.z.string().optional(),retry:Ph.breakerConfig.optional()});class Co extends oo{constructor(t){const n=Ro.parse(t),{host:i,port:a,username:o,password:l,connectivityPollFrequency:u,secure:h,retry:f}=n,d=new Ep(new ah({host:i,port:Number(a)}),f,h);d.use(Gh);let k;o!=null&&l!=null&&(k=new Ef(d.unary,{username:o,password:l}),d.use(k.middleware()));const S=new ps(new Yt(d.unary)),se=new to(d.unary,S);super(d.stream,d.unary,S);c(this,"createdAt");c(this,"props");c(this,"ranges");c(this,"channels");c(this,"auth");c(this,"user");c(this,"access");c(this,"connectivity");c(this,"ontology");c(this,"workspaces");c(this,"labels");c(this,"hardware");c(this,"control");c(this,"transport");c(this,"clientVersion","0.40.0");this.createdAt=$.now(),this.props=n,this.auth=k,this.transport=d,this.channels=new Xa(this,S,d.unary,se),this.connectivity=new Ft(d.unary,u,this.clientVersion,n.name),this.control=new lo(this),this.ontology=new Wa(d.unary,this);const L=new So(this.transport.unary);this.labels=new Oo(this.transport.unary,this,this.ontology),this.ranges=new zo(this,L,this.transport.unary,S,this.labels,this.ontology),this.access=new Va(this.transport.unary),this.user=new ro(this.transport.unary),this.workspaces=new xo(this.transport.unary);const Po=new ho(this.transport.unary,this),Os=new mo(this.transport.unary,this,this.ontology,this.ranges),jo=new fo(this.transport.unary,Os);this.hardware=new uo(Os,jo,Po)}get key(){return this.createdAt.valueOf().toString()}close(){this.connectivity.stopChecking()}}c(Co,"connectivity",Ft);const Lg=dt.Authority;exports.AuthError=ve;exports.Authority=Lg;exports.Channel=gs;exports.ContiguityError=Ln;exports.DataType=I;exports.Density=X;exports.Frame=Y;exports.MultiSeries=fa;exports.MultipleFoundError=Ne;exports.NotFoundError=Oe;exports.QueryError=ie;exports.Rate=ut;exports.RouteError=_t;exports.Series=ke;exports.Synnax=Co;exports.TimeRange=G;exports.TimeSpan=N;exports.TimeStamp=$;exports.UnexpectedError=xe;exports.ValidationError=U;exports.access=kd;exports.channel=Kd;exports.connection=Sf;exports.control=Vf;exports.device=oy;exports.framer=qf;exports.group=id;exports.hardware=Jf;exports.isCalculated=Wt;exports.label=Yy;exports.linePlot=Bp;exports.log=Xp;exports.ontology=yd;exports.policy=$d;exports.rack=py;exports.ranger=Op;exports.schematic=pg;exports.signals=Kf;exports.synnaxPropsZ=Ro;exports.table=kg;exports.task=Ay;exports.user=gf;exports.workspace=Ug;
|