prisma-generator-express 1.16.3 → 1.16.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.
@@ -21,7 +21,7 @@ import { ${modelName}DeleteMany } from './${modelName}DeleteMany';
21
21
  import { ${modelName}Aggregate } from './${modelName}Aggregate';
22
22
  import { ${modelName}Count } from './${modelName}Count';
23
23
  import { ${modelName}GroupBy } from './${modelName}GroupBy';
24
- import { createValidatorMiddleware, sanitizePrefix } from '../createValidatorMiddleware'
24
+ import { createValidatorMiddleware, removeTrailingSlash } from '../createValidatorMiddleware'
25
25
  import { RouteConfig, ValidatorConfig } from '../routeConfig'
26
26
  import { parseQueryParams } from "../parseQueryParams";
27
27
 
@@ -40,8 +40,8 @@ const defaultBeforeAfter = {
40
40
  */
41
41
  export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
42
42
  const router = express.Router();
43
- const basePath = sanitizePrefix(config.customUrlPrefix || '') +
44
- sanitizePrefix(config.addModelPrefix !== false ? '/${modelName.toLowerCase()}' : '');
43
+ const basePath = removeTrailingSlash(config.customUrlPrefix || '') +
44
+ removeTrailingSlash(config.addModelPrefix !== false ? '/${modelName.toLowerCase()}' : '');
45
45
 
46
46
  const setupRoute = (
47
47
  path: string,
@@ -85,7 +85,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
85
85
  const { before = [], after = [], inputValidator, outputValidator } = config.findFirst || defaultBeforeAfter;
86
86
  setupRoute('/first', 'get', before, ${modelName}FindFirst as RequestHandler, inputValidator, outputValidator);
87
87
  if (after.length) {
88
- router.use(basePath + '/first', ...after);
88
+ router.use(removeTrailingSlash(basePath) + '/first', ...after);
89
89
  }
90
90
  }
91
91
 
@@ -93,7 +93,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
93
93
  const { before = [], after = [], inputValidator, outputValidator } = config.findMany || defaultBeforeAfter;
94
94
  setupRoute('/', 'get', before, ${modelName}FindMany as RequestHandler, inputValidator, outputValidator);
95
95
  if (after.length) {
96
- router.use(basePath + '/', ...after);
96
+ router.use(removeTrailingSlash(basePath + '/'), ...after);
97
97
  }
98
98
  }
99
99
 
@@ -101,7 +101,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
101
101
  const { before = [], after = [], inputValidator, outputValidator } = config.findUnique || defaultBeforeAfter;
102
102
  setupRoute('/:id', 'get', before, ${modelName}FindUnique as any, inputValidator, outputValidator);
103
103
  if (after.length) {
104
- router.use(basePath + '/:id', ...after);
104
+ router.use(removeTrailingSlash(basePath) + '/:id', ...after);
105
105
  }
106
106
  }
107
107
 
@@ -109,7 +109,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
109
109
  const { before = [], after = [], inputValidator, outputValidator } = config.create || defaultBeforeAfter;
110
110
  setupRoute('/', 'post', before, ${modelName}Create as RequestHandler, inputValidator, outputValidator);
111
111
  if (after.length) {
112
- router.use(basePath + '/', ...after);
112
+ router.use(removeTrailingSlash(basePath + '/'), ...after);
113
113
  }
114
114
  }
115
115
 
@@ -117,7 +117,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
117
117
  const { before = [], after = [], inputValidator, outputValidator } = config.createMany || defaultBeforeAfter;
118
118
  setupRoute('/many', 'post', before, ${modelName}CreateMany as RequestHandler, inputValidator, outputValidator);
119
119
  if (after.length) {
120
- router.use(basePath + '/many', ...after);
120
+ router.use(removeTrailingSlash(basePath) + '/many', ...after);
121
121
  }
122
122
  }
123
123
 
@@ -125,7 +125,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
125
125
  const { before = [], after = [], inputValidator, outputValidator } = config.update || defaultBeforeAfter;
126
126
  setupRoute('/', 'put', before, ${modelName}Update as RequestHandler, inputValidator, outputValidator);
127
127
  if (after.length) {
128
- router.use(basePath + '/', ...after);
128
+ router.use(removeTrailingSlash(basePath + '/'), ...after);
129
129
  }
130
130
  }
131
131
 
@@ -133,7 +133,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
133
133
  const { before = [], after = [], inputValidator, outputValidator } = config.updateMany || defaultBeforeAfter;
