@synnaxlabs/client 0.34.0 → 0.36.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 (126) 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/client.cjs +28 -28
  5. package/dist/client.d.ts +35 -0
  6. package/dist/client.d.ts.map +1 -1
  7. package/dist/client.js +3092 -2820
  8. package/dist/control/state.d.ts.map +1 -1
  9. package/dist/framer/deleter.d.ts.map +1 -1
  10. package/dist/framer/frame.d.ts +14 -7
  11. package/dist/framer/frame.d.ts.map +1 -1
  12. package/dist/framer/writer.d.ts +8 -8
  13. package/dist/framer/writer.d.ts.map +1 -1
  14. package/dist/hardware/device/client.d.ts +2 -2
  15. package/dist/hardware/device/client.d.ts.map +1 -1
  16. package/dist/hardware/device/payload.d.ts +2 -2
  17. package/dist/hardware/device/payload.d.ts.map +1 -1
  18. package/dist/hardware/task/client.d.ts +4 -2
  19. package/dist/hardware/task/client.d.ts.map +1 -1
  20. package/dist/hardware/task/payload.d.ts +9 -5
  21. package/dist/hardware/task/payload.d.ts.map +1 -1
  22. package/dist/index.d.ts +2 -0
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/label/writer.d.ts +5 -5
  25. package/dist/ontology/client.d.ts +8 -8
  26. package/dist/ontology/group/payload.d.ts +3 -0
  27. package/dist/ontology/group/payload.d.ts.map +1 -1
  28. package/dist/ontology/payload.d.ts +43 -43
  29. package/dist/ontology/payload.d.ts.map +1 -1
  30. package/dist/ranger/client.d.ts +1 -0
  31. package/dist/ranger/client.d.ts.map +1 -1
  32. package/dist/ranger/payload.d.ts.map +1 -1
  33. package/dist/ranger/writer.d.ts +5 -5
  34. package/dist/ranger/writer.d.ts.map +1 -1
  35. package/dist/transport.d.ts +2 -1
  36. package/dist/transport.d.ts.map +1 -1
  37. package/dist/workspace/client.d.ts +70 -11
  38. package/dist/workspace/client.d.ts.map +1 -1
  39. package/dist/workspace/index.d.ts +1 -1
  40. package/dist/workspace/index.d.ts.map +1 -1
  41. package/dist/workspace/lineplot/client.d.ts +48 -6
  42. package/dist/workspace/lineplot/client.d.ts.map +1 -1
  43. package/dist/workspace/lineplot/index.d.ts +1 -1
  44. package/dist/workspace/lineplot/index.d.ts.map +1 -1
  45. package/dist/workspace/log/client.d.ts +48 -6
  46. package/dist/workspace/log/client.d.ts.map +1 -1
  47. package/dist/workspace/log/index.d.ts +1 -1
  48. package/dist/workspace/log/index.d.ts.map +1 -1
  49. package/dist/workspace/schematic/client.d.ts +72 -6
  50. package/dist/workspace/schematic/client.d.ts.map +1 -1
  51. package/dist/workspace/schematic/index.d.ts +1 -1
  52. package/dist/workspace/schematic/index.d.ts.map +1 -1
  53. package/dist/workspace/table/client.d.ts +71 -0
  54. package/dist/workspace/table/client.d.ts.map +1 -0
  55. package/dist/workspace/table/index.d.ts +2 -0
  56. package/dist/workspace/table/index.d.ts.map +1 -0
  57. package/dist/workspace/table/table.spec.d.ts +2 -0
  58. package/dist/workspace/table/table.spec.d.ts.map +1 -0
  59. package/package.json +10 -10
  60. package/src/client.ts +16 -2
  61. package/src/control/state.ts +1 -1
  62. package/src/framer/frame.spec.ts +32 -3
  63. package/src/framer/frame.ts +17 -0
  64. package/src/hardware/device/client.ts +10 -4
  65. package/src/hardware/task/client.ts +51 -3
  66. package/src/hardware/task/payload.ts +21 -6
  67. package/src/index.ts +2 -0
  68. package/src/ontology/group/payload.ts +8 -7
  69. package/src/ontology/payload.ts +1 -0
  70. package/src/ranger/client.ts +4 -1
  71. package/src/transport.ts +8 -3
  72. package/src/workspace/client.ts +151 -47
  73. package/src/workspace/index.ts +1 -1
  74. package/src/workspace/lineplot/client.ts +96 -28
  75. package/src/workspace/lineplot/index.ts +1 -1
  76. package/src/workspace/log/client.ts +93 -28
  77. package/src/workspace/log/index.ts +1 -1
  78. package/src/workspace/schematic/client.ts +121 -29
  79. package/src/workspace/schematic/index.ts +1 -1
  80. package/src/workspace/table/client.ts +125 -0
  81. package/src/workspace/{external.ts → table/index.ts} +1 -2
  82. package/src/workspace/table/table.spec.ts +65 -0
  83. package/dist/workspace/external.d.ts +0 -3
  84. package/dist/workspace/external.d.ts.map +0 -1
  85. package/dist/workspace/lineplot/external.d.ts +0 -3
  86. package/dist/workspace/lineplot/external.d.ts.map +0 -1
  87. package/dist/workspace/lineplot/retriever.d.ts +0 -9
  88. package/dist/workspace/lineplot/retriever.d.ts.map +0 -1
  89. package/dist/workspace/lineplot/writer.d.ts +0 -35
  90. package/dist/workspace/lineplot/writer.d.ts.map +0 -1
  91. package/dist/workspace/log/external.d.ts +0 -3
  92. package/dist/workspace/log/external.d.ts.map +0 -1
  93. package/dist/workspace/log/payload.d.ts +0 -36
  94. package/dist/workspace/log/payload.d.ts.map +0 -1
  95. package/dist/workspace/log/retriever.d.ts +0 -9
  96. package/dist/workspace/log/retriever.d.ts.map +0 -1
  97. package/dist/workspace/log/writer.d.ts +0 -35
  98. package/dist/workspace/log/writer.d.ts.map +0 -1
  99. package/dist/workspace/payload.d.ts +0 -38
  100. package/dist/workspace/payload.d.ts.map +0 -1
  101. package/dist/workspace/retriever.d.ts +0 -13
  102. package/dist/workspace/retriever.d.ts.map +0 -1
  103. package/dist/workspace/schematic/external.d.ts +0 -3
  104. package/dist/workspace/schematic/external.d.ts.map +0 -1
  105. package/dist/workspace/schematic/payload.d.ts +0 -42
  106. package/dist/workspace/schematic/payload.d.ts.map +0 -1
  107. package/dist/workspace/schematic/retriever.d.ts +0 -9
  108. package/dist/workspace/schematic/retriever.d.ts.map +0 -1
  109. package/dist/workspace/schematic/writer.d.ts +0 -41
  110. package/dist/workspace/schematic/writer.d.ts.map +0 -1
  111. package/dist/workspace/writer.d.ts +0 -66
  112. package/dist/workspace/writer.d.ts.map +0 -1
  113. package/src/workspace/lineplot/external.ts +0 -11
  114. package/src/workspace/lineplot/retriever.ts +0 -34
  115. package/src/workspace/lineplot/writer.ts +0 -115
  116. package/src/workspace/log/external.ts +0 -11
  117. package/src/workspace/log/payload.ts +0 -36
  118. package/src/workspace/log/retriever.ts +0 -38
  119. package/src/workspace/log/writer.ts +0 -116
  120. package/src/workspace/payload.ts +0 -44
  121. package/src/workspace/retriever.ts +0 -70
  122. package/src/workspace/schematic/external.ts +0 -11
  123. package/src/workspace/schematic/payload.ts +0 -38
  124. package/src/workspace/schematic/retriever.ts +0 -42
  125. package/src/workspace/schematic/writer.ts +0 -140
  126. package/src/workspace/writer.ts +0 -111
