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

TML-2849: Make entries[kind][name] the canonical PSL-namespace store, with typed accessors over it (Slice 3) - #757

Merged
wmadden merged 6 commits into
mainfrom
tml-2849-slice-3-psl-ast-entries-migration
Jun 8, 2026
Merged

wmadden merged 6 commits into
mainfrom
tml-2849-slice-3-psl-ast-entries-migration

Conversation

@wmadden-electric

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

Copy link
Copy Markdown
Contributor

At a glance

A PSL namespace now stores every entity it contains — built-in and extension-contributed — in one place, addressed the same way: entries[kind][name].

// One coordinate system for every kind in a namespace:
ns.entries['model']['User']               // a parsed `model User { … }`
ns.entries['enum']['Role']                 // a parsed `enum Role { … }`
ns.entries['policy_select']['ReadPosts']   // an extension-contributed block

// The typed reads we already had still work — they're now getters over
// `entries`, not stored arrays:
ns.models          // === Object.values(ns.entries['model'] ?? {})
ns.enums
ns.compositeTypes

The decision

Make entries[kind][name] the single canonical store on PslNamespace. Keep the typed reads (models / enums / compositeTypes) exactly as callers know them, but compute them as derived getters over entries rather than storing them as parallel arrays.

Why this PR exists

The contract IR already addresses entities by (kind, name) coordinates. The PSL AST didn't. Built-in kinds lived in typed arrays (models, enums, compositeTypes); the extension-contributed blocks added in Slices 1–2 sat in a separate extensionBlocks array. So "give me the entity named X of kind K" had two different shapes depending on whether K was built in — and extension kinds had no coordinate access at all. This PR closes that gap, so the PSL AST and the IR share one coordinate model (ADR 224).

How it works

  • entries is the canonical store — a frozen outer container of frozen per-kind maps. Keys are singular, essence-named: model / enum / compositeType for built-ins, and each extension block's discriminator (e.g. policy_select) for contributed kinds.
  • The core kinds keep typed accessors — models / enums / compositeTypes are getters built by the makePslNamespace factory, each narrowing its slice once (via blindCast). Framework code that needs a built-in kind's static type reads it directly; no per-call-site casts.
  • Contributed kinds are read generically — entries[discriminator], or the namespacePslExtensionBlocks(ns) helper.
  • The accessors are non-enumerable, so spreading or JSON.stringify-ing a namespace copies only entries — the derived views never double up the data.

Why the blast radius is small

Because the accessors preserve the exact .models / .enums read interface callers already use, every reader is untouched. Only the two places that construct a namespace had to change — sql-schema-ir-to-psl-ast and one contract infer CLI test — and they now go through makePslNamespace. The framework-wide migration this first looked like collapsed to two producer sites.

No behavioral change

This is an in-memory AST shape change only. Emitted artifacts are unaffected: fixtures:check is clean and git diff over contract.* is empty. Contract emission runs through the separate domain-IR path (untouched), and the printer reads the PSL AST through the accessors, never spreading or serializing the namespace object.

What's in this PR

  • E1 — entries becomes the canonical store; makePslNamespaceEntries builds it; makePslNamespace provides the derived getters; the parser writes entries, and both printer phases + the extension-block validator read it.
  • E2 — the two namespace producers migrate to the factory; the accessors are made non-enumerable; a test proves a built-in (entries['model']) and a contributed (entries['policy_select']) kind are reached through the same expression.
  • Rebase completion — #753 (Slice 1) and #754 (Slice 2) merged after E1/E2 were authored, so a few of their later test readers still used the old ns.extensionBlocks field / inline namespace literals; those move to namespacePslExtensionBlocks and the makeNs factory. Two stale {@link PslNamespace.extensionBlocks} JSDoc references (the removed field) are repointed at entries.

Verification

Gate Result
pnpm typecheck (framework-components / psl-parser / psl-printer / family-sql / cli) clean
pnpm test (those packages, in isolation) 396 / 110 / 55 / 351 / contract infer green
pnpm lint:deps clean
pnpm lint:casts delta=0 (accessor narrowing is blindCast, not bare as)
pnpm fixtures:check / git diff contract.* unchanged

