Skip to content

cypher-codegen: type-check generated query output under Effect v4#83

Merged
jbmusso merged 2 commits into
mainfrom
effect-v4-codegen-fix
Jun 4, 2026
Merged

cypher-codegen: type-check generated query output under Effect v4#83
jbmusso merged 2 commits into
mainfrom
effect-v4-codegen-fix

Conversation

@jbmusso

@jbmusso jbmusso commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Summary

Generated cypher-codegen query code did not type-check under Effect v4. This branch fixes the generator so its output compiles cleanly, and adds a compile guard so the class of regression can't silently return.

The previous unit tests only asserted on the emitted source string — they never compiled it — so "generated code fails tsc" could never surface as a failing test. Adding a real compile guard immediately surfaced three distinct type errors in generated output, all fixed here.

Fixes

  • Row decoding — dropped the untyped Neo4jRecordToObject schema transform (its composition with the Row struct didn't satisfy decodeTo's getter under v4). record.toObject() is now called in the Effect pipeline and each row is validated directly with Schema.Array(Row), so the struct fully type-checks the decoded shape.
  • TemporalString transform — inferred Transformation<string, string>, which didn't match its Schema.Unknown source. Now emits explicit SchemaTransformation.transform<string, unknown> type parameters. The unknown is confined to the encoded boundary (the opaque neo4j temporal object); decoded values stay string.
  • Module params — single-file modules emitted untyped destructured params (an implicit any under strict). Resolved param types are now threaded through generateModule and annotated, matching the barrel output via a shared queryParams helper. VitePlugin and Register forward the analyzer's resolved params.

Test guard

New CypherCodegen.typecheck.node.unit.test.ts runs the TypeScript checker over generateModule and generateBarrel output (using the repo's real compiler options) and asserts zero diagnostics — covering scalars, Neo4jInt, nullable, temporal, list, map, the Neo4jValue escape hatch, and typed params. Adds typescript as a package devDependency.

Notes

  • The only residual unknown/any in generated output is the encoded side of TemporalString, the deliberate Neo4jValue escape hatch, and the no-schema untyped fallback (which has no param types to emit). Consumer-facing decoded/param types are fully typed.

Verification

  • All 218 cypher-codegen unit tests pass (including the new guard).
  • tsc -b clean, lint clean.

Changeset

patch for @evryg/effect-cypher-codegen.

jbmusso and others added 2 commits June 4, 2026 22:50
Generated query modules failed to compile under Effect v4 in three ways:

- Row decoding emitted an untyped Neo4jRecordToObject schema transform whose
  composition with the Row struct did not satisfy decodeTo's getter. Drop it:
  call record.toObject() in the Effect pipeline and validate each row directly
  with Schema.Array(Row), so the struct fully type-checks the decoded shape.
- The TemporalString transform inferred Transformation<string, string>, which
  did not match its Schema.Unknown source. Emit explicit
  SchemaTransformation.transform<string, unknown> type parameters.
- Single-file modules emitted untyped destructured params, an implicit any
  under strict mode. Thread resolved param types through generateModule and
  annotate them, matching the barrel output (shared via a queryParams helper).

VitePlugin and Register now forward the analyzer's resolved params so module
output is fully typed.

Generated with AI

Co-Authored-By: AI <ai@example.com>
The existing unit tests only assert on the emitted source string, so a
regression where generated code fails to type-check could never surface as a
failing test. Add a guard that runs the TypeScript checker over generateModule
and generateBarrel output (using the repo's real compiler options) and asserts
zero diagnostics — covering scalars, Neo4jInt, nullable, temporal, list, map,
the Neo4jValue escape hatch, and typed params.

Generated with AI

Co-Authored-By: AI <ai@example.com>
@jbmusso
jbmusso force-pushed the effect-v4-codegen-fix branch from dfbe850 to 8d03b0b Compare June 4, 2026 21:01
@jbmusso
jbmusso merged commit 6b43ff8 into main Jun 4, 2026
8 checks passed
@github-actions github-actions Bot mentioned this pull request Jun 4, 2026
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