prisma-generator-express 1.42.0 → 1.43.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/generators/generateFastifyHandler.js +17 -4
- package/dist/generators/generateFastifyHandler.js.map +1 -1
- package/dist/generators/generateHonoHandler.js +4 -4
- package/dist/generators/generateOperationCore.d.ts +0 -1
- package/dist/generators/generateOperationCore.js +34 -546
- package/dist/generators/generateOperationCore.js.map +1 -1
- package/dist/generators/generateRelationMeta.d.ts +13 -0
- package/dist/generators/generateRelationMeta.js +106 -0
- package/dist/generators/generateRelationMeta.js.map +1 -0
- package/dist/generators/generateRouteConfigType.js +4 -4
- package/dist/generators/generateRouteConfigType.js.map +1 -1
- package/dist/generators/generateRouter.js +51 -13
- package/dist/generators/generateRouter.js.map +1 -1
- package/dist/generators/generateRouterFastify.js +127 -384
- package/dist/generators/generateRouterFastify.js.map +1 -1
- package/dist/generators/generateRouterHono.js +48 -36
- package/dist/generators/generateRouterHono.js.map +1 -1
- package/dist/generators/generateUnifiedHandler.js +24 -8
- package/dist/generators/generateUnifiedHandler.js.map +1 -1
- package/dist/index.js +21 -5
- package/dist/index.js.map +1 -1
- package/dist/utils/copyFiles.js +12 -0
- package/dist/utils/copyFiles.js.map +1 -1
- package/dist/utils/writeFileSafely.js +3 -0
- package/dist/utils/writeFileSafely.js.map +1 -1
- package/package.json +1 -1
- package/src/copy/autoIncludePlanner.ts +299 -0
- package/src/copy/autoIncludeRuntime.ts +307 -0
- package/src/copy/operationRuntime.ts +603 -0
- package/src/copy/routeConfig.express.ts +5 -3
- package/src/copy/routeConfig.fastify.ts +2 -2
- package/src/copy/routeConfig.hono.ts +3 -3
- package/src/copy/routeConfig.ts +20 -9
- package/src/generators/generateFastifyHandler.ts +17 -4
- package/src/generators/generateHonoHandler.ts +4 -4
- package/src/generators/generateOperationCore.ts +34 -546
- package/src/generators/generateRelationMeta.ts +154 -0
- package/src/generators/generateRouteConfigType.ts +5 -5
- package/src/generators/generateRouter.ts +51 -13
- package/src/generators/generateRouterFastify.ts +127 -384
- package/src/generators/generateRouterHono.ts +48 -36
- package/src/generators/generateUnifiedHandler.ts +24 -8
- package/src/index.ts +25 -7
- package/src/utils/copyFiles.ts +13 -0
- package/src/utils/writeFileSafely.ts +3 -0
package/src/copy/routeConfig.ts
CHANGED
|
@@ -36,26 +36,37 @@ export type ProgressiveStageResult<T = unknown> =
|
|
|
36
36
|
| ProgressivePatch[]
|
|
37
37
|
| ProgressiveStopResult<T>
|
|
38
38
|
|
|
39
|
-
export type ProgressiveStageContext<TContext = unknown, TPrisma =
|
|
39
|
+
export type ProgressiveStageContext<TContext = unknown, TPrisma = unknown> = {
|
|
40
40
|
ctx: TContext
|
|
41
|
-
req:
|
|
42
|
-
res:
|
|
41
|
+
req: unknown
|
|
42
|
+
res: unknown
|
|
43
43
|
prisma: TPrisma
|
|
44
44
|
variant: string
|
|
45
45
|
accumulated: Record<string, unknown>
|
|
46
46
|
signal: AbortSignal
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
export type ProgressiveStage<TContext = unknown, TPrisma =
|
|
49
|
+
export type ProgressiveStage<TContext = unknown, TPrisma = unknown, T = unknown> = (
|
|
50
50
|
context: ProgressiveStageContext<TContext, TPrisma>,
|
|
51
51
|
) => Promise<ProgressiveStageResult<T>>
|
|
52
52
|
|
|
53
|
-
export type
|
|
53
|
+
export type ManualProgressiveVariantConfig = {
|
|
54
54
|
enabled?: boolean
|
|
55
|
+
mode?: 'manual'
|
|
55
56
|
stages: string[]
|
|
56
57
|
}
|
|
57
58
|
|
|
58
|
-
export
|
|
59
|
+
export type AutoIncludeProgressiveVariantConfig = {
|
|
60
|
+
enabled?: boolean
|
|
61
|
+
mode: 'autoInclude'
|
|
62
|
+
fallback?: 'singleResult' | 'error'
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export type ProgressiveVariantConfig =
|
|
66
|
+
| ManualProgressiveVariantConfig
|
|
67
|
+
| AutoIncludeProgressiveVariantConfig
|
|
68
|
+
|
|
69
|
+
export interface BaseOperationConfig<HookHandler, TShape = Record<string, unknown>> {
|
|
59
70
|
before?: HookHandler[]
|
|
60
71
|
after?: HookHandler[]
|
|
61
72
|
shape?: TShape
|
|
@@ -64,7 +75,7 @@ export interface BaseOperationConfig<HookHandler, TShape = Record<string, any>>
|
|
|
64
75
|
export interface BaseRouteConfig<
|
|
65
76
|
HookHandler,
|
|
66
77
|
RequestType,
|
|
67
|
-
TShape = Record<string,
|
|
78
|
+
TShape = Record<string, unknown>,
|
|
68
79
|
TCtx = unknown,
|
|
69
80
|
> {
|
|
70
81
|
enableAll?: boolean
|
|
@@ -111,5 +122,5 @@ export interface BaseRouteConfig<
|
|
|
111
122
|
groupBy?: BaseOperationConfig<HookHandler, TShape>
|
|
112
123
|
}
|
|
113
124
|
|
|
114
|
-
export type OperationConfig = BaseOperationConfig<
|
|
115
|
-
export type RouteConfig = BaseRouteConfig<
|
|
125
|
+
export type OperationConfig = BaseOperationConfig<unknown>
|
|
126
|
+
export type RouteConfig = BaseRouteConfig<unknown, unknown>
|
|
@@ -54,7 +54,7 @@ export async function ${exportName}(
|
|
|
54
54
|
_reply: FastifyReply,
|
|
55
55
|
): Promise<void> {
|
|
56
56
|
const data = await core.${coreFnName(op)}(buildContext(request))
|
|
57
|
-
;(request as
|
|
57
|
+
;(request as FastifyExtended).resultData = data
|
|
58
58
|
}`
|
|
59
59
|
}).join('\n')
|
|
60
60
|
|
|
@@ -68,8 +68,9 @@ export async function ${exportName}(
|
|
|
68
68
|
_reply: FastifyReply,
|
|
69
69
|
): Promise<void> {
|
|
70
70
|
const data = await core.${coreFnName(op)}(buildContext(request))
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
const ext = request as FastifyExtended
|
|
72
|
+
ext.resultData = data
|
|
73
|
+
ext.resultStatus = ${statusCode}
|
|
73
74
|
}`
|
|
74
75
|
}).join('\n')
|
|
75
76
|
|
|
@@ -77,8 +78,20 @@ export async function ${exportName}(
|
|
|
77
78
|
import * as core from './${modelName}Core'
|
|
78
79
|
import type { OperationContext } from '../operationRuntime'
|
|
79
80
|
|
|
81
|
+
type FastifyExtended = FastifyRequest & {
|
|
82
|
+
prisma?: unknown
|
|
83
|
+
postgres?: unknown
|
|
84
|
+
sqlite?: unknown
|
|
85
|
+
parsedQuery?: Record<string, unknown>
|
|
86
|
+
routeConfig?: { pagination?: OperationContext['paginationConfig'] }
|
|
87
|
+
guardShape?: Record<string, unknown>
|
|
88
|
+
guardCaller?: string
|
|
89
|
+
resultData?: unknown
|
|
90
|
+
resultStatus?: number
|
|
91
|
+
}
|
|
92
|
+
|
|
80
93
|
function buildContext(request: FastifyRequest): OperationContext {
|
|
81
|
-
const req = request as
|
|
94
|
+
const req = request as FastifyExtended
|
|
82
95
|
return {
|
|
83
96
|
prisma: req.prisma,
|
|
84
97
|
postgres: req.postgres,
|
|
@@ -72,12 +72,12 @@ import * as core from './${modelName}Core'
|
|
|
72
72
|
import type { OperationContext } from '../operationRuntime'
|
|
73
73
|
|
|
74
74
|
type HonoVariables = {
|
|
75
|
-
prisma:
|
|
76
|
-
postgres?:
|
|
77
|
-
sqlite?:
|
|
75
|
+
prisma: unknown
|
|
76
|
+
postgres?: unknown
|
|
77
|
+
sqlite?: unknown
|
|
78
78
|
parsedQuery?: Record<string, unknown>
|
|
79
79
|
body?: unknown
|
|
80
|
-
routeConfig?:
|
|
80
|
+
routeConfig?: { pagination?: OperationContext['paginationConfig'] }
|
|
81
81
|
guardShape?: Record<string, unknown>
|
|
82
82
|
guardCaller?: string
|
|
83
83
|
resultData?: unknown
|