gg-express 1.0.86 → 1.0.90
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/v2/run_v2.test.d.ts +23 -1
- package/dist/v2/run_v2.test.js +90 -8
- package/dist/v2/typeResolver.d.ts +4 -12
- package/dist/v2/typeResolver.js +43 -0
- package/package.json +1 -1
- package/src/v2/generateStaticRouteFileV2.ts +2 -3
- package/src/v2/run_v2.test.ts +92 -9
- package/src/v2/typeResolver.ts +32 -30
package/dist/v2/run_v2.test.d.ts
CHANGED
|
@@ -1 +1,23 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export declare const hotel_model_const_temp: {
|
|
2
|
+
readonly booking: {
|
|
3
|
+
readonly id: "number";
|
|
4
|
+
readonly bookingGroupID: "number";
|
|
5
|
+
readonly checkInDate: "string";
|
|
6
|
+
readonly checkOutDate: "string";
|
|
7
|
+
readonly checkInTime: "string";
|
|
8
|
+
readonly checkOutTime: "string";
|
|
9
|
+
readonly roomRate: "number";
|
|
10
|
+
readonly extraBedRate: "number";
|
|
11
|
+
readonly roomNumber: "string";
|
|
12
|
+
readonly editTime: "string";
|
|
13
|
+
readonly createTime: "string";
|
|
14
|
+
readonly shiftDate: "string";
|
|
15
|
+
readonly shiftName: "string";
|
|
16
|
+
readonly userName: "string";
|
|
17
|
+
readonly bookingStatus: readonly ["ACTIVE", "CLOSE", "CANCEL", "NO_SHOW"];
|
|
18
|
+
readonly is_specificRoom: "number";
|
|
19
|
+
readonly guestCount: "number";
|
|
20
|
+
readonly reasonToCancel: "string";
|
|
21
|
+
readonly note: "string";
|
|
22
|
+
};
|
|
23
|
+
};
|
package/dist/v2/run_v2.test.js
CHANGED
|
@@ -12,29 +12,111 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
12
12
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
13
|
};
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.hotel_model_const_temp = void 0;
|
|
15
16
|
const express_1 = __importDefault(require("express"));
|
|
16
17
|
const GGExpressV2_1 = __importDefault(require("./GGExpressV2"));
|
|
17
|
-
|
|
18
|
+
exports.hotel_model_const_temp = {
|
|
19
|
+
booking: {
|
|
20
|
+
id: "number",
|
|
21
|
+
bookingGroupID: "number",
|
|
22
|
+
checkInDate: "string",
|
|
23
|
+
checkOutDate: "string",
|
|
24
|
+
checkInTime: "string",
|
|
25
|
+
checkOutTime: "string",
|
|
26
|
+
roomRate: "number",
|
|
27
|
+
extraBedRate: "number",
|
|
28
|
+
roomNumber: "string",
|
|
29
|
+
editTime: "string",
|
|
30
|
+
createTime: "string",
|
|
31
|
+
shiftDate: "string",
|
|
32
|
+
shiftName: "string",
|
|
33
|
+
userName: "string",
|
|
34
|
+
bookingStatus: ["ACTIVE", "CLOSE", "CANCEL", "NO_SHOW"],
|
|
35
|
+
is_specificRoom: "number",
|
|
36
|
+
guestCount: "number",
|
|
37
|
+
reasonToCancel: "string",
|
|
38
|
+
note: "string",
|
|
39
|
+
},
|
|
40
|
+
};
|
|
18
41
|
function run() {
|
|
19
42
|
const app = (0, express_1.default)();
|
|
20
43
|
const ggapp = new GGExpressV2_1.default(app, "hotel", ["./output"]);
|
|
21
44
|
ggapp.get("/api/hotel/users/id", {
|
|
22
45
|
requireParams: {
|
|
23
46
|
id: "number",
|
|
47
|
+
data: exports.hotel_model_const_temp["booking"],
|
|
48
|
+
name: "string",
|
|
49
|
+
status: ["on", "off"],
|
|
24
50
|
},
|
|
25
51
|
responseStructure: {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
52
|
+
x: "string",
|
|
53
|
+
data: [
|
|
54
|
+
{
|
|
55
|
+
zoneID: "number",
|
|
56
|
+
zoneName: "string",
|
|
57
|
+
data: [
|
|
58
|
+
{
|
|
59
|
+
itemID: "number",
|
|
60
|
+
itemEachHotelID: "number",
|
|
61
|
+
itemName: "string",
|
|
62
|
+
requisitionQty: {
|
|
63
|
+
expected: "number",
|
|
64
|
+
actual: "number",
|
|
65
|
+
},
|
|
66
|
+
zoneStockQty: {
|
|
67
|
+
begin: "number",
|
|
68
|
+
end: "number",
|
|
69
|
+
},
|
|
70
|
+
usedQty: "number",
|
|
71
|
+
lossQty: "number",
|
|
72
|
+
damageQty: "number",
|
|
73
|
+
returnQty: {
|
|
74
|
+
expected: "number",
|
|
75
|
+
actual: "number",
|
|
76
|
+
},
|
|
77
|
+
notReturnQty: "number",
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
},
|
|
81
|
+
],
|
|
30
82
|
},
|
|
31
83
|
}, (req, res, next) => {
|
|
32
|
-
|
|
33
|
-
console.log("req.query.id", req.query.id);
|
|
84
|
+
req.query.status === "on";
|
|
34
85
|
return res.json({
|
|
35
86
|
message: "",
|
|
36
87
|
status: "SUCCESS",
|
|
37
|
-
data: {
|
|
88
|
+
data: {
|
|
89
|
+
x: "",
|
|
90
|
+
data: [
|
|
91
|
+
{
|
|
92
|
+
zoneID: 0,
|
|
93
|
+
zoneName: "",
|
|
94
|
+
data: [
|
|
95
|
+
{
|
|
96
|
+
itemID: 0,
|
|
97
|
+
itemEachHotelID: 0,
|
|
98
|
+
itemName: "",
|
|
99
|
+
requisitionQty: {
|
|
100
|
+
actual: 0,
|
|
101
|
+
expected: 0,
|
|
102
|
+
},
|
|
103
|
+
zoneStockQty: {
|
|
104
|
+
begin: 0,
|
|
105
|
+
end: 0,
|
|
106
|
+
},
|
|
107
|
+
usedQty: 0,
|
|
108
|
+
lossQty: 0,
|
|
109
|
+
damageQty: 0,
|
|
110
|
+
returnQty: {
|
|
111
|
+
expected: 0,
|
|
112
|
+
actual: 0,
|
|
113
|
+
},
|
|
114
|
+
notReturnQty: 0,
|
|
115
|
+
},
|
|
116
|
+
],
|
|
117
|
+
},
|
|
118
|
+
],
|
|
119
|
+
},
|
|
38
120
|
});
|
|
39
121
|
});
|
|
40
122
|
ggapp.post("/api/hotel/booking/id", {
|
|
@@ -1,22 +1,14 @@
|
|
|
1
1
|
type BaseType = "string" | "number" | "string[]" | "number[]";
|
|
2
2
|
export type CustomType = BaseType | `${BaseType}?` | `${BaseType}~` | `${BaseType}?~`;
|
|
3
|
-
|
|
4
|
-
[key in string]: CustomType;
|
|
5
|
-
};
|
|
6
|
-
type InputEnum = string[] | number[];
|
|
3
|
+
type InputEnum = readonly string[] | readonly number[];
|
|
7
4
|
export type InputParent = {
|
|
8
|
-
[key in string]: CustomType |
|
|
5
|
+
[key in string]: CustomType | InputParent | InputParent[] | InputEnum;
|
|
9
6
|
};
|
|
10
7
|
type ResolveBase<T extends BaseType> = T extends "string" ? string : T extends "string[]" ? string[] : T extends "number" ? number : T extends "number[]" ? number[] : never;
|
|
11
8
|
export declare const toArray: <T extends InputParent>(input: T) => T[];
|
|
12
9
|
type ResolveType<T> = T extends `${infer B}?~` ? ResolveBase<B & BaseType> | null | undefined : T extends `${infer B}?` ? ResolveBase<B & BaseType> | undefined : T extends `${infer B}~` ? ResolveBase<B & BaseType> | null : ResolveBase<T & BaseType>;
|
|
13
|
-
type
|
|
14
|
-
type
|
|
15
|
-
type convertChildObjet<T> = {
|
|
16
|
-
[K in keyof T]: chooseType<T[K]>;
|
|
17
|
-
};
|
|
18
|
-
type convertObject<T> = T extends object ? convertChildObjet<T> : checkEnum<T>;
|
|
19
|
-
type chooseType<T> = T extends InputEnum ? T[number] : convertObject<T>;
|
|
10
|
+
type checkEnum<T> = T extends InputEnum ? T[number] : ResolveType<T>;
|
|
11
|
+
type chooseType<T> = T extends readonly (string | number)[] ? checkEnum<T> : T extends object ? convertRoot<T> : checkEnum<T>;
|
|
20
12
|
export type convertRoot<T> = {
|
|
21
13
|
[K in keyof T]: chooseType<T[K]>;
|
|
22
14
|
};
|
package/dist/v2/typeResolver.js
CHANGED
|
@@ -5,6 +5,48 @@ const toArray = (input) => {
|
|
|
5
5
|
return [input];
|
|
6
6
|
};
|
|
7
7
|
exports.toArray = toArray;
|
|
8
|
+
// let req2 = {
|
|
9
|
+
// booking: {
|
|
10
|
+
// id: "number",
|
|
11
|
+
// bookingGroupID: "number",
|
|
12
|
+
// checkInDate: "string",
|
|
13
|
+
// checkOutDate: "string",
|
|
14
|
+
// checkInTime: "string",
|
|
15
|
+
// checkOutTime: "string",
|
|
16
|
+
// roomRate: "number",
|
|
17
|
+
// extraBedRate: "number",
|
|
18
|
+
// roomNumber: "string",
|
|
19
|
+
// editTime: "string",
|
|
20
|
+
// createTime: "string",
|
|
21
|
+
// shiftDate: "string",
|
|
22
|
+
// shiftName: "string",
|
|
23
|
+
// userName: "string",
|
|
24
|
+
// bookingStatus: ["ACTIVE", "CLOSE", "CANCEL", "NO_SHOW"],
|
|
25
|
+
// is_specificRoom: "number",
|
|
26
|
+
// guestCount: "number",
|
|
27
|
+
// reasonToCancel: "string",
|
|
28
|
+
// note: "string",
|
|
29
|
+
// },
|
|
30
|
+
// status: ["ACTIVE", "DISABLE"],
|
|
31
|
+
// rooms: toArray({
|
|
32
|
+
// id: "number",
|
|
33
|
+
// status: ["ON", "OFF"],
|
|
34
|
+
// roomNumber: "string",
|
|
35
|
+
// log: toArray({
|
|
36
|
+
// time: "string",
|
|
37
|
+
// logger: [{ info: "string" }],
|
|
38
|
+
// }),
|
|
39
|
+
// }),
|
|
40
|
+
// data: {
|
|
41
|
+
// level_1: {
|
|
42
|
+
// title: "string",
|
|
43
|
+
// level_2: {
|
|
44
|
+
// id: "number",
|
|
45
|
+
// name: "string",
|
|
46
|
+
// },
|
|
47
|
+
// },
|
|
48
|
+
// },
|
|
49
|
+
// } as const satisfies InputParent
|
|
8
50
|
// const data = {} as convertRoot<typeof req2>
|
|
9
51
|
// data.booking.bookingStatus
|
|
10
52
|
// data.status
|
|
@@ -13,3 +55,4 @@ exports.toArray = toArray;
|
|
|
13
55
|
// data.rooms.map((row) => row.status === "OFF")
|
|
14
56
|
// data.data.level_1.level_2.id
|
|
15
57
|
// data.booking.createTime
|
|
58
|
+
// req2.data.level_1.level_2
|
package/package.json
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Method } from "./GGExpressV2"
|
|
2
|
-
import {
|
|
3
|
-
import fs from "fs"
|
|
2
|
+
import { InputParent } from "./typeResolver"
|
|
4
3
|
type routeList = {
|
|
5
4
|
method: Method
|
|
6
5
|
url: string
|
|
@@ -91,7 +90,7 @@ function parentInputToCode(data: InputParent) {
|
|
|
91
90
|
.join(",")}] `
|
|
92
91
|
// nest or input nest
|
|
93
92
|
else if (typeof target[0] === "object")
|
|
94
|
-
for (const row of target as
|
|
93
|
+
for (const row of target as InputParent[]) {
|
|
95
94
|
result = result + " " + recursiveExtract(row, parentKeyName) + "[] "
|
|
96
95
|
}
|
|
97
96
|
}
|
package/src/v2/run_v2.test.ts
CHANGED
|
@@ -1,7 +1,32 @@
|
|
|
1
1
|
import express, { Express } from "express"
|
|
2
2
|
import GGExpressV2 from "./GGExpressV2"
|
|
3
|
-
import { toArray } from "./typeResolver"
|
|
3
|
+
import { InputParent, toArray } from "./typeResolver"
|
|
4
4
|
import { GGApi_v2 } from "./output/apiConnector_hotel_v2"
|
|
5
|
+
|
|
6
|
+
export const hotel_model_const_temp = {
|
|
7
|
+
booking: {
|
|
8
|
+
id: "number",
|
|
9
|
+
bookingGroupID: "number",
|
|
10
|
+
checkInDate: "string",
|
|
11
|
+
checkOutDate: "string",
|
|
12
|
+
checkInTime: "string",
|
|
13
|
+
checkOutTime: "string",
|
|
14
|
+
roomRate: "number",
|
|
15
|
+
extraBedRate: "number",
|
|
16
|
+
roomNumber: "string",
|
|
17
|
+
editTime: "string",
|
|
18
|
+
createTime: "string",
|
|
19
|
+
shiftDate: "string",
|
|
20
|
+
shiftName: "string",
|
|
21
|
+
userName: "string",
|
|
22
|
+
bookingStatus: ["ACTIVE", "CLOSE", "CANCEL", "NO_SHOW"],
|
|
23
|
+
is_specificRoom: "number",
|
|
24
|
+
guestCount: "number",
|
|
25
|
+
reasonToCancel: "string",
|
|
26
|
+
note: "string",
|
|
27
|
+
},
|
|
28
|
+
} as const
|
|
29
|
+
|
|
5
30
|
function run() {
|
|
6
31
|
const app = express()
|
|
7
32
|
const ggapp = new GGExpressV2<"hotel">(app, "hotel", ["./output"])
|
|
@@ -10,22 +35,80 @@ function run() {
|
|
|
10
35
|
{
|
|
11
36
|
requireParams: {
|
|
12
37
|
id: "number",
|
|
38
|
+
data: hotel_model_const_temp["booking"],
|
|
39
|
+
name: "string",
|
|
40
|
+
status: ["on", "off"],
|
|
13
41
|
},
|
|
14
42
|
responseStructure: {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
43
|
+
x: "string",
|
|
44
|
+
data: [
|
|
45
|
+
{
|
|
46
|
+
zoneID: "number",
|
|
47
|
+
zoneName: "string",
|
|
48
|
+
data: [
|
|
49
|
+
{
|
|
50
|
+
itemID: "number",
|
|
51
|
+
itemEachHotelID: "number",
|
|
52
|
+
itemName: "string",
|
|
53
|
+
requisitionQty: {
|
|
54
|
+
expected: "number",
|
|
55
|
+
actual: "number",
|
|
56
|
+
},
|
|
57
|
+
zoneStockQty: {
|
|
58
|
+
begin: "number",
|
|
59
|
+
end: "number",
|
|
60
|
+
},
|
|
61
|
+
usedQty: "number",
|
|
62
|
+
lossQty: "number",
|
|
63
|
+
damageQty: "number",
|
|
64
|
+
returnQty: {
|
|
65
|
+
expected: "number",
|
|
66
|
+
actual: "number",
|
|
67
|
+
},
|
|
68
|
+
notReturnQty: "number",
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
},
|
|
72
|
+
],
|
|
19
73
|
},
|
|
20
74
|
},
|
|
21
75
|
(req, res, next) => {
|
|
22
|
-
|
|
23
|
-
console.log("req.query.id", req.query.id)
|
|
24
|
-
|
|
76
|
+
req.query.status === "on"
|
|
25
77
|
return res.json({
|
|
26
78
|
message: "",
|
|
27
79
|
status: "SUCCESS",
|
|
28
|
-
data: {
|
|
80
|
+
data: {
|
|
81
|
+
x: "",
|
|
82
|
+
data: [
|
|
83
|
+
{
|
|
84
|
+
zoneID: 0,
|
|
85
|
+
zoneName: "",
|
|
86
|
+
data: [
|
|
87
|
+
{
|
|
88
|
+
itemID: 0,
|
|
89
|
+
itemEachHotelID: 0,
|
|
90
|
+
itemName: "",
|
|
91
|
+
requisitionQty: {
|
|
92
|
+
actual: 0,
|
|
93
|
+
expected: 0,
|
|
94
|
+
},
|
|
95
|
+
zoneStockQty: {
|
|
96
|
+
begin: 0,
|
|
97
|
+
end: 0,
|
|
98
|
+
},
|
|
99
|
+
usedQty: 0,
|
|
100
|
+
lossQty: 0,
|
|
101
|
+
damageQty: 0,
|
|
102
|
+
returnQty: {
|
|
103
|
+
expected: 0,
|
|
104
|
+
actual: 0,
|
|
105
|
+
},
|
|
106
|
+
notReturnQty: 0,
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
},
|
|
110
|
+
],
|
|
111
|
+
},
|
|
29
112
|
})
|
|
30
113
|
}
|
|
31
114
|
)
|
package/src/v2/typeResolver.ts
CHANGED
|
@@ -5,13 +5,15 @@ export type CustomType =
|
|
|
5
5
|
| `${BaseType}~`
|
|
6
6
|
| `${BaseType}?~`
|
|
7
7
|
|
|
8
|
-
export type InputNest = { [key in string]: CustomType }
|
|
9
|
-
|
|
8
|
+
// export type InputNest = { [key in string]: CustomType }
|
|
9
|
+
|
|
10
|
+
type InputEnum = readonly string[] | readonly number[]
|
|
11
|
+
// type InputEnum = readonly (string | number)[]
|
|
10
12
|
export type InputParent = {
|
|
11
13
|
[key in string]:
|
|
12
14
|
| CustomType
|
|
13
|
-
| InputNest
|
|
14
|
-
| InputNest[]
|
|
15
|
+
// | InputNest
|
|
16
|
+
// | InputNest[]
|
|
15
17
|
| InputParent
|
|
16
18
|
| InputParent[]
|
|
17
19
|
| InputEnum
|
|
@@ -30,6 +32,31 @@ export const toArray = <T extends InputParent>(input: T) => {
|
|
|
30
32
|
return [input]
|
|
31
33
|
}
|
|
32
34
|
|
|
35
|
+
type ResolveType<T> =
|
|
36
|
+
// both null + undefined
|
|
37
|
+
T extends `${infer B}?~`
|
|
38
|
+
? ResolveBase<B & BaseType> | null | undefined
|
|
39
|
+
: // undefined only
|
|
40
|
+
T extends `${infer B}?`
|
|
41
|
+
? ResolveBase<B & BaseType> | undefined
|
|
42
|
+
: // null only
|
|
43
|
+
T extends `${infer B}~`
|
|
44
|
+
? ResolveBase<B & BaseType> | null
|
|
45
|
+
: // plain primitive
|
|
46
|
+
ResolveBase<T & BaseType>
|
|
47
|
+
|
|
48
|
+
type checkEnum<T> = T extends InputEnum ? T[number] : ResolveType<T>
|
|
49
|
+
|
|
50
|
+
type chooseType<T> = T extends readonly (string | number)[]
|
|
51
|
+
? checkEnum<T>
|
|
52
|
+
: T extends object
|
|
53
|
+
? convertRoot<T>
|
|
54
|
+
: checkEnum<T>
|
|
55
|
+
|
|
56
|
+
export type convertRoot<T> = {
|
|
57
|
+
[K in keyof T]: chooseType<T[K]>
|
|
58
|
+
}
|
|
59
|
+
|
|
33
60
|
// let req2 = {
|
|
34
61
|
// booking: {
|
|
35
62
|
// id: "number",
|
|
@@ -73,32 +100,6 @@ export const toArray = <T extends InputParent>(input: T) => {
|
|
|
73
100
|
// },
|
|
74
101
|
// },
|
|
75
102
|
// } as const satisfies InputParent
|
|
76
|
-
|
|
77
|
-
type ResolveType<T> =
|
|
78
|
-
// both null + undefined
|
|
79
|
-
T extends `${infer B}?~`
|
|
80
|
-
? ResolveBase<B & BaseType> | null | undefined
|
|
81
|
-
: // undefined only
|
|
82
|
-
T extends `${infer B}?`
|
|
83
|
-
? ResolveBase<B & BaseType> | undefined
|
|
84
|
-
: // null only
|
|
85
|
-
T extends `${infer B}~`
|
|
86
|
-
? ResolveBase<B & BaseType> | null
|
|
87
|
-
: // plain primitive
|
|
88
|
-
ResolveBase<T & BaseType>
|
|
89
|
-
|
|
90
|
-
type convertNest<T> = ResolveType<T>
|
|
91
|
-
|
|
92
|
-
type checkEnum<T> = T extends InputEnum ? T[number] : convertNest<T>
|
|
93
|
-
type convertChildObjet<T> = {
|
|
94
|
-
[K in keyof T]: chooseType<T[K]>
|
|
95
|
-
}
|
|
96
|
-
type convertObject<T> = T extends object ? convertChildObjet<T> : checkEnum<T>
|
|
97
|
-
type chooseType<T> = T extends InputEnum ? T[number] : convertObject<T>
|
|
98
|
-
export type convertRoot<T> = {
|
|
99
|
-
[K in keyof T]: chooseType<T[K]>
|
|
100
|
-
}
|
|
101
|
-
|
|
102
103
|
// const data = {} as convertRoot<typeof req2>
|
|
103
104
|
|
|
104
105
|
// data.booking.bookingStatus
|
|
@@ -108,3 +109,4 @@ export type convertRoot<T> = {
|
|
|
108
109
|
// data.rooms.map((row) => row.status === "OFF")
|
|
109
110
|
// data.data.level_1.level_2.id
|
|
110
111
|
// data.booking.createTime
|
|
112
|
+
// req2.data.level_1.level_2
|