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

TML-2956: migrate @default to declarative attribute specs (both paths) - #938

Merged
SevInf merged 29 commits into
mainfrom
tml-2956-sql-default
Jul 14, 2026
Merged

SevInf merged 29 commits into
mainfrom
tml-2956-sql-default

Conversation

@SevInf

@SevInf SevInf commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Linked issue

Refs TML-2956 — "Language Tools Support Prisma Next PSL".

Follow-up to #932 (the 7 non-@default SQL attributes). This PR finishes the SQL family: @default was split out of that slice because of its size, and lands here. With it, every SQL attribute's argument parsing is declarative — and @default's spec is composed dynamically per field, so the grammar itself describes exactly which values are valid at each site.

At a glance

The @default spec is built per field from the field's resolved context (the composed default-function registry, isList, and — for enum fields — the enum's members), composed entirely from atomic combinators via oneOf:

// non-enum field, from { isList, registry }
oneOf(
  str(), num(), bool(),                                          // flexible literals (codec still type-checks the value)
  ...(isList ? [list(oneOf(str(), num(), bool()))] : []),        // list arm ONLY on list fields
  ...[...registry.entries()].map(([name, entry]) =>             // one typed arm per registered default function
    funcCall(name, entry.signature)),
)

// enum field, from enumHandle.enumMembers
oneOf(...enumMembers.map((m) => identifier(m.name)))             // e.g. Expected one of: Low | High

Each default function now declares an argument signature built from combinators — so uuid(4) / uuid(7), the required cuid(2), nanoid's 2..255 size, and dbgenerated's string are parsed and range/shape-checked by the grammar, and each registry lower receives a typed { fn, span, args } call instead of re-parsing argument source text:

// adapter registry entry (postgres/sqlite)
['uuid', { signature: { positional: [{ key: 'version', type: optional(oneOf(num(4), num(7))) }] },
           lower: (i) => i.call.args.version === 7 ? gen('uuidv7') : gen('uuidv4') }]

Previously @default was parsed by three hand-written string scanners (parseDefaultLiteralValue, parseListDefaultExpression, a ~160-line parseDefaultFunctionCall) and each registry lower re-parsed raw argument strings (parseIntegerArgument, parseStringLiteral, expectNoArgs, manual count checks). All of it is gone; the specs interpret the real AST and the lower bodies read typed args.

Decision

This PR makes @default spec-driven on both lowering paths and composes each spec dynamically per field:

  1. Dynamic non-enum spec — buildDefaultSpec({ isList, registry }) composes literal/list/function arms; the list arm exists only for list fields, and one funcCall(name) arm is emitted per registered default function.
  2. Dynamic enum spec — buildEnumDefaultSpec(members) is oneOf(identifier(member)…), so a bare member name is validated against the actual enum by the grammar.
  3. Kit — funcCall(name, signature) (name-pinned, parallel to identifier(name)) parses a call's arguments through a recursive positional/named signature into a typed { fn, span, args }; a general num() number-literal atom (any number incl. floats; int({ min, max }) stays integer-only, now bounded); str()/bool()/list()/oneOf()/identifier()/optional() reused as-is.
  4. Typed function arguments (ADR 231). Each SQL default function declares a FuncCallSig; the registry lower reads the typed args cast-free (typeof/literal comparisons), and the imperative arg parsers are deleted. Because FuncCallSig is authoring-layer and the core registry entry can't name it, signature is an opaque unknown on the entry, narrowed with one justified blindCast<FuncCallSig> in buildDefaultSpec.
  5. Validation lifted into the grammar — unknown function name, unknown enum member, and now argument shape / arity / range are PSL_INVALID_ATTRIBUTE_SYNTAX grammar failures; array-on-scalar / scalar-on-list are grammar misses. The single surviving semantic arg check is dbgenerated empty → PSL_INVALID_DEFAULT_FUNCTION_ARGUMENT. Each per-field spec becomes a precise description a future language server can read for autocomplete.
  6. Dead-code removal — the three legacy string scanners, funcCall's span-arithmetic chain, the monolithic scalarLiteral()/bareIdentifier() combinators, and the per-lower imperative arg parsers (parseIntegerArgument/parseStringLiteral/expectNoArgs) — all deleted (net −589 lines in the final commit).

