Skip to content

TML-3324: Parse view bodies as model fields only in Prisma 7 and Prisma 6 schemas - #30507

Merged
wmadden merged 11 commits into
mainfrom
tml-3324-view-body-parser-option
Sep 30, 2026
Merged

wmadden merged 11 commits into
mainfrom
tml-3324-view-body-parser-option

Conversation

@wmadden-electric

@wmadden-electric wmadden-electric commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Linked issue

Refs: TML-3324

Summary

A Prisma 7 schema can declare a view:

view ActiveUsers {
  id    Int    @unique
  email String @db.VarChar(255)
}

The Prisma 7 source refuses it with one error, PSL.PRISMA7_VIEW_UNSUPPORTED. To report one error, the parser has to read the lines of the view block as model fields. Until now the shared parser did that in every file, Prisma 8 files included, where view is not part of the language.

Decision: the parser names the grammar versions it reads. A PSL contract source declares which one its files are written in, through parserOptions.grammar: prisma-8 (the default) or prisma-7. In the prisma-7 grammar a view body parses as model fields.

export function prisma7Contract(schemaPath: string, options: Prisma7ContractOptions): ContractConfig {
  const parserOptions = { grammar: 'prisma-7' } as const;
  return {
    source: { format: 'psl', inputs: [schemaPath], parserOptions, async load(context) { /* parse(schema, file.sourceId, parserOptions) */ } },
    // …
  };
}

Prisma 6 schemas use the same grammar, so prisma6Contract declares prisma-7 too. A prisma-6 value gets added only if a Prisma 6 grammar difference turns up.

Every tool that parses a source's files passes the source's options to the parser:

  • The Prisma 7 and Prisma 6 MongoDB sources declare the grammar and pass it to their own parse calls. Their view errors and spans are unchanged.
  • prisma contract format passes source.parserOptions to format(), so it still formats a Prisma 7 schema that contains a view with attributed fields.
  • The language server reads the options from the config and passes them when it diagnoses and formats a file. It binds each stored document snapshot to a project's options once.
  • The config loader checks parserOptions. It reports a grammar it does not know, and an option key it does not know.

In a Prisma 8 file, a view body now parses as key = value entries, like any other block the parser does not know. Two things change for a user who writes one:

  • A field line with an attribute is a parse error (PSL_INVALID_EXTENSION_BLOCK_MEMBER), reported before the block error PSL_UNSUPPORTED_TOP_LEVEL_BLOCK, which is unchanged.
  • A field line without an attribute reads as two entries, so contract format writes id Int as id and Int on separate lines, as it does in any block it does not know.

PslGrammar and PslParserOptions live in @internal/config beside PslContractSourceProvider, which declares them. The parser already depends on that package. The framework vocabulary rule forbids names of Prisma versions before 8 in the framework; it now records one exception, the parser's own grammar names, and the three sites carry a suppression with that reason.

ADR 252, the config and parser READMEs, the two source READMEs and the project spec describe the grammar option.

Testing performed

  • Parser: parse-view-body.test.ts and the formatter tests cover a view body in the prisma-7 grammar and in the default grammar.
  • Sources: each Prisma 7 and Prisma 6 source test checks that it declares grammar: 'prisma-7'. The existing view fixtures still report the same codes and spans.
  • Prisma 8 sources: a test per family loads a file with a view block and asserts the full list of diagnostics.
  • contract format: a unit test uses a source that declares the grammar. A step in the Prisma 7 source journey formats a real Prisma 7 project with a view; it fails when the source does not declare the grammar.
  • Language server: tests diagnose and format a marked file under a source that declares the grammar, and check that an unmarked file is left alone. A project-level test checks that two projects reading the same open file each parse it with their own options, and parse it only once.
  • Config loader: tests report an unknown grammar, a non-object parserOptions, and a misspelled option key.
  • Ran the tests of the parser, config loader, language server, CLI, and the Prisma 7 and Prisma 6 sources. Ran lint, lint:deps, lint:throws, lint:framework-vocabulary, check:upgrade-coverage and typecheck.

Skill update

n/a. Users do not write parserOptions; the Prisma 7 and Prisma 6 sources set it. Those sources report the same view errors as before, and a view block in a Prisma 8 file is still refused.