134
134
  setupRoute('/many', 'put', before, ${modelName}UpdateMany as RequestHandler, inputValidator, outputValidator);
135
135
  if (after.length) {
136
- router.use(basePath + '/many', ...after);
136
+ router.use(removeTrailingSlash(basePath) + '/many', ...after);
137
137
  }
138
138
  }
139
139
 
@@ -141,7 +141,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
141
141
  const { before = [], after = [], inputValidator, outputValidator } = config.upsert || defaultBeforeAfter;
142
142
  setupRoute('/', 'patch', before, ${modelName}Upsert as RequestHandler, inputValidator, outputValidator);
143
143
  if (after.length) {
144
- router.use(basePath + '/', ...after);
144
+ router.use(removeTrailingSlash(basePath + '/'), ...after);
145
145
  }
146
146
  }
147
147
 
@@ -149,7 +149,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
149
149
  const { before = [], after = [], inputValidator, outputValidator } = config.delete || defaultBeforeAfter;
150
150
  setupRoute('/', 'delete', before, ${modelName}Delete as RequestHandler, inputValidator, outputValidator);
151
151
  if (after.length) {
152
- router.use(basePath + '/', ...after);
152
+ router.use(removeTrailingSlash(basePath + '/'), ...after);
153
153
  }
154
154
  }
155
155
 
@@ -157,7 +157,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
157
157
  const { before = [], after = [], inputValidator, outputValidator } = config.deleteMany || defaultBeforeAfter;
158
158
  setupRoute('/many', 'delete', before, ${modelName}DeleteMany as RequestHandler, inputValidator, outputValidator);
159
159
  if (after.length) {
160
- router.use(basePath + '/many', ...after);
160
+ router.use(removeTrailingSlash(basePath) + '/many', ...after);
161
161
  }
162
162
  }
163
163
 
@@ -165,7 +165,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
165
165
  const { before = [], after = [], inputValidator, outputValidator } = config.aggregate || defaultBeforeAfter;
166
166
  setupRoute('/aggregate', 'get', before, ${modelName}Aggregate as RequestHandler, inputValidator, outputValidator);
167
167
  if (after.length) {
168
- router.use(basePath + '/aggregate', ...after);
168
+ router.use(removeTrailingSlash(basePath) + '/aggregate', ...after);
169
169
  }
170
170
  }
171
171
 
@@ -173,7 +173,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
173
173
  const { before = [], after = [], inputValidator, outputValidator } = config.count || defaultBeforeAfter;
174
174
  setupRoute('/count', 'get', before, ${modelName}Count as RequestHandler, inputValidator, outputValidator);
175
175
  if (after.length) {
176
- router.use(basePath + '/count', ...after);
176
+ router.use(removeTrailingSlash(basePath) + '/count', ...after);
177
177
  }
178
178
  }
179
179
 
@@ -181,7 +181,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
181
181
  const { before = [], after = [], inputValidator, outputValidator } = config.groupBy || defaultBeforeAfter;
182
182
  setupRoute('/groupby', 'get', before, ${modelName}GroupBy as RequestHandler, inputValidator, outputValidator);
183
183
  if (after.length) {
184
- router.use(basePath + '/groupby', ...after);
184
+ router.use(removeTrailingSlash(basePath) + '/groupby', ...after);
185
185
  }
186
186
  }
187
187
 
@@ -1 +1 @@
1
- {"version":3,"file":"generateRouteFile.js","sourceRoot":"","sources":["../../src/helpers/generateRouteFile.ts"],"names":[],"mappings":";;;AAEA,SAAgB,sBAAsB,CAAC,EACrC,KAAK,GAGN;IACC,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAA;IAC5B,MAAM,kBAAkB,GAAG,GAAG,SAAS,QAAQ,CAAA;IAE/C,OAAO;;;;WAIE,SAAS,uBAAuB,SAAS;WACzC,SAAS,sBAAsB,SAAS;WACxC,SAAS,wBAAwB,SAAS;WAC1C,SAAS,oBAAoB,SAAS;WACtC,SAAS,wBAAwB,SAAS;WAC1C,SAAS,oBAAoB,SAAS;WACtC,SAAS,wBAAwB,SAAS;WAC1C,SAAS,oBAAoB,SAAS;WACtC,SAAS,oBAAoB,SAAS;WACtC,SAAS,wBAAwB,SAAS;WAC1C,S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;;;;;;;;;;;;;;;;;;;;;;0CA0CzD,SAAS;;;;;;;;qCAQd,SAAS;;;;;;;;wCAQN,SAAS;;;;;;;;sCAQX,SAAS;;;;;;;;0CAQL,SAAS;;;;;;;;qCAQd,SAAS;;;;;;;;yCAQL,SAAS;;;;;;;;uCAQX,SAAS;;;;;;;;wCAQR,SAAS;;;;;;;;4CAQL,SAAS;;;;;;;;8CAQP,SAAS;;;;;;;;0CAQb,SAAS;;;;;;;;4CAQP,SAAS;;;;;;;;CAQpD,CAAA;AACD,CAAC;AAhMD,wDAgMC"}
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.3",
4
+ "version": "1.16.4",
5
5
  "main": "dist/generator.js",
