prisma-generator-express 1.0.2 → 1.0.4

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.
Files changed (50) hide show
  1. package/package.json +6 -2
  2. package/CHANGELOG.md +0 -6
  3. package/LICENSE +0 -21
  4. package/README.md +0 -179
  5. package/dist/bin.js.map +0 -1
  6. package/dist/constants.js +0 -5
  7. package/dist/constants.js.map +0 -1
  8. package/dist/generator.js.map +0 -1
  9. package/dist/helpers/genEnum.js +0 -9
  10. package/dist/helpers/genEnum.js.map +0 -1
  11. package/dist/helpers/generateAggregate.js +0 -50
  12. package/dist/helpers/generateAggregate.js.map +0 -1
  13. package/dist/helpers/generateCount.js +0 -50
  14. package/dist/helpers/generateCount.js.map +0 -1
  15. package/dist/helpers/generateCreate.js +0 -51
  16. package/dist/helpers/generateCreate.js.map +0 -1
  17. package/dist/helpers/generateCreateMany.js +0 -51
  18. package/dist/helpers/generateCreateMany.js.map +0 -1
  19. package/dist/helpers/generateDelete.js +0 -52
  20. package/dist/helpers/generateDelete.js.map +0 -1
  21. package/dist/helpers/generateDeleteMany.js +0 -50
  22. package/dist/helpers/generateDeleteMany.js.map +0 -1
  23. package/dist/helpers/generateFindFirst.js +0 -61
  24. package/dist/helpers/generateFindFirst.js.map +0 -1
  25. package/dist/helpers/generateFindMany.js +0 -61
  26. package/dist/helpers/generateFindMany.js.map +0 -1
  27. package/dist/helpers/generateFindUnique copy.js +0 -49
  28. package/dist/helpers/generateFindUnique copy.js.map +0 -1
  29. package/dist/helpers/generateFindUnique.js +0 -61
  30. package/dist/helpers/generateFindUnique.js.map +0 -1
  31. package/dist/helpers/generateGroupBy.js +0 -50
  32. package/dist/helpers/generateGroupBy.js.map +0 -1
  33. package/dist/helpers/generateImportPrismaStatement.js +0 -26
  34. package/dist/helpers/generateImportPrismaStatement.js.map +0 -1
  35. package/dist/helpers/generatePrismaImport.js +0 -2
  36. package/dist/helpers/generatePrismaImport.js.map +0 -1
  37. package/dist/helpers/generateRouteFile.js +0 -181
  38. package/dist/helpers/generateRouteFile.js.map +0 -1
  39. package/dist/helpers/generateUpdate.js +0 -55
  40. package/dist/helpers/generateUpdate.js.map +0 -1
  41. package/dist/helpers/generateUpdateMany.js +0 -52
  42. package/dist/helpers/generateUpdateMany.js.map +0 -1
  43. package/dist/helpers/generateUpsert.js +0 -52
  44. package/dist/helpers/generateUpsert.js.map +0 -1
  45. package/dist/utils/formatFile.js +0 -26
  46. package/dist/utils/formatFile.js.map +0 -1
  47. package/dist/utils/getGeneratorOptions.js +0 -14
  48. package/dist/utils/getGeneratorOptions.js.map +0 -1
  49. package/dist/utils/writeFileSafely.js +0 -21
  50. package/dist/utils/writeFileSafely.js.map +0 -1
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.2",
4
+ "version": "1.0.4",
5
5
  "main": "dist/generator.js",
6
6
  "license": "MIT",
