@synnaxlabs/client 0.26.0 → 0.26.7
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 +293 -270
- package/dist/framer/adapter.d.ts +2 -0
- package/dist/framer/adapter.d.ts.map +1 -1
- package/dist/framer/writer.d.ts +9 -6
- package/dist/framer/writer.d.ts.map +1 -1
- package/examples/node/basicReadWrite.js +28 -18
- package/examples/node/liveStream.js +7 -8
- package/examples/node/package-lock.json +2165 -2365
- package/examples/node/package.json +1 -1
- package/examples/node/seriesAndFrames.js +48 -47
- package/examples/node/streamWrite.js +34 -33
- package/package.json +3 -3
- package/src/framer/adapter.spec.ts +9 -0
- package/src/framer/adapter.ts +12 -0
- package/src/framer/client.ts +2 -2
- package/src/framer/writer.spec.ts +99 -14
- package/src/framer/writer.ts +56 -23
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @synnaxlabs/client@0.26.
|
|
2
|
+
> @synnaxlabs/client@0.26.7 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[2m231.
|
|
14
|
-
[vite:dts] Declaration files built in
|
|
13
|
+
[2mdist/[22m[36mclient.js [39m[1m[2m231.96 kB[22m[1m[22m[2m │ gzip: 54.05 kB[22m
|
|
14
|
+
[vite:dts] Declaration files built in 4212ms.
|
|
15
15
|
|
|
16
|
-
[2mdist/[22m[36mclient.cjs [39m[1m[
|
|
17
|
-
[32m✓ built in
|
|
16
|
+
[2mdist/[22m[36mclient.cjs [39m[1m[2m146.12 kB[22m[1m[22m[2m │ gzip: 39.55 kB[22m
|
|
17
|
+
[32m✓ built in 5.07s[39m
|
package/dist/client.cjs
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
`);o(this,"type",je.TYPE)}};o(je,"TYPE",me+"unexpected"),o(je,"matches",J(je.TYPE));let pe=je;const Pe=class Pe extends te{constructor(){super(...arguments);o(this,"type",Pe.TYPE)}};o(Pe,"TYPE",me+"query"),o(Pe,"matches",J(Pe.TYPE));let X=Pe;const De=class De extends X{constructor(){super(...arguments);o(this,"type",De.TYPE)}};o(De,"TYPE",X.TYPE+".not_found"),o(De,"matches",J(De.TYPE));let Ie=De;const Me=class Me extends X{constructor(){super(...arguments);o(this,"type",Me.TYPE)}};o(Me,"TYPE",X.TYPE+".multiple_results"),o(Me,"matches",J(Me.TYPE));let ke=Me;const Ze=class Ze extends te{constructor(t,n){super(t);o(this,"type",Ze.TYPE);o(this,"path");this.path=n}};o(Ze,"TYPE",me+"route"),o(Ze,"matches",J(Ze.TYPE));let gt=Ze;const Ue=class Ue extends te{constructor(){super(...arguments);o(this,"type",Ue.TYPE)}};o(Ue,"TYPE",me+"control"),o(Ue,"matches",J(Ue.TYPE));let Ge=Ue;const Be=class Be extends Ge{constructor(){super(...arguments);o(this,"type",Be.TYPE)}};o(Be,"TYPE",Ge.TYPE+".unauthorized"),o(Be,"matches",J(Be.TYPE));let Lt=Be;const Le=class Le extends te{constructor(){super(...arguments);o(this,"type",Le.TYPE)}};o(Le,"TYPE",me+"contiguity"),o(Le,"matches",J(Le.TYPE));let xr=Le;const pc=r=>{if(!r.type.startsWith(me))return null;if(r.type.startsWith(C.TYPE)){if(r.type===Bt.TYPE){const e=r.data.split(": ");return e.length<2?new C(r.data):new Bt(e[0],e[1])}return new C(r.data)}return r.type.startsWith(Ne.TYPE)?r.type.startsWith(pt.TYPE)?new pt(r.data):new Ne(r.data):r.type.startsWith(pe.TYPE)?new pe(r.data):r.type.startsWith(X.TYPE)?r.type.startsWith(Ie.TYPE)?new Ie(r.data):r.type.startsWith(ke.TYPE)?new ke(r.data):new X(r.data):r.type.startsWith(Ge.TYPE)?r.type.startsWith(Lt.TYPE)?new Lt(r.data):new Ge(r.data):r.type.startsWith(gt.TYPE)?new gt(r.data,r.data):new pe(r.data)},gc=()=>{throw new Error("Not implemented")};ns({encode:gc,decode:pc});const mc=async(r,e)=>{const[t,n]=await e(r);return n==null?[t,n]:n instanceof Se?[t,new Se({message:`Cannot reach cluster at ${n.url.host}:${n.url.port}`,url:n.url})]:[t,n]};class Rs{constructor(e,t){o(this,"key");o(this,"name");this.key=t,this.name=e}get ontologyID(){return new x({type:"group",key:this.key})}}const wc=s.z.string().uuid(),xs=s.z.object({key:wc,name:s.z.string()}),Cs=s.z.union([s.z.literal("label"),s.z.literal("builtin"),s.z.literal("cluster"),s.z.literal("channel"),s.z.literal("node"),s.z.literal("group"),s.z.literal("range"),s.z.literal("range-alias"),s.z.literal("user"),s.z.literal("workspace"),s.z.literal("schematic"),s.z.literal("lineplot"),s.z.literal("rack"),s.z.literal("device"),s.z.literal("task"),s.z.literal("policy")]),bc="builtin",vc="cluster",Tc="node",H=s.z.object({type:Cs,key:s.z.string()}),js=s.z.string().transform(r=>{const[e,t]=r.split(":");return{type:e,key:t}}),Ps=s.z.union([js,H]),qe=class qe{constructor(e){o(this,"type");o(this,"key");if(e instanceof qe)this.type=e.type,this.key=e.key;else if(typeof e=="string"){const[t,n]=e.split(":");this.type=t,this.key=n}else this.type=e.type,this.key=e.key}toString(){return`${this.type}:${this.key}`}get payload(){return{type:this.type,key:this.key}}};o(qe,"z",s.z.union([Ps,s.z.instanceof(qe)]).transform(e=>new qe(e)));let x=qe;const Oc=new x({type:"builtin",key:"root"}),Ds=s.z.object({type:s.z.number()}),Ms=s.z.object({type:Cs,fields:s.z.record(Ds)}),Zs=s.z.object({id:x.z,name:s.z.string(),schema:Ms.optional().nullable(),data:s.z.record(s.z.unknown()).optional().nullable()}).transform(r=>({key:r.id.toString(),...r})),zc=s.z.object({from:x.z,type:s.z.string(),to:x.z}),Cr=r=>{const[e,t,n]=r.split("->");return{from:new x(e),type:t,to:new x(n)}},Ec=s.z.object({group:xs}),Sc=s.z.object({parent:H,key:s.z.string().uuid().optional(),name:s.z.string()}),Nc=s.z.object({key:s.z.string(),name:s.z.string()}),Ic=s.z.object({keys:s.z.array(s.z.string())});var ee;let kc=(ee=class{constructor(e){o(this,"client");this.client=e}async create(e,t,n){const[i,a]=await this.client.send(ee.ENDPOINT,{parent:e,name:t,key:n},Sc,Ec);if(a!=null)throw a;return i.group}async rename(e,t){const n={key:e,name:t},[,i]=await this.client.send(ee.ENDPOINT_RENAME,n,Nc,s.z.object({}));if(i!=null)throw i}async delete(e){const t={keys:e},[,n]=await this.client.send(ee.ENDPOINT_DELETE,t,Ic,s.z.object({}));if(n!=null)throw n}},o(ee,"ENDPOINT","/ontology/create-group"),o(ee,"ENDPOINT_RENAME","/ontology/rename-group"),o(ee,"ENDPOINT_DELETE","/ontology/delete-group"),ee),Ac=class{constructor(e){o(this,"creator");this.creator=new kc(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 Rs(e.name,e.key)}};const yr={ADD_CHILDREN:"/ontology/add-children",REMOVE_CHILDREN:"/ontology/remove-children",MOVE_CHILDREN:"/ontology/move-children"},$n=s.z.object({id:H,children:H.array()}),$c=s.z.object({from:H,to:H,children:H.array()});let Rc=class{constructor(e){o(this,"client");this.client=e}async addChildren(e,...t){await w(this.client,yr.ADD_CHILDREN,{id:e,children:t},$n,s.z.object({}))}async removeChildren(e,...t){await w(this.client,yr.REMOVE_CHILDREN,{id:e,children:t},$n,s.z.object({}))}async moveChildren(e,t,...n){const i={from:e,to:t,children:n};await w(this.client,yr.MOVE_CHILDREN,i,$c,s.z.object({}))}};const xc="/ontology/retrieve",Cc=s.z.object({ids:H.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()}),jc=s.z.object({resources:Zs.array()}),dr=r=>T(r).map(e=>new x(e).payload);let Us=class{constructor(e,t){o(this,"type","ontology");o(this,"groups");o(this,"client");o(this,"writer");o(this,"framer");this.client=e,this.writer=new Rc(e),this.groups=new Ac(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:dr(e),...t});if(Array.isArray(e))return n;if(n.length===0)throw new X(`No resource found with ID ${e.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:dr(e),children:!0,...t})}async retrieveParents(e,t){return await this.execRetrieve({ids:dr(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 Kt.open(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,xc,e,Cc,jc);return t}};const Rn="sy_ontology_resource_set",xn="sy_ontology_resource_delete",Cn="sy_ontology_relationship_set",jn="sy_ontology_relationship_delete";class Kt{constructor(e,t){o(this,"resourceObs");o(this,"relationshipObs");o(this,"relationships");o(this,"resources");o(this,"streamer");o(this,"client");o(this,"closePromise");this.relationshipObs=new Ar.Observer,this.relationships=this.relationshipObs,this.resourceObs=new Ar.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),c=this.parseRelationshipDeletes(e);a.concat(c).length>0&&this.relationshipObs.notify(a.concat(c))}parseRelationshipSets(e){const t=e.get(Cn);return t.length===0?[]:Array.from(t.as("string")).map(n=>({variant:"set",key:Cr(n),value:void 0}))}parseRelationshipDeletes(e){const t=e.get(jn);return t.length===0?[]:Array.from(t.as("string")).map(n=>({variant:"delete",key:Cr(n)}))}async parseResourceSets(e){const t=e.get(Rn);if(t.length===0)return[];const n=Array.from(t.as("string")).map(i=>new x(i));try{return(await this.client.retrieve(n)).map(a=>({variant:"set",key:a.id,value:a}))}catch(i){if(i instanceof X)return[];throw i}}parseResourceDeletes(e){const t=e.get(xn);return t.length===0?[]:Array.from(t.as("string")).map(n=>({variant:"delete",key:new x(n)}))}static async open(e,t){const n=await e.openStreamer([Rn,xn,Cn,jn]);return new Kt(n,t)}}const Pc=Object.freeze(Object.defineProperty({__proto__:null,BuiltinOntologyType:bc,ChangeTracker:Kt,Client:Us,ClusterOntologyType:vc,ID:x,NodeOntologyType:Tc,Root:Oc,crudeIDZ:Ps,idZ:H,parseRelationship:Cr,relationshipSchemaZ:zc,resourceSchemaZ:Zs,schemaFieldZ:Ds,schemaZ:Ms,stringIDZ:js},Symbol.toStringTag,{value:"Module"})),we=s.z.number(),Ot=s.z.object({name:s.z.string(),key:s.z.number(),rate:Gt.z,dataType:z.z,leaseholder:s.z.number(),index:s.z.number(),isIndex:s.z.boolean(),internal:s.z.boolean(),alias:s.z.string().optional()}),Bs=Ot.extend({key:s.z.number().optional(),leaseholder:s.z.number().optional(),index:s.z.number().optional(),rate:Gt.z.optional().default(0),isIndex:s.z.boolean().optional(),internal:s.z.boolean().optional().default(!1),virtual:s.z.boolean().optional().default(!1)}),Ls="channel",Dc=r=>new x({type:Ls,key:r.toString()}),Mc=new Error("request for lock canceled");var Zc=function(r,e,t,n){function i(a){return a instanceof t?a:new t(function(c){c(a)})}return new(t||(t=Promise))(function(a,c){function l(p){try{f(n.next(p))}catch(g){c(g)}}function u(p){try{f(n.throw(p))}catch(g){c(g)}}function f(p){p.done?a(p.value):i(p.value).then(l,u)}f((n=n.apply(r,e||[])).next())})};class Uc{constructor(e,t=Mc){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},c=qs(this._queue,l=>t<=l.priority);c===-1&&e<=this._value?this._dispatchItem(a):this._queue.splice(c+1,0,a)})}runExclusive(e){return Zc(this,arguments,void 0,function*(t,n=1,i=0){const[a,c]=yield this.acquire(n,i);try{return yield t(a)}finally{c()}})}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]=[]),Bc(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 Bc(r,e){const t=qs(r,n=>e.priority<=n.priority);r.splice(t+1,0,e)}function qs(r,e){for(let t=r.length-1;t>=0;t--)if(e(r[t]))return t;return-1}var Lc=function(r,e,t,n){function i(a){return a instanceof t?a:new t(function(c){c(a)})}return new(t||(t=Promise))(function(a,c){function l(p){try{f(n.next(p))}catch(g){c(g)}}function u(p){try{f(n.throw(p))}catch(g){c(g)}}function f(p){p.done?a(p.value):i(p.value).then(l,u)}f((n=n.apply(r,e||[])).next())})};class qc{constructor(e){this._semaphore=new Uc(1,e)}acquire(){return Lc(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 Vt=(r,e,{convertNumericStrings:t=!0}={})=>{const n=!Array.isArray(r);let i=T(r);const a=i[0],c=typeof a;let l;return c==="string"&&t&&!isNaN(parseInt(a))&&"number"in e?(l=e.number,i=i.map(u=>parseInt(u))):l=e[c],{single:n,variant:l,normalized:i,actual:r}},Jt=(r,e,t,n)=>{if(n){if(t.length===0)throw new Ie(`${r} not found matching ${JSON.stringify(e)}`);if(t.length>1)throw new ke(`Expected one ${r} matching ${JSON.stringify(e)}, but found ${t.length}`)}},Ve=r=>s.z.union([s.z.null().transform(()=>[]),r.array()]),Yc=s.z.object({leaseholder:s.z.number().optional(),keys:s.z.number().array().optional(),names:s.z.string().array().optional(),search:s.z.string().optional(),rangeKey:s.z.string().optional(),limit:s.z.number().optional(),offset:s.z.number().optional(),dataTypes:z.z.array().optional(),notDataTypes:z.z.array().optional(),virtual:s.z.boolean().optional(),isIndex:s.z.boolean().optional(),internal:s.z.boolean().optional()}),Wc=s.z.object({channels:Ve(Ot)}),ye=r=>Vt(r,{number:"keys",string:"names"}),Yt=class Yt{constructor(e){o(this,"client");this.client=e}async search(e,t){return await this.execute({search:e,...t})}async retrieve(e,t){const n=ye(e),{variant:i}=n;let{normalized:a}=n;return i==="keys"&&a.indexOf(0)!==-1&&(a=a.filter(c=>c!==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(Yt.ENDPOINT,e,Yc,Wc);if(n!=null)throw n;return t.channels}};o(Yt,"ENDPOINT","/channel/retrieve");let mt=Yt;class qr{constructor(e){o(this,"cache");o(this,"namesToKeys");o(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}=Vt(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 c=await this.wrapped.retrieve(a,t);return this.set(c),i.concat(c)}delete(e){const{variant:t,normalized:n}=ye(e);t==="names"?n.forEach(i=>{const a=this.namesToKeys.get(i);a!=null&&(a.forEach(c=>this.cache.delete(c)),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],c=this.cache.get(n);if(c==null)return;this.cache.delete(n);const l=this.namesToKeys.get(c.name);l!=null&&(l.delete(n),l.size===0&&this.namesToKeys.delete(c.name)),c.name=a,this.cache.set(n,c);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 Ys{constructor(e,t){o(this,"mu",new qc);o(this,"requests",new Map);o(this,"wrapped");o(this,"debouncedRun");this.wrapped=e,this.debouncedRun=Xo(()=>{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}=ye(e);return n==="names"?await this.wrapped.retrieve(t):await new Promise((a,c)=>{this.mu.runExclusive(()=>{this.requests.set(t,{resolve:a,reject:c}),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 Ws=async(r,e)=>{const{normalized:t}=ye(e),n=await r.retrieve(t),i=[];if(t.forEach(a=>{n.find(c=>c.name===a||c.key===a)==null&&i.push(a)}),i.length>0)throw new X(`Could not find channels: ${JSON.stringify(i)}`);return n};class Yr{constructor({dataType:e,rate:t,name:n,leaseholder:i=0,key:a=0,isIndex:c=!1,index:l=0,internal:u=!1,frameClient:f,alias:p}){o(this,"_frameClient");o(this,"key");o(this,"name");o(this,"rate");o(this,"dataType");o(this,"leaseholder");o(this,"index");o(this,"isIndex");o(this,"internal");o(this,"alias");this.key=a,this.name=n,this.rate=new Gt(t??0),this.dataType=new z(e),this.leaseholder=i,this.index=l,this.isIndex=c,this.internal=u,this.alias=p,this._frameClient=f??null}get framer(){if(this._frameClient==null)throw new C("cannot read from a channel that has not been created");return this._frameClient}get payload(){return Ot.parse({key:this.key,name:this.name,rate:this.rate.valueOf(),dataType:this.dataType.valueOf(),leaseholder:this.leaseholder,index:this.index,isIndex:this.isIndex,internal:this.internal})}get ontologyID(){return new x({type:"channel",key:this.key.toString()})}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 Fc="/channel/retrieve-group",_c=s.z.object({}),Gc=s.z.object({group:xs});let Fs=class{constructor(e,t,n,i){o(this,"type","channel");o(this,"frameClient");o(this,"client");o(this,"retriever");o(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=T(e),c=[];if(n){const l=await this.retriever.retrieve(a.map(f=>f.name)),u=new Set(l.map(f=>f.name));a=a.filter(f=>!u.has(f.name)),c=this.sugar(l)}return c=c.concat(this.sugar(await this.writer.create(a))),i?c[0]:c}async retrieve(e,t){const n=!Array.isArray(e),i=this.sugar(await this.retriever.retrieve(e,t));return Jt("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}=ye(e);return n==="keys"?await this.writer.delete({keys:t}):await this.writer.delete({names:t})}async rename(e,t){return await this.writer.rename(T(e),T(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 qr(new Ys(new mt(this.client),e))}sugar(e){const{frameClient:t}=this;return e.map(n=>new Yr({...n,frameClient:t}))}async retrieveGroup(){const e=await w(this.client,Fc,{},_c,Gc);return new Rs(e.group.name,e.group.key)}};const Kc=s.z.object({channels:Bs.array()}),Vc=s.z.object({channels:Ot.array()}),Jc=s.z.object({keys:we.array().optional(),names:s.z.string().array().optional()}),Hc=s.z.object({}),Xc=s.z.object({keys:we.array(),names:s.z.string().array()}),Qc=s.z.object({}),el="/channel/create",tl="/channel/delete",rl="/channel/rename";let _s=class{constructor(e,t){o(this,"client");o(this,"cache");this.client=e,this.cache=t}async create(e){const{channels:t}=await w(this.client,el,{channels:e},Kc,Vc);return this.cache.set(t),t}async delete(e){await w(this.client,tl,e,Jc,Hc),e.keys!=null&&this.cache.delete(e.keys),e.names!=null&&this.cache.delete(e.names)}async rename(e,t){await w(this.client,rl,{keys:e,names:t},Xc,Qc),this.cache.rename(e,t)}};const nl=Object.freeze(Object.defineProperty({__proto__:null,CacheRetriever:qr,Channel:Yr,ChannelOntologyType:Ls,Client:Fs,ClusterRetriever:mt,DebouncedBatchRetriever:Ys,Writer:_s,analyzeChannelParams:ye,keyZ:we,newPayload:Bs,ontologyID:Dc,payload:Ot,retrieveRequired:Ws},Symbol.toStringTag,{value:"Module"})),Wr=s.z.string().uuid(),Fr=s.z.object({key:Wr,subjects:H.array(),objects:H.array(),actions:s.z.string().array()}),sl=Fr.extend({key:Wr.optional()}),il="/access/policy/create",al="/access/policy/delete",ol="/access/policy/retrieve",cl=s.z.object({policies:sl.array()}),ll=s.z.object({policies:Fr.array()}),ul=s.z.object({keys:Wr.array()}),hl=s.z.object({}),yl=s.z.object({subject:H}),dl=s.z.object({policies:Fr.array().optional().default([])});let fl=class{constructor(e){o(this,"client");this.client=e}async create(e){const t=!Array.isArray(e),{policies:n}=await w(this.client,il,{policies:T(e)},cl,ll);return t?n[0]:n}async retrieve(e){const{policies:t}=await w(this.client,ol,{subject:e},yl,dl);return t}async delete(e){await w(this.client,al,{keys:T(e)},ul,hl)}};const pl="/user/register";let gl=class{constructor(e){o(this,"client");this.client=e}async register(e,t){const{user:n}=await w(this.client,pl,{username:e,password:t},Gs,Ks);return n}};s.z.string().uuid();const ml=s.z.object({key:s.z.string(),username:s.z.string()}),Gs=s.z.object({username:s.z.string(),password:s.z.string()}),Ks=s.z.object({token:s.z.string(),user:ml}),Pn="/auth/login",wl=3;let bl=class{constructor(e,t){o(this,"token");o(this,"client");o(this,"credentials");o(this,"authenticating");o(this,"authenticated");o(this,"user");o(this,"retryCount");this.client=e,this.authenticated=!1,this.credentials=t,this.retryCount=0}middleware(){const e=async(t,n)=>{if(!this.authenticated&&!t.target.endsWith(Pn)){this.authenticating==null&&(this.authenticating=new Promise((l,u)=>{this.client.send(Pn,this.credentials,Gs,Ks).then(([f,p])=>{if(p!=null)return l(p);this.token=f==null?void 0:f.token,this.user=f==null?void 0:f.user,this.authenticated=!0,l(null)}).catch(u)}));const c=await this.authenticating;if(c!=null)return[t,c]}t.params.Authorization=`Bearer ${this.token}`;const[i,a]=await n(t);return pt.matches(a)&&this.retryCount<wl?(this.authenticated=!1,this.authenticating=void 0,this.retryCount+=1,e(t,n)):(this.retryCount=0,[i,a])};return e}};const vl=["disconnected","connecting","connected","failed"],Vs=s.z.enum(vl),Js=s.z.object({status:Vs,error:s.z.instanceof(Error).optional(),message:s.z.string().optional(),clusterKey:s.z.string()}),Tl=s.z.object({clusterKey:s.z.string()}),Dn={clusterKey:"",status:"disconnected",error:void 0,message:"Disconnected"},Ye=class Ye{constructor(e,t=E.seconds(30),n){o(this,"_state");o(this,"pollFrequency",E.seconds(30));o(this,"client");o(this,"name");o(this,"interval");o(this,"onChangeHandlers",[]);this._state={...Dn},this.client=e,this.pollFrequency=t,this.name=n,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(Ye.ENDPOINT,{},s.z.object({}),Tl);if(i!=null)throw i;this._state.status="connected",this._state.message=`Connected to ${this.name??"cluster"}`,this._state.clusterKey=n.clusterKey}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)}};o(Ye,"ENDPOINT","/connectivity/check"),o(Ye,"DEFAULT",Dn),o(Ye,"connectionStateZ",Js);let wt=Ye;const Ol=Object.freeze(Object.defineProperty({__proto__:null,Checker:wt,state:Js,status:Vs},Symbol.toStringTag,{value:"Module"})),zl=s.z.object({keys:we.array().optional(),bounds:G.z,names:s.z.string().array().optional()}),El=s.z.object({}),Sl="/frame/delete";class Nl{constructor(e){o(this,"client");this.client=e}async delete(e){await w(this.client,Sl,e,zl,El)}}const Mn=r=>{const e=T(r);return e.length===0?null:typeof e[0]=="number"||!isNaN(parseInt(e[0]))?"key":"name"},Zn=(r,e)=>{const t=T(r);if(t.length===e.length)return;const n=Mn(r);throw Mn===null?new C("[Frame] - channel keys or names must be provided when constructing a frame."):new C(`[Frame] - ${n}s and arrays must be the same length.
|
|
22
22
|
Got ${t.length} ${n}s and ${e.length} arrays.`)};class U{constructor(e=[],t=[]){o(this,"columns",[]);o(this,"series",[]);if(e instanceof U){this.columns=e.columns,this.series=e.series;return}if(e instanceof Map){e.forEach((i,a)=>this.push(a,...T(i)));return}if(typeof e=="object"&&!Array.isArray(e)){if("keys"in e&&"series"in e){const i=e,a=i.series.map(c=>Xs(c));Zn(i.keys,a),i.keys.forEach((c,l)=>this.push(c,a[l]))}else Object.entries(e).forEach(([i,a])=>{const c=parseInt(i);if(isNaN(c))this.push(i,...T(a));else return this.push(c,...T(a))});return}if(Array.isArray(e)||["string","number"].includes(typeof e)){const i=T(t),a=T(e);Zn(a,i),i.forEach((c,l)=>this.push(a[l],c));return}throw new C(`[Frame] - invalid frame construction parameters. data parameter ust be a frame
|
|
23
23
|
payload, a list of lazy arrays, a lazy array, a map, or a record keyed by channel
|
|
24
|
-
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 pe("colType is not key");return this.columns??[]}get uniqueKeys(){return An(this.keys)}get names(){if(this.colType==="key")throw new pe("colType is not name");return this.columns??[]}get uniqueNames(){return An(this.names)}get uniqueColumns(){return this.colType==="key"?this.uniqueKeys:this.uniqueNames}toPayload(){return{series:this.series.map(e=>Qs(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=O.min(...this.series.map(a=>a.timeRange.start)),i=O.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 Ns(this.series.filter((t,n)=>this.columns[n]===e))}push(e,...t){if(e instanceof U){if(this.colType!==null&&e.colType!==this.colType)throw new C("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 C("keyVariant must match");if(typeof e!="string"&&this.colType==="name")throw new C("keyVariant must match");this.columns.push(...Array.from({length:t.length},()=>e))}}concat(e){return new U([...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 U;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 U;return this.columns.forEach((n,i)=>{const a=this.series[i];e(n,a,i)&&t.push(n,a)}),t}get byteLength(){return new ft(this.series.reduce((e,t)=>e.add(t.byteLength),ft.ZERO))}get length(){return this.series.reduce((e,t)=>e+t.length,0)}}const Hs=s.z.object({timeRange:G.z.optional(),alignment:s.z.bigint().or(s.z.string().transform(r=>BigInt(r))).optional(),dataType:z.z,data:s.z.string().transform(r=>new Uint8Array(atob(r).split("").map(e=>e.charCodeAt(0))).buffer)}),Ht=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(()=>[]),Hs.array().optional().default([])])}),Xs=r=>{const{dataType:e,data:t,timeRange:n,alignment:i}=r;return new Oe({data:t,dataType:e,timeRange:n,glBufferUsage:"static",alignment:i})},Qs=r=>({timeRange:r._timeRange,dataType:r.dataType,data:new Uint8Array(r.data.buffer),alignment:r.alignment});class Xt{constructor(e){o(this,"adapter");o(this,"retriever");o(this,"keys");this.retriever=e,this.adapter=null,this.keys=[]}static async open(e,t){const n=new Xt(e);return await n.update(t),n}async update(e){const{variant:t,normalized:n}=ye(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(c=>{const l=i.find(u=>u.name===c);if(l==null)throw new Error(`Channel ${c} 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 _r{constructor(e){o(this,"adapter");o(this,"retriever");o(this,"keys");this.retriever=e,this.adapter=null,this.keys=[]}static async open(e,t){const n=new _r(e);return await n.update(t),n}async update(e){const t=await Ws(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 adapt(e,t){if(typeof e=="string"||typeof e=="number"){if(t==null)throw new C(`
|
|
24
|
+
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 pe("colType is not key");return this.columns??[]}get uniqueKeys(){return An(this.keys)}get names(){if(this.colType==="key")throw new pe("colType is not name");return this.columns??[]}get uniqueNames(){return An(this.names)}get uniqueColumns(){return this.colType==="key"?this.uniqueKeys:this.uniqueNames}toPayload(){return{series:this.series.map(e=>Qs(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=O.min(...this.series.map(a=>a.timeRange.start)),i=O.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 Ns(this.series.filter((t,n)=>this.columns[n]===e))}push(e,...t){if(e instanceof U){if(this.colType!==null&&e.colType!==this.colType)throw new C("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 C("keyVariant must match");if(typeof e!="string"&&this.colType==="name")throw new C("keyVariant must match");this.columns.push(...Array.from({length:t.length},()=>e))}}concat(e){return new U([...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 U;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 U;return this.columns.forEach((n,i)=>{const a=this.series[i];e(n,a,i)&&t.push(n,a)}),t}get byteLength(){return new ft(this.series.reduce((e,t)=>e.add(t.byteLength),ft.ZERO))}get length(){return this.series.reduce((e,t)=>e+t.length,0)}}const Hs=s.z.object({timeRange:G.z.optional(),alignment:s.z.bigint().or(s.z.string().transform(r=>BigInt(r))).optional(),dataType:z.z,data:s.z.string().transform(r=>new Uint8Array(atob(r).split("").map(e=>e.charCodeAt(0))).buffer)}),Ht=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(()=>[]),Hs.array().optional().default([])])}),Xs=r=>{const{dataType:e,data:t,timeRange:n,alignment:i}=r;return new Oe({data:t,dataType:e,timeRange:n,glBufferUsage:"static",alignment:i})},Qs=r=>({timeRange:r._timeRange,dataType:r.dataType,data:new Uint8Array(r.data.buffer),alignment:r.alignment});class Xt{constructor(e){o(this,"adapter");o(this,"retriever");o(this,"keys");this.retriever=e,this.adapter=null,this.keys=[]}static async open(e,t){const n=new Xt(e);return await n.update(t),n}async update(e){const{variant:t,normalized:n}=ye(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(c=>{const l=i.find(u=>u.name===c);if(l==null)throw new Error(`Channel ${c} 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 _r{constructor(e){o(this,"adapter");o(this,"retriever");o(this,"keys");this.retriever=e,this.adapter=null,this.keys=[]}static async open(e,t){const n=new _r(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 Ws(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 C(`
|
|
25
25
|
Received a single channel name or key but no series.
|
|
26
26
|
`);if(Array.isArray(t)){if(t.some(u=>u instanceof Oe||Array.isArray(u)))throw new C(`
|
|
27
27
|
Received a single channel name or key but multiple series.
|
|
@@ -34,4 +34,4 @@
|
|
|
34
34
|
`);const p=new Oe({data:t[u],dataType:f.dataType});c.push(f.key),l.push(p)}return new U(c,l)}if(e instanceof U||e instanceof Map){const c=new U(e);if(this.adapter==null)return c;let l=[];return l=c.columns.map(u=>{var p;const f=typeof u=="string"?(p=this.adapter)==null?void 0:p.get(u):u;if(f==null)throw new C(`
|
|
35
35
|
Channel ${u} was not provided in the list of channels when opening the writer
|
|
36
36
|
`);return f}),new U(l,c.series)}const n=[],i=[],a=Object.entries(e);for(let c=0;c<a.length;c++){const[l,u]=a[c],f=await this.fetchChannel(l),p=new Oe({data:u,dataType:f.dataType});n.push(f.key),i.push(p)}return new U(n,i)}}class Gr{constructor(e,t){o(this,"name");o(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.
|
|
37
|
-
Please report this error to the Synnax team. ${JSON.stringify(e)}`),t!=null){if(ge.matches(t))return;throw t}}}closeSend(){this.stream.closeSend()}send(e){const t=this.stream.send(e);if(t!=null)throw t}}const jr=new E(-1);var Kr=(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))(Kr||{}),ei=(r=>(r[r.None=0]="None",r[r.Ack=1]="Ack",r[r.Data=2]="Data",r))(ei||{});const Il=s.z.object({command:s.z.nativeEnum(Kr),span:E.z.optional(),bounds:G.z.optional(),stamp:O.z.optional(),keys:s.z.number().array().optional(),chunkSize:s.z.number().optional()}),kl=s.z.object({variant:s.z.nativeEnum(ei),ack:s.z.boolean(),command:s.z.nativeEnum(Kr),error:Tt.optional().nullable(),frame:Ht.optional()}),dt=class dt{constructor(e,t){o(this,"stream");o(this,"adapter");o(this,"value");this.stream=new Gr("Iterator",e),this.value=new U,this.adapter=t}static async _open(e,t,n,i,a={}){const c=await Xt.open(n,t),l=await i.stream(dt.ENDPOINT,Il,kl),u=new dt(l,c);return await u.execute({command:0,keys:c.keys,bounds:new G(e),chunkSize:a.chunkSize??1e5}),u}async next(e=jr){return await this.execute({command:1,span:new E(e)})}async prev(e=jr){return await this.execute({command:2,span:new E(e)})}async seekFirst(){return await this.execute({command:3})}async seekLast(){return await this.execute({command:4})}async seekLE(e){return await this.execute({command:5,stamp:new O(e)})}async seekGE(e){return await this.execute({command:6,stamp:new O(e)})}async valid(){return await this.execute({command:7})}async close(){await this.stream.closeAndAck()}[Symbol.asyncIterator](){return new Al(this)}async execute(e){for(this.stream.send(e),this.value=new U;;){const t=await this.stream.receive();if(t.variant===1)return t.ack;this.value.push(this.adapter.adapt(new U(t.frame)))}}};o(dt,"ENDPOINT","/frame/iterate");let qt=dt;class Al{constructor(e){o(this,"iter");o(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 $l=s.z.object({start:O.z.optional(),keys:s.z.number().array()}),Rl=s.z.object({frame:Ht,error:Tt.optional().nullable()}),xl="/frame/stream";class Qt{constructor(e,t){o(this,"stream");o(this,"adapter");this.stream=new Gr("Streamer",e),this.adapter=t}get keys(){return this.adapter.keys}static async _open(e,t,{channels:n,from:i}){const a=await Xt.open(e,n),c=await t.stream(xl,$l,Rl),l=new Qt(c,a);return c.send({start:new O(i),keys:a.keys}),l}async next(){try{return{done:!1,value:await this.read()}}catch(e){if(ge.matches(e))return{done:!0,value:void 0};throw e}}async read(){return this.adapter.adapt(new U((await this.stream.receive()).frame))}async update(e){await this.adapter.update(e),this.stream.send({keys:this.adapter.keys})}close(){this.stream.closeSend()}[Symbol.asyncIterator](){return this}}class zt extends Ar.Observer{constructor(t,n){super(n);o(this,"streamer");o(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 Vr=(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))(Vr||{}),bt=(r=>(r[r.PersistStream=1]="PersistStream",r[r.PersistOnly=2]="PersistOnly",r[r.StreamOnly=3]="StreamOnly",r))(bt||{});const Cl=new E(-1),jl=s.z.object({start:O.z.optional(),controlSubject:_e.subjectZ.optional(),keys:s.z.number().array().optional(),authorities:_e.Authority.z.array().optional(),mode:s.z.nativeEnum(bt).optional(),errOnUnauthorized:s.z.boolean().optional(),enableAutoCommit:s.z.boolean().optional(),autoIndexPersistInterval:E.z.optional()}),Pl=s.z.object({command:s.z.nativeEnum(Vr),config:jl.optional(),frame:Ht.optional()}),Dl=s.z.object({ack:s.z.boolean(),command:s.z.nativeEnum(Vr),error:Tt.optional().nullable()});var fe;let ti=(fe=class{constructor(e,t){o(this,"stream");o(this,"adapter");this.stream=new Gr("Writer",e),this.adapter=t}static async _open(e,t,{channels:n,start:i=O.now(),authorities:a=_e.Authority.Absolute,controlSubject:c,mode:l=1,errOnUnauthorized:u=!1,enableAutoCommit:f=!1,autoIndexPersistInterval:p=E.SECOND}){const g=await _r.open(e,n),P=await t.stream(fe.ENDPOINT,Pl,Dl),j=new fe(P,g);return await j.execute({command:0,config:{start:new O(i),keys:g.keys,controlSubject:c,authorities:T(a),mode:l,errOnUnauthorized:u,enableAutoCommit:f,autoIndexPersistInterval:p}}),j}async write(e,t){const n=await this.adapter.adapt(e,t);return this.stream.send({command:1,frame:n.toPayload()}),!0}async setAuthority(e){return(await this.execute({command:4,config:{keys:Object.keys(e).map(n=>Number(n)),authorities:Object.values(e)}})).ack}async commit(){return this.errorAccumulated?!1:(await this.execute({command:2})).ack}async error(){this.stream.send({command:3});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()}},o(fe,"ENDPOINT","/frame/write"),fe),ri=class{constructor(e,t,n){o(this,"streamClient");o(this,"retriever");o(this,"deleter");this.streamClient=e,this.retriever=n,this.deleter=new Nl(t)}async openIterator(e,t,n){return await qt._open(e,t,this.retriever,this.streamClient,n)}async openWriter(e){return(Array.isArray(e)||typeof e!="object")&&(e={channels:e}),await ti._open(this.retriever,this.streamClient,e)}async openStreamer(e){return(Array.isArray(e)||typeof e!="object")&&(e={channels:e}),await Qt._open(this.retriever,this.streamClient,e)}async write(e,t,n){if(n==null){const a=t,c=await this.openWriter({start:e,channels:Object.keys(a),mode:bt.PersistOnly});try{await c.write(a),await c.commit()}finally{await c.close()}return}const i=await this.openWriter({start:e,channels:t,mode:bt.PersistOnly,errOnUnauthorized:!0,enableAutoCommit:!0,autoIndexPersistInterval:E.MAX});try{await i.write(t,n)}finally{await i.close()}}async read(e,t){const{single:n}=ye(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 U;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}=ye(e);return i==="keys"?await this.deleter.delete({keys:n,bounds:t}):await this.deleter.delete({names:n,bounds:t})}};const Ml=Object.freeze(Object.defineProperty({__proto__:null,ALWAYS_INDEX_PERSIST_ON_AUTO_COMMIT:Cl,AUTO_SPAN:jr,Client:ri,Frame:U,Iterator:qt,ObservableStreamer:zt,Streamer:Qt,Writer:ti,WriterMode:bt,frameZ:Ht,series:Hs,seriesFromPayload:Xs,seriesToPayload:Qs},Symbol.toStringTag,{value:"Module"})),Zl=_e.Authority,Ul=_e.stateZ(s.z.number()),Bl=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 ni extends zt{constructor(t){super(t,n=>{const i=this.codec.decode(n.series[0].buffer);return this.merge(i),[i.transfers,!0]});o(this,"states");o(this,"codec");this.states=new Map,this.codec=new Ke.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 Ll="sy_node_1_control";let si=class{constructor(e){o(this,"framer");this.framer=e}async openStateTracker(){const e=await this.framer.openStreamer(Ll);return new ni(e)}};const ql=Object.freeze(Object.defineProperty({__proto__:null,Authority:Zl,Client:si,StateTracker:ni,stateZ:Ul,transferString:Bl},Symbol.toStringTag,{value:"Module"}));let ii=class{constructor(e,t,n){o(this,"tasks");o(this,"racks");o(this,"devices");this.tasks=e,this.racks=t,this.devices=n}};const Yl=Object.freeze(Object.defineProperty({__proto__:null,Client:ii},Symbol.toStringTag,{value:"Module"})),Je=s.z.number(),er=s.z.object({key:Je,name:s.z.string()}),ai=er.partial({key:!0}),oi="rack",Wl=r=>new x({type:oi,key:r.toString()}),tr=s.z.string(),Et=s.z.object({key:tr,rack:Je,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(r=>r===""?{}:Ke.JSON_CODEC.decodeString(r)))}),ci=Et.extend({properties:s.z.unknown().transform(r=>Ke.JSON_CODEC.encodeString(r))}),li="device",Fl=r=>new x({type:li,key:r.toString()}),He=async(r,e,t,n)=>{const i=await r.openStreamer([e,t]),a=c=>{const l=[];return t!=null&&l.push(...c.get(t).series.flatMap(u=>n("delete",u))),e!=null&&l.push(...c.get(e).series.flatMap(u=>n("set",u))),[l,l.length>0]};return new zt(i,a)},_l=Object.freeze(Object.defineProperty({__proto__:null,openObservable:He},Symbol.toStringTag,{value:"Module"})),Gl="sy_device_set",Kl="sy_device_delete",fr="/hardware/device/retrieve",Vl="/hardware/device/create",Jl="/hardware/device/delete",Hl=s.z.object({devices:ci.array()}),Xl=s.z.object({devices:Et.array()}),Ql=s.z.object({keys:tr.array()}),eu=s.z.object({}),pr=s.z.object({search:s.z.string().optional(),limit:s.z.number().optional(),offset:s.z.number().optional(),keys:tr.array().optional(),names:s.z.string().array().optional(),makes:s.z.string().array().optional()}),gr=s.z.object({devices:Ve(Et)});let ui=class{constructor(e,t){o(this,"type","device");o(this,"client");o(this,"frameClient");this.client=e,this.frameClient=t}async retrieve(e,t){const n=!Array.isArray(e),i=await w(this.client,fr,{keys:T(e),...t},pr,gr);return Jt("Device",e,i.devices,n),n?i.devices[0]:i.devices}async search(e,t){return(await w(this.client,fr,{search:e,...t},pr,gr)).devices}async page(e,t,n){return(await w(this.client,fr,{offset:e,limit:t,...n},pr,gr)).devices}async create(e){const t=!Array.isArray(e),n=await w(this.client,Vl,{devices:T(e)},Hl,Xl);return t?n.devices[0]:n.devices}async delete(e){await w(this.client,Jl,{keys:T(e)},Ql,eu)}async openDeviceTracker(){return await He(this.frameClient,Gl,Kl,tu)}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 tu=(r,e)=>r==="delete"?e.toStrings().map(t=>({variant:r,key:t,value:void 0})):e.parseJSON(Et).map(t=>({variant:r,key:t.key,value:t})),ru=Object.freeze(Object.defineProperty({__proto__:null,Client:ui,DeviceOntologyType:li,deviceKeyZ:tr,deviceZ:Et,newDeviceZ:ci,ontologyID:Fl},Symbol.toStringTag,{value:"Module"})),mr="/hardware/rack/retrieve",nu="/hardware/rack/create",su="/hardware/rack/delete",wr=s.z.object({keys:Je.array().optional(),names:s.z.string().array().optional(),search:s.z.string().optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),br=s.z.object({racks:Ve(er)}),iu=s.z.object({racks:ai.array()}),au=s.z.object({racks:er.array()}),ou=s.z.object({keys:Je.array()}),cu=s.z.object({});let hi=class{constructor(e,t,n){o(this,"type","rack");o(this,"client");o(this,"frameClient");o(this,"tasks");this.client=e,this.frameClient=t,this.tasks=n}async delete(e){await w(this.client,su,{keys:T(e)},ou,cu)}async create(e){const t=!Array.isArray(e),n=await w(this.client,nu,{racks:T(e)},iu,au),i=this.sugar(n.racks);return t?i[0]:i}async search(e){const t=await w(this.client,mr,{search:e},wr,br);return this.sugar(t.racks)}async page(e,t){const n=await w(this.client,mr,{offset:e,limit:t},wr,br);return this.sugar(n.racks)}async retrieve(e){const{variant:t,normalized:n,single:i}=Vt(e,{string:"names",number:"keys"}),a=await w(this.client,mr,{[t]:n},wr,br),c=this.sugar(a.racks);return Jt("Rack",e,c,i),i?c[0]:c}sugar(e){return e.map(({key:t,name:n})=>new yi(t,n,this.tasks))}};class yi{constructor(e,t,n){o(this,"key");o(this,"name");o(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 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 lu=Object.freeze(Object.defineProperty({__proto__:null,Client:hi,Rack:yi,RackOntologyType:oi,newRackZ:ai,ontologyID:Wl,rackKeyZ:Je,rackZ:er},Symbol.toStringTag,{value:"Module"})),Xe=s.z.union([s.z.string(),s.z.bigint().transform(r=>r.toString()),s.z.number().transform(r=>r.toString())]),vt=s.z.object({task:Xe,variant:s.z.string(),key:s.z.string().optional(),details:s.z.record(s.z.unknown()).or(s.z.string().transform(r=>r===""?{}:JSON.parse(r))).or(s.z.array(s.z.unknown())).or(s.z.null())}),rr=s.z.object({key:Xe,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(r=>r===""?{}:Ke.JSON_CODEC.decodeString(r))),state:vt.optional().nullable()}),di=rr.omit({key:!0}).extend({key:Xe.transform(r=>r.toString()).optional(),config:s.z.unknown().transform(r=>Ke.JSON_CODEC.encodeString(r))}),uu=s.z.object({task:Xe,type:s.z.string(),key:s.z.string(),args:s.z.record(s.z.unknown()).or(s.z.string().transform(r=>r===""?{}:JSON.parse(r)))}),fi="task",hu=r=>new x({type:fi,key:r.toString()}),yt="sy_task_state",Un="sy_task_cmd";class pi{constructor(e,t,n,i,a,c=!1,l){o(this,"key");o(this,"name");o(this,"internal");o(this,"type");o(this,"config");o(this,"state");o(this,"frameClient");this.key=e,this.name=t,this.type=n,this.config=i,this.internal=c,l!==null&&(this.state=l),this.frameClient=a}get payload(){return{key:this.key,name:this.name,type:this.type,config:this.config,state:this.state,internal:this.internal}}async executeCommand(e,t){const n=await this.frameClient.openWriter(Un),i=Fo.id();return await n.write(Un,[{task:this.key,type:e,key:i,args:t}]),await n.close(),i}async executeCommandSync(e,t,n){const i=await this.frameClient.openStreamer(yt),a=await this.executeCommand(e,t);let c;const l=new Promise(u=>setTimeout(()=>u(!1),new E(n).milliseconds));for(;;){const u=await Promise.any([i.read(),l]);if(u===!1)throw new Error("Command timed out");const f=vt.safeParse(u.at(-1).sy_task_state);if(f.success){if(c=f.data,c.key===a)break}else console.error(f.error)}return i.close(),c}async openStateObserver(){return new zt(await this.frameClient.openStreamer(yt),e=>{const t=e.get(yt);if(t.length===0)return[null,!1];const n=vt.safeParse(t.at(-1));if(!n.success)return[null,!1];const i=n.data;return i.task!==this.key?[null,!1]:[i,!0]})}}const yu=s.z.object({rack:Je.optional(),keys:s.z.string().array().optional(),names:s.z.string().array().optional(),offset:s.z.number().optional(),limit:s.z.number().optional(),includeState:s.z.boolean().optional()}),du=s.z.object({tasks:Ve(rr)}),fu="/hardware/task/retrieve",pu="/hardware/task/create",gu="/hardware/task/delete",mu=s.z.object({tasks:di.array()}),wu=s.z.object({tasks:rr.array()}),bu=s.z.object({keys:Xe.array()}),vu=s.z.object({});let gi=class{constructor(e,t){o(this,"type","task");o(this,"client");o(this,"frameClient");this.client=e,this.frameClient=t}async create(e){const t=!Array.isArray(e),n=await w(this.client,pu,{tasks:T(e)},mu,wu),i=this.sugar(n.tasks);return t?i[0]:i}async delete(e){await w(this.client,gu,{keys:T(e)},bu,vu)}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}=Vt(e,{number:"rack",string:"keys"},{convertNumericStrings:!1}),c={...t};a==="rack"?c.rack=e:c.keys=i;const l=await this.execRetrieve(c),u=this.sugar(l);return n&&a!=="rack"?u[0]:u}async retrieveByName(e,t){const n=await this.execRetrieve({names:[e],rack:t});return Jt("Task",e,n,!0),this.sugar(n)[0]}async execRetrieve(e){return(await w(this.client,fu,e,yu,du)).tasks}sugar(e){return e.map(({key:t,name:n,type:i,config:a,state:c,internal:l})=>new pi(t,n,i,a,this.frameClient,l,c))}async openTracker(){return await He(this.frameClient,"sy_task_set","sy_task_delete",(e,t)=>Array.from(t).map(n=>({variant:e,key:n.toString(),value:n.toString()})))}async openStateObserver(){return new zt(await this.frameClient.openStreamer(yt),e=>{const t=e.get(yt);if(t.length===0)return[null,!1];const n=vt.safeParse(t.at(-1));return n.success?[n.data,!0]:[null,!1]})}};const Tu=Object.freeze(Object.defineProperty({__proto__:null,Client:gi,DeviceOntologyType:fi,Task:pi,commandZ:uu,newTaskZ:di,ontologyID:hu,stateZ:vt,taskKeyZ:Xe,taskZ:rr},Symbol.toStringTag,{value:"Module"})),Qe=s.z.string().uuid(),St=s.z.object({key:Qe,name:s.z.string().min(1),color:s.z.string()}),mi="label",Ou=r=>new x({type:mi,key:r}),zu=s.z.object({keys:Qe.array().optional(),for:H.optional(),search:s.z.string().optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),Eu=s.z.object({labels:St.array().optional().default([])});var ze;let wi=(ze=class{constructor(e){o(this,"client");this.client=e}async retrieve(e){const t=T(e);return await this.execute({keys:t})}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(ze.ENDPOINT,e,zu,Eu);if(n!=null)throw n;return t.labels}},o(ze,"ENDPOINT","/label/retrieve"),ze);const bi=St.extend({key:Qe.optional()}),Su=s.z.object({labels:bi.array()}),Nu=s.z.object({labels:St.array()}),Iu=s.z.object({keys:Qe.array()}),vi=s.z.object({id:H,labels:Qe.array()}),ku=vi,vr=s.z.object({}),Au="/label/create",$u="/label/delete",Ru="/label/set",xu="/label/remove";let Ti=class{constructor(e){o(this,"client");this.client=e}async create(e){return(await w(this.client,Au,{labels:T(e)},Su,Nu)).labels}async delete(e){await w(this.client,$u,{keys:T(e)},Iu,vr)}async set(e,t){await w(this.client,Ru,{id:e,labels:t},vi,vr)}async remove(e,t){await w(this.client,xu,{id:e,labels:t},ku,vr)}};const Cu="sy_label_set",ju="sy_label_delete";let Oi=class{constructor(e,t){o(this,"type","label");o(this,"retriever");o(this,"writer");o(this,"frameClient");this.writer=new Ti(e),this.retriever=new wi(e),this.frameClient=t}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(e)}async label(e,t){await this.writer.set(e,t)}async removeLabels(e,t){await this.writer.remove(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 He(this.frameClient,Cu,ju,Pu)}};const Pu=(r,e)=>r==="delete"?e.toUUIDs().map(t=>({variant:r,key:t})):e.parseJSON(St).map(t=>({variant:r,key:t.key,value:t})),Du=Object.freeze(Object.defineProperty({__proto__:null,Client:Oi,LabelOntologyType:mi,Retriever:wi,Writer:Ti,keyZ:Qe,labelZ:St,newLabelPayloadZ:bi,ontologyID:Ou},Symbol.toStringTag,{value:"Module"})),K=s.z.string().uuid(),et=s.z.object({key:K,name:s.z.string().min(1),timeRange:G.z,color:s.z.string().optional()}),zi=et.extend({key:s.z.string().uuid().optional()}),Ei=r=>{const e=T(r);if(e.length===0)throw new Error("Range params must not be empty");const t=K.safeParse(e[0]).success;return{single:!Array.isArray(r),variant:t?"keys":"names",normalized:e,actual:r}},Si="range",Ni="range-alias",Mu=r=>new x({type:Si,key:r}),Zu=r=>new x({type:Ni,key:r}),Uu=s.z.object({}),Bu=s.z.object({range:et}),Lu=s.z.object({range:K}),qu=s.z.object({range:K}),Yu=s.z.object({}),Wu="/range/set-active",Fu="/range/retrieve-active",_u="/range/clear-active";class Gu{constructor(e){o(this,"client");this.client=e}async setActive(e){await w(this.client,Wu,{range:e},Lu,Uu)}async retrieveActive(){const[e,t]=await this.client.send(Fu,{},s.z.object({}),Bu);if(X.matches(t))return null;if(t!=null)throw t;return e.range}async clearActive(e){await w(this.client,_u,{range:e},qu,Yu)}}const Ku="sy_range_alias_set",Vu="sy_range_alias_delete",Ju=s.z.object({range:K,aliases:s.z.string().array()}),Hu=s.z.object({aliases:s.z.record(s.z.string(),we)}),Xu=s.z.object({range:K,aliases:s.z.record(we.or(s.z.string()),s.z.string())}),Qu=s.z.unknown(),eh=s.z.object({range:K,channels:we.array()}),th=s.z.unknown(),rh=s.z.object({range:K}),nh=s.z.object({aliases:s.z.record(s.z.string(),s.z.string())}),ae=class ae{constructor(e,t,n){o(this,"frameClient");o(this,"cache",new Map);o(this,"client");o(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 c=this.cache.get(e);if(c!=null)return c;t.push(e)}else e.forEach(c=>{const l=this.cache.get(c);l!=null?i[c]=l:t.push(c)});if(t.length===0)return i;const a=await w(this.client,ae.RESOLVE_ENDPOINT,{range:this.rangeKey,aliases:t},Ju,Hu);return Object.entries(a.aliases).forEach(([c,l])=>this.cache.set(c,l)),n?a.aliases[t[0]]:{...i,...a.aliases}}async set(e){await w(this.client,ae.SET_ENDPOINT,{range:this.rangeKey,aliases:e},Xu,Qu)}async list(){return(await w(this.client,ae.LIST_ENDPOINT,{range:this.rangeKey},rh,nh)).aliases}async delete(e){await w(this.client,ae.DELETE_ENDPOINT,{range:this.rangeKey,channels:e},eh,th)}async openChangeTracker(){return await He(this.frameClient,Ku,Vu,ah(this.rangeKey))}};o(ae,"SET_ENDPOINT","/range/alias/set"),o(ae,"RESOLVE_ENDPOINT","/range/alias/resolve"),o(ae,"LIST_ENDPOINT","/range/alias/list"),o(ae,"DELETE_ENDPOINT","/range/alias/delete");let Pr=ae;const sh=s.z.object({range:K,channel:we,alias:s.z.string()}),ih="---",ah=r=>(e,t)=>e==="delete"?t.toStrings().filter(n=>n.split(ih)[0]===r).map(n=>({variant:e,key:n,value:void 0})):t.parseJSON(sh).map(n=>({variant:e,key:n.alias,value:n})),oh=s.z.object({range:K,keys:s.z.string().array()}),ch=s.z.object({pairs:s.z.record(s.z.string(),s.z.string())}),lh=s.z.object({range:K,pairs:s.z.record(s.z.string(),s.z.string())}),uh=s.z.object({range:K,keys:s.z.string().array()}),de=class de{constructor(e,t){o(this,"rangeKey");o(this,"client");this.rangeKey=e,this.client=t}async get(e){const[t,n]=await this.client.send(de.GET_ENDPOINT,{range:this.rangeKey,keys:T(e)},oh,ch);if(n!=null)throw n;return Array.isArray(e)?t.pairs:t.pairs[e]}async list(){return this.get([])}async set(e,t=""){await w(this.client,de.SET_ENDPOINT,{range:this.rangeKey,pairs:Ur(e)?e:{[e]:t}},lh,s.z.unknown())}async delete(e){await w(this.client,de.DELETE_ENDPOINT,{range:this.rangeKey,keys:T(e)},uh,s.z.unknown())}};o(de,"GET_ENDPOINT","/range/kv/get"),o(de,"SET_ENDPOINT","/range/kv/set"),o(de,"DELETE_ENDPOINT","/range/kv/delete");let Dr=de;const Tr=r=>new x({type:"range",key:r});class Ii{constructor(e,t=G.ZERO,n,i,a,c,l,u,f){o(this,"key");o(this,"name");o(this,"kv");o(this,"timeRange");o(this,"color");o(this,"channels");o(this,"aliaser");o(this,"frameClient");o(this,"labelClient");this.key=n,this.name=e,this.timeRange=t,this.frameClient=a,this.color=i,this.kv=c,this.aliaser=l,this.channels=u,this.labelClient=f}async setAlias(e,t){const n=await this.channels.retrieve(e);if(n.length===0)throw new X(`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 openAliasTracker(){return await this.aliaser.openChangeTracker()}async read(e){return await this.frameClient.read(this.timeRange,e)}async labels(){return await this.labelClient.retrieveFor(Tr(this.key))}async addLabel(...e){await this.labelClient.label(Tr(this.key),e)}async removeLabel(...e){await this.labelClient.removeLabels(Tr(this.key),e)}}const hh=s.z.object({keys:K.array().optional(),names:s.z.array(s.z.string()).optional(),term:s.z.string().optional(),overlapsWith:G.z.optional()}),yh="/range/retrieve",dh=s.z.object({ranges:Ve(et)});let ki=class{constructor(e,t,n,i,a){o(this,"type","range");o(this,"frameClient");o(this,"writer");o(this,"unaryClient");o(this,"channels");o(this,"active");o(this,"labelClient");this.frameClient=e,this.writer=t,this.unaryClient=n,this.channels=i,this.active=new Gu(n),this.labelClient=a}async create(e){const t=!Array.isArray(e),n=this.sugar(await this.writer.create(T(e)));return t?n[0]:n}async rename(e,t){await this.writer.rename(e,t)}async delete(e){await this.writer.delete(T(e))}async search(e){return this.sugar(await this.execRetrieve({term:e}))}async page(){return[]}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}=Ei(e),c=await this.execRetrieve({[i]:a});if(!t)return c;if(c.length===0)throw new Ie(`range matching ${n} not found`);if(c.length>1)throw new ke(`multiple ranges matching ${n} found`);return c[0]}async execRetrieve(e){const{ranges:t}=await w(this.unaryClient,yh,e,hh,dh);return this.sugar(t)}async setActive(e){await this.active.setActive(e)}async retrieveActive(){const e=await this.active.retrieveActive();return e==null?null:this.sugar([e])[0]}async clearActive(e){await this.active.clearActive(e)}sugar(e){return e.map(t=>new Ii(t.name,t.timeRange,t.key,t.color,this.frameClient,new Dr(t.key,this.unaryClient),new Pr(t.key,this.frameClient,this.unaryClient),this.channels,this.labelClient))}async openTracker(){return await He(this.frameClient,"sy_range_set","sy_range_delete",(e,t)=>e==="delete"?t.toStrings().map(i=>({variant:e,key:i,value:void 0})):this.sugar(t.parseJSON(et)).map(i=>({variant:e,key:i.key,value:i})))}};const fh=s.z.object({ranges:et.array()}),ph=s.z.object({ranges:zi.array()}),gh=s.z.object({keys:K.array()}),mh=s.z.object({}),wh=s.z.object({key:K,name:s.z.string()}),bh=s.z.object({}),vh="/range/create",Th="/range/delete",Oh="/range/rename";let Ai=class{constructor(e){o(this,"client");this.client=e}async rename(e,t){await w(this.client,Oh,{key:e,name:t},wh,bh)}async create(e){return(await w(this.client,vh,{ranges:e},ph,fh)).ranges}async delete(e){await w(this.client,Th,{keys:e},gh,mh)}};const zh=Object.freeze(Object.defineProperty({__proto__:null,Client:ki,Range:Ii,RangeAliasOntologyType:Ni,RangeOntologyType:Si,Writer:Ai,analyzeParams:Ei,keyZ:K,newPayloadZ:zi,payloadZ:et,rangeAliasOntologyID:Zu,rangeOntologyID:Mu},Symbol.toStringTag,{value:"Module"})),Eh="/api/v1/";class Sh{constructor(e,t=!1){o(this,"url");o(this,"unary");o(this,"stream");o(this,"secure");this.secure=t,this.url=e.child(Eh);const n=new Ke.JSONCodec;this.unary=new Fa(this.url,n,this.secure),this.stream=new eo(this.url,n,this.secure)}use(...e){this.unary.use(...e),this.stream.use(...e)}}const Jr=s.z.string().uuid(),Hr=s.z.object({key:s.z.string(),name:s.z.string(),data:Lr.or(s.z.string().transform(r=>JSON.parse(r)))}),Nh=s.z.object({keys:s.z.string().array()}),Ih=s.z.object({linePlots:Hr.array()});let kh=class{constructor(e){o(this,"ENDPOINT","/workspace/lineplot/retrieve");o(this,"client");this.client=e}async retrieve(e){const t=T(e);return(await w(this.client,this.ENDPOINT,{keys:t},Nh,Ih)).linePlots}};const be=s.z.string().uuid(),$i=r=>JSON.parse(r),Xr=s.z.object({name:s.z.string(),key:be,layout:Lr.or(s.z.string().transform(r=>$i(r)))}),Qr=Xr.omit({layout:!0}).extend({layout:s.z.string().transform(r=>$i(r))}),Ri="workspace",Ah=r=>new x({type:Ri,key:r}),$h=Hr.partial({key:!0}).transform(r=>({...r,data:JSON.stringify(r.data)})),Rh=s.z.object({workspace:be,linePlots:$h.array()}),xh=s.z.object({linePlots:Hr.array()}),Ch=s.z.object({keys:Jr.array()}),jh=s.z.object({}),Ph=s.z.object({key:Jr,name:s.z.string()}),Dh=s.z.object({}),Mh=s.z.object({key:Jr,data:s.z.string()}),Zh=s.z.object({}),Uh="/workspace/lineplot/create",Bh="/workspace/lineplot/delete",Lh="/workspace/lineplot/rename",qh="/workspace/lineplot/set-data";let Yh=class{constructor(e){o(this,"client");this.client=e}async create(e,t){const n={...t,data:JSON.stringify(t.data)};return(await w(this.client,Uh,{workspace:e,linePlots:[n]},Rh,xh)).linePlots[0]}async delete(e){const t=T(e);await w(this.client,Bh,{keys:t},Ch,jh)}async rename(e,t){await w(this.client,Lh,{key:e,name:t},Ph,Dh)}async setData(e,t){await w(this.client,qh,{key:e,data:JSON.stringify(t)},Mh,Zh)}},Wh=class{constructor(e){o(this,"writer");o(this,"retriever");this.writer=new Yh(e),this.retriever=new kh(e)}async create(e,t){return await this.writer.create(e,t)}async rename(e,t){await this.writer.rename(e,t)}async setData(e,t){await this.writer.setData(e,t)}async retrieve(e){const t=Array.isArray(e),n=await this.retriever.retrieve(e);return t?n:n[0]}async delete(e){await this.writer.delete(e)}};const Fh=s.z.object({keys:be.array().optional(),search:s.z.string().optional(),author:s.z.string().uuid().optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),_h=s.z.object({workspaces:Ve(Qr)});var Ee;let Gh=(Ee=class{constructor(e){o(this,"client");this.client=e}async retrieve(e){const t=T(e);return await this.execute({keys:t})}async retrieveByAuthor(e){return await this.execute({author: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){return(await w(this.client,Ee.ENDPOINT,e,Fh,_h)).workspaces}},o(Ee,"ENDPOINT","/workspace/retrieve"),Ee);const nr=s.z.string().uuid(),Kh=s.z.object({key:s.z.string(),name:s.z.string(),data:Lr.or(s.z.string().transform(r=>JSON.parse(r))),snapshot:s.z.boolean()}),en=s.z.object({key:s.z.string(),name:s.z.string(),snapshot:s.z.boolean(),data:s.z.string().transform(r=>JSON.parse(r))}),Vh=s.z.object({keys:s.z.string().array()}),Jh=s.z.object({schematics:en.array()});class Hh{constructor(e){o(this,"ENDPOINT","/workspace/schematic/retrieve");o(this,"client");this.client=e}async retrieve(e){return(await w(this.client,this.ENDPOINT,{keys:T(e)},Vh,Jh)).schematics}}const Xh=Kh.partial({key:!0,snapshot:!0}).transform(r=>({...r,data:JSON.stringify(r.data)})),Qh=s.z.object({workspace:be,schematics:Xh.array()}),ey=s.z.object({schematics:en.array()}),ty=s.z.object({keys:nr.array()}),ry=s.z.object({}),ny=s.z.object({key:nr,name:s.z.string()}),Bn=s.z.object({}),sy=s.z.object({key:nr,data:s.z.string()});s.z.object({});const iy=s.z.object({key:nr,name:s.z.string(),snapshot:s.z.boolean()}),ay=s.z.object({schematic:en}),oy="/workspace/schematic/create",cy="/workspace/schematic/delete",ly="/workspace/schematic/rename",uy="/workspace/schematic/set-data",hy="/workspace/schematic/copy";let yy=class{constructor(e){o(this,"client");this.client=e}async create(e,t){const n={...t,data:JSON.stringify(t.data)};return(await w(this.client,oy,{workspace:e,schematics:[n]},Qh,ey)).schematics[0]}async copy(e,t,n){return(await w(this.client,hy,{key:e,name:t,snapshot:n},iy,ay)).schematic}async delete(e){const t=T(e);await w(this.client,cy,{keys:t},ty,ry)}async rename(e,t){await w(this.client,ly,{key:e,name:t},ny,Bn)}async setData(e,t){await w(this.client,uy,{key:e,data:JSON.stringify(t)},sy,Bn)}},dy=class{constructor(e){o(this,"writer");o(this,"retriever");this.writer=new yy(e),this.retriever=new Hh(e)}async create(e,t){return await this.writer.create(e,t)}async rename(e,t){await this.writer.rename(e,t)}async setData(e,t){await this.writer.setData(e,t)}async retrieve(e){const t=Array.isArray(e),n=await this.retriever.retrieve(e);return t?n:n[0]}async delete(e){await this.writer.delete(e)}async copy(e,t,n){return await this.writer.copy(e,t,n)}};const fy=Xr.partial({key:!0}).transform(r=>({...r,layout:JSON.stringify(r.layout)})),py=s.z.object({workspaces:fy.array()}),gy=s.z.object({workspaces:Qr.array()}),my=s.z.object({keys:be.array()}),wy=s.z.object({}),by=s.z.object({key:be,name:s.z.string()}),vy=s.z.object({}),Ty=s.z.object({key:be,layout:s.z.string()}),Oy=s.z.object({}),zy="/workspace/create",Ey="/workspace/delete",Sy="/workspace/rename",Ny="/workspace/set-layout";class Iy{constructor(e){o(this,"client");this.client=e}async create(e){return(await w(this.client,zy,{workspaces:T(e)},py,gy)).workspaces}async delete(e){await w(this.client,Ey,{keys:T(e)},my,wy)}async rename(e,t){await w(this.client,Sy,{key:e,name:t},by,vy)}async setLayout(e,t){await w(this.client,Ny,{key:e,layout:JSON.stringify(t)},Ty,Oy)}}class xi{constructor(e){o(this,"type","workspace");o(this,"schematic");o(this,"linePlot");o(this,"retriever");o(this,"writer");this.schematic=new dy(e),this.linePlot=new Wh(e),this.retriever=new Gh(e),this.writer=new Iy(e)}async search(e){return await this.retriever.search(e)}async retrieveByAuthor(e){return await this.retriever.retrieveByAuthor(e)}async retrieve(e){const t=Array.isArray(e),n=await this.retriever.retrieve(e);return t?n:n[0]}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 rename(e,t){await this.writer.rename(e,t)}async setLayout(e,t){await this.writer.setLayout(e,t)}async delete(...e){await this.writer.delete(e)}}const ky=Object.freeze(Object.defineProperty({__proto__:null,Client:xi,WorkspaceOntologyType:Ri,keyZ:be,ontologyID:Ah,workspaceRemoteZ:Qr,workspaceZ:Xr},Symbol.toStringTag,{value:"Module"})),Ci=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().optional(),password:s.z.string().optional(),connectivityPollFrequency:E.z.default(E.seconds(30)),secure:s.z.boolean().optional().default(!1),name:s.z.string().optional()});class ji extends ri{constructor(t){const n=Ci.parse(t),{host:i,port:a,username:c,password:l,connectivityPollFrequency:u,secure:f}=n,p=new Sh(new lc({host:i,port:Number(a)}),f);p.use(mc);let g;c!=null&&l!=null&&(g=new bl(p.unary,{username:c,password:l}),p.use(g.middleware()));const P=new qr(new mt(p.unary)),j=new _s(p.unary,P);super(p.stream,p.unary,P);o(this,"createdAt");o(this,"props");o(this,"ranges");o(this,"channels");o(this,"auth");o(this,"user");o(this,"access");o(this,"connectivity");o(this,"ontology");o(this,"workspaces");o(this,"labels");o(this,"hardware");o(this,"control");o(this,"transport");this.createdAt=O.now(),this.props=n,this.auth=g,this.transport=p,this.channels=new Fs(this,P,p.unary,j),this.connectivity=new wt(p.unary,u,n.name),this.control=new si(this),this.ontology=new Us(p.unary,this);const Q=new Ai(this.transport.unary);this.labels=new Oi(this.transport.unary,this),this.ranges=new ki(this,Q,this.transport.unary,P,this.labels),this.access=new fl(this.transport.unary),this.user=new gl(this.transport.unary),this.workspaces=new xi(this.transport.unary);const D=new ui(this.transport.unary,this),tn=new gi(this.transport.unary,this),Pi=new hi(this.transport.unary,this,tn);this.hardware=new ii(tn,Pi,D)}get key(){return this.createdAt.valueOf().toString()}close(){this.connectivity.stopChecking()}}o(ji,"connectivity",wt);const Ay=_e.Authority;exports.AuthError=Ne;exports.Authority=Ay;exports.Channel=Yr;exports.ContiguityError=xr;exports.DataType=z;exports.Density=_;exports.Frame=U;exports.MultiSeries=Ns;exports.MultipleFoundError=ke;exports.NotFoundError=Ie;exports.QueryError=X;exports.Rate=Gt;exports.RouteError=gt;exports.Series=Oe;exports.Synnax=ji;exports.TimeRange=G;exports.TimeSpan=E;exports.TimeStamp=O;exports.UnexpectedError=pe;exports.ValidationError=C;exports.channel=nl;exports.connection=Ol;exports.control=ql;exports.device=ru;exports.framer=Ml;exports.hardware=Yl;exports.label=Du;exports.ontology=Pc;exports.rack=lu;exports.ranger=zh;exports.signals=_l;exports.synnaxPropsZ=Ci;exports.task=Tu;exports.workspace=ky;
|
|
37
|
+
Please report this error to the Synnax team. ${JSON.stringify(e)}`),t!=null){if(ge.matches(t))return;throw t}}}closeSend(){this.stream.closeSend()}send(e){const t=this.stream.send(e);if(t!=null)throw t}}const jr=new E(-1);var Kr=(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))(Kr||{}),ei=(r=>(r[r.None=0]="None",r[r.Ack=1]="Ack",r[r.Data=2]="Data",r))(ei||{});const Il=s.z.object({command:s.z.nativeEnum(Kr),span:E.z.optional(),bounds:G.z.optional(),stamp:O.z.optional(),keys:s.z.number().array().optional(),chunkSize:s.z.number().optional()}),kl=s.z.object({variant:s.z.nativeEnum(ei),ack:s.z.boolean(),command:s.z.nativeEnum(Kr),error:Tt.optional().nullable(),frame:Ht.optional()}),dt=class dt{constructor(e,t){o(this,"stream");o(this,"adapter");o(this,"value");this.stream=new Gr("Iterator",e),this.value=new U,this.adapter=t}static async _open(e,t,n,i,a={}){const c=await Xt.open(n,t),l=await i.stream(dt.ENDPOINT,Il,kl),u=new dt(l,c);return await u.execute({command:0,keys:c.keys,bounds:new G(e),chunkSize:a.chunkSize??1e5}),u}async next(e=jr){return await this.execute({command:1,span:new E(e)})}async prev(e=jr){return await this.execute({command:2,span:new E(e)})}async seekFirst(){return await this.execute({command:3})}async seekLast(){return await this.execute({command:4})}async seekLE(e){return await this.execute({command:5,stamp:new O(e)})}async seekGE(e){return await this.execute({command:6,stamp:new O(e)})}async valid(){return await this.execute({command:7})}async close(){await this.stream.closeAndAck()}[Symbol.asyncIterator](){return new Al(this)}async execute(e){for(this.stream.send(e),this.value=new U;;){const t=await this.stream.receive();if(t.variant===1)return t.ack;this.value.push(this.adapter.adapt(new U(t.frame)))}}};o(dt,"ENDPOINT","/frame/iterate");let qt=dt;class Al{constructor(e){o(this,"iter");o(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 $l=s.z.object({start:O.z.optional(),keys:s.z.number().array()}),Rl=s.z.object({frame:Ht,error:Tt.optional().nullable()}),xl="/frame/stream";class Qt{constructor(e,t){o(this,"stream");o(this,"adapter");this.stream=new Gr("Streamer",e),this.adapter=t}get keys(){return this.adapter.keys}static async _open(e,t,{channels:n,from:i}){const a=await Xt.open(e,n),c=await t.stream(xl,$l,Rl),l=new Qt(c,a);return c.send({start:new O(i),keys:a.keys}),l}async next(){try{return{done:!1,value:await this.read()}}catch(e){if(ge.matches(e))return{done:!0,value:void 0};throw e}}async read(){return this.adapter.adapt(new U((await this.stream.receive()).frame))}async update(e){await this.adapter.update(e),this.stream.send({keys:this.adapter.keys})}close(){this.stream.closeSend()}[Symbol.asyncIterator](){return this}}class zt extends Ar.Observer{constructor(t,n){super(n);o(this,"streamer");o(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 Vr=(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))(Vr||{}),bt=(r=>(r[r.PersistStream=1]="PersistStream",r[r.Persist=2]="Persist",r[r.Stream=3]="Stream",r))(bt||{});const Cl=r=>{switch(r){case"persist":return 2;case"stream":return 3;case"persistStream":return 1;default:return r}},jl=new E(-1),Pl=s.z.object({start:O.z.optional(),controlSubject:_e.subjectZ.optional(),keys:s.z.number().array().optional(),authorities:_e.Authority.z.array().optional(),mode:s.z.nativeEnum(bt).optional(),errOnUnauthorized:s.z.boolean().optional(),enableAutoCommit:s.z.boolean().optional(),autoIndexPersistInterval:E.z.optional()}),Dl=s.z.object({command:s.z.nativeEnum(Vr),config:Pl.optional(),frame:Ht.optional()}),Ml=s.z.object({ack:s.z.boolean(),command:s.z.nativeEnum(Vr),error:Tt.optional().nullable()});var fe;let ti=(fe=class{constructor(e,t){o(this,"stream");o(this,"adapter");this.stream=new Gr("Writer",e),this.adapter=t}static async _open(e,t,{channels:n,start:i=O.now(),authorities:a=_e.Authority.Absolute,controlSubject:c,mode:l=1,errOnUnauthorized:u=!1,enableAutoCommit:f=!1,autoIndexPersistInterval:p=E.SECOND}){const g=await _r.open(e,n),P=await t.stream(fe.ENDPOINT,Dl,Ml),j=new fe(P,g);return await j.execute({command:0,config:{start:new O(i),keys:g.keys,controlSubject:c,authorities:T(a),mode:Cl(l),errOnUnauthorized:u,enableAutoCommit:f,autoIndexPersistInterval:p}}),j}async write(e,t){const n=await this.adapter.adapt(e,t);return this.stream.send({command:1,frame:n.toPayload()}),!0}async setAuthority(e,t){let n={keys:[],authorities:[]};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(c=>Number(c)),authorities:Object.values(a)}}return(await this.execute({command:4,config:n})).ack}async commit(){return this.errorAccumulated?!1:(await this.execute({command:2})).ack}async error(){this.stream.send({command:3});const 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()}},o(fe,"ENDPOINT","/frame/write"),fe),ri=class{constructor(e,t,n){o(this,"streamClient");o(this,"retriever");o(this,"deleter");this.streamClient=e,this.retriever=n,this.deleter=new Nl(t)}async openIterator(e,t,n){return await qt._open(e,t,this.retriever,this.streamClient,n)}async openWriter(e){return(Array.isArray(e)||typeof e!="object")&&(e={channels:e}),await ti._open(this.retriever,this.streamClient,e)}async openStreamer(e){return(Array.isArray(e)||typeof e!="object")&&(e={channels:e}),await Qt._open(this.retriever,this.streamClient,e)}async write(e,t,n){if(n==null){const a=t,c=await this.openWriter({start:e,channels:Object.keys(a),mode:bt.Persist});try{await c.write(a),await c.commit()}finally{await c.close()}return}const i=await this.openWriter({start:e,channels:t,mode:bt.Persist,errOnUnauthorized:!0,enableAutoCommit:!0,autoIndexPersistInterval:E.MAX});try{await i.write(t,n)}finally{await i.close()}}async read(e,t){const{single:n}=ye(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 U;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}=ye(e);return i==="keys"?await this.deleter.delete({keys:n,bounds:t}):await this.deleter.delete({names:n,bounds:t})}};const Zl=Object.freeze(Object.defineProperty({__proto__:null,ALWAYS_INDEX_PERSIST_ON_AUTO_COMMIT:jl,AUTO_SPAN:jr,Client:ri,Frame:U,Iterator:qt,ObservableStreamer:zt,Streamer:Qt,Writer:ti,WriterMode:bt,frameZ:Ht,series:Hs,seriesFromPayload:Xs,seriesToPayload:Qs},Symbol.toStringTag,{value:"Module"})),Ul=_e.Authority,Bl=_e.stateZ(s.z.number()),Ll=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 ni extends zt{constructor(t){super(t,n=>{const i=this.codec.decode(n.series[0].buffer);return this.merge(i),[i.transfers,!0]});o(this,"states");o(this,"codec");this.states=new Map,this.codec=new Ke.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 ql="sy_node_1_control";let si=class{constructor(e){o(this,"framer");this.framer=e}async openStateTracker(){const e=await this.framer.openStreamer(ql);return new ni(e)}};const Yl=Object.freeze(Object.defineProperty({__proto__:null,Authority:Ul,Client:si,StateTracker:ni,stateZ:Bl,transferString:Ll},Symbol.toStringTag,{value:"Module"}));let ii=class{constructor(e,t,n){o(this,"tasks");o(this,"racks");o(this,"devices");this.tasks=e,this.racks=t,this.devices=n}};const Wl=Object.freeze(Object.defineProperty({__proto__:null,Client:ii},Symbol.toStringTag,{value:"Module"})),Je=s.z.number(),er=s.z.object({key:Je,name:s.z.string()}),ai=er.partial({key:!0}),oi="rack",Fl=r=>new x({type:oi,key:r.toString()}),tr=s.z.string(),Et=s.z.object({key:tr,rack:Je,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(r=>r===""?{}:Ke.JSON_CODEC.decodeString(r)))}),ci=Et.extend({properties:s.z.unknown().transform(r=>Ke.JSON_CODEC.encodeString(r))}),li="device",_l=r=>new x({type:li,key:r.toString()}),He=async(r,e,t,n)=>{const i=await r.openStreamer([e,t]),a=c=>{const l=[];return t!=null&&l.push(...c.get(t).series.flatMap(u=>n("delete",u))),e!=null&&l.push(...c.get(e).series.flatMap(u=>n("set",u))),[l,l.length>0]};return new zt(i,a)},Gl=Object.freeze(Object.defineProperty({__proto__:null,openObservable:He},Symbol.toStringTag,{value:"Module"})),Kl="sy_device_set",Vl="sy_device_delete",fr="/hardware/device/retrieve",Jl="/hardware/device/create",Hl="/hardware/device/delete",Xl=s.z.object({devices:ci.array()}),Ql=s.z.object({devices:Et.array()}),eu=s.z.object({keys:tr.array()}),tu=s.z.object({}),pr=s.z.object({search:s.z.string().optional(),limit:s.z.number().optional(),offset:s.z.number().optional(),keys:tr.array().optional(),names:s.z.string().array().optional(),makes:s.z.string().array().optional()}),gr=s.z.object({devices:Ve(Et)});let ui=class{constructor(e,t){o(this,"type","device");o(this,"client");o(this,"frameClient");this.client=e,this.frameClient=t}async retrieve(e,t){const n=!Array.isArray(e),i=await w(this.client,fr,{keys:T(e),...t},pr,gr);return Jt("Device",e,i.devices,n),n?i.devices[0]:i.devices}async search(e,t){return(await w(this.client,fr,{search:e,...t},pr,gr)).devices}async page(e,t,n){return(await w(this.client,fr,{offset:e,limit:t,...n},pr,gr)).devices}async create(e){const t=!Array.isArray(e),n=await w(this.client,Jl,{devices:T(e)},Xl,Ql);return t?n.devices[0]:n.devices}async delete(e){await w(this.client,Hl,{keys:T(e)},eu,tu)}async openDeviceTracker(){return await He(this.frameClient,Kl,Vl,ru)}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 ru=(r,e)=>r==="delete"?e.toStrings().map(t=>({variant:r,key:t,value:void 0})):e.parseJSON(Et).map(t=>({variant:r,key:t.key,value:t})),nu=Object.freeze(Object.defineProperty({__proto__:null,Client:ui,DeviceOntologyType:li,deviceKeyZ:tr,deviceZ:Et,newDeviceZ:ci,ontologyID:_l},Symbol.toStringTag,{value:"Module"})),mr="/hardware/rack/retrieve",su="/hardware/rack/create",iu="/hardware/rack/delete",wr=s.z.object({keys:Je.array().optional(),names:s.z.string().array().optional(),search:s.z.string().optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),br=s.z.object({racks:Ve(er)}),au=s.z.object({racks:ai.array()}),ou=s.z.object({racks:er.array()}),cu=s.z.object({keys:Je.array()}),lu=s.z.object({});let hi=class{constructor(e,t,n){o(this,"type","rack");o(this,"client");o(this,"frameClient");o(this,"tasks");this.client=e,this.frameClient=t,this.tasks=n}async delete(e){await w(this.client,iu,{keys:T(e)},cu,lu)}async create(e){const t=!Array.isArray(e),n=await w(this.client,su,{racks:T(e)},au,ou),i=this.sugar(n.racks);return t?i[0]:i}async search(e){const t=await w(this.client,mr,{search:e},wr,br);return this.sugar(t.racks)}async page(e,t){const n=await w(this.client,mr,{offset:e,limit:t},wr,br);return this.sugar(n.racks)}async retrieve(e){const{variant:t,normalized:n,single:i}=Vt(e,{string:"names",number:"keys"}),a=await w(this.client,mr,{[t]:n},wr,br),c=this.sugar(a.racks);return Jt("Rack",e,c,i),i?c[0]:c}sugar(e){return e.map(({key:t,name:n})=>new yi(t,n,this.tasks))}};class yi{constructor(e,t,n){o(this,"key");o(this,"name");o(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 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 uu=Object.freeze(Object.defineProperty({__proto__:null,Client:hi,Rack:yi,RackOntologyType:oi,newRackZ:ai,ontologyID:Fl,rackKeyZ:Je,rackZ:er},Symbol.toStringTag,{value:"Module"})),Xe=s.z.union([s.z.string(),s.z.bigint().transform(r=>r.toString()),s.z.number().transform(r=>r.toString())]),vt=s.z.object({task:Xe,variant:s.z.string(),key:s.z.string().optional(),details:s.z.record(s.z.unknown()).or(s.z.string().transform(r=>r===""?{}:JSON.parse(r))).or(s.z.array(s.z.unknown())).or(s.z.null())}),rr=s.z.object({key:Xe,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(r=>r===""?{}:Ke.JSON_CODEC.decodeString(r))),state:vt.optional().nullable()}),di=rr.omit({key:!0}).extend({key:Xe.transform(r=>r.toString()).optional(),config:s.z.unknown().transform(r=>Ke.JSON_CODEC.encodeString(r))}),hu=s.z.object({task:Xe,type:s.z.string(),key:s.z.string(),args:s.z.record(s.z.unknown()).or(s.z.string().transform(r=>r===""?{}:JSON.parse(r)))}),fi="task",yu=r=>new x({type:fi,key:r.toString()}),yt="sy_task_state",Un="sy_task_cmd";class pi{constructor(e,t,n,i,a,c=!1,l){o(this,"key");o(this,"name");o(this,"internal");o(this,"type");o(this,"config");o(this,"state");o(this,"frameClient");this.key=e,this.name=t,this.type=n,this.config=i,this.internal=c,l!==null&&(this.state=l),this.frameClient=a}get payload(){return{key:this.key,name:this.name,type:this.type,config:this.config,state:this.state,internal:this.internal}}async executeCommand(e,t){const n=await this.frameClient.openWriter(Un),i=Fo.id();return await n.write(Un,[{task:this.key,type:e,key:i,args:t}]),await n.close(),i}async executeCommandSync(e,t,n){const i=await this.frameClient.openStreamer(yt),a=await this.executeCommand(e,t);let c;const l=new Promise(u=>setTimeout(()=>u(!1),new E(n).milliseconds));for(;;){const u=await Promise.any([i.read(),l]);if(u===!1)throw new Error("Command timed out");const f=vt.safeParse(u.at(-1).sy_task_state);if(f.success){if(c=f.data,c.key===a)break}else console.error(f.error)}return i.close(),c}async openStateObserver(){return new zt(await this.frameClient.openStreamer(yt),e=>{const t=e.get(yt);if(t.length===0)return[null,!1];const n=vt.safeParse(t.at(-1));if(!n.success)return[null,!1];const i=n.data;return i.task!==this.key?[null,!1]:[i,!0]})}}const du=s.z.object({rack:Je.optional(),keys:s.z.string().array().optional(),names:s.z.string().array().optional(),offset:s.z.number().optional(),limit:s.z.number().optional(),includeState:s.z.boolean().optional()}),fu=s.z.object({tasks:Ve(rr)}),pu="/hardware/task/retrieve",gu="/hardware/task/create",mu="/hardware/task/delete",wu=s.z.object({tasks:di.array()}),bu=s.z.object({tasks:rr.array()}),vu=s.z.object({keys:Xe.array()}),Tu=s.z.object({});let gi=class{constructor(e,t){o(this,"type","task");o(this,"client");o(this,"frameClient");this.client=e,this.frameClient=t}async create(e){const t=!Array.isArray(e),n=await w(this.client,gu,{tasks:T(e)},wu,bu),i=this.sugar(n.tasks);return t?i[0]:i}async delete(e){await w(this.client,mu,{keys:T(e)},vu,Tu)}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}=Vt(e,{number:"rack",string:"keys"},{convertNumericStrings:!1}),c={...t};a==="rack"?c.rack=e:c.keys=i;const l=await this.execRetrieve(c),u=this.sugar(l);return n&&a!=="rack"?u[0]:u}async retrieveByName(e,t){const n=await this.execRetrieve({names:[e],rack:t});return Jt("Task",e,n,!0),this.sugar(n)[0]}async execRetrieve(e){return(await w(this.client,pu,e,du,fu)).tasks}sugar(e){return e.map(({key:t,name:n,type:i,config:a,state:c,internal:l})=>new pi(t,n,i,a,this.frameClient,l,c))}async openTracker(){return await He(this.frameClient,"sy_task_set","sy_task_delete",(e,t)=>Array.from(t).map(n=>({variant:e,key:n.toString(),value:n.toString()})))}async openStateObserver(){return new zt(await this.frameClient.openStreamer(yt),e=>{const t=e.get(yt);if(t.length===0)return[null,!1];const n=vt.safeParse(t.at(-1));return n.success?[n.data,!0]:[null,!1]})}};const Ou=Object.freeze(Object.defineProperty({__proto__:null,Client:gi,DeviceOntologyType:fi,Task:pi,commandZ:hu,newTaskZ:di,ontologyID:yu,stateZ:vt,taskKeyZ:Xe,taskZ:rr},Symbol.toStringTag,{value:"Module"})),Qe=s.z.string().uuid(),St=s.z.object({key:Qe,name:s.z.string().min(1),color:s.z.string()}),mi="label",zu=r=>new x({type:mi,key:r}),Eu=s.z.object({keys:Qe.array().optional(),for:H.optional(),search:s.z.string().optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),Su=s.z.object({labels:St.array().optional().default([])});var ze;let wi=(ze=class{constructor(e){o(this,"client");this.client=e}async retrieve(e){const t=T(e);return await this.execute({keys:t})}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(ze.ENDPOINT,e,Eu,Su);if(n!=null)throw n;return t.labels}},o(ze,"ENDPOINT","/label/retrieve"),ze);const bi=St.extend({key:Qe.optional()}),Nu=s.z.object({labels:bi.array()}),Iu=s.z.object({labels:St.array()}),ku=s.z.object({keys:Qe.array()}),vi=s.z.object({id:H,labels:Qe.array()}),Au=vi,vr=s.z.object({}),$u="/label/create",Ru="/label/delete",xu="/label/set",Cu="/label/remove";let Ti=class{constructor(e){o(this,"client");this.client=e}async create(e){return(await w(this.client,$u,{labels:T(e)},Nu,Iu)).labels}async delete(e){await w(this.client,Ru,{keys:T(e)},ku,vr)}async set(e,t){await w(this.client,xu,{id:e,labels:t},vi,vr)}async remove(e,t){await w(this.client,Cu,{id:e,labels:t},Au,vr)}};const ju="sy_label_set",Pu="sy_label_delete";let Oi=class{constructor(e,t){o(this,"type","label");o(this,"retriever");o(this,"writer");o(this,"frameClient");this.writer=new Ti(e),this.retriever=new wi(e),this.frameClient=t}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(e)}async label(e,t){await this.writer.set(e,t)}async removeLabels(e,t){await this.writer.remove(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 He(this.frameClient,ju,Pu,Du)}};const Du=(r,e)=>r==="delete"?e.toUUIDs().map(t=>({variant:r,key:t})):e.parseJSON(St).map(t=>({variant:r,key:t.key,value:t})),Mu=Object.freeze(Object.defineProperty({__proto__:null,Client:Oi,LabelOntologyType:mi,Retriever:wi,Writer:Ti,keyZ:Qe,labelZ:St,newLabelPayloadZ:bi,ontologyID:zu},Symbol.toStringTag,{value:"Module"})),K=s.z.string().uuid(),et=s.z.object({key:K,name:s.z.string().min(1),timeRange:G.z,color:s.z.string().optional()}),zi=et.extend({key:s.z.string().uuid().optional()}),Ei=r=>{const e=T(r);if(e.length===0)throw new Error("Range params must not be empty");const t=K.safeParse(e[0]).success;return{single:!Array.isArray(r),variant:t?"keys":"names",normalized:e,actual:r}},Si="range",Ni="range-alias",Zu=r=>new x({type:Si,key:r}),Uu=r=>new x({type:Ni,key:r}),Bu=s.z.object({}),Lu=s.z.object({range:et}),qu=s.z.object({range:K}),Yu=s.z.object({range:K}),Wu=s.z.object({}),Fu="/range/set-active",_u="/range/retrieve-active",Gu="/range/clear-active";class Ku{constructor(e){o(this,"client");this.client=e}async setActive(e){await w(this.client,Fu,{range:e},qu,Bu)}async retrieveActive(){const[e,t]=await this.client.send(_u,{},s.z.object({}),Lu);if(X.matches(t))return null;if(t!=null)throw t;return e.range}async clearActive(e){await w(this.client,Gu,{range:e},Yu,Wu)}}const Vu="sy_range_alias_set",Ju="sy_range_alias_delete",Hu=s.z.object({range:K,aliases:s.z.string().array()}),Xu=s.z.object({aliases:s.z.record(s.z.string(),we)}),Qu=s.z.object({range:K,aliases:s.z.record(we.or(s.z.string()),s.z.string())}),eh=s.z.unknown(),th=s.z.object({range:K,channels:we.array()}),rh=s.z.unknown(),nh=s.z.object({range:K}),sh=s.z.object({aliases:s.z.record(s.z.string(),s.z.string())}),ae=class ae{constructor(e,t,n){o(this,"frameClient");o(this,"cache",new Map);o(this,"client");o(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 c=this.cache.get(e);if(c!=null)return c;t.push(e)}else e.forEach(c=>{const l=this.cache.get(c);l!=null?i[c]=l:t.push(c)});if(t.length===0)return i;const a=await w(this.client,ae.RESOLVE_ENDPOINT,{range:this.rangeKey,aliases:t},Hu,Xu);return Object.entries(a.aliases).forEach(([c,l])=>this.cache.set(c,l)),n?a.aliases[t[0]]:{...i,...a.aliases}}async set(e){await w(this.client,ae.SET_ENDPOINT,{range:this.rangeKey,aliases:e},Qu,eh)}async list(){return(await w(this.client,ae.LIST_ENDPOINT,{range:this.rangeKey},nh,sh)).aliases}async delete(e){await w(this.client,ae.DELETE_ENDPOINT,{range:this.rangeKey,channels:e},th,rh)}async openChangeTracker(){return await He(this.frameClient,Vu,Ju,oh(this.rangeKey))}};o(ae,"SET_ENDPOINT","/range/alias/set"),o(ae,"RESOLVE_ENDPOINT","/range/alias/resolve"),o(ae,"LIST_ENDPOINT","/range/alias/list"),o(ae,"DELETE_ENDPOINT","/range/alias/delete");let Pr=ae;const ih=s.z.object({range:K,channel:we,alias:s.z.string()}),ah="---",oh=r=>(e,t)=>e==="delete"?t.toStrings().filter(n=>n.split(ah)[0]===r).map(n=>({variant:e,key:n,value:void 0})):t.parseJSON(ih).map(n=>({variant:e,key:n.alias,value:n})),ch=s.z.object({range:K,keys:s.z.string().array()}),lh=s.z.object({pairs:s.z.record(s.z.string(),s.z.string())}),uh=s.z.object({range:K,pairs:s.z.record(s.z.string(),s.z.string())}),hh=s.z.object({range:K,keys:s.z.string().array()}),de=class de{constructor(e,t){o(this,"rangeKey");o(this,"client");this.rangeKey=e,this.client=t}async get(e){const[t,n]=await this.client.send(de.GET_ENDPOINT,{range:this.rangeKey,keys:T(e)},ch,lh);if(n!=null)throw n;return Array.isArray(e)?t.pairs:t.pairs[e]}async list(){return this.get([])}async set(e,t=""){await w(this.client,de.SET_ENDPOINT,{range:this.rangeKey,pairs:Ur(e)?e:{[e]:t}},uh,s.z.unknown())}async delete(e){await w(this.client,de.DELETE_ENDPOINT,{range:this.rangeKey,keys:T(e)},hh,s.z.unknown())}};o(de,"GET_ENDPOINT","/range/kv/get"),o(de,"SET_ENDPOINT","/range/kv/set"),o(de,"DELETE_ENDPOINT","/range/kv/delete");let Dr=de;const Tr=r=>new x({type:"range",key:r});class Ii{constructor(e,t=G.ZERO,n,i,a,c,l,u,f){o(this,"key");o(this,"name");o(this,"kv");o(this,"timeRange");o(this,"color");o(this,"channels");o(this,"aliaser");o(this,"frameClient");o(this,"labelClient");this.key=n,this.name=e,this.timeRange=t,this.frameClient=a,this.color=i,this.kv=c,this.aliaser=l,this.channels=u,this.labelClient=f}async setAlias(e,t){const n=await this.channels.retrieve(e);if(n.length===0)throw new X(`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 openAliasTracker(){return await this.aliaser.openChangeTracker()}async read(e){return await this.frameClient.read(this.timeRange,e)}async labels(){return await this.labelClient.retrieveFor(Tr(this.key))}async addLabel(...e){await this.labelClient.label(Tr(this.key),e)}async removeLabel(...e){await this.labelClient.removeLabels(Tr(this.key),e)}}const yh=s.z.object({keys:K.array().optional(),names:s.z.array(s.z.string()).optional(),term:s.z.string().optional(),overlapsWith:G.z.optional()}),dh="/range/retrieve",fh=s.z.object({ranges:Ve(et)});let ki=class{constructor(e,t,n,i,a){o(this,"type","range");o(this,"frameClient");o(this,"writer");o(this,"unaryClient");o(this,"channels");o(this,"active");o(this,"labelClient");this.frameClient=e,this.writer=t,this.unaryClient=n,this.channels=i,this.active=new Ku(n),this.labelClient=a}async create(e){const t=!Array.isArray(e),n=this.sugar(await this.writer.create(T(e)));return t?n[0]:n}async rename(e,t){await this.writer.rename(e,t)}async delete(e){await this.writer.delete(T(e))}async search(e){return this.sugar(await this.execRetrieve({term:e}))}async page(){return[]}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}=Ei(e),c=await this.execRetrieve({[i]:a});if(!t)return c;if(c.length===0)throw new Ie(`range matching ${n} not found`);if(c.length>1)throw new ke(`multiple ranges matching ${n} found`);return c[0]}async execRetrieve(e){const{ranges:t}=await w(this.unaryClient,dh,e,yh,fh);return this.sugar(t)}async setActive(e){await this.active.setActive(e)}async retrieveActive(){const e=await this.active.retrieveActive();return e==null?null:this.sugar([e])[0]}async clearActive(e){await this.active.clearActive(e)}sugar(e){return e.map(t=>new Ii(t.name,t.timeRange,t.key,t.color,this.frameClient,new Dr(t.key,this.unaryClient),new Pr(t.key,this.frameClient,this.unaryClient),this.channels,this.labelClient))}async openTracker(){return await He(this.frameClient,"sy_range_set","sy_range_delete",(e,t)=>e==="delete"?t.toStrings().map(i=>({variant:e,key:i,value:void 0})):this.sugar(t.parseJSON(et)).map(i=>({variant:e,key:i.key,value:i})))}};const ph=s.z.object({ranges:et.array()}),gh=s.z.object({ranges:zi.array()}),mh=s.z.object({keys:K.array()}),wh=s.z.object({}),bh=s.z.object({key:K,name:s.z.string()}),vh=s.z.object({}),Th="/range/create",Oh="/range/delete",zh="/range/rename";let Ai=class{constructor(e){o(this,"client");this.client=e}async rename(e,t){await w(this.client,zh,{key:e,name:t},bh,vh)}async create(e){return(await w(this.client,Th,{ranges:e},gh,ph)).ranges}async delete(e){await w(this.client,Oh,{keys:e},mh,wh)}};const Eh=Object.freeze(Object.defineProperty({__proto__:null,Client:ki,Range:Ii,RangeAliasOntologyType:Ni,RangeOntologyType:Si,Writer:Ai,analyzeParams:Ei,keyZ:K,newPayloadZ:zi,payloadZ:et,rangeAliasOntologyID:Uu,rangeOntologyID:Zu},Symbol.toStringTag,{value:"Module"})),Sh="/api/v1/";class Nh{constructor(e,t=!1){o(this,"url");o(this,"unary");o(this,"stream");o(this,"secure");this.secure=t,this.url=e.child(Sh);const n=new Ke.JSONCodec;this.unary=new Fa(this.url,n,this.secure),this.stream=new eo(this.url,n,this.secure)}use(...e){this.unary.use(...e),this.stream.use(...e)}}const Jr=s.z.string().uuid(),Hr=s.z.object({key:s.z.string(),name:s.z.string(),data:Lr.or(s.z.string().transform(r=>JSON.parse(r)))}),Ih=s.z.object({keys:s.z.string().array()}),kh=s.z.object({linePlots:Hr.array()});let Ah=class{constructor(e){o(this,"ENDPOINT","/workspace/lineplot/retrieve");o(this,"client");this.client=e}async retrieve(e){const t=T(e);return(await w(this.client,this.ENDPOINT,{keys:t},Ih,kh)).linePlots}};const be=s.z.string().uuid(),$i=r=>JSON.parse(r),Xr=s.z.object({name:s.z.string(),key:be,layout:Lr.or(s.z.string().transform(r=>$i(r)))}),Qr=Xr.omit({layout:!0}).extend({layout:s.z.string().transform(r=>$i(r))}),Ri="workspace",$h=r=>new x({type:Ri,key:r}),Rh=Hr.partial({key:!0}).transform(r=>({...r,data:JSON.stringify(r.data)})),xh=s.z.object({workspace:be,linePlots:Rh.array()}),Ch=s.z.object({linePlots:Hr.array()}),jh=s.z.object({keys:Jr.array()}),Ph=s.z.object({}),Dh=s.z.object({key:Jr,name:s.z.string()}),Mh=s.z.object({}),Zh=s.z.object({key:Jr,data:s.z.string()}),Uh=s.z.object({}),Bh="/workspace/lineplot/create",Lh="/workspace/lineplot/delete",qh="/workspace/lineplot/rename",Yh="/workspace/lineplot/set-data";let Wh=class{constructor(e){o(this,"client");this.client=e}async create(e,t){const n={...t,data:JSON.stringify(t.data)};return(await w(this.client,Bh,{workspace:e,linePlots:[n]},xh,Ch)).linePlots[0]}async delete(e){const t=T(e);await w(this.client,Lh,{keys:t},jh,Ph)}async rename(e,t){await w(this.client,qh,{key:e,name:t},Dh,Mh)}async setData(e,t){await w(this.client,Yh,{key:e,data:JSON.stringify(t)},Zh,Uh)}},Fh=class{constructor(e){o(this,"writer");o(this,"retriever");this.writer=new Wh(e),this.retriever=new Ah(e)}async create(e,t){return await this.writer.create(e,t)}async rename(e,t){await this.writer.rename(e,t)}async setData(e,t){await this.writer.setData(e,t)}async retrieve(e){const t=Array.isArray(e),n=await this.retriever.retrieve(e);return t?n:n[0]}async delete(e){await this.writer.delete(e)}};const _h=s.z.object({keys:be.array().optional(),search:s.z.string().optional(),author:s.z.string().uuid().optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),Gh=s.z.object({workspaces:Ve(Qr)});var Ee;let Kh=(Ee=class{constructor(e){o(this,"client");this.client=e}async retrieve(e){const t=T(e);return await this.execute({keys:t})}async retrieveByAuthor(e){return await this.execute({author: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){return(await w(this.client,Ee.ENDPOINT,e,_h,Gh)).workspaces}},o(Ee,"ENDPOINT","/workspace/retrieve"),Ee);const nr=s.z.string().uuid(),Vh=s.z.object({key:s.z.string(),name:s.z.string(),data:Lr.or(s.z.string().transform(r=>JSON.parse(r))),snapshot:s.z.boolean()}),en=s.z.object({key:s.z.string(),name:s.z.string(),snapshot:s.z.boolean(),data:s.z.string().transform(r=>JSON.parse(r))}),Jh=s.z.object({keys:s.z.string().array()}),Hh=s.z.object({schematics:en.array()});class Xh{constructor(e){o(this,"ENDPOINT","/workspace/schematic/retrieve");o(this,"client");this.client=e}async retrieve(e){return(await w(this.client,this.ENDPOINT,{keys:T(e)},Jh,Hh)).schematics}}const Qh=Vh.partial({key:!0,snapshot:!0}).transform(r=>({...r,data:JSON.stringify(r.data)})),ey=s.z.object({workspace:be,schematics:Qh.array()}),ty=s.z.object({schematics:en.array()}),ry=s.z.object({keys:nr.array()}),ny=s.z.object({}),sy=s.z.object({key:nr,name:s.z.string()}),Bn=s.z.object({}),iy=s.z.object({key:nr,data:s.z.string()});s.z.object({});const ay=s.z.object({key:nr,name:s.z.string(),snapshot:s.z.boolean()}),oy=s.z.object({schematic:en}),cy="/workspace/schematic/create",ly="/workspace/schematic/delete",uy="/workspace/schematic/rename",hy="/workspace/schematic/set-data",yy="/workspace/schematic/copy";let dy=class{constructor(e){o(this,"client");this.client=e}async create(e,t){const n={...t,data:JSON.stringify(t.data)};return(await w(this.client,cy,{workspace:e,schematics:[n]},ey,ty)).schematics[0]}async copy(e,t,n){return(await w(this.client,yy,{key:e,name:t,snapshot:n},ay,oy)).schematic}async delete(e){const t=T(e);await w(this.client,ly,{keys:t},ry,ny)}async rename(e,t){await w(this.client,uy,{key:e,name:t},sy,Bn)}async setData(e,t){await w(this.client,hy,{key:e,data:JSON.stringify(t)},iy,Bn)}},fy=class{constructor(e){o(this,"writer");o(this,"retriever");this.writer=new dy(e),this.retriever=new Xh(e)}async create(e,t){return await this.writer.create(e,t)}async rename(e,t){await this.writer.rename(e,t)}async setData(e,t){await this.writer.setData(e,t)}async retrieve(e){const t=Array.isArray(e),n=await this.retriever.retrieve(e);return t?n:n[0]}async delete(e){await this.writer.delete(e)}async copy(e,t,n){return await this.writer.copy(e,t,n)}};const py=Xr.partial({key:!0}).transform(r=>({...r,layout:JSON.stringify(r.layout)})),gy=s.z.object({workspaces:py.array()}),my=s.z.object({workspaces:Qr.array()}),wy=s.z.object({keys:be.array()}),by=s.z.object({}),vy=s.z.object({key:be,name:s.z.string()}),Ty=s.z.object({}),Oy=s.z.object({key:be,layout:s.z.string()}),zy=s.z.object({}),Ey="/workspace/create",Sy="/workspace/delete",Ny="/workspace/rename",Iy="/workspace/set-layout";class ky{constructor(e){o(this,"client");this.client=e}async create(e){return(await w(this.client,Ey,{workspaces:T(e)},gy,my)).workspaces}async delete(e){await w(this.client,Sy,{keys:T(e)},wy,by)}async rename(e,t){await w(this.client,Ny,{key:e,name:t},vy,Ty)}async setLayout(e,t){await w(this.client,Iy,{key:e,layout:JSON.stringify(t)},Oy,zy)}}class xi{constructor(e){o(this,"type","workspace");o(this,"schematic");o(this,"linePlot");o(this,"retriever");o(this,"writer");this.schematic=new fy(e),this.linePlot=new Fh(e),this.retriever=new Kh(e),this.writer=new ky(e)}async search(e){return await this.retriever.search(e)}async retrieveByAuthor(e){return await this.retriever.retrieveByAuthor(e)}async retrieve(e){const t=Array.isArray(e),n=await this.retriever.retrieve(e);return t?n:n[0]}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 rename(e,t){await this.writer.rename(e,t)}async setLayout(e,t){await this.writer.setLayout(e,t)}async delete(...e){await this.writer.delete(e)}}const Ay=Object.freeze(Object.defineProperty({__proto__:null,Client:xi,WorkspaceOntologyType:Ri,keyZ:be,ontologyID:$h,workspaceRemoteZ:Qr,workspaceZ:Xr},Symbol.toStringTag,{value:"Module"})),Ci=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().optional(),password:s.z.string().optional(),connectivityPollFrequency:E.z.default(E.seconds(30)),secure:s.z.boolean().optional().default(!1),name:s.z.string().optional()});class ji extends ri{constructor(t){const n=Ci.parse(t),{host:i,port:a,username:c,password:l,connectivityPollFrequency:u,secure:f}=n,p=new Nh(new lc({host:i,port:Number(a)}),f);p.use(mc);let g;c!=null&&l!=null&&(g=new bl(p.unary,{username:c,password:l}),p.use(g.middleware()));const P=new qr(new mt(p.unary)),j=new _s(p.unary,P);super(p.stream,p.unary,P);o(this,"createdAt");o(this,"props");o(this,"ranges");o(this,"channels");o(this,"auth");o(this,"user");o(this,"access");o(this,"connectivity");o(this,"ontology");o(this,"workspaces");o(this,"labels");o(this,"hardware");o(this,"control");o(this,"transport");this.createdAt=O.now(),this.props=n,this.auth=g,this.transport=p,this.channels=new Fs(this,P,p.unary,j),this.connectivity=new wt(p.unary,u,n.name),this.control=new si(this),this.ontology=new Us(p.unary,this);const Q=new Ai(this.transport.unary);this.labels=new Oi(this.transport.unary,this),this.ranges=new ki(this,Q,this.transport.unary,P,this.labels),this.access=new fl(this.transport.unary),this.user=new gl(this.transport.unary),this.workspaces=new xi(this.transport.unary);const D=new ui(this.transport.unary,this),tn=new gi(this.transport.unary,this),Pi=new hi(this.transport.unary,this,tn);this.hardware=new ii(tn,Pi,D)}get key(){return this.createdAt.valueOf().toString()}close(){this.connectivity.stopChecking()}}o(ji,"connectivity",wt);const $y=_e.Authority;exports.AuthError=Ne;exports.Authority=$y;exports.Channel=Yr;exports.ContiguityError=xr;exports.DataType=z;exports.Density=_;exports.Frame=U;exports.MultiSeries=Ns;exports.MultipleFoundError=ke;exports.NotFoundError=Ie;exports.QueryError=X;exports.Rate=Gt;exports.RouteError=gt;exports.Series=Oe;exports.Synnax=ji;exports.TimeRange=G;exports.TimeSpan=E;exports.TimeStamp=O;exports.UnexpectedError=pe;exports.ValidationError=C;exports.channel=nl;exports.connection=Ol;exports.control=Yl;exports.device=nu;exports.framer=Zl;exports.hardware=Wl;exports.label=Mu;exports.ontology=Pc;exports.rack=uu;exports.ranger=Eh;exports.signals=Gl;exports.synnaxPropsZ=Ci;exports.task=Ou;exports.workspace=Ay;
|