@synnaxlabs/client 0.16.4 → 0.17.1

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 (73) hide show
  1. package/.turbo/turbo-build.log +5 -5
  2. package/dist/auth/auth.d.ts +2 -2
  3. package/dist/channel/client.d.ts +6 -2
  4. package/dist/client.cjs +11 -11
  5. package/dist/client.cjs.map +1 -1
  6. package/dist/client.d.ts +14 -4
  7. package/dist/client.js +5442 -5436
  8. package/dist/client.js.map +1 -1
  9. package/dist/framer/frame.d.ts +280 -24
  10. package/dist/framer/writer.d.ts +203 -15
  11. package/dist/hardware/rack/client.d.ts +1 -1
  12. package/dist/hardware/task/payload.d.ts +5 -5
  13. package/dist/ontology/retriever.d.ts +1 -1
  14. package/dist/ranger/active.d.ts +1 -1
  15. package/dist/ranger/payload.d.ts +308 -20
  16. package/dist/workspace/client.d.ts +2 -2
  17. package/dist/workspace/lineplot/client.d.ts +2 -2
  18. package/dist/workspace/lineplot/payload.d.ts +3 -16
  19. package/dist/workspace/lineplot/retriever.d.ts +0 -1
  20. package/dist/workspace/lineplot/writer.d.ts +9 -14
  21. package/dist/workspace/payload.d.ts +3 -3
  22. package/dist/workspace/pid/client.d.ts +2 -2
  23. package/dist/workspace/pid/payload.d.ts +3 -3
  24. package/dist/workspace/pid/retriever.d.ts +0 -1
  25. package/dist/workspace/pid/writer.d.ts +12 -18
  26. package/dist/workspace/writer.d.ts +14 -6
  27. package/examples/node/basicReadWrite.js +67 -0
  28. package/examples/node/package-lock.json +76 -64
  29. package/examples/node/package.json +1 -1
  30. package/examples/node/streamWrite.js +23 -0
  31. package/package.json +5 -5
  32. package/src/auth/auth.ts +5 -4
  33. package/src/channel/channel.spec.ts +68 -2
  34. package/src/channel/client.ts +18 -7
  35. package/src/channel/creator.ts +1 -0
  36. package/src/channel/retriever.ts +2 -2
  37. package/src/client.ts +2 -2
  38. package/src/connection/checker.ts +1 -1
  39. package/src/framer/client.ts +1 -1
  40. package/src/framer/frame.ts +4 -4
  41. package/src/hardware/device/retriever.ts +3 -3
  42. package/src/hardware/device/writer.ts +3 -1
  43. package/src/hardware/rack/client.ts +3 -4
  44. package/src/hardware/rack/retriever.ts +3 -0
  45. package/src/hardware/rack/writer.ts +2 -0
  46. package/src/hardware/task/payload.ts +5 -4
  47. package/src/hardware/task/retriever.ts +10 -7
  48. package/src/hardware/task/writer.ts +3 -1
  49. package/src/label/retriever.ts +1 -0
  50. package/src/label/writer.ts +4 -0
  51. package/src/ontology/group/writer.ts +18 -5
  52. package/src/ontology/retriever.ts +9 -9
  53. package/src/ontology/writer.ts +25 -11
  54. package/src/ranger/active.ts +26 -8
  55. package/src/ranger/alias.ts +9 -13
  56. package/src/ranger/client.ts +0 -1
  57. package/src/ranger/kv.ts +4 -1
  58. package/src/ranger/retriever.ts +1 -1
  59. package/src/ranger/writer.ts +3 -0
  60. package/src/workspace/client.ts +3 -3
  61. package/src/workspace/lineplot/client.ts +2 -2
  62. package/src/workspace/lineplot/payload.ts +1 -7
  63. package/src/workspace/lineplot/retriever.ts +10 -11
  64. package/src/workspace/lineplot/writer.ts +13 -8
  65. package/src/workspace/payload.ts +1 -1
  66. package/src/workspace/pid/client.ts +2 -2
  67. package/src/workspace/pid/payload.ts +1 -1
  68. package/src/workspace/pid/retriever.ts +8 -10
  69. package/src/workspace/pid/writer.ts +12 -5
  70. package/src/workspace/retriever.ts +2 -4
  71. package/src/workspace/workspace.spec.ts +4 -4
  72. package/src/workspace/writer.ts +12 -10
  73. package/examples/node/basicReadWriter.js +0 -37
