Skip to content

Give exported connection files an explicit wire-format type#1822

Draft
kmcginnes wants to merge 1 commit into
simplify-configuration-mergefrom
explicit-exported-connection-type
Draft

Give exported connection files an explicit wire-format type#1822
kmcginnes wants to merge 1 commit into
simplify-configuration-mergefrom
explicit-exported-connection-type

Conversation

@kmcginnes

Copy link
Copy Markdown
Collaborator

Description

Slice 1 of retiring the legacy RawConfiguration "god object". The exported connection-file format (saveConfigurationToFileisValidConfigurationFile on import) borrowed the in-memory configuration shape via Pick<ConfigurationContextProps, "id"|"displayLabel"|"connection"|"schema">. That borrowing is what keeps the unused in-memory RawConfiguration.schema field 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), and lastUpdate is 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.ts wire format). 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 with the "Invalid File" toast. The Zod schema enforces the shape declaratively and stays lenient about unknown/legacy fields, so styling and prefix __matches still pass through on import (the import hook reads the original parsed object, not the schema's output).

Suggested reading order:

  1. isValidConfigurationFile.ts — the new ExportedConnectionFile type and the Zod validator that replaces the throw-prone imperative loops (core change).
  2. saveConfigurationToFile.ts — now explicitly typed as ExportedConnectionFile.
  3. useImportConnectionFile.ts — drops now-redundant optional chaining on the guaranteed schema.
  4. Tests + CONTEXT.md glossary entry.

One accepted, tiny behavior change: a connection-less export now emits connection.url: "" instead of omitting url (forced by the strict type; aligns the writer with the validator, which already requires url). 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 checks passes (lint, format, types).
  • pnpm test passes — full suite, 1793 tests.
  • New tests pin the malformed-schema rejection (previously threw), the save→validate round-trip, and the url: "" asymmetry. Backward-compat pins for legacy imports and backups stay green.

Related Issues

Check List

  • I confirm that my contribution is made under the terms of the Apache 2.0 license.
  • I have verified `pnpm checks` passes with no errors.
  • I have verified `pnpm test` passes with no failures.
  • I have covered new added functionality with unit tests if necessary.
  • I have updated documentation if necessary.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant