@synnaxlabs/client 0.38.1 → 0.40.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/payload.d.ts +6 -6
- package/dist/access/payload.d.ts.map +1 -1
- package/dist/access/policy/client.d.ts +5 -3
- package/dist/access/policy/client.d.ts.map +1 -1
- package/dist/access/policy/external.d.ts +1 -0
- package/dist/access/policy/external.d.ts.map +1 -1
- package/dist/access/policy/ontology.d.ts +5 -0
- package/dist/access/policy/ontology.d.ts.map +1 -0
- package/dist/access/policy/payload.d.ts +86 -89
- package/dist/access/policy/payload.d.ts.map +1 -1
- package/dist/access/policy/retriever.d.ts +7 -6
- package/dist/access/policy/retriever.d.ts.map +1 -1
- package/dist/access/policy/writer.d.ts +2 -2
- package/dist/access/policy/writer.d.ts.map +1 -1
- package/dist/auth/auth.d.ts +2 -1
- package/dist/auth/auth.d.ts.map +1 -1
- package/dist/channel/client.d.ts +6 -5
- package/dist/channel/client.d.ts.map +1 -1
- package/dist/channel/payload.d.ts +13 -11
- package/dist/channel/payload.d.ts.map +1 -1
- package/dist/channel/retriever.d.ts +9 -6
- package/dist/channel/retriever.d.ts.map +1 -1
- package/dist/channel/writer.d.ts +6 -4
- package/dist/channel/writer.d.ts.map +1 -1
- package/dist/client.cjs +30 -30
- package/dist/client.d.ts +4 -2
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +3387 -3433
- package/dist/connection/checker.d.ts +5 -4
- package/dist/connection/checker.d.ts.map +1 -1
- package/dist/control/state.d.ts +10 -8
- package/dist/control/state.d.ts.map +1 -1
- package/dist/errors.d.ts +5 -0
- package/dist/errors.d.ts.map +1 -1
- package/dist/framer/adapter.d.ts +14 -15
- package/dist/framer/adapter.d.ts.map +1 -1
- package/dist/framer/client.d.ts +13 -15
- package/dist/framer/client.d.ts.map +1 -1
- package/dist/framer/deleter.d.ts +3 -2
- package/dist/framer/deleter.d.ts.map +1 -1
- package/dist/framer/frame.d.ts +31 -27
- package/dist/framer/frame.d.ts.map +1 -1
- package/dist/framer/iterator.d.ts +4 -5
- package/dist/framer/iterator.d.ts.map +1 -1
- package/dist/framer/streamer.d.ts +5 -6
- package/dist/framer/streamer.d.ts.map +1 -1
- package/dist/framer/writer.d.ts +42 -39
- package/dist/framer/writer.d.ts.map +1 -1
- package/dist/hardware/device/client.d.ts +20 -12
- package/dist/hardware/device/client.d.ts.map +1 -1
- package/dist/hardware/device/payload.d.ts +19 -16
- package/dist/hardware/device/payload.d.ts.map +1 -1
- package/dist/hardware/rack/client.d.ts +15 -15
- package/dist/hardware/rack/client.d.ts.map +1 -1
- package/dist/hardware/rack/payload.d.ts +9 -8
- package/dist/hardware/rack/payload.d.ts.map +1 -1
- package/dist/hardware/task/client.d.ts +38 -29
- package/dist/hardware/task/client.d.ts.map +1 -1
- package/dist/hardware/task/payload.d.ts +58 -53
- package/dist/hardware/task/payload.d.ts.map +1 -1
- package/dist/label/client.d.ts +4 -3
- package/dist/label/client.d.ts.map +1 -1
- package/dist/label/payload.d.ts +4 -4
- package/dist/label/payload.d.ts.map +1 -1
- package/dist/label/retriever.d.ts.map +1 -1
- package/dist/label/writer.d.ts +13 -10
- package/dist/label/writer.d.ts.map +1 -1
- package/dist/ontology/client.d.ts +12 -10
- package/dist/ontology/client.d.ts.map +1 -1
- package/dist/ontology/group/client.d.ts +5 -4
- package/dist/ontology/group/client.d.ts.map +1 -1
- package/dist/ontology/group/group.d.ts +7 -5
- package/dist/ontology/group/group.d.ts.map +1 -1
- package/dist/ontology/group/payload.d.ts +6 -5
- package/dist/ontology/group/payload.d.ts.map +1 -1
- package/dist/ontology/group/writer.d.ts +8 -8
- package/dist/ontology/group/writer.d.ts.map +1 -1
- package/dist/ontology/payload.d.ts +72 -62
- package/dist/ontology/payload.d.ts.map +1 -1
- package/dist/ontology/writer.d.ts.map +1 -1
- package/dist/ranger/alias.d.ts +9 -10
- package/dist/ranger/alias.d.ts.map +1 -1
- package/dist/ranger/client.d.ts +18 -18
- package/dist/ranger/client.d.ts.map +1 -1
- package/dist/ranger/external.d.ts +1 -1
- package/dist/ranger/external.d.ts.map +1 -1
- package/dist/ranger/kv.d.ts +18 -14
- package/dist/ranger/kv.d.ts.map +1 -1
- package/dist/ranger/payload.d.ts +13 -13
- package/dist/ranger/payload.d.ts.map +1 -1
- package/dist/ranger/writer.d.ts +14 -14
- package/dist/ranger/writer.d.ts.map +1 -1
- package/dist/setupspecs.d.ts.map +1 -1
- package/dist/signals/observable.d.ts +3 -1
- package/dist/signals/observable.d.ts.map +1 -1
- package/dist/user/client.d.ts +5 -3
- package/dist/user/client.d.ts.map +1 -1
- package/dist/user/payload.d.ts +7 -6
- package/dist/user/payload.d.ts.map +1 -1
- package/dist/user/retriever.d.ts +2 -1
- package/dist/user/retriever.d.ts.map +1 -1
- package/dist/user/writer.d.ts +2 -2
- package/dist/user/writer.d.ts.map +1 -1
- package/dist/util/decodeJSONString.d.ts +3 -0
- package/dist/util/decodeJSONString.d.ts.map +1 -0
- package/dist/util/parseWithoutKeyConversion.d.ts +3 -0
- package/dist/util/parseWithoutKeyConversion.d.ts.map +1 -0
- package/dist/util/retrieve.d.ts +1 -1
- package/dist/util/retrieve.d.ts.map +1 -1
- package/dist/util/telem.d.ts.map +1 -1
- package/dist/util/zod.d.ts.map +1 -1
- package/dist/workspace/client.d.ts +6 -60
- package/dist/workspace/client.d.ts.map +1 -1
- package/dist/workspace/external.d.ts +3 -0
- package/dist/workspace/external.d.ts.map +1 -0
- package/dist/workspace/index.d.ts +1 -1
- package/dist/workspace/index.d.ts.map +1 -1
- package/dist/workspace/lineplot/client.d.ts +5 -44
- package/dist/workspace/lineplot/client.d.ts.map +1 -1
- package/dist/workspace/lineplot/external.d.ts +3 -0
- package/dist/workspace/lineplot/external.d.ts.map +1 -0
- package/dist/workspace/lineplot/index.d.ts +1 -1
- package/dist/workspace/lineplot/index.d.ts.map +1 -1
- package/dist/workspace/lineplot/payload.d.ts +45 -0
- package/dist/workspace/lineplot/payload.d.ts.map +1 -0
- package/dist/workspace/log/client.d.ts +5 -44
- package/dist/workspace/log/client.d.ts.map +1 -1
- package/dist/workspace/log/external.d.ts +3 -0
- package/dist/workspace/log/external.d.ts.map +1 -0
- package/dist/workspace/log/index.d.ts +1 -1
- package/dist/workspace/log/index.d.ts.map +1 -1
- package/dist/workspace/log/payload.d.ts +45 -0
- package/dist/workspace/log/payload.d.ts.map +1 -0
- package/dist/workspace/payload.d.ts +60 -0
- package/dist/workspace/payload.d.ts.map +1 -0
- package/dist/workspace/schematic/client.d.ts +5 -68
- package/dist/workspace/schematic/client.d.ts.map +1 -1
- package/dist/workspace/schematic/external.d.ts +3 -0
- package/dist/workspace/schematic/external.d.ts.map +1 -0
- package/dist/workspace/schematic/index.d.ts +1 -1
- package/dist/workspace/schematic/index.d.ts.map +1 -1
- package/dist/workspace/schematic/payload.d.ts +71 -0
- package/dist/workspace/schematic/payload.d.ts.map +1 -0
- package/dist/workspace/table/client.d.ts +5 -57
- package/dist/workspace/table/client.d.ts.map +1 -1
- 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 +1 -1
- package/dist/workspace/table/index.d.ts.map +1 -1
- package/dist/workspace/table/payload.d.ts +60 -0
- package/dist/workspace/table/payload.d.ts.map +1 -0
- package/examples/node/basicReadWrite.js +26 -26
- package/examples/node/liveStream.js +15 -15
- package/examples/node/seriesAndFrames.js +38 -38
- package/examples/node/streamWrite.js +47 -45
- package/package.json +15 -13
- package/src/access/payload.ts +12 -12
- package/src/access/policy/client.ts +13 -12
- package/src/access/policy/external.ts +1 -0
- package/src/access/policy/ontology.ts +17 -0
- package/src/access/policy/payload.ts +7 -19
- package/src/access/policy/policy.spec.ts +16 -16
- package/src/access/policy/retriever.ts +2 -1
- package/src/access/policy/writer.ts +4 -4
- package/src/auth/auth.spec.ts +27 -23
- package/src/auth/auth.ts +7 -11
- package/src/channel/batchRetriever.spec.ts +25 -22
- package/src/channel/client.ts +19 -21
- package/src/channel/payload.ts +16 -20
- package/src/channel/retriever.ts +20 -21
- package/src/channel/writer.ts +11 -13
- package/src/client.ts +6 -16
- package/src/connection/checker.ts +9 -11
- package/src/connection/connection.spec.ts +17 -5
- package/src/control/state.ts +8 -9
- package/src/errors.spec.ts +1 -1
- package/src/errors.ts +8 -0
- package/src/framer/adapter.spec.ts +28 -23
- package/src/framer/adapter.ts +37 -41
- package/src/framer/client.spec.ts +5 -11
- package/src/framer/client.ts +34 -38
- package/src/framer/deleter.ts +5 -6
- package/src/framer/frame.ts +62 -50
- package/src/framer/iterator.ts +11 -16
- package/src/framer/streamer.spec.ts +2 -10
- package/src/framer/streamer.ts +15 -19
- package/src/framer/writer.spec.ts +48 -7
- package/src/framer/writer.ts +39 -31
- package/src/hardware/device/client.ts +67 -39
- package/src/hardware/device/device.spec.ts +91 -33
- package/src/hardware/device/payload.ts +29 -28
- package/src/hardware/rack/client.ts +52 -65
- package/src/hardware/rack/payload.ts +9 -18
- package/src/hardware/rack/rack.spec.ts +12 -0
- package/src/hardware/task/client.ts +160 -131
- package/src/hardware/task/payload.ts +49 -68
- package/src/hardware/task/task.spec.ts +98 -81
- package/src/label/client.ts +12 -15
- package/src/label/payload.ts +3 -9
- package/src/label/retriever.ts +3 -7
- package/src/label/writer.ts +8 -15
- package/src/ontology/client.ts +17 -22
- package/src/ontology/group/client.ts +5 -5
- package/src/ontology/group/group.spec.ts +4 -4
- package/src/ontology/group/group.ts +10 -7
- package/src/ontology/group/payload.ts +11 -35
- package/src/ontology/group/writer.ts +22 -26
- package/src/ontology/ontology.spec.ts +15 -15
- package/src/ontology/payload.ts +67 -43
- package/src/ontology/writer.ts +16 -23
- package/src/ranger/alias.ts +25 -42
- package/src/ranger/client.ts +29 -38
- package/src/ranger/external.ts +1 -1
- package/src/ranger/kv.ts +9 -32
- package/src/ranger/payload.ts +14 -36
- package/src/ranger/ranger.spec.ts +1 -2
- package/src/ranger/writer.ts +8 -26
- package/src/signals/observable.ts +3 -4
- package/src/user/client.ts +8 -4
- package/src/user/payload.ts +5 -9
- package/src/user/retriever.ts +1 -1
- package/src/user/user.spec.ts +17 -15
- package/src/user/writer.ts +3 -10
- package/src/util/decodeJSONString.ts +13 -0
- package/src/util/parseWithoutKeyConversion.ts +19 -0
- package/src/util/retrieve.spec.ts +3 -13
- package/src/util/retrieve.ts +2 -12
- package/src/util/telem.ts +1 -1
- package/src/vite-env.d.ts +1 -0
- package/src/workspace/client.ts +30 -57
- package/src/workspace/external.ts +11 -0
- package/src/workspace/index.ts +1 -1
- package/src/workspace/lineplot/client.ts +22 -36
- package/src/workspace/lineplot/external.ts +11 -0
- package/src/workspace/lineplot/index.ts +1 -1
- package/src/workspace/lineplot/linePlot.spec.ts +1 -2
- package/src/workspace/lineplot/payload.ts +32 -0
- package/src/workspace/log/client.ts +25 -39
- package/src/workspace/log/external.ts +11 -0
- package/src/workspace/log/index.ts +1 -1
- package/src/workspace/log/log.spec.ts +5 -18
- package/src/workspace/log/payload.ts +32 -0
- package/src/workspace/payload.ts +36 -0
- package/src/workspace/schematic/client.ts +30 -56
- package/src/workspace/schematic/external.ts +11 -0
- package/src/workspace/schematic/index.ts +1 -1
- package/src/workspace/schematic/payload.ts +37 -0
- package/src/workspace/schematic/schematic.spec.ts +15 -6
- package/src/workspace/table/client.ts +27 -50
- package/src/workspace/table/external.ts +11 -0
- package/src/workspace/table/index.ts +1 -1
- package/src/workspace/table/payload.ts +36 -0
- package/src/workspace/workspace.spec.ts +1 -2
- package/dist/channel/creator.d.ts +0 -9
- package/dist/channel/creator.d.ts.map +0 -1
- package/src/channel/creator.ts +0 -37
|
@@ -15,101 +15,118 @@ import { newClient } from "@/setupspecs";
|
|
|
15
15
|
|
|
16
16
|
const client = newClient();
|
|
17
17
|
|
|
18
|
-
describe("
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
type: "ni",
|
|
27
|
-
});
|
|
28
|
-
expect(m.key).not.toHaveLength(0);
|
|
29
|
-
const rackKey = BigInt(m.key) >> 32n;
|
|
30
|
-
expect(Number(rackKey)).toBe(r.key);
|
|
18
|
+
describe("Task", async () => {
|
|
19
|
+
const testRack = await client.hardware.racks.create({ name: "test" });
|
|
20
|
+
describe("create", () => {
|
|
21
|
+
it("should create a task on a rack", async () => {
|
|
22
|
+
const m = await testRack.createTask({
|
|
23
|
+
name: "test",
|
|
24
|
+
config: { a: "dog" },
|
|
25
|
+
type: "ni",
|
|
31
26
|
});
|
|
27
|
+
expect(m.key).not.toHaveLength(0);
|
|
28
|
+
const rackKey = BigInt(m.key) >> 32n;
|
|
29
|
+
expect(Number(rackKey)).toBe(testRack.key);
|
|
32
30
|
});
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
31
|
+
it("should create a task with a config", async () => {
|
|
32
|
+
const config = {
|
|
33
|
+
stateRate: 100,
|
|
34
|
+
inputChannels: [
|
|
35
|
+
{ port: "AIN0", enabled: true },
|
|
36
|
+
{ port: "DAC2", enabled: false },
|
|
37
|
+
],
|
|
38
|
+
dataSaving: false,
|
|
39
|
+
};
|
|
40
|
+
const m = await testRack.createTask({
|
|
41
|
+
name: "test",
|
|
42
|
+
config,
|
|
43
|
+
type: "ni",
|
|
46
44
|
});
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const retrieved = await client.hardware.tasks.retrieveByName(name);
|
|
57
|
-
expect(retrieved.key).toBe(m.key);
|
|
58
|
-
});
|
|
45
|
+
expect(m.config).toStrictEqual(config);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
describe("update", () => {
|
|
49
|
+
it("should update a task if the key is provided", async () => {
|
|
50
|
+
const m = await testRack.createTask({
|
|
51
|
+
name: "test",
|
|
52
|
+
config: { a: "dog" },
|
|
53
|
+
type: "ni",
|
|
59
54
|
});
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const t = await r.createTask({
|
|
64
|
-
name: "test",
|
|
65
|
-
config: { a: "dog" },
|
|
66
|
-
type: "ni",
|
|
67
|
-
});
|
|
68
|
-
const w = await client.openWriter(["sy_task_state"]);
|
|
69
|
-
interface StateDetails {
|
|
70
|
-
dog: string;
|
|
71
|
-
}
|
|
72
|
-
const state: task.State<StateDetails> = {
|
|
73
|
-
key: id.id(),
|
|
74
|
-
task: t.key,
|
|
75
|
-
variant: "success",
|
|
76
|
-
};
|
|
77
|
-
expect(await w.write("sy_task_state", [state])).toBeTruthy();
|
|
78
|
-
await w.close();
|
|
79
|
-
const retrieved = await client.hardware.tasks.retrieve(t.key, {
|
|
80
|
-
includeState: true,
|
|
81
|
-
});
|
|
82
|
-
expect(retrieved.state).not.toBeNull();
|
|
83
|
-
expect(retrieved.state?.variant).toBe(state.variant);
|
|
84
|
-
});
|
|
55
|
+
const updated = await client.hardware.tasks.create({
|
|
56
|
+
...m,
|
|
57
|
+
name: "updated",
|
|
85
58
|
});
|
|
59
|
+
expect(updated.name).toBe("updated");
|
|
60
|
+
const retrieved = await client.hardware.tasks.retrieve(m.key);
|
|
61
|
+
expect(retrieved.name).toBe("updated");
|
|
86
62
|
});
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
63
|
+
});
|
|
64
|
+
describe("retrieve", () => {
|
|
65
|
+
it("should retrieve a task by its key", async () => {
|
|
66
|
+
const m = await testRack.createTask({
|
|
67
|
+
name: "test",
|
|
68
|
+
config: { a: "dog" },
|
|
69
|
+
type: "ni",
|
|
70
|
+
});
|
|
71
|
+
const retrieved = await client.hardware.tasks.retrieve(m.key);
|
|
72
|
+
expect(retrieved.key).toBe(m.key);
|
|
73
|
+
expect(retrieved.name).toBe("test");
|
|
74
|
+
expect(retrieved.config).toStrictEqual({ a: "dog" });
|
|
75
|
+
expect(retrieved.type).toBe("ni");
|
|
76
|
+
});
|
|
77
|
+
describe("retrieveByName", () => {
|
|
78
|
+
it("should retrieve a task by its name", async () => {
|
|
79
|
+
const name = `test-${Date.now()}-${Math.random()}`;
|
|
80
|
+
const m = await testRack.createTask({ name, config: { a: "dog" }, type: "ni" });
|
|
81
|
+
const retrieved = await client.hardware.tasks.retrieveByName(name);
|
|
82
|
+
expect(retrieved.key).toBe(m.key);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
describe("retrieve with state", () => {
|
|
86
|
+
it("should also send the tasks state", async () => {
|
|
87
|
+
const t = await testRack.createTask({
|
|
92
88
|
name: "test",
|
|
93
89
|
config: { a: "dog" },
|
|
94
90
|
type: "ni",
|
|
95
91
|
});
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
92
|
+
const w = await client.openWriter(["sy_task_state"]);
|
|
93
|
+
interface StateDetails {
|
|
94
|
+
dog: string;
|
|
95
|
+
}
|
|
96
|
+
const state: task.State<StateDetails> = {
|
|
97
|
+
key: id.create(),
|
|
98
|
+
task: t.key,
|
|
99
|
+
variant: "success",
|
|
100
|
+
};
|
|
101
|
+
expect(await w.write("sy_task_state", [state])).toBeTruthy();
|
|
102
|
+
await w.close();
|
|
103
|
+
const retrieved = await client.hardware.tasks.retrieve(t.key, {
|
|
104
|
+
includeState: true,
|
|
105
|
+
});
|
|
106
|
+
expect(retrieved.state).not.toBeNull();
|
|
107
|
+
expect(retrieved.state?.variant).toBe(state.variant);
|
|
99
108
|
});
|
|
100
109
|
});
|
|
110
|
+
});
|
|
101
111
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
type: "ni",
|
|
109
|
-
});
|
|
110
|
-
const tasks = await client.hardware.tasks.list();
|
|
111
|
-
expect(tasks.length).toBeGreaterThan(0);
|
|
112
|
+
describe("copy", () => {
|
|
113
|
+
it("should correctly copy the task", async () => {
|
|
114
|
+
const m = await testRack.createTask({
|
|
115
|
+
name: "test",
|
|
116
|
+
config: { a: "dog" },
|
|
117
|
+
type: "ni",
|
|
112
118
|
});
|
|
119
|
+
const copy = await client.hardware.tasks.copy(m.key, "New Name", false);
|
|
120
|
+
expect(copy.name).toBe("New Name");
|
|
121
|
+
expect(copy.config).toStrictEqual({ a: "dog" });
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
describe("list", () => {
|
|
126
|
+
it("should list all tasks", async () => {
|
|
127
|
+
await testRack.createTask({ name: "test", config: { a: "dog" }, type: "ni" });
|
|
128
|
+
const tasks = await client.hardware.tasks.list();
|
|
129
|
+
expect(tasks.length).toBeGreaterThan(0);
|
|
113
130
|
});
|
|
114
131
|
});
|
|
115
132
|
});
|
package/src/label/client.ts
CHANGED
|
@@ -12,14 +12,14 @@ import { observe } from "@synnaxlabs/x";
|
|
|
12
12
|
import { type AsyncTermSearcher } from "@synnaxlabs/x/search";
|
|
13
13
|
|
|
14
14
|
import { type framer } from "@/framer";
|
|
15
|
-
import { type Key, type Label, labelZ,
|
|
15
|
+
import { type Key, type Label, labelZ, ONTOLOGY_TYPE } from "@/label/payload";
|
|
16
16
|
import { Retriever } from "@/label/retriever";
|
|
17
|
-
import { type
|
|
17
|
+
import { type New, type SetOptions, Writer } from "@/label/writer";
|
|
18
18
|
import { ontology } from "@/ontology";
|
|
19
19
|
import { signals } from "@/signals";
|
|
20
20
|
|
|
21
|
-
const
|
|
22
|
-
const
|
|
21
|
+
const SET_CHANNEL_NAME = "sy_label_set";
|
|
22
|
+
const DELETE_CHANNEL_NAME = "sy_label_delete";
|
|
23
23
|
|
|
24
24
|
export class Client implements AsyncTermSearcher<string, Key, Label> {
|
|
25
25
|
readonly type: string = "label";
|
|
@@ -44,9 +44,7 @@ export class Client implements AsyncTermSearcher<string, Key, Label> {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
async retrieve(key: Key): Promise<Label>;
|
|
47
|
-
|
|
48
47
|
async retrieve(keys: Key[]): Promise<Label[]>;
|
|
49
|
-
|
|
50
48
|
async retrieve(keys: Key | Key[]): Promise<Label | Label[]> {
|
|
51
49
|
const isMany = Array.isArray(keys);
|
|
52
50
|
const res = await this.retriever.retrieve(keys);
|
|
@@ -73,20 +71,16 @@ export class Client implements AsyncTermSearcher<string, Key, Label> {
|
|
|
73
71
|
return await this.retriever.page(offset, limit);
|
|
74
72
|
}
|
|
75
73
|
|
|
76
|
-
async create(label:
|
|
77
|
-
|
|
78
|
-
async create(labels:
|
|
79
|
-
|
|
80
|
-
async create(labels: NewLabelPayload | NewLabelPayload[]): Promise<Label | Label[]> {
|
|
74
|
+
async create(label: New): Promise<Label>;
|
|
75
|
+
async create(labels: New[]): Promise<Label[]>;
|
|
76
|
+
async create(labels: New | New[]): Promise<Label | Label[]> {
|
|
81
77
|
const isMany = Array.isArray(labels);
|
|
82
78
|
const res = await this.writer.create(labels);
|
|
83
79
|
return isMany ? res : res[0];
|
|
84
80
|
}
|
|
85
81
|
|
|
86
82
|
async delete(key: Key): Promise<void>;
|
|
87
|
-
|
|
88
83
|
async delete(keys: Key[]): Promise<void>;
|
|
89
|
-
|
|
90
84
|
async delete(keys: Key | Key[]): Promise<void> {
|
|
91
85
|
await this.writer.delete(keys);
|
|
92
86
|
}
|
|
@@ -94,8 +88,8 @@ export class Client implements AsyncTermSearcher<string, Key, Label> {
|
|
|
94
88
|
async openChangeTracker(): Promise<signals.Observable<string, Label>> {
|
|
95
89
|
return await signals.openObservable<string, Label>(
|
|
96
90
|
this.frameClient,
|
|
97
|
-
|
|
98
|
-
|
|
91
|
+
SET_CHANNEL_NAME,
|
|
92
|
+
DELETE_CHANNEL_NAME,
|
|
99
93
|
decodeChanges,
|
|
100
94
|
);
|
|
101
95
|
}
|
|
@@ -132,3 +126,6 @@ const decodeChanges: signals.Decoder<string, Label> = (variant, data) => {
|
|
|
132
126
|
if (variant === "delete") return data.toUUIDs().map((v) => ({ variant, key: v }));
|
|
133
127
|
return data.parseJSON(labelZ).map((l) => ({ variant, key: l.key, value: l }));
|
|
134
128
|
};
|
|
129
|
+
|
|
130
|
+
export const ontologyID = (key: Key): ontology.ID =>
|
|
131
|
+
new ontology.ID({ type: ONTOLOGY_TYPE, key });
|
package/src/label/payload.ts
CHANGED
|
@@ -9,10 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
import { z } from "zod";
|
|
11
11
|
|
|
12
|
-
import { ontology } from "@/ontology";
|
|
13
|
-
|
|
14
12
|
export const keyZ = z.string().uuid();
|
|
15
|
-
|
|
16
13
|
export type Key = z.infer<typeof keyZ>;
|
|
17
14
|
|
|
18
15
|
export type Params = Key | Key[];
|
|
@@ -22,10 +19,7 @@ export const labelZ = z.object({
|
|
|
22
19
|
name: z.string().min(1),
|
|
23
20
|
color: z.string(),
|
|
24
21
|
});
|
|
22
|
+
export interface Label extends z.infer<typeof labelZ> {}
|
|
25
23
|
|
|
26
|
-
export
|
|
27
|
-
|
|
28
|
-
export const ONTOLOGY_TYPE: ontology.ResourceType = "label";
|
|
29
|
-
|
|
30
|
-
export const ontologyID = (key: Key): ontology.ID =>
|
|
31
|
-
new ontology.ID({ type: ONTOLOGY_TYPE, key });
|
|
24
|
+
export const ONTOLOGY_TYPE = "label";
|
|
25
|
+
export type OntologyType = typeof ONTOLOGY_TYPE;
|
package/src/label/retriever.ts
CHANGED
|
@@ -22,12 +22,9 @@ const reqZ = z.object({
|
|
|
22
22
|
offset: z.number().optional(),
|
|
23
23
|
limit: z.number().optional(),
|
|
24
24
|
});
|
|
25
|
+
interface Request extends z.infer<typeof reqZ> {}
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const resZ = z.object({
|
|
29
|
-
labels: nullableArrayZ(labelZ),
|
|
30
|
-
});
|
|
27
|
+
const resZ = z.object({ labels: nullableArrayZ(labelZ) });
|
|
31
28
|
|
|
32
29
|
export class Retriever {
|
|
33
30
|
private static readonly ENDPOINT = "/label/retrieve";
|
|
@@ -38,8 +35,7 @@ export class Retriever {
|
|
|
38
35
|
}
|
|
39
36
|
|
|
40
37
|
async retrieve(labels: Params): Promise<Label[]> {
|
|
41
|
-
|
|
42
|
-
return await this.execute({ keys: normalized });
|
|
38
|
+
return await this.execute({ keys: toArray(labels) });
|
|
43
39
|
}
|
|
44
40
|
|
|
45
41
|
async retrieveFor(id: ontology.ID): Promise<Label[]> {
|
package/src/label/writer.ts
CHANGED
|
@@ -14,21 +14,14 @@ import { z } from "zod";
|
|
|
14
14
|
import { type Key, keyZ, type Label, labelZ } from "@/label/payload";
|
|
15
15
|
import { ontology } from "@/ontology";
|
|
16
16
|
|
|
17
|
-
export const
|
|
17
|
+
export const newZ = labelZ.extend({ key: keyZ.optional() });
|
|
18
|
+
export interface New extends z.infer<typeof newZ> {}
|
|
18
19
|
|
|
19
|
-
|
|
20
|
+
const createReqZ = z.object({ labels: newZ.array() });
|
|
20
21
|
|
|
21
|
-
const
|
|
22
|
-
labels: newLabelPayloadZ.array(),
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
const createResZ = z.object({
|
|
26
|
-
labels: labelZ.array(),
|
|
27
|
-
});
|
|
22
|
+
const createResZ = z.object({ labels: labelZ.array() });
|
|
28
23
|
|
|
29
|
-
const deleteReqZ = z.object({
|
|
30
|
-
keys: keyZ.array(),
|
|
31
|
-
});
|
|
24
|
+
const deleteReqZ = z.object({ keys: keyZ.array() });
|
|
32
25
|
|
|
33
26
|
const setReqZ = z.object({
|
|
34
27
|
id: ontology.idZ,
|
|
@@ -36,8 +29,8 @@ const setReqZ = z.object({
|
|
|
36
29
|
replace: z.boolean().optional(),
|
|
37
30
|
});
|
|
38
31
|
|
|
39
|
-
|
|
40
|
-
export
|
|
32
|
+
interface SetReq extends z.infer<typeof setReqZ> {}
|
|
33
|
+
export interface SetOptions extends Pick<SetReq, "replace"> {}
|
|
41
34
|
|
|
42
35
|
const removeReqZ = setReqZ.omit({ replace: true });
|
|
43
36
|
|
|
@@ -55,7 +48,7 @@ export class Writer {
|
|
|
55
48
|
this.client = client;
|
|
56
49
|
}
|
|
57
50
|
|
|
58
|
-
async create(labels:
|
|
51
|
+
async create(labels: New | New[]): Promise<Label[]> {
|
|
59
52
|
const res = await sendRequired<typeof createReqZ, typeof createResZ>(
|
|
60
53
|
this.client,
|
|
61
54
|
CREATE_ENDPOINT,
|
package/src/ontology/client.ts
CHANGED
|
@@ -25,8 +25,8 @@ import {
|
|
|
25
25
|
type RelationshipDirection,
|
|
26
26
|
type Resource,
|
|
27
27
|
type ResourceChange,
|
|
28
|
-
resourceSchemaZ,
|
|
29
28
|
resourceTypeZ,
|
|
29
|
+
resourceZ,
|
|
30
30
|
} from "@/ontology/payload";
|
|
31
31
|
import { Writer } from "@/ontology/writer";
|
|
32
32
|
|
|
@@ -43,17 +43,12 @@ const retrieveReqZ = z.object({
|
|
|
43
43
|
offset: z.number().optional(),
|
|
44
44
|
types: resourceTypeZ.array().optional(),
|
|
45
45
|
});
|
|
46
|
+
interface RetrieveRequest extends z.infer<typeof retrieveReqZ> {}
|
|
46
47
|
|
|
47
|
-
|
|
48
|
+
export interface RetrieveOptions
|
|
49
|
+
extends Pick<RetrieveRequest, "includeSchema" | "excludeFieldData" | "types"> {}
|
|
48
50
|
|
|
49
|
-
|
|
50
|
-
RetrieveRequest,
|
|
51
|
-
"includeSchema" | "excludeFieldData" | "types"
|
|
52
|
-
>;
|
|
53
|
-
|
|
54
|
-
const retrieveResZ = z.object({
|
|
55
|
-
resources: resourceSchemaZ.array(),
|
|
56
|
-
});
|
|
51
|
+
const retrieveResZ = z.object({ resources: resourceZ.array() });
|
|
57
52
|
|
|
58
53
|
export const parseIDs = (ids: CrudeID | CrudeID[] | string | string[]): IDPayload[] =>
|
|
59
54
|
toArray(ids).map((id) => new ID(id).payload);
|
|
@@ -254,10 +249,10 @@ export class Client implements AsyncTermSearcher<string, string, Resource> {
|
|
|
254
249
|
}
|
|
255
250
|
}
|
|
256
251
|
|
|
257
|
-
const
|
|
258
|
-
const
|
|
259
|
-
const
|
|
260
|
-
const
|
|
252
|
+
const RESOURCE_SET_CHANNEL_NAME = "sy_ontology_resource_set";
|
|
253
|
+
const RESOURCE_DELETE_CHANNEL_NAME = "sy_ontology_resource_delete";
|
|
254
|
+
const RELATIONSHIP_SET_CHANNEL_NAME = "sy_ontology_relationship_set";
|
|
255
|
+
const RELATIONSHIP_DELETE_CHANNEL_NAME = "sy_ontology_relationship_delete";
|
|
261
256
|
|
|
262
257
|
/**
|
|
263
258
|
* A class that tracks changes to the ontology's resources and relationships.
|
|
@@ -310,7 +305,7 @@ export class ChangeTracker {
|
|
|
310
305
|
}
|
|
311
306
|
|
|
312
307
|
private parseRelationshipSets(frame: framer.Frame): RelationshipChange[] {
|
|
313
|
-
const relationships = frame.get(
|
|
308
|
+
const relationships = frame.get(RELATIONSHIP_SET_CHANNEL_NAME);
|
|
314
309
|
if (relationships.length === 0) return [];
|
|
315
310
|
return Array.from(relationships.as("string")).map((rel) => ({
|
|
316
311
|
variant: "set",
|
|
@@ -320,7 +315,7 @@ export class ChangeTracker {
|
|
|
320
315
|
}
|
|
321
316
|
|
|
322
317
|
private parseRelationshipDeletes(frame: framer.Frame): RelationshipChange[] {
|
|
323
|
-
const relationships = frame.get(
|
|
318
|
+
const relationships = frame.get(RELATIONSHIP_DELETE_CHANNEL_NAME);
|
|
324
319
|
if (relationships.length === 0) return [];
|
|
325
320
|
return Array.from(relationships.as("string")).map((rel) => ({
|
|
326
321
|
variant: "delete",
|
|
@@ -329,7 +324,7 @@ export class ChangeTracker {
|
|
|
329
324
|
}
|
|
330
325
|
|
|
331
326
|
private async parseResourceSets(frame: framer.Frame): Promise<ResourceChange[]> {
|
|
332
|
-
const sets = frame.get(
|
|
327
|
+
const sets = frame.get(RESOURCE_SET_CHANNEL_NAME);
|
|
333
328
|
if (sets.length === 0) return [];
|
|
334
329
|
// We should only ever get one series of sets
|
|
335
330
|
const ids = Array.from(sets.as("string")).map((id: string) => new ID(id));
|
|
@@ -347,7 +342,7 @@ export class ChangeTracker {
|
|
|
347
342
|
}
|
|
348
343
|
|
|
349
344
|
private parseResourceDeletes(frame: framer.Frame): ResourceChange[] {
|
|
350
|
-
const deletes = frame.get(
|
|
345
|
+
const deletes = frame.get(RESOURCE_DELETE_CHANNEL_NAME);
|
|
351
346
|
if (deletes.length === 0) return [];
|
|
352
347
|
// We should only ever get one series of deletes
|
|
353
348
|
return Array.from(deletes.as("string")).map((str) => ({
|
|
@@ -358,10 +353,10 @@ export class ChangeTracker {
|
|
|
358
353
|
|
|
359
354
|
static async open(client: framer.Client, retriever: Client): Promise<ChangeTracker> {
|
|
360
355
|
const streamer = await client.openStreamer([
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
356
|
+
RESOURCE_SET_CHANNEL_NAME,
|
|
357
|
+
RESOURCE_DELETE_CHANNEL_NAME,
|
|
358
|
+
RELATIONSHIP_SET_CHANNEL_NAME,
|
|
359
|
+
RELATIONSHIP_DELETE_CHANNEL_NAME,
|
|
365
360
|
]);
|
|
366
361
|
return new ChangeTracker(streamer, retriever);
|
|
367
362
|
}
|
|
@@ -9,10 +9,10 @@
|
|
|
9
9
|
|
|
10
10
|
import { type UnaryClient } from "@synnaxlabs/freighter";
|
|
11
11
|
|
|
12
|
+
import { type ontology } from "@/ontology";
|
|
12
13
|
import { Group } from "@/ontology/group/group";
|
|
13
|
-
import { type Payload } from "@/ontology/group/payload";
|
|
14
|
+
import { type Key, type Name, type Payload } from "@/ontology/group/payload";
|
|
14
15
|
import { Writer } from "@/ontology/group/writer";
|
|
15
|
-
import { type ID } from "@/ontology/payload";
|
|
16
16
|
|
|
17
17
|
export class Client {
|
|
18
18
|
private readonly creator: Writer;
|
|
@@ -21,15 +21,15 @@ export class Client {
|
|
|
21
21
|
this.creator = new Writer(unary);
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
async create(parent: ID, name:
|
|
24
|
+
async create(parent: ontology.ID, name: Name, key?: Key): Promise<Group> {
|
|
25
25
|
return this.sugar(await this.creator.create(parent, name, key));
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
async rename(key:
|
|
28
|
+
async rename(key: Key, name: Name): Promise<void> {
|
|
29
29
|
return await this.creator.rename(key, name);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
async delete(...keys:
|
|
32
|
+
async delete(...keys: Key[]): Promise<void> {
|
|
33
33
|
return await this.creator.delete(keys);
|
|
34
34
|
}
|
|
35
35
|
|
|
@@ -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,it } from "vitest";
|
|
10
|
+
import { describe, expect, it } from "vitest";
|
|
11
11
|
|
|
12
12
|
import { QueryError } from "@/errors";
|
|
13
13
|
import { ontology } from "@/ontology";
|
|
@@ -19,14 +19,14 @@ describe("Group", () => {
|
|
|
19
19
|
describe("create", () => {
|
|
20
20
|
it("should correctly create a group", async () => {
|
|
21
21
|
const name = `group-${Math.random()}`;
|
|
22
|
-
const g = await client.ontology.groups.create(ontology.
|
|
22
|
+
const g = await client.ontology.groups.create(ontology.ROOT_ID, name);
|
|
23
23
|
expect(g.name).toEqual(name);
|
|
24
24
|
});
|
|
25
25
|
});
|
|
26
26
|
describe("rename", () => {
|
|
27
27
|
it("should correctly rename a group", async () => {
|
|
28
28
|
const name = `group-${Math.random()}`;
|
|
29
|
-
const g = await client.ontology.groups.create(ontology.
|
|
29
|
+
const g = await client.ontology.groups.create(ontology.ROOT_ID, name);
|
|
30
30
|
const newName = `group-${Math.random()}`;
|
|
31
31
|
await client.ontology.groups.rename(g.key, newName);
|
|
32
32
|
const g2 = await client.ontology.retrieve(g.ontologyID);
|
|
@@ -36,7 +36,7 @@ describe("Group", () => {
|
|
|
36
36
|
describe("delete", () => {
|
|
37
37
|
it("should correctly delete the group", async () => {
|
|
38
38
|
const name = `group-${Math.random()}`;
|
|
39
|
-
const g = await client.ontology.groups.create(ontology.
|
|
39
|
+
const g = await client.ontology.groups.create(ontology.ROOT_ID, name);
|
|
40
40
|
await client.ontology.groups.delete(g.key);
|
|
41
41
|
await expect(
|
|
42
42
|
async () => await client.ontology.retrieve(g.ontologyID),
|
|
@@ -7,19 +7,22 @@
|
|
|
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 { type
|
|
11
|
-
import {
|
|
10
|
+
import { type Key, type Name, ONTOLOGY_TYPE } from "@/ontology/group/payload";
|
|
11
|
+
import { ID as OntologyID } from "@/ontology/payload";
|
|
12
12
|
|
|
13
13
|
export class Group {
|
|
14
|
-
key:
|
|
15
|
-
name:
|
|
14
|
+
key: Key;
|
|
15
|
+
name: Name;
|
|
16
16
|
|
|
17
|
-
constructor(name:
|
|
17
|
+
constructor(name: Name, key: Key) {
|
|
18
18
|
this.key = key;
|
|
19
19
|
this.name = name;
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
get ontologyID():
|
|
23
|
-
return
|
|
22
|
+
get ontologyID(): OntologyID {
|
|
23
|
+
return ontologyID(this.key);
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
|
+
|
|
27
|
+
export const ontologyID = (key: Key): OntologyID =>
|
|
28
|
+
new OntologyID({ type: ONTOLOGY_TYPE, key });
|
|
@@ -10,44 +10,22 @@
|
|
|
10
10
|
import { toArray } from "@synnaxlabs/x/toArray";
|
|
11
11
|
import { z } from "zod";
|
|
12
12
|
|
|
13
|
-
import { ontology } from "@/ontology";
|
|
14
|
-
|
|
15
13
|
export const keyZ = z.string().uuid();
|
|
16
14
|
export type Key = z.infer<typeof keyZ>;
|
|
17
|
-
export
|
|
15
|
+
export const nameZ = z.string();
|
|
16
|
+
export type Name = z.infer<typeof nameZ>;
|
|
18
17
|
export type Keys = Key[];
|
|
19
18
|
export type Names = Name[];
|
|
20
19
|
export type Params = Key | Name | Keys | Names;
|
|
21
20
|
|
|
22
|
-
export const groupZ = z.object({ key: keyZ, name:
|
|
23
|
-
|
|
24
|
-
export type Payload = z.infer<typeof groupZ>;
|
|
21
|
+
export const groupZ = z.object({ key: keyZ, name: nameZ });
|
|
22
|
+
export interface Payload extends z.infer<typeof groupZ> {}
|
|
25
23
|
|
|
26
24
|
export type ParamAnalysisResult =
|
|
27
|
-
| {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
actual: Key;
|
|
32
|
-
}
|
|
33
|
-
| {
|
|
34
|
-
single: true;
|
|
35
|
-
variant: "names";
|
|
36
|
-
normalized: Names;
|
|
37
|
-
actual: Name;
|
|
38
|
-
}
|
|
39
|
-
| {
|
|
40
|
-
single: false;
|
|
41
|
-
variant: "keys";
|
|
42
|
-
normalized: Keys;
|
|
43
|
-
actual: Keys;
|
|
44
|
-
}
|
|
45
|
-
| {
|
|
46
|
-
single: false;
|
|
47
|
-
variant: "names";
|
|
48
|
-
normalized: Names;
|
|
49
|
-
actual: Names;
|
|
50
|
-
};
|
|
25
|
+
| { single: true; variant: "keys"; normalized: Keys; actual: Key }
|
|
26
|
+
| { single: true; variant: "names"; normalized: Names; actual: Name }
|
|
27
|
+
| { single: false; variant: "keys"; normalized: Keys; actual: Keys }
|
|
28
|
+
| { single: false; variant: "names"; normalized: Names; actual: Names };
|
|
51
29
|
|
|
52
30
|
export const analyzeParams = (groups: Params): ParamAnalysisResult => {
|
|
53
31
|
const normal = toArray(groups) as Keys | Names;
|
|
@@ -58,10 +36,8 @@ export const analyzeParams = (groups: Params): ParamAnalysisResult => {
|
|
|
58
36
|
variant: isKey ? "keys" : "names",
|
|
59
37
|
normalized: normal,
|
|
60
38
|
actual: groups,
|
|
61
|
-
} as
|
|
39
|
+
} as ParamAnalysisResult;
|
|
62
40
|
};
|
|
63
41
|
|
|
64
|
-
export const ONTOLOGY_TYPE
|
|
65
|
-
|
|
66
|
-
export const ontologyID = (key: Key): ontology.ID =>
|
|
67
|
-
new ontology.ID({ type: ONTOLOGY_TYPE, key });
|
|
42
|
+
export const ONTOLOGY_TYPE = "group";
|
|
43
|
+
export type OntologyType = typeof ONTOLOGY_TYPE;
|