@synnaxlabs/client 0.43.1 → 0.44.2

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 (245) hide show
  1. package/.turbo/turbo-build.log +7 -7
  2. package/dist/access/payload.d.ts +1 -1
  3. package/dist/access/payload.d.ts.map +1 -1
  4. package/dist/access/policy/client.d.ts +263 -6
  5. package/dist/access/policy/client.d.ts.map +1 -1
  6. package/dist/access/policy/external.d.ts +0 -1
  7. package/dist/access/policy/external.d.ts.map +1 -1
  8. package/dist/access/policy/payload.d.ts +105 -93
  9. package/dist/access/policy/payload.d.ts.map +1 -1
  10. package/dist/auth/auth.d.ts +1 -1
  11. package/dist/auth/auth.d.ts.map +1 -1
  12. package/dist/channel/client.d.ts +23 -17
  13. package/dist/channel/client.d.ts.map +1 -1
  14. package/dist/channel/payload.d.ts +151 -21
  15. package/dist/channel/payload.d.ts.map +1 -1
  16. package/dist/channel/retriever.d.ts +9 -16
  17. package/dist/channel/retriever.d.ts.map +1 -1
  18. package/dist/channel/writer.d.ts +1 -1
  19. package/dist/channel/writer.d.ts.map +1 -1
  20. package/dist/client.cjs +27 -135
  21. package/dist/client.d.ts +3 -3
  22. package/dist/client.d.ts.map +1 -1
  23. package/dist/client.js +8657 -28963
  24. package/dist/connection/checker.d.ts +1 -1
  25. package/dist/connection/checker.d.ts.map +1 -1
  26. package/dist/control/client.d.ts +1 -0
  27. package/dist/control/client.d.ts.map +1 -1
  28. package/dist/control/state.d.ts +6 -6
  29. package/dist/control/state.d.ts.map +1 -1
  30. package/dist/errors.d.ts +18 -5
  31. package/dist/errors.d.ts.map +1 -1
  32. package/dist/framer/adapter.d.ts +3 -3
  33. package/dist/framer/adapter.d.ts.map +1 -1
  34. package/dist/framer/client.d.ts +4 -13
  35. package/dist/framer/client.d.ts.map +1 -1
  36. package/dist/framer/codec.d.ts +1 -1
  37. package/dist/framer/codec.d.ts.map +1 -1
  38. package/dist/framer/deleter.d.ts +5 -5
  39. package/dist/framer/deleter.d.ts.map +1 -1
  40. package/dist/framer/frame.d.ts +5 -7
  41. package/dist/framer/frame.d.ts.map +1 -1
  42. package/dist/framer/streamProxy.d.ts +1 -1
  43. package/dist/framer/streamProxy.d.ts.map +1 -1
  44. package/dist/framer/streamer.d.ts +235 -20
  45. package/dist/framer/streamer.d.ts.map +1 -1
  46. package/dist/framer/writer.d.ts +302 -33
  47. package/dist/framer/writer.d.ts.map +1 -1
  48. package/dist/hardware/device/client.d.ts +49 -28
  49. package/dist/hardware/device/client.d.ts.map +1 -1
  50. package/dist/hardware/device/payload.d.ts +126 -46
  51. package/dist/hardware/device/payload.d.ts.map +1 -1
  52. package/dist/hardware/rack/client.d.ts +78 -22
  53. package/dist/hardware/rack/client.d.ts.map +1 -1
  54. package/dist/hardware/rack/payload.d.ts +99 -56
  55. package/dist/hardware/rack/payload.d.ts.map +1 -1
  56. package/dist/hardware/task/client.d.ts +100 -41
  57. package/dist/hardware/task/client.d.ts.map +1 -1
  58. package/dist/hardware/task/payload.d.ts +83 -61
  59. package/dist/hardware/task/payload.d.ts.map +1 -1
  60. package/dist/index.d.ts +2 -2
  61. package/dist/index.d.ts.map +1 -1
  62. package/dist/label/client.d.ts +138 -20
  63. package/dist/label/client.d.ts.map +1 -1
  64. package/dist/label/external.d.ts +0 -2
  65. package/dist/label/external.d.ts.map +1 -1
  66. package/dist/label/payload.d.ts +4 -5
  67. package/dist/label/payload.d.ts.map +1 -1
  68. package/dist/ontology/client.d.ts +45 -135
  69. package/dist/ontology/client.d.ts.map +1 -1
  70. package/dist/ontology/group/group.d.ts +3 -3
  71. package/dist/ontology/group/group.d.ts.map +1 -1
  72. package/dist/ontology/group/payload.d.ts +3 -27
  73. package/dist/ontology/group/payload.d.ts.map +1 -1
  74. package/dist/ontology/payload.d.ts +114 -243
  75. package/dist/ontology/payload.d.ts.map +1 -1
  76. package/dist/ontology/writer.d.ts +4 -4
  77. package/dist/ontology/writer.d.ts.map +1 -1
  78. package/dist/ranger/alias.d.ts +15 -5
  79. package/dist/ranger/alias.d.ts.map +1 -1
  80. package/dist/ranger/client.d.ts +91 -30
  81. package/dist/ranger/client.d.ts.map +1 -1
  82. package/dist/ranger/external.d.ts +1 -1
  83. package/dist/ranger/external.d.ts.map +1 -1
  84. package/dist/ranger/kv.d.ts +11 -12
  85. package/dist/ranger/kv.d.ts.map +1 -1
  86. package/dist/ranger/payload.d.ts +19 -44
  87. package/dist/ranger/payload.d.ts.map +1 -1
  88. package/dist/ranger/writer.d.ts +22 -19
  89. package/dist/ranger/writer.d.ts.map +1 -1
  90. package/dist/testutil/client.d.ts +4 -0
  91. package/dist/testutil/client.d.ts.map +1 -0
  92. package/dist/user/client.d.ts +59 -6
  93. package/dist/user/client.d.ts.map +1 -1
  94. package/dist/user/payload.d.ts +4 -6
  95. package/dist/user/payload.d.ts.map +1 -1
  96. package/dist/user/retriever.d.ts +2 -2
  97. package/dist/user/retriever.d.ts.map +1 -1
  98. package/dist/util/decodeJSONString.d.ts +2 -2
  99. package/dist/util/decodeJSONString.d.ts.map +1 -1
  100. package/dist/util/parseWithoutKeyConversion.d.ts +2 -2
  101. package/dist/util/parseWithoutKeyConversion.d.ts.map +1 -1
  102. package/dist/util/retrieve.d.ts +1 -1
  103. package/dist/util/retrieve.d.ts.map +1 -1
  104. package/dist/util/zod.d.ts +1 -1
  105. package/dist/util/zod.d.ts.map +1 -1
  106. package/dist/workspace/client.d.ts +17 -6
  107. package/dist/workspace/client.d.ts.map +1 -1
  108. package/dist/workspace/lineplot/client.d.ts +2 -2
  109. package/dist/workspace/lineplot/client.d.ts.map +1 -1
  110. package/dist/workspace/lineplot/payload.d.ts +8 -9
  111. package/dist/workspace/lineplot/payload.d.ts.map +1 -1
  112. package/dist/workspace/log/client.d.ts +2 -2
  113. package/dist/workspace/log/client.d.ts.map +1 -1
  114. package/dist/workspace/log/payload.d.ts +8 -9
  115. package/dist/workspace/log/payload.d.ts.map +1 -1
  116. package/dist/workspace/payload.d.ts +10 -11
  117. package/dist/workspace/payload.d.ts.map +1 -1
  118. package/dist/workspace/schematic/client.d.ts +2 -2
  119. package/dist/workspace/schematic/client.d.ts.map +1 -1
  120. package/dist/workspace/schematic/payload.d.ts +10 -11
  121. package/dist/workspace/schematic/payload.d.ts.map +1 -1
  122. package/dist/workspace/table/client.d.ts +2 -2
  123. package/dist/workspace/table/client.d.ts.map +1 -1
  124. package/dist/workspace/table/payload.d.ts +10 -11
  125. package/dist/workspace/table/payload.d.ts.map +1 -1
  126. package/examples/node/package-lock.json +47 -39
  127. package/examples/node/package.json +2 -1
  128. package/examples/node/streamWrite.js +5 -11
  129. package/package.json +14 -13
  130. package/src/access/payload.ts +1 -1
  131. package/src/access/policy/client.ts +87 -32
  132. package/src/access/policy/external.ts +0 -1
  133. package/src/access/policy/payload.ts +4 -4
  134. package/src/access/policy/policy.spec.ts +86 -83
  135. package/src/auth/auth.spec.ts +29 -18
  136. package/src/auth/auth.ts +1 -1
  137. package/src/channel/batchRetriever.spec.ts +4 -9
  138. package/src/channel/channel.spec.ts +24 -6
  139. package/src/channel/client.ts +52 -51
  140. package/src/channel/payload.ts +15 -16
  141. package/src/channel/retriever.ts +26 -41
  142. package/src/channel/writer.ts +7 -4
  143. package/src/client.ts +4 -4
  144. package/src/connection/checker.ts +1 -1
  145. package/src/connection/connection.spec.ts +31 -23
  146. package/src/control/client.ts +2 -2
  147. package/src/control/state.spec.ts +3 -3
  148. package/src/control/state.ts +1 -1
  149. package/src/errors.spec.ts +9 -5
  150. package/src/errors.ts +28 -15
  151. package/src/framer/adapter.spec.ts +118 -9
  152. package/src/framer/adapter.ts +24 -11
  153. package/src/framer/client.spec.ts +125 -2
  154. package/src/framer/client.ts +41 -47
  155. package/src/framer/codec.ts +1 -1
  156. package/src/framer/deleter.spec.ts +2 -2
  157. package/src/framer/deleter.ts +1 -1
  158. package/src/framer/frame.ts +1 -4
  159. package/src/framer/iterator.spec.ts +8 -8
  160. package/src/framer/iterator.ts +1 -1
  161. package/src/framer/streamProxy.ts +1 -1
  162. package/src/framer/streamer.spec.ts +185 -36
  163. package/src/framer/streamer.ts +28 -36
  164. package/src/framer/writer.spec.ts +7 -6
  165. package/src/framer/writer.ts +97 -111
  166. package/src/hardware/device/client.ts +45 -131
  167. package/src/hardware/device/device.spec.ts +163 -52
  168. package/src/hardware/device/payload.ts +10 -21
  169. package/src/hardware/rack/client.ts +87 -105
  170. package/src/hardware/rack/payload.ts +4 -13
  171. package/src/hardware/rack/rack.spec.ts +28 -35
  172. package/src/hardware/task/client.ts +335 -291
  173. package/src/hardware/task/payload.ts +86 -62
  174. package/src/hardware/task/task.spec.ts +208 -32
  175. package/src/index.ts +2 -1
  176. package/src/label/client.ts +100 -95
  177. package/src/label/external.ts +0 -2
  178. package/src/label/label.spec.ts +8 -6
  179. package/src/label/payload.ts +3 -4
  180. package/src/ontology/client.ts +41 -324
  181. package/src/ontology/group/group.spec.ts +2 -2
  182. package/src/ontology/group/group.ts +4 -5
  183. package/src/ontology/group/payload.ts +2 -25
  184. package/src/ontology/group/writer.ts +1 -1
  185. package/src/ontology/ontology.spec.ts +355 -41
  186. package/src/ontology/payload.ts +77 -112
  187. package/src/ontology/writer.ts +8 -17
  188. package/src/ranger/alias.ts +45 -37
  189. package/src/ranger/client.ts +144 -149
  190. package/src/ranger/external.ts +1 -1
  191. package/src/ranger/kv.ts +9 -27
  192. package/src/ranger/payload.ts +23 -37
  193. package/src/ranger/ranger.spec.ts +37 -56
  194. package/src/ranger/writer.ts +1 -1
  195. package/src/{signals/index.ts → testutil/client.ts} +11 -1
  196. package/src/user/client.ts +122 -47
  197. package/src/user/payload.ts +2 -5
  198. package/src/user/retriever.ts +1 -1
  199. package/src/user/user.spec.ts +31 -31
  200. package/src/user/writer.ts +1 -1
  201. package/src/util/decodeJSONString.ts +3 -3
  202. package/src/util/parseWithoutKeyConversion.ts +2 -2
  203. package/src/util/retrieve.ts +1 -1
  204. package/src/util/zod.ts +1 -1
  205. package/src/workspace/client.ts +20 -36
  206. package/src/workspace/lineplot/client.ts +5 -7
  207. package/src/workspace/lineplot/lineplot.spec.ts +2 -2
  208. package/src/workspace/lineplot/payload.ts +4 -7
  209. package/src/workspace/log/client.ts +5 -7
  210. package/src/workspace/log/log.spec.ts +2 -2
  211. package/src/workspace/log/payload.ts +4 -7
  212. package/src/workspace/payload.ts +4 -7
  213. package/src/workspace/schematic/client.ts +5 -7
  214. package/src/workspace/schematic/payload.ts +4 -7
  215. package/src/workspace/schematic/schematic.spec.ts +2 -2
  216. package/src/workspace/table/client.ts +5 -7
  217. package/src/workspace/table/payload.ts +4 -7
  218. package/src/workspace/table/table.spec.ts +2 -2
  219. package/src/workspace/workspace.spec.ts +2 -2
  220. package/dist/access/policy/ontology.d.ts +0 -5
  221. package/dist/access/policy/ontology.d.ts.map +0 -1
  222. package/dist/access/policy/retriever.d.ts +0 -40
  223. package/dist/access/policy/retriever.d.ts.map +0 -1
  224. package/dist/access/policy/writer.d.ts +0 -9
  225. package/dist/access/policy/writer.d.ts.map +0 -1
  226. package/dist/label/retriever.d.ts +0 -14
  227. package/dist/label/retriever.d.ts.map +0 -1
  228. package/dist/label/writer.d.ts +0 -54
  229. package/dist/label/writer.d.ts.map +0 -1
  230. package/dist/setupspecs.d.ts +0 -5
  231. package/dist/setupspecs.d.ts.map +0 -1
  232. package/dist/signals/external.d.ts +0 -2
  233. package/dist/signals/external.d.ts.map +0 -1
  234. package/dist/signals/index.d.ts +0 -2
  235. package/dist/signals/index.d.ts.map +0 -1
  236. package/dist/signals/observable.d.ts +0 -12
  237. package/dist/signals/observable.d.ts.map +0 -1
  238. package/src/access/policy/ontology.ts +0 -17
  239. package/src/access/policy/retriever.ts +0 -44
  240. package/src/access/policy/writer.ts +0 -65
  241. package/src/label/retriever.ts +0 -63
  242. package/src/label/writer.ts +0 -95
  243. package/src/setupspecs.ts +0 -27
  244. package/src/signals/external.ts +0 -10
  245. package/src/signals/observable.ts +0 -42
