@synnaxlabs/client 0.2.1 → 0.13.6
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/.eslintrc.cjs +18 -0
- package/.pytest_cache/README.md +8 -0
- package/.turbo/turbo-build.log +16 -0
- package/LICENSE +4 -21
- package/{build/module/lib → dist/auth}/auth.d.ts +16 -19
- package/dist/auth/index.d.ts +1 -0
- package/dist/cdc/external.d.ts +1 -0
- package/dist/cdc/index.d.ts +1 -0
- package/dist/cdc/observable.d.ts +17 -0
- package/dist/channel/client.d.ts +58 -0
- package/dist/channel/creator.d.ts +8 -0
- package/dist/channel/external.d.ts +4 -0
- package/dist/channel/index.d.ts +1 -0
- package/dist/channel/payload.d.ts +63 -0
- package/dist/channel/retriever.d.ts +49 -0
- package/dist/client.cjs.js +23050 -0
- package/dist/client.cjs.js.map +1 -0
- package/dist/client.d.ts +73 -0
- package/dist/client.es.js +23050 -0
- package/dist/client.es.js.map +1 -0
- package/dist/connection/checker.d.ts +66 -0
- package/dist/connection/index.d.ts +1 -0
- package/dist/control/authority.d.ts +6 -0
- package/dist/control/external.d.ts +2 -0
- package/dist/control/index.d.ts +1 -0
- package/dist/control/state.d.ts +81 -0
- package/{build/main/lib → dist}/errors.d.ts +6 -3
- package/dist/framer/adapter.d.ts +21 -0
- package/dist/framer/client.d.ts +44 -0
- package/dist/framer/external.d.ts +5 -0
- package/dist/framer/frame.d.ts +251 -0
- package/dist/framer/index.d.ts +1 -0
- package/{build/module/lib/segment → dist/framer}/iterator.d.ts +32 -64
- package/dist/framer/streamProxy.d.ts +12 -0
- package/dist/framer/streamer.d.ts +17 -0
- package/dist/framer/writer.d.ts +257 -0
- package/dist/index.d.ts +16 -0
- package/dist/label/client.d.ts +25 -0
- package/dist/label/external.d.ts +4 -0
- package/dist/label/index.d.ts +1 -0
- package/dist/label/payload.d.ts +20 -0
- package/dist/label/retriever.d.ts +13 -0
- package/dist/label/writer.d.ts +26 -0
- package/dist/ontology/cdc.d.ts +25 -0
- package/dist/ontology/client.d.ts +25 -0
- package/dist/ontology/external.d.ts +3 -0
- package/dist/ontology/group/client.d.ts +11 -0
- package/dist/ontology/group/external.d.ts +2 -0
- package/dist/ontology/group/group.d.ts +7 -0
- package/dist/ontology/group/index.d.ts +1 -0
- package/dist/ontology/group/payload.d.ts +40 -0
- package/dist/ontology/group/writer.d.ts +13 -0
- package/dist/ontology/index.d.ts +1 -0
- package/dist/ontology/ontology.spec.d.ts +1 -0
- package/dist/ontology/payload.d.ts +235 -0
- package/dist/ontology/retriever.d.ts +12 -0
- package/dist/ontology/signals.d.ts +25 -0
- package/dist/ontology/writer.d.ts +9 -0
- package/dist/ranger/active.d.ts +9 -0
- package/dist/ranger/alias.d.ts +32 -0
- package/dist/ranger/client.d.ts +31 -0
- package/dist/ranger/external.d.ts +6 -0
- package/dist/ranger/index.d.ts +1 -0
- package/dist/ranger/kv.d.ts +50 -0
- package/dist/ranger/payload.d.ts +94 -0
- package/dist/ranger/range.d.ts +29 -0
- package/dist/ranger/ranger.spec.d.ts +1 -0
- package/dist/ranger/retriever.d.ts +10 -0
- package/dist/ranger/writer.d.ts +9 -0
- package/{build/main → dist}/setupspecs.d.ts +2 -2
- package/dist/signals/external.d.ts +1 -0
- package/dist/signals/index.d.ts +1 -0
- package/dist/signals/observable.d.ts +17 -0
- package/dist/transport.d.ts +10 -0
- package/dist/user/index.d.ts +1 -0
- package/{build/main/lib → dist}/user/payload.d.ts +3 -3
- package/dist/util/telem.d.ts +2 -0
- package/dist/workspace/client.d.ts +22 -0
- package/dist/workspace/external.d.ts +2 -0
- package/dist/workspace/index.d.ts +1 -0
- package/dist/workspace/lineplot/client.d.ts +15 -0
- package/dist/workspace/lineplot/external.d.ts +2 -0
- package/dist/workspace/lineplot/index.d.ts +1 -0
- package/dist/workspace/lineplot/linePlot.spec.d.ts +1 -0
- package/dist/workspace/lineplot/payload.d.ts +31 -0
- package/dist/workspace/lineplot/retriever.d.ts +9 -0
- package/dist/workspace/lineplot/writer.d.ts +39 -0
- package/dist/workspace/payload.d.ts +31 -0
- package/dist/workspace/pid/client.d.ts +16 -0
- package/dist/workspace/pid/external.d.ts +2 -0
- package/dist/workspace/pid/index.d.ts +1 -0
- package/dist/workspace/pid/payload.d.ts +37 -0
- package/dist/workspace/pid/pid.spec.d.ts +1 -0
- package/dist/workspace/pid/retriever.d.ts +9 -0
- package/dist/workspace/pid/writer.d.ts +46 -0
- package/dist/workspace/retriever.d.ts +12 -0
- package/dist/workspace/workspace.spec.d.ts +1 -0
- package/dist/workspace/writer.d.ts +55 -0
- package/package.json +27 -98
- package/src/auth/auth.spec.ts +46 -0
- package/src/auth/auth.ts +83 -0
- package/src/auth/index.ts +10 -0
- package/src/channel/channel.spec.ts +82 -0
- package/src/channel/client.ts +209 -0
- package/src/channel/creator.ts +43 -0
- package/src/channel/external.ts +13 -0
- package/src/channel/index.ts +10 -0
- package/src/channel/payload.ts +52 -0
- package/src/channel/retriever.ts +160 -0
- package/src/client.ts +116 -0
- package/src/connection/checker.ts +104 -0
- package/src/connection/connection.spec.ts +35 -0
- package/src/connection/index.ts +10 -0
- package/src/control/authority.ts +26 -0
- package/src/control/external.ts +11 -0
- package/src/control/index.ts +10 -0
- package/src/control/state.spec.ts +24 -0
- package/src/control/state.ts +133 -0
- package/src/errors.ts +163 -0
- package/src/framer/adapter.ts +116 -0
- package/src/framer/client.ts +116 -0
- package/src/framer/external.ts +14 -0
- package/src/framer/frame.spec.ts +317 -0
- package/src/framer/frame.ts +412 -0
- package/src/framer/index.ts +10 -0
- package/src/framer/iterator.spec.ts +62 -0
- package/src/framer/iterator.ts +240 -0
- package/src/framer/streamProxy.ts +59 -0
- package/src/framer/streamer.spec.ts +42 -0
- package/src/framer/streamer.ts +86 -0
- package/src/framer/writer.spec.ts +52 -0
- package/src/framer/writer.ts +236 -0
- package/src/index.ts +53 -0
- package/src/label/client.ts +103 -0
- package/src/label/external.ts +13 -0
- package/src/label/index.ts +10 -0
- package/src/label/label.spec.ts +51 -0
- package/src/label/payload.ts +29 -0
- package/src/label/retriever.ts +65 -0
- package/src/label/writer.ts +90 -0
- package/src/ontology/client.ts +104 -0
- package/src/ontology/external.ts +12 -0
- package/src/ontology/group/client.ts +40 -0
- package/src/ontology/group/external.ts +11 -0
- package/src/ontology/group/group.spec.ts +46 -0
- package/src/ontology/group/group.ts +27 -0
- package/src/ontology/group/index.ts +10 -0
- package/src/ontology/group/payload.ts +65 -0
- package/src/ontology/group/writer.ts +48 -0
- package/src/ontology/index.ts +10 -0
- package/src/ontology/ontology.spec.ts +114 -0
- package/src/ontology/payload.ts +118 -0
- package/src/ontology/retriever.ts +91 -0
- package/src/ontology/signals.ts +135 -0
- package/src/ontology/writer.ts +49 -0
- package/src/ranger/active.ts +56 -0
- package/src/ranger/alias.ts +183 -0
- package/src/ranger/client.ts +129 -0
- package/src/ranger/external.ts +15 -0
- package/src/ranger/index.ts +10 -0
- package/src/ranger/kv.ts +91 -0
- package/src/ranger/payload.ts +70 -0
- package/src/ranger/range.ts +95 -0
- package/src/ranger/ranger.spec.ts +201 -0
- package/src/ranger/retriever.ts +50 -0
- package/src/ranger/writer.ts +80 -0
- package/src/setupspecs.ts +25 -0
- package/src/signals/external.ts +10 -0
- package/src/signals/index.ts +10 -0
- package/src/signals/observable.ts +80 -0
- package/src/transport.ts +39 -0
- package/src/user/index.ts +10 -0
- package/src/user/payload.ts +17 -0
- package/src/util/telem.ts +19 -0
- package/src/vite-env.d.ts +11 -0
- package/src/workspace/client.ts +75 -0
- package/src/workspace/external.ts +11 -0
- package/src/workspace/index.ts +10 -0
- package/src/workspace/lineplot/client.ts +51 -0
- package/src/workspace/lineplot/external.ts +11 -0
- package/src/workspace/lineplot/index.ts +10 -0
- package/src/workspace/lineplot/linePlot.spec.ts +78 -0
- package/src/workspace/lineplot/payload.ts +29 -0
- package/src/workspace/lineplot/retriever.ts +49 -0
- package/src/workspace/lineplot/writer.ts +109 -0
- package/src/workspace/payload.ts +29 -0
- package/src/workspace/pid/client.ts +55 -0
- package/src/workspace/pid/external.ts +11 -0
- package/src/workspace/pid/index.ts +10 -0
- package/src/workspace/pid/payload.ts +31 -0
- package/src/workspace/pid/pid.spec.ts +111 -0
- package/src/workspace/pid/retriever.ts +45 -0
- package/src/workspace/pid/writer.ts +130 -0
- package/src/workspace/retriever.ts +66 -0
- package/src/workspace/workspace.spec.ts +62 -0
- package/src/workspace/writer.ts +103 -0
- package/tsconfig.json +7 -0
- package/tsconfig.vite.json +4 -0
- package/vite.config.ts +25 -0
- package/CHANGELOG.md +0 -5
- package/build/main/index.d.ts +0 -4
- package/build/main/index.js +0 -35
- package/build/main/lib/auth.d.ts +0 -54
- package/build/main/lib/auth.js +0 -62
- package/build/main/lib/auth.spec.js +0 -39
- package/build/main/lib/channel/channel.spec.js +0 -49
- package/build/main/lib/channel/client.d.ts +0 -94
- package/build/main/lib/channel/client.js +0 -134
- package/build/main/lib/channel/creator.d.ts +0 -19
- package/build/main/lib/channel/creator.js +0 -44
- package/build/main/lib/channel/payload.d.ts +0 -25
- package/build/main/lib/channel/payload.js +0 -18
- package/build/main/lib/channel/registry.d.ts +0 -9
- package/build/main/lib/channel/registry.js +0 -37
- package/build/main/lib/channel/retriever.d.ts +0 -11
- package/build/main/lib/channel/retriever.js +0 -39
- package/build/main/lib/client.d.ts +0 -30
- package/build/main/lib/client.js +0 -46
- package/build/main/lib/errors.js +0 -122
- package/build/main/lib/segment/client.d.ts +0 -62
- package/build/main/lib/segment/client.js +0 -95
- package/build/main/lib/segment/iterator.d.ts +0 -134
- package/build/main/lib/segment/iterator.js +0 -253
- package/build/main/lib/segment/iterator.spec.js +0 -73
- package/build/main/lib/segment/payload.d.ts +0 -16
- package/build/main/lib/segment/payload.js +0 -13
- package/build/main/lib/segment/splitter.d.ts +0 -7
- package/build/main/lib/segment/splitter.js +0 -25
- package/build/main/lib/segment/typed.d.ts +0 -15
- package/build/main/lib/segment/typed.js +0 -49
- package/build/main/lib/segment/validator.d.ts +0 -22
- package/build/main/lib/segment/validator.js +0 -64
- package/build/main/lib/segment/writer.d.ts +0 -98
- package/build/main/lib/segment/writer.js +0 -183
- package/build/main/lib/segment/writer.spec.js +0 -90
- package/build/main/lib/telem.d.ts +0 -395
- package/build/main/lib/telem.js +0 -553
- package/build/main/lib/telem.spec.js +0 -152
- package/build/main/lib/transport.d.ts +0 -10
- package/build/main/lib/transport.js +0 -22
- package/build/main/lib/user/payload.js +0 -9
- package/build/main/lib/util/telem.d.ts +0 -2
- package/build/main/lib/util/telem.js +0 -13
- package/build/main/setupspecs.js +0 -17
- package/build/module/index.d.ts +0 -4
- package/build/module/index.js +0 -5
- package/build/module/lib/auth.js +0 -63
- package/build/module/lib/auth.spec.js +0 -34
- package/build/module/lib/channel/channel.spec.js +0 -44
- package/build/module/lib/channel/client.d.ts +0 -94
- package/build/module/lib/channel/client.js +0 -134
- package/build/module/lib/channel/creator.d.ts +0 -19
- package/build/module/lib/channel/creator.js +0 -42
- package/build/module/lib/channel/payload.d.ts +0 -25
- package/build/module/lib/channel/payload.js +0 -15
- package/build/module/lib/channel/registry.d.ts +0 -9
- package/build/module/lib/channel/registry.js +0 -36
- package/build/module/lib/channel/retriever.d.ts +0 -11
- package/build/module/lib/channel/retriever.js +0 -37
- package/build/module/lib/client.d.ts +0 -30
- package/build/module/lib/client.js +0 -44
- package/build/module/lib/errors.d.ts +0 -53
- package/build/module/lib/errors.js +0 -113
- package/build/module/lib/segment/client.d.ts +0 -62
- package/build/module/lib/segment/client.js +0 -94
- package/build/module/lib/segment/iterator.js +0 -248
- package/build/module/lib/segment/iterator.spec.js +0 -68
- package/build/module/lib/segment/payload.d.ts +0 -16
- package/build/module/lib/segment/payload.js +0 -10
- package/build/module/lib/segment/splitter.d.ts +0 -7
- package/build/module/lib/segment/splitter.js +0 -26
- package/build/module/lib/segment/typed.d.ts +0 -15
- package/build/module/lib/segment/typed.js +0 -49
- package/build/module/lib/segment/validator.d.ts +0 -22
- package/build/module/lib/segment/validator.js +0 -60
- package/build/module/lib/segment/writer.d.ts +0 -98
- package/build/module/lib/segment/writer.js +0 -183
- package/build/module/lib/segment/writer.spec.js +0 -85
- package/build/module/lib/telem.d.ts +0 -395
- package/build/module/lib/telem.js +0 -545
- package/build/module/lib/telem.spec.js +0 -147
- package/build/module/lib/transport.d.ts +0 -10
- package/build/module/lib/transport.js +0 -22
- package/build/module/lib/user/payload.d.ts +0 -12
- package/build/module/lib/user/payload.js +0 -6
- package/build/module/lib/util/telem.d.ts +0 -2
- package/build/module/lib/util/telem.js +0 -9
- package/build/module/setupspecs.d.ts +0 -4
- package/build/module/setupspecs.js +0 -16
- /package/{build/main/lib → dist/auth}/auth.spec.d.ts +0 -0
- /package/{build/main/lib → dist}/channel/channel.spec.d.ts +0 -0
- /package/{build/main/lib/segment/iterator.spec.d.ts → dist/connection/connection.spec.d.ts} +0 -0
- /package/{build/main/lib/segment/writer.spec.d.ts → dist/control/state.spec.d.ts} +0 -0
- /package/{build/main/lib/telem.spec.d.ts → dist/framer/frame.spec.d.ts} +0 -0
- /package/{build/module/lib/segment → dist/framer}/iterator.spec.d.ts +0 -0
- /package/{build/module/lib/auth.spec.d.ts → dist/framer/streamer.spec.d.ts} +0 -0
- /package/{build/module/lib/segment → dist/framer}/writer.spec.d.ts +0 -0
- /package/{build/module/lib/channel/channel.spec.d.ts → dist/label/label.spec.d.ts} +0 -0
- /package/{build/module/lib/telem.spec.d.ts → dist/ontology/group/group.spec.d.ts} +0 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// Copyright 2023 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 Key, type Name, type Params } from "@/channel/payload";
|
|
11
|
+
import { type Retriever, analyzeParams } from "@/channel/retriever";
|
|
12
|
+
import { type Frame } from "@/framer/frame";
|
|
13
|
+
|
|
14
|
+
export class BackwardFrameAdapter {
|
|
15
|
+
private adapter: Map<Key, Name> | null;
|
|
16
|
+
retriever: Retriever;
|
|
17
|
+
keys: Key[];
|
|
18
|
+
|
|
19
|
+
private constructor(retriever: Retriever) {
|
|
20
|
+
this.retriever = retriever;
|
|
21
|
+
this.adapter = null;
|
|
22
|
+
this.keys = [];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static async open(
|
|
26
|
+
retriever: Retriever,
|
|
27
|
+
channels: Params,
|
|
28
|
+
): Promise<BackwardFrameAdapter> {
|
|
29
|
+
const adapter = new BackwardFrameAdapter(retriever);
|
|
30
|
+
await adapter.update(channels);
|
|
31
|
+
return adapter;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async update(channels: Params): Promise<void> {
|
|
35
|
+
const { variant, normalized } = analyzeParams(channels);
|
|
36
|
+
if (variant === "keys") {
|
|
37
|
+
this.adapter = null;
|
|
38
|
+
this.keys = normalized;
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const fetched = await this.retriever.retrieve(normalized);
|
|
42
|
+
const a = new Map<Key, Name>();
|
|
43
|
+
this.adapter = a;
|
|
44
|
+
normalized.forEach((name) => {
|
|
45
|
+
const channel = fetched.find((channel) => channel.name === name);
|
|
46
|
+
if (channel == null) throw new Error(`Channel ${name} not found`);
|
|
47
|
+
a.set(channel.key, channel.name);
|
|
48
|
+
});
|
|
49
|
+
this.keys = Array.from(this.adapter.keys());
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
adapt(fr: Frame): Frame {
|
|
53
|
+
if (this.adapter == null) return fr;
|
|
54
|
+
const a = this.adapter;
|
|
55
|
+
return fr.map((k, arr) => {
|
|
56
|
+
if (typeof k === "number") {
|
|
57
|
+
const name = a.get(k);
|
|
58
|
+
if (name == null) throw new Error(`Channel ${k} not found`);
|
|
59
|
+
return [name, arr];
|
|
60
|
+
}
|
|
61
|
+
return [k, arr];
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export class ForwardFrameAdapter {
|
|
67
|
+
private adapter: Map<Name, Key> | null;
|
|
68
|
+
retriever: Retriever;
|
|
69
|
+
keys: Key[];
|
|
70
|
+
|
|
71
|
+
private constructor(retriever: Retriever) {
|
|
72
|
+
this.retriever = retriever;
|
|
73
|
+
this.adapter = null;
|
|
74
|
+
this.keys = [];
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
static async open(
|
|
78
|
+
retriever: Retriever,
|
|
79
|
+
channels: Params,
|
|
80
|
+
): Promise<ForwardFrameAdapter> {
|
|
81
|
+
const adapter = new ForwardFrameAdapter(retriever);
|
|
82
|
+
await adapter.update(channels);
|
|
83
|
+
return adapter;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async update(channels: Params): Promise<void> {
|
|
87
|
+
const { variant, normalized } = analyzeParams(channels);
|
|
88
|
+
if (variant === "keys") {
|
|
89
|
+
this.adapter = null;
|
|
90
|
+
this.keys = normalized;
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const fetched = await this.retriever.retrieve(normalized);
|
|
94
|
+
const a = new Map<Name, Key>();
|
|
95
|
+
this.adapter = a;
|
|
96
|
+
normalized.forEach((name) => {
|
|
97
|
+
const channel = fetched.find((channel) => channel.name === name);
|
|
98
|
+
if (channel == null) throw new Error(`Channel ${name} not found`);
|
|
99
|
+
a.set(channel.name, channel.key);
|
|
100
|
+
});
|
|
101
|
+
this.keys = fetched.map((c) => c.key);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
adapt(fr: Frame): Frame {
|
|
105
|
+
if (this.adapter == null) return fr;
|
|
106
|
+
const a = this.adapter;
|
|
107
|
+
return fr.map((k, arr) => {
|
|
108
|
+
if (typeof k === "string") {
|
|
109
|
+
const key = a.get(k);
|
|
110
|
+
if (key == null) throw new Error(`Channel ${k} not found`);
|
|
111
|
+
return [key, arr];
|
|
112
|
+
}
|
|
113
|
+
return [k, arr];
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// Copyright 2023 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 StreamClient } from "@synnaxlabs/freighter";
|
|
11
|
+
import {
|
|
12
|
+
type NativeTypedArray,
|
|
13
|
+
type Series,
|
|
14
|
+
type TimeRange,
|
|
15
|
+
type CrudeTimeStamp,
|
|
16
|
+
TimeStamp,
|
|
17
|
+
} from "@synnaxlabs/x";
|
|
18
|
+
|
|
19
|
+
import { type KeyOrName, type Params } from "@/channel/payload";
|
|
20
|
+
import { type Retriever, analyzeParams } from "@/channel/retriever";
|
|
21
|
+
import { Authority } from "@/control/authority";
|
|
22
|
+
import { Frame } from "@/framer/frame";
|
|
23
|
+
import { Iterator } from "@/framer/iterator";
|
|
24
|
+
import { Streamer } from "@/framer/streamer";
|
|
25
|
+
import { Writer, type WriterConfig } from "@/framer/writer";
|
|
26
|
+
|
|
27
|
+
export class Client {
|
|
28
|
+
private readonly stream: StreamClient;
|
|
29
|
+
private readonly retriever: Retriever;
|
|
30
|
+
|
|
31
|
+
constructor(stream: StreamClient, retriever: Retriever) {
|
|
32
|
+
this.stream = stream;
|
|
33
|
+
this.retriever = retriever;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Opens a new iterator over the given channels within the provided time range.
|
|
38
|
+
*
|
|
39
|
+
* @param tr - A time range to iterate over.
|
|
40
|
+
* @param keys - A list of channel keys to iterate over.
|
|
41
|
+
* @returns a new {@link TypedIterator}.
|
|
42
|
+
*/
|
|
43
|
+
async newIterator(tr: TimeRange, channels: Params): Promise<Iterator> {
|
|
44
|
+
return await Iterator._open(tr, channels, this.retriever, this.stream);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Opens a new writer on the given channels.
|
|
49
|
+
*
|
|
50
|
+
* @param keys - The keys of the channels to write to. A writer cannot write to
|
|
51
|
+
* a channel that is not in this list. See the {@link RecordWriter} documentation
|
|
52
|
+
* for more information.
|
|
53
|
+
* @returns a new {@link RecordWriter}.
|
|
54
|
+
*/
|
|
55
|
+
async newWriter({
|
|
56
|
+
start,
|
|
57
|
+
channels,
|
|
58
|
+
controlSubject,
|
|
59
|
+
authorities = Authority.ABSOLUTE,
|
|
60
|
+
}: WriterConfig): Promise<Writer> {
|
|
61
|
+
return await Writer._open(this.retriever, this.stream, {
|
|
62
|
+
start: start ?? TimeStamp.now(),
|
|
63
|
+
controlSubject,
|
|
64
|
+
channels,
|
|
65
|
+
authorities,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
async newStreamer(
|
|
70
|
+
params: Params,
|
|
71
|
+
from: TimeStamp = TimeStamp.now(),
|
|
72
|
+
): Promise<Streamer> {
|
|
73
|
+
return await Streamer._open(from, params, this.retriever, this.stream);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Writes telemetry to the given channel starting at the given timestamp.
|
|
78
|
+
*
|
|
79
|
+
* @param to - The key of the channel to write to.
|
|
80
|
+
* @param start - The starting timestamp of the first sample in data.
|
|
81
|
+
* @param data - The telemetry to write. This telemetry must have the same
|
|
82
|
+
* data type as the channel.
|
|
83
|
+
* @throws if the channel does not exist.
|
|
84
|
+
*/
|
|
85
|
+
async write(
|
|
86
|
+
to: KeyOrName,
|
|
87
|
+
start: CrudeTimeStamp,
|
|
88
|
+
data: NativeTypedArray,
|
|
89
|
+
): Promise<void> {
|
|
90
|
+
const w = await this.newWriter({ start, channels: to });
|
|
91
|
+
try {
|
|
92
|
+
await w.write(to, data);
|
|
93
|
+
if (!(await w.commit())) throw (await w.error()) as Error;
|
|
94
|
+
} catch {
|
|
95
|
+
await w.close();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
async read(tr: TimeRange, channel: KeyOrName): Promise<Series>;
|
|
100
|
+
|
|
101
|
+
async read(tr: TimeRange, channels: Params): Promise<Frame>;
|
|
102
|
+
|
|
103
|
+
async read(tr: TimeRange, channels: Params): Promise<Series | Frame> {
|
|
104
|
+
const { single } = analyzeParams(channels);
|
|
105
|
+
const fr = await this.readFrame(tr, channels);
|
|
106
|
+
if (single) return fr.series[0];
|
|
107
|
+
return fr;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
private async readFrame(tr: TimeRange, params: Params): Promise<Frame> {
|
|
111
|
+
const i = await this.newIterator(tr, params);
|
|
112
|
+
const frame = new Frame();
|
|
113
|
+
for await (const f of i) frame.push(f);
|
|
114
|
+
return frame;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Copyright 2023 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
|
+
export * from "@/framer/client";
|
|
11
|
+
export * from "@/framer/frame";
|
|
12
|
+
export * from "@/framer/iterator";
|
|
13
|
+
export * from "@/framer/streamer";
|
|
14
|
+
export * from "@/framer/writer";
|
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
// Copyright 2023 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 { DataType, Series, TimeRange } from "@synnaxlabs/x";
|
|
11
|
+
import { describe, expect, it, test } from "vitest";
|
|
12
|
+
|
|
13
|
+
import { framer } from "@/framer";
|
|
14
|
+
|
|
15
|
+
describe("framer.Frame", () => {
|
|
16
|
+
describe("construction", () => {
|
|
17
|
+
describe("valid", () => {
|
|
18
|
+
test("from an array of channel names and an array of arrays", () => {
|
|
19
|
+
const f = new framer.Frame(
|
|
20
|
+
["a", "b", "c"],
|
|
21
|
+
[
|
|
22
|
+
new Series(new Float32Array([1, 2, 3])),
|
|
23
|
+
new Series(new Float32Array([1, 2, 3])),
|
|
24
|
+
new Series(new Float32Array([1, 2, 3])),
|
|
25
|
+
],
|
|
26
|
+
);
|
|
27
|
+
expect(f.length).toEqual(9);
|
|
28
|
+
expect(f.colType).toEqual("name");
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
test("from an array of channel keys and an array of arrays", () => {
|
|
32
|
+
const f = new framer.Frame(
|
|
33
|
+
[12, 13, 14],
|
|
34
|
+
[
|
|
35
|
+
new Series(new Float32Array([1, 2, 3])),
|
|
36
|
+
new Series(new Float32Array([1, 2, 3])),
|
|
37
|
+
new Series(new Float32Array([1, 2, 3])),
|
|
38
|
+
],
|
|
39
|
+
);
|
|
40
|
+
expect(f.length).toEqual(9);
|
|
41
|
+
expect(f.colType).toEqual("key");
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test("from a single name and an array of arrays", () => {
|
|
45
|
+
const f = new framer.Frame("a", [new Series(new Float32Array([1, 2, 3]))]);
|
|
46
|
+
expect(f.length).toEqual(3);
|
|
47
|
+
expect(f.colType).toEqual("name");
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test("from a single key and an array of arrays", () => {
|
|
51
|
+
const f = new framer.Frame(12, [new Series(new Float32Array([1, 2, 3]))]);
|
|
52
|
+
expect(f.length).toEqual(3);
|
|
53
|
+
expect(f.colType).toEqual("key");
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test("from a single key and a single array", () => {
|
|
57
|
+
const f = new framer.Frame(12, new Series(new Float32Array([1, 2, 3])));
|
|
58
|
+
expect(f.length).toEqual(3);
|
|
59
|
+
expect(f.colType).toEqual("key");
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
test("from a single name and a single array", () => {
|
|
63
|
+
const f = new framer.Frame("a", new Series(new Float32Array([1, 2, 3])));
|
|
64
|
+
expect(f.length).toEqual(3);
|
|
65
|
+
expect(f.colType).toEqual("name");
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test("from payload", () => {
|
|
69
|
+
const f = new framer.Frame({
|
|
70
|
+
keys: [12],
|
|
71
|
+
series: [
|
|
72
|
+
{
|
|
73
|
+
dataType: new DataType("float32"),
|
|
74
|
+
data: new SharedArrayBuffer(12),
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
});
|
|
78
|
+
expect(f.length.valueOf()).toEqual(3);
|
|
79
|
+
expect(f.columns.length).toEqual(1);
|
|
80
|
+
expect(f.series.length).toEqual(1);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
test("from record", () => {
|
|
84
|
+
const f = new framer.Frame({
|
|
85
|
+
a: new Series(new Float32Array([1, 2, 3])),
|
|
86
|
+
});
|
|
87
|
+
expect(f.length.valueOf()).toEqual(3);
|
|
88
|
+
expect(f.columns.length).toEqual(1);
|
|
89
|
+
expect(f.series.length).toEqual(1);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test("from map", () => {
|
|
93
|
+
const f = new framer.Frame(
|
|
94
|
+
new Map([[12, new Series(new Float32Array([1, 2, 3]))]]),
|
|
95
|
+
);
|
|
96
|
+
expect(f.length).toEqual(3);
|
|
97
|
+
expect(f.columns.length).toEqual(1);
|
|
98
|
+
expect(f.series.length).toEqual(1);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
describe("invalid", () => {
|
|
103
|
+
test("mismatched lengths", () => {
|
|
104
|
+
expect(
|
|
105
|
+
() =>
|
|
106
|
+
new framer.Frame(
|
|
107
|
+
["a", "b", "c"],
|
|
108
|
+
[
|
|
109
|
+
new Series(new Float32Array([1, 2, 3])),
|
|
110
|
+
new Series(new Float32Array([1, 2, 3])),
|
|
111
|
+
],
|
|
112
|
+
),
|
|
113
|
+
).toThrow();
|
|
114
|
+
});
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
describe("vertical", () => {
|
|
119
|
+
it("should return false if a key has more than one array", () => {
|
|
120
|
+
const f = new framer.Frame(
|
|
121
|
+
new Map([
|
|
122
|
+
[12, [new Series(new Float32Array([1, 2, 3]))]],
|
|
123
|
+
[
|
|
124
|
+
13,
|
|
125
|
+
[
|
|
126
|
+
new Series(new Float32Array([1, 2, 3])),
|
|
127
|
+
new Series(new Float32Array([1, 2, 3])),
|
|
128
|
+
],
|
|
129
|
+
],
|
|
130
|
+
]),
|
|
131
|
+
);
|
|
132
|
+
expect(f.isVertical).toEqual(false);
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
describe("horizontal", () => {
|
|
137
|
+
it("should return false if there is more than one key", () => {
|
|
138
|
+
const f = new framer.Frame(
|
|
139
|
+
new Map([
|
|
140
|
+
[12, [new Series(new Float32Array([1, 2, 3]))]],
|
|
141
|
+
[13, [new Series(new Float32Array([1, 2, 3]))]],
|
|
142
|
+
]),
|
|
143
|
+
);
|
|
144
|
+
expect(f.isHorizontal).toEqual(false);
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
describe("weaklyAligned", () => {
|
|
149
|
+
it("should return true if all keys have the same timerange", () => {
|
|
150
|
+
const f = new framer.Frame(
|
|
151
|
+
new Map([
|
|
152
|
+
[
|
|
153
|
+
12,
|
|
154
|
+
[
|
|
155
|
+
new Series(
|
|
156
|
+
new Float32Array([1, 2, 3]),
|
|
157
|
+
undefined,
|
|
158
|
+
new TimeRange(500, 50000),
|
|
159
|
+
),
|
|
160
|
+
],
|
|
161
|
+
],
|
|
162
|
+
[
|
|
163
|
+
13,
|
|
164
|
+
[
|
|
165
|
+
new Series(
|
|
166
|
+
new Float32Array([1, 2, 3]),
|
|
167
|
+
undefined,
|
|
168
|
+
new TimeRange(500, 50000),
|
|
169
|
+
),
|
|
170
|
+
],
|
|
171
|
+
],
|
|
172
|
+
]),
|
|
173
|
+
);
|
|
174
|
+
expect(f.isWeaklyAligned).toEqual(true);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it("should return false if any key has a different timerange", () => {
|
|
178
|
+
const f = new framer.Frame(
|
|
179
|
+
new Map([
|
|
180
|
+
[
|
|
181
|
+
12,
|
|
182
|
+
[
|
|
183
|
+
new Series(
|
|
184
|
+
new Float32Array([1, 2, 3]),
|
|
185
|
+
undefined,
|
|
186
|
+
new TimeRange(500, 50000),
|
|
187
|
+
),
|
|
188
|
+
],
|
|
189
|
+
],
|
|
190
|
+
[
|
|
191
|
+
13,
|
|
192
|
+
[
|
|
193
|
+
new Series(
|
|
194
|
+
new Float32Array([1, 2, 3]),
|
|
195
|
+
undefined,
|
|
196
|
+
new TimeRange(500, 50001),
|
|
197
|
+
),
|
|
198
|
+
],
|
|
199
|
+
],
|
|
200
|
+
]),
|
|
201
|
+
);
|
|
202
|
+
expect(f.isWeaklyAligned).toEqual(false);
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
describe("timeRange", () => {
|
|
207
|
+
describe("no key provided", () => {
|
|
208
|
+
it("should return the maxium time range of the frame", () => {
|
|
209
|
+
const f = new framer.Frame(
|
|
210
|
+
new Map([
|
|
211
|
+
[
|
|
212
|
+
12,
|
|
213
|
+
[
|
|
214
|
+
new Series(
|
|
215
|
+
new Float32Array([1, 2, 3]),
|
|
216
|
+
undefined,
|
|
217
|
+
new TimeRange(40, 50000),
|
|
218
|
+
),
|
|
219
|
+
],
|
|
220
|
+
],
|
|
221
|
+
[
|
|
222
|
+
13,
|
|
223
|
+
[
|
|
224
|
+
new Series(
|
|
225
|
+
new Float32Array([1, 2, 3]),
|
|
226
|
+
undefined,
|
|
227
|
+
new TimeRange(500, 50001),
|
|
228
|
+
),
|
|
229
|
+
],
|
|
230
|
+
],
|
|
231
|
+
]),
|
|
232
|
+
);
|
|
233
|
+
expect(f.timeRange()).toEqual(new TimeRange(40, 50001));
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
describe("key provided", () => {
|
|
238
|
+
it("should return the time range of the key", () => {
|
|
239
|
+
const f = new framer.Frame({
|
|
240
|
+
a: new Series(
|
|
241
|
+
new Float32Array([1, 2, 3]),
|
|
242
|
+
undefined,
|
|
243
|
+
new TimeRange(40, 50000),
|
|
244
|
+
),
|
|
245
|
+
b: new Series(
|
|
246
|
+
new Float32Array([1, 2, 3]),
|
|
247
|
+
undefined,
|
|
248
|
+
new TimeRange(500, 50001),
|
|
249
|
+
),
|
|
250
|
+
});
|
|
251
|
+
expect(f.timeRange("a")).toEqual(new TimeRange(40, 50000));
|
|
252
|
+
});
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
describe("filter", () => {
|
|
256
|
+
it("should return a frame filtered on a particular condition", () => {
|
|
257
|
+
const f = new framer.Frame(
|
|
258
|
+
new Map([
|
|
259
|
+
[
|
|
260
|
+
12,
|
|
261
|
+
[
|
|
262
|
+
new Series(
|
|
263
|
+
new Float32Array([1, 2, 3]),
|
|
264
|
+
undefined,
|
|
265
|
+
new TimeRange(40, 50000),
|
|
266
|
+
),
|
|
267
|
+
],
|
|
268
|
+
],
|
|
269
|
+
[
|
|
270
|
+
13,
|
|
271
|
+
[
|
|
272
|
+
new Series(
|
|
273
|
+
new Float32Array([1, 2, 3]),
|
|
274
|
+
undefined,
|
|
275
|
+
new TimeRange(500, 50001),
|
|
276
|
+
),
|
|
277
|
+
],
|
|
278
|
+
],
|
|
279
|
+
]),
|
|
280
|
+
);
|
|
281
|
+
expect(f.filter((k) => k === 12).columns).toEqual([12]);
|
|
282
|
+
});
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
|
|
286
|
+
describe("toPayload", () => {
|
|
287
|
+
it("should return the frame as framer.FramePayload", () => {
|
|
288
|
+
const f = new framer.Frame(
|
|
289
|
+
new Map([
|
|
290
|
+
[
|
|
291
|
+
12,
|
|
292
|
+
[
|
|
293
|
+
new Series(
|
|
294
|
+
new Float32Array([1, 2, 3]),
|
|
295
|
+
undefined,
|
|
296
|
+
new TimeRange(40, 50000),
|
|
297
|
+
),
|
|
298
|
+
],
|
|
299
|
+
],
|
|
300
|
+
[
|
|
301
|
+
13,
|
|
302
|
+
[
|
|
303
|
+
new Series(
|
|
304
|
+
new Float32Array([1, 2, 3]),
|
|
305
|
+
undefined,
|
|
306
|
+
new TimeRange(500, 50001),
|
|
307
|
+
),
|
|
308
|
+
],
|
|
309
|
+
],
|
|
310
|
+
]),
|
|
311
|
+
);
|
|
312
|
+
const pld = f.toPayload();
|
|
313
|
+
expect(pld.keys).toEqual([12, 13]);
|
|
314
|
+
expect(pld.series?.[0].data.byteLength).toEqual(12);
|
|
315
|
+
});
|
|
316
|
+
});
|
|
317
|
+
});
|