@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,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Licensed under BSL 1.1. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* e3-web's own byte endpoints: what the URLs a {@link WebTransferBackend}
|
|
7
|
+
* gives answer, in the e3 worker — an upload's parts and an import's zip put,
|
|
8
|
+
* a dataset's object and an export's zip got — as the local server's data
|
|
9
|
+
* endpoints answer its own, over the backend's staged blobs rather than files.
|
|
10
|
+
*
|
|
11
|
+
* @packageDocumentation
|
|
12
|
+
*/
|
|
13
|
+
import { Hono } from 'hono';
|
|
14
|
+
import type { WebStorage } from '../storage/WebStorage.js';
|
|
15
|
+
import type { WebTransferBackend } from './WebTransferBackend.js';
|
|
16
|
+
/**
|
|
17
|
+
* The byte endpoints, mounted at `/api/uploads` and `/api/downloads`.
|
|
18
|
+
*/
|
|
19
|
+
export interface WebDataEndpoints {
|
|
20
|
+
/** `PUT /:id` — an import's zip; `PUT /:id/parts/:part` — one part of a
|
|
21
|
+
* dataset upload */
|
|
22
|
+
readonly uploads: Hono;
|
|
23
|
+
/** `GET /:id` — a dataset's object, or a completed export's zip */
|
|
24
|
+
readonly downloads: Hono;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Creates e3-web's byte endpoints over its transfer backend.
|
|
28
|
+
*
|
|
29
|
+
* @remarks
|
|
30
|
+
* - A body is sized by its bytes as they arrived, never by what a header
|
|
31
|
+
* claims. A body crosses from the page whole, so each is read whole: a
|
|
32
|
+
* part is at most the backend's part size, and an import's zip is the
|
|
33
|
+
* package's.
|
|
34
|
+
* - An import's zip of another size than its record's is refused, and the
|
|
35
|
+
* import forgotten, as the local server refuses it.
|
|
36
|
+
* - A part is checked against the range the upload's plan gives it before it
|
|
37
|
+
* is staged, so a part too long or too short stages nothing; a part sent
|
|
38
|
+
* again replaces itself; and a committed upload takes no more parts.
|
|
39
|
+
* - A download is served once: its record goes as it is answered.
|
|
40
|
+
*
|
|
41
|
+
* @param transfer - The transfer backend whose URLs these answer
|
|
42
|
+
* @param storage - The storage a dataset's object is read from
|
|
43
|
+
* @returns The two apps, to mount at `/api/uploads` and `/api/downloads`
|
|
44
|
+
*/
|
|
45
|
+
export declare function createWebDataEndpoints(transfer: WebTransferBackend, storage: WebStorage): WebDataEndpoints;
|
|
46
|
+
//# sourceMappingURL=endpoints.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"endpoints.d.ts","sourceRoot":"","sources":["../../../src/transfer/endpoints.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;GAOG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAK5B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AA8BlE;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;yBACqB;IACrB,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC;IACvB,mEAAmE;IACnE,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC;CAC1B;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,kBAAkB,EAAE,OAAO,EAAE,UAAU,GAAG,gBAAgB,CAkG1G"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Licensed under BSL 1.1. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* e3-web's own byte endpoints: what the URLs a {@link WebTransferBackend}
|
|
7
|
+
* gives answer, in the e3 worker — an upload's parts and an import's zip put,
|
|
8
|
+
* a dataset's object and an export's zip got — as the local server's data
|
|
9
|
+
* endpoints answer its own, over the backend's staged blobs rather than files.
|
|
10
|
+
*
|
|
11
|
+
* @packageDocumentation
|
|
12
|
+
*/
|
|
13
|
+
import { Hono } from 'hono';
|
|
14
|
+
import { IntegerType, equalFor, printFor } from '@elaraai/east';
|
|
15
|
+
import { BEAST2_CONTENT_TYPE, transferPartCount, transferPartRange } from '@elaraai/e3-types';
|
|
16
|
+
import { ObjectNotFoundError } from '@elaraai/e3-core/portable';
|
|
17
|
+
const sameInteger = equalFor(IntegerType);
|
|
18
|
+
const printInteger = printFor(IntegerType);
|
|
19
|
+
/**
|
|
20
|
+
* Refuses a request that carries credentials in an `Authorization` header, as
|
|
21
|
+
* the local server's data endpoints do: the transfer's id in the URL is its
|
|
22
|
+
* sole capability, as a presigned URL's signature is for e3-cloud. An empty
|
|
23
|
+
* header carries none, and is taken, as the local server takes it.
|
|
24
|
+
*/
|
|
25
|
+
function rejectAuthHeader(c) {
|
|
26
|
+
const authorization = c.req.header('authorization');
|
|
27
|
+
if (authorization !== undefined && authorization !== '') {
|
|
28
|
+
return new Response('Authorization header must not be sent to data endpoints', { status: 400 });
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
/** Bytes as a response's body takes them: over an `ArrayBuffer`, copied
|
|
33
|
+
* when they lie over any other buffer. */
|
|
34
|
+
function bodyOf(bytes) {
|
|
35
|
+
return bytes.buffer instanceof ArrayBuffer ? bytes : bytes.slice();
|
|
36
|
+
}
|
|
37
|
+
/** Answers that nothing is at a URL. */
|
|
38
|
+
function notFound() {
|
|
39
|
+
return new Response('Not found', { status: 404 });
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Creates e3-web's byte endpoints over its transfer backend.
|
|
43
|
+
*
|
|
44
|
+
* @remarks
|
|
45
|
+
* - A body is sized by its bytes as they arrived, never by what a header
|
|
46
|
+
* claims. A body crosses from the page whole, so each is read whole: a
|
|
47
|
+
* part is at most the backend's part size, and an import's zip is the
|
|
48
|
+
* package's.
|
|
49
|
+
* - An import's zip of another size than its record's is refused, and the
|
|
50
|
+
* import forgotten, as the local server refuses it.
|
|
51
|
+
* - A part is checked against the range the upload's plan gives it before it
|
|
52
|
+
* is staged, so a part too long or too short stages nothing; a part sent
|
|
53
|
+
* again replaces itself; and a committed upload takes no more parts.
|
|
54
|
+
* - A download is served once: its record goes as it is answered.
|
|
55
|
+
*
|
|
56
|
+
* @param transfer - The transfer backend whose URLs these answer
|
|
57
|
+
* @param storage - The storage a dataset's object is read from
|
|
58
|
+
* @returns The two apps, to mount at `/api/uploads` and `/api/downloads`
|
|
59
|
+
*/
|
|
60
|
+
export function createWebDataEndpoints(transfer, storage) {
|
|
61
|
+
const uploads = new Hono();
|
|
62
|
+
const downloads = new Hono();
|
|
63
|
+
// PUT /api/uploads/:id — an import's zip, staged for its trigger to process
|
|
64
|
+
uploads.put('/:id', async (c) => {
|
|
65
|
+
const rejected = rejectAuthHeader(c);
|
|
66
|
+
if (rejected !== null)
|
|
67
|
+
return rejected;
|
|
68
|
+
const id = c.req.param('id');
|
|
69
|
+
const record = await transfer.packageImport.get(id);
|
|
70
|
+
if (record === null)
|
|
71
|
+
return notFound();
|
|
72
|
+
const body = new Uint8Array(await c.req.arrayBuffer());
|
|
73
|
+
if (!sameInteger(BigInt(body.byteLength), record.size)) {
|
|
74
|
+
await transfer.packageImport.delete(id);
|
|
75
|
+
return new Response(`size mismatch: expected ${printInteger(record.size)}, got ${body.byteLength}`, { status: 400 });
|
|
76
|
+
}
|
|
77
|
+
await transfer.packageImport.stageZip(id, record.repo, body);
|
|
78
|
+
return new Response(null, { status: 200 });
|
|
79
|
+
});
|
|
80
|
+
// PUT /api/uploads/:id/parts/:part — one part of a dataset upload, staged
|
|
81
|
+
// whole in its own blob
|
|
82
|
+
uploads.put('/:id/parts/:part', async (c) => {
|
|
83
|
+
const rejected = rejectAuthHeader(c);
|
|
84
|
+
if (rejected !== null)
|
|
85
|
+
return rejected;
|
|
86
|
+
const id = c.req.param('id');
|
|
87
|
+
const record = await transfer.datasetUpload.get(id);
|
|
88
|
+
const partBytes = record === null ? null : await transfer.datasetUpload.getPartBytes(id);
|
|
89
|
+
if (record === null || partBytes === null)
|
|
90
|
+
return notFound();
|
|
91
|
+
// A part sent once the commit is under way could change the bytes it
|
|
92
|
+
// verifies.
|
|
93
|
+
if ((await transfer.datasetUpload.getCommitStatus(id)) !== null) {
|
|
94
|
+
return new Response('the upload is committed: it takes no more parts', { status: 409 });
|
|
95
|
+
}
|
|
96
|
+
const part = Number(c.req.param('part'));
|
|
97
|
+
const range = transferPartRange(record.size, partBytes, part);
|
|
98
|
+
if (range === null) {
|
|
99
|
+
return new Response(`No part ${c.req.param('part')}: the upload has ${transferPartCount(record.size, partBytes)} parts`, { status: 404 });
|
|
100
|
+
}
|
|
101
|
+
const expected = range.end - range.start;
|
|
102
|
+
const body = new Uint8Array(await c.req.arrayBuffer());
|
|
103
|
+
if (body.byteLength > expected) {
|
|
104
|
+
return new Response(`part ${part} is ${expected} bytes, and more were sent`, { status: 400 });
|
|
105
|
+
}
|
|
106
|
+
if (body.byteLength < expected) {
|
|
107
|
+
return new Response(`part ${part} is ${expected} bytes, got ${body.byteLength}`, { status: 400 });
|
|
108
|
+
}
|
|
109
|
+
await transfer.datasetUpload.stagePart(id, record.repo, part, body);
|
|
110
|
+
return new Response(null, { status: 200 });
|
|
111
|
+
});
|
|
112
|
+
// GET /api/downloads/:id — a dataset's object, or an export's zip
|
|
113
|
+
downloads.get('/:id', async (c) => {
|
|
114
|
+
const rejected = rejectAuthHeader(c);
|
|
115
|
+
if (rejected !== null)
|
|
116
|
+
return rejected;
|
|
117
|
+
const id = c.req.param('id');
|
|
118
|
+
const dataset = await transfer.datasetDownload.get(id);
|
|
119
|
+
if (dataset !== null) {
|
|
120
|
+
let data;
|
|
121
|
+
try {
|
|
122
|
+
data = await storage.objects.read(dataset.repo, dataset.hash);
|
|
123
|
+
}
|
|
124
|
+
catch (err) {
|
|
125
|
+
await transfer.datasetDownload.delete(id);
|
|
126
|
+
if (err instanceof ObjectNotFoundError)
|
|
127
|
+
return notFound();
|
|
128
|
+
throw err;
|
|
129
|
+
}
|
|
130
|
+
await transfer.datasetDownload.delete(id);
|
|
131
|
+
return new Response(bodyOf(data), {
|
|
132
|
+
headers: {
|
|
133
|
+
'Content-Type': BEAST2_CONTENT_TYPE,
|
|
134
|
+
'Content-Length': String(data.byteLength),
|
|
135
|
+
'X-Content-SHA256': dataset.hash,
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
const exported = await transfer.packageExport.get(id);
|
|
140
|
+
if (exported !== null && exported.status.type === 'completed') {
|
|
141
|
+
const zip = await transfer.packageExport.zipOf(id);
|
|
142
|
+
if (zip === null)
|
|
143
|
+
return notFound();
|
|
144
|
+
await transfer.packageExport.delete(id);
|
|
145
|
+
return new Response(bodyOf(zip), {
|
|
146
|
+
status: 200,
|
|
147
|
+
headers: {
|
|
148
|
+
'Content-Type': 'application/zip',
|
|
149
|
+
'Content-Length': String(zip.byteLength),
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
return notFound();
|
|
154
|
+
});
|
|
155
|
+
return { uploads, downloads };
|
|
156
|
+
}
|
|
157
|
+
//# sourceMappingURL=endpoints.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"endpoints.js","sourceRoot":"","sources":["../../../src/transfer/endpoints.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;GAOG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAE5B,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC9F,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAIhE,MAAM,WAAW,GAAG,QAAQ,CAAC,WAAW,CAAC,CAAC;AAC1C,MAAM,YAAY,GAAG,QAAQ,CAAC,WAAW,CAAC,CAAC;AAE3C;;;;;GAKG;AACH,SAAS,gBAAgB,CAAC,CAAU;IAClC,MAAM,aAAa,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;IACpD,IAAI,aAAa,KAAK,SAAS,IAAI,aAAa,KAAK,EAAE,EAAE,CAA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G,CAAC,EAAE,CAAC,CAAC;QACtD,IAAI,QAAQ,KAAK,IAAI,IAAI,QAAQ,CAAC,MAAM,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;YAC9D,MAAM,GAAG,GAAG,MAAM,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;YACnD,IAAI,GAAG,KAAK,IAAI;gBAAE,OAAO,QAAQ,EAAE,CAAC;YACpC,MAAM,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;YACxC,OAAO,IAAI,QAAQ,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE;gBAC/B,MAAM,EAAE,GAAG;gBACX,OAAO,EAAE;oBACP,cAAc,EAAE,iBAAiB;oBACjC,gBAAgB,EAAE,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC;iBACzC;aACF,CAAC,CAAC;QACL,CAAC;QAED,OAAO,QAAQ,EAAE,CAAC;IACpB,CAAC,CAAC,CAAC;IAEH,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC;AAChC,CAAC"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Licensed under BSL 1.1. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
import { type UnitPlatforms } from './execution/unit-server.js';
|
|
6
|
+
export { EAST_NODE_STD, STANDARD_PLATFORMS, type UnitPlatformContext, type UnitPlatformPackage, type UnitPlatforms, } from './execution/unit-server.js';
|
|
7
|
+
export { E3_PLATFORM } from './execution/e3-platform.js';
|
|
8
|
+
/**
|
|
9
|
+
* How {@link serveUnits} serves units.
|
|
10
|
+
*/
|
|
11
|
+
export interface ServeUnitsOptions {
|
|
12
|
+
/**
|
|
13
|
+
* An app's platform packages, by the name a runner lists each under in a
|
|
14
|
+
* unit: its platform functions, or what makes them for each unit from the
|
|
15
|
+
* unit's console and the port of its host's services. Served beside the
|
|
16
|
+
* standard ones ({@link STANDARD_PLATFORMS}): east-node-std's, which
|
|
17
|
+
* east-web-std answers, and e3's own; a package of one of their names here
|
|
18
|
+
* is served instead.
|
|
19
|
+
*/
|
|
20
|
+
readonly platforms?: UnitPlatforms;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Serves units in this dedicated Web Worker: what an app's unit worker script
|
|
24
|
+
* calls, once, for the e3 worker to run East programs on it.
|
|
25
|
+
*
|
|
26
|
+
* @remarks
|
|
27
|
+
* Each unit the e3 worker sends is run with east's `executeUnit` over its
|
|
28
|
+
* files in memory, its inputs staged whole: what its console writes goes to
|
|
29
|
+
* the execution's logs as it writes it. The worker holds a Web Lock while it
|
|
30
|
+
* lives, which its pool waits on: a worker that closes itself fails the unit
|
|
31
|
+
* it was running, and its place goes to another. A unit that calls e3's own platform
|
|
32
|
+
* functions reaches the e3 worker that started this one, over the port it
|
|
33
|
+
* handed it, and the e3 worker answers with its own API. A unit that lists a
|
|
34
|
+
* platform package this worker does not serve fails, naming the package; one
|
|
35
|
+
* that calls a platform function its packages do not provide — east-web-std
|
|
36
|
+
* has no FileSystem, Env or large-JSON reader — fails, naming the function.
|
|
37
|
+
*
|
|
38
|
+
* @param options - The app's platform packages, by name
|
|
39
|
+
* @throws {Error} When it is not called in a dedicated Web Worker.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```ts
|
|
43
|
+
* // unit.worker.ts — an app's own platform package beside the standard one
|
|
44
|
+
* import { serveUnits } from '@elaraai/e3-web/units';
|
|
45
|
+
* import { PricingPlatform } from './pricing-platform.js';
|
|
46
|
+
*
|
|
47
|
+
* serveUnits({ platforms: { '@acme/pricing': PricingPlatform } });
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
export declare function serveUnits(options?: ServeUnitsOptions): void;
|
|
51
|
+
//# sourceMappingURL=units.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"units.d.ts","sourceRoot":"","sources":["../../src/units.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA4BH,OAAO,EAAkC,KAAK,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAGhG,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,KAAK,mBAAmB,EACxB,KAAK,mBAAmB,EACxB,KAAK,aAAa,GACnB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAEzD;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;;;;;OAOG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,aAAa,CAAC;CACpC;AAQD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,UAAU,CAAC,OAAO,GAAE,iBAAsB,GAAG,IAAI,CAehE"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Licensed under BSL 1.1. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* The unit worker: where e3 runs East programs in a browser.
|
|
7
|
+
*
|
|
8
|
+
* An app's unit worker script calls {@link serveUnits}, and the e3 worker
|
|
9
|
+
* starts as many of them as its pool is wide. Each runs the units it is sent
|
|
10
|
+
* with east's `executeUnit` — the code east-node's `exec` runs — over the
|
|
11
|
+
* unit's files in memory. east-node-std's platform functions are answered by
|
|
12
|
+
* east-web-std's, so a task written for east-node runs unchanged; e3's own
|
|
13
|
+
* (`@elaraai/e3-api-client`'s `Platform`) reach the e3 worker that started the
|
|
14
|
+
* unit worker; and an app adds its own packages.
|
|
15
|
+
*
|
|
16
|
+
* This entry (`@elaraai/e3-web/units`) reaches nothing of Node, and nothing of
|
|
17
|
+
* the e3 worker's storage, so a unit worker bundles little more than East and
|
|
18
|
+
* e3's client.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* // unit.worker.ts
|
|
23
|
+
* import { serveUnits } from '@elaraai/e3-web/units';
|
|
24
|
+
* serveUnits();
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* @packageDocumentation
|
|
28
|
+
*/
|
|
29
|
+
import { holdLifeline } from './bridge/protocol.js';
|
|
30
|
+
import { STANDARD_PLATFORMS, UnitServer } from './execution/unit-server.js';
|
|
31
|
+
export { EAST_NODE_STD, STANDARD_PLATFORMS, } from './execution/unit-server.js';
|
|
32
|
+
export { E3_PLATFORM } from './execution/e3-platform.js';
|
|
33
|
+
/**
|
|
34
|
+
* Serves units in this dedicated Web Worker: what an app's unit worker script
|
|
35
|
+
* calls, once, for the e3 worker to run East programs on it.
|
|
36
|
+
*
|
|
37
|
+
* @remarks
|
|
38
|
+
* Each unit the e3 worker sends is run with east's `executeUnit` over its
|
|
39
|
+
* files in memory, its inputs staged whole: what its console writes goes to
|
|
40
|
+
* the execution's logs as it writes it. The worker holds a Web Lock while it
|
|
41
|
+
* lives, which its pool waits on: a worker that closes itself fails the unit
|
|
42
|
+
* it was running, and its place goes to another. A unit that calls e3's own platform
|
|
43
|
+
* functions reaches the e3 worker that started this one, over the port it
|
|
44
|
+
* handed it, and the e3 worker answers with its own API. A unit that lists a
|
|
45
|
+
* platform package this worker does not serve fails, naming the package; one
|
|
46
|
+
* that calls a platform function its packages do not provide — east-web-std
|
|
47
|
+
* has no FileSystem, Env or large-JSON reader — fails, naming the function.
|
|
48
|
+
*
|
|
49
|
+
* @param options - The app's platform packages, by name
|
|
50
|
+
* @throws {Error} When it is not called in a dedicated Web Worker.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* ```ts
|
|
54
|
+
* // unit.worker.ts — an app's own platform package beside the standard one
|
|
55
|
+
* import { serveUnits } from '@elaraai/e3-web/units';
|
|
56
|
+
* import { PricingPlatform } from './pricing-platform.js';
|
|
57
|
+
*
|
|
58
|
+
* serveUnits({ platforms: { '@acme/pricing': PricingPlatform } });
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export function serveUnits(options = {}) {
|
|
62
|
+
const DedicatedWorkerScope = globalThis.DedicatedWorkerGlobalScope;
|
|
63
|
+
if (DedicatedWorkerScope === undefined || !(globalThis instanceof DedicatedWorkerScope)) {
|
|
64
|
+
throw new Error('serveUnits serves units in a dedicated Web Worker: call it in the unit worker script the e3 worker starts');
|
|
65
|
+
}
|
|
66
|
+
const scope = globalThis;
|
|
67
|
+
// Held while the worker lives: the browser frees it once the worker stops.
|
|
68
|
+
const lifeline = holdLifeline('e3-web:unit', new Promise(() => undefined));
|
|
69
|
+
const server = new UnitServer({ postMessage: (message, transfer) => scope.postMessage(message, transfer) }, { platforms: { ...STANDARD_PLATFORMS, ...options.platforms }, lifeline: () => lifeline });
|
|
70
|
+
scope.onmessage = (event) => {
|
|
71
|
+
void server.receive(event.data);
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=units.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"units.js","sourceRoot":"","sources":["../../src/units.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAsB,MAAM,4BAA4B,CAAC;AAGhG,OAAO,EACL,aAAa,EACb,kBAAkB,GAInB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAuBzD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,UAAU,UAAU,CAAC,UAA6B,EAAE;IACxD,MAAM,oBAAoB,GAAI,UAAsC,CAAC,0BAAsE,CAAC;IAC5I,IAAI,oBAAoB,KAAK,SAAS,IAAI,CAAC,CAAC,UAAU,YAAY,oBAAoB,CAAC,EAAE,CAAC;QACxF,MAAM,IAAI,KAAK,CAAC,2GAA2G,CAAC,CAAC;IAC/H,CAAC;IACD,MAAM,KAAK,GAAG,UAAoC,CAAC;IACnD,2EAA2E;IAC3E,MAAM,QAAQ,GAAG,YAAY,CAAC,aAAa,EAAE,IAAI,OAAO,CAAO,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;IACjF,MAAM,MAAM,GAAG,IAAI,UAAU,CAC3B,EAAE,WAAW,EAAE,CAAC,OAAO,EAAE,QAAQ,EAAE,EAAE,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,EAAE,QAAQ,CAAC,EAAE,EAC5E,EAAE,SAAS,EAAE,EAAE,GAAG,kBAAkB,EAAE,GAAG,OAAO,CAAC,SAAS,EAAE,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,QAAQ,EAAE,CACzF,CAAC;IACF,KAAK,CAAC,SAAS,GAAG,CAAC,KAAK,EAAE,EAAE;QAC1B,KAAK,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2025 Elara AI Pty Ltd
|
|
3
|
+
* Licensed under BSL 1.1. See LICENSE for details.
|
|
4
|
+
*/
|
|
5
|
+
import { type OneShotAccess } from '@elaraai/e3-api-server/portable';
|
|
6
|
+
import { type Identify } from './app.js';
|
|
7
|
+
import { type BridgeEndpoint } from './bridge/worker.js';
|
|
8
|
+
import type { UnitWorker } from './execution/protocol.js';
|
|
9
|
+
export type { Identify } from './app.js';
|
|
10
|
+
export type { BridgeEndpoint } from './bridge/worker.js';
|
|
11
|
+
export type { UnitWorker } from './execution/protocol.js';
|
|
12
|
+
export { oneShotAccessByRoles, type Identity, type OneShotAccess } from '@elaraai/e3-api-server/portable';
|
|
13
|
+
/**
|
|
14
|
+
* How {@link serveE3} runs e3.
|
|
15
|
+
*/
|
|
16
|
+
export interface ServeE3Options {
|
|
17
|
+
/**
|
|
18
|
+
* Starts a unit worker: a dedicated Web Worker whose script calls
|
|
19
|
+
* `serveUnits()` from `@elaraai/e3-web/units`. The e3 worker starts as many
|
|
20
|
+
* as the machine has cores, and runs every unit of every task on them.
|
|
21
|
+
*/
|
|
22
|
+
readonly units: () => UnitWorker;
|
|
23
|
+
/**
|
|
24
|
+
* The grant each request's caller holds for what it supplies to run — a
|
|
25
|
+
* one-shot, a split call, a function call naming its own runner. Unless
|
|
26
|
+
* given, it is the local server's: by the caller's roles
|
|
27
|
+
* (`oneShotAccessByRoles()`) when {@link identify} says who calls, as a
|
|
28
|
+
* server with auth grants; and `any` when nothing does, since the page is
|
|
29
|
+
* then single-tenant, as a server without auth is.
|
|
30
|
+
*/
|
|
31
|
+
readonly access?: OneShotAccess;
|
|
32
|
+
/**
|
|
33
|
+
* Who calls: the identity of each request's caller, from the request, which
|
|
34
|
+
* {@link access} and the record routes read — a mutation commits as it, and
|
|
35
|
+
* compaction needs an elevated role. A request to a repository whose caller
|
|
36
|
+
* it does not identify is answered 401, as a server's auth answers one it
|
|
37
|
+
* cannot verify. Unset, no request has one: the page's one caller, who may
|
|
38
|
+
* do everything.
|
|
39
|
+
*/
|
|
40
|
+
readonly identify?: Identify;
|
|
41
|
+
/**
|
|
42
|
+
* Whether repositories outlive the page: kept in IndexedDB, OPFS and Web
|
|
43
|
+
* Locks (`true`, unless given), or in memory, starting fresh on every load
|
|
44
|
+
* (`false`), which needs none of them.
|
|
45
|
+
*/
|
|
46
|
+
readonly persist?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* What the storage is named after: `e3` unless given. Two e3 workers of one
|
|
49
|
+
* name, in one tab or two, share their repositories.
|
|
50
|
+
*/
|
|
51
|
+
readonly name?: string;
|
|
52
|
+
/**
|
|
53
|
+
* The largest delivery one intake unit takes in whole, in bytes:
|
|
54
|
+
* `WebTaskRunner`'s default, 256 MiB, unless given. A unit holds its
|
|
55
|
+
* delivery in memory, so an upload that cannot be cut into pieces is
|
|
56
|
+
* refused above it. One that is not a whole number of bytes, zero or more,
|
|
57
|
+
* is refused as the e3 boots.
|
|
58
|
+
*/
|
|
59
|
+
readonly wholeIntakeLimit?: number;
|
|
60
|
+
/**
|
|
61
|
+
* The size of every part of a dataset upload but the last, in bytes:
|
|
62
|
+
* 8 MiB unless given, since a part crosses from the page whole.
|
|
63
|
+
*/
|
|
64
|
+
readonly transferPartBytes?: number;
|
|
65
|
+
/**
|
|
66
|
+
* How long a dataset commit waits for its upload to be verified before it
|
|
67
|
+
* answers `processing` for the client to poll, in milliseconds: the routes'
|
|
68
|
+
* default, 5 s, unless given; 0 answers `processing` at once.
|
|
69
|
+
*/
|
|
70
|
+
readonly transferCommitWaitMs?: number;
|
|
71
|
+
/**
|
|
72
|
+
* The most bytes of a package's zip one round of an export writes before
|
|
73
|
+
* the e3 worker answers what waits — the page's requests — and writes the
|
|
74
|
+
* next: 16 MiB unless given.
|
|
75
|
+
*/
|
|
76
|
+
readonly transferExportRoundBytes?: number;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Runs e3 in this e3 worker, and serves it to the page: what an app's e3
|
|
80
|
+
* worker script calls, once.
|
|
81
|
+
*
|
|
82
|
+
* @remarks
|
|
83
|
+
* It boots, in order:
|
|
84
|
+
* - the storage (`openWebStorage`), which a browser that lacks IndexedDB,
|
|
85
|
+
* OPFS or Web Locks refuses, naming the API: the page's `createWebE3`
|
|
86
|
+
* rejects with that refusal. Not persisted, it needs none of them;
|
|
87
|
+
* - the state store every dataflow run keeps its state in (`WebStateStore`);
|
|
88
|
+
* - the unit pool, which starts unit workers from {@link ServeE3Options.units}
|
|
89
|
+
* and hands each a port to this e3, and each repository's runner over it
|
|
90
|
+
* (`WebTaskRunner`);
|
|
91
|
+
* - the orchestrator (`LocalOrchestrator`), which records a split task's own
|
|
92
|
+
* execution under the tab's session, as the runner records every other;
|
|
93
|
+
* - the transfer backend (`WebTransferBackend`), which records what a closed
|
|
94
|
+
* tab left — a job, or an upload's commit — failed, naming why, and never
|
|
95
|
+
* runs it again, and forgets what is past its retention while the tab
|
|
96
|
+
* lives;
|
|
97
|
+
* - the app: e3-api-server's routes over all of it (`createWebApp`).
|
|
98
|
+
*
|
|
99
|
+
* Every request the page's `e3.fetch` posts is then answered by the app, and
|
|
100
|
+
* so is every request a unit's e3 platform functions make, over its worker's
|
|
101
|
+
* port; once the pool lets a unit worker go, what the e3 was answering for it
|
|
102
|
+
* is given up. The page is told whether the repositories outlive it.
|
|
103
|
+
*
|
|
104
|
+
* Over a `MessagePort`, the e3 closes once its page has gone: the page's
|
|
105
|
+
* `e3.close()` tells it, the Web Lock the page holds while it is connected is
|
|
106
|
+
* freed — its tab closed — or the port closes, where the platform says so (a
|
|
107
|
+
* browser's port does not). Its unit workers are terminated, and its storage
|
|
108
|
+
* closed, which frees the tab's session for the next.
|
|
109
|
+
*
|
|
110
|
+
* @param options - The unit workers, who may run what, and how the
|
|
111
|
+
* repositories are kept
|
|
112
|
+
* @param endpoint - What the page's messages come over: this worker's global
|
|
113
|
+
* scope unless given, or a `MessagePort`
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```ts
|
|
117
|
+
* // e3.worker.ts — repositories in memory, gone with the page
|
|
118
|
+
* import { serveE3 } from '@elaraai/e3-web/worker';
|
|
119
|
+
* serveE3({
|
|
120
|
+
* units: () => new Worker(new URL('./unit.worker.ts', import.meta.url), { type: 'module' }),
|
|
121
|
+
* persist: false,
|
|
122
|
+
* });
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
export declare function serveE3(options: ServeE3Options, endpoint?: BridgeEndpoint): void;
|
|
126
|
+
//# sourceMappingURL=worker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"worker.d.ts","sourceRoot":"","sources":["../../src/worker.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAwBH,OAAO,EAAwB,KAAK,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAC3F,OAAO,EA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