prisma-generator-express 1.40.0 → 1.41.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 +444 -12
- package/dist/generators/generateOperationCore.d.ts +3 -1
- package/dist/generators/generateOperationCore.js +266 -160
- package/dist/generators/generateOperationCore.js.map +1 -1
- package/dist/generators/generateRouteConfigType.d.ts +3 -1
- package/dist/generators/generateRouteConfigType.js +36 -31
- package/dist/generators/generateRouteConfigType.js.map +1 -1
- package/dist/generators/generateRouter.d.ts +4 -2
- package/dist/generators/generateRouter.js +130 -119
- package/dist/generators/generateRouter.js.map +1 -1
- package/dist/generators/generateRouterFastify.d.ts +3 -1
- package/dist/generators/generateRouterFastify.js +12 -10
- package/dist/generators/generateRouterFastify.js.map +1 -1
- package/dist/generators/generateRouterHono.d.ts +3 -1
- package/dist/generators/generateRouterHono.js +12 -9
- package/dist/generators/generateRouterHono.js.map +1 -1
- package/dist/generators/generateUnifiedDocs.d.ts +2 -1
- package/dist/generators/generateUnifiedDocs.js +6 -4
- package/dist/generators/generateUnifiedDocs.js.map +1 -1
- package/dist/index.js +16 -21
- package/dist/index.js.map +1 -1
- package/dist/utils/copyFiles.d.ts +2 -1
- package/dist/utils/copyFiles.js +39 -34
- package/dist/utils/copyFiles.js.map +1 -1
- package/dist/utils/importExt.d.ts +2 -0
- package/dist/utils/importExt.js +11 -0
- package/dist/utils/importExt.js.map +1 -0
- package/dist/utils/resolveImportStyle.d.ts +3 -0
- package/dist/utils/resolveImportStyle.js +211 -0
- package/dist/utils/resolveImportStyle.js.map +1 -0
- package/dist/utils/writeFileSafely.js +6 -9
- package/dist/utils/writeFileSafely.js.map +1 -1
- package/package.json +1 -1
- package/src/copy/routeConfig.express.ts +39 -5
- package/src/copy/routeConfig.fastify.ts +8 -4
- package/src/copy/routeConfig.hono.ts +7 -3
- package/src/copy/routeConfig.ts +42 -2
- package/src/generators/generateOperationCore.ts +273 -169
- package/src/generators/generateRouteConfigType.ts +42 -35
- package/src/generators/generateRouter.ts +134 -121
- package/src/generators/generateRouterFastify.ts +14 -9
- package/src/generators/generateRouterHono.ts +14 -8
- package/src/generators/generateUnifiedDocs.ts +8 -3
- package/src/index.ts +25 -47
- package/src/utils/copyFiles.ts +45 -45
- package/src/utils/importExt.ts +7 -0
- package/src/utils/resolveImportStyle.ts +187 -0
- package/src/utils/writeFileSafely.ts +6 -22
|
@@ -49,9 +49,8 @@ async function getPrettierOptions() {
|
|
|
49
49
|
}
|
|
50
50
|
async function writeFileSafely({ content, options, model, operation, }) {
|
|
51
51
|
const outputPath = options.generator.output?.value;
|
|
52
|
-
if (!outputPath)
|
|
52
|
+
if (!outputPath)
|
|
53
53
|
throw new Error('Output path not defined');
|
|
54
|
-
}
|
|
55
54
|
let filePath;
|
|
56
55
|
switch (operation) {
|
|
57
56
|
case 'combinedDocs':
|
|
@@ -64,15 +63,13 @@ async function writeFileSafely({ content, options, model, operation, }) {
|
|
|
64
63
|
filePath = path.join(outputPath, 'operationRuntime.ts');
|
|
65
64
|
break;
|
|
66
65
|
default:
|
|
67
|
-
if (!model)
|
|
68
|
-
throw new Error(
|
|
69
|
-
}
|
|
66
|
+
if (!model)
|
|
67
|
+
throw new Error('Model required for operation: ' + operation);
|
|
70
68
|
filePath = path.join(outputPath, model.name, `${model.name}${operation}.ts`);
|
|
71
69
|
}
|
|
72
70
|
const dirPath = path.dirname(filePath);
|
|
73
|
-
if (!fs.existsSync(dirPath))
|
|
71
|
+
if (!fs.existsSync(dirPath))
|
|
74
72
|
fs.mkdirSync(dirPath, { recursive: true });
|
|
75
|
-
}
|
|
76
73
|
let formattedContent;
|
|
77
74
|
try {
|
|
78
75
|
const resolvedOptions = await getPrettierOptions();
|
|
@@ -81,8 +78,8 @@ async function writeFileSafely({ content, options, model, operation, }) {
|
|
|
81
78
|
parser: 'typescript',
|
|
82
79
|
});
|
|
83
80
|
}
|
|
84
|
-
catch
|
|
85
|
-
console.warn(
|
|
81
|
+
catch {
|
|
82
|
+
console.warn('⚠️ Prettier formatting failed for ' + path.basename(filePath) + ', writing unformatted');
|
|
86
83
|
formattedContent = content;
|
|
87
84
|
}
|
|
88
85
|
fs.writeFileSync(filePath, formattedContent);
|
|
@@ -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,0CAyCC;AA5DD,uCAAwB;AACxB,2CAA4B;AAC5B,wDAA+B;AAS/B,IAAI,gBAAqD,CAAA;AAEzD,KAAK,UAAU,kBAAkB;IAC/B,IAAI,gBAAgB,KAAK,SAAS;QAAE,OAAO,gBAAgB,CAAA;IAC3D,gBAAgB,GAAG,MAAM,kBAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAA;IAC9D,OAAO,gBAAgB,CAAA;AACzB,CAAC;AAEM,KAAK,UAAU,eAAe,CAAC,EACpC,OAAO,EACP,OAAO,EACP,KAAK,EACL,SAAS,GACQ;IACjB,MAAM,UAAU,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,EAAE,KAAK,CAAA;IAClD,IAAI,CAAC,UAAU;QAAE,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAA;IAE3D,IAAI,QAAgB,CAAA;IACpB,QAAQ,SAAS,EAAE,CAAC;QAClB,KAAK,cAAc;YACjB,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,iBAAiB,CAAC,CAAA;YACnD,MAAK;QACP,KAAK,cAAc;YACjB,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,iBAAiB,CAAC,CAAA;YACnD,MAAK;QACP,KAAK,kBAAkB;YACrB,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,qBAAqB,CAAC,CAAA;YACvD,MAAK;QACP;YACE,IAAI,CAAC,KAAK;gBAAE,MAAM,IAAI,KAAK,CAAC,gCAAgC,GAAG,SAAS,CAAC,CAAA;YACzE,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,KAAK,CAAC,IAAI,EAAE,GAAG,KAAK,CAAC,IAAI,GAAG,SAAS,KAAK,CAAC,CAAA;IAChF,CAAC;IAED,MAAM,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAA;IACtC,IAAI,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC;QAAE,EAAE,CAAC,SAAS,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;IAEvE,IAAI,gBAAwB,CAAA;IAC5B,IAAI,CAAC;QACH,MAAM,eAAe,GAAG,MAAM,kBAAkB,EAAE,CAAA;QAClD,gBAAgB,GAAG,MAAM,kBAAQ,CAAC,MAAM,CAAC,OAAO,EAAE;YAChD,GAAG,eAAe;YAClB,MAAM,EAAE,YAAY;SACrB,CAAC,CAAA;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,CAAC,IAAI,CAAC,qCAAqC,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,GAAG,uBAAuB,CAAC,CAAA;QACvG,gBAAgB,GAAG,OAAO,CAAA;IAC5B,CAAC;IAED,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.41.0",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"license": "MIT",
|
|
@@ -1,16 +1,50 @@
|
|
|
1
|
-
import { Request, RequestHandler } from 'express'
|
|
2
|
-
import {
|
|
1
|
+
import type { Request, RequestHandler } from 'express'
|
|
2
|
+
import type {
|
|
3
3
|
BaseOperationConfig,
|
|
4
4
|
BaseRouteConfig,
|
|
5
|
+
ProgressiveStage,
|
|
6
|
+
ProgressiveVariantConfig,
|
|
5
7
|
QueryBuilderConfig,
|
|
6
8
|
OpenApiServerConfig,
|
|
7
9
|
OpenApiSecuritySchemeConfig,
|
|
8
10
|
} from './routeConfig'
|
|
9
11
|
|
|
10
|
-
export type {
|
|
12
|
+
export type {
|
|
13
|
+
QueryBuilderConfig,
|
|
14
|
+
OpenApiServerConfig,
|
|
15
|
+
OpenApiSecuritySchemeConfig,
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type {
|
|
19
|
+
ProgressivePatch,
|
|
20
|
+
ProgressiveStopResult,
|
|
21
|
+
ProgressiveStageResult,
|
|
22
|
+
ProgressiveStageContext,
|
|
23
|
+
ProgressiveStage,
|
|
24
|
+
ProgressiveVariantConfig,
|
|
25
|
+
} from './routeConfig'
|
|
11
26
|
|
|
12
27
|
export type OperationConfig<TShape = Record<string, any>> =
|
|
13
28
|
BaseOperationConfig<RequestHandler, TShape>
|
|
14
29
|
|
|
15
|
-
export type
|
|
16
|
-
|
|
30
|
+
export type ReadOperationConfig<TShape = Record<string, any>, TCtx = unknown> =
|
|
31
|
+
BaseOperationConfig<RequestHandler, TShape> & {
|
|
32
|
+
progressive?: Record<string, ProgressiveVariantConfig>
|
|
33
|
+
progressiveStages?: Record<string, ProgressiveStage<TCtx>>
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
type ReadOperationOverrides<TShape, TCtx> = {
|
|
37
|
+
findFirst?: ReadOperationConfig<TShape, TCtx>
|
|
38
|
+
findFirstOrThrow?: ReadOperationConfig<TShape, TCtx>
|
|
39
|
+
findUnique?: ReadOperationConfig<TShape, TCtx>
|
|
40
|
+
findUniqueOrThrow?: ReadOperationConfig<TShape, TCtx>
|
|
41
|
+
findMany?: ReadOperationConfig<TShape, TCtx>
|
|
42
|
+
findManyPaginated?: ReadOperationConfig<TShape, TCtx>
|
|
43
|
+
count?: ReadOperationConfig<TShape, TCtx>
|
|
44
|
+
aggregate?: ReadOperationConfig<TShape, TCtx>
|
|
45
|
+
groupBy?: ReadOperationConfig<TShape, TCtx>
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export type RouteConfig<TShape = Record<string, any>, TCtx = unknown> =
|
|
49
|
+
BaseRouteConfig<RequestHandler, Request, TShape, TCtx> &
|
|
50
|
+
ReadOperationOverrides<TShape, TCtx>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { FastifyRequest, FastifyReply } from 'fastify'
|
|
2
|
-
import {
|
|
2
|
+
import type {
|
|
3
3
|
BaseOperationConfig,
|
|
4
4
|
BaseRouteConfig,
|
|
5
5
|
QueryBuilderConfig,
|
|
@@ -7,7 +7,11 @@ import {
|
|
|
7
7
|
OpenApiSecuritySchemeConfig,
|
|
8
8
|
} from './routeConfig'
|
|
9
9
|
|
|
10
|
-
export type {
|
|
10
|
+
export type {
|
|
11
|
+
QueryBuilderConfig,
|
|
12
|
+
OpenApiServerConfig,
|
|
13
|
+
OpenApiSecuritySchemeConfig,
|
|
14
|
+
}
|
|
11
15
|
|
|
12
16
|
export type FastifyHookHandler = (
|
|
13
17
|
request: FastifyRequest,
|
|
@@ -17,5 +21,5 @@ export type FastifyHookHandler = (
|
|
|
17
21
|
export type OperationConfig<TShape = Record<string, any>> =
|
|
18
22
|
BaseOperationConfig<FastifyHookHandler, TShape>
|
|
19
23
|
|
|
20
|
-
export type RouteConfig<TShape = Record<string, any
|
|
21
|
-
BaseRouteConfig<FastifyHookHandler, FastifyRequest, TShape>
|
|
24
|
+
export type RouteConfig<TShape = Record<string, any>, TCtx = unknown> =
|
|
25
|
+
BaseRouteConfig<FastifyHookHandler, FastifyRequest, TShape, TCtx>
|
|
@@ -7,7 +7,11 @@ import type {
|
|
|
7
7
|
OpenApiSecuritySchemeConfig,
|
|
8
8
|
} from './routeConfig'
|
|
9
9
|
|
|
10
|
-
export type {
|
|
10
|
+
export type {
|
|
11
|
+
QueryBuilderConfig,
|
|
12
|
+
OpenApiServerConfig,
|
|
13
|
+
OpenApiSecuritySchemeConfig,
|
|
14
|
+
}
|
|
11
15
|
|
|
12
16
|
export type HonoHookHandler<Env extends { Variables: any } = any> = (
|
|
13
17
|
c: Context<Env>,
|
|
@@ -17,5 +21,5 @@ export type HonoHookHandler<Env extends { Variables: any } = any> = (
|
|
|
17
21
|
export type OperationConfig<TShape = Record<string, any>> =
|
|
18
22
|
BaseOperationConfig<HonoHookHandler, TShape>
|
|
19
23
|
|
|
20
|
-
export type RouteConfig<TShape = Record<string, any
|
|
21
|
-
BaseRouteConfig<HonoHookHandler, Context, TShape>
|
|
24
|
+
export type RouteConfig<TShape = Record<string, any>, TCtx = unknown> =
|
|
25
|
+
BaseRouteConfig<HonoHookHandler, Context, TShape, TCtx>
|
package/src/copy/routeConfig.ts
CHANGED
|
@@ -20,13 +20,53 @@ export interface OpenApiSecuritySchemeConfig {
|
|
|
20
20
|
description?: string
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
+
export type ProgressivePatch = {
|
|
24
|
+
key: string
|
|
25
|
+
value: unknown
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type ProgressiveStopResult<T = unknown> = {
|
|
29
|
+
stop: true
|
|
30
|
+
data: T
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type ProgressiveStageResult<T = unknown> =
|
|
34
|
+
| void
|
|
35
|
+
| ProgressivePatch
|
|
36
|
+
| ProgressivePatch[]
|
|
37
|
+
| ProgressiveStopResult<T>
|
|
38
|
+
|
|
39
|
+
export type ProgressiveStageContext<TContext = unknown, TPrisma = any> = {
|
|
40
|
+
ctx: TContext
|
|
41
|
+
req: any
|
|
42
|
+
res: any
|
|
43
|
+
prisma: TPrisma
|
|
44
|
+
variant: string
|
|
45
|
+
accumulated: Record<string, unknown>
|
|
46
|
+
signal: AbortSignal
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export type ProgressiveStage<TContext = unknown, TPrisma = any, T = unknown> = (
|
|
50
|
+
context: ProgressiveStageContext<TContext, TPrisma>,
|
|
51
|
+
) => Promise<ProgressiveStageResult<T>>
|
|
52
|
+
|
|
53
|
+
export type ProgressiveVariantConfig = {
|
|
54
|
+
enabled?: boolean
|
|
55
|
+
stages: string[]
|
|
56
|
+
}
|
|
57
|
+
|
|
23
58
|
export interface BaseOperationConfig<HookHandler, TShape = Record<string, any>> {
|
|
24
59
|
before?: HookHandler[]
|
|
25
60
|
after?: HookHandler[]
|
|
26
61
|
shape?: TShape
|
|
27
62
|
}
|
|
28
63
|
|
|
29
|
-
export interface BaseRouteConfig<
|
|
64
|
+
export interface BaseRouteConfig<
|
|
65
|
+
HookHandler,
|
|
66
|
+
RequestType,
|
|
67
|
+
TShape = Record<string, any>,
|
|
68
|
+
TCtx = unknown,
|
|
69
|
+
> {
|
|
30
70
|
enableAll?: boolean
|
|
31
71
|
addModelPrefix?: boolean
|
|
32
72
|
customUrlPrefix?: string
|
|
@@ -44,6 +84,7 @@ export interface BaseRouteConfig<HookHandler, RequestType, TShape = Record<strin
|
|
|
44
84
|
resolveVariant?: (request: RequestType) => string | undefined
|
|
45
85
|
variantHeader?: string
|
|
46
86
|
}
|
|
87
|
+
resolveContext?: (request: RequestType) => TCtx | Promise<TCtx>
|
|
47
88
|
queryBuilder?: QueryBuilderConfig | false
|
|
48
89
|
pagination?: {
|
|
49
90
|
defaultLimit?: number
|
|
@@ -71,5 +112,4 @@ export interface BaseRouteConfig<HookHandler, RequestType, TShape = Record<strin
|
|
|
71
112
|
}
|
|
72
113
|
|
|
73
114
|
export type OperationConfig = BaseOperationConfig<any>
|
|
74
|
-
|
|
75
115
|
export type RouteConfig = BaseRouteConfig<any, any>
|