Skip to content

TML-2915: Infer an enum's @@type from its members#905

Merged
wmadden merged 6 commits into
mainfrom
tml-2915-enum-conveniences
Jul 2, 2026
Merged

TML-2915: Infer an enum's @@type from its members#905
wmadden merged 6 commits into
mainfrom
tml-2915-enum-conveniences

Conversation

@wmadden-electric

@wmadden-electric wmadden-electric commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

At a glance

Before, an enum had to spell out its @@type. Now it can leave it off:

enum Role {          // inferred: @@type("pg/text@1"), admin = "admin", user = "user"
  admin
  user
}

enum Priority {      // inferred: @@type("pg/int@1")
  low  = 1
  high = 2
}

The decision

Let an enum block omit @@type, and infer the codec from its members. The rule is deliberately small:

  • every member is a bare name or a string value → the target's text codec
  • every member is an integer value → the target's int codec
  • anything else — float, bigint, boolean, or a mix → a PSL_ENUM_CANNOT_INFER_TYPE diagnostic that says to add an explicit @@type(...)

An explicit @@type still wins and behaves exactly as before. This covers the two common cases and asks you to be explicit for everything else. It applies to Postgres, SQLite, and Mongo.

Why it's a small change

Most of this already worked. The parser already tags each enum member as bare (admin) or a value (admin = 1), and the interpreter already lowers both — a bare member feeds its name through the codec, a value member decodes its right-hand side. So bare names and numeric values already parsed and lowered fine; the only thing that forced you to write @@type was that it was mandatory. This PR replaces that "missing @@type" error, when the attribute is absent, with the inference above.

How it works

A shared classifyEnumMemberType helper looks at the members and returns text, int, or "can't tell". Each family's enum factory calls it when @@type is absent and picks the target's default codec. Those default codec ids (pg/text@1 / pg/int@1, sqlite/text@1 / sqlite/integer@1, mongo/string@1 / mongo/int32@1) are supplied by each target on the authoring context. The field is optional on that context, because the TypeScript authoring path always names its codec explicitly and never infers.

Testing

Per-family factory tests for every branch (bare→text, string→text, integer→int, and float/boolean/mixed → the diagnostic), a unit test for the classifier, and a Mongo integration test proving a no-@@type enum lowers with the inferred codec end to end. Explicit-@@type fixtures are unchanged (fixtures:check clean). Build, typecheck, lint, and the test suites pass.

Alternatives considered

  • A new keyword (e.g. enum Role text { … }). Rejected — this is @@type omission, which needs no new grammar and reads as "the obvious default"; a keyword is more surface for the same result.
  • Matching this in the TypeScript builder. Rejected — the TS enumType/member API already takes an explicit codec and has no ambiguity to resolve, so there's nothing to infer. (That's also why the context field is optional rather than required.)
  • Inferring more types — floats, bigints, booleans, mixed members. Rejected for now — a convenience should be predictable; these stay explicit, and the diagnostic points the way. Easy to extend later if the demand shows up.

Spec + plan: projects/enums-as-domain-concept/slices/infer-enum-type-from-members/. Closes TML-2915.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Enum definitions can now infer their type when @@type is omitted, based on member values.
    • Support was added for both text and integer enum inference across supported targets.
  • Bug Fixes
    • Improved diagnostics when enum type can’t be inferred, with clearer error reporting for mixed or unsupported member values.
    • Explicit enum type handling continues to work as before.

…2915)

Slice contract + two-dispatch plan. The parser/interpreter already handle bare
names and numeric member values; the only gap is that @@type is mandatory. Infer
it when omitted — text codec for bare/string members, int for integers, error
otherwise — via a shared classifier + per-pack default codec ids, both families.

Signed-off-by: willbot <w.a.madden+machine@gmail.com>
Signed-off-by: Will Madden <madden@prisma.io>
A PSL enum block may omit @@type; the codec is inferred from the members — the
target's text codec when every member is a bare name or string value, the int
codec when every member is an integer, and a PSL_ENUM_CANNOT_INFER_TYPE
diagnostic otherwise. Explicit @@type is unchanged. Works for Postgres, SQLite,
and Mongo.

A shared classifyEnumMemberType helper classifies the members; each family enum
factory infers when @@type is absent. The target's default codec ids ride on an
optional AuthoringEntityContext.enumInferenceCodecs, populated on the PSL path;
the TypeScript authoring path never infers, so the field is optional there.

