jh-be-tools 1.0.0 → 1.0.1

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/package.json CHANGED
@@ -1,11 +1,12 @@
1
1
  {
2
2
  "name": "jh-be-tools",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "",
5
5
  "main": "index.js",
6
+ "types": "index.d.ts",
6
7
  "scripts": {
7
- "build": "npx tsc --build",
8
- "test": "echo \"Error: no test specified\" && exit 1"
8
+ "build": "npx tsc --build && cp package.json dist/.",
9
+ "test": "echo \"Error: no test\" && exit 1"
9
10
  },
10
11
  "author": "",
11
12
  "license": "ISC",
@@ -17,8 +18,5 @@
17
18
  "dependencies": {
18
19
  "express": "^4.18.2",
19
20
  "zod": "^3.22.4"
20
- },
21
- "files": [
22
- "dist/*"
23
- ]
21
+ }
24
22
  }
@@ -4,9 +4,9 @@ export interface RouteSchema {
4
4
  request?: z.ZodSchema;
5
5
  response?: z.ZodSchema;
6
6
  }
7
- interface ReturnValue {
8
- data: unknown;
7
+ interface ReturnValue<T> {
8
+ data: T;
9
9
  status?: number;
10
10
  }
11
- export declare const RouteHandler: (req: Request, res: Response, fun: (req: Request) => Promise<ReturnValue>, schema: RouteSchema) => Promise<Response<any, Record<string, any>> | undefined>;
11
+ export declare const RouteHandler: (req: Request, res: Response, fun: (req?: any) => Promise<ReturnValue<unknown>>, schema: RouteSchema) => Promise<Response<any, Record<string, any>> | undefined>;
12
12
  export {};
@@ -26,12 +26,12 @@ const RouteHandler = async (req, res, fun, schema) => {
26
26
  }
27
27
  if (schema.response) {
28
28
  try {
29
- await schema.response.parseAsync(data);
29
+ await schema.response.parseAsync({ data });
30
30
  }
31
31
  catch (error) {
32
- return res.status(400).json(error);
32
+ return res.status(500).json(error);
33
33
  }
34
34
  }
35
- res.status(status).json(data);
35
+ res.status(status).json({ data });
36
36
  };
37
37
  exports.RouteHandler = RouteHandler;
File without changes
File without changes