7
7
  "bin": {
@@ -41,7 +41,7 @@
41
41
  "homepage": "https://github.com/multipliedtwice/prisma-generator-express/blob/master/README.md",
42
42
  "repository": {
43
43
  "type": "git",
44
- "url": "https://github.com/multipliedtwice/prisma-generator-express"
44
+ "url": "git+https://github.com/multipliedtwice/prisma-generator-express.git"
45
45
  },
46
46
  "author": "multipliedtwice",
47
47
  "keywords": [
@@ -50,6 +50,10 @@
50
50
  "crud",
51
51
  "generator"
52
52
  ],
53
+ "files": [
54
+ "../../../README.md",
55
+ "../../../LICENSE"
56
+ ],
53
57
  "release": {
54
58
  "branches": [
55
59
  "master"
package/CHANGELOG.md DELETED
@@ -1,6 +0,0 @@
1
- # 1.0.0 (2024-05-15)
2
-
3
-
4
- ### Bug Fixes
5
-
6
- * **generator:** update minimum required Node.js version to 20.0 in engines field ([1b4e7b2](https://github.com/multipliedtwice/prisma-generator-express/commit/1b4e7b2a8e29cc8a9710cc6393ada81b01631de3))
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2022 multipliedtwice
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
package/README.md DELETED
@@ -1,179 +0,0 @@
1
- # Prisma Generator Express
2
-
3
- [![npm version](https://badge.fury.io/js/prisma-generator-express.svg)](https://badge.fury.io/js/prisma-generator-express)
4
- [![npm](https://img.shields.io/npm/dt/prisma-generator-express.svg)](https://www.npmjs.com/package/prisma-generator-express)
5
- [![HitCount](https://hits.dwyl.com/multipliedtwice/prisma-generator-express.svg?style=flat)](http://hits.dwyl.com/multipliedtwice/prisma-generator-express)
6
- [![npm](https://img.shields.io/npm/l/prisma-generator-express.svg)](LICENSE)
7
-
8
- This tool helps you quickly create API endpoints in your Express app using your Prisma models.
9
-
10
- When you run `npx prisma generate`, it automatically creates two things:
11
-
12
- - Service functions that you can import into your Express routes. By default these functions handle CRUD operations and output validation. This behavior can be controlled.
13
- - Router generator function that lets you select which routes to add to the application and which middlewares to apply.
14
-
15
- ## Table of Contents
16
-
17
- - [Installation](#installation)
18
- - [Usage](#usage)
19
- - [Customizations](#customizations)
20
- - [Request Object Properties](#request-object-properties)
21
-
22
- # Installation
23
-
24
- Using npm:
25
-
26
- ```bash
27
- npm install prisma-generator-express
28
- ```
29
-
30
- Using yarn:
31
-
32
- ```bash
33
- yarn add prisma-generator-express
34
- ```
35
-
36
- # Basic usage
37
-
38
- - Include this generator in your schema.prisma file:
39
-
40
- ```prisma
41
- generator express {
42
- provider = "prisma-generator-express"
43
- }
44
- ```
45
-
46
- - Generate your middleware functions by running:
47
-
48
- ```bash
49
- npx prisma generate
50
- ```
51
-
52
- - Attach Prisma instance
53
-
54
- ```ts
55
- import { PrismaClient } from '@prisma/client'
56
- import express from 'express'
57
-
58
- const prisma = new PrismaClient()
59
- const app = express()
60
-
61
- app.use(express.json()) // for parsing application/json
62
-
63
- // Attach Prisma to every request
64
- app.use((req, res, next) => {
65
- req.prisma = prisma
66
- next()
67
- })
68
- ```
69
-
70
- - Here’s how you can use a generated function in your Express app:
71
-
72
- ```ts
73
- import { UserFindUnique } from './generated/UserFindUnique' // Adjust the path as necessary
74
- import { FindUniqueUserSchema } from './prisma-zod-generator/schemas/FindUniqueUser.schema' // Adjust the path as necessary
75
- import { FindUniqueUserSchemaOutput } from './prisma-zod-generator/schemas/FindUniqueUserOutput.schema' // Adjust the path as necessary
76
-
77
- // move this to /helpers
78
- export function validateQuery(schema: ZodSchema) {
79
- return async (req: Request, res: Response, next: NextFunction) => {
80
- try {
81
- req.query = schema.parse(req.query)
82
- next()
83
- } catch (error) {
84
- res.status(400).json({
85
- error: 'Input Validation failed',
86
- details: error.errors,
87
- })
88
- }
89
- }
90
- }
91
-
92
- app.get(
93
- '/user/:id',
94
- validateQuery(FindUniqueUserSchema),
95
- async (req, res, next) => {
96
- // Attach generated Zod schema for output validation
97
- req.outputValidation = FindUniqueUserOutput
98
-
99
- // Use the generated middleware to handle the request
100
- await UserFindUnique(req, res, next)
101
- },
102
- )
103
- ```
104
-
105
- The `UserFindUnique` function will fetch the user details from the database, validate the output with Zod, and handle the API response.
106
-
107
- # Router generator usage
108
-
109
- The library will create functions to generate routers per each model in schema. Each route can accept middleware that will be injected right before generated handler is invoked. You can use it to modify/remove/validate request payload. The output validation can be also attached to `req` object on this step.
110
-
111
- ```ts
112
- import express from 'express'
113
- import { UserRouter } from './path/to/generated/UserRouter' // Adjust the path as necessary
114
- import { UserFindManyArgs } from './prisma-zod-generator/schemas/UserFindManyArgs.schema' // Adjust the path as necessary
115
-
116
- const app = express()
117
-
118
- export const validateUserQuery = (
119
- req: Request,
120
- res: Response,
121
- next: NextFunction,
122
- ) => {
123
- try {
124
- UserFindManyArgs.parse(req.query)
125
- next()
126
- } catch (error) {
127
- if (error instanceof ZodError) {
128
- return res.status(400).json({
129
- message: 'Validation failed',
130
- errors: error.errors,
131
- })
132
- }
133
- next(error)
134
- }
135
- }
136
-
137
- const userRouterConfig = {
138
- findManyMiddleware: [validateUserQuery], // Add other middleware as needed
139
- findUniqueMiddleware: undefined, // This can be omitted, route won't be generated if middleware is not provided
140
- }
141
-
142
- // Use the router in your application
143
- app.use('/users', UserRouter(userRouterConfig))
144
-
145
- app.listen(3000, () => {
146
- console.log('Server is running on http://localhost:3000')
147
- })
148
- ```
149
-
150
- ## Request Object Properties
151
-
152
- The following properties can be attached to the `req` object to control the behavior of generated middleware:
153
-
154
- | Property | Type | Description |
155
- | ---------------------- | ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
156
- | `prisma` | PrismaClient | An instance of PrismaClient that allows the middleware to interact with your database. |
157
- | `passToNext` | boolean | Optional, if `true` - the result of a Prisma request will be passed to a next middleware as `req.locals.data` |
158
- | `query` | Object | A structured object that conforms to Prisma's API for the selected method. |
159
- | `outputValidation` | ZodTypeAny | (Optional) A Zod schema used to validate the data returned from the Prisma query before sending it to the client. This helps ensure the response adheres to expected data formats. |
160
- | `omitOutputValidation` | Boolean | (Optional) A flag that, if set to `true`, disables output validation even if a Zod schema is provided. |
161
-
162
- ## Roadmap
163
-
164
- | Function | Supported | Notes |
165
- | -------------- | ------------------ | ---------- |
166
- | `Model router` | :white_check_mark: | Available. |
167
- | `findUnique` | :white_check_mark: | Available. |
168
- | `findFirst` | :white_check_mark: | Available. |
169
- | `findMany` | :white_check_mark: | Available. |
170
- | `create` | :white_check_mark: | Available. |
171
- | `createMany` | :white_check_mark: | Available. |
172
- | `update` | :white_check_mark: | Available. |
173
- | `updateMany` | :white_check_mark: | Available. |
174
- | `upsert` | :white_check_mark: | Available. |
175
- | `delete` | :white_check_mark: | Available. |
176
- | `deleteMany` | :white_check_mark: | Available. |
177
- | `aggregate` | :white_check_mark: | Available. |
178
- | `count` | :white_check_mark: | Available. |
179
- | `groupBy` | :white_check_mark: | Available. |
package/dist/bin.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"bin.js","sourceRoot":"","sources":["../src/bin.ts"],"names":[],"mappings":";;;AACA,uBAAoB"}
package/dist/constants.js DELETED
@@ -1,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GENERATOR_NAME = void 0;
4
- exports.GENERATOR_NAME = 'prisma-generator-express';
5
- //# sourceMappingURL=constants.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,cAAc,GAAG,0BAA0B,CAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"generator.js","sourceRoot":"","sources":["../src/generator.ts"],"names":[],"mappings":";;AAAA,+DAA6E;AAC7E,qCAAoC;AACpC,2CAA4C;AAC5C,6DAAyD;AACzD,qEAAyE;AACzE,2FAAuF;AACvF,iEAAqE;AACrE,mEAAuE;AACvE,6DAAiE;AACjE,mEAAoE;AACpE,qEAAyE;AACzE,6DAAiE;AACjE,qEAAyE;AACzE,6DAAiE;AACjE,6DAAiE;AACjE,qEAAyE;AACzE,mEAAuE;AACvE,2DAA+D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AEF,MAAM,IAAA,iCAAe,EAAC;gBACpB,OAAO,EAAE,IAAA,qCAAqB,EAAC;oBAC7B,KAAK;oBACL,qBAAqB;iBACtB,CAAC;gBACF,OAAO;gBACP,KAAK;gBACL,SAAS,EAAE,OAAO;aACnB,CAAC,CAAA;YAEF,MAAM,IAAA,iCAAe,EAAC;gBACpB,OAAO,EAAE,IAAA,yCAAuB,EAAC;oBAC/B,KAAK;oBACL,qBAAqB;iBACtB,CAAC;gBACF,OAAO;gBACP,KAAK;gBACL,SAAS,EAAE,SAAS;aACrB,CAAC,CAAA;YAEF,MAAM,IAAA,iCAAe,EAAC;gBACpB,OAAO,EAAE,IAAA,0CAAsB,EAAC,EAAE,KAAK,EAAE,CAAC;gBAC1C,OAAO;gBACP,KAAK;gBACL,SAAS,EAAE,OAAO;aACnB,CAAC,CAAA;QACJ,CAAC,CAAC,CAAA;IACJ,CAAC;CACF,CAAC,CAAA"}
@@ -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,50 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateAggregateFunction = void 0;
4
- const generateAggregateFunction = (options) => {
5
- const { model, prismaImportStatement } = options;
6
- const modelName = model.name;
7
- const functionName = `${modelName}Aggregate`;
8
- const argsTypeName = `Prisma.${modelName}AggregateArgs`;
9
- return `
10
- ${prismaImportStatement}
11
- import { Request, Response, NextFunction } from 'express';
12
- import { RequestHandler, ParamsDictionary } from 'express-serve-static-core'
13
- import { ZodTypeAny } from 'zod';
14
-
15
- interface AggregateRequest extends Request {
16
- prisma: PrismaClient;
17
- body: ${argsTypeName};
18
- outputValidation?: ZodTypeAny;
19
- omitOutputValidation?: boolean;
20
- }
21
-
22
- export type AggregateMiddleware = RequestHandler<ParamsDictionary, any, ${argsTypeName}, Record<string, any>>;
23
-
24
- export async function ${functionName}(req: AggregateRequest, res: Response, next: NextFunction) {
25
- try {
26
- if (!req.outputValidation && !req.omitOutputValidation) {
27
- throw new Error('Output validation schema or omission flag must be provided.');
28
- }
29
-
30
- const result = await req.prisma.${modelName.toLowerCase()}.aggregate(req.body);
31
-
32
- if (!req.omitOutputValidation && req.outputValidation) {
33
- const validationResult = req.outputValidation.safeParse(result);
34
- if (validationResult.success) {
35
- res.status(200).json(validationResult.data);
36
- } else {
37
- res.status(400).json({ error: 'Invalid data format', details: validationResult.error });
38
- }
39
- } else {
40
- res.status(200).json(result);
41
- }
42
- } catch (error) {
43
- console.error('Error in handling aggregation request:', error);
44
- res.status(500).json({ error: error.message });
45
- next(error);
46
- }
47
- }`;
48
- };
49
- exports.generateAggregateFunction = generateAggregateFunction;
50
- //# sourceMappingURL=generateAggregate.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generateAggregate.js","sourceRoot":"","sources":["../../src/helpers/generateAggregate.ts"],"names":[],"mappings":";;;AASO,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,YAAY,GAAG,UAAU,SAAS,eAAe,CAAA;IAEvD,OAAO;EACP,qBAAqB;;;;;;;UAOb,YAAY;;;;;0EAKoD,YAAY;;wBAE9D,YAAY;;;;;;sCAME,SAAS,CAAC,WAAW,EAAE;;;;;;;;;;;;;;;;;EAiB3D,CAAA;AACF,CAAC,CAAA;AAhDY,QAAA,yBAAyB,6BAgDrC"}
@@ -1,50 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateCountFunction = void 0;
4
- const generateCountFunction = (options) => {
5
- const { model, prismaImportStatement } = options;
6
- const modelName = model.name;
7
- const functionName = `${modelName}Count`;
8
- const argsTypeName = `Prisma.${modelName}CountArgs`;
9
- return `
10
- ${prismaImportStatement}
11
- import { Request, Response, NextFunction } from 'express';
12
- import { RequestHandler, ParamsDictionary } from 'express-serve-static-core'
13
- import { ZodTypeAny } from 'zod';
14
-
15
- interface CountRequest extends Request {
16
- prisma: PrismaClient;
17
- body: ${argsTypeName};
18
- outputValidation?: ZodTypeAny;
19
- omitOutputValidation?: boolean;
20
- }
21
-
22
- export type CountMiddleware = RequestHandler<ParamsDictionary, any, ${argsTypeName}, Record<string, any>>;
23
-
24
- export async function ${functionName}(req: CountRequest, res: Response, next: NextFunction) {
25
- try {
26
- if (!req.outputValidation && !req.omitOutputValidation) {
27
- throw new Error('Output validation schema or omission flag must be provided.');
28
- }
29
-
30
- const result = await req.prisma.${modelName.toLowerCase()}.count(req.body);
31
-
32
- if (!req.omitOutputValidation && req.outputValidation) {
33
- const validationResult = req.outputValidation.safeParse(result);
34
- if (validationResult.success) {
35
- res.status(200).json(validationResult.data);
36
- } else {
37
- res.status(400).json({ error: 'Invalid data format', details: validationResult.error });
38
- }
39
- } else {
40
- res.status(200).json(result);
41
- }
42
- } catch (error) {
43
- console.error('Error in handling count request:', error);
44
- res.status(500).json({ error: error.message });
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":";;;AASO,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;;;;;;;UAOb,YAAY;;;;;sEAKgD,YAAY;;wBAE1D,YAAY;;;;;;sCAME,SAAS,CAAC,WAAW,EAAE;;;;;;;;;;;;;;;;;EAiB3D,CAAA;AACF,CAAC,CAAA;AAhDY,QAAA,qBAAqB,yBAgDjC"}
@@ -1,51 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateCreateFunction = void 0;
4
- const generateCreateFunction = (options) => {
5
- const { model, prismaImportStatement } = options;
6
- const modelName = model.name;
7
- const functionName = `${modelName}Create`;
8
- const argsTypeName = `Prisma.${modelName}CreateArgs`;
9
- return `
10
- ${prismaImportStatement}
11
- import { Request, Response, NextFunction } from 'express';
12
- import { RequestHandler, ParamsDictionary } from 'express-serve-static-core'
13
- import { ZodTypeAny } from 'zod';
14
-
15
- interface CreateRequest extends Request {
16
- prisma: PrismaClient;
17
- body: ${argsTypeName};
18
- outputValidation?: ZodTypeAny;
19
- omitOutputValidation?: boolean;
20
- }
21
-
22
- export type CreateMiddleware = RequestHandler<ParamsDictionary, any, ${argsTypeName}, Record<string, any>>
23
-
24
- export async function ${functionName}(req: CreateRequest, res: Response, next: NextFunction) {
25
- try {
26
- if (!req.outputValidation && !req.omitOutputValidation) {
27
- throw new Error('Output validation schema or omission flag must be provided.');
28
- }
29
-
30
- const data = await req.prisma.${modelName.toLowerCase()}.create(req.body);
31
- if (!req.omitOutputValidation && req.outputValidation) {
32
- const validationResult = req.outputValidation.safeParse(data);
33
- if (validationResult.success) {
34
- res.status(201).json(validationResult.data);
35
- } else {
36
- res.status(400).json({ error: 'Invalid data format', details: validationResult.error });
37
- }
38
- } else if (!req.omitOutputValidation) {
39
- throw new Error('Output validation schema must be provided unless explicitly omitted.');
40
- } else {
41
- res.status(201).json(data);
42
- }
43
- } catch (error) {
44
- console.error('Error in handling create request:', error);
45
- res.status(500).json({ error: error.message });
46
- next(error);
47
- }
48
- }`;
49
- };
50
- exports.generateCreateFunction = generateCreateFunction;
51
- //# sourceMappingURL=generateCreate.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generateCreate.js","sourceRoot":"","sources":["../../src/helpers/generateCreate.ts"],"names":[],"mappings":";;;AAQO,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;;;;;uEAKiD,YAAY;;wBAE3D,YAAY;;;;;;oCAMA,SAAS,CAAC,WAAW,EAAE;;;;;;;;;;;;;;;;;;EAkBzD,CAAA;AACF,CAAC,CAAA;AAjDY,QAAA,sBAAsB,0BAiDlC"}
@@ -1,51 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateCreateManyFunction = void 0;
4
- const generateCreateManyFunction = (options) => {
5
- const { model, prismaImportStatement } = options;
6
- const modelName = model.name;
7
- const functionName = `${modelName}CreateMany`;
8
- const argsTypeName = `Prisma.${modelName}CreateManyArgs`;
9
- return `
10
- ${prismaImportStatement}
11
- import { Request, Response, NextFunction } from 'express';
12
- import { RequestHandler, ParamsDictionary } from 'express-serve-static-core';
13
- import { ZodTypeAny } from 'zod';
14
-
15
- interface CreateManyRequest extends Request {
16
- prisma: PrismaClient;
17
- body: ${argsTypeName};
18
- outputValidation?: ZodTypeAny;
19
- omitOutputValidation?: boolean;
20
- }
21
-
22
- export type CreateManyMiddleware = RequestHandler<ParamsDictionary, any, ${argsTypeName}, Record<string, any>>
23
-
24
- export async function ${functionName}(req: CreateManyRequest, res: Response, next: NextFunction) {
25
- try {
26
- if (!req.outputValidation && !req.omitOutputValidation) {
27
- throw new Error('Output validation schema or omission flag must be provided.');
28
- }
29
-
30
- const data = await req.prisma.${modelName.toLowerCase()}.createMany(req.body);
31
- if (!req.omitOutputValidation && req.outputValidation) {
32
- const validationResult = req.outputValidation.safeParse(data);
33
- if (validationResult.success) {
34
- res.status(201).json(validationResult.data);
35
- } else {
36
- res.status(400).json({ error: 'Invalid data format', details: validationResult.error });
37
- }
38
- } else if (!req.omitOutputValidation) {
39
- throw new Error('Output validation schema must be provided unless explicitly omitted.');
40
- } else {
41
- res.status(201).json(data);
42
- }
43
- } catch (error) {
44
- console.error('Error in handling createMany request:', error);
45
- res.status(500).json({ error: error.message });
46
- next(error);
47
- }
48
- }`;
49
- };
50
- exports.generateCreateManyFunction = generateCreateManyFunction;
51
- //# sourceMappingURL=generateCreateMany.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generateCreateMany.js","sourceRoot":"","sources":["../../src/helpers/generateCreateMany.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,YAAY,GAAG,UAAU,SAAS,gBAAgB,CAAA;IAExD,OAAO;EACP,qBAAqB;;;;;;;UAOb,YAAY;;;;;2EAKqD,YAAY;;wBAE/D,YAAY;;;;;;oCAMA,SAAS,CAAC,WAAW,EAAE;;;;;;;;;;;;;;;;;;EAkBzD,CAAA;AACF,CAAC,CAAA;AAjDY,QAAA,0BAA0B,8BAiDtC"}
@@ -1,52 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateDeleteFunction = void 0;
4
- const generateDeleteFunction = (options) => {
5
- const { model, prismaImportStatement } = options;
6
- const modelName = model.name;
7
- const functionName = `${modelName}Delete`;
8
- const argsTypeName = `Prisma.${modelName}DeleteArgs`;
9
- return `
10
- ${prismaImportStatement}
11
- import { Request, Response, NextFunction } from 'express';
12
- import { RequestHandler, ParamsDictionary } from 'express-serve-static-core';
13
- import { ZodTypeAny } from 'zod';
14
-
15
- interface DeleteRequest extends Request {
16
- prisma: PrismaClient;
17
- body: ${argsTypeName};
18
- outputValidation?: ZodTypeAny;
19
- omitOutputValidation?: boolean;
20
- }
21
-
22
- export type DeleteMiddleware = RequestHandler<ParamsDictionary, any, ${argsTypeName}, Record<string, any>>
23
-
24
- export async function ${functionName}(req: DeleteRequest, res: Response, next: NextFunction) {
25
- try {
26
- if (!req.outputValidation && !req.omitOutputValidation) {
27
- throw new Error('Output validation schema or omission flag must be provided.');
28
- }
29
-
30
- const data = await req.prisma.${modelName.toLowerCase()}.delete(req.body);
31
-
32
- if (!req.omitOutputValidation && req.outputValidation) {
33
- const validationResult = req.outputValidation.safeParse(data);
34
- if (validationResult.success) {
35
- res.status(200).json(validationResult.data);
36
- } else {
37
- res.status(400).json({ error: 'Invalid data format', details: validationResult.error });
38
- }
39
- } else if (!req.omitOutputValidation) {
40
- throw new Error('Output validation schema must be provided unless explicitly omitted.');
41
- } else {
42
- res.status(200).json(data);
43
- }
44
- } catch (error) {
45
- console.error('Error in handling delete request:', error);
46
- res.status(500).json({ error: error.message });
47
- next(error);
48
- }
49
- }`;
50
- };
51
- exports.generateDeleteFunction = generateDeleteFunction;
52
- //# sourceMappingURL=generateDelete.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generateDelete.js","sourceRoot":"","sources":["../../src/helpers/generateDelete.ts"],"names":[],"mappings":";;;AASO,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;;;;;uEAKiD,YAAY;;wBAE3D,YAAY;;;;;;oCAMA,SAAS,CAAC,WAAW,EAAE;;;;;;;;;;;;;;;;;;;EAmBzD,CAAA;AACF,CAAC,CAAA;AAlDY,QAAA,sBAAsB,0BAkDlC"}
@@ -1,50 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateDeleteManyFunction = void 0;
4
- const generateDeleteManyFunction = (options) => {
5
- const { model, prismaImportStatement } = options;
6
- const modelName = model.name;
7
- const functionName = `${modelName}DeleteMany`;
8
- const argsTypeName = `Prisma.${modelName}DeleteManyArgs`;
9
- return `
10
- ${prismaImportStatement}
11
- import { Request, Response, NextFunction } from 'express';
12
- import { RequestHandler, ParamsDictionary } from 'express-serve-static-core';
13
- import { ZodTypeAny } from 'zod';
14
-
15
- interface DeleteManyRequest extends Request {
16
- prisma: PrismaClient;
17
- body: ${argsTypeName};
18
- outputValidation?: ZodTypeAny;
19
- omitOutputValidation?: boolean;
20
- }
21
-
22
- export type DeleteManyMiddleware = RequestHandler<ParamsDictionary, any, Prisma.${modelName}DeleteManyArgs, Record<string, any>>;
23
-
24
- export async function ${functionName}(req: DeleteManyRequest, res: Response, next: NextFunction) {
25
- try {
26
- if (!req.outputValidation && !req.omitOutputValidation) {
27
- throw new Error('Output validation schema or omission flag must be provided.');
28
- }
29
-
30
- const result = await req.prisma.${modelName.toLowerCase()}.deleteMany(req.body);
31
-
32
- if (!req.omitOutputValidation && req.outputValidation) {
33
- const validationResult = req.outputValidation.safeParse(result);
34
- if (validationResult.success) {
35
- res.status(200).json(validationResult.data);
36
- } else {
37
- res.status(400).json({ error: 'Invalid data format', details: validationResult.error });
38
- }
39
- } else {
40
- res.status(200).json(result);
41
- }
42
- } catch (error) {
43
- console.error('Error in handling batch delete request:', error);
44
- res.status(500).json({ error: error.message });
45
- next(error);
46
- }
47
- }`;
48
- };
49
- exports.generateDeleteManyFunction = generateDeleteManyFunction;
50
- //# sourceMappingURL=generateDeleteMany.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generateDeleteMany.js","sourceRoot":"","sources":["../../src/helpers/generateDeleteMany.ts"],"names":[],"mappings":";;;AASO,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;;;;;kFAK4D,SAAS;;wBAEnE,YAAY;;;;;;sCAME,SAAS,CAAC,WAAW,EAAE;;;;;;;;;;;;;;;;;EAiB3D,CAAA;AACF,CAAC,CAAA;AAhDY,QAAA,0BAA0B,8BAgDtC"}