Signed-off-by: willbot <w.a.madden+machine@gmail.com>
Signed-off-by: Will Madden <madden@prisma.io>
@wmadden-electric wmadden-electric requested a review from a team as a code owner July 2, 2026 15:54
@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds PSL enum @@type inference from member values when omitted, via new classifyEnumMemberType and resolveEnumCodecId helpers with an enumInferenceCodecs context option. Wires this through Mongo/SQL interpreters, providers, family enum factories, extension configs, a new Mongo adapter codec-ids export, and associated tests.

Changes

Enum type inference

Layer / File(s) Summary
Core classification and resolution helpers
packages/1-framework/1-core/framework-components/src/shared/framework-authoring.ts, .../src/exports/authoring.ts, .../test/framework-components.authoring.test.ts
Adds EnumInferredMemberType, classifyEnumMemberType, resolveEnumCodecId, extends AuthoringEntityContext with enumInferenceCodecs, re-exports both helpers, and adds unit tests.
Mongo family enum inference
packages/2-mongo-family/2-authoring/contract-psl/src/interpreter.ts, .../src/provider.ts, packages/2-mongo-family/9-family/src/core/authoring-entity-types.ts, .../test/authoring-entity-types.enum.test.ts, test/integration/test/mongo/interpreter.enum.test.ts
Interpreter/provider forward enumInferenceCodecs; mongo enum factory delegates to resolveEnumCodecId with codecSpan-based diagnostics; new unit and integration tests cover inference and failure cases.
SQL family enum factory
packages/2-sql/9-family/src/core/authoring-entity-types.ts, .../test/authoring-entity-types.enum.test.ts
Removes local quoted-string parsing, delegates to resolveEnumCodecId, updates diagnostic spans, and adds inference/explicit-type tests.
SQL interpreter, provider, target wiring
packages/2-sql/2-authoring/contract-psl/src/interpreter.ts, .../src/provider.ts, packages/3-targets/3-targets/postgres/src/core/postgres-contract-serializer.ts
Threads enumInferenceCodecs through InterpretPslDocumentToSqlContractInput, PrismaContractOptions, and Postgres serializer authoring context.
SQL fixtures and interpreter tests
packages/2-sql/2-authoring/contract-psl/test/fixtures.ts, .../test/interpreter.enum.test.ts
Fixtures delegate to resolveEnumCodecId, export Postgres/SQLite inference codec maps, extend helper return shapes, and expand describe.each inference test coverage for both targets.
Extension configs and Mongo adapter codec-ids export
packages/3-extensions/postgres/src/config/define-config.ts, packages/3-extensions/sqlite/src/config/define-config.ts, packages/3-extensions/mongo/src/config/define-config.ts, packages/3-mongo-target/2-mongo-adapter/package.json, .../src/exports/codec-ids.ts, .../tsdown.config.ts, skills/.../instructions.md
Extension configs pass target-specific enumInferenceCodecs; Mongo adapter gains a ./codec-ids export path; upgrade docs describe the new inference feature.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Config as defineConfig
  participant Provider as prismaContract/mongoContract provider
  participant Interpreter as interpretPslDocumentToXContract
  participant Factory as family enum descriptor factory
  participant Resolver as resolveEnumCodecId

  Config->>Provider: enumInferenceCodecs (text/int codec ids)
  Provider->>Interpreter: enumInferenceCodecs
  Interpreter->>Factory: entityContext with enumInferenceCodecs
  Factory->>Resolver: resolveEnumCodecId(block, ctx)
  Resolver->>Resolver: classifyEnumMemberType(block) if @@type omitted
  Resolver-->>Factory: codecId + codecSpan, or diagnostic
  Factory-->>Interpreter: enum entity or undefined
Loading

Suggested reviewers: wmadden, jkomyno

🚥 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 accurately summarizes the main change: inferring an enum's @@type from its members.
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.
✨ 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-2915-enum-conveniences

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 2, 2026

Copy link
Copy Markdown

Open in StackBlitz

@prisma-next/extension-author-tools

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

@prisma-next/mongo-runtime

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

@prisma-next/family-mongo

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

@prisma-next/sql-runtime

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

@prisma-next/family-sql

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

@prisma-next/extension-arktype-json

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

@prisma-next/middleware-cache

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

@prisma-next/mongo

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

@prisma-next/extension-paradedb

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

@prisma-next/extension-pgvector

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

@prisma-next/extension-postgis

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

