prisma-generator-express 1.0.5 → 1.2.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 CHANGED
@@ -1,7 +1,8 @@
1
1
  # Prisma Generator Express
2
2
 
3
- [![npm version](https://badge.fury.io/js/prisma-generator-express.svg)](https://badge.fury.io/js/prisma-generator-express)
3
+ [![npm version](https://img.shields.io/npm/v/prisma-generator-express.svg)](https://www.npmjs.com/package/prisma-generator-express)
4
4
  [![npm](https://img.shields.io/npm/dt/prisma-generator-express.svg)](https://www.npmjs.com/package/prisma-generator-express)
5
+ [![npm](https://img.shields.io/npm/types/prisma-generator-express)](https://www.npmjs.com/package/prisma-generator-express)
5
6
  [![HitCount](https://hits.dwyl.com/multipliedtwice/prisma-generator-express.svg?style=flat)](http://hits.dwyl.com/multipliedtwice/prisma-generator-express)
6
7
  [![npm](https://img.shields.io/npm/l/prisma-generator-express.svg)](LICENSE)
7
8
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "prisma-generator-express",
3
3
  "description": "Prisma generator of Express CRUD API",
4
- "version": "1.0.5",
4
+ "version": "1.2.0",
5
5
  "main": "dist/generator.js",
6
6
  "license": "MIT",
7
7
  "bin": {
@@ -85,4 +85,4 @@
85
85
  ]
86
86
  ]
87
87
  }
88
- }
88
+ }
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.genEnum = void 0;
4
- const genEnum = ({ name, values }) => {
5
- const enumValues = values.map(({ name }) => `${name}="${name}"`).join(',\n');
6
- return `enum ${name} { \n${enumValues}\n }`;
7
- };
8
- exports.genEnum = genEnum;
9
- //# sourceMappingURL=genEnum.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"genEnum.js","sourceRoot":"","sources":["../../src/helpers/genEnum.ts"],"names":[],"mappings":";;;AAEO,MAAM,OAAO,GAAG,CAAC,EAAE,IAAI,EAAE,MAAM,EAAsB,EAAE,EAAE;IAC9D,MAAM,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,GAAG,IAAI,KAAK,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAE5E,OAAO,QAAQ,IAAI,QAAQ,UAAU,MAAM,CAAA;AAC7C,CAAC,CAAA;AAJY,QAAA,OAAO,WAInB"}
@@ -1,49 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateFindUniqueFunction = void 0;
4
- const generateFindUniqueFunction = (options) => {
5
- const { model, prismaImportStatement } = options;
6
- const modelName = model.name;
7
- const functionName = `${modelName}FindUnique`;
8
- const queryTypeName = `Prisma.${modelName}FindUniqueArgs`;
9
- return `
10
- ${prismaImportStatement}
11
- import { Request, Response, NextFunction } from 'express';
12
- import { ParsedQs } from 'qs';
13
- import { ZodTypeAny } from 'zod';
14
-
15
- interface PrismaRequest extends Request {
16
- prisma: PrismaClient;
17
- query: ${queryTypeName} & ParsedQs;
18
- outputValidation?: ZodTypeAny;
19
- omitOutputValidation?: boolean;
20
- }
21
-
22
- export async function ${functionName}(req: PrismaRequest, res: Response, next: NextFunction) {
23
- try {
24
- if (!req.outputValidation && !req.omitOutputValidation) {
25
- throw new Error('Output validation schema or omission flag must be provided.');
26
- }
27
-
28
- const data = await req.prisma.${modelName.toLowerCase()}.findUnique(req.query as ${queryTypeName});
29
- if (!req.omitOutputValidation && req.outputValidation) {
30
- const validationResult = req.outputValidation.safeParse(data);
31
- if (validationResult.success) {
32
- res.status(200).json(validationResult.data);
33
- } else {
34
- res.status(400).json({ error: 'Invalid data format', details: validationResult.error });
35
- }
36
- } else if (!req.omitOutputValidation) {
37
- throw new Error('Output validation schema must be provided unless explicitly omitted. Attach omitOutputValidation = true to request to suppress this error.');
38
- } else {
39
- res.status(200).json(data);
40
- }
41
- } catch (error) {
42
- console.error('Error in handling request:', error);
43
- res.status(500).json({ error: error.message });
44
- next(error);
45
- }
46
- }`;
47
- };
48
- exports.generateFindUniqueFunction = generateFindUniqueFunction;
49
- //# sourceMappingURL=generateFindUnique%20copy.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generateFindUnique copy.js","sourceRoot":"","sources":["../../src/helpers/generateFindUnique copy.ts"],"names":[],"mappings":";;;AAQO,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;;;;;;;WAOZ,aAAa;;;;;wBAKA,YAAY;;;;;;oCAMA,SAAS,CAAC,WAAW,EAAE,4BAA4B,aAAa;;;;;;;;;;;;;;;;;;EAkBlG,CAAA;AACF,CAAC,CAAA;AA/CY,QAAA,0BAA0B,8BA+CtC"}
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=generatePrismaImport.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generatePrismaImport.js","sourceRoot":"","sources":["../../src/helpers/generatePrismaImport.ts"],"names":[],"mappings":""}
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getGeneratorOptions = void 0;
4
- function getGeneratorOptions(options) {
5
- var _a;
6
- return {
7
- isCustomPrismaClientOutputPath: Boolean(options.generator.config.customOutputPath),
8
- outputPath: ((_a = options.generator.output) === null || _a === void 0 ? void 0 : _a.value) || './generated',
9
- prismaClientOutputPath: (options.generator.config.clientPath ||
10
- '@prisma/client'),
11
- };
12
- }
13
- exports.getGeneratorOptions = getGeneratorOptions;
14
- //# sourceMappingURL=getGeneratorOptions.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getGeneratorOptions.js","sourceRoot":"","sources":["../../src/utils/getGeneratorOptions.ts"],"names":[],"mappings":";;;AAGA,SAAgB,mBAAmB,CACjC,OAAyB;;IAEzB,OAAO;QACL,8BAA8B,EAAE,OAAO,CACrC,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,gBAAgB,CAC1C;QACD,UAAU,EAAE,CAAA,MAAA,OAAO,CAAC,SAAS,CAAC,MAAM,0CAAE,KAAK,KAAI,aAAa;QAC5D,sBAAsB,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,UAAU;YAC1D,gBAAgB,CAAW;KAC9B,CAAA;AACH,CAAC;AAXD,kDAWC"}