gg-express 1.0.54 → 1.0.56
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 +3 -1
- package/dist/GGExpress.d.ts +7 -6
- package/dist/GGExpress.js +4 -3
- package/dist/run.test.d.ts +1 -0
- package/dist/run.test.js +90 -0
- package/package.json +1 -1
- package/src/GGExpress.ts +15 -9
- package/src/{test.ts → run.test.ts} +8 -7
package/.gitlab-ci.yml
CHANGED
package/dist/GGExpress.d.ts
CHANGED
|
@@ -59,24 +59,25 @@ type MyResponse<DT extends responseStructure["dataType"], T extends responseStru
|
|
|
59
59
|
[key in K]: numberOrString<T[key]>;
|
|
60
60
|
};
|
|
61
61
|
}>;
|
|
62
|
-
export default class GGExpress {
|
|
62
|
+
export default class GGExpress<appName extends string> {
|
|
63
63
|
express: Express.Express;
|
|
64
64
|
private outputPath;
|
|
65
|
-
|
|
65
|
+
appName: string;
|
|
66
|
+
constructor(app: Express.Express, appName: appName, outputPath: string[]);
|
|
66
67
|
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
|
|
68
|
+
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/${appName}/${string}`, options: {
|
|
68
69
|
requireParams: M;
|
|
69
70
|
responseStructure: R;
|
|
70
71
|
}, ...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
|
|
72
|
+
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/${appName}/${string}`, options: {
|
|
72
73
|
requireParams: M;
|
|
73
74
|
responseStructure: R;
|
|
74
75
|
}, ...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
|
|
76
|
+
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/${appName}/${string}`, options: {
|
|
76
77
|
requireParams: M;
|
|
77
78
|
responseStructure: R;
|
|
78
79
|
}, ...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
|
|
80
|
+
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/${appName}/${string}`, options: {
|
|
80
81
|
requireParams: M;
|
|
81
82
|
responseStructure: R;
|
|
82
83
|
}, ...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/GGExpress.js
CHANGED
|
@@ -17,9 +17,10 @@ const path_1 = __importDefault(require("path"));
|
|
|
17
17
|
const chalk_1 = __importDefault(require("chalk"));
|
|
18
18
|
const myExpressRouteList = [];
|
|
19
19
|
class GGExpress {
|
|
20
|
-
constructor(app, outputPath) {
|
|
20
|
+
constructor(app, appName, outputPath) {
|
|
21
21
|
this.express = app;
|
|
22
22
|
this.outputPath = outputPath;
|
|
23
|
+
this.appName = appName;
|
|
23
24
|
}
|
|
24
25
|
rootMethod(method, url, options, ...middlewares) {
|
|
25
26
|
myExpressRouteList.push({
|
|
@@ -170,8 +171,8 @@ class GGExpress {
|
|
|
170
171
|
delete : { ${genInterfaceString(deleteDelete)} },
|
|
171
172
|
}`;
|
|
172
173
|
for (let row of this.outputPath) {
|
|
173
|
-
fs_1.default.writeFileSync(path_1.default.join(row,
|
|
174
|
-
yield this.generateGGApi(path_1.default.join(row,
|
|
174
|
+
fs_1.default.writeFileSync(path_1.default.join(row, `staticRouteInterface_${this.appName}.ts`), content);
|
|
175
|
+
yield this.generateGGApi(path_1.default.join(row, `apiConnector_${this.appName}.ts`));
|
|
175
176
|
}
|
|
176
177
|
});
|
|
177
178
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/run.test.js
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const GGExpress_1 = __importDefault(require("./GGExpress"));
|
|
7
|
+
const express_1 = __importDefault(require("express"));
|
|
8
|
+
function run() {
|
|
9
|
+
const app = (0, express_1.default)();
|
|
10
|
+
const ggapp = new GGExpress_1.default(app, "hotel", ["./"]);
|
|
11
|
+
ggapp.get("/api/hotel/users/id", {
|
|
12
|
+
requireParams: {
|
|
13
|
+
parameter: {},
|
|
14
|
+
dataType: "arrayObject",
|
|
15
|
+
structure: { id: "number", name: ["A", "B"] },
|
|
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
|
+
req.query.data.data;
|
|
27
|
+
console.log(req.query);
|
|
28
|
+
return res.json({
|
|
29
|
+
message: "",
|
|
30
|
+
status: "SUCCESS",
|
|
31
|
+
data: [],
|
|
32
|
+
parameter: {
|
|
33
|
+
itemName: "",
|
|
34
|
+
numberOfPeople: 2,
|
|
35
|
+
},
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
ggapp.post("/api/hotel/item", {
|
|
39
|
+
requireParams: {
|
|
40
|
+
parameter: {
|
|
41
|
+
lotNumber: "number",
|
|
42
|
+
},
|
|
43
|
+
isPartialStructure: true,
|
|
44
|
+
dataType: "singleObject",
|
|
45
|
+
structure: {
|
|
46
|
+
id: "number",
|
|
47
|
+
name: ["item-1", "item-2"],
|
|
48
|
+
price: "number",
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
responseStructure: {
|
|
52
|
+
parameter: { numberOfPeople: "number", itemName: "string" },
|
|
53
|
+
dataType: "arrayObject",
|
|
54
|
+
structure: {
|
|
55
|
+
id: "number",
|
|
56
|
+
name: "string",
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
}, (req, res, next) => {
|
|
60
|
+
const x = req.body.data.data.name;
|
|
61
|
+
// in body or query, you can access only requireParams that you declare at start
|
|
62
|
+
const data = req.body.data;
|
|
63
|
+
/* data structure =
|
|
64
|
+
data: {
|
|
65
|
+
parameter: {
|
|
66
|
+
lotNumber: number;
|
|
67
|
+
};
|
|
68
|
+
data: {
|
|
69
|
+
id: number;
|
|
70
|
+
name: string;
|
|
71
|
+
price: number;
|
|
72
|
+
}[];
|
|
73
|
+
}
|
|
74
|
+
*/
|
|
75
|
+
// also res.json(), you can only return structure like responseStructure that you declare at start
|
|
76
|
+
return res.json({
|
|
77
|
+
message: "",
|
|
78
|
+
status: "SUCCESS",
|
|
79
|
+
data: [],
|
|
80
|
+
parameter: {
|
|
81
|
+
itemName: "",
|
|
82
|
+
numberOfPeople: 2,
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
});
|
|
86
|
+
app.listen(3002, () => {
|
|
87
|
+
ggapp.generateAPIFiles();
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
run();
|
package/package.json
CHANGED
package/src/GGExpress.ts
CHANGED
|
@@ -5,7 +5,6 @@ import fs from "fs"
|
|
|
5
5
|
import path from "path"
|
|
6
6
|
import chalk from "chalk"
|
|
7
7
|
|
|
8
|
-
// export { GGApi } from "./GGApi"
|
|
9
8
|
type Unarray<T> = T extends (infer U)[] ? U : T
|
|
10
9
|
type AsConstArray<T extends readonly any[]> = [...T]
|
|
11
10
|
type paramType =
|
|
@@ -102,12 +101,14 @@ const myExpressRouteList: {
|
|
|
102
101
|
responseStructure: responseStructure
|
|
103
102
|
}[] = []
|
|
104
103
|
|
|
105
|
-
export default class GGExpress {
|
|
104
|
+
export default class GGExpress<appName extends string> {
|
|
106
105
|
public express: Express.Express
|
|
107
106
|
private outputPath: string[]
|
|
108
|
-
|
|
107
|
+
appName: string
|
|
108
|
+
constructor(app: Express.Express, appName: appName, outputPath: string[]) {
|
|
109
109
|
this.express = app
|
|
110
110
|
this.outputPath = outputPath
|
|
111
|
+
this.appName = appName
|
|
111
112
|
}
|
|
112
113
|
|
|
113
114
|
private rootMethod<
|
|
@@ -165,7 +166,7 @@ export default class GGExpress {
|
|
|
165
166
|
PP extends R["parameter"],
|
|
166
167
|
J extends M["isPartialStructure"]
|
|
167
168
|
>(
|
|
168
|
-
url: `/api
|
|
169
|
+
url: `/api/${appName}/${string}`,
|
|
169
170
|
options: {
|
|
170
171
|
requireParams: M
|
|
171
172
|
responseStructure: R
|
|
@@ -192,7 +193,7 @@ export default class GGExpress {
|
|
|
192
193
|
PP extends R["parameter"],
|
|
193
194
|
J extends M["isPartialStructure"]
|
|
194
195
|
>(
|
|
195
|
-
url: `/api
|
|
196
|
+
url: `/api/${appName}/${string}`,
|
|
196
197
|
options: {
|
|
197
198
|
requireParams: M
|
|
198
199
|
responseStructure: R
|
|
@@ -218,7 +219,7 @@ export default class GGExpress {
|
|
|
218
219
|
PP extends R["parameter"],
|
|
219
220
|
J extends M["isPartialStructure"]
|
|
220
221
|
>(
|
|
221
|
-
url: `/api
|
|
222
|
+
url: `/api/${appName}/${string}`,
|
|
222
223
|
options: {
|
|
223
224
|
requireParams: M
|
|
224
225
|
responseStructure: R
|
|
@@ -244,7 +245,7 @@ export default class GGExpress {
|
|
|
244
245
|
PP extends R["parameter"],
|
|
245
246
|
J extends M["isPartialStructure"]
|
|
246
247
|
>(
|
|
247
|
-
url: `/api
|
|
248
|
+
url: `/api/${appName}/${string}`,
|
|
248
249
|
options: {
|
|
249
250
|
requireParams: M
|
|
250
251
|
responseStructure: R
|
|
@@ -394,8 +395,13 @@ export default class GGExpress {
|
|
|
394
395
|
}`
|
|
395
396
|
|
|
396
397
|
for (let row of this.outputPath) {
|
|
397
|
-
fs.writeFileSync(
|
|
398
|
-
|
|
398
|
+
fs.writeFileSync(
|
|
399
|
+
path.join(row, `staticRouteInterface_${this.appName}.ts`),
|
|
400
|
+
content
|
|
401
|
+
)
|
|
402
|
+
await this.generateGGApi(
|
|
403
|
+
path.join(row, `apiConnector_${this.appName}.ts`)
|
|
404
|
+
)
|
|
399
405
|
}
|
|
400
406
|
}
|
|
401
407
|
private async generateGGApi(filePathWithFileName: string) {
|
|
@@ -2,14 +2,14 @@ import GGExpress from "./GGExpress"
|
|
|
2
2
|
import express, { Express } from "express"
|
|
3
3
|
function run() {
|
|
4
4
|
const app = express()
|
|
5
|
-
const ggapp = new GGExpress(app, ["./"])
|
|
5
|
+
const ggapp = new GGExpress<"hotel">(app, "hotel", ["./"])
|
|
6
6
|
ggapp.get(
|
|
7
|
-
"/api/
|
|
7
|
+
"/api/hotel/users/id",
|
|
8
8
|
{
|
|
9
9
|
requireParams: {
|
|
10
10
|
parameter: {},
|
|
11
11
|
dataType: "arrayObject",
|
|
12
|
-
structure: { id: "number" },
|
|
12
|
+
structure: { id: "number", name: ["A", "B"] as const },
|
|
13
13
|
},
|
|
14
14
|
responseStructure: {
|
|
15
15
|
parameter: { numberOfPeople: "number", itemName: "string" },
|
|
@@ -36,7 +36,7 @@ function run() {
|
|
|
36
36
|
)
|
|
37
37
|
|
|
38
38
|
ggapp.post(
|
|
39
|
-
"/api/
|
|
39
|
+
"/api/hotel/item",
|
|
40
40
|
{
|
|
41
41
|
requireParams: {
|
|
42
42
|
parameter: {
|
|
@@ -46,7 +46,7 @@ function run() {
|
|
|
46
46
|
dataType: "singleObject",
|
|
47
47
|
structure: {
|
|
48
48
|
id: "number",
|
|
49
|
-
name: ["item-1", "item-2"],
|
|
49
|
+
name: ["item-1", "item-2"] as const,
|
|
50
50
|
price: "number",
|
|
51
51
|
},
|
|
52
52
|
},
|
|
@@ -60,10 +60,11 @@ function run() {
|
|
|
60
60
|
},
|
|
61
61
|
},
|
|
62
62
|
(req, res, next) => {
|
|
63
|
-
req.body.data.data
|
|
63
|
+
const x = req.body.data.data.name
|
|
64
|
+
|
|
64
65
|
// in body or query, you can access only requireParams that you declare at start
|
|
65
66
|
const data = req.body.data
|
|
66
|
-
/* data structure
|
|
67
|
+
/* data structure =
|
|
67
68
|
data: {
|
|
68
69
|
parameter: {
|
|
69
70
|
lotNumber: number;
|