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
|
@@ -1,26 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.generateRouteConfigType = generateRouteConfigType;
|
|
4
|
+
const importExt_1 = require("../utils/importExt");
|
|
4
5
|
const ROUTER_OPERATIONS = [
|
|
5
|
-
'findUnique',
|
|
6
|
-
'
|
|
7
|
-
'
|
|
8
|
-
'
|
|
9
|
-
'
|
|
10
|
-
'findManyPaginated',
|
|
11
|
-
'count',
|
|
12
|
-
'aggregate',
|
|
13
|
-
'groupBy',
|
|
14
|
-
'create',
|
|
15
|
-
'createMany',
|
|
16
|
-
'createManyAndReturn',
|
|
17
|
-
'update',
|
|
18
|
-
'updateMany',
|
|
19
|
-
'updateManyAndReturn',
|
|
20
|
-
'upsert',
|
|
21
|
-
'delete',
|
|
22
|
-
'deleteMany',
|
|
6
|
+
'findUnique', 'findUniqueOrThrow', 'findFirst', 'findFirstOrThrow',
|
|
7
|
+
'findMany', 'findManyPaginated', 'count', 'aggregate', 'groupBy',
|
|
8
|
+
'create', 'createMany', 'createManyAndReturn',
|
|
9
|
+
'update', 'updateMany', 'updateManyAndReturn',
|
|
10
|
+
'upsert', 'delete', 'deleteMany',
|
|
23
11
|
];
|
|
12
|
+
const READ_OPERATIONS = new Set([
|
|
13
|
+
'findUnique', 'findUniqueOrThrow', 'findFirst', 'findFirstOrThrow',
|
|
14
|
+
'findMany', 'findManyPaginated', 'count', 'aggregate', 'groupBy',
|
|
15
|
+
]);
|
|
24
16
|
const ROUTER_OP_TO_SHAPE_OP = {
|
|
25
17
|
findUnique: 'findUnique',
|
|
26
18
|
findUniqueOrThrow: 'findUniqueOrThrow',
|
|
@@ -44,29 +36,42 @@ const ROUTER_OP_TO_SHAPE_OP = {
|
|
|
44
36
|
function capitalize(s) {
|
|
45
37
|
return s.charAt(0).toUpperCase() + s.slice(1);
|
|
46
38
|
}
|
|
47
|
-
function generateRouteConfigType(modelName, hookHandlerType, guardShapesImport) {
|
|
39
|
+
function generateRouteConfigType(modelName, hookHandlerType, guardShapesImport, importStyle, target) {
|
|
40
|
+
const ext = (0, importExt_1.importExt)(importStyle);
|
|
48
41
|
const m = modelName;
|
|
42
|
+
const supportsProgressive = target === 'express';
|
|
49
43
|
if (!guardShapesImport) {
|
|
50
|
-
return `export type ${m}RouteConfig<TCtx = unknown> = RouteConfig
|
|
44
|
+
return `export type ${m}RouteConfig<TCtx = unknown> = RouteConfig<Record<string, any>, TCtx>\n`;
|
|
51
45
|
}
|
|
52
46
|
const shapeOps = Object.values(ROUTER_OP_TO_SHAPE_OP).filter((v, i, a) => a.indexOf(v) === i);
|
|
53
|
-
const opShapeImports = shapeOps
|
|
54
|
-
.map((op) => `${m}${capitalize(op)}ShapeInput`)
|
|
55
|
-
.join(',\n ');
|
|
47
|
+
const opShapeImports = shapeOps.map((op) => `${m}${capitalize(op)}ShapeInput`).join(',\n ');
|
|
56
48
|
const overrides = ROUTER_OPERATIONS.map((routerOp) => {
|
|
57
49
|
const shapeOp = ROUTER_OP_TO_SHAPE_OP[routerOp];
|
|
58
50
|
const c = capitalize(shapeOp);
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
`
|
|
62
|
-
`
|
|
63
|
-
`
|
|
51
|
+
const isRead = READ_OPERATIONS.has(routerOp);
|
|
52
|
+
const lines = [
|
|
53
|
+
` before?: ${hookHandlerType}[]`,
|
|
54
|
+
` after?: ${hookHandlerType}[]`,
|
|
55
|
+
` shape?: ${m}${c}ShapeInput<TCtx>`,
|
|
56
|
+
];
|
|
57
|
+
if (isRead && supportsProgressive) {
|
|
58
|
+
lines.push(` progressive?: Record<string, ProgressiveVariantConfig>`);
|
|
59
|
+
lines.push(` progressiveStages?: Record<string, ProgressiveStage<TCtx>>`);
|
|
60
|
+
}
|
|
61
|
+
return ` ${routerOp}?: {\n${lines.join('\n')}\n }`;
|
|
64
62
|
}).join('\n');
|
|
65
63
|
const omitKeys = ROUTER_OPERATIONS.map((k) => `'${k}'`).join('\n | ');
|
|
66
|
-
|
|
64
|
+
const progressiveTypeImport = supportsProgressive
|
|
65
|
+
? `import type { ProgressiveVariantConfig, ProgressiveStage } from '../routeConfig.target${ext}'\n\n`
|
|
66
|
+
: '';
|
|
67
|
+
return (progressiveTypeImport +
|
|
68
|
+
`import type {\n ${opShapeImports}\n} from '${guardShapesImport}'\n\n` +
|
|
67
69
|
`export type ${m}RouteConfig<TCtx = unknown> = Omit<\n` +
|
|
68
|
-
` RouteConfig
|
|
70
|
+
` RouteConfig<Record<string, any>, TCtx>,\n` +
|
|
69
71
|
` | ${omitKeys}\n` +
|
|
70
|
-
|
|
72
|
+
` | 'resolveContext'\n` +
|
|
73
|
+
`> & {\n` +
|
|
74
|
+
` resolveContext?: (request: import('express').Request) => TCtx | Promise<TCtx>\n` +
|
|
75
|
+
`${overrides}\n}\n`);
|
|
71
76
|
}
|
|
72
77
|
//# sourceMappingURL=generateRouteConfigType.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateRouteConfigType.js","sourceRoot":"","sources":["../../src/generators/generateRouteConfigType.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"generateRouteConfigType.js","sourceRoot":"","sources":["../../src/generators/generateRouteConfigType.ts"],"names":[],"mappings":";;AA4CA,0DAmDC;AA9FD,kDAA8C;AAG9C,MAAM,iBAAiB,GAAG;IACxB,YAAY,EAAE,mBAAmB,EAAE,WAAW,EAAE,kBAAkB;IAClE,UAAU,EAAE,mBAAmB,EAAE,OAAO,EAAE,WAAW,EAAE,SAAS;IAChE,Q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CAAC,CAAA;IAEtE,MAAM,qBAAqB,GAAG,mBAAmB;QAC/C,CAAC,CAAC,yFAAyF,GAAG,OAAO;QACrG,CAAC,CAAC,EAAE,CAAA;IAEN,OAAO,CACL,qBAAqB;QACrB,oBAAoB,cAAc,aAAa,iBAAiB,OAAO;QACvE,eAAe,CAAC,uCAAuC;QACvD,6CAA6C;QAC7C,OAAO,QAAQ,IAAI;QACnB,wBAAwB;QACxB,SAAS;QACT,mFAAmF;QACnF,GAAG,SAAS,OAAO,CACpB,CAAA;AACH,CAAC"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { DMMF } from '@prisma/generator-helper';
|
|
2
|
-
|
|
2
|
+
import { ImportStyle } from '../utils/resolveImportStyle';
|
|
3
|
+
export declare function generateRouterFunction({ model, enums, guardShapesImport, importStyle, }: {
|
|
3
4
|
model: DMMF.Model;
|
|
4
5
|
enums: DMMF.DatamodelEnum[];
|
|
5
|
-
relativeClientPath
|
|
6
|
+
relativeClientPath?: string;
|
|
6
7
|
guardShapesImport: string | null;
|
|
8
|
+
importStyle: ImportStyle;
|
|
7
9
|
}): string;
|
|
@@ -3,7 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generateRouterFunction = generateRouterFunction;
|
|
4
4
|
const strings_1 = require("../utils/strings");
|
|
5
5
|
const generateRouteConfigType_1 = require("./generateRouteConfigType");
|
|
6
|
-
|
|
6
|
+
const importExt_1 = require("../utils/importExt");
|
|
7
|
+
function generateRouterFunction({ model, enums, guardShapesImport, importStyle, }) {
|
|
8
|
+
const ext = (0, importExt_1.importExt)(importStyle);
|
|
7
9
|
const modelName = model.name;
|
|
8
10
|
const prefix = (0, strings_1.toCamelCase)(modelName);
|
|
9
11
|
const modelNameLower = modelName.toLowerCase();
|
|
@@ -26,8 +28,8 @@ function generateRouterFunction({ model, enums, relativeClientPath, guardShapesI
|
|
|
26
28
|
name: e.name,
|
|
27
29
|
values: e.values.map((v) => ({ name: v.name })),
|
|
28
30
|
}));
|
|
29
|
-
return `import express
|
|
30
|
-
import type {
|
|
31
|
+
return `import express from 'express'
|
|
32
|
+
import type { Request, Response, NextFunction, RequestHandler } from 'express'
|
|
31
33
|
import {
|
|
32
34
|
${prefix}FindUnique,
|
|
33
35
|
${prefix}FindUniqueOrThrow,
|
|
@@ -46,19 +48,25 @@ import {
|
|
|
46
48
|
${prefix}DeleteMany,
|
|
47
49
|
${prefix}Aggregate,
|
|
48
50
|
${prefix}Count,
|
|
49
|
-
${prefix}GroupBy
|
|
50
|
-
} from './${modelName}Handlers'
|
|
51
|
-
import
|
|
52
|
-
import {
|
|
53
|
-
import {
|
|
54
|
-
import {
|
|
55
|
-
import {
|
|
51
|
+
${prefix}GroupBy,
|
|
52
|
+
} from './${modelName}Handlers${ext}'
|
|
53
|
+
import * as core from './${modelName}Core${ext}'
|
|
54
|
+
import type { RouteConfig } from '../routeConfig.target${ext}'
|
|
55
|
+
import { parseQueryParams } from '../parseQueryParams${ext}'
|
|
56
|
+
import { sanitizeKeys } from '../misc${ext}'
|
|
57
|
+
import { buildModelOpenApi } from '../buildModelOpenApi${ext}'
|
|
58
|
+
import type { OperationContext } from '../operationRuntime${ext}'
|
|
59
|
+
import {
|
|
60
|
+
transformResult,
|
|
61
|
+
acceptsEventStream,
|
|
62
|
+
runProgressiveEndpoint,
|
|
63
|
+
runSingleResultSSE,
|
|
64
|
+
} from '../operationRuntime${ext}'
|
|
56
65
|
|
|
57
|
-
${(0, generateRouteConfigType_1.generateRouteConfigType)(modelName, 'RequestHandler', guardShapesImport)}
|
|
66
|
+
${(0, generateRouteConfigType_1.generateRouteConfigType)(modelName, 'RequestHandler', guardShapesImport, importStyle, 'express')}
|
|
58
67
|
const _env = typeof process !== 'undefined' && process.env ? process.env : {} as Record<string, string | undefined>
|
|
59
68
|
|
|
60
69
|
const MODEL_FIELDS = ${JSON.stringify(fieldsMeta, null, 2)} as const
|
|
61
|
-
|
|
62
70
|
const MODEL_ENUMS = ${JSON.stringify(enumsMeta, null, 2)} as const
|
|
63
71
|
|
|
64
72
|
const defaultOpConfig = {
|
|
@@ -90,7 +98,6 @@ function getQueryBuilderConfig(config: RouteConfig) {
|
|
|
90
98
|
|
|
91
99
|
export function ${routerFunctionName}<TCtx = unknown>(config: ${modelName}RouteConfig<TCtx> = {}) {
|
|
92
100
|
const router = express.Router()
|
|
93
|
-
|
|
94
101
|
router.use(express.json())
|
|
95
102
|
|
|
96
103
|
const customPrefix = normalizePrefix(config.customUrlPrefix || '')
|
|
@@ -98,22 +105,29 @@ export function ${routerFunctionName}<TCtx = unknown>(config: ${modelName}RouteC
|
|
|
98
105
|
const basePath = customPrefix + modelPrefix
|
|
99
106
|
|
|
100
107
|
const openApiDisabled = config.disableOpenApi === true
|
|
101
|
-
|| (config.disableOpenApi !== false && (
|
|
102
|
-
_env.DISABLE_OPENAPI === 'true'
|
|
103
|
-
|| _env.NODE_ENV === 'production'
|
|
104
|
-
))
|
|
108
|
+
|| (config.disableOpenApi !== false && (_env.DISABLE_OPENAPI === 'true' || _env.NODE_ENV === 'production'))
|
|
105
109
|
|
|
106
110
|
const postReadsEnabled = !config.disablePostReads
|
|
107
111
|
|
|
108
112
|
const qbEnabled = isQueryBuilderEnabled(config)
|
|
109
|
-
|
|
110
113
|
if (qbEnabled) {
|
|
111
114
|
const qbConfig = getQueryBuilderConfig(config)
|
|
112
115
|
if (qbConfig) {
|
|
113
|
-
try { require('../queryBuilder').startQueryBuilder(qbConfig) } catch (err) { if (_env.NODE_ENV !== 'production') console.warn('[query-builder]', err) }
|
|
116
|
+
try { require('../queryBuilder${ext}').startQueryBuilder(qbConfig) } catch (err) { if (_env.NODE_ENV !== 'production') console.warn('[query-builder]', err) }
|
|
114
117
|
}
|
|
115
118
|
}
|
|
116
119
|
|
|
120
|
+
const buildContext = (req: Request, res: Response): OperationContext => ({
|
|
121
|
+
prisma: (req as any).prisma,
|
|
122
|
+
postgres: (req as any).postgres,
|
|
123
|
+
sqlite: (req as any).sqlite,
|
|
124
|
+
parsedQuery: res.locals.parsedQuery,
|
|
125
|
+
body: req.body,
|
|
126
|
+
guardShape: res.locals.guardShape,
|
|
127
|
+
guardCaller: res.locals.guardCaller,
|
|
128
|
+
paginationConfig: res.locals.routeConfig?.pagination,
|
|
129
|
+
})
|
|
130
|
+
|
|
117
131
|
const parseQuery: RequestHandler = (req, res, next) => {
|
|
118
132
|
const rawQuery = req.query
|
|
119
133
|
if (rawQuery && Object.keys(rawQuery).length > 0) {
|
|
@@ -133,147 +147,154 @@ export function ${routerFunctionName}<TCtx = unknown>(config: ${modelName}RouteC
|
|
|
133
147
|
const setShape = (opConfig: any): RequestHandler => {
|
|
134
148
|
return (req, res, next) => {
|
|
135
149
|
res.locals.routeConfig = config
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
150
|
+
const caller = config.guard?.resolveVariant?.(req)
|
|
151
|
+
?? req.get(config.guard?.variantHeader || 'x-api-variant')
|
|
152
|
+
?? undefined
|
|
153
|
+
if (caller) res.locals.guardCaller = caller
|
|
154
|
+
if (opConfig.shape) res.locals.guardShape = opConfig.shape
|
|
155
|
+
next()
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const maybeProgressiveSSE = (opConfig: any, coreFn: (ctx: OperationContext) => Promise<unknown>): RequestHandler => {
|
|
160
|
+
return async (req, res, next) => {
|
|
161
|
+
if (res.headersSent || res.writableEnded) return next()
|
|
162
|
+
if (req.method !== 'GET') return next()
|
|
163
|
+
if (!acceptsEventStream(req.headers.accept)) return next()
|
|
164
|
+
|
|
165
|
+
const variant = res.locals.guardCaller as string | undefined
|
|
166
|
+
const progressiveConfig = variant ? opConfig.progressive?.[variant] : undefined
|
|
167
|
+
|
|
168
|
+
try {
|
|
169
|
+
if (!progressiveConfig || progressiveConfig.enabled === false) {
|
|
170
|
+
await runSingleResultSSE({
|
|
171
|
+
req,
|
|
172
|
+
res,
|
|
173
|
+
coreQueryFn: () => coreFn(buildContext(req, res)),
|
|
174
|
+
})
|
|
175
|
+
return
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (!Array.isArray(progressiveConfig.stages)) {
|
|
179
|
+
return next({ status: 500, message: 'Progressive endpoint requires stages array' })
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const stageRegistry = opConfig.progressiveStages ?? {}
|
|
183
|
+
const missingStage = progressiveConfig.stages.find(
|
|
184
|
+
(name: string) => typeof stageRegistry[name] !== 'function',
|
|
185
|
+
)
|
|
186
|
+
if (missingStage) {
|
|
187
|
+
return next({ status: 500, message: 'Missing progressive stage: ' + missingStage })
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (typeof config.resolveContext !== 'function') {
|
|
191
|
+
return next({ status: 500, message: 'Progressive endpoint requires config.resolveContext' })
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const ctx = await config.resolveContext(req)
|
|
195
|
+
await runProgressiveEndpoint({
|
|
196
|
+
req,
|
|
197
|
+
res,
|
|
198
|
+
ctx,
|
|
199
|
+
prisma: (req as any).prisma,
|
|
200
|
+
variant: variant as string,
|
|
201
|
+
stages: progressiveConfig.stages,
|
|
202
|
+
stageRegistry,
|
|
203
|
+
})
|
|
204
|
+
} catch (err) {
|
|
205
|
+
if (!res.headersSent) {
|
|
206
|
+
return next({ status: 500, message: 'Internal server error' })
|
|
143
207
|
}
|
|
144
208
|
}
|
|
145
|
-
next()
|
|
146
209
|
}
|
|
147
210
|
}
|
|
148
211
|
|
|
149
212
|
const respond: RequestHandler = (_req, res) => {
|
|
150
213
|
const data = res.locals.data
|
|
151
|
-
if (data === undefined) {
|
|
152
|
-
return res.status(500).json({ message: 'No data set by handler' })
|
|
153
|
-
}
|
|
214
|
+
if (data === undefined) return res.status(500).json({ message: 'No data set by handler' })
|
|
154
215
|
return res.json(transformResult(data))
|
|
155
216
|
}
|
|
156
217
|
|
|
157
218
|
const respondCreated: RequestHandler = (_req, res) => {
|
|
158
219
|
const data = res.locals.data
|
|
159
|
-
if (data === undefined) {
|
|
160
|
-
return res.status(500).json({ message: 'No data set by handler' })
|
|
161
|
-
}
|
|
220
|
+
if (data === undefined) return res.status(500).json({ message: 'No data set by handler' })
|
|
162
221
|
return res.status(201).json(transformResult(data))
|
|
163
222
|
}
|
|
164
223
|
|
|
165
224
|
if (!openApiDisabled) {
|
|
166
225
|
const openapiJsonPath = basePath ? \`\${basePath}/openapi.json\` : '/openapi.json'
|
|
167
226
|
const openapiYamlPath = basePath ? \`\${basePath}/openapi.yaml\` : '/openapi.yaml'
|
|
168
|
-
|
|
169
227
|
router.get(openapiJsonPath, (_req, res) => {
|
|
170
|
-
const spec = buildModelOpenApi(
|
|
171
|
-
'${modelName}',
|
|
172
|
-
MODEL_FIELDS as any,
|
|
173
|
-
MODEL_ENUMS as any,
|
|
174
|
-
config,
|
|
175
|
-
{ format: 'json' }
|
|
176
|
-
)
|
|
228
|
+
const spec = buildModelOpenApi('${modelName}', MODEL_FIELDS as any, MODEL_ENUMS as any, config, { format: 'json' })
|
|
177
229
|
res.json(spec)
|
|
178
230
|
})
|
|
179
|
-
|
|
180
231
|
router.get(openapiYamlPath, (_req, res) => {
|
|
181
|
-
const spec = buildModelOpenApi(
|
|
182
|
-
'${modelName}',
|
|
183
|
-
MODEL_FIELDS as any,
|
|
184
|
-
MODEL_ENUMS as any,
|
|
185
|
-
config,
|
|
186
|
-
{ format: 'yaml' }
|
|
187
|
-
)
|
|
232
|
+
const spec = buildModelOpenApi('${modelName}', MODEL_FIELDS as any, MODEL_ENUMS as any, config, { format: 'yaml' })
|
|
188
233
|
res.type('application/yaml').send(spec as string)
|
|
189
234
|
})
|
|
190
235
|
}
|
|
191
236
|
|
|
192
237
|
if (config.enableAll || config.findFirst) {
|
|
193
|
-
const opConfig = config.findFirst || defaultOpConfig
|
|
238
|
+
const opConfig: any = config.findFirst || defaultOpConfig
|
|
194
239
|
const { before = [], after = [] } = opConfig
|
|
195
240
|
const path = basePath ? \`\${basePath}/first\` : '/first'
|
|
196
|
-
router.get(path, parseQuery, setShape(opConfig), ...before, ${prefix}FindFirst as RequestHandler, ...after, respond)
|
|
197
|
-
if (postReadsEnabled) {
|
|
198
|
-
router.post(path, parseBodyAsQuery, setShape(opConfig), ...before, ${prefix}FindFirst as RequestHandler, ...after, respond)
|
|
199
|
-
}
|
|
241
|
+
router.get(path, parseQuery, setShape(opConfig), ...before, maybeProgressiveSSE(opConfig, core.findFirst), ${prefix}FindFirst as RequestHandler, ...after, respond)
|
|
242
|
+
if (postReadsEnabled) router.post(path, parseBodyAsQuery, setShape(opConfig), ...before, ${prefix}FindFirst as RequestHandler, ...after, respond)
|
|
200
243
|
}
|
|
201
|
-
|
|
202
244
|
if (config.enableAll || config.findFirstOrThrow) {
|
|
203
|
-
const opConfig = config.findFirstOrThrow || defaultOpConfig
|
|
245
|
+
const opConfig: any = config.findFirstOrThrow || defaultOpConfig
|
|
204
246
|
const { before = [], after = [] } = opConfig
|
|
205
247
|
const path = basePath ? \`\${basePath}/first/strict\` : '/first/strict'
|
|
206
|
-
router.get(path, parseQuery, setShape(opConfig), ...before, ${prefix}FindFirstOrThrow as RequestHandler, ...after, respond)
|
|
207
|
-
if (postReadsEnabled) {
|
|
208
|
-
router.post(path, parseBodyAsQuery, setShape(opConfig), ...before, ${prefix}FindFirstOrThrow as RequestHandler, ...after, respond)
|
|
209
|
-
}
|
|
248
|
+
router.get(path, parseQuery, setShape(opConfig), ...before, maybeProgressiveSSE(opConfig, core.findFirstOrThrow), ${prefix}FindFirstOrThrow as RequestHandler, ...after, respond)
|
|
249
|
+
if (postReadsEnabled) router.post(path, parseBodyAsQuery, setShape(opConfig), ...before, ${prefix}FindFirstOrThrow as RequestHandler, ...after, respond)
|
|
210
250
|
}
|
|
211
|
-
|
|
212
251
|
if (config.enableAll || config.findManyPaginated) {
|
|
213
|
-
const opConfig = config.findManyPaginated || defaultOpConfig
|
|
252
|
+
const opConfig: any = config.findManyPaginated || defaultOpConfig
|
|
214
253
|
const { before = [], after = [] } = opConfig
|
|
215
254
|
const path = basePath ? \`\${basePath}/paginated\` : '/paginated'
|
|
216
|
-
router.get(path, parseQuery, setShape(opConfig), ...before, ${prefix}FindManyPaginated as RequestHandler, ...after, respond)
|
|
217
|
-
if (postReadsEnabled) {
|
|
218
|
-
router.post(path, parseBodyAsQuery, setShape(opConfig), ...before, ${prefix}FindManyPaginated as RequestHandler, ...after, respond)
|
|
219
|
-
}
|
|
255
|
+
router.get(path, parseQuery, setShape(opConfig), ...before, maybeProgressiveSSE(opConfig, core.findManyPaginated), ${prefix}FindManyPaginated as RequestHandler, ...after, respond)
|
|
256
|
+
if (postReadsEnabled) router.post(path, parseBodyAsQuery, setShape(opConfig), ...before, ${prefix}FindManyPaginated as RequestHandler, ...after, respond)
|
|
220
257
|
}
|
|
221
|
-
|
|
222
258
|
if (config.enableAll || config.aggregate) {
|
|
223
|
-
const opConfig = config.aggregate || defaultOpConfig
|
|
259
|
+
const opConfig: any = config.aggregate || defaultOpConfig
|
|
224
260
|
const { before = [], after = [] } = opConfig
|
|
225
261
|
const path = basePath ? \`\${basePath}/aggregate\` : '/aggregate'
|
|
226
|
-
router.get(path, parseQuery, setShape(opConfig), ...before, ${prefix}Aggregate as RequestHandler, ...after, respond)
|
|
227
|
-
if (postReadsEnabled) {
|
|
228
|
-
router.post(path, parseBodyAsQuery, setShape(opConfig), ...before, ${prefix}Aggregate as RequestHandler, ...after, respond)
|
|
229
|
-
}
|
|
262
|
+
router.get(path, parseQuery, setShape(opConfig), ...before, maybeProgressiveSSE(opConfig, core.aggregate), ${prefix}Aggregate as RequestHandler, ...after, respond)
|
|
263
|
+
if (postReadsEnabled) router.post(path, parseBodyAsQuery, setShape(opConfig), ...before, ${prefix}Aggregate as RequestHandler, ...after, respond)
|
|
230
264
|
}
|
|
231
|
-
|
|
232
265
|
if (config.enableAll || config.count) {
|
|
233
|
-
const opConfig = config.count || defaultOpConfig
|
|
266
|
+
const opConfig: any = config.count || defaultOpConfig
|
|
234
267
|
const { before = [], after = [] } = opConfig
|
|
235
268
|
const path = basePath ? \`\${basePath}/count\` : '/count'
|
|
236
|
-
router.get(path, parseQuery, setShape(opConfig), ...before, ${prefix}Count as RequestHandler, ...after, respond)
|
|
237
|
-
if (postReadsEnabled) {
|
|
238
|
-
router.post(path, parseBodyAsQuery, setShape(opConfig), ...before, ${prefix}Count as RequestHandler, ...after, respond)
|
|
239
|
-
}
|
|
269
|
+
router.get(path, parseQuery, setShape(opConfig), ...before, maybeProgressiveSSE(opConfig, core.count), ${prefix}Count as RequestHandler, ...after, respond)
|
|
270
|
+
if (postReadsEnabled) router.post(path, parseBodyAsQuery, setShape(opConfig), ...before, ${prefix}Count as RequestHandler, ...after, respond)
|
|
240
271
|
}
|
|
241
|
-
|
|
242
272
|
if (config.enableAll || config.groupBy) {
|
|
243
|
-
const opConfig = config.groupBy || defaultOpConfig
|
|
273
|
+
const opConfig: any = config.groupBy || defaultOpConfig
|
|
244
274
|
const { before = [], after = [] } = opConfig
|
|
245
275
|
const path = basePath ? \`\${basePath}/groupby\` : '/groupby'
|
|
246
|
-
router.get(path, parseQuery, setShape(opConfig), ...before, ${prefix}GroupBy as RequestHandler, ...after, respond)
|
|
247
|
-
if (postReadsEnabled) {
|
|
248
|
-
router.post(path, parseBodyAsQuery, setShape(opConfig), ...before, ${prefix}GroupBy as RequestHandler, ...after, respond)
|
|
249
|
-
}
|
|
276
|
+
router.get(path, parseQuery, setShape(opConfig), ...before, maybeProgressiveSSE(opConfig, core.groupBy), ${prefix}GroupBy as RequestHandler, ...after, respond)
|
|
277
|
+
if (postReadsEnabled) router.post(path, parseBodyAsQuery, setShape(opConfig), ...before, ${prefix}GroupBy as RequestHandler, ...after, respond)
|
|
250
278
|
}
|
|
251
|
-
|
|
252
279
|
if (config.enableAll || config.findUniqueOrThrow) {
|
|
253
|
-
const opConfig = config.findUniqueOrThrow || defaultOpConfig
|
|
280
|
+
const opConfig: any = config.findUniqueOrThrow || defaultOpConfig
|
|
254
281
|
const { before = [], after = [] } = opConfig
|
|
255
282
|
const path = basePath ? \`\${basePath}/unique/strict\` : '/unique/strict'
|
|
256
|
-
router.get(path, parseQuery, setShape(opConfig), ...before, ${prefix}FindUniqueOrThrow as RequestHandler, ...after, respond)
|
|
257
|
-
if (postReadsEnabled) {
|
|
258
|
-
router.post(path, parseBodyAsQuery, setShape(opConfig), ...before, ${prefix}FindUniqueOrThrow as RequestHandler, ...after, respond)
|
|
259
|
-
}
|
|
283
|
+
router.get(path, parseQuery, setShape(opConfig), ...before, maybeProgressiveSSE(opConfig, core.findUniqueOrThrow), ${prefix}FindUniqueOrThrow as RequestHandler, ...after, respond)
|
|
284
|
+
if (postReadsEnabled) router.post(path, parseBodyAsQuery, setShape(opConfig), ...before, ${prefix}FindUniqueOrThrow as RequestHandler, ...after, respond)
|
|
260
285
|
}
|
|
261
|
-
|
|
262
286
|
if (config.enableAll || config.findUnique) {
|
|
263
|
-
const opConfig = config.findUnique || defaultOpConfig
|
|
287
|
+
const opConfig: any = config.findUnique || defaultOpConfig
|
|
264
288
|
const { before = [], after = [] } = opConfig
|
|
265
289
|
const path = basePath ? \`\${basePath}/unique\` : '/unique'
|
|
266
|
-
router.get(path, parseQuery, setShape(opConfig), ...before, ${prefix}FindUnique as RequestHandler, ...after, respond)
|
|
267
|
-
if (postReadsEnabled) {
|
|
268
|
-
router.post(path, parseBodyAsQuery, setShape(opConfig), ...before, ${prefix}FindUnique as RequestHandler, ...after, respond)
|
|
269
|
-
}
|
|
290
|
+
router.get(path, parseQuery, setShape(opConfig), ...before, maybeProgressiveSSE(opConfig, core.findUnique), ${prefix}FindUnique as RequestHandler, ...after, respond)
|
|
291
|
+
if (postReadsEnabled) router.post(path, parseBodyAsQuery, setShape(opConfig), ...before, ${prefix}FindUnique as RequestHandler, ...after, respond)
|
|
270
292
|
}
|
|
271
|
-
|
|
272
293
|
if (config.enableAll || config.findMany) {
|
|
273
|
-
const opConfig = config.findMany || defaultOpConfig
|
|
294
|
+
const opConfig: any = config.findMany || defaultOpConfig
|
|
274
295
|
const { before = [], after = [] } = opConfig
|
|
275
296
|
const path = basePath || '/'
|
|
276
|
-
router.get(path, parseQuery, setShape(opConfig), ...before, ${prefix}FindMany as RequestHandler, ...after, respond)
|
|
297
|
+
router.get(path, parseQuery, setShape(opConfig), ...before, maybeProgressiveSSE(opConfig, core.findMany), ${prefix}FindMany as RequestHandler, ...after, respond)
|
|
277
298
|
if (postReadsEnabled) {
|
|
278
299
|
const postPath = basePath ? \`\${basePath}/read\` : '/read'
|
|
279
300
|
router.post(postPath, parseBodyAsQuery, setShape(opConfig), ...before, ${prefix}FindMany as RequestHandler, ...after, respond)
|
|
@@ -281,63 +302,55 @@ export function ${routerFunctionName}<TCtx = unknown>(config: ${modelName}RouteC
|
|
|
281
302
|
}
|
|
282
303
|
|
|
283
304
|
if (config.enableAll || config.createManyAndReturn) {
|
|
284
|
-
const opConfig = config.createManyAndReturn || defaultOpConfig
|
|
305
|
+
const opConfig: any = config.createManyAndReturn || defaultOpConfig
|
|
285
306
|
const { before = [], after = [] } = opConfig
|
|
286
307
|
const path = basePath ? \`\${basePath}/many/return\` : '/many/return'
|
|
287
308
|
router.post(path, setShape(opConfig), ...before, ${prefix}CreateManyAndReturn as RequestHandler, ...after, respondCreated)
|
|
288
309
|
}
|
|
289
|
-
|
|
290
310
|
if (config.enableAll || config.createMany) {
|
|
291
|
-
const opConfig = config.createMany || defaultOpConfig
|
|
311
|
+
const opConfig: any = config.createMany || defaultOpConfig
|
|
292
312
|
const { before = [], after = [] } = opConfig
|
|
293
313
|
const path = basePath ? \`\${basePath}/many\` : '/many'
|
|
294
314
|
router.post(path, setShape(opConfig), ...before, ${prefix}CreateMany as RequestHandler, ...after, respondCreated)
|
|
295
315
|
}
|
|
296
|
-
|
|
297
316
|
if (config.enableAll || config.create) {
|
|
298
|
-
const opConfig = config.create || defaultOpConfig
|
|
317
|
+
const opConfig: any = config.create || defaultOpConfig
|
|
299
318
|
const { before = [], after = [] } = opConfig
|
|
300
319
|
const path = basePath || '/'
|
|
301
320
|
router.post(path, setShape(opConfig), ...before, ${prefix}Create as RequestHandler, ...after, respondCreated)
|
|
302
321
|
}
|
|
303
|
-
|
|
304
322
|
if (config.enableAll || config.updateManyAndReturn) {
|
|
305
|
-
const opConfig = config.updateManyAndReturn || defaultOpConfig
|
|
323
|
+
const opConfig: any = config.updateManyAndReturn || defaultOpConfig
|
|
306
324
|
const { before = [], after = [] } = opConfig
|
|
307
325
|
const path = basePath ? \`\${basePath}/many/return\` : '/many/return'
|
|
308
326
|
router.put(path, setShape(opConfig), ...before, ${prefix}UpdateManyAndReturn as RequestHandler, ...after, respond)
|
|
309
327
|
}
|
|
310
|
-
|
|
311
328
|
if (config.enableAll || config.updateMany) {
|
|
312
|
-
const opConfig = config.updateMany || defaultOpConfig
|
|
329
|
+
const opConfig: any = config.updateMany || defaultOpConfig
|
|
313
330
|
const { before = [], after = [] } = opConfig
|
|
314
331
|
const path = basePath ? \`\${basePath}/many\` : '/many'
|
|
315
332
|
router.put(path, setShape(opConfig), ...before, ${prefix}UpdateMany as RequestHandler, ...after, respond)
|
|
316
333
|
}
|
|
317
|
-
|
|
318
334
|
if (config.enableAll || config.update) {
|
|
319
|
-
const opConfig = config.update || defaultOpConfig
|
|
335
|
+
const opConfig: any = config.update || defaultOpConfig
|
|
320
336
|
const { before = [], after = [] } = opConfig
|
|
321
337
|
const path = basePath || '/'
|
|
322
338
|
router.put(path, setShape(opConfig), ...before, ${prefix}Update as RequestHandler, ...after, respond)
|
|
323
339
|
}
|
|
324
|
-
|
|
325
340
|
if (config.enableAll || config.upsert) {
|
|
326
|
-
const opConfig = config.upsert || defaultOpConfig
|
|
341
|
+
const opConfig: any = config.upsert || defaultOpConfig
|
|
327
342
|
const { before = [], after = [] } = opConfig
|
|
328
343
|
const path = basePath || '/'
|
|
329
344
|
router.patch(path, setShape(opConfig), ...before, ${prefix}Upsert as RequestHandler, ...after, respond)
|
|
330
345
|
}
|
|
331
|
-
|
|
332
346
|
if (config.enableAll || config.deleteMany) {
|
|
333
|
-
const opConfig = config.deleteMany || defaultOpConfig
|
|
347
|
+
const opConfig: any = config.deleteMany || defaultOpConfig
|
|
334
348
|
const { before = [], after = [] } = opConfig
|
|
335
349
|
const path = basePath ? \`\${basePath}/many\` : '/many'
|
|
336
350
|
router.delete(path, setShape(opConfig), ...before, ${prefix}DeleteMany as RequestHandler, ...after, respond)
|
|
337
351
|
}
|
|
338
|
-
|
|
339
352
|
if (config.enableAll || config.delete) {
|
|
340
|
-
const opConfig = config.delete || defaultOpConfig
|
|
353
|
+
const opConfig: any = config.delete || defaultOpConfig
|
|
341
354
|
const { before = [], after = [] } = opConfig
|
|
342
355
|
const path = basePath || '/'
|
|
343
356
|
router.delete(path, setShape(opConfig), ...before, ${prefix}Delete as RequestHandler, ...after, respond)
|
|
@@ -346,9 +359,7 @@ export function ${routerFunctionName}<TCtx = unknown>(config: ${modelName}RouteC
|
|
|
346
359
|
router.use((err: any, _req: Request, res: Response, next: NextFunction) => {
|
|
347
360
|
const status = typeof err.status === 'number' ? err.status : 500
|
|
348
361
|
const message = err.message || 'Internal server error'
|
|
349
|
-
if (!res.headersSent) {
|
|
350
|
-
return res.status(status).json({ message })
|
|
351
|
-
}
|
|
362
|
+
if (!res.headersSent) return res.status(status).json({ message })
|
|
352
363
|
next(err)
|
|
353
364
|
})
|
|
354
365
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateRouter.js","sourceRoot":"","sources":["../../src/generators/generateRouter.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"generateRouter.js","sourceRoot":"","sources":["../../src/generators/generateRouter.ts"],"names":[],"mappings":";;AAMA,wDA2XC;AAhYD,8CAA8C;AAC9C,uEAAmE;AAEnE,kDAA8C;AAE9C,SAAgB,sBAAsB,CAAC,EACrC,KAAK,EACL,KAAK,EACL,iBAAiB,EACjB,WAAW,GAOZ;IACC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AM;+FACzB,MAAM;;;;;;gHAMW,MAAM;;;+EAGvC,MAAM;;;;;;;;uDAQ9B,MAAM;;;;;;uDAMN,MAAM;;;;;;uDAMN,MAAM;;;;;;sDAMP,MAAM;;;;;;sDAMN,MAAM;;;;;;sDAMN,MAAM;;;;;;wDAMJ,MAAM;;;;;;yDAML,MAAM;;;;;;yDAMN,MAAM;;;;;;;;;;;;CAY9D,CAAA;AACD,CAAC"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { DMMF } from '@prisma/generator-helper';
|
|
2
|
-
|
|
2
|
+
import { ImportStyle } from '../utils/resolveImportStyle';
|
|
3
|
+
export declare function generateFastifyRouterFunction({ model, enums, guardShapesImport, importStyle, }: {
|
|
3
4
|
model: DMMF.Model;
|
|
4
5
|
enums: DMMF.DatamodelEnum[];
|
|
5
6
|
guardShapesImport: string | null;
|
|
7
|
+
importStyle: ImportStyle;
|
|
6
8
|
}): string;
|
|
@@ -3,7 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.generateFastifyRouterFunction = generateFastifyRouterFunction;
|
|
4
4
|
const strings_1 = require("../utils/strings");
|
|
5
5
|
const generateRouteConfigType_1 = require("./generateRouteConfigType");
|
|
6
|
-
|
|
6
|
+
const importExt_1 = require("../utils/importExt");
|
|
7
|
+
function generateFastifyRouterFunction({ model, enums, guardShapesImport, importStyle, }) {
|
|
8
|
+
const ext = (0, importExt_1.importExt)(importStyle);
|
|
7
9
|
const modelName = model.name;
|
|
8
10
|
const prefix = (0, strings_1.toCamelCase)(modelName);
|
|
9
11
|
const modelNameLower = modelName.toLowerCase();
|
|
@@ -46,14 +48,14 @@ import {
|
|
|
46
48
|
${prefix}Aggregate,
|
|
47
49
|
${prefix}Count,
|
|
48
50
|
${prefix}GroupBy,
|
|
49
|
-
} from './${modelName}Handlers'
|
|
50
|
-
import type { RouteConfig, FastifyHookHandler } from '../routeConfig.target'
|
|
51
|
-
import { parseQueryParams } from '../parseQueryParams'
|
|
52
|
-
import { sanitizeKeys } from '../misc'
|
|
53
|
-
import { buildModelOpenApi } from '../buildModelOpenApi'
|
|
54
|
-
import { mapError, transformResult, HttpError } from '../operationRuntime'
|
|
55
|
-
|
|
56
|
-
${(0, generateRouteConfigType_1.generateRouteConfigType)(modelName, 'FastifyHookHandler', guardShapesImport)}
|
|
51
|
+
} from './${modelName}Handlers${ext}'
|
|
52
|
+
import type { RouteConfig, FastifyHookHandler } from '../routeConfig.target${ext}'
|
|
53
|
+
import { parseQueryParams } from '../parseQueryParams${ext}'
|
|
54
|
+
import { sanitizeKeys } from '../misc${ext}'
|
|
55
|
+
import { buildModelOpenApi } from '../buildModelOpenApi${ext}'
|
|
56
|
+
import { mapError, transformResult, HttpError } from '../operationRuntime${ext}'
|
|
57
|
+
|
|
58
|
+
${(0, generateRouteConfigType_1.generateRouteConfigType)(modelName, 'FastifyHookHandler', guardShapesImport, importStyle, 'fastify')}
|
|
57
59
|
const _env = typeof process !== 'undefined' && process.env ? process.env : {} as Record<string, string | undefined>
|
|
58
60
|
|
|
59
61
|
const MODEL_FIELDS = ${JSON.stringify(fieldsMeta, null, 2)} as const
|
|
@@ -168,7 +170,7 @@ export async function ${routerFunctionName}<TCtx = unknown>(
|
|
|
168
170
|
if (qbEnabled) {
|
|
169
171
|
const qbConfig = getQueryBuilderConfig(config)
|
|
170
172
|
if (qbConfig) {
|
|
171
|
-
try { require('../queryBuilder').startQueryBuilder(qbConfig) } catch (err) { if (_env.NODE_ENV !== 'production') console.warn('[query-builder]', err) }
|
|
173
|
+
try { require('../queryBuilder${ext}').startQueryBuilder(qbConfig) } catch (err) { if (_env.NODE_ENV !== 'production') console.warn('[query-builder]', err) }
|
|
172
174
|
}
|
|
173
175
|
}
|
|
174
176
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateRouterFastify.js","sourceRoot":"","sources":["../../src/generators/generateRouterFastify.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"gener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;;;;;;;;;;;;kBAaJ,MAAM;;;;;;;;;;;;;;;;;;;gBAmBR,MAAM;;;;;;;;;;;;;kBAaJ,MAAM;;;;;;;;;;;;;;;;;;;gBAmBR,MAAM;;;;;;;;;;;;;kBAaJ,MAAM;;;;;;;;;;;;;;;;;;;gBAmBR,MAAM;;;;;;;;;;;;;kBAaJ,MAAM;;;;;;;;;;;;;;;;;;;gBAmBR,MAAM;;;;;;;;;;;;;kBAaJ,MAAM;;;;;;;;;;;;;;;;;;;gBAmBR,MAAM;;;;;;;;;;;;;kBAaJ,MAAM;;;;;;;;;;;;;;;;;;;gBAmBR,MAAM;;;;;;;;;;;;;kBAaJ,MAAM;;;;;;;;;;;;;;;;;;;gBAmBR,MAAM;;;;;;;;;;;;;;kBAcJ,MAAM;;;;;;;;;;;;;;;;;;gBAkBR,MAAM;;;;;;;;;;;;;;;;;gBAiBN,MAAM;;;;;;;;;;;;;;;;;gBAiBN,MAAM;;;;;;;;;;;;;;;;;gBAiBN,MAAM;;;;;;;;;;;;;;;;;gBAiBN,MAAM;;;;;;;;;;;;;;;;;gBAiBN,MAAM;;;;;;;;;;;;;;;;;gBAiBN,MAAM;;;;;;;;;;;;;;;;;gBAiBN,MAAM;;;;;;;;;;;;;;;;;gBAiBN,MAAM;;;;;;;;;CASrB,CAAA;AACD,CAAC"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { DMMF } from '@prisma/generator-helper';
|
|
2
|
-
|
|
2
|
+
import { ImportStyle } from '../utils/resolveImportStyle';
|
|
3
|
+
export declare function generateHonoRouterFunction({ model, enums, guardShapesImport, importStyle, }: {
|
|
3
4
|
model: DMMF.Model;
|
|
4
5
|
enums: DMMF.DatamodelEnum[];
|
|
5
6
|
guardShapesImport: string | null;
|
|
7
|
+
importStyle: ImportStyle;
|
|
6
8
|
}): string;
|