@synnaxlabs/x 0.11.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,5 +1,5 @@
1
1
 
2
- > @synnaxlabs/x@0.11.0 build /home/runner/work/synnax/synnax/x/ts
2
+ > @synnaxlabs/x@0.12.0 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.es.js 289.25 kB │ gzip: 54.55 kB │ map: 594.27 kB
14
- [vite:dts] Declaration files built in 2781ms.
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 290.12 kB │ gzip: 54.70 kB │ map: 594.39 kB
17
- ✓ built in 3.62s
16
+ dist/x.cjs.js 290.78 kB │ gzip: 54.89 kB │ map: 596.09 kB
17
+ ✓ built in 3.63s
@@ -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.
package/dist/x.cjs.js CHANGED
@@ -6470,7 +6470,7 @@ class Series {
6470
6470
  bufferUsage: glBufferUsage
6471
6471
  };
6472
6472
  }
6473
- static alloc({ length, dataType, ...props }) {
6473
+ static alloc({ capacity: length, dataType, ...props }) {
6474
6474
  if (length === 0)
6475
6475
  throw new Error("[Series] - cannot allocate an array of length 0");
6476
6476
  const data = new new DataType(dataType).Array(length);
@@ -6515,12 +6515,20 @@ class Series {
6515
6515
  else if (this._refCount < 0)
6516
6516
  throw new Error("cannot release an array with a negative reference count");
6517
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
+ */
6518
6526
  write(other) {
6519
6527
  if (!other.dataType.equals(this.dataType))
6520
6528
  throw new Error("buffer must be of the same type as this array");
6521
6529
  if (this.writePos === FULL_BUFFER)
6522
6530
  return 0;
6523
- const available = this.cap - this.writePos;
6531
+ const available = this.capacity - this.writePos;
6524
6532
  const toWrite = available < other.length ? other.slice(0, available) : other;
6525
6533
  this.underlyingData.set(toWrite.data, this.writePos);
6526
6534
  this.maybeRecomputeMinMax(toWrite);
@@ -6567,18 +6575,18 @@ class Series {
6567
6575
  validateFieldNotNull("timeRange", this._timeRange);
6568
6576
  return this._timeRange;
6569
6577
  }
6570
- /** @returns the capacity of the underlying buffer in bytes. */
6571
- get byteCap() {
6578
+ /** @returns the capacity of the series in bytes. */
6579
+ get byteCapacity() {
6572
6580
  return new Size(this.buffer.byteLength);
6573
6581
  }
6574
- /** @returns the capacity of the underlying buffer in samples. */
6575
- get cap() {
6576
- 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);
6577
6585
  }
6578
- /** @returns the length of the underlying buffer in samples. */
6586
+ /** @returns the length of the series in bytes. */
6579
6587
  get byteLength() {
6580
6588
  if (this.writePos === FULL_BUFFER)
6581
- return this.byteCap;
6589
+ return this.byteCapacity;
6582
6590
  return this.dataType.density.size(this.writePos);
6583
6591
  }
6584
6592
  /** @returns the number of samples in this array. */
@@ -6679,10 +6687,15 @@ class Series {
6679
6687
  get range() {
6680
6688
  return addSamples(this.max, -this.min);
6681
6689
  }
6682
- at(index) {
6690
+ at(index, required) {
6691
+ if (index < 0)
6692
+ index = this.length + index;
6683
6693
  const v = this.data[index];
6684
- if (v == null)
6694
+ if (v == null) {
6695
+ if (required)
6696
+ throw new Error(`[series] - no value at index ${index}`);
6685
6697
  return void 0;
6698
+ }
6686
6699
  return addSamples(v, this.sampleOffset);
6687
6700
  }
6688
6701
  /**
@@ -6696,7 +6709,7 @@ class Series {
6696
6709
  const cf = newF(value);
6697
6710
  while (left2 <= right2) {
6698
6711
  const mid = Math.floor((left2 + right2) / 2);
6699
- const cmp = cf(this.at(mid), value);
6712
+ const cmp = cf(this.at(mid, true), value);
6700
6713
  if (cmp === 0)
6701
6714
  return mid;
6702
6715
  if (cmp < 0)
@@ -6718,7 +6731,7 @@ class Series {
6718
6731
  gl.bindBuffer(gl.ARRAY_BUFFER, this.gl.buffer);
6719
6732
  if (this.writePos !== FULL_BUFFER) {
6720
6733
  if (prevBuffer === 0) {
6721
- gl.bufferData(gl.ARRAY_BUFFER, this.byteCap.valueOf(), gl.STATIC_DRAW);
6734
+ gl.bufferData(gl.ARRAY_BUFFER, this.byteCapacity.valueOf(), gl.STATIC_DRAW);
6722
6735
  }
6723
6736
  const byteOffset = this.dataType.density.size(prevBuffer).valueOf();
6724
6737
  const slice = this.underlyingData.slice(this.gl.prevBuffer, this.writePos);