@venizia/ignis-worker 0.2.0-2 → 0.2.0-20

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.
Files changed (103) hide show
  1. package/dist/cjs/envelope/common/index.d.ts +2 -0
  2. package/dist/cjs/envelope/common/index.d.ts.map +1 -0
  3. package/dist/cjs/envelope/common/index.js +18 -0
  4. package/dist/cjs/envelope/common/index.js.map +1 -0
  5. package/dist/cjs/envelope/common/types.d.ts.map +1 -0
  6. package/dist/{esm/envelope → cjs/envelope/common}/types.js.map +1 -1
  7. package/dist/cjs/envelope/encode.d.ts +1 -1
  8. package/dist/cjs/envelope/encode.d.ts.map +1 -1
  9. package/dist/cjs/envelope/index.d.ts +1 -1
  10. package/dist/cjs/envelope/index.d.ts.map +1 -1
  11. package/dist/cjs/envelope/index.js +1 -1
  12. package/dist/cjs/envelope/index.js.map +1 -1
  13. package/dist/cjs/transport/fetch-bridge.d.ts +35 -0
  14. package/dist/cjs/transport/fetch-bridge.d.ts.map +1 -0
  15. package/dist/cjs/transport/fetch-bridge.js +95 -0
  16. package/dist/cjs/transport/fetch-bridge.js.map +1 -0
  17. package/dist/cjs/transport/in-process.d.ts +2 -1
  18. package/dist/cjs/transport/in-process.d.ts.map +1 -1
  19. package/dist/cjs/transport/in-process.js +3 -1
  20. package/dist/cjs/transport/in-process.js.map +1 -1
  21. package/dist/cjs/transport/index.d.ts +2 -0
  22. package/dist/cjs/transport/index.d.ts.map +1 -1
  23. package/dist/cjs/transport/index.js +2 -0
  24. package/dist/cjs/transport/index.js.map +1 -1
  25. package/dist/cjs/transport/shared/common/constants.d.ts +14 -0
  26. package/dist/cjs/transport/shared/common/constants.d.ts.map +1 -0
  27. package/dist/cjs/transport/shared/common/constants.js +19 -0
  28. package/dist/cjs/transport/shared/common/constants.js.map +1 -0
  29. package/dist/cjs/transport/shared/common/index.d.ts +3 -0
  30. package/dist/cjs/transport/shared/common/index.d.ts.map +1 -0
  31. package/dist/cjs/transport/shared/common/index.js +19 -0
  32. package/dist/cjs/transport/shared/common/index.js.map +1 -0
  33. package/dist/cjs/transport/shared/common/types.d.ts +35 -0
  34. package/dist/cjs/transport/shared/common/types.d.ts.map +1 -0
  35. package/dist/cjs/transport/shared/common/types.js +3 -0
  36. package/dist/cjs/transport/shared/common/types.js.map +1 -0
  37. package/dist/cjs/transport/shared/index.d.ts +4 -0
  38. package/dist/cjs/transport/shared/index.d.ts.map +1 -0
  39. package/dist/cjs/transport/shared/index.js +11 -0
  40. package/dist/cjs/transport/shared/index.js.map +1 -0
  41. package/dist/cjs/transport/shared/transport.d.ts +87 -0
  42. package/dist/cjs/transport/shared/transport.d.ts.map +1 -0
  43. package/dist/cjs/transport/shared/transport.js +383 -0
  44. package/dist/cjs/transport/shared/transport.js.map +1 -0
  45. package/dist/cjs/transport/worker.d.ts +16 -2
  46. package/dist/cjs/transport/worker.d.ts.map +1 -1
  47. package/dist/cjs/transport/worker.js +65 -7
  48. package/dist/cjs/transport/worker.js.map +1 -1
  49. package/dist/esm/envelope/common/index.d.ts +2 -0
  50. package/dist/esm/envelope/common/index.d.ts.map +1 -0
  51. package/dist/esm/envelope/common/index.js +2 -0
  52. package/dist/esm/envelope/common/index.js.map +1 -0
  53. package/dist/esm/envelope/common/types.d.ts.map +1 -0
  54. package/dist/{cjs/envelope → esm/envelope/common}/types.js.map +1 -1
  55. package/dist/esm/envelope/encode.d.ts +1 -1
  56. package/dist/esm/envelope/encode.d.ts.map +1 -1
  57. package/dist/esm/envelope/index.d.ts +1 -1
  58. package/dist/esm/envelope/index.d.ts.map +1 -1
  59. package/dist/esm/envelope/index.js +1 -1
  60. package/dist/esm/envelope/index.js.map +1 -1
  61. package/dist/esm/transport/fetch-bridge.d.ts +35 -0
  62. package/dist/esm/transport/fetch-bridge.d.ts.map +1 -0
  63. package/dist/esm/transport/fetch-bridge.js +91 -0
  64. package/dist/esm/transport/fetch-bridge.js.map +1 -0
  65. package/dist/esm/transport/in-process.d.ts +2 -1
  66. package/dist/esm/transport/in-process.d.ts.map +1 -1
  67. package/dist/esm/transport/in-process.js +4 -2
  68. package/dist/esm/transport/in-process.js.map +1 -1
  69. package/dist/esm/transport/index.d.ts +2 -0
  70. package/dist/esm/transport/index.d.ts.map +1 -1
  71. package/dist/esm/transport/index.js +2 -0
  72. package/dist/esm/transport/index.js.map +1 -1
  73. package/dist/esm/transport/shared/common/constants.d.ts +14 -0
  74. package/dist/esm/transport/shared/common/constants.d.ts.map +1 -0
  75. package/dist/esm/transport/shared/common/constants.js +14 -0
  76. package/dist/esm/transport/shared/common/constants.js.map +1 -0
  77. package/dist/esm/transport/shared/common/index.d.ts +3 -0
  78. package/dist/esm/transport/shared/common/index.d.ts.map +1 -0
  79. package/dist/esm/transport/shared/common/index.js +3 -0
  80. package/dist/esm/transport/shared/common/index.js.map +1 -0
  81. package/dist/esm/transport/shared/common/types.d.ts +35 -0
  82. package/dist/esm/transport/shared/common/types.d.ts.map +1 -0
  83. package/dist/esm/transport/shared/common/types.js +2 -0
  84. package/dist/esm/transport/shared/common/types.js.map +1 -0
  85. package/dist/esm/transport/shared/index.d.ts +4 -0
  86. package/dist/esm/transport/shared/index.d.ts.map +1 -0
  87. package/dist/esm/transport/shared/index.js +6 -0
  88. package/dist/esm/transport/shared/index.js.map +1 -0
  89. package/dist/esm/transport/shared/transport.d.ts +87 -0
  90. package/dist/esm/transport/shared/transport.d.ts.map +1 -0
  91. package/dist/esm/transport/shared/transport.js +379 -0
  92. package/dist/esm/transport/shared/transport.js.map +1 -0
  93. package/dist/esm/transport/worker.d.ts +16 -2
  94. package/dist/esm/transport/worker.d.ts.map +1 -1
  95. package/dist/esm/transport/worker.js +65 -7
  96. package/dist/esm/transport/worker.js.map +1 -1
  97. package/package.json +9 -9
  98. package/dist/cjs/envelope/types.d.ts.map +0 -1
  99. package/dist/esm/envelope/types.d.ts.map +0 -1
  100. /package/dist/cjs/envelope/{types.d.ts → common/types.d.ts} +0 -0
  101. /package/dist/cjs/envelope/{types.js → common/types.js} +0 -0
  102. /package/dist/esm/envelope/{types.d.ts → common/types.d.ts} +0 -0
  103. /package/dist/esm/envelope/{types.js → common/types.js} +0 -0