@@ -11,37 +11,34 @@ import { id } from "@synnaxlabs/x";
11
11
  import { describe, expect, test } from "vitest";
12
12
 
13
13
  import { type policy } from "@/access/policy";
14
- import { channel } from "@/channel";
15
- import Synnax from "@/client";
16
14
  import { AuthError } from "@/errors";
17
- import { label } from "@/label";
18
- import { HOST, newClient, PORT } from "@/setupspecs";
15
+ import { createTestClient } from "@/testutil/client";
19
16
  import { user } from "@/user";
20
- import { schematic } from "@/workspace/schematic";
21
17
 
22
- const client = newClient();
18
+ const client = createTestClient();
23
19
 
24
20
  describe("Policy", () => {
25
21
  describe("create", () => {
26
22
  describe("one", () => {
27
23
  test("without key", async () => {
28
24
  const policy = await client.access.policy.create({
29
- subjects: user.ONTOLOGY_TYPE,
30
- objects: [user.ONTOLOGY_TYPE, channel.ONTOLOGY_TYPE],
25
+ subjects: "user",
26
+ objects: ["user", "channel"],
31
27
  actions: "delete",
32
28
  });
33
29
  expect(policy.key).toBeDefined();
34
30
  expect(policy.subjects.length).toEqual(1);
35
31
  expect(policy.subjects[0].key).toEqual("");
36
- expect(policy.subjects[0].type).toEqual(user.ONTOLOGY_TYPE);
32
+ expect(policy.subjects[0].type).toEqual("user");
37
33
  expect(policy.objects.length).toEqual(2);
38
34
  expect(policy.objects[0].key).toEqual("");
39
35
  expect(policy.objects[1].key).toEqual("");
40
- expect(policy.objects[0].type).toEqual(user.ONTOLOGY_TYPE);
41
- expect(policy.objects[1].type).toEqual(channel.ONTOLOGY_TYPE);
36
+ expect(policy.objects[0].type).toEqual("user");
37
+ expect(policy.objects[1].type).toEqual("channel");
42
38
  expect(policy.actions).toEqual(["delete"]);
43
39
  await client.access.policy.delete(policy.key);
44
40
  });
41
+
45
42
  test("missing subjects", async () => {
46
43
  const policy = await client.access.policy.create({
47
44
  subjects: [],
@@ -52,42 +49,46 @@ describe("Policy", () => {
52
49
  expect(policy.subjects).toHaveLength(0);
53
50
  expect(policy.objects).toHaveLength(0);
54
51
  expect(policy.actions).toHaveLength(0);
55
- const retrievedPolicy = await client.access.policy.retrieve(policy.key);
52
+ const retrievedPolicy = await client.access.policy.retrieve({
53
+ key: policy.key,
54
+ });
56
55
  expect(retrievedPolicy).toMatchObject(policy);
57
56
  });
58
57
  test("missing objects", async () => {
59
58
  const policy = await client.access.policy.create({
60
- subjects: user.ontologyID("1"),
59
+ subjects: "user",
61
60
  objects: [],
62
61
  actions: [],
63
62
  });
64
63
  expect(policy.key).toBeDefined();
65
64
  expect(policy.subjects.length).toEqual(1);
66
- expect(policy.subjects[0].key).toEqual("1");
67
- expect(policy.subjects[0].type).toEqual(user.ONTOLOGY_TYPE);
65
+ expect(policy.subjects[0].key).toEqual("");
66
+ expect(policy.subjects[0].type).toEqual("user");
68
67
  expect(policy.objects).toHaveLength(0);
69
68
  expect(policy.actions).toHaveLength(0);
70
- const retrievedPolicy = await client.access.policy.retrieve(policy.key);
69
+ const retrievedPolicy = await client.access.policy.retrieve({
70
+ key: policy.key,
71
+ });
71
72
  expect(retrievedPolicy).toMatchObject(policy);
72
73
  });
73
74
  test("with key", async () => {
74
75
  const policy = await client.access.policy.create({
75
76
  subjects: [
76
- { type: user.ONTOLOGY_TYPE, key: "1" },
77
- { type: channel.ONTOLOGY_TYPE, key: "2" },
77
+ { type: "user", key: "1" },
78
+ { type: "channel", key: "2" },
78
79
  ],
79
- objects: { type: channel.ONTOLOGY_TYPE, key: "3" },
80
+ objects: { type: "channel", key: "3" },
80
81
  actions: ["delete", "retrieve"],
81
82
  });
82
83
  expect(policy.key).toBeDefined();
83
84
  expect(policy.subjects.length).toEqual(2);
84
85
  expect(policy.subjects[0].key).toEqual("1");
85
- expect(policy.subjects[0].type).toEqual(user.ONTOLOGY_TYPE);
86
+ expect(policy.subjects[0].type).toEqual("user");
86
87
  expect(policy.subjects[1].key).toEqual("2");
87
- expect(policy.subjects[1].type).toEqual(channel.ONTOLOGY_TYPE);
88
+ expect(policy.subjects[1].type).toEqual("channel");
88
89
  expect(policy.objects.length).toEqual(1);
89
90
  expect(policy.objects[0].key).toEqual("3");
90
- expect(policy.objects[0].type).toEqual(channel.ONTOLOGY_TYPE);
91
+ expect(policy.objects[0].type).toEqual("channel");
91
92
  expect(policy.actions).toEqual(["delete", "retrieve"]);
92
93
  await client.access.policy.delete(policy.key);
93
94
  });
@@ -96,21 +97,21 @@ describe("Policy", () => {
96
97
  test("with keys", async () => {
97
98
  const policiesToCreate: policy.New[] = [
98
99
  {
99
- subjects: [{ type: user.ONTOLOGY_TYPE, key: "10" }],
100
+ subjects: [{ type: "user", key: "10" }],
100
101
  objects: [
101
- { type: user.ONTOLOGY_TYPE, key: "20" },
102
- { type: schematic.ONTOLOGY_TYPE, key: "21" },
102
+ { type: "user", key: "20" },
103
+ { type: "schematic", key: "21" },
103
104
  ],
104
105
  actions: ["retrieve"],
105
106
  },
106
107
  {
107
108
  subjects: [
108
- { type: user.ONTOLOGY_TYPE, key: "20" },
109
- { type: schematic.ONTOLOGY_TYPE, key: "21" },
109
+ { type: "user", key: "20" },
110
+ { type: "schematic", key: "21" },
110
111
  ],
111
112
  objects: [
112
- { type: user.ONTOLOGY_TYPE, key: "20" },
113
- { type: schematic.ONTOLOGY_TYPE, key: "30" },
113
+ { type: "user", key: "20" },
114
+ { type: "schematic", key: "30" },
114
115
  ],
115
116
  actions: ["delete"],
116
117
  },
@@ -123,13 +124,13 @@ describe("Policy", () => {
123
124
  test("without keys", async () => {
124
125
  const policies = await client.access.policy.create([
125
126
  {
126
- subjects: user.ONTOLOGY_TYPE,
127
- objects: [user.ONTOLOGY_TYPE, schematic.ONTOLOGY_TYPE],
127
+ subjects: "user",
128
+ objects: ["user", "schematic"],
128
129
  actions: ["retrieve"],
129
130
  },
130
131
  {
131
- subjects: [user.ONTOLOGY_TYPE, schematic.ONTOLOGY_TYPE],
132
- objects: [channel.ONTOLOGY_TYPE],
132
+ subjects: ["user", "schematic"],
133
+ objects: ["channel"],
133
134
  actions: "retrieve",
134
135
  },
135
136
  ]);
@@ -137,22 +138,22 @@ describe("Policy", () => {
137
138
  expect(policies[0].key).toBeDefined();
138
139
  expect(policies[0].subjects.length).toEqual(1);
139
140
  expect(policies[0].subjects[0].key).toEqual("");
140
- expect(policies[0].subjects[0].type).toEqual(user.ONTOLOGY_TYPE);
141
+ expect(policies[0].subjects[0].type).toEqual("user");
141
142
  expect(policies[0].objects.length).toEqual(2);
142
143
  expect(policies[0].objects[0].key).toEqual("");
143
144
  expect(policies[0].objects[1].key).toEqual("");
144
- expect(policies[0].objects[0].type).toEqual(user.ONTOLOGY_TYPE);
145
- expect(policies[0].objects[1].type).toEqual(schematic.ONTOLOGY_TYPE);
145
+ expect(policies[0].objects[0].type).toEqual("user");
146
+ expect(policies[0].objects[1].type).toEqual("schematic");
146
147
  expect(policies[0].actions).toEqual(["retrieve"]);
147
148
  expect(policies[1].key).toBeDefined();
148
149
  expect(policies[1].subjects.length).toEqual(2);
149
150
  expect(policies[1].subjects[0].key).toEqual("");
150
151
  expect(policies[1].subjects[1].key).toEqual("");
151
- expect(policies[1].subjects[0].type).toEqual(user.ONTOLOGY_TYPE);
152
- expect(policies[1].subjects[1].type).toEqual(schematic.ONTOLOGY_TYPE);
152
+ expect(policies[1].subjects[0].type).toEqual("user");
153
+ expect(policies[1].subjects[1].type).toEqual("schematic");
153
154
  expect(policies[1].objects.length).toEqual(1);
154
155
  expect(policies[1].objects[0].key).toEqual("");
155
- expect(policies[1].objects[0].type).toEqual(channel.ONTOLOGY_TYPE);
156
+ expect(policies[1].objects[0].type).toEqual("channel");
156
157
  expect(policies[1].actions).toEqual(["retrieve"]);
157
158
  await client.access.policy.delete([policies[0].key, policies[1].key]);
158
159
  });
@@ -162,22 +163,21 @@ describe("Policy", () => {
162
163
  test("by key", async () => {
163
164
  const policies = await client.access.policy.create([
164
165
  {
165
- subjects: user.ONTOLOGY_TYPE,
166
- objects: [user.ONTOLOGY_TYPE, channel.ONTOLOGY_TYPE],
166
+ subjects: "user",
167
+ objects: ["user", "channel"],
167
168
  actions: "delete",
168
169
  },
169
170
  {
170
- subjects: user.ONTOLOGY_TYPE,
171
- objects: [schematic.ONTOLOGY_TYPE, channel.ONTOLOGY_TYPE],
171
+ subjects: "user",
172
+ objects: ["schematic", "channel"],
172
173
  actions: "retrieve",
173
174
  },
174
175
  ]);
175
- const result = await client.access.policy.retrieve(policies[0].key);
176
+ const result = await client.access.policy.retrieve({ key: policies[0].key });
176
177
  expect(result).toMatchObject(policies[0]);
177
- const results = await client.access.policy.retrieve([
178
- policies[0].key,
179
- policies[1].key,
180
- ]);
178
+ const results = await client.access.policy.retrieve({
179
+ keys: [policies[0].key, policies[1].key],
180
+ });
181
181
  expect(results).toHaveLength(2);
182
182
  expect(results[0]).toMatchObject(policies[0]);
183
183
  expect(results[1]).toMatchObject(policies[1]);
@@ -190,25 +190,27 @@ describe("Policy", () => {
190
190
  const created = await client.access.policy.create([
191
191
  {
192
192
  subjects: [
193
- { type: user.ONTOLOGY_TYPE, key: key1 },
194
- { type: user.ONTOLOGY_TYPE, key: key2 },
193
+ { type: "user", key: key1 },
194
+ { type: "user", key: key2 },
195
195
  ],
196
196
  objects: [
197
- { type: user.ONTOLOGY_TYPE, key: "234" },
198
- { type: channel.ONTOLOGY_TYPE, key: "30" },
197
+ { type: "user", key: "234" },
198
+ { type: "channel", key: "30" },
199
199
  ],
200
200
  actions: ["retrieve"],
201
201
  },
202
202
  {
203
- subjects: { type: user.ONTOLOGY_TYPE, key: key1 },
203
+ subjects: { type: "user", key: key1 },
204
204
  objects: [
205
- { type: label.ONTOLOGY_TYPE, key: "23123" },
206
- { type: channel.ONTOLOGY_TYPE, key: "30" },
205
+ { type: "label", key: "23123" },
206
+ { type: "channel", key: "30" },
207
207
  ],
208
208
  actions: "delete",
209
209
  },
210
210
  ]);
211
- const received = await client.access.policy.retrieveFor(user.ontologyID(key2));
211
+ const received = await client.access.policy.retrieve({
212
+ for: user.ontologyID(key2),
213
+ });
212
214
  const newReceived = received.filter((p) => created.some((c) => c.key === p.key));
213
215
  expect(created[0]).toMatchObject(newReceived[0]);
214
216
  await client.access.policy.delete([created[0].key, created[1].key]);
@@ -222,23 +224,23 @@ describe("Policy", () => {
222
224
  const policies: policy.New[] = [
223
225
  {
224
226
  subjects: [
225
- { type: user.ONTOLOGY_TYPE, key: id1 },
226
- { type: user.ONTOLOGY_TYPE, key: id2 },
227
+ { type: "user", key: id1 },
228
+ { type: "user", key: id2 },
227
229
  ],
228
230
  objects: [
229
- { type: user.ONTOLOGY_TYPE, key: "20" },
230
- { type: channel.ONTOLOGY_TYPE, key: "30" },
231
+ { type: "user", key: "20" },
232
+ { type: "channel", key: "30" },
231
233
  ],
232
234
  actions: ["retrieve"],
233
235
  },
234
236
  {
235
237
  subjects: [
236
- { type: user.ONTOLOGY_TYPE, key: id1 },
237
- { type: user.ONTOLOGY_TYPE, key: id3 },
238
+ { type: "user", key: id1 },
239
+ { type: "user", key: id3 },
238
240
  ],
239
241
  objects: [
240
- { type: label.ONTOLOGY_TYPE, key: "20" },
241
- { type: channel.ONTOLOGY_TYPE, key: "30" },
242
+ { type: "label", key: "20" },
243
+ { type: "channel", key: "30" },
242
244
  ],
243
245
  actions: ["delete"],
244
246
  },
@@ -246,7 +248,9 @@ describe("Policy", () => {
246
248
 
247
249
  const created = await client.access.policy.create(policies);
248
250
  await client.access.policy.delete(created[0].key);
249
- await expect(client.access.policy.retrieve(created[0].key)).rejects.toThrow();
251
+ await expect(
252
+ client.access.policy.retrieve({ key: created[0].key }),
253
+ ).rejects.toThrow();
250
254
  await client.access.policy.delete(created[1].key);
251
255
  });
252
256
  test("many", async () => {
@@ -256,23 +260,23 @@ describe("Policy", () => {
256
260
  const policies: policy.New[] = [
257
261
  {
258
262
  subjects: [
259
- { type: user.ONTOLOGY_TYPE, key: id1 },
260
- { type: user.ONTOLOGY_TYPE, key: id2 },
263
+ { type: "user", key: id1 },
264
+ { type: "user", key: id2 },
261
265
  ],
262
266
  objects: [
263
- { type: user.ONTOLOGY_TYPE, key: "20" },
264
- { type: channel.ONTOLOGY_TYPE, key: "30" },
267
+ { type: "user", key: "20" },
268
+ { type: "channel", key: "30" },
265
269
  ],
266
270
  actions: ["retrieve"],
267
271
  },
268
272
  {
269
273
  subjects: [
270
- { type: user.ONTOLOGY_TYPE, key: id1 },
271
- { type: user.ONTOLOGY_TYPE, key: id3 },
274
+ { type: "user", key: id1 },
275
+ { type: "user", key: id3 },
272
276
  ],
273
277
  objects: [
274
- { type: label.ONTOLOGY_TYPE, key: "20" },
275
- { type: channel.ONTOLOGY_TYPE, key: "30" },
278
+ { type: "label", key: "20" },
279
+ { type: "channel", key: "30" },
276
280
  ],
277
281
  actions: ["delete"],
278
282
  },
@@ -280,8 +284,12 @@ describe("Policy", () => {
280
284
 
281
285
  const created = await client.access.policy.create(policies);
282
286
  await client.access.policy.delete([created[0].key, created[1].key]);
283
- await expect(client.access.policy.retrieve(created[0].key)).rejects.toThrow();
284
- await expect(client.access.policy.retrieve(created[1].key)).rejects.toThrow();
287
+ await expect(
288
+ client.access.policy.retrieve({ key: created[0].key }),
289
+ ).rejects.toThrow();
290
+ await expect(
291
+ client.access.policy.retrieve({ key: created[1].key }),
292
+ ).rejects.toThrow();
285
293
  });
286
294
  });
287
295
  });
@@ -291,19 +299,14 @@ describe("privilege", async () => {
291
299
  const username = id.create();
292
300
  const user2 = await client.user.create({ username, password: "pwd1" });
293
301
  expect(user2).toBeDefined();
294
- const client2 = new Synnax({
295
- host: HOST,
296
- port: PORT,
297
- username: user2.username,
298
- password: "pwd1",
299
- });
302
+ const client2 = createTestClient({ username: user2.username, password: "pwd1" });
300
303
  await expect(
301
304
  client2.user.create({ username: id.create(), password: id.create() }),
302
305
  ).rejects.toThrow(AuthError);
303
306
 
304
307
  const policy = await client.access.policy.create({
305
- subjects: user.ontologyID(user2.key),
306
- objects: user.ONTOLOGY_TYPE,
308
+ subjects: "user",
309
+ objects: "user",
307
310
  actions: ["create"],
308
311
  });
309
312
 
@@ -13,7 +13,7 @@ import { describe, expect, it, test } from "vitest";
13
13
 
14
14
  import { auth } from "@/auth";
15
15
  import { AuthError, ExpiredTokenError, InvalidTokenError } from "@/errors";
16
- import { HOST, PORT } from "@/setupspecs";
16
+ import { TEST_CLIENT_PROPS } from "@/testutil/client";
17
17
  import { Transport } from "@/transport";
18
18
 
19
19
  const DUMMY_CTX: Context = {
@@ -25,20 +25,27 @@ const DUMMY_CTX: Context = {
25
25
 
26
26
  describe("auth", () => {
27
27
  test("valid credentials", async () => {
28
- const transport = new Transport(new URL({ host: HOST, port: PORT }));
29
- const client = new auth.Client(transport.unary, {
30
- username: "synnax",
31
- password: "seldon",
32
- });
28
+ const transport = new Transport(
29
+ new URL({
30
+ host: TEST_CLIENT_PROPS.host,
31
+ port: Number(TEST_CLIENT_PROPS.port),
32
+ }),
33
+ );
34
+ const client = new auth.Client(transport.unary, TEST_CLIENT_PROPS);
33
35
  const mw = client.middleware();
34
36
  const res = await mw(DUMMY_CTX, async () => [DUMMY_CTX, null]);
35
37
  expect(res).toEqual([DUMMY_CTX, null]);
36
38
  });
37
39
 
38
40
  test("invalid credentials", async () => {
39
- const transport = new Transport(new URL({ host: HOST, port: PORT }));
41
+ const transport = new Transport(
42
+ new URL({
43
+ host: TEST_CLIENT_PROPS.host,
44
+ port: Number(TEST_CLIENT_PROPS.port),
45
+ }),
46
+ );
40
47
  const client = new auth.Client(transport.unary, {
41
- username: "synnax",
48
+ ...TEST_CLIENT_PROPS,
42
49
  password: "wrong",
43
50
  });
44
51
  const mw = client.middleware();
@@ -50,11 +57,13 @@ describe("auth", () => {
50
57
  const ERROR_TYPES = [InvalidTokenError, ExpiredTokenError];
51
58
  ERROR_TYPES.forEach((ErrorType) => {
52
59
  it(`should re-authenticate and retry the request for ${ErrorType.name}`, async () => {
53
- const transport = new Transport(new URL({ host: HOST, port: PORT }));
54
- const client = new auth.Client(transport.unary, {
55
- username: "synnax",
56
- password: "seldon",
57
- });
60
+ const transport = new Transport(
61
+ new URL({
62
+ host: TEST_CLIENT_PROPS.host,
63
+ port: Number(TEST_CLIENT_PROPS.port),
64
+ }),
65
+ );
66
+ const client = new auth.Client(transport.unary, TEST_CLIENT_PROPS);
58
67
  const mw = client.middleware();
59
68
  let isFirst = true;
60
69
  let tkOne: string | undefined;
@@ -75,11 +84,13 @@ describe("auth", () => {
75
84
  });
76
85
 
77
86
  it("should fail after MAX_RETRIES", async () => {
78
- const transport = new Transport(new URL({ host: HOST, port: PORT }));
79
- const client = new auth.Client(transport.unary, {
80
- username: "synnax",
81
- password: "seldon",
82
- });
87
+ const transport = new Transport(
88
+ new URL({
89
+ host: TEST_CLIENT_PROPS.host,
90
+ port: Number(TEST_CLIENT_PROPS.port),
91
+ }),
92
+ );
93
+ const client = new auth.Client(transport.unary, TEST_CLIENT_PROPS);
83
94
  const mw = client.middleware();
84
95
  const [, err] = await mw(DUMMY_CTX, async () => [
85
96
  DUMMY_CTX,
package/src/auth/auth.ts CHANGED
@@ -8,7 +8,7 @@
8
8
  // included in the file licenses/APL.txt.
9
9
 
10
10
  import { type Middleware, sendRequired, type UnaryClient } from "@synnaxlabs/freighter";
11
- import { z } from "zod/v4";
11
+ import { z } from "zod";
12
12
 
13
13
  import { ExpiredTokenError, InvalidTokenError } from "@/errors";
14
14
  import { user } from "@/user";
@@ -7,6 +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 { errors } from "@synnaxlabs/x";
10
11
  import { DataType, Rate } from "@synnaxlabs/x/telem";
11
12
  import { describe, expect, it, vi } from "vitest";
12
13
 
@@ -27,18 +28,12 @@ class MockRetriever implements channel.Retriever {
27
28
  this.func = func;
28
29
  }
29
30
 
30
- async search(): Promise<channel.Payload[]> {
31
- throw new Error("Method not implemented.");
32
- }
33
-
34
- async page(): Promise<channel.Payload[]> {
35
- throw new Error("Method not implemented.");
36
- }
37
-
38
31
  async retrieve(
39
- channels: channel.Params,
32
+ channels: channel.Params | channel.RetrieveRequest,
40
33
  options?: channel.RetrieveOptions,
41
34
  ): Promise<channel.Payload[]> {
35
+ if (typeof channels === "object" && !Array.isArray(channels))
36
+ throw new errors.NotImplemented();
42
37
  return await this.func(channels, options);
43
38
  }
44
39
  }
@@ -11,10 +11,10 @@ import { DataType, TimeStamp } from "@synnaxlabs/x/telem";
11
11
  import { beforeAll, describe, expect, it, test } from "vitest";
12
12
 
13
13
  import { Channel } from "@/channel/client";
14
- import { NotFoundError } from "@/errors";
15
- import { newClient } from "@/setupspecs";
14
+ import { NotFoundError, PathError } from "@/errors";
15
+ import { createTestClient } from "@/testutil/client";
16
16
 
17
- const client = newClient();
17
+ const client = createTestClient();
18
18
 
19
19
  describe("Channel", () => {
20
20
  describe("create", () => {
@@ -26,7 +26,7 @@ describe("Channel", () => {
26
26
  });
27
27
  expect(channel.name, "test").toEqual("test");
28
28
  expect(channel.leaseholder).toEqual(1);
29
- expect(channel.virtual).toBeTruthy();
29
+ expect(channel.virtual).toBe(true);
30
30
  expect(channel.dataType).toEqual(DataType.FLOAT32);
31
31
  }, 80000);
32
32
 
@@ -51,6 +51,24 @@ describe("Channel", () => {
51
51
  expect(calculatedCH.requires).toEqual([chOne.key]);
52
52
  });
53
53
 
54
+ test("create calculated, missing required channel", async () => {
55
+ try {
56
+ await client.channels.create({
57
+ name: "test",
58
+ virtual: true,
59
+ dataType: DataType.FLOAT32,
60
+ expression: "test * 2",
61
+ requires: [],
62
+ });
63
+ } catch (e) {
64
+ expect(PathError.matches(e)).toBe(true);
65
+ expect((e as PathError).path).toEqual(["requires"]);
66
+ expect((e as PathError).error.message).contain(
67
+ "calculated channels must require at least one channel",
68
+ );
69
+ }
70
+ });
71
+
54
72
  test("create index and indexed pair", async () => {
55
73
  const one = await client.channels.create({
56
74
  name: "Time",
@@ -112,7 +130,7 @@ describe("Channel", () => {
112
130
  });
113
131
  expect(channel.virtual).toEqual(true);
114
132
  const retrieved = await client.channels.retrieve(channel.key);
115
- expect(retrieved.virtual).toBeTruthy();
133
+ expect(retrieved.virtual).toBe(true);
116
134
  });
117
135
  });
118
136
 
@@ -270,7 +288,7 @@ describe("Channel", () => {
270
288
  });
271
289
  });
272
290
 
273
- describe("update", () => {
291
+ describe("update calculations", () => {
274
292
  let idxCH: Channel;
275
293
  beforeAll(async () => {
276
294
  idxCH = await client.channels.create({