@@ -1,51 +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 { type UnaryClient } from "@synnaxlabs/freighter";
11
- import { type UnknownRecord } from "@synnaxlabs/x/record";
12
-
13
- import { type Key, type Log, type Params } from "@/workspace/log/payload";
14
- import { Retriever } from "@/workspace/log/retriever";
15
- import { type NewLog, Writer } from "@/workspace/log/writer";
1
+ import { ontology } from "@/ontology";
2
+ import { sendRequired, UnaryClient } from "@synnaxlabs/freighter";
3
+ import { toArray, UnknownRecord } from "@synnaxlabs/x";
4
+ import { unknownRecordZ } from "@synnaxlabs/x/record";
5
+ import { z } from "zod";
6
+
7
+ export const keyZ = z.string().uuid();
8
+ export type Key = z.infer<typeof keyZ>;
9
+ export type Params = Key | Key[];
10
+
11
+ export const logZ = z.object({
12
+ key: z.string(),
13
+ name: z.string(),
14
+ data: unknownRecordZ.or(z.string().transform((s) => JSON.parse(s) as UnknownRecord)),
15
+ });
16
+
17
+ export type Log = z.infer<typeof logZ>;
18
+
19
+ export const ONTOLOGY_TYPE: ontology.ResourceType = "log";
20
+
21
+ export const ontologyID = (key: Key): ontology.ID =>
22
+ new ontology.ID({ type: ONTOLOGY_TYPE, key });
23
+
24
+ const RETRIEVE_ENDPOINT = "/workspace/log/retrieve";
25
+ const CREATE_ENDPOINT = "/workspace/log/create";
26
+ const RENAME_ENDPOINT = "/workspace/log/rename";
27
+ const SET_DATA_ENDPOINT = "/workspace/log/set-data";
28
+ const DELETE_ENDPOINT = "/workspace/log/delete";
29
+
30
+ export const newLogZ = logZ.partial({ key: true }).transform((p) => ({
31
+ ...p,
32
+ data: JSON.stringify(p.data),
33
+ }));
34
+
35
+ export type NewLog = z.input<typeof newLogZ>;
36
+
37
+ const retrieveReqZ = z.object({ keys: z.string().array() });
38
+ const createReqZ = z.object({ workspace: z.string(), logs: newLogZ.array() });
39
+ const renameReqZ = z.object({ key: z.string(), name: z.string() });
40
+ const setDataReqZ = z.object({ key: z.string(), data: z.string() });
41
+ const deleteReqZ = z.object({ keys: z.string().array() });
42
+
43
+ const retrieveResZ = z.object({ logs: logZ.array() });
44
+ const createResZ = z.object({ logs: logZ.array() });
45
+ const emptyResZ = z.object({});
16
46
 