Checklist

  • All commits are signed off (git commit -s) per the DCO.
  • I read CONTRIBUTING.md and the change is scoped to one logical concern.
  • Tests are updated.
  • The PR title is in TML-NNNN: <sentence-case title> form.
  • The Skill update section above is filled in.

Notes for the reviewer

One case gets worse and is filed as TML-3370. A Prisma 8 source whose input pattern also matches an unmarked Prisma 7 file skips that file, but contract format still formats it with the Prisma 8 grammar. A view in that file is now refused or split. The fix needs the source to declare which files it reads, which is a separate design question.

Alternatives considered:

  • A behaviour flag, viewBodyAsModelFields, instead of a grammar version. Rejected: the flag has no meaning on its own. It exists only because the Prisma 7 grammar reads view bodies that way, and nobody would set it on a Prisma 8 source. Naming the grammar says why, and absorbs any further Prisma 7 grammar difference without a second flag.
  • Each tool detects the dialect from the file, for example from a datasource block or a missing // use prisma-8 line. Rejected: every tool would repeat the detection, and a guess can be wrong.
  • Keep the rule on for every file. Rejected: Prisma 8's grammar would keep a rule that exists only for Prisma 7 and Prisma 6 files, and a pack could not claim the view keyword.
  • A parse function on the source instead of options. Rejected: more than the problem needs, and the config loader cannot check a function.

Agent: shaka-90

Summary by CodeRabbit

  • New Features
    • PSL contract sources can select Prisma 7 or Prisma 8 grammar for schema parsing. Prisma 8 remains the default; Prisma 7 reads view bodies as model fields.
    • Formatting and language-server tools use the grammar selected by the source.
    • Prisma 6 and Prisma 7 contract sources now use Prisma 7 grammar for consistent schema parsing.
  • Bug Fixes
    • Invalid grammar settings and parser options now produce specific configuration errors.
  • Documentation
    • Updated guidance explains grammar options and how each grammar parses view bodies.

…ma 6 schemas

A PSL contract source declares parserOptions. The Prisma 7 and Prisma 6 sources set viewBodyAsModelFields; contract format passes the source's options to the formatter. By default a view body parses as key = value entries.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…ests pin what users see

Addresses the code review: the language server reads parserOptions from the config and passes them when it diagnoses and formats; PslParseOptions is renamed PslParserOptions; the config loader rejects an unknown parser option; the Prisma 8 sources, the formatter and a Prisma 7 format journey have tests for a view block; ADR 252 and the config README describe the rule.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
wmadden-electric requested a review from a team as a code owner September 29, 2026 15:26
@coderabbitai

coderabbitai Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: prisma/orm/.coderabbit.yml

Review profile: CHILL

Plan: Advanced

Run ID: fd5f549c-1d8f-4b1c-bd48-e097366be00a

📥 Commits

Reviewing files that changed from the base of the PR and between 0bb5fb5 and 47e5508.