@prisma-next/postgres

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

@prisma-next/sql-orm-client

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

@prisma-next/sqlite

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

@prisma-next/extension-supabase

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

@prisma-next/target-mongo

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

@prisma-next/adapter-mongo

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

@prisma-next/driver-mongo

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

@prisma-next/contract

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

@prisma-next/utils

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

@prisma-next/config

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

@prisma-next/errors

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

@prisma-next/framework-components

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

@prisma-next/operations

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

@prisma-next/ts-render

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

@prisma-next/contract-authoring

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

@prisma-next/ids

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

@prisma-next/psl-parser

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

@prisma-next/psl-printer

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

@prisma-next/cli

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

@prisma-next/cli-telemetry

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

@prisma-next/config-loader

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

@prisma-next/emitter

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

@prisma-next/language-server

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

@prisma-next/migration-tools

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

prisma-next

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

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

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

@prisma-next/mongo-codec

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

@prisma-next/mongo-contract

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

@prisma-next/mongo-value

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

@prisma-next/mongo-contract-psl

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

@prisma-next/mongo-contract-ts

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

@prisma-next/mongo-emitter

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

@prisma-next/mongo-schema-ir

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

@prisma-next/mongo-query-ast

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

@prisma-next/mongo-orm

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

@prisma-next/mongo-query-builder

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

@prisma-next/mongo-lowering

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

@prisma-next/mongo-wire

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

@prisma-next/sql-contract

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

@prisma-next/sql-errors

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

@prisma-next/sql-operations

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

@prisma-next/sql-schema-ir

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

@prisma-next/sql-contract-psl

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

@prisma-next/sql-contract-ts

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

@prisma-next/sql-contract-emitter

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

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

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

@prisma-next/sql-relational-core

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

@prisma-next/sql-builder

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

@prisma-next/target-postgres

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

@prisma-next/target-sqlite

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

@prisma-next/adapter-postgres

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

@prisma-next/adapter-sqlite

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

@prisma-next/driver-postgres

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

@prisma-next/driver-sqlite

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

commit: 2e9d7e8

@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown

size-limit report 📦

Path Size
postgres / no-emit 160.74 KB (+0.17% 🔺)
postgres / emit 147.87 KB (+0.21% 🔺)
mongo / no-emit 98.2 KB (+0.22% 🔺)
mongo / emit 89.39 KB (+0.03% 🔺)
cf-worker / no-emit 188.88 KB (+0.16% 🔺)
cf-worker / emit 174.17 KB (+0.18% 🔺)

@wmadden wmadden 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.

Why is there a comment about an incomplete Mongo dispatch?

Comment thread packages/2-mongo-family/2-authoring/contract-psl/src/interpreter.ts Outdated
The comment referenced a transient dispatch id and described a temporary
"required field" state that no longer exists — the mongo factory reads the
inferred codecs in this PR, and the field is optional.

Signed-off-by: willbot <w.a.madden+machine@gmail.com>
Signed-off-by: Will Madden <madden@prisma.io>

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
packages/2-mongo-family/9-family/test/authoring-entity-types.enum.test.ts (1)

102-177: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider mirroring SQL family's test coverage for parity.

The SQL enum test suite (packages/2-sql/9-family/test/authoring-entity-types.enum.test.ts) additionally covers a boolean-member-cannot-infer case and an "explicit @@type overrides a value that would otherwise fail inference" case. Since the mongo factory implementation is identical, mirroring those cases here would guard against regressions in the shared logic.

🤖 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-mongo-family/9-family/test/authoring-entity-types.enum.test.ts`
around lines 102 - 177, Add the missing Mongo enum inference parity cases in
authoring-entity-types.enum.test.ts by mirroring the SQL suite: extend the
mongoFamilyEnumEntityDescriptor coverage to include a
boolean-member-cannot-infer test and an explicit @@type overrides a value that
would otherwise fail inference test. Reuse the existing factory, enumBlock,
bareMember/valueMember, makeContext, and codecId assertions so the shared
inference logic is exercised consistently across mongo and SQL families.
packages/2-mongo-family/9-family/src/core/authoring-entity-types.ts (1)

13-18: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Duplicate inference/parsing logic between Mongo and SQL family factories.

parseQuotedString and the entire @@type inference/parsing branch (Lines 32-62) are byte-identical to the SQL family's packages/2-sql/9-family/src/core/authoring-entity-types.ts. Since classifyEnumMemberType is already shared via framework-components, consider also hoisting this codec-resolution logic (parseQuotedString + the branch that derives codecId/typeArgSpan) into a shared helper so both families stay in sync as this logic evolves.

Also applies to: 32-62

🤖 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-mongo-family/9-family/src/core/authoring-entity-types.ts` around
lines 13 - 18, The quoted-string parsing and @@type codec-resolution branch in
authoring-entity-types are duplicated between the Mongo and SQL family
factories. Extract parseQuotedString and the logic that derives codecId and
typeArgSpan into a shared helper, then have both family implementations call
that helper so the behavior stays consistent with classifyEnumMemberType and
future changes only need to be made once.
🤖 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.