17
47
  export class Client {
18
- private readonly writer: Writer;
19
- private readonly retriever: Retriever;
48
+ private readonly client: UnaryClient;
20
49
 
21
50
  constructor(client: UnaryClient) {
22
- this.writer = new Writer(client);
23
- this.retriever = new Retriever(client);
51
+ this.client = client;
24
52
  }
25
53
 
26
- async create(workspace: string, log: NewLog): Promise<Log> {
27
- return await this.writer.create(workspace, log);
54
+ async create(workspace: string, log: NewLog): Promise<Log>;
55
+ async create(workspace: string, logs: NewLog[]): Promise<Log[]>;
56
+ async create(workspace: string, logs: NewLog | NewLog[]): Promise<Log | Log[]> {
57
+ const isMany = Array.isArray(logs);
58
+ const normalized = toArray(logs);
59
+ const res = await sendRequired(
60
+ this.client,
61
+ CREATE_ENDPOINT,
62
+ { workspace, logs: normalized },
63
+ createReqZ,
64
+ createResZ,
65
+ );
66
+ return isMany ? res.logs : res.logs[0];
28
67
  }
29
68
 
30
69
  async rename(key: Key, name: string): Promise<void> {
31
- await this.writer.rename(key, name);
70
+ await sendRequired(
71
+ this.client,
72
+ RENAME_ENDPOINT,
73
+ { key, name },
74
+ renameReqZ,
75
+ emptyResZ,
76
+ );
32
77
  }
33
78
 
34
79
  async setData(key: Key, data: UnknownRecord): Promise<void> {
35
- await this.writer.setData(key, data);
80
+ await sendRequired(
81
+ this.client,
82
+ SET_DATA_ENDPOINT,
83
+ { key, data: JSON.stringify(data) },
84
+ setDataReqZ,
85
+ emptyResZ,
86
+ );
36
87
  }
37
88
 
38
89
  async retrieve(key: Key): Promise<Log>;
39
-
40
90
  async retrieve(keys: Key[]): Promise<Log[]>;
41
-
42
91
  async retrieve(keys: Params): Promise<Log | Log[]> {
43
92
  const isMany = Array.isArray(keys);
44
- const res = await this.retriever.retrieve(keys);
45
- return isMany ? res : res[0];
93
+ const normalized = toArray(keys);
94
+ const res = await sendRequired(
95
+ this.client,
96
+ RETRIEVE_ENDPOINT,
97
+ { keys: normalized },
98
+ retrieveReqZ,
99
+ retrieveResZ,
100
+ );
101
+ return isMany ? res.logs : res.logs[0];
46
102
  }
47
103
 
104
+ async delete(key: Key): Promise<void>;
105
+ async delete(keys: Key[]): Promise<void>;
48
106
  async delete(keys: Params): Promise<void> {
49
- await this.writer.delete(keys);
107
+ const normalized = toArray(keys);
108
+ await sendRequired(
109
+ this.client,
110
+ DELETE_ENDPOINT,
111
+ { keys: normalized },
112
+ deleteReqZ,
113
+ emptyResZ,
114
+ );
50
115
  }
51
116
  }
@@ -7,4 +7,4 @@
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
- export * as log from "@/workspace/log/external";
10
+ export * as log from "@/workspace/log/client";
@@ -1,55 +1,147 @@
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 UnaryClient } from "@synnaxlabs/freighter";
11
- import { type UnknownRecord } from "@synnaxlabs/x/record";
12
-
13
- import { type Key, type Params, type Schematic } from "@/workspace/schematic/payload";
14
- import { Retriever } from "@/workspace/schematic/retriever";
15
- import { type NewSchematic, Writer } from "@/workspace/schematic/writer";
1
+ import { ontology } from "@/ontology";
2
+ import { nullableArrayZ } from "@/util/zod";
3
+ import { sendRequired, UnaryClient } from "@synnaxlabs/freighter";
4
+ import { toArray, UnknownRecord } from "@synnaxlabs/x";
5
+ import { unknownRecordZ } from "@synnaxlabs/x/record";
6
+ import { z } from "zod";
7
+
8
+ export const keyZ = z.string().uuid();
9
+ export type Key = z.infer<typeof keyZ>;
10
+ export type Params = Key | Key[];
11
+
12
+ export const schematicZ = z.object({
13
+ key: z.string(),
14
+ name: z.string(),
15
+ data: unknownRecordZ.or(z.string().transform((s) => JSON.parse(s) as UnknownRecord)),
16
+ snapshot: z.boolean(),
17
+ });
18
+
19
+ export const schematicRemoteZ = z.object({
20
+ key: z.string(),
21
+ name: z.string(),
22
+ snapshot: z.boolean(),
23
+ data: z.string().transform((s) => JSON.parse(s) as UnknownRecord),
24
+ });
25
+
26
+ export type Schematic = z.infer<typeof schematicZ>;
27
+
28
+ export const ONTOLOGY_TYPE: ontology.ResourceType = "schematic";
29
+
30
+ export const ontologyID = (key: Key): ontology.ID =>
31
+ new ontology.ID({ type: ONTOLOGY_TYPE, key });
32
+
33
+ const RETRIEVE_ENDPOINT = "/workspace/schematic/retrieve";
34
+ const CREATE_ENDPOINT = "/workspace/schematic/create";
35
+ const RENAME_ENDPOINT = "/workspace/schematic/rename";
36
+ const SET_DATA_ENDPOINT = "/workspace/schematic/set-data";
37
+ const DELETE_ENDPOINT = "/workspace/schematic/delete";
38
+ const COPY_ENDPOINT = "/workspace/schematic/copy";
39
+
40
+ export const newSchematicZ = schematicZ
41
+ .partial({ key: true, snapshot: true })
42
+ .transform((p) => ({
43
+ ...p,
44
+ data: JSON.stringify(p.data),
45
+ }));
46
+
47
+ export type NewSchematic = z.input<typeof newSchematicZ>;
48
+
49
+ const retrieveReqZ = z.object({ keys: z.string().array() });
50
+ const createReqZ = z.object({
51
+ workspace: z.string(),
52
+ schematics: newSchematicZ.array(),
53
+ });
54
+ const renameReqZ = z.object({ key: z.string(), name: z.string() });
55
+ const setDataReqZ = z.object({ key: z.string(), data: z.string() });
56
+ const deleteReqZ = z.object({ keys: z.string().array() });
57
+ const copyReqZ = z.object({ key: z.string(), name: z.string(), snapshot: z.boolean() });
58
+
59
+ const retrieveResZ = z.object({ schematics: nullableArrayZ(schematicRemoteZ) });
60
+ const createResZ = z.object({ schematics: schematicRemoteZ.array() });
61
+ const copyResZ = z.object({ schematic: schematicZ });
62
+ const emptyResZ = z.object({});
16
63
 
