@openfairygui/backend 0.2.0-alpha.9 → 0.3.0-alpha.1

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 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 advisory locking
16
+ - adapter-backed file sessions and backend-local session locking
17
17
  - capability discovery
18
18
  - transport-neutral bootstrap
19
19
 
@@ -28,13 +28,28 @@ It also provides:
28
28
  - polling runtime events with per-runtime monotonic sequence and bounded retention
29
29
  - `cache.refresh` in-memory jobs with cooperative cancel and terminal retention
30
30
  - revision-bound derived read-only cache snapshots
31
+ - revision-bound project identity outlines for transaction planning
31
32
  - explicit Node bridge boundaries for publish/restore
32
33
 
33
34
  It does **not** redefine transaction grammar or expose `Document`.
34
35
  It also does **not** implement MCP or any transport-specific wire protocol.
35
36
  The root `@openfairygui/backend` entrypoint is browser-safe: pure authoring sessions can run in memory,
36
37
  and browser editors can inject an async storage adapter for OPFS, IndexedDB, ZIP-backed virtual filesystems,
37
- or File System Access API bridges. The default Node filesystem/runtime lives under `@openfairygui/backend/node`.
38
+ or File System Access API bridges. Storage adapters must implement `unlink()` so resource rename/move/remove
39
+ can clean up stale source files. Existing browser projects use a session-lifetime Web Lock: a live peer tab
40
+ receives `lock_conflict`, while reload or abrupt document termination releases ownership without leaving a
41
+ persistent `.openfairygui.backend.lock` marker. When Web Locks are unavailable, the storage adapter must
42
+ provide `acquireSessionLock()` with the same atomic cross-context and owner-termination semantics. The default
43
+ Node filesystem/runtime lives under `@openfairygui/backend/node` and retains its advisory lock file behavior.
44
+ Adapter-backed `openSession` hydrates primary resource bytes so browser-safe transactions can rename/move
45
+ assets or add/replace/remove binary resources. `saveSession` writes replacement bytes before it removes
46
+ stale source files, preserving the prior file when a write fails.
47
+ It also compares the source project with a UAM round trip through `ProjectWriter`; sessions with
48
+ unrepresented persisted properties expose `uamFidelity: 'unsupported'`, and write attempts fail with
49
+ `uam_fidelity_unsupported`. Existing projects in browser storage must be opened through this path by
50
+ injecting `createBackendStorageFileSystem(storage)` into `BackendRuntime`; `openProjectSession` is only
51
+ for sessions whose supplied UAM project is authoritative. Transactions, saves, and materialization are
52
+ serialized per session.
38
53
 
39
54
  ## Relationship to other packages
40
55
 
@@ -44,7 +59,7 @@ or File System Access API bridges. The default Node filesystem/runtime lives und
44
59
 
45
60
  ## Example
46
61
 
47
- Browser-safe project session:
62
+ Browser-safe authoritative UAM project session:
48
63
 
49
64
  ```ts
50
65
  import { BackendRuntime } from '@openfairygui/backend';
@@ -53,6 +68,9 @@ const runtime = new BackendRuntime();
53
68
  const opened = runtime.openProjectSession({ project: uamProject });
54
69
  if (!opened.ok) throw new Error(opened.error.message);
55
70
 
71
+ const outline = runtime.getProjectOutline({ sessionId: opened.data.sessionId });
72
+ if (!outline.ok) throw new Error(outline.error.message);
73
+
56
74
  const applied = await runtime.applyTransaction({
57
75
  sessionId: opened.data.sessionId,
58
76
  expectedRevision: opened.data.revision,
@@ -60,7 +78,7 @@ const applied = await runtime.applyTransaction({
60
78
  });
61
79
  ```
62
80
 
63
- Browser-safe project session with injected storage:
81
+ Open an existing project from browser async storage with source-fidelity checks:
64
82
 
65
83
  ```ts
66
84
  import { BackendRuntime, createBackendStorageFileSystem } from '@openfairygui/backend';
@@ -73,15 +91,22 @@ const fileSystem = createBackendStorageFileSystem({
73
91
  async mkdir(dirPath) { await storage.mkdir(dirPath); },
74
92
  async readdir(dirPath) { return storage.readdir(dirPath); },
75
93
  async exists(filePath) { return storage.exists(filePath); },
94
+ async unlink(filePath) { await storage.remove(filePath); },
95
+ async rmdir(dirPath) { await storage.rmdir(dirPath); },
76
96
  });
77
97
 
98
+ const runtime = new BackendRuntime({ fileSystem });
99
+ const opened = await runtime.openSession({ projectPath: 'ExistingProject' });
100
+ if (!opened.ok) throw new Error(opened.error.message);
101
+ ```
102
+
103
+ Materialize an authoritative UAM project into browser async storage:
104
+
105
+ ```ts
78
106
  const runtime = new BackendRuntime();
79
107
  const opened = runtime.openProjectSession({
80
108
  project: uamProject,
81
- storage: {
82
- fileSystem,
83
- fairyPath: 'Project.fairy',
84
- },
109
+ storage: { fileSystem, fairyPath: 'NewProject/Project.fairy' },
85
110
  });
86
111
  if (!opened.ok) throw new Error(opened.error.message);
87
112