prisma-generator-express 1.16.1 → 1.16.3

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
@@ -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
- ## Rememo.io [Free Kanban & Chat](https://rememo.io)
288
+ #### Credits:
289
+ - Super Kick Gym - [Brazilian Jiu Jitsu in Bangkok](https://en.bjj-bangkok.com)
289
290
 
290
- <img src="https://github.com/multipliedtwice/prisma-generator-express/blob/feat/internal-validation/rememo-192.png?raw=true" alt="Free Kanban & Corporate Chat">
291
+ - Rememo - [Free Task Management and Corporate Chat](https://rememo.io)
@@ -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 } from '../createValidatorMiddleware'
24
+ import { createValidatorMiddleware, sanitizePrefix } from '../createValidatorMiddleware'
25
25
  import { RouteConfig, ValidatorConfig } from '../routeConfig'
26
26
  import { parseQueryParams } from "../parseQueryParams";
27
27
 
@@ -40,7 +40,8 @@ const defaultBeforeAfter = {
40
40
  */
41
41
  export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
42
42
  const router = express.Router();
43
- const basePath = (config.customUrlPrefix || '') + (config.addModelPrefix ? '/${modelName.toLowerCase()}' : '');
43
+ const basePath = sanitizePrefix(config.customUrlPrefix || '') +
44
+ sanitizePrefix(config.addModelPrefix !== false ? '/${modelName.toLowerCase()}' : '');
44
45
 
45
46
  const setupRoute = (
46
47
  path: string,
@@ -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,SAAS,uBAAuB,SAAS;WACzC,SAAS,mBAAmB,SAAS;WACrC,SAAS,qBAAqB,SAAS;;;;;;;;;;;;;qCAab,SAAS;;;;;kBAK5B,kBAAkB;;iFAE6C,SAAS,CAAC,WAAW,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0CA0C9D,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;AA/LD,wDA+LC"}
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,SAAS,uBAAuB,SAAS;WACzC,SAAS,mBAAmB,SAAS;WACrC,SAAS,qBAAqB,SAAS;;;;;;;;;;;;;qCAab,SAAS;;;;;kBAK5B,kBAAkB;;;uEAGmC,SAAS,CAAC,WAAW,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;0CA0CpD,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.1",
4
+ "version": "1.16.3",
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.15.0",
24
- "@prisma/generator-helper": "5.15.0",
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.2",
38
+ "@types/node": "20.14.9",
39
39
  "@types/prettier": "3.0.0",
40
40
  "jest": "29.7.0",
41
- "prisma": "5.15.0",
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"
@@ -30,7 +30,13 @@ export function createOutputValidatorMiddleware({
30
30
  const validationResult = schema.safeParse(data)
31
31
  if (!validationResult.success) {
32
32
  const errors = validationResult.error.errors
33
- return next({
33
+ next({
34
+ status: 400,
35
+ message: 'Output validation failed',
36
+ errors,
37
+ })
38
+
39
+ return res.status(400).json({
34
40
  status: 400,
35
41
  message: 'Output validation failed',
36
42
  errors,
@@ -53,3 +53,7 @@ export function createValidatorMiddleware({
53
53
  next()
54
54
  }
55
55
  }
56
+
57
+ export function sanitizePrefix(prefix: string): string {
58
+ return prefix.replace(/\/+$/, '')
59
+ }
@@ -10,8 +10,8 @@ export interface ValidatorConfig {
10
10
  interface MiddlewareConfig<M> {
11
11
  before?: M[]
12
12
  after?: RequestHandler[]
13
- inputValidatior?: ValidatorConfig
14
- outputValidatior?: ValidatorConfig
13
+ inputValidator?: ValidatorConfig
14
+ outputValidator?: ValidatorConfig
15
15
  }
16
16
 
17
17
  export interface RouteConfig<M> {
@@ -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 } from '../createValidatorMiddleware'
28
+ import { createValidatorMiddleware, sanitizePrefix } from '../createValidatorMiddleware'
29
29
  import { RouteConfig, ValidatorConfig } from '../routeConfig'
30
30
  import { parseQueryParams } from "../parseQueryParams";
31
31
 
@@ -44,7 +44,8 @@ const defaultBeforeAfter = {
44
44
  */
45
45
  export function ${routerFunctionName}(config: RouteConfig<RequestHandler>) {
46
46
  const router = express.Router();
47
- const basePath = (config.customUrlPrefix || '') + (config.addModelPrefix ? '/${modelName.toLowerCase()}' : '');
47
+ const basePath = sanitizePrefix(config.customUrlPrefix || '') +
48
+ sanitizePrefix(config.addModelPrefix !== false ? '/${modelName.toLowerCase()}' : '');
48
49
 
49
50
  const setupRoute = (
50
51
  path: string,