⛔ Files ignored due to path filters (1)
  • projects/prisma7-contract-source/spec.md is excluded by !projects/**
📒 Files selected for processing (5)
  • .agents/rules/no-family-vocabulary-in-framework.mdc
  • docs/architecture docs/adrs/ADR 252 - An earlier Prisma version's schema is a contract source.md
  • packages/1-framework/2-authoring/psl-parser/README.md
  • packages/1-framework/2-authoring/psl-parser/test/parse-view-body.test.ts
  • packages/1-framework/3-tooling/config-loader/test/orm-section.test.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/1-framework/2-authoring/psl-parser/README.md

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.


📝 Walkthrough

Walkthrough

PSL sources can declare parser options that select how view-body lines are parsed. The parser, formatter, CLI, and language server pass these options through. Prisma 6 and Prisma 7 sources declare the prisma-7 grammar.

Changes

Configurable PSL view parsing

Layer / File(s) Summary
Parser options and conditional view parsing
packages/1-framework/1-core/config/src/contract-source-types.ts, packages/1-framework/1-core/config/src/exports/config-types.ts, packages/1-framework/2-authoring/psl-parser/src/*, packages/1-framework/2-authoring/psl-parser/test/*, packages/1-framework/1-core/config/README.md, packages/1-framework/2-authoring/psl-parser/README.md, .agents/rules/no-family-vocabulary-in-framework.mdc, docs/architecture docs/adrs/ADR 252 - An earlier Prisma version's schema is a contract source.md
Adds PslGrammar and PslParserOptions. The parser uses model-member parsing for view bodies only with prisma-7; the default prisma-8 grammar uses key-value parsing. Tests cover both modes.
Prisma source parser options
packages/1-framework/3-tooling/config-loader/*, packages/2-mongo-family/2-authoring/contract-prisma6/*, packages/2-sql/2-authoring/contract-prisma7/*, packages/2-mongo-family/2-authoring/contract-psl/test/*, packages/2-sql/2-authoring/contract-psl/test/*
Config validation accepts prisma-7 and prisma-8. Prisma 6 and Prisma 7 sources declare and pass prisma-7. Contract tests check diagnostics for unsupported views.
CLI formatter option propagation
packages/1-framework/3-tooling/cli/src/control-api/operations/format.ts, packages/1-framework/3-tooling/cli/test/control-api/format.test.ts, test/integration/test/cli-journeys/prisma7-source.e2e.test.ts
The CLI passes source parser options to formatting. Tests cover configured view formatting and a Prisma 7 formatting journey.
Language-server option propagation
packages/1-framework/3-tooling/language-server/src/config-resolution.ts, packages/1-framework/3-tooling/language-server/src/document-snapshot.ts, packages/1-framework/3-tooling/language-server/src/project-artifacts.ts, packages/1-framework/3-tooling/language-server/src/project.ts, packages/1-framework/3-tooling/language-server/test/*
The language server resolves parser options and passes them to snapshots, parsing, and formatting. Tests cover configured and default grammar behavior.

Priority: ➖ Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant resolveConfigInputs
  participant Project
  participant ProjectArtifacts
  participant DocumentSnapshot
  participant parse
  resolveConfigInputs->>Project: returns parserOptions
  Project->>ProjectArtifacts: passes parserOptions
  ProjectArtifacts->>DocumentSnapshot: creates configured snapshot
  DocumentSnapshot->>parse: parses text with parserOptions
Loading

Suggested reviewers: sevinf

Merge Risk: ⚪ Minimal · up to 47e55

No actionable merge-blocking risk remains; files should be formatted using the grammar configured for their source.

Architecture Summary

Architecture risk: 🔵 Low · up to 47e55

The change affects 5 systems.

Changed systems: packages/1-framework, packages/2-mongo-family, packages/2-sql, docs, test

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — packages/1-framework (library) was modified; 24 changed files map to changed impact.
  • observed — packages/2-mongo-family (library) was modified; 5 changed files map to changed impact.
  • observed — packages/2-sql (library) was modified; 5 changed files map to changed impact.
  • observed — docs (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in packages/1-framework/2-authoring/psl-parser/src/format/format.ts: Added a type-only import of PslParserOptions.
  • observed — Modified behavior in packages/1-framework/2-authoring/psl-parser/src/format/format.ts: format adds an optional parserOptions parameter defaulting to {} and passes it to parse; previously parse was called without parser options.
  • observed — Modified behavior in packages/1-framework/2-authoring/psl-parser/test/format/fixtures/view-block-plain-fields/expected.prisma: The expected fixture defining the ActiveUsers view with id Int and email String fields was removed.
  • observed — Modified behavior in packages/1-framework/2-authoring/psl-parser/test/format/fixtures/view-block-plain-fields/input.prisma: The ActiveUsers view fixture, including its id Int and email String fields, was removed.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 25 functions across 32 files. (3 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: view bodies are parsed as model fields only for Prisma 7 and Prisma 6 schemas.
Full details: Docstring Coverage

Explanation

Docstring coverage is 28.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 25 functions across 32 files. (3 skipped: 3 unsupported.)

✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@prisma/orm-extension-arktype-json

npm i https://pkg.pr.new/@prisma/orm-extension-arktype-json@30507

@prisma/orm-extension-middleware-cache

npm i https://pkg.pr.new/@prisma/orm-extension-middleware-cache@30507

@prisma/orm-extension-paradedb

npm i https://pkg.pr.new/@prisma/orm-extension-paradedb@30507

@prisma/orm-extension-pgvector

npm i https://pkg.pr.new/@prisma/orm-extension-pgvector@30507

@prisma/orm-extension-postgis

npm i https://pkg.pr.new/@prisma/orm-extension-postgis@30507

@prisma/orm-extension-supabase

npm i https://pkg.pr.new/@prisma/orm-extension-supabase@30507

@prisma/orm-family-mongo

npm i https://pkg.pr.new/@prisma/orm-family-mongo@30507

@prisma/orm-family-sql

npm i https://pkg.pr.new/@prisma/orm-family-sql@30507

@prisma/orm-framework

npm i https://pkg.pr.new/@prisma/orm-framework@30507

@prisma/orm-mongo

npm i https://pkg.pr.new/@prisma/orm-mongo@30507

@prisma/orm-postgres

npm i https://pkg.pr.new/@prisma/orm-postgres@30507

@prisma/orm-sqlite

npm i https://pkg.pr.new/@prisma/orm-sqlite@30507

@prisma/orm-target-mongo

npm i https://pkg.pr.new/@prisma/orm-target-mongo@30507

@prisma/orm-target-postgres

npm i https://pkg.pr.new/@prisma/orm-target-postgres@30507

@prisma/orm-target-sqlite

npm i https://pkg.pr.new/@prisma/orm-target-sqlite@30507

@prisma/orm-toolchain

npm i https://pkg.pr.new/@prisma/orm-toolchain@30507

commit: f99a6ad

@github-actions

github-actions Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
postgres / no-emit 209.22 KB (0%)
postgres / emit 187.53 KB (0%)
mongo / no-emit 194.5 KB (0%)
mongo / emit 173.93 KB (0%)
cf-worker / no-emit 264.52 KB (0%)
cf-worker / emit 240.28 KB (0%)

…-view-body-parser-option

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>

# Conflicts:
#	packages/1-framework/3-tooling/language-server/src/config-resolution.ts
#	packages/1-framework/3-tooling/language-server/src/document-diagnostics.ts
#	packages/1-framework/3-tooling/language-server/src/pipeline.ts
#	packages/1-framework/3-tooling/language-server/src/project-artifacts.ts
#	packages/1-framework/3-tooling/language-server/test/server.test.ts
…er stored snapshot

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
… the artifacts load into project.ts

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…-body flag

The parser option is grammar: 'prisma-7' | 'prisma-8', default prisma-8. In the prisma-7 grammar a view body parses as model fields. The Prisma 7 and Prisma 6 sources declare prisma-7, since Prisma 6 schemas use the same grammar. The parser is the authority on its own grammar, so its grammar names may name the Prisma version; the vocabulary rule records that exception.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…cabulary check

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…the grammar option; tests cover an explicit prisma-8

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden
wmadden enabled auto-merge September 30, 2026 16:12
Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden
wmadden added this pull request to the merge queue Sep 30, 2026
Merged via the queue into main with commit de72393 Sep 30, 2026
27 checks passed
@wmadden
wmadden deleted the tml-3324-view-body-parser-option branch September 30, 2026 16:52
wmadden-electric added a commit that referenced this pull request Oct 1, 2026
This brings in seven main commits: the rc.14 release, Mongo values
through their field's codecs (#30519), `sql` as the tag of
sql/expression (#30534), view bodies parsed as fields only in Prisma 7
and 6 schemas (#30507), and three docs and CI changes.

Both sides' rules hold after the merge.
- Mongo codecs: main's encode checks and this branch's decodeJson
  readers are combined, and the int32 bounds use INT32_RANGE.
- One test codec from main now has the decodeJson that mongoCodec
  requires.
- contract-psl: main's tag reading and sql/expression default replace
  the lowering entry. This branch's stored-value reader, InternalError
  rethrows, list-column and value-object default checks, and
  CodecLookupWithDescriptors are kept.
- A value-object default of the wrong shape uses main's renamed code,
  PSL_VALUE_TYPE_INCOMPATIBLE. A Uuid default the text-to-uuid cast
  refuses is PSL_INVALID_LITERAL, like any other cast refusal.

Signed-off-by: willbot <[email protected]>
Signed-off-by: Will Madden <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

2 participants