gg-express 1.0.41 → 1.0.44

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.
@@ -64,19 +64,19 @@ export default class GGExpress {
64
64
  private outputPath;
65
65
  constructor(app: Express.Express, outputPath: string[]);
66
66
  private rootMethod;
67
- get<M extends requireParamsStructure, T extends M["structure"], K extends keyof T, R extends responseStructure, RS extends R["structure"], KR extends keyof RS, P extends M["parameter"], PP extends R["parameter"], J extends M["isPartialStructure"]>(url: `/api/${string}`, options: {
67
+ get<M extends requireParamsStructure, T extends M["structure"], K extends keyof T, R extends responseStructure, RS extends R["structure"], KR extends keyof RS, P extends M["parameter"], PP extends R["parameter"], J extends M["isPartialStructure"]>(url: `/api/gg/${string}`, options: {
68
68
  requireParams: M;
69
69
  responseStructure: R;
70
70
  }, ...middlewares: Array<(req: MyRequest<M["dataType"], T, K, P, J>, res: MyResponse<R["dataType"], RS, KR, PP, J>, next: NextFunction) => any>): Express.Express;
71
- post<M extends requireParamsStructure, T extends M["structure"], K extends keyof T, R extends responseStructure, RS extends R["structure"], KR extends keyof RS, P extends M["parameter"], PP extends R["parameter"], J extends M["isPartialStructure"]>(url: `/api/${string}`, options: {
71
+ post<M extends requireParamsStructure, T extends M["structure"], K extends keyof T, R extends responseStructure, RS extends R["structure"], KR extends keyof RS, P extends M["parameter"], PP extends R["parameter"], J extends M["isPartialStructure"]>(url: `/api/gg/${string}`, options: {
72
72
  requireParams: M;
73
73
  responseStructure: R;
74
74
  }, ...middlewares: Array<(req: MyRequest<M["dataType"], T, K, P, J>, res: MyResponse<R["dataType"], RS, KR, PP, J>, next: NextFunction) => any>): Express.Express;
75
- put<M extends requireParamsStructure, T extends M["structure"], K extends keyof T, R extends responseStructure, RS extends R["structure"], KR extends keyof RS, P extends M["parameter"], PP extends R["parameter"], J extends M["isPartialStructure"]>(url: `/api/${string}`, options: {
75
+ put<M extends requireParamsStructure, T extends M["structure"], K extends keyof T, R extends responseStructure, RS extends R["structure"], KR extends keyof RS, P extends M["parameter"], PP extends R["parameter"], J extends M["isPartialStructure"]>(url: `/api/gg/${string}`, options: {
76
76
  requireParams: M;
77
77
  responseStructure: R;
78
78
  }, ...middlewares: Array<(req: MyRequest<M["dataType"], T, K, P, J>, res: MyResponse<R["dataType"], RS, KR, PP, J>, next: NextFunction) => any>): Express.Express;
79
- delete<M extends requireParamsStructure, T extends M["structure"], K extends keyof T, R extends responseStructure, RS extends R["structure"], KR extends keyof RS, P extends M["parameter"], PP extends R["parameter"], J extends M["isPartialStructure"]>(url: `/api/${string}`, options: {
79
+ delete<M extends requireParamsStructure, T extends M["structure"], K extends keyof T, R extends responseStructure, RS extends R["structure"], KR extends keyof RS, P extends M["parameter"], PP extends R["parameter"], J extends M["isPartialStructure"]>(url: `/api/gg/${string}`, options: {
80
80
  requireParams: M;
81
81
  responseStructure: R;
82
82
  }, ...middlewares: Array<(req: MyRequest<M["dataType"], T, K, P, J>, res: MyResponse<R["dataType"], RS, KR, PP, J>, next: NextFunction) => any>): Express.Express;
package/dist/test.js CHANGED
@@ -8,7 +8,7 @@ const express_1 = __importDefault(require("express"));
8
8
  function run() {
9
9
  const app = (0, express_1.default)();
10
10
  const ggapp = new GGExpress_1.default(app, ["./"]);
11
- ggapp.get("/api/users/id", {
11
+ ggapp.get("/api/gg/users/id", {
12
12
  requireParams: {
13
13
  parameter: {},
14
14
  dataType: "arrayObject",
@@ -35,7 +35,7 @@ function run() {
35
35
  },
36
36
  });
37
37
  });
38
- ggapp.post("/api/item", {
38
+ ggapp.post("/api/gg/item", {
39
39
  requireParams: {
40
40
  parameter: {
41
41
  lotNumber: "number",
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "gg-express",
3
- "version": "1.0.41",
3
+ "version": "1.0.44",
4
4
  "description": "",
5
5
  "main": "dist/GGExpress.js",
6
6
  "scripts": {
7
7
  "build": "npm version patch && tsc",
8
8
  "test": "echo \"Error: no test specified\" && exit 1"
9
9
  },
10
- "author": "",
10
+ "author": "goomgum",
11
11
  "license": "ISC",
12
12
  "dependencies": {
13
13
  "@types/axios": "^0.14.0",
@@ -20,5 +20,15 @@
20
20
  },
21
21
  "devDependencies": {
22
22
  "@types/express": "^5.0.0"
23
- }
23
+ },
24
+ "keywords": [
25
+ "express",
26
+ "typescript",
27
+ "api",
28
+ "wrapper",
29
+ "type-safe",
30
+ "backend",
31
+ "frontend",
32
+ "api-connector"
33
+ ]
24
34
  }
package/readme.md CHANGED
@@ -1,39 +1,37 @@
1
- # GG-Express
1
+ # 🚀 GG-Express
2
2
 
3
3
  **GG-Express** is an Express.js wrapper that enforces strong type requirements for `GET`, `POST`, `PUT`, and `DELETE` methods. It ensures that `req.query` and `req.body` follow strict structure definitions and automatically generates an `apiConnector` class file for easy use in front-end development.
4
4
 
5
- ## Features
5
+ ## Features
6
6
 
7
- - Enforces required request (`req.query` and `req.body`) and response parameter types for `GET`, `POST`, `PUT`, and `DELETE` methods in Express.
8
- - Automatically generates a static API URL class that strongly types parameters and auto-casts return types to match the backend's response structure.
9
- - Simplifies integrating strong typing between back-end and front-end.
7
+ - **Strict Type Enforcement**: Ensures that `req.query` and `req.body` follow the declared types.
8
+ - **Auto-Generated API Connector**: Automatically creates a static API class for strongly-typed parameters.
9
+ - **Seamless Front-End Integration**: Simplifies the connection between the back-end and front-end by enforcing consistency.
10
10
 
11
+ ## 🔑 Key Points
11
12
 
12
- ## Key Points
13
+ - **Strict Parameter Enforcement**: GG-Express ensures only the declared parameters are accessible in `req.body` or `req.query`.
14
+ - **Type-Safe Responses**: Ensures that the backend responds with a structure that matches front-end expectations.
15
+ - **API Connector Generation**: It automatically generates a type-safe API connector class file for the front-end.
13
16
 
14
- - Strict Parameter Enforcement: GG-Express ensures that only the declared parameters are accessible in your req.body or req.query.
17
+ ## 🛠 Installation
15
18
 
16
- - Type-Safe Responses: You can only return data that follows the predefined responseStructure, improving consistency between backend and frontend.
17
-
18
- - API Connector Generation: It automatically generates an API connector class file for your front-end, making API calls more reliable and type-safe.
19
-
20
- ## Installation
21
19
  ```bash
22
20
  npm install gg-express
23
21
  ```
24
22
 
25
- use case
26
- ```javascript
23
+ 🧑‍💻 Use Case in Backend
27
24
 
28
- const express = require('express');
29
- const GGExpress = require('gg-express'); // Import GG-Express
30
- const app = express();
25
+ ```typescript
26
+ import express from "express"
27
+ import GGExpress from "gg-express"
28
+ const app = express()
31
29
 
32
30
  // Initialize GG-Express with backend and frontend file paths
33
31
  const ggapp = new GGExpress(app, [
34
- './server/location-for-generating-file', // Path to generate backend file
35
- './myapp/location-for-generating-file', // Path to generate frontend file
36
- ]);
32
+ "./server/output-path-for-apiConnector.ts", // Path to generate apiConnector.ts backend file
33
+ "./myapp/output-path-for-apiConnector.ts", // Path to generate apiConnector.ts frontend file
34
+ ])
37
35
 
38
36
  // Example of a POST request with enforced parameters
39
37
  ggapp.post(
@@ -58,22 +56,10 @@ ggapp.post(
58
56
  },
59
57
  },
60
58
  (req, res, next) => {
61
- // You can only access the required parameters declared above
62
- const data = req.body.data;
63
-
64
- // Expected data structure:
65
- // data: {
66
- // parameter: {
67
- // lotNumber: number;
68
- // };
69
- // data: [{
70
- // id: number;
71
- // name: string;
72
- // price: number;
73
- // }];
74
- // }
75
-
76
- // Response structure also follows the predefined format
59
+ // Access only the required parameters declared above
60
+ const data = req.body.data
61
+
62
+ // Response structure follows the predefined format
77
63
  return res.json({
78
64
  message: "",
79
65
  status: "SUCCESS",
@@ -82,15 +68,49 @@ ggapp.post(
82
68
  itemName: "",
83
69
  numberOfPeople: 2,
84
70
  },
85
- });
71
+ })
86
72
  }
87
- );
73
+ )
88
74
 
89
75
  // Start the server and generate the API files
90
76
  app.listen(3000, () => {
91
- ggapp.generateAPIFiles(); // Generates the apiConnector class for front-end use
92
- });
77
+ ggapp.generateAPIFiles() // Generates the apiConnector class for front-end use
78
+ })
79
+ ```
93
80
 
81
+ 📲 Use Case in Frontend
82
+ • The apiConnector.ts file will be automatically generated by the GGExpress class you configured in the backend
94
83
 
84
+ ```typescript
85
+ import GGApi from "apiConnector.ts"
86
+
87
+ const api = new GGApi()
88
+ const response = await api.post("/api/item", {
89
+ parameter: {
90
+ lotNumber: 2,
91
+ },
92
+ data: [
93
+ {
94
+ id: 1032,
95
+ name: "machete",
96
+ price: 4599,
97
+ },
98
+ ],
99
+ })
100
+ console.log(response.data)
101
+ // Expected data structure:
102
+ // parameter: { numberOfPeople: number, itemName: string },
103
+ // structure: {
104
+ // id: number,
105
+ // name: string,
106
+ // }[],
107
+ // }
95
108
  ```
96
109
 
110
+ ## 🔑 Keywords
111
+
112
+ - Express.js
113
+ - TypeScript
114
+ - API wrapper
115
+ - Type-safe API
116
+ - Backend-frontend integration
package/src/GGExpress.ts CHANGED
@@ -165,7 +165,7 @@ export default class GGExpress {
165
165
  PP extends R["parameter"],
166
166
  J extends M["isPartialStructure"]
167
167
  >(
168
- url: `/api/${string}`,
168
+ url: `/api/gg/${string}`,
169
169
  options: {
170
170
  requireParams: M
171
171
  responseStructure: R
@@ -192,7 +192,7 @@ export default class GGExpress {
192
192
  PP extends R["parameter"],
193
193
  J extends M["isPartialStructure"]
194
194
  >(
195
- url: `/api/${string}`,
195
+ url: `/api/gg/${string}`,
196
196
  options: {
197
197
  requireParams: M
198
198
  responseStructure: R
@@ -218,7 +218,7 @@ export default class GGExpress {
218
218
  PP extends R["parameter"],
219
219
  J extends M["isPartialStructure"]
220
220
  >(
221
- url: `/api/${string}`,
221
+ url: `/api/gg/${string}`,
222
222
  options: {
223
223
  requireParams: M
224
224
  responseStructure: R
@@ -244,7 +244,7 @@ export default class GGExpress {
244
244
  PP extends R["parameter"],
245
245
  J extends M["isPartialStructure"]
246
246
  >(
247
- url: `/api/${string}`,
247
+ url: `/api/gg/${string}`,
248
248
  options: {
249
249
  requireParams: M
250
250
  responseStructure: R
package/src/test.ts CHANGED
@@ -4,7 +4,7 @@ function run() {
4
4
  const app = express()
5
5
  const ggapp = new GGExpress(app, ["./"])
6
6
  ggapp.get(
7
- "/api/users/id",
7
+ "/api/gg/users/id",
8
8
  {
9
9
  requireParams: {
10
10
  parameter: {},
@@ -36,7 +36,7 @@ function run() {
36
36
  )
37
37
 
38
38
  ggapp.post(
39
- "/api/item",
39
+ "/api/gg/item",
40
40
  {
41
41
  requireParams: {
42
42
  parameter: {