@synnaxlabs/client 0.24.0 → 0.26.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 (160) hide show
  1. package/.turbo/turbo-build.log +9 -10
  2. package/dist/access/access.spec.d.ts +2 -0
  3. package/dist/access/access.spec.d.ts.map +1 -0
  4. package/dist/access/client.d.ts +13 -0
  5. package/dist/access/client.d.ts.map +1 -0
  6. package/dist/access/external.d.ts +3 -0
  7. package/dist/access/external.d.ts.map +1 -0
  8. package/dist/access/index.d.ts +2 -0
  9. package/dist/access/index.d.ts.map +1 -0
  10. package/dist/access/payload.d.ts +105 -0
  11. package/dist/access/payload.d.ts.map +1 -0
  12. package/dist/auth/auth.d.ts +2 -2
  13. package/dist/auth/auth.d.ts.map +1 -1
  14. package/dist/channel/client.d.ts +8 -8
  15. package/dist/channel/creator.d.ts +1 -1
  16. package/dist/channel/payload.d.ts +18 -15
  17. package/dist/channel/payload.d.ts.map +1 -1
  18. package/dist/channel/retriever.d.ts +11 -11
  19. package/dist/channel/retriever.d.ts.map +1 -1
  20. package/dist/channel/writer.d.ts +3 -3
  21. package/dist/client.cjs +22 -22
  22. package/dist/client.d.ts +15 -11
  23. package/dist/client.d.ts.map +1 -1
  24. package/dist/client.js +3124 -3776
  25. package/dist/connection/checker.d.ts +2 -2
  26. package/dist/control/client.d.ts +1 -1
  27. package/dist/control/state.d.ts +6 -6
  28. package/dist/control/state.d.ts.map +1 -1
  29. package/dist/errors.d.ts +12 -12
  30. package/dist/errors.d.ts.map +1 -1
  31. package/dist/framer/adapter.d.ts +3 -3
  32. package/dist/framer/client.d.ts +7 -7
  33. package/dist/framer/client.d.ts.map +1 -1
  34. package/dist/framer/deleter.d.ts +3 -3
  35. package/dist/framer/deleter.d.ts.map +1 -1
  36. package/dist/framer/frame.d.ts +2 -2
  37. package/dist/framer/iterator.d.ts +4 -4
  38. package/dist/framer/streamProxy.d.ts +1 -1
  39. package/dist/framer/streamer.d.ts +5 -5
  40. package/dist/framer/writer.d.ts +6 -6
  41. package/dist/hardware/client.d.ts +2 -2
  42. package/dist/hardware/device/client.d.ts +6 -71
  43. package/dist/hardware/device/client.d.ts.map +1 -1
  44. package/dist/hardware/device/external.d.ts +1 -0
  45. package/dist/hardware/device/external.d.ts.map +1 -1
  46. package/dist/hardware/device/index.d.ts +1 -1
  47. package/dist/hardware/device/index.d.ts.map +1 -1
  48. package/dist/hardware/device/payload.d.ts +73 -0
  49. package/dist/hardware/device/payload.d.ts.map +1 -0
  50. package/dist/hardware/rack/client.d.ts +6 -29
  51. package/dist/hardware/rack/client.d.ts.map +1 -1
  52. package/dist/hardware/rack/external.d.ts +1 -0
  53. package/dist/hardware/rack/external.d.ts.map +1 -1
  54. package/dist/hardware/rack/payload.d.ts +30 -0
  55. package/dist/hardware/rack/payload.d.ts.map +1 -0
  56. package/dist/hardware/task/client.d.ts +7 -151
  57. package/dist/hardware/task/client.d.ts.map +1 -1
  58. package/dist/hardware/task/external.d.ts +3 -0
  59. package/dist/hardware/task/external.d.ts.map +1 -0
  60. package/dist/hardware/task/index.d.ts +1 -1
  61. package/dist/hardware/task/index.d.ts.map +1 -1
  62. package/dist/hardware/task/payload.d.ts +151 -0
  63. package/dist/hardware/task/payload.d.ts.map +1 -0
  64. package/dist/index.d.ts +1 -2
  65. package/dist/index.d.ts.map +1 -1
  66. package/dist/label/client.d.ts +6 -6
  67. package/dist/label/payload.d.ts +2 -1
  68. package/dist/label/payload.d.ts.map +1 -1
  69. package/dist/label/retriever.d.ts +2 -2
  70. package/dist/label/writer.d.ts +3 -3
  71. package/dist/ontology/client.d.ts +11 -11
  72. package/dist/ontology/group/client.d.ts +2 -2
  73. package/dist/ontology/group/writer.d.ts +2 -2
  74. package/dist/ontology/group/writer.d.ts.map +1 -1
  75. package/dist/ontology/payload.d.ts +47 -44
  76. package/dist/ontology/payload.d.ts.map +1 -1
  77. package/dist/ontology/writer.d.ts +1 -1
  78. package/dist/ranger/active.d.ts +1 -1
  79. package/dist/ranger/alias.d.ts +6 -6
  80. package/dist/ranger/client.d.ts +10 -10
  81. package/dist/ranger/kv.d.ts +2 -2
  82. package/dist/ranger/payload.d.ts +6 -1
  83. package/dist/ranger/payload.d.ts.map +1 -1
  84. package/dist/ranger/range.d.ts +8 -8
  85. package/dist/ranger/range.d.ts.map +1 -1
  86. package/dist/ranger/writer.d.ts +1 -1
  87. package/dist/setupspecs.d.ts.map +1 -1
  88. package/dist/signals/observable.d.ts +5 -5
  89. package/dist/signals/observable.d.ts.map +1 -1
  90. package/dist/transport.d.ts +1 -1
  91. package/dist/user/client.d.ts +9 -0
  92. package/dist/user/client.d.ts.map +1 -0
  93. package/dist/user/external.d.ts +3 -0
  94. package/dist/user/external.d.ts.map +1 -0
  95. package/dist/user/index.d.ts +1 -1
  96. package/dist/user/index.d.ts.map +1 -1
  97. package/dist/user/payload.d.ts +5 -0
  98. package/dist/user/payload.d.ts.map +1 -1
  99. package/dist/util/retrieve.d.ts +1 -1
  100. package/dist/util/retrieve.d.ts.map +1 -1
  101. package/dist/util/zod.d.ts.map +1 -1
  102. package/dist/workspace/client.d.ts +6 -6
  103. package/dist/workspace/lineplot/client.d.ts +3 -3
  104. package/dist/workspace/lineplot/payload.d.ts +4 -1
  105. package/dist/workspace/lineplot/payload.d.ts.map +1 -1
  106. package/dist/workspace/lineplot/retriever.d.ts +1 -1
  107. package/dist/workspace/lineplot/writer.d.ts +3 -3
  108. package/dist/workspace/payload.d.ts +4 -1
  109. package/dist/workspace/payload.d.ts.map +1 -1
  110. package/dist/workspace/retriever.d.ts +1 -1
  111. package/dist/workspace/schematic/client.d.ts +3 -3
  112. package/dist/workspace/schematic/payload.d.ts +4 -1
  113. package/dist/workspace/schematic/payload.d.ts.map +1 -1
  114. package/dist/workspace/schematic/retriever.d.ts +1 -1
  115. package/dist/workspace/schematic/writer.d.ts +3 -3
  116. package/dist/workspace/writer.d.ts +3 -3
  117. package/examples/node/package.json +1 -1
  118. package/package.json +11 -12
  119. package/src/access/access.spec.ts +276 -0
  120. package/src/access/client.ts +86 -0
  121. package/src/access/external.ts +11 -0
  122. package/src/access/index.ts +10 -0
  123. package/src/access/payload.ts +35 -0
  124. package/src/auth/auth.ts +1 -1
  125. package/src/channel/payload.ts +7 -0
  126. package/src/client.ts +7 -1
  127. package/src/control/state.ts +3 -3
  128. package/src/errors.spec.ts +0 -1
  129. package/src/framer/client.ts +1 -0
  130. package/src/framer/deleter.ts +2 -4
  131. package/src/framer/writer.spec.ts +29 -1
  132. package/src/hardware/device/client.ts +8 -36
  133. package/src/hardware/device/external.ts +1 -0
  134. package/src/hardware/device/index.ts +1 -1
  135. package/src/hardware/device/payload.ts +44 -0
  136. package/src/hardware/rack/client.ts +10 -15
  137. package/src/hardware/rack/external.ts +1 -0
  138. package/src/hardware/rack/payload.ts +23 -0
  139. package/src/hardware/task/client.ts +3 -86
  140. package/src/hardware/task/external.ts +11 -0
  141. package/src/hardware/task/index.ts +1 -1
  142. package/src/hardware/task/payload.ts +92 -0
  143. package/src/hardware/task/task.spec.ts +2 -2
  144. package/src/index.ts +1 -2
  145. package/src/label/payload.ts +3 -1
  146. package/src/ontology/group/writer.ts +1 -1
  147. package/src/ontology/ontology.spec.ts +1 -1
  148. package/src/ontology/payload.ts +6 -1
  149. package/src/ranger/payload.ts +11 -0
  150. package/src/setupspecs.ts +4 -2
  151. package/src/signals/observable.ts +5 -3
  152. package/src/transport.ts +3 -3
  153. package/src/user/client.ts +37 -0
  154. package/src/user/external.ts +11 -0
  155. package/src/user/index.ts +1 -1
  156. package/src/user/payload.ts +11 -0
  157. package/src/workspace/lineplot/payload.ts +7 -0
  158. package/src/workspace/payload.ts +7 -0
  159. package/src/workspace/schematic/payload.ts +7 -0
  160. package/tsconfig.json +4 -2
