Give exported connection files an explicit wire-format type#1822
Draft
kmcginnes wants to merge 1 commit into
Draft
Give exported connection files an explicit wire-format type#1822kmcginnes wants to merge 1 commit into
kmcginnes wants to merge 1 commit into
Conversation
The file validator and saver borrowed the in-memory configuration shape (Pick<ConfigurationContextProps, ...>), which is what kept the unused in-memory RawConfiguration.schema field alive. Introduce an explicit ExportedConnectionFile type so the on-disk format is honest and can evolve independently: schema is required, and lastUpdate is typed as the ISO string it actually is on disk. Replace the hand-rolled validator with a Zod schema. The old imperative version asserted the stronger type but never checked that schema.vertices / schema.edges were arrays before iterating them, so a malformed file threw an uncaught TypeError instead of being rejected. The Zod schema enforces the shape declaratively and stays lenient about unknown/legacy fields so styling and prefix __matches still pass through on import. Add a save-then-validate round-trip test pinning the writer/reader contract, and pin the accepted connection-less url:"" asymmetry. Document the Exported Connection File wire format in CONTEXT.md.
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Slice 1 of retiring the legacy
RawConfiguration"god object". The exported connection-file format (saveConfigurationToFile→isValidConfigurationFileon import) borrowed the in-memory configuration shape viaPick<ConfigurationContextProps, "id"|"displayLabel"|"connection"|"schema">. That borrowing is what keeps the unused in-memoryRawConfiguration.schemafield alive, so it blocks the later slices.This gives the on-disk format its own honest type,
ExportedConnectionFile, decoupled from the in-memory and persisted shapes so the wire format can evolve independently. Schema is required (not optional), andlastUpdateis typed as the ISO string it actually is on disk.While here, the hand-rolled validator is replaced with a Zod schema (matching the sibling
exportedGraph.tswire format). The old imperative version asserted the stronger type but never checked thatschema.vertices/schema.edgeswere arrays before iterating them, so a malformed file threw an uncaughtTypeErrorinstead of being rejected with the "Invalid File" toast. The Zod schema enforces the shape declaratively and stays lenient about unknown/legacy fields, so styling and prefix__matchesstill pass through on import (the import hook reads the original parsed object, not the schema's output).Suggested reading order:
isValidConfigurationFile.ts— the newExportedConnectionFiletype and the Zod validator that replaces the throw-prone imperative loops (core change).saveConfigurationToFile.ts— now explicitly typed asExportedConnectionFile.useImportConnectionFile.ts— drops now-redundant optional chaining on the guaranteedschema.CONTEXT.mdglossary entry.One accepted, tiny behavior change: a connection-less export now emits
connection.url: ""instead of omittingurl(forced by the strict type; aligns the writer with the validator, which already requiresurl). This is a not-actually-reachable state and is pinned by a test noting it should disappear in a later slice.This is the first of three stacked PRs. Slice 2 removes
RawConfiguration.schema; slice 3 migrates the storage type.Validation
pnpm checkspasses (lint, format, types).pnpm testpasses — full suite, 1793 tests.url: ""asymmetry. Backward-compat pins for legacy imports and backups stay green.Related Issues
Check List