33 lines
3.2 KiB
TypeScript
33 lines
3.2 KiB
TypeScript
export interface FormatRuntimeIndex {
|
|
schema: "freecad-web-format-runtime-index/v1";
|
|
source: { inventory: string; inventoryRecords: number; inventorySha256: string };
|
|
fields: { modules: string[]; directions: string[]; kinds: string[] };
|
|
records: [string, number, number, string, number, number][];
|
|
}
|
|
|
|
export interface FormatRuntimeRecord { id: string; module: string; kind: string; name: string; direction: string; evidenceCount: number; }
|
|
|
|
export function decodeFormatRuntimeRecord(index: FormatRuntimeIndex, row: FormatRuntimeIndex["records"][number]): FormatRuntimeRecord {
|
|
return { id: row[0], module: index.fields.modules[row[1]] ?? "", kind: index.fields.kinds[row[2]] ?? "", name: row[3], direction: index.fields.directions[row[4]] ?? "", evidenceCount: row[5] };
|
|
}
|
|
|
|
export function createFormatRuntimeLookup(index: FormatRuntimeIndex): Map<string, FormatRuntimeRecord> {
|
|
return new Map(index.records.map((row) => { const record = decodeFormatRuntimeRecord(index, row); return [record.id, record] as const; }));
|
|
}
|
|
|
|
export interface FormatActionRoute { module: string; command: string; worker?: string; reason: string; }
|
|
|
|
export function resolveFormatAction(record: FormatRuntimeRecord): FormatActionRoute | undefined {
|
|
if (record.kind !== "extension") return undefined;
|
|
if (record.module === "Import" && [".step", ".stp", ".iges", ".igs"].includes(record.name) && record.direction === "import") return { module: "Import", command: "import.step", reason: "native Import STEP/IGES route" };
|
|
if (record.module === "Part" && [".brep", ".brp"].includes(record.name)) return { module: "Part", command: "part.importExport", worker: "part.worker.ts", reason: "native Part BREP route" };
|
|
if (record.module === "Part" && record.name === ".fcstd") return { module: "Part", command: "part.saveReopen", worker: "part-save.worker.ts", reason: "native Part FCStd round-trip route" };
|
|
if (record.module === "Mesh" && [".stl", ".obj", ".ply", ".off", ".3mf", ".amf"].includes(record.name)) return { module: "Mesh", command: "mesh.importExport", reason: "native Mesh import/export route" };
|
|
if (record.module === "TechDraw" && [".svg", ".dxf"].includes(record.name)) return { module: "TechDraw", command: "techdraw.nativeImportExport", worker: "techdraw-native.worker.ts", reason: "native TechDraw projection route" };
|
|
if (record.module === "Draft" && [".svg", ".dxf"].includes(record.name)) return { module: "Draft", command: "draft.formatBatch", worker: "draft.worker.ts", reason: "native Draft geometry format route" };
|
|
if (record.module === "OpenSCAD" && record.name.toLowerCase() === ".dxf" && record.direction === "import") return { module: "OpenSCAD", command: "openscad.importDxf", worker: "openscad.worker.ts", reason: "native OpenSCAD DXF face import route" };
|
|
if (record.module === "Spreadsheet" && record.name === ".fcstd") return { module: "Spreadsheet", command: "spreadsheet.saveReopen", worker: "spreadsheet-save.worker.ts", reason: "native Spreadsheet FCStd route" };
|
|
if (record.module === "Spreadsheet" && record.name.toLowerCase() === ".csv") return { module: "Spreadsheet", command: "spreadsheet.importExportCsv", worker: "spreadsheet.worker.ts", reason: "native Spreadsheet CSV import/export route" };
|
|
return undefined;
|
|
}
|