@synnaxlabs/client 0.45.1 → 0.46.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 +7 -7
- package/dist/access/policy/client.d.ts +38 -26
- package/dist/access/policy/client.d.ts.map +1 -1
- package/dist/access/policy/payload.d.ts +22 -10
- package/dist/access/policy/payload.d.ts.map +1 -1
- package/dist/arc/client.d.ts +72 -0
- package/dist/arc/client.d.ts.map +1 -0
- package/dist/arc/external.d.ts +3 -0
- package/dist/arc/external.d.ts.map +1 -0
- package/dist/arc/index.d.ts +2 -0
- package/dist/arc/index.d.ts.map +1 -0
- package/dist/arc/payload.d.ts +155 -0
- package/dist/arc/payload.d.ts.map +1 -0
- package/dist/channel/client.d.ts +2 -3
- package/dist/channel/client.d.ts.map +1 -1
- package/dist/channel/payload.d.ts +23 -63
- package/dist/channel/payload.d.ts.map +1 -1
- package/dist/channel/retriever.d.ts.map +1 -1
- package/dist/client.cjs +44 -25
- package/dist/client.d.ts +5 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +7449 -4753
- package/dist/framer/client.d.ts +2 -2
- package/dist/framer/client.d.ts.map +1 -1
- package/dist/framer/deleter.d.ts +2 -2
- package/dist/framer/frame.d.ts +2 -2
- package/dist/framer/streamer.d.ts +42 -56
- package/dist/framer/streamer.d.ts.map +1 -1
- package/dist/framer/writer.d.ts +45 -43
- package/dist/framer/writer.d.ts.map +1 -1
- package/dist/hardware/device/client.d.ts +5 -6
- package/dist/hardware/device/client.d.ts.map +1 -1
- package/dist/hardware/device/payload.d.ts +83 -18
- package/dist/hardware/device/payload.d.ts.map +1 -1
- package/dist/hardware/rack/client.d.ts +4 -5
- package/dist/hardware/rack/client.d.ts.map +1 -1
- package/dist/hardware/rack/payload.d.ts +81 -17
- package/dist/hardware/rack/payload.d.ts.map +1 -1
- package/dist/hardware/task/client.d.ts +61 -12
- package/dist/hardware/task/client.d.ts.map +1 -1
- package/dist/hardware/task/payload.d.ts +18 -51
- package/dist/hardware/task/payload.d.ts.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/label/client.d.ts +14 -9
- package/dist/label/client.d.ts.map +1 -1
- package/dist/label/payload.d.ts +10 -11
- package/dist/label/payload.d.ts.map +1 -1
- package/dist/ontology/client.d.ts +7 -3
- package/dist/ontology/client.d.ts.map +1 -1
- package/dist/ontology/group/client.d.ts +45 -9
- package/dist/ontology/group/client.d.ts.map +1 -1
- package/dist/ontology/group/external.d.ts +0 -1
- package/dist/ontology/group/external.d.ts.map +1 -1
- package/dist/ontology/group/payload.d.ts +3 -1
- package/dist/ontology/group/payload.d.ts.map +1 -1
- package/dist/ontology/payload.d.ts +30 -17
- package/dist/ontology/payload.d.ts.map +1 -1
- package/dist/ontology/writer.d.ts +161 -0
- package/dist/ontology/writer.d.ts.map +1 -1
- package/dist/ranger/alias.d.ts +1 -1
- package/dist/ranger/alias.d.ts.map +1 -1
- package/dist/ranger/client.d.ts +9 -8
- package/dist/ranger/client.d.ts.map +1 -1
- package/dist/ranger/kv.d.ts.map +1 -1
- package/dist/ranger/payload.d.ts +5 -5
- package/dist/ranger/payload.d.ts.map +1 -1
- package/dist/ranger/writer.d.ts +6 -4
- package/dist/ranger/writer.d.ts.map +1 -1
- package/dist/status/client.d.ts +63 -0
- package/dist/status/client.d.ts.map +1 -0
- package/dist/status/external.d.ts +3 -0
- package/dist/status/external.d.ts.map +1 -0
- package/dist/status/index.d.ts +2 -0
- package/dist/status/index.d.ts.map +1 -0
- package/dist/status/payload.d.ts +32 -0
- package/dist/status/payload.d.ts.map +1 -0
- package/dist/status/status.spec.d.ts +2 -0
- package/dist/status/status.spec.d.ts.map +1 -0
- package/dist/user/client.d.ts.map +1 -1
- package/dist/user/retriever.d.ts.map +1 -1
- package/dist/workspace/client.d.ts +11 -6
- package/dist/workspace/client.d.ts.map +1 -1
- package/dist/workspace/lineplot/client.d.ts +28 -5
- package/dist/workspace/lineplot/client.d.ts.map +1 -1
- package/dist/workspace/lineplot/index.d.ts +1 -1
- package/dist/workspace/log/client.d.ts +28 -5
- package/dist/workspace/log/client.d.ts.map +1 -1
- package/dist/workspace/schematic/client.d.ts +35 -6
- package/dist/workspace/schematic/client.d.ts.map +1 -1
- package/dist/workspace/schematic/symbol/client.d.ts +6 -7
- package/dist/workspace/schematic/symbol/client.d.ts.map +1 -1
- package/dist/workspace/table/client.d.ts +28 -5
- package/dist/workspace/table/client.d.ts.map +1 -1
- package/examples/node/package-lock.json +30 -95
- package/examples/node/package.json +1 -1
- package/package.json +9 -9
- package/src/access/policy/client.ts +5 -6
- package/src/access/policy/payload.ts +4 -4
- package/src/access/policy/policy.spec.ts +4 -4
- package/src/arc/client.ts +117 -0
- package/src/{util/zod.ts → arc/external.ts} +2 -7
- package/src/arc/index.ts +10 -0
- package/src/arc/payload.ts +69 -0
- package/src/channel/client.ts +3 -4
- package/src/channel/payload.ts +4 -6
- package/src/channel/retriever.ts +2 -2
- package/src/client.ts +8 -2
- package/src/errors.spec.ts +1 -1
- package/src/framer/client.ts +4 -3
- package/src/framer/codec.spec.ts +1 -1
- package/src/hardware/device/client.ts +6 -8
- package/src/hardware/device/payload.ts +7 -6
- package/src/hardware/rack/client.ts +6 -8
- package/src/hardware/rack/payload.ts +2 -1
- package/src/hardware/task/client.ts +140 -100
- package/src/hardware/task/payload.ts +4 -4
- package/src/hardware/task/task.spec.ts +9 -2
- package/src/index.ts +3 -1
- package/src/label/client.ts +5 -8
- package/src/label/payload.ts +6 -11
- package/src/ontology/client.ts +3 -3
- package/src/ontology/group/client.ts +51 -18
- package/src/ontology/group/external.ts +0 -1
- package/src/ontology/group/group.spec.ts +6 -5
- package/src/ontology/group/payload.ts +5 -1
- package/src/ontology/ontology.spec.ts +88 -21
- package/src/ontology/payload.ts +15 -6
- package/src/ontology/writer.ts +3 -5
- package/src/ranger/alias.ts +2 -2
- package/src/ranger/client.ts +7 -3
- package/src/ranger/kv.ts +1 -2
- package/src/ranger/payload.ts +13 -1
- package/src/ranger/ranger.spec.ts +65 -1
- package/src/status/client.ts +129 -0
- package/src/status/external.ts +11 -0
- package/src/status/index.ts +10 -0
- package/src/status/payload.ts +35 -0
- package/src/status/status.spec.ts +352 -0
- package/src/user/client.ts +1 -2
- package/src/user/payload.ts +1 -1
- package/src/user/retriever.ts +2 -2
- package/src/user/user.spec.ts +41 -41
- package/src/workspace/client.ts +18 -15
- package/src/workspace/lineplot/client.ts +27 -13
- package/src/workspace/lineplot/index.ts +1 -1
- package/src/workspace/lineplot/lineplot.spec.ts +13 -10
- package/src/workspace/log/client.ts +26 -12
- package/src/workspace/log/log.spec.ts +13 -10
- package/src/workspace/payload.ts +1 -1
- package/src/workspace/schematic/client.ts +42 -17
- package/src/workspace/schematic/schematic.spec.ts +29 -25
- package/src/workspace/schematic/symbol/client.spec.ts +27 -24
- package/src/workspace/schematic/symbol/client.ts +6 -9
- package/src/workspace/table/client.ts +26 -12
- package/src/workspace/table/table.spec.ts +13 -10
- package/dist/ontology/group/group.d.ts +0 -10
- package/dist/ontology/group/group.d.ts.map +0 -1
- package/dist/ontology/group/writer.d.ts +0 -14
- package/dist/ontology/group/writer.d.ts.map +0 -1
- package/dist/util/zod.d.ts +0 -3
- package/dist/util/zod.d.ts.map +0 -1
- package/src/ontology/group/group.ts +0 -27
- package/src/ontology/group/writer.ts +0 -71
package/src/client.ts
CHANGED
|
@@ -13,6 +13,7 @@ import { URL } from "@synnaxlabs/x/url";
|
|
|
13
13
|
import { z } from "zod";
|
|
14
14
|
|
|
15
15
|
import { access } from "@/access";
|
|
16
|
+
import { arc } from "@/arc";
|
|
16
17
|
import { auth } from "@/auth";
|
|
17
18
|
import { channel } from "@/channel";
|
|
18
19
|
import { connection } from "@/connection";
|
|
@@ -26,6 +27,7 @@ import { task } from "@/hardware/task";
|
|
|
26
27
|
import { label } from "@/label";
|
|
27
28
|
import { ontology } from "@/ontology";
|
|
28
29
|
import { ranger } from "@/ranger";
|
|
30
|
+
import { status } from "@/status";
|
|
29
31
|
import { Transport } from "@/transport";
|
|
30
32
|
import { user } from "@/user";
|
|
31
33
|
import { workspace } from "@/workspace";
|
|
@@ -60,14 +62,16 @@ export default class Synnax extends framer.Client {
|
|
|
60
62
|
readonly ranges: ranger.Client;
|
|
61
63
|
readonly channels: channel.Client;
|
|
62
64
|
readonly auth: auth.Client | undefined;
|
|
63
|
-
readonly
|
|
65
|
+
readonly users: user.Client;
|
|
64
66
|
readonly access: access.Client;
|
|
65
67
|
readonly connectivity: connection.Checker;
|
|
66
68
|
readonly ontology: ontology.Client;
|
|
67
69
|
readonly workspaces: workspace.Client;
|
|
68
70
|
readonly labels: label.Client;
|
|
71
|
+
readonly statuses: status.Client;
|
|
69
72
|
readonly hardware: hardware.Client;
|
|
70
73
|
readonly control: control.Client;
|
|
74
|
+
readonly arcs: arc.Client;
|
|
71
75
|
static readonly connectivity = connection.Checker;
|
|
72
76
|
private readonly transport: Transport;
|
|
73
77
|
|
|
@@ -133,6 +137,7 @@ export default class Synnax extends framer.Client {
|
|
|
133
137
|
this.ontology = new ontology.Client(transport.unary, this);
|
|
134
138
|
const rangeWriter = new ranger.Writer(this.transport.unary);
|
|
135
139
|
this.labels = new label.Client(this.transport.unary);
|
|
140
|
+
this.statuses = new status.Client(this.transport.unary);
|
|
136
141
|
this.ranges = new ranger.Client(
|
|
137
142
|
this,
|
|
138
143
|
rangeWriter,
|
|
@@ -142,7 +147,7 @@ export default class Synnax extends framer.Client {
|
|
|
142
147
|
this.ontology,
|
|
143
148
|
);
|
|
144
149
|
this.access = new access.Client(this.transport.unary);
|
|
145
|
-
this.
|
|
150
|
+
this.users = new user.Client(this.transport.unary);
|
|
146
151
|
this.workspaces = new workspace.Client(this.transport.unary);
|
|
147
152
|
const devices = new device.Client(this.transport.unary);
|
|
148
153
|
const tasks = new task.Client(
|
|
@@ -153,6 +158,7 @@ export default class Synnax extends framer.Client {
|
|
|
153
158
|
);
|
|
154
159
|
const racks = new rack.Client(this.transport.unary, tasks);
|
|
155
160
|
this.hardware = new hardware.Client(tasks, racks, devices);
|
|
161
|
+
this.arcs = new arc.Client(this.transport.unary);
|
|
156
162
|
}
|
|
157
163
|
|
|
158
164
|
get key(): string {
|
package/src/errors.spec.ts
CHANGED
|
@@ -64,7 +64,7 @@ test("client", async () => {
|
|
|
64
64
|
expect(NotFoundError.matches(e)).toBe(true);
|
|
65
65
|
}
|
|
66
66
|
try {
|
|
67
|
-
await client.workspaces.
|
|
67
|
+
await client.workspaces.schematics.retrieve({ key: uuid.create() });
|
|
68
68
|
} catch (e) {
|
|
69
69
|
expect(NotFoundError.matches(e)).toBe(true);
|
|
70
70
|
}
|
package/src/framer/client.ts
CHANGED
|
@@ -199,16 +199,17 @@ export class Client {
|
|
|
199
199
|
return frame;
|
|
200
200
|
}
|
|
201
201
|
|
|
202
|
-
async delete(channels: channel.Params, timeRange:
|
|
202
|
+
async delete(channels: channel.Params, timeRange: CrudeTimeRange): Promise<void> {
|
|
203
203
|
const { normalized, variant } = channel.analyzeParams(channels);
|
|
204
|
+
const bounds = new TimeRange(timeRange);
|
|
204
205
|
if (variant === "keys")
|
|
205
206
|
return await this.deleter.delete({
|
|
206
207
|
keys: normalized as channel.Key[],
|
|
207
|
-
bounds
|
|
208
|
+
bounds,
|
|
208
209
|
});
|
|
209
210
|
return await this.deleter.delete({
|
|
210
211
|
names: normalized as string[],
|
|
211
|
-
bounds
|
|
212
|
+
bounds,
|
|
212
213
|
});
|
|
213
214
|
}
|
|
214
215
|
}
|
package/src/framer/codec.spec.ts
CHANGED
|
@@ -206,7 +206,7 @@ describe("encoder", () => {
|
|
|
206
206
|
const ser = spec.frame.get(k);
|
|
207
207
|
expect(ser.series.length).toBeGreaterThan(0);
|
|
208
208
|
const os = ser.series[0];
|
|
209
|
-
if (dcs.timeRange != null && !dcs.timeRange.isZero)
|
|
209
|
+
if (dcs.timeRange != null && !dcs.timeRange.span.isZero)
|
|
210
210
|
expect(dcs.timeRange.toString()).toEqual(os.timeRange?.toString());
|
|
211
211
|
expect(new Series(dcs).toString()).toEqual(os.toString());
|
|
212
212
|
});
|
|
@@ -22,7 +22,6 @@ import {
|
|
|
22
22
|
import { keyZ as rackKeyZ } from "@/hardware/rack/payload";
|
|
23
23
|
import { type ontology } from "@/ontology";
|
|
24
24
|
import { checkForMultipleOrNoResults } from "@/util/retrieve";
|
|
25
|
-
import { nullableArrayZ } from "@/util/zod";
|
|
26
25
|
|
|
27
26
|
export const SET_CHANNEL_NAME = "sy_device_set";
|
|
28
27
|
export const DELETE_CHANNEL_NAME = "sy_device_delete";
|
|
@@ -50,7 +49,7 @@ const retrieveRequestZ = z.object({
|
|
|
50
49
|
offset: z.number().optional(),
|
|
51
50
|
includeStatus: z.boolean().optional(),
|
|
52
51
|
});
|
|
53
|
-
const retrieveResZ = z.object({ devices:
|
|
52
|
+
const retrieveResZ = z.object({ devices: array.nullableZ(deviceZ) });
|
|
54
53
|
|
|
55
54
|
const singleRetrieveArgsZ = z
|
|
56
55
|
.object({
|
|
@@ -62,15 +61,14 @@ const singleRetrieveArgsZ = z
|
|
|
62
61
|
includeStatus,
|
|
63
62
|
}));
|
|
64
63
|
|
|
65
|
-
export type
|
|
66
|
-
export type
|
|
64
|
+
export type RetrieveSingleParams = z.input<typeof singleRetrieveArgsZ>;
|
|
65
|
+
export type RetrieveMultipleParams = z.input<typeof retrieveRequestZ>;
|
|
67
66
|
|
|
68
67
|
const retrieveArgsZ = z.union([singleRetrieveArgsZ, retrieveRequestZ]);
|
|
69
68
|
|
|
70
69
|
export type RetrieveArgs = z.input<typeof retrieveArgsZ>;
|
|
71
70
|
|
|
72
71
|
export class Client {
|
|
73
|
-
readonly type = "device";
|
|
74
72
|
private readonly client: UnaryClient;
|
|
75
73
|
|
|
76
74
|
constructor(client: UnaryClient) {
|
|
@@ -81,13 +79,13 @@ export class Client {
|
|
|
81
79
|
Properties extends record.Unknown = record.Unknown,
|
|
82
80
|
Make extends string = string,
|
|
83
81
|
Model extends string = string,
|
|
84
|
-
>(args:
|
|
82
|
+
>(args: RetrieveSingleParams): Promise<Device<Properties, Make, Model>>;
|
|
85
83
|
|
|
86
84
|
async retrieve<
|
|
87
85
|
Properties extends record.Unknown = record.Unknown,
|
|
88
86
|
Make extends string = string,
|
|
89
87
|
Model extends string = string,
|
|
90
|
-
>(args:
|
|
88
|
+
>(args: RetrieveMultipleParams): Promise<Array<Device<Properties, Make, Model>>>;
|
|
91
89
|
|
|
92
90
|
async retrieve<
|
|
93
91
|
Properties extends record.Unknown = record.Unknown,
|
|
@@ -138,7 +136,7 @@ export class Client {
|
|
|
138
136
|
return isSingle ? created[0] : created;
|
|
139
137
|
}
|
|
140
138
|
|
|
141
|
-
async delete(keys:
|
|
139
|
+
async delete(keys: Key | Key[]): Promise<void> {
|
|
142
140
|
await sendRequired(
|
|
143
141
|
this.client,
|
|
144
142
|
DELETE_ENDPOINT,
|
|
@@ -16,17 +16,18 @@ import { decodeJSONString } from "@/util/decodeJSONString";
|
|
|
16
16
|
export const keyZ = z.string();
|
|
17
17
|
export type Key = z.infer<typeof keyZ>;
|
|
18
18
|
|
|
19
|
-
export const
|
|
19
|
+
export const statusDetailsSchema = z.object({ rack: rackKeyZ, device: keyZ });
|
|
20
|
+
export const statusZ = status.statusZ(statusDetailsSchema);
|
|
20
21
|
|
|
21
22
|
export interface Status extends z.infer<typeof statusZ> {}
|
|
22
23
|
|
|
23
24
|
export const deviceZ = z.object({
|
|
24
25
|
key: keyZ,
|
|
25
|
-
rack: rackKeyZ,
|
|
26
|
-
name: z.string(),
|
|
27
|
-
make: z.string(),
|
|
28
|
-
model: z.string(),
|
|
29
|
-
location: z.string(),
|
|
26
|
+
rack: rackKeyZ.min(1, "Must select a location to connect from"),
|
|
27
|
+
name: z.string().min(1, "Name is required"),
|
|
28
|
+
make: z.string().min(1, "Make is required"),
|
|
29
|
+
model: z.string().min(1, "Model is required"),
|
|
30
|
+
location: z.string().min(1, "Location is required"),
|
|
30
31
|
configured: z.boolean().optional(),
|
|
31
32
|
properties: record.unknownZ.or(z.string().transform(decodeJSONString)),
|
|
32
33
|
status: zod.nullToUndefined(statusZ),
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// included in the file licenses/APL.txt.
|
|
9
9
|
|
|
10
10
|
import { sendRequired, type UnaryClient } from "@synnaxlabs/freighter";
|
|
11
|
-
import { array } from "@synnaxlabs/x
|
|
11
|
+
import { array } from "@synnaxlabs/x";
|
|
12
12
|
import { z } from "zod";
|
|
13
13
|
|
|
14
14
|
import {
|
|
@@ -23,7 +23,6 @@ import {
|
|
|
23
23
|
import { type task } from "@/hardware/task";
|
|
24
24
|
import { type ontology } from "@/ontology";
|
|
25
25
|
import { checkForMultipleOrNoResults } from "@/util/retrieve";
|
|
26
|
-
import { nullableArrayZ } from "@/util/zod";
|
|
27
26
|
|
|
28
27
|
const RETRIEVE_ENDPOINT = "/hardware/rack/retrieve";
|
|
29
28
|
const CREATE_ENDPOINT = "/hardware/rack/create";
|
|
@@ -43,7 +42,7 @@ const retrieveReqZ = z.object({
|
|
|
43
42
|
offset: z.number().optional(),
|
|
44
43
|
includeStatus: z.boolean().optional(),
|
|
45
44
|
});
|
|
46
|
-
const retrieveResZ = z.object({ racks:
|
|
45
|
+
const retrieveResZ = z.object({ racks: array.nullableZ(rackZ) });
|
|
47
46
|
|
|
48
47
|
const singleRetrieveArgsZ = z.union([
|
|
49
48
|
z
|
|
@@ -59,11 +58,11 @@ const singleRetrieveArgsZ = z.union([
|
|
|
59
58
|
})
|
|
60
59
|
.transform(({ name, includeStatus }) => ({ names: [name], includeStatus })),
|
|
61
60
|
]);
|
|
62
|
-
export type
|
|
61
|
+
export type RetrieveSingleParams = z.input<typeof singleRetrieveArgsZ>;
|
|
63
62
|
|
|
64
63
|
const multiRetrieveArgsZ = retrieveReqZ;
|
|
65
64
|
|
|
66
|
-
export type
|
|
65
|
+
export type RetrieveMultipleParams = z.input<typeof multiRetrieveArgsZ>;
|
|
67
66
|
|
|
68
67
|
const retrieveArgsZ = z.union([singleRetrieveArgsZ, multiRetrieveArgsZ]);
|
|
69
68
|
|
|
@@ -76,7 +75,6 @@ const deleteReqZ = z.object({ keys: keyZ.array() });
|
|
|
76
75
|
const deleteResZ = z.object({});
|
|
77
76
|
|
|
78
77
|
export class Client {
|
|
79
|
-
readonly type = "rack";
|
|
80
78
|
private readonly client: UnaryClient;
|
|
81
79
|
private readonly tasks: task.Client;
|
|
82
80
|
|
|
@@ -110,8 +108,8 @@ export class Client {
|
|
|
110
108
|
return isSingle ? sugared[0] : sugared;
|
|
111
109
|
}
|
|
112
110
|
|
|
113
|
-
async retrieve(args:
|
|
114
|
-
async retrieve(args:
|
|
111
|
+
async retrieve(args: RetrieveSingleParams): Promise<Rack>;
|
|
112
|
+
async retrieve(args: RetrieveMultipleParams): Promise<Rack[]>;
|
|
115
113
|
async retrieve(args: RetrieveArgs): Promise<Rack | Rack[]> {
|
|
116
114
|
const isSingle = "key" in args || "name" in args;
|
|
117
115
|
const res = await sendRequired(
|
|
@@ -13,7 +13,8 @@ import { z } from "zod";
|
|
|
13
13
|
export const keyZ = z.uint32();
|
|
14
14
|
export type Key = z.infer<typeof keyZ>;
|
|
15
15
|
|
|
16
|
-
export const
|
|
16
|
+
export const statusDetailsSchema = z.object({ rack: keyZ });
|
|
17
|
+
export const statusZ = status.statusZ(statusDetailsSchema);
|
|
17
18
|
|
|
18
19
|
export interface Status extends z.infer<typeof statusZ> {}
|
|
19
20
|
|
|
@@ -8,8 +8,7 @@
|
|
|
8
8
|
// included in the file licenses/APL.txt.
|
|
9
9
|
|
|
10
10
|
import { sendRequired, type UnaryClient } from "@synnaxlabs/freighter";
|
|
11
|
-
import { caseconv, id, strings } from "@synnaxlabs/x";
|
|
12
|
-
import { array } from "@synnaxlabs/x/array";
|
|
11
|
+
import { array, caseconv, id, type record, strings } from "@synnaxlabs/x";
|
|
13
12
|
import { type CrudeTimeSpan, TimeSpan } from "@synnaxlabs/x/telem";
|
|
14
13
|
import { z } from "zod";
|
|
15
14
|
|
|
@@ -29,7 +28,6 @@ import {
|
|
|
29
28
|
import { type ontology } from "@/ontology";
|
|
30
29
|
import { type ranger } from "@/ranger";
|
|
31
30
|
import { checkForMultipleOrNoResults } from "@/util/retrieve";
|
|
32
|
-
import { nullableArrayZ } from "@/util/zod";
|
|
33
31
|
|
|
34
32
|
export const STATUS_CHANNEL_NAME = "sy_task_status";
|
|
35
33
|
export const COMMAND_CHANNEL_NAME = "sy_task_cmd";
|
|
@@ -44,6 +42,29 @@ const retrieveSnapshottedTo = async (taskKey: Key, ontologyClient: ontology.Clie
|
|
|
44
42
|
return parents[0];
|
|
45
43
|
};
|
|
46
44
|
|
|
45
|
+
export interface TaskExecuteCommandParams {
|
|
46
|
+
type: string;
|
|
47
|
+
args?: record.Unknown;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface ExecuteCommandParams extends TaskExecuteCommandParams {
|
|
51
|
+
task: Key;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface ExecuteCommandsParams {
|
|
55
|
+
commands: NewCommand[];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export interface TaskExecuteCommandSyncParams extends TaskExecuteCommandParams {
|
|
59
|
+
timeout?: CrudeTimeSpan;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface ExecuteCommandsSyncParams<StatusData extends z.ZodType>
|
|
63
|
+
extends Omit<ExecuteCommandsSyncInternalParams<StatusData>, "frameClient" | "name"> {}
|
|
64
|
+
|
|
65
|
+
export interface ExecuteCommandSyncParams<StatusData extends z.ZodType>
|
|
66
|
+
extends Omit<ExecuteCommandSyncInternalParams<StatusData>, "frameClient" | "name"> {}
|
|
67
|
+
|
|
47
68
|
export class Task<
|
|
48
69
|
Type extends z.ZodLiteral<string> = z.ZodLiteral<string>,
|
|
49
70
|
Config extends z.ZodType = z.ZodType,
|
|
@@ -124,24 +145,24 @@ export class Task<
|
|
|
124
145
|
return ontologyID(this.key);
|
|
125
146
|
}
|
|
126
147
|
|
|
127
|
-
async executeCommand(
|
|
128
|
-
return await executeCommand(
|
|
148
|
+
async executeCommand(params: TaskExecuteCommandParams): Promise<string> {
|
|
149
|
+
return await executeCommand({
|
|
150
|
+
...params,
|
|
151
|
+
frameClient: this.frameClient,
|
|
152
|
+
task: this.key,
|
|
153
|
+
});
|
|
129
154
|
}
|
|
130
155
|
|
|
131
156
|
async executeCommandSync(
|
|
132
|
-
|
|
133
|
-
timeout: CrudeTimeSpan,
|
|
134
|
-
args?: {},
|
|
157
|
+
params: TaskExecuteCommandSyncParams,
|
|
135
158
|
): Promise<Status<StatusData>> {
|
|
136
|
-
return await executeCommandSync<StatusData>(
|
|
137
|
-
|
|
138
|
-
this.
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
this.
|
|
142
|
-
|
|
143
|
-
args,
|
|
144
|
-
);
|
|
159
|
+
return await executeCommandSync<StatusData>({
|
|
160
|
+
...params,
|
|
161
|
+
frameClient: this.frameClient,
|
|
162
|
+
task: this.key,
|
|
163
|
+
name: this.name,
|
|
164
|
+
statusDataZ: this.schemas?.statusDataSchema,
|
|
165
|
+
});
|
|
145
166
|
}
|
|
146
167
|
|
|
147
168
|
async snapshottedTo(): Promise<ontology.Resource | null> {
|
|
@@ -158,6 +179,7 @@ const retrieveReqZ = z.object({
|
|
|
158
179
|
names: z.string().array().optional(),
|
|
159
180
|
types: z.string().array().optional(),
|
|
160
181
|
includeStatus: z.boolean().optional(),
|
|
182
|
+
searchTerm: z.string().optional(),
|
|
161
183
|
offset: z.number().optional(),
|
|
162
184
|
limit: z.number().optional(),
|
|
163
185
|
});
|
|
@@ -169,11 +191,17 @@ const singleRetrieveArgsZ = z.union([
|
|
|
169
191
|
z
|
|
170
192
|
.object({ name: z.string(), includeStatus: z.boolean().optional() })
|
|
171
193
|
.transform(({ name, includeStatus }) => ({ names: [name], includeStatus })),
|
|
194
|
+
z
|
|
195
|
+
.object({
|
|
196
|
+
type: z.string(),
|
|
197
|
+
rack: rackKeyZ.optional(),
|
|
198
|
+
})
|
|
199
|
+
.transform(({ type, rack }) => ({ types: [type], rack })),
|
|
172
200
|
]);
|
|
173
|
-
export type
|
|
201
|
+
export type RetrieveSingleParams = z.input<typeof singleRetrieveArgsZ>;
|
|
174
202
|
|
|
175
203
|
const multiRetrieveArgsZ = retrieveReqZ;
|
|
176
|
-
export type
|
|
204
|
+
export type RetrieveMultipleParams = z.input<typeof multiRetrieveArgsZ>;
|
|
177
205
|
|
|
178
206
|
const retrieveArgsZ = z.union([singleRetrieveArgsZ, multiRetrieveArgsZ]);
|
|
179
207
|
export type RetrieveArgs = z.input<typeof retrieveArgsZ>;
|
|
@@ -194,7 +222,7 @@ const retrieveResZ = <
|
|
|
194
222
|
schemas?: Schemas<Type, Config, StatusData>,
|
|
195
223
|
) =>
|
|
196
224
|
z.object({
|
|
197
|
-
tasks:
|
|
225
|
+
tasks: array.nullableZ(taskZ(schemas)),
|
|
198
226
|
});
|
|
199
227
|
|
|
200
228
|
export interface RetrieveRequest extends z.infer<typeof retrieveReqZ> {}
|
|
@@ -309,17 +337,17 @@ export class Client {
|
|
|
309
337
|
Config extends z.ZodType,
|
|
310
338
|
StatusData extends z.ZodType,
|
|
311
339
|
>(
|
|
312
|
-
args:
|
|
340
|
+
args: RetrieveSingleParams & RetrieveSchemas<Type, Config, StatusData>,
|
|
313
341
|
): Promise<Task<Type, Config, StatusData>>;
|
|
314
|
-
async retrieve(args:
|
|
342
|
+
async retrieve(args: RetrieveSingleParams): Promise<Task>;
|
|
315
343
|
async retrieve<
|
|
316
344
|
Type extends z.ZodLiteral<string>,
|
|
317
345
|
Config extends z.ZodType,
|
|
318
346
|
StatusData extends z.ZodType,
|
|
319
347
|
>(
|
|
320
|
-
args:
|
|
348
|
+
args: RetrieveMultipleParams & RetrieveSchemas<Type, Config, StatusData>,
|
|
321
349
|
): Promise<Task<Type, Config, StatusData>[]>;
|
|
322
|
-
async retrieve(args:
|
|
350
|
+
async retrieve(args: RetrieveMultipleParams): Promise<Task[]>;
|
|
323
351
|
async retrieve<
|
|
324
352
|
Type extends z.ZodLiteral<string>,
|
|
325
353
|
Config extends z.ZodType,
|
|
@@ -330,7 +358,7 @@ export class Client {
|
|
|
330
358
|
}: RetrieveArgs & RetrieveSchemas<Type, Config, StatusData>): Promise<
|
|
331
359
|
Task<Type, Config, StatusData> | Task<Type, Config, StatusData>[]
|
|
332
360
|
> {
|
|
333
|
-
const isSingle =
|
|
361
|
+
const isSingle = singleRetrieveArgsZ.safeParse(args).success;
|
|
334
362
|
const res = await sendRequired(
|
|
335
363
|
this.client,
|
|
336
364
|
RETRIEVE_ENDPOINT,
|
|
@@ -409,79 +437,72 @@ export class Client {
|
|
|
409
437
|
return isSingle ? res[0] : res;
|
|
410
438
|
}
|
|
411
439
|
|
|
412
|
-
async executeCommand(
|
|
440
|
+
async executeCommand(params: ExecuteCommandParams): Promise<string>;
|
|
413
441
|
|
|
414
|
-
async executeCommand(
|
|
442
|
+
async executeCommand(params: ExecuteCommandsParams): Promise<string[]>;
|
|
415
443
|
|
|
416
444
|
async executeCommand(
|
|
417
|
-
|
|
418
|
-
type?: string,
|
|
419
|
-
args?: {},
|
|
445
|
+
params: ExecuteCommandParams | ExecuteCommandsParams,
|
|
420
446
|
): Promise<string | string[]> {
|
|
421
|
-
if (
|
|
422
|
-
|
|
423
|
-
return await executeCommand(this.frameClient
|
|
447
|
+
if ("commands" in params)
|
|
448
|
+
return await executeCommands({ ...params, frameClient: this.frameClient });
|
|
449
|
+
return await executeCommand({ ...params, frameClient: this.frameClient });
|
|
424
450
|
}
|
|
425
451
|
|
|
426
452
|
async executeCommandSync<StatusData extends z.ZodType = z.ZodType>(
|
|
427
|
-
|
|
428
|
-
type: string,
|
|
429
|
-
timeout: CrudeTimeSpan,
|
|
430
|
-
args?: {},
|
|
431
|
-
name?: string,
|
|
432
|
-
statusDataZ?: StatusData,
|
|
433
|
-
): Promise<Status<StatusData>>;
|
|
434
|
-
async executeCommandSync<StatusData extends z.ZodType = z.ZodType>(
|
|
435
|
-
commands: NewCommand[],
|
|
436
|
-
timeout: CrudeTimeSpan,
|
|
437
|
-
statusDataZ?: StatusData,
|
|
453
|
+
parms: ExecuteCommandsSyncParams<StatusData>,
|
|
438
454
|
): Promise<Status<StatusData>[]>;
|
|
439
455
|
|
|
440
456
|
async executeCommandSync<StatusData extends z.ZodType = z.ZodType>(
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
457
|
+
parms: ExecuteCommandSyncParams<StatusData>,
|
|
458
|
+
): Promise<Status<StatusData>>;
|
|
459
|
+
|
|
460
|
+
async executeCommandSync<StatusData extends z.ZodType = z.ZodType>(
|
|
461
|
+
params:
|
|
462
|
+
| ExecuteCommandsSyncParams<StatusData>
|
|
463
|
+
| ExecuteCommandSyncParams<StatusData>,
|
|
447
464
|
): Promise<Status<StatusData> | Status<StatusData>[]> {
|
|
448
|
-
if (
|
|
465
|
+
if ("commands" in params) {
|
|
449
466
|
const retrieveNames = async () => {
|
|
450
|
-
const
|
|
467
|
+
const { commands } = params;
|
|
468
|
+
const ts = await this.retrieve({ keys: commands.map((t) => t.task) });
|
|
451
469
|
return ts.map((t) => t.name);
|
|
452
470
|
};
|
|
453
|
-
return await executeCommandsSync(
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
retrieveNames,
|
|
459
|
-
);
|
|
471
|
+
return await executeCommandsSync({
|
|
472
|
+
...params,
|
|
473
|
+
frameClient: this.frameClient,
|
|
474
|
+
name: retrieveNames,
|
|
475
|
+
});
|
|
460
476
|
}
|
|
461
477
|
const retrieveName = async () => {
|
|
478
|
+
const { task } = params;
|
|
462
479
|
const t = await this.retrieve({ key: task });
|
|
463
480
|
return t.name;
|
|
464
481
|
};
|
|
465
|
-
return await executeCommandSync(
|
|
466
|
-
this.frameClient,
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
name ?? retrieveName,
|
|
471
|
-
statusDataZ,
|
|
472
|
-
args,
|
|
473
|
-
);
|
|
482
|
+
return await executeCommandSync({
|
|
483
|
+
frameClient: this.frameClient,
|
|
484
|
+
name: retrieveName,
|
|
485
|
+
...params,
|
|
486
|
+
});
|
|
474
487
|
}
|
|
475
488
|
}
|
|
476
489
|
|
|
477
490
|
export const ontologyID = (key: Key): ontology.ID => ({ type: "task", key });
|
|
478
491
|
|
|
479
|
-
|
|
480
|
-
frameClient: framer.Client | null
|
|
481
|
-
task: Key
|
|
482
|
-
type: string
|
|
483
|
-
args?: {}
|
|
484
|
-
|
|
492
|
+
interface ExecuteCommandInternalParams {
|
|
493
|
+
frameClient: framer.Client | null;
|
|
494
|
+
task: Key;
|
|
495
|
+
type: string;
|
|
496
|
+
args?: {};
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
const executeCommand = async ({
|
|
500
|
+
frameClient,
|
|
501
|
+
task,
|
|
502
|
+
type,
|
|
503
|
+
args,
|
|
504
|
+
}: ExecuteCommandInternalParams): Promise<string> =>
|
|
505
|
+
(await executeCommands({ frameClient, commands: [{ args, task, type }] }))[0];
|
|
485
506
|
|
|
486
507
|
export interface NewCommand {
|
|
487
508
|
task: Key;
|
|
@@ -489,10 +510,15 @@ export interface NewCommand {
|
|
|
489
510
|
args?: {};
|
|
490
511
|
}
|
|
491
512
|
|
|
492
|
-
|
|
493
|
-
frameClient: framer.Client | null
|
|
494
|
-
commands: NewCommand[]
|
|
495
|
-
|
|
513
|
+
interface ExecuteCommandsInternalParams {
|
|
514
|
+
frameClient: framer.Client | null;
|
|
515
|
+
commands: NewCommand[];
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
const executeCommands = async ({
|
|
519
|
+
frameClient,
|
|
520
|
+
commands,
|
|
521
|
+
}: ExecuteCommandsInternalParams): Promise<string[]> => {
|
|
496
522
|
if (frameClient == null) throw NOT_CREATED_ERROR;
|
|
497
523
|
const w = await frameClient.openWriter(COMMAND_CHANNEL_NAME);
|
|
498
524
|
const cmds = commands.map((c) => ({ ...c, key: id.create() }));
|
|
@@ -501,35 +527,49 @@ const executeCommands = async (
|
|
|
501
527
|
return cmds.map((c) => c.key);
|
|
502
528
|
};
|
|
503
529
|
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
530
|
+
interface ExecuteCommandSyncInternalParams<StatusData extends z.ZodType = z.ZodType>
|
|
531
|
+
extends Omit<ExecuteCommandsSyncInternalParams<StatusData>, "commands">,
|
|
532
|
+
TaskExecuteCommandSyncParams {
|
|
533
|
+
task: Key;
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
const executeCommandSync = async <StatusData extends z.ZodType = z.ZodType>({
|
|
537
|
+
frameClient,
|
|
538
|
+
task,
|
|
539
|
+
type,
|
|
540
|
+
timeout,
|
|
541
|
+
name: taskName,
|
|
542
|
+
statusDataZ,
|
|
543
|
+
args,
|
|
544
|
+
}: ExecuteCommandSyncInternalParams<StatusData>): Promise<Status<StatusData>> =>
|
|
513
545
|
(
|
|
514
|
-
await executeCommandsSync(
|
|
546
|
+
await executeCommandsSync({
|
|
515
547
|
frameClient,
|
|
516
|
-
[{ args, task, type }],
|
|
548
|
+
commands: [{ args, task, type }],
|
|
517
549
|
timeout,
|
|
518
550
|
statusDataZ,
|
|
519
|
-
|
|
520
|
-
)
|
|
551
|
+
name: taskName,
|
|
552
|
+
})
|
|
521
553
|
)[0];
|
|
522
554
|
|
|
523
|
-
|
|
524
|
-
frameClient: framer.Client | null
|
|
525
|
-
commands: NewCommand[]
|
|
526
|
-
timeout
|
|
527
|
-
statusDataZ: StatusData
|
|
528
|
-
|
|
529
|
-
|
|
555
|
+
interface ExecuteCommandsSyncInternalParams<StatusData extends z.ZodType = z.ZodType> {
|
|
556
|
+
frameClient: framer.Client | null;
|
|
557
|
+
commands: NewCommand[];
|
|
558
|
+
timeout?: CrudeTimeSpan;
|
|
559
|
+
statusDataZ: StatusData;
|
|
560
|
+
name: string | string[] | (() => Promise<string | string[]>);
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
const executeCommandsSync = async <StatusData extends z.ZodType = z.ZodType>({
|
|
564
|
+
frameClient,
|
|
565
|
+
commands,
|
|
566
|
+
timeout = TimeSpan.seconds(10),
|
|
567
|
+
statusDataZ,
|
|
568
|
+
name: taskName,
|
|
569
|
+
}: ExecuteCommandsSyncInternalParams<StatusData>): Promise<Status<StatusData>[]> => {
|
|
530
570
|
if (frameClient == null) throw NOT_CREATED_ERROR;
|
|
531
571
|
const streamer = await frameClient.openStreamer(STATUS_CHANNEL_NAME);
|
|
532
|
-
const cmdKeys = await executeCommands(frameClient, commands);
|
|
572
|
+
const cmdKeys = await executeCommands({ frameClient, commands });
|
|
533
573
|
const parsedTimeout = new TimeSpan(timeout);
|
|
534
574
|
let states: Status<StatusData>[] = [];
|
|
535
575
|
let timeoutID: NodeJS.Timeout | undefined;
|
|
@@ -537,7 +577,7 @@ const executeCommandsSync = async <StatusData extends z.ZodType = z.ZodType>(
|
|
|
537
577
|
timeoutID = setTimeout(() => {
|
|
538
578
|
void (async () => {
|
|
539
579
|
const taskKeys = commands.map((c) => c.task);
|
|
540
|
-
reject(await formatTimeoutError("command",
|
|
580
|
+
reject(await formatTimeoutError("command", taskName, parsedTimeout, taskKeys));
|
|
541
581
|
})();
|
|
542
582
|
}, parsedTimeout.milliseconds);
|
|
543
583
|
});
|
|
@@ -21,14 +21,14 @@ export const keyZ = z.union([
|
|
|
21
21
|
]);
|
|
22
22
|
export type Key = z.infer<typeof keyZ>;
|
|
23
23
|
|
|
24
|
-
export const statusDetailsZ = <
|
|
24
|
+
export const statusDetailsZ = <DataSchema extends z.ZodType>(data: DataSchema) =>
|
|
25
25
|
z.object({ task: keyZ, running: z.boolean(), data });
|
|
26
26
|
|
|
27
|
-
export type StatusDetails<
|
|
28
|
-
ReturnType<typeof statusDetailsZ<
|
|
27
|
+
export type StatusDetails<DataSchema extends z.ZodType> = z.infer<
|
|
28
|
+
ReturnType<typeof statusDetailsZ<DataSchema>>
|
|
29
29
|
>;
|
|
30
30
|
|
|
31
|
-
export const statusZ = <
|
|
31
|
+
export const statusZ = <DataSchema extends z.ZodType>(data: DataSchema) =>
|
|
32
32
|
status.statusZ(statusDetailsZ(data));
|
|
33
33
|
|
|
34
34
|
export type Status<StatusData extends z.ZodType = z.ZodUnknown> = z.infer<
|