@venizia/ignis-worker 0.2.0-2 → 0.2.0-4
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/cjs/transport/fetch-bridge.d.ts +35 -0
- package/dist/cjs/transport/fetch-bridge.d.ts.map +1 -0
- package/dist/cjs/transport/fetch-bridge.js +95 -0
- package/dist/cjs/transport/fetch-bridge.js.map +1 -0
- package/dist/cjs/transport/index.d.ts +2 -0
- package/dist/cjs/transport/index.d.ts.map +1 -1
- package/dist/cjs/transport/index.js +2 -0
- package/dist/cjs/transport/index.js.map +1 -1
- package/dist/cjs/transport/shared.d.ts +102 -0
- package/dist/cjs/transport/shared.d.ts.map +1 -0
- package/dist/cjs/transport/shared.js +396 -0
- package/dist/cjs/transport/shared.js.map +1 -0
- package/dist/cjs/transport/worker.d.ts +16 -2
- package/dist/cjs/transport/worker.d.ts.map +1 -1
- package/dist/cjs/transport/worker.js +65 -7
- package/dist/cjs/transport/worker.js.map +1 -1
- package/dist/esm/transport/fetch-bridge.d.ts +35 -0
- package/dist/esm/transport/fetch-bridge.d.ts.map +1 -0
- package/dist/esm/transport/fetch-bridge.js +91 -0
- package/dist/esm/transport/fetch-bridge.js.map +1 -0
- package/dist/esm/transport/index.d.ts +2 -0
- package/dist/esm/transport/index.d.ts.map +1 -1
- package/dist/esm/transport/index.js +2 -0
- package/dist/esm/transport/index.js.map +1 -1
- package/dist/esm/transport/shared.d.ts +102 -0
- package/dist/esm/transport/shared.d.ts.map +1 -0
- package/dist/esm/transport/shared.js +391 -0
- package/dist/esm/transport/shared.js.map +1 -0
- package/dist/esm/transport/worker.d.ts +16 -2
- package/dist/esm/transport/worker.d.ts.map +1 -1
- package/dist/esm/transport/worker.js +65 -7
- package/dist/esm/transport/worker.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { IBffTransport } from './common/types';
|
|
2
|
+
type TFetch = typeof globalThis.fetch;
|
|
3
|
+
/** The carrier whose `fetch` is replaced - `globalThis` in a page, an object a test controls otherwise. */
|
|
4
|
+
interface IFetchCarrier {
|
|
5
|
+
fetch: TFetch;
|
|
6
|
+
}
|
|
7
|
+
export interface IInstallBffFetchOptions {
|
|
8
|
+
/** Anything implementing the transport contract, so an in-process transport works in a test. */
|
|
9
|
+
transport: IBffTransport;
|
|
10
|
+
/**
|
|
11
|
+
* Path prefixes the BFF owns, matched against the request's PATHNAME. Everything else is passed
|
|
12
|
+
* to the original `fetch` untouched.
|
|
13
|
+
*/
|
|
14
|
+
basePath: string | Array<string>;
|
|
15
|
+
/** Defaults to `globalThis`. */
|
|
16
|
+
carrier?: IFetchCarrier;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Routes the page's own `fetch` into a BFF transport for anything under `basePath`, and leaves every
|
|
20
|
+
* other call on the network untouched.
|
|
21
|
+
*
|
|
22
|
+
* This is the seam that lets an existing HTTP client talk to an in-browser IGNIS application without
|
|
23
|
+
* knowing one exists. A data provider, an SDK or a generated client reaches the network through the
|
|
24
|
+
* global `fetch` and usually accepts no custom fetcher, so answering that `fetch` is the only place
|
|
25
|
+
* an in-browser backend becomes a drop-in swap rather than a fork of the client.
|
|
26
|
+
*
|
|
27
|
+
* Install it BEFORE the application that will use it boots: a request issued while the original
|
|
28
|
+
* `fetch` is still in place leaves the page and 404s against whatever is serving it.
|
|
29
|
+
*
|
|
30
|
+
* @returns The uninstall function. It restores the previous `fetch` only if this bridge is still the
|
|
31
|
+
* installed one - if something patched `fetch` afterwards, restoring would silently discard that.
|
|
32
|
+
*/
|
|
33
|
+
export declare const installBffFetch: (opts: IInstallBffFetchOptions) => (() => void);
|
|
34
|
+
export {};
|
|
35
|
+
//# sourceMappingURL=fetch-bridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-bridge.d.ts","sourceRoot":"","sources":["../../../src/transport/fetch-bridge.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAQpD,KAAK,MAAM,GAAG,OAAO,UAAU,CAAC,KAAK,CAAC;AAEtC,2GAA2G;AAC3G,UAAU,aAAa;IACrB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,uBAAuB;IACtC,gGAAgG;IAChG,SAAS,EAAE,aAAa,CAAC;IACzB;;;OAGG;IACH,QAAQ,EAAE,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC;IACjC,gCAAgC;IAChC,OAAO,CAAC,EAAE,aAAa,CAAC;CACzB;AA+CD;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,eAAe,GAAI,MAAM,uBAAuB,KAAG,CAAC,MAAM,IAAI,CA2C1E,CAAC"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.installBffFetch = void 0;
|
|
4
|
+
const core_1 = require("@venizia/ignis-helpers/core");
|
|
5
|
+
/**
|
|
6
|
+
* Marks the patched `fetch` so a second install is refused rather than silently stacking. `Symbol.for`
|
|
7
|
+
* and not a private symbol: two copies of this package in one page must still see each other's mark.
|
|
8
|
+
*/
|
|
9
|
+
const BRIDGE_MARKER = Symbol.for('@venizia/ignis-worker/bff-fetch');
|
|
10
|
+
/**
|
|
11
|
+
* Resolves a request's absolute URL WITHOUT constructing a `Request`.
|
|
12
|
+
*
|
|
13
|
+
* This is the whole reason this helper exists rather than one obvious line. `new Request(input)`,
|
|
14
|
+
* where `input` is a `Request` carrying a body, marks that body disturbed - so building one just to
|
|
15
|
+
* read `.url` breaks the very pass-through it is deciding about: the next line hands the same, now
|
|
16
|
+
* unreadable, request to the network.
|
|
17
|
+
*
|
|
18
|
+
* Measured, because the runtimes disagree. Chromium:
|
|
19
|
+
*
|
|
20
|
+
* original.bodyUsed // false
|
|
21
|
+
* new Request(original)
|
|
22
|
+
* original.bodyUsed // true
|
|
23
|
+
* await original.text() // TypeError: body stream already read
|
|
24
|
+
*
|
|
25
|
+
* Bun does NOT disturb it, so the unit tests pass either way and cannot guard this. The browser is
|
|
26
|
+
* where this code runs, so the browser is the behaviour to write for.
|
|
27
|
+
*/
|
|
28
|
+
const resolveRequestUrl = (input) => {
|
|
29
|
+
if (typeof input === 'string') {
|
|
30
|
+
return new URL(input, globalThis.location?.href).href;
|
|
31
|
+
}
|
|
32
|
+
if (input instanceof URL) {
|
|
33
|
+
return input.href;
|
|
34
|
+
}
|
|
35
|
+
return input.url;
|
|
36
|
+
};
|
|
37
|
+
const toPrefixList = (basePath) => {
|
|
38
|
+
const prefixes = (Array.isArray(basePath) ? basePath : [basePath]).filter(prefix => prefix.length > 0);
|
|
39
|
+
if (prefixes.length === 0) {
|
|
40
|
+
throw (0, core_1.getError)({
|
|
41
|
+
message: '[installBffFetch] Invalid basePath | At least one non-empty path prefix is required',
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return prefixes;
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Routes the page's own `fetch` into a BFF transport for anything under `basePath`, and leaves every
|
|
48
|
+
* other call on the network untouched.
|
|
49
|
+
*
|
|
50
|
+
* This is the seam that lets an existing HTTP client talk to an in-browser IGNIS application without
|
|
51
|
+
* knowing one exists. A data provider, an SDK or a generated client reaches the network through the
|
|
52
|
+
* global `fetch` and usually accepts no custom fetcher, so answering that `fetch` is the only place
|
|
53
|
+
* an in-browser backend becomes a drop-in swap rather than a fork of the client.
|
|
54
|
+
*
|
|
55
|
+
* Install it BEFORE the application that will use it boots: a request issued while the original
|
|
56
|
+
* `fetch` is still in place leaves the page and 404s against whatever is serving it.
|
|
57
|
+
*
|
|
58
|
+
* @returns The uninstall function. It restores the previous `fetch` only if this bridge is still the
|
|
59
|
+
* installed one - if something patched `fetch` afterwards, restoring would silently discard that.
|
|
60
|
+
*/
|
|
61
|
+
const installBffFetch = (opts) => {
|
|
62
|
+
const { transport, basePath } = opts;
|
|
63
|
+
const carrier = opts.carrier ?? globalThis;
|
|
64
|
+
const prefixes = toPrefixList(basePath);
|
|
65
|
+
const previousFetch = carrier.fetch;
|
|
66
|
+
if (Object.getOwnPropertyDescriptor(previousFetch, BRIDGE_MARKER)) {
|
|
67
|
+
throw (0, core_1.getError)({
|
|
68
|
+
message: '[installBffFetch] A BFF fetch bridge is already installed | Uninstall it first, or pass every prefix to a single install',
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
const networkFetch = previousFetch.bind(carrier);
|
|
72
|
+
const bridged = async (input, init) => {
|
|
73
|
+
const { pathname } = new URL(resolveRequestUrl(input));
|
|
74
|
+
if (!prefixes.some(prefix => pathname.startsWith(prefix))) {
|
|
75
|
+
return networkFetch(input, init);
|
|
76
|
+
}
|
|
77
|
+
// Constructed only now, on the branch that owns the request - so the pass-through above never
|
|
78
|
+
// disturbs a body it is about to hand to the network.
|
|
79
|
+
return transport.fetch({ request: new Request(input, init) });
|
|
80
|
+
};
|
|
81
|
+
// Whatever the runtime hung on `fetch` comes along - Bun puts `preconnect` there, and a
|
|
82
|
+
// replacement that dropped it would break any caller reaching for it. Copying the descriptors is
|
|
83
|
+
// also what makes this satisfy `typeof fetch` rather than merely resembling it.
|
|
84
|
+
Object.defineProperties(bridged, Object.getOwnPropertyDescriptors(previousFetch));
|
|
85
|
+
Object.defineProperty(bridged, BRIDGE_MARKER, { value: true });
|
|
86
|
+
carrier.fetch = bridged;
|
|
87
|
+
return () => {
|
|
88
|
+
if (carrier.fetch !== bridged) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
carrier.fetch = previousFetch;
|
|
92
|
+
};
|
|
93
|
+
};
|
|
94
|
+
exports.installBffFetch = installBffFetch;
|
|
95
|
+
//# sourceMappingURL=fetch-bridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fetch-bridge.js","sourceRoot":"","sources":["../../../src/transport/fetch-bridge.ts"],"names":[],"mappings":";;;A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Ae,mBA2C1B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/transport/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/transport/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC"}
|
|
@@ -15,6 +15,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./common"), exports);
|
|
18
|
+
__exportStar(require("./fetch-bridge"), exports);
|
|
18
19
|
__exportStar(require("./in-process"), exports);
|
|
20
|
+
__exportStar(require("./shared"), exports);
|
|
19
21
|
__exportStar(require("./worker"), exports);
|
|
20
22
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/transport/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,+CAA6B;AAC7B,2CAAyB"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/transport/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,iDAA+B;AAC/B,+CAA6B;AAC7B,2CAAyB;AACzB,2CAAyB"}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { BaseHelper } from '@venizia/ignis-helpers/core';
|
|
2
|
+
import type { TConstValue } from '@venizia/ignis-helpers/common';
|
|
3
|
+
import type { IBffTransport } from './common/types';
|
|
4
|
+
/** Which part this tab plays. `ELECTING` is the brief window before the lock answers. */
|
|
5
|
+
export declare class BffRoles {
|
|
6
|
+
static readonly ELECTING = "electing";
|
|
7
|
+
static readonly LEADER = "leader";
|
|
8
|
+
static readonly FOLLOWER = "follower";
|
|
9
|
+
}
|
|
10
|
+
export type TBffRole = TConstValue<typeof BffRoles>;
|
|
11
|
+
export interface ISharedBffTransportOptions {
|
|
12
|
+
/** Builds the Worker. Called ONLY by whichever tab wins the election - the others never start one. */
|
|
13
|
+
createWorker: () => Worker;
|
|
14
|
+
/** Distinguishes independent BFFs on one origin. The lock name is derived from it. */
|
|
15
|
+
channelName?: string;
|
|
16
|
+
timeoutMs?: number;
|
|
17
|
+
scope?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* One BFF for every tab of an origin, instead of one per tab.
|
|
21
|
+
*
|
|
22
|
+
* The problem it solves is not a framework limitation, it is a storage one. PGlite in
|
|
23
|
+
* `opfs-ahp://` mode holds an exclusive access handle on the database file, and OPFS access handles
|
|
24
|
+
* are exclusive PER ORIGIN. Measured in Chromium with two tabs of the same page: the first tab
|
|
25
|
+
* works, and the second never boots its database -
|
|
26
|
+
* `Failed to execute 'createSyncAccessHandle' on 'FileSystemFileHandle': Access Handles cannot be
|
|
27
|
+
* created if there is another open Access Handle or Writable stream associated with the same file`.
|
|
28
|
+
* The first tab is unaffected, and closing it lets the second recover on reload - so the failure is
|
|
29
|
+
* contained and self-healing, but the second tab is simply dead until then.
|
|
30
|
+
*
|
|
31
|
+
* So exactly one tab may own the database. This transport elects that tab with the Web Locks API,
|
|
32
|
+
* gives it the Worker, and forwards every other tab's request to it over a `BroadcastChannel`,
|
|
33
|
+
* carried in the same envelope the Worker itself speaks. When the leader's tab closes, the lock is
|
|
34
|
+
* released by the browser and a follower is promoted automatically - no heartbeat, no timeout, no
|
|
35
|
+
* stale-leader window to reason about.
|
|
36
|
+
*
|
|
37
|
+
* A host with no `navigator.locks` runs single-tab, exactly as before. That is not a compromise:
|
|
38
|
+
* measured on a plain-http origin, `navigator.locks` and `navigator.storage.getDirectory` are BOTH
|
|
39
|
+
* undefined, because both are secure-context only. Wherever OPFS works the lock exists, and where it
|
|
40
|
+
* does not the database could not have started either.
|
|
41
|
+
*/
|
|
42
|
+
export declare class SharedBffTransport extends BaseHelper implements IBffTransport {
|
|
43
|
+
private readonly createWorker;
|
|
44
|
+
private readonly channel;
|
|
45
|
+
private readonly lockName;
|
|
46
|
+
private readonly timeoutMs;
|
|
47
|
+
private readonly requestIdGenerator;
|
|
48
|
+
private readonly pendingRequests;
|
|
49
|
+
private role;
|
|
50
|
+
private leaderTransport?;
|
|
51
|
+
private isClosed;
|
|
52
|
+
/**
|
|
53
|
+
* Held because THIS class created it. `WorkerBffTransport.close()` deliberately leaves a worker
|
|
54
|
+
* running - it did not create the one it was handed - so without this reference the worker would
|
|
55
|
+
* outlive `close()` still holding the exclusive OPFS access handle, while the lock has already
|
|
56
|
+
* gone to another tab that opens the same database.
|
|
57
|
+
*/
|
|
58
|
+
private leaderWorker?;
|
|
59
|
+
/** Set when `createWorker()` throws, so callers get that failure instead of parking forever. */
|
|
60
|
+
private leaderStartupError?;
|
|
61
|
+
/** Resolving this releases the Web Lock, which is what promotes a follower. */
|
|
62
|
+
private releaseLeadership?;
|
|
63
|
+
/** Drops this tab out of the lock QUEUE on close, so a closed transport cannot be promoted. */
|
|
64
|
+
private readonly leadershipQueueAbort;
|
|
65
|
+
/** Callers parked in `fetch()` while the election is still running. */
|
|
66
|
+
private roleWaiters;
|
|
67
|
+
constructor(opts: ISharedBffTransportOptions);
|
|
68
|
+
getRole(): TBffRole;
|
|
69
|
+
fetch(opts: {
|
|
70
|
+
request: Request;
|
|
71
|
+
}): Promise<Response>;
|
|
72
|
+
close(): void;
|
|
73
|
+
private elect;
|
|
74
|
+
private becomeLeader;
|
|
75
|
+
private becomeFollower;
|
|
76
|
+
private heldUntilClosed;
|
|
77
|
+
private whenRoleSettled;
|
|
78
|
+
private settleRoleWaiters;
|
|
79
|
+
/**
|
|
80
|
+
* The caller's `AbortSignal` is honoured HERE as well as in `WorkerBffTransport`. Without it the
|
|
81
|
+
* same page code behaves differently depending on which tab won the lock: abort works in the
|
|
82
|
+
* leader and silently does nothing in every follower, so a data provider that aborts on unmount
|
|
83
|
+
* leaves promises pending for the full timeout in every tab but one.
|
|
84
|
+
*
|
|
85
|
+
* Aborting settles the CALLER. It does not cancel the leader's work - there is no cancel message,
|
|
86
|
+
* and a write already dispatched cannot be taken back.
|
|
87
|
+
*/
|
|
88
|
+
private fetchViaLeader;
|
|
89
|
+
/** `signal.reason` first, the way `globalThis.fetch` rejects, so a custom abort reason survives. */
|
|
90
|
+
private toAbortError;
|
|
91
|
+
private takePending;
|
|
92
|
+
private rejectAllPending;
|
|
93
|
+
/**
|
|
94
|
+
* A `BroadcastChannel` never delivers a message to the instance that sent it, so a leader does not
|
|
95
|
+
* hear its own answers and a follower does not hear its own requests. Every tab does hear every
|
|
96
|
+
* OTHER tab, which is why a response is matched by id and silently ignored when it belongs to
|
|
97
|
+
* someone else.
|
|
98
|
+
*/
|
|
99
|
+
private readonly handleChannelMessage;
|
|
100
|
+
private serveAsLeader;
|
|
101
|
+
}
|
|
102
|
+
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../../src/transport/shared.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAgC,MAAM,6BAA6B,CAAC;AACvF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAOjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAMpD,yFAAyF;AACzF,qBAAa,QAAQ;IACnB,MAAM,CAAC,QAAQ,CAAC,QAAQ,cAAc;IACtC,MAAM,CAAC,QAAQ,CAAC,MAAM,YAAY;IAClC,MAAM,CAAC,QAAQ,CAAC,QAAQ,cAAc;CACvC;AAED,MAAM,MAAM,QAAQ,GAAG,WAAW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