@synnaxlabs/client 0.18.2 → 0.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +5 -5
- package/dist/channel/client.d.ts +5 -4
- package/dist/channel/external.d.ts +1 -1
- package/dist/channel/payload.d.ts +2 -3
- package/dist/channel/writer.d.ts +21 -0
- package/dist/client.cjs +18 -18
- package/dist/client.cjs.map +1 -1
- package/dist/client.js +9179 -9168
- package/dist/client.js.map +1 -1
- package/examples/node/package-lock.json +8 -8
- package/examples/node/package.json +1 -1
- package/examples/node/seriesAndFrames.js +101 -2
- package/package.json +5 -5
- package/src/channel/channel.spec.ts +91 -33
- package/src/channel/client.ts +12 -6
- package/src/channel/external.ts +1 -1
- package/src/channel/payload.ts +1 -11
- package/src/channel/retriever.ts +1 -1
- package/src/channel/writer.ts +63 -0
- package/src/client.ts +1 -1
- package/src/framer/adapter.spec.ts +6 -6
- package/dist/channel/creator.d.ts +0 -8
- package/src/channel/creator.ts +0 -44
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"version": "1.0.0",
|
|
10
10
|
"license": "ISC",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@synnaxlabs/client": "^0.18.
|
|
12
|
+
"@synnaxlabs/client": "^0.18.2"
|
|
13
13
|
}
|
|
14
14
|
},
|
|
15
15
|
"node_modules/@grpc/grpc-js": {
|
|
@@ -3653,20 +3653,20 @@
|
|
|
3653
3653
|
}
|
|
3654
3654
|
},
|
|
3655
3655
|
"node_modules/@synnaxlabs/client": {
|
|
3656
|
-
"version": "0.18.
|
|
3657
|
-
"resolved": "https://registry.npmjs.org/@synnaxlabs/client/-/client-0.18.
|
|
3658
|
-
"integrity": "sha512-
|
|
3656
|
+
"version": "0.18.2",
|
|
3657
|
+
"resolved": "https://registry.npmjs.org/@synnaxlabs/client/-/client-0.18.2.tgz",
|
|
3658
|
+
"integrity": "sha512-y/uetgJq4zeB+7HTqFZyMkLYe1cV4iU0gRc90V/kYvVwTtWt0F5aB2kpZi5ta4nJTFFczPSUwzHOQNVm0zUZOQ==",
|
|
3659
3659
|
"dependencies": {
|
|
3660
3660
|
"@synnaxlabs/freighter": "0.9.3",
|
|
3661
|
-
"@synnaxlabs/x": "0.15.
|
|
3661
|
+
"@synnaxlabs/x": "0.15.2",
|
|
3662
3662
|
"async-mutex": "^0.4.0",
|
|
3663
3663
|
"zod": "3.22.4"
|
|
3664
3664
|
}
|
|
3665
3665
|
},
|
|
3666
3666
|
"node_modules/@synnaxlabs/client/node_modules/@synnaxlabs/x": {
|
|
3667
|
-
"version": "0.15.
|
|
3668
|
-
"resolved": "https://registry.npmjs.org/@synnaxlabs/x/-/x-0.15.
|
|
3669
|
-
"integrity": "sha512-
|
|
3667
|
+
"version": "0.15.2",
|
|
3668
|
+
"resolved": "https://registry.npmjs.org/@synnaxlabs/x/-/x-0.15.2.tgz",
|
|
3669
|
+
"integrity": "sha512-d0XP4tk7dx7847aeXppAFVCKLmPSGIWRnsyDvTkbU9rEZdt1XLnQh1+PoWBmlYUNtliGhcgOKkbCv3Tj9Di38Q==",
|
|
3670
3670
|
"dependencies": {
|
|
3671
3671
|
"async-mutex": "^0.4.0",
|
|
3672
3672
|
"js-convert-case": "^4.2.0",
|
|
@@ -60,5 +60,104 @@ const tr = new TimeRange(start, start.add(TimeSpan.seconds(5)));
|
|
|
60
60
|
series = new Series({
|
|
61
61
|
data: [1, 2, 3, 4, 5],
|
|
62
62
|
dataType: "float64",
|
|
63
|
-
timeRange: new TimeRange(
|
|
64
|
-
});
|
|
63
|
+
timeRange: new TimeRange(start, start.add(TimeSpan.seconds(6)))
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
series = new Series([1, 2, 3, 4, 5]);
|
|
67
|
+
console.log(series.length); // 5
|
|
68
|
+
|
|
69
|
+
const stringSeries = new Series(["apple", "banana", "cherry"]);
|
|
70
|
+
console.log(stringSeries.length); // 3
|
|
71
|
+
|
|
72
|
+
import { DataType } from "@synnaxlabs/client";
|
|
73
|
+
|
|
74
|
+
series = new Series([1, 2, 3, 4, 5]);
|
|
75
|
+
console.log(series.dataType.toString()); // "float64"
|
|
76
|
+
console.log(series.dataType.equals(DataType.STRING)); // true
|
|
77
|
+
|
|
78
|
+
series = new Series([1, 2, 3, 4, 5]);
|
|
79
|
+
console.log(series.max); // 5
|
|
80
|
+
console.log(series.min); // 1
|
|
81
|
+
console.log(series.bounds); // { lower: 1, upper: 5 }
|
|
82
|
+
|
|
83
|
+
import { Frame } from "@synnaxlabs/client";
|
|
84
|
+
|
|
85
|
+
// Construct a frame for the given channel names.
|
|
86
|
+
let frame = new Frame({
|
|
87
|
+
"channel1": new Series([1, 2, 3, 4, 5]),
|
|
88
|
+
"channel2": new Series([5, 4, 3, 2, 1]),
|
|
89
|
+
"channel3": new Series([1, 1, 1, 1, 1]),
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
// Construct a frame for the given channel keys
|
|
93
|
+
frame = new Frame({
|
|
94
|
+
1: new Series([1, 2, 3, 4, 5]),
|
|
95
|
+
2: new Series([5, 4, 3, 2, 1]),
|
|
96
|
+
// Notice that series do not need to be the same length.
|
|
97
|
+
3: new Series([1, 1, 1]),
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
// Construct a frame from a map
|
|
101
|
+
frame = new Frame(new Map([
|
|
102
|
+
["channel1", new Series([1, 2, 3, 4, 5])],
|
|
103
|
+
["channel2", new Series([5, 4, 3, 2, 1])],
|
|
104
|
+
["channel3", new Series([1, 1, 1, 1, 1])],
|
|
105
|
+
]));
|
|
106
|
+
|
|
107
|
+
// Or from an array of keys and series
|
|
108
|
+
frame = new Frame(["channel1", "channel2", "channel3"], [
|
|
109
|
+
new Series([1, 2, 3, 4, 5]),
|
|
110
|
+
new Series([5, 4, 3, 2, 1]),
|
|
111
|
+
new Series([1, 1, 1, 1, 1]),
|
|
112
|
+
]);
|
|
113
|
+
|
|
114
|
+
// Or construct a frame with multiple series for a single channel
|
|
115
|
+
frame = new Frame({
|
|
116
|
+
"channel1": [
|
|
117
|
+
new Series([1, 2, 3, 4, 5]),
|
|
118
|
+
new Series([5, 4, 3, 2, 1]),
|
|
119
|
+
new Series([1, 1, 1, 1, 1]),
|
|
120
|
+
],
|
|
121
|
+
"channel2": [
|
|
122
|
+
new Series([1, 2, 3, 4, 5]),
|
|
123
|
+
],
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
import { MultiSeries } from "@synnaxlabs/client";
|
|
127
|
+
|
|
128
|
+
frame = new Frame({
|
|
129
|
+
"channel1": [new Series([1, 2]), new Series([3, 4, 5])],
|
|
130
|
+
"channel2": new Series([5, 4, 3, 2, 1]),
|
|
131
|
+
"channel3": new Series([1, 1, 1, 1, 1]),
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
const multiSeries = frame.get("channel1");
|
|
135
|
+
// Access a value
|
|
136
|
+
console.log(multiSeries.at(0)); // 1
|
|
137
|
+
|
|
138
|
+
// Access a value from a specific series
|
|
139
|
+
console.log(multiSeries.series[0].at(0)); // 1
|
|
140
|
+
|
|
141
|
+
// Construct a Javascript array from the MultiSeries
|
|
142
|
+
jsArray = [...multiSeries];
|
|
143
|
+
console.log(jsArray); // [ 1, 2, 3, 4, 5 ]
|
|
144
|
+
|
|
145
|
+
frame = new Frame({
|
|
146
|
+
"channel1": new Series([1, 2, 3, 4, 5]),
|
|
147
|
+
"channel2": new Series([5, 4, 3, 2, 1]),
|
|
148
|
+
"channel3": new Series([1, 1]),
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
let obj = frame.at(3);
|
|
152
|
+
console.log(obj); // { channel1: 1, channel2: 5, channel3: undefined }
|
|
153
|
+
|
|
154
|
+
frame = new Frame({
|
|
155
|
+
"channel1": new Series([1, 2, 3, 4, 5]),
|
|
156
|
+
"channel2": new Series([5, 4, 3, 2, 1]),
|
|
157
|
+
"channel3": new Series([1, 1]),
|
|
158
|
+
});
|
|
159
|
+
try {
|
|
160
|
+
obj = frame.at(3, true); // Throws an error
|
|
161
|
+
} catch (e) {
|
|
162
|
+
console.log(e.message); // no value at index
|
|
163
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@synnaxlabs/client",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.19.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"description": "The Client Library for Synnax",
|
|
7
7
|
"repository": "https://github.com/synnaxlabs/synnax/tree/main/client/ts",
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"async-mutex": "^0.4.0",
|
|
20
20
|
"zod": "3.22.4",
|
|
21
|
-
"@synnaxlabs/
|
|
22
|
-
"@synnaxlabs/
|
|
21
|
+
"@synnaxlabs/x": "0.15.4",
|
|
22
|
+
"@synnaxlabs/freighter": "0.9.4"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
25
|
"@types/node": "^20.10.5",
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
"typescript": "^5.3.3",
|
|
29
29
|
"vite": "^5.1.2",
|
|
30
30
|
"vitest": "^1.2.2",
|
|
31
|
-
"
|
|
31
|
+
"eslint-config-synnaxlabs": "0.0.1",
|
|
32
32
|
"@synnaxlabs/vite-plugin": "0.0.1",
|
|
33
|
-
"
|
|
33
|
+
"@synnaxlabs/tsconfig": "0.0.2"
|
|
34
34
|
},
|
|
35
35
|
"main": "dist/client.cjs",
|
|
36
36
|
"module": "dist/client.js",
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
import { DataType, Rate, TimeStamp } from "@synnaxlabs/x";
|
|
11
11
|
import { describe, test, expect, it } from "vitest";
|
|
12
12
|
|
|
13
|
+
import { Channel } from "@/channel/client";
|
|
13
14
|
import { QueryError } from "@/errors";
|
|
14
15
|
import { newClient } from "@/setupspecs";
|
|
15
16
|
|
|
@@ -62,72 +63,102 @@ describe("Channel", () => {
|
|
|
62
63
|
expect(channels[0].name).toEqual("test1");
|
|
63
64
|
expect(channels[1].name).toEqual("test2");
|
|
64
65
|
});
|
|
66
|
+
test("create instances of channels", async () => {
|
|
67
|
+
const timeIndexChannel = await client.channels.create({
|
|
68
|
+
name: "time",
|
|
69
|
+
dataType: DataType.TIMESTAMP,
|
|
70
|
+
isIndex: true,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
const sensorOne = new Channel({
|
|
74
|
+
name: "sensor_one",
|
|
75
|
+
dataType: DataType.FLOAT32,
|
|
76
|
+
index: timeIndexChannel.key,
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const sensorTwo = new Channel({
|
|
80
|
+
name: "sensor_two",
|
|
81
|
+
dataType: DataType.FLOAT32,
|
|
82
|
+
index: timeIndexChannel.key,
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
const sensorThree = new Channel({
|
|
86
|
+
name: "sensor_three",
|
|
87
|
+
dataType: DataType.FLOAT32,
|
|
88
|
+
index: timeIndexChannel.key,
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
const sensors = await client.channels.create([sensorOne, sensorTwo, sensorThree]);
|
|
92
|
+
});
|
|
65
93
|
describe("retrieveIfNameExists", () => {
|
|
66
94
|
it("should retrieve the existing channel when it exists", async () => {
|
|
67
|
-
const name = `test-${Math.random()}-${TimeStamp.now().valueOf()}
|
|
95
|
+
const name = `test-${Math.random()}-${TimeStamp.now().valueOf()}`;
|
|
68
96
|
const channel = await client.channels.create({
|
|
69
97
|
name,
|
|
70
98
|
leaseholder: 1,
|
|
71
99
|
rate: Rate.hz(1),
|
|
72
100
|
dataType: DataType.FLOAT32,
|
|
73
101
|
});
|
|
74
|
-
const channelTwo = await client.channels.create(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
102
|
+
const channelTwo = await client.channels.create(
|
|
103
|
+
{
|
|
104
|
+
name,
|
|
105
|
+
leaseholder: 1,
|
|
106
|
+
rate: Rate.hz(1),
|
|
107
|
+
dataType: DataType.FLOAT32,
|
|
108
|
+
},
|
|
109
|
+
{ retrieveIfNameExists: true },
|
|
81
110
|
);
|
|
82
111
|
expect(channelTwo.key).toEqual(channel.key);
|
|
83
112
|
});
|
|
84
113
|
it("should create a new channel when it does not exist", async () => {
|
|
85
|
-
const name = `test-${Math.random()}-${TimeStamp.now().valueOf()}
|
|
114
|
+
const name = `test-${Math.random()}-${TimeStamp.now().valueOf()}`;
|
|
86
115
|
const channel = await client.channels.create({
|
|
87
116
|
name,
|
|
88
117
|
leaseholder: 1,
|
|
89
118
|
rate: Rate.hz(1),
|
|
90
119
|
dataType: DataType.FLOAT32,
|
|
91
120
|
});
|
|
92
|
-
const channelTwo = await client.channels.create(
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
121
|
+
const channelTwo = await client.channels.create(
|
|
122
|
+
{
|
|
123
|
+
name: `${name}-2`,
|
|
124
|
+
leaseholder: 1,
|
|
125
|
+
rate: Rate.hz(1),
|
|
126
|
+
dataType: DataType.FLOAT32,
|
|
127
|
+
},
|
|
128
|
+
{ retrieveIfNameExists: true },
|
|
99
129
|
);
|
|
100
130
|
expect(channelTwo.key).not.toEqual(channel.key);
|
|
101
131
|
});
|
|
102
132
|
it("should retrieve and create the correct channels when creating many", async () => {
|
|
103
|
-
const name = `test-${Math.random()}-${TimeStamp.now().valueOf()}
|
|
133
|
+
const name = `test-${Math.random()}-${TimeStamp.now().valueOf()}`;
|
|
104
134
|
const channel = await client.channels.create({
|
|
105
135
|
name,
|
|
106
136
|
leaseholder: 1,
|
|
107
137
|
rate: Rate.hz(1),
|
|
108
138
|
dataType: DataType.FLOAT32,
|
|
109
139
|
});
|
|
110
|
-
const channelTwo = await client.channels.create(
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
140
|
+
const channelTwo = await client.channels.create(
|
|
141
|
+
[
|
|
142
|
+
{
|
|
143
|
+
name,
|
|
144
|
+
leaseholder: 1,
|
|
145
|
+
rate: Rate.hz(1),
|
|
146
|
+
dataType: DataType.FLOAT32,
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
name: `${name}-2`,
|
|
150
|
+
leaseholder: 1,
|
|
151
|
+
rate: Rate.hz(1),
|
|
152
|
+
dataType: DataType.FLOAT32,
|
|
153
|
+
},
|
|
154
|
+
],
|
|
155
|
+
{ retrieveIfNameExists: true },
|
|
125
156
|
);
|
|
126
157
|
expect(channelTwo.length).toEqual(2);
|
|
127
158
|
expect(channelTwo[0].key).toEqual(channel.key);
|
|
128
159
|
expect(channelTwo[1].key).not.toEqual(channel.key);
|
|
129
160
|
});
|
|
130
|
-
})
|
|
161
|
+
});
|
|
131
162
|
});
|
|
132
163
|
test("retrieve by key", async () => {
|
|
133
164
|
const channel = await client.channels.create({
|
|
@@ -162,4 +193,31 @@ describe("Channel", () => {
|
|
|
162
193
|
expect(retrieved.length).toBeGreaterThan(0);
|
|
163
194
|
retrieved.forEach((ch) => expect(ch.name).toEqual("test"));
|
|
164
195
|
});
|
|
196
|
+
|
|
197
|
+
describe("delete", async () => {
|
|
198
|
+
test("delete by key", async () => {
|
|
199
|
+
const channel = await client.channels.create({
|
|
200
|
+
name: "test",
|
|
201
|
+
leaseholder: 1,
|
|
202
|
+
rate: Rate.hz(1),
|
|
203
|
+
dataType: DataType.FLOAT32,
|
|
204
|
+
});
|
|
205
|
+
await client.channels.delete(channel.key);
|
|
206
|
+
await expect(
|
|
207
|
+
async () => await client.channels.retrieve(channel.key),
|
|
208
|
+
).rejects.toThrow(QueryError);
|
|
209
|
+
});
|
|
210
|
+
test("delete by name", async () => {
|
|
211
|
+
const channel = await client.channels.create({
|
|
212
|
+
name: "test",
|
|
213
|
+
leaseholder: 1,
|
|
214
|
+
rate: Rate.hz(1),
|
|
215
|
+
dataType: DataType.FLOAT32,
|
|
216
|
+
});
|
|
217
|
+
await client.channels.delete(["test"]);
|
|
218
|
+
await expect(
|
|
219
|
+
async () => await client.channels.retrieve(channel.key),
|
|
220
|
+
).rejects.toThrow(QueryError);
|
|
221
|
+
});
|
|
222
|
+
});
|
|
165
223
|
});
|
package/src/channel/client.ts
CHANGED
|
@@ -20,7 +20,6 @@ import {
|
|
|
20
20
|
type CrudeTimeStamp,
|
|
21
21
|
} from "@synnaxlabs/x";
|
|
22
22
|
|
|
23
|
-
import { type Creator } from "@/channel/creator";
|
|
24
23
|
import {
|
|
25
24
|
type Key,
|
|
26
25
|
type KeyOrName,
|
|
@@ -36,6 +35,7 @@ import {
|
|
|
36
35
|
DebouncedBatchRetriever,
|
|
37
36
|
type Retriever,
|
|
38
37
|
} from "@/channel/retriever";
|
|
38
|
+
import { type Writer } from "@/channel/writer";
|
|
39
39
|
import { MultipleResultsError, NoResultsError, ValidationError } from "@/errors";
|
|
40
40
|
import { type framer } from "@/framer";
|
|
41
41
|
|
|
@@ -170,20 +170,20 @@ export class Channel {
|
|
|
170
170
|
*/
|
|
171
171
|
export class Client implements AsyncTermSearcher<string, Key, Channel> {
|
|
172
172
|
private readonly frameClient: framer.Client;
|
|
173
|
-
readonly retriever: Retriever;
|
|
174
|
-
private readonly creator: Creator;
|
|
175
173
|
private readonly client: UnaryClient;
|
|
174
|
+
readonly retriever: Retriever;
|
|
175
|
+
readonly writer: Writer;
|
|
176
176
|
|
|
177
177
|
constructor(
|
|
178
178
|
frameClient: framer.Client,
|
|
179
179
|
retriever: Retriever,
|
|
180
180
|
client: UnaryClient,
|
|
181
|
-
|
|
181
|
+
writer: Writer,
|
|
182
182
|
) {
|
|
183
183
|
this.frameClient = frameClient;
|
|
184
184
|
this.retriever = retriever;
|
|
185
185
|
this.client = client;
|
|
186
|
-
this.
|
|
186
|
+
this.writer = writer;
|
|
187
187
|
}
|
|
188
188
|
|
|
189
189
|
/**
|
|
@@ -261,7 +261,7 @@ export class Client implements AsyncTermSearcher<string, Key, Channel> {
|
|
|
261
261
|
toCreate = toCreate.filter((c) => !existingNames.has(c.name));
|
|
262
262
|
created = this.sugar(res);
|
|
263
263
|
}
|
|
264
|
-
created = created.concat(this.sugar(await this.
|
|
264
|
+
created = created.concat(this.sugar(await this.writer.create(toCreate)));
|
|
265
265
|
return single ? created[0] : created;
|
|
266
266
|
}
|
|
267
267
|
|
|
@@ -322,6 +322,12 @@ export class Client implements AsyncTermSearcher<string, Key, Channel> {
|
|
|
322
322
|
return res[0];
|
|
323
323
|
}
|
|
324
324
|
|
|
325
|
+
async delete(channels: Params): Promise<void> {
|
|
326
|
+
const { normalized, variant } = analyzeParams(channels);
|
|
327
|
+
if (variant === "keys") return await this.writer.delete({ keys: normalized });
|
|
328
|
+
return await this.writer.delete({ names: normalized });
|
|
329
|
+
}
|
|
330
|
+
|
|
325
331
|
async search(term: string, rangeKey?: string): Promise<Channel[]> {
|
|
326
332
|
return this.sugar(await this.retriever.search(term, rangeKey));
|
|
327
333
|
}
|
package/src/channel/external.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
// License, use of this software will be governed by the Apache License, Version 2.0,
|
|
8
8
|
// included in the file licenses/APL.txt.
|
|
9
9
|
|
|
10
|
-
export * from "@/channel/
|
|
10
|
+
export * from "@/channel/writer";
|
|
11
11
|
export * from "@/channel/client";
|
|
12
12
|
export * from "@/channel/payload";
|
|
13
13
|
export * from "@/channel/retriever";
|
package/src/channel/payload.ts
CHANGED
|
@@ -36,18 +36,8 @@ export const newPayload = payload.extend({
|
|
|
36
36
|
key: z.number().optional(),
|
|
37
37
|
leaseholder: z.number().optional(),
|
|
38
38
|
index: z.number().optional(),
|
|
39
|
-
rate: Rate.z.optional(),
|
|
39
|
+
rate: Rate.z.optional().default(0),
|
|
40
40
|
isIndex: z.boolean().optional(),
|
|
41
41
|
});
|
|
42
42
|
|
|
43
43
|
export type NewPayload = z.input<typeof newPayload>;
|
|
44
|
-
|
|
45
|
-
export const parseChannels = (channels: NewPayload[]): NewPayload[] =>
|
|
46
|
-
channels.map((channel) => ({
|
|
47
|
-
name: channel.name,
|
|
48
|
-
dataType: channel.dataType,
|
|
49
|
-
rate: channel.rate ?? 0,
|
|
50
|
-
leaseholder: channel.leaseholder,
|
|
51
|
-
index: channel.index,
|
|
52
|
-
isIndex: channel.isIndex,
|
|
53
|
-
}));
|
package/src/channel/retriever.ts
CHANGED
|
@@ -0,0 +1,63 @@
|
|
|
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 { z } from "zod";
|
|
12
|
+
|
|
13
|
+
import {
|
|
14
|
+
type Payload,
|
|
15
|
+
payload,
|
|
16
|
+
newPayload,
|
|
17
|
+
type NewPayload,
|
|
18
|
+
keyZ,
|
|
19
|
+
} from "@/channel/payload";
|
|
20
|
+
|
|
21
|
+
const createReqZ = z.object({ channels: newPayload.array() });
|
|
22
|
+
const createResZ = z.object({ channels: payload.array() });
|
|
23
|
+
|
|
24
|
+
const deleteReqZ = z.object({
|
|
25
|
+
keys: keyZ.array().optional(),
|
|
26
|
+
names: z.string().array().optional(),
|
|
27
|
+
});
|
|
28
|
+
const deleteResZ = z.object({});
|
|
29
|
+
|
|
30
|
+
const CREATE_ENDPOINT = "/channel/create";
|
|
31
|
+
const DELETE_ENDPOINT = "/channel/delete";
|
|
32
|
+
|
|
33
|
+
export type DeleteProps = z.input<typeof deleteReqZ>;
|
|
34
|
+
|
|
35
|
+
export class Writer {
|
|
36
|
+
private readonly client: UnaryClient;
|
|
37
|
+
|
|
38
|
+
constructor(client: UnaryClient) {
|
|
39
|
+
this.client = client;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
async create(channels: NewPayload[]): Promise<Payload[]> {
|
|
43
|
+
return (
|
|
44
|
+
await sendRequired<typeof createReqZ, typeof createResZ>(
|
|
45
|
+
this.client,
|
|
46
|
+
CREATE_ENDPOINT,
|
|
47
|
+
{ channels },
|
|
48
|
+
createReqZ,
|
|
49
|
+
createResZ,
|
|
50
|
+
)
|
|
51
|
+
).channels;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async delete(props: DeleteProps): Promise<void> {
|
|
55
|
+
await sendRequired<typeof deleteReqZ, typeof deleteResZ>(
|
|
56
|
+
this.client,
|
|
57
|
+
DELETE_ENDPOINT,
|
|
58
|
+
props,
|
|
59
|
+
deleteReqZ,
|
|
60
|
+
deleteResZ,
|
|
61
|
+
);
|
|
62
|
+
}
|
|
63
|
+
}
|
package/src/client.ts
CHANGED
|
@@ -94,7 +94,7 @@ export default class Synnax {
|
|
|
94
94
|
const chRetriever = new channel.CacheRetriever(
|
|
95
95
|
new channel.ClusterRetriever(this.transport.unary),
|
|
96
96
|
);
|
|
97
|
-
const chCreator = new channel.
|
|
97
|
+
const chCreator = new channel.Writer(this.transport.unary);
|
|
98
98
|
this.telem = new framer.Client(this.transport.stream, chRetriever);
|
|
99
99
|
this.channels = new channel.Client(
|
|
100
100
|
this.telem,
|
|
@@ -41,7 +41,7 @@ describe("WriteFrameAdapter", () => {
|
|
|
41
41
|
expect(res.series).toHaveLength(2);
|
|
42
42
|
expect(res.get(timeCh.key)).toHaveLength(1);
|
|
43
43
|
expect(res.get(dataCh.key)).toHaveLength(1);
|
|
44
|
-
expect(res.get(timeCh.key).at(0)).toEqual(
|
|
44
|
+
expect(res.get(timeCh.key).at(0)).toEqual(ts);
|
|
45
45
|
expect(res.get(dataCh.key).at(0)).toEqual(1);
|
|
46
46
|
});
|
|
47
47
|
|
|
@@ -55,7 +55,7 @@ describe("WriteFrameAdapter", () => {
|
|
|
55
55
|
expect(res2.series).toHaveLength(2);
|
|
56
56
|
expect(res2.get(timeCh.key)).toHaveLength(1);
|
|
57
57
|
expect(res2.get(dataCh.key)).toHaveLength(1);
|
|
58
|
-
expect(res2.get(timeCh.key).at(0)).toEqual(
|
|
58
|
+
expect(res2.get(timeCh.key).at(0)).toEqual(ts);
|
|
59
59
|
expect(res2.get(dataCh.key).at(0)).toEqual(1);
|
|
60
60
|
});
|
|
61
61
|
|
|
@@ -75,7 +75,7 @@ describe("WriteFrameAdapter", () => {
|
|
|
75
75
|
);
|
|
76
76
|
expect(res4.get(timeCh.key)).toHaveLength(1);
|
|
77
77
|
expect(res4.get(dataCh.key)).toHaveLength(1);
|
|
78
|
-
expect(res4.get(timeCh.key).at(0)).toEqual(
|
|
78
|
+
expect(res4.get(timeCh.key).at(0)).toEqual(ts);
|
|
79
79
|
expect(res4.get(dataCh.key).at(0)).toEqual(1);
|
|
80
80
|
});
|
|
81
81
|
|
|
@@ -88,7 +88,7 @@ describe("WriteFrameAdapter", () => {
|
|
|
88
88
|
const res = await adapter.adapt(fr);
|
|
89
89
|
expect(res.columns).toHaveLength(2);
|
|
90
90
|
expect(res.series).toHaveLength(2);
|
|
91
|
-
expect(res.get(timeCh.key).at(0)).toEqual(
|
|
91
|
+
expect(res.get(timeCh.key).at(0)).toEqual(ts);
|
|
92
92
|
expect(res.get(dataCh.key).at(0)).toEqual(1);
|
|
93
93
|
});
|
|
94
94
|
|
|
@@ -101,7 +101,7 @@ describe("WriteFrameAdapter", () => {
|
|
|
101
101
|
const res = await adapter.adapt(fr);
|
|
102
102
|
expect(res.columns).toHaveLength(2);
|
|
103
103
|
expect(res.series).toHaveLength(2);
|
|
104
|
-
expect(res.get(timeCh.key).at(0)).toEqual(
|
|
104
|
+
expect(res.get(timeCh.key).at(0)).toEqual(ts);
|
|
105
105
|
expect(res.get(dataCh.key).at(0)).toEqual(1);
|
|
106
106
|
});
|
|
107
107
|
|
|
@@ -113,6 +113,6 @@ describe("WriteFrameAdapter", () => {
|
|
|
113
113
|
expect(res.columns).toHaveLength(1);
|
|
114
114
|
expect(res.series).toHaveLength(1);
|
|
115
115
|
expect(res.get(timeCh.key)).toHaveLength(1);
|
|
116
|
-
expect(res.get(timeCh.key).at(0)).toEqual(
|
|
116
|
+
expect(res.get(timeCh.key).at(0)).toEqual(ts);
|
|
117
117
|
});
|
|
118
118
|
});
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { UnaryClient } from "@synnaxlabs/freighter";
|
|
2
|
-
import { type Payload, type NewPayload } from './payload';
|
|
3
|
-
export declare class Creator {
|
|
4
|
-
private static readonly ENDPOINT;
|
|
5
|
-
private readonly client;
|
|
6
|
-
constructor(client: UnaryClient);
|
|
7
|
-
create(channels: NewPayload[]): Promise<Payload[]>;
|
|
8
|
-
}
|
package/src/channel/creator.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
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 { z } from "zod";
|
|
12
|
-
|
|
13
|
-
import {
|
|
14
|
-
type Payload,
|
|
15
|
-
payload,
|
|
16
|
-
parseChannels,
|
|
17
|
-
newPayload,
|
|
18
|
-
type NewPayload,
|
|
19
|
-
} from "@/channel/payload";
|
|
20
|
-
|
|
21
|
-
const reqZ = z.object({ channels: newPayload.array() });
|
|
22
|
-
|
|
23
|
-
const resZ = z.object({ channels: payload.array() });
|
|
24
|
-
|
|
25
|
-
export class Creator {
|
|
26
|
-
private static readonly ENDPOINT = "/channel/create";
|
|
27
|
-
private readonly client: UnaryClient;
|
|
28
|
-
|
|
29
|
-
constructor(client: UnaryClient) {
|
|
30
|
-
this.client = client;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
async create(channels: NewPayload[]): Promise<Payload[]> {
|
|
34
|
-
const req = { channels: parseChannels(channels) };
|
|
35
|
-
const [res, err] = await this.client.send<typeof reqZ, typeof resZ>(
|
|
36
|
-
Creator.ENDPOINT,
|
|
37
|
-
req,
|
|
38
|
-
reqZ,
|
|
39
|
-
resZ,
|
|
40
|
-
);
|
|
41
|
-
if (err != null) throw err;
|
|
42
|
-
return res.channels;
|
|
43
|
-
}
|
|
44
|
-
}
|