@synnaxlabs/client 0.45.1 → 0.46.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (164) hide show
  1. package/.turbo/turbo-build.log +7 -7
  2. package/dist/access/policy/client.d.ts +38 -26
  3. package/dist/access/policy/client.d.ts.map +1 -1
  4. package/dist/access/policy/payload.d.ts +22 -10
  5. package/dist/access/policy/payload.d.ts.map +1 -1
  6. package/dist/arc/client.d.ts +72 -0
  7. package/dist/arc/client.d.ts.map +1 -0
  8. package/dist/arc/external.d.ts +3 -0
  9. package/dist/arc/external.d.ts.map +1 -0
  10. package/dist/arc/index.d.ts +2 -0
  11. package/dist/arc/index.d.ts.map +1 -0
  12. package/dist/arc/payload.d.ts +155 -0
  13. package/dist/arc/payload.d.ts.map +1 -0
  14. package/dist/channel/client.d.ts +2 -3
  15. package/dist/channel/client.d.ts.map +1 -1
  16. package/dist/channel/payload.d.ts +23 -63
  17. package/dist/channel/payload.d.ts.map +1 -1
  18. package/dist/channel/retriever.d.ts.map +1 -1
  19. package/dist/client.cjs +44 -25
  20. package/dist/client.d.ts +5 -1
  21. package/dist/client.d.ts.map +1 -1
  22. package/dist/client.js +7449 -4753
  23. package/dist/framer/client.d.ts +2 -2
  24. package/dist/framer/client.d.ts.map +1 -1
  25. package/dist/framer/deleter.d.ts +2 -2
  26. package/dist/framer/frame.d.ts +2 -2
  27. package/dist/framer/streamer.d.ts +42 -56
  28. package/dist/framer/streamer.d.ts.map +1 -1
  29. package/dist/framer/writer.d.ts +45 -43
  30. package/dist/framer/writer.d.ts.map +1 -1
  31. package/dist/hardware/device/client.d.ts +5 -6
  32. package/dist/hardware/device/client.d.ts.map +1 -1
  33. package/dist/hardware/device/payload.d.ts +83 -18
  34. package/dist/hardware/device/payload.d.ts.map +1 -1
  35. package/dist/hardware/rack/client.d.ts +4 -5
  36. package/dist/hardware/rack/client.d.ts.map +1 -1
  37. package/dist/hardware/rack/payload.d.ts +81 -17
  38. package/dist/hardware/rack/payload.d.ts.map +1 -1
  39. package/dist/hardware/task/client.d.ts +61 -12
  40. package/dist/hardware/task/client.d.ts.map +1 -1
  41. package/dist/hardware/task/payload.d.ts +18 -51
  42. package/dist/hardware/task/payload.d.ts.map +1 -1
  43. package/dist/index.d.ts +3 -1
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/label/client.d.ts +14 -9
  46. package/dist/label/client.d.ts.map +1 -1
  47. package/dist/label/payload.d.ts +10 -11
  48. package/dist/label/payload.d.ts.map +1 -1
  49. package/dist/ontology/client.d.ts +7 -3
  50. package/dist/ontology/client.d.ts.map +1 -1
  51. package/dist/ontology/group/client.d.ts +45 -9
  52. package/dist/ontology/group/client.d.ts.map +1 -1
  53. package/dist/ontology/group/external.d.ts +0 -1
  54. package/dist/ontology/group/external.d.ts.map +1 -1
  55. package/dist/ontology/group/payload.d.ts +3 -1
  56. package/dist/ontology/group/payload.d.ts.map +1 -1
  57. package/dist/ontology/payload.d.ts +30 -17
  58. package/dist/ontology/payload.d.ts.map +1 -1
  59. package/dist/ontology/writer.d.ts +161 -0
  60. package/dist/ontology/writer.d.ts.map +1 -1
  61. package/dist/ranger/alias.d.ts +1 -1
  62. package/dist/ranger/alias.d.ts.map +1 -1
  63. package/dist/ranger/client.d.ts +9 -8
  64. package/dist/ranger/client.d.ts.map +1 -1
  65. package/dist/ranger/kv.d.ts.map +1 -1
  66. package/dist/ranger/payload.d.ts +5 -5
  67. package/dist/ranger/payload.d.ts.map +1 -1
  68. package/dist/ranger/writer.d.ts +6 -4
  69. package/dist/ranger/writer.d.ts.map +1 -1
  70. package/dist/status/client.d.ts +63 -0
  71. package/dist/status/client.d.ts.map +1 -0
  72. package/dist/status/external.d.ts +3 -0
  73. package/dist/status/external.d.ts.map +1 -0
  74. package/dist/status/index.d.ts +2 -0
  75. package/dist/status/index.d.ts.map +1 -0
  76. package/dist/status/payload.d.ts +32 -0
  77. package/dist/status/payload.d.ts.map +1 -0
  78. package/dist/status/status.spec.d.ts +2 -0
  79. package/dist/status/status.spec.d.ts.map +1 -0
  80. package/dist/user/client.d.ts.map +1 -1
  81. package/dist/user/retriever.d.ts.map +1 -1
  82. package/dist/workspace/client.d.ts +11 -6
  83. package/dist/workspace/client.d.ts.map +1 -1
  84. package/dist/workspace/lineplot/client.d.ts +28 -5
  85. package/dist/workspace/lineplot/client.d.ts.map +1 -1
  86. package/dist/workspace/lineplot/index.d.ts +1 -1
  87. package/dist/workspace/log/client.d.ts +28 -5
  88. package/dist/workspace/log/client.d.ts.map +1 -1
  89. package/dist/workspace/schematic/client.d.ts +35 -6
  90. package/dist/workspace/schematic/client.d.ts.map +1 -1
  91. package/dist/workspace/schematic/symbol/client.d.ts +6 -7
  92. package/dist/workspace/schematic/symbol/client.d.ts.map +1 -1
  93. package/dist/workspace/table/client.d.ts +28 -5
  94. package/dist/workspace/table/client.d.ts.map +1 -1
  95. package/examples/node/package-lock.json +30 -95
  96. package/examples/node/package.json +1 -1
  97. package/package.json +9 -9
  98. package/src/access/policy/client.ts +5 -6
  99. package/src/access/policy/payload.ts +4 -4
  100. package/src/access/policy/policy.spec.ts +4 -4
  101. package/src/arc/client.ts +117 -0
  102. package/src/{util/zod.ts → arc/external.ts} +2 -7
  103. package/src/arc/index.ts +10 -0
  104. package/src/arc/payload.ts +69 -0
  105. package/src/channel/client.ts +3 -4
  106. package/src/channel/payload.ts +4 -6
  107. package/src/channel/retriever.ts +2 -2
  108. package/src/client.ts +8 -2
  109. package/src/errors.spec.ts +1 -1
  110. package/src/framer/client.ts +4 -3
  111. package/src/framer/codec.spec.ts +1 -1
  112. package/src/hardware/device/client.ts +6 -8
  113. package/src/hardware/device/payload.ts +7 -6
  114. package/src/hardware/rack/client.ts +6 -8
  115. package/src/hardware/rack/payload.ts +2 -1
  116. package/src/hardware/task/client.ts +140 -100
  117. package/src/hardware/task/payload.ts +4 -4
  118. package/src/hardware/task/task.spec.ts +9 -2
  119. package/src/index.ts +3 -1
  120. package/src/label/client.ts +5 -8
  121. package/src/label/payload.ts +6 -11
  122. package/src/ontology/client.ts +3 -3
  123. package/src/ontology/group/client.ts +51 -18
  124. package/src/ontology/group/external.ts +0 -1
  125. package/src/ontology/group/group.spec.ts +6 -5
  126. package/src/ontology/group/payload.ts +5 -1
  127. package/src/ontology/ontology.spec.ts +88 -21
  128. package/src/ontology/payload.ts +15 -6
  129. package/src/ontology/writer.ts +3 -5
  130. package/src/ranger/alias.ts +2 -2
  131. package/src/ranger/client.ts +7 -3
  132. package/src/ranger/kv.ts +1 -2
  133. package/src/ranger/payload.ts +13 -1
  134. package/src/ranger/ranger.spec.ts +65 -1
  135. package/src/status/client.ts +129 -0
  136. package/src/status/external.ts +11 -0
  137. package/src/status/index.ts +10 -0
  138. package/src/status/payload.ts +35 -0
  139. package/src/status/status.spec.ts +352 -0
  140. package/src/user/client.ts +1 -2
  141. package/src/user/payload.ts +1 -1
  142. package/src/user/retriever.ts +2 -2
  143. package/src/user/user.spec.ts +41 -41
  144. package/src/workspace/client.ts +18 -15
  145. package/src/workspace/lineplot/client.ts +27 -13
  146. package/src/workspace/lineplot/index.ts +1 -1
  147. package/src/workspace/lineplot/lineplot.spec.ts +13 -10
  148. package/src/workspace/log/client.ts +26 -12
  149. package/src/workspace/log/log.spec.ts +13 -10
  150. package/src/workspace/payload.ts +1 -1
  151. package/src/workspace/schematic/client.ts +42 -17
  152. package/src/workspace/schematic/schematic.spec.ts +29 -25
  153. package/src/workspace/schematic/symbol/client.spec.ts +27 -24
  154. package/src/workspace/schematic/symbol/client.ts +6 -9
  155. package/src/workspace/table/client.ts +26 -12
  156. package/src/workspace/table/table.spec.ts +13 -10
  157. package/dist/ontology/group/group.d.ts +0 -10
  158. package/dist/ontology/group/group.d.ts.map +0 -1
  159. package/dist/ontology/group/writer.d.ts +0 -14
  160. package/dist/ontology/group/writer.d.ts.map +0 -1
  161. package/dist/util/zod.d.ts +0 -3
  162. package/dist/util/zod.d.ts.map +0 -1
  163. package/src/ontology/group/group.ts +0 -27
  164. package/src/ontology/group/writer.ts +0 -71