Inline comments:
In `@packages/2-mongo-family/2-authoring/contract-psl/src/interpreter.ts`:
- Around line 961-963: Update the stale comment near enumInferenceCodecs in
interpreter.ts so it reflects the current behavior: Mongo’s enum factory already
consumes ctx.enumInferenceCodecs via classifyEnumMemberType(block), so remove
the “lands in TML-2915 D2”/“until Mongo’s own factory reads it” wording and
replace it with a note that inference is active now. Keep the change limited to
the comment text around the enumInferenceCodecs assignment and align it with the
implementation in authoring-entity-types.ts.

---

Nitpick comments:
In `@packages/2-mongo-family/9-family/src/core/authoring-entity-types.ts`:
- Around line 13-18: The quoted-string parsing and @@type codec-resolution
branch in authoring-entity-types are duplicated between the Mongo and SQL family
factories. Extract parseQuotedString and the logic that derives codecId and
typeArgSpan into a shared helper, then have both family implementations call
that helper so the behavior stays consistent with classifyEnumMemberType and
future changes only need to be made once.

In `@packages/2-mongo-family/9-family/test/authoring-entity-types.enum.test.ts`:
- Around line 102-177: Add the missing Mongo enum inference parity cases in
authoring-entity-types.enum.test.ts by mirroring the SQL suite: extend the
mongoFamilyEnumEntityDescriptor coverage to include a
boolean-member-cannot-infer test and an explicit @@type overrides a value that
would otherwise fail inference test. Reuse the existing factory, enumBlock,
bareMember/valueMember, makeContext, and codecId assertions so the shared
inference logic is exercised consistently across mongo and SQL families.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: ec026b47-2b47-4ab5-a5cb-1460367743b7

📥 Commits

Reviewing files that changed from the base of the PR and between 5c898e7 and 38c88b6.

