@openfairygui/backend 0.2.0-alpha.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 +59 -0
- package/dist/index.cjs +1120 -0
- package/dist/index.d.cts +364 -0
- package/dist/index.d.mts +364 -0
- package/dist/index.mjs +1091 -0
- package/package.json +54 -0
- package/src/contracts.ts +32 -0
- package/src/index.ts +50 -0
- package/src/path-policy.ts +105 -0
- package/src/runtime.ts +600 -0
- package/src/services/artifact-service.ts +9 -0
- package/src/services/authoring-service.ts +186 -0
- package/src/services/cache-service.ts +60 -0
- package/src/services/context.ts +112 -0
- package/src/services/event-service.ts +84 -0
- package/src/services/job-service.ts +239 -0
- package/src/services/read-service.ts +24 -0
- package/src/services/runtime-service.ts +125 -0
- package/src/services/session-utils.ts +42 -0
- package/src/services/snapshot-utils.ts +43 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
import { UamTransactionOperation } from "@openfairygui/core";
|
|
2
|
+
import { ApplyUamTransactionAppError } from "@openfairygui/functions";
|
|
3
|
+
import { Stats } from "node:fs";
|
|
4
|
+
|
|
5
|
+
//#region src/contracts.d.ts
|
|
6
|
+
declare const BACKEND_CONTRACT_VERSION: "1.1.0-p2";
|
|
7
|
+
declare const BACKEND_CAPABILITY_SCHEMA_VERSION: 2;
|
|
8
|
+
declare const BACKEND_COMPATIBILITY_POLICY: {
|
|
9
|
+
readonly incompatibleChange: "requires contractVersion bump";
|
|
10
|
+
readonly capabilitySchemaChange: "requires capabilitySchemaVersion bump";
|
|
11
|
+
readonly additiveChange: "allowed without breaking existing consumers";
|
|
12
|
+
};
|
|
13
|
+
type BackendStage = 'read' | 'authoring' | 'runtime';
|
|
14
|
+
interface BackendMessage {
|
|
15
|
+
code: string;
|
|
16
|
+
message: string;
|
|
17
|
+
}
|
|
18
|
+
interface BackendDiagnostic {
|
|
19
|
+
code: string;
|
|
20
|
+
message: string;
|
|
21
|
+
severity: 'info' | 'warning' | 'error';
|
|
22
|
+
}
|
|
23
|
+
interface BackendResponseMeta {
|
|
24
|
+
requestId: string;
|
|
25
|
+
sessionId?: string;
|
|
26
|
+
revision?: number;
|
|
27
|
+
durationMs: number;
|
|
28
|
+
warnings: BackendMessage[];
|
|
29
|
+
diagnostics: BackendDiagnostic[];
|
|
30
|
+
stage: BackendStage;
|
|
31
|
+
contractVersion: typeof BACKEND_CONTRACT_VERSION;
|
|
32
|
+
capabilitySchemaVersion: typeof BACKEND_CAPABILITY_SCHEMA_VERSION;
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/path-policy.d.ts
|
|
36
|
+
interface PathPolicyViolationError {
|
|
37
|
+
code: 'path_policy_violation';
|
|
38
|
+
message: string;
|
|
39
|
+
policy: 'save_target';
|
|
40
|
+
attemptedPath: string;
|
|
41
|
+
allowedPath: string;
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/runtime.d.ts
|
|
45
|
+
interface BackendFileHandle {
|
|
46
|
+
writeFile(content: string): Promise<void>;
|
|
47
|
+
close(): Promise<void>;
|
|
48
|
+
}
|
|
49
|
+
interface BackendFileSystem {
|
|
50
|
+
stat(filePath: string): Promise<Stats>;
|
|
51
|
+
readdir(dirPath: string): Promise<string[]>;
|
|
52
|
+
readFile(filePath: string): Promise<string>;
|
|
53
|
+
readFileRaw(filePath: string): Promise<Uint8Array>;
|
|
54
|
+
writeFile(filePath: string, content: string): Promise<void>;
|
|
55
|
+
writeFileRaw(filePath: string, data: Uint8Array): Promise<void>;
|
|
56
|
+
mkdir(dirPath: string, options?: {
|
|
57
|
+
recursive?: boolean;
|
|
58
|
+
}): Promise<void>;
|
|
59
|
+
resolvePath(filePath: string): Promise<string>;
|
|
60
|
+
openExclusive(filePath: string): Promise<BackendFileHandle>;
|
|
61
|
+
unlink(filePath: string): Promise<void>;
|
|
62
|
+
join(...paths: string[]): string;
|
|
63
|
+
dirname(filePath: string): string;
|
|
64
|
+
resolve(...paths: string[]): string;
|
|
65
|
+
}
|
|
66
|
+
interface BackendCapabilities {
|
|
67
|
+
contractVersion: typeof BACKEND_CONTRACT_VERSION;
|
|
68
|
+
capabilitySchemaVersion: typeof BACKEND_CAPABILITY_SCHEMA_VERSION;
|
|
69
|
+
transactionKernelOwner: '@openfairygui/core';
|
|
70
|
+
appSeamOwner: '@openfairygui/functions';
|
|
71
|
+
runtimeOwner: '@openfairygui/backend';
|
|
72
|
+
methods: readonly ['getCapabilities', 'openSession', 'getSession', 'applyTransaction', 'saveSession', 'closeSession', 'getEvents', 'getJob', 'listJobs', 'cancelJob', 'getCacheSnapshot', 'refreshCache'];
|
|
73
|
+
read: {
|
|
74
|
+
capabilitySnapshot: true;
|
|
75
|
+
sessionSnapshot: true;
|
|
76
|
+
};
|
|
77
|
+
authoring: {
|
|
78
|
+
applyTransaction: true;
|
|
79
|
+
saveSession: true;
|
|
80
|
+
resourceKinds: readonly string[];
|
|
81
|
+
nodeKinds: readonly string[];
|
|
82
|
+
gearKinds: readonly string[];
|
|
83
|
+
unsupported: readonly ['artifact.publish', 'artifact.restore'];
|
|
84
|
+
};
|
|
85
|
+
artifact: {
|
|
86
|
+
publish: false;
|
|
87
|
+
restore: false;
|
|
88
|
+
status: 'deferred';
|
|
89
|
+
};
|
|
90
|
+
compatibilityPolicy: typeof BACKEND_COMPATIBILITY_POLICY;
|
|
91
|
+
runtime: {
|
|
92
|
+
sessionRuntime: true;
|
|
93
|
+
advisoryLocking: true;
|
|
94
|
+
coordinatedSave: true;
|
|
95
|
+
atomicSave: false;
|
|
96
|
+
staleRevisionProtection: true;
|
|
97
|
+
pathPolicy: {
|
|
98
|
+
canonicalization: 'realpath+normalized-casefold';
|
|
99
|
+
sessionIdentity: 'project-root';
|
|
100
|
+
saveTarget: 'opened-project-only';
|
|
101
|
+
outputTargets: 'deferred';
|
|
102
|
+
workspaceBoundary: 'project-root-only';
|
|
103
|
+
};
|
|
104
|
+
events: {
|
|
105
|
+
polling: true;
|
|
106
|
+
subscriptions: false;
|
|
107
|
+
retentionLimit: 1000;
|
|
108
|
+
sequenceScope: 'runtime';
|
|
109
|
+
};
|
|
110
|
+
jobs: {
|
|
111
|
+
inMemory: true;
|
|
112
|
+
cooperativeCancel: true;
|
|
113
|
+
persistent: false;
|
|
114
|
+
supportedKinds: readonly ['cache.refresh'];
|
|
115
|
+
artifactJobs: false;
|
|
116
|
+
completedRetentionLimit: 100;
|
|
117
|
+
};
|
|
118
|
+
cache: {
|
|
119
|
+
derivedReadOnly: true;
|
|
120
|
+
keyedBy: 'canonicalPathKey';
|
|
121
|
+
sourceOfTruth: false;
|
|
122
|
+
refreshMethod: 'refreshCache';
|
|
123
|
+
};
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
interface BackendSessionSnapshot {
|
|
127
|
+
sessionId: string;
|
|
128
|
+
canonicalProjectPath: string;
|
|
129
|
+
revision: number;
|
|
130
|
+
lastSavedRevision: number;
|
|
131
|
+
dirty: boolean;
|
|
132
|
+
lockHeld: boolean;
|
|
133
|
+
capabilities: BackendCapabilities;
|
|
134
|
+
}
|
|
135
|
+
interface BackendSuccess<T> {
|
|
136
|
+
ok: true;
|
|
137
|
+
meta: BackendResponseMeta;
|
|
138
|
+
data: T;
|
|
139
|
+
}
|
|
140
|
+
interface BackendFailure<E extends BackendError = BackendError> {
|
|
141
|
+
ok: false;
|
|
142
|
+
meta: BackendResponseMeta;
|
|
143
|
+
error: E;
|
|
144
|
+
session?: BackendSessionSnapshot;
|
|
145
|
+
}
|
|
146
|
+
type BackendResult<T, E extends BackendError = BackendError> = BackendSuccess<T> | BackendFailure<E>;
|
|
147
|
+
interface SessionNotFoundError {
|
|
148
|
+
code: 'session_not_found';
|
|
149
|
+
message: string;
|
|
150
|
+
sessionId: string;
|
|
151
|
+
}
|
|
152
|
+
interface SessionStaleWriteError {
|
|
153
|
+
code: 'stale_write';
|
|
154
|
+
message: string;
|
|
155
|
+
sessionId: string;
|
|
156
|
+
canonicalPathKey: string;
|
|
157
|
+
expectedRevision: number;
|
|
158
|
+
actualRevision: number;
|
|
159
|
+
}
|
|
160
|
+
interface InProcessLockConflictError {
|
|
161
|
+
code: 'lock_conflict';
|
|
162
|
+
kind: 'in_process_session_exists';
|
|
163
|
+
message: string;
|
|
164
|
+
canonicalPathKey: string;
|
|
165
|
+
holderSessionId: string;
|
|
166
|
+
lockFilePath?: string;
|
|
167
|
+
}
|
|
168
|
+
interface AdvisoryLockConflictError {
|
|
169
|
+
code: 'lock_conflict';
|
|
170
|
+
kind: 'advisory_lock_conflict';
|
|
171
|
+
message: string;
|
|
172
|
+
canonicalPathKey: string;
|
|
173
|
+
holderSessionId?: string;
|
|
174
|
+
lockFilePath: string;
|
|
175
|
+
}
|
|
176
|
+
interface SavePartialFailureError {
|
|
177
|
+
code: 'save_partial_failure';
|
|
178
|
+
message: string;
|
|
179
|
+
sessionId: string;
|
|
180
|
+
canonicalPathKey: string;
|
|
181
|
+
attemptedRevision: number;
|
|
182
|
+
lastSavedRevision: number;
|
|
183
|
+
committedPaths: string[];
|
|
184
|
+
failedPaths: string[];
|
|
185
|
+
diskMayBePartiallyUpdated: true;
|
|
186
|
+
}
|
|
187
|
+
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';
|
|
188
|
+
interface BackendEvent {
|
|
189
|
+
sequence: number;
|
|
190
|
+
kind: BackendEventKind;
|
|
191
|
+
timestamp: string;
|
|
192
|
+
sessionId?: string;
|
|
193
|
+
canonicalPathKey?: string;
|
|
194
|
+
revision?: number;
|
|
195
|
+
cacheRevision?: number;
|
|
196
|
+
jobId?: string;
|
|
197
|
+
diagnostics: BackendDiagnostic[];
|
|
198
|
+
payload?: unknown;
|
|
199
|
+
}
|
|
200
|
+
interface GetEventsInput {
|
|
201
|
+
sessionId: string;
|
|
202
|
+
after?: string;
|
|
203
|
+
limit?: number;
|
|
204
|
+
}
|
|
205
|
+
interface GetEventsSnapshot {
|
|
206
|
+
events: BackendEvent[];
|
|
207
|
+
oldestSequence: number;
|
|
208
|
+
currentSequence: number;
|
|
209
|
+
cursorExpired: boolean;
|
|
210
|
+
}
|
|
211
|
+
interface EventCursorInvalidError {
|
|
212
|
+
code: 'event_cursor_invalid';
|
|
213
|
+
message: string;
|
|
214
|
+
sessionId: string;
|
|
215
|
+
after: string;
|
|
216
|
+
}
|
|
217
|
+
type BackendJobStatus = 'queued' | 'running' | 'completed' | 'failed' | 'cancelled';
|
|
218
|
+
type BackendJobKind = 'cache.refresh';
|
|
219
|
+
type BackendJobListStatusFilter = BackendJobStatus | 'active' | 'terminal';
|
|
220
|
+
interface BackendJobProgress {
|
|
221
|
+
completed: number;
|
|
222
|
+
total?: number;
|
|
223
|
+
message?: string;
|
|
224
|
+
}
|
|
225
|
+
interface BackendJobSnapshot {
|
|
226
|
+
jobId: string;
|
|
227
|
+
kind: BackendJobKind;
|
|
228
|
+
status: BackendJobStatus;
|
|
229
|
+
createdAt: string;
|
|
230
|
+
startedAt?: string;
|
|
231
|
+
finishedAt?: string;
|
|
232
|
+
sessionId?: string;
|
|
233
|
+
canonicalPathKey?: string;
|
|
234
|
+
revision?: number;
|
|
235
|
+
cacheRevision?: number;
|
|
236
|
+
diagnostics: BackendDiagnostic[];
|
|
237
|
+
progress?: BackendJobProgress;
|
|
238
|
+
result?: unknown;
|
|
239
|
+
error?: BackendError;
|
|
240
|
+
}
|
|
241
|
+
interface BackendJobListSnapshot {
|
|
242
|
+
jobs: BackendJobSnapshot[];
|
|
243
|
+
}
|
|
244
|
+
interface GetJobInput {
|
|
245
|
+
sessionId: string;
|
|
246
|
+
jobId: string;
|
|
247
|
+
}
|
|
248
|
+
interface ListJobsInput {
|
|
249
|
+
sessionId: string;
|
|
250
|
+
status?: BackendJobListStatusFilter;
|
|
251
|
+
kind?: BackendJobKind;
|
|
252
|
+
limit?: number;
|
|
253
|
+
}
|
|
254
|
+
interface CancelJobInput {
|
|
255
|
+
sessionId: string;
|
|
256
|
+
jobId: string;
|
|
257
|
+
}
|
|
258
|
+
interface BackendJobNotFoundError {
|
|
259
|
+
code: 'job_not_found';
|
|
260
|
+
message: string;
|
|
261
|
+
sessionId: string;
|
|
262
|
+
jobId: string;
|
|
263
|
+
}
|
|
264
|
+
interface BackendJobNotCancellableError {
|
|
265
|
+
code: 'job_not_cancellable';
|
|
266
|
+
message: string;
|
|
267
|
+
sessionId: string;
|
|
268
|
+
jobId: string;
|
|
269
|
+
status: 'completed' | 'failed' | 'cancelled';
|
|
270
|
+
}
|
|
271
|
+
interface BackendJobCancelledError {
|
|
272
|
+
code: 'job_cancelled';
|
|
273
|
+
message: string;
|
|
274
|
+
sessionId: string;
|
|
275
|
+
jobId: string;
|
|
276
|
+
}
|
|
277
|
+
interface CacheRefreshFailedError {
|
|
278
|
+
code: 'cache_refresh_failed';
|
|
279
|
+
message: string;
|
|
280
|
+
sessionId: string;
|
|
281
|
+
jobId: string;
|
|
282
|
+
causeCode?: string;
|
|
283
|
+
}
|
|
284
|
+
type BackendJobErrors = BackendJobNotFoundError | BackendJobNotCancellableError | BackendJobCancelledError | CacheRefreshFailedError;
|
|
285
|
+
interface BackendCacheSnapshot {
|
|
286
|
+
cacheRevision: number;
|
|
287
|
+
entries: BackendCacheEntry[];
|
|
288
|
+
}
|
|
289
|
+
interface BackendCacheEntry {
|
|
290
|
+
canonicalPathKey: string;
|
|
291
|
+
sessionId?: string;
|
|
292
|
+
revision: number;
|
|
293
|
+
lastSavedRevision: number;
|
|
294
|
+
dirty: boolean;
|
|
295
|
+
valid: boolean;
|
|
296
|
+
indexedAt: string;
|
|
297
|
+
summary: {
|
|
298
|
+
resourceCount: number;
|
|
299
|
+
packageCount?: number;
|
|
300
|
+
diagnostics: BackendDiagnostic[];
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
interface GetCacheSnapshotInput {
|
|
304
|
+
sessionId: string;
|
|
305
|
+
}
|
|
306
|
+
interface RefreshCacheInput {
|
|
307
|
+
sessionId: string;
|
|
308
|
+
reason?: 'manual' | 'session_open' | 'after_save';
|
|
309
|
+
}
|
|
310
|
+
type BackendError = SessionNotFoundError | SessionStaleWriteError | InProcessLockConflictError | AdvisoryLockConflictError | SavePartialFailureError | PathPolicyViolationError | EventCursorInvalidError | BackendJobNotFoundError | BackendJobNotCancellableError | BackendJobCancelledError | CacheRefreshFailedError | ApplyUamTransactionAppError;
|
|
311
|
+
interface ApplySessionTransactionInput {
|
|
312
|
+
sessionId: string;
|
|
313
|
+
expectedRevision: number;
|
|
314
|
+
operations: UamTransactionOperation[];
|
|
315
|
+
}
|
|
316
|
+
interface BackendRuntimeOptions {
|
|
317
|
+
fileSystem?: BackendFileSystem;
|
|
318
|
+
}
|
|
319
|
+
declare function createNodeBackendFileSystem(): BackendFileSystem;
|
|
320
|
+
declare class BackendRuntime {
|
|
321
|
+
private readonly fileSystem;
|
|
322
|
+
private readonly capabilities;
|
|
323
|
+
private readonly sessions;
|
|
324
|
+
private readonly sessionsByPath;
|
|
325
|
+
private readonly eventsBySession;
|
|
326
|
+
private readonly jobsBySession;
|
|
327
|
+
private readonly cacheBySession;
|
|
328
|
+
private eventSequence;
|
|
329
|
+
private readonly context;
|
|
330
|
+
private readonly readService;
|
|
331
|
+
private readonly runtimeService;
|
|
332
|
+
private readonly authoringService;
|
|
333
|
+
private readonly cacheService;
|
|
334
|
+
private readonly eventService;
|
|
335
|
+
private readonly jobService;
|
|
336
|
+
constructor(options?: BackendRuntimeOptions);
|
|
337
|
+
getCapabilities(): BackendSuccess<BackendCapabilities>;
|
|
338
|
+
openSession(input: {
|
|
339
|
+
projectPath: string;
|
|
340
|
+
}): Promise<BackendResult<BackendSessionSnapshot, InProcessLockConflictError | AdvisoryLockConflictError>>;
|
|
341
|
+
getSession(input: {
|
|
342
|
+
sessionId: string;
|
|
343
|
+
}): BackendResult<BackendSessionSnapshot, SessionNotFoundError>;
|
|
344
|
+
applyTransaction(input: ApplySessionTransactionInput): Promise<BackendResult<BackendSessionSnapshot, SessionNotFoundError | SessionStaleWriteError | ApplyUamTransactionAppError>>;
|
|
345
|
+
saveSession(input: {
|
|
346
|
+
sessionId: string;
|
|
347
|
+
expectedRevision?: number;
|
|
348
|
+
targetPath?: string;
|
|
349
|
+
}): Promise<BackendResult<BackendSessionSnapshot, SessionNotFoundError | SessionStaleWriteError | SavePartialFailureError | PathPolicyViolationError>>;
|
|
350
|
+
closeSession(input: {
|
|
351
|
+
sessionId: string;
|
|
352
|
+
}): Promise<BackendResult<{
|
|
353
|
+
sessionId: string;
|
|
354
|
+
closed: true;
|
|
355
|
+
}, SessionNotFoundError>>;
|
|
356
|
+
getEvents(input: GetEventsInput): BackendResult<GetEventsSnapshot, SessionNotFoundError | EventCursorInvalidError>;
|
|
357
|
+
getJob(input: GetJobInput): BackendResult<BackendJobSnapshot, SessionNotFoundError | BackendJobNotFoundError>;
|
|
358
|
+
listJobs(input: ListJobsInput): BackendResult<BackendJobListSnapshot, SessionNotFoundError>;
|
|
359
|
+
cancelJob(input: CancelJobInput): BackendResult<BackendJobSnapshot, SessionNotFoundError | BackendJobNotFoundError | BackendJobNotCancellableError>;
|
|
360
|
+
getCacheSnapshot(input: GetCacheSnapshotInput): BackendResult<BackendCacheSnapshot, SessionNotFoundError>;
|
|
361
|
+
refreshCache(input: RefreshCacheInput): BackendResult<BackendJobSnapshot, SessionNotFoundError>;
|
|
362
|
+
}
|
|
363
|
+
//#endregion
|
|
364
|
+
export { type AdvisoryLockConflictError, type ApplySessionTransactionInput, BACKEND_CAPABILITY_SCHEMA_VERSION, BACKEND_COMPATIBILITY_POLICY, BACKEND_CONTRACT_VERSION, type BackendCacheEntry, type BackendCacheSnapshot, type BackendCapabilities, type BackendDiagnostic, type BackendError, type BackendEvent, type BackendEventKind, type BackendFailure, type BackendFileHandle, type BackendFileSystem, type BackendJobErrors, type BackendJobKind, type BackendJobListSnapshot, type BackendJobListStatusFilter, type BackendJobNotCancellableError, type BackendJobNotFoundError, type BackendJobProgress, type BackendJobSnapshot, type BackendJobStatus, type BackendMessage, type BackendResponseMeta, type BackendResult, BackendRuntime, type BackendRuntimeOptions, type BackendSessionSnapshot, type BackendStage, type BackendSuccess, type CacheRefreshFailedError, type CancelJobInput, type EventCursorInvalidError, type GetCacheSnapshotInput, type GetEventsInput, type GetEventsSnapshot, type GetJobInput, type InProcessLockConflictError, type ListJobsInput, type RefreshCacheInput, type SavePartialFailureError, type SessionNotFoundError, type SessionStaleWriteError, createNodeBackendFileSystem };
|