@synnaxlabs/client 0.38.1 → 0.39.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 +3376 -3423
  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 +17 -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 +64 -39
  191. package/src/hardware/device/device.spec.ts +49 -33
  192. package/src/hardware/device/payload.ts +29 -29
  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
@@ -10,42 +10,38 @@
10
10
  import { sendRequired, type UnaryClient } from "@synnaxlabs/freighter";
11
11
  import { z } from "zod";
12
12
 
13
- import { groupZ, type Payload } from "@/ontology/group/payload";
14
- import { type ID, idZ } from "@/ontology/payload";
13
+ import {
14
+ groupZ,
15
+ type Key,
16
+ keyZ,
17
+ type Name,
18
+ nameZ,
19
+ type Payload,
20
+ } from "@/ontology/group/payload";
21
+ import { type ID as OntologyID, idZ as ontologyIDZ } from "@/ontology/payload";
15
22
 
16
- const resZ = z.object({
17
- group: groupZ,
18
- });
23
+ const resZ = z.object({ group: groupZ });
19
24
 
20
- const createReqZ = z.object({
21
- parent: idZ,
22
- key: z.string().uuid().optional(),
23
- name: z.string(),
24
- });
25
+ const createReqZ = z.object({ parent: ontologyIDZ, key: keyZ.optional(), name: nameZ });
25
26
 
26
- const renameReqZ = z.object({
27
- key: z.string(),
28
- name: z.string(),
29
- });
27
+ const renameReqZ = z.object({ key: keyZ, name: nameZ });
30
28
 
31
- const deleteReqZ = z.object({
32
- keys: z.array(z.string()),
33
- });
29
+ const deleteReqZ = z.object({ keys: z.array(keyZ) });
34
30
 