⛔ Files ignored due to path filters (2)
  • projects/enums-as-domain-concept/slices/infer-enum-type-from-members/plan.md is excluded by !projects/**
  • projects/enums-as-domain-concept/slices/infer-enum-type-from-members/spec.md is excluded by !projects/**
📒 Files selected for processing (31)
  • packages/1-framework/1-core/framework-components/src/exports/authoring.ts
  • packages/1-framework/1-core/framework-components/src/shared/framework-authoring.ts
  • packages/1-framework/1-core/framework-components/test/framework-components.authoring.test.ts
  • packages/2-mongo-family/2-authoring/contract-psl/src/interpreter.ts
  • packages/2-mongo-family/9-family/src/core/authoring-entity-types.ts
  • packages/2-mongo-family/9-family/test/authoring-entity-types.enum.test.ts
  • packages/2-sql/2-authoring/contract-psl/src/interpreter.ts
  • packages/2-sql/2-authoring/contract-psl/src/provider.ts
  • packages/2-sql/2-authoring/contract-psl/test/composed-mutation-defaults.test.ts
  • packages/2-sql/2-authoring/contract-psl/test/fixtures.ts
  • packages/2-sql/2-authoring/contract-psl/test/interpreter.control-policy.test.ts
  • packages/2-sql/2-authoring/contract-psl/test/interpreter.defaults.test.ts
  • packages/2-sql/2-authoring/contract-psl/test/interpreter.diagnostics.test.ts
  • packages/2-sql/2-authoring/contract-psl/test/interpreter.enum.test.ts
  • packages/2-sql/2-authoring/contract-psl/test/interpreter.extensions.test.ts
  • packages/2-sql/2-authoring/contract-psl/test/interpreter.namespaces.test.ts
  • packages/2-sql/2-authoring/contract-psl/test/interpreter.polymorphism.test.ts
  • packages/2-sql/2-authoring/contract-psl/test/interpreter.relations.many-to-many.test.ts
  • packages/2-sql/2-authoring/contract-psl/test/interpreter.relations.test.ts
  • packages/2-sql/2-authoring/contract-psl/test/interpreter.test.ts
  • packages/2-sql/2-authoring/contract-psl/test/interpreter.types.test.ts
  • packages/2-sql/2-authoring/contract-psl/test/interpreter.value-objects.test.ts
  • packages/2-sql/2-authoring/contract-psl/test/provider.test.ts
  • packages/2-sql/2-authoring/contract-psl/test/psl-ts-namespace-parity.test.ts
  • packages/2-sql/2-authoring/contract-psl/test/ts-psl-parity.test.ts
  • packages/2-sql/9-family/src/core/authoring-entity-types.ts
  • packages/2-sql/9-family/test/authoring-entity-types.enum.test.ts
  • packages/3-extensions/postgres/src/config/define-config.ts
  • packages/3-extensions/sqlite/src/config/define-config.ts
  • packages/3-targets/3-targets/postgres/src/core/postgres-contract-serializer.ts
  • test/integration/test/mongo/interpreter.enum.test.ts

Comment thread packages/2-mongo-family/2-authoring/contract-psl/src/interpreter.ts Outdated
Comment thread packages/2-mongo-family/2-authoring/contract-psl/src/interpreter.ts Outdated
… not the interpreter

Mirror the Postgres/SQLite pattern: the mongo defineConfig injects
enumInferenceCodecs into the provider, which threads it into the interpreter as
input; the family-layer interpreter no longer hardcodes mongo codec ids. Adds a
@prisma-next/adapter-mongo/codec-ids entrypoint (the mongo analogue of
target-postgres/codec-ids) so the config imports the constants.

Signed-off-by: willbot <w.a.madden+machine@gmail.com>
Signed-off-by: Will Madden <madden@prisma.io>
… churn

Address review: collapse the duplicated infer/explicit @@type resolution from both
family factories (and the test fixture) into a single resolveEnumCodecId in
framework-components, so SQL/Mongo symmetry is structural, not copied. Revert the
~15 test files that only carried a vestigial enumInferenceCodecs line from the
abandoned "required-field" iteration (the field is optional). Record the additive
change as incidental for the 0.14->0.15 extension-author upgrade.

Signed-off-by: willbot <w.a.madden+machine@gmail.com>
Signed-off-by: Will Madden <madden@prisma.io>
@wmadden wmadden enabled auto-merge July 2, 2026 18:55
…ences

# Conflicts:
#	packages/2-sql/2-authoring/contract-psl/src/interpreter.ts
#	packages/2-sql/2-authoring/contract-psl/test/interpreter.enum.test.ts
#	skills/extension-author/prisma-next-extension-upgrade/upgrades/0.14-to-0.15/instructions.md

@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 (2)
packages/2-mongo-family/9-family/src/core/authoring-entity-types.ts (1)

13-138: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy lift

Enum factory body (member decoding/validation, lines ~52-136) is byte-for-byte identical to packages/2-sql/9-family/src/core/authoring-entity-types.ts.

Only the @@type resolution (lines 24-47, now delegated to the new resolveEnumCodecId) was deduplicated in this PR; the remaining ~85 lines of member iteration/decoding/duplicate-detection logic remain duplicated verbatim across the Mongo and SQL families. Given this PR already established the pattern of extracting shared enum logic into framework-components, extending that to the member-decoding loop would remove the remaining duplication (pre-existing, not introduced by this diff).

🤖 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-mongo-family/9-family/src/core/authoring-entity-types.ts` around
lines 13 - 138, The enum factory in mongoFamilyEnumEntityDescriptor still
duplicates the member decoding, validation, and duplicate-detection logic found
in the SQL family’s authoring-entity-types module. Extract the shared loop and
related error handling into a reusable helper in framework-components, then have
mongoFamilyEnumEntityDescriptor.factory and the SQL equivalent call that helper
after resolveEnumCodecId so the two families only differ in their small
family-specific setup.
packages/1-framework/1-core/framework-components/src/shared/framework-authoring.ts (1)

191-198: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Doc comment on exported function may run against the "avoid comments" guideline.

This is an 8-line JSDoc block explaining resolveEnumCodecId's contract (codecSpan semantics, diagnostic push side-effect, cross-family sharing rationale). As per coding guidelines, **/*.{ts,tsx,js,jsx,mts,mjs}: "Don't add comments if avoidable, prefer code that expresses its intent." Given the non-obvious return semantics (implicit error signaling via undefined + diagnostics sink), this may be a reasonable exception, but flagging for awareness since it's a fairly large comment block for a codebase with this rule.

