prisma-generator-express 1.31.0 → 1.33.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/generateRouter.js +1 -1
- package/dist/generators/generateRouterFastify.js +1 -1
- package/dist/generators/generateUnifiedDocs.js +1 -1
- package/dist/generators/generateUnifiedDocs.js.map +1 -1
- package/dist/index.js +16 -1
- package/dist/index.js.map +1 -1
- package/dist/utils/copyFiles.js +12 -27
- package/dist/utils/copyFiles.js.map +1 -1
- package/package.json +1 -1
- package/src/copy/routeConfig.express.ts +14 -0
- package/src/copy/routeConfig.fastify.ts +19 -0
- package/src/copy/routeConfig.ts +31 -34
- package/src/generators/generateRouter.ts +1 -1
- package/src/generators/generateRouterFastify.ts +1 -1
- package/src/generators/generateUnifiedDocs.ts +1 -1
- package/src/index.ts +17 -1
- package/src/utils/copyFiles.ts +15 -32
|
@@ -45,7 +45,7 @@ import {
|
|
|
45
45
|
${modelName}Count,
|
|
46
46
|
${modelName}GroupBy
|
|
47
47
|
} from './${modelName}Handlers.js'
|
|
48
|
-
import type { RouteConfig } from '../routeConfig.js'
|
|
48
|
+
import type { RouteConfig } from '../routeConfig.target.js'
|
|
49
49
|
import { parseQueryParams } from '../parseQueryParams.js'
|
|
50
50
|
import { buildModelOpenApi } from '../buildModelOpenApi.js'
|
|
51
51
|
import { transformResult } from '../operationRuntime.js'
|
|
@@ -44,7 +44,7 @@ import {
|
|
|
44
44
|
${modelName}Count,
|
|
45
45
|
${modelName}GroupBy,
|
|
46
46
|
} from './${modelName}Handlers.js'
|
|
47
|
-
import type { RouteConfig, FastifyHookHandler } from '../routeConfig.js'
|
|
47
|
+
import type { RouteConfig, FastifyHookHandler } from '../routeConfig.target.js'
|
|
48
48
|
import { parseQueryParams } from '../parseQueryParams.js'
|
|
49
49
|
import { buildModelOpenApi } from '../buildModelOpenApi.js'
|
|
50
50
|
import { mapError, transformResult } from '../operationRuntime.js'
|
|
@@ -11,7 +11,7 @@ function generateUnifiedDocs(models, target = 'express') {
|
|
|
11
11
|
const frameworkImport = target === 'fastify'
|
|
12
12
|
? `import type { FastifyInstance, FastifyRequest, FastifyReply } from 'fastify'`
|
|
13
13
|
: `import { Request, Response } from 'express'`;
|
|
14
|
-
const routeConfigImport = `import type { RouteConfig } from './routeConfig.js'`;
|
|
14
|
+
const routeConfigImport = `import type { RouteConfig } from './routeConfig.target.js'`;
|
|
15
15
|
const handlerType = target === 'fastify'
|
|
16
16
|
? `(config: any) => (request: FastifyRequest, reply: FastifyReply) => Promise<void>`
|
|
17
17
|
: `(config: any) => (req: Request, res: Response) => any`;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateUnifiedDocs.js","sourceRoot":"","sources":["../../src/generators/generateUnifiedDocs.ts"],"names":[],"mappings":";;AAEA,kDAkLC;AAlLD,SAAgB,mBAAmB,CACjC,MAAgB,EAChB,SAAiB,SAAS;IAE1B,MAAM,OAAO,GAAG,MAAM;SACnB,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,YAAY,KAAK,kBAAkB,KAAK,IAAI,KAAK,UAAU,CAAC;SAC3E,IAAI,CAAC,IAAI,CAAC,CAAA;IAEb,MAAM,eAAe,GAAG,MAAM;SAC3B,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,KAAK,KAAK,MAAM,CAAC;SAC1C,IAAI,CAAC,KAAK,CAAC,CAAA;IAEd,MAAM,eAAe,GACnB,MAAM,KAAK,SAAS;QAClB,CAAC,CAAC,8EAA8E;QAChF,CAAC,CAAC,6CAA6C,CAAA;IAEnD,MAAM,iBAAiB,GAAG,
|
|
1
|
+
{"version":3,"file":"generateUnifiedDocs.js","sourceRoot":"","sources":["../../src/generators/generateUnifiedDocs.ts"],"names":[],"mappings":";;AAEA,kDAkLC;AAlLD,SAAgB,mBAAmB,CACjC,MAAgB,EAChB,SAAiB,SAAS;IAE1B,MAAM,OAAO,GAAG,MAAM;SACnB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;;;;;;;EAqBP,CAAA;AACF,CAAC;AAED,SAAS,2BAA2B;IAClC,OAAO;;;;;;;;;;;;;;;;;;;;;EAqBP,CAAA;AACF,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
const generator_helper_1 = require("@prisma/generator-helper");
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
4
8
|
const generateUnifiedHandler_js_1 = require("./generators/generateUnifiedHandler.js");
|
|
5
9
|
const generateFastifyHandler_js_1 = require("./generators/generateFastifyHandler.js");
|
|
6
10
|
const generateRouter_js_1 = require("./generators/generateRouter.js");
|
|
@@ -19,18 +23,29 @@ function getTarget(options) {
|
|
|
19
23
|
return raw;
|
|
20
24
|
throw new Error(`Invalid target "${raw}". Expected "express" or "fastify".`);
|
|
21
25
|
}
|
|
26
|
+
function resolveOutputPath(options, target) {
|
|
27
|
+
const explicit = options.generator.output?.value;
|
|
28
|
+
if (explicit && explicit.length > 0) {
|
|
29
|
+
return explicit;
|
|
30
|
+
}
|
|
31
|
+
const schemaDir = path_1.default.dirname(options.schemaPath);
|
|
32
|
+
return path_1.default.join(schemaDir, 'generated', target);
|
|
33
|
+
}
|
|
22
34
|
(0, generator_helper_1.generatorHandler)({
|
|
23
35
|
onManifest() {
|
|
24
36
|
return {
|
|
25
37
|
version: require('../package.json').version,
|
|
26
|
-
defaultOutput: '
|
|
38
|
+
defaultOutput: '',
|
|
27
39
|
prettyName: constants_js_1.GENERATOR_NAME,
|
|
28
40
|
};
|
|
29
41
|
},
|
|
30
42
|
async onGenerate(options) {
|
|
31
43
|
const target = getTarget(options);
|
|
44
|
+
const outputPath = resolveOutputPath(options, target);
|
|
45
|
+
options.generator.output = { value: outputPath, fromEnvVar: null };
|
|
32
46
|
console.log(`\n═══ Prisma Generator (${target.toUpperCase()}) ═══`);
|
|
33
47
|
console.log(` Target: ${target}`);
|
|
48
|
+
console.log(` Output: ${outputPath}`);
|
|
34
49
|
await (0, copyFiles_js_1.copyFiles)(options, target);
|
|
35
50
|
await (0, writeFileSafely_js_1.writeFileSafely)({
|
|
36
51
|
content: (0, generateOperationCore_js_1.generateOperationRuntime)(),
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;AAAA,+DAIiC;AACjC,gDAAuB;AACvB,sFAA+E;AAC/E,sFAA+E;AAC/E,sEAAuE;AACvE,oFAAqF;AACrF,wFAAiF;AACjF,gFAAyE;AACzE,8FAAuF;AACvF,oFAG8C;AAC9C,oGAGsD;AACtD,mEAA4D;AAC5D,uDAAgD;AAChD,iDAAuD;AAEvD,SAAS,SAAS,CAAC,OAAyB;IAC1C,MAAM,GAAG,GAAG,MAAM,CACf,OAAO,CAAC,SAAS,CAAC,MAAkC,CAAC,MAAM,IAAI,SAAS,CAC1E,CAAC,WAAW,EAAE,CAAA;IACf,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,SAAS;QAAE,OAAO,GAAG,CAAA;IACtD,MAAM,IAAI,KAAK,CAAC,mBAAmB,GAAG,qCAAqC,CAAC,CAAA;AAC9E,CAAC;AAED,SAAS,iBAAiB,CAAC,OAAyB,EAAE,MAAc;IAClE,MAAM,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAC,MAAM,EAAE,KAAK,CAAA;IAEhD,IAAI,QAAQ,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACpC,OAAO,QAAQ,CAAA;IACjB,CAAC;IAED,MAAM,SAAS,GAAG,cAAI,CAAC,OAA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gBACF,OAAO;gBACP,KAAK,EAAE,KAAmB;gBAC1B,SAAS,EAAE,MAAM;aAClB,CAAC,CAAA;QACJ,CAAC;QAED,MAAM,IAAA,oCAAe,EAAC;YACpB,OAAO,EAAE,IAAA,4CAAmB,EAAC,UAAU,EAAE,MAAM,CAAC;YAChD,OAAO;YACP,SAAS,EAAE,cAAc;SAC1B,CAAC,CAAA;QAEF,MAAM,IAAA,oCAAe,EAAC;YACpB,OAAO,EAAE,IAAA,0DAA0B,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,mCAAmC,CAAC,CAAA;QAChD,OAAO,CAAC,GAAG,CAAC,kCAAkC,CAAC,CAAA;QAC/C,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;IACjB,CAAC;CACF,CAAC,CAAA"}
|
package/dist/utils/copyFiles.js
CHANGED
|
@@ -41,11 +41,9 @@ const SHARED_FILES = [
|
|
|
41
41
|
'buildModelOpenApi.ts',
|
|
42
42
|
'operationDefinitions.ts',
|
|
43
43
|
'misc.ts',
|
|
44
|
+
'routeConfig.ts',
|
|
45
|
+
'docsRenderer.ts',
|
|
44
46
|
];
|
|
45
|
-
const TARGET_FILES = {
|
|
46
|
-
express: ['routeConfig.ts'],
|
|
47
|
-
fastify: ['routeConfig.ts'],
|
|
48
|
-
};
|
|
49
47
|
function resolveTemplateDir(subpath) {
|
|
50
48
|
const fromSrc = path.join(__dirname, '..', '..', 'src', subpath);
|
|
51
49
|
if (fs.existsSync(fromSrc))
|
|
@@ -60,22 +58,13 @@ function resolveTemplateDir(subpath) {
|
|
|
60
58
|
` __dirname: ${__dirname}\n` +
|
|
61
59
|
` Ensure template files are included in the published package.`);
|
|
62
60
|
}
|
|
63
|
-
function getTargetSourceDir(copyBase, target) {
|
|
64
|
-
if (target === 'express')
|
|
65
|
-
return copyBase;
|
|
66
|
-
const targetDir = path.join(copyBase, target);
|
|
67
|
-
if (!fs.existsSync(targetDir)) {
|
|
68
|
-
throw new Error(`Target template directory not found: ${targetDir}\n` +
|
|
69
|
-
` Expected directory for target "${target}".`);
|
|
70
|
-
}
|
|
71
|
-
return targetDir;
|
|
72
|
-
}
|
|
73
61
|
function escapeRegex(str) {
|
|
74
62
|
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
|
75
63
|
}
|
|
76
64
|
function copyFileSync(srcDir, destDir, filename, options) {
|
|
77
65
|
const srcPath = path.join(srcDir, filename);
|
|
78
|
-
const
|
|
66
|
+
const destFilename = options?.destFilename || filename;
|
|
67
|
+
const destPath = path.join(destDir, destFilename);
|
|
79
68
|
if (!fs.existsSync(srcPath)) {
|
|
80
69
|
if (options?.required) {
|
|
81
70
|
return `Required file not found: ${srcPath}`;
|
|
@@ -116,18 +105,14 @@ async function copyFiles(options, target) {
|
|
|
116
105
|
if (err)
|
|
117
106
|
errors.push(err);
|
|
118
107
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
const err = copyFileSync(targetSrcDir, outputPath, file, { required: true });
|
|
128
|
-
if (err)
|
|
129
|
-
errors.push(err);
|
|
130
|
-
}
|
|
108
|
+
const targetConfigFile = `routeConfig.${target}.ts`;
|
|
109
|
+
const err = copyFileSync(copyBase, outputPath, targetConfigFile, {
|
|
110
|
+
required: true,
|
|
111
|
+
destFilename: 'routeConfig.target.ts',
|
|
112
|
+
importRewrites: [{ from: './routeConfig', to: './routeConfig' }],
|
|
113
|
+
});
|
|
114
|
+
if (err)
|
|
115
|
+
errors.push(err);
|
|
131
116
|
const clientDir = path.join(outputPath, 'client');
|
|
132
117
|
if (!fs.existsSync(clientDir)) {
|
|
133
118
|
fs.mkdirSync(clientDir, { recursive: true });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"copyFiles.js","sourceRoot":"","sources":["../../src/utils/copyFiles.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"copyFiles.js","sourceRoot":"","sources":["../../src/utils/copyFiles.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyFA,8BAoDC;AA5ID,uCAAwB;AACxB,2CAA4B;AAG5B,MAAM,YAAY,GAAG;IACnB,qBAAqB;IACrB,sBAAsB;IACtB,yBAAyB;IACzB,SAAS;IACT,gBAAgB;IAChB,iBAAiB;CAClB,CAAA;AAQD,SAAS,kBAAkB,CAAC,OAAe;IACzC,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,CAAA;IAChE,IAAI,EAAE,CAAC,UAAU,CAAC,OAAO,CAAC;QAAE,OAAO,OAAO,CAAA;IAE1C,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,EAAE,OAAO,CAAC,CAAA;IACpD,IAAI,EAAE,CAAC,UAAU,CAAC,QAAQ,CAAC;QAAE,OAAO,QAAQ,CAAA;IAE5C,MAAM,IAAI,KAAK,CACb,uBAAuB,OAAO,gBAAgB;QAC9C,eAAe;QACf,OAAO,OAAO,IAAI;QAClB,OAAO,QAAQ,IAAI;QACnB,gBAAgB,SAAS,IAAI;QAC7B,gEAAgE,CACjE,CAAA;AACH,CAAC;AAED,SAAS,WAAW,CAAC,GAAW;IAC9B,OAAO,GAAG,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAA;AACnD,CAAC;AAED,SAAS,YAAY,CACnB,MAAc,EACd,OAAe,EACf,QAAgB,EAChB,OA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MAAM,YAAY,GAAG,kBAAkB,CAAC,QAAQ,CAAC,CAAA;IACjD,MAAM,SAAS,GAAG,YAAY,CAC5B,YAAY,EACZ,SAAS,EACT,sBAAsB,EACtB;QACE,QAAQ,EAAE,IAAI;QACd,cAAc,EAAE,CAAC,EAAE,IAAI,EAAE,iBAAiB,EAAE,EAAE,EAAE,YAAY,EAAE,CAAC;KAChE,CACF,CAAA;IACD,IAAI,SAAS;QAAE,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;IAErC,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACtB,MAAM,IAAI,KAAK,CACb,kBAAkB,MAAM,CAAC,MAAM,sBAAsB;YACrD,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;YACxC,iBAAiB,QAAQ,EAAE;YAC3B,kBAAkB,SAAS,EAAE,CAC9B,CAAA;IACH,CAAC;IAED,OAAO,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAA;AACtD,CAAC"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Request, RequestHandler } from 'express'
|
|
2
|
+
import {
|
|
3
|
+
BaseOperationConfig,
|
|
4
|
+
BaseRouteConfig,
|
|
5
|
+
QueryBuilderConfig,
|
|
6
|
+
OpenApiServerConfig,
|
|
7
|
+
OpenApiSecuritySchemeConfig,
|
|
8
|
+
} from './routeConfig'
|
|
9
|
+
|
|
10
|
+
export type { QueryBuilderConfig, OpenApiServerConfig, OpenApiSecuritySchemeConfig }
|
|
11
|
+
|
|
12
|
+
export type OperationConfig = BaseOperationConfig<RequestHandler>
|
|
13
|
+
|
|
14
|
+
export type RouteConfig = BaseRouteConfig<RequestHandler, Request>
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { FastifyRequest, FastifyReply } from 'fastify'
|
|
2
|
+
import {
|
|
3
|
+
BaseOperationConfig,
|
|
4
|
+
BaseRouteConfig,
|
|
5
|
+
QueryBuilderConfig,
|
|
6
|
+
OpenApiServerConfig,
|
|
7
|
+
OpenApiSecuritySchemeConfig,
|
|
8
|
+
} from './routeConfig'
|
|
9
|
+
|
|
10
|
+
export type { QueryBuilderConfig, OpenApiServerConfig, OpenApiSecuritySchemeConfig }
|
|
11
|
+
|
|
12
|
+
export type FastifyHookHandler = (
|
|
13
|
+
request: FastifyRequest,
|
|
14
|
+
reply: FastifyReply,
|
|
15
|
+
) => Promise<void> | void
|
|
16
|
+
|
|
17
|
+
export type OperationConfig = BaseOperationConfig<FastifyHookHandler>
|
|
18
|
+
|
|
19
|
+
export type RouteConfig = BaseRouteConfig<FastifyHookHandler, FastifyRequest>
|
package/src/copy/routeConfig.ts
CHANGED
|
@@ -1,16 +1,3 @@
|
|
|
1
|
-
import type { FastifyRequest, FastifyReply } from 'fastify'
|
|
2
|
-
|
|
3
|
-
export type FastifyHookHandler = (
|
|
4
|
-
request: FastifyRequest,
|
|
5
|
-
reply: FastifyReply,
|
|
6
|
-
) => Promise<void> | void
|
|
7
|
-
|
|
8
|
-
export interface OperationConfig {
|
|
9
|
-
before?: FastifyHookHandler[]
|
|
10
|
-
after?: FastifyHookHandler[]
|
|
11
|
-
shape?: Record<string, any>
|
|
12
|
-
}
|
|
13
|
-
|
|
14
1
|
export interface QueryBuilderConfig {
|
|
15
2
|
enabled?: boolean
|
|
16
3
|
port?: number
|
|
@@ -33,7 +20,13 @@ export interface OpenApiSecuritySchemeConfig {
|
|
|
33
20
|
description?: string
|
|
34
21
|
}
|
|
35
22
|
|
|
36
|
-
export interface
|
|
23
|
+
export interface BaseOperationConfig<HookHandler> {
|
|
24
|
+
before?: HookHandler[]
|
|
25
|
+
after?: HookHandler[]
|
|
26
|
+
shape?: Record<string, any>
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface BaseRouteConfig<HookHandler, RequestType> {
|
|
37
30
|
enableAll?: boolean
|
|
38
31
|
addModelPrefix?: boolean
|
|
39
32
|
customUrlPrefix?: string
|
|
@@ -49,7 +42,7 @@ export interface RouteConfig {
|
|
|
49
42
|
openApiSecurity?: Record<string, string[]>[]
|
|
50
43
|
|
|
51
44
|
guard?: {
|
|
52
|
-
resolveVariant?: (request:
|
|
45
|
+
resolveVariant?: (request: RequestType) => string | undefined
|
|
53
46
|
variantHeader?: string
|
|
54
47
|
}
|
|
55
48
|
|
|
@@ -61,22 +54,26 @@ export interface RouteConfig {
|
|
|
61
54
|
distinctCountLimit?: number
|
|
62
55
|
}
|
|
63
56
|
|
|
64
|
-
findUnique?:
|
|
65
|
-
findUniqueOrThrow?:
|
|
66
|
-
findFirst?:
|
|
67
|
-
findFirstOrThrow?:
|
|
68
|
-
findMany?:
|
|
69
|
-
findManyPaginated?:
|
|
70
|
-
create?:
|
|
71
|
-
createMany?:
|
|
72
|
-
createManyAndReturn?:
|
|
73
|
-
update?:
|
|
74
|
-
updateMany?:
|
|
75
|
-
updateManyAndReturn?:
|
|
76
|
-
upsert?:
|
|
77
|
-
delete?:
|
|
78
|
-
deleteMany?:
|
|
79
|
-
aggregate?:
|
|
80
|
-
count?:
|
|
81
|
-
groupBy?:
|
|
82
|
-
}
|
|
57
|
+
findUnique?: BaseOperationConfig<HookHandler>
|
|
58
|
+
findUniqueOrThrow?: BaseOperationConfig<HookHandler>
|
|
59
|
+
findFirst?: BaseOperationConfig<HookHandler>
|
|
60
|
+
findFirstOrThrow?: BaseOperationConfig<HookHandler>
|
|
61
|
+
findMany?: BaseOperationConfig<HookHandler>
|
|
62
|
+
findManyPaginated?: BaseOperationConfig<HookHandler>
|
|
63
|
+
create?: BaseOperationConfig<HookHandler>
|
|
64
|
+
createMany?: BaseOperationConfig<HookHandler>
|
|
65
|
+
createManyAndReturn?: BaseOperationConfig<HookHandler>
|
|
66
|
+
update?: BaseOperationConfig<HookHandler>
|
|
67
|
+
updateMany?: BaseOperationConfig<HookHandler>
|
|
68
|
+
updateManyAndReturn?: BaseOperationConfig<HookHandler>
|
|
69
|
+
upsert?: BaseOperationConfig<HookHandler>
|
|
70
|
+
delete?: BaseOperationConfig<HookHandler>
|
|
71
|
+
deleteMany?: BaseOperationConfig<HookHandler>
|
|
72
|
+
aggregate?: BaseOperationConfig<HookHandler>
|
|
73
|
+
count?: BaseOperationConfig<HookHandler>
|
|
74
|
+
groupBy?: BaseOperationConfig<HookHandler>
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export type OperationConfig = BaseOperationConfig<any>
|
|
78
|
+
|
|
79
|
+
export type RouteConfig = BaseRouteConfig<any, any>
|
|
@@ -58,7 +58,7 @@ import {
|
|
|
58
58
|
${modelName}Count,
|
|
59
59
|
${modelName}GroupBy
|
|
60
60
|
} from './${modelName}Handlers.js'
|
|
61
|
-
import type { RouteConfig } from '../routeConfig.js'
|
|
61
|
+
import type { RouteConfig } from '../routeConfig.target.js'
|
|
62
62
|
import { parseQueryParams } from '../parseQueryParams.js'
|
|
63
63
|
import { buildModelOpenApi } from '../buildModelOpenApi.js'
|
|
64
64
|
import { transformResult } from '../operationRuntime.js'
|
|
@@ -55,7 +55,7 @@ import {
|
|
|
55
55
|
${modelName}Count,
|
|
56
56
|
${modelName}GroupBy,
|
|
57
57
|
} from './${modelName}Handlers.js'
|
|
58
|
-
import type { RouteConfig, FastifyHookHandler } from '../routeConfig.js'
|
|
58
|
+
import type { RouteConfig, FastifyHookHandler } from '../routeConfig.target.js'
|
|
59
59
|
import { parseQueryParams } from '../parseQueryParams.js'
|
|
60
60
|
import { buildModelOpenApi } from '../buildModelOpenApi.js'
|
|
61
61
|
import { mapError, transformResult } from '../operationRuntime.js'
|
|
@@ -17,7 +17,7 @@ export function generateUnifiedDocs(
|
|
|
17
17
|
? `import type { FastifyInstance, FastifyRequest, FastifyReply } from 'fastify'`
|
|
18
18
|
: `import { Request, Response } from 'express'`
|
|
19
19
|
|
|
20
|
-
const routeConfigImport = `import type { RouteConfig } from './routeConfig.js'`
|
|
20
|
+
const routeConfigImport = `import type { RouteConfig } from './routeConfig.target.js'`
|
|
21
21
|
|
|
22
22
|
const handlerType =
|
|
23
23
|
target === 'fastify'
|
package/src/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
GeneratorOptions,
|
|
4
4
|
DMMF,
|
|
5
5
|
} from '@prisma/generator-helper'
|
|
6
|
+
import path from 'path'
|
|
6
7
|
import { generateUnifiedHandler } from './generators/generateUnifiedHandler.js'
|
|
7
8
|
import { generateFastifyHandler } from './generators/generateFastifyHandler.js'
|
|
8
9
|
import { generateRouterFunction } from './generators/generateRouter.js'
|
|
@@ -30,20 +31,35 @@ function getTarget(options: GeneratorOptions): Target {
|
|
|
30
31
|
throw new Error(`Invalid target "${raw}". Expected "express" or "fastify".`)
|
|
31
32
|
}
|
|
32
33
|
|
|
34
|
+
function resolveOutputPath(options: GeneratorOptions, target: Target): string {
|
|
35
|
+
const explicit = options.generator.output?.value
|
|
36
|
+
|
|
37
|
+
if (explicit && explicit.length > 0) {
|
|
38
|
+
return explicit
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const schemaDir = path.dirname(options.schemaPath)
|
|
42
|
+
return path.join(schemaDir, 'generated', target)
|
|
43
|
+
}
|
|
44
|
+
|
|
33
45
|
generatorHandler({
|
|
34
46
|
onManifest() {
|
|
35
47
|
return {
|
|
36
48
|
version: require('../package.json').version,
|
|
37
|
-
defaultOutput: '
|
|
49
|
+
defaultOutput: '',
|
|
38
50
|
prettyName: GENERATOR_NAME,
|
|
39
51
|
}
|
|
40
52
|
},
|
|
41
53
|
|
|
42
54
|
async onGenerate(options: GeneratorOptions) {
|
|
43
55
|
const target = getTarget(options)
|
|
56
|
+
const outputPath = resolveOutputPath(options, target)
|
|
57
|
+
|
|
58
|
+
options.generator.output = { value: outputPath, fromEnvVar: null }
|
|
44
59
|
|
|
45
60
|
console.log(`\n═══ Prisma Generator (${target.toUpperCase()}) ═══`)
|
|
46
61
|
console.log(` Target: ${target}`)
|
|
62
|
+
console.log(` Output: ${outputPath}`)
|
|
47
63
|
|
|
48
64
|
await copyFiles(options, target)
|
|
49
65
|
|
package/src/utils/copyFiles.ts
CHANGED
|
@@ -8,11 +8,14 @@ const SHARED_FILES = [
|
|
|
8
8
|
'buildModelOpenApi.ts',
|
|
9
9
|
'operationDefinitions.ts',
|
|
10
10
|
'misc.ts',
|
|
11
|
+
'routeConfig.ts',
|
|
12
|
+
'docsRenderer.ts',
|
|
11
13
|
]
|
|
12
14
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
interface CopyFileOptions {
|
|
16
|
+
required?: boolean
|
|
17
|
+
importRewrites?: Array<{ from: string; to: string }>
|
|
18
|
+
destFilename?: string
|
|
16
19
|
}
|
|
17
20
|
|
|
18
21
|
function resolveTemplateDir(subpath: string): string {
|
|
@@ -32,23 +35,6 @@ function resolveTemplateDir(subpath: string): string {
|
|
|
32
35
|
)
|
|
33
36
|
}
|
|
34
37
|
|
|
35
|
-
function getTargetSourceDir(copyBase: string, target: Target): string {
|
|
36
|
-
if (target === 'express') return copyBase
|
|
37
|
-
const targetDir = path.join(copyBase, target)
|
|
38
|
-
if (!fs.existsSync(targetDir)) {
|
|
39
|
-
throw new Error(
|
|
40
|
-
`Target template directory not found: ${targetDir}\n` +
|
|
41
|
-
` Expected directory for target "${target}".`,
|
|
42
|
-
)
|
|
43
|
-
}
|
|
44
|
-
return targetDir
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
interface CopyFileOptions {
|
|
48
|
-
required?: boolean
|
|
49
|
-
importRewrites?: Array<{ from: string; to: string }>
|
|
50
|
-
}
|
|
51
|
-
|
|
52
38
|
function escapeRegex(str: string): string {
|
|
53
39
|
return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
|
54
40
|
}
|
|
@@ -60,7 +46,8 @@ function copyFileSync(
|
|
|
60
46
|
options?: CopyFileOptions,
|
|
61
47
|
): string | null {
|
|
62
48
|
const srcPath = path.join(srcDir, filename)
|
|
63
|
-
const
|
|
49
|
+
const destFilename = options?.destFilename || filename
|
|
50
|
+
const destPath = path.join(destDir, destFilename)
|
|
64
51
|
|
|
65
52
|
if (!fs.existsSync(srcPath)) {
|
|
66
53
|
if (options?.required) {
|
|
@@ -117,17 +104,13 @@ export async function copyFiles(
|
|
|
117
104
|
if (err) errors.push(err)
|
|
118
105
|
}
|
|
119
106
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
for (const file of TARGET_FILES[target]) {
|
|
128
|
-
const err = copyFileSync(targetSrcDir, outputPath, file, { required: true })
|
|
129
|
-
if (err) errors.push(err)
|
|
130
|
-
}
|
|
107
|
+
const targetConfigFile = `routeConfig.${target}.ts`
|
|
108
|
+
const err = copyFileSync(copyBase, outputPath, targetConfigFile, {
|
|
109
|
+
required: true,
|
|
110
|
+
destFilename: 'routeConfig.target.ts',
|
|
111
|
+
importRewrites: [{ from: './routeConfig', to: './routeConfig' }],
|
|
112
|
+
})
|
|
113
|
+
if (err) errors.push(err)
|
|
131
114
|
|
|
132
115
|
const clientDir = path.join(outputPath, 'client')
|
|
133
116
|
if (!fs.existsSync(clientDir)) {
|