@@ -0,0 +1,383 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SharedBffTransport = void 0;
4
+ const core_1 = require("@venizia/ignis-helpers/core");
5
+ const encode_1 = require("../../envelope/encode");
6
+ const worker_1 = require("../worker");
7
+ const common_1 = require("./common");
8
+ /**
9
+ * One BFF for every tab of an origin, instead of one per tab.
10
+ *
11
+ * The problem it solves is not a framework limitation, it is a storage one. PGlite in
12
+ * `opfs-ahp://` mode holds an exclusive access handle on the database file, and OPFS access handles
13
+ * are exclusive PER ORIGIN. Measured in Chromium with two tabs of the same page: the first tab
14
+ * works, and the second never boots its database -
15
+ * `Failed to execute 'createSyncAccessHandle' on 'FileSystemFileHandle': Access Handles cannot be
16
+ * created if there is another open Access Handle or Writable stream associated with the same file`.
17
+ * The first tab is unaffected, and closing it lets the second recover on reload - so the failure is
18
+ * contained and self-healing, but the second tab is simply dead until then.
19
+ *
20
+ * So exactly one tab may own the database. This transport elects that tab with the Web Locks API,
21
+ * gives it the Worker, and forwards every other tab's request to it over a `BroadcastChannel`,
22
+ * carried in the same envelope the Worker itself speaks. When the leader's tab closes, the lock is
23
+ * released by the browser and a follower is promoted automatically - no heartbeat, no timeout, no
24
+ * stale-leader window to reason about.
25
+ *
26
+ * A host with no `navigator.locks` runs single-tab, exactly as before. That is not a compromise:
27
+ * measured on a plain-http origin, `navigator.locks` and `navigator.storage.getDirectory` are BOTH
28
+ * undefined, because both are secure-context only. Wherever OPFS works the lock exists, and where it
29
+ * does not the database could not have started either.
30
+ */
31
+ class SharedBffTransport extends core_1.BaseHelper {
32
+ constructor(opts) {
33
+ super({ scope: opts.scope ?? SharedBffTransport.name });
34
+ this.pendingRequests = new Map();
35
+ this.role = common_1.BffRoles.ELECTING;
36
+ this.isClosed = false;
37
+ /** Drops this tab out of the lock QUEUE on close, so a closed transport cannot be promoted. */
38
+ this.leadershipQueueAbort = new AbortController();
39
+ /** Callers parked in `fetch()` while the election is still running. */
40
+ this.roleWaiters = [];
41
+ /**
42
+ * A `BroadcastChannel` never delivers a message to the instance that sent it, so a leader does not
43
+ * hear its own answers and a follower does not hear its own requests. Every tab does hear every
44
+ * OTHER tab, which is why a response is matched by id and silently ignored when it belongs to
45
+ * someone else.
46
+ */
47
+ this.handleChannelMessage = (event) => {
48
+ const message = event.data;
49
+ switch (message?.kind) {
50
+ case common_1.ChannelMessageKinds.REQUEST: {
51
+ if (this.role !== common_1.BffRoles.LEADER) {
52
+ return;
53
+ }
54
+ // `serveAsLeader` answers its own failures on the channel; this catch is for the one case
55
+ // it cannot - the channel itself refusing the message, e.g. a body that will not clone.
56
+ this.serveAsLeader({ envelope: message.envelope }).catch((error) => {
57
+ this.logger
58
+ .for(this.serveAsLeader.name)
59
+ .error('Could not answer a follower at all | id: %s | error: %s', message.envelope.id, error);
60
+ });
61
+ return;
62
+ }
63
+ // Both decodes are guarded. The channel is origin-wide and its name is the application's, not
64
+ // a secret, and version skew is the realistic trigger: a long-lived tab on v1 and a new tab
65
+ // on v2 share the same channel and lock BY DESIGN. An envelope this build cannot read must
66
+ // fail its caller, never leave the promise unsettled for the full timeout.
67
+ case common_1.ChannelMessageKinds.RESPONSE: {
68
+ const pending = this.takePending({ id: message.envelope.id });
69
+ if (!pending) {
70
+ return;
71
+ }
72
+ try {
73
+ pending.resolve(encode_1.BffEnvelope.decodeResponse({ envelope: message.envelope }));
74
+ }
75
+ catch (error) {
76
+ this.logger
77
+ .for(this.handleChannelMessage.name)
78
+ .error('Undecodable response envelope | id: %s | error: %s', message.envelope.id, error);
79
+ pending.reject((0, core_1.getError)({
80
+ message: `[SharedBffTransport] The leader's response could not be decoded | id: ${message.envelope.id}`,
81
+ cause: error,
82
+ }));
83
+ }
84
+ return;
85
+ }
86
+ case common_1.ChannelMessageKinds.ERROR: {
87
+ const pending = this.takePending({ id: message.envelope.id });
88
+ if (!pending) {
89
+ return;
90
+ }
91
+ try {
92
+ pending.reject(encode_1.BffEnvelope.decodeError({ envelope: message.envelope }));
93
+ }
94
+ catch (error) {
95
+ pending.reject((0, core_1.getError)({
96
+ message: `[SharedBffTransport] The leader's error envelope could not be decoded | id: ${message.envelope.id}`,
97
+ cause: error,
98
+ }));
99
+ }
100
+ return;
101
+ }
102
+ default: {
103
+ return;
104
+ }
105
+ }
106
+ };
107
+ const channelName = opts.channelName ?? common_1.DEFAULT_CHANNEL_NAME;
108
+ this.createWorker = opts.createWorker;
109
+ this.timeoutMs = opts.timeoutMs ?? common_1.DEFAULT_TIMEOUT_MS;
110
+ this.lockName = `${channelName}.leader`;
111
+ this.requestIdGenerator = new core_1.RequestIdGenerator({ scope: SharedBffTransport.name });
112
+ // Attached BEFORE the election starts: a tab that becomes leader a moment later must not miss a
113
+ // request a follower posted while it was still deciding.
114
+ this.channel = new BroadcastChannel(channelName);
115
+ this.channel.addEventListener('message', this.handleChannelMessage);
116
+ // A failed election must not leave `fetch()` parked forever waiting for a role that never
117
+ // arrives: this tab falls back to serving itself, which is the pre-election behaviour.
118
+ this.elect().catch((error) => {
119
+ // `close()` aborts the queued lock request, and the rejection that produces is the expected
120
+ // end of the election - not a failure to report.
121
+ if (this.isClosed) {
122
+ return;
123
+ }
124
+ this.logger
125
+ .for(this.elect.name)
126
+ .error('Leader election failed, falling back to single-tab | error: %s', error);
127
+ if (this.role === common_1.BffRoles.ELECTING) {
128
+ this.becomeLeader();
129
+ }
130
+ });
131
+ }
132
+ getRole() {
133
+ return this.role;
134
+ }
135
+ async fetch(opts) {
136
+ if (this.isClosed) {
137
+ throw (0, core_1.getError)({
138
+ message: '[SharedBffTransport] The transport is closed | open a new one to make requests',
139
+ });
140
+ }
141
+ await this.whenRoleSettled();
142
+ // Re-checked AFTER the await: `close()` can land while the election is still running, and
143
+ // posting then reaches a channel that is already closed - the caller would get a raw
144
+ // `DOMException` instead of this error, and a pending entry plus a live timer would be left
145
+ // behind on a transport nothing can settle.
146
+ if (this.isClosed) {
147
+ throw (0, core_1.getError)({
148
+ message: '[SharedBffTransport] The transport is closed | open a new one to make requests',
149
+ });
150
+ }
151
+ if (this.leaderStartupError) {
152
+ throw (0, core_1.getError)({
153
+ message: '[SharedBffTransport] This tab leads but its BFF worker never started | reload the page',
154
+ cause: this.leaderStartupError,
155
+ });
156
+ }
157
+ if (this.role === common_1.BffRoles.LEADER && this.leaderTransport) {
158
+ return this.leaderTransport.fetch(opts);
159
+ }
160
+ return this.fetchViaLeader(opts);
161
+ }
162
+ close() {
163
+ this.isClosed = true;
164
+ // A follower is parked in the lock QUEUE rather than holding anything. Without this it stays
165
+ // queued after close, and the browser would eventually hand leadership to a dead transport -
166
+ // which returns straight away, but only after the tab that could have served was skipped.
167
+ this.leadershipQueueAbort.abort();
168
+ // ORDER IS THE POINT, and it is the opposite of the obvious one. The worker has to be GONE
169
+ // before the lock is released: releasing first promotes another tab, which opens the same OPFS
170
+ // database while this worker still holds the exclusive access handle - the exact failure this
171
+ // transport exists to prevent, reintroduced by its own teardown.
172
+ //
173
+ // `terminate()` is abrupt by design. It is no worse than the tab-close path the browser already
174
+ // takes on every leader, and leaving the worker alive is strictly worse than an abrupt stop.
175
+ this.leaderTransport?.close();
176
+ this.leaderTransport = undefined;
177
+ this.leaderWorker?.terminate();
178
+ this.leaderWorker = undefined;
179
+ // Only now: the next tab may open the database.
180
+ this.releaseLeadership?.();
181
+ this.releaseLeadership = undefined;
182
+ this.channel.removeEventListener('message', this.handleChannelMessage);
183
+ this.channel.close();
184
+ this.rejectAllPending({ reason: 'the transport was closed' });
185
+ this.settleRoleWaiters();
186
+ }
187
+ async elect() {
188
+ const locks = globalThis.navigator?.locks;
189
+ if (!locks) {
190
+ this.logger
191
+ .for(this.elect.name)
192
+ .warn('navigator.locks is unavailable - running single-tab | a second tab cannot open the same OPFS database');
193
+ this.becomeLeader();
194
+ return;
195
+ }
196
+ // `ifAvailable` answers NOW instead of queueing, which is what lets this tab find out it is a
197
+ // follower rather than hanging until the current leader goes away.
198
+ const hasWon = await locks.request(this.lockName, { ifAvailable: true }, async (lock) => {
199
+ if (!lock) {
200
+ return false;
201
+ }
202
+ // Symmetric with the queued branch below, and not defensive padding. A real `LockManager`
203
+ // grants from a queued task - it never runs this callback synchronously inside `request()` -
204
+ // so `close()` can land between the constructor and this line. Without the guard a CLOSED
205
+ // transport starts a worker, reports itself leader, and then holds the lock for the lifetime
206
+ // of the page: `close()` has already read and cleared `releaseLeadership`, so the assignment
207
+ // `heldUntilClosed()` makes below can never be resolved by anything. No other tab is ever
208
+ // promoted, and this one answers nobody - its channel listener is already detached.
209
+ //
210
+ // Returning true, not false: this tab DID hold the lock. Returning releases it immediately,
211
+ // which is exactly what a closed transport should do with it.
212
+ if (this.isClosed) {
213
+ return true;
214
+ }
215
+ this.becomeLeader();
216
+ await this.heldUntilClosed();
217
+ return true;
218
+ });
219
+ if (hasWon || this.isClosed) {
220
+ return;
221
+ }
222
+ this.becomeFollower();
223
+ // Queues behind the current leader. The browser releases its lock when that tab goes away - a
224
+ // crash included - so this resolves without anything having to detect the death.
225
+ await locks.request(this.lockName, { signal: this.leadershipQueueAbort.signal }, async () => {
226
+ if (this.isClosed) {
227
+ return;
228
+ }
229
+ this.logger
230
+ .for(this.elect.name)
231
+ .info('Promoted to leader | previous leader released the lock');
232
+ this.becomeLeader();
233
+ await this.heldUntilClosed();
234
+ });
235
+ }
236
+ becomeLeader() {
237
+ // Anything this tab had in flight was addressed to the leader that just went away. It cannot be
238
+ // replayed - a write may well have been applied - so it is failed explicitly rather than left
239
+ // to run out its timeout under a leader that will never answer it.
240
+ this.rejectAllPending({
241
+ reason: 'the leader serving it went away before this tab was promoted',
242
+ });
243
+ try {
244
+ this.leaderWorker = this.createWorker();
245
+ this.leaderTransport = new worker_1.WorkerBffTransport({
246
+ worker: this.leaderWorker,
247
+ timeoutMs: this.timeoutMs,
248
+ });
249
+ }
250
+ catch (error) {
251
+ // A CSP refusal or a bad worker URL must still SETTLE the role. `whenRoleSettled()` has no
252
+ // timeout of its own and the per-request timer is armed only inside `fetchViaLeader()`, which
253
+ // this tab never reaches - so leaving the role unsettled hangs every caller forever, with no
254
+ // error and no log per request.
255
+ this.leaderStartupError = error;
256
+ this.logger
257
+ .for(this.becomeLeader.name)
258
+ .error('Could not start the BFF worker | error: %s', error);
259
+ }
260
+ this.role = common_1.BffRoles.LEADER;
261
+ this.settleRoleWaiters();
262
+ }
263
+ becomeFollower() {
264
+ this.role = common_1.BffRoles.FOLLOWER;
265
+ this.settleRoleWaiters();
266
+ }
267
+ heldUntilClosed() {
268
+ return new Promise(resolve => {
269
+ this.releaseLeadership = resolve;
270
+ });
271
+ }
272
+ whenRoleSettled() {
273
+ if (this.role !== common_1.BffRoles.ELECTING) {
274
+ return Promise.resolve();
275
+ }
276
+ return new Promise(resolve => {
277
+ this.roleWaiters.push(resolve);
278
+ });
279
+ }
280
+ settleRoleWaiters() {
281
+ const waiters = this.roleWaiters;
282
+ this.roleWaiters = [];
283
+ for (const waiter of waiters) {
284
+ waiter();
285
+ }
286
+ }
287
+ /**
288
+ * The caller's `AbortSignal` is honoured HERE as well as in `WorkerBffTransport`. Without it the
289
+ * same page code behaves differently depending on which tab won the lock: abort works in the
290
+ * leader and silently does nothing in every follower, so a data provider that aborts on unmount
291
+ * leaves promises pending for the full timeout in every tab but one.
292
+ *
293
+ * Aborting settles the CALLER. It does not cancel the leader's work - there is no cancel message,
294
+ * and a write already dispatched cannot be taken back.
295
+ */
296
+ async fetchViaLeader(opts) {
297
+ const { signal } = opts.request;
298
+ if (signal?.aborted) {
299
+ throw this.toAbortError({ signal });
300
+ }
301
+ const id = this.requestIdGenerator.nextId();
302
+ const envelope = await encode_1.BffEnvelope.encodeRequest({
303
+ request: opts.request,
304
+ id,
305
+ url: encode_1.BffEnvelope.toSyntheticUrl({ url: opts.request.url }),
306
+ });
307
+ return new Promise((resolve, reject) => {
308
+ const timer = setTimeout(() => {
309
+ this.takePending({ id })?.reject((0, core_1.getError)({
310
+ message: `[SharedBffTransport] Timed out waiting for the leader tab | id: ${id} | timeoutMs: ${this.timeoutMs}`,
311
+ }));
312
+ }, this.timeoutMs);
313
+ const handleAbort = () => {
314
+ this.takePending({ id })?.reject(this.toAbortError({ signal }));
315
+ };
316
+ signal?.addEventListener('abort', handleAbort);
317
+ this.pendingRequests.set(id, {
318
+ resolve,
319
+ reject,
320
+ release: () => {
321
+ clearTimeout(timer);
322
+ signal?.removeEventListener('abort', handleAbort);
323
+ },
324
+ });
325
+ // Buffering the body took an await, and `addEventListener('abort')` never fires on a signal
326
+ // that aborted before it was attached - without this re-read that window loses the abort.
327
+ if (signal?.aborted) {
328
+ handleAbort();
329
+ return;
330
+ }
331
+ this.channel.postMessage({
332
+ kind: common_1.ChannelMessageKinds.REQUEST,
333
+ envelope,
334
+ });
335
+ });
336
+ }
337
+ /** `signal.reason` first, the way `globalThis.fetch` rejects, so a custom abort reason survives. */
338
+ toAbortError(opts) {
339
+ return (opts.signal?.reason ??
340
+ (0, core_1.getError)({ message: '[SharedBffTransport] The request was aborted by its caller' }));
341
+ }
342
+ takePending(opts) {
343
+ const pending = this.pendingRequests.get(opts.id);
344
+ if (!pending) {
345
+ return undefined;
346
+ }
347
+ this.pendingRequests.delete(opts.id);
348
+ pending.release();
349
+ return pending;
350
+ }
351
+ rejectAllPending(opts) {
352
+ for (const id of [...this.pendingRequests.keys()]) {
353
+ this.takePending({ id })?.reject((0, core_1.getError)({
354
+ message: `[SharedBffTransport] Request abandoned | id: ${id} | reason: ${opts.reason}`,
355
+ }));
356
+ }
357
+ }
358
+ async serveAsLeader(opts) {
359
+ const { envelope } = opts;
360
+ try {
361
+ const response = await this.leaderTransport.fetch({
362
+ request: encode_1.BffEnvelope.decodeRequest({ envelope }),
363
+ });
364
+ this.channel.postMessage({
365
+ kind: common_1.ChannelMessageKinds.RESPONSE,
366
+ envelope: await encode_1.BffEnvelope.encodeResponse({ response, id: envelope.id }),
367
+ });
368
+ }
369
+ catch (error) {
370
+ // The follower gets the failure as a failure, rather than waiting out a timeout that would
371
+ // tell it nothing about what went wrong.
372
+ this.logger
373
+ .for(this.serveAsLeader.name)
374
+ .error('Failed to serve a follower request | id: %s | error: %s', envelope.id, error);
375
+ this.channel.postMessage({
376
+ kind: common_1.ChannelMessageKinds.ERROR,
377
+ envelope: encode_1.BffEnvelope.encodeError({ id: envelope.id, error }),
378
+ });
379
+ }
380
+ }
381
+ }
382
+ exports.SharedBffTransport = SharedBffTransport;
383
+ //# sourceMappingURL=transport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport.js","sourceRoot":"","sources":["../../../../src/transport/shared/transport.ts"],"names":[],"mappings":";;;AAAA,sDAAuF;AACvF,8CAAgD;AAGhD,sCAA+C;AAC/C,qCAAmG;AAQnG;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAa,kBAAmB,SAAQ,iBAAU;IAgChD,YAAY,IAAgC;QAC1C,KAAK,CAAC,EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,IAAI,kBAAkB,CAAC,IAAI,EAAE,CAAC,CAAC;QA3BzC,oBAAe,GAAG,IAAI,GAAG,EAA2B,CAAC;QAE9D,SAAI,GAAa,iBAAQ,CAAC,QAAQ,CAAC;QAEnC,aAAQ,GAAG,KAAK,CAAC;QAgBzB,+FAA+F;QAC9E,yBAAoB,GAAG,IAAI,eAAe,EAAE,CAAC;QAE9D,uEAAuE;QAC/D,gBAAW,GAAsB,EAAE,CAAC;QA0T5C;;;;;WAKG;QACc,yBAAoB,GAAG,CAAC,KAAmB,EAAQ,EAAE;YACpE,MAAM,OAAO,GAAG,KAAK,CAAC,IAAmC,CAAC;YAE1D,QAAQ,OAAO,EAAE,IAAI,EAAE,CAAC;gBACtB,KAAK,4BAAmB,CAAC,OAAO,CAAC,CAAC,CAAC;oBACjC,IAAI,IAAI,CAAC,IAAI,KAAK,iBAAQ,CAAC,MAAM,EAAE,CAAC;wBAClC,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Helper implements IBffTransp
15
15
  private readonly timeoutMs;
