@synnaxlabs/client 0.2.0 → 0.2.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/.DS_Store +0 -0
- package/.editorconfig +0 -15
- package/.eslintrc.json +0 -33
- package/.gitignore +0 -9
- package/.nyc_output/20720f2d-6abe-420f-a3c5-304d52d60827.json +0 -1
- package/.nyc_output/4725921c-6f1b-4ae9-9819-e455f702d31c.json +0 -1
- package/.nyc_output/47478588-5ffd-4332-873c-facaa4a2fc38.json +0 -1
- package/.nyc_output/48180641-e0b2-49ab-a6eb-e7910e9eac2f.json +0 -1
- package/.nyc_output/cb0abf31-740f-47db-b94a-8e3f8f117cb8.json +0 -1
- package/.nyc_output/fc77fce2-dad0-49a8-8d4b-0a9014ecf8c5.json +0 -1
- package/.nyc_output/processinfo/20720f2d-6abe-420f-a3c5-304d52d60827.json +0 -1
- package/.nyc_output/processinfo/4725921c-6f1b-4ae9-9819-e455f702d31c.json +0 -1
- package/.nyc_output/processinfo/47478588-5ffd-4332-873c-facaa4a2fc38.json +0 -1
- package/.nyc_output/processinfo/48180641-e0b2-49ab-a6eb-e7910e9eac2f.json +0 -1
- package/.nyc_output/processinfo/cb0abf31-740f-47db-b94a-8e3f8f117cb8.json +0 -1
- package/.nyc_output/processinfo/fc77fce2-dad0-49a8-8d4b-0a9014ecf8c5.json +0 -1
- package/.nyc_output/processinfo/index.json +0 -1
- package/.prettierignore +0 -2
- package/build/tsconfig.module.tsbuildinfo +0 -1
- package/build/tsconfig.tsbuildinfo +0 -1
- package/coverage/base.css +0 -224
- package/coverage/block-navigation.js +0 -87
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +0 -191
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -87
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +0 -191
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -196
- package/coverage/lcov-report/src/index.html +0 -116
- package/coverage/lcov-report/src/lib/auth.ts.html +0 -340
- package/coverage/lcov-report/src/lib/channel/client.ts.html +0 -604
- package/coverage/lcov-report/src/lib/channel/creator.ts.html +0 -304
- package/coverage/lcov-report/src/lib/channel/index.html +0 -176
- package/coverage/lcov-report/src/lib/channel/payload.ts.html +0 -139
- package/coverage/lcov-report/src/lib/channel/registry.ts.html +0 -202
- package/coverage/lcov-report/src/lib/channel/retriever.ts.html +0 -244
- package/coverage/lcov-report/src/lib/client.ts.html +0 -244
- package/coverage/lcov-report/src/lib/errors.ts.html +0 -484
- package/coverage/lcov-report/src/lib/index.html +0 -176
- package/coverage/lcov-report/src/lib/segment/client.ts.html +0 -463
- package/coverage/lcov-report/src/lib/segment/index.html +0 -206
- package/coverage/lcov-report/src/lib/segment/iterator.ts.html +0 -928
- package/coverage/lcov-report/src/lib/segment/payload.ts.html +0 -139
- package/coverage/lcov-report/src/lib/segment/splitter.ts.html +0 -181
- package/coverage/lcov-report/src/lib/segment/typed.ts.html +0 -307
- package/coverage/lcov-report/src/lib/segment/validator.ts.html +0 -331
- package/coverage/lcov-report/src/lib/segment/writer.ts.html +0 -727
- package/coverage/lcov-report/src/lib/telem.ts.html +0 -2056
- package/coverage/lcov-report/src/lib/transport.ts.html +0 -196
- package/coverage/lcov-report/src/lib/user/index.html +0 -116
- package/coverage/lcov-report/src/lib/user/payload.ts.html +0 -109
- package/coverage/lcov-report/src/lib/util/index.html +0 -116
- package/coverage/lcov-report/src/lib/util/telem.ts.html +0 -124
- package/coverage/lcov-report/src/setupspecs.ts.html +0 -133
- package/coverage/lcov.info +0 -1230
- package/coverage/prettify.css +0 -1
- package/coverage/prettify.js +0 -2
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +0 -196
- package/coverage/src/index.html +0 -116
- package/coverage/src/lib/auth.ts.html +0 -340
- package/coverage/src/lib/channel/client.ts.html +0 -604
- package/coverage/src/lib/channel/creator.ts.html +0 -304
- package/coverage/src/lib/channel/index.html +0 -176
- package/coverage/src/lib/channel/payload.ts.html +0 -139
- package/coverage/src/lib/channel/registry.ts.html +0 -202
- package/coverage/src/lib/channel/retriever.ts.html +0 -244
- package/coverage/src/lib/client.ts.html +0 -244
- package/coverage/src/lib/errors.ts.html +0 -484
- package/coverage/src/lib/index.html +0 -176
- package/coverage/src/lib/segment/client.ts.html +0 -463
- package/coverage/src/lib/segment/index.html +0 -206
- package/coverage/src/lib/segment/iterator.ts.html +0 -928
- package/coverage/src/lib/segment/payload.ts.html +0 -139
- package/coverage/src/lib/segment/splitter.ts.html +0 -181
- package/coverage/src/lib/segment/typed.ts.html +0 -307
- package/coverage/src/lib/segment/validator.ts.html +0 -331
- package/coverage/src/lib/segment/writer.ts.html +0 -727
- package/coverage/src/lib/telem.ts.html +0 -2056
- package/coverage/src/lib/transport.ts.html +0 -196
- package/coverage/src/lib/user/index.html +0 -116
- package/coverage/src/lib/user/payload.ts.html +0 -109
- package/coverage/src/lib/util/index.html +0 -116
- package/coverage/src/lib/util/telem.ts.html +0 -124
- package/coverage/src/setupspecs.ts.html +0 -133
- package/src/index.ts +0 -13
- package/src/lib/.DS_Store +0 -0
- package/src/lib/auth.spec.ts +0 -36
- package/src/lib/auth.ts +0 -85
- package/src/lib/channel/channel.spec.ts +0 -49
- package/src/lib/channel/client.ts +0 -173
- package/src/lib/channel/creator.ts +0 -73
- package/src/lib/channel/payload.ts +0 -18
- package/src/lib/channel/registry.ts +0 -39
- package/src/lib/channel/retriever.ts +0 -53
- package/src/lib/client.ts +0 -53
- package/src/lib/errors.ts +0 -133
- package/src/lib/segment/client.ts +0 -126
- package/src/lib/segment/iterator.spec.ts +0 -78
- package/src/lib/segment/iterator.ts +0 -281
- package/src/lib/segment/payload.ts +0 -18
- package/src/lib/segment/splitter.ts +0 -32
- package/src/lib/segment/typed.ts +0 -74
- package/src/lib/segment/validator.ts +0 -82
- package/src/lib/segment/writer.spec.ts +0 -85
- package/src/lib/segment/writer.ts +0 -214
- package/src/lib/telem.spec.ts +0 -200
- package/src/lib/telem.ts +0 -657
- package/src/lib/transport.ts +0 -37
- package/src/lib/user/payload.ts +0 -8
- package/src/lib/util/telem.ts +0 -13
- package/src/setupspecs.ts +0 -16
- package/tsconfig.json +0 -47
- package/tsconfig.module.json +0 -9
- package/yarn-error.log +0 -5756
- package/yarn.lock +0 -5936
package/src/lib/telem.ts
DELETED
|
@@ -1,657 +0,0 @@
|
|
|
1
|
-
import { registerCustomTypeEncoder } from '@synnaxlabs/freighter';
|
|
2
|
-
|
|
3
|
-
const valueOfEncoder = (value: unknown): unknown => value?.valueOf();
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Represents a nanosecond precision UTC timestamp.
|
|
7
|
-
*/
|
|
8
|
-
export class TimeStamp extends Number {
|
|
9
|
-
constructor(value: UnparsedTimeStamp) {
|
|
10
|
-
super(value);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Checks if the TimeStamp is equal to another TimeStamp.
|
|
15
|
-
* @param other - the other TimeStamp to compare to.
|
|
16
|
-
* @returns true if the TimeStamps are equal, false otherwise.
|
|
17
|
-
*/
|
|
18
|
-
equals(other: UnparsedTimeStamp): boolean {
|
|
19
|
-
return this.valueOf() === new TimeStamp(other).valueOf();
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Creates a TimeSpan representing the duration between the two timestamps.
|
|
24
|
-
* @param other - the other TimeStamp to compare to.
|
|
25
|
-
* @returns a TimeSpan representing the duration between the two timestamps.
|
|
26
|
-
* The span is guaranteed to be positive.
|
|
27
|
-
*/
|
|
28
|
-
span(other: UnparsedTimeStamp): TimeSpan {
|
|
29
|
-
return this.range(other).span();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Creates a TimeRange spanning the given TimeStamp.
|
|
34
|
-
* @param other - the other TimeStamp to compare to.
|
|
35
|
-
* @returns a TimeRange spanning the given TimeStamp that is guaranteed to be valid,
|
|
36
|
-
* regardless of the TimeStamp order.
|
|
37
|
-
*/
|
|
38
|
-
range(other: UnparsedTimeStamp): TimeRange {
|
|
39
|
-
return new TimeRange(this, other).makeValid();
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Creates a TimeRange starting at the TimeStamp and spanning the given TimeSpan.
|
|
44
|
-
* @param other - the TimeSpan to span.
|
|
45
|
-
* @returns a TimeRange starting at the TimeStamp and spanning the given TimeSpan.
|
|
46
|
-
* The TimeRange is guaranteed to be valid.
|
|
47
|
-
*/
|
|
48
|
-
spanRange(other: UnparsedTimeSpan): TimeRange {
|
|
49
|
-
return this.range(this.add(other)).makeValid();
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Checks if the TimeStamp represents the unix epoch.
|
|
54
|
-
* @returns true if the TimeStamp represents the unix epoch, false otherwise.
|
|
55
|
-
*/
|
|
56
|
-
isZero(): boolean {
|
|
57
|
-
return this.valueOf() === 0;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Checks if the TimeStamp is after the given TimeStamp.
|
|
62
|
-
* @param other - the other TimeStamp to compare to.
|
|
63
|
-
* @returns true if the TimeStamp is after the given TimeStamp, false otherwise.
|
|
64
|
-
*/
|
|
65
|
-
after(other: UnparsedTimeStamp): boolean {
|
|
66
|
-
return this.valueOf() > new TimeStamp(other).valueOf();
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Checks if the TimeStamp is after or equal to the given TimeStamp.
|
|
71
|
-
* @param other - the other TimeStamp to compare to.
|
|
72
|
-
* @returns true if the TimeStamp is after or equal to the given TimeStamp, false otherwise.
|
|
73
|
-
*/
|
|
74
|
-
afterEq(other: UnparsedTimeStamp): boolean {
|
|
75
|
-
return this.valueOf() >= new TimeStamp(other).valueOf();
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Checks if the TimeStamp is before the given TimeStamp.
|
|
80
|
-
* @param other - the other TimeStamp to compare to.
|
|
81
|
-
* @returns true if the TimeStamp is before the given TimeStamp, false otherwise.
|
|
82
|
-
*/
|
|
83
|
-
before(other: UnparsedTimeStamp): boolean {
|
|
84
|
-
return this.valueOf() < new TimeStamp(other).valueOf();
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Checks if TimeStamp is before or equal to the current timestamp.
|
|
89
|
-
* @param other - the other TimeStamp to compare to.
|
|
90
|
-
* @returns true if TimeStamp is before or equal to the current timestamp, false otherwise.
|
|
91
|
-
*/
|
|
92
|
-
beforeEq(other: UnparsedTimeStamp): boolean {
|
|
93
|
-
return this.valueOf() <= new TimeStamp(other).valueOf();
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Adds a TimeSpan to the TimeStamp.
|
|
98
|
-
* @param span - the TimeSpan to add.
|
|
99
|
-
* @returns a new TimeStamp representing the sum of the TimeStamp and TimeSpan.
|
|
100
|
-
*/
|
|
101
|
-
add(span: UnparsedTimeSpan): TimeStamp {
|
|
102
|
-
return new TimeStamp(this.valueOf() + span.valueOf());
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Subtracts a TimeSpan from the TimeStamp.
|
|
107
|
-
* @param span - the TimeSpan to subtract.
|
|
108
|
-
* @returns a new TimeStamp representing the difference of the TimeStamp and TimeSpan.
|
|
109
|
-
*/
|
|
110
|
-
sub(span: UnparsedTimeSpan): TimeStamp {
|
|
111
|
-
return new TimeStamp(this.valueOf() - span.valueOf());
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/** The maximum possible value for a timestamp */
|
|
115
|
-
static readonly Max = new TimeStamp(TimeStamp.MAX_VALUE);
|
|
116
|
-
|
|
117
|
-
/** The minimum possible value for a timestamp */
|
|
118
|
-
static readonly Min = new TimeStamp(TimeStamp.MIN_VALUE);
|
|
119
|
-
|
|
120
|
-
/** The unix epoch */
|
|
121
|
-
static readonly Zero = new TimeStamp(0);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* TimeSpan represents a nanosecond precision duration.
|
|
126
|
-
*/
|
|
127
|
-
export class TimeSpan extends Number {
|
|
128
|
-
constructor(value: UnparsedTimeSpan) {
|
|
129
|
-
super(value);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* @returns the number of seconds in the TimeSpan.
|
|
134
|
-
*/
|
|
135
|
-
seconds(): number {
|
|
136
|
-
return this.valueOf() / TimeSpan.Seconds(1).valueOf();
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* Checks if the TimeSpan represents a zero duration.
|
|
141
|
-
* @returns true if the TimeSpan represents a zero duration, false otherwise.
|
|
142
|
-
*/
|
|
143
|
-
isZero(): boolean {
|
|
144
|
-
return this.valueOf() === 0;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Checks if the TimeSpan is equal to another TimeSpan.
|
|
149
|
-
* @returns true if the TimeSpans are equal, false otherwise.
|
|
150
|
-
*/
|
|
151
|
-
equals(other: UnparsedTimeSpan): boolean {
|
|
152
|
-
return this.valueOf() === new TimeSpan(other).valueOf();
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Adds a TimeSpan to the TimeSpan.
|
|
157
|
-
* @returns a new TimeSpan representing the sum of the two TimeSpans.
|
|
158
|
-
*/
|
|
159
|
-
add(other: UnparsedTimeSpan): TimeSpan {
|
|
160
|
-
return new TimeSpan(this.valueOf() + new TimeSpan(other).valueOf());
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* Creates a TimeSpan representing the duration between the two timestamps.
|
|
165
|
-
* @param other
|
|
166
|
-
*/
|
|
167
|
-
sub(other: UnparsedTimeSpan): TimeSpan {
|
|
168
|
-
return new TimeSpan(this.valueOf() - new TimeSpan(other).valueOf());
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Creates a TimeSpan representing the given number of nanoseconds.
|
|
173
|
-
* @param value - the number of nanoseconds.
|
|
174
|
-
* @returns a TimeSpan representing the given number of nanoseconds.
|
|
175
|
-
*/
|
|
176
|
-
static Nanoseconds(value: UnparsedTimeSpan = 1): TimeSpan {
|
|
177
|
-
return new TimeSpan(value);
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* A nanosecond.
|
|
182
|
-
*/
|
|
183
|
-
static readonly Nanosecond = TimeSpan.Nanoseconds(1);
|
|
184
|
-
|
|
185
|
-
/**
|
|
186
|
-
* Creates a TimeSpan representing the given number of microseconds.
|
|
187
|
-
* @param value - the number of microseconds.
|
|
188
|
-
* @returns a TimeSpan representing the given number of microseconds.
|
|
189
|
-
*/
|
|
190
|
-
static Microseconds(value: UnparsedTimeStamp = 1): TimeSpan {
|
|
191
|
-
return TimeSpan.Nanoseconds(value.valueOf() * 1000);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
/**
|
|
195
|
-
* A microsecond.
|
|
196
|
-
*/
|
|
197
|
-
static readonly Microsecond = TimeSpan.Microseconds(1);
|
|
198
|
-
|
|
199
|
-
/**
|
|
200
|
-
* Creates a TimeSpan representing the given number of milliseconds.
|
|
201
|
-
* @param value - the number of milliseconds.
|
|
202
|
-
* @returns a TimeSpan representing the given number of milliseconds.
|
|
203
|
-
*/
|
|
204
|
-
static Milliseconds(value: UnparsedTimeStamp = 1): TimeSpan {
|
|
205
|
-
return TimeSpan.Microseconds(value.valueOf() * 1000);
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
/**
|
|
209
|
-
* A millisecond.
|
|
210
|
-
*/
|
|
211
|
-
static readonly Millisecond = TimeSpan.Milliseconds(1);
|
|
212
|
-
|
|
213
|
-
/**
|
|
214
|
-
* Creates a TimeSpan representing the given number of seconds.
|
|
215
|
-
* @param value - the number of seconds.
|
|
216
|
-
* @returns a TimeSpan representing the given number of seconds.
|
|
217
|
-
*/
|
|
218
|
-
static Seconds(value: UnparsedTimeStamp = 1): TimeSpan {
|
|
219
|
-
return TimeSpan.Milliseconds(value.valueOf() * 1000);
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
/**
|
|
223
|
-
* A second.
|
|
224
|
-
*/
|
|
225
|
-
static readonly Second = TimeSpan.Seconds(1);
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* Creates a TimeSpan representing the given number of minutes.
|
|
229
|
-
* @param value - the number of minutes.
|
|
230
|
-
* @returns a TimeSpan representing the given number of minutes.
|
|
231
|
-
*/
|
|
232
|
-
static Minutes(value: UnparsedTimeStamp = 1): TimeSpan {
|
|
233
|
-
return TimeSpan.Seconds(value.valueOf() * 60);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* A minute.
|
|
238
|
-
*/
|
|
239
|
-
static readonly Minute = TimeSpan.Minutes(1);
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* Creates a TimeSpan representing the given number of hours.
|
|
243
|
-
* @param value - the number of hours.
|
|
244
|
-
* @returns a TimeSpan representing the given number of hours.
|
|
245
|
-
*/
|
|
246
|
-
static Hours(value: UnparsedTimeStamp = 1): TimeSpan {
|
|
247
|
-
return TimeSpan.Minutes(value.valueOf() * 60);
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
/**
|
|
251
|
-
* Represents an hour.
|
|
252
|
-
*/
|
|
253
|
-
static readonly Hour = TimeSpan.Hours(1);
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* The maximum possible value for a TimeSpan.
|
|
257
|
-
*/
|
|
258
|
-
static readonly Max = new TimeSpan(TimeSpan.MAX_VALUE);
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
* The minimum possible value for a TimeSpan.
|
|
262
|
-
*/
|
|
263
|
-
static readonly Min = new TimeSpan(TimeSpan.MIN_VALUE);
|
|
264
|
-
|
|
265
|
-
/**
|
|
266
|
-
* The zero value for a TimeSpan.
|
|
267
|
-
*/
|
|
268
|
-
static readonly Zero = new TimeSpan(0);
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
/**
|
|
272
|
-
* Rate represents a data rate in Hz.
|
|
273
|
-
*/
|
|
274
|
-
export class Rate extends Number {
|
|
275
|
-
constructor(value: UnparsedRate) {
|
|
276
|
-
super(value);
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
/**
|
|
280
|
-
* @returns the number of seconds in the Rate.
|
|
281
|
-
*/
|
|
282
|
-
equals(other: UnparsedRate): boolean {
|
|
283
|
-
return this.valueOf() === new Rate(other).valueOf();
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* Calculates the period of the Rate as a TimeSpan.
|
|
288
|
-
* @returns a TimeSpan representing the period of the Rate.
|
|
289
|
-
*/
|
|
290
|
-
period(): TimeSpan {
|
|
291
|
-
return new TimeSpan(TimeSpan.Seconds(this.valueOf()).valueOf());
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
/**
|
|
295
|
-
* Calculates the number of samples in the given TimeSpan at this rate.
|
|
296
|
-
* @param duration - the duration to calculate the sample count from.
|
|
297
|
-
* @returns the number of samples in the given TimeSpan at this rate.
|
|
298
|
-
*/
|
|
299
|
-
sampleCount(duration: UnparsedTimeSpan): number {
|
|
300
|
-
return new TimeSpan(duration).seconds() * this.valueOf();
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
* Calculates the number of bytes in the given TimeSpan at this rate.
|
|
305
|
-
* @param span - the duration to calculate the byte count from.
|
|
306
|
-
* @param density - the density of the data in bytes per sample.
|
|
307
|
-
* @returns the number of bytes in the given TimeSpan at this rate.
|
|
308
|
-
*/
|
|
309
|
-
byteCount(span: UnparsedTimeSpan, density: UnparsedDensity): number {
|
|
310
|
-
return this.sampleCount(span) * new Density(density).valueOf();
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
/**
|
|
314
|
-
* Calculates a TimeSpan given the number of samples at this rate.
|
|
315
|
-
* @param sampleCount - the number of samples in the span.
|
|
316
|
-
* @returns a TimeSpan that corresponds to the given number of samples.
|
|
317
|
-
*/
|
|
318
|
-
span(sampleCount: number): TimeSpan {
|
|
319
|
-
return TimeSpan.Seconds(sampleCount / this.valueOf());
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
/**
|
|
323
|
-
* Calculates a TimeSpan given the number of bytes at this rate.
|
|
324
|
-
* @param size - the number of bytes in the span.
|
|
325
|
-
* @param density - the density of the data in bytes per sample.
|
|
326
|
-
* @returns a TimeSpan that corresponds to the given number of bytes.
|
|
327
|
-
*/
|
|
328
|
-
byteSpan(size: Size, density: UnparsedDensity): TimeSpan {
|
|
329
|
-
return this.span(size.valueOf() / density.valueOf());
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
/**
|
|
333
|
-
* Creates a Rate representing the given number of Hz.
|
|
334
|
-
* @param value - the number of Hz.
|
|
335
|
-
* @returns a Rate representing the given number of Hz.
|
|
336
|
-
*/
|
|
337
|
-
static Hz(value: number): Rate {
|
|
338
|
-
return new Rate(value);
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
/**
|
|
342
|
-
* Creates a Rate representing the given number of kHz.
|
|
343
|
-
* @param value - the number of kHz.
|
|
344
|
-
* @returns a Rate representing the given number of kHz.
|
|
345
|
-
*/
|
|
346
|
-
static KHz(value: number): Rate {
|
|
347
|
-
return Rate.Hz(value * 1000);
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
/**
|
|
352
|
-
* Density represents the number of bytes in a value.
|
|
353
|
-
*/
|
|
354
|
-
export class Density extends Number {
|
|
355
|
-
/**
|
|
356
|
-
* Creates a Density representing the given number of bytes per value.
|
|
357
|
-
* @param value - the number of bytes per value.
|
|
358
|
-
* @returns a Density representing the given number of bytes per value.
|
|
359
|
-
* @constructor
|
|
360
|
-
*/
|
|
361
|
-
constructor(value: UnparsedDensity) {
|
|
362
|
-
super(value);
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
/**
|
|
366
|
-
* Represents an Unknown/Invalid Density.
|
|
367
|
-
*/
|
|
368
|
-
static readonly Unknown = new Density(0);
|
|
369
|
-
/**
|
|
370
|
-
* Represents a Density of 64 bits per value.
|
|
371
|
-
*/
|
|
372
|
-
static readonly Bit64 = new Density(8);
|
|
373
|
-
/**
|
|
374
|
-
* Represents a Density of 32 bits per value.
|
|
375
|
-
*/
|
|
376
|
-
static readonly Bit32 = new Density(4);
|
|
377
|
-
/**
|
|
378
|
-
* Represents a Density of 16 bits per value.
|
|
379
|
-
*/
|
|
380
|
-
static readonly Bit16 = new Density(2);
|
|
381
|
-
/**
|
|
382
|
-
* Represents a Density of 8 bits per value.
|
|
383
|
-
*/
|
|
384
|
-
static readonly Bit8 = new Density(1);
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
/**
|
|
388
|
-
* TimeRange represents a range of time between two TimeStamps. It's important
|
|
389
|
-
* to note that the start of the range is inclusive, while the end of the range
|
|
390
|
-
* is exclusive.
|
|
391
|
-
*
|
|
392
|
-
* @property start - a TimeStamp representing the start of the range.
|
|
393
|
-
* @property end - a Timestamp representing the end of the range.
|
|
394
|
-
*/
|
|
395
|
-
export class TimeRange {
|
|
396
|
-
start: TimeStamp;
|
|
397
|
-
end: TimeStamp;
|
|
398
|
-
|
|
399
|
-
/**
|
|
400
|
-
* Creates a TimeRange from the given start and end TimeStamps.
|
|
401
|
-
* @param start - a TimeStamp representing the start of the range.
|
|
402
|
-
* @param end - a TimeStamp representing the end of the range.
|
|
403
|
-
*/
|
|
404
|
-
constructor(start: UnparsedTimeStamp, end: UnparsedTimeStamp) {
|
|
405
|
-
this.start = new TimeStamp(start);
|
|
406
|
-
this.end = new TimeStamp(end);
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
/**
|
|
410
|
-
* @returns the TimeSpan occupied by the TimeRange.
|
|
411
|
-
*/
|
|
412
|
-
span(): TimeSpan {
|
|
413
|
-
return new TimeSpan(this.end.valueOf() - this.start.valueOf());
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
/**
|
|
417
|
-
* Checks if the timestamp is valid i.e. the start is before the end.
|
|
418
|
-
* @returns true if the TimeRange is valid.
|
|
419
|
-
*/
|
|
420
|
-
isValid(): boolean {
|
|
421
|
-
return this.start.valueOf() <= this.end.valueOf();
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
/**
|
|
425
|
-
* Makes sure the TimeRange is valid i.e. the start is before the end.
|
|
426
|
-
* @returns a TimeRange that is valid.
|
|
427
|
-
*/
|
|
428
|
-
makeValid(): TimeRange {
|
|
429
|
-
return this.isValid() ? this : this.swap();
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
/**
|
|
433
|
-
* Checks if the TimeRange has a zero span.
|
|
434
|
-
* @returns true if the TimeRange has a zero span.
|
|
435
|
-
*/
|
|
436
|
-
isZero(): boolean {
|
|
437
|
-
return this.span().isZero();
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
/**
|
|
441
|
-
* Creates a new TimeRange with the start and end swapped.
|
|
442
|
-
* @returns a TimeRange with the start and end swapped.
|
|
443
|
-
*/
|
|
444
|
-
swap(): TimeRange {
|
|
445
|
-
return new TimeRange(this.end, this.start);
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
/**
|
|
449
|
-
* Checks if the TimeRange is equal to the given TimeRange.
|
|
450
|
-
* @param other - the TimeRange to compare to.
|
|
451
|
-
* @returns true if the TimeRange is equal to the given TimeRange.
|
|
452
|
-
*/
|
|
453
|
-
equals(other: TimeRange): boolean {
|
|
454
|
-
return this.start.equals(other.start) && this.end.equals(other.end);
|
|
455
|
-
}
|
|
456
|
-
|
|
457
|
-
static readonly Max = new TimeRange(TimeStamp.Min, TimeStamp.Max);
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
/**
|
|
461
|
-
* DataType is a string that represents a data type.
|
|
462
|
-
*/
|
|
463
|
-
export class DataType extends String {
|
|
464
|
-
constructor(value: UnparsedDataType) {
|
|
465
|
-
if (typeof value === 'string') {
|
|
466
|
-
super(value);
|
|
467
|
-
} else {
|
|
468
|
-
super(value.valueOf());
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
get arrayConstructor(): TypedArrayConstructor {
|
|
473
|
-
const v = ARRAY_CONSTRUCTORS.get(this.string);
|
|
474
|
-
if (v === undefined) {
|
|
475
|
-
throw new Error(`Unknown data type: ${this.string}`);
|
|
476
|
-
}
|
|
477
|
-
return v;
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
get string(): string {
|
|
481
|
-
return this.valueOf();
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
get density(): Density {
|
|
485
|
-
const v = DATA_TYPE_DENSITIES.get(this.string);
|
|
486
|
-
if (v === undefined) {
|
|
487
|
-
throw new Error(`Unknown data type: ${this.string}`);
|
|
488
|
-
}
|
|
489
|
-
return v;
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
checkArray(array: TypedArray): boolean {
|
|
493
|
-
return array.constructor === this.arrayConstructor;
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
toJSON(): string {
|
|
497
|
-
return this.string;
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
/**
|
|
501
|
-
* Represents an Unknown/Invalid DataType.
|
|
502
|
-
*/
|
|
503
|
-
static readonly Unknown = new DataType('unknown');
|
|
504
|
-
/**
|
|
505
|
-
* Represents a 64-bit floating point value.
|
|
506
|
-
*/
|
|
507
|
-
static readonly Float64 = new DataType('float64');
|
|
508
|
-
/**
|
|
509
|
-
* Represents a 32-bit floating point value.
|
|
510
|
-
*/
|
|
511
|
-
static readonly Float32 = new DataType('float32');
|
|
512
|
-
/**
|
|
513
|
-
* Represents a 64-bit signed integer value.
|
|
514
|
-
*/
|
|
515
|
-
static readonly Int64 = new DataType('int64');
|
|
516
|
-
/**
|
|
517
|
-
* Represents a 32-bit signed integer value.
|
|
518
|
-
*/
|
|
519
|
-
static readonly Int32 = new DataType('int32');
|
|
520
|
-
/**
|
|
521
|
-
* Represents a 16-bit signed integer value.
|
|
522
|
-
*/
|
|
523
|
-
static readonly Int16 = new DataType('int16');
|
|
524
|
-
/**
|
|
525
|
-
* Represents a 8-bit signed integer value.
|
|
526
|
-
*/
|
|
527
|
-
static readonly Int8 = new DataType('int8');
|
|
528
|
-
/**
|
|
529
|
-
* Represents a 64-bit unsigned integer value.
|
|
530
|
-
*/
|
|
531
|
-
static readonly Uint64 = new DataType('uint64');
|
|
532
|
-
/**
|
|
533
|
-
* Represents a 32-bit unsigned integer value.
|
|
534
|
-
*/
|
|
535
|
-
static readonly Uint32 = new DataType('uint32');
|
|
536
|
-
/**
|
|
537
|
-
* Represents a 16-bit unsigned integer value.
|
|
538
|
-
*/
|
|
539
|
-
static readonly Uint16 = new DataType('uint16');
|
|
540
|
-
/**
|
|
541
|
-
* Represents a 8-bit unsigned integer value.
|
|
542
|
-
*/
|
|
543
|
-
static readonly Uint8 = new DataType('uint8');
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
export class Size extends Number {
|
|
547
|
-
constructor(value: UnparsedSize) {
|
|
548
|
-
super(value.valueOf());
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
largerThan(other: Size): boolean {
|
|
552
|
-
return this.valueOf() > other.valueOf();
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
smallerThan(other: Size): boolean {
|
|
556
|
-
return this.valueOf() < other.valueOf();
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
static Bytes(value: UnparsedSize): Size {
|
|
560
|
-
return new Size(value);
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
static readonly Byte = new Size(1);
|
|
564
|
-
|
|
565
|
-
static Kilobytes(value: UnparsedSize): Size {
|
|
566
|
-
return Size.Bytes(value.valueOf() * 1e3);
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
static readonly Kilobyte = Size.Kilobytes(1);
|
|
570
|
-
|
|
571
|
-
static Megabytes(value: UnparsedSize): Size {
|
|
572
|
-
return Size.Kilobytes(value.valueOf() * 1e3);
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
static readonly Megabyte = Size.Megabytes(1);
|
|
576
|
-
|
|
577
|
-
static Gigabytes(value: UnparsedSize): Size {
|
|
578
|
-
return Size.Megabytes(value.valueOf() * 1e3);
|
|
579
|
-
}
|
|
580
|
-
|
|
581
|
-
static readonly Gigabyte = Size.Gigabytes(1);
|
|
582
|
-
|
|
583
|
-
static Terabytes(value: UnparsedSize): Size {
|
|
584
|
-
return Size.Gigabytes(value.valueOf() * 1e3);
|
|
585
|
-
}
|
|
586
|
-
|
|
587
|
-
static readonly Terabyte = Size.Terabytes(1);
|
|
588
|
-
}
|
|
589
|
-
|
|
590
|
-
export type UnparsedTimeStamp = TimeStamp | TimeSpan | number;
|
|
591
|
-
export type UnparsedTimeSpan = TimeSpan | number;
|
|
592
|
-
export type UnparsedRate = Rate | number;
|
|
593
|
-
export type UnparsedDensity = Density | number;
|
|
594
|
-
export type UnparsedDataType = DataType | string;
|
|
595
|
-
export type UnparsedSize = Size | number;
|
|
596
|
-
|
|
597
|
-
registerCustomTypeEncoder({ Class: TimeStamp, write: valueOfEncoder });
|
|
598
|
-
registerCustomTypeEncoder({ Class: TimeSpan, write: valueOfEncoder });
|
|
599
|
-
registerCustomTypeEncoder({
|
|
600
|
-
Class: DataType,
|
|
601
|
-
write: (v) => (v as DataType).string,
|
|
602
|
-
});
|
|
603
|
-
registerCustomTypeEncoder({ Class: Rate, write: valueOfEncoder });
|
|
604
|
-
registerCustomTypeEncoder({ Class: Density, write: valueOfEncoder });
|
|
605
|
-
|
|
606
|
-
export type TypedArray =
|
|
607
|
-
| Uint8Array
|
|
608
|
-
| Uint16Array
|
|
609
|
-
| Uint32Array
|
|
610
|
-
| BigUint64Array
|
|
611
|
-
| Float32Array
|
|
612
|
-
| Float64Array
|
|
613
|
-
| Int8Array
|
|
614
|
-
| Int16Array
|
|
615
|
-
| Int32Array
|
|
616
|
-
| BigInt64Array;
|
|
617
|
-
|
|
618
|
-
type TypedArrayConstructor =
|
|
619
|
-
| Uint8ArrayConstructor
|
|
620
|
-
| Uint16ArrayConstructor
|
|
621
|
-
| Uint32ArrayConstructor
|
|
622
|
-
| BigUint64ArrayConstructor
|
|
623
|
-
| Float32ArrayConstructor
|
|
624
|
-
| Float64ArrayConstructor
|
|
625
|
-
| Int8ArrayConstructor
|
|
626
|
-
| Int16ArrayConstructor
|
|
627
|
-
| Int32ArrayConstructor
|
|
628
|
-
| BigInt64ArrayConstructor;
|
|
629
|
-
|
|
630
|
-
const ARRAY_CONSTRUCTORS: Map<string, TypedArrayConstructor> = new Map<
|
|
631
|
-
string,
|
|
632
|
-
TypedArrayConstructor
|
|
633
|
-
>([
|
|
634
|
-
[DataType.Uint8.string, Uint8Array],
|
|
635
|
-
[DataType.Uint16.string, Uint16Array],
|
|
636
|
-
[DataType.Uint32.string, Uint32Array],
|
|
637
|
-
[DataType.Uint64.string, BigUint64Array],
|
|
638
|
-
[DataType.Float32.string, Float32Array],
|
|
639
|
-
[DataType.Float64.string, Float64Array],
|
|
640
|
-
[DataType.Int8.string, Int8Array],
|
|
641
|
-
[DataType.Int16.string, Int16Array],
|
|
642
|
-
[DataType.Int32.string, Int32Array],
|
|
643
|
-
[DataType.Int64.string, BigInt64Array],
|
|
644
|
-
]);
|
|
645
|
-
|
|
646
|
-
const DATA_TYPE_DENSITIES = new Map<string, Density>([
|
|
647
|
-
[DataType.Uint8.string, Density.Bit8],
|
|
648
|
-
[DataType.Uint16.string, Density.Bit16],
|
|
649
|
-
[DataType.Uint32.string, Density.Bit32],
|
|
650
|
-
[DataType.Uint64.string, Density.Bit64],
|
|
651
|
-
[DataType.Float32.string, Density.Bit32],
|
|
652
|
-
[DataType.Float64.string, Density.Bit64],
|
|
653
|
-
[DataType.Int8.string, Density.Bit8],
|
|
654
|
-
[DataType.Int16.string, Density.Bit16],
|
|
655
|
-
[DataType.Int32.string, Density.Bit32],
|
|
656
|
-
[DataType.Int64.string, Density.Bit64],
|
|
657
|
-
]);
|
package/src/lib/transport.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
HTTPClientFactory,
|
|
3
|
-
JSONEncoderDecoder,
|
|
4
|
-
Middleware,
|
|
5
|
-
StreamClient,
|
|
6
|
-
UnaryClient,
|
|
7
|
-
URL,
|
|
8
|
-
WebSocketClient,
|
|
9
|
-
} from '@synnaxlabs/freighter';
|
|
10
|
-
|
|
11
|
-
export default class Transport {
|
|
12
|
-
url: URL;
|
|
13
|
-
httpFactory: HTTPClientFactory;
|
|
14
|
-
streamClient: StreamClient;
|
|
15
|
-
|
|
16
|
-
constructor(url: URL) {
|
|
17
|
-
this.url = url.child('/api/v1/');
|
|
18
|
-
this.httpFactory = new HTTPClientFactory(
|
|
19
|
-
this.url,
|
|
20
|
-
new JSONEncoderDecoder()
|
|
21
|
-
);
|
|
22
|
-
this.streamClient = new WebSocketClient(new JSONEncoderDecoder(), this.url);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
getClient(): UnaryClient {
|
|
26
|
-
return this.httpFactory.getClient();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
postClient(): UnaryClient {
|
|
30
|
-
return this.httpFactory.postClient();
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
use(...middleware: Middleware[]) {
|
|
34
|
-
this.httpFactory.use(...middleware);
|
|
35
|
-
this.streamClient.use(...middleware);
|
|
36
|
-
}
|
|
37
|
-
}
|
package/src/lib/user/payload.ts
DELETED
package/src/lib/util/telem.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { DataType, TypedArray } from '../telem';
|
|
2
|
-
|
|
3
|
-
export const randomTypedArray = (
|
|
4
|
-
length: number,
|
|
5
|
-
dataType: DataType
|
|
6
|
-
): TypedArray => {
|
|
7
|
-
// generate random bytes of the correct length
|
|
8
|
-
const bytes = new Uint8Array(length * dataType.density.valueOf());
|
|
9
|
-
for (let i = 0; i < bytes.byteLength; i++) {
|
|
10
|
-
bytes[i] = Math.floor(Math.random() * 256);
|
|
11
|
-
}
|
|
12
|
-
return new dataType.arrayConstructor(bytes.buffer);
|
|
13
|
-
};
|