ENG-1977 Add schema import data layer for Obsidian - #1264
Conversation
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
| template: | ||
| importedNodeType.template && | ||
| (selectedTemplateNames.has(importedNodeType.template) || | ||
| matchPlan.existingTemplateNames.has(importedNodeType.template)) | ||
| ? importedNodeType.template | ||
| : undefined, |
There was a problem hiding this comment.
🟡 Imported node type loses its template link when the template already exists in the vault but wasn't part of the imported file
A newly imported node type drops its template reference (matchPlan.existingTemplateNames.has(...) at apps/obsidian/src/utils/specImport.ts:336) whenever the referenced template exists locally but is not itself listed in the imported schema file, so the link is silently cleared even though the template is present in the vault.
Impact: A node type that should point at an existing local template ends up with no template, so notes created from it won't apply the expected template.
Why the local-existence check is too narrow
The preservation condition at apps/obsidian/src/utils/specImport.ts:333-338 keeps importedNodeType.template only if it is in selectedTemplateNames or in matchPlan.existingTemplateNames. existingTemplateNames is built in buildSchemaImportMatchPlan (apps/obsidian/src/utils/specImport.ts:176-181) by iterating schemaFile.templates and intersecting with the local template names — i.e. it only contains templates that are BOTH in the schema file AND present locally.
However, the exporter (apps/obsidian/src/utils/specExport.ts:92-95) includes only the templates explicitly selected for export, independent of which templates the exported node types reference. So a node type can be exported with template: "Foo" while "Foo" is not in schemaFile.templates. If "Foo" happens to exist locally in the importing vault, existingTemplateNames will not contain it, selectedTemplateNames won't either, and the reference is set to undefined — contradicting the intended behavior of retaining a template reference when the template already exists locally.
A correct check would compare importedNodeType.template against the full set of local template names (available at apps/obsidian/src/utils/specImport.ts:237), not just the schema∩local intersection.
Prompt for agents
In applySchemaImportSelection (apps/obsidian/src/utils/specImport.ts), the new node type's template reference is only preserved when the template name is in selectedTemplateNames or matchPlan.existingTemplateNames. matchPlan.existingTemplateNames is the intersection of the schema file's templates and the local vault templates, so a node type that references a template which exists locally but was NOT included in the schema file's templates array loses its reference. To fix, thread the full set of local template names (the localTemplateNames set computed in pickAndPreviewSchemaImport) into the match plan (e.g. store it on SchemaImportMatchPlan) and check the node's template against that full local set, so a reference to any locally-existing template is preserved regardless of whether the template was part of the imported file.
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
Fixed: added localTemplateNames to SchemaImportMatchPlan and changed the template-preservation check from matchPlan.existingTemplateNames (schema∩local intersection) to matchPlan.localTemplateNames (full local set). A node type that references a template present in the vault but not in the imported file now correctly retains its template link.
3af9adf to
f364d5a
Compare
… set, not schema intersection
23c69c1 to
d417d43
Compare
Summary
Adds the import data layer — file parsing, match planning, and apply logic. The UI modal is in the next PR.
specImport.ts— three responsibilities co-located:parseDgSchemaFile— lightweight version guard + cast (no Zod; export is the authoritative source)buildSchemaImportMatchPlan— computes id and name/label mappings between the schema file and the local vault in one pass; id match first, name/label fallback secondapplySchemaImportSelection— creates new items asprovisional, skips existing matches; preserves template reference when template already exists locallyStack
PR 4 of 5 for FEE-840. Stacks on #1263.
Test plan
pnpm --filter @discourse-graphs/obsidian check-typespassesparseDgSchemaFilerejects files with wrong version with a clear errorbuildSchemaImportMatchPlanid-matches first, name/label fallback secondapplySchemaImportSelectioncreates new items asprovisional, skips duplicates