Skip to content
This repository was archived by the owner on Nov 25, 2026. It is now read-only.

TML-2956: migrate 7 SQL attributes to declarative attribute specs - #932

Merged
SevInf merged 14 commits into
mainfrom
tml-2956-sql-attributes
Jul 9, 2026
Merged

SevInf merged 14 commits into
mainfrom
tml-2956-sql-attributes

Conversation

@SevInf

@SevInf SevInf commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Linked issue

Refs TML-2956 — "Language Tools Support Prisma Next PSL".

Second of three slices under that ticket. Builds on the attribute-spec kit + @relation migration shipped in #891 (slice 1). @default was split mid-flight into a follow-up slice sql-default (see Reviewer notes).

At a glance

SQL attributes now declare their argument grammar as data instead of hand-parsing it. @@index, for example:

const indexModelSpec = modelAttribute('index', {
  positional: [{ key: 'fields', type: list(fieldRef('self'), { nonEmpty: true, unique: true }) }],
  named: { map: optional(str()), type: optional(str()), options: optional(record(str())) },
  refine: (value, ctx) =>
    value.options !== undefined && value.type === undefined
      ? [leafDiagnostic(ctx, ctx.selfModel.node, '`@@index` options argument requires a type argument')]
      : [],
});

Previously each attribute had a bespoke string-scanning parser (parseAttributeFieldList, parseObjectLiteralStringMap, parseControlPolicyAttribute, …) that re-tokenised already-parsed PSL text by hand. The kit interprets the real AST, so field-existence, list non-emptiness, uniqueness, and object-literal shape all fall out of the combinators.

Decision

This PR makes every SQL attribute except @default spec-driven, and grows the shared attribute-spec kit with the combinators those attributes need:

  1. Migrated attributes — @map/@@map, @id/@unique, @@id/@@unique, @@index, @@control, @@discriminator, @@base are now interpreted through AttributeSpecs in packages/2-sql/2-authoring/contract-psl/src/sql-attribute-specs.ts. Only argument syntax moved to specs; the interpreter keeps every semantic check (column mapping, applicability, duplicate-attribute guards, polymorphism resolution).
  2. Kit growth (in @prisma-next/psl-parser) — a modelAttribute constructor plus int, bool, record, and entityRef combinators, each unit-tested in isolation before their first consumer landed.
  3. Dead-code removal — ten hand-written string-parsing helpers deleted once their last caller migrated, net −711 lines in the SQL package's parsing surface.

@default — the most complex attribute — was split into a follow-up slice rather than bundled here; see Reviewer notes.

How it fits together

  1. Grow the kit first. modelAttribute (mirroring the existing fieldAttribute) lets model-level @@ attributes be specced; int/bool/record/entityRef are leaf combinators added right before the attribute that first needs them. Each ships with combinator unit tests in packages/1-framework/2-authoring/psl-parser/test/attribute-spec-combinators.test.ts.
  2. SQL-side plumbing. sql-attribute-specs.ts holds the specs plus small interpret* helpers that locate the attribute's AST node (findModelAttributeNode/findFieldAttributeNode), build the interpret context, run interpretAttribute, and either return the typed result or push the kit's diagnostics.
  3. Route the interpreter. interpreter.ts and psl-field-resolution.ts call those helpers instead of the legacy parsers. Where a legacy branch fused two attributes (the shared @@unique/@@index field-list path), it was split so each attribute migrates independently.
  4. Delete the dead helpers. After each attribute's last caller moved to a spec, its parser was removed and rg-confirmed to have zero remaining callers — the @db.* native-type helpers and the three @default-only helpers are deliberately retained.

Behavior changes & evidence

  • Attribute-argument syntax errors now report a single unified code. Malformed arguments (non-string @map, non-list @@id, unknown @@index option, bad @@control policy word) surface PSL_INVALID_ATTRIBUTE_SYNTAX from the kit rather than the old per-parser PSL_INVALID_ATTRIBUTE_ARGUMENT. Semantic diagnostics keep their codes. See sql-attribute-specs.ts; evidence in interpreter.diagnostics.test.ts.
  • @@index object-literal options are parsed structurally. The new record(str()) combinator replaces the hand-rolled brace/colon scanner; options-requires-type moved to the spec's refine. See combinators/record.ts; evidence in attribute-spec-combinators.test.ts.
  • @@discriminator unknown-field now reports PSL_INVALID_ATTRIBUTE_SYNTAX. Modelling the field via fieldRef('self') folds field-existence into the parse, unifying it with how @@id/@@unique/@@index already report unknown fields; the now-unreachable SQL PSL_DISCRIMINATOR_FIELD_NOT_FOUND block was removed. See interpreter.ts; evidence in interpreter.polymorphism.test.ts.
  • Two attribute spellings intentionally narrowed to their canonical forms — the named @@index(fields: […]) form (positional-only now) and the quoted @@control("external") form (bare-identifier only). Both are invisible in practice: no in-repo schema, fixture, or example uses either. Rationale recorded in the slice spec.

Reviewer notes

  • Largest diff: psl-attribute-parsing.ts (−314) and interpreter.ts (±279). The former is almost entirely deletions (the retired parsers); the latter is the branch-by-branch routing to specs. The one non-mechanical change in interpreter.ts is the @@unique/@@index branch split — worth spot-checking that @@index behaviour is byte-for-byte preserved (it stays on the legacy path in this PR).
  • @default deliberately excluded. It introduces a novel registry-parameterised funcCall combinator plus six preserved semantic codes; bundling it would push this PR past a single coherent review. It ships in the follow-up slice sql-default. Consequently the three @default-only helpers (parseDefaultLiteralValue, parseDefaultFunctionCall, parseListDefaultExpression) are retained here.
  • @@index refine diagnostic anchors to the model node, not the attribute span. The kit's refine(value, ctx) signature carries no attribute node; no test asserts that span, so parity holds. Widening the signature is a future kit tidy-up, not in scope.
  • Mongo is untouched. Its own PSL_DISCRIMINATOR_FIELD_NOT_FOUND and parsers remain — the Mongo family migrates in slice 3.
  • Project artefacts on disk. projects/typed-attribute-parsers/slices/sql-attributes/ (spec, plan, per-dispatch briefs) is included for review provenance and will be migrated/removed at project close-out.

