feat(pgsql-types): add new package for narrowed PostgreSQL AST types #258
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.
feat(pgsql-types): add package for narrowed PostgreSQL AST types
Summary
This PR adds a new
pgsql-typespackage that generates narrowed TypeScript type definitions for PostgreSQL AST Node fields. Instead of using the genericNodeunion type (~250 types), fields are now typed with specific unions based on what actually appears in practice.For example,
DefElem.argchanges from:to:
The package includes:
scripts/infer-field-metadata.ts): Parses 496 SQL fixture files (67,572 statements) to discover which node types appear in each Node-typed fieldscripts/generate-types.ts): Generates 277 narrowed type aliases and interfacesfield-metadata.json(metadata) andtypes.ts(TypeScript definitions)Addresses: constructive-io/libpg-query-node#143
Updates since last revision
@pgsql/enumsto resolve missing type errors@pgsql/types- noCreateStmt_tableEltsnoise in autocomplete@pgsql/typesfor production, andDefElemusage exampleReview & Testing Checklist for Human
DefEleminterface insrc/types.tsshows the narrowed union inline (not referencing an exported type alias)npm pack --dry-runor check the exports - only interfaces and enums should be exported, not the internalNodeName_fieldNametype aliasescd packages/pgsql-types && npm run buildto verify the complete pipeline (infer → clean → tsc → copy)Recommended test plan:
cd packages/pgsql-types && npm run infer && npm run generatesrc/types.tscompiles:npx tsc --noEmittypes.tsusetype(notexport type)DefEleminterface matches the README exampleNotes
.d.tsoutput (TypeScript includes them so exported interfaces can reference them) - this is expected../../utils/src/runtime-schema- this works but is fragileLink to Devin run: https://app.devin.ai/sessions/db627c3d06d741d7b2ece147ce39f0d3
Requested by: Dan Lynch ([email protected]) / @pyramation