@synnaxlabs/client 0.15.3 → 0.16.4
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/README.md +11 -2
- package/dist/channel/client.d.ts +147 -15
- package/dist/client.cjs +21 -0
- package/dist/client.cjs.map +1 -0
- package/dist/client.d.ts +1 -1
- package/dist/{client.es.js → client.js} +4782 -4656
- package/dist/client.js.map +1 -0
- package/dist/errors.d.ts +4 -0
- package/dist/ontology/payload.d.ts +38 -38
- package/examples/node/basicReadWriter.js +37 -0
- package/examples/node/package-lock.json +4961 -0
- package/examples/node/package.json +16 -0
- package/package.json +7 -7
- package/src/channel/channel.spec.ts +19 -2
- package/src/channel/client.ts +170 -38
- package/src/channel/payload.ts +2 -2
- package/src/client.ts +10 -5
- package/src/connection/checker.ts +5 -1
- package/src/errors.ts +4 -0
- package/src/framer/client.ts +6 -2
- package/src/framer/streamer.spec.ts +1 -0
- package/dist/client.cjs.js +0 -21
- package/dist/client.cjs.js.map +0 -1
- package/dist/client.es.js.map +0 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @synnaxlabs/client@0.
|
|
2
|
+
> @synnaxlabs/client@0.16.4 build /home/runner/work/synnax/synnax/client/ts
|
|
3
3
|
> tsc --noEmit && vite build
|
|
4
4
|
|
|
5
5
|
[36mvite v5.1.2 [32mbuilding for production...[36m[39m
|
|
@@ -9,8 +9,8 @@ rendering chunks...
|
|
|
9
9
|
[32m
|
|
10
10
|
[36m[vite:dts][32m Start generate declaration files...[39m
|
|
11
11
|
computing gzip size...
|
|
12
|
-
[2mdist/[22m[36mclient.
|
|
13
|
-
[32m[36m[vite:dts][32m Declaration files built in
|
|
12
|
+
[2mdist/[22m[36mclient.js [39m[1m[33m525.40 kB[39m[22m[2m │ gzip: 115.77 kB[22m[2m │ map: 1,305.16 kB[22m
|
|
13
|
+
[32m[36m[vite:dts][32m Declaration files built in 3559ms.
|
|
14
14
|
[39m
|
|
15
|
-
[2mdist/[22m[36mclient.cjs
|
|
16
|
-
[32m✓ built in 5.
|
|
15
|
+
[2mdist/[22m[36mclient.cjs [39m[1m[2m349.36 kB[22m[1m[22m[2m │ gzip: 92.12 kB[22m[2m │ map: 1,250.30 kB[22m
|
|
16
|
+
[32m✓ built in 5.09s[39m
|
package/README.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Synnax Client
|
|
2
|
+
|
|
3
|
+
A client library for interacting with a Synnax cluster. It supports Typescript and can be used in both node and browser environments.
|
|
4
|
+
|
|
5
|
+
Detailed documentation is available [here](https://docs.synnaxlabs.com/typescript-client/get-started]).
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @synnaxlabs/client
|
|
11
|
+
```
|
|
2
12
|
|
|
3
|
-
synnax Client Library
|
package/dist/channel/client.d.ts
CHANGED
|
@@ -1,28 +1,68 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type UnaryClient } from "@synnaxlabs/freighter";
|
|
2
|
+
import { DataType, Rate, type NativeTypedArray, type CrudeDensity, type Series, type TimeRange, type AsyncTermSearcher, type CrudeTimeStamp } from "@synnaxlabs/x";
|
|
2
3
|
import { type Creator } from './creator';
|
|
3
4
|
import { type Key, type KeyOrName, type Params, type Payload, type NewPayload } from './payload';
|
|
4
5
|
import { type Retriever } from './retriever';
|
|
5
6
|
import { type framer } from '../framer';
|
|
6
|
-
import { UnaryClient } from "@synnaxlabs/freighter";
|
|
7
7
|
/**
|
|
8
|
-
* Represents a Channel in a Synnax database.
|
|
9
|
-
* directly, but
|
|
8
|
+
* Represents a Channel in a Synnax database. Typically, channels should not be
|
|
9
|
+
* instantiated directly, but instead created via the `.channels.create` or retrieved
|
|
10
|
+
* via the `.channels.retrieve` method on a Synnax client.
|
|
11
|
+
*
|
|
12
|
+
* Please refer to the [Synnax documentation](https://docs.synnaxlabs.com) for detailed
|
|
13
|
+
* information on what channels are and how to use them.
|
|
10
14
|
*/
|
|
11
15
|
export declare class Channel {
|
|
12
16
|
private readonly _frameClient;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
/**
|
|
18
|
+
* A unique key identifying the channel in the Synnax database. This key is
|
|
19
|
+
* automatically assigned by Synnax.
|
|
20
|
+
*/
|
|
21
|
+
readonly key: Key;
|
|
22
|
+
/**
|
|
23
|
+
* A human-readable name for the channel. This name is not guaranteed to be
|
|
24
|
+
* unique.
|
|
25
|
+
*/
|
|
26
|
+
readonly name: string;
|
|
27
|
+
/**
|
|
28
|
+
* The rate at which the channel samples telemetry. This only applies to fixed rate
|
|
29
|
+
* channels, and will be 0 if the channel is indexed.
|
|
30
|
+
*/
|
|
31
|
+
readonly rate: Rate;
|
|
32
|
+
/**
|
|
33
|
+
* The data type of the channel.
|
|
34
|
+
*/
|
|
35
|
+
readonly dataType: DataType;
|
|
36
|
+
/**
|
|
37
|
+
* The key of the node in the Synnax cluster that holds the 'lease' over the channel
|
|
38
|
+
* i.e. it's the only node in the cluster allowed to accept writes to the channel. This
|
|
39
|
+
* property is mostly for internal use.
|
|
40
|
+
*/
|
|
41
|
+
readonly leaseholder: number;
|
|
42
|
+
/**
|
|
43
|
+
* The key of the index channel that this channel is associated with i.e. the channel
|
|
44
|
+
* that stores its timestamps.
|
|
45
|
+
*/
|
|
46
|
+
readonly index: Key;
|
|
47
|
+
/**
|
|
48
|
+
* This is set to true if the channel is an index channel, and false otherwise.
|
|
49
|
+
*/
|
|
50
|
+
readonly isIndex: boolean;
|
|
51
|
+
/**
|
|
52
|
+
* An alias for the channel under a specific range. This parameter is unstable and
|
|
53
|
+
* should not be relied upon in the current version of Synnax.
|
|
54
|
+
*/
|
|
55
|
+
readonly alias: string | undefined;
|
|
21
56
|
constructor({ dataType, rate, name, leaseholder, key, isIndex, index, frameClient, alias, }: NewPayload & {
|
|
22
57
|
frameClient?: framer.Client;
|
|
23
58
|
density?: CrudeDensity;
|
|
24
59
|
});
|
|
25
60
|
private get framer();
|
|
61
|
+
/**
|
|
62
|
+
* Returns the payload representation of this channel i.e. a pure JS object with
|
|
63
|
+
* all of the channel fields but without any methods. This is used internally for
|
|
64
|
+
* network transportation, but also provided to you as a convenience.
|
|
65
|
+
*/
|
|
26
66
|
get payload(): Payload;
|
|
27
67
|
/**
|
|
28
68
|
* Reads telemetry from the channel between the two timestamps.
|
|
@@ -38,21 +78,113 @@ export declare class Channel {
|
|
|
38
78
|
* @param start - The starting timestamp of the first sample in data.
|
|
39
79
|
* @param data - THe telemetry to write to the channel.
|
|
40
80
|
*/
|
|
41
|
-
write(start:
|
|
81
|
+
write(start: CrudeTimeStamp, data: NativeTypedArray): Promise<void>;
|
|
42
82
|
}
|
|
43
83
|
/**
|
|
44
84
|
* The core client class for executing channel operations against a Synnax
|
|
45
|
-
* cluster.
|
|
85
|
+
* cluster. This class should not be instantiated directly, and instead should be used
|
|
86
|
+
* through the `channels` property of an {@link Synnax} client.
|
|
46
87
|
*/
|
|
47
88
|
export declare class Client implements AsyncTermSearcher<string, Key, Channel> {
|
|
48
89
|
private readonly frameClient;
|
|
49
90
|
private readonly retriever;
|
|
50
91
|
private readonly creator;
|
|
51
92
|
private readonly client;
|
|
52
|
-
constructor(
|
|
93
|
+
constructor(frameClient: framer.Client, retriever: Retriever, client: UnaryClient, creator: Creator);
|
|
94
|
+
/**
|
|
95
|
+
* Creates a single channel with the given properties.
|
|
96
|
+
*
|
|
97
|
+
* @param name - A human-readable name for the channel.
|
|
98
|
+
* @param rate - The rate of the channel. This only applies to fixed rate channels.
|
|
99
|
+
* @param dataType - The data type for the samples stored in the channel.
|
|
100
|
+
* @param index - The key of the index channel that this channel should be associated
|
|
101
|
+
* with. An 'index' channel is a channel that stores timestamps for other channels. Refer
|
|
102
|
+
* to the Synnax documentation (https://docs.synnaxlabs.com) for more information. The
|
|
103
|
+
* index channel must have already been created. This field does not need to be specified
|
|
104
|
+
* if the channel is an index channel, or the channel is a fixed rate channel. If this
|
|
105
|
+
* value is specified, the 'rate' parameter will be ignored.
|
|
106
|
+
* @param isIndex - Set to true if the channel is an index channel, and false otherwise.
|
|
107
|
+
* Index channels must have a data type of `DataType.TIMESTAMP`.
|
|
108
|
+
* @returns the created channel. {@see Channel}
|
|
109
|
+
* @throws {ValidationError} if any of the parameters for creating the channel are
|
|
110
|
+
* invalid.
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* const indexChannel = await client.channels.create({
|
|
115
|
+
* name: "time",
|
|
116
|
+
* dataType: DataType.TIMESTAMP,
|
|
117
|
+
* isIndex: true,
|
|
118
|
+
* })
|
|
119
|
+
*
|
|
120
|
+
*
|
|
121
|
+
* const dataChannel = await client.channels.create({
|
|
122
|
+
* name: "temperature",
|
|
123
|
+
* dataType: DataType.FLOAT,
|
|
124
|
+
* index: indexChannel.key,
|
|
125
|
+
* });
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
53
128
|
create(channel: NewPayload): Promise<Channel>;
|
|
129
|
+
/**
|
|
130
|
+
* Creates multiple channels with the given properties. The order of the channels
|
|
131
|
+
* returned is guaranteed to match the order of the channels passed in.
|
|
132
|
+
*
|
|
133
|
+
* @param channels - An array of channel properties to create.
|
|
134
|
+
* For each channel, the following properties should be considered:
|
|
135
|
+
*
|
|
136
|
+
* @param name - A human-readable name for the channel.
|
|
137
|
+
* @param rate - The rate of the channel. This only applies to fixed rate channels. If
|
|
138
|
+
* the 'index' parameter is specified or 'isIndex' is set to true, this parameter will
|
|
139
|
+
* be ignored.
|
|
140
|
+
* @param dataType - The data type for the samples stored in the channel.
|
|
141
|
+
* @param index - The key of the index channel that this channel should be associated
|
|
142
|
+
* with. An 'index' channel is a channel that stores timestamps for other channels. Refer
|
|
143
|
+
* to the Synnax documentation (https://docs.synnaxlabs.com) for more information. The
|
|
144
|
+
* index channel must have already been created. This field does not need to be specified
|
|
145
|
+
* if the channel is an index channel, or the channel is a fixed rate channel. If this
|
|
146
|
+
* value is specified, the 'rate' parameter will be ignored.
|
|
147
|
+
* @param isIndex - Set to true if the channel is an index channel, and false otherwise.
|
|
148
|
+
* Index channels must have a data type of `DataType.TIMESTAMP`.
|
|
149
|
+
*
|
|
150
|
+
* @param channels
|
|
151
|
+
*/
|
|
54
152
|
create(channels: NewPayload[]): Promise<Channel[]>;
|
|
153
|
+
/**
|
|
154
|
+
* Retrieves a channel from the database using the given key or name.
|
|
155
|
+
*
|
|
156
|
+
* @param channel - The key or name of the channel to retrieve.
|
|
157
|
+
* @param options - Optional parameters to control the retrieval process.
|
|
158
|
+
* @param options.dataTypes - Limits the query to only channels with the specified data
|
|
159
|
+
* type.
|
|
160
|
+
* @param options.notDataTypes - Limits the query to only channels without the specified
|
|
161
|
+
* data type.
|
|
162
|
+
*
|
|
163
|
+
* @returns The retrieved channel.
|
|
164
|
+
* @throws {NotFoundError} if the channel does not exist in the cluster.
|
|
165
|
+
* @throws {MultipleResultsError} is only thrown if the channel is retrieved by name,
|
|
166
|
+
* and multiple channels with the same name exist in the cluster.
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
*
|
|
170
|
+
* ```typescript
|
|
171
|
+
* const channel = await client.channels.retrieve("temperature");
|
|
172
|
+
* const channel = await client.channels.retrieve(1);
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
55
175
|
retrieve(channel: KeyOrName, rangeKey?: string): Promise<Channel>;
|
|
176
|
+
/**
|
|
177
|
+
* Retrieves multiple channels from the database using the provided keys or the
|
|
178
|
+
* provided names.
|
|
179
|
+
*
|
|
180
|
+
* @param channels - The keys or the names of the channels to retrieve. Note that
|
|
181
|
+
* this method does not support mixing keys and names in the same call.
|
|
182
|
+
* @param options - Optional parameters to control the retrieval process.
|
|
183
|
+
* @param options.dataTypes - Limits the query to only channels with the specified data
|
|
184
|
+
* type.
|
|
185
|
+
* @param options.notDataTypes - Limits the query to only channels without the specified
|
|
186
|
+
*
|
|
187
|
+
*/
|
|
56
188
|
retrieve(channels: Params, rangeKey?: string): Promise<Channel[]>;
|
|
57
189
|
search(term: string, rangeKey?: string): Promise<Channel[]>;
|
|
58
190
|
newSearcherUnderRange(rangeKey?: string): AsyncTermSearcher<string, Key, Channel>;
|