Verification

Run on final HEAD:

  • pnpm --filter @prisma-next/psl-parser build && typecheck — clean; 584 tests
  • pnpm --filter @prisma-next/sql-contract-psl typecheck — clean; 283 tests
  • pnpm fixtures:check — clean, no contract/migration drift
  • pnpm lint:framework-vocabulary — 906/906
  • pnpm lint:deps — 0 layering violations (1169 modules cruised)

Follow-ups

  • sql-default slice — migrate @default (funcCall/registry + literal/enum/list leaves), delete the three retained default helpers.
  • Mongo attribute migration — slice 3.

Alternatives considered

  • Preserve the named @@index(fields: […]) and quoted @@control("external") spellings by declaring the arg in both positional and named forms. Rejected: the engine supports it, but it carries dual-spelling complexity forever for forms no in-repo schema uses; the canonical positional/bare-identifier forms are what Prisma emits.
  • Keep @@discriminator field-existence as a dedicated semantic check (PSL_DISCRIMINATOR_FIELD_NOT_FOUND) by parsing only the bare name. Rejected in favour of fieldRef('self') for consistency with the other model field-list attributes; the dedicated code became redundant.
  • Ship @default in this PR as the last dispatch. Rejected on size — its novel combinator surface and semantic-code count warranted its own reviewable slice.

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.
  • Skill update: n/a — internal refactor; no user-facing CLI/API/config/error-code surface changed (attribute-syntax error codes consolidated, documented in the slice spec).

Summary by CodeRabbit

  • New Features
    • Added support for additional PSL attribute value types: booleans, integers, model name references, and record/object arguments.
    • Introduced model-level attribute specifications to improve how model annotations are parsed and interpreted.
  • Bug Fixes
    • Improved PSL syntax validation and normalized diagnostic codes/messages for invalid or duplicate inputs across constraints, mappings, indexing, control policies, and polymorphism.
    • Enhanced attribute interpretation to be more syntax-accurate for better span reporting.
  • Tests
    • Expanded and updated coverage for the new value types, model-level behavior, and updated diagnostic expectations.

@SevInf
SevInf requested a review from a team as a code owner July 8, 2026 14:59
@coderabbitai

coderabbitai Bot commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@SevInf, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 49 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 1e9835e1-5b33-49b5-8dc6-259026cb4905

📥 Commits

Reviewing files that changed from the base of the PR and between 1344d43 and 69b7e7f.

