@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
package/src/toArray.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
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 const toArray = <T>(value: T | T[]): T[] =>
|
|
11
|
+
Array.isArray(value) ? value : [value];
|
package/src/transform.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 ArrayTransform<E = unknown, R = E> = (data: E[]) => R[];
|
package/src/unique.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 const unique = <V>(values: V[] | readonly V[]): V[] => [...new Set(values)];
|
package/src/url/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 * from "./url";
|
|
@@ -0,0 +1,47 @@
|
|
|
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 } from "vitest";
|
|
11
|
+
|
|
12
|
+
import { URL } from "@/url";
|
|
13
|
+
|
|
14
|
+
describe("URL", () => {
|
|
15
|
+
test("URL - child", () => {
|
|
16
|
+
const endpoint = new URL({
|
|
17
|
+
host: "localhost",
|
|
18
|
+
port: 8080,
|
|
19
|
+
protocol: "http",
|
|
20
|
+
pathPrefix: "api",
|
|
21
|
+
});
|
|
22
|
+
expect(endpoint.child("test").toString()).toEqual("http://localhost:8080/api/test");
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
test("URL - child with trailing slash", () => {
|
|
26
|
+
const endpoint = new URL({
|
|
27
|
+
host: "localhost",
|
|
28
|
+
port: 8080,
|
|
29
|
+
protocol: "http",
|
|
30
|
+
pathPrefix: "api",
|
|
31
|
+
});
|
|
32
|
+
const child = endpoint.child("test/");
|
|
33
|
+
expect(child.toString()).toEqual("http://localhost:8080/api/test");
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test("URL - replacing protocol", () => {
|
|
37
|
+
const endpoint = new URL({
|
|
38
|
+
host: "localhost",
|
|
39
|
+
port: 8080,
|
|
40
|
+
protocol: "http",
|
|
41
|
+
pathPrefix: "api",
|
|
42
|
+
});
|
|
43
|
+
expect(endpoint.child("test").replace({ protocol: "https" }).toString()).toEqual(
|
|
44
|
+
"https://localhost:8080/api/test"
|
|
45
|
+
);
|
|
46
|
+
});
|
|
47
|
+
});
|
package/src/url/url.ts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
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
|
+
interface URLProps {
|
|
11
|
+
host: string;
|
|
12
|
+
port: number;
|
|
13
|
+
protocol?: string;
|
|
14
|
+
pathPrefix?: string;
|
|
15
|
+
params?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** @returns the paths joined with a single slash */
|
|
19
|
+
const joinPaths = (...paths: string[]): string => paths.map(formatPath).join("");
|
|
20
|
+
|
|
21
|
+
/** ensures that a path is correctly formatted for joining */
|
|
22
|
+
const formatPath = (path: string): string => {
|
|
23
|
+
if (!path.endsWith("/")) path += "/";
|
|
24
|
+
if (path.startsWith("/")) path = path.slice(1);
|
|
25
|
+
return path;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/** removes the trailing slash from a path */
|
|
29
|
+
const removeTrailingSlash = (path: string): string =>
|
|
30
|
+
path.endsWith("/") ? path.slice(0, -1) : path;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Builds a query string from a record.
|
|
34
|
+
* @param record - The record to build the query string from. If the record is null,
|
|
35
|
+
* an empty string is returned.
|
|
36
|
+
* @returns the query string.
|
|
37
|
+
*/
|
|
38
|
+
export const buildQueryString = (
|
|
39
|
+
request: Record<string, unknown>,
|
|
40
|
+
prefix: string = ""
|
|
41
|
+
): string => {
|
|
42
|
+
if (request === null) return "";
|
|
43
|
+
return (
|
|
44
|
+
"?" +
|
|
45
|
+
Object.entries(request)
|
|
46
|
+
.filter(([, value]) => {
|
|
47
|
+
if (value === undefined || value === null) return false;
|
|
48
|
+
if (Array.isArray(value)) return value.length > 0;
|
|
49
|
+
return true;
|
|
50
|
+
})
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
52
|
+
.map(([key, value]) => `${prefix}${key}=${value}`)
|
|
53
|
+
.join("&")
|
|
54
|
+
);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* URL is a simple class for building and extending URLs.
|
|
59
|
+
*/
|
|
60
|
+
export class URL {
|
|
61
|
+
protocol: string;
|
|
62
|
+
host: string;
|
|
63
|
+
port: number;
|
|
64
|
+
path: string;
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @param host - The hostname or IP address of the server.
|
|
68
|
+
* @param port - The port number of the server.
|
|
69
|
+
* @param protocol - The protocol to use for all requests. Defaults to "".
|
|
70
|
+
* @param pathPrefix - A path prefix to use for all requests. Defaults to "".
|
|
71
|
+
*/
|
|
72
|
+
constructor({ host, port, protocol = "", pathPrefix = "" }: URLProps) {
|
|
73
|
+
this.protocol = protocol;
|
|
74
|
+
this.host = host;
|
|
75
|
+
this.port = port;
|
|
76
|
+
this.path = formatPath(pathPrefix);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Replaces creates a new URL with the specified properties replaced.
|
|
81
|
+
* @param props - The properties to replace.
|
|
82
|
+
* @returns a new URL.
|
|
83
|
+
*/
|
|
84
|
+
replace(props: Partial<URLProps>): URL {
|
|
85
|
+
return new URL({
|
|
86
|
+
host: props.host ?? this.host,
|
|
87
|
+
port: props.port ?? this.port,
|
|
88
|
+
protocol: props.protocol ?? this.protocol,
|
|
89
|
+
pathPrefix: props.pathPrefix ?? this.path,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Creates a new url with the given path appended to the current path.
|
|
95
|
+
* @param path - the path to append to the URL.
|
|
96
|
+
* @returns a new URL.
|
|
97
|
+
*/
|
|
98
|
+
child(path: string): URL {
|
|
99
|
+
return new URL({
|
|
100
|
+
...this,
|
|
101
|
+
pathPrefix: joinPaths(this.path, path),
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/** @returns a string representation of the url */
|
|
106
|
+
toString(): string {
|
|
107
|
+
return removeTrailingSlash(
|
|
108
|
+
`${this.protocol}://${this.host}:${this.port}/${this.path}`
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
static readonly UNKNOWN = new URL({ host: "unknown", port: 0 });
|
|
113
|
+
}
|
|
@@ -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 { describe, expect, it, vi } from "vitest";
|
|
11
|
+
|
|
12
|
+
import { createMockWorkers } from "./worker";
|
|
13
|
+
|
|
14
|
+
interface MockMessage {
|
|
15
|
+
value: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
describe("Worker", () => {
|
|
19
|
+
it("should correctly send and handle a message from a typed worker", () => {
|
|
20
|
+
const [a, b] = createMockWorkers();
|
|
21
|
+
const aT = a.route<MockMessage>("dog");
|
|
22
|
+
const bT = b.route<MockMessage>("dog");
|
|
23
|
+
const handler = vi.fn();
|
|
24
|
+
bT.handle(handler);
|
|
25
|
+
aT.send({ value: "hello" });
|
|
26
|
+
expect(handler).toHaveBeenCalledWith({ value: "hello" });
|
|
27
|
+
});
|
|
28
|
+
it("should route the message to the correct location", () => {
|
|
29
|
+
const [a, b] = createMockWorkers();
|
|
30
|
+
const aT = a.route<MockMessage>("dog");
|
|
31
|
+
const bT = b.route<MockMessage>("cat");
|
|
32
|
+
const dogBT = b.route<MockMessage>("dog");
|
|
33
|
+
const handler = vi.fn();
|
|
34
|
+
bT.handle(handler);
|
|
35
|
+
const dogHandler = vi.fn();
|
|
36
|
+
dogBT.handle(dogHandler);
|
|
37
|
+
aT.send({ value: "hello" });
|
|
38
|
+
expect(handler).not.toHaveBeenCalled();
|
|
39
|
+
expect(dogHandler).toHaveBeenCalled();
|
|
40
|
+
});
|
|
41
|
+
});
|
|
@@ -0,0 +1,86 @@
|
|
|
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 Sender<T> {
|
|
11
|
+
send: (value: T, transfer?: Transferable[]) => void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface Handler<T> {
|
|
15
|
+
handle: (handler: (value: T) => void) => void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface SenderHandler<I, O> extends Sender<I>, Handler<O> {}
|
|
19
|
+
|
|
20
|
+
interface TypedWorkerMessage {
|
|
21
|
+
type: string;
|
|
22
|
+
payload: any;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
type SendFunc = (value: any, transfer?: Transferable[]) => void;
|
|
26
|
+
type HandlerFunc = (value: any) => void;
|
|
27
|
+
|
|
28
|
+
export class RoutedWorker {
|
|
29
|
+
sender: SendFunc;
|
|
30
|
+
handlers: Map<string, TypedWorker<any>>;
|
|
31
|
+
|
|
32
|
+
constructor(send: SendFunc) {
|
|
33
|
+
this.sender = send;
|
|
34
|
+
this.handlers = new Map();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
handle({ data }: { data: TypedWorkerMessage }): void {
|
|
38
|
+
const handler = this.handlers.get(data.type)?.handler;
|
|
39
|
+
if (handler == null) console.warn(`No handler for ${data.type}`);
|
|
40
|
+
else handler(data.payload);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
route<RQ, RS = RQ>(type: string): TypedWorker<RQ, RS> {
|
|
44
|
+
const send = typedSend(type, this.sender);
|
|
45
|
+
const t = new TypedWorker<RQ, RS>(send);
|
|
46
|
+
this.handlers.set(type, t);
|
|
47
|
+
return t;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const typedSend =
|
|
52
|
+
(type: string, send: SendFunc): SendFunc =>
|
|
53
|
+
(payload: any, transfer?: Transferable[]) => {
|
|
54
|
+
return send({ type, payload }, transfer);
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export class TypedWorker<RQ, RS = RQ> implements SenderHandler<RQ, RS> {
|
|
58
|
+
private readonly _send: SendFunc;
|
|
59
|
+
handler: HandlerFunc | null;
|
|
60
|
+
|
|
61
|
+
constructor(send: SendFunc) {
|
|
62
|
+
this._send = send;
|
|
63
|
+
this.handler = null;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
send(payload: RQ, transfer: Transferable[] = []): void {
|
|
67
|
+
this._send(payload, transfer);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
handle(handler: (payload: RS) => void): void {
|
|
71
|
+
this.handler = handler;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export const createMockWorkers = (): [RoutedWorker, RoutedWorker] => {
|
|
76
|
+
let a: RoutedWorker, b: RoutedWorker;
|
|
77
|
+
const aSend = (value: any, transfer?: Transferable[]): void => {
|
|
78
|
+
b.handle({ data: value });
|
|
79
|
+
};
|
|
80
|
+
const bSend = (value: any, transfer?: Transferable[]): void => {
|
|
81
|
+
a.handle({ data: value });
|
|
82
|
+
};
|
|
83
|
+
a = new RoutedWorker(aSend);
|
|
84
|
+
b = new RoutedWorker(bSend);
|
|
85
|
+
return [a, b];
|
|
86
|
+
};
|
package/tsconfig.json
ADDED
package/vite.config.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
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 { lib } from "@synnaxlabs/vite-plugin";
|
|
11
|
+
import { defineConfig } from "vite";
|
|
12
|
+
|
|
13
|
+
export default defineConfig({
|
|
14
|
+
plugins: [lib({ name: "x" })],
|
|
15
|
+
build: {
|
|
16
|
+
sourcemap: true,
|
|
17
|
+
minify: false,
|
|
18
|
+
},
|
|
19
|
+
test: {
|
|
20
|
+
globals: true,
|
|
21
|
+
environment: "jsdom",
|
|
22
|
+
},
|
|
23
|
+
});
|