@synnaxlabs/client 0.32.0 → 0.34.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 (109) hide show
  1. package/.turbo/turbo-build.log +7 -7
  2. package/dist/access/policy/payload.d.ts +40 -40
  3. package/dist/access/policy/retriever.d.ts +5 -5
  4. package/dist/auth/auth.d.ts.map +1 -1
  5. package/dist/channel/client.d.ts +1 -1
  6. package/dist/channel/writer.d.ts.map +1 -1
  7. package/dist/client.cjs +34 -34
  8. package/dist/client.d.ts.map +1 -1
  9. package/dist/client.js +2999 -2557
  10. package/dist/control/client.d.ts.map +1 -1
  11. package/dist/control/state.d.ts.map +1 -1
  12. package/dist/errors.d.ts +3 -3
  13. package/dist/errors.d.ts.map +1 -1
  14. package/dist/framer/adapter.d.ts.map +1 -1
  15. package/dist/framer/client.d.ts.map +1 -1
  16. package/dist/framer/deleter.d.ts.map +1 -1
  17. package/dist/framer/frame.d.ts.map +1 -1
  18. package/dist/framer/writer.d.ts.map +1 -1
  19. package/dist/hardware/device/client.d.ts.map +1 -1
  20. package/dist/hardware/device/payload.d.ts.map +1 -1
  21. package/dist/hardware/rack/client.d.ts.map +1 -1
  22. package/dist/hardware/task/client.d.ts +1 -1
  23. package/dist/hardware/task/client.d.ts.map +1 -1
  24. package/dist/hardware/task/ni/types.d.ts +13 -13
  25. package/dist/hardware/task/ni/types.d.ts.map +1 -1
  26. package/dist/hardware/task/payload.d.ts.map +1 -1
  27. package/dist/index.d.ts +3 -2
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/label/client.d.ts.map +1 -1
  30. package/dist/label/writer.d.ts +5 -5
  31. package/dist/ontology/client.d.ts +9 -9
  32. package/dist/ontology/client.d.ts.map +1 -1
  33. package/dist/ontology/payload.d.ts +43 -43
  34. package/dist/ontology/payload.d.ts.map +1 -1
  35. package/dist/ranger/alias.d.ts.map +1 -1
  36. package/dist/ranger/client.d.ts.map +1 -1
  37. package/dist/ranger/kv.d.ts.map +1 -1
  38. package/dist/ranger/payload.d.ts.map +1 -1
  39. package/dist/ranger/writer.d.ts +5 -5
  40. package/dist/ranger/writer.d.ts.map +1 -1
  41. package/dist/util/telem.d.ts.map +1 -1
  42. package/dist/workspace/client.d.ts +2 -0
  43. package/dist/workspace/client.d.ts.map +1 -1
  44. package/dist/workspace/lineplot/payload.d.ts.map +1 -1
  45. package/dist/workspace/log/client.d.ts +16 -0
  46. package/dist/workspace/log/client.d.ts.map +1 -0
  47. package/dist/workspace/log/external.d.ts +3 -0
  48. package/dist/workspace/log/external.d.ts.map +1 -0
  49. package/dist/workspace/log/index.d.ts +2 -0
  50. package/dist/workspace/log/index.d.ts.map +1 -0
  51. package/dist/workspace/log/log.spec.d.ts +2 -0
  52. package/dist/workspace/log/log.spec.d.ts.map +1 -0
  53. package/dist/workspace/log/payload.d.ts +36 -0
  54. package/dist/workspace/log/payload.d.ts.map +1 -0
  55. package/dist/workspace/log/retriever.d.ts +9 -0
  56. package/dist/workspace/log/retriever.d.ts.map +1 -0
  57. package/dist/workspace/log/writer.d.ts +35 -0
  58. package/dist/workspace/log/writer.d.ts.map +1 -0
  59. package/dist/workspace/payload.d.ts.map +1 -1
  60. package/dist/workspace/schematic/payload.d.ts.map +1 -1
  61. package/eslint.config.js +1 -1
  62. package/package.json +15 -16
  63. package/src/access/policy/policy.spec.ts +8 -10
  64. package/src/auth/auth.spec.ts +1 -1
  65. package/src/auth/auth.ts +17 -18
  66. package/src/channel/client.ts +1 -1
  67. package/src/channel/writer.ts +2 -2
  68. package/src/connection/checker.ts +1 -1
  69. package/src/control/client.ts +1 -1
  70. package/src/control/state.ts +2 -2
  71. package/src/errors.spec.ts +20 -1
  72. package/src/errors.ts +14 -15
  73. package/src/framer/adapter.ts +5 -6
  74. package/src/framer/client.ts +9 -4
  75. package/src/framer/deleter.ts +1 -1
  76. package/src/framer/frame.ts +9 -11
  77. package/src/framer/iterator.spec.ts +2 -3
  78. package/src/framer/writer.ts +1 -1
  79. package/src/hardware/device/client.ts +3 -3
  80. package/src/hardware/device/payload.ts +1 -1
  81. package/src/hardware/rack/client.ts +3 -3
  82. package/src/hardware/task/client.ts +13 -11
  83. package/src/hardware/task/ni/types.ts +14 -14
  84. package/src/hardware/task/payload.ts +1 -1
  85. package/src/hardware/task/task.spec.ts +1 -1
  86. package/src/index.ts +2 -2
  87. package/src/label/client.ts +1 -1
  88. package/src/ontology/client.ts +2 -4
  89. package/src/ontology/group/payload.ts +2 -2
  90. package/src/ontology/payload.ts +2 -1
  91. package/src/ranger/alias.ts +2 -3
  92. package/src/ranger/client.ts +7 -9
  93. package/src/ranger/kv.ts +2 -2
  94. package/src/ranger/payload.ts +2 -2
  95. package/src/ranger/ranger.spec.ts +2 -2
  96. package/src/user/user.spec.ts +1 -2
  97. package/src/util/telem.ts +1 -3
  98. package/src/workspace/client.ts +3 -0
  99. package/src/workspace/lineplot/payload.ts +1 -1
  100. package/src/workspace/log/client.ts +51 -0
  101. package/src/workspace/log/external.ts +11 -0
  102. package/src/workspace/log/index.ts +10 -0
  103. package/src/workspace/log/log.spec.ts +78 -0
  104. package/src/workspace/log/payload.ts +36 -0
  105. package/src/workspace/log/retriever.ts +38 -0
  106. package/src/workspace/log/writer.ts +116 -0
  107. package/src/workspace/payload.ts +1 -1
  108. package/src/workspace/schematic/payload.ts +1 -1
  109. package/src/workspace/schematic/writer.ts +1 -1
