@prisma-next/sql-runtime 0.5.0-dev.4 → 0.5.0-dev.41
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 +29 -21
- package/dist/exports-CrHMfIKo.mjs +1564 -0
- package/dist/exports-CrHMfIKo.mjs.map +1 -0
- package/dist/{index-yb51L_1h.d.mts → index-_dXSGeho.d.mts} +78 -25
- package/dist/index-_dXSGeho.d.mts.map +1 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +2 -2
- package/dist/test/utils.d.mts +6 -5
- package/dist/test/utils.d.mts.map +1 -1
- package/dist/test/utils.mjs +11 -5
- package/dist/test/utils.mjs.map +1 -1
- package/package.json +10 -12
- package/src/codecs/decoding.ts +294 -173
- package/src/codecs/encoding.ts +162 -37
- package/src/codecs/validation.ts +22 -3
- package/src/exports/index.ts +11 -7
- package/src/fingerprint.ts +22 -0
- package/src/guardrails/raw.ts +165 -0
- package/src/lower-sql-plan.ts +3 -3
- package/src/marker.ts +75 -0
- package/src/middleware/before-compile-chain.ts +1 -0
- package/src/middleware/budgets.ts +26 -96
- package/src/middleware/lints.ts +3 -3
- package/src/middleware/sql-middleware.ts +6 -5
- package/src/runtime-spi.ts +44 -0
- package/src/sql-context.ts +332 -78
- package/src/sql-family-adapter.ts +3 -2
- package/src/sql-marker.ts +62 -47
- package/src/sql-runtime.ts +332 -113
- package/dist/exports-BQZSVXXt.mjs +0 -981
- package/dist/exports-BQZSVXXt.mjs.map +0 -1
- package/dist/index-yb51L_1h.d.mts.map +0 -1
- package/test/async-iterable-result.test.ts +0 -141
- package/test/before-compile-chain.test.ts +0 -223
- package/test/budgets.test.ts +0 -431
- package/test/context.types.test-d.ts +0 -68
- package/test/execution-stack.test.ts +0 -161
- package/test/json-schema-validation.test.ts +0 -571
- package/test/lints.test.ts +0 -160
- package/test/mutation-default-generators.test.ts +0 -254
- package/test/parameterized-types.test.ts +0 -529
- package/test/sql-context.test.ts +0 -384
- package/test/sql-family-adapter.test.ts +0 -103
- package/test/sql-runtime.test.ts +0 -792
- package/test/utils.ts +0 -297
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ SQL runtime implementation for Prisma Next.
|
|
|
10
10
|
|
|
11
11
|
## Overview
|
|
12
12
|
|
|
13
|
-
The SQL runtime package implements the SQL family runtime by
|
|
13
|
+
The SQL runtime package implements the SQL family runtime by extending the abstract `RuntimeCore` base class from `@prisma-next/framework-components/runtime` with SQL-specific adapters, drivers, codecs, marker verification, telemetry fingerprinting, and a `beforeCompile` middleware chain. It provides the public runtime API for SQL-based databases, including descriptor-based static context derivation via `SqlStaticContributions` and execution-plane composition via `ExecutionStack`.
|
|
14
14
|
|
|
15
15
|
## Purpose
|
|
16
16
|
|
|
@@ -26,13 +26,16 @@ Execute SQL query Plans with deterministic verification, guardrails, and feedbac
|
|
|
26
26
|
- **SQL Marker Management**: Provide SQL statements for reading/writing contract markers
|
|
27
27
|
- **Codec Encoding/Decoding**: Encode parameters and decode rows using SQL codec registries
|
|
28
28
|
- **Codec Validation**: Validate that codec registries contain all required codecs
|
|
29
|
-
- **SQL Family Adapter**: Implement `RuntimeFamilyAdapter` for SQL contracts
|
|
30
|
-
- **
|
|
29
|
+
- **SQL Family Adapter**: Implement `RuntimeFamilyAdapter` for SQL contracts (defined in `runtime-spi.ts`)
|
|
30
|
+
- **Marker Verification**: Parse contract-marker rows from the database (`marker.ts`) and gate execution on hash equality
|
|
31
|
+
- **Telemetry Fingerprinting**: Compute SQL fingerprints for telemetry events (`fingerprint.ts`)
|
|
32
|
+
- **Raw-SQL Guardrails**: Heuristic safety checks for raw SQL plans (`guardrails/raw.ts`)
|
|
33
|
+
- **`beforeCompile` Chain**: AST-rewrite middleware chain run pre-lowering (`middleware/before-compile-chain.ts`)
|
|
34
|
+
- **SQL Runtime**: `SqlRuntime` extends `RuntimeCore<SqlQueryPlan, SqlExecutionPlan, SqlMiddleware>` and overrides `lower`, `runDriver`, `runBeforeCompile`, and `close` with SQL-specific behaviour
|
|
31
35
|
|
|
32
36
|
## Dependencies
|
|
33
37
|
|
|
34
|
-
- `@prisma-next/framework-components` - Runtime component descriptor types (
|
|
35
|
-
- `@prisma-next/runtime-executor` - Target-neutral execution engine
|
|
38
|
+
- `@prisma-next/framework-components` - Runtime component descriptor types (`./execution`) and the abstract `RuntimeCore` base class plus `runWithMiddleware` helper (`./runtime`)
|
|
36
39
|
- `@prisma-next/sql-contract` - SQL contract types (via `@prisma-next/sql-contract/types`)
|
|
37
40
|
- `@prisma-next/operations` - Operation registry
|
|
38
41
|
|
|
@@ -44,7 +47,12 @@ import postgresDriver from '@prisma-next/driver-postgres/runtime';
|
|
|
44
47
|
import pgvector from '@prisma-next/extension-pgvector/runtime';
|
|
45
48
|
import postgresTarget from '@prisma-next/target-postgres/runtime';
|
|
46
49
|
import { instantiateExecutionStack } from '@prisma-next/framework-components/execution';
|
|
47
|
-
import {
|
|
50
|
+
import {
|
|
51
|
+
budgets,
|
|
52
|
+
createExecutionContext,
|
|
53
|
+
createRuntime,
|
|
54
|
+
createSqlExecutionStack,
|
|
55
|
+
} from '@prisma-next/sql-runtime';
|
|
48
56
|
|
|
49
57
|
const contract = validateContract<Contract>(contractJson);
|
|
50
58
|
const stack = createSqlExecutionStack({
|
|
@@ -65,7 +73,7 @@ const runtime = createRuntime({
|
|
|
65
73
|
context,
|
|
66
74
|
driver,
|
|
67
75
|
verify: { mode: 'onFirstUse', requireMarker: false },
|
|
68
|
-
|
|
76
|
+
middleware: [budgets()],
|
|
69
77
|
});
|
|
70
78
|
|
|
71
79
|
for await (const row of runtime.execute(plan)) {
|
|
@@ -116,44 +124,44 @@ for await (const row of runtime.execute(plan)) {
|
|
|
116
124
|
|
|
117
125
|
- `lowerSqlPlan` - SQL plan lowering via adapter
|
|
118
126
|
|
|
119
|
-
###
|
|
127
|
+
### Middleware
|
|
120
128
|
|
|
121
|
-
- `budgets` - **AST-first budget
|
|
122
|
-
- `lints` - **AST-first lint
|
|
123
|
-
- `
|
|
124
|
-
- `
|
|
125
|
-
- `AfterExecuteResult` -
|
|
126
|
-
- `Log` - Log entry type
|
|
129
|
+
- `budgets` - **AST-first budget middleware** (canonical in SQL domain), inspects `plan.ast` when present for row estimation
|
|
130
|
+
- `lints` - **AST-first lint middleware** (canonical in SQL domain), inspects `plan.ast` when present
|
|
131
|
+
- `SqlMiddleware`, `SqlMiddlewareContext` - SQL-family middleware interface and per-execution context
|
|
132
|
+
- `BudgetsOptions`, `LintsOptions` - Middleware option types
|
|
133
|
+
- `AfterExecuteResult` - Middleware `afterExecute` hook result type (re-exported from `@prisma-next/framework-components/runtime`)
|
|
134
|
+
- `Log` - Log entry type (re-exported from `@prisma-next/framework-components/runtime`)
|
|
127
135
|
|
|
128
|
-
#### Lints
|
|
136
|
+
#### Lints middleware (SQL domain)
|
|
129
137
|
|
|
130
|
-
The `lints`
|
|
138
|
+
The `lints` middleware operates on `plan.ast` when it is a SQL `QueryAst`:
|
|
131
139
|
|
|
132
140
|
- **DELETE without WHERE** — blocks execution (configurable severity)
|
|
133
141
|
- **UPDATE without WHERE** — blocks execution (configurable severity)
|
|
134
142
|
- **Unbounded SELECT** — warns/errors when `limit` is missing
|
|
135
143
|
- **SELECT \* intent** — warns/errors when `selectAllIntent` is present
|
|
136
144
|
|
|
137
|
-
When `plan.ast` is missing, the
|
|
145
|
+
When `plan.ast` is missing, the middleware falls back to raw heuristic guardrails (`fallbackWhenAstMissing: 'raw'`) or skips linting (`fallbackWhenAstMissing: 'skip'`). Default is `'raw'`.
|
|
138
146
|
|
|
139
147
|
```typescript
|
|
140
148
|
import { createRuntime, lints } from '@prisma-next/sql-runtime';
|
|
141
149
|
|
|
142
150
|
const runtime = createRuntime({
|
|
143
151
|
// ...
|
|
144
|
-
|
|
152
|
+
middleware: [lints({ severities: { noLimit: 'error' } })],
|
|
145
153
|
});
|
|
146
154
|
```
|
|
147
155
|
|
|
148
156
|
## Architecture
|
|
149
157
|
|
|
150
|
-
The SQL runtime
|
|
158
|
+
The SQL runtime extends the abstract `RuntimeCore` base class from `@prisma-next/framework-components/runtime` with SQL-specific implementations. Descriptors implement `SqlStaticContributions` so `ExecutionContext` can be derived from the descriptors-only stack without instantiation.
|
|
151
159
|
|
|
152
160
|
1. **ExecutionStack**: Descriptors-only stack (from `@prisma-next/framework-components/execution`)
|
|
153
161
|
2. **SqlStaticContributions**: Codecs, operation signatures, parameterized codecs, and mutation default generators contributed by each descriptor
|
|
154
162
|
3. **ExecutionContext**: Built from contract + stack descriptors (no instantiation)
|
|
155
163
|
4. **ExecutionStackInstance**: Instantiated components used at runtime for execution
|
|
156
|
-
5. **SqlRuntime**:
|
|
164
|
+
5. **SqlRuntime**: `class SqlRuntimeImpl extends RuntimeCore<SqlQueryPlan, SqlExecutionPlan, SqlMiddleware>` — overrides `lower` (with codec param-encoding), `runDriver`, `runBeforeCompile` (delegates to the SQL `beforeCompile` chain), and `close`. The execution path also wraps the `runWithMiddleware` helper from `framework-components/runtime` with codec row-decoding, marker verification (via the `RuntimeFamilyAdapter` defined in `runtime-spi.ts`), and telemetry fingerprinting (via `computeSqlFingerprint` from `fingerprint.ts`).
|
|
157
165
|
6. **SqlMarker**: Provides SQL statements for marker management
|
|
158
166
|
|
|
159
167
|
```mermaid
|
|
@@ -164,7 +172,7 @@ flowchart LR
|
|
|
164
172
|
Stack --> AdapterDesc[Adapter Descriptor]
|
|
165
173
|
Stack --> Packs[Extension Packs]
|
|
166
174
|
Context --> Runtime[SqlRuntime]
|
|
167
|
-
Runtime
|
|
175
|
+
Runtime -.extends.-> Core[RuntimeCore]
|
|
168
176
|
DriverDesc --> DriverInst[Driver Instance]
|
|
169
177
|
AdapterDesc --> AdapterInst[Adapter Instance]
|
|
170
178
|
Runtime --> DriverInst
|