prisma-generator-express 1.42.0 → 1.44.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.d.ts +2 -0
- package/dist/generators/generateFastifyHandler.js +21 -6
- package/dist/generators/generateFastifyHandler.js.map +1 -1
- package/dist/generators/generateHonoHandler.d.ts +2 -0
- package/dist/generators/generateHonoHandler.js +8 -6
- package/dist/generators/generateHonoHandler.js.map +1 -1
- 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 +110 -0
- package/dist/generators/generateRelationMeta.js.map +1 -0
- package/dist/generators/generateRouteConfigType.js +13 -5
- package/dist/generators/generateRouteConfigType.js.map +1 -1
- package/dist/generators/generateRouter.js +83 -19
- 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.d.ts +2 -0
- package/dist/generators/generateUnifiedHandler.js +28 -10
- package/dist/generators/generateUnifiedHandler.js.map +1 -1
- package/dist/generators/generateUnifiedScalarUI.d.ts +2 -0
- package/dist/generators/generateUnifiedScalarUI.js +19 -16
- package/dist/generators/generateUnifiedScalarUI.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 +2 -2
- package/dist/utils/writeFileSafely.js.map +1 -1
- package/package.json +1 -1
- package/src/copy/autoIncludePlanner.ts +354 -0
- package/src/copy/autoIncludeRuntime.ts +362 -0
- package/src/copy/operationRuntime.ts +614 -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 +23 -6
- package/src/generators/generateHonoHandler.ts +10 -6
- package/src/generators/generateOperationCore.ts +34 -546
- package/src/generators/generateRelationMeta.ts +160 -0
- package/src/generators/generateRouteConfigType.ts +13 -6
- package/src/generators/generateRouter.ts +83 -19
- package/src/generators/generateRouterFastify.ts +127 -384
- package/src/generators/generateRouterHono.ts +48 -36
- package/src/generators/generateUnifiedHandler.ts +30 -10
- package/src/generators/generateUnifiedScalarUI.ts +21 -16
- package/src/index.ts +31 -13
- package/src/utils/copyFiles.ts +13 -0
- package/src/utils/writeFileSafely.ts +2 -2
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateFastifyHandler = generateFastifyHandler;
|
|
4
4
|
const strings_1 = require("../utils/strings");
|
|
5
|
+
const importExt_1 = require("../utils/importExt");
|
|
5
6
|
const CORE_NAME_MAP = {
|
|
6
7
|
delete: 'deleteUnique',
|
|
7
8
|
};
|
|
@@ -36,6 +37,7 @@ const CREATED_OPS = new Set([
|
|
|
36
37
|
'createManyAndReturn',
|
|
37
38
|
]);
|
|
38
39
|
function generateFastifyHandler(options) {
|
|
40
|
+
const ext = (0, importExt_1.importExt)(options.importStyle);
|
|
39
41
|
const modelName = options.model.name;
|
|
40
42
|
const prefix = (0, strings_1.toCamelCase)(modelName);
|
|
41
43
|
const readHandlers = READ_OPS.map((op) => {
|
|
@@ -46,7 +48,7 @@ export async function ${exportName}(
|
|
|
46
48
|
_reply: FastifyReply,
|
|
47
49
|
): Promise<void> {
|
|
48
50
|
const data = await core.${coreFnName(op)}(buildContext(request))
|
|
49
|
-
;(request as
|
|
51
|
+
;(request as FastifyExtended).resultData = data
|
|
50
52
|
}`;
|
|
51
53
|
}).join('\n');
|
|
52
54
|
const writeHandlers = WRITE_OPS.map((op) => {
|
|
@@ -58,16 +60,29 @@ export async function ${exportName}(
|
|
|
58
60
|
_reply: FastifyReply,
|
|
59
61
|
): Promise<void> {
|
|
60
62
|
const data = await core.${coreFnName(op)}(buildContext(request))
|
|
61
|
-
|
|
62
|
-
|
|
63
|
+
const ext = request as FastifyExtended
|
|
64
|
+
ext.resultData = data
|
|
65
|
+
ext.resultStatus = ${statusCode}
|
|
63
66
|
}`;
|
|
64
67
|
}).join('\n');
|
|
65
68
|
return `import type { FastifyRequest, FastifyReply } from 'fastify'
|
|
66
|
-
import * as core from './${modelName}Core'
|
|
67
|
-
import type { OperationContext } from '../operationRuntime'
|
|
69
|
+
import * as core from './${modelName}Core${ext}'
|
|
70
|
+
import type { OperationContext } from '../operationRuntime${ext}'
|
|
71
|
+
|
|
72
|
+
type FastifyExtended = FastifyRequest & {
|
|
73
|
+
prisma?: unknown
|
|
74
|
+
postgres?: unknown
|
|
75
|
+
sqlite?: unknown
|
|
76
|
+
parsedQuery?: Record<string, unknown>
|
|
77
|
+
routeConfig?: { pagination?: OperationContext['paginationConfig'] }
|
|
78
|
+
guardShape?: Record<string, unknown>
|
|
79
|
+
guardCaller?: string
|
|
80
|
+
resultData?: unknown
|
|
81
|
+
resultStatus?: number
|
|
82
|
+
}
|
|
68
83
|
|
|
69
84
|
function buildContext(request: FastifyRequest): OperationContext {
|
|
70
|
-
const req = request as
|
|
85
|
+
const req = request as FastifyExtended
|
|
71
86
|
return {
|
|
72
87
|
prisma: req.prisma,
|
|
73
88
|
postgres: req.postgres,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateFastifyHandler.js","sourceRoot":"","sources":["../../src/generators/generateFastifyHandler.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"generateFastifyHandler.js","sourceRoot":"","sources":["../../src/generators/generateFastifyHandler.ts"],"names":[],"mappings":";;AA2CA,wDAqEC;AA/GD,8CAA8C;AAE9C,kDAA8C;AAE9C,MAAM,aA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E,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAA;QACzE,MAAM,UAAU,GAAG,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAA;QAElD,OAAO;wBACa,UAAU;;;;4BAIN,UAAU,CAAC,EAAE,CAAC;;;uBAGnB,UAAU;EAC/B,CAAA;IACA,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAEb,OAAO;2BACkB,SAAS,OAAO,GAAG;4DACc,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;EA2B7D,YAAY;EACZ,aAAa;CACd,CAAA;AACD,CAAC"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateHonoHandler = generateHonoHandler;
|
|
4
4
|
const strings_1 = require("../utils/strings");
|
|
5
|
+
const importExt_1 = require("../utils/importExt");
|
|
5
6
|
const CORE_NAME_MAP = {
|
|
6
7
|
delete: 'deleteUnique',
|
|
7
8
|
};
|
|
@@ -36,6 +37,7 @@ const CREATED_OPS = new Set([
|
|
|
36
37
|
'createManyAndReturn',
|
|
37
38
|
]);
|
|
38
39
|
function generateHonoHandler(options) {
|
|
40
|
+
const ext = (0, importExt_1.importExt)(options.importStyle);
|
|
39
41
|
const modelName = options.model.name;
|
|
40
42
|
const prefix = (0, strings_1.toCamelCase)(modelName);
|
|
41
43
|
const readHandlers = READ_OPS.map((op) => {
|
|
@@ -57,16 +59,16 @@ export async function ${exportName}(c: Context<HonoEnv>): Promise<void> {
|
|
|
57
59
|
}`;
|
|
58
60
|
}).join('\n');
|
|
59
61
|
return `import type { Context } from 'hono'
|
|
60
|
-
import * as core from './${modelName}Core'
|
|
61
|
-
import type { OperationContext } from '../operationRuntime'
|
|
62
|
+
import * as core from './${modelName}Core${ext}'
|
|
63
|
+
import type { OperationContext } from '../operationRuntime${ext}'
|
|
62
64
|
|
|
63
65
|
type HonoVariables = {
|
|
64
|
-
prisma:
|
|
65
|
-
postgres?:
|
|
66
|
-
sqlite?:
|
|
66
|
+
prisma: unknown
|
|
67
|
+
postgres?: unknown
|
|
68
|
+
sqlite?: unknown
|
|
67
69
|
parsedQuery?: Record<string, unknown>
|
|
68
70
|
body?: unknown
|
|
69
|
-
routeConfig?:
|
|
71
|
+
routeConfig?: { pagination?: OperationContext['paginationConfig'] }
|
|
70
72
|
guardShape?: Record<string, unknown>
|
|
71
73
|
guardCaller?: string
|
|
72
74
|
resultData?: unknown
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateHonoHandler.js","sourceRoot":"","sources":["../../src/generators/generateHonoHandler.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"generateHonoHandler.js","sourceRoot":"","sources":["../../src/generators/generateHonoHandler.ts"],"names":[],"mappings":";;AA2CA,kDAgEC;AA1GD,8CAA8C;AAE9C,kDAA8C;AAE9C,MAAM,aAAa,GAA2B;IAC5C,MAAM,EAAE,cAAc;CACvB,CAAA;AAED,SAAS,UAAU,CAAC,EAAU;IAC5B,OAAO,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,CAAA;AAChC,CAAC;AAED,MAAM,QAAQ,GAAG;IACf,UAAU;IACV,WAAW;IACX,kBAAkB;IAClB,YAAY;IACZ,mBAAmB;IACnB,mBAAmB;IACnB,WAAW;IACX,OAAO;IACP,SAAS;CACV,CAAA;AAED,MAAM,SAAS,GAAG;IAChB,QAAQ;IACR,YAAY;IACZ,qBAAqB;IACrB,QAAQ;IACR,YAAY;IACZ,qBAAqB;IACrB,QAAQ;IACR,QAAQ;IACR,YAAY;CACb,CAAA;AAED,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC;IAC1B,QAAQ;IACR,YAAY;IACZ,qBAAqB;CACtB,CAAC,CAAA;AAEF,SAAgB,mBAAmB,C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
import { ImportStyle } from '../utils/resolveImportStyle';
|
|
3
|
-
export declare function generateOperationRuntime(importStyle: ImportStyle): string;
|
|
4
3
|
export interface ModelCoreOptions {
|
|
5
4
|
model: DMMF.Model;
|
|
6
5
|
importStyle: ImportStyle;
|