prisma-generator-express 1.53.0 → 1.55.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 +123 -12
- package/dist/constants.d.ts +1 -0
- package/dist/generators/generateOperationCore.d.ts +2 -0
- package/dist/generators/generateOperationCore.js +30 -3
- package/dist/generators/generateOperationCore.js.map +1 -1
- package/dist/generators/generateRouter.d.ts +3 -1
- package/dist/generators/generateRouter.js +6 -4
- package/dist/generators/generateRouter.js.map +1 -1
- package/dist/generators/generateRouterFastify.d.ts +3 -1
- package/dist/generators/generateRouterFastify.js +6 -4
- package/dist/generators/generateRouterFastify.js.map +1 -1
- package/dist/generators/generateRouterHono.d.ts +3 -1
- package/dist/generators/generateRouterHono.js +6 -3
- package/dist/generators/generateRouterHono.js.map +1 -1
- package/dist/generators/generateUnifiedScalarUI.d.ts +2 -1
- package/dist/generators/generateUnifiedScalarUI.js +13 -10
- package/dist/generators/generateUnifiedScalarUI.js.map +1 -1
- package/dist/index.js +23 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/constants.ts +3 -1
- package/src/copy/autoIncludeRuntime.ts +52 -24
- package/src/copy/buildModelOpenApi.ts +144 -23
- package/src/copy/docsRenderer.ts +121 -95
- package/src/copy/operationRuntime.ts +9 -0
- package/src/copy/routeConfig.express.ts +2 -0
- package/src/copy/routeConfig.fastify.ts +2 -0
- package/src/copy/routeConfig.hono.ts +2 -0
- package/src/copy/routeConfig.ts +2 -0
- package/src/generators/generateOperationCore.ts +43 -3
- package/src/generators/generateRouter.ts +8 -3
- package/src/generators/generateRouterFastify.ts +8 -3
- package/src/generators/generateRouterHono.ts +8 -2
- package/src/generators/generateUnifiedScalarUI.ts +15 -11
- package/src/index.ts +27 -7
package/README.md
CHANGED
|
@@ -26,6 +26,7 @@ Supports **Express**, **Fastify**, and **Hono** targets via the `target` configu
|
|
|
26
26
|
- [Compatibility](#compatibility)
|
|
27
27
|
- [Installation](#installation)
|
|
28
28
|
- [Setup](#setup)
|
|
29
|
+
- [Write strategy](#write-strategy)
|
|
29
30
|
- [Path casing in generated endpoints](#path-casing-in-generated-endpoints)
|
|
30
31
|
- [Usage (Express)](#usage-express)
|
|
31
32
|
- [Usage (Fastify)](#usage-fastify)
|
|
@@ -62,6 +63,7 @@ Some operations require newer versions:
|
|
|
62
63
|
| Operation | Minimum Prisma version | Notes |
|
|
63
64
|
| --------------------- | ---------------------- | ------------------------------------ |
|
|
64
65
|
| `omit` parameter | 6.2.0 | Returns 400 on versions 6.0.x–6.1.x |
|
|
66
|
+
| `createManyAndReturn` | 5.14.0 | PostgreSQL, CockroachDB, SQLite only |
|
|
65
67
|
| `updateManyAndReturn` | 6.2.0 | PostgreSQL, CockroachDB, SQLite only |
|
|
66
68
|
|
|
67
69
|
### Framework support
|
|
@@ -160,6 +162,37 @@ Generate:
|
|
|
160
162
|
npx prisma generate
|
|
161
163
|
```
|
|
162
164
|
|
|
165
|
+
## Write strategy
|
|
166
|
+
|
|
167
|
+
`writeStrategy` is a schema-wide generator option. It controls only non-returning bulk data writes that have Prisma returning counterparts: `createMany` and `updateMany`. It does not affect `deleteMany`.
|
|
168
|
+
|
|
169
|
+
```prisma
|
|
170
|
+
generator express {
|
|
171
|
+
provider = "prisma-generator-express"
|
|
172
|
+
writeStrategy = "regular"
|
|
173
|
+
}
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
Valid values:
|
|
177
|
+
|
|
178
|
+
| Value | Behavior |
|
|
179
|
+
| ----- | -------- |
|
|
180
|
+
| `regular` | Default. `createMany` and `updateMany` call the normal Prisma methods and return `{ count }`. |
|
|
181
|
+
| `throwOnNonReturning` | Disables the generated `createMany` and `updateMany` endpoints (`POST /{modelname}/many` and `PUT /{modelname}/many`). Direct calls return `501`. Use `createManyAndReturn` and `updateManyAndReturn` endpoints instead. |
|
|
182
|
+
| `forceReturn` | `createMany` silently invokes `createManyAndReturn`, and `updateMany` silently invokes `updateManyAndReturn`. These endpoints return arrays of records instead of `{ count }` and support `select`, `include`, and `omit`. |
|
|
183
|
+
|
|
184
|
+
`forceReturn` still follows Prisma provider support. If the current provider does not support `createManyAndReturn` or `updateManyAndReturn`, the generated endpoint returns `501 Not Implemented` at runtime.
|
|
185
|
+
|
|
186
|
+
Example:
|
|
187
|
+
|
|
188
|
+
```prisma
|
|
189
|
+
generator express {
|
|
190
|
+
provider = "prisma-generator-express"
|
|
191
|
+
target = "express"
|
|
192
|
+
writeStrategy = "forceReturn"
|
|
193
|
+
}
|
|
194
|
+
```
|
|
195
|
+
|
|
163
196
|
## Path casing in generated endpoints
|
|
164
197
|
|
|
165
198
|
Model names are converted to **flat lowercase** in URL paths. There is no kebab-case or snake_case conversion — the model name is lowercased character by character.
|
|
@@ -961,7 +994,7 @@ const userConfig = {
|
|
|
961
994
|
}
|
|
962
995
|
```
|
|
963
996
|
|
|
964
|
-
The client can include `include` or `select` in the request body. If the shape does not define projection, the client cannot request one.
|
|
997
|
+
The client can include `include` or `select` in the request body. If the shape does not define projection, the client cannot request one. Non-returning batch methods (`createMany`, `updateMany`, `deleteMany`) do not support projection. When `writeStrategy = "forceReturn"`, the generated `createMany` and `updateMany` endpoints invoke returning methods and can use `select`, `include`, and `omit` like `createManyAndReturn` and `updateManyAndReturn`.
|
|
965
998
|
|
|
966
999
|
For mutations, projection shapes only validate and constrain client-requested projections by default — if the client omits `select`/`include`, Prisma returns the full record. This differs from read operations, where the shape's projection is automatically applied as default. Enable `enforceProjection` in the prisma-guard generator config to always apply mutation projection shapes.
|
|
967
1000
|
|
|
@@ -1230,7 +1263,7 @@ All write operations accept the full Prisma args object as the JSON request body
|
|
|
1230
1263
|
{ "where": { "id": 1 }, "create": { "name": "Alice" }, "update": { "name": "Bob" } }
|
|
1231
1264
|
```
|
|
1232
1265
|
|
|
1233
|
-
Write operations that return records (create
|
|
1266
|
+
Write operations that return records (`create`, `update`, `delete`, `upsert`, `createManyAndReturn`, `updateManyAndReturn`) support `select`, `include`, and `omit` in the request body to control the response shape. When `writeStrategy = "forceReturn"`, the generated `createMany` and `updateMany` endpoints are rewritten to returning methods and also support `select`, `include`, and `omit`.
|
|
1234
1267
|
|
|
1235
1268
|
For Express, mount `express.json()` before the router so request bodies are parsed. For Hono, malformed JSON bodies are rejected with 400 (`{ "message": "Invalid JSON in request body" }`) before reaching the handler.
|
|
1236
1269
|
|
|
@@ -1238,6 +1271,8 @@ For Express, mount `express.json()` before the router so request bodies are pars
|
|
|
1238
1271
|
|
|
1239
1272
|
`createMany`, `createManyAndReturn`, `updateMany`, and `updateManyAndReturn` accept scalar-only data inputs. Nested relation writes are not supported in bulk operations.
|
|
1240
1273
|
|
|
1274
|
+
By default, `createMany` and `updateMany` return `{ count }`, while `createManyAndReturn` and `updateManyAndReturn` return arrays of records. With `writeStrategy = "forceReturn"`, the generated `createMany` and `updateMany` endpoints return arrays of records because they invoke the returning Prisma methods internally.
|
|
1275
|
+
|
|
1241
1276
|
### Batch operation safety
|
|
1242
1277
|
|
|
1243
1278
|
`deleteMany`, `updateMany`, and `updateManyAndReturn` require a `where` field in the request body. Requests without `where` are rejected with 400 to prevent accidental mass operations. Sending `{ "where": {} }` is valid and matches all records — this protection catches accidental omission, not intentional broad operations.
|
|
@@ -1562,7 +1597,7 @@ Progressive SSE has two modes:
|
|
|
1562
1597
|
|
|
1563
1598
|
Manual mode is explicit staged data loading. You define stages yourself and each stage decides what query to run and which field path to patch.
|
|
1564
1599
|
|
|
1565
|
-
Auto-include mode is generated relation loading. The router keeps the normal GET endpoint, runs the root query first, then loads supported included relations as separate follow-up queries. For single-record reads, relation paths are streamed as field patches. For `findMany` and `findManyPaginated`, root rows are streamed first, direct root relation stages are streamed as index-aligned relation batches, and deeper nested relation stages are
|
|
1600
|
+
Auto-include mode is generated relation loading. The router keeps the normal GET endpoint, runs the root query first, then loads supported included relations as separate follow-up queries. For single-record reads, relation paths are streamed as field patches. For `findMany` and `findManyPaginated`, root rows are streamed first, direct root relation stages are streamed as index-aligned relation batches, and deeper nested relation stages are streamed as locator-based nested relation batches. The terminal `result` event still contains the fully assembled payload.
|
|
1566
1601
|
|
|
1567
1602
|
### Request format
|
|
1568
1603
|
|
|
@@ -1643,6 +1678,21 @@ Relation batch event for a direct root relation in `findMany` / `findManyPaginat
|
|
|
1643
1678
|
{ "type": "relationBatch", "relationPath": "profile", "values": [{ "id": "profile-1" }, null] }
|
|
1644
1679
|
```
|
|
1645
1680
|
|
|
1681
|
+
Nested relation batch event for a depth-2-or-deeper relation in `findMany` / `findManyPaginated` auto-include:
|
|
1682
|
+
|
|
1683
|
+
```json
|
|
1684
|
+
{
|
|
1685
|
+
"type": "nestedRelationBatch",
|
|
1686
|
+
"relationPath": "companies.users",
|
|
1687
|
+
"depth": 2,
|
|
1688
|
+
"attachments": [
|
|
1689
|
+
{ "locator": [0, "companies", 0], "value": [{ "id": "user-1" }] }
|
|
1690
|
+
]
|
|
1691
|
+
}
|
|
1692
|
+
```
|
|
1693
|
+
|
|
1694
|
+
Each `attachments[].locator` is walked from `rootArray.data` to the parent object. The leaf field to assign is the last segment of `relationPath`. For example, `relationPath: "companies.users"` and `locator: [0, "companies", 0]` means `rootArray.data[0].companies[0].users = value`.
|
|
1695
|
+
|
|
1646
1696
|
Final result event:
|
|
1647
1697
|
|
|
1648
1698
|
```json
|
|
@@ -1657,7 +1707,7 @@ Error event:
|
|
|
1657
1707
|
|
|
1658
1708
|
For single-record progressive responses, the final `result.data` is the accumulated object built from all applied patches, unless a manual stage returns a stop result.
|
|
1659
1709
|
|
|
1660
|
-
For `findMany` auto-include responses, `rootArray.data` is the source of truth for root row identity and order. Each depth-1 `relationBatch.values` array is index-aligned with `rootArray.data`, so `values[i]` belongs to `rootArray.data[i]`.
|
|
1710
|
+
For `findMany` auto-include responses, `rootArray.data` is the source of truth for root row identity and order. Each depth-1 `relationBatch.values` array is index-aligned with `rootArray.data`, so `values[i]` belongs to `rootArray.data[i]`. Each depth-2-or-deeper `nestedRelationBatch.attachments` array carries locator/value pairs that can be applied to the accumulated root rows immediately. The terminal `result.data` is the fully merged array and can be used as a final reconcile.
|
|
1661
1711
|
|
|
1662
1712
|
For `findManyPaginated` auto-include responses, `pageMeta` is sent before `rootArray`. The terminal `result.data` has the normal paginated shape: `{ data, total, hasMore }`.
|
|
1663
1713
|
|
|
@@ -1926,7 +1976,7 @@ On single-record reads, auto-include sends root scalar fields first, then sends
|
|
|
1926
1976
|
|
|
1927
1977
|
The final `result` event contains the assembled object.
|
|
1928
1978
|
|
|
1929
|
-
For `findMany`, auto-include sends the root rows first, then sends one relation batch event for each supported direct root relation stage.
|
|
1979
|
+
For `findMany`, auto-include sends the root rows first, then sends one relation batch event for each supported direct root relation stage. Depth-2-or-deeper stages send `nestedRelationBatch` events with locators pointing to the parent object inside the accumulated root rows:
|
|
1930
1980
|
|
|
1931
1981
|
```ts
|
|
1932
1982
|
const listConfig = {
|
|
@@ -1980,7 +2030,7 @@ Example shallow `findMany` auto-include event sequence:
|
|
|
1980
2030
|
{ "type": "result", "data": [{ "id": "user-1", "profile": { "id": "profile-1", "displayName": "Alice" } }, { "id": "user-2", "profile": null }] }
|
|
1981
2031
|
```
|
|
1982
2032
|
|
|
1983
|
-
Deep `findMany` and `findManyPaginated` requests use the same planner. Nested stages are loaded by flattening the parent rows at each path:
|
|
2033
|
+
Deep `findMany` and `findManyPaginated` requests use the same planner. Nested stages are loaded by flattening the parent rows at each path, then emitted as locator-based attachment batches:
|
|
1984
2034
|
|
|
1985
2035
|
```ts
|
|
1986
2036
|
const params = encodeQueryParams({
|
|
@@ -2026,11 +2076,25 @@ Example deep event sequence:
|
|
|
2026
2076
|
```
|
|
2027
2077
|
|
|
2028
2078
|
```json
|
|
2029
|
-
{
|
|
2079
|
+
{
|
|
2080
|
+
"type": "nestedRelationBatch",
|
|
2081
|
+
"relationPath": "companies.users",
|
|
2082
|
+
"depth": 2,
|
|
2083
|
+
"attachments": [
|
|
2084
|
+
{ "locator": [0, "companies", 0], "value": [{ "id": "user-1" }] }
|
|
2085
|
+
]
|
|
2086
|
+
}
|
|
2030
2087
|
```
|
|
2031
2088
|
|
|
2032
2089
|
```json
|
|
2033
|
-
{
|
|
2090
|
+
{
|
|
2091
|
+
"type": "nestedRelationBatch",
|
|
2092
|
+
"relationPath": "companies.users.profile",
|
|
2093
|
+
"depth": 3,
|
|
2094
|
+
"attachments": [
|
|
2095
|
+
{ "locator": [0, "companies", 0, "users", 0], "value": { "id": "profile-1", "displayName": "Alice" } }
|
|
2096
|
+
]
|
|
2097
|
+
}
|
|
2034
2098
|
```
|
|
2035
2099
|
|
|
2036
2100
|
```json
|
|
@@ -2068,7 +2132,7 @@ Supported `findMany` and `findManyPaginated` relation shapes:
|
|
|
2068
2132
|
- single-column link fields only
|
|
2069
2133
|
- nested depth up to the configured planner limit
|
|
2070
2134
|
|
|
2071
|
-
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
|
|
2135
|
+
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.
|
|
2072
2136
|
|
|
2073
2137
|
`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.
|
|
2074
2138
|
|
|
@@ -2137,6 +2201,20 @@ let rows: Array<Record<string, unknown>> = []
|
|
|
2137
2201
|
let fields: Record<string, unknown> = {}
|
|
2138
2202
|
let data: unknown = undefined
|
|
2139
2203
|
|
|
2204
|
+
const lastSegment = (path: string) => {
|
|
2205
|
+
const parts = path.split('.')
|
|
2206
|
+
return parts[parts.length - 1] ?? path
|
|
2207
|
+
}
|
|
2208
|
+
|
|
2209
|
+
const walk = (source: Array<Record<string, unknown>>, locator: Array<number | string>) => {
|
|
2210
|
+
let cursor: unknown = source[locator[0] as number]
|
|
2211
|
+
for (let i = 1; i < locator.length; i++) {
|
|
2212
|
+
if (cursor == null) return null
|
|
2213
|
+
cursor = (cursor as Record<string | number, unknown>)[locator[i]]
|
|
2214
|
+
}
|
|
2215
|
+
return cursor
|
|
2216
|
+
}
|
|
2217
|
+
|
|
2140
2218
|
while (true) {
|
|
2141
2219
|
const { value, done } = await reader.read()
|
|
2142
2220
|
if (done) break
|
|
@@ -2163,12 +2241,24 @@ while (true) {
|
|
|
2163
2241
|
}
|
|
2164
2242
|
|
|
2165
2243
|
if (event.type === 'relationBatch') {
|
|
2244
|
+
const field = lastSegment(event.relationPath)
|
|
2166
2245
|
rows = rows.map((row, index) => ({
|
|
2167
2246
|
...row,
|
|
2168
|
-
[
|
|
2247
|
+
[field]: event.values[index],
|
|
2169
2248
|
}))
|
|
2170
2249
|
}
|
|
2171
2250
|
|
|
2251
|
+
if (event.type === 'nestedRelationBatch') {
|
|
2252
|
+
const field = lastSegment(event.relationPath)
|
|
2253
|
+
for (const attachment of event.attachments) {
|
|
2254
|
+
const parent = walk(rows, attachment.locator)
|
|
2255
|
+
if (parent && typeof parent === 'object' && !Array.isArray(parent)) {
|
|
2256
|
+
const record = parent as Record<string, unknown>
|
|
2257
|
+
record[field] = attachment.value
|
|
2258
|
+
}
|
|
2259
|
+
}
|
|
2260
|
+
}
|
|
2261
|
+
|
|
2172
2262
|
if (event.type === 'result') {
|
|
2173
2263
|
data = event.data
|
|
2174
2264
|
}
|
|
@@ -2184,7 +2274,7 @@ For React Query, include the variant and mode in the query key:
|
|
|
2184
2274
|
|
|
2185
2275
|
Do not reuse the same query key as the JSON endpoint because the same URL can return different shapes depending on `x-api-variant`.
|
|
2186
2276
|
|
|
2187
|
-
For deep `findMany` / `findManyPaginated` auto-include,
|
|
2277
|
+
For deep `findMany` / `findManyPaginated` auto-include, apply `nestedRelationBatch` events for progressive rendering and still treat the final `result` event as the authoritative nested payload for reconciliation. Direct root relation stages emit `relationBatch`; depth-2-or-deeper relation stages emit `nestedRelationBatch`.
|
|
2188
2278
|
|
|
2189
2279
|
### Runtime notes
|
|
2190
2280
|
|
|
@@ -2550,6 +2640,8 @@ Paths shown are relative suffixes. Actual paths include the model prefix (e.g.,
|
|
|
2550
2640
|
|
|
2551
2641
|
POST read endpoints are enabled by default. Set `disablePostReads: true` to remove them.
|
|
2552
2642
|
|
|
2643
|
+
The schema-wide `writeStrategy` option can change the behavior of `POST /{modelname}/many` and `PUT /{modelname}/many`. It does not change `DELETE /{modelname}/many`.
|
|
2644
|
+
|
|
2553
2645
|
For the Express target, GET read endpoints can also stream SSE events when the request sends `Accept: text/event-stream`. SSE uses the same GET paths shown above; no additional routes are generated. See [Progressive Endpoint Composition](#progressive-endpoint-composition-express-sse).
|
|
2554
2646
|
|
|
2555
2647
|
## Skipping models
|
|
@@ -2565,6 +2657,23 @@ model InternalLog {
|
|
|
2565
2657
|
|
|
2566
2658
|
## Configuration
|
|
2567
2659
|
|
|
2660
|
+
### Generator options
|
|
2661
|
+
|
|
2662
|
+
Generator options are configured in `schema.prisma` and apply schema-wide.
|
|
2663
|
+
|
|
2664
|
+
```prisma
|
|
2665
|
+
generator express {
|
|
2666
|
+
provider = "prisma-generator-express"
|
|
2667
|
+
target = "express"
|
|
2668
|
+
writeStrategy = "regular"
|
|
2669
|
+
}
|
|
2670
|
+
```
|
|
2671
|
+
|
|
2672
|
+
| Option | Values | Default | Description |
|
|
2673
|
+
| ------ | ------ | ------- | ----------- |
|
|
2674
|
+
| `target` | `"express"`, `"fastify"`, `"hono"` | `"express"` | Selects the generated router target. |
|
|
2675
|
+
| `writeStrategy` | `"regular"`, `"throwOnNonReturning"`, `"forceReturn"` | `"regular"` | Controls only `createMany` and `updateMany`. See [Write strategy](#write-strategy). |
|
|
2676
|
+
|
|
2568
2677
|
### Express
|
|
2569
2678
|
|
|
2570
2679
|
```ts
|
|
@@ -2728,7 +2837,9 @@ The `guard.resolveVariant` callback receives Hono's `Context`. Hooks are native
|
|
|
2728
2837
|
|
|
2729
2838
|
The Hono router does not auto-start the Query Builder. Set `queryBuilder: false` to make the playground route return 404, or run `prisma-query-builder-ui` manually for development.
|
|
2730
2839
|
|
|
2731
|
-
### Shared options
|
|
2840
|
+
### Shared route options
|
|
2841
|
+
|
|
2842
|
+
These options are passed to the generated router at runtime. They are separate from schema-wide generator options such as `target` and `writeStrategy`.
|
|
2732
2843
|
|
|
2733
2844
|
`customUrlPrefix` is normalized to ensure a leading slash and strip trailing slashes.
|
|
2734
2845
|
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { DMMF } from '@prisma/generator-helper';
|
|
2
2
|
import { ImportStyle } from '../utils/resolveImportStyle';
|
|
3
|
+
import { WriteStrategy } from '../constants';
|
|
3
4
|
export interface ModelCoreOptions {
|
|
4
5
|
model: DMMF.Model;
|
|
5
6
|
importStyle: ImportStyle;
|
|
7
|
+
writeStrategy: WriteStrategy;
|
|
6
8
|
}
|
|
7
9
|
export declare function generateModelCore(options: ModelCoreOptions): string;
|
|
@@ -2,10 +2,27 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateModelCore = generateModelCore;
|
|
4
4
|
const importExt_1 = require("../utils/importExt");
|
|
5
|
+
function decideWriteOp(name, defaultMethod, strategy) {
|
|
6
|
+
if (strategy === 'regular') {
|
|
7
|
+
return { mode: 'normal', method: defaultMethod };
|
|
8
|
+
}
|
|
9
|
+
if (strategy === 'throwOnNonReturning') {
|
|
10
|
+
if (name === 'createMany' || name === 'updateMany') {
|
|
11
|
+
return { mode: 'throw' };
|
|
12
|
+
}
|
|
13
|
+
return { mode: 'normal', method: defaultMethod };
|
|
14
|
+
}
|
|
15
|
+
if (name === 'createMany')
|
|
16
|
+
return { mode: 'redirect', method: 'createManyAndReturn' };
|
|
17
|
+
if (name === 'updateMany')
|
|
18
|
+
return { mode: 'redirect', method: 'updateManyAndReturn' };
|
|
19
|
+
return { mode: 'normal', method: defaultMethod };
|
|
20
|
+
}
|
|
5
21
|
function generateModelCore(options) {
|
|
6
22
|
const ext = (0, importExt_1.importExt)(options.importStyle);
|
|
7
23
|
const modelName = options.model.name;
|
|
8
24
|
const modelNameLower = modelName.charAt(0).toLowerCase() + modelName.slice(1);
|
|
25
|
+
const writeStrategy = options.writeStrategy;
|
|
9
26
|
const standardReadOps = [
|
|
10
27
|
'findFirst', 'findUnique', 'findUniqueOrThrow', 'findFirstOrThrow',
|
|
11
28
|
'count', 'aggregate', 'groupBy',
|
|
@@ -35,7 +52,17 @@ export async function ${op}(ctx: OperationContext): Promise<unknown> {
|
|
|
35
52
|
{ name: 'upsert', method: 'upsert', requiredFields: ['where', 'create', 'update'] },
|
|
36
53
|
];
|
|
37
54
|
const writeHandlers = writeOps.map((op) => {
|
|
38
|
-
const
|
|
55
|
+
const decision = decideWriteOp(op.name, op.method, writeStrategy);
|
|
56
|
+
if (decision.mode === 'throw') {
|
|
57
|
+
return `
|
|
58
|
+
export async function ${op.name}(_ctx: OperationContext): Promise<unknown> {
|
|
59
|
+
throw new HttpError(501, '${op.name} is disabled by writeStrategy="${writeStrategy}"')
|
|
60
|
+
}`;
|
|
61
|
+
}
|
|
62
|
+
const method = decision.method;
|
|
63
|
+
const validationLines = op.requiredFields
|
|
64
|
+
.map((field) => ` requireBodyField(body, '${field}')`)
|
|
65
|
+
.join('\n');
|
|
39
66
|
return `
|
|
40
67
|
export async function ${op.name}(ctx: OperationContext): Promise<unknown> {
|
|
41
68
|
const body = validateBody(ctx.body)
|
|
@@ -44,9 +71,9 @@ ${validationLines}
|
|
|
44
71
|
const delegate = getDelegate(extended, '${modelNameLower}')
|
|
45
72
|
if (ctx.guardShape) {
|
|
46
73
|
assertGuard(delegate)
|
|
47
|
-
return delegate.guard(ctx.guardShape, ctx.guardCaller).${
|
|
74
|
+
return delegate.guard(ctx.guardShape, ctx.guardCaller).${method}(body)
|
|
48
75
|
}
|
|
49
|
-
return delegate.${
|
|
76
|
+
return delegate.${method}(body)
|
|
50
77
|
}`;
|
|
51
78
|
}).join('\n');
|
|
52
79
|
return `import {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateOperationCore.js","sourceRoot":"","sources":["../../src/generators/generateOperationCore.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"generateOperationCore.js","sourceRoot":"","sources":["../../src/generators/generateOperationCore.ts"],"names":[],"mappings":";;AAmCA,8CAwLC;AAzND,kDAA8C;AAc9C,SAAS,aAAa,CACpB,IAAY,EACZ,aAAqB,EACrB,QAAuB;IAEvB,IAAI,QAAQ,KAAK,SAAS,EAAE,CAAC;QAC3B,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,aAAa,EAAE,CAAA;IAClD,CAAC;IACD,IAAI,QAAQ,KAAK,qBAAqB,EAAE,CAAC;QACvC,IAAI,IAAI,KAAK,YAAY,IAAI,IAAI,KAAK,YAAY,EAAE,CAAC;YACnD,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAA;QAC1B,CAAC;QACD,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,aAAa,EAAE,CAAA;IAClD,CAAC;IACD,IAAI,IAAI,KAAK,YAAY;QAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,qBAAqB,EAAE,CAAA;IACrF,IAAI,IAAI,KAAK,YAAY;QAAE,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,MAAM,EAAE,qBAAqB,EAAE,CAAA;IACrF,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,aAAa,EAAE,CAAA;AAClD,CAAC;AAED,SAAgB,iBAAiB,CAAC,OAAyB;IACzD,MAAM,GAAG,GAAG,IAAA,qBAAS,EAAC,OAAO,CAAC,WAAW,CAAC,CAAA;IAC1C,MAAM,SAAS,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAA;IACpC,MAAM,cAAc,GAAG,SAAS,CA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ator-helper';
|
|
2
2
|
import { ImportStyle } from '../utils/resolveImportStyle';
|
|
3
|
-
|
|
3
|
+
import { WriteStrategy } from '../constants';
|
|
4
|
+
export declare function generateRouterFunction({ model, enums, guardShapesImport, importStyle, writeStrategy, }: {
|
|
4
5
|
model: DMMF.Model;
|
|
5
6
|
enums: DMMF.DatamodelEnum[];
|
|
6
7
|
guardShapesImport: string | null;
|
|
7
8
|
importStyle: ImportStyle;
|
|
9
|
+
writeStrategy: WriteStrategy;
|
|
8
10
|
}): string;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generateRouterFunction = generateRouterFunction;
|
|
4
4
|
const generateRouteConfigType_1 = require("./generateRouteConfigType");
|
|
5
5
|
const importExt_1 = require("../utils/importExt");
|
|
6
|
-
function generateRouterFunction({ model, enums, guardShapesImport, importStyle, }) {
|
|
6
|
+
function generateRouterFunction({ model, enums, guardShapesImport, importStyle, writeStrategy, }) {
|
|
7
7
|
const ext = (0, importExt_1.importExt)(importStyle);
|
|
8
8
|
const modelName = model.name;
|
|
9
9
|
const modelNameLower = modelName.toLowerCase();
|
|
@@ -51,7 +51,7 @@ import {
|
|
|
51
51
|
${modelName}GroupBy,
|
|
52
52
|
} from './${modelName}Handlers${ext}'
|
|
53
53
|
import * as core from './${modelName}Core${ext}'
|
|
54
|
-
import type { RouteConfig, QueryBuilderConfig } from '../routeConfig.target${ext}'
|
|
54
|
+
import type { RouteConfig, QueryBuilderConfig, WriteStrategy } from '../routeConfig.target${ext}'
|
|
55
55
|
import { parseQueryParams } from '../parseQueryParams${ext}'
|
|
56
56
|
import { sanitizeKeys, normalizePrefix, getEnv } from '../misc${ext}'
|
|
57
57
|
import { buildModelOpenApi } from '../buildModelOpenApi${ext}'
|
|
@@ -72,6 +72,8 @@ import { runAutoIncludeProgressive } from '../autoIncludeRuntime${ext}'
|
|
|
72
72
|
${(0, generateRouteConfigType_1.generateRouteConfigType)(modelName, 'RequestHandler', guardShapesImport, importStyle, 'express')}
|
|
73
73
|
const _env = getEnv()
|
|
74
74
|
|
|
75
|
+
const WRITE_STRATEGY: WriteStrategy = '${writeStrategy}'
|
|
76
|
+
|
|
75
77
|
const MODEL_FIELDS = ${JSON.stringify(fieldsMeta, null, 2)} as const
|
|
76
78
|
const MODEL_ENUMS = ${JSON.stringify(enumsMeta, null, 2)} as const
|
|
77
79
|
|
|
@@ -138,7 +140,7 @@ export function ${routerFunctionName}<TCtx = unknown, TPrisma = any>(config: ${m
|
|
|
138
140
|
MODEL_FIELDS as unknown as Parameters<typeof buildModelOpenApi>[1],
|
|
139
141
|
MODEL_ENUMS as unknown as Parameters<typeof buildModelOpenApi>[2],
|
|
140
142
|
config as unknown as Parameters<typeof buildModelOpenApi>[3],
|
|
141
|
-
{ format: 'json' },
|
|
143
|
+
{ format: 'json', writeStrategy: WRITE_STRATEGY },
|
|
142
144
|
)
|
|
143
145
|
const openApiYamlSpec = openApiDisabled
|
|
144
146
|
? null
|
|
@@ -147,7 +149,7 @@ export function ${routerFunctionName}<TCtx = unknown, TPrisma = any>(config: ${m
|
|
|
147
149
|
MODEL_FIELDS as unknown as Parameters<typeof buildModelOpenApi>[1],
|
|
148
150
|
MODEL_ENUMS as unknown as Parameters<typeof buildModelOpenApi>[2],
|
|
149
151
|
config as unknown as Parameters<typeof buildModelOpenApi>[3],
|
|
150
|
-
{ format: 'yaml' },
|
|
152
|
+
{ format: 'yaml', writeStrategy: WRITE_STRATEGY },
|
|
151
153
|
)
|
|
152
154
|
|
|
153
155
|
const qbEnabled = isQueryBuilderEnabled(config)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateRouter.js","sourceRoot":"","sources":["../../src/generators/generateRouter.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"generateRouter.js","sourceRoot":"","sources":["../../src/generators/generateRouter.ts"],"names":[],"mappings":";;AAMA,wDAqgBC;AA1gBD,uEAAmE;AAEnE,kDAA8C;AAG9C,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;8BACP,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;8HA+EqF,SAAS;+FACxC,SAAS;;;;;;4IAMoC,SAAS;+FACtD,SAAS;;;;;;8IAMsC,SAAS;+FACxD,SAAS;;;;;;8HAMsB,SAAS;+FACxC,SAAS;;;;;;sHAMc,SAAS;+FAChC,SAAS;;;;;;0HAMkB,SAAS;+FACpC,SAAS;;;;;;8IAMsC,SAAS;+FACxD,SAAS;;;;;;gIAMwB,SAAS;+FAC1C,SAAS;;;;;;4HAMoB,SAAS;;;+EAGtD,SAAS;;;;;;;;uDAQjC,SAAS;;;;;;uDAMT,SAAS;;;;;;uDAMT,SAAS;;;;;;sDAMV,SAAS;;;;;;sDAMT,SAAS;;;;;;sDAMT,SAAS;;;;;;wDAMP,SAAS;;;;;;yDAMR,SAAS;;;;;;yDAMT,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwCjE,CAAA;AACD,CAAC"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { DMMF } from '@prisma/generator-helper';
|
|
2
2
|
import { ImportStyle } from '../utils/resolveImportStyle';
|
|
3
|
-
|
|
3
|
+
import { WriteStrategy } from '../constants';
|
|
4
|
+
export declare function generateFastifyRouterFunction({ model, enums, guardShapesImport, importStyle, writeStrategy, }: {
|
|
4
5
|
model: DMMF.Model;
|
|
5
6
|
enums: DMMF.DatamodelEnum[];
|
|
6
7
|
guardShapesImport: string | null;
|
|
7
8
|
importStyle: ImportStyle;
|
|
9
|
+
writeStrategy: WriteStrategy;
|
|
8
10
|
}): string;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generateFastifyRouterFunction = generateFastifyRouterFunction;
|
|
4
4
|
const generateRouteConfigType_1 = require("./generateRouteConfigType");
|
|
5
5
|
const importExt_1 = require("../utils/importExt");
|
|
6
|
-
function generateFastifyRouterFunction({ model, enums, guardShapesImport, importStyle, }) {
|
|
6
|
+
function generateFastifyRouterFunction({ model, enums, guardShapesImport, importStyle, writeStrategy, }) {
|
|
7
7
|
const ext = (0, importExt_1.importExt)(importStyle);
|
|
8
8
|
const modelName = model.name;
|
|
9
9
|
const modelNameLower = modelName.toLowerCase();
|
|
@@ -48,7 +48,7 @@ import {
|
|
|
48
48
|
${modelName}Count,
|
|
49
49
|
${modelName}GroupBy,
|
|
50
50
|
} from './${modelName}Handlers${ext}'
|
|
51
|
-
import type { RouteConfig, FastifyHookHandler } from '../routeConfig.target${ext}'
|
|
51
|
+
import type { RouteConfig, FastifyHookHandler, WriteStrategy } from '../routeConfig.target${ext}'
|
|
52
52
|
import { parseQueryParams } from '../parseQueryParams${ext}'
|
|
53
53
|
import { sanitizeKeys, normalizePrefix, getEnv } from '../misc${ext}'
|
|
54
54
|
import { buildModelOpenApi } from '../buildModelOpenApi${ext}'
|
|
@@ -57,6 +57,8 @@ import { mapError, transformResult, HttpError, type OperationContext } from '../
|
|
|
57
57
|
${(0, generateRouteConfigType_1.generateRouteConfigType)(modelName, 'FastifyHookHandler', guardShapesImport, importStyle, 'fastify')}
|
|
58
58
|
const _env = getEnv()
|
|
59
59
|
|
|
60
|
+
const WRITE_STRATEGY: WriteStrategy = '${writeStrategy}'
|
|
61
|
+
|
|
60
62
|
const MODEL_FIELDS = ${JSON.stringify(fieldsMeta, null, 2)} as const
|
|
61
63
|
|
|
62
64
|
const MODEL_ENUMS = ${JSON.stringify(enumsMeta, null, 2)} as const
|
|
@@ -187,7 +189,7 @@ export async function ${routerFunctionName}<TCtx = unknown, TPrisma = any>(
|
|
|
187
189
|
MODEL_FIELDS as unknown as Parameters<typeof buildModelOpenApi>[1],
|
|
188
190
|
MODEL_ENUMS as unknown as Parameters<typeof buildModelOpenApi>[2],
|
|
189
191
|
config,
|
|
190
|
-
{ format: 'json' },
|
|
192
|
+
{ format: 'json', writeStrategy: WRITE_STRATEGY },
|
|
191
193
|
)
|
|
192
194
|
const openApiYamlSpec = openApiDisabled
|
|
193
195
|
? null
|
|
@@ -196,7 +198,7 @@ export async function ${routerFunctionName}<TCtx = unknown, TPrisma = any>(
|
|
|
196
198
|
MODEL_FIELDS as unknown as Parameters<typeof buildModelOpenApi>[1],
|
|
197
199
|
MODEL_ENUMS as unknown as Parameters<typeof buildModelOpenApi>[2],
|
|
198
200
|
config,
|
|
199
|
-
{ format: 'yaml' },
|
|
201
|
+
{ format: 'yaml', writeStrategy: WRITE_STRATEGY },
|
|
200
202
|
)
|
|
201
203
|
|
|
202
204
|
const qbEnabled = isQueryBuilderEnabled(config)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateRouterFastify.js","sourceRoot":"","sources":["../../src/generators/generateRouterFastify.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"generateRouterFastify.js","sourceRoot":"","sources":["../../src/generators/generateRouterFastify.ts"],"names":[],"mappings":";;AAMA,sEAsZC;AA3ZD,uEAAmE;AAEnE,kDAA8C;AAG9C,SAAgB,6BAA6B,CAAC,EAC5C,KAAK,EACL,KAAK,EACL,iBAAiB,EACjB,WAAW,EACX,aAAa,GAOd;IACC,MAAM,GAAG,GAAG,IAAA,qBAAS,EAAC,WAAW,CAAC,CAAA;IAClC,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAA;IAC5B,MAAM,cAAc,GAAG,SAAS,CAAC,WAAW,EAAE,CAAA;IAC9C,MAAM,kBAAkB,GAAG,GAAG,SAAS,QAAQ,CAAA;IAE/C,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAC1C,IAAI,EAAE,CAAC,CAAC,IAAI;QACZ,IAAI,EAAE,CAAC,CAAC,IAAI;QACZ,IAAI,EAAE,CAAC,CAAC,IAAI;QACZ,MAAM,EAAE,CAAC,CAAC,MAAM;QAChB,UAAU,EAAE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C;;;yCAG5D,aAAa;;uBAE/B,IAAI,CAAC,SAAS,CAAC,UAAU,EAAE,IAAI,EAAE,CAAC,CAAC;;sBAEpC,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YAsD5C,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAmDG,kBAAkB;;YAE9B,SAAS;;;4DAGuC,cAAc;;;;;;;;;;;;;;WAc/D,SAAS;;;;;;;;;WAST,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4CA+EwB,SAAS;mEACc,SAAS;;;;;;4CAMhC,SAAS;mEACc,SAAS;;;;;;4CAMhC,SAAS;mEACc,SAAS;;;;;;4CAMhC,SAAS;mEACc,SAAS;;;;;;4CAMhC,SAAS;mEACc,SAAS;;;;;;4CAMhC,SAAS;mEACc,SAAS;;;;;;4CAMhC,SAAS;mEACc,SAAS;;;;;;4CAMhC,SAAS;mEACc,SAAS;;;;;;4CAMhC,SAAS;;;mDAGF,SAAS;;;;;;;+CAOb,SAAS;;;;;;+CAMT,SAAS;;;;;;+CAMT,SAAS;;;;;;8CAMV,SAAS;;;;;;8CAMT,SAAS;;;;;;8CAMT,SAAS;;;;;;gDAMP,SAAS;;;;;;iDAMR,SAAS;;;;;;iDAMT,SAAS;;;CAGzD,CAAA;AACD,CAAC"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { DMMF } from '@prisma/generator-helper';
|
|
2
2
|
import { ImportStyle } from '../utils/resolveImportStyle';
|
|
3
|
-
|
|
3
|
+
import { WriteStrategy } from '../constants';
|
|
4
|
+
export declare function generateHonoRouterFunction({ model, enums, guardShapesImport, importStyle, writeStrategy, }: {
|
|
4
5
|
model: DMMF.Model;
|
|
5
6
|
enums: DMMF.DatamodelEnum[];
|
|
6
7
|
guardShapesImport: string | null;
|
|
7
8
|
importStyle: ImportStyle;
|
|
9
|
+
writeStrategy: WriteStrategy;
|
|
8
10
|
}): string;
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generateHonoRouterFunction = generateHonoRouterFunction;
|
|
4
4
|
const generateRouteConfigType_1 = require("./generateRouteConfigType");
|
|
5
5
|
const importExt_1 = require("../utils/importExt");
|
|
6
|
-
function generateHonoRouterFunction({ model, enums, guardShapesImport, importStyle, }) {
|
|
6
|
+
function generateHonoRouterFunction({ model, enums, guardShapesImport, importStyle, writeStrategy, }) {
|
|
7
7
|
const ext = (0, importExt_1.importExt)(importStyle);
|
|
8
8
|
const modelName = model.name;
|
|
9
9
|
const modelNameLower = modelName.toLowerCase();
|
|
@@ -57,6 +57,7 @@ import type {
|
|
|
57
57
|
HonoEnvBase,
|
|
58
58
|
HonoInternalVariables,
|
|
59
59
|
GeneratedHonoEnv,
|
|
60
|
+
WriteStrategy,
|
|
60
61
|
} from '../routeConfig.target${ext}'
|
|
61
62
|
import { parseQueryParams } from '../parseQueryParams${ext}'
|
|
62
63
|
import { sanitizeKeys, normalizePrefix, getEnv } from '../misc${ext}'
|
|
@@ -66,6 +67,8 @@ import { mapError, transformResult, type OperationContext } from '../operationRu
|
|
|
66
67
|
${(0, generateRouteConfigType_1.generateRouteConfigType)(modelName, 'HonoHookHandler', guardShapesImport, importStyle, 'hono')}
|
|
67
68
|
const _env = getEnv()
|
|
68
69
|
|
|
70
|
+
const WRITE_STRATEGY: WriteStrategy = '${writeStrategy}'
|
|
71
|
+
|
|
69
72
|
const MODEL_FIELDS = ${JSON.stringify(fieldsMeta, null, 2)} as const
|
|
70
73
|
|
|
71
74
|
const MODEL_ENUMS = ${JSON.stringify(enumsMeta, null, 2)} as const
|
|
@@ -208,7 +211,7 @@ export function ${routerFunctionName}<TCtx = unknown, TPrisma = any, TEnv extend
|
|
|
208
211
|
MODEL_FIELDS as unknown as Parameters<typeof buildModelOpenApi>[1],
|
|
209
212
|
MODEL_ENUMS as unknown as Parameters<typeof buildModelOpenApi>[2],
|
|
210
213
|
config as RouteConfig,
|
|
211
|
-
{ format: 'json' },
|
|
214
|
+
{ format: 'json', writeStrategy: WRITE_STRATEGY },
|
|
212
215
|
)
|
|
213
216
|
const openApiYamlSpec = openApiDisabled
|
|
214
217
|
? null
|
|
@@ -217,7 +220,7 @@ export function ${routerFunctionName}<TCtx = unknown, TPrisma = any, TEnv extend
|
|
|
217
220
|
MODEL_FIELDS as unknown as Parameters<typeof buildModelOpenApi>[1],
|
|
218
221
|
MODEL_ENUMS as unknown as Parameters<typeof buildModelOpenApi>[2],
|
|
219
222
|
config as RouteConfig,
|
|
220
|
-
{ format: 'yaml' },
|
|
223
|
+
{ format: 'yaml', writeStrategy: WRITE_STRATEGY },
|
|
221
224
|
)
|
|
222
225
|
|
|
223
226
|
if (isQueryBuilderEnabled(config as RouteConfig)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateRouterHono.js","sourceRoot":"","sources":["../../src/generators/generateRouterHono.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"generateRouterHono.js","sourceRoot":"","sources":["../../src/generators/generateRouterHono.ts"],"names":[],"mappings":";;AAMA,gEAiaC;AAtaD,uEAAmE;AAEnE,kDAA8C;AAG9C,SAAgB,0BAA0B,CAAC,EACzC,KAAK,EACL,KAAK,EACL,iBAAiB,EACjB,WAAW,EACX,aAAa,GAOd;IACC,MAAM,GAAG,GAAG,IAAA,qBAAS,EAAC,WAAW,CAAC,CAAA;IAClC,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAA;IAC5B,MAAM,cAAc,GAAG,SAAS,CAAC,WAAW,EAAE,CAAA;IAC9C,MAAM,kBAAkB,GAAG,GAAG,SAAS,QAAQ,CAAA;IAE/C,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM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|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { DMMF } from '@prisma/generator-helper';
|
|
2
|
-
import { Target } from '../constants';
|
|
2
|
+
import { Target, WriteStrategy } from '../constants';
|
|
3
3
|
import { ImportStyle } from '../utils/resolveImportStyle';
|
|
4
4
|
export declare function generateScalarUIHandler(options: {
|
|
5
5
|
model: DMMF.Model;
|
|
6
6
|
enums: DMMF.DatamodelEnum[];
|
|
7
7
|
target?: Target;
|
|
8
8
|
importStyle: ImportStyle;
|
|
9
|
+
writeStrategy: WriteStrategy;
|
|
9
10
|
}): string;
|