Only argument syntax moved to specs; the genuinely semantic rules stay in the interpreter.

How it fits together

  1. Atomic combinators. str()/num()/bool() are flexible literal leaves; funcCall(name) matches a call with an exact callee (raw args captured — the registry still validates them); identifier(name) matches an exact bare identifier. Array defaults reuse list().
  2. The spec is assembled at interpretation time. lowerDefaultForField calls buildDefaultSpec({ isList, registry }); lowerEnumDefaultForField calls buildEnumDefaultSpec(enumHandle.enumMembers.map(m => m.name)). Because the registry and field facts are in hand there, oneOf(funcCall(name)…) enumerates the open contributed function set — no bespoke funcCallFrom combinator needed (composition over special-casing, per ADR 231 principle 4).
  3. Interpreter keeps the semantics. For a function value, the interpreter hands the typed call to lowerDefaultFunctionWithRegistry → entry.lower, which now reads typed args and keeps generator applicability + codec matching (PSL_INVALID_DEFAULT_APPLICABILITY) and the dbgenerated-empty check (PSL_INVALID_DEFAULT_FUNCTION_ARGUMENT). Literal↔codec type is still enforced downstream by the codec's encodeJson. For enum, the interpreter maps the (grammar-validated) member name to its value.
  4. Grammar subsumes the shape/membership/arity checks. With the list arm gated on isList, one funcCall(name, sig)/identifier(member) arm per known function/member, and each function's args range/shape-checked by its signature, an unknown function, unknown member, scalar-on-list, array-on-scalar, or malformed argument is just an unmatched oneOf — one uniform PSL_INVALID_ATTRIBUTE_SYNTAX.

Behavior changes & evidence

  • @default specs are composed per field. The function set and enum-member set come from the field's context, so the spec describes exactly what's valid there. See sql-attribute-specs.ts (buildDefaultSpec/buildEnumDefaultSpec); wired in psl-column-resolution.ts + psl-field-resolution.ts.
  • Unknown function name and unknown enum member are now grammar failures (PSL_INVALID_ATTRIBUTE_SYNTAX, Expected one of: …), replacing the post-validation PSL_UNKNOWN_DEFAULT_FUNCTION / PSL_ENUM_UNKNOWN_DEFAULT_MEMBER. Evidence in interpreter.defaults.test.ts + interpreter.enum.test.ts.
  • funcCall(name, signature) parses typed args; num(value)/int({min,max}) added. funcCall('now') matches now() but not foo.now(); a signed call binds args into { fn, span, args }. See func-call.ts + num.ts; evidence in attribute-spec-combinators.test.ts.
  • Malformed function arguments are now grammar failures. uuid(5), cuid(), nanoid(1), dbgenerated(123), and args-on-nullary shift from PSL_INVALID_DEFAULT_FUNCTION_ARGUMENT / PSL_UNKNOWN_DEFAULT_FUNCTION to PSL_INVALID_ATTRIBUTE_SYNTAX (operator "Option A"). Registry lower bodies read typed args and are cast-free. See default-function-registry.ts, control-mutation-defaults.ts; evidence in interpreter.defaults.test.ts + the adapter control-mutation-defaults.test.ts.

