@synnaxlabs/client 0.26.1 → 0.27.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.
Files changed (125) hide show
  1. package/.turbo/turbo-build.log +7 -7
  2. package/README.md +36 -10
  3. package/api/client.api.md +3077 -0
  4. package/api-extractor.json +7 -0
  5. package/dist/access/client.d.ts +0 -1
  6. package/dist/access/payload.d.ts +0 -1
  7. package/dist/auth/auth.d.ts +0 -1
  8. package/dist/channel/client.d.ts +6 -2
  9. package/dist/channel/client.d.ts.map +1 -1
  10. package/dist/channel/creator.d.ts +0 -1
  11. package/dist/channel/payload.d.ts +4 -1
  12. package/dist/channel/payload.d.ts.map +1 -1
  13. package/dist/channel/retriever.d.ts +0 -1
  14. package/dist/channel/writer.d.ts +0 -1
  15. package/dist/client.cjs +17 -17
  16. package/dist/client.d.ts +6 -7
  17. package/dist/client.d.ts.map +1 -1
  18. package/dist/client.js +2006 -1745
  19. package/dist/connection/checker.d.ts +0 -1
  20. package/dist/control/client.d.ts +0 -1
  21. package/dist/control/client.d.ts.map +1 -1
  22. package/dist/control/state.d.ts +0 -1
  23. package/dist/errors.d.ts +0 -1
  24. package/dist/framer/adapter.d.ts +0 -1
  25. package/dist/framer/client.d.ts +0 -1
  26. package/dist/framer/deleter.d.ts +0 -1
  27. package/dist/framer/frame.d.ts +11 -12
  28. package/dist/framer/iterator.d.ts +0 -1
  29. package/dist/framer/streamProxy.d.ts +0 -1
  30. package/dist/framer/streamer.d.ts +0 -1
  31. package/dist/framer/writer.d.ts +0 -1
  32. package/dist/framer/writer.d.ts.map +1 -1
  33. package/dist/hardware/client.d.ts +0 -1
  34. package/dist/hardware/device/client.d.ts +0 -1
  35. package/dist/hardware/device/payload.d.ts +0 -1
  36. package/dist/hardware/device/payload.d.ts.map +1 -1
  37. package/dist/hardware/rack/client.d.ts +0 -1
  38. package/dist/hardware/rack/payload.d.ts +0 -1
  39. package/dist/hardware/rack/payload.d.ts.map +1 -1
  40. package/dist/hardware/task/client.d.ts +0 -1
  41. package/dist/hardware/task/payload.d.ts +0 -1
  42. package/dist/hardware/task/payload.d.ts.map +1 -1
  43. package/dist/label/client.d.ts +8 -6
  44. package/dist/label/client.d.ts.map +1 -1
  45. package/dist/label/payload.d.ts +0 -1
  46. package/dist/label/retriever.d.ts +0 -1
  47. package/dist/label/retriever.d.ts.map +1 -1
  48. package/dist/label/writer.d.ts +32 -2
  49. package/dist/label/writer.d.ts.map +1 -1
  50. package/dist/ontology/client.d.ts +124 -11
  51. package/dist/ontology/client.d.ts.map +1 -1
  52. package/dist/ontology/group/client.d.ts +0 -1
  53. package/dist/ontology/group/group.d.ts +0 -1
  54. package/dist/ontology/group/payload.d.ts +0 -1
  55. package/dist/ontology/group/writer.d.ts +0 -1
  56. package/dist/ontology/payload.d.ts +5 -1
  57. package/dist/ontology/payload.d.ts.map +1 -1
  58. package/dist/ontology/writer.d.ts +4 -5
  59. package/dist/ontology/writer.d.ts.map +1 -1
  60. package/dist/ranger/alias.d.ts +0 -1
  61. package/dist/ranger/client.d.ts +55 -14
  62. package/dist/ranger/client.d.ts.map +1 -1
  63. package/dist/ranger/external.d.ts +1 -1
  64. package/dist/ranger/external.d.ts.map +1 -1
  65. package/dist/ranger/kv.d.ts +42 -5
  66. package/dist/ranger/kv.d.ts.map +1 -1
  67. package/dist/ranger/payload.d.ts +5 -2
  68. package/dist/ranger/payload.d.ts.map +1 -1
  69. package/dist/ranger/writer.d.ts +107 -2
  70. package/dist/ranger/writer.d.ts.map +1 -1
  71. package/dist/setupspecs.d.ts +0 -1
  72. package/dist/signals/observable.d.ts +0 -1
  73. package/dist/transport.d.ts +0 -1
  74. package/dist/user/client.d.ts +0 -1
  75. package/dist/user/payload.d.ts +0 -1
  76. package/dist/util/retrieve.d.ts +0 -1
  77. package/dist/util/telem.d.ts +0 -1
  78. package/dist/util/zod.d.ts +0 -1
  79. package/dist/workspace/client.d.ts +0 -1
  80. package/dist/workspace/lineplot/client.d.ts +0 -1
  81. package/dist/workspace/lineplot/payload.d.ts +0 -1
  82. package/dist/workspace/lineplot/retriever.d.ts +0 -1
  83. package/dist/workspace/lineplot/writer.d.ts +0 -1
  84. package/dist/workspace/payload.d.ts +0 -1
  85. package/dist/workspace/retriever.d.ts +0 -1
  86. package/dist/workspace/schematic/client.d.ts +0 -1
  87. package/dist/workspace/schematic/payload.d.ts +0 -1
  88. package/dist/workspace/schematic/retriever.d.ts +0 -1
  89. package/dist/workspace/schematic/writer.d.ts +0 -1
  90. package/dist/workspace/writer.d.ts +0 -1
  91. package/package.json +14 -12
  92. package/src/access/access.spec.ts +11 -11
  93. package/src/channel/batchRetriever.spec.ts +2 -0
  94. package/src/channel/channel.spec.ts +51 -31
  95. package/src/channel/client.ts +7 -0
  96. package/src/channel/payload.ts +1 -0
  97. package/src/client.ts +4 -3
  98. package/src/control/client.ts +9 -0
  99. package/src/errors.spec.ts +9 -0
  100. package/src/framer/frame.spec.ts +2 -2
  101. package/src/framer/frame.ts +22 -22
  102. package/src/framer/writer.ts +2 -1
  103. package/src/hardware/device/payload.ts +9 -0
  104. package/src/hardware/rack/payload.ts +9 -0
  105. package/src/hardware/task/payload.ts +9 -0
  106. package/src/label/client.ts +49 -19
  107. package/src/label/label.spec.ts +9 -0
  108. package/src/label/retriever.ts +2 -1
  109. package/src/label/writer.ts +11 -3
  110. package/src/ontology/client.ts +214 -13
  111. package/src/ontology/payload.ts +4 -0
  112. package/src/ontology/writer.ts +26 -12
  113. package/src/ranger/client.ts +204 -28
  114. package/src/ranger/external.ts +1 -1
  115. package/src/ranger/kv.ts +50 -11
  116. package/src/ranger/payload.ts +9 -5
  117. package/src/ranger/ranger.spec.ts +114 -49
  118. package/src/ranger/writer.ts +7 -2
  119. package/vite.config.ts +1 -1
  120. package/dist/ranger/active.d.ts +0 -11
  121. package/dist/ranger/active.d.ts.map +0 -1
  122. package/dist/ranger/range.d.ts +0 -32
  123. package/dist/ranger/range.d.ts.map +0 -1
  124. package/src/ranger/active.ts +0 -74
  125. package/src/ranger/range.ts +0 -98
