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

docs(target-contributed-psl-blocks): declarative SPI respec - #749

Merged
wmadden merged 1 commit into
mainfrom
tml-2804-declarative-respec
Jun 7, 2026
Merged

wmadden merged 1 commit into
mainfrom
tml-2804-declarative-respec

Conversation

@wmadden-electric

@wmadden-electric wmadden-electric commented Jun 7, 2026 •

Copy link
Copy Markdown
Contributor

Reshapes the Target-contributed top-level PSL blocks project from a function-based SPI to a declarative one, following a design discussion. Docs only — no implementation.

What changed

  • spec.md — rewritten. An extension describes a top-level block as data (keyword, name, typed parameters of kinds ref / value / option / list); the framework owns one generic parser / validator / printer that interprets any declared block. Includes the vocabulary, why declarative, the cherry-pick list from TML-2804: extensions can contribute top-level PSL block keywords #718, a 12-point project-DoD, and alternatives considered.
  • plan.md — four-slice composition: declarative substrate (TML-2804) → generic printer + contract infer (TML-2854) → PSL-AST → entries migration (TML-2849) → ADR + close-out (TML-2806).
  • ADR 126 — a banner marking the parseFn/emitFn function SPI it records as superseded; the full rewrite is the close-out slice's job (against the as-shipped substrate).
  • slices/substrate/plan.md — a banner marking it the record of the superseded TML-2804: extensions can contribute top-level PSL block keywords #718 function-SPI dispatch plan.

Why declarative

The PSL grammar is closed and uniform (a block is a name + field declarations + x = y assignments + double-quoted values), so a block's structure can be described as data and validated/analysed without executing extension code. The function SPI (PR #718, now draft) re-implements parsing the framework already does, can't be inspected from its data, and forced parse-time failure-isolation machinery (catching thrown parsers, undefined returns, kind/discriminator drift) — all of which exists only because foreign code runs at parse time. Describing blocks as data removes the foreign code and the defence with it.

The four parameter value-kinds: ref (resolves to a declared entity, with a same-namespace / same-space / cross-space scope), value (codec-typed — the same rails field types and @default already ride; the codec owns PSL parse/print), option (one of a fixed set of allowed literal tokens — an authoring-time parameter constraint, not a domain or persistence enum), and list (combinator). Where validity is context-dependent (RLS USING vs WITH CHECK per command), the answer is separate block keywords with fixed parameter sets, not conditional logic in the descriptor.

Relationships

Refs TML-2804, TML-2854, TML-2849, TML-2806.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Documentation
    • Updated architecture documentation with a revision notice clarifying that the function SPI description is now superseded by a declarative descriptor approach, directing users to the current authoritative design specification.

Reshapes the project from a function-based PSL-block SPI to a declarative one: an extension describes a block as data (keyword, name, typed parameters ref/value/option/list) and the framework owns one generic parser/validator/printer. Rewrites spec.md + plan.md (four-slice composition), banners ADR 126 (superseded function SPI; full rewrite is the close-out slice), and banners the superseded #718 dispatch plan. Docs only.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden-electric
wmadden-electric requested a review from a team as a code owner June 7, 2026 10:32
@coderabbitai

coderabbitai Bot commented Jun 7, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 9cbe9b9b-cebc-49ba-a640-98e9865ea925

📥 Commits

Reviewing files that changed from the base of the PR and between f8e89b3 and a34cc05.

