swarpc 0.19.0 → 0.20.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.js CHANGED
@@ -120,6 +120,7 @@ export function Client(procedures, { worker, nodes: nodeCount, loglevel = "debug
120
120
  pendingRequests.set(requestId, {
121
121
  nodeId,
122
122
  functionName,
123
+ startedAt: performance.now(),
123
124
  concurrencyKey,
124
125
  resolve,
125
126
  onProgress: onProgress ?? emptyProgressCallback,
@@ -320,10 +321,12 @@ async function startClientListener(ctx) {
320
321
  if (!handlers) {
321
322
  throw new Error(`[SWARPC Client] ${requestId} has no active request handlers, cannot process ${JSON.stringify(data)}`);
322
323
  }
324
+ const duration = performance.now() - handlers.startedAt;
323
325
  if ("error" in data) {
324
326
  ctx.hooks.error?.({
325
327
  procedure: data.functionName,
326
328
  error: new Error(data.error.message),
329
+ duration,
327
330
  });
328
331
  handlers.reject(new Error(data.error.message));
329
332
  pendingRequests.delete(requestId);
@@ -332,6 +335,7 @@ async function startClientListener(ctx) {
332
335
  ctx.hooks.progress?.({
333
336
  procedure: data.functionName,
334
337
  data: data.progress,
338
+ duration,
335
339
  });
336
340
  handlers.onProgress(data.progress);
337
341
  }
@@ -339,6 +343,7 @@ async function startClientListener(ctx) {
339
343
  ctx.hooks.success?.({
340
344
  procedure: data.functionName,
341
345
  data: data.result,
346
+ duration,
342
347
  });
343
348
  handlers.resolve(data.result);
344
349
  pendingRequests.delete(requestId);
package/dist/types.d.ts CHANGED
@@ -90,6 +90,8 @@ type ProcedureNameAndData<Procedures extends ProceduresMap, Key extends "progres
90
90
  [K in keyof Procedures]: {
91
91
  procedure: K;
92
92
  data: Schema.InferOutput<Procedures[K][Key]>;
93
+ /** Time in milliseconds the procedure call took */
94
+ duration: number;
93
95
  };
94
96
  }[keyof Procedures];
95
97
  /**
@@ -102,9 +104,12 @@ export type Hooks<Procedures extends ProceduresMap> = {
102
104
  success?: (arg: ProcedureNameAndData<Procedures, "success">) => void;
103
105
  /**
104
106
  * Called when a procedure call has failed.
107
+ * @param arg
108
+ * @param arg.duration time in milliseconds the procedure call took
105
109
  */
106
110
  error?: (arg: {
107
111
  procedure: keyof Procedures;
112
+ duration: number;
108
113
  error: Error;
109
114
  }) => void;
110
115
  /**
@@ -200,7 +205,7 @@ export type BroadcasterResultExtrasFailure = {
200
205
  successes: [];
201
206
  byNode: Map<string, PromiseRejectedResult>;
202
207
  };
203
- type ClientMethodExtraCallables<P extends Procedure<Schema, Schema, Schema>> = {
208
+ export type ClientMethodExtraCallables<P extends Procedure<Schema, Schema, Schema>> = {
204
209
  /**
205
210
  * A method that returns a `CancelablePromise`. Cancel it by calling `.cancel(reason)` on it, and wait for the request to resolve by awaiting the `request` property on the returned object.
206
211
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swarpc",
3
- "version": "0.19.0",
3
+ "version": "0.20.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",
@@ -47,36 +47,36 @@
47
47
  },
48
48
  "devDependencies": {
49
49
  "@8hobbies/typedoc-plugin-plausible": "^2.2.0",
50
- "@playwright/test": "^1.57.0",
50
+ "@playwright/test": "^1.58.2",
51
51
  "@size-limit/esbuild-why": "^12.0.0",
52
52
  "@size-limit/preset-small-lib": "^12.0.0",
53
- "@vitest/web-worker": "^4.0.17",
53
+ "@vitest/web-worker": "^4.0.18",
54
54
  "arktype": "^2.1.29",
55
55
  "date-fns": "^4.1.0",
56
56
  "husky": "^9.1.7",
57
57
  "kacl": "^1.1.1",
58
- "knip": "^5.82.1",
58
+ "knip": "^5.85.0",
59
59
  "lint-staged": "^16.2.7",
60
- "nodemon": "^3.1.11",
61
- "oxlint": "^1.40.0",
62
- "pkg-pr-new": "^0.0.62",
63
- "prettier": "^3.8.0",
60
+ "nodemon": "^3.1.14",
61
+ "oxlint": "^1.50.0",
62
+ "pkg-pr-new": "^0.0.63",
63
+ "prettier": "^3.8.1",
64
64
  "sirv-cli": "^3.0.1",
65
65
  "size-limit": "^12.0.0",
66
- "typedoc": "^0.28.16",
66
+ "typedoc": "^0.28.17",
67
67
  "typedoc-material-theme": "^1.4.1",
68
- "typedoc-plugin-dt-links": "^2.0.38",
68
+ "typedoc-plugin-dt-links": "^2.0.43",
69
69
  "typedoc-plugin-extras": "^4.0.1",
70
70
  "typedoc-plugin-inline-sources": "^1.3.0",
71
- "typedoc-plugin-mdn-links": "^5.1.0",
72
- "typedoc-plugin-redirect": "^1.2.1",
71
+ "typedoc-plugin-mdn-links": "^5.1.1",
72
+ "typedoc-plugin-redirect": "^1.3.0",
73
73
  "typescript": "^5.9.3",
74
74
  "vite": "^7.3.1",
75
- "vitest": "^4.0.17"
75
+ "vitest": "^4.0.18"
76
76
  },
77
77
  "volta": {
78
- "node": "24.13.0",
79
- "npm": "11.7.0"
78
+ "node": "24.13.1",
79
+ "npm": "11.10.1"
80
80
  },
81
81
  "lint-staged": {
82
82
  "*.{ts,js,md,json,yaml,yml}": [