@synnaxlabs/x 0.10.0 → 0.12.0

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,6 +1,6 @@
1
1
 
2
- > @synnaxlabs/x@0.10.0 build /home/runner/work/synnax/synnax/x/ts
3
- > vite build
2
+ > @synnaxlabs/x@0.12.0 build /home/runner/work/synnax/synnax/x/ts
3
+ > tsc --noEmit && vite build
4
4
 
5
5
  vite v5.1.2 building for production...
6
6
  transforming...
@@ -10,8 +10,8 @@ rendering chunks...
10
10
  
11
11
  [vite:dts] Start generate declaration files...
12
12
  computing gzip size...
13
- dist/x.es.js 288.78 kB │ gzip: 54.42 kB │ map: 594.40 kB
14
- [vite:dts] Declaration files built in 2871ms.
13
+ dist/x.es.js 289.91 kB │ gzip: 54.74 kB │ map: 595.98 kB
14
+ [vite:dts] Declaration files built in 2784ms.
15
15
  
16
- dist/x.cjs.js 289.65 kB │ gzip: 54.57 kB │ map: 594.52 kB
17
- ✓ built in 3.78s
16
+ dist/x.cjs.js 290.78 kB │ gzip: 54.89 kB │ map: 596.09 kB
17
+ ✓ built in 3.63s
package/dist/case.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export declare namespace Case {
2
- const toSnake: <T>(entity: T) => Record<string, T[keyof T]>;
3
- const toCamel: <T extends Partial<Record<keyof T, unknown>>>(entity: T) => Record<string, T[keyof T]>;
2
+ const toSnake: <T>(entity: T) => T;
3
+ const toCamel: <T>(entity: T) => T;
4
4
  const capitalize: (str: string) => string;
5
5
  }
@@ -1 +1 @@
1
- export declare const copy: <T extends Partial<Record<keyof T, unknown>>>(obj: T) => T;
1
+ export declare const copy: <T>(obj: T) => T;
@@ -1,2 +1,2 @@
1
1
  import { type Key } from './path';
2
- export declare const deleteD: <T extends Partial<Record<keyof T, unknown>>, D extends number = 5>(target: T, ...keys: Key<T, D>[]) => T;
2
+ export declare const deleteD: <T extends unknown, D extends number = 5>(target: T, ...keys: Key<T, D>[]) => T;
@@ -1,8 +1,2 @@
1
- import { type UnknownRecord } from '../record';
2
- import { Primitive } from '../primitive';
3
- type DeepEqualBaseRecord = UnknownRecord | {
4
- equals?: (other: any) => boolean;
5
- };
6
- export declare const equal: <T extends DeepEqualBaseRecord | DeepEqualBaseRecord[] | Primitive[]>(a: T, b: T) => boolean;
7
- export declare const partialEqual: <T extends Partial<Record<keyof T, unknown>>>(base: T, partial: Partial<T>) => boolean;
8
- export {};
1
+ export declare const equal: <T extends unknown>(a: T, b: T) => boolean;
2
+ export declare const partialEqual: <T extends unknown>(base: T, partial: Partial<T>) => boolean;
@@ -1,2 +1,2 @@
1
1
  import { type Partial } from './partial';
2
- export declare const merge: <T extends globalThis.Partial<Record<keyof T, unknown>>>(base: T, ...objects: Partial<T>[]) => T;
2
+ export declare const merge: <T>(base: T, ...objects: Partial<T>[]) => T;
@@ -1,5 +1,4 @@
1
1
  import { type Join } from '../join';
