@openfairygui/backend 0.2.0-alpha.0 → 0.2.0-alpha.10

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 OpenFairyGUI Contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -11,7 +11,9 @@ It owns:
11
11
  - project/session lifecycle
12
12
  - revisioned request handling
13
13
  - coordinated but non-atomic save semantics
14
- - backend-local advisory locking
14
+ - browser-safe project sessions
15
+ - browser-safe async project storage adapter
16
+ - adapter-backed file sessions and backend-local advisory locking
15
17
  - capability discovery
16
18
  - transport-neutral bootstrap
17
19
 
@@ -26,9 +28,13 @@ It also provides:
26
28
  - polling runtime events with per-runtime monotonic sequence and bounded retention
27
29
  - `cache.refresh` in-memory jobs with cooperative cancel and terminal retention
28
30
  - revision-bound derived read-only cache snapshots
31
+ - explicit Node bridge boundaries for publish/restore
29
32
 
30
33
  It does **not** redefine transaction grammar or expose `Document`.
31
34
  It also does **not** implement MCP or any transport-specific wire protocol.
35
+ The root `@openfairygui/backend` entrypoint is browser-safe: pure authoring sessions can run in memory,
36
+ 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`.
32
38
 
33
39
  ## Relationship to other packages
34
40
 
@@ -38,16 +44,71 @@ It also does **not** implement MCP or any transport-specific wire protocol.
38
44
 
39
45
  ## Example
40
46
 
47
+ Browser-safe project session:
48
+
41
49
  ```ts
42
50
  import { BackendRuntime } from '@openfairygui/backend';
43
51
 
44
52
  const runtime = new BackendRuntime();
53
+ const opened = runtime.openProjectSession({ project: uamProject });
54
+ if (!opened.ok) throw new Error(opened.error.message);
55
+
56
+ const applied = await runtime.applyTransaction({
57
+ sessionId: opened.data.sessionId,
58
+ expectedRevision: opened.data.revision,
59
+ operations,
60
+ });
61
+ ```
62
+
63
+ Browser-safe project session with injected storage:
64
+
65
+ ```ts
66
+ import { BackendRuntime, createBackendStorageFileSystem } from '@openfairygui/backend';
67
+
68
+ const fileSystem = createBackendStorageFileSystem({
69
+ async readFile(filePath) { return storage.readText(filePath); },
70
+ async readFileRaw(filePath) { return storage.readBytes(filePath); },
71
+ async writeFile(filePath, content) { await storage.writeText(filePath, content); },
72
+ async writeFileRaw(filePath, data) { await storage.writeBytes(filePath, data); },
73
+ async mkdir(dirPath) { await storage.mkdir(dirPath); },
74
+ async readdir(dirPath) { return storage.readdir(dirPath); },
75
+ async exists(filePath) { return storage.exists(filePath); },
76
+ });
77
+
78
+ const runtime = new BackendRuntime();
79
+ const opened = runtime.openProjectSession({
80
+ project: uamProject,
81
+ storage: {
82
+ fileSystem,
83
+ fairyPath: 'Project.fairy',
84
+ },
85
+ });
86
+ if (!opened.ok) throw new Error(opened.error.message);
87
+
88
+ const bootstrapped = await runtime.materializeSession({
89
+ sessionId: opened.data.sessionId,
90
+ expectedRevision: opened.data.revision,
91
+ mode: 'fullProject',
92
+ reason: 'workspace_bootstrap',
93
+ });
94
+ if (!bootstrapped.ok) throw new Error(bootstrapped.error.message);
95
+
96
+ console.log(bootstrapped.data.writtenPaths);
97
+ ```
98
+
99
+ Node file-backed session:
100
+
101
+ ```ts
102
+ import { createNodeBackendRuntime } from '@openfairygui/backend/node';
103
+
104
+ const runtime = createNodeBackendRuntime();
45
105
  const opened = await runtime.openSession({ projectPath: './MyProject' });
46
106
  if (!opened.ok) throw new Error(opened.error.message);
47
107
 
48
108
  const capabilities = runtime.getCapabilities();
49
109
  console.log(capabilities.data.runtimeOwner);
50
110
  console.log(capabilities.data.contractVersion);
111
+ console.log(capabilities.data.artifact.publishBridge.executionBoundary);
51
112
  console.log(capabilities.data.compatibilityPolicy.incompatibleChange);
52
113
 
53
114
  const refresh = runtime.refreshCache({ sessionId: opened.data.sessionId });