@elaraai/e3-web 0.0.0-stage → 1.0.85
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,228 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Licensed under BSL 1.1. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Locks through Web Locks (`navigator.locks`), taken by the tab's session.
|
|
7
|
+
*
|
|
8
|
+
* A tab opens one session: an id it holds a Web Lock of its own under for as
|
|
9
|
+
* long as it lives. Every lock the tab takes is a Web Lock too, so when the
|
|
10
|
+
* tab closes, or crashes, the browser frees all of them, the session's among
|
|
11
|
+
* them. A lock holder another tab recorded names the session as its `bootId`,
|
|
12
|
+
* with pid 0, and a tab asks whether that holder is alive by asking Web Locks
|
|
13
|
+
* whether the session's lock is still held. So two tabs over one origin take
|
|
14
|
+
* locks as two processes over one directory do, and a closed tab's locks are
|
|
15
|
+
* free.
|
|
16
|
+
*
|
|
17
|
+
* @packageDocumentation
|
|
18
|
+
*/
|
|
19
|
+
import { AdapterClosedError, checkLockRequest } from './adapters.js';
|
|
20
|
+
/**
|
|
21
|
+
* The name of the Web Lock a session holds for as long as it lives: another
|
|
22
|
+
* tab that waits for it learns when the session has ended.
|
|
23
|
+
*
|
|
24
|
+
* @param prefix - What the session's lock names begin with
|
|
25
|
+
* @param session - The session's id
|
|
26
|
+
* @returns The Web Lock's name
|
|
27
|
+
*/
|
|
28
|
+
export function sessionLockName(prefix, session) {
|
|
29
|
+
return `${prefix}session:${session}`;
|
|
30
|
+
}
|
|
31
|
+
/** The Web Lock a name given to {@link WebLocks.acquire} is. */
|
|
32
|
+
function namedLockName(prefix, name) {
|
|
33
|
+
return `${prefix}lock:${name}`;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Opens the tab's session: takes the session's own Web Lock, which the tab
|
|
37
|
+
* holds until the session closes or the tab does.
|
|
38
|
+
*
|
|
39
|
+
* @param options - What the session's lock names begin with, and the lock
|
|
40
|
+
* manager
|
|
41
|
+
* @returns The session's locks
|
|
42
|
+
* @throws {Error} When the page has no Web Locks: it is not a secure context
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* const locks = await openWebLocks();
|
|
47
|
+
* const hold = await locks.acquire('main', 'exclusive', { wait: true, timeout: 30_000 });
|
|
48
|
+
* // another tab: await locks.isAlive(session) is true until this tab closes
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export async function openWebLocks(options = {}) {
|
|
52
|
+
const manager = options.manager ?? globalThis.navigator?.locks;
|
|
53
|
+
if (manager === undefined) {
|
|
54
|
+
throw new Error('Web Locks are not available: e3-web needs a secure context — https:, or http://localhost');
|
|
55
|
+
}
|
|
56
|
+
const prefix = options.prefix ?? 'e3:';
|
|
57
|
+
// Web Locks keeps the names that begin with '-' to itself.
|
|
58
|
+
if (prefix.startsWith('-'))
|
|
59
|
+
throw new TypeError(`a Web Locks prefix does not begin with '-': ${JSON.stringify(prefix)}`);
|
|
60
|
+
const session = crypto.randomUUID();
|
|
61
|
+
const held = await take(manager, sessionLockName(prefix, session), 'exclusive', { ifAvailable: true });
|
|
62
|
+
if (held === null)
|
|
63
|
+
throw new Error(`the session ${session} is open already`);
|
|
64
|
+
return new WebLocks(manager, prefix, session, held);
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Asks the lock manager for a lock, and answers once it has been granted, or
|
|
68
|
+
* refused.
|
|
69
|
+
*
|
|
70
|
+
* @param manager - The lock manager
|
|
71
|
+
* @param name - The Web Lock's name
|
|
72
|
+
* @param mode - How to hold it
|
|
73
|
+
* @param how - `ifAvailable`: refuse at once when it cannot be granted;
|
|
74
|
+
* `signal`: wait until it is granted or the signal aborts
|
|
75
|
+
* @returns The lock held, or `null` when it was refused
|
|
76
|
+
*/
|
|
77
|
+
function take(manager, name, mode, how) {
|
|
78
|
+
return new Promise((resolve, reject) => {
|
|
79
|
+
let release;
|
|
80
|
+
const released = new Promise((resolveRelease) => {
|
|
81
|
+
release = resolveRelease;
|
|
82
|
+
});
|
|
83
|
+
let answered = false;
|
|
84
|
+
const request = manager.request(name, { mode, ...how }, (lock) => {
|
|
85
|
+
answered = true;
|
|
86
|
+
if (lock === null) {
|
|
87
|
+
resolve(null);
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
90
|
+
resolve({
|
|
91
|
+
release: async () => {
|
|
92
|
+
release();
|
|
93
|
+
// The request settles once the manager has let the lock go.
|
|
94
|
+
await request;
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
return released;
|
|
98
|
+
});
|
|
99
|
+
request.catch((err) => {
|
|
100
|
+
if (answered)
|
|
101
|
+
return;
|
|
102
|
+
// A request aborted while it waited was refused; anything else failed.
|
|
103
|
+
if ('signal' in how && how.signal.aborted)
|
|
104
|
+
resolve(null);
|
|
105
|
+
else
|
|
106
|
+
reject(err instanceof Error ? err : new Error(`Web Locks refused ${name}: ${String(err)}`));
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* A tab's session over Web Locks: the {@link LocksAdapter} of a browser.
|
|
112
|
+
*
|
|
113
|
+
* @remarks
|
|
114
|
+
* Requests for a name are made of the lock manager in the order they were
|
|
115
|
+
* made of the session: a request that cannot be granted at once is refused,
|
|
116
|
+
* or waits behind the ones before it, as Web Locks queues them. A timeout
|
|
117
|
+
* bounds a wait for a name another holds; a name that can be granted at once
|
|
118
|
+
* is granted whatever the timeout.
|
|
119
|
+
*/
|
|
120
|
+
export class WebLocks {
|
|
121
|
+
manager;
|
|
122
|
+
prefix;
|
|
123
|
+
session;
|
|
124
|
+
own;
|
|
125
|
+
closed = false;
|
|
126
|
+
/** Aborted as the session closes: every request of it still waiting is
|
|
127
|
+
* refused */
|
|
128
|
+
closing = new AbortController();
|
|
129
|
+
/** The holds the session has not released */
|
|
130
|
+
holds = new Set();
|
|
131
|
+
/** For each name, what the last request for it settles once it has been
|
|
132
|
+
* made of the lock manager */
|
|
133
|
+
made = new Map();
|
|
134
|
+
/**
|
|
135
|
+
* @param manager - The lock manager
|
|
136
|
+
* @param prefix - What the session's lock names begin with
|
|
137
|
+
* @param session - The session's id
|
|
138
|
+
* @param own - The session's own lock
|
|
139
|
+
* @internal
|
|
140
|
+
*/
|
|
141
|
+
constructor(manager, prefix, session, own) {
|
|
142
|
+
this.manager = manager;
|
|
143
|
+
this.prefix = prefix;
|
|
144
|
+
this.session = session;
|
|
145
|
+
this.own = own;
|
|
146
|
+
}
|
|
147
|
+
assertOpen() {
|
|
148
|
+
if (this.closed)
|
|
149
|
+
throw new AdapterClosedError('locks');
|
|
150
|
+
}
|
|
151
|
+
async acquire(name, mode, options = {}) {
|
|
152
|
+
this.assertOpen();
|
|
153
|
+
checkLockRequest(mode, options);
|
|
154
|
+
const lock = namedLockName(this.prefix, name);
|
|
155
|
+
const previous = this.made.get(lock) ?? Promise.resolve();
|
|
156
|
+
let madeIt;
|
|
157
|
+
const made = new Promise((resolve) => {
|
|
158
|
+
madeIt = resolve;
|
|
159
|
+
});
|
|
160
|
+
this.made.set(lock, made);
|
|
161
|
+
try {
|
|
162
|
+
await previous;
|
|
163
|
+
if (this.closed)
|
|
164
|
+
return null;
|
|
165
|
+
const tried = await take(this.manager, lock, mode, { ifAvailable: true });
|
|
166
|
+
if (tried !== null)
|
|
167
|
+
return await this.keep(tried);
|
|
168
|
+
if (options.wait !== true)
|
|
169
|
+
return null;
|
|
170
|
+
const signal = options.timeout === undefined
|
|
171
|
+
? this.closing.signal
|
|
172
|
+
: AbortSignal.any([this.closing.signal, AbortSignal.timeout(options.timeout)]);
|
|
173
|
+
// The request that waits is made here, so the next request of the
|
|
174
|
+
// session for this name is made after it, and queues behind it.
|
|
175
|
+
const waiting = take(this.manager, lock, mode, { signal });
|
|
176
|
+
madeIt();
|
|
177
|
+
const held = await waiting;
|
|
178
|
+
return held === null ? null : await this.keep(held);
|
|
179
|
+
}
|
|
180
|
+
finally {
|
|
181
|
+
madeIt();
|
|
182
|
+
if (this.made.get(lock) === made)
|
|
183
|
+
this.made.delete(lock);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/** Keeps a lock granted as a hold of the session, unless the session has
|
|
187
|
+
* closed meanwhile, when it lets the lock go. */
|
|
188
|
+
async keep(held) {
|
|
189
|
+
if (this.closed) {
|
|
190
|
+
await held.release();
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
let released = false;
|
|
194
|
+
const hold = {
|
|
195
|
+
release: async () => {
|
|
196
|
+
if (released)
|
|
197
|
+
return;
|
|
198
|
+
released = true;
|
|
199
|
+
this.holds.delete(hold);
|
|
200
|
+
await held.release();
|
|
201
|
+
},
|
|
202
|
+
};
|
|
203
|
+
this.holds.add(hold);
|
|
204
|
+
return hold;
|
|
205
|
+
}
|
|
206
|
+
async held(name) {
|
|
207
|
+
this.assertOpen();
|
|
208
|
+
const lock = namedLockName(this.prefix, name);
|
|
209
|
+
const { held = [] } = await this.manager.query();
|
|
210
|
+
return held.filter((info) => info.name === lock).map((info) => info.mode ?? 'exclusive').sort();
|
|
211
|
+
}
|
|
212
|
+
async isAlive(session) {
|
|
213
|
+
this.assertOpen();
|
|
214
|
+
const lock = sessionLockName(this.prefix, session);
|
|
215
|
+
const { held = [] } = await this.manager.query();
|
|
216
|
+
return held.some((info) => info.name === lock);
|
|
217
|
+
}
|
|
218
|
+
async close() {
|
|
219
|
+
if (this.closed)
|
|
220
|
+
return;
|
|
221
|
+
this.closed = true;
|
|
222
|
+
this.closing.abort();
|
|
223
|
+
for (const hold of [...this.holds])
|
|
224
|
+
await hold.release();
|
|
225
|
+
await this.own.release();
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
//# sourceMappingURL=web-locks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-locks.js","sourceRoot":"","sources":["../../../src/storage/web-locks.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAqE,MAAM,eAAe,CAAC;AAcxI;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAAC,MAAc,EAAE,OAAe;IAC7D,OAAO,GAAG,MAAM,WAAW,OAAO,EAAE,CAAC;AACvC,CAAC;AAED,gEAAgE;AAChE,SAAS,aAAa,CAAC,MAAc,EAAE,IAAY;IACjD,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MAAM,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;IAC3B,CAAC;CACF"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Licensed under BSL 1.1. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* The adapters' contract: what every implementation of the four adapters
|
|
7
|
+
* does, whether it keeps what it holds in memory, in IndexedDB, in OPFS, with
|
|
8
|
+
* Web Locks or on the machine.
|
|
9
|
+
*
|
|
10
|
+
* A case is a plain function over a setup, asserting with `./assert.js`, so
|
|
11
|
+
* it runs where its adapters are: in Node, registered as a `node:test` test
|
|
12
|
+
* over the in-memory adapters and the machine's files, and in a page over
|
|
13
|
+
* IndexedDB, OPFS and Web Locks, where the page runs it by name and the
|
|
14
|
+
* Node-side spec reports it as a test of its own.
|
|
15
|
+
*
|
|
16
|
+
* @packageDocumentation
|
|
17
|
+
*/
|
|
18
|
+
import { type BlobsAdapter, type FilesAdapter, type LocksAdapter, type RecordsAdapter } from '../storage/adapters.js';
|
|
19
|
+
/**
|
|
20
|
+
* A case of the contract: what it holds an adapter to, and how.
|
|
21
|
+
*/
|
|
22
|
+
export interface AdapterCase<S> {
|
|
23
|
+
/** What the case holds the adapter to, which names its test */
|
|
24
|
+
readonly name: string;
|
|
25
|
+
/** Runs the case over a fresh setup */
|
|
26
|
+
readonly run: (setup: S) => Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
/** Undoes part of a setup once its case has run. */
|
|
29
|
+
export type Cleanup = () => Promise<void> | void;
|
|
30
|
+
/**
|
|
31
|
+
* Makes a fresh setup for one case, registering what undoes it.
|
|
32
|
+
*
|
|
33
|
+
* @param cleanup - Registers what runs once the case has, last registered
|
|
34
|
+
* first, whether or not it passed
|
|
35
|
+
*/
|
|
36
|
+
export type AdapterSetup<S> = (cleanup: (undo: Cleanup) => void) => Promise<S>;
|
|
37
|
+
/**
|
|
38
|
+
* Runs a case over a fresh setup, and undoes the setup after.
|
|
39
|
+
*
|
|
40
|
+
* @param adapterCase - The case
|
|
41
|
+
* @param setup - Makes its setup
|
|
42
|
+
* @throws What the case throws; or, when it passed, what undoing its setup
|
|
43
|
+
* threw
|
|
44
|
+
*/
|
|
45
|
+
export declare function runAdapterCase<S>(adapterCase: AdapterCase<S>, setup: AdapterSetup<S>): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Finds a case of a contract by its name.
|
|
48
|
+
*
|
|
49
|
+
* @param contract - The contract
|
|
50
|
+
* @param name - The case's name
|
|
51
|
+
* @returns The case
|
|
52
|
+
* @throws {Error} When the contract has no case of that name
|
|
53
|
+
*/
|
|
54
|
+
export declare function caseNamed<S>(contract: readonly AdapterCase<S>[], name: string): AdapterCase<S>;
|
|
55
|
+
/**
|
|
56
|
+
* What a records case runs over: one store, which it opens adapters over.
|
|
57
|
+
*/
|
|
58
|
+
export interface RecordsSetup {
|
|
59
|
+
/** Opens an adapter over the setup's store: each another connection to
|
|
60
|
+
* it, as another tab's */
|
|
61
|
+
open(): Promise<RecordsAdapter>;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* What a blobs case runs over: an adapter over blobs of its own.
|
|
65
|
+
*/
|
|
66
|
+
export interface BlobsSetup {
|
|
67
|
+
/** The adapter, over no blobs yet */
|
|
68
|
+
readonly blobs: BlobsAdapter;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* What a locks case runs over: one origin's locks, which it opens sessions
|
|
72
|
+
* over.
|
|
73
|
+
*/
|
|
74
|
+
export interface LocksSetup {
|
|
75
|
+
/** Opens a session over the setup's locks: each another, as another tab's */
|
|
76
|
+
open(): Promise<LocksAdapter>;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The read size every files setup makes its adapter with: 100,000 bytes.
|
|
80
|
+
*
|
|
81
|
+
* @remarks
|
|
82
|
+
* No browser's stream of a file chunks by it. Chromium hands an OPFS file's
|
|
83
|
+
* stream over in multiples of 64 KiB, or whole, as its reads find it, so the
|
|
84
|
+
* 300,000 bytes of the contract's large file come back in three chunks of no
|
|
85
|
+
* more than 100,000 bytes from an adapter that slices them, and never from one
|
|
86
|
+
* that yields what the stream yields.
|
|
87
|
+
*/
|
|
88
|
+
export declare const CONTRACT_READ_CHUNK = 100000;
|
|
89
|
+
/**
|
|
90
|
+
* What a files case runs over: an adapter, and an empty directory of its own.
|
|
91
|
+
*/
|
|
92
|
+
export interface FilesSetup {
|
|
93
|
+
/** The adapter, made with the read size {@link CONTRACT_READ_CHUNK} */
|
|
94
|
+
readonly files: FilesAdapter;
|
|
95
|
+
/** A directory that is there, empty, for the case's files */
|
|
96
|
+
readonly dir: string;
|
|
97
|
+
/** The path of a name in a directory, as the adapter's paths join */
|
|
98
|
+
join(dir: string, name: string): string;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* The records adapter's contract.
|
|
102
|
+
*/
|
|
103
|
+
export declare const recordsContract: readonly AdapterCase<RecordsSetup>[];
|
|
104
|
+
/**
|
|
105
|
+
* The blobs adapter's contract.
|
|
106
|
+
*/
|
|
107
|
+
export declare const blobsContract: readonly AdapterCase<BlobsSetup>[];
|
|
108
|
+
/**
|
|
109
|
+
* The locks adapter's contract.
|
|
110
|
+
*/
|
|
111
|
+
export declare const locksContract: readonly AdapterCase<LocksSetup>[];
|
|
112
|
+
/**
|
|
113
|
+
* The files adapter's contract.
|
|
114
|
+
*/
|
|
115
|
+
export declare const filesContract: readonly AdapterCase<FilesSetup>[];
|
|
116
|
+
//# sourceMappingURL=adapter-contract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter-contract.d.ts","sourceRoot":"","sources":["../../../src/testing/adapter-contract.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;GAYG;AAEH,OAAO,EAEL,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,YAAY,EAGjB,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