@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
package/LICENSE.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Business Source License 1.1
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Elara AI Pty Ltd
|
|
4
|
+
|
|
5
|
+
## License
|
|
6
|
+
|
|
7
|
+
**Licensor:** Elara AI Pty Ltd
|
|
8
|
+
|
|
9
|
+
**Licensed Work:** @elaraai/e3-web
|
|
10
|
+
|
|
11
|
+
**Change Date:** Four years from the date of each release
|
|
12
|
+
|
|
13
|
+
**Change License:** AGPL-3.0
|
|
14
|
+
|
|
15
|
+
## Terms
|
|
16
|
+
|
|
17
|
+
The Licensed Work is provided under the terms of the Business Source License 1.1 as detailed below.
|
|
18
|
+
|
|
19
|
+
### Grant of Rights
|
|
20
|
+
|
|
21
|
+
The Licensor grants you the right to copy, modify, create derivative works, redistribute, and make non-production use of the Licensed Work.
|
|
22
|
+
|
|
23
|
+
### Production Use Limitation
|
|
24
|
+
|
|
25
|
+
**"Production Use"** means any use by or on behalf of a for-profit entity, other than for evaluation, testing, or development purposes.
|
|
26
|
+
|
|
27
|
+
Production Use requires a separate commercial license from the Licensor.
|
|
28
|
+
|
|
29
|
+
### Change Date
|
|
30
|
+
|
|
31
|
+
On the Change Date (four years after each release), the Licensed Work will be made available under the Change License (AGPL-3.0).
|
|
32
|
+
|
|
33
|
+
### No Warranty
|
|
34
|
+
|
|
35
|
+
THE LICENSED WORK IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND. THE LICENSOR DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|
36
|
+
|
|
37
|
+
### Package-Specific Licenses
|
|
38
|
+
|
|
39
|
+
Individual packages within this repository may have different licensing terms. See the LICENSE.md file in each package directory for details.
|
|
40
|
+
|
|
41
|
+
## Commercial Licensing
|
|
42
|
+
|
|
43
|
+
To obtain a commercial license for Production Use, contact:
|
|
44
|
+
|
|
45
|
+
**Email:** support@elara.ai
|
|
46
|
+
**Website:** https://elaraai.com
|
|
47
|
+
|
|
48
|
+
## Governing Law
|
|
49
|
+
|
|
50
|
+
This license is governed by the laws of New South Wales, Australia.
|
|
51
|
+
|
|
52
|
+
---
|
|
53
|
+
|
|
54
|
+
*Elara AI Pty Ltd*
|
package/README.md
CHANGED
|
@@ -1,3 +1,396 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @elaraai/e3-web
|
|
2
2
|
|
|
3
|
-
This
|
|
3
|
+
e3 running entirely in a browser: a repository kept in the page's own storage, with no server. This package is e3's third backend, beside the local one and e3-cloud. It keeps e3's records in IndexedDB, its objects in the origin private file system (OPFS), and its locks with Web Locks, runs every East program on a pool of Web Workers, and answers e3's whole API in the page: paged dataset reads and key search, function calls, one-shot and split calls, record mutations, deploys, uploads, imports and exports, and dataflow runs.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @elaraai/e3-web
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Using it
|
|
12
|
+
|
|
13
|
+
An app runs e3 in three scripts: the page, the e3 worker, and the unit workers the e3 worker starts.
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
// unit.worker.ts — where East programs run. east-web-std answers for east-node-std's
|
|
17
|
+
// platform functions, and e3's own reach the e3 worker; an app adds its own packages
|
|
18
|
+
// with serveUnits({ platforms })
|
|
19
|
+
import { serveUnits } from '@elaraai/e3-web/units';
|
|
20
|
+
serveUnits();
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
// e3.worker.ts — e3 itself: its storage, its orchestrator, its runner and its API
|
|
25
|
+
import { serveE3 } from '@elaraai/e3-web/worker';
|
|
26
|
+
serveE3({
|
|
27
|
+
units: () => new Worker(new URL('./unit.worker.ts', import.meta.url), { type: 'module' }),
|
|
28
|
+
});
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
// main.ts — the page
|
|
33
|
+
import { createWebE3 } from '@elaraai/e3-web';
|
|
34
|
+
import {
|
|
35
|
+
repoList, repoCreate, packageImport, workspaceCreate, workspaceDeploy, dataflowExecute,
|
|
36
|
+
} from '@elaraai/e3-api-client';
|
|
37
|
+
|
|
38
|
+
const e3 = await createWebE3(new Worker(new URL('./e3.worker.ts', import.meta.url), { type: 'module' }));
|
|
39
|
+
const opts = { token: null, fetch: e3.fetch };
|
|
40
|
+
|
|
41
|
+
// The first visit makes the repository; later visits find it where they left it.
|
|
42
|
+
if (!(await repoList(e3.apiUrl, opts)).includes('default')) {
|
|
43
|
+
await repoCreate(e3.apiUrl, 'default', opts);
|
|
44
|
+
// The package zip e3.export wrote at build time, served beside the page
|
|
45
|
+
const zip = new Uint8Array(await (await fetch('/sales-planning-1.0.0.zip')).arrayBuffer());
|
|
46
|
+
const { name, version } = await packageImport(e3.apiUrl, 'default', zip, opts);
|
|
47
|
+
await workspaceCreate(e3.apiUrl, 'default', 'main', opts);
|
|
48
|
+
await workspaceDeploy(e3.apiUrl, 'default', 'main', `${name}@${version}`, opts);
|
|
49
|
+
await dataflowExecute(e3.apiUrl, 'default', 'main', {}, opts);
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
A page that renders e3-ui surfaces gives e3-ui-components the same two things, `apiUrl` and `fetch`, in its `E3Config`. `<ReactiveDatasetProvider>` installs the adapters `Data.bind`, `Data.bindPaged`, `Func.bind` and `Record.bind` resolve through, and `<UITaskPreview>` renders a deployed `ui()` task; every request they make goes through `e3.fetch`, and is answered in the page:
|
|
54
|
+
|
|
55
|
+
```tsx
|
|
56
|
+
// main.tsx — a deployed ui() task, every request it makes answered in the page
|
|
57
|
+
import { createRoot } from 'react-dom/client';
|
|
58
|
+
import { ChakraProvider } from '@chakra-ui/react';
|
|
59
|
+
import { system } from '@elaraai/east-ui-components';
|
|
60
|
+
import { E3Provider, ReactiveDatasetProvider, UITaskPreview } from '@elaraai/e3-ui-components';
|
|
61
|
+
import { createWebE3 } from '@elaraai/e3-web';
|
|
62
|
+
|
|
63
|
+
const e3 = await createWebE3(new Worker(new URL('./e3.worker.ts', import.meta.url), { type: 'module' }));
|
|
64
|
+
|
|
65
|
+
createRoot(document.getElementById('root')!).render(
|
|
66
|
+
<ChakraProvider value={system}>
|
|
67
|
+
<E3Provider config={{ apiUrl: e3.apiUrl, repo: 'default', workspace: 'main', fetch: e3.fetch }}>
|
|
68
|
+
<ReactiveDatasetProvider>
|
|
69
|
+
<UITaskPreview task="dashboard" />
|
|
70
|
+
</ReactiveDatasetProvider>
|
|
71
|
+
</E3Provider>
|
|
72
|
+
</ChakraProvider>,
|
|
73
|
+
);
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## The page: `createWebE3`
|
|
77
|
+
|
|
78
|
+
`createWebE3` connects the page to its e3 worker. It gives the page `e3.fetch`, which the worker answers, and `e3.apiUrl`, the URL e3's client and e3-ui-components are given with it. No request reaches the network.
|
|
79
|
+
|
|
80
|
+
| Member | What it is |
|
|
81
|
+
|---|---|
|
|
82
|
+
| `apiUrl` | `https://e3-web.invalid`. Its origin is reserved, so a request that bypasses `e3.fetch` fails at once rather than reaching the network |
|
|
83
|
+
| `fetch` | The global `fetch`'s signature, answered by the worker: the `fetch` of e3-api-client's `RequestOptions` and e3-ui-components' `E3Config` |
|
|
84
|
+
| `persisted` | Whether the browser keeps the worker's repositories through storage pressure |
|
|
85
|
+
| `close()` | Terminates the worker, or, over a port, tells the e3 at its other end that the page has closed, which closes it, and closes the port. Every request pending rejects, naming the close, and every later one is refused |
|
|
86
|
+
|
|
87
|
+
How it behaves:
|
|
88
|
+
|
|
89
|
+
- **Boot.** The page says hello, and `createWebE3` resolves once the worker answers that it is ready, however long after its boot the page connects. If the worker's boot fails, `createWebE3` rejects with the boot's message, and the worker is closed. A browser that lacks an API e3 keeps repositories with fails this way, and the message names the API.
|
|
90
|
+
- **Requests.** `e3.fetch` posts each request's method, URL, every header and body to the worker, and resolves to a `Response` made of the worker's answer. It answers only `apiUrl`'s origin: any other is refused with a `TypeError` that names it, and nothing is posted. It follows no redirect.
|
|
91
|
+
- **Bodies** cross whole between the page and the worker, as `ArrayBuffer`s transferred rather than copied. The caller's own body is copied once, as `fetch` copies it, and stays the caller's.
|
|
92
|
+
- **Aborts.** A request's signal aborts it. The promise rejects with an `AbortError`, and the signal of the `Request` the worker's handler holds aborts too.
|
|
93
|
+
- **Failures.** A request the worker answers with no response, because its handler threw, rejects with a `TypeError` carrying what failed, as `fetch` rejects a network failure. An error the app answers with a response, a 500 say, is that response.
|
|
94
|
+
- **A worker that stops.** The worker may be terminated by other code, close itself, raise an error it does not catch, or send a message the page cannot read. Then every request pending rejects, naming what happened, and every later one is refused. The page learns that the worker has stopped through a Web Lock the worker holds while it lives, since no event tells it.
|
|
95
|
+
- **Over a port.** The page holds a Web Lock of its own while it is connected, and the e3 at the other end waits on it: the e3 closes once the page has gone, its tab closed, as it does when `close()` tells it. A browser's port says nothing as it closes.
|
|
96
|
+
- **Persistence.** When the worker keeps repositories past the page, `createWebE3` asks `navigator.storage.persist()`, which only a page can ask, and `persisted` is the browser's answer. An app that asks at a moment of its own choosing gives `requestPersistence: false`, since Firefox asks its user. `persisted` is then `navigator.storage.persisted()`'s answer.
|
|
97
|
+
|
|
98
|
+
The page and the worker speak `e3.fetch`'s protocol, a few messages over the worker's `postMessage`. The same messages work over a `MessagePort`, which is how the protocol is tested in Node.
|
|
99
|
+
|
|
100
|
+
## The e3 worker: `serveE3`
|
|
101
|
+
|
|
102
|
+
`serveE3`, from `@elaraai/e3-web/worker`, runs e3 in the worker and serves it to the page. It boots, in order:
|
|
103
|
+
|
|
104
|
+
1. the storage (`openWebStorage`): refused, naming the API, in a browser that lacks one, and `createWebE3` rejects with the refusal;
|
|
105
|
+
2. the state store every dataflow run keeps its state in (`WebStateStore`);
|
|
106
|
+
3. the unit pool, which starts unit workers from `units`, and each repository's runner over it (`WebTaskRunner`);
|
|
107
|
+
4. the orchestrator (`LocalOrchestrator`, as the local server runs it), which records a split task's own execution under the tab's session;
|
|
108
|
+
5. the transfer backend (`WebTransferBackend`), which records the jobs and commits a closed tab left failed, never running them again, and forgets what is past its retention while the tab lives;
|
|
109
|
+
6. the app: e3-api-server's own route factories, mounted as the local server mounts them over many repositories, beside e3-web's byte endpoints for uploads and downloads.
|
|
110
|
+
|
|
111
|
+
Every request the page's `e3.fetch` posts is answered by the app, and so is every request a unit's e3 platform functions make.
|
|
112
|
+
|
|
113
|
+
| Option | Default | Effect |
|
|
114
|
+
|---|---|---|
|
|
115
|
+
| `units` | — | Starts a unit worker: a Web Worker whose script calls `serveUnits()` |
|
|
116
|
+
| `access` | by roles, or `any` | The grant each request's caller holds for what it supplies to run — a one-shot, a split call, a function call naming its own runner. As the local server grants it: by the caller's roles (`oneShotAccessByRoles()`) when `identify` says who calls, and `any` when nothing does, the page being single-tenant then, as a server without auth is |
|
|
117
|
+
| `identify` | none | Who calls: the identity (`{ sub, email?, roles }`) of each request's caller, which `access` reads and the record routes commit as. A request to a repository whose caller it does not identify is answered 401, as a server's auth answers one it cannot verify: `Unauthorized: Missing Bearer token`, `Unauthorized: Invalid token`, or `Unauthorized: <why>` when it throws. With none, the page's one caller may do everything |
|
|
118
|
+
| `persist` | `true` | `false` keeps repositories in memory, gone with the page, and needs neither IndexedDB, OPFS nor Web Locks |
|
|
119
|
+
| `name` | `'e3'` | What the storage is named after. Two e3 workers of one name share their repositories, in one tab or several |
|
|
120
|
+
| `wholeIntakeLimit` | 256 MiB | The largest delivery one intake unit takes in whole. One that is not a whole number of bytes, zero or more, fails the boot, naming it |
|
|
121
|
+
| `transferPartBytes` | 8 MiB | The size of every part of a dataset upload but the last |
|
|
122
|
+
| `transferCommitWaitMs` | 5 000 | How long a dataset commit waits for its upload to be verified before it answers `processing` for the client to poll |
|
|
123
|
+
| `transferExportRoundBytes` | 16 MiB | The most bytes of a package's zip one round of an export writes before the worker answers what waits, the page's requests, and writes the next |
|
|
124
|
+
|
|
125
|
+
```typescript
|
|
126
|
+
// e3.worker.ts — callers known by their tokens, and granted by their roles
|
|
127
|
+
import { serveE3, oneShotAccessByRoles } from '@elaraai/e3-web/worker';
|
|
128
|
+
|
|
129
|
+
serveE3({
|
|
130
|
+
units: () => new Worker(new URL('./unit.worker.ts', import.meta.url), { type: 'module' }),
|
|
131
|
+
identify: (request) => callerOf(request.headers.get('authorization')),
|
|
132
|
+
access: oneShotAccessByRoles(),
|
|
133
|
+
});
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
`serveE3(options, port)` serves over a `MessagePort` instead of the worker's own scope, and closes once its page has gone: the page's `close()` tells it, the Web Lock the page holds while it is connected is freed as its tab closes, or the port closes where the platform says so, as Node's does and a browser's does not. Its unit workers are terminated and its storage closed, which frees its session. That is how e3's Node test pass runs it, with units in its own thread (`inProcessUnits()`).
|
|
137
|
+
|
|
138
|
+
## e3's own platform functions, in a unit
|
|
139
|
+
|
|
140
|
+
A task may call e3's own platform functions, e3-api-client's `Platform`, to reach the e3 it runs in. Every unit worker serves them, bound to the e3 worker that started it: the e3 worker hands each unit worker a port, and answers what comes over it with its own app. A task lists them under e3-api-client's name, and passes `https://e3-web.invalid` as the URL:
|
|
141
|
+
|
|
142
|
+
```typescript
|
|
143
|
+
import e3 from '@elaraai/e3';
|
|
144
|
+
import { ArrayType, East, StringType } from '@elaraai/east';
|
|
145
|
+
import { Platform } from '@elaraai/e3-api-client';
|
|
146
|
+
|
|
147
|
+
const repo = e3.input('repo', StringType);
|
|
148
|
+
const workspaces = e3.task('workspaces', [repo], East.asyncFunction([StringType], ArrayType(StringType), ($, name) => {
|
|
149
|
+
const found = $.let(Platform.workspaceList('https://e3-web.invalid', name, ''));
|
|
150
|
+
return found.map(($, workspace) => workspace.name);
|
|
151
|
+
}), { runner: { runtime: 'east-node', platforms: ['@elaraai/east-node-std', { custom: '@elaraai/e3-api-client' }] } });
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
A URL on any other origin is refused rather than fetched. The token a program passes is sent as the request's bearer token, as it is sent to a server, so `identify` knows the caller. Once the pool lets a unit worker go — its run aborted or timed out, or the worker stopped — what the e3 was answering for it is given up: a one-shot it was waiting on is stopped, its own worker terminated.
|
|
155
|
+
|
|
156
|
+
## Transfers: `WebTransferBackend`
|
|
157
|
+
|
|
158
|
+
`WebTransferBackend` implements e3-core's `TransferBackend`, all seven of its stores. Its URLs are e3-web's own byte endpoints, root-relative, which the routes resolve against `https://e3-web.invalid`, so they too are answered in the page.
|
|
159
|
+
|
|
160
|
+
| Store | What it does |
|
|
161
|
+
|---|---|
|
|
162
|
+
| Dataset uploads | Each part is staged whole in OPFS, sized by its bytes. The commit copies the parts into one buffer of the upload's size, hashes it once, and stores it as the object it hashes to — refused, with nothing written, when a part is missing or that is not the upload's hash — then adopts it (`datasetAdoptObject`), a collection taken in by intake units on the runner |
|
|
163
|
+
| Dataset downloads | A download URL is served once, from the object store |
|
|
164
|
+
| Package import | The zip a client uploads is staged in OPFS, and the job reads it as a `ZipSource`, by ranges |
|
|
165
|
+
| Package export | The job writes its zip through e3-core's portable sink a round at a time, each round's bytes a blob, the next round going on from where the last stopped. A workspace's export holds the workspace's lock across its rounds, so nothing changes it between them. An export that fails removes its rounds |
|
|
166
|
+
| Deploy, gc, split call | Run through e3-core's shared handlers, on the repository's runner |
|
|
167
|
+
|
|
168
|
+
Every job's status is a record, polled as the local server's is. A job, and an upload's commit, records the tab's session until it ends. What a closed tab left unfinished is never run again: the next tab to start over the same storage records it failed — "its tab closed before it finished" — and removes what it staged, since the client that knew of it closed with the tab, and the repository may have changed since. What a tab that lives runs is left to it. A job or a commit asked for twice at once runs once.
|
|
169
|
+
|
|
170
|
+
A finished job's status, and a finished commit's, stays readable for a poll for ten minutes, and a record nothing finished or fetched is forgotten after a day, with what it staged; a tab that lives forgets them every ten minutes (`WebTransferBackend`'s `retention`). gc sweeps what a transfer staged once its record is gone.
|
|
171
|
+
|
|
172
|
+
## The storage backend
|
|
173
|
+
|
|
174
|
+
`openWebStorage` opens `WebStorage`, which implements every method of e3-core's `StorageBackend`, so e3-core's portable logic (`@elaraai/e3-core/portable`) runs over it as it runs over a local repository:
|
|
175
|
+
|
|
176
|
+
```typescript
|
|
177
|
+
import { openWebStorage, WebStateStore } from '@elaraai/e3-web';
|
|
178
|
+
import { LocalOrchestrator, repoGc, repositoryOpen } from '@elaraai/e3-core/portable';
|
|
179
|
+
|
|
180
|
+
const storage = await openWebStorage(); // IndexedDB, OPFS and Web Locks, named `e3`
|
|
181
|
+
if (!(await storage.repos.exists('default'))) await storage.repos.create('default');
|
|
182
|
+
await repositoryOpen(storage, 'default');
|
|
183
|
+
|
|
184
|
+
const hash = await storage.objects.write('default', new TextEncoder().encode('an object'));
|
|
185
|
+
await repoGc(storage, 'default'); // holds the repository still, through Web Locks
|
|
186
|
+
|
|
187
|
+
// A dataflow run keeps its state in the same IndexedDB database
|
|
188
|
+
const orchestrator = new LocalOrchestrator(new WebStateStore(storage.adapters.records));
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
| Option | Default | Effect |
|
|
192
|
+
|---|---|---|
|
|
193
|
+
| `persist` | `true` | `false` keeps everything in memory: the page starts with no repositories on every load |
|
|
194
|
+
| `name` | `'e3'` | The IndexedDB database, the OPFS directory (`/<name>/blobs`, `/<name>/files`) and the Web Locks prefix (`<name>:`). Storages of one name share their repositories, in one tab or several |
|
|
195
|
+
|
|
196
|
+
A persisted storage first checks that the page has every API it keeps repositories with: IndexedDB, `navigator.storage.getDirectory`, `FileSystemFileHandle.createWritable` and `move`, and Web Locks. If one is missing, `openWebStorage` refuses before it opens anything, names the API, and suggests `persist: false`, which keeps repositories in memory instead.
|
|
197
|
+
|
|
198
|
+
How the backend keeps things:
|
|
199
|
+
|
|
200
|
+
- **Objects** are OPFS files, named by their SHA-256 in a catalogue of records. `readRange` reads a page of an object without reading the rest of it. Placing an object at a path copies its bytes (`placement` is `download`).
|
|
201
|
+
- **Records** are IndexedDB records: refs, dataset refs (whose `writeIf` compares the revision each write mints), executions, runs, logs, lock states, gc's notes and the transfers' jobs. A change that reads a record and writes it back is one transaction, so it loses no other tab's write.
|
|
202
|
+
- **Logs** are a record per append, keyed by the byte of the log it starts at. A read cuts its window from the few records it covers, however many appends the log took.
|
|
203
|
+
- **Locks** are Web Locks, held by the tab's session. A lock's holder is a `process` holder with pid 0 and the session's id as its `bootId`. `isHolderAlive` asks Web Locks whether that session is alive. Two tabs take locks as two processes over one local repository do, and a closed tab's locks are free.
|
|
204
|
+
- **gc** runs over it as over any backend: holding the repository still, or beside running work, in steps. Its `gcSweepBackend` removes what a tab closed mid-write left.
|
|
205
|
+
|
|
206
|
+
## The runner
|
|
207
|
+
|
|
208
|
+
`WebTaskRunner` implements e3-core's `TaskRunner`. It runs every unit — a task, a piece or a merge of a split task, a function call, an intake — on a worker of a `UnitPool`, with East's `executeUnit`, the code east-node's `exec` runs. `serveE3` makes the pool and a runner for each repository; a host of its own makes them itself:
|
|
209
|
+
|
|
210
|
+
```typescript
|
|
211
|
+
import { openWebStorage, UnitPool, WebTaskRunner } from '@elaraai/e3-web';
|
|
212
|
+
|
|
213
|
+
const storage = await openWebStorage();
|
|
214
|
+
const pool = new UnitPool({
|
|
215
|
+
units: () => new Worker(new URL('./unit.worker.js', import.meta.url), { type: 'module' }),
|
|
216
|
+
});
|
|
217
|
+
const runner = new WebTaskRunner({ repo: 'default', pool, locks: storage.adapters.locks });
|
|
218
|
+
const result = await runner.execute(storage, taskHash, inputHashes);
|
|
219
|
+
```
|
|
220
|
+
|
|
221
|
+
```typescript
|
|
222
|
+
// unit.worker.ts — where East programs run
|
|
223
|
+
import { serveUnits } from '@elaraai/e3-web/units';
|
|
224
|
+
import { PricingPlatform } from './pricing-platform.js';
|
|
225
|
+
|
|
226
|
+
// east-node-std's platform functions, answered by east-web-std's, e3's own, and an app's own package
|
|
227
|
+
serveUnits({ platforms: { '@acme/pricing': PricingPlatform } });
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
| What it runs | What it does |
|
|
231
|
+
|---|---|
|
|
232
|
+
| A task, or a unit of a split task | Runs it on a worker, its inputs read from the store and handed over whole. It records the execution as the local runner does: its owner (the tab's session), `running`, and then `success`, `failed` (exit code 1), `error` or `cancelled` |
|
|
233
|
+
| A split task (`e3.partition`) | Runs its pieces and merges through e3-core's engine, as many at once as the pool is wide. A relaunch is served from the execution cache |
|
|
234
|
+
| What a unit's console writes | Appends it to the execution's logs, as it writes it. A failure ends stderr as east-node's `exec` writes it: `Error: <message>`, then its ` at file:line:col` lines |
|
|
235
|
+
| A function call (`runDetached`) | Answers its value inline, and writes nothing durable. Past `timeoutMs` its worker is terminated and replaced; past `maxResultBytes` it is `too_large`; each log keeps its last `maxLogBytes` |
|
|
236
|
+
| An intake | Takes a run of a delivery's segments in, read from the store by ranges. A delivery with no index is taken in whole, up to `wholeIntakeLimit` |
|
|
237
|
+
| An aborted run | Terminates its worker, which the pool replaces, and records the execution `cancelled` |
|
|
238
|
+
| A unit whose worker stops on its own — closes itself, which no event says | Fails the unit, naming it, and gives its place to the next: the pool learns of it through the Web Lock each unit worker holds while it lives |
|
|
239
|
+
| A custom task, or a task on the custom runtime | Records it `error`: "a browser runs no commands" |
|
|
240
|
+
| A platform package its worker does not serve | Fails the unit, naming the package |
|
|
241
|
+
| A platform function no package provides (FileSystem, Env) | Fails the unit, naming the function |
|
|
242
|
+
|
|
243
|
+
An execution recorded `running` can still finish while the session of the tab that owns it lives: its Web Lock is held. A run whose tab closed is reported as the local server reports a run whose process died — its task `stale-running`, under pid 0, and its workspace free — and the next run is served the units that finished from the execution cache. Memory is not measured, so no record names a peak, and the pool's width is the only budget.
|
|
244
|
+
|
|
245
|
+
| Option | Default | Effect |
|
|
246
|
+
|---|---|---|
|
|
247
|
+
| `UnitPool` `units` | — | Starts a unit worker |
|
|
248
|
+
| `UnitPool` `width` | `navigator.hardwareConcurrency` | The most units that run at once |
|
|
249
|
+
| `UnitPool` `connect` | none | Makes the services each worker is handed as it starts: a port, which a platform package given as a function reaches, and what ends the host's side once the pool lets the worker go. `serveE3`'s serves e3's API over the port |
|
|
250
|
+
| `UnitPool` `startTimeoutMs` | 60 000 | How long a worker may take to start serving units |
|
|
251
|
+
| `WebTaskRunner` `wholeIntakeLimit` | 256 MiB | The largest delivery one intake unit takes in whole |
|
|
252
|
+
|
|
253
|
+
## What a browser cannot do
|
|
254
|
+
|
|
255
|
+
Each of these fails with a message naming it, and none is a partial answer:
|
|
256
|
+
|
|
257
|
+
- **Commands.** Custom tasks and command bodies are recorded `error`: a browser runs no commands.
|
|
258
|
+
- **Platform functions with no browser meaning.** east-web-std provides no FileSystem, Env or large-JSON reader, and east-node-io and everything Python have no browser equivalent. A unit calling one fails, naming the function.
|
|
259
|
+
- **Segments on demand.** A unit's inputs are staged whole into its worker, and the unit's `fetch` is false. The runner protocol's `fetch` waits for a segment synchronously, which a browser worker can do only on a `SharedArrayBuffer`, and a page has one only when it is cross-origin isolated, which GitHub Pages cannot give. A task over a large input splits it into pieces (`e3.partition`), as it bounds a unit's memory anywhere. An upload that cannot be cut into pieces is refused above `wholeIntakeLimit`, naming the fix.
|
|
260
|
+
- **Memory budget.** Memory is not measured: the pool is sized by cores, there is no memory budget, and records carry no peak memory.
|
|
261
|
+
- **The CLI.** The e3 CLI drives e3 over HTTP, which an in-page e3 does not serve.
|
|
262
|
+
|
|
263
|
+
## The storage adapters
|
|
264
|
+
|
|
265
|
+
e3-web keeps a repository over four small adapters, each with an implementation for the browser and one in memory:
|
|
266
|
+
|
|
267
|
+
| Adapter | Holds | In a browser | In memory (Node, `persist: false`) |
|
|
268
|
+
|---|---|---|---|
|
|
269
|
+
| `RecordsAdapter` | records, keyed and ordered, written in transactions | `openIndexedDbRecords` | `openMemoryRecords` |
|
|
270
|
+
| `BlobsAdapter` | blobs, read whole or by range | `OpfsBlobs` | `MemoryBlobs` |
|
|
271
|
+
| `LocksAdapter` | locks, exclusive and shared, held by a tab's session | `openWebLocks` | `MemoryLockSpace` |
|
|
272
|
+
| `FilesAdapter` | files named by path | `OpfsFiles` | `MemoryFiles`, or the machine's files: `NodeFiles` from `@elaraai/e3-web/node` |
|
|
273
|
+
|
|
274
|
+
```typescript
|
|
275
|
+
import { openIndexedDbRecords, OpfsBlobs, opfsDirectory, openWebLocks } from '@elaraai/e3-web';
|
|
276
|
+
|
|
277
|
+
const records = await openIndexedDbRecords('e3');
|
|
278
|
+
const blobs = new OpfsBlobs(await opfsDirectory('/e3/blobs'));
|
|
279
|
+
const locks = await openWebLocks();
|
|
280
|
+
|
|
281
|
+
// A compare-and-swap: transactions over one database run one after another, in any tab
|
|
282
|
+
await records.transact(async (tx) => {
|
|
283
|
+
const current = await tx.get(['refs', 'main']);
|
|
284
|
+
if (current === null) tx.put(['refs', 'main'], new TextEncoder().encode('first'));
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
// Blobs are written whole: a reader sees the old blob or the new one, never part of one
|
|
288
|
+
await blobs.write(['objects', 'ab12'], new TextEncoder().encode('an object'));
|
|
289
|
+
const head = await blobs.readRange(['objects', 'ab12'], 0, 2);
|
|
290
|
+
|
|
291
|
+
// A lock is held by the tab's session. When the tab closes, the lock is free,
|
|
292
|
+
// and another tab's `isAlive(locks.session)` answers false.
|
|
293
|
+
const hold = await locks.acquire('main', 'exclusive', { wait: true, timeout: 30_000 });
|
|
294
|
+
await hold?.release();
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
Each adapter's implementations answer alike. A records transaction's work awaits only its own operations, because IndexedDB commits a transaction as soon as it has nothing to do. Every implementation refuses work that awaits anything else. Locks are queued as Web Locks queue them. A file is read in slices of its adapter's read size, each 1 MiB (`FILE_READ_CHUNK`) but the last, unless the adapter is made with another (`readChunk`), whatever chunks a stream of the file would come in. An open that would upgrade an IndexedDB database, or a deletion, that another connection holds up is refused, naming why, once that connection has not closed in five seconds (`blockedMs`), rather than waited on for ever; one closing as it was asked, its last transactions finishing, lets it through.
|
|
298
|
+
|
|
299
|
+
The adapters need a secure context (`https:`, or `http://localhost`). They have been tested in Chromium.
|
|
300
|
+
|
|
301
|
+
## Tests
|
|
302
|
+
|
|
303
|
+
Every shared API suite of `@elaraai/e3-api-tests` — repository, packages, workspaces, datasets, dataset pages, dataset transfer, dataflow, functions with one-shot and split calls, records, keyed records, record deploys, package transfer and platform — passes against e3-web twice, as an admin and in its reader cases as a reader, with the global `fetch` refusing every request that does not go through `e3.fetch`:
|
|
304
|
+
|
|
305
|
+
- in Node, `serveE3` over a `MessageChannel`, in-memory repositories and units in the test's own thread (`libs/e3/test/integration`'s `web-compliance.spec.ts`);
|
|
306
|
+
- in Chromium, the suites in Node and each of their requests forwarded into a page running e3 over IndexedDB, OPFS, Web Workers and Web Locks (`e3-api.ts`, in parts, a spec file and a browser each).
|
|
307
|
+
|
|
308
|
+
In Chromium, specs also show that a task calling e3's own `Platform.workspaceList` from a unit worker lists the workspaces of the e3 in its page; that a dataflow interrupted by closing its page is reported by the next page as the local server reports a run whose process died, and that a new run there is served the pieces that finished from the execution cache; that the Web Locks the origin holds stay bounded across runs whose unit workers are terminated, a port a unit worker was handed holding none; that a one-shot a terminated unit was waiting on is stopped; and that an e3 served over a port closes, freeing its session, when its page closes its connection and when the page has gone. Every Chromium case ends asserting its page raised nothing, the harness keeping every error a page raised, a call reporting it or not. In Node, specs show `serveE3`'s boot, its refusal naming a missing API or a whole-intake limit it cannot use, its close with the page, a caller it does not know answered 401 and a reader's one-shot granted by roles, the in-process host clearing a terminated unit's timers, the forwarding fetch giving up in the page what Node aborted, every browser bundle naming none of Node's globals and warning of nothing, and the transfer backend's jobs: an export written a round at a time into the zip one round writes, holding its workspace across its rounds; what a closed tab left recorded failed, with what it staged removed, and what a live tab runs left to it; a job or a commit asked for twice at once run once; retention, and gc's sweep of what a transfer staged; and gc as a job. `libs/e3/test/integration`'s `dataset-transfer-parts.spec.ts` runs the byte endpoints' checks against the local server and e3-web alike.
|
|
309
|
+
|
|
310
|
+
`e3.fetch`'s contract runs twice: in Node, over a `MessageChannel`, and in Chromium, over a dedicated worker. Both times the worker answers with a plain handler. The contract covers:
|
|
311
|
+
|
|
312
|
+
- a round trip with a body each way, each transferred;
|
|
313
|
+
- a streamed body;
|
|
314
|
+
- headers, a header given twice among them;
|
|
315
|
+
- status and status text;
|
|
316
|
+
- empty bodies;
|
|
317
|
+
- a handler that throws;
|
|
318
|
+
- aborts before and during handling;
|
|
319
|
+
- a foreign origin refused;
|
|
320
|
+
- `close()`, and a worker that stops, with requests pending and after;
|
|
321
|
+
- a boot refused, naming the missing API;
|
|
322
|
+
- a page that connects after the worker booted, ready or refused;
|
|
323
|
+
- `persisted`.
|
|
324
|
+
|
|
325
|
+
In Chromium, specs also show a 64 MiB body each way, transferred, a worker that closes itself or raises an error mid-request, `persisted` as the browser answers, and the harness keeping an error a page raised after its last call.
|
|
326
|
+
|
|
327
|
+
Every contract suite a storage backend runs passes over `WebStorage` and `WebStateStore` in Node, over the in-memory adapters. The adapters' contract runs in Node over the in-memory adapters, and in Chromium over IndexedDB, OPFS and Web Locks. In Chromium, specs across pages show that:
|
|
328
|
+
|
|
329
|
+
- two tabs never hold one lock exclusively at once;
|
|
330
|
+
- a closed tab's locks are free, and its session has ended;
|
|
331
|
+
- what one tab writes, the tab after a reload reads;
|
|
332
|
+
- a repository one tab writes through the stores is read after a reload and by another tab, and gc collects only what nothing names;
|
|
333
|
+
- another tab sees who holds a workspace's lock while its holder lives, and can take the lock once the holder's tab has closed;
|
|
334
|
+
- a repository opened with `persist: false` is gone after a reload;
|
|
335
|
+
- a page whose OPFS cannot move a file is refused a persisted storage, which names the missing API and creates nothing;
|
|
336
|
+
- an IndexedDB database another connection holds open, and does not close, is refused to a deletion, naming why.
|
|
337
|
+
|
|
338
|
+
`WebTaskRunner`'s cases run in Node over workers in the test's own thread (`inProcessUnits`), and in Chromium over Web Workers, IndexedDB, OPFS and Web Locks. They run tasks of every output kind, a split task through its pieces and merges, failing, cancelled and refused tasks, function calls within their limits and past each, a one-shot, a split call, a record mutation, an intake, and the liveness of executions other tabs own. In Chromium, a call whose program never yields its thread is ended by terminating its worker, and one whose worker closes itself fails, its place going to the next. The tasks the cases run are a package written with e3's SDK, which the specs export in Node and hand to the page as data: the SDK is a dev dependency, and nothing a browser bundles reaches it.
|
|
339
|
+
|
|
340
|
+
In Chromium, east-node-std's compliance suite also passes over `@elaraai/east-web-std`, the browser's platform functions: every East test of its Console, Crypto, Fetch, Path, Random and Time modules. The spec reads the suite from `EAST_NODE_STD_IR`, where `make -C libs/east-node test-export-std` exports it — the workspace root's `paths.mk` sets it to the checkout's `tmp/east-node-std` when the tests run through make — and its Fetch tests call httpbin on `:8085`, which the workspace root's `make services-up` starts.
|
|
341
|
+
|
|
342
|
+
The Chromium specs launch the executable `E3_UI_CHROMIUM_PATH` names, when it is set. Otherwise they launch Playwright's managed Chromium:
|
|
343
|
+
|
|
344
|
+
```bash
|
|
345
|
+
pnpm --filter @elaraai/e3-web exec playwright-core install --only-shell chromium
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
## Claude Code plugin
|
|
349
|
+
|
|
350
|
+
The East ecosystem also ships a [Claude Code](https://claude.com/claude-code) plugin — East language skills, example search, and preemptive diagnostics for East code — installed separately from the `elaraai` marketplace:
|
|
351
|
+
|
|
352
|
+
```text
|
|
353
|
+
# Inside Claude Code
|
|
354
|
+
/plugin marketplace add elaraai/east-workspace
|
|
355
|
+
/plugin install east@elaraai
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
```bash
|
|
359
|
+
# From a terminal
|
|
360
|
+
claude plugin marketplace add elaraai/east-workspace
|
|
361
|
+
claude plugin install east@elaraai
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
## License
|
|
365
|
+
|
|
366
|
+
BSL 1.1. See [LICENSE.md](./LICENSE.md).
|
|
367
|
+
|
|
368
|
+
### Ecosystem
|
|
369
|
+
|
|
370
|
+
- **[East](https://github.com/elaraai/east-workspace/tree/main/libs/east)**: Statically typed, expression-based language with serializable IR. Run portable logic across TypeScript, Python, C, and other runtimes.
|
|
371
|
+
- [@elaraai/east](https://www.npmjs.com/package/@elaraai/east): Core language SDK with type system, expressions, and reference JS compiler
|
|
372
|
+
|
|
373
|
+
- **[e3 — East Execution Engine](https://github.com/elaraai/east-workspace/tree/main/libs/e3)**: Durable execution engine for running East pipelines at scale. Git-like content-addressable storage, automatic memoization, reactive dataflow, real-time monitoring.
|
|
374
|
+
- [@elaraai/e3](https://www.npmjs.com/package/@elaraai/e3): SDK for authoring e3 packages with typed tasks and pipelines
|
|
375
|
+
- [@elaraai/e3-core](https://www.npmjs.com/package/@elaraai/e3-core): Object store, dataflow orchestrator, execution state
|
|
376
|
+
- [@elaraai/e3-types](https://www.npmjs.com/package/@elaraai/e3-types): Shared type definitions for e3 packages
|
|
377
|
+
- [@elaraai/e3-cli](https://www.npmjs.com/package/@elaraai/e3-cli): `e3 repo`, `e3 package`, `e3 workspace`, `e3 dataflow run`, `e3 watch`, `e3 task logs` commands
|
|
378
|
+
- [@elaraai/e3-api-client](https://www.npmjs.com/package/@elaraai/e3-api-client): HTTP client for remote e3 repositories
|
|
379
|
+
- [@elaraai/e3-api-server](https://www.npmjs.com/package/@elaraai/e3-api-server): REST API server for e3 repositories
|
|
380
|
+
- [@elaraai/e3-api-tests](https://www.npmjs.com/package/@elaraai/e3-api-tests): Shared API compliance test suites
|
|
381
|
+
- [@elaraai/e3-web](https://www.npmjs.com/package/@elaraai/e3-web): e3 running in a browser
|
|
382
|
+
|
|
383
|
+
## Links
|
|
384
|
+
|
|
385
|
+
- [East Language](https://github.com/elaraai/east-workspace/tree/main/libs/east)
|
|
386
|
+
- [Elara AI](https://elaraai.com/)
|
|
387
|
+
- [Issues](https://github.com/elaraai/east-workspace/issues)
|
|
388
|
+
- support@elara.ai
|
|
389
|
+
|
|
390
|
+
## About Elara
|
|
391
|
+
|
|
392
|
+
East is developed by [Elara AI Pty Ltd](https://elaraai.com/), an AI-powered platform that creates economic digital twins of businesses that optimize performance. Elara combines business objectives, decisions and data to help organizations make data-driven decisions across operations, purchasing, sales and customer engagement, and project and investment planning. East powers the computational layer of Elara solutions, enabling the expression of complex business logic and data in a simple, type-safe and portable language.
|
|
393
|
+
|
|
394
|
+
---
|
|
395
|
+
|
|
396
|
+
*Developed by [Elara AI Pty Ltd](https://elaraai.com/).*
|
|
@@ -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
|
+
* e3's API in the e3 worker: {@link createWebApp}, the Hono app `serveE3`
|
|
7
|
+
* answers `e3.fetch` with. It mounts every route factory of e3-api-server's
|
|
8
|
+
* portable entry in multi-repository mode, in the order the local server
|
|
9
|
+
* mounts them, over e3-web's seams, beside e3-web's own byte endpoints.
|
|
10
|
+
*
|
|
11
|
+
* @packageDocumentation
|
|
12
|
+
*/
|
|
13
|
+
import { Hono } from 'hono';
|
|
14
|
+
import { type DataflowOrchestrator, type ExecutionStateStore, type TaskRunner } from '@elaraai/e3-core/portable';
|
|
15
|
+
import { type Identity, type OneShotAccess } from '@elaraai/e3-api-server/portable';
|
|
16
|
+
import type { WebStorage } from './storage/WebStorage.js';
|
|
17
|
+
import type { WebTransferBackend } from './transfer/WebTransferBackend.js';
|
|
18
|
+
/**
|
|
19
|
+
* Says who calls: the identity of a request's caller, or none.
|
|
20
|
+
*
|
|
21
|
+
* @remarks
|
|
22
|
+
* The identity is what a server's auth sets on a request's context, and what
|
|
23
|
+
* the routes that answer by who calls read: `oneShotAccessByRoles` grants by
|
|
24
|
+
* its roles, and the record routes commit as it and gate compaction on its
|
|
25
|
+
* roles. A request to a repository whose caller it gives none for is answered
|
|
26
|
+
* 401, as e3-api-server's auth middleware answers a caller it cannot verify:
|
|
27
|
+
* `Unauthorized: Missing Bearer token` with no bearer token, `Unauthorized:
|
|
28
|
+
* Invalid token` with one, and `Unauthorized: <message>` when it throws.
|
|
29
|
+
*
|
|
30
|
+
* @param request - The request, as the page sent it: its `Authorization`
|
|
31
|
+
* header among its headers
|
|
32
|
+
* @returns The caller's identity, or `null` or `undefined` for none
|
|
33
|
+
*/
|
|
34
|
+
export type Identify = (request: Request) => Identity | null | undefined | Promise<Identity | null | undefined>;
|
|
35
|
+
/**
|
|
36
|
+
* What {@link createWebApp} mounts the routes over.
|
|
37
|
+
*/
|
|
38
|
+
export interface WebAppSeams {
|
|
39
|
+
/** The storage the repositories are kept in */
|
|
40
|
+
readonly storage: WebStorage;
|
|
41
|
+
/** The transfers and jobs: its URLs are the byte endpoints this app serves */
|
|
42
|
+
readonly transfer: WebTransferBackend;
|
|
43
|
+
/** Each repository's runner */
|
|
44
|
+
readonly getRunner: (repo: string) => TaskRunner;
|
|
45
|
+
/** What runs every repository's dataflows, and cancels one */
|
|
46
|
+
readonly orchestrator: DataflowOrchestrator;
|
|
47
|
+
/** The store every repository's runs keep their state in: the one the
|
|
48
|
+
* orchestrator writes */
|
|
49
|
+
readonly stateStore: ExecutionStateStore;
|
|
50
|
+
/** The tasks and units a dataflow keeps in flight: the unit pool's width */
|
|
51
|
+
readonly width: number;
|
|
52
|
+
/** The grant each request's caller holds for what it supplies to run */
|
|
53
|
+
readonly access: OneShotAccess;
|
|
54
|
+
/** Who calls, when the host says: a request to a repository whose caller
|
|
55
|
+
* it does not identify is answered 401. Unset, no request has an
|
|
56
|
+
* identity, and every request is answered */
|
|
57
|
+
readonly identify?: Identify;
|
|
58
|
+
/** How long a dataset commit waits for its verification before it answers
|
|
59
|
+
* `processing` for the client to poll: the routes' default unless set */
|
|
60
|
+
readonly commitWaitMs?: number;
|
|
61
|
+
}
|
|
62
|
+
/** The app: its routes read the caller's identity from its context. */
|
|
63
|
+
export type WebApp = Hono<{
|
|
64
|
+
Variables: {
|
|
65
|
+
identity?: Identity;
|
|
66
|
+
};
|
|
67
|
+
}>;
|
|
68
|
+
/**
|
|
69
|
+
* Creates e3's API over e3-web's seams.
|
|
70
|
+
*
|
|
71
|
+
* @remarks
|
|
72
|
+
* The routes are e3-api-server's own, mounted as the local server mounts them
|
|
73
|
+
* over many repositories, so an e3 in a page answers every request as the
|
|
74
|
+
* local server does:
|
|
75
|
+
* - e3-web's byte endpoints, at `/api/uploads` and `/api/downloads`, ahead of
|
|
76
|
+
* any identity: their URLs are capabilities;
|
|
77
|
+
* - who calls ({@link WebAppSeams.identify}), set on each request to a
|
|
78
|
+
* repository, and a caller it does not know answered 401;
|
|
79
|
+
* - the gate every request to a repository passes, which applies the
|
|
80
|
+
* upgrades it owes in the request, as an in-page request has no time
|
|
81
|
+
* limit; and the repositories' own routes;
|
|
82
|
+
* - a repository's status, gc, packages and their transfer, workspaces,
|
|
83
|
+
* datasets and their transfer, tasks, functions and one-shot with its split
|
|
84
|
+
* calls under the host's `access`, records, the dataflow, and objects.
|
|
85
|
+
*
|
|
86
|
+
* @param seams - The storage, transfers, runners, orchestrator and state
|
|
87
|
+
* store the routes run over, and who may run what
|
|
88
|
+
* @returns The app, whose `fetch` answers each request
|
|
89
|
+
*/
|
|
90
|
+
export declare function createWebApp(seams: WebAppSeams): WebApp;
|
|
91
|
+
//# sourceMappingURL=app.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../src/app.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;;;GAOG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAC5B,OAAO,EAAa,KAAK,oBAAoB,EAAE,KAAK,mBAAmB,EAAE,KAAK,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5H,OAAO,EAgBL,KAAK,QAAQ,EACb,KAAK,aAAa,EACnB,MAAM,iCAAiC,CAAC;AACzC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAE1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAE3E;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,QAAQ,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,GAAG,SAAS,CAAC,CAAC;AAEhH;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,+CAA+C;IAC/C,QAAQ,CAAC,OAAO,EAAE,UAAU,CAAC;IAC7B,8EAA8E;IAC9E,QAAQ,CAAC,QAAQ,EAAE,kBAAkB,CAAC;IACtC,+BAA+B;IAC/B,QAAQ,CAAC,SAAS,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,UAAU,CAAC;IACjD,8DAA8D;IAC9D,QAAQ,CAAC,YAAY,EAAE,oBAAoB,CAAC;IAC5C;8BAC0B;IAC1B,QAAQ,CAAC,UAAU,EAAE,mBAAmB,CAAC;IACzC,4EAA4E;IAC5E,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,wEAAwE;IACxE,QAAQ,CAAC,MAAM,EAAE,aAAa,CAAC;IAC/B;;kDAE8C;IAC9C,QAAQ,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC;IAC7B;8EAC0E;IAC1E,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;CAChC;AAED,uEAAuE;AACvE,MAAM,MAAM,MAAM,GAAG,IAAI,CAAC;IAAE,SAAS,EAAE;QAAE,QAAQ,CAAC,EAAE,QAAQ,CAAA;KAAE,CAAA;CAAE,CAAC,CAAC;AAalE;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,WAAW,GAAG,MAAM,CAwEvD"}
|