@synnaxlabs/client 0.29.0 → 0.31.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 +6 -6
- package/api/client.api.md +615 -261
- package/dist/access/client.d.ts +2 -7
- package/dist/access/client.d.ts.map +1 -1
- package/dist/access/payload.d.ts +7 -102
- package/dist/access/payload.d.ts.map +1 -1
- package/dist/access/policy/client.d.ts +17 -0
- package/dist/access/policy/client.d.ts.map +1 -0
- package/dist/access/policy/external.d.ts +3 -0
- package/dist/access/policy/external.d.ts.map +1 -0
- package/dist/access/policy/index.d.ts +2 -0
- package/dist/access/policy/index.d.ts.map +1 -0
- package/dist/access/policy/payload.d.ts +163 -0
- package/dist/access/policy/payload.d.ts.map +1 -0
- package/dist/access/policy/policy.spec.d.ts +2 -0
- package/dist/access/policy/policy.spec.d.ts.map +1 -0
- package/dist/access/policy/retriever.d.ts +36 -0
- package/dist/access/policy/retriever.d.ts.map +1 -0
- package/dist/access/policy/writer.d.ts +9 -0
- package/dist/access/policy/writer.d.ts.map +1 -0
- package/dist/auth/auth.d.ts +6 -30
- package/dist/auth/auth.d.ts.map +1 -1
- package/dist/channel/payload.d.ts +17 -17
- package/dist/channel/payload.d.ts.map +1 -1
- package/dist/channel/retriever.d.ts +8 -8
- package/dist/client.cjs +31 -21
- package/dist/client.js +2962 -2230
- package/dist/framer/client.d.ts +4 -1
- package/dist/framer/client.d.ts.map +1 -1
- package/dist/framer/frame.d.ts +27 -80
- package/dist/framer/frame.d.ts.map +1 -1
- package/dist/framer/streamer.d.ts +3 -1
- package/dist/framer/streamer.d.ts.map +1 -1
- package/dist/framer/writer.d.ts +24 -16
- package/dist/framer/writer.d.ts.map +1 -1
- package/dist/hardware/device/client.d.ts +2 -2
- package/dist/hardware/device/payload.d.ts +1 -1
- package/dist/hardware/device/payload.d.ts.map +1 -1
- package/dist/hardware/rack/payload.d.ts +1 -1
- package/dist/hardware/rack/payload.d.ts.map +1 -1
- package/dist/hardware/task/client.d.ts +2 -2
- package/dist/hardware/task/ni/types.d.ts +16 -16
- package/dist/hardware/task/payload.d.ts +13 -13
- package/dist/hardware/task/payload.d.ts.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/label/payload.d.ts +1 -1
- package/dist/label/payload.d.ts.map +1 -1
- package/dist/label/writer.d.ts +5 -5
- package/dist/ontology/client.d.ts +32 -30
- package/dist/ontology/client.d.ts.map +1 -1
- package/dist/ontology/payload.d.ts +62 -63
- package/dist/ontology/payload.d.ts.map +1 -1
- package/dist/ranger/payload.d.ts +2 -2
- package/dist/ranger/payload.d.ts.map +1 -1
- package/dist/ranger/writer.d.ts +5 -5
- package/dist/user/client.d.ts +13 -3
- package/dist/user/client.d.ts.map +1 -1
- package/dist/user/payload.d.ts +34 -3
- package/dist/user/payload.d.ts.map +1 -1
- package/dist/user/retriever.d.ts +21 -0
- package/dist/user/retriever.d.ts.map +1 -0
- package/dist/user/user.spec.d.ts +2 -0
- package/dist/user/user.spec.d.ts.map +1 -0
- package/dist/user/writer.d.ts +11 -0
- package/dist/user/writer.d.ts.map +1 -0
- package/dist/workspace/lineplot/payload.d.ts +1 -1
- package/dist/workspace/lineplot/payload.d.ts.map +1 -1
- package/dist/workspace/payload.d.ts +1 -1
- package/dist/workspace/payload.d.ts.map +1 -1
- package/dist/workspace/schematic/client.d.ts.map +1 -1
- package/dist/workspace/schematic/payload.d.ts +1 -1
- package/dist/workspace/schematic/payload.d.ts.map +1 -1
- package/examples/node/package-lock.json +963 -134
- package/examples/node/package.json +1 -1
- package/package.json +3 -3
- package/src/access/client.ts +4 -70
- package/src/access/payload.ts +14 -24
- package/src/access/policy/client.ts +65 -0
- package/src/access/policy/external.ts +11 -0
- package/src/access/policy/index.ts +10 -0
- package/src/access/policy/payload.ts +45 -0
- package/src/access/policy/policy.spec.ts +331 -0
- package/src/access/policy/retriever.ts +43 -0
- package/src/access/policy/writer.ts +65 -0
- package/src/auth/auth.ts +32 -10
- package/src/channel/payload.ts +2 -2
- package/src/framer/client.ts +7 -1
- package/src/framer/frame.spec.ts +21 -12
- package/src/framer/frame.ts +9 -24
- package/src/framer/streamer.spec.ts +51 -0
- package/src/framer/streamer.ts +9 -4
- package/src/framer/writer.ts +0 -2
- package/src/hardware/device/payload.ts +2 -2
- package/src/hardware/rack/payload.ts +2 -2
- package/src/hardware/task/payload.ts +2 -2
- package/src/index.ts +16 -13
- package/src/label/payload.ts +2 -2
- package/src/ontology/client.ts +35 -34
- package/src/ontology/payload.ts +28 -35
- package/src/ranger/payload.ts +5 -7
- package/src/setupspecs.ts +2 -2
- package/src/user/client.ts +63 -19
- package/src/user/payload.ts +14 -7
- package/src/user/retriever.ts +41 -0
- package/src/user/user.spec.ts +289 -0
- package/src/user/writer.ts +91 -0
- package/src/workspace/lineplot/payload.ts +2 -2
- package/src/workspace/payload.ts +2 -2
- package/src/workspace/schematic/client.ts +1 -1
- package/src/workspace/schematic/payload.ts +2 -2
- package/src/workspace/workspace.spec.ts +1 -1
- package/dist/access/access.spec.d.ts +0 -2
- package/dist/access/access.spec.d.ts.map +0 -1
- package/src/access/access.spec.ts +0 -276
|
@@ -0,0 +1,289 @@
|
|
|
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 { id } from "@synnaxlabs/x";
|
|
11
|
+
import { describe, expect, test } from "vitest";
|
|
12
|
+
|
|
13
|
+
import { AuthError, NotFoundError } from "@/errors";
|
|
14
|
+
import { newClient } from "@/setupspecs";
|
|
15
|
+
import { type user } from "@/user";
|
|
16
|
+
|
|
17
|
+
type SortType = { username: string };
|
|
18
|
+
|
|
19
|
+
const sort = (a: SortType, b: SortType) => a.username.localeCompare(b.username);
|
|
20
|
+
|
|
21
|
+
const client = newClient();
|
|
22
|
+
|
|
23
|
+
const userOne: user.NewUser = {
|
|
24
|
+
username: id.id(),
|
|
25
|
+
password: "test",
|
|
26
|
+
firstName: "George",
|
|
27
|
+
lastName: "Washington",
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const userTwo: user.NewUser = { username: id.id(), password: "test" };
|
|
31
|
+
|
|
32
|
+
const userThree: user.NewUser = {
|
|
33
|
+
username: id.id(),
|
|
34
|
+
password: "test",
|
|
35
|
+
firstName: "John",
|
|
36
|
+
lastName: "Adams",
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const userArray: user.NewUser[] = [
|
|
40
|
+
{ username: id.id(), password: "secondTest", firstName: "Steve" },
|
|
41
|
+
{ username: id.id(), password: "testArray" },
|
|
42
|
+
].sort(sort);
|
|
43
|
+
|
|
44
|
+
describe("User", () => {
|
|
45
|
+
describe("Create", () => {
|
|
46
|
+
describe("One", () => {
|
|
47
|
+
test("with a name", async () => {
|
|
48
|
+
const res = await client.user.create(userOne);
|
|
49
|
+
expect(res.username).toEqual(userOne.username);
|
|
50
|
+
expect(res.key).not.toEqual("");
|
|
51
|
+
expect(res.firstName).toEqual(userOne.firstName);
|
|
52
|
+
expect(res.lastName).toEqual(userOne.lastName);
|
|
53
|
+
userOne.key = res.key;
|
|
54
|
+
});
|
|
55
|
+
test("with no name", async () => {
|
|
56
|
+
const res = await client.user.create(userTwo);
|
|
57
|
+
expect(res.username).toEqual(userTwo.username);
|
|
58
|
+
expect(res.key).not.toEqual("");
|
|
59
|
+
userTwo.key = res.key;
|
|
60
|
+
expect(res.firstName).toEqual("");
|
|
61
|
+
expect(res.lastName).toEqual("");
|
|
62
|
+
});
|
|
63
|
+
test("Repeated username", async () =>
|
|
64
|
+
await expect(
|
|
65
|
+
client.user.create({ username: userOne.username, password: "test" }),
|
|
66
|
+
).rejects.toThrow(AuthError));
|
|
67
|
+
});
|
|
68
|
+
describe("Many", () => {
|
|
69
|
+
test("array empty", async () => {
|
|
70
|
+
const res = await client.user.create([]);
|
|
71
|
+
expect(res).toHaveLength(0);
|
|
72
|
+
});
|
|
73
|
+
test("array is one", async () => {
|
|
74
|
+
const res = await client.user.create([userThree]);
|
|
75
|
+
expect(res).toHaveLength(1);
|
|
76
|
+
expect(res[0].username).toEqual(userThree.username);
|
|
77
|
+
expect(res[0].key).not.toEqual("");
|
|
78
|
+
userThree.key = res[0].key;
|
|
79
|
+
expect(res[0].firstName).toEqual(userThree.firstName);
|
|
80
|
+
expect(res[0].lastName).toEqual(userThree.lastName);
|
|
81
|
+
});
|
|
82
|
+
test("array not empty", async () => {
|
|
83
|
+
const res = await client.user.create(userArray);
|
|
84
|
+
expect(res).toHaveLength(2);
|
|
85
|
+
userArray.forEach((u, i) => {
|
|
86
|
+
expect(res[i].username).toEqual(u.username);
|
|
87
|
+
expect(res[i].key).not.toEqual("");
|
|
88
|
+
userArray[i].key = res[i].key;
|
|
89
|
+
expect(res[i].firstName).toEqual(u.firstName ?? "");
|
|
90
|
+
expect(res[i].lastName).toEqual(u.lastName ?? "");
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
test("Repeated username", async () =>
|
|
94
|
+
await expect(client.user.create([userOne, userTwo])).rejects.toThrow(
|
|
95
|
+
AuthError,
|
|
96
|
+
));
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
describe("Retrieve", () => {
|
|
100
|
+
describe("by name", () => {
|
|
101
|
+
describe("one", () => {
|
|
102
|
+
test("found", async () => {
|
|
103
|
+
const res = await client.user.retrieveByName(userOne.username);
|
|
104
|
+
expect(res.username).toEqual(userOne.username);
|
|
105
|
+
expect(res.key).toEqual(userOne.key);
|
|
106
|
+
expect(res.firstName).toEqual(userOne.firstName);
|
|
107
|
+
expect(res.lastName).toEqual(userOne.lastName);
|
|
108
|
+
});
|
|
109
|
+
test("not found", async () =>
|
|
110
|
+
await expect(client.user.retrieveByName(id.id())).rejects.toThrow(
|
|
111
|
+
NotFoundError,
|
|
112
|
+
));
|
|
113
|
+
});
|
|
114
|
+
describe("many", () => {
|
|
115
|
+
test("found", async () => {
|
|
116
|
+
const res = await client.user.retrieveByName(
|
|
117
|
+
userArray.map((u) => u.username),
|
|
118
|
+
);
|
|
119
|
+
expect(res.sort(sort)).toHaveLength(2);
|
|
120
|
+
res.forEach((u, i) => {
|
|
121
|
+
expect(u.username).toEqual(userArray[i].username);
|
|
122
|
+
expect(u.key).toEqual(userArray[i].key);
|
|
123
|
+
expect(u.firstName).toEqual(userArray[i].firstName ?? "");
|
|
124
|
+
expect(u.lastName).toEqual(userArray[i].lastName ?? "");
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
test("not found", async () => {
|
|
128
|
+
const res = await client.user.retrieveByName([id.id()]);
|
|
129
|
+
expect(res).toEqual([]);
|
|
130
|
+
});
|
|
131
|
+
test("extra names getting deleted", async () => {
|
|
132
|
+
const res = await client.user.retrieveByName([
|
|
133
|
+
...userArray.map((u) => u.username),
|
|
134
|
+
id.id(),
|
|
135
|
+
]);
|
|
136
|
+
expect(res.sort(sort)).toHaveLength(2);
|
|
137
|
+
res.forEach((u, i) => {
|
|
138
|
+
expect(u.username).toEqual(userArray[i].username);
|
|
139
|
+
expect(u.key).toEqual(userArray[i].key);
|
|
140
|
+
expect(u.firstName).toEqual(userArray[i].firstName ?? "");
|
|
141
|
+
expect(u.lastName).toEqual(userArray[i].lastName ?? "");
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
test("calling with no names", async () => {
|
|
145
|
+
const res = await client.user.retrieveByName([]);
|
|
146
|
+
const usernames = res.map((u) => u.username);
|
|
147
|
+
expect(usernames).toContain(userOne.username);
|
|
148
|
+
expect(usernames).toContain(userTwo.username);
|
|
149
|
+
expect(usernames).toContain(userThree.username);
|
|
150
|
+
userArray.forEach((u) => expect(usernames).toContain(u.username));
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
describe("by key", () => {
|
|
155
|
+
describe("one", () => {
|
|
156
|
+
test("found", async () => {
|
|
157
|
+
const res = await client.user.retrieve(userOne.key as string);
|
|
158
|
+
expect(res.username).toEqual(userOne.username);
|
|
159
|
+
expect(res.key).toEqual(userOne.key);
|
|
160
|
+
expect(res.firstName).toEqual(userOne.firstName);
|
|
161
|
+
expect(res.lastName).toEqual(userOne.lastName);
|
|
162
|
+
});
|
|
163
|
+
test("not found", async () => {
|
|
164
|
+
await expect(
|
|
165
|
+
client.user.delete(userOne.key as string),
|
|
166
|
+
).resolves.toBeUndefined();
|
|
167
|
+
await expect(client.user.retrieve(userOne.key as string)).rejects.toThrow(
|
|
168
|
+
NotFoundError,
|
|
169
|
+
);
|
|
170
|
+
const u = await client.user.create(userOne);
|
|
171
|
+
userOne.key = u.key;
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
describe("many", () => {
|
|
175
|
+
test("found", async () => {
|
|
176
|
+
const res = await client.user.retrieve(userArray.map((u) => u.key as string));
|
|
177
|
+
expect(res.sort(sort)).toHaveLength(2);
|
|
178
|
+
res.forEach((u, i) => {
|
|
179
|
+
expect(u.username).toEqual(userArray[i].username);
|
|
180
|
+
expect(u.key).toEqual(userArray[i].key);
|
|
181
|
+
expect(u.firstName).toEqual(userArray[i].firstName ?? "");
|
|
182
|
+
expect(u.lastName).toEqual(userArray[i].lastName ?? "");
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
test("not found", async () => {
|
|
186
|
+
for (const u of userArray) {
|
|
187
|
+
await expect(client.user.delete(u.key as string)).resolves.toBeUndefined();
|
|
188
|
+
}
|
|
189
|
+
await expect(
|
|
190
|
+
client.user.retrieve(userArray.map((u) => u.key as string)),
|
|
191
|
+
).rejects.toThrow(NotFoundError);
|
|
192
|
+
// cleanup
|
|
193
|
+
const users = await client.user.create(userArray);
|
|
194
|
+
users.forEach((u, i) => (userArray[i].key = u.key));
|
|
195
|
+
});
|
|
196
|
+
test("all", async () => {
|
|
197
|
+
const res = await client.user.retrieve([]);
|
|
198
|
+
const usernames = res.map((u) => u.username);
|
|
199
|
+
expect(usernames).toContain(userOne.username);
|
|
200
|
+
expect(usernames).toContain(userTwo.username);
|
|
201
|
+
expect(usernames).toContain(userThree.username);
|
|
202
|
+
userArray.forEach((u) => expect(usernames).toContain(u.username));
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
});
|
|
207
|
+
describe("Change Username", () => {
|
|
208
|
+
test("Successful", async () => {
|
|
209
|
+
const newUsername = id.id();
|
|
210
|
+
await expect(
|
|
211
|
+
client.user.changeUsername(userOne.key as string, newUsername),
|
|
212
|
+
).resolves.toBeUndefined();
|
|
213
|
+
const res = await client.user.retrieveByName(newUsername);
|
|
214
|
+
expect(res.username).toEqual(newUsername);
|
|
215
|
+
expect(res.key).not.toEqual("");
|
|
216
|
+
expect(res.firstName).toEqual(userOne.firstName);
|
|
217
|
+
expect(res.lastName).toEqual(userOne.lastName);
|
|
218
|
+
userOne.username = newUsername;
|
|
219
|
+
});
|
|
220
|
+
test("Unsuccessful", async () =>
|
|
221
|
+
await expect(
|
|
222
|
+
client.user.changeUsername(userTwo.key as string, userOne.username),
|
|
223
|
+
).rejects.toThrow(AuthError));
|
|
224
|
+
test("Repeated usernames fail", async () => {
|
|
225
|
+
const oldUsername = id.id();
|
|
226
|
+
const user = await client.user.create({
|
|
227
|
+
username: oldUsername,
|
|
228
|
+
password: "test",
|
|
229
|
+
});
|
|
230
|
+
const newUsername = id.id();
|
|
231
|
+
await client.user.changeUsername(user.key, newUsername);
|
|
232
|
+
await expect(
|
|
233
|
+
client.user.create({ username: newUsername, password: "test" }),
|
|
234
|
+
).rejects.toThrow(AuthError);
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
describe("Change Name", () => {
|
|
238
|
+
test("Successful", async () => {
|
|
239
|
+
await expect(
|
|
240
|
+
client.user.rename(userOne.key as string, "Thomas", "Jefferson"),
|
|
241
|
+
).resolves.toBeUndefined();
|
|
242
|
+
const res = await client.user.retrieve(userOne.key as string);
|
|
243
|
+
expect(res.username).toEqual(userOne.username);
|
|
244
|
+
expect(res.key).toEqual(userOne.key);
|
|
245
|
+
expect(res.firstName).toEqual("Thomas");
|
|
246
|
+
expect(res.lastName).toEqual("Jefferson");
|
|
247
|
+
userOne.firstName = "Thomas";
|
|
248
|
+
userOne.lastName = "Jefferson";
|
|
249
|
+
});
|
|
250
|
+
test("Only one name", async () => {
|
|
251
|
+
await expect(
|
|
252
|
+
client.user.rename(userOne.key as string, "James"),
|
|
253
|
+
).resolves.toBeUndefined();
|
|
254
|
+
const res = await client.user.retrieve(userOne.key as string);
|
|
255
|
+
expect(res.username).toEqual(userOne.username);
|
|
256
|
+
expect(res.key).toEqual(userOne.key);
|
|
257
|
+
expect(res.firstName).toEqual("James");
|
|
258
|
+
expect(res.lastName).toEqual(userOne.lastName);
|
|
259
|
+
userOne.firstName = "James";
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
describe("Delete", () => {
|
|
263
|
+
test("one that exists", async () => {
|
|
264
|
+
await expect(client.user.delete(userOne.key as string)).resolves.toBeUndefined();
|
|
265
|
+
await expect(client.user.retrieve(userOne.key as string)).rejects.toThrow(
|
|
266
|
+
NotFoundError,
|
|
267
|
+
);
|
|
268
|
+
});
|
|
269
|
+
test("many that exist", async () => {
|
|
270
|
+
await expect(
|
|
271
|
+
client.user.delete(userArray.map((u) => u.key as string)),
|
|
272
|
+
).resolves.toBeUndefined();
|
|
273
|
+
await expect(
|
|
274
|
+
client.user.retrieve(userArray.map((u) => u.key as string)),
|
|
275
|
+
).rejects.toThrow(NotFoundError);
|
|
276
|
+
});
|
|
277
|
+
test("one that doesn't exist", async () => {
|
|
278
|
+
await expect(client.user.delete(userOne.key as string)).resolves.toBeUndefined();
|
|
279
|
+
});
|
|
280
|
+
test("many where some don't exist", async () => {
|
|
281
|
+
await expect(
|
|
282
|
+
client.user.delete([userOne.key as string, userTwo.key as string]),
|
|
283
|
+
).resolves.toBeUndefined();
|
|
284
|
+
await expect(client.user.retrieve(userTwo.key as string)).rejects.toThrow(
|
|
285
|
+
NotFoundError,
|
|
286
|
+
);
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
});
|
|
@@ -0,0 +1,91 @@
|
|
|
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 {
|
|
15
|
+
type Key,
|
|
16
|
+
keyZ,
|
|
17
|
+
type NewUser,
|
|
18
|
+
newUserZ,
|
|
19
|
+
type User,
|
|
20
|
+
userZ,
|
|
21
|
+
} from "@/user/payload";
|
|
22
|
+
|
|
23
|
+
const createReqZ = z.object({ users: newUserZ.array() });
|
|
24
|
+
const createResZ = z.object({ users: userZ.array() });
|
|
25
|
+
|
|
26
|
+
const changeUsernameReqZ = z.object({ key: keyZ, username: z.string().min(1) });
|
|
27
|
+
const changeUsernameResZ = z.object({});
|
|
28
|
+
|
|
29
|
+
const renameReqZ = z.object({
|
|
30
|
+
key: keyZ,
|
|
31
|
+
firstName: z.string().optional(),
|
|
32
|
+
lastName: z.string().optional(),
|
|
33
|
+
});
|
|
34
|
+
const renameResZ = z.object({});
|
|
35
|
+
|
|
36
|
+
const deleteReqZ = z.object({ keys: keyZ.array() });
|
|
37
|
+
const deleteResZ = z.object({});
|
|
38
|
+
|
|
39
|
+
const CREATE_ENDPOINT = "/user/create";
|
|
40
|
+
const CHANGE_USERNAME_ENDPOINT = "/user/change-username";
|
|
41
|
+
const RENAME_ENDPOINT = "/user/rename";
|
|
42
|
+
const DELETE_ENDPOINT = "/user/delete";
|
|
43
|
+
|
|
44
|
+
export class Writer {
|
|
45
|
+
private readonly client: UnaryClient;
|
|
46
|
+
|
|
47
|
+
constructor(client: UnaryClient) {
|
|
48
|
+
this.client = client;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async create(users: NewUser | NewUser[]): Promise<User[]> {
|
|
52
|
+
const res = await sendRequired<typeof createReqZ, typeof createResZ>(
|
|
53
|
+
this.client,
|
|
54
|
+
CREATE_ENDPOINT,
|
|
55
|
+
{ users: toArray(users) },
|
|
56
|
+
createReqZ,
|
|
57
|
+
createResZ,
|
|
58
|
+
);
|
|
59
|
+
return res.users;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
async changeUsername(key: Key, newUsername: string): Promise<void> {
|
|
63
|
+
await sendRequired<typeof changeUsernameReqZ, typeof changeUsernameResZ>(
|
|
64
|
+
this.client,
|
|
65
|
+
CHANGE_USERNAME_ENDPOINT,
|
|
66
|
+
{ key, username: newUsername },
|
|
67
|
+
changeUsernameReqZ,
|
|
68
|
+
changeUsernameResZ,
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async rename(key: Key, firstName?: string, lastName?: string): Promise<void> {
|
|
73
|
+
await sendRequired<typeof renameReqZ, typeof renameResZ>(
|
|
74
|
+
this.client,
|
|
75
|
+
RENAME_ENDPOINT,
|
|
76
|
+
{ key, firstName, lastName },
|
|
77
|
+
renameReqZ,
|
|
78
|
+
renameResZ,
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async delete(keys: Key | Key[]): Promise<void> {
|
|
83
|
+
await sendRequired<typeof deleteReqZ, typeof deleteResZ>(
|
|
84
|
+
this.client,
|
|
85
|
+
DELETE_ENDPOINT,
|
|
86
|
+
{ keys: toArray(keys) },
|
|
87
|
+
deleteReqZ,
|
|
88
|
+
deleteResZ,
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -24,7 +24,7 @@ export const linePlotZ = z.object({
|
|
|
24
24
|
|
|
25
25
|
export type LinePlot = z.infer<typeof linePlotZ>;
|
|
26
26
|
|
|
27
|
-
export const
|
|
27
|
+
export const ONTOLOGY_TYPE: ontology.ResourceType = "lineplot";
|
|
28
28
|
|
|
29
29
|
export const ontologyID = (key: Key): ontology.ID =>
|
|
30
|
-
new ontology.ID({ type:
|
|
30
|
+
new ontology.ID({ type: ONTOLOGY_TYPE, key: key });
|
package/src/workspace/payload.ts
CHANGED
|
@@ -38,7 +38,7 @@ export const workspaceRemoteZ = workspaceZ.omit({ layout: true }).extend({
|
|
|
38
38
|
|
|
39
39
|
export type Workspace = z.infer<typeof workspaceZ>;
|
|
40
40
|
|
|
41
|
-
export const
|
|
41
|
+
export const ONTOLOGY_TYPE: ontology.ResourceType = "workspace";
|
|
42
42
|
|
|
43
43
|
export const ontologyID = (key: Key): ontology.ID =>
|
|
44
|
-
new ontology.ID({ type:
|
|
44
|
+
new ontology.ID({ type: ONTOLOGY_TYPE, key: key });
|
|
@@ -12,7 +12,7 @@ import { type UnknownRecord } from "@synnaxlabs/x/record";
|
|
|
12
12
|
|
|
13
13
|
import { type Key, type Params, type Schematic } from "@/workspace/schematic/payload";
|
|
14
14
|
import { Retriever } from "@/workspace/schematic/retriever";
|
|
15
|
-
import { type NewSchematic,Writer } from "@/workspace/schematic/writer";
|
|
15
|
+
import { type NewSchematic, Writer } from "@/workspace/schematic/writer";
|
|
16
16
|
|
|
17
17
|
export class Client {
|
|
18
18
|
private readonly writer: Writer;
|
|
@@ -32,7 +32,7 @@ export const schematicRemoteZ = z.object({
|
|
|
32
32
|
|
|
33
33
|
export type Schematic = z.infer<typeof schematicZ>;
|
|
34
34
|
|
|
35
|
-
export const
|
|
35
|
+
export const ONTOLOGY_TYPE: ontology.ResourceType = "schematic";
|
|
36
36
|
|
|
37
37
|
export const ontologyID = (key: Key): ontology.ID =>
|
|
38
|
-
new ontology.ID({ type:
|
|
38
|
+
new ontology.ID({ type: ONTOLOGY_TYPE, key: key });
|
|
@@ -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 { describe, expect,test } from "vitest";
|
|
10
|
+
import { describe, expect, test } from "vitest";
|
|
11
11
|
|
|
12
12
|
import { newClient } from "@/setupspecs";
|
|
13
13
|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"access.spec.d.ts","sourceRoot":"","sources":["../../src/access/access.spec.ts"],"names":[],"mappings":""}
|