@increase21/simplenodejs 1.0.8 → 1.0.10

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/dist/router.js CHANGED
@@ -55,6 +55,8 @@ async function route(req, res, controllersDir) {
55
55
  return res.status(404).json({ error: "The requested resource does not exist" });
56
56
  const ControllerClass = meta.Controller;
57
57
  const controller = new ControllerClass();
58
+ //Update the method name to the framework pathen
59
+ methodName = (methodName || "").replace(/\-{1}\w{1}/g, match => match.replace("-", "").toUpperCase());
58
60
  //if the endpoint not a function
59
61
  if (typeof controller[methodName] !== "function") {
60
62
  //if it's using index
@@ -1,9 +1,5 @@
1
- import { HttpMethod, ObjectPayload, RequestObject, ResponseObject } from "../typings/general";
2
- type SubRequestHandler = Partial<Record<HttpMethod, (params: PrivateMethodProps) => any>>;
3
- interface PrivateMethodProps {
4
- id?: string;
5
- idMethod?: Partial<Record<HttpMethod, "required" | "optional">>;
6
- }
1
+ import { HttpMethod, ObjectPayload, RequestObject, ResponseObject, SimpleJsPrivateMethodProps } from "../typings/general";
2
+ type SubRequestHandler = Partial<Record<HttpMethod, (params: SimpleJsPrivateMethodProps) => any>>;
7
3
  export declare class SimpleNodeJsController {
8
4
  protected req: RequestObject;
9
5
  protected res: ResponseObject;
@@ -17,6 +13,6 @@ export declare class SimpleNodeJsController {
17
13
  res: ResponseObject;
18
14
  }): void;
19
15
  __checkContext(): void;
20
- protected RunRequest(handlers: SubRequestHandler, params?: PrivateMethodProps): any;
16
+ protected RunRequest(handlers: SubRequestHandler, params: SimpleJsPrivateMethodProps): any;
21
17
  }
22
18
  export {};
@@ -14,13 +14,11 @@ class SimpleNodeJsController {
14
14
  __checkContext() { }
15
15
  RunRequest(handlers, params) {
16
16
  const method = this.req.method?.toLowerCase();
17
- if (!method) {
17
+ if (!method)
18
18
  return this.res.status(400).json({ code: 400, error: "Invalid HTTP Method" });
19
- }
20
19
  const runFn = handlers[method];
21
- if (typeof runFn !== "function") {
20
+ if (typeof runFn !== "function")
22
21
  return this.res.status(405).json({ code: 405, error: "Method Not Allowed" });
23
- }
24
22
  // ID validation rules
25
23
  if (params && params.id && (!params.idMethod || !params.idMethod[method])) {
26
24
  return this.res.status(404).json({ code: 404, error: "Resource not found" });
@@ -28,11 +26,7 @@ class SimpleNodeJsController {
28
26
  if (params && params.idMethod?.[method] === "required" && !params.id) {
29
27
  return this.res.status(404).json({ code: 404, error: "Resource not found" });
30
28
  }
31
- return runFn({
32
- ...(params || {}),
33
- req: this.req,
34
- res: this.res,
35
- });
29
+ return runFn(params);
36
30
  }
37
31
  }
38
32
  exports.SimpleNodeJsController = SimpleNodeJsController;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@increase21/simplenodejs",
3
- "version": "1.0.8",
3
+ "version": "1.0.10",
4
4
  "description": "Lightweight Node.js HTTP framework with middleware and plugins",
5
5
  "dev": "dist/index.js",
6
6
  "bugs": "https://github.com/increase21/simplenodejs/issues",
@@ -22,7 +22,7 @@
22
22
  "dist"
23
23
  ],
24
24
  "scripts": {
25
- "build": "tsc",
25
+ "build": "tsc && npm publish",
26
26
  "test": "node dist/test.js",
27
27
  "dev": "nodemon server.ts"
28
28
  },