prisma-generator-express 1.45.0 → 1.46.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 +155 -30
- package/dist/client/encodeQueryParams.js +4 -0
- package/dist/client/encodeQueryParams.js.map +1 -1
- package/dist/copy/misc.d.ts +4 -2
- package/dist/copy/misc.js +35 -24
- package/dist/copy/misc.js.map +1 -1
- package/dist/generators/generateFastifyHandler.js +2 -4
- package/dist/generators/generateFastifyHandler.js.map +1 -1
- package/dist/generators/generateHonoHandler.js +2 -4
- package/dist/generators/generateHonoHandler.js.map +1 -1
- package/dist/generators/generateImportPrismaStatement.d.ts +0 -1
- package/dist/generators/generateImportPrismaStatement.js +2 -20
- package/dist/generators/generateImportPrismaStatement.js.map +1 -1
- package/dist/generators/generateOperationCore.js +1 -1
- package/dist/generators/generateQueryBuilderHelper.js +9 -0
- package/dist/generators/generateQueryBuilderHelper.js.map +1 -1
- package/dist/generators/generateRelationMeta.js +0 -10
- package/dist/generators/generateRelationMeta.js.map +1 -1
- package/dist/generators/generateRouteConfigType.js +33 -12
- package/dist/generators/generateRouteConfigType.js.map +1 -1
- package/dist/generators/generateRouter.d.ts +0 -1
- package/dist/generators/generateRouter.js +75 -70
- package/dist/generators/generateRouter.js.map +1 -1
- package/dist/generators/generateRouterFastify.js +83 -89
- package/dist/generators/generateRouterFastify.js.map +1 -1
- package/dist/generators/generateRouterHono.js +257 -237
- package/dist/generators/generateRouterHono.js.map +1 -1
- package/dist/generators/generateUnifiedDocs.d.ts +2 -2
- package/dist/generators/generateUnifiedDocs.js +90 -252
- package/dist/generators/generateUnifiedDocs.js.map +1 -1
- package/dist/generators/generateUnifiedHandler.js +2 -4
- package/dist/generators/generateUnifiedHandler.js.map +1 -1
- package/dist/index.js +16 -8
- package/dist/index.js.map +1 -1
- package/dist/utils/copyFiles.js +3 -2
- package/dist/utils/copyFiles.js.map +1 -1
- package/dist/utils/strings.d.ts +0 -1
- package/dist/utils/strings.js +0 -9
- package/dist/utils/strings.js.map +1 -1
- package/package.json +1 -1
- package/src/client/encodeQueryParams.ts +7 -15
- package/src/copy/autoIncludePlanner.ts +4 -17
- package/src/copy/autoIncludeRuntime.ts +11 -19
- package/src/copy/buildModelOpenApi.ts +11 -14
- package/src/copy/docsRenderer.ts +8 -14
- package/src/copy/misc.ts +28 -23
- package/src/copy/operationRuntime.ts +61 -43
- package/src/copy/parseQueryParams.ts +5 -14
- package/src/copy/routeConfig.express.ts +24 -18
- package/src/copy/routeConfig.fastify.ts +1 -1
- package/src/copy/routeConfig.hono.ts +34 -6
- package/src/copy/routeConfig.ts +2 -2
- package/src/generators/generateFastifyHandler.ts +2 -5
- package/src/generators/generateHonoHandler.ts +2 -5
- package/src/generators/generateImportPrismaStatement.ts +3 -35
- package/src/generators/generateOperationCore.ts +1 -1
- package/src/generators/generateQueryBuilderHelper.ts +9 -0
- package/src/generators/generateRelationMeta.ts +0 -10
- package/src/generators/generateRouteConfigType.ts +34 -10
- package/src/generators/generateRouter.ts +75 -71
- package/src/generators/generateRouterFastify.ts +83 -89
- package/src/generators/generateRouterHono.ts +257 -237
- package/src/generators/generateUnifiedDocs.ts +89 -267
- package/src/generators/generateUnifiedHandler.ts +2 -4
- package/src/index.ts +45 -14
- package/src/utils/copyFiles.ts +2 -2
- package/src/utils/strings.ts +0 -8
- package/src/copy/createOutputValidatorMiddleware.ts +0 -47
- package/src/copy/createValidatorMiddleware.ts +0 -62
- package/src/copy/transformZod.ts +0 -139
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ Running `npx prisma generate` produces:
|
|
|
12
12
|
- Handler functions for all Prisma operations (findMany, create, update, delete, etc.)
|
|
13
13
|
- Router generator with middleware support (before/after hooks per operation)
|
|
14
14
|
- POST read endpoints for all read operations (for complex queries exceeding URL length limits)
|
|
15
|
-
- Express-only progressive read streaming over Server-Sent Events (SSE)
|
|
15
|
+
- Express-only progressive read streaming over Server-Sent Events (SSE), using manual stages or auto-include splitting for single-record relation reads
|
|
16
16
|
- OpenAPI 3.1 spec (JSON and YAML endpoints registered automatically per router)
|
|
17
17
|
- Documentation helpers for contract view and Scalar UI (require manual mounting)
|
|
18
18
|
- Client-side query parameter encoder
|
|
@@ -72,7 +72,7 @@ Some operations require newer versions:
|
|
|
72
72
|
|
|
73
73
|
The Hono target v1 is tested on Node.js runtimes only. See [Cloudflare Workers and edge runtimes](#cloudflare-workers-and-edge-runtimes).
|
|
74
74
|
|
|
75
|
-
Progressive Endpoint Composition over Server-Sent Events is currently supported by the Express target only. Fastify and Hono continue to support normal JSON read and write routes.
|
|
75
|
+
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 single-record relation reads. Fastify and Hono continue to support normal JSON read and write routes.
|
|
76
76
|
|
|
77
77
|
### Database provider support
|
|
78
78
|
|
|
@@ -1331,15 +1331,22 @@ app.use('/', UserRouter({
|
|
|
1331
1331
|
|
|
1332
1332
|
Progressive Endpoint Composition lets an Express read endpoint stream partial response fields over Server-Sent Events while still ending with a final result event.
|
|
1333
1333
|
|
|
1334
|
-
This is useful for page-level endpoints where different UI sections need different slices of data. For example, a dashboard can render profile basics first, then saved jobs, applications, invitations, and activity as each
|
|
1334
|
+
This is useful for page-level endpoints where different UI sections need different slices of data. For example, a dashboard can render profile basics first, then saved jobs, applications, invitations, and activity as each part finishes.
|
|
1335
1335
|
|
|
1336
1336
|
This feature is **Express-only** in v1.
|
|
1337
1337
|
|
|
1338
1338
|
### Mental model
|
|
1339
1339
|
|
|
1340
|
-
Progressive
|
|
1340
|
+
Progressive SSE has two modes:
|
|
1341
1341
|
|
|
1342
|
-
|
|
1342
|
+
| Mode | Config | Best for |
|
|
1343
|
+
| ---- | ------ | -------- |
|
|
1344
|
+
| Manual stages | `{ stages: [...] }` or `{ mode: 'manual', stages: [...] }` | Custom page-level composition where each stage runs its own query and returns patches |
|
|
1345
|
+
| Auto include | `{ mode: 'autoInclude' }` | Single-record reads where the client already sends a Prisma `include` or relation `select` tree and you want relation fields streamed progressively |
|
|
1346
|
+
|
|
1347
|
+
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.
|
|
1348
|
+
|
|
1349
|
+
Auto-include mode is generated relation loading. The router keeps the normal GET endpoint, runs the root single-record query first, streams root fields, then loads supported included relations as separate follow-up queries and streams each relation path as it resolves.
|
|
1343
1350
|
|
|
1344
1351
|
### Request format
|
|
1345
1352
|
|
|
@@ -1359,7 +1366,7 @@ POST read endpoints remain JSON-only.
|
|
|
1359
1366
|
|
|
1360
1367
|
### Supported operations
|
|
1361
1368
|
|
|
1362
|
-
|
|
1369
|
+
Manual progressive SSE can be configured on Express GET read operations only:
|
|
1363
1370
|
|
|
1364
1371
|
- `findMany`
|
|
1365
1372
|
- `findUnique`
|
|
@@ -1371,6 +1378,15 @@ Progressive SSE can be configured on Express GET read operations only:
|
|
|
1371
1378
|
- `aggregate`
|
|
1372
1379
|
- `groupBy`
|
|
1373
1380
|
|
|
1381
|
+
Auto-include progressive SSE only supports single-record read operations:
|
|
1382
|
+
|
|
1383
|
+
- `findUnique`
|
|
1384
|
+
- `findUniqueOrThrow`
|
|
1385
|
+
- `findFirst`
|
|
1386
|
+
- `findFirstOrThrow`
|
|
1387
|
+
|
|
1388
|
+
If auto-include is configured on another operation, the router either falls back to single-result SSE or sends an SSE error depending on `fallback`.
|
|
1389
|
+
|
|
1374
1390
|
Write operations do not support progressive SSE.
|
|
1375
1391
|
|
|
1376
1392
|
### Event protocol
|
|
@@ -1407,9 +1423,11 @@ Error event:
|
|
|
1407
1423
|
{ "type": "error", "message": "Could not load progressive response" }
|
|
1408
1424
|
```
|
|
1409
1425
|
|
|
1410
|
-
The final `result.data` is the accumulated object built from all applied patches, unless a stage returns a stop result.
|
|
1426
|
+
The final `result.data` is the accumulated object built from all applied patches, unless a manual stage returns a stop result.
|
|
1411
1427
|
|
|
1412
|
-
###
|
|
1428
|
+
### Manual staged mode
|
|
1429
|
+
|
|
1430
|
+
Manual mode is selected when a progressive variant has a `stages` array. `mode: 'manual'` is optional.
|
|
1413
1431
|
|
|
1414
1432
|
Progressive config lives on an Express read operation. It is keyed by the resolved variant.
|
|
1415
1433
|
|
|
@@ -1453,17 +1471,6 @@ const dashboardProfileBasics: ProgressiveStage<{ userId: string }> = async ({
|
|
|
1453
1471
|
location: true,
|
|
1454
1472
|
skills: true,
|
|
1455
1473
|
isAvailableForHire: true,
|
|
1456
|
-
_count: {
|
|
1457
|
-
select: {
|
|
1458
|
-
profileViews: true,
|
|
1459
|
-
savedAt: true,
|
|
1460
|
-
},
|
|
1461
|
-
},
|
|
1462
|
-
boost: {
|
|
1463
|
-
select: {
|
|
1464
|
-
boostedUntil: true,
|
|
1465
|
-
},
|
|
1466
|
-
},
|
|
1467
1474
|
},
|
|
1468
1475
|
},
|
|
1469
1476
|
},
|
|
@@ -1477,10 +1484,6 @@ const dashboardProfileBasics: ProgressiveStage<{ userId: string }> = async ({
|
|
|
1477
1484
|
...user.profile,
|
|
1478
1485
|
appliedTo: [],
|
|
1479
1486
|
invitationsFor: [],
|
|
1480
|
-
jobAdViews: [],
|
|
1481
|
-
campaign_clicks: [],
|
|
1482
|
-
jobAssignments: [],
|
|
1483
|
-
resourceOfCompanyTalentRoster: [],
|
|
1484
1487
|
}
|
|
1485
1488
|
: null,
|
|
1486
1489
|
}
|
|
@@ -1503,8 +1506,6 @@ const dashboardApplications: ProgressiveStage<{ userId: string }> = async ({
|
|
|
1503
1506
|
id: true,
|
|
1504
1507
|
createdAt: true,
|
|
1505
1508
|
viewedAt: true,
|
|
1506
|
-
details: true,
|
|
1507
|
-
jobAd: true,
|
|
1508
1509
|
},
|
|
1509
1510
|
},
|
|
1510
1511
|
},
|
|
@@ -1552,7 +1553,7 @@ const userConfig = {
|
|
|
1552
1553
|
app.use('/', UserRouter(userConfig))
|
|
1553
1554
|
```
|
|
1554
1555
|
|
|
1555
|
-
`resolveContext` is required for a variant with `progressive.enabled !== false`. It is not required for ordinary JSON requests or
|
|
1556
|
+
`resolveContext` is required for a manual progressive variant with `progressive.enabled !== false`. It is not required for ordinary JSON requests, auto-include mode, or single-result SSE fallback.
|
|
1556
1557
|
|
|
1557
1558
|
### Stage function API
|
|
1558
1559
|
|
|
@@ -1616,16 +1617,129 @@ return {
|
|
|
1616
1617
|
|
|
1617
1618
|
Patch path segments `__proto__`, `constructor`, `prototype`, and empty path segments are rejected.
|
|
1618
1619
|
|
|
1620
|
+
### Auto-include mode
|
|
1621
|
+
|
|
1622
|
+
Auto-include mode is selected with `mode: 'autoInclude'`.
|
|
1623
|
+
|
|
1624
|
+
```ts
|
|
1625
|
+
const userConfig = {
|
|
1626
|
+
guard: {
|
|
1627
|
+
variantHeader: 'x-api-variant',
|
|
1628
|
+
},
|
|
1629
|
+
|
|
1630
|
+
findUnique: {
|
|
1631
|
+
progressive: {
|
|
1632
|
+
detail: {
|
|
1633
|
+
enabled: true,
|
|
1634
|
+
mode: 'autoInclude',
|
|
1635
|
+
fallback: 'singleResult',
|
|
1636
|
+
},
|
|
1637
|
+
},
|
|
1638
|
+
},
|
|
1639
|
+
}
|
|
1640
|
+
|
|
1641
|
+
app.use('/', UserRouter(userConfig))
|
|
1642
|
+
```
|
|
1643
|
+
|
|
1644
|
+
Client request:
|
|
1645
|
+
|
|
1646
|
+
```ts
|
|
1647
|
+
import { encodeQueryParams } from './generated/client/encodeQueryParams'
|
|
1648
|
+
|
|
1649
|
+
const params = encodeQueryParams({
|
|
1650
|
+
where: { id: 'user-id' },
|
|
1651
|
+
include: {
|
|
1652
|
+
profile: {
|
|
1653
|
+
select: {
|
|
1654
|
+
id: true,
|
|
1655
|
+
displayName: true,
|
|
1656
|
+
},
|
|
1657
|
+
},
|
|
1658
|
+
posts: {
|
|
1659
|
+
orderBy: { createdAt: 'desc' },
|
|
1660
|
+
take: 10,
|
|
1661
|
+
select: {
|
|
1662
|
+
id: true,
|
|
1663
|
+
title: true,
|
|
1664
|
+
},
|
|
1665
|
+
},
|
|
1666
|
+
},
|
|
1667
|
+
})
|
|
1668
|
+
|
|
1669
|
+
const response = await fetch(`/user/unique?${params}`, {
|
|
1670
|
+
headers: {
|
|
1671
|
+
Accept: 'text/event-stream',
|
|
1672
|
+
'x-api-variant': 'detail',
|
|
1673
|
+
},
|
|
1674
|
+
})
|
|
1675
|
+
```
|
|
1676
|
+
|
|
1677
|
+
Auto-include sends root scalar fields first, then sends relation field events as separate relation queries finish:
|
|
1678
|
+
|
|
1679
|
+
```json
|
|
1680
|
+
{ "type": "field", "key": "id", "value": "user-id" }
|
|
1681
|
+
```
|
|
1682
|
+
|
|
1683
|
+
```json
|
|
1684
|
+
{ "type": "field", "key": "profile", "value": { "id": "profile-id", "displayName": "Alice" } }
|
|
1685
|
+
```
|
|
1686
|
+
|
|
1687
|
+
```json
|
|
1688
|
+
{ "type": "field", "key": "posts", "value": [{ "id": "post-id", "title": "Hello" }] }
|
|
1689
|
+
```
|
|
1690
|
+
|
|
1691
|
+
The final `result` event contains the assembled object.
|
|
1692
|
+
|
|
1693
|
+
### Auto-include behavior and limits
|
|
1694
|
+
|
|
1695
|
+
Auto-include is designed for supported Prisma `include` and relation `select` trees on single-record reads.
|
|
1696
|
+
|
|
1697
|
+
Supported root operations:
|
|
1698
|
+
|
|
1699
|
+
- `findUnique`
|
|
1700
|
+
- `findUniqueOrThrow`
|
|
1701
|
+
- `findFirst`
|
|
1702
|
+
- `findFirstOrThrow`
|
|
1703
|
+
|
|
1704
|
+
Supported relation shapes:
|
|
1705
|
+
|
|
1706
|
+
- direct to-one relation includes/selects
|
|
1707
|
+
- direct to-many relation includes/selects
|
|
1708
|
+
- to-many relation args such as `where`, `orderBy`, `take`, `skip`, `cursor`, and `distinct`
|
|
1709
|
+
- nested to-one relation loading through to-one parents
|
|
1710
|
+
|
|
1711
|
+
Current MVP fallback cases include:
|
|
1712
|
+
|
|
1713
|
+
- `_count` in `select` or `include`
|
|
1714
|
+
- implicit many-to-many relations
|
|
1715
|
+
- `select` and `include` at the same level
|
|
1716
|
+
- `select` and `omit` at the same level
|
|
1717
|
+
- relation filters/order/cursor in the root query
|
|
1718
|
+
- relation filters/order/cursor inside staged relation queries when unsupported
|
|
1719
|
+
- nested relation loading through a to-many parent
|
|
1720
|
+
- omitted required link fields needed to stitch parent and child records
|
|
1721
|
+
- planner limits for maximum depth or stage count
|
|
1722
|
+
|
|
1723
|
+
When fallback happens:
|
|
1724
|
+
|
|
1725
|
+
- `fallback: 'singleResult'` runs the normal Prisma read and returns one SSE `result` event
|
|
1726
|
+
- `fallback: 'error'` sends an SSE `error` event instead
|
|
1727
|
+
|
|
1728
|
+
If `fallback` is omitted, the default behavior is equivalent to `'singleResult'`.
|
|
1729
|
+
|
|
1730
|
+
Auto-include does not require `resolveContext` or `progressiveStages`.
|
|
1731
|
+
|
|
1619
1732
|
### Hooks and guard behavior
|
|
1620
1733
|
|
|
1621
1734
|
For SSE requests:
|
|
1622
1735
|
|
|
1623
1736
|
- `before` hooks run before streaming starts
|
|
1624
1737
|
- `after` hooks do not run, because the SSE middleware handles the response and does not continue to the normal handler
|
|
1625
|
-
- progressive stages receive `req.prisma` directly
|
|
1626
|
-
-
|
|
1738
|
+
- manual progressive stages receive `req.prisma` directly
|
|
1739
|
+
- manual progressive stages do not automatically use guard shapes
|
|
1740
|
+
- auto-include mode does not run when an operation has a guard `shape`; it falls back to single-result SSE or emits an SSE error depending on `fallback`
|
|
1627
1741
|
|
|
1628
|
-
|
|
1742
|
+
Manual stage authors are responsible for using the resolved context and enforcing ownership or tenant constraints in their stage queries.
|
|
1629
1743
|
|
|
1630
1744
|
For variants without progressive config, the single-result SSE fallback uses the normal generated core read handler, so guard shape behavior matches the JSON endpoint.
|
|
1631
1745
|
|
|
@@ -2134,11 +2248,22 @@ interface ReadOperationConfig<TCtx = unknown> extends OperationConfig {
|
|
|
2134
2248
|
progressiveStages?: Record<string, ProgressiveStage<TCtx>>
|
|
2135
2249
|
}
|
|
2136
2250
|
|
|
2137
|
-
type
|
|
2251
|
+
type ManualProgressiveVariantConfig = {
|
|
2138
2252
|
enabled?: boolean
|
|
2253
|
+
mode?: 'manual'
|
|
2139
2254
|
stages: string[]
|
|
2140
2255
|
}
|
|
2141
2256
|
|
|
2257
|
+
type AutoIncludeProgressiveVariantConfig = {
|
|
2258
|
+
enabled?: boolean
|
|
2259
|
+
mode: 'autoInclude'
|
|
2260
|
+
fallback?: 'singleResult' | 'error'
|
|
2261
|
+
}
|
|
2262
|
+
|
|
2263
|
+
type ProgressiveVariantConfig =
|
|
2264
|
+
| ManualProgressiveVariantConfig
|
|
2265
|
+
| AutoIncludeProgressiveVariantConfig
|
|
2266
|
+
|
|
2142
2267
|
type ProgressiveStageContext<TContext = unknown, TPrisma = any> = {
|
|
2143
2268
|
ctx: TContext
|
|
2144
2269
|
req: Request
|
|
@@ -21,6 +21,10 @@ const encodeQueryParams = (params) => {
|
|
|
21
21
|
entries.push(`${encodeURIComponent(key)}=${encodeURIComponent(value.toString())}`);
|
|
22
22
|
continue;
|
|
23
23
|
}
|
|
24
|
+
if (typeof value === 'string') {
|
|
25
|
+
entries.push(`${encodeURIComponent(key)}=${encodeURIComponent(JSON.stringify(value))}`);
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
24
28
|
if (Array.isArray(value) || (0, misc_1.isObject)(value)) {
|
|
25
29
|
entries.push(`${encodeURIComponent(key)}=${encodeURIComponent(JSON.stringify(value, replacer))}`);
|
|
26
30
|
continue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encodeQueryParams.js","sourceRoot":"","sources":["../../src/client/encodeQueryParams.ts"],"names":[],"mappings":";;;AAAA,uCAAuC;
|
|
1
|
+
{"version":3,"file":"encodeQueryParams.js","sourceRoot":"","sources":["../../src/client/encodeQueryParams.ts"],"names":[],"mappings":";;;AAAA,uCAAuC;AAEvC,SAAS,QAAQ,CAAC,IAAY,EAAE,KAAc;IAC5C,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK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MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAClE,CAAA;IACH,CAAC;IAED,OAAO,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAC1B,CAAC,CAAA;AAtCY,QAAA,iBAAiB,qBAsC7B"}
|
package/dist/copy/misc.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
export declare function isJsonString(str: string | unknown): boolean;
|
|
2
|
-
export declare function safeJSONparse<T>(data: unknown): T | boolean | undefined | null;
|
|
3
1
|
export declare const isObject: (value: unknown) => value is Record<string, unknown>;
|
|
2
|
+
export declare function isPlainObject(value: unknown): value is Record<string, unknown>;
|
|
4
3
|
export declare function isSafeKey(key: string): boolean;
|
|
5
4
|
export declare function sanitizeKeys<T>(value: T): T;
|
|
5
|
+
export declare function normalizePrefix(p: string): string;
|
|
6
|
+
export declare function removeTrailingSlash(path: string): string;
|
|
7
|
+
export declare function getEnv(): Record<string, string | undefined>;
|
package/dist/copy/misc.js
CHANGED
|
@@ -1,35 +1,24 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isObject = void 0;
|
|
4
|
-
exports.
|
|
5
|
-
exports.safeJSONparse = safeJSONparse;
|
|
4
|
+
exports.isPlainObject = isPlainObject;
|
|
6
5
|
exports.isSafeKey = isSafeKey;
|
|
7
6
|
exports.sanitizeKeys = sanitizeKeys;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
try {
|
|
13
|
-
JSON.parse(str);
|
|
14
|
-
}
|
|
15
|
-
catch (e) {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
return true;
|
|
19
|
-
}
|
|
20
|
-
function safeJSONparse(data) {
|
|
21
|
-
if (data === 'false')
|
|
22
|
-
return false;
|
|
23
|
-
if (data === 'undefined')
|
|
24
|
-
return undefined;
|
|
25
|
-
if (data === 'null')
|
|
26
|
-
return null;
|
|
27
|
-
return isJsonString(data) ? JSON.parse(data) : data;
|
|
28
|
-
}
|
|
7
|
+
exports.normalizePrefix = normalizePrefix;
|
|
8
|
+
exports.removeTrailingSlash = removeTrailingSlash;
|
|
9
|
+
exports.getEnv = getEnv;
|
|
29
10
|
const isObject = (value) => {
|
|
30
11
|
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
31
12
|
};
|
|
32
13
|
exports.isObject = isObject;
|
|
14
|
+
function isPlainObject(value) {
|
|
15
|
+
if (value === null || typeof value !== 'object')
|
|
16
|
+
return false;
|
|
17
|
+
if (Array.isArray(value))
|
|
18
|
+
return false;
|
|
19
|
+
const proto = Object.getPrototypeOf(value);
|
|
20
|
+
return proto === Object.prototype || proto === null;
|
|
21
|
+
}
|
|
33
22
|
const UNSAFE_KEYS = new Set(['__proto__', 'constructor', 'prototype']);
|
|
34
23
|
function isSafeKey(key) {
|
|
35
24
|
return !UNSAFE_KEYS.has(key);
|
|
@@ -38,7 +27,7 @@ function sanitizeKeys(value) {
|
|
|
38
27
|
if (Array.isArray(value)) {
|
|
39
28
|
return value.map(sanitizeKeys);
|
|
40
29
|
}
|
|
41
|
-
if ((
|
|
30
|
+
if (isPlainObject(value)) {
|
|
42
31
|
const result = {};
|
|
43
32
|
for (const key of Object.keys(value)) {
|
|
44
33
|
if (!isSafeKey(key))
|
|
@@ -49,4 +38,26 @@ function sanitizeKeys(value) {
|
|
|
49
38
|
}
|
|
50
39
|
return value;
|
|
51
40
|
}
|
|
41
|
+
function normalizePrefix(p) {
|
|
42
|
+
if (!p)
|
|
43
|
+
return '';
|
|
44
|
+
let result = p;
|
|
45
|
+
if (!result.startsWith('/'))
|
|
46
|
+
result = '/' + result;
|
|
47
|
+
while (result.length > 1 && result.endsWith('/'))
|
|
48
|
+
result = result.slice(0, -1);
|
|
49
|
+
if (result === '/')
|
|
50
|
+
return '';
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
function removeTrailingSlash(path) {
|
|
54
|
+
if (path === '/')
|
|
55
|
+
return '';
|
|
56
|
+
return path.endsWith('/') ? path.slice(0, -1) : path;
|
|
57
|
+
}
|
|
58
|
+
function getEnv() {
|
|
59
|
+
return typeof process !== 'undefined' && process.env
|
|
60
|
+
? process.env
|
|
61
|
+
: {};
|
|
62
|
+
}
|
|
52
63
|
//# sourceMappingURL=misc.js.map
|
package/dist/copy/misc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"misc.js","sourceRoot":"","sources":["../../src/copy/misc.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"misc.js","sourceRoot":"","sources":["../../src/copy/misc.ts"],"names":[],"mappings":";;;AAIA,sCAKC;AAID,8BAEC;AAED,oCAaC;AAED,0CAOC;AAED,kDAGC;AAED,wBAIC;AAlDM,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAoC,EAAE;IAC3E,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;AAC7E,CAAC,CAAA;AAFY,QAAA,QAAQ,YAEpB;AAED,SAAgB,aAAa,CAAC,KAAc;IAC1C,IAAI,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAA;IAC7D,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAA;IACtC,MAAM,KAAK,GAAG,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAA;IAC1C,OAAO,KAAK,KAAK,MAAM,CAAC,SAAS,IAAI,KAAK,KAAK,IAAI,CAAA;AACrD,CAAC;AAED,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,aAAa,EAAE,WAAW,CAAC,CAAC,CAAA;AAEtE,SAAgB,SAAS,CAAC,GAAW;IACnC,OAAO,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC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C,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;AACtD,CAAC;AAED,SAAgB,MAAM;IACpB,OAAO,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,CAAC,GAAG;QAClD,CAAC,CAAC,OAAO,CAAC,GAAG;QACb,CAAC,CAAE,EAAyC,CAAA;AAChD,CAAC"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateFastifyHandler = generateFastifyHandler;
|
|
4
|
-
const strings_1 = require("../utils/strings");
|
|
5
4
|
const importExt_1 = require("../utils/importExt");
|
|
6
5
|
const CORE_NAME_MAP = {
|
|
7
6
|
delete: 'deleteUnique',
|
|
@@ -39,9 +38,8 @@ const CREATED_OPS = new Set([
|
|
|
39
38
|
function generateFastifyHandler(options) {
|
|
40
39
|
const ext = (0, importExt_1.importExt)(options.importStyle);
|
|
41
40
|
const modelName = options.model.name;
|
|
42
|
-
const prefix = (0, strings_1.toCamelCase)(modelName);
|
|
43
41
|
const readHandlers = READ_OPS.map((op) => {
|
|
44
|
-
const exportName = `${
|
|
42
|
+
const exportName = `${modelName}${op.charAt(0).toUpperCase() + op.slice(1)}`;
|
|
45
43
|
return `
|
|
46
44
|
export async function ${exportName}(
|
|
47
45
|
request: FastifyRequest,
|
|
@@ -52,7 +50,7 @@ export async function ${exportName}(
|
|
|
52
50
|
}`;
|
|
53
51
|
}).join('\n');
|
|
54
52
|
const writeHandlers = WRITE_OPS.map((op) => {
|
|
55
|
-
const exportName = `${
|
|
53
|
+
const exportName = `${modelName}${op.charAt(0).toUpperCase() + op.slice(1)}`;
|
|
56
54
|
const statusCode = CREATED_OPS.has(op) ? 201 : 200;
|
|
57
55
|
return `
|
|
58
56
|
export async function ${exportName}(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateFastifyHandler.js","sourceRoot":"","sources":["../../src/generators/generateFastifyHandler.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"generateFastifyHandler.js","sourceRoot":"","sources":["../../src/generators/generateFastifyHandler.ts"],"names":[],"mappings":";;AA0CA,wDAmEC;AA3GD,kDAA8C;AAE9C,MAAM,aAAa,GAA2B;IAC5C,MAAM,EAAE,cAAc;CACvB,CAAA;AAED,SAAS,UAAU,CAAC,EAAU;IAC5B,OAAO,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,CAAA;AAChC,CAAC;AAED,MAAM,QAAQ,GAAG;IACf,UAAU;IACV,WAAW;IACX,kBAAkB;IAClB,YAAY;IACZ,mBAAmB;IACnB,mBAAmB;IACnB,WAAW;IACX,OAAO;IACP,SAAS;CACV,CAAA;AAED,MAAM,SAAS,GAAG;IAChB,QAAQ;IACR,YAAY;IACZ,qBAAqB;IACrB,QAAQ;IACR,YAAY;IACZ,qBAAqB;IACrB,QAAQ;IACR,QAAQ;IACR,YAAY;CACb,CAAA;AAED,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC;IAC1B,QAAQ;IACR,YAAY;IACZ,qBAAqB;CACtB,CAAC,CAAA;AAEF,SAAgB,sBAAsB,CAAC,OAGtC;IACC,MAAM,GAAG,GAAG,IAAA,qBAAS,EAAC,OAAO,CAAC,WAAW,CAAC,CAAA;IAC1C,MAAM,SAAS,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAA;IAEpC,MAAM,YAAY,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE;QACvC,MAAM,UAAU,GAAG,GAAG,SAAS,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAA;QAC5E,OAAO;wBACa,UAAU;;;;4BAIN,UAAU,CAAC,EAAE,CAAC;;EAExC,CAAA;IACA,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAEb,MAAM,aAAa,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE;QACzC,MAAM,UAAU,GAAG,GAAG,SAAS,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAA;QAC5E,MAAM,UAAU,GAAG,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAA;QAElD,OAAO;wBACa,UAAU;;;;4BAIN,UAAU,CAAC,EAAE,CAAC;;;uBAGnB,UAAU;EAC/B,CAAA;IACA,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAEb,OAAO;2BACkB,SAAS,OAAO,GAAG;4DACc,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2B7D,YAAY;EACZ,aAAa;CACd,CAAA;AACD,CAAC"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateHonoHandler = generateHonoHandler;
|
|
4
|
-
const strings_1 = require("../utils/strings");
|
|
5
4
|
const importExt_1 = require("../utils/importExt");
|
|
6
5
|
const CORE_NAME_MAP = {
|
|
7
6
|
delete: 'deleteUnique',
|
|
@@ -39,9 +38,8 @@ const CREATED_OPS = new Set([
|
|
|
39
38
|
function generateHonoHandler(options) {
|
|
40
39
|
const ext = (0, importExt_1.importExt)(options.importStyle);
|
|
41
40
|
const modelName = options.model.name;
|
|
42
|
-
const prefix = (0, strings_1.toCamelCase)(modelName);
|
|
43
41
|
const readHandlers = READ_OPS.map((op) => {
|
|
44
|
-
const exportName = `${
|
|
42
|
+
const exportName = `${modelName}${op.charAt(0).toUpperCase() + op.slice(1)}`;
|
|
45
43
|
return `
|
|
46
44
|
export async function ${exportName}(c: Context<HonoEnv>): Promise<void> {
|
|
47
45
|
const data = await core.${coreFnName(op)}(buildContext(c))
|
|
@@ -49,7 +47,7 @@ export async function ${exportName}(c: Context<HonoEnv>): Promise<void> {
|
|
|
49
47
|
}`;
|
|
50
48
|
}).join('\n');
|
|
51
49
|
const writeHandlers = WRITE_OPS.map((op) => {
|
|
52
|
-
const exportName = `${
|
|
50
|
+
const exportName = `${modelName}${op.charAt(0).toUpperCase() + op.slice(1)}`;
|
|
53
51
|
const statusCode = CREATED_OPS.has(op) ? 201 : 200;
|
|
54
52
|
return `
|
|
55
53
|
export async function ${exportName}(c: Context<HonoEnv>): Promise<void> {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateHonoHandler.js","sourceRoot":"","sources":["../../src/generators/generateHonoHandler.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"generateHonoHandler.js","sourceRoot":"","sources":["../../src/generators/generateHonoHandler.ts"],"names":[],"mappings":";;AA0CA,kDA8DC;AAtGD,kDAA8C;AAE9C,MAAM,aAAa,GAA2B;IAC5C,MAAM,EAAE,cAAc;CACvB,CAAA;AAED,SAAS,UAAU,CAAC,EAAU;IAC5B,OAAO,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,CAAA;AAChC,CAAC;AAED,MAAM,QAAQ,GAAG;IACf,UAAU;IACV,WAAW;IACX,kBAAkB;IAClB,YAAY;IACZ,mBAAmB;IACnB,mBAAmB;IACnB,WAAW;IACX,OAAO;IACP,SAAS;CACV,CAAA;AAED,MAAM,SAAS,GAAG;IAChB,QAAQ;IACR,YAAY;IACZ,qBAAqB;IACrB,QAAQ;IACR,YAAY;IACZ,qBAAqB;IACrB,QAAQ;IACR,QAAQ;IACR,YAAY;CACb,CAAA;AAED,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC;IAC1B,QAAQ;IACR,YAAY;IACZ,qBAAqB;CACtB,CAAC,CAAA;AAEF,SAAgB,mBAAmB,CAAC,OAGnC;IACC,MAAM,GAAG,GAAG,IAAA,qBAAS,EAAC,OAAO,CAAC,WAAW,CAAC,CAAA;IAC1C,MAAM,SAAS,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAA;IAEpC,MAAM,YAAY,GAAG,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE;QACvC,MAAM,UAAU,GAAG,GAAG,SAAS,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAA;QAC5E,OAAO;wBACa,UAAU;4BACN,UAAU,CAAC,EAAE,CAAC;;EAExC,CAAA;IACA,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAEb,MAAM,aAAa,GAAG,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE;QACzC,MAAM,UAAU,GAAG,GAAG,SAAS,GAAG,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAA;QAC5E,MAAM,UAAU,GAAG,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAA;QAElD,OAAO;wBACa,UAAU;4BACN,UAAU,CAAC,EAAE,CAAC;;0BAEhB,UAAU;EAClC,CAAA;IACA,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAEb,OAAO;2BACkB,SAAS,OAAO,GAAG;4DACc,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA6B7D,YAAY;EACZ,aAAa;CACd,CAAA;AACD,CAAC"}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import { GeneratorOptions } from '@prisma/generator-helper';
|
|
2
|
-
export declare function generateImportPrismaStatement(generatorOptions: GeneratorOptions): string;
|
|
3
2
|
export declare function getRelativeClientPath(generatorOptions: GeneratorOptions, modelName: string): string;
|
|
4
3
|
export declare function getGuardShapesImport(options: GeneratorOptions, modelName: string): string | null;
|
|
@@ -3,7 +3,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.generateImportPrismaStatement = generateImportPrismaStatement;
|
|
7
6
|
exports.getRelativeClientPath = getRelativeClientPath;
|
|
8
7
|
exports.getGuardShapesImport = getGuardShapesImport;
|
|
9
8
|
const path_1 = __importDefault(require("path"));
|
|
@@ -14,11 +13,7 @@ function findClientGenerator(options) {
|
|
|
14
13
|
const byProvider = options.otherGenerators.find((gen) => gen.provider.value === 'prisma-client-js' ||
|
|
15
14
|
gen.provider.value === '@prisma/client' ||
|
|
16
15
|
gen.provider.value === 'prisma-client');
|
|
17
|
-
|
|
18
|
-
return byProvider;
|
|
19
|
-
const withOutput = options.otherGenerators.find((gen) => gen.output?.value?.includes('prisma') ||
|
|
20
|
-
gen.output?.value?.includes('client'));
|
|
21
|
-
return withOutput || null;
|
|
16
|
+
return byProvider || null;
|
|
22
17
|
}
|
|
23
18
|
function getRelativeImportPath(fromDir, clientOutputPath) {
|
|
24
19
|
let relativeImportPath = path_1.default.relative(fromDir, clientOutputPath);
|
|
@@ -28,23 +23,10 @@ function getRelativeImportPath(fromDir, clientOutputPath) {
|
|
|
28
23
|
}
|
|
29
24
|
return relativeImportPath;
|
|
30
25
|
}
|
|
31
|
-
function generateImportPrismaStatement(generatorOptions) {
|
|
32
|
-
const clientGenerator = findClientGenerator(generatorOptions);
|
|
33
|
-
if (!clientGenerator || !clientGenerator.output?.value) {
|
|
34
|
-
throw new Error('Prisma client generator not found. Ensure a generator with provider "prisma-client-js" exists in your schema.');
|
|
35
|
-
}
|
|
36
|
-
const outputValue = generatorOptions.generator.output?.value;
|
|
37
|
-
if (!outputValue) {
|
|
38
|
-
throw new Error('Generator output path not defined.');
|
|
39
|
-
}
|
|
40
|
-
const subDir = path_1.default.join(outputValue, '_relative');
|
|
41
|
-
const outputPath = getRelativeImportPath(subDir, clientGenerator.output.value);
|
|
42
|
-
return `import { Prisma, PrismaClient } from '${outputPath}';\n`;
|
|
43
|
-
}
|
|
44
26
|
function getRelativeClientPath(generatorOptions, modelName) {
|
|
45
27
|
const clientGenerator = findClientGenerator(generatorOptions);
|
|
46
28
|
if (!clientGenerator || !clientGenerator.output?.value) {
|
|
47
|
-
throw new Error('Prisma client generator not found. Ensure a generator with provider
|
|
29
|
+
throw new Error('Prisma client generator not found. Ensure a generator block exists with name "client" or provider one of: prisma-client-js, @prisma/client, prisma-client.');
|
|
48
30
|
}
|
|
49
31
|
const outputValue = generatorOptions.generator.output?.value;
|
|
50
32
|
if (!outputValue) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateImportPrismaStatement.js","sourceRoot":"","sources":["../../src/generators/generateImportPrismaStatement.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"generateImportPrismaStatement.js","sourceRoot":"","sources":["../../src/generators/generateImportPrismaStatement.ts"],"names":[],"mappings":";;;;;AAyBA,sDAoBC;AAmBD,oDAeC;AA9ED,gDAAuB;AAEvB,SAAS,mBAAmB,CAAC,OAAyB;IACpD,MAAM,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAA;IAC3E,IAAI,MAAM;QAAE,OAAO,MAAM,CAAA;IAEzB,MAAM,UAAU,GAAG,OAAO,CAAC,eAAe,CAAC,IAAI,CAC7C,CAAC,GAAG,EAAE,EAAE,CACN,GAAG,CAAC,QAAQ,CAAC,KAAK,KAAK,kBAAkB;QACzC,GAAG,CAAC,QAAQ,CAAC,KAAK,KAAK,gBAAgB;QACvC,GAAG,CAAC,QAAQ,CAAC,KAAK,KAAK,eAAe,CACzC,CAAA;IACD,OAAO,UAAU,IAAI,IAAI,C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CAAC,KAAK,CAAC,QAAQ,CAAC,cAAc,CAAC,CACvE,CAAA;IACD,IAAI,UAAU;QAAE,OAAO,UAAU,CAAA;IAEjC,MAAM,QAAQ,GAAG,OAAO,CAAC,eAAe,CAAC,IAAI,CAC3C,CAAC,GAAG,EAAE,EAAE,CACN,CAAC,CAAC,GAAG,CAAC,MAAM;QACZ,CAAC,kBAAkB,IAAI,GAAG,CAAC,MAAM;YAC/B,cAAc,IAAI,GAAG,CAAC,MAAM;YAC5B,gBAAgB,IAAI,GAAG,CAAC,MAAM,CAAC,CACpC,CAAA;IACD,OAAO,QAAQ,IAAI,IAAI,CAAA;AACzB,CAAC;AAED,SAAgB,oBAAoB,CAClC,OAAyB,EACzB,SAAiB;IAEjB,MAAM,KAAK,GAAG,kBAAkB,CAAC,OAAO,CAAC,CAAA;IACzC,IAAI,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK;QAAE,OAAO,IAAI,CAAA;IAE/C,IAAI,KAAK,CAAC,MAAM,EAAE,gBAAgB,KAAK,OAAO;QAAE,OAAO,IAAI,CAAA;IAE3D,MAAM,WAAW,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,EAAE,KAAK,CAAA;IACnD,IAAI,CAAC,WAAW;QAAE,OAAO,IAAI,CAAA;IAE7B,MAAM,OAAO,GAAG,cAAI,CAAC,IAAI,CAAC,WAAW,EAAE,SAAS,CAAC,CAAA;IACjD,MAAM,UAAU,GAAG,cAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;IAC1D,OAAO,qBAAqB,CAAC,OAAO,EAAE,UAAU,CAAC,CAAA;AACnD,CAAC"}
|
|
@@ -113,7 +113,7 @@ export async function findManyPaginated(
|
|
|
113
113
|
total = txResult.t
|
|
114
114
|
} catch (txError: unknown) {
|
|
115
115
|
const txe = txError as { message?: string; code?: string }
|
|
116
|
-
if (
|
|
116
|
+
if (txe?.code === 'P2028') {
|
|
117
117
|
console.warn('[prisma-generator-express] Interactive transactions not available, pagination queries are non-atomic')
|
|
118
118
|
items = (await delegate.findMany(query)) as unknown[]
|
|
119
119
|
total = await countForPagination(delegate, query, undefined, undefined, distinctCountLimit)
|
|
@@ -86,6 +86,15 @@ function doStart(options: QueryBuilderOptions): Promise<void> {
|
|
|
86
86
|
return
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
+
const schemaByteLength = Buffer.byteLength(schemaContent, 'utf8')
|
|
90
|
+
if (schemaByteLength > 28000) {
|
|
91
|
+
console.warn(
|
|
92
|
+
'[query-builder] Schema size is ' + schemaByteLength + ' bytes. ' +
|
|
93
|
+
'Environment variable size limits may cause spawn failure on Windows (~32KB). ' +
|
|
94
|
+
'If the query builder fails to start, this is the likely cause.',
|
|
95
|
+
)
|
|
96
|
+
}
|
|
97
|
+
|
|
89
98
|
const schemaCwd = dirname(resolve(schemaPath))
|
|
90
99
|
|
|
91
100
|
_process = spawn(process.execPath, [cliPath], {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateQueryBuilderHelper.js","sourceRoot":"","sources":["../../src/generators/generateQueryBuilderHelper.ts"],"names":[],"mappings":";;AAEA,
|
|
1
|
+
{"version":3,"file":"generateQueryBuilderHelper.js","sourceRoot":"","sources":["../../src/generators/generateQueryBuilderHelper.ts"],"names":[],"mappings":";;AAEA,gEAgKC;AAhKD,SAAgB,0BAA0B,CAAC,OAAyB;IAClE,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU;QACnC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC;QACpC,CAAC,CAAC,gEAAgE,CAAA;IAEpE,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;+CA+DsC,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2FxD,CAAA;AACD,CAAC"}
|
|
@@ -57,7 +57,6 @@ function computeRelation(field, selfModelName, models) {
|
|
|
57
57
|
}
|
|
58
58
|
function buildModelMeta(model, models) {
|
|
59
59
|
const scalarFields = [];
|
|
60
|
-
const idFields = [];
|
|
61
60
|
const relations = {};
|
|
62
61
|
for (const field of model.fields) {
|
|
63
62
|
if (field.kind === 'object') {
|
|
@@ -65,21 +64,12 @@ function buildModelMeta(model, models) {
|
|
|
65
64
|
}
|
|
66
65
|
else if (field.kind === 'scalar' || field.kind === 'enum') {
|
|
67
66
|
scalarFields.push(field.name);
|
|
68
|
-
if (field.isId)
|
|
69
|
-
idFields.push(field.name);
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
if (model.primaryKey && Array.isArray(model.primaryKey.fields)) {
|
|
73
|
-
for (const f of model.primaryKey.fields) {
|
|
74
|
-
if (!idFields.includes(f))
|
|
75
|
-
idFields.push(f);
|
|
76
67
|
}
|
|
77
68
|
}
|
|
78
69
|
return {
|
|
79
70
|
name: model.name,
|
|
80
71
|
delegateKey: model.name.charAt(0).toLowerCase() + model.name.slice(1),
|
|
81
72
|
scalarFields,
|
|
82
|
-
idFields,
|
|
83
73
|
relations,
|
|
84
74
|
};
|
|
85
75
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateRelationMeta.js","sourceRoot":"","sources":["../../src/generators/generateRelationMeta.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"generateRelationMeta.js","sourceRoot":"","sources":["../../src/generators/generateRelationMeta.ts"],"names":[],"mappings":";;AAwHA,oDAOC;AAOD,kEAeC;AAnJD,kDAA8C;AAqB9C,SAAS,iBAAiB,CACxB,MAAiC,EACjC,eAAuB,EACvB,YAAgC,EAChC,aAAqB,EACrB,aAAqB;IAErB,IAAI,CAAC,YAAY;QAAE,OAAO,IAAI,CAAA;IAC9B,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,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