@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
@@ -11,36 +11,34 @@ import { sendRequired, type UnaryClient } from "@synnaxlabs/freighter";
11
11
  import { z } from "zod";
12
12
 
13
13
  import {
14
+ channelZ,
14
15
  type Key,
15
16
  keyZ,
16
- type NewPayload,
17
- newPayload,
17
+ nameZ,
18
+ type New,
19
+ newZ,
18
20
  type Payload,
19
- payload,
20
21
  } from "@/channel/payload";
21
22
  import { type CacheRetriever } from "@/channel/retriever";
22
23
 
23
- const createReqZ = z.object({ channels: newPayload.array() });
24
- const createResZ = z.object({ channels: payload.array() });
24
+ const createReqZ = z.object({ channels: newZ.array() });
25
+ const createResZ = z.object({ channels: channelZ.array() });
25
26
 
26
27
  const deleteReqZ = z.object({
27
28
  keys: keyZ.array().optional(),
28
- names: z.string().array().optional(),
29
+ names: nameZ.array().optional(),
29
30
  });
30
31
  const deleteResZ = z.object({});
31
32
 
32
- const renameReqZ = z.object({
33
- keys: keyZ.array(),
34
- names: z.string().array(),
35
- });
33
+ const renameReqZ = z.object({ keys: keyZ.array(), names: nameZ.array() });
36
34
  const renameResZ = z.object({});
37
35
 
38
36
  const CREATE_ENDPOINT = "/channel/create";
39
37
  const DELETE_ENDPOINT = "/channel/delete";
40
38
  const RENAME_ENDPOINT = "/channel/rename";
41
39
 
42
- export type DeleteProps = z.input<typeof deleteReqZ>;
43
- export type RenameProps = z.input<typeof renameReqZ>;
40
+ export interface DeleteProps extends z.input<typeof deleteReqZ> {}
41
+ export interface RenameProps extends z.input<typeof renameReqZ> {}
44
42
 
