@openfairygui/backend 0.2.0-alpha.8 → 0.2.0
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/README.md +29 -8
- package/dist/index.cjs +1633 -27
- package/dist/index.d.cts +516 -4
- package/dist/index.d.mts +516 -4
- package/dist/index.mjs +1629 -23
- package/dist/node.cjs +1603 -9
- package/dist/node.d.cts +507 -2
- package/dist/node.d.mts +507 -2
- package/dist/node.mjs +1601 -6
- package/package.json +7 -6
- package/src/index.ts +18 -17
- package/src/node.ts +24 -8
- package/src/runtime/capabilities.ts +126 -0
- package/src/runtime/contracts.ts +518 -0
- package/src/runtime.ts +49 -623
- package/src/services/authoring-service.ts +242 -99
- package/src/services/cache-service.ts +1 -2
- package/src/services/context.ts +17 -8
- package/src/services/event-service.ts +1 -2
- package/src/services/job-service.ts +4 -5
- package/src/services/read-service.ts +1 -2
- package/src/services/runtime-service.ts +133 -27
- package/src/services/session-project-writer.ts +69 -0
- package/src/services/session-utils.ts +6 -3
- package/src/storage.ts +67 -27
- package/dist/runtime-DFatY9W0.mjs +0 -1417
- package/dist/runtime-GKzsXJdO.cjs +0 -1441
- package/dist/runtime-GyNVxAQ0.d.mts +0 -494
- package/dist/runtime-Jec6FcF5.d.cts +0 -494
- package/src/services/snapshot-utils.ts +0 -43
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ It owns:
|
|
|
13
13
|
- coordinated but non-atomic save semantics
|
|
14
14
|
- browser-safe project sessions
|
|
15
15
|
- browser-safe async project storage adapter
|
|
16
|
-
- adapter-backed file sessions and backend-local
|
|
16
|
+
- adapter-backed file sessions and backend-local session locking
|
|
17
17
|
- capability discovery
|
|
18
18
|
- transport-neutral bootstrap
|
|
19
19
|
|
|
@@ -34,7 +34,21 @@ It does **not** redefine transaction grammar or expose `Document`.
|
|
|
34
34
|
It also does **not** implement MCP or any transport-specific wire protocol.
|
|
35
35
|
The root `@openfairygui/backend` entrypoint is browser-safe: pure authoring sessions can run in memory,
|
|
36
36
|
and browser editors can inject an async storage adapter for OPFS, IndexedDB, ZIP-backed virtual filesystems,
|
|
37
|
-
or File System Access API bridges.
|
|
37
|
+
or File System Access API bridges. Storage adapters must implement `unlink()` so resource rename/move/remove
|
|
38
|
+
can clean up stale source files. Existing browser projects use a session-lifetime Web Lock: a live peer tab
|
|
39
|
+
receives `lock_conflict`, while reload or abrupt document termination releases ownership without leaving a
|
|
40
|
+
persistent `.openfairygui.backend.lock` marker. When Web Locks are unavailable, the storage adapter must
|
|
41
|
+
provide `acquireSessionLock()` with the same atomic cross-context and owner-termination semantics. The default
|
|
42
|
+
Node filesystem/runtime lives under `@openfairygui/backend/node` and retains its advisory lock file behavior.
|
|
43
|
+
Adapter-backed `openSession` hydrates primary resource bytes so browser-safe transactions can rename/move
|
|
44
|
+
assets or add/replace/remove binary resources. `saveSession` writes replacement bytes before it removes
|
|
45
|
+
stale source files, preserving the prior file when a write fails.
|
|
46
|
+
It also compares the source project with a UAM round trip through `ProjectWriter`; sessions with
|
|
47
|
+
unrepresented persisted properties expose `uamFidelity: 'unsupported'`, and write attempts fail with
|
|
48
|
+
`uam_fidelity_unsupported`. Existing projects in browser storage must be opened through this path by
|
|
49
|
+
injecting `createBackendStorageFileSystem(storage)` into `BackendRuntime`; `openProjectSession` is only
|
|
50
|
+
for sessions whose supplied UAM project is authoritative. Transactions, saves, and materialization are
|
|
51
|
+
serialized per session.
|
|
38
52
|
|
|
39
53
|
## Relationship to other packages
|
|
40
54
|
|
|
@@ -44,7 +58,7 @@ or File System Access API bridges. The default Node filesystem/runtime lives und
|
|
|
44
58
|
|
|
45
59
|
## Example
|
|
46
60
|
|
|
47
|
-
Browser-safe project session:
|
|
61
|
+
Browser-safe authoritative UAM project session:
|
|
48
62
|
|
|
49
63
|
```ts
|
|
50
64
|
import { BackendRuntime } from '@openfairygui/backend';
|
|
@@ -60,7 +74,7 @@ const applied = await runtime.applyTransaction({
|
|
|
60
74
|
});
|
|
61
75
|
```
|
|
62
76
|
|
|
63
|
-
|
|
77
|
+
Open an existing project from browser async storage with source-fidelity checks:
|
|
64
78
|
|
|
65
79
|
```ts
|
|
66
80
|
import { BackendRuntime, createBackendStorageFileSystem } from '@openfairygui/backend';
|
|
@@ -73,15 +87,22 @@ const fileSystem = createBackendStorageFileSystem({
|
|
|
73
87
|
async mkdir(dirPath) { await storage.mkdir(dirPath); },
|
|
74
88
|
async readdir(dirPath) { return storage.readdir(dirPath); },
|
|
75
89
|
async exists(filePath) { return storage.exists(filePath); },
|
|
90
|
+
async unlink(filePath) { await storage.remove(filePath); },
|
|
91
|
+
async rmdir(dirPath) { await storage.rmdir(dirPath); },
|
|
76
92
|
});
|
|
77
93
|
|
|
94
|
+
const runtime = new BackendRuntime({ fileSystem });
|
|
95
|
+
const opened = await runtime.openSession({ projectPath: 'ExistingProject' });
|
|
96
|
+
if (!opened.ok) throw new Error(opened.error.message);
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
Materialize an authoritative UAM project into browser async storage:
|
|
100
|
+
|
|
101
|
+
```ts
|
|
78
102
|
const runtime = new BackendRuntime();
|
|
79
103
|
const opened = runtime.openProjectSession({
|
|
80
104
|
project: uamProject,
|
|
81
|
-
storage: {
|
|
82
|
-
fileSystem,
|
|
83
|
-
fairyPath: 'Project.fairy',
|
|
84
|
-
},
|
|
105
|
+
storage: { fileSystem, fairyPath: 'NewProject/Project.fairy' },
|
|
85
106
|
});
|
|
86
107
|
if (!opened.ok) throw new Error(opened.error.message);
|
|
87
108
|
|