@synnaxlabs/client 0.38.1 → 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 +6 -5
- 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 +3376 -3423
- 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/examples/node/basicReadWrite.js +26 -26
- package/examples/node/liveStream.js +15 -15
- package/examples/node/seriesAndFrames.js +38 -38
- package/examples/node/streamWrite.js +47 -45
- package/package.json +15 -13
- package/src/access/payload.ts +12 -12
- package/src/access/policy/client.ts +13 -12
- package/src/access/policy/external.ts +1 -0
- package/src/access/policy/ontology.ts +17 -0
- package/src/access/policy/payload.ts +7 -19
- package/src/access/policy/policy.spec.ts +16 -16
- package/src/access/policy/retriever.ts +2 -1
- package/src/access/policy/writer.ts +4 -4
- package/src/auth/auth.spec.ts +27 -23
- package/src/auth/auth.ts +7 -11
- package/src/channel/batchRetriever.spec.ts +25 -22
- package/src/channel/client.ts +19 -21
- package/src/channel/payload.ts +16 -20
- package/src/channel/retriever.ts +20 -21
- package/src/channel/writer.ts +11 -13
- package/src/client.ts +6 -16
- package/src/connection/checker.ts +9 -11
- package/src/connection/connection.spec.ts +17 -5
- package/src/control/state.ts +8 -9
- package/src/errors.spec.ts +1 -1
- package/src/errors.ts +8 -0
- package/src/framer/adapter.spec.ts +28 -23
- package/src/framer/adapter.ts +37 -41
- package/src/framer/client.spec.ts +5 -11
- package/src/framer/client.ts +34 -38
- package/src/framer/deleter.ts +5 -6
- package/src/framer/frame.ts +62 -50
- package/src/framer/iterator.ts +11 -16
- package/src/framer/streamer.spec.ts +2 -10
- package/src/framer/streamer.ts +15 -19
- package/src/framer/writer.spec.ts +48 -7
- package/src/framer/writer.ts +39 -31
- package/src/hardware/device/client.ts +64 -39
- package/src/hardware/device/device.spec.ts +49 -33
- package/src/hardware/device/payload.ts +29 -29
- package/src/hardware/rack/client.ts +52 -65
- package/src/hardware/rack/payload.ts +9 -18
- package/src/hardware/rack/rack.spec.ts +12 -0
- package/src/hardware/task/client.ts +160 -131
- package/src/hardware/task/payload.ts +49 -68
- package/src/hardware/task/task.spec.ts +98 -81
- package/src/label/client.ts +12 -15
- package/src/label/payload.ts +3 -9
- package/src/label/retriever.ts +3 -7
- package/src/label/writer.ts +8 -15
- package/src/ontology/client.ts +17 -22
- package/src/ontology/group/client.ts +5 -5
- package/src/ontology/group/group.spec.ts +4 -4
- package/src/ontology/group/group.ts +10 -7
- package/src/ontology/group/payload.ts +11 -35
- package/src/ontology/group/writer.ts +22 -26
- package/src/ontology/ontology.spec.ts +15 -15
- package/src/ontology/payload.ts +67 -43
- package/src/ontology/writer.ts +16 -23
- package/src/ranger/alias.ts +25 -42
- package/src/ranger/client.ts +29 -38
- package/src/ranger/external.ts +1 -1
- package/src/ranger/kv.ts +9 -32
- package/src/ranger/payload.ts +14 -36
- package/src/ranger/ranger.spec.ts +1 -2
- package/src/ranger/writer.ts +8 -26
- package/src/signals/observable.ts +3 -4
- package/src/user/client.ts +8 -4
- package/src/user/payload.ts +5 -9
- package/src/user/retriever.ts +1 -1
- package/src/user/user.spec.ts +17 -15
- package/src/user/writer.ts +3 -10
- package/src/util/decodeJSONString.ts +13 -0
- package/src/util/parseWithoutKeyConversion.ts +19 -0
- package/src/util/retrieve.spec.ts +3 -13
- package/src/util/retrieve.ts +2 -12
- package/src/util/telem.ts +1 -1
- package/src/vite-env.d.ts +1 -0
- package/src/workspace/client.ts +30 -57
- package/src/workspace/external.ts +11 -0
- package/src/workspace/index.ts +1 -1
- package/src/workspace/lineplot/client.ts +22 -36
- package/src/workspace/lineplot/external.ts +11 -0
- package/src/workspace/lineplot/index.ts +1 -1
- package/src/workspace/lineplot/linePlot.spec.ts +1 -2
- package/src/workspace/lineplot/payload.ts +32 -0
- package/src/workspace/log/client.ts +25 -39
- package/src/workspace/log/external.ts +11 -0
- package/src/workspace/log/index.ts +1 -1
- package/src/workspace/log/log.spec.ts +5 -18
- package/src/workspace/log/payload.ts +32 -0
- package/src/workspace/payload.ts +36 -0
- package/src/workspace/schematic/client.ts +30 -56
- package/src/workspace/schematic/external.ts +11 -0
- package/src/workspace/schematic/index.ts +1 -1
- package/src/workspace/schematic/payload.ts +37 -0
- package/src/workspace/schematic/schematic.spec.ts +15 -6
- package/src/workspace/table/client.ts +27 -50
- package/src/workspace/table/external.ts +11 -0
- package/src/workspace/table/index.ts +1 -1
- package/src/workspace/table/payload.ts +36 -0
- package/src/workspace/workspace.spec.ts +1 -2
- 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/channel/writer.ts
CHANGED
|
@@ -11,36 +11,34 @@ import { sendRequired, type UnaryClient } from "@synnaxlabs/freighter";
|
|
|
11
11
|
import { z } from "zod";
|
|
12
12
|
|
|
13
13
|
import {
|
|
14
|
+
channelZ,
|
|
14
15
|
type Key,
|
|
15
16
|
keyZ,
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
nameZ,
|
|
18
|
+
type New,
|
|
19
|
+
newZ,
|
|
18
20
|
type Payload,
|
|
19
|
-
payload,
|
|
20
21
|
} from "@/channel/payload";
|
|
21
22
|
import { type CacheRetriever } from "@/channel/retriever";
|
|
22
23
|
|
|
23
|
-
const createReqZ = z.object({ channels:
|
|
24
|
-
const createResZ = z.object({ channels:
|
|
24
|
+
const createReqZ = z.object({ channels: newZ.array() });
|
|
25
|
+
const createResZ = z.object({ channels: channelZ.array() });
|
|
25
26
|
|
|
26
27
|
const deleteReqZ = z.object({
|
|
27
28
|
keys: keyZ.array().optional(),
|
|
28
|
-
names:
|
|
29
|
+
names: nameZ.array().optional(),
|
|
29
30
|
});
|
|
30
31
|
const deleteResZ = z.object({});
|
|
31
32
|
|
|
32
|
-
const renameReqZ = z.object({
|
|
33
|
-
keys: keyZ.array(),
|
|
34
|
-
names: z.string().array(),
|
|
35
|
-
});
|
|
33
|
+
const renameReqZ = z.object({ keys: keyZ.array(), names: nameZ.array() });
|
|
36
34
|
const renameResZ = z.object({});
|
|
37
35
|
|
|
38
36
|
const CREATE_ENDPOINT = "/channel/create";
|
|
39
37
|
const DELETE_ENDPOINT = "/channel/delete";
|
|
40
38
|
const RENAME_ENDPOINT = "/channel/rename";
|
|
41
39
|
|
|
42
|
-
export
|
|
43
|
-
export
|
|
40
|
+
export interface DeleteProps extends z.input<typeof deleteReqZ> {}
|
|
41
|
+
export interface RenameProps extends z.input<typeof renameReqZ> {}
|
|
44
42
|
|
|
45
43
|
export class Writer {
|
|
46
44
|
private readonly client: UnaryClient;
|
|
@@ -51,7 +49,7 @@ export class Writer {
|
|
|
51
49
|
this.cache = cache;
|
|
52
50
|
}
|
|
53
51
|
|
|
54
|
-
async create(channels:
|
|
52
|
+
async create(channels: New[]): Promise<Payload[]> {
|
|
55
53
|
const { channels: created } = await sendRequired<
|
|
56
54
|
typeof createReqZ,
|
|
57
55
|
typeof createResZ
|
package/src/client.ts
CHANGED
|
@@ -31,20 +31,10 @@ import { user } from "@/user";
|
|
|
31
31
|
import { workspace } from "@/workspace";
|
|
32
32
|
|
|
33
33
|
export const synnaxPropsZ = z.object({
|
|
34
|
-
host: z
|
|
35
|
-
.string({
|
|
36
|
-
required_error: "Host is required",
|
|
37
|
-
})
|
|
38
|
-
.min(1, "Host is required"),
|
|
34
|
+
host: z.string({ required_error: "Host is required" }).min(1, "Host is required"),
|
|
39
35
|
port: z
|
|
40
|
-
.number({
|
|
41
|
-
|
|
42
|
-
})
|
|
43
|
-
.or(
|
|
44
|
-
z.string({
|
|
45
|
-
required_error: "Port is required",
|
|
46
|
-
}),
|
|
47
|
-
),
|
|
36
|
+
.number({ required_error: "Port is required" })
|
|
37
|
+
.or(z.string({ required_error: "Port is required" })),
|
|
48
38
|
username: z.string().min(1, "Username is required"),
|
|
49
39
|
password: z.string().min(1, "Password is required"),
|
|
50
40
|
connectivityPollFrequency: TimeSpan.z.default(TimeSpan.seconds(30)),
|
|
@@ -53,8 +43,8 @@ export const synnaxPropsZ = z.object({
|
|
|
53
43
|
retry: breaker.breakerConfig.optional(),
|
|
54
44
|
});
|
|
55
45
|
|
|
56
|
-
export
|
|
57
|
-
export
|
|
46
|
+
export interface SynnaxProps extends z.input<typeof synnaxPropsZ> {}
|
|
47
|
+
export interface ParsedSynnaxProps extends z.output<typeof synnaxPropsZ> {}
|
|
58
48
|
|
|
59
49
|
/**
|
|
60
50
|
* Client to perform operations against a Synnax cluster.
|
|
@@ -161,7 +151,7 @@ export default class Synnax extends framer.Client {
|
|
|
161
151
|
this.ontology,
|
|
162
152
|
this.ranges,
|
|
163
153
|
);
|
|
164
|
-
const racks = new rack.Client(this.transport.unary,
|
|
154
|
+
const racks = new rack.Client(this.transport.unary, tasks);
|
|
165
155
|
this.hardware = new hardware.Client(tasks, racks, devices);
|
|
166
156
|
}
|
|
167
157
|
|
|
@@ -12,12 +12,11 @@ import { migrate } from "@synnaxlabs/x";
|
|
|
12
12
|
import { TimeSpan } from "@synnaxlabs/x/telem";
|
|
13
13
|
import { z } from "zod";
|
|
14
14
|
|
|
15
|
-
const
|
|
16
|
-
export
|
|
17
|
-
export type Status = z.infer<typeof status>;
|
|
15
|
+
export const statusZ = z.enum(["disconnected", "connecting", "connected", "failed"]);
|
|
16
|
+
export type Status = z.infer<typeof statusZ>;
|
|
18
17
|
|
|
19
|
-
export const
|
|
20
|
-
status,
|
|
18
|
+
export const stateZ = z.object({
|
|
19
|
+
status: statusZ,
|
|
21
20
|
error: z.instanceof(Error).optional(),
|
|
22
21
|
message: z.string().optional(),
|
|
23
22
|
clusterKey: z.string(),
|
|
@@ -25,8 +24,7 @@ export const state = z.object({
|
|
|
25
24
|
clientServerCompatible: z.boolean(),
|
|
26
25
|
nodeVersion: z.string().optional(),
|
|
27
26
|
});
|
|
28
|
-
|
|
29
|
-
export type State = z.infer<typeof state>;
|
|
27
|
+
export interface State extends z.infer<typeof stateZ> {}
|
|
30
28
|
|
|
31
29
|
const responseZ = z.object({
|
|
32
30
|
clusterKey: z.string(),
|
|
@@ -42,7 +40,7 @@ const DEFAULT: State = {
|
|
|
42
40
|
clientVersion: __VERSION__,
|
|
43
41
|
};
|
|
44
42
|
|
|
45
|
-
const
|
|
43
|
+
const createWarning = (
|
|
46
44
|
nodeVersion: string | null,
|
|
47
45
|
clientVersion: string,
|
|
48
46
|
clientIsNewer: boolean,
|
|
@@ -64,7 +62,7 @@ export class Checker {
|
|
|
64
62
|
private interval?: NodeJS.Timeout;
|
|
65
63
|
private readonly clientVersion: string;
|
|
66
64
|
private readonly onChangeHandlers: Array<(state: State) => void> = [];
|
|
67
|
-
static readonly connectionStateZ =
|
|
65
|
+
static readonly connectionStateZ = stateZ;
|
|
68
66
|
private versionWarned = false;
|
|
69
67
|
|
|
70
68
|
/**
|
|
@@ -112,7 +110,7 @@ export class Checker {
|
|
|
112
110
|
if (nodeVersion == null) {
|
|
113
111
|
this._state.clientServerCompatible = false;
|
|
114
112
|
if (!warned) {
|
|
115
|
-
console.warn(
|
|
113
|
+
console.warn(createWarning(null, clientVersion, true));
|
|
116
114
|
this.versionWarned = true;
|
|
117
115
|
}
|
|
118
116
|
} else if (
|
|
@@ -125,7 +123,7 @@ export class Checker {
|
|
|
125
123
|
this._state.clientServerCompatible = false;
|
|
126
124
|
if (!warned) {
|
|
127
125
|
console.warn(
|
|
128
|
-
|
|
126
|
+
createWarning(
|
|
129
127
|
nodeVersion,
|
|
130
128
|
clientVersion,
|
|
131
129
|
migrate.semVerNewer(clientVersion, nodeVersion),
|
|
@@ -12,7 +12,7 @@ import { describe, expect, it } from "vitest";
|
|
|
12
12
|
import { z } from "zod";
|
|
13
13
|
|
|
14
14
|
import { auth } from "@/auth";
|
|
15
|
-
import {
|
|
15
|
+
import { connection } from "@/connection";
|
|
16
16
|
import { HOST, PORT } from "@/setupspecs";
|
|
17
17
|
import { Transport } from "@/transport";
|
|
18
18
|
|
|
@@ -24,7 +24,11 @@ describe("connectivity", () => {
|
|
|
24
24
|
password: "seldon",
|
|
25
25
|
});
|
|
26
26
|
transport.use(client.middleware());
|
|
27
|
-
const connectivity = new Checker(
|
|
27
|
+
const connectivity = new connection.Checker(
|
|
28
|
+
transport.unary,
|
|
29
|
+
undefined,
|
|
30
|
+
__VERSION__,
|
|
31
|
+
);
|
|
28
32
|
const state = await connectivity.check();
|
|
29
33
|
expect(state.status).toEqual("connected");
|
|
30
34
|
expect(z.string().uuid().safeParse(state.clusterKey).success).toBe(true);
|
|
@@ -37,7 +41,11 @@ describe("connectivity", () => {
|
|
|
37
41
|
password: "seldon",
|
|
38
42
|
});
|
|
39
43
|
transport.use(client.middleware());
|
|
40
|
-
const connectivity = new Checker(
|
|
44
|
+
const connectivity = new connection.Checker(
|
|
45
|
+
transport.unary,
|
|
46
|
+
undefined,
|
|
47
|
+
__VERSION__,
|
|
48
|
+
);
|
|
41
49
|
const state = await connectivity.check();
|
|
42
50
|
expect(state.clientServerCompatible).toBe(true);
|
|
43
51
|
expect(state.clientVersion).toBe(__VERSION__);
|
|
@@ -49,7 +57,11 @@ describe("connectivity", () => {
|
|
|
49
57
|
password: "seldon",
|
|
50
58
|
});
|
|
51
59
|
transport.use(client.middleware());
|
|
52
|
-
const connectivity = new Checker(
|
|
60
|
+
const connectivity = new connection.Checker(
|
|
61
|
+
transport.unary,
|
|
62
|
+
undefined,
|
|
63
|
+
"50000.0.0",
|
|
64
|
+
);
|
|
53
65
|
const state = await connectivity.check();
|
|
54
66
|
expect(state.clientServerCompatible).toBe(false);
|
|
55
67
|
expect(state.clientVersion).toBe("50000.0.0");
|
|
@@ -61,7 +73,7 @@ describe("connectivity", () => {
|
|
|
61
73
|
password: "seldon",
|
|
62
74
|
});
|
|
63
75
|
transport.use(client.middleware());
|
|
64
|
-
const connectivity = new Checker(transport.unary, undefined, "0.0.0");
|
|
76
|
+
const connectivity = new connection.Checker(transport.unary, undefined, "0.0.0");
|
|
65
77
|
const state = await connectivity.check();
|
|
66
78
|
expect(state.clientServerCompatible).toBe(false);
|
|
67
79
|
expect(state.clientVersion).toBe("0.0.0");
|
package/src/control/state.ts
CHANGED
|
@@ -12,15 +12,14 @@ import { binary } from "@synnaxlabs/x/binary";
|
|
|
12
12
|
import { type observe } from "@synnaxlabs/x/observe";
|
|
13
13
|
import { z } from "zod";
|
|
14
14
|
|
|
15
|
-
import { type
|
|
15
|
+
import { type channel } from "@/channel";
|
|
16
16
|
import { framer } from "@/framer";
|
|
17
|
-
import { type Streamer as FrameStreamer } from "@/framer/streamer";
|
|
18
17
|
|
|
19
|
-
export
|
|
18
|
+
export interface Authority extends control.Authority {}
|
|
20
19
|
export const Authority = control.Authority;
|
|
21
|
-
export type Transfer = control.Transfer<
|
|
22
|
-
export
|
|
23
|
-
export
|
|
20
|
+
export type Transfer = control.Transfer<channel.Key>;
|
|
21
|
+
export interface State extends control.State<channel.Key> {}
|
|
22
|
+
export interface Subject extends control.Subject {}
|
|
24
23
|
export const stateZ = control.stateZ(z.number());
|
|
25
24
|
|
|
26
25
|
export const transferString = (t: Transfer): string => {
|
|
@@ -35,17 +34,17 @@ export const transferString = (t: Transfer): string => {
|
|
|
35
34
|
};
|
|
36
35
|
|
|
37
36
|
interface Update {
|
|
38
|
-
transfers: control.Transfer<
|
|
37
|
+
transfers: control.Transfer<channel.Key>[];
|
|
39
38
|
}
|
|
40
39
|
|
|
41
40
|
export class StateTracker
|
|
42
41
|
extends framer.ObservableStreamer<Transfer[]>
|
|
43
42
|
implements observe.ObservableAsyncCloseable<Transfer[]>
|
|
44
43
|
{
|
|
45
|
-
readonly states: Map<
|
|
44
|
+
readonly states: Map<channel.Key, State>;
|
|
46
45
|
private readonly codec: binary.Codec;
|
|
47
46
|
|
|
48
|
-
constructor(streamer:
|
|
47
|
+
constructor(streamer: framer.Streamer) {
|
|
49
48
|
super(streamer, (frame) => {
|
|
50
49
|
const update: Update = this.codec.decode(frame.series[0].buffer);
|
|
51
50
|
this.merge(update);
|
package/src/errors.spec.ts
CHANGED
package/src/errors.ts
CHANGED
|
@@ -64,6 +64,12 @@ export class InvalidTokenError extends AuthError {
|
|
|
64
64
|
static readonly matches = errorMatcher(InvalidTokenError.TYPE);
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
export class ExpiredTokenError extends AuthError {
|
|
68
|
+
static readonly TYPE = `${AuthError.TYPE}.expired-token`;
|
|
69
|
+
type = ExpiredTokenError.TYPE;
|
|
70
|
+
static readonly matches = errorMatcher(ExpiredTokenError.TYPE);
|
|
71
|
+
}
|
|
72
|
+
|
|
67
73
|
/**
|
|
68
74
|
* UnexpectedError is raised when an unexpected error occurs.
|
|
69
75
|
*/
|
|
@@ -154,6 +160,8 @@ const decode = (payload: ErrorPayload): Error | null => {
|
|
|
154
160
|
if (payload.type.startsWith(AuthError.TYPE)) {
|
|
155
161
|
if (payload.type.startsWith(InvalidTokenError.TYPE))
|
|
156
162
|
return new InvalidTokenError(payload.data);
|
|
163
|
+
if (payload.type.startsWith(ExpiredTokenError.TYPE))
|
|
164
|
+
return new ExpiredTokenError(payload.data);
|
|
157
165
|
return new AuthError(payload.data);
|
|
158
166
|
}
|
|
159
167
|
|
|
@@ -11,7 +11,7 @@ import { DataType, Series, TimeStamp } from "@synnaxlabs/x/telem";
|
|
|
11
11
|
import { beforeAll, describe, expect, it } from "vitest";
|
|
12
12
|
|
|
13
13
|
import { type channel } from "@/channel";
|
|
14
|
-
import {
|
|
14
|
+
import { WriteAdapter } from "@/framer/adapter";
|
|
15
15
|
import { Frame } from "@/index";
|
|
16
16
|
import { newClient } from "@/setupspecs";
|
|
17
17
|
|
|
@@ -20,7 +20,7 @@ const client = newClient();
|
|
|
20
20
|
describe("WriteFrameAdapter", () => {
|
|
21
21
|
let timeCh: channel.Channel;
|
|
22
22
|
let dataCh: channel.Channel;
|
|
23
|
-
let adapter:
|
|
23
|
+
let adapter: WriteAdapter;
|
|
24
24
|
|
|
25
25
|
beforeAll(async () => {
|
|
26
26
|
timeCh = await client.channels.create({
|
|
@@ -34,7 +34,7 @@ describe("WriteFrameAdapter", () => {
|
|
|
34
34
|
index: timeCh.key,
|
|
35
35
|
});
|
|
36
36
|
|
|
37
|
-
adapter = await
|
|
37
|
+
adapter = await WriteAdapter.open(client.channels.retriever, [
|
|
38
38
|
timeCh.key,
|
|
39
39
|
dataCh.key,
|
|
40
40
|
]);
|
|
@@ -42,10 +42,7 @@ describe("WriteFrameAdapter", () => {
|
|
|
42
42
|
|
|
43
43
|
it("should correctly adapt a record of keys to single values", async () => {
|
|
44
44
|
const ts = TimeStamp.now().valueOf();
|
|
45
|
-
const res = await adapter.adapt({
|
|
46
|
-
[timeCh.key]: ts,
|
|
47
|
-
[dataCh.key]: 1,
|
|
48
|
-
});
|
|
45
|
+
const res = await adapter.adapt({ [timeCh.key]: ts, [dataCh.key]: 1 });
|
|
49
46
|
expect(res.columns).toHaveLength(2);
|
|
50
47
|
expect(res.series).toHaveLength(2);
|
|
51
48
|
expect(res.get(timeCh.key)).toHaveLength(1);
|
|
@@ -56,10 +53,7 @@ describe("WriteFrameAdapter", () => {
|
|
|
56
53
|
|
|
57
54
|
it("should correctly adapt a record of names to single values", async () => {
|
|
58
55
|
const ts = TimeStamp.now().valueOf();
|
|
59
|
-
const res2 = await adapter.adapt({
|
|
60
|
-
[timeCh.name]: ts,
|
|
61
|
-
[dataCh.name]: 1,
|
|
62
|
-
});
|
|
56
|
+
const res2 = await adapter.adapt({ [timeCh.name]: ts, [dataCh.name]: 1 });
|
|
63
57
|
expect(res2.columns).toHaveLength(2);
|
|
64
58
|
expect(res2.series).toHaveLength(2);
|
|
65
59
|
expect(res2.get(timeCh.key)).toHaveLength(1);
|
|
@@ -103,10 +97,7 @@ describe("WriteFrameAdapter", () => {
|
|
|
103
97
|
|
|
104
98
|
it("should not modify a frame keyed by key", async () => {
|
|
105
99
|
const ts = TimeStamp.now().valueOf();
|
|
106
|
-
const fr = new Frame({
|
|
107
|
-
[timeCh.key]: new Series(ts),
|
|
108
|
-
[dataCh.key]: new Series(1),
|
|
109
|
-
});
|
|
100
|
+
const fr = new Frame({ [timeCh.key]: new Series(ts), [dataCh.key]: new Series(1) });
|
|
110
101
|
const res = await adapter.adapt(fr);
|
|
111
102
|
expect(res.columns).toHaveLength(2);
|
|
112
103
|
expect(res.series).toHaveLength(2);
|
|
@@ -131,7 +122,7 @@ describe("WriteFrameAdapter", () => {
|
|
|
131
122
|
dataType: DataType.JSON,
|
|
132
123
|
virtual: true,
|
|
133
124
|
});
|
|
134
|
-
const adapter = await
|
|
125
|
+
const adapter = await WriteAdapter.open(client.channels.retriever, [
|
|
135
126
|
jsonChannel.key,
|
|
136
127
|
]);
|
|
137
128
|
const res = await adapter.adapt(jsonChannel.name, [{ dog: "blue" }]);
|
|
@@ -147,7 +138,7 @@ describe("WriteFrameAdapter", () => {
|
|
|
147
138
|
dataType: DataType.JSON,
|
|
148
139
|
virtual: true,
|
|
149
140
|
});
|
|
150
|
-
const adapter = await
|
|
141
|
+
const adapter = await WriteAdapter.open(client.channels.retriever, [
|
|
151
142
|
jsonChannel.key,
|
|
152
143
|
]);
|
|
153
144
|
const res = await adapter.adapt(jsonChannel.name, new Series([{ dog: "blue" }]));
|
|
@@ -157,12 +148,26 @@ describe("WriteFrameAdapter", () => {
|
|
|
157
148
|
expect(res.get(jsonChannel.key).at(0)).toEqual({ dog: "blue" });
|
|
158
149
|
});
|
|
159
150
|
|
|
160
|
-
it("should correctly adapt
|
|
161
|
-
const
|
|
162
|
-
|
|
163
|
-
|
|
151
|
+
it("should correctly adapt a numeric value to a BigInt keyed by key", async () => {
|
|
152
|
+
const bigIntCh = await client.channels.create({
|
|
153
|
+
name: `bigint-${Math.random()}-${TimeStamp.now().toString()}`,
|
|
154
|
+
dataType: DataType.INT64,
|
|
155
|
+
virtual: true,
|
|
156
|
+
});
|
|
157
|
+
const res = await adapter.adapt({
|
|
158
|
+
[bigIntCh.key]: 12,
|
|
159
|
+
});
|
|
160
|
+
expect(res.get(bigIntCh.key).at(0)).toEqual(12n);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
describe("adaptObjectKeys", () => {
|
|
164
|
+
it("should correctly adapt generic object keys", async () => {
|
|
165
|
+
const res = await adapter.adaptObjectKeys({
|
|
166
|
+
[timeCh.name]: 532,
|
|
167
|
+
[dataCh.name]: 123,
|
|
168
|
+
});
|
|
169
|
+
expect(res).toHaveProperty(timeCh.key.toString());
|
|
170
|
+
expect(res).toHaveProperty(dataCh.key.toString());
|
|
164
171
|
});
|
|
165
|
-
expect(res).toHaveProperty(timeCh.key.toString());
|
|
166
|
-
expect(res).toHaveProperty(dataCh.key.toString());
|
|
167
172
|
});
|
|
168
173
|
});
|
package/src/framer/adapter.ts
CHANGED
|
@@ -9,47 +9,39 @@
|
|
|
9
9
|
|
|
10
10
|
import { type CrudeSeries, Series } from "@synnaxlabs/x/telem";
|
|
11
11
|
|
|
12
|
-
import {
|
|
13
|
-
type Key,
|
|
14
|
-
type KeyOrName,
|
|
15
|
-
type Name,
|
|
16
|
-
type Params,
|
|
17
|
-
type Payload,
|
|
18
|
-
} from "@/channel/payload";
|
|
19
|
-
import {
|
|
20
|
-
analyzeChannelParams,
|
|
21
|
-
type Retriever,
|
|
22
|
-
retrieveRequired,
|
|
23
|
-
} from "@/channel/retriever";
|
|
12
|
+
import { channel } from "@/channel";
|
|
24
13
|
import { ValidationError } from "@/errors";
|
|
25
|
-
import { type
|
|
14
|
+
import { type Crude, Frame } from "@/framer/frame";
|
|
26
15
|
|
|
27
|
-
export class
|
|
28
|
-
private adapter: Map<Key, Name> | null;
|
|
29
|
-
retriever: Retriever;
|
|
30
|
-
keys: Key[];
|
|
16
|
+
export class ReadAdapter {
|
|
17
|
+
private adapter: Map<channel.Key, channel.Name> | null;
|
|
18
|
+
retriever: channel.Retriever;
|
|
19
|
+
keys: channel.Key[];
|
|
31
20
|
|
|
32
|
-
private constructor(retriever: Retriever) {
|
|
21
|
+
private constructor(retriever: channel.Retriever) {
|
|
33
22
|
this.retriever = retriever;
|
|
34
23
|
this.adapter = null;
|
|
35
24
|
this.keys = [];
|
|
36
25
|
}
|
|
37
26
|
|
|
38
|
-
static async open(
|
|
39
|
-
|
|
27
|
+
static async open(
|
|
28
|
+
retriever: channel.Retriever,
|
|
29
|
+
channels: channel.Params,
|
|
30
|
+
): Promise<ReadAdapter> {
|
|
31
|
+
const adapter = new ReadAdapter(retriever);
|
|
40
32
|
await adapter.update(channels);
|
|
41
33
|
return adapter;
|
|
42
34
|
}
|
|
43
35
|
|
|
44
|
-
async update(channels: Params): Promise<void> {
|
|
45
|
-
const { variant, normalized } =
|
|
36
|
+
async update(channels: channel.Params): Promise<void> {
|
|
37
|
+
const { variant, normalized } = channel.analyzeParams(channels);
|
|
46
38
|
if (variant === "keys") {
|
|
47
39
|
this.adapter = null;
|
|
48
|
-
this.keys = normalized as Key[];
|
|
40
|
+
this.keys = normalized as channel.Key[];
|
|
49
41
|
return;
|
|
50
42
|
}
|
|
51
43
|
const fetched = await this.retriever.retrieve(normalized);
|
|
52
|
-
const a = new Map<Key, Name>();
|
|
44
|
+
const a = new Map<channel.Key, channel.Name>();
|
|
53
45
|
this.adapter = a;
|
|
54
46
|
normalized.forEach((name) => {
|
|
55
47
|
const channel = fetched.find((channel) => channel.name === name);
|
|
@@ -73,52 +65,56 @@ export class ReadFrameAdapter {
|
|
|
73
65
|
}
|
|
74
66
|
}
|
|
75
67
|
|
|
76
|
-
export class
|
|
77
|
-
private adapter: Map<Name, Key> | null;
|
|
78
|
-
retriever: Retriever;
|
|
79
|
-
keys: Key[];
|
|
68
|
+
export class WriteAdapter {
|
|
69
|
+
private adapter: Map<channel.Name, channel.Key> | null;
|
|
70
|
+
retriever: channel.Retriever;
|
|
71
|
+
keys: channel.Key[];
|
|
80
72
|
|
|
81
|
-
private constructor(retriever: Retriever) {
|
|
73
|
+
private constructor(retriever: channel.Retriever) {
|
|
82
74
|
this.retriever = retriever;
|
|
83
75
|
this.adapter = null;
|
|
84
76
|
this.keys = [];
|
|
85
77
|
}
|
|
86
78
|
|
|
87
79
|
static async open(
|
|
88
|
-
retriever: Retriever,
|
|
89
|
-
channels: Params,
|
|
90
|
-
): Promise<
|
|
91
|
-
const adapter = new
|
|
80
|
+
retriever: channel.Retriever,
|
|
81
|
+
channels: channel.Params,
|
|
82
|
+
): Promise<WriteAdapter> {
|
|
83
|
+
const adapter = new WriteAdapter(retriever);
|
|
92
84
|
await adapter.update(channels);
|
|
93
85
|
return adapter;
|
|
94
86
|
}
|
|
95
87
|
|
|
96
|
-
async adaptObjectKeys<V>(
|
|
97
|
-
|
|
88
|
+
async adaptObjectKeys<V>(
|
|
89
|
+
data: Record<channel.KeyOrName, V>,
|
|
90
|
+
): Promise<Record<channel.Key, V>> {
|
|
91
|
+
const out: Record<channel.Key, V> = {};
|
|
98
92
|
for (const [k, v] of Object.entries(data)) out[await this.adaptToKey(k)] = v;
|
|
99
93
|
return out;
|
|
100
94
|
}
|
|
101
95
|
|
|
102
|
-
async update(channels: Params): Promise<void> {
|
|
103
|
-
const results = await retrieveRequired(this.retriever, channels);
|
|
104
|
-
this.adapter = new Map<Name, Key>(
|
|
96
|
+
async update(channels: channel.Params): Promise<void> {
|
|
97
|
+
const results = await channel.retrieveRequired(this.retriever, channels);
|
|
98
|
+
this.adapter = new Map<channel.Name, channel.Key>(
|
|
99
|
+
results.map((c) => [c.name, c.key]),
|
|
100
|
+
);
|
|
105
101
|
this.keys = results.map((c) => c.key);
|
|
106
102
|
}
|
|
107
103
|
|
|
108
|
-
private async fetchChannel(ch: Key | Name): Promise<Payload> {
|
|
104
|
+
private async fetchChannel(ch: channel.Key | channel.Name): Promise<channel.Payload> {
|
|
109
105
|
const res = await this.retriever.retrieve(ch);
|
|
110
106
|
if (res.length === 0) throw new Error(`Channel ${ch} not found`);
|
|
111
107
|
return res[0];
|
|
112
108
|
}
|
|
113
109
|
|
|
114
|
-
private async adaptToKey(k: KeyOrName): Promise<Key> {
|
|
110
|
+
private async adaptToKey(k: channel.KeyOrName): Promise<channel.Key> {
|
|
115
111
|
if (typeof k === "number") return k;
|
|
116
112
|
const res = await this.fetchChannel(k);
|
|
117
113
|
return res.key;
|
|
118
114
|
}
|
|
119
115
|
|
|
120
116
|
async adapt(
|
|
121
|
-
columnsOrData: Params | Record<KeyOrName, CrudeSeries> |
|
|
117
|
+
columnsOrData: channel.Params | Record<channel.KeyOrName, CrudeSeries> | Crude,
|
|
122
118
|
series?: CrudeSeries | CrudeSeries[],
|
|
123
119
|
): Promise<Frame> {
|
|
124
120
|
if (typeof columnsOrData === "string" || typeof columnsOrData === "number") {
|
|
@@ -29,17 +29,11 @@ describe("Client", () => {
|
|
|
29
29
|
index: time.key,
|
|
30
30
|
});
|
|
31
31
|
const start = TimeStamp.now();
|
|
32
|
-
await client.write(start, {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
{
|
|
38
|
-
start,
|
|
39
|
-
end: start.add(TimeSpan.seconds(1)),
|
|
40
|
-
},
|
|
41
|
-
[time.key, data.key],
|
|
42
|
-
);
|
|
32
|
+
await client.write(start, { [time.key]: [start], [data.key]: [1] });
|
|
33
|
+
const frame = await client.read({ start, end: start.add(TimeSpan.seconds(1)) }, [
|
|
34
|
+
time.key,
|
|
35
|
+
data.key,
|
|
36
|
+
]);
|
|
43
37
|
expect(Array.from(frame.get(time.key))).toEqual([start.valueOf()]);
|
|
44
38
|
expect(Array.from(frame.get(data.key))).toEqual([1]);
|
|
45
39
|
});
|