@synnaxlabs/client 0.33.0 → 0.34.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 +6 -6
- package/dist/auth/auth.d.ts.map +1 -1
- package/dist/channel/writer.d.ts.map +1 -1
- package/dist/client.cjs +26 -26
- package/dist/client.js +235 -190
- package/dist/control/client.d.ts.map +1 -1
- package/dist/control/state.d.ts.map +1 -1
- package/dist/errors.d.ts +3 -3
- package/dist/errors.d.ts.map +1 -1
- package/dist/framer/adapter.d.ts.map +1 -1
- package/dist/framer/client.d.ts.map +1 -1
- package/dist/framer/deleter.d.ts.map +1 -1
- package/dist/framer/frame.d.ts.map +1 -1
- package/dist/framer/writer.d.ts.map +1 -1
- package/dist/hardware/device/client.d.ts.map +1 -1
- package/dist/hardware/device/payload.d.ts.map +1 -1
- package/dist/hardware/rack/client.d.ts.map +1 -1
- package/dist/hardware/task/client.d.ts +1 -1
- package/dist/hardware/task/client.d.ts.map +1 -1
- package/dist/hardware/task/ni/types.d.ts.map +1 -1
- package/dist/hardware/task/payload.d.ts.map +1 -1
- package/dist/label/client.d.ts.map +1 -1
- package/dist/ontology/client.d.ts.map +1 -1
- package/dist/ontology/payload.d.ts.map +1 -1
- package/dist/ranger/alias.d.ts.map +1 -1
- package/dist/ranger/client.d.ts.map +1 -1
- package/dist/ranger/kv.d.ts.map +1 -1
- package/dist/ranger/payload.d.ts.map +1 -1
- package/dist/util/telem.d.ts.map +1 -1
- package/dist/workspace/lineplot/payload.d.ts.map +1 -1
- package/dist/workspace/log/payload.d.ts.map +1 -1
- package/dist/workspace/payload.d.ts.map +1 -1
- package/dist/workspace/schematic/payload.d.ts.map +1 -1
- package/eslint.config.js +1 -1
- package/package.json +11 -11
- package/src/access/policy/policy.spec.ts +2 -4
- package/src/auth/auth.spec.ts +1 -1
- package/src/auth/auth.ts +17 -18
- package/src/channel/writer.ts +2 -2
- package/src/connection/checker.ts +1 -1
- package/src/control/client.ts +1 -1
- package/src/control/state.ts +1 -1
- package/src/errors.spec.ts +1 -1
- package/src/errors.ts +14 -15
- package/src/framer/adapter.ts +5 -6
- package/src/framer/client.ts +9 -4
- package/src/framer/deleter.ts +1 -1
- package/src/framer/frame.ts +9 -11
- package/src/framer/iterator.spec.ts +2 -3
- package/src/framer/writer.ts +1 -1
- package/src/hardware/device/client.ts +3 -3
- package/src/hardware/device/payload.ts +1 -1
- package/src/hardware/rack/client.ts +3 -3
- package/src/hardware/task/client.ts +13 -11
- package/src/hardware/task/ni/types.ts +1 -1
- package/src/hardware/task/payload.ts +1 -1
- package/src/hardware/task/task.spec.ts +1 -1
- package/src/label/client.ts +1 -1
- package/src/ontology/client.ts +1 -3
- package/src/ontology/group/payload.ts +2 -2
- package/src/ontology/payload.ts +1 -1
- package/src/ranger/alias.ts +2 -3
- package/src/ranger/client.ts +7 -9
- package/src/ranger/kv.ts +2 -2
- package/src/ranger/payload.ts +2 -2
- package/src/ranger/ranger.spec.ts +2 -2
- package/src/user/user.spec.ts +1 -2
- package/src/util/telem.ts +1 -3
- package/src/workspace/lineplot/payload.ts +1 -1
- package/src/workspace/log/payload.ts +1 -1
- package/src/workspace/payload.ts +1 -1
- package/src/workspace/schematic/payload.ts +1 -1
package/src/auth/auth.ts
CHANGED
|
@@ -72,24 +72,23 @@ export class Client {
|
|
|
72
72
|
middleware(): Middleware {
|
|
73
73
|
const mw: Middleware = async (reqCtx, next) => {
|
|
74
74
|
if (!this.authenticated && !reqCtx.target.endsWith(LOGIN_ENDPOINT)) {
|
|
75
|
-
|
|
76
|
-
this.
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
});
|
|
75
|
+
this.authenticating ??= new Promise((resolve, reject) => {
|
|
76
|
+
this.client
|
|
77
|
+
.send(
|
|
78
|
+
LOGIN_ENDPOINT,
|
|
79
|
+
this.credentials,
|
|
80
|
+
insecureCredentialsZ,
|
|
81
|
+
tokenResponseZ,
|
|
82
|
+
)
|
|
83
|
+
.then(([res, err]) => {
|
|
84
|
+
if (err != null) return resolve(err);
|
|
85
|
+
this.token = res?.token;
|
|
86
|
+
this.user = res?.user;
|
|
87
|
+
this.authenticated = true;
|
|
88
|
+
resolve(null);
|
|
89
|
+
})
|
|
90
|
+
.catch(reject);
|
|
91
|
+
});
|
|
93
92
|
const err = await this.authenticating;
|
|
94
93
|
if (err != null) return [reqCtx, err];
|
|
95
94
|
}
|
package/src/channel/writer.ts
CHANGED
|
@@ -11,14 +11,14 @@ import { sendRequired, type UnaryClient } from "@synnaxlabs/freighter";
|
|
|
11
11
|
import { z } from "zod";
|
|
12
12
|
|
|
13
13
|
import {
|
|
14
|
-
Key,
|
|
14
|
+
type Key,
|
|
15
15
|
keyZ,
|
|
16
16
|
type NewPayload,
|
|
17
17
|
newPayload,
|
|
18
18
|
type Payload,
|
|
19
19
|
payload,
|
|
20
20
|
} from "@/channel/payload";
|
|
21
|
-
import { CacheRetriever } from "@/channel/retriever";
|
|
21
|
+
import { type CacheRetriever } from "@/channel/retriever";
|
|
22
22
|
|
|
23
23
|
const createReqZ = z.object({ channels: newPayload.array() });
|
|
24
24
|
const createResZ = z.object({ channels: payload.array() });
|
|
@@ -48,7 +48,7 @@ const generateWarning = (
|
|
|
48
48
|
clientIsNewer: boolean,
|
|
49
49
|
): string => {
|
|
50
50
|
const toUpgrade = clientIsNewer ? "cluster" : "client";
|
|
51
|
-
return `Synnax cluster node version ${nodeVersion != null ? nodeVersion
|
|
51
|
+
return `Synnax cluster node version ${nodeVersion != null ? `${nodeVersion} ` : ""}is too ${clientIsNewer ? "old" : "new"} for client version ${clientVersion}.
|
|
52
52
|
This may cause compatibility issues. We recommend updating the ${toUpgrade}. For more information, see
|
|
53
53
|
https://docs.synnaxlabs.com/reference/typescript-client/troubleshooting#old-${toUpgrade}-version`;
|
|
54
54
|
};
|
package/src/control/client.ts
CHANGED
package/src/control/state.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
import { control } from "@synnaxlabs/x";
|
|
11
11
|
import { binary } from "@synnaxlabs/x/binary";
|
|
12
|
-
import { observe } from "@synnaxlabs/x/observe";
|
|
12
|
+
import { type observe } from "@synnaxlabs/x/observe";
|
|
13
13
|
import { z } from "zod";
|
|
14
14
|
|
|
15
15
|
import { type Key as ChannelKey } from "@/channel/payload";
|
package/src/errors.spec.ts
CHANGED
|
@@ -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 { MatchableErrorType } from "@synnaxlabs/freighter/src/errors";
|
|
10
|
+
import { type MatchableErrorType } from "@synnaxlabs/freighter/src/errors";
|
|
11
11
|
import { id } from "@synnaxlabs/x";
|
|
12
12
|
import { v4 as uuid } from "uuid";
|
|
13
13
|
import { describe, expect, test } from "vitest";
|
package/src/errors.ts
CHANGED
|
@@ -27,20 +27,20 @@ export interface Field {
|
|
|
27
27
|
* Raised when a validation error occurs.
|
|
28
28
|
*/
|
|
29
29
|
export class ValidationError extends BaseTypedError {
|
|
30
|
-
static readonly TYPE = _FREIGHTER_EXCEPTION_PREFIX
|
|
30
|
+
static readonly TYPE: string = `${_FREIGHTER_EXCEPTION_PREFIX}validation`;
|
|
31
31
|
type = ValidationError.TYPE;
|
|
32
32
|
static readonly matches = errorMatcher(ValidationError.TYPE);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
export class FieldError extends ValidationError {
|
|
36
|
-
static readonly TYPE = ValidationError.TYPE
|
|
36
|
+
static readonly TYPE = `${ValidationError.TYPE}.field`;
|
|
37
37
|
type = FieldError.TYPE;
|
|
38
38
|
static readonly matches = errorMatcher(FieldError.TYPE);
|
|
39
39
|
readonly field: string;
|
|
40
40
|
readonly message: string;
|
|
41
41
|
|
|
42
42
|
constructor(field: string, message: string) {
|
|
43
|
-
super(field
|
|
43
|
+
super(`${field}: ${message}`);
|
|
44
44
|
this.field = field;
|
|
45
45
|
this.message = message;
|
|
46
46
|
}
|
|
@@ -50,7 +50,7 @@ export class FieldError extends ValidationError {
|
|
|
50
50
|
* AuthError is raised when an authentication error occurs.
|
|
51
51
|
*/
|
|
52
52
|
export class AuthError extends BaseTypedError {
|
|
53
|
-
static readonly TYPE = _FREIGHTER_EXCEPTION_PREFIX
|
|
53
|
+
static readonly TYPE: string = `${_FREIGHTER_EXCEPTION_PREFIX}auth`;
|
|
54
54
|
type = AuthError.TYPE;
|
|
55
55
|
static readonly matches = errorMatcher(AuthError.TYPE);
|
|
56
56
|
}
|
|
@@ -59,7 +59,7 @@ export class AuthError extends BaseTypedError {
|
|
|
59
59
|
* InvalidTokenError is raised when an authentication token is invalid.
|
|
60
60
|
*/
|
|
61
61
|
export class InvalidTokenError extends AuthError {
|
|
62
|
-
static readonly TYPE = AuthError.TYPE
|
|
62
|
+
static readonly TYPE = `${AuthError.TYPE}.invalid-token`;
|
|
63
63
|
type = InvalidTokenError.TYPE;
|
|
64
64
|
static readonly matches = errorMatcher(InvalidTokenError.TYPE);
|
|
65
65
|
}
|
|
@@ -68,7 +68,7 @@ export class InvalidTokenError extends AuthError {
|
|
|
68
68
|
* UnexpectedError is raised when an unexpected error occurs.
|
|
69
69
|
*/
|
|
70
70
|
export class UnexpectedError extends BaseTypedError {
|
|
71
|
-
static readonly TYPE = _FREIGHTER_EXCEPTION_PREFIX
|
|
71
|
+
static readonly TYPE = `${_FREIGHTER_EXCEPTION_PREFIX}unexpected`;
|
|
72
72
|
type = UnexpectedError.TYPE;
|
|
73
73
|
static readonly matches = errorMatcher(UnexpectedError.TYPE);
|
|
74
74
|
|
|
@@ -87,19 +87,19 @@ export class UnexpectedError extends BaseTypedError {
|
|
|
87
87
|
* QueryError is raised when a query error occurs.
|
|
88
88
|
*/
|
|
89
89
|
export class QueryError extends BaseTypedError {
|
|
90
|
-
static readonly TYPE = _FREIGHTER_EXCEPTION_PREFIX
|
|
90
|
+
static readonly TYPE: string = `${_FREIGHTER_EXCEPTION_PREFIX}query`;
|
|
91
91
|
type = QueryError.TYPE;
|
|
92
92
|
static readonly matches = errorMatcher(QueryError.TYPE);
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
export class NotFoundError extends QueryError {
|
|
96
|
-
static readonly TYPE = QueryError.TYPE
|
|
96
|
+
static readonly TYPE = `${QueryError.TYPE}.not_found`;
|
|
97
97
|
type = NotFoundError.TYPE;
|
|
98
98
|
static readonly matches = errorMatcher(NotFoundError.TYPE);
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
export class MultipleFoundError extends QueryError {
|
|
102
|
-
static readonly TYPE = QueryError.TYPE
|
|
102
|
+
static readonly TYPE = `${QueryError.TYPE}.multiple_results`;
|
|
103
103
|
type = MultipleFoundError.TYPE;
|
|
104
104
|
static readonly matches = errorMatcher(MultipleFoundError.TYPE);
|
|
105
105
|
}
|
|
@@ -108,7 +108,7 @@ export class MultipleFoundError extends QueryError {
|
|
|
108
108
|
* RouteError is raised when a routing error occurs.
|
|
109
109
|
*/
|
|
110
110
|
export class RouteError extends BaseTypedError {
|
|
111
|
-
static readonly TYPE = _FREIGHTER_EXCEPTION_PREFIX
|
|
111
|
+
static readonly TYPE = `${_FREIGHTER_EXCEPTION_PREFIX}route`;
|
|
112
112
|
type = RouteError.TYPE;
|
|
113
113
|
static readonly matches = errorMatcher(RouteError.TYPE);
|
|
114
114
|
path: string;
|
|
@@ -120,13 +120,13 @@ export class RouteError extends BaseTypedError {
|
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
export class ControlError extends BaseTypedError {
|
|
123
|
-
static readonly TYPE = _FREIGHTER_EXCEPTION_PREFIX
|
|
123
|
+
static readonly TYPE: string = `${_FREIGHTER_EXCEPTION_PREFIX}control`;
|
|
124
124
|
type = ControlError.TYPE;
|
|
125
125
|
static readonly matches = errorMatcher(ControlError.TYPE);
|
|
126
126
|
}
|
|
127
127
|
|
|
128
128
|
export class UnauthorizedError extends ControlError {
|
|
129
|
-
static readonly TYPE = ControlError.TYPE
|
|
129
|
+
static readonly TYPE = `${ControlError.TYPE}.unauthorized`;
|
|
130
130
|
type = UnauthorizedError.TYPE;
|
|
131
131
|
static readonly matches = errorMatcher(UnauthorizedError.TYPE);
|
|
132
132
|
}
|
|
@@ -135,7 +135,7 @@ export class UnauthorizedError extends ControlError {
|
|
|
135
135
|
* Raised when time-series data is not contiguous.
|
|
136
136
|
*/
|
|
137
137
|
export class ContiguityError extends BaseTypedError {
|
|
138
|
-
static readonly TYPE = _FREIGHTER_EXCEPTION_PREFIX
|
|
138
|
+
static readonly TYPE = `${_FREIGHTER_EXCEPTION_PREFIX}contiguity`;
|
|
139
139
|
type = ContiguityError.TYPE;
|
|
140
140
|
static readonly matches = errorMatcher(ContiguityError.TYPE);
|
|
141
141
|
}
|
|
@@ -157,9 +157,8 @@ const decode = (payload: ErrorPayload): Error | null => {
|
|
|
157
157
|
return new AuthError(payload.data);
|
|
158
158
|
}
|
|
159
159
|
|
|
160
|
-
if (payload.type.startsWith(UnexpectedError.TYPE))
|
|
160
|
+
if (payload.type.startsWith(UnexpectedError.TYPE))
|
|
161
161
|
return new UnexpectedError(payload.data);
|
|
162
|
-
}
|
|
163
162
|
|
|
164
163
|
if (payload.type.startsWith(QueryError.TYPE)) {
|
|
165
164
|
if (payload.type.startsWith(NotFoundError.TYPE))
|
package/src/framer/adapter.ts
CHANGED
|
@@ -127,11 +127,11 @@ export class WriteFrameAdapter {
|
|
|
127
127
|
Received a single channel name or key but no series.
|
|
128
128
|
`);
|
|
129
129
|
if (Array.isArray(series)) {
|
|
130
|
-
if (series.some((s) => s instanceof Series || Array.isArray(s)))
|
|
130
|
+
if (series.some((s) => s instanceof Series || Array.isArray(s)))
|
|
131
131
|
throw new ValidationError(`
|
|
132
132
|
Received a single channel name or key but multiple series.
|
|
133
133
|
`);
|
|
134
|
-
|
|
134
|
+
|
|
135
135
|
series = series as CrudeSeries;
|
|
136
136
|
}
|
|
137
137
|
const pld = await this.fetchChannel(columnsOrData);
|
|
@@ -152,11 +152,11 @@ export class WriteFrameAdapter {
|
|
|
152
152
|
const data = [];
|
|
153
153
|
for (let i = 0; i < columnsOrData.length; i++) {
|
|
154
154
|
const pld = await this.fetchChannel(columnsOrData[i]);
|
|
155
|
-
if (i >= series.length)
|
|
155
|
+
if (i >= series.length)
|
|
156
156
|
throw new ValidationError(`
|
|
157
157
|
Received an array of channel names or keys but not enough series.
|
|
158
158
|
`);
|
|
159
|
-
|
|
159
|
+
|
|
160
160
|
const s = new Series({
|
|
161
161
|
data: series[i] as CrudeSeries,
|
|
162
162
|
dataType: pld.dataType,
|
|
@@ -170,8 +170,7 @@ export class WriteFrameAdapter {
|
|
|
170
170
|
if (columnsOrData instanceof Frame || columnsOrData instanceof Map) {
|
|
171
171
|
const fr = new Frame(columnsOrData);
|
|
172
172
|
if (this.adapter == null) return fr;
|
|
173
|
-
|
|
174
|
-
cols = fr.columns.map((col_) => {
|
|
173
|
+
const cols = fr.columns.map((col_) => {
|
|
175
174
|
const col = typeof col_ === "string" ? this.adapter?.get(col_) : col_;
|
|
176
175
|
if (col == null)
|
|
177
176
|
throw new ValidationError(`
|
package/src/framer/client.ts
CHANGED
|
@@ -7,21 +7,26 @@
|
|
|
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 StreamClient, UnaryClient } from "@synnaxlabs/freighter";
|
|
10
|
+
import { type StreamClient, type UnaryClient } from "@synnaxlabs/freighter";
|
|
11
11
|
import {
|
|
12
12
|
type CrudeSeries,
|
|
13
13
|
type CrudeTimeRange,
|
|
14
14
|
type CrudeTimeStamp,
|
|
15
15
|
type MultiSeries,
|
|
16
|
-
TimeRange,
|
|
16
|
+
type TimeRange,
|
|
17
17
|
TimeSpan,
|
|
18
18
|
} from "@synnaxlabs/x";
|
|
19
19
|
|
|
20
|
-
import {
|
|
20
|
+
import {
|
|
21
|
+
type Key,
|
|
22
|
+
type KeyOrName,
|
|
23
|
+
type KeysOrNames,
|
|
24
|
+
type Params,
|
|
25
|
+
} from "@/channel/payload";
|
|
21
26
|
import { analyzeChannelParams, type Retriever } from "@/channel/retriever";
|
|
22
27
|
import { Deleter } from "@/framer/deleter";
|
|
23
28
|
import { Frame } from "@/framer/frame";
|
|
24
|
-
import { Iterator, IteratorConfig } from "@/framer/iterator";
|
|
29
|
+
import { Iterator, type IteratorConfig } from "@/framer/iterator";
|
|
25
30
|
import { Streamer, type StreamerConfig } from "@/framer/streamer";
|
|
26
31
|
import { Writer, type WriterConfig, WriterMode } from "@/framer/writer";
|
|
27
32
|
import { ontology } from "@/ontology";
|
package/src/framer/deleter.ts
CHANGED
|
@@ -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 { sendRequired, UnaryClient } from "@synnaxlabs/freighter";
|
|
10
|
+
import { sendRequired, type UnaryClient } from "@synnaxlabs/freighter";
|
|
11
11
|
import { TimeRange } from "@synnaxlabs/x";
|
|
12
12
|
import { z } from "zod";
|
|
13
13
|
|
package/src/framer/frame.ts
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
import {
|
|
11
11
|
MultiSeries,
|
|
12
12
|
Series,
|
|
13
|
-
SeriesPayload,
|
|
13
|
+
type SeriesPayload,
|
|
14
14
|
Size,
|
|
15
15
|
type TelemValue,
|
|
16
16
|
TimeRange,
|
|
@@ -126,7 +126,7 @@ export class Frame {
|
|
|
126
126
|
Object.entries(columnsOrData).forEach(([k, v]) => {
|
|
127
127
|
const key = parseInt(k);
|
|
128
128
|
if (!isNaN(key)) return this.push(key, ...toArray(v));
|
|
129
|
-
|
|
129
|
+
this.push(k, ...toArray(v));
|
|
130
130
|
});
|
|
131
131
|
return;
|
|
132
132
|
}
|
|
@@ -334,7 +334,7 @@ export class Frame {
|
|
|
334
334
|
*/
|
|
335
335
|
has(channel: KeyOrName): boolean {
|
|
336
336
|
if (typeof channel === "string" && this.colType === "key") return false;
|
|
337
|
-
|
|
337
|
+
if (typeof channel === "number" && this.colType === "name") return false;
|
|
338
338
|
return (this.columns as Keys).includes(channel as Key);
|
|
339
339
|
}
|
|
340
340
|
|
|
@@ -418,11 +418,9 @@ export const seriesFromPayload = (series: SeriesPayload): Series => {
|
|
|
418
418
|
return new Series({ data, dataType, timeRange, glBufferUsage: "static", alignment });
|
|
419
419
|
};
|
|
420
420
|
|
|
421
|
-
export const seriesToPayload = (series: Series): SeriesPayload => {
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
};
|
|
428
|
-
};
|
|
421
|
+
export const seriesToPayload = (series: Series): SeriesPayload => ({
|
|
422
|
+
timeRange: series._timeRange,
|
|
423
|
+
dataType: series.dataType,
|
|
424
|
+
data: new Uint8Array(series.data.buffer),
|
|
425
|
+
alignment: series.alignment,
|
|
426
|
+
});
|
|
@@ -17,14 +17,13 @@ import { randomSeries } from "@/util/telem";
|
|
|
17
17
|
|
|
18
18
|
const client = newClient();
|
|
19
19
|
|
|
20
|
-
const newChannel = async (): Promise<channel.Channel> =>
|
|
21
|
-
|
|
20
|
+
const newChannel = async (): Promise<channel.Channel> =>
|
|
21
|
+
await client.channels.create({
|
|
22
22
|
name: "test",
|
|
23
23
|
leaseholder: 1,
|
|
24
24
|
rate: Rate.hz(25),
|
|
25
25
|
dataType: DataType.FLOAT64,
|
|
26
26
|
});
|
|
27
|
-
};
|
|
28
27
|
|
|
29
28
|
describe("Iterator", () => {
|
|
30
29
|
test("happy path", async () => {
|
package/src/framer/writer.ts
CHANGED
|
@@ -245,7 +245,7 @@ export class Writer {
|
|
|
245
245
|
value: Record<KeyOrName, control.Authority> | KeyOrName | number,
|
|
246
246
|
authority?: control.Authority,
|
|
247
247
|
): Promise<boolean> {
|
|
248
|
-
let config: Config
|
|
248
|
+
let config: Config;
|
|
249
249
|
if (typeof value === "number" && authority == null)
|
|
250
250
|
config = { keys: [], authorities: [value] };
|
|
251
251
|
else {
|
|
@@ -14,11 +14,11 @@ import { z } from "zod";
|
|
|
14
14
|
|
|
15
15
|
import { type framer } from "@/framer";
|
|
16
16
|
import {
|
|
17
|
-
Device,
|
|
18
|
-
DeviceKey,
|
|
17
|
+
type Device,
|
|
18
|
+
type DeviceKey,
|
|
19
19
|
deviceKeyZ,
|
|
20
20
|
deviceZ,
|
|
21
|
-
NewDevice,
|
|
21
|
+
type NewDevice,
|
|
22
22
|
newDeviceZ,
|
|
23
23
|
} from "@/hardware/device/payload";
|
|
24
24
|
import { signals } from "@/signals";
|
|
@@ -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 { binary, UnknownRecord } from "@synnaxlabs/x";
|
|
10
|
+
import { binary, type UnknownRecord } from "@synnaxlabs/x";
|
|
11
11
|
import { z } from "zod";
|
|
12
12
|
|
|
13
13
|
import { rackKeyZ } from "@/hardware/rack/payload";
|
|
@@ -15,11 +15,11 @@ import { z } from "zod";
|
|
|
15
15
|
|
|
16
16
|
import { type framer } from "@/framer";
|
|
17
17
|
import {
|
|
18
|
-
NewRack,
|
|
18
|
+
type NewRack,
|
|
19
19
|
newRackZ,
|
|
20
|
-
RackKey,
|
|
20
|
+
type RackKey,
|
|
21
21
|
rackKeyZ,
|
|
22
|
-
RackPayload,
|
|
22
|
+
type RackPayload,
|
|
23
23
|
rackZ,
|
|
24
24
|
} from "@/hardware/rack/payload";
|
|
25
25
|
import { type task } from "@/hardware/task";
|
|
@@ -19,18 +19,18 @@ import { framer } from "@/framer";
|
|
|
19
19
|
import { type Frame } from "@/framer/frame";
|
|
20
20
|
import { rack } from "@/hardware/rack";
|
|
21
21
|
import {
|
|
22
|
-
NewTask,
|
|
22
|
+
type NewTask,
|
|
23
23
|
newTaskZ,
|
|
24
|
-
Payload,
|
|
25
|
-
State,
|
|
26
|
-
StateObservable,
|
|
24
|
+
type Payload,
|
|
25
|
+
type State,
|
|
26
|
+
type StateObservable,
|
|
27
27
|
stateZ,
|
|
28
|
-
TaskKey,
|
|
28
|
+
type TaskKey,
|
|
29
29
|
taskKeyZ,
|
|
30
30
|
taskZ,
|
|
31
31
|
} from "@/hardware/task/payload";
|
|
32
32
|
import { ontology } from "@/ontology";
|
|
33
|
-
import { ranger } from "@/ranger";
|
|
33
|
+
import { type ranger } from "@/ranger";
|
|
34
34
|
import { signals } from "@/signals";
|
|
35
35
|
import { analyzeParams, checkForMultipleOrNoResults } from "@/util/retrieve";
|
|
36
36
|
import { nullableArrayZ } from "@/util/zod";
|
|
@@ -123,9 +123,7 @@ export class Task<
|
|
|
123
123
|
if (parsed.success) {
|
|
124
124
|
res = parsed.data as State<D>;
|
|
125
125
|
if (res.key === cmdKey) break;
|
|
126
|
-
} else
|
|
127
|
-
console.error(parsed.error);
|
|
128
|
-
}
|
|
126
|
+
} else console.error(parsed.error);
|
|
129
127
|
}
|
|
130
128
|
streamer.close();
|
|
131
129
|
return res;
|
|
@@ -316,10 +314,14 @@ export class Client implements AsyncTermSearcher<string, TaskKey, Payload> {
|
|
|
316
314
|
return this.sugar([res.task])[0];
|
|
317
315
|
}
|
|
318
316
|
|
|
319
|
-
async retrieveByName
|
|
317
|
+
async retrieveByName<
|
|
318
|
+
C extends UnknownRecord = UnknownRecord,
|
|
319
|
+
D extends {} = UnknownRecord,
|
|
320
|
+
T extends string = string,
|
|
321
|
+
>(name: string, rack?: number): Promise<Task<C, D, T>> {
|
|
320
322
|
const tasks = await this.execRetrieve({ names: [name], rack });
|
|
321
323
|
checkForMultipleOrNoResults("Task", name, tasks, true);
|
|
322
|
-
return this.sugar(tasks)[0]
|
|
324
|
+
return this.sugar(tasks)[0] as Task<C, D, T>;
|
|
323
325
|
}
|
|
324
326
|
|
|
325
327
|
private async execRetrieve(req: RetrieveRequest): Promise<Payload[]> {
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
import { z } from "zod";
|
|
11
11
|
|
|
12
12
|
import { device } from "@/hardware/device";
|
|
13
|
-
import { task } from "@/hardware/task";
|
|
13
|
+
import { type task } from "@/hardware/task";
|
|
14
14
|
|
|
15
15
|
export const unitsVoltsZ = z.literal("Volts");
|
|
16
16
|
export type UnitsVolts = z.infer<typeof unitsVoltsZ>;
|
|
@@ -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 { binary, observe, UnknownRecord } from "@synnaxlabs/x";
|
|
10
|
+
import { binary, type observe, type UnknownRecord } from "@synnaxlabs/x";
|
|
11
11
|
import { z } from "zod";
|
|
12
12
|
|
|
13
13
|
import { ontology } from "@/ontology";
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
import { id } from "@synnaxlabs/x";
|
|
11
11
|
import { describe, expect, it } from "vitest";
|
|
12
12
|
|
|
13
|
-
import { task } from "@/hardware/task";
|
|
13
|
+
import { type task } from "@/hardware/task";
|
|
14
14
|
import { newClient } from "@/setupspecs";
|
|
15
15
|
|
|
16
16
|
const client = newClient();
|
package/src/label/client.ts
CHANGED
|
@@ -14,7 +14,7 @@ import { type AsyncTermSearcher } from "@synnaxlabs/x/search";
|
|
|
14
14
|
import { type framer } from "@/framer";
|
|
15
15
|
import { type Key, type Label, labelZ } from "@/label/payload";
|
|
16
16
|
import { Retriever } from "@/label/retriever";
|
|
17
|
-
import { type NewLabelPayload, SetOptions, Writer } from "@/label/writer";
|
|
17
|
+
import { type NewLabelPayload, type SetOptions, Writer } from "@/label/writer";
|
|
18
18
|
import { ontology } from "@/ontology";
|
|
19
19
|
import { signals } from "@/signals";
|
|
20
20
|
|
package/src/ontology/client.ts
CHANGED
|
@@ -290,9 +290,7 @@ export class ChangeTracker {
|
|
|
290
290
|
}
|
|
291
291
|
|
|
292
292
|
private async start(): Promise<void> {
|
|
293
|
-
for await (const frame of this.streamer)
|
|
294
|
-
await this.update(frame);
|
|
295
|
-
}
|
|
293
|
+
for await (const frame of this.streamer) await this.update(frame);
|
|
296
294
|
}
|
|
297
295
|
|
|
298
296
|
private async update(frame: framer.Frame): Promise<void> {
|
|
@@ -52,9 +52,9 @@ export type ParamAnalysisResult =
|
|
|
52
52
|
|
|
53
53
|
export const analyzeParams = (groups: Params): ParamAnalysisResult => {
|
|
54
54
|
const normal = toArray(groups) as Keys | Names;
|
|
55
|
-
if (normal.length === 0)
|
|
55
|
+
if (normal.length === 0)
|
|
56
56
|
throw new Error("No groups specified");
|
|
57
|
-
|
|
57
|
+
|
|
58
58
|
const isKey = keyZ.safeParse(normal[0]).success;
|
|
59
59
|
return {
|
|
60
60
|
single: !Array.isArray(groups),
|
package/src/ontology/payload.ts
CHANGED
|
@@ -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 { change, UnknownRecord } from "@synnaxlabs/x";
|
|
10
|
+
import { type change, type UnknownRecord } from "@synnaxlabs/x";
|
|
11
11
|
import { z } from "zod";
|
|
12
12
|
|
|
13
13
|
export type ResourceChange = change.Change<ID, Resource>;
|
package/src/ranger/alias.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { type change } from "@synnaxlabs/x/change";
|
|
|
12
12
|
import { z } from "zod";
|
|
13
13
|
|
|
14
14
|
import { type channel } from "@/channel";
|
|
15
|
-
import { type Key as ChannelKey,keyZ as channelKeyZ } from "@/channel/payload";
|
|
15
|
+
import { type Key as ChannelKey, keyZ as channelKeyZ } from "@/channel/payload";
|
|
16
16
|
import { type Client as FrameClient } from "@/framer/client";
|
|
17
17
|
import { type Key, keyZ } from "@/ranger/payload";
|
|
18
18
|
import { signals } from "@/signals";
|
|
@@ -161,7 +161,7 @@ const aliasSeparator = "---";
|
|
|
161
161
|
const decodeAliasChanges =
|
|
162
162
|
(rangeKey: Key): signals.Decoder<string, Alias> =>
|
|
163
163
|
(variant, data) => {
|
|
164
|
-
if (variant === "delete")
|
|
164
|
+
if (variant === "delete")
|
|
165
165
|
return data
|
|
166
166
|
.toStrings()
|
|
167
167
|
.filter((k) => k.split(aliasSeparator)[0] === rangeKey)
|
|
@@ -170,7 +170,6 @@ const decodeAliasChanges =
|
|
|
170
170
|
key: alias,
|
|
171
171
|
value: undefined,
|
|
172
172
|
}));
|
|
173
|
-
}
|
|
174
173
|
return data.parseJSON(aliasZ).map((alias) => ({
|
|
175
174
|
variant,
|
|
176
175
|
key: alias.alias,
|
package/src/ranger/client.ts
CHANGED
|
@@ -8,21 +8,20 @@
|
|
|
8
8
|
// included in the file licenses/APL.txt.
|
|
9
9
|
|
|
10
10
|
import { sendRequired, type UnaryClient } from "@synnaxlabs/freighter";
|
|
11
|
-
import { CrudeTimeRange, observe, TimeRange } from "@synnaxlabs/x";
|
|
11
|
+
import { type CrudeTimeRange, observe, TimeRange } from "@synnaxlabs/x";
|
|
12
12
|
import { type AsyncTermSearcher } from "@synnaxlabs/x/search";
|
|
13
13
|
import { type Series } from "@synnaxlabs/x/telem";
|
|
14
14
|
import { toArray } from "@synnaxlabs/x/toArray";
|
|
15
15
|
import { z } from "zod";
|
|
16
16
|
|
|
17
|
-
import { Key as ChannelKey } from "@/channel/payload";
|
|
17
|
+
import { type Key as ChannelKey } from "@/channel/payload";
|
|
18
18
|
import { type Retriever as ChannelRetriever } from "@/channel/retriever";
|
|
19
|
-
import { MultipleFoundError, NotFoundError } from "@/errors";
|
|
20
|
-
import { QueryError } from "@/errors";
|
|
19
|
+
import { MultipleFoundError, NotFoundError, QueryError } from "@/errors";
|
|
21
20
|
import { type framer } from "@/framer";
|
|
22
21
|
import { type label } from "@/label";
|
|
23
22
|
import { type Label } from "@/label/payload";
|
|
24
23
|
import { ontology } from "@/ontology";
|
|
25
|
-
import { Resource } from "@/ontology/payload";
|
|
24
|
+
import { type Resource } from "@/ontology/payload";
|
|
26
25
|
import { type Alias, Aliaser } from "@/ranger/alias";
|
|
27
26
|
import { KV } from "@/ranger/kv";
|
|
28
27
|
import {
|
|
@@ -37,7 +36,7 @@ import {
|
|
|
37
36
|
type Payload,
|
|
38
37
|
payloadZ,
|
|
39
38
|
} from "@/ranger/payload";
|
|
40
|
-
import { CreateOptions, type Writer } from "@/ranger/writer";
|
|
39
|
+
import { type CreateOptions, type Writer } from "@/ranger/writer";
|
|
41
40
|
import { signals } from "@/signals";
|
|
42
41
|
import { nullableArrayZ } from "@/util/zod";
|
|
43
42
|
|
|
@@ -98,9 +97,8 @@ export class Range {
|
|
|
98
97
|
|
|
99
98
|
async setAlias(channel: ChannelKey | Name, alias: string): Promise<void> {
|
|
100
99
|
const ch = await this.channels.retrieve(channel);
|
|
101
|
-
if (ch.length === 0) {
|
|
102
|
-
|
|
103
|
-
}
|
|
100
|
+
if (ch.length === 0) throw new QueryError(`Channel ${channel} does not exist`);
|
|
101
|
+
|
|
104
102
|
await this.aliaser.set({ [ch[0].key]: alias });
|
|
105
103
|
}
|
|
106
104
|
|
package/src/ranger/kv.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { isObject } from "@synnaxlabs/x/identity";
|
|
|
12
12
|
import { toArray } from "@synnaxlabs/x/toArray";
|
|
13
13
|
import { z } from "zod";
|
|
14
14
|
|
|
15
|
-
import { framer } from "@/framer";
|
|
15
|
+
import { type framer } from "@/framer";
|
|
16
16
|
import { type Key, keyZ } from "@/ranger/payload";
|
|
17
17
|
import { signals } from "@/signals";
|
|
18
18
|
import { nullableArrayZ } from "@/util/zod";
|
|
@@ -96,7 +96,7 @@ export class KV {
|
|
|
96
96
|
key: k,
|
|
97
97
|
value: v,
|
|
98
98
|
}));
|
|
99
|
-
else pairs = [{ range: this.rangeKey, key
|
|
99
|
+
else pairs = [{ range: this.rangeKey, key, value }];
|
|
100
100
|
await sendRequired(
|
|
101
101
|
this.client,
|
|
102
102
|
KV.SET_ENDPOINT,
|
package/src/ranger/payload.ts
CHANGED
|
@@ -79,7 +79,7 @@ export const ONTOLOGY_TYPE: ontology.ResourceType = "range";
|
|
|
79
79
|
export const ALIAS_ONTOLOGY_TYPE: ontology.ResourceType = "range-alias";
|
|
80
80
|
|
|
81
81
|
export const rangeOntologyID = (key: Key): ontology.ID =>
|
|
82
|
-
new ontology.ID({ type: ONTOLOGY_TYPE, key
|
|
82
|
+
new ontology.ID({ type: ONTOLOGY_TYPE, key });
|
|
83
83
|
|
|
84
84
|
export const rangeAliasOntologyID = (key: Key): ontology.ID =>
|
|
85
|
-
new ontology.ID({ type: ALIAS_ONTOLOGY_TYPE, key
|
|
85
|
+
new ontology.ID({ type: ALIAS_ONTOLOGY_TYPE, key });
|