mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-09-09 19:31:57 +02:00
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:
co-authored by
Claude Opus 5
parent
e63a87718c
commit
81a2a5d955
@@ -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) {
|
||||
|
||||
@@ -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",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user