@venizia/ignis-worker 0.2.0-10

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 (105) hide show
  1. package/dist/cjs/applications/index.d.ts +2 -0
  2. package/dist/cjs/applications/index.d.ts.map +1 -0
  3. package/dist/cjs/applications/index.js +18 -0
  4. package/dist/cjs/applications/index.js.map +1 -0
  5. package/dist/cjs/applications/worker.d.ts +67 -0
  6. package/dist/cjs/applications/worker.d.ts.map +1 -0
  7. package/dist/cjs/applications/worker.js +175 -0
  8. package/dist/cjs/applications/worker.js.map +1 -0
  9. package/dist/cjs/envelope/encode.d.ts +61 -0
  10. package/dist/cjs/envelope/encode.d.ts.map +1 -0
  11. package/dist/cjs/envelope/encode.js +116 -0
  12. package/dist/cjs/envelope/encode.js.map +1 -0
  13. package/dist/cjs/envelope/index.d.ts +3 -0
  14. package/dist/cjs/envelope/index.d.ts.map +1 -0
  15. package/dist/cjs/envelope/index.js +19 -0
  16. package/dist/cjs/envelope/index.js.map +1 -0
  17. package/dist/cjs/envelope/types.d.ts +37 -0
  18. package/dist/cjs/envelope/types.d.ts.map +1 -0
  19. package/dist/cjs/envelope/types.js +3 -0
  20. package/dist/cjs/envelope/types.js.map +1 -0
  21. package/dist/cjs/index.d.ts +5 -0
  22. package/dist/cjs/index.d.ts.map +1 -0
  23. package/dist/cjs/index.js +21 -0
  24. package/dist/cjs/index.js.map +1 -0
  25. package/dist/cjs/transport/common/index.d.ts +2 -0
  26. package/dist/cjs/transport/common/index.d.ts.map +1 -0
  27. package/dist/cjs/transport/common/index.js +18 -0
  28. package/dist/cjs/transport/common/index.js.map +1 -0
  29. package/dist/cjs/transport/common/types.d.ts +6 -0
  30. package/dist/cjs/transport/common/types.d.ts.map +1 -0
  31. package/dist/cjs/transport/common/types.js +3 -0
  32. package/dist/cjs/transport/common/types.js.map +1 -0
  33. package/dist/cjs/transport/fetch-bridge.d.ts +35 -0
  34. package/dist/cjs/transport/fetch-bridge.d.ts.map +1 -0
  35. package/dist/cjs/transport/fetch-bridge.js +95 -0
  36. package/dist/cjs/transport/fetch-bridge.js.map +1 -0
  37. package/dist/cjs/transport/in-process.d.ts +23 -0
  38. package/dist/cjs/transport/in-process.d.ts.map +1 -0
  39. package/dist/cjs/transport/in-process.js +47 -0
  40. package/dist/cjs/transport/in-process.js.map +1 -0
  41. package/dist/cjs/transport/index.d.ts +6 -0
  42. package/dist/cjs/transport/index.d.ts.map +1 -0
  43. package/dist/cjs/transport/index.js +22 -0
  44. package/dist/cjs/transport/index.js.map +1 -0
  45. package/dist/cjs/transport/shared.d.ts +102 -0
  46. package/dist/cjs/transport/shared.d.ts.map +1 -0
  47. package/dist/cjs/transport/shared.js +396 -0
  48. package/dist/cjs/transport/shared.js.map +1 -0
  49. package/dist/cjs/transport/worker.d.ts +62 -0
  50. package/dist/cjs/transport/worker.d.ts.map +1 -0
  51. package/dist/cjs/transport/worker.js +223 -0
  52. package/dist/cjs/transport/worker.js.map +1 -0
  53. package/dist/esm/applications/index.d.ts +2 -0
  54. package/dist/esm/applications/index.d.ts.map +1 -0
  55. package/dist/esm/applications/index.js +2 -0
  56. package/dist/esm/applications/index.js.map +1 -0
  57. package/dist/esm/applications/worker.d.ts +67 -0
  58. package/dist/esm/applications/worker.d.ts.map +1 -0
  59. package/dist/esm/applications/worker.js +171 -0
  60. package/dist/esm/applications/worker.js.map +1 -0
  61. package/dist/esm/envelope/encode.d.ts +61 -0
  62. package/dist/esm/envelope/encode.d.ts.map +1 -0
  63. package/dist/esm/envelope/encode.js +112 -0
  64. package/dist/esm/envelope/encode.js.map +1 -0
  65. package/dist/esm/envelope/index.d.ts +3 -0
  66. package/dist/esm/envelope/index.d.ts.map +1 -0
  67. package/dist/esm/envelope/index.js +3 -0
  68. package/dist/esm/envelope/index.js.map +1 -0
  69. package/dist/esm/envelope/types.d.ts +37 -0
  70. package/dist/esm/envelope/types.d.ts.map +1 -0
  71. package/dist/esm/envelope/types.js +2 -0
  72. package/dist/esm/envelope/types.js.map +1 -0
  73. package/dist/esm/index.d.ts +5 -0
  74. package/dist/esm/index.d.ts.map +1 -0
  75. package/dist/esm/index.js +5 -0
  76. package/dist/esm/index.js.map +1 -0
  77. package/dist/esm/transport/common/index.d.ts +2 -0
  78. package/dist/esm/transport/common/index.d.ts.map +1 -0
  79. package/dist/esm/transport/common/index.js +2 -0
  80. package/dist/esm/transport/common/index.js.map +1 -0
  81. package/dist/esm/transport/common/types.d.ts +6 -0
  82. package/dist/esm/transport/common/types.d.ts.map +1 -0
  83. package/dist/esm/transport/common/types.js +2 -0
  84. package/dist/esm/transport/common/types.js.map +1 -0
  85. package/dist/esm/transport/fetch-bridge.d.ts +35 -0
  86. package/dist/esm/transport/fetch-bridge.d.ts.map +1 -0
  87. package/dist/esm/transport/fetch-bridge.js +91 -0
  88. package/dist/esm/transport/fetch-bridge.js.map +1 -0
  89. package/dist/esm/transport/in-process.d.ts +23 -0
  90. package/dist/esm/transport/in-process.d.ts.map +1 -0
  91. package/dist/esm/transport/in-process.js +43 -0
  92. package/dist/esm/transport/in-process.js.map +1 -0
  93. package/dist/esm/transport/index.d.ts +6 -0
  94. package/dist/esm/transport/index.d.ts.map +1 -0
  95. package/dist/esm/transport/index.js +6 -0
  96. package/dist/esm/transport/index.js.map +1 -0
  97. package/dist/esm/transport/shared.d.ts +102 -0
  98. package/dist/esm/transport/shared.d.ts.map +1 -0
  99. package/dist/esm/transport/shared.js +391 -0
  100. package/dist/esm/transport/shared.js.map +1 -0
  101. package/dist/esm/transport/worker.d.ts +62 -0
  102. package/dist/esm/transport/worker.d.ts.map +1 -0
  103. package/dist/esm/transport/worker.js +219 -0
  104. package/dist/esm/transport/worker.js.map +1 -0
  105. package/package.json +94 -0
