@synnaxlabs/client 0.2.1 → 0.13.5
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/cdc/external.ts +10 -0
- package/src/cdc/index.ts +10 -0
- package/src/cdc/observable.ts +80 -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 +112 -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 +25 -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 +117 -0
- package/src/errors.ts +153 -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 +52 -0
- package/src/ontology/cdc.ts +135 -0
- package/src/ontology/client.ts +103 -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 +121 -0
- package/src/ontology/retriever.ts +91 -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 +124 -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 +74 -0
- package/src/ranger/ranger.spec.ts +167 -0
- package/src/ranger/retriever.ts +50 -0
- package/src/ranger/writer.ts +80 -0
- package/src/setupspecs.ts +25 -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 +67 -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,62 @@
|
|
|
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 { describe, test, expect } from "vitest";
|
|
11
|
+
|
|
12
|
+
import { newClient } from "@/setupspecs";
|
|
13
|
+
|
|
14
|
+
const client = newClient();
|
|
15
|
+
|
|
16
|
+
const ZERO_UUID = "00000000-0000-0000-0000-000000000000";
|
|
17
|
+
|
|
18
|
+
describe("Workspace", () => {
|
|
19
|
+
describe("create", () => {
|
|
20
|
+
test("create one", async () => {
|
|
21
|
+
const pid = await client.workspaces.create({
|
|
22
|
+
name: "PID",
|
|
23
|
+
layout: { one: 1 },
|
|
24
|
+
});
|
|
25
|
+
expect(pid.name).toEqual("PID");
|
|
26
|
+
expect(pid.key).not.toEqual(ZERO_UUID);
|
|
27
|
+
expect(pid.layout.one).toEqual(1);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
describe("rename", () => {
|
|
31
|
+
test("rename one", async () => {
|
|
32
|
+
const ws = await client.workspaces.create({
|
|
33
|
+
name: "PID",
|
|
34
|
+
layout: { one: 1 },
|
|
35
|
+
});
|
|
36
|
+
await client.workspaces.rename(ws.key, "PID2");
|
|
37
|
+
const res = await client.workspaces.retrieve(ws.key);
|
|
38
|
+
expect(res.name).toEqual("PID2");
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
describe("setLayout", () => {
|
|
42
|
+
test("set layout", async () => {
|
|
43
|
+
const ws = await client.workspaces.create({
|
|
44
|
+
name: "PID",
|
|
45
|
+
layout: { one: 1 },
|
|
46
|
+
});
|
|
47
|
+
await client.workspaces.setLayout(ws.key, { two: 2 });
|
|
48
|
+
const res = await client.workspaces.retrieve(ws.key);
|
|
49
|
+
expect(res.layout.two).toEqual(2);
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
describe("delete", () => {
|
|
53
|
+
test("delete one", async () => {
|
|
54
|
+
const ws = await client.workspaces.create({
|
|
55
|
+
name: "PID",
|
|
56
|
+
layout: { one: 1 },
|
|
57
|
+
});
|
|
58
|
+
await client.workspaces.delete(ws.key);
|
|
59
|
+
await expect(client.workspaces.retrieve(ws.key)).rejects.toThrow();
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
});
|
|
@@ -0,0 +1,103 @@
|
|
|
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 { sendRequired, type UnaryClient } from "@synnaxlabs/freighter";
|
|
11
|
+
import { toArray, type UnknownRecord } from "@synnaxlabs/x";
|
|
12
|
+
import { z } from "zod";
|
|
13
|
+
|
|
14
|
+
import { type Workspace, workspaceZ, keyZ, workspaceRemoteZ } from "./payload";
|
|
15
|
+
|
|
16
|
+
const crudeWorkspaceZ = workspaceZ.partial({ key: true });
|
|
17
|
+
const workspaceWriteZ = workspaceRemoteZ.partial({ key: true });
|
|
18
|
+
|
|
19
|
+
export type CrudeWorkspace = z.infer<typeof crudeWorkspaceZ>;
|
|
20
|
+
|
|
21
|
+
const createReqZ = z.object({
|
|
22
|
+
workspaces: workspaceWriteZ.partial({ key: true }).array(),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const createResZ = z.object({
|
|
26
|
+
workspaces: workspaceRemoteZ.array(),
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const deleteReqZ = z.object({
|
|
30
|
+
keys: keyZ.array(),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const deleteResZ = z.object({});
|
|
34
|
+
|
|
35
|
+
const renameReqZ = z.object({
|
|
36
|
+
key: keyZ,
|
|
37
|
+
name: z.string(),
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const renameResZ = z.object({});
|
|
41
|
+
|
|
42
|
+
const setLayoutReqZ = z.object({
|
|
43
|
+
key: keyZ,
|
|
44
|
+
layout: z.string(),
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const setLayoutResZ = z.object({});
|
|
48
|
+
|
|
49
|
+
export type Response = z.infer<typeof createResZ>;
|
|
50
|
+
|
|
51
|
+
const CREATE_ENDPOINT = "/workspace/create";
|
|
52
|
+
const DELETE_ENDPOINT = "/workspace/delete";
|
|
53
|
+
const RENAME_ENDPOINT = "/workspace/rename";
|
|
54
|
+
const SET_LAYOUT_ENDPOINT = "/workspace/set-layout";
|
|
55
|
+
|
|
56
|
+
export class Writer {
|
|
57
|
+
private readonly client: UnaryClient;
|
|
58
|
+
|
|
59
|
+
constructor(client: UnaryClient) {
|
|
60
|
+
this.client = client;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async create(workspaces: CrudeWorkspace | CrudeWorkspace[]): Promise<Workspace[]> {
|
|
64
|
+
const ws = toArray(workspaces).map((w) => ({
|
|
65
|
+
...w,
|
|
66
|
+
layout: JSON.stringify(w.layout),
|
|
67
|
+
}));
|
|
68
|
+
const res = await sendRequired<typeof createReqZ, typeof createResZ>(
|
|
69
|
+
this.client,
|
|
70
|
+
CREATE_ENDPOINT,
|
|
71
|
+
{ workspaces: ws },
|
|
72
|
+
createResZ,
|
|
73
|
+
);
|
|
74
|
+
return res.workspaces;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
async delete(keys: string | string[]): Promise<void> {
|
|
78
|
+
await sendRequired<typeof deleteReqZ, typeof deleteResZ>(
|
|
79
|
+
this.client,
|
|
80
|
+
DELETE_ENDPOINT,
|
|
81
|
+
{ keys: toArray(keys) },
|
|
82
|
+
deleteResZ,
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async rename(key: string, name: string): Promise<void> {
|
|
87
|
+
await sendRequired<typeof renameReqZ, typeof renameResZ>(
|
|
88
|
+
this.client,
|
|
89
|
+
RENAME_ENDPOINT,
|
|
90
|
+
{ key, name },
|
|
91
|
+
renameResZ,
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
async setLayout(key: string, layout: UnknownRecord): Promise<void> {
|
|
96
|
+
await sendRequired<typeof setLayoutReqZ, typeof setLayoutResZ>(
|
|
97
|
+
this.client,
|
|
98
|
+
SET_LAYOUT_ENDPOINT,
|
|
99
|
+
{ key, layout: JSON.stringify(layout) },
|
|
100
|
+
setLayoutResZ,
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
}
|
package/tsconfig.json
ADDED
package/vite.config.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
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 { lib } from "@synnaxlabs/vite-plugin";
|
|
11
|
+
import { defineConfig } from "vite";
|
|
12
|
+
|
|
13
|
+
export default defineConfig({
|
|
14
|
+
plugins: [lib({ name: "client" })],
|
|
15
|
+
build: {
|
|
16
|
+
minify: false,
|
|
17
|
+
rollupOptions: {
|
|
18
|
+
external: "zod",
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
test: {
|
|
22
|
+
globals: true,
|
|
23
|
+
environment: "jsdom",
|
|
24
|
+
},
|
|
25
|
+
});
|
package/CHANGELOG.md
DELETED
package/build/main/index.d.ts
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export { default as Synnax } from './lib/client';
|
|
2
|
-
export * from './lib/telem';
|
|
3
|
-
export { AuthError, ContiguityError, GeneralError, ParseError, QueryError, RouteError, UnexpectedError, ValidationError, } from './lib/errors';
|
|
4
|
-
export { Channel } from './lib/channel/client';
|
package/build/main/index.js
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
-
};
|
|
19
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
-
exports.Channel = exports.ValidationError = exports.UnexpectedError = exports.RouteError = exports.QueryError = exports.ParseError = exports.GeneralError = exports.ContiguityError = exports.AuthError = exports.Synnax = void 0;
|
|
21
|
-
var client_1 = require("./lib/client");
|
|
22
|
-
Object.defineProperty(exports, "Synnax", { enumerable: true, get: function () { return __importDefault(client_1).default; } });
|
|
23
|
-
__exportStar(require("./lib/telem"), exports);
|
|
24
|
-
var errors_1 = require("./lib/errors");
|
|
25
|
-
Object.defineProperty(exports, "AuthError", { enumerable: true, get: function () { return errors_1.AuthError; } });
|
|
26
|
-
Object.defineProperty(exports, "ContiguityError", { enumerable: true, get: function () { return errors_1.ContiguityError; } });
|
|
27
|
-
Object.defineProperty(exports, "GeneralError", { enumerable: true, get: function () { return errors_1.GeneralError; } });
|
|
28
|
-
Object.defineProperty(exports, "ParseError", { enumerable: true, get: function () { return errors_1.ParseError; } });
|
|
29
|
-
Object.defineProperty(exports, "QueryError", { enumerable: true, get: function () { return errors_1.QueryError; } });
|
|
30
|
-
Object.defineProperty(exports, "RouteError", { enumerable: true, get: function () { return errors_1.RouteError; } });
|
|
31
|
-
Object.defineProperty(exports, "UnexpectedError", { enumerable: true, get: function () { return errors_1.UnexpectedError; } });
|
|
32
|
-
Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return errors_1.ValidationError; } });
|
|
33
|
-
var client_2 = require("./lib/channel/client");
|
|
34
|
-
Object.defineProperty(exports, "Channel", { enumerable: true, get: function () { return client_2.Channel; } });
|
|
35
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7QUFBQSx1Q0FBaUQ7QUFBeEMsaUhBQUEsT0FBTyxPQUFVO0FBQzFCLDhDQUE0QjtBQUM1Qix1Q0FTc0I7QUFScEIsbUdBQUEsU0FBUyxPQUFBO0FBQ1QseUdBQUEsZUFBZSxPQUFBO0FBQ2Ysc0dBQUEsWUFBWSxPQUFBO0FBQ1osb0dBQUEsVUFBVSxPQUFBO0FBQ1Ysb0dBQUEsVUFBVSxPQUFBO0FBQ1Ysb0dBQUEsVUFBVSxPQUFBO0FBQ1YseUdBQUEsZUFBZSxPQUFBO0FBQ2YseUdBQUEsZUFBZSxPQUFBO0FBRWpCLCtDQUErQztBQUF0QyxpR0FBQSxPQUFPLE9BQUEifQ==
|
package/build/main/lib/auth.d.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { HTTPClientFactory, Middleware } from '@synnaxlabs/freighter';
|
|
2
|
-
import { z } from 'zod';
|
|
3
|
-
import { UserPayload } from './user/payload';
|
|
4
|
-
export declare const tokenMiddleware: (token: () => Promise<string>) => Middleware;
|
|
5
|
-
export declare const InsecureCredentialsSchema: z.ZodObject<{
|
|
6
|
-
username: z.ZodString;
|
|
7
|
-
password: z.ZodString;
|
|
8
|
-
}, "strip", z.ZodTypeAny, {
|
|
9
|
-
username: string;
|
|
10
|
-
password: string;
|
|
11
|
-
}, {
|
|
12
|
-
username: string;
|
|
13
|
-
password: string;
|
|
14
|
-
}>;
|
|
15
|
-
export declare type InsecureCredentials = z.infer<typeof InsecureCredentialsSchema>;
|
|
16
|
-
export declare const TokenResponseSchema: z.ZodObject<{
|
|
17
|
-
token: z.ZodString;
|
|
18
|
-
user: z.ZodObject<{
|
|
19
|
-
key: z.ZodString;
|
|
20
|
-
username: z.ZodString;
|
|
21
|
-
}, "strip", z.ZodTypeAny, {
|
|
22
|
-
username: string;
|
|
23
|
-
key: string;
|
|
24
|
-
}, {
|
|
25
|
-
username: string;
|
|
26
|
-
key: string;
|
|
27
|
-
}>;
|
|
28
|
-
}, "strip", z.ZodTypeAny, {
|
|
29
|
-
token: string;
|
|
30
|
-
user: {
|
|
31
|
-
username: string;
|
|
32
|
-
key: string;
|
|
33
|
-
};
|
|
34
|
-
}, {
|
|
35
|
-
token: string;
|
|
36
|
-
user: {
|
|
37
|
-
username: string;
|
|
38
|
-
key: string;
|
|
39
|
-
};
|
|
40
|
-
}>;
|
|
41
|
-
export declare type TokenResponse = z.infer<typeof TokenResponseSchema>;
|
|
42
|
-
export default class AuthenticationClient {
|
|
43
|
-
private static ENDPOINT;
|
|
44
|
-
private token;
|
|
45
|
-
private client;
|
|
46
|
-
private credentials;
|
|
47
|
-
authenticating: Promise<void> | undefined;
|
|
48
|
-
authenticated: boolean;
|
|
49
|
-
user: UserPayload | undefined;
|
|
50
|
-
constructor(factory: HTTPClientFactory, creds: InsecureCredentials);
|
|
51
|
-
authenticate(): void;
|
|
52
|
-
private maybeWaitAuthenticated;
|
|
53
|
-
middleware(): Middleware;
|
|
54
|
-
}
|
package/build/main/lib/auth.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.TokenResponseSchema = exports.InsecureCredentialsSchema = exports.tokenMiddleware = void 0;
|
|
4
|
-
const zod_1 = require("zod");
|
|
5
|
-
const errors_1 = require("./errors");
|
|
6
|
-
const payload_1 = require("./user/payload");
|
|
7
|
-
const tokenMiddleware = (token) => {
|
|
8
|
-
return async (md, next) => {
|
|
9
|
-
md.params['Authorization'] = `Bearer ${await token()}`;
|
|
10
|
-
return await next(md);
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
exports.tokenMiddleware = tokenMiddleware;
|
|
14
|
-
exports.InsecureCredentialsSchema = zod_1.z.object({
|
|
15
|
-
username: zod_1.z.string(),
|
|
16
|
-
password: zod_1.z.string(),
|
|
17
|
-
});
|
|
18
|
-
exports.TokenResponseSchema = zod_1.z.object({
|
|
19
|
-
token: zod_1.z.string(),
|
|
20
|
-
user: payload_1.UserPayloadSchema,
|
|
21
|
-
});
|
|
22
|
-
class AuthenticationClient {
|
|
23
|
-
constructor(factory, creds) {
|
|
24
|
-
this.client = factory.postClient();
|
|
25
|
-
this.credentials = creds;
|
|
26
|
-
this.authenticated = false;
|
|
27
|
-
this.authenticate();
|
|
28
|
-
}
|
|
29
|
-
authenticate() {
|
|
30
|
-
this.authenticating = new Promise((resolve, reject) => {
|
|
31
|
-
this.client
|
|
32
|
-
.send(AuthenticationClient.ENDPOINT, this.credentials, exports.TokenResponseSchema)
|
|
33
|
-
.then(([res, err]) => {
|
|
34
|
-
if (err) {
|
|
35
|
-
reject(err);
|
|
36
|
-
return;
|
|
37
|
-
}
|
|
38
|
-
this.token = res === null || res === void 0 ? void 0 : res.token;
|
|
39
|
-
this.user = res === null || res === void 0 ? void 0 : res.user;
|
|
40
|
-
this.authenticated = true;
|
|
41
|
-
resolve();
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
}
|
|
45
|
-
async maybeWaitAuthenticated() {
|
|
46
|
-
if (this.authenticating)
|
|
47
|
-
await this.authenticating;
|
|
48
|
-
this.authenticating = undefined;
|
|
49
|
-
}
|
|
50
|
-
middleware() {
|
|
51
|
-
return (0, exports.tokenMiddleware)(async () => {
|
|
52
|
-
await this.maybeWaitAuthenticated();
|
|
53
|
-
if (!this.token) {
|
|
54
|
-
throw new errors_1.AuthError('[auth] - attempting to authenticate without a token');
|
|
55
|
-
}
|
|
56
|
-
return this.token;
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
exports.default = AuthenticationClient;
|
|
61
|
-
AuthenticationClient.ENDPOINT = '/auth/login';
|
|
62
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXV0aC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uL3NyYy9saWIvYXV0aC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7QUFLQSw2QkFBd0I7QUFFeEIscUNBQXFDO0FBQ3JDLDRDQUFnRTtBQUV6RCxNQUFNLGVBQWUsR0FBRyxDQUFDLEtBQTRCLEVBQWMsRUFBRTtJQUMxRSxPQUFPLEtBQUssRUFBRSxFQUFFLEVBQUUsSUFBSSxFQUFFLEVBQUU7UUFDeEIsRUFBRSxDQUFDLE1BQU0sQ0FBQyxlQUFlLENBQUMsR0FBRyxVQUFVLE1BQU0sS0FBSyxFQUFFLEVBQUUsQ0FBQztRQUN2RCxPQUFPLE1BQU0sSUFBSSxDQUFDLEVBQUUsQ0FBQyxDQUFDO0lBQ3hCLENBQUMsQ0FBQztBQUNKLENBQUMsQ0FBQztBQUxXLFFBQUEsZUFBZSxtQkFLMUI7QUFFVyxRQUFBLHlCQUF5QixHQUFHLE9BQUMsQ0FBQyxNQUFNLENBQUM7SUFDaEQsUUFBUSxFQUFFLE9BQUMsQ0FBQyxNQUFNLEVBQUU7SUFDcEIsUUFBUSxFQUFFLE9BQUMsQ0FBQyxNQUFNLEVBQUU7Q0FDckIsQ0FBQyxDQUFDO0FBSVUsUUFBQSxtQkFBbUIsR0FBRyxPQUFDLENBQUMsTUFBTSxDQUFDO0lBQzF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QUFDLENBQUM7UUFDUCxDQUFDLENBQUMsQ0FBQztJQUNMLENBQUM7SUFFTyxLQUFLLENBQUMsc0JBQXNCO1FBQ2xDLElBQUksSUFBSSxDQUFDLGNBQWM7WUFBRSxNQUFNLElBQUksQ0FBQyxjQUFjLENBQUM7UUFDbkQsSUFBSSxDQUFDLGNBQWMsR0FBRyxTQUFTLENBQUM7SUFDbEMsQ0FBQztJQUVELFVBQVU7UUFDUixPQUFPLElBQUEsdUJBQWUsRUFBQyxLQUFLLElBQUksRUFBRTtZQUNoQyxNQUFNLElBQUksQ0FBQyxzQkFBc0IsRUFBRSxDQUFDO1lBQ3BDLElBQUksQ0FBQyxJQUFJLENBQUMsS0FBSyxFQUFFO2dCQUNmLE1BQU0sSUFBSSxrQkFBUyxDQUNqQixxREFBcUQsQ0FDdEQsQ0FBQzthQUNIO1lBQ0QsT0FBTyxJQUFJLENBQUMsS0FBSyxDQUFDO1FBQ3BCLENBQUMsQ0FBQyxDQUFDO0lBQ0wsQ0FBQzs7QUFwREgsdUNBcURDO0FBcERnQiw2QkFBUSxHQUFHLGFBQWEsQ0FBQyJ9
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const freighter_1 = require("@synnaxlabs/freighter");
|
|
7
|
-
const ava_1 = __importDefault(require("ava"));
|
|
8
|
-
const setupspecs_1 = require("../setupspecs");
|
|
9
|
-
const auth_1 = __importDefault(require("./auth"));
|
|
10
|
-
const errors_1 = require("./errors");
|
|
11
|
-
const transport_1 = __importDefault(require("./transport"));
|
|
12
|
-
(0, ava_1.default)('[auth] - valid credentials', async (t) => {
|
|
13
|
-
const transport = new transport_1.default(new freighter_1.URL({ host: setupspecs_1.HOST, port: setupspecs_1.PORT }));
|
|
14
|
-
const client = new auth_1.default(transport.httpFactory, {
|
|
15
|
-
username: 'synnax',
|
|
16
|
-
password: 'seldon',
|
|
17
|
-
});
|
|
18
|
-
await client.authenticating;
|
|
19
|
-
t.assert(client.authenticated);
|
|
20
|
-
});
|
|
21
|
-
(0, ava_1.default)('[auth] - invalid credentials', async (t) => {
|
|
22
|
-
const transport = new transport_1.default(new freighter_1.URL({ host: setupspecs_1.HOST, port: setupspecs_1.PORT }));
|
|
23
|
-
const client = new auth_1.default(transport.httpFactory, {
|
|
24
|
-
username: 'synnax',
|
|
25
|
-
password: 'wrong',
|
|
26
|
-
});
|
|
27
|
-
try {
|
|
28
|
-
await client.authenticating;
|
|
29
|
-
t.assert(false);
|
|
30
|
-
}
|
|
31
|
-
catch (e) {
|
|
32
|
-
t.assert(!client.authenticated);
|
|
33
|
-
t.assert(e instanceof errors_1.AuthError);
|
|
34
|
-
if (e instanceof errors_1.AuthError) {
|
|
35
|
-
t.is(e.message, '[synnax] - invalid credentials');
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiYXV0aC5zcGVjLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2xpYi9hdXRoLnNwZWMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7QUFBQSxxREFBNEM7QUFDNUMsOENBQXVCO0FBRXZCLDhDQUEyQztBQUUzQyxrREFBMEM7QUFDMUMscUNBQXFDO0FBQ3JDLDREQUFvQztBQUVwQyxJQUFBLGFBQUksRUFBQyw0QkFBNEIsRUFBRSxLQUFLLEVBQUUsQ0FBQyxFQUFFLEVBQUU7SUFDN0MsTUFBTSxTQUFTLEdBQUcsSUFBSSxtQkFBUyxDQUFDLElBQUksZUFBRyxDQUFDLEVBQUUsSUFBSSxFQUFFLGlCQUFJLEVBQUUsSUFBSSxFQUFF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TtZQUMxQixDQUFDLENBQUMsRUFBRSxDQUFDLENBQUMsQ0FBQyxPQUFPLEVBQUUsZ0NBQWdDLENBQUMsQ0FBQztTQUNuRDtLQUNGO0FBQ0gsQ0FBQyxDQUFDLENBQUMifQ==
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const ava_1 = __importDefault(require("ava"));
|
|
7
|
-
const setupspecs_1 = require("../../setupspecs");
|
|
8
|
-
const errors_1 = require("../errors");
|
|
9
|
-
const telem_1 = require("../telem");
|
|
10
|
-
const client = (0, setupspecs_1.newClient)();
|
|
11
|
-
(0, ava_1.default)('Channel - create', async (t) => {
|
|
12
|
-
const channel = await client.channel.create({
|
|
13
|
-
name: 'test',
|
|
14
|
-
nodeId: 1,
|
|
15
|
-
rate: telem_1.Rate.Hz(1),
|
|
16
|
-
dataType: telem_1.DataType.Float32,
|
|
17
|
-
});
|
|
18
|
-
t.is(channel.name, 'test');
|
|
19
|
-
t.is(channel.nodeId, 1);
|
|
20
|
-
t.deepEqual(channel.rate, telem_1.Rate.Hz(1));
|
|
21
|
-
t.deepEqual(channel.dataType, telem_1.DataType.Float32);
|
|
22
|
-
});
|
|
23
|
-
(0, ava_1.default)('Channel - retrieve by key', async (t) => {
|
|
24
|
-
const channel = await client.channel.create({
|
|
25
|
-
name: 'test',
|
|
26
|
-
nodeId: 1,
|
|
27
|
-
rate: telem_1.Rate.Hz(1),
|
|
28
|
-
dataType: telem_1.DataType.Float32,
|
|
29
|
-
});
|
|
30
|
-
const retrieved = (await client.channel.retrieveByKeys(channel.key))[0];
|
|
31
|
-
t.is(retrieved.name, 'test');
|
|
32
|
-
t.is(retrieved.nodeId, 1);
|
|
33
|
-
t.deepEqual(retrieved.rate, telem_1.Rate.Hz(1));
|
|
34
|
-
t.deepEqual(retrieved.dataType, telem_1.DataType.Float32);
|
|
35
|
-
});
|
|
36
|
-
(0, ava_1.default)('Channel - retrieve by key - not found', async (t) => {
|
|
37
|
-
const err = await t.throwsAsync(async () => {
|
|
38
|
-
await client.channel.retrieveByKeys('1-1000');
|
|
39
|
-
});
|
|
40
|
-
t.true(err instanceof errors_1.QueryError);
|
|
41
|
-
});
|
|
42
|
-
(0, ava_1.default)('Channel - retrieve by node id', async (t) => {
|
|
43
|
-
const retrieved = await client.channel.retrieveByNodeId(1);
|
|
44
|
-
t.true(retrieved.length > 0);
|
|
45
|
-
retrieved.forEach((ch) => {
|
|
46
|
-
t.is(ch.nodeId, 1);
|
|
47
|
-
});
|
|
48
|
-
});
|
|
49
|
-
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2hhbm5lbC5zcGVjLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vc3JjL2xpYi9jaGFubmVsL2NoYW5uZWwuc3BlYy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUFBLDhDQUF1QjtBQUV2QixpREFBNkM7QUFDN0Msc0NBQXVDO0FBQ3ZDLG9DQUEwQztBQUUxQyxNQUFNLE1BQU0sR0FBRyxJQUFBLHNCQUFTLEdBQUUsQ0FBQztBQUUzQixJQUFBLGFBQUksRUFBQyxrQkFBa0IsRUFBRSxLQUFLLEVBQUUsQ0FBQyxFQUFFLEVBQUU7SUFDbkMsTUFBTSxPQUFPLEdBQUcsTUFBTSxNQUFNLENBQUMsT0FBTyxDQUFDLE1BQU0sQ0FBQztRQUMxQyxJQUFJLEVBQUUsTUFBTTtRQUNaLE1BQU0sRUFBRSxDQUFDO1FBQ1QsSUFBSSxFQUFFLFlBQUksQ0FBQyxFQUFFLENBQUMsQ0FBQyxDQUFDO1FBQ2hCLFFBQVEsRUFBRSxnQkFBUSxDQUF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yxDQUFDO0FBQ0wsQ0FBQyxDQUFDLENBQUMifQ==
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
import SegmentClient from '../segment/client';
|
|
2
|
-
import { DataType, Density, Rate, TypedArray, UnparsedTimeStamp } from '../telem';
|
|
3
|
-
import ChannelCreator from './creator';
|
|
4
|
-
import { CreateChannelProps } from './creator';
|
|
5
|
-
import { ChannelPayload } from './payload';
|
|
6
|
-
import ChannelRetriever from './retriever';
|
|
7
|
-
/**
|
|
8
|
-
* Represents a Channel in a Synnax database. It should not be instantiated
|
|
9
|
-
* directly, but rather created or retrieved from a {@link ChannelClient}.
|
|
10
|
-
*/
|
|
11
|
-
export declare class Channel {
|
|
12
|
-
private readonly segmentClient;
|
|
13
|
-
private payload;
|
|
14
|
-
constructor(payload: ChannelPayload, segmentClient: SegmentClient);
|
|
15
|
-
get key(): string;
|
|
16
|
-
get name(): string;
|
|
17
|
-
get nodeId(): number;
|
|
18
|
-
get rate(): Rate;
|
|
19
|
-
get dataType(): DataType;
|
|
20
|
-
get density(): Density;
|
|
21
|
-
/**
|
|
22
|
-
* Reads telemetry from the channel between the two timestamps.
|
|
23
|
-
*
|
|
24
|
-
* @param start - The starting timestamp of the range to read from.
|
|
25
|
-
* @param end - The ending timestamp of the range to read from.
|
|
26
|
-
* @returns a typed array containing the retrieved
|
|
27
|
-
*/
|
|
28
|
-
read(start: UnparsedTimeStamp, end: UnparsedTimeStamp): Promise<TypedArray>;
|
|
29
|
-
/**
|
|
30
|
-
* Writes telemetry to the channel starting at the given timestamp.
|
|
31
|
-
*
|
|
32
|
-
* @param start - The starting timestamp of the first sample in data.
|
|
33
|
-
* @param data - THe telemetry to write to the channel.
|
|
34
|
-
*/
|
|
35
|
-
write(start: UnparsedTimeStamp, data: TypedArray): Promise<boolean>;
|
|
36
|
-
}
|
|
37
|
-
/** The core client class for executing channel operations against a Synnax
|
|
38
|
-
* database .
|
|
39
|
-
* */
|
|
40
|
-
export default class ChannelClient {
|
|
41
|
-
private readonly segmentClient;
|
|
42
|
-
private readonly retriever;
|
|
43
|
-
private readonly creator;
|
|
44
|
-
constructor(segmentClient: SegmentClient, retriever: ChannelRetriever, creator: ChannelCreator);
|
|
45
|
-
/**
|
|
46
|
-
* Creates a new channel with the given properties.
|
|
47
|
-
*
|
|
48
|
-
* @param props.rate - The rate of the channel.
|
|
49
|
-
* @param props.dataType - The data type of the channel.
|
|
50
|
-
* @param props.name - The name of the channel. Optional.
|
|
51
|
-
* @param props.nodeId - The ID of the node that holds the lease on the channel.
|
|
52
|
-
* If you don't know what this is, don't worry about it.
|
|
53
|
-
* @returns the created channel.
|
|
54
|
-
*/
|
|
55
|
-
create(props: CreateChannelProps): Promise<Channel>;
|
|
56
|
-
/**
|
|
57
|
-
* creates N channels using the given parameters as a template.
|
|
58
|
-
*
|
|
59
|
-
* @param props.rate - The rate of the channel.
|
|
60
|
-
* @param props.dataType - The data type of the channel.
|
|
61
|
-
* @param props.name - The name of the channel. Optional.
|
|
62
|
-
* @param props.nodeId - The ID of the node that holds the lease on the channel.
|
|
63
|
-
* If you don't know what this is, don't worry about it.
|
|
64
|
-
* @param props.count - The number of channels to create.
|
|
65
|
-
* @returns the created channels.
|
|
66
|
-
*/
|
|
67
|
-
createMany(props: CreateChannelProps & {
|
|
68
|
-
count: number;
|
|
69
|
-
}): Promise<Channel[]>;
|
|
70
|
-
/**
|
|
71
|
-
* Retrieves channels with the given keys.
|
|
72
|
-
*
|
|
73
|
-
* @param keys - The keys of the channels to retrieve.
|
|
74
|
-
* @throws QueryError if any of the channels can't be found.
|
|
75
|
-
* @returns the retrieved channels.
|
|
76
|
-
*/
|
|
77
|
-
retrieveByKeys(...keys: string[]): Promise<Channel[]>;
|
|
78
|
-
/**
|
|
79
|
-
* Retrieves channels with the given names.
|
|
80
|
-
*
|
|
81
|
-
* @param names - The list of names to retrieve channels for.
|
|
82
|
-
* @returns A list of retrieved channels matching the given names. If a channel
|
|
83
|
-
* with a given name can't be found, it will be omitted from the list.
|
|
84
|
-
*/
|
|
85
|
-
retrieveByNames(...names: string[]): Promise<Channel[]>;
|
|
86
|
-
/**
|
|
87
|
-
* Retrieves channels whose lease node is the given ID.
|
|
88
|
-
*
|
|
89
|
-
* @param nodeId - The ID of the node to retrieve channels for.
|
|
90
|
-
* @returns A list of retrieved channels matching the given node ID.
|
|
91
|
-
*/
|
|
92
|
-
retrieveByNodeId(nodeId: number): Promise<Channel[]>;
|
|
93
|
-
private sugar;
|
|
94
|
-
}
|