16
16
  private readonly requestIdGenerator;
17
17
  private readonly pendingRequests;
18
+ /** Set by `close()`, so a later `fetch()` is refused instead of reaching a worker nothing listens to. */
19
+ private isClosed;
20
+ /** Outstanding `handleWorkerError` grace timers, cleared by `close()` so none outlives the transport. */
21
+ private readonly graceTimers;
18
22
  constructor(opts: {
19
23
  worker: Worker;
20
24
  timeoutMs?: number;
@@ -23,10 +27,20 @@ export declare class WorkerBffTransport extends BaseHelper implements IBffTransp
23
27
  private readonly takePending;
24
28
  private readonly handleMessage;
25
29
  /**
26
- * A dead or crashed worker never posts anything back, so every in-flight request is lost - this
27
- * is the one event that legitimately settles all of them, instead of leaving each to time out.
30
+ * An `error` event does NOT mean the worker is dead.
31
+ *
32
+ * Measured in Chromium: a synchronous uncaught throw anywhere in the worker - a third-party timer,
33
+ * say - fires this event while the worker keeps serving, and the genuine responses to the
34
+ * in-flight requests arrive a moment later. Rejecting immediately reported a committed POST as
35
+ * failed and then dropped its real 200 on the floor, because nothing was left waiting for it.
36
+ *
37
+ * So the event is logged at once and the requests are given a grace window. Whatever the worker
38
+ * still answers inside it settles normally; whatever is left after it really is lost, and is
39
+ * rejected with the diagnostics rather than left to run out its own timeout.
28
40
  */
29
41
  private readonly handleWorkerError;
42
+ /** `ErrorEvent` carries the useful fields; a plain `Event` does not, so both shapes are handled. */
43
+ private describeErrorEvent;
30
44
  /**
31
45
  * `messageerror` means exactly ONE posted message failed to deserialise, and the event carries
32
46
  * nothing that says which. With a single request in flight that is unambiguous, so it settles
@@ -1 +1 @@
1
- {"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../../../src/transport/worker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAY,MAAM,6BAA6B,CAAC;AAInE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAiBpD;;;;;;;;;GASG;AACH,qBAAa,kBAAmB,SAAQ,UAAW,YAAW,aAAa;IACz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E;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE;IAWxD,wHAAwH;IACxH,OAAO,CAAC,QAAQ,CAAC,WAAW,CAS1B;IAEF,OAAO,CAAC,QAAQ,CAAC,aAAa,CAgC5B;IAEF;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CA+BhC;IAEF,oGAAoG;IACpG,OAAO,CAAC,kBAAkB;IAe1B;;;;;OAKG;IACH,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAkBjC;IAEI,KAAK,CAAC,IAAI,EAAE;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,GAAG,OAAO,CAAC,QAAQ,CAAC;IA0E1D,2HAA2H;IAC3H,OAAO,CAAC,YAAY;IAOpB;;;OAGG;IACH,KAAK,IAAI,IAAI;CAmBd"}
@@ -5,6 +5,8 @@ const core_1 = require("@venizia/ignis-helpers/core");
5
5
  const core_2 = require("@venizia/ignis-helpers/core");
6
6
  const encode_1 = require("../envelope/encode");
7
7
  const DEFAULT_TIMEOUT_MS = 30_000;
8
+ /** How long a still-serving worker gets to answer after it reports an error - see `handleWorkerError`. */
9
+ const WORKER_ERROR_GRACE_MS = 250;
8
10
  const isErrorEnvelope = (data) => {
9
11
  return 'error' in data;
10
12
  };
@@ -25,6 +27,10 @@ class WorkerBffTransport extends core_1.BaseHelper {
25
27
  scope: WorkerBffTransport.name,
26
28
  });
27
29
  this.pendingRequests = new Map();
30
+ /** Set by `close()`, so a later `fetch()` is refused instead of reaching a worker nothing listens to. */
31
+ this.isClosed = false;
32
+ /** Outstanding `handleWorkerError` grace timers, cleared by `close()` so none outlives the transport. */
33
+ this.graceTimers = new Set();
28
34
  /** Removes a pending request from the map and releases its timer and abort listener, so nothing can settle it twice. */
29
35
  this.takePending = (opts) => {
30
36
  const pending = this.pendingRequests.get(opts.id);
@@ -65,15 +71,37 @@ class WorkerBffTransport extends core_1.BaseHelper {
65
71
  }
66
72
  };
67
73
  /**
68
- * A dead or crashed worker never posts anything back, so every in-flight request is lost - this
69
- * is the one event that legitimately settles all of them, instead of leaving each to time out.
74
+ * An `error` event does NOT mean the worker is dead.
75
+ *
76
+ * Measured in Chromium: a synchronous uncaught throw anywhere in the worker - a third-party timer,
77
+ * say - fires this event while the worker keeps serving, and the genuine responses to the
78
+ * in-flight requests arrive a moment later. Rejecting immediately reported a committed POST as
79
+ * failed and then dropped its real 200 on the floor, because nothing was left waiting for it.
80
+ *
81
+ * So the event is logged at once and the requests are given a grace window. Whatever the worker
82
+ * still answers inside it settles normally; whatever is left after it really is lost, and is
83
+ * rejected with the diagnostics rather than left to run out its own timeout.
70
84
  */
71
85
  this.handleWorkerError = (event) => {
72
- for (const id of [...this.pendingRequests.keys()]) {
73
- this.takePending({ id })?.reject((0, core_1.getError)({
74
- message: `[WorkerBffTransport] Worker failed while awaiting a response | id: ${id} | event: ${String(event)}`,
75
- }));
76
- }
86
+ // `String(event)` is always `[object ErrorEvent]` - it says nothing. Read the fields a browser
87
+ // actually populates, so the log names the file and line that failed.
88
+ const detail = this.describeErrorEvent(event);
89
+ this.logger
90
+ .for('handleWorkerError')
91
+ .error('Worker reported an error | pending: %s | detail: %s', this.pendingRequests.size, detail);
92
+ const affected = [...this.pendingRequests.keys()];
93
+ // Held so `close()` can clear it. A grace timer that outlives the transport keeps the process
94
+ // (or a test runner) awake and fires against a map nobody is watching any more.
95
+ const timer = setTimeout(() => {
96
+ this.graceTimers.delete(timer);
97
+ for (const id of affected) {
98
+ // `takePending` answers undefined for anything the worker managed to settle in the window.
99
+ this.takePending({ id })?.reject((0, core_1.getError)({
100
+ message: `[WorkerBffTransport] Worker failed while awaiting a response | id: ${id} | detail: ${detail}`,
101
+ }));
102
+ }
103
+ }, WORKER_ERROR_GRACE_MS);
104
+ this.graceTimers.add(timer);
77
105
  };
78
106
  /**
79
107
  * `messageerror` means exactly ONE posted message failed to deserialise, and the event carries
@@ -99,9 +127,25 @@ class WorkerBffTransport extends core_1.BaseHelper {
99
127
  this.worker.addEventListener('error', this.handleWorkerError);
100
128
  this.worker.addEventListener('messageerror', this.handleMessageError);
101
129
  }
130
+ /** `ErrorEvent` carries the useful fields; a plain `Event` does not, so both shapes are handled. */
131
+ describeErrorEvent(event) {
132
+ const candidate = event;
133
+ if (!candidate.message) {
134
+ return event.type;
135
+ }
136
+ return `${candidate.message} (${candidate.filename ?? 'unknown'}:${candidate.lineno ?? 0}:${candidate.colno ?? 0})`;
137
+ }
102
138
  async fetch(opts) {
103
139
  const { request } = opts;
104
140
  const { signal } = request;
141
+ // Refused, not queued. `close()` detaches the message listener, so a request posted after it
142
+ // still reached the worker - which EXECUTED it, writes included - while the answer had nowhere
143
+ // to land and the caller waited out the full timeout.
144
+ if (this.isClosed) {
145
+ throw (0, core_1.getError)({
146
+ message: '[WorkerBffTransport] The transport is closed | open a new one to make requests',
147
+ });
148
+ }
105
149
  if (signal?.aborted) {
106
150
  throw this.toAbortError({ signal });
107
151
  }
@@ -138,6 +182,15 @@ class WorkerBffTransport extends core_1.BaseHelper {
138
182
  handleAbort();
139
183
  return;
140
184
  }
185
+ // `close()` can land during that same await. The entry guard above is then stale, and posting
186
+ // reaches a worker that EXECUTES the request - writes included - while the answer has nowhere
187
+ // to land, because `close()` already detached the listener.
188
+ if (this.isClosed) {
189
+ this.takePending({ id })?.reject((0, core_1.getError)({
190
+ message: `[WorkerBffTransport] The transport closed while the request was being encoded | id: ${id}`,
191
+ }));
192
+ return;
193
+ }
141
194
  this.worker.postMessage(requestEnvelope, requestEnvelope.body ? [requestEnvelope.body] : []);
142
195
  });