🤖 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/1-framework/1-core/framework-components/src/shared/framework-authoring.ts`
around lines 191 - 198, The JSDoc on resolveEnumCodecId is larger than needed
and may conflict with the “avoid comments” guideline. Trim or remove the block
in framework-authoring.ts, keeping only the essential contract details that
cannot be expressed by the function signature or types, and prefer concise code
or naming to convey the codecSpan/diagnostic behavior. If documentation is still
needed, shorten it substantially and keep it directly aligned with
resolveEnumCodecId’s exported API.

Source: Coding guidelines

🤖 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/1-framework/1-core/framework-components/src/shared/framework-authoring.ts`:
- Around line 191-198: The JSDoc on resolveEnumCodecId is larger than needed and
may conflict with the “avoid comments” guideline. Trim or remove the block in
framework-authoring.ts, keeping only the essential contract details that cannot
be expressed by the function signature or types, and prefer concise code or
naming to convey the codecSpan/diagnostic behavior. If documentation is still
needed, shorten it substantially and keep it directly aligned with
resolveEnumCodecId’s exported API.

In `@packages/2-mongo-family/9-family/src/core/authoring-entity-types.ts`:
- Around line 13-138: The enum factory in mongoFamilyEnumEntityDescriptor still
duplicates the member decoding, validation, and duplicate-detection logic found
in the SQL family’s authoring-entity-types module. Extract the shared loop and
related error handling into a reusable helper in framework-components, then have
mongoFamilyEnumEntityDescriptor.factory and the SQL equivalent call that helper
after resolveEnumCodecId so the two families only differ in their small
family-specific setup.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: 7782b4f5-4c78-4a54-a259-1373da6862ff

📥 Commits

Reviewing files that changed from the base of the PR and between 374855e and 2e9d7e8.

📒 Files selected for processing (16)
  • packages/1-framework/1-core/framework-components/src/exports/authoring.ts
  • packages/1-framework/1-core/framework-components/src/shared/framework-authoring.ts
  • packages/2-mongo-family/2-authoring/contract-psl/src/interpreter.ts
  • packages/2-mongo-family/2-authoring/contract-psl/src/provider.ts
  • packages/2-mongo-family/9-family/src/core/authoring-entity-types.ts
  • packages/2-sql/2-authoring/contract-psl/src/interpreter.ts
  • packages/2-sql/2-authoring/contract-psl/src/provider.ts
  • packages/2-sql/2-authoring/contract-psl/test/fixtures.ts
  • packages/2-sql/2-authoring/contract-psl/test/interpreter.enum.test.ts
  • packages/2-sql/9-family/src/core/authoring-entity-types.ts
  • packages/3-extensions/mongo/src/config/define-config.ts
  • packages/3-mongo-target/2-mongo-adapter/package.json
  • packages/3-mongo-target/2-mongo-adapter/src/exports/codec-ids.ts
  • packages/3-mongo-target/2-mongo-adapter/tsdown.config.ts
  • skills/extension-author/prisma-next-extension-upgrade/upgrades/0.14-to-0.15/instructions.md
  • test/integration/test/mongo/interpreter.enum.test.ts
✅ Files skipped from review due to trivial changes (1)
  • skills/extension-author/prisma-next-extension-upgrade/upgrades/0.14-to-0.15/instructions.md
🚧 Files skipped from review as they are similar to previous changes (7)
  • packages/1-framework/1-core/framework-components/src/exports/authoring.ts
  • packages/2-sql/2-authoring/contract-psl/src/provider.ts
  • test/integration/test/mongo/interpreter.enum.test.ts
  • packages/2-sql/2-authoring/contract-psl/src/interpreter.ts
  • packages/2-mongo-family/2-authoring/contract-psl/src/interpreter.ts
  • packages/2-sql/2-authoring/contract-psl/test/interpreter.enum.test.ts
  • packages/2-sql/2-authoring/contract-psl/test/fixtures.ts

@wmadden wmadden added this pull request to the merge queue Jul 2, 2026
Merged via the queue into main with commit 284a838 Jul 2, 2026
21 checks passed
@wmadden wmadden deleted the tml-2915-enum-conveniences branch July 2, 2026 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants