Skip to content

feat(semantics): extract statement-classification facts into @pgsql/semantics - #334

Merged
pyramation merged 1 commit into
mainfrom
feat/pgsql-semantics
Aug 2, 2026
Merged

feat(semantics): extract statement-classification facts into @pgsql/semantics#334
pyramation merged 1 commit into
mainfrom
feat/pgsql-semantics

Conversation

@pyramation

Copy link
Copy Markdown
Collaborator

Summary

Extracts the statement-classification facts layer out of @pgsql/transform into a new package, @pgsql/semantics. This is a move, not a redesign — no new API surface. What moved is semantics (which relations/functions/types a statement reads and creates, which namespaces it touches, security relevance), which had grown up inside @pgsql/transform as a gate for bundle namespace validation but is not itself transformation.

facts.ts moves across verbatim (543 lines, unchanged) along with its test. @pgsql/transform now depends on @pgsql/semantics and re-exports the same symbols from the same path, so every existing consumer — this repo's own qualify/restructure/naming/graph drivers, @pgpmjs/transform's categorize.ts, and any other — is untouched. The transform-specific rewriting drivers stay in @pgsql/transform.

What moved

packages/transform/src/facts.tspackages/semantics/src/facts.ts (git-tracked as a rename of the test; the source shows as add+delete because the transform-side file is replaced by a re-export stub). Includes classifyStatements and the types StatementFacts, StatementKind, QualifiedName, ExtensionFact, ExtensionAction, StatementSpan. Its test (facts.test.ts, 16 cases) moved too.

What stayed

Everything transform-specific: transformSql, SchemaRouter/RoleRouter/extension routers, qualifyUnqualified, round-trip validation, buildStatementGraph, identityOf, restructureSql, etc.

Compatibility seam

@pgsql/transform's internal drivers import classifyStatements/StatementFacts from ./facts, and its index.ts re-exports them. Rather than repoint every import, transform/src/facts.ts becomes a one-line re-export so both the public path and internal paths keep working:

// packages/transform/src/facts.ts
export * from '@pgsql/semantics';

New package

@pgsql/semantics follows the sibling-package layout exactly (copied from @pgsql/traverse/@pgsql/quotes): same package.json scripts (tsc CJS + ESM, makage assets), tsconfig.json/tsconfig.esm.json, jest.config.js, .gitignore, publishConfig.directory: dist. Dependencies are @pgsql/traverse + plpgsql-parser (what facts.ts actually imports). Version starts at 18.0.0. Added to the CI test matrix in .github/workflows/run-tests.yaml.

Verification

  • pnpm build — all packages compile (CJS + ESM).
  • pnpm --filter @pgsql/semantics test — 16 passed; pnpm --filter @pgsql/transform test — 236 passed.
  • Full repo test run: only @pgsql/cli fails ("No tests found"), which is preexisting on main and not in the CI matrix.
  • pnpm lint — no new errors.
  • Lockfile updated minimally (workspace link: entries only; regenerated with pnpm 9 to match CI and verified with --frozen-lockfile).

Link to Devin session: https://app.devin.ai/sessions/af81a09043504701874ca63e67a9cd4b
Requested by: @pyramation

…emantics

Move facts.ts (classifyStatements + StatementFacts and friends) verbatim out of @pgsql/transform into a new @pgsql/semantics package. @pgsql/transform depends on it and re-exports the same symbols from src/facts.ts, so all existing consumers are unaffected. Transform-specific rewriting drivers stay in @pgsql/transform.
@pyramation pyramation self-assigned this Aug 2, 2026
@devin-ai-integration

Copy link
Copy Markdown
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

@pyramation
pyramation merged commit 630a57c into main Aug 2, 2026
14 checks passed
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