@synnaxlabs/client 0.1.0 → 0.1.2
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/build/main/index.d.ts +4 -0
- package/build/main/index.js +36 -0
- package/build/main/lib/channel/channel.spec.d.ts +1 -0
- package/build/main/lib/channel/channel.spec.js +35 -0
- package/build/main/lib/channel/client.d.ts +94 -0
- package/build/main/lib/channel/client.js +131 -0
- package/build/main/lib/channel/creator.d.ts +19 -0
- package/build/main/lib/channel/creator.js +44 -0
- package/build/main/lib/channel/payload.d.ts +25 -0
- package/build/main/lib/channel/payload.js +18 -0
- package/build/main/lib/channel/registry.d.ts +9 -0
- package/build/main/lib/channel/registry.js +37 -0
- package/build/main/lib/channel/retriever.d.ts +11 -0
- package/build/main/lib/channel/retriever.js +39 -0
- package/build/main/lib/client.d.ts +23 -0
- package/build/main/lib/client.js +34 -0
- package/build/main/lib/errors.d.ts +53 -0
- package/build/main/lib/errors.js +122 -0
- package/build/main/lib/segment/client.d.ts +62 -0
- package/build/main/lib/segment/client.js +95 -0
- package/build/main/lib/segment/iterator.d.ts +134 -0
- package/build/main/lib/segment/iterator.js +253 -0
- package/build/main/lib/segment/iterator.spec.d.ts +1 -0
- package/build/main/lib/segment/iterator.spec.js +62 -0
- package/build/main/lib/segment/payload.d.ts +16 -0
- package/build/main/lib/segment/payload.js +13 -0
- package/build/main/lib/segment/splitter.d.ts +7 -0
- package/build/main/lib/segment/splitter.js +25 -0
- package/build/main/lib/segment/typed.d.ts +15 -0
- package/build/main/lib/segment/typed.js +49 -0
- package/build/main/lib/segment/validator.d.ts +22 -0
- package/build/main/lib/segment/validator.js +64 -0
- package/build/main/lib/segment/writer.d.ts +98 -0
- package/build/main/lib/segment/writer.js +183 -0
- package/build/main/lib/segment/writer.spec.d.ts +1 -0
- package/build/main/lib/segment/writer.spec.js +76 -0
- package/build/main/lib/telem.d.ts +395 -0
- package/build/main/lib/telem.js +553 -0
- package/build/main/lib/telem.spec.d.ts +1 -0
- package/build/main/lib/telem.spec.js +150 -0
- package/build/main/lib/transport.d.ts +9 -0
- package/build/main/lib/transport.js +18 -0
- package/build/main/lib/util/telem.d.ts +2 -0
- package/build/main/lib/util/telem.js +13 -0
- package/build/module/index.d.ts +4 -0
- package/build/module/index.js +5 -0
- package/build/module/lib/channel/channel.spec.d.ts +1 -0
- package/build/module/lib/channel/channel.spec.js +30 -0
- package/build/module/lib/channel/client.d.ts +94 -0
- package/build/module/lib/channel/client.js +131 -0
- package/build/module/lib/channel/creator.d.ts +19 -0
- package/build/module/lib/channel/creator.js +42 -0
- package/build/module/lib/channel/payload.d.ts +25 -0
- package/build/module/lib/channel/payload.js +15 -0
- package/build/module/lib/channel/registry.d.ts +9 -0
- package/build/module/lib/channel/registry.js +36 -0
- package/build/module/lib/channel/retriever.d.ts +11 -0
- package/build/module/lib/channel/retriever.js +37 -0
- package/build/module/lib/client.d.ts +23 -0
- package/build/module/lib/client.js +31 -0
- package/build/module/lib/errors.d.ts +53 -0
- package/build/module/lib/errors.js +113 -0
- package/build/module/lib/segment/client.d.ts +62 -0
- package/build/module/lib/segment/client.js +94 -0
- package/build/module/lib/segment/iterator.d.ts +134 -0
- package/build/module/lib/segment/iterator.js +248 -0
- package/build/module/lib/segment/iterator.spec.d.ts +1 -0
- package/build/module/lib/segment/iterator.spec.js +57 -0
- package/build/module/lib/segment/payload.d.ts +16 -0
- package/build/module/lib/segment/payload.js +10 -0
- package/build/module/lib/segment/splitter.d.ts +7 -0
- package/build/module/lib/segment/splitter.js +26 -0
- package/build/module/lib/segment/typed.d.ts +15 -0
- package/build/module/lib/segment/typed.js +49 -0
- package/build/module/lib/segment/validator.d.ts +22 -0
- package/build/module/lib/segment/validator.js +60 -0
- package/build/module/lib/segment/writer.d.ts +98 -0
- package/build/module/lib/segment/writer.js +183 -0
- package/build/module/lib/segment/writer.spec.d.ts +1 -0
- package/build/module/lib/segment/writer.spec.js +71 -0
- package/build/module/lib/telem.d.ts +395 -0
- package/build/module/lib/telem.js +545 -0
- package/build/module/lib/telem.spec.d.ts +1 -0
- package/build/module/lib/telem.spec.js +145 -0
- package/build/module/lib/transport.d.ts +9 -0
- package/build/module/lib/transport.js +18 -0
- package/build/module/lib/util/telem.d.ts +2 -0
- package/build/module/lib/util/telem.js +9 -0
- package/package.json +2 -2
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export default class Registry {
|
|
2
|
+
retriever;
|
|
3
|
+
channels;
|
|
4
|
+
constructor(retriever) {
|
|
5
|
+
this.retriever = retriever;
|
|
6
|
+
this.channels = new Map();
|
|
7
|
+
}
|
|
8
|
+
async get(key) {
|
|
9
|
+
let channel = this.channels.get(key);
|
|
10
|
+
if (channel === undefined) {
|
|
11
|
+
channel = (await this.retriever.retrieveByKeys(key))[0];
|
|
12
|
+
this.channels.set(key, channel);
|
|
13
|
+
}
|
|
14
|
+
return channel;
|
|
15
|
+
}
|
|
16
|
+
async getN(...keys) {
|
|
17
|
+
const results = [];
|
|
18
|
+
const retrieveKeys = [];
|
|
19
|
+
keys.forEach((key) => {
|
|
20
|
+
const channel = this.channels.get(key);
|
|
21
|
+
if (channel === undefined)
|
|
22
|
+
retrieveKeys.push(key);
|
|
23
|
+
else
|
|
24
|
+
results.push(channel);
|
|
25
|
+
});
|
|
26
|
+
if (retrieveKeys.length > 0) {
|
|
27
|
+
const channels = await this.retriever.retrieveByKeys(...retrieveKeys);
|
|
28
|
+
channels.forEach((channel) => {
|
|
29
|
+
this.channels.set(channel.key, channel);
|
|
30
|
+
results.push(channel);
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
return results;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmVnaXN0cnkuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi9zcmMvbGliL2NoYW5uZWwvcmVnaXN0cnkudHMiXSwibmFt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0FBQzs7Z0JBQzdDLE9BQU8sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDLENBQUM7UUFDN0IsQ0FBQyxDQUFDLENBQUM7UUFDSCxJQUFJLFlBQVksQ0FBQyxNQUFNLEdBQUcsQ0FBQyxFQUFFO1lBQzNCLE1BQU0sUUFBUSxHQUFHLE1BQU0sSUFBSSxDQUFDLFNBQVMsQ0FBQyxjQUFjLENBQUMsR0FBRyxZQUFZLENBQUMsQ0FBQztZQUN0RSxRQUFRLENBQUMsT0FBTyxDQUFDLENBQUMsT0FBTyxFQUFFLEVBQUU7Z0JBQzNCLElBQUksQ0FBQyxRQUFRLENBQUMsR0FBRyxDQUFDLE9BQU8sQ0FBQyxHQUFhLEVBQUUsT0FBTyxDQUFDLENBQUM7Z0JBQ2xELE9BQU8sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFDLENBQUM7WUFDeEIsQ0FBQyxDQUFDLENBQUM7U0FDSjtRQUNELE9BQU8sT0FBTyxDQUFDO0lBQ2pCLENBQUM7Q0FDRiJ9
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import Transport from '../transport';
|
|
2
|
+
import { ChannelPayload } from './payload';
|
|
3
|
+
export default class Retriever {
|
|
4
|
+
private static ENDPOINT;
|
|
5
|
+
private client;
|
|
6
|
+
constructor(transport: Transport);
|
|
7
|
+
private execute;
|
|
8
|
+
retrieveByKeys(...keys: string[]): Promise<ChannelPayload[]>;
|
|
9
|
+
retrieveByNames(...names: string[]): Promise<ChannelPayload[]>;
|
|
10
|
+
retrieveByNodeID(nodeId: number): Promise<ChannelPayload[]>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ChannelPayloadSchema } from './payload';
|
|
3
|
+
const RequestSchema = z.object({
|
|
4
|
+
keys: z.string().array().optional(),
|
|
5
|
+
nodeId: z.number().optional(),
|
|
6
|
+
names: z.string().array().optional(),
|
|
7
|
+
});
|
|
8
|
+
const ResponseSchema = z.object({
|
|
9
|
+
channels: ChannelPayloadSchema.array(),
|
|
10
|
+
});
|
|
11
|
+
export default class Retriever {
|
|
12
|
+
static ENDPOINT = '/channel/retrieve';
|
|
13
|
+
client;
|
|
14
|
+
constructor(transport) {
|
|
15
|
+
this.client = transport.getClient();
|
|
16
|
+
}
|
|
17
|
+
async execute(request) {
|
|
18
|
+
const [res, err] = await this.client.send(Retriever.ENDPOINT, request,
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
ResponseSchema);
|
|
22
|
+
if (err) {
|
|
23
|
+
throw err;
|
|
24
|
+
}
|
|
25
|
+
return res?.channels;
|
|
26
|
+
}
|
|
27
|
+
async retrieveByKeys(...keys) {
|
|
28
|
+
return await this.execute({ keys });
|
|
29
|
+
}
|
|
30
|
+
async retrieveByNames(...names) {
|
|
31
|
+
return await this.execute({ names });
|
|
32
|
+
}
|
|
33
|
+
async retrieveByNodeID(nodeId) {
|
|
34
|
+
return await this.execute({ nodeId: nodeId });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicmV0cmlldmVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vc3JjL2xpYi9jaGFubmVsL3JldHJpZXZlci50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFDQSxPQUFPLEVBQUUsQ0FBQyxFQUFFLE1BQU0sS0FBSyxDQUFDO0FBSXhCLE9BQU8sRUFBa0Isb0JBQW9CLEVBQUUsTUFBTSxXQUFXLENBQUM7QUFFakUsTUFBTSxhQUFhLEdBQUcsQ0FBQyxDQUFDLE1BQU0sQ0FBQztJQUM3QixJQUFJLEVBQUUsQ0FBQyxDQUFDLE1BQU0sRUFBRSxDQUFDLEtBQUssRUFBRSxDQUFDLFFBQVEsRUF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GVBQWUsQ0FBQyxHQUFHLEtBQWU7UUFDdEMsT0FBTyxNQUFNLElBQUksQ0FBQyxPQUFPLENBQUMsRUFBRSxLQUFLLEVBQUUsQ0FBQyxDQUFDO0lBQ3ZDLENBQUM7SUFFRCxLQUFLLENBQUMsZ0JBQWdCLENBQUMsTUFBYztRQUNuQyxPQUFPLE1BQU0sSUFBSSxDQUFDLE9BQU8sQ0FBQyxFQUFFLE1BQU0sRUFBRSxNQUFNLEVBQUUsQ0FBQyxDQUFDO0lBQ2hELENBQUMifQ==
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import ChannelClient from './channel/client';
|
|
2
|
+
import SegmentClient from './segment/client';
|
|
3
|
+
import Transport from './transport';
|
|
4
|
+
export declare type ClientProps = {
|
|
5
|
+
host: string;
|
|
6
|
+
port: number;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Client to perform operations against a Synnax cluster.
|
|
10
|
+
*
|
|
11
|
+
* @property channel - Channel client for creating and retrieving channels.
|
|
12
|
+
* @property data - Data client for reading and writing telemetry.
|
|
13
|
+
*/
|
|
14
|
+
export default class Synnax {
|
|
15
|
+
transport: Transport;
|
|
16
|
+
data: SegmentClient;
|
|
17
|
+
channel: ChannelClient;
|
|
18
|
+
/**
|
|
19
|
+
* @param host - Hostname of a node in the cluster.
|
|
20
|
+
* @param port - Port of the node in the cluster.
|
|
21
|
+
*/
|
|
22
|
+
constructor({ host, port }: ClientProps);
|
|
23
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { URL } from '@synnaxlabs/freighter';
|
|
2
|
+
import ChannelClient from './channel/client';
|
|
3
|
+
import ChannelCreator from './channel/creator';
|
|
4
|
+
import Registry from './channel/registry';
|
|
5
|
+
import ChannelRetriever from './channel/retriever';
|
|
6
|
+
import SegmentClient from './segment/client';
|
|
7
|
+
import Transport from './transport';
|
|
8
|
+
/**
|
|
9
|
+
* Client to perform operations against a Synnax cluster.
|
|
10
|
+
*
|
|
11
|
+
* @property channel - Channel client for creating and retrieving channels.
|
|
12
|
+
* @property data - Data client for reading and writing telemetry.
|
|
13
|
+
*/
|
|
14
|
+
export default class Synnax {
|
|
15
|
+
transport;
|
|
16
|
+
data;
|
|
17
|
+
channel;
|
|
18
|
+
/**
|
|
19
|
+
* @param host - Hostname of a node in the cluster.
|
|
20
|
+
* @param port - Port of the node in the cluster.
|
|
21
|
+
*/
|
|
22
|
+
constructor({ host, port }) {
|
|
23
|
+
this.transport = new Transport(new URL({ host, port }));
|
|
24
|
+
const chRetriever = new ChannelRetriever(this.transport);
|
|
25
|
+
const chCreator = new ChannelCreator(this.transport);
|
|
26
|
+
const chRegistry = new Registry(chRetriever);
|
|
27
|
+
this.data = new SegmentClient(this.transport, chRegistry);
|
|
28
|
+
this.channel = new ChannelClient(this.data, chRetriever, chCreator);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2xpZW50LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2xpYi9jbGllbnQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsT0FBTyxFQUFFLEdBQUcsRUFBRSxNQUFNLHVCQUF1QixDQUFDO0FBRTVDLE9BQU8sYUFBYSxNQUFNLGtCQUFrQixDQUFDO0FBQzdDLE9BQU8sY0FBYyxNQUFNLG1CQUFtQixDQUFDO0FBQy9DLE9BQU8sUUFBUSxNQUFNLG9CQUFvQixDQUFDO0FBQzFDLE9BQU8sZ0JBQWdCLE1BQU0scUJBQXFCLENBQUM7QUFDbkQsT0FBTyxhQUFhLE1BQU0sa0JBQWtCLENBQUM7QUFDN0MsT0FBTyxTQUFTLE1BQU0sYUFBYSxDQUFDO0FBT3BDOzs7OztHQUtHO0FBQ0gsTUFBTSxDQUFDLE9BQU8sT0FBTyxNQUFNO0lBQ3pCLFNBQVMsQ0FBWTtJQUNyQixJQUFJLENBQWdCO0lBQ3BCLE9BQU8sQ0FBZ0I7SUFFdkI7OztPQUdHO0lBQ0gsWUFBWSxFQUFFLElBQUksRUFBRSxJQUFJLEVBQWU7UUFDckMsSUFBSSxDQUFDLFNBQVMsR0FBRyxJQUFJLFNBQVMsQ0FBQyxJQUFJLEdBQUcsQ0FBQyxFQUFFLElBQUksRUFBRSxJQUFJLEVBQUUsQ0FBQyxDQUFDLENBQUM7UUFDeEQsTUFBTSxXQUFXLEdBQUcsSUFBSSxnQkFBZ0IsQ0FBQyxJQUFJLENBQUMsU0FBUyxDQUFDLENBQUM7UUFDekQsTUFBTSxTQUFTLEdBQUcsSUFBSSxjQUFjLENBQUMsSUFBSSxDQUFDLFNBQVMsQ0FBQyxDQUFDO1FBQ3JELE1BQU0sVUFBVSxHQUFHLElBQUksUUFBUSxDQUFDLFdBQVcsQ0FBQyxDQUFDO1FBQzdDLElBQUksQ0FBQyxJQUFJLEdBQUcsSUFBSSxhQUFhLENBQUMsSUFBSSxDQUFDLFNBQVMsRUFBRSxVQUFVLENBQUMsQ0FBQztRQUMxRCxJQUFJLENBQUMsT0FBTyxHQUFHLElBQUksYUFBYSxDQUFDLElBQUksQ0FBQyxJQUFJLEVBQUUsV0FBVyxFQUFFLFNBQVMsQ0FBQyxDQUFDO0lBQ3RFLENBQUM7Q0FDRiJ9
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { BaseTypedError } from '@synnaxlabs/freighter';
|
|
2
|
+
export declare type Field = {
|
|
3
|
+
field: string;
|
|
4
|
+
message: string;
|
|
5
|
+
};
|
|
6
|
+
declare class BaseError extends BaseTypedError {
|
|
7
|
+
constructor(message: string);
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Raised when a validation error occurs.
|
|
11
|
+
*/
|
|
12
|
+
export declare class ValidationError extends BaseError {
|
|
13
|
+
fields: Field[];
|
|
14
|
+
constructor(fieldsOrMessage: string | Field[] | Field);
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* GeneralError is raised when a general error occurs.
|
|
18
|
+
*/
|
|
19
|
+
export declare class GeneralError extends BaseError {
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* ParseError is raised when a parse error occurs.
|
|
23
|
+
*/
|
|
24
|
+
export declare class ParseError extends BaseError {
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* AuthError is raised when an authentication error occurs.
|
|
28
|
+
*/
|
|
29
|
+
export declare class AuthError extends BaseError {
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* UnexpectedError is raised when an unexpected error occurs.
|
|
33
|
+
*/
|
|
34
|
+
export declare class UnexpectedError extends BaseError {
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* QueryError is raised when a query error occurs.
|
|
38
|
+
*/
|
|
39
|
+
export declare class QueryError extends BaseError {
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* RouteError is raised when a routing error occurs.
|
|
43
|
+
*/
|
|
44
|
+
export declare class RouteError extends BaseError {
|
|
45
|
+
path: string;
|
|
46
|
+
constructor(message: string, path: string);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Raised when time-series data is not contiguous.
|
|
50
|
+
*/
|
|
51
|
+
export declare class ContiguityError extends BaseError {
|
|
52
|
+
}
|
|
53
|
+
export {};
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { BaseTypedError, registerError } from '@synnaxlabs/freighter';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
const _FREIGHTER_EXCEPTION_TYPE = 'synnax.api.errors';
|
|
4
|
+
const APIErrorPayloadSchema = z.object({
|
|
5
|
+
type: z.string(),
|
|
6
|
+
error: z.record(z.unknown()),
|
|
7
|
+
});
|
|
8
|
+
var APIErrorType;
|
|
9
|
+
(function (APIErrorType) {
|
|
10
|
+
APIErrorType["General"] = "general";
|
|
11
|
+
APIErrorType["Nil"] = "nil";
|
|
12
|
+
APIErrorType["Parse"] = "parse";
|
|
13
|
+
APIErrorType["Auth"] = "auth";
|
|
14
|
+
APIErrorType["Unexpected"] = "unexpected";
|
|
15
|
+
APIErrorType["Validation"] = "validation";
|
|
16
|
+
APIErrorType["Query"] = "query";
|
|
17
|
+
APIErrorType["Route"] = "route";
|
|
18
|
+
})(APIErrorType || (APIErrorType = {}));
|
|
19
|
+
class BaseError extends BaseTypedError {
|
|
20
|
+
constructor(message) {
|
|
21
|
+
super(message, _FREIGHTER_EXCEPTION_TYPE);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Raised when a validation error occurs.
|
|
26
|
+
*/
|
|
27
|
+
export class ValidationError extends BaseError {
|
|
28
|
+
fields;
|
|
29
|
+
constructor(fieldsOrMessage) {
|
|
30
|
+
if (typeof fieldsOrMessage === 'string') {
|
|
31
|
+
super(fieldsOrMessage);
|
|
32
|
+
this.fields = [];
|
|
33
|
+
}
|
|
34
|
+
else if (Array.isArray(fieldsOrMessage)) {
|
|
35
|
+
super(fieldsOrMessage
|
|
36
|
+
.map((field) => `${field.field}: ${field.message}`)
|
|
37
|
+
.join('\n'));
|
|
38
|
+
this.fields = fieldsOrMessage;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
super(`${fieldsOrMessage.field}: ${fieldsOrMessage.message}`);
|
|
42
|
+
this.fields = [fieldsOrMessage];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* GeneralError is raised when a general error occurs.
|
|
48
|
+
*/
|
|
49
|
+
export class GeneralError extends BaseError {
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* ParseError is raised when a parse error occurs.
|
|
53
|
+
*/
|
|
54
|
+
export class ParseError extends BaseError {
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* AuthError is raised when an authentication error occurs.
|
|
58
|
+
*/
|
|
59
|
+
export class AuthError extends BaseError {
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* UnexpectedError is raised when an unexpected error occurs.
|
|
63
|
+
*/
|
|
64
|
+
export class UnexpectedError extends BaseError {
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* QueryError is raised when a query error occurs.
|
|
68
|
+
*/
|
|
69
|
+
export class QueryError extends BaseError {
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* RouteError is raised when a routing error occurs.
|
|
73
|
+
*/
|
|
74
|
+
export class RouteError extends BaseError {
|
|
75
|
+
path;
|
|
76
|
+
constructor(message, path) {
|
|
77
|
+
super(message);
|
|
78
|
+
this.path = path;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Raised when time-series data is not contiguous.
|
|
83
|
+
*/
|
|
84
|
+
export class ContiguityError extends BaseError {
|
|
85
|
+
}
|
|
86
|
+
const parsePayload = (payload) => {
|
|
87
|
+
switch (payload.type) {
|
|
88
|
+
case APIErrorType.General:
|
|
89
|
+
return new GeneralError(payload.error.message);
|
|
90
|
+
case APIErrorType.Parse:
|
|
91
|
+
return new ParseError(payload.error.message);
|
|
92
|
+
case APIErrorType.Auth:
|
|
93
|
+
return new AuthError(payload.error.message);
|
|
94
|
+
case APIErrorType.Unexpected:
|
|
95
|
+
return new UnexpectedError(JSON.stringify(payload.error));
|
|
96
|
+
case APIErrorType.Validation:
|
|
97
|
+
return new ValidationError(payload.error.fields);
|
|
98
|
+
case APIErrorType.Query:
|
|
99
|
+
return new QueryError(payload.error.message);
|
|
100
|
+
case APIErrorType.Route:
|
|
101
|
+
return new RouteError(payload.error.path, payload.error.message);
|
|
102
|
+
default:
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
const decode = (encoded) => {
|
|
107
|
+
return parsePayload(APIErrorPayloadSchema.parse(JSON.parse(encoded)));
|
|
108
|
+
};
|
|
109
|
+
const encode = () => {
|
|
110
|
+
throw new Error('Not implemented');
|
|
111
|
+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0FBQyxPQUFPLENBQUMsS0FBSyxDQUFDLE9BQWlCLENBQUMsQ0FBQztRQUN6RCxLQUFLLFlBQVksQ0FBQyxLQUFLO1lBQ3JCLE9BQU8sSUFBSSxVQUFVLENBQ25CLE9BQU8sQ0FBQyxLQUFLLENBQUMsSUFBYyxFQUM1QixPQUFPLENBQUMsS0FBSyxDQUFDLE9BQWlCLENBQ2hDLENBQUM7UUFDSjtZQUNFLE9BQU8sU0FBUyxDQUFDO0tBQ3BCO0FBQ0gsQ0FBQyxDQUFDO0FBRUYsTUFBTSxNQUFNLEdBQUcsQ0FBQyxPQUFlLEVBQXFCLEVBQUU7SUFDcEQsT0FBTyxZQUFZLENBQUMscUJBQXFCLENBQUMsS0FBSyxDQUFDLElBQUksQ0FBQyxLQUFLLENBQUMsT0FBTyxDQUFDLENBQUMsQ0FBQyxDQUFDO0FBQ3hFLENBQUMsQ0FBQztBQUVGLE1BQU0sTUFBTSxHQUFHLEdBQVcsRUFBRTtJQUMxQixNQUFNLElBQUksS0FBSyxDQUFDLGlCQUFpQixDQUFDLENBQUM7QUFDckMsQ0FBQyxDQUFDO0FBRUYsYUFBYSxDQUFDLEVBQUUsSUFBSSxFQUFFLHlCQUF5QixFQUFFLE1BQU0sRUFBRSxNQUFNLEVBQUUsQ0FBQyxDQUFDIn0=
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import Registry from '../channel/registry';
|
|
2
|
+
import { TimeRange, TypedArray, UnparsedTimeStamp } from '../telem';
|
|
3
|
+
import Transport from '../transport';
|
|
4
|
+
import { TypedIterator } from './iterator';
|
|
5
|
+
import TypedSegment from './typed';
|
|
6
|
+
import { TypedWriter } from './writer';
|
|
7
|
+
export default class SegmentClient {
|
|
8
|
+
private transport;
|
|
9
|
+
private channels;
|
|
10
|
+
constructor(transport: Transport, channels: Registry);
|
|
11
|
+
/**
|
|
12
|
+
* Opens a new iterator over the given channels within the provided time range.
|
|
13
|
+
*
|
|
14
|
+
* @param tr - A time range to iterate over.
|
|
15
|
+
* @param keys - A list of channel keys to iterate over.
|
|
16
|
+
* @param aggregate - Whether to accumulate iteration results or reset them
|
|
17
|
+
* on every iterator method call.
|
|
18
|
+
* @returns a new {@link TypedIterator}.
|
|
19
|
+
*/
|
|
20
|
+
newIterator(tr: TimeRange, keys: string[], aggregate: boolean): Promise<TypedIterator>;
|
|
21
|
+
/**
|
|
22
|
+
* Opens a new writer on the given channels.
|
|
23
|
+
*
|
|
24
|
+
* @param keys - The keys of the channels to write to. A writer cannot write to
|
|
25
|
+
* a channel that is not in this list. See the {@link TypedWriter} documentation
|
|
26
|
+
* for more information.
|
|
27
|
+
* @returns a new {@link TypedWriter}.
|
|
28
|
+
*/
|
|
29
|
+
newWriter(keys: string[]): Promise<TypedWriter>;
|
|
30
|
+
/**
|
|
31
|
+
* Writes telemetry to the given channel starting at the given timestamp.
|
|
32
|
+
*
|
|
33
|
+
* @param to - The key of the channel to write to.
|
|
34
|
+
* @param start - The starting timestamp of the first sample in data.
|
|
35
|
+
* @param data - The telemetry to write. This telemetry must have the same
|
|
36
|
+
* data type as the channel.
|
|
37
|
+
* @throws if the channel does not exist.
|
|
38
|
+
*/
|
|
39
|
+
write(to: string, start: UnparsedTimeStamp, data: TypedArray): Promise<boolean>;
|
|
40
|
+
/**
|
|
41
|
+
* Reads telemetry from the channel between the two timestamps.
|
|
42
|
+
*
|
|
43
|
+
* @param from - The key of the channel to read from.
|
|
44
|
+
* @param start - The starting timestamp of the range to read from.
|
|
45
|
+
* @param end - The ending timestamp of the range to read from.
|
|
46
|
+
* @returns a typed array containing the retrieved telemetry.
|
|
47
|
+
* @throws if the channel does not exist.
|
|
48
|
+
* @throws if the telemetry between start and end is not contiguous.
|
|
49
|
+
*/
|
|
50
|
+
read(from: string, start: UnparsedTimeStamp, end: UnparsedTimeStamp): Promise<TypedArray>;
|
|
51
|
+
/**
|
|
52
|
+
* Reads a segment from the channel between the two timestamps.
|
|
53
|
+
*
|
|
54
|
+
* @param from - The key of the channel to read from.
|
|
55
|
+
* @param start - The starting timestamp of the range to read from.
|
|
56
|
+
* @param end - The ending timestamp of the range to read from.
|
|
57
|
+
* @returns a segment containing the retrieved telemetry.
|
|
58
|
+
* @throws if the channel does not exist.
|
|
59
|
+
* @throws if the telemetry between start and end is not contiguous.
|
|
60
|
+
*/
|
|
61
|
+
readSegment(from: string, start: UnparsedTimeStamp, end: UnparsedTimeStamp): Promise<TypedSegment>;
|
|
62
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { TimeRange } from '../telem';
|
|
2
|
+
import { TypedIterator } from './iterator';
|
|
3
|
+
import { TypedWriter } from './writer';
|
|
4
|
+
export default class SegmentClient {
|
|
5
|
+
transport;
|
|
6
|
+
channels;
|
|
7
|
+
constructor(transport, channels) {
|
|
8
|
+
this.transport = transport;
|
|
9
|
+
this.channels = channels;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Opens a new iterator over the given channels within the provided time range.
|
|
13
|
+
*
|
|
14
|
+
* @param tr - A time range to iterate over.
|
|
15
|
+
* @param keys - A list of channel keys to iterate over.
|
|
16
|
+
* @param aggregate - Whether to accumulate iteration results or reset them
|
|
17
|
+
* on every iterator method call.
|
|
18
|
+
* @returns a new {@link TypedIterator}.
|
|
19
|
+
*/
|
|
20
|
+
async newIterator(tr, keys, aggregate) {
|
|
21
|
+
const iter = new TypedIterator(this.transport.streamClient, this.channels, aggregate);
|
|
22
|
+
await iter.open(tr, keys);
|
|
23
|
+
return iter;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Opens a new writer on the given channels.
|
|
27
|
+
*
|
|
28
|
+
* @param keys - The keys of the channels to write to. A writer cannot write to
|
|
29
|
+
* a channel that is not in this list. See the {@link TypedWriter} documentation
|
|
30
|
+
* for more information.
|
|
31
|
+
* @returns a new {@link TypedWriter}.
|
|
32
|
+
*/
|
|
33
|
+
async newWriter(keys) {
|
|
34
|
+
const writer = new TypedWriter(this.transport.streamClient, this.channels);
|
|
35
|
+
await writer.open(keys);
|
|
36
|
+
return writer;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Writes telemetry to the given channel starting at the given timestamp.
|
|
40
|
+
*
|
|
41
|
+
* @param to - The key of the channel to write to.
|
|
42
|
+
* @param start - The starting timestamp of the first sample in data.
|
|
43
|
+
* @param data - The telemetry to write. This telemetry must have the same
|
|
44
|
+
* data type as the channel.
|
|
45
|
+
* @throws if the channel does not exist.
|
|
46
|
+
*/
|
|
47
|
+
async write(to, start, data) {
|
|
48
|
+
const writer = await this.newWriter([to]);
|
|
49
|
+
try {
|
|
50
|
+
return await writer.write(to, start, data);
|
|
51
|
+
}
|
|
52
|
+
finally {
|
|
53
|
+
await writer.close();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Reads telemetry from the channel between the two timestamps.
|
|
58
|
+
*
|
|
59
|
+
* @param from - The key of the channel to read from.
|
|
60
|
+
* @param start - The starting timestamp of the range to read from.
|
|
61
|
+
* @param end - The ending timestamp of the range to read from.
|
|
62
|
+
* @returns a typed array containing the retrieved telemetry.
|
|
63
|
+
* @throws if the channel does not exist.
|
|
64
|
+
* @throws if the telemetry between start and end is not contiguous.
|
|
65
|
+
*/
|
|
66
|
+
async read(from, start, end) {
|
|
67
|
+
return (await this.readSegment(from, start, end)).view;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Reads a segment from the channel between the two timestamps.
|
|
71
|
+
*
|
|
72
|
+
* @param from - The key of the channel to read from.
|
|
73
|
+
* @param start - The starting timestamp of the range to read from.
|
|
74
|
+
* @param end - The ending timestamp of the range to read from.
|
|
75
|
+
* @returns a segment containing the retrieved telemetry.
|
|
76
|
+
* @throws if the channel does not exist.
|
|
77
|
+
* @throws if the telemetry between start and end is not contiguous.
|
|
78
|
+
*/
|
|
79
|
+
async readSegment(from, start, end) {
|
|
80
|
+
const iter = await this.newIterator(new TimeRange(start, end), [from], true);
|
|
81
|
+
let seg;
|
|
82
|
+
try {
|
|
83
|
+
await iter.first();
|
|
84
|
+
// eslint-disable-next-line no-empty
|
|
85
|
+
while (await iter.next()) { }
|
|
86
|
+
seg = (await iter.value())[from];
|
|
87
|
+
}
|
|
88
|
+
finally {
|
|
89
|
+
await iter.close();
|
|
90
|
+
}
|
|
91
|
+
return seg;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2xpZW50LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vc3JjL2xpYi9zZWdtZW50L2NsaWVudC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFDQSxPQUFPLEVBQUUsU0FBUyxFQUFpQyxNQUFNLFVBQVUsQ0FBQztBQUdwRSxPQUFPLEVBQUUsYUFBYSxFQUFFLE1BQU0sWUFBWSxDQUFDO0FBRTNDLE9BQU8sRUFBRSxXQUFXLEVBQUUsTUFBTSxVQUFVLENBQUM7QUFFdkMsTUFBTSxDQUFDLE9BQU8sT0FBTyxhQUFhO0lBQ3hCLFNBQVMsQ0FBWTtJQUNyQixRQUFRLENBQVc7SUFFM0IsWUFBWSxTQUFvQixFQUFFLFFBQWtCO1FBQ2xELElBQUksQ0FBQyxTQUFTLEdBQUcsU0FBUyxDQUFDO1FBQzNCLElBQUksQ0FBQyxRQUFRLEdBQUcsUUFBUSxDQUFDO0lBQzNCLENBQUM7SUFFRDs7Ozs7Ozs7T0FRRztJQUNILEtBQUssQ0FBQyxXQUFXLENBQ2YsRUFBYSxFQUNiLElBQWMsRUFDZCxTQUFrQjtRQUVsQixNQUFNLElBQUksR0FBRyxJQUFJLGFBQWEsQ0FDNUIsSUFBSSxDQUFDLFNBQVMsQ0FBQyxZQUFZLEVBQzNCLElBQUksQ0FBQyxRQUFRLEVBQ2IsU0FBUyxDQUNWLENBQUM7UUFDRixNQUFNLElBQUksQ0FBQyxJ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NmLElBQVksRUFDWixLQUF3QixFQUN4QixHQUFzQjtRQUV0QixNQUFNLElBQUksR0FBRyxNQUFNLElBQUksQ0FBQyxXQUFXLENBQ2pDLElBQUksU0FBUyxDQUFDLEtBQUssRUFBRSxHQUFHLENBQUMsRUFDekIsQ0FBQyxJQUFJLENBQUMsRUFDTixJQUFJLENBQ0wsQ0FBQztRQUNGLElBQUksR0FBaUIsQ0FBQztRQUN0QixJQUFJO1lBQ0YsTUFBTSxJQUFJLENBQUMsS0FBSyxFQUFFLENBQUM7WUFDbkIsb0NBQW9DO1lBQ3BDLE9BQU8sTUFBTSxJQUFJLENBQUMsSUFBSSxFQUFFLEVBQUUsR0FBRTtZQUM1QixHQUFHLEdBQUcsQ0FBQyxNQUFNLElBQUksQ0FBQyxLQUFLLEVBQUUsQ0FBQyxDQUFDLElBQUksQ0FBQyxDQUFDO1NBQ2xDO2dCQUFTO1lBQ1IsTUFBTSxJQUFJLENBQUMsS0FBSyxFQUFFLENBQUM7U0FDcEI7UUFDRCxPQUFPLEdBQW1CLENBQUM7SUFDN0IsQ0FBQztDQUNGIn0=
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { StreamClient } from '@synnaxlabs/freighter';
|
|
2
|
+
import Registry from '../channel/registry';
|
|
3
|
+
import { TimeRange } from '../telem';
|
|
4
|
+
import { SegmentPayload } from './payload';
|
|
5
|
+
import TypedSegment from './typed';
|
|
6
|
+
/**
|
|
7
|
+
* Used to iterate over a clusters telemetry in time-order. It should not be
|
|
8
|
+
* instantiated directly, and should instead be instantiated via the SegmentClient.
|
|
9
|
+
*
|
|
10
|
+
* Using an iterator is ideal when querying/processing large ranges of data, but
|
|
11
|
+
* is relatively complex and difficult to use. If you're looking to retrieve
|
|
12
|
+
* telemetry between two timestamps, see the SegmentClient.read method.
|
|
13
|
+
*/
|
|
14
|
+
export declare class CoreIterator {
|
|
15
|
+
private static ENDPOINT;
|
|
16
|
+
private client;
|
|
17
|
+
private stream;
|
|
18
|
+
private readonly aggregate;
|
|
19
|
+
values: SegmentPayload[];
|
|
20
|
+
constructor(client: StreamClient, aggregate?: boolean);
|
|
21
|
+
/**
|
|
22
|
+
* Opens the iterator, configuring it to iterate over the telemetry in the
|
|
23
|
+
* channels with the given keys within the provided time range.
|
|
24
|
+
*
|
|
25
|
+
* @param tr - The time range to iterate over.
|
|
26
|
+
* @param keys - The keys of the channels to iterate over.
|
|
27
|
+
*/
|
|
28
|
+
open(tr: TimeRange, keys: string[]): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Reads the next segment for each channel in the iterator.
|
|
31
|
+
*
|
|
32
|
+
* @returns false if the next segment can't be found for one or more channels or
|
|
33
|
+
* the iterator has accumulated an error.
|
|
34
|
+
*/
|
|
35
|
+
next(): Promise<boolean>;
|
|
36
|
+
/**
|
|
37
|
+
* Reads the previous segment for each channel in the iterator.
|
|
38
|
+
*
|
|
39
|
+
* @returns false if the next segment can't be found for one or more channels or
|
|
40
|
+
* the iterator has accumulated an error.
|
|
41
|
+
*/
|
|
42
|
+
prev(): Promise<boolean>;
|
|
43
|
+
/**
|
|
44
|
+
* Seeks to the beginning of the time range and reads the first segment of each
|
|
45
|
+
* channel in the iterator.
|
|
46
|
+
*
|
|
47
|
+
* @returns false if no segments exists in the time range for a particular channel
|
|
48
|
+
* or the iterator has accumulated an error.
|
|
49
|
+
*/
|
|
50
|
+
first(): Promise<boolean>;
|
|
51
|
+
/**
|
|
52
|
+
* Seeks to the end of the time range and reads the last segment of each channel
|
|
53
|
+
* in the iterator.
|
|
54
|
+
*
|
|
55
|
+
* @returns false if no segments exists in the time range for a particular channel,
|
|
56
|
+
* or the iterator has accumulated an error.
|
|
57
|
+
*/
|
|
58
|
+
last(): Promise<boolean>;
|
|
59
|
+
/**
|
|
60
|
+
* Reads the next time span of telemetry for each channel in the iterator.
|
|
61
|
+
*
|
|
62
|
+
* @returns false if a segment satisfying the request can't be found for a
|
|
63
|
+
* particular channel or the iterator has accumulated an error.
|
|
64
|
+
*/
|
|
65
|
+
nextSpan(span: number): Promise<boolean>;
|
|
66
|
+
/**
|
|
67
|
+
* Reads the previous time span of telemetry for each channel in the iterator.
|
|
68
|
+
*
|
|
69
|
+
* @returns false if a segment satisfying the request can't be found for a particular
|
|
70
|
+
* channel or the iterator has accumulated an error.
|
|
71
|
+
*/
|
|
72
|
+
prevSpan(span: number): Promise<boolean>;
|
|
73
|
+
/**
|
|
74
|
+
* Seeks the iterator to the start of the time range and reads the telemetry within
|
|
75
|
+
* the range for each channel.
|
|
76
|
+
*
|
|
77
|
+
* @returns: False if a segment satisfying the request can't be found for a particular
|
|
78
|
+
* channel or the iterator has accumulated an error.
|
|
79
|
+
*/
|
|
80
|
+
nextRange(range: TimeRange): Promise<boolean>;
|
|
81
|
+
/**
|
|
82
|
+
* Seeks the iterator to the first segment in the time range, but does not read
|
|
83
|
+
* it. Also invalidates the iterator. The iterator will not be considered valid
|
|
84
|
+
* until a call to first, last, next, prev, prev_span, next_span, or next_range.
|
|
85
|
+
*
|
|
86
|
+
* @returns false if the iterator is not pointing to a valid segment for a particular
|
|
87
|
+
* channel or has accumulated an error.
|
|
88
|
+
*/
|
|
89
|
+
seekFirst(): Promise<boolean>;
|
|
90
|
+
/** Seeks the iterator to the last segment in the time range, but does not read it.
|
|
91
|
+
* Also invalidates the iterator. The iterator will not be considered valid
|
|
92
|
+
* until a call to first, last, next, prev, prev_span, next_span, or next_range.
|
|
93
|
+
*
|
|
94
|
+
* @returns false if the iterator is not pointing to a valid segment for a particular
|
|
95
|
+
* channel or has accumulated an error.
|
|
96
|
+
*/
|
|
97
|
+
seekLast(): Promise<boolean>;
|
|
98
|
+
/**
|
|
99
|
+
* Seeks the iterator to the first segment whose start is less than or equal to
|
|
100
|
+
* the provided timestamp. Also invalidates the iterator. The iterator will not be
|
|
101
|
+
* considered valid until a call to first, last, next, prev, prev_span, next_span, or next_range.
|
|
102
|
+
*
|
|
103
|
+
* @returns false if the iterator is not pointing to a valid segment for a particular
|
|
104
|
+
* channel or has accumulated an error.
|
|
105
|
+
*/
|
|
106
|
+
seekLT(stamp: number): Promise<boolean>;
|
|
107
|
+
/**
|
|
108
|
+
* Seeks the iterator to the first segment whose start is greater than or equal to
|
|
109
|
+
* the provided timestamp. Also invalidates the iterator. The iterator will not be
|
|
110
|
+
* considered valid until a call to first, last, next, prev, prev_span, next_span, or next_range.
|
|
111
|
+
*
|
|
112
|
+
* @returns false if the iterator is not pointing to a valid segment for a particular
|
|
113
|
+
* channel or has accumulated an error.
|
|
114
|
+
*/
|
|
115
|
+
seekGE(stamp: number): Promise<boolean>;
|
|
116
|
+
/**
|
|
117
|
+
* @returns true if the iterator value contains a valid segment, and fale otherwise.
|
|
118
|
+
* valid most commonly returns false when the iterator is exhausted or has
|
|
119
|
+
* accumulated an error.
|
|
120
|
+
*/
|
|
121
|
+
valid(): Promise<boolean>;
|
|
122
|
+
/**
|
|
123
|
+
* Closes the iterator. An iterator MUST be closed after use, and this method
|
|
124
|
+
* should probably be placed in a 'finally' block. If the iterator is not closed,
|
|
125
|
+
* it may leak resources.
|
|
126
|
+
*/
|
|
127
|
+
close(): Promise<void>;
|
|
128
|
+
private execute;
|
|
129
|
+
}
|
|
130
|
+
export declare class TypedIterator extends CoreIterator {
|
|
131
|
+
channels: Registry;
|
|
132
|
+
constructor(client: StreamClient, channels: Registry, aggregate?: boolean);
|
|
133
|
+
value(): Promise<Record<string, TypedSegment>>;
|
|
134
|
+
}
|