prisma-generator-express 1.60.0 → 1.61.0

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 CHANGED
@@ -14,7 +14,7 @@ Running `npx prisma generate` produces:
14
14
  - Per-route and per-endpoint pagination config, including optional materialized-view count sources
15
15
  - Router generator with middleware support (before/after hooks per operation)
16
16
  - POST read endpoints for all read operations (for complex queries exceeding URL length limits)
17
- - Express-only progressive read streaming over Server-Sent Events (SSE), using manual stages or auto-include splitting for supported relation reads, including deep `findMany` / `findManyPaginated` auto-include paths
17
+ - Express-only progressive read streaming over Server-Sent Events (SSE), using manual stages or auto-include splitting for supported relation reads, including unguarded deep `findMany` / `findManyPaginated` auto-include paths and guarded single-record auto-include paths
18
18
  - Express-only standalone materialized view router for read-only access to registered PostgreSQL materialized views
19
19
  - OpenAPI 3.1 spec (JSON and YAML endpoints registered automatically per router)
20
20
  - Documentation helpers for contract view and Scalar UI (require manual mounting)
@@ -80,7 +80,7 @@ Some operations require newer versions:
80
80
 
81
81
  The Hono target v1 is tested on Node.js runtimes only. See [Cloudflare Workers and edge runtimes](#cloudflare-workers-and-edge-runtimes).
82
82
 
83
- Progressive Endpoint Composition over Server-Sent Events is currently supported by the Express target only. Express supports both manual staged streaming and auto-include streaming for supported relation reads, including single-record reads and deep `findMany` / `findManyPaginated` reads within the configured planner limits. Fastify and Hono continue to support normal JSON read and write routes.
83
+ Progressive Endpoint Composition over Server-Sent Events is currently supported by the Express target only. Express supports both manual staged streaming and auto-include streaming for supported relation reads. Unguarded auto-include supports single-record reads and deep `findMany` / `findManyPaginated` reads within the configured planner limits. Guarded auto-include supports selected single-record read shapes while keeping every root and relation-stage query inside prisma-guard. Fastify and Hono continue to support normal JSON read and write routes.
84
84
 
85
85
  ### Database provider support
86
86
 
@@ -589,6 +589,8 @@ The downstream handler reads these values (`res.locals.guardShape`, `request.gua
589
589
 
590
590
  When `shape` is absent, the handler calls Prisma directly with no guard enforcement.
591
591
 
592
+ For Express auto-include SSE on supported single-record reads, the router can also resolve the guard shape before planning the stream. It still executes the root query and every relation-stage query through prisma-guard. See [Guarded auto-include mode](#guarded-auto-include-mode).
593
+
592
594
  Generated route config types treat `shape` as a named shape map. Use `default` for the normal single-shape case, and add other keys only when you need caller-based variants. The runtime still passes the map to `prisma-guard`; the `default` variant is selected when no caller is provided or no variant matches.
593
595
 
594
596
  ### Default shape per operation
@@ -1670,7 +1672,7 @@ Manual progressive SSE can be configured on Express GET read operations only:
1670
1672
  - `aggregate`
1671
1673
  - `groupBy`
1672
1674
 
1673
- Auto-include progressive SSE supports these Express GET read operations:
1675
+ Auto-include progressive SSE supports these Express GET read operations when no guard shape is attached:
1674
1676
 
1675
1677
  - `findUnique`
1676
1678
  - `findUniqueOrThrow`
@@ -1679,7 +1681,16 @@ Auto-include progressive SSE supports these Express GET read operations:
1679
1681
  - `findMany`
1680
1682
  - `findManyPaginated`
1681
1683
 
1682
- `findMany` and `findManyPaginated` support deep relation loading by flattening parent rows at each relation path, with fallback cases listed in [Auto-include behavior and limits](#auto-include-behavior-and-limits).
1684
+ Unguarded `findMany` and `findManyPaginated` support deep relation loading by flattening parent rows at each relation path, with fallback cases listed in [Auto-include behavior and limits](#auto-include-behavior-and-limits).
1685
+
1686
+ When a prisma-guard shape is attached, auto-include supports these single-record read operations:
1687
+
1688
+ - `findUnique`
1689
+ - `findUniqueOrThrow`
1690
+ - `findFirst`
1691
+ - `findFirstOrThrow`
1692
+
1693
+ Guarded `findMany` and `findManyPaginated` continue to use the configured fallback behavior. Normal guarded JSON reads are not affected.
1683
1694
 
1684
1695
  If auto-include is configured on an unsupported operation, the router either falls back to single-result SSE or sends an SSE error depending on `fallback`.
1685
1696
 
@@ -2143,13 +2154,109 @@ Example deep event sequence:
2143
2154
  ```
2144
2155
 
2145
2156
 
2157
+
2158
+ ### Guarded auto-include mode
2159
+
2160
+ Auto-include also works with prisma-guard on supported single-record Express reads.
2161
+
2162
+ When a route operation has both `progressive: { mode: 'autoInclude' }` and a guard `shape`, the router resolves the shape through prisma-guard before planning the stream. The request should not send `select`, `include`, or `omit`; the guard shape's default read projection is used as the response contract.
2163
+
2164
+ ```ts
2165
+ import { force } from 'prisma-guard'
2166
+
2167
+ const userConfig = {
2168
+ guard: {
2169
+ variantHeader: 'x-api-variant',
2170
+ },
2171
+
2172
+ findFirst: {
2173
+ shape: {
2174
+ me: (ctx) => ({
2175
+ where: {
2176
+ id: { equals: force(ctx.userId) },
2177
+ },
2178
+ select: {
2179
+ id: true,
2180
+ email: true,
2181
+ profile: {
2182
+ select: {
2183
+ id: true,
2184
+ displayName: true,
2185
+ },
2186
+ },
2187
+ companies: {
2188
+ where: {
2189
+ company: {
2190
+ is: {
2191
+ deletedAt: { equals: null },
2192
+ },
2193
+ },
2194
+ },
2195
+ select: {
2196
+ company: {
2197
+ select: {
2198
+ id: true,
2199
+ name: true,
2200
+ },
2201
+ },
2202
+ role: {
2203
+ select: {
2204
+ role: true,
2205
+ },
2206
+ },
2207
+ },
2208
+ },
2209
+ },
2210
+ }),
2211
+ },
2212
+ progressive: {
2213
+ me: {
2214
+ enabled: true,
2215
+ mode: 'autoInclude',
2216
+ fallback: 'error',
2217
+ },
2218
+ },
2219
+ },
2220
+ }
2221
+
2222
+ app.use('/', UserRouter(userConfig))
2223
+ ```
2224
+
2225
+ Client request:
2226
+
2227
+ ```http
2228
+ GET /user/first
2229
+ Accept: text/event-stream
2230
+ x-api-variant: me
2231
+ ```
2232
+
2233
+ The guarded auto-include planner resolves the matched shape, applies the shape's default projection, strips direct relation branches from the root query, and loads those direct relations as follow-up guarded stage queries. The root query and every stage query execute through `prisma.model.guard(slicedShape, caller).method(args)`. Relation stages are never executed as raw Prisma delegate calls.
2234
+
2235
+ Direct relation stages stream as normal `field` events:
2236
+
2237
+ ```json
2238
+ { "type": "field", "key": "id", "value": "user-id" }
2239
+ ```
2240
+
2241
+ ```json
2242
+ { "type": "field", "key": "profile", "value": { "id": "profile-id", "displayName": "Alice" } }
2243
+ ```
2244
+
2245
+ ```json
2246
+ { "type": "field", "key": "companies", "value": [{ "company": { "id": "company-id", "name": "Acme" }, "role": { "role": "admin" } }] }
2247
+ ```
2248
+
2249
+ The final `result` event contains the assembled object.
2250
+
2251
+ For guarded auto-include, `fallback: 'error'` is recommended during development so unsupported shapes are visible immediately. In production, `fallback: 'singleResult'` can be used to return one final SSE result through the normal guarded handler when the planner cannot split the shape.
2252
+
2146
2253
  ### Auto-include behavior and limits
2147
2254
 
2148
2255
  Auto-include is designed for supported Prisma `include` and relation `select` trees on reads.
2149
2256
 
2150
2257
  When `findManyPaginatedMode = "transaction"`, the root `findMany` and the total count run inside one interactive transaction, so `data` and `total` are mutually consistent. Relation stages, however, load **after** the transaction commits and are not part of it — relation batches can reflect writes committed between the root transaction and the stage queries.
2151
2258
 
2152
- Supported root operations:
2259
+ Supported unguarded root operations:
2153
2260
 
2154
2261
  - `findUnique`
2155
2262
  - `findUniqueOrThrow`
@@ -2158,16 +2265,23 @@ Supported root operations:
2158
2265
  - `findMany`
2159
2266
  - `findManyPaginated`
2160
2267
 
2161
- Supported single-record relation shapes:
2268
+ Supported guarded root operations:
2269
+
2270
+ - `findUnique`
2271
+ - `findUniqueOrThrow`
2272
+ - `findFirst`
2273
+ - `findFirstOrThrow`
2274
+
2275
+ Supported unguarded single-record relation shapes:
2162
2276
 
2163
2277
  - direct to-one relation includes/selects
2164
2278
  - direct to-many relation includes/selects
2165
2279
  - to-many relation args such as `where`, `orderBy`, `take`, `skip`, `cursor`, and `distinct`
2166
2280
  - nested relation loading through to-one parents
2167
2281
 
2168
- Single-record auto-include falls back when a nested stage crosses a to-many parent. Direct to-many loading is still supported, but nested loading under that array is not handled by the single-record progressive runtime.
2282
+ Unguarded single-record auto-include falls back when a nested stage crosses a to-many parent. Direct to-many loading is still supported, but nested loading under that array is not handled by the single-record progressive runtime.
2169
2283
 
2170
- Supported `findMany` and `findManyPaginated` relation shapes:
2284
+ Supported unguarded `findMany` and `findManyPaginated` relation shapes:
2171
2285
 
2172
2286
  - direct and nested to-one relation includes/selects
2173
2287
  - direct and nested to-many relation includes/selects
@@ -2175,11 +2289,33 @@ Supported `findMany` and `findManyPaginated` relation shapes:
2175
2289
  - single-column link fields only
2176
2290
  - nested depth up to the configured planner limit
2177
2291
 
2178
- For `findMany` and `findManyPaginated`, each stage loads children with a batched query over the flattened parent rows at that stage's `parentPath`. Direct root stages stream `relationBatch` events. Depth-2-or-deeper stages stream `nestedRelationBatch` events with locator/value attachments, then also appear in the terminal `result` event.
2292
+ For unguarded `findMany` and `findManyPaginated`, each stage loads children with a batched query over the flattened parent rows at that stage's `parentPath`. Direct root stages stream `relationBatch` events. Depth-2-or-deeper stages stream `nestedRelationBatch` events with locator/value attachments, then also appear in the terminal `result` event.
2179
2293
 
2180
2294
  `findMany` and `findManyPaginated` auto-include apply configured pagination limits to the root query before loading relation batches. If the client omits `take`, `pagination.defaultLimit` is applied when configured. If the client sends a large `take`, `pagination.maxLimit` is enforced before the root query runs.
2181
2295
 
2182
- Current MVP fallback cases include:
2296
+ Supported guarded single-record relation shapes:
2297
+
2298
+ - direct to-one relation `select` branches
2299
+ - direct to-many relation `select` branches
2300
+ - relation-level `where`, `orderBy`, `take`, `skip`, `cursor`, and `distinct` on direct to-many stages
2301
+ - nested `select` trees inside a direct relation stage, loaded as part of that guarded stage query
2302
+
2303
+ Guarded auto-include plans from the guard shape's default projection. Client-provided `select`, `include`, or `omit` is rejected for guarded auto-include and follows the configured fallback behavior. Normal guarded JSON reads still support client projection validation according to prisma-guard rules.
2304
+
2305
+ Guarded auto-include falls back when a shape uses an unsupported streaming form, including:
2306
+
2307
+ - client-provided `select`, `include`, or `omit`
2308
+ - shape-level `include` or `omit` in the auto-include plan
2309
+ - `_count` anywhere in the planned projection
2310
+ - implicit many-to-many relations
2311
+ - composite relation link fields
2312
+ - root relation filters in `where`, `orderBy`, or `cursor`
2313
+ - relation references in a staged relation's `orderBy` or `cursor`
2314
+ - link-field collisions in a staged relation `where`
2315
+ - planner limits for maximum stage count
2316
+ - guarded `findMany` or `findManyPaginated` auto-include
2317
+
2318
+ Unguarded auto-include falls back when a request uses an unsupported streaming form, including:
2183
2319
 
2184
2320
  - `_count` in `select` or `include`
2185
2321
  - implicit many-to-many relations
@@ -3140,7 +3276,7 @@ E2E=true
3140
3276
 
3141
3277
  ### E2E scalar-list support
3142
3278
 
3143
- E2E SQLite scalar-list support is intentionally narrow in phase 1.
3279
+ E2E SQLite scalar-list support is intentionally narrow.
3144
3280
 
3145
3281
  Supported:
3146
3282
 
@@ -3178,7 +3314,7 @@ basePrisma
3178
3314
 
3179
3315
  Guard extension remains in the chain, but generated routers do not pass guard shapes when `E2E=true`.
3180
3316
 
3181
- ### Phase 1 scope
3317
+ ### Supported E2E scalar-list scope
3182
3318
 
3183
3319
  Supported:
3184
3320
 
@@ -3215,7 +3351,7 @@ Do not depend on SQLite-generated guard output for this path.
3215
3351
 
3216
3352
  The SQLite schema is a derived test schema. It may intentionally erase Postgres-only field information such as scalar-list types. Guard correctness belongs to the production schema, not the SQLite test schema.
3217
3353
 
3218
- For phase 1, global E2E guard drop is simpler:
3354
+ Global E2E guard drop keeps this path simple:
3219
3355
 
3220
3356
  ```text
3221
3357
  production keeps guard
@@ -3258,4 +3394,4 @@ Hono
3258
3394
 
3259
3395
  ## License
3260
3396
 
3261
- MIT
3397
+ MIT
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "prisma-generator-express",
3
3
  "description": "Prisma generator for Express, Fastify, and Hono CRUD APIs with OpenAPI documentation",
4
- "version": "1.60.0",
4
+ "version": "1.61.0",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "license": "MIT",