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
Re-importing an edited document currently has no way to tell an updated request from a new one, because every import mints fresh model IDs. Give each imported resource a key that identifies its source element instead, so a later import can match against what it already created. `ImportResponse` gains an optional `sourceKeys` map, keyed by the resource IDs plugins already emit. A parallel map keeps `ImportResources` and the partial TS types unchanged. Bundled importers emit keys where the format carries them: Postman item IDs, Insomnia `_id`s, OpenAPI `operationId` (falling back to the route), and Yaak model IDs. curl has no identity of its own, so it emits none. Planning derives a key for anything left over, hashed from the model type, folder ancestry, and name or method+URL, prefixed `fb:` so later code can tell derived keys from importer-provided ones. These break when the source document renames or moves a resource, which is accepted. Keys land in `ImportPlan.source_keys`, keyed by minted model ID so the mapping stays lossless, ready for the commit step to persist. Nothing consumes them yet. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5
parent
fce1039bac
commit
333e3c1653
@@ -1,6 +1,6 @@
|
||||
import type { Context, PluginDefinition } from "@yaakapp/api";
|
||||
import YAML from "yaml";
|
||||
import { deleteUndefinedAttrs, isJSObject } from "./common";
|
||||
import { deleteUndefinedAttrs, isJSObject, sourceKeysFromResources } from "./common";
|
||||
import { convertInsomniaV4 } from "./v4";
|
||||
import { convertInsomniaV5 } from "./v5";
|
||||
|
||||
@@ -32,6 +32,10 @@ export function convertInsomnia(contents: string) {
|
||||
if (!isJSObject(parsed)) return null;
|
||||
|
||||
const result = convertInsomniaV5(parsed) ?? convertInsomniaV4(parsed);
|
||||
if (result == null) return null;
|
||||
|
||||
return deleteUndefinedAttrs(result);
|
||||
return deleteUndefinedAttrs({
|
||||
...result,
|
||||
sourceKeys: sourceKeysFromResources(result.resources),
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user