@@ -0,0 +1,78 @@
1
+ // Copyright 2024 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 { describe, expect, test } from "vitest";
11
+
12
+ import { newClient } from "@/setupspecs";
13
+
14
+ const client = newClient();
15
+
16
+ const ZERO_UUID = "00000000-0000-0000-0000-000000000000";
17
+
18
+ describe("Log", () => {
19
+ describe("create", () => {
20
+ test("create one", async () => {
21
+ const ws = await client.workspaces.create({
22
+ name: "Log",
23
+ layout: { one: 1 },
24
+ });
25
+ const log = await client.workspaces.log.create(ws.key, {
26
+ name: "Log",
27
+ data: { one: 1 },
28
+ });
29
+ expect(log.name).toEqual("Log");
30
+ expect(log.key).not.toEqual(ZERO_UUID);
31
+ expect(log.data.one).toEqual(1);
32
+ });
33
+ });
34
+ describe("rename", () => {
35
+ test("rename one", async () => {
36
+ const ws = await client.workspaces.create({
37
+ name: "Log",
38
+ layout: { one: 1 },
39
+ });
40
+ const log = await client.workspaces.log.create(ws.key, {
41
+ name: "Log",
42
+ data: { one: 1 },
43
+ });
44
+ await client.workspaces.log.rename(log.key, "Log2");
45
+ const res = await client.workspaces.log.retrieve(log.key);
46
+ expect(res.name).toEqual("Log2");
47
+ });
48
+ });
49
+ describe("setData", () => {
50
+ test("set data", async () => {
51
+ const ws = await client.workspaces.create({
52
+ name: "Log",
53
+ layout: { one: 1 },
54
+ });
55
+ const log = await client.workspaces.log.create(ws.key, {
56
+ name: "Log",
57
+ data: { one: 1 },
58
+ });
59
+ await client.workspaces.log.setData(log.key, { two: 2 });
60
+ const res = await client.workspaces.log.retrieve(log.key);
61
+ expect(res.data.two).toEqual(2);
62
+ });
63
+ });
64
+ describe("delete", () => {
65
+ test("delete one", async () => {
66
+ const ws = await client.workspaces.create({
67
+ name: "Log",
68
+ layout: { one: 1 },
69
+ });
70
+ const log = await client.workspaces.log.create(ws.key, {
71
+ name: "Log",
72
+ data: { one: 1 },
73
+ });
74
+ await client.workspaces.log.delete(log.key);
75
+ await expect(client.workspaces.log.retrieve(log.key)).rejects.toThrow();
76
+ });
77
+ });
78
+ });
@@ -0,0 +1,36 @@
1
+ // Copyright 2024 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 UnknownRecord, unknownRecordZ } from "@synnaxlabs/x/record";
11
+ import { z } from "zod";
12
+
13
+ import { ontology } from "@/ontology";
14
+
15
+ export const keyZ = z.string().uuid();
16
+ export type Key = z.infer<typeof keyZ>;
17
+ export type Params = Key | Key[];
18
+
19
+ export const logZ = z.object({
20
+ key: z.string(),
21
+ name: z.string(),
22
+ data: unknownRecordZ.or(z.string().transform((s) => JSON.parse(s) as UnknownRecord)),
23
+ });
24
+
25
+ export const logRemoteZ = z.object({
26
+ key: z.string(),
27
+ name: z.string(),
28
+ data: z.string().transform((s) => JSON.parse(s) as UnknownRecord),
29
+ });
30
+
31
+ export type Log = z.infer<typeof logZ>;
32
+
33
+ export const ONTOLOGY_TYPE: ontology.ResourceType = "log";
34
+
35
+ export const ontologyID = (key: Key): ontology.ID =>
36
+ new ontology.ID({ type: ONTOLOGY_TYPE, key });
@@ -0,0 +1,38 @@
1
+ // Copyright 2024 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 { sendRequired, type UnaryClient } from "@synnaxlabs/freighter";
11
+ import { toArray } from "@synnaxlabs/x/toArray";
12
+ import { z } from "zod";
13
+
14
+ import { type Log, logRemoteZ, type Params } from "@/workspace/log/payload";
15
+
16
+ const reqZ = z.object({ keys: z.string().array() });
17
+ const resZ = z.object({ logs: logRemoteZ.array() });
18
+
19
+ export class Retriever {
20
+ private readonly ENDPOINT = "/workspace/log/retrieve";
21
+ private readonly client: UnaryClient;
22
+
23
+ constructor(client: UnaryClient) {
24
+ this.client = client;
25
+ }
26
+
27
+ async retrieve(logs: Params): Promise<Log[]> {
28
+ return (
29
+ await sendRequired(
30
+ this.client,
31
+ this.ENDPOINT,
32
+ { keys: toArray(logs) },
33
+ reqZ,
34
+ resZ,
35
+ )
36
+ ).logs;
37
+ }
38
+ }
@@ -0,0 +1,116 @@
1
+ // Copyright 2024 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 { sendRequired, type UnaryClient } from "@synnaxlabs/freighter";
11
+ import { type UnknownRecord } from "@synnaxlabs/x/record";
12
+ import { toArray } from "@synnaxlabs/x/toArray";
13
+ import { z } from "zod";
14
+
15
+ import {
16
+ type Key,
17
+ keyZ,
18
+ type Log,
19
+ logRemoteZ,
20
+ logZ,
21
+ type Params,
22
+ } from "@/workspace/log/payload";
23
+ import { keyZ as workspaceKeyZ } from "@/workspace/payload";
24
+
25
+ export const newLogZ = logZ.partial({ key: true }).transform((p) => ({
26
+ ...p,
27
+ data: JSON.stringify(p.data),
28
+ }));
29
+
30
+ export type NewLog = z.input<typeof newLogZ>;
31
+
32
+ const createReqZ = z.object({
33
+ workspace: workspaceKeyZ,
34
+ logs: newLogZ.array(),
35
+ });
36
+
37
+ const createResZ = z.object({
38
+ logs: logRemoteZ.array(),
39
+ });
40
+
41
+ const deleteReqZ = z.object({
42
+ keys: keyZ.array(),
43
+ });
44
+
45
+ const deleteResZ = z.object({});
46
+
47
+ const renameReqZ = z.object({
48
+ key: keyZ,
49
+ name: z.string(),
50
+ });
51
+
52
+ const renameResZ = z.object({});
53
+
54
+ const setDataReqZ = z.object({
55
+ key: keyZ,
56
+ data: z.string(),
57
+ });
58
+
59
+ const setDataResZ = z.object({});
60
+
61
+ const CREATE_ENDPOINT = "/workspace/log/create";
62
+ const DELETE_ENDPOINT = "/workspace/log/delete";
63
+ const RENAME_ENDPOINT = "/workspace/log/rename";
64
+ const SET_DATA_ENDPOINT = "/workspace/log/set-data";
65
+
66
+ export class Writer {
67
+ private readonly client: UnaryClient;
68
+
69
+ constructor(client: UnaryClient) {
70
+ this.client = client;
71
+ }
72
+
73
+ async create(workspace: string, log: NewLog): Promise<Log> {
74
+ const log_ = { ...log, data: JSON.stringify(log.data) };
75
+ const res = await sendRequired<typeof createReqZ, typeof createResZ>(
76
+ this.client,
77
+ CREATE_ENDPOINT,
78
+ { workspace, logs: [log_] },
79
+ createReqZ,
80
+ createResZ,
81
+ );
82
+
83
+ return res.logs[0];
84
+ }
85
+
86
+ async delete(logs: Params): Promise<void> {
87
+ const normalized = toArray(logs);
88
+ await sendRequired<typeof deleteReqZ, typeof deleteResZ>(
89
+ this.client,
90
+ DELETE_ENDPOINT,
91
+ { keys: normalized },
92
+ deleteReqZ,
93
+ deleteResZ,
94
+ );
95
+ }
96
+
97
+ async rename(log: Key, name: string): Promise<void> {
98
+ await sendRequired<typeof renameReqZ, typeof renameResZ>(
99
+ this.client,
100
+ RENAME_ENDPOINT,
101
+ { key: log, name },
102
+ renameReqZ,
103
+ renameResZ,
104
+ );
105
+ }
106
+
107
+ async setData(log: Key, data: UnknownRecord): Promise<void> {
108
+ await sendRequired<typeof setDataReqZ, typeof setDataResZ>(
109
+ this.client,
110
+ SET_DATA_ENDPOINT,
111
+ { key: log, data: JSON.stringify(data) },
112
+ setDataReqZ,
113
+ setDataResZ,
114
+ );
115
+ }
116
+ }
@@ -41,4 +41,4 @@ export type Workspace = z.infer<typeof workspaceZ>;
41
41
  export const ONTOLOGY_TYPE: ontology.ResourceType = "workspace";
42
42
 
43
43
  export const ontologyID = (key: Key): ontology.ID =>
44
- new ontology.ID({ type: ONTOLOGY_TYPE, key: key });
44
+ new ontology.ID({ type: ONTOLOGY_TYPE, key });
@@ -35,4 +35,4 @@ export type Schematic = z.infer<typeof schematicZ>;
35
35
  export const ONTOLOGY_TYPE: ontology.ResourceType = "schematic";
36
36
 
37
37
  export const ontologyID = (key: Key): ontology.ID =>
38
- new ontology.ID({ type: ONTOLOGY_TYPE, key: key });
38
+ new ontology.ID({ type: ONTOLOGY_TYPE, key });
@@ -134,7 +134,7 @@ export class Writer {
134
134
  SET_DATA_ENDPOINT,
135
135
  { key: schematic, data: JSON.stringify(data) },
136
136
  setDataReqZ,
137
- renameResZ,
137
+ setDataResZ,
138
138
  );
139
139
  }
140
140
  }