prisma-generator-express 1.59.0 → 1.60.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/dist/client/encodeQueryParams.js +19 -23
- package/dist/client/encodeQueryParams.js.map +1 -1
- package/dist/copy/operationDefinitions.d.ts +37 -0
- package/dist/copy/operationDefinitions.js +412 -0
- package/dist/copy/operationDefinitions.js.map +1 -0
- package/dist/generators/generateFastifyHandler.js +10 -41
- package/dist/generators/generateFastifyHandler.js.map +1 -1
- package/dist/generators/generateHonoHandler.js +10 -41
- package/dist/generators/generateHonoHandler.js.map +1 -1
- package/dist/generators/generateModelMetadata.d.ts +8 -0
- package/dist/generators/generateModelMetadata.js +77 -0
- package/dist/generators/generateModelMetadata.js.map +1 -0
- package/dist/generators/generateOperationCore.js +20 -30
- package/dist/generators/generateOperationCore.js.map +1 -1
- package/dist/generators/generateQueryBuilderHelper.js +1 -1
- package/dist/generators/generateQueryBuilderHelper.js.map +1 -1
- package/dist/generators/generateRouteConfigType.js +11 -57
- package/dist/generators/generateRouteConfigType.js.map +1 -1
- package/dist/generators/generateRouter.js +64 -177
- package/dist/generators/generateRouter.js.map +1 -1
- package/dist/generators/generateRouterFastify.js +59 -169
- package/dist/generators/generateRouterFastify.js.map +1 -1
- package/dist/generators/generateRouterHono.js +52 -152
- package/dist/generators/generateRouterHono.js.map +1 -1
- package/dist/generators/generateUnifiedHandler.js +7 -30
- package/dist/generators/generateUnifiedHandler.js.map +1 -1
- package/dist/generators/generateUnifiedScalarUI.js +9 -74
- package/dist/generators/generateUnifiedScalarUI.js.map +1 -1
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -1
- package/dist/utils/copyFiles.js +7 -0
- package/dist/utils/copyFiles.js.map +1 -1
- package/dist/utils/writeFileSafely.js +5 -12
- package/dist/utils/writeFileSafely.js.map +1 -1
- package/package.json +12 -2
- package/src/client/encodeQueryParams.ts +23 -36
- package/src/copy/autoIncludePlanner.ts +14 -23
- package/src/copy/autoIncludeRuntime.ts +117 -228
- package/src/copy/buildModelOpenApi.ts +248 -628
- package/src/copy/concurrency.ts +20 -0
- package/src/copy/docsRenderer.ts +63 -333
- package/src/copy/errorMapper.ts +126 -0
- package/src/copy/guardHelpers.ts +56 -0
- package/src/copy/materializedCount.ts +68 -0
- package/src/copy/materializedRouter.ts +33 -29
- package/src/copy/operationDefinitions.ts +359 -35
- package/src/copy/operationRuntime.ts +11 -605
- package/src/copy/pagination.ts +151 -0
- package/src/copy/scalarTypes.ts +2 -0
- package/src/copy/sse.ts +296 -0
- package/src/generators/generateFastifyHandler.ts +13 -47
- package/src/generators/generateHonoHandler.ts +13 -47
- package/src/generators/generateModelMetadata.ts +92 -0
- package/src/generators/generateOperationCore.ts +19 -32
- package/src/generators/generateQueryBuilderHelper.ts +1 -1
- package/src/generators/generateRouteConfigType.ts +9 -60
- package/src/generators/generateRouter.ts +88 -180
- package/src/generators/generateRouterFastify.ts +65 -172
- package/src/generators/generateRouterHono.ts +58 -155
- package/src/generators/generateUnifiedHandler.ts +8 -33
- package/src/generators/generateUnifiedScalarUI.ts +9 -91
- package/src/index.ts +13 -1
- package/src/utils/copyFiles.ts +7 -0
- package/src/utils/writeFileSafely.ts +5 -11
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"writeFileSafely.js","sourceRoot":"","sources":["../../src/utils/writeFileSafely.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBA,
|
|
1
|
+
{"version":3,"file":"writeFileSafely.js","sourceRoot":"","sources":["../../src/utils/writeFileSafely.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBA,0CAmCC;AAtDD,uCAAwB;AACxB,2CAA4B;AAC5B,wDAA+B;AAS/B,IAAI,gBAAqD,CAAA;AAEzD,KAAK,UAAU,kBAAkB;IAC/B,IAAI,gBAAgB,KAAK,SAAS;QAAE,OAAO,gBAAgB,C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AClD,MAAM,gBAAgB,GAAG,MAAM,kBAAQ,CAAC,MAAM,CAAC,OAAO,EAAE;QACtD,GAAG,eAAe;QAClB,MAAM,EAAE,YAAY;KACrB,CAAC,CAAA;IAEF,EAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,gBAAgB,CAAC,CAAA;AAC9C,CAAC"}
|
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.
|
|
4
|
+
"version": "1.60.0",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"license": "MIT",
|
|
@@ -19,7 +19,8 @@
|
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@prisma/generator-helper": "7.5.0",
|
|
22
|
-
"prettier": "3.6.2"
|
|
22
|
+
"prettier": "3.6.2",
|
|
23
|
+
"yaml": "^2.9.0"
|
|
23
24
|
},
|
|
24
25
|
"peerDependencies": {
|
|
25
26
|
"@prisma/client": ">=6.0.0",
|
|
@@ -31,6 +32,15 @@
|
|
|
31
32
|
"prisma-sql": ">=1.0.0"
|
|
32
33
|
},
|
|
33
34
|
"peerDependenciesMeta": {
|
|
35
|
+
"express": {
|
|
36
|
+
"optional": true
|
|
37
|
+
},
|
|
38
|
+
"fastify": {
|
|
39
|
+
"optional": true
|
|
40
|
+
},
|
|
41
|
+
"hono": {
|
|
42
|
+
"optional": true
|
|
43
|
+
},
|
|
34
44
|
"prisma-guard": {
|
|
35
45
|
"optional": true
|
|
36
46
|
},
|
|
@@ -1,48 +1,35 @@
|
|
|
1
1
|
import { isObject } from '../copy/misc'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const bigintReplacer = (_key: string, value: unknown): unknown =>
|
|
4
|
+
typeof value === 'bigint' ? value.toString() : value
|
|
5
|
+
|
|
6
|
+
const encodeEntry = (key: string, value: unknown): string | null => {
|
|
7
|
+
if (value === undefined) return null
|
|
8
|
+
|
|
9
|
+
const encodedKey = encodeURIComponent(key)
|
|
10
|
+
|
|
11
|
+
if (value === null) return encodedKey + '=null'
|
|
12
|
+
|
|
4
13
|
if (typeof value === 'bigint') {
|
|
5
|
-
return value.toString()
|
|
14
|
+
return encodedKey + '=' + encodeURIComponent(value.toString())
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (typeof value === 'string') {
|
|
18
|
+
return encodedKey + '=' + encodeURIComponent(JSON.stringify(value))
|
|
6
19
|
}
|
|
7
|
-
|
|
20
|
+
|
|
21
|
+
if (Array.isArray(value) || isObject(value)) {
|
|
22
|
+
return encodedKey + '=' + encodeURIComponent(JSON.stringify(value, bigintReplacer))
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return encodedKey + '=' + encodeURIComponent(String(value))
|
|
8
26
|
}
|
|
9
27
|
|
|
10
28
|
export const encodeQueryParams = (params: Record<string, unknown>): string => {
|
|
11
29
|
const entries: string[] = []
|
|
12
|
-
|
|
13
30
|
for (const [key, value] of Object.entries(params)) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
if (value === null) {
|
|
17
|
-
entries.push(`${encodeURIComponent(key)}=null`)
|
|
18
|
-
continue
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
if (typeof value === 'bigint') {
|
|
22
|
-
entries.push(
|
|
23
|
-
`${encodeURIComponent(key)}=${encodeURIComponent(value.toString())}`,
|
|
24
|
-
)
|
|
25
|
-
continue
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
if (typeof value === 'string') {
|
|
29
|
-
entries.push(
|
|
30
|
-
`${encodeURIComponent(key)}=${encodeURIComponent(JSON.stringify(value))}`,
|
|
31
|
-
)
|
|
32
|
-
continue
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (Array.isArray(value) || isObject(value)) {
|
|
36
|
-
entries.push(
|
|
37
|
-
`${encodeURIComponent(key)}=${encodeURIComponent(JSON.stringify(value, replacer))}`,
|
|
38
|
-
)
|
|
39
|
-
continue
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
entries.push(
|
|
43
|
-
`${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`,
|
|
44
|
-
)
|
|
31
|
+
const entry = encodeEntry(key, value)
|
|
32
|
+
if (entry !== null) entries.push(entry)
|
|
45
33
|
}
|
|
46
|
-
|
|
47
34
|
return entries.join('&')
|
|
48
35
|
}
|
|
@@ -64,15 +64,15 @@ function hasWhereLikeRelationReference(
|
|
|
64
64
|
args: Record<string, unknown>,
|
|
65
65
|
model: ModelRelationMap,
|
|
66
66
|
): boolean {
|
|
67
|
-
const
|
|
67
|
+
const hasRelationKeysInObj = (obj: unknown): boolean => {
|
|
68
68
|
if (!isPlainObject(obj)) return false
|
|
69
69
|
for (const key of Object.keys(obj)) {
|
|
70
70
|
if (model.relations[key]) return true
|
|
71
71
|
if (key === 'AND' || key === 'OR' || key === 'NOT') {
|
|
72
72
|
const sub = obj[key]
|
|
73
73
|
if (Array.isArray(sub)) {
|
|
74
|
-
for (const item of sub) if (
|
|
75
|
-
} else if (
|
|
74
|
+
for (const item of sub) if (hasRelationKeysInObj(item)) return true
|
|
75
|
+
} else if (hasRelationKeysInObj(sub)) {
|
|
76
76
|
return true
|
|
77
77
|
}
|
|
78
78
|
}
|
|
@@ -80,24 +80,22 @@ function hasWhereLikeRelationReference(
|
|
|
80
80
|
return false
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const obs = Array.isArray(args.orderBy) ? args.orderBy : [args.orderBy]
|
|
87
|
-
for (const ob of obs) {
|
|
83
|
+
const anyOrderByHasRelation = (v: unknown): boolean => {
|
|
84
|
+
const list = Array.isArray(v) ? v : [v]
|
|
85
|
+
for (const ob of list) {
|
|
88
86
|
if (!isPlainObject(ob)) continue
|
|
89
|
-
for (const key of Object.keys(ob))
|
|
90
|
-
if (model.relations[key]) return true
|
|
91
|
-
}
|
|
87
|
+
for (const key of Object.keys(ob)) if (model.relations[key]) return true
|
|
92
88
|
}
|
|
89
|
+
return false
|
|
93
90
|
}
|
|
94
91
|
|
|
92
|
+
if (hasRelationKeysInObj(args.where)) return true
|
|
93
|
+
if (args.orderBy && anyOrderByHasRelation(args.orderBy)) return true
|
|
95
94
|
if (isPlainObject(args.cursor)) {
|
|
96
95
|
for (const key of Object.keys(args.cursor)) {
|
|
97
96
|
if (model.relations[key]) return true
|
|
98
97
|
}
|
|
99
98
|
}
|
|
100
|
-
|
|
101
99
|
return false
|
|
102
100
|
}
|
|
103
101
|
|
|
@@ -246,11 +244,7 @@ function walk(
|
|
|
246
244
|
|
|
247
245
|
const relationPath = parentPath ? parentPath + '.' + branch.name : branch.name
|
|
248
246
|
|
|
249
|
-
const
|
|
250
|
-
for (const [k, v] of Object.entries(relationArgs)) {
|
|
251
|
-
if (k === 'select' || k === 'include' || k === 'omit') continue
|
|
252
|
-
stageArgs[k] = v
|
|
253
|
-
}
|
|
247
|
+
const { select: _s, include: _i, omit: _o, ...stageArgs } = relationArgs
|
|
254
248
|
|
|
255
249
|
const stageIndex = ctx.stages.length
|
|
256
250
|
|
|
@@ -314,12 +308,9 @@ export function planAutoInclude(input: AutoIncludePlannerInput): AutoIncludePlan
|
|
|
314
308
|
rootArgs.select = result.projectionAfterStrip
|
|
315
309
|
delete rootArgs.include
|
|
316
310
|
} else if (rootModel && isPlainObject(input.args.include)) {
|
|
317
|
-
const stripped
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
stripped[k] = v
|
|
321
|
-
}
|
|
322
|
-
}
|
|
311
|
+
const stripped = Object.fromEntries(
|
|
312
|
+
Object.entries(input.args.include).filter(([k]) => !rootModel.relations[k]),
|
|
313
|
+
)
|
|
323
314
|
if (Object.keys(stripped).length > 0) {
|
|
324
315
|
rootArgs.include = stripped
|
|
325
316
|
} else {
|