⛔ Files ignored due to path filters (3)
  • projects/target-contributed-psl-blocks/plan.md is excluded by !projects/**
  • projects/target-contributed-psl-blocks/slices/substrate/plan.md is excluded by !projects/**
  • projects/target-contributed-psl-blocks/spec.md is excluded by !projects/**
📒 Files selected for processing (1)
  • docs/architecture docs/adrs/ADR 126 - PSL top-level block SPI.md

📝 Walkthrough

Walkthrough

This PR adds a revision advisory to ADR 126 documenting that the function-based SPI approach described in the document has been superseded by a declarative descriptor design. The notice directs readers to the current authoritative specification and marks the existing content as historical.

Changes

ADR 126 Revision Notice

Layer / File(s) Summary
Documentation revision advisory
docs/architecture docs/adrs/ADR 126 - PSL top-level block SPI.md
Added a top-of-document "Under revision (2026-06)" advisory block indicating that the function SPI is superseded by a declarative descriptor approach, referencing the current spec in projects/target-contributed-psl-blocks/spec.md, and clarifying that the remainder of the document is historical.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

📜 A rabbit's note: the old scroll takes rest,
Its tale now marked as once-the-best.
New words in spec files shine ahead—
A gentle bridge from old to read! 🐰

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'docs(target-contributed-psl-blocks): declarative SPI respec' is directly related to the main change - adding a revision notice to ADR 126 documenting the shift from function-based SPI to declarative SPI approach for PSL blocks.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch tml-2804-declarative-respec

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 and usage tips.

@wmadden
wmadden merged commit e4826b2 into main Jun 7, 2026
19 checks passed
@wmadden
wmadden deleted the tml-2804-declarative-respec branch June 7, 2026 10:38
wmadden-electric added a commit that referenced this pull request Jun 8, 2026
… 1 — read side) (#753)

## At a glance

Slice 1 of 4 of **[Target-contributed top-level PSL
blocks](https://linear.app/prisma-company/issue/TML-2804)** — the **read
side** of the declarative SPI. After this, an extension describes a new
top-level PSL block **as data** (a descriptor of its keyword, name, and
typed parameters), and the framework **parses, validates, and lowers it
to contract IR** with one generic interpreter. No extension-supplied
parse/print code runs.

This supersedes the function-based SPI built on
[#718](#718) (now draft): that
cut had each extension ship imperative `parser`/`printer` functions. The
mechanism is cherry-picked here; the functions are replaced by the
descriptor + generic interpreter. Rationale + design are in
`projects/target-contributed-psl-blocks/spec.md` (landed via #749).

```prisma
namespace public {
  model Profile { id String @id  userId String @unique }

  policy_select profiles_select_anon {
    target = Profile               // ref (same-namespace)
    as     = permissive            // option: permissive | restrictive
    roles  = [anon, authenticated] // list of ref (cross-space)
    using  = "auth.uid() = user_id"// value (codec-typed)
  }
}
```

The framework never learns the `policy_select` keyword directly — the
descriptor is data.

## What's in this PR

The parameter value-kind vocabulary and the generic read pipeline, built
across seven dispatches:

- **Declarative descriptor + vocabulary** (`framework-components`) —
`AuthoringPslBlockDescriptor` is data: keyword, discriminator, `name`,
and a `parameters` map of the four-kind union `PslBlockParam`: **`ref`**
(resolves to a declared entity; `refKind` + `scope`), **`value`**
(codec-typed), **`option`** (a closed set of allowed literal tokens — an
authoring constraint, *not* a domain enum), **`list`** (combinator). No
`parser`/`printer` fields. Plus the uniform parsed-node base (`{ kind,
name, parameters, span }`) and the `PslNamespace.extensionBlocks` slot.
- **Codec-typed `value` via the codec's existing `decodeJson`** — a
`value` literal is interpreted as JSON through the codec the parameter
declares: `codecLookup.get(codecId).decodeJson(JSON.parse(raw))` — the
same path that decodes literal column defaults. There is no bespoke PSL
codec hook; PSL literals are handled generically and codecs already own
value↔JSON, so `value` rides that existing medium (and gets full codec
expressiveness + correct JSON escaping for free). (`@default`'s legacy
literal handling is untouched — separate, future work.)
- **Generic parser** (`psl-parser`) — on an unknown top-level keyword,
the parser reads any declared block into the uniform node, capturing
each parameter's RHS by its declared kind. Built-in keywords stay
framework-parsed; an unregistered keyword still gets the clean
unknown-keyword diagnostic.
- **Generic validator + `ref` resolution** — reports (with spans)
unknown / missing-required parameters, `option`-not-in-set,
codec-rejected `value`, and `ref` unresolved within its scope
(`same-namespace`/`same-space` resolved against the parsed namespaces;
`cross-space` is a documented pass-through per the spec's first-consumer
allowance, leaning on the merged #745 coordinate model). A small
`PSL_EXTENSION_*` diagnostic taxonomy.
- **Load-time validation** — `assembleAuthoringContributions` rejects
duplicate keyword, duplicate discriminator (within `pslBlocks` and
within `entityTypes`), a `pslBlocks` descriptor with no matching
`entityTypes` factory, and a malformed descriptor. Standalone
`entityTypes` factories stay allowed.
- **Lowering + fixture + round-trip** — the uniform node lowers to IR
via the matching `entityTypes` factory; a test-only declarative
`policy_select` fixture round-trips **parse → validate → lower → IR**.

## A design decision worth a look

Validation runs **inside `parsePslDocument`** whenever `pslBlocks` are
registered, joining the parser's existing diagnostics. A `value`
parameter is validated by parsing its literal as JSON and running the
codec's existing `decodeJson`
(`codecLookup.get(codecId).decodeJson(JSON.parse(raw))`); malformed JSON
or a codec rejection surfaces a diagnostic. No production caller passes
`pslBlocks` yet — this is the read-side seam.

## Out of scope (later slices)

- **Generic printer + `contract infer`** — Slice 2,
[TML-2854](https://linear.app/prisma-company/issue/TML-2854). This PR's
round-trip stops at the lowered IR.
- **`PslNamespace` → ADR 224 `entries` migration** — Slice 3,
[TML-2849](https://linear.app/prisma-company/issue/TML-2849).
- **ADR 126 revision + three-layer ADR + close-out** — Slice 4,
[TML-2806](https://linear.app/prisma-company/issue/TML-2806).
- A `number` value-kind / field-declaration block bodies (deferred to
first consumer); real RLS (downstream).

## Relationships

- **[#718](#718 —
superseded function-SPI cut; draft; mechanism cherry-picked; branch
preserved.
- **[#745](#745) / TML-2500**
— merged; `ref` `cross-space` scope builds on its coordinate model. Not
a blocker.
- **[#748](#748) /
enums-as-domain** — independent; `option` is not an enum, `value` uses
ordinary scalar codecs.

## Verification

| Gate | Result |
|---|---|
| `pnpm typecheck` (the four touched packages) | clean |
| `pnpm test:packages` (psl-parser / psl-printer / framework-components
/ cli, in isolation) | pass — 100 / 34 / 395 / 1316 |
| `pnpm lint:deps` | clean |
| `pnpm lint:casts` | `delta=0` (no regression) |

A monorepo-wide typecheck has pre-existing, unrelated worktree
dist-not-built failures (migration-tools / mongo-contract /
sql-schema-ir / emitter / mongo-lowering) — none introduced here;
per-package typechecks for the touched packages are clean, and the
changes don't alter a public export signature those packages consume.

## Follow-ups recorded for downstream (not this slice)

- `ref-kind` vs `discriminator` mismatch for a non-`cross-space` ref to
an extension-contributed entity (the first RLS-roles-style consumer must
map `refKind` → discriminator).
- Duplicate-*keyword-string* across different namespace keys isn't
caught at assembly (duplicate-*path* is); harden in the keyword-dispatch
index if it matters.

Refs [TML-2804](https://linear.app/prisma-company/issue/TML-2804).

🤖 Generated with [Claude Code](https://claude.com/claude-code)


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Support for PSL extension blocks: parsing, validation, diagnostics,
namespace-aware reference resolution, and codec-backed value checks.
* Authoring API expanded so contributors can declare/register
extension-block descriptors that integrate into parse/validation and
cross-registry consistency checks.

* **Tests**
* Extensive unit and round‑trip tests and fixtures covering parsing,
validation, diagnostics, lowering, and reference/codec behaviors.

* **Chores**
* Test fixtures and tooling adjusted to include the new authoring
contributions shape.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Signed-off-by: Will Madden <[email protected]>
Co-authored-by: Will Madden <[email protected]>
Co-authored-by: Claude Opus 4.8 <[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.

2 participants