@openfairygui/backend 0.4.0 → 0.5.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 +1 -0
- package/dist/docs.cjs +4776 -845
- package/dist/docs.d.cts +14 -1
- package/dist/docs.d.mts +14 -1
- package/dist/docs.mjs +4776 -845
- package/dist/index.cjs +137 -10
- package/dist/index.d.cts +100 -5
- package/dist/index.d.mts +100 -5
- package/dist/index.mjs +137 -11
- package/dist/node.cjs +135 -9
- package/dist/node.d.cts +67 -4
- package/dist/node.d.mts +67 -4
- package/dist/node.mjs +135 -9
- package/docs/workflow.md +10 -0
- package/package.json +3 -3
- package/src/contracts.ts +1 -1
- package/src/diagnostics.ts +8 -0
- package/src/generated/contracts.ts +8588 -1733
- package/src/generated/docs.ts +3 -3
- package/src/index.ts +10 -0
- package/src/runtime/capabilities.ts +5 -1
- package/src/runtime/contracts.ts +54 -0
- package/src/runtime.ts +14 -0
- package/src/services/read-service.ts +80 -8
package/dist/index.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import { ProjectReader, ProjectWriter } from "@openfairygui/core/project-io";
|
|
|
4
4
|
import { validateProject } from "@openfairygui/functions";
|
|
5
5
|
//#region src/contracts.ts
|
|
6
6
|
const BACKEND_CONTRACT_VERSION = "2.0.0-p2";
|
|
7
|
-
const BACKEND_CAPABILITY_SCHEMA_VERSION =
|
|
7
|
+
const BACKEND_CAPABILITY_SCHEMA_VERSION = 11;
|
|
8
8
|
const BACKEND_COMPATIBILITY_POLICY = {
|
|
9
9
|
incompatibleChange: "requires contractVersion bump",
|
|
10
10
|
capabilitySchemaChange: "requires capabilitySchemaVersion bump",
|
|
@@ -66,6 +66,22 @@ const job = {
|
|
|
66
66
|
};
|
|
67
67
|
/** Exhaustiveness and exact ownership are checked against the canonical unions. */
|
|
68
68
|
const BACKEND_DIAGNOSTIC_GUIDES = [
|
|
69
|
+
{
|
|
70
|
+
code: "stale_read",
|
|
71
|
+
owners: ["backend"],
|
|
72
|
+
remediation: {
|
|
73
|
+
kind: "refresh-and-replan",
|
|
74
|
+
message: "Discard the incomplete model/bytes read and restart with readSessionState. Use its revision for every readResourceBytes call. No historical state is retained or reserved; do not combine resources from different edit revisions."
|
|
75
|
+
}
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
code: "session_read_failed",
|
|
79
|
+
owners: ["backend"],
|
|
80
|
+
remediation: {
|
|
81
|
+
kind: "host-action",
|
|
82
|
+
message: "Inspect error.reason: invalid_query requires valid inputs; not_found/ambiguous requires exact current resource identifiers; unsupported_resource/bytes_unavailable means primary bytes cannot be read from this session. Budget or non-JSON failures require host inspection. Preserve unsaved work; do not save, reopen, repair or mutate the model merely to obtain a read."
|
|
83
|
+
}
|
|
84
|
+
},
|
|
69
85
|
{
|
|
70
86
|
code: "transaction_preview_failed",
|
|
71
87
|
owners: ["backend"],
|
|
@@ -727,7 +743,7 @@ function createMeta(stage, startedAt, options) {
|
|
|
727
743
|
diagnostics: (options?.diagnostics ?? []).map((entry) => enrichBackendDiagnostic(entry, options?.sessionId)),
|
|
728
744
|
stage,
|
|
729
745
|
contractVersion: BACKEND_CONTRACT_VERSION,
|
|
730
|
-
capabilitySchemaVersion:
|
|
746
|
+
capabilitySchemaVersion: 11
|
|
731
747
|
};
|
|
732
748
|
}
|
|
733
749
|
function success(stage, startedAt, data, options) {
|
|
@@ -849,6 +865,14 @@ const BACKEND_ENTITY_QUERY_LIMITS = {
|
|
|
849
865
|
maxDepth: 32,
|
|
850
866
|
maxNodes: 1e5
|
|
851
867
|
};
|
|
868
|
+
const BACKEND_SESSION_READ_LIMITS = {
|
|
869
|
+
model: {
|
|
870
|
+
maxBytes: 4194304,
|
|
871
|
+
maxDepth: 64,
|
|
872
|
+
maxNodes: 5e5
|
|
873
|
+
},
|
|
874
|
+
resourceBytes: 1048576
|
|
875
|
+
};
|
|
852
876
|
const BACKEND_TRANSACTION_PREVIEW_LIMITS = {
|
|
853
877
|
maxBytes: 262144,
|
|
854
878
|
maxEntries: 2e3
|
|
@@ -1995,7 +2019,7 @@ var JobService = class {
|
|
|
1995
2019
|
//#endregion
|
|
1996
2020
|
//#region src/services/read-service.ts
|
|
1997
2021
|
/** Bound traversal before serialization or cloning, including non-JSON values on a malformed native input. */
|
|
1998
|
-
function queryResponseProblem(value) {
|
|
2022
|
+
function queryResponseProblem(value, limits = BACKEND_ENTITY_QUERY_LIMITS) {
|
|
1999
2023
|
const pending = [{
|
|
2000
2024
|
value,
|
|
2001
2025
|
depth: 0
|
|
@@ -2004,26 +2028,37 @@ function queryResponseProblem(value) {
|
|
|
2004
2028
|
let stringUnits = 0;
|
|
2005
2029
|
while (pending.length) {
|
|
2006
2030
|
const { value, depth } = pending.pop();
|
|
2007
|
-
if (++nodes >
|
|
2008
|
-
if (typeof value === "string" && (stringUnits += value.length) >
|
|
2031
|
+
if (++nodes > limits.maxNodes || depth > limits.maxDepth) return "response_budget_exceeded";
|
|
2032
|
+
if (typeof value === "string" && (stringUnits += value.length) > limits.maxBytes) return "response_budget_exceeded";
|
|
2009
2033
|
if (value === void 0 || value === null || typeof value === "string" || typeof value === "boolean") continue;
|
|
2010
2034
|
if (typeof value === "number") {
|
|
2011
2035
|
if (!Number.isFinite(value)) return "non_json_value";
|
|
2012
2036
|
continue;
|
|
2013
2037
|
}
|
|
2014
2038
|
if (typeof value !== "object" || !Array.isArray(value) && Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) return "non_json_value";
|
|
2015
|
-
if (Array.isArray(value) && value.length + pending.length + nodes >
|
|
2039
|
+
if (Array.isArray(value) && value.length + pending.length + nodes > limits.maxNodes) return "response_budget_exceeded";
|
|
2016
2040
|
const entries = Object.entries(value);
|
|
2017
|
-
if (entries.length + pending.length + nodes >
|
|
2041
|
+
if (entries.length + pending.length + nodes > limits.maxNodes) return "response_budget_exceeded";
|
|
2018
2042
|
for (const [key, child] of entries) {
|
|
2019
|
-
if (!Array.isArray(value) && (stringUnits += key.length) >
|
|
2043
|
+
if (!Array.isArray(value) && (stringUnits += key.length) > limits.maxBytes) return "response_budget_exceeded";
|
|
2020
2044
|
pending.push({
|
|
2021
2045
|
value: child,
|
|
2022
2046
|
depth: depth + 1
|
|
2023
2047
|
});
|
|
2024
2048
|
}
|
|
2025
2049
|
}
|
|
2026
|
-
if (new TextEncoder().encode(JSON.stringify(value)).byteLength >
|
|
2050
|
+
if (new TextEncoder().encode(JSON.stringify(value)).byteLength > limits.maxBytes) return "response_budget_exceeded";
|
|
2051
|
+
}
|
|
2052
|
+
function readFailure(startedAt, sessionId, reason, revision) {
|
|
2053
|
+
return failure("read", startedAt, {
|
|
2054
|
+
code: "session_read_failed",
|
|
2055
|
+
sessionId,
|
|
2056
|
+
reason,
|
|
2057
|
+
message: `Session read failed: ${reason}.`
|
|
2058
|
+
}, void 0, {
|
|
2059
|
+
sessionId,
|
|
2060
|
+
revision
|
|
2061
|
+
});
|
|
2027
2062
|
}
|
|
2028
2063
|
function toProjectOutline(session) {
|
|
2029
2064
|
const project = session.project;
|
|
@@ -2207,6 +2242,80 @@ var ReadService = class {
|
|
|
2207
2242
|
}
|
|
2208
2243
|
return respond(entity);
|
|
2209
2244
|
}
|
|
2245
|
+
resolveReadSession(input, startedAt) {
|
|
2246
|
+
if (!input || typeof input.sessionId !== "string" || !input.sessionId.length || input.sessionId.length > 256 || input.expectedRevision !== void 0 && (!Number.isSafeInteger(input.expectedRevision) || input.expectedRevision < 0)) return readFailure(startedAt, typeof input?.sessionId === "string" ? input.sessionId : "", "invalid_query");
|
|
2247
|
+
const session = this.context.sessions.get(input.sessionId);
|
|
2248
|
+
if (!session || session.closed) return failure("read", startedAt, createSessionNotFoundError(input.sessionId));
|
|
2249
|
+
const meta = {
|
|
2250
|
+
sessionId: session.sessionId,
|
|
2251
|
+
revision: session.revision
|
|
2252
|
+
};
|
|
2253
|
+
if (input.expectedRevision !== void 0 && input.expectedRevision !== session.revision) return failure("read", startedAt, {
|
|
2254
|
+
code: "stale_read",
|
|
2255
|
+
sessionId: session.sessionId,
|
|
2256
|
+
expectedRevision: input.expectedRevision,
|
|
2257
|
+
actualRevision: session.revision,
|
|
2258
|
+
message: "The session edit revision changed. Restart the model and resource read."
|
|
2259
|
+
}, void 0, meta);
|
|
2260
|
+
return success("read", startedAt, session, meta);
|
|
2261
|
+
}
|
|
2262
|
+
readSessionState(input) {
|
|
2263
|
+
const startedAt = Date.now();
|
|
2264
|
+
const resolved = this.resolveReadSession(input, startedAt);
|
|
2265
|
+
if (!resolved.ok) return resolved;
|
|
2266
|
+
const session = resolved.data;
|
|
2267
|
+
const meta = {
|
|
2268
|
+
sessionId: session.sessionId,
|
|
2269
|
+
revision: session.revision
|
|
2270
|
+
};
|
|
2271
|
+
const data = {
|
|
2272
|
+
...meta,
|
|
2273
|
+
dirty: session.dirty,
|
|
2274
|
+
lastSavedRevision: session.lastSavedRevision,
|
|
2275
|
+
uamFidelity: session.uamFidelity,
|
|
2276
|
+
readComplete: session.readComplete,
|
|
2277
|
+
readDiagnostics: session.readDiagnostics,
|
|
2278
|
+
project: {
|
|
2279
|
+
...session.project,
|
|
2280
|
+
packages: session.project.packages.map((pkg) => ({
|
|
2281
|
+
...pkg,
|
|
2282
|
+
resources: pkg.resources.map((resource) => {
|
|
2283
|
+
if (resource.kind === "component") return resource;
|
|
2284
|
+
const { sourceBytes: _sourceBytes, ...model } = resource;
|
|
2285
|
+
return model;
|
|
2286
|
+
})
|
|
2287
|
+
}))
|
|
2288
|
+
}
|
|
2289
|
+
};
|
|
2290
|
+
const problem = queryResponseProblem(data, BACKEND_SESSION_READ_LIMITS.model);
|
|
2291
|
+
return problem ? readFailure(startedAt, session.sessionId, problem, session.revision) : success("read", startedAt, structuredClone(data), meta);
|
|
2292
|
+
}
|
|
2293
|
+
readResourceBytes(input) {
|
|
2294
|
+
const startedAt = Date.now();
|
|
2295
|
+
const resolved = this.resolveReadSession(input, startedAt);
|
|
2296
|
+
if (!resolved.ok) return resolved;
|
|
2297
|
+
const session = resolved.data;
|
|
2298
|
+
const reject = (reason) => readFailure(startedAt, session.sessionId, reason, session.revision);
|
|
2299
|
+
const selector = input.selector;
|
|
2300
|
+
if (input.expectedRevision === void 0 || !selector || typeof selector !== "object" || Array.isArray(selector) || Object.keys(selector).length !== 2 || ["packageId", "resourceId"].some((key) => !Object.hasOwn(selector, key)) || [selector.packageId, selector.resourceId].some((value) => typeof value !== "string" || !value.length || value.length > 256)) return reject("invalid_query");
|
|
2301
|
+
const packages = session.project.packages.filter((pkg) => pkg.id === selector.packageId);
|
|
2302
|
+
if (packages.length !== 1) return reject(packages.length ? "ambiguous" : "not_found");
|
|
2303
|
+
const resources = packages[0].resources.filter((resource) => resource.id === selector.resourceId);
|
|
2304
|
+
if (resources.length !== 1) return reject(resources.length ? "ambiguous" : "not_found");
|
|
2305
|
+
const resource = resources[0];
|
|
2306
|
+
if (resource.kind === "component") return reject("unsupported_resource");
|
|
2307
|
+
if (!(resource.sourceBytes instanceof Uint8Array)) return reject("bytes_unavailable");
|
|
2308
|
+
if (resource.sourceBytes.byteLength > BACKEND_SESSION_READ_LIMITS.resourceBytes) return reject("response_budget_exceeded");
|
|
2309
|
+
const meta = {
|
|
2310
|
+
sessionId: session.sessionId,
|
|
2311
|
+
revision: session.revision
|
|
2312
|
+
};
|
|
2313
|
+
return success("read", startedAt, {
|
|
2314
|
+
...meta,
|
|
2315
|
+
selector: { ...selector },
|
|
2316
|
+
sourceBytes: new Uint8Array(resource.sourceBytes)
|
|
2317
|
+
}, meta);
|
|
2318
|
+
}
|
|
2210
2319
|
validateSession(input) {
|
|
2211
2320
|
const startedAt = Date.now();
|
|
2212
2321
|
const session = this.context.sessions.get(input.sessionId);
|
|
@@ -2517,6 +2626,8 @@ const BACKEND_METHODS = [
|
|
|
2517
2626
|
"getSession",
|
|
2518
2627
|
"getProjectOutline",
|
|
2519
2628
|
"queryEntity",
|
|
2629
|
+
"readSessionState",
|
|
2630
|
+
"readResourceBytes",
|
|
2520
2631
|
"validateSession",
|
|
2521
2632
|
"preflightTransaction",
|
|
2522
2633
|
"applyTransaction",
|
|
@@ -2540,7 +2651,7 @@ const ARTIFACT_BRIDGE_CAPABILITY = {
|
|
|
2540
2651
|
function createCapabilities(atomicSave = false) {
|
|
2541
2652
|
return {
|
|
2542
2653
|
contractVersion: BACKEND_CONTRACT_VERSION,
|
|
2543
|
-
capabilitySchemaVersion:
|
|
2654
|
+
capabilitySchemaVersion: 11,
|
|
2544
2655
|
transactionKernelOwner: "@openfairygui/core",
|
|
2545
2656
|
appSeamOwner: "@openfairygui/functions",
|
|
2546
2657
|
runtimeOwner: "@openfairygui/backend",
|
|
@@ -2563,6 +2674,15 @@ function createCapabilities(atomicSave = false) {
|
|
|
2563
2674
|
sourceBytes: false,
|
|
2564
2675
|
limits: BACKEND_ENTITY_QUERY_LIMITS
|
|
2565
2676
|
},
|
|
2677
|
+
sessionState: {
|
|
2678
|
+
sourceBytes: false,
|
|
2679
|
+
limits: BACKEND_SESSION_READ_LIMITS.model
|
|
2680
|
+
},
|
|
2681
|
+
resourceBytes: {
|
|
2682
|
+
expectedRevisionRequired: true,
|
|
2683
|
+
hydration: false,
|
|
2684
|
+
maxBytes: BACKEND_SESSION_READ_LIMITS.resourceBytes
|
|
2685
|
+
},
|
|
2566
2686
|
projectValidation: true
|
|
2567
2687
|
},
|
|
2568
2688
|
authoring: {
|
|
@@ -2727,6 +2847,12 @@ var BackendRuntime = class {
|
|
|
2727
2847
|
queryEntity(input) {
|
|
2728
2848
|
return this.readService.queryEntity(input);
|
|
2729
2849
|
}
|
|
2850
|
+
readSessionState(input) {
|
|
2851
|
+
return this.readService.readSessionState(input);
|
|
2852
|
+
}
|
|
2853
|
+
readResourceBytes(input) {
|
|
2854
|
+
return this.readService.readResourceBytes(input);
|
|
2855
|
+
}
|
|
2730
2856
|
validateSession(input) {
|
|
2731
2857
|
return this.readService.validateSession(input);
|
|
2732
2858
|
}
|
|
@@ -2935,4 +3061,4 @@ function createBackendStorageFileSystem(storage) {
|
|
|
2935
3061
|
return fileSystem;
|
|
2936
3062
|
}
|
|
2937
3063
|
//#endregion
|
|
2938
|
-
export { BACKEND_CAPABILITY_SCHEMA_VERSION, BACKEND_COMPATIBILITY_POLICY, BACKEND_CONTRACT_VERSION, BACKEND_DIAGNOSTICS_URI, BACKEND_DIAGNOSTIC_TEMPLATE, BACKEND_ENTITY_QUERY_LIMITS, BACKEND_TRANSACTION_PREVIEW_LIMITS, BackendRuntime, createBackendStorageFileSystem, getBackendDiagnosticCatalog, getBackendDiagnosticGuide };
|
|
3064
|
+
export { BACKEND_CAPABILITY_SCHEMA_VERSION, BACKEND_COMPATIBILITY_POLICY, BACKEND_CONTRACT_VERSION, BACKEND_DIAGNOSTICS_URI, BACKEND_DIAGNOSTIC_TEMPLATE, BACKEND_ENTITY_QUERY_LIMITS, BACKEND_SESSION_READ_LIMITS, BACKEND_TRANSACTION_PREVIEW_LIMITS, BackendRuntime, createBackendStorageFileSystem, getBackendDiagnosticCatalog, getBackendDiagnosticGuide };
|
package/dist/node.cjs
CHANGED
|
@@ -170,6 +170,22 @@ const job = {
|
|
|
170
170
|
};
|
|
171
171
|
/** Exhaustiveness and exact ownership are checked against the canonical unions. */
|
|
172
172
|
const BACKEND_DIAGNOSTIC_GUIDES = [
|
|
173
|
+
{
|
|
174
|
+
code: "stale_read",
|
|
175
|
+
owners: ["backend"],
|
|
176
|
+
remediation: {
|
|
177
|
+
kind: "refresh-and-replan",
|
|
178
|
+
message: "Discard the incomplete model/bytes read and restart with readSessionState. Use its revision for every readResourceBytes call. No historical state is retained or reserved; do not combine resources from different edit revisions."
|
|
179
|
+
}
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
code: "session_read_failed",
|
|
183
|
+
owners: ["backend"],
|
|
184
|
+
remediation: {
|
|
185
|
+
kind: "host-action",
|
|
186
|
+
message: "Inspect error.reason: invalid_query requires valid inputs; not_found/ambiguous requires exact current resource identifiers; unsupported_resource/bytes_unavailable means primary bytes cannot be read from this session. Budget or non-JSON failures require host inspection. Preserve unsaved work; do not save, reopen, repair or mutate the model merely to obtain a read."
|
|
187
|
+
}
|
|
188
|
+
},
|
|
173
189
|
{
|
|
174
190
|
code: "transaction_preview_failed",
|
|
175
191
|
owners: ["backend"],
|
|
@@ -745,7 +761,7 @@ function createMeta(stage, startedAt, options) {
|
|
|
745
761
|
diagnostics: (options?.diagnostics ?? []).map((entry) => enrichBackendDiagnostic(entry, options?.sessionId)),
|
|
746
762
|
stage,
|
|
747
763
|
contractVersion: BACKEND_CONTRACT_VERSION,
|
|
748
|
-
capabilitySchemaVersion:
|
|
764
|
+
capabilitySchemaVersion: 11
|
|
749
765
|
};
|
|
750
766
|
}
|
|
751
767
|
function success(stage, startedAt, data, options) {
|
|
@@ -867,6 +883,14 @@ const BACKEND_ENTITY_QUERY_LIMITS = {
|
|
|
867
883
|
maxDepth: 32,
|
|
868
884
|
maxNodes: 1e5
|
|
869
885
|
};
|
|
886
|
+
const BACKEND_SESSION_READ_LIMITS = {
|
|
887
|
+
model: {
|
|
888
|
+
maxBytes: 4194304,
|
|
889
|
+
maxDepth: 64,
|
|
890
|
+
maxNodes: 5e5
|
|
891
|
+
},
|
|
892
|
+
resourceBytes: 1048576
|
|
893
|
+
};
|
|
870
894
|
const BACKEND_TRANSACTION_PREVIEW_LIMITS = {
|
|
871
895
|
maxBytes: 262144,
|
|
872
896
|
maxEntries: 2e3
|
|
@@ -2013,7 +2037,7 @@ var JobService = class {
|
|
|
2013
2037
|
//#endregion
|
|
2014
2038
|
//#region src/services/read-service.ts
|
|
2015
2039
|
/** Bound traversal before serialization or cloning, including non-JSON values on a malformed native input. */
|
|
2016
|
-
function queryResponseProblem(value) {
|
|
2040
|
+
function queryResponseProblem(value, limits = BACKEND_ENTITY_QUERY_LIMITS) {
|
|
2017
2041
|
const pending = [{
|
|
2018
2042
|
value,
|
|
2019
2043
|
depth: 0
|
|
@@ -2022,26 +2046,37 @@ function queryResponseProblem(value) {
|
|
|
2022
2046
|
let stringUnits = 0;
|
|
2023
2047
|
while (pending.length) {
|
|
2024
2048
|
const { value, depth } = pending.pop();
|
|
2025
|
-
if (++nodes >
|
|
2026
|
-
if (typeof value === "string" && (stringUnits += value.length) >
|
|
2049
|
+
if (++nodes > limits.maxNodes || depth > limits.maxDepth) return "response_budget_exceeded";
|
|
2050
|
+
if (typeof value === "string" && (stringUnits += value.length) > limits.maxBytes) return "response_budget_exceeded";
|
|
2027
2051
|
if (value === void 0 || value === null || typeof value === "string" || typeof value === "boolean") continue;
|
|
2028
2052
|
if (typeof value === "number") {
|
|
2029
2053
|
if (!Number.isFinite(value)) return "non_json_value";
|
|
2030
2054
|
continue;
|
|
2031
2055
|
}
|
|
2032
2056
|
if (typeof value !== "object" || !Array.isArray(value) && Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null) return "non_json_value";
|
|
2033
|
-
if (Array.isArray(value) && value.length + pending.length + nodes >
|
|
2057
|
+
if (Array.isArray(value) && value.length + pending.length + nodes > limits.maxNodes) return "response_budget_exceeded";
|
|
2034
2058
|
const entries = Object.entries(value);
|
|
2035
|
-
if (entries.length + pending.length + nodes >
|
|
2059
|
+
if (entries.length + pending.length + nodes > limits.maxNodes) return "response_budget_exceeded";
|
|
2036
2060
|
for (const [key, child] of entries) {
|
|
2037
|
-
if (!Array.isArray(value) && (stringUnits += key.length) >
|
|
2061
|
+
if (!Array.isArray(value) && (stringUnits += key.length) > limits.maxBytes) return "response_budget_exceeded";
|
|
2038
2062
|
pending.push({
|
|
2039
2063
|
value: child,
|
|
2040
2064
|
depth: depth + 1
|
|
2041
2065
|
});
|
|
2042
2066
|
}
|
|
2043
2067
|
}
|
|
2044
|
-
if (new TextEncoder().encode(JSON.stringify(value)).byteLength >
|
|
2068
|
+
if (new TextEncoder().encode(JSON.stringify(value)).byteLength > limits.maxBytes) return "response_budget_exceeded";
|
|
2069
|
+
}
|
|
2070
|
+
function readFailure(startedAt, sessionId, reason, revision) {
|
|
2071
|
+
return failure("read", startedAt, {
|
|
2072
|
+
code: "session_read_failed",
|
|
2073
|
+
sessionId,
|
|
2074
|
+
reason,
|
|
2075
|
+
message: `Session read failed: ${reason}.`
|
|
2076
|
+
}, void 0, {
|
|
2077
|
+
sessionId,
|
|
2078
|
+
revision
|
|
2079
|
+
});
|
|
2045
2080
|
}
|
|
2046
2081
|
function toProjectOutline(session) {
|
|
2047
2082
|
const project = session.project;
|
|
@@ -2225,6 +2260,80 @@ var ReadService = class {
|
|
|
2225
2260
|
}
|
|
2226
2261
|
return respond(entity);
|
|
2227
2262
|
}
|
|
2263
|
+
resolveReadSession(input, startedAt) {
|
|
2264
|
+
if (!input || typeof input.sessionId !== "string" || !input.sessionId.length || input.sessionId.length > 256 || input.expectedRevision !== void 0 && (!Number.isSafeInteger(input.expectedRevision) || input.expectedRevision < 0)) return readFailure(startedAt, typeof input?.sessionId === "string" ? input.sessionId : "", "invalid_query");
|
|
2265
|
+
const session = this.context.sessions.get(input.sessionId);
|
|
2266
|
+
if (!session || session.closed) return failure("read", startedAt, createSessionNotFoundError(input.sessionId));
|
|
2267
|
+
const meta = {
|
|
2268
|
+
sessionId: session.sessionId,
|
|
2269
|
+
revision: session.revision
|
|
2270
|
+
};
|
|
2271
|
+
if (input.expectedRevision !== void 0 && input.expectedRevision !== session.revision) return failure("read", startedAt, {
|
|
2272
|
+
code: "stale_read",
|
|
2273
|
+
sessionId: session.sessionId,
|
|
2274
|
+
expectedRevision: input.expectedRevision,
|
|
2275
|
+
actualRevision: session.revision,
|
|
2276
|
+
message: "The session edit revision changed. Restart the model and resource read."
|
|
2277
|
+
}, void 0, meta);
|
|
2278
|
+
return success("read", startedAt, session, meta);
|
|
2279
|
+
}
|
|
2280
|
+
readSessionState(input) {
|
|
2281
|
+
const startedAt = Date.now();
|
|
2282
|
+
const resolved = this.resolveReadSession(input, startedAt);
|
|
2283
|
+
if (!resolved.ok) return resolved;
|
|
2284
|
+
const session = resolved.data;
|
|
2285
|
+
const meta = {
|
|
2286
|
+
sessionId: session.sessionId,
|
|
2287
|
+
revision: session.revision
|
|
2288
|
+
};
|
|
2289
|
+
const data = {
|
|
2290
|
+
...meta,
|
|
2291
|
+
dirty: session.dirty,
|
|
2292
|
+
lastSavedRevision: session.lastSavedRevision,
|
|
2293
|
+
uamFidelity: session.uamFidelity,
|
|
2294
|
+
readComplete: session.readComplete,
|
|
2295
|
+
readDiagnostics: session.readDiagnostics,
|
|
2296
|
+
project: {
|
|
2297
|
+
...session.project,
|
|
2298
|
+
packages: session.project.packages.map((pkg) => ({
|
|
2299
|
+
...pkg,
|
|
2300
|
+
resources: pkg.resources.map((resource) => {
|
|
2301
|
+
if (resource.kind === "component") return resource;
|
|
2302
|
+
const { sourceBytes: _sourceBytes, ...model } = resource;
|
|
2303
|
+
return model;
|
|
2304
|
+
})
|
|
2305
|
+
}))
|
|
2306
|
+
}
|
|
2307
|
+
};
|
|
2308
|
+
const problem = queryResponseProblem(data, BACKEND_SESSION_READ_LIMITS.model);
|
|
2309
|
+
return problem ? readFailure(startedAt, session.sessionId, problem, session.revision) : success("read", startedAt, structuredClone(data), meta);
|
|
2310
|
+
}
|
|
2311
|
+
readResourceBytes(input) {
|
|
2312
|
+
const startedAt = Date.now();
|
|
2313
|
+
const resolved = this.resolveReadSession(input, startedAt);
|
|
2314
|
+
if (!resolved.ok) return resolved;
|
|
2315
|
+
const session = resolved.data;
|
|
2316
|
+
const reject = (reason) => readFailure(startedAt, session.sessionId, reason, session.revision);
|
|
2317
|
+
const selector = input.selector;
|
|
2318
|
+
if (input.expectedRevision === void 0 || !selector || typeof selector !== "object" || Array.isArray(selector) || Object.keys(selector).length !== 2 || ["packageId", "resourceId"].some((key) => !Object.hasOwn(selector, key)) || [selector.packageId, selector.resourceId].some((value) => typeof value !== "string" || !value.length || value.length > 256)) return reject("invalid_query");
|
|
2319
|
+
const packages = session.project.packages.filter((pkg) => pkg.id === selector.packageId);
|
|
2320
|
+
if (packages.length !== 1) return reject(packages.length ? "ambiguous" : "not_found");
|
|
2321
|
+
const resources = packages[0].resources.filter((resource) => resource.id === selector.resourceId);
|
|
2322
|
+
if (resources.length !== 1) return reject(resources.length ? "ambiguous" : "not_found");
|
|
2323
|
+
const resource = resources[0];
|
|
2324
|
+
if (resource.kind === "component") return reject("unsupported_resource");
|
|
2325
|
+
if (!(resource.sourceBytes instanceof Uint8Array)) return reject("bytes_unavailable");
|
|
2326
|
+
if (resource.sourceBytes.byteLength > BACKEND_SESSION_READ_LIMITS.resourceBytes) return reject("response_budget_exceeded");
|
|
2327
|
+
const meta = {
|
|
2328
|
+
sessionId: session.sessionId,
|
|
2329
|
+
revision: session.revision
|
|
2330
|
+
};
|
|
2331
|
+
return success("read", startedAt, {
|
|
2332
|
+
...meta,
|
|
2333
|
+
selector: { ...selector },
|
|
2334
|
+
sourceBytes: new Uint8Array(resource.sourceBytes)
|
|
2335
|
+
}, meta);
|
|
2336
|
+
}
|
|
2228
2337
|
validateSession(input) {
|
|
2229
2338
|
const startedAt = Date.now();
|
|
2230
2339
|
const session = this.context.sessions.get(input.sessionId);
|
|
@@ -2535,6 +2644,8 @@ const BACKEND_METHODS = [
|
|
|
2535
2644
|
"getSession",
|
|
2536
2645
|
"getProjectOutline",
|
|
2537
2646
|
"queryEntity",
|
|
2647
|
+
"readSessionState",
|
|
2648
|
+
"readResourceBytes",
|
|
2538
2649
|
"validateSession",
|
|
2539
2650
|
"preflightTransaction",
|
|
2540
2651
|
"applyTransaction",
|
|
@@ -2558,7 +2669,7 @@ const ARTIFACT_BRIDGE_CAPABILITY = {
|
|
|
2558
2669
|
function createCapabilities(atomicSave = false) {
|
|
2559
2670
|
return {
|
|
2560
2671
|
contractVersion: BACKEND_CONTRACT_VERSION,
|
|
2561
|
-
capabilitySchemaVersion:
|
|
2672
|
+
capabilitySchemaVersion: 11,
|
|
2562
2673
|
transactionKernelOwner: "@openfairygui/core",
|
|
2563
2674
|
appSeamOwner: "@openfairygui/functions",
|
|
2564
2675
|
runtimeOwner: "@openfairygui/backend",
|
|
@@ -2581,6 +2692,15 @@ function createCapabilities(atomicSave = false) {
|
|
|
2581
2692
|
sourceBytes: false,
|
|
2582
2693
|
limits: BACKEND_ENTITY_QUERY_LIMITS
|
|
2583
2694
|
},
|
|
2695
|
+
sessionState: {
|
|
2696
|
+
sourceBytes: false,
|
|
2697
|
+
limits: BACKEND_SESSION_READ_LIMITS.model
|
|
2698
|
+
},
|
|
2699
|
+
resourceBytes: {
|
|
2700
|
+
expectedRevisionRequired: true,
|
|
2701
|
+
hydration: false,
|
|
2702
|
+
maxBytes: BACKEND_SESSION_READ_LIMITS.resourceBytes
|
|
2703
|
+
},
|
|
2584
2704
|
projectValidation: true
|
|
2585
2705
|
},
|
|
2586
2706
|
authoring: {
|
|
@@ -2745,6 +2865,12 @@ var BackendRuntime = class {
|
|
|
2745
2865
|
queryEntity(input) {
|
|
2746
2866
|
return this.readService.queryEntity(input);
|
|
2747
2867
|
}
|
|
2868
|
+
readSessionState(input) {
|
|
2869
|
+
return this.readService.readSessionState(input);
|
|
2870
|
+
}
|
|
2871
|
+
readResourceBytes(input) {
|
|
2872
|
+
return this.readService.readResourceBytes(input);
|
|
2873
|
+
}
|
|
2748
2874
|
validateSession(input) {
|
|
2749
2875
|
return this.readService.validateSession(input);
|
|
2750
2876
|
}
|
package/dist/node.d.cts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ApplyUamTransactionAppError } from "@openfairygui/functions/uam";
|
|
2
|
+
import * as _$_openfairygui_core0 from "@openfairygui/core";
|
|
2
3
|
import { ProjectDiagnosticCode, ProjectValidationReport } from "@openfairygui/core";
|
|
3
|
-
import { UamComponentModel, UamComponentResource, UamComponentSelector, UamControllerModel, UamControllerSelector, UamDisplayNode, UamDisplayNodeKind, UamDisplayNodeSelector, UamGenericAssetResource, UamImageResource, UamMovieClipResource, UamPackageSelector, UamPackageSettings, UamProject, UamResource, UamResourceSelector, UamTransactionOperation, UamTransactionSupportIssueCode, UamTransitionModel, UamTransitionSelector } from "@openfairygui/core/uam";
|
|
4
|
+
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
5
|
|
|
5
6
|
//#region src/path-policy.d.ts
|
|
6
7
|
interface PathPolicyViolationError {
|
|
@@ -13,7 +14,7 @@ interface PathPolicyViolationError {
|
|
|
13
14
|
//#endregion
|
|
14
15
|
//#region src/contracts.d.ts
|
|
15
16
|
declare const BACKEND_CONTRACT_VERSION: "2.0.0-p2";
|
|
16
|
-
declare const BACKEND_CAPABILITY_SCHEMA_VERSION:
|
|
17
|
+
declare const BACKEND_CAPABILITY_SCHEMA_VERSION: 11;
|
|
17
18
|
declare const BACKEND_COMPATIBILITY_POLICY: {
|
|
18
19
|
readonly incompatibleChange: "requires contractVersion bump";
|
|
19
20
|
readonly capabilitySchemaChange: "requires capabilitySchemaVersion bump";
|
|
@@ -67,7 +68,7 @@ interface BackendResponseMeta {
|
|
|
67
68
|
}
|
|
68
69
|
//#endregion
|
|
69
70
|
//#region src/runtime/capabilities.d.ts
|
|
70
|
-
declare const BACKEND_METHODS: readonly ["getCapabilities", "openSession", "openProjectSession", "getSession", "getProjectOutline", "queryEntity", "validateSession", "preflightTransaction", "applyTransaction", "saveSession", "materializeSession", "closeSession", "getEvents", "getJob", "listJobs", "cancelJob", "getCacheSnapshot", "refreshCache"];
|
|
71
|
+
declare const BACKEND_METHODS: readonly ["getCapabilities", "openSession", "openProjectSession", "getSession", "getProjectOutline", "queryEntity", "readSessionState", "readResourceBytes", "validateSession", "preflightTransaction", "applyTransaction", "saveSession", "materializeSession", "closeSession", "getEvents", "getJob", "listJobs", "cancelJob", "getCacheSnapshot", "refreshCache"];
|
|
71
72
|
//#endregion
|
|
72
73
|
//#region src/runtime/contracts.d.ts
|
|
73
74
|
declare const BACKEND_ENTITY_QUERY_LIMITS: {
|
|
@@ -75,6 +76,57 @@ declare const BACKEND_ENTITY_QUERY_LIMITS: {
|
|
|
75
76
|
readonly maxDepth: 32;
|
|
76
77
|
readonly maxNodes: 100000;
|
|
77
78
|
};
|
|
79
|
+
declare const BACKEND_SESSION_READ_LIMITS: {
|
|
80
|
+
readonly model: {
|
|
81
|
+
readonly maxBytes: 4194304;
|
|
82
|
+
readonly maxDepth: 64;
|
|
83
|
+
readonly maxNodes: 500000;
|
|
84
|
+
};
|
|
85
|
+
readonly resourceBytes: 1048576;
|
|
86
|
+
};
|
|
87
|
+
/** The public UAM model, excluding only each asset resource's primary sourceBytes. */
|
|
88
|
+
type BackendSessionResourceModel = UamComponentResource | Omit<UamImageResource, 'sourceBytes'> | Omit<UamMovieClipResource, 'sourceBytes'> | Omit<UamGenericAssetResource, 'sourceBytes'>;
|
|
89
|
+
interface BackendSessionPackageModel extends Omit<UamPackage, 'resources'> {
|
|
90
|
+
resources: BackendSessionResourceModel[];
|
|
91
|
+
}
|
|
92
|
+
interface BackendSessionProjectModel extends Omit<UamProject, 'packages'> {
|
|
93
|
+
packages: BackendSessionPackageModel[];
|
|
94
|
+
}
|
|
95
|
+
interface ReadSessionStateInput {
|
|
96
|
+
sessionId: string;
|
|
97
|
+
expectedRevision?: number;
|
|
98
|
+
}
|
|
99
|
+
interface ReadResourceBytesInput {
|
|
100
|
+
sessionId: string;
|
|
101
|
+
expectedRevision: number;
|
|
102
|
+
selector: UamResourceSelector;
|
|
103
|
+
}
|
|
104
|
+
interface BackendSessionStateSnapshot extends Pick<BackendSessionSnapshot, 'sessionId' | 'revision' | 'lastSavedRevision' | 'dirty' | 'uamFidelity'> {
|
|
105
|
+
project: BackendSessionProjectModel;
|
|
106
|
+
readDiagnostics: _$_openfairygui_core0.ProjectDiagnostic[];
|
|
107
|
+
/** Source-read completeness, not a guarantee of resource bytes or downstream usability. */
|
|
108
|
+
readComplete: boolean;
|
|
109
|
+
}
|
|
110
|
+
interface BackendResourceBytesSnapshot {
|
|
111
|
+
sessionId: string;
|
|
112
|
+
revision: number;
|
|
113
|
+
selector: UamResourceSelector;
|
|
114
|
+
/** Only primary bytes already held in this session; no filesystem hydration. */
|
|
115
|
+
sourceBytes: Uint8Array;
|
|
116
|
+
}
|
|
117
|
+
interface SessionReadError {
|
|
118
|
+
code: 'session_read_failed';
|
|
119
|
+
message: string;
|
|
120
|
+
sessionId: string;
|
|
121
|
+
reason: 'invalid_query' | 'not_found' | 'ambiguous' | 'unsupported_resource' | 'bytes_unavailable' | 'response_budget_exceeded' | 'non_json_value';
|
|
122
|
+
}
|
|
123
|
+
interface SessionStaleReadError {
|
|
124
|
+
code: 'stale_read';
|
|
125
|
+
message: string;
|
|
126
|
+
sessionId: string;
|
|
127
|
+
expectedRevision: number;
|
|
128
|
+
actualRevision: number;
|
|
129
|
+
}
|
|
78
130
|
declare const BACKEND_TRANSACTION_PREVIEW_LIMITS: {
|
|
79
131
|
readonly maxBytes: 262144;
|
|
80
132
|
readonly maxEntries: 2000;
|
|
@@ -247,6 +299,15 @@ interface BackendCapabilities {
|
|
|
247
299
|
sourceBytes: false;
|
|
248
300
|
limits: typeof BACKEND_ENTITY_QUERY_LIMITS;
|
|
249
301
|
};
|
|
302
|
+
sessionState: {
|
|
303
|
+
sourceBytes: false;
|
|
304
|
+
limits: typeof BACKEND_SESSION_READ_LIMITS.model;
|
|
305
|
+
};
|
|
306
|
+
resourceBytes: {
|
|
307
|
+
expectedRevisionRequired: true;
|
|
308
|
+
hydration: false;
|
|
309
|
+
maxBytes: typeof BACKEND_SESSION_READ_LIMITS.resourceBytes;
|
|
310
|
+
};
|
|
250
311
|
projectValidation: true;
|
|
251
312
|
};
|
|
252
313
|
authoring: {
|
|
@@ -588,7 +649,7 @@ interface RefreshCacheInput {
|
|
|
588
649
|
sessionId: string;
|
|
589
650
|
reason?: 'manual' | 'session_open' | 'after_save';
|
|
590
651
|
}
|
|
591
|
-
type BackendError = SessionNotFoundError | TransactionPreviewError | EntityQueryError | SessionIdConflictError | SessionStaleWriteError | InProcessLockConflictError | AdvisoryLockConflictError | SavePartialFailureError | UamFidelityUnsupportedError | MaterializeValidationFailedError | MaterializeWriteFailedError | PathPolicyViolationError | EventCursorInvalidError | BackendJobNotFoundError | BackendJobNotCancellableError | BackendJobCancelledError | CacheRefreshFailedError | BackendCapabilityUnavailableError | ProjectRootNotAllowedError | ProjectOpenFailedError | ApplyUamTransactionAppError;
|
|
652
|
+
type BackendError = SessionNotFoundError | TransactionPreviewError | EntityQueryError | SessionReadError | SessionStaleReadError | SessionIdConflictError | SessionStaleWriteError | InProcessLockConflictError | AdvisoryLockConflictError | SavePartialFailureError | UamFidelityUnsupportedError | MaterializeValidationFailedError | MaterializeWriteFailedError | PathPolicyViolationError | EventCursorInvalidError | BackendJobNotFoundError | BackendJobNotCancellableError | BackendJobCancelledError | CacheRefreshFailedError | BackendCapabilityUnavailableError | ProjectRootNotAllowedError | ProjectOpenFailedError | ApplyUamTransactionAppError;
|
|
592
653
|
interface ProjectRootNotAllowedError {
|
|
593
654
|
code: 'project_root_not_allowed';
|
|
594
655
|
message: string;
|
|
@@ -714,6 +775,8 @@ declare class BackendRuntime {
|
|
|
714
775
|
}): BackendResult<BackendSessionSnapshot, SessionNotFoundError>;
|
|
715
776
|
getProjectOutline(input: GetProjectOutlineInput): BackendResult<BackendProjectOutline, SessionNotFoundError>;
|
|
716
777
|
queryEntity(input: QueryEntityInput): BackendResult<BackendEntitySnapshot, SessionNotFoundError | EntityQueryError>;
|
|
778
|
+
readSessionState(input: ReadSessionStateInput): BackendResult<BackendSessionStateSnapshot, SessionNotFoundError | SessionReadError | SessionStaleReadError>;
|
|
779
|
+
readResourceBytes(input: ReadResourceBytesInput): BackendResult<BackendResourceBytesSnapshot, SessionNotFoundError | SessionReadError | SessionStaleReadError>;
|
|
717
780
|
validateSession(input: ValidateSessionInput): BackendResult<ProjectValidationReport, SessionNotFoundError>;
|
|
718
781
|
preflightTransaction(input: ApplySessionTransactionInput): Promise<BackendResult<BackendTransactionPreview, SessionNotFoundError | SessionStaleWriteError | ApplyUamTransactionAppError | TransactionPreviewError>>;
|
|
719
782
|
applyTransaction(input: ApplySessionTransactionInput): Promise<BackendResult<BackendSessionSnapshot, SessionNotFoundError | SessionStaleWriteError | ApplyUamTransactionAppError>>;
|