(Pre-existing cli client.test / version.test flakes are unrelated — they pass in isolation and Slice 3 touches no cli command/version/client source. The supabase example's fixtures:check/build failure is a worktree env artifact — prisma-next: command not found — independent of this PR.)

Out of scope

  • ADR 126 revision + the three-layer extensibility ADR + project close-out — Slice 4, TML-2806. The ADR must record this decision as "canonical entries + typed accessors over it", not "deleted the typed slots".
  • IR-layer changes (the IR's entries already shipped); real RLS (downstream).

Open item recorded

namespacePslExtensionBlocks returns contributed blocks grouped by kind, not in flat cross-kind source order. Not exercised today; revisit when a consumer interleaves multiple policy_* kinds and needs cross-kind print order preserved.

Alternatives considered

Delete the typed slots and expose a raw generic map (Record<string, Record<string, PslNamespaceEntry>>). Rejected: the generic container loses per-kind static types, so every typed read across the SQL/Mongo families would need a narrowing cast at the call site — a cast regression for negative ergonomic value. ADR 224's own IR already solves this by keeping entries as canonical storage with typed accessors layered over it; this PR mirrors that proven shape rather than inventing a flatter, less-typed one.

Refs TML-2849.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Refactor
    • Restructured internal namespace data organization for improved consistency and maintainability. Updated helper functions and validation logic to access namespace components through a unified canonical structure.

@wmadden-electric
wmadden-electric requested a review from a team as a code owner June 7, 2026 18:20
@coderabbitai

coderabbitai Bot commented Jun 7, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: ebc77998-6927-4a38-a224-cf7baadcbc5b

📥 Commits

Reviewing files that changed from the base of the PR and between 7b1bbd3 and 3b628dc.

⛔ Files ignored due to path filters (1)
  • projects/target-contributed-psl-blocks/slices/entries-migration/plan.md is excluded by !projects/**
📒 Files selected for processing (13)
  • packages/1-framework/1-core/framework-components/src/control/psl-ast.ts
  • packages/1-framework/1-core/framework-components/src/control/psl-extension-block-validator.ts
  • packages/1-framework/1-core/framework-components/src/shared/framework-authoring.ts
  • packages/1-framework/1-core/framework-components/test/psl-ast.test.ts
  • packages/1-framework/1-core/framework-components/test/psl-extension-block-validator.test.ts
  • packages/1-framework/2-authoring/psl-parser/src/parser.ts
  • packages/1-framework/2-authoring/psl-parser/test/parser.test.ts
  • packages/1-framework/2-authoring/psl-printer/src/ast-to-print-document.ts
  • packages/1-framework/2-authoring/psl-printer/test/declarative-policy-select.round-trip.test.ts
  • packages/1-framework/2-authoring/psl-printer/test/generic-extension-block-printer.test.ts
  • packages/1-framework/2-authoring/psl-printer/test/print-psl-from-ast.test.ts
  • packages/1-framework/3-tooling/cli/test/commands/contract-infer.command.test.ts
  • packages/2-sql/9-family/src/core/psl-contract-infer/sql-schema-ir-to-psl-ast.ts

📝 Walkthrough

Walkthrough

This PR refactors PSL namespaces to use a canonical frozen entries container (nested maps keyed by kind, then name) instead of exposing direct models, enums, compositeTypes, and extensionBlocks fields. Factory helpers (makePslNamespace, makePslNamespaceEntries) and extraction functions (namespacePslExtensionBlocks) unify how namespaces are constructed and read throughout the AST, parser, validator, printer, and SQL IR pipelines. All test suites are updated to construct fixtures via the new helpers.

Changes

Namespace entries model migration

Layer / File(s) Summary
Core namespace entries contract and AST tests
packages/1-framework/1-core/framework-components/src/control/psl-ast.ts, packages/1-framework/1-core/framework-components/test/psl-ast.test.ts, packages/1-framework/1-core/framework-components/src/shared/framework-authoring.ts
Introduces PslNamespaceEntry union type, redefines PslNamespace to center on frozen entries maps, adds PslNamespaceNode class with derived getters, and exports makePslNamespace, makePslNamespaceEntries, BUILTIN_PSL_KIND_KEYS, and namespacePslExtensionBlocks helpers. Flatten helpers (flatPslModels, flatPslEnums, flatPslCompositeTypes) read from entries[kind] instead of per-namespace properties. Comprehensive tests validate entries structure, derived accessors, non-enumerability, and extension-block filtering.
Validator, parser, printer, and SQL IR adoption
packages/1-framework/1-core/framework-components/src/control/psl-extension-block-validator.ts, packages/1-framework/2-authoring/psl-parser/src/parser.ts, packages/1-framework/2-authoring/psl-printer/src/ast-to-print-document.ts, packages/2-sql/9-family/src/core/psl-contract-infer/sql-schema-ir-to-psl-ast.ts
Updates resolveEntityInNamespaces to uniformly resolve entities through entries[refKind] with Object.hasOwn. Parser now constructs namespaces via makePslNamespace + makePslNamespaceEntries and enumerates extension blocks via namespacePslExtensionBlocks helper. Printer derives namespace extension blocks through the same helper instead of direct property access. SQL IR generation uses the factory helpers for namespace construction.
Test fixture migration across validator, parser, printer, and CLI
packages/1-framework/1-core/framework-components/test/psl-extension-block-validator.test.ts, packages/1-framework/2-authoring/psl-parser/test/parser.test.ts, packages/1-framework/2-authoring/psl-printer/test/declarative-policy-select.round-trip.test.ts, packages/1-framework/2-authoring/psl-printer/test/generic-extension-block-printer.test.ts, packages/1-framework/2-authoring/psl-printer/test/print-psl-from-ast.test.ts, packages/1-framework/3-tooling/cli/test/commands/contract-infer.command.test.ts
Validator and parser test fixtures construct namespaces via makePslNamespace/makePslNamespaceEntries instead of inline objects. Parser tests update all extension-block assertions to use namespacePslExtensionBlocks(ns) for enumeration. Printer tests introduce local makeNs helpers and refactor namespace construction across all test cases, replacing verbose inline namespace literals with factory calls. CLI contract-infer tests update synthetic AST construction to use the same factory-based approach.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • prisma/prisma-next#753: Introduced extension-contributed PSL blocks and PslNamespace.extensionBlocks field; this PR refactors that field to live under entries[discriminator] and adds helpers for enumeration.
  • prisma/prisma-next#754: Changes how namespace extension blocks are represented and enumerated, impacting the generic descriptor-driven PSL printing path that serializes extension blocks.

Suggested reviewers

  • wmadden

Poem

🐰 Nested maps now hold what once lived loose,
Kind by kind, a structured truce.
Entries bloom where fields once sprawled,
Helpers guide where data's called.
Tests rejoice in factories—
Builders craft what schemas please! ✨

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch tml-2849-slice-3-psl-ast-entries-migration

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.

@pkg-pr-new

pkg-pr-new Bot commented Jun 7, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@prisma-next/extension-author-tools

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

@prisma-next/mongo-runtime

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

@prisma-next/family-mongo

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

@prisma-next/sql-runtime

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

@prisma-next/family-sql

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

@prisma-next/extension-arktype-json

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

@prisma-next/middleware-cache

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

@prisma-next/mongo

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

@prisma-next/extension-paradedb

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

@prisma-next/extension-pgvector

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

@prisma-next/extension-postgis

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

@prisma-next/postgres

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

@prisma-next/sql-orm-client

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

@prisma-next/sqlite

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

@prisma-next/extension-supabase

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

@prisma-next/target-mongo

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

@prisma-next/adapter-mongo

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

@prisma-next/driver-mongo

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

@prisma-next/contract

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

@prisma-next/utils

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

@prisma-next/config

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

@prisma-next/errors

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

@prisma-next/framework-components

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

@prisma-next/operations

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

@prisma-next/ts-render

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

@prisma-next/contract-authoring

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

@prisma-next/ids

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

@prisma-next/psl-parser

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

@prisma-next/psl-printer

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

@prisma-next/cli

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

@prisma-next/cli-telemetry

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

@prisma-next/emitter

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

@prisma-next/migration-tools

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

prisma-next

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

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

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

@prisma-next/mongo-codec

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

@prisma-next/mongo-contract

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

@prisma-next/mongo-value

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

@prisma-next/mongo-contract-psl

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

@prisma-next/mongo-contract-ts

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

@prisma-next/mongo-emitter

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

@prisma-next/mongo-schema-ir

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

@prisma-next/mongo-query-ast

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

@prisma-next/mongo-orm

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

@prisma-next/mongo-query-builder

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

@prisma-next/mongo-lowering

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

@prisma-next/mongo-wire

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

@prisma-next/sql-contract

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

@prisma-next/sql-errors

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

@prisma-next/sql-operations

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

@prisma-next/sql-schema-ir

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

@prisma-next/sql-contract-psl

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

@prisma-next/sql-contract-ts

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

@prisma-next/sql-contract-emitter

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

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

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

@prisma-next/sql-relational-core

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

@prisma-next/sql-builder

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

@prisma-next/target-postgres

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

@prisma-next/target-sqlite

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

@prisma-next/adapter-postgres

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

@prisma-next/adapter-sqlite

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

@prisma-next/driver-postgres

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

@prisma-next/driver-sqlite

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

commit: 3a9355f

@github-actions

github-actions Bot commented Jun 7, 2026 •

Copy link
Copy Markdown

size-limit report 📦

Path Size
postgres / no-emit 149.27 KB (0%)
postgres / emit 118.32 KB (0%)
mongo / no-emit 76.67 KB (0%)
mongo / emit 70.96 KB (0%)
cf-worker / no-emit 179.31 KB (0%)
cf-worker / emit 145.03 KB (0%)

@wmadden-electric
wmadden-electric force-pushed the tml-2854-slice-2-generic-printer-contract-infer branch from 71ffbca to 0ca207e Compare June 8, 2026 05:51
@wmadden-electric
wmadden-electric force-pushed the tml-2854-slice-2-generic-printer-contract-infer branch 2 times, most recently from bd57d14 to 9416e8d Compare June 8, 2026 07:45
wmadden-electric added a commit that referenced this pull request Jun 8, 2026
…ks (Slice 2 — write side) (#754)

## At a glance

Slice 2 of 4 of **[Target-contributed top-level PSL
blocks](https://linear.app/prisma-company/issue/TML-2854)** — the
**write side** of the declarative SPI. Slice 1
([#753](#753), merged) gave
the framework a generic *read* path (parse → validate → lower an
extension-contributed block from its descriptor). This PR adds the
matching *write* path: one generic descriptor-driven printer renders any
registered block back to PSL, and `contract infer` threads the
registered descriptors through so an inferred contract prints its
extension blocks. No extension-supplied printer code runs.

```prisma
policy_select ProfilesSelect {
  target = Post
  using  = "auth.uid() = author_id"
}
```

The printer never learns the `policy_select` keyword — it reads the
descriptor (keyword, `name`, typed `parameters`) and renders each
parameter by its declared kind.

## What's in this PR

- **Generic descriptor-driven printer** (`psl-printer`) —
`serializePrintDocument` builds a discriminator-keyed dispatch map from
the registered `pslBlockDescriptors` and renders each block's parameters
by kind: `ref` → identifier, `option` → token, `list` → bracketed
elements, `value` → the codec's JSON medium (below). An unregistered
discriminator throws, naming it.
- **`value` params are serialized *through the codec*, not echoed** —
`renderValueParam` runs a value literal through
`JSON.stringify(codec.encodeJson(codec.decodeJson(JSON.parse(raw))))`.
This is the exact print-back mirror of Slice 1's parse-side validator
(`codecLookup.get(codecId).decodeJson(JSON.parse(raw))`): a PSL value
literal *is* the JSON serialization of the value, and the codec owns
that medium. There is no bespoke codec PSL hook.
- **`contract infer` threading** (`cli`) — the assembled
`pslBlockDescriptors` namespace flows from `inspectLiveSchema` into
`printPsl`, so an inferred contract can print extension blocks.
- **Round-trip + codec-drives-output coverage** — the declarative
`policy_select` fixture now round-trips the full pipeline (parse →
validate → lower → IR → serialize → hydrate → IR → **print** → re-parse
→ structurally-equivalent AST), and a dedicated printer test proves the
codec — not the captured raw text — produces the literal.

## A design decision worth a look

**The codec owns the serialized form of a value parameter, on both
sides.** The original cut of this slice shipped a bespoke codec PSL hook
(`parsePslLiteral` / `printPslLiteral`); that was rejected in Slice 1 in
favour of the codec's existing JSON medium, and this PR was **rebased
onto `main`** with that hook commit dropped and the printer reworked to
`encodeJson`/`decodeJson` + `JSON.parse`/`JSON.stringify`.

The risk with that path is a test that can't tell "the codec serialized
the value" apart from "the raw text passed through untouched" — an
identity codec (`encodeJson(v) => v`) makes them indistinguishable. So
the proof test uses a **non-identity** codec: `decodeJson` coerces a
quoted `"42"` to the number `42`, `encodeJson` emits a bare JSON number,
and the printed literal is `using = 42` (unquoted) — which can only come
from the codec running on the value. Mutating `renderValueParam` to echo
`raw` fails this test (`using = "42"` ≠ `using = 42`). This is also the
exact value path an IR/value source would take, fabricated directly
rather than waiting on a production block contributor.

## Out of scope (later slices / first consumer)

- **`PslNamespace` → ADR 224 `entries` migration** — Slice 3,
[TML-2849](https://linear.app/prisma-company/issue/TML-2849)
([#757](#757), to be rebased
onto this).
- **ADR 126 revision + three-layer ADR + close-out** — Slice 4,
[TML-2806](https://linear.app/prisma-company/issue/TML-2806).
- **A standalone `value → raw` lowering helper for IR-originated
blocks** — deferred to the first real block-contributing extension. The
print seam already routes through the codec and is proven; the node
stores `raw`, and there is no production contributor yet to fix a
helper's signature against.

## Verification

| Gate | Result |
|---|---|
| `pnpm build` (framework-components → psl-parser → psl-printer) | clean
|
| `pnpm typecheck` (psl-printer / cli) | clean |
| `pnpm test` — psl-printer / cli | 50 / 1317 pass |
| `pnpm lint:deps` | clean |
| `pnpm lint:casts` | `delta=0` (the one new cast is a `blindCast` with
reason, not a bare `as`) |
| `pnpm fixtures:check` | clean — except a pre-existing `supabase`
example failure (`prisma-next: command not found`, an env/PATH issue in
that example) that reproduces independently of this PR |

## Relationships

- **[#753](#753) / TML-2804**
— Slice 1, merged; this is its write-side mirror. Rebased onto `main`;
the superseded codec-PSL-hook commit was dropped.
- **[#757](#757) / TML-2849**
— Slice 3, stacked; will be rebased onto this branch.

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

🤖 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**
* Extension blocks are now properly printed and serialized in PSL
documents with support for codec-based parameter rendering and custom
block descriptors.

* **Tests**
* Added comprehensive test coverage for extension block printing,
round-trip validation, and command integration with extension blocks.

<!-- 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]>
Base automatically changed from tml-2854-slice-2-generic-printer-contract-infer to main June 8, 2026 08:20
@wmadden-electric
wmadden-electric force-pushed the tml-2849-slice-3-psl-ast-entries-migration branch from de75dae to e398808 Compare June 8, 2026 09:33
@wmadden-electric wmadden-electric changed the title TML-2849: PSL AST converges on entries coordinate shape (Slice 3) TML-2849: Make entries[kind][name] the canonical PSL-namespace store, with typed accessors over it (Slice 3) Jun 8, 2026
@wmadden-electric
wmadden-electric force-pushed the tml-2849-slice-3-psl-ast-entries-migration branch from 97158b6 to 07a8a3b Compare June 8, 2026 09:53
wmadden and others added 6 commits June 8, 2026 12:34
…ccessors (E1)

PslNamespace.entries[kind][name] (ADR 224: singular essence-named keys model/enum/compositeType + contributed discriminators; container + inner maps frozen) is the single canonical store, built via makePslNamespaceEntries. models/enums/compositeTypes are PERMANENT typed accessors that DERIVE from entries via a makePslNamespace factory (Object.create getter descriptors, blindCast once each) — no parallel stored arrays. extensionBlocks dropped from the interface; contributed kinds read via namespacePslExtensionBlocks(ns) (generic over entries). Parser builds entries and constructs via the factory; both printer phases + the extension-block validator read entries/accessors; framework packages green, lint:casts delta=0. External producers (E2) and the IR layer are untouched.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…bility hardening (E2)

Closing dispatch. Migrates the 2 producers that constructed PslNamespace literals (sql-schema-ir-to-psl-ast, a cli contract-infer test) to build entries via makePslNamespaceEntries + makePslNamespace; no per-kind data fields; the extension block goes into entries under its discriminator. Makes the derived models/enums/compositeTypes accessors non-enumerable so spread/serialize copies only entries (no duplication). Adds a uniform-coordinate-access test (built-in entries[model] + contributed entries[policy_select] via one expression). Readers untouched (accessors preserve the interface). Emitted output unchanged (fixtures:check clean; contract.* diff empty) — the migration is in-memory AST only. Spec DoD item 10 reworded to the canonical-entries + derived-typed-accessors decision; slice plan updated.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
The entries migration (E1) was authored before Slice 1/2's later test
additions landed on main, so the rebase surfaced readers/producers E1 could
not have updated: the #753 generic-parser coverage tests read ns.extensionBlocks,
and Slice 2's printer tests built inline old-shape namespace literals
(models/enums/compositeTypes/extensionBlocks arrays). Route them through the
namespacePslExtensionBlocks helper and the makeNs factory, matching the rest of
the entries migration. No behaviour change; psl-parser 110, psl-printer 55.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…locks

The entries migration removed the PslNamespace.extensionBlocks field, but two
JSDoc @link references still pointed at it. Repoint them at entries +
namespacePslExtensionBlocks. Doc-only.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
…te types

Address PR review:
- Replace the Object.create(null, {…descriptors…}) + whole-object blindCast in
  makePslNamespace with a PslNamespaceNode class: entries stored in the
  constructor, models/enums/compositeTypes as getter accessors. Prototype
  getters are non-enumerable by construction, so the spread/serialize guarantee
  holds without descriptor gymnastics, and the whole-object cast is gone (the
  per-getter slice narrowing remains). makePslNamespace returns an instance.
- Add a JSDoc to PslCompositeType explaining what a composite type is (an
  embedded reusable field group, the `type X { … }` block), since the term was
  unclear in review.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
The canonical-entries fact was documented three times over (interface JSDoc with
two code blocks, the entries field, the class), and several comments restated the
getter code or described branching the code does not have. Trim to tight doc on
each exported type; let the uniform entries[kind][name] lookups speak for
themselves. Also fold the extension-block grouping in makePslNamespaceEntries into
a spread rather than a copy loop with a how-it-works comment. No behaviour change.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
@wmadden
wmadden force-pushed the tml-2849-slice-3-psl-ast-entries-migration branch from 3a9355f to 3b628dc Compare June 8, 2026 10:34
@wmadden
wmadden merged commit 3496511 into main Jun 8, 2026
9 checks passed
@wmadden
wmadden deleted the tml-2849-slice-3-psl-ast-entries-migration branch June 8, 2026 10:34
wmadden-electric pushed a commit that referenced this pull request Jun 8, 2026
All four slices delivered (#753/#754/#757 + this PR); the durable architecture
decisions landed in ADR 126/225 and the retro lessons in adr-writing.mdc +
docs/Testing Guide.md. The transient project workspace (spec, plans, slice
plans) drops with the close-out. No external references to scrub.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
wmadden added a commit that referenced this pull request Jun 8, 2026
…ecture docs

Make the architecture record match what Slices 1-3 shipped (#753/#754/#757):
- Rewrite ADR 126 from the superseded parseFn/validateFn/emitFn function SPI to
  the declarative AuthoringPslBlockDescriptor design: keyword + name + typed
  parameters (ref/value/option/list), interpreted by one generic framework
  parser/validator/printer; value rides the codec JSON medium; option is an
  authoring-token constraint, not a domain enum; the block lowers via the
  entityTypes factory.
- Add ADR 225: how the three layers carry a pack-contributed entity kind, tied
  by its discriminator (IR class -> entityTypes lowering -> declarative
  parse+print). Subsystem doc 6 points at it.
- Fix the AuthoringContributions.entities -> entityTypes doc-bug in AGENTS.md
  (CLAUDE.md symlinks it) and docs/reference/typescript-patterns.md.

Markdown-only. Project close-out (project-dir deletion + retro) follows separately.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Signed-off-by: Will Madden <[email protected]>
wmadden added a commit that referenced this pull request Jun 8, 2026
All four slices delivered (#753/#754/#757 + this PR); the durable architecture
decisions landed in ADR 126/225 and the retro lessons in adr-writing.mdc +
docs/Testing Guide.md. The transient project workspace (spec, plans, slice
plans) drops with the close-out. No external references to scrub.

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