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
|
@@ -3,31 +3,6 @@ import { Target, WriteStrategy } from '../constants'
|
|
|
3
3
|
import { ImportStyle } from '../utils/resolveImportStyle'
|
|
4
4
|
import { importExt } from '../utils/importExt'
|
|
5
5
|
|
|
6
|
-
function exampleValueForType(fieldType: string): unknown {
|
|
7
|
-
switch (fieldType) {
|
|
8
|
-
case 'String':
|
|
9
|
-
return 'example'
|
|
10
|
-
case 'Int':
|
|
11
|
-
return 1
|
|
12
|
-
case 'BigInt':
|
|
13
|
-
return '1'
|
|
14
|
-
case 'Float':
|
|
15
|
-
return 1.0
|
|
16
|
-
case 'Decimal':
|
|
17
|
-
return '1.0'
|
|
18
|
-
case 'Boolean':
|
|
19
|
-
return true
|
|
20
|
-
case 'DateTime':
|
|
21
|
-
return '2025-01-01T00:00:00.000Z'
|
|
22
|
-
case 'Json':
|
|
23
|
-
return {}
|
|
24
|
-
case 'Bytes':
|
|
25
|
-
return 'base64data'
|
|
26
|
-
default:
|
|
27
|
-
return 'example'
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
6
|
function generateExpressDocsExport(modelName: string): string {
|
|
32
7
|
return `export function ${modelName}Docs(config: DocsConfig = {}) {
|
|
33
8
|
return (req: Request, res: Response) => {
|
|
@@ -186,65 +161,11 @@ export function generateScalarUIHandler(options: {
|
|
|
186
161
|
importStyle: ImportStyle
|
|
187
162
|
writeStrategy: WriteStrategy
|
|
188
163
|
}): string {
|
|
189
|
-
const { model,
|
|
164
|
+
const { model, writeStrategy } = options
|
|
190
165
|
const target = options.target || 'express'
|
|
191
166
|
const ext = importExt(options.importStyle)
|
|
192
167
|
const modelName = model.name
|
|
193
168
|
|
|
194
|
-
const fieldsMeta = model.fields.map((f: any) => ({
|
|
195
|
-
name: f.name,
|
|
196
|
-
kind: f.kind,
|
|
197
|
-
type: f.type,
|
|
198
|
-
isList: f.isList,
|
|
199
|
-
isRequired: f.isRequired,
|
|
200
|
-
hasDefaultValue: f.hasDefaultValue,
|
|
201
|
-
isUpdatedAt: Boolean(f.isUpdatedAt),
|
|
202
|
-
documentation: f.documentation ?? null,
|
|
203
|
-
isId: Boolean(f.isId),
|
|
204
|
-
isUnique: Boolean(f.isUnique),
|
|
205
|
-
relationFromFields: f.relationFromFields,
|
|
206
|
-
}))
|
|
207
|
-
|
|
208
|
-
const referencedEnumTypes = new Set(
|
|
209
|
-
model.fields.filter((f: any) => f.kind === 'enum').map((f: any) => f.type),
|
|
210
|
-
)
|
|
211
|
-
|
|
212
|
-
const enumsMeta = enums
|
|
213
|
-
.filter((e) => referencedEnumTypes.has(e.name))
|
|
214
|
-
.map((e) => ({
|
|
215
|
-
name: e.name,
|
|
216
|
-
values: e.values.map((v) => ({ name: v.name })),
|
|
217
|
-
}))
|
|
218
|
-
|
|
219
|
-
const exampleValueMap = JSON.stringify(
|
|
220
|
-
Object.fromEntries(
|
|
221
|
-
model.fields
|
|
222
|
-
.filter(
|
|
223
|
-
(f: any) =>
|
|
224
|
-
f.isId || f.isUnique || f.kind === 'scalar' || f.kind === 'enum',
|
|
225
|
-
)
|
|
226
|
-
.map((f: any) => {
|
|
227
|
-
if (f.kind === 'enum') {
|
|
228
|
-
const enumDef = enums.find((e) => e.name === f.type)
|
|
229
|
-
return [f.name, enumDef?.values[0]?.name || 'VALUE']
|
|
230
|
-
}
|
|
231
|
-
return [f.name, exampleValueForType(f.type)]
|
|
232
|
-
}),
|
|
233
|
-
),
|
|
234
|
-
)
|
|
235
|
-
|
|
236
|
-
const compoundIdMeta =
|
|
237
|
-
model.primaryKey && model.primaryKey.fields.length > 1
|
|
238
|
-
? { fields: model.primaryKey.fields }
|
|
239
|
-
: null
|
|
240
|
-
|
|
241
|
-
const compoundUniquesMeta = ((model as any).uniqueIndexes || [])
|
|
242
|
-
.filter((idx: any) => idx.fields && idx.fields.length > 1)
|
|
243
|
-
.map((idx: any) => ({
|
|
244
|
-
name: idx.name || idx.fields.join('_'),
|
|
245
|
-
fields: idx.fields,
|
|
246
|
-
}))
|
|
247
|
-
|
|
248
169
|
const frameworkImport =
|
|
249
170
|
target === 'fastify'
|
|
250
171
|
? `import type { FastifyRequest, FastifyReply } from 'fastify'`
|
|
@@ -268,24 +189,21 @@ import {
|
|
|
268
189
|
renderPlayground,
|
|
269
190
|
isOpenApiDisabled,
|
|
270
191
|
isPlaygroundAvailable,
|
|
271
|
-
type FieldMeta,
|
|
272
|
-
type EnumMeta,
|
|
273
192
|
type DocsUI,
|
|
274
193
|
type DocsConfig,
|
|
275
194
|
type DocsModelContext,
|
|
276
195
|
} from '../docsRenderer${ext}'
|
|
196
|
+
import {
|
|
197
|
+
MODEL_FIELDS,
|
|
198
|
+
MODEL_ENUMS,
|
|
199
|
+
COMPOUND_ID,
|
|
200
|
+
COMPOUND_UNIQUES,
|
|
201
|
+
EXAMPLE_VALUES,
|
|
202
|
+
} from './${modelName}Metadata${ext}'
|
|
277
203
|
|
|
278
204
|
const WRITE_STRATEGY: WriteStrategy = '${writeStrategy}'
|
|
279
205
|
|
|
280
|
-
export
|
|
281
|
-
|
|
282
|
-
export const MODEL_ENUMS: EnumMeta[] = ${JSON.stringify(enumsMeta, null, 2)}
|
|
283
|
-
|
|
284
|
-
const COMPOUND_ID: { fields: string[] } | null = ${JSON.stringify(compoundIdMeta)}
|
|
285
|
-
|
|
286
|
-
const COMPOUND_UNIQUES: { name: string; fields: string[] }[] = ${JSON.stringify(compoundUniquesMeta)}
|
|
287
|
-
|
|
288
|
-
const EXAMPLE_VALUES: Record<string, unknown> = ${exampleValueMap}
|
|
206
|
+
export { MODEL_FIELDS, MODEL_ENUMS }
|
|
289
207
|
|
|
290
208
|
const MODEL_CONTEXT: DocsModelContext = {
|
|
291
209
|
fields: MODEL_FIELDS,
|
package/src/index.ts
CHANGED
|
@@ -18,6 +18,7 @@ import {
|
|
|
18
18
|
generateRelationMeta,
|
|
19
19
|
generateRelationModelsIndex,
|
|
20
20
|
} from './generators/generateRelationMeta'
|
|
21
|
+
import { generateModelMetadata } from './generators/generateModelMetadata'
|
|
21
22
|
import {
|
|
22
23
|
getRelativeClientPath,
|
|
23
24
|
getGuardShapesImport,
|
|
@@ -182,6 +183,17 @@ generatorHandler({
|
|
|
182
183
|
|
|
183
184
|
const guardShapesImport = getGuardShapesImport(options, model.name)
|
|
184
185
|
|
|
186
|
+
await writeFileSafely({
|
|
187
|
+
content: generateModelMetadata({
|
|
188
|
+
model: model as DMMF.Model,
|
|
189
|
+
enums: options.dmmf.datamodel.enums as DMMF.DatamodelEnum[],
|
|
190
|
+
importStyle,
|
|
191
|
+
}),
|
|
192
|
+
options,
|
|
193
|
+
model: model as DMMF.Model,
|
|
194
|
+
operation: 'Metadata',
|
|
195
|
+
})
|
|
196
|
+
|
|
185
197
|
await writeFileSafely({
|
|
186
198
|
content: generateModelCore({
|
|
187
199
|
model: model as DMMF.Model,
|
|
@@ -289,4 +301,4 @@ generatorHandler({
|
|
|
289
301
|
console.log(`✓ ${modelNames.length} models (${target})`)
|
|
290
302
|
console.log('')
|
|
291
303
|
},
|
|
292
|
-
})
|
|
304
|
+
})
|
package/src/utils/copyFiles.ts
CHANGED
|
@@ -13,6 +13,13 @@ const SHARED_FILES = [
|
|
|
13
13
|
'routeConfig.ts',
|
|
14
14
|
'docsRenderer.ts',
|
|
15
15
|
'operationRuntime.ts',
|
|
16
|
+
'errorMapper.ts',
|
|
17
|
+
'sse.ts',
|
|
18
|
+
'pagination.ts',
|
|
19
|
+
'materializedCount.ts',
|
|
20
|
+
'guardHelpers.ts',
|
|
21
|
+
'scalarTypes.ts',
|
|
22
|
+
'concurrency.ts',
|
|
16
23
|
]
|
|
17
24
|
|
|
18
25
|
const EXPRESS_ONLY_FILES = [
|
|
@@ -47,17 +47,11 @@ export async function writeFileSafely({
|
|
|
47
47
|
const dirPath = path.dirname(filePath)
|
|
48
48
|
if (!fs.existsSync(dirPath)) fs.mkdirSync(dirPath, { recursive: true })
|
|
49
49
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
parser: 'typescript',
|
|
56
|
-
})
|
|
57
|
-
} catch {
|
|
58
|
-
console.warn('⚠️ Prettier formatting failed for ' + path.basename(filePath) + ', writing unformatted')
|
|
59
|
-
formattedContent = content
|
|
60
|
-
}
|
|
50
|
+
const resolvedOptions = await getPrettierOptions()
|
|
51
|
+
const formattedContent = await prettier.format(content, {
|
|
52
|
+
...resolvedOptions,
|
|
53
|
+
parser: 'typescript',
|
|
54
|
+
})
|
|
61
55
|
|
|
62
56
|
fs.writeFileSync(filePath, formattedContent)
|
|
63
57
|
}
|