@synnaxlabs/x 0.7.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.
- package/.eslintrc.cjs +18 -0
- package/.turbo/turbo-build.log +16 -0
- package/.vscode/settings.json +3 -0
- package/LICENSE +4 -0
- package/README.md +44 -0
- package/dist/binary/encoder.d.ts +59 -0
- package/dist/binary/encoder.spec.d.ts +1 -0
- package/dist/binary/index.d.ts +1 -0
- package/dist/case.d.ts +5 -0
- package/dist/change/change.d.ts +32 -0
- package/dist/change/index.d.ts +1 -0
- package/dist/clamp.d.ts +1 -0
- package/dist/compare/compare.d.ts +39 -0
- package/dist/compare/index.d.ts +1 -0
- package/dist/debounce.d.ts +2 -0
- package/dist/deep/copy.d.ts +1 -0
- package/dist/deep/delete.d.ts +2 -0
- package/dist/deep/delete.spec.d.ts +1 -0
- package/dist/deep/equal.d.ts +8 -0
- package/dist/deep/equal.spec.d.ts +1 -0
- package/dist/deep/external.d.ts +7 -0
- package/dist/deep/index.d.ts +1 -0
- package/dist/deep/key.d.ts +30 -0
- package/dist/deep/memo.d.ts +1 -0
- package/dist/deep/merge.d.ts +2 -0
- package/dist/deep/merge.spec.d.ts +1 -0
- package/dist/deep/partial.d.ts +3 -0
- package/dist/destructor.d.ts +1 -0
- package/dist/identity.d.ts +1 -0
- package/dist/index.d.ts +25 -0
- package/dist/join.d.ts +1 -0
- package/dist/kv/index.d.ts +1 -0
- package/dist/kv/types.d.ts +32 -0
- package/dist/mock/MockGLBufferController.d.ts +20 -0
- package/dist/mock/index.d.ts +1 -0
- package/dist/observe/index.d.ts +1 -0
- package/dist/observe/observe.d.ts +11 -0
- package/dist/optional.d.ts +1 -0
- package/dist/primitive.d.ts +8 -0
- package/dist/record.d.ts +14 -0
- package/dist/renderable.d.ts +4 -0
- package/dist/runtime/detect.d.ts +9 -0
- package/dist/runtime/external.d.ts +2 -0
- package/dist/runtime/index.d.ts +1 -0
- package/dist/runtime/os.d.ts +9 -0
- package/dist/search.d.ts +15 -0
- package/dist/spatial/base.d.ts +102 -0
- package/dist/spatial/bounds.d.ts +31 -0
- package/dist/spatial/bounds.spec.d.ts +1 -0
- package/dist/spatial/box.d.ts +265 -0
- package/dist/spatial/box.spec.d.ts +1 -0
- package/dist/spatial/dimensions.d.ts +59 -0
- package/dist/spatial/dimensions.spec.d.ts +1 -0
- package/dist/spatial/direction.d.ts +10 -0
- package/dist/spatial/direction.spec.d.ts +1 -0
- package/dist/spatial/external.d.ts +8 -0
- package/dist/spatial/index.d.ts +1 -0
- package/dist/spatial/location.d.ts +52 -0
- package/dist/spatial/location.spec.d.ts +1 -0
- package/dist/spatial/position.d.ts +2 -0
- package/dist/spatial/scale.d.ts +241 -0
- package/dist/spatial/scale.spec.d.ts +1 -0
- package/dist/spatial/spatial.d.ts +1 -0
- package/dist/spatial/xy.d.ts +116 -0
- package/dist/spatial/xy.spec.d.ts +1 -0
- package/dist/telem/encode.d.ts +1 -0
- package/dist/telem/generate.d.ts +2 -0
- package/dist/telem/gl.d.ts +11 -0
- package/dist/telem/index.d.ts +3 -0
- package/dist/telem/series.d.ts +104 -0
- package/dist/telem/series.spec.d.ts +1 -0
- package/dist/telem/telem.d.ts +633 -0
- package/dist/telem/telem.spec.d.ts +1 -0
- package/dist/toArray.d.ts +1 -0
- package/dist/transform.d.ts +1 -0
- package/dist/unique.d.ts +1 -0
- package/dist/url/index.d.ts +1 -0
- package/dist/url/url.d.ts +46 -0
- package/dist/url/url.spec.d.ts +1 -0
- package/dist/worker/worker.d.ts +32 -0
- package/dist/worker/worker.spec.d.ts +1 -0
- package/dist/x.cjs.js +9046 -0
- package/dist/x.cjs.js.map +1 -0
- package/dist/x.es.js +9047 -0
- package/dist/x.es.js.map +1 -0
- package/package.json +42 -0
- package/src/binary/encoder.spec.ts +31 -0
- package/src/binary/encoder.ts +118 -0
- package/src/binary/index.ts +10 -0
- package/src/case.ts +31 -0
- package/src/change/change.ts +31 -0
- package/src/change/index.ts +10 -0
- package/src/clamp.ts +14 -0
- package/src/compare/compare.ts +116 -0
- package/src/compare/index.ts +10 -0
- package/src/debounce.ts +45 -0
- package/src/deep/copy.ts +13 -0
- package/src/deep/delete.spec.ts +36 -0
- package/src/deep/delete.ts +27 -0
- package/src/deep/equal.spec.ts +82 -0
- package/src/deep/equal.ts +65 -0
- package/src/deep/external.ts +15 -0
- package/src/deep/index.ts +10 -0
- package/src/deep/key.ts +46 -0
- package/src/deep/merge.spec.ts +63 -0
- package/src/deep/merge.ts +41 -0
- package/src/deep/partial.ts +14 -0
- package/src/destructor.ts +10 -0
- package/src/identity.ts +14 -0
- package/src/index.ts +34 -0
- package/src/join.ts +14 -0
- package/src/kv/index.ts +10 -0
- package/src/kv/types.ts +52 -0
- package/src/mock/MockGLBufferController.ts +70 -0
- package/src/mock/index.ts +10 -0
- package/src/observe/index.ts +10 -0
- package/src/observe/observe.ts +33 -0
- package/src/optional.ts +10 -0
- package/src/primitive.ts +46 -0
- package/src/record.ts +45 -0
- package/src/renderable.ts +20 -0
- package/src/runtime/detect.ts +34 -0
- package/src/runtime/external.ts +11 -0
- package/src/runtime/index.ts +10 -0
- package/src/runtime/os.ts +38 -0
- package/src/search.ts +40 -0
- package/src/spatial/base.ts +80 -0
- package/src/spatial/bounds.spec.ts +99 -0
- package/src/spatial/bounds.ts +80 -0
- package/src/spatial/box.spec.ts +137 -0
- package/src/spatial/box.ts +326 -0
- package/src/spatial/dimensions.spec.ts +47 -0
- package/src/spatial/dimensions.ts +64 -0
- package/src/spatial/direction.spec.ts +25 -0
- package/src/spatial/direction.ts +47 -0
- package/src/spatial/external.ts +17 -0
- package/src/spatial/index.ts +10 -0
- package/src/spatial/location.spec.ts +24 -0
- package/src/spatial/location.ts +124 -0
- package/src/spatial/position.ts +26 -0
- package/src/spatial/scale.spec.ts +74 -0
- package/src/spatial/scale.ts +351 -0
- package/src/spatial/spatial.ts +17 -0
- package/src/spatial/xy.spec.ts +68 -0
- package/src/spatial/xy.ts +164 -0
- package/src/telem/encode.ts +22 -0
- package/src/telem/generate.ts +19 -0
- package/src/telem/gl.ts +22 -0
- package/src/telem/index.ts +12 -0
- package/src/telem/series.spec.ts +289 -0
- package/src/telem/series.ts +449 -0
- package/src/telem/telem.spec.ts +302 -0
- package/src/telem/telem.ts +1237 -0
- package/src/toArray.ts +11 -0
- package/src/transform.ts +10 -0
- package/src/unique.ts +10 -0
- package/src/url/index.ts +10 -0
- package/src/url/url.spec.ts +47 -0
- package/src/url/url.ts +113 -0
- package/src/worker/worker.spec.ts +41 -0
- package/src/worker/worker.ts +86 -0
- package/tsconfig.json +7 -0
- package/tsconfig.vite.json +4 -0
- package/vite.config.ts +23 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Copyright 2023 Synnax Labs, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Use of this software is governed by the Business Source License included in the file
|
|
4
|
+
// licenses/BSL.txt.
|
|
5
|
+
//
|
|
6
|
+
// As of the Change Date specified in that file, in accordance with the Business Source
|
|
7
|
+
// License, use of this software will be governed by the Apache License, Version 2.0,
|
|
8
|
+
// included in the file licenses/APL.txt.
|
|
9
|
+
|
|
10
|
+
import { registerCustomTypeEncoder } from "@/binary";
|
|
11
|
+
import { DataType, Density, Rate, TimeSpan, TimeStamp } from "@/telem/telem";
|
|
12
|
+
|
|
13
|
+
const valueOfEncoder = (value: unknown): unknown => value?.valueOf();
|
|
14
|
+
|
|
15
|
+
registerCustomTypeEncoder({ Class: TimeStamp, write: valueOfEncoder });
|
|
16
|
+
registerCustomTypeEncoder({ Class: TimeSpan, write: valueOfEncoder });
|
|
17
|
+
registerCustomTypeEncoder({
|
|
18
|
+
Class: DataType,
|
|
19
|
+
write: (v: unknown) => (v as DataType).toString,
|
|
20
|
+
});
|
|
21
|
+
registerCustomTypeEncoder({ Class: Rate, write: valueOfEncoder });
|
|
22
|
+
registerCustomTypeEncoder({ Class: Density, write: valueOfEncoder });
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// Copyright 2023 Synnax Labs, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Use of this software is governed by the Business Source License included in the file
|
|
4
|
+
// licenses/BSL.txt.
|
|
5
|
+
//
|
|
6
|
+
// As of the Change Date specified in that file, in accordance with the Business Source
|
|
7
|
+
// License, use of this software will be governed by the Apache License, Version 2.0,
|
|
8
|
+
// included in the file licenses/APL.txt.
|
|
9
|
+
|
|
10
|
+
import { DataTypeT, NativeTypedArray } from "@/telem/telem";
|
|
11
|
+
|
|
12
|
+
export const randomSeries = (length: number, dataType: DataTypeT): NativeTypedArray => {
|
|
13
|
+
// generate random bytes of the correct length
|
|
14
|
+
const bytes = new Uint8Array(length * dataType.density.valueOf());
|
|
15
|
+
for (let i = 0; i < bytes.byteLength; i++) {
|
|
16
|
+
bytes[i] = Math.floor(Math.random() * 256);
|
|
17
|
+
}
|
|
18
|
+
return new dataType.Array(bytes.buffer);
|
|
19
|
+
};
|
package/src/telem/gl.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// Copyright 2023 Synnax Labs, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Use of this software is governed by the Business Source License included in the file
|
|
4
|
+
// licenses/BSL.txt.
|
|
5
|
+
//
|
|
6
|
+
// As of the Change Date specified in that file, in accordance with the Business Source
|
|
7
|
+
// License, use of this software will be governed by the Apache License, Version 2.0,
|
|
8
|
+
// included in the file licenses/APL.txt.
|
|
9
|
+
|
|
10
|
+
export interface GLBufferController {
|
|
11
|
+
createBuffer: () => WebGLBuffer | null;
|
|
12
|
+
bufferData: ((target: number, data: ArrayBufferLike, usage: number) => void) &
|
|
13
|
+
((target: number, size: number, usage: number) => void);
|
|
14
|
+
bufferSubData: (target: number, offset: number, data: ArrayBufferLike) => void;
|
|
15
|
+
bindBuffer: (target: number, buffer: WebGLBuffer | null) => void;
|
|
16
|
+
deleteBuffer: (buffer: WebGLBuffer | null) => void;
|
|
17
|
+
ARRAY_BUFFER: number;
|
|
18
|
+
STATIC_DRAW: number;
|
|
19
|
+
DYNAMIC_DRAW: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type GLBufferUsage = "static" | "dynamic";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Copyright 2023 Synnax Labs, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Use of this software is governed by the Business Source License included in the file
|
|
4
|
+
// licenses/BSL.txt.
|
|
5
|
+
//
|
|
6
|
+
// As of the Change Date specified in that file, in accordance with the Business Source
|
|
7
|
+
// License, use of this software will be governed by the Apache License, Version 2.0,
|
|
8
|
+
// included in the file licenses/APL.txt.
|
|
9
|
+
|
|
10
|
+
export * from "@/telem/series";
|
|
11
|
+
export * from "@/telem/telem";
|
|
12
|
+
export type { GLBufferController } from "@/telem/gl";
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
// Copyright 2023 Synnax Labs, Inc.
|
|
2
|
+
//
|
|
3
|
+
// Use of this software is governed by the Business Source License included in the file
|
|
4
|
+
// licenses/BSL.txt.
|
|
5
|
+
//
|
|
6
|
+
// As of the Change Date specified in that file, in accordance with the Business Source
|
|
7
|
+
// License, use of this software will be governed by the Apache License, Version 2.0,
|
|
8
|
+
// included in the file licenses/APL.txt.
|
|
9
|
+
|
|
10
|
+
import { describe, expect, test, it } from "vitest";
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
|
|
13
|
+
import { MockGLBufferController } from "@/mock/MockGLBufferController";
|
|
14
|
+
import { Series } from "@/telem/series";
|
|
15
|
+
import { DataType, Rate, Size, TimeRange, TimeStamp } from "@/telem/telem";
|
|
16
|
+
|
|
17
|
+
describe("Series", () => {
|
|
18
|
+
describe("construction", () => {
|
|
19
|
+
test("valid from native", () => {
|
|
20
|
+
const a = new Series(new Float32Array([1, 2, 3]));
|
|
21
|
+
expect(a.dataType.toString()).toBe(DataType.FLOAT32.toString());
|
|
22
|
+
expect(a.length).toEqual(3);
|
|
23
|
+
expect(a.byteLength).toEqual(Size.bytes(12));
|
|
24
|
+
expect(a.byteCap).toEqual(Size.bytes(12));
|
|
25
|
+
expect(a.cap).toEqual(3);
|
|
26
|
+
const b = new Series(new BigInt64Array([BigInt(1)]));
|
|
27
|
+
expect(b.dataType.toString()).toBe(DataType.INT64.toString());
|
|
28
|
+
const c = new Series(new BigInt64Array([BigInt(1)]), DataType.TIMESTAMP);
|
|
29
|
+
expect(c.dataType.toString()).toBe(DataType.TIMESTAMP.toString());
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test("from buffer without data type provided", () => {
|
|
33
|
+
expect(() => {
|
|
34
|
+
// eslint-disable-next-line no-new
|
|
35
|
+
new Series(new ArrayBuffer(4));
|
|
36
|
+
}).toThrow();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
test("from buffer with data type provided", () => {
|
|
40
|
+
const a = new Series(new ArrayBuffer(4), DataType.FLOAT32);
|
|
41
|
+
expect(a.dataType.toString()).toBe(DataType.FLOAT32.toString());
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test("with time range", () => {
|
|
45
|
+
const a = new Series(
|
|
46
|
+
new Float32Array([1, 2, 3]),
|
|
47
|
+
DataType.FLOAT32,
|
|
48
|
+
new TimeRange(1, 2),
|
|
49
|
+
);
|
|
50
|
+
expect(a.timeRange.span.valueOf()).toBe(1);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe("allocation", () => {
|
|
54
|
+
it("should allocate a lazy array", () => {
|
|
55
|
+
const arr = Series.alloc(10, DataType.FLOAT32);
|
|
56
|
+
expect(arr.byteCap).toEqual(Size.bytes(40));
|
|
57
|
+
expect(arr.cap).toEqual(10);
|
|
58
|
+
expect(arr.length).toEqual(0);
|
|
59
|
+
expect(arr.byteLength).toEqual(Size.bytes(0));
|
|
60
|
+
});
|
|
61
|
+
it("should throw an error when attempting to allocate an array of lenght 0", () => {
|
|
62
|
+
expect(() => {
|
|
63
|
+
Series.alloc(0, DataType.FLOAT32);
|
|
64
|
+
}).toThrow();
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
test("at", () => {
|
|
70
|
+
it("should return the value at the given index and add the sample offset", () => {
|
|
71
|
+
const arr = new Series(
|
|
72
|
+
new Float32Array([1, 2, 3]),
|
|
73
|
+
DataType.FLOAT32,
|
|
74
|
+
undefined,
|
|
75
|
+
2,
|
|
76
|
+
);
|
|
77
|
+
expect(arr.at(0)).toEqual(3);
|
|
78
|
+
expect(arr.at(1)).toEqual(4);
|
|
79
|
+
expect(arr.at(2)).toEqual(5);
|
|
80
|
+
});
|
|
81
|
+
it("should return undefined when the index is out of bounds", () => {
|
|
82
|
+
const arr = new Series(new Float32Array([1, 2, 3]), DataType.FLOAT32);
|
|
83
|
+
expect(arr.at(3)).toBeUndefined();
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
describe("slice", () => {
|
|
88
|
+
it("should slice a lazy array", () => {
|
|
89
|
+
const a = new Series(new Float32Array([1, 2, 3]), DataType.FLOAT32);
|
|
90
|
+
const b = a.slice(1, 2);
|
|
91
|
+
expect(b.dataType.toString()).toBe(DataType.FLOAT32.toString());
|
|
92
|
+
expect(b.data).toEqual(new Float32Array([2]));
|
|
93
|
+
expect(b.length).toEqual(1);
|
|
94
|
+
expect(b.byteLength).toEqual(Size.bytes(4));
|
|
95
|
+
expect(b.byteCap).toEqual(Size.bytes(4));
|
|
96
|
+
expect(b.cap).toEqual(1);
|
|
97
|
+
});
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
describe("min and max", () => {
|
|
101
|
+
it("should return a min and max of zero on an allocated array", () => {
|
|
102
|
+
const arr = Series.alloc(10, DataType.FLOAT32);
|
|
103
|
+
expect(arr.max).toEqual(-Infinity);
|
|
104
|
+
expect(arr.min).toEqual(Infinity);
|
|
105
|
+
});
|
|
106
|
+
it("should correctly calculate the min and max of a lazy array", () => {
|
|
107
|
+
const arr = new Series(new Float32Array([1, 2, 3]), DataType.FLOAT32);
|
|
108
|
+
expect(arr.max).toEqual(3);
|
|
109
|
+
expect(arr.min).toEqual(1);
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
describe("conversion", () => {
|
|
114
|
+
test("from float64 to float32", () => {
|
|
115
|
+
const a = new Series(new Float64Array([1, 2, 3]), DataType.FLOAT64);
|
|
116
|
+
const b = a.convert(DataType.FLOAT32);
|
|
117
|
+
expect(b.dataType.toString()).toBe(DataType.FLOAT32.toString());
|
|
118
|
+
expect(b.data).toEqual(new Float32Array([1, 2, 3]));
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
test("from int64 to int32", () => {
|
|
122
|
+
const a = new Series(new BigInt64Array([BigInt(1), BigInt(2), BigInt(3)]));
|
|
123
|
+
const b = a.convert(DataType.INT32);
|
|
124
|
+
expect(b.dataType.toString()).toBe(DataType.INT32.toString());
|
|
125
|
+
expect(b.data).toEqual(new Int32Array([1, 2, 3]));
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test("from float32 to int64", () => {
|
|
129
|
+
const a = new Series(new Float32Array([1, 2, 3]), DataType.FLOAT32);
|
|
130
|
+
const b = a.convert(DataType.INT64);
|
|
131
|
+
expect(b.dataType.toString()).toBe(DataType.INT64.toString());
|
|
132
|
+
expect(b.data).toEqual(new BigInt64Array([BigInt(1), BigInt(2), BigInt(3)]));
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
describe("writing", () => {
|
|
137
|
+
it("should correctly write to an allocated lazy array", () => {
|
|
138
|
+
const arr = Series.alloc(10, DataType.FLOAT32);
|
|
139
|
+
expect(arr.byteCap).toEqual(Size.bytes(40));
|
|
140
|
+
expect(arr.length).toEqual(0);
|
|
141
|
+
const writeOne = new Series(new Float32Array([1]));
|
|
142
|
+
expect(arr.write(writeOne)).toEqual(1);
|
|
143
|
+
expect(arr.length).toEqual(1);
|
|
144
|
+
const writeTwo = new Series(new Float32Array([2, 3]));
|
|
145
|
+
expect(arr.write(writeTwo)).toEqual(2);
|
|
146
|
+
expect(arr.length).toEqual(3);
|
|
147
|
+
});
|
|
148
|
+
it("should recompute cached max and min correctly", () => {
|
|
149
|
+
const arr = Series.alloc(10, DataType.FLOAT32);
|
|
150
|
+
arr.enrich();
|
|
151
|
+
const writeTwo = new Series(new Float32Array([2, 3]));
|
|
152
|
+
arr.write(writeTwo);
|
|
153
|
+
expect(arr.max).toEqual(3);
|
|
154
|
+
expect(arr.min).toEqual(2);
|
|
155
|
+
});
|
|
156
|
+
it("should correctly adjust the sample offset of a written array", () => {
|
|
157
|
+
const arr = Series.alloc(2, DataType.FLOAT32, TimeRange.ZERO, -3);
|
|
158
|
+
const writeOne = new Series(new Float32Array([-2]));
|
|
159
|
+
expect(arr.write(writeOne)).toEqual(1);
|
|
160
|
+
expect(arr.min).toEqual(-5);
|
|
161
|
+
const writeTwo = new Series(
|
|
162
|
+
new Float32Array([1]),
|
|
163
|
+
DataType.FLOAT32,
|
|
164
|
+
TimeRange.ZERO,
|
|
165
|
+
-1,
|
|
166
|
+
);
|
|
167
|
+
expect(arr.write(writeTwo)).toEqual(1);
|
|
168
|
+
expect(arr.min).toEqual(-5);
|
|
169
|
+
expect(arr.max).toEqual(-2);
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
describe("generateTimeStamps", () => {
|
|
174
|
+
it("should correctly generate timestamps", () => {
|
|
175
|
+
const ts = Series.generateTimestamps(5, Rate.hz(1), TimeStamp.seconds(1));
|
|
176
|
+
expect(ts.timeRange).toEqual(
|
|
177
|
+
new TimeRange(TimeStamp.seconds(1), TimeStamp.seconds(6)),
|
|
178
|
+
);
|
|
179
|
+
expect(ts.cap).toEqual(5);
|
|
180
|
+
expect(ts.length).toEqual(5);
|
|
181
|
+
expect(ts.dataType.toString()).toEqual(DataType.TIMESTAMP.toString());
|
|
182
|
+
expect(ts.data).toEqual(
|
|
183
|
+
new BigInt64Array([
|
|
184
|
+
BigInt(TimeStamp.seconds(1).valueOf()),
|
|
185
|
+
BigInt(TimeStamp.seconds(2).valueOf()),
|
|
186
|
+
BigInt(TimeStamp.seconds(3).valueOf()),
|
|
187
|
+
BigInt(TimeStamp.seconds(4).valueOf()),
|
|
188
|
+
BigInt(TimeStamp.seconds(5).valueOf()),
|
|
189
|
+
]),
|
|
190
|
+
);
|
|
191
|
+
});
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
describe("webgl buffering", () => {
|
|
195
|
+
it("should correctly buffer a new lazy array", () => {
|
|
196
|
+
const arr = new Series(new Float32Array([1, 2, 3]), DataType.FLOAT32);
|
|
197
|
+
const controller = new MockGLBufferController();
|
|
198
|
+
arr.updateGLBuffer(controller);
|
|
199
|
+
expect(controller.createBufferMock).toHaveBeenCalledTimes(1);
|
|
200
|
+
expect(controller.bindBufferMock).toHaveBeenCalledTimes(1);
|
|
201
|
+
expect(controller.bufferDataMock).toHaveBeenCalledTimes(1);
|
|
202
|
+
expect(controller.bufferSubDataMock).not.toHaveBeenCalled();
|
|
203
|
+
const buf = controller.buffers[arr.glBuffer as number];
|
|
204
|
+
expect(buf).toBeDefined();
|
|
205
|
+
expect(buf.byteLength).toEqual(12);
|
|
206
|
+
expect(buf).toEqual(new Float32Array([1, 2, 3]));
|
|
207
|
+
});
|
|
208
|
+
it("should correctly update a buffer when writing to an allocated array", () => {
|
|
209
|
+
const arr = Series.alloc(10, DataType.FLOAT32);
|
|
210
|
+
const controller = new MockGLBufferController();
|
|
211
|
+
arr.updateGLBuffer(controller);
|
|
212
|
+
expect(controller.createBufferMock).toHaveBeenCalledTimes(1);
|
|
213
|
+
expect(controller.bindBufferMock).not.toHaveBeenCalled();
|
|
214
|
+
expect(controller.bufferDataMock).not.toHaveBeenCalled();
|
|
215
|
+
expect(controller.bufferSubDataMock).not.toHaveBeenCalled();
|
|
216
|
+
let buf = controller.buffers[arr.glBuffer as number];
|
|
217
|
+
expect(buf).toBeDefined();
|
|
218
|
+
expect(buf.byteLength).toEqual(0);
|
|
219
|
+
const writeOne = new Series(new Float32Array([1]));
|
|
220
|
+
arr.write(writeOne);
|
|
221
|
+
arr.updateGLBuffer(controller);
|
|
222
|
+
expect(controller.bufferDataMock).toHaveBeenCalledTimes(1);
|
|
223
|
+
expect(controller.bufferSubDataMock).toHaveBeenCalledTimes(1);
|
|
224
|
+
buf = controller.buffers[arr.glBuffer as number];
|
|
225
|
+
expect(buf.byteLength).toEqual(arr.byteCap.valueOf());
|
|
226
|
+
expect(new Float32Array(buf)[0]).toEqual(1);
|
|
227
|
+
const writeTwo = new Series(new Float32Array([2, 3]));
|
|
228
|
+
arr.write(writeTwo);
|
|
229
|
+
arr.updateGLBuffer(controller);
|
|
230
|
+
expect(controller.bufferDataMock).not.toHaveBeenCalledTimes(2);
|
|
231
|
+
expect(controller.bufferSubDataMock).toHaveBeenCalledTimes(2);
|
|
232
|
+
buf = controller.buffers[arr.glBuffer as number];
|
|
233
|
+
expect(buf.byteLength).toEqual(arr.byteCap.valueOf());
|
|
234
|
+
expect(new Float32Array(buf)[0]).toEqual(1);
|
|
235
|
+
expect(new Float32Array(buf)[1]).toEqual(2);
|
|
236
|
+
expect(new Float32Array(buf)[2]).toEqual(3);
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
describe("acquire", () => {
|
|
241
|
+
it("should increase the reference count and buffer gl data", () => {
|
|
242
|
+
const s = new Series(new Float32Array([1, 2, 3]));
|
|
243
|
+
expect(s.refCount).toEqual(0);
|
|
244
|
+
const control = new MockGLBufferController();
|
|
245
|
+
s.acquire(control);
|
|
246
|
+
expect(s.refCount).toEqual(1);
|
|
247
|
+
expect(control.createBufferMock).toHaveBeenCalled();
|
|
248
|
+
s.release();
|
|
249
|
+
expect(s.refCount).toEqual(0);
|
|
250
|
+
expect(control.deleteBufferMock).toHaveBeenCalled();
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
describe("string series", () => {
|
|
255
|
+
it("should correctly encode and decode a string series", () => {
|
|
256
|
+
const s = Series.fromStrings(["apple", "banana", "carrot"]);
|
|
257
|
+
expect(s.dataType.toString()).toEqual(DataType.STRING.toString());
|
|
258
|
+
const outStrings = s.toStrings();
|
|
259
|
+
expect(outStrings).toEqual(["apple", "banana", "carrot"]);
|
|
260
|
+
});
|
|
261
|
+
it("should throw an error if the series is not of type string", () => {
|
|
262
|
+
const s = new Series(new Float32Array([1, 2, 3]));
|
|
263
|
+
expect(() => {
|
|
264
|
+
s.toStrings();
|
|
265
|
+
}).toThrow();
|
|
266
|
+
});
|
|
267
|
+
});
|
|
268
|
+
|
|
269
|
+
describe("JSON series", () => {
|
|
270
|
+
it("should correctly encode and decode a JSON series", () => {
|
|
271
|
+
const schema = z.object({
|
|
272
|
+
a: z.number(),
|
|
273
|
+
b: z.string(),
|
|
274
|
+
});
|
|
275
|
+
const s = Series.fromJSON<z.output<typeof schema>>([
|
|
276
|
+
{ a: 1, b: "apple" },
|
|
277
|
+
{ a: 2, b: "banana" },
|
|
278
|
+
{ a: 3, b: "carrot" },
|
|
279
|
+
]);
|
|
280
|
+
const outJSON = s.parseJSON(schema);
|
|
281
|
+
print(outJSON);
|
|
282
|
+
expect(outJSON).toEqual([
|
|
283
|
+
{ a: 1, b: "apple" },
|
|
284
|
+
{ a: 2, b: "banana" },
|
|
285
|
+
{ a: 3, b: "carrot" },
|
|
286
|
+
]);
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
});
|