@@ -12,7 +12,7 @@ import { array, type record } from "@synnaxlabs/x";
12
12
  import { z } from "zod";
13
13
 
14
14
  import { type ontology } from "@/ontology";
15
- import { nullableArrayZ } from "@/util/zod";
15
+ import { checkForMultipleOrNoResults } from "@/util/retrieve";
16
16
  import { type Key as WorkspaceKey, keyZ as workspaceKeyZ } from "@/workspace/payload";
17
17
  import {
18
18
  type Key,
@@ -33,15 +33,36 @@ const SET_DATA_ENDPOINT = "/workspace/schematic/set-data";
33
33
  const DELETE_ENDPOINT = "/workspace/schematic/delete";
34
34
  const COPY_ENDPOINT = "/workspace/schematic/copy";
35
35
 
36
- const retrieveReqZ = z.object({ keys: keyZ.array() });
37
- const createReqZ = z.object({ workspace: workspaceKeyZ, schematics: newZ.array() });
38
36
  const renameReqZ = z.object({ key: keyZ, name: z.string() });
37
+
39
38
  const setDataReqZ = z.object({ key: keyZ, data: z.string() });
40
39
  const deleteReqZ = z.object({ keys: keyZ.array() });
41
- const copyReqZ = z.object({ key: keyZ, name: z.string(), snapshot: z.boolean() });
42
40
 
43
- const retrieveResZ = z.object({ schematics: nullableArrayZ(remoteZ) });
41
+ const copyReqZ = z.object({
42
+ key: keyZ,
43
+ name: z.string(),
44
+ snapshot: z.boolean(),
45
+ });
46
+
47
+ const retrieveReqZ = z.object({ keys: keyZ.array() });
48
+ const singleRetrieveArgsZ = z
49
+ .object({ key: keyZ })
50
+ .transform(({ key }) => ({ keys: [key] }));
51
+
52
+ export const retrieveArgsZ = z.union([singleRetrieveArgsZ, retrieveReqZ]);
53
+ export type RetrieveArgs = z.input<typeof retrieveArgsZ>;
54
+ export type RetrieveSingleParams = z.input<typeof singleRetrieveArgsZ>;
55
+ export type RetrieveMultipleParams = z.input<typeof retrieveReqZ>;
56
+ export type CopyArgs = z.input<typeof copyReqZ>;
57
+
58
+ const retrieveResZ = z.object({ schematics: array.nullableZ(remoteZ) });
59
+
60
+ const createReqZ = z.object({
61
+ workspace: workspaceKeyZ,
62
+ schematics: newZ.array(),
63
+ });
44
64
  const createResZ = z.object({ schematics: remoteZ.array() });
65
+
45
66
  const copyResZ = z.object({ schematic: schematicZ });
46
67
  const emptyResZ = z.object({});
47
68
 
@@ -91,22 +112,23 @@ export class Client {
91
112
  );
92
113
  }
