@floless/app 0.137.1 → 0.137.3
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/dist/floless-server.cjs +879 -640
- package/dist/web/app.css +21 -0
- package/dist/web/commands-shell.js +11 -0
- package/dist/web/steel-editor.html +127 -10
- package/dist/web/workspaces.js +81 -1
- package/package.json +1 -1
package/dist/floless-server.cjs
CHANGED
|
@@ -55058,7 +55058,7 @@ function appVersion() {
|
|
|
55058
55058
|
return resolveVersion({
|
|
55059
55059
|
isSea: isSea2(),
|
|
55060
55060
|
sqVersionXml: readSqVersionXml(),
|
|
55061
|
-
define: true ? "0.137.
|
|
55061
|
+
define: true ? "0.137.3" : void 0,
|
|
55062
55062
|
pkgVersion: readPkgVersion()
|
|
55063
55063
|
});
|
|
55064
55064
|
}
|
|
@@ -55074,7 +55074,7 @@ function resolveChannel(s) {
|
|
|
55074
55074
|
function appChannel() {
|
|
55075
55075
|
return resolveChannel({
|
|
55076
55076
|
isSea: isSea2(),
|
|
55077
|
-
define: true ? "0.137.
|
|
55077
|
+
define: true ? "0.137.3" : void 0,
|
|
55078
55078
|
// argv[1] is the entry the runtime actually loaded (…/dist/floless-server.cjs), which is what
|
|
55079
55079
|
// carries the npx cache prefix. Absent under the SEA exe, which never reaches the npx branch.
|
|
55080
55080
|
modulePath: process.argv[1]
|
|
@@ -58945,6 +58945,10 @@ function etagsOf(doc) {
|
|
|
58945
58945
|
const superseded = `"${supersededContractIdentityHash(doc)}"`;
|
|
58946
58946
|
return { current, superseded: superseded === current ? null : superseded };
|
|
58947
58947
|
}
|
|
58948
|
+
function recordedEtagsNameDocument(recorded, doc) {
|
|
58949
|
+
const etags = etagsOf(doc);
|
|
58950
|
+
return recorded.map((tag) => recordedEtagNamesContract(tag, etags));
|
|
58951
|
+
}
|
|
58948
58952
|
function recordedEtagNamesContract(recorded, etags) {
|
|
58949
58953
|
if (!recorded) return false;
|
|
58950
58954
|
return recorded === etags.current || etags.superseded !== null && recorded === etags.superseded;
|
|
@@ -64363,7 +64367,7 @@ My note: ${req.instruction}` : "";
|
|
|
64363
64367
|
return `In floless project "${req.project}" (app "${req.appId}"), a REVISED drawing set was attached. Re-read it into the SAME steel.model/v2 project. ${manifestPhase} The server writes the exact Filter into the existing model. Then STOP and tell me exactly: ${REVISION_READ_FILTER_QUESTION} Do not read members, build the model, open 3D, or POST /revision-read until I explicitly return after saving the Drawing Filter. Only after Save, read selected elements into model-global members in world millimetres, preserve unchanged member ids, attach active observations using { sourceHash, sheet, elementId }, and preserve grid and plan registration unless the drawings explicitly prove a reviewed change. ${post}${snaps}${note}`;
|
|
64364
64368
|
}
|
|
64365
64369
|
if (isInitialRead) {
|
|
64366
|
-
return `In floless project "${req.project}" (app "${req.appId}"), an initial drawing set was attached. Create its first steel model version without creating another project. ${manifestPhase} Use the exact returned Filter and bound pages to compose a schema-valid native steel.model/v2 checkpoint shell with zero members/model records, one canonical model grid, and one registered plans[] row per DRAWING VIEW covering the manifest model sheets \u2014 a page carrying several elevations gets one row each, sharing that page's sheet and stating its own model-global id. PUT that shell to /api/contract/${req.appId}?project=${req.project} with If-None-Match: * and X-FloLess-Prepass-Request: "${req.id}". Then STOP and tell me exactly: ${REVISION_READ_FILTER_QUESTION} Do not read members or post /revision-read before Save. AFTER Save, add model-global members in world millimetres and active observations using { sourceHash, sheet, elementId }, preserving the checkpoint Filter
|
|
64370
|
+
return `In floless project "${req.project}" (app "${req.appId}"), an initial drawing set was attached. Create its first steel model version without creating another project. ${manifestPhase} Use the exact returned Filter and bound pages to compose a schema-valid native steel.model/v2 checkpoint shell with zero members/model records, one canonical model grid, and one registered plans[] row per DRAWING VIEW covering the manifest model sheets \u2014 a page carrying several elevations gets one row each, sharing that page's sheet and stating its own model-global id. PUT that shell to /api/contract/${req.appId}?project=${req.project} with If-None-Match: * and X-FloLess-Prepass-Request: "${req.id}". Then STOP and tell me exactly: ${REVISION_READ_FILTER_QUESTION} Do not read members or post /revision-read before Save. AFTER Save, add model-global members in world millimetres and active observations using { sourceHash, sheet, elementId }, preserving the checkpoint Filter byte-for-byte and every grid field and plan registration value the checkpoint STATES. Where the checkpoint states nothing this build can honour you MUST author it: a grid whose axes[] is empty, a datum_ref/control2_ref in the retired { axis_x, axis_y } spelling (replace it with { xAxisId, yAxisId } \u2014 do not delete it, an omitted datum_ref means the datum IS the model origin), and a plans[] row carrying no registration at all. Never change a view's id, sheet or viewKind, and never add or remove a plans[] row. ${post}${snaps}${note}`;
|
|
64367
64371
|
}
|
|
64368
64372
|
throw new Error("unreachable steel revision-read instruction branch");
|
|
64369
64373
|
}
|
|
@@ -65975,6 +65979,194 @@ function withDeterministicFilterIds(document) {
|
|
|
65975
65979
|
return copy;
|
|
65976
65980
|
}
|
|
65977
65981
|
|
|
65982
|
+
// steel-intersection-ref.ts
|
|
65983
|
+
var axisId = (v) => {
|
|
65984
|
+
if (typeof v !== "string") return null;
|
|
65985
|
+
const t = v.trim();
|
|
65986
|
+
return t.length > 0 ? t : null;
|
|
65987
|
+
};
|
|
65988
|
+
var isObj3 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
65989
|
+
function intersectionRef(v) {
|
|
65990
|
+
if (v === void 0 || v === null) return { state: "absent" };
|
|
65991
|
+
if (isObj3(v)) {
|
|
65992
|
+
const unknown = Object.keys(v).filter((k) => k !== "xAxisId" && k !== "yAxisId");
|
|
65993
|
+
if (unknown.length) {
|
|
65994
|
+
return { state: "invalid", why: `an intersection has only \`xAxisId\` and \`yAxisId\` \u2014 ${unknown.map((k) => `\`${k}\``).join(", ")} ${unknown.length > 1 ? "are" : "is"} not recognised${unknown.some((k) => k === "axis_x" || k === "axis_y") ? "; registration names grid axis IDS now, never labels" : ""}` };
|
|
65995
|
+
}
|
|
65996
|
+
const x = axisId(v.xAxisId), y = axisId(v.yAxisId);
|
|
65997
|
+
if (x && y) return { state: "valid", x, y };
|
|
65998
|
+
const missing = [!x ? "xAxisId" : null, !y ? "yAxisId" : null].filter(Boolean).join(" and ");
|
|
65999
|
+
return { state: "invalid", why: `${missing} must each be a non-blank grid axis id` };
|
|
66000
|
+
}
|
|
66001
|
+
return { state: "invalid", why: `a ${Array.isArray(v) ? "list" : typeof v} names no grid intersection; expected { xAxisId, yAxisId }` };
|
|
66002
|
+
}
|
|
66003
|
+
function canonicalRef(r) {
|
|
66004
|
+
return { xAxisId: r.x, yAxisId: r.y };
|
|
66005
|
+
}
|
|
66006
|
+
|
|
66007
|
+
// steel-shell-invariants.ts
|
|
66008
|
+
var SHELL_REGISTRATION_FIELDS = [
|
|
66009
|
+
"id",
|
|
66010
|
+
"sheet",
|
|
66011
|
+
"viewKind",
|
|
66012
|
+
"elevation_in",
|
|
66013
|
+
"pt_per_ft",
|
|
66014
|
+
"datum_at",
|
|
66015
|
+
"datum_ref",
|
|
66016
|
+
"control2_at",
|
|
66017
|
+
"control2_ref",
|
|
66018
|
+
"frame",
|
|
66019
|
+
"sourceRegistration"
|
|
66020
|
+
];
|
|
66021
|
+
var IDENTITY_FIELDS = ["id", "sheet", "viewKind"];
|
|
66022
|
+
var REGISTRATION_FIELDS = SHELL_REGISTRATION_FIELDS.filter((key2) => !IDENTITY_FIELDS.includes(key2));
|
|
66023
|
+
var PLAN_REGISTRATION_FIELDS = [
|
|
66024
|
+
"elevation_in",
|
|
66025
|
+
"pt_per_ft",
|
|
66026
|
+
"datum_at",
|
|
66027
|
+
"datum_ref",
|
|
66028
|
+
"control2_at",
|
|
66029
|
+
"control2_ref",
|
|
66030
|
+
"frame"
|
|
66031
|
+
];
|
|
66032
|
+
var SOURCE_REGISTRATION_FIELDS = ["pt_per_ft", "sourceRegistration", "frame"];
|
|
66033
|
+
var G1_AUTHORABLE_GRID_FIELDS = [
|
|
66034
|
+
"axes",
|
|
66035
|
+
"origin",
|
|
66036
|
+
"x",
|
|
66037
|
+
"y",
|
|
66038
|
+
"z",
|
|
66039
|
+
"labels_x",
|
|
66040
|
+
"labels_y",
|
|
66041
|
+
"labels_z",
|
|
66042
|
+
"hidden_z",
|
|
66043
|
+
"ext",
|
|
66044
|
+
"on",
|
|
66045
|
+
"ends"
|
|
66046
|
+
];
|
|
66047
|
+
var isObj4 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
66048
|
+
var states = (row, key2) => isObj4(row) && row[key2] !== void 0 && row[key2] !== null;
|
|
66049
|
+
var plansOf = (doc) => {
|
|
66050
|
+
const plans = isObj4(doc) ? doc.plans : void 0;
|
|
66051
|
+
return Array.isArray(plans) ? plans : [];
|
|
66052
|
+
};
|
|
66053
|
+
var gridOf = (doc) => {
|
|
66054
|
+
const grid = isObj4(doc) ? doc.grid : void 0;
|
|
66055
|
+
return isObj4(grid) ? grid : null;
|
|
66056
|
+
};
|
|
66057
|
+
function registrationFieldsFor(viewKind) {
|
|
66058
|
+
if (viewKind === "plan") return PLAN_REGISTRATION_FIELDS;
|
|
66059
|
+
if (viewKind === "elevation" || viewKind === "section") return SOURCE_REGISTRATION_FIELDS;
|
|
66060
|
+
return [];
|
|
66061
|
+
}
|
|
66062
|
+
function shellMask(shell) {
|
|
66063
|
+
const unbound = [];
|
|
66064
|
+
const plans = plansOf(shell);
|
|
66065
|
+
const grid = gridOf(shell);
|
|
66066
|
+
const g3Fields = plans.map((row) => {
|
|
66067
|
+
if (!isObj4(row)) return [];
|
|
66068
|
+
if (REGISTRATION_FIELDS.some((key2) => states(row, key2))) return [];
|
|
66069
|
+
return registrationFieldsFor(row.viewKind);
|
|
66070
|
+
});
|
|
66071
|
+
g3Fields.forEach((fields, index) => {
|
|
66072
|
+
for (const field of fields) {
|
|
66073
|
+
unbound.push({ path: `$.plans[${index}].${field}`, reason: "unregistered-view", mode: "author" });
|
|
66074
|
+
}
|
|
66075
|
+
});
|
|
66076
|
+
plans.forEach((row, index) => {
|
|
66077
|
+
if (!isObj4(row)) return;
|
|
66078
|
+
for (const side2 of ["datum", "control2"]) {
|
|
66079
|
+
const key2 = `${side2}_ref`;
|
|
66080
|
+
const at = `${side2}_at`;
|
|
66081
|
+
if (states(row, key2)) {
|
|
66082
|
+
if (intersectionRef(row[key2]).state !== "invalid") continue;
|
|
66083
|
+
unbound.push({
|
|
66084
|
+
path: `$.plans[${index}].${key2}`,
|
|
66085
|
+
reason: "unreadable-reference",
|
|
66086
|
+
mode: states(row, at) ? "replace" : "author"
|
|
66087
|
+
});
|
|
66088
|
+
} else if (side2 === "control2" && row.viewKind === "plan" && states(row, at)) {
|
|
66089
|
+
unbound.push({ path: `$.plans[${index}].${key2}`, reason: "unreadable-reference", mode: "author" });
|
|
66090
|
+
}
|
|
66091
|
+
}
|
|
66092
|
+
});
|
|
66093
|
+
const axes = grid?.axes;
|
|
66094
|
+
const axesUnstated = axes === void 0 || axes === null || Array.isArray(axes) && axes.length === 0;
|
|
66095
|
+
const gridCorroborated = plans.some((row, index) => isObj4(row) && row.viewKind === "plan" && (states(row, "datum_ref") || states(row, "control2_ref") || g3Fields[index].length > 0));
|
|
66096
|
+
if (grid && axesUnstated && gridCorroborated) {
|
|
66097
|
+
for (const field of G1_AUTHORABLE_GRID_FIELDS) {
|
|
66098
|
+
if (field !== "axes" && states(grid, field)) continue;
|
|
66099
|
+
unbound.push({ path: `$.grid.${field}`, reason: "grid-unstated", mode: "author" });
|
|
66100
|
+
}
|
|
66101
|
+
}
|
|
66102
|
+
return unbound;
|
|
66103
|
+
}
|
|
66104
|
+
var PRESENT = "\0shell:stated";
|
|
66105
|
+
function maskIndex(unbound) {
|
|
66106
|
+
return new Map(unbound.map((row) => [row.path, row.mode]));
|
|
66107
|
+
}
|
|
66108
|
+
function projectPlans(doc, unbound) {
|
|
66109
|
+
const index = maskIndex(unbound);
|
|
66110
|
+
return plansOf(doc).map((raw, i) => {
|
|
66111
|
+
const entries = [];
|
|
66112
|
+
for (const key2 of SHELL_REGISTRATION_FIELDS) {
|
|
66113
|
+
const mode = index.get(`$.plans[${i}].${key2}`);
|
|
66114
|
+
if (mode === "author") continue;
|
|
66115
|
+
if (!states(raw, key2)) continue;
|
|
66116
|
+
entries.push([key2, mode === "replace" ? PRESENT : raw[key2]]);
|
|
66117
|
+
}
|
|
66118
|
+
return Object.fromEntries(entries);
|
|
66119
|
+
});
|
|
66120
|
+
}
|
|
66121
|
+
function projectGrid(doc, unbound) {
|
|
66122
|
+
const grid = gridOf(doc);
|
|
66123
|
+
if (!grid) return isObj4(doc) ? doc.grid : void 0;
|
|
66124
|
+
const index = maskIndex(unbound);
|
|
66125
|
+
const entries = [];
|
|
66126
|
+
for (const key2 of Object.keys(grid)) {
|
|
66127
|
+
if (index.get(`$.grid.${key2}`) === "author") continue;
|
|
66128
|
+
entries.push([key2, grid[key2]]);
|
|
66129
|
+
}
|
|
66130
|
+
return Object.fromEntries(entries);
|
|
66131
|
+
}
|
|
66132
|
+
function shellBinding(shell, candidate) {
|
|
66133
|
+
const unbound = shellMask(shell);
|
|
66134
|
+
const deviations = [];
|
|
66135
|
+
const compare = (invariant, detail, left, right) => {
|
|
66136
|
+
const shellHash = contractHash(left);
|
|
66137
|
+
const candidateHash = contractHash(right);
|
|
66138
|
+
if (shellHash !== candidateHash) deviations.push({ invariant, detail, shellHash, candidateHash });
|
|
66139
|
+
};
|
|
66140
|
+
compare(
|
|
66141
|
+
"grid",
|
|
66142
|
+
"the submitted model changed the saved grid",
|
|
66143
|
+
projectGrid(shell, unbound),
|
|
66144
|
+
projectGrid(candidate, unbound)
|
|
66145
|
+
);
|
|
66146
|
+
compare(
|
|
66147
|
+
"registration",
|
|
66148
|
+
"the submitted model changed saved plan registration",
|
|
66149
|
+
projectPlans(shell, unbound),
|
|
66150
|
+
projectPlans(candidate, unbound)
|
|
66151
|
+
);
|
|
66152
|
+
const shellGrid = gridOf(shell);
|
|
66153
|
+
const candidateGrid = gridOf(candidate);
|
|
66154
|
+
const shellPlans = plansOf(shell);
|
|
66155
|
+
const candidatePlans = plansOf(candidate);
|
|
66156
|
+
const usedUnbound = unbound.filter((row) => {
|
|
66157
|
+
const gridField = /^\$\.grid\.(.+)$/.exec(row.path);
|
|
66158
|
+
if (gridField) return contractHash(shellGrid?.[gridField[1]]) !== contractHash(candidateGrid?.[gridField[1]]);
|
|
66159
|
+
const planField = /^\$\.plans\[(\d+)\]\.(.+)$/.exec(row.path);
|
|
66160
|
+
if (!planField) return false;
|
|
66161
|
+
const index = Number(planField[1]);
|
|
66162
|
+
const key2 = planField[2];
|
|
66163
|
+
const left = shellPlans[index], right = candidatePlans[index];
|
|
66164
|
+
if (!isObj4(right)) return false;
|
|
66165
|
+
return contractHash(isObj4(left) ? left[key2] : void 0) !== contractHash(right[key2]);
|
|
66166
|
+
});
|
|
66167
|
+
return { deviations, unbound, usedUnbound, maskHash: contractHash(usedUnbound) };
|
|
66168
|
+
}
|
|
66169
|
+
|
|
65978
66170
|
// steel-prepass-status.ts
|
|
65979
66171
|
function hasSteelFilterCheckpoint(document) {
|
|
65980
66172
|
if (!document || typeof document !== "object" || Array.isArray(document)) return false;
|
|
@@ -67289,9 +67481,9 @@ var InvalidModelV2Error = class extends Error {
|
|
|
67289
67481
|
function invalidModelV2Reply(err2) {
|
|
67290
67482
|
return { ok: false, error: err2.issues[0] ?? err2.message, issues: err2.issues };
|
|
67291
67483
|
}
|
|
67292
|
-
var
|
|
67484
|
+
var isObj5 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
67293
67485
|
function isModelV2(doc) {
|
|
67294
|
-
return
|
|
67486
|
+
return isObj5(doc) && doc.type === "steel.model/v2";
|
|
67295
67487
|
}
|
|
67296
67488
|
function readModel(doc) {
|
|
67297
67489
|
return readModelOrIssues(doc).view ?? null;
|
|
@@ -69341,12 +69533,12 @@ var SteelManifestCoverageError = class extends Error {
|
|
|
69341
69533
|
}
|
|
69342
69534
|
diagnostic;
|
|
69343
69535
|
};
|
|
69344
|
-
var
|
|
69536
|
+
var isObj6 = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
69345
69537
|
function verifiedRawIds(elements, sourceHash, page, filterCount) {
|
|
69346
69538
|
const ids = [];
|
|
69347
69539
|
const seen = /* @__PURE__ */ new Set();
|
|
69348
69540
|
for (const raw of elements) {
|
|
69349
|
-
const element =
|
|
69541
|
+
const element = isObj6(raw) ? raw : {};
|
|
69350
69542
|
const id = typeof element.id === "string" ? element.id : "";
|
|
69351
69543
|
if (!RAW_ID.test(id)) throw new SteelManifestCoverageError({ sourceHash, page, evidenceCount: elements.length, filterCount, category: "missing-id", samples: [`${typeof element.id}:${id.length}:${id.slice(0, 16)}`] });
|
|
69352
69544
|
if (element.sourceHash !== sourceHash) throw new SteelManifestCoverageError({ sourceHash, page, evidenceCount: elements.length, filterCount, category: "source-mismatch", samples: [id] });
|
|
@@ -69441,7 +69633,7 @@ function steelReadPageShards(stored2) {
|
|
|
69441
69633
|
}
|
|
69442
69634
|
var canonicalKey = (dim, value) => facetKey(dim, value);
|
|
69443
69635
|
function selectionIndex(filter) {
|
|
69444
|
-
const source =
|
|
69636
|
+
const source = isObj6(filter) ? filter : {};
|
|
69445
69637
|
const mode = selectionMode(source.mode);
|
|
69446
69638
|
const active2 = new Set(selectionDims(mode));
|
|
69447
69639
|
const onKeys = (dim) => {
|
|
@@ -69449,7 +69641,7 @@ function selectionIndex(filter) {
|
|
|
69449
69641
|
const rows2 = Array.isArray(source[descriptor.control]) ? source[descriptor.control] : [];
|
|
69450
69642
|
const out = /* @__PURE__ */ new Set();
|
|
69451
69643
|
for (const row of rows2) {
|
|
69452
|
-
if (!
|
|
69644
|
+
if (!isObj6(row) || row.on !== true) continue;
|
|
69453
69645
|
const key2 = canonicalKey(dim, row[descriptor.rowKey]);
|
|
69454
69646
|
if (key2 !== void 0) out.add(key2);
|
|
69455
69647
|
}
|
|
@@ -69490,8 +69682,8 @@ function sourceLineInventory(input) {
|
|
|
69490
69682
|
const lines = [];
|
|
69491
69683
|
const unboundSheets = [];
|
|
69492
69684
|
const unownedCandidates = [];
|
|
69493
|
-
if (
|
|
69494
|
-
const sheets = (Array.isArray(filter.sheets) ? filter.sheets : []).filter(
|
|
69685
|
+
if (isObj6(filter)) {
|
|
69686
|
+
const sheets = (Array.isArray(filter.sheets) ? filter.sheets : []).filter(isObj6);
|
|
69495
69687
|
const claims = /* @__PURE__ */ new Map();
|
|
69496
69688
|
for (const sheet of sheets) if (typeof sheet.pageId === "string") claims.set(sheet.pageId, (claims.get(sheet.pageId) ?? 0) + 1);
|
|
69497
69689
|
for (const sheet of sheets) {
|
|
@@ -69509,7 +69701,7 @@ function sourceLineInventory(input) {
|
|
|
69509
69701
|
const modelable = reasons.length === 0;
|
|
69510
69702
|
const sheetName = typeof sheet.sheet === "string" ? sheet.sheet : "";
|
|
69511
69703
|
for (const raw of Array.isArray(sheet.elements) ? sheet.elements : []) {
|
|
69512
|
-
if (!
|
|
69704
|
+
if (!isObj6(raw)) continue;
|
|
69513
69705
|
const identity = typeof raw.elementId === "string" ? raw.elementId : raw.id;
|
|
69514
69706
|
if (raw.kind !== "line" || typeof identity !== "string" || typeof raw.sourceHash !== "string") continue;
|
|
69515
69707
|
const facets = facetsOf(raw);
|
|
@@ -69560,7 +69752,7 @@ function sourceLineInventory(input) {
|
|
|
69560
69752
|
unownedCandidates.push(`${candidate.id}:miskinded`);
|
|
69561
69753
|
continue;
|
|
69562
69754
|
}
|
|
69563
|
-
if (!
|
|
69755
|
+
if (!isObj6(candidate.element)) {
|
|
69564
69756
|
if (candidate.kind === "potential-member-line") {
|
|
69565
69757
|
unownedCandidates.push(`${candidate.id}:malformed`);
|
|
69566
69758
|
continue;
|
|
@@ -69937,11 +70129,11 @@ if (Object.keys(DIM_OF_ROW_KEY).length !== MODE_ORDER.length) {
|
|
|
69937
70129
|
for (const { key: key2 } of FACETS) {
|
|
69938
70130
|
if (!DIM_OF_ROW_KEY[key2]) throw new Error(`facet row key ${JSON.stringify(key2)} has no dimension in FACET_DIMS`);
|
|
69939
70131
|
}
|
|
69940
|
-
var
|
|
70132
|
+
var isObj7 = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
69941
70133
|
function rowsOf(source, facet) {
|
|
69942
|
-
if (!
|
|
70134
|
+
if (!isObj7(source)) return [];
|
|
69943
70135
|
const rows2 = source[facet];
|
|
69944
|
-
return Array.isArray(rows2) ? rows2.filter(
|
|
70136
|
+
return Array.isArray(rows2) ? rows2.filter(isObj7) : [];
|
|
69945
70137
|
}
|
|
69946
70138
|
function keyOf(row, key2) {
|
|
69947
70139
|
const dim = DIM_OF_ROW_KEY[key2];
|
|
@@ -69954,7 +70146,7 @@ function explicitOn(row, facet) {
|
|
|
69954
70146
|
return facet === "layers" ? !!row.steel : true;
|
|
69955
70147
|
}
|
|
69956
70148
|
function withUsableDefaultMode(filter) {
|
|
69957
|
-
if (!
|
|
70149
|
+
if (!isObj7(filter)) return filter;
|
|
69958
70150
|
const hasSelection = (dim) => {
|
|
69959
70151
|
const descriptor = FACET_DIMS[dim];
|
|
69960
70152
|
return !!descriptor && rowsOf(filter, descriptor.control).some((row) => explicitOn(row, descriptor.control));
|
|
@@ -69966,7 +70158,7 @@ function withUsableDefaultMode(filter) {
|
|
|
69966
70158
|
}
|
|
69967
70159
|
function mergeWholeSetLayerCensus(input) {
|
|
69968
70160
|
const { modelFilter, evidenceFilter, priorFilter } = input;
|
|
69969
|
-
if (!
|
|
70161
|
+
if (!isObj7(modelFilter)) return modelFilter;
|
|
69970
70162
|
const merged = { ...modelFilter };
|
|
69971
70163
|
for (const { facet, key: key2 } of FACETS) {
|
|
69972
70164
|
const wholeSetCount = /* @__PURE__ */ new Map();
|
|
@@ -70024,27 +70216,27 @@ function mergeWholeSetLayerCensus(input) {
|
|
|
70024
70216
|
return merged;
|
|
70025
70217
|
}
|
|
70026
70218
|
function hasTotalBooleanOn(filter) {
|
|
70027
|
-
if (!
|
|
70219
|
+
if (!isObj7(filter)) return false;
|
|
70028
70220
|
return FACETS.every(({ facet }) => {
|
|
70029
70221
|
const rows2 = filter[facet];
|
|
70030
70222
|
if (rows2 === void 0) return true;
|
|
70031
70223
|
if (!Array.isArray(rows2)) return false;
|
|
70032
|
-
return rows2.every((row) =>
|
|
70224
|
+
return rows2.every((row) => isObj7(row) && typeof row.on === "boolean");
|
|
70033
70225
|
});
|
|
70034
70226
|
}
|
|
70035
70227
|
function hasCanonicalMode(filter) {
|
|
70036
|
-
if (!
|
|
70228
|
+
if (!isObj7(filter)) return false;
|
|
70037
70229
|
const mode = filter.mode;
|
|
70038
70230
|
return typeof mode === "string" && mode !== "" && mode === canonicalMode(modeDims(mode));
|
|
70039
70231
|
}
|
|
70040
70232
|
function hasWellFormedControlValues(filter) {
|
|
70041
|
-
if (!
|
|
70233
|
+
if (!isObj7(filter)) return false;
|
|
70042
70234
|
return FACETS.every(({ facet, key: key2 }) => {
|
|
70043
70235
|
const rows2 = filter[facet];
|
|
70044
70236
|
if (rows2 === void 0) return true;
|
|
70045
70237
|
if (!Array.isArray(rows2)) return false;
|
|
70046
70238
|
const dim = DIM_OF_ROW_KEY[key2];
|
|
70047
|
-
return rows2.every((row) =>
|
|
70239
|
+
return rows2.every((row) => isObj7(row) && facetKey(dim, row[key2]) !== void 0);
|
|
70048
70240
|
});
|
|
70049
70241
|
}
|
|
70050
70242
|
|
|
@@ -71428,7 +71620,7 @@ var MAX_MEMBERS = 1e4;
|
|
|
71428
71620
|
var MAX_TEXT = 1e3;
|
|
71429
71621
|
var SHA = /^[0-9a-f]{64}$/;
|
|
71430
71622
|
var SHORTHAND_DISPOSITIONS = /* @__PURE__ */ new Set(["annotation", "existing", "other"]);
|
|
71431
|
-
var
|
|
71623
|
+
var isObj8 = (value) => !!value && typeof value === "object" && !Array.isArray(value);
|
|
71432
71624
|
var text3 = (value, max2 = MAX_TEXT) => typeof value === "string" && value.trim().length > 0 && value.length <= max2 ? value.trim() : null;
|
|
71433
71625
|
var exactKeys2 = (value, allowed) => Object.keys(value).every((key2) => allowed.includes(key2));
|
|
71434
71626
|
var SteelReadAttestationError = class extends Error {
|
|
@@ -71456,7 +71648,7 @@ function parseSteelReadAttestation(input) {
|
|
|
71456
71648
|
} catch {
|
|
71457
71649
|
throw new SteelReadAttestationError("attestation must be acyclic JSON");
|
|
71458
71650
|
}
|
|
71459
|
-
if (typeof json2 !== "string" || !
|
|
71651
|
+
if (typeof json2 !== "string" || !isObj8(input)) throw new SteelReadAttestationError(ATTESTATION_SHAPE_ERROR);
|
|
71460
71652
|
if (input.version === 1) throw new SteelReadAttestationRetiredError(1, ATTESTATION_V1_RETIRED_ERROR);
|
|
71461
71653
|
if (input.version === 2) throw new SteelReadAttestationRetiredError(2, ATTESTATION_V2_RETIRED_ERROR);
|
|
71462
71654
|
if (input.version === 3) throw new SteelReadAttestationRetiredError(3, ATTESTATION_V3_RETIRED_ERROR);
|
|
@@ -71464,18 +71656,18 @@ function parseSteelReadAttestation(input) {
|
|
|
71464
71656
|
if (input.version !== 4 || !exactKeys2(input, ["version", "massing", "layers", "facetExclusions", "lineDispositions", "lineDispositionGroups", "pageReviews", "references", "candidateDispositions", "jointReviews"])) {
|
|
71465
71657
|
throw new SteelReadAttestationError(ATTESTATION_SHAPE_ERROR);
|
|
71466
71658
|
}
|
|
71467
|
-
if (!
|
|
71659
|
+
if (!isObj8(input.massing) || !exactKeys2(input.massing, ["buildingCount", "summary"]) || !Number.isInteger(input.massing.buildingCount) || input.massing.buildingCount < 1 || !text3(input.massing.summary)) {
|
|
71468
71660
|
throw new SteelReadAttestationError("massing must state a positive buildingCount and bounded summary");
|
|
71469
71661
|
}
|
|
71470
71662
|
if (!Array.isArray(input.layers) || input.layers.length > MAX_LAYERS) throw new SteelReadAttestationError("layers must be a bounded array");
|
|
71471
71663
|
const layerNames = /* @__PURE__ */ new Set();
|
|
71472
71664
|
const layerKinds = /* @__PURE__ */ new Set(["member", "annotation", "existing", "mixed", "other"]);
|
|
71473
71665
|
const layers = input.layers.map((raw, index) => {
|
|
71474
|
-
if (!
|
|
71666
|
+
if (!isObj8(raw) || !exactKeys2(raw, ["layer", "disposition", "note", "lineCounts"])) throw new SteelReadAttestationError(`layers[${index}] has unknown or missing keys`);
|
|
71475
71667
|
const layer = text3(raw.layer, 200), note = text3(raw.note);
|
|
71476
71668
|
if (!layer || layerNames.has(layer) || typeof raw.disposition !== "string" || !layerKinds.has(raw.disposition) || !note) throw new SteelReadAttestationError(`layers[${index}] is malformed or duplicated`);
|
|
71477
71669
|
const counts2 = raw.lineCounts;
|
|
71478
|
-
if (!
|
|
71670
|
+
if (!isObj8(counts2) || !exactKeys2(counts2, ["model", "evidence"]) || !Number.isInteger(counts2.model) || counts2.model < 0 || !Number.isInteger(counts2.evidence) || counts2.evidence < 0) {
|
|
71479
71671
|
throw new SteelReadAttestationError(`layers[${index}] must state non-negative integer model/evidence lineCounts`);
|
|
71480
71672
|
}
|
|
71481
71673
|
layerNames.add(layer);
|
|
@@ -71490,7 +71682,7 @@ function parseSteelReadAttestation(input) {
|
|
|
71490
71682
|
const facetSeen = /* @__PURE__ */ new Set();
|
|
71491
71683
|
const facetKinds = /* @__PURE__ */ new Set(["member", "annotation", "existing", "mixed", "other"]);
|
|
71492
71684
|
const facetExclusions = input.facetExclusions.map((raw, index) => {
|
|
71493
|
-
if (!
|
|
71685
|
+
if (!isObj8(raw) || !exactKeys2(raw, ["dim", "value", "disposition", "note", "lineCounts"])) throw new SteelReadAttestationError(`facetExclusions[${index}] has unknown or missing keys`);
|
|
71494
71686
|
const dim = raw.dim === "thickness" ? "thickness" : raw.dim === "color" ? "color" : void 0;
|
|
71495
71687
|
if (dim === void 0) throw new SteelReadAttestationError(`facetExclusions[${index}] must name the thickness or color dimension`);
|
|
71496
71688
|
const key2 = facetKey(dim, dim === "thickness" ? raw.value : typeof raw.value === "string" && raw.value.length <= MAX_FACET_VALUE_CHARS ? raw.value : void 0);
|
|
@@ -71501,7 +71693,7 @@ function parseSteelReadAttestation(input) {
|
|
|
71501
71693
|
if (facetSeen.has(seenKey)) throw new SteelReadAttestationError(`facetExclusions[${index}] duplicates an earlier (dim, value)`);
|
|
71502
71694
|
facetSeen.add(seenKey);
|
|
71503
71695
|
const counts2 = raw.lineCounts;
|
|
71504
|
-
if (!
|
|
71696
|
+
if (!isObj8(counts2) || !exactKeys2(counts2, ["model", "evidence"]) || !Number.isInteger(counts2.model) || counts2.model < 0 || !Number.isInteger(counts2.evidence) || counts2.evidence < 0) {
|
|
71505
71697
|
throw new SteelReadAttestationError(`facetExclusions[${index}] must state non-negative integer model/evidence lineCounts`);
|
|
71506
71698
|
}
|
|
71507
71699
|
return {
|
|
@@ -71516,7 +71708,7 @@ function parseSteelReadAttestation(input) {
|
|
|
71516
71708
|
const lineIds = /* @__PURE__ */ new Set();
|
|
71517
71709
|
const dispositions = /* @__PURE__ */ new Set(["annotation", "existing", "duplicate", "not-steel", "unresolved"]);
|
|
71518
71710
|
const lineDispositions = input.lineDispositions.map((raw, index) => {
|
|
71519
|
-
if (!
|
|
71711
|
+
if (!isObj8(raw) || !exactKeys2(raw, ["elementId", "disposition", "reason", "duplicateOf"])) throw new SteelReadAttestationError(`lineDispositions[${index}] has unknown keys`);
|
|
71520
71712
|
const elementId = text3(raw.elementId, 200), reason = text3(raw.reason);
|
|
71521
71713
|
if (!elementId || lineIds.has(elementId) || typeof raw.disposition !== "string" || !dispositions.has(raw.disposition) || !reason) throw new SteelReadAttestationError(`lineDispositions[${index}] is malformed or duplicated`);
|
|
71522
71714
|
const duplicateOf = raw.duplicateOf === void 0 ? void 0 : text3(raw.duplicateOf, 200);
|
|
@@ -71526,7 +71718,7 @@ function parseSteelReadAttestation(input) {
|
|
|
71526
71718
|
});
|
|
71527
71719
|
if (!Array.isArray(input.lineDispositionGroups) || input.lineDispositionGroups.length > MAX_DISPOSITION_GROUPS) throw new SteelReadAttestationError("lineDispositionGroups must be a bounded array");
|
|
71528
71720
|
const lineDispositionGroups = input.lineDispositionGroups.map((raw, index) => {
|
|
71529
|
-
if (!
|
|
71721
|
+
if (!isObj8(raw) || !exactKeys2(raw, ["disposition", "reason", "duplicateOf", "elementIds"])) throw new SteelReadAttestationError(`lineDispositionGroups[${index}] has unknown or missing keys`);
|
|
71530
71722
|
const reason = text3(raw.reason);
|
|
71531
71723
|
if (typeof raw.disposition !== "string" || !dispositions.has(raw.disposition) || !reason) throw new SteelReadAttestationError(`lineDispositionGroups[${index}] is malformed`);
|
|
71532
71724
|
const duplicateOf = raw.duplicateOf === void 0 ? void 0 : text3(raw.duplicateOf, 200);
|
|
@@ -71547,7 +71739,7 @@ function parseSteelReadAttestation(input) {
|
|
|
71547
71739
|
if (!Array.isArray(input.pageReviews) || input.pageReviews.length > MAX_PAGES) throw new SteelReadAttestationError("pageReviews must be bounded");
|
|
71548
71740
|
const reviewedPageIds = /* @__PURE__ */ new Set();
|
|
71549
71741
|
const pageReviews = input.pageReviews.map((raw, index) => {
|
|
71550
|
-
if (!
|
|
71742
|
+
if (!isObj8(raw) || !exactKeys2(raw, ["pageId", "kind", "candidateShardHash", "note"])) throw new SteelReadAttestationError(`pageReviews[${index}] has unknown keys`);
|
|
71551
71743
|
const pageId = text3(raw.pageId, 200), note = text3(raw.note);
|
|
71552
71744
|
if (!pageId || reviewedPageIds.has(pageId) || raw.kind !== "whole" || typeof raw.candidateShardHash !== "string" || !SHA.test(raw.candidateShardHash) || !note) {
|
|
71553
71745
|
throw new SteelReadAttestationError(`pageReviews[${index}] is malformed or duplicated`);
|
|
@@ -71558,7 +71750,7 @@ function parseSteelReadAttestation(input) {
|
|
|
71558
71750
|
if (!Array.isArray(input.references) || input.references.length > MAX_LINES) throw new SteelReadAttestationError("references must be bounded");
|
|
71559
71751
|
const referenceIds = /* @__PURE__ */ new Set();
|
|
71560
71752
|
const references = input.references.map((raw, index) => {
|
|
71561
|
-
if (!
|
|
71753
|
+
if (!isObj8(raw) || !exactKeys2(raw, ["elementId", "status", "targetPageId", "reason"])) throw new SteelReadAttestationError(`references[${index}] has unknown keys`);
|
|
71562
71754
|
const elementId = text3(raw.elementId, 200);
|
|
71563
71755
|
if (!elementId || referenceIds.has(elementId) || raw.status !== "resolved" && raw.status !== "missing") throw new SteelReadAttestationError(`references[${index}] is malformed or duplicated`);
|
|
71564
71756
|
const targetPageId = raw.targetPageId === void 0 ? void 0 : text3(raw.targetPageId, 200);
|
|
@@ -71571,7 +71763,7 @@ function parseSteelReadAttestation(input) {
|
|
|
71571
71763
|
const candidateIds = /* @__PURE__ */ new Set();
|
|
71572
71764
|
const candidateDispositionKinds = /* @__PURE__ */ new Set(["modeled", "annotation", "not-applicable", "unresolved"]);
|
|
71573
71765
|
const candidateDispositions = input.candidateDispositions.map((raw, index) => {
|
|
71574
|
-
if (!
|
|
71766
|
+
if (!isObj8(raw) || !exactKeys2(raw, ["elementId", "disposition", "reason", "jointId"])) throw new SteelReadAttestationError(`candidateDispositions[${index}] has unknown keys`);
|
|
71575
71767
|
const elementId = text3(raw.elementId, 200), reason = text3(raw.reason);
|
|
71576
71768
|
const jointId = raw.jointId === void 0 ? void 0 : text3(raw.jointId, 200);
|
|
71577
71769
|
if (!elementId || candidateIds.has(elementId) || !candidateDispositionKinds.has(String(raw.disposition)) || !reason) throw new SteelReadAttestationError(`candidateDispositions[${index}] is malformed or duplicated`);
|
|
@@ -71582,7 +71774,7 @@ function parseSteelReadAttestation(input) {
|
|
|
71582
71774
|
if (!Array.isArray(input.jointReviews) || input.jointReviews.length > MAX_JOINTS) throw new SteelReadAttestationError("jointReviews must be bounded");
|
|
71583
71775
|
const jointIds = /* @__PURE__ */ new Set();
|
|
71584
71776
|
const jointReviews = input.jointReviews.map((raw, index) => {
|
|
71585
|
-
if (!
|
|
71777
|
+
if (!isObj8(raw) || !exactKeys2(raw, ["jointId", "dependencyHash", "note"])) throw new SteelReadAttestationError(`jointReviews[${index}] has unknown keys`);
|
|
71586
71778
|
const jointId = text3(raw.jointId, 200), note = text3(raw.note);
|
|
71587
71779
|
if (!jointId || jointIds.has(jointId) || typeof raw.dependencyHash !== "string" || !SHA.test(raw.dependencyHash) || !note) throw new SteelReadAttestationError(`jointReviews[${index}] is malformed or duplicated`);
|
|
71588
71780
|
jointIds.add(jointId);
|
|
@@ -71591,13 +71783,13 @@ function parseSteelReadAttestation(input) {
|
|
|
71591
71783
|
return { version: 4, massing: { buildingCount: input.massing.buildingCount, summary: text3(input.massing.summary) }, layers, facetExclusions, lineDispositions, lineDispositionGroups, pageReviews, references, candidateDispositions, jointReviews };
|
|
71592
71784
|
}
|
|
71593
71785
|
function referenceInventory(filter, manifest, inventory) {
|
|
71594
|
-
if (!
|
|
71786
|
+
if (!isObj8(filter)) return [];
|
|
71595
71787
|
const out = [];
|
|
71596
71788
|
const seen = /* @__PURE__ */ new Set();
|
|
71597
71789
|
for (const rawSheet of Array.isArray(filter.sheets) ? filter.sheets : []) {
|
|
71598
|
-
if (!
|
|
71790
|
+
if (!isObj8(rawSheet)) continue;
|
|
71599
71791
|
for (const raw of Array.isArray(rawSheet.elements) ? rawSheet.elements : []) {
|
|
71600
|
-
if (
|
|
71792
|
+
if (isObj8(raw) && raw.kind === "text" && typeof raw.id === "string" && typeof raw.text === "string" && isSteelReferenceText(raw.text)) {
|
|
71601
71793
|
out.push({ id: raw.id, text: raw.text });
|
|
71602
71794
|
seen.add(raw.id);
|
|
71603
71795
|
}
|
|
@@ -71610,7 +71802,7 @@ function referenceInventory(filter, manifest, inventory) {
|
|
|
71610
71802
|
seen.add(candidate.id);
|
|
71611
71803
|
}
|
|
71612
71804
|
} else for (const page of manifest.manifest.pages) for (const candidate of page.candidates ?? []) {
|
|
71613
|
-
const element =
|
|
71805
|
+
const element = isObj8(candidate.element) ? candidate.element : {};
|
|
71614
71806
|
const candidateText = typeof element.text === "string" ? element.text : "";
|
|
71615
71807
|
if (!isSteelReferenceText(candidateText) || seen.has(candidate.id)) continue;
|
|
71616
71808
|
out.push({ id: candidate.id, text: candidateText });
|
|
@@ -71622,11 +71814,11 @@ function activeObservationElements(candidate, retainedMemberIds) {
|
|
|
71622
71814
|
const out = /* @__PURE__ */ new Map();
|
|
71623
71815
|
let missingEndpointLineageCount = 0;
|
|
71624
71816
|
const missingEndpointLineage = [];
|
|
71625
|
-
if (!
|
|
71817
|
+
if (!isObj8(candidate)) return { elements: out, missingEndpointLineageCount, missingEndpointLineage };
|
|
71626
71818
|
for (const plan of Array.isArray(candidate.plans) ? candidate.plans : []) {
|
|
71627
|
-
if (!
|
|
71819
|
+
if (!isObj8(plan)) continue;
|
|
71628
71820
|
for (const observation of Array.isArray(plan.memberObservations) ? plan.memberObservations : []) {
|
|
71629
|
-
if (!
|
|
71821
|
+
if (!isObj8(observation) || !isObj8(observation.binding) || observation.binding.status !== "active") continue;
|
|
71630
71822
|
const memberIds = Array.isArray(observation.binding.memberIds) ? observation.binding.memberIds.filter((id) => typeof id === "string") : [];
|
|
71631
71823
|
if (!Array.isArray(observation.binding.endpointLineage) || observation.binding.endpointLineage.length === 0) {
|
|
71632
71824
|
const observationId = typeof observation.id === "string" ? observation.id : "<unknown>";
|
|
@@ -71636,10 +71828,10 @@ function activeObservationElements(candidate, retainedMemberIds) {
|
|
|
71636
71828
|
if (missingEndpointLineage.length < 20) missingEndpointLineage.push(`${observationId}:${id}`);
|
|
71637
71829
|
}
|
|
71638
71830
|
}
|
|
71639
|
-
if (!
|
|
71831
|
+
if (!isObj8(observation.evidence) || !isObj8(observation.evidence.source)) continue;
|
|
71640
71832
|
const source = observation.evidence.source;
|
|
71641
71833
|
if (typeof source.elementId !== "string" || typeof source.sourceHash !== "string") continue;
|
|
71642
|
-
const wp =
|
|
71834
|
+
const wp = isObj8(observation.evidence.local) ? observation.evidence.local.wp : void 0;
|
|
71643
71835
|
if (!Array.isArray(wp) || wp.length !== 2 || !wp.every((point3) => Array.isArray(point3) && point3.length === 2 && point3.every(Number.isFinite))) continue;
|
|
71644
71836
|
out.set(source.elementId, { sourceHash: source.sourceHash, sheet: typeof source.sheet === "string" ? source.sheet : "", wp, memberIds });
|
|
71645
71837
|
}
|
|
@@ -71696,8 +71888,8 @@ function worklineMatches(svg, wp) {
|
|
|
71696
71888
|
return straightSegments(svg).some(([a, b]) => samePoint2(a, wp[0]) && samePoint2(b, wp[1]) || samePoint2(a, wp[1]) && samePoint2(b, wp[0]));
|
|
71697
71889
|
}
|
|
71698
71890
|
function jointDependencyHash(candidate, jointId) {
|
|
71699
|
-
if (!
|
|
71700
|
-
const joints = Array.isArray(candidate.joints) ? candidate.joints.filter(
|
|
71891
|
+
if (!isObj8(candidate)) return null;
|
|
71892
|
+
const joints = Array.isArray(candidate.joints) ? candidate.joints.filter(isObj8) : [];
|
|
71701
71893
|
const joint = joints.find((row) => row.id === jointId);
|
|
71702
71894
|
if (!joint) return null;
|
|
71703
71895
|
const memberIds = /* @__PURE__ */ new Set();
|
|
@@ -71705,8 +71897,8 @@ function jointDependencyHash(candidate, jointId) {
|
|
|
71705
71897
|
if (Array.isArray(joint.secondaries)) {
|
|
71706
71898
|
for (const id of joint.secondaries) if (typeof id === "string") memberIds.add(id);
|
|
71707
71899
|
}
|
|
71708
|
-
const members = (Array.isArray(candidate.members) ? candidate.members.filter(
|
|
71709
|
-
const connection = typeof joint.conn === "string" && Array.isArray(candidate.connections) ? candidate.connections.filter(
|
|
71900
|
+
const members = (Array.isArray(candidate.members) ? candidate.members.filter(isObj8) : []).filter((row) => typeof row.id === "string" && memberIds.has(row.id));
|
|
71901
|
+
const connection = typeof joint.conn === "string" && Array.isArray(candidate.connections) ? candidate.connections.filter(isObj8).find((row) => row.id === joint.conn) ?? null : null;
|
|
71710
71902
|
return hashOf({ policy: "steel-joint-dependency/v1", joint, members, connection, expansion: "steel-joints/v2-measured-fit" });
|
|
71711
71903
|
}
|
|
71712
71904
|
function steelExclusionSignOffValid(input) {
|
|
@@ -71719,7 +71911,7 @@ function steelExclusionSignOffValid(input) {
|
|
|
71719
71911
|
if (!hasCanonicalMode(filter)) return { ok: false, why: "mode-noncanonical" };
|
|
71720
71912
|
if (signOff.manifestHash !== storedManifest.manifestHash) return { ok: false, why: "manifest-moved" };
|
|
71721
71913
|
if (signOff.controlsHash !== steelFilterControlsHash(filter)) return { ok: false, why: "controls-moved" };
|
|
71722
|
-
const source =
|
|
71914
|
+
const source = isObj8(filter) ? filter : {};
|
|
71723
71915
|
const active2 = selectionDims(source.mode);
|
|
71724
71916
|
const censusByDim = /* @__PURE__ */ new Map();
|
|
71725
71917
|
for (const dim of active2) {
|
|
@@ -71727,7 +71919,7 @@ function steelExclusionSignOffValid(input) {
|
|
|
71727
71919
|
const rows2 = Array.isArray(source[descriptor.control]) ? source[descriptor.control] : [];
|
|
71728
71920
|
const keys = /* @__PURE__ */ new Set();
|
|
71729
71921
|
for (const row of rows2) {
|
|
71730
|
-
if (!
|
|
71922
|
+
if (!isObj8(row)) continue;
|
|
71731
71923
|
const key2 = facetKey(dim, row[descriptor.rowKey]);
|
|
71732
71924
|
if (key2 !== void 0) keys.add(key2);
|
|
71733
71925
|
}
|
|
@@ -71750,7 +71942,7 @@ function evaluateSteelRead(context) {
|
|
|
71750
71942
|
const add = (id, status, detail, samples) => checks.push({ id, status, detail, ...samples?.length ? { samples: samples.slice(0, 20) } : {} });
|
|
71751
71943
|
const candidateHash = hashOf(candidate);
|
|
71752
71944
|
const proofHash = hashOf(proof3);
|
|
71753
|
-
const filter =
|
|
71945
|
+
const filter = isObj8(candidate) ? candidate.filter : void 0;
|
|
71754
71946
|
const checkpointRecorded = !!storedManifest.savedFilterHash && !!storedManifest.savedFilterEtag;
|
|
71755
71947
|
const checkpointBytesMatch = checkpointRecorded && hashOf(filter) === storedManifest.savedFilterHash;
|
|
71756
71948
|
const checkpointGeometryMatch = checkpointBytesMatch && steelFilterGeometryHash(filter) === steelFilterGeometryHash(storedManifest.manifest.filter);
|
|
@@ -71765,12 +71957,33 @@ function evaluateSteelRead(context) {
|
|
|
71765
71957
|
else if (!checkpointModeCanonical) add("filter-checkpoint", "block", "the saved Filter's match-on mode is empty or not canonical; reopen the Drawing Filter and save it again");
|
|
71766
71958
|
else if (!checkpointControlValuesOk) add("filter-checkpoint", "block", "the saved Filter has a layer, thickness or colour control whose value is not a value for that control");
|
|
71767
71959
|
else add("filter-checkpoint", "pass", "candidate uses the exact saved server-owned Filter");
|
|
71960
|
+
if (context.initialFilterCheckpoint) {
|
|
71961
|
+
const binding = shellBinding(context.current, candidate);
|
|
71962
|
+
if (binding.deviations.length) {
|
|
71963
|
+
add(
|
|
71964
|
+
"shell-preserved",
|
|
71965
|
+
"block",
|
|
71966
|
+
`${binding.deviations.map((deviation) => deviation.detail).join("; ")} \u2014 an initial read may fill the saved Drawing Filter checkpoint in, but may not restate it`,
|
|
71967
|
+
binding.deviations.map((deviation) => `${deviation.invariant}: shell ${deviation.shellHash} vs candidate ${deviation.candidateHash}`)
|
|
71968
|
+
);
|
|
71969
|
+
} else if (binding.usedUnbound.length) {
|
|
71970
|
+
const reasons = [...new Set(binding.usedUnbound.map((row) => row.reason))].sort();
|
|
71971
|
+
add(
|
|
71972
|
+
"shell-preserved",
|
|
71973
|
+
"warning",
|
|
71974
|
+
`${binding.usedUnbound.length} field(s) authored where the saved Drawing Filter checkpoint states nothing this build can honour (${reasons.join(", ")}; mask ${binding.maskHash}) \u2014 every OTHER field the checkpoint states is unchanged`,
|
|
71975
|
+
binding.usedUnbound.map((row) => `${row.path} (${row.reason}, ${row.mode})`)
|
|
71976
|
+
);
|
|
71977
|
+
} else {
|
|
71978
|
+
add("shell-preserved", "pass", "candidate preserves the saved grid and plan registration");
|
|
71979
|
+
}
|
|
71980
|
+
}
|
|
71768
71981
|
const validation = validateSteelModelV2(candidate);
|
|
71769
71982
|
if (!validation.valid) add("contract-validity", "block", `${validation.errors.length} v2 schema/semantic error(s)`, validation.errors.map((error) => `${error.path}: ${error.message}`));
|
|
71770
71983
|
else add("contract-validity", "pass", "final candidate is valid steel.model/v2");
|
|
71771
71984
|
if (validation.valid) {
|
|
71772
71985
|
const model = candidate;
|
|
71773
|
-
const retainedIds = new Set(
|
|
71986
|
+
const retainedIds = new Set(isObj8(context.current) && Array.isArray(context.current.members) ? context.current.members.filter(isObj8).flatMap((member) => typeof member.id === "string" ? [member.id] : []) : []);
|
|
71774
71987
|
const expectedViews = canonicalLineagedViewIds(model);
|
|
71775
71988
|
const report = context.normalization.report;
|
|
71776
71989
|
const scopeMatches = expectedViews.length ? report.scope.kind === "conversion" && JSON.stringify(report.scope.viewIds) === JSON.stringify(expectedViews) : report.scope.kind === "model-3d";
|
|
@@ -71785,12 +71998,12 @@ function evaluateSteelRead(context) {
|
|
|
71785
71998
|
if (inventory) {
|
|
71786
71999
|
const filterIdsByPage = /* @__PURE__ */ new Map();
|
|
71787
72000
|
const filterLineIdsByPage = /* @__PURE__ */ new Map();
|
|
71788
|
-
for (const rawSheet of
|
|
71789
|
-
if (!
|
|
72001
|
+
for (const rawSheet of isObj8(filter) && Array.isArray(filter.sheets) ? filter.sheets : []) {
|
|
72002
|
+
if (!isObj8(rawSheet) || typeof rawSheet.pageId !== "string") continue;
|
|
71790
72003
|
const ids = filterIdsByPage.get(rawSheet.pageId) ?? /* @__PURE__ */ new Set();
|
|
71791
72004
|
const lineIds2 = filterLineIdsByPage.get(rawSheet.pageId) ?? /* @__PURE__ */ new Set();
|
|
71792
72005
|
for (const element of Array.isArray(rawSheet.elements) ? rawSheet.elements : []) {
|
|
71793
|
-
if (!
|
|
72006
|
+
if (!isObj8(element) || typeof element.id !== "string") continue;
|
|
71794
72007
|
ids.add(element.id);
|
|
71795
72008
|
if (element.kind === "line") lineIds2.add(element.id);
|
|
71796
72009
|
}
|
|
@@ -71894,7 +72107,7 @@ function evaluateSteelRead(context) {
|
|
|
71894
72107
|
return owner2 ? { ok: true, ...owner2 } : { ok: false, why: "selected" };
|
|
71895
72108
|
};
|
|
71896
72109
|
const shorthandGatesOpen = filterCheckpointPassed && signOffValid;
|
|
71897
|
-
const retainedMemberIds = new Set(
|
|
72110
|
+
const retainedMemberIds = new Set(isObj8(context.current) && Array.isArray(context.current.members) ? context.current.members.filter(isObj8).flatMap((member) => typeof member.id === "string" ? [member.id] : []) : []);
|
|
71898
72111
|
const observationAudit = activeObservationElements(candidate, retainedMemberIds);
|
|
71899
72112
|
const observations2 = observationAudit.elements;
|
|
71900
72113
|
if (validation.valid) {
|
|
@@ -72040,7 +72253,7 @@ function evaluateSteelRead(context) {
|
|
|
72040
72253
|
const markerCandidates = (inventory ?? storedManifest.manifest.pages.flatMap((page) => page.candidates ?? [])).filter((candidate2) => candidate2.kind === "detail-marker" || candidate2.kind === "connection-marker");
|
|
72041
72254
|
const markerIds = new Set(markerCandidates.map((marker) => marker.id));
|
|
72042
72255
|
const dispositionByCandidate = new Map(proof3.candidateDispositions.map((row) => [row.elementId, row]));
|
|
72043
|
-
const jointIdSet = new Set((
|
|
72256
|
+
const jointIdSet = new Set((isObj8(candidate) && Array.isArray(candidate.joints) ? candidate.joints.filter(isObj8) : []).flatMap((joint) => typeof joint.id === "string" ? [joint.id] : []));
|
|
72044
72257
|
const badCandidates = [];
|
|
72045
72258
|
for (const marker of markerCandidates) {
|
|
72046
72259
|
const disposition = dispositionByCandidate.get(marker.id);
|
|
@@ -72049,9 +72262,9 @@ function evaluateSteelRead(context) {
|
|
|
72049
72262
|
for (const id of dispositionByCandidate.keys()) if (!markerIds.has(id)) badCandidates.push(id);
|
|
72050
72263
|
const unresolvedCandidates = proof3.candidateDispositions.filter((row) => row.disposition === "unresolved").map((row) => row.elementId);
|
|
72051
72264
|
add("detail-reconciliation", badCandidates.length ? "block" : unresolvedCandidates.length ? "warning" : "pass", badCandidates.length ? "detail/connection markers are unaccounted or bind to missing joints" : `${markerCandidates.length} detail/connection marker(s) reconciled`, [...badCandidates, ...unresolvedCandidates]);
|
|
72052
|
-
const candidateObj =
|
|
72053
|
-
const members = Array.isArray(candidateObj.members) ? candidateObj.members.filter(
|
|
72054
|
-
const candidateJoints = Array.isArray(candidateObj.joints) ? candidateObj.joints.filter(
|
|
72265
|
+
const candidateObj = isObj8(candidate) ? candidate : {};
|
|
72266
|
+
const members = Array.isArray(candidateObj.members) ? candidateObj.members.filter(isObj8) : [];
|
|
72267
|
+
const candidateJoints = Array.isArray(candidateObj.joints) ? candidateObj.joints.filter(isObj8) : [];
|
|
72055
72268
|
const budgetExceeded = members.length > MAX_MEMBERS || candidateJoints.length > MAX_JOINTS || lines.length > MAX_LINES;
|
|
72056
72269
|
add("work-budget", budgetExceeded ? "block" : "pass", budgetExceeded ? "candidate or source geometry exceeds the deterministic audit work limits" : `${lines.length} line(s), ${members.length} member(s), and ${candidateJoints.length} joint(s) are within audit limits`);
|
|
72057
72270
|
add("endpoint-lineage", observationAudit.missingEndpointLineageCount ? "block" : "pass", observationAudit.missingEndpointLineageCount ? `${observationAudit.missingEndpointLineageCount} new-member observation binding(s) lack physical endpoint lineage` : "every new-member observation binding carries physical endpoint lineage", observationAudit.missingEndpointLineage);
|
|
@@ -72060,8 +72273,8 @@ function evaluateSteelRead(context) {
|
|
|
72060
72273
|
const id = typeof member.id === "string" ? member.id : "<unknown>";
|
|
72061
72274
|
if (typeof member.profile !== "string" || !profileDims(member.profile)) unresolvedMembers.push(`${id}:profile`);
|
|
72062
72275
|
for (const end of ["from", "to"]) {
|
|
72063
|
-
const point3 =
|
|
72064
|
-
if (!point3 || !
|
|
72276
|
+
const point3 = isObj8(member[end]) ? member[end] : null;
|
|
72277
|
+
if (!point3 || !isObj8(point3.z) || typeof point3.z.known !== "number") unresolvedMembers.push(`${id}:${end}Z`);
|
|
72065
72278
|
}
|
|
72066
72279
|
}
|
|
72067
72280
|
add("resolved-members", unresolvedMembers.length ? "warning" : "pass", unresolvedMembers.length ? `${unresolvedMembers.length} member profile/elevation RFI(s)` : `${members.length} member(s) have resolved profiles and elevations`, unresolvedMembers);
|
|
@@ -72069,8 +72282,8 @@ function evaluateSteelRead(context) {
|
|
|
72069
72282
|
const reviewByJoint = new Map(proof3.jointReviews.map((row) => [row.jointId, row]));
|
|
72070
72283
|
const changedReviewMissing = [];
|
|
72071
72284
|
const currentJointHashes = /* @__PURE__ */ new Map();
|
|
72072
|
-
if (
|
|
72073
|
-
for (const joint of context.current.joints.filter(
|
|
72285
|
+
if (isObj8(context.current) && Array.isArray(context.current.joints)) {
|
|
72286
|
+
for (const joint of context.current.joints.filter(isObj8)) if (typeof joint.id === "string") {
|
|
72074
72287
|
const digest2 = jointDependencyHash(context.current, joint.id);
|
|
72075
72288
|
if (digest2) currentJointHashes.set(joint.id, digest2);
|
|
72076
72289
|
}
|
|
@@ -72320,10 +72533,16 @@ async function runNativeInitialRead(opts) {
|
|
|
72320
72533
|
const checked = validateSteelFilter(candidate, opts.source?.files.map((file) => file.sha256.toLowerCase()));
|
|
72321
72534
|
if (!checked.ok) throw new ContractTransactionError("This filter no longer matches the attached drawing set. Reload the Drawing Filter and review it again.", "filter-invalid", checked.errors);
|
|
72322
72535
|
if (contractHash(shell.filter) !== contractHash(candidate.filter)) throw new ContractTransactionError("the submitted model does not contain the exact saved Drawing Filter", "filter-changed");
|
|
72323
|
-
|
|
72324
|
-
const
|
|
72325
|
-
|
|
72326
|
-
if (
|
|
72536
|
+
const binding = shellBinding(shell, candidate);
|
|
72537
|
+
const deviation = binding.deviations[0];
|
|
72538
|
+
if (deviation) throw new ContractTransactionError(deviation.detail, "shell-changed");
|
|
72539
|
+
if (binding.usedUnbound.length && !opts.readAudit) {
|
|
72540
|
+
throw new ContractTransactionError(
|
|
72541
|
+
`this read authors ${binding.usedUnbound.length} field(s) the saved Drawing Filter checkpoint does not state, which requires a completion audit to record it \u2014 re-attach the drawing set so the request is created under the completion-audit policy`,
|
|
72542
|
+
"shell-authored-without-audit",
|
|
72543
|
+
{ unbound: binding.usedUnbound, maskHash: binding.maskHash }
|
|
72544
|
+
);
|
|
72545
|
+
}
|
|
72327
72546
|
const normalized = normalizeSteelMemberEndsForRead(opts.candidate);
|
|
72328
72547
|
let readAuditReport;
|
|
72329
72548
|
let storedReadAudit;
|
|
@@ -72334,6 +72553,11 @@ async function runNativeInitialRead(opts) {
|
|
|
72334
72553
|
candidate: normalized.model,
|
|
72335
72554
|
attestation: input.attestation,
|
|
72336
72555
|
current,
|
|
72556
|
+
// Definitionally true here: this function refuses anything but an exact checkpoint shell with
|
|
72557
|
+
// empty history (above), which is the same pair of clauses the routes compute. The check can
|
|
72558
|
+
// only pass by the time it runs — the deviation throw is earlier — but the report is what the
|
|
72559
|
+
// receipt stores, and it must say the same thing the preview said (#962).
|
|
72560
|
+
initialFilterCheckpoint: true,
|
|
72337
72561
|
normalization: normalized
|
|
72338
72562
|
});
|
|
72339
72563
|
if (readAuditReport.status !== "read-complete") {
|
|
@@ -76700,6 +76924,9 @@ function logSteelAuditEvent(log2, input) {
|
|
|
76700
76924
|
durationMs: Math.max(0, Date.now() - input.startedAt)
|
|
76701
76925
|
}, "steel read audit event");
|
|
76702
76926
|
}
|
|
76927
|
+
function bindsShellInvariants(headVersion, current) {
|
|
76928
|
+
return headVersion === 0 && isExactFilterCheckpointShell(current);
|
|
76929
|
+
}
|
|
76703
76930
|
function loadAuthoritativeSteelAuditState(project, requestId, attestation, allowedStatuses = /* @__PURE__ */ new Set(["pending"])) {
|
|
76704
76931
|
const request = getRequest(requestId);
|
|
76705
76932
|
if (!request || request.type !== "revision-read" || request.project !== project.id || request.appId !== project.app || request.settledVersion !== void 0 || !allowedStatuses.has(request.status)) {
|
|
@@ -76734,7 +76961,13 @@ function loadAuthoritativeSteelAuditState(project, requestId, attestation, allow
|
|
|
76734
76961
|
attestation: parsedAttestation,
|
|
76735
76962
|
current,
|
|
76736
76963
|
baseVersion: request.baseVersion ?? 0,
|
|
76737
|
-
baseHash: current == null ? null : etagOf(current)?.replace(/^"|"$/g, "") ?? null
|
|
76964
|
+
baseHash: current == null ? null : etagOf(current)?.replace(/^"|"$/g, "") ?? null,
|
|
76965
|
+
// Whether the publish gate will hold this candidate to the shell invariants, computed HERE so both
|
|
76966
|
+
// `evaluateSteelRead` call sites get the one answer (#962). The expression is the initial-read
|
|
76967
|
+
// dispatch condition of the commit route, which is what makes the audit's verdict predict the
|
|
76968
|
+
// publish's: same question, same two clauses. A revision read gets `false` and is not asked to
|
|
76969
|
+
// preserve a grid it is entitled to rewrite.
|
|
76970
|
+
initialFilterCheckpoint: bindsShellInvariants(listVersions(project.id)[0]?.n ?? 0, current)
|
|
76738
76971
|
};
|
|
76739
76972
|
}
|
|
76740
76973
|
function preparedManifestNeedsRegeneration(project, request) {
|
|
@@ -76866,6 +77099,7 @@ async function stageForReviewAudited(reply, project, requestId, candidateInput,
|
|
|
76866
77099
|
candidate,
|
|
76867
77100
|
attestation: state2.attestation,
|
|
76868
77101
|
current: state2.current,
|
|
77102
|
+
initialFilterCheckpoint: state2.initialFilterCheckpoint,
|
|
76869
77103
|
normalization: normalized
|
|
76870
77104
|
});
|
|
76871
77105
|
if (report.status === "blocked") {
|
|
@@ -77953,6 +78187,7 @@ function registerRevisionRoutes(app, deps = {}) {
|
|
|
77953
78187
|
candidate,
|
|
77954
78188
|
attestation: state2.attestation,
|
|
77955
78189
|
current: state2.current,
|
|
78190
|
+
initialFilterCheckpoint: state2.initialFilterCheckpoint,
|
|
77956
78191
|
normalization: normalized
|
|
77957
78192
|
});
|
|
77958
78193
|
const normalization = {
|
|
@@ -78075,7 +78310,7 @@ function registerRevisionRoutes(app, deps = {}) {
|
|
|
78075
78310
|
}
|
|
78076
78311
|
const currentForEvidence = readAcceptedForRequest(project.app, project.id, "read");
|
|
78077
78312
|
const guardError = revisionReadContractError(resolveTemplateId(project.app), req.body.contract, currentForEvidence, {
|
|
78078
|
-
initialFilterCheckpoint: head
|
|
78313
|
+
initialFilterCheckpoint: bindsShellInvariants(head, currentForEvidence)
|
|
78079
78314
|
});
|
|
78080
78315
|
if (guardError) {
|
|
78081
78316
|
return reply.status(400).send({
|
|
@@ -78121,6 +78356,7 @@ function registerRevisionRoutes(app, deps = {}) {
|
|
|
78121
78356
|
return { ok: true, version, contractType: VECTOR_V1 };
|
|
78122
78357
|
}
|
|
78123
78358
|
if (head === 0 && storedContractType(project.app, project.id) === STEEL_V2 && declaredTypeOf(req.body.contract) === STEEL_V2) {
|
|
78359
|
+
const commitStartedAt = Date.now();
|
|
78124
78360
|
try {
|
|
78125
78361
|
const committed = await runNativeInitialRead({
|
|
78126
78362
|
appId: project.app,
|
|
@@ -78149,6 +78385,16 @@ function registerRevisionRoutes(app, deps = {}) {
|
|
|
78149
78385
|
} : {}
|
|
78150
78386
|
});
|
|
78151
78387
|
const version = listVersions(project.id).find((row) => row.n === committed.versionN);
|
|
78388
|
+
if (committed.readAudit) {
|
|
78389
|
+
logSteelAuditEvent(req.log, {
|
|
78390
|
+
phase: "submit",
|
|
78391
|
+
projectId: project.id,
|
|
78392
|
+
requestId: request.id,
|
|
78393
|
+
outcome: `published-v${committed.versionN}`,
|
|
78394
|
+
startedAt: commitStartedAt,
|
|
78395
|
+
report: committed.readAudit
|
|
78396
|
+
});
|
|
78397
|
+
}
|
|
78152
78398
|
broadcast(contractChangedWithReason(project.app, project.id, committed.etag, committed.storeRevision, "revision-read"));
|
|
78153
78399
|
settleCommittedRevisionRequest(request, committed.versionN, req.log);
|
|
78154
78400
|
if (requiresSteelAudit) {
|
|
@@ -78629,43 +78875,456 @@ function registerRevisionRoutes(app, deps = {}) {
|
|
|
78629
78875
|
);
|
|
78630
78876
|
}
|
|
78631
78877
|
|
|
78632
|
-
//
|
|
78878
|
+
// workspace-approved-snapshot.ts
|
|
78879
|
+
var WorkspaceSnapshotError = class extends Error {
|
|
78880
|
+
constructor(status, message, notReviewable, version) {
|
|
78881
|
+
super(message);
|
|
78882
|
+
this.status = status;
|
|
78883
|
+
this.notReviewable = notReviewable;
|
|
78884
|
+
this.version = version;
|
|
78885
|
+
}
|
|
78886
|
+
status;
|
|
78887
|
+
notReviewable;
|
|
78888
|
+
version;
|
|
78889
|
+
};
|
|
78890
|
+
var NoApprovedVersionError = class extends WorkspaceSnapshotError {
|
|
78891
|
+
constructor() {
|
|
78892
|
+
super(409, "project has no approved version");
|
|
78893
|
+
this.name = "NoApprovedVersionError";
|
|
78894
|
+
}
|
|
78895
|
+
};
|
|
78896
|
+
function approvedRows(projectId) {
|
|
78897
|
+
const project = getProject(projectId);
|
|
78898
|
+
if (!project) return [];
|
|
78899
|
+
const allRows = listVersions(projectId);
|
|
78900
|
+
if (project.uuid) {
|
|
78901
|
+
const tainted = allRows.find((v) => v.gate === "model" && v.kind === "approve" && !v.approval);
|
|
78902
|
+
if (tainted) {
|
|
78903
|
+
throw new WorkspaceSnapshotError(409, `project has no approved version: approved version ${tainted.n} has no approval proof`, void 0, tainted.n);
|
|
78904
|
+
}
|
|
78905
|
+
}
|
|
78906
|
+
const projectTime = Date.parse(project.createdAt);
|
|
78907
|
+
return allRows.filter((v) => v.gate === "model" && v.kind === "approve").filter((v) => v.approval ? !!project.uuid && v.approval.projectUuid === project.uuid : Number.isFinite(projectTime) && Date.parse(v.ts) >= projectTime).map(({ current: _current, ...meta }) => meta);
|
|
78908
|
+
}
|
|
78909
|
+
function latestApprovedVersion(projectId) {
|
|
78910
|
+
return approvedRows(projectId)[0] ?? null;
|
|
78911
|
+
}
|
|
78912
|
+
function listApprovedVersionMetadata(projectId) {
|
|
78913
|
+
return approvedRows(projectId);
|
|
78914
|
+
}
|
|
78915
|
+
function currentApprovedSnapshot(projectId, version) {
|
|
78916
|
+
const project = getProject(projectId);
|
|
78917
|
+
if (!project) throw new WorkspaceSnapshotError(404, `unknown project: ${projectId}`);
|
|
78918
|
+
const rows2 = approvedRows(projectId);
|
|
78919
|
+
const row = version === void 0 ? rows2[0] : rows2.find((v) => v.n === version);
|
|
78920
|
+
if (!row) {
|
|
78921
|
+
if (version === void 0) throw new NoApprovedVersionError();
|
|
78922
|
+
throw new WorkspaceSnapshotError(404, `approved version not found: ${version}`);
|
|
78923
|
+
}
|
|
78924
|
+
const latest = rows2[0];
|
|
78925
|
+
const assertOwned = (candidate, hash3) => {
|
|
78926
|
+
if (candidate.approval) {
|
|
78927
|
+
if (!project.uuid || candidate.approval.projectUuid !== project.uuid) {
|
|
78928
|
+
throw new WorkspaceSnapshotError(409, `approved version ${candidate.n} belongs to another project incarnation`);
|
|
78929
|
+
}
|
|
78930
|
+
if (candidate.approval.candidateHash !== hash3) {
|
|
78931
|
+
throw new WorkspaceSnapshotError(409, `approved version ${candidate.n} failed its content-hash proof`);
|
|
78932
|
+
}
|
|
78933
|
+
return;
|
|
78934
|
+
}
|
|
78935
|
+
const rowTime = Date.parse(candidate.ts);
|
|
78936
|
+
const projectTime = Date.parse(project.createdAt);
|
|
78937
|
+
if (!Number.isFinite(rowTime) || !Number.isFinite(projectTime) || rowTime < projectTime) {
|
|
78938
|
+
throw new WorkspaceSnapshotError(409, `approved version ${candidate.n} has no ownership proof`);
|
|
78939
|
+
}
|
|
78940
|
+
};
|
|
78941
|
+
const contract = readAcceptedVersion(projectId, row.n, { appId: project.app, projectId, operation: "read" });
|
|
78942
|
+
if (contract == null) throw new WorkspaceSnapshotError(409, `approved version ${row.n} is unreadable`);
|
|
78943
|
+
const selectedHash = contractHash(contract);
|
|
78944
|
+
assertOwned(row, selectedHash);
|
|
78945
|
+
const latestContract = latest.n === row.n ? contract : readAcceptedVersion(projectId, latest.n, { appId: project.app, projectId, operation: "read" });
|
|
78946
|
+
if (latestContract == null) throw new WorkspaceSnapshotError(409, `approved version ${latest.n} is unreadable`);
|
|
78947
|
+
const latestHash = contractHash(latestContract);
|
|
78948
|
+
assertOwned(latest, latestHash);
|
|
78949
|
+
const draft = readAcceptedForRequest(project.app, projectId, "read");
|
|
78950
|
+
const comparable = comparableContractHash;
|
|
78951
|
+
const dirtySinceApproval = draft == null || comparable(draft) !== comparable(latestContract);
|
|
78952
|
+
return {
|
|
78953
|
+
project,
|
|
78954
|
+
version: row,
|
|
78955
|
+
contract,
|
|
78956
|
+
contractHash: selectedHash,
|
|
78957
|
+
currentApprovedAt: project.approvedAt ?? null,
|
|
78958
|
+
dirtySinceApproval,
|
|
78959
|
+
latestApprovedVersion: latest.n,
|
|
78960
|
+
headDiverged: row.n !== latest.n
|
|
78961
|
+
};
|
|
78962
|
+
}
|
|
78963
|
+
function approvedSnapshotForMetadata(projectId, surface, onRefusal) {
|
|
78964
|
+
try {
|
|
78965
|
+
return currentApprovedSnapshot(projectId);
|
|
78966
|
+
} catch (error) {
|
|
78967
|
+
if (error instanceof NoApprovedVersionError) return null;
|
|
78968
|
+
if (error instanceof WorkspaceSnapshotError && error.status === 404) throw error;
|
|
78969
|
+
if (error instanceof WorkspaceSnapshotError || error instanceof ContractPolicyError) {
|
|
78970
|
+
const status = error instanceof WorkspaceSnapshotError ? error.status : error.code;
|
|
78971
|
+
onRefusal?.(error);
|
|
78972
|
+
console.error(
|
|
78973
|
+
`${surface}: project ${projectId} has an approved version the gate refused to serve (${status}) \u2014 reporting no approved head. ${error.message}`
|
|
78974
|
+
);
|
|
78975
|
+
return null;
|
|
78976
|
+
}
|
|
78977
|
+
throw error;
|
|
78978
|
+
}
|
|
78979
|
+
}
|
|
78980
|
+
|
|
78981
|
+
// working-revision-manifest.ts
|
|
78633
78982
|
var import_node_crypto32 = require("node:crypto");
|
|
78634
78983
|
var import_node_fs47 = require("node:fs");
|
|
78635
78984
|
var import_node_path42 = require("node:path");
|
|
78985
|
+
var nativePublicationIdentity = (projectUuid) => `project:${projectUuid}`;
|
|
78986
|
+
var pathOf = (projectId) => (0, import_node_path42.join)(projectDir(projectId), ".floless-working-revision-state-v1.json");
|
|
78987
|
+
var checksumOf = (body) => hashOf(body);
|
|
78988
|
+
function bodyOf(value) {
|
|
78989
|
+
const { checksum: _checksum, ...body } = value;
|
|
78990
|
+
return body;
|
|
78991
|
+
}
|
|
78992
|
+
function assertProject(project) {
|
|
78993
|
+
if (!project.uuid) throw new Error(`project ${project.id} has no incarnation UUID`);
|
|
78994
|
+
return project.uuid;
|
|
78995
|
+
}
|
|
78996
|
+
function readWorkingRevisionManifest(project) {
|
|
78997
|
+
const uuid = assertProject(project);
|
|
78998
|
+
try {
|
|
78999
|
+
const value = JSON.parse((0, import_node_fs47.readFileSync)(pathOf(project.id), "utf8"));
|
|
79000
|
+
if (value?.schema !== 1 || value.projectUuid !== uuid || !Number.isInteger(value.epoch) || value.epoch < 0) return null;
|
|
79001
|
+
return checksumOf(bodyOf(value)) === value.checksum ? value : null;
|
|
79002
|
+
} catch {
|
|
79003
|
+
return null;
|
|
79004
|
+
}
|
|
79005
|
+
}
|
|
79006
|
+
function ensureWorkingRevisionManifest(input) {
|
|
79007
|
+
const existing = readWorkingRevisionManifest(input.project);
|
|
79008
|
+
if (existing) return existing;
|
|
79009
|
+
const body = {
|
|
79010
|
+
schema: 1,
|
|
79011
|
+
projectUuid: assertProject(input.project),
|
|
79012
|
+
publicationIdentity: input.publicationIdentity,
|
|
79013
|
+
revisionId: (0, import_node_crypto32.randomUUID)(),
|
|
79014
|
+
epoch: 0,
|
|
79015
|
+
source: { kind: "working" },
|
|
79016
|
+
workingBase: input.workingBase,
|
|
79017
|
+
draftHash: hashOf(input.contract),
|
|
79018
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
79019
|
+
};
|
|
79020
|
+
const value = { ...body, checksum: checksumOf(body) };
|
|
79021
|
+
(0, import_node_fs47.mkdirSync)(projectDir(input.project.id), { recursive: true });
|
|
79022
|
+
if (!(0, import_node_fs47.existsSync)(pathOf(input.project.id))) writeJsonAtomic(pathOf(input.project.id), value);
|
|
79023
|
+
return readWorkingRevisionManifest(input.project) ?? value;
|
|
79024
|
+
}
|
|
79025
|
+
function advanceWorkingRevisionManifest(input) {
|
|
79026
|
+
const current = readWorkingRevisionManifest(input.project);
|
|
79027
|
+
if (!current) throw new Error("working revision state is missing or corrupt");
|
|
79028
|
+
if (current.epoch !== input.expectedEpoch || current.draftHash !== input.expectedDraftHash) {
|
|
79029
|
+
throw new Error("working revision changed; reload before continuing");
|
|
79030
|
+
}
|
|
79031
|
+
if (current.publicationIdentity !== input.publicationIdentity) throw new Error("working revision belongs to another app publication");
|
|
79032
|
+
const body = {
|
|
79033
|
+
...bodyOf(current),
|
|
79034
|
+
revisionId: (0, import_node_crypto32.randomUUID)(),
|
|
79035
|
+
epoch: current.epoch + 1,
|
|
79036
|
+
source: input.source,
|
|
79037
|
+
workingBase: input.workingBase,
|
|
79038
|
+
draftHash: hashOf(input.contract),
|
|
79039
|
+
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
79040
|
+
};
|
|
79041
|
+
const value = { ...body, checksum: checksumOf(body) };
|
|
79042
|
+
writeJsonAtomic(pathOf(input.project.id), value);
|
|
79043
|
+
return value;
|
|
79044
|
+
}
|
|
79045
|
+
function refreshWorkingDraftHash(input) {
|
|
79046
|
+
const current = readWorkingRevisionManifest(input.project);
|
|
79047
|
+
if (!current) throw new Error("working revision state is missing or corrupt");
|
|
79048
|
+
if (current.epoch !== input.expectedEpoch || current.draftHash !== input.expectedDraftHash) {
|
|
79049
|
+
throw new Error("working revision changed; reload before saving");
|
|
79050
|
+
}
|
|
79051
|
+
const body = { ...bodyOf(current), draftHash: hashOf(input.contract), updatedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
79052
|
+
const value = { ...body, checksum: checksumOf(body) };
|
|
79053
|
+
writeJsonAtomic(pathOf(input.project.id), value);
|
|
79054
|
+
return value;
|
|
79055
|
+
}
|
|
79056
|
+
|
|
79057
|
+
// project-checkpoints-store.ts
|
|
79058
|
+
var import_node_crypto33 = require("node:crypto");
|
|
79059
|
+
var import_node_fs48 = require("node:fs");
|
|
79060
|
+
var import_node_path43 = require("node:path");
|
|
79061
|
+
var HASH_RE3 = /^[0-9a-f]{64}$/;
|
|
79062
|
+
function root5(projectId) {
|
|
79063
|
+
return (0, import_node_path43.join)(projectDir(projectId), ".floless-checkpoints-store-v1");
|
|
79064
|
+
}
|
|
79065
|
+
var objectsDir2 = (projectId) => (0, import_node_path43.join)(root5(projectId), "objects");
|
|
79066
|
+
var eventsPath = (projectId) => (0, import_node_path43.join)(root5(projectId), "events.json");
|
|
79067
|
+
function readEvents(projectId) {
|
|
79068
|
+
try {
|
|
79069
|
+
const parsed = JSON.parse((0, import_node_fs48.readFileSync)(eventsPath(projectId), "utf8"));
|
|
79070
|
+
if (parsed?.schema !== 1 || !Array.isArray(parsed.events)) return { schema: 1, events: [] };
|
|
79071
|
+
return { schema: 1, events: parsed.events.filter(validEvent) };
|
|
79072
|
+
} catch {
|
|
79073
|
+
return { schema: 1, events: [] };
|
|
79074
|
+
}
|
|
79075
|
+
}
|
|
79076
|
+
function validEvent(value) {
|
|
79077
|
+
if (!value || typeof value !== "object") return false;
|
|
79078
|
+
const e = value;
|
|
79079
|
+
return typeof e.eventId === "string" && typeof e.checkpointId === "string" && HASH_RE3.test(e.checkpointId) && (e.kind === "captured" || e.kind === "archived" || e.kind === "incorporated") && typeof e.at === "string" && Number.isInteger(e.revisionEpoch) && typeof e.appIdAtCapture === "string";
|
|
79080
|
+
}
|
|
79081
|
+
function readContent(projectId, id) {
|
|
79082
|
+
if (!HASH_RE3.test(id)) return null;
|
|
79083
|
+
try {
|
|
79084
|
+
const value = JSON.parse((0, import_node_fs48.readFileSync)((0, import_node_path43.join)(objectsDir2(projectId), `${id}.json`), "utf8"));
|
|
79085
|
+
if (value?.schema !== 1 || value.id !== id || hashCheckpoint(value) !== id) return null;
|
|
79086
|
+
return value;
|
|
79087
|
+
} catch {
|
|
79088
|
+
return null;
|
|
79089
|
+
}
|
|
79090
|
+
}
|
|
79091
|
+
function hashCheckpoint(value) {
|
|
79092
|
+
const { id: _id, ...identity } = value;
|
|
79093
|
+
return hashOf(identity);
|
|
79094
|
+
}
|
|
79095
|
+
function requireIdentity(project) {
|
|
79096
|
+
if (!project.uuid) throw new Error(`project ${project.id} has no incarnation UUID`);
|
|
79097
|
+
return project.uuid;
|
|
79098
|
+
}
|
|
79099
|
+
function appendEvent(projectId, event) {
|
|
79100
|
+
(0, import_node_fs48.mkdirSync)(root5(projectId), { recursive: true });
|
|
79101
|
+
const log2 = readEvents(projectId);
|
|
79102
|
+
const row = { ...event, eventId: (0, import_node_crypto33.randomUUID)(), at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
79103
|
+
log2.events.push(row);
|
|
79104
|
+
writeJsonAtomic(eventsPath(projectId), log2);
|
|
79105
|
+
return row;
|
|
79106
|
+
}
|
|
79107
|
+
function captureProjectCheckpoint(input) {
|
|
79108
|
+
const projectUuid = requireIdentity(input.project);
|
|
79109
|
+
const withoutId = {
|
|
79110
|
+
schema: 1,
|
|
79111
|
+
projectUuid,
|
|
79112
|
+
publicationIdentity: input.publicationIdentity,
|
|
79113
|
+
base: input.base,
|
|
79114
|
+
draftHash: hashOf(input.contract),
|
|
79115
|
+
contract: input.contract
|
|
79116
|
+
};
|
|
79117
|
+
const id = hashCheckpoint(withoutId);
|
|
79118
|
+
(0, import_node_fs48.mkdirSync)(objectsDir2(input.project.id), { recursive: true });
|
|
79119
|
+
const path = (0, import_node_path43.join)(objectsDir2(input.project.id), `${id}.json`);
|
|
79120
|
+
if (!(0, import_node_fs48.existsSync)(path)) writeJsonAtomic(path, { ...withoutId, id });
|
|
79121
|
+
const event = appendEvent(input.project.id, {
|
|
79122
|
+
checkpointId: id,
|
|
79123
|
+
kind: "captured",
|
|
79124
|
+
revisionEpoch: input.revisionEpoch,
|
|
79125
|
+
appIdAtCapture: input.project.app
|
|
79126
|
+
});
|
|
79127
|
+
return describe(input.project.id, { ...withoutId, id }, event.eventId);
|
|
79128
|
+
}
|
|
79129
|
+
function describe(projectId, content, latestEventId) {
|
|
79130
|
+
const events = readEvents(projectId).events.filter((event) => event.checkpointId === content.id);
|
|
79131
|
+
const captures = events.filter((event) => event.kind === "captured");
|
|
79132
|
+
const first = captures[0];
|
|
79133
|
+
const latest = events.at(-1);
|
|
79134
|
+
if (!first || !latest) return null;
|
|
79135
|
+
return {
|
|
79136
|
+
...content,
|
|
79137
|
+
capturedAt: first.at,
|
|
79138
|
+
archived: latest.kind === "archived",
|
|
79139
|
+
incorporated: events.some((event) => event.kind === "incorporated"),
|
|
79140
|
+
captureCount: captures.length,
|
|
79141
|
+
latestEventId: latestEventId ?? latest.eventId
|
|
79142
|
+
};
|
|
79143
|
+
}
|
|
79144
|
+
function listProjectCheckpoints(project) {
|
|
79145
|
+
const uuid = requireIdentity(project);
|
|
79146
|
+
const ids = [...new Set(readEvents(project.id).events.map((event) => event.checkpointId))];
|
|
79147
|
+
return ids.map((id) => readContent(project.id, id)).filter((v) => v !== null).filter((v) => v.projectUuid === uuid).map((v) => describe(project.id, v)).filter((v) => v !== null).sort((a, b) => b.capturedAt.localeCompare(a.capturedAt));
|
|
79148
|
+
}
|
|
79149
|
+
function readProjectCheckpoint(project, checkpointId) {
|
|
79150
|
+
const content = readContent(project.id, checkpointId);
|
|
79151
|
+
return content && content.projectUuid === requireIdentity(project) ? describe(project.id, content) : null;
|
|
79152
|
+
}
|
|
79153
|
+
function markProjectCheckpoint(project, checkpointId, kind, expectedEventId) {
|
|
79154
|
+
const current = readProjectCheckpoint(project, checkpointId);
|
|
79155
|
+
if (!current) throw new Error(`unknown checkpoint: ${checkpointId}`);
|
|
79156
|
+
if (current.latestEventId !== expectedEventId) throw new Error("checkpoint changed; reload saved work");
|
|
79157
|
+
const event = appendEvent(project.id, { checkpointId, kind, revisionEpoch: 0, appIdAtCapture: project.app });
|
|
79158
|
+
return describe(project.id, current, event.eventId);
|
|
79159
|
+
}
|
|
79160
|
+
|
|
79161
|
+
// project-revision-start-routes.ts
|
|
79162
|
+
function registerProjectRevisionStartRoutes(app, deps) {
|
|
79163
|
+
const { broadcast: broadcast2 } = deps;
|
|
79164
|
+
app.post(
|
|
79165
|
+
"/api/projects/:id/revisions/start",
|
|
79166
|
+
async (req, reply) => {
|
|
79167
|
+
const project = getProject(req.params.id);
|
|
79168
|
+
if (!project?.uuid) return reply.status(project ? 409 : 404).send({ ok: false, error: project ? "project has no incarnation identity" : `unknown project: ${req.params.id}` });
|
|
79169
|
+
const version = Number(req.body?.version);
|
|
79170
|
+
if (!Number.isInteger(version) || version < 1) return reply.status(400).send({ ok: false, error: "choose a valid approved version" });
|
|
79171
|
+
return withLifecycleLock("project", project.id, async () => {
|
|
79172
|
+
let target;
|
|
79173
|
+
try {
|
|
79174
|
+
target = currentApprovedSnapshot(project.id, version);
|
|
79175
|
+
} catch (error) {
|
|
79176
|
+
if (error instanceof WorkspaceSnapshotError) return reply.status(error.status).send({ ok: false, error: error.message });
|
|
79177
|
+
throw error;
|
|
79178
|
+
}
|
|
79179
|
+
const current = readAcceptedForRequest(project.app, project.id, "read");
|
|
79180
|
+
if (current == null) return reply.status(409).send({ ok: false, error: "the current working copy is unreadable" });
|
|
79181
|
+
const actualEtags = storeEtags(project.app, project.id);
|
|
79182
|
+
const suppliedEpoch = req.body && Object.prototype.hasOwnProperty.call(req.body, "expectedEpoch") ? req.body.expectedEpoch : void 0;
|
|
79183
|
+
if (typeof req.body?.expectedEtag !== "string" || suppliedEpoch !== null && (!Number.isInteger(Number(suppliedEpoch)) || Number(suppliedEpoch) < 0)) {
|
|
79184
|
+
return reply.status(428).send({ ok: false, error: "Reload History and send the working ETag and revision epoch." });
|
|
79185
|
+
}
|
|
79186
|
+
if (!recordedEtagNamesContract(req.body.expectedEtag, actualEtags)) {
|
|
79187
|
+
return reply.status(409).send({ ok: false, error: "The working copy changed. Reload History before starting." });
|
|
79188
|
+
}
|
|
79189
|
+
const observedManifest = readWorkingRevisionManifest(project);
|
|
79190
|
+
if ((observedManifest?.epoch ?? null) !== (suppliedEpoch === null ? null : Number(suppliedEpoch))) {
|
|
79191
|
+
return reply.status(409).send({ ok: false, error: "The working revision changed. Reload History before starting." });
|
|
79192
|
+
}
|
|
79193
|
+
const publicationIdentity = observedManifest?.publicationIdentity ?? nativePublicationIdentity(project.uuid);
|
|
79194
|
+
let manifest = ensureWorkingRevisionManifest({
|
|
79195
|
+
project,
|
|
79196
|
+
publicationIdentity,
|
|
79197
|
+
contract: current,
|
|
79198
|
+
workingBase: { version: target.latestApprovedVersion, hash: currentApprovedSnapshot(project.id).contractHash }
|
|
79199
|
+
});
|
|
79200
|
+
if (manifest.draftHash !== contractHash(current)) {
|
|
79201
|
+
manifest = refreshWorkingDraftHash({ project, expectedEpoch: manifest.epoch, expectedDraftHash: manifest.draftHash, contract: current });
|
|
79202
|
+
}
|
|
79203
|
+
const latest = currentApprovedSnapshot(project.id);
|
|
79204
|
+
const dirty = comparableContractHash(current) !== comparableContractHash(latest.contract);
|
|
79205
|
+
const checkpoint = dirty ? captureProjectCheckpoint({
|
|
79206
|
+
project,
|
|
79207
|
+
publicationIdentity,
|
|
79208
|
+
base: manifest.workingBase,
|
|
79209
|
+
contract: current,
|
|
79210
|
+
revisionEpoch: manifest.epoch
|
|
79211
|
+
}) : null;
|
|
79212
|
+
let publication = null;
|
|
79213
|
+
try {
|
|
79214
|
+
const written = await writeContractGenerationChecked(project.app, target.contract, project.id, `start a new revision from approved v${version}`, { restoring: true });
|
|
79215
|
+
publication = written;
|
|
79216
|
+
} catch (error) {
|
|
79217
|
+
if (error instanceof ContractError) return reply.status(409).send({ ok: false, error: error.message });
|
|
79218
|
+
throw error;
|
|
79219
|
+
}
|
|
79220
|
+
clearApproval(project.id);
|
|
79221
|
+
const next = advanceWorkingRevisionManifest({
|
|
79222
|
+
project,
|
|
79223
|
+
expectedEpoch: manifest.epoch,
|
|
79224
|
+
expectedDraftHash: manifest.draftHash,
|
|
79225
|
+
publicationIdentity,
|
|
79226
|
+
contract: normalisePlanViewIds(target.contract),
|
|
79227
|
+
// The PROOFS stay the ledger's raw hashes — `workingBase.hash` is checked against History and
|
|
79228
|
+
// `source.hash` names the version this came from — while `contract:` above is the document the
|
|
79229
|
+
// gateway actually wrote, which is canonical. Hashing raw bytes into `draftHash` for a document
|
|
79230
|
+
// stored canonically made the manifest disagree with the store the instant it was written.
|
|
79231
|
+
source: { kind: "approved", version, hash: target.contractHash },
|
|
79232
|
+
workingBase: { version, hash: target.contractHash }
|
|
79233
|
+
});
|
|
79234
|
+
broadcast2(contractChangedWithReason(project.app, project.id, publication.etag, publication.storeRevision, "rollback"));
|
|
79235
|
+
return {
|
|
79236
|
+
ok: true,
|
|
79237
|
+
checkpoint,
|
|
79238
|
+
revision: next,
|
|
79239
|
+
workingBaseVersion: version,
|
|
79240
|
+
latestApprovedVersion: latest.version.n,
|
|
79241
|
+
message: checkpoint ? `Saved pending work${checkpoint.base ? ` from v${checkpoint.base.version}` : ""}. Started a DRAFT from v${version}.` : `Started a DRAFT from v${version}.`
|
|
79242
|
+
};
|
|
79243
|
+
}, { label: `starting a revision from v${version}` });
|
|
79244
|
+
}
|
|
79245
|
+
);
|
|
79246
|
+
app.post(
|
|
79247
|
+
"/api/projects/:id/checkpoints/:checkpointId/resume",
|
|
79248
|
+
async (req, reply) => {
|
|
79249
|
+
const project = getProject(req.params.id);
|
|
79250
|
+
if (!project?.uuid) return reply.status(project ? 409 : 404).send({ ok: false, error: project ? "project has no incarnation identity" : `unknown project: ${req.params.id}` });
|
|
79251
|
+
return withLifecycleLock("project", project.id, async () => {
|
|
79252
|
+
const saved = readProjectCheckpoint(project, req.params.checkpointId);
|
|
79253
|
+
if (!saved) return reply.status(404).send({ ok: false, error: "checkpoint not found" });
|
|
79254
|
+
const current = readAcceptedForRequest(project.app, project.id, "read");
|
|
79255
|
+
if (current == null) return reply.status(409).send({ ok: false, error: "the current working copy is unreadable" });
|
|
79256
|
+
const suppliedEpoch = req.body && Object.prototype.hasOwnProperty.call(req.body, "expectedEpoch") ? req.body.expectedEpoch : void 0;
|
|
79257
|
+
if (typeof req.body?.expectedEtag !== "string" || suppliedEpoch !== null && (!Number.isInteger(Number(suppliedEpoch)) || Number(suppliedEpoch) < 0)) {
|
|
79258
|
+
return reply.status(428).send({ ok: false, error: "Reload Saved work and send the working ETag and revision epoch." });
|
|
79259
|
+
}
|
|
79260
|
+
if (!recordedEtagNamesContract(req.body.expectedEtag, storeEtags(project.app, project.id))) return reply.status(409).send({ ok: false, error: "The working copy changed. Reload Saved work." });
|
|
79261
|
+
const observedManifest = readWorkingRevisionManifest(project);
|
|
79262
|
+
if ((observedManifest?.epoch ?? null) !== (suppliedEpoch === null ? null : Number(suppliedEpoch))) return reply.status(409).send({ ok: false, error: "The working revision changed. Reload Saved work." });
|
|
79263
|
+
const publicationIdentity = saved.publicationIdentity;
|
|
79264
|
+
let manifest = ensureWorkingRevisionManifest({ project, publicationIdentity, contract: current, workingBase: saved.base });
|
|
79265
|
+
if (manifest.draftHash !== contractHash(current)) manifest = refreshWorkingDraftHash({ project, expectedEpoch: manifest.epoch, expectedDraftHash: manifest.draftHash, contract: current });
|
|
79266
|
+
const latest = approvedSnapshotForMetadata(project.id, "resuming saved work");
|
|
79267
|
+
if (!latest || comparableContractHash(current) !== comparableContractHash(latest.contract)) captureProjectCheckpoint({ project, publicationIdentity, base: manifest.workingBase, contract: current, revisionEpoch: manifest.epoch });
|
|
79268
|
+
let publication;
|
|
79269
|
+
try {
|
|
79270
|
+
publication = await writeContractGenerationChecked(project.app, saved.contract, project.id, "resume an explicitly selected saved-work checkpoint", { restoring: true });
|
|
79271
|
+
} catch (error) {
|
|
79272
|
+
return reply.status(409).send({ ok: false, error: error instanceof Error ? error.message : "checkpoint cannot be resumed" });
|
|
79273
|
+
}
|
|
79274
|
+
clearApproval(project.id);
|
|
79275
|
+
const next = advanceWorkingRevisionManifest({
|
|
79276
|
+
project,
|
|
79277
|
+
expectedEpoch: manifest.epoch,
|
|
79278
|
+
expectedDraftHash: manifest.draftHash,
|
|
79279
|
+
publicationIdentity,
|
|
79280
|
+
contract: normalisePlanViewIds(saved.contract),
|
|
79281
|
+
source: { kind: "checkpoint", checkpointId: saved.id, hash: saved.draftHash },
|
|
79282
|
+
workingBase: saved.base
|
|
79283
|
+
});
|
|
79284
|
+
broadcast2(contractChangedWithReason(project.app, project.id, publication.etag, publication.storeRevision, "rollback"));
|
|
79285
|
+
return { ok: true, revision: next, checkpoint: saved, latestApprovedVersion: latest?.version.n ?? null };
|
|
79286
|
+
}, { label: "resuming saved work" });
|
|
79287
|
+
}
|
|
79288
|
+
);
|
|
79289
|
+
}
|
|
79290
|
+
|
|
79291
|
+
// member-end-resolution-store.ts
|
|
79292
|
+
var import_node_crypto34 = require("node:crypto");
|
|
79293
|
+
var import_node_fs49 = require("node:fs");
|
|
79294
|
+
var import_node_path44 = require("node:path");
|
|
78636
79295
|
var VERSION = 1;
|
|
78637
79296
|
var RETAIN_MAX = 100;
|
|
78638
79297
|
var RETAIN_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
78639
79298
|
var contentHash = (value) => `sha256:${hashOf(value)}`;
|
|
78640
|
-
var storeRoot = (projectId) => (0,
|
|
78641
|
-
var artifactRoot = (projectId) => (0,
|
|
78642
|
-
var registryPath = (projectId) => (0,
|
|
79299
|
+
var storeRoot = (projectId) => (0, import_node_path44.join)(projectDir(projectId), ".member-end-resolution");
|
|
79300
|
+
var artifactRoot = (projectId) => (0, import_node_path44.join)(storeRoot(projectId), "artifacts");
|
|
79301
|
+
var registryPath = (projectId) => (0, import_node_path44.join)(storeRoot(projectId), "tokens.json");
|
|
78643
79302
|
function atomicJson(path, value) {
|
|
78644
|
-
const temp = `${path}.${process.pid}.${(0,
|
|
78645
|
-
(0,
|
|
78646
|
-
(0,
|
|
79303
|
+
const temp = `${path}.${process.pid}.${(0, import_node_crypto34.randomUUID)()}.tmp`;
|
|
79304
|
+
(0, import_node_fs49.writeFileSync)(temp, JSON.stringify(value));
|
|
79305
|
+
(0, import_node_fs49.renameSync)(temp, path);
|
|
78647
79306
|
}
|
|
78648
79307
|
function readRegistry(projectId) {
|
|
78649
79308
|
const path = registryPath(projectId);
|
|
78650
|
-
if (!(0,
|
|
79309
|
+
if (!(0, import_node_fs49.existsSync)(path)) return { version: VERSION, tokens: [] };
|
|
78651
79310
|
try {
|
|
78652
|
-
const value = JSON.parse((0,
|
|
79311
|
+
const value = JSON.parse((0, import_node_fs49.readFileSync)(path, "utf8"));
|
|
78653
79312
|
return value?.version === VERSION && Array.isArray(value.tokens) ? value : { version: VERSION, tokens: [] };
|
|
78654
79313
|
} catch {
|
|
78655
79314
|
return { version: VERSION, tokens: [] };
|
|
78656
79315
|
}
|
|
78657
79316
|
}
|
|
78658
79317
|
function persistRegistry(projectId, registry2) {
|
|
78659
|
-
(0,
|
|
79318
|
+
(0, import_node_fs49.mkdirSync)(storeRoot(projectId), { recursive: true });
|
|
78660
79319
|
const now = Date.now();
|
|
78661
79320
|
const retained = registry2.tokens.filter((record4) => record4.status !== "consumed" || Date.parse(record4.expiresAt) > now).sort((a, b) => Date.parse(b.createdAt) - Date.parse(a.createdAt)).slice(0, RETAIN_MAX);
|
|
78662
79321
|
atomicJson(registryPath(projectId), { version: VERSION, tokens: retained });
|
|
78663
79322
|
const referenced = new Set(retained.filter((record4) => record4.status !== "consumed" && Date.parse(record4.expiresAt) > now).map((record4) => `${record4.targetArtifact.slice(7)}.json`));
|
|
78664
79323
|
const artifacts = artifactRoot(projectId);
|
|
78665
|
-
if ((0,
|
|
78666
|
-
for (const entry2 of (0,
|
|
79324
|
+
if ((0, import_node_fs49.existsSync)(artifacts)) {
|
|
79325
|
+
for (const entry2 of (0, import_node_fs49.readdirSync)(artifacts, { withFileTypes: true })) {
|
|
78667
79326
|
if (entry2.isFile() && /^[a-f0-9]{64}\.json$/.test(entry2.name) && !referenced.has(entry2.name)) {
|
|
78668
|
-
(0,
|
|
79327
|
+
(0, import_node_fs49.rmSync)((0, import_node_path44.join)(artifacts, entry2.name));
|
|
78669
79328
|
}
|
|
78670
79329
|
}
|
|
78671
79330
|
}
|
|
@@ -78673,14 +79332,14 @@ function persistRegistry(projectId, registry2) {
|
|
|
78673
79332
|
function persistArtifact(projectId, contract) {
|
|
78674
79333
|
const hash3 = contentHash(contract);
|
|
78675
79334
|
const root6 = artifactRoot(projectId);
|
|
78676
|
-
(0,
|
|
78677
|
-
const path = (0,
|
|
78678
|
-
if (!(0,
|
|
79335
|
+
(0, import_node_fs49.mkdirSync)(root6, { recursive: true });
|
|
79336
|
+
const path = (0, import_node_path44.join)(root6, `${hash3.slice(7)}.json`);
|
|
79337
|
+
if (!(0, import_node_fs49.existsSync)(path)) atomicJson(path, { hash: hash3, contract });
|
|
78679
79338
|
return hash3;
|
|
78680
79339
|
}
|
|
78681
79340
|
function readArtifact(projectId, hash3) {
|
|
78682
|
-
const path = (0,
|
|
78683
|
-
const value = JSON.parse((0,
|
|
79341
|
+
const path = (0, import_node_path44.join)(artifactRoot(projectId), `${hash3.slice(7)}.json`);
|
|
79342
|
+
const value = JSON.parse((0, import_node_fs49.readFileSync)(path, "utf8"));
|
|
78684
79343
|
if (value?.hash !== hash3 || contentHash(value.contract) !== hash3) throw new Error("member-end undo artifact failed its content hash");
|
|
78685
79344
|
return value.contract;
|
|
78686
79345
|
}
|
|
@@ -78690,8 +79349,8 @@ function stageResolutionToken(projectId, expectedContract, targetContract, direc
|
|
|
78690
79349
|
const targetArtifact = persistArtifact(projectId, targetContract);
|
|
78691
79350
|
const record4 = {
|
|
78692
79351
|
version: VERSION,
|
|
78693
|
-
token: (0,
|
|
78694
|
-
operationId: (0,
|
|
79352
|
+
token: (0, import_node_crypto34.randomUUID)(),
|
|
79353
|
+
operationId: (0, import_node_crypto34.randomUUID)(),
|
|
78695
79354
|
direction,
|
|
78696
79355
|
expectedHash: contentHash(expectedContract),
|
|
78697
79356
|
targetHash: targetArtifact,
|
|
@@ -79188,38 +79847,13 @@ function registerConnectionRoutes(app) {
|
|
|
79188
79847
|
registerReviewVerb(app, "untrack", "/api/projects/:id/connections/:jointId/untrack");
|
|
79189
79848
|
}
|
|
79190
79849
|
|
|
79191
|
-
// steel-intersection-ref.ts
|
|
79192
|
-
var axisId = (v) => {
|
|
79193
|
-
if (typeof v !== "string") return null;
|
|
79194
|
-
const t = v.trim();
|
|
79195
|
-
return t.length > 0 ? t : null;
|
|
79196
|
-
};
|
|
79197
|
-
var isObj7 = (v) => typeof v === "object" && v !== null && !Array.isArray(v);
|
|
79198
|
-
function intersectionRef(v) {
|
|
79199
|
-
if (v === void 0 || v === null) return { state: "absent" };
|
|
79200
|
-
if (isObj7(v)) {
|
|
79201
|
-
const unknown = Object.keys(v).filter((k) => k !== "xAxisId" && k !== "yAxisId");
|
|
79202
|
-
if (unknown.length) {
|
|
79203
|
-
return { state: "invalid", why: `an intersection has only \`xAxisId\` and \`yAxisId\` \u2014 ${unknown.map((k) => `\`${k}\``).join(", ")} ${unknown.length > 1 ? "are" : "is"} not recognised${unknown.some((k) => k === "axis_x" || k === "axis_y") ? "; registration names grid axis IDS now, never labels" : ""}` };
|
|
79204
|
-
}
|
|
79205
|
-
const x = axisId(v.xAxisId), y = axisId(v.yAxisId);
|
|
79206
|
-
if (x && y) return { state: "valid", x, y };
|
|
79207
|
-
const missing = [!x ? "xAxisId" : null, !y ? "yAxisId" : null].filter(Boolean).join(" and ");
|
|
79208
|
-
return { state: "invalid", why: `${missing} must each be a non-blank grid axis id` };
|
|
79209
|
-
}
|
|
79210
|
-
return { state: "invalid", why: `a ${Array.isArray(v) ? "list" : typeof v} names no grid intersection; expected { xAxisId, yAxisId }` };
|
|
79211
|
-
}
|
|
79212
|
-
function canonicalRef(r) {
|
|
79213
|
-
return { xAxisId: r.x, yAxisId: r.y };
|
|
79214
|
-
}
|
|
79215
|
-
|
|
79216
79850
|
// steel-prepass-route.ts
|
|
79217
79851
|
var ROOT_KEYS = ["filter"];
|
|
79218
79852
|
var PLAN_KEYS = ["datum_at", "datum_ref", "control2_at", "control2_ref", "elevation_in"];
|
|
79219
|
-
var
|
|
79853
|
+
var isObj9 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
79220
79854
|
function filterSheetsOf(doc) {
|
|
79221
|
-
const filter =
|
|
79222
|
-
return filter && Array.isArray(filter.sheets) ? filter.sheets.filter(
|
|
79855
|
+
const filter = isObj9(doc.filter) ? doc.filter : null;
|
|
79856
|
+
return filter && Array.isArray(filter.sheets) ? filter.sheets.filter(isObj9) : [];
|
|
79223
79857
|
}
|
|
79224
79858
|
function registerSteelPrepassRoute(app, deps) {
|
|
79225
79859
|
app.put("/api/projects/:id/steel-prepass", { bodyLimit: STEEL_CONTRACT_BODY_LIMIT_BYTES }, async (req, reply) => {
|
|
@@ -79233,7 +79867,7 @@ function registerSteelPrepassRoute(app, deps) {
|
|
|
79233
79867
|
error: "Reload the Drawing Filter and send its exact ETag before saving."
|
|
79234
79868
|
});
|
|
79235
79869
|
}
|
|
79236
|
-
if (!
|
|
79870
|
+
if (!isObj9(req.body)) return reply.status(400).send({ ok: false, error: "body must be an object" });
|
|
79237
79871
|
const body = req.body;
|
|
79238
79872
|
const unknownRoot = Object.keys(body).filter((key2) => ![...ROOT_KEYS, "sheets", "requestId"].includes(key2));
|
|
79239
79873
|
if (unknownRoot.length) {
|
|
@@ -79243,12 +79877,12 @@ function registerSteelPrepassRoute(app, deps) {
|
|
|
79243
79877
|
error: `Drawing Filter pre-read cannot write ${unknownRoot.map((key2) => `\`${key2}\``).join(", ")}. Members and model geometry go through the drawing-read review.`
|
|
79244
79878
|
});
|
|
79245
79879
|
}
|
|
79246
|
-
if (body.sheets !== void 0 && !
|
|
79880
|
+
if (body.sheets !== void 0 && !isObj9(body.sheets)) {
|
|
79247
79881
|
return reply.status(400).send({ ok: false, error: "`sheets` must be an object keyed by sheet name" });
|
|
79248
79882
|
}
|
|
79249
|
-
const sheets =
|
|
79883
|
+
const sheets = isObj9(body.sheets) ? body.sheets : {};
|
|
79250
79884
|
for (const [sheet, patch2] of Object.entries(sheets)) {
|
|
79251
|
-
if (!
|
|
79885
|
+
if (!isObj9(patch2)) return reply.status(400).send({ ok: false, error: `sheets["${sheet}"] must be an object` });
|
|
79252
79886
|
const unknown = Object.keys(patch2).filter((key2) => !PLAN_KEYS.includes(key2));
|
|
79253
79887
|
if (unknown.length) {
|
|
79254
79888
|
return reply.status(400).send({
|
|
@@ -79270,7 +79904,7 @@ function registerSteelPrepassRoute(app, deps) {
|
|
|
79270
79904
|
return reply.status(400).send({ ok: false, code: "prepass-not-steel", error: `this project does not hold a ${STEEL_V2} document` });
|
|
79271
79905
|
}
|
|
79272
79906
|
let doc = structuredClone(current);
|
|
79273
|
-
const plans = Array.isArray(doc.plans) ? doc.plans.filter(
|
|
79907
|
+
const plans = Array.isArray(doc.plans) ? doc.plans.filter(isObj9) : [];
|
|
79274
79908
|
const names2 = plans.map((plan) => rawPlanViewId(plan) ?? "");
|
|
79275
79909
|
const missing = Object.keys(sheets).filter((sheet) => !names2.includes(sheet));
|
|
79276
79910
|
if (missing.length) return reply.status(400).send({ ok: false, code: "prepass-unknown-sheet", error: `unknown drawing view: ${missing.join(", ")}` });
|
|
@@ -79287,7 +79921,7 @@ function registerSteelPrepassRoute(app, deps) {
|
|
|
79287
79921
|
const sheet = rawPlanViewId(plan) ?? "";
|
|
79288
79922
|
const viewName = viewLabels.get(sheet) ?? sheet;
|
|
79289
79923
|
const patch2 = sheets[sheet];
|
|
79290
|
-
if (!
|
|
79924
|
+
if (!isObj9(patch2)) continue;
|
|
79291
79925
|
if (plan.viewKind !== "plan" && PLAN_KEYS.some((key2) => patch2[key2] !== void 0)) {
|
|
79292
79926
|
return reply.status(400).send({
|
|
79293
79927
|
ok: false,
|
|
@@ -79299,7 +79933,7 @@ function registerSteelPrepassRoute(app, deps) {
|
|
|
79299
79933
|
if (patch2[key2] === void 0) continue;
|
|
79300
79934
|
if (key2 === "datum_ref" || key2 === "control2_ref") {
|
|
79301
79935
|
const parsed = intersectionRef(patch2[key2]);
|
|
79302
|
-
if (parsed.state !== "valid" || !
|
|
79936
|
+
if (parsed.state !== "valid" || !isObj9(patch2[key2])) {
|
|
79303
79937
|
refErrors.push(`sheets["${sheet}"].${key2}`);
|
|
79304
79938
|
continue;
|
|
79305
79939
|
}
|
|
@@ -79377,8 +80011,8 @@ function registerSteelPrepassRoute(app, deps) {
|
|
|
79377
80011
|
}
|
|
79378
80012
|
|
|
79379
80013
|
// reference-routes.ts
|
|
79380
|
-
var
|
|
79381
|
-
var
|
|
80014
|
+
var import_node_crypto37 = require("node:crypto");
|
|
80015
|
+
var import_node_fs52 = require("node:fs");
|
|
79382
80016
|
|
|
79383
80017
|
// reference-import.ts
|
|
79384
80018
|
var AGENT2 = "ifc-reference-reader";
|
|
@@ -79887,14 +80521,14 @@ async function readReferenceModel(companionId, ifcPath, opts = {}) {
|
|
|
79887
80521
|
}
|
|
79888
80522
|
|
|
79889
80523
|
// reference-progress.ts
|
|
79890
|
-
var
|
|
80524
|
+
var import_node_crypto35 = require("node:crypto");
|
|
79891
80525
|
var MAX_BUFFER_BYTES = 8 * 1024 * 1024;
|
|
79892
80526
|
var SESSION_TTL_MS = 10 * 6e4;
|
|
79893
80527
|
var UNCLAIMED_TTL_MS = 2 * 6e4;
|
|
79894
80528
|
var SWEEP_MS = 3e4;
|
|
79895
80529
|
var sessions = /* @__PURE__ */ new Map();
|
|
79896
80530
|
function createProgressSession(appId, project) {
|
|
79897
|
-
const id = (0,
|
|
80531
|
+
const id = (0, import_node_crypto35.randomUUID)();
|
|
79898
80532
|
sessions.set(id, {
|
|
79899
80533
|
id,
|
|
79900
80534
|
appId,
|
|
@@ -80005,15 +80639,15 @@ var sweep = setInterval(() => {
|
|
|
80005
80639
|
sweep.unref?.();
|
|
80006
80640
|
|
|
80007
80641
|
// reference-store.ts
|
|
80008
|
-
var
|
|
80009
|
-
var
|
|
80642
|
+
var import_node_crypto36 = require("node:crypto");
|
|
80643
|
+
var import_node_fs51 = require("node:fs");
|
|
80010
80644
|
var import_promises4 = require("node:fs/promises");
|
|
80011
80645
|
var import_promises5 = require("node:stream/promises");
|
|
80012
|
-
var
|
|
80646
|
+
var import_node_path45 = require("node:path");
|
|
80013
80647
|
|
|
80014
80648
|
// reference-binary.ts
|
|
80015
80649
|
var import_node_zlib = require("node:zlib");
|
|
80016
|
-
var
|
|
80650
|
+
var import_node_fs50 = require("node:fs");
|
|
80017
80651
|
var import_node_util4 = require("node:util");
|
|
80018
80652
|
var REFERENCE_BINARY_TYPE = "application/vnd.floless.reference-geometry-v7";
|
|
80019
80653
|
var REFERENCE_BINARY_HEADER_BYTES = 192;
|
|
@@ -80159,14 +80793,14 @@ async function encodeReferenceBinaryAsync(cache2) {
|
|
|
80159
80793
|
}
|
|
80160
80794
|
function readReferenceBinaryHandleManifest(fd2, actualSize) {
|
|
80161
80795
|
const header = Buffer.alloc(REFERENCE_BINARY_HEADER_BYTES);
|
|
80162
|
-
if ((0,
|
|
80796
|
+
if ((0, import_node_fs50.readSync)(fd2, header, 0, header.length, 0) !== header.length || !header.subarray(0, 8).equals(MAGIC)) throw new Error("not a reference binary");
|
|
80163
80797
|
if (header.readUInt32LE(8) !== 7 || header.readUInt32LE(12) !== REFERENCE_BINARY_HEADER_BYTES) throw new Error("unsupported reference binary version");
|
|
80164
80798
|
const total = get64(header, 16);
|
|
80165
80799
|
if (total !== actualSize || total > MAX_FILE) throw new Error("reference binary length mismatch");
|
|
80166
80800
|
const offset = get64(header, 24), length2 = get64(header, 32);
|
|
80167
80801
|
if (offset % 8 || length2 > MAX_META || offset + length2 > total) throw new Error("invalid manifest section");
|
|
80168
80802
|
const manifest = Buffer.alloc(length2);
|
|
80169
|
-
if ((0,
|
|
80803
|
+
if ((0, import_node_fs50.readSync)(fd2, manifest, 0, length2, offset) !== length2 || referenceCrc32(manifest) !== header.readUInt32LE(40)) throw new Error("manifest checksum mismatch");
|
|
80170
80804
|
const parsed = JSON.parse(manifest.toString("utf8"));
|
|
80171
80805
|
if (!Number.isInteger(parsed.v) || typeof parsed.sourceHash !== "string") throw new Error("reference manifest is incomplete");
|
|
80172
80806
|
return { v: parsed.v, sourceHash: parsed.sourceHash, filter: parsed.filter ?? null };
|
|
@@ -80181,70 +80815,70 @@ function insideProject(projectId, relPath) {
|
|
|
80181
80815
|
throw new ReferenceImportError("that reference does not name one of its own files, so it cannot be read or removed");
|
|
80182
80816
|
}
|
|
80183
80817
|
const root6 = realish(projectDir(projectId));
|
|
80184
|
-
const abs = (0,
|
|
80185
|
-
if (realish((0,
|
|
80818
|
+
const abs = (0, import_node_path45.resolve)(root6, REFERENCE_DIR, name);
|
|
80819
|
+
if (realish((0, import_node_path45.join)(root6, REFERENCE_DIR)) !== (0, import_node_path45.resolve)(root6, REFERENCE_DIR)) {
|
|
80186
80820
|
throw new ReferenceImportError("this project\u2019s references folder is a link to somewhere else, so it will not be written to");
|
|
80187
80821
|
}
|
|
80188
|
-
if (!abs.startsWith(root6 +
|
|
80822
|
+
if (!abs.startsWith(root6 + import_node_path45.sep)) {
|
|
80189
80823
|
throw new ReferenceImportError("that reference points outside its project, so it cannot be read or removed");
|
|
80190
80824
|
}
|
|
80191
80825
|
return abs;
|
|
80192
80826
|
}
|
|
80193
80827
|
function realish(p) {
|
|
80194
80828
|
try {
|
|
80195
|
-
return
|
|
80829
|
+
return import_node_fs51.realpathSync.native((0, import_node_path45.resolve)(p));
|
|
80196
80830
|
} catch {
|
|
80197
|
-
return (0,
|
|
80831
|
+
return (0, import_node_path45.resolve)(p);
|
|
80198
80832
|
}
|
|
80199
80833
|
}
|
|
80200
80834
|
var REFERENCE_CACHE_VERSION = 7;
|
|
80201
|
-
var legacyJsonCachePath = (projectId, refId2) => (0,
|
|
80835
|
+
var legacyJsonCachePath = (projectId, refId2) => (0, import_node_path45.join)(projectDir(projectId), `.floless-refcache-${safeId2(refId2)}.json`);
|
|
80202
80836
|
var binaryCachePrefix = (refId2) => `.floless-refcache-${safeId2(refId2)}-`;
|
|
80203
80837
|
var cacheGenerationSequence = 0;
|
|
80204
80838
|
var activePendingCacheGenerations = /* @__PURE__ */ new Set();
|
|
80205
80839
|
var cachePruneTimers = /* @__PURE__ */ new Map();
|
|
80206
80840
|
var CACHE_PENDING_TTL_MS = 10 * 6e4;
|
|
80207
80841
|
var binaryCachePath = (projectId, refId2, sourceHash, filter, version = REFERENCE_CACHE_VERSION) => {
|
|
80208
|
-
const key2 = (0,
|
|
80209
|
-
return (0,
|
|
80842
|
+
const key2 = (0, import_node_crypto36.createHash)("sha256").update(String(version)).update("\0").update(sourceHash).update("\0").update(filterKey(filter) ?? "").digest("hex").slice(0, 20);
|
|
80843
|
+
return (0, import_node_path45.join)(projectDir(projectId), `${binaryCachePrefix(refId2)}${key2}.bin`);
|
|
80210
80844
|
};
|
|
80211
|
-
var legacyBinaryCachePath = (projectId, refId2) => (0,
|
|
80212
|
-
var cacheCurrentPath = (projectId, refId2) => (0,
|
|
80845
|
+
var legacyBinaryCachePath = (projectId, refId2) => (0, import_node_path45.join)(projectDir(projectId), `.floless-refcache-${safeId2(refId2)}.bin`);
|
|
80846
|
+
var cacheCurrentPath = (projectId, refId2) => (0, import_node_path45.join)(projectDir(projectId), `${binaryCachePrefix(refId2)}current`);
|
|
80213
80847
|
function currentCacheGeneration(projectId, refId2) {
|
|
80214
80848
|
const pointer = cacheCurrentPath(projectId, refId2);
|
|
80215
|
-
if (!(0,
|
|
80849
|
+
if (!(0, import_node_fs51.existsSync)(pointer)) return null;
|
|
80216
80850
|
try {
|
|
80217
|
-
const name = (0,
|
|
80218
|
-
if (!name || (0,
|
|
80219
|
-
return cacheGenerationTarget(projectId, refId2, (0,
|
|
80851
|
+
const name = (0, import_node_fs51.readFileSync)(pointer, "utf8").trim();
|
|
80852
|
+
if (!name || (0, import_node_path45.basename)(name) !== name) return null;
|
|
80853
|
+
return cacheGenerationTarget(projectId, refId2, (0, import_node_path45.join)(projectDir(projectId), name), [".bin"]);
|
|
80220
80854
|
} catch {
|
|
80221
80855
|
return null;
|
|
80222
80856
|
}
|
|
80223
80857
|
}
|
|
80224
80858
|
function publishCurrentCacheGeneration(projectId, refId2, generationName) {
|
|
80225
80859
|
const pointer = cacheCurrentPath(projectId, refId2);
|
|
80226
|
-
const pending = `${pointer}.${process.pid}.${(0,
|
|
80860
|
+
const pending = `${pointer}.${process.pid}.${(0, import_node_crypto36.randomUUID)()}.part`;
|
|
80227
80861
|
try {
|
|
80228
|
-
(0,
|
|
80229
|
-
(0,
|
|
80862
|
+
(0, import_node_fs51.writeFileSync)(pending, generationName, "utf8");
|
|
80863
|
+
(0, import_node_fs51.renameSync)(pending, pointer);
|
|
80230
80864
|
} finally {
|
|
80231
|
-
(0,
|
|
80865
|
+
(0, import_node_fs51.rmSync)(pending, { force: true });
|
|
80232
80866
|
}
|
|
80233
80867
|
}
|
|
80234
80868
|
function binaryCacheCandidates(projectId, refId2, sourceHash, filter) {
|
|
80235
80869
|
collectStalePendingCacheGenerations(projectId, refId2);
|
|
80236
|
-
if ((0,
|
|
80870
|
+
if ((0, import_node_fs51.existsSync)(cacheCurrentPath(projectId, refId2))) {
|
|
80237
80871
|
const current = currentCacheGeneration(projectId, refId2);
|
|
80238
80872
|
if (current) sweepExpiredCacheGenerations(projectId, refId2, current);
|
|
80239
80873
|
return current ? [current] : [];
|
|
80240
80874
|
}
|
|
80241
80875
|
const exact = binaryCachePath(projectId, refId2, sourceHash, filter);
|
|
80242
|
-
const generationPrefix = (0,
|
|
80876
|
+
const generationPrefix = (0, import_node_path45.basename)(exact, ".bin") + "-";
|
|
80243
80877
|
let generated = [];
|
|
80244
80878
|
try {
|
|
80245
|
-
generated = (0,
|
|
80879
|
+
generated = (0, import_node_fs51.readdirSync)(projectDir(projectId)).filter((name) => name.startsWith(generationPrefix) && name.endsWith(".bin")).map((name) => (0, import_node_path45.join)(projectDir(projectId), name)).sort((a, b) => {
|
|
80246
80880
|
try {
|
|
80247
|
-
return (0,
|
|
80881
|
+
return (0, import_node_fs51.statSync)(b).mtimeMs - (0, import_node_fs51.statSync)(a).mtimeMs || (0, import_node_path45.basename)(b).localeCompare((0, import_node_path45.basename)(a));
|
|
80248
80882
|
} catch {
|
|
80249
80883
|
return 0;
|
|
80250
80884
|
}
|
|
@@ -80257,13 +80891,13 @@ function binaryCacheCandidates(projectId, refId2, sourceHash, filter) {
|
|
|
80257
80891
|
function sweepExpiredCacheGenerations(projectId, refId2, preserve) {
|
|
80258
80892
|
const staleBefore = Date.now() - CACHE_PENDING_TTL_MS;
|
|
80259
80893
|
try {
|
|
80260
|
-
for (const name of (0,
|
|
80894
|
+
for (const name of (0, import_node_fs51.readdirSync)(projectDir(projectId))) {
|
|
80261
80895
|
if (!name.startsWith(binaryCachePrefix(refId2)) || !name.endsWith(".bin") && !name.endsWith(".pending")) continue;
|
|
80262
|
-
const candidate = (0,
|
|
80263
|
-
if ((0,
|
|
80264
|
-
if (activePendingCacheGenerations.has((0,
|
|
80896
|
+
const candidate = (0, import_node_path45.join)(projectDir(projectId), name);
|
|
80897
|
+
if ((0, import_node_path45.resolve)(candidate) === (0, import_node_path45.resolve)(preserve)) continue;
|
|
80898
|
+
if (activePendingCacheGenerations.has((0, import_node_path45.resolve)(candidate))) continue;
|
|
80265
80899
|
try {
|
|
80266
|
-
if ((0,
|
|
80900
|
+
if ((0, import_node_fs51.statSync)(candidate).mtimeMs < staleBefore) (0, import_node_fs51.rmSync)(candidate, { force: true });
|
|
80267
80901
|
} catch {
|
|
80268
80902
|
}
|
|
80269
80903
|
}
|
|
@@ -80276,21 +80910,21 @@ function safeId2(refId2) {
|
|
|
80276
80910
|
return s;
|
|
80277
80911
|
}
|
|
80278
80912
|
async function hashFile(path) {
|
|
80279
|
-
const h = (0,
|
|
80280
|
-
await (0, import_promises5.pipeline)((0,
|
|
80913
|
+
const h = (0, import_node_crypto36.createHash)("sha256");
|
|
80914
|
+
await (0, import_promises5.pipeline)((0, import_node_fs51.createReadStream)(path), h);
|
|
80281
80915
|
return h.digest("hex");
|
|
80282
80916
|
}
|
|
80283
80917
|
function copyOriginal(projectId, relPath, sourceAbs, tag) {
|
|
80284
80918
|
const abs = insideProject(projectId, relPath);
|
|
80285
|
-
(0,
|
|
80919
|
+
(0, import_node_fs51.mkdirSync)((0, import_node_path45.dirname)(abs), { recursive: true });
|
|
80286
80920
|
const tmp = `${abs}.${safeId2(tag)}.part`;
|
|
80287
|
-
(0,
|
|
80288
|
-
(0,
|
|
80921
|
+
(0, import_node_fs51.copyFileSync)(sourceAbs, tmp);
|
|
80922
|
+
(0, import_node_fs51.renameSync)(tmp, abs);
|
|
80289
80923
|
return abs;
|
|
80290
80924
|
}
|
|
80291
80925
|
function referenceFilesOnDisk(projectId) {
|
|
80292
80926
|
try {
|
|
80293
|
-
return (0,
|
|
80927
|
+
return (0, import_node_fs51.readdirSync)((0, import_node_path45.join)(projectDir(projectId), REFERENCE_DIR)).map((f) => `${REFERENCE_DIR}/${f}`);
|
|
80294
80928
|
} catch (e) {
|
|
80295
80929
|
if (e.code === "ENOENT") return [];
|
|
80296
80930
|
throw new ReferenceImportError(
|
|
@@ -80300,16 +80934,16 @@ function referenceFilesOnDisk(projectId) {
|
|
|
80300
80934
|
}
|
|
80301
80935
|
function originalPath(projectId, relPath) {
|
|
80302
80936
|
const abs = insideProject(projectId, relPath);
|
|
80303
|
-
return (0,
|
|
80937
|
+
return (0, import_node_fs51.existsSync)(abs) ? abs : null;
|
|
80304
80938
|
}
|
|
80305
80939
|
async function writeCache2(projectId, refId2, cache2, options = {}) {
|
|
80306
80940
|
collectStalePendingCacheGenerations(projectId, refId2);
|
|
80307
80941
|
const binary = binaryCachePath(projectId, refId2, cache2.sourceHash, cache2.filter, cache2.v);
|
|
80308
80942
|
const sequence = (++cacheGenerationSequence).toString(36).padStart(8, "0");
|
|
80309
80943
|
const suffix = options.staged ? ".pending" : ".bin";
|
|
80310
|
-
const generation = `${binary.slice(0, -4)}-${Date.now().toString(36)}-${sequence}-${(0,
|
|
80944
|
+
const generation = `${binary.slice(0, -4)}-${Date.now().toString(36)}-${sequence}-${(0, import_node_crypto36.randomUUID)()}${suffix}`;
|
|
80311
80945
|
const binaryTmp = `${generation}.${process.pid}.part`;
|
|
80312
|
-
const pendingToken = options.staged ? (0,
|
|
80946
|
+
const pendingToken = options.staged ? (0, import_node_path45.resolve)(generation) : null;
|
|
80313
80947
|
if (pendingToken) activePendingCacheGenerations.add(pendingToken);
|
|
80314
80948
|
let encoded;
|
|
80315
80949
|
try {
|
|
@@ -80331,10 +80965,10 @@ async function writeCache2(projectId, refId2, cache2, options = {}) {
|
|
|
80331
80965
|
return generation;
|
|
80332
80966
|
}
|
|
80333
80967
|
function cacheGenerationTarget(projectId, refId2, path, suffixes) {
|
|
80334
|
-
const root6 = (0,
|
|
80335
|
-
const target = (0,
|
|
80336
|
-
const name = (0,
|
|
80337
|
-
if ((0,
|
|
80968
|
+
const root6 = (0, import_node_path45.resolve)(projectDir(projectId));
|
|
80969
|
+
const target = (0, import_node_path45.resolve)(path);
|
|
80970
|
+
const name = (0, import_node_path45.basename)(target);
|
|
80971
|
+
if ((0, import_node_path45.dirname)(target) !== root6 || !name.startsWith(binaryCachePrefix(refId2)) || !suffixes.some((suffix) => name.endsWith(suffix))) {
|
|
80338
80972
|
throw new ReferenceImportError("that reference cache generation cannot be changed safely");
|
|
80339
80973
|
}
|
|
80340
80974
|
return target;
|
|
@@ -80342,24 +80976,24 @@ function cacheGenerationTarget(projectId, refId2, path, suffixes) {
|
|
|
80342
80976
|
function commitCacheGeneration(projectId, refId2, pendingPath) {
|
|
80343
80977
|
const pending = cacheGenerationTarget(projectId, refId2, pendingPath, [".pending"]);
|
|
80344
80978
|
const committed = `${pending.slice(0, -".pending".length)}.bin`;
|
|
80345
|
-
(0,
|
|
80979
|
+
(0, import_node_fs51.renameSync)(pending, committed);
|
|
80346
80980
|
activePendingCacheGenerations.delete(pending);
|
|
80347
80981
|
return committed;
|
|
80348
80982
|
}
|
|
80349
80983
|
function removeCacheGeneration(projectId, refId2, path) {
|
|
80350
80984
|
const target = cacheGenerationTarget(projectId, refId2, path, [".bin", ".pending"]);
|
|
80351
80985
|
activePendingCacheGenerations.delete(target);
|
|
80352
|
-
(0,
|
|
80986
|
+
(0, import_node_fs51.rmSync)(target, { force: true });
|
|
80353
80987
|
}
|
|
80354
80988
|
function collectStalePendingCacheGenerations(projectId, refId2) {
|
|
80355
80989
|
const staleBefore = Date.now() - CACHE_PENDING_TTL_MS;
|
|
80356
80990
|
try {
|
|
80357
|
-
for (const name of (0,
|
|
80991
|
+
for (const name of (0, import_node_fs51.readdirSync)(projectDir(projectId))) {
|
|
80358
80992
|
if (!name.startsWith(binaryCachePrefix(refId2)) || !name.endsWith(".pending")) continue;
|
|
80359
|
-
const candidate = (0,
|
|
80993
|
+
const candidate = (0, import_node_path45.resolve)((0, import_node_path45.join)(projectDir(projectId), name));
|
|
80360
80994
|
if (activePendingCacheGenerations.has(candidate)) continue;
|
|
80361
80995
|
try {
|
|
80362
|
-
if ((0,
|
|
80996
|
+
if ((0, import_node_fs51.statSync)(candidate).mtimeMs < staleBefore) (0, import_node_fs51.rmSync)(candidate, { force: true });
|
|
80363
80997
|
} catch {
|
|
80364
80998
|
}
|
|
80365
80999
|
}
|
|
@@ -80369,21 +81003,21 @@ function collectStalePendingCacheGenerations(projectId, refId2) {
|
|
|
80369
81003
|
}
|
|
80370
81004
|
}
|
|
80371
81005
|
function pruneCache(projectId, refId2, committedGeneration, options = {}) {
|
|
80372
|
-
const root6 = (0,
|
|
80373
|
-
const preserve = (0,
|
|
80374
|
-
const preserveName = (0,
|
|
80375
|
-
if ((0,
|
|
81006
|
+
const root6 = (0, import_node_path45.resolve)(projectDir(projectId));
|
|
81007
|
+
const preserve = (0, import_node_path45.resolve)(committedGeneration);
|
|
81008
|
+
const preserveName = (0, import_node_path45.basename)(preserve);
|
|
81009
|
+
if ((0, import_node_path45.dirname)(preserve) !== root6 || !preserveName.startsWith(binaryCachePrefix(refId2)) || !preserveName.endsWith(".bin") || !(0, import_node_fs51.existsSync)(preserve)) {
|
|
80376
81010
|
throw new Error("the committed reference cache generation is unavailable");
|
|
80377
81011
|
}
|
|
80378
81012
|
try {
|
|
80379
|
-
publishCurrentCacheGeneration(projectId, refId2, (0,
|
|
81013
|
+
publishCurrentCacheGeneration(projectId, refId2, (0, import_node_path45.basename)(preserve));
|
|
80380
81014
|
} catch (error) {
|
|
80381
|
-
(0,
|
|
81015
|
+
(0, import_node_fs51.rmSync)(preserve, { force: true });
|
|
80382
81016
|
throw error;
|
|
80383
81017
|
}
|
|
80384
81018
|
const committedAt = /* @__PURE__ */ new Date();
|
|
80385
81019
|
try {
|
|
80386
|
-
(0,
|
|
81020
|
+
(0, import_node_fs51.utimesSync)(preserve, committedAt, committedAt);
|
|
80387
81021
|
} catch {
|
|
80388
81022
|
}
|
|
80389
81023
|
sweepExpiredCacheGenerations(projectId, refId2, preserve);
|
|
@@ -80409,19 +81043,19 @@ function filterKey(filter) {
|
|
|
80409
81043
|
function cachedGeometryBinary(projectId, refId2, expectHash, expectFilter) {
|
|
80410
81044
|
const candidates = binaryCacheCandidates(projectId, refId2, expectHash, expectFilter);
|
|
80411
81045
|
for (const path of candidates) {
|
|
80412
|
-
if (!(0,
|
|
81046
|
+
if (!(0, import_node_fs51.existsSync)(path)) continue;
|
|
80413
81047
|
let fd2 = null;
|
|
80414
81048
|
try {
|
|
80415
|
-
fd2 = (0,
|
|
80416
|
-
const size = (0,
|
|
81049
|
+
fd2 = (0, import_node_fs51.openSync)(path, "r");
|
|
81050
|
+
const size = (0, import_node_fs51.fstatSync)(fd2).size;
|
|
80417
81051
|
const manifest = readReferenceBinaryHandleManifest(fd2, size);
|
|
80418
81052
|
if (manifest.v !== REFERENCE_CACHE_VERSION || manifest.sourceHash !== expectHash || filterKey(manifest.filter) !== filterKey(expectFilter)) {
|
|
80419
|
-
(0,
|
|
81053
|
+
(0, import_node_fs51.closeSync)(fd2);
|
|
80420
81054
|
return null;
|
|
80421
81055
|
}
|
|
80422
81056
|
return { fd: fd2, size, path };
|
|
80423
81057
|
} catch (error) {
|
|
80424
|
-
if (fd2 !== null) (0,
|
|
81058
|
+
if (fd2 !== null) (0, import_node_fs51.closeSync)(fd2);
|
|
80425
81059
|
const code = error?.code;
|
|
80426
81060
|
if (code && ["EACCES", "EBUSY", "EMFILE", "ENFILE"].includes(code)) {
|
|
80427
81061
|
throw new ReferenceImportError("the reference cache could not be opened \u2014 check the project folder is readable and try again");
|
|
@@ -80432,20 +81066,20 @@ function cachedGeometryBinary(projectId, refId2, expectHash, expectFilter) {
|
|
|
80432
81066
|
return null;
|
|
80433
81067
|
}
|
|
80434
81068
|
function dropCache(projectId, refId2) {
|
|
80435
|
-
const timerKey = `${(0,
|
|
81069
|
+
const timerKey = `${(0, import_node_path45.resolve)(projectDir(projectId))}\0${safeId2(refId2)}`;
|
|
80436
81070
|
const timer = cachePruneTimers.get(timerKey);
|
|
80437
81071
|
if (timer) {
|
|
80438
81072
|
clearTimeout(timer);
|
|
80439
81073
|
cachePruneTimers.delete(timerKey);
|
|
80440
81074
|
}
|
|
80441
|
-
(0,
|
|
80442
|
-
(0,
|
|
80443
|
-
(0,
|
|
81075
|
+
(0, import_node_fs51.rmSync)(legacyJsonCachePath(projectId, refId2), { force: true });
|
|
81076
|
+
(0, import_node_fs51.rmSync)(legacyBinaryCachePath(projectId, refId2), { force: true });
|
|
81077
|
+
(0, import_node_fs51.rmSync)(cacheCurrentPath(projectId, refId2), { force: true });
|
|
80444
81078
|
const prefix = binaryCachePrefix(refId2);
|
|
80445
81079
|
try {
|
|
80446
|
-
for (const name of (0,
|
|
80447
|
-
activePendingCacheGenerations.delete((0,
|
|
80448
|
-
(0,
|
|
81080
|
+
for (const name of (0, import_node_fs51.readdirSync)(projectDir(projectId))) if (name.startsWith(prefix) && (name.endsWith(".bin") || name.endsWith(".pending") || name.endsWith(".part"))) {
|
|
81081
|
+
activePendingCacheGenerations.delete((0, import_node_path45.resolve)((0, import_node_path45.join)(projectDir(projectId), name)));
|
|
81082
|
+
(0, import_node_fs51.rmSync)((0, import_node_path45.join)(projectDir(projectId), name), { force: true });
|
|
80449
81083
|
}
|
|
80450
81084
|
} catch (error) {
|
|
80451
81085
|
if (error.code !== "ENOENT") throw error;
|
|
@@ -80453,10 +81087,10 @@ function dropCache(projectId, refId2) {
|
|
|
80453
81087
|
}
|
|
80454
81088
|
function removeReference(projectId, refId2, relPath) {
|
|
80455
81089
|
dropCache(projectId, refId2);
|
|
80456
|
-
if (relPath) (0,
|
|
81090
|
+
if (relPath) (0, import_node_fs51.rmSync)(insideProject(projectId, relPath), { force: true });
|
|
80457
81091
|
}
|
|
80458
81092
|
function removeReferenceFile(projectId, relPath) {
|
|
80459
|
-
(0,
|
|
81093
|
+
(0, import_node_fs51.rmSync)(insideProject(projectId, relPath), { force: true });
|
|
80460
81094
|
}
|
|
80461
81095
|
function takenReferencePaths(refs) {
|
|
80462
81096
|
return new Set((refs ?? []).map((r) => r.file).filter((f) => typeof f === "string"));
|
|
@@ -81074,7 +81708,7 @@ function registerReferenceRoutes(app, deps) {
|
|
|
81074
81708
|
return reply.status(404).send({ ok: false, error: "the uploaded IFC is no longer available \u2014 drop the file again" });
|
|
81075
81709
|
}
|
|
81076
81710
|
const displayName = String(name || "model.ifc");
|
|
81077
|
-
const id = (0,
|
|
81711
|
+
const id = (0, import_node_crypto37.randomUUID)();
|
|
81078
81712
|
let rel;
|
|
81079
81713
|
try {
|
|
81080
81714
|
rel = await withLifecycleLock("project", g.project, () => {
|
|
@@ -81244,7 +81878,7 @@ function registerReferenceRoutes(app, deps) {
|
|
|
81244
81878
|
const stored2 = entry2.filter;
|
|
81245
81879
|
const hit = rebuild ? null : cachedGeometryBinary(g.project, entry2.id, sourceHash, stored2);
|
|
81246
81880
|
if (hit) {
|
|
81247
|
-
return reply.type(REFERENCE_BINARY_TYPE).header("content-length", String(hit.size)).header("x-floless-reference-cache", "hit").send((0,
|
|
81881
|
+
return reply.type(REFERENCE_BINARY_TYPE).header("content-length", String(hit.size)).header("x-floless-reference-cache", "hit").send((0, import_node_fs52.createReadStream)(hit.path, { fd: hit.fd, autoClose: true }));
|
|
81248
81882
|
}
|
|
81249
81883
|
let preview2 = null;
|
|
81250
81884
|
try {
|
|
@@ -81301,7 +81935,7 @@ function registerReferenceRoutes(app, deps) {
|
|
|
81301
81935
|
}
|
|
81302
81936
|
const built = cachedGeometryBinary(g.project, entry2.id, sourceHash, stored2);
|
|
81303
81937
|
if (!built) throw new Error("the reference binary was not published");
|
|
81304
|
-
return reply.type(REFERENCE_BINARY_TYPE).header("content-length", String(built.size)).header("x-floless-reference-cache", "miss").send((0,
|
|
81938
|
+
return reply.type(REFERENCE_BINARY_TYPE).header("content-length", String(built.size)).header("x-floless-reference-cache", "miss").send((0, import_node_fs52.createReadStream)(built.path, { fd: built.fd, autoClose: true }));
|
|
81305
81939
|
} catch (e) {
|
|
81306
81940
|
if (e instanceof LifecycleLockBusyError) throw e;
|
|
81307
81941
|
const r = importRefusal(e);
|
|
@@ -81383,7 +82017,7 @@ function registerReferenceRoutes(app, deps) {
|
|
|
81383
82017
|
};
|
|
81384
82018
|
try {
|
|
81385
82019
|
try {
|
|
81386
|
-
assertAcceptable((0,
|
|
82020
|
+
assertAcceptable((0, import_node_fs52.statSync)(source).size, displayName);
|
|
81387
82021
|
} catch (e) {
|
|
81388
82022
|
const r = importRefusal(e);
|
|
81389
82023
|
if (r) return reply.status(r.status).send(r.body);
|
|
@@ -81988,10 +82622,10 @@ function registerReferenceRoutes(app, deps) {
|
|
|
81988
82622
|
|
|
81989
82623
|
// bom-export.ts
|
|
81990
82624
|
var import_node_os27 = require("node:os");
|
|
81991
|
-
var
|
|
82625
|
+
var import_node_path46 = require("node:path");
|
|
81992
82626
|
|
|
81993
82627
|
// node_modules/write-excel-file/modules/export/writeXlsxFileNode.js
|
|
81994
|
-
var
|
|
82628
|
+
var import_node_fs53 = __toESM(require("node:fs"), 1);
|
|
81995
82629
|
|
|
81996
82630
|
// node_modules/write-excel-file/modules/xlsx/helpers/features/getAdditionalContent.js
|
|
81997
82631
|
function _createForOfIteratorHelperLoose(r, e) {
|
|
@@ -85091,7 +85725,7 @@ function writeXlsxFile(arg1, arg2, arg3) {
|
|
|
85091
85725
|
},
|
|
85092
85726
|
toFile: function toFile(filePath) {
|
|
85093
85727
|
return createReadableStream().then(function(readableStream) {
|
|
85094
|
-
return pipe(readableStream,
|
|
85728
|
+
return pipe(readableStream, import_node_fs53.default.createWriteStream(filePath));
|
|
85095
85729
|
});
|
|
85096
85730
|
}
|
|
85097
85731
|
};
|
|
@@ -85353,8 +85987,8 @@ var BOM_EXPORT_KIND = {
|
|
|
85353
85987
|
html: "bom-html"
|
|
85354
85988
|
};
|
|
85355
85989
|
function bomExportPath(appId, format) {
|
|
85356
|
-
const root6 = process.env.FLOLESS_HOME ?? (0,
|
|
85357
|
-
return (0,
|
|
85990
|
+
const root6 = process.env.FLOLESS_HOME ?? (0, import_node_path46.join)((0, import_node_os27.homedir)(), ".floless");
|
|
85991
|
+
return (0, import_node_path46.join)(root6, "exports", appId, `${appId}-bom.${format}`);
|
|
85358
85992
|
}
|
|
85359
85993
|
function csvField(v) {
|
|
85360
85994
|
let s = String(v);
|
|
@@ -85532,7 +86166,14 @@ function registerContractAccessRoutes(app, deps) {
|
|
|
85532
86166
|
if (!snapshot && req.query.quietMissing === "1") return reply.status(204).send();
|
|
85533
86167
|
if (!snapshot) return reply.status(404).send({ ok: false, error: "no contract for this app yet" });
|
|
85534
86168
|
reply.header("ETag", snapshot.etag);
|
|
85535
|
-
|
|
86169
|
+
const asked = (Array.isArray(req.query.recordedEtag) ? req.query.recordedEtag : [req.query.recordedEtag]).filter((tag) => typeof tag === "string" && tag !== "");
|
|
86170
|
+
const recorded = [...new Set(asked)].slice(0, 4);
|
|
86171
|
+
if (!recorded.length) return snapshot;
|
|
86172
|
+
const names2 = deps.recordedEtagsNameDocument(recorded, snapshot.contract);
|
|
86173
|
+
return {
|
|
86174
|
+
...snapshot,
|
|
86175
|
+
recordedBases: recorded.map((tag, i) => ({ recorded: tag, namesSnapshot: names2[i] === true }))
|
|
86176
|
+
};
|
|
85536
86177
|
});
|
|
85537
86178
|
app.post(
|
|
85538
86179
|
"/api/contract/:appId/scene",
|
|
@@ -85753,8 +86394,8 @@ function workspaceContractLifecycle(contract, hasHistory = false) {
|
|
|
85753
86394
|
}
|
|
85754
86395
|
|
|
85755
86396
|
// project-export-files.ts
|
|
85756
|
-
var
|
|
85757
|
-
var
|
|
86397
|
+
var import_node_fs54 = require("node:fs");
|
|
86398
|
+
var import_node_path47 = require("node:path");
|
|
85758
86399
|
function projectExportFiles(appId, kindOf2 = appId) {
|
|
85759
86400
|
if (kindOf2 === "vectorize") {
|
|
85760
86401
|
return [{ kind: "svg", filename: `${appId}.svg` }];
|
|
@@ -85783,119 +86424,16 @@ function exportFileBase(projectId, appId, now = /* @__PURE__ */ new Date()) {
|
|
|
85783
86424
|
}
|
|
85784
86425
|
function uniqueProjectExportFilename(projectId, preferred) {
|
|
85785
86426
|
const dir = projectExportsDir(projectId);
|
|
85786
|
-
if (!(0,
|
|
85787
|
-
const extension = (0,
|
|
86427
|
+
if (!(0, import_node_fs54.existsSync)((0, import_node_path47.join)(dir, preferred))) return preferred;
|
|
86428
|
+
const extension = (0, import_node_path47.extname)(preferred);
|
|
85788
86429
|
const stem = preferred.slice(0, preferred.length - extension.length);
|
|
85789
86430
|
for (let suffix = 2; suffix <= 9999; suffix += 1) {
|
|
85790
86431
|
const candidate = `${stem}-${suffix}${extension}`;
|
|
85791
|
-
if (!(0,
|
|
86432
|
+
if (!(0, import_node_fs54.existsSync)((0, import_node_path47.join)(dir, candidate))) return candidate;
|
|
85792
86433
|
}
|
|
85793
86434
|
throw new Error("could not allocate a unique project export filename");
|
|
85794
86435
|
}
|
|
85795
86436
|
|
|
85796
|
-
// workspace-approved-snapshot.ts
|
|
85797
|
-
var WorkspaceSnapshotError = class extends Error {
|
|
85798
|
-
constructor(status, message, notReviewable, version) {
|
|
85799
|
-
super(message);
|
|
85800
|
-
this.status = status;
|
|
85801
|
-
this.notReviewable = notReviewable;
|
|
85802
|
-
this.version = version;
|
|
85803
|
-
}
|
|
85804
|
-
status;
|
|
85805
|
-
notReviewable;
|
|
85806
|
-
version;
|
|
85807
|
-
};
|
|
85808
|
-
var NoApprovedVersionError = class extends WorkspaceSnapshotError {
|
|
85809
|
-
constructor() {
|
|
85810
|
-
super(409, "project has no approved version");
|
|
85811
|
-
this.name = "NoApprovedVersionError";
|
|
85812
|
-
}
|
|
85813
|
-
};
|
|
85814
|
-
function approvedRows(projectId) {
|
|
85815
|
-
const project = getProject(projectId);
|
|
85816
|
-
if (!project) return [];
|
|
85817
|
-
const allRows = listVersions(projectId);
|
|
85818
|
-
if (project.uuid) {
|
|
85819
|
-
const tainted = allRows.find((v) => v.gate === "model" && v.kind === "approve" && !v.approval);
|
|
85820
|
-
if (tainted) {
|
|
85821
|
-
throw new WorkspaceSnapshotError(409, `project has no approved version: approved version ${tainted.n} has no approval proof`, void 0, tainted.n);
|
|
85822
|
-
}
|
|
85823
|
-
}
|
|
85824
|
-
const projectTime = Date.parse(project.createdAt);
|
|
85825
|
-
return allRows.filter((v) => v.gate === "model" && v.kind === "approve").filter((v) => v.approval ? !!project.uuid && v.approval.projectUuid === project.uuid : Number.isFinite(projectTime) && Date.parse(v.ts) >= projectTime).map(({ current: _current, ...meta }) => meta);
|
|
85826
|
-
}
|
|
85827
|
-
function latestApprovedVersion(projectId) {
|
|
85828
|
-
return approvedRows(projectId)[0] ?? null;
|
|
85829
|
-
}
|
|
85830
|
-
function listApprovedVersionMetadata(projectId) {
|
|
85831
|
-
return approvedRows(projectId);
|
|
85832
|
-
}
|
|
85833
|
-
function currentApprovedSnapshot(projectId, version) {
|
|
85834
|
-
const project = getProject(projectId);
|
|
85835
|
-
if (!project) throw new WorkspaceSnapshotError(404, `unknown project: ${projectId}`);
|
|
85836
|
-
const rows2 = approvedRows(projectId);
|
|
85837
|
-
const row = version === void 0 ? rows2[0] : rows2.find((v) => v.n === version);
|
|
85838
|
-
if (!row) {
|
|
85839
|
-
if (version === void 0) throw new NoApprovedVersionError();
|
|
85840
|
-
throw new WorkspaceSnapshotError(404, `approved version not found: ${version}`);
|
|
85841
|
-
}
|
|
85842
|
-
const latest = rows2[0];
|
|
85843
|
-
const assertOwned = (candidate, hash3) => {
|
|
85844
|
-
if (candidate.approval) {
|
|
85845
|
-
if (!project.uuid || candidate.approval.projectUuid !== project.uuid) {
|
|
85846
|
-
throw new WorkspaceSnapshotError(409, `approved version ${candidate.n} belongs to another project incarnation`);
|
|
85847
|
-
}
|
|
85848
|
-
if (candidate.approval.candidateHash !== hash3) {
|
|
85849
|
-
throw new WorkspaceSnapshotError(409, `approved version ${candidate.n} failed its content-hash proof`);
|
|
85850
|
-
}
|
|
85851
|
-
return;
|
|
85852
|
-
}
|
|
85853
|
-
const rowTime = Date.parse(candidate.ts);
|
|
85854
|
-
const projectTime = Date.parse(project.createdAt);
|
|
85855
|
-
if (!Number.isFinite(rowTime) || !Number.isFinite(projectTime) || rowTime < projectTime) {
|
|
85856
|
-
throw new WorkspaceSnapshotError(409, `approved version ${candidate.n} has no ownership proof`);
|
|
85857
|
-
}
|
|
85858
|
-
};
|
|
85859
|
-
const contract = readAcceptedVersion(projectId, row.n, { appId: project.app, projectId, operation: "read" });
|
|
85860
|
-
if (contract == null) throw new WorkspaceSnapshotError(409, `approved version ${row.n} is unreadable`);
|
|
85861
|
-
const selectedHash = contractHash(contract);
|
|
85862
|
-
assertOwned(row, selectedHash);
|
|
85863
|
-
const latestContract = latest.n === row.n ? contract : readAcceptedVersion(projectId, latest.n, { appId: project.app, projectId, operation: "read" });
|
|
85864
|
-
if (latestContract == null) throw new WorkspaceSnapshotError(409, `approved version ${latest.n} is unreadable`);
|
|
85865
|
-
const latestHash = contractHash(latestContract);
|
|
85866
|
-
assertOwned(latest, latestHash);
|
|
85867
|
-
const draft = readAcceptedForRequest(project.app, projectId, "read");
|
|
85868
|
-
const comparable = comparableContractHash;
|
|
85869
|
-
const dirtySinceApproval = draft == null || comparable(draft) !== comparable(latestContract);
|
|
85870
|
-
return {
|
|
85871
|
-
project,
|
|
85872
|
-
version: row,
|
|
85873
|
-
contract,
|
|
85874
|
-
contractHash: selectedHash,
|
|
85875
|
-
currentApprovedAt: project.approvedAt ?? null,
|
|
85876
|
-
dirtySinceApproval,
|
|
85877
|
-
latestApprovedVersion: latest.n,
|
|
85878
|
-
headDiverged: row.n !== latest.n
|
|
85879
|
-
};
|
|
85880
|
-
}
|
|
85881
|
-
function approvedSnapshotForMetadata(projectId, surface, onRefusal) {
|
|
85882
|
-
try {
|
|
85883
|
-
return currentApprovedSnapshot(projectId);
|
|
85884
|
-
} catch (error) {
|
|
85885
|
-
if (error instanceof NoApprovedVersionError) return null;
|
|
85886
|
-
if (error instanceof WorkspaceSnapshotError && error.status === 404) throw error;
|
|
85887
|
-
if (error instanceof WorkspaceSnapshotError || error instanceof ContractPolicyError) {
|
|
85888
|
-
const status = error instanceof WorkspaceSnapshotError ? error.status : error.code;
|
|
85889
|
-
onRefusal?.(error);
|
|
85890
|
-
console.error(
|
|
85891
|
-
`${surface}: project ${projectId} has an approved version the gate refused to serve (${status}) \u2014 reporting no approved head. ${error.message}`
|
|
85892
|
-
);
|
|
85893
|
-
return null;
|
|
85894
|
-
}
|
|
85895
|
-
throw error;
|
|
85896
|
-
}
|
|
85897
|
-
}
|
|
85898
|
-
|
|
85899
86437
|
// approval-partition.ts
|
|
85900
86438
|
var unchangedNode = (value) => ({ materialize: () => value });
|
|
85901
86439
|
var atomicNode = (groupId, before, after) => ({
|
|
@@ -85985,7 +86523,7 @@ var changedKeys = (before, after) => {
|
|
|
85985
86523
|
};
|
|
85986
86524
|
|
|
85987
86525
|
// approval-contract-adapters.ts
|
|
85988
|
-
var
|
|
86526
|
+
var isObj10 = (v) => !!v && typeof v === "object" && !Array.isArray(v);
|
|
85989
86527
|
var arr4 = (v) => Array.isArray(v) ? v : [];
|
|
85990
86528
|
var eq = (a, b) => canonicalJson(a) === canonicalJson(b);
|
|
85991
86529
|
var own = (o, k) => Object.prototype.hasOwnProperty.call(o, k);
|
|
@@ -86009,8 +86547,8 @@ function groupOf(opts) {
|
|
|
86009
86547
|
dependencyGroup: id,
|
|
86010
86548
|
technicalFacts: keys.slice(0, 20).map((key2) => ({
|
|
86011
86549
|
label: key2,
|
|
86012
|
-
...
|
|
86013
|
-
...
|
|
86550
|
+
...isObj10(opts.before) && own(opts.before, key2) ? { before: displayValue(opts.before[key2]) } : {},
|
|
86551
|
+
...isObj10(opts.after) && own(opts.after, key2) ? { after: displayValue(opts.after[key2]) } : {}
|
|
86014
86552
|
}))
|
|
86015
86553
|
};
|
|
86016
86554
|
}
|
|
@@ -86042,7 +86580,7 @@ function keyedCollection(opts) {
|
|
|
86042
86580
|
const map = /* @__PURE__ */ new Map();
|
|
86043
86581
|
const order = [];
|
|
86044
86582
|
for (const value of values2) {
|
|
86045
|
-
if (!
|
|
86583
|
+
if (!isObj10(value)) return null;
|
|
86046
86584
|
const key2 = opts.keyOf(value);
|
|
86047
86585
|
if (!key2 || map.has(key2)) return null;
|
|
86048
86586
|
map.set(key2, value);
|
|
@@ -86064,11 +86602,11 @@ function keyedCollection(opts) {
|
|
|
86064
86602
|
parent: opts.parent,
|
|
86065
86603
|
entity: key2,
|
|
86066
86604
|
category: opts.category,
|
|
86067
|
-
headline: opts.labelOf(
|
|
86605
|
+
headline: opts.labelOf(isObj10(bv) ? bv : av, key2),
|
|
86068
86606
|
location: opts.parent ? `${parentLabel(opts)} \xB7 ${key2}` : key2,
|
|
86069
86607
|
before: av,
|
|
86070
86608
|
after: bv,
|
|
86071
|
-
references:
|
|
86609
|
+
references: isObj10(bv) ? opts.referencesOf?.(bv) : []
|
|
86072
86610
|
}, opts.groups);
|
|
86073
86611
|
return { key: key2, node, inBase: a.map.has(key2), inDraft: b.map.has(key2) };
|
|
86074
86612
|
});
|
|
@@ -86097,7 +86635,7 @@ function objectWithOwnedKeys(base, draft, owned, groups, type) {
|
|
|
86097
86635
|
return objectNode(children);
|
|
86098
86636
|
}
|
|
86099
86637
|
function nestedEntity(base, draft, opts, groups) {
|
|
86100
|
-
if (base === ABSENT || draft === ABSENT || !
|
|
86638
|
+
if (base === ABSENT || draft === ABSENT || !isObj10(base) || !isObj10(draft)) {
|
|
86101
86639
|
return atomicChanged({
|
|
86102
86640
|
type: opts.type,
|
|
86103
86641
|
collection: opts.collection,
|
|
@@ -86167,9 +86705,9 @@ function token(type, collection, parent, id) {
|
|
|
86167
86705
|
function movedAcrossParents(baseParents, draftParents, childKey) {
|
|
86168
86706
|
const locations = (parents) => {
|
|
86169
86707
|
const out = /* @__PURE__ */ new Map();
|
|
86170
|
-
for (const parent of arr4(parents)) if (
|
|
86708
|
+
for (const parent of arr4(parents)) if (isObj10(parent)) {
|
|
86171
86709
|
const parentId = typeof parent.sheet === "string" ? parent.sheet : typeof parent.id === "string" ? parent.id : "";
|
|
86172
|
-
for (const child of arr4(parent[childKey])) if (
|
|
86710
|
+
for (const child of arr4(parent[childKey])) if (isObj10(child) && typeof child.id === "string") {
|
|
86173
86711
|
const list = out.get(child.id) ?? [];
|
|
86174
86712
|
list.push(parentId);
|
|
86175
86713
|
out.set(child.id, list);
|
|
@@ -86213,7 +86751,7 @@ function unionDependencies(groups) {
|
|
|
86213
86751
|
}
|
|
86214
86752
|
function planLabeller(base, draft) {
|
|
86215
86753
|
const byId = /* @__PURE__ */ new Map();
|
|
86216
|
-
for (const row of [...arr4(
|
|
86754
|
+
for (const row of [...arr4(isObj10(draft) ? draft.plans : null), ...arr4(isObj10(base) ? base.plans : null)]) {
|
|
86217
86755
|
const key2 = rawPlanViewId(row);
|
|
86218
86756
|
if (key2 !== null && !byId.has(key2)) byId.set(key2, row);
|
|
86219
86757
|
}
|
|
@@ -86235,7 +86773,7 @@ function fallback(base, draft, type, reason) {
|
|
|
86235
86773
|
return wholeVersionPartition(base, draft, reason, group);
|
|
86236
86774
|
}
|
|
86237
86775
|
function buildKnown(base, draft, type) {
|
|
86238
|
-
if (!
|
|
86776
|
+
if (!isObj10(base) || !isObj10(draft)) return fallback(base, draft, type, "incomplete-comparison");
|
|
86239
86777
|
const groups = [];
|
|
86240
86778
|
const owned = /* @__PURE__ */ new Map();
|
|
86241
86779
|
let reason;
|
|
@@ -86253,7 +86791,7 @@ function buildKnown(base, draft, type) {
|
|
|
86253
86791
|
keyOf: (v) => typeof v.id === "string" ? v.id : null,
|
|
86254
86792
|
labelOf: (v, id) => String(v.mark ?? id),
|
|
86255
86793
|
groups,
|
|
86256
|
-
referencesOf: (v) => arr4(v.ends).flatMap((end) =>
|
|
86794
|
+
referencesOf: (v) => arr4(v.ends).flatMap((end) => isObj10(end) && typeof end.conn === "string" ? [token(type, "connection", null, end.conn)] : [])
|
|
86257
86795
|
}));
|
|
86258
86796
|
const planLabel = planLabeller(base, draft);
|
|
86259
86797
|
add("plans", keyedCollection({
|
|
@@ -86277,7 +86815,7 @@ function buildKnown(base, draft, type) {
|
|
|
86277
86815
|
category: "Observation",
|
|
86278
86816
|
keyOf: (v) => typeof v.id === "string" ? v.id : null,
|
|
86279
86817
|
labelOf: (_v2, id) => `Observation ${id}`,
|
|
86280
|
-
referencesOf: (v) =>
|
|
86818
|
+
referencesOf: (v) => isObj10(v.binding) && Array.isArray(v.binding.memberIds) ? v.binding.memberIds.filter((id) => typeof id === "string").map((id) => token(type, "member", null, id)) : []
|
|
86281
86819
|
},
|
|
86282
86820
|
{
|
|
86283
86821
|
key: "dims",
|
|
@@ -86355,7 +86893,7 @@ function buildKnown(base, draft, type) {
|
|
|
86355
86893
|
labelOf: (v, id) => String(v.label ?? id),
|
|
86356
86894
|
referencesOf: (v) => [
|
|
86357
86895
|
...arr4(v.elementIds).filter((x) => typeof x === "string").map((id) => token(type, "element", key2, id)),
|
|
86358
|
-
...[
|
|
86896
|
+
...[isObj10(v.extrude) ? v.extrude.from : null, isObj10(v.extrude) ? v.extrude.to : null].filter((x) => typeof x === "string").map((id) => token(type, "datum", null, id))
|
|
86359
86897
|
]
|
|
86360
86898
|
}
|
|
86361
86899
|
]
|
|
@@ -86372,7 +86910,7 @@ function buildKnown(base, draft, type) {
|
|
|
86372
86910
|
groups
|
|
86373
86911
|
}));
|
|
86374
86912
|
const links = [...arr4(base.links), ...arr4(draft.links)];
|
|
86375
|
-
if (links.every((v) =>
|
|
86913
|
+
if (links.every((v) => isObj10(v) && typeof v.id === "string")) add("links", keyedCollection({
|
|
86376
86914
|
type,
|
|
86377
86915
|
collection: "link",
|
|
86378
86916
|
category: "Link",
|
|
@@ -86480,82 +87018,6 @@ function buildApprovalReview(input) {
|
|
|
86480
87018
|
return prepared;
|
|
86481
87019
|
}
|
|
86482
87020
|
|
|
86483
|
-
// working-revision-manifest.ts
|
|
86484
|
-
var import_node_crypto36 = require("node:crypto");
|
|
86485
|
-
var import_node_fs53 = require("node:fs");
|
|
86486
|
-
var import_node_path46 = require("node:path");
|
|
86487
|
-
var nativePublicationIdentity = (projectUuid) => `project:${projectUuid}`;
|
|
86488
|
-
var pathOf = (projectId) => (0, import_node_path46.join)(projectDir(projectId), ".floless-working-revision-state-v1.json");
|
|
86489
|
-
var checksumOf = (body) => hashOf(body);
|
|
86490
|
-
function bodyOf(value) {
|
|
86491
|
-
const { checksum: _checksum, ...body } = value;
|
|
86492
|
-
return body;
|
|
86493
|
-
}
|
|
86494
|
-
function assertProject(project) {
|
|
86495
|
-
if (!project.uuid) throw new Error(`project ${project.id} has no incarnation UUID`);
|
|
86496
|
-
return project.uuid;
|
|
86497
|
-
}
|
|
86498
|
-
function readWorkingRevisionManifest(project) {
|
|
86499
|
-
const uuid = assertProject(project);
|
|
86500
|
-
try {
|
|
86501
|
-
const value = JSON.parse((0, import_node_fs53.readFileSync)(pathOf(project.id), "utf8"));
|
|
86502
|
-
if (value?.schema !== 1 || value.projectUuid !== uuid || !Number.isInteger(value.epoch) || value.epoch < 0) return null;
|
|
86503
|
-
return checksumOf(bodyOf(value)) === value.checksum ? value : null;
|
|
86504
|
-
} catch {
|
|
86505
|
-
return null;
|
|
86506
|
-
}
|
|
86507
|
-
}
|
|
86508
|
-
function ensureWorkingRevisionManifest(input) {
|
|
86509
|
-
const existing = readWorkingRevisionManifest(input.project);
|
|
86510
|
-
if (existing) return existing;
|
|
86511
|
-
const body = {
|
|
86512
|
-
schema: 1,
|
|
86513
|
-
projectUuid: assertProject(input.project),
|
|
86514
|
-
publicationIdentity: input.publicationIdentity,
|
|
86515
|
-
revisionId: (0, import_node_crypto36.randomUUID)(),
|
|
86516
|
-
epoch: 0,
|
|
86517
|
-
source: { kind: "working" },
|
|
86518
|
-
workingBase: input.workingBase,
|
|
86519
|
-
draftHash: hashOf(input.contract),
|
|
86520
|
-
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
86521
|
-
};
|
|
86522
|
-
const value = { ...body, checksum: checksumOf(body) };
|
|
86523
|
-
(0, import_node_fs53.mkdirSync)(projectDir(input.project.id), { recursive: true });
|
|
86524
|
-
if (!(0, import_node_fs53.existsSync)(pathOf(input.project.id))) writeJsonAtomic(pathOf(input.project.id), value);
|
|
86525
|
-
return readWorkingRevisionManifest(input.project) ?? value;
|
|
86526
|
-
}
|
|
86527
|
-
function advanceWorkingRevisionManifest(input) {
|
|
86528
|
-
const current = readWorkingRevisionManifest(input.project);
|
|
86529
|
-
if (!current) throw new Error("working revision state is missing or corrupt");
|
|
86530
|
-
if (current.epoch !== input.expectedEpoch || current.draftHash !== input.expectedDraftHash) {
|
|
86531
|
-
throw new Error("working revision changed; reload before continuing");
|
|
86532
|
-
}
|
|
86533
|
-
if (current.publicationIdentity !== input.publicationIdentity) throw new Error("working revision belongs to another app publication");
|
|
86534
|
-
const body = {
|
|
86535
|
-
...bodyOf(current),
|
|
86536
|
-
revisionId: (0, import_node_crypto36.randomUUID)(),
|
|
86537
|
-
epoch: current.epoch + 1,
|
|
86538
|
-
source: input.source,
|
|
86539
|
-
workingBase: input.workingBase,
|
|
86540
|
-
draftHash: hashOf(input.contract),
|
|
86541
|
-
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
86542
|
-
};
|
|
86543
|
-
const value = { ...body, checksum: checksumOf(body) };
|
|
86544
|
-
writeJsonAtomic(pathOf(input.project.id), value);
|
|
86545
|
-
return value;
|
|
86546
|
-
}
|
|
86547
|
-
function refreshWorkingDraftHash(input) {
|
|
86548
|
-
const current = readWorkingRevisionManifest(input.project);
|
|
86549
|
-
if (!current) throw new Error("working revision state is missing or corrupt");
|
|
86550
|
-
if (current.epoch !== input.expectedEpoch || current.draftHash !== input.expectedDraftHash) {
|
|
86551
|
-
throw new Error("working revision changed; reload before saving");
|
|
86552
|
-
}
|
|
86553
|
-
const body = { ...bodyOf(current), draftHash: hashOf(input.contract), updatedAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
86554
|
-
const value = { ...body, checksum: checksumOf(body) };
|
|
86555
|
-
writeJsonAtomic(pathOf(input.project.id), value);
|
|
86556
|
-
return value;
|
|
86557
|
-
}
|
|
86558
|
-
|
|
86559
87021
|
// three-way-contract-merge.ts
|
|
86560
87022
|
var MISSING = /* @__PURE__ */ Symbol("missing");
|
|
86561
87023
|
var same3 = (a, b) => canonicalJson(a) === canonicalJson(b);
|
|
@@ -86791,110 +87253,6 @@ function projectApprovalCandidateAccepted(appId, projectId, candidate) {
|
|
|
86791
87253
|
return acceptSteelForRoute(candidate, { appId, projectId }, "stored").accepted;
|
|
86792
87254
|
}
|
|
86793
87255
|
|
|
86794
|
-
// project-checkpoints-store.ts
|
|
86795
|
-
var import_node_crypto37 = require("node:crypto");
|
|
86796
|
-
var import_node_fs54 = require("node:fs");
|
|
86797
|
-
var import_node_path47 = require("node:path");
|
|
86798
|
-
var HASH_RE3 = /^[0-9a-f]{64}$/;
|
|
86799
|
-
function root5(projectId) {
|
|
86800
|
-
return (0, import_node_path47.join)(projectDir(projectId), ".floless-checkpoints-store-v1");
|
|
86801
|
-
}
|
|
86802
|
-
var objectsDir2 = (projectId) => (0, import_node_path47.join)(root5(projectId), "objects");
|
|
86803
|
-
var eventsPath = (projectId) => (0, import_node_path47.join)(root5(projectId), "events.json");
|
|
86804
|
-
function readEvents(projectId) {
|
|
86805
|
-
try {
|
|
86806
|
-
const parsed = JSON.parse((0, import_node_fs54.readFileSync)(eventsPath(projectId), "utf8"));
|
|
86807
|
-
if (parsed?.schema !== 1 || !Array.isArray(parsed.events)) return { schema: 1, events: [] };
|
|
86808
|
-
return { schema: 1, events: parsed.events.filter(validEvent) };
|
|
86809
|
-
} catch {
|
|
86810
|
-
return { schema: 1, events: [] };
|
|
86811
|
-
}
|
|
86812
|
-
}
|
|
86813
|
-
function validEvent(value) {
|
|
86814
|
-
if (!value || typeof value !== "object") return false;
|
|
86815
|
-
const e = value;
|
|
86816
|
-
return typeof e.eventId === "string" && typeof e.checkpointId === "string" && HASH_RE3.test(e.checkpointId) && (e.kind === "captured" || e.kind === "archived" || e.kind === "incorporated") && typeof e.at === "string" && Number.isInteger(e.revisionEpoch) && typeof e.appIdAtCapture === "string";
|
|
86817
|
-
}
|
|
86818
|
-
function readContent(projectId, id) {
|
|
86819
|
-
if (!HASH_RE3.test(id)) return null;
|
|
86820
|
-
try {
|
|
86821
|
-
const value = JSON.parse((0, import_node_fs54.readFileSync)((0, import_node_path47.join)(objectsDir2(projectId), `${id}.json`), "utf8"));
|
|
86822
|
-
if (value?.schema !== 1 || value.id !== id || hashCheckpoint(value) !== id) return null;
|
|
86823
|
-
return value;
|
|
86824
|
-
} catch {
|
|
86825
|
-
return null;
|
|
86826
|
-
}
|
|
86827
|
-
}
|
|
86828
|
-
function hashCheckpoint(value) {
|
|
86829
|
-
const { id: _id, ...identity } = value;
|
|
86830
|
-
return hashOf(identity);
|
|
86831
|
-
}
|
|
86832
|
-
function requireIdentity(project) {
|
|
86833
|
-
if (!project.uuid) throw new Error(`project ${project.id} has no incarnation UUID`);
|
|
86834
|
-
return project.uuid;
|
|
86835
|
-
}
|
|
86836
|
-
function appendEvent(projectId, event) {
|
|
86837
|
-
(0, import_node_fs54.mkdirSync)(root5(projectId), { recursive: true });
|
|
86838
|
-
const log2 = readEvents(projectId);
|
|
86839
|
-
const row = { ...event, eventId: (0, import_node_crypto37.randomUUID)(), at: (/* @__PURE__ */ new Date()).toISOString() };
|
|
86840
|
-
log2.events.push(row);
|
|
86841
|
-
writeJsonAtomic(eventsPath(projectId), log2);
|
|
86842
|
-
return row;
|
|
86843
|
-
}
|
|
86844
|
-
function captureProjectCheckpoint(input) {
|
|
86845
|
-
const projectUuid = requireIdentity(input.project);
|
|
86846
|
-
const withoutId = {
|
|
86847
|
-
schema: 1,
|
|
86848
|
-
projectUuid,
|
|
86849
|
-
publicationIdentity: input.publicationIdentity,
|
|
86850
|
-
base: input.base,
|
|
86851
|
-
draftHash: hashOf(input.contract),
|
|
86852
|
-
contract: input.contract
|
|
86853
|
-
};
|
|
86854
|
-
const id = hashCheckpoint(withoutId);
|
|
86855
|
-
(0, import_node_fs54.mkdirSync)(objectsDir2(input.project.id), { recursive: true });
|
|
86856
|
-
const path = (0, import_node_path47.join)(objectsDir2(input.project.id), `${id}.json`);
|
|
86857
|
-
if (!(0, import_node_fs54.existsSync)(path)) writeJsonAtomic(path, { ...withoutId, id });
|
|
86858
|
-
const event = appendEvent(input.project.id, {
|
|
86859
|
-
checkpointId: id,
|
|
86860
|
-
kind: "captured",
|
|
86861
|
-
revisionEpoch: input.revisionEpoch,
|
|
86862
|
-
appIdAtCapture: input.project.app
|
|
86863
|
-
});
|
|
86864
|
-
return describe(input.project.id, { ...withoutId, id }, event.eventId);
|
|
86865
|
-
}
|
|
86866
|
-
function describe(projectId, content, latestEventId) {
|
|
86867
|
-
const events = readEvents(projectId).events.filter((event) => event.checkpointId === content.id);
|
|
86868
|
-
const captures = events.filter((event) => event.kind === "captured");
|
|
86869
|
-
const first = captures[0];
|
|
86870
|
-
const latest = events.at(-1);
|
|
86871
|
-
if (!first || !latest) return null;
|
|
86872
|
-
return {
|
|
86873
|
-
...content,
|
|
86874
|
-
capturedAt: first.at,
|
|
86875
|
-
archived: latest.kind === "archived",
|
|
86876
|
-
incorporated: events.some((event) => event.kind === "incorporated"),
|
|
86877
|
-
captureCount: captures.length,
|
|
86878
|
-
latestEventId: latestEventId ?? latest.eventId
|
|
86879
|
-
};
|
|
86880
|
-
}
|
|
86881
|
-
function listProjectCheckpoints(project) {
|
|
86882
|
-
const uuid = requireIdentity(project);
|
|
86883
|
-
const ids = [...new Set(readEvents(project.id).events.map((event) => event.checkpointId))];
|
|
86884
|
-
return ids.map((id) => readContent(project.id, id)).filter((v) => v !== null).filter((v) => v.projectUuid === uuid).map((v) => describe(project.id, v)).filter((v) => v !== null).sort((a, b) => b.capturedAt.localeCompare(a.capturedAt));
|
|
86885
|
-
}
|
|
86886
|
-
function readProjectCheckpoint(project, checkpointId) {
|
|
86887
|
-
const content = readContent(project.id, checkpointId);
|
|
86888
|
-
return content && content.projectUuid === requireIdentity(project) ? describe(project.id, content) : null;
|
|
86889
|
-
}
|
|
86890
|
-
function markProjectCheckpoint(project, checkpointId, kind, expectedEventId) {
|
|
86891
|
-
const current = readProjectCheckpoint(project, checkpointId);
|
|
86892
|
-
if (!current) throw new Error(`unknown checkpoint: ${checkpointId}`);
|
|
86893
|
-
if (current.latestEventId !== expectedEventId) throw new Error("checkpoint changed; reload saved work");
|
|
86894
|
-
const event = appendEvent(project.id, { checkpointId, kind, revisionEpoch: 0, appIdAtCapture: project.app });
|
|
86895
|
-
return describe(project.id, current, event.eventId);
|
|
86896
|
-
}
|
|
86897
|
-
|
|
86898
87256
|
// export-source.ts
|
|
86899
87257
|
var import_node_crypto38 = require("node:crypto");
|
|
86900
87258
|
var import_node_fs55 = require("node:fs");
|
|
@@ -100308,131 +100666,7 @@ async function startServer() {
|
|
|
100308
100666
|
}))
|
|
100309
100667
|
}), { label: "listing saved work" });
|
|
100310
100668
|
});
|
|
100311
|
-
app
|
|
100312
|
-
"/api/projects/:id/revisions/start",
|
|
100313
|
-
async (req, reply) => {
|
|
100314
|
-
const project = getProject(req.params.id);
|
|
100315
|
-
if (!project?.uuid) return reply.status(project ? 409 : 404).send({ ok: false, error: project ? "project has no incarnation identity" : `unknown project: ${req.params.id}` });
|
|
100316
|
-
const version = Number(req.body?.version);
|
|
100317
|
-
if (!Number.isInteger(version) || version < 1) return reply.status(400).send({ ok: false, error: "choose a valid approved version" });
|
|
100318
|
-
return withLifecycleLock("project", project.id, async () => {
|
|
100319
|
-
let target;
|
|
100320
|
-
try {
|
|
100321
|
-
target = currentApprovedSnapshot(project.id, version);
|
|
100322
|
-
} catch (error) {
|
|
100323
|
-
if (error instanceof WorkspaceSnapshotError) return reply.status(error.status).send({ ok: false, error: error.message });
|
|
100324
|
-
throw error;
|
|
100325
|
-
}
|
|
100326
|
-
const current = readAcceptedForRequest(project.app, project.id, "read");
|
|
100327
|
-
if (current == null) return reply.status(409).send({ ok: false, error: "the current working copy is unreadable" });
|
|
100328
|
-
const actualEtags = storeEtags(project.app, project.id);
|
|
100329
|
-
const suppliedEpoch = req.body && Object.prototype.hasOwnProperty.call(req.body, "expectedEpoch") ? req.body.expectedEpoch : void 0;
|
|
100330
|
-
if (typeof req.body?.expectedEtag !== "string" || suppliedEpoch !== null && (!Number.isInteger(Number(suppliedEpoch)) || Number(suppliedEpoch) < 0)) {
|
|
100331
|
-
return reply.status(428).send({ ok: false, error: "Reload History and send the working ETag and revision epoch." });
|
|
100332
|
-
}
|
|
100333
|
-
if (!recordedEtagNamesContract(req.body.expectedEtag, actualEtags)) {
|
|
100334
|
-
return reply.status(409).send({ ok: false, error: "The working copy changed. Reload History before starting." });
|
|
100335
|
-
}
|
|
100336
|
-
const observedManifest = readWorkingRevisionManifest(project);
|
|
100337
|
-
if ((observedManifest?.epoch ?? null) !== (suppliedEpoch === null ? null : Number(suppliedEpoch))) {
|
|
100338
|
-
return reply.status(409).send({ ok: false, error: "The working revision changed. Reload History before starting." });
|
|
100339
|
-
}
|
|
100340
|
-
const publicationIdentity = observedManifest?.publicationIdentity ?? nativePublicationIdentity(project.uuid);
|
|
100341
|
-
let manifest = ensureWorkingRevisionManifest({
|
|
100342
|
-
project,
|
|
100343
|
-
publicationIdentity,
|
|
100344
|
-
contract: current,
|
|
100345
|
-
workingBase: { version: target.latestApprovedVersion, hash: currentApprovedSnapshot(project.id).contractHash }
|
|
100346
|
-
});
|
|
100347
|
-
if (manifest.draftHash !== contractHash(current)) {
|
|
100348
|
-
manifest = refreshWorkingDraftHash({ project, expectedEpoch: manifest.epoch, expectedDraftHash: manifest.draftHash, contract: current });
|
|
100349
|
-
}
|
|
100350
|
-
const latest = currentApprovedSnapshot(project.id);
|
|
100351
|
-
const dirty = comparableContractHash(current) !== comparableContractHash(latest.contract);
|
|
100352
|
-
const checkpoint = dirty ? captureProjectCheckpoint({
|
|
100353
|
-
project,
|
|
100354
|
-
publicationIdentity,
|
|
100355
|
-
base: manifest.workingBase,
|
|
100356
|
-
contract: current,
|
|
100357
|
-
revisionEpoch: manifest.epoch
|
|
100358
|
-
}) : null;
|
|
100359
|
-
let publication = null;
|
|
100360
|
-
try {
|
|
100361
|
-
const written = await writeContractGenerationChecked(project.app, target.contract, project.id, `start a new revision from approved v${version}`, { restoring: true });
|
|
100362
|
-
publication = written;
|
|
100363
|
-
} catch (error) {
|
|
100364
|
-
if (error instanceof ContractError) return reply.status(409).send({ ok: false, error: error.message });
|
|
100365
|
-
throw error;
|
|
100366
|
-
}
|
|
100367
|
-
clearApproval(project.id);
|
|
100368
|
-
const next = advanceWorkingRevisionManifest({
|
|
100369
|
-
project,
|
|
100370
|
-
expectedEpoch: manifest.epoch,
|
|
100371
|
-
expectedDraftHash: manifest.draftHash,
|
|
100372
|
-
publicationIdentity,
|
|
100373
|
-
contract: normalisePlanViewIds(target.contract),
|
|
100374
|
-
// The PROOFS stay the ledger's raw hashes — `workingBase.hash` is checked against History and
|
|
100375
|
-
// `source.hash` names the version this came from — while `contract:` above is the document the
|
|
100376
|
-
// gateway actually wrote, which is canonical. Hashing raw bytes into `draftHash` for a document
|
|
100377
|
-
// stored canonically made the manifest disagree with the store the instant it was written.
|
|
100378
|
-
source: { kind: "approved", version, hash: target.contractHash },
|
|
100379
|
-
workingBase: { version, hash: target.contractHash }
|
|
100380
|
-
});
|
|
100381
|
-
broadcast(contractChangedWithReason(project.app, project.id, publication.etag, publication.storeRevision, "rollback"));
|
|
100382
|
-
return {
|
|
100383
|
-
ok: true,
|
|
100384
|
-
checkpoint,
|
|
100385
|
-
revision: next,
|
|
100386
|
-
workingBaseVersion: version,
|
|
100387
|
-
latestApprovedVersion: latest.version.n,
|
|
100388
|
-
message: checkpoint ? `Saved pending work${checkpoint.base ? ` from v${checkpoint.base.version}` : ""}. Started a DRAFT from v${version}.` : `Started a DRAFT from v${version}.`
|
|
100389
|
-
};
|
|
100390
|
-
}, { label: `starting a revision from v${version}` });
|
|
100391
|
-
}
|
|
100392
|
-
);
|
|
100393
|
-
app.post(
|
|
100394
|
-
"/api/projects/:id/checkpoints/:checkpointId/resume",
|
|
100395
|
-
async (req, reply) => {
|
|
100396
|
-
const project = getProject(req.params.id);
|
|
100397
|
-
if (!project?.uuid) return reply.status(project ? 409 : 404).send({ ok: false, error: project ? "project has no incarnation identity" : `unknown project: ${req.params.id}` });
|
|
100398
|
-
return withLifecycleLock("project", project.id, async () => {
|
|
100399
|
-
const saved = readProjectCheckpoint(project, req.params.checkpointId);
|
|
100400
|
-
if (!saved) return reply.status(404).send({ ok: false, error: "checkpoint not found" });
|
|
100401
|
-
const current = readAcceptedForRequest(project.app, project.id, "read");
|
|
100402
|
-
if (current == null) return reply.status(409).send({ ok: false, error: "the current working copy is unreadable" });
|
|
100403
|
-
const suppliedEpoch = req.body && Object.prototype.hasOwnProperty.call(req.body, "expectedEpoch") ? req.body.expectedEpoch : void 0;
|
|
100404
|
-
if (typeof req.body?.expectedEtag !== "string" || suppliedEpoch !== null && (!Number.isInteger(Number(suppliedEpoch)) || Number(suppliedEpoch) < 0)) {
|
|
100405
|
-
return reply.status(428).send({ ok: false, error: "Reload Saved work and send the working ETag and revision epoch." });
|
|
100406
|
-
}
|
|
100407
|
-
if (!recordedEtagNamesContract(req.body.expectedEtag, storeEtags(project.app, project.id))) return reply.status(409).send({ ok: false, error: "The working copy changed. Reload Saved work." });
|
|
100408
|
-
const observedManifest = readWorkingRevisionManifest(project);
|
|
100409
|
-
if ((observedManifest?.epoch ?? null) !== (suppliedEpoch === null ? null : Number(suppliedEpoch))) return reply.status(409).send({ ok: false, error: "The working revision changed. Reload Saved work." });
|
|
100410
|
-
const publicationIdentity = saved.publicationIdentity;
|
|
100411
|
-
let manifest = ensureWorkingRevisionManifest({ project, publicationIdentity, contract: current, workingBase: saved.base });
|
|
100412
|
-
if (manifest.draftHash !== contractHash(current)) manifest = refreshWorkingDraftHash({ project, expectedEpoch: manifest.epoch, expectedDraftHash: manifest.draftHash, contract: current });
|
|
100413
|
-
const latest = approvedSnapshotForMetadata(project.id, "resuming saved work");
|
|
100414
|
-
if (!latest || comparableContractHash(current) !== comparableContractHash(latest.contract)) captureProjectCheckpoint({ project, publicationIdentity, base: manifest.workingBase, contract: current, revisionEpoch: manifest.epoch });
|
|
100415
|
-
let publication;
|
|
100416
|
-
try {
|
|
100417
|
-
publication = await writeContractGenerationChecked(project.app, saved.contract, project.id, "resume an explicitly selected saved-work checkpoint", { restoring: true });
|
|
100418
|
-
} catch (error) {
|
|
100419
|
-
return reply.status(409).send({ ok: false, error: error instanceof Error ? error.message : "checkpoint cannot be resumed" });
|
|
100420
|
-
}
|
|
100421
|
-
clearApproval(project.id);
|
|
100422
|
-
const next = advanceWorkingRevisionManifest({
|
|
100423
|
-
project,
|
|
100424
|
-
expectedEpoch: manifest.epoch,
|
|
100425
|
-
expectedDraftHash: manifest.draftHash,
|
|
100426
|
-
publicationIdentity,
|
|
100427
|
-
contract: normalisePlanViewIds(saved.contract),
|
|
100428
|
-
source: { kind: "checkpoint", checkpointId: saved.id, hash: saved.draftHash },
|
|
100429
|
-
workingBase: saved.base
|
|
100430
|
-
});
|
|
100431
|
-
broadcast(contractChangedWithReason(project.app, project.id, publication.etag, publication.storeRevision, "rollback"));
|
|
100432
|
-
return { ok: true, revision: next, checkpoint: saved, latestApprovedVersion: latest?.version.n ?? null };
|
|
100433
|
-
}, { label: "resuming saved work" });
|
|
100434
|
-
}
|
|
100435
|
-
);
|
|
100669
|
+
registerProjectRevisionStartRoutes(app, { broadcast });
|
|
100436
100670
|
app.get("/api/projects/:id/export-sources", async (req, reply) => {
|
|
100437
100671
|
const project = getProject(req.params.id);
|
|
100438
100672
|
if (!project) return reply.status(404).send({ ok: false, error: `unknown project: ${req.params.id}` });
|
|
@@ -100664,6 +100898,11 @@ async function startServer() {
|
|
|
100664
100898
|
resolveAppContract,
|
|
100665
100899
|
etagOf,
|
|
100666
100900
|
storeEtag,
|
|
100901
|
+
// Passed BY NAME, never composed here: an expression at this wiring site is one no test can reach
|
|
100902
|
+
// (every route test stubs the dep, every editor test stubs the fetch), and review proved that
|
|
100903
|
+
// rewriting it to an exact compare left the whole suite green while #957 was unfixed in production.
|
|
100904
|
+
// The composition and its tests live in project-contract-hash.
|
|
100905
|
+
recordedEtagsNameDocument,
|
|
100667
100906
|
postProcessVector: (doc) => postProcess(doc),
|
|
100668
100907
|
parseSelection: readSelectionFromBody,
|
|
100669
100908
|
genericBakeHostLabel,
|