@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,80 @@
|
|
|
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 { observe, type Destructor, type change, type Series } from "@synnaxlabs/x";
|
|
11
|
+
|
|
12
|
+
import { type channel } from "@/channel";
|
|
13
|
+
import { type framer } from "@/framer";
|
|
14
|
+
|
|
15
|
+
export type Decoder<K, V> = (
|
|
16
|
+
variant: change.Variant,
|
|
17
|
+
data: Series,
|
|
18
|
+
) => Array<change.Change<K, V>>;
|
|
19
|
+
|
|
20
|
+
export class Observable<K, V>
|
|
21
|
+
implements observe.Observable<Array<change.Change<K, V>>>
|
|
22
|
+
{
|
|
23
|
+
private readonly streamer: framer.Streamer;
|
|
24
|
+
private readonly decoder: Decoder<K, V>;
|
|
25
|
+
private readonly base: observe.Observer<Array<change.Change<K, V>>>;
|
|
26
|
+
private readonly closePromise: Promise<void>;
|
|
27
|
+
private readonly deleteChannel?: channel.Key | channel.Name;
|
|
28
|
+
private readonly setChannel?: channel.Key | channel.Name;
|
|
29
|
+
|
|
30
|
+
private constructor(
|
|
31
|
+
streamer: framer.Streamer,
|
|
32
|
+
ecd: Decoder<K, V>,
|
|
33
|
+
setChannel?: channel.Key | channel.Name,
|
|
34
|
+
deleteChannel?: channel.Key | channel.Name,
|
|
35
|
+
) {
|
|
36
|
+
this.streamer = streamer;
|
|
37
|
+
this.decoder = ecd;
|
|
38
|
+
this.base = new observe.Observer<Array<change.Change<K, V>>>();
|
|
39
|
+
this.closePromise = this.stream();
|
|
40
|
+
this.deleteChannel = deleteChannel;
|
|
41
|
+
this.setChannel = setChannel;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
onChange(handler: observe.Handler<Array<change.Change<K, V>>>): Destructor {
|
|
45
|
+
return this.base.onChange(handler);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async close(): Promise<void> {
|
|
49
|
+
this.streamer.close();
|
|
50
|
+
return await this.closePromise;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async stream(): Promise<void> {
|
|
54
|
+
for await (const frame of this.streamer) {
|
|
55
|
+
const changes: Array<change.Change<K, V>> = [];
|
|
56
|
+
if (this.deleteChannel != null) {
|
|
57
|
+
const deletes = frame.get(this.deleteChannel);
|
|
58
|
+
changes.push(...deletes.flatMap((s) => this.decoder("delete", s)));
|
|
59
|
+
}
|
|
60
|
+
if (this.setChannel != null) {
|
|
61
|
+
const sets = frame.get(this.setChannel);
|
|
62
|
+
changes.push(...sets.flatMap((s) => this.decoder("set", s)));
|
|
63
|
+
}
|
|
64
|
+
this.base.notify(changes);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
static async open<K, V>(
|
|
69
|
+
client: framer.Client,
|
|
70
|
+
setChannel: channel.Key | channel.Name,
|
|
71
|
+
deleteChannel: channel.Key | channel.Name,
|
|
72
|
+
ecd: Decoder<K, V>,
|
|
73
|
+
): Promise<Observable<K, V>> {
|
|
74
|
+
const stream = await client.newStreamer([
|
|
75
|
+
setChannel,
|
|
76
|
+
deleteChannel,
|
|
77
|
+
] as channel.Keys);
|
|
78
|
+
return new Observable(stream, ecd, setChannel, deleteChannel);
|
|
79
|
+
}
|
|
80
|
+
}
|
package/src/transport.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
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 {
|
|
11
|
+
HTTPClient,
|
|
12
|
+
WebSocketClient,
|
|
13
|
+
type Middleware,
|
|
14
|
+
type StreamClient,
|
|
15
|
+
type UnaryClient,
|
|
16
|
+
} from "@synnaxlabs/freighter";
|
|
17
|
+
import { binary, type URL } from "@synnaxlabs/x";
|
|
18
|
+
|
|
19
|
+
const baseAPIEndpoint = "/api/v1/";
|
|
20
|
+
|
|
21
|
+
export class Transport {
|
|
22
|
+
readonly url: URL;
|
|
23
|
+
readonly unary: UnaryClient;
|
|
24
|
+
readonly stream: StreamClient;
|
|
25
|
+
readonly secure: boolean;
|
|
26
|
+
|
|
27
|
+
constructor(url: URL, secure: boolean = false) {
|
|
28
|
+
this.secure = secure;
|
|
29
|
+
this.url = url.child(baseAPIEndpoint);
|
|
30
|
+
const ecd = new binary.JSONEncoderDecoder();
|
|
31
|
+
this.unary = new HTTPClient(this.url, ecd, this.secure);
|
|
32
|
+
this.stream = new WebSocketClient(this.url, ecd, this.secure);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
use(...middleware: Middleware[]): void {
|
|
36
|
+
this.unary.use(...middleware);
|
|
37
|
+
this.stream.use(...middleware);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
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 * as user from "@/user/payload";
|
|
@@ -0,0 +1,17 @@
|
|
|
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 { z } from "zod";
|
|
11
|
+
|
|
12
|
+
export const payloadZ = z.object({
|
|
13
|
+
key: z.string(),
|
|
14
|
+
username: z.string(),
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export type Payload = z.infer<typeof payloadZ>;
|
|
@@ -0,0 +1,19 @@
|
|
|
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, NativeTypedArray } from "@synnaxlabs/x";
|
|
11
|
+
|
|
12
|
+
export const randomSeries = (length: number, dataType: DataType): NativeTypedArray => {
|
|
13
|
+
// generate random bytes of the correct length
|
|
14
|
+
const bytes = new Uint8Array(length * dataType.density.valueOf());
|
|
15
|
+
for (let i = 0; i < bytes.byteLength; i++) {
|
|
16
|
+
bytes[i] = Math.floor(Math.random() * 256);
|
|
17
|
+
}
|
|
18
|
+
return new dataType.Array(bytes.buffer);
|
|
19
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
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
|
+
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
|
|
11
|
+
/// <reference types="vite/client" />
|
|
@@ -0,0 +1,75 @@
|
|
|
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 UnaryClient } from "@synnaxlabs/freighter";
|
|
11
|
+
import { type UnknownRecord, type AsyncTermSearcher } from "@synnaxlabs/x";
|
|
12
|
+
|
|
13
|
+
import { linePlot } from "@/workspace/lineplot";
|
|
14
|
+
import { type Key, type Workspace } from "@/workspace/payload";
|
|
15
|
+
import { pid } from "@/workspace/pid";
|
|
16
|
+
import { Retriever } from "@/workspace/retriever";
|
|
17
|
+
import { type CrudeWorkspace, Writer } from "@/workspace/writer";
|
|
18
|
+
|
|
19
|
+
export class Client implements AsyncTermSearcher<string, Key, Workspace> {
|
|
20
|
+
readonly pid: pid.Client;
|
|
21
|
+
readonly linePlot: linePlot.Client;
|
|
22
|
+
private readonly retriever: Retriever;
|
|
23
|
+
private readonly writer: Writer;
|
|
24
|
+
|
|
25
|
+
constructor(client: UnaryClient) {
|
|
26
|
+
this.pid = new pid.Client(client);
|
|
27
|
+
this.linePlot = new linePlot.Client(client);
|
|
28
|
+
this.retriever = new Retriever(client);
|
|
29
|
+
this.writer = new Writer(client);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
async search(term: string): Promise<Workspace[]> {
|
|
33
|
+
return await this.retriever.search(term);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async retrieveByAuthor(author: string): Promise<Workspace[]> {
|
|
37
|
+
return await this.retriever.retrieveByAuthor(author);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
async retrieve(key: Key): Promise<Workspace>;
|
|
41
|
+
|
|
42
|
+
async retrieve(keys: Key[]): Promise<Workspace[]>;
|
|
43
|
+
|
|
44
|
+
async retrieve(keys: Key | Key[]): Promise<Workspace | Workspace[]> {
|
|
45
|
+
const isMany = Array.isArray(keys);
|
|
46
|
+
const res = await this.retriever.retrieve(keys);
|
|
47
|
+
return isMany ? res : res[0];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async page(offset: number, limit: number): Promise<Workspace[]> {
|
|
51
|
+
return await this.retriever.page(offset, limit);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async create(workspace: CrudeWorkspace): Promise<Workspace>;
|
|
55
|
+
|
|
56
|
+
async create(
|
|
57
|
+
workspaces: CrudeWorkspace | CrudeWorkspace[],
|
|
58
|
+
): Promise<Workspace | Workspace[]> {
|
|
59
|
+
const isMany = Array.isArray(workspaces);
|
|
60
|
+
const res = await this.writer.create(workspaces);
|
|
61
|
+
return isMany ? res : res[0];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async rename(key: Key, name: string): Promise<void> {
|
|
65
|
+
await this.writer.rename(key, name);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async setLayout(key: Key, layout: UnknownRecord): Promise<void> {
|
|
69
|
+
await this.writer.setLayout(key, layout);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
async delete(...keys: Key[]): Promise<void> {
|
|
73
|
+
await this.writer.delete(keys);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
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 "@/workspace/payload";
|
|
11
|
+
export * from "@/workspace/client";
|
|
@@ -0,0 +1,10 @@
|
|
|
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 * as workspace from "@/workspace/external";
|
|
@@ -0,0 +1,51 @@
|
|
|
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 UnaryClient } from "@synnaxlabs/freighter";
|
|
11
|
+
import { type UnknownRecord } from "@synnaxlabs/x";
|
|
12
|
+
|
|
13
|
+
import { type LinePlot, type Key, type Params } from "@/workspace/lineplot/payload";
|
|
14
|
+
import { Retriever } from "@/workspace/lineplot/retriever";
|
|
15
|
+
import { type CrudeLinePlot, Writer } from "@/workspace/lineplot/writer";
|
|
16
|
+
|
|
17
|
+
export class Client {
|
|
18
|
+
private readonly writer: Writer;
|
|
19
|
+
private readonly retriever: Retriever;
|
|
20
|
+
|
|
21
|
+
constructor(client: UnaryClient) {
|
|
22
|
+
this.writer = new Writer(client);
|
|
23
|
+
this.retriever = new Retriever(client);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async create(workspace: string, pid: CrudeLinePlot): Promise<LinePlot> {
|
|
27
|
+
return await this.writer.create(workspace, pid);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
async rename(key: Key, name: string): Promise<void> {
|
|
31
|
+
await this.writer.rename(key, name);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
async setData(key: Key, data: UnknownRecord): Promise<void> {
|
|
35
|
+
await this.writer.setData(key, data);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async retrieve(key: Key): Promise<LinePlot>;
|
|
39
|
+
|
|
40
|
+
async retrieve(keys: Key[]): Promise<LinePlot[]>;
|
|
41
|
+
|
|
42
|
+
async retrieve(keys: Params): Promise<LinePlot | LinePlot[]> {
|
|
43
|
+
const isMany = Array.isArray(keys);
|
|
44
|
+
const res = await this.retriever.retrieve(keys);
|
|
45
|
+
return isMany ? res : res[0];
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async delete(keys: Params): Promise<void> {
|
|
49
|
+
await this.writer.delete(keys);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
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 "@/workspace/lineplot/payload";
|
|
11
|
+
export * from "@/workspace/lineplot/client";
|
|
@@ -0,0 +1,10 @@
|
|
|
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 * as linePlot from "@/workspace/lineplot/external";
|
|
@@ -0,0 +1,78 @@
|
|
|
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("LinePlot", () => {
|
|
19
|
+
describe("create", () => {
|
|
20
|
+
test("create one", async () => {
|
|
21
|
+
const ws = await client.workspaces.create({
|
|
22
|
+
name: "PID",
|
|
23
|
+
layout: { one: 1 },
|
|
24
|
+
});
|
|
25
|
+
const linePlot = await client.workspaces.linePlot.create(ws.key, {
|
|
26
|
+
name: "PID",
|
|
27
|
+
data: { one: 1 },
|
|
28
|
+
});
|
|
29
|
+
expect(linePlot.name).toEqual("PID");
|
|
30
|
+
expect(linePlot.key).not.toEqual(ZERO_UUID);
|
|
31
|
+
expect(linePlot.data.one).toEqual(1);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
describe("rename", () => {
|
|
35
|
+
test("rename one", async () => {
|
|
36
|
+
const ws = await client.workspaces.create({
|
|
37
|
+
name: "PID",
|
|
38
|
+
layout: { one: 1 },
|
|
39
|
+
});
|
|
40
|
+
const linePlot = await client.workspaces.linePlot.create(ws.key, {
|
|
41
|
+
name: "PID",
|
|
42
|
+
data: { one: 1 },
|
|
43
|
+
});
|
|
44
|
+
await client.workspaces.linePlot.rename(linePlot.key, "PID2");
|
|
45
|
+
const res = await client.workspaces.linePlot.retrieve(linePlot.key);
|
|
46
|
+
expect(res.name).toEqual("PID2");
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
describe("setData", () => {
|
|
50
|
+
test("set data", async () => {
|
|
51
|
+
const ws = await client.workspaces.create({
|
|
52
|
+
name: "PID",
|
|
53
|
+
layout: { one: 1 },
|
|
54
|
+
});
|
|
55
|
+
const linePlot = await client.workspaces.linePlot.create(ws.key, {
|
|
56
|
+
name: "PID",
|
|
57
|
+
data: { one: 1 },
|
|
58
|
+
});
|
|
59
|
+
await client.workspaces.linePlot.setData(linePlot.key, { two: 2 });
|
|
60
|
+
const res = await client.workspaces.linePlot.retrieve(linePlot.key);
|
|
61
|
+
expect(res.data.two).toEqual(2);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
describe("delete", () => {
|
|
65
|
+
test("delete one", async () => {
|
|
66
|
+
const ws = await client.workspaces.create({
|
|
67
|
+
name: "PID",
|
|
68
|
+
layout: { one: 1 },
|
|
69
|
+
});
|
|
70
|
+
const linePlot = await client.workspaces.linePlot.create(ws.key, {
|
|
71
|
+
name: "PID",
|
|
72
|
+
data: { one: 1 },
|
|
73
|
+
});
|
|
74
|
+
await client.workspaces.linePlot.delete(linePlot.key);
|
|
75
|
+
await expect(client.workspaces.linePlot.retrieve(linePlot.key)).rejects.toThrow();
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
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 UnknownRecord, unknownRecordZ } from "@synnaxlabs/x";
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
|
|
13
|
+
export const keyZ = z.string().uuid();
|
|
14
|
+
export type Key = z.infer<typeof keyZ>;
|
|
15
|
+
export type Params = Key | Key[];
|
|
16
|
+
|
|
17
|
+
export const linePlotZ = z.object({
|
|
18
|
+
key: z.string(),
|
|
19
|
+
name: z.string(),
|
|
20
|
+
data: unknownRecordZ,
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
export const linePlotRemoteZ = z.object({
|
|
24
|
+
key: z.string(),
|
|
25
|
+
name: z.string(),
|
|
26
|
+
data: z.string().transform((s) => JSON.parse(s) as UnknownRecord),
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
export type LinePlot = z.infer<typeof linePlotZ>;
|
|
@@ -0,0 +1,49 @@
|
|
|
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 UnaryClient } from "@synnaxlabs/freighter";
|
|
11
|
+
import { toArray } from "@synnaxlabs/x";
|
|
12
|
+
import { z } from "zod";
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
type LinePlot,
|
|
16
|
+
type Params,
|
|
17
|
+
linePlotRemoteZ,
|
|
18
|
+
} from "@/workspace/lineplot/payload";
|
|
19
|
+
|
|
20
|
+
const reqZ = z.object({
|
|
21
|
+
keys: z.string().array(),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
type Request = z.infer<typeof reqZ>;
|
|
25
|
+
|
|
26
|
+
const resZ = z.object({
|
|
27
|
+
linePlots: linePlotRemoteZ.array(),
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
export class Retriever {
|
|
31
|
+
private readonly ENDPOINT = "/workspace/lineplot/retrieve";
|
|
32
|
+
private readonly client: UnaryClient;
|
|
33
|
+
|
|
34
|
+
constructor(client: UnaryClient) {
|
|
35
|
+
this.client = client;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
async retrieve(params: Params): Promise<LinePlot[]> {
|
|
39
|
+
const normalized = toArray(params);
|
|
40
|
+
const res = await this.execute({ keys: normalized });
|
|
41
|
+
return res;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
private async execute(request: Request): Promise<LinePlot[]> {
|
|
45
|
+
const [res, err] = await this.client.send(this.ENDPOINT, request, resZ);
|
|
46
|
+
if (err != null) throw err;
|
|
47
|
+
return res.linePlots;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
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 {
|
|
15
|
+
linePlotZ,
|
|
16
|
+
type LinePlot,
|
|
17
|
+
type Params,
|
|
18
|
+
keyZ,
|
|
19
|
+
type Key,
|
|
20
|
+
linePlotRemoteZ,
|
|
21
|
+
} from "@/workspace/lineplot/payload";
|
|
22
|
+
import { keyZ as workspaceKeyZ } from "@/workspace/payload";
|
|
23
|
+
|
|
24
|
+
export const crudeLinePlotZ = linePlotZ.partial({ key: true });
|
|
25
|
+
export const linePlotWriteZ = linePlotRemoteZ.partial({ key: true });
|
|
26
|
+
|
|
27
|
+
export type CrudeLinePlot = z.infer<typeof crudeLinePlotZ>;
|
|
28
|
+
|
|
29
|
+
const createReqZ = z.object({
|
|
30
|
+
workspace: workspaceKeyZ,
|
|
31
|
+
linePlots: linePlotWriteZ.array(),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const createResZ = z.object({
|
|
35
|
+
linePlots: linePlotRemoteZ.array(),
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const deleteReqZ = z.object({
|
|
39
|
+
keys: keyZ.array(),
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const deleteResZ = z.object({});
|
|
43
|
+
|
|
44
|
+
const renameReqZ = z.object({
|
|
45
|
+
key: keyZ,
|
|
46
|
+
name: z.string(),
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const renameResZ = z.object({});
|
|
50
|
+
|
|
51
|
+
const setDataReqZ = z.object({
|
|
52
|
+
key: keyZ,
|
|
53
|
+
data: z.string(),
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const setDataResZ = z.object({});
|
|
57
|
+
|
|
58
|
+
const CREATE_ENDPOINT = "/workspace/lineplot/create";
|
|
59
|
+
const DELETE_ENDPOINT = "/workspace/lineplot/delete";
|
|
60
|
+
const RENAME_ENDPOINT = "/workspace/lineplot/rename";
|
|
61
|
+
const SET_DATA_ENDPOINT = "/workspace/lineplot/set-data";
|
|
62
|
+
|
|
63
|
+
export class Writer {
|
|
64
|
+
private readonly client: UnaryClient;
|
|
65
|
+
|
|
66
|
+
constructor(client: UnaryClient) {
|
|
67
|
+
this.client = client;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
async create(workspace: string, plot: CrudeLinePlot): Promise<LinePlot> {
|
|
71
|
+
const pid_ = { ...plot, data: JSON.stringify(plot.data) };
|
|
72
|
+
const res = await sendRequired<typeof createReqZ, typeof createResZ>(
|
|
73
|
+
this.client,
|
|
74
|
+
CREATE_ENDPOINT,
|
|
75
|
+
{ workspace, linePlots: [pid_] },
|
|
76
|
+
createResZ,
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
return res.linePlots[0];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async delete(params: Params): Promise<void> {
|
|
83
|
+
const normalized = toArray(params);
|
|
84
|
+
await sendRequired<typeof deleteReqZ, typeof deleteResZ>(
|
|
85
|
+
this.client,
|
|
86
|
+
DELETE_ENDPOINT,
|
|
87
|
+
{ keys: normalized },
|
|
88
|
+
deleteResZ,
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
async rename(pid: Key, name: string): Promise<void> {
|
|
93
|
+
await sendRequired<typeof renameReqZ, typeof renameResZ>(
|
|
94
|
+
this.client,
|
|
95
|
+
RENAME_ENDPOINT,
|
|
96
|
+
{ key: pid, name },
|
|
97
|
+
renameResZ,
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async setData(pid: Key, data: UnknownRecord): Promise<void> {
|
|
102
|
+
await sendRequired<typeof setDataReqZ, typeof setDataResZ>(
|
|
103
|
+
this.client,
|
|
104
|
+
SET_DATA_ENDPOINT,
|
|
105
|
+
{ key: pid, data: JSON.stringify(data) },
|
|
106
|
+
renameResZ,
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
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 UnknownRecord, unknownRecordZ } from "@synnaxlabs/x";
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
|
|
13
|
+
export const keyZ = z.string().uuid();
|
|
14
|
+
|
|
15
|
+
export type Key = z.infer<typeof keyZ>;
|
|
16
|
+
|
|
17
|
+
export type Params = Key | Key[];
|
|
18
|
+
|
|
19
|
+
export const workspaceZ = z.object({
|
|
20
|
+
name: z.string(),
|
|
21
|
+
key: keyZ,
|
|
22
|
+
layout: unknownRecordZ,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export const workspaceRemoteZ = workspaceZ.omit({ layout: true }).extend({
|
|
26
|
+
layout: z.string().transform((s) => JSON.parse(s) as UnknownRecord),
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
export type Workspace = z.infer<typeof workspaceZ>;
|