Skip to content

Generate content mapper types from json schema - #65565

Merged
Gabriela Araujo Britto (gabritto) merged 8 commits into
mainfrom
gabritto/gen-content-mapper
Nov 19, 2026
Merged

Gabriela Araujo Britto (gabritto) merged 8 commits into
mainfrom
gabritto/gen-content-mapper

Conversation

@gabritto

Copy link
Copy Markdown
Member

Similar to what we do for AST, this PR introduces a JSON schema for the content mapper protocol types, and a script for producing Go types from the schema.

Content mapper implementers can then import the schema from our TypeScript package, and generate types/validation for whatever implementation language they're using.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The schema is missing from package exports and rejects supported null mappings, preventing intended imports and causing validators to reject valid mapper responses.

2 open issues
2 files not reviewed
  • tsc/internal/contentmapper/protocol_generated.go: Generated file
  • tsc/internal/spanmap/types_generated.go: Generated file
What changed in this PR

This PR introduces a shared JSON schema for the content mapper protocol, intended for mapper implementers to consume from the TypeScript package. It generates protocol and span-map types from that schema instead of maintaining them separately.

Changes:

  • Adds the schema, generator, and generated Go and TypeScript types.
  • Replaces raw JSON mappings with typed tuples and adds serialization and validation tests.
  • Integrates generation and code-generation checks into Hereby tasks.
File Description
tsc/​internal/​testutil/​contentmappertest/​transforming.go Returns typed mapping tuples.
tsc/​internal/​testutil/​contentmappertest/​synthesizing.go Uses tuples for synthesized output.
tsc/​internal/​testutil/​contentmappertest/​supplemental_diagnostics.go Uses typed supplemental mappings.
tsc/​internal/​testutil/​contentmappertest/​protocol.go Converts identity mappings to tuples.
tsc/​internal/​testutil/​contentmappertest/​lisp.go Uses typed Lisp mappings.
tsc/​internal/​testutil/​contentmappertest/​hoisting.go Returns typed hoisting mappings.
tsc/​internal/​testutil/​contentmappertest/​editing.go Migrates editing fixtures to tuples.
tsc/​internal/​testutil/​contentmappertest/​duplicate.go Migrates duplicate-mapping fixtures to tuples.
tsc/​internal/​testutil/​contentmappertest/​component.go Returns typed component mappings.
tsc/​internal/​spanmap/​types_generated.go Adds generated span-map types and constants.
tsc/​internal/​spanmap/​spanmap.go Adds tuple conversion helpers; removes handwritten types.
tsc/​internal/​spanmap/​spanmap_test.go Tests tuple round trips and invalid lengths.
tsc/​internal/​contentmapper/​protocol_generated.go Adds generated protocol types and tuple serialization.
tsc/​internal/​contentmapper/​hostimpl.go Uses generated types and decodes typed mappings.
tsc/​internal/​contentmapper/​host_test.go Tests mapping JSON and malformed tuples.
tools/​scripts/​tsc/​generate-enums.ts Sources span-map enums from the schema.
tools/​scripts/​tsc/​generate-contentmapper.ts Generates protocol and span-map types.
packages/​typescript/​src/​ast/​spanMapTypes.generated.ts Adds generated TypeScript span-map types.
packages/​typescript/​src/​ast/​spanMap.ts Imports and re-exports generated types.
packages/​typescript/​schemas/​contentmapper.schema.json Defines protocol methods, payloads, and mappings.
packages/​typescript/​enums/​spanMapKind.js Updates the generation-source comment only.
packages/​typescript/​enums/​spanMapKind.d.ts Updates the generation-source comment only.
packages/​typescript/​enums/​spanMapFidelity.js Updates the generation-source comment only.
packages/​typescript/​enums/​spanMapFidelity.d.ts Updates the generation-source comment only.
packages/​typescript/​enums/​spanMapFeature.js Updates the generation-source comment only.
packages/​typescript/​enums/​spanMapFeature.d.ts Uses equivalent numeric literals from the schema.
Herebyfile.mjs Adds content-mapper generation and expands code-generation checks.

Review effort: Balanced

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The new schema is missing from build watch paths, leaving generated bindings and the compiler stale after edits, and codegen tests do not verify the three generated artifacts.

2 open issues
2 resolved since last review
2 files not reviewed
  • tsc/internal/contentmapper/protocol_generated.go: Generated file
  • tsc/internal/spanmap/types_generated.go: Generated file

Review effort: Balanced

Comment thread Herebyfile.mjs Resolved

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The way the .Tuples() feature cleans up the test package is really nice too. Thank you!

Merged via the queue into main with commit 95a2462 Nov 19, 2026
34 checks passed
@gabritto
Gabriela Araujo Britto (gabritto) deleted the gabritto/gen-content-mapper branch November 19, 2026 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Author: Team For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants