@synnaxlabs/x 0.13.0 → 0.14.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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @synnaxlabs/x@0.13.0 build /home/runner/work/synnax/synnax/x/ts
2
+ > @synnaxlabs/x@0.14.2 build /home/runner/work/synnax/synnax/x/ts
3
3
  > tsc --noEmit && vite build
4
4
 
5
5
  vite v5.1.2 building for production...
@@ -10,8 +10,8 @@ rendering chunks...
10
10
  
11
11
  [vite:dts] Start generate declaration files...
12
12
  computing gzip size...
13
- dist/x.js 299.72 kB │ gzip: 56.93 kB │ map: 617.77 kB
14
- [vite:dts] Declaration files built in 2906ms.
13
+ dist/x.js 213.15 kB │ gzip: 49.72 kB │ map: 639.91 kB
14
+ [vite:dts] Declaration files built in 3061ms.
15
15
  
16
- dist/x.cjs 300.61 kB │ gzip: 57.08 kB │ map: 617.89 kB
17
- ✓ built in 3.78s
16
+ dist/x.cjs 140.09 kB │ gzip: 39.81 kB │ map: 619.46 kB
17
+ ✓ built in 3.99s
@@ -1,19 +1,4 @@
1
1
  import { type ZodSchema, type z } from "zod";
2
- /**
3
- * CustomTypeEncoder is an interface for a class that needs to transform its
4
- * value before encoding.
5
- */
6
- interface CustomTypeEncoder {
7
- /** The Class the custom encoder is set for */
8
- Class: Function;
9
- /**
10
- * The function that transforms the value before encoding;
11
- *
12
- * @param instance - The instance of the class to transform.
13
- * @returns The transformed value.
14
- */
15
- write: <P>(instance: P) => unknown;
16
- }
17
2
  /**
18
3
  * EncoderDecoder is an entity that encodes and decodes messages to and from a
19
4
  * binary format.
@@ -36,24 +21,19 @@ export interface EncoderDecoder {
36
21
  */
37
22
  decode: <P>(data: Uint8Array | ArrayBuffer, schema?: ZodSchema<P>) => P;
38
23
  }
39
- interface StaticEncoderDecoder {
40
- registerCustomType: (encoder: CustomTypeEncoder) => void;
41
- }
42
24
  /** MsgpackEncoderDecoder is a msgpack implementation of EncoderDecoder. */
43
25
  export declare class MsgpackEncoderDecoder implements EncoderDecoder {
44
26
  contentType: string;
45
27
  encode(payload: unknown): ArrayBuffer;
46
28
  decode<P extends z.ZodTypeAny>(data: Uint8Array | ArrayBuffer, schema?: P): z.output<P>;
47
- static registerCustomType(encoder: CustomTypeEncoder): void;
48
29
  }
49
30
  /** JSONEncoderDecoder is a JSON implementation of EncoderDecoder. */
50
31
  export declare class JSONEncoderDecoder implements EncoderDecoder {
51
32
  contentType: string;
33
+ readonly decoder: TextDecoder;
34
+ constructor();
52
35
  encode(payload: unknown): ArrayBuffer;
53
36
  decode<P extends z.ZodTypeAny>(data: Uint8Array | ArrayBuffer, schema?: P): z.output<P>;
54
37
  static registerCustomType(): void;
55
38
  }
56
39
  export declare const ENCODERS: EncoderDecoder[];
57
- export declare const ENCODER_CLASSES: StaticEncoderDecoder[];
58
- export declare const registerCustomTypeEncoder: (encoder: CustomTypeEncoder) => void;
59
- export {};
@@ -1,2 +1,2 @@
1
- import { DataTypeT, NativeTypedArray } from './telem';
2
- export declare const randomSeries: (length: number, dataType: DataTypeT) => NativeTypedArray;
1
+ import { type DataTypeT, type TypedArray } from './telem';
2
+ export declare const randomSeries: (length: number, dataType: DataTypeT) => TypedArray;
@@ -1,7 +1,7 @@
1
1
  import { type z } from "zod";
2
2
  import { bounds } from '../spatial';
