@synnaxlabs/client 0.31.0 → 0.31.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +5 -5
- package/dist/client.cjs +2 -2
- package/dist/client.js +5 -5
- package/dist/user/payload.d.ts +9 -9
- package/package.json +5 -5
- package/src/user/payload.ts +3 -3
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @synnaxlabs/client@0.31.
|
|
2
|
+
> @synnaxlabs/client@0.31.1 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[2m272.
|
|
14
|
-
[vite:dts] Declaration files built in
|
|
13
|
+
[2mdist/[22m[36mclient.js [39m[1m[2m272.96 kB[22m[1m[22m[2m │ gzip: 63.80 kB[22m
|
|
14
|
+
[vite:dts] Declaration files built in 6308ms.
|
|
15
15
|
|
|
16
|
-
[2mdist/[22m[36mclient.cjs [39m[1m[2m173.
|
|
17
|
-
[32m✓ built in 7.
|
|
16
|
+
[2mdist/[22m[36mclient.cjs [39m[1m[2m173.46 kB[22m[1m[22m[2m │ gzip: 47.40 kB[22m
|
|
17
|
+
[32m✓ built in 7.29s[39m
|
package/dist/client.cjs
CHANGED
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
${t}
|
|
31
31
|
|
|
32
32
|
Please report this to the Synnax team.
|
|
33
|
-
`);o(this,"type",_e.TYPE)}};o(_e,"TYPE",ze+"unexpected"),o(_e,"matches",H(_e.TYPE));let ve=_e;const Ye=class Ye extends ne{constructor(){super(...arguments);o(this,"type",Ye.TYPE)}};o(Ye,"TYPE",ze+"query"),o(Ye,"matches",H(Ye.TYPE));let te=Ye;const qe=class qe extends te{constructor(){super(...arguments);o(this,"type",qe.TYPE)}};o(qe,"TYPE",te.TYPE+".not_found"),o(qe,"matches",H(qe.TYPE));let pe=qe;const We=class We extends te{constructor(){super(...arguments);o(this,"type",We.TYPE)}};o(We,"TYPE",te.TYPE+".multiple_results"),o(We,"matches",H(We.TYPE));let ge=We;const Ge=class Ge extends ne{constructor(t,n){super(t);o(this,"type",Ge.TYPE);o(this,"path");this.path=n}};o(Ge,"TYPE",ze+"route"),o(Ge,"matches",H(Ge.TYPE));let Nt=Ge;const Fe=class Fe extends ne{constructor(){super(...arguments);o(this,"type",Fe.TYPE)}};o(Fe,"TYPE",ze+"control"),o(Fe,"matches",H(Fe.TYPE));let tt=Fe;const Ve=class Ve extends tt{constructor(){super(...arguments);o(this,"type",Ve.TYPE)}};o(Ve,"TYPE",tt.TYPE+".unauthorized"),o(Ve,"matches",H(Ve.TYPE));let ur=Ve;const Ke=class Ke extends ne{constructor(){super(...arguments);o(this,"type",Ke.TYPE)}};o(Ke,"TYPE",ze+"contiguity"),o(Ke,"matches",H(Ke.TYPE));let nn=Ke;const Rl=r=>{if(!r.type.startsWith(ze))return null;if(r.type.startsWith(M.TYPE)){if(r.type===lr.TYPE){const e=r.data.split(": ");return e.length<2?new M(r.data):new lr(e[0],e[1])}return new M(r.data)}return r.type.startsWith(Ce.TYPE)?r.type.startsWith(St.TYPE)?new St(r.data):new Ce(r.data):r.type.startsWith(ve.TYPE)?new ve(r.data):r.type.startsWith(te.TYPE)?r.type.startsWith(pe.TYPE)?new pe(r.data):r.type.startsWith(ge.TYPE)?new ge(r.data):new te(r.data):r.type.startsWith(tt.TYPE)?r.type.startsWith(ur.TYPE)?new ur(r.data):new tt(r.data):r.type.startsWith(Nt.TYPE)?new Nt(r.data,r.data):new ve(r.data)},xl=()=>{throw new Error("Not implemented")};Ps({encode:xl,decode:Rl});const Cl=async(r,e)=>{const[t,n]=await e(r);return n==null?[t,n]:n instanceof Re?[t,new Re({message:`Cannot reach cluster at ${n.url.host}:${n.url.port}`,url:n.url})]:[t,n]};class li{constructor(e,t){o(this,"key");o(this,"name");this.key=t,this.name=e}get ontologyID(){return new b({type:"group",key:this.key})}}const Pl=s.z.string().uuid(),ui=s.z.object({key:Pl,name:s.z.string()}),Ct=s.z.union([s.z.literal("label"),s.z.literal("allow_all"),s.z.literal("builtin"),s.z.literal("cluster"),s.z.literal("channel"),s.z.literal("node"),s.z.literal("group"),s.z.literal("range"),s.z.literal("framer"),s.z.literal("range-alias"),s.z.literal("user"),s.z.literal("workspace"),s.z.literal("schematic"),s.z.literal("lineplot"),s.z.literal("rack"),s.z.literal("device"),s.z.literal("task"),s.z.literal("policy")]),Dl="builtin",jl="cluster",Ml="node",J=s.z.object({type:Ct,key:s.z.string()}),hi=s.z.string().transform(r=>{const[e,t]=r.split(":");return{type:Ct.parse(e),key:t??""}}),Me=s.z.union([hi,J]),Je=class Je{constructor(e){o(this,"type");o(this,"key");if(e instanceof Je){this.type=e.type,this.key=e.key;return}if(typeof e=="string"){const[t,n]=e.split(":");this.type=t,this.key=n??"";return}this.type=e.type,this.key=e.key}toString(){return`${this.type}:${this.key}`}isType(){return this.key===""}matchesType(e){return this.type===e&&this.isType()}get payload(){return{type:this.type,key:this.key}}};o(Je,"z",s.z.union([s.z.instanceof(Je),Me.transform(e=>new Je(e))]));let b=Je;const Bl=new b({type:"builtin",key:"root"}),yi=s.z.object({type:s.z.number()}),di=s.z.object({type:Ct,fields:s.z.record(yi)}),fi=s.z.object({id:b.z,name:s.z.string(),schema:di.optional().nullable(),data:s.z.record(s.z.unknown()).optional().nullable()}).transform(r=>({key:r.id.toString(),...r})),Ul=s.z.object({from:b.z,type:s.z.string(),to:b.z}),sn=r=>{const[e,t,n]=r.split("->");return{from:new b(e),type:t,to:new b(n)}},Zl=s.z.object({group:ui}),Ll=s.z.object({parent:J,key:s.z.string().uuid().optional(),name:s.z.string()}),_l=s.z.object({key:s.z.string(),name:s.z.string()}),Yl=s.z.object({keys:s.z.array(s.z.string())});var re;let ql=(re=class{constructor(e){o(this,"client");this.client=e}async create(e,t,n){return(await w(this.client,re.ENDPOINT,{parent:e,name:t,key:n},Ll,Zl)).group}async rename(e,t){await w(this.client,re.ENDPOINT_RENAME,{key:e,name:t},_l,s.z.object({}))}async delete(e){await w(this.client,re.ENDPOINT_DELETE,{keys:e},Yl,s.z.object({}))}},o(re,"ENDPOINT","/ontology/create-group"),o(re,"ENDPOINT_RENAME","/ontology/rename-group"),o(re,"ENDPOINT_DELETE","/ontology/delete-group"),re),Wl=class{constructor(e){o(this,"creator");this.creator=new ql(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 li(e.name,e.key)}};const Ur={ADD_CHILDREN:"/ontology/add-children",REMOVE_CHILDREN:"/ontology/remove-children",MOVE_CHILDREN:"/ontology/move-children"},rs=s.z.object({id:J,children:J.array()}),Gl=s.z.object({from:J,to:J,children:J.array()});let Fl=class{constructor(e){o(this,"client");this.client=e}async addChildren(e,...t){await w(this.client,Ur.ADD_CHILDREN,{id:new b(e).payload,children:t.map(n=>new b(n).payload)},rs,s.z.object({}))}async removeChildren(e,...t){await w(this.client,Ur.REMOVE_CHILDREN,{id:new b(e).payload,children:t.map(n=>new b(n).payload)},rs,s.z.object({}))}async moveChildren(e,t,...n){const i={from:new b(e).payload,to:new b(t).payload,children:n.map(a=>new b(a).payload)};await w(this.client,Ur.MOVE_CHILDREN,i,Gl,s.z.object({}))}};const Vl="/ontology/retrieve",Kl=s.z.object({ids:J.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:Ct.array().optional()}),Jl=s.z.object({resources:fi.array()}),ir=r=>T(r).map(e=>new b(e).payload);let pi=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 Fl(e),this.groups=new Wl(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:ir(e),...t});if(Array.isArray(e))return n;if(n.length===0)throw new te(`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:ir(e),children:!0,...t})}async retrieveParents(e,t){return await this.execRetrieve({ids:ir(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 Pt.open(this.framer,this)}async openDependentTracker(e){return await wr.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,Vl,e,Kl,Jl);return t}};const ns="sy_ontology_resource_set",ss="sy_ontology_resource_delete",is="sy_ontology_relationship_set",as="sy_ontology_relationship_delete";class Pt{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 xe.Observer,this.relationships=this.relationshipObs,this.resourceObs=new xe.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(is);return t.length===0?[]:Array.from(t.as("string")).map(n=>({variant:"set",key:sn(n),value:void 0}))}parseRelationshipDeletes(e){const t=e.get(as);return t.length===0?[]:Array.from(t.as("string")).map(n=>({variant:"delete",key:sn(n)}))}async parseResourceSets(e){const t=e.get(ns);if(t.length===0)return[];const n=Array.from(t.as("string")).map(i=>new b(i));try{return(await this.client.retrieve(n)).map(a=>({variant:"set",key:a.id,value:a}))}catch(i){if(i instanceof te)return[];throw i}}parseResourceDeletes(e){const t=e.get(ss);return t.length===0?[]:Array.from(t.as("string")).map(n=>({variant:"delete",key:new b(n)}))}static async open(e,t){const n=await e.openStreamer([ns,ss,is,as]);return new Pt(n,t)}}const os=r=>r==="from"?"to":"from";class wr extends xe.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[os(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[os(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(y=>y.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 Pt.open(n,i);return new wr(t,a,i)}async close(){await this.internal.close()}}const Hl=Object.freeze(Object.defineProperty({__proto__:null,BUILTIN_TYPE:Dl,CLUSTER_TYPE:jl,ChangeTracker:Pt,Client:pi,DependentTracker:wr,ID:b,NODE_TYPE:Ml,Root:Bl,crudeIDZ:Me,idZ:J,parseIDs:ir,parseRelationship:sn,relationshipSchemaZ:Ul,resourceSchemaZ:fi,resourceTypeZ:Ct,schemaFieldZ:yi,schemaZ:di,stringIDZ:hi},Symbol.toStringTag,{value:"Module"})),ee=r=>s.z.union([s.z.null().transform(()=>[]),r.array()]),Dt=s.z.string().uuid(),gi=s.z.object({key:Dt.optional(),subjects:Me.array().or(Me),objects:Me.array().or(Me),actions:or.array().or(or)}),br=s.z.object({key:Dt,subjects:ee(J),objects:ee(J),actions:ee(or)}),mi="policy",Xl=r=>new b({type:mi,key:r}),wi="allow_all",Ql=new b({type:wi,key:""}),eu=s.z.object({keys:Dt.array().optional(),subjects:J.array().optional()}),tu=s.z.object({policies:ee(br)}),ru="/access/policy/retrieve";let nu=class{constructor(e){o(this,"client");this.client=e}async retrieve(e){return(await w(this.client,ru,e,eu,tu)).policies}};const su=s.z.object({policies:br.partial({key:!0}).array()}),iu=s.z.object({policies:br.array()}),au=s.z.object({keys:Dt.array()}),ou=s.z.object({}),cu="/access/policy/create",lu="/access/policy/delete";let uu=class{constructor(e){o(this,"client");this.client=e}async create(e){const n=gi.array().parse(T(e)).map(a=>({objects:T(a.objects),actions:T(a.actions),subjects:T(a.subjects)}));return(await w(this.client,cu,{policies:n},su,iu)).policies}async delete(e){await w(this.client,lu,{keys:T(e)},au,ou)}},bi=class{constructor(e){o(this,"retriever");o(this,"writer");this.retriever=new nu(e),this.writer=new uu(e)}async create(e){const t=Array.isArray(e),n=await this.writer.create(e);return t?n:n[0]}async retrieve(e){const t=Array.isArray(e),n=await this.retriever.retrieve({keys:T(e)});return t?n:n[0]}async retrieveFor(e){const t=T(e).map(n=>new b(n).payload);return await this.retriever.retrieve({subjects:t})}async delete(e){await this.writer.delete(e)}};const hu=Object.freeze(Object.defineProperty({__proto__:null,ALLOW_ALL_ONTOLOGY_ID:Ql,ALLOW_ALL_ONTOLOGY_TYPE:wi,Client:bi,ONTOLOGY_TYPE:mi,keyZ:Dt,newPolicyZ:gi,ontologyID:Xl,policyZ:br},Symbol.toStringTag,{value:"Module"}));let Ti=class{constructor(e){o(this,"policy");this.policy=new bi(e)}};const yu=Object.freeze(Object.defineProperty({__proto__:null,ALL_ACTION:rc,CREATE_ACTION:nc,Client:Ti,DELETE_ACTION:sc,RETRIEVE_ACTION:ic,UPDATE_ACTION:ac,actionZ:or},Symbol.toStringTag,{value:"Module"})),Ee=s.z.number(),jt=s.z.object({name:s.z.string(),key:s.z.number(),rate:mr.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()}),vi=jt.extend({key:s.z.number().optional(),leaseholder:s.z.number().optional(),index:s.z.number().optional(),rate:mr.z.optional().default(0),isIndex:s.z.boolean().optional(),internal:s.z.boolean().optional().default(!1),virtual:s.z.boolean().optional().default(!1)}),Oi="channel",du=r=>new b({type:Oi,key:r.toString()}),fu=new Error("request for lock canceled");var pu=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(d){try{y(n.next(d))}catch(h){c(h)}}function u(d){try{y(n.throw(d))}catch(h){c(h)}}function y(d){d.done?a(d.value):i(d.value).then(l,u)}y((n=n.apply(r,e||[])).next())})};class gu{constructor(e,t=fu){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=zi(this._queue,l=>t<=l.priority);c===-1&&e<=this._value?this._dispatchItem(a):this._queue.splice(c+1,0,a)})}runExclusive(e){return pu(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]=[]),mu(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 mu(r,e){const t=zi(r,n=>e.priority<=n.priority);r.splice(t+1,0,e)}function zi(r,e){for(let t=r.length-1;t>=0;t--)if(e(r[t]))return t;return-1}var wu=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(d){try{y(n.next(d))}catch(h){c(h)}}function u(d){try{y(n.throw(d))}catch(h){c(h)}}function y(d){d.done?a(d.value):i(d.value).then(l,u)}y((n=n.apply(r,e||[])).next())})};class bu{constructor(e){this._semaphore=new gu(1,e)}acquire(){return wu(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 Tr=(r,e,{convertNumericStrings:t=!0}={})=>{const n=!Array.isArray(r);let i=T(r);const a=i[0],c=typeof a;let l;return c==="string"&&t&&!isNaN(parseInt(a))&&"number"in e?(l=e.number,i=i.map(u=>parseInt(u))):l=e[c],{single:n,variant:l,normalized:i,actual:r}},vr=(r,e,t,n)=>{if(n){if(t.length===0)throw new pe(`${r} not found matching ${JSON.stringify(e)}`);if(t.length>1)throw new ge(`Expected one ${r} matching ${JSON.stringify(e)}, but found ${t.length}`)}},Tu=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()}),vu=s.z.object({channels:ee(jt)}),me=r=>Tr(r,{number:"keys",string:"names"}),yr=class yr{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=me(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(yr.ENDPOINT,e,Tu,vu);if(n!=null)throw n;return t.channels}};o(yr,"ENDPOINT","/channel/retrieve");let It=yr;class fn{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}=Tr(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}=me(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 bu);o(this,"requests",new Map);o(this,"wrapped");o(this,"debouncedRun");this.wrapped=e,this.debouncedRun=Vc(()=>{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}=me(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 Si=async(r,e)=>{const{normalized:t}=me(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 te(`Could not find channels: ${JSON.stringify(i)}`);return n};class pn{constructor({dataType:e,rate:t,name:n,leaseholder:i=0,key:a=0,isIndex:c=!1,index:l=0,internal:u=!1,virtual:y=!1,frameClient:d,alias:h}){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 mr(t??0),this.dataType=new z(e),this.leaseholder=i,this.index=l,this.isIndex=c,this.internal=u,this.alias=h,this.virtual=y,this._frameClient=d??null}get framer(){if(this._frameClient==null)throw new M("cannot read from a channel that has not been created");return this._frameClient}get payload(){return jt.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 b({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 Ou="/channel/retrieve-group",zu=s.z.object({}),Eu=s.z.object({group:ui});let Ni=class{constructor(e,t,n,i){o(this,"type","channel");o(this,"frameClient");o(this,"client");o(this,"retriever");o(this,"writer");this.frameClient=e,this.retriever=t,this.client=n,this.writer=i}async create(e,t={}){const{retrieveIfNameExists:n=!1}=t,i=!Array.isArray(e);let a=T(e),c=[];if(n){const l=await this.retriever.retrieve(a.map(y=>y.name)),u=new Set(l.map(y=>y.name));a=a.filter(y=>!u.has(y.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 vr("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}=me(e);return n==="keys"?await this.writer.delete({keys:t}):await this.writer.delete({names:t})}async rename(e,t){return await this.writer.rename(T(e),T(t))}newSearcherWithOptions(e){return{type:this.type,search:async t=>await this.search(t,e),retrieve:async t=>await this.retrieve(t,e),page:async(t,n)=>await this.page(t,n,e)}}async page(e,t,n){return this.sugar(await this.retriever.page(e,t,n))}createDebouncedBatchRetriever(e=10){return new fn(new Ei(new It(this.client),e))}sugar(e){const{frameClient:t}=this;return e.map(n=>new pn({...n,frameClient:t}))}async retrieveGroup(){const e=await w(this.client,Ou,{},zu,Eu);return new li(e.group.name,e.group.key)}};const Su=s.z.object({channels:vi.array()}),Nu=s.z.object({channels:jt.array()}),Iu=s.z.object({keys:Ee.array().optional(),names:s.z.string().array().optional()}),ku=s.z.object({}),Au=s.z.object({keys:Ee.array(),names:s.z.string().array()}),$u=s.z.object({}),Ru="/channel/create",xu="/channel/delete",Cu="/channel/rename";let Ii=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,Ru,{channels:e},Su,Nu);return this.cache.set(t),t}async delete(e){await w(this.client,xu,e,Iu,ku),e.keys!=null&&this.cache.delete(e.keys),e.names!=null&&this.cache.delete(e.names)}async rename(e,t){await w(this.client,Cu,{keys:e,names:t},Au,$u),this.cache.rename(e,t)}};const Pu=Object.freeze(Object.defineProperty({__proto__:null,CacheRetriever:fn,Channel:pn,Client:Ni,ClusterRetriever:It,DebouncedBatchRetriever:Ei,ONTOLOGY_TYPE:Oi,Writer:Ii,analyzeChannelParams:me,keyZ:Ee,newPayload:vi,ontologyID:du,payload:jt,retrieveRequired:Si},Symbol.toStringTag,{value:"Module"})),st=s.z.string().uuid(),Mt=s.z.object({key:st,username:s.z.string().min(1),firstName:s.z.string(),lastName:s.z.string(),rootUser:s.z.boolean()}),ki=Mt.partial({key:!0,firstName:!0,lastName:!0}).omit({rootUser:!0}).extend({password:s.z.string().min(1)}),Ai="user",Du=r=>new b({type:Ai,key:r}),ju=s.z.object({keys:st.array().optional(),usernames:s.z.string().array().optional()}),Mu=s.z.object({users:ee(Mt)}),Bu="/user/retrieve";let Uu=class{constructor(e){o(this,"client");this.client=e}async retrieve(e){return(await w(this.client,Bu,e,ju,Mu)).users}};const Zu=s.z.object({users:ki.array()}),Lu=s.z.object({users:Mt.array()}),_u=s.z.object({key:st,username:s.z.string().min(1)}),Yu=s.z.object({}),qu=s.z.object({key:st,firstName:s.z.string().optional(),lastName:s.z.string().optional()}),Wu=s.z.object({}),Gu=s.z.object({keys:st.array()}),Fu=s.z.object({}),Vu="/user/create",Ku="/user/change-username",Ju="/user/rename",Hu="/user/delete";let Xu=class{constructor(e){o(this,"client");this.client=e}async create(e){return(await w(this.client,Vu,{users:T(e)},Zu,Lu)).users}async changeUsername(e,t){await w(this.client,Ku,{key:e,username:t},_u,Yu)}async rename(e,t,n){await w(this.client,Ju,{key:e,firstName:t,lastName:n},qu,Wu)}async delete(e){await w(this.client,Hu,{keys:T(e)},Gu,Fu)}},$i=class{constructor(e){o(this,"reader");o(this,"writer");this.writer=new Xu(e),this.reader=new Uu(e)}async create(e){const t=Array.isArray(e),n=await this.writer.create(e);return t?n:n[0]}async changeUsername(e,t){await this.writer.changeUsername(e,t)}async retrieve(e){const t=Array.isArray(e),n=await this.reader.retrieve({keys:T(e)});if(t)return n;if(n.length===0)throw new pe(`No user with key ${e} found`);if(n.length>1)throw new ge(`Multiple users found with key ${e}`);return n[0]}async retrieveByName(e){const t=Array.isArray(e),n=await this.reader.retrieve({usernames:T(e)});if(t)return n;if(n.length===0)throw new pe(`No user with username ${e} found`);if(n.length>1)throw new ge(`Multiple users found with username ${e}`);return n[0]}async rename(e,t,n){await this.writer.rename(e,t,n)}async delete(e){await this.writer.delete(e)}};const Qu=Object.freeze(Object.defineProperty({__proto__:null,Client:$i,ONTOLOGY_TYPE:Ai,keyZ:st,newUserZ:ki,ontologyID:Du,userZ:Mt},Symbol.toStringTag,{value:"Module"})),eh=s.z.object({username:s.z.string(),password:s.z.string()}),th=s.z.object({token:s.z.string(),user:Mt}),cs="/auth/login",rh=3,nh="/auth/change-password",sh=s.z.object({username:s.z.string(),password:s.z.string(),newPassword:s.z.string().min(1)}),ih=s.z.object({});let ah=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}async changePassword(e){if(!this.authenticated)throw new Error("Not authenticated");await w(this.client,nh,{username:this.credentials.username,password:this.credentials.password,newPassword:e},sh,ih),this.credentials.password=e}middleware(){const e=async(t,n)=>{if(!this.authenticated&&!t.target.endsWith(cs)){this.authenticating==null&&(this.authenticating=new Promise((l,u)=>{this.client.send(cs,this.credentials,eh,th).then(([y,d])=>{if(d!=null)return l(d);this.token=y==null?void 0:y.token,this.user=y==null?void 0:y.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 St.matches(a)&&this.retryCount<rh?(this.authenticated=!1,this.authenticating=void 0,this.retryCount+=1,e(t,n)):(this.retryCount=0,[i,a])};return e}};const oh=["disconnected","connecting","connected","failed"],Ri=s.z.enum(oh),xi=s.z.object({status:Ri,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()}),ch=s.z.object({clusterKey:s.z.string(),nodeVersion:s.z.string().optional()}),ls={clusterKey:"",status:"disconnected",error:void 0,message:"Disconnected",clientServerCompatible:!1,clientVersion:"0.31.0"},us=(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}.
|
|
33
|
+
`);o(this,"type",_e.TYPE)}};o(_e,"TYPE",ze+"unexpected"),o(_e,"matches",H(_e.TYPE));let ve=_e;const Ye=class Ye extends ne{constructor(){super(...arguments);o(this,"type",Ye.TYPE)}};o(Ye,"TYPE",ze+"query"),o(Ye,"matches",H(Ye.TYPE));let te=Ye;const qe=class qe extends te{constructor(){super(...arguments);o(this,"type",qe.TYPE)}};o(qe,"TYPE",te.TYPE+".not_found"),o(qe,"matches",H(qe.TYPE));let pe=qe;const We=class We extends te{constructor(){super(...arguments);o(this,"type",We.TYPE)}};o(We,"TYPE",te.TYPE+".multiple_results"),o(We,"matches",H(We.TYPE));let ge=We;const Ge=class Ge extends ne{constructor(t,n){super(t);o(this,"type",Ge.TYPE);o(this,"path");this.path=n}};o(Ge,"TYPE",ze+"route"),o(Ge,"matches",H(Ge.TYPE));let Nt=Ge;const Fe=class Fe extends ne{constructor(){super(...arguments);o(this,"type",Fe.TYPE)}};o(Fe,"TYPE",ze+"control"),o(Fe,"matches",H(Fe.TYPE));let tt=Fe;const Ve=class Ve extends tt{constructor(){super(...arguments);o(this,"type",Ve.TYPE)}};o(Ve,"TYPE",tt.TYPE+".unauthorized"),o(Ve,"matches",H(Ve.TYPE));let ur=Ve;const Ke=class Ke extends ne{constructor(){super(...arguments);o(this,"type",Ke.TYPE)}};o(Ke,"TYPE",ze+"contiguity"),o(Ke,"matches",H(Ke.TYPE));let nn=Ke;const Rl=r=>{if(!r.type.startsWith(ze))return null;if(r.type.startsWith(M.TYPE)){if(r.type===lr.TYPE){const e=r.data.split(": ");return e.length<2?new M(r.data):new lr(e[0],e[1])}return new M(r.data)}return r.type.startsWith(Ce.TYPE)?r.type.startsWith(St.TYPE)?new St(r.data):new Ce(r.data):r.type.startsWith(ve.TYPE)?new ve(r.data):r.type.startsWith(te.TYPE)?r.type.startsWith(pe.TYPE)?new pe(r.data):r.type.startsWith(ge.TYPE)?new ge(r.data):new te(r.data):r.type.startsWith(tt.TYPE)?r.type.startsWith(ur.TYPE)?new ur(r.data):new tt(r.data):r.type.startsWith(Nt.TYPE)?new Nt(r.data,r.data):new ve(r.data)},xl=()=>{throw new Error("Not implemented")};Ps({encode:xl,decode:Rl});const Cl=async(r,e)=>{const[t,n]=await e(r);return n==null?[t,n]:n instanceof Re?[t,new Re({message:`Cannot reach cluster at ${n.url.host}:${n.url.port}`,url:n.url})]:[t,n]};class li{constructor(e,t){o(this,"key");o(this,"name");this.key=t,this.name=e}get ontologyID(){return new b({type:"group",key:this.key})}}const Pl=s.z.string().uuid(),ui=s.z.object({key:Pl,name:s.z.string()}),Ct=s.z.union([s.z.literal("label"),s.z.literal("allow_all"),s.z.literal("builtin"),s.z.literal("cluster"),s.z.literal("channel"),s.z.literal("node"),s.z.literal("group"),s.z.literal("range"),s.z.literal("framer"),s.z.literal("range-alias"),s.z.literal("user"),s.z.literal("workspace"),s.z.literal("schematic"),s.z.literal("lineplot"),s.z.literal("rack"),s.z.literal("device"),s.z.literal("task"),s.z.literal("policy")]),Dl="builtin",jl="cluster",Ml="node",J=s.z.object({type:Ct,key:s.z.string()}),hi=s.z.string().transform(r=>{const[e,t]=r.split(":");return{type:Ct.parse(e),key:t??""}}),Me=s.z.union([hi,J]),Je=class Je{constructor(e){o(this,"type");o(this,"key");if(e instanceof Je){this.type=e.type,this.key=e.key;return}if(typeof e=="string"){const[t,n]=e.split(":");this.type=t,this.key=n??"";return}this.type=e.type,this.key=e.key}toString(){return`${this.type}:${this.key}`}isType(){return this.key===""}matchesType(e){return this.type===e&&this.isType()}get payload(){return{type:this.type,key:this.key}}};o(Je,"z",s.z.union([s.z.instanceof(Je),Me.transform(e=>new Je(e))]));let b=Je;const Bl=new b({type:"builtin",key:"root"}),yi=s.z.object({type:s.z.number()}),di=s.z.object({type:Ct,fields:s.z.record(yi)}),fi=s.z.object({id:b.z,name:s.z.string(),schema:di.optional().nullable(),data:s.z.record(s.z.unknown()).optional().nullable()}).transform(r=>({key:r.id.toString(),...r})),Ul=s.z.object({from:b.z,type:s.z.string(),to:b.z}),sn=r=>{const[e,t,n]=r.split("->");return{from:new b(e),type:t,to:new b(n)}},Zl=s.z.object({group:ui}),Ll=s.z.object({parent:J,key:s.z.string().uuid().optional(),name:s.z.string()}),_l=s.z.object({key:s.z.string(),name:s.z.string()}),Yl=s.z.object({keys:s.z.array(s.z.string())});var re;let ql=(re=class{constructor(e){o(this,"client");this.client=e}async create(e,t,n){return(await w(this.client,re.ENDPOINT,{parent:e,name:t,key:n},Ll,Zl)).group}async rename(e,t){await w(this.client,re.ENDPOINT_RENAME,{key:e,name:t},_l,s.z.object({}))}async delete(e){await w(this.client,re.ENDPOINT_DELETE,{keys:e},Yl,s.z.object({}))}},o(re,"ENDPOINT","/ontology/create-group"),o(re,"ENDPOINT_RENAME","/ontology/rename-group"),o(re,"ENDPOINT_DELETE","/ontology/delete-group"),re),Wl=class{constructor(e){o(this,"creator");this.creator=new ql(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 li(e.name,e.key)}};const Ur={ADD_CHILDREN:"/ontology/add-children",REMOVE_CHILDREN:"/ontology/remove-children",MOVE_CHILDREN:"/ontology/move-children"},rs=s.z.object({id:J,children:J.array()}),Gl=s.z.object({from:J,to:J,children:J.array()});let Fl=class{constructor(e){o(this,"client");this.client=e}async addChildren(e,...t){await w(this.client,Ur.ADD_CHILDREN,{id:new b(e).payload,children:t.map(n=>new b(n).payload)},rs,s.z.object({}))}async removeChildren(e,...t){await w(this.client,Ur.REMOVE_CHILDREN,{id:new b(e).payload,children:t.map(n=>new b(n).payload)},rs,s.z.object({}))}async moveChildren(e,t,...n){const i={from:new b(e).payload,to:new b(t).payload,children:n.map(a=>new b(a).payload)};await w(this.client,Ur.MOVE_CHILDREN,i,Gl,s.z.object({}))}};const Vl="/ontology/retrieve",Kl=s.z.object({ids:J.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:Ct.array().optional()}),Jl=s.z.object({resources:fi.array()}),ir=r=>T(r).map(e=>new b(e).payload);let pi=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 Fl(e),this.groups=new Wl(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:ir(e),...t});if(Array.isArray(e))return n;if(n.length===0)throw new te(`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:ir(e),children:!0,...t})}async retrieveParents(e,t){return await this.execRetrieve({ids:ir(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 Pt.open(this.framer,this)}async openDependentTracker(e){return await wr.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,Vl,e,Kl,Jl);return t}};const ns="sy_ontology_resource_set",ss="sy_ontology_resource_delete",is="sy_ontology_relationship_set",as="sy_ontology_relationship_delete";class Pt{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 xe.Observer,this.relationships=this.relationshipObs,this.resourceObs=new xe.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(is);return t.length===0?[]:Array.from(t.as("string")).map(n=>({variant:"set",key:sn(n),value:void 0}))}parseRelationshipDeletes(e){const t=e.get(as);return t.length===0?[]:Array.from(t.as("string")).map(n=>({variant:"delete",key:sn(n)}))}async parseResourceSets(e){const t=e.get(ns);if(t.length===0)return[];const n=Array.from(t.as("string")).map(i=>new b(i));try{return(await this.client.retrieve(n)).map(a=>({variant:"set",key:a.id,value:a}))}catch(i){if(i instanceof te)return[];throw i}}parseResourceDeletes(e){const t=e.get(ss);return t.length===0?[]:Array.from(t.as("string")).map(n=>({variant:"delete",key:new b(n)}))}static async open(e,t){const n=await e.openStreamer([ns,ss,is,as]);return new Pt(n,t)}}const os=r=>r==="from"?"to":"from";class wr extends xe.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[os(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[os(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(y=>y.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 Pt.open(n,i);return new wr(t,a,i)}async close(){await this.internal.close()}}const Hl=Object.freeze(Object.defineProperty({__proto__:null,BUILTIN_TYPE:Dl,CLUSTER_TYPE:jl,ChangeTracker:Pt,Client:pi,DependentTracker:wr,ID:b,NODE_TYPE:Ml,Root:Bl,crudeIDZ:Me,idZ:J,parseIDs:ir,parseRelationship:sn,relationshipSchemaZ:Ul,resourceSchemaZ:fi,resourceTypeZ:Ct,schemaFieldZ:yi,schemaZ:di,stringIDZ:hi},Symbol.toStringTag,{value:"Module"})),ee=r=>s.z.union([s.z.null().transform(()=>[]),r.array()]),Dt=s.z.string().uuid(),gi=s.z.object({key:Dt.optional(),subjects:Me.array().or(Me),objects:Me.array().or(Me),actions:or.array().or(or)}),br=s.z.object({key:Dt,subjects:ee(J),objects:ee(J),actions:ee(or)}),mi="policy",Xl=r=>new b({type:mi,key:r}),wi="allow_all",Ql=new b({type:wi,key:""}),eu=s.z.object({keys:Dt.array().optional(),subjects:J.array().optional()}),tu=s.z.object({policies:ee(br)}),ru="/access/policy/retrieve";let nu=class{constructor(e){o(this,"client");this.client=e}async retrieve(e){return(await w(this.client,ru,e,eu,tu)).policies}};const su=s.z.object({policies:br.partial({key:!0}).array()}),iu=s.z.object({policies:br.array()}),au=s.z.object({keys:Dt.array()}),ou=s.z.object({}),cu="/access/policy/create",lu="/access/policy/delete";let uu=class{constructor(e){o(this,"client");this.client=e}async create(e){const n=gi.array().parse(T(e)).map(a=>({objects:T(a.objects),actions:T(a.actions),subjects:T(a.subjects)}));return(await w(this.client,cu,{policies:n},su,iu)).policies}async delete(e){await w(this.client,lu,{keys:T(e)},au,ou)}},bi=class{constructor(e){o(this,"retriever");o(this,"writer");this.retriever=new nu(e),this.writer=new uu(e)}async create(e){const t=Array.isArray(e),n=await this.writer.create(e);return t?n:n[0]}async retrieve(e){const t=Array.isArray(e),n=await this.retriever.retrieve({keys:T(e)});return t?n:n[0]}async retrieveFor(e){const t=T(e).map(n=>new b(n).payload);return await this.retriever.retrieve({subjects:t})}async delete(e){await this.writer.delete(e)}};const hu=Object.freeze(Object.defineProperty({__proto__:null,ALLOW_ALL_ONTOLOGY_ID:Ql,ALLOW_ALL_ONTOLOGY_TYPE:wi,Client:bi,ONTOLOGY_TYPE:mi,keyZ:Dt,newPolicyZ:gi,ontologyID:Xl,policyZ:br},Symbol.toStringTag,{value:"Module"}));let Ti=class{constructor(e){o(this,"policy");this.policy=new bi(e)}};const yu=Object.freeze(Object.defineProperty({__proto__:null,ALL_ACTION:rc,CREATE_ACTION:nc,Client:Ti,DELETE_ACTION:sc,RETRIEVE_ACTION:ic,UPDATE_ACTION:ac,actionZ:or},Symbol.toStringTag,{value:"Module"})),Ee=s.z.number(),jt=s.z.object({name:s.z.string(),key:s.z.number(),rate:mr.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()}),vi=jt.extend({key:s.z.number().optional(),leaseholder:s.z.number().optional(),index:s.z.number().optional(),rate:mr.z.optional().default(0),isIndex:s.z.boolean().optional(),internal:s.z.boolean().optional().default(!1),virtual:s.z.boolean().optional().default(!1)}),Oi="channel",du=r=>new b({type:Oi,key:r.toString()}),fu=new Error("request for lock canceled");var pu=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(d){try{y(n.next(d))}catch(h){c(h)}}function u(d){try{y(n.throw(d))}catch(h){c(h)}}function y(d){d.done?a(d.value):i(d.value).then(l,u)}y((n=n.apply(r,e||[])).next())})};class gu{constructor(e,t=fu){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=zi(this._queue,l=>t<=l.priority);c===-1&&e<=this._value?this._dispatchItem(a):this._queue.splice(c+1,0,a)})}runExclusive(e){return pu(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]=[]),mu(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 mu(r,e){const t=zi(r,n=>e.priority<=n.priority);r.splice(t+1,0,e)}function zi(r,e){for(let t=r.length-1;t>=0;t--)if(e(r[t]))return t;return-1}var wu=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(d){try{y(n.next(d))}catch(h){c(h)}}function u(d){try{y(n.throw(d))}catch(h){c(h)}}function y(d){d.done?a(d.value):i(d.value).then(l,u)}y((n=n.apply(r,e||[])).next())})};class bu{constructor(e){this._semaphore=new gu(1,e)}acquire(){return wu(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 Tr=(r,e,{convertNumericStrings:t=!0}={})=>{const n=!Array.isArray(r);let i=T(r);const a=i[0],c=typeof a;let l;return c==="string"&&t&&!isNaN(parseInt(a))&&"number"in e?(l=e.number,i=i.map(u=>parseInt(u))):l=e[c],{single:n,variant:l,normalized:i,actual:r}},vr=(r,e,t,n)=>{if(n){if(t.length===0)throw new pe(`${r} not found matching ${JSON.stringify(e)}`);if(t.length>1)throw new ge(`Expected one ${r} matching ${JSON.stringify(e)}, but found ${t.length}`)}},Tu=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()}),vu=s.z.object({channels:ee(jt)}),me=r=>Tr(r,{number:"keys",string:"names"}),yr=class yr{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=me(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(yr.ENDPOINT,e,Tu,vu);if(n!=null)throw n;return t.channels}};o(yr,"ENDPOINT","/channel/retrieve");let It=yr;class fn{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}=Tr(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}=me(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 bu);o(this,"requests",new Map);o(this,"wrapped");o(this,"debouncedRun");this.wrapped=e,this.debouncedRun=Vc(()=>{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}=me(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 Si=async(r,e)=>{const{normalized:t}=me(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 te(`Could not find channels: ${JSON.stringify(i)}`);return n};class pn{constructor({dataType:e,rate:t,name:n,leaseholder:i=0,key:a=0,isIndex:c=!1,index:l=0,internal:u=!1,virtual:y=!1,frameClient:d,alias:h}){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 mr(t??0),this.dataType=new z(e),this.leaseholder=i,this.index=l,this.isIndex=c,this.internal=u,this.alias=h,this.virtual=y,this._frameClient=d??null}get framer(){if(this._frameClient==null)throw new M("cannot read from a channel that has not been created");return this._frameClient}get payload(){return jt.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 b({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 Ou="/channel/retrieve-group",zu=s.z.object({}),Eu=s.z.object({group:ui});let Ni=class{constructor(e,t,n,i){o(this,"type","channel");o(this,"frameClient");o(this,"client");o(this,"retriever");o(this,"writer");this.frameClient=e,this.retriever=t,this.client=n,this.writer=i}async create(e,t={}){const{retrieveIfNameExists:n=!1}=t,i=!Array.isArray(e);let a=T(e),c=[];if(n){const l=await this.retriever.retrieve(a.map(y=>y.name)),u=new Set(l.map(y=>y.name));a=a.filter(y=>!u.has(y.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 vr("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}=me(e);return n==="keys"?await this.writer.delete({keys:t}):await this.writer.delete({names:t})}async rename(e,t){return await this.writer.rename(T(e),T(t))}newSearcherWithOptions(e){return{type:this.type,search:async t=>await this.search(t,e),retrieve:async t=>await this.retrieve(t,e),page:async(t,n)=>await this.page(t,n,e)}}async page(e,t,n){return this.sugar(await this.retriever.page(e,t,n))}createDebouncedBatchRetriever(e=10){return new fn(new Ei(new It(this.client),e))}sugar(e){const{frameClient:t}=this;return e.map(n=>new pn({...n,frameClient:t}))}async retrieveGroup(){const e=await w(this.client,Ou,{},zu,Eu);return new li(e.group.name,e.group.key)}};const Su=s.z.object({channels:vi.array()}),Nu=s.z.object({channels:jt.array()}),Iu=s.z.object({keys:Ee.array().optional(),names:s.z.string().array().optional()}),ku=s.z.object({}),Au=s.z.object({keys:Ee.array(),names:s.z.string().array()}),$u=s.z.object({}),Ru="/channel/create",xu="/channel/delete",Cu="/channel/rename";let Ii=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,Ru,{channels:e},Su,Nu);return this.cache.set(t),t}async delete(e){await w(this.client,xu,e,Iu,ku),e.keys!=null&&this.cache.delete(e.keys),e.names!=null&&this.cache.delete(e.names)}async rename(e,t){await w(this.client,Cu,{keys:e,names:t},Au,$u),this.cache.rename(e,t)}};const Pu=Object.freeze(Object.defineProperty({__proto__:null,CacheRetriever:fn,Channel:pn,Client:Ni,ClusterRetriever:It,DebouncedBatchRetriever:Ei,ONTOLOGY_TYPE:Oi,Writer:Ii,analyzeChannelParams:me,keyZ:Ee,newPayload:vi,ontologyID:du,payload:jt,retrieveRequired:Si},Symbol.toStringTag,{value:"Module"})),st=s.z.string().uuid(),Mt=s.z.object({key:st,username:s.z.string().min(1),firstName:s.z.string().optional().default(""),lastName:s.z.string().optional().default(""),rootUser:s.z.boolean().optional().default(!0)}),ki=Mt.partial({key:!0,firstName:!0,lastName:!0}).omit({rootUser:!0}).extend({password:s.z.string().min(1)}),Ai="user",Du=r=>new b({type:Ai,key:r}),ju=s.z.object({keys:st.array().optional(),usernames:s.z.string().array().optional()}),Mu=s.z.object({users:ee(Mt)}),Bu="/user/retrieve";let Uu=class{constructor(e){o(this,"client");this.client=e}async retrieve(e){return(await w(this.client,Bu,e,ju,Mu)).users}};const Zu=s.z.object({users:ki.array()}),Lu=s.z.object({users:Mt.array()}),_u=s.z.object({key:st,username:s.z.string().min(1)}),Yu=s.z.object({}),qu=s.z.object({key:st,firstName:s.z.string().optional(),lastName:s.z.string().optional()}),Wu=s.z.object({}),Gu=s.z.object({keys:st.array()}),Fu=s.z.object({}),Vu="/user/create",Ku="/user/change-username",Ju="/user/rename",Hu="/user/delete";let Xu=class{constructor(e){o(this,"client");this.client=e}async create(e){return(await w(this.client,Vu,{users:T(e)},Zu,Lu)).users}async changeUsername(e,t){await w(this.client,Ku,{key:e,username:t},_u,Yu)}async rename(e,t,n){await w(this.client,Ju,{key:e,firstName:t,lastName:n},qu,Wu)}async delete(e){await w(this.client,Hu,{keys:T(e)},Gu,Fu)}},$i=class{constructor(e){o(this,"reader");o(this,"writer");this.writer=new Xu(e),this.reader=new Uu(e)}async create(e){const t=Array.isArray(e),n=await this.writer.create(e);return t?n:n[0]}async changeUsername(e,t){await this.writer.changeUsername(e,t)}async retrieve(e){const t=Array.isArray(e),n=await this.reader.retrieve({keys:T(e)});if(t)return n;if(n.length===0)throw new pe(`No user with key ${e} found`);if(n.length>1)throw new ge(`Multiple users found with key ${e}`);return n[0]}async retrieveByName(e){const t=Array.isArray(e),n=await this.reader.retrieve({usernames:T(e)});if(t)return n;if(n.length===0)throw new pe(`No user with username ${e} found`);if(n.length>1)throw new ge(`Multiple users found with username ${e}`);return n[0]}async rename(e,t,n){await this.writer.rename(e,t,n)}async delete(e){await this.writer.delete(e)}};const Qu=Object.freeze(Object.defineProperty({__proto__:null,Client:$i,ONTOLOGY_TYPE:Ai,keyZ:st,newUserZ:ki,ontologyID:Du,userZ:Mt},Symbol.toStringTag,{value:"Module"})),eh=s.z.object({username:s.z.string(),password:s.z.string()}),th=s.z.object({token:s.z.string(),user:Mt}),cs="/auth/login",rh=3,nh="/auth/change-password",sh=s.z.object({username:s.z.string(),password:s.z.string(),newPassword:s.z.string().min(1)}),ih=s.z.object({});let ah=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}async changePassword(e){if(!this.authenticated)throw new Error("Not authenticated");await w(this.client,nh,{username:this.credentials.username,password:this.credentials.password,newPassword:e},sh,ih),this.credentials.password=e}middleware(){const e=async(t,n)=>{if(!this.authenticated&&!t.target.endsWith(cs)){this.authenticating==null&&(this.authenticating=new Promise((l,u)=>{this.client.send(cs,this.credentials,eh,th).then(([y,d])=>{if(d!=null)return l(d);this.token=y==null?void 0:y.token,this.user=y==null?void 0:y.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 St.matches(a)&&this.retryCount<rh?(this.authenticated=!1,this.authenticating=void 0,this.retryCount+=1,e(t,n)):(this.retryCount=0,[i,a])};return e}};const oh=["disconnected","connecting","connected","failed"],Ri=s.z.enum(oh),xi=s.z.object({status:Ri,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()}),ch=s.z.object({clusterKey:s.z.string(),nodeVersion:s.z.string().optional()}),ls={clusterKey:"",status:"disconnected",error:void 0,message:"Disconnected",clientServerCompatible:!1,clientVersion:"0.31.1"},us=(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}.
|
|
34
34
|
This may cause compatibility issues. We recommend updating the ${n}. For more information, see
|
|
35
35
|
https://docs.synnaxlabs.com/reference/typescript-client/troubleshooting#old-${n}-version`},He=class He{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={...ls},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(He.ENDPOINT,{},s.z.object({}),ch);if(i!=null)throw i;const a=n.nodeVersion,c=this.clientVersion,l=this.versionWarned;a==null?(this._state.clientServerCompatible=!1,l||(console.warn(us(null,c,!0)),this.versionWarned=!0)):ts.versionsEqual(c,a,{checkMajor:!0,checkMinor:!0,checkPatch:!1})?this._state.clientServerCompatible=!0:(this._state.clientServerCompatible=!1,l||(console.warn(us(a,c,ts.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(He,"ENDPOINT","/connectivity/check"),o(He,"DEFAULT",ls),o(He,"connectionStateZ",xi);let kt=He;const lh=Object.freeze(Object.defineProperty({__proto__:null,Checker:kt,state:xi,status:Ri},Symbol.toStringTag,{value:"Module"})),uh=s.z.object({keys:Ee.array().optional(),bounds:W.z,names:s.z.string().array().optional()}),hh=s.z.object({}),yh="/frame/delete";class dh{constructor(e){o(this,"client");this.client=e}async delete(e){await w(this.client,yh,e,uh,hh)}}const hs=r=>{const e=T(r);return e.length===0?null:typeof e[0]=="number"||!isNaN(parseInt(e[0]))?"key":"name"},ys=(r,e)=>{const t=T(r);if(t.length===e.length)return;const n=hs(r);throw hs===null?new M("[Frame] - channel keys or names must be provided when constructing a frame."):new M(`[Frame] - ${n}s and series must be the same length.
|
|
36
36
|
Got ${t.length} ${n}s and ${e.length} series.`)};class _{constructor(e=[],t=[]){o(this,"columns",[]);o(this,"series",[]);if(e instanceof _){this.columns=e.columns,this.series=e.series;return}if(e instanceof Map){e.forEach((i,a)=>this.push(a,...T(i)));return}if(typeof e=="object"&&!Array.isArray(e)){if("keys"in e&&"series"in e){const i=e;i.series??(i.series=[]),i.keys??(i.keys=[]);const a=i.series.map(c=>Ci(c));ys(i.keys,a),i.keys.forEach((c,l)=>this.push(c,a[l]))}else Object.entries(e).forEach(([i,a])=>{const c=parseInt(i);if(isNaN(c))this.push(i,...T(a));else return this.push(c,...T(a))});return}if(Array.isArray(e)||["string","number"].includes(typeof e)){const i=T(t),a=T(e);ys(a,i),i.forEach((c,l)=>this.push(a[l],c));return}throw new M(`[Frame] - invalid frame construction parameters. data parameter ust be a frame
|
|
@@ -48,4 +48,4 @@
|
|
|
48
48
|
`);const d=new be({data:t[u],dataType:y.dataType});c.push(y.key),l.push(d)}return new _(c,l)}if(e instanceof _||e instanceof Map){const c=new _(e);if(this.adapter==null)return c;let l=[];return l=c.columns.map(u=>{var d;const y=typeof u=="string"?(d=this.adapter)==null?void 0:d.get(u):u;if(y==null)throw new M(`
|
|
49
49
|
Channel ${u} was not provided in the list of channels when opening the writer
|
|
50
50
|
`);return y}),new _(l,c.series)}const n=[],i=[],a=Object.entries(e);for(let c=0;c<a.length;c++){const[l,u]=a[c],y=await this.fetchChannel(l),d=new be({data:u,dataType:y.dataType});n.push(y.key),i.push(d)}return new _(n,i)}}class mn{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.
|
|
51
|
-
Please report this error to the Synnax team. ${JSON.stringify(e)}`),t!=null){if(Oe.matches(t))return;throw t}}}closeSend(){this.stream.closeSend()}send(e){const t=this.stream.send(e);if(t!=null)throw t}}const an=new E(-1);var wn=(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))(wn||{}),Di=(r=>(r[r.None=0]="None",r[r.Ack=1]="Ack",r[r.Data=2]="Data",r))(Di||{});const fh=s.z.object({command:s.z.nativeEnum(wn),span:E.z.optional(),bounds:W.z.optional(),stamp:S.z.optional(),keys:s.z.number().array().optional(),chunkSize:s.z.number().optional()}),ph=s.z.object({variant:s.z.nativeEnum(Di),ack:s.z.boolean(),command:s.z.nativeEnum(wn),error:Rt.optional().nullable(),frame:Or.optional()}),zt=class zt{constructor(e,t){o(this,"stream");o(this,"adapter");o(this,"value");this.stream=new mn("Iterator",e),this.value=new _,this.adapter=t}static async _open(e,t,n,i,a={}){const c=await zr.open(n,t),l=await i.stream(zt.ENDPOINT,fh,ph),u=new zt(l,c);return await u.execute({command:0,keys:c.keys,bounds:new W(e),chunkSize:a.chunkSize??1e5}),u}async next(e=an){return await this.execute({command:1,span:new E(e)})}async prev(e=an){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 gh(this)}async execute(e){for(this.stream.send(e),this.value=new _;;){const t=await this.stream.receive();if(t.variant===1)return t.ack;this.value.push(this.adapter.adapt(new _(t.frame)))}}};o(zt,"ENDPOINT","/frame/iterate");let hr=zt;class gh{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 mh=s.z.object({keys:s.z.number().array(),downsampleFactor:s.z.number()}),wh=s.z.object({frame:Or,error:Rt.optional().nullable()}),bh="/frame/stream";class Er{constructor(e,t){o(this,"stream");o(this,"adapter");o(this,"downsampleFactor");this.stream=new mn("Streamer",e),this.adapter=t,this.downsampleFactor=1}get keys(){return this.adapter.keys}static async _open(e,t,{channels:n,downsampleFactor:i}){const a=await zr.open(e,n),c=await t.stream(bh,mh,wh),l=new Er(c,a);c.send({keys:a.keys,downsampleFactor:i??1});const[,u]=await c.receive();if(u!=null)throw u;return l}async next(){try{return{done:!1,value:await this.read()}}catch(e){if(Oe.matches(e))return{done:!0,value:void 0};throw e}}async read(){return this.adapter.adapt(new _((await this.stream.receive()).frame))}async update(e){await this.adapter.update(e),this.stream.send({keys:this.adapter.keys,downsampleFactor:this.downsampleFactor})}close(){this.stream.closeSend()}[Symbol.asyncIterator](){return this}}class Bt extends xe.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 bn=(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))(bn||{}),rt=(r=>(r[r.PersistStream=1]="PersistStream",r[r.Persist=2]="Persist",r[r.Stream=3]="Stream",r))(rt||{});const Th=r=>{switch(r){case"persist":return 2;case"stream":return 3;case"persistStream":return 1;default:if(typeof r=="number"&&r in rt)return r;throw new Error(`invalid writer mode: ${r}`)}},vh=new E(-1),Oh=s.z.object({start:S.z.optional(),controlSubject:et.subjectZ.optional(),keys:s.z.number().array().optional(),authorities:et.Authority.z.array().optional(),mode:s.z.nativeEnum(rt).optional(),errOnUnauthorized:s.z.boolean().optional(),enableAutoCommit:s.z.boolean().optional(),autoIndexPersistInterval:E.z.optional()}),zh=s.z.object({command:s.z.nativeEnum(bn),config:Oh.optional(),frame:Or.optional()}),Eh=s.z.object({ack:s.z.boolean(),command:s.z.nativeEnum(bn),error:Rt.optional().nullable()});var Te;let ji=(Te=class{constructor(e,t){o(this,"stream");o(this,"adapter");this.stream=new mn("Writer",e),this.adapter=t}static async _open(e,t,{channels:n,start:i=S.now(),authorities:a=et.Authority.Absolute,controlSubject:c,mode:l=1,errOnUnauthorized:u=!1,enableAutoCommit:y=!1,autoIndexPersistInterval:d=E.SECOND}){const h=await gn.open(e,n),D=await t.stream(Te.ENDPOINT,zh,Eh),P=new Te(D,h);return await P.execute({command:0,config:{start:new S(i),keys:h.keys,controlSubject:c,authorities:T(a),mode:Th(l),errOnUnauthorized:u,enableAutoCommit:y,autoIndexPersistInterval:d}}),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?un(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(Te,"ENDPOINT","/frame/write"),Te);const Mi="framer",Sh=r=>new b({type:Mi,key:r.toString()});let Bi=class{constructor(e,t,n){o(this,"streamClient");o(this,"retriever");o(this,"deleter");this.streamClient=e,this.retriever=n,this.deleter=new dh(t)}async openIterator(e,t,n){return await hr._open(e,t,this.retriever,this.streamClient,n)}async openWriter(e){return(Array.isArray(e)||typeof e!="object")&&(e={channels:e}),await ji._open(this.retriever,this.streamClient,e)}async openStreamer(e){return(Array.isArray(e)||typeof e!="object")&&(e={channels:e,downsampleFactor:1}),await Er._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:rt.Persist});try{await c.write(a),await c.commit()}finally{await c.close()}return}const i=await this.openWriter({start:e,channels:t,mode:rt.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}=me(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 _;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}=me(e);return i==="keys"?await this.deleter.delete({keys:n,bounds:t}):await this.deleter.delete({names:n,bounds:t})}};const Nh=Object.freeze(Object.defineProperty({__proto__:null,ALWAYS_INDEX_PERSIST_ON_AUTO_COMMIT:vh,AUTO_SPAN:an,Client:Bi,Frame:_,Iterator:hr,ONTOLOGY_TYPE:Mi,ObservableStreamer:Bt,Streamer:Er,Writer:ji,WriterMode:rt,frameZ:Or,ontologyID:Sh,seriesFromPayload:Ci,seriesToPayload:Pi},Symbol.toStringTag,{value:"Module"})),Ih=et.Authority,kh=et.stateZ(s.z.number()),Ah=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 Ui extends Bt{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 nt.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 $h="sy_node_1_control";let Zi=class{constructor(e){o(this,"framer");this.framer=e}async openStateTracker(){const e=await this.framer.openStreamer($h);return new Ui(e)}};const Rh=Object.freeze(Object.defineProperty({__proto__:null,Authority:Ih,Client:Zi,StateTracker:Ui,stateZ:kh,transferString:Ah},Symbol.toStringTag,{value:"Module"}));let Li=class{constructor(e,t,n){o(this,"tasks");o(this,"racks");o(this,"devices");this.tasks=e,this.racks=t,this.devices=n}};const xh=Object.freeze(Object.defineProperty({__proto__:null,Client:Li},Symbol.toStringTag,{value:"Module"})),it=s.z.number(),Sr=s.z.object({key:it,name:s.z.string()}),_i=Sr.partial({key:!0}),Yi="rack",Ch=r=>new b({type:Yi,key:r.toString()}),Nr=s.z.string(),Ut=s.z.object({key:Nr,rack:it,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===""?{}:nt.JSON_CODEC.decodeString(r)))}),qi=Ut.extend({properties:s.z.unknown().transform(r=>nt.JSON_CODEC.encodeString(r))}),Wi="device",Ph=r=>new b({type:Wi,key:r.toString()}),Pe=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 Bt(i,a)},Dh=Object.freeze(Object.defineProperty({__proto__:null,openObservable:Pe},Symbol.toStringTag,{value:"Module"})),jh="sy_device_set",Mh="sy_device_delete",Zr="/hardware/device/retrieve",Bh="/hardware/device/create",Uh="/hardware/device/delete",Zh=s.z.object({devices:qi.array()}),Lh=s.z.object({devices:Ut.array()}),_h=s.z.object({keys:Nr.array()}),Yh=s.z.object({}),Lr=s.z.object({search:s.z.string().optional(),limit:s.z.number().optional(),offset:s.z.number().optional(),keys:Nr.array().optional(),names:s.z.string().array().optional(),makes:s.z.string().array().optional()}),_r=s.z.object({devices:ee(Ut)});let Gi=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:T(e),...t},Lr,_r);return vr("Device",e,i.devices,n),n?i.devices[0]:i.devices}async search(e,t){return(await w(this.client,Zr,{search:e,...t},Lr,_r)).devices}async page(e,t,n){return(await w(this.client,Zr,{offset:e,limit:t,...n},Lr,_r)).devices}async create(e){const t=!Array.isArray(e),n=await w(this.client,Bh,{devices:T(e)},Zh,Lh);return t?n.devices[0]:n.devices}async delete(e){await w(this.client,Uh,{keys:T(e)},_h,Yh)}async openDeviceTracker(){return await Pe(this.frameClient,jh,Mh,qh)}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 qh=(r,e)=>r==="delete"?e.toStrings().map(t=>({variant:r,key:t,value:void 0})):e.parseJSON(Ut).map(t=>({variant:r,key:t.key,value:t})),Wh=Object.freeze(Object.defineProperty({__proto__:null,Client:Gi,ONTOLOGY_TYPE:Wi,deviceKeyZ:Nr,deviceZ:Ut,newDeviceZ:qi,ontologyID:Ph},Symbol.toStringTag,{value:"Module"})),Yr="/hardware/rack/retrieve",Gh="/hardware/rack/create",Fh="/hardware/rack/delete",qr=s.z.object({keys:it.array().optional(),names:s.z.string().array().optional(),search:s.z.string().optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),Wr=s.z.object({racks:ee(Sr)}),Vh=s.z.object({racks:_i.array()}),Kh=s.z.object({racks:Sr.array()}),Jh=s.z.object({keys:it.array()}),Hh=s.z.object({});let Fi=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,Fh,{keys:T(e)},Jh,Hh)}async create(e){const t=!Array.isArray(e),n=await w(this.client,Gh,{racks:T(e)},Vh,Kh),i=this.sugar(n.racks);return t?i[0]:i}async search(e){const t=await w(this.client,Yr,{search:e},qr,Wr);return this.sugar(t.racks)}async page(e,t){const n=await w(this.client,Yr,{offset:e,limit:t},qr,Wr);return this.sugar(n.racks)}async retrieve(e){const{variant:t,normalized:n,single:i}=Tr(e,{string:"names",number:"keys"}),a=await w(this.client,Yr,{[t]:n},qr,Wr),c=this.sugar(a.racks);return vr("Rack",e,c,i),i?c[0]:c}sugar(e){return e.map(({key:t,name:n})=>new Vi(t,n,this.tasks))}};class Vi{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 Xh=Object.freeze(Object.defineProperty({__proto__:null,Client:Fi,ONTOLOGY_TYPE:Yi,Rack:Vi,newRackZ:_i,ontologyID:Ch,rackKeyZ:it,rackZ:Sr},Symbol.toStringTag,{value:"Module"})),De=s.z.union([s.z.string(),s.z.bigint().transform(r=>r.toString()),s.z.number().transform(r=>r.toString())]),At=s.z.object({task:De,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())}),Zt=s.z.object({key:De,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===""?{}:nt.JSON_CODEC.decodeString(r))),state:At.optional().nullable(),snapshot:s.z.boolean().optional()}),Ki=Zt.omit({key:!0}).extend({key:De.transform(r=>r.toString()).optional(),config:s.z.unknown().transform(r=>nt.JSON_CODEC.encodeString(r))}),Qh=s.z.object({task:De,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)))}),Ji="task",ey=r=>new b({type:Ji,key:r.toString()}),Ot="sy_task_state",ds="sy_task_cmd",Ft=new Error("Task not created");class Hi{constructor(e,t,n,i,a=!1,c=!1,l,u=null,y=null,d=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=y,this.rangeClient=d}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 b({type:"task",key:this.key})}async executeCommand(e,t){if(this.frameClient==null)throw Ft;const n=await this.frameClient.openWriter(ds),i=tl.id();return await n.write(ds,[{task:this.key,type:e,key:i,args:t}]),await n.close(),i}async executeCommandSync(e,t,n){if(this.frameClient==null)throw Ft;const i=await this.frameClient.openStreamer(Ot),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 y=At.safeParse(u.at(-1).sy_task_state);if(y.success){if(c=y.data,c.key===a)break}else console.error(y.error)}return i.close(),c}async openStateObserver(){if(this.frameClient==null)throw Ft;return new Bt(await this.frameClient.openStreamer(Ot),e=>{const t=e.get(Ot);if(t.length===0)return[null,!1];const n=At.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 Ft;if(!this.snapshot)return null;const e=await this.ontologyClient.retrieveParents(this.ontologyID);return e.length==0?null:e[0]}}const ty=s.z.object({rack:it.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()}),ry=s.z.object({tasks:ee(Zt)}),ny="/hardware/task/retrieve",sy="/hardware/task/create",iy="/hardware/task/delete",ay="/hardware/task/copy",oy=s.z.object({tasks:Ki.array()}),cy=s.z.object({tasks:Zt.array()}),ly=s.z.object({keys:De.array()}),uy=s.z.object({}),hy=s.z.object({key:De,name:s.z.string(),snapshot:s.z.boolean()}),yy=s.z.object({task:Zt});let Xi=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,sy,{tasks:T(e)},oy,cy),i=this.sugar(n.tasks);return t?i[0]:i}async delete(e){await w(this.client,iy,{keys:T(e)},ly,uy)}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}=Tr(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,ay,{key:e,name:t,snapshot:n},hy,yy);return this.sugar([i.task])[0]}async retrieveByName(e,t){const n=await this.execRetrieve({names:[e],rack:t});return vr("Task",e,n,!0),this.sugar(n)[0]}async execRetrieve(e){return(await w(this.client,ny,e,ty,ry)).tasks}sugar(e){return e.map(({key:t,name:n,type:i,config:a,state:c,internal:l,snapshot:u})=>new Hi(t,n,i,a,l,u,c,this.frameClient,this.ontologyClient,this.rangeClient))}async openTracker(){return await Pe(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 Bt(await this.frameClient.openStreamer(Ot),e=>{const t=e.get(Ot);if(t.length===0)return[null,!1];const n=At.safeParse(t.at(-1));return n.success?[n.data,!0]:[null,!1]})}};const dy=Object.freeze(Object.defineProperty({__proto__:null,Client:Xi,ONTOLOGY_TYPE:Ji,Task:Hi,commandZ:Qh,newTaskZ:Ki,ontologyID:ey,stateZ:At,taskKeyZ:De,taskZ:Zt},Symbol.toStringTag,{value:"Module"})),at=s.z.string().uuid(),Lt=s.z.object({key:at,name:s.z.string().min(1),color:s.z.string()}),Qi="label",fy=r=>new b({type:Qi,key:r}),py=s.z.object({keys:at.array().optional(),for:J.optional(),search:s.z.string().optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),gy=s.z.object({labels:ee(Lt)});var Ae;let ea=(Ae=class{constructor(e){o(this,"client");this.client=e}async retrieve(e){const t=T(e);return await this.execute({keys:t})}async retrieveFor(e){return await this.execute({for:e})}async search(e){return await this.execute({search:e})}async page(e,t){return await this.execute({offset:e,limit:t})}async execute(e){const[t,n]=await this.client.send(Ae.ENDPOINT,e,py,gy);if(n!=null)throw n;return t.labels}},o(Ae,"ENDPOINT","/label/retrieve"),Ae);const ta=Lt.extend({key:at.optional()}),my=s.z.object({labels:ta.array()}),wy=s.z.object({labels:Lt.array()}),by=s.z.object({keys:at.array()}),ra=s.z.object({id:J,labels:at.array(),replace:s.z.boolean().optional()}),Ty=ra.omit({replace:!0}),Gr=s.z.object({}),vy="/label/create",Oy="/label/delete",zy="/label/set",Ey="/label/remove";let na=class{constructor(e){o(this,"client");this.client=e}async create(e){return(await w(this.client,vy,{labels:T(e)},my,wy)).labels}async delete(e){await w(this.client,Oy,{keys:T(e)},by,Gr)}async set(e,t,{replace:n}={}){await w(this.client,zy,{id:e,labels:t,replace:n},ra,Gr)}async remove(e,t){await w(this.client,Ey,{id:e,labels:t},Ty,Gr)}};const Sy="sy_label_set",Ny="sy_label_delete";let sa=class{constructor(e,t,n){o(this,"type","label");o(this,"retriever");o(this,"writer");o(this,"frameClient");o(this,"ontology");this.writer=new na(e),this.retriever=new ea(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 b(e))}async label(e,t,n={}){await this.writer.set(new b(e),t,n)}async removeLabels(e,t){await this.writer.remove(new b(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 Pe(this.frameClient,Sy,Ny,Iy)}async trackLabelsOf(e){const t=new xe.Observer,n=(await this.retrieveFor(e)).map(a=>({id:new b({key:a.key,type:"label"}),key:a.key,name:a.name,data:a}));return(await this.ontology.openDependentTracker({target:new b(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 Iy=(r,e)=>r==="delete"?e.toUUIDs().map(t=>({variant:r,key:t})):e.parseJSON(Lt).map(t=>({variant:r,key:t.key,value:t})),ky=Object.freeze(Object.defineProperty({__proto__:null,Client:sa,ONTOLOGY_TYPE:Qi,Retriever:ea,Writer:na,keyZ:at,labelZ:Lt,newLabelPayloadZ:ta,ontologyID:fy},Symbol.toStringTag,{value:"Module"})),X=s.z.string().uuid(),_t=s.z.object({key:X,name:s.z.string().min(1),timeRange:W.z,color:s.z.string().optional()}),ia=_t.extend({key:s.z.string().uuid().optional()}),aa=r=>{const e=T(r),t=e.length===0;let n=!1;return t||(n=X.safeParse(e[0]).success),{single:!Array.isArray(r),variant:n?"keys":"names",normalized:e,actual:r,empty:t}},oa="range",ca="range-alias",Ay=r=>new b({type:oa,key:r}),$y=r=>new b({type:ca,key:r}),Ry="sy_range_alias_set",xy="sy_range_alias_delete",Cy=s.z.object({range:X,aliases:s.z.string().array()}),Py=s.z.object({aliases:s.z.record(s.z.string(),Ee)}),Dy=s.z.object({range:X,aliases:s.z.record(Ee.or(s.z.string()),s.z.string())}),jy=s.z.unknown(),My=s.z.object({range:X,channels:Ee.array()}),By=s.z.unknown(),Uy=s.z.object({range:X}),Zy=s.z.object({aliases:s.z.record(s.z.string(),s.z.string())}),ce=class ce{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,ce.RESOLVE_ENDPOINT,{range:this.rangeKey,aliases:t},Cy,Py);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,ce.SET_ENDPOINT,{range:this.rangeKey,aliases:e},Dy,jy)}async list(){return(await w(this.client,ce.LIST_ENDPOINT,{range:this.rangeKey},Uy,Zy)).aliases}async delete(e){await w(this.client,ce.DELETE_ENDPOINT,{range:this.rangeKey,channels:e},My,By)}async openChangeTracker(){return await Pe(this.frameClient,Ry,xy,Yy(this.rangeKey))}};o(ce,"SET_ENDPOINT","/range/alias/set"),o(ce,"RESOLVE_ENDPOINT","/range/alias/resolve"),o(ce,"LIST_ENDPOINT","/range/alias/list"),o(ce,"DELETE_ENDPOINT","/range/alias/delete");let on=ce;const Ly=s.z.object({range:X,channel:Ee,alias:s.z.string()}),_y="---",Yy=r=>(e,t)=>e==="delete"?t.toStrings().filter(n=>n.split(_y)[0]===r).map(n=>({variant:e,key:n,value:void 0})):t.parseJSON(Ly).map(n=>({variant:e,key:n.alias,value:n})),qy=s.z.object({range:X,keys:s.z.string().array()}),Tn=s.z.object({range:X,key:s.z.string(),value:s.z.string()}),Wy=s.z.object({pairs:ee(Tn)}),Gy=s.z.object({range:X,pairs:Tn.array()}),Fy=s.z.object({range:X,keys:s.z.string().array()}),we=class we{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,we.GET_ENDPOINT,{range:this.rangeKey,keys:T(e)},qy,Wy);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;hn(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,we.SET_ENDPOINT,{range:this.rangeKey,pairs:n},Gy,s.z.unknown())}async delete(e){await w(this.client,we.DELETE_ENDPOINT,{range:this.rangeKey,keys:T(e)},Fy,s.z.unknown())}async openTracker(){return await Pe(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(Tn).map(n=>({variant:e,key:`${n.range}${n.key}`,value:n})))}};o(we,"GET_ENDPOINT","/range/kv/get"),o(we,"SET_ENDPOINT","/range/kv/set"),o(we,"DELETE_ENDPOINT","/range/kv/delete");let $t=we;const Fr=r=>new b({type:"range",key:r});class la{constructor(e,t=W.ZERO,n,i,a,c,l,u,y,d,h){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=y,this.ontologyClient=d,this.rangeClient=h}get ontologyID(){return new b({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 te(`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(Fr(this.key))}async addLabel(...e){await this.labelClient.label(Fr(this.key),e)}async removeLabel(...e){await this.labelClient.removeLabels(Fr(this.key),e)}async openChildRangeTracker(){const e=new xe.Observer,t=(await this.retrieveChildren()).map(i=>{const a=new b({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 xe.Observer,t=await this.retrieveParent();if(t==null)return null;const n=new b({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 Vy=s.z.object({keys:X.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()}),Ky="/range/retrieve",Jy=s.z.object({ranges:ee(_t)});let ua=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(T(e),t));return n?i[0]:i}async rename(e,t){await this.writer.rename(e,t)}async delete(e){await this.writer.delete(T(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}=aa(e);if(c)return[];const l=await this.execRetrieve({[i]:a});if(!t)return l;if(l.length===0)throw new pe(`range matching ${n} not found`);if(l.length>1)throw new ge(`multiple ranges matching ${n} found`);return l[0]}getKV(e){return new $t(e,this.unaryClient,this.frameClient)}async execRetrieve(e){const{ranges:t}=await w(this.unaryClient,Ky,e,Vy,Jy);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 la(e.name,e.timeRange,e.key,e.color,this.frameClient,new $t(e.key,this.unaryClient,this.frameClient),new on(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 Pe(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 Hy=s.z.object({ranges:_t.array()}),Xy=s.z.object({parent:J.optional(),ranges:ia.array()}),Qy=s.z.object({keys:X.array()}),ed=s.z.object({}),td=s.z.object({key:X,name:s.z.string()}),rd=s.z.object({}),nd="/range/create",sd="/range/delete",id="/range/rename";let ha=class{constructor(e){o(this,"client");this.client=e}async rename(e,t){await w(this.client,id,{key:e,name:t},td,rd)}async create(e,t){return(await w(this.client,nd,{ranges:e,...t},Xy,Hy)).ranges}async delete(e){await w(this.client,sd,{keys:e},Qy,ed)}};const ad=Object.freeze(Object.defineProperty({__proto__:null,ALIAS_ONTOLOGY_TYPE:ca,Client:ua,KV:$t,ONTOLOGY_TYPE:oa,Range:la,Writer:ha,analyzeParams:aa,keyZ:X,newPayloadZ:ia,payloadZ:_t,rangeAliasOntologyID:$y,rangeOntologyID:Ay},Symbol.toStringTag,{value:"Module"})),od="/api/v1/";class cd{constructor(e,t=!1){o(this,"url");o(this,"unary");o(this,"stream");o(this,"secure");this.secure=t,this.url=e.child(od);const n=new nt.JSONCodec;this.unary=new Go(this.url,n,this.secure),this.stream=new tc(this.url,n,this.secure)}use(...e){this.unary.use(...e),this.stream.use(...e)}}const Ir=s.z.string().uuid(),kr=s.z.object({key:s.z.string(),name:s.z.string(),data:dn.or(s.z.string().transform(r=>JSON.parse(r)))}),ya="lineplot",ld=r=>new b({type:ya,key:r}),ud=s.z.object({keys:s.z.string().array()}),hd=s.z.object({linePlots:kr.array()});let yd=class{constructor(e){o(this,"ENDPOINT","/workspace/lineplot/retrieve");o(this,"client");this.client=e}async retrieve(e){const t=T(e);return(await w(this.client,this.ENDPOINT,{keys:t},ud,hd)).linePlots}};const Se=s.z.string().uuid(),da=r=>JSON.parse(r),vn=s.z.object({name:s.z.string(),key:Se,layout:dn.or(s.z.string().transform(r=>da(r)))}),On=vn.omit({layout:!0}).extend({layout:s.z.string().transform(r=>da(r))}),fa="workspace",dd=r=>new b({type:fa,key:r}),fd=kr.partial({key:!0}).transform(r=>({...r,data:JSON.stringify(r.data)})),pd=s.z.object({workspace:Se,linePlots:fd.array()}),gd=s.z.object({linePlots:kr.array()}),md=s.z.object({keys:Ir.array()}),wd=s.z.object({}),bd=s.z.object({key:Ir,name:s.z.string()}),Td=s.z.object({}),vd=s.z.object({key:Ir,data:s.z.string()}),Od=s.z.object({}),zd="/workspace/lineplot/create",Ed="/workspace/lineplot/delete",Sd="/workspace/lineplot/rename",Nd="/workspace/lineplot/set-data";let Id=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,zd,{workspace:e,linePlots:[n]},pd,gd)).linePlots[0]}async delete(e){const t=T(e);await w(this.client,Ed,{keys:t},md,wd)}async rename(e,t){await w(this.client,Sd,{key:e,name:t},bd,Td)}async setData(e,t){await w(this.client,Nd,{key:e,data:JSON.stringify(t)},vd,Od)}},pa=class{constructor(e){o(this,"writer");o(this,"retriever");this.writer=new Id(e),this.retriever=new yd(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 kd=Object.freeze(Object.defineProperty({__proto__:null,Client:pa,ONTOLOGY_TYPE:ya,keyZ:Ir,linePlotZ:kr,ontologyID:ld},Symbol.toStringTag,{value:"Module"})),Ad=s.z.object({keys:Se.array().optional(),search:s.z.string().optional(),author:s.z.string().uuid().optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),$d=s.z.object({workspaces:ee(On)});var $e;let Rd=($e=class{constructor(e){o(this,"client");this.client=e}async retrieve(e){const t=T(e);return await this.execute({keys:t})}async retrieveByAuthor(e){return await this.execute({author:e})}async search(e){return await this.execute({search:e})}async page(e,t){return await this.execute({offset:e,limit:t})}async execute(e){return(await w(this.client,$e.ENDPOINT,e,Ad,$d)).workspaces}},o($e,"ENDPOINT","/workspace/retrieve"),$e);const Yt=s.z.string().uuid(),ga=s.z.object({key:s.z.string(),name:s.z.string(),data:dn.or(s.z.string().transform(r=>JSON.parse(r))),snapshot:s.z.boolean()}),Ar=s.z.object({key:s.z.string(),name:s.z.string(),snapshot:s.z.boolean(),data:s.z.string().transform(r=>JSON.parse(r))}),ma="schematic",xd=r=>new b({type:ma,key:r}),Cd=s.z.object({keys:s.z.string().array()}),Pd=s.z.object({schematics:Ar.array()});class Dd{constructor(e){o(this,"ENDPOINT","/workspace/schematic/retrieve");o(this,"client");this.client=e}async retrieve(e){return(await w(this.client,this.ENDPOINT,{keys:T(e)},Cd,Pd)).schematics}}const jd=ga.partial({key:!0,snapshot:!0}).transform(r=>({...r,data:JSON.stringify(r.data)})),Md=s.z.object({workspace:Se,schematics:jd.array()}),Bd=s.z.object({schematics:Ar.array()}),Ud=s.z.object({keys:Yt.array()}),Zd=s.z.object({}),Ld=s.z.object({key:Yt,name:s.z.string()}),fs=s.z.object({}),_d=s.z.object({key:Yt,data:s.z.string()});s.z.object({});const Yd=s.z.object({key:Yt,name:s.z.string(),snapshot:s.z.boolean()}),qd=s.z.object({schematic:Ar}),Wd="/workspace/schematic/create",Gd="/workspace/schematic/delete",Fd="/workspace/schematic/rename",Vd="/workspace/schematic/set-data",Kd="/workspace/schematic/copy";let Jd=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,Wd,{workspace:e,schematics:[n]},Md,Bd)).schematics[0]}async copy(e,t,n){return(await w(this.client,Kd,{key:e,name:t,snapshot:n},Yd,qd)).schematic}async delete(e){const t=T(e);await w(this.client,Gd,{keys:t},Ud,Zd)}async rename(e,t){await w(this.client,Fd,{key:e,name:t},Ld,fs)}async setData(e,t){await w(this.client,Vd,{key:e,data:JSON.stringify(t)},_d,fs)}},wa=class{constructor(e){o(this,"writer");o(this,"retriever");this.writer=new Jd(e),this.retriever=new Dd(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 Hd=Object.freeze(Object.defineProperty({__proto__:null,Client:wa,ONTOLOGY_TYPE:ma,keyZ:Yt,ontologyID:xd,schematicRemoteZ:Ar,schematicZ:ga},Symbol.toStringTag,{value:"Module"})),Xd=vn.partial({key:!0}).transform(r=>({...r,layout:JSON.stringify(r.layout)})),Qd=s.z.object({workspaces:Xd.array()}),ef=s.z.object({workspaces:On.array()}),tf=s.z.object({keys:Se.array()}),rf=s.z.object({}),nf=s.z.object({key:Se,name:s.z.string()}),sf=s.z.object({}),af=s.z.object({key:Se,layout:s.z.string()}),of=s.z.object({}),cf="/workspace/create",lf="/workspace/delete",uf="/workspace/rename",hf="/workspace/set-layout";class yf{constructor(e){o(this,"client");this.client=e}async create(e){return(await w(this.client,cf,{workspaces:T(e)},Qd,ef)).workspaces}async delete(e){await w(this.client,lf,{keys:T(e)},tf,rf)}async rename(e,t){await w(this.client,uf,{key:e,name:t},nf,sf)}async setLayout(e,t){await w(this.client,hf,{key:e,layout:JSON.stringify(t)},af,of)}}class ba{constructor(e){o(this,"type","workspace");o(this,"schematic");o(this,"linePlot");o(this,"retriever");o(this,"writer");this.schematic=new wa(e),this.linePlot=new pa(e),this.retriever=new Rd(e),this.writer=new yf(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 df=Object.freeze(Object.defineProperty({__proto__:null,Client:ba,ONTOLOGY_TYPE:fa,keyZ:Se,ontologyID:dd,workspaceRemoteZ:On,workspaceZ:vn},Symbol.toStringTag,{value:"Module"})),Ta=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 va extends Bi{constructor(t){const n=Ta.parse(t),{host:i,port:a,username:c,password:l,connectivityPollFrequency:u,secure:y}=n,d=new cd(new vl({host:i,port:Number(a)}),y);d.use(Cl);let h;c!=null&&l!=null&&(h=new ah(d.unary,{username:c,password:l}),d.use(h.middleware()));const D=new fn(new It(d.unary)),P=new Ii(d.unary,D);super(d.stream,d.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.31.0");this.createdAt=S.now(),this.props=n,this.auth=h,this.transport=d,this.channels=new Ni(this,D,d.unary,P),this.connectivity=new kt(d.unary,u,this.clientVersion,n.name),this.control=new Zi(this),this.ontology=new pi(d.unary,this);const Q=new ha(this.transport.unary);this.labels=new sa(this.transport.unary,this,this.ontology),this.ranges=new ua(this,Q,this.transport.unary,D,this.labels,this.ontology),this.access=new Ti(this.transport.unary),this.user=new $i(this.transport.unary),this.workspaces=new ba(this.transport.unary);const B=new Gi(this.transport.unary,this),zn=new Xi(this.transport.unary,this,this.ontology,this.ranges),Oa=new Fi(this.transport.unary,this,zn);this.hardware=new Li(zn,Oa,B)}get key(){return this.createdAt.valueOf().toString()}close(){this.connectivity.stopChecking()}}o(va,"connectivity",kt);const ff=et.Authority;exports.AuthError=Ce;exports.Authority=ff;exports.Channel=pn;exports.ContiguityError=nn;exports.DataType=z;exports.Density=V;exports.Frame=_;exports.MultiSeries=ni;exports.MultipleFoundError=ge;exports.NotFoundError=pe;exports.QueryError=te;exports.Rate=mr;exports.RouteError=Nt;exports.Series=be;exports.Synnax=va;exports.TimeRange=W;exports.TimeSpan=E;exports.TimeStamp=S;exports.UnexpectedError=ve;exports.ValidationError=M;exports.access=yu;exports.channel=Pu;exports.connection=lh;exports.control=Rh;exports.device=Wh;exports.framer=Nh;exports.hardware=xh;exports.label=ky;exports.linePlot=kd;exports.ontology=Hl;exports.policy=hu;exports.rack=Xh;exports.ranger=ad;exports.schematic=Hd;exports.signals=Dh;exports.synnaxPropsZ=Ta;exports.task=dy;exports.user=Qu;exports.workspace=df;
|
|
51
|
+
Please report this error to the Synnax team. ${JSON.stringify(e)}`),t!=null){if(Oe.matches(t))return;throw t}}}closeSend(){this.stream.closeSend()}send(e){const t=this.stream.send(e);if(t!=null)throw t}}const an=new E(-1);var wn=(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))(wn||{}),Di=(r=>(r[r.None=0]="None",r[r.Ack=1]="Ack",r[r.Data=2]="Data",r))(Di||{});const fh=s.z.object({command:s.z.nativeEnum(wn),span:E.z.optional(),bounds:W.z.optional(),stamp:S.z.optional(),keys:s.z.number().array().optional(),chunkSize:s.z.number().optional()}),ph=s.z.object({variant:s.z.nativeEnum(Di),ack:s.z.boolean(),command:s.z.nativeEnum(wn),error:Rt.optional().nullable(),frame:Or.optional()}),zt=class zt{constructor(e,t){o(this,"stream");o(this,"adapter");o(this,"value");this.stream=new mn("Iterator",e),this.value=new _,this.adapter=t}static async _open(e,t,n,i,a={}){const c=await zr.open(n,t),l=await i.stream(zt.ENDPOINT,fh,ph),u=new zt(l,c);return await u.execute({command:0,keys:c.keys,bounds:new W(e),chunkSize:a.chunkSize??1e5}),u}async next(e=an){return await this.execute({command:1,span:new E(e)})}async prev(e=an){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 gh(this)}async execute(e){for(this.stream.send(e),this.value=new _;;){const t=await this.stream.receive();if(t.variant===1)return t.ack;this.value.push(this.adapter.adapt(new _(t.frame)))}}};o(zt,"ENDPOINT","/frame/iterate");let hr=zt;class gh{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 mh=s.z.object({keys:s.z.number().array(),downsampleFactor:s.z.number()}),wh=s.z.object({frame:Or,error:Rt.optional().nullable()}),bh="/frame/stream";class Er{constructor(e,t){o(this,"stream");o(this,"adapter");o(this,"downsampleFactor");this.stream=new mn("Streamer",e),this.adapter=t,this.downsampleFactor=1}get keys(){return this.adapter.keys}static async _open(e,t,{channels:n,downsampleFactor:i}){const a=await zr.open(e,n),c=await t.stream(bh,mh,wh),l=new Er(c,a);c.send({keys:a.keys,downsampleFactor:i??1});const[,u]=await c.receive();if(u!=null)throw u;return l}async next(){try{return{done:!1,value:await this.read()}}catch(e){if(Oe.matches(e))return{done:!0,value:void 0};throw e}}async read(){return this.adapter.adapt(new _((await this.stream.receive()).frame))}async update(e){await this.adapter.update(e),this.stream.send({keys:this.adapter.keys,downsampleFactor:this.downsampleFactor})}close(){this.stream.closeSend()}[Symbol.asyncIterator](){return this}}class Bt extends xe.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 bn=(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))(bn||{}),rt=(r=>(r[r.PersistStream=1]="PersistStream",r[r.Persist=2]="Persist",r[r.Stream=3]="Stream",r))(rt||{});const Th=r=>{switch(r){case"persist":return 2;case"stream":return 3;case"persistStream":return 1;default:if(typeof r=="number"&&r in rt)return r;throw new Error(`invalid writer mode: ${r}`)}},vh=new E(-1),Oh=s.z.object({start:S.z.optional(),controlSubject:et.subjectZ.optional(),keys:s.z.number().array().optional(),authorities:et.Authority.z.array().optional(),mode:s.z.nativeEnum(rt).optional(),errOnUnauthorized:s.z.boolean().optional(),enableAutoCommit:s.z.boolean().optional(),autoIndexPersistInterval:E.z.optional()}),zh=s.z.object({command:s.z.nativeEnum(bn),config:Oh.optional(),frame:Or.optional()}),Eh=s.z.object({ack:s.z.boolean(),command:s.z.nativeEnum(bn),error:Rt.optional().nullable()});var Te;let ji=(Te=class{constructor(e,t){o(this,"stream");o(this,"adapter");this.stream=new mn("Writer",e),this.adapter=t}static async _open(e,t,{channels:n,start:i=S.now(),authorities:a=et.Authority.Absolute,controlSubject:c,mode:l=1,errOnUnauthorized:u=!1,enableAutoCommit:y=!1,autoIndexPersistInterval:d=E.SECOND}){const h=await gn.open(e,n),D=await t.stream(Te.ENDPOINT,zh,Eh),P=new Te(D,h);return await P.execute({command:0,config:{start:new S(i),keys:h.keys,controlSubject:c,authorities:T(a),mode:Th(l),errOnUnauthorized:u,enableAutoCommit:y,autoIndexPersistInterval:d}}),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?un(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(Te,"ENDPOINT","/frame/write"),Te);const Mi="framer",Sh=r=>new b({type:Mi,key:r.toString()});let Bi=class{constructor(e,t,n){o(this,"streamClient");o(this,"retriever");o(this,"deleter");this.streamClient=e,this.retriever=n,this.deleter=new dh(t)}async openIterator(e,t,n){return await hr._open(e,t,this.retriever,this.streamClient,n)}async openWriter(e){return(Array.isArray(e)||typeof e!="object")&&(e={channels:e}),await ji._open(this.retriever,this.streamClient,e)}async openStreamer(e){return(Array.isArray(e)||typeof e!="object")&&(e={channels:e,downsampleFactor:1}),await Er._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:rt.Persist});try{await c.write(a),await c.commit()}finally{await c.close()}return}const i=await this.openWriter({start:e,channels:t,mode:rt.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}=me(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 _;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}=me(e);return i==="keys"?await this.deleter.delete({keys:n,bounds:t}):await this.deleter.delete({names:n,bounds:t})}};const Nh=Object.freeze(Object.defineProperty({__proto__:null,ALWAYS_INDEX_PERSIST_ON_AUTO_COMMIT:vh,AUTO_SPAN:an,Client:Bi,Frame:_,Iterator:hr,ONTOLOGY_TYPE:Mi,ObservableStreamer:Bt,Streamer:Er,Writer:ji,WriterMode:rt,frameZ:Or,ontologyID:Sh,seriesFromPayload:Ci,seriesToPayload:Pi},Symbol.toStringTag,{value:"Module"})),Ih=et.Authority,kh=et.stateZ(s.z.number()),Ah=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 Ui extends Bt{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 nt.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 $h="sy_node_1_control";let Zi=class{constructor(e){o(this,"framer");this.framer=e}async openStateTracker(){const e=await this.framer.openStreamer($h);return new Ui(e)}};const Rh=Object.freeze(Object.defineProperty({__proto__:null,Authority:Ih,Client:Zi,StateTracker:Ui,stateZ:kh,transferString:Ah},Symbol.toStringTag,{value:"Module"}));let Li=class{constructor(e,t,n){o(this,"tasks");o(this,"racks");o(this,"devices");this.tasks=e,this.racks=t,this.devices=n}};const xh=Object.freeze(Object.defineProperty({__proto__:null,Client:Li},Symbol.toStringTag,{value:"Module"})),it=s.z.number(),Sr=s.z.object({key:it,name:s.z.string()}),_i=Sr.partial({key:!0}),Yi="rack",Ch=r=>new b({type:Yi,key:r.toString()}),Nr=s.z.string(),Ut=s.z.object({key:Nr,rack:it,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===""?{}:nt.JSON_CODEC.decodeString(r)))}),qi=Ut.extend({properties:s.z.unknown().transform(r=>nt.JSON_CODEC.encodeString(r))}),Wi="device",Ph=r=>new b({type:Wi,key:r.toString()}),Pe=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 Bt(i,a)},Dh=Object.freeze(Object.defineProperty({__proto__:null,openObservable:Pe},Symbol.toStringTag,{value:"Module"})),jh="sy_device_set",Mh="sy_device_delete",Zr="/hardware/device/retrieve",Bh="/hardware/device/create",Uh="/hardware/device/delete",Zh=s.z.object({devices:qi.array()}),Lh=s.z.object({devices:Ut.array()}),_h=s.z.object({keys:Nr.array()}),Yh=s.z.object({}),Lr=s.z.object({search:s.z.string().optional(),limit:s.z.number().optional(),offset:s.z.number().optional(),keys:Nr.array().optional(),names:s.z.string().array().optional(),makes:s.z.string().array().optional()}),_r=s.z.object({devices:ee(Ut)});let Gi=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:T(e),...t},Lr,_r);return vr("Device",e,i.devices,n),n?i.devices[0]:i.devices}async search(e,t){return(await w(this.client,Zr,{search:e,...t},Lr,_r)).devices}async page(e,t,n){return(await w(this.client,Zr,{offset:e,limit:t,...n},Lr,_r)).devices}async create(e){const t=!Array.isArray(e),n=await w(this.client,Bh,{devices:T(e)},Zh,Lh);return t?n.devices[0]:n.devices}async delete(e){await w(this.client,Uh,{keys:T(e)},_h,Yh)}async openDeviceTracker(){return await Pe(this.frameClient,jh,Mh,qh)}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 qh=(r,e)=>r==="delete"?e.toStrings().map(t=>({variant:r,key:t,value:void 0})):e.parseJSON(Ut).map(t=>({variant:r,key:t.key,value:t})),Wh=Object.freeze(Object.defineProperty({__proto__:null,Client:Gi,ONTOLOGY_TYPE:Wi,deviceKeyZ:Nr,deviceZ:Ut,newDeviceZ:qi,ontologyID:Ph},Symbol.toStringTag,{value:"Module"})),Yr="/hardware/rack/retrieve",Gh="/hardware/rack/create",Fh="/hardware/rack/delete",qr=s.z.object({keys:it.array().optional(),names:s.z.string().array().optional(),search:s.z.string().optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),Wr=s.z.object({racks:ee(Sr)}),Vh=s.z.object({racks:_i.array()}),Kh=s.z.object({racks:Sr.array()}),Jh=s.z.object({keys:it.array()}),Hh=s.z.object({});let Fi=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,Fh,{keys:T(e)},Jh,Hh)}async create(e){const t=!Array.isArray(e),n=await w(this.client,Gh,{racks:T(e)},Vh,Kh),i=this.sugar(n.racks);return t?i[0]:i}async search(e){const t=await w(this.client,Yr,{search:e},qr,Wr);return this.sugar(t.racks)}async page(e,t){const n=await w(this.client,Yr,{offset:e,limit:t},qr,Wr);return this.sugar(n.racks)}async retrieve(e){const{variant:t,normalized:n,single:i}=Tr(e,{string:"names",number:"keys"}),a=await w(this.client,Yr,{[t]:n},qr,Wr),c=this.sugar(a.racks);return vr("Rack",e,c,i),i?c[0]:c}sugar(e){return e.map(({key:t,name:n})=>new Vi(t,n,this.tasks))}};class Vi{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 Xh=Object.freeze(Object.defineProperty({__proto__:null,Client:Fi,ONTOLOGY_TYPE:Yi,Rack:Vi,newRackZ:_i,ontologyID:Ch,rackKeyZ:it,rackZ:Sr},Symbol.toStringTag,{value:"Module"})),De=s.z.union([s.z.string(),s.z.bigint().transform(r=>r.toString()),s.z.number().transform(r=>r.toString())]),At=s.z.object({task:De,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())}),Zt=s.z.object({key:De,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===""?{}:nt.JSON_CODEC.decodeString(r))),state:At.optional().nullable(),snapshot:s.z.boolean().optional()}),Ki=Zt.omit({key:!0}).extend({key:De.transform(r=>r.toString()).optional(),config:s.z.unknown().transform(r=>nt.JSON_CODEC.encodeString(r))}),Qh=s.z.object({task:De,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)))}),Ji="task",ey=r=>new b({type:Ji,key:r.toString()}),Ot="sy_task_state",ds="sy_task_cmd",Ft=new Error("Task not created");class Hi{constructor(e,t,n,i,a=!1,c=!1,l,u=null,y=null,d=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=y,this.rangeClient=d}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 b({type:"task",key:this.key})}async executeCommand(e,t){if(this.frameClient==null)throw Ft;const n=await this.frameClient.openWriter(ds),i=tl.id();return await n.write(ds,[{task:this.key,type:e,key:i,args:t}]),await n.close(),i}async executeCommandSync(e,t,n){if(this.frameClient==null)throw Ft;const i=await this.frameClient.openStreamer(Ot),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 y=At.safeParse(u.at(-1).sy_task_state);if(y.success){if(c=y.data,c.key===a)break}else console.error(y.error)}return i.close(),c}async openStateObserver(){if(this.frameClient==null)throw Ft;return new Bt(await this.frameClient.openStreamer(Ot),e=>{const t=e.get(Ot);if(t.length===0)return[null,!1];const n=At.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 Ft;if(!this.snapshot)return null;const e=await this.ontologyClient.retrieveParents(this.ontologyID);return e.length==0?null:e[0]}}const ty=s.z.object({rack:it.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()}),ry=s.z.object({tasks:ee(Zt)}),ny="/hardware/task/retrieve",sy="/hardware/task/create",iy="/hardware/task/delete",ay="/hardware/task/copy",oy=s.z.object({tasks:Ki.array()}),cy=s.z.object({tasks:Zt.array()}),ly=s.z.object({keys:De.array()}),uy=s.z.object({}),hy=s.z.object({key:De,name:s.z.string(),snapshot:s.z.boolean()}),yy=s.z.object({task:Zt});let Xi=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,sy,{tasks:T(e)},oy,cy),i=this.sugar(n.tasks);return t?i[0]:i}async delete(e){await w(this.client,iy,{keys:T(e)},ly,uy)}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}=Tr(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,ay,{key:e,name:t,snapshot:n},hy,yy);return this.sugar([i.task])[0]}async retrieveByName(e,t){const n=await this.execRetrieve({names:[e],rack:t});return vr("Task",e,n,!0),this.sugar(n)[0]}async execRetrieve(e){return(await w(this.client,ny,e,ty,ry)).tasks}sugar(e){return e.map(({key:t,name:n,type:i,config:a,state:c,internal:l,snapshot:u})=>new Hi(t,n,i,a,l,u,c,this.frameClient,this.ontologyClient,this.rangeClient))}async openTracker(){return await Pe(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 Bt(await this.frameClient.openStreamer(Ot),e=>{const t=e.get(Ot);if(t.length===0)return[null,!1];const n=At.safeParse(t.at(-1));return n.success?[n.data,!0]:[null,!1]})}};const dy=Object.freeze(Object.defineProperty({__proto__:null,Client:Xi,ONTOLOGY_TYPE:Ji,Task:Hi,commandZ:Qh,newTaskZ:Ki,ontologyID:ey,stateZ:At,taskKeyZ:De,taskZ:Zt},Symbol.toStringTag,{value:"Module"})),at=s.z.string().uuid(),Lt=s.z.object({key:at,name:s.z.string().min(1),color:s.z.string()}),Qi="label",fy=r=>new b({type:Qi,key:r}),py=s.z.object({keys:at.array().optional(),for:J.optional(),search:s.z.string().optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),gy=s.z.object({labels:ee(Lt)});var Ae;let ea=(Ae=class{constructor(e){o(this,"client");this.client=e}async retrieve(e){const t=T(e);return await this.execute({keys:t})}async retrieveFor(e){return await this.execute({for:e})}async search(e){return await this.execute({search:e})}async page(e,t){return await this.execute({offset:e,limit:t})}async execute(e){const[t,n]=await this.client.send(Ae.ENDPOINT,e,py,gy);if(n!=null)throw n;return t.labels}},o(Ae,"ENDPOINT","/label/retrieve"),Ae);const ta=Lt.extend({key:at.optional()}),my=s.z.object({labels:ta.array()}),wy=s.z.object({labels:Lt.array()}),by=s.z.object({keys:at.array()}),ra=s.z.object({id:J,labels:at.array(),replace:s.z.boolean().optional()}),Ty=ra.omit({replace:!0}),Gr=s.z.object({}),vy="/label/create",Oy="/label/delete",zy="/label/set",Ey="/label/remove";let na=class{constructor(e){o(this,"client");this.client=e}async create(e){return(await w(this.client,vy,{labels:T(e)},my,wy)).labels}async delete(e){await w(this.client,Oy,{keys:T(e)},by,Gr)}async set(e,t,{replace:n}={}){await w(this.client,zy,{id:e,labels:t,replace:n},ra,Gr)}async remove(e,t){await w(this.client,Ey,{id:e,labels:t},Ty,Gr)}};const Sy="sy_label_set",Ny="sy_label_delete";let sa=class{constructor(e,t,n){o(this,"type","label");o(this,"retriever");o(this,"writer");o(this,"frameClient");o(this,"ontology");this.writer=new na(e),this.retriever=new ea(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 b(e))}async label(e,t,n={}){await this.writer.set(new b(e),t,n)}async removeLabels(e,t){await this.writer.remove(new b(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 Pe(this.frameClient,Sy,Ny,Iy)}async trackLabelsOf(e){const t=new xe.Observer,n=(await this.retrieveFor(e)).map(a=>({id:new b({key:a.key,type:"label"}),key:a.key,name:a.name,data:a}));return(await this.ontology.openDependentTracker({target:new b(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 Iy=(r,e)=>r==="delete"?e.toUUIDs().map(t=>({variant:r,key:t})):e.parseJSON(Lt).map(t=>({variant:r,key:t.key,value:t})),ky=Object.freeze(Object.defineProperty({__proto__:null,Client:sa,ONTOLOGY_TYPE:Qi,Retriever:ea,Writer:na,keyZ:at,labelZ:Lt,newLabelPayloadZ:ta,ontologyID:fy},Symbol.toStringTag,{value:"Module"})),X=s.z.string().uuid(),_t=s.z.object({key:X,name:s.z.string().min(1),timeRange:W.z,color:s.z.string().optional()}),ia=_t.extend({key:s.z.string().uuid().optional()}),aa=r=>{const e=T(r),t=e.length===0;let n=!1;return t||(n=X.safeParse(e[0]).success),{single:!Array.isArray(r),variant:n?"keys":"names",normalized:e,actual:r,empty:t}},oa="range",ca="range-alias",Ay=r=>new b({type:oa,key:r}),$y=r=>new b({type:ca,key:r}),Ry="sy_range_alias_set",xy="sy_range_alias_delete",Cy=s.z.object({range:X,aliases:s.z.string().array()}),Py=s.z.object({aliases:s.z.record(s.z.string(),Ee)}),Dy=s.z.object({range:X,aliases:s.z.record(Ee.or(s.z.string()),s.z.string())}),jy=s.z.unknown(),My=s.z.object({range:X,channels:Ee.array()}),By=s.z.unknown(),Uy=s.z.object({range:X}),Zy=s.z.object({aliases:s.z.record(s.z.string(),s.z.string())}),ce=class ce{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,ce.RESOLVE_ENDPOINT,{range:this.rangeKey,aliases:t},Cy,Py);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,ce.SET_ENDPOINT,{range:this.rangeKey,aliases:e},Dy,jy)}async list(){return(await w(this.client,ce.LIST_ENDPOINT,{range:this.rangeKey},Uy,Zy)).aliases}async delete(e){await w(this.client,ce.DELETE_ENDPOINT,{range:this.rangeKey,channels:e},My,By)}async openChangeTracker(){return await Pe(this.frameClient,Ry,xy,Yy(this.rangeKey))}};o(ce,"SET_ENDPOINT","/range/alias/set"),o(ce,"RESOLVE_ENDPOINT","/range/alias/resolve"),o(ce,"LIST_ENDPOINT","/range/alias/list"),o(ce,"DELETE_ENDPOINT","/range/alias/delete");let on=ce;const Ly=s.z.object({range:X,channel:Ee,alias:s.z.string()}),_y="---",Yy=r=>(e,t)=>e==="delete"?t.toStrings().filter(n=>n.split(_y)[0]===r).map(n=>({variant:e,key:n,value:void 0})):t.parseJSON(Ly).map(n=>({variant:e,key:n.alias,value:n})),qy=s.z.object({range:X,keys:s.z.string().array()}),Tn=s.z.object({range:X,key:s.z.string(),value:s.z.string()}),Wy=s.z.object({pairs:ee(Tn)}),Gy=s.z.object({range:X,pairs:Tn.array()}),Fy=s.z.object({range:X,keys:s.z.string().array()}),we=class we{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,we.GET_ENDPOINT,{range:this.rangeKey,keys:T(e)},qy,Wy);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;hn(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,we.SET_ENDPOINT,{range:this.rangeKey,pairs:n},Gy,s.z.unknown())}async delete(e){await w(this.client,we.DELETE_ENDPOINT,{range:this.rangeKey,keys:T(e)},Fy,s.z.unknown())}async openTracker(){return await Pe(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(Tn).map(n=>({variant:e,key:`${n.range}${n.key}`,value:n})))}};o(we,"GET_ENDPOINT","/range/kv/get"),o(we,"SET_ENDPOINT","/range/kv/set"),o(we,"DELETE_ENDPOINT","/range/kv/delete");let $t=we;const Fr=r=>new b({type:"range",key:r});class la{constructor(e,t=W.ZERO,n,i,a,c,l,u,y,d,h){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=y,this.ontologyClient=d,this.rangeClient=h}get ontologyID(){return new b({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 te(`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(Fr(this.key))}async addLabel(...e){await this.labelClient.label(Fr(this.key),e)}async removeLabel(...e){await this.labelClient.removeLabels(Fr(this.key),e)}async openChildRangeTracker(){const e=new xe.Observer,t=(await this.retrieveChildren()).map(i=>{const a=new b({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 xe.Observer,t=await this.retrieveParent();if(t==null)return null;const n=new b({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 Vy=s.z.object({keys:X.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()}),Ky="/range/retrieve",Jy=s.z.object({ranges:ee(_t)});let ua=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(T(e),t));return n?i[0]:i}async rename(e,t){await this.writer.rename(e,t)}async delete(e){await this.writer.delete(T(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}=aa(e);if(c)return[];const l=await this.execRetrieve({[i]:a});if(!t)return l;if(l.length===0)throw new pe(`range matching ${n} not found`);if(l.length>1)throw new ge(`multiple ranges matching ${n} found`);return l[0]}getKV(e){return new $t(e,this.unaryClient,this.frameClient)}async execRetrieve(e){const{ranges:t}=await w(this.unaryClient,Ky,e,Vy,Jy);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 la(e.name,e.timeRange,e.key,e.color,this.frameClient,new $t(e.key,this.unaryClient,this.frameClient),new on(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 Pe(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 Hy=s.z.object({ranges:_t.array()}),Xy=s.z.object({parent:J.optional(),ranges:ia.array()}),Qy=s.z.object({keys:X.array()}),ed=s.z.object({}),td=s.z.object({key:X,name:s.z.string()}),rd=s.z.object({}),nd="/range/create",sd="/range/delete",id="/range/rename";let ha=class{constructor(e){o(this,"client");this.client=e}async rename(e,t){await w(this.client,id,{key:e,name:t},td,rd)}async create(e,t){return(await w(this.client,nd,{ranges:e,...t},Xy,Hy)).ranges}async delete(e){await w(this.client,sd,{keys:e},Qy,ed)}};const ad=Object.freeze(Object.defineProperty({__proto__:null,ALIAS_ONTOLOGY_TYPE:ca,Client:ua,KV:$t,ONTOLOGY_TYPE:oa,Range:la,Writer:ha,analyzeParams:aa,keyZ:X,newPayloadZ:ia,payloadZ:_t,rangeAliasOntologyID:$y,rangeOntologyID:Ay},Symbol.toStringTag,{value:"Module"})),od="/api/v1/";class cd{constructor(e,t=!1){o(this,"url");o(this,"unary");o(this,"stream");o(this,"secure");this.secure=t,this.url=e.child(od);const n=new nt.JSONCodec;this.unary=new Go(this.url,n,this.secure),this.stream=new tc(this.url,n,this.secure)}use(...e){this.unary.use(...e),this.stream.use(...e)}}const Ir=s.z.string().uuid(),kr=s.z.object({key:s.z.string(),name:s.z.string(),data:dn.or(s.z.string().transform(r=>JSON.parse(r)))}),ya="lineplot",ld=r=>new b({type:ya,key:r}),ud=s.z.object({keys:s.z.string().array()}),hd=s.z.object({linePlots:kr.array()});let yd=class{constructor(e){o(this,"ENDPOINT","/workspace/lineplot/retrieve");o(this,"client");this.client=e}async retrieve(e){const t=T(e);return(await w(this.client,this.ENDPOINT,{keys:t},ud,hd)).linePlots}};const Se=s.z.string().uuid(),da=r=>JSON.parse(r),vn=s.z.object({name:s.z.string(),key:Se,layout:dn.or(s.z.string().transform(r=>da(r)))}),On=vn.omit({layout:!0}).extend({layout:s.z.string().transform(r=>da(r))}),fa="workspace",dd=r=>new b({type:fa,key:r}),fd=kr.partial({key:!0}).transform(r=>({...r,data:JSON.stringify(r.data)})),pd=s.z.object({workspace:Se,linePlots:fd.array()}),gd=s.z.object({linePlots:kr.array()}),md=s.z.object({keys:Ir.array()}),wd=s.z.object({}),bd=s.z.object({key:Ir,name:s.z.string()}),Td=s.z.object({}),vd=s.z.object({key:Ir,data:s.z.string()}),Od=s.z.object({}),zd="/workspace/lineplot/create",Ed="/workspace/lineplot/delete",Sd="/workspace/lineplot/rename",Nd="/workspace/lineplot/set-data";let Id=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,zd,{workspace:e,linePlots:[n]},pd,gd)).linePlots[0]}async delete(e){const t=T(e);await w(this.client,Ed,{keys:t},md,wd)}async rename(e,t){await w(this.client,Sd,{key:e,name:t},bd,Td)}async setData(e,t){await w(this.client,Nd,{key:e,data:JSON.stringify(t)},vd,Od)}},pa=class{constructor(e){o(this,"writer");o(this,"retriever");this.writer=new Id(e),this.retriever=new yd(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 kd=Object.freeze(Object.defineProperty({__proto__:null,Client:pa,ONTOLOGY_TYPE:ya,keyZ:Ir,linePlotZ:kr,ontologyID:ld},Symbol.toStringTag,{value:"Module"})),Ad=s.z.object({keys:Se.array().optional(),search:s.z.string().optional(),author:s.z.string().uuid().optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),$d=s.z.object({workspaces:ee(On)});var $e;let Rd=($e=class{constructor(e){o(this,"client");this.client=e}async retrieve(e){const t=T(e);return await this.execute({keys:t})}async retrieveByAuthor(e){return await this.execute({author:e})}async search(e){return await this.execute({search:e})}async page(e,t){return await this.execute({offset:e,limit:t})}async execute(e){return(await w(this.client,$e.ENDPOINT,e,Ad,$d)).workspaces}},o($e,"ENDPOINT","/workspace/retrieve"),$e);const Yt=s.z.string().uuid(),ga=s.z.object({key:s.z.string(),name:s.z.string(),data:dn.or(s.z.string().transform(r=>JSON.parse(r))),snapshot:s.z.boolean()}),Ar=s.z.object({key:s.z.string(),name:s.z.string(),snapshot:s.z.boolean(),data:s.z.string().transform(r=>JSON.parse(r))}),ma="schematic",xd=r=>new b({type:ma,key:r}),Cd=s.z.object({keys:s.z.string().array()}),Pd=s.z.object({schematics:Ar.array()});class Dd{constructor(e){o(this,"ENDPOINT","/workspace/schematic/retrieve");o(this,"client");this.client=e}async retrieve(e){return(await w(this.client,this.ENDPOINT,{keys:T(e)},Cd,Pd)).schematics}}const jd=ga.partial({key:!0,snapshot:!0}).transform(r=>({...r,data:JSON.stringify(r.data)})),Md=s.z.object({workspace:Se,schematics:jd.array()}),Bd=s.z.object({schematics:Ar.array()}),Ud=s.z.object({keys:Yt.array()}),Zd=s.z.object({}),Ld=s.z.object({key:Yt,name:s.z.string()}),fs=s.z.object({}),_d=s.z.object({key:Yt,data:s.z.string()});s.z.object({});const Yd=s.z.object({key:Yt,name:s.z.string(),snapshot:s.z.boolean()}),qd=s.z.object({schematic:Ar}),Wd="/workspace/schematic/create",Gd="/workspace/schematic/delete",Fd="/workspace/schematic/rename",Vd="/workspace/schematic/set-data",Kd="/workspace/schematic/copy";let Jd=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,Wd,{workspace:e,schematics:[n]},Md,Bd)).schematics[0]}async copy(e,t,n){return(await w(this.client,Kd,{key:e,name:t,snapshot:n},Yd,qd)).schematic}async delete(e){const t=T(e);await w(this.client,Gd,{keys:t},Ud,Zd)}async rename(e,t){await w(this.client,Fd,{key:e,name:t},Ld,fs)}async setData(e,t){await w(this.client,Vd,{key:e,data:JSON.stringify(t)},_d,fs)}},wa=class{constructor(e){o(this,"writer");o(this,"retriever");this.writer=new Jd(e),this.retriever=new Dd(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 Hd=Object.freeze(Object.defineProperty({__proto__:null,Client:wa,ONTOLOGY_TYPE:ma,keyZ:Yt,ontologyID:xd,schematicRemoteZ:Ar,schematicZ:ga},Symbol.toStringTag,{value:"Module"})),Xd=vn.partial({key:!0}).transform(r=>({...r,layout:JSON.stringify(r.layout)})),Qd=s.z.object({workspaces:Xd.array()}),ef=s.z.object({workspaces:On.array()}),tf=s.z.object({keys:Se.array()}),rf=s.z.object({}),nf=s.z.object({key:Se,name:s.z.string()}),sf=s.z.object({}),af=s.z.object({key:Se,layout:s.z.string()}),of=s.z.object({}),cf="/workspace/create",lf="/workspace/delete",uf="/workspace/rename",hf="/workspace/set-layout";class yf{constructor(e){o(this,"client");this.client=e}async create(e){return(await w(this.client,cf,{workspaces:T(e)},Qd,ef)).workspaces}async delete(e){await w(this.client,lf,{keys:T(e)},tf,rf)}async rename(e,t){await w(this.client,uf,{key:e,name:t},nf,sf)}async setLayout(e,t){await w(this.client,hf,{key:e,layout:JSON.stringify(t)},af,of)}}class ba{constructor(e){o(this,"type","workspace");o(this,"schematic");o(this,"linePlot");o(this,"retriever");o(this,"writer");this.schematic=new wa(e),this.linePlot=new pa(e),this.retriever=new Rd(e),this.writer=new yf(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 df=Object.freeze(Object.defineProperty({__proto__:null,Client:ba,ONTOLOGY_TYPE:fa,keyZ:Se,ontologyID:dd,workspaceRemoteZ:On,workspaceZ:vn},Symbol.toStringTag,{value:"Module"})),Ta=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 va extends Bi{constructor(t){const n=Ta.parse(t),{host:i,port:a,username:c,password:l,connectivityPollFrequency:u,secure:y}=n,d=new cd(new vl({host:i,port:Number(a)}),y);d.use(Cl);let h;c!=null&&l!=null&&(h=new ah(d.unary,{username:c,password:l}),d.use(h.middleware()));const D=new fn(new It(d.unary)),P=new Ii(d.unary,D);super(d.stream,d.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.31.1");this.createdAt=S.now(),this.props=n,this.auth=h,this.transport=d,this.channels=new Ni(this,D,d.unary,P),this.connectivity=new kt(d.unary,u,this.clientVersion,n.name),this.control=new Zi(this),this.ontology=new pi(d.unary,this);const Q=new ha(this.transport.unary);this.labels=new sa(this.transport.unary,this,this.ontology),this.ranges=new ua(this,Q,this.transport.unary,D,this.labels,this.ontology),this.access=new Ti(this.transport.unary),this.user=new $i(this.transport.unary),this.workspaces=new ba(this.transport.unary);const B=new Gi(this.transport.unary,this),zn=new Xi(this.transport.unary,this,this.ontology,this.ranges),Oa=new Fi(this.transport.unary,this,zn);this.hardware=new Li(zn,Oa,B)}get key(){return this.createdAt.valueOf().toString()}close(){this.connectivity.stopChecking()}}o(va,"connectivity",kt);const ff=et.Authority;exports.AuthError=Ce;exports.Authority=ff;exports.Channel=pn;exports.ContiguityError=nn;exports.DataType=z;exports.Density=V;exports.Frame=_;exports.MultiSeries=ni;exports.MultipleFoundError=ge;exports.NotFoundError=pe;exports.QueryError=te;exports.Rate=mr;exports.RouteError=Nt;exports.Series=be;exports.Synnax=va;exports.TimeRange=W;exports.TimeSpan=E;exports.TimeStamp=S;exports.UnexpectedError=ve;exports.ValidationError=M;exports.access=yu;exports.channel=Pu;exports.connection=lh;exports.control=Rh;exports.device=Wh;exports.framer=Nh;exports.hardware=xh;exports.label=ky;exports.linePlot=kd;exports.ontology=Hl;exports.policy=hu;exports.rack=Xh;exports.ranger=ad;exports.schematic=Hd;exports.signals=Dh;exports.synnaxPropsZ=Ta;exports.task=dy;exports.user=Qu;exports.workspace=df;
|
package/dist/client.js
CHANGED
|
@@ -5753,9 +5753,9 @@ const Tf = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
|
5753
5753
|
}, Symbol.toStringTag, { value: "Module" })), st = s.string().uuid(), Mt = s.object({
|
|
5754
5754
|
key: st,
|
|
5755
5755
|
username: s.string().min(1),
|
|
5756
|
-
firstName: s.string(),
|
|
5757
|
-
lastName: s.string(),
|
|
5758
|
-
rootUser: s.boolean()
|
|
5756
|
+
firstName: s.string().optional().default(""),
|
|
5757
|
+
lastName: s.string().optional().default(""),
|
|
5758
|
+
rootUser: s.boolean().optional().default(!0)
|
|
5759
5759
|
}), ki = Mt.partial({ key: !0, firstName: !0, lastName: !0 }).omit({ rootUser: !0 }).extend({ password: s.string().min(1) }), Ai = "user", $u = (r) => new b({ type: Ai, key: r }), Ru = s.object({
|
|
5760
5760
|
keys: st.array().optional(),
|
|
5761
5761
|
usernames: s.string().array().optional()
|
|
@@ -5943,7 +5943,7 @@ const eh = ["disconnected", "connecting", "connected", "failed"], Ri = s.enum(eh
|
|
|
5943
5943
|
error: void 0,
|
|
5944
5944
|
message: "Disconnected",
|
|
5945
5945
|
clientServerCompatible: !1,
|
|
5946
|
-
clientVersion: "0.31.
|
|
5946
|
+
clientVersion: "0.31.1"
|
|
5947
5947
|
}, ls = (r, e, t) => {
|
|
5948
5948
|
const n = t ? "cluster" : "client";
|
|
5949
5949
|
return `Synnax cluster node version ${r != null ? r + " " : ""}is too ${t ? "old" : "new"} for client version ${e}.
|
|
@@ -8532,7 +8532,7 @@ class Vd extends Bi {
|
|
|
8532
8532
|
/**
|
|
8533
8533
|
* The version of the client.
|
|
8534
8534
|
*/
|
|
8535
|
-
o(this, "clientVersion", "0.31.
|
|
8535
|
+
o(this, "clientVersion", "0.31.1");
|
|
8536
8536
|
this.createdAt = k.now(), this.props = n, this.auth = h, this.transport = d, this.channels = new Ni(this, j, d.unary, D), this.connectivity = new kt(
|
|
8537
8537
|
d.unary,
|
|
8538
8538
|
u,
|
package/dist/user/payload.d.ts
CHANGED
|
@@ -5,9 +5,9 @@ export type Key = z.infer<typeof keyZ>;
|
|
|
5
5
|
export declare const userZ: z.ZodObject<{
|
|
6
6
|
key: z.ZodString;
|
|
7
7
|
username: z.ZodString;
|
|
8
|
-
firstName: z.ZodString
|
|
9
|
-
lastName: z.ZodString
|
|
10
|
-
rootUser: z.ZodBoolean
|
|
8
|
+
firstName: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
9
|
+
lastName: z.ZodDefault<z.ZodOptional<z.ZodString>>;
|
|
10
|
+
rootUser: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
11
11
|
}, "strip", z.ZodTypeAny, {
|
|
12
12
|
key: string;
|
|
13
13
|
username: string;
|
|
@@ -17,17 +17,17 @@ export declare const userZ: z.ZodObject<{
|
|
|
17
17
|
}, {
|
|
18
18
|
key: string;
|
|
19
19
|
username: string;
|
|
20
|
-
firstName
|
|
21
|
-
lastName
|
|
22
|
-
rootUser
|
|
20
|
+
firstName?: string | undefined;
|
|
21
|
+
lastName?: string | undefined;
|
|
22
|
+
rootUser?: boolean | undefined;
|
|
23
23
|
}>;
|
|
24
24
|
export type User = z.infer<typeof userZ>;
|
|
25
25
|
export declare const newUserZ: z.ZodObject<z.objectUtil.extendShape<Omit<{
|
|
26
26
|
key: z.ZodOptional<z.ZodString>;
|
|
27
27
|
username: z.ZodString;
|
|
28
|
-
firstName: z.ZodOptional<z.ZodString
|
|
29
|
-
lastName: z.ZodOptional<z.ZodString
|
|
30
|
-
rootUser: z.ZodBoolean
|
|
28
|
+
firstName: z.ZodOptional<z.ZodDefault<z.ZodOptional<z.ZodString>>>;
|
|
29
|
+
lastName: z.ZodOptional<z.ZodDefault<z.ZodOptional<z.ZodString>>>;
|
|
30
|
+
rootUser: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
31
31
|
}, "rootUser">, {
|
|
32
32
|
password: z.ZodString;
|
|
33
33
|
}>, "strip", z.ZodTypeAny, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@synnaxlabs/client",
|
|
3
|
-
"version": "0.31.
|
|
3
|
+
"version": "0.31.1",
|
|
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/
|
|
30
|
-
"@synnaxlabs/
|
|
29
|
+
"@synnaxlabs/freighter": "0.31.0",
|
|
30
|
+
"@synnaxlabs/x": "0.31.0"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@types/node": "^22.5.4",
|
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
"typescript": "^5.6.2",
|
|
37
37
|
"vite": "5.4.4",
|
|
38
38
|
"vitest": "^2.1.0",
|
|
39
|
-
"@synnaxlabs/tsconfig": "0.0.2",
|
|
40
39
|
"@synnaxlabs/vite-plugin": "0.0.1",
|
|
41
|
-
"eslint-config-synnaxlabs": "0.0.1"
|
|
40
|
+
"eslint-config-synnaxlabs": "0.0.1",
|
|
41
|
+
"@synnaxlabs/tsconfig": "0.0.2"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"zod": "3.23.8"
|
package/src/user/payload.ts
CHANGED
|
@@ -17,9 +17,9 @@ export type Key = z.infer<typeof keyZ>;
|
|
|
17
17
|
export const userZ = z.object({
|
|
18
18
|
key: keyZ,
|
|
19
19
|
username: z.string().min(1),
|
|
20
|
-
firstName: z.string(),
|
|
21
|
-
lastName: z.string(),
|
|
22
|
-
rootUser: z.boolean(),
|
|
20
|
+
firstName: z.string().optional().default(""),
|
|
21
|
+
lastName: z.string().optional().default(""),
|
|
22
|
+
rootUser: z.boolean().optional().default(true),
|
|
23
23
|
});
|
|
24
24
|
export type User = z.infer<typeof userZ>;
|
|
25
25
|
|