@elaraai/e3-web 0.0.0-stage → 1.0.86
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/LICENSE.md +54 -0
- package/README.md +395 -2
- package/dist/src/app.d.ts +91 -0
- package/dist/src/app.d.ts.map +1 -0
- package/dist/src/app.js +112 -0
- package/dist/src/app.js.map +1 -0
- package/dist/src/bridge/bridge.spec.d.ts +6 -0
- package/dist/src/bridge/bridge.spec.d.ts.map +1 -0
- package/dist/src/bridge/bridge.spec.js +56 -0
- package/dist/src/bridge/bridge.spec.js.map +1 -0
- package/dist/src/bridge/page.d.ts +149 -0
- package/dist/src/bridge/page.d.ts.map +1 -0
- package/dist/src/bridge/page.js +328 -0
- package/dist/src/bridge/page.js.map +1 -0
- package/dist/src/bridge/protocol.d.ts +181 -0
- package/dist/src/bridge/protocol.d.ts.map +1 -0
- package/dist/src/bridge/protocol.js +113 -0
- package/dist/src/bridge/protocol.js.map +1 -0
- package/dist/src/bridge/worker.d.ts +124 -0
- package/dist/src/bridge/worker.d.ts.map +1 -0
- package/dist/src/bridge/worker.js +185 -0
- package/dist/src/bridge/worker.js.map +1 -0
- package/dist/src/browser/bridge.page.d.ts +12 -0
- package/dist/src/browser/bridge.page.d.ts.map +1 -0
- package/dist/src/browser/bridge.page.js +79 -0
- package/dist/src/browser/bridge.page.js.map +1 -0
- package/dist/src/browser/bridge.spec.d.ts +6 -0
- package/dist/src/browser/bridge.spec.d.ts.map +1 -0
- package/dist/src/browser/bridge.spec.js +105 -0
- package/dist/src/browser/bridge.spec.js.map +1 -0
- package/dist/src/browser/bridge.worker.d.ts +6 -0
- package/dist/src/browser/bridge.worker.d.ts.map +1 -0
- package/dist/src/browser/bridge.worker.js +35 -0
- package/dist/src/browser/bridge.worker.js.map +1 -0
- package/dist/src/browser/compliance.d.ts +68 -0
- package/dist/src/browser/compliance.d.ts.map +1 -0
- package/dist/src/browser/compliance.js +30 -0
- package/dist/src/browser/compliance.js.map +1 -0
- package/dist/src/browser/compliance.page.d.ts +6 -0
- package/dist/src/browser/compliance.page.d.ts.map +1 -0
- package/dist/src/browser/compliance.page.js +204 -0
- package/dist/src/browser/compliance.page.js.map +1 -0
- package/dist/src/browser/compliance.spec.d.ts +6 -0
- package/dist/src/browser/compliance.spec.d.ts.map +1 -0
- package/dist/src/browser/compliance.spec.js +147 -0
- package/dist/src/browser/compliance.spec.js.map +1 -0
- package/dist/src/browser/e3-api-1.spec.d.ts +6 -0
- package/dist/src/browser/e3-api-1.spec.d.ts.map +1 -0
- package/dist/src/browser/e3-api-1.spec.js +12 -0
- package/dist/src/browser/e3-api-1.spec.js.map +1 -0
- package/dist/src/browser/e3-api-2.spec.d.ts +6 -0
- package/dist/src/browser/e3-api-2.spec.d.ts.map +1 -0
- package/dist/src/browser/e3-api-2.spec.js +12 -0
- package/dist/src/browser/e3-api-2.spec.js.map +1 -0
- package/dist/src/browser/e3-api-3.spec.d.ts +6 -0
- package/dist/src/browser/e3-api-3.spec.d.ts.map +1 -0
- package/dist/src/browser/e3-api-3.spec.js +12 -0
- package/dist/src/browser/e3-api-3.spec.js.map +1 -0
- package/dist/src/browser/e3-api-parts.spec.d.ts +6 -0
- package/dist/src/browser/e3-api-parts.spec.d.ts.map +1 -0
- package/dist/src/browser/e3-api-parts.spec.js +45 -0
- package/dist/src/browser/e3-api-parts.spec.js.map +1 -0
- package/dist/src/browser/e3-api.d.ts +28 -0
- package/dist/src/browser/e3-api.d.ts.map +1 -0
- package/dist/src/browser/e3-api.js +144 -0
- package/dist/src/browser/e3-api.js.map +1 -0
- package/dist/src/browser/e3-client.worker.d.ts +6 -0
- package/dist/src/browser/e3-client.worker.d.ts.map +1 -0
- package/dist/src/browser/e3-client.worker.js +19 -0
- package/dist/src/browser/e3-client.worker.js.map +1 -0
- package/dist/src/browser/e3-forward.d.ts +27 -0
- package/dist/src/browser/e3-forward.d.ts.map +1 -0
- package/dist/src/browser/e3-forward.js +81 -0
- package/dist/src/browser/e3-forward.js.map +1 -0
- package/dist/src/browser/e3-forward.spec.d.ts +6 -0
- package/dist/src/browser/e3-forward.spec.d.ts.map +1 -0
- package/dist/src/browser/e3-forward.spec.js +84 -0
- package/dist/src/browser/e3-forward.spec.js.map +1 -0
- package/dist/src/browser/e3-port.worker.d.ts +6 -0
- package/dist/src/browser/e3-port.worker.d.ts.map +1 -0
- package/dist/src/browser/e3-port.worker.js +21 -0
- package/dist/src/browser/e3-port.worker.js.map +1 -0
- package/dist/src/browser/e3-unit.worker.d.ts +6 -0
- package/dist/src/browser/e3-unit.worker.d.ts.map +1 -0
- package/dist/src/browser/e3-unit.worker.js +18 -0
- package/dist/src/browser/e3-unit.worker.js.map +1 -0
- package/dist/src/browser/e3-wire.d.ts +43 -0
- package/dist/src/browser/e3-wire.d.ts.map +1 -0
- package/dist/src/browser/e3-wire.js +32 -0
- package/dist/src/browser/e3-wire.js.map +1 -0
- package/dist/src/browser/e3.page.d.ts +21 -0
- package/dist/src/browser/e3.page.d.ts.map +1 -0
- package/dist/src/browser/e3.page.js +119 -0
- package/dist/src/browser/e3.page.js.map +1 -0
- package/dist/src/browser/e3.spec.d.ts +6 -0
- package/dist/src/browser/e3.spec.d.ts.map +1 -0
- package/dist/src/browser/e3.spec.js +358 -0
- package/dist/src/browser/e3.spec.js.map +1 -0
- package/dist/src/browser/e3.worker.d.ts +6 -0
- package/dist/src/browser/e3.worker.d.ts.map +1 -0
- package/dist/src/browser/e3.worker.js +38 -0
- package/dist/src/browser/e3.worker.js.map +1 -0
- package/dist/src/browser/harness.d.ts +175 -0
- package/dist/src/browser/harness.d.ts.map +1 -0
- package/dist/src/browser/harness.js +375 -0
- package/dist/src/browser/harness.js.map +1 -0
- package/dist/src/browser/page.d.ts +47 -0
- package/dist/src/browser/page.d.ts.map +1 -0
- package/dist/src/browser/page.js +47 -0
- package/dist/src/browser/page.js.map +1 -0
- package/dist/src/browser/repository.page.d.ts +85 -0
- package/dist/src/browser/repository.page.d.ts.map +1 -0
- package/dist/src/browser/repository.page.js +271 -0
- package/dist/src/browser/repository.page.js.map +1 -0
- package/dist/src/browser/runner.page.d.ts +6 -0
- package/dist/src/browser/runner.page.d.ts.map +1 -0
- package/dist/src/browser/runner.page.js +62 -0
- package/dist/src/browser/runner.page.js.map +1 -0
- package/dist/src/browser/runner.spec.d.ts +6 -0
- package/dist/src/browser/runner.spec.d.ts.map +1 -0
- package/dist/src/browser/runner.spec.js +46 -0
- package/dist/src/browser/runner.spec.js.map +1 -0
- package/dist/src/browser/storage.page.d.ts +6 -0
- package/dist/src/browser/storage.page.d.ts.map +1 -0
- package/dist/src/browser/storage.page.js +289 -0
- package/dist/src/browser/storage.page.js.map +1 -0
- package/dist/src/browser/storage.spec.d.ts +6 -0
- package/dist/src/browser/storage.spec.d.ts.map +1 -0
- package/dist/src/browser/storage.spec.js +211 -0
- package/dist/src/browser/storage.spec.js.map +1 -0
- package/dist/src/browser/unit.worker.d.ts +6 -0
- package/dist/src/browser/unit.worker.d.ts.map +1 -0
- package/dist/src/browser/unit.worker.js +17 -0
- package/dist/src/browser/unit.worker.js.map +1 -0
- package/dist/src/execution/WebTaskRunner.d.ts +159 -0
- package/dist/src/execution/WebTaskRunner.d.ts.map +1 -0
- package/dist/src/execution/WebTaskRunner.js +581 -0
- package/dist/src/execution/WebTaskRunner.js.map +1 -0
- package/dist/src/execution/WebTaskRunner.spec.d.ts +6 -0
- package/dist/src/execution/WebTaskRunner.spec.d.ts.map +1 -0
- package/dist/src/execution/WebTaskRunner.spec.js +91 -0
- package/dist/src/execution/WebTaskRunner.spec.js.map +1 -0
- package/dist/src/execution/e3-platform.d.ts +41 -0
- package/dist/src/execution/e3-platform.d.ts.map +1 -0
- package/dist/src/execution/e3-platform.js +52 -0
- package/dist/src/execution/e3-platform.js.map +1 -0
- package/dist/src/execution/in-process.d.ts +32 -0
- package/dist/src/execution/in-process.d.ts.map +1 -0
- package/dist/src/execution/in-process.js +89 -0
- package/dist/src/execution/in-process.js.map +1 -0
- package/dist/src/execution/pool.d.ts +172 -0
- package/dist/src/execution/pool.d.ts.map +1 -0
- package/dist/src/execution/pool.js +352 -0
- package/dist/src/execution/pool.js.map +1 -0
- package/dist/src/execution/pool.spec.d.ts +6 -0
- package/dist/src/execution/pool.spec.d.ts.map +1 -0
- package/dist/src/execution/pool.spec.js +252 -0
- package/dist/src/execution/pool.spec.js.map +1 -0
- package/dist/src/execution/protocol.d.ts +108 -0
- package/dist/src/execution/protocol.d.ts.map +1 -0
- package/dist/src/execution/protocol.js +27 -0
- package/dist/src/execution/protocol.js.map +1 -0
- package/dist/src/execution/unit-server.d.ts +131 -0
- package/dist/src/execution/unit-server.d.ts.map +1 -0
- package/dist/src/execution/unit-server.js +142 -0
- package/dist/src/execution/unit-server.js.map +1 -0
- package/dist/src/index.d.ts +39 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +37 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/index.spec.d.ts +6 -0
- package/dist/src/index.spec.d.ts.map +1 -0
- package/dist/src/index.spec.js +212 -0
- package/dist/src/index.spec.js.map +1 -0
- package/dist/src/node.d.ts +12 -0
- package/dist/src/node.d.ts.map +1 -0
- package/dist/src/node.js +12 -0
- package/dist/src/node.js.map +1 -0
- package/dist/src/storage/WebStateStore.d.ts +64 -0
- package/dist/src/storage/WebStateStore.d.ts.map +1 -0
- package/dist/src/storage/WebStateStore.js +237 -0
- package/dist/src/storage/WebStateStore.js.map +1 -0
- package/dist/src/storage/WebStorage.d.ts +225 -0
- package/dist/src/storage/WebStorage.d.ts.map +1 -0
- package/dist/src/storage/WebStorage.js +1462 -0
- package/dist/src/storage/WebStorage.js.map +1 -0
- package/dist/src/storage/adapters.d.ts +610 -0
- package/dist/src/storage/adapters.d.ts.map +1 -0
- package/dist/src/storage/adapters.js +246 -0
- package/dist/src/storage/adapters.js.map +1 -0
- package/dist/src/storage/indexeddb.d.ts +93 -0
- package/dist/src/storage/indexeddb.d.ts.map +1 -0
- package/dist/src/storage/indexeddb.js +384 -0
- package/dist/src/storage/indexeddb.js.map +1 -0
- package/dist/src/storage/indexeddb.spec.d.ts +6 -0
- package/dist/src/storage/indexeddb.spec.d.ts.map +1 -0
- package/dist/src/storage/indexeddb.spec.js +77 -0
- package/dist/src/storage/indexeddb.spec.js.map +1 -0
- package/dist/src/storage/memory.d.ts +275 -0
- package/dist/src/storage/memory.d.ts.map +1 -0
- package/dist/src/storage/memory.js +724 -0
- package/dist/src/storage/memory.js.map +1 -0
- package/dist/src/storage/memory.spec.d.ts +6 -0
- package/dist/src/storage/memory.spec.d.ts.map +1 -0
- package/dist/src/storage/memory.spec.js +71 -0
- package/dist/src/storage/memory.spec.js.map +1 -0
- package/dist/src/storage/node-files.d.ts +38 -0
- package/dist/src/storage/node-files.d.ts.map +1 -0
- package/dist/src/storage/node-files.js +148 -0
- package/dist/src/storage/node-files.js.map +1 -0
- package/dist/src/storage/node-files.spec.d.ts +6 -0
- package/dist/src/storage/node-files.spec.d.ts.map +1 -0
- package/dist/src/storage/node-files.spec.js +40 -0
- package/dist/src/storage/node-files.spec.js.map +1 -0
- package/dist/src/storage/opfs.d.ts +145 -0
- package/dist/src/storage/opfs.d.ts.map +1 -0
- package/dist/src/storage/opfs.js +514 -0
- package/dist/src/storage/opfs.js.map +1 -0
- package/dist/src/storage/opfs.spec.d.ts +6 -0
- package/dist/src/storage/opfs.spec.d.ts.map +1 -0
- package/dist/src/storage/opfs.spec.js +51 -0
- package/dist/src/storage/opfs.spec.js.map +1 -0
- package/dist/src/storage/record-keys.d.ts +78 -0
- package/dist/src/storage/record-keys.d.ts.map +1 -0
- package/dist/src/storage/record-keys.js +71 -0
- package/dist/src/storage/record-keys.js.map +1 -0
- package/dist/src/storage/stores.spec.d.ts +6 -0
- package/dist/src/storage/stores.spec.d.ts.map +1 -0
- package/dist/src/storage/stores.spec.js +326 -0
- package/dist/src/storage/stores.spec.js.map +1 -0
- package/dist/src/storage/web-locks.d.ts +103 -0
- package/dist/src/storage/web-locks.d.ts.map +1 -0
- package/dist/src/storage/web-locks.js +228 -0
- package/dist/src/storage/web-locks.js.map +1 -0
- package/dist/src/testing/adapter-contract.d.ts +116 -0
- package/dist/src/testing/adapter-contract.d.ts.map +1 -0
- package/dist/src/testing/adapter-contract.js +769 -0
- package/dist/src/testing/adapter-contract.js.map +1 -0
- package/dist/src/testing/assert.d.ts +75 -0
- package/dist/src/testing/assert.d.ts.map +1 -0
- package/dist/src/testing/assert.js +146 -0
- package/dist/src/testing/assert.js.map +1 -0
- package/dist/src/testing/assert.spec.d.ts +6 -0
- package/dist/src/testing/assert.spec.d.ts.map +1 -0
- package/dist/src/testing/assert.spec.js +62 -0
- package/dist/src/testing/assert.spec.js.map +1 -0
- package/dist/src/testing/bridge-contract.d.ts +55 -0
- package/dist/src/testing/bridge-contract.d.ts.map +1 -0
- package/dist/src/testing/bridge-contract.js +376 -0
- package/dist/src/testing/bridge-contract.js.map +1 -0
- package/dist/src/testing/bridge-handler.d.ts +35 -0
- package/dist/src/testing/bridge-handler.d.ts.map +1 -0
- package/dist/src/testing/bridge-handler.js +108 -0
- package/dist/src/testing/bridge-handler.js.map +1 -0
- package/dist/src/testing/callers.d.ts +29 -0
- package/dist/src/testing/callers.d.ts.map +1 -0
- package/dist/src/testing/callers.js +24 -0
- package/dist/src/testing/callers.js.map +1 -0
- package/dist/src/testing/e3-fixtures.d.ts +38 -0
- package/dist/src/testing/e3-fixtures.d.ts.map +1 -0
- package/dist/src/testing/e3-fixtures.js +126 -0
- package/dist/src/testing/e3-fixtures.js.map +1 -0
- package/dist/src/testing/hold-platform.d.ts +33 -0
- package/dist/src/testing/hold-platform.d.ts.map +1 -0
- package/dist/src/testing/hold-platform.js +41 -0
- package/dist/src/testing/hold-platform.js.map +1 -0
- package/dist/src/testing/runner-cases.d.ts +112 -0
- package/dist/src/testing/runner-cases.d.ts.map +1 -0
- package/dist/src/testing/runner-cases.js +959 -0
- package/dist/src/testing/runner-cases.js.map +1 -0
- package/dist/src/testing/runner-fixtures.d.ts +13 -0
- package/dist/src/testing/runner-fixtures.d.ts.map +1 -0
- package/dist/src/testing/runner-fixtures.js +173 -0
- package/dist/src/testing/runner-fixtures.js.map +1 -0
- package/dist/src/testing/test-platform.d.ts +73 -0
- package/dist/src/testing/test-platform.d.ts.map +1 -0
- package/dist/src/testing/test-platform.js +143 -0
- package/dist/src/testing/test-platform.js.map +1 -0
- package/dist/src/transfer/WebTransferBackend.d.ts +780 -0
- package/dist/src/transfer/WebTransferBackend.d.ts.map +1 -0
- package/dist/src/transfer/WebTransferBackend.js +1140 -0
- package/dist/src/transfer/WebTransferBackend.js.map +1 -0
- package/dist/src/transfer/WebTransferBackend.spec.d.ts +6 -0
- package/dist/src/transfer/WebTransferBackend.spec.d.ts.map +1 -0
- package/dist/src/transfer/WebTransferBackend.spec.js +582 -0
- package/dist/src/transfer/WebTransferBackend.spec.js.map +1 -0
- package/dist/src/transfer/endpoints.d.ts +46 -0
- package/dist/src/transfer/endpoints.d.ts.map +1 -0
- package/dist/src/transfer/endpoints.js +157 -0
- package/dist/src/transfer/endpoints.js.map +1 -0
- package/dist/src/units.d.ts +51 -0
- package/dist/src/units.d.ts.map +1 -0
- package/dist/src/units.js +74 -0
- package/dist/src/units.js.map +1 -0
- package/dist/src/worker.d.ts +126 -0
- package/dist/src/worker.d.ts.map +1 -0
- package/dist/src/worker.js +186 -0
- package/dist/src/worker.js.map +1 -0
- package/dist/src/worker.spec.d.ts +6 -0
- package/dist/src/worker.spec.d.ts.map +1 -0
- package/dist/src/worker.spec.js +195 -0
- package/dist/src/worker.spec.js.map +1 -0
- package/package.json +76 -3
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Licensed under BSL 1.1. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* The e3 worker's side of `e3.fetch`: {@link serveBridge}, which boots the
|
|
7
|
+
* worker's e3, tells each page that says hello whether it is ready, and
|
|
8
|
+
* answers the page's requests.
|
|
9
|
+
*
|
|
10
|
+
* `serveE3`, the e3 worker's public entry, serves through it: its boot opens
|
|
11
|
+
* the storage and the runner, and its handler is the app that mounts e3's
|
|
12
|
+
* routes.
|
|
13
|
+
*
|
|
14
|
+
* @packageDocumentation
|
|
15
|
+
*/
|
|
16
|
+
import { type WorkerMessage } from './protocol.js';
|
|
17
|
+
/**
|
|
18
|
+
* What answers a request in the worker: a fetch handler, as Hono's
|
|
19
|
+
* `app.fetch` is. It is called as a plain function, never as a method.
|
|
20
|
+
*/
|
|
21
|
+
export type RequestHandler = (request: Request) => Response | Promise<Response>;
|
|
22
|
+
/**
|
|
23
|
+
* What the worker's boot resolves to.
|
|
24
|
+
*/
|
|
25
|
+
export interface BridgeBoot {
|
|
26
|
+
/** Answers each request the page posts */
|
|
27
|
+
readonly fetch: RequestHandler;
|
|
28
|
+
/** Whether the worker keeps repositories past the page's life, so the page
|
|
29
|
+
* asks the browser to keep them through storage pressure */
|
|
30
|
+
readonly persist: boolean;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* What the worker's side speaks over: a dedicated worker's global scope, or a
|
|
34
|
+
* `MessagePort`.
|
|
35
|
+
*/
|
|
36
|
+
export interface BridgeEndpoint {
|
|
37
|
+
postMessage(message: WorkerMessage, transfer: Transferable[]): void;
|
|
38
|
+
addEventListener(type: string, listener: (event: Event) => void): void;
|
|
39
|
+
/** Starts a port's messages; a worker's global scope has none to start */
|
|
40
|
+
start?(): void;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* How {@link serveBridge} serves.
|
|
44
|
+
*/
|
|
45
|
+
export interface BridgeOptions {
|
|
46
|
+
/**
|
|
47
|
+
* Whether the worker holds a lifeline the page waits on to learn it has
|
|
48
|
+
* stopped, and waits on the lifeline a page connected over a port names, to
|
|
49
|
+
* learn the page has gone: `true` unless given. The port a unit worker is
|
|
50
|
+
* handed has neither: the pool that let the worker go ends its bridge
|
|
51
|
+
* ({@link BridgeServer.end}).
|
|
52
|
+
*/
|
|
53
|
+
readonly lifelines?: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Told once, when the page has gone: it closed its connection over a port,
|
|
56
|
+
* the lifeline it named was freed, or its port closed. The bridge has ended
|
|
57
|
+
* by then. Not told when {@link BridgeServer.end} ends it.
|
|
58
|
+
*/
|
|
59
|
+
readonly onEnd?: () => void;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* A bridge being served.
|
|
63
|
+
*/
|
|
64
|
+
export interface BridgeServer {
|
|
65
|
+
/**
|
|
66
|
+
* Ends the bridge: every request it is answering is aborted, and it answers
|
|
67
|
+
* nothing the page posts after. Its lifeline is freed. Ending it again does
|
|
68
|
+
* nothing.
|
|
69
|
+
*/
|
|
70
|
+
end(): void;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Serves `e3.fetch` from an e3 worker: boots the worker's e3, tells each page
|
|
74
|
+
* that says hello whether it is ready, or that it failed, and answers each
|
|
75
|
+
* request the page posts with the boot's handler.
|
|
76
|
+
*
|
|
77
|
+
* @param boot - Boots the worker's e3: resolves to the handler that answers
|
|
78
|
+
* requests, and whether the worker keeps repositories past the page; or
|
|
79
|
+
* rejects with what failed — a browser API it lacks, named — which the
|
|
80
|
+
* page's `createWebE3` rejects with
|
|
81
|
+
* @param endpoint - What the page's messages come over: the worker's global
|
|
82
|
+
* scope unless given, or a `MessagePort`
|
|
83
|
+
* @param options - Whether it holds and waits on lifelines, and what it tells
|
|
84
|
+
* when the page has gone
|
|
85
|
+
* @returns The bridge, which its host may end
|
|
86
|
+
*
|
|
87
|
+
* @remarks
|
|
88
|
+
* - The worker answers every hello, once its boot has settled: `ready`, or
|
|
89
|
+
* `boot-error` with what failed. A page that connects late — long after the
|
|
90
|
+
* boot, or a second time — is answered as the first.
|
|
91
|
+
* - The page posts its requests once it is told the worker is ready; a
|
|
92
|
+
* request that came sooner would wait for the boot.
|
|
93
|
+
* - Each request reaches the handler as a `Request` whose signal aborts when
|
|
94
|
+
* the page gives the request up, or when the bridge ends.
|
|
95
|
+
* - The handler's response is posted back: its status, status text, headers
|
|
96
|
+
* and body, the body whole and transferred. A `HEAD` request's response has
|
|
97
|
+
* no body, as `fetch` gives it none.
|
|
98
|
+
* - A handler that throws, or whose response's body fails, is answered with
|
|
99
|
+
* no response: the page's `fetch` rejects with a `TypeError` carrying what
|
|
100
|
+
* failed, as `fetch` rejects a network failure. An app answers its own
|
|
101
|
+
* errors with responses: Hono's `app.fetch` answers what a route throws
|
|
102
|
+
* with a 500.
|
|
103
|
+
* - Unless told otherwise, the worker holds a Web Lock for as long as it
|
|
104
|
+
* lives, and names it to the page, which learns from it that the worker has
|
|
105
|
+
* stopped. Over a port, the bridge ends when the page posts `close`, when
|
|
106
|
+
* the lifeline the page named is freed — its tab has gone — or when the port
|
|
107
|
+
* closes, where the platform says so; {@link BridgeOptions.onEnd} is told.
|
|
108
|
+
*
|
|
109
|
+
* @example
|
|
110
|
+
* ```ts
|
|
111
|
+
* // e3.worker.ts
|
|
112
|
+
* import { Hono } from 'hono';
|
|
113
|
+
* import { openWebStorage } from '@elaraai/e3-web';
|
|
114
|
+
*
|
|
115
|
+
* serveBridge(async () => {
|
|
116
|
+
* const storage = await openWebStorage(); // refuses, naming the API, in a browser that lacks one
|
|
117
|
+
* const app = new Hono();
|
|
118
|
+
* app.get('/api/repos', async (c) => c.json(await storage.repos.list()));
|
|
119
|
+
* return { fetch: app.fetch, persist: true };
|
|
120
|
+
* });
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
export declare function serveBridge(boot: () => Promise<BridgeBoot>, endpoint?: BridgeEndpoint, options?: BridgeOptions): BridgeServer;
|
|
124
|
+
//# sourceMappingURL=worker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../../../src/bridge/worker.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA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ensed under BSL 1.1. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* The e3 worker's side of `e3.fetch`: {@link serveBridge}, which boots the
|
|
7
|
+
* worker's e3, tells each page that says hello whether it is ready, and
|
|
8
|
+
* answers the page's requests.
|
|
9
|
+
*
|
|
10
|
+
* `serveE3`, the e3 worker's public entry, serves through it: its boot opens
|
|
11
|
+
* the storage and the runner, and its handler is the app that mounts e3's
|
|
12
|
+
* routes.
|
|
13
|
+
*
|
|
14
|
+
* @packageDocumentation
|
|
15
|
+
*/
|
|
16
|
+
import { errorText, holdLifeline, protocolMessage, watchLifeline, } from './protocol.js';
|
|
17
|
+
/** Lets a response's body go unread. */
|
|
18
|
+
async function discard(response) {
|
|
19
|
+
await response.body?.cancel().catch(() => undefined);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Serves `e3.fetch` from an e3 worker: boots the worker's e3, tells each page
|
|
23
|
+
* that says hello whether it is ready, or that it failed, and answers each
|
|
24
|
+
* request the page posts with the boot's handler.
|
|
25
|
+
*
|
|
26
|
+
* @param boot - Boots the worker's e3: resolves to the handler that answers
|
|
27
|
+
* requests, and whether the worker keeps repositories past the page; or
|
|
28
|
+
* rejects with what failed — a browser API it lacks, named — which the
|
|
29
|
+
* page's `createWebE3` rejects with
|
|
30
|
+
* @param endpoint - What the page's messages come over: the worker's global
|
|
31
|
+
* scope unless given, or a `MessagePort`
|
|
32
|
+
* @param options - Whether it holds and waits on lifelines, and what it tells
|
|
33
|
+
* when the page has gone
|
|
34
|
+
* @returns The bridge, which its host may end
|
|
35
|
+
*
|
|
36
|
+
* @remarks
|
|
37
|
+
* - The worker answers every hello, once its boot has settled: `ready`, or
|
|
38
|
+
* `boot-error` with what failed. A page that connects late — long after the
|
|
39
|
+
* boot, or a second time — is answered as the first.
|
|
40
|
+
* - The page posts its requests once it is told the worker is ready; a
|
|
41
|
+
* request that came sooner would wait for the boot.
|
|
42
|
+
* - Each request reaches the handler as a `Request` whose signal aborts when
|
|
43
|
+
* the page gives the request up, or when the bridge ends.
|
|
44
|
+
* - The handler's response is posted back: its status, status text, headers
|
|
45
|
+
* and body, the body whole and transferred. A `HEAD` request's response has
|
|
46
|
+
* no body, as `fetch` gives it none.
|
|
47
|
+
* - A handler that throws, or whose response's body fails, is answered with
|
|
48
|
+
* no response: the page's `fetch` rejects with a `TypeError` carrying what
|
|
49
|
+
* failed, as `fetch` rejects a network failure. An app answers its own
|
|
50
|
+
* errors with responses: Hono's `app.fetch` answers what a route throws
|
|
51
|
+
* with a 500.
|
|
52
|
+
* - Unless told otherwise, the worker holds a Web Lock for as long as it
|
|
53
|
+
* lives, and names it to the page, which learns from it that the worker has
|
|
54
|
+
* stopped. Over a port, the bridge ends when the page posts `close`, when
|
|
55
|
+
* the lifeline the page named is freed — its tab has gone — or when the port
|
|
56
|
+
* closes, where the platform says so; {@link BridgeOptions.onEnd} is told.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* // e3.worker.ts
|
|
61
|
+
* import { Hono } from 'hono';
|
|
62
|
+
* import { openWebStorage } from '@elaraai/e3-web';
|
|
63
|
+
*
|
|
64
|
+
* serveBridge(async () => {
|
|
65
|
+
* const storage = await openWebStorage(); // refuses, naming the API, in a browser that lacks one
|
|
66
|
+
* const app = new Hono();
|
|
67
|
+
* app.get('/api/repos', async (c) => c.json(await storage.repos.list()));
|
|
68
|
+
* return { fetch: app.fetch, persist: true };
|
|
69
|
+
* });
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export function serveBridge(boot, endpoint = globalThis, options = {}) {
|
|
73
|
+
const lifelines = options.lifelines ?? true;
|
|
74
|
+
/** The requests being answered, by number: what aborts each */
|
|
75
|
+
const answering = new Map();
|
|
76
|
+
const booted = Promise.resolve().then(boot);
|
|
77
|
+
// A boot that failed is told to each page that says hello.
|
|
78
|
+
booted.catch(() => undefined);
|
|
79
|
+
/** Aborted once the bridge ends: frees its lifeline, and withdraws its
|
|
80
|
+
* waits on the page's */
|
|
81
|
+
const ending = new AbortController();
|
|
82
|
+
const ended = new Promise((resolve) => {
|
|
83
|
+
ending.signal.addEventListener('abort', () => resolve(), { once: true });
|
|
84
|
+
});
|
|
85
|
+
/** The worker's lifeline, once taken: one for every page that says hello */
|
|
86
|
+
let lifeline = null;
|
|
87
|
+
const post = (message, transfer = []) => endpoint.postMessage(message, transfer);
|
|
88
|
+
const end = () => {
|
|
89
|
+
if (ending.signal.aborted)
|
|
90
|
+
return;
|
|
91
|
+
ending.abort();
|
|
92
|
+
for (const abort of answering.values())
|
|
93
|
+
abort.abort();
|
|
94
|
+
};
|
|
95
|
+
/** Ends the bridge as the page has gone, and says so. */
|
|
96
|
+
const gone = () => {
|
|
97
|
+
if (ending.signal.aborted)
|
|
98
|
+
return;
|
|
99
|
+
end();
|
|
100
|
+
options.onEnd?.();
|
|
101
|
+
};
|
|
102
|
+
/** Answers a page's hello, once the boot has settled. */
|
|
103
|
+
function greet(hello) {
|
|
104
|
+
if (lifelines)
|
|
105
|
+
watchLifeline(hello.lifeline, ending.signal, gone);
|
|
106
|
+
void booted.then(async ({ persist }) => {
|
|
107
|
+
const name = lifelines ? await (lifeline ??= holdLifeline('e3-web:worker', ended)) : null;
|
|
108
|
+
if (!ending.signal.aborted)
|
|
109
|
+
post({ kind: 'ready', persist, lifeline: name });
|
|
110
|
+
}, (err) => {
|
|
111
|
+
if (!ending.signal.aborted)
|
|
112
|
+
post({ kind: 'boot-error', message: errorText(err) });
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
/** Answers a request with the handler's response, or with what failed. */
|
|
116
|
+
async function answer(message) {
|
|
117
|
+
const { id } = message;
|
|
118
|
+
const abort = new AbortController();
|
|
119
|
+
answering.set(id, abort);
|
|
120
|
+
try {
|
|
121
|
+
const { fetch } = await booted;
|
|
122
|
+
const request = new Request(message.url, {
|
|
123
|
+
method: message.method,
|
|
124
|
+
headers: message.headers,
|
|
125
|
+
body: message.body,
|
|
126
|
+
signal: abort.signal,
|
|
127
|
+
});
|
|
128
|
+
const response = await fetch(request);
|
|
129
|
+
if (response.type === 'error')
|
|
130
|
+
throw new Error('its handler answered with a network error (Response.error())');
|
|
131
|
+
let body = null;
|
|
132
|
+
if (message.method === 'HEAD' || response.body === null || abort.signal.aborted)
|
|
133
|
+
await discard(response);
|
|
134
|
+
else
|
|
135
|
+
body = await response.arrayBuffer();
|
|
136
|
+
// A request the page has given up, or the bridge ended, is answered no
|
|
137
|
+
// more.
|
|
138
|
+
if (abort.signal.aborted)
|
|
139
|
+
return;
|
|
140
|
+
post({
|
|
141
|
+
kind: 'response',
|
|
142
|
+
id,
|
|
143
|
+
status: response.status,
|
|
144
|
+
statusText: response.statusText,
|
|
145
|
+
headers: [...response.headers],
|
|
146
|
+
body,
|
|
147
|
+
}, body === null ? [] : [body]);
|
|
148
|
+
}
|
|
149
|
+
catch (err) {
|
|
150
|
+
if (!abort.signal.aborted)
|
|
151
|
+
post({ kind: 'error', id, message: errorText(err) });
|
|
152
|
+
}
|
|
153
|
+
finally {
|
|
154
|
+
answering.delete(id);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
endpoint.addEventListener('message', (event) => {
|
|
158
|
+
if (ending.signal.aborted)
|
|
159
|
+
return;
|
|
160
|
+
const message = protocolMessage(event.data);
|
|
161
|
+
switch (message?.kind) {
|
|
162
|
+
case 'hello':
|
|
163
|
+
greet(message);
|
|
164
|
+
return;
|
|
165
|
+
case 'request':
|
|
166
|
+
void answer(message);
|
|
167
|
+
return;
|
|
168
|
+
case 'abort':
|
|
169
|
+
answering.get(message.id)?.abort();
|
|
170
|
+
return;
|
|
171
|
+
case 'close':
|
|
172
|
+
gone();
|
|
173
|
+
return;
|
|
174
|
+
default:
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
// A port's close event, where the platform fires one — Node's does, a
|
|
179
|
+
// browser's does not — says the page has gone. A worker's global scope
|
|
180
|
+
// never closes so; the worker ends.
|
|
181
|
+
endpoint.addEventListener('close', () => gone());
|
|
182
|
+
endpoint.start?.();
|
|
183
|
+
return { end };
|
|
184
|
+
}
|
|
185
|
+
//# sourceMappingURL=worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.js","sourceRoot":"","sources":["../../../src/bridge/worker.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;GAUG;AAEH,OAAO,EACL,SAAS,EACT,YAAY,EACZ,eAAe,EACf,aAAa,GAKd,MAAM,eAAe,CAAC;AA8DvB,wCAAwC;AACxC,KAAK,UAAU,OAAO,CAAC,QAAkB;IACvC,MAAM,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;AACvD,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,MAAM,UAAU,WAAW,CACzB,IAA+B,EAC/B,WAA2B,UAAuC,EAClE,UAAyB,EAAE;IAE3B,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,IAAI,CAAC;IAC5C,+DAA+D;IAC/D,MAAM,SAAS,GAAG,IAAI,GAAG,EAA2B,CAAC;IACrD,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5C,2DAA2D;IAC3D,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;IAC9B;8BAC0B;IAC1B,MAAM,MAAM,GAAG,IAAI,eAAe,EAAE,CAAC;IACrC,MAAM,KAAK,GAAG,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,EAAE;QAC1C,MAAM,CAAC,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,C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IAAI,EAAE,CAAC,CAAC;IACjD,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC;IAEnB,OAAO,EAAE,GAAG,EAAE,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Licensed under BSL 1.1. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
/** What the page's e3 says of the browser's keeping its repositories. */
|
|
6
|
+
export interface Persistence {
|
|
7
|
+
/** `persisted`, as `createWebE3` answered it */
|
|
8
|
+
readonly persisted: boolean;
|
|
9
|
+
/** How many times the page asked `navigator.storage.persist()` */
|
|
10
|
+
readonly asked: number;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=bridge.page.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge.page.d.ts","sourceRoot":"","sources":["../../../src/browser/bridge.page.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAkDH,yEAAyE;AACzE,MAAM,WAAW,WAAW;IAC1B,gDAAgD;IAChD,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,kEAAkE;IAClE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Licensed under BSL 1.1. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* The bridge specs' test page: it runs `e3.fetch`'s contract over dedicated
|
|
7
|
+
* workers — each a `bridge.worker.ts`, answering with the contract's plain
|
|
8
|
+
* handler — and what only a browser shows: a 64 MiB body each way, a worker
|
|
9
|
+
* that closes itself, an error a worker raises, and what the browser answers
|
|
10
|
+
* `navigator.storage.persist()`.
|
|
11
|
+
*
|
|
12
|
+
* The harness bundles it for Chromium; `bridge.spec.ts` drives it.
|
|
13
|
+
*
|
|
14
|
+
* @packageDocumentation
|
|
15
|
+
*/
|
|
16
|
+
import { createWebE3 } from '../bridge/page.js';
|
|
17
|
+
import { caseNamed, runAdapterCase } from '../testing/adapter-contract.js';
|
|
18
|
+
import { bridgeContract, browserBridgeContract, recordPosts } from '../testing/bridge-contract.js';
|
|
19
|
+
import { servePage } from './page.js';
|
|
20
|
+
const setup = (cleanup) => Promise.resolve({
|
|
21
|
+
// The worker's refused boot takes it away: see bridge.worker.ts.
|
|
22
|
+
missing: 'FileSystemFileHandle.move',
|
|
23
|
+
start: (boot) => {
|
|
24
|
+
const worker = new Worker(`/bridge-worker.js?boot=${boot}`, { type: 'module' });
|
|
25
|
+
cleanup(() => worker.terminate());
|
|
26
|
+
return { endpoint: worker, posted: recordPosts(worker), kill: () => worker.terminate() };
|
|
27
|
+
},
|
|
28
|
+
persistAsks: () => {
|
|
29
|
+
// The browser's own answers, recorded as the page asks.
|
|
30
|
+
const answers = [];
|
|
31
|
+
const storage = navigator.storage;
|
|
32
|
+
const persist = storage.persist.bind(storage);
|
|
33
|
+
Object.defineProperty(storage, 'persist', {
|
|
34
|
+
configurable: true,
|
|
35
|
+
value: async () => {
|
|
36
|
+
const answer = await persist();
|
|
37
|
+
answers.push(answer);
|
|
38
|
+
return answer;
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
cleanup(() => {
|
|
42
|
+
Reflect.deleteProperty(storage, 'persist');
|
|
43
|
+
});
|
|
44
|
+
return answers;
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
/** The cases the page runs, by the contract they are of. */
|
|
48
|
+
const contracts = { contract: bridgeContract, browser: browserBridgeContract };
|
|
49
|
+
servePage({
|
|
50
|
+
/** Runs a case of a contract over dedicated workers. */
|
|
51
|
+
runCase(contract, name) {
|
|
52
|
+
const cases = contracts[contract];
|
|
53
|
+
if (cases === undefined)
|
|
54
|
+
throw new Error(`no contract '${contract}'`);
|
|
55
|
+
return runAdapterCase(caseNamed(cases, name), setup);
|
|
56
|
+
},
|
|
57
|
+
/** Raises an error once the call has answered: what the harness keeps for
|
|
58
|
+
* a spec to see, though no call reports it. */
|
|
59
|
+
raiseLater(message) {
|
|
60
|
+
setTimeout(() => {
|
|
61
|
+
throw new Error(message);
|
|
62
|
+
});
|
|
63
|
+
},
|
|
64
|
+
/** Connects to a worker that keeps repositories, and answers what its e3
|
|
65
|
+
* says of the browser's keeping them. */
|
|
66
|
+
async persistence() {
|
|
67
|
+
let found;
|
|
68
|
+
await runAdapterCase({
|
|
69
|
+
name: 'persistence',
|
|
70
|
+
run: async ({ start, persistAsks }) => {
|
|
71
|
+
const answers = persistAsks();
|
|
72
|
+
const e3 = await createWebE3(start('persist').endpoint);
|
|
73
|
+
found = { persisted: e3.persisted, asked: answers.length };
|
|
74
|
+
},
|
|
75
|
+
}, setup);
|
|
76
|
+
return found;
|
|
77
|
+
},
|
|
78
|
+
});
|
|
79
|
+
//# sourceMappingURL=bridge.page.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge.page.js","sourceRoot":"","sources":["../../../src/browser/bridge.page.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,cAAc,EAAqB,MAAM,gCAAgC,CAAC;AAC9F,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,WAAW,EAAqC,MAAM,+BAA+B,CAAC;AACtI,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,KAAK,GAA8B,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC;IACpE,iEAAiE;IACjE,OAAO,EAAE,2BAA2B;IACpC,KAAK,EAAE,CAAC,IAAI,EAAE,EAAE;QACd,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,0BAA0B,IAAI,EAAE,EAAE,EAAE,IAA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AC;QACtE,OAAO,cAAc,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,EAAE,KAAK,CAAC,CAAC;IACvD,CAAC;IAED;oDACgD;IAChD,UAAU,CAAC,OAAe;QACxB,UAAU,CAAC,GAAG,EAAE;YACd,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;QAC3B,CAAC,CAAC,CAAC;IACL,CAAC;IAED;8CAC0C;IAC1C,KAAK,CAAC,WAAW;QACf,IAAI,KAA8B,CAAC;QACnC,MAAM,cAAc,CAAC;YACnB,IAAI,EAAE,aAAa;YACnB,GAAG,EAAE,KAAK,EAAE,EAAE,KAAK,EAAE,WAAW,EAAE,EAAE,EAAE;gBACpC,MAAM,OAAO,GAAG,WAAW,EAAE,CAAC;gBAC9B,MAAM,EAAE,GAAG,MAAM,WAAW,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC,QAAQ,CAAC,CAAC;gBACxD,KAAK,GAAG,EAAE,SAAS,EAAE,EAAE,CAAC,SAAS,EAAE,KAAK,EAAE,OAAO,CAAC,MAAM,EAAE,CAAC;YAC7D,CAAC;SACF,EAAE,KAAK,CAAC,CAAC;QACV,OAAO,KAAM,CAAC;IAChB,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge.spec.d.ts","sourceRoot":"","sources":["../../../src/browser/bridge.spec.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Licensed under BSL 1.1. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* `e3.fetch` in Chromium, over a dedicated worker: the contract
|
|
7
|
+
* `bridge/bridge.spec.ts` holds a `MessageChannel` to, each case a test of its
|
|
8
|
+
* own, run in a page whose workers answer with the contract's plain handler —
|
|
9
|
+
* its worker that stops mid-request is terminated — and what only a browser
|
|
10
|
+
* shows: a 64 MiB body each way, a worker that closes itself, an error a
|
|
11
|
+
* worker raises, and `persisted` as the browser answers
|
|
12
|
+
* `navigator.storage.persist()`. Each case ends asserting the page raised
|
|
13
|
+
* nothing, and the harness keeps an error a page raises after its last call
|
|
14
|
+
* for that to see.
|
|
15
|
+
*/
|
|
16
|
+
import { after, before, describe, it } from 'node:test';
|
|
17
|
+
import assert from 'node:assert/strict';
|
|
18
|
+
import { fileURLToPath } from 'node:url';
|
|
19
|
+
import { bridgeContract, browserBridgeContract } from '../testing/bridge-contract.js';
|
|
20
|
+
import { Harness } from './harness.js';
|
|
21
|
+
const entries = {
|
|
22
|
+
bridge: fileURLToPath(new URL('./bridge.page.js', import.meta.url)),
|
|
23
|
+
'bridge-worker': fileURLToPath(new URL('./bridge.worker.js', import.meta.url)),
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Grants a page's origin durable storage, as a browser grants it to a site it
|
|
27
|
+
* keeps, until the grant is reset.
|
|
28
|
+
*
|
|
29
|
+
* @returns What resets the page's browser context's permissions
|
|
30
|
+
*/
|
|
31
|
+
async function grantDurableStorage(page, origin) {
|
|
32
|
+
const context = page.page.context();
|
|
33
|
+
const browser = context.browser();
|
|
34
|
+
if (browser === null)
|
|
35
|
+
throw new Error('the page has no browser to grant durable storage');
|
|
36
|
+
const target = await context.newCDPSession(page.page);
|
|
37
|
+
const { targetInfo } = await target.send('Target.getTargetInfo');
|
|
38
|
+
await target.detach();
|
|
39
|
+
const { browserContextId } = targetInfo;
|
|
40
|
+
const session = await browser.newBrowserCDPSession();
|
|
41
|
+
await session.send('Browser.grantPermissions', { permissions: ['durableStorage'], origin, browserContextId });
|
|
42
|
+
return async () => {
|
|
43
|
+
await session.send('Browser.resetPermissions', { browserContextId });
|
|
44
|
+
await session.detach();
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
describe('e3.fetch in Chromium, over a dedicated worker', () => {
|
|
48
|
+
let harness;
|
|
49
|
+
/** The page each case runs in */
|
|
50
|
+
let page;
|
|
51
|
+
/** Runs a case in the page, which then has raised nothing. */
|
|
52
|
+
async function runCase(contract, name) {
|
|
53
|
+
await page.call('runCase', contract, name);
|
|
54
|
+
assert.deepEqual(page.raisedErrors.map((error) => error.stack ?? error.message), [], 'the page raised nothing');
|
|
55
|
+
}
|
|
56
|
+
before(async () => {
|
|
57
|
+
harness = await Harness.open({ entries });
|
|
58
|
+
page = await harness.newPage('bridge');
|
|
59
|
+
});
|
|
60
|
+
after(async () => {
|
|
61
|
+
await harness?.close();
|
|
62
|
+
});
|
|
63
|
+
describe('its contract', () => {
|
|
64
|
+
for (const { name } of bridgeContract)
|
|
65
|
+
it(name, () => runCase('contract', name));
|
|
66
|
+
});
|
|
67
|
+
describe('what only a browser shows', () => {
|
|
68
|
+
for (const { name } of browserBridgeContract)
|
|
69
|
+
it(name, () => runCase('browser', name));
|
|
70
|
+
it('reports as persisted what the browser answers navigator.storage.persist(), asking once', async () => {
|
|
71
|
+
assert.deepEqual(await page.call('persistence'), { persisted: false, asked: 1 }, 'a browser that does not keep the origin\'s storage answers no');
|
|
72
|
+
const reset = await grantDurableStorage(page, harness.origin);
|
|
73
|
+
try {
|
|
74
|
+
assert.deepEqual(await page.call('persistence'), { persisted: true, asked: 1 }, 'a browser that keeps it answers yes');
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
await reset();
|
|
78
|
+
}
|
|
79
|
+
assert.deepEqual(page.raisedErrors.map((error) => error.message), [], 'the page raised nothing');
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
describe('the harness', () => {
|
|
83
|
+
it('keeps an error a page raises after its last call, which no later call reports, and through a call whose answer nobody reads', async (t) => {
|
|
84
|
+
const raising = await harness.newPage('bridge');
|
|
85
|
+
t.after(() => raising.close());
|
|
86
|
+
/** Waits until the page has raised as many errors as named. */
|
|
87
|
+
const raised = async (count) => {
|
|
88
|
+
for (let waited = 0; raising.raisedErrors.length < count && waited < 10_000; waited += 10) {
|
|
89
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
await raising.call('raiseLater', 'raised after its call answered');
|
|
93
|
+
await raised(1);
|
|
94
|
+
// A call whose answer nobody reads, as a forwarded request's abort is,
|
|
95
|
+
// neither reports the error before it nor loses it.
|
|
96
|
+
raising.tell('raiseLater', 'raised after a call whose answer nobody reads');
|
|
97
|
+
await raised(2);
|
|
98
|
+
assert.deepEqual(raising.raisedErrors.map((error) => error.message), [
|
|
99
|
+
'raised after its call answered',
|
|
100
|
+
'raised after a call whose answer nobody reads',
|
|
101
|
+
]);
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
//# sourceMappingURL=bridge.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge.spec.js","sourceRoot":"","sources":["../../../src/browser/bridge.spec.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,WAAW,CAAC;AACxD,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAEtF,OAAO,EAAE,OAAO,EAAoB,MAAM,cAAc,CAAC;AAEzD,MAAM,OAAO,GAAG;IACd,MAAM,EAAE,aAAa,CAAC,IAAI,GAAG,CAAC,kBAAkB,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACnE,eAAe,EAAE,aAAa,CAAC,IAAI,GAAG,CAAC,oBAAoB,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;CAC/E,CAAC;AAEF;;;;;GAKG;AACH,KAAK,UAAU,mBAAmB,CAAC,IAAiB,EAAE,MA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G,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE;gBACnE,gCAAgC;gBAChC,+CAA+C;aAChD,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge.worker.d.ts","sourceRoot":"","sources":["../../../src/browser/bridge.worker.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Licensed under BSL 1.1. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* The e3 worker the bridge specs' page starts: it serves `e3.fetch` through
|
|
7
|
+
* `serveBridge` from a dedicated worker, answering with the contract's plain
|
|
8
|
+
* handler, booted as its URL's `boot` names (`persist`, `memory` or
|
|
9
|
+
* `refused`). A refused boot opens a persisted storage with `FileSystemFileHandle`'s
|
|
10
|
+
* `move` taken away, which `openWebStorage` refuses, naming it.
|
|
11
|
+
*
|
|
12
|
+
* The harness bundles it for Chromium; `bridge.page.ts` starts it.
|
|
13
|
+
*
|
|
14
|
+
* @packageDocumentation
|
|
15
|
+
*/
|
|
16
|
+
import { serveBridge } from '../bridge/worker.js';
|
|
17
|
+
import { openWebStorage } from '../storage/WebStorage.js';
|
|
18
|
+
import { contractBoot, contractWorker } from '../testing/bridge-handler.js';
|
|
19
|
+
/** Takes `move` from this worker's file handles, as a browser whose OPFS
|
|
20
|
+
* cannot move a file lacks it. */
|
|
21
|
+
function takeMoveAway() {
|
|
22
|
+
// The prototype that defines it: FileSystemFileHandle's in Chromium
|
|
23
|
+
let owner = FileSystemFileHandle.prototype;
|
|
24
|
+
while (owner !== null && !Object.prototype.hasOwnProperty.call(owner, 'move'))
|
|
25
|
+
owner = Object.getPrototypeOf(owner);
|
|
26
|
+
if (owner === null)
|
|
27
|
+
throw new Error('this browser\'s file handles have no move to take away');
|
|
28
|
+
Reflect.deleteProperty(owner, 'move');
|
|
29
|
+
}
|
|
30
|
+
const worker = contractWorker(globalThis);
|
|
31
|
+
serveBridge(contractBoot(new URL(self.location.href).searchParams.get('boot'), worker, async () => {
|
|
32
|
+
takeMoveAway();
|
|
33
|
+
await (await openWebStorage({ name: `e3-web-bridge-${crypto.randomUUID()}` })).close();
|
|
34
|
+
}), worker.endpoint);
|
|
35
|
+
//# sourceMappingURL=bridge.worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bridge.worker.js","sourceRoot":"","sources":["../../../src/browser/bridge.worker.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,WAAW,EAAuB,MAAM,qBAAqB,CAAC;AACvE,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE5E;mCACmC;AACnC,SAAS,YAAY;IACnB,oEAAoE;IACpE,IAAI,KAAK,GAAkB,oBAAoB,CAAC,SAAS,CAAC;IAC1D,OAAO,KAAK,KAAK,IAAI,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC;QAAE,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAkB,CAAC;IACrI,IAAI,KAAK,KAAK,IAAI;QAAE,MAAM,IAAI,KAAK,CAAC,wDAAwD,CAAC,CAAC;IAC9F,OAAO,CAAC,cAAc,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;AACxC,CAAC;AAED,MAAM,MAAM,GAAG,cAAc,CAAC,UAAuC,CAAC,CAAC;AACvE,WAAW,CAAC,YAAY,CAAC,IAAI,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,KAAK,IAAI,EAAE;IAChG,YAAY,EAAE,CAAC;IACf,MAAM,CAAC,MAAM,cAAc,CAAC,EAAE,IAAI,EAAE,iBAAiB,MAAM,CAAC,UAAU,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC;AACzF,CAAC,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC"}
|