gg-express 1.0.44 → 1.0.54
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/.gitlab-ci.yml +13 -0
- package/dist/GGApi.js +3 -5
- package/dist/GGExpress.js +9 -8
- package/dist/apiConnector.js +1 -1
- package/dist/staticRouteInterface.d.ts +3 -3
- package/dist/test.js +1 -1
- package/package.json +8 -3
- package/readme.md +1 -1
- package/src/GGApi.ts +3 -5
- package/src/GGExpress.ts +8 -5
- package/src/apiConnector.ts +1 -1
- package/src/staticRouteInterface.ts +3 -3
- package/src/test.ts +1 -1
- package/src/parseQueryJSON.ts +0 -33
package/.gitlab-ci.yml
ADDED
package/dist/GGApi.js
CHANGED
|
@@ -79,11 +79,9 @@ function run() {
|
|
|
79
79
|
// data: [{ id: 2 }, { id: 3 }, { id: 20 }],
|
|
80
80
|
// }
|
|
81
81
|
// )
|
|
82
|
-
const data2 = yield api.get("/api/users/id", {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
api.post("/api/item", {
|
|
86
|
-
data: { id: 2 },
|
|
82
|
+
const data2 = yield api.get("/api/gg/users/id", { data: [{ id: 2 }] });
|
|
83
|
+
api.post("/api/gg/item", {
|
|
84
|
+
data: { id: 1, name: "item-1", price: 2 },
|
|
87
85
|
parameter: {
|
|
88
86
|
lotNumber: 2,
|
|
89
87
|
},
|
package/dist/GGExpress.js
CHANGED
|
@@ -87,16 +87,17 @@ class GGExpress {
|
|
|
87
87
|
.map((row) => {
|
|
88
88
|
if (Array.isArray(row.value)) {
|
|
89
89
|
return ` ${row.name} : ${row.value
|
|
90
|
-
.map((vRow) => {
|
|
91
|
-
if (typeof vRow === "string")
|
|
92
|
-
return `"${vRow}"`;
|
|
93
|
-
else if (typeof vRow === "number")
|
|
94
|
-
return `${vRow}`;
|
|
95
|
-
})
|
|
90
|
+
.map((vRow) => `"${vRow}"`)
|
|
96
91
|
.join(" | ")}`;
|
|
97
92
|
}
|
|
98
|
-
else
|
|
99
|
-
|
|
93
|
+
else {
|
|
94
|
+
let type;
|
|
95
|
+
if (row.value === "number")
|
|
96
|
+
type = "number";
|
|
97
|
+
if (row.value === "string")
|
|
98
|
+
type = "string";
|
|
99
|
+
return ` ${row.name} : ${type}`;
|
|
100
|
+
}
|
|
100
101
|
})
|
|
101
102
|
.join(",");
|
|
102
103
|
return result;
|
package/dist/apiConnector.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export interface staticRouteInterface {
|
|
2
2
|
get: {
|
|
3
|
-
"/api/users/id": {
|
|
3
|
+
"/api/gg/users/id": {
|
|
4
4
|
requireParams: {
|
|
5
5
|
data: {
|
|
6
6
|
id: number;
|
|
@@ -21,14 +21,14 @@ export interface staticRouteInterface {
|
|
|
21
21
|
};
|
|
22
22
|
};
|
|
23
23
|
post: {
|
|
24
|
-
"/api/item": {
|
|
24
|
+
"/api/gg/item": {
|
|
25
25
|
requireParams: {
|
|
26
26
|
parameter: {
|
|
27
27
|
lotNumber: number;
|
|
28
28
|
};
|
|
29
29
|
data: Partial<{
|
|
30
30
|
id: number;
|
|
31
|
-
name:
|
|
31
|
+
name: "item-1" | "item-2";
|
|
32
32
|
price: number;
|
|
33
33
|
}>;
|
|
34
34
|
};
|
package/dist/test.js
CHANGED
package/package.json
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gg-express",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.54",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/GGExpress.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"build": "npm version patch
|
|
7
|
+
"build": "tsc && npm version patch --no-git-tag-version",
|
|
8
8
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
9
9
|
},
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://gitlab.com/tin.sittiyot/gg-express.git"
|
|
13
|
+
},
|
|
10
14
|
"author": "goomgum",
|
|
11
15
|
"license": "ISC",
|
|
12
16
|
"dependencies": {
|
|
@@ -19,7 +23,8 @@
|
|
|
19
23
|
"path": "^0.12.7"
|
|
20
24
|
},
|
|
21
25
|
"devDependencies": {
|
|
22
|
-
"@types/express": "^5.0.0"
|
|
26
|
+
"@types/express": "^5.0.0",
|
|
27
|
+
"typescript": "^5.6.3"
|
|
23
28
|
},
|
|
24
29
|
"keywords": [
|
|
25
30
|
"express",
|
package/readme.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# 🚀 GG-Express
|
|
2
2
|
|
|
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.
|
|
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
5
|
## ✨ Features
|
|
6
6
|
|
package/src/GGApi.ts
CHANGED
|
@@ -80,11 +80,9 @@ async function run() {
|
|
|
80
80
|
// data: [{ id: 2 }, { id: 3 }, { id: 20 }],
|
|
81
81
|
// }
|
|
82
82
|
// )
|
|
83
|
-
const data2 = await api.get("/api/users/id", {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
api.post("/api/item", {
|
|
87
|
-
data: { id: 2 },
|
|
83
|
+
const data2 = await api.get("/api/gg/users/id", { data: [{ id: 2 }] })
|
|
84
|
+
api.post("/api/gg/item", {
|
|
85
|
+
data: { id: 1, name: "item-1", price: 2 },
|
|
88
86
|
parameter: {
|
|
89
87
|
lotNumber: 2,
|
|
90
88
|
},
|
package/src/GGExpress.ts
CHANGED
|
@@ -301,12 +301,15 @@ export default class GGExpress {
|
|
|
301
301
|
.map((row) => {
|
|
302
302
|
if (Array.isArray(row.value)) {
|
|
303
303
|
return ` ${row.name} : ${row.value
|
|
304
|
-
.map((vRow) => {
|
|
305
|
-
if (typeof vRow === "string") return `"${vRow}"`
|
|
306
|
-
else if (typeof vRow === "number") return `${vRow}`
|
|
307
|
-
})
|
|
304
|
+
.map((vRow) => `"${vRow}"`)
|
|
308
305
|
.join(" | ")}`
|
|
309
|
-
} else
|
|
306
|
+
} else {
|
|
307
|
+
let type
|
|
308
|
+
if (row.value === "number") type = "number"
|
|
309
|
+
if (row.value === "string") type = "string"
|
|
310
|
+
|
|
311
|
+
return ` ${row.name} : ${type}`
|
|
312
|
+
}
|
|
310
313
|
})
|
|
311
314
|
.join(",")
|
|
312
315
|
return result
|
package/src/apiConnector.ts
CHANGED
|
@@ -57,7 +57,7 @@ export class GGApi {
|
|
|
57
57
|
): Promise<staticRouteInterface["delete"][T]["responseStructure"]> {
|
|
58
58
|
return new Promise((resolve, reject) => {
|
|
59
59
|
axios
|
|
60
|
-
.delete(url as string, { data: requireParams })
|
|
60
|
+
.delete(url as string, { data: { data: requireParams } })
|
|
61
61
|
.then((response) => {
|
|
62
62
|
resolve(response.data)
|
|
63
63
|
})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export interface staticRouteInterface {
|
|
2
2
|
get: {
|
|
3
|
-
"/api/users/id": {
|
|
3
|
+
"/api/gg/users/id": {
|
|
4
4
|
requireParams: { data: { id: number }[] }
|
|
5
5
|
responseStructure: {
|
|
6
6
|
status: "SUCCESS" | "ERROR"
|
|
@@ -11,10 +11,10 @@ export interface staticRouteInterface {
|
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
post: {
|
|
14
|
-
"/api/item": {
|
|
14
|
+
"/api/gg/item": {
|
|
15
15
|
requireParams: {
|
|
16
16
|
parameter: { lotNumber: number }
|
|
17
|
-
data: Partial<{ id: number; name:
|
|
17
|
+
data: Partial<{ id: number; name: "item-1" | "item-2"; price: number }>
|
|
18
18
|
}
|
|
19
19
|
responseStructure: {
|
|
20
20
|
status: "SUCCESS" | "ERROR"
|
package/src/test.ts
CHANGED
package/src/parseQueryJSON.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
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
|
-
}
|