@@ -0,0 +1,391 @@
1
+ import { BaseHelper, getError, RequestIdGenerator } from '@venizia/ignis-helpers/core';
2
+ import { BffEnvelope } from '../envelope/encode.js';
3
+ import { WorkerBffTransport } from './worker.js';
4
+ const DEFAULT_CHANNEL_NAME = 'ignis.bff';
5
+ const DEFAULT_TIMEOUT_MS = 30_000;
6
+ /** Which part this tab plays. `ELECTING` is the brief window before the lock answers. */
7
+ export class BffRoles {
8
+ static { this.ELECTING = 'electing'; }
9
+ static { this.LEADER = 'leader'; }
10
+ static { this.FOLLOWER = 'follower'; }
11
+ }
12
+ class ChannelMessageKinds {
13
+ static { this.REQUEST = 'ignis.bff.request'; }
14
+ static { this.RESPONSE = 'ignis.bff.response'; }
15
+ static { this.ERROR = 'ignis.bff.error'; }
16
+ }
17
+ /**
18
+ * One BFF for every tab of an origin, instead of one per tab.
19
+ *
20
+ * The problem it solves is not a framework limitation, it is a storage one. PGlite in
21
+ * `opfs-ahp://` mode holds an exclusive access handle on the database file, and OPFS access handles
22
+ * are exclusive PER ORIGIN. Measured in Chromium with two tabs of the same page: the first tab
23
+ * works, and the second never boots its database -
24
+ * `Failed to execute 'createSyncAccessHandle' on 'FileSystemFileHandle': Access Handles cannot be
25
+ * created if there is another open Access Handle or Writable stream associated with the same file`.
26
+ * The first tab is unaffected, and closing it lets the second recover on reload - so the failure is
27
+ * contained and self-healing, but the second tab is simply dead until then.
28
+ *
29
+ * So exactly one tab may own the database. This transport elects that tab with the Web Locks API,
30
+ * gives it the Worker, and forwards every other tab's request to it over a `BroadcastChannel`,
31
+ * carried in the same envelope the Worker itself speaks. When the leader's tab closes, the lock is
32
+ * released by the browser and a follower is promoted automatically - no heartbeat, no timeout, no
33
+ * stale-leader window to reason about.
34
+ *
35
+ * A host with no `navigator.locks` runs single-tab, exactly as before. That is not a compromise:
36
+ * measured on a plain-http origin, `navigator.locks` and `navigator.storage.getDirectory` are BOTH
37
+ * undefined, because both are secure-context only. Wherever OPFS works the lock exists, and where it
38
+ * does not the database could not have started either.
39
+ */
40
+ export class SharedBffTransport extends BaseHelper {
41
+ constructor(opts) {
42
+ super({ scope: opts.scope ?? SharedBffTransport.name });
43
+ this.pendingRequests = new Map();
44
+ this.role = BffRoles.ELECTING;
45
+ this.isClosed = false;
46
+ /** Drops this tab out of the lock QUEUE on close, so a closed transport cannot be promoted. */
47
+ this.leadershipQueueAbort = new AbortController();
48
+ /** Callers parked in `fetch()` while the election is still running. */
49
+ this.roleWaiters = [];
50
+ /**
51
+ * A `BroadcastChannel` never delivers a message to the instance that sent it, so a leader does not
52
+ * hear its own answers and a follower does not hear its own requests. Every tab does hear every
53
+ * OTHER tab, which is why a response is matched by id and silently ignored when it belongs to
54
+ * someone else.
55
+ */
56
+ this.handleChannelMessage = (event) => {
57
+ const message = event.data;
58
+ switch (message?.kind) {
59
+ case ChannelMessageKinds.REQUEST: {
60
+ if (this.role !== BffRoles.LEADER) {
61
+ return;
62
+ }
63
+ // `serveAsLeader` answers its own failures on the channel; this catch is for the one case
64
+ // it cannot - the channel itself refusing the message, e.g. a body that will not clone.
65
+ this.serveAsLeader({ envelope: message.envelope }).catch((error) => {
66
+ this.logger
67
+ .for(this.serveAsLeader.name)
68
+ .error('Could not answer a follower at all | id: %s | error: %s', message.envelope.id, error);
69
+ });
70
+ return;
71
+ }
72
+ // Both decodes are guarded. The channel is origin-wide and its name is the application's, not
73
+ // a secret, and version skew is the realistic trigger: a long-lived tab on v1 and a new tab
74
+ // on v2 share the same channel and lock BY DESIGN. An envelope this build cannot read must
75
+ // fail its caller, never leave the promise unsettled for the full timeout.
76
+ case ChannelMessageKinds.RESPONSE: {
77
+ const pending = this.takePending({ id: message.envelope.id });
78
+ if (!pending) {
79
+ return;
80
+ }
81
+ try {
82
+ pending.resolve(BffEnvelope.decodeResponse({ envelope: message.envelope }));
83
+ }
84
+ catch (error) {
85
+ this.logger
86
+ .for(this.handleChannelMessage.name)
87
+ .error('Undecodable response envelope | id: %s | error: %s', message.envelope.id, error);
88
+ pending.reject(getError({
89
+ message: `[SharedBffTransport] The leader's response could not be decoded | id: ${message.envelope.id}`,
90
+ cause: error,
91
+ }));
92
+ }
93
+ return;
94
+ }
95
+ case ChannelMessageKinds.ERROR: {
96
+ const pending = this.takePending({ id: message.envelope.id });
97
+ if (!pending) {
98
+ return;
99
+ }
100
+ try {
101
+ pending.reject(BffEnvelope.decodeError({ envelope: message.envelope }));
102
+ }
103
+ catch (error) {
104
+ pending.reject(getError({
105
+ message: `[SharedBffTransport] The leader's error envelope could not be decoded | id: ${message.envelope.id}`,
106
+ cause: error,
107
+ }));
108
+ }
109
+ return;
110
+ }
111
+ default: {
112
+ return;
113
+ }
114
+ }
115
+ };
116
+ const channelName = opts.channelName ?? DEFAULT_CHANNEL_NAME;
117
+ this.createWorker = opts.createWorker;
118
+ this.timeoutMs = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS;
119
+ this.lockName = `${channelName}.leader`;
120
+ this.requestIdGenerator = new RequestIdGenerator({ scope: SharedBffTransport.name });
121
+ // Attached BEFORE the election starts: a tab that becomes leader a moment later must not miss a
122
+ // request a follower posted while it was still deciding.
123
+ this.channel = new BroadcastChannel(channelName);
124
+ this.channel.addEventListener('message', this.handleChannelMessage);
125
+ // A failed election must not leave `fetch()` parked forever waiting for a role that never
126
+ // arrives: this tab falls back to serving itself, which is the pre-election behaviour.
127
+ this.elect().catch((error) => {
128
+ // `close()` aborts the queued lock request, and the rejection that produces is the expected
129
+ // end of the election - not a failure to report.
130
+ if (this.isClosed) {
131
+ return;
132
+ }
133
+ this.logger
134
+ .for(this.elect.name)
135
+ .error('Leader election failed, falling back to single-tab | error: %s', error);
136
+ if (this.role === BffRoles.ELECTING) {
137
+ this.becomeLeader();
138
+ }
139
+ });
140
+ }
141
+ getRole() {
142
+ return this.role;
143
+ }
144
+ async fetch(opts) {
145
+ if (this.isClosed) {
146
+ throw getError({
147
+ message: '[SharedBffTransport] The transport is closed | open a new one to make requests',
148
+ });
149
+ }
150
+ await this.whenRoleSettled();
151
+ // Re-checked AFTER the await: `close()` can land while the election is still running, and
152
+ // posting then reaches a channel that is already closed - the caller would get a raw
153
+ // `DOMException` instead of this error, and a pending entry plus a live timer would be left
154
+ // behind on a transport nothing can settle.
155
+ if (this.isClosed) {
156
+ throw getError({
157
+ message: '[SharedBffTransport] The transport is closed | open a new one to make requests',
158
+ });
159
+ }
160
+ if (this.leaderStartupError) {
161
+ throw getError({
162
+ message: '[SharedBffTransport] This tab leads but its BFF worker never started | reload the page',
163
+ cause: this.leaderStartupError,
164
+ });
165
+ }
166
+ if (this.role === BffRoles.LEADER && this.leaderTransport) {
167
+ return this.leaderTransport.fetch(opts);
168
+ }
169
+ return this.fetchViaLeader(opts);
170
+ }
171
+ close() {
172
+ this.isClosed = true;
173
+ // A follower is parked in the lock QUEUE rather than holding anything. Without this it stays
174
+ // queued after close, and the browser would eventually hand leadership to a dead transport -
175
+ // which returns straight away, but only after the tab that could have served was skipped.
176
+ this.leadershipQueueAbort.abort();
177
+ // ORDER IS THE POINT, and it is the opposite of the obvious one. The worker has to be GONE
178
+ // before the lock is released: releasing first promotes another tab, which opens the same OPFS
179
+ // database while this worker still holds the exclusive access handle - the exact failure this
180
+ // transport exists to prevent, reintroduced by its own teardown.
181
+ //
182
+ // `terminate()` is abrupt by design. It is no worse than the tab-close path the browser already
183
+ // takes on every leader, and leaving the worker alive is strictly worse than an abrupt stop.
184
+ this.leaderTransport?.close();
185
+ this.leaderTransport = undefined;
186
+ this.leaderWorker?.terminate();
187
+ this.leaderWorker = undefined;
188
+ // Only now: the next tab may open the database.
189
+ this.releaseLeadership?.();
190
+ this.releaseLeadership = undefined;
191
+ this.channel.removeEventListener('message', this.handleChannelMessage);
192
+ this.channel.close();
193
+ this.rejectAllPending({ reason: 'the transport was closed' });
194
+ this.settleRoleWaiters();
195
+ }
196
+ async elect() {
197
+ const locks = globalThis.navigator?.locks;
198
+ if (!locks) {
199
+ this.logger
200
+ .for(this.elect.name)
201
+ .warn('navigator.locks is unavailable - running single-tab | a second tab cannot open the same OPFS database');
202
+ this.becomeLeader();
203
+ return;
204
+ }
205
+ // `ifAvailable` answers NOW instead of queueing, which is what lets this tab find out it is a
206
+ // follower rather than hanging until the current leader goes away.
207
+ const hasWon = await locks.request(this.lockName, { ifAvailable: true }, async (lock) => {
208
+ if (!lock) {
209
+ return false;
210
+ }
211
+ // Symmetric with the queued branch below, and not defensive padding. A real `LockManager`
212
+ // grants from a queued task - it never runs this callback synchronously inside `request()` -
213
+ // so `close()` can land between the constructor and this line. Without the guard a CLOSED
214
+ // transport starts a worker, reports itself leader, and then holds the lock for the lifetime
215
+ // of the page: `close()` has already read and cleared `releaseLeadership`, so the assignment
216
+ // `heldUntilClosed()` makes below can never be resolved by anything. No other tab is ever
217
+ // promoted, and this one answers nobody - its channel listener is already detached.
218
+ //
219
+ // Returning true, not false: this tab DID hold the lock. Returning releases it immediately,
220
+ // which is exactly what a closed transport should do with it.
221
+ if (this.isClosed) {
222
+ return true;
223
+ }
224
+ this.becomeLeader();
225
+ await this.heldUntilClosed();
226
+ return true;
227
+ });
228
+ if (hasWon || this.isClosed) {
229
+ return;
230
+ }
231
+ this.becomeFollower();
232
+ // Queues behind the current leader. The browser releases its lock when that tab goes away - a
233
+ // crash included - so this resolves without anything having to detect the death.
234
+ await locks.request(this.lockName, { signal: this.leadershipQueueAbort.signal }, async () => {
235
+ if (this.isClosed) {
236
+ return;
237
+ }
238
+ this.logger
239
+ .for(this.elect.name)
240
+ .info('Promoted to leader | previous leader released the lock');
241
+ this.becomeLeader();
242
+ await this.heldUntilClosed();
243
+ });
244
+ }
245
+ becomeLeader() {
246
+ // Anything this tab had in flight was addressed to the leader that just went away. It cannot be
247
+ // replayed - a write may well have been applied - so it is failed explicitly rather than left
248
+ // to run out its timeout under a leader that will never answer it.
249
+ this.rejectAllPending({
250
+ reason: 'the leader serving it went away before this tab was promoted',
251
+ });
252
+ try {
253
+ this.leaderWorker = this.createWorker();
254
+ this.leaderTransport = new WorkerBffTransport({
255
+ worker: this.leaderWorker,
256
+ timeoutMs: this.timeoutMs,
257
+ });
258
+ }
259
+ catch (error) {
260
+ // A CSP refusal or a bad worker URL must still SETTLE the role. `whenRoleSettled()` has no
261
+ // timeout of its own and the per-request timer is armed only inside `fetchViaLeader()`, which
262
+ // this tab never reaches - so leaving the role unsettled hangs every caller forever, with no
263
+ // error and no log per request.
264
+ this.leaderStartupError = error;
265
+ this.logger
266
+ .for(this.becomeLeader.name)
267
+ .error('Could not start the BFF worker | error: %s', error);
268
+ }
269
+ this.role = BffRoles.LEADER;
270
+ this.settleRoleWaiters();
271
+ }
272
+ becomeFollower() {
273
+ this.role = BffRoles.FOLLOWER;
274
+ this.settleRoleWaiters();
275
+ }
276
+ heldUntilClosed() {
277
+ return new Promise(resolve => {
278
+ this.releaseLeadership = resolve;
279
+ });
280
+ }
281
+ whenRoleSettled() {
282
+ if (this.role !== BffRoles.ELECTING) {
283
+ return Promise.resolve();
284
+ }
285
+ return new Promise(resolve => {
286
+ this.roleWaiters.push(resolve);
287
+ });
288
+ }
289
+ settleRoleWaiters() {
290
+ const waiters = this.roleWaiters;
291
+ this.roleWaiters = [];
292
+ for (const waiter of waiters) {
293
+ waiter();
294
+ }
295
+ }
296
+ /**
297
+ * The caller's `AbortSignal` is honoured HERE as well as in `WorkerBffTransport`. Without it the
298
+ * same page code behaves differently depending on which tab won the lock: abort works in the
299
+ * leader and silently does nothing in every follower, so a data provider that aborts on unmount
300
+ * leaves promises pending for the full timeout in every tab but one.
301
+ *
302
+ * Aborting settles the CALLER. It does not cancel the leader's work - there is no cancel message,
303
+ * and a write already dispatched cannot be taken back.
304
+ */
305
+ async fetchViaLeader(opts) {
306
+ const { signal } = opts.request;
307
+ if (signal?.aborted) {
308
+ throw this.toAbortError({ signal });
309
+ }
310
+ const id = this.requestIdGenerator.nextId();
311
+ const envelope = await BffEnvelope.encodeRequest({
312
+ request: opts.request,
313
+ id,
314
+ url: BffEnvelope.toSyntheticUrl({ url: opts.request.url }),
315
+ });
316
+ return new Promise((resolve, reject) => {
317
+ const timer = setTimeout(() => {
318
+ this.takePending({ id })?.reject(getError({
319
+ message: `[SharedBffTransport] Timed out waiting for the leader tab | id: ${id} | timeoutMs: ${this.timeoutMs}`,
320
+ }));
321
+ }, this.timeoutMs);
322
+ const handleAbort = () => {
323
+ this.takePending({ id })?.reject(this.toAbortError({ signal }));
324
+ };
325
+ signal?.addEventListener('abort', handleAbort);
326
+ this.pendingRequests.set(id, {
327
+ resolve,
328
+ reject,
329
+ release: () => {
330
+ clearTimeout(timer);
331
+ signal?.removeEventListener('abort', handleAbort);
332
+ },
333
+ });
334
+ // Buffering the body took an await, and `addEventListener('abort')` never fires on a signal
335
+ // that aborted before it was attached - without this re-read that window loses the abort.
336
+ if (signal?.aborted) {
337
+ handleAbort();
338
+ return;
339
+ }
340
+ this.channel.postMessage({
341
+ kind: ChannelMessageKinds.REQUEST,
342
+ envelope,
343
+ });
344
+ });
345
+ }
346
+ /** `signal.reason` first, the way `globalThis.fetch` rejects, so a custom abort reason survives. */
347
+ toAbortError(opts) {
348
+ return (opts.signal?.reason ??
349
+ getError({ message: '[SharedBffTransport] The request was aborted by its caller' }));
350
+ }
351
+ takePending(opts) {
352
+ const pending = this.pendingRequests.get(opts.id);
353
+ if (!pending) {
354
+ return undefined;
355
+ }
356
+ this.pendingRequests.delete(opts.id);
357
+ pending.release();
358
+ return pending;
359
+ }
360
+ rejectAllPending(opts) {
361
+ for (const id of [...this.pendingRequests.keys()]) {
362
+ this.takePending({ id })?.reject(getError({
363
+ message: `[SharedBffTransport] Request abandoned | id: ${id} | reason: ${opts.reason}`,
364
+ }));
365
+ }
366
+ }
367
+ async serveAsLeader(opts) {
368
+ const { envelope } = opts;
369
+ try {
370
+ const response = await this.leaderTransport.fetch({
371
+ request: BffEnvelope.decodeRequest({ envelope }),
372
+ });
373
+ this.channel.postMessage({
374
+ kind: ChannelMessageKinds.RESPONSE,
375
+ envelope: await BffEnvelope.encodeResponse({ response, id: envelope.id }),
376
+ });
377
+ }
378
+ catch (error) {
379
+ // The follower gets the failure as a failure, rather than waiting out a timeout that would
380
+ // tell it nothing about what went wrong.
381
+ this.logger
382
+ .for(this.serveAsLeader.name)
383
+ .error('Failed to serve a follower request | id: %s | error: %s', envelope.id, error);
384
+ this.channel.postMessage({
385
+ kind: ChannelMessageKinds.ERROR,
386
+ envelope: BffEnvelope.encodeError({ id: envelope.id, error }),
387
+ });
388
+ }
389
+ }
390
+ }
391
+ //# sourceMappingURL=shared.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../src/transport/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAEvF,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAOhD,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAE9C,MAAM,oBAAoB,GAAG,WAAW,CAAC;AACzC,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAElC,yFAAyF;AACzF,MAAM,OAAO,QAAQ;aACH,aAAQ,GAAG,UAAU,CAAC;aACtB,WAAM,GAAG,QAAQ,CAAC;aAClB,aAAQ,GAAG,UAAU,CAAC;;AAKxC,MAAM,mBAAmB;aACP,YAAO,GAAG,mBAAmB,CAAC;aAC9B,aAAQ,GAAG,oBAAoB,CAAC;aAChC,UAAK,GAAG,iBAAiB,CAAC;;AA8B5C;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,OAAO,kBAAmB,SAAQ,UAAU;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,QAAQ,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,GAA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AW,CAAC,WAAW,CAAC,EAAE,EAAE,EAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,EAAE,CAAC;aACpC,CAAC,CAAC;QAC/B,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,62 @@
1
+ import { BaseHelper } from '@venizia/ignis-helpers/core';
2
+ import type { IBffTransport } from './common/types.js';
3
+ /**
4
+ * UI-side half of the BFF: posts an encoded request to a real `Worker` and resolves the matching
5
+ * response by `id` - the far side of `WorkerApplication.listen()`.
6
+ *
7
+ * The three worker listeners are attached ONCE, in the constructor, and every request is tracked in
8
+ * `pendingRequests` instead. Registering them per request looks equivalent and is not: they are
9
+ * scoped to the shared `Worker`, so a single `messageerror` - which means exactly one message
10
+ * failed to deserialise - would fire every in-flight request's handler, rejecting nine healthy
11
+ * requests that are about to be answered normally.
12
+ */
13
+ export declare class WorkerBffTransport extends BaseHelper implements IBffTransport {
14
+ private readonly worker;
15
+ private readonly timeoutMs;
16
+ private readonly requestIdGenerator;
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;
22
+ constructor(opts: {
23
+ worker: Worker;
24
+ timeoutMs?: number;
25
+ });
26
+ /** Removes a pending request from the map and releases its timer and abort listener, so nothing can settle it twice. */
27
+ private readonly takePending;
28
+ private readonly handleMessage;
29
+ /**
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.
40
+ */
41
+ private readonly handleWorkerError;
42
+ /** `ErrorEvent` carries the useful fields; a plain `Event` does not, so both shapes are handled. */
43
+ private describeErrorEvent;
44
+ /**
45
+ * `messageerror` means exactly ONE posted message failed to deserialise, and the event carries
46
+ * nothing that says which. With a single request in flight that is unambiguous, so it settles
47
+ * now; with several, the lost answer belongs to one of them and rejecting the rest would be a
48
+ * lie - each then ends on its own timeout, under its own id.
49
+ */
50
+ private readonly handleMessageError;
51
+ fetch(opts: {
52
+ request: Request;
53
+ }): Promise<Response>;
54
+ /** `signal.reason` first, the way `globalThis.fetch` rejects, so `controller.abort(myReason)` still reaches the caller. */
55
+ private toAbortError;
56
+ /**
57
+ * Detaches the three worker listeners and fails whatever is still in flight. The worker itself is
58
+ * left alone - this transport did not create it, and a page may hand the same one to another.
59
+ */
60
+ close(): void;
61
+ }
62
+ //# sourceMappingURL=worker.d.ts.map
@@ -0,0 +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;AAoBpD;;;;;;;;;GASG;AACH,qBAAa,kBAAmB,SAAQ,UAAW,YAAW,aAAa;IACzE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;IACnC,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAEhC;IACH,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAsC;IAEtE,yGAAyG;IACzG,OAAO,CAAC,QAAQ,CAAS;IAEzB,yGAAyG;IACzG,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA4C;gBAE5D,IAAI,EAAE;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"}