Skip to content

v8.0.0-rc.8-dev.3

@StevenMcClankerton StevenMcClankerton tagged this 27 Aug 14:08
## Linked issue

Refs [TML-2956](https://linear.app/prisma-company/issue/TML-2956) —
Language Tools Support Prisma Next PSL.

Completes the Mongo-family migration onto the declarative attribute-spec
kit introduced by the preceding SQL slices.

## At a glance

```prisma
@@textIndex([name, description], weights: { name: 10, description: 1 })
```

Mongo text-index weights now use a native typed PSL record; wildcard
projections similarly use native string lists such as `include:
["metadata", "nested.path"]`.

## Decision

This PR makes Mongo PSL attribute argument parsing spec-driven:

1. Mongo model- and field-level attributes are interpreted through typed
`AttributeSpec` definitions and shared wrappers around
`interpretAttribute`.
2. Index specs are built from the current model so field references,
sorted field calls, and wildcard calls compose from `fieldRef`,
`funcCall`, `list`, and `oneOf`.
3. Mongo index values use native combinators: projections are
`list(str())`, text weights are `record(int({ min: 1, max: 99_999 }))`,
and quoted JSON remains only for the `filter` exception.
4. The legacy attribute string parsers and post-parse normalization they
replaced are removed.
5. Consumer schemas receive executable upgrade instructions for the two
syntax migrations.

## Reviewer notes

- `include` and `exclude` intentionally accept strings rather than model
field references because Mongo wildcard projections may contain
arbitrary dotted paths and dynamically shaped document fields.
- Missing model fields are rejected by the typed grammar as
`PSL_INVALID_ATTRIBUTE_SYNTAX`; fields that exist but cannot be indexed,
such as relation fields, retain semantic index diagnostics.
- `@@textIndex` exposes only its supported arguments. Index-only options
that were previously ignored are now rejected as invalid syntax.
- `filter` remains quoted JSON. Native records are introduced
specifically for `weights`, where the key/value shape is known and can
support future language tooling.

## How it fits together

1. `mongo-attribute-specs.ts` provides model- and field-level
interpretation contexts and wrappers that convert parser failures into
contract diagnostics.
2. Simple attributes such as `@map`, `@@map`, `@relation`,
`@@discriminator`, and `@@base` declare their positional and named
arguments directly.
3. Index field elements are assembled per model from `fieldRef('self')`,
typed sorted-field `funcCall` arms, and the wildcard function call.
4. `@@index`, `@@unique`, and `@@textIndex` compose those field elements
with typed options for collation, projections, filters, and weights.
5. The interpreter consumes the typed output and retains only
cross-field and cross-model semantic validation.

## Behavior changes & evidence

- **Mongo attributes now reject malformed arguments through one typed
grammar.** The specs and wrappers live in
[`mongo-attribute-specs.ts`](packages/2-mongo-family/2-authoring/contract-psl/src/mongo-attribute-specs.ts),
with interpreter behavior covered by
[`interpreter.test.ts`](packages/2-mongo-family/2-authoring/contract-psl/test/interpreter.test.ts)
and
[`interpreter.polymorphism.test.ts`](packages/2-mongo-family/2-authoring/contract-psl/test/interpreter.polymorphism.test.ts).
- **Index projections use native PSL lists.** `include` and `exclude`
are declared as `list(str())`; integration coverage is in
[`migration-psl-authoring.test.ts`](test/integration/test/mongo/migration-psl-authoring.test.ts).
- **Text-index weights use a bounded native record.** Keys are
preserved, including prototype-named keys, and values must be integers
from 1 through 99,999. Combinator behavior is covered by
[`attribute-spec-combinators.test.ts`](packages/1-framework/2-authoring/psl-parser/test/attribute-spec-combinators.test.ts),
while the retail example and migration snapshots exercise contract and
migration regeneration.
- **Pinned combinator literals preserve exact output types.**
[`str.ts`](packages/1-framework/2-authoring/psl-parser/src/attribute-spec/combinators/str.ts)
and
[`num.ts`](packages/1-framework/2-authoring/psl-parser/src/attribute-spec/combinators/num.ts)
support exact alternatives used by index type and collation specs.

## Compatibility / migration / risk

This intentionally changes two Prisma schema syntaxes:

```prisma
// Before
@@index([wildcard()], include: "[metadata, nested.path]")
@@textIndex([title, body], weights: "{\"title\": 10, \"body\": 5}")

// After
@@index([wildcard()], include: ["metadata", "nested.path"])
@@textIndex([title, body], weights: { title: 10, body: 5 })
```

The migration is recorded in
[`skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.8-to-8.0.0-rc.9/instructions.md`](skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.8-to-8.0.0-rc.9/instructions.md).

## Testing performed

- `pnpm --filter @prisma-next/mongo-contract-psl build && pnpm --filter
@prisma-next/mongo-contract-psl typecheck && pnpm --filter
@prisma-next/mongo-contract-psl test` — 155 tests passed.
- `pnpm --filter @prisma-next/psl-parser build && pnpm --filter
@prisma-next/psl-parser typecheck && pnpm --filter
@prisma-next/psl-parser test` — 635 tests passed.
- `pnpm test:integration` — 2,061 tests passed with 53 expected failures
and no type errors.
- `pnpm --filter retail-store test` — 55 tests passed.
- `pnpm build` — 85 tasks passed.
- `pnpm fixtures:check` — passed after updating the retail migration
lineage to native weight records.
- `pnpm check:upgrade-coverage` — passed.
- `git diff --check` — passed.

## Skill update

Added executable app upgrade instructions under
[`skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.8-to-8.0.0-rc.9/`](skills/prisma-8/upgrading/app/upgrades/8.0.0-rc.8-to-8.0.0-rc.9/)
for native Mongo projection lists and text-index weight records.

## Alternatives considered

- **Keep encoded projection and weight strings.** Rejected because their
structure would remain opaque to typed parsing and future language
tooling, while requiring redundant post-validation.
- **Use model field references for wildcard projections.** Rejected
because Mongo permits arbitrary dotted projection paths that need not
correspond to declared model fields.
- **Add dedicated sorted-field and wildcard combinators.** Rejected
because the existing `oneOf`, `fieldRef`, and typed `funcCall`
combinators express the grammar from the model context without expanding
the kit.

## Checklist

- [x] All commits are signed off (`git commit -s`) per the DCO.
- [x] I read `CONTRIBUTING.md` and the change is scoped to one logical
concern.
- [x] Tests are updated.
- [x] The PR title is in `TML-NNNN: <sentence-case title>` form.
- [x] The Skill update section is filled in.

---------

Signed-off-by: Serhii Tatarintsev <tatarintsev@prisma.io>
Signed-off-by: Steven McClankerton <tatarintsev@prisma.io>
Co-authored-by: Serhii Tatarintsev <tatarintsev@prisma.io>
Assets 2
Loading