@synnaxlabs/client 0.38.0 → 0.39.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 +8 -7
- 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 +3488 -3500
- 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 +17 -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/eslint.config.js +1 -1
- package/examples/node/basicReadWrite.js +27 -27
- package/examples/node/liveStream.js +16 -16
- package/examples/node/seriesAndFrames.js +39 -39
- package/examples/node/streamWrite.js +48 -46
- package/package.json +14 -12
- package/src/access/client.ts +1 -1
- package/src/access/external.ts +1 -1
- package/src/access/index.ts +1 -1
- package/src/access/payload.ts +13 -13
- package/src/access/policy/client.ts +14 -13
- package/src/access/policy/external.ts +2 -1
- package/src/access/policy/index.ts +1 -1
- package/src/access/policy/ontology.ts +17 -0
- package/src/access/policy/payload.ts +8 -20
- package/src/access/policy/policy.spec.ts +17 -17
- package/src/access/policy/retriever.ts +3 -2
- package/src/access/policy/writer.ts +5 -5
- package/src/auth/auth.spec.ts +28 -24
- package/src/auth/auth.ts +8 -12
- package/src/auth/index.ts +1 -1
- package/src/channel/batchRetriever.spec.ts +26 -23
- package/src/channel/channel.spec.ts +1 -1
- package/src/channel/client.ts +24 -24
- package/src/channel/external.ts +1 -1
- package/src/channel/index.ts +1 -1
- package/src/channel/payload.ts +17 -21
- package/src/channel/retriever.ts +21 -22
- package/src/channel/writer.ts +12 -14
- package/src/client.ts +7 -17
- package/src/connection/checker.ts +10 -12
- package/src/connection/connection.spec.ts +18 -6
- package/src/connection/index.ts +1 -1
- package/src/control/client.ts +1 -1
- package/src/control/external.ts +1 -1
- package/src/control/index.ts +1 -1
- package/src/control/state.spec.ts +1 -1
- package/src/control/state.ts +9 -10
- package/src/errors.spec.ts +2 -2
- package/src/errors.ts +9 -1
- package/src/framer/adapter.spec.ts +29 -24
- package/src/framer/adapter.ts +38 -42
- package/src/framer/client.spec.ts +6 -12
- package/src/framer/client.ts +35 -39
- package/src/framer/deleter.spec.ts +1 -1
- package/src/framer/deleter.ts +6 -7
- package/src/framer/external.ts +1 -1
- package/src/framer/frame.spec.ts +1 -1
- package/src/framer/frame.ts +63 -51
- package/src/framer/index.ts +1 -1
- package/src/framer/iterator.spec.ts +1 -1
- package/src/framer/iterator.ts +12 -17
- package/src/framer/streamProxy.ts +2 -2
- package/src/framer/streamer.spec.ts +3 -11
- package/src/framer/streamer.ts +16 -20
- package/src/framer/writer.spec.ts +49 -8
- package/src/framer/writer.ts +40 -32
- package/src/hardware/client.ts +1 -1
- package/src/hardware/device/client.ts +65 -40
- package/src/hardware/device/device.spec.ts +50 -34
- package/src/hardware/device/external.ts +1 -1
- package/src/hardware/device/index.ts +1 -1
- package/src/hardware/device/payload.ts +30 -30
- package/src/hardware/external.ts +1 -1
- package/src/hardware/index.ts +1 -1
- package/src/hardware/rack/client.ts +53 -66
- package/src/hardware/rack/external.ts +1 -1
- package/src/hardware/rack/index.ts +1 -1
- package/src/hardware/rack/payload.ts +10 -19
- package/src/hardware/rack/rack.spec.ts +13 -1
- package/src/hardware/task/client.ts +161 -132
- package/src/hardware/task/external.ts +1 -1
- package/src/hardware/task/index.ts +1 -1
- package/src/hardware/task/payload.ts +50 -69
- package/src/hardware/task/task.spec.ts +99 -82
- package/src/index.ts +1 -1
- package/src/label/client.ts +13 -16
- package/src/label/external.ts +1 -1
- package/src/label/index.ts +1 -1
- package/src/label/label.spec.ts +1 -1
- package/src/label/payload.ts +4 -10
- package/src/label/retriever.ts +4 -8
- package/src/label/writer.ts +9 -16
- package/src/ontology/client.ts +31 -29
- package/src/ontology/external.ts +1 -1
- package/src/ontology/group/client.ts +6 -6
- package/src/ontology/group/external.ts +1 -1
- package/src/ontology/group/group.spec.ts +5 -5
- package/src/ontology/group/group.ts +11 -8
- package/src/ontology/group/index.ts +1 -1
- package/src/ontology/group/payload.ts +12 -36
- package/src/ontology/group/writer.ts +23 -27
- package/src/ontology/index.ts +1 -1
- package/src/ontology/ontology.spec.ts +16 -16
- package/src/ontology/payload.ts +68 -44
- package/src/ontology/writer.ts +17 -24
- package/src/ranger/alias.ts +26 -43
- package/src/ranger/client.ts +34 -41
- package/src/ranger/external.ts +2 -2
- package/src/ranger/index.ts +1 -1
- package/src/ranger/kv.ts +10 -33
- package/src/ranger/payload.ts +15 -37
- package/src/ranger/ranger.spec.ts +2 -3
- package/src/ranger/writer.ts +9 -27
- package/src/setupspecs.ts +1 -1
- package/src/signals/external.ts +1 -1
- package/src/signals/index.ts +1 -1
- package/src/signals/observable.ts +4 -5
- package/src/transport.ts +1 -1
- package/src/user/client.ts +9 -5
- package/src/user/external.ts +1 -1
- package/src/user/index.ts +1 -1
- package/src/user/payload.ts +6 -10
- package/src/user/retriever.ts +2 -2
- package/src/user/user.spec.ts +18 -16
- package/src/user/writer.ts +4 -11
- package/src/util/decodeJSONString.ts +13 -0
- package/src/util/parseWithoutKeyConversion.ts +19 -0
- package/src/util/retrieve.spec.ts +4 -14
- package/src/util/retrieve.ts +3 -13
- package/src/util/telem.ts +2 -2
- package/src/util/zod.ts +1 -1
- package/src/vite-env.d.ts +2 -1
- package/src/workspace/client.ts +39 -57
- package/src/workspace/external.ts +11 -0
- package/src/workspace/index.ts +2 -2
- package/src/workspace/lineplot/client.ts +31 -36
- package/src/workspace/lineplot/external.ts +11 -0
- package/src/workspace/lineplot/index.ts +2 -2
- package/src/workspace/lineplot/linePlot.spec.ts +2 -3
- package/src/workspace/lineplot/payload.ts +32 -0
- package/src/workspace/log/client.ts +34 -39
- package/src/workspace/log/external.ts +11 -0
- package/src/workspace/log/index.ts +2 -2
- package/src/workspace/log/log.spec.ts +6 -19
- package/src/workspace/log/payload.ts +32 -0
- package/src/workspace/payload.ts +36 -0
- package/src/workspace/schematic/client.ts +39 -56
- package/src/workspace/schematic/external.ts +11 -0
- package/src/workspace/schematic/index.ts +2 -2
- package/src/workspace/schematic/payload.ts +37 -0
- package/src/workspace/schematic/schematic.spec.ts +16 -7
- package/src/workspace/table/client.ts +36 -50
- package/src/workspace/table/external.ts +11 -0
- package/src/workspace/table/index.ts +2 -2
- package/src/workspace/table/payload.ts +36 -0
- package/src/workspace/table/table.spec.ts +1 -1
- package/src/workspace/workspace.spec.ts +2 -3
- package/vite.config.ts +1 -1
- package/dist/channel/creator.d.ts +0 -9
- package/dist/channel/creator.d.ts.map +0 -1
- package/src/channel/creator.ts +0 -37
package/src/ontology/client.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
1
|
+
// Copyright 2025 Synnax Labs, Inc.
|
|
2
2
|
//
|
|
3
3
|
// Use of this software is governed by the Business Source License included in the file
|
|
4
4
|
// licenses/BSL.txt.
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
// included in the file licenses/APL.txt.
|
|
9
9
|
|
|
10
10
|
import { sendRequired, type UnaryClient } from "@synnaxlabs/freighter";
|
|
11
|
-
import { observe, toArray } from "@synnaxlabs/x";
|
|
11
|
+
import { observe, strings, toArray } from "@synnaxlabs/x";
|
|
12
12
|
import { type AsyncTermSearcher } from "@synnaxlabs/x/search";
|
|
13
13
|
import { z } from "zod";
|
|
14
14
|
|
|
@@ -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);
|
|
@@ -123,7 +118,11 @@ export class Client implements AsyncTermSearcher<string, string, Resource> {
|
|
|
123
118
|
const resources = await this.execRetrieve({ ids: parseIDs(ids), ...options });
|
|
124
119
|
if (Array.isArray(ids)) return resources;
|
|
125
120
|
if (resources.length === 0)
|
|
126
|
-
throw new QueryError(
|
|
121
|
+
throw new QueryError(
|
|
122
|
+
`No resource found with ID ${strings.naturalLanguageJoin(
|
|
123
|
+
toArray(ids).map((id) => new ID(id).toString()),
|
|
124
|
+
)}`,
|
|
125
|
+
);
|
|
127
126
|
return resources[0];
|
|
128
127
|
}
|
|
129
128
|
|
|
@@ -250,10 +249,10 @@ export class Client implements AsyncTermSearcher<string, string, Resource> {
|
|
|
250
249
|
}
|
|
251
250
|
}
|
|
252
251
|
|
|
253
|
-
const
|
|
254
|
-
const
|
|
255
|
-
const
|
|
256
|
-
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";
|
|
257
256
|
|
|
258
257
|
/**
|
|
259
258
|
* A class that tracks changes to the ontology's resources and relationships.
|
|
@@ -306,7 +305,7 @@ export class ChangeTracker {
|
|
|
306
305
|
}
|
|
307
306
|
|
|
308
307
|
private parseRelationshipSets(frame: framer.Frame): RelationshipChange[] {
|
|
309
|
-
const relationships = frame.get(
|
|
308
|
+
const relationships = frame.get(RELATIONSHIP_SET_CHANNEL_NAME);
|
|
310
309
|
if (relationships.length === 0) return [];
|
|
311
310
|
return Array.from(relationships.as("string")).map((rel) => ({
|
|
312
311
|
variant: "set",
|
|
@@ -316,7 +315,7 @@ export class ChangeTracker {
|
|
|
316
315
|
}
|
|
317
316
|
|
|
318
317
|
private parseRelationshipDeletes(frame: framer.Frame): RelationshipChange[] {
|
|
319
|
-
const relationships = frame.get(
|
|
318
|
+
const relationships = frame.get(RELATIONSHIP_DELETE_CHANNEL_NAME);
|
|
320
319
|
if (relationships.length === 0) return [];
|
|
321
320
|
return Array.from(relationships.as("string")).map((rel) => ({
|
|
322
321
|
variant: "delete",
|
|
@@ -325,7 +324,7 @@ export class ChangeTracker {
|
|
|
325
324
|
}
|
|
326
325
|
|
|
327
326
|
private async parseResourceSets(frame: framer.Frame): Promise<ResourceChange[]> {
|
|
328
|
-
const sets = frame.get(
|
|
327
|
+
const sets = frame.get(RESOURCE_SET_CHANNEL_NAME);
|
|
329
328
|
if (sets.length === 0) return [];
|
|
330
329
|
// We should only ever get one series of sets
|
|
331
330
|
const ids = Array.from(sets.as("string")).map((id: string) => new ID(id));
|
|
@@ -343,7 +342,7 @@ export class ChangeTracker {
|
|
|
343
342
|
}
|
|
344
343
|
|
|
345
344
|
private parseResourceDeletes(frame: framer.Frame): ResourceChange[] {
|
|
346
|
-
const deletes = frame.get(
|
|
345
|
+
const deletes = frame.get(RESOURCE_DELETE_CHANNEL_NAME);
|
|
347
346
|
if (deletes.length === 0) return [];
|
|
348
347
|
// We should only ever get one series of deletes
|
|
349
348
|
return Array.from(deletes.as("string")).map((str) => ({
|
|
@@ -354,10 +353,10 @@ export class ChangeTracker {
|
|
|
354
353
|
|
|
355
354
|
static async open(client: framer.Client, retriever: Client): Promise<ChangeTracker> {
|
|
356
355
|
const streamer = await client.openStreamer([
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
356
|
+
RESOURCE_SET_CHANNEL_NAME,
|
|
357
|
+
RESOURCE_DELETE_CHANNEL_NAME,
|
|
358
|
+
RELATIONSHIP_SET_CHANNEL_NAME,
|
|
359
|
+
RELATIONSHIP_DELETE_CHANNEL_NAME,
|
|
361
360
|
]);
|
|
362
361
|
return new ChangeTracker(streamer, retriever);
|
|
363
362
|
}
|
|
@@ -458,10 +457,13 @@ export class DependentTracker
|
|
|
458
457
|
c.key[oppositeDirection(this.relDir)].type === this.resourceType),
|
|
459
458
|
);
|
|
460
459
|
if (sets.length === 0) return this.notify(this.dependents);
|
|
461
|
-
this.client
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
460
|
+
this.client
|
|
461
|
+
.retrieve(sets.map((s) => s.key.to))
|
|
462
|
+
.then((resources) => {
|
|
463
|
+
this.dependents = this.dependents.concat(resources);
|
|
464
|
+
this.notify(this.dependents);
|
|
465
|
+
})
|
|
466
|
+
.catch(console.error);
|
|
465
467
|
};
|
|
466
468
|
|
|
467
469
|
async close(): Promise<void> {
|
package/src/ontology/external.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
1
|
+
// Copyright 2025 Synnax Labs, Inc.
|
|
2
2
|
//
|
|
3
3
|
// Use of this software is governed by the Business Source License included in the file
|
|
4
4
|
// licenses/BSL.txt.
|
|
@@ -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
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
1
|
+
// Copyright 2025 Synnax Labs, Inc.
|
|
2
2
|
//
|
|
3
3
|
// Use of this software is governed by the Business Source License included in the file
|
|
4
4
|
// licenses/BSL.txt.
|
|
@@ -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),
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
1
|
+
// Copyright 2025 Synnax Labs, Inc.
|
|
2
2
|
//
|
|
3
3
|
// Use of this software is governed by the Business Source License included in the file
|
|
4
4
|
// licenses/BSL.txt.
|
|
@@ -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 });
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
1
|
+
// Copyright 2025 Synnax Labs, Inc.
|
|
2
2
|
//
|
|
3
3
|
// Use of this software is governed by the Business Source License included in the file
|
|
4
4
|
// licenses/BSL.txt.
|
|
@@ -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;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
1
|
+
// Copyright 2025 Synnax Labs, Inc.
|
|
2
2
|
//
|
|
3
3
|
// Use of this software is governed by the Business Source License included in the file
|
|
4
4
|
// licenses/BSL.txt.
|
|
@@ -10,42 +10,38 @@
|
|
|
10
10
|
import { sendRequired, type UnaryClient } from "@synnaxlabs/freighter";
|
|
11
11
|
import { z } from "zod";
|
|
12
12
|
|
|
13
|
-
import {
|
|
14
|
-
|
|
13
|
+
import {
|
|
14
|
+
groupZ,
|
|
15
|
+
type Key,
|
|
16
|
+
keyZ,
|
|
17
|
+
type Name,
|
|
18
|
+
nameZ,
|
|
19
|
+
type Payload,
|
|
20
|
+
} from "@/ontology/group/payload";
|
|
21
|
+
import { type ID as OntologyID, idZ as ontologyIDZ } from "@/ontology/payload";
|
|
15
22
|
|
|
16
|
-
const resZ = z.object({
|
|
17
|
-
group: groupZ,
|
|
18
|
-
});
|
|
23
|
+
const resZ = z.object({ group: groupZ });
|
|
19
24
|
|
|
20
|
-
const createReqZ = z.object({
|
|
21
|
-
parent: idZ,
|
|
22
|
-
key: z.string().uuid().optional(),
|
|
23
|
-
name: z.string(),
|
|
24
|
-
});
|
|
25
|
+
const createReqZ = z.object({ parent: ontologyIDZ, key: keyZ.optional(), name: nameZ });
|
|
25
26
|
|
|
26
|
-
const renameReqZ = z.object({
|
|
27
|
-
key: z.string(),
|
|
28
|
-
name: z.string(),
|
|
29
|
-
});
|
|
27
|
+
const renameReqZ = z.object({ key: keyZ, name: nameZ });
|
|
30
28
|
|
|
31
|
-
const deleteReqZ = z.object({
|
|
32
|
-
keys: z.array(z.string()),
|
|
33
|
-
});
|
|
29
|
+
const deleteReqZ = z.object({ keys: z.array(keyZ) });
|
|
34
30
|
|
|
35
31
|
export class Writer {
|
|
36
|
-
private static readonly
|
|
37
|
-
private static readonly
|
|
38
|
-
private static readonly
|
|
32
|
+
private static readonly CREATE_ENDPOINT = "/ontology/create-group";
|
|
33
|
+
private static readonly RENAME_ENDPOINT = "/ontology/rename-group";
|
|
34
|
+
private static readonly DELETE_ENDPOINT = "/ontology/delete-group";
|
|
39
35
|
client: UnaryClient;
|
|
40
36
|
|
|
41
37
|
constructor(client: UnaryClient) {
|
|
42
38
|
this.client = client;
|
|
43
39
|
}
|
|
44
40
|
|
|
45
|
-
async create(parent:
|
|
41
|
+
async create(parent: OntologyID, name: Name, key?: Key): Promise<Payload> {
|
|
46
42
|
const res = await sendRequired(
|
|
47
43
|
this.client,
|
|
48
|
-
Writer.
|
|
44
|
+
Writer.CREATE_ENDPOINT,
|
|
49
45
|
{ parent, name, key },
|
|
50
46
|
createReqZ,
|
|
51
47
|
resZ,
|
|
@@ -53,20 +49,20 @@ export class Writer {
|
|
|
53
49
|
return res.group;
|
|
54
50
|
}
|
|
55
51
|
|
|
56
|
-
async rename(key:
|
|
52
|
+
async rename(key: Key, name: Name): Promise<void> {
|
|
57
53
|
await sendRequired(
|
|
58
54
|
this.client,
|
|
59
|
-
Writer.
|
|
55
|
+
Writer.RENAME_ENDPOINT,
|
|
60
56
|
{ key, name },
|
|
61
57
|
renameReqZ,
|
|
62
58
|
z.object({}),
|
|
63
59
|
);
|
|
64
60
|
}
|
|
65
61
|
|
|
66
|
-
async delete(keys:
|
|
62
|
+
async delete(keys: Key[]): Promise<void> {
|
|
67
63
|
await sendRequired(
|
|
68
64
|
this.client,
|
|
69
|
-
Writer.
|
|
65
|
+
Writer.DELETE_ENDPOINT,
|
|
70
66
|
{ keys },
|
|
71
67
|
deleteReqZ,
|
|
72
68
|
z.object({}),
|
package/src/ontology/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
1
|
+
// Copyright 2025 Synnax Labs, Inc.
|
|
2
2
|
//
|
|
3
3
|
// Use of this software is governed by the Business Source License included in the file
|
|
4
4
|
// licenses/BSL.txt.
|
|
@@ -20,13 +20,13 @@ describe("Ontology", () => {
|
|
|
20
20
|
describe("retrieve", () => {
|
|
21
21
|
test("retrieve", async () => {
|
|
22
22
|
const name = randomName();
|
|
23
|
-
const g = await client.ontology.groups.create(ontology.
|
|
23
|
+
const g = await client.ontology.groups.create(ontology.ROOT_ID, name);
|
|
24
24
|
const g2 = await client.ontology.retrieve(g.ontologyID);
|
|
25
25
|
expect(g2.name).toEqual(name);
|
|
26
26
|
});
|
|
27
27
|
test("retrieve children", async () => {
|
|
28
28
|
const name = randomName();
|
|
29
|
-
const g = await client.ontology.groups.create(ontology.
|
|
29
|
+
const g = await client.ontology.groups.create(ontology.ROOT_ID, name);
|
|
30
30
|
const name2 = randomName();
|
|
31
31
|
await client.ontology.groups.create(g.ontologyID, name2);
|
|
32
32
|
const children = await client.ontology.retrieveChildren(g.ontologyID);
|
|
@@ -35,7 +35,7 @@ describe("Ontology", () => {
|
|
|
35
35
|
});
|
|
36
36
|
test("retrieve parents", async () => {
|
|
37
37
|
const name = randomName();
|
|
38
|
-
const g = await client.ontology.groups.create(ontology.
|
|
38
|
+
const g = await client.ontology.groups.create(ontology.ROOT_ID, name);
|
|
39
39
|
const name2 = randomName();
|
|
40
40
|
const g2 = await client.ontology.groups.create(g.ontologyID, name2);
|
|
41
41
|
const parents = await client.ontology.retrieveParents(g2.ontologyID);
|
|
@@ -46,7 +46,7 @@ describe("Ontology", () => {
|
|
|
46
46
|
describe("page", () => {
|
|
47
47
|
it("should return a page of resources", async () => {
|
|
48
48
|
for (let i = 0; i < 10; i++)
|
|
49
|
-
await client.ontology.groups.create(ontology.
|
|
49
|
+
await client.ontology.groups.create(ontology.ROOT_ID, randomName());
|
|
50
50
|
const page = await client.ontology.page(0, 5);
|
|
51
51
|
expect(page.length).toEqual(5);
|
|
52
52
|
const page2 = await client.ontology.page(5, 5);
|
|
@@ -60,9 +60,9 @@ describe("Ontology", () => {
|
|
|
60
60
|
describe("write", () => {
|
|
61
61
|
test("add children", async () => {
|
|
62
62
|
const name = randomName();
|
|
63
|
-
const g = await client.ontology.groups.create(ontology.
|
|
63
|
+
const g = await client.ontology.groups.create(ontology.ROOT_ID, name);
|
|
64
64
|
const name2 = randomName();
|
|
65
|
-
const g2 = await client.ontology.groups.create(ontology.
|
|
65
|
+
const g2 = await client.ontology.groups.create(ontology.ROOT_ID, name2);
|
|
66
66
|
await client.ontology.addChildren(g.ontologyID, g2.ontologyID);
|
|
67
67
|
const children = await client.ontology.retrieveChildren(g.ontologyID);
|
|
68
68
|
expect(children.length).toEqual(1);
|
|
@@ -70,9 +70,9 @@ describe("Ontology", () => {
|
|
|
70
70
|
});
|
|
71
71
|
test("remove children", async () => {
|
|
72
72
|
const name = randomName();
|
|
73
|
-
const g = await client.ontology.groups.create(ontology.
|
|
73
|
+
const g = await client.ontology.groups.create(ontology.ROOT_ID, name);
|
|
74
74
|
const name2 = randomName();
|
|
75
|
-
const g2 = await client.ontology.groups.create(ontology.
|
|
75
|
+
const g2 = await client.ontology.groups.create(ontology.ROOT_ID, name2);
|
|
76
76
|
await client.ontology.addChildren(g.ontologyID, g2.ontologyID);
|
|
77
77
|
await client.ontology.removeChildren(g.ontologyID, g2.ontologyID);
|
|
78
78
|
const children = await client.ontology.retrieveChildren(g.ontologyID);
|
|
@@ -80,15 +80,15 @@ describe("Ontology", () => {
|
|
|
80
80
|
});
|
|
81
81
|
test("move children", async () => {
|
|
82
82
|
const name = randomName();
|
|
83
|
-
const g = await client.ontology.groups.create(ontology.
|
|
83
|
+
const g = await client.ontology.groups.create(ontology.ROOT_ID, name);
|
|
84
84
|
const name2 = randomName();
|
|
85
|
-
const g2 = await client.ontology.groups.create(ontology.
|
|
86
|
-
const oldRootLength = (await client.ontology.retrieveChildren(ontology.
|
|
85
|
+
const g2 = await client.ontology.groups.create(ontology.ROOT_ID, name2);
|
|
86
|
+
const oldRootLength = (await client.ontology.retrieveChildren(ontology.ROOT_ID))
|
|
87
87
|
.length;
|
|
88
|
-
await client.ontology.moveChildren(ontology.
|
|
88
|
+
await client.ontology.moveChildren(ontology.ROOT_ID, g.ontologyID, g2.ontologyID);
|
|
89
89
|
const children = await client.ontology.retrieveChildren(g.ontologyID);
|
|
90
90
|
expect(children.length).toEqual(1);
|
|
91
|
-
const newRootLength = (await client.ontology.retrieveChildren(ontology.
|
|
91
|
+
const newRootLength = (await client.ontology.retrieveChildren(ontology.ROOT_ID))
|
|
92
92
|
.length;
|
|
93
93
|
expect(newRootLength).toEqual(oldRootLength - 1);
|
|
94
94
|
});
|
|
@@ -107,7 +107,7 @@ describe("Ontology", () => {
|
|
|
107
107
|
const p = new Promise<ontology.ResourceChange[]>((resolve) =>
|
|
108
108
|
change.resources.onChange((changes) => resolve(changes)),
|
|
109
109
|
);
|
|
110
|
-
await client.ontology.groups.create(ontology.
|
|
110
|
+
await client.ontology.groups.create(ontology.ROOT_ID, randomName());
|
|
111
111
|
const c = await p;
|
|
112
112
|
expect(c.length).toBeGreaterThan(0);
|
|
113
113
|
await change.close();
|
|
@@ -119,7 +119,7 @@ describe("Ontology", () => {
|
|
|
119
119
|
resolve(changes);
|
|
120
120
|
});
|
|
121
121
|
});
|
|
122
|
-
await client.ontology.groups.create(ontology.
|
|
122
|
+
await client.ontology.groups.create(ontology.ROOT_ID, randomName());
|
|
123
123
|
const c = await p;
|
|
124
124
|
expect(c.length).toBeGreaterThan(0);
|
|
125
125
|
await change.close();
|