@@ -7,10 +7,12 @@
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 } from "@synnaxlabs/x";
10
11
  import { DataType, Rate, TimeSpan, TimeStamp } from "@synnaxlabs/x/telem";
11
12
  import { describe, expect, it } from "vitest";
12
13
 
13
14
  import { QueryError } from "@/errors";
15
+ import { ranger } from "@/ranger";
14
16
  import { type NewPayload } from "@/ranger/payload";
15
17
  import { newClient } from "@/setupspecs";
16
18
 
@@ -47,6 +49,21 @@ describe("Ranger", () => {
47
49
  expect(createdRanges[0].timeRange).toEqual(ranges[0].timeRange);
48
50
  expect(createdRanges[1].timeRange).toEqual(ranges[1].timeRange);
49
51
  });
52
+ it("should create a range with a parent", async () => {
53
+ const parentRange = await client.ranges.create({
54
+ name: "My New Parent Range",
55
+ timeRange: TimeStamp.now().spanRange(TimeSpan.seconds(1)),
56
+ });
57
+ await client.ranges.create(
58
+ {
59
+ name: "My New Child Range",
60
+ timeRange: TimeStamp.now().spanRange(TimeSpan.seconds(1)),
61
+ },
62
+ { parent: parentRange.ontologyID },
63
+ );
64
+ const children = await client.ontology.retrieveChildren(parentRange.ontologyID);
65
+ expect(children).toHaveLength(1);
66
+ });
50
67
  });