@@ -43,7 +43,7 @@ export class Retriever {
43
43
  }
44
44
 
45
45
  private async execute(request: Request): Promise<Payload[]> {
46
- const [res, err] = await this.client.send(this.ENDPOINT, request, resZ);
46
+ const [res, err] = await this.client.send(this.ENDPOINT, request, reqZ, resZ);
47
47
  if (err != null) throw err;
48
48
  return res.ranges;
49
49
  }
@@ -55,6 +55,7 @@ export class Writer {
55
55
  this.client,
56
56
  RENAME_ENDPOINT,
57
57
  { key, name },
58
+ renameReqZ,
58
59
  renameResZ,
59
60
  );
60
61
  }
@@ -64,6 +65,7 @@ export class Writer {
64
65
  this.client,
65
66
  CREATE_ENDPOINT,
66
67
  { ranges },
68
+ createReqZ,
67
69
  createResZ,
68
70
  );
69
71
  return res.ranges;
@@ -74,6 +76,7 @@ export class Writer {
74
76
  this.client,
75
77
  DELETE_ENDPOINT,
76
78
  { keys },
79
+ deleteReqZ,
77
80
  deleteResZ,
78
81
  );
79
82
  }
@@ -14,7 +14,7 @@ import { linePlot } from "@/workspace/lineplot";
14
14
  import { type Key, type Workspace } from "@/workspace/payload";
15
15
  import { pid } from "@/workspace/pid";
16
16
  import { Retriever } from "@/workspace/retriever";
17
- import { type CrudeWorkspace, Writer } from "@/workspace/writer";
17
+ import { type NewWorkspace, Writer } from "@/workspace/writer";
18
18
 