45
43
  export class Writer {
46
44
  private readonly client: UnaryClient;
@@ -51,7 +49,7 @@ export class Writer {
51
49
  this.cache = cache;
52
50
  }
53
51
 
54
- async create(channels: NewPayload[]): Promise<Payload[]> {
52
+ async create(channels: New[]): Promise<Payload[]> {
55
53
  const { channels: created } = await sendRequired<
56
54
  typeof createReqZ,
57
55
  typeof createResZ
package/src/client.ts CHANGED
@@ -31,20 +31,10 @@ import { user } from "@/user";
31
31
  import { workspace } from "@/workspace";
32
32
 
33
33
  export const synnaxPropsZ = z.object({
34
- host: z
35
- .string({
36
- required_error: "Host is required",
37
- })
38
- .min(1, "Host is required"),
34
+ host: z.string({ required_error: "Host is required" }).min(1, "Host is required"),
39
35
  port: z
40
- .number({
41
- required_error: "Port is required",
42
- })
43
- .or(
44
- z.string({
45
- required_error: "Port is required",
46
- }),
47
- ),
36
+ .number({ required_error: "Port is required" })
37
+ .or(z.string({ required_error: "Port is required" })),
48
38
  username: z.string().min(1, "Username is required"),
49
39
  password: z.string().min(1, "Password is required"),
50
40
  connectivityPollFrequency: TimeSpan.z.default(TimeSpan.seconds(30)),
@@ -53,8 +43,8 @@ export const synnaxPropsZ = z.object({
53
43
  retry: breaker.breakerConfig.optional(),
54
44
  });
55
45
 
56
- export type SynnaxProps = z.input<typeof synnaxPropsZ>;
57
- export type ParsedSynnaxProps = z.output<typeof synnaxPropsZ>;
46
+ export interface SynnaxProps extends z.input<typeof synnaxPropsZ> {}
47
+ export interface ParsedSynnaxProps extends z.output<typeof synnaxPropsZ> {}
58
48
 
59
49
  /**
60
50
  * Client to perform operations against a Synnax cluster.
@@ -161,7 +151,7 @@ export default class Synnax extends framer.Client {
161
151
  this.ontology,
162
152
  this.ranges,
163
153
  );
164
- const racks = new rack.Client(this.transport.unary, this, tasks);
154
+ const racks = new rack.Client(this.transport.unary, tasks);
165
155
  this.hardware = new hardware.Client(tasks, racks, devices);
166
156
  }
167
157
 
@@ -12,12 +12,11 @@ import { migrate } from "@synnaxlabs/x";
12
12
  import { TimeSpan } from "@synnaxlabs/x/telem";
13
13
  import { z } from "zod";
14
14
 
15
- const STATUSES = ["disconnected", "connecting", "connected", "failed"] as const;
16
- export const status = z.enum(STATUSES);
17
- export type Status = z.infer<typeof status>;
15
+ export const statusZ = z.enum(["disconnected", "connecting", "connected", "failed"]);
16
+ export type Status = z.infer<typeof statusZ>;
18
17
 
19
- export const state = z.object({
20
- status,
18
+ export const stateZ = z.object({
19
+ status: statusZ,
21
20
  error: z.instanceof(Error).optional(),
22
21
  message: z.string().optional(),
23
22
  clusterKey: z.string(),
@@ -25,8 +24,7 @@ export const state = z.object({
25
24
  clientServerCompatible: z.boolean(),
26
25
  nodeVersion: z.string().optional(),
27
26
  });
28
-
29
- export type State = z.infer<typeof state>;
27
+ export interface State extends z.infer<typeof stateZ> {}
30
28
 
31
29
  const responseZ = z.object({
32
30
  clusterKey: z.string(),
@@ -42,7 +40,7 @@ const DEFAULT: State = {
42
40
  clientVersion: __VERSION__,
43
41
  };
44
42
 
45
- const generateWarning = (
43
+ const createWarning = (
46
44
  nodeVersion: string | null,
47
45
  clientVersion: string,
48
46
  clientIsNewer: boolean,
@@ -64,7 +62,7 @@ export class Checker {
64
62
  private interval?: NodeJS.Timeout;
65
63
  private readonly clientVersion: string;
66
64
  private readonly onChangeHandlers: Array<(state: State) => void> = [];
67
- static readonly connectionStateZ = state;
65
+ static readonly connectionStateZ = stateZ;
68
66
  private versionWarned = false;
69
67
 
70
68
  /**
@@ -112,7 +110,7 @@ export class Checker {
112
110
  if (nodeVersion == null) {
113
111
  this._state.clientServerCompatible = false;
114
112
  if (!warned) {
115
- console.warn(generateWarning(null, clientVersion, true));
113
+ console.warn(createWarning(null, clientVersion, true));
116
114
  this.versionWarned = true;
117
115
  }
118
116
  } else if (
@@ -125,7 +123,7 @@ export class Checker {
125
123
  this._state.clientServerCompatible = false;
126
124
  if (!warned) {
127
125
  console.warn(
128
- generateWarning(
126
+ createWarning(
129
127
  nodeVersion,
130
128
  clientVersion,
131
129
  migrate.semVerNewer(clientVersion, nodeVersion),
@@ -12,7 +12,7 @@ import { describe, expect, it } from "vitest";
12
12
  import { z } from "zod";
13
13
 
14
14
  import { auth } from "@/auth";
15
- import { Checker } from "@/connection/checker";
15
+ import { connection } from "@/connection";
16
16
  import { HOST, PORT } from "@/setupspecs";
17
17
  import { Transport } from "@/transport";
18
18
 
@@ -24,7 +24,11 @@ describe("connectivity", () => {
24
24
  password: "seldon",
25
25
  });
26
26
  transport.use(client.middleware());
27
- const connectivity = new Checker(transport.unary, undefined, __VERSION__);
27
+ const connectivity = new connection.Checker(
28
+ transport.unary,
29
+ undefined,
30
+ __VERSION__,
31
+ );
28
32
  const state = await connectivity.check();
29
33
  expect(state.status).toEqual("connected");
30
34
  expect(z.string().uuid().safeParse(state.clusterKey).success).toBe(true);
@@ -37,7 +41,11 @@ describe("connectivity", () => {
37
41
  password: "seldon",
38
42
  });
39
43
  transport.use(client.middleware());
40
- const connectivity = new Checker(transport.unary, undefined, __VERSION__);
44
+ const connectivity = new connection.Checker(
45
+ transport.unary,
46
+ undefined,
47
+ __VERSION__,
48
+ );
41
49
  const state = await connectivity.check();
42
50
  expect(state.clientServerCompatible).toBe(true);
43
51
  expect(state.clientVersion).toBe(__VERSION__);
@@ -49,7 +57,11 @@ describe("connectivity", () => {
49
57
  password: "seldon",
50
58
  });
51
59
  transport.use(client.middleware());
52
- const connectivity = new Checker(transport.unary, undefined, "50000.0.0");
60
+ const connectivity = new connection.Checker(
61
+ transport.unary,
62
+ undefined,
63
+ "50000.0.0",
64
+ );
53
65
  const state = await connectivity.check();
54
66
  expect(state.clientServerCompatible).toBe(false);
55
67
  expect(state.clientVersion).toBe("50000.0.0");
@@ -61,7 +73,7 @@ describe("connectivity", () => {
61
73
  password: "seldon",
62
74
  });
63
75
  transport.use(client.middleware());
64
- const connectivity = new Checker(transport.unary, undefined, "0.0.0");
76
+ const connectivity = new connection.Checker(transport.unary, undefined, "0.0.0");
65
77
  const state = await connectivity.check();
66
78
  expect(state.clientServerCompatible).toBe(false);
67
79
  expect(state.clientVersion).toBe("0.0.0");
@@ -12,15 +12,14 @@ import { binary } from "@synnaxlabs/x/binary";
12
12
  import { type observe } from "@synnaxlabs/x/observe";
13
13
  import { z } from "zod";
14
14
 
15
- import { type Key as ChannelKey } from "@/channel/payload";
15
+ import { type channel } from "@/channel";
16
16
  import { framer } from "@/framer";
17
- import { type Streamer as FrameStreamer } from "@/framer/streamer";
18
17
 
19
- export type Authority = control.Authority;
18
+ export interface Authority extends control.Authority {}
20
19
  export const Authority = control.Authority;
21
- export type Transfer = control.Transfer<ChannelKey>;
22
- export type State = control.State<ChannelKey>;
23
- export type Subject = control.Subject;
20
+ export type Transfer = control.Transfer<channel.Key>;
21
+ export interface State extends control.State<channel.Key> {}
22
+ export interface Subject extends control.Subject {}
24
23
  export const stateZ = control.stateZ(z.number());
25
24
 
26
25
  export const transferString = (t: Transfer): string => {
@@ -35,17 +34,17 @@ export const transferString = (t: Transfer): string => {
35
34
  };
36
35
 
37
36
  interface Update {
38
- transfers: control.Transfer<ChannelKey>[];
37
+ transfers: control.Transfer<channel.Key>[];
39
38
  }
40
39
 
41
40
  export class StateTracker
42
41
  extends framer.ObservableStreamer<Transfer[]>
43
42
  implements observe.ObservableAsyncCloseable<Transfer[]>
44
43
  {
45
- readonly states: Map<ChannelKey, State>;
44
+ readonly states: Map<channel.Key, State>;
46
45
  private readonly codec: binary.Codec;
47
46
 
48
- constructor(streamer: FrameStreamer) {
47
+ constructor(streamer: framer.Streamer) {
49
48
  super(streamer, (frame) => {
50
49
  const update: Update = this.codec.decode(frame.series[0].buffer);
51
50
  this.merge(update);
@@ -55,7 +55,7 @@ const client = newClient();
55
55
  test("client", async () => {
56
56
  expect.assertions(2);
57
57
  try {
58
- await client.channels.retrieve(id.id());
58
+ await client.channels.retrieve(id.create());
59
59
  } catch (e) {
60
60
  expect(NotFoundError.matches(e)).toBe(true);
61
61
  }
package/src/errors.ts CHANGED
@@ -64,6 +64,12 @@ export class InvalidTokenError extends AuthError {
64
64
  static readonly matches = errorMatcher(InvalidTokenError.TYPE);
65
65
  }
66
66
 
67
+ export class ExpiredTokenError extends AuthError {
68
+ static readonly TYPE = `${AuthError.TYPE}.expired-token`;
69
+ type = ExpiredTokenError.TYPE;
70
+ static readonly matches = errorMatcher(ExpiredTokenError.TYPE);
71
+ }
72
+
67
73
  /**
68
74
  * UnexpectedError is raised when an unexpected error occurs.
69
75
  */
@@ -154,6 +160,8 @@ const decode = (payload: ErrorPayload): Error | null => {
154
160
  if (payload.type.startsWith(AuthError.TYPE)) {
155
161
  if (payload.type.startsWith(InvalidTokenError.TYPE))
156
162
  return new InvalidTokenError(payload.data);
163
+ if (payload.type.startsWith(ExpiredTokenError.TYPE))
164
+ return new ExpiredTokenError(payload.data);
157
165
  return new AuthError(payload.data);
158
166
  }
159
167
 
@@ -11,7 +11,7 @@ import { DataType, Series, TimeStamp } from "@synnaxlabs/x/telem";
11
11
  import { beforeAll, describe, expect, it } from "vitest";
12
12
 
13
13
  import { type channel } from "@/channel";
14
- import { WriteFrameAdapter } from "@/framer/adapter";
14
+ import { WriteAdapter } from "@/framer/adapter";
15
15
  import { Frame } from "@/index";
16
16
  import { newClient } from "@/setupspecs";
17
17
 
@@ -20,7 +20,7 @@ const client = newClient();
20
20
  describe("WriteFrameAdapter", () => {
21
21
  let timeCh: channel.Channel;
22
22
  let dataCh: channel.Channel;
23
- let adapter: WriteFrameAdapter;
23
+ let adapter: WriteAdapter;
24
24
 
25
25
  beforeAll(async () => {
26
26
  timeCh = await client.channels.create({
@@ -34,7 +34,7 @@ describe("WriteFrameAdapter", () => {
34
34
  index: timeCh.key,
35
35
  });
36
36
 
37
- adapter = await WriteFrameAdapter.open(client.channels.retriever, [
37
+ adapter = await WriteAdapter.open(client.channels.retriever, [
38
38
  timeCh.key,
39
39
  dataCh.key,
40
40
  ]);
@@ -42,10 +42,7 @@ describe("WriteFrameAdapter", () => {
42
42
 
43
43
  it("should correctly adapt a record of keys to single values", async () => {
44
44
  const ts = TimeStamp.now().valueOf();
45
- const res = await adapter.adapt({
46
- [timeCh.key]: ts,
47
- [dataCh.key]: 1,
48
- });
45
+ const res = await adapter.adapt({ [timeCh.key]: ts, [dataCh.key]: 1 });
49
46
  expect(res.columns).toHaveLength(2);
50
47
  expect(res.series).toHaveLength(2);
51
48
  expect(res.get(timeCh.key)).toHaveLength(1);
@@ -56,10 +53,7 @@ describe("WriteFrameAdapter", () => {
56
53
 
57
54
  it("should correctly adapt a record of names to single values", async () => {
58
55
  const ts = TimeStamp.now().valueOf();
59
- const res2 = await adapter.adapt({
60
- [timeCh.name]: ts,
61
- [dataCh.name]: 1,
62
- });
56
+ const res2 = await adapter.adapt({ [timeCh.name]: ts, [dataCh.name]: 1 });
63
57
  expect(res2.columns).toHaveLength(2);
64
58
  expect(res2.series).toHaveLength(2);
65
59
  expect(res2.get(timeCh.key)).toHaveLength(1);
@@ -103,10 +97,7 @@ describe("WriteFrameAdapter", () => {
103
97
 
104
98
  it("should not modify a frame keyed by key", async () => {
105
99
  const ts = TimeStamp.now().valueOf();
106
- const fr = new Frame({
107
- [timeCh.key]: new Series(ts),
108
- [dataCh.key]: new Series(1),
109
- });
100
+ const fr = new Frame({ [timeCh.key]: new Series(ts), [dataCh.key]: new Series(1) });
110
101
  const res = await adapter.adapt(fr);
111
102
  expect(res.columns).toHaveLength(2);
112
103
  expect(res.series).toHaveLength(2);
@@ -131,7 +122,7 @@ describe("WriteFrameAdapter", () => {
131
122
  dataType: DataType.JSON,
132
123
  virtual: true,
133
124
  });
134
- const adapter = await WriteFrameAdapter.open(client.channels.retriever, [
125
+ const adapter = await WriteAdapter.open(client.channels.retriever, [
135
126
  jsonChannel.key,
136
127
  ]);
137
128
  const res = await adapter.adapt(jsonChannel.name, [{ dog: "blue" }]);
@@ -147,7 +138,7 @@ describe("WriteFrameAdapter", () => {
147
138
  dataType: DataType.JSON,
148
139
  virtual: true,
149
140
  });
150
- const adapter = await WriteFrameAdapter.open(client.channels.retriever, [
141
+ const adapter = await WriteAdapter.open(client.channels.retriever, [
151
142
  jsonChannel.key,
152
143
  ]);
153
144
  const res = await adapter.adapt(jsonChannel.name, new Series([{ dog: "blue" }]));
@@ -157,12 +148,26 @@ describe("WriteFrameAdapter", () => {
157
148
  expect(res.get(jsonChannel.key).at(0)).toEqual({ dog: "blue" });
158
149
  });
159
150
 
160
- it("should correctly adapt generic object keys", async () => {
161
- const res = await adapter.adaptObjectKeys({
162
- [timeCh.name]: 532,
163
- [dataCh.name]: 123,
151
+ it("should correctly adapt a numeric value to a BigInt keyed by key", async () => {
152
+ const bigIntCh = await client.channels.create({
153
+ name: `bigint-${Math.random()}-${TimeStamp.now().toString()}`,
154
+ dataType: DataType.INT64,
155
+ virtual: true,
156
+ });
157
+ const res = await adapter.adapt({
158
+ [bigIntCh.key]: 12,
159
+ });
160
+ expect(res.get(bigIntCh.key).at(0)).toEqual(12n);
161
+ });
162
+
163
+ describe("adaptObjectKeys", () => {
164
+ it("should correctly adapt generic object keys", async () => {
165
+ const res = await adapter.adaptObjectKeys({
166
+ [timeCh.name]: 532,
167
+ [dataCh.name]: 123,
168
+ });
169
+ expect(res).toHaveProperty(timeCh.key.toString());
170
+ expect(res).toHaveProperty(dataCh.key.toString());
164
171
  });
165
- expect(res).toHaveProperty(timeCh.key.toString());
166
- expect(res).toHaveProperty(dataCh.key.toString());
167
172
  });
168
173
  });
@@ -9,47 +9,39 @@
9
9
 
10
10
  import { type CrudeSeries, Series } from "@synnaxlabs/x/telem";
11
11
 
12
- import {
13
- type Key,
14
- type KeyOrName,
15
- type Name,
16
- type Params,
17
- type Payload,
18
- } from "@/channel/payload";
19
- import {
20
- analyzeChannelParams,
21
- type Retriever,
22
- retrieveRequired,
23
- } from "@/channel/retriever";
12
+ import { channel } from "@/channel";
24
13
  import { ValidationError } from "@/errors";
25
- import { type CrudeFrame, Frame } from "@/framer/frame";
14
+ import { type Crude, Frame } from "@/framer/frame";
26
15
 
27
- export class ReadFrameAdapter {
28
- private adapter: Map<Key, Name> | null;
29
- retriever: Retriever;
30
- keys: Key[];
16
+ export class ReadAdapter {
17
+ private adapter: Map<channel.Key, channel.Name> | null;
18
+ retriever: channel.Retriever;
19
+ keys: channel.Key[];
31
20
 
32
- private constructor(retriever: Retriever) {
21
+ private constructor(retriever: channel.Retriever) {
33
22
  this.retriever = retriever;
34
23
  this.adapter = null;
35
24
  this.keys = [];
36
25
  }
37
26
 
38
- static async open(retriever: Retriever, channels: Params): Promise<ReadFrameAdapter> {
39
- const adapter = new ReadFrameAdapter(retriever);
27
+ static async open(
28
+ retriever: channel.Retriever,
29
+ channels: channel.Params,
30
+ ): Promise<ReadAdapter> {
31
+ const adapter = new ReadAdapter(retriever);
40
32
  await adapter.update(channels);
41
33
  return adapter;
42
34
  }
43
35
 
44
- async update(channels: Params): Promise<void> {
45
- const { variant, normalized } = analyzeChannelParams(channels);
36
+ async update(channels: channel.Params): Promise<void> {
37
+ const { variant, normalized } = channel.analyzeParams(channels);
46
38
  if (variant === "keys") {
47
39
  this.adapter = null;
48
- this.keys = normalized as Key[];
40
+ this.keys = normalized as channel.Key[];
49
41
  return;
50
42
  }
51
43
  const fetched = await this.retriever.retrieve(normalized);
52
- const a = new Map<Key, Name>();
44
+ const a = new Map<channel.Key, channel.Name>();
53
45
  this.adapter = a;
54
46
  normalized.forEach((name) => {
55
47
  const channel = fetched.find((channel) => channel.name === name);
@@ -73,52 +65,56 @@ export class ReadFrameAdapter {
73
65
  }
74
66
  }
75
67
 
76
- export class WriteFrameAdapter {
77
- private adapter: Map<Name, Key> | null;
78
- retriever: Retriever;
79
- keys: Key[];
68
+ export class WriteAdapter {
69
+ private adapter: Map<channel.Name, channel.Key> | null;
70
+ retriever: channel.Retriever;
71
+ keys: channel.Key[];
80
72
 
81
- private constructor(retriever: Retriever) {
73
+ private constructor(retriever: channel.Retriever) {
82
74
  this.retriever = retriever;
83
75
  this.adapter = null;
84
76
  this.keys = [];
85
77
  }
86
78
 
87
79
  static async open(
88
- retriever: Retriever,
89
- channels: Params,
90
- ): Promise<WriteFrameAdapter> {
91
- const adapter = new WriteFrameAdapter(retriever);
80
+ retriever: channel.Retriever,
81
+ channels: channel.Params,
82
+ ): Promise<WriteAdapter> {
83
+ const adapter = new WriteAdapter(retriever);
92
84
  await adapter.update(channels);
93
85
  return adapter;
94
86
  }
95
87
 
96
- async adaptObjectKeys<V>(data: Record<KeyOrName, V>): Promise<Record<Key, V>> {
97
- const out: Record<Key, V> = {};
88
+ async adaptObjectKeys<V>(
89
+ data: Record<channel.KeyOrName, V>,
90
+ ): Promise<Record<channel.Key, V>> {
91
+ const out: Record<channel.Key, V> = {};
98
92
  for (const [k, v] of Object.entries(data)) out[await this.adaptToKey(k)] = v;
99
93
  return out;
100
94
  }
101
95
 
102
- async update(channels: Params): Promise<void> {
103
- const results = await retrieveRequired(this.retriever, channels);
104
- this.adapter = new Map<Name, Key>(results.map((c) => [c.name, c.key]));
96
+ async update(channels: channel.Params): Promise<void> {
97
+ const results = await channel.retrieveRequired(this.retriever, channels);
98
+ this.adapter = new Map<channel.Name, channel.Key>(
99
+ results.map((c) => [c.name, c.key]),
100
+ );
105
101
  this.keys = results.map((c) => c.key);
106
102
  }
107
103
 
108
- private async fetchChannel(ch: Key | Name): Promise<Payload> {
104
+ private async fetchChannel(ch: channel.Key | channel.Name): Promise<channel.Payload> {
109
105
  const res = await this.retriever.retrieve(ch);
110
106
  if (res.length === 0) throw new Error(`Channel ${ch} not found`);
111
107
  return res[0];
112
108
  }
113
109
 
114
- private async adaptToKey(k: KeyOrName): Promise<Key> {
110
+ private async adaptToKey(k: channel.KeyOrName): Promise<channel.Key> {
115
111
  if (typeof k === "number") return k;
116
112
  const res = await this.fetchChannel(k);
117
113
  return res.key;
118
114
  }
119
115
 
120
116
  async adapt(
121
- columnsOrData: Params | Record<KeyOrName, CrudeSeries> | CrudeFrame,
117
+ columnsOrData: channel.Params | Record<channel.KeyOrName, CrudeSeries> | Crude,
122
118
  series?: CrudeSeries | CrudeSeries[],
123
119
  ): Promise<Frame> {
124
120
  if (typeof columnsOrData === "string" || typeof columnsOrData === "number") {
@@ -29,17 +29,11 @@ describe("Client", () => {
29
29
  index: time.key,
30
30
  });
31
31
  const start = TimeStamp.now();
32
- await client.write(start, {
33
- [time.key]: [start],
34
- [data.key]: [1],
35
- });
36
- const frame = await client.read(
37
- {
38
- start,
39
- end: start.add(TimeSpan.seconds(1)),
40
- },
41
- [time.key, data.key],
42
- );
32
+ await client.write(start, { [time.key]: [start], [data.key]: [1] });
33
+ const frame = await client.read({ start, end: start.add(TimeSpan.seconds(1)) }, [
34
+ time.key,
35
+ data.key,
36
+ ]);
43
37
  expect(Array.from(frame.get(time.key))).toEqual([start.valueOf()]);
44
38
  expect(Array.from(frame.get(data.key))).toEqual([1]);
45
39
  });