@synnaxlabs/client 0.35.0 → 0.37.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.
- package/.turbo/turbo-build.log +7 -7
- package/dist/client.cjs +28 -28
- package/dist/client.d.ts +35 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +3125 -2990
- package/dist/control/state.d.ts.map +1 -1
- package/dist/framer/deleter.d.ts.map +1 -1
- package/dist/framer/frame.d.ts +14 -7
- package/dist/framer/frame.d.ts.map +1 -1
- package/dist/framer/writer.d.ts +8 -8
- package/dist/framer/writer.d.ts.map +1 -1
- package/dist/hardware/device/payload.d.ts +2 -2
- package/dist/hardware/device/payload.d.ts.map +1 -1
- package/dist/hardware/task/payload.d.ts +4 -4
- package/dist/hardware/task/payload.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/ontology/group/payload.d.ts +3 -0
- package/dist/ontology/group/payload.d.ts.map +1 -1
- package/dist/ranger/client.d.ts +1 -0
- package/dist/ranger/client.d.ts.map +1 -1
- package/dist/ranger/payload.d.ts.map +1 -1
- package/dist/ranger/writer.d.ts.map +1 -1
- package/dist/transport.d.ts +2 -1
- package/dist/transport.d.ts.map +1 -1
- package/dist/workspace/client.d.ts +68 -11
- package/dist/workspace/client.d.ts.map +1 -1
- package/dist/workspace/index.d.ts +1 -1
- package/dist/workspace/index.d.ts.map +1 -1
- package/dist/workspace/lineplot/client.d.ts +48 -6
- package/dist/workspace/lineplot/client.d.ts.map +1 -1
- package/dist/workspace/lineplot/index.d.ts +1 -1
- package/dist/workspace/lineplot/index.d.ts.map +1 -1
- package/dist/workspace/log/client.d.ts +48 -6
- package/dist/workspace/log/client.d.ts.map +1 -1
- package/dist/workspace/log/index.d.ts +1 -1
- package/dist/workspace/log/index.d.ts.map +1 -1
- package/dist/workspace/schematic/client.d.ts +72 -6
- package/dist/workspace/schematic/client.d.ts.map +1 -1
- package/dist/workspace/schematic/index.d.ts +1 -1
- package/dist/workspace/schematic/index.d.ts.map +1 -1
- package/dist/workspace/table/client.d.ts +61 -6
- package/dist/workspace/table/client.d.ts.map +1 -1
- package/dist/workspace/table/index.d.ts +1 -1
- package/dist/workspace/table/index.d.ts.map +1 -1
- package/package.json +13 -13
- package/src/client.ts +16 -2
- package/src/control/state.ts +1 -1
- package/src/framer/frame.spec.ts +31 -3
- package/src/framer/frame.ts +17 -0
- package/src/framer/streamer.spec.ts +15 -6
- package/src/index.ts +1 -0
- package/src/ontology/group/payload.ts +9 -7
- package/src/ranger/client.ts +4 -1
- package/src/transport.ts +7 -2
- package/src/workspace/client.ts +147 -45
- package/src/workspace/index.ts +1 -1
- package/src/workspace/lineplot/client.ts +97 -28
- package/src/workspace/lineplot/index.ts +1 -1
- package/src/workspace/log/client.ts +94 -28
- package/src/workspace/log/index.ts +1 -1
- package/src/workspace/schematic/client.ts +122 -29
- package/src/workspace/schematic/index.ts +1 -1
- package/src/workspace/table/client.ts +103 -28
- package/src/workspace/table/index.ts +1 -1
- package/dist/workspace/external.d.ts +0 -3
- package/dist/workspace/external.d.ts.map +0 -1
- package/dist/workspace/lineplot/external.d.ts +0 -3
- package/dist/workspace/lineplot/external.d.ts.map +0 -1
- package/dist/workspace/lineplot/retriever.d.ts +0 -9
- package/dist/workspace/lineplot/retriever.d.ts.map +0 -1
- package/dist/workspace/lineplot/writer.d.ts +0 -35
- package/dist/workspace/lineplot/writer.d.ts.map +0 -1
- package/dist/workspace/log/external.d.ts +0 -3
- package/dist/workspace/log/external.d.ts.map +0 -1
- package/dist/workspace/log/payload.d.ts +0 -36
- package/dist/workspace/log/payload.d.ts.map +0 -1
- package/dist/workspace/log/retriever.d.ts +0 -9
- package/dist/workspace/log/retriever.d.ts.map +0 -1
- package/dist/workspace/log/writer.d.ts +0 -35
- package/dist/workspace/log/writer.d.ts.map +0 -1
- package/dist/workspace/payload.d.ts +0 -38
- package/dist/workspace/payload.d.ts.map +0 -1
- package/dist/workspace/retriever.d.ts +0 -13
- package/dist/workspace/retriever.d.ts.map +0 -1
- package/dist/workspace/schematic/external.d.ts +0 -3
- package/dist/workspace/schematic/external.d.ts.map +0 -1
- package/dist/workspace/schematic/payload.d.ts +0 -42
- package/dist/workspace/schematic/payload.d.ts.map +0 -1
- package/dist/workspace/schematic/retriever.d.ts +0 -9
- package/dist/workspace/schematic/retriever.d.ts.map +0 -1
- package/dist/workspace/schematic/writer.d.ts +0 -41
- package/dist/workspace/schematic/writer.d.ts.map +0 -1
- package/dist/workspace/table/external.d.ts +0 -3
- package/dist/workspace/table/external.d.ts.map +0 -1
- package/dist/workspace/table/payload.d.ts +0 -36
- package/dist/workspace/table/payload.d.ts.map +0 -1
- package/dist/workspace/table/retriever.d.ts +0 -8
- package/dist/workspace/table/retriever.d.ts.map +0 -1
- package/dist/workspace/table/writer.d.ts +0 -35
- package/dist/workspace/table/writer.d.ts.map +0 -1
- package/dist/workspace/writer.d.ts +0 -66
- package/dist/workspace/writer.d.ts.map +0 -1
- package/src/workspace/external.ts +0 -11
- package/src/workspace/lineplot/external.ts +0 -11
- package/src/workspace/lineplot/retriever.ts +0 -34
- package/src/workspace/lineplot/writer.ts +0 -115
- package/src/workspace/log/external.ts +0 -11
- package/src/workspace/log/payload.ts +0 -36
- package/src/workspace/log/retriever.ts +0 -38
- package/src/workspace/log/writer.ts +0 -116
- package/src/workspace/payload.ts +0 -44
- package/src/workspace/retriever.ts +0 -70
- package/src/workspace/schematic/external.ts +0 -11
- package/src/workspace/schematic/payload.ts +0 -38
- package/src/workspace/schematic/retriever.ts +0 -42
- package/src/workspace/schematic/writer.ts +0 -140
- package/src/workspace/table/external.ts +0 -11
- package/src/workspace/table/payload.ts +0 -36
- package/src/workspace/table/retriever.ts +0 -33
- package/src/workspace/table/writer.ts +0 -102
- package/src/workspace/writer.ts +0 -111
package/src/workspace/client.ts
CHANGED
|
@@ -1,23 +1,73 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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";
|
|
1
|
+
import { sendRequired, type UnaryClient } from "@synnaxlabs/freighter";
|
|
2
|
+
import { toArray, type UnknownRecord } from "@synnaxlabs/x";
|
|
3
|
+
import { unknownRecordZ } from "@synnaxlabs/x/record";
|
|
12
4
|
import { type AsyncTermSearcher } from "@synnaxlabs/x/search";
|
|
5
|
+
import { z } from "zod";
|
|
13
6
|
|
|
7
|
+
import { ontology } from "@/ontology";
|
|
8
|
+
import { nullableArrayZ } from "@/util/zod";
|
|
14
9
|
import { linePlot } from "@/workspace/lineplot";
|
|
15
10
|
import { log } from "@/workspace/log";
|
|
16
|
-
import { type Key, type Workspace } from "@/workspace/payload";
|
|
17
|
-
import { Retriever } from "@/workspace/retriever";
|
|
18
11
|
import { schematic } from "@/workspace/schematic";
|
|
19
12
|
import { table } from "@/workspace/table";
|
|
20
|
-
|
|
13
|
+
|
|
14
|
+
export const keyZ = z.string().uuid();
|
|
15
|
+
export type Key = z.infer<typeof keyZ>;
|
|
16
|
+
export type Params = Key | Key[];
|
|
17
|
+
|
|
18
|
+
// --- VERY IMPORTANT ---
|
|
19
|
+
// Synnax's encoders (in the binary package inside x) automatically convert the case
|
|
20
|
+
// of keys in objects to snake_case and back to camelCase when encoding and decoding
|
|
21
|
+
// respectively. This is done to ensure that the keys are consistent across all
|
|
22
|
+
// languages and platforms. Sometimes workspaces have keys that are uuids, which have
|
|
23
|
+
// dashes, and those get messed up. So we just use regular JSON for workspaces.
|
|
24
|
+
const parse = (s: string): UnknownRecord => JSON.parse(s) as UnknownRecord;
|
|
25
|
+
|
|
26
|
+
export const workspaceZ = z.object({
|
|
27
|
+
key: z.string(),
|
|
28
|
+
name: z.string(),
|
|
29
|
+
layout: unknownRecordZ.or(z.string().transform((s) => parse(s) as UnknownRecord)),
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
export type Workspace = z.infer<typeof workspaceZ>;
|
|
33
|
+
|
|
34
|
+
export const ONTOLOGY_TYPE: ontology.ResourceType = "workspace";
|
|
35
|
+
|
|
36
|
+
export const ontologyID = (key: Key): ontology.ID =>
|
|
37
|
+
new ontology.ID({ type: ONTOLOGY_TYPE, key });
|
|
38
|
+
|
|
39
|
+
const RETRIEVE_ENDPOINT = "/workspace/retrieve";
|
|
40
|
+
const CREATE_ENDPOINT = "/workspace/create";
|
|
41
|
+
const RENAME_ENDPOINT = "/workspace/rename";
|
|
42
|
+
const SET_LAYOUT_ENDPOINT = "/workspace/set-layout";
|
|
43
|
+
const DELETE_ENDPOINT = "/workspace/delete";
|
|
44
|
+
|
|
45
|
+
export const newWorkspaceZ = workspaceZ.partial({ key: true }).transform((p) => ({
|
|
46
|
+
...p,
|
|
47
|
+
layout: JSON.stringify(p.layout),
|
|
48
|
+
}));
|
|
49
|
+
|
|
50
|
+
export const workspaceRemoteZ = workspaceZ.omit({ layout: true }).extend({
|
|
51
|
+
layout: z.string().transform((s) => parse(s) as UnknownRecord),
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
export type NewWorkspace = z.input<typeof newWorkspaceZ>;
|
|
55
|
+
|
|
56
|
+
const retrieveReqZ = z.object({
|
|
57
|
+
keys: z.string().array().optional(),
|
|
58
|
+
search: z.string().optional(),
|
|
59
|
+
author: z.string().uuid().optional(),
|
|
60
|
+
offset: z.number().optional(),
|
|
61
|
+
limit: z.number().optional(),
|
|
62
|
+
});
|
|
63
|
+
const createReqZ = z.object({ workspaces: newWorkspaceZ.array() });
|
|
64
|
+
const renameReqZ = z.object({ key: z.string(), name: z.string() });
|
|
65
|
+
const setLayoutReqZ = z.object({ key: z.string(), layout: z.string() });
|
|
66
|
+
const deleteReqZ = z.object({ keys: z.string().array() });
|
|
67
|
+
|
|
68
|
+
const retrieveResZ = z.object({ workspaces: nullableArrayZ(workspaceZ) });
|
|
69
|
+
const createResZ = z.object({ workspaces: workspaceRemoteZ.array() });
|
|
70
|
+
const emptyResZ = z.object({});
|
|
21
71
|
|
|
22
72
|
export class Client implements AsyncTermSearcher<string, Key, Workspace> {
|
|
23
73
|
readonly type = "workspace";
|
|
@@ -25,59 +75,111 @@ export class Client implements AsyncTermSearcher<string, Key, Workspace> {
|
|
|
25
75
|
readonly linePlot: linePlot.Client;
|
|
26
76
|
readonly log: log.Client;
|
|
27
77
|
readonly table: table.Client;
|
|
28
|
-
private readonly
|
|
29
|
-
private readonly writer: Writer;
|
|
78
|
+
private readonly client: UnaryClient;
|
|
30
79
|
|
|
31
80
|
constructor(client: UnaryClient) {
|
|
81
|
+
this.client = client;
|
|
32
82
|
this.schematic = new schematic.Client(client);
|
|
33
83
|
this.linePlot = new linePlot.Client(client);
|
|
34
|
-
this.retriever = new Retriever(client);
|
|
35
84
|
this.log = new log.Client(client);
|
|
36
|
-
this.writer = new Writer(client);
|
|
37
85
|
this.table = new table.Client(client);
|
|
38
86
|
}
|
|
39
87
|
|
|
40
|
-
async
|
|
41
|
-
|
|
88
|
+
async create(workspace: NewWorkspace): Promise<Workspace>;
|
|
89
|
+
async create(workspaces: NewWorkspace[]): Promise<Workspace[]>;
|
|
90
|
+
async create(
|
|
91
|
+
workspaces: NewWorkspace | NewWorkspace[],
|
|
92
|
+
): Promise<Workspace | Workspace[]> {
|
|
93
|
+
const isMany = Array.isArray(workspaces);
|
|
94
|
+
const normalized = toArray(workspaces);
|
|
95
|
+
const res = await sendRequired(
|
|
96
|
+
this.client,
|
|
97
|
+
CREATE_ENDPOINT,
|
|
98
|
+
{ workspaces: normalized },
|
|
99
|
+
createReqZ,
|
|
100
|
+
createResZ,
|
|
101
|
+
);
|
|
102
|
+
return isMany ? res.workspaces : res.workspaces[0];
|
|
42
103
|
}
|
|
43
104
|
|
|
44
|
-
async
|
|
45
|
-
|
|
105
|
+
async rename(key: Key, name: string): Promise<void> {
|
|
106
|
+
await sendRequired(
|
|
107
|
+
this.client,
|
|
108
|
+
RENAME_ENDPOINT,
|
|
109
|
+
{ key, name },
|
|
110
|
+
renameReqZ,
|
|
111
|
+
emptyResZ,
|
|
112
|
+
);
|
|
46
113
|
}
|
|
47
114
|
|
|
48
|
-
async
|
|
115
|
+
async setLayout(key: Key, layout: UnknownRecord): Promise<void> {
|
|
116
|
+
await sendRequired(
|
|
117
|
+
this.client,
|
|
118
|
+
SET_LAYOUT_ENDPOINT,
|
|
119
|
+
{ key, layout: JSON.stringify(layout) },
|
|
120
|
+
setLayoutReqZ,
|
|
121
|
+
emptyResZ,
|
|
122
|
+
);
|
|
123
|
+
}
|
|
49
124
|
|
|
125
|
+
async retrieve(key: Key): Promise<Workspace>;
|
|
50
126
|
async retrieve(keys: Key[]): Promise<Workspace[]>;
|
|
51
|
-
|
|
52
|
-
async retrieve(keys: Key | Key[]): Promise<Workspace | Workspace[]> {
|
|
127
|
+
async retrieve(keys: Params): Promise<Workspace | Workspace[]> {
|
|
53
128
|
const isMany = Array.isArray(keys);
|
|
54
|
-
const
|
|
55
|
-
|
|
129
|
+
const normalized = toArray(keys);
|
|
130
|
+
const res = await sendRequired(
|
|
131
|
+
this.client,
|
|
132
|
+
RETRIEVE_ENDPOINT,
|
|
133
|
+
{ keys: normalized },
|
|
134
|
+
retrieveReqZ,
|
|
135
|
+
retrieveResZ,
|
|
136
|
+
);
|
|
137
|
+
return isMany ? res.workspaces : res.workspaces[0];
|
|
56
138
|
}
|
|
57
139
|
|
|
58
|
-
async
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const isMany = Array.isArray(workspaces);
|
|
68
|
-
const res = await this.writer.create(workspaces);
|
|
69
|
-
return isMany ? res : res[0];
|
|
140
|
+
async retrieveByAuthor(author: string): Promise<Workspace[]> {
|
|
141
|
+
const res = await sendRequired(
|
|
142
|
+
this.client,
|
|
143
|
+
RETRIEVE_ENDPOINT,
|
|
144
|
+
{ author },
|
|
145
|
+
retrieveReqZ,
|
|
146
|
+
retrieveResZ,
|
|
147
|
+
);
|
|
148
|
+
return res.workspaces;
|
|
70
149
|
}
|
|
71
150
|
|
|
72
|
-
async
|
|
73
|
-
await
|
|
151
|
+
async search(term: string): Promise<Workspace[]> {
|
|
152
|
+
const res = await sendRequired(
|
|
153
|
+
this.client,
|
|
154
|
+
RETRIEVE_ENDPOINT,
|
|
155
|
+
{ search: term },
|
|
156
|
+
retrieveReqZ,
|
|
157
|
+
retrieveResZ,
|
|
158
|
+
);
|
|
159
|
+
return res.workspaces;
|
|
74
160
|
}
|
|
75
161
|
|
|
76
|
-
async
|
|
77
|
-
await
|
|
162
|
+
async page(offset: number, limit: number): Promise<Workspace[]> {
|
|
163
|
+
const res = await sendRequired(
|
|
164
|
+
this.client,
|
|
165
|
+
RETRIEVE_ENDPOINT,
|
|
166
|
+
{ offset, limit },
|
|
167
|
+
retrieveReqZ,
|
|
168
|
+
retrieveResZ,
|
|
169
|
+
);
|
|
170
|
+
return res.workspaces;
|
|
78
171
|
}
|
|
79
172
|
|
|
80
|
-
async delete(
|
|
81
|
-
|
|
173
|
+
async delete(key: Key): Promise<void>;
|
|
174
|
+
async delete(keys: Key[]): Promise<void>;
|
|
175
|
+
async delete(keys: Params): Promise<void> {
|
|
176
|
+
const normalized = toArray(keys);
|
|
177
|
+
await sendRequired(
|
|
178
|
+
this.client,
|
|
179
|
+
DELETE_ENDPOINT,
|
|
180
|
+
{ keys: normalized },
|
|
181
|
+
deleteReqZ,
|
|
182
|
+
emptyResZ,
|
|
183
|
+
);
|
|
82
184
|
}
|
|
83
185
|
}
|
package/src/workspace/index.ts
CHANGED
|
@@ -1,51 +1,120 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
import { sendRequired, type UnaryClient } from "@synnaxlabs/freighter";
|
|
2
|
+
import { toArray, type UnknownRecord } from "@synnaxlabs/x";
|
|
3
|
+
import { unknownRecordZ } from "@synnaxlabs/x/record";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
|
|
6
|
+
import { ontology } from "@/ontology";
|
|
7
|
+
import { nullableArrayZ } from "@/util/zod";
|
|
8
|
+
|
|
9
|
+
export const keyZ = z.string().uuid();
|
|
10
|
+
export type Key = z.infer<typeof keyZ>;
|
|
11
|
+
export type Params = Key | Key[];
|
|
12
|
+
|
|
13
|
+
export const linePlotZ = z.object({
|
|
14
|
+
key: z.string(),
|
|
15
|
+
name: z.string(),
|
|
16
|
+
data: unknownRecordZ.or(z.string().transform((s) => JSON.parse(s) as UnknownRecord)),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export type LinePlot = z.infer<typeof linePlotZ>;
|
|
20
|
+
|
|
21
|
+
export const ONTOLOGY_TYPE: ontology.ResourceType = "lineplot";
|
|
22
|
+
|
|
23
|
+
export const ontologyID = (key: Key): ontology.ID =>
|
|
24
|
+
new ontology.ID({ type: ONTOLOGY_TYPE, key });
|
|
25
|
+
|
|
26
|
+
const RETRIEVE_ENDPOINT = "/workspace/lineplot/retrieve";
|
|
27
|
+
const CREATE_ENDPOINT = "/workspace/lineplot/create";
|
|
28
|
+
const RENAME_ENDPOINT = "/workspace/lineplot/rename";
|
|
29
|
+
const SET_DATA_ENDPOINT = "/workspace/lineplot/set-data";
|
|
30
|
+
const DELETE_ENDPOINT = "/workspace/lineplot/delete";
|
|
31
|
+
|
|
32
|
+
export const newLinePlotZ = linePlotZ.partial({ key: true }).transform((p) => ({
|
|
33
|
+
...p,
|
|
34
|
+
data: JSON.stringify(p.data),
|
|
35
|
+
}));
|
|
36
|
+
|
|
37
|
+
export type NewLinePlot = z.input<typeof newLinePlotZ>;
|
|
38
|
+
|
|
39
|
+
const retrieveReqZ = z.object({ keys: keyZ.array() });
|
|
40
|
+
const createReqZ = z.object({ workspace: z.string(), linePlots: newLinePlotZ.array() });
|
|
41
|
+
const renameReqZ = z.object({ key: keyZ, name: z.string() });
|
|
42
|
+
const setDataReqZ = z.object({ key: keyZ, data: z.string() });
|
|
43
|
+
const deleteReqZ = z.object({ keys: keyZ.array() });
|
|
44
|
+
const retrieveResZ = z.object({ linePlots: nullableArrayZ(linePlotZ) });
|
|
45
|
+
const createResZ = z.object({ linePlots: linePlotZ.array() });
|
|
46
|
+
const emptyResZ = z.object({});
|
|
16
47
|
|
|
17
48
|
export class Client {
|
|
18
|
-
private readonly
|
|
19
|
-
private readonly retriever: Retriever;
|
|
49
|
+
private readonly client: UnaryClient;
|
|
20
50
|
|
|
21
51
|
constructor(client: UnaryClient) {
|
|
22
|
-
this.
|
|
23
|
-
this.retriever = new Retriever(client);
|
|
52
|
+
this.client = client;
|
|
24
53
|
}
|
|
25
54
|
|
|
26
|
-
async create(workspace: string, linePlot: NewLinePlot): Promise<LinePlot
|
|
27
|
-
|
|
55
|
+
async create(workspace: string, linePlot: NewLinePlot): Promise<LinePlot>;
|
|
56
|
+
async create(workspace: string, linePlots: NewLinePlot[]): Promise<LinePlot[]>;
|
|
57
|
+
async create(
|
|
58
|
+
workspace: string,
|
|
59
|
+
linePlots: NewLinePlot | NewLinePlot[],
|
|
60
|
+
): Promise<LinePlot | LinePlot[]> {
|
|
61
|
+
const isMany = Array.isArray(linePlots);
|
|
62
|
+
const normalized = toArray(linePlots);
|
|
63
|
+
const res = await sendRequired(
|
|
64
|
+
this.client,
|
|
65
|
+
CREATE_ENDPOINT,
|
|
66
|
+
{ workspace, linePlots: normalized },
|
|
67
|
+
createReqZ,
|
|
68
|
+
createResZ,
|
|
69
|
+
);
|
|
70
|
+
return isMany ? res.linePlots : res.linePlots[0];
|
|
28
71
|
}
|
|
29
72
|
|
|
30
73
|
async rename(key: Key, name: string): Promise<void> {
|
|
31
|
-
await
|
|
74
|
+
await sendRequired(
|
|
75
|
+
this.client,
|
|
76
|
+
RENAME_ENDPOINT,
|
|
77
|
+
{ key, name },
|
|
78
|
+
renameReqZ,
|
|
79
|
+
emptyResZ,
|
|
80
|
+
);
|
|
32
81
|
}
|
|
33
82
|
|
|
34
83
|
async setData(key: Key, data: UnknownRecord): Promise<void> {
|
|
35
|
-
await
|
|
84
|
+
await sendRequired(
|
|
85
|
+
this.client,
|
|
86
|
+
SET_DATA_ENDPOINT,
|
|
87
|
+
{ key, data: JSON.stringify(data) },
|
|
88
|
+
setDataReqZ,
|
|
89
|
+
emptyResZ,
|
|
90
|
+
);
|
|
36
91
|
}
|
|
37
92
|
|
|
38
93
|
async retrieve(key: Key): Promise<LinePlot>;
|
|
39
|
-
|
|
40
94
|
async retrieve(keys: Key[]): Promise<LinePlot[]>;
|
|
41
|
-
|
|
42
95
|
async retrieve(keys: Params): Promise<LinePlot | LinePlot[]> {
|
|
43
96
|
const isMany = Array.isArray(keys);
|
|
44
|
-
const
|
|
45
|
-
|
|
97
|
+
const normalized = toArray(keys);
|
|
98
|
+
const res = await sendRequired(
|
|
99
|
+
this.client,
|
|
100
|
+
RETRIEVE_ENDPOINT,
|
|
101
|
+
{ keys: normalized },
|
|
102
|
+
retrieveReqZ,
|
|
103
|
+
retrieveResZ,
|
|
104
|
+
);
|
|
105
|
+
return isMany ? res.linePlots : res.linePlots[0];
|
|
46
106
|
}
|
|
47
107
|
|
|
108
|
+
async delete(key: Key): Promise<void>;
|
|
109
|
+
async delete(keys: Key[]): Promise<void>;
|
|
48
110
|
async delete(keys: Params): Promise<void> {
|
|
49
|
-
|
|
111
|
+
const normalized = toArray(keys);
|
|
112
|
+
await sendRequired(
|
|
113
|
+
this.client,
|
|
114
|
+
DELETE_ENDPOINT,
|
|
115
|
+
{ keys: normalized },
|
|
116
|
+
deleteReqZ,
|
|
117
|
+
emptyResZ,
|
|
118
|
+
);
|
|
50
119
|
}
|
|
51
120
|
}
|
|
@@ -1,51 +1,117 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
import { sendRequired, type UnaryClient } from "@synnaxlabs/freighter";
|
|
2
|
+
import { toArray, type UnknownRecord } from "@synnaxlabs/x";
|
|
3
|
+
import { unknownRecordZ } from "@synnaxlabs/x/record";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
|
|
6
|
+
import { ontology } from "@/ontology";
|
|
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 logZ = z.object({
|
|
13
|
+
key: z.string(),
|
|
14
|
+
name: z.string(),
|
|
15
|
+
data: unknownRecordZ.or(z.string().transform((s) => JSON.parse(s) as UnknownRecord)),
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
export type Log = z.infer<typeof logZ>;
|
|
19
|
+
|
|
20
|
+
export const ONTOLOGY_TYPE: ontology.ResourceType = "log";
|
|
21
|
+
|
|
22
|
+
export const ontologyID = (key: Key): ontology.ID =>
|
|
23
|
+
new ontology.ID({ type: ONTOLOGY_TYPE, key });
|
|
24
|
+
|
|
25
|
+
const RETRIEVE_ENDPOINT = "/workspace/log/retrieve";
|
|
26
|
+
const CREATE_ENDPOINT = "/workspace/log/create";
|
|
27
|
+
const RENAME_ENDPOINT = "/workspace/log/rename";
|
|
28
|
+
const SET_DATA_ENDPOINT = "/workspace/log/set-data";
|
|
29
|
+
const DELETE_ENDPOINT = "/workspace/log/delete";
|
|
30
|
+
|
|
31
|
+
export const newLogZ = logZ.partial({ key: true }).transform((p) => ({
|
|
32
|
+
...p,
|
|
33
|
+
data: JSON.stringify(p.data),
|
|
34
|
+
}));
|
|
35
|
+
|
|
36
|
+
export type NewLog = z.input<typeof newLogZ>;
|
|
37
|
+
|
|
38
|
+
const retrieveReqZ = z.object({ keys: z.string().array() });
|
|
39
|
+
const createReqZ = z.object({ workspace: z.string(), logs: newLogZ.array() });
|
|
40
|
+
const renameReqZ = z.object({ key: z.string(), name: z.string() });
|
|
41
|
+
const setDataReqZ = z.object({ key: z.string(), data: z.string() });
|
|
42
|
+
const deleteReqZ = z.object({ keys: z.string().array() });
|
|
43
|
+
|
|
44
|
+
const retrieveResZ = z.object({ logs: logZ.array() });
|
|
45
|
+
const createResZ = z.object({ logs: logZ.array() });
|
|
46
|
+
const emptyResZ = z.object({});
|
|
16
47
|
|
|
17
48
|
export class Client {
|
|
18
|
-
private readonly
|
|
19
|
-
private readonly retriever: Retriever;
|
|
49
|
+
private readonly client: UnaryClient;
|
|
20
50
|
|
|
21
51
|
constructor(client: UnaryClient) {
|
|
22
|
-
this.
|
|
23
|
-
this.retriever = new Retriever(client);
|
|
52
|
+
this.client = client;
|
|
24
53
|
}
|
|
25
54
|
|
|
26
|
-
async create(workspace: string, log: NewLog): Promise<Log
|
|
27
|
-
|
|
55
|
+
async create(workspace: string, log: NewLog): Promise<Log>;
|
|
56
|
+
async create(workspace: string, logs: NewLog[]): Promise<Log[]>;
|
|
57
|
+
async create(workspace: string, logs: NewLog | NewLog[]): Promise<Log | Log[]> {
|
|
58
|
+
const isMany = Array.isArray(logs);
|
|
59
|
+
const normalized = toArray(logs);
|
|
60
|
+
const res = await sendRequired(
|
|
61
|
+
this.client,
|
|
62
|
+
CREATE_ENDPOINT,
|
|
63
|
+
{ workspace, logs: normalized },
|
|
64
|
+
createReqZ,
|
|
65
|
+
createResZ,
|
|
66
|
+
);
|
|
67
|
+
return isMany ? res.logs : res.logs[0];
|
|
28
68
|
}
|
|
29
69
|
|
|
30
70
|
async rename(key: Key, name: string): Promise<void> {
|
|
31
|
-
await
|
|
71
|
+
await sendRequired(
|
|
72
|
+
this.client,
|
|
73
|
+
RENAME_ENDPOINT,
|
|
74
|
+
{ key, name },
|
|
75
|
+
renameReqZ,
|
|
76
|
+
emptyResZ,
|
|
77
|
+
);
|
|
32
78
|
}
|
|
33
79
|
|
|
34
80
|
async setData(key: Key, data: UnknownRecord): Promise<void> {
|
|
35
|
-
await
|
|
81
|
+
await sendRequired(
|
|
82
|
+
this.client,
|
|
83
|
+
SET_DATA_ENDPOINT,
|
|
84
|
+
{ key, data: JSON.stringify(data) },
|
|
85
|
+
setDataReqZ,
|
|
86
|
+
emptyResZ,
|
|
87
|
+
);
|
|
36
88
|
}
|
|
37
89
|
|
|
38
90
|
async retrieve(key: Key): Promise<Log>;
|
|
39
|
-
|
|
40
91
|
async retrieve(keys: Key[]): Promise<Log[]>;
|
|
41
|
-
|
|
42
92
|
async retrieve(keys: Params): Promise<Log | Log[]> {
|
|
43
93
|
const isMany = Array.isArray(keys);
|
|
44
|
-
const
|
|
45
|
-
|
|
94
|
+
const normalized = toArray(keys);
|
|
95
|
+
const res = await sendRequired(
|
|
96
|
+
this.client,
|
|
97
|
+
RETRIEVE_ENDPOINT,
|
|
98
|
+
{ keys: normalized },
|
|
99
|
+
retrieveReqZ,
|
|
100
|
+
retrieveResZ,
|
|
101
|
+
);
|
|
102
|
+
return isMany ? res.logs : res.logs[0];
|
|
46
103
|
}
|
|
47
104
|
|
|
105
|
+
async delete(key: Key): Promise<void>;
|
|
106
|
+
async delete(keys: Key[]): Promise<void>;
|
|
48
107
|
async delete(keys: Params): Promise<void> {
|
|
49
|
-
|
|
108
|
+
const normalized = toArray(keys);
|
|
109
|
+
await sendRequired(
|
|
110
|
+
this.client,
|
|
111
|
+
DELETE_ENDPOINT,
|
|
112
|
+
{ keys: normalized },
|
|
113
|
+
deleteReqZ,
|
|
114
|
+
emptyResZ,
|
|
115
|
+
);
|
|
50
116
|
}
|
|
51
117
|
}
|