93
114
 
94
- async retrieve(key: Key): Promise<Schematic>;
95
- async retrieve(keys: Key[]): Promise<Schematic[]>;
96
- async retrieve(keys: Params): Promise<Schematic | Schematic[]> {
97
- const isMany = Array.isArray(keys);
115
+ async retrieve(args: RetrieveSingleParams): Promise<Schematic>;
116
+ async retrieve(args: RetrieveMultipleParams): Promise<Schematic[]>;
117
+ async retrieve(
118
+ args: RetrieveSingleParams | RetrieveMultipleParams,
119
+ ): Promise<Schematic | Schematic[]> {
120
+ const isSingle = singleRetrieveArgsZ.safeParse(args).success;
98
121
  const res = await sendRequired(
99
122
  this.client,
100
123
  RETRIEVE_ENDPOINT,
101
- { keys: array.toArray(keys) },
102
- retrieveReqZ,
124
+ args,
125
+ retrieveArgsZ,
103
126
  retrieveResZ,
104
127
  );
105
- return isMany ? res.schematics : res.schematics[0];
128
+ checkForMultipleOrNoResults("Schematic", args, res.schematics, isSingle);
129
+ return isSingle ? res.schematics[0] : res.schematics;
106
130
  }
107
131
 
108
- async delete(key: Key): Promise<void>;
109
- async delete(keys: Key[]): Promise<void>;
110
132
  async delete(keys: Params): Promise<void> {
111
133
  await sendRequired(
112
134
  this.client,
@@ -117,11 +139,11 @@ export class Client {
117
139
  );
118
140
  }
119
141
 
120
- async copy(key: Key, name: string, snapshot: boolean): Promise<Schematic> {
142
+ async copy(args: CopyArgs): Promise<Schematic> {
121
143
  const res = await sendRequired(
122
144
  this.client,
123
145
  COPY_ENDPOINT,
124
- { key, name, snapshot },
146
+ args,
125
147
  copyReqZ,
126
148
  copyResZ,
127
149
  );
@@ -129,4 +151,7 @@ export class Client {
129
151
  }
130
152
  }
131
153
 
132
- export const ontologyID = (key: Key): ontology.ID => ({ type: "schematic", key });
154
+ export const ontologyID = (key: Key): ontology.ID => ({
155
+ type: "schematic",
156
+ key,
157
+ });
@@ -10,7 +10,7 @@
10
10
  import { uuid } from "@synnaxlabs/x";
11
11
  import { describe, expect, it, test } from "vitest";
12
12
 
13
- import { ValidationError } from "@/errors";
13
+ import { NotFoundError, ValidationError } from "@/errors";
14
14
  import { createTestClient } from "@/testutil/client";
15
15
 
16
16
  const client = createTestClient();
@@ -22,7 +22,7 @@ describe("Schematic", () => {
22
22
  name: "Schematic",
23
23
  layout: { one: 1 },
24
24
  });
25
- const schematic = await client.workspaces.schematic.create(ws.key, {
25
+ const schematic = await client.workspaces.schematics.create(ws.key, {
26
26
  name: "Schematic",
27
27
  data: { one: 1 },
28
28
  });
@@ -37,12 +37,14 @@ describe("Schematic", () => {
37
37
  name: "Schematic",
38
38
  layout: { one: 1 },
39
39
  });
40
- const schematic = await client.workspaces.schematic.create(ws.key, {
40
+ const schematic = await client.workspaces.schematics.create(ws.key, {
41
41
  name: "Schematic",
42
42
  data: { one: 1 },
43
43
  });
44
- await client.workspaces.schematic.rename(schematic.key, "Schematic2");
45
- const res = await client.workspaces.schematic.retrieve(schematic.key);
44
+ await client.workspaces.schematics.rename(schematic.key, "Schematic2");
45
+ const res = await client.workspaces.schematics.retrieve({
46
+ key: schematic.key,
47
+ });
46
48
  expect(res.name).toEqual("Schematic2");
47
49
  });
48
50
  });
@@ -52,12 +54,14 @@ describe("Schematic", () => {
52
54
  name: "Schematic",
53
55
  layout: { one: 1 },
54
56
  });
55
- const schematic = await client.workspaces.schematic.create(ws.key, {
57
+ const schematic = await client.workspaces.schematics.create(ws.key, {
56
58
  name: "Schematic",
57
59
  data: { one: 1 },
58
60
  });
59
- await client.workspaces.schematic.setData(schematic.key, { two: 2 });
60
- const res = await client.workspaces.schematic.retrieve(schematic.key);
61
+ await client.workspaces.schematics.setData(schematic.key, { two: 2 });
62
+ const res = await client.workspaces.schematics.retrieve({
63
+ key: schematic.key,
64
+ });
61
65
  expect(res.data.two).toEqual(2);
62
66
  });
63
67
  });
@@ -67,14 +71,14 @@ describe("Schematic", () => {
67
71
  name: "Schematic",
68
72
  layout: { one: 1 },
69
73
  });
70
- const schematic = await client.workspaces.schematic.create(ws.key, {
74
+ const schematic = await client.workspaces.schematics.create(ws.key, {
71
75
  name: "Schematic",
72
76
  data: { one: 1 },
73
77
  });
74
- await client.workspaces.schematic.delete(schematic.key);
78
+ await client.workspaces.schematics.delete(schematic.key);
75
79
  await expect(
76
- client.workspaces.schematic.retrieve(schematic.key),
77
- ).rejects.toThrow();
80
+ client.workspaces.schematics.retrieve({ key: schematic.key }),
81
+ ).rejects.toThrow(NotFoundError);
78
82
  });
