@synnaxlabs/client 0.27.0 → 0.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +5 -5
- package/api/client.api.md +52 -8
- package/dist/client.cjs +22 -18
- package/dist/client.d.ts +4 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +1880 -1719
- package/dist/connection/checker.d.ts +21 -1
- package/dist/connection/checker.d.ts.map +1 -1
- package/dist/framer/client.d.ts.map +1 -1
- package/dist/hardware/task/client.d.ts +12 -2
- package/dist/hardware/task/client.d.ts.map +1 -1
- package/dist/hardware/task/ni/types.d.ts +14495 -0
- package/dist/hardware/task/ni/types.d.ts.map +1 -0
- package/dist/hardware/task/payload.d.ts +6 -0
- package/dist/hardware/task/payload.d.ts.map +1 -1
- package/dist/ontology/client.d.ts +16 -5
- package/dist/ontology/client.d.ts.map +1 -1
- package/dist/ontology/group/writer.d.ts.map +1 -1
- package/dist/ontology/payload.d.ts +1 -2
- package/dist/ontology/payload.d.ts.map +1 -1
- package/dist/ranger/client.d.ts +3 -1
- package/dist/ranger/client.d.ts.map +1 -1
- package/package.json +5 -5
- package/src/client.ts +13 -5
- package/src/connection/checker.ts +58 -1
- package/src/connection/connection.spec.ts +43 -3
- package/src/framer/client.ts +0 -1
- package/src/hardware/task/client.ts +82 -6
- package/src/hardware/task/ni/types.ts +1716 -0
- package/src/hardware/task/payload.ts +1 -0
- package/src/hardware/task/task.spec.ts +45 -30
- package/src/label/client.ts +5 -5
- package/src/ontology/client.ts +43 -31
- package/src/ontology/group/writer.ts +10 -12
- package/src/ontology/ontology.spec.ts +3 -5
- package/src/ontology/payload.ts +1 -1
- package/src/ranger/client.ts +46 -40
- package/src/vite-env.d.ts +1 -1
- package/vite.config.ts +5 -0
|
@@ -18,7 +18,19 @@ import { z } from "zod";
|
|
|
18
18
|
import { framer } from "@/framer";
|
|
19
19
|
import { type Frame } from "@/framer/frame";
|
|
20
20
|
import { rack } from "@/hardware/rack";
|
|
21
|
-
import {
|
|
21
|
+
import {
|
|
22
|
+
NewTask,
|
|
23
|
+
newTaskZ,
|
|
24
|
+
Payload,
|
|
25
|
+
State,
|
|
26
|
+
StateObservable,
|
|
27
|
+
stateZ,
|
|
28
|
+
TaskKey,
|
|
29
|
+
taskKeyZ,
|
|
30
|
+
taskZ,
|
|
31
|
+
} from "@/hardware/task/payload";
|
|
32
|
+
import { ontology } from "@/ontology";
|
|
33
|
+
import { ranger } from "@/ranger";
|
|
22
34
|
import { signals } from "@/signals";
|
|
23
35
|
import { analyzeParams, checkForMultipleOrNoResults } from "@/util/retrieve";
|
|
24
36
|
import { nullableArrayZ } from "@/util/zod";
|
|
@@ -26,6 +38,8 @@ import { nullableArrayZ } from "@/util/zod";
|
|
|
26
38
|
const TASK_STATE_CHANNEL = "sy_task_state";
|
|
27
39
|
const TASK_CMD_CHANNEL = "sy_task_cmd";
|
|
28
40
|
|
|
41
|
+
const TASK_NOT_CREATED = new Error("Task not created");
|
|
42
|
+
|
|
29
43
|
export class Task<
|
|
30
44
|
C extends UnknownRecord = UnknownRecord,
|
|
31
45
|
D extends {} = UnknownRecord,
|
|
@@ -36,25 +50,34 @@ export class Task<
|
|
|
36
50
|
readonly internal: boolean;
|
|
37
51
|
readonly type: T;
|
|
38
52
|
readonly config: C;
|
|
53
|
+
readonly snapshot: boolean;
|
|
39
54
|
state?: State<D>;
|
|
40
|
-
private readonly frameClient: framer.Client;
|
|
55
|
+
private readonly frameClient: framer.Client | null;
|
|
56
|
+
private readonly ontologyClient: ontology.Client | null;
|
|
57
|
+
private readonly rangeClient: ranger.Client | null;
|
|
41
58
|
|
|
42
59
|
constructor(
|
|
43
60
|
key: TaskKey,
|
|
44
61
|
name: string,
|
|
45
62
|
type: T,
|
|
46
63
|
config: C,
|
|
47
|
-
frameClient: framer.Client,
|
|
48
64
|
internal: boolean = false,
|
|
65
|
+
snapshot: boolean = false,
|
|
49
66
|
state?: State<D> | null,
|
|
67
|
+
frameClient: framer.Client | null = null,
|
|
68
|
+
ontologyClient: ontology.Client | null = null,
|
|
69
|
+
rangeClient: ranger.Client | null = null,
|
|
50
70
|
) {
|
|
51
71
|
this.key = key;
|
|
52
72
|
this.name = name;
|
|
53
73
|
this.type = type;
|
|
54
74
|
this.config = config;
|
|
55
75
|
this.internal = internal;
|
|
76
|
+
this.snapshot = snapshot;
|
|
56
77
|
if (state !== null) this.state = state;
|
|
57
78
|
this.frameClient = frameClient;
|
|
79
|
+
this.ontologyClient = ontologyClient;
|
|
80
|
+
this.rangeClient = rangeClient;
|
|
58
81
|
}
|
|
59
82
|
|
|
60
83
|
get payload(): Payload<C, D> {
|
|
@@ -68,7 +91,12 @@ export class Task<
|
|
|
68
91
|
};
|
|
69
92
|
}
|
|
70
93
|
|
|
94
|
+
get ontologyID(): ontology.ID {
|
|
95
|
+
return new ontology.ID({ type: "task", key: this.key });
|
|
96
|
+
}
|
|
97
|
+
|
|
71
98
|
async executeCommand(type: string, args?: UnknownRecord): Promise<string> {
|
|
99
|
+
if (this.frameClient == null) throw TASK_NOT_CREATED;
|
|
72
100
|
const writer = await this.frameClient.openWriter(TASK_CMD_CHANNEL);
|
|
73
101
|
const key = id.id();
|
|
74
102
|
await writer.write(TASK_CMD_CHANNEL, [{ task: this.key, type, key, args }]);
|
|
@@ -81,6 +109,7 @@ export class Task<
|
|
|
81
109
|
args: UnknownRecord,
|
|
82
110
|
timeout: CrudeTimeSpan,
|
|
83
111
|
): Promise<State<D>> {
|
|
112
|
+
if (this.frameClient == null) throw TASK_NOT_CREATED;
|
|
84
113
|
const streamer = await this.frameClient.openStreamer(TASK_STATE_CHANNEL);
|
|
85
114
|
const cmdKey = await this.executeCommand(type, args);
|
|
86
115
|
let res: State<D>;
|
|
@@ -105,6 +134,7 @@ export class Task<
|
|
|
105
134
|
async openStateObserver<D extends UnknownRecord = UnknownRecord>(): Promise<
|
|
106
135
|
StateObservable<D>
|
|
107
136
|
> {
|
|
137
|
+
if (this.frameClient == null) throw TASK_NOT_CREATED;
|
|
108
138
|
return new framer.ObservableStreamer<State<D>>(
|
|
109
139
|
await this.frameClient.openStreamer(TASK_STATE_CHANNEL),
|
|
110
140
|
(frame) => {
|
|
@@ -118,6 +148,14 @@ export class Task<
|
|
|
118
148
|
},
|
|
119
149
|
);
|
|
120
150
|
}
|
|
151
|
+
|
|
152
|
+
async snapshottedTo(): Promise<ontology.Resource | null> {
|
|
153
|
+
if (this.ontologyClient == null || this.rangeClient == null) throw TASK_NOT_CREATED;
|
|
154
|
+
if (!this.snapshot) return null;
|
|
155
|
+
const parents = await this.ontologyClient.retrieveParents(this.ontologyID);
|
|
156
|
+
if (parents.length == 0) return null;
|
|
157
|
+
return parents[0];
|
|
158
|
+
}
|
|
121
159
|
}
|
|
122
160
|
|
|
123
161
|
const retrieveReqZ = z.object({
|
|
@@ -143,20 +181,36 @@ export type RetrieveOptions = Pick<
|
|
|
143
181
|
const RETRIEVE_ENDPOINT = "/hardware/task/retrieve";
|
|
144
182
|
const CREATE_ENDPOINT = "/hardware/task/create";
|
|
145
183
|
const DELETE_ENDPOINT = "/hardware/task/delete";
|
|
184
|
+
const COPY_ENDPOINT = "/hardware/task/copy";
|
|
146
185
|
|
|
147
186
|
const createReqZ = z.object({ tasks: newTaskZ.array() });
|
|
148
187
|
const createResZ = z.object({ tasks: taskZ.array() });
|
|
149
188
|
const deleteReqZ = z.object({ keys: taskKeyZ.array() });
|
|
150
189
|
const deleteResZ = z.object({});
|
|
190
|
+
const copyReqZ = z.object({
|
|
191
|
+
key: taskKeyZ,
|
|
192
|
+
name: z.string(),
|
|
193
|
+
snapshot: z.boolean(),
|
|
194
|
+
});
|
|
195
|
+
const copyResZ = z.object({ task: taskZ });
|
|
151
196
|
|
|
152
197
|
export class Client implements AsyncTermSearcher<string, TaskKey, Payload> {
|
|
153
198
|
readonly type: string = "task";
|
|
154
199
|
private readonly client: UnaryClient;
|
|
155
200
|
private readonly frameClient: framer.Client;
|
|
201
|
+
private readonly ontologyClient: ontology.Client;
|
|
202
|
+
private readonly rangeClient: ranger.Client;
|
|
156
203
|
|
|
157
|
-
constructor(
|
|
204
|
+
constructor(
|
|
205
|
+
client: UnaryClient,
|
|
206
|
+
frameClient: framer.Client,
|
|
207
|
+
ontologyClient: ontology.Client,
|
|
208
|
+
rangeClient: ranger.Client,
|
|
209
|
+
) {
|
|
158
210
|
this.client = client;
|
|
159
211
|
this.frameClient = frameClient;
|
|
212
|
+
this.ontologyClient = ontologyClient;
|
|
213
|
+
this.rangeClient = rangeClient;
|
|
160
214
|
}
|
|
161
215
|
|
|
162
216
|
async create<
|
|
@@ -251,6 +305,17 @@ export class Client implements AsyncTermSearcher<string, TaskKey, Payload> {
|
|
|
251
305
|
return single && variant !== "rack" ? sugared[0] : sugared;
|
|
252
306
|
}
|
|
253
307
|
|
|
308
|
+
async copy(key: string, name: string, snapshot: boolean): Promise<Task> {
|
|
309
|
+
const res = await sendRequired(
|
|
310
|
+
this.client,
|
|
311
|
+
COPY_ENDPOINT,
|
|
312
|
+
{ key, name, snapshot },
|
|
313
|
+
copyReqZ,
|
|
314
|
+
copyResZ,
|
|
315
|
+
);
|
|
316
|
+
return this.sugar([res.task])[0];
|
|
317
|
+
}
|
|
318
|
+
|
|
254
319
|
async retrieveByName(name: string, rack?: number): Promise<Task> {
|
|
255
320
|
const tasks = await this.execRetrieve({ names: [name], rack });
|
|
256
321
|
checkForMultipleOrNoResults("Task", name, tasks, true);
|
|
@@ -270,8 +335,19 @@ export class Client implements AsyncTermSearcher<string, TaskKey, Payload> {
|
|
|
270
335
|
|
|
271
336
|
private sugar(payloads: Payload[]): Task[] {
|
|
272
337
|
return payloads.map(
|
|
273
|
-
({ key, name, type, config, state, internal }) =>
|
|
274
|
-
new Task(
|
|
338
|
+
({ key, name, type, config, state, internal, snapshot }) =>
|
|
339
|
+
new Task(
|
|
340
|
+
key,
|
|
341
|
+
name,
|
|
342
|
+
type,
|
|
343
|
+
config,
|
|
344
|
+
internal,
|
|
345
|
+
snapshot,
|
|
346
|
+
state,
|
|
347
|
+
this.frameClient,
|
|
348
|
+
this.ontologyClient,
|
|
349
|
+
this.rangeClient,
|
|
350
|
+
),
|
|
275
351
|
);
|
|
276
352
|
}
|
|
277
353
|
|