@openfairygui/backend 0.6.3 → 0.7.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.
Files changed (48) hide show
  1. package/dist/contracts-Bx8HUr7I.d.cts +756 -0
  2. package/dist/contracts-CMQiPEyz.d.mts +756 -0
  3. package/dist/diagnostics-CIe7S-RW.cjs +670 -0
  4. package/dist/diagnostics-CZ12H1Mx.d.cts +1679 -0
  5. package/dist/diagnostics-CpJ8cAP6.d.mts +1679 -0
  6. package/dist/diagnostics-DTnLXQGs.mjs +641 -0
  7. package/dist/docs.cjs +11530 -5940
  8. package/dist/docs.d.cts +5 -185
  9. package/dist/docs.d.mts +5 -185
  10. package/dist/docs.mjs +11528 -5939
  11. package/dist/index.cjs +16 -2703
  12. package/dist/index.d.cts +5 -2362
  13. package/dist/index.d.mts +5 -2362
  14. package/dist/index.mjs +4 -2691
  15. package/dist/node.cjs +367 -2779
  16. package/dist/node.d.cts +4 -724
  17. package/dist/node.d.mts +4 -724
  18. package/dist/node.mjs +359 -2751
  19. package/dist/rolldown-runtime-BJqNVkSG.cjs +28 -0
  20. package/dist/runtime-DYqG77ak.cjs +2249 -0
  21. package/dist/runtime-gStewf1p.mjs +2189 -0
  22. package/package.json +4 -5
  23. package/src/contracts.ts +0 -58
  24. package/src/diagnostics.ts +0 -188
  25. package/src/docs.ts +0 -109
  26. package/src/generated/contracts.ts +0 -24207
  27. package/src/generated/docs.ts +0 -12
  28. package/src/index.ts +0 -99
  29. package/src/node.ts +0 -317
  30. package/src/path-policy.ts +0 -123
  31. package/src/runtime/capabilities.ts +0 -131
  32. package/src/runtime/contracts.ts +0 -672
  33. package/src/runtime.ts +0 -231
  34. package/src/services/artifact-service.ts +0 -19
  35. package/src/services/authoring-service.ts +0 -229
  36. package/src/services/cache-service.ts +0 -81
  37. package/src/services/capture-project.ts +0 -75
  38. package/src/services/context.ts +0 -150
  39. package/src/services/event-service.ts +0 -86
  40. package/src/services/persistence-service.ts +0 -550
  41. package/src/services/read-service.ts +0 -274
  42. package/src/services/runtime-service.ts +0 -342
  43. package/src/services/session-operation-queue.ts +0 -21
  44. package/src/services/session-project-writer.ts +0 -89
  45. package/src/services/session-registry.ts +0 -70
  46. package/src/services/session-utils.ts +0 -45
  47. package/src/services/transaction-preview.ts +0 -116
  48. package/src/storage.ts +0 -232
