[5] Doppelspur Door/Opening aufgeloest: Formatversion 2 migriert Legacy-Tueren zu Oeffnungen (kind door), Project.doors und Door entfernt, Legacy-Pfade in Plan/Schnitt/Ansicht/3D/Liste gestrichen; Tests angepasst
This commit is contained in:
1 parent
346798eee6
commit
b0270bae3e
94 files changed
+100
-367
No files matched your search
@@ -31,11 +31,11 @@ describe("Projektdatei-Format", () => {
|
||||
expect(!r.ok && r.error).toMatch(/walls/);
|
||||
});
|
||||
it("tolerant: fehlende Listen ergaenzt, falsche Typen geleert, unbekannte Felder gemeldet und behalten", () => {
|
||||
const { doors: _d, ...rest } = sampleProject;
|
||||
const { lineStyles: _l, ...rest } = sampleProject;
|
||||
const r = parseProjectFile(JSON.stringify({ ...rest, hatches: "x", zukunft: 1 }));
|
||||
expect(r.ok).toBe(true);
|
||||
if (!r.ok) return;
|
||||
expect(r.project.doors).toEqual([]);
|
||||
expect(r.project.lineStyles).toEqual([]);
|
||||
expect(r.project.hatches).toEqual([]);
|
||||
expect((r.project as unknown as { zukunft: number }).zukunft).toBe(1);
|
||||
expect(r.warnings.join(" ")).toMatch(/hatches/);
|
||||
@@ -45,3 +45,25 @@ describe("Projektdatei-Format", () => {
|
||||
expect(parseProjectFile(JSON.stringify({ ...sampleProject, formatVersion: "1" })).ok).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Migration 1 → 2: Legacy-Türen werden Öffnungen", () => {
|
||||
it("doors → openings (kind door), Feld doors entfällt, Kollisions-ids bleiben eindeutig", () => {
|
||||
const base = JSON.parse(JSON.stringify(sampleProject)) as Record<string, unknown>;
|
||||
const existing = (base.openings as Array<{ id: string }>)[0].id;
|
||||
base.formatVersion = 1;
|
||||
base.doors = [
|
||||
{ id: "TX", type: "door", hostWallId: "W1", categoryCode: "21", position: 0.5, width: 0.9, height: 2.1, swing: "right", hinge: "end" },
|
||||
{ id: existing, type: "door", hostWallId: "W1", categoryCode: "21", position: 3, width: 0.8, height: 2, swing: "left", hinge: "start" },
|
||||
];
|
||||
const r = parseProjectFile(JSON.stringify(base));
|
||||
expect(r.ok).toBe(true);
|
||||
if (!r.ok) return;
|
||||
expect(r.migratedFrom).toBe(1);
|
||||
expect("doors" in r.project).toBe(false);
|
||||
const ids = (r.project.openings ?? []).map((o) => o.id);
|
||||
expect(new Set(ids).size).toBe(ids.length);
|
||||
const tx = r.project.openings!.find((o) => o.id === "TX")!;
|
||||
expect(tx).toMatchObject({ kind: "door", position: 0.5, width: 0.9, height: 2.1, sillHeight: 0, swing: "right", hinge: "end", type: "opening" });
|
||||
expect(r.project.openings!.some((o) => o.id === `${existing}-t` && o.kind === "door")).toBe(true);
|
||||
});
|
||||
});
|
||||
+33
-3
@@ -15,7 +15,7 @@
|
||||
import type { Project } from "../model/types";
|
||||
|
||||
/** Aktuelle Version des Dateiformats. Bei jeder Formatänderung erhöhen + Migration anhängen. */
|
||||
export const PROJECT_FORMAT_VERSION = 1;
|
||||
export const PROJECT_FORMAT_VERSION = 2;
|
||||
|
||||
/**
|
||||
* Migrationen: `MIGRATIONS[i]` hebt eine Datei von Version `i` auf `i + 1`. Arbeitet auf dem
|
||||
@@ -24,19 +24,49 @@ export const PROJECT_FORMAT_VERSION = 1;
|
||||
const MIGRATIONS: Array<(raw: Record<string, unknown>) => Record<string, unknown>> = [
|
||||
// 0 → 1: Einführung von `formatVersion`; Inhalt unverändert.
|
||||
(raw) => raw,
|
||||
// 1 → 2: Legacy-Türen (`doors`) werden zu Öffnungen (`openings`, kind "door"). Es gibt nur noch
|
||||
// EINEN Datensatz-Typ für Türen und Fenster.
|
||||
(raw) => {
|
||||
const doors = Array.isArray(raw.doors) ? (raw.doors as Array<Record<string, unknown>>) : [];
|
||||
const { doors: _drop, ...rest } = raw;
|
||||
if (doors.length === 0) return rest;
|
||||
const openings = Array.isArray(rest.openings) ? [...(rest.openings as Array<Record<string, unknown>>)] : [];
|
||||
const taken = new Set(openings.map((o) => String(o.id)));
|
||||
const doorTypes = Array.isArray(rest.doorTypes) ? (rest.doorTypes as Array<{ id?: string }>) : [];
|
||||
for (const d of doors) {
|
||||
let id = String(d.id);
|
||||
while (taken.has(id)) id = `${id}-t`;
|
||||
taken.add(id);
|
||||
openings.push({
|
||||
id,
|
||||
type: "opening",
|
||||
hostWallId: d.hostWallId,
|
||||
categoryCode: d.categoryCode,
|
||||
kind: "door",
|
||||
position: d.position,
|
||||
width: d.width,
|
||||
height: d.height,
|
||||
sillHeight: 0,
|
||||
swing: d.swing,
|
||||
hinge: d.hinge,
|
||||
...(doorTypes[0]?.id ? { typeId: doorTypes[0].id } : {}),
|
||||
});
|
||||
}
|
||||
return { ...rest, openings };
|
||||
},
|
||||
];
|
||||
|
||||
/** Pflichtlisten: fehlen sie, ist es kein Dossier-Projekt. */
|
||||
const REQUIRED_ARRAYS = ["walls", "layers", "drawingLevels"] as const;
|
||||
/** Listen, die bei Fehlen leer ergänzt werden. */
|
||||
const DEFAULT_ARRAYS = ["lineStyles", "hatches", "components", "wallTypes", "doors", "drawings2d"] as const;
|
||||
const DEFAULT_ARRAYS = ["lineStyles", "hatches", "components", "wallTypes", "drawings2d"] as const;
|
||||
|
||||
/** Bekannte Felder von `Project` (für die Meldung unbekannter Felder). */
|
||||
const KNOWN_KEYS = new Set<string>([
|
||||
"formatVersion", "id", "name", "lineStyles", "textStyles", "hatches", "components", "wallTypes",
|
||||
"ceilingTypes", "roofTypes", "blockDefs", "doorTypes", "windowTypes", "stairTypes", "pens",
|
||||
"penSets", "activePenSetId", "customPalettes", "builtinPaletteBanks", "drawingLevels", "layers",
|
||||
"walls", "ceilings", "roofs", "doors", "openings", "stairs", "rooms", "drawings2d", "context",
|
||||
"walls", "ceilings", "roofs", "openings", "stairs", "rooms", "drawings2d", "context",
|
||||
"extrudedSolids", "columns", "groups", "parametricWalls", "overrideRules", "viewSnapshots",
|
||||
"viewSnapshotFolders", "layouts", "masterLayouts", "layoutFolders", "referenceElevationMasl",
|
||||
"geoAnchor",
|
||||
|
||||
Reference in new issue
Block a user