@prisma-next/psl-parser 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +75 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.mjs +3 -0
- package/dist/parser-BP2RP4rk.mjs +681 -0
- package/dist/parser-BP2RP4rk.mjs.map +1 -0
- package/dist/parser-CUqO9VeG.d.mts +7 -0
- package/dist/parser-CUqO9VeG.d.mts.map +1 -0
- package/dist/parser.d.mts +2 -0
- package/dist/parser.mjs +3 -0
- package/dist/types-QqDFOzNR.d.mts +119 -0
- package/dist/types-QqDFOzNR.d.mts.map +1 -0
- package/dist/types.d.mts +2 -0
- package/dist/types.mjs +1 -0
- package/package.json +45 -0
- package/src/exports/index.ts +26 -0
- package/src/exports/parser.ts +1 -0
- package/src/exports/types.ts +28 -0
- package/src/parser.ts +927 -0
- package/src/types.ts +151 -0
package/README.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# @prisma-next/psl-parser
|
|
2
|
+
|
|
3
|
+
Reusable PSL parser for Prisma Next.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
`@prisma-next/psl-parser` parses Prisma Schema Language (PSL) source into a deterministic AST with source spans and stable machine-readable diagnostics. It is intentionally parser-only: normalization to contract IR and emit integration happen in downstream milestones/packages.
|
|
8
|
+
|
|
9
|
+
In the provider-based authoring model, PSL providers call this parser and then return `Result<ContractIR, ContractSourceDiagnostics>` to the framework emit pipeline.
|
|
10
|
+
|
|
11
|
+
## Responsibilities
|
|
12
|
+
|
|
13
|
+
- Parse PSL source text (`schema` + `sourceId`) with deterministic ordering.
|
|
14
|
+
- Return AST nodes with source spans for models, fields, enums, and `types { ... }`.
|
|
15
|
+
- Preserve raw PSL relation action tokens (for example `Cascade`) without semantic normalization.
|
|
16
|
+
- Return stable diagnostics (`code`, `message`, `span`, `sourceId`) for invalid and unsupported constructs.
|
|
17
|
+
- Enforce strict error behavior for unsupported syntax (no warning or best-effort mode).
|
|
18
|
+
- Parse attributes generically (namespaced or not), including optional argument lists; semantics live downstream.
|
|
19
|
+
- Emit attribute nodes with explicit target (`field` / `model` / `namedType`), attribute name, and parsed argument list with spans.
|
|
20
|
+
|
|
21
|
+
## Attributes (generic parsing boundary)
|
|
22
|
+
|
|
23
|
+
`@prisma-next/psl-parser` parses attributes **generically**:
|
|
24
|
+
|
|
25
|
+
- Attributes may be **non-namespaced** (for example `@id`) or **namespaced** (for example `@pgvector.column`).
|
|
26
|
+
- Attributes may include an **optional argument list**.
|
|
27
|
+
- Arguments are parsed into positional/named entries with preserved raw values and source spans.
|
|
28
|
+
- The parser owns **syntax + structure + spans**, not semantics.
|
|
29
|
+
|
|
30
|
+
Interpretation/validation (for example `@prisma-next/sql-contract-psl`) is responsible for:
|
|
31
|
+
|
|
32
|
+
- mapping attributes to existing contract authoring shapes,
|
|
33
|
+
- enforcing strictness (unknown/unsupported attributes are errors),
|
|
34
|
+
- enforcing pack composition (using `@<ns>.*` without composing the pack fails), and
|
|
35
|
+
- ensuring parity with the TS authoring surface.
|
|
36
|
+
|
|
37
|
+
## Public API
|
|
38
|
+
|
|
39
|
+
- `parsePslDocument(input)` in `src/parser.ts`
|
|
40
|
+
- Exported AST/diagnostic/span types in `src/types.ts`
|
|
41
|
+
- Subpath exports:
|
|
42
|
+
- `@prisma-next/psl-parser/parser`
|
|
43
|
+
- `@prisma-next/psl-parser/types`
|
|
44
|
+
|
|
45
|
+
## Dependencies
|
|
46
|
+
|
|
47
|
+
- **Depends on**
|
|
48
|
+
- No cross-domain runtime dependencies.
|
|
49
|
+
- **Used by**
|
|
50
|
+
- PSL normalization/emission tooling (next milestone)
|
|
51
|
+
- Potential language tooling and external parsers that need spans + diagnostics
|
|
52
|
+
|
|
53
|
+
## Architecture
|
|
54
|
+
|
|
55
|
+
```mermaid
|
|
56
|
+
flowchart LR
|
|
57
|
+
PSL[PSL source text] --> Parser[psl-parser]
|
|
58
|
+
Parser --> AST[PSL AST with spans]
|
|
59
|
+
Parser --> Diagnostics[Structured diagnostics]
|
|
60
|
+
AST --> Normalizer[PSL -> contract IR normalizer]
|
|
61
|
+
Diagnostics --> CLI[CLI/editor renderers]
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Package Boundaries
|
|
65
|
+
|
|
66
|
+
- This package does not perform file I/O.
|
|
67
|
+
- This package does not normalize to contract IR.
|
|
68
|
+
- This package does not emit `contract.json` or `contract.d.ts`.
|
|
69
|
+
|
|
70
|
+
## Related Docs
|
|
71
|
+
|
|
72
|
+
- `docs/Architecture Overview.md`
|
|
73
|
+
- `docs/architecture docs/subsystems/2. Contract Emitter & Types.md`
|
|
74
|
+
- `docs/architecture docs/adrs/ADR 163 - Provider-invoked source interpretation packages.md`
|
|
75
|
+
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { S as PslPosition, T as PslTypesBlock, _ as PslFieldAttribute, a as PslAttributeNamedArgument, b as PslModelAttribute, c as PslDefaultFunctionValue, d as PslDiagnostic, f as PslDiagnosticCode, g as PslField, h as PslEnumValue, i as PslAttributeArgument, l as PslDefaultLiteralValue, m as PslEnum, n as ParsePslDocumentResult, o as PslAttributePositionalArgument, p as PslDocumentAst, r as PslAttribute, s as PslAttributeTarget, t as ParsePslDocumentInput, u as PslDefaultValue, w as PslSpan, x as PslNamedTypeDeclaration, y as PslModel } from "./types-QqDFOzNR.mjs";
|
|
2
|
+
import { t as parsePslDocument } from "./parser-CUqO9VeG.mjs";
|
|
3
|
+
export { type ParsePslDocumentInput, type ParsePslDocumentResult, type PslAttribute, type PslAttributeArgument, type PslAttributeNamedArgument, type PslAttributePositionalArgument, type PslAttributeTarget, type PslDefaultFunctionValue, type PslDefaultLiteralValue, type PslDefaultValue, type PslDiagnostic, type PslDiagnosticCode, type PslDocumentAst, type PslEnum, type PslEnumValue, type PslField, type PslFieldAttribute, type PslModel, type PslModelAttribute, type PslNamedTypeDeclaration, type PslPosition, type PslSpan, type PslTypesBlock, parsePslDocument };
|
package/dist/index.mjs
ADDED