@synnaxlabs/client 0.33.0 → 0.35.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/access/policy/payload.d.ts +40 -40
- package/dist/access/policy/retriever.d.ts +5 -5
- package/dist/auth/auth.d.ts.map +1 -1
- package/dist/channel/writer.d.ts.map +1 -1
- package/dist/client.cjs +29 -29
- package/dist/client.js +1880 -1686
- package/dist/control/client.d.ts.map +1 -1
- package/dist/control/state.d.ts.map +1 -1
- package/dist/errors.d.ts +3 -3
- package/dist/errors.d.ts.map +1 -1
- package/dist/framer/adapter.d.ts.map +1 -1
- package/dist/framer/client.d.ts.map +1 -1
- package/dist/framer/deleter.d.ts.map +1 -1
- package/dist/framer/frame.d.ts.map +1 -1
- package/dist/framer/writer.d.ts.map +1 -1
- package/dist/hardware/device/client.d.ts +2 -2
- package/dist/hardware/device/client.d.ts.map +1 -1
- package/dist/hardware/device/payload.d.ts.map +1 -1
- package/dist/hardware/rack/client.d.ts.map +1 -1
- package/dist/hardware/task/client.d.ts +5 -3
- package/dist/hardware/task/client.d.ts.map +1 -1
- package/dist/hardware/task/ni/types.d.ts.map +1 -1
- package/dist/hardware/task/payload.d.ts +7 -3
- 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/label/client.d.ts.map +1 -1
- package/dist/label/writer.d.ts +5 -5
- package/dist/ontology/client.d.ts +8 -8
- package/dist/ontology/client.d.ts.map +1 -1
- package/dist/ontology/payload.d.ts +43 -43
- package/dist/ontology/payload.d.ts.map +1 -1
- package/dist/ranger/alias.d.ts.map +1 -1
- package/dist/ranger/client.d.ts.map +1 -1
- package/dist/ranger/kv.d.ts.map +1 -1
- package/dist/ranger/payload.d.ts.map +1 -1
- package/dist/ranger/writer.d.ts +5 -5
- package/dist/util/telem.d.ts.map +1 -1
- package/dist/workspace/client.d.ts +2 -0
- package/dist/workspace/client.d.ts.map +1 -1
- package/dist/workspace/lineplot/payload.d.ts.map +1 -1
- package/dist/workspace/log/payload.d.ts.map +1 -1
- package/dist/workspace/payload.d.ts.map +1 -1
- package/dist/workspace/schematic/payload.d.ts.map +1 -1
- package/dist/workspace/table/client.d.ts +16 -0
- package/dist/workspace/table/client.d.ts.map +1 -0
- package/dist/workspace/table/external.d.ts +3 -0
- package/dist/workspace/table/external.d.ts.map +1 -0
- package/dist/workspace/table/index.d.ts +2 -0
- package/dist/workspace/table/index.d.ts.map +1 -0
- package/dist/workspace/table/payload.d.ts +36 -0
- package/dist/workspace/table/payload.d.ts.map +1 -0
- package/dist/workspace/table/retriever.d.ts +8 -0
- package/dist/workspace/table/retriever.d.ts.map +1 -0
- package/dist/workspace/table/table.spec.d.ts +2 -0
- package/dist/workspace/table/table.spec.d.ts.map +1 -0
- package/dist/workspace/table/writer.d.ts +35 -0
- package/dist/workspace/table/writer.d.ts.map +1 -0
- package/eslint.config.js +1 -1
- package/package.json +12 -12
- package/src/access/policy/policy.spec.ts +2 -4
- package/src/auth/auth.spec.ts +1 -1
- package/src/auth/auth.ts +17 -18
- package/src/channel/writer.ts +2 -2
- package/src/connection/checker.ts +1 -1
- package/src/control/client.ts +1 -1
- package/src/control/state.ts +1 -1
- package/src/errors.spec.ts +1 -1
- package/src/errors.ts +14 -15
- package/src/framer/adapter.ts +5 -6
- package/src/framer/client.ts +9 -4
- package/src/framer/deleter.ts +1 -1
- package/src/framer/frame.ts +9 -11
- package/src/framer/iterator.spec.ts +2 -3
- package/src/framer/writer.ts +1 -1
- package/src/hardware/device/client.ts +13 -7
- package/src/hardware/device/payload.ts +1 -1
- package/src/hardware/rack/client.ts +3 -3
- package/src/hardware/task/client.ts +64 -14
- package/src/hardware/task/ni/types.ts +1 -1
- package/src/hardware/task/payload.ts +22 -7
- package/src/hardware/task/task.spec.ts +1 -1
- package/src/index.ts +1 -0
- package/src/label/client.ts +1 -1
- package/src/ontology/client.ts +1 -3
- package/src/ontology/group/payload.ts +2 -2
- package/src/ontology/payload.ts +2 -1
- package/src/ranger/alias.ts +2 -3
- package/src/ranger/client.ts +7 -9
- package/src/ranger/kv.ts +2 -2
- package/src/ranger/payload.ts +2 -2
- package/src/ranger/ranger.spec.ts +2 -2
- package/src/user/user.spec.ts +1 -2
- package/src/util/telem.ts +1 -3
- package/src/workspace/client.ts +3 -0
- package/src/workspace/lineplot/payload.ts +1 -1
- package/src/workspace/log/payload.ts +1 -1
- package/src/workspace/payload.ts +1 -1
- package/src/workspace/schematic/payload.ts +1 -1
- package/src/workspace/table/client.ts +51 -0
- package/src/workspace/table/external.ts +11 -0
- package/src/workspace/table/index.ts +10 -0
- package/src/workspace/table/payload.ts +36 -0
- package/src/workspace/table/retriever.ts +33 -0
- package/src/workspace/table/table.spec.ts +65 -0
- package/src/workspace/table/writer.ts +102 -0
|
@@ -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
|
+
});
|
|
@@ -0,0 +1,102 @@
|
|
|
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 { keyZ as workspaceKeyZ } from "@/workspace/payload";
|
|
16
|
+
import {
|
|
17
|
+
type Key,
|
|
18
|
+
keyZ,
|
|
19
|
+
type Params,
|
|
20
|
+
type Table,
|
|
21
|
+
tableRemoteZ,
|
|
22
|
+
tableZ,
|
|
23
|
+
} from "@/workspace/table/payload";
|
|
24
|
+
|
|
25
|
+
export const newTableZ = tableZ
|
|
26
|
+
.partial({ key: true })
|
|
27
|
+
.transform((p) => ({ ...p, data: JSON.stringify(p.data) }));
|
|
28
|
+
|
|
29
|
+
export type NewTable = z.input<typeof newTableZ>;
|
|
30
|
+
|
|
31
|
+
const createReqZ = z.object({ workspace: workspaceKeyZ, tables: newTableZ.array() });
|
|
32
|
+
|
|
33
|
+
const createResZ = z.object({ tables: tableRemoteZ.array() });
|
|
34
|
+
|
|
35
|
+
const deleteReqZ = z.object({ keys: keyZ.array() });
|
|
36
|
+
|
|
37
|
+
const deleteResZ = z.object({});
|
|
38
|
+
|
|
39
|
+
const renameReqZ = z.object({ key: keyZ, name: z.string() });
|
|
40
|
+
|
|
41
|
+
const renameResZ = z.object({});
|
|
42
|
+
|
|
43
|
+
const setDataReqZ = z.object({ key: keyZ, data: z.string() });
|
|
44
|
+
|
|
45
|
+
const setDataResZ = z.object({});
|
|
46
|
+
|
|
47
|
+
const CREATE_ENDPOINT = "/workspace/table/create";
|
|
48
|
+
const DELETE_ENDPOINT = "/workspace/table/delete";
|
|
49
|
+
const RENAME_ENDPOINT = "/workspace/table/rename";
|
|
50
|
+
const SET_DATA_ENDPOINT = "/workspace/table/set-data";
|
|
51
|
+
|
|
52
|
+
export class Writer {
|
|
53
|
+
private readonly client: UnaryClient;
|
|
54
|
+
|
|
55
|
+
constructor(client: UnaryClient) {
|
|
56
|
+
this.client = client;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
async create(workspace: string, table: NewTable): Promise<Table> {
|
|
60
|
+
const table_ = { ...table, data: JSON.stringify(table.data) };
|
|
61
|
+
const res = await sendRequired<typeof createReqZ, typeof createResZ>(
|
|
62
|
+
this.client,
|
|
63
|
+
CREATE_ENDPOINT,
|
|
64
|
+
{ workspace, tables: [table_] },
|
|
65
|
+
createReqZ,
|
|
66
|
+
createResZ,
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
return res.tables[0];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async delete(tables: Params): Promise<void> {
|
|
73
|
+
const normalized = toArray(tables);
|
|
74
|
+
await sendRequired<typeof deleteReqZ, typeof deleteResZ>(
|
|
75
|
+
this.client,
|
|
76
|
+
DELETE_ENDPOINT,
|
|
77
|
+
{ keys: normalized },
|
|
78
|
+
deleteReqZ,
|
|
79
|
+
deleteResZ,
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
async rename(table: Key, name: string): Promise<void> {
|
|
84
|
+
await sendRequired<typeof renameReqZ, typeof renameResZ>(
|
|
85
|
+
this.client,
|
|
86
|
+
RENAME_ENDPOINT,
|
|
87
|
+
{ key: table, name },
|
|
88
|
+
renameReqZ,
|
|
89
|
+
renameResZ,
|
|
90
|
+
);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async setData(table: Key, data: UnknownRecord): Promise<void> {
|
|
94
|
+
await sendRequired<typeof setDataReqZ, typeof setDataResZ>(
|
|
95
|
+
this.client,
|
|
96
|
+
SET_DATA_ENDPOINT,
|
|
97
|
+
{ key: table, data: JSON.stringify(data) },
|
|
98
|
+
setDataReqZ,
|
|
99
|
+
setDataResZ,
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
}
|