package/src/client.ts CHANGED
@@ -11,6 +11,7 @@ import { TimeSpan, TimeStamp } from "@synnaxlabs/x/telem";
11
11
  import { URL } from "@synnaxlabs/x/url";
12
12
  import { z } from "zod";
13
13
 
14
+ import { access } from "@/access";
14
15
  import { auth } from "@/auth";
15
16
  import { channel } from "@/channel";
16
17
  import { connection } from "@/connection";
@@ -25,6 +26,7 @@ import { label } from "@/label";
25
26
  import { ontology } from "@/ontology";
26
27
  import { ranger } from "@/ranger";
27
28
  import { Transport } from "@/transport";
29
+ import { user } from "@/user";
28
30
  import { workspace } from "@/workspace";
29
31
 
30
32
  export const synnaxPropsZ = z.object({
@@ -66,6 +68,8 @@ export default class Synnax extends framer.Client {
66
68
  readonly ranges: ranger.Client;
67
69
  readonly channels: channel.Client;
68
70
  readonly auth: auth.Client | undefined;
71
+ readonly user: user.Client;
72
+ readonly access: access.Client;
69
73
  readonly connectivity: connection.Checker;
70
74
  readonly ontology: ontology.Client;
71
75
  readonly workspaces: workspace.Client;
@@ -97,7 +101,7 @@ export default class Synnax extends framer.Client {
97
101
  transport.use(errorsMiddleware);
98
102
  let auth_: auth.Client | undefined;
99
103
  if (username != null && password != null) {
100
- const auth_ = new auth.Client(transport.unary, {
104
+ auth_ = new auth.Client(transport.unary, {
101
105
  username,
102
106
  password,
103
107
  });
@@ -129,6 +133,8 @@ export default class Synnax extends framer.Client {
129
133
  chRetriever,
130
134
  this.labels,
131
135
  );
136
+ this.access = new access.Client(this.transport.unary);
137
+ this.user = new user.Client(this.transport.unary);
132
138
  this.workspaces = new workspace.Client(this.transport.unary);
133
139
  const devices = new device.Client(this.transport.unary, this);
134
140
  const tasks = new task.Client(this.transport.unary, this);
@@ -43,16 +43,16 @@ export class StateTracker
43
43
  implements observe.ObservableAsyncCloseable<Transfer[]>
44
44
  {
45
45
  readonly states: Map<ChannelKey, State>;
46
- private readonly ecd: binary.EncoderDecoder;
46
+ private readonly codec: binary.Codec;
47
47
 
48
48
  constructor(streamer: FrameStreamer) {
49
49
  super(streamer, (frame) => {
50
- const update: Update = this.ecd.decode(frame.series[0].buffer);
50
+ const update: Update = this.codec.decode(frame.series[0].buffer);
51
51
  this.merge(update);
52
52
  return [update.transfers, true];
53
53
  });
54
54
  this.states = new Map();
55
- this.ecd = new binary.JSONEncoderDecoder();
55
+ this.codec = new binary.JSONCodec();
56
56
  }
57
57
 
58
58
  subjects(): Subject[] {
@@ -1,4 +1,3 @@
1
- import { BaseTypedError, TypedError } from "@synnaxlabs/freighter";
2
1
  import { MatchableErrorType } from "@synnaxlabs/freighter/src/errors";
3
2
  import { describe, expect, test } from "vitest";
4
3
 
@@ -15,6 +15,7 @@ import {
15
15
  type MultiSeries,
16
16
  TimeRange,
17
17
  TimeSpan,
18
+ toArray,
18
19
  } from "@synnaxlabs/x";
19
20
 
20
21
  import { type Key, type KeyOrName, KeysOrNames, type Params } from "@/channel/payload";
@@ -15,8 +15,8 @@ import { keyZ } from "@/channel/payload";
15
15
 
16
16
  const reqZ = z.object({
17
17
  keys: keyZ.array().optional(),
18
- names: z.string().array().optional(),
19
18
  bounds: TimeRange.z,
19
+ names: z.string().array().optional(),
20
20
  });
21
21
 
22
22
  type RequestProps = z.infer<typeof reqZ>;
@@ -31,9 +31,7 @@ export class Deleter {
31
31
  */
32
32
  private readonly client: UnaryClient;
33
33
 
34
- constructor(
35
- client: UnaryClient,
36
- ) {
34
+ constructor(client: UnaryClient) {
37
35
  this.client = client;
38
36
  }
39
37
 
@@ -117,7 +117,7 @@ describe("Writer", () => {
117
117
  test("write with errOnUnauthorized", async () => {
118
118
  const ch = await newChannel();
119
119
  const w1 = await client.openWriter({
120
- start: 0,
120
+ start: new TimeStamp(TimeSpan.milliseconds(500)),
121
121
  channels: ch.key,
122
122
  });
123
123
 
@@ -130,6 +130,34 @@ describe("Writer", () => {
130
130
  ).rejects.toThrow(UnauthorizedError);
131
131
  await w1.close();
132
132
  });
133
+ test("setAuthority", async () => {
134
+ const ch = await newChannel();
135
+ const w1 = await client.openWriter({
136
+ start: 0,
137
+ channels: ch.key,
138
+ authorities: 10,
139
+ enableAutoCommit: true,
140
+ })
141
+ const w2 = await client.openWriter({
142
+ start: 0,
143
+ channels: ch.key,
144
+ authorities: 20,
145
+ enableAutoCommit: true,
146
+ })
147
+
148
+ await w1.write(ch.key, randomSeries(10, ch.dataType))
149
+ let f = await ch.read(TimeRange.MAX)
150
+ expect(f.length).toEqual(0)
151
+
152
+ await w1.setAuthority({[ch.key]: 100});
153
+ await w1.write(ch.key, randomSeries(10, ch.dataType))
154
+
155
+ f = await ch.read(TimeRange.MAX)
156
+ expect(f.length).toEqual(10)
157
+
158
+ await w1.close()
159
+ await w2.close()
160
+ })
133
161
  });
134
162
  describe("Client", () => {
135
163
  test("Client - basic write", async () => {
@@ -9,12 +9,18 @@
9
9
 
10
10
  import { sendRequired, type UnaryClient } from "@synnaxlabs/freighter";
11
11
  import { toArray, type UnknownRecord } from "@synnaxlabs/x";
12
- import { binary } from "@synnaxlabs/x/binary";
13
12
  import { type AsyncTermSearcher } from "@synnaxlabs/x/search";
14
13
  import { z } from "zod";
15
14
 
16
15
  import { type framer } from "@/framer";
17
- import { rackKeyZ } from "@/hardware/rack/client";
16
+ import {
17
+ Device,
18
+ DeviceKey,
19
+ deviceKeyZ,
20
+ deviceZ,
21
+ NewDevice,
22
+ newDeviceZ,
23
+ } from "@/hardware/device/payload";
18
24
  import { signals } from "@/signals";
19
25
  import { checkForMultipleOrNoResults } from "@/util/retrieve";
20
26
  import { nullableArrayZ } from "@/util/zod";
@@ -26,40 +32,6 @@ const RETRIEVE_ENDPOINT = "/hardware/device/retrieve";
26
32
  const CREATE_ENDPOINT = "/hardware/device/create";
27
33
  const DELETE_ENDPOINT = "/hardware/device/delete";
28
34
 
29
- export const deviceKeyZ = z.string();
30
-
31
- export const deviceZ = z.object({
32
- key: deviceKeyZ,
33
- rack: rackKeyZ,
34
- name: z.string(),
35
- make: z.string(),
36
- model: z.string(),
37
- location: z.string(),
38
- configured: z.boolean().optional(),
39
- properties: z.record(z.unknown()).or(
40
- z.string().transform((c) => {
41
- if (c === "") return {};
42
- return binary.JSON_ECD.decodeString(c);
43
- }),
44
- ) as z.ZodType<UnknownRecord>,
45
- });
46
-
47
- export type Device<P extends UnknownRecord = UnknownRecord> = Omit<
48
- z.output<typeof deviceZ>,
49
- "properties"
50
- > & { properties: P };
51
-
52
- export type DeviceKey = z.infer<typeof deviceKeyZ>;
53
-
54
- export const newDeviceZ = deviceZ.extend({
55
- properties: z.unknown().transform((c) => binary.JSON_ECD.encodeString(c)),
56
- });
57
-
58
- export type NewDevice<P extends UnknownRecord = UnknownRecord> = Omit<
59
- z.input<typeof newDeviceZ>,
60
- "properties"
61
- > & { properties: P };
62
-
63
35
  const createReqZ = z.object({ devices: newDeviceZ.array() });
64
36
 
65
37
  const createResZ = z.object({ devices: deviceZ.array() });
@@ -8,3 +8,4 @@
8
8
  // included in the file licenses/APL.txt.
9
9
 
10
10
  export * from "@/hardware/device/client";
11
+ export * from "@/hardware/device/payload";
@@ -7,4 +7,4 @@
7
7
  // License, use of this software will be governed by the Apache License, Version 2.0,
8
8
  // included in the file licenses/APL.txt.
9
9
 
10
- export * as device from "@/hardware/device/client";
10
+ export * as device from "@/hardware/device/external";
@@ -0,0 +1,44 @@
1
+ import { binary, UnknownRecord } from "@synnaxlabs/x";
2
+ import { z } from "zod";
3
+
4
+ import { rackKeyZ } from "@/hardware/rack/payload";
5
+ import { ontology } from "@/ontology";
6
+
7
+ export const deviceKeyZ = z.string();
8
+
9
+ export const deviceZ = z.object({
10
+ key: deviceKeyZ,
11
+ rack: rackKeyZ,
12
+ name: z.string(),
13
+ make: z.string(),
14
+ model: z.string(),
15
+ location: z.string(),
16
+ configured: z.boolean().optional(),
17
+ properties: z.record(z.unknown()).or(
18
+ z.string().transform((c) => {
19
+ if (c === "") return {};
20
+ return binary.JSON_CODEC.decodeString(c);
21
+ }),
22
+ ) as z.ZodType<UnknownRecord>,
23
+ });
24
+
25
+ export type Device<P extends UnknownRecord = UnknownRecord> = Omit<
26
+ z.output<typeof deviceZ>,
27
+ "properties"
28
+ > & { properties: P };
29
+
30
+ export type DeviceKey = z.infer<typeof deviceKeyZ>;
31
+
32
+ export const newDeviceZ = deviceZ.extend({
33
+ properties: z.unknown().transform((c) => binary.JSON_CODEC.encodeString(c)),
34
+ });
35
+
36
+ export type NewDevice<P extends UnknownRecord = UnknownRecord> = Omit<
37
+ z.input<typeof newDeviceZ>,
38
+ "properties"
39
+ > & { properties: P };
40
+
41
+ export const DeviceOntologyType = "device" as ontology.ResourceType;
42
+
43
+ export const ontologyID = (key: DeviceKey): ontology.ID =>
44
+ new ontology.ID({ type: DeviceOntologyType, key: key.toString() });
@@ -14,25 +14,18 @@ import { toArray } from "@synnaxlabs/x/toArray";
14
14
  import { z } from "zod";
15
15
 
16
16
  import { type framer } from "@/framer";
17
+ import {
18
+ NewRack,
19
+ newRackZ,
20
+ RackKey,
21
+ rackKeyZ,
22
+ RackPayload,
23
+ rackZ,
24
+ } from "@/hardware/rack/payload";
17
25
  import { type task } from "@/hardware/task";
18
26
  import { analyzeParams, checkForMultipleOrNoResults } from "@/util/retrieve";
19
27
  import { nullableArrayZ } from "@/util/zod";
20
28
 
21
- export const rackKeyZ = z.number();
22
-
23
- export type RackKey = z.infer<typeof rackKeyZ>;
24
-
25
- export const rackZ = z.object({
26
- key: rackKeyZ,
27
- name: z.string(),
28
- });
29
-
30
- export type RackPayload = z.infer<typeof rackZ>;
31
-
32
- export const newRackZ = rackZ.partial({ key: true });
33
-
34
- export type NewRack = z.input<typeof newRackZ>;
35
-
36
29
  const RETRIEVE_ENDPOINT = "/hardware/rack/retrieve";
37
30
  const CREATE_RACK_ENDPOINT = "/hardware/rack/create";
38
31
  const DELETE_RACK_ENDPOINT = "/hardware/rack/delete";
@@ -192,3 +185,5 @@ export class Rack {
192
185
  await this.tasks.delete([task]);
193
186
  }
194
187
  }
188
+ export { rackKeyZ };
189
+
@@ -8,3 +8,4 @@
8
8
  // included in the file licenses/APL.txt.
9
9
 
10
10
  export * from "@/hardware/rack/client";
11
+ export * from "@/hardware/rack/payload";
@@ -0,0 +1,23 @@
1
+ import { z } from "zod";
2
+
3
+ import { ontology } from "@/ontology";
4
+
5
+ export const rackKeyZ = z.number();
6
+
7
+ export type RackKey = z.infer<typeof rackKeyZ>;
8
+
9
+ export const rackZ = z.object({
10
+ key: rackKeyZ,
11
+ name: z.string(),
12
+ });
13
+
14
+ export type RackPayload = z.infer<typeof rackZ>;
15
+
16
+ export const newRackZ = rackZ.partial({ key: true });
17
+
18
+ export type NewRack = z.input<typeof newRackZ>;
19
+
20
+ export const RackOntologyType = "rack" as ontology.ResourceType;
21
+
22
+ export const ontologyID = (key: RackKey): ontology.ID =>
23
+ new ontology.ID({ type: RackOntologyType, key: key.toString() });
@@ -8,17 +8,17 @@
8
8
  // included in the file licenses/APL.txt.
9
9
 
10
10
  import { sendRequired, type UnaryClient } from "@synnaxlabs/freighter";
11
- import { binary, type observe } from "@synnaxlabs/x";
11
+ import { id } from "@synnaxlabs/x";
12
12
  import { type UnknownRecord } from "@synnaxlabs/x/record";
13
13
  import { type AsyncTermSearcher } from "@synnaxlabs/x/search";
14
14
  import { type CrudeTimeSpan, TimeSpan } from "@synnaxlabs/x/telem";
15
15
  import { toArray } from "@synnaxlabs/x/toArray";
16
- import { nanoid } from "nanoid/non-secure";
17
16
  import { z } from "zod";
18
17
 
19
18
  import { framer } from "@/framer";
20
19
  import { type Frame } from "@/framer/frame";
21
20
  import { rack } from "@/hardware/rack";
21
+ import { NewTask, newTaskZ, Payload, State, StateObservable, stateZ, TaskKey, taskKeyZ, taskZ } from "@/hardware/task/payload";
22
22
  import { signals } from "@/signals";
23
23
  import { analyzeParams, checkForMultipleOrNoResults } from "@/util/retrieve";
24
24
  import { nullableArrayZ } from "@/util/zod";
@@ -26,89 +26,6 @@ import { nullableArrayZ } from "@/util/zod";
26
26
  const TASK_STATE_CHANNEL = "sy_task_state";
27
27
  const TASK_CMD_CHANNEL = "sy_task_cmd";
28
28
 
29
- export const taskKeyZ = z.union([
30
- z.string(),
31
- z.bigint().transform((k) => k.toString()),
32
- z.number().transform((k) => k.toString()),
33
- ]);
34
-
35
- export type TaskKey = z.infer<typeof taskKeyZ>;
36
-
37
- export const stateZ = z.object({
38
- task: taskKeyZ,
39
- variant: z.string(),
40
- key: z.string().optional(),
41
- details: z
42
- .record(z.unknown())
43
- .or(
44
- z.string().transform((c) => {
45
- if (c === "") return {};
46
- return JSON.parse(c);
47
- }),
48
- )
49
- .or(z.array(z.unknown()))
50
- .or(z.null()),
51
- });
52
-
53
- export type State<D extends {} = UnknownRecord> = Omit<
54
- z.infer<typeof stateZ>,
55
- "details"
56
- > & {
57
- details?: D;
58
- };
59
-
60
- export const taskZ = z.object({
61
- key: taskKeyZ,
62
- name: z.string(),
63
- type: z.string(),
64
- internal: z.boolean().optional(),
65
- config: z.record(z.unknown()).or(
66
- z.string().transform((c) => {
67
- if (c === "") return {};
68
- return binary.JSON_ECD.decodeString(c);
69
- }),
70
- ) as z.ZodType<UnknownRecord>,
71
- state: stateZ.optional().nullable(),
72
- });
73
-
74
- export const newTaskZ = taskZ.omit({ key: true }).extend({
75
- key: taskKeyZ.transform((k) => k.toString()).optional(),
76
- config: z.unknown().transform((c) => binary.JSON_ECD.encodeString(c)),
77
- });
78
-
79
- export type NewTask<
80
- C extends UnknownRecord = UnknownRecord,
81
- T extends string = string,
82
- > = Omit<z.input<typeof newTaskZ>, "config" | "state"> & {
83
- type: T;
84
- config: C;
85
- };
86
-
87
- export type Payload<
88
- C extends UnknownRecord = UnknownRecord,
89
- D extends {} = UnknownRecord,
90
- T extends string = string,
91
- > = Omit<z.output<typeof taskZ>, "config" | "type" | "state"> & {
92
- type: T;
93
- config: C;
94
- state?: State<D> | null;
95
- };
96
-
97
- export const commandZ = z.object({
98
- task: taskKeyZ,
99
- type: z.string(),
100
- key: z.string(),
101
- args: z.record(z.unknown()).or(
102
- z.string().transform((c) => {
103
- if (c === "") return {};
104
- return JSON.parse(c);
105
- }),
106
- ) as z.ZodType<UnknownRecord>,
107
- });
108
-
109
- export type StateObservable<D extends UnknownRecord = UnknownRecord> =
110
- observe.ObservableAsyncCloseable<State<D>>;
111
-
112
29
  export class Task<
113
30
  C extends UnknownRecord = UnknownRecord,
114
31
  D extends {} = UnknownRecord,
@@ -153,7 +70,7 @@ export class Task<
153
70
 
154
71
  async executeCommand(type: string, args?: UnknownRecord): Promise<string> {
155
72
  const writer = await this.frameClient.openWriter(TASK_CMD_CHANNEL);
156
- const key = nanoid();
73
+ const key = id.id();
157
74
  await writer.write(TASK_CMD_CHANNEL, [{ task: this.key, type, key, args }]);
158
75
  await writer.close();
159
76
  return key;
@@ -0,0 +1,11 @@
1
+ // Copyright 2024 Synnax Labs, Inc.
2
+ //
3
+ // Use of this software is governed by the Business Source License included in the file
4
+ // licenses/BSL.txt.
5
+ //
6
+ // As of the Change Date specified in that file, in accordance with the Business Source
7
+ // License, use of this software will be governed by the Apache License, Version 2.0,
8
+ // included in the file licenses/APL.txt.
9
+
10
+ export * from "@/hardware/task/client";
11
+ export * from "@/hardware/task/payload";
@@ -7,4 +7,4 @@
7
7
  // License, use of this software will be governed by the Apache License, Version 2.0,
8
8
  // included in the file licenses/APL.txt.
9
9
 
10
- export * as task from "@/hardware/task/client";
10
+ export * as task from "@/hardware/task/external";
@@ -0,0 +1,92 @@
1
+ import { binary, observe, UnknownRecord } from "@synnaxlabs/x";
2
+ import { z } from "zod";
3
+
4
+ import { ontology } from "@/ontology";
5
+
6
+ export const taskKeyZ = z.union([
7
+ z.string(),
8
+ z.bigint().transform((k) => k.toString()),
9
+ z.number().transform((k) => k.toString()),
10
+ ]);
11
+
12
+ export type TaskKey = z.infer<typeof taskKeyZ>;
13
+
14
+ export const stateZ = z.object({
15
+ task: taskKeyZ,
16
+ variant: z.string(),
17
+ key: z.string().optional(),
18
+ details: z
19
+ .record(z.unknown())
20
+ .or(
21
+ z.string().transform((c) => {
22
+ if (c === "") return {};
23
+ return JSON.parse(c);
24
+ }),
25
+ )
26
+ .or(z.array(z.unknown()))
27
+ .or(z.null()),
28
+ });
29
+
30
+ export type State<D extends {} = UnknownRecord> = Omit<
31
+ z.infer<typeof stateZ>,
32
+ "details"
33
+ > & {
34
+ details?: D;
35
+ };
36
+
37
+ export const taskZ = z.object({
38
+ key: taskKeyZ,
39
+ name: z.string(),
40
+ type: z.string(),
41
+ internal: z.boolean().optional(),
42
+ config: z.record(z.unknown()).or(
43
+ z.string().transform((c) => {
44
+ if (c === "") return {};
45
+ return binary.JSON_CODEC.decodeString(c);
46
+ }),
47
+ ) as z.ZodType<UnknownRecord>,
48
+ state: stateZ.optional().nullable(),
49
+ });
50
+
51
+ export const newTaskZ = taskZ.omit({ key: true }).extend({
52
+ key: taskKeyZ.transform((k) => k.toString()).optional(),
53
+ config: z.unknown().transform((c) => binary.JSON_CODEC.encodeString(c)),
54
+ });
55
+
56
+ export type NewTask<
57
+ C extends UnknownRecord = UnknownRecord,
58
+ T extends string = string,
59
+ > = Omit<z.input<typeof newTaskZ>, "config" | "state"> & {
60
+ type: T;
61
+ config: C;
62
+ };
63
+
64
+ export type Payload<
65
+ C extends UnknownRecord = UnknownRecord,
66
+ D extends {} = UnknownRecord,
67
+ T extends string = string,
68
+ > = Omit<z.output<typeof taskZ>, "config" | "type" | "state"> & {
69
+ type: T;
70
+ config: C;
71
+ state?: State<D> | null;
72
+ };
73
+
74
+ export const commandZ = z.object({
75
+ task: taskKeyZ,
76
+ type: z.string(),
77
+ key: z.string(),
78
+ args: z.record(z.unknown()).or(
79
+ z.string().transform((c) => {
80
+ if (c === "") return {};
81
+ return JSON.parse(c);
82
+ }),
83
+ ) as z.ZodType<UnknownRecord>,
84
+ });
85
+
86
+ export type StateObservable<D extends UnknownRecord = UnknownRecord> =
87
+ observe.ObservableAsyncCloseable<State<D>>;
88
+
89
+ export const DeviceOntologyType = "task" as ontology.ResourceType;
90
+
91
+ export const ontologyID = (key: TaskKey): ontology.ID =>
92
+ new ontology.ID({ type: DeviceOntologyType, key: key.toString() });
@@ -7,7 +7,7 @@
7
7
  // License, use of this software will be governed by the Apache License, Version 2.0,
8
8
  // included in the file licenses/APL.txt.
9
9
 
10
- import { nanoid } from "nanoid";
10
+ import { id } from "@synnaxlabs/x";
11
11
  import { describe, expect, it } from "vitest";
12
12
 
13
13
  import { task } from "@/hardware/task";
@@ -71,7 +71,7 @@ describe("Hardware", () => {
71
71
  dog: string;
72
72
  }
73
73
  const state: task.State<StateDetails> = {
74
- key: nanoid(),
74
+ key: id.id(),
75
75
  task: t.key,
76
76
  variant: "success",
77
77
  };
package/src/index.ts CHANGED
@@ -9,8 +9,7 @@
9
9
 
10
10
  export * from "@/channel";
11
11
  export { Channel } from "@/channel/client";
12
- export type { SynnaxProps } from "@/client";
13
- export { default as Synnax, synnaxPropsZ } from "@/client";
12
+ export { default as Synnax, type SynnaxProps, synnaxPropsZ } from "@/client";
14
13
  export * from "@/connection";
15
14
  export { control } from "@/control";
16
15
  export {
@@ -25,5 +25,7 @@ export const labelZ = z.object({
25
25
 
26
26
  export type Label = z.infer<typeof labelZ>;
27
27
 
28
+ export const LabelOntologyType = "label" as ontology.ResourceType;
29
+
28
30
  export const ontologyID = (key: Key): ontology.ID =>
29
- new ontology.ID({ type: "label", key });
31
+ new ontology.ID({ type: LabelOntologyType, key });
@@ -10,7 +10,7 @@
10
10
  import { type UnaryClient } from "@synnaxlabs/freighter";
11
11
  import { z } from "zod";
12
12
 
13
- import { type Payload, groupZ } from "@/ontology/group/payload";
13
+ import { groupZ,type Payload } from "@/ontology/group/payload";
14
14
  import { type ID, idZ } from "@/ontology/payload";
15
15
 
16
16
  const resZ = z.object({
@@ -7,7 +7,7 @@
7
7
  // License, use of this software will be governed by the Apache License, Version 2.0,
8
8
  // included in the file licenses/APL.txt.
9
9
 
10
- import { describe, expect, it,test } from "vitest";
10
+ import { describe, expect, it, test } from "vitest";
11
11
 
12
12
  import { ontology } from "@/ontology";
13
13
  import { newClient } from "@/setupspecs";
@@ -7,7 +7,7 @@
7
7
  // License, use of this software will be governed by the Apache License, Version 2.0,
8
8
  // included in the file licenses/APL.txt.
9
9
 
10
- import { change,UnknownRecord } from "@synnaxlabs/x";
10
+ import { change, UnknownRecord } from "@synnaxlabs/x";
11
11
  import { z } from "zod";
12
12
 
13
13
  export type ResourceChange = change.Change<ID, Resource>;
@@ -33,10 +33,15 @@ const resourceTypeZ = z.union([
33
33
  z.literal("rack"),
34
34
  z.literal("device"),
35
35
  z.literal("task"),
36
+ z.literal("policy"),
36
37
  ]);
37
38
 
38
39
  export type ResourceType = z.infer<typeof resourceTypeZ>;
39
40
 
41
+ export const BuiltinOntologyType = "builtin" as ResourceType;
42
+ export const ClusterOntologyType = "cluster" as ResourceType;
43
+ export const NodeOntologyType = "node" as ResourceType;
44
+
40
45
  export const idZ = z.object({ type: resourceTypeZ, key: z.string() });
41
46
 
42
47
  export type IDPayload = z.infer<typeof idZ>;
@@ -11,6 +11,8 @@ import { TimeRange } from "@synnaxlabs/x/telem";
11
11
  import { toArray } from "@synnaxlabs/x/toArray";
12
12
  import { z } from "zod";
13
13
 
14
+ import { ontology } from "@/ontology";
15
+
14
16
  export const keyZ = z.string().uuid();
15
17
  export type Key = z.infer<typeof keyZ>;
16
18
  export type Name = string;
@@ -70,3 +72,12 @@ export const analyzeParams = (params: Params): ParamAnalysisResult => {
70
72
  actual: params,
71
73
  } as const as ParamAnalysisResult;
72
74
  };
75
+
76
+ export const RangeOntologyType = "range" as ontology.ResourceType;
77
+ export const RangeAliasOntologyType = "range-alias" as ontology.ResourceType;
78
+
79
+ export const rangeOntologyID = (key: Key): ontology.ID =>
80
+ new ontology.ID({ type: RangeOntologyType, key: key });
81
+
82
+ export const rangeAliasOntologyID = (key: Key): ontology.ID =>
83
+ new ontology.ID({ type: RangeAliasOntologyType, key: key });