6
6
  "license": "MIT",
7
7
  "bin": {
@@ -54,6 +54,9 @@ export function createValidatorMiddleware({
54
54
  }
55
55
  }
56
56
 
57
- export function sanitizePrefix(prefix: string): string {
58
- return prefix.replace(/\/+$/, '')
57
+ export function removeTrailingSlash(path: string): string {
58
+ if (path === '/') {
59
+ return path
60
+ }
61
+ return path.replace(/\/+$/, '')
59
62
  }
@@ -25,7 +25,7 @@ import { ${modelName}DeleteMany } from './${modelName}DeleteMany';
25
25
  import { ${modelName}Aggregate } from './${modelName}Aggregate';
26
26
  import { ${modelName}Count } from './${modelName}Count';
27
27
  import { ${modelName}GroupBy } from './${modelName}GroupBy';
28
- import { createValidatorMiddleware, sanitizePrefix } from '../createValidatorMiddleware'
28
+ import { createValidatorMiddleware, removeTrailingSlash } from '../createValidatorMiddleware'
29
29
  import { RouteConfig, ValidatorConfig } from '../routeConfig'
30
30
  import { parseQueryParams } from "../parseQueryParams";
31
31
 
@@ -44,8 +44,8 @@ const defaultBeforeAfter = {
44
44
  */
45
45
  export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
46
46
  const router = express.Router();
47
- const basePath = sanitizePrefix(config.customUrlPrefix || '') +
48
- sanitizePrefix(config.addModelPrefix !== false ? '/${modelName.toLowerCase()}' : '');
47
+ const basePath = removeTrailingSlash(config.customUrlPrefix || '') +
48
+ removeTrailingSlash(config.addModelPrefix !== false ? '/${modelName.toLowerCase()}' : '');
49
49
 
50
50
  const setupRoute = (
51
51
  path: string,
@@ -89,7 +89,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
89
89
  const { before = [], after = [], inputValidator, outputValidator } = config.findFirst || defaultBeforeAfter;
90
90
  setupRoute('/first', 'get', before, ${modelName}FindFirst as RequestHandler, inputValidator, outputValidator);
91
91
  if (after.length) {
92
- router.use(basePath + '/first', ...after);
92
+ router.use(removeTrailingSlash(basePath) + '/first', ...after);
93
93
  }
94
94
  }
95
95
 
@@ -97,7 +97,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
97
97
  const { before = [], after = [], inputValidator, outputValidator } = config.findMany || defaultBeforeAfter;
98
98
  setupRoute('/', 'get', before, ${modelName}FindMany as RequestHandler, inputValidator, outputValidator);
99
99
  if (after.length) {
100
- router.use(basePath + '/', ...after);
100
+ router.use(removeTrailingSlash(basePath + '/'), ...after);
101
101
  }
102
102
  }
103
103
 
@@ -105,7 +105,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
105
105
  const { before = [], after = [], inputValidator, outputValidator } = config.findUnique || defaultBeforeAfter;
106
106
  setupRoute('/:id', 'get', before, ${modelName}FindUnique as any, inputValidator, outputValidator);
107
107
  if (after.length) {
108
- router.use(basePath + '/:id', ...after);
108
+ router.use(removeTrailingSlash(basePath) + '/:id', ...after);
109
109
  }
110
110
  }
111
111
 
@@ -113,7 +113,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
113
113
  const { before = [], after = [], inputValidator, outputValidator } = config.create || defaultBeforeAfter;
114
114
  setupRoute('/', 'post', before, ${modelName}Create as RequestHandler, inputValidator, outputValidator);
115
115
  if (after.length) {
116
- router.use(basePath + '/', ...after);
116
+ router.use(removeTrailingSlash(basePath + '/'), ...after);
117
117
  }
118
118
  }