35
31
  export class Writer {
36
- private static readonly ENDPOINT = "/ontology/create-group";
37
- private static readonly ENDPOINT_RENAME = "/ontology/rename-group";
38
- private static readonly ENDPOINT_DELETE = "/ontology/delete-group";
32
+ private static readonly CREATE_ENDPOINT = "/ontology/create-group";
33
+ private static readonly RENAME_ENDPOINT = "/ontology/rename-group";
34
+ private static readonly DELETE_ENDPOINT = "/ontology/delete-group";
39
35
  client: UnaryClient;
40
36
 
41
37
  constructor(client: UnaryClient) {
42
38
  this.client = client;
43
39
  }
44
40
 
45
- async create(parent: ID, name: string, key?: string): Promise<Payload> {
41
+ async create(parent: OntologyID, name: Name, key?: Key): Promise<Payload> {
46
42
  const res = await sendRequired(
47
43
  this.client,
48
- Writer.ENDPOINT,
44
+ Writer.CREATE_ENDPOINT,
49
45
  { parent, name, key },
50
46
  createReqZ,
51
47
  resZ,
@@ -53,20 +49,20 @@ export class Writer {
53
49
  return res.group;
54
50
  }
55
51
 
56
- async rename(key: string, name: string): Promise<void> {
52
+ async rename(key: Key, name: Name): Promise<void> {
57
53
  await sendRequired(
58
54
  this.client,
59
- Writer.ENDPOINT_RENAME,
55
+ Writer.RENAME_ENDPOINT,
60
56
  { key, name },
61
57
  renameReqZ,
62
58
  z.object({}),
63
59
  );
64
60
  }
65
61
 
66
- async delete(keys: string[]): Promise<void> {
62
+ async delete(keys: Key[]): Promise<void> {
67
63
  await sendRequired(
68
64
  this.client,
69
- Writer.ENDPOINT_DELETE,
65
+ Writer.DELETE_ENDPOINT,
70
66
  { keys },
71
67
  deleteReqZ,
72
68
  z.object({}),
@@ -20,13 +20,13 @@ describe("Ontology", () => {
20
20
  describe("retrieve", () => {
21
21
  test("retrieve", async () => {
22
22
  const name = randomName();
23
- const g = await client.ontology.groups.create(ontology.Root, name);
23
+ const g = await client.ontology.groups.create(ontology.ROOT_ID, name);
24
24
  const g2 = await client.ontology.retrieve(g.ontologyID);
25
25
  expect(g2.name).toEqual(name);
26
26
  });
27
27
  test("retrieve children", async () => {
28
28
  const name = randomName();
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 name2 = randomName();
31
31
  await client.ontology.groups.create(g.ontologyID, name2);
32
32
  const children = await client.ontology.retrieveChildren(g.ontologyID);
@@ -35,7 +35,7 @@ describe("Ontology", () => {
35
35
  });
36
36
  test("retrieve parents", async () => {
37
37
  const name = randomName();
38
- const g = await client.ontology.groups.create(ontology.Root, name);
38
+ const g = await client.ontology.groups.create(ontology.ROOT_ID, name);
39
39
  const name2 = randomName();
40
40
  const g2 = await client.ontology.groups.create(g.ontologyID, name2);
41
41
  const parents = await client.ontology.retrieveParents(g2.ontologyID);
@@ -46,7 +46,7 @@ describe("Ontology", () => {
46
46
  describe("page", () => {
47
47
  it("should return a page of resources", async () => {
48
48
  for (let i = 0; i < 10; i++)
49
- await client.ontology.groups.create(ontology.Root, randomName());
49
+ await client.ontology.groups.create(ontology.ROOT_ID, randomName());
50
50
  const page = await client.ontology.page(0, 5);
51
51
  expect(page.length).toEqual(5);
52
52
  const page2 = await client.ontology.page(5, 5);
@@ -60,9 +60,9 @@ describe("Ontology", () => {
60
60
  describe("write", () => {
61
61
  test("add children", async () => {
62
62
  const name = randomName();
63
- const g = await client.ontology.groups.create(ontology.Root, name);
63
+ const g = await client.ontology.groups.create(ontology.ROOT_ID, name);
64
64
  const name2 = randomName();
65
- const g2 = await client.ontology.groups.create(ontology.Root, name2);
65
+ const g2 = await client.ontology.groups.create(ontology.ROOT_ID, name2);
66
66
  await client.ontology.addChildren(g.ontologyID, g2.ontologyID);
67
67
  const children = await client.ontology.retrieveChildren(g.ontologyID);
68
68
  expect(children.length).toEqual(1);
@@ -70,9 +70,9 @@ describe("Ontology", () => {
70
70
  });
71
71
  test("remove children", async () => {
72
72
  const name = randomName();
73
- const g = await client.ontology.groups.create(ontology.Root, name);
73
+ const g = await client.ontology.groups.create(ontology.ROOT_ID, name);
74
74
  const name2 = randomName();
75
- const g2 = await client.ontology.groups.create(ontology.Root, name2);
75
+ const g2 = await client.ontology.groups.create(ontology.ROOT_ID, name2);
76
76
  await client.ontology.addChildren(g.ontologyID, g2.ontologyID);
77
77
  await client.ontology.removeChildren(g.ontologyID, g2.ontologyID);
78
78
  const children = await client.ontology.retrieveChildren(g.ontologyID);
@@ -80,15 +80,15 @@ describe("Ontology", () => {
80
80
  });
81
81
  test("move children", async () => {
82
82
  const name = randomName();
83
- const g = await client.ontology.groups.create(ontology.Root, name);
83
+ const g = await client.ontology.groups.create(ontology.ROOT_ID, name);
84
84
  const name2 = randomName();
85
- const g2 = await client.ontology.groups.create(ontology.Root, name2);
86
- const oldRootLength = (await client.ontology.retrieveChildren(ontology.Root))
85
+ const g2 = await client.ontology.groups.create(ontology.ROOT_ID, name2);
86
+ const oldRootLength = (await client.ontology.retrieveChildren(ontology.ROOT_ID))
87
87
  .length;
88
- await client.ontology.moveChildren(ontology.Root, g.ontologyID, g2.ontologyID);
88
+ await client.ontology.moveChildren(ontology.ROOT_ID, g.ontologyID, g2.ontologyID);
89
89
  const children = await client.ontology.retrieveChildren(g.ontologyID);
90
90
  expect(children.length).toEqual(1);
91
- const newRootLength = (await client.ontology.retrieveChildren(ontology.Root))
91
+ const newRootLength = (await client.ontology.retrieveChildren(ontology.ROOT_ID))
92
92
  .length;
93
93
  expect(newRootLength).toEqual(oldRootLength - 1);
94
94
  });
@@ -107,7 +107,7 @@ describe("Ontology", () => {
107
107
  const p = new Promise<ontology.ResourceChange[]>((resolve) =>
108
108
  change.resources.onChange((changes) => resolve(changes)),
109
109
  );
110
- await client.ontology.groups.create(ontology.Root, randomName());
110
+ await client.ontology.groups.create(ontology.ROOT_ID, randomName());
111
111
  const c = await p;
112
112
  expect(c.length).toBeGreaterThan(0);
113
113
  await change.close();
@@ -119,7 +119,7 @@ describe("Ontology", () => {
119
119
  resolve(changes);
120
120
  });
121
121
  });
122
- await client.ontology.groups.create(ontology.Root, randomName());
122
+ await client.ontology.groups.create(ontology.ROOT_ID, randomName());
123
123
  const c = await p;
124
124
  expect(c.length).toBeGreaterThan(0);
125
125
  await change.close();
@@ -10,43 +10,65 @@
10
10
  import { type change, type UnknownRecord } from "@synnaxlabs/x";
11
11
  import { z } from "zod";
12
12
 
13
+ import {
14
+ ALLOW_ALL_ONTOLOGY_TYPE as ALLOW_ALL_TYPE,
15
+ ONTOLOGY_TYPE as POLICY_TYPE,
16
+ } from "@/access/policy/ontology";
17
+ import { ONTOLOGY_TYPE as CHANNEL_TYPE } from "@/channel/payload";
18
+ import { ONTOLOGY_TYPE as FRAMER_TYPE } from "@/framer/frame";
19
+ import { ONTOLOGY_TYPE as DEVICE_TYPE } from "@/hardware/device/payload";
20
+ import { ONTOLOGY_TYPE as RACK_TYPE } from "@/hardware/rack/payload";
21
+ import { ONTOLOGY_TYPE as TASK_TYPE } from "@/hardware/task/payload";
22
+ import { ONTOLOGY_TYPE as LABEL_TYPE } from "@/label/payload";
23
+ import { ONTOLOGY_TYPE as GROUP_TYPE } from "@/ontology/group/payload";
24
+ import {
25
+ ALIAS_ONTOLOGY_TYPE as RANGE_ALIAS_TYPE,
26
+ ONTOLOGY_TYPE as RANGE_TYPE,
27
+ } from "@/ranger/payload";
28
+ import { ONTOLOGY_TYPE as USER_TYPE } from "@/user/payload";
29
+ import { ONTOLOGY_TYPE as LINE_PLOT_TYPE } from "@/workspace/lineplot/payload";
30
+ import { ONTOLOGY_TYPE as LOG_TYPE } from "@/workspace/log/payload";
31
+ import { ONTOLOGY_TYPE as WORKSPACE_TYPE } from "@/workspace/payload";
32
+ import { ONTOLOGY_TYPE as SCHEMATIC_TYPE } from "@/workspace/schematic/payload";
33
+ import { ONTOLOGY_TYPE as TABLE_TYPE } from "@/workspace/table/payload";
34
+
13
35
  export type ResourceChange = change.Change<ID, Resource>;
14
- export type ResourceSet = change.Set<ID, Resource>;
15
- export type ResourceDelete = change.Delete<ID, Resource>;
36
+ export interface ResourceSet extends change.Set<ID, Resource> {}
37
+ export interface ResourceDelete extends change.Delete<ID, Resource> {}
16
38
  export type RelationshipChange = change.Change<Relationship, undefined>;
17
- export type RelationshipSet = change.Set<Relationship, undefined>;
18
- export type RelationshipDelete = change.Delete<Relationship, undefined>;
19
-
20
- export const resourceTypeZ = z.union([
21
- z.literal("label"),
22
- z.literal("log"),
23
- z.literal("allow_all"),
24
- z.literal("builtin"),
25
- z.literal("cluster"),
26
- z.literal("channel"),
27
- z.literal("node"),
28
- z.literal("group"),
29
- z.literal("range"),
30
- z.literal("framer"),
31
- z.literal("range-alias"),
32
- z.literal("user"),
33
- z.literal("workspace"),
34
- z.literal("schematic"),
35
- z.literal("lineplot"),
36
- z.literal("rack"),
37
- z.literal("device"),
38
- z.literal("task"),
39
- z.literal("policy"),
40
- z.literal("table"),
39
+ export interface RelationshipSet extends change.Set<Relationship, undefined> {}
40
+ export interface RelationshipDelete extends change.Delete<Relationship, undefined> {}
41
+
42
+ export const BUILTIN_TYPE = "builtin";
43
+ export const CLUSTER_TYPE = "cluster";
44
+ export const NODE_TYPE = "node";
45
+
46
+ export const resourceTypeZ = z.enum([
47
+ LABEL_TYPE,
48
+ LOG_TYPE,
49
+ ALLOW_ALL_TYPE,
50
+ BUILTIN_TYPE,
51
+ CLUSTER_TYPE,
52
+ CHANNEL_TYPE,
53
+ NODE_TYPE,
54
+ GROUP_TYPE,
55
+ RANGE_TYPE,
56
+ FRAMER_TYPE,
57
+ RANGE_ALIAS_TYPE,
58
+ USER_TYPE,
59
+ WORKSPACE_TYPE,
60
+ SCHEMATIC_TYPE,
61
+ LINE_PLOT_TYPE,
62
+ RACK_TYPE,
63
+ DEVICE_TYPE,
64
+ TASK_TYPE,
65
+ POLICY_TYPE,
66
+ TABLE_TYPE,
41
67
  ]);
42
68
  export type ResourceType = z.infer<typeof resourceTypeZ>;
43
69
 
44
- export const BUILTIN_TYPE: ResourceType = "builtin";
45
- export const CLUSTER_TYPE: ResourceType = "cluster";
46
- export const NODE_TYPE: ResourceType = "node";
47
-
48
70
  export const idZ = z.object({ type: resourceTypeZ, key: z.string() });
49
- export type IDPayload = z.infer<typeof idZ>;
71
+ export interface IDPayload extends z.infer<typeof idZ> {}
50
72
 
51
73
  export const stringIDZ = z.string().transform((v) => {
52
74
  const [type, key] = v.split(":");
@@ -95,19 +117,18 @@ export class ID {
95
117
  static readonly z = z.union([z.instanceof(ID), crudeIDZ.transform((v) => new ID(v))]);
96
118
  }
97
119
 
98
- export const Root = new ID({ type: BUILTIN_TYPE, key: "root" });
120
+ export const ROOT_ID = new ID({ type: BUILTIN_TYPE, key: "root" });
99
121
 
100
122
  export const schemaFieldZ = z.object({ type: z.number() });
101
-
102
- export type SchemaField = z.infer<typeof schemaFieldZ>;
123
+ export interface SchemaField extends z.infer<typeof schemaFieldZ> {}
103
124
 
104
125
  export const schemaZ = z.object({
105
126
  type: resourceTypeZ,
106
127
  fields: z.record(schemaFieldZ),
107
128
  });
108
- export type Schema = z.infer<typeof schemaZ>;
129
+ export interface Schema extends z.infer<typeof schemaZ> {}
109
130
 
110
- export const resourceSchemaZ = z
131
+ export const resourceZ = z
111
132
  .object({
112
133
  id: ID.z,
113
134
  name: z.string(),
@@ -115,16 +136,19 @@ export const resourceSchemaZ = z
115
136
  data: z.record(z.unknown()).optional().nullable(),
116
137
  })
117
138
  .transform((resource) => ({ key: resource.id.toString(), ...resource }));
139
+ export interface Resource<T extends UnknownRecord = UnknownRecord>
140
+ extends Omit<z.output<typeof resourceZ>, "data"> {
141
+ data?: T | null;
142
+ }
118
143
 
119
- export type Resource<T extends UnknownRecord = UnknownRecord> = Omit<
120
- z.output<typeof resourceSchemaZ>,
121
- "data"
122
- > & { data?: T | null };
123
-
124
- export type RelationshipDirection = "from" | "to";
144
+ export const TO_RELATIONSHIP_DIRECTION = "to";
145
+ export const FROM_RELATIONSHIP_DIRECTION = "from";
146
+ export type RelationshipDirection =
147
+ | typeof TO_RELATIONSHIP_DIRECTION
148
+ | typeof FROM_RELATIONSHIP_DIRECTION;
125
149
 
126
150
  export const relationshipSchemaZ = z.object({ from: ID.z, type: z.string(), to: ID.z });
127
- export type Relationship = z.infer<typeof relationshipSchemaZ>;
151
+ export interface Relationship extends z.infer<typeof relationshipSchemaZ> {}
128
152
 
129
153
  export const parseRelationship = (str: string): Relationship => {
130
154
  const [from, type, to] = str.split("->");
@@ -12,22 +12,15 @@ import { z } from "zod";
12
12
 
13
13
  import { type CrudeID, ID, idZ } from "@/ontology/payload";
14
14
 
15
- const ENDPOINTS = {
16
- ADD_CHILDREN: "/ontology/add-children",
17
- REMOVE_CHILDREN: "/ontology/remove-children",
18
- MOVE_CHILDREN: "/ontology/move-children",
19
- };
15
+ const ADD_CHILDREN_ENDPOINT = "/ontology/add-children";
16
+ const REMOVE_CHILDREN_ENDPOINT = "/ontology/remove-children";
17
+ const MOVE_CHILDREN_ENDPOINT = "/ontology/move-children";
20
18
 
21
- const addRemoveChildrenReqZ = z.object({
22
- id: idZ,
23
- children: idZ.array(),
24
- });
19
+ const addRemoveChildrenReqZ = z.object({ id: idZ, children: idZ.array() });
25
20
 
26
- const moveChildrenReqZ = z.object({
27
- from: idZ,
28
- to: idZ,
29
- children: idZ.array(),
30
- });
21
+ const moveChildrenReqZ = z.object({ from: idZ, to: idZ, children: idZ.array() });
22
+
23
+ const emptyResZ = z.object({});
31
24
 
32
25
  export class Writer {
33
26
  client: UnaryClient;
@@ -37,22 +30,22 @@ export class Writer {
37
30
  }
38
31
 
39
32
  async addChildren(id: CrudeID, ...children: CrudeID[]): Promise<void> {
40
- await sendRequired<typeof addRemoveChildrenReqZ, z.ZodTypeAny>(
33
+ await sendRequired<typeof addRemoveChildrenReqZ, typeof emptyResZ>(
41
34
  this.client,
42
- ENDPOINTS.ADD_CHILDREN,
35
+ ADD_CHILDREN_ENDPOINT,
43
36
  { id: new ID(id).payload, children: children.map((c) => new ID(c).payload) },
44
37
  addRemoveChildrenReqZ,
45
- z.object({}),
38
+ emptyResZ,
46
39
  );
47
40
  }
48
41
 
49
42
  async removeChildren(id: CrudeID, ...children: CrudeID[]): Promise<void> {
50
- await sendRequired<typeof addRemoveChildrenReqZ, z.ZodTypeAny>(
43
+ await sendRequired<typeof addRemoveChildrenReqZ, typeof emptyResZ>(
51
44
  this.client,
52
- ENDPOINTS.REMOVE_CHILDREN,
45
+ REMOVE_CHILDREN_ENDPOINT,
53
46
  { id: new ID(id).payload, children: children.map((c) => new ID(c).payload) },
54
47
  addRemoveChildrenReqZ,
55
- z.object({}),
48
+ emptyResZ,
56
49
  );
57
50
  }
58
51
 
@@ -66,12 +59,12 @@ export class Writer {
66
59
  to: new ID(to).payload,
67
60
  children: children.map((c) => new ID(c).payload),
68
61
  };
69
- await sendRequired(
62
+ await sendRequired<typeof moveChildrenReqZ, typeof emptyResZ>(
70
63
  this.client,
71
- ENDPOINTS.MOVE_CHILDREN,
64
+ MOVE_CHILDREN_ENDPOINT,
72
65
  req,
73
66
  moveChildrenReqZ,
74
- z.object({}),
67
+ emptyResZ,
75
68
  );
76
69
  }
77
70
  }
@@ -11,73 +11,60 @@ import { sendRequired, type UnaryClient } from "@synnaxlabs/freighter";
11
11
  import { type change } from "@synnaxlabs/x/change";
12
12
  import { z } from "zod";
13
13
 
14
- import { type channel } from "@/channel";
15
- import { type Key as ChannelKey, keyZ as channelKeyZ } from "@/channel/payload";
16
- import { type Client as FrameClient } from "@/framer/client";
14
+ import { channel } from "@/channel";
15
+ import { type framer } from "@/framer";
17
16
  import { type Key, keyZ } from "@/ranger/payload";
18
17
  import { signals } from "@/signals";
19
18
 
20
- export const ALIAS_SET_NAME = "sy_range_alias_set";
21
- export const ALIAS_DELETE_NAME = "sy_range_alias_delete";
19
+ export const SET_ALIAS_CHANNEL_NAME = "sy_range_alias_set";
20
+ export const DELETE_ALIAS_CHANNEL_NAME = "sy_range_alias_delete";
22
21
 
23
- const resolveReqZ = z.object({
24
- range: keyZ,
25
- aliases: z.string().array(),
26
- });
22
+ const resolveReqZ = z.object({ range: keyZ, aliases: z.string().array() });
27
23
 
28
- const resolveResZ = z.object({
29
- aliases: z.record(z.string(), channelKeyZ),
30
- });
24
+ const resolveResZ = z.object({ aliases: z.record(z.string(), channel.keyZ) });
31
25
 
32
26
  const setReqZ = z.object({
33
27
  range: keyZ,
34
- aliases: z.record(channelKeyZ.or(z.string()), z.string()),
28
+ aliases: z.record(channel.keyZ.or(z.string()), z.string()),
35
29
  });
36
30
 
37
31
  const setResZ = z.unknown();
38
32
 
39
- const deleteReqZ = z.object({
40
- range: keyZ,
41
- channels: channelKeyZ.array(),
42
- });
33
+ const deleteReqZ = z.object({ range: keyZ, channels: channel.keyZ.array() });
43
34
 
44
35
  const deleteResZ = z.unknown();
45
36
 
46
- const listReqZ = z.object({
47
- range: keyZ,
48
- });
37
+ const listReqZ = z.object({ range: keyZ });
49
38
 
50
- const listResZ = z.object({
51
- aliases: z.record(z.string(), z.string()),
52
- });
39
+ const listResZ = z.object({ aliases: z.record(z.string(), z.string()) });
53
40
 
54
41
  export class Aliaser {
55
42
  private static readonly SET_ENDPOINT = "/range/alias/set";
56
43
  private static readonly RESOLVE_ENDPOINT = "/range/alias/resolve";
57
44
  private static readonly LIST_ENDPOINT = "/range/alias/list";
58
45
  private static readonly DELETE_ENDPOINT = "/range/alias/delete";
59
- private readonly frameClient: FrameClient;
60
- private readonly cache = new Map<string, ChannelKey>();
46
+ private readonly frameClient: framer.Client;
47
+ private readonly cache = new Map<string, channel.Key>();
61
48
  private readonly client: UnaryClient;
62
49
  private readonly rangeKey: Key;
63
50
 
64
- constructor(rangeKey: Key, frameClient: FrameClient, client: UnaryClient) {
51
+ constructor(rangeKey: Key, frameClient: framer.Client, client: UnaryClient) {
65
52
  this.rangeKey = rangeKey;
66
53
  this.cache = new Map();
67
54
  this.client = client;
68
55
  this.frameClient = frameClient;
69
56
  }
70
57
 
71
- resolve(aliases: string): Promise<ChannelKey>;
58
+ resolve(aliases: string): Promise<channel.Key>;
72
59
 
73
- resolve(aliases: string[]): Promise<Record<string, ChannelKey>>;
60
+ resolve(aliases: string[]): Promise<Record<string, channel.Key>>;
74
61
 
75
62
  async resolve(
76
63
  aliases: string | string[],
77
- ): Promise<ChannelKey | Record<string, ChannelKey>> {
64
+ ): Promise<channel.Key | Record<string, channel.Key>> {
78
65
  const toFetch: string[] = [];
79
66
  const isSingle = typeof aliases === "string";
80
- const cached: Record<string, ChannelKey> = {};
67
+ const cached: Record<string, channel.Key> = {};
81
68
  if (isSingle) {
82
69
  const c = this.cache.get(aliases);
83
70
  if (c != null) return c;
@@ -100,7 +87,7 @@ export class Aliaser {
100
87
  return isSingle ? res.aliases[toFetch[0]] : { ...cached, ...res.aliases };
101
88
  }
102
89
 
103
- async set(aliases: Record<ChannelKey, string>): Promise<void> {
90
+ async set(aliases: Record<channel.Key, string>): Promise<void> {
104
91
  await sendRequired<typeof setReqZ, typeof setResZ>(
105
92
  this.client,
106
93
  Aliaser.SET_ENDPOINT,
@@ -110,7 +97,7 @@ export class Aliaser {
110
97
  );
111
98
  }
112
99
 
113
- async list(): Promise<Record<ChannelKey, string>> {
100
+ async list(): Promise<Record<channel.Key, string>> {
114
101
  return (
115
102
  await sendRequired<typeof listReqZ, typeof listResZ>(
116
103
  this.client,
@@ -122,7 +109,7 @@ export class Aliaser {
122
109
  ).aliases;
123
110
  }
124
111
 
125
- async delete(aliases: ChannelKey[]): Promise<void> {
112
+ async delete(aliases: channel.Key[]): Promise<void> {
126
113
  await sendRequired<typeof deleteReqZ, typeof deleteResZ>(
127
114
  this.client,
128
115
  Aliaser.DELETE_ENDPOINT,
@@ -135,8 +122,8 @@ export class Aliaser {
135
122
  async openChangeTracker(): Promise<signals.Observable<string, Alias>> {
136
123
  return await signals.openObservable<string, Alias>(
137
124
  this.frameClient,
138
- ALIAS_SET_NAME,
139
- ALIAS_DELETE_NAME,
125
+ SET_ALIAS_CHANNEL_NAME,
126
+ DELETE_ALIAS_CHANNEL_NAME,
140
127
  decodeAliasChanges(this.rangeKey),
141
128
  );
142
129
  }
@@ -150,13 +137,9 @@ export interface Alias {
150
137
 
151
138
  export type AliasChange = change.Change<string, Alias>;
152
139
 
153
- const aliasZ = z.object({
154
- range: keyZ,
155
- channel: channelKeyZ,
156
- alias: z.string(),
157
- });
140
+ const aliasZ = z.object({ range: keyZ, channel: channel.keyZ, alias: z.string() });
158
141
 
159
- const aliasSeparator = "---";
142
+ const separator = "---";
160
143
 
161
144
  const decodeAliasChanges =
162
145
  (rangeKey: Key): signals.Decoder<string, Alias> =>
@@ -164,7 +147,7 @@ const decodeAliasChanges =
164
147
  if (variant === "delete")
165
148
  return data
166
149
  .toStrings()
167
- .filter((k) => k.split(aliasSeparator)[0] === rangeKey)
150
+ .filter((k) => k.split(separator)[0] === rangeKey)
168
151
  .map((alias) => ({
169
152
  variant,
170
153
  key: alias,