feat(import): add stable per-resource source keys to the importer contract (#614)

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Gregory Schier
2026-09-01 08:11:54 -07:00
committed by GitHub
co-authored by Claude Opus 5
parent e63a87718c
commit 81a2a5d955
28 changed files with 785 additions and 49 deletions
+9 -1
View File
@@ -80,7 +80,15 @@ export function migrateImport(contents: string) {
}
}
return { resources: parsed.resources };
const sourceKeys: Record<string, string> = {};
for (const models of Object.values(parsed.resources)) {
if (!Array.isArray(models)) continue;
for (const model of models) {
if (typeof model?.id === "string") sourceKeys[model.id] = model.id;
}
}
return { resources: parsed.resources, sourceKeys };
}
function isJSObject(obj: unknown) {
+28
View File
@@ -148,4 +148,32 @@ describe("importer-yaak", () => {
}),
);
});
test("Keys models by their Yaak ID, unchanged by a rename", () => {
const exported = (requestName: string) =>
JSON.stringify({
yaakSchema: 5,
resources: {
workspaces: [{ id: "wk_1", model: "workspace", name: "Keys" }],
httpRequests: [
{
id: "rq_1",
model: "http_request",
workspaceId: "wk_1",
name: requestName,
url: "https://yaak.app",
},
],
},
});
expect(migrateImport(exported("Original"))?.sourceKeys).toEqual({
wk_1: "wk_1",
rq_1: "rq_1",
});
expect(migrateImport(exported("Renamed"))?.sourceKeys).toEqual({
wk_1: "wk_1",
rq_1: "rq_1",
});
});
});