@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,65 @@
|
|
|
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 { type UnknownRecord } from "@/record";
|
|
11
|
+
import { Primitive } from "@/primitive";
|
|
12
|
+
|
|
13
|
+
type DeepEqualBaseRecord = UnknownRecord | {
|
|
14
|
+
equals?: (other: any) => boolean;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const equal = <T extends DeepEqualBaseRecord | DeepEqualBaseRecord[] | Primitive[]>(a: T, b: T): boolean => {
|
|
18
|
+
const aIsArray = Array.isArray(a);
|
|
19
|
+
const bIsArray = Array.isArray(b);
|
|
20
|
+
if (aIsArray !== bIsArray) return false;
|
|
21
|
+
if (aIsArray && bIsArray) {
|
|
22
|
+
const aArr = a as DeepEqualBaseRecord[];
|
|
23
|
+
const bArr = b as DeepEqualBaseRecord[];
|
|
24
|
+
if (aArr.length !== bArr.length) return false;
|
|
25
|
+
for (let i = 0; i < aArr.length; i++) {
|
|
26
|
+
if (!equal(aArr[i], bArr[i])) return false;
|
|
27
|
+
}
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
if (typeof a !== "object" || typeof b !== "object") return a === b;
|
|
31
|
+
if ("equals" in a)
|
|
32
|
+
return (a.equals as (other: any) => boolean)(b);
|
|
33
|
+
const aKeys = Object.keys(a);
|
|
34
|
+
const bKeys = Object.keys(b);
|
|
35
|
+
if (aKeys.length !== bKeys.length) return false;
|
|
36
|
+
for (const key of aKeys) {
|
|
37
|
+
// @ts-expect-error
|
|
38
|
+
const aVal = a[key];
|
|
39
|
+
// @ts-expect-error
|
|
40
|
+
const bVal = b[key];
|
|
41
|
+
if (typeof aVal === "object" && typeof bVal === "object") {
|
|
42
|
+
if (!equal(aVal, bVal)) return false;
|
|
43
|
+
} else if (aVal !== bVal) return false;
|
|
44
|
+
}
|
|
45
|
+
return true;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const partialEqual = <T extends UnknownRecord<T>>(
|
|
49
|
+
base: T,
|
|
50
|
+
partial: Partial<T>,
|
|
51
|
+
): boolean => {
|
|
52
|
+
const baseKeys = Object.keys(base);
|
|
53
|
+
const partialKeys = Object.keys(partial);
|
|
54
|
+
if (partialKeys.length > baseKeys.length) return false;
|
|
55
|
+
for (const key of partialKeys) {
|
|
56
|
+
// @ts-expect-error
|
|
57
|
+
const baseVal = base[key];
|
|
58
|
+
// @ts-expect-error
|
|
59
|
+
const partialVal = partial[key];
|
|
60
|
+
if (typeof baseVal === "object" && typeof partialVal === "object") {
|
|
61
|
+
if (!partialEqual(baseVal, partialVal)) return false;
|
|
62
|
+
} else if (baseVal !== partialVal) return false;
|
|
63
|
+
}
|
|
64
|
+
return true;
|
|
65
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
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 "@/deep/copy";
|
|
11
|
+
export * from "@/deep/delete";
|
|
12
|
+
export * from "@/deep/key";
|
|
13
|
+
export * from "@/deep/merge";
|
|
14
|
+
export * from "@/deep/partial";
|
|
15
|
+
export * from "@/deep/equal";
|
|
@@ -0,0 +1,10 @@
|
|
|
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 * as deep from "@/deep/external";
|
package/src/deep/key.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
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 { type Join } from "@/join";
|
|
11
|
+
|
|
12
|
+
type Prev = [
|
|
13
|
+
never,
|
|
14
|
+
0,
|
|
15
|
+
1,
|
|
16
|
+
2,
|
|
17
|
+
3,
|
|
18
|
+
4,
|
|
19
|
+
5,
|
|
20
|
+
6,
|
|
21
|
+
7,
|
|
22
|
+
8,
|
|
23
|
+
9,
|
|
24
|
+
10,
|
|
25
|
+
11,
|
|
26
|
+
12,
|
|
27
|
+
13,
|
|
28
|
+
14,
|
|
29
|
+
15,
|
|
30
|
+
16,
|
|
31
|
+
17,
|
|
32
|
+
18,
|
|
33
|
+
19,
|
|
34
|
+
20,
|
|
35
|
+
...Array<0>,
|
|
36
|
+
];
|
|
37
|
+
|
|
38
|
+
export type Key<T, D extends number = 5> = [D] extends [never]
|
|
39
|
+
? never
|
|
40
|
+
: T extends object
|
|
41
|
+
? {
|
|
42
|
+
[K in keyof T]-?: K extends string | number
|
|
43
|
+
? `${K}` | Join<K, Key<T[K], Prev[D]>>
|
|
44
|
+
: never;
|
|
45
|
+
}[keyof T]
|
|
46
|
+
: "";
|
|
@@ -0,0 +1,63 @@
|
|
|
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, it, expect } from "vitest";
|
|
11
|
+
|
|
12
|
+
import { deep } from "@/deep";
|
|
13
|
+
|
|
14
|
+
interface TestRecord {
|
|
15
|
+
a: number;
|
|
16
|
+
b?: {
|
|
17
|
+
c?: number;
|
|
18
|
+
d?: number;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
describe("deepMerge", () => {
|
|
23
|
+
it("should deep two objects", () => {
|
|
24
|
+
const a: TestRecord = {
|
|
25
|
+
a: 1,
|
|
26
|
+
b: {
|
|
27
|
+
c: 2,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
const b: TestRecord = {
|
|
31
|
+
a: 3,
|
|
32
|
+
b: {
|
|
33
|
+
d: 4,
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
const c: TestRecord = {
|
|
37
|
+
a: 3,
|
|
38
|
+
b: {
|
|
39
|
+
c: 2,
|
|
40
|
+
d: 4,
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
expect(deep.merge(a, b)).toEqual(c);
|
|
44
|
+
});
|
|
45
|
+
it("Should set a value even when its parent is undefined", () => {
|
|
46
|
+
const a: TestRecord = {
|
|
47
|
+
a: 1,
|
|
48
|
+
};
|
|
49
|
+
const b: TestRecord = {
|
|
50
|
+
a: 3,
|
|
51
|
+
b: {
|
|
52
|
+
d: 4,
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
const c: TestRecord = {
|
|
56
|
+
a: 3,
|
|
57
|
+
b: {
|
|
58
|
+
d: 4,
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
expect(deep.merge(a, b)).toEqual(c);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
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 { type Partial } from "@/deep/partial";
|
|
11
|
+
import { isObject } from "@/identity";
|
|
12
|
+
import { type UnknownRecord } from "@/record";
|
|
13
|
+
|
|
14
|
+
export const merge = <T extends UnknownRecord<T>>(
|
|
15
|
+
base: T,
|
|
16
|
+
...objects: Array<Partial<T>>
|
|
17
|
+
): T => {
|
|
18
|
+
if (objects.length === 0) return base;
|
|
19
|
+
const source = objects.shift();
|
|
20
|
+
|
|
21
|
+
if (isObject(base) && isObject(source)) {
|
|
22
|
+
for (const key in source) {
|
|
23
|
+
try {
|
|
24
|
+
if (isObject(source[key])) {
|
|
25
|
+
if (!(key in base)) Object.assign(base, { [key]: {} });
|
|
26
|
+
// @ts-expect-error
|
|
27
|
+
merge(base[key], source[key]);
|
|
28
|
+
} else {
|
|
29
|
+
Object.assign(base, { [key]: source[key] });
|
|
30
|
+
}
|
|
31
|
+
} catch (e) {
|
|
32
|
+
if (e instanceof TypeError) {
|
|
33
|
+
throw new TypeError(`.${key}: ${e.message}`);
|
|
34
|
+
}
|
|
35
|
+
throw e;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return merge(base, ...objects);
|
|
41
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
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 type Partial<T> = T extends object
|
|
11
|
+
? {
|
|
12
|
+
[P in keyof T]?: Partial<T[P]>;
|
|
13
|
+
}
|
|
14
|
+
: T;
|
|
@@ -0,0 +1,10 @@
|
|
|
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 type Destructor = () => void;
|
package/src/identity.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
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 { type UnknownRecord } from "@/record";
|
|
11
|
+
|
|
12
|
+
export const isObject = <T extends UnknownRecord = UnknownRecord>(
|
|
13
|
+
item?: unknown,
|
|
14
|
+
): item is T => item != null && typeof item === "object" && !Array.isArray(item);
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
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";
|
|
11
|
+
export * from "@/primitive";
|
|
12
|
+
export * from "@/record";
|
|
13
|
+
export * from "@/renderable";
|
|
14
|
+
export * from "@/optional";
|
|
15
|
+
export * from "@/identity";
|
|
16
|
+
export * from "@/runtime";
|
|
17
|
+
export * from "@/deep";
|
|
18
|
+
export * from "@/debounce";
|
|
19
|
+
export * from "@/clamp";
|
|
20
|
+
export * from "@/compare";
|
|
21
|
+
export * from "@/runtime";
|
|
22
|
+
export * from "@/unique";
|
|
23
|
+
export * from "@/kv";
|
|
24
|
+
export * from "@/spatial";
|
|
25
|
+
export * from "@/url";
|
|
26
|
+
export * from "@/toArray";
|
|
27
|
+
export * from "@/case";
|
|
28
|
+
export * from "@/search";
|
|
29
|
+
export * from "@/destructor";
|
|
30
|
+
export * from "@/worker/worker";
|
|
31
|
+
export * from "@/transform";
|
|
32
|
+
export * from "@/binary";
|
|
33
|
+
export * from "@/observe";
|
|
34
|
+
export * from "@/change";
|
package/src/join.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
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 type Join<K, P> = K extends string | number
|
|
11
|
+
? P extends string | number
|
|
12
|
+
? `${K}${"" extends P ? "" : "."}${P}`
|
|
13
|
+
: never
|
|
14
|
+
: never;
|
package/src/kv/index.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
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 * as kv from "@/kv/types";
|
package/src/kv/types.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
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 KV<K = string, V = string, WK = K, WV = V, D = K>
|
|
11
|
+
extends Reader<K, V>,
|
|
12
|
+
Writer<WK, WV>,
|
|
13
|
+
Deleter<D> {}
|
|
14
|
+
|
|
15
|
+
export interface Reader<K = string, V = string> {
|
|
16
|
+
/** @returns the value for a given key, or null if the key is not present. */
|
|
17
|
+
get: (key: K) => V | null;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface Writer<K = string, V = string> {
|
|
21
|
+
/** Sets a key-value pair in the store. */
|
|
22
|
+
set: (key: K, value: V) => void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface Deleter<K = string> {
|
|
26
|
+
/** Deletes a key-value pair from the store. */
|
|
27
|
+
delete: (key: K) => void;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** A read-writable key-value store. */
|
|
31
|
+
export interface Async<K = string, V = string, WK = K, WV = V, D = K>
|
|
32
|
+
extends AsyncReader<K, V>,
|
|
33
|
+
AsyncWriter<WK, WV>,
|
|
34
|
+
AsyncDeleter<D> {}
|
|
35
|
+
|
|
36
|
+
/** A readable key-value store. */
|
|
37
|
+
export interface AsyncReader<K = string, V = string> {
|
|
38
|
+
/** Get the value for a given key. */
|
|
39
|
+
get: (key: K) => Promise<V | null>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** A writable key-value store. */
|
|
43
|
+
export interface AsyncWriter<K = string, V = string> {
|
|
44
|
+
/** Sets a key-value pair in the store. The value must be serializable. */
|
|
45
|
+
set: (key: K, value: V) => Promise<void>;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** A key-value store that can delete key-value pairs. */
|
|
49
|
+
export interface AsyncDeleter<K = string> {
|
|
50
|
+
/** Deletes a key-value pair from the store. */
|
|
51
|
+
delete: (key: K) => Promise<void>;
|
|
52
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
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 { vi, Mock } from "vitest";
|
|
11
|
+
|
|
12
|
+
import { GLBufferController } from "@/telem/gl";
|
|
13
|
+
|
|
14
|
+
export class MockGLBufferController implements GLBufferController {
|
|
15
|
+
ARRAY_BUFFER: number = 1;
|
|
16
|
+
STATIC_DRAW: number = 2;
|
|
17
|
+
DYNAMIC_DRAW: number = 3;
|
|
18
|
+
|
|
19
|
+
targets: Record<number, number> = {};
|
|
20
|
+
counter: number = 0;
|
|
21
|
+
buffers: Record<number, ArrayBuffer> = {};
|
|
22
|
+
|
|
23
|
+
createBufferMock: Mock<[], WebGLBuffer | null> = vi.fn();
|
|
24
|
+
bufferDataMock: Mock<[number, ArrayBufferLike | number, number]> = vi.fn();
|
|
25
|
+
bufferSubDataMock: Mock<[number, number, ArrayBufferLike]> = vi.fn();
|
|
26
|
+
bindBufferMock: Mock<[number, WebGLBuffer | null]> = vi.fn();
|
|
27
|
+
deleteBufferMock: Mock<[WebGLBuffer | null]> = vi.fn();
|
|
28
|
+
|
|
29
|
+
deleteBuffer(buffer: WebGLBuffer | null): void {
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
|
|
31
|
+
if (buffer != null) delete this.buffers[buffer as number];
|
|
32
|
+
this.deleteBufferMock(buffer);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
createBuffer(): WebGLBuffer | null {
|
|
36
|
+
this.createBufferMock();
|
|
37
|
+
const v = ++this.counter;
|
|
38
|
+
this.buffers[v] = new ArrayBuffer(0);
|
|
39
|
+
return v;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
bufferData(
|
|
43
|
+
target: number,
|
|
44
|
+
dataOrSize: ArrayBufferLike | number,
|
|
45
|
+
usage: number
|
|
46
|
+
): void {
|
|
47
|
+
if (typeof dataOrSize === "number")
|
|
48
|
+
this.buffers[this.targets[target]] = new ArrayBuffer(dataOrSize);
|
|
49
|
+
else this.buffers[this.targets[target]] = dataOrSize;
|
|
50
|
+
|
|
51
|
+
this.bufferDataMock(target, dataOrSize as any, usage);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
bindBuffer(target: number, buffer: WebGLBuffer | null): void {
|
|
55
|
+
if (buffer === 0) throw new Error("Cannot bind to 0");
|
|
56
|
+
this.targets[target] = buffer as number;
|
|
57
|
+
this.bindBufferMock(target, buffer);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
bufferSubData(target: number, offset: number, data: ArrayBufferLike): void {
|
|
61
|
+
let buffer = this.buffers[this.targets[target]];
|
|
62
|
+
if (buffer == null) {
|
|
63
|
+
buffer = new ArrayBuffer(offset + data.byteLength);
|
|
64
|
+
this.buffers[target] = buffer;
|
|
65
|
+
}
|
|
66
|
+
const view = new Uint8Array(buffer);
|
|
67
|
+
view.set(new Uint8Array(data), offset);
|
|
68
|
+
this.bufferSubDataMock(target, offset, data);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
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 "@/mock/MockGLBufferController";
|
|
@@ -0,0 +1,10 @@
|
|
|
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 * as observe from "@/observe/observe";
|
|
@@ -0,0 +1,33 @@
|
|
|
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 { type Destructor } from "@/destructor";
|
|
11
|
+
|
|
12
|
+
export type Handler<T> = (value: T) => void;
|
|
13
|
+
|
|
14
|
+
export interface Observable<T> {
|
|
15
|
+
onChange: (handler: Handler<T>) => Destructor;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export class Observer<T> implements Observable<T> {
|
|
19
|
+
private readonly handlers: Map<Handler<T>, null>;
|
|
20
|
+
|
|
21
|
+
constructor() {
|
|
22
|
+
this.handlers = new Map();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
onChange(handler: Handler<T>): Destructor {
|
|
26
|
+
this.handlers.set(handler, null);
|
|
27
|
+
return () => this.handlers.delete(handler);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
notify(value: T): void {
|
|
31
|
+
this.handlers.forEach((_, handler) => handler(value));
|
|
32
|
+
}
|
|
33
|
+
}
|
package/src/optional.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
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 type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
|
package/src/primitive.ts
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
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 { type Key } from "@/record";
|
|
11
|
+
|
|
12
|
+
export type Primitive =
|
|
13
|
+
| string
|
|
14
|
+
| number
|
|
15
|
+
| bigint
|
|
16
|
+
| boolean
|
|
17
|
+
| Stringer
|
|
18
|
+
| null
|
|
19
|
+
| undefined;
|
|
20
|
+
|
|
21
|
+
export interface Stringer {
|
|
22
|
+
toString: () => string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const isStringer = (value: unknown): boolean =>
|
|
26
|
+
value != null && typeof value === "object" && "toString" in value;
|
|
27
|
+
|
|
28
|
+
export type PrimitiveRecord = Record<Key, Primitive>;
|
|
29
|
+
|
|
30
|
+
export const primitiveIsZero = (value: Primitive): boolean => {
|
|
31
|
+
if (isStringer(value)) return value?.toString().length === 0;
|
|
32
|
+
switch (typeof value) {
|
|
33
|
+
case "string":
|
|
34
|
+
return value.length === 0;
|
|
35
|
+
case "number":
|
|
36
|
+
return value === 0;
|
|
37
|
+
case "bigint":
|
|
38
|
+
return value === BigInt(0);
|
|
39
|
+
case "boolean":
|
|
40
|
+
return !value;
|
|
41
|
+
case "undefined":
|
|
42
|
+
return true;
|
|
43
|
+
case "object":
|
|
44
|
+
return value === null;
|
|
45
|
+
}
|
|
46
|
+
};
|
package/src/record.ts
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
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 { z } from "zod";
|
|
11
|
+
|
|
12
|
+
import { type RenderableValue } from "@/renderable";
|
|
13
|
+
|
|
14
|
+
export type Key = string | number | symbol;
|
|
15
|
+
|
|
16
|
+
export type KeyedRecord<
|
|
17
|
+
K extends Key = Key,
|
|
18
|
+
E extends Record<string, unknown> = Record<string, unknown>,
|
|
19
|
+
> = {
|
|
20
|
+
key: K;
|
|
21
|
+
} & Partial<Record<keyof E, unknown>>;
|
|
22
|
+
|
|
23
|
+
export type UnknownRecord<E extends Record<Key, unknown> = Record<Key, unknown>> =
|
|
24
|
+
Partial<Record<keyof E, unknown>>;
|
|
25
|
+
|
|
26
|
+
export type RenderableRecord<
|
|
27
|
+
E extends Record<string, RenderableValue> = Record<string, RenderableValue>,
|
|
28
|
+
> = E;
|
|
29
|
+
|
|
30
|
+
export type KeyedRenderableRecord<
|
|
31
|
+
K extends Key = Key,
|
|
32
|
+
E extends Record<string, RenderableValue> = Record<string, RenderableValue>,
|
|
33
|
+
> = KeyedRecord<K, E> & Omit<RenderableRecord<E>, "key">;
|
|
34
|
+
|
|
35
|
+
export const unknownRecordZ = z.record(
|
|
36
|
+
z.union([z.number(), z.string(), z.symbol()]),
|
|
37
|
+
z.unknown(),
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
export type Entries<T> = {
|
|
41
|
+
[K in keyof T]: [K, T[K]];
|
|
42
|
+
}[keyof T][];
|
|
43
|
+
|
|
44
|
+
export const getEntries = <T extends Record<Key, unknown>>(obj: T): Entries<T> =>
|
|
45
|
+
Object.entries(obj) as Entries<T>;
|
|
@@ -0,0 +1,20 @@
|
|
|
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 { type Stringer } from "@/primitive";
|
|
11
|
+
|
|
12
|
+
export type PureRenderableValue = string | number | undefined;
|
|
13
|
+
export type RenderableValue = PureRenderableValue | Stringer;
|
|
14
|
+
|
|
15
|
+
export const convertRenderV = (value: RenderableValue): string | number | undefined => {
|
|
16
|
+
if (value === undefined || typeof value === "string" || typeof value === "number")
|
|
17
|
+
return value;
|
|
18
|
+
if (value.toString === undefined) throw new Error("invalid renderer");
|
|
19
|
+
return value.toString();
|
|
20
|
+
};
|