swarpc 0.7.0 → 0.8.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/dist/client.d.ts +39 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/{src/client.js → client.js} +11 -3
- package/dist/{src/index.d.ts → index.d.ts} +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/{src/index.js → index.js} +4 -0
- package/dist/log.d.ts +28 -0
- package/dist/log.d.ts.map +1 -0
- package/dist/log.js +55 -0
- package/dist/server.d.ts +32 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/{src/server.js → server.js} +18 -10
- package/dist/{src/types.d.ts → types.d.ts} +44 -23
- package/dist/types.d.ts.map +1 -0
- package/dist/{src/types.js → types.js} +17 -0
- package/dist/utils.d.ts.map +1 -0
- package/package.json +18 -5
- package/src/client.ts +22 -4
- package/src/index.ts +5 -0
- package/src/log.ts +68 -12
- package/src/server.ts +37 -16
- package/src/types.ts +43 -31
- package/dist/src/client.d.ts +0 -22
- package/dist/src/client.d.ts.map +0 -1
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/log.d.ts +0 -20
- package/dist/src/log.d.ts.map +0 -1
- package/dist/src/log.js +0 -45
- package/dist/src/server.d.ts +0 -15
- package/dist/src/server.d.ts.map +0 -1
- package/dist/src/types.d.ts.map +0 -1
- package/dist/src/utils.d.ts.map +0 -1
- package/dist/tests/core.procedures.d.ts +0 -45
- package/dist/tests/core.procedures.d.ts.map +0 -1
- package/dist/tests/core.procedures.js +0 -49
- package/dist/tests/core.test.d.ts +0 -2
- package/dist/tests/core.test.d.ts.map +0 -1
- package/dist/tests/core.test.js +0 -100
- package/dist/tests/core.worker.d.ts +0 -2
- package/dist/tests/core.worker.d.ts.map +0 -1
- package/dist/tests/core.worker.js +0 -30
- package/dist/vite.config.d.ts +0 -3
- package/dist/vite.config.d.ts.map +0 -1
- package/dist/vite.config.js +0 -7
- /package/dist/{src/utils.d.ts → utils.d.ts} +0 -0
- /package/dist/{src/utils.js → utils.js} +0 -0
package/dist/tests/core.test.js
DELETED
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
import "@vitest/web-worker";
|
|
2
|
-
import { beforeEach, describe, expect, test, vi } from "vitest";
|
|
3
|
-
import { Client } from "../src/index.js";
|
|
4
|
-
import { procedures } from "./core.procedures.js";
|
|
5
|
-
// @ts-ignore
|
|
6
|
-
import Worker from "./core.worker.js?worker";
|
|
7
|
-
const client = Client(procedures, { worker: new Worker(), loglevel: "warn" });
|
|
8
|
-
test("Simple exchange", async () => {
|
|
9
|
-
const answer = await client.hello("world");
|
|
10
|
-
expect(answer).toBe("Hello world");
|
|
11
|
-
});
|
|
12
|
-
test("Progress info", async () => {
|
|
13
|
-
const callback = vi.fn();
|
|
14
|
-
const answer = await client.helloWithProgress("world", callback);
|
|
15
|
-
expect(answer).toBe("Hello with progress world");
|
|
16
|
-
expect(callback.mock.calls).toStrictEqual([
|
|
17
|
-
[{ current: 0, total: 10 }],
|
|
18
|
-
[{ current: 1, total: 10 }],
|
|
19
|
-
[{ current: 2, total: 10 }],
|
|
20
|
-
[{ current: 3, total: 10 }],
|
|
21
|
-
[{ current: 4, total: 10 }],
|
|
22
|
-
[{ current: 5, total: 10 }],
|
|
23
|
-
[{ current: 6, total: 10 }],
|
|
24
|
-
[{ current: 7, total: 10 }],
|
|
25
|
-
[{ current: 8, total: 10 }],
|
|
26
|
-
[{ current: 9, total: 10 }],
|
|
27
|
-
]);
|
|
28
|
-
});
|
|
29
|
-
describe("Cancellable procedure", () => {
|
|
30
|
-
const progress = vi.fn();
|
|
31
|
-
beforeEach(() => {
|
|
32
|
-
progress.mockReset();
|
|
33
|
-
});
|
|
34
|
-
test("Can be cancelled", async () => {
|
|
35
|
-
const { cancel } = client.cancellable.cancelable("test", progress);
|
|
36
|
-
await new Promise((resolve) => setTimeout(resolve, 2));
|
|
37
|
-
await cancel("test cancellation");
|
|
38
|
-
expect(progress.mock.calls.length).toBeLessThan(10);
|
|
39
|
-
});
|
|
40
|
-
test("Can be completed", async () => {
|
|
41
|
-
const { request } = client.cancellable.cancelable("test", progress);
|
|
42
|
-
const answer = await request;
|
|
43
|
-
expect(answer).toBe("Cancellable hello test");
|
|
44
|
-
expect(progress.mock.calls.length).toBe(10);
|
|
45
|
-
});
|
|
46
|
-
test("Can be run normally", async () => {
|
|
47
|
-
const answer = await client.cancellable("test", progress);
|
|
48
|
-
expect(answer).toBe("Cancellable hello test");
|
|
49
|
-
expect(progress.mock.calls.length).toBe(10);
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
describe("Complex data", () => {
|
|
53
|
-
test("Processes complex data", async () => {
|
|
54
|
-
const response = await client.complexData({
|
|
55
|
-
name: "test",
|
|
56
|
-
custom: '{"key": "value"}',
|
|
57
|
-
address: {
|
|
58
|
-
street: "Main St",
|
|
59
|
-
city: "Testville",
|
|
60
|
-
zip: "12345",
|
|
61
|
-
houseno: 42,
|
|
62
|
-
},
|
|
63
|
-
age: 30,
|
|
64
|
-
});
|
|
65
|
-
expect(response).toEqual({
|
|
66
|
-
message: "Processed data for test",
|
|
67
|
-
addr: "42 Main St, Testville 12345",
|
|
68
|
-
});
|
|
69
|
-
});
|
|
70
|
-
test("Handles missing optional fields", async () => {
|
|
71
|
-
const response = await client.complexData({
|
|
72
|
-
name: "test",
|
|
73
|
-
custom: '{"key": "value"}',
|
|
74
|
-
address: {
|
|
75
|
-
street: "Main St",
|
|
76
|
-
city: "Testville",
|
|
77
|
-
zip: "12345",
|
|
78
|
-
},
|
|
79
|
-
age: 30,
|
|
80
|
-
});
|
|
81
|
-
expect(response).toEqual({
|
|
82
|
-
message: "Processed data for test",
|
|
83
|
-
addr: "Main St, Testville 12345",
|
|
84
|
-
});
|
|
85
|
-
});
|
|
86
|
-
test("Errors on invalid data", async () => {
|
|
87
|
-
await expect(client.complexData({
|
|
88
|
-
name: "test",
|
|
89
|
-
custom: '{"key": "value"}',
|
|
90
|
-
address: {
|
|
91
|
-
street: "Main St",
|
|
92
|
-
city: "Testville",
|
|
93
|
-
zip: "12345",
|
|
94
|
-
// @ts-expect-error
|
|
95
|
-
houseno: "not-a-number", // Invalid type
|
|
96
|
-
},
|
|
97
|
-
age: 30,
|
|
98
|
-
})).rejects.toThrowErrorMatchingInlineSnapshot(`[TraversalError: address.houseno must be a number (was a string)]`);
|
|
99
|
-
});
|
|
100
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"core.worker.d.ts","sourceRoot":"","sources":["../../tests/core.worker.ts"],"names":[],"mappings":""}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { Server } from "../src/index.js";
|
|
2
|
-
import { procedures } from "./core.procedures.js";
|
|
3
|
-
const server = Server(procedures, { worker: self, loglevel: "warn" });
|
|
4
|
-
server.hello(async (input) => {
|
|
5
|
-
return `Hello ${input}`;
|
|
6
|
-
});
|
|
7
|
-
server.helloWithProgress(async (input, onProgress) => {
|
|
8
|
-
for (let i = 0; i < 10; i++) {
|
|
9
|
-
onProgress({ current: i, total: 10 });
|
|
10
|
-
}
|
|
11
|
-
return `Hello with progress ${input}`;
|
|
12
|
-
});
|
|
13
|
-
server.cancellable(async (input, onProgress, abortSignal) => {
|
|
14
|
-
let aborted = false;
|
|
15
|
-
abortSignal?.addEventListener("abort", () => {
|
|
16
|
-
aborted = true;
|
|
17
|
-
});
|
|
18
|
-
for (let i = 0; i < 10; i++) {
|
|
19
|
-
if (aborted)
|
|
20
|
-
return "cancelled";
|
|
21
|
-
onProgress({ current: i, total: 10 });
|
|
22
|
-
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
23
|
-
}
|
|
24
|
-
return `Cancellable hello ${input}`;
|
|
25
|
-
});
|
|
26
|
-
server.complexData(async (input, onProgress) => {
|
|
27
|
-
onProgress({ message: "Processing data", percent: 50 });
|
|
28
|
-
return { message: `Processed data for ${input.name}`, addr: input.address };
|
|
29
|
-
});
|
|
30
|
-
server.start(self);
|
package/dist/vite.config.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"vite.config.d.ts","sourceRoot":"","sources":["../vite.config.ts"],"names":[],"mappings":";AAEA,wBAKE"}
|
package/dist/vite.config.js
DELETED
|
File without changes
|
|
File without changes
|