@synnaxlabs/client 0.44.4 → 0.45.1

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.
Files changed (38) hide show
  1. package/.turbo/turbo-build.log +6 -6
  2. package/dist/access/policy/client.d.ts +28 -22
  3. package/dist/access/policy/client.d.ts.map +1 -1
  4. package/dist/access/policy/payload.d.ts +16 -10
  5. package/dist/access/policy/payload.d.ts.map +1 -1
  6. package/dist/client.cjs +22 -22
  7. package/dist/client.js +3275 -2914
  8. package/dist/label/client.d.ts +6 -3
  9. package/dist/label/client.d.ts.map +1 -1
  10. package/dist/ontology/client.d.ts +3 -1
  11. package/dist/ontology/client.d.ts.map +1 -1
  12. package/dist/ontology/payload.d.ts +17 -12
  13. package/dist/ontology/payload.d.ts.map +1 -1
  14. package/dist/ranger/writer.d.ts +2 -1
  15. package/dist/ranger/writer.d.ts.map +1 -1
  16. package/dist/workspace/schematic/client.d.ts +2 -0
  17. package/dist/workspace/schematic/client.d.ts.map +1 -1
  18. package/dist/workspace/schematic/external.d.ts +1 -0
  19. package/dist/workspace/schematic/external.d.ts.map +1 -1
  20. package/dist/workspace/schematic/symbol/client.d.ts +57 -0
  21. package/dist/workspace/schematic/symbol/client.d.ts.map +1 -0
  22. package/dist/workspace/schematic/symbol/client.spec.d.ts +2 -0
  23. package/dist/workspace/schematic/symbol/client.spec.d.ts.map +1 -0
  24. package/dist/workspace/schematic/symbol/external.d.ts +3 -0
  25. package/dist/workspace/schematic/symbol/external.d.ts.map +1 -0
  26. package/dist/workspace/schematic/symbol/index.d.ts +2 -0
  27. package/dist/workspace/schematic/symbol/index.d.ts.map +1 -0
  28. package/dist/workspace/schematic/symbol/payload.d.ts +169 -0
  29. package/dist/workspace/schematic/symbol/payload.d.ts.map +1 -0
  30. package/package.json +4 -4
  31. package/src/ontology/payload.ts +1 -0
  32. package/src/workspace/schematic/client.ts +3 -0
  33. package/src/workspace/schematic/external.ts +1 -0
  34. package/src/workspace/schematic/symbol/client.spec.ts +133 -0
  35. package/src/workspace/schematic/symbol/client.ts +146 -0
  36. package/src/workspace/schematic/symbol/external.ts +11 -0
  37. package/src/workspace/schematic/symbol/index.ts +10 -0
  38. package/src/workspace/schematic/symbol/payload.ts +70 -0
