gg-express 1.0.29 → 1.0.30

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/GGApi.js CHANGED
@@ -19,7 +19,7 @@ class GGApi {
19
19
  get(url, requireParams) {
20
20
  return new Promise((resolve, reject) => {
21
21
  axios_1.default
22
- .get(url, { params: requireParams })
22
+ .get(url, { params: { data: requireParams } })
23
23
  .then((response) => {
24
24
  resolve(response.data);
25
25
  })
@@ -69,11 +69,13 @@ exports.GGApi = GGApi;
69
69
  function run() {
70
70
  return __awaiter(this, void 0, void 0, function* () {
71
71
  const api = new GGApi();
72
- const data = yield api.post("/api/item", {
73
- parameter: { lotNumber: 1223 },
74
- data: [],
72
+ // const data = await api.post("/api/item", {
73
+ // parameter: { lotNumber: 1223 },
74
+ // data: [],
75
+ // })
76
+ const data2 = yield api.get(("http://localhost:3002" + "/api/users/id"), {
77
+ data: [{ id: 2 }, { id: 3 }, { id: 20 }],
75
78
  });
76
- const data2 = yield api.get("/api/users", {});
77
- data.data;
78
79
  });
79
80
  }
81
+ run();
package/dist/GGExpress.js CHANGED
@@ -172,7 +172,7 @@ class GGExpress {
172
172
  return __awaiter(this, void 0, void 0, function* () {
173
173
  // const code = await fs.readFileSync("./GGApi.ts")
174
174
  const code = `
175
- import axios from "axios"
175
+ import axios from "axios"
176
176
  import { staticRouteInterface } from "./staticRouteInterface"
177
177
 
178
178
  export class GGApi {
@@ -184,7 +184,7 @@ export class GGApi {
184
184
  ): Promise<staticRouteInterface["get"][T]["responseStructure"]> {
185
185
  return new Promise((resolve, reject) => {
186
186
  axios
187
- .get(url as string, { params: requireParams })
187
+ .get(url as string, { params: { data: requireParams } })
188
188
  .then((response) => {
189
189
  resolve(response.data)
190
190
  })
@@ -0,0 +1,2 @@
1
+ import { NextFunction, Request, Response } from "express";
2
+ export declare function parseQueryJSON(req: Request, res: Response, next: NextFunction): void;
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseQueryJSON = parseQueryJSON;
4
+ function parseQueryJSON(req, res, next) {
5
+ // Check if there's any query parameter to parse
6
+ if (req.query) {
7
+ for (const key in req.query) {
8
+ if (Array.isArray(req.query[key])) {
9
+ // If the query param is an array of stringified JSON, parse each item
10
+ req.query[key] = req.query[key].map((item) => {
11
+ try {
12
+ return JSON.parse(item);
13
+ }
14
+ catch (err) {
15
+ console.error(`Failed to parse query parameter: ${item}`);
16
+ return item; // Return the original if parsing fails
17
+ }
18
+ });
19
+ }
20
+ else if (typeof req.query[key] === "string") {
21
+ // If the query param is a stringified JSON, attempt to parse it
22
+ try {
23
+ req.query[key] = JSON.parse(req.query[key]);
24
+ }
25
+ catch (err) {
26
+ console.error(`Failed to parse query parameter: ${req.query[key]}`);
27
+ // Keep the original string if parsing fails
28
+ }
29
+ }
30
+ }
31
+ }
32
+ next(); // Call next middleware in the stack
33
+ }
@@ -1,7 +1,11 @@
1
1
  export interface staticRouteInterface {
2
2
  get: {
3
- "/api/users": {
4
- requireParams: {};
3
+ "/api/users/id": {
4
+ requireParams: {
5
+ data: {
6
+ id: number;
7
+ }[];
8
+ };
5
9
  responseStructure: {
6
10
  status: "SUCCESS" | "ERROR";
7
11
  message: string;
package/dist/test.js CHANGED
@@ -8,37 +8,11 @@ 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", {
11
+ ggapp.get("/api/users/id", {
12
12
  requireParams: {
13
13
  parameter: {},
14
- dataType: "singleObject",
15
- structure: {},
16
- },
17
- responseStructure: {
18
- parameter: { numberOfPeople: "number", itemName: "string" },
19
14
  dataType: "arrayObject",
20
- structure: {
21
- id: "number",
22
- name: "string",
23
- },
24
- },
25
- }, (req, res, next) => {
26
- const data = req.body.data.parameter;
27
- return res.json({
28
- message: "",
29
- status: "SUCCESS",
30
- data: [],
31
- parameter: {
32
- itemName: "",
33
- numberOfPeople: 2,
34
- },
35
- });
36
- });
37
- ggapp.get("/api/users", {
38
- requireParams: {
39
- parameter: {},
40
- dataType: "singleObject",
41
- structure: {},
15
+ structure: { id: "number" },
42
16
  },
43
17
  responseStructure: {
44
18
  parameter: { numberOfPeople: "number", itemName: "string" },
@@ -49,7 +23,7 @@ function run() {
49
23
  },
50
24
  },
51
25
  }, (req, res, next) => {
52
- const data = req.body.data.parameter;
26
+ console.log(req.query);
53
27
  return res.json({
54
28
  message: "",
55
29
  status: "SUCCESS",
@@ -106,7 +80,7 @@ function run() {
106
80
  },
107
81
  });
108
82
  });
109
- app.listen(3000, () => {
83
+ app.listen(3002, () => {
110
84
  ggapp.generateAPIFiles();
111
85
  });
112
86
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gg-express",
3
- "version": "1.0.29",
3
+ "version": "1.0.30",
4
4
  "description": "",
5
5
  "main": "dist/GGExpress.js",
6
6
  "scripts": {
package/src/GGApi.ts CHANGED
@@ -10,7 +10,7 @@ export class GGApi {
10
10
  ): Promise<staticRouteInterface["get"][T]["responseStructure"]> {
11
11
  return new Promise((resolve, reject) => {
12
12
  axios
13
- .get(url as string, { params: requireParams })
13
+ .get(url as string, { params: { data: requireParams } })
14
14
  .then((response) => {
15
15
  resolve(response.data)
16
16
  })
@@ -69,11 +69,16 @@ export class GGApi {
69
69
 
70
70
  async function run() {
71
71
  const api = new GGApi()
72
- const data = await api.post("/api/item", {
73
- parameter: { lotNumber: 1223 },
74
- data: [],
75
- })
72
+ // const data = await api.post("/api/item", {
73
+ // parameter: { lotNumber: 1223 },
74
+ // data: [],
75
+ // })
76
76
 
77
- const data2 = await api.get("/api/users", {})
78
- data.data
77
+ const data2 = await api.get(
78
+ ("http://localhost:3002" + "/api/users/id") as any,
79
+ {
80
+ data: [{ id: 2 }, { id: 3 }, { id: 20 }],
81
+ }
82
+ )
79
83
  }
84
+ run()
package/src/GGExpress.ts CHANGED
@@ -375,7 +375,7 @@ export default class GGExpress {
375
375
  private async generateGGApi(filePathWithFileName: string) {
376
376
  // const code = await fs.readFileSync("./GGApi.ts")
377
377
  const code = `
378
- import axios from "axios"
378
+ import axios from "axios"
379
379
  import { staticRouteInterface } from "./staticRouteInterface"
380
380
 
381
381
  export class GGApi {
@@ -387,7 +387,7 @@ export class GGApi {
387
387
  ): Promise<staticRouteInterface["get"][T]["responseStructure"]> {
388
388
  return new Promise((resolve, reject) => {
389
389
  axios
390
- .get(url as string, { params: requireParams })
390
+ .get(url as string, { params: { data: requireParams } })
391
391
  .then((response) => {
392
392
  resolve(response.data)
393
393
  })
@@ -0,0 +1,33 @@
1
+ import { NextFunction, Request, Response } from "express"
2
+
3
+ export function parseQueryJSON(
4
+ req: Request,
5
+ res: Response,
6
+ next: NextFunction
7
+ ) {
8
+ // Check if there's any query parameter to parse
9
+ if (req.query) {
10
+ for (const key in req.query) {
11
+ if (Array.isArray(req.query[key])) {
12
+ // If the query param is an array of stringified JSON, parse each item
13
+ req.query[key] = req.query[key].map((item) => {
14
+ try {
15
+ return JSON.parse(item as any)
16
+ } catch (err) {
17
+ console.error(`Failed to parse query parameter: ${item}`)
18
+ return item // Return the original if parsing fails
19
+ }
20
+ })
21
+ } else if (typeof req.query[key] === "string") {
22
+ // If the query param is a stringified JSON, attempt to parse it
23
+ try {
24
+ req.query[key] = JSON.parse(req.query[key])
25
+ } catch (err) {
26
+ console.error(`Failed to parse query parameter: ${req.query[key]}`)
27
+ // Keep the original string if parsing fails
28
+ }
29
+ }
30
+ }
31
+ }
32
+ next() // Call next middleware in the stack
33
+ }
@@ -1,6 +1,6 @@
1
1
  export interface staticRouteInterface {
2
- get : { "/api/users" : {
3
- requireParams : {},
2
+ get : { "/api/users/id" : {
3
+ requireParams : { data:{ id : number}[]},
4
4
  responseStructure : {
5
5
  status : "SUCCESS" | "ERROR",
6
6
  message : string,
package/src/test.ts CHANGED
@@ -4,43 +4,12 @@ function run() {
4
4
  const app = express()
5
5
  const ggapp = new GGExpress(app, ["./"])
6
6
  ggapp.get(
7
- "/api/users",
7
+ "/api/users/id",
8
8
  {
9
9
  requireParams: {
10
10
  parameter: {},
11
- dataType: "singleObject",
12
- structure: {},
13
- },
14
- responseStructure: {
15
- parameter: { numberOfPeople: "number", itemName: "string" },
16
11
  dataType: "arrayObject",
17
- structure: {
18
- id: "number",
19
- name: "string",
20
- },
21
- },
22
- },
23
- (req, res, next) => {
24
- const data = req.body.data.parameter
25
- return res.json({
26
- message: "",
27
- status: "SUCCESS",
28
- data: [],
29
- parameter: {
30
- itemName: "",
31
- numberOfPeople: 2,
32
- },
33
- })
34
- }
35
- )
36
-
37
- ggapp.get(
38
- "/api/users",
39
- {
40
- requireParams: {
41
- parameter: {},
42
- dataType: "singleObject",
43
- structure: {},
12
+ structure: { id: "number" },
44
13
  },
45
14
  responseStructure: {
46
15
  parameter: { numberOfPeople: "number", itemName: "string" },
@@ -52,7 +21,7 @@ function run() {
52
21
  },
53
22
  },
54
23
  (req, res, next) => {
55
- const data = req.body.data.parameter
24
+ console.log(req.query)
56
25
  return res.json({
57
26
  message: "",
58
27
  status: "SUCCESS",
@@ -64,6 +33,7 @@ function run() {
64
33
  })
65
34
  }
66
35
  )
36
+
67
37
  ggapp.post(
68
38
  "/api/item",
69
39
  {
@@ -115,7 +85,7 @@ function run() {
115
85
  })
116
86
  }
117
87
  )
118
- app.listen(3000, () => {
88
+ app.listen(3002, () => {
119
89
  ggapp.generateAPIFiles()
120
90
  })
121
91
  }