51
68
 
52
69
  describe("delete", () => {
@@ -109,6 +126,43 @@ describe("Ranger", () => {
109
126
  });
110
127
  });
111
128
 
129
+ describe("retrieveParent", () => {
130
+ it("should retrieve the parent of a range", async () => {
131
+ const parentRange = await client.ranges.create({
132
+ name: "My New Parent Range",
133
+ timeRange: TimeStamp.now().spanRange(TimeSpan.seconds(1)),
134
+ });
135
+ const childRange = await client.ranges.create(
136
+ {
137
+ name: "My New Child Range",
138
+ timeRange: TimeStamp.now().spanRange(TimeSpan.seconds(1)),
139
+ },
140
+ { parent: parentRange.ontologyID },
141
+ );
142
+ const parent = await childRange.retrieveParent();
143
+ expect(parent?.key).toEqual(parentRange.key);
144
+ });
145
+ });
146
+
147
+ describe("page", () => {
148
+ it("should page through ranges", async () => {
149
+ await client.ranges.create({
150
+ name: "My New One Second Range",
151
+ timeRange: TimeStamp.now().spanRange(TimeSpan.seconds(1)),
152
+ });
153
+ await client.ranges.create({
154
+ name: "My New Two Second Range",
155
+ timeRange: TimeStamp.now().spanRange(TimeSpan.seconds(2)),
156
+ });
157
+ const ranges = await client.ranges.page(0, 1);
158
+ expect(ranges.length).toEqual(1);
159
+ const keys = ranges.map((r) => r.key);
160
+ const next = await client.ranges.page(1, 1);
161
+ expect(next.length).toEqual(1);
162
+ expect(next.map((r) => r.key)).not.toContain(keys[0]);
163
+ });
164
+ });
165
+
112
166
  describe("KV", () => {
113
167
  it("should set, get, and delete a single key", async () => {
114
168
  const rng = await client.ranges.create({
@@ -141,82 +195,93 @@ describe("Ranger", () => {
141
195
  const res = await rng.kv.list();
142
196
  expect(res).toEqual({ foo: "bar", baz: "qux" });
143
197
  });
144
- });
145
198
 
146
- describe("Alias", () => {
147
- describe("list", () => {
148
- it("should list the aliases for the range", async () => {
149
- const ch = await client.channels.create({
150
- name: "My New Channel",
151
- dataType: DataType.FLOAT32,
152
- rate: Rate.hz(1),
153
- });
199
+ describe("observable", () => {
200
+ it("should listen to key-value sets on the range", async () => {
154
201
  const rng = await client.ranges.create({
155
202
  name: "My New One Second Range",
156
203
  timeRange: TimeStamp.now().spanRange(TimeSpan.seconds(1)),
157
204
  });
158
- await rng.setAlias(ch.key, "myalias");
159
- const aliases = await rng.listAliases();
160
- expect(aliases).toEqual({ [ch.key]: "myalias" });
205
+ const obs = await rng.kv.openTracker();
206
+ const res = new Promise<change.Change<string, ranger.KVPair>[]>((resolve) => {
207
+ obs.onChange((pair) => resolve(pair));
208
+ });
209
+ await rng.kv.set("foo", "bar");
210
+ const pair = await res;
211
+ expect(pair.length).toBeGreaterThan(0);
212
+ expect(pair[0].value?.range).toEqual(rng.key);
213
+ expect(pair[0].value?.key).toEqual("foo");
214
+ expect(pair[0].value?.value).toEqual("bar");
161
215
  });
162
- });
163
- });
164
-
165
- describe("Active", () => {
166
- describe("setActive", () => {
167
- it("should create and set a range as active", async () => {
216
+ it("should listen to key-value deletes on the range", async () => {
168
217
  const rng = await client.ranges.create({
169
218
  name: "My New One Second Range",
170
219
  timeRange: TimeStamp.now().spanRange(TimeSpan.seconds(1)),
171
220
  });
172
- await client.ranges.setActive(rng.key);
173
- const retrieved = await client.ranges.retrieveActive();
174
- expect(retrieved).not.toBeNull();
175
- expect(retrieved?.key).toEqual(rng.key);
221
+ await rng.kv.set("foo", "bar");
222
+ const obs = await rng.kv.openTracker();
223
+ const res = new Promise<change.Change<string, ranger.KVPair>[]>((resolve) => {
224
+ obs.onChange((changes) => {
225
+ if (changes.every((c) => c.variant === "delete")) resolve(changes);
226
+ });
227
+ });
228
+ await rng.kv.delete("foo");
229
+ const pair = await res;
230
+ expect(pair.length).toBeGreaterThan(0);
231
+ expect(pair[0].value?.range).toEqual(rng.key);
232
+ expect(pair[0].value?.key).toEqual("foo");
233
+ expect(pair[0].value?.value).toHaveLength(0);
176
234
  });
177
- it("should clear the active range", async () => {
235
+ });
236
+ });
237
+
238
+ describe("Alias", () => {
239
+ describe("set + resolve", () => {
240
+ it("should set and resolve an alias for the range", async () => {
241
+ const ch = await client.channels.create({
242
+ name: "My New Channel",
243
+ dataType: DataType.FLOAT32,
244
+ rate: Rate.hz(1),
245
+ });
178
246
  const rng = await client.ranges.create({
179
247
  name: "My New One Second Range",
180
248
  timeRange: TimeStamp.now().spanRange(TimeSpan.seconds(1)),
181
249
  });
182
- await client.ranges.setActive(rng.key);
183
- await client.ranges.clearActive(rng.key);
184
- const retrieved = await client.ranges.retrieveActive();
185
- expect(retrieved).toBeNull();
250
+ await rng.setAlias(ch.key, "myalias");
251
+ const resolved = await rng.resolveAlias("myalias");
252
+ expect(resolved).toEqual(ch.key);
186
253
  });
187
254
  });
188
- });
189
-
190
- describe("Labels", () => {
191
- describe("set", () => {
192
- it("should set a label on a range", async () => {
255
+ describe("deleteAlias", () => {
256
+ it("should remove an alias for the range", async () => {
257
+ const ch = await client.channels.create({
258
+ name: "My New Channel",
259
+ dataType: DataType.FLOAT32,
260
+ rate: Rate.hz(1),
261
+ });
193
262
  const rng = await client.ranges.create({
194
263
  name: "My New One Second Range",
195
264
  timeRange: TimeStamp.now().spanRange(TimeSpan.seconds(1)),
196
265
  });
197
- const lbl = await client.labels.create({
198
- name: "My New Label",
199
- color: "#E774D0",
200
- });
201
- await rng.addLabel(lbl.key);
202
- const retrieved = await rng.labels();
203
- expect(retrieved).toEqual([lbl]);
266
+ await rng.setAlias(ch.key, "myalias");
267
+ await rng.deleteAlias(ch.key);
268
+ expect(await rng.resolveAlias("myalias")).toBeUndefined();
204
269
  });
205
270
  });
206
- describe("remove", () => {
207
- it("should remove a label from a range", async () => {
271
+ describe("list", () => {
272
+ it("should list the aliases for the range", async () => {
273
+ const ch = await client.channels.create({
274
+ name: "My New Channel",
275
+ dataType: DataType.FLOAT32,
276
+ rate: Rate.hz(1),
277
+ });
208
278
  const rng = await client.ranges.create({
209
279
  name: "My New One Second Range",
210
280
  timeRange: TimeStamp.now().spanRange(TimeSpan.seconds(1)),
211
281
  });
212
- const lbl = await client.labels.create({
213
- name: "My New Label",
214
- color: "#E774D0",
215
- });
216
- await rng.addLabel(lbl.key);
217
- await rng.removeLabel(lbl.key);
218
- const retrieved = await rng.labels();
219
- expect(retrieved).toEqual([]);
282
+ await rng.setAlias(ch.key, "myalias");
283
+ const aliases = await rng.listAliases();
284
+ expect(aliases).toEqual({ [ch.key]: "myalias" });
220
285
  });
221
286
  });
222
287
  });
@@ -10,6 +10,7 @@
10
10
  import { sendRequired, type UnaryClient } from "@synnaxlabs/freighter";
11
11
  import { z } from "zod";
12
12
 
13
+ import { ontology } from "@/ontology";
13
14
  import {
14
15
  keyZ,
15
16
  type NewPayload,
@@ -23,9 +24,13 @@ const createResZ = z.object({
23
24
  });
24
25
 
25
26
  const createReqZ = z.object({
27
+ parent: ontology.idZ.optional(),
26
28
  ranges: newPayloadZ.array(),
27
29
  });
28
30
 
31
+ type CreateRequest = z.infer<typeof createReqZ>;
32
+ export type CreateOptions = Pick<CreateRequest, "parent">;
33
+
29
34
  const deleteReqZ = z.object({
30
35
  keys: keyZ.array(),
31
36
  });
@@ -60,11 +65,11 @@ export class Writer {
60
65
  );
61
66
  }
62
67
 
63
- async create(ranges: NewPayload[]): Promise<Payload[]> {
68
+ async create(ranges: NewPayload[], options?: CreateOptions): Promise<Payload[]> {
64
69
  const res = await sendRequired<typeof createReqZ, typeof createResZ>(
65
70
  this.client,
66
71
  CREATE_ENDPOINT,
67
- { ranges },
72
+ { ranges, ...options },
68
73
  createReqZ,
69
74
  createResZ,
70
75
  );
package/vite.config.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 { isProd, lib } from "@synnaxlabs/vite-plugin";
10
+ import { lib } from "@synnaxlabs/vite-plugin";
11
11
  import { defineConfig } from "vite";
12
12
 
13
13
  export default defineConfig({
@@ -1,11 +0,0 @@
1
- import { UnaryClient } from '@synnaxlabs/freighter';
2
- import { Key, Payload } from './payload';
3
-
4
- export declare class Active {
5
- private readonly client;
6
- constructor(client: UnaryClient);
7
- setActive(range: Key): Promise<void>;
8
- retrieveActive(): Promise<Payload | null>;
9
- clearActive(range: Key): Promise<void>;
10
- }
11
- //# sourceMappingURL=active.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"active.d.ts","sourceRoot":"","sources":["../../src/ranger/active.ts"],"names":[],"mappings":"AASA,OAAO,EAAgB,KAAK,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAIvE,OAAO,EAAE,KAAK,GAAG,EAAQ,KAAK,OAAO,EAAY,MAAM,kBAAkB,CAAC;AAsB1E,qBAAa,MAAM;IACjB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAc;gBAEzB,MAAM,EAAE,WAAW;IAIzB,SAAS,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;IAUpC,cAAc,IAAI,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;IAYzC,WAAW,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;CAS7C"}
@@ -1,32 +0,0 @@
1
- import { Series, TimeRange } from '@synnaxlabs/x/telem';
2
- import { Key, Name, Params } from '../channel/payload';
3
- import { Retriever as ChannelRetriever } from '../channel/retriever';
4
- import { framer } from '../framer';
5
- import { label } from '../label';
6
- import { Label } from '../label/payload';
7
- import { Alias, Aliaser } from './alias';
8
- import { KV } from './kv';
9
- import { signals } from '../signals';
10
-
11
- export declare class Range {
12
- key: string;
13
- name: string;
14
- readonly kv: KV;
15
- readonly timeRange: TimeRange;
16
- readonly color: string | undefined;
17
- readonly channels: ChannelRetriever;
18
- private readonly aliaser;
19
- private readonly frameClient;
20
- private readonly labelClient;
21
- constructor(name: string, timeRange: TimeRange | undefined, key: string, color: string | undefined, _frameClient: framer.Client, _kv: KV, _aliaser: Aliaser, _channels: ChannelRetriever, _labelClient: label.Client);
22
- setAlias(channel: Key | Name, alias: string): Promise<void>;
23
- deleteAlias(...channels: Key[]): Promise<void>;
24
- listAliases(): Promise<Record<Key, string>>;
25
- openAliasTracker(): Promise<signals.Observable<string, Alias>>;
26
- read(channel: Key | Name): Promise<Series>;
27
- read(channels: Params): Promise<framer.Frame>;
28
- labels(): Promise<Label[]>;
29
- addLabel(...labels: label.Key[]): Promise<void>;
30
- removeLabel(...labels: label.Key[]): Promise<void>;
31
- }
32
- //# sourceMappingURL=range.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"range.d.ts","sourceRoot":"","sources":["../../src/ranger/range.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,KAAK,MAAM,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAE7D,OAAO,EAAE,KAAK,GAAG,EAAE,KAAK,IAAI,EAAC,KAAK,MAAM,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,KAAK,SAAS,IAAI,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEzE,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAE7C,OAAO,EAAE,KAAK,KAAK,EAAE,KAAK,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,KAAK,EAAE,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,WAAW,CAAC;AAKzC,qBAAa,KAAK;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,EAAE,EAAE,CAAC;IAChB,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,QAAQ,CAAC,QAAQ,EAAE,gBAAgB,CAAC;IACpC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAU;IAClC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAgB;IAC5C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAe;gBAGzC,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,SAAS,YAAiB,EACrC,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,YAAY,EAAE,MAAM,CAAC,MAAM,EAC3B,GAAG,EAAE,EAAE,EACP,QAAQ,EAAE,OAAO,EACjB,SAAS,EAAE,gBAAgB,EAC3B,YAAY,EAAE,KAAK,CAAC,MAAM;IAatB,QAAQ,CAAC,OAAO,EAAE,GAAG,GAAG,IAAI,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQ3D,WAAW,CAAC,GAAG,QAAQ,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAI9C,WAAW,IAAI,OAAO,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IAI3C,gBAAgB,IAAI,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IAI9D,IAAI,CAAC,OAAO,EAAE,GAAG,GAAG,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC;IAE1C,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC;IAM7C,MAAM,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;IAI1B,QAAQ,CAAC,GAAG,MAAM,EAAE,KAAK,CAAC,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAI/C,WAAW,CAAC,GAAG,MAAM,EAAE,KAAK,CAAC,GAAG,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;CAGzD"}
@@ -1,74 +0,0 @@
1
- // Copyright 2024 Synnax Labs, Inc.
2
- //
3
- // Use of this software is governed by the Business Source License included in the file
4
- // licenses/BSL.txt.
5
- //
6
- // As of the Change Date specified in that file, in accordance with the Business Source
7
- // License, use of this software will be governed by the Apache License, Version 2.0,
8
- // included in the file licenses/APL.txt.
9
-
10
- import { sendRequired, type UnaryClient } from "@synnaxlabs/freighter";
11
- import { z } from "zod";
12
-
13
- import { QueryError } from "@/errors";
14
- import { type Key, keyZ, type Payload, payloadZ } from "@/ranger/payload";
15
-
16
- const setActiveResZ = z.object({});
17
-
18
- const retrieveActiveResZ = z.object({
19
- range: payloadZ,
20
- });
21
-
22
- const setActiveReqZ = z.object({
23
- range: keyZ,
24
- });
25
-
26
- const clearActiveReqZ = z.object({
27
- range: keyZ,
28
- });
29
-
30
- const clearActiveResZ = z.object({});
31
-
32
- const SET_ENDPOINT = "/range/set-active";
33
- const RETRIEVE_ENDPOINT = "/range/retrieve-active";
34
- const CLEAR_ENDPOINT = "/range/clear-active";
35
-
36
- export class Active {
37
- private readonly client: UnaryClient;
38
-
39
- constructor(client: UnaryClient) {
40
- this.client = client;
41
- }
42
-
43
- async setActive(range: Key): Promise<void> {
44
- await sendRequired<typeof setActiveReqZ, typeof setActiveResZ>(
45
- this.client,
46
- SET_ENDPOINT,
47
- { range },
48
- setActiveReqZ,
49
- setActiveResZ,
50
- );
51
- }
52
-
53
- async retrieveActive(): Promise<Payload | null> {
54
- const [res, err] = await this.client.send(
55
- RETRIEVE_ENDPOINT,
56
- {},
57
- z.object({}),
58
- retrieveActiveResZ,
59
- );
60
- if (QueryError.matches(err)) return null;
61
- if (err != null) throw err;
62
- return res.range;
63
- }
64
-
65
- async clearActive(range: Key): Promise<void> {
66
- await sendRequired<typeof clearActiveReqZ, typeof clearActiveResZ>(
67
- this.client,
68
- CLEAR_ENDPOINT,
69
- { range },
70
- clearActiveReqZ,
71
- clearActiveResZ,
72
- );
73
- }
74
- }
@@ -1,98 +0,0 @@
1
- // Copyright 2024 Synnax Labs, Inc.
2
- //
3
- // Use of this software is governed by the Business Source License included in the file
4
- // licenses/BSL.txt.
5
- //
6
- // As of the Change Date specified in that file, in accordance with the Business Source
7
- // License, use of this software will be governed by the Apache License, Version 2.0,
8
- // included in the file licenses/APL.txt.
9
-
10
- import { type Series, TimeRange } from "@synnaxlabs/x/telem";
11
-
12
- import { type Key, type Name,type Params } from "@/channel/payload";
13
- import { type Retriever as ChannelRetriever } from "@/channel/retriever";
14
- import { QueryError } from "@/errors";
15
- import { type framer } from "@/framer";
16
- import { type label } from "@/label";
17
- import { type Label } from "@/label/payload";
18
- import { ontology } from "@/ontology";
19
- import { type Alias, type Aliaser } from "@/ranger/alias";
20
- import { type KV } from "@/ranger/kv";
21
- import { type signals } from "@/signals";
22
-
23
- const ontologyID = (key: string): ontology.ID =>
24
- new ontology.ID({ type: "range", key });
25
-
26
- export class Range {
27
- key: string;
28
- name: string;
29
- readonly kv: KV;
30
- readonly timeRange: TimeRange;
31
- readonly color: string | undefined;
32
- readonly channels: ChannelRetriever;
33
- private readonly aliaser: Aliaser;
34
- private readonly frameClient: framer.Client;
35
- private readonly labelClient: label.Client;
36
-
37
- constructor(
38
- name: string,
39
- timeRange: TimeRange = TimeRange.ZERO,
40
- key: string,
41
- color: string | undefined,
42
- _frameClient: framer.Client,
43
- _kv: KV,
44
- _aliaser: Aliaser,
45
- _channels: ChannelRetriever,
46
- _labelClient: label.Client,
47
- ) {
48
- this.key = key;
49
- this.name = name;
50
- this.timeRange = timeRange;
51
- this.frameClient = _frameClient;
52
- this.color = color;
53
- this.kv = _kv;
54
- this.aliaser = _aliaser;
55
- this.channels = _channels;
56
- this.labelClient = _labelClient;
57
- }
58
-
59
- async setAlias(channel: Key | Name, alias: string): Promise<void> {
60
- const ch = await this.channels.retrieve(channel);
61
- if (ch.length === 0) {
62
- throw new QueryError(`Channel ${channel} does not exist`);
63
- }
64
- await this.aliaser.set({ [ch[0].key]: alias });
65
- }
66
-
67
- async deleteAlias(...channels: Key[]): Promise<void> {
68
- await this.aliaser.delete(channels);
69
- }
70
-
71
- async listAliases(): Promise<Record<Key, string>> {
72
- return await this.aliaser.list();
73
- }
74
-
75
- async openAliasTracker(): Promise<signals.Observable<string, Alias>> {
76
- return await this.aliaser.openChangeTracker();
77
- }
78
-
79
- async read(channel: Key | Name): Promise<Series>;
80
-
81
- async read(channels: Params): Promise<framer.Frame>;
82
-
83
- async read(channels: Params): Promise<Series | framer.Frame> {
84
- return await this.frameClient.read(this.timeRange, channels);
85
- }
86
-
87
- async labels(): Promise<Label[]> {
88
- return await this.labelClient.retrieveFor(ontologyID(this.key));
89
- }
90
-
91
- async addLabel(...labels: label.Key[]): Promise<void> {
92
- await this.labelClient.label(ontologyID(this.key), labels);
93
- }
94
-
95
- async removeLabel(...labels: label.Key[]): Promise<void> {
96
- await this.labelClient.removeLabels(ontologyID(this.key), labels);
97
- }
98
- }