Repository navigation
docs(target-contributed-psl-blocks): declarative SPI respec - #749
Conversation
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]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Run ID: ⛔ Files ignored due to path filters (3)
📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThis 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. ChangesADR 126 Revision Notice
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~2 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
… 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]>
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 kindsref/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 →entriesmigration (TML-2849) → ADR + close-out (TML-2806).parseFn/emitFnfunction 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 = yassignments + 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,undefinedreturns,kind/discriminatordrift) — 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 asame-namespace/same-space/cross-spacescope),value(codec-typed — the same rails field types and@defaultalready 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), andlist(combinator). Where validity is context-dependent (RLSUSINGvsWITH CHECKper command), the answer is separate block keywords with fixed parameter sets, not conditional logic in the descriptor.Relationships
extensionBlocksslot, keyword dispatch, load-time validation, printer plumbing,contract inferthreading, round-trip harness) is cherry-picked; only the contributedparser/printerfunctions are replaced. Branch preserved.refcross-spacescope, not a blocker.optionis not an enum, andvalueuses ordinary scalar codecs, not enum codecs.Refs TML-2804, TML-2854, TML-2849, TML-2806.
🤖 Generated with Claude Code
Summary by CodeRabbit