143
196
  }
@@ -151,6 +204,11 @@ class WorkerBffTransport extends core_1.BaseHelper {
151
204
  * left alone - this transport did not create it, and a page may hand the same one to another.
152
205
  */
153
206
  close() {
207
+ this.isClosed = true;
208
+ for (const timer of this.graceTimers) {
209
+ clearTimeout(timer);
210
+ }
211
+ this.graceTimers.clear();
154
212
  this.worker.removeEventListener('message', this.handleMessage);
155
213
  this.worker.removeEventListener('error', this.handleWorkerError);
156
214
  this.worker.removeEventListener('messageerror', this.handleMessageError);
@@ -1 +1 @@
1
- {"version":3,"file":"worker.js","sourceRoot":"","sources":["../../../src/transport/worker.ts"],"names":[],"mappings":";;;AAAA,sDAAmE;AACnE,sDAAiE;AACjE,8CAAgD;AAIhD,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAElC,MAAM,eAAe,GAAG,CACtB,IAA8C,EACnB,EAAE;IAC7B,OAAO,OAAO,IAAI,IAAI,CAAC;AACzB,CAAC,CAAC;AASF;;;;;;;;;GASG;AACH,MAAa,kBAAmB,SAAQ,iBAAU;IAQhD,YAAY,IAA4C;QACtD,KAAK,CAAC,EAAE,KAAK,EAAE,kBAAkB,CAAC,IAAI,EAAE,CAAC,CAAC;QAN3B,uBAAkB,GAAG,IAAI,yBAAkB,CAAC;YAC3D,KAAK,EAAE,kBAAkB,CAAC,IAAI;SAC/B,CAAC,CAAC;QACc,oBAAe,GAAG,IAAI,GAAG,EAA2B,CAAC;QAatE,wHAAwH;QACvG,gBAAW,GAAG,CAAC,IAAoB,EAA+B,EAAE;YACnF,MAAM,OAAO,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAClD,IAAI,CAAC,OAAO,EAAE,CAAC;gBACb,OAAO,SAAS,CAAC;YACnB,CAAC;YAED,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YACrC,OAAO,CAAC,OAAO,EAAE,CAAC;YAClB,OAAO,OAAO,CAAC;QACjB,CAAC,CAAC;QAEe,kBAAa,GAAG,CAAC,KAAmB,EAAQ,EAAE;YAC7D,iGAAiG;YACjG,6FAA6F;YAC7F,2BAA2B;YAC3B,MAAM,IAAI,GAAG,KAAK,CAAC,IAA4D,CAAC;YAChF,IAAI,CAAC,IAAI,EAAE,EAAE,EAAE,CAAC;gBACd,OAAO;YACT,CAAC;YAED,MAAM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/F,CAAC,CAAC,CAAC;IACL,CAAC;IAED,2HAA2H;IACnH,YAAY,CAAC,IAA8B;QACjD,OAAO,CACL,IAAI,CAAC,MAAM,EAAE,MAAM;YACnB,IAAA,eAAQ,EAAC,EAAE,OAAO,EAAE,4DAA4D,EAAE,CAAC,CACpF,CAAC;IACJ,CAAC;IAED;;;OAGG;IACH,KAAK;QACH,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QAErB,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACrC,YAAY,CAAC,KAAK,CAAC,CAAC;QACtB,CAAC;QACD,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;QACzB,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC;QAC/D,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC;QACjE,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC,cAAc,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC;QAEzE,KAAK,MAAM,EAAE,IAAI,CAAC,GAAG,IAAI,CAAC,eAAe,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC;YAClD,IAAI,CAAC,WAAW,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,MAAM,CAC9B,IAAA,eAAQ,EAAC;gBACP,OAAO,EAAE,iFAAiF,EAAE,EAAE;aAC/F,CAAC,CACH,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AAvQD,gDAuQC"}
@@ -0,0 +1,2 @@
1
+ export * from './types.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/envelope/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './types.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/envelope/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/envelope/common/types.ts"],"names":[],"mappings":"AAAA,uFAAuF;AACvF,MAAM,MAAM,gBAAgB,GAAG,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAEvD,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,gBAAgB,CAAC;IAC1B,+EAA+E;IAC/E,IAAI,CAAC,EAAE,WAAW,CAAC;CACpB;AAED,MAAM,WAAW,oBAAoB;IACnC,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,gBAAgB,CAAC;IAC1B,IAAI,CAAC,EAAE,WAAW,CAAC;CACpB;AAED;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX;;;;OAIG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;CACxD"}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/envelope/types.ts"],"names":[],"mappings":""}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/envelope/common/types.ts"],"names":[],"mappings":""}
@@ -1,5 +1,5 @@
1
1
  import type { ApplicationError } from '@venizia/ignis-helpers/core';