⛔ Files ignored due to path filters (8)
  • projects/typed-attribute-parsers/slices/sql-attributes/dispatches/01-model-attribute-kit.md is excluded by !projects/**
  • projects/typed-attribute-parsers/slices/sql-attributes/dispatches/02-map.md is excluded by !projects/**
  • projects/typed-attribute-parsers/slices/sql-attributes/dispatches/03-id-unique.md is excluded by !projects/**
  • projects/typed-attribute-parsers/slices/sql-attributes/dispatches/04-index.md is excluded by !projects/**
  • projects/typed-attribute-parsers/slices/sql-attributes/dispatches/05-control.md is excluded by !projects/**
  • projects/typed-attribute-parsers/slices/sql-attributes/dispatches/06-polymorphism.md is excluded by !projects/**
  • projects/typed-attribute-parsers/slices/sql-attributes/plan.md is excluded by !projects/**
  • projects/typed-attribute-parsers/slices/sql-attributes/spec.md is excluded by !projects/**
📒 Files selected for processing (20)
  • packages/1-framework/2-authoring/psl-parser/src/attribute-spec/combinators/bool.ts
  • packages/1-framework/2-authoring/psl-parser/src/attribute-spec/combinators/entity-ref.ts
  • packages/1-framework/2-authoring/psl-parser/src/attribute-spec/combinators/int.ts
  • packages/1-framework/2-authoring/psl-parser/src/attribute-spec/combinators/record.ts
  • packages/1-framework/2-authoring/psl-parser/src/attribute-spec/model-attribute.ts
  • packages/1-framework/2-authoring/psl-parser/src/exports/index.ts
  • packages/1-framework/2-authoring/psl-parser/src/syntax/ast/qualified-name.ts
  • packages/1-framework/2-authoring/psl-parser/test/attribute-spec-combinators.test.ts
  • packages/1-framework/2-authoring/psl-parser/test/attribute-spec.test-d.ts
  • packages/1-framework/2-authoring/psl-parser/test/syntax/ast.test.ts
  • packages/2-sql/2-authoring/contract-psl/src/interpreter.ts
  • packages/2-sql/2-authoring/contract-psl/src/psl-attribute-parsing.ts
  • packages/2-sql/2-authoring/contract-psl/src/psl-field-resolution.ts
  • packages/2-sql/2-authoring/contract-psl/src/psl-relation-resolution.ts
  • packages/2-sql/2-authoring/contract-psl/src/sql-attribute-specs.ts
  • packages/2-sql/2-authoring/contract-psl/test/interpreter.control-policy.test.ts
  • packages/2-sql/2-authoring/contract-psl/test/interpreter.diagnostics.test.ts
  • packages/2-sql/2-authoring/contract-psl/test/interpreter.polymorphism.test.ts
  • packages/2-sql/2-authoring/contract-psl/test/interpreter.test.ts
  • packages/2-sql/2-authoring/contract-psl/test/psl-attribute-parsing.test.ts
📝 Walkthrough

Walkthrough

This PR adds new PSL attribute-spec combinators and a model-level attribute factory, and rewires contract-psl to interpret model and field attributes through node-based specs. It also updates diagnostic expectations and removes legacy parsing helpers.

Changes

PSL Attribute Combinators

Layer / File(s) Summary
bool and int literal combinators
.../combinators/bool.ts, .../combinators/int.ts, .../exports/index.ts, test/attribute-spec-combinators.test.ts
Adds bool() and int() combinators parsing boolean/integer AST literals into typed results, re-exports new combinators, and adds tests.
entityRef combinator
.../combinators/entity-ref.ts, test/attribute-spec-combinators.test.ts
Adds entityRef() parsing bare identifiers into model-name strings, with rejection tests for other token types.
record combinator
.../combinators/record.ts, test/attribute-spec-combinators.test.ts
Adds record() parsing object literals into Record<string, T> with duplicate/missing-key diagnostics, plus tests.
modelAttribute factory and type tests
.../attribute-spec/model-attribute.ts, test/attribute-spec.test-d.ts
Adds ModelAttributeConfig and modelAttribute() factory for model-level AttributeSpecs, exported and type-tested.
QualifiedName simple-name helper
.../syntax/ast/qualified-name.ts, test/syntax/ast.test.ts
Adds QualifiedNameAst.isSimpleName() and tests its matching behavior for bare and qualified names.

SQL Attribute Interpretation Refactor

Layer / File(s) Summary
New sql-attribute-specs interpretation helpers
src/sql-attribute-specs.ts
Adds attribute node lookups, interpretation-context helpers, typed wrappers, and attribute specs for model and field interpretation.
interpreter.ts model attribute wiring
src/interpreter.ts
Switches model-attribute processing to node-based interpret* helpers, threads sourceFile, and removes prior manual duplicate/discriminator validation.
Field and relation resolution via interpreters
src/psl-field-resolution.ts, src/psl-relation-resolution.ts
Updates constraint, mapping, and relation-attribute resolution to use the new interpreters with sourceFile threaded through.
Removal of legacy attribute-parsing helpers
src/psl-attribute-parsing.ts
Removes field-list, map, object-literal-string-map, and control-policy parsing helpers, keeping only remaining shared utilities.
Updated diagnostic code/message expectations
test/interpreter.control-policy.test.ts, test/interpreter.diagnostics.test.ts, test/interpreter.polymorphism.test.ts, test/interpreter.test.ts
Updates expected diagnostic codes/messages to PSL_INVALID_ATTRIBUTE_SYNTAX and revises the affected interpreter tests.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related PRs

  • prisma/prisma-next#805: Both PRs modify packages/2-sql/2-authoring/contract-psl/src/interpreter.ts and related model-building flow.
  • prisma/prisma-next#891: Adds the core attribute-spec combinator infrastructure that the new bool, int, record, entityRef, and modelAttribute helpers build on.

Suggested reviewers: wmadden, aqrln

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 12.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main refactor: migrating seven SQL attributes to declarative attribute specs.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch tml-2956-sql-attributes

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@pkg-pr-new

pkg-pr-new Bot commented Jul 8, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@prisma-next/extension-author-tools

npm i https://pkg.pr.new/@prisma-next/extension-author-tools@932

@prisma-next/mongo-runtime

npm i https://pkg.pr.new/@prisma-next/mongo-runtime@932

@prisma-next/family-mongo

npm i https://pkg.pr.new/@prisma-next/family-mongo@932

@prisma-next/sql-runtime

npm i https://pkg.pr.new/@prisma-next/sql-runtime@932

@prisma-next/family-sql

npm i https://pkg.pr.new/@prisma-next/family-sql@932

@prisma-next/extension-arktype-json

npm i https://pkg.pr.new/@prisma-next/extension-arktype-json@932

@prisma-next/middleware-cache

npm i https://pkg.pr.new/@prisma-next/middleware-cache@932

@prisma-next/mongo

npm i https://pkg.pr.new/@prisma-next/mongo@932

@prisma-next/extension-paradedb

npm i https://pkg.pr.new/@prisma-next/extension-paradedb@932

@prisma-next/extension-pgvector

npm i https://pkg.pr.new/@prisma-next/extension-pgvector@932

@prisma-next/extension-postgis

npm i https://pkg.pr.new/@prisma-next/extension-postgis@932

@prisma-next/postgres

npm i https://pkg.pr.new/@prisma-next/postgres@932

@prisma-next/sql-orm-client

npm i https://pkg.pr.new/@prisma-next/sql-orm-client@932

@prisma-next/sqlite

npm i https://pkg.pr.new/@prisma-next/sqlite@932

@prisma-next/extension-supabase

npm i https://pkg.pr.new/@prisma-next/extension-supabase@932

@prisma-next/target-mongo

npm i https://pkg.pr.new/@prisma-next/target-mongo@932

@prisma-next/adapter-mongo

npm i https://pkg.pr.new/@prisma-next/adapter-mongo@932

@prisma-next/driver-mongo

npm i https://pkg.pr.new/@prisma-next/driver-mongo@932

@prisma-next/contract

npm i https://pkg.pr.new/@prisma-next/contract@932

@prisma-next/utils

npm i https://pkg.pr.new/@prisma-next/utils@932

@prisma-next/config

npm i https://pkg.pr.new/@prisma-next/config@932

@prisma-next/errors

npm i https://pkg.pr.new/@prisma-next/errors@932

@prisma-next/framework-components

npm i https://pkg.pr.new/@prisma-next/framework-components@932

@prisma-next/operations

npm i https://pkg.pr.new/@prisma-next/operations@932

@prisma-next/ts-render

npm i https://pkg.pr.new/@prisma-next/ts-render@932

@prisma-next/contract-authoring

npm i https://pkg.pr.new/@prisma-next/contract-authoring@932

@prisma-next/ids

npm i https://pkg.pr.new/@prisma-next/ids@932

@prisma-next/psl-parser

npm i https://pkg.pr.new/@prisma-next/psl-parser@932

@prisma-next/psl-printer

npm i https://pkg.pr.new/@prisma-next/psl-printer@932

@prisma-next/cli

npm i https://pkg.pr.new/@prisma-next/cli@932

@prisma-next/cli-telemetry

npm i https://pkg.pr.new/@prisma-next/cli-telemetry@932

@prisma-next/config-loader

npm i https://pkg.pr.new/@prisma-next/config-loader@932

@prisma-next/emitter

npm i https://pkg.pr.new/@prisma-next/emitter@932

@prisma-next/language-server

npm i https://pkg.pr.new/@prisma-next/language-server@932

@prisma-next/migration-tools

npm i https://pkg.pr.new/@prisma-next/migration-tools@932

prisma-next

npm i https://pkg.pr.new/prisma-next@932

@prisma-next/vite-plugin-contract-emit

npm i https://pkg.pr.new/@prisma-next/vite-plugin-contract-emit@932

@prisma-next/mongo-codec

npm i https://pkg.pr.new/@prisma-next/mongo-codec@932

@prisma-next/mongo-contract

npm i https://pkg.pr.new/@prisma-next/mongo-contract@932

@prisma-next/mongo-value

npm i https://pkg.pr.new/@prisma-next/mongo-value@932

@prisma-next/mongo-contract-psl

npm i https://pkg.pr.new/@prisma-next/mongo-contract-psl@932

@prisma-next/mongo-contract-ts

npm i https://pkg.pr.new/@prisma-next/mongo-contract-ts@932

@prisma-next/mongo-emitter

npm i https://pkg.pr.new/@prisma-next/mongo-emitter@932

@prisma-next/mongo-schema-ir

npm i https://pkg.pr.new/@prisma-next/mongo-schema-ir@932

@prisma-next/mongo-query-ast

npm i https://pkg.pr.new/@prisma-next/mongo-query-ast@932

@prisma-next/mongo-orm

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

@prisma-next/mongo-query-builder

npm i https://pkg.pr.new/@prisma-next/mongo-query-builder@932

@prisma-next/mongo-lowering

npm i https://pkg.pr.new/@prisma-next/mongo-lowering@932

@prisma-next/mongo-wire

npm i https://pkg.pr.new/@prisma-next/mongo-wire@932

@prisma-next/sql-contract

npm i https://pkg.pr.new/@prisma-next/sql-contract@932

@prisma-next/sql-errors

npm i https://pkg.pr.new/@prisma-next/sql-errors@932

@prisma-next/sql-operations

npm i https://pkg.pr.new/@prisma-next/sql-operations@932

@prisma-next/sql-schema-ir

npm i https://pkg.pr.new/@prisma-next/sql-schema-ir@932

@prisma-next/sql-contract-psl

npm i https://pkg.pr.new/@prisma-next/sql-contract-psl@932

@prisma-next/sql-contract-ts

npm i https://pkg.pr.new/@prisma-next/sql-contract-ts@932

@prisma-next/sql-contract-emitter

npm i https://pkg.pr.new/@prisma-next/sql-contract-emitter@932

@prisma-next/sql-lane-query-builder

npm i https://pkg.pr.new/@prisma-next/sql-lane-query-builder@932

@prisma-next/sql-relational-core

npm i https://pkg.pr.new/@prisma-next/sql-relational-core@932

@prisma-next/sql-builder

npm i https://pkg.pr.new/@prisma-next/sql-builder@932

@prisma-next/target-postgres

npm i https://pkg.pr.new/@prisma-next/target-postgres@932

@prisma-next/target-sqlite

npm i https://pkg.pr.new/@prisma-next/target-sqlite@932

@prisma-next/adapter-postgres

npm i https://pkg.pr.new/@prisma-next/adapter-postgres@932

@prisma-next/adapter-sqlite

npm i https://pkg.pr.new/@prisma-next/adapter-sqlite@932

@prisma-next/driver-postgres

npm i https://pkg.pr.new/@prisma-next/driver-postgres@932

@prisma-next/driver-sqlite

npm i https://pkg.pr.new/@prisma-next/driver-sqlite@932

commit: 69b7e7f

@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown

size-limit report 📦

Path Size
postgres / no-emit 149.75 KB (0%)
postgres / emit 127.19 KB (0%)
mongo / no-emit 98.36 KB (0%)
mongo / emit 89.39 KB (0%)
cf-worker / no-emit 176.55 KB (0%)
cf-worker / emit 151.7 KB (0%)

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (1)
packages/2-sql/2-authoring/contract-psl/test/interpreter.test.ts (1)

786-787: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low value

Assertion is now code-only — consider keeping a message check.

The previous assertion matched a specific "missing colon" message via regex. The new assertion only checks d.code === 'PSL_INVALID_ATTRIBUTE_SYNTAX', which is less precise — a regression in the diagnostic message content would go undetected. If the record combinator's message is stable, consider adding a d.message check alongside the code assertion.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/2-sql/2-authoring/contract-psl/test/interpreter.test.ts` around
lines 786 - 787, The diagnostic assertion in interpreter.test.ts is now too
broad because it only checks PSL_INVALID_ATTRIBUTE_SYNTAX and can miss
regressions in the actual error text. Update the failing assertion around the
record combinator parsing case in the relevant test so it also verifies
d.message contains the expected “missing colon” wording (or equivalent stable
text) alongside the existing code check. Keep the check scoped to the same
result.failure.diagnostics.some(...) assertion used in the test.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@packages/2-sql/2-authoring/contract-psl/test/interpreter.test.ts`:
- Around line 786-787: The diagnostic assertion in interpreter.test.ts is now
too broad because it only checks PSL_INVALID_ATTRIBUTE_SYNTAX and can miss
regressions in the actual error text. Update the failing assertion around the
record combinator parsing case in the relevant test so it also verifies
d.message contains the expected “missing colon” wording (or equivalent stable
text) alongside the existing code check. Keep the check scoped to the same
result.failure.diagnostics.some(...) assertion used in the test.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 7113f90d-7157-4b17-863a-d841493cbd4f

📥 Commits

Reviewing files that changed from the base of the PR and between f44cbcb and 224f716.

⛔ Files ignored due to path filters (8)
  • projects/typed-attribute-parsers/slices/sql-attributes/dispatches/01-model-attribute-kit.md is excluded by !projects/**
  • projects/typed-attribute-parsers/slices/sql-attributes/dispatches/02-map.md is excluded by !projects/**
  • projects/typed-attribute-parsers/slices/sql-attributes/dispatches/03-id-unique.md is excluded by !projects/**
  • projects/typed-attribute-parsers/slices/sql-attributes/dispatches/04-index.md is excluded by !projects/**
  • projects/typed-attribute-parsers/slices/sql-attributes/dispatches/05-control.md is excluded by !projects/**
  • projects/typed-attribute-parsers/slices/sql-attributes/dispatches/06-polymorphism.md is excluded by !projects/**
  • projects/typed-attribute-parsers/slices/sql-attributes/plan.md is excluded by !projects/**
  • projects/typed-attribute-parsers/slices/sql-attributes/spec.md is excluded by !projects/**
📒 Files selected for processing (17)
  • packages/1-framework/2-authoring/psl-parser/src/attribute-spec/combinators/bool.ts
  • packages/1-framework/2-authoring/psl-parser/src/attribute-spec/combinators/entity-ref.ts
  • packages/1-framework/2-authoring/psl-parser/src/attribute-spec/combinators/int.ts
  • packages/1-framework/2-authoring/psl-parser/src/attribute-spec/combinators/record.ts
  • packages/1-framework/2-authoring/psl-parser/src/attribute-spec/model-attribute.ts
  • packages/1-framework/2-authoring/psl-parser/src/exports/index.ts
  • packages/1-framework/2-authoring/psl-parser/test/attribute-spec-combinators.test.ts
  • packages/1-framework/2-authoring/psl-parser/test/attribute-spec.test-d.ts
  • packages/2-sql/2-authoring/contract-psl/src/interpreter.ts
  • packages/2-sql/2-authoring/contract-psl/src/psl-attribute-parsing.ts
  • packages/2-sql/2-authoring/contract-psl/src/psl-field-resolution.ts
  • packages/2-sql/2-authoring/contract-psl/src/sql-attribute-specs.ts
  • packages/2-sql/2-authoring/contract-psl/test/interpreter.control-policy.test.ts
  • packages/2-sql/2-authoring/contract-psl/test/interpreter.diagnostics.test.ts
  • packages/2-sql/2-authoring/contract-psl/test/interpreter.polymorphism.test.ts
  • packages/2-sql/2-authoring/contract-psl/test/interpreter.test.ts
  • packages/2-sql/2-authoring/contract-psl/test/psl-attribute-parsing.test.ts
💤 Files with no reviewable changes (2)
  • packages/2-sql/2-authoring/contract-psl/test/psl-attribute-parsing.test.ts
  • packages/2-sql/2-authoring/contract-psl/src/psl-attribute-parsing.ts

@SevInf
SevInf force-pushed the tml-2956-sql-attributes branch from 86e1ce3 to 1344d43 Compare July 9, 2026 09:13
SevInf added 14 commits July 9, 2026 09:16
…plan, D1 brief, review scaffold

Signed-off-by: Serhii Tatarintsev <[email protected]>
Grow the attribute-spec kit so model-level attributes can be interpreted.

- modelAttribute(name, config): model-level analogue of fieldAttribute,
  fixing level to 'model' with the same positional/named/refine shape
  and AttributeOut inference.
- int(): parses an integer NumberLiteralExpr to number; non-integer or
  non-number arguments produce the standard leaf diagnostic.
- bool(): parses a BooleanLiteralExpr to boolean; otherwise a leaf
  diagnostic.

Unit and type-level tests cover success and diagnostic paths, and pin
that modelAttribute infers the same shape as fieldAttribute.

Signed-off-by: Serhii Tatarintsev <[email protected]>
Replace parseMapName with declarative modelAttribute/fieldAttribute specs
interpreted through the combinator kit. Invalid @Map arguments now surface
PSL_INVALID_ATTRIBUTE_SYNTAX instead of PSL_INVALID_ATTRIBUTE_ARGUMENT.

Signed-off-by: Serhii Tatarintsev <[email protected]>
Lower the four SQL constraint attributes through the attribute-spec kit:
field @id/@unique map name via optional(str()); model @@id/@@unique field
list + map via list(fieldRef(self), { nonEmpty, unique }) + optional(str()).

Split the shared @@unique/@@index interpreter branch: @@unique now routes
through the spec while @@index stays on the legacy parseAttributeFieldList /
findDuplicateFieldName / parseConstraintMapArgument path (migrates in D4).
Semantic checks (nullable-in-PK, column mapping, both-inline-and-block PK,
duplicate @@id declaration) remain in the interpreter.

Argument-syntax errors now surface PSL_INVALID_ATTRIBUTE_SYNTAX with the kit
messages; semantic diagnostics keep their existing codes.

Signed-off-by: Serhii Tatarintsev <[email protected]>
Add the record(of) combinator to the psl-parser kit: it parses an
ObjectLiteralExprAst into a Record<string, T>, accumulating leaf
failures and rejecting non-object args, keyless/valueless fields, and
duplicate keys. Export leafDiagnostic so spec refines can build
consistent kit diagnostics.

Migrate @@index onto a declarative model spec (positional field list via
list(fieldRef(self), { nonEmpty, unique }); named map/type/options with
options: record(str()); options-requires-type in refine) and add the
interpretModelIndex helper. Index output is unchanged.

Delete the now-dead SQL syntax helpers subsumed by the kit:
parseObjectLiteralStringMap, splitObjectLiteralEntries, findTopLevelColon,
parseAttributeFieldList, parseFieldList, findDuplicateFieldName, and
parseConstraintMapArgument. Argument-syntax errors now surface
PSL_INVALID_ATTRIBUTE_SYNTAX; test assertions updated accordingly.

Signed-off-by: Serhii Tatarintsev <[email protected]>
Lower @@control via a modelAttribute spec using oneOf(identifier(...)) for
the policy word, replacing the hand-rolled parseControlPolicyAttribute. The
duplicate-attribute guard stays in the interpreter. Argument-syntax errors
now surface PSL_INVALID_ATTRIBUTE_SYNTAX with the kit messages. Delete the
four control-policy helpers now that they have no callers.

Signed-off-by: Serhii Tatarintsev <[email protected]>
… specs

Add the entityRef kit combinator (bare model-name reference; existence
resolved downstream) with unit tests. Lower @@Discriminator via
fieldRef('self') and @@base via entityRef()+str() through the SQL
attribute specs, threading sourceFile into collectPolymorphismDeclarations.
The discriminator String-type check is retained; the now-unreachable
PSL_DISCRIMINATOR_FIELD_NOT_FOUND block is removed (SQL only, Mongo
untouched). Delete the dead singular getPositionalArgument helper.

Signed-off-by: Serhii Tatarintsev <[email protected]>
…into generic wrappers

Signed-off-by: Serhii Tatarintsev <[email protected]>
…tribute lookups

Replace the .path().join(".") AST stringify in findModelAttributeNode and
findFieldAttributeNode with a structural isSimpleName getter, avoiding the
re-stringify anti-pattern. Harden the malformed-options test to assert the
record combinator message substring.

Signed-off-by: Serhii Tatarintsev <[email protected]>
…relation

Delete findRelationAttributeNode and buildRelationInterpretCtx from psl-relation-resolution and route @relation through the generic findFieldAttributeNode/interpretFieldAttribute helpers. Extend interpretFieldAttribute/buildFieldInterpretCtx with an optional resolveReferencedModel knob (defaulted to () => undefined) so map/id/unique callers are unaffected. Removes the last path().join AST-name stringify from the SQL src.

Signed-off-by: Serhii Tatarintsev <[email protected]>
@SevInf
SevInf force-pushed the tml-2956-sql-attributes branch from 1344d43 to 69b7e7f Compare July 9, 2026 09:17
@SevInf
SevInf merged commit a65e8bd into main Jul 9, 2026
20 checks passed
@SevInf
SevInf deleted the tml-2956-sql-attributes branch July 9, 2026 09:55
SevInf added a commit that referenced this pull request Jul 14, 2026
#938)

## Linked issue

Refs [TML-2956](https://linear.app/prisma-company/issue/TML-2956) —
"Language Tools Support Prisma Next PSL".

Follow-up to #932 (the 7 non-`@default` SQL attributes). This PR
finishes the SQL family: `@default` was split out of that slice because
of its size, and lands here. With it, every SQL attribute's argument
parsing is declarative — and `@default`'s spec is composed **dynamically
per field**, so the grammar itself describes exactly which values are
valid at each site.

## At a glance

The `@default` spec is built per field from the field's resolved context
(the composed default-function registry, `isList`, and — for enum fields
— the enum's members), composed entirely from atomic combinators via
`oneOf`:

```ts
// non-enum field, from { isList, registry }
oneOf(
  str(), num(), bool(),                                          // flexible literals (codec still type-checks the value)
  ...(isList ? [list(oneOf(str(), num(), bool()))] : []),        // list arm ONLY on list fields
  ...[...registry.entries()].map(([name, entry]) =>             // one typed arm per registered default function
    funcCall(name, entry.signature)),
)

// enum field, from enumHandle.enumMembers
oneOf(...enumMembers.map((m) => identifier(m.name)))             // e.g. Expected one of: Low | High
```

Each default function now declares an **argument signature** built from
combinators — so `uuid(4)` / `uuid(7)`, the required `cuid(2)`,
`nanoid`'s `2..255` size, and `dbgenerated`'s string are parsed and
range/shape-checked by the grammar, and each registry `lower` receives a
**typed** `{ fn, span, args }` call instead of re-parsing argument
source text:

```ts
// adapter registry entry (postgres/sqlite)
['uuid', { signature: { positional: [{ key: 'version', type: optional(oneOf(num(4), num(7))) }] },
           lower: (i) => i.call.args.version === 7 ? gen('uuidv7') : gen('uuidv4') }]
```

Previously `@default` was parsed by three hand-written string scanners
(`parseDefaultLiteralValue`, `parseListDefaultExpression`, a ~160-line
`parseDefaultFunctionCall`) **and** each registry `lower` re-parsed raw
argument strings (`parseIntegerArgument`, `parseStringLiteral`,
`expectNoArgs`, manual count checks). All of it is gone; the specs
interpret the real AST and the `lower` bodies read typed args.

## Decision

This PR makes `@default` spec-driven on both lowering paths and composes
each spec dynamically per field:

1. **Dynamic non-enum spec** — `buildDefaultSpec({ isList, registry })`
composes literal/list/function arms; the `list` arm exists only for list
fields, and one `funcCall(name)` arm is emitted per registered default
function.
2. **Dynamic enum spec** — `buildEnumDefaultSpec(members)` is
`oneOf(identifier(member)…)`, so a bare member name is validated against
the actual enum by the grammar.
3. **Kit** — `funcCall(name, signature)` (name-pinned, parallel to
`identifier(name)`) parses a call's arguments through a recursive
positional/named signature into a typed `{ fn, span, args }`; a general
`num()` number-literal atom (any number incl. floats; `int({ min, max
})` stays integer-only, now bounded);
`str()`/`bool()`/`list()`/`oneOf()`/`identifier()`/`optional()` reused
as-is.
4. **Typed function arguments (ADR 231).** Each SQL default function
declares a `FuncCallSig`; the registry `lower` reads the typed args
cast-free (`typeof`/literal comparisons), and the imperative arg parsers
are deleted. Because `FuncCallSig` is authoring-layer and the core
registry entry can't name it, `signature` is an opaque `unknown` on the
entry, narrowed with one justified `blindCast<FuncCallSig>` in
`buildDefaultSpec`.
5. **Validation lifted into the grammar** — unknown function name,
unknown enum member, and now **argument shape / arity / range** are
`PSL_INVALID_ATTRIBUTE_SYNTAX` grammar failures; array-on-scalar /
scalar-on-list are grammar misses. The single surviving semantic arg
check is `dbgenerated` empty → `PSL_INVALID_DEFAULT_FUNCTION_ARGUMENT`.
Each per-field spec becomes a precise description a future language
server can read for autocomplete.
6. **Dead-code removal** — the three legacy string scanners,
`funcCall`'s span-arithmetic chain, the monolithic
`scalarLiteral()`/`bareIdentifier()` combinators, and the per-`lower`
imperative arg parsers
(`parseIntegerArgument`/`parseStringLiteral`/`expectNoArgs`) — all
deleted (net −589 lines in the final commit).

Only *argument syntax* moved to specs; the genuinely semantic rules stay
in the interpreter.

## How it fits together

1. **Atomic combinators.** `str()`/`num()`/`bool()` are flexible literal
leaves; `funcCall(name)` matches a call with an exact callee (raw args
captured — the registry still validates them); `identifier(name)`
matches an exact bare identifier. Array defaults reuse `list()`.
2. **The spec is assembled at interpretation time.**
`lowerDefaultForField` calls `buildDefaultSpec({ isList, registry })`;
`lowerEnumDefaultForField` calls
`buildEnumDefaultSpec(enumHandle.enumMembers.map(m => m.name))`. Because
the registry and field facts are in hand there, `oneOf(funcCall(name)…)`
enumerates the open contributed function set — no bespoke `funcCallFrom`
combinator needed (composition over special-casing, per ADR 231
principle 4).
3. **Interpreter keeps the semantics.** For a function value, the
interpreter hands the typed call to `lowerDefaultFunctionWithRegistry` →
`entry.lower`, which now reads typed args and keeps generator
applicability + codec matching (`PSL_INVALID_DEFAULT_APPLICABILITY`) and
the `dbgenerated`-empty check (`PSL_INVALID_DEFAULT_FUNCTION_ARGUMENT`).
Literal↔codec type is still enforced downstream by the codec's
`encodeJson`. For enum, the interpreter maps the (grammar-validated)
member name to its value.
4. **Grammar subsumes the shape/membership/arity checks.** With the list
arm gated on `isList`, one `funcCall(name, sig)`/`identifier(member)`
arm per known function/member, and each function's args
range/shape-checked by its signature, an unknown function, unknown
member, scalar-on-list, array-on-scalar, or malformed argument is just
an unmatched `oneOf` — one uniform `PSL_INVALID_ATTRIBUTE_SYNTAX`.

## Behavior changes & evidence

- **`@default` specs are composed per field.** The function set and
enum-member set come from the field's context, so the spec describes
exactly what's valid there. See
[`sql-attribute-specs.ts`](packages/2-sql/2-authoring/contract-psl/src/sql-attribute-specs.ts)
(`buildDefaultSpec`/`buildEnumDefaultSpec`); wired in
[`psl-column-resolution.ts`](packages/2-sql/2-authoring/contract-psl/src/psl-column-resolution.ts)
+
[`psl-field-resolution.ts`](packages/2-sql/2-authoring/contract-psl/src/psl-field-resolution.ts).
- **Unknown function name and unknown enum member are now grammar
failures** (`PSL_INVALID_ATTRIBUTE_SYNTAX`, `Expected one of: …`),
replacing the post-validation `PSL_UNKNOWN_DEFAULT_FUNCTION` /
`PSL_ENUM_UNKNOWN_DEFAULT_MEMBER`. Evidence in
[`interpreter.defaults.test.ts`](packages/2-sql/2-authoring/contract-psl/test/interpreter.defaults.test.ts)
+
[`interpreter.enum.test.ts`](packages/2-sql/2-authoring/contract-psl/test/interpreter.enum.test.ts).
- **`funcCall(name, signature)` parses typed args;
`num(value)`/`int({min,max})` added.** `funcCall('now')` matches `now()`
but not `foo.now()`; a signed call binds args into `{ fn, span, args }`.
See
[`func-call.ts`](packages/1-framework/2-authoring/psl-parser/src/attribute-spec/combinators/func-call.ts)
+
[`num.ts`](packages/1-framework/2-authoring/psl-parser/src/attribute-spec/combinators/num.ts);
evidence in
[`attribute-spec-combinators.test.ts`](packages/1-framework/2-authoring/psl-parser/test/attribute-spec-combinators.test.ts).
- **Malformed function arguments are now grammar failures.** `uuid(5)`,
`cuid()`, `nanoid(1)`, `dbgenerated(123)`, and args-on-nullary shift
from `PSL_INVALID_DEFAULT_FUNCTION_ARGUMENT` /
`PSL_UNKNOWN_DEFAULT_FUNCTION` to `PSL_INVALID_ATTRIBUTE_SYNTAX`
(operator "Option A"). Registry `lower` bodies read typed args and are
cast-free. See
[`default-function-registry.ts`](packages/2-sql/2-authoring/contract-psl/src/default-function-registry.ts),
[`control-mutation-defaults.ts`](packages/3-targets/6-adapters/postgres/src/core/control-mutation-defaults.ts);
evidence in
[`interpreter.defaults.test.ts`](packages/2-sql/2-authoring/contract-psl/test/interpreter.defaults.test.ts)
+ the adapter `control-mutation-defaults.test.ts`.

## Reviewer notes

- **`funcCallFrom` was never built.**
`oneOf(...registry.keys().map(funcCall))`, composed at interpretation
time, is the open-set dispatch the ADR proposed `funcCallFrom` for —
with the matched arm as the `fn` discriminant. Composition over a
bespoke combinator (ADR 231 principle 4).
- **`matchingScalarLiteral` deferred; literals stay flexible.** Codec
value-validation remains the codec's `encodeJson` (the single authority,
shared with the TS builder); moving it into the grammar would need codec
accept-schema metadata that doesn't exist yet. Recorded in the slice
spec.
- **`oneOf` variadic typing.** `buildDefaultSpec`/`buildEnumDefaultSpec`
annotate the arms as a non-empty readonly tuple (`readonly [ArgType<T>,
...ArgType<T>[]]`) to satisfy `oneOf`'s constraint — no casts.
- **Diagnostic-code shifts are intentional** (consistent with #932 /
operator "Option A"): shape, membership, **and function-argument
arity/range** errors → `PSL_INVALID_ATTRIBUTE_SYNTAX`; genuinely
semantic codes (`PSL_INVALID_DEFAULT_FUNCTION_ARGUMENT` for
`dbgenerated` empty, `PSL_INVALID_DEFAULT_APPLICABILITY`) preserved.
**Coarse-diagnostic trade-off (accepted per ADR 231):** a malformed
argument on a callee-matched funcCall arm makes the outer `oneOf`
backtrack to a generic `Expected one of: …` message, so
`@default(uuid(5))` no longer gets a uuid-specific hint. `cuid()` loses
its former "use `cuid(2)`" guidance for the same reason.
- **⚠ Breaking change to the extension-authoring contract.**
`ControlMutationDefaultEntry.lower` now receives a typed
`TypedDefaultFunctionCall` (was `ParsedDefaultFunctionCall`), and an
arg-bearing contributed default function must declare a `signature`. Any
extension contributing default functions must migrate (the
`default-pack-slugid` parity fixture was migrated as the in-repo
example). Downstream-upgrade need recorded in the slice spec.
- **Bundling fix:** `@prisma-next/psl-parser` promoted from a dev- to a
runtime dependency of `adapter-postgres` so tsdown externalises (not
bundles) the combinators — a bundled copy gave `num()`/`str()` private
AST classes, failing `instanceof` against `sql-contract-psl`-parsed
nodes so every valid argumented `@default` silently failed to parse.
Invisible to source-resolved unit tests; caught only by the
dist-consuming real-pack parity suite.
- **ADR 231 left untouched** (operator instruction); the deviations
(`funcCallFrom` dropped for `oneOf(funcCall(name, sig))`;
`matchingScalarLiteral` deferred; typed-funcCall provenance) are
recorded in the slice spec.
- **Project artefacts** under
`projects/typed-attribute-parsers/slices/sql-default/` are included for
review provenance; migrated/removed at project close-out.

## Verification

Run on final HEAD:
- `pnpm --filter @prisma-next/framework-components build && typecheck &&
test` — clean; **469** tests
- `pnpm --filter @prisma-next/psl-parser build && typecheck && test` —
clean; **623** tests
- `pnpm --filter @prisma-next/sql-contract-psl typecheck && test` —
clean; **333** tests
- `pnpm --filter @prisma-next/adapter-postgres typecheck && test` (+
coverage ≥ thresholds) — **675** tests
- `pnpm --filter @prisma-next/adapter-sqlite typecheck && test` —
**220** tests
- Integration authoring parity (incl. dist-consuming real-pack
`instanceof` parity + `@default` diagnostics fixtures) — **50** tests
- `pnpm build` — 68/68 · `pnpm fixtures:check` — clean, no drift · `pnpm
lint:framework-vocabulary` — 836/836 · `pnpm lint:deps` — 0 violations

## Follow-ups

- Mongo family attribute + `@default` migration — the remaining slice of
TML-2956.
- Language-server autocomplete reading these per-field specs — the
deferred LS-scoped work this dynamic design enables.

## Alternatives considered

- **`funcCallFrom(registry)` as a dedicated combinator.** Rejected: with
dynamic per-field construction the registry is in hand, so
`oneOf(funcCall(name)…)` composes the same open-set dispatch without a
bespoke combinator or dragging registry concerns into the kit.
- **`matchingScalarLiteral()` / codec-typed literals now.** Rejected for
this PR: literal↔type validation already lives at the codec's
`encodeJson`; a spec-level matcher would duplicate it (drift risk) or
need codec accept-schema metadata that doesn't exist. Deferred.
- **Keeping `PSL_UNKNOWN_DEFAULT_FUNCTION` /
`PSL_ENUM_UNKNOWN_DEFAULT_MEMBER` as semantic checks.** Rejected:
folding membership into the grammar is the point (less post-validation),
and `oneOf`'s "Expected one of: …" preserves the helpful supported-set
message.
- **Typing `signature` on the core entry as `FuncCallSig` (not
`unknown`).** Rejected: `FuncCallSig` lives in the authoring layer
(`@prisma-next/psl-parser`); the core `framework-components` entry type
cannot name it without a layering violation (`pnpm lint:deps`). The
opaque-`unknown` + single narrowing `blindCast` in the SQL family is the
layer-clean shape; the typed `{fn,span,args}` call passed to `lower` is
plain-structural and needs no cast.
- **Keeping the imperative per-`lower` arg parsers.** Rejected: that is
exactly the raw-string re-parse ADR 231's typed `funcCall` replaces; the
signatures make arg validation a grammar concern and delete the parsers.

## Checklist

- [x] All commits are signed off (`git commit -s`) per the DCO.
- [x] I read CONTRIBUTING.md and the change is scoped to one logical
concern.
- [x] Tests are updated.
- [x] The PR title is in `TML-NNNN: <sentence-case title>` form.
- [x] Skill update: n/a — internal refactor; `@default` argument-syntax
error *codes* consolidated (documented in the slice spec), no
CLI/API/config surface change.

---------

Signed-off-by: Serhii Tatarintsev <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant