@synnaxlabs/client 0.45.0 → 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.
Files changed (164) hide show
  1. package/.turbo/turbo-build.log +7 -7
  2. package/dist/access/policy/client.d.ts +38 -26
  3. package/dist/access/policy/client.d.ts.map +1 -1
  4. package/dist/access/policy/payload.d.ts +22 -10
  5. package/dist/access/policy/payload.d.ts.map +1 -1
  6. package/dist/arc/client.d.ts +72 -0
  7. package/dist/arc/client.d.ts.map +1 -0
  8. package/dist/arc/external.d.ts +3 -0
  9. package/dist/arc/external.d.ts.map +1 -0
  10. package/dist/arc/index.d.ts +2 -0
  11. package/dist/arc/index.d.ts.map +1 -0
  12. package/dist/arc/payload.d.ts +155 -0
  13. package/dist/arc/payload.d.ts.map +1 -0
  14. package/dist/channel/client.d.ts +2 -3
  15. package/dist/channel/client.d.ts.map +1 -1
  16. package/dist/channel/payload.d.ts +23 -63
  17. package/dist/channel/payload.d.ts.map +1 -1
  18. package/dist/channel/retriever.d.ts.map +1 -1
  19. package/dist/client.cjs +44 -25
  20. package/dist/client.d.ts +5 -1
  21. package/dist/client.d.ts.map +1 -1
  22. package/dist/client.js +7548 -4837
  23. package/dist/framer/client.d.ts +2 -2
  24. package/dist/framer/client.d.ts.map +1 -1
  25. package/dist/framer/deleter.d.ts +2 -2
  26. package/dist/framer/frame.d.ts +2 -2
  27. package/dist/framer/streamer.d.ts +42 -56
  28. package/dist/framer/streamer.d.ts.map +1 -1
  29. package/dist/framer/writer.d.ts +45 -43
  30. package/dist/framer/writer.d.ts.map +1 -1
  31. package/dist/hardware/device/client.d.ts +5 -6
  32. package/dist/hardware/device/client.d.ts.map +1 -1
  33. package/dist/hardware/device/payload.d.ts +83 -18
  34. package/dist/hardware/device/payload.d.ts.map +1 -1
  35. package/dist/hardware/rack/client.d.ts +4 -5
  36. package/dist/hardware/rack/client.d.ts.map +1 -1
  37. package/dist/hardware/rack/payload.d.ts +81 -17
  38. package/dist/hardware/rack/payload.d.ts.map +1 -1
  39. package/dist/hardware/task/client.d.ts +61 -12
  40. package/dist/hardware/task/client.d.ts.map +1 -1
  41. package/dist/hardware/task/payload.d.ts +18 -51
  42. package/dist/hardware/task/payload.d.ts.map +1 -1
  43. package/dist/index.d.ts +3 -1
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/label/client.d.ts +14 -9
  46. package/dist/label/client.d.ts.map +1 -1
  47. package/dist/label/payload.d.ts +10 -11
  48. package/dist/label/payload.d.ts.map +1 -1
  49. package/dist/ontology/client.d.ts +7 -3
  50. package/dist/ontology/client.d.ts.map +1 -1
  51. package/dist/ontology/group/client.d.ts +45 -9
  52. package/dist/ontology/group/client.d.ts.map +1 -1
  53. package/dist/ontology/group/external.d.ts +0 -1
  54. package/dist/ontology/group/external.d.ts.map +1 -1
  55. package/dist/ontology/group/payload.d.ts +3 -1
  56. package/dist/ontology/group/payload.d.ts.map +1 -1
  57. package/dist/ontology/payload.d.ts +30 -17
  58. package/dist/ontology/payload.d.ts.map +1 -1
  59. package/dist/ontology/writer.d.ts +161 -0
  60. package/dist/ontology/writer.d.ts.map +1 -1
  61. package/dist/ranger/alias.d.ts +1 -1
  62. package/dist/ranger/alias.d.ts.map +1 -1
  63. package/dist/ranger/client.d.ts +9 -8
  64. package/dist/ranger/client.d.ts.map +1 -1
  65. package/dist/ranger/kv.d.ts.map +1 -1
  66. package/dist/ranger/payload.d.ts +5 -5
  67. package/dist/ranger/payload.d.ts.map +1 -1
  68. package/dist/ranger/writer.d.ts +6 -4
  69. package/dist/ranger/writer.d.ts.map +1 -1
  70. package/dist/status/client.d.ts +63 -0
  71. package/dist/status/client.d.ts.map +1 -0
  72. package/dist/status/external.d.ts +3 -0
  73. package/dist/status/external.d.ts.map +1 -0
  74. package/dist/status/index.d.ts +2 -0
  75. package/dist/status/index.d.ts.map +1 -0
  76. package/dist/status/payload.d.ts +32 -0
  77. package/dist/status/payload.d.ts.map +1 -0
  78. package/dist/status/status.spec.d.ts +2 -0
  79. package/dist/status/status.spec.d.ts.map +1 -0
  80. package/dist/user/client.d.ts.map +1 -1
  81. package/dist/user/retriever.d.ts.map +1 -1
  82. package/dist/workspace/client.d.ts +11 -6
  83. package/dist/workspace/client.d.ts.map +1 -1
  84. package/dist/workspace/lineplot/client.d.ts +28 -5
  85. package/dist/workspace/lineplot/client.d.ts.map +1 -1
  86. package/dist/workspace/lineplot/index.d.ts +1 -1
  87. package/dist/workspace/log/client.d.ts +28 -5
  88. package/dist/workspace/log/client.d.ts.map +1 -1
  89. package/dist/workspace/schematic/client.d.ts +35 -6
  90. package/dist/workspace/schematic/client.d.ts.map +1 -1
  91. package/dist/workspace/schematic/symbol/client.d.ts +6 -7
  92. package/dist/workspace/schematic/symbol/client.d.ts.map +1 -1
  93. package/dist/workspace/table/client.d.ts +28 -5
  94. package/dist/workspace/table/client.d.ts.map +1 -1
  95. package/examples/node/package-lock.json +30 -95
  96. package/examples/node/package.json +1 -1
  97. package/package.json +8 -8
  98. package/src/access/policy/client.ts +5 -6
  99. package/src/access/policy/payload.ts +4 -4
  100. package/src/access/policy/policy.spec.ts +4 -4
  101. package/src/arc/client.ts +117 -0
  102. package/src/{util/zod.ts → arc/external.ts} +2 -7
  103. package/src/arc/index.ts +10 -0
  104. package/src/arc/payload.ts +69 -0
  105. package/src/channel/client.ts +3 -4
  106. package/src/channel/payload.ts +4 -6
  107. package/src/channel/retriever.ts +2 -2
  108. package/src/client.ts +8 -2
  109. package/src/errors.spec.ts +1 -1
  110. package/src/framer/client.ts +4 -3
  111. package/src/framer/codec.spec.ts +1 -1
  112. package/src/hardware/device/client.ts +6 -8
  113. package/src/hardware/device/payload.ts +7 -6
  114. package/src/hardware/rack/client.ts +6 -8
  115. package/src/hardware/rack/payload.ts +2 -1
  116. package/src/hardware/task/client.ts +140 -100
  117. package/src/hardware/task/payload.ts +4 -4
  118. package/src/hardware/task/task.spec.ts +9 -2
  119. package/src/index.ts +3 -1
  120. package/src/label/client.ts +5 -8
  121. package/src/label/payload.ts +6 -11
  122. package/src/ontology/client.ts +3 -3
  123. package/src/ontology/group/client.ts +51 -18
  124. package/src/ontology/group/external.ts +0 -1
  125. package/src/ontology/group/group.spec.ts +6 -5
  126. package/src/ontology/group/payload.ts +5 -1
  127. package/src/ontology/ontology.spec.ts +88 -21
  128. package/src/ontology/payload.ts +15 -6
  129. package/src/ontology/writer.ts +3 -5
  130. package/src/ranger/alias.ts +2 -2
  131. package/src/ranger/client.ts +7 -3
  132. package/src/ranger/kv.ts +1 -2
  133. package/src/ranger/payload.ts +13 -1
  134. package/src/ranger/ranger.spec.ts +65 -1
  135. package/src/status/client.ts +129 -0
  136. package/src/status/external.ts +11 -0
  137. package/src/status/index.ts +10 -0
  138. package/src/status/payload.ts +35 -0
  139. package/src/status/status.spec.ts +352 -0
  140. package/src/user/client.ts +1 -2
  141. package/src/user/payload.ts +1 -1
  142. package/src/user/retriever.ts +2 -2
  143. package/src/user/user.spec.ts +41 -41
  144. package/src/workspace/client.ts +18 -15
  145. package/src/workspace/lineplot/client.ts +27 -13
  146. package/src/workspace/lineplot/index.ts +1 -1
  147. package/src/workspace/lineplot/lineplot.spec.ts +13 -10
  148. package/src/workspace/log/client.ts +26 -12
  149. package/src/workspace/log/log.spec.ts +13 -10
  150. package/src/workspace/payload.ts +1 -1
  151. package/src/workspace/schematic/client.ts +42 -17
  152. package/src/workspace/schematic/schematic.spec.ts +29 -25
  153. package/src/workspace/schematic/symbol/client.spec.ts +27 -24
  154. package/src/workspace/schematic/symbol/client.ts +6 -9
  155. package/src/workspace/table/client.ts +26 -12
  156. package/src/workspace/table/table.spec.ts +13 -10
  157. package/dist/ontology/group/group.d.ts +0 -10
  158. package/dist/ontology/group/group.d.ts.map +0 -1
  159. package/dist/ontology/group/writer.d.ts +0 -14
  160. package/dist/ontology/group/writer.d.ts.map +0 -1
  161. package/dist/util/zod.d.ts +0 -3
  162. package/dist/util/zod.d.ts.map +0 -1
  163. package/src/ontology/group/group.ts +0 -27
  164. 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 user: user.Client;
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.user = new user.Client(this.transport.unary);
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 {
@@ -64,7 +64,7 @@ test("client", async () => {
64
64
  expect(NotFoundError.matches(e)).toBe(true);
65
65
  }
66
66
  try {
67
- await client.workspaces.schematic.retrieve(uuid.create());
67
+ await client.workspaces.schematics.retrieve({ key: uuid.create() });
68
68
  } catch (e) {
69
69
  expect(NotFoundError.matches(e)).toBe(true);
70
70
  }
@@ -199,16 +199,17 @@ export class Client {
199
199
  return frame;
200
200
  }
201
201
 
202
- async delete(channels: channel.Params, timeRange: TimeRange): Promise<void> {
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: timeRange,
208
+ bounds,
208
209
  });
209
210
  return await this.deleter.delete({
210
211
  names: normalized as string[],
211
- bounds: timeRange,
212
+ bounds,
212
213
  });
213
214
  }
