prisma-generator-express 1.55.0 → 1.56.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 +131 -12
- package/dist/constants.d.ts +1 -0
- package/dist/generators/generateFastifyHandler.js +3 -1
- package/dist/generators/generateFastifyHandler.js.map +1 -1
- package/dist/generators/generateHonoHandler.js +3 -1
- package/dist/generators/generateHonoHandler.js.map +1 -1
- package/dist/generators/generateOperationCore.d.ts +2 -1
- package/dist/generators/generateOperationCore.js +38 -36
- package/dist/generators/generateOperationCore.js.map +1 -1
- package/dist/generators/generateRouteConfigType.js +4 -1
- package/dist/generators/generateRouteConfigType.js.map +1 -1
- package/dist/generators/generateRouter.d.ts +3 -2
- package/dist/generators/generateRouter.js +16 -5
- package/dist/generators/generateRouter.js.map +1 -1
- package/dist/generators/generateRouterFastify.d.ts +3 -2
- package/dist/generators/generateRouterFastify.js +19 -7
- package/dist/generators/generateRouterFastify.js.map +1 -1
- package/dist/generators/generateRouterHono.d.ts +3 -2
- package/dist/generators/generateRouterHono.js +24 -14
- package/dist/generators/generateRouterHono.js.map +1 -1
- package/dist/index.js +20 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/constants.ts +3 -1
- package/src/copy/autoIncludeRuntime.ts +60 -35
- package/src/copy/docsRenderer.ts +5 -4
- package/src/copy/operationRuntime.ts +94 -9
- package/src/copy/routeConfig.express.ts +6 -0
- package/src/copy/routeConfig.fastify.ts +7 -1
- package/src/copy/routeConfig.hono.ts +8 -2
- package/src/copy/routeConfig.ts +21 -5
- package/src/generators/generateFastifyHandler.ts +3 -1
- package/src/generators/generateHonoHandler.ts +3 -1
- package/src/generators/generateOperationCore.ts +42 -37
- package/src/generators/generateRouteConfigType.ts +5 -2
- package/src/generators/generateRouter.ts +18 -5
- package/src/generators/generateRouterFastify.ts +21 -7
- package/src/generators/generateRouterHono.ts +26 -14
- package/src/index.ts +24 -2
|
@@ -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, writeStrategy, }) {
|
|
6
|
+
function generateFastifyRouterFunction({ model, enums, guardShapesImport, importStyle, writeStrategy, findManyPaginatedMode, }) {
|
|
7
7
|
const ext = (0, importExt_1.importExt)(importStyle);
|
|
8
8
|
const modelName = model.name;
|
|
9
9
|
const modelNameLower = modelName.toLowerCase();
|
|
@@ -48,16 +48,23 @@ import {
|
|
|
48
48
|
${modelName}Count,
|
|
49
49
|
${modelName}GroupBy,
|
|
50
50
|
} from './${modelName}Handlers${ext}'
|
|
51
|
-
import type {
|
|
51
|
+
import type {
|
|
52
|
+
RouteConfig,
|
|
53
|
+
FastifyHookHandler,
|
|
54
|
+
WriteStrategy,
|
|
55
|
+
FindManyPaginatedMode,
|
|
56
|
+
PaginationConfig,
|
|
57
|
+
} from '../routeConfig.target${ext}'
|
|
52
58
|
import { parseQueryParams } from '../parseQueryParams${ext}'
|
|
53
59
|
import { sanitizeKeys, normalizePrefix, getEnv } from '../misc${ext}'
|
|
54
60
|
import { buildModelOpenApi } from '../buildModelOpenApi${ext}'
|
|
55
|
-
import { mapError, transformResult, HttpError, type OperationContext } from '../operationRuntime${ext}'
|
|
61
|
+
import { mapError, transformResult, mergePaginationConfig, HttpError, type OperationContext } from '../operationRuntime${ext}'
|
|
56
62
|
|
|
57
63
|
${(0, generateRouteConfigType_1.generateRouteConfigType)(modelName, 'FastifyHookHandler', guardShapesImport, importStyle, 'fastify')}
|
|
58
64
|
const _env = getEnv()
|
|
59
65
|
|
|
60
66
|
const WRITE_STRATEGY: WriteStrategy = '${writeStrategy}'
|
|
67
|
+
const FIND_MANY_PAGINATED_MODE: FindManyPaginatedMode = '${findManyPaginatedMode}'
|
|
61
68
|
|
|
62
69
|
const MODEL_FIELDS = ${JSON.stringify(fieldsMeta, null, 2)} as const
|
|
63
70
|
|
|
@@ -67,6 +74,7 @@ type OperationConfigLike = {
|
|
|
67
74
|
before?: FastifyHookHandler[]
|
|
68
75
|
after?: FastifyHookHandler[]
|
|
69
76
|
shape?: Record<string, unknown>
|
|
77
|
+
pagination?: Partial<PaginationConfig>
|
|
70
78
|
}
|
|
71
79
|
|
|
72
80
|
type FastifyExtended = FastifyRequest & {
|
|
@@ -74,7 +82,7 @@ type FastifyExtended = FastifyRequest & {
|
|
|
74
82
|
postgres?: unknown
|
|
75
83
|
sqlite?: unknown
|
|
76
84
|
parsedQuery?: Record<string, unknown>
|
|
77
|
-
routeConfig?: { pagination?:
|
|
85
|
+
routeConfig?: { pagination?: PaginationConfig }
|
|
78
86
|
guardShape?: Record<string, unknown>
|
|
79
87
|
guardCaller?: string
|
|
80
88
|
resultData?: unknown
|
|
@@ -120,9 +128,9 @@ function makeShapeHook(
|
|
|
120
128
|
): (request: FastifyRequest) => void {
|
|
121
129
|
return (request: FastifyRequest) => {
|
|
122
130
|
const fx = request as FastifyExtended
|
|
123
|
-
const
|
|
124
|
-
if (
|
|
125
|
-
fx.routeConfig = { pagination:
|
|
131
|
+
const merged = mergePaginationConfig(config.pagination, opConfig.pagination)
|
|
132
|
+
if (merged) {
|
|
133
|
+
fx.routeConfig = { pagination: merged }
|
|
126
134
|
}
|
|
127
135
|
const headerName = (config.guard?.variantHeader || 'x-api-variant').toLowerCase()
|
|
128
136
|
const headerValue = request.headers[headerName]
|
|
@@ -214,6 +222,10 @@ export async function ${routerFunctionName}<TCtx = unknown, TPrisma = any>(
|
|
|
214
222
|
}
|
|
215
223
|
}
|
|
216
224
|
|
|
225
|
+
fastify.addHook('onRequest', async (request: FastifyRequest) => {
|
|
226
|
+
(request as FastifyExtended & { findManyPaginatedMode?: FindManyPaginatedMode }).findManyPaginatedMode = FIND_MANY_PAGINATED_MODE
|
|
227
|
+
})
|
|
228
|
+
|
|
217
229
|
fastify.setErrorHandler((error: FastifyError, _request: FastifyRequest, reply: FastifyReply) => {
|
|
218
230
|
const e = error as { status?: number; statusCode?: number; message?: string }
|
|
219
231
|
const status = e.status ?? e.statusCode ?? 500
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateRouterFastify.js","sourceRoot":"","sources":["../../src/generators/generateRouterFastify.ts"],"names":[],"mappings":";;AAMA,
|
|
1
|
+
{"version":3,"file":"generateRouterFastify.js","sourceRoot":"","sources":["../../src/generators/generateRouterFastify.ts"],"names":[],"mappings":";;AAMA,sEAoaC;AAzaD,uEAAmE;AAEnE,kDAA8C;AAG9C,SAAgB,6BAA6B,CAAC,EAC5C,KAAK,EACL,KAAK,EACL,iBAAiB,EACjB,WAAW,EACX,aAAa,EACb,qBAAqB,GAQtB;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,CAAC,CAAC,UAAU;QACxB,eAAe,EAAE,CAAC,CAAC,eAAe;QAClC,WAAW,EAAE,CAAC,CAAC,WAAW,IAAI,KAAK;QACnC,aAAa,EAAE,CAAC,CAAC,aAAa;QAC9B,kBAAkB,EAAE,CAAC,CAAC,kBAAkB;KACzC,CAAC,CAAC,CAAA;IAEH,MAAM,mBAAmB,GAAG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;;;;;;;;;;;;;;YAuD5C,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;wBAmDG,kBAAkB;;YAE9B,SAAS;;;4DAGuC,cAAc;;;;;;;;;;;;;;WAc/D,SAAS;;;;;;;;;WAST,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4CAmFwB,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,10 +1,11 @@
|
|
|
1
1
|
import { DMMF } from '@prisma/generator-helper';
|
|
2
2
|
import { ImportStyle } from '../utils/resolveImportStyle';
|
|
3
|
-
import { WriteStrategy } from '../constants';
|
|
4
|
-
export declare function generateHonoRouterFunction({ model, enums, guardShapesImport, importStyle, writeStrategy, }: {
|
|
3
|
+
import { WriteStrategy, FindManyPaginatedMode } from '../constants';
|
|
4
|
+
export declare function generateHonoRouterFunction({ model, enums, guardShapesImport, importStyle, writeStrategy, findManyPaginatedMode, }: {
|
|
5
5
|
model: DMMF.Model;
|
|
6
6
|
enums: DMMF.DatamodelEnum[];
|
|
7
7
|
guardShapesImport: string | null;
|
|
8
8
|
importStyle: ImportStyle;
|
|
9
9
|
writeStrategy: WriteStrategy;
|
|
10
|
+
findManyPaginatedMode: FindManyPaginatedMode;
|
|
10
11
|
}): 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, writeStrategy, }) {
|
|
6
|
+
function generateHonoRouterFunction({ model, enums, guardShapesImport, importStyle, writeStrategy, findManyPaginatedMode, }) {
|
|
7
7
|
const ext = (0, importExt_1.importExt)(importStyle);
|
|
8
8
|
const modelName = model.name;
|
|
9
9
|
const modelNameLower = modelName.toLowerCase();
|
|
@@ -58,16 +58,24 @@ import type {
|
|
|
58
58
|
HonoInternalVariables,
|
|
59
59
|
GeneratedHonoEnv,
|
|
60
60
|
WriteStrategy,
|
|
61
|
+
FindManyPaginatedMode,
|
|
62
|
+
PaginationConfig,
|
|
61
63
|
} from '../routeConfig.target${ext}'
|
|
62
64
|
import { parseQueryParams } from '../parseQueryParams${ext}'
|
|
63
65
|
import { sanitizeKeys, normalizePrefix, getEnv } from '../misc${ext}'
|
|
64
66
|
import { buildModelOpenApi } from '../buildModelOpenApi${ext}'
|
|
65
|
-
import {
|
|
67
|
+
import {
|
|
68
|
+
mapError,
|
|
69
|
+
transformResult,
|
|
70
|
+
mergePaginationConfig,
|
|
71
|
+
type OperationContext,
|
|
72
|
+
} from '../operationRuntime${ext}'
|
|
66
73
|
|
|
67
74
|
${(0, generateRouteConfigType_1.generateRouteConfigType)(modelName, 'HonoHookHandler', guardShapesImport, importStyle, 'hono')}
|
|
68
75
|
const _env = getEnv()
|
|
69
76
|
|
|
70
77
|
const WRITE_STRATEGY: WriteStrategy = '${writeStrategy}'
|
|
78
|
+
const FIND_MANY_PAGINATED_MODE: FindManyPaginatedMode = '${findManyPaginatedMode}'
|
|
71
79
|
|
|
72
80
|
const MODEL_FIELDS = ${JSON.stringify(fieldsMeta, null, 2)} as const
|
|
73
81
|
|
|
@@ -77,6 +85,7 @@ type OperationConfigLike<TEnv extends HonoEnvBase> = {
|
|
|
77
85
|
before?: HonoHookHandler<TEnv>[]
|
|
78
86
|
after?: HonoHookHandler<TEnv>[]
|
|
79
87
|
shape?: Record<string, unknown>
|
|
88
|
+
pagination?: Partial<PaginationConfig>
|
|
80
89
|
}
|
|
81
90
|
|
|
82
91
|
const defaultOpConfig = Object.freeze({
|
|
@@ -84,7 +93,7 @@ const defaultOpConfig = Object.freeze({
|
|
|
84
93
|
after: Object.freeze([]),
|
|
85
94
|
}) as unknown as OperationConfigLike<HonoEnvBase>
|
|
86
95
|
|
|
87
|
-
type HandlerContext = Context<{ Variables: HonoInternalVariables }>
|
|
96
|
+
type HandlerContext = Context<{ Variables: HonoInternalVariables & { findManyPaginatedMode?: FindManyPaginatedMode } }>
|
|
88
97
|
|
|
89
98
|
function isQueryBuilderEnabled(config: RouteConfig): boolean {
|
|
90
99
|
if (config.queryBuilder === false) return false
|
|
@@ -137,10 +146,11 @@ function makeShapeMiddleware<TCtx, TPrisma, TEnv extends HonoEnvBase>(
|
|
|
137
146
|
opConfig: OperationConfigLike<TEnv>,
|
|
138
147
|
) {
|
|
139
148
|
return (c: Context<GeneratedHonoEnv<TEnv>>): void => {
|
|
140
|
-
const
|
|
141
|
-
if (
|
|
142
|
-
c.set('routeConfig', { pagination:
|
|
149
|
+
const merged = mergePaginationConfig(config.pagination, opConfig.pagination)
|
|
150
|
+
if (merged) {
|
|
151
|
+
c.set('routeConfig', { pagination: merged })
|
|
143
152
|
}
|
|
153
|
+
;(c as unknown as HandlerContext).set('findManyPaginatedMode', FIND_MANY_PAGINATED_MODE)
|
|
144
154
|
const headerName = config.guard?.variantHeader || 'x-api-variant'
|
|
145
155
|
const headerValue = c.req.header(headerName)
|
|
146
156
|
const caller = config.guard?.resolveVariant?.(c) ?? headerValue ?? undefined
|
|
@@ -257,17 +267,17 @@ export function ${routerFunctionName}<TCtx = unknown, TPrisma = any, TEnv extend
|
|
|
257
267
|
parseFn: (c: HandlerContext) => Promise<void>,
|
|
258
268
|
) => async (c: Context<GeneratedHonoEnv<TEnv>>): Promise<Response> => {
|
|
259
269
|
try {
|
|
260
|
-
await parseFn(c)
|
|
270
|
+
await parseFn(c as unknown as HandlerContext)
|
|
261
271
|
makeShapeMiddleware<TCtx, TPrisma, TEnv>(config, opConfig)(c)
|
|
262
272
|
const { before = [], after = [] } = opConfig
|
|
263
273
|
const beforeResp = await runHooks<TEnv>(before, c)
|
|
264
274
|
if (beforeResp) return beforeResp
|
|
265
|
-
await handlerFn(c)
|
|
275
|
+
await handlerFn(c as unknown as HandlerContext)
|
|
266
276
|
const afterResp = await runHooks<TEnv>(after, c)
|
|
267
277
|
if (afterResp) return afterResp
|
|
268
|
-
return sendResult(c)
|
|
278
|
+
return sendResult(c as unknown as HandlerContext)
|
|
269
279
|
} catch (error: unknown) {
|
|
270
|
-
return sendError(c, error)
|
|
280
|
+
return sendError(c as unknown as HandlerContext, error)
|
|
271
281
|
}
|
|
272
282
|
}
|
|
273
283
|
|
|
@@ -276,17 +286,17 @@ export function ${routerFunctionName}<TCtx = unknown, TPrisma = any, TEnv extend
|
|
|
276
286
|
handlerFn: (c: HandlerContext) => Promise<void>,
|
|
277
287
|
) => async (c: Context<GeneratedHonoEnv<TEnv>>): Promise<Response> => {
|
|
278
288
|
try {
|
|
279
|
-
await parseWriteBodyMiddleware(c)
|
|
289
|
+
await parseWriteBodyMiddleware(c as unknown as HandlerContext)
|
|
280
290
|
makeShapeMiddleware<TCtx, TPrisma, TEnv>(config, opConfig)(c)
|
|
281
291
|
const { before = [], after = [] } = opConfig
|
|
282
292
|
const beforeResp = await runHooks<TEnv>(before, c)
|
|
283
293
|
if (beforeResp) return beforeResp
|
|
284
|
-
await handlerFn(c)
|
|
294
|
+
await handlerFn(c as unknown as HandlerContext)
|
|
285
295
|
const afterResp = await runHooks<TEnv>(after, c)
|
|
286
296
|
if (afterResp) return afterResp
|
|
287
|
-
return sendResult(c)
|
|
297
|
+
return sendResult(c as unknown as HandlerContext)
|
|
288
298
|
} catch (error: unknown) {
|
|
289
|
-
return sendError(c, error)
|
|
299
|
+
return sendError(c as unknown as HandlerContext, error)
|
|
290
300
|
}
|
|
291
301
|
}
|
|
292
302
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateRouterHono.js","sourceRoot":"","sources":["../../src/generators/generateRouterHono.ts"],"names":[],"mappings":";;AAMA,
|
|
1
|
+
{"version":3,"file":"generateRouterHono.js","sourceRoot":"","sources":["../../src/generators/generateRouterHono.ts"],"names":[],"mappings":";;AAMA,gEA6aC;AAlbD,uEAAmE;AAEnE,kDAA8C;AAG9C,SAAgB,0BAA0B,CAAC,EACzC,KAAK,EACL,KAAK,EACL,iBAAiB,EACjB,WAAW,EACX,aAAa,EACb,qBAAqB,GAQtB;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,CAAC,CAAC,UAAU;QACxB,eAAe,EAAE,CAAC,CAAC,eAAe;QAClC,WAAW,EAAE,CAAC,CAAC,WAAW,IAAI,KAAK;QACnC,aAAa,EAAE,CAAC,CAAC,a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,IAAI,CAAC,SAAS,CAAC,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;YA+D5C,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAyDH,kBAAkB,mFAAmF,SAAS;;;;4DAIpE,cAAc;;;;;;;;;;;;;;WAc/D,SAAS;;;;;;;;;WAST,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;mCA0Ee,SAAS;;;;;;;;yCAQH,SAAS;gEACc,SAAS;;;;;yCAKhC,SAAS;gEACc,SAAS;;;;;yCAKhC,SAAS;gEACc,SAAS;;;;;yCAKhC,SAAS;gEACc,SAAS;;;;;yCAKhC,SAAS;gEACc,SAAS;;;;;yCAKhC,SAAS;gEACc,SAAS;;;;;yCAKhC,SAAS;gEACc,SAAS;;;;;yCAKhC,SAAS;gEACc,SAAS;;;;;yCAKhC,SAAS;;;gDAGF,SAAS;;;;;;;2CAOd,SAAS;;;;;2CAKT,SAAS;;;;;2CAKT,SAAS;;;;;0CAKV,SAAS;;;;;0CAKT,SAAS;;;;;0CAKT,SAAS;;;;;4CAKP,SAAS;;;;;6CAKR,SAAS;;;;;6CAKT,SAAS;;;;;CAKrD,CAAA;AACD,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -43,6 +43,15 @@ function getWriteStrategy(options) {
|
|
|
43
43
|
return 'forceReturn';
|
|
44
44
|
throw new Error(`Invalid writeStrategy "${raw}". Expected "regular", "throwOnNonReturning", or "forceReturn".`);
|
|
45
45
|
}
|
|
46
|
+
function getFindManyPaginatedMode(options) {
|
|
47
|
+
const raw = String(options.generator.config.findManyPaginatedMode ?? 'promiseAll');
|
|
48
|
+
const lower = raw.toLowerCase();
|
|
49
|
+
if (lower === 'transaction')
|
|
50
|
+
return 'transaction';
|
|
51
|
+
if (lower === 'promiseall')
|
|
52
|
+
return 'promiseAll';
|
|
53
|
+
throw new Error(`Invalid findManyPaginatedMode "${raw}". Expected "transaction" or "promiseAll".`);
|
|
54
|
+
}
|
|
46
55
|
function validateClientGeneratorPresent(options) {
|
|
47
56
|
(0, generateImportPrismaStatement_1.getRelativeClientPath)(options, options.dmmf.datamodel.models[0]?.name ?? 'Model');
|
|
48
57
|
}
|
|
@@ -57,6 +66,7 @@ function validateClientGeneratorPresent(options) {
|
|
|
57
66
|
async onGenerate(options) {
|
|
58
67
|
const target = getTarget(options);
|
|
59
68
|
const writeStrategy = getWriteStrategy(options);
|
|
69
|
+
const findManyPaginatedMode = getFindManyPaginatedMode(options);
|
|
60
70
|
const hasExplicitOutput = !!options.generator.output?.fromEnvVar ||
|
|
61
71
|
options.generator.config.output !== undefined;
|
|
62
72
|
if (!hasExplicitOutput) {
|
|
@@ -70,6 +80,7 @@ function validateClientGeneratorPresent(options) {
|
|
|
70
80
|
console.log(` Output: ${options.generator.output?.value}`);
|
|
71
81
|
console.log(` Import style: ${importStyle}`);
|
|
72
82
|
console.log(` Write strategy: ${writeStrategy}`);
|
|
83
|
+
console.log(` findManyPaginated mode: ${findManyPaginatedMode}`);
|
|
73
84
|
if (options.dmmf.datamodel.models.length > 0) {
|
|
74
85
|
validateClientGeneratorPresent(options);
|
|
75
86
|
}
|
|
@@ -89,7 +100,12 @@ function validateClientGeneratorPresent(options) {
|
|
|
89
100
|
modelNames.push(model.name);
|
|
90
101
|
const guardShapesImport = (0, generateImportPrismaStatement_1.getGuardShapesImport)(options, model.name);
|
|
91
102
|
await (0, writeFileSafely_1.writeFileSafely)({
|
|
92
|
-
content: (0, generateOperationCore_1.generateModelCore)({
|
|
103
|
+
content: (0, generateOperationCore_1.generateModelCore)({
|
|
104
|
+
model: model,
|
|
105
|
+
importStyle,
|
|
106
|
+
writeStrategy,
|
|
107
|
+
findManyPaginatedMode,
|
|
108
|
+
}),
|
|
93
109
|
options,
|
|
94
110
|
model: model,
|
|
95
111
|
operation: 'Core',
|
|
@@ -107,6 +123,7 @@ function validateClientGeneratorPresent(options) {
|
|
|
107
123
|
guardShapesImport,
|
|
108
124
|
importStyle,
|
|
109
125
|
writeStrategy,
|
|
126
|
+
findManyPaginatedMode,
|
|
110
127
|
})
|
|
111
128
|
: target === 'hono'
|
|
112
129
|
? (0, generateRouterHono_1.generateHonoRouterFunction)({
|
|
@@ -115,6 +132,7 @@ function validateClientGeneratorPresent(options) {
|
|
|
115
132
|
guardShapesImport,
|
|
116
133
|
importStyle,
|
|
117
134
|
writeStrategy,
|
|
135
|
+
findManyPaginatedMode,
|
|
118
136
|
})
|
|
119
137
|
: (0, generateRouter_1.generateRouterFunction)({
|
|
120
138
|
model: model,
|
|
@@ -122,6 +140,7 @@ function validateClientGeneratorPresent(options) {
|
|
|
122
140
|
guardShapesImport,
|
|
123
141
|
importStyle,
|
|
124
142
|
writeStrategy,
|
|
143
|
+
findManyPaginatedMode,
|
|
125
144
|
});
|
|
126
145
|
await (0, writeFileSafely_1.writeFileSafely)({
|
|
127
146
|
content: routerContent,
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA,+DAIiC;AACjC,gDAAuB;AACvB,gFAA4E;AAC5E,gFAA4E;AAC5E,0EAAsE;AACtE,gEAAoE;AACpE,8EAAkF;AAClF,wEAA4E;AAC5E,kFAA8E;AAC9E,0EAAsE;AACtE,wFAAoF;AACpF,8EAAsE;AACtE,4EAG0C;AAC1C,8FAGmD;AACnD,6DAAyD;AACzD,iDAA6C;AAC7C,mEAA4E;AAC5E,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA,+DAIiC;AACjC,gDAAuB;AACvB,gFAA4E;AAC5E,gFAA4E;AAC5E,0EAAsE;AACtE,gEA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AC1B,CAAC,CAAA;QAEF,MAAM,IAAA,iCAAe,EAAC;YACpB,OAAO,EAAE,IAAA,uDAA0B,EAAC,OAAO,CAAC;YAC5C,OAAO;YACP,SAAS,EAAE,cAAc;SAC1B,CAAC,CAAA;QAEF,OAAO,CAAC,GAAG,CAAC,+BAA+B,CAAC,CAAA;QAC5C,OAAO,CAAC,GAAG,CAAC,KAAK,UAAU,CAAC,MAAM,YAAY,MAAM,GAAG,CAAC,CAAA;QACxD,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;IACjB,CAAC;CACF,CAAC,CAAA"}
|
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.56.0",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"license": "MIT",
|
package/src/constants.ts
CHANGED
|
@@ -2,4 +2,6 @@ export const GENERATOR_NAME = 'prisma-generator-express'
|
|
|
2
2
|
|
|
3
3
|
export type Target = 'express' | 'fastify' | 'hono'
|
|
4
4
|
|
|
5
|
-
export type WriteStrategy = 'regular' | 'throwOnNonReturning' | 'forceReturn'
|
|
5
|
+
export type WriteStrategy = 'regular' | 'throwOnNonReturning' | 'forceReturn'
|
|
6
|
+
|
|
7
|
+
export type FindManyPaginatedMode = 'transaction' | 'promiseAll'
|
|
@@ -19,8 +19,10 @@ import {
|
|
|
19
19
|
applyPaginationLimits,
|
|
20
20
|
countForPagination,
|
|
21
21
|
mapError,
|
|
22
|
+
HttpError,
|
|
22
23
|
type OperationContext,
|
|
23
24
|
type PrismaDelegate,
|
|
25
|
+
type FindManyPaginatedMode,
|
|
24
26
|
} from './operationRuntime'
|
|
25
27
|
import { isPlainObject } from './misc'
|
|
26
28
|
import {
|
|
@@ -300,9 +302,7 @@ async function runOneStageSingle(options: {
|
|
|
300
302
|
|
|
301
303
|
const parentRaw = readPath(internal, stage.parentPath)
|
|
302
304
|
if (!isPlainObject(parentRaw)) {
|
|
303
|
-
if (stage.parentPath !== '')
|
|
304
|
-
return
|
|
305
|
-
}
|
|
305
|
+
if (stage.parentPath !== '') return
|
|
306
306
|
const empty = emptyResultFor(stage.relationField.isList)
|
|
307
307
|
const applied = setByPath(publicState, stage.relationPath, empty)
|
|
308
308
|
if (applied) sendSSEField(res, stage.relationPath, empty)
|
|
@@ -705,36 +705,58 @@ async function processFindManyStages(args: {
|
|
|
705
705
|
return stageErrorMessage
|
|
706
706
|
}
|
|
707
707
|
|
|
708
|
-
async function runPaginatedRoot(
|
|
709
|
-
extended: unknown
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
): Promise<{ data: unknown[]; count: number }> {
|
|
715
|
-
const
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
if (
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
} catch (err) {
|
|
729
|
-
const e = err as { code?: string }
|
|
730
|
-
if (e?.code !== 'P2028') throw err
|
|
731
|
-
console.warn('[auto-progressive] Interactive transactions not available, paginated queries are non-atomic')
|
|
708
|
+
async function runPaginatedRoot(args: {
|
|
709
|
+
extended: unknown
|
|
710
|
+
delegateKey: string
|
|
711
|
+
rootArgs: Record<string, unknown>
|
|
712
|
+
ctx: OperationContext
|
|
713
|
+
mode: FindManyPaginatedMode
|
|
714
|
+
}): Promise<{ data: unknown[]; count: number }> {
|
|
715
|
+
const { extended, delegateKey, rootArgs, ctx, mode } = args
|
|
716
|
+
const distinctCountLimit = ctx.paginationConfig?.distinctCountLimit
|
|
717
|
+
const countSource = ctx.paginationConfig?.countSource
|
|
718
|
+
|
|
719
|
+
if (mode === 'transaction') {
|
|
720
|
+
const txClient = extended as {
|
|
721
|
+
$transaction?: <T>(fn: (tx: unknown) => Promise<T>) => Promise<T>
|
|
722
|
+
}
|
|
723
|
+
if (typeof txClient.$transaction !== 'function') {
|
|
724
|
+
throw new HttpError(
|
|
725
|
+
500,
|
|
726
|
+
'findManyPaginatedMode="transaction" requires transaction support on the Prisma client',
|
|
727
|
+
)
|
|
732
728
|
}
|
|
729
|
+
const result = await txClient.$transaction(async (tx: unknown) => {
|
|
730
|
+
const txDelegate = getDelegate(tx, delegateKey)
|
|
731
|
+
const [data, count] = await Promise.all([
|
|
732
|
+
txDelegate.findMany(rootArgs),
|
|
733
|
+
countForPagination(
|
|
734
|
+
txDelegate,
|
|
735
|
+
rootArgs,
|
|
736
|
+
undefined,
|
|
737
|
+
undefined,
|
|
738
|
+
distinctCountLimit,
|
|
739
|
+
countSource,
|
|
740
|
+
tx,
|
|
741
|
+
),
|
|
742
|
+
])
|
|
743
|
+
return { data, count }
|
|
744
|
+
})
|
|
745
|
+
return { data: result.data as unknown[], count: result.count }
|
|
733
746
|
}
|
|
734
747
|
|
|
748
|
+
const rootDelegate = getDelegate(extended, delegateKey)
|
|
735
749
|
const [data, count] = await Promise.all([
|
|
736
750
|
rootDelegate.findMany(rootArgs),
|
|
737
|
-
countForPagination(
|
|
751
|
+
countForPagination(
|
|
752
|
+
rootDelegate,
|
|
753
|
+
rootArgs,
|
|
754
|
+
undefined,
|
|
755
|
+
undefined,
|
|
756
|
+
distinctCountLimit,
|
|
757
|
+
countSource,
|
|
758
|
+
extended,
|
|
759
|
+
),
|
|
738
760
|
])
|
|
739
761
|
return { data: data as unknown[], count }
|
|
740
762
|
}
|
|
@@ -826,18 +848,21 @@ async function runAutoIncludePaginated(
|
|
|
826
848
|
const extended = await getExtendedClient(ctx)
|
|
827
849
|
if (isClientGone()) return
|
|
828
850
|
|
|
829
|
-
const rootDelegate = getDelegate(extended, delegateKey)
|
|
830
851
|
const rootArgs = applyPaginationLimits(plan.rootArgs, ctx.paginationConfig)
|
|
831
|
-
const
|
|
852
|
+
const mode: FindManyPaginatedMode = ctx.findManyPaginatedMode ?? 'promiseAll'
|
|
832
853
|
|
|
833
854
|
let rootRows: unknown[]
|
|
834
855
|
let total: number
|
|
835
856
|
try {
|
|
836
|
-
const
|
|
837
|
-
extended,
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
857
|
+
const r = await runPaginatedRoot({
|
|
858
|
+
extended,
|
|
859
|
+
delegateKey,
|
|
860
|
+
rootArgs,
|
|
861
|
+
ctx,
|
|
862
|
+
mode,
|
|
863
|
+
})
|
|
864
|
+
rootRows = r.data
|
|
865
|
+
total = r.count
|
|
841
866
|
} catch (err) {
|
|
842
867
|
if (isClientGone()) return
|
|
843
868
|
console.error('[auto-progressive] root findManyPaginated failed:', err)
|
package/src/copy/docsRenderer.ts
CHANGED
|
@@ -881,7 +881,7 @@ export function renderDocs(
|
|
|
881
881
|
return argsReferenceWriteBase
|
|
882
882
|
})()
|
|
883
883
|
|
|
884
|
-
|
|
884
|
+
const batchMutationNote =
|
|
885
885
|
writeStrategy === 'forceReturn'
|
|
886
886
|
? 'Batch mutations: deleteMany returns { count }. createMany and updateMany silently invoke their returning counterparts and return arrays of records. Batch data inputs are scalar-only — nested relation writes are not supported.'
|
|
887
887
|
: writeStrategy === 'throwOnNonReturning'
|
|
@@ -895,7 +895,7 @@ export function renderDocs(
|
|
|
895
895
|
'findManyPaginated returns { data, total, hasMore }. hasMore is reliable for forward offset pagination only.',
|
|
896
896
|
batchMutationNote,
|
|
897
897
|
'findUnique and findFirst return null (not 404) when no record matches. Use the OrThrow variants for 404 behavior.',
|
|
898
|
-
'createManyAndReturn requires Prisma 5.14.0+, updateManyAndReturn requires Prisma 6.2.0+. Both are limited to PostgreSQL
|
|
898
|
+
'createManyAndReturn requires Prisma 5.14.0+, updateManyAndReturn requires Prisma 6.2.0+. Both are limited to PostgreSQL/CockroachDB/SQLite.',
|
|
899
899
|
]
|
|
900
900
|
|
|
901
901
|
const errorRows = [
|
|
@@ -903,7 +903,7 @@ export function renderDocs(
|
|
|
903
903
|
{ status: '403', description: 'Forbidden', causes: 'Guard policy rejected the operation.' },
|
|
904
904
|
{ status: '404', description: 'Not found', causes: 'Record not found. Only from OrThrow operations, update, and delete.' },
|
|
905
905
|
{ status: '409', description: 'Conflict', causes: 'Unique constraint violation on create/update/upsert, or transaction conflict (e.g. in findManyPaginated).' },
|
|
906
|
-
{ status: '500', description: 'Internal server error', causes: 'Database error, table/column missing, raw query failure, or
|
|
906
|
+
{ status: '500', description: 'Internal server error', causes: 'Database error, table/column missing, raw query failure, unhandled error, or findManyPaginatedMode="transaction" without transaction support on the Prisma client.' },
|
|
907
907
|
{ status: '501', description: 'Not implemented', causes: 'Database provider does not support the requested feature, or writeStrategy disabled the endpoint.' },
|
|
908
908
|
{ status: '503', description: 'Service unavailable', causes: 'Database connection pool timeout.' },
|
|
909
909
|
]
|
|
@@ -1033,7 +1033,8 @@ export function renderDocs(
|
|
|
1033
1033
|
'<strong>POST read endpoints:</strong> All read operations accept POST as an alternative transport. The request body is a plain JSON object with the same argument structure as the GET query params — no JSON-string encoding needed. POST reads use native JSON types (numbers, booleans, objects) directly. findMany POST read is at <span class="font-mono">/read</span>; all other read operations use the same path as their GET counterpart. Disable with <span class="font-mono">disablePostReads: true</span> in route config.',
|
|
1034
1034
|
'<strong>Request body validation:</strong> All write endpoints require a JSON object body. Sending <span class="font-mono">null</span>, arrays, or non-object JSON values returns 400.',
|
|
1035
1035
|
'<strong>Documentation in production:</strong> Docs endpoints are disabled by default when <span class="font-mono">NODE_ENV=production</span> or <span class="font-mono">DISABLE_OPENAPI=true</span>. To enable in production, set <span class="font-mono">disableOpenApi: false</span> in the route config.',
|
|
1036
|
-
'<strong>Paginated query
|
|
1036
|
+
'<strong>Paginated query execution:</strong> findManyPaginated execution is controlled by the generator option <span class="font-mono">findManyPaginatedMode</span>. The default <span class="font-mono">"promiseAll"</span> runs data and count with <span class="font-mono">Promise.all</span> — faster, but not atomic under concurrent writes (data and total may be slightly inconsistent). <span class="font-mono">"transaction"</span> runs data and count inside an interactive transaction and throws <span class="font-mono">500</span> if the Prisma client does not support transactions. There is no implicit fallback in transaction mode.',
|
|
1037
|
+
'<strong>Materialized count source:</strong> findManyPaginated supports endpoint-level <span class="font-mono">pagination.countSource.type="materializedView"</span> for counts driven by a materialized view. The view query is used only when the request has no dynamic <span class="font-mono">where</span>, no <span class="font-mono">distinct</span>, and no guard shape — any of those falls back to the delegate count to keep the total consistent with the filtered data. The generated SQL uses PostgreSQL-style <span class="font-mono">$N</span> placeholders (PostgreSQL and CockroachDB). The optional <span class="font-mono">countSource.where</span> field supports flat equality and <span class="font-mono">null</span> only — no operators, no nested objects.',
|
|
1037
1038
|
'<strong>Distinct count approximation:</strong> When findManyPaginated is used with distinct and the number of unique values exceeds 100,000, the total falls back to a non-distinct count which may overcount. When a guard shape is configured alongside distinct, the total also falls back to a non-distinct count to avoid imposing the public read shape on the internal counting query. The hasMore value is affected accordingly.',
|
|
1038
1039
|
'<strong>Serialization:</strong> BigInt values are serialized as strings. Bytes/Buffer values are serialized as base64 strings. Decimal values are serialized as strings. DateTime values are serialized as ISO 8601 strings.',
|
|
1039
1040
|
'<strong>Playground:</strong> The query playground embeds an iframe to a local prisma-query-builder-ui instance. It connects to your real database using the configured DATABASE_URL. It is disabled in production and when queryBuilder is set to false or queryBuilder.enabled is set to false.',
|