@synnaxlabs/client 0.43.1 → 0.44.2
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 +1 -1
- package/dist/access/payload.d.ts.map +1 -1
- package/dist/access/policy/client.d.ts +263 -6
- package/dist/access/policy/client.d.ts.map +1 -1
- package/dist/access/policy/external.d.ts +0 -1
- package/dist/access/policy/external.d.ts.map +1 -1
- package/dist/access/policy/payload.d.ts +105 -93
- package/dist/access/policy/payload.d.ts.map +1 -1
- package/dist/auth/auth.d.ts +1 -1
- package/dist/auth/auth.d.ts.map +1 -1
- package/dist/channel/client.d.ts +23 -17
- package/dist/channel/client.d.ts.map +1 -1
- package/dist/channel/payload.d.ts +151 -21
- package/dist/channel/payload.d.ts.map +1 -1
- package/dist/channel/retriever.d.ts +9 -16
- package/dist/channel/retriever.d.ts.map +1 -1
- package/dist/channel/writer.d.ts +1 -1
- package/dist/channel/writer.d.ts.map +1 -1
- package/dist/client.cjs +27 -135
- package/dist/client.d.ts +3 -3
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +8657 -28963
- package/dist/connection/checker.d.ts +1 -1
- package/dist/connection/checker.d.ts.map +1 -1
- package/dist/control/client.d.ts +1 -0
- package/dist/control/client.d.ts.map +1 -1
- package/dist/control/state.d.ts +6 -6
- package/dist/control/state.d.ts.map +1 -1
- package/dist/errors.d.ts +18 -5
- package/dist/errors.d.ts.map +1 -1
- package/dist/framer/adapter.d.ts +3 -3
- package/dist/framer/adapter.d.ts.map +1 -1
- package/dist/framer/client.d.ts +4 -13
- package/dist/framer/client.d.ts.map +1 -1
- package/dist/framer/codec.d.ts +1 -1
- package/dist/framer/codec.d.ts.map +1 -1
- package/dist/framer/deleter.d.ts +5 -5
- package/dist/framer/deleter.d.ts.map +1 -1
- package/dist/framer/frame.d.ts +5 -7
- package/dist/framer/frame.d.ts.map +1 -1
- package/dist/framer/streamProxy.d.ts +1 -1
- package/dist/framer/streamProxy.d.ts.map +1 -1
- package/dist/framer/streamer.d.ts +235 -20
- package/dist/framer/streamer.d.ts.map +1 -1
- package/dist/framer/writer.d.ts +302 -33
- package/dist/framer/writer.d.ts.map +1 -1
- package/dist/hardware/device/client.d.ts +49 -28
- package/dist/hardware/device/client.d.ts.map +1 -1
- package/dist/hardware/device/payload.d.ts +126 -46
- package/dist/hardware/device/payload.d.ts.map +1 -1
- package/dist/hardware/rack/client.d.ts +78 -22
- package/dist/hardware/rack/client.d.ts.map +1 -1
- package/dist/hardware/rack/payload.d.ts +99 -56
- package/dist/hardware/rack/payload.d.ts.map +1 -1
- package/dist/hardware/task/client.d.ts +100 -41
- package/dist/hardware/task/client.d.ts.map +1 -1
- package/dist/hardware/task/payload.d.ts +83 -61
- package/dist/hardware/task/payload.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/label/client.d.ts +138 -20
- package/dist/label/client.d.ts.map +1 -1
- package/dist/label/external.d.ts +0 -2
- package/dist/label/external.d.ts.map +1 -1
- package/dist/label/payload.d.ts +4 -5
- package/dist/label/payload.d.ts.map +1 -1
- package/dist/ontology/client.d.ts +45 -135
- package/dist/ontology/client.d.ts.map +1 -1
- package/dist/ontology/group/group.d.ts +3 -3
- package/dist/ontology/group/group.d.ts.map +1 -1
- package/dist/ontology/group/payload.d.ts +3 -27
- package/dist/ontology/group/payload.d.ts.map +1 -1
- package/dist/ontology/payload.d.ts +114 -243
- package/dist/ontology/payload.d.ts.map +1 -1
- package/dist/ontology/writer.d.ts +4 -4
- package/dist/ontology/writer.d.ts.map +1 -1
- package/dist/ranger/alias.d.ts +15 -5
- package/dist/ranger/alias.d.ts.map +1 -1
- package/dist/ranger/client.d.ts +91 -30
- 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 +11 -12
- package/dist/ranger/kv.d.ts.map +1 -1
- package/dist/ranger/payload.d.ts +19 -44
- package/dist/ranger/payload.d.ts.map +1 -1
- package/dist/ranger/writer.d.ts +22 -19
- package/dist/ranger/writer.d.ts.map +1 -1
- package/dist/testutil/client.d.ts +4 -0
- package/dist/testutil/client.d.ts.map +1 -0
- package/dist/user/client.d.ts +59 -6
- package/dist/user/client.d.ts.map +1 -1
- package/dist/user/payload.d.ts +4 -6
- package/dist/user/payload.d.ts.map +1 -1
- package/dist/user/retriever.d.ts +2 -2
- package/dist/user/retriever.d.ts.map +1 -1
- package/dist/util/decodeJSONString.d.ts +2 -2
- package/dist/util/decodeJSONString.d.ts.map +1 -1
- package/dist/util/parseWithoutKeyConversion.d.ts +2 -2
- package/dist/util/parseWithoutKeyConversion.d.ts.map +1 -1
- package/dist/util/retrieve.d.ts +1 -1
- package/dist/util/retrieve.d.ts.map +1 -1
- package/dist/util/zod.d.ts +1 -1
- package/dist/util/zod.d.ts.map +1 -1
- package/dist/workspace/client.d.ts +17 -6
- package/dist/workspace/client.d.ts.map +1 -1
- package/dist/workspace/lineplot/client.d.ts +2 -2
- package/dist/workspace/lineplot/client.d.ts.map +1 -1
- package/dist/workspace/lineplot/payload.d.ts +8 -9
- package/dist/workspace/lineplot/payload.d.ts.map +1 -1
- package/dist/workspace/log/client.d.ts +2 -2
- package/dist/workspace/log/client.d.ts.map +1 -1
- package/dist/workspace/log/payload.d.ts +8 -9
- package/dist/workspace/log/payload.d.ts.map +1 -1
- package/dist/workspace/payload.d.ts +10 -11
- package/dist/workspace/payload.d.ts.map +1 -1
- package/dist/workspace/schematic/client.d.ts +2 -2
- package/dist/workspace/schematic/client.d.ts.map +1 -1
- package/dist/workspace/schematic/payload.d.ts +10 -11
- package/dist/workspace/schematic/payload.d.ts.map +1 -1
- package/dist/workspace/table/client.d.ts +2 -2
- package/dist/workspace/table/client.d.ts.map +1 -1
- package/dist/workspace/table/payload.d.ts +10 -11
- package/dist/workspace/table/payload.d.ts.map +1 -1
- package/examples/node/package-lock.json +47 -39
- package/examples/node/package.json +2 -1
- package/examples/node/streamWrite.js +5 -11
- package/package.json +14 -13
- package/src/access/payload.ts +1 -1
- package/src/access/policy/client.ts +87 -32
- package/src/access/policy/external.ts +0 -1
- package/src/access/policy/payload.ts +4 -4
- package/src/access/policy/policy.spec.ts +86 -83
- package/src/auth/auth.spec.ts +29 -18
- package/src/auth/auth.ts +1 -1
- package/src/channel/batchRetriever.spec.ts +4 -9
- package/src/channel/channel.spec.ts +24 -6
- package/src/channel/client.ts +52 -51
- package/src/channel/payload.ts +15 -16
- package/src/channel/retriever.ts +26 -41
- package/src/channel/writer.ts +7 -4
- package/src/client.ts +4 -4
- package/src/connection/checker.ts +1 -1
- package/src/connection/connection.spec.ts +31 -23
- package/src/control/client.ts +2 -2
- package/src/control/state.spec.ts +3 -3
- package/src/control/state.ts +1 -1
- package/src/errors.spec.ts +9 -5
- package/src/errors.ts +28 -15
- package/src/framer/adapter.spec.ts +118 -9
- package/src/framer/adapter.ts +24 -11
- package/src/framer/client.spec.ts +125 -2
- package/src/framer/client.ts +41 -47
- package/src/framer/codec.ts +1 -1
- package/src/framer/deleter.spec.ts +2 -2
- package/src/framer/deleter.ts +1 -1
- package/src/framer/frame.ts +1 -4
- package/src/framer/iterator.spec.ts +8 -8
- package/src/framer/iterator.ts +1 -1
- package/src/framer/streamProxy.ts +1 -1
- package/src/framer/streamer.spec.ts +185 -36
- package/src/framer/streamer.ts +28 -36
- package/src/framer/writer.spec.ts +7 -6
- package/src/framer/writer.ts +97 -111
- package/src/hardware/device/client.ts +45 -131
- package/src/hardware/device/device.spec.ts +163 -52
- package/src/hardware/device/payload.ts +10 -21
- package/src/hardware/rack/client.ts +87 -105
- package/src/hardware/rack/payload.ts +4 -13
- package/src/hardware/rack/rack.spec.ts +28 -35
- package/src/hardware/task/client.ts +335 -291
- package/src/hardware/task/payload.ts +86 -62
- package/src/hardware/task/task.spec.ts +208 -32
- package/src/index.ts +2 -1
- package/src/label/client.ts +100 -95
- package/src/label/external.ts +0 -2
- package/src/label/label.spec.ts +8 -6
- package/src/label/payload.ts +3 -4
- package/src/ontology/client.ts +41 -324
- package/src/ontology/group/group.spec.ts +2 -2
- package/src/ontology/group/group.ts +4 -5
- package/src/ontology/group/payload.ts +2 -25
- package/src/ontology/group/writer.ts +1 -1
- package/src/ontology/ontology.spec.ts +355 -41
- package/src/ontology/payload.ts +77 -112
- package/src/ontology/writer.ts +8 -17
- package/src/ranger/alias.ts +45 -37
- package/src/ranger/client.ts +144 -149
- package/src/ranger/external.ts +1 -1
- package/src/ranger/kv.ts +9 -27
- package/src/ranger/payload.ts +23 -37
- package/src/ranger/ranger.spec.ts +37 -56
- package/src/ranger/writer.ts +1 -1
- package/src/{signals/index.ts → testutil/client.ts} +11 -1
- package/src/user/client.ts +122 -47
- package/src/user/payload.ts +2 -5
- package/src/user/retriever.ts +1 -1
- package/src/user/user.spec.ts +31 -31
- package/src/user/writer.ts +1 -1
- package/src/util/decodeJSONString.ts +3 -3
- package/src/util/parseWithoutKeyConversion.ts +2 -2
- package/src/util/retrieve.ts +1 -1
- package/src/util/zod.ts +1 -1
- package/src/workspace/client.ts +20 -36
- package/src/workspace/lineplot/client.ts +5 -7
- package/src/workspace/lineplot/lineplot.spec.ts +2 -2
- package/src/workspace/lineplot/payload.ts +4 -7
- package/src/workspace/log/client.ts +5 -7
- package/src/workspace/log/log.spec.ts +2 -2
- package/src/workspace/log/payload.ts +4 -7
- package/src/workspace/payload.ts +4 -7
- package/src/workspace/schematic/client.ts +5 -7
- package/src/workspace/schematic/payload.ts +4 -7
- package/src/workspace/schematic/schematic.spec.ts +2 -2
- package/src/workspace/table/client.ts +5 -7
- package/src/workspace/table/payload.ts +4 -7
- package/src/workspace/table/table.spec.ts +2 -2
- package/src/workspace/workspace.spec.ts +2 -2
- package/dist/access/policy/ontology.d.ts +0 -5
- package/dist/access/policy/ontology.d.ts.map +0 -1
- package/dist/access/policy/retriever.d.ts +0 -40
- package/dist/access/policy/retriever.d.ts.map +0 -1
- package/dist/access/policy/writer.d.ts +0 -9
- package/dist/access/policy/writer.d.ts.map +0 -1
- package/dist/label/retriever.d.ts +0 -14
- package/dist/label/retriever.d.ts.map +0 -1
- package/dist/label/writer.d.ts +0 -54
- package/dist/label/writer.d.ts.map +0 -1
- package/dist/setupspecs.d.ts +0 -5
- package/dist/setupspecs.d.ts.map +0 -1
- package/dist/signals/external.d.ts +0 -2
- package/dist/signals/external.d.ts.map +0 -1
- package/dist/signals/index.d.ts +0 -2
- package/dist/signals/index.d.ts.map +0 -1
- package/dist/signals/observable.d.ts +0 -12
- package/dist/signals/observable.d.ts.map +0 -1
- package/src/access/policy/ontology.ts +0 -17
- package/src/access/policy/retriever.ts +0 -44
- package/src/access/policy/writer.ts +0 -65
- package/src/label/retriever.ts +0 -63
- package/src/label/writer.ts +0 -95
- package/src/setupspecs.ts +0 -27
- package/src/signals/external.ts +0 -10
- package/src/signals/observable.ts +0 -42
package/src/label/client.ts
CHANGED
|
@@ -7,125 +7,130 @@
|
|
|
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 UnaryClient } from "@synnaxlabs/freighter";
|
|
11
|
-
import {
|
|
12
|
-
import
|
|
13
|
-
|
|
14
|
-
import { type
|
|
15
|
-
import { type Key, type Label, labelZ, ONTOLOGY_TYPE } from "@/label/payload";
|
|
16
|
-
import { Retriever } from "@/label/retriever";
|
|
17
|
-
import { type New, type SetOptions, Writer } from "@/label/writer";
|
|
10
|
+
import { sendRequired, type UnaryClient } from "@synnaxlabs/freighter";
|
|
11
|
+
import { array } from "@synnaxlabs/x/array";
|
|
12
|
+
import z from "zod";
|
|
13
|
+
|
|
14
|
+
import { type Key, keyZ, type Label, labelZ } from "@/label/payload";
|
|
18
15
|
import { ontology } from "@/ontology";
|
|
19
|
-
import {
|
|
16
|
+
import { checkForMultipleOrNoResults } from "@/util/retrieve";
|
|
17
|
+
import { nullableArrayZ } from "@/util/zod";
|
|
20
18
|
|
|
21
|
-
const SET_CHANNEL_NAME = "sy_label_set";
|
|
22
|
-
const DELETE_CHANNEL_NAME = "sy_label_delete";
|
|
19
|
+
export const SET_CHANNEL_NAME = "sy_label_set";
|
|
20
|
+
export const DELETE_CHANNEL_NAME = "sy_label_delete";
|
|
23
21
|
|
|
24
|
-
export
|
|
25
|
-
|
|
26
|
-
private readonly retriever: Retriever;
|
|
27
|
-
private readonly writer: Writer;
|
|
28
|
-
private readonly frameClient: framer.Client;
|
|
29
|
-
private readonly ontology: ontology.Client;
|
|
30
|
-
|
|
31
|
-
constructor(
|
|
32
|
-
client: UnaryClient,
|
|
33
|
-
frameClient: framer.Client,
|
|
34
|
-
ontology: ontology.Client,
|
|
35
|
-
) {
|
|
36
|
-
this.writer = new Writer(client);
|
|
37
|
-
this.retriever = new Retriever(client);
|
|
38
|
-
this.frameClient = frameClient;
|
|
39
|
-
this.ontology = ontology;
|
|
40
|
-
}
|
|
22
|
+
export const newZ = labelZ.extend({ key: keyZ.optional() });
|
|
23
|
+
export interface New extends z.infer<typeof newZ> {}
|
|
41
24
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
25
|
+
const createReqZ = z.object({ labels: newZ.array() });
|
|
26
|
+
const createResZ = z.object({ labels: labelZ.array() });
|
|
27
|
+
const deleteReqZ = z.object({ keys: keyZ.array() });
|
|
28
|
+
const setReqZ = z.object({
|
|
29
|
+
id: ontology.idZ,
|
|
30
|
+
labels: keyZ.array(),
|
|
31
|
+
replace: z.boolean().optional(),
|
|
32
|
+
});
|
|
45
33
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
34
|
+
interface SetReq extends z.infer<typeof setReqZ> {}
|
|
35
|
+
export interface SetOptions extends Pick<SetReq, "replace"> {}
|
|
36
|
+
|
|
37
|
+
const removeReqZ = setReqZ.omit({ replace: true });
|
|
38
|
+
const emptyResZ = z.object({});
|
|
39
|
+
|
|
40
|
+
const CREATE_ENDPOINT = "/label/create";
|
|
41
|
+
const DELETE_ENDPOINT = "/label/delete";
|
|
42
|
+
const SET_ENDPOINT = "/label/set";
|
|
43
|
+
const REMOVE_ENDPOINT = "/label/remove";
|
|
44
|
+
const RETRIEVE_ENDPOINT = "/label/retrieve";
|
|
45
|
+
|
|
46
|
+
const retrieveRequestZ = z.object({
|
|
47
|
+
keys: keyZ.array().optional(),
|
|
48
|
+
for: ontology.idZ.optional(),
|
|
49
|
+
searchTerm: z.string().optional(),
|
|
50
|
+
offset: z.number().optional(),
|
|
51
|
+
limit: z.number().optional(),
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
const singleRetrieveArgsZ = z
|
|
55
|
+
.object({ key: keyZ })
|
|
56
|
+
.transform(({ key }) => ({ keys: [key] }));
|
|
57
|
+
|
|
58
|
+
const retrieveArgsZ = z.union([singleRetrieveArgsZ, retrieveRequestZ]);
|
|
59
|
+
|
|
60
|
+
export type RetrieveArgs = z.input<typeof retrieveArgsZ>;
|
|
61
|
+
export type SingleRetrieveArgs = z.input<typeof singleRetrieveArgsZ>;
|
|
62
|
+
export type MultiRetrieveArgs = z.input<typeof retrieveRequestZ>;
|
|
63
|
+
|
|
64
|
+
const retrieveResponseZ = z.object({ labels: nullableArrayZ(labelZ) });
|
|
53
65
|
|
|
54
|
-
|
|
55
|
-
|
|
66
|
+
export class Client {
|
|
67
|
+
readonly type: string = "label";
|
|
68
|
+
private readonly client: UnaryClient;
|
|
69
|
+
|
|
70
|
+
constructor(client: UnaryClient) {
|
|
71
|
+
this.client = client;
|
|
56
72
|
}
|
|
57
73
|
|
|
58
|
-
async
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
74
|
+
async retrieve(args: SingleRetrieveArgs): Promise<Label>;
|
|
75
|
+
async retrieve(args: MultiRetrieveArgs): Promise<Label[]>;
|
|
76
|
+
async retrieve(args: RetrieveArgs): Promise<Label | Label[]> {
|
|
77
|
+
const isSingle = "key" in args;
|
|
78
|
+
const res = await sendRequired(
|
|
79
|
+
this.client,
|
|
80
|
+
RETRIEVE_ENDPOINT,
|
|
81
|
+
args,
|
|
82
|
+
retrieveArgsZ,
|
|
83
|
+
retrieveResponseZ,
|
|
84
|
+
);
|
|
85
|
+
checkForMultipleOrNoResults("Label", args, res.labels, isSingle);
|
|
86
|
+
return isSingle ? res.labels[0] : res.labels;
|
|
64
87
|
}
|
|
65
88
|
|
|
66
|
-
async
|
|
67
|
-
await
|
|
89
|
+
async label(id: ontology.ID, labels: Key[], opts: SetOptions = {}): Promise<void> {
|
|
90
|
+
await sendRequired<typeof setReqZ, typeof emptyResZ>(
|
|
91
|
+
this.client,
|
|
92
|
+
SET_ENDPOINT,
|
|
93
|
+
{ id, labels, replace: opts.replace },
|
|
94
|
+
setReqZ,
|
|
95
|
+
emptyResZ,
|
|
96
|
+
);
|
|
68
97
|
}
|
|
69
98
|
|
|
70
|
-
async
|
|
71
|
-
|
|
99
|
+
async remove(id: ontology.ID, labels: Key[]): Promise<void> {
|
|
100
|
+
await sendRequired<typeof removeReqZ, typeof emptyResZ>(
|
|
101
|
+
this.client,
|
|
102
|
+
REMOVE_ENDPOINT,
|
|
103
|
+
{ id, labels },
|
|
104
|
+
removeReqZ,
|
|
105
|
+
emptyResZ,
|
|
106
|
+
);
|
|
72
107
|
}
|
|
73
108
|
|
|
74
109
|
async create(label: New): Promise<Label>;
|
|
75
110
|
async create(labels: New[]): Promise<Label[]>;
|
|
76
111
|
async create(labels: New | New[]): Promise<Label | Label[]> {
|
|
77
112
|
const isMany = Array.isArray(labels);
|
|
78
|
-
const res = await
|
|
79
|
-
|
|
113
|
+
const res = await sendRequired<typeof createReqZ, typeof createResZ>(
|
|
114
|
+
this.client,
|
|
115
|
+
CREATE_ENDPOINT,
|
|
116
|
+
{ labels: array.toArray(labels) },
|
|
117
|
+
createReqZ,
|
|
118
|
+
createResZ,
|
|
119
|
+
);
|
|
120
|
+
return isMany ? res.labels : res.labels[0];
|
|
80
121
|
}
|
|
81
122
|
|
|
82
123
|
async delete(key: Key): Promise<void>;
|
|
83
124
|
async delete(keys: Key[]): Promise<void>;
|
|
84
125
|
async delete(keys: Key | Key[]): Promise<void> {
|
|
85
|
-
await
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
SET_CHANNEL_NAME,
|
|
92
|
-
DELETE_CHANNEL_NAME,
|
|
93
|
-
decodeChanges,
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
async trackLabelsOf(
|
|
98
|
-
id: ontology.CrudeID,
|
|
99
|
-
): Promise<observe.ObservableAsyncCloseable<Label[]>> {
|
|
100
|
-
const wrapper = new observe.Observer<Label[]>();
|
|
101
|
-
const initial = (await this.retrieveFor(id)).map((l) => ({
|
|
102
|
-
id: ontologyID(l.key),
|
|
103
|
-
key: l.key,
|
|
104
|
-
name: l.name,
|
|
105
|
-
data: l,
|
|
106
|
-
}));
|
|
107
|
-
const base = await this.ontology.openDependentTracker({
|
|
108
|
-
target: new ontology.ID(id),
|
|
109
|
-
dependents: initial,
|
|
110
|
-
relationshipType: "labeled_by",
|
|
111
|
-
});
|
|
112
|
-
base.onChange((resources: ontology.Resource[]) =>
|
|
113
|
-
wrapper.notify(
|
|
114
|
-
resources.map((r) => ({
|
|
115
|
-
key: r.id.key,
|
|
116
|
-
color: r.data?.color as string,
|
|
117
|
-
name: r.data?.name as string,
|
|
118
|
-
})),
|
|
119
|
-
),
|
|
126
|
+
await sendRequired<typeof deleteReqZ, typeof emptyResZ>(
|
|
127
|
+
this.client,
|
|
128
|
+
DELETE_ENDPOINT,
|
|
129
|
+
{ keys: array.toArray(keys) },
|
|
130
|
+
deleteReqZ,
|
|
131
|
+
emptyResZ,
|
|
120
132
|
);
|
|
121
|
-
return wrapper;
|
|
122
133
|
}
|
|
123
134
|
}
|
|
124
135
|
|
|
125
|
-
const
|
|
126
|
-
if (variant === "delete") return data.toUUIDs().map((v) => ({ variant, key: v }));
|
|
127
|
-
return data.parseJSON(labelZ).map((l) => ({ variant, key: l.key, value: l }));
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
export const ontologyID = (key: Key): ontology.ID =>
|
|
131
|
-
new ontology.ID({ type: ONTOLOGY_TYPE, key });
|
|
136
|
+
export const ontologyID = (key: Key): ontology.ID => ({ type: "label", key });
|
package/src/label/external.ts
CHANGED
package/src/label/label.spec.ts
CHANGED
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
import { describe, expect, it } from "vitest";
|
|
11
11
|
|
|
12
12
|
import { label } from "@/label";
|
|
13
|
-
import {
|
|
13
|
+
import { createTestClient } from "@/testutil/client";
|
|
14
14
|
|
|
15
|
-
const client =
|
|
15
|
+
const client = createTestClient();
|
|
16
16
|
|
|
17
17
|
describe("Label", () => {
|
|
18
18
|
describe("create", () => {
|
|
@@ -25,7 +25,7 @@ describe("Label", () => {
|
|
|
25
25
|
describe("retrieve", () => {
|
|
26
26
|
it("should retrieve a label by its key", async () => {
|
|
27
27
|
const v = await client.labels.create({ name: "Label", color: "#E774D0" });
|
|
28
|
-
const retrieved = await client.labels.retrieve(v.key);
|
|
28
|
+
const retrieved = await client.labels.retrieve({ key: v.key });
|
|
29
29
|
expect(retrieved).toEqual(v);
|
|
30
30
|
});
|
|
31
31
|
});
|
|
@@ -34,7 +34,9 @@ describe("Label", () => {
|
|
|
34
34
|
it("should delete a label by its key", async () => {
|
|
35
35
|
const v = await client.labels.create({ name: "Label", color: "#E774D0" });
|
|
36
36
|
await client.labels.delete(v.key);
|
|
37
|
-
await expect(
|
|
37
|
+
await expect(
|
|
38
|
+
async () => await client.labels.retrieve({ key: v.key }),
|
|
39
|
+
).rejects.toThrow();
|
|
38
40
|
});
|
|
39
41
|
});
|
|
40
42
|
|
|
@@ -43,7 +45,7 @@ describe("Label", () => {
|
|
|
43
45
|
const l1 = await client.labels.create({ name: "Label One", color: "#E774D)" });
|
|
44
46
|
const l2 = await client.labels.create({ name: "Label Two", color: "#E774D)" });
|
|
45
47
|
await client.labels.label(label.ontologyID(l1.key), [l2.key]);
|
|
46
|
-
const labels = await client.labels.
|
|
48
|
+
const labels = await client.labels.retrieve({ for: label.ontologyID(l1.key) });
|
|
47
49
|
expect(labels).toHaveLength(1);
|
|
48
50
|
expect(labels[0].key).toEqual(l2.key);
|
|
49
51
|
});
|
|
@@ -52,7 +54,7 @@ describe("Label", () => {
|
|
|
52
54
|
const l2 = await client.labels.create({ name: "Label Two", color: "#E774D)" });
|
|
53
55
|
await client.labels.label(label.ontologyID(l1.key), [l2.key]);
|
|
54
56
|
await client.labels.label(label.ontologyID(l1.key), [l1.key], { replace: true });
|
|
55
|
-
const labels = await client.labels.
|
|
57
|
+
const labels = await client.labels.retrieve({ for: label.ontologyID(l1.key) });
|
|
56
58
|
expect(labels).toHaveLength(1);
|
|
57
59
|
expect(labels[0].key).toEqual(l1.key);
|
|
58
60
|
});
|
package/src/label/payload.ts
CHANGED
|
@@ -7,9 +7,9 @@
|
|
|
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 { z } from "zod
|
|
10
|
+
import { z } from "zod";
|
|
11
11
|
|
|
12
|
-
export const keyZ = z.
|
|
12
|
+
export const keyZ = z.uuid();
|
|
13
13
|
export type Key = z.infer<typeof keyZ>;
|
|
14
14
|
|
|
15
15
|
export type Params = Key | Key[];
|
|
@@ -21,5 +21,4 @@ export const labelZ = z.object({
|
|
|
21
21
|
});
|
|
22
22
|
export interface Label extends z.infer<typeof labelZ> {}
|
|
23
23
|
|
|
24
|
-
export const
|
|
25
|
-
export type OntologyType = typeof ONTOLOGY_TYPE;
|
|
24
|
+
export const LABELED_BY_ONTOLOGY_RELATIONSHIP_TYPE = "labeled_by";
|