@synnaxlabs/client 0.54.2 → 0.56.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 +10 -13
- package/dist/client.cjs +60 -42
- package/dist/client.js +8037 -6265
- package/dist/src/access/policy/client.d.ts +70 -80
- package/dist/src/access/policy/client.d.ts.map +1 -1
- package/dist/src/access/policy/types.gen.d.ts +18 -20
- package/dist/src/access/policy/types.gen.d.ts.map +1 -1
- package/dist/src/access/role/client.d.ts.map +1 -1
- package/dist/src/access/role/types.gen.d.ts +2 -2
- package/dist/src/actions/actions.d.ts +68 -0
- package/dist/src/actions/actions.d.ts.map +1 -0
- package/dist/src/actions/actions.spec.d.ts +2 -0
- package/dist/src/actions/actions.spec.d.ts.map +1 -0
- package/dist/src/actions/external.d.ts +2 -0
- package/dist/src/actions/external.d.ts.map +1 -0
- package/dist/src/actions/index.d.ts +2 -0
- package/dist/src/actions/index.d.ts.map +1 -0
- package/dist/src/arc/arc.spec.d.ts +2 -0
- package/dist/src/arc/arc.spec.d.ts.map +1 -0
- package/dist/src/arc/client.d.ts.map +1 -1
- package/dist/src/arc/compiler/types.gen.d.ts +1 -1
- package/dist/src/arc/compiler/types.gen.d.ts.map +1 -1
- package/dist/src/arc/graph/types.gen.d.ts +40 -40
- package/dist/src/arc/graph/types.gen.d.ts.map +1 -1
- package/dist/src/arc/ir/types.gen.d.ts +202 -233
- package/dist/src/arc/ir/types.gen.d.ts.map +1 -1
- package/dist/src/arc/module/types.gen.d.ts +63 -82
- package/dist/src/arc/module/types.gen.d.ts.map +1 -1
- package/dist/src/arc/program/types.gen.d.ts +63 -82
- package/dist/src/arc/program/types.gen.d.ts.map +1 -1
- package/dist/src/arc/types/types.gen.d.ts +11 -11
- package/dist/src/arc/types/types.gen.d.ts.map +1 -1
- package/dist/src/arc/types.gen.d.ts +139 -158
- package/dist/src/arc/types.gen.d.ts.map +1 -1
- package/dist/src/auth/auth.d.ts +3 -3
- package/dist/src/auth/auth.d.ts.map +1 -1
- package/dist/src/channel/client.d.ts +2 -2
- package/dist/src/channel/client.d.ts.map +1 -1
- package/dist/src/channel/retriever.d.ts +5 -8
- package/dist/src/channel/retriever.d.ts.map +1 -1
- package/dist/src/channel/types.gen.d.ts +3 -3
- package/dist/src/channel/types.gen.d.ts.map +1 -1
- package/dist/src/channel/writer.d.ts.map +1 -1
- package/dist/src/client.d.ts +5 -0
- package/dist/src/client.d.ts.map +1 -1
- package/dist/src/connection/checker.d.ts +17 -2
- package/dist/src/connection/checker.d.ts.map +1 -1
- package/dist/src/control/state.d.ts.map +1 -1
- package/dist/src/device/client.d.ts.map +1 -1
- package/dist/src/device/types.gen.d.ts +6 -8
- package/dist/src/device/types.gen.d.ts.map +1 -1
- package/dist/src/errors.d.ts +2 -0
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/framer/adapter.d.ts.map +1 -1
- package/dist/src/framer/client.d.ts +2 -2
- package/dist/src/framer/client.d.ts.map +1 -1
- package/dist/src/framer/codec.d.ts +9 -1
- package/dist/src/framer/codec.d.ts.map +1 -1
- package/dist/src/framer/deleter.d.ts.map +1 -1
- package/dist/src/framer/frame.d.ts +1 -1
- package/dist/src/framer/iterator.d.ts +84 -3
- package/dist/src/framer/iterator.d.ts.map +1 -1
- package/dist/src/framer/streamProxy.d.ts.map +1 -1
- package/dist/src/framer/streamer.d.ts +1 -3
- package/dist/src/framer/streamer.d.ts.map +1 -1
- package/dist/src/framer/types.gen.d.ts +18 -0
- package/dist/src/framer/types.gen.d.ts.map +1 -1
- package/dist/src/framer/writer.d.ts +8 -8
- package/dist/src/framer/writer.d.ts.map +1 -1
- package/dist/src/group/client.d.ts +1 -2
- package/dist/src/group/client.d.ts.map +1 -1
- package/dist/src/group/types.gen.d.ts +2 -2
- package/dist/src/index.d.ts +2 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/label/client.d.ts +5 -8
- package/dist/src/label/client.d.ts.map +1 -1
- package/dist/src/lineplot/client.d.ts.map +1 -1
- package/dist/src/lineplot/types.gen.d.ts +2 -2
- package/dist/src/log/client.d.ts.map +1 -1
- package/dist/src/log/types.gen.d.ts +2 -2
- package/dist/src/ontology/client.d.ts +1 -3
- package/dist/src/ontology/client.d.ts.map +1 -1
- package/dist/src/ontology/payload.d.ts +12 -16
- package/dist/src/ontology/payload.d.ts.map +1 -1
- package/dist/src/ontology/types.gen.d.ts +1 -2
- package/dist/src/ontology/types.gen.d.ts.map +1 -1
- package/dist/src/ontology/writer.d.ts +5 -10
- package/dist/src/ontology/writer.d.ts.map +1 -1
- package/dist/src/rack/client.d.ts.map +1 -1
- package/dist/src/rack/types.gen.d.ts +3 -3
- package/dist/src/ranger/alias/client.d.ts.map +1 -1
- package/dist/src/ranger/client.d.ts.map +1 -1
- package/dist/src/ranger/kv/client.d.ts.map +1 -1
- package/dist/src/ranger/types.gen.d.ts +6 -6
- package/dist/src/ranger/types.gen.d.ts.map +1 -1
- package/dist/src/ranger/writer.d.ts +2 -3
- package/dist/src/ranger/writer.d.ts.map +1 -1
- package/dist/src/schematic/actions.d.ts +147 -0
- package/dist/src/schematic/actions.d.ts.map +1 -0
- package/dist/src/schematic/actions.gen.d.ts +484 -0
- package/dist/src/schematic/actions.gen.d.ts.map +1 -0
- package/dist/src/schematic/actions.spec.d.ts +2 -0
- package/dist/src/schematic/actions.spec.d.ts.map +1 -0
- package/dist/src/schematic/client.d.ts +53 -2
- package/dist/src/schematic/client.d.ts.map +1 -1
- package/dist/src/schematic/external.d.ts +2 -0
- package/dist/src/schematic/external.d.ts.map +1 -1
- package/dist/src/schematic/symbol/client.d.ts.map +1 -1
- package/dist/src/schematic/symbol/types.gen.d.ts +48 -58
- package/dist/src/schematic/symbol/types.gen.d.ts.map +1 -1
- package/dist/src/schematic/types.gen.d.ts +131 -5
- package/dist/src/schematic/types.gen.d.ts.map +1 -1
- package/dist/src/status/client.d.ts.map +1 -1
- package/dist/src/status/payload.d.ts +3 -3
- package/dist/src/table/actions.d.ts +156 -0
- package/dist/src/table/actions.d.ts.map +1 -0
- package/dist/src/table/actions.gen.d.ts +587 -0
- package/dist/src/table/actions.gen.d.ts.map +1 -0
- package/dist/src/table/client.d.ts +28 -2
- package/dist/src/table/client.d.ts.map +1 -1
- package/dist/src/table/external.d.ts +2 -0
- package/dist/src/table/external.d.ts.map +1 -1
- package/dist/src/table/types.gen.d.ts +71 -4
- package/dist/src/table/types.gen.d.ts.map +1 -1
- package/dist/src/task/client.d.ts.map +1 -1
- package/dist/src/task/types.gen.d.ts +7 -7
- package/dist/src/task/types.gen.d.ts.map +1 -1
- package/dist/src/user/client.d.ts +2 -2
- package/dist/src/user/client.d.ts.map +1 -1
- package/dist/src/user/types.gen.d.ts +2 -2
- package/dist/src/view/client.d.ts.map +1 -1
- package/dist/src/view/types.gen.d.ts +2 -2
- package/dist/src/workspace/client.d.ts.map +1 -1
- package/dist/src/workspace/types.gen.d.ts +3 -3
- package/dist/src/workspace/types.gen.d.ts.map +1 -1
- package/package.json +12 -11
- package/src/access/policy/client.ts +4 -7
- package/src/access/role/client.ts +6 -26
- package/src/actions/actions.spec.ts +229 -0
- package/src/actions/actions.ts +104 -0
- package/src/actions/external.ts +10 -0
- package/src/actions/index.ts +10 -0
- package/src/arc/arc.spec.ts +44 -0
- package/src/arc/client.ts +3 -7
- package/src/arc/compiler/types.gen.ts +2 -1
- package/src/arc/ir/types.gen.ts +102 -48
- package/src/arc/lsp.spec.ts +3 -7
- package/src/arc/types/types.gen.ts +3 -3
- package/src/auth/auth.spec.ts +12 -13
- package/src/auth/auth.ts +48 -34
- package/src/channel/batchRetriever.spec.ts +13 -4
- package/src/channel/channel.spec.ts +13 -0
- package/src/channel/client.ts +8 -6
- package/src/channel/retriever.ts +7 -16
- package/src/channel/types.gen.ts +1 -2
- package/src/channel/writer.ts +4 -20
- package/src/client.ts +3 -0
- package/src/connection/checker.ts +48 -10
- package/src/connection/connection.spec.ts +64 -2
- package/src/control/state.ts +5 -4
- package/src/device/client.ts +5 -8
- package/src/device/device.spec.ts +7 -5
- package/src/device/types.gen.ts +4 -4
- package/src/errors.ts +8 -9
- package/src/framer/adapter.ts +2 -4
- package/src/framer/client.ts +12 -0
- package/src/framer/codec.spec.ts +53 -3
- package/src/framer/codec.ts +58 -25
- package/src/framer/deleter.ts +2 -8
- package/src/framer/iterator.ts +42 -39
- package/src/framer/streamProxy.ts +11 -12
- package/src/framer/streamer.spec.ts +1 -1
- package/src/framer/streamer.ts +2 -7
- package/src/framer/types.gen.ts +20 -0
- package/src/framer/writer.spec.ts +221 -1
- package/src/framer/writer.ts +53 -28
- package/src/group/client.ts +4 -7
- package/src/index.ts +3 -2
- package/src/label/client.ts +6 -16
- package/src/label/label.spec.ts +12 -0
- package/src/lineplot/client.ts +6 -21
- package/src/log/client.ts +6 -21
- package/src/ontology/client.ts +2 -3
- package/src/ontology/ontology.spec.ts +10 -0
- package/src/ontology/types.gen.ts +0 -1
- package/src/ontology/writer.ts +4 -7
- package/src/rack/client.ts +4 -7
- package/src/rack/rack.spec.ts +12 -1
- package/src/ranger/alias/client.ts +6 -11
- package/src/ranger/client.ts +2 -3
- package/src/ranger/kv/client.ts +4 -7
- package/src/ranger/ranger.spec.ts +12 -0
- package/src/ranger/writer.ts +4 -17
- package/src/schematic/access.spec.ts +6 -6
- package/src/schematic/actions.gen.ts +200 -0
- package/src/schematic/actions.spec.ts +699 -0
- package/src/schematic/actions.ts +168 -0
- package/src/schematic/client.ts +34 -30
- package/src/schematic/external.ts +2 -0
- package/src/schematic/schematic.spec.ts +233 -69
- package/src/schematic/symbol/client.spec.ts +33 -9
- package/src/schematic/symbol/client.ts +6 -11
- package/src/schematic/symbol/types.gen.ts +1 -10
- package/src/schematic/types.gen.ts +55 -6
- package/src/status/client.ts +4 -10
- package/src/status/status.spec.ts +7 -6
- package/src/table/access.spec.ts +0 -6
- package/src/table/actions.gen.ts +243 -0
- package/src/table/actions.ts +255 -0
- package/src/table/client.ts +21 -25
- package/src/table/external.ts +2 -0
- package/src/table/table.spec.ts +588 -43
- package/src/table/types.gen.ts +58 -5
- package/src/task/client.ts +14 -20
- package/src/task/task.spec.ts +15 -1
- package/src/task/types.gen.ts +8 -6
- package/src/user/client.ts +6 -11
- package/src/view/client.ts +4 -7
- package/src/view/view.spec.ts +9 -5
- package/src/workspace/client.ts +6 -16
- package/src/workspace/types.gen.ts +2 -1
- package/src/workspace/workspace.spec.ts +14 -1
package/src/ranger/kv/client.ts
CHANGED
|
@@ -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 {
|
|
10
|
+
import { type UnaryClient } from "@synnaxlabs/freighter";
|
|
11
11
|
import { array } from "@synnaxlabs/x";
|
|
12
12
|
import { z } from "zod";
|
|
13
13
|
|
|
@@ -31,8 +31,7 @@ export class Client {
|
|
|
31
31
|
async get(key: string): Promise<string>;
|
|
32
32
|
async get(keys: string[]): Promise<Record<string, string>>;
|
|
33
33
|
async get(keys: string | string[]): Promise<string | Record<string, string>> {
|
|
34
|
-
const res = await
|
|
35
|
-
this.client,
|
|
34
|
+
const res = await this.client.send(
|
|
36
35
|
"/range/kv/get",
|
|
37
36
|
{ range: this.rangeKey, keys: array.toArray(keys) },
|
|
38
37
|
getReqZ,
|
|
@@ -58,8 +57,7 @@ export class Client {
|
|
|
58
57
|
value: v,
|
|
59
58
|
}));
|
|
60
59
|
|
|
61
|
-
await
|
|
62
|
-
this.client,
|
|
60
|
+
await this.client.send(
|
|
63
61
|
"/range/kv/set",
|
|
64
62
|
{ range: this.rangeKey, pairs },
|
|
65
63
|
setReqZ,
|
|
@@ -68,8 +66,7 @@ export class Client {
|
|
|
68
66
|
}
|
|
69
67
|
|
|
70
68
|
async delete(key: string | string[]): Promise<void> {
|
|
71
|
-
await
|
|
72
|
-
this.client,
|
|
69
|
+
await this.client.send(
|
|
73
70
|
"/range/kv/delete",
|
|
74
71
|
{ range: this.rangeKey, keys: array.toArray(key) },
|
|
75
72
|
deleteReqZ,
|
|
@@ -185,6 +185,18 @@ describe("range", () => {
|
|
|
185
185
|
expect(retrieved.length).toBeGreaterThan(0);
|
|
186
186
|
expect(retrieved.map((r) => r.key)).toContain(range.key);
|
|
187
187
|
});
|
|
188
|
+
it("should retrieve ranges by search term", async () => {
|
|
189
|
+
const prefix = `searchable-range-${id.create()}`;
|
|
190
|
+
const timeRange = TimeStamp.now().spanRange(TimeSpan.seconds(1));
|
|
191
|
+
const names = [`${prefix}-1`, `${prefix}-2`];
|
|
192
|
+
await client.ranges.create(names.map((name) => ({ name, timeRange })));
|
|
193
|
+
await expect
|
|
194
|
+
.poll(async () => {
|
|
195
|
+
const results = await client.ranges.retrieve({ searchTerm: prefix });
|
|
196
|
+
return results.map((r) => r.name).sort();
|
|
197
|
+
})
|
|
198
|
+
.toEqual(names);
|
|
199
|
+
});
|
|
188
200
|
});
|
|
189
201
|
|
|
190
202
|
describe("retrieveParent", () => {
|
package/src/ranger/writer.ts
CHANGED
|
@@ -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 {
|
|
10
|
+
import { type UnaryClient } from "@synnaxlabs/freighter";
|
|
11
11
|
import { z } from "zod";
|
|
12
12
|
|
|
13
13
|
import { ontology } from "@/ontology";
|
|
@@ -35,18 +35,11 @@ export class Writer {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
async rename(key: string, name: string): Promise<void> {
|
|
38
|
-
await
|
|
39
|
-
this.client,
|
|
40
|
-
"/range/rename",
|
|
41
|
-
{ key, name },
|
|
42
|
-
renameReqZ,
|
|
43
|
-
renameResZ,
|
|
44
|
-
);
|
|
38
|
+
await this.client.send("/range/rename", { key, name }, renameReqZ, renameResZ);
|
|
45
39
|
}
|
|
46
40
|
|
|
47
41
|
async create(ranges: New[], options?: CreateOptions): Promise<Payload[]> {
|
|
48
|
-
const res = await
|
|
49
|
-
this.client,
|
|
42
|
+
const res = await this.client.send(
|
|
50
43
|
"/range/create",
|
|
51
44
|
{ ranges, ...options },
|
|
52
45
|
createReqZ,
|
|
@@ -56,12 +49,6 @@ export class Writer {
|
|
|
56
49
|
}
|
|
57
50
|
|
|
58
51
|
async delete(keys: string[]): Promise<void> {
|
|
59
|
-
await
|
|
60
|
-
this.client,
|
|
61
|
-
"/range/delete",
|
|
62
|
-
{ keys },
|
|
63
|
-
deleteReqZ,
|
|
64
|
-
deleteResZ,
|
|
65
|
-
);
|
|
52
|
+
await this.client.send("/range/delete", { keys }, deleteReqZ, deleteResZ);
|
|
66
53
|
}
|
|
67
54
|
}
|
|
@@ -29,8 +29,8 @@ describe("schematic", () => {
|
|
|
29
29
|
layout: {},
|
|
30
30
|
});
|
|
31
31
|
const randomSchematic = await client.schematics.create(ws.key, {
|
|
32
|
+
...schematic.ZERO_NEW,
|
|
32
33
|
name: "test",
|
|
33
|
-
data: {},
|
|
34
34
|
});
|
|
35
35
|
await expect(
|
|
36
36
|
userClient.schematics.retrieve({ key: randomSchematic.key }),
|
|
@@ -48,8 +48,8 @@ describe("schematic", () => {
|
|
|
48
48
|
layout: {},
|
|
49
49
|
});
|
|
50
50
|
const randomSchematic = await client.schematics.create(ws.key, {
|
|
51
|
+
...schematic.ZERO_NEW,
|
|
51
52
|
name: "test",
|
|
52
|
-
data: {},
|
|
53
53
|
});
|
|
54
54
|
const retrieved = await userClient.schematics.retrieve({
|
|
55
55
|
key: randomSchematic.key,
|
|
@@ -69,8 +69,8 @@ describe("schematic", () => {
|
|
|
69
69
|
layout: {},
|
|
70
70
|
});
|
|
71
71
|
await userClient.schematics.create(ws.key, {
|
|
72
|
+
...schematic.ZERO_NEW,
|
|
72
73
|
name: "test",
|
|
73
|
-
data: {},
|
|
74
74
|
});
|
|
75
75
|
});
|
|
76
76
|
|
|
@@ -86,8 +86,8 @@ describe("schematic", () => {
|
|
|
86
86
|
});
|
|
87
87
|
await expect(
|
|
88
88
|
userClient.schematics.create(ws.key, {
|
|
89
|
+
...schematic.ZERO_NEW,
|
|
89
90
|
name: "test",
|
|
90
|
-
data: {},
|
|
91
91
|
}),
|
|
92
92
|
).rejects.toThrow(AuthError);
|
|
93
93
|
});
|
|
@@ -103,8 +103,8 @@ describe("schematic", () => {
|
|
|
103
103
|
layout: {},
|
|
104
104
|
});
|
|
105
105
|
const randomSchematic = await client.schematics.create(ws.key, {
|
|
106
|
+
...schematic.ZERO_NEW,
|
|
106
107
|
name: "test",
|
|
107
|
-
data: {},
|
|
108
108
|
});
|
|
109
109
|
await userClient.schematics.delete(randomSchematic.key);
|
|
110
110
|
await expect(
|
|
@@ -123,8 +123,8 @@ describe("schematic", () => {
|
|
|
123
123
|
layout: {},
|
|
124
124
|
});
|
|
125
125
|
const randomSchematic = await client.schematics.create(ws.key, {
|
|
126
|
+
...schematic.ZERO_NEW,
|
|
126
127
|
name: "test",
|
|
127
|
-
data: {},
|
|
128
128
|
});
|
|
129
129
|
await expect(userClient.schematics.delete(randomSchematic.key)).rejects.toThrow(
|
|
130
130
|
AuthError,
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
// Copyright 2026 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
|
+
// Code generated by Oracle. DO NOT EDIT.
|
|
11
|
+
import { caseconv, record, spatial, zod } from "@synnaxlabs/x";
|
|
12
|
+
import { type Draft } from "immer";
|
|
13
|
+
import { z } from "zod";
|
|
14
|
+
|
|
15
|
+
import { actions } from "@/actions";
|
|
16
|
+
import { edgeZ, keyZ, nodeZ, type Schematic } from "@/schematic/types.gen";
|
|
17
|
+
|
|
18
|
+
/** Rename renames the schematic. */
|
|
19
|
+
export const renamePayloadZ = z.object({
|
|
20
|
+
name: z.string(),
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
export type RenamePayload = z.infer<typeof renamePayloadZ>;
|
|
24
|
+
|
|
25
|
+
/** SetNodePosition moves a node to a new position. */
|
|
26
|
+
export const setNodePositionPayloadZ = z.object({
|
|
27
|
+
key: z.string(),
|
|
28
|
+
position: spatial.xyZ,
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
export type SetNodePositionPayload = z.infer<typeof setNodePositionPayloadZ>;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* SetNodeMeasured updates the rendered pixel size of a node. Emitted by the
|
|
35
|
+
* renderer after measuring the mounted node and stored on the
|
|
36
|
+
* node so diagram measurements stay consistent across re-renders.
|
|
37
|
+
*/
|
|
38
|
+
export const setNodeMeasuredPayloadZ = z.object({
|
|
39
|
+
key: z.string(),
|
|
40
|
+
measured: spatial.dimensionsZ,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
export type SetNodeMeasuredPayload = z.infer<typeof setNodeMeasuredPayloadZ>;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* SetNode inserts the node if no node with the same key exists, otherwise
|
|
47
|
+
* replaces the existing node in place. If config is non-empty it is
|
|
48
|
+
* stored under the node's key in the schematic configs map.
|
|
49
|
+
*/
|
|
50
|
+
export const setNodePayloadZ = z.object({
|
|
51
|
+
node: nodeZ,
|
|
52
|
+
config: caseconv.preserveCase(zod.nullToUndefined(record.unknownZ())),
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
export type SetNodePayload = z.infer<typeof setNodePayloadZ>;
|
|
56
|
+
|
|
57
|
+
/** RemoveNode removes a node and any config stored under its key. */
|
|
58
|
+
export const removeNodePayloadZ = z.object({
|
|
59
|
+
key: z.string(),
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
export type RemoveNodePayload = z.infer<typeof removeNodePayloadZ>;
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* AddEdge appends the edge to the schematic. No-op when an edge with the
|
|
66
|
+
* same key already exists.
|
|
67
|
+
*/
|
|
68
|
+
export const addEdgePayloadZ = z.object({
|
|
69
|
+
edge: edgeZ,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
export type AddEdgePayload = z.infer<typeof addEdgePayloadZ>;
|
|
73
|
+
|
|
74
|
+
/** RemoveEdge removes the edge with the given key, if present. */
|
|
75
|
+
export const removeEdgePayloadZ = z.object({
|
|
76
|
+
key: z.string(),
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
export type RemoveEdgePayload = z.infer<typeof removeEdgePayloadZ>;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* SetConfig merges the given config fields into the existing config entry for
|
|
83
|
+
* the given node or edge key. Top-level fields present in the payload
|
|
84
|
+
* overwrite existing fields; fields absent from the payload are
|
|
85
|
+
* preserved. When no entry exists yet and the key matches an edge
|
|
86
|
+
* whose source node carries a color, the source color overrides
|
|
87
|
+
* whatever color (if any) was in the payload.
|
|
88
|
+
*/
|
|
89
|
+
export const setConfigPayloadZ = z.object({
|
|
90
|
+
key: z.string(),
|
|
91
|
+
config: caseconv.preserveCase(record.nullishToEmpty()),
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
export type SetConfigPayload = z.infer<typeof setConfigPayloadZ>;
|
|
95
|
+
|
|
96
|
+
export const actionZ = z.discriminatedUnion("type", [
|
|
97
|
+
z.object({ type: z.literal("rename"), rename: renamePayloadZ }),
|
|
98
|
+
z.object({
|
|
99
|
+
type: z.literal("set_node_position"),
|
|
100
|
+
setNodePosition: setNodePositionPayloadZ,
|
|
101
|
+
}),
|
|
102
|
+
z.object({
|
|
103
|
+
type: z.literal("set_node_measured"),
|
|
104
|
+
setNodeMeasured: setNodeMeasuredPayloadZ,
|
|
105
|
+
}),
|
|
106
|
+
z.object({ type: z.literal("set_node"), setNode: setNodePayloadZ }),
|
|
107
|
+
z.object({ type: z.literal("remove_node"), removeNode: removeNodePayloadZ }),
|
|
108
|
+
z.object({ type: z.literal("add_edge"), addEdge: addEdgePayloadZ }),
|
|
109
|
+
z.object({ type: z.literal("remove_edge"), removeEdge: removeEdgePayloadZ }),
|
|
110
|
+
z.object({ type: z.literal("set_config"), setConfig: setConfigPayloadZ }),
|
|
111
|
+
]);
|
|
112
|
+
|
|
113
|
+
export type Action = z.infer<typeof actionZ>;
|
|
114
|
+
|
|
115
|
+
export const rename = (payload: RenamePayload): Action => ({
|
|
116
|
+
type: "rename",
|
|
117
|
+
rename: payload,
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
export const setNodePosition = (payload: SetNodePositionPayload): Action => ({
|
|
121
|
+
type: "set_node_position",
|
|
122
|
+
setNodePosition: payload,
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
export const setNodeMeasured = (payload: SetNodeMeasuredPayload): Action => ({
|
|
126
|
+
type: "set_node_measured",
|
|
127
|
+
setNodeMeasured: payload,
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
export const setNode = (payload: SetNodePayload): Action => ({
|
|
131
|
+
type: "set_node",
|
|
132
|
+
setNode: payload,
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
export const removeNode = (payload: RemoveNodePayload): Action => ({
|
|
136
|
+
type: "remove_node",
|
|
137
|
+
removeNode: payload,
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
export const addEdge = (payload: AddEdgePayload): Action => ({
|
|
141
|
+
type: "add_edge",
|
|
142
|
+
addEdge: payload,
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
export const removeEdge = (payload: RemoveEdgePayload): Action => ({
|
|
146
|
+
type: "remove_edge",
|
|
147
|
+
removeEdge: payload,
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
export const setConfig = (payload: SetConfigPayload): Action => ({
|
|
151
|
+
type: "set_config",
|
|
152
|
+
setConfig: payload,
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
export type HandlerResult = actions.HandlerResult<Action>;
|
|
156
|
+
|
|
157
|
+
export type ReduceAllResult = actions.ReduceAllResult<Schematic, Action>;
|
|
158
|
+
|
|
159
|
+
export interface Handlers {
|
|
160
|
+
rename: (state: Draft<Schematic>, payload: RenamePayload) => HandlerResult;
|
|
161
|
+
setNodePosition: (
|
|
162
|
+
state: Draft<Schematic>,
|
|
163
|
+
payload: SetNodePositionPayload,
|
|
164
|
+
) => HandlerResult;
|
|
165
|
+
setNodeMeasured: (
|
|
166
|
+
state: Draft<Schematic>,
|
|
167
|
+
payload: SetNodeMeasuredPayload,
|
|
168
|
+
) => HandlerResult;
|
|
169
|
+
setNode: (state: Draft<Schematic>, payload: SetNodePayload) => HandlerResult;
|
|
170
|
+
removeNode: (state: Draft<Schematic>, payload: RemoveNodePayload) => HandlerResult;
|
|
171
|
+
addEdge: (state: Draft<Schematic>, payload: AddEdgePayload) => HandlerResult;
|
|
172
|
+
removeEdge: (state: Draft<Schematic>, payload: RemoveEdgePayload) => HandlerResult;
|
|
173
|
+
setConfig: (state: Draft<Schematic>, payload: SetConfigPayload) => HandlerResult;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
export const createReduceAll = (handlers: Handlers) =>
|
|
177
|
+
actions.createReduceAll<Schematic, Action>((state, action) => {
|
|
178
|
+
switch (action.type) {
|
|
179
|
+
case "rename":
|
|
180
|
+
return handlers.rename(state, action.rename);
|
|
181
|
+
case "set_node_position":
|
|
182
|
+
return handlers.setNodePosition(state, action.setNodePosition);
|
|
183
|
+
case "set_node_measured":
|
|
184
|
+
return handlers.setNodeMeasured(state, action.setNodeMeasured);
|
|
185
|
+
case "set_node":
|
|
186
|
+
return handlers.setNode(state, action.setNode);
|
|
187
|
+
case "remove_node":
|
|
188
|
+
return handlers.removeNode(state, action.removeNode);
|
|
189
|
+
case "add_edge":
|
|
190
|
+
return handlers.addEdge(state, action.addEdge);
|
|
191
|
+
case "remove_edge":
|
|
192
|
+
return handlers.removeEdge(state, action.removeEdge);
|
|
193
|
+
case "set_config":
|
|
194
|
+
return handlers.setConfig(state, action.setConfig);
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
export const scopedActionZ = actions.scopedZ(keyZ, actionZ);
|
|
199
|
+
|
|
200
|
+
export const dispatchReqZ = actions.dispatchReqZ(keyZ, actionZ);
|