gg-express 1.0.22 → 1.0.25
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 +2 -0
- package/dist/GGExpress.js +22 -14
- package/dist/apiConnector.js +0 -21
- package/dist/staticRouteInterface.d.ts +17 -1
- package/dist/test.js +26 -0
- package/package.json +1 -1
- package/src/GGApi.ts +3 -0
- package/src/GGExpress.ts +21 -18
- package/src/apiConnector.ts +4 -11
- package/src/staticRouteInterface.ts +8 -2
- package/src/test.ts +30 -0
package/dist/GGApi.js
CHANGED
package/dist/GGExpress.js
CHANGED
|
@@ -49,7 +49,7 @@ class GGExpress {
|
|
|
49
49
|
generateStaticRouteFile() {
|
|
50
50
|
return __awaiter(this, void 0, void 0, function* () {
|
|
51
51
|
const genParamCodeParameter = (data) => {
|
|
52
|
-
let result;
|
|
52
|
+
let result = "";
|
|
53
53
|
const resultArray = Object.entries(data["parameter"]).map(([key, value]) => ({
|
|
54
54
|
name: key,
|
|
55
55
|
value: value,
|
|
@@ -74,8 +74,8 @@ class GGExpress {
|
|
|
74
74
|
.join(",");
|
|
75
75
|
return result;
|
|
76
76
|
};
|
|
77
|
-
const
|
|
78
|
-
let result;
|
|
77
|
+
const genDataParamCode = (data) => {
|
|
78
|
+
let result = "";
|
|
79
79
|
const resultArray = Object.entries(data["structure"]).map(([key, value]) => ({
|
|
80
80
|
name: key,
|
|
81
81
|
value: value,
|
|
@@ -114,12 +114,29 @@ class GGExpress {
|
|
|
114
114
|
return "";
|
|
115
115
|
rawString = data
|
|
116
116
|
.map((row) => {
|
|
117
|
+
const parameterCode = genParamCodeParameter(row.requireParams);
|
|
118
|
+
const parameterDataCode = genDataParamCode(row.requireParams);
|
|
119
|
+
const requireParameterCode = () => {
|
|
120
|
+
if (parameterCode === "")
|
|
121
|
+
return "";
|
|
122
|
+
else
|
|
123
|
+
return ` parameter:{${parameterCode}} `;
|
|
124
|
+
};
|
|
125
|
+
const requireDataCode = () => {
|
|
126
|
+
if (parameterDataCode === "")
|
|
127
|
+
return "";
|
|
128
|
+
else
|
|
129
|
+
return ` data:{${parameterDataCode}}${isArray(row.requireParams)}`;
|
|
130
|
+
};
|
|
131
|
+
let requireParamCode = `{${[requireParameterCode(), requireDataCode()]
|
|
132
|
+
.filter((row) => row.length > 0)
|
|
133
|
+
.join(",")}}`;
|
|
117
134
|
return ` "${row.url}" : {
|
|
118
|
-
requireParams :
|
|
135
|
+
requireParams : ${requireParamCode},
|
|
119
136
|
responseStructure : {
|
|
120
137
|
status : "SUCCESS" | "ERROR",
|
|
121
138
|
message : string,
|
|
122
|
-
parameter : {${genParamCodeParameter(row.responseStructure)}}, data : { ${
|
|
139
|
+
parameter : {${genParamCodeParameter(row.responseStructure)}}, data : { ${genDataParamCode(row.responseStructure)} } ${isArray(row.responseStructure)}}
|
|
123
140
|
} `;
|
|
124
141
|
})
|
|
125
142
|
.join(",");
|
|
@@ -214,15 +231,6 @@ export class GGApi {
|
|
|
214
231
|
}
|
|
215
232
|
}
|
|
216
233
|
|
|
217
|
-
async function run() {
|
|
218
|
-
const api = new GGApi()
|
|
219
|
-
const data = await api.post("/api/item", {
|
|
220
|
-
parameter: {
|
|
221
|
-
bankID: 1,
|
|
222
|
-
},
|
|
223
|
-
data: [{ id: 2, name: "2" }],
|
|
224
|
-
})
|
|
225
|
-
}
|
|
226
234
|
|
|
227
235
|
`;
|
|
228
236
|
fs_1.default.writeFileSync(filePathWithFileName, code);
|
package/dist/apiConnector.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -66,15 +57,3 @@ class GGApi {
|
|
|
66
57
|
}
|
|
67
58
|
}
|
|
68
59
|
exports.GGApi = GGApi;
|
|
69
|
-
function run() {
|
|
70
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
-
const api = new GGApi();
|
|
72
|
-
const data = yield api.post("/api/item", {
|
|
73
|
-
parameter: {
|
|
74
|
-
bankID: 1,
|
|
75
|
-
},
|
|
76
|
-
data: [{ id: 2, name: "2" }],
|
|
77
|
-
});
|
|
78
|
-
data.data;
|
|
79
|
-
});
|
|
80
|
-
}
|
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
export interface staticRouteInterface {
|
|
2
|
-
get: {
|
|
2
|
+
get: {
|
|
3
|
+
"/api/users": {
|
|
4
|
+
requireParams: {};
|
|
5
|
+
responseStructure: {
|
|
6
|
+
status: "SUCCESS" | "ERROR";
|
|
7
|
+
message: string;
|
|
8
|
+
parameter: {
|
|
9
|
+
numberOfPeople: number;
|
|
10
|
+
itemName: string;
|
|
11
|
+
};
|
|
12
|
+
data: {
|
|
13
|
+
id: number;
|
|
14
|
+
name: string;
|
|
15
|
+
}[];
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
};
|
|
3
19
|
post: {
|
|
4
20
|
"/api/item": {
|
|
5
21
|
requireParams: {
|
package/dist/test.js
CHANGED
|
@@ -8,6 +8,32 @@ 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", {
|
|
12
|
+
requireParams: {
|
|
13
|
+
parameter: {},
|
|
14
|
+
dataType: "singleObject",
|
|
15
|
+
structure: {},
|
|
16
|
+
},
|
|
17
|
+
responseStructure: {
|
|
18
|
+
parameter: { numberOfPeople: "number", itemName: "string" },
|
|
19
|
+
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
|
+
});
|
|
11
37
|
ggapp.post("/api/item", {
|
|
12
38
|
requireParams: {
|
|
13
39
|
parameter: {
|
package/package.json
CHANGED
package/src/GGApi.ts
CHANGED
package/src/GGExpress.ts
CHANGED
|
@@ -246,7 +246,7 @@ export default class GGExpress {
|
|
|
246
246
|
}
|
|
247
247
|
private async generateStaticRouteFile() {
|
|
248
248
|
const genParamCodeParameter = (data: requireParamsStructure) => {
|
|
249
|
-
let result: string
|
|
249
|
+
let result: string = ""
|
|
250
250
|
const resultArray = Object.entries(data["parameter"]).map(
|
|
251
251
|
([key, value]) => ({
|
|
252
252
|
name: key,
|
|
@@ -269,8 +269,8 @@ export default class GGExpress {
|
|
|
269
269
|
.join(",")
|
|
270
270
|
return result
|
|
271
271
|
}
|
|
272
|
-
const
|
|
273
|
-
let result: string
|
|
272
|
+
const genDataParamCode = (data: requireParamsStructure) => {
|
|
273
|
+
let result: string = ""
|
|
274
274
|
const resultArray = Object.entries(data["structure"]).map(
|
|
275
275
|
([key, value]) => ({
|
|
276
276
|
name: key,
|
|
@@ -304,18 +304,30 @@ export default class GGExpress {
|
|
|
304
304
|
if (data.length === 0) return ""
|
|
305
305
|
rawString = data
|
|
306
306
|
.map((row) => {
|
|
307
|
+
const parameterCode = genParamCodeParameter(row.requireParams)
|
|
308
|
+
const parameterDataCode = genDataParamCode(row.requireParams)
|
|
309
|
+
|
|
310
|
+
const requireParameterCode = () => {
|
|
311
|
+
if (parameterCode === "") return ""
|
|
312
|
+
else return ` parameter:{${parameterCode}} `
|
|
313
|
+
}
|
|
314
|
+
const requireDataCode = () => {
|
|
315
|
+
if (parameterDataCode === "") return ""
|
|
316
|
+
else
|
|
317
|
+
return ` data:{${parameterDataCode}}${isArray(row.requireParams)}`
|
|
318
|
+
}
|
|
319
|
+
let requireParamCode = `{${[requireParameterCode(), requireDataCode()]
|
|
320
|
+
.filter((row) => row.length > 0)
|
|
321
|
+
.join(",")}}`
|
|
322
|
+
|
|
307
323
|
return ` "${row.url}" : {
|
|
308
|
-
requireParams :
|
|
309
|
-
row.requireParams
|
|
310
|
-
)}}, data : { ${genParamCode(row.requireParams)} }${isArray(
|
|
311
|
-
row.requireParams
|
|
312
|
-
)}},
|
|
324
|
+
requireParams : ${requireParamCode},
|
|
313
325
|
responseStructure : {
|
|
314
326
|
status : "SUCCESS" | "ERROR",
|
|
315
327
|
message : string,
|
|
316
328
|
parameter : {${genParamCodeParameter(
|
|
317
329
|
row.responseStructure
|
|
318
|
-
)}}, data : { ${
|
|
330
|
+
)}}, data : { ${genDataParamCode(row.responseStructure)} } ${isArray(
|
|
319
331
|
row.responseStructure
|
|
320
332
|
)}}
|
|
321
333
|
} `
|
|
@@ -414,15 +426,6 @@ export class GGApi {
|
|
|
414
426
|
}
|
|
415
427
|
}
|
|
416
428
|
|
|
417
|
-
async function run() {
|
|
418
|
-
const api = new GGApi()
|
|
419
|
-
const data = await api.post("/api/item", {
|
|
420
|
-
parameter: {
|
|
421
|
-
bankID: 1,
|
|
422
|
-
},
|
|
423
|
-
data: [{ id: 2, name: "2" }],
|
|
424
|
-
})
|
|
425
|
-
}
|
|
426
429
|
|
|
427
430
|
`
|
|
428
431
|
|
package/src/apiConnector.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
|
+
import axios from "axios"
|
|
2
3
|
import { staticRouteInterface } from "./staticRouteInterface"
|
|
3
4
|
|
|
4
5
|
export class GGApi {
|
|
@@ -67,13 +68,5 @@ export class GGApi {
|
|
|
67
68
|
}
|
|
68
69
|
}
|
|
69
70
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const data = await api.post("/api/item", {
|
|
73
|
-
parameter: {
|
|
74
|
-
bankID: 1,
|
|
75
|
-
},
|
|
76
|
-
data: [{ id: 2, name: "2" }],
|
|
77
|
-
})
|
|
78
|
-
data.data
|
|
79
|
-
}
|
|
71
|
+
|
|
72
|
+
|
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
export interface staticRouteInterface {
|
|
2
|
-
get : {
|
|
2
|
+
get : { "/api/users" : {
|
|
3
|
+
requireParams : {},
|
|
4
|
+
responseStructure : {
|
|
5
|
+
status : "SUCCESS" | "ERROR",
|
|
6
|
+
message : string,
|
|
7
|
+
parameter : { numberOfPeople : number, itemName : string}, data : { id : number, name : string } []}
|
|
8
|
+
} },
|
|
3
9
|
post : { "/api/item" : {
|
|
4
|
-
requireParams : { parameter
|
|
10
|
+
requireParams : { parameter:{ bankID : number} , data:{ id : number, name : string}[]},
|
|
5
11
|
responseStructure : {
|
|
6
12
|
status : "SUCCESS" | "ERROR",
|
|
7
13
|
message : string,
|
package/src/test.ts
CHANGED
|
@@ -3,6 +3,36 @@ import express, { Express } from "express"
|
|
|
3
3
|
function run() {
|
|
4
4
|
const app = express()
|
|
5
5
|
const ggapp = new GGExpress(app, ["./"])
|
|
6
|
+
ggapp.get(
|
|
7
|
+
"/api/users",
|
|
8
|
+
{
|
|
9
|
+
requireParams: {
|
|
10
|
+
parameter: {},
|
|
11
|
+
dataType: "singleObject",
|
|
12
|
+
structure: {},
|
|
13
|
+
},
|
|
14
|
+
responseStructure: {
|
|
15
|
+
parameter: { numberOfPeople: "number", itemName: "string" },
|
|
16
|
+
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
|
+
)
|
|
6
36
|
ggapp.post(
|
|
7
37
|
"/api/item",
|
|
8
38
|
{
|