2
- import { UnknownRecord } from "..";
3
2
  type Prev = [
4
3
  never,
5
4
  0,
@@ -28,10 +27,10 @@ type Prev = [
28
27
  export type Key<T, D extends number = 5> = [D] extends [never] ? never : T extends object ? {
29
28
  [K in keyof T]-?: K extends string | number ? `${K}` | Join<K, Key<T[K], Prev[D]>> : never;
30
29
  }[keyof T] : "";
31
- export type Get<V extends UnknownRecord = UnknownRecord> = ((obj: V, path: string, allowNull: true) => unknown | null) & ((obj: V, path: string, allowNull: boolean) => unknown);
30
+ export type Get = (<T>(obj: T, path: string, allowNull: true) => unknown | null) & (<T>(obj: T, path: string, allowNull?: boolean) => unknown);
32
31
  export declare const get: Get;
33
- export declare const set: (obj: UnknownRecord, path: string, value: unknown) => void;
32
+ export declare const set: <V>(obj: V, path: string, value: unknown) => void;
34
33
  export declare const element: (path: string, index: number) => string;
35
34
  export declare const join: (path: string[]) => string;
36
- export declare const has: (obj: UnknownRecord, path: string) => boolean;
35
+ export declare const has: <V>(obj: V, path: string) => boolean;
37
36
  export {};
@@ -1 +1,2 @@
1
- export declare const isObject: <T extends Partial<Record<import('./record').Key, unknown>> = Partial<Record<import('./record').Key, unknown>>>(item?: unknown) => item is T;
1
+ import { type UnknownRecord } from './record';
2
+ export declare const isObject: <T extends UnknownRecord = UnknownRecord>(item?: unknown) => item is T;
package/dist/record.d.ts CHANGED
@@ -1,12 +1,11 @@
1
1
  import { z } from "zod";
2
- import { type RenderableValue } from './renderable';
3
2
  export type Key = string | number | symbol;
4
- export type KeyedRecord<K extends Key = Key, E extends Record<string, unknown> = Record<string, unknown>> = {
3
+ export type UnknownRecord = {
4
+ [key: Key]: unknown;
5
+ };
6
+ export type Keyed<K extends Key> = {
5
7
  key: K;
6
- } & Partial<Record<keyof E, unknown>>;
7
- export type UnknownRecord<E extends Record<Key, unknown> = Record<Key, unknown>> = Partial<Record<keyof E, unknown>>;
8
- export type RenderableRecord<E extends Record<string, RenderableValue> = Record<string, RenderableValue>> = E;
9
- export type KeyedRenderableRecord<K extends Key = Key, E extends Record<string, RenderableValue> = Record<string, RenderableValue>> = KeyedRecord<K, E> & Omit<RenderableRecord<E>, "key">;
8
+ };
10
9
  export declare const unknownRecordZ: z.ZodRecord<z.ZodUnion<[z.ZodNumber, z.ZodString, z.ZodSymbol]>, z.ZodUnknown>;
11
10
  export type Entries<T> = {
12
11
  [K in keyof T]: [K, T[K]];
package/dist/search.d.ts CHANGED
@@ -1,14 +1,14 @@
1
1
  import { type CompareF } from './compare/compare';
2
- import { type Key, type KeyedRecord } from './record';
2
+ import { type Key, type Keyed } from './record';
3
3
  export declare const Search: {
4
4
  binary: <T>(arr: T[], target: T, compare: CompareF<T>) => number;
5
5
  };
6
- export interface TermSearcher<T, K extends Key, E extends KeyedRecord<K, E>> {
6
+ export interface TermSearcher<T, K extends Key, E extends Keyed<K>> {
7
7
  search: (term: T) => E[];
8
8
  retrieve: (keys: K[]) => E[];
9
9
  page: (offset: number, limit: number) => E[];
10
10
  }
11
- export interface AsyncTermSearcher<T, K extends Key, E extends KeyedRecord<K, E>> {
11
+ export interface AsyncTermSearcher<T, K extends Key, E extends Keyed<K>> {
12
12
  search: (term: T) => Promise<E[]>;
13
13
  retrieve: (keys: K[]) => Promise<E[]>;
14
14
  page: (offset: number, limit: number) => Promise<E[]>;
@@ -236,4 +236,5 @@ export declare const isBox: (value: unknown) => value is {
236
236
  };
237
237
  };
238
238
  export declare const aspect: (b: Box) => number;
239
+ export declare const translate: (b: Box, t: xy.XY) => Box;
239
240
  export {};
@@ -23,7 +23,7 @@ export interface SeriesProps extends BaseSeriesProps {
23
23
  data: ArrayBuffer | NativeTypedArray;
24
24
  }
25
25
  export interface SeriesAllocProps extends BaseSeriesProps {
26
- length: number;
26
+ capacity: number;
27
27
  dataType: CrudeDataType;
28
28
  }
29
29
  export interface SeriesMemInfo {
@@ -62,7 +62,7 @@ export declare class Series {
62
62
  private writePos;
63
63
  /** Tracks the number of entities currently using this array. */
64
64
  private _refCount;
65
- static alloc({ length, dataType, ...props }: SeriesAllocProps): Series;
65
+ static alloc({ capacity: length, dataType, ...props }: SeriesAllocProps): Series;
66
66
  static generateTimestamps(length: number, rate: Rate, start: TimeStamp): Series;
67
67
  get refCount(): number;
68
68
  static fromStrings(data: string[], timeRange?: TimeRange): Series;
@@ -70,6 +70,14 @@ export declare class Series {
70
70
  constructor({ data, dataType, timeRange, sampleOffset, glBufferUsage, alignment, key, }: SeriesProps);
71
71
  acquire(gl?: GLBufferController): void;
72
72
  release(): void;
73
+ /**
74
+ * Writes the given series to this series. If the series being written exceeds the
75
+ * remaining of series being written to, only the portion that fits will be written.
76
+ * @param other the series to write to this series. The data type of the series written
77
+ * must be the same as the data type of the series being written to.
78
+ * @returns the number of samples written. If the entire series fits, this value is
79
+ * equal to the length of the series being written.
80
+ */
73
81
  write(other: Series): number;
74
82
  /** @returns the underlying buffer backing this array. */
75
83
  get buffer(): ArrayBufferLike;
@@ -81,11 +89,11 @@ export declare class Series {
81
89
  parseJSON<Z extends z.ZodTypeAny>(schema: Z): Array<z.output<Z>>;
82
90
  /** @returns the time range of this array. */
83
91
  get timeRange(): TimeRange;
84
- /** @returns the capacity of the underlying buffer in bytes. */
85
- get byteCap(): Size;
86
- /** @returns the capacity of the underlying buffer in samples. */
87
- get cap(): number;
88
- /** @returns the length of the underlying buffer in samples. */
92
+ /** @returns the capacity of the series in bytes. */
93
+ get byteCapacity(): Size;
94
+ /** @returns the capacity of the series in samples. */
95
+ get capacity(): number;
96
+ /** @returns the length of the series in bytes. */
89
97
  get byteLength(): Size;
90
98
  /** @returns the number of samples in this array. */
91
99
  get length(): number;
@@ -110,7 +118,8 @@ export declare class Series {
110
118
  private maybeRecomputeMinMax;
111
119
  enrich(): void;
112
120
  get range(): SampleValue;
113
- at(index: number): SampleValue;
121
+ at(index: number, required: true): SampleValue;
122
+ at(index: number, required?: false): SampleValue | undefined;
114
123
  /**
115
124
  * @returns the index of the first sample that is greater than or equal to the given value.
116
125
  * The underlying array must be sorted. If it is not, the behavior of this method is undefined.
@@ -200,6 +200,7 @@ export declare class TimeSpan extends Number implements Stringer {
200
200
  constructor(value: CrudeTimeSpan);
201
201
  remainder(divisor: TimeSpan): TimeSpan;
202
202
  truncate(span: TimeSpan): TimeSpan;
203
+ multiply(factor: number): TimeSpan;
203
204
  toString(): string;
204
205
  /** @returns the decimal number of days in the timespan */
205
206
  get days(): number;
@@ -625,8 +626,8 @@ export type DataTypeT = string;
625
626
  export type CrudeSize = Size | number | Number;
626
627
  export type SizeT = number;
627
628
  export interface CrudeTimeRange {
628
- start: TimeStampT;
629
- end: TimeStampT;
629
+ start: CrudeTimeStamp;
630
+ end: CrudeTimeStamp;
630
631
  }
631
632
  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>]>;
632
633
  export type NativeTypedArray = z.infer<typeof nativeTypedArray>;
package/dist/x.cjs.js CHANGED
@@ -4740,7 +4740,7 @@ const translateY = (c, y2) => {
4740
4740
  const p = construct$2(c);
4741
4741
  return { x: p.x, y: p.y + y2 };
4742
4742
  };
4743
- const translate = (a, b, v, ...cb) => {
4743
+ const translate$1 = (a, b, v, ...cb) => {
4744
4744
  if (typeof b === "string" && typeof v === "number") {
4745
4745
  if (b === "x")
4746
4746
  return translateX(a, v);
@@ -4811,7 +4811,7 @@ const xy = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
4811
4811
  isZero: isZero$1,
4812
4812
  scale: scale$2,
4813
4813
  set: set$1,
4814
- translate,
4814
+ translate: translate$1,
4815
4815
  translateX,
4816
4816
  translateY,
4817
4817
  translation,
@@ -4950,7 +4950,7 @@ const right = (b) => loc(b, "right");
4950
4950
  const bottom = (b) => loc(b, "bottom");
4951
4951
  const left = (b) => loc(b, "left");
4952
4952
  const top = (b) => loc(b, "top");
4953
- const center = (b) => translate(topLeft(b), {
4953
+ const center = (b) => translate$1(topLeft(b), {
4954
4954
  x: signedWidth(b) / 2,
4955
4955
  y: signedHeight(b) / 2
4956
4956
  });
@@ -4997,6 +4997,16 @@ const isBox = (value) => {
4997
4997
  return "one" in value && "two" in value && "root" in value;
4998
4998
  };
4999
4999
  const aspect = (b) => width(b) / height(b);
5000
+ const translate = (b, t) => {
5001
+ const b_ = construct$1(b);
5002
+ return construct$1(
5003
+ translate$1(b_.one, t),
5004
+ translate$1(b_.two, t),
5005
+ void 0,
5006
+ void 0,
5007
+ b_.root
5008
+ );
5009
+ };
5000
5010
  const box$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
5001
5011
  __proto__: null,
5002
5012
  DECIMAL: DECIMAL$1,
@@ -5032,6 +5042,7 @@ const box$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePropert
5032
5042
  top,
5033
5043
  topLeft,
5034
5044
  topRight,
5045
+ translate,
5035
5046
  width,
5036
5047
  x,
5037
5048
  xBounds,
@@ -5709,6 +5720,9 @@ const _TimeSpan = class _TimeSpan extends Number {
5709
5720
  truncate(span2) {
5710
5721
  return new _TimeSpan(Math.trunc(this.valueOf() / span2.valueOf()) * span2.valueOf());
5711
5722
  }
5723
+ multiply(factor) {
5724
+ return new _TimeSpan(this.valueOf() * factor);
5725
+ }
5712
5726
  toString() {
5713
5727
  const totalDays = this.truncate(_TimeSpan.DAY);
5714
5728
  const totalHours = this.truncate(_TimeSpan.HOUR);
@@ -6456,7 +6470,7 @@ class Series {
6456
6470
  bufferUsage: glBufferUsage
6457
6471
  };
6458
6472
  }
6459
- static alloc({ length, dataType, ...props }) {
6473
+ static alloc({ capacity: length, dataType, ...props }) {
6460
6474
  if (length === 0)
6461
6475
  throw new Error("[Series] - cannot allocate an array of length 0");
6462
6476
  const data = new new DataType(dataType).Array(length);
@@ -6501,12 +6515,20 @@ class Series {
6501
6515
  else if (this._refCount < 0)
6502
6516
  throw new Error("cannot release an array with a negative reference count");
6503
6517
  }
6518
+ /**
6519
+ * Writes the given series to this series. If the series being written exceeds the
6520
+ * remaining of series being written to, only the portion that fits will be written.
6521
+ * @param other the series to write to this series. The data type of the series written
6522
+ * must be the same as the data type of the series being written to.
6523
+ * @returns the number of samples written. If the entire series fits, this value is
6524
+ * equal to the length of the series being written.
6525
+ */
6504
6526
  write(other) {
6505
6527
  if (!other.dataType.equals(this.dataType))
6506
6528
  throw new Error("buffer must be of the same type as this array");
6507
6529
  if (this.writePos === FULL_BUFFER)
6508
6530
  return 0;
6509
- const available = this.cap - this.writePos;
6531
+ const available = this.capacity - this.writePos;
6510
6532
  const toWrite = available < other.length ? other.slice(0, available) : other;
6511
6533
  this.underlyingData.set(toWrite.data, this.writePos);
6512
6534
  this.maybeRecomputeMinMax(toWrite);
@@ -6553,18 +6575,18 @@ class Series {
6553
6575
  validateFieldNotNull("timeRange", this._timeRange);
6554
6576
  return this._timeRange;
6555
6577
  }
6556
- /** @returns the capacity of the underlying buffer in bytes. */
6557
- get byteCap() {
6578
+ /** @returns the capacity of the series in bytes. */
6579
+ get byteCapacity() {
6558
6580
  return new Size(this.buffer.byteLength);
6559
6581
  }
6560
- /** @returns the capacity of the underlying buffer in samples. */
6561
- get cap() {
6562
- return this.dataType.density.length(this.byteCap);
6582
+ /** @returns the capacity of the series in samples. */
6583
+ get capacity() {
6584
+ return this.dataType.density.length(this.byteCapacity);
6563
6585
  }
6564
- /** @returns the length of the underlying buffer in samples. */
6586
+ /** @returns the length of the series in bytes. */
6565
6587
  get byteLength() {
6566
6588
  if (this.writePos === FULL_BUFFER)
6567
- return this.byteCap;
6589
+ return this.byteCapacity;
6568
6590
  return this.dataType.density.size(this.writePos);
6569
6591
  }
6570
6592
  /** @returns the number of samples in this array. */
@@ -6665,10 +6687,15 @@ class Series {
6665
6687
  get range() {
6666
6688
  return addSamples(this.max, -this.min);
6667
6689
  }
6668
- at(index) {
6690
+ at(index, required) {
6691
+ if (index < 0)
6692
+ index = this.length + index;
6669
6693
  const v = this.data[index];
6670
- if (v == null)
6694
+ if (v == null) {
6695
+ if (required)
6696
+ throw new Error(`[series] - no value at index ${index}`);
6671
6697
  return void 0;
6698
+ }
6672
6699
  return addSamples(v, this.sampleOffset);
6673
6700
  }
6674
6701
  /**
@@ -6682,7 +6709,7 @@ class Series {
6682
6709
  const cf = newF(value);
6683
6710
  while (left2 <= right2) {
6684
6711
  const mid = Math.floor((left2 + right2) / 2);
6685
- const cmp = cf(this.at(mid), value);
6712
+ const cmp = cf(this.at(mid, true), value);
6686
6713
  if (cmp === 0)
6687
6714
  return mid;
6688
6715
  if (cmp < 0)
@@ -6697,15 +6724,14 @@ class Series {
6697
6724
  if (!this.dataType.equals(DataType.FLOAT32))
6698
6725
  throw new Error("Only FLOAT32 arrays can be used in WebGL");
6699
6726
  const { buffer, bufferUsage, prevBuffer } = this.gl;
6700
- if (buffer == null) {
6727
+ if (buffer == null)
6701
6728
  this.gl.buffer = gl.createBuffer();
6702
- }
6703
6729
  if (this.writePos === prevBuffer)
6704
6730
  return;
6705
6731
  gl.bindBuffer(gl.ARRAY_BUFFER, this.gl.buffer);
6706
6732
  if (this.writePos !== FULL_BUFFER) {
6707
6733
  if (prevBuffer === 0) {
6708
- gl.bufferData(gl.ARRAY_BUFFER, this.byteCap.valueOf(), gl.STATIC_DRAW);
6734
+ gl.bufferData(gl.ARRAY_BUFFER, this.byteCapacity.valueOf(), gl.STATIC_DRAW);
6709
6735
  }
6710
6736
  const byteOffset = this.dataType.density.size(prevBuffer).valueOf();
6711
6737
  const slice = this.underlyingData.slice(this.gl.prevBuffer, this.writePos);
@@ -6748,6 +6774,7 @@ class Series {
6748
6774
  gl.deleteBuffer(this.gl.buffer);
6749
6775
  this.gl.buffer = null;
6750
6776
  this.gl.prevBuffer = 0;
6777
+ this.gl.control = null;
6751
6778
  }
6752
6779
  get glBuffer() {
6753
6780
  if (this.gl.buffer == null)
@@ -6857,8 +6884,10 @@ const deleteD = (target2, ...keys) => {
6857
6884
  });
6858
6885
  return target2;
6859
6886
  };
6860
- const get = (obj, path, allowNull) => {
6887
+ const get = (obj, path, allowNull = false) => {
6861
6888
  const parts = path.split(".");
6889
+ if (parts.length === 1 && parts[0] === "")
6890
+ return obj;
6862
6891
  let result = obj;
6863
6892
  for (const part of parts) {
6864
6893
  const v = result[part];
@@ -6932,13 +6961,12 @@ const equal = (a, b) => {
6932
6961
  const bArr = b;
6933
6962
  if (aArr.length !== bArr.length)
6934
6963
  return false;
6935
- for (let i = 0; i < aArr.length; i++) {
6964
+ for (let i = 0; i < aArr.length; i++)
6936
6965
  if (!equal(aArr[i], bArr[i]))
6937
6966
  return false;
6938
- }
6939
6967
  return true;
6940
6968
  }
6941
- if (typeof a !== "object" || typeof b !== "object")
6969
+ if (a == null || b == null || typeof a !== "object" || typeof b !== "object")
6942
6970
  return a === b;
6943
6971
  if ("equals" in a)
6944
6972
  return a.equals(b);
@@ -6958,6 +6986,8 @@ const equal = (a, b) => {
6958
6986
  return true;
6959
6987
  };
6960
6988
  const partialEqual = (base, partial) => {
6989
+ if (typeof base !== "object" || base == null)
6990
+ return base === partial;
6961
6991
  const baseKeys = Object.keys(base);
6962
6992
  const partialKeys = Object.keys(partial);
6963
6993
  if (partialKeys.length > baseKeys.length)