79
83
  });
80
84
  describe("copy", () => {
@@ -83,15 +87,15 @@ describe("Schematic", () => {
83
87
  name: "Schematic",
84
88
  layout: { one: 1 },
85
89
  });
86
- const schematic = await client.workspaces.schematic.create(ws.key, {
90
+ const schematic = await client.workspaces.schematics.create(ws.key, {
87
91
  name: "Schematic",
88
92
  data: { one: 1 },
89
93
  });
90
- const schematic2 = await client.workspaces.schematic.copy(
91
- schematic.key,
92
- "Schematic2",
93
- false,
94
- );
94
+ const schematic2 = await client.workspaces.schematics.copy({
95
+ key: schematic.key,
96
+ name: "Schematic2",
97
+ snapshot: false,
98
+ });
95
99
  expect(schematic2.name).toEqual("Schematic2");
96
100
  expect(schematic2.key).not.toEqual(uuid.ZERO);
97
101
  expect(schematic2.data.one).toEqual(1);
@@ -102,17 +106,17 @@ describe("Schematic", () => {
102
106
  name: "Schematic",
103
107
  layout: { one: 1 },
104
108
  });
105
- const schematic = await client.workspaces.schematic.create(ws.key, {
109
+ const schematic = await client.workspaces.schematics.create(ws.key, {
106
110
  name: "Schematic",
107
111
  data: { one: 1 },
108
112
  });
109
- const schematic2 = await client.workspaces.schematic.copy(
110
- schematic.key,
111
- "Schematic2",
112
- true,
113
- );
113
+ const schematic2 = await client.workspaces.schematics.copy({
114
+ key: schematic.key,
115
+ name: "Schematic2",
116
+ snapshot: true,
117
+ });
114
118
  await expect(
115
- client.workspaces.schematic.setData(schematic2.key, { two: 2 }),
119
+ client.workspaces.schematics.setData(schematic2.key, { two: 2 }),
116
120
  ).rejects.toThrow(ValidationError);
117
121
  });
118
122
  });
@@ -10,19 +10,22 @@
10
10
  import { beforeAll, describe, expect, it } from "vitest";
11
11
 
12
12
  import { ontology } from "@/ontology";
13
- import { type group } from "@/ontology/group";
13
+ import { group } from "@/ontology/group";
14
14
  import { createTestClient } from "@/testutil/client";
15
15
 
16
16
  const client = createTestClient();
17
17
 
18
18
  describe("Symbol Client", () => {
19
- let group: group.Group;
19
+ let symbolGroup: group.Group;
20
20
  beforeAll(async () => {
21
- group = await client.ontology.groups.create(ontology.ROOT_ID, "Test Symbols");
21
+ symbolGroup = await client.ontology.groups.create({
22
+ parent: ontology.ROOT_ID,
23
+ name: "Test Symbols",
24
+ });
22
25
  });
23
26
  describe("create", () => {
24
27
  it("should create a single symbol", async () => {
25
- const symbol = await client.workspaces.schematic.symbols.create({
28
+ const symbol = await client.workspaces.schematics.symbols.create({
26
29
  name: "Test Symbol",
27
30
  data: {
28
31
  svg: "<svg></svg>",
@@ -30,14 +33,14 @@ describe("Symbol Client", () => {
30
33
  handles: [],
31
34
  variant: "sensor",
32
35
  },
33
- parent: group.ontologyID,
36
+ parent: group.ontologyID(symbolGroup.key),
34
37
  });
35
38
  expect(symbol.name).toBe("Test Symbol");
36
39
  expect(symbol.key).toBeDefined();
37
40
  });
38
41
 
39
42
  it("should create multiple symbols", async () => {
40
- const symbols = await client.workspaces.schematic.symbols.create({
43
+ const symbols = await client.workspaces.schematics.symbols.create({
41
44
  symbols: [
42
45
  {
43
46
  name: "Symbol 1",
@@ -48,7 +51,7 @@ describe("Symbol Client", () => {
48
51
  data: { svg: "<svg></svg>", states: [], handles: [], variant: "sensor" },
49
52
  },
50
53
  ],
51
- parent: group.ontologyID,
54
+ parent: group.ontologyID(symbolGroup.key),
52
55
  });
53
56
  expect(symbols).toHaveLength(2);
54
57
  expect(symbols[0].name).toBe("Symbol 1");
@@ -58,13 +61,13 @@ describe("Symbol Client", () => {
58
61
 
59
62
  describe("retrieve", () => {
60
63
  it("should retrieve a single symbol by key", async () => {
61
- const created = await client.workspaces.schematic.symbols.create({
64
+ const created = await client.workspaces.schematics.symbols.create({
62
65
  name: "Retrieve Test",
63
66
  data: { svg: "<svg></svg>", states: [], handles: [], variant: "sensor" },
64
- parent: group.ontologyID,
67
+ parent: group.ontologyID(symbolGroup.key),
65
68
  });
66
69
 
67
- const retrieved = await client.workspaces.schematic.symbols.retrieve({
70
+ const retrieved = await client.workspaces.schematics.symbols.retrieve({
68
71
  key: created.key,
69
72
  });
70
73
  expect(retrieved.key).toBe(created.key);
@@ -72,18 +75,18 @@ describe("Symbol Client", () => {
72
75
  });
73
76
 
74
77
  it("should retrieve multiple symbols by keys", async () => {
75
- const created1 = await client.workspaces.schematic.symbols.create({
78
+ const created1 = await client.workspaces.schematics.symbols.create({
76
79
  name: "Multi Test 1",
77
80
  data: { svg: "<svg></svg>", states: [], handles: [], variant: "sensor" },
78
- parent: group.ontologyID,
81
+ parent: group.ontologyID(symbolGroup.key),
79
82
  });
80
- const created2 = await client.workspaces.schematic.symbols.create({
83
+ const created2 = await client.workspaces.schematics.symbols.create({
81
84
  name: "Multi Test 2",
82
85
  data: { svg: "<svg></svg>", states: [], handles: [], variant: "sensor" },
83
- parent: group.ontologyID,
86
+ parent: group.ontologyID(symbolGroup.key),
84
87
  });
85
88
 
86
- const retrieved = await client.workspaces.schematic.symbols.retrieve({
89
+ const retrieved = await client.workspaces.schematics.symbols.retrieve({
87
90
  keys: [created1.key, created2.key],
88
91
  });
89
92
  expect(retrieved).toHaveLength(2);
@@ -92,15 +95,15 @@ describe("Symbol Client", () => {
92
95
 
93
96
  describe("rename", () => {
94
97
  it("should rename a symbol", async () => {
95
- const symbol = await client.workspaces.schematic.symbols.create({
98
+ const symbol = await client.workspaces.schematics.symbols.create({
96
99
  name: "Original Name",
97
100
  data: { svg: "<svg></svg>", states: [], handles: [], variant: "sensor" },
98
- parent: group.ontologyID,
101
+ parent: group.ontologyID(symbolGroup.key),
99
102
  });
100
103
 
101
- await client.workspaces.schematic.symbols.rename(symbol.key, "New Name");
104
+ await client.workspaces.schematics.symbols.rename(symbol.key, "New Name");
102
105
 
103
- const retrieved = await client.workspaces.schematic.symbols.retrieve({
106
+ const retrieved = await client.workspaces.schematics.symbols.retrieve({
104
107
  key: symbol.key,
105
108
  });
106
109
  expect(retrieved.name).toBe("New Name");
@@ -109,23 +112,23 @@ describe("Symbol Client", () => {
109
112
 
110
113
  describe("delete", () => {
111
114
  it("should delete a single symbol", async () => {
112
- const symbol = await client.workspaces.schematic.symbols.create({
115
+ const symbol = await client.workspaces.schematics.symbols.create({
113
116
  name: "Delete Test",
114
117
  data: { svg: "<svg></svg>", states: [], handles: [], variant: "sensor" },
115
- parent: group.ontologyID,
118
+ parent: group.ontologyID(symbolGroup.key),
116
119
  });
117
120
 
118
- await client.workspaces.schematic.symbols.delete(symbol.key);
121
+ await client.workspaces.schematics.symbols.delete(symbol.key);
119
122
 
120
123
  await expect(
121
- client.workspaces.schematic.symbols.retrieve({ key: symbol.key }),
124
+ client.workspaces.schematics.symbols.retrieve({ key: symbol.key }),
122
125
  ).rejects.toThrow();
123
126
  });
124
127
  });
125
128
 
126
129
  describe("retrieveGroup", () => {
127
130
  it("should retrieve the symbol group", async () => {
128
- const group = await client.workspaces.schematic.symbols.retrieveGroup();
131
+ const group = await client.workspaces.schematics.symbols.retrieveGroup();
129
132
  expect(group.key).toBeDefined();
130
133
  expect(group.name).toBe("Schematic Symbols");
131
134
  });
@@ -14,7 +14,6 @@ import { z } from "zod";
14
14
  import { ontology } from "@/ontology";
15
15
  import { group } from "@/ontology/group";
16
16
  import { checkForMultipleOrNoResults } from "@/util/retrieve";
17
- import { nullableArrayZ } from "@/util/zod";
18
17
  import {
19
18
  type Key,
20
19
  keyZ,
@@ -48,10 +47,10 @@ const singleRetrieveArgsZ = z
48
47
  const retrieveArgsZ = z.union([singleRetrieveArgsZ, retrieveRequestZ]);
49
48
 
50
49
  export type RetrieveArgs = z.input<typeof retrieveArgsZ>;
51
- export type SingleRetrieveArgs = z.input<typeof singleRetrieveArgsZ>;
52
- export type MultiRetrieveArgs = z.input<typeof retrieveRequestZ>;
50
+ export type RetrieveSingleParams = z.input<typeof singleRetrieveArgsZ>;
51
+ export type RetrieveMultipleParams = z.input<typeof retrieveRequestZ>;
53
52
 
54
- const retrieveResZ = z.object({ symbols: nullableArrayZ(symbolZ) });
53
+ const retrieveResZ = z.object({ symbols: array.nullableZ(symbolZ) });
55
54
  const createResZ = z.object({ symbols: symbolZ.array() });
56
55
  const emptyResZ = z.object({});
57
56
  const retrieveGroupReqZ = z.object({});
@@ -101,8 +100,8 @@ export class Client {
101
100
  );
102
101
  }
103
102
 
104
- async retrieve(args: SingleRetrieveArgs): Promise<Symbol>;
105
- async retrieve(args: MultiRetrieveArgs): Promise<Symbol[]>;
103
+ async retrieve(args: RetrieveSingleParams): Promise<Symbol>;
104
+ async retrieve(args: RetrieveMultipleParams): Promise<Symbol[]>;
106
105
  async retrieve(args: RetrieveArgs): Promise<Symbol | Symbol[]> {
107
106
  const isSingle = "key" in args;
108
107
  const res = await sendRequired(
@@ -116,8 +115,6 @@ export class Client {
116
115
  return isSingle ? res.symbols[0] : res.symbols;
117
116
  }
118
117
 
119
- async delete(key: Key): Promise<void>;
120
- async delete(keys: Key[]): Promise<void>;
121
118
  async delete(keys: Key | Key[]): Promise<void> {
122
119
  await sendRequired(
123
120
  this.client,
@@ -128,7 +125,7 @@ export class Client {
128
125
  );
129
126
  }
130
127
 
131
- async retrieveGroup(): Promise<group.Payload> {
128
+ async retrieveGroup(): Promise<group.Group> {
132
129
  const res = await sendRequired(
133
130
  this.client,
134
131
  RETRIEVE_GROUP_ENDPOINT,
@@ -12,6 +12,7 @@ import { array, type record } from "@synnaxlabs/x";
12
12
  import { z } from "zod";
13
13
 
14
14
  import { type ontology } from "@/ontology";
15
+ import { checkForMultipleOrNoResults } from "@/util/retrieve";
15
16
  import { type Key as WorkspaceKey, keyZ as workspaceKeyZ } from "@/workspace/payload";
16
17
  import {
17
18
  type Key,
@@ -29,14 +30,26 @@ const RENAME_ENDPOINT = "/workspace/table/rename";
29
30
  const SET_DATA_ENDPOINT = "/workspace/table/set-data";
30
31
  const DELETE_ENDPOINT = "/workspace/table/delete";
31
32
 
32
- const retrieveReqZ = z.object({ keys: keyZ.array() });
33
- const createReqZ = z.object({ workspace: workspaceKeyZ, tables: newZ.array() });
34
33
  const renameReqZ = z.object({ key: keyZ, name: z.string() });
34
+
35
35
  const setDataReqZ = z.object({ key: keyZ, data: z.string() });
36
36
  const deleteReqZ = z.object({ keys: keyZ.array() });
37
37
 
38
- const retrieveResZ = z.object({ tables: remoteZ.array() });
38
+ const retrieveReqZ = z.object({ keys: keyZ.array() });
39
+ const singleRetrieveArgsZ = z
40
+ .object({ key: keyZ })
41
+ .transform(({ key }) => ({ keys: [key] }));
42
+
43
+ export const retrieveArgsZ = z.union([singleRetrieveArgsZ, retrieveReqZ]);
44
+ export type RetrieveArgs = z.input<typeof retrieveArgsZ>;
45
+ export type RetrieveSingleParams = z.input<typeof singleRetrieveArgsZ>;
46
+ export type RetrieveMultipleParams = z.input<typeof retrieveReqZ>;
47
+
48
+ const retrieveResZ = z.object({ tables: array.nullableZ(remoteZ) });
49
+
50
+ const createReqZ = z.object({ workspace: workspaceKeyZ, tables: newZ.array() });
39
51
  const createResZ = z.object({ tables: remoteZ.array() });
52
+
40
53
  const emptyResZ = z.object({});
41
54
 
42
55
  export class Client {
@@ -80,22 +93,23 @@ export class Client {
80
93
  );
81
94
  }
82
95
 
83
- async retrieve(key: Key): Promise<Table>;
84
- async retrieve(keys: Key[]): Promise<Table[]>;
85
- async retrieve(keys: Params): Promise<Table | Table[]> {
86
- const isMany = Array.isArray(keys);
96
+ async retrieve(args: RetrieveSingleParams): Promise<Table>;
97
+ async retrieve(args: RetrieveMultipleParams): Promise<Table[]>;
98
+ async retrieve(
99
+ args: RetrieveSingleParams | RetrieveMultipleParams,
100
+ ): Promise<Table | Table[]> {
101
+ const isSingle = singleRetrieveArgsZ.safeParse(args).success;
87
102
  const res = await sendRequired(
88
103
  this.client,
89
104
  RETRIEVE_ENDPOINT,
90
- { keys: array.toArray(keys) },
91
- retrieveReqZ,
105
+ args,
106
+ retrieveArgsZ,
92
107
  retrieveResZ,
93
108
  );
94
- return isMany ? res.tables : res.tables[0];
109
+ checkForMultipleOrNoResults("Table", args, res.tables, isSingle);
110
+ return isSingle ? res.tables[0] : res.tables;
95
111
  }
96
112
 
97
- async delete(key: Key): Promise<void>;
98
- async delete(keys: Key[]): Promise<void>;
99
113
  async delete(keys: Params): Promise<void> {
100
114
  await sendRequired(
101
115
  this.client,
@@ -10,6 +10,7 @@
10
10
  import { uuid } from "@synnaxlabs/x";
11
11
  import { describe, expect, test } from "vitest";
12
12
 
13
+ import { NotFoundError } from "@/errors";
13
14
  import { createTestClient } from "@/testutil/client";
14
15
 
15
16
  const client = createTestClient();
@@ -18,7 +19,7 @@ describe("Table", () => {
18
19
  describe("create", () => {
19
20
  test("create one", async () => {
20
21
  const ws = await client.workspaces.create({ name: "Table", layout: { one: 1 } });
21
- const table = await client.workspaces.table.create(ws.key, {
22
+ const table = await client.workspaces.tables.create(ws.key, {
22
23
  name: "Table",
23
24
  data: { one: 1 },
24
25
  });
@@ -30,36 +31,38 @@ describe("Table", () => {
30
31
  describe("rename", () => {
31
32
  test("rename one", async () => {
32
33
  const ws = await client.workspaces.create({ name: "Table", layout: { one: 1 } });
33
- const table = await client.workspaces.table.create(ws.key, {
34
+ const table = await client.workspaces.tables.create(ws.key, {
34
35
  name: "Table",
35
36
  data: { one: 1 },
36
37
  });
37
- await client.workspaces.table.rename(table.key, "Table2");
38
- const res = await client.workspaces.table.retrieve(table.key);
38
+ await client.workspaces.tables.rename(table.key, "Table2");
39
+ const res = await client.workspaces.tables.retrieve({ key: table.key });
39
40
  expect(res.name).toEqual("Table2");
40
41
  });
41
42
  });
42
43
  describe("setData", () => {
43
44
  test("set data", async () => {
44
45
  const ws = await client.workspaces.create({ name: "Table", layout: { one: 1 } });
45
- const table = await client.workspaces.table.create(ws.key, {
46
+ const table = await client.workspaces.tables.create(ws.key, {
46
47
  name: "Table",
47
48
  data: { one: 1 },
48
49
  });
49
- await client.workspaces.table.setData(table.key, { two: 2 });
50
- const res = await client.workspaces.table.retrieve(table.key);
50
+ await client.workspaces.tables.setData(table.key, { two: 2 });
51
+ const res = await client.workspaces.tables.retrieve({ key: table.key });
51
52
  expect(res.data.two).toEqual(2);
52
53
  });
53
54
  });
54
55
  describe("delete", () => {
55
56
  test("delete one", async () => {
56
57
  const ws = await client.workspaces.create({ name: "Table", layout: { one: 1 } });
57
- const table = await client.workspaces.table.create(ws.key, {
58
+ const table = await client.workspaces.tables.create(ws.key, {
58
59
  name: "Table",
59
60
  data: { one: 1 },
60
61
  });
61
- await client.workspaces.table.delete(table.key);
62
- await expect(client.workspaces.table.retrieve(table.key)).rejects.toThrow();
62
+ await client.workspaces.tables.delete(table.key);
63
+ await expect(
64
+ client.workspaces.tables.retrieve({ key: table.key }),
65
+ ).rejects.toThrow(NotFoundError);
63
66
  });
64
67
  });
65
68
  });
@@ -1,10 +0,0 @@
1
- import { ontology } from '..';
2
- import { Key, Name } from './payload';
3
- export declare class Group {
4
- key: Key;
5
- name: Name;
6
- constructor(name: Name, key: Key);
7
- get ontologyID(): ontology.ID;
8
- }
9
- export declare const ontologyID: (key: Key) => ontology.ID;
10
- //# sourceMappingURL=group.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"group.d.ts","sourceRoot":"","sources":["../../../src/ontology/group/group.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,KAAK,GAAG,EAAE,KAAK,IAAI,EAAE,MAAM,0BAA0B,CAAC;AAE/D,qBAAa,KAAK;IAChB,GAAG,EAAE,GAAG,CAAC;IACT,IAAI,EAAE,IAAI,CAAC;gBAEC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG;IAKhC,IAAI,UAAU,IAAI,QAAQ,CAAC,EAAE,CAE5B;CACF;AAED,eAAO,MAAM,UAAU,GAAI,KAAK,GAAG,KAAG,QAAQ,CAAC,EAA8B,CAAC"}
@@ -1,14 +0,0 @@
1
- import { UnaryClient } from '@synnaxlabs/freighter';
2
- import { Key, Name, Payload } from './payload';
3
- import { ID as OntologyID } from '../payload';
4
- export declare class Writer {
5
- private static readonly CREATE_ENDPOINT;
6
- private static readonly RENAME_ENDPOINT;
7
- private static readonly DELETE_ENDPOINT;
8
- client: UnaryClient;
9
- constructor(client: UnaryClient);
10
- create(parent: OntologyID, name: Name, key?: Key): Promise<Payload>;
11
- rename(key: Key, name: Name): Promise<void>;
12
- delete(keys: Key[]): Promise<void>;
13
- }
14
- //# sourceMappingURL=writer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"writer.d.ts","sourceRoot":"","sources":["../../../src/ontology/group/writer.ts"],"names":[],"mappings":"AASA,OAAO,EAAgB,KAAK,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGvE,OAAO,EAEL,KAAK,GAAG,EAER,KAAK,IAAI,EAET,KAAK,OAAO,EACb,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,IAAI,UAAU,EAAsB,MAAM,oBAAoB,CAAC;AAU/E,qBAAa,MAAM;IACjB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAA4B;IACnE,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAA4B;IACnE,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAA4B;IACnE,MAAM,EAAE,WAAW,CAAC;gBAER,MAAM,EAAE,WAAW;IAIzB,MAAM,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC;IAWnE,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAU3C,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CASzC"}
@@ -1,3 +0,0 @@
1
- import { z } from 'zod';
2
- export declare const nullableArrayZ: <Z extends z.ZodType>(item: Z) => z.ZodUnion<readonly [z.ZodPipe<z.ZodUnion<readonly [z.ZodNull, z.ZodUndefined]>, z.ZodTransform<z.core.output<Z>[], null | undefined>>, z.ZodArray<Z>]>;
3
- //# sourceMappingURL=zod.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"zod.d.ts","sourceRoot":"","sources":["../../src/util/zod.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,MAAM,CAAC,4JAIvD,CAAC"}
@@ -1,27 +0,0 @@
1
- // Copyright 2025 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
- import { type ontology } from "@/ontology";
11
- import { type Key, type Name } from "@/ontology/group/payload";
12
-
13
- export class Group {
14
- key: Key;
15
- name: Name;
16
-
17
- constructor(name: Name, key: Key) {
18
- this.key = key;
19
- this.name = name;
20
- }
21
-
22
- get ontologyID(): ontology.ID {
23
- return ontologyID(this.key);
24
- }
25
- }
26
-
27
- export const ontologyID = (key: Key): ontology.ID => ({ type: "group", key });