@synnaxlabs/client 0.38.1 → 0.40.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 +3387 -3433
- 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 +20 -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 +67 -39
- package/src/hardware/device/device.spec.ts +91 -33
- package/src/hardware/device/payload.ts +29 -28
- 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
|
@@ -10,44 +10,45 @@
|
|
|
10
10
|
import { binary, type UnknownRecord } from "@synnaxlabs/x";
|
|
11
11
|
import { z } from "zod";
|
|
12
12
|
|
|
13
|
-
import { rackKeyZ } from "@/hardware/rack/payload";
|
|
14
|
-
import {
|
|
13
|
+
import { keyZ as rackKeyZ } from "@/hardware/rack/payload";
|
|
14
|
+
import { decodeJSONString } from "@/util/decodeJSONString";
|
|
15
15
|
|
|
16
|
-
export const
|
|
16
|
+
export const keyZ = z.string();
|
|
17
|
+
export type Key = z.infer<typeof keyZ>;
|
|
17
18
|
|
|
18
19
|
export const deviceZ = z.object({
|
|
19
|
-
key:
|
|
20
|
+
key: keyZ,
|
|
20
21
|
rack: rackKeyZ,
|
|
21
22
|
name: z.string(),
|
|
22
23
|
make: z.string(),
|
|
23
24
|
model: z.string(),
|
|
24
25
|
location: z.string(),
|
|
25
26
|
configured: z.boolean().optional(),
|
|
26
|
-
properties: z.record(z.unknown()).or(
|
|
27
|
-
z.string().transform((c) => {
|
|
28
|
-
if (c === "") return {};
|
|
29
|
-
return binary.JSON_CODEC.decodeString(c);
|
|
30
|
-
}),
|
|
31
|
-
) as z.ZodType<UnknownRecord>,
|
|
27
|
+
properties: z.record(z.unknown()).or(z.string().transform(decodeJSONString)),
|
|
32
28
|
});
|
|
33
29
|
|
|
34
|
-
export
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
30
|
+
export interface Device<
|
|
31
|
+
Properties extends UnknownRecord = UnknownRecord,
|
|
32
|
+
Make extends string = string,
|
|
33
|
+
Model extends string = string,
|
|
34
|
+
> extends Omit<z.output<typeof deviceZ>, "properties"> {
|
|
35
|
+
properties: Properties;
|
|
36
|
+
make: Make;
|
|
37
|
+
model: Model;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const newZ = deviceZ.extend({
|
|
42
41
|
properties: z.unknown().transform((c) => binary.JSON_CODEC.encodeString(c)),
|
|
43
42
|
});
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
>
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
43
|
+
export interface New<
|
|
44
|
+
Properties extends UnknownRecord = UnknownRecord,
|
|
45
|
+
Make extends string = string,
|
|
46
|
+
Model extends string = string,
|
|
47
|
+
> extends Omit<z.input<typeof newZ>, "properties"> {
|
|
48
|
+
properties: Properties;
|
|
49
|
+
make: Make;
|
|
50
|
+
model: Model;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export const ONTOLOGY_TYPE = "device";
|
|
54
|
+
export type OntologyType = typeof ONTOLOGY_TYPE;
|
|
@@ -13,84 +13,69 @@ import { type AsyncTermSearcher } from "@synnaxlabs/x/search";
|
|
|
13
13
|
import { toArray } from "@synnaxlabs/x/toArray";
|
|
14
14
|
import { z } from "zod";
|
|
15
15
|
|
|
16
|
-
import { type framer } from "@/framer";
|
|
17
16
|
import {
|
|
18
|
-
type
|
|
19
|
-
|
|
20
|
-
type
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
type Key,
|
|
18
|
+
keyZ,
|
|
19
|
+
type New,
|
|
20
|
+
newZ,
|
|
21
|
+
ONTOLOGY_TYPE,
|
|
22
|
+
type Payload,
|
|
23
23
|
rackZ,
|
|
24
24
|
} from "@/hardware/rack/payload";
|
|
25
25
|
import { type task } from "@/hardware/task";
|
|
26
|
+
import { ontology } from "@/ontology";
|
|
26
27
|
import { analyzeParams, checkForMultipleOrNoResults } from "@/util/retrieve";
|
|
27
28
|
import { nullableArrayZ } from "@/util/zod";
|
|
28
29
|
|
|
29
30
|
const RETRIEVE_ENDPOINT = "/hardware/rack/retrieve";
|
|
30
|
-
const
|
|
31
|
-
const
|
|
31
|
+
const CREATE_ENDPOINT = "/hardware/rack/create";
|
|
32
|
+
const DELETE_ENDPOINT = "/hardware/rack/delete";
|
|
32
33
|
|
|
33
|
-
const
|
|
34
|
-
keys:
|
|
34
|
+
const retrieveReqZ = z.object({
|
|
35
|
+
keys: keyZ.array().optional(),
|
|
35
36
|
names: z.string().array().optional(),
|
|
36
37
|
search: z.string().optional(),
|
|
37
38
|
offset: z.number().optional(),
|
|
38
39
|
limit: z.number().optional(),
|
|
39
40
|
});
|
|
40
41
|
|
|
41
|
-
const
|
|
42
|
-
racks: nullableArrayZ(rackZ),
|
|
43
|
-
});
|
|
42
|
+
const retrieveResZ = z.object({ racks: nullableArrayZ(rackZ) });
|
|
44
43
|
|
|
45
|
-
const createReqZ = z.object({
|
|
46
|
-
racks: newRackZ.array(),
|
|
47
|
-
});
|
|
44
|
+
const createReqZ = z.object({ racks: newZ.array() });
|
|
48
45
|
|
|
49
|
-
const createResZ = z.object({
|
|
50
|
-
racks: rackZ.array(),
|
|
51
|
-
});
|
|
46
|
+
const createResZ = z.object({ racks: rackZ.array() });
|
|
52
47
|
|
|
53
|
-
const deleteReqZ = z.object({
|
|
54
|
-
keys: rackKeyZ.array(),
|
|
55
|
-
});
|
|
48
|
+
const deleteReqZ = z.object({ keys: keyZ.array() });
|
|
56
49
|
|
|
57
50
|
const deleteResZ = z.object({});
|
|
58
51
|
|
|
59
|
-
export class Client implements AsyncTermSearcher<string,
|
|
60
|
-
readonly type
|
|
52
|
+
export class Client implements AsyncTermSearcher<string, Key, Payload> {
|
|
53
|
+
readonly type = ONTOLOGY_TYPE;
|
|
61
54
|
private readonly client: UnaryClient;
|
|
62
|
-
private readonly frameClient: framer.Client;
|
|
63
55
|
private readonly tasks: task.Client;
|
|
64
56
|
|
|
65
|
-
constructor(
|
|
66
|
-
client: UnaryClient,
|
|
67
|
-
frameClient: framer.Client,
|
|
68
|
-
taskClient: task.Client,
|
|
69
|
-
) {
|
|
57
|
+
constructor(client: UnaryClient, taskClient: task.Client) {
|
|
70
58
|
this.client = client;
|
|
71
|
-
this.frameClient = frameClient;
|
|
72
59
|
this.tasks = taskClient;
|
|
73
60
|
}
|
|
74
61
|
|
|
75
|
-
async delete(keys:
|
|
62
|
+
async delete(keys: Key | Key[]): Promise<void> {
|
|
76
63
|
await sendRequired<typeof deleteReqZ, typeof deleteResZ>(
|
|
77
64
|
this.client,
|
|
78
|
-
|
|
65
|
+
DELETE_ENDPOINT,
|
|
79
66
|
{ keys: toArray(keys) },
|
|
80
67
|
deleteReqZ,
|
|
81
68
|
deleteResZ,
|
|
82
69
|
);
|
|
83
70
|
}
|
|
84
71
|
|
|
85
|
-
async create(rack:
|
|
86
|
-
|
|
87
|
-
async create(
|
|
88
|
-
|
|
89
|
-
async create(rack: NewRack | NewRack[]): Promise<Rack | Rack[]> {
|
|
72
|
+
async create(rack: New): Promise<Rack>;
|
|
73
|
+
async create(racks: New[]): Promise<Rack[]>;
|
|
74
|
+
async create(rack: New | New[]): Promise<Rack | Rack[]> {
|
|
90
75
|
const isSingle = !Array.isArray(rack);
|
|
91
76
|
const res = await sendRequired<typeof createReqZ, typeof createResZ>(
|
|
92
77
|
this.client,
|
|
93
|
-
|
|
78
|
+
CREATE_ENDPOINT,
|
|
94
79
|
{ racks: toArray(rack) },
|
|
95
80
|
createReqZ,
|
|
96
81
|
createResZ,
|
|
@@ -101,64 +86,60 @@ export class Client implements AsyncTermSearcher<string, RackKey, Rack> {
|
|
|
101
86
|
}
|
|
102
87
|
|
|
103
88
|
async search(term: string): Promise<Rack[]> {
|
|
104
|
-
const res = await sendRequired<typeof
|
|
89
|
+
const res = await sendRequired<typeof retrieveReqZ, typeof retrieveResZ>(
|
|
105
90
|
this.client,
|
|
106
91
|
RETRIEVE_ENDPOINT,
|
|
107
92
|
{ search: term },
|
|
108
|
-
|
|
109
|
-
|
|
93
|
+
retrieveReqZ,
|
|
94
|
+
retrieveResZ,
|
|
110
95
|
);
|
|
111
96
|
return this.sugar(res.racks);
|
|
112
97
|
}
|
|
113
98
|
|
|
114
99
|
async page(offset: number, limit: number): Promise<Rack[]> {
|
|
115
|
-
const res = await sendRequired<typeof
|
|
100
|
+
const res = await sendRequired<typeof retrieveReqZ, typeof retrieveResZ>(
|
|
116
101
|
this.client,
|
|
117
102
|
RETRIEVE_ENDPOINT,
|
|
118
103
|
{ offset, limit },
|
|
119
|
-
|
|
120
|
-
|
|
104
|
+
retrieveReqZ,
|
|
105
|
+
retrieveResZ,
|
|
121
106
|
);
|
|
122
107
|
return this.sugar(res.racks);
|
|
123
108
|
}
|
|
124
109
|
|
|
125
|
-
async retrieve(key: string |
|
|
126
|
-
|
|
127
|
-
async retrieve(
|
|
128
|
-
|
|
129
|
-
async retrieve(
|
|
130
|
-
racks: string | RackKey | string[] | RackKey[],
|
|
131
|
-
): Promise<Rack | Rack[]> {
|
|
110
|
+
async retrieve(key: string | Key): Promise<Rack>;
|
|
111
|
+
async retrieve(keys: Key[]): Promise<Rack[]>;
|
|
112
|
+
async retrieve(racks: string | Key | Key[]): Promise<Rack | Rack[]> {
|
|
132
113
|
const { variant, normalized, single } = analyzeParams(racks, {
|
|
133
114
|
string: "names",
|
|
134
115
|
number: "keys",
|
|
135
116
|
});
|
|
136
|
-
const res = await sendRequired<typeof
|
|
117
|
+
const res = await sendRequired<typeof retrieveReqZ, typeof retrieveResZ>(
|
|
137
118
|
this.client,
|
|
138
119
|
RETRIEVE_ENDPOINT,
|
|
139
120
|
{ [variant]: normalized },
|
|
140
|
-
|
|
141
|
-
|
|
121
|
+
retrieveReqZ,
|
|
122
|
+
retrieveResZ,
|
|
142
123
|
);
|
|
143
124
|
const sugared = this.sugar(res.racks);
|
|
144
125
|
checkForMultipleOrNoResults("Rack", racks, sugared, single);
|
|
145
126
|
return single ? sugared[0] : sugared;
|
|
146
127
|
}
|
|
147
128
|
|
|
148
|
-
private sugar(payloads:
|
|
129
|
+
private sugar(payloads: Payload[]): Rack[] {
|
|
149
130
|
return payloads.map(({ key, name }) => new Rack(key, name, this.tasks));
|
|
150
131
|
}
|
|
151
132
|
}
|
|
152
133
|
|
|
153
134
|
export class Rack {
|
|
154
|
-
key:
|
|
135
|
+
key: Key;
|
|
155
136
|
name: string;
|
|
156
137
|
private readonly tasks: task.Client;
|
|
157
138
|
|
|
158
|
-
constructor(key:
|
|
139
|
+
constructor(key: Key, name: string, taskClient: task.Client) {
|
|
159
140
|
this.key = key;
|
|
160
141
|
this.name = name;
|
|
161
|
-
this.tasks =
|
|
142
|
+
this.tasks = taskClient;
|
|
162
143
|
}
|
|
163
144
|
|
|
164
145
|
async listTasks(): Promise<task.Task[]> {
|
|
@@ -169,20 +150,26 @@ export class Rack {
|
|
|
169
150
|
return await this.tasks.retrieveByName(name, this.key);
|
|
170
151
|
}
|
|
171
152
|
|
|
153
|
+
async retrieveTaskByType(type: string): Promise<task.Task[]> {
|
|
154
|
+
return await this.tasks.retrieveByType(type, this.key);
|
|
155
|
+
}
|
|
156
|
+
|
|
172
157
|
async createTask<
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
>(task: task.
|
|
158
|
+
Config extends UnknownRecord,
|
|
159
|
+
Details extends {} = UnknownRecord,
|
|
160
|
+
Type extends string = string,
|
|
161
|
+
>(task: task.New<Config, Type>): Promise<task.Task<Config, Details, Type>> {
|
|
177
162
|
task.key = (
|
|
178
163
|
(BigInt(this.key) << 32n) +
|
|
179
164
|
(BigInt(task.key ?? 0) & 0xffffffffn)
|
|
180
165
|
).toString();
|
|
181
|
-
return await this.tasks.create<
|
|
166
|
+
return await this.tasks.create<Config, Details, Type>(task);
|
|
182
167
|
}
|
|
183
168
|
|
|
184
169
|
async deleteTask(task: bigint): Promise<void> {
|
|
185
170
|
await this.tasks.delete([task]);
|
|
186
171
|
}
|
|
187
172
|
}
|
|
188
|
-
|
|
173
|
+
|
|
174
|
+
export const ontologyID = (key: Key): ontology.ID =>
|
|
175
|
+
new ontology.ID({ type: ONTOLOGY_TYPE, key: key.toString() });
|
|
@@ -7,26 +7,17 @@
|
|
|
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 { zod } from "@synnaxlabs/x";
|
|
10
11
|
import { z } from "zod";
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
export const keyZ = zod.uint32;
|
|
14
|
+
export type Key = z.infer<typeof keyZ>;
|
|
13
15
|
|
|
14
|
-
export const
|
|
16
|
+
export const rackZ = z.object({ key: keyZ, name: z.string() });
|
|
17
|
+
export interface Payload extends z.infer<typeof rackZ> {}
|
|
15
18
|
|
|
16
|
-
export
|
|
19
|
+
export const newZ = rackZ.partial({ key: true });
|
|
20
|
+
export interface New extends z.input<typeof newZ> {}
|
|
17
21
|
|
|
18
|
-
export const
|
|
19
|
-
|
|
20
|
-
name: z.string(),
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
export type RackPayload = z.infer<typeof rackZ>;
|
|
24
|
-
|
|
25
|
-
export const newRackZ = rackZ.partial({ key: true });
|
|
26
|
-
|
|
27
|
-
export type NewRack = z.input<typeof newRackZ>;
|
|
28
|
-
|
|
29
|
-
export const ONTOLOGY_TYPE: ontology.ResourceType = "rack";
|
|
30
|
-
|
|
31
|
-
export const ontologyID = (key: RackKey): ontology.ID =>
|
|
32
|
-
new ontology.ID({ type: ONTOLOGY_TYPE, key: key.toString() });
|
|
22
|
+
export const ONTOLOGY_TYPE = "rack";
|
|
23
|
+
export type OntologyType = typeof ONTOLOGY_TYPE;
|
|
@@ -26,6 +26,18 @@ describe("Rack", () => {
|
|
|
26
26
|
await expect(client.hardware.racks.create({})).rejects.toThrow(ZodError);
|
|
27
27
|
});
|
|
28
28
|
});
|
|
29
|
+
describe("update", () => {
|
|
30
|
+
it("should update a rack if the key is provided", async () => {
|
|
31
|
+
const r = await client.hardware.racks.create({ name: "test" });
|
|
32
|
+
const updated = await client.hardware.racks.create({
|
|
33
|
+
key: r.key,
|
|
34
|
+
name: "updated",
|
|
35
|
+
});
|
|
36
|
+
expect(updated.name).toBe("updated");
|
|
37
|
+
const retrieved = await client.hardware.racks.retrieve(r.key);
|
|
38
|
+
expect(retrieved.name).toBe("updated");
|
|
39
|
+
});
|
|
40
|
+
});
|
|
29
41
|
describe("retrieve", () => {
|
|
30
42
|
it("should retrieve a rack by its key", async () => {
|
|
31
43
|
const r = await client.hardware.racks.create({ name: "test" });
|