@synnaxlabs/client 0.29.0 → 0.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @synnaxlabs/client@0.
|
|
2
|
+
> @synnaxlabs/client@0.30.0 build /home/runner/work/synnax/synnax/client/ts
|
|
3
3
|
> tsc --noEmit && vite build
|
|
4
4
|
|
|
5
5
|
[34m Synnax - Production mode[0m
|
|
@@ -10,8 +10,8 @@ rendering chunks...
|
|
|
10
10
|
|
|
11
11
|
[vite:dts] Start generate declaration files...
|
|
12
12
|
computing gzip size...
|
|
13
|
-
[2mdist/[22m[36mclient.js [39m[1m[2m247.
|
|
14
|
-
[vite:dts] Declaration files built in
|
|
13
|
+
[2mdist/[22m[36mclient.js [39m[1m[2m247.53 kB[22m[1m[22m[2m │ gzip: 57.78 kB[22m
|
|
14
|
+
[vite:dts] Declaration files built in 5940ms.
|
|
15
15
|
|
|
16
|
-
[2mdist/[22m[36mclient.cjs [39m[1m[2m155.
|
|
17
|
-
[32m✓ built in 6.
|
|
16
|
+
[2mdist/[22m[36mclient.cjs [39m[1m[2m155.14 kB[22m[1m[22m[2m │ gzip: 42.21 kB[22m
|
|
17
|
+
[32m✓ built in 6.79s[39m
|
package/dist/client.cjs
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
${t}
|
|
21
21
|
|
|
22
22
|
Please report this to the Synnax team.
|
|
23
|
-
`);o(this,"type",Ze.TYPE)}};o(Ze,"TYPE",me+"unexpected"),o(Ze,"matches",J(Ze.TYPE));let pe=Ze;const Ue=class Ue extends te{constructor(){super(...arguments);o(this,"type",Ue.TYPE)}};o(Ue,"TYPE",me+"query"),o(Ue,"matches",J(Ue.TYPE));let Q=Ue;const Be=class Be extends Q{constructor(){super(...arguments);o(this,"type",Be.TYPE)}};o(Be,"TYPE",Q.TYPE+".not_found"),o(Be,"matches",J(Be.TYPE));let Ae=Be;const Le=class Le extends Q{constructor(){super(...arguments);o(this,"type",Le.TYPE)}};o(Le,"TYPE",Q.TYPE+".multiple_results"),o(Le,"matches",J(Le.TYPE));let $e=Le;const qe=class qe extends te{constructor(t,n){super(t);o(this,"type",qe.TYPE);o(this,"path");this.path=n}};o(qe,"TYPE",me+"route"),o(qe,"matches",J(qe.TYPE));let mt=qe;const Ye=class Ye extends te{constructor(){super(...arguments);o(this,"type",Ye.TYPE)}};o(Ye,"TYPE",me+"control"),o(Ye,"matches",J(Ye.TYPE));let He=Ye;const We=class We extends He{constructor(){super(...arguments);o(this,"type",We.TYPE)}};o(We,"TYPE",He.TYPE+".unauthorized"),o(We,"matches",J(We.TYPE));let Gt=We;const _e=class _e extends te{constructor(){super(...arguments);o(this,"type",_e.TYPE)}};o(_e,"TYPE",me+"contiguity"),o(_e,"matches",J(_e.TYPE));let Br=_e;const Pc=r=>{if(!r.type.startsWith(me))return null;if(r.type.startsWith(x.TYPE)){if(r.type===Kt.TYPE){const e=r.data.split(": ");return e.length<2?new x(r.data):new Kt(e[0],e[1])}return new x(r.data)}return r.type.startsWith(ke.TYPE)?r.type.startsWith(gt.TYPE)?new gt(r.data):new ke(r.data):r.type.startsWith(pe.TYPE)?new pe(r.data):r.type.startsWith(Q.TYPE)?r.type.startsWith(Ae.TYPE)?new Ae(r.data):r.type.startsWith($e.TYPE)?new $e(r.data):new Q(r.data):r.type.startsWith(He.TYPE)?r.type.startsWith(Gt.TYPE)?new Gt(r.data):new He(r.data):r.type.startsWith(mt.TYPE)?new mt(r.data,r.data):new pe(r.data)},Dc=()=>{throw new Error("Not implemented")};fs({encode:Dc,decode:Pc});const jc=async(r,e)=>{const[t,n]=await e(r);return n==null?[t,n]:n instanceof Ne?[t,new Ne({message:`Cannot reach cluster at ${n.url.host}:${n.url.port}`,url:n.url})]:[t,n]};class Ys{constructor(e,t){o(this,"key");o(this,"name");this.key=t,this.name=e}get ontologyID(){return new T({type:"group",key:this.key})}}const Mc=s.z.string().uuid(),Ws=s.z.object({key:Mc,name:s.z.string()}),rr=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")]),Zc="builtin",Uc="cluster",Bc="node",G=s.z.object({type:rr,key:s.z.string()}),_s=s.z.string().transform(r=>{const[e,t]=r.split(":");return{type:e,key:t}}),Vs=s.z.union([_s,G]),Ve=class Ve{constructor(e){o(this,"type");o(this,"key");if(e instanceof Ve)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(Ve,"z",s.z.union([Vs,s.z.instanceof(Ve)]).transform(e=>new Ve(e)));let T=Ve;const Lc=new T({type:"builtin",key:"root"}),Fs=s.z.object({type:s.z.number()}),Ks=s.z.object({type:rr,fields:s.z.record(Fs)}),Gs=s.z.object({id:T.z,name:s.z.string(),schema:Ks.optional().nullable(),data:s.z.record(s.z.unknown()).optional().nullable()}).transform(r=>({key:r.id.toString(),...r})),qc=s.z.object({from:T.z,type:s.z.string(),to:T.z}),Lr=r=>{const[e,t,n]=r.split("->");return{from:new T(e),type:t,to:new T(n)}},Yc=s.z.object({group:Ws}),Wc=s.z.object({parent:G,key:s.z.string().uuid().optional(),name:s.z.string()}),_c=s.z.object({key:s.z.string(),name:s.z.string()}),Vc=s.z.object({keys:s.z.array(s.z.string())});var ee;let Fc=(ee=class{constructor(e){o(this,"client");this.client=e}async create(e,t,n){return(await w(this.client,ee.ENDPOINT,{parent:e,name:t,key:n},Wc,Yc)).group}async rename(e,t){await w(this.client,ee.ENDPOINT_RENAME,{key:e,name:t},_c,s.z.object({}))}async delete(e){await w(this.client,ee.ENDPOINT_DELETE,{keys:e},Vc,s.z.object({}))}},o(ee,"ENDPOINT","/ontology/create-group"),o(ee,"ENDPOINT_RENAME","/ontology/rename-group"),o(ee,"ENDPOINT_DELETE","/ontology/delete-group"),ee),Kc=class{constructor(e){o(this,"creator");this.creator=new Fc(e)}async create(e,t,n){return this.sugar(await this.creator.create(e,t,n))}async rename(e,t){return await this.creator.rename(e,t)}async delete(...e){return await this.creator.delete(e)}sugar(e){return new Ys(e.name,e.key)}};const Or={ADD_CHILDREN:"/ontology/add-children",REMOVE_CHILDREN:"/ontology/remove-children",MOVE_CHILDREN:"/ontology/move-children"},Un=s.z.object({id:G,children:G.array()}),Gc=s.z.object({from:G,to:G,children:G.array()});let Jc=class{constructor(e){o(this,"client");this.client=e}async addChildren(e,...t){await w(this.client,Or.ADD_CHILDREN,{id:new T(e).payload,children:t.map(n=>new T(n).payload)},Un,s.z.object({}))}async removeChildren(e,...t){await w(this.client,Or.REMOVE_CHILDREN,{id:new T(e).payload,children:t.map(n=>new T(n).payload)},Un,s.z.object({}))}async moveChildren(e,t,...n){const i={from:new T(e).payload,to:new T(t).payload,children:n.map(a=>new T(a).payload)};await w(this.client,Or.MOVE_CHILDREN,i,Gc,s.z.object({}))}};const Hc="/ontology/retrieve",Xc=s.z.object({ids:G.array().optional(),children:s.z.boolean().optional(),parents:s.z.boolean().optional(),includeSchema:s.z.boolean().optional(),excludeFieldData:s.z.boolean().optional(),term:s.z.string().optional(),limit:s.z.number().optional(),offset:s.z.number().optional(),types:rr.array().optional()}),Qc=s.z.object({resources:Gs.array()}),_t=r=>O(r).map(e=>new T(e).payload);let Js=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 Jc(e),this.groups=new Kc(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:_t(e),...t});if(Array.isArray(e))return n;if(n.length===0)throw new Q(`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:_t(e),children:!0,...t})}async retrieveParents(e,t){return await this.execRetrieve({ids:_t(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 Et.open(this.framer,this)}async openDependentTracker(e){return await nr.open(e,this.framer,this)}newSearcherWithOptions(e){return{type:this.type,search:t=>this.search(t,e),retrieve:t=>this.retrieve(t,e),page:(t,n)=>this.page(t,n,e)}}async execRetrieve(e){const{resources:t}=await w(this.client,Hc,e,Xc,Qc);return t}};const Bn="sy_ontology_resource_set",Ln="sy_ontology_resource_delete",qn="sy_ontology_relationship_set",Yn="sy_ontology_relationship_delete";class Et{constructor(e,t){o(this,"relationships");o(this,"resources");o(this,"resourceObs");o(this,"relationshipObs");o(this,"streamer");o(this,"client");o(this,"closePromise");this.relationshipObs=new Ie.Observer,this.relationships=this.relationshipObs,this.resourceObs=new Ie.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(qn);return t.length===0?[]:Array.from(t.as("string")).map(n=>({variant:"set",key:Lr(n),value:void 0}))}parseRelationshipDeletes(e){const t=e.get(Yn);return t.length===0?[]:Array.from(t.as("string")).map(n=>({variant:"delete",key:Lr(n)}))}async parseResourceSets(e){const t=e.get(Bn);if(t.length===0)return[];const n=Array.from(t.as("string")).map(i=>new T(i));try{return(await this.client.retrieve(n)).map(a=>({variant:"set",key:a.id,value:a}))}catch(i){if(i instanceof Q)return[];throw i}}parseResourceDeletes(e){const t=e.get(Ln);return t.length===0?[]:Array.from(t.as("string")).map(n=>({variant:"delete",key:new T(n)}))}static async open(e,t){const n=await e.openStreamer([Bn,Ln,qn,Yn]);return new Et(n,t)}}const Wn=r=>r==="from"?"to":"from";class nr extends Ie.Observer{constructor({target:t,dependents:n,relationshipType:i="parent",relationshipDirection:a="from",resourceType:c},l,u){super();o(this,"internal");o(this,"target");o(this,"relDir");o(this,"resourceType");o(this,"dependents");o(this,"client");o(this,"relType");o(this,"handleResourceChange",t=>{this.dependents=this.dependents.map(n=>{const i=t.find(a=>a.key.toString()==n.id.toString());return i==null||i.variant==="delete"?n:i.value}),this.notify(this.dependents)});o(this,"handleRelationshipChange",t=>{const n=t.filter(a=>a.variant==="delete"&&a.key[this.relDir].toString()===this.target.toString()&&(this.resourceType==null||a.key[Wn(this.relDir)].type===this.resourceType));this.dependents=this.dependents.filter(a=>!n.some(c=>c.key.to.toString()===a.id.toString()&&c.key.type===this.relType));const i=t.filter(a=>a.variant==="set"&&a.key.type===this.relType&&a.key[this.relDir].toString()===this.target.toString()&&(this.resourceType==null||a.key[Wn(this.relDir)].type===this.resourceType));if(i.length===0)return this.notify(this.dependents);this.client.retrieve(i.map(a=>a.key.to)).then(a=>{this.dependents=this.dependents.concat(a),this.notify(this.dependents)})});this.resourceType=c,this.internal=l,this.target=t,this.dependents=n,this.resourceType!=null&&(this.dependents=this.dependents.filter(h=>h.id.type===this.resourceType)),this.client=u,this.relType=i,this.relDir=a,this.internal.resources.onChange(this.handleResourceChange),this.internal.relationships.onChange(this.handleRelationshipChange)}static async open(t,n,i){const a=await Et.open(n,i);return new nr(t,a,i)}async close(){await this.internal.close()}}const el=Object.freeze(Object.defineProperty({__proto__:null,BuiltinOntologyType:Zc,ChangeTracker:Et,Client:Js,ClusterOntologyType:Uc,DependentTracker:nr,ID:T,NodeOntologyType:Bc,Root:Lc,crudeIDZ:Vs,idZ:G,parseIDs:_t,parseRelationship:Lr,relationshipSchemaZ:qc,resourceSchemaZ:Gs,resourceTypeZ:rr,schemaFieldZ:Fs,schemaZ:Ks,stringIDZ:_s},Symbol.toStringTag,{value:"Module"})),we=s.z.number(),St=s.z.object({name:s.z.string(),key:s.z.number(),rate:tr.z,dataType:z.z,leaseholder:s.z.number(),index:s.z.number(),isIndex:s.z.boolean(),internal:s.z.boolean(),virtual:s.z.boolean(),alias:s.z.string().optional()}),Hs=St.extend({key:s.z.number().optional(),leaseholder:s.z.number().optional(),index:s.z.number().optional(),rate:tr.z.optional().default(0),isIndex:s.z.boolean().optional(),internal:s.z.boolean().optional().default(!1),virtual:s.z.boolean().optional().default(!1)}),Xs="channel",tl=r=>new T({type:Xs,key:r.toString()}),rl=new Error("request for lock canceled");var nl=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{h(n.next(p))}catch(g){c(g)}}function u(p){try{h(n.throw(p))}catch(g){c(g)}}function h(p){p.done?a(p.value):i(p.value).then(l,u)}h((n=n.apply(r,e||[])).next())})};class sl{constructor(e,t=rl){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 nl(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]=[]),il(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 il(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 al=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{h(n.next(p))}catch(g){c(g)}}function u(p){try{h(n.throw(p))}catch(g){c(g)}}function h(p){p.done?a(p.value):i(p.value).then(l,u)}h((n=n.apply(r,e||[])).next())})};class ol{constructor(e){this._semaphore=new sl(1,e)}acquire(){return al(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 sr=(r,e,{convertNumericStrings:t=!0}={})=>{const n=!Array.isArray(r);let i=O(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}},ir=(r,e,t,n)=>{if(n){if(t.length===0)throw new Ae(`${r} not found matching ${JSON.stringify(e)}`);if(t.length>1)throw new $e(`Expected one ${r} matching ${JSON.stringify(e)}, but found ${t.length}`)}},be=r=>s.z.union([s.z.null().transform(()=>[]),r.array()]),cl=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()}),ll=s.z.object({channels:be(St)}),ye=r=>sr(r,{number:"keys",string:"names"}),Ht=class Ht{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(Ht.ENDPOINT,e,cl,ll);if(n!=null)throw n;return t.channels}};o(Ht,"ENDPOINT","/channel/retrieve");let wt=Ht;class Gr{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}=sr(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 ei{constructor(e,t){o(this,"mu",new ol);o(this,"requests",new Map);o(this,"wrapped");o(this,"debouncedRun");this.wrapped=e,this.debouncedRun=dc(()=>{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 ti=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 Q(`Could not find channels: ${JSON.stringify(i)}`);return n};class Jr{constructor({dataType:e,rate:t,name:n,leaseholder:i=0,key:a=0,isIndex:c=!1,index:l=0,internal:u=!1,virtual:h=!1,frameClient:p,alias:g}){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");o(this,"virtual");this.key=a,this.name=n,this.rate=new tr(t??0),this.dataType=new z(e),this.leaseholder=i,this.index=l,this.isIndex=c,this.internal=u,this.alias=g,this.virtual=h,this._frameClient=p??null}get framer(){if(this._frameClient==null)throw new x("cannot read from a channel that has not been created");return this._frameClient}get payload(){return St.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 T({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 ul="/channel/retrieve-group",hl=s.z.object({}),yl=s.z.object({group:Ws});let ri=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=O(e),c=[];if(n){const l=await this.retriever.retrieve(a.map(h=>h.name)),u=new Set(l.map(h=>h.name));a=a.filter(h=>!u.has(h.name)),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 ir("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(O(e),O(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 Gr(new ei(new wt(this.client),e))}sugar(e){const{frameClient:t}=this;return e.map(n=>new Jr({...n,frameClient:t}))}async retrieveGroup(){const e=await w(this.client,ul,{},hl,yl);return new Ys(e.group.name,e.group.key)}};const dl=s.z.object({channels:Hs.array()}),fl=s.z.object({channels:St.array()}),pl=s.z.object({keys:we.array().optional(),names:s.z.string().array().optional()}),gl=s.z.object({}),ml=s.z.object({keys:we.array(),names:s.z.string().array()}),wl=s.z.object({}),bl="/channel/create",vl="/channel/delete",Tl="/channel/rename";let ni=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,bl,{channels:e},dl,fl);return this.cache.set(t),t}async delete(e){await w(this.client,vl,e,pl,gl),e.keys!=null&&this.cache.delete(e.keys),e.names!=null&&this.cache.delete(e.names)}async rename(e,t){await w(this.client,Tl,{keys:e,names:t},ml,wl),this.cache.rename(e,t)}};const Ol=Object.freeze(Object.defineProperty({__proto__:null,CacheRetriever:Gr,Channel:Jr,ChannelOntologyType:Xs,Client:ri,ClusterRetriever:wt,DebouncedBatchRetriever:ei,Writer:ni,analyzeChannelParams:ye,keyZ:we,newPayload:Hs,ontologyID:tl,payload:St,retrieveRequired:ti},Symbol.toStringTag,{value:"Module"})),Hr=s.z.string().uuid(),Xr=s.z.object({key:Hr,subjects:G.array(),objects:G.array(),actions:s.z.string().array()}),zl=Xr.extend({key:Hr.optional()}),El="/access/policy/create",Sl="/access/policy/delete",Nl="/access/policy/retrieve",Il=s.z.object({policies:zl.array()}),kl=s.z.object({policies:Xr.array()}),Al=s.z.object({keys:Hr.array()}),$l=s.z.object({}),Rl=s.z.object({subject:G}),Cl=s.z.object({policies:Xr.array().optional().default([])});let xl=class{constructor(e){o(this,"client");this.client=e}async create(e){const t=!Array.isArray(e),{policies:n}=await w(this.client,El,{policies:O(e)},Il,kl);return t?n[0]:n}async retrieve(e){const{policies:t}=await w(this.client,Nl,{subject:e},Rl,Cl);return t}async delete(e){await w(this.client,Sl,{keys:O(e)},Al,$l)}};const Pl="/user/register";let Dl=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},si,ii);return n}};s.z.string().uuid();const jl=s.z.object({key:s.z.string(),username:s.z.string()}),si=s.z.object({username:s.z.string(),password:s.z.string()}),ii=s.z.object({token:s.z.string(),user:jl}),_n="/auth/login",Ml=3;let Zl=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(_n)){this.authenticating==null&&(this.authenticating=new Promise((l,u)=>{this.client.send(_n,this.credentials,si,ii).then(([h,p])=>{if(p!=null)return l(p);this.token=h==null?void 0:h.token,this.user=h==null?void 0:h.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 gt.matches(a)&&this.retryCount<Ml?(this.authenticated=!1,this.authenticating=void 0,this.retryCount+=1,e(t,n)):(this.retryCount=0,[i,a])};return e}};const Ul=["disconnected","connecting","connected","failed"],ai=s.z.enum(Ul),oi=s.z.object({status:ai,error:s.z.instanceof(Error).optional(),message:s.z.string().optional(),clusterKey:s.z.string(),clientVersion:s.z.string(),clientServerCompatible:s.z.boolean(),nodeVersion:s.z.string().optional()}),Bl=s.z.object({clusterKey:s.z.string(),nodeVersion:s.z.string().optional()}),Vn={clusterKey:"",status:"disconnected",error:void 0,message:"Disconnected",clientServerCompatible:!1,clientVersion:"0.29.0"},Fn=(r,e,t)=>{const n=t?"cluster":"client";return`Synnax cluster node version ${r!=null?r+" ":""}is too ${t?"old":"new"} for client version ${e}.
|
|
23
|
+
`);o(this,"type",Ze.TYPE)}};o(Ze,"TYPE",me+"unexpected"),o(Ze,"matches",J(Ze.TYPE));let pe=Ze;const Ue=class Ue extends te{constructor(){super(...arguments);o(this,"type",Ue.TYPE)}};o(Ue,"TYPE",me+"query"),o(Ue,"matches",J(Ue.TYPE));let Q=Ue;const Be=class Be extends Q{constructor(){super(...arguments);o(this,"type",Be.TYPE)}};o(Be,"TYPE",Q.TYPE+".not_found"),o(Be,"matches",J(Be.TYPE));let Ae=Be;const Le=class Le extends Q{constructor(){super(...arguments);o(this,"type",Le.TYPE)}};o(Le,"TYPE",Q.TYPE+".multiple_results"),o(Le,"matches",J(Le.TYPE));let $e=Le;const qe=class qe extends te{constructor(t,n){super(t);o(this,"type",qe.TYPE);o(this,"path");this.path=n}};o(qe,"TYPE",me+"route"),o(qe,"matches",J(qe.TYPE));let mt=qe;const Ye=class Ye extends te{constructor(){super(...arguments);o(this,"type",Ye.TYPE)}};o(Ye,"TYPE",me+"control"),o(Ye,"matches",J(Ye.TYPE));let He=Ye;const We=class We extends He{constructor(){super(...arguments);o(this,"type",We.TYPE)}};o(We,"TYPE",He.TYPE+".unauthorized"),o(We,"matches",J(We.TYPE));let Gt=We;const _e=class _e extends te{constructor(){super(...arguments);o(this,"type",_e.TYPE)}};o(_e,"TYPE",me+"contiguity"),o(_e,"matches",J(_e.TYPE));let Br=_e;const Pc=r=>{if(!r.type.startsWith(me))return null;if(r.type.startsWith(x.TYPE)){if(r.type===Kt.TYPE){const e=r.data.split(": ");return e.length<2?new x(r.data):new Kt(e[0],e[1])}return new x(r.data)}return r.type.startsWith(ke.TYPE)?r.type.startsWith(gt.TYPE)?new gt(r.data):new ke(r.data):r.type.startsWith(pe.TYPE)?new pe(r.data):r.type.startsWith(Q.TYPE)?r.type.startsWith(Ae.TYPE)?new Ae(r.data):r.type.startsWith($e.TYPE)?new $e(r.data):new Q(r.data):r.type.startsWith(He.TYPE)?r.type.startsWith(Gt.TYPE)?new Gt(r.data):new He(r.data):r.type.startsWith(mt.TYPE)?new mt(r.data,r.data):new pe(r.data)},Dc=()=>{throw new Error("Not implemented")};fs({encode:Dc,decode:Pc});const jc=async(r,e)=>{const[t,n]=await e(r);return n==null?[t,n]:n instanceof Ne?[t,new Ne({message:`Cannot reach cluster at ${n.url.host}:${n.url.port}`,url:n.url})]:[t,n]};class Ys{constructor(e,t){o(this,"key");o(this,"name");this.key=t,this.name=e}get ontologyID(){return new T({type:"group",key:this.key})}}const Mc=s.z.string().uuid(),Ws=s.z.object({key:Mc,name:s.z.string()}),rr=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")]),Zc="builtin",Uc="cluster",Bc="node",G=s.z.object({type:rr,key:s.z.string()}),_s=s.z.string().transform(r=>{const[e,t]=r.split(":");return{type:e,key:t}}),Vs=s.z.union([_s,G]),Ve=class Ve{constructor(e){o(this,"type");o(this,"key");if(e instanceof Ve)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(Ve,"z",s.z.union([Vs,s.z.instanceof(Ve)]).transform(e=>new Ve(e)));let T=Ve;const Lc=new T({type:"builtin",key:"root"}),Fs=s.z.object({type:s.z.number()}),Ks=s.z.object({type:rr,fields:s.z.record(Fs)}),Gs=s.z.object({id:T.z,name:s.z.string(),schema:Ks.optional().nullable(),data:s.z.record(s.z.unknown()).optional().nullable()}).transform(r=>({key:r.id.toString(),...r})),qc=s.z.object({from:T.z,type:s.z.string(),to:T.z}),Lr=r=>{const[e,t,n]=r.split("->");return{from:new T(e),type:t,to:new T(n)}},Yc=s.z.object({group:Ws}),Wc=s.z.object({parent:G,key:s.z.string().uuid().optional(),name:s.z.string()}),_c=s.z.object({key:s.z.string(),name:s.z.string()}),Vc=s.z.object({keys:s.z.array(s.z.string())});var ee;let Fc=(ee=class{constructor(e){o(this,"client");this.client=e}async create(e,t,n){return(await w(this.client,ee.ENDPOINT,{parent:e,name:t,key:n},Wc,Yc)).group}async rename(e,t){await w(this.client,ee.ENDPOINT_RENAME,{key:e,name:t},_c,s.z.object({}))}async delete(e){await w(this.client,ee.ENDPOINT_DELETE,{keys:e},Vc,s.z.object({}))}},o(ee,"ENDPOINT","/ontology/create-group"),o(ee,"ENDPOINT_RENAME","/ontology/rename-group"),o(ee,"ENDPOINT_DELETE","/ontology/delete-group"),ee),Kc=class{constructor(e){o(this,"creator");this.creator=new Fc(e)}async create(e,t,n){return this.sugar(await this.creator.create(e,t,n))}async rename(e,t){return await this.creator.rename(e,t)}async delete(...e){return await this.creator.delete(e)}sugar(e){return new Ys(e.name,e.key)}};const Or={ADD_CHILDREN:"/ontology/add-children",REMOVE_CHILDREN:"/ontology/remove-children",MOVE_CHILDREN:"/ontology/move-children"},Un=s.z.object({id:G,children:G.array()}),Gc=s.z.object({from:G,to:G,children:G.array()});let Jc=class{constructor(e){o(this,"client");this.client=e}async addChildren(e,...t){await w(this.client,Or.ADD_CHILDREN,{id:new T(e).payload,children:t.map(n=>new T(n).payload)},Un,s.z.object({}))}async removeChildren(e,...t){await w(this.client,Or.REMOVE_CHILDREN,{id:new T(e).payload,children:t.map(n=>new T(n).payload)},Un,s.z.object({}))}async moveChildren(e,t,...n){const i={from:new T(e).payload,to:new T(t).payload,children:n.map(a=>new T(a).payload)};await w(this.client,Or.MOVE_CHILDREN,i,Gc,s.z.object({}))}};const Hc="/ontology/retrieve",Xc=s.z.object({ids:G.array().optional(),children:s.z.boolean().optional(),parents:s.z.boolean().optional(),includeSchema:s.z.boolean().optional(),excludeFieldData:s.z.boolean().optional(),term:s.z.string().optional(),limit:s.z.number().optional(),offset:s.z.number().optional(),types:rr.array().optional()}),Qc=s.z.object({resources:Gs.array()}),_t=r=>O(r).map(e=>new T(e).payload);let Js=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 Jc(e),this.groups=new Kc(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:_t(e),...t});if(Array.isArray(e))return n;if(n.length===0)throw new Q(`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:_t(e),children:!0,...t})}async retrieveParents(e,t){return await this.execRetrieve({ids:_t(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 Et.open(this.framer,this)}async openDependentTracker(e){return await nr.open(e,this.framer,this)}newSearcherWithOptions(e){return{type:this.type,search:t=>this.search(t,e),retrieve:t=>this.retrieve(t,e),page:(t,n)=>this.page(t,n,e)}}async execRetrieve(e){const{resources:t}=await w(this.client,Hc,e,Xc,Qc);return t}};const Bn="sy_ontology_resource_set",Ln="sy_ontology_resource_delete",qn="sy_ontology_relationship_set",Yn="sy_ontology_relationship_delete";class Et{constructor(e,t){o(this,"relationships");o(this,"resources");o(this,"resourceObs");o(this,"relationshipObs");o(this,"streamer");o(this,"client");o(this,"closePromise");this.relationshipObs=new Ie.Observer,this.relationships=this.relationshipObs,this.resourceObs=new Ie.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(qn);return t.length===0?[]:Array.from(t.as("string")).map(n=>({variant:"set",key:Lr(n),value:void 0}))}parseRelationshipDeletes(e){const t=e.get(Yn);return t.length===0?[]:Array.from(t.as("string")).map(n=>({variant:"delete",key:Lr(n)}))}async parseResourceSets(e){const t=e.get(Bn);if(t.length===0)return[];const n=Array.from(t.as("string")).map(i=>new T(i));try{return(await this.client.retrieve(n)).map(a=>({variant:"set",key:a.id,value:a}))}catch(i){if(i instanceof Q)return[];throw i}}parseResourceDeletes(e){const t=e.get(Ln);return t.length===0?[]:Array.from(t.as("string")).map(n=>({variant:"delete",key:new T(n)}))}static async open(e,t){const n=await e.openStreamer([Bn,Ln,qn,Yn]);return new Et(n,t)}}const Wn=r=>r==="from"?"to":"from";class nr extends Ie.Observer{constructor({target:t,dependents:n,relationshipType:i="parent",relationshipDirection:a="from",resourceType:c},l,u){super();o(this,"internal");o(this,"target");o(this,"relDir");o(this,"resourceType");o(this,"dependents");o(this,"client");o(this,"relType");o(this,"handleResourceChange",t=>{this.dependents=this.dependents.map(n=>{const i=t.find(a=>a.key.toString()==n.id.toString());return i==null||i.variant==="delete"?n:i.value}),this.notify(this.dependents)});o(this,"handleRelationshipChange",t=>{const n=t.filter(a=>a.variant==="delete"&&a.key[this.relDir].toString()===this.target.toString()&&(this.resourceType==null||a.key[Wn(this.relDir)].type===this.resourceType));this.dependents=this.dependents.filter(a=>!n.some(c=>c.key.to.toString()===a.id.toString()&&c.key.type===this.relType));const i=t.filter(a=>a.variant==="set"&&a.key.type===this.relType&&a.key[this.relDir].toString()===this.target.toString()&&(this.resourceType==null||a.key[Wn(this.relDir)].type===this.resourceType));if(i.length===0)return this.notify(this.dependents);this.client.retrieve(i.map(a=>a.key.to)).then(a=>{this.dependents=this.dependents.concat(a),this.notify(this.dependents)})});this.resourceType=c,this.internal=l,this.target=t,this.dependents=n,this.resourceType!=null&&(this.dependents=this.dependents.filter(h=>h.id.type===this.resourceType)),this.client=u,this.relType=i,this.relDir=a,this.internal.resources.onChange(this.handleResourceChange),this.internal.relationships.onChange(this.handleRelationshipChange)}static async open(t,n,i){const a=await Et.open(n,i);return new nr(t,a,i)}async close(){await this.internal.close()}}const el=Object.freeze(Object.defineProperty({__proto__:null,BuiltinOntologyType:Zc,ChangeTracker:Et,Client:Js,ClusterOntologyType:Uc,DependentTracker:nr,ID:T,NodeOntologyType:Bc,Root:Lc,crudeIDZ:Vs,idZ:G,parseIDs:_t,parseRelationship:Lr,relationshipSchemaZ:qc,resourceSchemaZ:Gs,resourceTypeZ:rr,schemaFieldZ:Fs,schemaZ:Ks,stringIDZ:_s},Symbol.toStringTag,{value:"Module"})),we=s.z.number(),St=s.z.object({name:s.z.string(),key:s.z.number(),rate:tr.z,dataType:z.z,leaseholder:s.z.number(),index:s.z.number(),isIndex:s.z.boolean(),internal:s.z.boolean(),virtual:s.z.boolean(),alias:s.z.string().optional()}),Hs=St.extend({key:s.z.number().optional(),leaseholder:s.z.number().optional(),index:s.z.number().optional(),rate:tr.z.optional().default(0),isIndex:s.z.boolean().optional(),internal:s.z.boolean().optional().default(!1),virtual:s.z.boolean().optional().default(!1)}),Xs="channel",tl=r=>new T({type:Xs,key:r.toString()}),rl=new Error("request for lock canceled");var nl=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{h(n.next(p))}catch(g){c(g)}}function u(p){try{h(n.throw(p))}catch(g){c(g)}}function h(p){p.done?a(p.value):i(p.value).then(l,u)}h((n=n.apply(r,e||[])).next())})};class sl{constructor(e,t=rl){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 nl(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]=[]),il(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 il(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 al=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{h(n.next(p))}catch(g){c(g)}}function u(p){try{h(n.throw(p))}catch(g){c(g)}}function h(p){p.done?a(p.value):i(p.value).then(l,u)}h((n=n.apply(r,e||[])).next())})};class ol{constructor(e){this._semaphore=new sl(1,e)}acquire(){return al(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 sr=(r,e,{convertNumericStrings:t=!0}={})=>{const n=!Array.isArray(r);let i=O(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}},ir=(r,e,t,n)=>{if(n){if(t.length===0)throw new Ae(`${r} not found matching ${JSON.stringify(e)}`);if(t.length>1)throw new $e(`Expected one ${r} matching ${JSON.stringify(e)}, but found ${t.length}`)}},be=r=>s.z.union([s.z.null().transform(()=>[]),r.array()]),cl=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()}),ll=s.z.object({channels:be(St)}),ye=r=>sr(r,{number:"keys",string:"names"}),Ht=class Ht{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(Ht.ENDPOINT,e,cl,ll);if(n!=null)throw n;return t.channels}};o(Ht,"ENDPOINT","/channel/retrieve");let wt=Ht;class Gr{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}=sr(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 ei{constructor(e,t){o(this,"mu",new ol);o(this,"requests",new Map);o(this,"wrapped");o(this,"debouncedRun");this.wrapped=e,this.debouncedRun=dc(()=>{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 ti=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 Q(`Could not find channels: ${JSON.stringify(i)}`);return n};class Jr{constructor({dataType:e,rate:t,name:n,leaseholder:i=0,key:a=0,isIndex:c=!1,index:l=0,internal:u=!1,virtual:h=!1,frameClient:p,alias:g}){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");o(this,"virtual");this.key=a,this.name=n,this.rate=new tr(t??0),this.dataType=new z(e),this.leaseholder=i,this.index=l,this.isIndex=c,this.internal=u,this.alias=g,this.virtual=h,this._frameClient=p??null}get framer(){if(this._frameClient==null)throw new x("cannot read from a channel that has not been created");return this._frameClient}get payload(){return St.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 T({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 ul="/channel/retrieve-group",hl=s.z.object({}),yl=s.z.object({group:Ws});let ri=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=O(e),c=[];if(n){const l=await this.retriever.retrieve(a.map(h=>h.name)),u=new Set(l.map(h=>h.name));a=a.filter(h=>!u.has(h.name)),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 ir("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(O(e),O(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 Gr(new ei(new wt(this.client),e))}sugar(e){const{frameClient:t}=this;return e.map(n=>new Jr({...n,frameClient:t}))}async retrieveGroup(){const e=await w(this.client,ul,{},hl,yl);return new Ys(e.group.name,e.group.key)}};const dl=s.z.object({channels:Hs.array()}),fl=s.z.object({channels:St.array()}),pl=s.z.object({keys:we.array().optional(),names:s.z.string().array().optional()}),gl=s.z.object({}),ml=s.z.object({keys:we.array(),names:s.z.string().array()}),wl=s.z.object({}),bl="/channel/create",vl="/channel/delete",Tl="/channel/rename";let ni=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,bl,{channels:e},dl,fl);return this.cache.set(t),t}async delete(e){await w(this.client,vl,e,pl,gl),e.keys!=null&&this.cache.delete(e.keys),e.names!=null&&this.cache.delete(e.names)}async rename(e,t){await w(this.client,Tl,{keys:e,names:t},ml,wl),this.cache.rename(e,t)}};const Ol=Object.freeze(Object.defineProperty({__proto__:null,CacheRetriever:Gr,Channel:Jr,ChannelOntologyType:Xs,Client:ri,ClusterRetriever:wt,DebouncedBatchRetriever:ei,Writer:ni,analyzeChannelParams:ye,keyZ:we,newPayload:Hs,ontologyID:tl,payload:St,retrieveRequired:ti},Symbol.toStringTag,{value:"Module"})),Hr=s.z.string().uuid(),Xr=s.z.object({key:Hr,subjects:G.array(),objects:G.array(),actions:s.z.string().array()}),zl=Xr.extend({key:Hr.optional()}),El="/access/policy/create",Sl="/access/policy/delete",Nl="/access/policy/retrieve",Il=s.z.object({policies:zl.array()}),kl=s.z.object({policies:Xr.array()}),Al=s.z.object({keys:Hr.array()}),$l=s.z.object({}),Rl=s.z.object({subject:G}),Cl=s.z.object({policies:Xr.array().optional().default([])});let xl=class{constructor(e){o(this,"client");this.client=e}async create(e){const t=!Array.isArray(e),{policies:n}=await w(this.client,El,{policies:O(e)},Il,kl);return t?n[0]:n}async retrieve(e){const{policies:t}=await w(this.client,Nl,{subject:e},Rl,Cl);return t}async delete(e){await w(this.client,Sl,{keys:O(e)},Al,$l)}};const Pl="/user/register";let Dl=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},si,ii);return n}};s.z.string().uuid();const jl=s.z.object({key:s.z.string(),username:s.z.string()}),si=s.z.object({username:s.z.string(),password:s.z.string()}),ii=s.z.object({token:s.z.string(),user:jl}),_n="/auth/login",Ml=3;let Zl=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(_n)){this.authenticating==null&&(this.authenticating=new Promise((l,u)=>{this.client.send(_n,this.credentials,si,ii).then(([h,p])=>{if(p!=null)return l(p);this.token=h==null?void 0:h.token,this.user=h==null?void 0:h.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 gt.matches(a)&&this.retryCount<Ml?(this.authenticated=!1,this.authenticating=void 0,this.retryCount+=1,e(t,n)):(this.retryCount=0,[i,a])};return e}};const Ul=["disconnected","connecting","connected","failed"],ai=s.z.enum(Ul),oi=s.z.object({status:ai,error:s.z.instanceof(Error).optional(),message:s.z.string().optional(),clusterKey:s.z.string(),clientVersion:s.z.string(),clientServerCompatible:s.z.boolean(),nodeVersion:s.z.string().optional()}),Bl=s.z.object({clusterKey:s.z.string(),nodeVersion:s.z.string().optional()}),Vn={clusterKey:"",status:"disconnected",error:void 0,message:"Disconnected",clientServerCompatible:!1,clientVersion:"0.30.0"},Fn=(r,e,t)=>{const n=t?"cluster":"client";return`Synnax cluster node version ${r!=null?r+" ":""}is too ${t?"old":"new"} for client version ${e}.
|
|
24
24
|
This may cause compatibility issues. We recommend updating the ${n}. For more information, see
|
|
25
25
|
https://docs.synnaxlabs.com/reference/typescript-client/troubleshooting#old-${n}-version`},Fe=class Fe{constructor(e,t=E.seconds(30),n,i){o(this,"_state");o(this,"pollFrequency",E.seconds(30));o(this,"client");o(this,"name");o(this,"interval");o(this,"clientVersion");o(this,"onChangeHandlers",[]);o(this,"versionWarned",!1);this._state={...Vn},this.client=e,this.pollFrequency=t,this.clientVersion=n,this.name=i,this.check(),this.startChecking()}stopChecking(){this.interval!=null&&clearInterval(this.interval)}async check(){var t;const e=this._state.status;try{const[n,i]=await this.client.send(Fe.ENDPOINT,{},s.z.object({}),Bl);if(i!=null)throw i;const a=n.nodeVersion,c=this.clientVersion,l=this.versionWarned;a==null?(this._state.clientServerCompatible=!1,l||(console.warn(Fn(null,c,!0)),this.versionWarned=!0)):Zn.versionsEqual(c,a,{checkMajor:!0,checkMinor:!0,checkPatch:!1})?this._state.clientServerCompatible=!0:(this._state.clientServerCompatible=!1,l||(console.warn(Fn(a,c,Zn.semVerNewer(c,a))),this.versionWarned=!0)),this._state.status="connected",this._state.message=`Connected to ${this.name??"cluster"}`,this._state.clusterKey=n.clusterKey,this._state.nodeVersion=n.nodeVersion,this._state.clientVersion=this.clientVersion}catch(n){this._state.status="failed",this._state.error=n,this._state.message=(t=this.state.error)==null?void 0:t.message}return this.onChangeHandlers.length>0&&e!==this._state.status&&this.onChangeHandlers.forEach(n=>n(this.state)),this.state}get state(){return{...this._state}}onChange(e){this.onChangeHandlers.push(e)}startChecking(){this.interval=setInterval(()=>{this.check()},this.pollFrequency.milliseconds)}};o(Fe,"ENDPOINT","/connectivity/check"),o(Fe,"DEFAULT",Vn),o(Fe,"connectionStateZ",oi);let bt=Fe;const Ll=Object.freeze(Object.defineProperty({__proto__:null,Checker:bt,state:oi,status:ai},Symbol.toStringTag,{value:"Module"})),ql=s.z.object({keys:we.array().optional(),bounds:W.z,names:s.z.string().array().optional()}),Yl=s.z.object({}),Wl="/frame/delete";class _l{constructor(e){o(this,"client");this.client=e}async delete(e){await w(this.client,Wl,e,ql,Yl)}}const Kn=r=>{const e=O(r);return e.length===0?null:typeof e[0]=="number"||!isNaN(parseInt(e[0]))?"key":"name"},Gn=(r,e)=>{const t=O(r);if(t.length===e.length)return;const n=Kn(r);throw Kn===null?new x("[Frame] - channel keys or names must be provided when constructing a frame."):new x(`[Frame] - ${n}s and series must be the same length.
|
|
26
26
|
Got ${t.length} ${n}s and ${e.length} series.`)};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,...O(i)));return}if(typeof e=="object"&&!Array.isArray(e)){if("keys"in e&&"series"in e){const i=e,a=i.series.map(c=>li(c));Gn(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,...O(a));else return this.push(c,...O(a))});return}if(Array.isArray(e)||["string","number"].includes(typeof e)){const i=O(t),a=O(e);Gn(a,i),i.forEach((c,l)=>this.push(a[l],c));return}throw new x(`[Frame] - invalid frame construction parameters. data parameter ust be a frame
|
|
@@ -38,4 +38,4 @@
|
|
|
38
38
|
`);const p=new ze({data:t[u],dataType:h.dataType});c.push(h.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 h=typeof u=="string"?(p=this.adapter)==null?void 0:p.get(u):u;if(h==null)throw new x(`
|
|
39
39
|
Channel ${u} was not provided in the list of channels when opening the writer
|
|
40
40
|
`);return h}),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],h=await this.fetchChannel(l),p=new ze({data:u,dataType:h.dataType});n.push(h.key),i.push(p)}return new U(n,i)}}class en{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.
|
|
41
|
-
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 qr=new E(-1);var tn=(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))(tn||{}),hi=(r=>(r[r.None=0]="None",r[r.Ack=1]="Ack",r[r.Data=2]="Data",r))(hi||{});const Vl=s.z.object({command:s.z.nativeEnum(tn),span:E.z.optional(),bounds:W.z.optional(),stamp:S.z.optional(),keys:s.z.number().array().optional(),chunkSize:s.z.number().optional()}),Fl=s.z.object({variant:s.z.nativeEnum(hi),ack:s.z.boolean(),command:s.z.nativeEnum(tn),error:Ot.optional().nullable(),frame:ar.optional()}),ft=class ft{constructor(e,t){o(this,"stream");o(this,"adapter");o(this,"value");this.stream=new en("Iterator",e),this.value=new U,this.adapter=t}static async _open(e,t,n,i,a={}){const c=await or.open(n,t),l=await i.stream(ft.ENDPOINT,Vl,Fl),u=new ft(l,c);return await u.execute({command:0,keys:c.keys,bounds:new W(e),chunkSize:a.chunkSize??1e5}),u}async next(e=qr){return await this.execute({command:1,span:new E(e)})}async prev(e=qr){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 S(e)})}async seekGE(e){return await this.execute({command:6,stamp:new S(e)})}async valid(){return await this.execute({command:7})}async close(){await this.stream.closeAndAck()}[Symbol.asyncIterator](){return new Kl(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(ft,"ENDPOINT","/frame/iterate");let Jt=ft;class Kl{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 Gl=s.z.object({keys:s.z.number().array()}),Jl=s.z.object({frame:ar,error:Ot.optional().nullable()}),Hl="/frame/stream";class cr{constructor(e,t){o(this,"stream");o(this,"adapter");this.stream=new en("Streamer",e),this.adapter=t}get keys(){return this.adapter.keys}static async _open(e,t,{channels:n}){const i=await or.open(e,n),a=await t.stream(Hl,Gl,Jl),c=new cr(a,i);return a.send({keys:i.keys}),c}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 Nt extends Ie.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 rn=(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))(rn||{}),Xe=(r=>(r[r.PersistStream=1]="PersistStream",r[r.Persist=2]="Persist",r[r.Stream=3]="Stream",r))(Xe||{});const Xl=r=>{switch(r){case"persist":return 2;case"stream":return 3;case"persistStream":return 1;default:if(typeof r=="number"&&r in Xe)return r;throw new Error(`invalid writer mode: ${r}`)}},Ql=new E(-1),eu=s.z.object({start:S.z.optional(),controlSubject:Je.subjectZ.optional(),keys:s.z.number().array().optional(),authorities:Je.Authority.z.array().optional(),mode:s.z.nativeEnum(Xe).optional(),errOnUnauthorized:s.z.boolean().optional(),enableAutoCommit:s.z.boolean().optional(),autoIndexPersistInterval:E.z.optional()}),tu=s.z.object({command:s.z.nativeEnum(rn),config:eu.optional(),frame:ar.optional()}),ru=s.z.object({ack:s.z.boolean(),command:s.z.nativeEnum(rn),error:Ot.optional().nullable()});var fe;let yi=(fe=class{constructor(e,t){o(this,"stream");o(this,"adapter");this.stream=new en("Writer",e),this.adapter=t}static async _open(e,t,{channels:n,start:i=S.now(),authorities:a=Je.Authority.Absolute,controlSubject:c,mode:l=1,errOnUnauthorized:u=!1,enableAutoCommit:h=!1,autoIndexPersistInterval:p=E.SECOND}){const g=await Qr.open(e,n),D=await t.stream(fe.ENDPOINT,tu,ru),P=new fe(D,g);return await P.execute({command:0,config:{start:new S(i),keys:g.keys,controlSubject:c,authorities:O(a),mode:Xl(l),errOnUnauthorized:u,enableAutoCommit:h,autoIndexPersistInterval:p}}),P}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?_r(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),di=class{constructor(e,t,n){o(this,"streamClient");o(this,"retriever");o(this,"deleter");this.streamClient=e,this.retriever=n,this.deleter=new _l(t)}async openIterator(e,t,n){return await Jt._open(e,t,this.retriever,this.streamClient,n)}async openWriter(e){return(Array.isArray(e)||typeof e!="object")&&(e={channels:e}),await yi._open(this.retriever,this.streamClient,e)}async openStreamer(e){return(Array.isArray(e)||typeof e!="object")&&(e={channels:e}),await cr._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:Xe.Persist});try{await c.write(a),await c.commit()}finally{await c.close()}return}const i=await this.openWriter({start:e,channels:t,mode:Xe.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 nu=Object.freeze(Object.defineProperty({__proto__:null,ALWAYS_INDEX_PERSIST_ON_AUTO_COMMIT:Ql,AUTO_SPAN:qr,Client:di,Frame:U,Iterator:Jt,ObservableStreamer:Nt,Streamer:cr,Writer:yi,WriterMode:Xe,frameZ:ar,series:ci,seriesFromPayload:li,seriesToPayload:ui},Symbol.toStringTag,{value:"Module"})),su=Je.Authority,iu=Je.stateZ(s.z.number()),au=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 fi extends Nt{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 Qe.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 ou="sy_node_1_control";let pi=class{constructor(e){o(this,"framer");this.framer=e}async openStateTracker(){const e=await this.framer.openStreamer(ou);return new fi(e)}};const cu=Object.freeze(Object.defineProperty({__proto__:null,Authority:su,Client:pi,StateTracker:fi,stateZ:iu,transferString:au},Symbol.toStringTag,{value:"Module"}));let gi=class{constructor(e,t,n){o(this,"tasks");o(this,"racks");o(this,"devices");this.tasks=e,this.racks=t,this.devices=n}};const lu=Object.freeze(Object.defineProperty({__proto__:null,Client:gi},Symbol.toStringTag,{value:"Module"})),et=s.z.number(),lr=s.z.object({key:et,name:s.z.string()}),mi=lr.partial({key:!0}),wi="rack",uu=r=>new T({type:wi,key:r.toString()}),ur=s.z.string(),It=s.z.object({key:ur,rack:et,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===""?{}:Qe.JSON_CODEC.decodeString(r)))}),bi=It.extend({properties:s.z.unknown().transform(r=>Qe.JSON_CODEC.encodeString(r))}),vi="device",hu=r=>new T({type:vi,key:r.toString()}),Re=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 Nt(i,a)},yu=Object.freeze(Object.defineProperty({__proto__:null,openObservable:Re},Symbol.toStringTag,{value:"Module"})),du="sy_device_set",fu="sy_device_delete",zr="/hardware/device/retrieve",pu="/hardware/device/create",gu="/hardware/device/delete",mu=s.z.object({devices:bi.array()}),wu=s.z.object({devices:It.array()}),bu=s.z.object({keys:ur.array()}),vu=s.z.object({}),Er=s.z.object({search:s.z.string().optional(),limit:s.z.number().optional(),offset:s.z.number().optional(),keys:ur.array().optional(),names:s.z.string().array().optional(),makes:s.z.string().array().optional()}),Sr=s.z.object({devices:be(It)});let Ti=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,zr,{keys:O(e),...t},Er,Sr);return ir("Device",e,i.devices,n),n?i.devices[0]:i.devices}async search(e,t){return(await w(this.client,zr,{search:e,...t},Er,Sr)).devices}async page(e,t,n){return(await w(this.client,zr,{offset:e,limit:t,...n},Er,Sr)).devices}async create(e){const t=!Array.isArray(e),n=await w(this.client,pu,{devices:O(e)},mu,wu);return t?n.devices[0]:n.devices}async delete(e){await w(this.client,gu,{keys:O(e)},bu,vu)}async openDeviceTracker(){return await Re(this.frameClient,du,fu,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(It).map(t=>({variant:r,key:t.key,value:t})),Ou=Object.freeze(Object.defineProperty({__proto__:null,Client:Ti,DeviceOntologyType:vi,deviceKeyZ:ur,deviceZ:It,newDeviceZ:bi,ontologyID:hu},Symbol.toStringTag,{value:"Module"})),Nr="/hardware/rack/retrieve",zu="/hardware/rack/create",Eu="/hardware/rack/delete",Ir=s.z.object({keys:et.array().optional(),names:s.z.string().array().optional(),search:s.z.string().optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),kr=s.z.object({racks:be(lr)}),Su=s.z.object({racks:mi.array()}),Nu=s.z.object({racks:lr.array()}),Iu=s.z.object({keys:et.array()}),ku=s.z.object({});let Oi=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,Eu,{keys:O(e)},Iu,ku)}async create(e){const t=!Array.isArray(e),n=await w(this.client,zu,{racks:O(e)},Su,Nu),i=this.sugar(n.racks);return t?i[0]:i}async search(e){const t=await w(this.client,Nr,{search:e},Ir,kr);return this.sugar(t.racks)}async page(e,t){const n=await w(this.client,Nr,{offset:e,limit:t},Ir,kr);return this.sugar(n.racks)}async retrieve(e){const{variant:t,normalized:n,single:i}=sr(e,{string:"names",number:"keys"}),a=await w(this.client,Nr,{[t]:n},Ir,kr),c=this.sugar(a.racks);return ir("Rack",e,c,i),i?c[0]:c}sugar(e){return e.map(({key:t,name:n})=>new zi(t,n,this.tasks))}};class zi{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 Au=Object.freeze(Object.defineProperty({__proto__:null,Client:Oi,Rack:zi,RackOntologyType:wi,newRackZ:mi,ontologyID:uu,rackKeyZ:et,rackZ:lr},Symbol.toStringTag,{value:"Module"})),Ce=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:Ce,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())}),kt=s.z.object({key:Ce,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===""?{}:Qe.JSON_CODEC.decodeString(r))),state:vt.optional().nullable(),snapshot:s.z.boolean().optional()}),Ei=kt.omit({key:!0}).extend({key:Ce.transform(r=>r.toString()).optional(),config:s.z.unknown().transform(r=>Qe.JSON_CODEC.encodeString(r))}),$u=s.z.object({task:Ce,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)))}),Si="task",Ru=r=>new T({type:Si,key:r.toString()}),dt="sy_task_state",Jn="sy_task_cmd",Pt=new Error("Task not created");class Ni{constructor(e,t,n,i,a=!1,c=!1,l,u=null,h=null,p=null){o(this,"key");o(this,"name");o(this,"internal");o(this,"type");o(this,"config");o(this,"snapshot");o(this,"state");o(this,"frameClient");o(this,"ontologyClient");o(this,"rangeClient");this.key=e,this.name=t,this.type=n,this.config=i,this.internal=a,this.snapshot=c,l!==null&&(this.state=l),this.frameClient=u,this.ontologyClient=h,this.rangeClient=p}get payload(){return{key:this.key,name:this.name,type:this.type,config:this.config,state:this.state,internal:this.internal}}get ontologyID(){return new T({type:"task",key:this.key})}async executeCommand(e,t){if(this.frameClient==null)throw Pt;const n=await this.frameClient.openWriter(Jn),i=ac.id();return await n.write(Jn,[{task:this.key,type:e,key:i,args:t}]),await n.close(),i}async executeCommandSync(e,t,n){if(this.frameClient==null)throw Pt;const i=await this.frameClient.openStreamer(dt),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 h=vt.safeParse(u.at(-1).sy_task_state);if(h.success){if(c=h.data,c.key===a)break}else console.error(h.error)}return i.close(),c}async openStateObserver(){if(this.frameClient==null)throw Pt;return new Nt(await this.frameClient.openStreamer(dt),e=>{const t=e.get(dt);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]})}async snapshottedTo(){if(this.ontologyClient==null||this.rangeClient==null)throw Pt;if(!this.snapshot)return null;const e=await this.ontologyClient.retrieveParents(this.ontologyID);return e.length==0?null:e[0]}}const Cu=s.z.object({rack:et.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()}),xu=s.z.object({tasks:be(kt)}),Pu="/hardware/task/retrieve",Du="/hardware/task/create",ju="/hardware/task/delete",Mu="/hardware/task/copy",Zu=s.z.object({tasks:Ei.array()}),Uu=s.z.object({tasks:kt.array()}),Bu=s.z.object({keys:Ce.array()}),Lu=s.z.object({}),qu=s.z.object({key:Ce,name:s.z.string(),snapshot:s.z.boolean()}),Yu=s.z.object({task:kt});let Ii=class{constructor(e,t,n,i){o(this,"type","task");o(this,"client");o(this,"frameClient");o(this,"ontologyClient");o(this,"rangeClient");this.client=e,this.frameClient=t,this.ontologyClient=n,this.rangeClient=i}async create(e){const t=!Array.isArray(e),n=await w(this.client,Du,{tasks:O(e)},Zu,Uu),i=this.sugar(n.tasks);return t?i[0]:i}async delete(e){await w(this.client,ju,{keys:O(e)},Bu,Lu)}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}=sr(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 copy(e,t,n){const i=await w(this.client,Mu,{key:e,name:t,snapshot:n},qu,Yu);return this.sugar([i.task])[0]}async retrieveByName(e,t){const n=await this.execRetrieve({names:[e],rack:t});return ir("Task",e,n,!0),this.sugar(n)[0]}async execRetrieve(e){return(await w(this.client,Pu,e,Cu,xu)).tasks}sugar(e){return e.map(({key:t,name:n,type:i,config:a,state:c,internal:l,snapshot:u})=>new Ni(t,n,i,a,l,u,c,this.frameClient,this.ontologyClient,this.rangeClient))}async openTracker(){return await Re(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 Nt(await this.frameClient.openStreamer(dt),e=>{const t=e.get(dt);if(t.length===0)return[null,!1];const n=vt.safeParse(t.at(-1));return n.success?[n.data,!0]:[null,!1]})}};const Wu=Object.freeze(Object.defineProperty({__proto__:null,Client:Ii,DeviceOntologyType:Si,Task:Ni,commandZ:$u,newTaskZ:Ei,ontologyID:Ru,stateZ:vt,taskKeyZ:Ce,taskZ:kt},Symbol.toStringTag,{value:"Module"})),tt=s.z.string().uuid(),At=s.z.object({key:tt,name:s.z.string().min(1),color:s.z.string()}),ki="label",_u=r=>new T({type:ki,key:r}),Vu=s.z.object({keys:tt.array().optional(),for:G.optional(),search:s.z.string().optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),Fu=s.z.object({labels:be(At)});var Ee;let Ai=(Ee=class{constructor(e){o(this,"client");this.client=e}async retrieve(e){const t=O(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(Ee.ENDPOINT,e,Vu,Fu);if(n!=null)throw n;return t.labels}},o(Ee,"ENDPOINT","/label/retrieve"),Ee);const $i=At.extend({key:tt.optional()}),Ku=s.z.object({labels:$i.array()}),Gu=s.z.object({labels:At.array()}),Ju=s.z.object({keys:tt.array()}),Ri=s.z.object({id:G,labels:tt.array(),replace:s.z.boolean().optional()}),Hu=Ri.omit({replace:!0}),Ar=s.z.object({}),Xu="/label/create",Qu="/label/delete",eh="/label/set",th="/label/remove";let Ci=class{constructor(e){o(this,"client");this.client=e}async create(e){return(await w(this.client,Xu,{labels:O(e)},Ku,Gu)).labels}async delete(e){await w(this.client,Qu,{keys:O(e)},Ju,Ar)}async set(e,t,{replace:n}={}){await w(this.client,eh,{id:e,labels:t,replace:n},Ri,Ar)}async remove(e,t){await w(this.client,th,{id:e,labels:t},Hu,Ar)}};const rh="sy_label_set",nh="sy_label_delete";let xi=class{constructor(e,t,n){o(this,"type","label");o(this,"retriever");o(this,"writer");o(this,"frameClient");o(this,"ontology");this.writer=new Ci(e),this.retriever=new Ai(e),this.frameClient=t,this.ontology=n}async search(e){return await this.retriever.search(e)}async retrieve(e){const t=Array.isArray(e),n=await this.retriever.retrieve(e);return t?n:n[0]}async retrieveFor(e){return await this.retriever.retrieveFor(new T(e))}async label(e,t,n={}){await this.writer.set(new T(e),t,n)}async removeLabels(e,t){await this.writer.remove(new T(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 Re(this.frameClient,rh,nh,sh)}async trackLabelsOf(e){const t=new Ie.Observer,n=(await this.retrieveFor(e)).map(a=>({id:new T({key:a.key,type:"label"}),key:a.key,name:a.name,data:a}));return(await this.ontology.openDependentTracker({target:new T(e),dependents:n,relationshipType:"labeled_by"})).onChange(a=>t.notify(a.map(c=>{var l,u;return{key:c.id.key,color:(l=c.data)==null?void 0:l.color,name:(u=c.data)==null?void 0:u.name}}))),t}};const sh=(r,e)=>r==="delete"?e.toUUIDs().map(t=>({variant:r,key:t})):e.parseJSON(At).map(t=>({variant:r,key:t.key,value:t})),ih=Object.freeze(Object.defineProperty({__proto__:null,Client:xi,LabelOntologyType:ki,Retriever:Ai,Writer:Ci,keyZ:tt,labelZ:At,newLabelPayloadZ:$i,ontologyID:_u},Symbol.toStringTag,{value:"Module"})),H=s.z.string().uuid(),$t=s.z.object({key:H,name:s.z.string().min(1),timeRange:W.z,color:s.z.string().optional()}),Pi=$t.extend({key:s.z.string().uuid().optional()}),Di=r=>{const e=O(r),t=e.length===0;let n=!1;return t||(n=H.safeParse(e[0]).success),{single:!Array.isArray(r),variant:n?"keys":"names",normalized:e,actual:r,empty:t}},ji="range",Mi="range-alias",ah=r=>new T({type:ji,key:r}),oh=r=>new T({type:Mi,key:r}),ch="sy_range_alias_set",lh="sy_range_alias_delete",uh=s.z.object({range:H,aliases:s.z.string().array()}),hh=s.z.object({aliases:s.z.record(s.z.string(),we)}),yh=s.z.object({range:H,aliases:s.z.record(we.or(s.z.string()),s.z.string())}),dh=s.z.unknown(),fh=s.z.object({range:H,channels:we.array()}),ph=s.z.unknown(),gh=s.z.object({range:H}),mh=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},uh,hh);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},yh,dh)}async list(){return(await w(this.client,ae.LIST_ENDPOINT,{range:this.rangeKey},gh,mh)).aliases}async delete(e){await w(this.client,ae.DELETE_ENDPOINT,{range:this.rangeKey,channels:e},fh,ph)}async openChangeTracker(){return await Re(this.frameClient,ch,lh,vh(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 Yr=ae;const wh=s.z.object({range:H,channel:we,alias:s.z.string()}),bh="---",vh=r=>(e,t)=>e==="delete"?t.toStrings().filter(n=>n.split(bh)[0]===r).map(n=>({variant:e,key:n,value:void 0})):t.parseJSON(wh).map(n=>({variant:e,key:n.alias,value:n})),Th=s.z.object({range:H,keys:s.z.string().array()}),nn=s.z.object({range:H,key:s.z.string(),value:s.z.string()}),Oh=s.z.object({pairs:be(nn)}),zh=s.z.object({range:H,pairs:nn.array()}),Eh=s.z.object({range:H,keys:s.z.string().array()}),de=class de{constructor(e,t,n){o(this,"rangeKey");o(this,"client");o(this,"frameClient");this.rangeKey=e,this.client=t,this.frameClient=n}async get(e){const t=await w(this.client,de.GET_ENDPOINT,{range:this.rangeKey,keys:O(e)},Th,Oh);return typeof e=="string"?t.pairs[0].value:Object.fromEntries(t.pairs.map(n=>[n.key,n.value]))}async list(){return this.get([])}async set(e,t=""){let n;Vr(e)?n=Object.entries(e).map(([i,a])=>({range:this.rangeKey,key:i,value:a})):n=[{range:this.rangeKey,key:e,value:t}],await w(this.client,de.SET_ENDPOINT,{range:this.rangeKey,pairs:n},zh,s.z.unknown())}async delete(e){await w(this.client,de.DELETE_ENDPOINT,{range:this.rangeKey,keys:O(e)},Eh,s.z.unknown())}async openTracker(){return await Re(this.frameClient,"sy_range_kv_set","sy_range_kv_delete",(e,t)=>e==="delete"?t.toStrings().map(n=>{const[i,a]=n.split("<--->",2);return{variant:e,key:n,value:{range:i,key:a,value:""}}}):t.parseJSON(nn).map(n=>({variant:e,key:`${n.range}${n.key}`,value:n})))}};o(de,"GET_ENDPOINT","/range/kv/get"),o(de,"SET_ENDPOINT","/range/kv/set"),o(de,"DELETE_ENDPOINT","/range/kv/delete");let Tt=de;const $r=r=>new T({type:"range",key:r});class Zi{constructor(e,t=W.ZERO,n,i,a,c,l,u,h,p,g){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");o(this,"ontologyClient");o(this,"rangeClient");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=h,this.ontologyClient=p,this.rangeClient=g}get ontologyID(){return new T({key:this.key,type:"range"})}get payload(){return{key:this.key,name:this.name,timeRange:this.timeRange,color:this.color}}async setAlias(e,t){const n=await this.channels.retrieve(e);if(n.length===0)throw new Q(`Channel ${e} does not exist`);await this.aliaser.set({[n[0].key]:t})}async deleteAlias(...e){await this.aliaser.delete(e)}async listAliases(){return await this.aliaser.list()}async resolveAlias(e){return await this.aliaser.resolve(e)}async openAliasTracker(){return await this.aliaser.openChangeTracker()}async retrieveParent(){return this.rangeClient.retrieveParent(this.key)}async retrieveChildren(){const e=(await this.ontologyClient.retrieveChildren(this.ontologyID,{excludeFieldData:!0,types:["range"]})).map(t=>t.id.key);return await this.rangeClient.retrieve(e)}async read(e){return await this.frameClient.read(this.timeRange,e)}async labels(){return await this.labelClient.retrieveFor($r(this.key))}async addLabel(...e){await this.labelClient.label($r(this.key),e)}async removeLabel(...e){await this.labelClient.removeLabels($r(this.key),e)}async openChildRangeTracker(){const e=new Ie.Observer,t=(await this.retrieveChildren()).map(i=>{const a=new T({key:i.key,type:"range"});return{id:a,key:a.toString(),name:i.name,data:i.payload}}),n=await this.ontologyClient.openDependentTracker({target:this.ontologyID,dependents:t,resourceType:"range"});return n.onChange(i=>e.notify(this.rangeClient.resourcesToRanges(i))),e.setCloser(async()=>await n.close()),e}async openParentRangeTracker(){const e=new Ie.Observer,t=await this.retrieveParent();if(t==null)return null;const n=new T({key:t.key,type:"range"}),i={id:n,key:n.toString(),name:t.name,data:t.payload},a=await this.ontologyClient.openDependentTracker({target:this.ontologyID,dependents:[i],relationshipDirection:"to"});return a.onChange(c=>{const l=this.rangeClient.resourcesToRanges(c);if(l.length===0)return;const u=l[0];e.notify(u)}),e.setCloser(async()=>await a.close()),e}}const Sh=s.z.object({keys:H.array().optional(),names:s.z.array(s.z.string()).optional(),term:s.z.string().optional(),overlapsWith:W.z.optional(),limit:s.z.number().int().optional(),offset:s.z.number().int().optional()}),Nh="/range/retrieve",Ih=s.z.object({ranges:be($t)});let Ui=class{constructor(e,t,n,i,a,c){o(this,"type","range");o(this,"frameClient");o(this,"writer");o(this,"unaryClient");o(this,"channels");o(this,"labelClient");o(this,"ontologyClient");this.frameClient=e,this.writer=t,this.unaryClient=n,this.channels=i,this.labelClient=a,this.ontologyClient=c}async create(e,t){const n=!Array.isArray(e),i=this.sugarMany(await this.writer.create(O(e),t));return n?i[0]:i}async rename(e,t){await this.writer.rename(e,t)}async delete(e){await this.writer.delete(O(e))}async search(e){return this.sugarMany(await this.execRetrieve({term:e}))}async page(e,t){return this.sugarMany(await this.execRetrieve({offset:e,limit:t}))}async retrieve(e){if(typeof e=="object"&&"start"in e)return await this.execRetrieve({overlapsWith:new W(e)});const{single:t,actual:n,variant:i,normalized:a,empty:c}=Di(e);if(c)return[];const l=await this.execRetrieve({[i]:a});if(!t)return l;if(l.length===0)throw new Ae(`range matching ${n} not found`);if(l.length>1)throw new $e(`multiple ranges matching ${n} found`);return l[0]}getKV(e){return new Tt(e,this.unaryClient,this.frameClient)}async execRetrieve(e){const{ranges:t}=await w(this.unaryClient,Nh,e,Sh,Ih);return this.sugarMany(t)}async retrieveParent(e){const t=await this.ontologyClient.retrieveParents({key:e,type:"range"});if(t.length===0)return null;const n=t[0];return n.id.type!=="range"?null:await this.retrieve(n.id.key)}sugarOne(e){return new Zi(e.name,e.timeRange,e.key,e.color,this.frameClient,new Tt(e.key,this.unaryClient,this.frameClient),new Yr(e.key,this.frameClient,this.unaryClient),this.channels,this.labelClient,this.ontologyClient,this)}sugarMany(e){return e.map(t=>this.sugarOne(t))}async openTracker(){return await Re(this.frameClient,"sy_range_set","sy_range_delete",(e,t)=>e==="delete"?t.toStrings().map(i=>({variant:e,key:i,value:void 0})):this.sugarMany(t.parseJSON($t)).map(i=>({variant:e,key:i.key,value:i})))}resourcesToRanges(e){return e.map(t=>this.resourceToRange(t))}resourceToRange(e){var t,n,i;return this.sugarOne({key:e.id.key,name:(t=e.data)==null?void 0:t.name,timeRange:new W((n=e.data)==null?void 0:n.timeRange),color:(i=e.data)==null?void 0:i.color})}};const kh=s.z.object({ranges:$t.array()}),Ah=s.z.object({parent:G.optional(),ranges:Pi.array()}),$h=s.z.object({keys:H.array()}),Rh=s.z.object({}),Ch=s.z.object({key:H,name:s.z.string()}),xh=s.z.object({}),Ph="/range/create",Dh="/range/delete",jh="/range/rename";let Bi=class{constructor(e){o(this,"client");this.client=e}async rename(e,t){await w(this.client,jh,{key:e,name:t},Ch,xh)}async create(e,t){return(await w(this.client,Ph,{ranges:e,...t},Ah,kh)).ranges}async delete(e){await w(this.client,Dh,{keys:e},$h,Rh)}};const Mh=Object.freeze(Object.defineProperty({__proto__:null,Client:Ui,KV:Tt,Range:Zi,RangeAliasOntologyType:Mi,RangeOntologyType:ji,Writer:Bi,analyzeParams:Di,keyZ:H,newPayloadZ:Pi,payloadZ:$t,rangeAliasOntologyID:oh,rangeOntologyID:ah},Symbol.toStringTag,{value:"Module"})),Zh="/api/v1/";class Uh{constructor(e,t=!1){o(this,"url");o(this,"unary");o(this,"stream");o(this,"secure");this.secure=t,this.url=e.child(Zh);const n=new Qe.JSONCodec;this.unary=new ro(this.url,n,this.secure),this.stream=new ho(this.url,n,this.secure)}use(...e){this.unary.use(...e),this.stream.use(...e)}}const sn=s.z.string().uuid(),an=s.z.object({key:s.z.string(),name:s.z.string(),data:Kr.or(s.z.string().transform(r=>JSON.parse(r)))}),Bh=s.z.object({keys:s.z.string().array()}),Lh=s.z.object({linePlots:an.array()});let qh=class{constructor(e){o(this,"ENDPOINT","/workspace/lineplot/retrieve");o(this,"client");this.client=e}async retrieve(e){const t=O(e);return(await w(this.client,this.ENDPOINT,{keys:t},Bh,Lh)).linePlots}};const ve=s.z.string().uuid(),Li=r=>JSON.parse(r),on=s.z.object({name:s.z.string(),key:ve,layout:Kr.or(s.z.string().transform(r=>Li(r)))}),cn=on.omit({layout:!0}).extend({layout:s.z.string().transform(r=>Li(r))}),qi="workspace",Yh=r=>new T({type:qi,key:r}),Wh=an.partial({key:!0}).transform(r=>({...r,data:JSON.stringify(r.data)})),_h=s.z.object({workspace:ve,linePlots:Wh.array()}),Vh=s.z.object({linePlots:an.array()}),Fh=s.z.object({keys:sn.array()}),Kh=s.z.object({}),Gh=s.z.object({key:sn,name:s.z.string()}),Jh=s.z.object({}),Hh=s.z.object({key:sn,data:s.z.string()}),Xh=s.z.object({}),Qh="/workspace/lineplot/create",ey="/workspace/lineplot/delete",ty="/workspace/lineplot/rename",ry="/workspace/lineplot/set-data";let ny=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,Qh,{workspace:e,linePlots:[n]},_h,Vh)).linePlots[0]}async delete(e){const t=O(e);await w(this.client,ey,{keys:t},Fh,Kh)}async rename(e,t){await w(this.client,ty,{key:e,name:t},Gh,Jh)}async setData(e,t){await w(this.client,ry,{key:e,data:JSON.stringify(t)},Hh,Xh)}},sy=class{constructor(e){o(this,"writer");o(this,"retriever");this.writer=new ny(e),this.retriever=new qh(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 iy=s.z.object({keys:ve.array().optional(),search:s.z.string().optional(),author:s.z.string().uuid().optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),ay=s.z.object({workspaces:be(cn)});var Se;let oy=(Se=class{constructor(e){o(this,"client");this.client=e}async retrieve(e){const t=O(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,Se.ENDPOINT,e,iy,ay)).workspaces}},o(Se,"ENDPOINT","/workspace/retrieve"),Se);const hr=s.z.string().uuid(),cy=s.z.object({key:s.z.string(),name:s.z.string(),data:Kr.or(s.z.string().transform(r=>JSON.parse(r))),snapshot:s.z.boolean()}),ln=s.z.object({key:s.z.string(),name:s.z.string(),snapshot:s.z.boolean(),data:s.z.string().transform(r=>JSON.parse(r))}),ly=s.z.object({keys:s.z.string().array()}),uy=s.z.object({schematics:ln.array()});class hy{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:O(e)},ly,uy)).schematics}}const yy=cy.partial({key:!0,snapshot:!0}).transform(r=>({...r,data:JSON.stringify(r.data)})),dy=s.z.object({workspace:ve,schematics:yy.array()}),fy=s.z.object({schematics:ln.array()}),py=s.z.object({keys:hr.array()}),gy=s.z.object({}),my=s.z.object({key:hr,name:s.z.string()}),Hn=s.z.object({}),wy=s.z.object({key:hr,data:s.z.string()});s.z.object({});const by=s.z.object({key:hr,name:s.z.string(),snapshot:s.z.boolean()}),vy=s.z.object({schematic:ln}),Ty="/workspace/schematic/create",Oy="/workspace/schematic/delete",zy="/workspace/schematic/rename",Ey="/workspace/schematic/set-data",Sy="/workspace/schematic/copy";let Ny=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,Ty,{workspace:e,schematics:[n]},dy,fy)).schematics[0]}async copy(e,t,n){return(await w(this.client,Sy,{key:e,name:t,snapshot:n},by,vy)).schematic}async delete(e){const t=O(e);await w(this.client,Oy,{keys:t},py,gy)}async rename(e,t){await w(this.client,zy,{key:e,name:t},my,Hn)}async setData(e,t){await w(this.client,Ey,{key:e,data:JSON.stringify(t)},wy,Hn)}},Iy=class{constructor(e){o(this,"writer");o(this,"retriever");this.writer=new Ny(e),this.retriever=new hy(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 ky=on.partial({key:!0}).transform(r=>({...r,layout:JSON.stringify(r.layout)})),Ay=s.z.object({workspaces:ky.array()}),$y=s.z.object({workspaces:cn.array()}),Ry=s.z.object({keys:ve.array()}),Cy=s.z.object({}),xy=s.z.object({key:ve,name:s.z.string()}),Py=s.z.object({}),Dy=s.z.object({key:ve,layout:s.z.string()}),jy=s.z.object({}),My="/workspace/create",Zy="/workspace/delete",Uy="/workspace/rename",By="/workspace/set-layout";class Ly{constructor(e){o(this,"client");this.client=e}async create(e){return(await w(this.client,My,{workspaces:O(e)},Ay,$y)).workspaces}async delete(e){await w(this.client,Zy,{keys:O(e)},Ry,Cy)}async rename(e,t){await w(this.client,Uy,{key:e,name:t},xy,Py)}async setLayout(e,t){await w(this.client,By,{key:e,layout:JSON.stringify(t)},Dy,jy)}}class Yi{constructor(e){o(this,"type","workspace");o(this,"schematic");o(this,"linePlot");o(this,"retriever");o(this,"writer");this.schematic=new Iy(e),this.linePlot=new sy(e),this.retriever=new oy(e),this.writer=new Ly(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 qy=Object.freeze(Object.defineProperty({__proto__:null,Client:Yi,WorkspaceOntologyType:qi,keyZ:ve,ontologyID:Yh,workspaceRemoteZ:cn,workspaceZ:on},Symbol.toStringTag,{value:"Module"})),Wi=s.z.object({host:s.z.string({required_error:"Host is required"}).min(1,"Host is required"),port:s.z.number({required_error:"Port is required"}).or(s.z.string({required_error:"Port is required"})),username:s.z.string().min(1,"Username is required"),password:s.z.string().min(1,"Password is required"),connectivityPollFrequency:E.z.default(E.seconds(30)),secure:s.z.boolean().optional().default(!1),name:s.z.string().optional()});class _i extends di{constructor(t){const n=Wi.parse(t),{host:i,port:a,username:c,password:l,connectivityPollFrequency:u,secure:h}=n,p=new Uh(new Ec({host:i,port:Number(a)}),h);p.use(jc);let g;c!=null&&l!=null&&(g=new Zl(p.unary,{username:c,password:l}),p.use(g.middleware()));const D=new Gr(new wt(p.unary)),P=new ni(p.unary,D);super(p.stream,p.unary,D);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");o(this,"clientVersion","0.29.0");this.createdAt=S.now(),this.props=n,this.auth=g,this.transport=p,this.channels=new ri(this,D,p.unary,P),this.connectivity=new bt(p.unary,u,this.clientVersion,n.name),this.control=new pi(this),this.ontology=new Js(p.unary,this);const X=new Bi(this.transport.unary);this.labels=new xi(this.transport.unary,this,this.ontology),this.ranges=new Ui(this,X,this.transport.unary,D,this.labels,this.ontology),this.access=new xl(this.transport.unary),this.user=new Dl(this.transport.unary),this.workspaces=new Yi(this.transport.unary);const j=new Ti(this.transport.unary,this),un=new Ii(this.transport.unary,this,this.ontology,this.ranges),Vi=new Oi(this.transport.unary,this,un);this.hardware=new gi(un,Vi,j)}get key(){return this.createdAt.valueOf().toString()}close(){this.connectivity.stopChecking()}}o(_i,"connectivity",bt);const Yy=Je.Authority;exports.AuthError=ke;exports.Authority=Yy;exports.Channel=Jr;exports.ContiguityError=Br;exports.DataType=z;exports.Density=F;exports.Frame=U;exports.MultiSeries=Ms;exports.MultipleFoundError=$e;exports.NotFoundError=Ae;exports.QueryError=Q;exports.Rate=tr;exports.RouteError=mt;exports.Series=ze;exports.Synnax=_i;exports.TimeRange=W;exports.TimeSpan=E;exports.TimeStamp=S;exports.UnexpectedError=pe;exports.ValidationError=x;exports.channel=Ol;exports.connection=Ll;exports.control=cu;exports.device=Ou;exports.framer=nu;exports.hardware=lu;exports.label=ih;exports.ontology=el;exports.rack=Au;exports.ranger=Mh;exports.signals=yu;exports.synnaxPropsZ=Wi;exports.task=Wu;exports.workspace=qy;
|
|
41
|
+
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 qr=new E(-1);var tn=(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))(tn||{}),hi=(r=>(r[r.None=0]="None",r[r.Ack=1]="Ack",r[r.Data=2]="Data",r))(hi||{});const Vl=s.z.object({command:s.z.nativeEnum(tn),span:E.z.optional(),bounds:W.z.optional(),stamp:S.z.optional(),keys:s.z.number().array().optional(),chunkSize:s.z.number().optional()}),Fl=s.z.object({variant:s.z.nativeEnum(hi),ack:s.z.boolean(),command:s.z.nativeEnum(tn),error:Ot.optional().nullable(),frame:ar.optional()}),ft=class ft{constructor(e,t){o(this,"stream");o(this,"adapter");o(this,"value");this.stream=new en("Iterator",e),this.value=new U,this.adapter=t}static async _open(e,t,n,i,a={}){const c=await or.open(n,t),l=await i.stream(ft.ENDPOINT,Vl,Fl),u=new ft(l,c);return await u.execute({command:0,keys:c.keys,bounds:new W(e),chunkSize:a.chunkSize??1e5}),u}async next(e=qr){return await this.execute({command:1,span:new E(e)})}async prev(e=qr){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 S(e)})}async seekGE(e){return await this.execute({command:6,stamp:new S(e)})}async valid(){return await this.execute({command:7})}async close(){await this.stream.closeAndAck()}[Symbol.asyncIterator](){return new Kl(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(ft,"ENDPOINT","/frame/iterate");let Jt=ft;class Kl{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 Gl=s.z.object({keys:s.z.number().array()}),Jl=s.z.object({frame:ar,error:Ot.optional().nullable()}),Hl="/frame/stream";class cr{constructor(e,t){o(this,"stream");o(this,"adapter");this.stream=new en("Streamer",e),this.adapter=t}get keys(){return this.adapter.keys}static async _open(e,t,{channels:n}){const i=await or.open(e,n),a=await t.stream(Hl,Gl,Jl),c=new cr(a,i);a.send({keys:i.keys});const[,l]=await a.receive();if(l!=null)throw l;return c}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 Nt extends Ie.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 rn=(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))(rn||{}),Xe=(r=>(r[r.PersistStream=1]="PersistStream",r[r.Persist=2]="Persist",r[r.Stream=3]="Stream",r))(Xe||{});const Xl=r=>{switch(r){case"persist":return 2;case"stream":return 3;case"persistStream":return 1;default:if(typeof r=="number"&&r in Xe)return r;throw new Error(`invalid writer mode: ${r}`)}},Ql=new E(-1),eu=s.z.object({start:S.z.optional(),controlSubject:Je.subjectZ.optional(),keys:s.z.number().array().optional(),authorities:Je.Authority.z.array().optional(),mode:s.z.nativeEnum(Xe).optional(),errOnUnauthorized:s.z.boolean().optional(),enableAutoCommit:s.z.boolean().optional(),autoIndexPersistInterval:E.z.optional()}),tu=s.z.object({command:s.z.nativeEnum(rn),config:eu.optional(),frame:ar.optional()}),ru=s.z.object({ack:s.z.boolean(),command:s.z.nativeEnum(rn),error:Ot.optional().nullable()});var fe;let yi=(fe=class{constructor(e,t){o(this,"stream");o(this,"adapter");this.stream=new en("Writer",e),this.adapter=t}static async _open(e,t,{channels:n,start:i=S.now(),authorities:a=Je.Authority.Absolute,controlSubject:c,mode:l=1,errOnUnauthorized:u=!1,enableAutoCommit:h=!1,autoIndexPersistInterval:p=E.SECOND}){const g=await Qr.open(e,n),D=await t.stream(fe.ENDPOINT,tu,ru),P=new fe(D,g);return await P.execute({command:0,config:{start:new S(i),keys:g.keys,controlSubject:c,authorities:O(a),mode:Xl(l),errOnUnauthorized:u,enableAutoCommit:h,autoIndexPersistInterval:p}}),P}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?_r(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),di=class{constructor(e,t,n){o(this,"streamClient");o(this,"retriever");o(this,"deleter");this.streamClient=e,this.retriever=n,this.deleter=new _l(t)}async openIterator(e,t,n){return await Jt._open(e,t,this.retriever,this.streamClient,n)}async openWriter(e){return(Array.isArray(e)||typeof e!="object")&&(e={channels:e}),await yi._open(this.retriever,this.streamClient,e)}async openStreamer(e){return(Array.isArray(e)||typeof e!="object")&&(e={channels:e}),await cr._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:Xe.Persist});try{await c.write(a),await c.commit()}finally{await c.close()}return}const i=await this.openWriter({start:e,channels:t,mode:Xe.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 nu=Object.freeze(Object.defineProperty({__proto__:null,ALWAYS_INDEX_PERSIST_ON_AUTO_COMMIT:Ql,AUTO_SPAN:qr,Client:di,Frame:U,Iterator:Jt,ObservableStreamer:Nt,Streamer:cr,Writer:yi,WriterMode:Xe,frameZ:ar,series:ci,seriesFromPayload:li,seriesToPayload:ui},Symbol.toStringTag,{value:"Module"})),su=Je.Authority,iu=Je.stateZ(s.z.number()),au=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 fi extends Nt{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 Qe.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 ou="sy_node_1_control";let pi=class{constructor(e){o(this,"framer");this.framer=e}async openStateTracker(){const e=await this.framer.openStreamer(ou);return new fi(e)}};const cu=Object.freeze(Object.defineProperty({__proto__:null,Authority:su,Client:pi,StateTracker:fi,stateZ:iu,transferString:au},Symbol.toStringTag,{value:"Module"}));let gi=class{constructor(e,t,n){o(this,"tasks");o(this,"racks");o(this,"devices");this.tasks=e,this.racks=t,this.devices=n}};const lu=Object.freeze(Object.defineProperty({__proto__:null,Client:gi},Symbol.toStringTag,{value:"Module"})),et=s.z.number(),lr=s.z.object({key:et,name:s.z.string()}),mi=lr.partial({key:!0}),wi="rack",uu=r=>new T({type:wi,key:r.toString()}),ur=s.z.string(),It=s.z.object({key:ur,rack:et,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===""?{}:Qe.JSON_CODEC.decodeString(r)))}),bi=It.extend({properties:s.z.unknown().transform(r=>Qe.JSON_CODEC.encodeString(r))}),vi="device",hu=r=>new T({type:vi,key:r.toString()}),Re=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 Nt(i,a)},yu=Object.freeze(Object.defineProperty({__proto__:null,openObservable:Re},Symbol.toStringTag,{value:"Module"})),du="sy_device_set",fu="sy_device_delete",zr="/hardware/device/retrieve",pu="/hardware/device/create",gu="/hardware/device/delete",mu=s.z.object({devices:bi.array()}),wu=s.z.object({devices:It.array()}),bu=s.z.object({keys:ur.array()}),vu=s.z.object({}),Er=s.z.object({search:s.z.string().optional(),limit:s.z.number().optional(),offset:s.z.number().optional(),keys:ur.array().optional(),names:s.z.string().array().optional(),makes:s.z.string().array().optional()}),Sr=s.z.object({devices:be(It)});let Ti=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,zr,{keys:O(e),...t},Er,Sr);return ir("Device",e,i.devices,n),n?i.devices[0]:i.devices}async search(e,t){return(await w(this.client,zr,{search:e,...t},Er,Sr)).devices}async page(e,t,n){return(await w(this.client,zr,{offset:e,limit:t,...n},Er,Sr)).devices}async create(e){const t=!Array.isArray(e),n=await w(this.client,pu,{devices:O(e)},mu,wu);return t?n.devices[0]:n.devices}async delete(e){await w(this.client,gu,{keys:O(e)},bu,vu)}async openDeviceTracker(){return await Re(this.frameClient,du,fu,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(It).map(t=>({variant:r,key:t.key,value:t})),Ou=Object.freeze(Object.defineProperty({__proto__:null,Client:Ti,DeviceOntologyType:vi,deviceKeyZ:ur,deviceZ:It,newDeviceZ:bi,ontologyID:hu},Symbol.toStringTag,{value:"Module"})),Nr="/hardware/rack/retrieve",zu="/hardware/rack/create",Eu="/hardware/rack/delete",Ir=s.z.object({keys:et.array().optional(),names:s.z.string().array().optional(),search:s.z.string().optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),kr=s.z.object({racks:be(lr)}),Su=s.z.object({racks:mi.array()}),Nu=s.z.object({racks:lr.array()}),Iu=s.z.object({keys:et.array()}),ku=s.z.object({});let Oi=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,Eu,{keys:O(e)},Iu,ku)}async create(e){const t=!Array.isArray(e),n=await w(this.client,zu,{racks:O(e)},Su,Nu),i=this.sugar(n.racks);return t?i[0]:i}async search(e){const t=await w(this.client,Nr,{search:e},Ir,kr);return this.sugar(t.racks)}async page(e,t){const n=await w(this.client,Nr,{offset:e,limit:t},Ir,kr);return this.sugar(n.racks)}async retrieve(e){const{variant:t,normalized:n,single:i}=sr(e,{string:"names",number:"keys"}),a=await w(this.client,Nr,{[t]:n},Ir,kr),c=this.sugar(a.racks);return ir("Rack",e,c,i),i?c[0]:c}sugar(e){return e.map(({key:t,name:n})=>new zi(t,n,this.tasks))}};class zi{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 Au=Object.freeze(Object.defineProperty({__proto__:null,Client:Oi,Rack:zi,RackOntologyType:wi,newRackZ:mi,ontologyID:uu,rackKeyZ:et,rackZ:lr},Symbol.toStringTag,{value:"Module"})),Ce=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:Ce,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())}),kt=s.z.object({key:Ce,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===""?{}:Qe.JSON_CODEC.decodeString(r))),state:vt.optional().nullable(),snapshot:s.z.boolean().optional()}),Ei=kt.omit({key:!0}).extend({key:Ce.transform(r=>r.toString()).optional(),config:s.z.unknown().transform(r=>Qe.JSON_CODEC.encodeString(r))}),$u=s.z.object({task:Ce,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)))}),Si="task",Ru=r=>new T({type:Si,key:r.toString()}),dt="sy_task_state",Jn="sy_task_cmd",Pt=new Error("Task not created");class Ni{constructor(e,t,n,i,a=!1,c=!1,l,u=null,h=null,p=null){o(this,"key");o(this,"name");o(this,"internal");o(this,"type");o(this,"config");o(this,"snapshot");o(this,"state");o(this,"frameClient");o(this,"ontologyClient");o(this,"rangeClient");this.key=e,this.name=t,this.type=n,this.config=i,this.internal=a,this.snapshot=c,l!==null&&(this.state=l),this.frameClient=u,this.ontologyClient=h,this.rangeClient=p}get payload(){return{key:this.key,name:this.name,type:this.type,config:this.config,state:this.state,internal:this.internal}}get ontologyID(){return new T({type:"task",key:this.key})}async executeCommand(e,t){if(this.frameClient==null)throw Pt;const n=await this.frameClient.openWriter(Jn),i=ac.id();return await n.write(Jn,[{task:this.key,type:e,key:i,args:t}]),await n.close(),i}async executeCommandSync(e,t,n){if(this.frameClient==null)throw Pt;const i=await this.frameClient.openStreamer(dt),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 h=vt.safeParse(u.at(-1).sy_task_state);if(h.success){if(c=h.data,c.key===a)break}else console.error(h.error)}return i.close(),c}async openStateObserver(){if(this.frameClient==null)throw Pt;return new Nt(await this.frameClient.openStreamer(dt),e=>{const t=e.get(dt);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]})}async snapshottedTo(){if(this.ontologyClient==null||this.rangeClient==null)throw Pt;if(!this.snapshot)return null;const e=await this.ontologyClient.retrieveParents(this.ontologyID);return e.length==0?null:e[0]}}const Cu=s.z.object({rack:et.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()}),xu=s.z.object({tasks:be(kt)}),Pu="/hardware/task/retrieve",Du="/hardware/task/create",ju="/hardware/task/delete",Mu="/hardware/task/copy",Zu=s.z.object({tasks:Ei.array()}),Uu=s.z.object({tasks:kt.array()}),Bu=s.z.object({keys:Ce.array()}),Lu=s.z.object({}),qu=s.z.object({key:Ce,name:s.z.string(),snapshot:s.z.boolean()}),Yu=s.z.object({task:kt});let Ii=class{constructor(e,t,n,i){o(this,"type","task");o(this,"client");o(this,"frameClient");o(this,"ontologyClient");o(this,"rangeClient");this.client=e,this.frameClient=t,this.ontologyClient=n,this.rangeClient=i}async create(e){const t=!Array.isArray(e),n=await w(this.client,Du,{tasks:O(e)},Zu,Uu),i=this.sugar(n.tasks);return t?i[0]:i}async delete(e){await w(this.client,ju,{keys:O(e)},Bu,Lu)}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}=sr(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 copy(e,t,n){const i=await w(this.client,Mu,{key:e,name:t,snapshot:n},qu,Yu);return this.sugar([i.task])[0]}async retrieveByName(e,t){const n=await this.execRetrieve({names:[e],rack:t});return ir("Task",e,n,!0),this.sugar(n)[0]}async execRetrieve(e){return(await w(this.client,Pu,e,Cu,xu)).tasks}sugar(e){return e.map(({key:t,name:n,type:i,config:a,state:c,internal:l,snapshot:u})=>new Ni(t,n,i,a,l,u,c,this.frameClient,this.ontologyClient,this.rangeClient))}async openTracker(){return await Re(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 Nt(await this.frameClient.openStreamer(dt),e=>{const t=e.get(dt);if(t.length===0)return[null,!1];const n=vt.safeParse(t.at(-1));return n.success?[n.data,!0]:[null,!1]})}};const Wu=Object.freeze(Object.defineProperty({__proto__:null,Client:Ii,DeviceOntologyType:Si,Task:Ni,commandZ:$u,newTaskZ:Ei,ontologyID:Ru,stateZ:vt,taskKeyZ:Ce,taskZ:kt},Symbol.toStringTag,{value:"Module"})),tt=s.z.string().uuid(),At=s.z.object({key:tt,name:s.z.string().min(1),color:s.z.string()}),ki="label",_u=r=>new T({type:ki,key:r}),Vu=s.z.object({keys:tt.array().optional(),for:G.optional(),search:s.z.string().optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),Fu=s.z.object({labels:be(At)});var Ee;let Ai=(Ee=class{constructor(e){o(this,"client");this.client=e}async retrieve(e){const t=O(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(Ee.ENDPOINT,e,Vu,Fu);if(n!=null)throw n;return t.labels}},o(Ee,"ENDPOINT","/label/retrieve"),Ee);const $i=At.extend({key:tt.optional()}),Ku=s.z.object({labels:$i.array()}),Gu=s.z.object({labels:At.array()}),Ju=s.z.object({keys:tt.array()}),Ri=s.z.object({id:G,labels:tt.array(),replace:s.z.boolean().optional()}),Hu=Ri.omit({replace:!0}),Ar=s.z.object({}),Xu="/label/create",Qu="/label/delete",eh="/label/set",th="/label/remove";let Ci=class{constructor(e){o(this,"client");this.client=e}async create(e){return(await w(this.client,Xu,{labels:O(e)},Ku,Gu)).labels}async delete(e){await w(this.client,Qu,{keys:O(e)},Ju,Ar)}async set(e,t,{replace:n}={}){await w(this.client,eh,{id:e,labels:t,replace:n},Ri,Ar)}async remove(e,t){await w(this.client,th,{id:e,labels:t},Hu,Ar)}};const rh="sy_label_set",nh="sy_label_delete";let xi=class{constructor(e,t,n){o(this,"type","label");o(this,"retriever");o(this,"writer");o(this,"frameClient");o(this,"ontology");this.writer=new Ci(e),this.retriever=new Ai(e),this.frameClient=t,this.ontology=n}async search(e){return await this.retriever.search(e)}async retrieve(e){const t=Array.isArray(e),n=await this.retriever.retrieve(e);return t?n:n[0]}async retrieveFor(e){return await this.retriever.retrieveFor(new T(e))}async label(e,t,n={}){await this.writer.set(new T(e),t,n)}async removeLabels(e,t){await this.writer.remove(new T(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 Re(this.frameClient,rh,nh,sh)}async trackLabelsOf(e){const t=new Ie.Observer,n=(await this.retrieveFor(e)).map(a=>({id:new T({key:a.key,type:"label"}),key:a.key,name:a.name,data:a}));return(await this.ontology.openDependentTracker({target:new T(e),dependents:n,relationshipType:"labeled_by"})).onChange(a=>t.notify(a.map(c=>{var l,u;return{key:c.id.key,color:(l=c.data)==null?void 0:l.color,name:(u=c.data)==null?void 0:u.name}}))),t}};const sh=(r,e)=>r==="delete"?e.toUUIDs().map(t=>({variant:r,key:t})):e.parseJSON(At).map(t=>({variant:r,key:t.key,value:t})),ih=Object.freeze(Object.defineProperty({__proto__:null,Client:xi,LabelOntologyType:ki,Retriever:Ai,Writer:Ci,keyZ:tt,labelZ:At,newLabelPayloadZ:$i,ontologyID:_u},Symbol.toStringTag,{value:"Module"})),H=s.z.string().uuid(),$t=s.z.object({key:H,name:s.z.string().min(1),timeRange:W.z,color:s.z.string().optional()}),Pi=$t.extend({key:s.z.string().uuid().optional()}),Di=r=>{const e=O(r),t=e.length===0;let n=!1;return t||(n=H.safeParse(e[0]).success),{single:!Array.isArray(r),variant:n?"keys":"names",normalized:e,actual:r,empty:t}},ji="range",Mi="range-alias",ah=r=>new T({type:ji,key:r}),oh=r=>new T({type:Mi,key:r}),ch="sy_range_alias_set",lh="sy_range_alias_delete",uh=s.z.object({range:H,aliases:s.z.string().array()}),hh=s.z.object({aliases:s.z.record(s.z.string(),we)}),yh=s.z.object({range:H,aliases:s.z.record(we.or(s.z.string()),s.z.string())}),dh=s.z.unknown(),fh=s.z.object({range:H,channels:we.array()}),ph=s.z.unknown(),gh=s.z.object({range:H}),mh=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},uh,hh);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},yh,dh)}async list(){return(await w(this.client,ae.LIST_ENDPOINT,{range:this.rangeKey},gh,mh)).aliases}async delete(e){await w(this.client,ae.DELETE_ENDPOINT,{range:this.rangeKey,channels:e},fh,ph)}async openChangeTracker(){return await Re(this.frameClient,ch,lh,vh(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 Yr=ae;const wh=s.z.object({range:H,channel:we,alias:s.z.string()}),bh="---",vh=r=>(e,t)=>e==="delete"?t.toStrings().filter(n=>n.split(bh)[0]===r).map(n=>({variant:e,key:n,value:void 0})):t.parseJSON(wh).map(n=>({variant:e,key:n.alias,value:n})),Th=s.z.object({range:H,keys:s.z.string().array()}),nn=s.z.object({range:H,key:s.z.string(),value:s.z.string()}),Oh=s.z.object({pairs:be(nn)}),zh=s.z.object({range:H,pairs:nn.array()}),Eh=s.z.object({range:H,keys:s.z.string().array()}),de=class de{constructor(e,t,n){o(this,"rangeKey");o(this,"client");o(this,"frameClient");this.rangeKey=e,this.client=t,this.frameClient=n}async get(e){const t=await w(this.client,de.GET_ENDPOINT,{range:this.rangeKey,keys:O(e)},Th,Oh);return typeof e=="string"?t.pairs[0].value:Object.fromEntries(t.pairs.map(n=>[n.key,n.value]))}async list(){return this.get([])}async set(e,t=""){let n;Vr(e)?n=Object.entries(e).map(([i,a])=>({range:this.rangeKey,key:i,value:a})):n=[{range:this.rangeKey,key:e,value:t}],await w(this.client,de.SET_ENDPOINT,{range:this.rangeKey,pairs:n},zh,s.z.unknown())}async delete(e){await w(this.client,de.DELETE_ENDPOINT,{range:this.rangeKey,keys:O(e)},Eh,s.z.unknown())}async openTracker(){return await Re(this.frameClient,"sy_range_kv_set","sy_range_kv_delete",(e,t)=>e==="delete"?t.toStrings().map(n=>{const[i,a]=n.split("<--->",2);return{variant:e,key:n,value:{range:i,key:a,value:""}}}):t.parseJSON(nn).map(n=>({variant:e,key:`${n.range}${n.key}`,value:n})))}};o(de,"GET_ENDPOINT","/range/kv/get"),o(de,"SET_ENDPOINT","/range/kv/set"),o(de,"DELETE_ENDPOINT","/range/kv/delete");let Tt=de;const $r=r=>new T({type:"range",key:r});class Zi{constructor(e,t=W.ZERO,n,i,a,c,l,u,h,p,g){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");o(this,"ontologyClient");o(this,"rangeClient");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=h,this.ontologyClient=p,this.rangeClient=g}get ontologyID(){return new T({key:this.key,type:"range"})}get payload(){return{key:this.key,name:this.name,timeRange:this.timeRange,color:this.color}}async setAlias(e,t){const n=await this.channels.retrieve(e);if(n.length===0)throw new Q(`Channel ${e} does not exist`);await this.aliaser.set({[n[0].key]:t})}async deleteAlias(...e){await this.aliaser.delete(e)}async listAliases(){return await this.aliaser.list()}async resolveAlias(e){return await this.aliaser.resolve(e)}async openAliasTracker(){return await this.aliaser.openChangeTracker()}async retrieveParent(){return this.rangeClient.retrieveParent(this.key)}async retrieveChildren(){const e=(await this.ontologyClient.retrieveChildren(this.ontologyID,{excludeFieldData:!0,types:["range"]})).map(t=>t.id.key);return await this.rangeClient.retrieve(e)}async read(e){return await this.frameClient.read(this.timeRange,e)}async labels(){return await this.labelClient.retrieveFor($r(this.key))}async addLabel(...e){await this.labelClient.label($r(this.key),e)}async removeLabel(...e){await this.labelClient.removeLabels($r(this.key),e)}async openChildRangeTracker(){const e=new Ie.Observer,t=(await this.retrieveChildren()).map(i=>{const a=new T({key:i.key,type:"range"});return{id:a,key:a.toString(),name:i.name,data:i.payload}}),n=await this.ontologyClient.openDependentTracker({target:this.ontologyID,dependents:t,resourceType:"range"});return n.onChange(i=>e.notify(this.rangeClient.resourcesToRanges(i))),e.setCloser(async()=>await n.close()),e}async openParentRangeTracker(){const e=new Ie.Observer,t=await this.retrieveParent();if(t==null)return null;const n=new T({key:t.key,type:"range"}),i={id:n,key:n.toString(),name:t.name,data:t.payload},a=await this.ontologyClient.openDependentTracker({target:this.ontologyID,dependents:[i],relationshipDirection:"to"});return a.onChange(c=>{const l=this.rangeClient.resourcesToRanges(c);if(l.length===0)return;const u=l[0];e.notify(u)}),e.setCloser(async()=>await a.close()),e}}const Sh=s.z.object({keys:H.array().optional(),names:s.z.array(s.z.string()).optional(),term:s.z.string().optional(),overlapsWith:W.z.optional(),limit:s.z.number().int().optional(),offset:s.z.number().int().optional()}),Nh="/range/retrieve",Ih=s.z.object({ranges:be($t)});let Ui=class{constructor(e,t,n,i,a,c){o(this,"type","range");o(this,"frameClient");o(this,"writer");o(this,"unaryClient");o(this,"channels");o(this,"labelClient");o(this,"ontologyClient");this.frameClient=e,this.writer=t,this.unaryClient=n,this.channels=i,this.labelClient=a,this.ontologyClient=c}async create(e,t){const n=!Array.isArray(e),i=this.sugarMany(await this.writer.create(O(e),t));return n?i[0]:i}async rename(e,t){await this.writer.rename(e,t)}async delete(e){await this.writer.delete(O(e))}async search(e){return this.sugarMany(await this.execRetrieve({term:e}))}async page(e,t){return this.sugarMany(await this.execRetrieve({offset:e,limit:t}))}async retrieve(e){if(typeof e=="object"&&"start"in e)return await this.execRetrieve({overlapsWith:new W(e)});const{single:t,actual:n,variant:i,normalized:a,empty:c}=Di(e);if(c)return[];const l=await this.execRetrieve({[i]:a});if(!t)return l;if(l.length===0)throw new Ae(`range matching ${n} not found`);if(l.length>1)throw new $e(`multiple ranges matching ${n} found`);return l[0]}getKV(e){return new Tt(e,this.unaryClient,this.frameClient)}async execRetrieve(e){const{ranges:t}=await w(this.unaryClient,Nh,e,Sh,Ih);return this.sugarMany(t)}async retrieveParent(e){const t=await this.ontologyClient.retrieveParents({key:e,type:"range"});if(t.length===0)return null;const n=t[0];return n.id.type!=="range"?null:await this.retrieve(n.id.key)}sugarOne(e){return new Zi(e.name,e.timeRange,e.key,e.color,this.frameClient,new Tt(e.key,this.unaryClient,this.frameClient),new Yr(e.key,this.frameClient,this.unaryClient),this.channels,this.labelClient,this.ontologyClient,this)}sugarMany(e){return e.map(t=>this.sugarOne(t))}async openTracker(){return await Re(this.frameClient,"sy_range_set","sy_range_delete",(e,t)=>e==="delete"?t.toStrings().map(i=>({variant:e,key:i,value:void 0})):this.sugarMany(t.parseJSON($t)).map(i=>({variant:e,key:i.key,value:i})))}resourcesToRanges(e){return e.map(t=>this.resourceToRange(t))}resourceToRange(e){var t,n,i;return this.sugarOne({key:e.id.key,name:(t=e.data)==null?void 0:t.name,timeRange:new W((n=e.data)==null?void 0:n.timeRange),color:(i=e.data)==null?void 0:i.color})}};const kh=s.z.object({ranges:$t.array()}),Ah=s.z.object({parent:G.optional(),ranges:Pi.array()}),$h=s.z.object({keys:H.array()}),Rh=s.z.object({}),Ch=s.z.object({key:H,name:s.z.string()}),xh=s.z.object({}),Ph="/range/create",Dh="/range/delete",jh="/range/rename";let Bi=class{constructor(e){o(this,"client");this.client=e}async rename(e,t){await w(this.client,jh,{key:e,name:t},Ch,xh)}async create(e,t){return(await w(this.client,Ph,{ranges:e,...t},Ah,kh)).ranges}async delete(e){await w(this.client,Dh,{keys:e},$h,Rh)}};const Mh=Object.freeze(Object.defineProperty({__proto__:null,Client:Ui,KV:Tt,Range:Zi,RangeAliasOntologyType:Mi,RangeOntologyType:ji,Writer:Bi,analyzeParams:Di,keyZ:H,newPayloadZ:Pi,payloadZ:$t,rangeAliasOntologyID:oh,rangeOntologyID:ah},Symbol.toStringTag,{value:"Module"})),Zh="/api/v1/";class Uh{constructor(e,t=!1){o(this,"url");o(this,"unary");o(this,"stream");o(this,"secure");this.secure=t,this.url=e.child(Zh);const n=new Qe.JSONCodec;this.unary=new ro(this.url,n,this.secure),this.stream=new ho(this.url,n,this.secure)}use(...e){this.unary.use(...e),this.stream.use(...e)}}const sn=s.z.string().uuid(),an=s.z.object({key:s.z.string(),name:s.z.string(),data:Kr.or(s.z.string().transform(r=>JSON.parse(r)))}),Bh=s.z.object({keys:s.z.string().array()}),Lh=s.z.object({linePlots:an.array()});let qh=class{constructor(e){o(this,"ENDPOINT","/workspace/lineplot/retrieve");o(this,"client");this.client=e}async retrieve(e){const t=O(e);return(await w(this.client,this.ENDPOINT,{keys:t},Bh,Lh)).linePlots}};const ve=s.z.string().uuid(),Li=r=>JSON.parse(r),on=s.z.object({name:s.z.string(),key:ve,layout:Kr.or(s.z.string().transform(r=>Li(r)))}),cn=on.omit({layout:!0}).extend({layout:s.z.string().transform(r=>Li(r))}),qi="workspace",Yh=r=>new T({type:qi,key:r}),Wh=an.partial({key:!0}).transform(r=>({...r,data:JSON.stringify(r.data)})),_h=s.z.object({workspace:ve,linePlots:Wh.array()}),Vh=s.z.object({linePlots:an.array()}),Fh=s.z.object({keys:sn.array()}),Kh=s.z.object({}),Gh=s.z.object({key:sn,name:s.z.string()}),Jh=s.z.object({}),Hh=s.z.object({key:sn,data:s.z.string()}),Xh=s.z.object({}),Qh="/workspace/lineplot/create",ey="/workspace/lineplot/delete",ty="/workspace/lineplot/rename",ry="/workspace/lineplot/set-data";let ny=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,Qh,{workspace:e,linePlots:[n]},_h,Vh)).linePlots[0]}async delete(e){const t=O(e);await w(this.client,ey,{keys:t},Fh,Kh)}async rename(e,t){await w(this.client,ty,{key:e,name:t},Gh,Jh)}async setData(e,t){await w(this.client,ry,{key:e,data:JSON.stringify(t)},Hh,Xh)}},sy=class{constructor(e){o(this,"writer");o(this,"retriever");this.writer=new ny(e),this.retriever=new qh(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 iy=s.z.object({keys:ve.array().optional(),search:s.z.string().optional(),author:s.z.string().uuid().optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),ay=s.z.object({workspaces:be(cn)});var Se;let oy=(Se=class{constructor(e){o(this,"client");this.client=e}async retrieve(e){const t=O(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,Se.ENDPOINT,e,iy,ay)).workspaces}},o(Se,"ENDPOINT","/workspace/retrieve"),Se);const hr=s.z.string().uuid(),cy=s.z.object({key:s.z.string(),name:s.z.string(),data:Kr.or(s.z.string().transform(r=>JSON.parse(r))),snapshot:s.z.boolean()}),ln=s.z.object({key:s.z.string(),name:s.z.string(),snapshot:s.z.boolean(),data:s.z.string().transform(r=>JSON.parse(r))}),ly=s.z.object({keys:s.z.string().array()}),uy=s.z.object({schematics:ln.array()});class hy{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:O(e)},ly,uy)).schematics}}const yy=cy.partial({key:!0,snapshot:!0}).transform(r=>({...r,data:JSON.stringify(r.data)})),dy=s.z.object({workspace:ve,schematics:yy.array()}),fy=s.z.object({schematics:ln.array()}),py=s.z.object({keys:hr.array()}),gy=s.z.object({}),my=s.z.object({key:hr,name:s.z.string()}),Hn=s.z.object({}),wy=s.z.object({key:hr,data:s.z.string()});s.z.object({});const by=s.z.object({key:hr,name:s.z.string(),snapshot:s.z.boolean()}),vy=s.z.object({schematic:ln}),Ty="/workspace/schematic/create",Oy="/workspace/schematic/delete",zy="/workspace/schematic/rename",Ey="/workspace/schematic/set-data",Sy="/workspace/schematic/copy";let Ny=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,Ty,{workspace:e,schematics:[n]},dy,fy)).schematics[0]}async copy(e,t,n){return(await w(this.client,Sy,{key:e,name:t,snapshot:n},by,vy)).schematic}async delete(e){const t=O(e);await w(this.client,Oy,{keys:t},py,gy)}async rename(e,t){await w(this.client,zy,{key:e,name:t},my,Hn)}async setData(e,t){await w(this.client,Ey,{key:e,data:JSON.stringify(t)},wy,Hn)}},Iy=class{constructor(e){o(this,"writer");o(this,"retriever");this.writer=new Ny(e),this.retriever=new hy(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 ky=on.partial({key:!0}).transform(r=>({...r,layout:JSON.stringify(r.layout)})),Ay=s.z.object({workspaces:ky.array()}),$y=s.z.object({workspaces:cn.array()}),Ry=s.z.object({keys:ve.array()}),Cy=s.z.object({}),xy=s.z.object({key:ve,name:s.z.string()}),Py=s.z.object({}),Dy=s.z.object({key:ve,layout:s.z.string()}),jy=s.z.object({}),My="/workspace/create",Zy="/workspace/delete",Uy="/workspace/rename",By="/workspace/set-layout";class Ly{constructor(e){o(this,"client");this.client=e}async create(e){return(await w(this.client,My,{workspaces:O(e)},Ay,$y)).workspaces}async delete(e){await w(this.client,Zy,{keys:O(e)},Ry,Cy)}async rename(e,t){await w(this.client,Uy,{key:e,name:t},xy,Py)}async setLayout(e,t){await w(this.client,By,{key:e,layout:JSON.stringify(t)},Dy,jy)}}class Yi{constructor(e){o(this,"type","workspace");o(this,"schematic");o(this,"linePlot");o(this,"retriever");o(this,"writer");this.schematic=new Iy(e),this.linePlot=new sy(e),this.retriever=new oy(e),this.writer=new Ly(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 qy=Object.freeze(Object.defineProperty({__proto__:null,Client:Yi,WorkspaceOntologyType:qi,keyZ:ve,ontologyID:Yh,workspaceRemoteZ:cn,workspaceZ:on},Symbol.toStringTag,{value:"Module"})),Wi=s.z.object({host:s.z.string({required_error:"Host is required"}).min(1,"Host is required"),port:s.z.number({required_error:"Port is required"}).or(s.z.string({required_error:"Port is required"})),username:s.z.string().min(1,"Username is required"),password:s.z.string().min(1,"Password is required"),connectivityPollFrequency:E.z.default(E.seconds(30)),secure:s.z.boolean().optional().default(!1),name:s.z.string().optional()});class _i extends di{constructor(t){const n=Wi.parse(t),{host:i,port:a,username:c,password:l,connectivityPollFrequency:u,secure:h}=n,p=new Uh(new Ec({host:i,port:Number(a)}),h);p.use(jc);let g;c!=null&&l!=null&&(g=new Zl(p.unary,{username:c,password:l}),p.use(g.middleware()));const D=new Gr(new wt(p.unary)),P=new ni(p.unary,D);super(p.stream,p.unary,D);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");o(this,"clientVersion","0.30.0");this.createdAt=S.now(),this.props=n,this.auth=g,this.transport=p,this.channels=new ri(this,D,p.unary,P),this.connectivity=new bt(p.unary,u,this.clientVersion,n.name),this.control=new pi(this),this.ontology=new Js(p.unary,this);const X=new Bi(this.transport.unary);this.labels=new xi(this.transport.unary,this,this.ontology),this.ranges=new Ui(this,X,this.transport.unary,D,this.labels,this.ontology),this.access=new xl(this.transport.unary),this.user=new Dl(this.transport.unary),this.workspaces=new Yi(this.transport.unary);const j=new Ti(this.transport.unary,this),un=new Ii(this.transport.unary,this,this.ontology,this.ranges),Vi=new Oi(this.transport.unary,this,un);this.hardware=new gi(un,Vi,j)}get key(){return this.createdAt.valueOf().toString()}close(){this.connectivity.stopChecking()}}o(_i,"connectivity",bt);const Yy=Je.Authority;exports.AuthError=ke;exports.Authority=Yy;exports.Channel=Jr;exports.ContiguityError=Br;exports.DataType=z;exports.Density=F;exports.Frame=U;exports.MultiSeries=Ms;exports.MultipleFoundError=$e;exports.NotFoundError=Ae;exports.QueryError=Q;exports.Rate=tr;exports.RouteError=mt;exports.Series=ze;exports.Synnax=_i;exports.TimeRange=W;exports.TimeSpan=E;exports.TimeStamp=S;exports.UnexpectedError=pe;exports.ValidationError=x;exports.channel=Ol;exports.connection=Ll;exports.control=cu;exports.device=Ou;exports.framer=nu;exports.hardware=lu;exports.label=ih;exports.ontology=el;exports.rack=Au;exports.ranger=Mh;exports.signals=yu;exports.synnaxPropsZ=Wi;exports.task=Wu;exports.workspace=qy;
|
package/dist/client.js
CHANGED
|
@@ -5229,7 +5229,7 @@ const jl = ["disconnected", "connecting", "connected", "failed"], ii = s.enum(jl
|
|
|
5229
5229
|
error: void 0,
|
|
5230
5230
|
message: "Disconnected",
|
|
5231
5231
|
clientServerCompatible: !1,
|
|
5232
|
-
clientVersion: "0.
|
|
5232
|
+
clientVersion: "0.30.0"
|
|
5233
5233
|
}, Vn = (r, e, t) => {
|
|
5234
5234
|
const n = t ? "cluster" : "client";
|
|
5235
5235
|
return `Synnax cluster node version ${r != null ? r + " " : ""}is too ${t ? "old" : "new"} for client version ${e}.
|
|
@@ -5931,7 +5931,10 @@ class or {
|
|
|
5931
5931
|
}
|
|
5932
5932
|
static async _open(e, t, { channels: n }) {
|
|
5933
5933
|
const i = await ar.open(e, n), a = await t.stream(Vl, zl, _l), c = new or(a, i);
|
|
5934
|
-
|
|
5934
|
+
a.send({ keys: i.keys });
|
|
5935
|
+
const [, l] = await a.receive();
|
|
5936
|
+
if (l != null) throw l;
|
|
5937
|
+
return c;
|
|
5935
5938
|
}
|
|
5936
5939
|
async next() {
|
|
5937
5940
|
try {
|
|
@@ -7805,7 +7808,7 @@ class $y extends yi {
|
|
|
7805
7808
|
/**
|
|
7806
7809
|
* The version of the client.
|
|
7807
7810
|
*/
|
|
7808
|
-
o(this, "clientVersion", "0.
|
|
7811
|
+
o(this, "clientVersion", "0.30.0");
|
|
7809
7812
|
this.createdAt = k.now(), this.props = n, this.auth = g, this.transport = p, this.channels = new ti(this, j, p.unary, P), this.connectivity = new wt(
|
|
7810
7813
|
p.unary,
|
|
7811
7814
|
u,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"streamer.d.ts","sourceRoot":"","sources":["../../src/framer/streamer.ts"],"names":[],"mappings":"AASA,OAAO,EAA4B,KAAK,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACpF,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAGxC,OAAO,EAAE,KAAK,GAAG,EAAE,KAAK,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,EAAE,KAAK,EAAU,MAAM,gBAAgB,CAAC;AAY/C,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,QAAS,YAAW,aAAa,CAAC,KAAK,CAAC,EAAE,aAAa,CAAC,KAAK,CAAC;IACzE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAwC;IAC/D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAmB;IAE3C,OAAO;IAQP,IAAI,IAAI,IAAI,GAAG,EAAE,CAEhB;WAEY,KAAK,CAChB,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,YAAY,EACpB,EAAE,QAAQ,EAAE,EAAE,cAAc,GAC3B,OAAO,CAAC,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"streamer.d.ts","sourceRoot":"","sources":["../../src/framer/streamer.ts"],"names":[],"mappings":"AASA,OAAO,EAA4B,KAAK,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACpF,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAGxC,OAAO,EAAE,KAAK,GAAG,EAAE,KAAK,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,EAAE,KAAK,EAAU,MAAM,gBAAgB,CAAC;AAY/C,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,qBAAa,QAAS,YAAW,aAAa,CAAC,KAAK,CAAC,EAAE,aAAa,CAAC,KAAK,CAAC;IACzE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAwC;IAC/D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAmB;IAE3C,OAAO;IAQP,IAAI,IAAI,IAAI,GAAG,EAAE,CAEhB;WAEY,KAAK,CAChB,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,YAAY,EACpB,EAAE,QAAQ,EAAE,EAAE,cAAc,GAC3B,OAAO,CAAC,QAAQ,CAAC;IAUd,IAAI,IAAI,OAAO,CAAC,cAAc,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IAU3C,IAAI,IAAI,OAAO,CAAC,KAAK,CAAC;IAItB,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAK7C,KAAK,IAAI,IAAI;IAIb,CAAC,MAAM,CAAC,aAAa,CAAC,IAAI,aAAa,CAAC,KAAK,EAAE,GAAG,EAAE,SAAS,CAAC;CAG/D;AAED,qBAAa,kBAAkB,CAAC,CAAC,GAAG,KAAK,CACvC,SAAQ,OAAO,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CACjC,YAAW,OAAO,CAAC,wBAAwB,CAAC,CAAC,CAAC;IAE9C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAW;IACpC,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAgB;gBAEjC,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,CAAC;IAMjE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;YAKd,MAAM;CAGrB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@synnaxlabs/client",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.0",
|
|
4
4
|
"description": "The Synnax Client Library",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"synnax",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"async-mutex": "^0.5.0",
|
|
28
28
|
"zod": "3.23.8",
|
|
29
|
-
"@synnaxlabs/freighter": "0.
|
|
30
|
-
"@synnaxlabs/x": "0.
|
|
29
|
+
"@synnaxlabs/freighter": "0.30.0",
|
|
30
|
+
"@synnaxlabs/x": "0.30.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/node": "^22.5.4",
|
|
@@ -47,4 +47,7 @@ describe("Streamer", () => {
|
|
|
47
47
|
it("should not throw an error when the streamer is opened with zero channels", async () => {
|
|
48
48
|
await expect(client.openStreamer([])).resolves.not.toThrow();
|
|
49
49
|
});
|
|
50
|
+
it("should throw an error when the streamer is opened with a channel that does not exist", async () => {
|
|
51
|
+
await expect(client.openStreamer([5678])).rejects.toThrow("not found");
|
|
52
|
+
});
|
|
50
53
|
});
|
package/src/framer/streamer.ts
CHANGED
|
@@ -55,6 +55,8 @@ export class Streamer implements AsyncIterator<Frame>, AsyncIterable<Frame> {
|
|
|
55
55
|
const stream = await client.stream(ENDPOINT, reqZ, resZ);
|
|
56
56
|
const streamer = new Streamer(stream, adapter);
|
|
57
57
|
stream.send({ keys: adapter.keys });
|
|
58
|
+
const [, err] = await stream.receive();
|
|
59
|
+
if (err != null) throw err;
|
|
58
60
|
return streamer;
|
|
59
61
|
}
|
|
60
62
|
|