@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,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Licensed under BSL 1.1. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* `WebTaskRunner` in Node: every runner case over the in-process unit workers
|
|
7
|
+
* and the adapters in memory, as `../browser/runner.spec.ts` runs them in
|
|
8
|
+
* Chromium over Web Workers, IndexedDB, OPFS and Web Locks; and what the
|
|
9
|
+
* in-process host does in place of terminating a thread, which it shares with
|
|
10
|
+
* the test: a unit whose run is aborted stops at its next platform call.
|
|
11
|
+
*
|
|
12
|
+
* The thread cases (`threadCases`) run in Chromium only: a unit that never
|
|
13
|
+
* yields its thread is ended by terminating the thread, and in process it is
|
|
14
|
+
* the test's.
|
|
15
|
+
*/
|
|
16
|
+
import { before, describe, it } from 'node:test';
|
|
17
|
+
import assert from 'node:assert/strict';
|
|
18
|
+
import { ArrayType, StringType } from '@elaraai/east';
|
|
19
|
+
import { datasetWrite, packageRead } from '@elaraai/e3-core/portable';
|
|
20
|
+
import { MemoryBlobs, MemoryFiles, MemoryLockSpace, MemoryRecordStore, openMemoryRecords } from '../storage/memory.js';
|
|
21
|
+
import { WebStorage } from '../storage/WebStorage.js';
|
|
22
|
+
import { runAdapterCase } from '../testing/adapter-contract.js';
|
|
23
|
+
import { FIXTURE_PACKAGE, FIXTURE_VERSION, runnerCases, runnerSetup, } from '../testing/runner-cases.js';
|
|
24
|
+
import { buildRunnerFixtures } from '../testing/runner-fixtures.js';
|
|
25
|
+
import { TEST_PLATFORM, testPlatform, testTicks } from '../testing/test-platform.js';
|
|
26
|
+
import { inProcessUnits } from './in-process.js';
|
|
27
|
+
/**
|
|
28
|
+
* A tab's storage over the adapters in memory, its origin's other sessions
|
|
29
|
+
* opened over the same lock space, and workers in this thread serving the
|
|
30
|
+
* specs' platform package beside the standard one.
|
|
31
|
+
*/
|
|
32
|
+
function environment(fixtures) {
|
|
33
|
+
return {
|
|
34
|
+
fixtures,
|
|
35
|
+
units: inProcessUnits({ platforms: { [TEST_PLATFORM]: testPlatform } }),
|
|
36
|
+
openStorage: async (cleanup) => {
|
|
37
|
+
const space = new MemoryLockSpace();
|
|
38
|
+
const storage = new WebStorage({
|
|
39
|
+
records: openMemoryRecords(new MemoryRecordStore()),
|
|
40
|
+
blobs: new MemoryBlobs(),
|
|
41
|
+
locks: await space.open(),
|
|
42
|
+
files: new MemoryFiles(),
|
|
43
|
+
});
|
|
44
|
+
cleanup(() => storage.close());
|
|
45
|
+
return { storage, openSession: () => space.open() };
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
/** Waits until `holds` does, checking every few milliseconds. */
|
|
50
|
+
async function until(what, holds) {
|
|
51
|
+
const deadline = Date.now() + 30_000;
|
|
52
|
+
while (!holds()) {
|
|
53
|
+
if (Date.now() > deadline)
|
|
54
|
+
throw new Error(`waited 30 s for ${what}`);
|
|
55
|
+
await new Promise((resolve) => setTimeout(resolve, 5));
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/** What the in-process host does in place of terminating a thread. */
|
|
59
|
+
const inProcessCase = {
|
|
60
|
+
name: 'stops a unit in process at its next platform call once its run is aborted, calling none after',
|
|
61
|
+
run: async (setup) => {
|
|
62
|
+
const runner = setup.runner(setup.pool({ width: 1 }));
|
|
63
|
+
const pkg = await packageRead(setup.storage, setup.repo, FIXTURE_PACKAGE, FIXTURE_VERSION);
|
|
64
|
+
const taskHash = pkg.tasks.get('ticking');
|
|
65
|
+
assert.ok(taskHash !== undefined);
|
|
66
|
+
const inputHashes = [await datasetWrite(setup.storage, setup.repo, ['a'], ArrayType(StringType))];
|
|
67
|
+
const from = testTicks();
|
|
68
|
+
const controller = new AbortController();
|
|
69
|
+
const running = runner.execute(setup.storage, taskHash, inputHashes, { signal: controller.signal });
|
|
70
|
+
// The unit ticks, a platform call every few milliseconds, until it is
|
|
71
|
+
// stopped.
|
|
72
|
+
await until('the unit to tick', () => testTicks() >= from + 3n);
|
|
73
|
+
controller.abort();
|
|
74
|
+
const result = await running;
|
|
75
|
+
assert.equal(result.cancelled, true);
|
|
76
|
+
const stopped = testTicks();
|
|
77
|
+
// Running, it would tick a score of times in this wait.
|
|
78
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
79
|
+
assert.equal(testTicks(), stopped, 'the unit made no platform call once its run was aborted');
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
describe('WebTaskRunner over in-process unit workers and the adapters in memory', () => {
|
|
83
|
+
let fixtures;
|
|
84
|
+
before(async () => {
|
|
85
|
+
fixtures = await buildRunnerFixtures();
|
|
86
|
+
});
|
|
87
|
+
for (const runnerCase of [...runnerCases, inProcessCase]) {
|
|
88
|
+
it(runnerCase.name, () => runAdapterCase(runnerCase, runnerSetup(environment(fixtures))));
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
//# sourceMappingURL=WebTaskRunner.spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WebTaskRunner.spec.js","sourceRoot":"","sources":["../../../src/execution/WebTaskRunner.spec.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;GAUG;AAEH,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,MAAM,MAAM,oBAAoB,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,eAAe,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AACvH,OAAO,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AACtD,OAAO,EAAE,cAAc,EAAoB,MAAM,gCAAgC,CAAC;AAClF,OAAO,EACL,eAAe,EACf,eAAe,EACf,WAAW,EACX,WAAW,GAIZ,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AACrF,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,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E,GAAG,CAAC,CAAC,CAAC;QACzD,MAAM,CAAC,KAAK,CAAC,SAAS,EAAE,EAAE,OAAO,EAAE,yDAAyD,CAAC,CAAC;IAChG,CAAC;CACF,CAAC;AAEF,QAAQ,CAAC,uEAAuE,EAAE,GAAG,EAAE;IACrF,IAAI,QAAwB,CAAC;IAE7B,MAAM,CAAC,KAAK,IAAI,EAAE;QAChB,QAAQ,GAAG,MAAM,mBAAmB,EAAE,CAAC;IACzC,CAAC,CAAC,CAAC;IAEH,KAAK,MAAM,UAAU,IAAI,CAAC,GAAG,WAAW,EAAE,aAAa,CAAC,EAAE,CAAC;QACzD,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE,GAAG,EAAE,CAAC,cAAc,CAAC,UAAU,EAAE,WAAW,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5F,CAAC;AACH,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Licensed under BSL 1.1. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* e3's own platform functions in a unit worker: e3-api-client's `Platform`,
|
|
7
|
+
* bound to a fetch into the e3 worker that started the unit worker, so an
|
|
8
|
+
* East program that calls `Platform.workspaceList` lists the workspaces of the
|
|
9
|
+
* e3 in its page, and nothing it calls reaches the network.
|
|
10
|
+
*
|
|
11
|
+
* @packageDocumentation
|
|
12
|
+
*/
|
|
13
|
+
import type { PlatformFunction } from '@elaraai/east/internal';
|
|
14
|
+
import type { UnitPlatformContext } from './unit-server.js';
|
|
15
|
+
/**
|
|
16
|
+
* The name a runner lists e3's platform functions under: the package whose
|
|
17
|
+
* `Platform` they are. A task lists it as a custom platform package:
|
|
18
|
+
* `platforms: ['@elaraai/east-node-std', { custom: '@elaraai/e3-api-client' }]`.
|
|
19
|
+
*/
|
|
20
|
+
export declare const E3_PLATFORM = "@elaraai/e3-api-client";
|
|
21
|
+
/**
|
|
22
|
+
* e3's platform functions for a unit, bound to the e3 worker that started its
|
|
23
|
+
* unit worker.
|
|
24
|
+
*
|
|
25
|
+
* @remarks
|
|
26
|
+
* Every request they make goes through `e3.fetch` over the port the e3 worker
|
|
27
|
+
* handed the unit worker as it started it, and the e3 worker answers it with
|
|
28
|
+
* its own app: the URL a program passes is `https://e3-web.invalid`, the
|
|
29
|
+
* in-page e3's `apiUrl`, and one on any other origin is refused rather than
|
|
30
|
+
* fetched. The token a program passes is sent as the request's bearer token,
|
|
31
|
+
* as it is sent to a server. A unit worker connects once, at the first unit
|
|
32
|
+
* that lists the package, and its units share the connection.
|
|
33
|
+
*
|
|
34
|
+
* @param context - The unit's context: the port of the e3 worker's services
|
|
35
|
+
* @returns The platform functions
|
|
36
|
+
* @throws {Error} When the unit worker was handed no port — its host is not an
|
|
37
|
+
* e3 worker's pool — or the e3 worker does not answer on it: the unit fails,
|
|
38
|
+
* naming why.
|
|
39
|
+
*/
|
|
40
|
+
export declare function e3Platform(context: UnitPlatformContext): Promise<readonly PlatformFunction[]>;
|
|
41
|
+
//# sourceMappingURL=e3-platform.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"e3-platform.d.ts","sourceRoot":"","sources":["../../../src/execution/e3-platform.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAG/D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAE5D;;;;GAIG;AACH,eAAO,MAAM,WAAW,2BAA2B,CAAC;AAMpD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,UAAU,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,SAAS,gBAAgB,EAAE,CAAC,CAkBnG"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Licensed under BSL 1.1. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
import { Platform } from '@elaraai/e3-api-client';
|
|
6
|
+
import { connectWebE3 } from '../bridge/page.js';
|
|
7
|
+
/**
|
|
8
|
+
* The name a runner lists e3's platform functions under: the package whose
|
|
9
|
+
* `Platform` they are. A task lists it as a custom platform package:
|
|
10
|
+
* `platforms: ['@elaraai/east-node-std', { custom: '@elaraai/e3-api-client' }]`.
|
|
11
|
+
*/
|
|
12
|
+
export const E3_PLATFORM = '@elaraai/e3-api-client';
|
|
13
|
+
/** Each unit worker's connection to its e3 worker, by the port it was
|
|
14
|
+
* handed: its units share it. */
|
|
15
|
+
const connections = new WeakMap();
|
|
16
|
+
/**
|
|
17
|
+
* e3's platform functions for a unit, bound to the e3 worker that started its
|
|
18
|
+
* unit worker.
|
|
19
|
+
*
|
|
20
|
+
* @remarks
|
|
21
|
+
* Every request they make goes through `e3.fetch` over the port the e3 worker
|
|
22
|
+
* handed the unit worker as it started it, and the e3 worker answers it with
|
|
23
|
+
* its own app: the URL a program passes is `https://e3-web.invalid`, the
|
|
24
|
+
* in-page e3's `apiUrl`, and one on any other origin is refused rather than
|
|
25
|
+
* fetched. The token a program passes is sent as the request's bearer token,
|
|
26
|
+
* as it is sent to a server. A unit worker connects once, at the first unit
|
|
27
|
+
* that lists the package, and its units share the connection.
|
|
28
|
+
*
|
|
29
|
+
* @param context - The unit's context: the port of the e3 worker's services
|
|
30
|
+
* @returns The platform functions
|
|
31
|
+
* @throws {Error} When the unit worker was handed no port — its host is not an
|
|
32
|
+
* e3 worker's pool — or the e3 worker does not answer on it: the unit fails,
|
|
33
|
+
* naming why.
|
|
34
|
+
*/
|
|
35
|
+
export async function e3Platform(context) {
|
|
36
|
+
const { port } = context;
|
|
37
|
+
if (port === null) {
|
|
38
|
+
throw new Error(`e3's platform functions (${E3_PLATFORM}) answer through the e3 worker that started this unit worker, and it handed none: ` +
|
|
39
|
+
'unit workers that run them are started by serveE3 from @elaraai/e3-web/worker');
|
|
40
|
+
}
|
|
41
|
+
let connection = connections.get(port);
|
|
42
|
+
if (connection === undefined) {
|
|
43
|
+
// A unit worker cannot ask the browser to keep the storage: only a page
|
|
44
|
+
// can, and the e3 worker's page has asked. It holds no lifeline: the pool
|
|
45
|
+
// that started it ends the e3 worker's side as it lets it go.
|
|
46
|
+
connection = connectWebE3(port, { requestPersistence: false, lifeline: false });
|
|
47
|
+
connections.set(port, connection);
|
|
48
|
+
}
|
|
49
|
+
const e3 = await connection;
|
|
50
|
+
return Platform.implementation({ fetch: e3.fetch });
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=e3-platform.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"e3-platform.js","sourceRoot":"","sources":["../../../src/execution/e3-platform.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAYH,OAAO,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAc,MAAM,mBAAmB,CAAC;AAG7D;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,wBAAwB,CAAC;AAEpD;kCACkC;AAClC,MAAM,WAAW,GAAG,IAAI,OAAO,EAA+B,CAAC;AAE/D;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,OAA4B;IAC3D,MAAM,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;IACzB,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;QAClB,MAAM,IAAI,KAAK,CACb,4BAA4B,WAAW,oFAAoF;YAC3H,+EAA+E,CAChF,CAAC;IACJ,CAAC;IACD,IAAI,UAAU,GAAG,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACvC,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;QAC7B,wEAAwE;QACxE,0EAA0E;QAC1E,8DAA8D;QAC9D,UAAU,GAAG,YAAY,CAAC,IAAI,EAAE,EAAE,kBAAkB,EAAE,KAAK,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC;QAChF,WAAW,CAAC,GAAG,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;IACpC,CAAC;IACD,MAAM,EAAE,GAAG,MAAM,UAAU,CAAC;IAC5B,OAAO,QAAQ,CAAC,cAAc,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC;AACtD,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Licensed under BSL 1.1. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
import type { UnitWorker } from './protocol.js';
|
|
6
|
+
import { type UnitPlatforms } from './unit-server.js';
|
|
7
|
+
/**
|
|
8
|
+
* How {@link inProcessUnits} serves units.
|
|
9
|
+
*/
|
|
10
|
+
export interface InProcessUnitsOptions {
|
|
11
|
+
/** An app's platform packages, by the name a runner lists each under:
|
|
12
|
+
* served beside the standard ones — east-node-std's and e3's own — as
|
|
13
|
+
* `serveUnits({ platforms })` serves them in a Web Worker */
|
|
14
|
+
readonly platforms?: UnitPlatforms;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* A factory of unit workers in this thread: what `WebTaskRunner`'s pool runs
|
|
18
|
+
* units on in e3's Node test pass, as it runs them on Web Workers in a
|
|
19
|
+
* browser.
|
|
20
|
+
*
|
|
21
|
+
* @param options - The app's platform packages, served beside the standard
|
|
22
|
+
* ones
|
|
23
|
+
* @returns The factory
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* const pool = new UnitPool({ units: inProcessUnits(), width: 4 });
|
|
28
|
+
* const runner = new WebTaskRunner({ repo: 'default', pool, locks: storage.adapters.locks });
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare function inProcessUnits(options?: InProcessUnitsOptions): () => UnitWorker;
|
|
32
|
+
//# sourceMappingURL=in-process.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"in-process.d.ts","sourceRoot":"","sources":["../../../src/execution/in-process.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAwBH,OAAO,KAAK,EAAe,UAAU,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,EAAkC,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEtF;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC;;kEAE8D;IAC9D,QAAQ,CAAC,SAAS,CAAC,EAAE,aAAa,CAAC;CACpC;AAuED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAAC,OAAO,GAAE,qBAA0B,GAAG,MAAM,UAAU,CAGpF"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Licensed under BSL 1.1. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
import { STANDARD_PLATFORMS, UnitServer } from './unit-server.js';
|
|
6
|
+
/**
|
|
7
|
+
* Wraps platform functions to refuse every call once a signal has aborted,
|
|
8
|
+
* and to fail every call still awaited when it does.
|
|
9
|
+
*
|
|
10
|
+
* @param functions - The platform functions
|
|
11
|
+
* @param signal - Aborted when the unit's worker is terminated
|
|
12
|
+
* @returns The functions, guarded
|
|
13
|
+
*/
|
|
14
|
+
function guarded(functions, signal) {
|
|
15
|
+
const terminated = () => new Error('the unit\'s worker was terminated');
|
|
16
|
+
const stopped = new Promise((_resolve, reject) => {
|
|
17
|
+
signal.addEventListener('abort', () => reject(terminated()), { once: true });
|
|
18
|
+
});
|
|
19
|
+
// Nothing else may ever await it.
|
|
20
|
+
stopped.catch(() => undefined);
|
|
21
|
+
const guard = (fn) => (...args) => {
|
|
22
|
+
if (signal.aborted)
|
|
23
|
+
throw terminated();
|
|
24
|
+
const answer = fn(...args);
|
|
25
|
+
return answer instanceof Promise ? Promise.race([answer, stopped]) : answer;
|
|
26
|
+
};
|
|
27
|
+
return functions.map((platform) => {
|
|
28
|
+
const fn = platform.fn;
|
|
29
|
+
// A generic function's `fn` makes its evaluator from its type parameters.
|
|
30
|
+
const generic = platform.type_parameters !== undefined && platform.type_parameters.length > 0;
|
|
31
|
+
return { ...platform, fn: generic ? (...types) => guard(fn(...types)) : guard(fn) };
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A unit worker in this thread: a {@link UnitServer} at one end of a
|
|
36
|
+
* `MessageChannel`, the pool at the other.
|
|
37
|
+
*/
|
|
38
|
+
class InProcessUnitWorker {
|
|
39
|
+
onmessage = null;
|
|
40
|
+
onerror = null;
|
|
41
|
+
channel = new MessageChannel();
|
|
42
|
+
stopped = new AbortController();
|
|
43
|
+
constructor(platforms) {
|
|
44
|
+
const { port1: host, port2: worker } = this.channel;
|
|
45
|
+
const server = new UnitServer({
|
|
46
|
+
// A terminated worker's answers are never heard.
|
|
47
|
+
postMessage: (message, transfer) => {
|
|
48
|
+
if (!this.stopped.signal.aborted)
|
|
49
|
+
worker.postMessage(message, transfer);
|
|
50
|
+
},
|
|
51
|
+
}, { platforms, guard: (functions) => guarded(functions, this.stopped.signal), signal: this.stopped.signal });
|
|
52
|
+
worker.onmessage = (event) => {
|
|
53
|
+
void server.receive(event.data);
|
|
54
|
+
};
|
|
55
|
+
host.onmessage = (event) => {
|
|
56
|
+
this.onmessage?.(event);
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
postMessage(message, transfer) {
|
|
60
|
+
this.channel.port1.postMessage(message, transfer);
|
|
61
|
+
}
|
|
62
|
+
terminate() {
|
|
63
|
+
if (this.stopped.signal.aborted)
|
|
64
|
+
return;
|
|
65
|
+
this.stopped.abort();
|
|
66
|
+
this.channel.port1.close();
|
|
67
|
+
this.channel.port2.close();
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* A factory of unit workers in this thread: what `WebTaskRunner`'s pool runs
|
|
72
|
+
* units on in e3's Node test pass, as it runs them on Web Workers in a
|
|
73
|
+
* browser.
|
|
74
|
+
*
|
|
75
|
+
* @param options - The app's platform packages, served beside the standard
|
|
76
|
+
* ones
|
|
77
|
+
* @returns The factory
|
|
78
|
+
*
|
|
79
|
+
* @example
|
|
80
|
+
* ```ts
|
|
81
|
+
* const pool = new UnitPool({ units: inProcessUnits(), width: 4 });
|
|
82
|
+
* const runner = new WebTaskRunner({ repo: 'default', pool, locks: storage.adapters.locks });
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
export function inProcessUnits(options = {}) {
|
|
86
|
+
const platforms = { ...STANDARD_PLATFORMS, ...options.platforms };
|
|
87
|
+
return () => new InProcessUnitWorker(platforms);
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=in-process.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"in-process.js","sourceRoot":"","sources":["../../../src/execution/in-process.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAyBH,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAsB,MAAM,kBAAkB,CAAC;AAYtF;;;;;;;GAOG;AACH,SAAS,OAAO,CAAC,SAAsC,EAAE,MAAmB;IAC1E,MAAM,UAAU,GAAG,GAAU,EAAE,CAAC,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;IAC/E,MAAM,OAAO,GAAG,IAAI,OAAO,CAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE;QACtD,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;IAC/E,CAAC,CAAC,CAAC;IACH,kCAAkC;IAClC,OAAO,CAAC,KAAK,CAAC,GAAG,EAA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AAO,GAAG,EAAE,CAAC,IAAI,mBAAmB,CAAC,SAAS,CAAC,CAAC;AAClD,CAAC"}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Licensed under BSL 1.1. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* The unit workers a page's runners run units on: a pool of dedicated Web
|
|
7
|
+
* Workers, started from the factory the app gives, as wide as the machine's
|
|
8
|
+
* cores unless set.
|
|
9
|
+
*
|
|
10
|
+
* A unit takes one of the pool's places, and runs on an idle worker or on one
|
|
11
|
+
* the pool starts for it; past the pool's width it waits for a place, in the
|
|
12
|
+
* order units asked. A worker is started with `start`, handed the port of the
|
|
13
|
+
* services its host serves units when the pool was given one, and serves units
|
|
14
|
+
* once it answers `ready`. A unit's run is stopped by terminating its worker
|
|
15
|
+
* — when the run is aborted, or runs past its timeout — and the worker is
|
|
16
|
+
* replaced by the next unit that needs one. A worker that fails, or never
|
|
17
|
+
* starts serving units, is let go the same way, failing the unit it was given;
|
|
18
|
+
* so is one that stops on its own — closes itself, say, which no event tells
|
|
19
|
+
* its pool — learned of through the Web Lock it holds while it lives. A worker
|
|
20
|
+
* let go has its host's services ended with it.
|
|
21
|
+
*
|
|
22
|
+
* @packageDocumentation
|
|
23
|
+
*/
|
|
24
|
+
import { type Unit, type UnitResult } from '@elaraai/east';
|
|
25
|
+
import { type UnitFile, type UnitWorker } from './protocol.js';
|
|
26
|
+
/**
|
|
27
|
+
* The services a host serves one unit worker: the port the worker is handed,
|
|
28
|
+
* and what ends them once the pool lets the worker go.
|
|
29
|
+
*/
|
|
30
|
+
export interface UnitConnection {
|
|
31
|
+
/** The port the worker is handed as it starts: its end of the services */
|
|
32
|
+
readonly port: MessagePort;
|
|
33
|
+
/**
|
|
34
|
+
* Ends the host's side, once the pool has let the worker go — terminated
|
|
35
|
+
* it, or learned it has stopped: what it was answering for the worker is
|
|
36
|
+
* given up, and its end of the port closed. A browser's port says nothing
|
|
37
|
+
* as the worker at its other end goes.
|
|
38
|
+
*/
|
|
39
|
+
close(): void;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* How a {@link UnitPool} starts its workers.
|
|
43
|
+
*/
|
|
44
|
+
export interface UnitPoolOptions {
|
|
45
|
+
/** Starts a unit worker: a dedicated Web Worker whose script calls
|
|
46
|
+
* `serveUnits()` from `@elaraai/e3-web/units`, or in-process ones
|
|
47
|
+
* (`inProcessUnits()`) */
|
|
48
|
+
readonly units: () => UnitWorker;
|
|
49
|
+
/** The most units that run at once, and so the most workers: the machine's
|
|
50
|
+
* cores (`navigator.hardwareConcurrency`) unless set */
|
|
51
|
+
readonly width?: number;
|
|
52
|
+
/**
|
|
53
|
+
* Makes the services each worker is handed as it starts: the port of what
|
|
54
|
+
* the host serves its units, such as a fetch into the e3 worker that e3's
|
|
55
|
+
* own platform functions are bound to, and what ends the host's side once
|
|
56
|
+
* the worker is let go. Unset, a worker is handed none.
|
|
57
|
+
*/
|
|
58
|
+
readonly connect?: () => UnitConnection;
|
|
59
|
+
/** How long a worker may take to start serving units, in milliseconds:
|
|
60
|
+
* 60 s unless set */
|
|
61
|
+
readonly startTimeoutMs?: number;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* How a unit's run ended.
|
|
65
|
+
*
|
|
66
|
+
* - `done`: the unit ran — its result, which says whether it succeeded, and
|
|
67
|
+
* every file it wrote, by its path relative to the unit;
|
|
68
|
+
* - `failed`: its worker could not run it: the worker failed, never started
|
|
69
|
+
* serving units, or could not read the unit — why, as the message says;
|
|
70
|
+
* - `aborted`: its run was aborted, before its worker was given it or while it
|
|
71
|
+
* ran, which terminated the worker;
|
|
72
|
+
* - `timed_out`: it ran past its timeout, which terminated its worker.
|
|
73
|
+
*/
|
|
74
|
+
export type UnitRun = {
|
|
75
|
+
readonly kind: 'done';
|
|
76
|
+
readonly result: UnitResult;
|
|
77
|
+
readonly files: ReadonlyMap<string, Uint8Array>;
|
|
78
|
+
} | {
|
|
79
|
+
readonly kind: 'failed';
|
|
80
|
+
readonly message: string;
|
|
81
|
+
} | {
|
|
82
|
+
readonly kind: 'aborted';
|
|
83
|
+
readonly started: boolean;
|
|
84
|
+
} | {
|
|
85
|
+
readonly kind: 'timed_out';
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* How {@link UnitPool.run} runs a unit.
|
|
89
|
+
*/
|
|
90
|
+
export interface UnitRunOptions {
|
|
91
|
+
/** Aborting it stops the unit: a unit waiting for its place never runs, and
|
|
92
|
+
* one running has its worker terminated */
|
|
93
|
+
readonly signal?: AbortSignal;
|
|
94
|
+
/** How long the unit may run once its worker has it, in milliseconds,
|
|
95
|
+
* before its worker is terminated: no limit unless set */
|
|
96
|
+
readonly timeoutMs?: number;
|
|
97
|
+
/** Hears what the unit's console writes, as it writes it */
|
|
98
|
+
readonly onLog?: (stream: 'stdout' | 'stderr', text: string) => void;
|
|
99
|
+
/**
|
|
100
|
+
* Called once the unit has a worker serving units, before the worker is
|
|
101
|
+
* given it: where a runner records its execution `running`. When it throws,
|
|
102
|
+
* the unit is not run, and the run throws what it threw.
|
|
103
|
+
*/
|
|
104
|
+
readonly onStart?: () => Promise<void>;
|
|
105
|
+
/** Called with 0 when the unit waits for its place, and with `null` once it
|
|
106
|
+
* has one or stops waiting: a wait for a core alone */
|
|
107
|
+
readonly onWaiting?: (needs: number | null) => void;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* A pool of unit workers, which a page's runners share.
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```ts
|
|
114
|
+
* const pool = new UnitPool({
|
|
115
|
+
* units: () => new Worker(new URL('./unit.worker.js', import.meta.url), { type: 'module' }),
|
|
116
|
+
* });
|
|
117
|
+
* const run = await pool.run(unit, files, { timeoutMs: 60_000 });
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
export declare class UnitPool {
|
|
121
|
+
private readonly options;
|
|
122
|
+
/** The most units that run at once. */
|
|
123
|
+
readonly width: number;
|
|
124
|
+
private readonly startTimeoutMs;
|
|
125
|
+
/** Workers serving units, or starting to, with no run in flight */
|
|
126
|
+
private readonly idle;
|
|
127
|
+
/** Every worker not let go */
|
|
128
|
+
private readonly live;
|
|
129
|
+
/** The units waiting for a place, first first */
|
|
130
|
+
private readonly waiting;
|
|
131
|
+
/** The places taken */
|
|
132
|
+
private taken;
|
|
133
|
+
private nextId;
|
|
134
|
+
private closed;
|
|
135
|
+
/**
|
|
136
|
+
* @param options - Its worker factory, its width, the port each worker is
|
|
137
|
+
* handed, and how long a worker may take to start
|
|
138
|
+
* @throws {RangeError} When the width is not a whole number of at least one,
|
|
139
|
+
* or none is given and the platform reports no cores
|
|
140
|
+
*/
|
|
141
|
+
constructor(options: UnitPoolOptions);
|
|
142
|
+
/**
|
|
143
|
+
* Runs a unit on a worker of the pool, once it has a place.
|
|
144
|
+
*
|
|
145
|
+
* @param unit - The unit
|
|
146
|
+
* @param files - Every file it names, by its path relative to the unit: the
|
|
147
|
+
* bytes are the worker's once sent, so a caller keeps none of them
|
|
148
|
+
* @param options - Its signal and timeout, what hears its console and its
|
|
149
|
+
* wait for a place, and what records it running
|
|
150
|
+
* @returns How its run ended
|
|
151
|
+
* @throws {Error} When the pool is closed, or `onStart` throws.
|
|
152
|
+
*/
|
|
153
|
+
run(unit: Unit, files: Iterable<UnitFile>, options?: UnitRunOptions): Promise<UnitRun>;
|
|
154
|
+
/**
|
|
155
|
+
* Terminates every worker, whatever it runs, and refuses every unit after:
|
|
156
|
+
* a unit running fails, and one waiting for its place never runs.
|
|
157
|
+
*/
|
|
158
|
+
close(): void;
|
|
159
|
+
/** Starts a worker. */
|
|
160
|
+
private start;
|
|
161
|
+
/**
|
|
162
|
+
* Takes a place for a unit: at once while the pool has one, and otherwise
|
|
163
|
+
* once a unit before it leaves one.
|
|
164
|
+
*
|
|
165
|
+
* @returns Whether it took one: not when the run was aborted, or the pool
|
|
166
|
+
* closed, while it waited
|
|
167
|
+
*/
|
|
168
|
+
private place;
|
|
169
|
+
/** Leaves a place: to the unit waiting longest, or free. */
|
|
170
|
+
private leave;
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=pool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pool.d.ts","sourceRoot":"","sources":["../../../src/execution/pool.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAA8D,KAAK,IAAI,EAAE,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAEvH,OAAO,EAAc,KAAK,QAAQ,EAAE,KAAK,UAAU,EAAsB,MAAM,eAAe,CAAC;AAK/F;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,0EAA0E;IAC1E,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAC3B;;;;;OAKG;IACH,KAAK,IAAI,IAAI,CAAC;CACf;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;+BAE2B;IAC3B,QAAQ,CAAC,KAAK,EAAE,MAAM,UAAU,CAAC;IACjC;6DACyD;IACzD,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB;;;;;OAKG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,cAAc,CAAC;IACxC;0BACsB;IACtB,QAAQ,CAAC,cAAc,CAAC,EAAE,MAAM,CAAC;CAClC;AAED;;;;;;;;;;GAUG;AACH,MAAM,MAAM,OAAO,GACf;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;CAAE,GACvG;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,M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