214
215
  }
@@ -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: nullableArrayZ(deviceZ) });
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 SingleRetrieveArgs = z.input<typeof singleRetrieveArgsZ>;
66
- export type MultiRetrieveArgs = z.input<typeof retrieveRequestZ>;
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: SingleRetrieveArgs): Promise<Device<Properties, Make, Model>>;
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: MultiRetrieveArgs): Promise<Array<Device<Properties, Make, Model>>>;
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: string | string[]): Promise<void> {
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 statusZ = status.statusZ(z.object({ rack: rackKeyZ, device: keyZ }));
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/array";
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: nullableArrayZ(rackZ) });
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 SingleRetrieveArgs = z.input<typeof singleRetrieveArgsZ>;
61
+ export type RetrieveSingleParams = z.input<typeof singleRetrieveArgsZ>;
63
62
 
64
63
  const multiRetrieveArgsZ = retrieveReqZ;
65
64
 
66
- export type MultiRetrieveArgs = z.input<typeof multiRetrieveArgsZ>;
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: SingleRetrieveArgs): Promise<Rack>;
114
- async retrieve(args: MultiRetrieveArgs): Promise<Rack[]>;
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 statusZ = status.statusZ(z.object({ rack: keyZ }));
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(type: string, args?: {}): Promise<string> {
128
- return await executeCommand(this.frameClient, this.key, type, args);
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
- type: string,
133
- timeout: CrudeTimeSpan,
134
- args?: {},
157
+ params: TaskExecuteCommandSyncParams,
135
158
  ): Promise<Status<StatusData>> {
136
- return await executeCommandSync<StatusData>(
137
- this.frameClient,
138
- this.key,
139
- type,
140
- timeout,
141
- this.name,
142
- this.schemas?.statusDataSchema,
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 SingleRetrieveArgs = z.input<typeof singleRetrieveArgsZ>;
201
+ export type RetrieveSingleParams = z.input<typeof singleRetrieveArgsZ>;
174
202
 
175
203
  const multiRetrieveArgsZ = retrieveReqZ;
176
- export type MultiRetrieveArgs = z.input<typeof multiRetrieveArgsZ>;
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: nullableArrayZ(taskZ(schemas)),
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: SingleRetrieveArgs & RetrieveSchemas<Type, Config, StatusData>,
340
+ args: RetrieveSingleParams & RetrieveSchemas<Type, Config, StatusData>,
313
341
  ): Promise<Task<Type, Config, StatusData>>;
314
- async retrieve(args: SingleRetrieveArgs): Promise<Task>;
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: MultiRetrieveArgs & RetrieveSchemas<Type, Config, StatusData>,
348
+ args: RetrieveMultipleParams & RetrieveSchemas<Type, Config, StatusData>,
321
349
  ): Promise<Task<Type, Config, StatusData>[]>;
