Skip to content

Commit c2d138b

Browse files
authored
SY-3833: Strongly Type Schematics on the Core (#2283)
1 parent c6358eb commit c2d138b

77 files changed

Lines changed: 20199 additions & 347 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

arc/go/graph/codec_gen_test.go

Lines changed: 7 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/ts/src/arc/compiler/types.gen.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
// Code generated by Oracle. DO NOT EDIT.
1111

12+
import { record } from "@synnaxlabs/x";
1213
import { z } from "zod";
1314

1415
/**
@@ -22,6 +23,6 @@ export const outputZ = z.object({
2223
* outputMemoryBases contains memory base addresses for multi-output functions, mapping
2324
* function keys to their base addresses.
2425
*/
25-
outputMemoryBases: z.record(z.string(), z.uint32()),
26+
outputMemoryBases: record.nullishToEmpty(z.string(), z.uint32()),
2627
});
2728
export interface Output extends z.infer<typeof outputZ> {}

client/ts/src/arc/ir/types.gen.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
// Code generated by Oracle. DO NOT EDIT.
1111

12-
import { array, zod } from "@synnaxlabs/x";
12+
import { array, record, zod } from "@synnaxlabs/x";
1313
import { z } from "zod";
1414

1515
import { types } from "@/arc/types";
@@ -76,7 +76,7 @@ export const authoritiesZ = z.object({
7676
/** default is the default authority for all write channels not explicitly listed. */
7777
default: zod.uint8.optional(),
7878
/** channels maps channel keys to their specific authority values. */
79-
channels: z.record(z.uint32(), zod.uint8),
79+
channels: record.nullishToEmpty(z.uint32(), zod.uint8),
8080
});
8181
export interface Authorities extends z.infer<typeof authoritiesZ> {}
8282

client/ts/src/arc/types/types.gen.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
// Code generated by Oracle. DO NOT EDIT.
1111

12-
import { array, zod } from "@synnaxlabs/x";
12+
import { array, record, zod } from "@synnaxlabs/x";
1313
import { z } from "zod";
1414

1515
export enum Kind {
@@ -48,9 +48,9 @@ export const chanDirectionZ = z.enum(ChanDirection);
4848
/** Channels contains channel declarations for reading from and writing to Synnax channels. */
4949
export const channelsZ = z.object({
5050
/** read contains readable channel indices mapped to parameter names. */
51-
read: z.record(z.uint32(), z.string()),
51+
read: record.nullishToEmpty(z.uint32(), z.string()),
5252
/** write contains writable channel indices mapped to parameter names. */
53-
write: z.record(z.uint32(), z.string()),
53+
write: record.nullishToEmpty(z.uint32(), z.string()),
5454
});
5555
export interface Channels extends z.infer<typeof channelsZ> {}
5656

client/ts/src/schematic/access.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ describe("schematic", () => {
2929
layout: {},
3030
});
3131
const randomSchematic = await client.schematics.create(ws.key, {
32+
...schematic.ZERO_NEW,
3233
name: "test",
33-
data: {},
3434
});
3535
await expect(
3636
userClient.schematics.retrieve({ key: randomSchematic.key }),
@@ -48,8 +48,8 @@ describe("schematic", () => {
4848
layout: {},
4949
});
5050
const randomSchematic = await client.schematics.create(ws.key, {
51+
...schematic.ZERO_NEW,
5152
name: "test",
52-
data: {},
5353
});
5454
const retrieved = await userClient.schematics.retrieve({
5555
key: randomSchematic.key,
@@ -69,8 +69,8 @@ describe("schematic", () => {
6969
layout: {},
7070
});
7171
await userClient.schematics.create(ws.key, {
72+
...schematic.ZERO_NEW,
7273
name: "test",
73-
data: {},
7474
});
7575
});
7676

@@ -86,8 +86,8 @@ describe("schematic", () => {
8686
});
8787
await expect(
8888
userClient.schematics.create(ws.key, {
89+
...schematic.ZERO_NEW,
8990
name: "test",
90-
data: {},
9191
}),
9292
).rejects.toThrow(AuthError);
9393
});
@@ -103,8 +103,8 @@ describe("schematic", () => {
103103
layout: {},
104104
});
105105
const randomSchematic = await client.schematics.create(ws.key, {
106+
...schematic.ZERO_NEW,
106107
name: "test",
107-
data: {},
108108
});
109109
await userClient.schematics.delete(randomSchematic.key);
110110
await expect(
@@ -123,8 +123,8 @@ describe("schematic", () => {
123123
layout: {},
124124
});
125125
const randomSchematic = await client.schematics.create(ws.key, {
126+
...schematic.ZERO_NEW,
126127
name: "test",
127-
data: {},
128128
});
129129
await expect(userClient.schematics.delete(randomSchematic.key)).rejects.toThrow(
130130
AuthError,

client/ts/src/schematic/client.ts

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
// included in the file licenses/APL.txt.
99

1010
import { sendRequired, type UnaryClient } from "@synnaxlabs/freighter";
11-
import { array, caseconv, record } from "@synnaxlabs/x";
11+
import { array } from "@synnaxlabs/x";
1212
import { z } from "zod";
1313

1414
import { symbol } from "@/schematic/symbol";
1515
import {
1616
type Key,
1717
keyZ,
18+
type Legend,
1819
type New,
1920
newZ,
2021
type Schematic,
@@ -25,10 +26,9 @@ import { workspace } from "@/workspace";
2526

2627
const renameReqZ = z.object({ key: keyZ, name: z.string() });
2728

28-
const setDataReqZ = z.object({
29-
key: keyZ,
30-
data: caseconv.preserveCase(record.unknownZ()),
31-
});
29+
const setDataBodyZ = schematicZ.omit({ key: true, name: true, snapshot: true });
30+
export type SetDataBody = z.input<typeof setDataBodyZ>;
31+
const setDataReqZ = z.object({ key: keyZ, data: setDataBodyZ });
3232
const deleteReqZ = z.object({ keys: keyZ.array() });
3333

3434
const copyReqZ = z.object({
@@ -95,7 +95,7 @@ export class Client {
9595
);
9696
}
9797

98-
async setData(key: Key, data: record.Unknown): Promise<void> {
98+
async setData(key: Key, data: SetDataBody): Promise<void> {
9999
await sendRequired(
100100
this.client,
101101
"/schematic/set-data",
@@ -143,3 +143,17 @@ export class Client {
143143
return res.schematic;
144144
}
145145
}
146+
147+
export const ZERO_LEGEND: Legend = {
148+
visible: true,
149+
position: { x: 50, y: 50, units: { x: "px", y: "px" } },
150+
colors: {},
151+
};
152+
153+
export const ZERO_NEW: New = {
154+
name: "",
155+
legend: ZERO_LEGEND,
156+
nodes: [],
157+
edges: [],
158+
configs: {},
159+
};

0 commit comments

Comments
 (0)