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

docs(enums): enums-as-domain-concept — project spec, plan, design notes - #748

Merged
wmadden merged 1 commit into
mainfrom
enums-as-domain-concept-planning
Jun 7, 2026
Merged

wmadden merged 1 commit into
mainfrom
enums-as-domain-concept-planning

Conversation

@wmadden

@wmadden wmadden commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Planning/shaping artifacts for the Enums as a domain concept project. Docs only — no implementation. Opened so the spec, plan, and design notes can be referenced from the slice issues and other PRs.

What is here

  • projects/enums-as-domain-concept/spec.md — decision-first project spec (worked example, design components mapped to requirements R1–R9, alternatives considered).
  • projects/enums-as-domain-concept/plan.md — four-slice composition (substrate → parallel realization pair → cleanup) with Linear links.
  • projects/enums-as-domain-concept/design-notes.md — synthesized design rationale.
  • Renames the prior postgres-enum-finishing shaping workspace.

The decision

An enum becomes a domain-plane concept: a codec is the type, an enum is a named valueSet restriction narrowing the permitted values. Storage realizes it as a named value-set + check constraint (never native CREATE TYPE); the persistence strategy is carried by structure, not a marker. The native Postgres enum machinery is deleted, restorable later as a different storage shape.

Slices (implementation lands in these, not here)

  • TML-2850 — Slice 1 · enum-contract-substrate
  • TML-2851 — Slice 2 · check-constraint-realization (∥ slice 3)
  • TML-2852 — Slice 3 · application-read-surface (∥ slice 2)
  • TML-2853 — Slice 4 · delete-native-enum-machinery

Linear project: https://linear.app/prisma-company/project/enums-as-a-domain-concept-696d6b36cb89

Refs TML-2850, TML-2851, TML-2852, TML-2853.

Scope

Documentation under projects/ only. No source, fixtures, or behavior change; the diff is the three artifacts plus the workspace rename. ~30-second review.

🤖 Generated with Claude Code

Reframe enums from a storage-plane native Postgres type to a domain-plane
concept: a codec is the type, an enum is a named valueSet restriction.
Storage realizes it as a named value-set + check constraint; native enum
machinery is removed (restorable as a different storage shape). Adds the
project spec, plan, and design-notes; renames the prior
postgres-enum-finishing workspace.

Refs TML-2850, TML-2851, TML-2852, TML-2853.

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

coderabbitai Bot commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Review was skipped due to path filters

⛔ Files ignored due to path filters (4)
  • projects/enums-as-domain-concept/design-notes.md is excluded by !projects/**
  • projects/enums-as-domain-concept/plan.md is excluded by !projects/**
  • projects/enums-as-domain-concept/spec.md is excluded by !projects/**
  • projects/postgres-enum-finishing/spec.md is excluded by !projects/**

CodeRabbit blocks several paths by default. You can override this behavior by explicitly including those paths in the path filters. For example, including **/dist/** will override the default block on the dist directory, by removing the pattern from both the lists.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 5d422fca-b38c-47c7-8a95-bb79879d5fc1

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch enums-as-domain-concept-planning

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

@wmadden
wmadden merged commit f8e89b3 into main Jun 7, 2026
18 of 19 checks passed
@wmadden
wmadden deleted the enums-as-domain-concept-planning branch June 7, 2026 10:00
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]>
wmadden-electric pushed a commit that referenced this pull request Jun 8, 2026
… reading

Lead each ADR with a grounding example and the decision, build up why -> how,
move the rejected alternatives (function SPI; option-as-enum; per-layer keys;
framework per-kind awareness) to the end. Strip references that will not age in
a long-lived doc: the PR #718 "earlier implementation" framing, the PR #748
pointer, and the "before this ADR" preceding-state phrasing. No content claims
changed.

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
… reading

Lead each ADR with a grounding example and the decision, build up why -> how,
move the rejected alternatives (function SPI; option-as-enum; per-layer keys;
framework per-kind awareness) to the end. Strip references that will not age in
a long-lived doc: the PR #718 "earlier implementation" framing, the PR #748
pointer, and the "before this ADR" preceding-state phrasing. No content claims
changed.

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.

1 participant