@openfairygui/backend 0.2.0-alpha.0 → 0.2.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.
@@ -0,0 +1,424 @@
1
+ import { UamProject, UamTransactionOperation } from "@openfairygui/core";
2
+ import { ApplyUamTransactionAppError } from "@openfairygui/functions";
3
+
4
+ //#region src/contracts.d.ts
5
+ declare const BACKEND_CONTRACT_VERSION: "1.1.0-p2";
6
+ declare const BACKEND_CAPABILITY_SCHEMA_VERSION: 2;
7
+ declare const BACKEND_COMPATIBILITY_POLICY: {
8
+ readonly incompatibleChange: "requires contractVersion bump";
9
+ readonly capabilitySchemaChange: "requires capabilitySchemaVersion bump";
10
+ readonly additiveChange: "allowed without breaking existing consumers";
11
+ };
12
+ type BackendStage = 'read' | 'authoring' | 'runtime';
13
+ interface BackendMessage {
14
+ code: string;
15
+ message: string;
16
+ }
17
+ interface BackendDiagnostic {
18
+ code: string;
19
+ message: string;
20
+ severity: 'info' | 'warning' | 'error';
21
+ }
22
+ interface BackendResponseMeta {
23
+ requestId: string;
24
+ sessionId?: string;
25
+ revision?: number;
26
+ durationMs: number;
27
+ warnings: BackendMessage[];
28
+ diagnostics: BackendDiagnostic[];
29
+ stage: BackendStage;
30
+ contractVersion: typeof BACKEND_CONTRACT_VERSION;
31
+ capabilitySchemaVersion: typeof BACKEND_CAPABILITY_SCHEMA_VERSION;
32
+ }
33
+ //#endregion
34
+ //#region src/path-policy.d.ts
35
+ interface PathPolicyViolationError {
36
+ code: 'path_policy_violation';
37
+ message: string;
38
+ policy: 'save_target';
39
+ attemptedPath: string;
40
+ allowedPath: string;
41
+ }
42
+ //#endregion
43
+ //#region src/runtime.d.ts
44
+ interface BackendFileHandle {
45
+ writeFile(content: string): Promise<void>;
46
+ close(): Promise<void>;
47
+ }
48
+ interface BackendFileStat {
49
+ isFile(): boolean;
50
+ isDirectory(): boolean;
51
+ }
52
+ interface BackendFileSystem {
53
+ stat(filePath: string): Promise<BackendFileStat>;
54
+ readdir(dirPath: string): Promise<string[]>;
55
+ readFile(filePath: string): Promise<string>;
56
+ readFileRaw(filePath: string): Promise<Uint8Array>;
57
+ writeFile(filePath: string, content: string): Promise<void>;
58
+ writeFileRaw(filePath: string, data: Uint8Array): Promise<void>;
59
+ mkdir(dirPath: string, options?: {
60
+ recursive?: boolean;
61
+ }): Promise<void>;
62
+ resolvePath(filePath: string): Promise<string>;
63
+ openExclusive(filePath: string): Promise<BackendFileHandle>;
64
+ unlink(filePath: string): Promise<void>;
65
+ join(...paths: string[]): string;
66
+ dirname(filePath: string): string;
67
+ resolve(...paths: string[]): string;
68
+ }
69
+ interface BackendHostAdapter {
70
+ lockMetadata?(input: {
71
+ canonicalPathKey: string;
72
+ canonicalProjectPath: string;
73
+ lockFilePath: string;
74
+ }): unknown;
75
+ }
76
+ interface BackendArtifactBridgeCapability {
77
+ available: false;
78
+ requiredHost: 'node';
79
+ executionBoundary: 'external-bridge';
80
+ bridgeEntrypoint: '@openfairygui/backend/node';
81
+ reason: string;
82
+ }
83
+ interface BackendCapabilityManifest {
84
+ browserSafe: true;
85
+ rootEntrypoint: '@openfairygui/backend';
86
+ nodeEntrypoint: '@openfairygui/backend/node';
87
+ adapters: {
88
+ fileSystem: {
89
+ injected: true;
90
+ requiredFor: readonly ['openSession', 'saveSession'];
91
+ };
92
+ host: {
93
+ injected: true;
94
+ requiredFor: readonly ['advisoryLockMetadata'];
95
+ };
96
+ };
97
+ executionBoundaries: {
98
+ projectSession: 'in-process-browser-safe';
99
+ fileBackedSession: 'adapter-backed';
100
+ artifactPublish: BackendArtifactBridgeCapability;
101
+ artifactRestore: BackendArtifactBridgeCapability;
102
+ };
103
+ diagnostics: {
104
+ stableCodes: true;
105
+ errorDiagnosticMirror: true;
106
+ };
107
+ }
108
+ interface BackendCapabilities {
109
+ contractVersion: typeof BACKEND_CONTRACT_VERSION;
110
+ capabilitySchemaVersion: typeof BACKEND_CAPABILITY_SCHEMA_VERSION;
111
+ transactionKernelOwner: '@openfairygui/core';
112
+ appSeamOwner: '@openfairygui/functions';
113
+ runtimeOwner: '@openfairygui/backend';
114
+ methods: readonly ['getCapabilities', 'openSession', 'openProjectSession', 'getSession', 'applyTransaction', 'saveSession', 'closeSession', 'getEvents', 'getJob', 'listJobs', 'cancelJob', 'getCacheSnapshot', 'refreshCache'];
115
+ read: {
116
+ capabilitySnapshot: true;
117
+ sessionSnapshot: true;
118
+ };
119
+ authoring: {
120
+ applyTransaction: true;
121
+ saveSession: true;
122
+ resourceKinds: readonly string[];
123
+ nodeKinds: readonly string[];
124
+ gearKinds: readonly string[];
125
+ unsupported: readonly ['artifact.publish', 'artifact.restore'];
126
+ };
127
+ artifact: {
128
+ publish: false;
129
+ restore: false;
130
+ status: 'bridge-required';
131
+ publishBridge: BackendArtifactBridgeCapability;
132
+ restoreBridge: BackendArtifactBridgeCapability;
133
+ };
134
+ manifest: BackendCapabilityManifest;
135
+ compatibilityPolicy: typeof BACKEND_COMPATIBILITY_POLICY;
136
+ runtime: {
137
+ sessionRuntime: true;
138
+ advisoryLocking: true;
139
+ coordinatedSave: true;
140
+ atomicSave: false;
141
+ staleRevisionProtection: true;
142
+ pathPolicy: {
143
+ canonicalization: 'realpath+normalized-casefold';
144
+ sessionIdentity: 'project-root';
145
+ saveTarget: 'opened-project-only';
146
+ outputTargets: 'deferred';
147
+ workspaceBoundary: 'project-root-only';
148
+ };
149
+ events: {
150
+ polling: true;
151
+ subscriptions: false;
152
+ retentionLimit: 1000;
153
+ sequenceScope: 'runtime';
154
+ };
155
+ jobs: {
156
+ inMemory: true;
157
+ cooperativeCancel: true;
158
+ persistent: false;
159
+ supportedKinds: readonly ['cache.refresh'];
160
+ artifactJobs: false;
161
+ completedRetentionLimit: 100;
162
+ };
163
+ cache: {
164
+ derivedReadOnly: true;
165
+ keyedBy: 'canonicalPathKey';
166
+ sourceOfTruth: false;
167
+ refreshMethod: 'refreshCache';
168
+ };
169
+ };
170
+ }
171
+ interface BackendSessionSnapshot {
172
+ sessionId: string;
173
+ canonicalProjectPath: string;
174
+ revision: number;
175
+ lastSavedRevision: number;
176
+ dirty: boolean;
177
+ lockHeld: boolean;
178
+ capabilities: BackendCapabilities;
179
+ }
180
+ interface BackendSuccess<T> {
181
+ ok: true;
182
+ meta: BackendResponseMeta;
183
+ data: T;
184
+ }
185
+ interface BackendFailure<E extends BackendError = BackendError> {
186
+ ok: false;
187
+ meta: BackendResponseMeta;
188
+ error: E;
189
+ session?: BackendSessionSnapshot;
190
+ }
191
+ type BackendResult<T, E extends BackendError = BackendError> = BackendSuccess<T> | BackendFailure<E>;
192
+ interface SessionNotFoundError {
193
+ code: 'session_not_found';
194
+ message: string;
195
+ sessionId: string;
196
+ }
197
+ interface SessionStaleWriteError {
198
+ code: 'stale_write';
199
+ message: string;
200
+ sessionId: string;
201
+ canonicalPathKey: string;
202
+ expectedRevision: number;
203
+ actualRevision: number;
204
+ }
205
+ interface InProcessLockConflictError {
206
+ code: 'lock_conflict';
207
+ kind: 'in_process_session_exists';
208
+ message: string;
209
+ canonicalPathKey: string;
210
+ holderSessionId: string;
211
+ lockFilePath?: string;
212
+ }
213
+ interface AdvisoryLockConflictError {
214
+ code: 'lock_conflict';
215
+ kind: 'advisory_lock_conflict';
216
+ message: string;
217
+ canonicalPathKey: string;
218
+ holderSessionId?: string;
219
+ lockFilePath: string;
220
+ }
221
+ interface SavePartialFailureError {
222
+ code: 'save_partial_failure';
223
+ message: string;
224
+ sessionId: string;
225
+ canonicalPathKey: string;
226
+ attemptedRevision: number;
227
+ lastSavedRevision: number;
228
+ committedPaths: string[];
229
+ failedPaths: string[];
230
+ diskMayBePartiallyUpdated: true;
231
+ }
232
+ type BackendEventKind = 'session.opened' | 'transaction.applied' | 'transaction.rejected' | 'save.started' | 'save.completed' | 'save.failed' | 'session.closeRequested' | 'session.closed' | 'cache.invalidated' | 'cache.updated' | 'job.created' | 'job.started' | 'job.progress' | 'job.cancelRequested' | 'job.cancelled' | 'job.completed' | 'job.failed';
233
+ interface BackendEvent {
234
+ sequence: number;
235
+ kind: BackendEventKind;
236
+ timestamp: string;
237
+ sessionId?: string;
238
+ canonicalPathKey?: string;
239
+ revision?: number;
240
+ cacheRevision?: number;
241
+ jobId?: string;
242
+ diagnostics: BackendDiagnostic[];
243
+ payload?: unknown;
244
+ }
245
+ interface GetEventsInput {
246
+ sessionId: string;
247
+ after?: string;
248
+ limit?: number;
249
+ }
250
+ interface GetEventsSnapshot {
251
+ events: BackendEvent[];
252
+ oldestSequence: number;
253
+ currentSequence: number;
254
+ cursorExpired: boolean;
255
+ }
256
+ interface EventCursorInvalidError {
257
+ code: 'event_cursor_invalid';
258
+ message: string;
259
+ sessionId: string;
260
+ after: string;
261
+ }
262
+ type BackendJobStatus = 'queued' | 'running' | 'completed' | 'failed' | 'cancelled';
263
+ type BackendJobKind = 'cache.refresh';
264
+ type BackendJobListStatusFilter = BackendJobStatus | 'active' | 'terminal';
265
+ interface BackendJobProgress {
266
+ completed: number;
267
+ total?: number;
268
+ message?: string;
269
+ }
270
+ interface BackendJobSnapshot {
271
+ jobId: string;
272
+ kind: BackendJobKind;
273
+ status: BackendJobStatus;
274
+ createdAt: string;
275
+ startedAt?: string;
276
+ finishedAt?: string;
277
+ sessionId?: string;
278
+ canonicalPathKey?: string;
279
+ revision?: number;
280
+ cacheRevision?: number;
281
+ diagnostics: BackendDiagnostic[];
282
+ progress?: BackendJobProgress;
283
+ result?: unknown;
284
+ error?: BackendError;
285
+ }
286
+ interface BackendJobListSnapshot {
287
+ jobs: BackendJobSnapshot[];
288
+ }
289
+ interface GetJobInput {
290
+ sessionId: string;
291
+ jobId: string;
292
+ }
293
+ interface ListJobsInput {
294
+ sessionId: string;
295
+ status?: BackendJobListStatusFilter;
296
+ kind?: BackendJobKind;
297
+ limit?: number;
298
+ }
299
+ interface CancelJobInput {
300
+ sessionId: string;
301
+ jobId: string;
302
+ }
303
+ interface BackendJobNotFoundError {
304
+ code: 'job_not_found';
305
+ message: string;
306
+ sessionId: string;
307
+ jobId: string;
308
+ }
309
+ interface BackendJobNotCancellableError {
310
+ code: 'job_not_cancellable';
311
+ message: string;
312
+ sessionId: string;
313
+ jobId: string;
314
+ status: 'completed' | 'failed' | 'cancelled';
315
+ }
316
+ interface BackendJobCancelledError {
317
+ code: 'job_cancelled';
318
+ message: string;
319
+ sessionId: string;
320
+ jobId: string;
321
+ }
322
+ interface CacheRefreshFailedError {
323
+ code: 'cache_refresh_failed';
324
+ message: string;
325
+ sessionId: string;
326
+ jobId: string;
327
+ causeCode?: string;
328
+ }
329
+ interface BackendCapabilityUnavailableError {
330
+ code: 'capability_unavailable';
331
+ message: string;
332
+ capability: 'fileSystem' | 'artifact.publish' | 'artifact.restore';
333
+ requiredAdapter?: 'BackendFileSystem';
334
+ requiredHost?: 'node';
335
+ bridgeBoundary?: 'external-bridge';
336
+ }
337
+ type BackendJobErrors = BackendJobNotFoundError | BackendJobNotCancellableError | BackendJobCancelledError | CacheRefreshFailedError;
338
+ interface BackendCacheSnapshot {
339
+ cacheRevision: number;
340
+ entries: BackendCacheEntry[];
341
+ }
342
+ interface BackendCacheEntry {
343
+ canonicalPathKey: string;
344
+ sessionId?: string;
345
+ revision: number;
346
+ lastSavedRevision: number;
347
+ dirty: boolean;
348
+ valid: boolean;
349
+ indexedAt: string;
350
+ summary: {
351
+ resourceCount: number;
352
+ packageCount?: number;
353
+ diagnostics: BackendDiagnostic[];
354
+ };
355
+ }
356
+ interface GetCacheSnapshotInput {
357
+ sessionId: string;
358
+ }
359
+ interface RefreshCacheInput {
360
+ sessionId: string;
361
+ reason?: 'manual' | 'session_open' | 'after_save';
362
+ }
363
+ type BackendError = SessionNotFoundError | SessionStaleWriteError | InProcessLockConflictError | AdvisoryLockConflictError | SavePartialFailureError | PathPolicyViolationError | EventCursorInvalidError | BackendJobNotFoundError | BackendJobNotCancellableError | BackendJobCancelledError | CacheRefreshFailedError | BackendCapabilityUnavailableError | ApplyUamTransactionAppError;
364
+ interface ApplySessionTransactionInput {
365
+ sessionId: string;
366
+ expectedRevision: number;
367
+ operations: UamTransactionOperation[];
368
+ }
369
+ interface OpenProjectSessionInput {
370
+ project: UamProject;
371
+ sessionId?: string;
372
+ canonicalProjectPath?: string;
373
+ canonicalPathKey?: string;
374
+ }
375
+ interface BackendRuntimeOptions {
376
+ fileSystem?: BackendFileSystem;
377
+ host?: BackendHostAdapter;
378
+ }
379
+ declare class BackendRuntime {
380
+ private readonly fileSystem?;
381
+ private readonly capabilities;
382
+ private readonly sessions;
383
+ private readonly sessionsByPath;
384
+ private readonly eventsBySession;
385
+ private readonly jobsBySession;
386
+ private readonly cacheBySession;
387
+ private eventSequence;
388
+ private readonly context;
389
+ private readonly readService;
390
+ private readonly runtimeService;
391
+ private readonly authoringService;
392
+ private readonly cacheService;
393
+ private readonly eventService;
394
+ private readonly jobService;
395
+ constructor(options?: BackendRuntimeOptions);
396
+ getCapabilities(): BackendSuccess<BackendCapabilities>;
397
+ openSession(input: {
398
+ projectPath: string;
399
+ }): Promise<BackendResult<BackendSessionSnapshot, InProcessLockConflictError | AdvisoryLockConflictError | BackendCapabilityUnavailableError>>;
400
+ openProjectSession(input: OpenProjectSessionInput): BackendResult<BackendSessionSnapshot>;
401
+ getSession(input: {
402
+ sessionId: string;
403
+ }): BackendResult<BackendSessionSnapshot, SessionNotFoundError>;
404
+ applyTransaction(input: ApplySessionTransactionInput): Promise<BackendResult<BackendSessionSnapshot, SessionNotFoundError | SessionStaleWriteError | ApplyUamTransactionAppError>>;
405
+ saveSession(input: {
406
+ sessionId: string;
407
+ expectedRevision?: number;
408
+ targetPath?: string;
409
+ }): Promise<BackendResult<BackendSessionSnapshot, SessionNotFoundError | SessionStaleWriteError | SavePartialFailureError | PathPolicyViolationError | BackendCapabilityUnavailableError>>;
410
+ closeSession(input: {
411
+ sessionId: string;
412
+ }): Promise<BackendResult<{
413
+ sessionId: string;
414
+ closed: true;
415
+ }, SessionNotFoundError>>;
416
+ getEvents(input: GetEventsInput): BackendResult<GetEventsSnapshot, SessionNotFoundError | EventCursorInvalidError>;
417
+ getJob(input: GetJobInput): BackendResult<BackendJobSnapshot, SessionNotFoundError | BackendJobNotFoundError>;
418
+ listJobs(input: ListJobsInput): BackendResult<BackendJobListSnapshot, SessionNotFoundError>;
419
+ cancelJob(input: CancelJobInput): BackendResult<BackendJobSnapshot, SessionNotFoundError | BackendJobNotFoundError | BackendJobNotCancellableError>;
420
+ getCacheSnapshot(input: GetCacheSnapshotInput): BackendResult<BackendCacheSnapshot, SessionNotFoundError>;
421
+ refreshCache(input: RefreshCacheInput): BackendResult<BackendJobSnapshot, SessionNotFoundError>;
422
+ }
423
+ //#endregion
424
+ export { BackendSuccess as A, OpenProjectSessionInput as B, BackendJobProgress as C, BackendRuntime as D, BackendResult as E, GetEventsInput as F, BACKEND_CAPABILITY_SCHEMA_VERSION as G, SavePartialFailureError as H, GetEventsSnapshot as I, BackendDiagnostic as J, BACKEND_COMPATIBILITY_POLICY as K, GetJobInput as L, CancelJobInput as M, EventCursorInvalidError as N, BackendRuntimeOptions as O, GetCacheSnapshotInput as P, InProcessLockConflictError as R, BackendJobNotFoundError as S, BackendJobStatus as T, SessionNotFoundError as U, RefreshCacheInput as V, SessionStaleWriteError as W, BackendResponseMeta as X, BackendMessage as Y, BackendStage as Z, BackendJobErrors as _, BackendCacheSnapshot as a, BackendJobListStatusFilter as b, BackendCapabilityUnavailableError as c, BackendEventKind as d, BackendFailure as f, BackendHostAdapter as g, BackendFileSystem as h, BackendCacheEntry as i, CacheRefreshFailedError as j, BackendSessionSnapshot as k, BackendError as l, BackendFileStat as m, ApplySessionTransactionInput as n, BackendCapabilities as o, BackendFileHandle as p, BACKEND_CONTRACT_VERSION as q, BackendArtifactBridgeCapability as r, BackendCapabilityManifest as s, AdvisoryLockConflictError as t, BackendEvent as u, BackendJobKind as v, BackendJobSnapshot as w, BackendJobNotCancellableError as x, BackendJobListSnapshot as y, ListJobsInput as z };