17
64
  export class Client {
18
- private readonly writer: Writer;
19
- private readonly retriever: Retriever;
65
+ private readonly client: UnaryClient;
20
66
 
21
67
  constructor(client: UnaryClient) {
22
- this.writer = new Writer(client);
23
- this.retriever = new Retriever(client);
68
+ this.client = client;
24
69
  }
25
70
 
26
- async create(workspace: string, schematic: NewSchematic): Promise<Schematic> {
27
- return await this.writer.create(workspace, schematic);
71
+ async create(workspace: string, schematic: NewSchematic): Promise<Schematic>;
72
+ async create(workspace: string, schematics: NewSchematic[]): Promise<Schematic[]>;
73
+ async create(
74
+ workspace: string,
75
+ schematics: NewSchematic | NewSchematic[],
76
+ ): Promise<Schematic | Schematic[]> {
77
+ const isMany = Array.isArray(schematics);
78
+ const normalized = toArray(schematics);
79
+ const res = await sendRequired(
80
+ this.client,
81
+ CREATE_ENDPOINT,
82
+ { workspace, schematics: normalized },
83
+ createReqZ,
84
+ createResZ,
85
+ );
86
+ return isMany ? res.schematics : res.schematics[0];
28
87
  }
29
88
 
30
89
  async rename(key: Key, name: string): Promise<void> {
31
- await this.writer.rename(key, name);
90
+ await sendRequired(
91
+ this.client,
92
+ RENAME_ENDPOINT,
93
+ { key, name },
94
+ renameReqZ,
95
+ emptyResZ,
96
+ );
32
97
  }
33
98
 
34
99
  async setData(key: Key, data: UnknownRecord): Promise<void> {
35
- await this.writer.setData(key, data);
100
+ await sendRequired(
101
+ this.client,
102
+ SET_DATA_ENDPOINT,
103
+ { key, data: JSON.stringify(data) },
104
+ setDataReqZ,
105
+ emptyResZ,
106
+ );
36
107
  }
37
108
 
38
109
  async retrieve(key: Key): Promise<Schematic>;
39
-
40
110
  async retrieve(keys: Key[]): Promise<Schematic[]>;
41
-
42
111
  async retrieve(keys: Params): Promise<Schematic | Schematic[]> {
43
112
  const isMany = Array.isArray(keys);
44
- const res = await this.retriever.retrieve(keys);
45
- return isMany ? res : res[0];
113
+ const normalized = toArray(keys);
114
+ const res = await sendRequired(
115
+ this.client,
116
+ RETRIEVE_ENDPOINT,
117
+ { keys: normalized },
118
+ retrieveReqZ,
119
+ retrieveResZ,
120
+ );
121
+ return isMany ? res.schematics : res.schematics[0];
46
122
  }
47
123
 
124
+ async delete(key: Key): Promise<void>;
125
+ async delete(keys: Key[]): Promise<void>;
48
126
  async delete(keys: Params): Promise<void> {
49
- await this.writer.delete(keys);
127
+ const normalized = toArray(keys);
128
+ await sendRequired(
129
+ this.client,
130
+ DELETE_ENDPOINT,
131
+ { keys: normalized },
132
+ deleteReqZ,
133
+ emptyResZ,
134
+ );
50
135
  }
51
136
 
52
137
  async copy(key: Key, name: string, snapshot: boolean): Promise<Schematic> {
53
- return await this.writer.copy(key, name, snapshot);
138
+ const res = await sendRequired(
139
+ this.client,
140
+ COPY_ENDPOINT,
141
+ { key, name, snapshot },
142
+ copyReqZ,
143
+ copyResZ,
144
+ );
145
+ return res.schematic;
54
146
  }
55
147
  }
@@ -7,4 +7,4 @@
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
- export * as schematic from "@/workspace/schematic/external";
10
+ export * as schematic from "@/workspace/schematic/client";
@@ -0,0 +1,125 @@
1
+ import { ontology } from "@/ontology";
2
+ import { sendRequired, UnaryClient } from "@synnaxlabs/freighter";
3
+ import { toArray, UnknownRecord } from "@synnaxlabs/x";
4
+ import { unknownRecordZ } from "@synnaxlabs/x/record";
5
+ import { z } from "zod";
6
+
7
+ export const keyZ = z.string().uuid();
8
+ export type Key = z.infer<typeof keyZ>;
9
+ export type Params = Key | Key[];
10
+
11
+ export const tableZ = z.object({
12
+ key: z.string(),
13
+ name: z.string(),
14
+ data: unknownRecordZ.or(z.string().transform((s) => JSON.parse(s) as UnknownRecord)),
15
+ });
16
+
17
+ export type Table = z.infer<typeof tableZ>;
18
+
19
+ export const ONTOLOGY_TYPE: ontology.ResourceType = "table";
20
+
21
+ export const ontologyID = (key: Key): ontology.ID =>
22
+ new ontology.ID({ type: ONTOLOGY_TYPE, key });
23
+
24
+ const RETRIEVE_ENDPOINT = "/workspace/table/retrieve";
25
+ const CREATE_ENDPOINT = "/workspace/table/create";
26
+ const RENAME_ENDPOINT = "/workspace/table/rename";
27
+ const SET_DATA_ENDPOINT = "/workspace/table/set-data";
28
+ const DELETE_ENDPOINT = "/workspace/table/delete";
29
+
30
+ export const newTableZ = tableZ.partial({ key: true }).transform((p) => ({
31
+ ...p,
32
+ data: JSON.stringify(p.data),
33
+ }));
34
+
35
+ export type NewTable = z.input<typeof newTableZ>;
36
+
37
+ export const tableRemoteZ = z.object({
38
+ key: z.string(),
39
+ name: z.string(),
40
+ data: z.string().transform((s) => JSON.parse(s) as UnknownRecord),
41
+ });
42
+
43
+ const retrieveReqZ = z.object({ keys: z.string().array() });
44
+ const createReqZ = z.object({ workspace: z.string(), tables: newTableZ.array() });
45
+ const renameReqZ = z.object({ key: z.string(), name: z.string() });
46
+ const setDataReqZ = z.object({ key: z.string(), data: z.string() });
47
+ const deleteReqZ = z.object({ keys: z.string().array() });
48
+
49
+ const retrieveResZ = z.object({ tables: tableRemoteZ.array() });
50
+ const createResZ = z.object({ tables: tableRemoteZ.array() });
51
+ const emptyResZ = z.object({});
52
+
53
+ export class Client {
54
+ private readonly client: UnaryClient;
55
+
56
+ constructor(client: UnaryClient) {
57
+ this.client = client;
58
+ }
59
+
60
+ async create(workspace: string, table: NewTable): Promise<Table>;
61
+ async create(workspace: string, tables: NewTable[]): Promise<Table[]>;
62
+ async create(
63
+ workspace: string,
64
+ tables: NewTable | NewTable[],
65
+ ): Promise<Table | Table[]> {
66
+ const isMany = Array.isArray(tables);
67
+ const normalized = toArray(tables);
68
+ const res = await sendRequired(
69
+ this.client,
70
+ CREATE_ENDPOINT,
71
+ { workspace, tables: normalized },
72
+ createReqZ,
73
+ createResZ,
74
+ );
75
+ return isMany ? res.tables : res.tables[0];
76
+ }
77
+
78
+ async rename(key: Key, name: string): Promise<void> {
79
+ await sendRequired(
80
+ this.client,
81
+ RENAME_ENDPOINT,
82
+ { key, name },
83
+ renameReqZ,
84
+ emptyResZ,
85
+ );
86
+ }
87
+
88
+ async setData(key: Key, data: UnknownRecord): Promise<void> {
89
+ await sendRequired(
90
+ this.client,
91
+ SET_DATA_ENDPOINT,
92
+ { key, data: JSON.stringify(data) },
93
+ setDataReqZ,
94
+ emptyResZ,
95
+ );
96
+ }
97
+
98
+ async retrieve(key: Key): Promise<Table>;
99
+ async retrieve(keys: Key[]): Promise<Table[]>;
100
+ async retrieve(keys: Params): Promise<Table | Table[]> {
101
+ const isMany = Array.isArray(keys);
102
+ const normalized = toArray(keys);
103
+ const res = await sendRequired(
104
+ this.client,
105
+ RETRIEVE_ENDPOINT,
106
+ { keys: normalized },
107
+ retrieveReqZ,
108
+ retrieveResZ,
109
+ );
110
+ return isMany ? res.tables : res.tables[0];
111
+ }
112
+
113
+ async delete(key: Key): Promise<void>;
114
+ async delete(keys: Key[]): Promise<void>;
115
+ async delete(keys: Params): Promise<void> {
116
+ const normalized = toArray(keys);
117
+ await sendRequired(
118
+ this.client,
119
+ DELETE_ENDPOINT,
120
+ { keys: normalized },
121
+ deleteReqZ,
122
+ emptyResZ,
123
+ );
124
+ }
125
+ }
@@ -7,5 +7,4 @@
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
- export * from "@/workspace/client";
11
- export * from "@/workspace/payload";
10
+ export * as table from "@/workspace/table/client";
@@ -0,0 +1,65 @@
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 { NIL as ZERO_UUID } from "uuid";
11
+ import { describe, expect, test } from "vitest";
12
+
13
+ import { newClient } from "@/setupspecs";
14
+
15
+ const client = newClient();
16
+
17
+ describe("Table", () => {
18
+ describe("create", () => {
19
+ test("create one", async () => {
20
+ const ws = await client.workspaces.create({ name: "Table", layout: { one: 1 } });
21
+ const table = await client.workspaces.table.create(ws.key, {
22
+ name: "Table",
23
+ data: { one: 1 },
24
+ });
25
+ expect(table.name).toEqual("Table");
26
+ expect(table.key).not.toEqual(ZERO_UUID);
27
+ expect(table.data.one).toEqual(1);
28
+ });
29
+ });
30
+ describe("rename", () => {
31
+ test("rename one", async () => {
32
+ const ws = await client.workspaces.create({ name: "Table", layout: { one: 1 } });
33
+ const table = await client.workspaces.table.create(ws.key, {
34
+ name: "Table",
35
+ data: { one: 1 },
36
+ });
37
+ await client.workspaces.table.rename(table.key, "Table2");
38
+ const res = await client.workspaces.table.retrieve(table.key);
39
+ expect(res.name).toEqual("Table2");
40
+ });
41
+ });
42
+ describe("setData", () => {
43
+ test("set data", async () => {
44
+ const ws = await client.workspaces.create({ name: "Table", layout: { one: 1 } });
45
+ const table = await client.workspaces.table.create(ws.key, {
46
+ name: "Table",
47
+ data: { one: 1 },
48
+ });
49
+ await client.workspaces.table.setData(table.key, { two: 2 });
50
+ const res = await client.workspaces.table.retrieve(table.key);
51
+ expect(res.data.two).toEqual(2);
52
+ });
53
+ });
54
+ describe("delete", () => {
55
+ test("delete one", async () => {
56
+ const ws = await client.workspaces.create({ name: "Table", layout: { one: 1 } });
57
+ const table = await client.workspaces.table.create(ws.key, {
58
+ name: "Table",
59
+ data: { one: 1 },
60
+ });
61
+ await client.workspaces.table.delete(table.key);
62
+ await expect(client.workspaces.table.retrieve(table.key)).rejects.toThrow();
63
+ });
64
+ });
65
+ });
@@ -1,3 +0,0 @@
1
- export * from './client';
2
- export * from './payload';
3
- //# sourceMappingURL=external.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"external.d.ts","sourceRoot":"","sources":["../../src/workspace/external.ts"],"names":[],"mappings":"AASA,cAAc,oBAAoB,CAAC;AACnC,cAAc,qBAAqB,CAAC"}
@@ -1,3 +0,0 @@
1
- export * from './client';
2
- export * from './payload';
3
- //# sourceMappingURL=external.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"external.d.ts","sourceRoot":"","sources":["../../../src/workspace/lineplot/external.ts"],"names":[],"mappings":"AASA,cAAc,6BAA6B,CAAC;AAC5C,cAAc,8BAA8B,CAAC"}
@@ -1,9 +0,0 @@
1
- import { UnaryClient } from '@synnaxlabs/freighter';
2
- import { LinePlot, Params } from './payload';
3
- export declare class Retriever {
4
- private readonly ENDPOINT;
5
- private readonly client;
6
- constructor(client: UnaryClient);
7
- retrieve(linePlots: Params): Promise<LinePlot[]>;
8
- }
9
- //# sourceMappingURL=retriever.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"retriever.d.ts","sourceRoot":"","sources":["../../../src/workspace/lineplot/retriever.ts"],"names":[],"mappings":"AASA,OAAO,EAAgB,KAAK,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAIvE,OAAO,EAAE,KAAK,QAAQ,EAAa,KAAK,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAMrF,qBAAa,SAAS;IACpB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAkC;IAC3D,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAc;gBAEzB,MAAM,EAAE,WAAW;IAIzB,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,QAAQ,EAAE,CAAC;CAMvD"}
@@ -1,35 +0,0 @@
1
- import { UnaryClient } from '@synnaxlabs/freighter';
2
- import { UnknownRecord } from '@synnaxlabs/x/record';
3
- import { z } from 'zod';
4
- import { Key, LinePlot, Params } from './payload';
5
- export declare const newLinePlotZ: z.ZodEffects<z.ZodObject<{
6
- name: z.ZodString;
7
- key: z.ZodOptional<z.ZodString>;
8
- data: z.ZodUnion<[z.ZodRecord<z.ZodUnion<[z.ZodNumber, z.ZodString, z.ZodSymbol]>, z.ZodUnknown>, z.ZodEffects<z.ZodString, UnknownRecord, string>]>;
9
- }, "strip", z.ZodTypeAny, {
10
- name: string;
11
- data: UnknownRecord | Record<string | number | symbol, unknown>;
12
- key?: string | undefined;
13
- }, {
14
- name: string;
15
- data: string | Record<string | number | symbol, unknown>;
16
- key?: string | undefined;
17
- }>, {
18
- data: string;
19
- name: string;
20
- key?: string | undefined;
21
- }, {
22
- name: string;
23
- data: string | Record<string | number | symbol, unknown>;
24
- key?: string | undefined;
25
- }>;
26
- export type NewLinePlot = z.input<typeof newLinePlotZ>;
27
- export declare class Writer {
28
- private readonly client;
29
- constructor(client: UnaryClient);
30
- create(workspace: string, plot: NewLinePlot): Promise<LinePlot>;
31
- delete(workspaces: Params): Promise<void>;
32
- rename(plot: Key, name: string): Promise<void>;
33
- setData(plot: Key, data: UnknownRecord): Promise<void>;
34
- }
35
- //# sourceMappingURL=writer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"writer.d.ts","sourceRoot":"","sources":["../../../src/workspace/lineplot/writer.ts"],"names":[],"mappings":"AASA,OAAO,EAAgB,KAAK,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACvE,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EACL,KAAK,GAAG,EAER,KAAK,QAAQ,EAEb,KAAK,MAAM,EACZ,MAAM,8BAA8B,CAAC;AAGtC,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;EAGtB,CAAC;AAEJ,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAC;AAoCvD,qBAAa,MAAM;IACjB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAc;gBAEzB,MAAM,EAAE,WAAW;IAIzB,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,QAAQ,CAAC;IAa/D,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAWzC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAU9C,OAAO,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC;CAS7D"}
@@ -1,3 +0,0 @@
1
- export * from './client';
2
- export * from './payload';
3
- //# sourceMappingURL=external.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"external.d.ts","sourceRoot":"","sources":["../../../src/workspace/log/external.ts"],"names":[],"mappings":"AASA,cAAc,wBAAwB,CAAC;AACvC,cAAc,yBAAyB,CAAC"}
@@ -1,36 +0,0 @@
1
- import { UnknownRecord } from '@synnaxlabs/x/record';
2
- import { z } from 'zod';
3
- import { ontology } from '../../ontology';
4
- export declare const keyZ: z.ZodString;
5
- export type Key = z.infer<typeof keyZ>;
6
- export type Params = Key | Key[];
7
- export declare const logZ: z.ZodObject<{
8
- key: z.ZodString;
9
- name: z.ZodString;
10
- data: z.ZodUnion<[z.ZodRecord<z.ZodUnion<[z.ZodNumber, z.ZodString, z.ZodSymbol]>, z.ZodUnknown>, z.ZodEffects<z.ZodString, UnknownRecord, string>]>;
11
- }, "strip", z.ZodTypeAny, {
12
- name: string;
13
- key: string;
14
- data: UnknownRecord | Record<string | number | symbol, unknown>;
15
- }, {
16
- name: string;
17
- key: string;
18
- data: string | Record<string | number | symbol, unknown>;
19
- }>;
20
- export declare const logRemoteZ: z.ZodObject<{
21
- key: z.ZodString;
22
- name: z.ZodString;
23
- data: z.ZodEffects<z.ZodString, UnknownRecord, string>;
24
- }, "strip", z.ZodTypeAny, {
25
- name: string;
26
- key: string;
27
- data: UnknownRecord;
28
- }, {
29
- name: string;
30
- key: string;
31
- data: string;
32
- }>;
33
- export type Log = z.infer<typeof logZ>;
34
- export declare const ONTOLOGY_TYPE: ontology.ResourceType;
35
- export declare const ontologyID: (key: Key) => ontology.ID;
36
- //# sourceMappingURL=payload.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"payload.d.ts","sourceRoot":"","sources":["../../../src/workspace/log/payload.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,KAAK,aAAa,EAAkB,MAAM,sBAAsB,CAAC;AAC1E,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,eAAO,MAAM,IAAI,aAAoB,CAAC;AACtC,MAAM,MAAM,GAAG,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC;AACvC,MAAM,MAAM,MAAM,GAAG,GAAG,GAAG,GAAG,EAAE,CAAC;AAEjC,eAAO,MAAM,IAAI;;;;;;;;;;;;EAIf,CAAC;AAEH,eAAO,MAAM,UAAU;;;;;;;;;;;;EAIrB,CAAC;AAEH,MAAM,MAAM,GAAG,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,IAAI,CAAC,CAAC;AAEvC,eAAO,MAAM,aAAa,EAAE,QAAQ,CAAC,YAAoB,CAAC;AAE1D,eAAO,MAAM,UAAU,QAAS,GAAG,KAAG,QAAQ,CAAC,EACA,CAAC"}
@@ -1,9 +0,0 @@
1
- import { UnaryClient } from '@synnaxlabs/freighter';
2
- import { Log, Params } from './payload';
3
- export declare class Retriever {
4
- private readonly ENDPOINT;
5
- private readonly client;
6
- constructor(client: UnaryClient);
7
- retrieve(logs: Params): Promise<Log[]>;
8
- }
9
- //# sourceMappingURL=retriever.d.ts.map