Reviewer notes

  • funcCallFrom was never built. oneOf(...registry.keys().map(funcCall)), composed at interpretation time, is the open-set dispatch the ADR proposed funcCallFrom for — with the matched arm as the fn discriminant. Composition over a bespoke combinator (ADR 231 principle 4).
  • matchingScalarLiteral deferred; literals stay flexible. Codec value-validation remains the codec's encodeJson (the single authority, shared with the TS builder); moving it into the grammar would need codec accept-schema metadata that doesn't exist yet. Recorded in the slice spec.
  • oneOf variadic typing. buildDefaultSpec/buildEnumDefaultSpec annotate the arms as a non-empty readonly tuple (readonly [ArgType<T>, ...ArgType<T>[]]) to satisfy oneOf's constraint — no casts.
  • Diagnostic-code shifts are intentional (consistent with TML-2956: migrate 7 SQL attributes to declarative attribute specs #932 / operator "Option A"): shape, membership, and function-argument arity/range errors → PSL_INVALID_ATTRIBUTE_SYNTAX; genuinely semantic codes (PSL_INVALID_DEFAULT_FUNCTION_ARGUMENT for dbgenerated empty, PSL_INVALID_DEFAULT_APPLICABILITY) preserved. Coarse-diagnostic trade-off (accepted per ADR 231): a malformed argument on a callee-matched funcCall arm makes the outer oneOf backtrack to a generic Expected one of: … message, so @default(uuid(5)) no longer gets a uuid-specific hint. cuid() loses its former "use cuid(2)" guidance for the same reason.
  • ⚠ Breaking change to the extension-authoring contract. ControlMutationDefaultEntry.lower now receives a typed TypedDefaultFunctionCall (was ParsedDefaultFunctionCall), and an arg-bearing contributed default function must declare a signature. Any extension contributing default functions must migrate (the default-pack-slugid parity fixture was migrated as the in-repo example). Downstream-upgrade need recorded in the slice spec.
  • Bundling fix: @prisma-next/psl-parser promoted from a dev- to a runtime dependency of adapter-postgres so tsdown externalises (not bundles) the combinators — a bundled copy gave num()/str() private AST classes, failing instanceof against sql-contract-psl-parsed nodes so every valid argumented @default silently failed to parse. Invisible to source-resolved unit tests; caught only by the dist-consuming real-pack parity suite.
  • ADR 231 left untouched (operator instruction); the deviations (funcCallFrom dropped for oneOf(funcCall(name, sig)); matchingScalarLiteral deferred; typed-funcCall provenance) are recorded in the slice spec.
  • Project artefacts under projects/typed-attribute-parsers/slices/sql-default/ are included for review provenance; migrated/removed at project close-out.

Verification

Run on final HEAD:

  • pnpm --filter @prisma-next/framework-components build && typecheck && test — clean; 469 tests
  • pnpm --filter @prisma-next/psl-parser build && typecheck && test — clean; 623 tests
  • pnpm --filter @prisma-next/sql-contract-psl typecheck && test — clean; 333 tests
  • pnpm --filter @prisma-next/adapter-postgres typecheck && test (+ coverage ≥ thresholds) — 675 tests
  • pnpm --filter @prisma-next/adapter-sqlite typecheck && test — 220 tests
  • Integration authoring parity (incl. dist-consuming real-pack instanceof parity + @default diagnostics fixtures) — 50 tests
  • pnpm build — 68/68 · pnpm fixtures:check — clean, no drift · pnpm lint:framework-vocabulary — 836/836 · pnpm lint:deps — 0 violations

Follow-ups

  • Mongo family attribute + @default migration — the remaining slice of TML-2956.
  • Language-server autocomplete reading these per-field specs — the deferred LS-scoped work this dynamic design enables.

Alternatives considered

  • funcCallFrom(registry) as a dedicated combinator. Rejected: with dynamic per-field construction the registry is in hand, so oneOf(funcCall(name)…) composes the same open-set dispatch without a bespoke combinator or dragging registry concerns into the kit.
  • matchingScalarLiteral() / codec-typed literals now. Rejected for this PR: literal↔type validation already lives at the codec's encodeJson; a spec-level matcher would duplicate it (drift risk) or need codec accept-schema metadata that doesn't exist. Deferred.
  • Keeping PSL_UNKNOWN_DEFAULT_FUNCTION / PSL_ENUM_UNKNOWN_DEFAULT_MEMBER as semantic checks. Rejected: folding membership into the grammar is the point (less post-validation), and oneOf's "Expected one of: …" preserves the helpful supported-set message.
  • Typing signature on the core entry as FuncCallSig (not unknown). Rejected: FuncCallSig lives in the authoring layer (@prisma-next/psl-parser); the core framework-components entry type cannot name it without a layering violation (pnpm lint:deps). The opaque-unknown + single narrowing blindCast in the SQL family is the layer-clean shape; the typed {fn,span,args} call passed to lower is plain-structural and needs no cast.
  • Keeping the imperative per-lower arg parsers. Rejected: that is exactly the raw-string re-parse ADR 231's typed funcCall replaces; the signatures make arg validation a grammar concern and delete the parsers.

Checklist

  • All commits are signed off (git commit -s) per the DCO.
  • I read CONTRIBUTING.md and the change is scoped to one logical concern.
  • Tests are updated.
  • The PR title is in TML-NNNN: <sentence-case title> form.
  • Skill update: n/a — internal refactor; @default argument-syntax error codes consolidated (documented in the slice spec), no CLI/API/config surface change.

@SevInf
SevInf requested a review from a team as a code owner July 9, 2026 14:43
@coderabbitai

coderabbitai Bot commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds numeric and pinned function-call PSL combinators, introduces attribute-spec grammars for field and enum defaults, replaces manual default parsing with AST interpretation, and updates registry, resolution, and diagnostic tests.

Changes

Default parsing and resolution

Layer / File(s) Summary
PSL combinators and exports
packages/1-framework/2-authoring/psl-parser/src/attribute-spec/combinators/*, packages/1-framework/2-authoring/psl-parser/src/exports/index.ts, packages/1-framework/2-authoring/psl-parser/test/attribute-spec-combinators.test.ts
Adds numeric and pinned function-call parsers, public exports, and coverage for accepted and rejected AST shapes.
Default and enum attribute specifications
packages/2-sql/2-authoring/contract-psl/src/sql-attribute-specs.ts
Builds scalar/list default grammars with registered function calls and enum grammars from member names.
Default-function registry boundary
packages/2-sql/2-authoring/contract-psl/src/default-function-registry.ts, packages/2-sql/2-authoring/contract-psl/test/default-function-registry.test.ts
Removes string-based function-call parsing and updates registry tests to construct parsed calls directly.
Field default interpretation
packages/2-sql/2-authoring/contract-psl/src/psl-column-resolution.ts
Interprets default attribute nodes and lowers scalar, array, and function values with generator applicability validation.
Enum default interpretation
packages/2-sql/2-authoring/contract-psl/src/psl-field-resolution.ts
Uses generated enum attribute specifications to interpret and resolve enum member defaults.
Diagnostic expectation updates
packages/2-sql/2-authoring/contract-psl/test/*.test.ts
Updates invalid-default cases to expect PSL_INVALID_ATTRIBUTE_SYNTAX and supports assertions that omit diagnostic messages.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant PSLParser
  participant AttributeSpec
  participant FieldResolution
  participant DefaultRegistry
  PSLParser->>AttributeSpec: parse default value
  AttributeSpec-->>FieldResolution: interpreted scalar, array, or function call
  FieldResolution->>DefaultRegistry: lower parsed function call
  DefaultRegistry-->>FieldResolution: lowered default or diagnostic
Loading

Possibly related PRs

Suggested reviewers: wmadden

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: migrating @default parsing to declarative attribute specs on both paths.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch tml-2956-sql-default

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.


// A bare identifier (e.g. an enum member name) → its text. No validation; the
// caller decides what the identifier must resolve to.
export function bareIdentifier(): ArgType<string> {

@SevInf SevInf Jul 9, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we already have identifier in the kit?

@pkg-pr-new

pkg-pr-new Bot commented Jul 9, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@prisma-next/extension-author-tools

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

@prisma-next/mongo-runtime

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

@prisma-next/family-mongo

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

@prisma-next/sql-runtime

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

@prisma-next/family-sql

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

@prisma-next/extension-arktype-json

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

@prisma-next/middleware-cache

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

@prisma-next/mongo

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

@prisma-next/extension-paradedb

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

@prisma-next/extension-pgvector

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

@prisma-next/extension-postgis

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

@prisma-next/postgres

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

@prisma-next/sql-orm-client

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

@prisma-next/sqlite

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

@prisma-next/extension-supabase

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

@prisma-next/target-mongo

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

@prisma-next/adapter-mongo

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

@prisma-next/driver-mongo

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

@prisma-next/contract

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

@prisma-next/utils

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

@prisma-next/config

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

@prisma-next/errors

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

@prisma-next/framework-components

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

@prisma-next/operations

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

@prisma-next/ts-render

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

@prisma-next/contract-authoring

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

@prisma-next/ids

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

@prisma-next/psl-parser

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

@prisma-next/psl-printer

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

@prisma-next/cli

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

@prisma-next/cli-telemetry

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

@prisma-next/config-loader

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

@prisma-next/emitter

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

@prisma-next/language-server

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

@prisma-next/migration-tools

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

prisma-next

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

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

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

@prisma-next/mongo-codec

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

@prisma-next/mongo-contract

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

@prisma-next/mongo-value

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

@prisma-next/mongo-contract-psl

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

@prisma-next/mongo-contract-ts

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

@prisma-next/mongo-emitter

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

@prisma-next/mongo-schema-ir

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

@prisma-next/mongo-query-ast

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

@prisma-next/mongo-orm

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

@prisma-next/mongo-query-builder

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

@prisma-next/mongo-lowering

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

@prisma-next/mongo-wire

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

@prisma-next/sql-contract

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

@prisma-next/sql-errors

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

@prisma-next/sql-operations

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

@prisma-next/sql-schema-ir

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

@prisma-next/sql-contract-psl

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

@prisma-next/sql-contract-ts

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

@prisma-next/sql-contract-emitter

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

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

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

@prisma-next/sql-relational-core

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

@prisma-next/sql-builder

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

@prisma-next/target-postgres

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

@prisma-next/target-sqlite

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

@prisma-next/adapter-postgres

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

@prisma-next/adapter-sqlite

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

@prisma-next/driver-postgres

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

@prisma-next/driver-sqlite

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

commit: 2af855d

import { leafDiagnostic } from './diagnostic';

// A string, number, or boolean literal reduced to its decoded value (never re-slicing text).
export function scalarLiteral(): ArgType<string | number | boolean> {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we just combine existing parser via oneOf?

@github-actions

github-actions Bot commented Jul 9, 2026 •

Copy link
Copy Markdown

size-limit report 📦

Path Size
postgres / no-emit 155.2 KB (0%)
postgres / emit 130.22 KB (0%)
mongo / no-emit 98.71 KB (0%)
mongo / emit 89.43 KB (0%)
cf-worker / no-emit 182.7 KB (0%)
cf-worker / emit 155.2 KB (0%)

@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 (1)
packages/1-framework/2-authoring/psl-parser/test/attribute-spec-combinators.test.ts (1)

577-655: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider adding a test for funcCall() with multiple arguments.

The current tests cover nullary, single-string, and single-numeric arguments. A test with multiple arguments (e.g., foo(1, "bar")) would exercise the Array.from(arg.args(), ...) mapping with more than one element and verify argument ordering.

💡 Suggested additional test
   it('preserves a numeric argument as source text', () => {
     const { expr, ctx } = argOf('uuid(7)');

     const result = funcCall().parse(expr, ctx);

     expect(result.ok).toBe(true);
     if (result.ok) {
       expect(result.value.name).toBe('uuid');
       expect(result.value.args).toHaveLength(1);
       expect(result.value.args[0]?.raw).toBe('7');
     }
   });
+
+  it('captures multiple arguments in source order', () => {
+    const { expr, ctx } = argOf('foo(1, "bar", true)');
+
+    const result = funcCall().parse(expr, ctx);
+
+    expect(result.ok).toBe(true);
+    if (result.ok) {
+      expect(result.value.name).toBe('foo');
+      expect(result.value.args).toHaveLength(3);
+      expect(result.value.args[0]?.raw).toBe('1');
+      expect(result.value.args[1]?.raw).toBe('"bar"');
+      expect(result.value.args[2]?.raw).toBe('true');
+    }
+  });
🤖 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/2-authoring/psl-parser/test/attribute-spec-combinators.test.ts`
around lines 577 - 655, Add a `funcCall()` test that covers multiple arguments
to exercise the `Array.from(arg.args(), ...)` path with more than one element.
Extend the existing `funcCall` test block in
`attribute-spec-combinators.test.ts` with a case like `foo(1, "bar")`, then
assert the parsed callee name, that `args` has length 2, and that each
argument’s `raw` value preserves both the ordering and original source text.
🤖 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/2-authoring/psl-parser/test/attribute-spec-combinators.test.ts`:
- Around line 577-655: Add a `funcCall()` test that covers multiple arguments to
exercise the `Array.from(arg.args(), ...)` path with more than one element.
Extend the existing `funcCall` test block in
`attribute-spec-combinators.test.ts` with a case like `foo(1, "bar")`, then
assert the parsed callee name, that `args` has length 2, and that each
argument’s `raw` value preserves both the ordering and original source text.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: f7fb897e-7ebf-48cc-b5b5-4426419cc931

📥 Commits

Reviewing files that changed from the base of the PR and between 9175ebb and 7c42825.

⛔ Files ignored due to path filters (6)
  • projects/typed-attribute-parsers/slices/sql-default/dispatches/01-kit-scalar-funccall.md is excluded by !projects/**
  • projects/typed-attribute-parsers/slices/sql-default/dispatches/02-migrate-nonenum.md is excluded by !projects/**
  • projects/typed-attribute-parsers/slices/sql-default/dispatches/03-migrate-enum.md is excluded by !projects/**
  • projects/typed-attribute-parsers/slices/sql-default/dispatches/04-delete-legacy-funccall-parser.md is excluded by !projects/**
  • projects/typed-attribute-parsers/slices/sql-default/plan.md is excluded by !projects/**
  • projects/typed-attribute-parsers/slices/sql-default/spec.md is excluded by !projects/**
📒 Files selected for processing (12)
  • packages/1-framework/2-authoring/psl-parser/src/attribute-spec/combinators/bare-identifier.ts
  • packages/1-framework/2-authoring/psl-parser/src/attribute-spec/combinators/func-call.ts
  • packages/1-framework/2-authoring/psl-parser/src/attribute-spec/combinators/scalar-literal.ts
  • packages/1-framework/2-authoring/psl-parser/src/exports/index.ts
  • packages/1-framework/2-authoring/psl-parser/test/attribute-spec-combinators.test.ts
  • packages/2-sql/2-authoring/contract-psl/src/default-function-registry.ts
  • packages/2-sql/2-authoring/contract-psl/src/psl-column-resolution.ts
  • packages/2-sql/2-authoring/contract-psl/src/psl-field-resolution.ts
  • packages/2-sql/2-authoring/contract-psl/src/sql-attribute-specs.ts
  • packages/2-sql/2-authoring/contract-psl/test/default-function-registry.test.ts
  • packages/2-sql/2-authoring/contract-psl/test/interpreter.defaults.test.ts
  • packages/2-sql/2-authoring/contract-psl/test/interpreter.enum.test.ts
💤 Files with no reviewable changes (1)
  • packages/2-sql/2-authoring/contract-psl/src/default-function-registry.ts

@SevInf
SevInf force-pushed the tml-2956-sql-default branch 3 times, most recently from 57269ff to 6f8c80a Compare July 13, 2026 09:15
const [first, ...rest] = memberNames.map((name) => identifier(name));
// memberNames is non-empty for any real enum; guard defensively so typing stays total.
const arms: readonly [ArgType<string>, ...ArgType<string>[]] =
first === undefined ? [identifier('')] : [first, ...rest];

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wtf is identifier('')? That does not make any semantical sense.

SevInf added 19 commits July 14, 2026 09:41
Grow the attribute-spec kit with the two leaf combinators @default needs:

- scalarLiteral(): ArgType<string | number | boolean> — a String/Number/
  Boolean literal reduced to its decoded .value().
- funcCall(): ArgType<ParsedDefaultFunctionCall> — a FunctionCallAst parsed
  into the framework ParsedDefaultFunctionCall shape (name via the structural
  QualifiedName.identifier() getter, each argument captured as verbatim source
  text so the SQL default registry can re-parse it downstream). Registry-
  agnostic: no name validation, no SQL dependency.

The parsed-call output type is imported from @prisma-next/framework-components/
control (framework to framework, layering-clean). Unit-tested in isolation.

Signed-off-by: Serhii Tatarintsev <[email protected]>
… (enum + non-enum)

Signed-off-by: Serhii Tatarintsev <[email protected]>
 to the attribute-spec path

Part A: funcCall() now rejects a namespaced (or absent) callee. QualifiedNameAst.identifier() returns the segment after a dot, so foo.now() wrongly yielded the bare registry name now. Guard on dot()/colon() before reading the identifier, and add a combinator test for the namespaced-callee reject. Also reword the combinator comment to keep the framework domain family-blind.

Part B: add defaultSpec (oneOf(scalarLiteral, list(scalarLiteral), funcCall)) and rewrite lowerDefaultForField to locate the @default node via the field and interpret it through the spec, then runtime shape-switch on the value: array -> array/scalar-mismatch literal, object -> registry-lowered function default (applicability/codec checks preserved verbatim), primitive -> scalar literal / list-mismatch. The hand-rolled arity check is dropped in favour of the spec engine. Delete the now-dead string parsers (parseDefaultLiteralValue, parseListDefaultExpression, decodeLiteralElement, ListDefaultParse); retain the registry helpers.

Update AC5g to expect PSL_INVALID_ATTRIBUTE_SYNTAX (the spec-level reject), leaving the registry/optional-field PSL_INVALID_DEFAULT_FUNCTION_ARGUMENT tests untouched.

Signed-off-by: Serhii Tatarintsev <[email protected]>
…(operator standing order, not a repo rule)

Signed-off-by: Serhii Tatarintsev <[email protected]>
Part A: add a bareIdentifier() combinator to psl-parser (modeled on
entity-ref.ts), export it, and unit-test it (accepts a bare identifier;
rejects a string literal, number, and function call).

Part B: migrate the enum @default path. Add enumDefaultSpec using
bareIdentifier(), and rewrite lowerEnumDefaultForField to interpret via
interpretFieldAttribute and match the member against enumHandle.enumMembers,
deleting the inline isQuotedString/isFunctionCall regex checks and the
exactly-one-positional guard. Thread field/model/sourceFile from the call
site. Arg-shape errors (quoted string, function call, missing/extra arg) now
surface as PSL_INVALID_ATTRIBUTE_SYNTAX; a non-member identifier still emits
PSL_ENUM_UNKNOWN_DEFAULT_MEMBER.

Signed-off-by: Serhii Tatarintsev <[email protected]>
…rseDefaultFunctionCall)

Signed-off-by: Serhii Tatarintsev <[email protected]>
The funcCall() kit combinator replaced parseDefaultFunctionCall on the
production @default path, leaving the hand-written string parser dead in
production with only its own unit test as a caller.

Remove parseDefaultFunctionCall and its exclusive support chain
(splitTopLevelArgs, createSpanFromBase, resolveSpanPositionFromBase, the
DefaultFunctionArgument interface, and the now-unused PslSpan import) from
default-function-registry.ts, keeping formatSupportedFunctionList and
lowerDefaultFunctionWithRegistry.

Refactor the test: drop the parsing-behaviour tests (now covered by
funcCall in psl-parser) and rebuild the lowering-test inputs via a local
call() helper that constructs ParsedDefaultFunctionCall literals directly.

Signed-off-by: Serhii Tatarintsev <[email protected]>
… sql-default (D5-D7)

Signed-off-by: Serhii Tatarintsev <[email protected]>
…e) + num()

Make funcCall name-pinned (funcCall(name)) and add a general num() number
atom (any number literal; int() stays integer-only). Replace the static
defaultSpec with buildDefaultSpec({ isList, registry }) that composes the
value grammar per field: literals (str/num/bool), a list arm for list
fields only, and one funcCall(name) arm per registered mutation-default
function.

Rewire lowerDefaultForField to build the spec dynamically and drop the
two shape-mismatch branches (array-on-scalar PSL_INVALID_DEFAULT_VALUE and
scalar-on-list PSL_LIST_DEFAULT_NOT_ARRAY): shape now maps to field kind,
so both become PSL_INVALID_ATTRIBUTE_SYNTAX at the grammar. Likewise a
function name absent from the registry has no arm and fails as invalid
syntax. The registry keeps validating args for known-name calls.

The oneOf(...valueArms) spread is typed cleanly without a cast by
annotating valueArms as a non-empty readonly tuple of ArgType<DefaultArgValue>.

Signed-off-by: Serhii Tatarintsev <[email protected]>
…(member)…)

Replace the static enumDefaultSpec (bareIdentifier + post-validation) with buildEnumDefaultSpec(memberNames), which builds oneOf(...identifier(name)) from the enum members so member-validity is a grammar concern. Rewire lowerEnumDefaultForField to build the spec from enumHandle.enumMembers and drop the PSL_ENUM_UNKNOWN_DEFAULT_MEMBER branch (an unknown member now fails as PSL_INVALID_ATTRIBUTE_SYNTAX). Shift the @default(Critical) test accordingly.

Signed-off-by: Serhii Tatarintsev <[email protected]>
…d combinators + vocab fix)

Signed-off-by: Serhii Tatarintsev <[email protected]>
…binators

D5/D6 made the @default specs dynamic, leaving scalarLiteral() and
bareIdentifier() without callers. Delete both combinators, their exports,
and their obsolete unit-test describe blocks.

Reword num.ts doc comment to drop the framework-vocabulary-flagged word
"constraint" (906 -> 905, lint now green) and reword stale bareIdentifier()
comments in interpreter.enum.test.ts to describe the current
oneOf(identifier(member)) shape.

Signed-off-by: Serhii Tatarintsev <[email protected]>
SevInf added 10 commits July 14, 2026 09:41
…oundation

Framework-only foundation for ADR 231 typed funcCall(sig):

- Extract the positional/named argument-binding out of interpretAttribute
  into an exported interpretArgs() helper. interpretAttribute now builds the
  attribute span, delegates binding to interpretArgs, and applies refine on
  the returned record via the same justified blindCast. Behaviour identical.
- Give funcCall an optional signature funcCall(name, sig?). With a sig, the
  args are parsed via interpretArgs and bound into { fn, ...args }; without a
  sig, todays raw ParsedDefaultFunctionCall capture is unchanged. Two
  overloads keep the two return shapes distinct without a cast.
- Extend num() to a pinnable num(value) and int() to a bounded int({min,max}).

No changes to packages/2-sql or packages/3-targets.

Signed-off-by: Serhii Tatarintsev <[email protected]>
Each default function declares a FuncCallSig argument signature; buildDefaultSpec builds funcCall(name, signature); each registry lower consumes the typed { fn, span, args } call instead of re-parsing raw argument source text. Arg shape/arity/range errors become grammar failures (PSL_INVALID_ATTRIBUTE_SYNTAX, Option A); the only surviving semantic arg check is dbgenerated empty -> PSL_INVALID_DEFAULT_FUNCTION_ARGUMENT.

framework-components: add TypedDefaultFunctionCall; ControlMutationDefaultEntry gains an opaque signature?: unknown and a typed lower. psl-parser: typedFuncCall returns nested { fn, span, args }. sql-contract-psl: buildDefaultSpec maps registry.entries() to funcCall(name, blindCast<FuncCallSig>(entry.signature)); lowerDefaultFunctionWithRegistry reads call.fn; stub registry + affected tests migrated. adapter-postgres/adapter-sqlite: signatures added, lower bodies read typed args cast-free, imperative arg parsers removed, and psl-parser promoted to a runtime dependency so the combinators are not bundled (fixes cross-copy instanceof during arg parsing). test/integration: migrate the slugid parity pack to the signature API and update the two invalid-@default diagnostics fixtures.
Signed-off-by: Serhii Tatarintsev <[email protected]>
After D9 every SQL @default funcCall is built with a signature, so the
no-signature funcCall(name) path (rawFuncCall) has no production caller.
Collapse funcCall to a single funcCall(name, sig): ArgType<TypedFuncCall>,
migrate/prune its psl-parser tests, and delete the now-vestigial
ParsedDefaultFunctionCall, DefaultFunctionArgument,
DefaultFunctionLoweringHandler, DefaultFunctionRegistryEntry and
DefaultFunctionRegistry types plus their re-exports. Align the sqlite
adapter to import LoweredDefaultResult / DefaultFunctionLoweringContext
directly from framework-components/control. Type/test-level only; no
runtime behaviour change.

Signed-off-by: Serhii Tatarintsev <[email protected]>
…ile-time guarantee

buildEnumDefaultSpec no longer fabricates an identifier('') arm for a
memberless enum. It now takes a non-empty tuple, so non-emptiness is
enforced by the type. The single caller handles the degenerate
memberless-enum case honestly by skipping lowering (a memberless enum is
already a contract error at its declaration and never produces a handle).

Signed-off-by: Serhii Tatarintsev <[email protected]>
@SevInf
SevInf force-pushed the tml-2956-sql-default branch from a888df3 to 2af855d Compare July 14, 2026 09:45
@SevInf
SevInf merged commit a7344a3 into main Jul 14, 2026
20 checks passed
@SevInf
SevInf deleted the tml-2956-sql-default branch July 14, 2026 10:55
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