@@ -0,0 +1,133 @@
1
+ // Copyright 2025 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 { beforeAll, describe, expect, it } from "vitest";
11
+
12
+ import { ontology } from "@/ontology";
13
+ import { type group } from "@/ontology/group";
14
+ import { createTestClient } from "@/testutil/client";
15
+
16
+ const client = createTestClient();
17
+
18
+ describe("Symbol Client", () => {
19
+ let group: group.Group;
20
+ beforeAll(async () => {
21
+ group = await client.ontology.groups.create(ontology.ROOT_ID, "Test Symbols");
22
+ });
23
+ describe("create", () => {
24
+ it("should create a single symbol", async () => {
25
+ const symbol = await client.workspaces.schematic.symbols.create({
26
+ name: "Test Symbol",
27
+ data: {
28
+ svg: "<svg></svg>",
29
+ states: [],
30
+ handles: [],
31
+ variant: "sensor",
32
+ },
33
+ parent: group.ontologyID,
34
+ });
35
+ expect(symbol.name).toBe("Test Symbol");
36
+ expect(symbol.key).toBeDefined();
37
+ });
38
+
39
+ it("should create multiple symbols", async () => {
40
+ const symbols = await client.workspaces.schematic.symbols.create({
41
+ symbols: [
42
+ {
43
+ name: "Symbol 1",
44
+ data: { svg: "<svg></svg>", states: [], handles: [], variant: "sensor" },
45
+ },
46
+ {
47
+ name: "Symbol 2",
48
+ data: { svg: "<svg></svg>", states: [], handles: [], variant: "sensor" },
49
+ },
50
+ ],
51
+ parent: group.ontologyID,
52
+ });
53
+ expect(symbols).toHaveLength(2);
54
+ expect(symbols[0].name).toBe("Symbol 1");
55
+ expect(symbols[1].name).toBe("Symbol 2");
56
+ });
57
+ });
58
+
59
+ describe("retrieve", () => {
60
+ it("should retrieve a single symbol by key", async () => {
61
+ const created = await client.workspaces.schematic.symbols.create({
62
+ name: "Retrieve Test",
63
+ data: { svg: "<svg></svg>", states: [], handles: [], variant: "sensor" },
64
+ parent: group.ontologyID,
65
+ });
66
+
67
+ const retrieved = await client.workspaces.schematic.symbols.retrieve({
68
+ key: created.key,
69
+ });
70
+ expect(retrieved.key).toBe(created.key);
71
+ expect(retrieved.name).toBe("Retrieve Test");
72
+ });
73
+
74
+ it("should retrieve multiple symbols by keys", async () => {
75
+ const created1 = await client.workspaces.schematic.symbols.create({
76
+ name: "Multi Test 1",
77
+ data: { svg: "<svg></svg>", states: [], handles: [], variant: "sensor" },
78
+ parent: group.ontologyID,
79
+ });
80
+ const created2 = await client.workspaces.schematic.symbols.create({
81
+ name: "Multi Test 2",
82
+ data: { svg: "<svg></svg>", states: [], handles: [], variant: "sensor" },
83
+ parent: group.ontologyID,
84
+ });
85
+
86
+ const retrieved = await client.workspaces.schematic.symbols.retrieve({
87
+ keys: [created1.key, created2.key],
88
+ });
89
+ expect(retrieved).toHaveLength(2);
90
+ });
91
+ });
92
+
93
+ describe("rename", () => {
94
+ it("should rename a symbol", async () => {
95
+ const symbol = await client.workspaces.schematic.symbols.create({
96
+ name: "Original Name",
97
+ data: { svg: "<svg></svg>", states: [], handles: [], variant: "sensor" },
98
+ parent: group.ontologyID,
99
+ });
100
+
101
+ await client.workspaces.schematic.symbols.rename(symbol.key, "New Name");
102
+
103
+ const retrieved = await client.workspaces.schematic.symbols.retrieve({
104
+ key: symbol.key,
105
+ });
106
+ expect(retrieved.name).toBe("New Name");
107
+ });
108
+ });
109
+
110
+ describe("delete", () => {
111
+ it("should delete a single symbol", async () => {
112
+ const symbol = await client.workspaces.schematic.symbols.create({
113
+ name: "Delete Test",
114
+ data: { svg: "<svg></svg>", states: [], handles: [], variant: "sensor" },
115
+ parent: group.ontologyID,
116
+ });
117
+
118
+ await client.workspaces.schematic.symbols.delete(symbol.key);
119
+
120
+ await expect(
121
+ client.workspaces.schematic.symbols.retrieve({ key: symbol.key }),
122
+ ).rejects.toThrow();
123
+ });
124
+ });
125
+
126
+ describe("retrieveGroup", () => {
127
+ it("should retrieve the symbol group", async () => {
128
+ const group = await client.workspaces.schematic.symbols.retrieveGroup();
129
+ expect(group.key).toBeDefined();
130
+ expect(group.name).toBe("Schematic Symbols");
131
+ });
132
+ });
133
+ });
@@ -0,0 +1,146 @@
1
+ // Copyright 2025 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 { array } from "@synnaxlabs/x";
12
+ import { z } from "zod";
13
+
14
+ import { ontology } from "@/ontology";
15
+ import { group } from "@/ontology/group";
16
+ import { checkForMultipleOrNoResults } from "@/util/retrieve";
17
+ import { nullableArrayZ } from "@/util/zod";
18
+ import {
19
+ type Key,
20
+ keyZ,
21
+ type New,
22
+ newZ,
23
+ type Symbol,
24
+ symbolZ,
25
+ } from "@/workspace/schematic/symbol/payload";
26
+
27
+ const RETRIEVE_ENDPOINT = "/workspace/schematic/symbol/retrieve";
28
+ const CREATE_ENDPOINT = "/workspace/schematic/symbol/create";
29
+ const RENAME_ENDPOINT = "/workspace/schematic/symbol/rename";
30
+ const DELETE_ENDPOINT = "/workspace/schematic/symbol/delete";
31
+ const RETRIEVE_GROUP_ENDPOINT = "/workspace/schematic/symbol/retrieve_group";
32
+
33
+ const createReqZ = z.object({ symbols: newZ.array(), parent: ontology.idZ });
34
+ const renameReqZ = z.object({ key: keyZ, name: z.string() });
35
+ const deleteReqZ = z.object({ keys: keyZ.array() });
36
+
37
+ const retrieveRequestZ = z.object({
38
+ keys: keyZ.array().optional(),
39
+ searchTerm: z.string().optional(),
40
+ offset: z.number().optional(),
41
+ limit: z.number().optional(),
42
+ });
43
+
44
+ const singleRetrieveArgsZ = z
45
+ .object({ key: keyZ })
46
+ .transform(({ key }) => ({ keys: [key] }));
47
+
48
+ const retrieveArgsZ = z.union([singleRetrieveArgsZ, retrieveRequestZ]);
49
+
50
+ export type RetrieveArgs = z.input<typeof retrieveArgsZ>;
51
+ export type SingleRetrieveArgs = z.input<typeof singleRetrieveArgsZ>;
52
+ export type MultiRetrieveArgs = z.input<typeof retrieveRequestZ>;
53
+
54
+ const retrieveResZ = z.object({ symbols: nullableArrayZ(symbolZ) });
55
+ const createResZ = z.object({ symbols: symbolZ.array() });
56
+ const emptyResZ = z.object({});
57
+ const retrieveGroupReqZ = z.object({});
58
+ const retrieveGroupResZ = z.object({ group: group.groupZ });
59
+
60
+ export const SET_CHANNEL_NAME = "sy_schematic_symbol_set";
61
+ export const DELETE_CHANNEL_NAME = "sy_schematic_symbol_delete";
62
+
63
+ export interface CreateArgs extends New {
64
+ parent: ontology.ID;
65
+ }
66
+
67
+ export interface CreateMultipleArgs {
68
+ symbols: New[];
69
+ parent: ontology.ID;
70
+ }
71
+
72
+ export class Client {
73
+ private readonly client: UnaryClient;
74
+
75
+ constructor(client: UnaryClient) {
76
+ this.client = client;
77
+ }
78
+
79
+ async create(options: CreateArgs): Promise<Symbol>;
80
+ async create(options: CreateMultipleArgs): Promise<Symbol[]>;
81
+ async create(options: CreateArgs | CreateMultipleArgs): Promise<Symbol | Symbol[]> {
82
+ const isMany = "symbols" in options;
83
+ const symbols = isMany ? options.symbols : [options];
84
+ const res = await sendRequired(
85
+ this.client,
86
+ CREATE_ENDPOINT,
87
+ { symbols, parent: options.parent },
88
+ createReqZ,
89
+ createResZ,
90
+ );
91
+ return isMany ? res.symbols : res.symbols[0];
92
+ }
93
+
94
+ async rename(key: Key, name: string): Promise<void> {
95
+ await sendRequired(
96
+ this.client,
97
+ RENAME_ENDPOINT,
98
+ { key, name },
99
+ renameReqZ,
100
+ emptyResZ,
101
+ );
102
+ }
103
+
104
+ async retrieve(args: SingleRetrieveArgs): Promise<Symbol>;
105
+ async retrieve(args: MultiRetrieveArgs): Promise<Symbol[]>;
106
+ async retrieve(args: RetrieveArgs): Promise<Symbol | Symbol[]> {
107
+ const isSingle = "key" in args;
108
+ const res = await sendRequired(
109
+ this.client,
110
+ RETRIEVE_ENDPOINT,
111
+ args,
112
+ retrieveArgsZ,
113
+ retrieveResZ,
114
+ );
115
+ checkForMultipleOrNoResults("Schematic Symbol", args, res.symbols, isSingle);
116
+ return isSingle ? res.symbols[0] : res.symbols;
117
+ }
118
+
119
+ async delete(key: Key): Promise<void>;
120
+ async delete(keys: Key[]): Promise<void>;
121
+ async delete(keys: Key | Key[]): Promise<void> {
122
+ await sendRequired(
123
+ this.client,
124
+ DELETE_ENDPOINT,
125
+ { keys: array.toArray(keys) },
126
+ deleteReqZ,
127
+ emptyResZ,
128
+ );
129
+ }
130
+
131
+ async retrieveGroup(): Promise<group.Payload> {
132
+ const res = await sendRequired(
133
+ this.client,
134
+ RETRIEVE_GROUP_ENDPOINT,
135
+ {},
136
+ retrieveGroupReqZ,
137
+ retrieveGroupResZ,
138
+ );
139
+ return res.group;
140
+ }
141
+ }
142
+
143
+ export const ontologyID = (key: Key): ontology.ID => ({
144
+ type: "schematic_symbol",
145
+ key,
146
+ });
@@ -0,0 +1,11 @@
1
+ // Copyright 2025 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
+ export * from "@/workspace/schematic/symbol/client";
11
+ export * from "@/workspace/schematic/symbol/payload";
@@ -0,0 +1,10 @@
1
+ // Copyright 2025 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
+ export * as symbol from "@/workspace/schematic/symbol/external";
@@ -0,0 +1,70 @@
1
+ // Copyright 2025 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 { location, xy } from "@synnaxlabs/x";
11
+ import { z } from "zod";
12
+
13
+ export const keyZ = z.uuid();
14
+ export type Key = z.infer<typeof keyZ>;
15
+ export type Params = Key | Key[];
16
+
17
+ export const regionZ = z.object({
18
+ key: z.string(),
19
+ name: z.string(),
20
+ selectors: z.string().array().default([]),
21
+ strokeColor: z.string().optional(),
22
+ fillColor: z.string().optional(),
23
+ });
24
+
25
+ export interface Region extends z.infer<typeof regionZ> {}
26
+
27
+ export const stateZ = z.object({
28
+ key: z.string(),
29
+ name: z.string(),
30
+ regions: regionZ.array(),
31
+ });
32
+
33
+ export interface State extends z.infer<typeof stateZ> {}
34
+
35
+ export const handleZ = z.object({
36
+ key: z.string(),
37
+ position: xy.xy,
38
+ orientation: location.outer,
39
+ });
40
+
41
+ export interface Handle extends z.infer<typeof handleZ> {}
42
+
43
+ const viewportZ = z.object({
44
+ zoom: z.number().positive().default(1),
45
+ position: xy.xy,
46
+ });
47
+
48
+ export const specZ = z.object({
49
+ svg: z.string().min(1, "SVG is required"),
50
+ states: stateZ.array(),
51
+ variant: z.string().min(1, "Variant is required"),
52
+ handles: handleZ.array(),
53
+ scale: z.number().positive().default(1),
54
+ scaleStroke: z.boolean().default(false),
55
+ previewViewport: viewportZ.default({ zoom: 1, position: { x: 0, y: 0 } }),
56
+ });
57
+
58
+ export interface Spec extends z.infer<typeof specZ> {}
59
+
60
+ export const symbolZ = z.object({
61
+ key: keyZ,
62
+ version: z.literal(1).optional().default(1),
63
+ name: z.string().min(1, "Name is required"),
64
+ data: specZ,
65
+ });
66
+
67
+ export const newZ = symbolZ.partial({ key: true });
68
+ export interface New extends z.input<typeof newZ> {}
69
+
70
+ export interface Symbol extends z.infer<typeof symbolZ> {}