19
19
  export class Client implements AsyncTermSearcher<string, Key, Workspace> {
20
20
  readonly pid: pid.Client;
@@ -51,10 +51,10 @@ export class Client implements AsyncTermSearcher<string, Key, Workspace> {
51
51
  return await this.retriever.page(offset, limit);
52
52
  }
53
53
 
54
- async create(workspace: CrudeWorkspace): Promise<Workspace>;
54
+ async create(workspace: NewWorkspace): Promise<Workspace>;
55
55
 
56
56
  async create(
57
- workspaces: CrudeWorkspace | CrudeWorkspace[],
57
+ workspaces: NewWorkspace | NewWorkspace[],
58
58
  ): Promise<Workspace | Workspace[]> {
59
59
  const isMany = Array.isArray(workspaces);
60
60
  const res = await this.writer.create(workspaces);
@@ -12,7 +12,7 @@ import { type UnknownRecord } from "@synnaxlabs/x";
12
12
 
13
13
  import { type LinePlot, type Key, type Params } from "@/workspace/lineplot/payload";
14
14
  import { Retriever } from "@/workspace/lineplot/retriever";
15
- import { type CrudeLinePlot, Writer } from "@/workspace/lineplot/writer";
15
+ import { type NewLinePlot, Writer } from "@/workspace/lineplot/writer";
16
16
 
17
17
  export class Client {
18
18
  private readonly writer: Writer;
@@ -23,7 +23,7 @@ export class Client {
23
23
  this.retriever = new Retriever(client);
24
24
  }
25
25
 
26
- async create(workspace: string, pid: CrudeLinePlot): Promise<LinePlot> {
26
+ async create(workspace: string, pid: NewLinePlot): Promise<LinePlot> {
27
27
  return await this.writer.create(workspace, pid);
28
28
  }
29
29
 
@@ -17,13 +17,7 @@ export type Params = Key | Key[];
17
17
  export const linePlotZ = z.object({
18
18
  key: z.string(),
19
19
  name: z.string(),
20
- data: unknownRecordZ,
21
- });
22
-
23
- export const linePlotRemoteZ = z.object({
24
- key: z.string(),
25
- name: z.string(),
26
- data: z.string().transform((s) => JSON.parse(s) as UnknownRecord),
20
+ data: unknownRecordZ.or(z.string().transform((s) => JSON.parse(s) as UnknownRecord)),
27
21
  });
28
22
 
29
23
  export type LinePlot = z.infer<typeof linePlotZ>;
@@ -7,14 +7,14 @@
7
7
  // License, use of this software will be governed by the Apache License, Version 2.0,
8
8
  // included in the file licenses/APL.txt.
9
9
 
10
- import { type UnaryClient } from "@synnaxlabs/freighter";
10
+ import { sendRequired, type UnaryClient } from "@synnaxlabs/freighter";
11
11
  import { toArray } from "@synnaxlabs/x";
12
12
  import { z } from "zod";
13
13
 
14
14
  import {
15
15
  type LinePlot,
16
16
  type Params,
17
- linePlotRemoteZ,
17
+ linePlotZ,
18
18
  } from "@/workspace/lineplot/payload";
19
19
 
20
20
  const reqZ = z.object({
@@ -24,7 +24,7 @@ const reqZ = z.object({
24
24
  type Request = z.infer<typeof reqZ>;
25
25
 
26
26
  const resZ = z.object({
27
- linePlots: linePlotRemoteZ.array(),
27
+ linePlots: linePlotZ.array(),
28
28
  });
29
29
 
30
30
  export class Retriever {
@@ -37,13 +37,12 @@ export class Retriever {
37
37
 
38
38
  async retrieve(params: Params): Promise<LinePlot[]> {
39
39
  const normalized = toArray(params);
40
- const res = await this.execute({ keys: normalized });
41
- return res;
42
- }
43
-
44
- private async execute(request: Request): Promise<LinePlot[]> {
45
- const [res, err] = await this.client.send(this.ENDPOINT, request, resZ);
46
- if (err != null) throw err;
47
- return res.linePlots;
40
+ return (await sendRequired(
41
+ this.client,
42
+ this.ENDPOINT,
43
+ { keys: normalized },
44
+ reqZ,
45
+ resZ
46
+ )).linePlots;
48
47
  }
49
48
  }
@@ -17,22 +17,23 @@ import {
17
17
  type Params,
18
18
  keyZ,
19
19
  type Key,
20
- linePlotRemoteZ,
21
20
  } from "@/workspace/lineplot/payload";
22
21
  import { keyZ as workspaceKeyZ } from "@/workspace/payload";
23
22
 
24
- export const crudeLinePlotZ = linePlotZ.partial({ key: true });
25
- export const linePlotWriteZ = linePlotRemoteZ.partial({ key: true });
23
+ export const newLinePlotZ = linePlotZ.partial({ key: true }).transform((p) => ({
24
+ ...p,
25
+ data: JSON.stringify(p.data),
26
+ }));
26
27
 
27
- export type CrudeLinePlot = z.infer<typeof crudeLinePlotZ>;
28
+ export type NewLinePlot = z.input<typeof newLinePlotZ>;
28
29
 
29
30
  const createReqZ = z.object({
30
31
  workspace: workspaceKeyZ,
31
- linePlots: linePlotWriteZ.array(),
32
+ linePlots: newLinePlotZ.array(),
32
33
  });
33
34
 
34
35
  const createResZ = z.object({
35
- linePlots: linePlotRemoteZ.array(),
36
+ linePlots: linePlotZ.array(),
36
37
  });
37
38
 
38
39
  const deleteReqZ = z.object({
@@ -67,12 +68,13 @@ export class Writer {
67
68
  this.client = client;
68
69
  }
69
70
 
70
- async create(workspace: string, plot: CrudeLinePlot): Promise<LinePlot> {
71
+ async create(workspace: string, plot: NewLinePlot): Promise<LinePlot> {
71
72
  const pid_ = { ...plot, data: JSON.stringify(plot.data) };
72
73
  const res = await sendRequired<typeof createReqZ, typeof createResZ>(
73
74
  this.client,
74
75
  CREATE_ENDPOINT,
75
76
  { workspace, linePlots: [pid_] },
77
+ createReqZ,
76
78
  createResZ,
77
79
  );
78
80
 
@@ -85,6 +87,7 @@ export class Writer {
85
87
  this.client,
86
88
  DELETE_ENDPOINT,
87
89
  { keys: normalized },
90
+ deleteReqZ,
88
91
  deleteResZ,
89
92
  );
90
93
  }
@@ -94,6 +97,7 @@ export class Writer {
94
97
  this.client,
95
98
  RENAME_ENDPOINT,
96
99
  { key: pid, name },
100
+ renameReqZ,
97
101
  renameResZ,
98
102
  );
99
103
  }
@@ -103,7 +107,8 @@ export class Writer {
103
107
  this.client,
104
108
  SET_DATA_ENDPOINT,
105
109
  { key: pid, data: JSON.stringify(data) },
106
- renameResZ,
110
+ setDataReqZ,
111
+ setDataResZ,
107
112
  );
108
113
  }
109
114
  }
@@ -19,7 +19,7 @@ export type Params = Key | Key[];
19
19
  export const workspaceZ = z.object({
20
20
  name: z.string(),
21
21
  key: keyZ,
22
- layout: unknownRecordZ,
22
+ layout: unknownRecordZ.or(z.string().transform((s) => JSON.parse(s) as UnknownRecord)),
23
23
  });
24
24
 
25
25
  export const workspaceRemoteZ = workspaceZ.omit({ layout: true }).extend({
@@ -12,7 +12,7 @@ import { type UnknownRecord } from "@synnaxlabs/x";
12
12
 
13
13
  import { type Key, type Params, type PID } from "@/workspace/pid/payload";
14
14
  import { Retriever } from "@/workspace/pid/retriever";
15
- import { Writer, type UncreatedPID } from "@/workspace/pid/writer";
15
+ import { Writer, type NewPID } from "@/workspace/pid/writer";
16
16
 
17
17
  export class Client {
18
18
  private readonly writer: Writer;
@@ -23,7 +23,7 @@ export class Client {
23
23
  this.retriever = new Retriever(client);
24
24
  }
25
25
 
26
- async create(workspace: string, pid: UncreatedPID): Promise<PID> {
26
+ async create(workspace: string, pid: NewPID): Promise<PID> {
27
27
  return await this.writer.create(workspace, pid);
28
28
  }
29
29
 
@@ -17,7 +17,7 @@ export type Params = Key | Key[];
17
17
  export const pidZ = z.object({
18
18
  key: z.string(),
19
19
  name: z.string(),
20
- data: unknownRecordZ,
20
+ data: unknownRecordZ.or(z.string().transform((s) => JSON.parse(s) as UnknownRecord)),
21
21
  snapshot: z.boolean(),
22
22
  });
23
23
 
@@ -7,7 +7,7 @@
7
7
  // License, use of this software will be governed by the Apache License, Version 2.0,
8
8
  // included in the file licenses/APL.txt.
9
9
 
10
- import { type UnaryClient } from "@synnaxlabs/freighter";
10
+ import { sendRequired, type UnaryClient } from "@synnaxlabs/freighter";
11
11
  import { toArray } from "@synnaxlabs/x";
12
12
  import { z } from "zod";
13
13
 
@@ -32,14 +32,12 @@ export class Retriever {
32
32
  }
33
33
 
34
34
  async retrieve(params: Params): Promise<PID[]> {
35
- const normalized = toArray(params);
36
- const res = await this.execute({ keys: normalized });
37
- return res;
38
- }
39
-
40
- private async execute(request: Request): Promise<PID[]> {
41
- const [res, err] = await this.client.send(this.ENDPOINT, request, resZ);
42
- if (err != null) throw err;
43
- return res.pids;
35
+ return (await sendRequired(
36
+ this.client,
37
+ this.ENDPOINT,
38
+ { keys: toArray(params) },
39
+ reqZ,
40
+ resZ,
41
+ )).pids;
44
42
  }
45
43
  }
@@ -21,14 +21,16 @@ import {
21
21
  pidRemoteZ,
22
22
  } from "@/workspace/pid/payload";
23
23
 
24
- export const crudePIDz = pidZ.partial({ key: true });
25
- export const pidWriteZ = pidRemoteZ.partial({ key: true, snapshot: true });
24
+ export const newPIDZ = pidZ.partial({ key: true, snapshot: true }).transform((p) => ({
25
+ ...p,
26
+ data: JSON.stringify(p.data),
27
+ }));
26
28
 
27
- export type UncreatedPID = z.infer<typeof pidWriteZ>;
29
+ export type NewPID = z.input<typeof newPIDZ>;
28
30
 
29
31
  const createReqZ = z.object({
30
32
  workspace: workspaceKeyZ,
31
- pids: pidWriteZ.array(),
33
+ pids: newPIDZ.array(),
32
34
  });
33
35
 
34
36
  const createResZ = z.object({
@@ -78,12 +80,13 @@ export class Writer {
78
80
  this.client = client;
79
81
  }
80
82
 
81
- async create(workspace: string, pid: UncreatedPID): Promise<PID> {
83
+ async create(workspace: string, pid: NewPID): Promise<PID> {
82
84
  const pid_ = { ...pid, data: JSON.stringify(pid.data) };
83
85
  const res = await sendRequired<typeof createReqZ, typeof createResZ>(
84
86
  this.client,
85
87
  CREATE_ENDPOINT,
86
88
  { workspace, pids: [pid_] },
89
+ createReqZ,
87
90
  createResZ,
88
91
  );
89
92
 
@@ -95,6 +98,7 @@ export class Writer {
95
98
  this.client,
96
99
  COPY_ENDPOINT,
97
100
  { key, name, snapshot },
101
+ copyReqZ,
98
102
  copyResZ,
99
103
  );
100
104
  return res.pid;
@@ -106,6 +110,7 @@ export class Writer {
106
110
  this.client,
107
111
  DELETE_ENDPOINT,
108
112
  { keys: normalized },
113
+ deleteReqZ,
109
114
  deleteResZ,
110
115
  );
111
116
  }
@@ -115,6 +120,7 @@ export class Writer {
115
120
  this.client,
116
121
  RENAME_ENDPOINT,
117
122
  { key: pid, name },
123
+ renameReqZ,
118
124
  renameResZ,
119
125
  );
120
126
  }
@@ -124,6 +130,7 @@ export class Writer {
124
130
  this.client,
125
131
  SET_DATA_ENDPOINT,
126
132
  { key: pid, data: JSON.stringify(data) },
133
+ setDataReqZ,
127
134
  renameResZ,
128
135
  );
129
136
  }
@@ -7,7 +7,7 @@
7
7
  // License, use of this software will be governed by the Apache License, Version 2.0,
8
8
  // included in the file licenses/APL.txt.
9
9
 
10
- import { type UnaryClient } from "@synnaxlabs/freighter";
10
+ import { sendRequired, type UnaryClient } from "@synnaxlabs/freighter";
11
11
  import { toArray } from "@synnaxlabs/x";
12
12
  import { z } from "zod";
13
13
 
@@ -59,8 +59,6 @@ export class Retriever {
59
59
  }
60
60
 
61
61
  private async execute(request: Request): Promise<Workspace[]> {
62
- const [res, err] = await this.client.send(Retriever.ENDPOINT, request, resZ);
63
- if (err != null) throw err;
64
- return res.workspaces;
62
+ return (await sendRequired(this.client, Retriever.ENDPOINT, request, reqZ, resZ)).workspaces;
65
63
  }
66
64
  }
@@ -18,13 +18,13 @@ const ZERO_UUID = "00000000-0000-0000-0000-000000000000";
18
18
  describe("Workspace", () => {
19
19
  describe("create", () => {
20
20
  test("create one", async () => {
21
- const pid = await client.workspaces.create({
21
+ const ws = await client.workspaces.create({
22
22
  name: "PID",
23
23
  layout: { one: 1 },
24
24
  });
25
- expect(pid.name).toEqual("PID");
26
- expect(pid.key).not.toEqual(ZERO_UUID);
27
- expect(pid.layout.one).toEqual(1);
25
+ expect(ws.name).toEqual("PID");
26
+ expect(ws.key).not.toEqual(ZERO_UUID);
27
+ expect(ws.layout.one).toEqual(1);
28
28
  });
29
29
  });
30
30
  describe("rename", () => {
@@ -13,13 +13,15 @@ import { z } from "zod";
13
13
 
14
14
  import { type Workspace, workspaceZ, keyZ, workspaceRemoteZ } from "./payload";
15
15
 
16
- const crudeWorkspaceZ = workspaceZ.partial({ key: true });
17
- const workspaceWriteZ = workspaceRemoteZ.partial({ key: true });
16
+ const newWorkspaceZ = workspaceZ.partial({ key: true }).transform((w) => ({
17
+ ...w,
18
+ layout: JSON.stringify(w.layout),
19
+ }));
18
20
 
19
- export type CrudeWorkspace = z.infer<typeof crudeWorkspaceZ>;
21
+ export type NewWorkspace = z.input<typeof newWorkspaceZ>;
20
22
 
21
23
  const createReqZ = z.object({
22
- workspaces: workspaceWriteZ.partial({ key: true }).array(),
24
+ workspaces: newWorkspaceZ.array(),
23
25
  });
24
26
 
25
27
  const createResZ = z.object({
@@ -60,15 +62,12 @@ export class Writer {
60
62
  this.client = client;
61
63
  }
62
64
 
63
- async create(workspaces: CrudeWorkspace | CrudeWorkspace[]): Promise<Workspace[]> {
64
- const ws = toArray(workspaces).map((w) => ({
65
- ...w,
66
- layout: JSON.stringify(w.layout),
67
- }));
65
+ async create(workspaces: NewWorkspace | NewWorkspace[]): Promise<Workspace[]> {
68
66
  const res = await sendRequired<typeof createReqZ, typeof createResZ>(
69
67
  this.client,
70
68
  CREATE_ENDPOINT,
71
- { workspaces: ws },
69
+ { workspaces: toArray(workspaces) },
70
+ createReqZ,
72
71
  createResZ,
73
72
  );
74
73
  return res.workspaces;
@@ -79,6 +78,7 @@ export class Writer {
79
78
  this.client,
80
79
  DELETE_ENDPOINT,
81
80
  { keys: toArray(keys) },
81
+ deleteReqZ,
82
82
  deleteResZ,
83
83
  );
84
84
  }
@@ -88,6 +88,7 @@ export class Writer {
88
88
  this.client,
89
89
  RENAME_ENDPOINT,
90
90
  { key, name },
91
+ renameReqZ,
91
92
  renameResZ,
92
93
  );
93
94
  }
@@ -97,6 +98,7 @@ export class Writer {
97
98
  this.client,
98
99
  SET_LAYOUT_ENDPOINT,
99
100
  { key, layout: JSON.stringify(layout) },
101
+ setLayoutReqZ,
100
102
  setLayoutResZ,
101
103
  );
102
104
  }
@@ -1,37 +0,0 @@
1
- import { DataType, Synnax, TimeSpan, TimeStamp } from "@synnaxlabs/client";
2
-
3
- const client = new Synnax({
4
- host: "localhost",
5
- port: 9090,
6
- username: "synnax",
7
- password: "seldon",
8
- secure: false
9
- });
10
-
11
- const time_channel = await client.channels.create({
12
- name: "basic_read_write_time",
13
- isIndex: true,
14
- dataType: DataType.TIMESTAMP
15
- });
16
-
17
- const data_channel = await client.channels.create({
18
- name: "basic_read_write_data",
19
- isIndex: false,
20
- dataType: DataType.FLOAT32,
21
- index: time_channel.key,
22
- });
23
-
24
- const N_SAMPLES = 500;
25
-
26
- const start = TimeStamp.now();
27
-
28
- const data = Float32Array.from({ length: N_SAMPLES }, (_, i) => Math.sin(i / 100));
29
- const time = BigInt64Array.from({ length: N_SAMPLES }, (_, i) => start.add(TimeSpan.milliseconds(i)).bigInt);
30
-
31
- await client.telem.write("basic_read_write_time", start, time);
32
- // console.log("HERE")
33
- // // await data_channel.write(start, data);
34
-
35
- console.log("HERE")
36
-
37
- client.close();