Datasets: URL→inline conversion drops url/fetchedAt

This commit is contained in:
2026-06-11 19:26:47 +03:00
parent fe2b039698
commit 181b9da8ab
2 changed files with 30 additions and 6 deletions
+15 -6
View File
@@ -291,11 +291,9 @@ export const useDatasetStore = create<DatasetState>((set, get) => ({
data: resolved.data,
format: resolved.format,
source: resolved.source,
// TODO: `update` shallow-merges, so these set the keys to `undefined`
// rather than removing them — a URL→inline record keeps `url`/`fetchedAt`
// present-but-undefined. Invisible today (rendering/profiling key off
// `source`/`data == null`, and JSON export drops undefined), but it breaks
// the "inline records carry no url/fetchedAt keys" invariant on this path.
// A URL→inline conversion must shed the remote origin; `update` deletes
// keys set to `undefined`, so these are removed rather than left
// present-but-undefined.
url: undefined,
fetchedAt: undefined,
comment: form.comment,
@@ -415,7 +413,18 @@ export const useDatasetStore = create<DatasetState>((set, get) => ({
update: (id, patch, now) => {
const modified = patch.modified ?? (now ?? new Date()).toISOString();
set((s) => ({
datasets: s.datasets.map((d) => (d.id === id ? { ...d, ...patch, modified } : d)),
datasets: s.datasets.map((d) => {
if (d.id !== id) return d;
const merged = { ...d, ...patch, modified };
// A patch key set to `undefined` removes it, rather than leaving a
// present-but-undefined key — so a URL→inline conversion drops `url`/
// `fetchedAt` cleanly, keeping the "inline records carry no remote-origin
// keys" invariant (docs/architecture/07 §6).
for (const key of Object.keys(patch) as (keyof Dataset)[]) {
if (patch[key] === undefined) delete merged[key];
}
return merged;
}),
}));
},