@synnaxlabs/client 0.26.0 → 0.26.1
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/client.cjs +2 -2
- package/dist/client.js +293 -270
- package/dist/framer/adapter.d.ts +2 -0
- package/dist/framer/adapter.d.ts.map +1 -1
- package/dist/framer/writer.d.ts +9 -6
- package/dist/framer/writer.d.ts.map +1 -1
- package/examples/node/basicReadWrite.js +28 -18
- package/examples/node/liveStream.js +7 -8
- package/examples/node/package-lock.json +2165 -2365
- package/examples/node/package.json +1 -1
- package/examples/node/seriesAndFrames.js +48 -47
- package/examples/node/streamWrite.js +34 -33
- package/package.json +3 -3
- package/src/framer/adapter.spec.ts +9 -0
- package/src/framer/adapter.ts +12 -0
- package/src/framer/client.ts +2 -2
- package/src/framer/writer.spec.ts +99 -14
- package/src/framer/writer.ts +56 -23
package/dist/framer/adapter.d.ts
CHANGED
|
@@ -18,8 +18,10 @@ export declare class WriteFrameAdapter {
|
|
|
18
18
|
keys: Key[];
|
|
19
19
|
private constructor();
|
|
20
20
|
static open(retriever: Retriever, channels: Params): Promise<WriteFrameAdapter>;
|
|
21
|
+
adaptObjectKeys<V>(data: Record<KeyOrName, V>): Promise<Record<Key, V>>;
|
|
21
22
|
update(channels: Params): Promise<void>;
|
|
22
23
|
private fetchChannel;
|
|
24
|
+
private adaptToKey;
|
|
23
25
|
adapt(columnsOrData: Params | Record<KeyOrName, CrudeSeries> | CrudeFrame, series?: CrudeSeries | CrudeSeries[]): Promise<Frame>;
|
|
24
26
|
}
|
|
25
27
|
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../../src/framer/adapter.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,KAAK,WAAW,EAAU,MAAM,qBAAqB,CAAC;AAE/D,OAAO,EACL,KAAK,GAAG,EACR,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OAAO,CAAC,OAAO,CAAwB;IACvC,SAAS,EAAE,SAAS,CAAC;IACrB,IAAI,EAAE,GAAG,EAAE,CAAC;IAEZ,OAAO;WAMM,IAAI,CAAC,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAM9E,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAkB7C,KAAK,CAAC,aAAa,EAAE,KAAK,GAAG,KAAK;CAYnC;AAED,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,OAAO,CAAwB;IACvC,SAAS,EAAE,SAAS,CAAC;IACrB,IAAI,EAAE,GAAG,EAAE,CAAC;IAEZ,OAAO;WAMM,IAAI,CACf,SAAS,EAAE,SAAS,EACpB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,iBAAiB,CAAC;IAMvB,eAAe,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;IAMvE,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;YAM/B,YAAY;YAMZ,UAAU;IAMlB,KAAK,CACT,aAAa,EAAE,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,WAAW,CAAC,GAAG,UAAU,EACnE,MAAM,CAAC,EAAE,WAAW,GAAG,WAAW,EAAE,GACnC,OAAO,CAAC,KAAK,CAAC;CA2ElB"}
|
package/dist/framer/writer.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { StreamClient } from '@synnaxlabs/freighter';
|
|
|
2
2
|
import { control } from '@synnaxlabs/x';
|
|
3
3
|
import { CrudeSeries, CrudeTimeStamp, TimeSpan, TimeStamp } from '@synnaxlabs/x/telem';
|
|
4
4
|
import { z } from 'zod';
|
|
5
|
-
import {
|
|
5
|
+
import { KeyOrName, KeysOrNames, Params } from '../channel/payload';
|
|
6
6
|
import { Retriever } from '../channel/retriever';
|
|
7
7
|
import { CrudeFrame } from './frame';
|
|
8
8
|
|
|
@@ -15,9 +15,10 @@ declare enum Command {
|
|
|
15
15
|
}
|
|
16
16
|
export declare enum WriterMode {
|
|
17
17
|
PersistStream = 1,
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
Persist = 2,
|
|
19
|
+
Stream = 3
|
|
20
20
|
}
|
|
21
|
+
export type CrudeWriterMode = "persist" | "stream" | "persistStream" | WriterMode;
|
|
21
22
|
export declare const ALWAYS_INDEX_PERSIST_ON_AUTO_COMMIT: TimeSpan;
|
|
22
23
|
declare const reqZ: z.ZodObject<{
|
|
23
24
|
command: z.ZodNativeEnum<typeof Command>;
|
|
@@ -269,7 +270,7 @@ export interface WriterConfig {
|
|
|
269
270
|
start?: CrudeTimeStamp;
|
|
270
271
|
controlSubject?: control.Subject;
|
|
271
272
|
authorities?: control.Authority | control.Authority[];
|
|
272
|
-
mode?:
|
|
273
|
+
mode?: CrudeWriterMode;
|
|
273
274
|
errOnUnauthorized?: boolean;
|
|
274
275
|
enableAutoCommit?: boolean;
|
|
275
276
|
autoIndexPersistInterval?: TimeSpan;
|
|
@@ -322,10 +323,12 @@ export declare class Writer {
|
|
|
322
323
|
write(channel: KeysOrNames, data: CrudeSeries[]): Promise<boolean>;
|
|
323
324
|
write(frame: CrudeFrame | Record<KeyOrName, CrudeSeries>): Promise<boolean>;
|
|
324
325
|
write(channelsOrData: Params | Record<KeyOrName, CrudeSeries> | CrudeFrame, series?: CrudeSeries | CrudeSeries[]): Promise<boolean>;
|
|
325
|
-
setAuthority(value:
|
|
326
|
+
setAuthority(value: number): Promise<boolean>;
|
|
327
|
+
setAuthority(key: KeyOrName, authority: control.Authority): Promise<boolean>;
|
|
328
|
+
setAuthority(value: Record<KeyOrName, control.Authority>): Promise<boolean>;
|
|
326
329
|
/**
|
|
327
330
|
* Commits the written frames to the database. Commit is synchronous, meaning that it
|
|
328
|
-
* will not return until all frames have been
|
|
331
|
+
* will not return until all frames have been committed to the database.
|
|
329
332
|
*
|
|
330
333
|
* @returns false if the commit failed due to an error. In this case, the caller
|
|
331
334
|
* should acknowledge the error by calling the error method or closing the writer.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"writer.d.ts","sourceRoot":"","sources":["../../src/framer/writer.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"writer.d.ts","sourceRoot":"","sources":["../../src/framer/writer.ts"],"names":[],"mappings":"AASA,OAAO,EAIL,KAAK,YAAY,EAClB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EACL,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,QAAQ,EACR,SAAS,EACV,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,WAAW,EAAE,KAAK,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAClF,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAErD,OAAO,EAAE,KAAK,UAAU,EAAU,MAAM,gBAAgB,CAAC;AAGzD,aAAK,OAAO;IACV,IAAI,IAAI;IACR,KAAK,IAAI;IACT,MAAM,IAAI;IACV,KAAK,IAAI;IACT,YAAY,IAAI;CACjB;AAED,oBAAY,UAAU;IACpB,aAAa,IAAI;IACjB,OAAO,IAAI;IACX,MAAM,IAAI;CACX;AAED,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,QAAQ,GAAG,eAAe,GAAG,UAAU,CAAC;AAelF,eAAO,MAAM,mCAAmC,EAAE,QAA2B,CAAC;AAe9E,QAAA,MAAM,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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IAoBZ,KAAK,CAAC,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC;IAE9D,KAAK,CAAC,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IAElE,KAAK,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAAC,SAAS,EAAE,WAAW,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;IAE3E,KAAK,CACT,cAAc,EAAE,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,WAAW,CAAC,GAAG,UAAU,EACpE,MAAM,CAAC,EAAE,WAAW,GAAG,WAAW,EAAE,GACnC,OAAO,CAAC,OAAO,CAAC;IA0Bb,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAE7C,YAAY,CAAC,GAAG,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,GAAG,OAAO,CAAC,OAAO,CAAC;IAE5E,YAAY,CAAC,KAAK,EAAE,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;IAwBjF;;;;;;;OAOG;IACG,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC;IAMhC;;;OAGG;IACG,KAAK,IAAI,OAAO,CAAC,KAAK,GAAG,IAAI,CAAC;IAMpC;;;;OAIG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAItB,OAAO,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,QAAQ,CAAC;IAU9C,OAAO,KAAK,gBAAgB,GAE3B;CACF"}
|
|
@@ -9,8 +9,9 @@
|
|
|
9
9
|
|
|
10
10
|
import { DataType, Synnax, TimeRange, TimeSpan, TimeStamp } from "@synnaxlabs/client";
|
|
11
11
|
|
|
12
|
-
// This example demonstrates the basics of reading and writing data from an index and
|
|
13
|
-
// channel in Synnax. We'll write a sine wave of data to a channel and then read it
|
|
12
|
+
// This example demonstrates the basics of reading and writing data from an index and
|
|
13
|
+
// data channel in Synnax. We'll write a sine wave of data to a channel and then read it
|
|
14
|
+
// back.
|
|
14
15
|
|
|
15
16
|
// Connect to a locally running, insecure Synnax cluster. If your connection parameters
|
|
16
17
|
// are different, enter them here.
|
|
@@ -19,25 +20,31 @@ const client = new Synnax({
|
|
|
19
20
|
port: 9090,
|
|
20
21
|
username: "synnax",
|
|
21
22
|
password: "seldon",
|
|
22
|
-
secure: false
|
|
23
|
+
secure: false,
|
|
23
24
|
});
|
|
24
25
|
|
|
25
26
|
// Create an index channel that will be used to store our timestamps.
|
|
26
|
-
const timeChannel = await client.channels.create(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
const timeChannel = await client.channels.create(
|
|
28
|
+
{
|
|
29
|
+
name: "basic_read_write_time",
|
|
30
|
+
isIndex: true,
|
|
31
|
+
dataType: DataType.TIMESTAMP,
|
|
32
|
+
},
|
|
33
|
+
{ retrieveIfNameExists: true },
|
|
34
|
+
);
|
|
31
35
|
|
|
32
36
|
// Create a channel that will be used to store our data.
|
|
33
|
-
const dataChannel = await client.channels.create(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
37
|
+
const dataChannel = await client.channels.create(
|
|
38
|
+
{
|
|
39
|
+
name: "basic_read_write_data",
|
|
40
|
+
isIndex: false,
|
|
41
|
+
dataType: DataType.FLOAT32,
|
|
42
|
+
// We need to specify the index channel that we want to use to store the timestamps
|
|
43
|
+
// for this data channel.
|
|
44
|
+
index: timeChannel.key,
|
|
45
|
+
},
|
|
46
|
+
{ retrieveIfNameExists: true },
|
|
47
|
+
);
|
|
41
48
|
|
|
42
49
|
const N_SAMPLES = 5000;
|
|
43
50
|
|
|
@@ -46,7 +53,10 @@ const N_SAMPLES = 5000;
|
|
|
46
53
|
const start = TimeStamp.now();
|
|
47
54
|
|
|
48
55
|
// Generate a new timestamp every millisecond for N_SAMPLES.
|
|
49
|
-
const time = BigInt64Array.from({ length: N_SAMPLES }, (_, i) =>
|
|
56
|
+
const time = BigInt64Array.from({ length: N_SAMPLES }, (_, i) =>
|
|
57
|
+
start.add(TimeSpan.milliseconds(i)).valueOf(),
|
|
58
|
+
);
|
|
59
|
+
|
|
50
60
|
// Generate a sine wave for N_SAMPLES.
|
|
51
61
|
const data = Float32Array.from({ length: N_SAMPLES }, (_, i) => Math.sin(i / 100));
|
|
52
62
|
|
|
@@ -73,4 +83,4 @@ console.log({
|
|
|
73
83
|
});
|
|
74
84
|
|
|
75
85
|
// Make sure to close the client when you're done.
|
|
76
|
-
client.close();
|
|
86
|
+
client.close();
|
|
@@ -7,13 +7,13 @@
|
|
|
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
|
-
import { Synnax
|
|
10
|
+
import { Synnax } from "@synnaxlabs/client";
|
|
11
11
|
|
|
12
12
|
// This example demonstrates how to stream live data from a channel in Synnax.
|
|
13
13
|
// Live-streaming is useful for real-time data processing and analysis, and is an
|
|
14
14
|
// integral part of Synnax's control sequence and data streaming capabilities.
|
|
15
15
|
|
|
16
|
-
// This example is meant to be used in conjunction with the stream_write.
|
|
16
|
+
// This example is meant to be used in conjunction with the stream_write.js example, and
|
|
17
17
|
// assumes that example is running in a separate terminal.
|
|
18
18
|
|
|
19
19
|
// Connect to a locally running, insecure Synnax cluster. If your connection parameters
|
|
@@ -23,21 +23,21 @@ const client = new Synnax({
|
|
|
23
23
|
port: 9090,
|
|
24
24
|
username: "synnax",
|
|
25
25
|
password: "seldon",
|
|
26
|
-
secure: false
|
|
26
|
+
secure: false,
|
|
27
27
|
});
|
|
28
28
|
|
|
29
29
|
// We can just specify the names of the channels we'd like to stream from.
|
|
30
30
|
const read_from = [
|
|
31
31
|
"stream_write_example_time",
|
|
32
32
|
"stream_write_example_data_1",
|
|
33
|
-
"stream_write_example_data_2"
|
|
34
|
-
]
|
|
33
|
+
"stream_write_example_data_2",
|
|
34
|
+
];
|
|
35
35
|
|
|
36
36
|
const streamer = await client.openStreamer(read_from);
|
|
37
37
|
|
|
38
38
|
// It's very important that we close the streamer when we're done with it to release
|
|
39
|
-
// network connections and other resources, so we wrap the streaming loop in a
|
|
40
|
-
// block.
|
|
39
|
+
// network connections and other resources, so we wrap the streaming loop in a
|
|
40
|
+
// try-finally block.
|
|
41
41
|
try {
|
|
42
42
|
// Loop through the frames in the streamer. Each iteration will block until a new
|
|
43
43
|
// frame is available, and then we'll just print out the last sample for each
|
|
@@ -48,4 +48,3 @@ try {
|
|
|
48
48
|
// Close the client when we're done with it.
|
|
49
49
|
client.close();
|
|
50
50
|
}
|
|
51
|
-
|