Files
FreeCADWasmDev/web/src/web-link-contract.ts
wangdequan 9a7c4f0335 Save FreeCAD Web workspace sources and user validation evidence
IFC native binding remains incomplete; preserve accurate test results.
2026-09-15 22:01:58 +08:00

21 lines
1.6 KiB
TypeScript

export const nativeLinkCommands = ["Std_LinkActions", "Std_LinkMake", "Std_LinkMakeGroup", "Std_LinkMakeRelative", "Std_LinkReplace", "Std_LinkUnlink", "Std_LinkImport", "Std_LinkImportAll", "Std_LinkSelectActions", "Std_LinkSelectAllLinks", "Std_LinkSelectLinked", "Std_LinkSelectLinkedFinal"];
export function isNativeLinkCommand(command: string): boolean {
return nativeLinkCommands.includes(command);
}
export function validLinkResult(value: unknown, command: string, documentId: string): boolean {
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
const result = value as Record<string, unknown>;
if (["Std_LinkMakeRelative", "Std_LinkReplace", "Std_LinkUnlink"].includes(command)
&& (!Array.isArray(result.parents) || !["read", "apply"].includes(String(result.action))
|| result.parents.some(item => !item || typeof item.documentId !== "string"
|| typeof item.object !== "string" || typeof item.label !== "string"))) return false;
return result.command === command && result.documentId === documentId
&& typeof result.changed === "boolean" && Array.isArray(result.selection)
&& result.selection.every(item => item && typeof item.documentId === "string"
&& typeof item.object === "string" && item.object.length > 0
&& (item.subelements === undefined || (Array.isArray(item.subelements)
&& item.subelements.every((name: unknown) => typeof name === "string"))))
&& (result.changedDocuments === undefined || (Array.isArray(result.changedDocuments)
&& result.changedDocuments.every(name => typeof name === "string")));
}