swarpc 0.16.1 → 0.17.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/README.md +4 -0
- package/dist/client.js +12 -3
- package/dist/types.d.ts +12 -4
- package/package.json +20 -20
package/README.md
CHANGED
|
@@ -5,6 +5,10 @@
|
|
|
5
5
|
|
|
6
6
|
RPC for Service (and other types of) Workers -- move that heavy computation off of your UI thread!
|
|
7
7
|
|
|
8
|
+

|
|
9
|
+

|
|
10
|
+

|
|
11
|
+
|
|
8
12
|
</div>
|
|
9
13
|
|
|
10
14
|
* * *
|
package/dist/client.js
CHANGED
|
@@ -175,16 +175,25 @@ async function startClientListener(ctx) {
|
|
|
175
175
|
throw new Error(`[SWARPC Client] ${requestId} has no active request handlers, cannot process ${JSON.stringify(data)}`);
|
|
176
176
|
}
|
|
177
177
|
if ("error" in data) {
|
|
178
|
-
ctx.hooks.error?.(
|
|
178
|
+
ctx.hooks.error?.({
|
|
179
|
+
procedure: data.functionName,
|
|
180
|
+
error: new Error(data.error.message),
|
|
181
|
+
});
|
|
179
182
|
handlers.reject(new Error(data.error.message));
|
|
180
183
|
pendingRequests.delete(requestId);
|
|
181
184
|
}
|
|
182
185
|
else if ("progress" in data) {
|
|
183
|
-
ctx.hooks.progress?.(
|
|
186
|
+
ctx.hooks.progress?.({
|
|
187
|
+
procedure: data.functionName,
|
|
188
|
+
data: data.progress,
|
|
189
|
+
});
|
|
184
190
|
handlers.onProgress(data.progress);
|
|
185
191
|
}
|
|
186
192
|
else if ("result" in data) {
|
|
187
|
-
ctx.hooks.success?.(
|
|
193
|
+
ctx.hooks.success?.({
|
|
194
|
+
procedure: data.functionName,
|
|
195
|
+
data: data.result,
|
|
196
|
+
});
|
|
188
197
|
handlers.resolve(data.result);
|
|
189
198
|
pendingRequests.delete(requestId);
|
|
190
199
|
}
|
package/dist/types.d.ts
CHANGED
|
@@ -66,7 +66,7 @@ onProgress: (progress: Schema.InferInput<P>) => void,
|
|
|
66
66
|
*/
|
|
67
67
|
tools: {
|
|
68
68
|
/**
|
|
69
|
-
* AbortSignal that can be used to handle request cancellation -- see [Make cancellable requests](https://
|
|
69
|
+
* AbortSignal that can be used to handle request cancellation -- see [Make cancellable requests](https://swarpc.js.org/#make-cancelable-requests)
|
|
70
70
|
*/
|
|
71
71
|
abortSignal?: AbortSignal;
|
|
72
72
|
/**
|
|
@@ -81,6 +81,10 @@ tools: {
|
|
|
81
81
|
* {@includeCode ../example/src/lib/procedures.ts}
|
|
82
82
|
*/
|
|
83
83
|
export type ProceduresMap = Record<string, Procedure<Schema, Schema, Schema>>;
|
|
84
|
+
type ProcedureNameAndData<Procedures extends ProceduresMap, Key extends "progress" | "success", Name extends keyof Procedures = keyof Procedures> = {
|
|
85
|
+
procedure: Name;
|
|
86
|
+
data: Schema.InferOutput<Procedures[Name][Key]>;
|
|
87
|
+
};
|
|
84
88
|
/**
|
|
85
89
|
* Declaration of hooks to run on messages received from the server
|
|
86
90
|
*/
|
|
@@ -88,15 +92,18 @@ export type Hooks<Procedures extends ProceduresMap> = {
|
|
|
88
92
|
/**
|
|
89
93
|
* Called when a procedure call has been successful.
|
|
90
94
|
*/
|
|
91
|
-
success?:
|
|
95
|
+
success?: (arg: ProcedureNameAndData<Procedures, "success">) => void;
|
|
92
96
|
/**
|
|
93
97
|
* Called when a procedure call has failed.
|
|
94
98
|
*/
|
|
95
|
-
error?:
|
|
99
|
+
error?: (arg: {
|
|
100
|
+
procedure: keyof Procedures;
|
|
101
|
+
error: Error;
|
|
102
|
+
}) => void;
|
|
96
103
|
/**
|
|
97
104
|
* Called when a procedure call sends progress updates.
|
|
98
105
|
*/
|
|
99
|
-
progress?:
|
|
106
|
+
progress?: (arg: ProcedureNameAndData<Procedures, "progress">) => void;
|
|
100
107
|
};
|
|
101
108
|
export type PayloadCore<PM extends ProceduresMap, Name extends keyof PM = keyof PM> = {
|
|
102
109
|
input: Schema.InferOutput<PM[Name]["input"]>;
|
|
@@ -139,3 +146,4 @@ export type WorkerConstructor<T extends Worker | SharedWorker = Worker | SharedW
|
|
|
139
146
|
name?: string;
|
|
140
147
|
}): T;
|
|
141
148
|
};
|
|
149
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "swarpc",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.17.0",
|
|
4
4
|
"description": "Full type-safe RPC library for service worker -- move things off of the UI thread with ease!",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"service-workers",
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"trpc",
|
|
10
10
|
"typesafe"
|
|
11
11
|
],
|
|
12
|
-
"homepage": "https://
|
|
12
|
+
"homepage": "https://swarpc.js.org",
|
|
13
13
|
"bugs": {
|
|
14
14
|
"url": "https://github.com/gwennlbh/swarpc/issues"
|
|
15
15
|
},
|
|
@@ -47,36 +47,36 @@
|
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@8hobbies/typedoc-plugin-plausible": "^2.2.0",
|
|
50
|
-
"@playwright/test": "^1.
|
|
51
|
-
"@size-limit/esbuild-why": "^
|
|
52
|
-
"@size-limit/preset-small-lib": "^
|
|
53
|
-
"@vitest/web-worker": "^4.0.
|
|
54
|
-
"arktype": "^2.1.
|
|
50
|
+
"@playwright/test": "^1.57.0",
|
|
51
|
+
"@size-limit/esbuild-why": "^12.0.0",
|
|
52
|
+
"@size-limit/preset-small-lib": "^12.0.0",
|
|
53
|
+
"@vitest/web-worker": "^4.0.15",
|
|
54
|
+
"arktype": "^2.1.28",
|
|
55
55
|
"date-fns": "^4.1.0",
|
|
56
56
|
"husky": "^9.1.7",
|
|
57
57
|
"kacl": "^1.1.1",
|
|
58
|
-
"knip": "^5.
|
|
59
|
-
"lint-staged": "^16.2.
|
|
60
|
-
"nodemon": "^3.1.
|
|
61
|
-
"oxlint": "^1.
|
|
62
|
-
"pkg-pr-new": "^0.0.
|
|
63
|
-
"prettier": "^3.
|
|
58
|
+
"knip": "^5.72.0",
|
|
59
|
+
"lint-staged": "^16.2.7",
|
|
60
|
+
"nodemon": "^3.1.11",
|
|
61
|
+
"oxlint": "^1.32.0",
|
|
62
|
+
"pkg-pr-new": "^0.0.62",
|
|
63
|
+
"prettier": "^3.7.4",
|
|
64
64
|
"sirv-cli": "^3.0.1",
|
|
65
|
-
"size-limit": "^
|
|
66
|
-
"typedoc": "^0.28.
|
|
65
|
+
"size-limit": "^12.0.0",
|
|
66
|
+
"typedoc": "^0.28.15",
|
|
67
67
|
"typedoc-material-theme": "^1.4.1",
|
|
68
|
-
"typedoc-plugin-dt-links": "^2.0.
|
|
68
|
+
"typedoc-plugin-dt-links": "^2.0.32",
|
|
69
69
|
"typedoc-plugin-extras": "^4.0.1",
|
|
70
70
|
"typedoc-plugin-inline-sources": "^1.3.0",
|
|
71
71
|
"typedoc-plugin-mdn-links": "^5.0.10",
|
|
72
72
|
"typedoc-plugin-redirect": "^1.2.1",
|
|
73
73
|
"typescript": "^5.9.3",
|
|
74
|
-
"vite": "^7.2.
|
|
75
|
-
"vitest": "^4.0.
|
|
74
|
+
"vite": "^7.2.7",
|
|
75
|
+
"vitest": "^4.0.15"
|
|
76
76
|
},
|
|
77
77
|
"volta": {
|
|
78
|
-
"node": "24.11.
|
|
79
|
-
"npm": "11.6.
|
|
78
|
+
"node": "24.11.1",
|
|
79
|
+
"npm": "11.6.4"
|
|
80
80
|
},
|
|
81
81
|
"lint-staged": {
|
|
82
82
|
"*.{ts,js,md,json,yaml,yml}": [
|