prisma-generator-express 1.16.7 → 1.19.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 +399 -194
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +1 -1
- package/dist/bin.js.map +1 -1
- package/dist/client/encodeQueryParams.d.ts +1 -0
- package/dist/client/encodeQueryParams.js +33 -0
- package/dist/client/encodeQueryParams.js.map +1 -0
- package/dist/constants.d.ts +1 -0
- package/dist/copy/misc.d.ts +5 -0
- package/dist/copy/misc.js +52 -0
- package/dist/copy/misc.js.map +1 -0
- package/dist/generators/generateImportPrismaStatement.d.ts +3 -0
- package/dist/generators/generateImportPrismaStatement.js +55 -0
- package/dist/generators/generateImportPrismaStatement.js.map +1 -0
- package/dist/generators/generateQueryBuilderHelper.d.ts +2 -0
- package/dist/generators/generateQueryBuilderHelper.js +139 -0
- package/dist/generators/generateQueryBuilderHelper.js.map +1 -0
- package/dist/generators/generateRouter.d.ts +6 -0
- package/dist/generators/generateRouter.js +340 -0
- package/dist/generators/generateRouter.js.map +1 -0
- package/dist/generators/generateUnifiedDocs.d.ts +1 -0
- package/dist/generators/generateUnifiedDocs.js +171 -0
- package/dist/generators/generateUnifiedDocs.js.map +1 -0
- package/dist/generators/generateUnifiedHandler.d.ts +6 -0
- package/dist/generators/generateUnifiedHandler.js +444 -0
- package/dist/generators/generateUnifiedHandler.js.map +1 -0
- package/dist/generators/generateUnifiedScalarUI.d.ts +5 -0
- package/dist/generators/generateUnifiedScalarUI.js +1390 -0
- package/dist/generators/generateUnifiedScalarUI.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +80 -0
- package/dist/index.js.map +1 -0
- package/dist/utils/copyFiles.d.ts +6 -0
- package/dist/utils/copyFiles.js +123 -21
- package/dist/utils/copyFiles.js.map +1 -1
- package/dist/utils/strings.d.ts +2 -0
- package/dist/utils/writeFileSafely.d.ts +10 -0
- package/dist/utils/writeFileSafely.js +86 -14
- package/dist/utils/writeFileSafely.js.map +1 -1
- package/package.json +64 -31
- package/src/client/encodeQueryParams.ts +56 -0
- package/src/copy/buildModelOpenApi.ts +1569 -0
- package/src/copy/createOutputValidatorMiddleware.ts +1 -1
- package/src/copy/createValidatorMiddleware.ts +1 -1
- package/src/copy/misc.ts +22 -1
- package/src/copy/operationDefinitions.ts +96 -0
- package/src/copy/parseQueryParams.ts +36 -21
- package/src/copy/routeConfig.ts +69 -27
- package/src/copy/transformZod.ts +15 -16
- package/dist/generator.js +0 -168
- package/dist/generator.js.map +0 -1
- package/dist/helpers/generateAggregate.js +0 -51
- package/dist/helpers/generateAggregate.js.map +0 -1
- package/dist/helpers/generateCount.js +0 -50
- package/dist/helpers/generateCount.js.map +0 -1
- package/dist/helpers/generateCreate.js +0 -49
- package/dist/helpers/generateCreate.js.map +0 -1
- package/dist/helpers/generateCreateMany.js +0 -49
- package/dist/helpers/generateCreateMany.js.map +0 -1
- package/dist/helpers/generateDelete.js +0 -49
- package/dist/helpers/generateDelete.js.map +0 -1
- package/dist/helpers/generateDeleteMany.js +0 -49
- package/dist/helpers/generateDeleteMany.js.map +0 -1
- package/dist/helpers/generateFindFirst.js +0 -56
- package/dist/helpers/generateFindFirst.js.map +0 -1
- package/dist/helpers/generateFindMany.js +0 -56
- package/dist/helpers/generateFindMany.js.map +0 -1
- package/dist/helpers/generateFindUnique.js +0 -56
- package/dist/helpers/generateFindUnique.js.map +0 -1
- package/dist/helpers/generateGroupBy.js +0 -51
- package/dist/helpers/generateGroupBy.js.map +0 -1
- package/dist/helpers/generateImportPrismaStatement.js +0 -25
- package/dist/helpers/generateImportPrismaStatement.js.map +0 -1
- package/dist/helpers/generateRouteFile.js +0 -192
- package/dist/helpers/generateRouteFile.js.map +0 -1
- package/dist/helpers/generateUpdate.js +0 -49
- package/dist/helpers/generateUpdate.js.map +0 -1
- package/dist/helpers/generateUpdateMany.js +0 -49
- package/dist/helpers/generateUpdateMany.js.map +0 -1
- package/dist/helpers/generateUpsert.js +0 -49
- package/dist/helpers/generateUpsert.js.map +0 -1
- package/dist/utils/formatFile.js +0 -26
- package/dist/utils/formatFile.js.map +0 -1
- package/src/bin.ts +0 -2
- package/src/constants.ts +0 -1
- package/src/copy/encodeQueryParams.spec.ts +0 -303
- package/src/copy/encodeQueryParams.ts +0 -44
- package/src/copy/misc.spec.ts +0 -62
- package/src/copy/parseQueryParams.spec.ts +0 -187
- package/src/copy/transformZod.spec.ts +0 -763
- package/src/generator.ts +0 -188
- package/src/helpers/generateAggregate.ts +0 -59
- package/src/helpers/generateCount.ts +0 -58
- package/src/helpers/generateCreate.ts +0 -56
- package/src/helpers/generateCreateMany.ts +0 -55
- package/src/helpers/generateDelete.ts +0 -57
- package/src/helpers/generateDeleteMany.ts +0 -57
- package/src/helpers/generateFindFirst.ts +0 -62
- package/src/helpers/generateFindMany.ts +0 -62
- package/src/helpers/generateFindUnique.ts +0 -62
- package/src/helpers/generateGroupBy.ts +0 -60
- package/src/helpers/generateImportPrismaStatement.ts +0 -38
- package/src/helpers/generateRouteFile.ts +0 -195
- package/src/helpers/generateUpdate.ts +0 -56
- package/src/helpers/generateUpdateMany.ts +0 -56
- package/src/helpers/generateUpsert.ts +0 -57
- package/src/utils/copyFiles.ts +0 -27
- package/src/utils/formatFile.ts +0 -22
- package/src/utils/strings.ts +0 -7
- package/src/utils/writeFileSafely.ts +0 -29
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateCountFunction = void 0;
|
|
4
|
-
const strings_1 = require("../utils/strings");
|
|
5
|
-
const generateCountFunction = (options) => {
|
|
6
|
-
const { model, prismaImportStatement } = options;
|
|
7
|
-
const modelName = model.name;
|
|
8
|
-
const functionName = `${modelName}Count`;
|
|
9
|
-
const argsTypeName = `Prisma.${modelName}CountArgs`;
|
|
10
|
-
return `
|
|
11
|
-
${prismaImportStatement}
|
|
12
|
-
import { Request, Response, NextFunction } from 'express';
|
|
13
|
-
import { RequestHandler, ParamsDictionary } from 'express-serve-static-core';
|
|
14
|
-
import { ParsedQs } from 'qs';
|
|
15
|
-
import { ZodTypeAny } from 'zod';
|
|
16
|
-
|
|
17
|
-
interface CountRequest extends Request {
|
|
18
|
-
prisma: PrismaClient;
|
|
19
|
-
query: Partial<${argsTypeName}> & ParsedQs;
|
|
20
|
-
outputValidation?: ZodTypeAny;
|
|
21
|
-
locals?: {
|
|
22
|
-
outputValidator?: ZodTypeAny;
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export type CountMiddleware = RequestHandler<ParamsDictionary, any, {}, ParsedQs>;
|
|
27
|
-
|
|
28
|
-
export async function ${functionName}(req: CountRequest, res: Response, next: NextFunction) {
|
|
29
|
-
try {
|
|
30
|
-
const outputValidator = req.locals?.outputValidator || req.outputValidation;
|
|
31
|
-
|
|
32
|
-
const result = await req.prisma.${(0, strings_1.toPascalCase)(modelName)}.count(req.query as ${argsTypeName});
|
|
33
|
-
|
|
34
|
-
if (outputValidator) {
|
|
35
|
-
const validationResult = outputValidator.safeParse(result);
|
|
36
|
-
if (validationResult.success) {
|
|
37
|
-
return res.status(200).json(validationResult.data);
|
|
38
|
-
} else {
|
|
39
|
-
return res.status(400).json({ error: 'Invalid data format', details: validationResult.error });
|
|
40
|
-
}
|
|
41
|
-
} else {
|
|
42
|
-
return res.status(200).json(result);
|
|
43
|
-
}
|
|
44
|
-
} catch(error: unknown) {
|
|
45
|
-
next(error)
|
|
46
|
-
}
|
|
47
|
-
}`;
|
|
48
|
-
};
|
|
49
|
-
exports.generateCountFunction = generateCountFunction;
|
|
50
|
-
//# sourceMappingURL=generateCount.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generateCount.js","sourceRoot":"","sources":["../../src/helpers/generateCount.ts"],"names":[],"mappings":";;;AACA,8CAA+C;AASxC,MAAM,qBAAqB,GAAG,CAAC,OAGrC,EAAU,EAAE;IACX,MAAM,EAAE,KAAK,EAAE,qBAAqB,EAAE,GAAG,OAAO,CAAA;IAChD,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAA;IAC5B,MAAM,YAAY,GAAG,GAAG,SAAS,OAAO,CAAA;IACxC,MAAM,YAAY,GAAG,UAAU,SAAS,WAAW,CAAA;IAEnD,OAAO;EACP,qBAAqB;;;;;;;;mBAQJ,YAAY;;;;;;;;;wBASP,YAAY;;;;sCAIE,IAAA,sBAAY,EAAC,SAAS,CAAC,uBAAuB,YAAY;;;;;;;;;;;;;;;EAe9F,CAAA;AACF,CAAC,CAAA;AA/CY,QAAA,qBAAqB,yBA+CjC"}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateCreateFunction = void 0;
|
|
4
|
-
const strings_1 = require("../utils/strings");
|
|
5
|
-
const generateCreateFunction = (options) => {
|
|
6
|
-
const { model, prismaImportStatement } = options;
|
|
7
|
-
const modelName = model.name;
|
|
8
|
-
const functionName = `${modelName}Create`;
|
|
9
|
-
const argsTypeName = `Prisma.${modelName}CreateArgs`;
|
|
10
|
-
return `
|
|
11
|
-
${prismaImportStatement}
|
|
12
|
-
import { Request, Response, NextFunction } from 'express';
|
|
13
|
-
import { RequestHandler, ParamsDictionary } from 'express-serve-static-core'
|
|
14
|
-
import { ZodTypeAny } from 'zod';
|
|
15
|
-
|
|
16
|
-
interface CreateRequest extends Request {
|
|
17
|
-
prisma: PrismaClient;
|
|
18
|
-
body: ${argsTypeName};
|
|
19
|
-
outputValidation?: ZodTypeAny;
|
|
20
|
-
locals?: {
|
|
21
|
-
outputValidator?: ZodTypeAny;
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export type CreateMiddleware = RequestHandler<ParamsDictionary, any, ${argsTypeName}, Record<string, any>>
|
|
26
|
-
|
|
27
|
-
export async function ${functionName}(req: CreateRequest, res: Response, next: NextFunction) {
|
|
28
|
-
try {
|
|
29
|
-
const outputValidator = req.locals?.outputValidator || req.outputValidation;
|
|
30
|
-
|
|
31
|
-
const data = await req.prisma.${(0, strings_1.toPascalCase)(modelName)}.create(req.body);
|
|
32
|
-
|
|
33
|
-
if (outputValidator) {
|
|
34
|
-
const validationResult = outputValidator.safeParse(data);
|
|
35
|
-
if (validationResult.success) {
|
|
36
|
-
return res.status(201).json(validationResult.data);
|
|
37
|
-
} else {
|
|
38
|
-
return res.status(400).json({ error: 'Invalid data format', details: validationResult.error });
|
|
39
|
-
}
|
|
40
|
-
} else {
|
|
41
|
-
return res.status(201).json(data);
|
|
42
|
-
}
|
|
43
|
-
} catch(error: unknown) {
|
|
44
|
-
next(error)
|
|
45
|
-
}
|
|
46
|
-
}`;
|
|
47
|
-
};
|
|
48
|
-
exports.generateCreateFunction = generateCreateFunction;
|
|
49
|
-
//# sourceMappingURL=generateCreate.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generateCreate.js","sourceRoot":"","sources":["../../src/helpers/generateCreate.ts"],"names":[],"mappings":";;;AACA,8CAA+C;AAQxC,MAAM,sBAAsB,GAAG,CAAC,OAGtC,EAAU,EAAE;IACX,MAAM,EAAE,KAAK,EAAE,qBAAqB,EAAE,GAAG,OAAO,CAAA;IAChD,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAA;IAC5B,MAAM,YAAY,GAAG,GAAG,SAAS,QAAQ,CAAA;IACzC,MAAM,YAAY,GAAG,UAAU,SAAS,YAAY,CAAA;IAEpD,OAAO;EACP,qBAAqB;;;;;;;UAOb,YAAY;;;;;;;uEAOiD,YAAY;;wBAE3D,YAAY;;;;oCAIA,IAAA,sBAAY,EAAC,SAAS,CAAC;;;;;;;;;;;;;;;EAezD,CAAA;AACF,CAAC,CAAA;AA9CY,QAAA,sBAAsB,0BA8ClC"}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateCreateManyFunction = void 0;
|
|
4
|
-
const strings_1 = require("../utils/strings");
|
|
5
|
-
const generateCreateManyFunction = (options) => {
|
|
6
|
-
const { model, prismaImportStatement } = options;
|
|
7
|
-
const modelName = model.name;
|
|
8
|
-
const functionName = `${modelName}CreateMany`;
|
|
9
|
-
const argsTypeName = `Prisma.${modelName}CreateManyArgs`;
|
|
10
|
-
return `
|
|
11
|
-
${prismaImportStatement}
|
|
12
|
-
import { Request, Response, NextFunction } from 'express';
|
|
13
|
-
import { RequestHandler, ParamsDictionary } from 'express-serve-static-core';
|
|
14
|
-
import { ZodTypeAny } from 'zod';
|
|
15
|
-
|
|
16
|
-
interface CreateManyRequest extends Request {
|
|
17
|
-
prisma: PrismaClient;
|
|
18
|
-
body: ${argsTypeName};
|
|
19
|
-
outputValidation?: ZodTypeAny;
|
|
20
|
-
locals?: {
|
|
21
|
-
outputValidator?: ZodTypeAny;
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export type CreateManyMiddleware = RequestHandler<ParamsDictionary, any, ${argsTypeName}, Record<string, any>>
|
|
26
|
-
|
|
27
|
-
export async function ${functionName}(req: CreateManyRequest, res: Response, next: NextFunction) {
|
|
28
|
-
try {
|
|
29
|
-
const outputValidator = req.locals?.outputValidator || req.outputValidation;
|
|
30
|
-
|
|
31
|
-
const data = await req.prisma.${(0, strings_1.toPascalCase)(modelName)}.createMany(req.body);
|
|
32
|
-
|
|
33
|
-
if (outputValidator) {
|
|
34
|
-
const validationResult = outputValidator.safeParse(data);
|
|
35
|
-
if (validationResult.success) {
|
|
36
|
-
return res.status(201).json(validationResult.data);
|
|
37
|
-
} else {
|
|
38
|
-
return res.status(400).json({ error: 'Invalid data format', details: validationResult.error });
|
|
39
|
-
}
|
|
40
|
-
} else {
|
|
41
|
-
return res.status(201).json(data);
|
|
42
|
-
}
|
|
43
|
-
} catch(error: unknown) {
|
|
44
|
-
next(error)
|
|
45
|
-
}
|
|
46
|
-
}`;
|
|
47
|
-
};
|
|
48
|
-
exports.generateCreateManyFunction = generateCreateManyFunction;
|
|
49
|
-
//# sourceMappingURL=generateCreateMany.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generateCreateMany.js","sourceRoot":"","sources":["../../src/helpers/generateCreateMany.ts"],"names":[],"mappings":";;;AACA,8CAA+C;AAOxC,MAAM,0BAA0B,GAAG,CAAC,OAG1C,EAAU,EAAE;IACX,MAAM,EAAE,KAAK,EAAE,qBAAqB,EAAE,GAAG,OAAO,CAAA;IAChD,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAA;IAC5B,MAAM,YAAY,GAAG,GAAG,SAAS,YAAY,CAAA;IAC7C,MAAM,YAAY,GAAG,UAAU,SAAS,gBAAgB,CAAA;IAExD,OAAO;EACP,qBAAqB;;;;;;;UAOb,YAAY;;;;;;;2EAOqD,YAAY;;wBAE/D,YAAY;;;;oCAIA,IAAA,sBAAY,EAAC,SAAS,CAAC;;;;;;;;;;;;;;;EAezD,CAAA;AACF,CAAC,CAAA;AA9CY,QAAA,0BAA0B,8BA8CtC"}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateDeleteFunction = void 0;
|
|
4
|
-
const strings_1 = require("../utils/strings");
|
|
5
|
-
const generateDeleteFunction = (options) => {
|
|
6
|
-
const { model, prismaImportStatement } = options;
|
|
7
|
-
const modelName = model.name;
|
|
8
|
-
const functionName = `${modelName}Delete`;
|
|
9
|
-
const argsTypeName = `Prisma.${modelName}DeleteArgs`;
|
|
10
|
-
return `
|
|
11
|
-
${prismaImportStatement}
|
|
12
|
-
import { Request, Response, NextFunction } from 'express';
|
|
13
|
-
import { RequestHandler, ParamsDictionary } from 'express-serve-static-core';
|
|
14
|
-
import { ZodTypeAny } from 'zod';
|
|
15
|
-
|
|
16
|
-
interface DeleteRequest extends Request {
|
|
17
|
-
prisma: PrismaClient;
|
|
18
|
-
body: ${argsTypeName};
|
|
19
|
-
outputValidation?: ZodTypeAny;
|
|
20
|
-
locals?: {
|
|
21
|
-
outputValidator?: ZodTypeAny;
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export type DeleteMiddleware = RequestHandler<ParamsDictionary, any, ${argsTypeName}, Record<string, any>>
|
|
26
|
-
|
|
27
|
-
export async function ${functionName}(req: DeleteRequest, res: Response, next: NextFunction) {
|
|
28
|
-
try {
|
|
29
|
-
const outputValidator = req.locals?.outputValidator || req.outputValidation;
|
|
30
|
-
|
|
31
|
-
const data = await req.prisma.${(0, strings_1.toPascalCase)(modelName)}.delete(req.body);
|
|
32
|
-
|
|
33
|
-
if (outputValidator) {
|
|
34
|
-
const validationResult = outputValidator.safeParse(data);
|
|
35
|
-
if (validationResult.success) {
|
|
36
|
-
return res.status(200).json(validationResult.data);
|
|
37
|
-
} else {
|
|
38
|
-
return res.status(400).json({ error: 'Invalid data format', details: validationResult.error });
|
|
39
|
-
}
|
|
40
|
-
} else {
|
|
41
|
-
return res.status(200).json(data);
|
|
42
|
-
}
|
|
43
|
-
} catch(error: unknown) {
|
|
44
|
-
next(error)
|
|
45
|
-
}
|
|
46
|
-
}`;
|
|
47
|
-
};
|
|
48
|
-
exports.generateDeleteFunction = generateDeleteFunction;
|
|
49
|
-
//# sourceMappingURL=generateDelete.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generateDelete.js","sourceRoot":"","sources":["../../src/helpers/generateDelete.ts"],"names":[],"mappings":";;;AACA,8CAA+C;AASxC,MAAM,sBAAsB,GAAG,CAAC,OAGtC,EAAU,EAAE;IACX,MAAM,EAAE,KAAK,EAAE,qBAAqB,EAAE,GAAG,OAAO,CAAA;IAChD,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAA;IAC5B,MAAM,YAAY,GAAG,GAAG,SAAS,QAAQ,CAAA;IACzC,MAAM,YAAY,GAAG,UAAU,SAAS,YAAY,CAAA;IAEpD,OAAO;EACP,qBAAqB;;;;;;;UAOb,YAAY;;;;;;;uEAOiD,YAAY;;wBAE3D,YAAY;;;;oCAIA,IAAA,sBAAY,EAAC,SAAS,CAAC;;;;;;;;;;;;;;;EAezD,CAAA;AACF,CAAC,CAAA;AA9CY,QAAA,sBAAsB,0BA8ClC"}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateDeleteManyFunction = void 0;
|
|
4
|
-
const strings_1 = require("../utils/strings");
|
|
5
|
-
const generateDeleteManyFunction = (options) => {
|
|
6
|
-
const { model, prismaImportStatement } = options;
|
|
7
|
-
const modelName = model.name;
|
|
8
|
-
const functionName = `${modelName}DeleteMany`;
|
|
9
|
-
const argsTypeName = `Prisma.${modelName}DeleteManyArgs`;
|
|
10
|
-
return `
|
|
11
|
-
${prismaImportStatement}
|
|
12
|
-
import { Request, Response, NextFunction } from 'express';
|
|
13
|
-
import { RequestHandler, ParamsDictionary } from 'express-serve-static-core';
|
|
14
|
-
import { ZodTypeAny } from 'zod';
|
|
15
|
-
|
|
16
|
-
interface DeleteManyRequest extends Request {
|
|
17
|
-
prisma: PrismaClient;
|
|
18
|
-
body: ${argsTypeName};
|
|
19
|
-
outputValidation?: ZodTypeAny;
|
|
20
|
-
locals?: {
|
|
21
|
-
outputValidator?: ZodTypeAny;
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export type DeleteManyMiddleware = RequestHandler<ParamsDictionary, any, ${argsTypeName}, Record<string, any>>;
|
|
26
|
-
|
|
27
|
-
export async function ${functionName}(req: DeleteManyRequest, res: Response, next: NextFunction) {
|
|
28
|
-
try {
|
|
29
|
-
const outputValidator = req.locals?.outputValidator || req.outputValidation;
|
|
30
|
-
|
|
31
|
-
const result = await req.prisma.${(0, strings_1.toPascalCase)(modelName)}.deleteMany(req.body);
|
|
32
|
-
|
|
33
|
-
if (outputValidator) {
|
|
34
|
-
const validationResult = outputValidator.safeParse(result);
|
|
35
|
-
if (validationResult.success) {
|
|
36
|
-
return res.status(200).json(validationResult.data);
|
|
37
|
-
} else {
|
|
38
|
-
return res.status(400).json({ error: 'Invalid data format', details: validationResult.error });
|
|
39
|
-
}
|
|
40
|
-
} else {
|
|
41
|
-
return res.status(200).json(result);
|
|
42
|
-
}
|
|
43
|
-
} catch(error: unknown) {
|
|
44
|
-
next(error)
|
|
45
|
-
}
|
|
46
|
-
}`;
|
|
47
|
-
};
|
|
48
|
-
exports.generateDeleteManyFunction = generateDeleteManyFunction;
|
|
49
|
-
//# sourceMappingURL=generateDeleteMany.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generateDeleteMany.js","sourceRoot":"","sources":["../../src/helpers/generateDeleteMany.ts"],"names":[],"mappings":";;;AACA,8CAA+C;AASxC,MAAM,0BAA0B,GAAG,CAAC,OAG1C,EAAU,EAAE;IACX,MAAM,EAAE,KAAK,EAAE,qBAAqB,EAAE,GAAG,OAAO,CAAA;IAChD,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAA;IAC5B,MAAM,YAAY,GAAG,GAAG,SAAS,YAAY,CAAA;IAC7C,MAAM,YAAY,GAAG,UAAU,SAAS,gBAAgB,CAAA;IAExD,OAAO;EACP,qBAAqB;;;;;;;UAOb,YAAY;;;;;;;2EAOqD,YAAY;;wBAE/D,YAAY;;;;sCAIE,IAAA,sBAAY,EAAC,SAAS,CAAC;;;;;;;;;;;;;;;EAe3D,CAAA;AACF,CAAC,CAAA;AA9CY,QAAA,0BAA0B,8BA8CtC"}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateFindFirstFunction = void 0;
|
|
4
|
-
const strings_1 = require("../utils/strings");
|
|
5
|
-
const generateFindFirstFunction = (options) => {
|
|
6
|
-
const { model, prismaImportStatement } = options;
|
|
7
|
-
const modelName = model.name;
|
|
8
|
-
const functionName = `${modelName}FindFirst`;
|
|
9
|
-
const queryTypeName = `Prisma.${modelName}FindFirstArgs`;
|
|
10
|
-
return `
|
|
11
|
-
${prismaImportStatement.replace('{ Prisma }', `{ Prisma, ${modelName} }`)}
|
|
12
|
-
import { Request, Response, NextFunction } from 'express'
|
|
13
|
-
import {
|
|
14
|
-
RequestHandler,
|
|
15
|
-
ParamsDictionary,
|
|
16
|
-
} from 'express-serve-static-core'
|
|
17
|
-
import { ParsedQs } from 'qs';
|
|
18
|
-
import { ZodTypeAny } from 'zod';
|
|
19
|
-
|
|
20
|
-
export interface FindFirstRequest extends Request {
|
|
21
|
-
prisma: PrismaClient;
|
|
22
|
-
query: ${queryTypeName} & ParsedQs;
|
|
23
|
-
outputValidation?: ZodTypeAny;
|
|
24
|
-
passToNext?: boolean;
|
|
25
|
-
locals?: {
|
|
26
|
-
data?: ${modelName} | null
|
|
27
|
-
outputValidator?: ZodTypeAny;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
export type FindFirstMiddleware = RequestHandler<ParamsDictionary, any, any, ${queryTypeName} & ParsedQs, Record<string, any>>
|
|
31
|
-
|
|
32
|
-
export async function ${functionName}(req: FindFirstRequest, res: Response, next: NextFunction) {
|
|
33
|
-
try {
|
|
34
|
-
const outputValidator = req.locals?.outputValidator || req.outputValidation;
|
|
35
|
-
|
|
36
|
-
const data = await req.prisma.${(0, strings_1.toPascalCase)(modelName)}.findFirst(req.query as ${queryTypeName});
|
|
37
|
-
if (req.passToNext) {
|
|
38
|
-
if (req.locals) req.locals.data = data;
|
|
39
|
-
next();
|
|
40
|
-
} else if (outputValidator) {
|
|
41
|
-
const validationResult = outputValidator.safeParse(data);
|
|
42
|
-
if (validationResult.success) {
|
|
43
|
-
return res.status(200).json(validationResult.data);
|
|
44
|
-
} else {
|
|
45
|
-
return res.status(400).json({ error: 'Invalid data format', details: validationResult.error });
|
|
46
|
-
}
|
|
47
|
-
} else {
|
|
48
|
-
return res.status(200).json(data);
|
|
49
|
-
}
|
|
50
|
-
} catch(error: unknown) {
|
|
51
|
-
next(error)
|
|
52
|
-
}
|
|
53
|
-
}`;
|
|
54
|
-
};
|
|
55
|
-
exports.generateFindFirstFunction = generateFindFirstFunction;
|
|
56
|
-
//# sourceMappingURL=generateFindFirst.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generateFindFirst.js","sourceRoot":"","sources":["../../src/helpers/generateFindFirst.ts"],"names":[],"mappings":";;;AACA,8CAA+C;AAOxC,MAAM,yBAAyB,GAAG,CAAC,OAGzC,EAAU,EAAE;IACX,MAAM,EAAE,KAAK,EAAE,qBAAqB,EAAE,GAAG,OAAO,CAAA;IAChD,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAA;IAC5B,MAAM,YAAY,GAAG,GAAG,SAAS,WAAW,CAAA;IAC5C,MAAM,aAAa,GAAG,UAAU,SAAS,eAAe,CAAA;IAExD,OAAO;EACP,qBAAqB,CAAC,OAAO,CAAC,YAAY,EAAE,aAAa,SAAS,IAAI,CAAC;;;;;;;;;;;WAW9D,aAAa;;;;aAIX,SAAS;;;;+EAIyD,aAAa;;wBAEpE,YAAY;;;;oCAIA,IAAA,sBAAY,EAAC,SAAS,CAAC,2BAA2B,aAAa;;;;;;;;;;;;;;;;;EAiBjG,CAAA;AACF,CAAC,CAAA;AArDY,QAAA,yBAAyB,6BAqDrC"}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateFindManyFunction = void 0;
|
|
4
|
-
const strings_1 = require("../utils/strings");
|
|
5
|
-
const generateFindManyFunction = (options) => {
|
|
6
|
-
const { model, prismaImportStatement } = options;
|
|
7
|
-
const modelName = model.name;
|
|
8
|
-
const functionName = `${modelName}FindMany`;
|
|
9
|
-
const queryTypeName = `Prisma.${modelName}FindManyArgs`;
|
|
10
|
-
return `
|
|
11
|
-
${prismaImportStatement.replace('{ Prisma }', `{ Prisma, ${modelName} }`)}
|
|
12
|
-
import { Request, Response, NextFunction } from 'express'
|
|
13
|
-
import {
|
|
14
|
-
RequestHandler,
|
|
15
|
-
ParamsDictionary,
|
|
16
|
-
} from 'express-serve-static-core'
|
|
17
|
-
import { ParsedQs } from 'qs';
|
|
18
|
-
import { ZodTypeAny } from 'zod';
|
|
19
|
-
|
|
20
|
-
export interface FindManyRequest extends Request {
|
|
21
|
-
prisma: PrismaClient;
|
|
22
|
-
query: ${queryTypeName} & ParsedQs;
|
|
23
|
-
outputValidation?: ZodTypeAny;
|
|
24
|
-
passToNext?: boolean;
|
|
25
|
-
locals?: {
|
|
26
|
-
data?: ${modelName}[]
|
|
27
|
-
outputValidator?: ZodTypeAny;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
export type FindManyMiddleware = RequestHandler<ParamsDictionary, any, any, ${queryTypeName} & ParsedQs, Record<string, any>>
|
|
31
|
-
|
|
32
|
-
export async function ${functionName}(req: FindManyRequest, res: Response, next: NextFunction) {
|
|
33
|
-
try {
|
|
34
|
-
const outputValidator = req.locals?.outputValidator || req.outputValidation;
|
|
35
|
-
|
|
36
|
-
const data = await req.prisma.${(0, strings_1.toPascalCase)(modelName)}.findMany(req.query as ${queryTypeName});
|
|
37
|
-
if (req.passToNext) {
|
|
38
|
-
if (req.locals) req.locals.data = data;
|
|
39
|
-
next();
|
|
40
|
-
} else if (outputValidator) {
|
|
41
|
-
const validationResult = outputValidator.safeParse(data);
|
|
42
|
-
if (validationResult.success) {
|
|
43
|
-
return res.status(200).json(validationResult.data);
|
|
44
|
-
} else {
|
|
45
|
-
return res.status(400).json({ error: 'Invalid data format', details: validationResult.error });
|
|
46
|
-
}
|
|
47
|
-
} else {
|
|
48
|
-
return res.status(200).json(data);
|
|
49
|
-
}
|
|
50
|
-
} catch(error: unknown) {
|
|
51
|
-
next(error)
|
|
52
|
-
}
|
|
53
|
-
}`;
|
|
54
|
-
};
|
|
55
|
-
exports.generateFindManyFunction = generateFindManyFunction;
|
|
56
|
-
//# sourceMappingURL=generateFindMany.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generateFindMany.js","sourceRoot":"","sources":["../../src/helpers/generateFindMany.ts"],"names":[],"mappings":";;;AACA,8CAA+C;AAOxC,MAAM,wBAAwB,GAAG,CAAC,OAGxC,EAAU,EAAE;IACX,MAAM,EAAE,KAAK,EAAE,qBAAqB,EAAE,GAAG,OAAO,CAAA;IAChD,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAA;IAC5B,MAAM,YAAY,GAAG,GAAG,SAAS,UAAU,CAAA;IAC3C,MAAM,aAAa,GAAG,UAAU,SAAS,cAAc,CAAA;IAEvD,OAAO;EACP,qBAAqB,CAAC,OAAO,CAAC,YAAY,EAAE,aAAa,SAAS,IAAI,CAAC;;;;;;;;;;;WAW9D,aAAa;;;;aAIX,SAAS;;;;8EAIwD,aAAa;;wBAEnE,YAAY;;;;oCAIA,IAAA,sBAAY,EAAC,SAAS,CAAC,0BAA0B,aAAa;;;;;;;;;;;;;;;;;EAiBhG,CAAA;AACF,CAAC,CAAA;AArDY,QAAA,wBAAwB,4BAqDpC"}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateFindUniqueFunction = void 0;
|
|
4
|
-
const strings_1 = require("../utils/strings");
|
|
5
|
-
const generateFindUniqueFunction = (options) => {
|
|
6
|
-
const { model, prismaImportStatement } = options;
|
|
7
|
-
const modelName = model.name;
|
|
8
|
-
const functionName = `${modelName}FindUnique`;
|
|
9
|
-
const queryTypeName = `Prisma.${modelName}FindUniqueArgs`;
|
|
10
|
-
return `
|
|
11
|
-
${prismaImportStatement.replace('{ Prisma }', `{ Prisma, ${modelName} }`)}
|
|
12
|
-
import { Request, Response, NextFunction } from 'express'
|
|
13
|
-
import {
|
|
14
|
-
RequestHandler,
|
|
15
|
-
ParamsDictionary,
|
|
16
|
-
} from 'express-serve-static-core'
|
|
17
|
-
import { ParsedQs } from 'qs';
|
|
18
|
-
import { ZodTypeAny } from 'zod';
|
|
19
|
-
|
|
20
|
-
export interface FindUniqueRequest extends Request {
|
|
21
|
-
prisma: PrismaClient;
|
|
22
|
-
query: ${queryTypeName} & ParsedQs;
|
|
23
|
-
outputValidation?: ZodTypeAny;
|
|
24
|
-
passToNext?: boolean;
|
|
25
|
-
locals?: {
|
|
26
|
-
data?: ${modelName} | null
|
|
27
|
-
outputValidator?: ZodTypeAny;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
export type FindUniqueMiddleware = RequestHandler<ParamsDictionary, any, any, ${queryTypeName} & ParsedQs, Record<string, any>>
|
|
31
|
-
|
|
32
|
-
export async function ${functionName}(req: FindUniqueRequest, res: Response, next: NextFunction) {
|
|
33
|
-
try {
|
|
34
|
-
const outputValidator = req.locals?.outputValidator || req.outputValidation;
|
|
35
|
-
|
|
36
|
-
const data = await req.prisma.${(0, strings_1.toPascalCase)(modelName)}.findUnique(req.query as ${queryTypeName});
|
|
37
|
-
if (req.passToNext) {
|
|
38
|
-
if (req.locals) req.locals.data = data;
|
|
39
|
-
next();
|
|
40
|
-
} else if (outputValidator) {
|
|
41
|
-
const validationResult = outputValidator.safeParse(data);
|
|
42
|
-
if (validationResult.success) {
|
|
43
|
-
return res.status(200).json(validationResult.data);
|
|
44
|
-
} else {
|
|
45
|
-
return res.status(400).json({ error: 'Invalid data format', details: validationResult.error });
|
|
46
|
-
}
|
|
47
|
-
} else {
|
|
48
|
-
return res.status(200).json(data);
|
|
49
|
-
}
|
|
50
|
-
} catch(error: unknown) {
|
|
51
|
-
next(error)
|
|
52
|
-
}
|
|
53
|
-
}`;
|
|
54
|
-
};
|
|
55
|
-
exports.generateFindUniqueFunction = generateFindUniqueFunction;
|
|
56
|
-
//# sourceMappingURL=generateFindUnique.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generateFindUnique.js","sourceRoot":"","sources":["../../src/helpers/generateFindUnique.ts"],"names":[],"mappings":";;;AACA,8CAA+C;AAOxC,MAAM,0BAA0B,GAAG,CAAC,OAG1C,EAAU,EAAE;IACX,MAAM,EAAE,KAAK,EAAE,qBAAqB,EAAE,GAAG,OAAO,CAAA;IAChD,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAA;IAC5B,MAAM,YAAY,GAAG,GAAG,SAAS,YAAY,CAAA;IAC7C,MAAM,aAAa,GAAG,UAAU,SAAS,gBAAgB,CAAA;IAEzD,OAAO;EACP,qBAAqB,CAAC,OAAO,CAAC,YAAY,EAAE,aAAa,SAAS,IAAI,CAAC;;;;;;;;;;;WAW9D,aAAa;;;;aAIX,SAAS;;;;gFAI0D,aAAa;;wBAErE,YAAY;;;;oCAIA,IAAA,sBAAY,EAAC,SAAS,CAAC,4BAA4B,aAAa;;;;;;;;;;;;;;;;;EAiBlG,CAAA;AACF,CAAC,CAAA;AArDY,QAAA,0BAA0B,8BAqDtC"}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateGroupByFunction = void 0;
|
|
4
|
-
const strings_1 = require("../utils/strings");
|
|
5
|
-
const generateGroupByFunction = (options) => {
|
|
6
|
-
const { model, prismaImportStatement } = options;
|
|
7
|
-
const modelName = model.name;
|
|
8
|
-
const functionName = `${modelName}GroupBy`;
|
|
9
|
-
const argsTypeName = `Prisma.${modelName}GroupByArgs`;
|
|
10
|
-
return `
|
|
11
|
-
${prismaImportStatement}
|
|
12
|
-
import { Request, Response, NextFunction } from 'express';
|
|
13
|
-
import { RequestHandler, ParamsDictionary } from 'express-serve-static-core';
|
|
14
|
-
import { ParsedQs } from 'qs';
|
|
15
|
-
import { ZodTypeAny } from 'zod';
|
|
16
|
-
|
|
17
|
-
interface GroupByRequest extends Request {
|
|
18
|
-
prisma: PrismaClient;
|
|
19
|
-
query: Partial<${argsTypeName}> & ParsedQs;
|
|
20
|
-
outputValidation?: ZodTypeAny;
|
|
21
|
-
locals?: {
|
|
22
|
-
outputValidator?: ZodTypeAny;
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export type GroupByMiddleware = RequestHandler<ParamsDictionary, any, {}, ParsedQs>;
|
|
27
|
-
|
|
28
|
-
export async function ${functionName}(req: GroupByRequest, res: Response, next: NextFunction) {
|
|
29
|
-
try {
|
|
30
|
-
const outputValidator = req.locals?.outputValidator || req.outputValidation;
|
|
31
|
-
|
|
32
|
-
// @ts-ignore
|
|
33
|
-
const result = await req.prisma.${(0, strings_1.toPascalCase)(modelName)}.groupBy(req.query);
|
|
34
|
-
|
|
35
|
-
if (outputValidator) {
|
|
36
|
-
const validationResult = outputValidator.safeParse(result);
|
|
37
|
-
if (validationResult.success) {
|
|
38
|
-
return res.status(200).json(validationResult.data);
|
|
39
|
-
} else {
|
|
40
|
-
return res.status(400).json({ error: 'Invalid data format', details: validationResult.error });
|
|
41
|
-
}
|
|
42
|
-
} else {
|
|
43
|
-
return res.status(200).json(result);
|
|
44
|
-
}
|
|
45
|
-
} catch(error: unknown) {
|
|
46
|
-
next(error)
|
|
47
|
-
}
|
|
48
|
-
}`;
|
|
49
|
-
};
|
|
50
|
-
exports.generateGroupByFunction = generateGroupByFunction;
|
|
51
|
-
//# sourceMappingURL=generateGroupBy.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generateGroupBy.js","sourceRoot":"","sources":["../../src/helpers/generateGroupBy.ts"],"names":[],"mappings":";;;AACA,8CAA+C;AAUxC,MAAM,uBAAuB,GAAG,CAAC,OAGvC,EAAU,EAAE;IACX,MAAM,EAAE,KAAK,EAAE,qBAAqB,EAAE,GAAG,OAAO,CAAA;IAChD,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAA;IAC5B,MAAM,YAAY,GAAG,GAAG,SAAS,SAAS,CAAA;IAC1C,MAAM,YAAY,GAAG,UAAU,SAAS,aAAa,CAAA;IAErD,OAAO;EACP,qBAAqB;;;;;;;;mBAQJ,YAAY;;;;;;;;;wBASP,YAAY;;;;;sCAKE,IAAA,sBAAY,EAAC,SAAS,CAAC;;;;;;;;;;;;;;;EAe3D,CAAA;AACF,CAAC,CAAA;AAhDY,QAAA,uBAAuB,2BAgDnC"}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.generateImportPrismaStatement = generateImportPrismaStatement;
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
8
|
-
function getImportGeneratorOptions(options) {
|
|
9
|
-
var _a, _b;
|
|
10
|
-
const clientGenerator = options.otherGenerators.find((gen) => gen.name === 'client');
|
|
11
|
-
if (!clientGenerator || !((_a = clientGenerator.output) === null || _a === void 0 ? void 0 : _a.value)) {
|
|
12
|
-
throw new Error('Prisma client generator not found.');
|
|
13
|
-
}
|
|
14
|
-
const modelDirPath = path_1.default.join((_b = options.generator.output) === null || _b === void 0 ? void 0 : _b.value, 'modelFolder');
|
|
15
|
-
const clientOutputPath = clientGenerator.output.value;
|
|
16
|
-
const relativeImportPath = path_1.default.relative(modelDirPath, clientOutputPath);
|
|
17
|
-
return {
|
|
18
|
-
outputPath: relativeImportPath.split(path_1.default.sep).join(path_1.default.posix.sep),
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
function generateImportPrismaStatement(generatorOptions) {
|
|
22
|
-
const options = getImportGeneratorOptions(generatorOptions);
|
|
23
|
-
return `import type { Prisma } from '${options.outputPath}';\nimport type { PrismaClient } from '${options.outputPath}';\n`;
|
|
24
|
-
}
|
|
25
|
-
//# sourceMappingURL=generateImportPrismaStatement.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generateImportPrismaStatement.js","sourceRoot":"","sources":["../../src/helpers/generateImportPrismaStatement.ts"],"names":[],"mappings":";;;;;AA+BA,sEAMC;AApCD,gDAAuB;AAMvB,SAAS,yBAAyB,CAChC,OAAyB;;IAEzB,MAAM,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC,IAAI,CAClD,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,QAAQ,CAC/B,CAAA;IAED,IAAI,CAAC,eAAe,IAAI,CAAC,CAAA,MAAA,eAAe,CAAC,MAAM,0CAAE,KAAK,CAAA,EAAE,CAAC;QACvD,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAA;IACvD,CAAC;IAED,MAAM,YAAY,GAAG,cAAI,CAAC,IAAI,CAC5B,MAAA,OAAO,CAAC,SAAS,CAAC,MAAM,0CAAE,KAAM,EAChC,aAAa,CACd,CAAA;IACD,MAAM,gBAAgB,GAAG,eAAe,CAAC,MAAM,CAAC,KAAK,CAAA;IAErD,MAAM,kBAAkB,GAAG,cAAI,CAAC,QAAQ,CAAC,YAAY,EAAE,gBAAgB,CAAC,CAAA;IAExE,OAAO;QACL,UAAU,EAAE,kBAAkB,CAAC,KAAK,CAAC,cAAI,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,cAAI,CAAC,KAAK,CAAC,GAAG,CAAC;KACpE,CAAA;AACH,CAAC;AAED,SAAgB,6BAA6B,CAC3C,gBAAkC;IAElC,MAAM,OAAO,GAAG,yBAAyB,CAAC,gBAAgB,CAAC,CAAA;IAE3D,OAAO,gCAAgC,OAAO,CAAC,UAAU,0CAA0C,OAAO,CAAC,UAAU,MAAM,CAAA;AAC7H,CAAC"}
|