2
- import type { IBffErrorEnvelope, IBffRequestEnvelope, IBffResponseEnvelope } from './types.js';
2
+ import type { IBffErrorEnvelope, IBffRequestEnvelope, IBffResponseEnvelope } from './common/index.js';
3
3
  /**
4
4
  * Every request built inside the Worker uses this origin. Never `self.location.href`: a `blob:`
5
5
  * worker origin is opaque and `new URL(path, blobUrl)` throws, and Hono's `getPath()` mis-parses
@@ -1 +1 @@
1
- {"version":3,"file":"encode.d.ts","sourceRoot":"","sources":["../../../src/envelope/encode.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAGpE,OAAO,KAAK,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAE5F;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,0BAA0B,CAAC;AAE5D,+IAA+I;AAC/I,qBAAa,WAAW;IACtB;;;OAGG;IACH,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,kBAAkB,CAA4B;IAEtE;;;;OAIG;IACH,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,MAAM;IAKpD;;;;;OAKG;WACU,aAAa,CAAC,IAAI,EAAE;QAC/B,OAAO,EAAE,OAAO,CAAC;QACjB,EAAE,EAAE,MAAM,CAAC;QACX,GAAG,CAAC,EAAE,MAAM,CAAC;KACd,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAahC,MAAM,CAAC,aAAa,CAAC,IAAI,EAAE;QAAE,QAAQ,EAAE,mBAAmB,CAAA;KAAE,GAAG,OAAO;WAUzD,cAAc,CAAC,IAAI,EAAE;QAChC,QAAQ,EAAE,QAAQ,CAAC;QACnB,EAAE,EAAE,MAAM,CAAC;KACZ,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAajC,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE;QAAE,QAAQ,EAAE,oBAAoB,CAAA;KAAE,GAAG,QAAQ;IAazE;;;;;;;OAOG;IACH,MAAM,CAAC,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