@synnaxlabs/client 0.38.1 → 0.40.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 (257) hide show
  1. package/.turbo/turbo-build.log +7 -7
  2. package/dist/access/payload.d.ts +6 -6
  3. package/dist/access/payload.d.ts.map +1 -1
  4. package/dist/access/policy/client.d.ts +5 -3
  5. package/dist/access/policy/client.d.ts.map +1 -1
  6. package/dist/access/policy/external.d.ts +1 -0
  7. package/dist/access/policy/external.d.ts.map +1 -1
  8. package/dist/access/policy/ontology.d.ts +5 -0
  9. package/dist/access/policy/ontology.d.ts.map +1 -0
  10. package/dist/access/policy/payload.d.ts +86 -89
  11. package/dist/access/policy/payload.d.ts.map +1 -1
  12. package/dist/access/policy/retriever.d.ts +7 -6
  13. package/dist/access/policy/retriever.d.ts.map +1 -1
  14. package/dist/access/policy/writer.d.ts +2 -2
  15. package/dist/access/policy/writer.d.ts.map +1 -1
  16. package/dist/auth/auth.d.ts +2 -1
  17. package/dist/auth/auth.d.ts.map +1 -1
  18. package/dist/channel/client.d.ts +6 -5
  19. package/dist/channel/client.d.ts.map +1 -1
  20. package/dist/channel/payload.d.ts +13 -11
  21. package/dist/channel/payload.d.ts.map +1 -1
  22. package/dist/channel/retriever.d.ts +9 -6
  23. package/dist/channel/retriever.d.ts.map +1 -1
  24. package/dist/channel/writer.d.ts +6 -4
  25. package/dist/channel/writer.d.ts.map +1 -1
  26. package/dist/client.cjs +30 -30
  27. package/dist/client.d.ts +4 -2
  28. package/dist/client.d.ts.map +1 -1
  29. package/dist/client.js +3387 -3433
  30. package/dist/connection/checker.d.ts +5 -4
  31. package/dist/connection/checker.d.ts.map +1 -1
  32. package/dist/control/state.d.ts +10 -8
  33. package/dist/control/state.d.ts.map +1 -1
  34. package/dist/errors.d.ts +5 -0
  35. package/dist/errors.d.ts.map +1 -1
  36. package/dist/framer/adapter.d.ts +14 -15
  37. package/dist/framer/adapter.d.ts.map +1 -1
  38. package/dist/framer/client.d.ts +13 -15
  39. package/dist/framer/client.d.ts.map +1 -1
  40. package/dist/framer/deleter.d.ts +3 -2
  41. package/dist/framer/deleter.d.ts.map +1 -1
  42. package/dist/framer/frame.d.ts +31 -27
  43. package/dist/framer/frame.d.ts.map +1 -1
  44. package/dist/framer/iterator.d.ts +4 -5
  45. package/dist/framer/iterator.d.ts.map +1 -1
  46. package/dist/framer/streamer.d.ts +5 -6
  47. package/dist/framer/streamer.d.ts.map +1 -1
  48. package/dist/framer/writer.d.ts +42 -39
  49. package/dist/framer/writer.d.ts.map +1 -1
  50. package/dist/hardware/device/client.d.ts +20 -12
  51. package/dist/hardware/device/client.d.ts.map +1 -1
  52. package/dist/hardware/device/payload.d.ts +19 -16
  53. package/dist/hardware/device/payload.d.ts.map +1 -1
  54. package/dist/hardware/rack/client.d.ts +15 -15
  55. package/dist/hardware/rack/client.d.ts.map +1 -1
  56. package/dist/hardware/rack/payload.d.ts +9 -8
  57. package/dist/hardware/rack/payload.d.ts.map +1 -1
  58. package/dist/hardware/task/client.d.ts +38 -29
  59. package/dist/hardware/task/client.d.ts.map +1 -1
  60. package/dist/hardware/task/payload.d.ts +58 -53
  61. package/dist/hardware/task/payload.d.ts.map +1 -1
  62. package/dist/label/client.d.ts +4 -3
  63. package/dist/label/client.d.ts.map +1 -1
  64. package/dist/label/payload.d.ts +4 -4
  65. package/dist/label/payload.d.ts.map +1 -1
  66. package/dist/label/retriever.d.ts.map +1 -1
  67. package/dist/label/writer.d.ts +13 -10
  68. package/dist/label/writer.d.ts.map +1 -1
  69. package/dist/ontology/client.d.ts +12 -10
  70. package/dist/ontology/client.d.ts.map +1 -1
  71. package/dist/ontology/group/client.d.ts +5 -4
  72. package/dist/ontology/group/client.d.ts.map +1 -1
  73. package/dist/ontology/group/group.d.ts +7 -5
  74. package/dist/ontology/group/group.d.ts.map +1 -1
  75. package/dist/ontology/group/payload.d.ts +6 -5
  76. package/dist/ontology/group/payload.d.ts.map +1 -1
  77. package/dist/ontology/group/writer.d.ts +8 -8
  78. package/dist/ontology/group/writer.d.ts.map +1 -1
  79. package/dist/ontology/payload.d.ts +72 -62
  80. package/dist/ontology/payload.d.ts.map +1 -1
  81. package/dist/ontology/writer.d.ts.map +1 -1
  82. package/dist/ranger/alias.d.ts +9 -10
  83. package/dist/ranger/alias.d.ts.map +1 -1
  84. package/dist/ranger/client.d.ts +18 -18
  85. package/dist/ranger/client.d.ts.map +1 -1
  86. package/dist/ranger/external.d.ts +1 -1
  87. package/dist/ranger/external.d.ts.map +1 -1
  88. package/dist/ranger/kv.d.ts +18 -14
  89. package/dist/ranger/kv.d.ts.map +1 -1
  90. package/dist/ranger/payload.d.ts +13 -13
  91. package/dist/ranger/payload.d.ts.map +1 -1
  92. package/dist/ranger/writer.d.ts +14 -14
  93. package/dist/ranger/writer.d.ts.map +1 -1
  94. package/dist/setupspecs.d.ts.map +1 -1
  95. package/dist/signals/observable.d.ts +3 -1
  96. package/dist/signals/observable.d.ts.map +1 -1
  97. package/dist/user/client.d.ts +5 -3
  98. package/dist/user/client.d.ts.map +1 -1
  99. package/dist/user/payload.d.ts +7 -6
  100. package/dist/user/payload.d.ts.map +1 -1
  101. package/dist/user/retriever.d.ts +2 -1
  102. package/dist/user/retriever.d.ts.map +1 -1
  103. package/dist/user/writer.d.ts +2 -2
  104. package/dist/user/writer.d.ts.map +1 -1
  105. package/dist/util/decodeJSONString.d.ts +3 -0
  106. package/dist/util/decodeJSONString.d.ts.map +1 -0
  107. package/dist/util/parseWithoutKeyConversion.d.ts +3 -0
  108. package/dist/util/parseWithoutKeyConversion.d.ts.map +1 -0
  109. package/dist/util/retrieve.d.ts +1 -1
  110. package/dist/util/retrieve.d.ts.map +1 -1
  111. package/dist/util/telem.d.ts.map +1 -1
  112. package/dist/util/zod.d.ts.map +1 -1
  113. package/dist/workspace/client.d.ts +6 -60
  114. package/dist/workspace/client.d.ts.map +1 -1
  115. package/dist/workspace/external.d.ts +3 -0
  116. package/dist/workspace/external.d.ts.map +1 -0
  117. package/dist/workspace/index.d.ts +1 -1
  118. package/dist/workspace/index.d.ts.map +1 -1
  119. package/dist/workspace/lineplot/client.d.ts +5 -44
  120. package/dist/workspace/lineplot/client.d.ts.map +1 -1
  121. package/dist/workspace/lineplot/external.d.ts +3 -0
  122. package/dist/workspace/lineplot/external.d.ts.map +1 -0
  123. package/dist/workspace/lineplot/index.d.ts +1 -1
  124. package/dist/workspace/lineplot/index.d.ts.map +1 -1
  125. package/dist/workspace/lineplot/payload.d.ts +45 -0
  126. package/dist/workspace/lineplot/payload.d.ts.map +1 -0
  127. package/dist/workspace/log/client.d.ts +5 -44
  128. package/dist/workspace/log/client.d.ts.map +1 -1
  129. package/dist/workspace/log/external.d.ts +3 -0
  130. package/dist/workspace/log/external.d.ts.map +1 -0
  131. package/dist/workspace/log/index.d.ts +1 -1
  132. package/dist/workspace/log/index.d.ts.map +1 -1
  133. package/dist/workspace/log/payload.d.ts +45 -0
  134. package/dist/workspace/log/payload.d.ts.map +1 -0
  135. package/dist/workspace/payload.d.ts +60 -0
  136. package/dist/workspace/payload.d.ts.map +1 -0
  137. package/dist/workspace/schematic/client.d.ts +5 -68
  138. package/dist/workspace/schematic/client.d.ts.map +1 -1
  139. package/dist/workspace/schematic/external.d.ts +3 -0
  140. package/dist/workspace/schematic/external.d.ts.map +1 -0
  141. package/dist/workspace/schematic/index.d.ts +1 -1
  142. package/dist/workspace/schematic/index.d.ts.map +1 -1
  143. package/dist/workspace/schematic/payload.d.ts +71 -0
  144. package/dist/workspace/schematic/payload.d.ts.map +1 -0
  145. package/dist/workspace/table/client.d.ts +5 -57
  146. package/dist/workspace/table/client.d.ts.map +1 -1
  147. package/dist/workspace/table/external.d.ts +3 -0
  148. package/dist/workspace/table/external.d.ts.map +1 -0
  149. package/dist/workspace/table/index.d.ts +1 -1
  150. package/dist/workspace/table/index.d.ts.map +1 -1
  151. package/dist/workspace/table/payload.d.ts +60 -0
  152. package/dist/workspace/table/payload.d.ts.map +1 -0
  153. package/examples/node/basicReadWrite.js +26 -26
  154. package/examples/node/liveStream.js +15 -15
  155. package/examples/node/seriesAndFrames.js +38 -38
  156. package/examples/node/streamWrite.js +47 -45
  157. package/package.json +15 -13
  158. package/src/access/payload.ts +12 -12
  159. package/src/access/policy/client.ts +13 -12
  160. package/src/access/policy/external.ts +1 -0
  161. package/src/access/policy/ontology.ts +17 -0
  162. package/src/access/policy/payload.ts +7 -19
  163. package/src/access/policy/policy.spec.ts +16 -16
  164. package/src/access/policy/retriever.ts +2 -1
  165. package/src/access/policy/writer.ts +4 -4
  166. package/src/auth/auth.spec.ts +27 -23
  167. package/src/auth/auth.ts +7 -11
  168. package/src/channel/batchRetriever.spec.ts +25 -22
  169. package/src/channel/client.ts +19 -21
  170. package/src/channel/payload.ts +16 -20
  171. package/src/channel/retriever.ts +20 -21
  172. package/src/channel/writer.ts +11 -13
  173. package/src/client.ts +6 -16
  174. package/src/connection/checker.ts +9 -11
  175. package/src/connection/connection.spec.ts +17 -5
  176. package/src/control/state.ts +8 -9
  177. package/src/errors.spec.ts +1 -1
  178. package/src/errors.ts +8 -0
  179. package/src/framer/adapter.spec.ts +28 -23
  180. package/src/framer/adapter.ts +37 -41
  181. package/src/framer/client.spec.ts +5 -11
  182. package/src/framer/client.ts +34 -38
  183. package/src/framer/deleter.ts +5 -6
  184. package/src/framer/frame.ts +62 -50
  185. package/src/framer/iterator.ts +11 -16
  186. package/src/framer/streamer.spec.ts +2 -10
  187. package/src/framer/streamer.ts +15 -19
  188. package/src/framer/writer.spec.ts +48 -7
  189. package/src/framer/writer.ts +39 -31
  190. package/src/hardware/device/client.ts +67 -39
  191. package/src/hardware/device/device.spec.ts +91 -33
  192. package/src/hardware/device/payload.ts +29 -28
  193. package/src/hardware/rack/client.ts +52 -65
  194. package/src/hardware/rack/payload.ts +9 -18
  195. package/src/hardware/rack/rack.spec.ts +12 -0
  196. package/src/hardware/task/client.ts +160 -131
  197. package/src/hardware/task/payload.ts +49 -68
  198. package/src/hardware/task/task.spec.ts +98 -81
  199. package/src/label/client.ts +12 -15
  200. package/src/label/payload.ts +3 -9
  201. package/src/label/retriever.ts +3 -7
  202. package/src/label/writer.ts +8 -15
  203. package/src/ontology/client.ts +17 -22
  204. package/src/ontology/group/client.ts +5 -5
  205. package/src/ontology/group/group.spec.ts +4 -4
  206. package/src/ontology/group/group.ts +10 -7
  207. package/src/ontology/group/payload.ts +11 -35
  208. package/src/ontology/group/writer.ts +22 -26
  209. package/src/ontology/ontology.spec.ts +15 -15
  210. package/src/ontology/payload.ts +67 -43
  211. package/src/ontology/writer.ts +16 -23
  212. package/src/ranger/alias.ts +25 -42
  213. package/src/ranger/client.ts +29 -38
  214. package/src/ranger/external.ts +1 -1
  215. package/src/ranger/kv.ts +9 -32
  216. package/src/ranger/payload.ts +14 -36
  217. package/src/ranger/ranger.spec.ts +1 -2
  218. package/src/ranger/writer.ts +8 -26
  219. package/src/signals/observable.ts +3 -4
  220. package/src/user/client.ts +8 -4
  221. package/src/user/payload.ts +5 -9
  222. package/src/user/retriever.ts +1 -1
  223. package/src/user/user.spec.ts +17 -15
  224. package/src/user/writer.ts +3 -10
  225. package/src/util/decodeJSONString.ts +13 -0
  226. package/src/util/parseWithoutKeyConversion.ts +19 -0
  227. package/src/util/retrieve.spec.ts +3 -13
  228. package/src/util/retrieve.ts +2 -12
  229. package/src/util/telem.ts +1 -1
  230. package/src/vite-env.d.ts +1 -0
  231. package/src/workspace/client.ts +30 -57
  232. package/src/workspace/external.ts +11 -0
  233. package/src/workspace/index.ts +1 -1
  234. package/src/workspace/lineplot/client.ts +22 -36
  235. package/src/workspace/lineplot/external.ts +11 -0
  236. package/src/workspace/lineplot/index.ts +1 -1
  237. package/src/workspace/lineplot/linePlot.spec.ts +1 -2
  238. package/src/workspace/lineplot/payload.ts +32 -0
  239. package/src/workspace/log/client.ts +25 -39
  240. package/src/workspace/log/external.ts +11 -0
  241. package/src/workspace/log/index.ts +1 -1
  242. package/src/workspace/log/log.spec.ts +5 -18
  243. package/src/workspace/log/payload.ts +32 -0
  244. package/src/workspace/payload.ts +36 -0
  245. package/src/workspace/schematic/client.ts +30 -56
  246. package/src/workspace/schematic/external.ts +11 -0
  247. package/src/workspace/schematic/index.ts +1 -1
  248. package/src/workspace/schematic/payload.ts +37 -0
  249. package/src/workspace/schematic/schematic.spec.ts +15 -6
  250. package/src/workspace/table/client.ts +27 -50
  251. package/src/workspace/table/external.ts +11 -0
  252. package/src/workspace/table/index.ts +1 -1
  253. package/src/workspace/table/payload.ts +36 -0
  254. package/src/workspace/workspace.spec.ts +1 -2
  255. package/dist/channel/creator.d.ts +0 -9
  256. package/dist/channel/creator.d.ts.map +0 -1
  257. package/src/channel/creator.ts +0 -37
