@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,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ContiguityError = exports.RouteError = exports.QueryError = exports.UnexpectedError = exports.AuthError = exports.ParseError = exports.GeneralError = exports.ValidationError = void 0;
|
|
4
|
+
const freighter_1 = require("@synnaxlabs/freighter");
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const _FREIGHTER_EXCEPTION_TYPE = 'synnax.api.errors';
|
|
7
|
+
const APIErrorPayloadSchema = zod_1.z.object({
|
|
8
|
+
type: zod_1.z.string(),
|
|
9
|
+
error: zod_1.z.record(zod_1.z.unknown()),
|
|
10
|
+
});
|
|
11
|
+
var APIErrorType;
|
|
12
|
+
(function (APIErrorType) {
|
|
13
|
+
APIErrorType["General"] = "general";
|
|
14
|
+
APIErrorType["Nil"] = "nil";
|
|
15
|
+
APIErrorType["Parse"] = "parse";
|
|
16
|
+
APIErrorType["Auth"] = "auth";
|
|
17
|
+
APIErrorType["Unexpected"] = "unexpected";
|
|
18
|
+
APIErrorType["Validation"] = "validation";
|
|
19
|
+
APIErrorType["Query"] = "query";
|
|
20
|
+
APIErrorType["Route"] = "route";
|
|
21
|
+
})(APIErrorType || (APIErrorType = {}));
|
|
22
|
+
class BaseError extends freighter_1.BaseTypedError {
|
|
23
|
+
constructor(message) {
|
|
24
|
+
super(message, _FREIGHTER_EXCEPTION_TYPE);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Raised when a validation error occurs.
|
|
29
|
+
*/
|
|
30
|
+
class ValidationError extends BaseError {
|
|
31
|
+
constructor(fieldsOrMessage) {
|
|
32
|
+
if (typeof fieldsOrMessage === 'string') {
|
|
33
|
+
super(fieldsOrMessage);
|
|
34
|
+
this.fields = [];
|
|
35
|
+
}
|
|
36
|
+
else if (Array.isArray(fieldsOrMessage)) {
|
|
37
|
+
super(fieldsOrMessage
|
|
38
|
+
.map((field) => `${field.field}: ${field.message}`)
|
|
39
|
+
.join('\n'));
|
|
40
|
+
this.fields = fieldsOrMessage;
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
super(`${fieldsOrMessage.field}: ${fieldsOrMessage.message}`);
|
|
44
|
+
this.fields = [fieldsOrMessage];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.ValidationError = ValidationError;
|
|
49
|
+
/**
|
|
50
|
+
* GeneralError is raised when a general error occurs.
|
|
51
|
+
*/
|
|
52
|
+
class GeneralError extends BaseError {
|
|
53
|
+
}
|
|
54
|
+
exports.GeneralError = GeneralError;
|
|
55
|
+
/**
|
|
56
|
+
* ParseError is raised when a parse error occurs.
|
|
57
|
+
*/
|
|
58
|
+
class ParseError extends BaseError {
|
|
59
|
+
}
|
|
60
|
+
exports.ParseError = ParseError;
|
|
61
|
+
/**
|
|
62
|
+
* AuthError is raised when an authentication error occurs.
|
|
63
|
+
*/
|
|
64
|
+
class AuthError extends BaseError {
|
|
65
|
+
}
|
|
66
|
+
exports.AuthError = AuthError;
|
|
67
|
+
/**
|
|
68
|
+
* UnexpectedError is raised when an unexpected error occurs.
|
|
69
|
+
*/
|
|
70
|
+
class UnexpectedError extends BaseError {
|
|
71
|
+
}
|
|
72
|
+
exports.UnexpectedError = UnexpectedError;
|
|
73
|
+
/**
|
|
74
|
+
* QueryError is raised when a query error occurs.
|
|
75
|
+
*/
|
|
76
|
+
class QueryError extends BaseError {
|
|
77
|
+
}
|
|
78
|
+
exports.QueryError = QueryError;
|
|
79
|
+
/**
|
|
80
|
+
* RouteError is raised when a routing error occurs.
|
|
81
|
+
*/
|
|
82
|
+
class RouteError extends BaseError {
|
|
83
|
+
constructor(message, path) {
|
|
84
|
+
super(message);
|
|
85
|
+
this.path = path;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.RouteError = RouteError;
|
|
89
|
+
/**
|
|
90
|
+
* Raised when time-series data is not contiguous.
|
|
91
|
+
*/
|
|
92
|
+
class ContiguityError extends BaseError {
|
|
93
|
+
}
|
|
94
|
+
exports.ContiguityError = ContiguityError;
|
|
95
|
+
const parsePayload = (payload) => {
|
|
96
|
+
switch (payload.type) {
|
|
97
|
+
case APIErrorType.General:
|
|
98
|
+
return new GeneralError(payload.error.message);
|
|
99
|
+
case APIErrorType.Parse:
|
|
100
|
+
return new ParseError(payload.error.message);
|
|
101
|
+
case APIErrorType.Auth:
|
|
102
|
+
return new AuthError(payload.error.message);
|
|
103
|
+
case APIErrorType.Unexpected:
|
|
104
|
+
return new UnexpectedError(JSON.stringify(payload.error));
|
|
105
|
+
case APIErrorType.Validation:
|
|
106
|
+
return new ValidationError(payload.error.fields);
|
|
107
|
+
case APIErrorType.Query:
|
|
108
|
+
return new QueryError(payload.error.message);
|
|
109
|
+
case APIErrorType.Route:
|
|
110
|
+
return new RouteError(payload.error.path, payload.error.message);
|
|
111
|
+
default:
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
const decode = (encoded) => {
|
|
116
|
+
return parsePayload(APIErrorPayloadSchema.parse(JSON.parse(encoded)));
|
|
117
|
+
};
|
|
118
|
+
const encode = () => {
|
|
119
|
+
throw new Error('Not implemented');
|
|
120
|
+
};
|
|
121
|
+
(0, freighter_1.registerError)({ type: _FREIGHTER_EXCEPTION_TYPE, encode, decode });
|
|
122
|
+
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZXJyb3JzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2xpYi9lcnJvcnMudHMiXS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Q3BCO0FBQ0gsQ0FBQyxDQUFDO0FBRUYsTUFBTSxNQUFNLEdBQUcsQ0FBQyxPQUFlLEVBQXFCLEVBQUU7SUFDcEQsT0FBTyxZQUFZLENBQUMscUJBQXFCLENBQUMsS0FBSyxDQUFDLElBQUksQ0FBQyxLQUFLLENBQUMsT0FBTyxDQUFDLENBQUMsQ0FBQyxDQUFDO0FBQ3hFLENBQUMsQ0FBQztBQUVGLE1BQU0sTUFBTSxHQUFHLEdBQVcsRUFBRTtJQUMxQixNQUFNLElBQUksS0FBSyxDQUFDLGlCQUFpQixDQUFDLENBQUM7QUFDckMsQ0FBQyxDQUFDO0FBRUYsSUFBQSx5QkFBYSxFQUFDLEVBQUUsSUFBSSxFQUFFLHlCQUF5QixFQUFFLE1BQU0sRUFBRSxNQUFNLEVBQUUsQ0FBQyxDQUFDIn0=
|
|
@@ -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,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const telem_1 = require("../telem");
|
|
4
|
+
const iterator_1 = require("./iterator");
|
|
5
|
+
const writer_1 = require("./writer");
|
|
6
|
+
class SegmentClient {
|
|
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 iterator_1.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 writer_1.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 telem_1.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
|
+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RTtZQUM1QixHQUFHLEdBQUcsQ0FBQyxNQUFNLElBQUksQ0FBQyxLQUFLLEVBQUUsQ0FBQyxDQUFDLElBQUksQ0FBQyxDQUFDO1NBQ2xDO2dCQUFTO1lBQ1IsTUFBTSxJQUFJLENBQUMsS0FBSyxFQUFFLENBQUM7U0FDcEI7UUFDRCxPQUFPLEdBQW1CLENBQUM7SUFDN0IsQ0FBQztDQUNGO0FBckhELGdDQXFIQyJ9
|
|
@@ -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
|
+
}
|