@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
|
@@ -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,108 +10,89 @@
|
|
|
10
10
|
import { binary, type observe, type UnknownRecord } from "@synnaxlabs/x";
|
|
11
11
|
import { z } from "zod";
|
|
12
12
|
|
|
13
|
-
import {
|
|
13
|
+
import { type Key as RackKey } from "@/hardware/rack/payload";
|
|
14
|
+
import { decodeJSONString } from "@/util/decodeJSONString";
|
|
15
|
+
import { parseWithoutKeyConversion } from "@/util/parseWithoutKeyConversion";
|
|
14
16
|
|
|
15
|
-
export const
|
|
17
|
+
export const keyZ = z.union([
|
|
16
18
|
z.string(),
|
|
17
19
|
z.bigint().transform((k) => k.toString()),
|
|
18
20
|
z.number().transform((k) => k.toString()),
|
|
19
21
|
]);
|
|
22
|
+
export type Key = z.infer<typeof keyZ>;
|
|
20
23
|
|
|
21
|
-
export
|
|
24
|
+
export const statusZ = z.enum(["info", "success", "error", "warning"]);
|
|
25
|
+
export type Status = z.infer<typeof statusZ>;
|
|
22
26
|
|
|
23
27
|
export const stateZ = z.object({
|
|
24
|
-
task:
|
|
25
|
-
variant:
|
|
28
|
+
task: keyZ,
|
|
29
|
+
variant: statusZ,
|
|
26
30
|
key: z.string().optional(),
|
|
27
31
|
details: z
|
|
28
32
|
.record(z.unknown())
|
|
29
|
-
.or(
|
|
30
|
-
z.string().transform((c) => {
|
|
31
|
-
if (c === "") return {};
|
|
32
|
-
return JSON.parse(c);
|
|
33
|
-
}),
|
|
34
|
-
)
|
|
33
|
+
.or(z.string().transform(parseWithoutKeyConversion))
|
|
35
34
|
.or(z.array(z.unknown()))
|
|
36
|
-
.or(z.null())
|
|
35
|
+
.or(z.null()) as z.ZodType<UnknownRecord | undefined>,
|
|
37
36
|
});
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
> & {
|
|
43
|
-
details?: D;
|
|
44
|
-
};
|
|
37
|
+
export interface State<Details extends {} = UnknownRecord>
|
|
38
|
+
extends Omit<z.infer<typeof stateZ>, "details"> {
|
|
39
|
+
details?: Details;
|
|
40
|
+
}
|
|
45
41
|
|
|
46
42
|
export const taskZ = z.object({
|
|
47
|
-
key:
|
|
43
|
+
key: keyZ,
|
|
48
44
|
name: z.string(),
|
|
49
45
|
type: z.string(),
|
|
50
46
|
internal: z.boolean().optional(),
|
|
51
|
-
config: z.record(z.unknown()).or(
|
|
52
|
-
z.string().transform((c) => {
|
|
53
|
-
if (c === "") return {};
|
|
54
|
-
return binary.JSON_CODEC.decodeString(c);
|
|
55
|
-
}),
|
|
56
|
-
) as z.ZodType<UnknownRecord>,
|
|
47
|
+
config: z.record(z.unknown()).or(z.string().transform(decodeJSONString)),
|
|
57
48
|
state: stateZ.optional().nullable(),
|
|
58
49
|
snapshot: z.boolean().optional(),
|
|
59
50
|
});
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
51
|
+
export interface Payload<
|
|
52
|
+
Config extends UnknownRecord = UnknownRecord,
|
|
53
|
+
Details extends {} = UnknownRecord,
|
|
54
|
+
Type extends string = string,
|
|
55
|
+
> extends Omit<z.output<typeof taskZ>, "config" | "type" | "state"> {
|
|
56
|
+
type: Type;
|
|
57
|
+
config: Config;
|
|
58
|
+
state?: State<Details> | null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export const newZ = taskZ.omit({ key: true }).extend({
|
|
62
|
+
key: keyZ.transform((k) => k.toString()).optional(),
|
|
63
63
|
config: z.unknown().transform((c) => binary.JSON_CODEC.encodeString(c)),
|
|
64
64
|
});
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
export type Payload<
|
|
75
|
-
C extends UnknownRecord = UnknownRecord,
|
|
76
|
-
D extends {} = UnknownRecord,
|
|
77
|
-
T extends string = string,
|
|
78
|
-
> = Omit<z.output<typeof taskZ>, "config" | "type" | "state"> & {
|
|
79
|
-
type: T;
|
|
80
|
-
config: C;
|
|
81
|
-
state?: State<D> | null;
|
|
82
|
-
};
|
|
65
|
+
export interface New<
|
|
66
|
+
Config extends UnknownRecord = UnknownRecord,
|
|
67
|
+
Type extends string = string,
|
|
68
|
+
> extends Omit<z.input<typeof newZ>, "config" | "state"> {
|
|
69
|
+
type: Type;
|
|
70
|
+
config: Config;
|
|
71
|
+
}
|
|
83
72
|
|
|
84
73
|
export const commandZ = z.object({
|
|
85
|
-
task:
|
|
74
|
+
task: keyZ,
|
|
86
75
|
type: z.string(),
|
|
87
76
|
key: z.string(),
|
|
88
77
|
args: z
|
|
89
78
|
.record(z.unknown())
|
|
90
|
-
.or(
|
|
91
|
-
z.string().transform((c) => {
|
|
92
|
-
if (c === "") return {};
|
|
93
|
-
return JSON.parse(c);
|
|
94
|
-
}),
|
|
95
|
-
)
|
|
79
|
+
.or(z.string().transform(parseWithoutKeyConversion))
|
|
96
80
|
.or(z.array(z.unknown()))
|
|
97
81
|
.or(z.null())
|
|
98
82
|
.optional() as z.ZodOptional<z.ZodType<UnknownRecord>>,
|
|
99
83
|
});
|
|
84
|
+
export interface Command<Args extends {} = UnknownRecord>
|
|
85
|
+
extends Omit<z.infer<typeof commandZ>, "args"> {
|
|
86
|
+
args?: Args;
|
|
87
|
+
}
|
|
100
88
|
|
|
101
|
-
export
|
|
102
|
-
|
|
103
|
-
"args"
|
|
104
|
-
> & {
|
|
105
|
-
args?: A;
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
export type StateObservable<D extends UnknownRecord = UnknownRecord> =
|
|
109
|
-
observe.ObservableAsyncCloseable<State<D>>;
|
|
89
|
+
export interface StateObservable<Details extends {} = UnknownRecord>
|
|
90
|
+
extends observe.ObservableAsyncCloseable<State<Details>> {}
|
|
110
91
|
|
|
111
|
-
export
|
|
112
|
-
observe.ObservableAsyncCloseable<Command<
|
|
92
|
+
export interface CommandObservable<Args extends {} = UnknownRecord>
|
|
93
|
+
extends observe.ObservableAsyncCloseable<Command<Args>> {}
|
|
113
94
|
|
|
114
|
-
export const ONTOLOGY_TYPE
|
|
95
|
+
export const ONTOLOGY_TYPE = "task";
|
|
96
|
+
export type OntologyType = typeof ONTOLOGY_TYPE;
|
|
115
97
|
|
|
116
|
-
export const
|
|
117
|
-
new ontology.ID({ type: ONTOLOGY_TYPE, key: key.toString() });
|
|
98
|
+
export const getRackKey = (key: Key): RackKey => Number(BigInt(key) >> 32n);
|
|
@@ -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.
|
|
@@ -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/index.ts
CHANGED
package/src/label/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.
|
|
@@ -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/external.ts
CHANGED
package/src/label/index.ts
CHANGED
package/src/label/label.spec.ts
CHANGED
package/src/label/payload.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,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
|
@@ -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.
|
|
@@ -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
|
@@ -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.
|
|
@@ -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,
|