119
119
 
@@ -121,7 +121,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
121
121
  const { before = [], after = [], inputValidator, outputValidator } = config.createMany || defaultBeforeAfter;
122
122
  setupRoute('/many', 'post', before, ${modelName}CreateMany as RequestHandler, inputValidator, outputValidator);
123
123
  if (after.length) {
124
- router.use(basePath + '/many', ...after);
124
+ router.use(removeTrailingSlash(basePath) + '/many', ...after);
125
125
  }
126
126
  }
127
127
 
@@ -129,7 +129,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
129
129
  const { before = [], after = [], inputValidator, outputValidator } = config.update || defaultBeforeAfter;
130
130
  setupRoute('/', 'put', before, ${modelName}Update as RequestHandler, inputValidator, outputValidator);
131
131
  if (after.length) {
132
- router.use(basePath + '/', ...after);
132
+ router.use(removeTrailingSlash(basePath + '/'), ...after);
133
133
  }
134
134
  }
135
135
 
@@ -137,7 +137,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
137
137
  const { before = [], after = [], inputValidator, outputValidator } = config.updateMany || defaultBeforeAfter;
138
138
  setupRoute('/many', 'put', before, ${modelName}UpdateMany as RequestHandler, inputValidator, outputValidator);
139
139
  if (after.length) {
140
- router.use(basePath + '/many', ...after);
140
+ router.use(removeTrailingSlash(basePath) + '/many', ...after);
141
141
  }
142
142
  }
143
143
 
@@ -145,7 +145,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
145
145
  const { before = [], after = [], inputValidator, outputValidator } = config.upsert || defaultBeforeAfter;
146
146
  setupRoute('/', 'patch', before, ${modelName}Upsert as RequestHandler, inputValidator, outputValidator);
147
147
  if (after.length) {
148
- router.use(basePath + '/', ...after);
148
+ router.use(removeTrailingSlash(basePath + '/'), ...after);
149
149
  }
150
150
  }
151
151
 
@@ -153,7 +153,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
153
153
  const { before = [], after = [], inputValidator, outputValidator } = config.delete || defaultBeforeAfter;
154
154
  setupRoute('/', 'delete', before, ${modelName}Delete as RequestHandler, inputValidator, outputValidator);
155
155
  if (after.length) {
156
- router.use(basePath + '/', ...after);
156
+ router.use(removeTrailingSlash(basePath + '/'), ...after);
157
157
  }
158
158
  }
159
159
 
@@ -161,7 +161,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
161
161
  const { before = [], after = [], inputValidator, outputValidator } = config.deleteMany || defaultBeforeAfter;
162
162
  setupRoute('/many', 'delete', before, ${modelName}DeleteMany as RequestHandler, inputValidator, outputValidator);
163
163
  if (after.length) {
164
- router.use(basePath + '/many', ...after);
164
+ router.use(removeTrailingSlash(basePath) + '/many', ...after);
165
165
  }
166
166
  }
167
167
 
@@ -169,7 +169,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
169
169
  const { before = [], after = [], inputValidator, outputValidator } = config.aggregate || defaultBeforeAfter;
170
170
  setupRoute('/aggregate', 'get', before, ${modelName}Aggregate as RequestHandler, inputValidator, outputValidator);
171
171
  if (after.length) {
172
- router.use(basePath + '/aggregate', ...after);
172
+ router.use(removeTrailingSlash(basePath) + '/aggregate', ...after);
173
173
  }
174
174
  }
175
175
 
@@ -177,7 +177,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
177
177
  const { before = [], after = [], inputValidator, outputValidator } = config.count || defaultBeforeAfter;
178
178
  setupRoute('/count', 'get', before, ${modelName}Count as RequestHandler, inputValidator, outputValidator);
179
179
  if (after.length) {
180
- router.use(basePath + '/count', ...after);
180
+ router.use(removeTrailingSlash(basePath) + '/count', ...after);
181
181
  }
182
182
  }
183
183
 
@@ -185,7 +185,7 @@ export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
185
185
  const { before = [], after = [], inputValidator, outputValidator } = config.groupBy || defaultBeforeAfter;
186
186
  setupRoute('/groupby', 'get', before, ${modelName}GroupBy as RequestHandler, inputValidator, outputValidator);
187
187
  if (after.length) {
188
- router.use(basePath + '/groupby', ...after);
188
+ router.use(removeTrailingSlash(basePath) + '/groupby', ...after);
189
189
  }
190
190
  }
191
191