swarpc 0.16.0 → 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 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
+ ![npm bundle size](https://img.shields.io/bundlephobia/minzip/swarpc)
9
+ ![NPM Version](https://img.shields.io/npm/v/swarpc)
10
+ ![GitHub branch check runs](https://img.shields.io/github/check-runs/gwennlbh/swarpc/main)
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?.(data.functionName, new Error(data.error.message));
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?.(data.functionName, data.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?.(data.functionName, data.result);
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
@@ -56,7 +56,7 @@ export type ProcedureImplementation<I extends Schema, P extends Schema, S extend
56
56
  /**
57
57
  * Input data for the procedure
58
58
  */
59
- input: Schema.InferInput<I>,
59
+ input: Schema.InferOutput<I>,
60
60
  /**
61
61
  * Callback to call with progress updates.
62
62
  */
@@ -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://gwennlbh.github.io/swarpc/docs/#make-cancelable-requests)
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?: <Procedure extends keyof ProceduresMap>(procedure: Procedure, data: Schema.InferOutput<Procedures[Procedure]["success"]>) => void;
95
+ success?: (arg: ProcedureNameAndData<Procedures, "success">) => void;
92
96
  /**
93
97
  * Called when a procedure call has failed.
94
98
  */
95
- error?: <Procedure extends keyof ProceduresMap>(procedure: Procedure, error: Error) => void;
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?: <Procedure extends keyof ProceduresMap>(procedure: Procedure, data: Schema.InferOutput<Procedures[Procedure]["progress"]>) => void;
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.16.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://github.com/gwennlbh/swarpc#readme",
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.56.1",
51
- "@size-limit/esbuild-why": "^11.2.0",
52
- "@size-limit/preset-small-lib": "^11.2.0",
53
- "@vitest/web-worker": "^4.0.6",
54
- "arktype": "^2.1.25",
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.67.0",
59
- "lint-staged": "^16.2.6",
60
- "nodemon": "^3.1.10",
61
- "oxlint": "^1.25.0",
62
- "pkg-pr-new": "^0.0.60",
63
- "prettier": "^3.6.2",
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": "^11.2.0",
66
- "typedoc": "^0.28.14",
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.27",
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.1.12",
75
- "vitest": "^4.0.6"
74
+ "vite": "^7.2.7",
75
+ "vitest": "^4.0.15"
76
76
  },
77
77
  "volta": {
78
- "node": "24.11.0",
79
- "npm": "11.6.2"
78
+ "node": "24.11.1",
79
+ "npm": "11.6.4"
80
80
  },
81
81
  "lint-staged": {
82
82
  "*.{ts,js,md,json,yaml,yml}": [