@@ -0,0 +1,756 @@
1
+ import * as _$_openfairygui_core0 from "@openfairygui/core";
2
+ import { ProjectDiagnosticCode, ProjectValidationReport } from "@openfairygui/core";
3
+ import { UamComponentModel, UamComponentResource, UamComponentSelector, UamControllerModel, UamControllerSelector, UamDisplayNode, UamDisplayNodeKind, UamDisplayNodeSelector, UamGenericAssetResource, UamImageResource, UamMovieClipResource, UamPackage, UamPackageSelector, UamPackageSettings, UamProject, UamResource, UamResourceSelector, UamTransactionOperation, UamTransactionSupportIssueCode, UamTransitionModel, UamTransitionSelector } from "@openfairygui/core/uam";
4
+ import { ApplyUamTransactionAppError } from "@openfairygui/functions/uam";
5
+
6
+ //#region src/path-policy.d.ts
7
+ interface PathPolicyViolationError {
8
+ code: 'path_policy_violation';
9
+ message: string;
10
+ policy: 'save_target';
11
+ attemptedPath: string;
12
+ allowedPath: string;
13
+ }
14
+ //#endregion
15
+ //#region src/runtime/capabilities.d.ts
16
+ declare const BACKEND_METHODS: readonly ["getCapabilities", "openSession", "openProjectSession", "getSession", "getProjectOutline", "queryEntity", "readSessionState", "readResourceBytes", "validateSession", "preflightTransaction", "applyTransaction", "saveSession", "materializeSession", "closeSession", "getEvents", "getCacheSnapshot", "refreshCache"];
17
+ //#endregion
18
+ //#region src/runtime/contracts.d.ts
19
+ type BackendMethodName = keyof BackendRuntime;
20
+ declare const BACKEND_ENTITY_QUERY_LIMITS: {
21
+ readonly maxBytes: 262144;
22
+ readonly maxDepth: 32;
23
+ readonly maxNodes: 100000;
24
+ };
25
+ declare const BACKEND_SESSION_READ_LIMITS: {
26
+ readonly model: {
27
+ readonly maxBytes: 4194304;
28
+ readonly maxDepth: 64;
29
+ readonly maxNodes: 500000;
30
+ };
31
+ readonly resourceBytes: 1048576;
32
+ };
33
+ /** The public UAM model, excluding only each asset resource's primary sourceBytes. */
34
+ type BackendSessionResourceModel = UamComponentResource | Omit<UamImageResource, 'sourceBytes'> | Omit<UamMovieClipResource, 'sourceBytes'> | Omit<UamGenericAssetResource, 'sourceBytes'>;
35
+ interface BackendSessionPackageModel extends Omit<UamPackage, 'resources'> {
36
+ resources: BackendSessionResourceModel[];
37
+ }
38
+ interface BackendSessionProjectModel extends Omit<UamProject, 'packages'> {
39
+ packages: BackendSessionPackageModel[];
40
+ }
41
+ interface ReadSessionStateInput {
42
+ sessionId: string;
43
+ expectedRevision?: number;
44
+ }
45
+ interface ReadResourceBytesInput {
46
+ sessionId: string;
47
+ expectedRevision: number;
48
+ selector: UamResourceSelector;
49
+ }
50
+ interface BackendSessionStateSnapshot extends Pick<BackendSessionSnapshot, 'sessionId' | 'revision' | 'lastSavedRevision' | 'dirty' | 'uamFidelity'> {
51
+ project: BackendSessionProjectModel;
52
+ readDiagnostics: _$_openfairygui_core0.ProjectDiagnostic[];
53
+ /** Source-read completeness, not a guarantee of resource bytes or downstream usability. */
54
+ readComplete: boolean;
55
+ }
56
+ interface BackendResourceBytesSnapshot {
57
+ sessionId: string;
58
+ revision: number;
59
+ selector: UamResourceSelector;
60
+ /** Only primary bytes already held in this session; no filesystem hydration. */
61
+ sourceBytes: Uint8Array;
62
+ }
63
+ interface SessionReadError {
64
+ code: 'session_read_failed';
65
+ message: string;
66
+ sessionId: string;
67
+ reason: 'invalid_query' | 'not_found' | 'ambiguous' | 'unsupported_resource' | 'bytes_unavailable' | 'response_budget_exceeded' | 'non_json_value';
68
+ }
69
+ interface SessionStaleReadError {
70
+ code: 'stale_read';
71
+ message: string;
72
+ sessionId: string;
73
+ expectedRevision: number;
74
+ actualRevision: number;
75
+ }
76
+ declare const BACKEND_TRANSACTION_PREVIEW_LIMITS: {
77
+ readonly maxBytes: 262144;
78
+ readonly maxEntries: 2000;
79
+ };
80
+ /** Fixed resource projection. Binary content, source bookkeeping and arbitrary metadata are excluded. */
81
+ declare const BACKEND_RESOURCE_QUERY_FIELDS: readonly ["kind", "id", "name", "path", "exported", "favorite", "branch", "branchItemIds", "fileName", "file", "dimensions", "image", "movieClip"];
82
+ type ResourceQueryFields<T> = Pick<T, Extract<keyof T, (typeof BACKEND_RESOURCE_QUERY_FIELDS)[number]>>;
83
+ type BackendResourceSnapshot = ResourceQueryFields<UamImageResource> | ResourceQueryFields<UamMovieClipResource> | ResourceQueryFields<UamGenericAssetResource> | ResourceQueryFields<UamComponentResource>;
84
+ type BackendComponentSnapshot = Pick<UamComponentModel, 'size' | 'properties' | 'customData'>;
85
+ type BackendProjectSnapshot = Pick<UamProject, 'projectId' | 'settings'>;
86
+ interface BackendPackageSnapshot {
87
+ id: string;
88
+ name: string;
89
+ settings: UamPackageSettings;
90
+ }
91
+ type BackendEntityTarget = {
92
+ kind: 'project';
93
+ } | {
94
+ kind: 'package';
95
+ selector: UamPackageSelector;
96
+ } | {
97
+ kind: 'resource';
98
+ selector: UamResourceSelector;
99
+ } | {
100
+ kind: 'component';
101
+ selector: UamComponentSelector;
102
+ } | {
103
+ kind: 'displayNode';
104
+ selector: UamDisplayNodeSelector;
105
+ } | {
106
+ kind: 'controller';
107
+ selector: UamControllerSelector;
108
+ } | {
109
+ kind: 'transition';
110
+ selector: UamTransitionSelector;
111
+ };
112
+ interface QueryEntityInput {
113
+ sessionId: string;
114
+ target: BackendEntityTarget;
115
+ }
116
+ interface BackendEntitySnapshot {
117
+ sessionId: string;
118
+ revision: number;
119
+ target: BackendEntityTarget;
120
+ entity: {
121
+ kind: 'project';
122
+ properties: BackendProjectSnapshot;
123
+ } | {
124
+ kind: 'package';
125
+ properties: BackendPackageSnapshot;
126
+ } | {
127
+ kind: 'resource';
128
+ properties: BackendResourceSnapshot;
129
+ } | {
130
+ kind: 'component';
131
+ properties: BackendComponentSnapshot;
132
+ } | {
133
+ kind: 'displayNode';
134
+ properties: UamDisplayNode;
135
+ } | {
136
+ kind: 'controller';
137
+ properties: UamControllerModel;
138
+ } | {
139
+ kind: 'transition';
140
+ properties: UamTransitionModel;
141
+ };
142
+ }
143
+ interface EntityQueryError {
144
+ code: 'entity_query_failed';
145
+ message: string;
146
+ sessionId: string;
147
+ reason: 'invalid_query' | 'not_found' | 'ambiguous' | 'response_budget_exceeded' | 'non_json_value';
148
+ }
149
+ /** An exclusive lock owned for the lifetime of one backend session. */
150
+ interface BackendSessionLock {
151
+ /** Persist optional host metadata without changing lock ownership. */
152
+ writeMetadata(content: string): Promise<void>;
153
+ /** Release ownership. Browser implementations must also release when their document terminates. */
154
+ release(): Promise<void>;
155
+ }
156
+ interface BackendFileStat {
157
+ isFile(): boolean;
158
+ isDirectory(): boolean;
159
+ }
160
+ /** A committed staged write. Cleanup problems after commit are reported here instead of failing the save. */
161
+ interface ProjectWriteTransactionResult {
162
+ /** Previous project copies the host could not remove; the committed project is unaffected. */
163
+ retainedBackupPaths?: string[];
164
+ }
165
+ /** A failed staged write with an explicit outcome for the original project. */
166
+ declare class ProjectWriteTransactionError extends Error {
167
+ readonly diskMayBePartiallyUpdated: boolean;
168
+ readonly recoveryPaths: string[];
169
+ readonly code = "project_write_transaction_failed";
170
+ /** Recognizes the same contract across separately bundled Node/root or ESM/CJS entries. */
171
+ static is(error: unknown): error is ProjectWriteTransactionError;
172
+ constructor(cause: unknown, diskMayBePartiallyUpdated: boolean, recoveryPaths?: string[]);
173
+ }
174
+ interface BackendFileSystem {
175
+ stat(filePath: string): Promise<BackendFileStat>;
176
+ readdir(dirPath: string): Promise<string[]>;
177
+ readFile(filePath: string): Promise<string>;
178
+ readFileRaw(filePath: string): Promise<Uint8Array>;
179
+ writeFile(filePath: string, content: string): Promise<void>;
180
+ writeFileRaw(filePath: string, data: Uint8Array): Promise<void>;
181
+ mkdir(dirPath: string, options?: {
182
+ recursive?: boolean;
183
+ }): Promise<void>;
184
+ resolvePath(filePath: string): Promise<string>;
185
+ /** Compare resolved paths case-sensitively. Omitted means case-insensitive comparison. */
186
+ caseSensitivePaths?: boolean;
187
+ /** Optional host validation before a project is read. Node rejects links in project-owned assets, settings and project files. */
188
+ validateProjectRoot?(projectRoot: string): Promise<void>;
189
+ /** Optional host-specific lock location. Node keeps it beside the project. */
190
+ getSessionLockPath?(canonicalProjectPath: string): string;
191
+ /** Stages project writes. On failure, throw ProjectWriteTransactionError to report rollback and recovery paths. */
192
+ runProjectWriteTransaction?(projectRoot: string, write: (stagedFileSystem: BackendFileSystem) => Promise<void>): Promise<ProjectWriteTransactionResult>;
193
+ acquireSessionLock(lockPath: string): Promise<BackendSessionLock>;
194
+ unlink(filePath: string): Promise<void>;
195
+ rmdir(dirPath: string): Promise<void>;
196
+ join(...paths: string[]): string;
197
+ dirname(filePath: string): string;
198
+ resolve(...paths: string[]): string;
199
+ }
200
+ interface BackendHostAdapter {
201
+ lockMetadata?(input: {
202
+ canonicalPathKey: string;
203
+ canonicalProjectPath: string;
204
+ lockFilePath: string;
205
+ }): unknown;
206
+ }
207
+ interface BackendArtifactBridgeCapability {
208
+ available: false;
209
+ requiredHost: 'node';
210
+ executionBoundary: 'external-bridge';
211
+ bridgeEntrypoint: '@openfairygui/backend/node';
212
+ reason: string;
213
+ }
214
+ interface BackendCapabilityManifest {
215
+ browserSafe: true;
216
+ rootEntrypoint: '@openfairygui/backend';
217
+ nodeEntrypoint: '@openfairygui/backend/node';
218
+ adapters: {
219
+ fileSystem: {
220
+ injected: true;
221
+ requiredFor: readonly ['openSession', 'saveSession', 'materializeSession'];
222
+ };
223
+ projectStorage: {
224
+ injected: true;
225
+ browserSafe: true;
226
+ requiredFor: readonly ['openProjectSession.writeback', 'saveSession', 'materializeSession'];
227
+ adapterFactory: 'createBackendStorageFileSystem';
228
+ };
229
+ host: {
230
+ injected: true;
231
+ requiredFor: readonly ['advisoryLockMetadata'];
232
+ };
233
+ };
234
+ executionBoundaries: {
235
+ projectSession: 'in-process-browser-safe';
236
+ fileBackedSession: 'adapter-backed';
237
+ artifactPublish: BackendArtifactBridgeCapability;
238
+ artifactRestore: BackendArtifactBridgeCapability;
239
+ };
240
+ diagnostics: {
241
+ stableCodes: true;
242
+ errorDiagnosticMirror: true;
243
+ recoveryGuides: 'all-formal-codes';
244
+ automaticRepair: false;
245
+ };
246
+ }
247
+ interface BackendCapabilities {
248
+ contractVersion: typeof BACKEND_CONTRACT_VERSION;
249
+ capabilitySchemaVersion: typeof BACKEND_CAPABILITY_SCHEMA_VERSION;
250
+ transactionKernelOwner: '@openfairygui/core';
251
+ appSeamOwner: '@openfairygui/functions';
252
+ runtimeOwner: '@openfairygui/backend';
253
+ methods: typeof BACKEND_METHODS;
254
+ read: {
255
+ capabilitySnapshot: true;
256
+ sessionSnapshot: true;
257
+ projectOutline: true;
258
+ entityQuery: {
259
+ kinds: readonly BackendEntityTarget['kind'][];
260
+ projection: 'properties';
261
+ sourceBytes: false;
262
+ limits: typeof BACKEND_ENTITY_QUERY_LIMITS;
263
+ };
264
+ sessionState: {
265
+ sourceBytes: false;
266
+ limits: typeof BACKEND_SESSION_READ_LIMITS.model;
267
+ };
268
+ resourceBytes: {
269
+ expectedRevisionRequired: true;
270
+ hydration: false;
271
+ maxBytes: typeof BACKEND_SESSION_READ_LIMITS.resourceBytes;
272
+ };
273
+ projectValidation: true;
274
+ };
275
+ authoring: {
276
+ preflightTransaction: {
277
+ mode: 'execute-and-discard';
278
+ reservesRevision: false;
279
+ impact: 'model-diff';
280
+ limits: typeof BACKEND_TRANSACTION_PREVIEW_LIMITS;
281
+ };
282
+ applyTransaction: true;
283
+ saveSession: true;
284
+ resourceKinds: readonly string[];
285
+ nodeKinds: readonly string[];
286
+ gearKinds: readonly string[];
287
+ transactionScope: {
288
+ resourceKinds: readonly string[];
289
+ nodeKinds: readonly string[];
290
+ gearKinds: readonly string[];
291
+ };
292
+ unsupported: readonly ['artifact.publish', 'artifact.restore'];
293
+ };
294
+ artifact: {
295
+ publish: false;
296
+ restore: false;
297
+ status: 'bridge-required';
298
+ publishBridge: BackendArtifactBridgeCapability;
299
+ restoreBridge: BackendArtifactBridgeCapability;
300
+ };
301
+ manifest: BackendCapabilityManifest;
302
+ compatibilityPolicy: typeof BACKEND_COMPATIBILITY_POLICY;
303
+ runtime: {
304
+ sessionRuntime: true; /** Open and opening sessions allowed at once; further opens fail with session_limit_exceeded. */
305
+ maxSessions: number; /** Clean idle sessions are closed after this interval; zero disables expiry. Dirty sessions are retained. */
306
+ idleSessionTimeoutMs: number;
307
+ advisoryLocking: true;
308
+ coordinatedSave: true;
309
+ atomicSave: boolean;
310
+ staleRevisionProtection: true;
311
+ pathPolicy: {
312
+ canonicalization: 'realpath+normalized' | 'realpath+normalized-casefold';
313
+ sessionIdentity: 'project-root';
314
+ saveTarget: 'opened-project-only';
315
+ outputTargets: 'deferred';
316
+ workspaceBoundary: 'project-root-only';
317
+ };
318
+ events: {
319
+ polling: true;
320
+ subscriptions: false;
321
+ retentionLimit: 1000;
322
+ sequenceScope: 'runtime';
323
+ };
324
+ cache: {
325
+ derivedReadOnly: true;
326
+ keyedBy: 'sessionId';
327
+ refreshMode: 'synchronous';
328
+ sourceOfTruth: false;
329
+ refreshMethod: 'refreshCache';
330
+ };
331
+ };
332
+ }
333
+ interface BackendSessionSnapshot {
334
+ sessionId: string;
335
+ canonicalProjectPath: string;
336
+ revision: number;
337
+ lastSavedRevision: number;
338
+ dirty: boolean;
339
+ uamFidelity: 'full' | 'unsupported';
340
+ lockHeld: boolean;
341
+ capabilities: BackendCapabilities;
342
+ }
343
+ interface BackendProjectOutline {
344
+ sessionId: string;
345
+ revision: number;
346
+ projectId: string;
347
+ projectType: number;
348
+ version: string;
349
+ branches: string[];
350
+ packages: BackendProjectOutlinePackage[];
351
+ }
352
+ interface BackendProjectOutlinePackage {
353
+ id: string;
354
+ name: string;
355
+ branchNames: string[];
356
+ folders: Array<{
357
+ branch: string;
358
+ path: string;
359
+ }>;
360
+ resources: BackendProjectOutlineResource[];
361
+ }
362
+ interface BackendProjectOutlineResource {
363
+ id: string;
364
+ name: string;
365
+ path: string;
366
+ kind: UamResource['kind'];
367
+ branch: string;
368
+ component?: {
369
+ displayList: Array<{
370
+ id: string;
371
+ name: string;
372
+ kind: UamDisplayNodeKind;
373
+ }>;
374
+ controllers: Array<{
375
+ name: string;
376
+ pages: Array<{
377
+ id: string;
378
+ name: string;
379
+ }>;
380
+ }>;
381
+ transitions: Array<{
382
+ name: string;
383
+ }>;
384
+ };
385
+ }
386
+ interface MaterializeSessionSnapshot extends BackendSessionSnapshot {
387
+ mode: 'fullProject';
388
+ reason?: string;
389
+ materializeRevision: number;
390
+ saveRevision: number;
391
+ writtenPaths: string[];
392
+ skippedPaths: string[];
393
+ diagnostics: BackendDiagnostic[];
394
+ }
395
+ interface BackendSuccess<T> {
396
+ ok: true;
397
+ meta: BackendResponseMeta;
398
+ data: T;
399
+ }
400
+ interface BackendFailure<E extends BackendError = BackendError> {
401
+ ok: false;
402
+ meta: BackendResponseMeta;
403
+ error: E;
404
+ session?: BackendSessionSnapshot;
405
+ }
406
+ type BackendResult<T, E extends BackendError = BackendError> = BackendSuccess<T> | BackendFailure<E>;
407
+ interface SessionNotFoundError {
408
+ code: 'session_not_found';
409
+ message: string;
410
+ sessionId: string;
411
+ }
412
+ interface SessionCloseFailedError {
413
+ code: 'session_close_failed';
414
+ message: string;
415
+ sessionId: string;
416
+ lockFilePath: string;
417
+ }
418
+ interface SessionStaleWriteError {
419
+ code: 'stale_write';
420
+ message: string;
421
+ sessionId: string;
422
+ canonicalPathKey: string;
423
+ expectedRevision: number;
424
+ actualRevision: number;
425
+ }
426
+ interface InProcessLockConflictError {
427
+ code: 'lock_conflict';
428
+ kind: 'in_process_session_exists';
429
+ message: string;
430
+ canonicalPathKey: string;
431
+ holderSessionId: string;
432
+ lockFilePath?: string;
433
+ }
434
+ interface AdvisoryLockConflictError {
435
+ code: 'lock_conflict';
436
+ kind: 'advisory_lock_conflict';
437
+ message: string;
438
+ canonicalPathKey: string;
439
+ holderSessionId?: string;
440
+ lockFilePath: string;
441
+ }
442
+ interface SessionLimitExceededError {
443
+ code: 'session_limit_exceeded';
444
+ message: string;
445
+ maxSessions: number;
446
+ }
447
+ interface SessionIdConflictError {
448
+ code: 'session_id_conflict';
449
+ message: string;
450
+ sessionId: string;
451
+ }
452
+ interface SavePartialFailureError {
453
+ code: 'save_partial_failure';
454
+ message: string;
455
+ sessionId: string;
456
+ canonicalPathKey: string;
457
+ attemptedRevision: number;
458
+ lastSavedRevision: number;
459
+ committedPaths: string[];
460
+ failedPaths: string[];
461
+ diskMayBePartiallyUpdated: boolean;
462
+ recoveryPaths?: string[];
463
+ }
464
+ interface UamFidelityUnsupportedError {
465
+ code: 'uam_fidelity_unsupported';
466
+ message: string;
467
+ sessionId: string;
468
+ canonicalPathKey: string;
469
+ }
470
+ interface MaterializeValidationFailedError {
471
+ code: 'materialize_validation_failed';
472
+ message: string;
473
+ sessionId: string;
474
+ canonicalPathKey: string;
475
+ issueCount: number;
476
+ diagnostics: BackendDiagnostic[];
477
+ }
478
+ interface MaterializeWriteFailedError {
479
+ code: 'write_failed';
480
+ message: string;
481
+ sessionId: string;
482
+ canonicalPathKey: string;
483
+ attemptedRevision: number;
484
+ lastSavedRevision: number;
485
+ writtenPaths: string[];
486
+ failedPaths: string[];
487
+ skippedPaths: string[];
488
+ diagnostics: BackendDiagnostic[];
489
+ diskMayBePartiallyUpdated: boolean;
490
+ recoveryPaths?: string[];
491
+ }
492
+ type BackendEventKind = 'session.opened' | 'transaction.applied' | 'transaction.rejected' | 'save.started' | 'save.completed' | 'save.failed' | 'session.closeRequested' | 'session.closed' | 'cache.invalidated' | 'cache.updated';
493
+ interface BackendEvent {
494
+ sequence: number;
495
+ kind: BackendEventKind;
496
+ timestamp: string;
497
+ sessionId?: string;
498
+ canonicalPathKey?: string;
499
+ revision?: number;
500
+ cacheRevision?: number;
501
+ diagnostics: BackendDiagnostic[];
502
+ payload?: unknown;
503
+ }
504
+ interface GetEventsInput {
505
+ sessionId: string;
506
+ after?: string;
507
+ limit?: number;
508
+ }
509
+ interface GetEventsSnapshot {
510
+ events: BackendEvent[];
511
+ oldestSequence: number;
512
+ currentSequence: number;
513
+ cursorExpired: boolean;
514
+ }
515
+ interface EventCursorInvalidError {
516
+ code: 'event_cursor_invalid';
517
+ message: string;
518
+ sessionId: string;
519
+ after: string;
520
+ }
521
+ interface BackendCapabilityUnavailableError {
522
+ code: 'capability_unavailable';
523
+ message: string;
524
+ capability: 'fileSystem' | 'artifact.publish' | 'artifact.restore';
525
+ requiredAdapter?: 'BackendFileSystem';
526
+ requiredHost?: 'node';
527
+ bridgeBoundary?: 'external-bridge';
528
+ }
529
+ interface BackendCacheSnapshot {
530
+ cacheRevision: number;
531
+ entries: BackendCacheEntry[];
532
+ }
533
+ interface BackendCacheEntry {
534
+ canonicalPathKey: string;
535
+ sessionId?: string;
536
+ revision: number;
537
+ lastSavedRevision: number;
538
+ dirty: boolean;
539
+ valid: boolean;
540
+ indexedAt: string;
541
+ summary: {
542
+ resourceCount: number;
543
+ packageCount?: number;
544
+ diagnostics: BackendDiagnostic[];
545
+ };
546
+ }
547
+ interface GetCacheSnapshotInput {
548
+ sessionId: string;
549
+ }
550
+ interface RefreshCacheInput {
551
+ sessionId: string;
552
+ reason?: 'manual' | 'session_open' | 'after_save';
553
+ }
554
+ type BackendError = SessionNotFoundError | SessionCloseFailedError | TransactionPreviewError | EntityQueryError | SessionReadError | SessionStaleReadError | SessionIdConflictError | SessionLimitExceededError | SessionStaleWriteError | InProcessLockConflictError | AdvisoryLockConflictError | SavePartialFailureError | UamFidelityUnsupportedError | MaterializeValidationFailedError | MaterializeWriteFailedError | PathPolicyViolationError | EventCursorInvalidError | BackendCapabilityUnavailableError | ProjectRootNotAllowedError | ProjectOpenFailedError | ApplyUamTransactionAppError;
555
+ interface ProjectRootNotAllowedError {
556
+ code: 'project_root_not_allowed';
557
+ message: string;
558
+ projectPath: string;
559
+ }
560
+ type ProjectOpenFailureReason = 'project_not_found' | 'not_a_project_file' | 'no_project_file' | 'multiple_project_files' | 'symbolic_link_unsupported' | 'access_denied' | 'project_read_failed' | 'unknown';
561
+ interface ProjectOpenFailedError {
562
+ code: 'project_open_failed';
563
+ /** Why the project could not be opened; `unknown` keeps unexpected exception details out of the result. */
564
+ reason: ProjectOpenFailureReason;
565
+ message: string;
566
+ projectPath: string;
567
+ }
568
+ interface ApplySessionTransactionInput {
569
+ sessionId: string;
570
+ expectedRevision: number;
571
+ operations: UamTransactionOperation[];
572
+ }
573
+ interface BackendTransactionPreview {
574
+ sessionId: string;
575
+ baseRevision: number;
576
+ /** Revision after applying this batch at baseRevision, including an empty batch. Not reserved. */
577
+ projectedRevision: number;
578
+ mode: 'execute-and-discard';
579
+ /** Complete, bounded comparison of current and projected UAM, not unsaved changes since last save. */
580
+ impact: {
581
+ entities: BackendTransactionEntityChange[]; /** Project-relative paths from the actual ProjectWriter, including empty directories. Not a disk write plan. */
582
+ files: Array<{
583
+ path: string;
584
+ kind: 'file' | 'directory';
585
+ change: 'added' | 'removed' | 'updated';
586
+ }>;
587
+ };
588
+ persistence: {
589
+ requiredAfterApply: true;
590
+ nextAction: 'saveSession' | 'materializeSession' | 'host-action';
591
+ fileSystemAvailable: boolean;
592
+ uamFidelity: BackendSessionSnapshot['uamFidelity']; /** Preflight never verifies filesystem permissions, materialize destinations or actual disk state. */
593
+ writeVerified: false;
594
+ };
595
+ }
596
+ interface BackendTransactionEntityChange {
597
+ target: BackendEntityTarget;
598
+ change: 'added' | 'removed' | 'updated';
599
+ /** Changed top-level property names; child collections contain identities and preserve their order. */
600
+ fields: string[];
601
+ }
602
+ interface TransactionPreviewError {
603
+ code: 'transaction_preview_failed';
604
+ message: string;
605
+ sessionId: string;
606
+ reason: 'response_budget_exceeded' | 'projection_failed';
607
+ }
608
+ interface GetProjectOutlineInput {
609
+ sessionId: string;
610
+ }
611
+ interface ValidateSessionInput {
612
+ sessionId: string;
613
+ }
614
+ interface OpenProjectSessionInput {
615
+ /** Authoritative UAM project. Use BackendRuntime.openSession() when importing an existing project from storage. */
616
+ project: UamProject;
617
+ sessionId?: string;
618
+ /** Session identity only; without explicit storage or a per-call filesystem this grants no filesystem access. */
619
+ canonicalProjectPath?: string;
620
+ /** Host-defined session identity; not a filesystem authorization or an allowed-root override. */
621
+ canonicalPathKey?: string;
622
+ /** Optional writeback target for the authoritative UAM project; this is not an import source. */
623
+ storage?: BackendProjectSessionStorage;
624
+ }
625
+ interface BackendProjectSessionStorage {
626
+ fileSystem: BackendFileSystem;
627
+ fairyPath: string;
628
+ canonicalProjectPath?: string;
629
+ canonicalPathKey?: string;
630
+ }
631
+ interface SaveSessionInput {
632
+ sessionId: string;
633
+ expectedRevision?: number;
634
+ targetPath?: string;
635
+ fileSystem?: BackendFileSystem;
636
+ force?: boolean;
637
+ mode?: 'materializeCleanSession';
638
+ }
639
+ interface MaterializeSessionInput {
640
+ sessionId: string;
641
+ expectedRevision?: number;
642
+ storage?: BackendProjectSessionStorage;
643
+ targetPath?: string;
644
+ fileSystem?: BackendFileSystem;
645
+ mode?: 'fullProject';
646
+ reason?: string;
647
+ }
648
+ interface BackendRuntimeOptions {
649
+ fileSystem?: BackendFileSystem;
650
+ host?: BackendHostAdapter;
651
+ /** Canonical filesystem roots available to file-backed sessions. Omit for unrestricted library use; an empty list allows no roots. */
652
+ allowedProjectRoots?: readonly string[];
653
+ /** Maximum open sessions, each holding its project in memory. Defaults to 32. */
654
+ maxSessions?: number;
655
+ /** Close clean idle sessions after this interval. Defaults to 30 minutes; zero disables expiry. */
656
+ idleSessionTimeoutMs?: number;
657
+ }
658
+ //#endregion
659
+ //#region src/runtime.d.ts
660
+ declare class BackendRuntime {
661
+ private readonly fileSystem?;
662
+ private readonly capabilities;
663
+ private readonly sessions;
664
+ private readonly sessionOperations;
665
+ private readonly context;
666
+ private readonly readService;
667
+ private readonly runtimeService;
668
+ private readonly authoringService;
669
+ private readonly persistenceService;
670
+ private readonly cacheService;
671
+ private readonly eventService;
672
+ constructor(options?: BackendRuntimeOptions);
673
+ getCapabilities(): BackendSuccess<BackendCapabilities>;
674
+ openSession(input: {
675
+ projectPath: string;
676
+ }): Promise<BackendResult<BackendSessionSnapshot, InProcessLockConflictError | AdvisoryLockConflictError | BackendCapabilityUnavailableError | ProjectRootNotAllowedError | ProjectOpenFailedError | SessionLimitExceededError>>;
677
+ openProjectSession(input: OpenProjectSessionInput): BackendResult<BackendSessionSnapshot, InProcessLockConflictError | SessionIdConflictError | SessionLimitExceededError>;
678
+ getSession(input: {
679
+ sessionId: string;
680
+ }): BackendResult<BackendSessionSnapshot, SessionNotFoundError>;
681
+ getProjectOutline(input: GetProjectOutlineInput): BackendResult<BackendProjectOutline, SessionNotFoundError>;
682
+ queryEntity(input: QueryEntityInput): BackendResult<BackendEntitySnapshot, SessionNotFoundError | EntityQueryError>;
683
+ readSessionState(input: ReadSessionStateInput): BackendResult<BackendSessionStateSnapshot, SessionNotFoundError | SessionReadError | SessionStaleReadError>;
684
+ readResourceBytes(input: ReadResourceBytesInput): BackendResult<BackendResourceBytesSnapshot, SessionNotFoundError | SessionReadError | SessionStaleReadError>;
685
+ validateSession(input: ValidateSessionInput): BackendResult<ProjectValidationReport, SessionNotFoundError>;
686
+ preflightTransaction(input: ApplySessionTransactionInput): Promise<BackendResult<BackendTransactionPreview, SessionNotFoundError | SessionStaleWriteError | ApplyUamTransactionAppError | TransactionPreviewError>>;
687
+ applyTransaction(input: ApplySessionTransactionInput): Promise<BackendResult<BackendSessionSnapshot, SessionNotFoundError | SessionStaleWriteError | ApplyUamTransactionAppError>>;
688
+ saveSession(input: SaveSessionInput): Promise<BackendResult<BackendSessionSnapshot | MaterializeSessionSnapshot, SessionNotFoundError | SessionStaleWriteError | SavePartialFailureError | UamFidelityUnsupportedError | MaterializeValidationFailedError | MaterializeWriteFailedError | PathPolicyViolationError | InProcessLockConflictError | BackendCapabilityUnavailableError>>;
689
+ materializeSession(input: MaterializeSessionInput): Promise<BackendResult<MaterializeSessionSnapshot, SessionNotFoundError | SessionStaleWriteError | UamFidelityUnsupportedError | MaterializeValidationFailedError | MaterializeWriteFailedError | PathPolicyViolationError | InProcessLockConflictError | BackendCapabilityUnavailableError>>;
690
+ closeSession(input: {
691
+ sessionId: string;
692
+ }): Promise<BackendResult<{
693
+ sessionId: string;
694
+ closed: true;
695
+ }, SessionNotFoundError | SessionCloseFailedError>>;
696
+ getEvents(input: GetEventsInput): BackendResult<GetEventsSnapshot, SessionNotFoundError | EventCursorInvalidError>;
697
+ getCacheSnapshot(input: GetCacheSnapshotInput): BackendResult<BackendCacheSnapshot, SessionNotFoundError>;
698
+ refreshCache(input: RefreshCacheInput): BackendResult<BackendCacheSnapshot, SessionNotFoundError>;
699
+ }
700
+ //#endregion
701
+ //#region src/contracts.d.ts
702
+ declare const BACKEND_CONTRACT_VERSION: "3.0.0";
703
+ declare const BACKEND_CAPABILITY_SCHEMA_VERSION: 15;
704
+ declare const BACKEND_COMPATIBILITY_POLICY: {
705
+ readonly incompatibleChange: "requires contractVersion bump";
706
+ readonly capabilitySchemaChange: "requires capabilitySchemaVersion bump";
707
+ readonly additiveChange: "allowed without breaking existing consumers";
708
+ };
709
+ type BackendStage = 'read' | 'authoring' | 'runtime';
710
+ interface BackendMessage {
711
+ code: string;
712
+ message: string;
713
+ }
714
+ type BackendDiagnosticCode = BackendError['code'] | UamTransactionSupportIssueCode | ProjectDiagnosticCode;
715
+ type BackendDiagnosticOwner = 'backend' | 'core.transaction' | 'core.validation';
716
+ interface BackendDiagnostic {
717
+ code: BackendDiagnosticCode;
718
+ message: string;
719
+ severity: 'info' | 'warning' | 'error';
720
+ path?: string;
721
+ nodeKind?: string;
722
+ resourceKind?: string;
723
+ gearKind?: string;
724
+ field?: string;
725
+ operationKind?: string;
726
+ opIndex?: number;
727
+ opId?: string;
728
+ /** Present for catalogued diagnostics only; original codes and classification are preserved. */
729
+ owner?: BackendDiagnosticOwner;
730
+ docsUri?: string;
731
+ remediation?: BackendDiagnosticRemediation;
732
+ }
733
+ interface BackendDiagnosticRemediation {
734
+ kind: 'refresh-and-replan' | 'revise-selector' | 'revise-operation' | 'host-action';
735
+ message: string;
736
+ /** A read-only starting point, never permission to retry or mutate. */
737
+ read?: {
738
+ method: 'getProjectOutline';
739
+ input: {
740
+ sessionId: string;
741
+ };
742
+ };
743
+ }
744
+ interface BackendResponseMeta {
745
+ requestId: string;
746
+ sessionId?: string;
747
+ revision?: number;
748
+ durationMs: number;
749
+ warnings: BackendMessage[];
750
+ diagnostics: BackendDiagnostic[];
751
+ stage: BackendStage;
752
+ contractVersion: typeof BACKEND_CONTRACT_VERSION;
753
+ capabilitySchemaVersion: typeof BACKEND_CAPABILITY_SCHEMA_VERSION;
754
+ }
755
+ //#endregion
756
+ export { EntityQueryError as $, BackendFileStat as A, UamFidelityUnsupportedError as At, BackendResourceBytesSnapshot as B, BackendComponentSnapshot as C, SessionIdConflictError as Ct, BackendEvent as D, SessionStaleReadError as Dt, BackendError as E, SessionReadError as Et, BackendProjectOutline as F, BackendSessionPackageModel as G, BackendResult as H, BackendProjectOutlinePackage as I, BackendSessionSnapshot as J, BackendSessionProjectModel as K, BackendProjectOutlineResource as L, BackendHostAdapter as M, BackendMethodName as N, BackendEventKind as O, SessionStaleWriteError as Ot, BackendPackageSnapshot as P, BackendTransactionPreview as Q, BackendProjectSessionStorage as R, BackendCapabilityUnavailableError as S, SessionCloseFailedError as St, BackendEntityTarget as T, SessionNotFoundError as Tt, BackendRuntimeOptions as U, BackendResourceSnapshot as V, BackendSessionLock as W, BackendSuccess as X, BackendSessionStateSnapshot as Y, BackendTransactionEntityChange as Z, BackendArtifactBridgeCapability as _, ReadResourceBytesInput as _t, BackendDiagnosticCode as a, InProcessLockConflictError as at, BackendCapabilities as b, SavePartialFailureError as bt, BackendMessage as c, MaterializeValidationFailedError as ct, BackendRuntime as d, ProjectOpenFailedError as dt, EventCursorInvalidError as et, AdvisoryLockConflictError as f, ProjectOpenFailureReason as ft, BACKEND_TRANSACTION_PREVIEW_LIMITS as g, QueryEntityInput as gt, BACKEND_SESSION_READ_LIMITS as h, ProjectWriteTransactionResult as ht, BackendDiagnostic as i, GetProjectOutlineInput as it, BackendFileSystem as j, ValidateSessionInput as jt, BackendFailure as k, TransactionPreviewError as kt, BackendResponseMeta as l, MaterializeWriteFailedError as lt, BACKEND_ENTITY_QUERY_LIMITS as m, ProjectWriteTransactionError as mt, BACKEND_COMPATIBILITY_POLICY as n, GetEventsInput as nt, BackendDiagnosticOwner as o, MaterializeSessionInput as ot, ApplySessionTransactionInput as p, ProjectRootNotAllowedError as pt, BackendSessionResourceModel as q, BACKEND_CONTRACT_VERSION as r, GetEventsSnapshot as rt, BackendDiagnosticRemediation as s, MaterializeSessionSnapshot as st, BACKEND_CAPABILITY_SCHEMA_VERSION as t, GetCacheSnapshotInput as tt, BackendStage as u, OpenProjectSessionInput as ut, BackendCacheEntry as v, ReadSessionStateInput as vt, BackendEntitySnapshot as w, SessionLimitExceededError as wt, BackendCapabilityManifest as x, SaveSessionInput as xt, BackendCacheSnapshot as y, RefreshCacheInput as yt, BackendProjectSnapshot as z };