@@ -15,101 +15,118 @@ import { newClient } from "@/setupspecs";
15
15
 
16
16
  const client = newClient();
17
17
 
18
- describe("Hardware", () => {
19
- describe("Task", () => {
20
- describe("create", () => {
21
- it("should create a task on a rack", async () => {
22
- const r = await client.hardware.racks.create({ name: "test" });
23
- const m = await r.createTask({
24
- name: "test",
25
- config: { a: "dog" },
26
- type: "ni",
27
- });
28
- expect(m.key).not.toHaveLength(0);
29
- const rackKey = BigInt(m.key) >> 32n;
30
- expect(Number(rackKey)).toBe(r.key);
18
+ describe("Task", async () => {
19
+ const testRack = await client.hardware.racks.create({ name: "test" });
20
+ describe("create", () => {
21
+ it("should create a task on a rack", async () => {
22
+ const m = await testRack.createTask({
23
+ name: "test",
24
+ config: { a: "dog" },
25
+ type: "ni",
31
26
  });
27
+ expect(m.key).not.toHaveLength(0);
28
+ const rackKey = BigInt(m.key) >> 32n;
29
+ expect(Number(rackKey)).toBe(testRack.key);
32
30
  });
33
- describe("retrieve", () => {
34
- it("should retrieve a task by its key", async () => {
35
- const r = await client.hardware.racks.create({ name: "test" });
36
- const m = await r.createTask({
37
- name: "test",
38
- config: { a: "dog" },
39
- type: "ni",
40
- });
41
- const retrieved = await client.hardware.tasks.retrieve(m.key);
42
- expect(retrieved.key).toBe(m.key);
43
- expect(retrieved.name).toBe("test");
44
- expect(retrieved.config).toStrictEqual({ a: "dog" });
45
- expect(retrieved.type).toBe("ni");
31
+ it("should create a task with a config", async () => {
32
+ const config = {
33
+ stateRate: 100,
34
+ inputChannels: [
35
+ { port: "AIN0", enabled: true },
36
+ { port: "DAC2", enabled: false },
37
+ ],
38
+ dataSaving: false,
39
+ };
40
+ const m = await testRack.createTask({
41
+ name: "test",
42
+ config,
43
+ type: "ni",
46
44
  });
47
- describe("retrieveByName", () => {
48
- it("should retrieve a task by its name", async () => {
49
- const name = `test-${Date.now()}-${Math.random()}`;
50
- const r = await client.hardware.racks.create({ name });
51
- const m = await r.createTask({
52
- name,
53
- config: { a: "dog" },
54
- type: "ni",
55
- });
56
- const retrieved = await client.hardware.tasks.retrieveByName(name);
57
- expect(retrieved.key).toBe(m.key);
58
- });
45
+ expect(m.config).toStrictEqual(config);
46
+ });
47
+ });
48
+ describe("update", () => {
49
+ it("should update a task if the key is provided", async () => {
50
+ const m = await testRack.createTask({
51
+ name: "test",
52
+ config: { a: "dog" },
53
+ type: "ni",
59
54
  });
60
- describe("retrieve with state", () => {
61
- it("should also send the tasks state", async () => {
62
- const r = await client.hardware.racks.create({ name: "test" });
63
- const t = await r.createTask({
64
- name: "test",
65
- config: { a: "dog" },
66
- type: "ni",
67
- });
68
- const w = await client.openWriter(["sy_task_state"]);
69
- interface StateDetails {
70
- dog: string;
71
- }
72
- const state: task.State<StateDetails> = {
73
- key: id.id(),
74
- task: t.key,
75
- variant: "success",
76
- };
77
- expect(await w.write("sy_task_state", [state])).toBeTruthy();
78
- await w.close();
79
- const retrieved = await client.hardware.tasks.retrieve(t.key, {
80
- includeState: true,
81
- });
82
- expect(retrieved.state).not.toBeNull();
83
- expect(retrieved.state?.variant).toBe(state.variant);
84
- });
55
+ const updated = await client.hardware.tasks.create({
56
+ ...m,
57
+ name: "updated",
85
58
  });
59
+ expect(updated.name).toBe("updated");
60
+ const retrieved = await client.hardware.tasks.retrieve(m.key);
61
+ expect(retrieved.name).toBe("updated");
86
62
  });
87
-
88
- describe("copy", () => {
89
- it("should correctly copy the task", async () => {
90
- const r = await client.hardware.racks.create({ name: "test" });
91
- const m = await r.createTask({
63
+ });
64
+ describe("retrieve", () => {
65
+ it("should retrieve a task by its key", async () => {
66
+ const m = await testRack.createTask({
67
+ name: "test",
68
+ config: { a: "dog" },
69
+ type: "ni",
70
+ });
71
+ const retrieved = await client.hardware.tasks.retrieve(m.key);
72
+ expect(retrieved.key).toBe(m.key);
73
+ expect(retrieved.name).toBe("test");
74
+ expect(retrieved.config).toStrictEqual({ a: "dog" });
75
+ expect(retrieved.type).toBe("ni");
76
+ });
77
+ describe("retrieveByName", () => {
78
+ it("should retrieve a task by its name", async () => {
79
+ const name = `test-${Date.now()}-${Math.random()}`;
80
+ const m = await testRack.createTask({ name, config: { a: "dog" }, type: "ni" });
81
+ const retrieved = await client.hardware.tasks.retrieveByName(name);
82
+ expect(retrieved.key).toBe(m.key);
83
+ });
84
+ });
85
+ describe("retrieve with state", () => {
86
+ it("should also send the tasks state", async () => {
87
+ const t = await testRack.createTask({
92
88
  name: "test",
93
89
  config: { a: "dog" },
94
90
  type: "ni",
95
91
  });
96
- const copy = await client.hardware.tasks.copy(m.key, "New Name", false);
97
- expect(copy.name).toBe("New Name");
98
- expect(copy.config).toStrictEqual({ a: "dog" });
92
+ const w = await client.openWriter(["sy_task_state"]);
93
+ interface StateDetails {
94
+ dog: string;
95
+ }
96
+ const state: task.State<StateDetails> = {
97
+ key: id.create(),
98
+ task: t.key,
99
+ variant: "success",
100
+ };
101
+ expect(await w.write("sy_task_state", [state])).toBeTruthy();
102
+ await w.close();
103
+ const retrieved = await client.hardware.tasks.retrieve(t.key, {
104
+ includeState: true,
105
+ });
106
+ expect(retrieved.state).not.toBeNull();
107
+ expect(retrieved.state?.variant).toBe(state.variant);
99
108
  });
100
109
  });
110
+ });
101
111
 
102
- describe("list", () => {
103
- it("should list all tasks", async () => {
104
- const t = await client.hardware.racks.create({ name: "test" });
105
- await t.createTask({
106
- name: "test",
107
- config: { a: "dog" },
108
- type: "ni",
109
- });
110
- const tasks = await client.hardware.tasks.list();
111
- expect(tasks.length).toBeGreaterThan(0);
112
+ describe("copy", () => {
113
+ it("should correctly copy the task", async () => {
114
+ const m = await testRack.createTask({
115
+ name: "test",
116
+ config: { a: "dog" },
117
+ type: "ni",
112
118
  });
119
+ const copy = await client.hardware.tasks.copy(m.key, "New Name", false);
120
+ expect(copy.name).toBe("New Name");
121
+ expect(copy.config).toStrictEqual({ a: "dog" });
122
+ });
123
+ });
124
+
125
+ describe("list", () => {
126
+ it("should list all tasks", async () => {
127
+ await testRack.createTask({ name: "test", config: { a: "dog" }, type: "ni" });
128
+ const tasks = await client.hardware.tasks.list();
129
+ expect(tasks.length).toBeGreaterThan(0);
113
130
  });
114
131
  });
115
132
  });
@@ -12,14 +12,14 @@ import { observe } from "@synnaxlabs/x";
12
12
  import { type AsyncTermSearcher } from "@synnaxlabs/x/search";
13
13
 
14
14
  import { type framer } from "@/framer";
15
- import { type Key, type Label, labelZ, ontologyID } from "@/label/payload";
15
+ import { type Key, type Label, labelZ, ONTOLOGY_TYPE } from "@/label/payload";
16
16
  import { Retriever } from "@/label/retriever";
17
- import { type NewLabelPayload, type SetOptions, Writer } from "@/label/writer";
17
+ import { type New, type SetOptions, Writer } from "@/label/writer";
18
18
  import { ontology } from "@/ontology";
19
19
  import { signals } from "@/signals";
20
20
 
21
- const LABEL_SET_NAME = "sy_label_set";
22
- const LABEL_DELETE_NAME = "sy_label_delete";
21
+ const SET_CHANNEL_NAME = "sy_label_set";
22
+ const DELETE_CHANNEL_NAME = "sy_label_delete";
23
23
 
24
24
  export class Client implements AsyncTermSearcher<string, Key, Label> {
25
25
  readonly type: string = "label";
@@ -44,9 +44,7 @@ export class Client implements AsyncTermSearcher<string, Key, Label> {
44
44
  }
45
45
 
46
46
  async retrieve(key: Key): Promise<Label>;
47
-
48
47
  async retrieve(keys: Key[]): Promise<Label[]>;
49
-
50
48
  async retrieve(keys: Key | Key[]): Promise<Label | Label[]> {
51
49
  const isMany = Array.isArray(keys);
52
50
  const res = await this.retriever.retrieve(keys);
@@ -73,20 +71,16 @@ export class Client implements AsyncTermSearcher<string, Key, Label> {
73
71
  return await this.retriever.page(offset, limit);
74
72
  }
75
73
 
76
- async create(label: NewLabelPayload): Promise<Label>;
77
-
78
- async create(labels: NewLabelPayload[]): Promise<Label[]>;
79
-
80
- async create(labels: NewLabelPayload | NewLabelPayload[]): Promise<Label | Label[]> {
74
+ async create(label: New): Promise<Label>;
75
+ async create(labels: New[]): Promise<Label[]>;
76
+ async create(labels: New | New[]): Promise<Label | Label[]> {
81
77
  const isMany = Array.isArray(labels);
82
78
  const res = await this.writer.create(labels);
83
79
  return isMany ? res : res[0];
84
80
  }
85
81
 
86
82
  async delete(key: Key): Promise<void>;
87
-
88
83
  async delete(keys: Key[]): Promise<void>;
89
-
90
84
  async delete(keys: Key | Key[]): Promise<void> {
91
85
  await this.writer.delete(keys);
92
86
  }
@@ -94,8 +88,8 @@ export class Client implements AsyncTermSearcher<string, Key, Label> {
94
88
  async openChangeTracker(): Promise<signals.Observable<string, Label>> {
95
89
  return await signals.openObservable<string, Label>(
96
90
  this.frameClient,
97
- LABEL_SET_NAME,
98
- LABEL_DELETE_NAME,
91
+ SET_CHANNEL_NAME,
92
+ DELETE_CHANNEL_NAME,
99
93
  decodeChanges,
100
94
  );
101
95
  }
@@ -132,3 +126,6 @@ const decodeChanges: signals.Decoder<string, Label> = (variant, data) => {
132
126
  if (variant === "delete") return data.toUUIDs().map((v) => ({ variant, key: v }));
133
127
  return data.parseJSON(labelZ).map((l) => ({ variant, key: l.key, value: l }));
134
128
  };
129
+
130
+ export const ontologyID = (key: Key): ontology.ID =>
131
+ new ontology.ID({ type: ONTOLOGY_TYPE, key });
@@ -9,10 +9,7 @@
9
9
 
10
10
  import { z } from "zod";
11
11
 
12
- import { ontology } from "@/ontology";
13
-
14
12
  export const keyZ = z.string().uuid();
15
-
16
13
  export type Key = z.infer<typeof keyZ>;
17
14
 
18
15
  export type Params = Key | Key[];
@@ -22,10 +19,7 @@ export const labelZ = z.object({
22
19
  name: z.string().min(1),
23
20
  color: z.string(),
24
21
  });
22
+ export interface Label extends z.infer<typeof labelZ> {}
25
23
 
26
- export type Label = z.infer<typeof labelZ>;
27
-
28
- export const ONTOLOGY_TYPE: ontology.ResourceType = "label";
29
-
30
- export const ontologyID = (key: Key): ontology.ID =>
31
- new ontology.ID({ type: ONTOLOGY_TYPE, key });
24
+ export const ONTOLOGY_TYPE = "label";
25
+ export type OntologyType = typeof ONTOLOGY_TYPE;
@@ -22,12 +22,9 @@ const reqZ = z.object({
22
22
  offset: z.number().optional(),
23
23
  limit: z.number().optional(),
24
24
  });
25
+ interface Request extends z.infer<typeof reqZ> {}
25
26
 
26
- type Request = z.infer<typeof reqZ>;
27
-
28
- const resZ = z.object({
29
- labels: nullableArrayZ(labelZ),
30
- });
27
+ const resZ = z.object({ labels: nullableArrayZ(labelZ) });
31
28
 
32
29
  export class Retriever {
33
30
  private static readonly ENDPOINT = "/label/retrieve";
@@ -38,8 +35,7 @@ export class Retriever {
38
35
  }
39
36
 
40
37
  async retrieve(labels: Params): Promise<Label[]> {
41
- const normalized = toArray(labels);
42
- return await this.execute({ keys: normalized });
38
+ return await this.execute({ keys: toArray(labels) });
43
39
  }
44
40
 
45
41
  async retrieveFor(id: ontology.ID): Promise<Label[]> {
@@ -14,21 +14,14 @@ import { z } from "zod";
14
14
  import { type Key, keyZ, type Label, labelZ } from "@/label/payload";
15
15
  import { ontology } from "@/ontology";
16
16
 
17
- export const newLabelPayloadZ = labelZ.extend({ key: keyZ.optional() });
17
+ export const newZ = labelZ.extend({ key: keyZ.optional() });
18
+ export interface New extends z.infer<typeof newZ> {}
18
19
 
19
- export type NewLabelPayload = z.infer<typeof newLabelPayloadZ>;
20
+ const createReqZ = z.object({ labels: newZ.array() });
20
21
 
21
- const createReqZ = z.object({
22
- labels: newLabelPayloadZ.array(),
23
- });
24
-
25
- const createResZ = z.object({
26
- labels: labelZ.array(),
27
- });
22
+ const createResZ = z.object({ labels: labelZ.array() });
28
23
 
29
- const deleteReqZ = z.object({
30
- keys: keyZ.array(),
31
- });
24
+ const deleteReqZ = z.object({ keys: keyZ.array() });
32
25
 
33
26
  const setReqZ = z.object({
34
27
  id: ontology.idZ,
@@ -36,8 +29,8 @@ const setReqZ = z.object({
36
29
  replace: z.boolean().optional(),
37
30
  });
38
31
 
39
- type SetReq = z.infer<typeof setReqZ>;
40
- export type SetOptions = Pick<SetReq, "replace">;
32
+ interface SetReq extends z.infer<typeof setReqZ> {}
33
+ export interface SetOptions extends Pick<SetReq, "replace"> {}
41
34
 
42
35
  const removeReqZ = setReqZ.omit({ replace: true });
43
36
 
@@ -55,7 +48,7 @@ export class Writer {
55
48
  this.client = client;
56
49
  }
57
50
 
58
- async create(labels: NewLabelPayload | NewLabelPayload[]): Promise<Label[]> {
51
+ async create(labels: New | New[]): Promise<Label[]> {
59
52
  const res = await sendRequired<typeof createReqZ, typeof createResZ>(
60
53
  this.client,
61
54
  CREATE_ENDPOINT,
@@ -25,8 +25,8 @@ import {
25
25
  type RelationshipDirection,
26
26
  type Resource,
27
27
  type ResourceChange,
28
- resourceSchemaZ,
29
28
  resourceTypeZ,
29
+ resourceZ,
30
30
  } from "@/ontology/payload";
31
31
  import { Writer } from "@/ontology/writer";
32
32
 
@@ -43,17 +43,12 @@ const retrieveReqZ = z.object({
43
43
  offset: z.number().optional(),
44
44
  types: resourceTypeZ.array().optional(),
45
45
  });
46
+ interface RetrieveRequest extends z.infer<typeof retrieveReqZ> {}
46
47
 
47
- type RetrieveRequest = z.infer<typeof retrieveReqZ>;
48
+ export interface RetrieveOptions
49
+ extends Pick<RetrieveRequest, "includeSchema" | "excludeFieldData" | "types"> {}
48
50
 
49
- export type RetrieveOptions = Pick<
50
- RetrieveRequest,
51
- "includeSchema" | "excludeFieldData" | "types"
52
- >;
53
-
54
- const retrieveResZ = z.object({
55
- resources: resourceSchemaZ.array(),
56
- });
51
+ const retrieveResZ = z.object({ resources: resourceZ.array() });
57
52
 
58
53
  export const parseIDs = (ids: CrudeID | CrudeID[] | string | string[]): IDPayload[] =>
59
54
  toArray(ids).map((id) => new ID(id).payload);
@@ -254,10 +249,10 @@ export class Client implements AsyncTermSearcher<string, string, Resource> {
254
249
  }
255
250
  }
256
251
 
257
- const RESOURCE_SET_NAME = "sy_ontology_resource_set";
258
- const RESOURCE_DELETE_NAME = "sy_ontology_resource_delete";
259
- const RELATIONSHIP_SET_NAME = "sy_ontology_relationship_set";
260
- const RELATIONSHIP_DELETE_NAME = "sy_ontology_relationship_delete";
252
+ const RESOURCE_SET_CHANNEL_NAME = "sy_ontology_resource_set";
253
+ const RESOURCE_DELETE_CHANNEL_NAME = "sy_ontology_resource_delete";
254
+ const RELATIONSHIP_SET_CHANNEL_NAME = "sy_ontology_relationship_set";
255
+ const RELATIONSHIP_DELETE_CHANNEL_NAME = "sy_ontology_relationship_delete";
261
256
 
262
257
  /**
263
258
  * A class that tracks changes to the ontology's resources and relationships.
@@ -310,7 +305,7 @@ export class ChangeTracker {
310
305
  }
311
306
 
312
307
  private parseRelationshipSets(frame: framer.Frame): RelationshipChange[] {
313
- const relationships = frame.get(RELATIONSHIP_SET_NAME);
308
+ const relationships = frame.get(RELATIONSHIP_SET_CHANNEL_NAME);
314
309
  if (relationships.length === 0) return [];
315
310
  return Array.from(relationships.as("string")).map((rel) => ({
316
311
  variant: "set",
@@ -320,7 +315,7 @@ export class ChangeTracker {
320
315
  }
321
316
 
322
317
  private parseRelationshipDeletes(frame: framer.Frame): RelationshipChange[] {
323
- const relationships = frame.get(RELATIONSHIP_DELETE_NAME);
318
+ const relationships = frame.get(RELATIONSHIP_DELETE_CHANNEL_NAME);
324
319
  if (relationships.length === 0) return [];
325
320
  return Array.from(relationships.as("string")).map((rel) => ({
326
321
  variant: "delete",
@@ -329,7 +324,7 @@ export class ChangeTracker {
329
324
  }
330
325
 
331
326
  private async parseResourceSets(frame: framer.Frame): Promise<ResourceChange[]> {
332
- const sets = frame.get(RESOURCE_SET_NAME);
327
+ const sets = frame.get(RESOURCE_SET_CHANNEL_NAME);
333
328
  if (sets.length === 0) return [];
334
329
  // We should only ever get one series of sets
335
330
  const ids = Array.from(sets.as("string")).map((id: string) => new ID(id));
@@ -347,7 +342,7 @@ export class ChangeTracker {
347
342
  }
348
343
 
349
344
  private parseResourceDeletes(frame: framer.Frame): ResourceChange[] {
350
- const deletes = frame.get(RESOURCE_DELETE_NAME);
345
+ const deletes = frame.get(RESOURCE_DELETE_CHANNEL_NAME);
351
346
  if (deletes.length === 0) return [];
352
347
  // We should only ever get one series of deletes
353
348
  return Array.from(deletes.as("string")).map((str) => ({
@@ -358,10 +353,10 @@ export class ChangeTracker {
358
353
 
359
354
  static async open(client: framer.Client, retriever: Client): Promise<ChangeTracker> {
360
355
  const streamer = await client.openStreamer([
361
- RESOURCE_SET_NAME,
362
- RESOURCE_DELETE_NAME,
363
- RELATIONSHIP_SET_NAME,
364
- RELATIONSHIP_DELETE_NAME,
356
+ RESOURCE_SET_CHANNEL_NAME,
357
+ RESOURCE_DELETE_CHANNEL_NAME,
358
+ RELATIONSHIP_SET_CHANNEL_NAME,
359
+ RELATIONSHIP_DELETE_CHANNEL_NAME,
365
360
  ]);
366
361
  return new ChangeTracker(streamer, retriever);
367
362
  }
@@ -9,10 +9,10 @@
9
9
 
10
10
  import { type UnaryClient } from "@synnaxlabs/freighter";
11
11
 
12
+ import { type ontology } from "@/ontology";
12
13
  import { Group } from "@/ontology/group/group";
13
- import { type Payload } from "@/ontology/group/payload";
14
+ import { type Key, type Name, type Payload } from "@/ontology/group/payload";
14
15
  import { Writer } from "@/ontology/group/writer";
15
- import { type ID } from "@/ontology/payload";
16
16
 
17
17
  export class Client {
18
18
  private readonly creator: Writer;
@@ -21,15 +21,15 @@ export class Client {
21
21
  this.creator = new Writer(unary);
22
22
  }
23
23
 
24
- async create(parent: ID, name: string, key?: string): Promise<Group> {
24
+ async create(parent: ontology.ID, name: Name, key?: Key): Promise<Group> {
25
25
  return this.sugar(await this.creator.create(parent, name, key));
26
26
  }
27
27
 
28
- async rename(key: string, name: string): Promise<void> {
28
+ async rename(key: Key, name: Name): Promise<void> {
29
29
  return await this.creator.rename(key, name);
30
30
  }
31
31
 
32
- async delete(...keys: string[]): Promise<void> {
32
+ async delete(...keys: Key[]): Promise<void> {
33
33
  return await this.creator.delete(keys);
34
34
  }
35
35
 
@@ -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 } from "vitest";
10
+ import { describe, expect, it } from "vitest";
11
11
 
12
12
  import { QueryError } from "@/errors";
13
13
  import { ontology } from "@/ontology";
@@ -19,14 +19,14 @@ describe("Group", () => {
19
19
  describe("create", () => {
20
20
  it("should correctly create a group", async () => {
21
21
  const name = `group-${Math.random()}`;
22
- const g = await client.ontology.groups.create(ontology.Root, name);
22
+ const g = await client.ontology.groups.create(ontology.ROOT_ID, name);
23
23
  expect(g.name).toEqual(name);
24
24
  });
25
25
  });
26
26
  describe("rename", () => {
27
27
  it("should correctly rename a group", async () => {
28
28
  const name = `group-${Math.random()}`;
29
- const g = await client.ontology.groups.create(ontology.Root, name);
29
+ const g = await client.ontology.groups.create(ontology.ROOT_ID, name);
30
30
  const newName = `group-${Math.random()}`;
31
31
  await client.ontology.groups.rename(g.key, newName);
32
32
  const g2 = await client.ontology.retrieve(g.ontologyID);
@@ -36,7 +36,7 @@ describe("Group", () => {
36
36
  describe("delete", () => {
37
37
  it("should correctly delete the group", async () => {
38
38
  const name = `group-${Math.random()}`;
39
- const g = await client.ontology.groups.create(ontology.Root, name);
39
+ const g = await client.ontology.groups.create(ontology.ROOT_ID, name);
40
40
  await client.ontology.groups.delete(g.key);
41
41
  await expect(
42
42
  async () => await client.ontology.retrieve(g.ontologyID),
@@ -7,19 +7,22 @@
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 { type ontology } from "@/ontology";
11
- import { ontologyID as payloadOntologyID } from "@/ontology/group/payload";
10
+ import { type Key, type Name, ONTOLOGY_TYPE } from "@/ontology/group/payload";
11
+ import { ID as OntologyID } from "@/ontology/payload";
12
12
 
13
13
  export class Group {
14
- key: string;
15
- name: string;
14
+ key: Key;
15
+ name: Name;
16
16
 
17
- constructor(name: string, key: string) {
17
+ constructor(name: Name, key: Key) {
18
18
  this.key = key;
19
19
  this.name = name;
20
20
  }
21
21
 
22
- get ontologyID(): ontology.ID {
23
- return payloadOntologyID(this.key);
22
+ get ontologyID(): OntologyID {
23
+ return ontologyID(this.key);
24
24
  }
25
25
  }
26
+
27
+ export const ontologyID = (key: Key): OntologyID =>
28
+ new OntologyID({ type: ONTOLOGY_TYPE, key });
@@ -10,44 +10,22 @@
10
10
  import { toArray } from "@synnaxlabs/x/toArray";
11
11
  import { z } from "zod";
12
12
 
13
- import { ontology } from "@/ontology";
14
-
15
13
  export const keyZ = z.string().uuid();
16
14
  export type Key = z.infer<typeof keyZ>;
17
- export type Name = string;
15
+ export const nameZ = z.string();
16
+ export type Name = z.infer<typeof nameZ>;
18
17
  export type Keys = Key[];
19
18
  export type Names = Name[];
20
19
  export type Params = Key | Name | Keys | Names;
21
20
 
22
- export const groupZ = z.object({ key: keyZ, name: z.string() });
23
-
24
- export type Payload = z.infer<typeof groupZ>;
21
+ export const groupZ = z.object({ key: keyZ, name: nameZ });
22
+ export interface Payload extends z.infer<typeof groupZ> {}
25
23
 
26
24
  export type ParamAnalysisResult =
27
- | {
28
- single: true;
29
- variant: "keys";
30
- normalized: Keys;
31
- actual: Key;
32
- }
33
- | {
34
- single: true;
35
- variant: "names";
36
- normalized: Names;
37
- actual: Name;
38
- }
39
- | {
40
- single: false;
41
- variant: "keys";
42
- normalized: Keys;
43
- actual: Keys;
44
- }
45
- | {
46
- single: false;
47
- variant: "names";
48
- normalized: Names;
49
- actual: Names;
50
- };
25
+ | { single: true; variant: "keys"; normalized: Keys; actual: Key }
26
+ | { single: true; variant: "names"; normalized: Names; actual: Name }
27
+ | { single: false; variant: "keys"; normalized: Keys; actual: Keys }
28
+ | { single: false; variant: "names"; normalized: Names; actual: Names };
51
29
 
52
30
  export const analyzeParams = (groups: Params): ParamAnalysisResult => {
53
31
  const normal = toArray(groups) as Keys | Names;
@@ -58,10 +36,8 @@ export const analyzeParams = (groups: Params): ParamAnalysisResult => {
58
36
  variant: isKey ? "keys" : "names",
59
37
  normalized: normal,
60
38
  actual: groups,
61
- } as const as ParamAnalysisResult;
39
+ } as ParamAnalysisResult;
62
40
  };
63
41
 
64
- export const ONTOLOGY_TYPE: ontology.ResourceType = "group";
65
-
66
- export const ontologyID = (key: Key): ontology.ID =>
67
- new ontology.ID({ type: ONTOLOGY_TYPE, key });
42
+ export const ONTOLOGY_TYPE = "group";
43
+ export type OntologyType = typeof ONTOLOGY_TYPE;