322
- async retrieve(args: MultiRetrieveArgs): Promise<Task[]>;
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 = "key" in args || "name" in args;
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(task: Key, type: string, args?: {}): Promise<string>;
440
+ async executeCommand(params: ExecuteCommandParams): Promise<string>;
413
441
 
414
- async executeCommand(commands: NewCommand[]): Promise<string[]>;
442
+ async executeCommand(params: ExecuteCommandsParams): Promise<string[]>;
415
443
 
416
444
  async executeCommand(
417
- task: Key | NewCommand[],
418
- type?: string,
419
- args?: {},
445
+ params: ExecuteCommandParams | ExecuteCommandsParams,
420
446
  ): Promise<string | string[]> {
421
- if (Array.isArray(task)) return await executeCommands(this.frameClient, task);
422
- if (type == null) throw new Error("Type is required");
423
- return await executeCommand(this.frameClient, task, type, args);
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
- task: Key,
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
- task: Key | NewCommand[],
442
- type: string | CrudeTimeSpan,
443
- timeout?: CrudeTimeSpan | StatusData,
444
- args?: {},
445
- name?: string,
446
- statusDataZ: StatusData = z.unknown() as unknown as StatusData,
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 (Array.isArray(task)) {
465
+ if ("commands" in params) {
449
466
  const retrieveNames = async () => {
450
- const ts = await this.retrieve({ keys: task.map((t) => t.task) });
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
- this.frameClient,
455
- task,
456
- type as CrudeTimeSpan,
457
- statusDataZ,
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
- task,
468
- type as string,
469
- timeout as CrudeTimeSpan,
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
- const executeCommand = async (
480
- frameClient: framer.Client | null,
481
- task: Key,
482
- type: string,
483
- args?: {},
484
- ): Promise<string> => (await executeCommands(frameClient, [{ args, task, type }]))[0];
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
- const executeCommands = async (
493
- frameClient: framer.Client | null,
494
- commands: NewCommand[],
495
- ): Promise<string[]> => {
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
- const executeCommandSync = async <StatusData extends z.ZodType = z.ZodType>(
505
- frameClient: framer.Client | null,
506
- task: Key,
507
- type: string,
508
- timeout: CrudeTimeSpan,
509
- tskName: string | (() => Promise<string>),
510
- statusDataZ: StatusData,
511
- args?: {},
512
- ): Promise<Status<StatusData>> =>
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
- tskName,
520
- )
551
+ name: taskName,
552
+ })
521
553
  )[0];
522
554
 
523
- const executeCommandsSync = async <StatusData extends z.ZodType = z.ZodType>(
524
- frameClient: framer.Client | null,
525
- commands: NewCommand[],
526
- timeout: CrudeTimeSpan,
527
- statusDataZ: StatusData,
528
- tskName: string | string[] | (() => Promise<string | string[]>),
529
- ): Promise<Status<StatusData>[]> => {
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", tskName, parsedTimeout, taskKeys));
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 = <D extends z.ZodType>(data: D) =>
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<D extends z.ZodType> = z.infer<
28
- ReturnType<typeof statusDetailsZ<D>>
27
+ export type StatusDetails<DataSchema extends z.ZodType> = z.infer<
28
+ ReturnType<typeof statusDetailsZ<DataSchema>>
29
29
  >;
30
30
 
31
- export const statusZ = <D extends z.ZodType>(data: D) =>
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<