prisma-generator-express 1.16.0 → 1.16.2
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 +4 -3
- package/dist/helpers/generateRouteFile.js +13 -13
- package/package.json +5 -5
- package/src/copy/routeConfig.ts +2 -2
- package/src/helpers/generateRouteFile.ts +13 -13
package/README.md
CHANGED
|
@@ -245,7 +245,7 @@ model UserAccount {
|
|
|
245
245
|
|
|
246
246
|
### createValidatorMiddleware(validatorOptions: ValidatorOptions)
|
|
247
247
|
|
|
248
|
-
Simple wrapper that internally uses `allow` or `forbid` logic for filtering incoming queries and data payloads
|
|
248
|
+
Simple wrapper that internally uses `allow` or `forbid` logic for filtering incoming queries and data payloads. Helps to make sure that schemas from `prisma-zod-generator` is not too permissive.
|
|
249
249
|
|
|
250
250
|
```ts
|
|
251
251
|
interface ValidatorOptions {
|
|
@@ -285,6 +285,7 @@ Same as `allow` but works in opposite way.
|
|
|
285
285
|
|
|
286
286
|
---
|
|
287
287
|
|
|
288
|
-
|
|
288
|
+
#### Credits:
|
|
289
|
+
- Super Kick Gym - [Brazilian Jiu Jitsu in Bangkok](https://en.bjj-bangkok.com)
|
|
289
290
|
|
|
290
|
-
|
|
291
|
+
- Rememo - [Free Task Management and Corporate Chat](https://rememo.io)
|
|
@@ -81,7 +81,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
|
|
|
81
81
|
|
|
82
82
|
|
|
83
83
|
if (config.enableAll || config?.findFirst) {
|
|
84
|
-
const { before = [], after = [], inputValidator, outputValidator
|
|
84
|
+
const { before = [], after = [], inputValidator, outputValidator } = config.findFirst || defaultBeforeAfter;
|
|
85
85
|
setupRoute('/first', 'get', before, ${modelName}FindFirst as RequestHandler, inputValidator, outputValidator);
|
|
86
86
|
if (after.length) {
|
|
87
87
|
router.use(basePath + '/first', ...after);
|
|
@@ -89,7 +89,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
|
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
if (config.enableAll || config?.findMany) {
|
|
92
|
-
const { before = [], after = [], inputValidator, outputValidator
|
|
92
|
+
const { before = [], after = [], inputValidator, outputValidator } = config.findMany || defaultBeforeAfter;
|
|
93
93
|
setupRoute('/', 'get', before, ${modelName}FindMany as RequestHandler, inputValidator, outputValidator);
|
|
94
94
|
if (after.length) {
|
|
95
95
|
router.use(basePath + '/', ...after);
|
|
@@ -97,7 +97,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
|
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
if (config.enableAll || config?.findUnique) {
|
|
100
|
-
const { before = [], after = [], inputValidator, outputValidator
|
|
100
|
+
const { before = [], after = [], inputValidator, outputValidator } = config.findUnique || defaultBeforeAfter;
|
|
101
101
|
setupRoute('/:id', 'get', before, ${modelName}FindUnique as any, inputValidator, outputValidator);
|
|
102
102
|
if (after.length) {
|
|
103
103
|
router.use(basePath + '/:id', ...after);
|
|
@@ -105,7 +105,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
|
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
if (config.enableAll || config?.create) {
|
|
108
|
-
const { before = [], after = [], inputValidator, outputValidator
|
|
108
|
+
const { before = [], after = [], inputValidator, outputValidator } = config.create || defaultBeforeAfter;
|
|
109
109
|
setupRoute('/', 'post', before, ${modelName}Create as RequestHandler, inputValidator, outputValidator);
|
|
110
110
|
if (after.length) {
|
|
111
111
|
router.use(basePath + '/', ...after);
|
|
@@ -113,7 +113,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
|
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
if (config.enableAll || config?.createMany) {
|
|
116
|
-
const { before = [], after = [], inputValidator, outputValidator
|
|
116
|
+
const { before = [], after = [], inputValidator, outputValidator } = config.createMany || defaultBeforeAfter;
|
|
117
117
|
setupRoute('/many', 'post', before, ${modelName}CreateMany as RequestHandler, inputValidator, outputValidator);
|
|
118
118
|
if (after.length) {
|
|
119
119
|
router.use(basePath + '/many', ...after);
|
|
@@ -121,7 +121,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
|
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
if (config.enableAll || config?.update) {
|
|
124
|
-
const { before = [], after = [], inputValidator, outputValidator
|
|
124
|
+
const { before = [], after = [], inputValidator, outputValidator } = config.update || defaultBeforeAfter;
|
|
125
125
|
setupRoute('/', 'put', before, ${modelName}Update as RequestHandler, inputValidator, outputValidator);
|
|
126
126
|
if (after.length) {
|
|
127
127
|
router.use(basePath + '/', ...after);
|
|
@@ -129,7 +129,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
|
|
|
129
129
|
}
|
|
130
130
|
|
|
131
131
|
if (config.enableAll || config?.updateMany) {
|
|
132
|
-
const { before = [], after = [], inputValidator, outputValidator
|
|
132
|
+
const { before = [], after = [], inputValidator, outputValidator } = config.updateMany || defaultBeforeAfter;
|
|
133
133
|
setupRoute('/many', 'put', before, ${modelName}UpdateMany as RequestHandler, inputValidator, outputValidator);
|
|
134
134
|
if (after.length) {
|
|
135
135
|
router.use(basePath + '/many', ...after);
|
|
@@ -137,7 +137,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
|
|
|
137
137
|
}
|
|
138
138
|
|
|
139
139
|
if (config.enableAll || config?.upsert) {
|
|
140
|
-
const { before = [], after = [], inputValidator, outputValidator
|
|
140
|
+
const { before = [], after = [], inputValidator, outputValidator } = config.upsert || defaultBeforeAfter;
|
|
141
141
|
setupRoute('/', 'patch', before, ${modelName}Upsert as RequestHandler, inputValidator, outputValidator);
|
|
142
142
|
if (after.length) {
|
|
143
143
|
router.use(basePath + '/', ...after);
|
|
@@ -145,7 +145,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
|
|
|
145
145
|
}
|
|
146
146
|
|
|
147
147
|
if (config.enableAll || config?.delete) {
|
|
148
|
-
const { before = [], after = [], inputValidator, outputValidator
|
|
148
|
+
const { before = [], after = [], inputValidator, outputValidator } = config.delete || defaultBeforeAfter;
|
|
149
149
|
setupRoute('/', 'delete', before, ${modelName}Delete as RequestHandler, inputValidator, outputValidator);
|
|
150
150
|
if (after.length) {
|
|
151
151
|
router.use(basePath + '/', ...after);
|
|
@@ -153,7 +153,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
|
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
if (config.enableAll || config?.deleteMany) {
|
|
156
|
-
const { before = [], after = [], inputValidator, outputValidator
|
|
156
|
+
const { before = [], after = [], inputValidator, outputValidator } = config.deleteMany || defaultBeforeAfter;
|
|
157
157
|
setupRoute('/many', 'delete', before, ${modelName}DeleteMany as RequestHandler, inputValidator, outputValidator);
|
|
158
158
|
if (after.length) {
|
|
159
159
|
router.use(basePath + '/many', ...after);
|
|
@@ -161,7 +161,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
|
|
|
161
161
|
}
|
|
162
162
|
|
|
163
163
|
if (config.enableAll || config?.aggregate) {
|
|
164
|
-
const { before = [], after = [], inputValidator, outputValidator
|
|
164
|
+
const { before = [], after = [], inputValidator, outputValidator } = config.aggregate || defaultBeforeAfter;
|
|
165
165
|
setupRoute('/aggregate', 'get', before, ${modelName}Aggregate as RequestHandler, inputValidator, outputValidator);
|
|
166
166
|
if (after.length) {
|
|
167
167
|
router.use(basePath + '/aggregate', ...after);
|
|
@@ -169,7 +169,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
|
|
|
169
169
|
}
|
|
170
170
|
|
|
171
171
|
if (config.enableAll || config?.count) {
|
|
172
|
-
const { before = [], after = [], inputValidator, outputValidator
|
|
172
|
+
const { before = [], after = [], inputValidator, outputValidator } = config.count || defaultBeforeAfter;
|
|
173
173
|
setupRoute('/count', 'get', before, ${modelName}Count as RequestHandler, inputValidator, outputValidator);
|
|
174
174
|
if (after.length) {
|
|
175
175
|
router.use(basePath + '/count', ...after);
|
|
@@ -177,7 +177,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
|
|
|
177
177
|
}
|
|
178
178
|
|
|
179
179
|
if (config.enableAll || config?.groupBy) {
|
|
180
|
-
const { before = [], after = [], inputValidator, outputValidator
|
|
180
|
+
const { before = [], after = [], inputValidator, outputValidator } = config.groupBy || defaultBeforeAfter;
|
|
181
181
|
setupRoute('/groupby', 'get', before, ${modelName}GroupBy as RequestHandler, inputValidator, outputValidator);
|
|
182
182
|
if (after.length) {
|
|
183
183
|
router.use(basePath + '/groupby', ...after);
|
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.16.
|
|
4
|
+
"version": "1.16.2",
|
|
5
5
|
"main": "dist/generator.js",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"bin": {
|
|
@@ -20,8 +20,8 @@
|
|
|
20
20
|
"prepublishOnly": "node copy.js "
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@prisma/client": "5.
|
|
24
|
-
"@prisma/generator-helper": "5.
|
|
23
|
+
"@prisma/client": "5.16.1",
|
|
24
|
+
"@prisma/generator-helper": "5.16.1",
|
|
25
25
|
"@prisma/sdk": "4.0.0",
|
|
26
26
|
"express": "^4.19.2",
|
|
27
27
|
"lodash": "^4.17.21",
|
|
@@ -35,10 +35,10 @@
|
|
|
35
35
|
"@types/express": "^4.17.21",
|
|
36
36
|
"@types/jest": "29.5.12",
|
|
37
37
|
"@types/lodash": "^4.17.4",
|
|
38
|
-
"@types/node": "20.14.
|
|
38
|
+
"@types/node": "20.14.9",
|
|
39
39
|
"@types/prettier": "3.0.0",
|
|
40
40
|
"jest": "29.7.0",
|
|
41
|
-
"prisma": "5.
|
|
41
|
+
"prisma": "5.16.1",
|
|
42
42
|
"semantic-release": "^24.0.0",
|
|
43
43
|
"ts-jest": "29.1.4",
|
|
44
44
|
"typescript": "5.4.5"
|
package/src/copy/routeConfig.ts
CHANGED
|
@@ -10,8 +10,8 @@ export interface ValidatorConfig {
|
|
|
10
10
|
interface MiddlewareConfig<M> {
|
|
11
11
|
before?: M[]
|
|
12
12
|
after?: RequestHandler[]
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
inputValidator?: ValidatorConfig
|
|
14
|
+
outputValidator?: ValidatorConfig
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export interface RouteConfig<M> {
|
|
@@ -85,7 +85,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
|
|
|
85
85
|
|
|
86
86
|
|
|
87
87
|
if (config.enableAll || config?.findFirst) {
|
|
88
|
-
const { before = [], after = [], inputValidator, outputValidator
|
|
88
|
+
const { before = [], after = [], inputValidator, outputValidator } = config.findFirst || defaultBeforeAfter;
|
|
89
89
|
setupRoute('/first', 'get', before, ${modelName}FindFirst as RequestHandler, inputValidator, outputValidator);
|
|
90
90
|
if (after.length) {
|
|
91
91
|
router.use(basePath + '/first', ...after);
|
|
@@ -93,7 +93,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
|
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
if (config.enableAll || config?.findMany) {
|
|
96
|
-
const { before = [], after = [], inputValidator, outputValidator
|
|
96
|
+
const { before = [], after = [], inputValidator, outputValidator } = config.findMany || defaultBeforeAfter;
|
|
97
97
|
setupRoute('/', 'get', before, ${modelName}FindMany as RequestHandler, inputValidator, outputValidator);
|
|
98
98
|
if (after.length) {
|
|
99
99
|
router.use(basePath + '/', ...after);
|
|
@@ -101,7 +101,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
|
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
if (config.enableAll || config?.findUnique) {
|
|
104
|
-
const { before = [], after = [], inputValidator, outputValidator
|
|
104
|
+
const { before = [], after = [], inputValidator, outputValidator } = config.findUnique || defaultBeforeAfter;
|
|
105
105
|
setupRoute('/:id', 'get', before, ${modelName}FindUnique as any, inputValidator, outputValidator);
|
|
106
106
|
if (after.length) {
|
|
107
107
|
router.use(basePath + '/:id', ...after);
|
|
@@ -109,7 +109,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
|
|
|
109
109
|
}
|
|
110
110
|
|
|
111
111
|
if (config.enableAll || config?.create) {
|
|
112
|
-
const { before = [], after = [], inputValidator, outputValidator
|
|
112
|
+
const { before = [], after = [], inputValidator, outputValidator } = config.create || defaultBeforeAfter;
|
|
113
113
|
setupRoute('/', 'post', before, ${modelName}Create as RequestHandler, inputValidator, outputValidator);
|
|
114
114
|
if (after.length) {
|
|
115
115
|
router.use(basePath + '/', ...after);
|
|
@@ -117,7 +117,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
|
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
if (config.enableAll || config?.createMany) {
|
|
120
|
-
const { before = [], after = [], inputValidator, outputValidator
|
|
120
|
+
const { before = [], after = [], inputValidator, outputValidator } = config.createMany || defaultBeforeAfter;
|
|
121
121
|
setupRoute('/many', 'post', before, ${modelName}CreateMany as RequestHandler, inputValidator, outputValidator);
|
|
122
122
|
if (after.length) {
|
|
123
123
|
router.use(basePath + '/many', ...after);
|
|
@@ -125,7 +125,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
|
|
|
125
125
|
}
|
|
126
126
|
|
|
127
127
|
if (config.enableAll || config?.update) {
|
|
128
|
-
const { before = [], after = [], inputValidator, outputValidator
|
|
128
|
+
const { before = [], after = [], inputValidator, outputValidator } = config.update || defaultBeforeAfter;
|
|
129
129
|
setupRoute('/', 'put', before, ${modelName}Update as RequestHandler, inputValidator, outputValidator);
|
|
130
130
|
if (after.length) {
|
|
131
131
|
router.use(basePath + '/', ...after);
|
|
@@ -133,7 +133,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
|
|
|
133
133
|
}
|
|
134
134
|
|
|
135
135
|
if (config.enableAll || config?.updateMany) {
|
|
136
|
-
const { before = [], after = [], inputValidator, outputValidator
|
|
136
|
+
const { before = [], after = [], inputValidator, outputValidator } = config.updateMany || defaultBeforeAfter;
|
|
137
137
|
setupRoute('/many', 'put', before, ${modelName}UpdateMany as RequestHandler, inputValidator, outputValidator);
|
|
138
138
|
if (after.length) {
|
|
139
139
|
router.use(basePath + '/many', ...after);
|
|
@@ -141,7 +141,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
|
|
|
141
141
|
}
|
|
142
142
|
|
|
143
143
|
if (config.enableAll || config?.upsert) {
|
|
144
|
-
const { before = [], after = [], inputValidator, outputValidator
|
|
144
|
+
const { before = [], after = [], inputValidator, outputValidator } = config.upsert || defaultBeforeAfter;
|
|
145
145
|
setupRoute('/', 'patch', before, ${modelName}Upsert as RequestHandler, inputValidator, outputValidator);
|
|
146
146
|
if (after.length) {
|
|
147
147
|
router.use(basePath + '/', ...after);
|
|
@@ -149,7 +149,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
|
|
|
149
149
|
}
|
|
150
150
|
|
|
151
151
|
if (config.enableAll || config?.delete) {
|
|
152
|
-
const { before = [], after = [], inputValidator, outputValidator
|
|
152
|
+
const { before = [], after = [], inputValidator, outputValidator } = config.delete || defaultBeforeAfter;
|
|
153
153
|
setupRoute('/', 'delete', before, ${modelName}Delete as RequestHandler, inputValidator, outputValidator);
|
|
154
154
|
if (after.length) {
|
|
155
155
|
router.use(basePath + '/', ...after);
|
|
@@ -157,7 +157,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
|
|
|
157
157
|
}
|
|
158
158
|
|
|
159
159
|
if (config.enableAll || config?.deleteMany) {
|
|
160
|
-
const { before = [], after = [], inputValidator, outputValidator
|
|
160
|
+
const { before = [], after = [], inputValidator, outputValidator } = config.deleteMany || defaultBeforeAfter;
|
|
161
161
|
setupRoute('/many', 'delete', before, ${modelName}DeleteMany as RequestHandler, inputValidator, outputValidator);
|
|
162
162
|
if (after.length) {
|
|
163
163
|
router.use(basePath + '/many', ...after);
|
|
@@ -165,7 +165,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
|
|
|
165
165
|
}
|
|
166
166
|
|
|
167
167
|
if (config.enableAll || config?.aggregate) {
|
|
168
|
-
const { before = [], after = [], inputValidator, outputValidator
|
|
168
|
+
const { before = [], after = [], inputValidator, outputValidator } = config.aggregate || defaultBeforeAfter;
|
|
169
169
|
setupRoute('/aggregate', 'get', before, ${modelName}Aggregate as RequestHandler, inputValidator, outputValidator);
|
|
170
170
|
if (after.length) {
|
|
171
171
|
router.use(basePath + '/aggregate', ...after);
|
|
@@ -173,7 +173,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
|
|
|
173
173
|
}
|
|
174
174
|
|
|
175
175
|
if (config.enableAll || config?.count) {
|
|
176
|
-
const { before = [], after = [], inputValidator, outputValidator
|
|
176
|
+
const { before = [], after = [], inputValidator, outputValidator } = config.count || defaultBeforeAfter;
|
|
177
177
|
setupRoute('/count', 'get', before, ${modelName}Count as RequestHandler, inputValidator, outputValidator);
|
|
178
178
|
if (after.length) {
|
|
179
179
|
router.use(basePath + '/count', ...after);
|
|
@@ -181,7 +181,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
|
|
|
181
181
|
}
|
|
182
182
|
|
|
183
183
|
if (config.enableAll || config?.groupBy) {
|
|
184
|
-
const { before = [], after = [], inputValidator, outputValidator
|
|
184
|
+
const { before = [], after = [], inputValidator, outputValidator } = config.groupBy || defaultBeforeAfter;
|
|
185
185
|
setupRoute('/groupby', 'get', before, ${modelName}GroupBy as RequestHandler, inputValidator, outputValidator);
|
|
186
186
|
if (after.length) {
|
|
187
187
|
router.use(basePath + '/groupby', ...after);
|