3
3
  import { type GLBufferController, type GLBufferUsage } from './gl';
4
- import { DataType, type NativeTypedArray, type Rate, Size, TimeRange, type TimeStamp, type CrudeDataType } from './telem';
4
+ import { DataType, type TypedArray, type Rate, Size, TimeRange, TimeStamp, type CrudeDataType, type TelemValue } from './telem';
5
5
  export type SampleValue = number | bigint;
6
6
  export interface SeriesDigest {
7
7
  key: string;
@@ -20,8 +20,10 @@ interface BaseSeriesProps {
20
20
  alignment?: number;
21
21
  key?: string;
22
22
  }
23
+ export type CrudeSeries = Series | ArrayBuffer | TypedArray | string[] | number[] | boolean[] | unknown[] | TimeStamp[] | Date[] | TelemValue;
24
+ export declare const isCrudeSeries: (value: unknown) => value is CrudeSeries;
23
25
  export interface SeriesProps extends BaseSeriesProps {
24
- data: ArrayBuffer | NativeTypedArray;
26
+ data: CrudeSeries;
25
27
  }
26
28
  export interface SeriesAllocProps extends BaseSeriesProps {
27
29
  capacity: number;
@@ -56,19 +58,20 @@ export declare class Series {
56
58
  readonly _timeRange?: TimeRange;
57
59
  readonly alignment: number;
58
60
  /** A cached minimum value. */
59
- private _min?;
61
+ private _cachedMin?;
60
62
  /** A cached maximum value. */
61
- private _max?;
63
+ private _cachedMax?;
62
64
  /** The write position of the buffer. */
63
65
  private writePos;
64
66
  /** Tracks the number of entities currently using this array. */
65
67
  private _refCount;
68
+ private _cachedLength?;
69
+ constructor(props: SeriesProps | CrudeSeries);
66
70
  static alloc({ capacity: length, dataType, ...props }: SeriesAllocProps): Series;
67
71
  static generateTimestamps(length: number, rate: Rate, start: TimeStamp): Series;
68
72
  get refCount(): number;
69
73
  static fromStrings(data: string[], timeRange?: TimeRange): Series;
70
74
  static fromJSON<T>(data: T[], timeRange?: TimeRange): Series;
71
- constructor({ data, dataType, timeRange, sampleOffset, glBufferUsage, alignment, key, }: SeriesProps);
72
75
  acquire(gl?: GLBufferController): void;
73
76
  release(): void;
74
77
  /**
@@ -84,7 +87,7 @@ export declare class Series {
84
87
  get buffer(): ArrayBufferLike;
85
88
  private get underlyingData();
86
89
  /** @returns a native typed array with the proper data type. */
87
- get data(): NativeTypedArray;
90
+ get data(): TypedArray;
88
91
  toStrings(): string[];
89
92
  toUUIDs(): string[];
90
93
  parseJSON<Z extends z.ZodTypeAny>(schema: Z): Array<z.output<Z>>;
@@ -98,6 +101,7 @@ export declare class Series {
98
101
  get byteLength(): Size;
99
102
  /** @returns the number of samples in this array. */
100
103
  get length(): number;
104
+ private calculateCachedLength;
101
105
  /**
102
106
  * Creates a new array with a different data type.
103
107
  * @param target the data type to convert to.
@@ -16,7 +16,7 @@ export type DateComponents = [number?, number?, number?];
16
16
  * 1. A number representing the number of milliseconds since the Unix epoch.
17
17
  * 2. A javascript Date object.
18
18
  * 3. An array of numbers satisfying the DateComponents type, where the first element is the
19
- * year, the second is the month, and the third is the day. To increaase resolution
19
+ * year, the second is the month, and the third is the day. To incraase resolution
20
20
  * when using this method, use the add method. It's important to note that this initializes
21
21
  * a timestamp at midnight UTC, regardless of the timezone specified.
22
22
  * 4. An ISO compliant date or date time string. The time zone component is ignored.
@@ -29,9 +29,13 @@ export type DateComponents = [number?, number?, number?];
29
29
  * @example ts = new TimeStamp([2021, 1, 1]).add(1 * TimeSpan.HOUR) // 1/1/2021 at 1am UTC
30
30
  * @example ts = new TimeStamp("2021-01-01T12:30:00Z") // 1/1/2021 at 12:30pm UTC
31
31
  */
32
- export declare class TimeStamp extends Number implements Stringer {
32
+ export declare class TimeStamp implements Stringer {
33
+ private readonly value;
34
+ readonly encodeValue: true;
33
35
  constructor(value?: CrudeTimeStamp, tzInfo?: TZInfo);
34
36
  private static parseDate;
37
+ encode(): string;
38
+ valueOf(): bigint;
35
39
  private static parseTimeString;
36
40
  private static parseDateTimeString;
37
41
  fString(format?: TimeStampStringFormat, tzInfo?: TZInfo): string;
@@ -153,13 +157,14 @@ export declare class TimeStamp extends Number implements Stringer {
153
157
  /** @returns true if the day portion TimeStamp is today, false otherwise. */
154
158
  get isToday(): boolean;
155
159
  truncate(span: TimeSpan | TimeStamp): TimeStamp;
156
- get bigInt(): bigint;
157
160
  /**
158
161
  * @returns A new TimeStamp representing the current time in UTC. It's important to
159
162
  * note that this TimeStamp is only accurate to the millisecond level (that's the best
160
163
  * JavaScript can do).
161
164
  */
162
165
  static now(): TimeStamp;
166
+ static max(...timestamps: CrudeTimeStamp[]): TimeStamp;
167
+ static min(...timestamps: CrudeTimeStamp[]): TimeStamp;
163
168
  /** @returns a new TimeStamp n nanoseconds after the unix epoch */
164
169
  static nanoseconds(value: number): TimeStamp;
165
170
  static readonly NANOSECOND: TimeStamp;
@@ -194,18 +199,29 @@ export declare class TimeStamp extends Number implements Stringer {
194
199
  /** The unix epoch */
195
200
  static readonly ZERO: TimeStamp;
196
201
  /** A zod schema for validating timestamps */
197
- static readonly z: z.ZodUnion<[z.ZodEffects<z.ZodType<Number, z.ZodTypeDef, Number>, TimeStamp, Number>, z.ZodEffects<z.ZodNumber, TimeStamp, number>, z.ZodType<TimeStamp, z.ZodTypeDef, TimeStamp>]>;
202
+ static readonly z: z.ZodUnion<[z.ZodEffects<z.ZodObject<{
203
+ value: z.ZodBigInt;
204
+ }, "strip", z.ZodTypeAny, {
205
+ value: bigint;
206
+ }, {
207
+ value: bigint;
208
+ }>, TimeStamp, {
209
+ value: bigint;
210
+ }>, z.ZodEffects<z.ZodString, TimeStamp, string>, z.ZodEffects<z.ZodType<Number, z.ZodTypeDef, Number>, TimeStamp, Number>, z.ZodEffects<z.ZodNumber, TimeStamp, number>, z.ZodType<TimeStamp, z.ZodTypeDef, TimeStamp>]>;
198
211
  }
199
212
  /** TimeSpan represents a nanosecond precision duration. */
200
- export declare class TimeSpan extends Number implements Stringer {
213
+ export declare class TimeSpan implements Stringer {
214
+ private readonly value;
215
+ readonly encodeValue: true;
201
216
  constructor(value: CrudeTimeSpan);
217
+ encode(): string;
218
+ valueOf(): bigint;
202
219
  lessThan(other: CrudeTimeSpan): boolean;
203
220
  greaterThan(other: CrudeTimeSpan): boolean;
204
221
  lessThanOrEqual(other: CrudeTimeSpan): boolean;
205
222
  greaterThanOrEqual(other: CrudeTimeSpan): boolean;
206
223
  remainder(divisor: TimeSpan): TimeSpan;
207
224
  truncate(span: TimeSpan): TimeSpan;
208
- multiply(factor: number): TimeSpan;
209
225
  toString(): string;
210
226
  /** @returns the decimal number of days in the timespan */
211
227
  get days(): number;
@@ -313,7 +329,15 @@ export declare class TimeSpan extends Number implements Stringer {
313
329
  /** The zero value for a TimeSpan. */
314
330
  static readonly ZERO: TimeSpan;
315
331
  /** A zod schema for validating and transforming timespans */
316
- static readonly z: z.ZodUnion<[z.ZodEffects<z.ZodType<Number, z.ZodTypeDef, Number>, TimeSpan, Number>, z.ZodEffects<z.ZodNumber, TimeSpan, number>, z.ZodType<TimeSpan, z.ZodTypeDef, TimeSpan>]>;
332
+ static readonly z: z.ZodUnion<[z.ZodEffects<z.ZodObject<{
333
+ value: z.ZodBigInt;
334
+ }, "strip", z.ZodTypeAny, {
335
+ value: bigint;
336
+ }, {
337
+ value: bigint;
338
+ }>, TimeSpan, {
339
+ value: bigint;
340
+ }>, z.ZodEffects<z.ZodString, TimeSpan, string>, z.ZodEffects<z.ZodType<Number, z.ZodTypeDef, Number>, TimeSpan, Number>, z.ZodEffects<z.ZodNumber, TimeSpan, number>, z.ZodType<TimeSpan, z.ZodTypeDef, TimeSpan>]>;
317
341
  }
318
342
  /** Rate represents a data rate in Hz. */
319
343
  export declare class Rate extends Number implements Stringer {
@@ -490,17 +514,49 @@ export declare class TimeRange implements Stringer {
490
514
  static readonly ZERO: TimeRange;
491
515
  /** A zod schema for validating and transforming time ranges */
492
516
  static readonly z: z.ZodUnion<[z.ZodEffects<z.ZodObject<{
493
- start: z.ZodUnion<[z.ZodEffects<z.ZodType<Number, z.ZodTypeDef, Number>, TimeStamp, Number>, z.ZodEffects<z.ZodNumber, TimeStamp, number>, z.ZodType<TimeStamp, z.ZodTypeDef, TimeStamp>]>;
494
- end: z.ZodUnion<[z.ZodEffects<z.ZodType<Number, z.ZodTypeDef, Number>, TimeStamp, Number>, z.ZodEffects<z.ZodNumber, TimeStamp, number>, z.ZodType<TimeStamp, z.ZodTypeDef, TimeStamp>]>;
517
+ start: z.ZodUnion<[z.ZodEffects<z.ZodObject<{
518
+ value: z.ZodBigInt;
519
+ }, "strip", z.ZodTypeAny, {
520
+ value: bigint;
521
+ }, {
522
+ value: bigint;
523
+ }>, TimeStamp, {
524
+ value: bigint;
525
+ }>, z.ZodEffects<z.ZodString, TimeStamp, string>, z.ZodEffects<z.ZodType<Number, z.ZodTypeDef, Number>, TimeStamp, Number>, z.ZodEffects<z.ZodNumber, TimeStamp, number>, z.ZodType<TimeStamp, z.ZodTypeDef, TimeStamp>]>;
526
+ end: z.ZodUnion<[z.ZodEffects<z.ZodObject<{
527
+ value: z.ZodBigInt;
528
+ }, "strip", z.ZodTypeAny, {
529
+ value: bigint;
530
+ }, {
531
+ value: bigint;
532
+ }>, TimeStamp, {
533
+ value: bigint;
534
+ }>, z.ZodEffects<z.ZodString, TimeStamp, string>, z.ZodEffects<z.ZodType<Number, z.ZodTypeDef, Number>, TimeStamp, Number>, z.ZodEffects<z.ZodNumber, TimeStamp, number>, z.ZodType<TimeStamp, z.ZodTypeDef, TimeStamp>]>;
495
535
  }, "strip", z.ZodTypeAny, {
496
536
  start: TimeStamp;
497
537
  end: TimeStamp;
498
538
  }, {
499
- start: (number | Number | TimeStamp) & (number | Number | TimeStamp | undefined);
500
- end: (number | Number | TimeStamp) & (number | Number | TimeStamp | undefined);
539
+ start: (string | number | Number | TimeStamp | {
540
+ value: bigint;
541
+ }) & (string | number | Number | TimeStamp | {
542
+ value: bigint;
543
+ } | undefined);
544
+ end: (string | number | Number | TimeStamp | {
545
+ value: bigint;
546
+ }) & (string | number | Number | TimeStamp | {
547
+ value: bigint;
548
+ } | undefined);
501
549
  }>, TimeRange, {
502
- start: (number | Number | TimeStamp) & (number | Number | TimeStamp | undefined);
503
- end: (number | Number | TimeStamp) & (number | Number | TimeStamp | undefined);
550
+ start: (string | number | Number | TimeStamp | {
551
+ value: bigint;
552
+ }) & (string | number | Number | TimeStamp | {
553
+ value: bigint;
554
+ } | undefined);
555
+ end: (string | number | Number | TimeStamp | {
556
+ value: bigint;
557
+ }) & (string | number | Number | TimeStamp | {
558
+ value: bigint;
559
+ } | undefined);
504
560
  }>, z.ZodType<TimeRange, z.ZodTypeDef, TimeRange>]>;
505
561
  }
506
562
  /** DataType is a string that represents a data type. */
@@ -509,10 +565,11 @@ export declare class DataType extends String implements Stringer {
509
565
  /**
510
566
  * @returns the TypedArray constructor for the DataType.
511
567
  */
512
- get Array(): NativeTypedArrayConstructor;
568
+ get Array(): TypedArrayConstructor;
513
569
  equals(other: DataType): boolean;
514
570
  /** @returns a string representation of the DataType. */
515
571
  toString(): string;
572
+ get isVariable(): boolean;
516
573
  get density(): Density;
517
574
  /**
518
575
  * Checks whether the given TypedArray is of the same type as the DataType.
@@ -520,7 +577,7 @@ export declare class DataType extends String implements Stringer {
520
577
  * @param array - The TypedArray to check.
521
578
  * @returns True if the TypedArray is of the same type as the DataType.
522
579
  */
523
- checkArray(array: NativeTypedArray): boolean;
580
+ checkArray(array: TypedArray): boolean;
524
581
  toJSON(): string;
525
582
  get usesBigInt(): boolean;
526
583
  /** Represents an Unknown/Invalid DataType. */
@@ -545,6 +602,8 @@ export declare class DataType extends String implements Stringer {
545
602
  static readonly UINT16: DataType;
546
603
  /** Represents a 8-bit unsigned integer value. */
547
604
  static readonly UINT8: DataType;
605
+ /** Represents a boolean value. Alias for UINT8. */
606
+ static readonly BOOLEAN: DataType;
548
607
  /** Represents a 64-bit unix epoch. */
549
608
  static readonly TIMESTAMP: DataType;
550
609
  /** Represents a UUID data type */
@@ -555,7 +614,7 @@ export declare class DataType extends String implements Stringer {
555
614
  /** Represents a JSON data type. JSON has an unknown density, and is separated by a
556
615
  * newline character. */
557
616
  static readonly JSON: DataType;
558
- static readonly ARRAY_CONSTRUCTORS: Map<string, NativeTypedArrayConstructor>;
617
+ static readonly ARRAY_CONSTRUCTORS: Map<string, TypedArrayConstructor>;
559
618
  static readonly ARRAY_CONSTRUCTOR_DATA_TYPES: Map<string, DataType>;
560
619
  static readonly DENSITIES: Map<string, Density>;
561
620
  /** All the data types. */
@@ -633,15 +692,15 @@ export declare class Size extends Number implements Stringer {
633
692
  static readonly z: z.ZodUnion<[z.ZodEffects<z.ZodNumber, Size, number>, z.ZodType<Size, z.ZodTypeDef, Size>]>;
634
693
  get isZero(): boolean;
635
694
  }
636
- export type CrudeTimeStamp = TimeStamp | TimeSpan | number | Date | string | DateComponents | Number;
695
+ export type CrudeTimeStamp = bigint | BigInt | TimeStamp | TimeSpan | number | Date | string | DateComponents | Number;
637
696
  export type TimeStampT = number;
638
- export type CrudeTimeSpan = TimeSpan | TimeStamp | number | Number;
697
+ export type CrudeTimeSpan = bigint | BigInt | TimeSpan | TimeStamp | number | Number;
639
698
  export type TimeSpanT = number;
640
699
  export type CrudeRate = Rate | number | Number;
641
700
  export type RateT = number;
642
701
  export type CrudeDensity = Density | number | Number;
643
702
  export type DensityT = number;
644
- export type CrudeDataType = DataType | string | NativeTypedArray;
703
+ export type CrudeDataType = DataType | string | TypedArray;
645
704
  export type DataTypeT = string;
646
705
  export type CrudeSize = Size | number | Number;
647
706
  export type SizeT = number;
@@ -649,9 +708,11 @@ export interface CrudeTimeRange {
649
708
  start: CrudeTimeStamp;
650
709
  end: CrudeTimeStamp;
651
710
  }
652
- export declare const nativeTypedArray: z.ZodUnion<[z.ZodType<Uint8Array, z.ZodTypeDef, Uint8Array>, z.ZodType<Uint16Array, z.ZodTypeDef, Uint16Array>, z.ZodType<Uint32Array, z.ZodTypeDef, Uint32Array>, z.ZodType<BigUint64Array, z.ZodTypeDef, BigUint64Array>, z.ZodType<Float32Array, z.ZodTypeDef, Float32Array>, z.ZodType<Float64Array, z.ZodTypeDef, Float64Array>, z.ZodType<Int8Array, z.ZodTypeDef, Int8Array>, z.ZodType<Int16Array, z.ZodTypeDef, Int16Array>, z.ZodType<Int32Array, z.ZodTypeDef, Int32Array>, z.ZodType<BigInt64Array, z.ZodTypeDef, BigInt64Array>]>;
653
- export type NativeTypedArray = z.infer<typeof nativeTypedArray>;
654
- type NativeTypedArrayConstructor = Uint8ArrayConstructor | Uint16ArrayConstructor | Uint32ArrayConstructor | BigUint64ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor | Int8ArrayConstructor | Int16ArrayConstructor | Int32ArrayConstructor | BigInt64ArrayConstructor;
655
- type TelemValue = number | bigint;
656
- export declare const convertDataType: (source: DataType, target: DataType, value: TelemValue, offset?: number | bigint) => TelemValue;
711
+ export declare const typedArrayZ: z.ZodUnion<[z.ZodType<Uint8Array, z.ZodTypeDef, Uint8Array>, z.ZodType<Uint16Array, z.ZodTypeDef, Uint16Array>, z.ZodType<Uint32Array, z.ZodTypeDef, Uint32Array>, z.ZodType<BigUint64Array, z.ZodTypeDef, BigUint64Array>, z.ZodType<Float32Array, z.ZodTypeDef, Float32Array>, z.ZodType<Float64Array, z.ZodTypeDef, Float64Array>, z.ZodType<Int8Array, z.ZodTypeDef, Int8Array>, z.ZodType<Int16Array, z.ZodTypeDef, Int16Array>, z.ZodType<Int32Array, z.ZodTypeDef, Int32Array>, z.ZodType<BigInt64Array, z.ZodTypeDef, BigInt64Array>]>;
712
+ export type TypedArray = z.infer<typeof typedArrayZ>;
713
+ type TypedArrayConstructor = Uint8ArrayConstructor | Uint16ArrayConstructor | Uint32ArrayConstructor | BigUint64ArrayConstructor | Float32ArrayConstructor | Float64ArrayConstructor | Int8ArrayConstructor | Int16ArrayConstructor | Int32ArrayConstructor | BigInt64ArrayConstructor;
714
+ type NumericTelemValue = number | bigint;
715
+ export type TelemValue = number | bigint | string | boolean | Date | TimeStamp | TimeSpan;
716
+ export declare const isTelemValue: (value: unknown) => value is TelemValue;
717
+ export declare const convertDataType: (source: DataType, target: DataType, value: NumericTelemValue, offset?: number | bigint) => NumericTelemValue;
657
718
  export {};