@synnaxlabs/client 0.45.1 → 0.46.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 +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 +7479 -4756
- 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 +67 -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 +10 -10
- 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 +142 -100
- package/src/hardware/task/payload.ts +4 -4
- package/src/hardware/task/task.spec.ts +53 -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,9 @@ 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
|
+
internal: z.boolean().optional(),
|
|
183
|
+
snapshot: z.boolean().optional(),
|
|
184
|
+
searchTerm: z.string().optional(),
|
|
161
185
|
offset: z.number().optional(),
|
|
162
186
|
limit: z.number().optional(),
|
|
163
187
|
});
|
|
@@ -169,11 +193,17 @@ const singleRetrieveArgsZ = z.union([
|
|
|
169
193
|
z
|
|
170
194
|
.object({ name: z.string(), includeStatus: z.boolean().optional() })
|
|
171
195
|
.transform(({ name, includeStatus }) => ({ names: [name], includeStatus })),
|
|
196
|
+
z
|
|
197
|
+
.object({
|
|
198
|
+
type: z.string(),
|
|
199
|
+
rack: rackKeyZ.optional(),
|
|
200
|
+
})
|
|
201
|
+
.transform(({ type, rack }) => ({ types: [type], rack })),
|
|
172
202
|
]);
|
|
173
|
-
export type
|
|
203
|
+
export type RetrieveSingleParams = z.input<typeof singleRetrieveArgsZ>;
|
|
174
204
|
|
|
175
205
|
const multiRetrieveArgsZ = retrieveReqZ;
|
|
176
|
-
export type
|
|
206
|
+
export type RetrieveMultipleParams = z.input<typeof multiRetrieveArgsZ>;
|
|
177
207
|
|
|
178
208
|
const retrieveArgsZ = z.union([singleRetrieveArgsZ, multiRetrieveArgsZ]);
|
|
179
209
|
export type RetrieveArgs = z.input<typeof retrieveArgsZ>;
|
|
@@ -194,7 +224,7 @@ const retrieveResZ = <
|
|
|
194
224
|
schemas?: Schemas<Type, Config, StatusData>,
|
|
195
225
|
) =>
|
|
196
226
|
z.object({
|
|
197
|
-
tasks:
|
|
227
|
+
tasks: array.nullableZ(taskZ(schemas)),
|
|
198
228
|
});
|
|
199
229
|
|
|
200
230
|
export interface RetrieveRequest extends z.infer<typeof retrieveReqZ> {}
|
|
@@ -309,17 +339,17 @@ export class Client {
|
|
|
309
339
|
Config extends z.ZodType,
|
|
310
340
|
StatusData extends z.ZodType,
|
|
311
341
|
>(
|
|
312
|
-
args:
|
|
342
|
+
args: RetrieveSingleParams & RetrieveSchemas<Type, Config, StatusData>,
|
|
313
343
|
): Promise<Task<Type, Config, StatusData>>;
|
|
314
|
-
async retrieve(args:
|
|
344
|
+
async retrieve(args: RetrieveSingleParams): Promise<Task>;
|
|
315
345
|
async retrieve<
|
|
316
346
|
Type extends z.ZodLiteral<string>,
|
|
317
347
|
Config extends z.ZodType,
|
|
318
348
|
StatusData extends z.ZodType,
|
|
319
349
|
>(
|
|
320
|
-
args:
|
|
350
|
+
args: RetrieveMultipleParams & RetrieveSchemas<Type, Config, StatusData>,
|
|
321
351
|
): Promise<Task<Type, Config, StatusData>[]>;
|
|
322
|
-
async retrieve(args:
|
|
352
|
+
async retrieve(args: RetrieveMultipleParams): Promise<Task[]>;
|
|
323
353
|
async retrieve<
|
|
324
354
|
Type extends z.ZodLiteral<string>,
|
|
325
355
|
Config extends z.ZodType,
|
|
@@ -330,7 +360,7 @@ export class Client {
|
|
|
330
360
|
}: RetrieveArgs & RetrieveSchemas<Type, Config, StatusData>): Promise<
|
|
331
361
|
Task<Type, Config, StatusData> | Task<Type, Config, StatusData>[]
|
|
332
362
|
> {
|
|
333
|
-
const isSingle =
|
|
363
|
+
const isSingle = singleRetrieveArgsZ.safeParse(args).success;
|
|
334
364
|
const res = await sendRequired(
|
|
335
365
|
this.client,
|
|
336
366
|
RETRIEVE_ENDPOINT,
|
|
@@ -409,79 +439,72 @@ export class Client {
|
|
|
409
439
|
return isSingle ? res[0] : res;
|
|
410
440
|
}
|
|
411
441
|
|
|
412
|
-
async executeCommand(
|
|
442
|
+
async executeCommand(params: ExecuteCommandParams): Promise<string>;
|
|
413
443
|
|
|
414
|
-
async executeCommand(
|
|
444
|
+
async executeCommand(params: ExecuteCommandsParams): Promise<string[]>;
|
|
415
445
|
|
|
416
446
|
async executeCommand(
|
|
417
|
-
|
|
418
|
-
type?: string,
|
|
419
|
-
args?: {},
|
|
447
|
+
params: ExecuteCommandParams | ExecuteCommandsParams,
|
|
420
448
|
): Promise<string | string[]> {
|
|
421
|
-
if (
|
|
422
|
-
|
|
423
|
-
return await executeCommand(this.frameClient
|
|
449
|
+
if ("commands" in params)
|
|
450
|
+
return await executeCommands({ ...params, frameClient: this.frameClient });
|
|
451
|
+
return await executeCommand({ ...params, frameClient: this.frameClient });
|
|
424
452
|
}
|
|
425
453
|
|
|
426
454
|
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,
|
|
455
|
+
parms: ExecuteCommandsSyncParams<StatusData>,
|
|
438
456
|
): Promise<Status<StatusData>[]>;
|
|
439
457
|
|
|
440
458
|
async executeCommandSync<StatusData extends z.ZodType = z.ZodType>(
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
459
|
+
parms: ExecuteCommandSyncParams<StatusData>,
|
|
460
|
+
): Promise<Status<StatusData>>;
|
|
461
|
+
|
|
462
|
+
async executeCommandSync<StatusData extends z.ZodType = z.ZodType>(
|
|
463
|
+
params:
|
|
464
|
+
| ExecuteCommandsSyncParams<StatusData>
|
|
465
|
+
| ExecuteCommandSyncParams<StatusData>,
|
|
447
466
|
): Promise<Status<StatusData> | Status<StatusData>[]> {
|
|
448
|
-
if (
|
|
467
|
+
if ("commands" in params) {
|
|
449
468
|
const retrieveNames = async () => {
|
|
450
|
-
const
|
|
469
|
+
const { commands } = params;
|
|
470
|
+
const ts = await this.retrieve({ keys: commands.map((t) => t.task) });
|
|
451
471
|
return ts.map((t) => t.name);
|
|
452
472
|
};
|
|
453
|
-
return await executeCommandsSync(
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
retrieveNames,
|
|
459
|
-
);
|
|
473
|
+
return await executeCommandsSync({
|
|
474
|
+
...params,
|
|
475
|
+
frameClient: this.frameClient,
|
|
476
|
+
name: retrieveNames,
|
|
477
|
+
});
|
|
460
478
|
}
|
|
461
479
|
const retrieveName = async () => {
|
|
480
|
+
const { task } = params;
|
|
462
481
|
const t = await this.retrieve({ key: task });
|
|
463
482
|
return t.name;
|
|
464
483
|
};
|
|
465
|
-
return await executeCommandSync(
|
|
466
|
-
this.frameClient,
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
name ?? retrieveName,
|
|
471
|
-
statusDataZ,
|
|
472
|
-
args,
|
|
473
|
-
);
|
|
484
|
+
return await executeCommandSync({
|
|
485
|
+
frameClient: this.frameClient,
|
|
486
|
+
name: retrieveName,
|
|
487
|
+
...params,
|
|
488
|
+
});
|
|
474
489
|
}
|
|
475
490
|
}
|
|
476
491
|
|
|
477
492
|
export const ontologyID = (key: Key): ontology.ID => ({ type: "task", key });
|
|
478
493
|
|
|
479
|
-
|
|
480
|
-
frameClient: framer.Client | null
|
|
481
|
-
task: Key
|
|
482
|
-
type: string
|
|
483
|
-
args?: {}
|
|
484
|
-
|
|
494
|
+
interface ExecuteCommandInternalParams {
|
|
495
|
+
frameClient: framer.Client | null;
|
|
496
|
+
task: Key;
|
|
497
|
+
type: string;
|
|
498
|
+
args?: {};
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
const executeCommand = async ({
|
|
502
|
+
frameClient,
|
|
503
|
+
task,
|
|
504
|
+
type,
|
|
505
|
+
args,
|
|
506
|
+
}: ExecuteCommandInternalParams): Promise<string> =>
|
|
507
|
+
(await executeCommands({ frameClient, commands: [{ args, task, type }] }))[0];
|
|
485
508
|
|
|
486
509
|
export interface NewCommand {
|
|
487
510
|
task: Key;
|
|
@@ -489,10 +512,15 @@ export interface NewCommand {
|
|
|
489
512
|
args?: {};
|
|
490
513
|
}
|
|
491
514
|
|
|
492
|
-
|
|
493
|
-
frameClient: framer.Client | null
|
|
494
|
-
commands: NewCommand[]
|
|
495
|
-
|
|
515
|
+
interface ExecuteCommandsInternalParams {
|
|
516
|
+
frameClient: framer.Client | null;
|
|
517
|
+
commands: NewCommand[];
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
const executeCommands = async ({
|
|
521
|
+
frameClient,
|
|
522
|
+
commands,
|
|
523
|
+
}: ExecuteCommandsInternalParams): Promise<string[]> => {
|
|
496
524
|
if (frameClient == null) throw NOT_CREATED_ERROR;
|
|
497
525
|
const w = await frameClient.openWriter(COMMAND_CHANNEL_NAME);
|
|
498
526
|
const cmds = commands.map((c) => ({ ...c, key: id.create() }));
|
|
@@ -501,35 +529,49 @@ const executeCommands = async (
|
|
|
501
529
|
return cmds.map((c) => c.key);
|
|
502
530
|
};
|
|
503
531
|
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
532
|
+
interface ExecuteCommandSyncInternalParams<StatusData extends z.ZodType = z.ZodType>
|
|
533
|
+
extends Omit<ExecuteCommandsSyncInternalParams<StatusData>, "commands">,
|
|
534
|
+
TaskExecuteCommandSyncParams {
|
|
535
|
+
task: Key;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
const executeCommandSync = async <StatusData extends z.ZodType = z.ZodType>({
|
|
539
|
+
frameClient,
|
|
540
|
+
task,
|
|
541
|
+
type,
|
|
542
|
+
timeout,
|
|
543
|
+
name: taskName,
|
|
544
|
+
statusDataZ,
|
|
545
|
+
args,
|
|
546
|
+
}: ExecuteCommandSyncInternalParams<StatusData>): Promise<Status<StatusData>> =>
|
|
513
547
|
(
|
|
514
|
-
await executeCommandsSync(
|
|
548
|
+
await executeCommandsSync({
|
|
515
549
|
frameClient,
|
|
516
|
-
[{ args, task, type }],
|
|
550
|
+
commands: [{ args, task, type }],
|
|
517
551
|
timeout,
|
|
518
552
|
statusDataZ,
|
|
519
|
-
|
|
520
|
-
)
|
|
553
|
+
name: taskName,
|
|
554
|
+
})
|
|
521
555
|
)[0];
|
|
522
556
|
|
|
523
|
-
|
|
524
|
-
frameClient: framer.Client | null
|
|
525
|
-
commands: NewCommand[]
|
|
526
|
-
timeout
|
|
527
|
-
statusDataZ: StatusData
|
|
528
|
-
|
|
529
|
-
|
|
557
|
+
interface ExecuteCommandsSyncInternalParams<StatusData extends z.ZodType = z.ZodType> {
|
|
558
|
+
frameClient: framer.Client | null;
|
|
559
|
+
commands: NewCommand[];
|
|
560
|
+
timeout?: CrudeTimeSpan;
|
|
561
|
+
statusDataZ: StatusData;
|
|
562
|
+
name: string | string[] | (() => Promise<string | string[]>);
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
const executeCommandsSync = async <StatusData extends z.ZodType = z.ZodType>({
|
|
566
|
+
frameClient,
|
|
567
|
+
commands,
|
|
568
|
+
timeout = TimeSpan.seconds(10),
|
|
569
|
+
statusDataZ,
|
|
570
|
+
name: taskName,
|
|
571
|
+
}: ExecuteCommandsSyncInternalParams<StatusData>): Promise<Status<StatusData>[]> => {
|
|
530
572
|
if (frameClient == null) throw NOT_CREATED_ERROR;
|
|
531
573
|
const streamer = await frameClient.openStreamer(STATUS_CHANNEL_NAME);
|
|
532
|
-
const cmdKeys = await executeCommands(frameClient, commands);
|
|
574
|
+
const cmdKeys = await executeCommands({ frameClient, commands });
|
|
533
575
|
const parsedTimeout = new TimeSpan(timeout);
|
|
534
576
|
let states: Status<StatusData>[] = [];
|
|
535
577
|
let timeoutID: NodeJS.Timeout | undefined;
|
|
@@ -537,7 +579,7 @@ const executeCommandsSync = async <StatusData extends z.ZodType = z.ZodType>(
|
|
|
537
579
|
timeoutID = setTimeout(() => {
|
|
538
580
|
void (async () => {
|
|
539
581
|
const taskKeys = commands.map((c) => c.task);
|
|
540
|
-
reject(await formatTimeoutError("command",
|
|
582
|
+
reject(await formatTimeoutError("command", taskName, parsedTimeout, taskKeys));
|
|
541
583
|
})();
|
|
542
584
|
}, parsedTimeout.milliseconds);
|
|
543
585
|
});
|
|
@@ -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<
|