gg-express 1.0.88 → 1.0.91
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/GGExpress.d.ts +2 -1
- package/dist/hotel_model_const_temp.d.ts +23 -0
- package/dist/hotel_model_const_temp.js +26 -0
- package/dist/run.test.js +3 -2
- package/dist/v2/run_v2.test.js +63 -11
- package/dist/v2/typeResolver.d.ts +3 -11
- package/dist/v2/typeResolver.js +43 -0
- package/package.json +1 -1
- package/src/GGExpress.ts +2 -0
- package/src/hotel_model_const_temp.ts +23 -0
- package/src/run.test.ts +3 -2
- package/src/v2/run_v2.test.ts +64 -11
- package/src/v2/typeResolver.ts +29 -37
package/dist/GGExpress.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { NextFunction, Request, Response } from "express";
|
|
2
2
|
import Express from "express-serve-static-core";
|
|
3
3
|
type Unarray<T> = T extends (infer U)[] ? U : T;
|
|
4
|
-
type
|
|
4
|
+
type InputEnum = readonly string[] | readonly number[];
|
|
5
|
+
type paramType = "number" | "string" | "any" | string[] | number[] | InputEnum;
|
|
5
6
|
interface responseStructure {
|
|
6
7
|
parameter: {
|
|
7
8
|
[key: string]: "number" | "string";
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hotel_model_const_temp = void 0;
|
|
4
|
+
exports.hotel_model_const_temp = {
|
|
5
|
+
booking: {
|
|
6
|
+
id: "number",
|
|
7
|
+
bookingGroupID: "number",
|
|
8
|
+
checkInDate: "string",
|
|
9
|
+
checkOutDate: "string",
|
|
10
|
+
checkInTime: "string",
|
|
11
|
+
checkOutTime: "string",
|
|
12
|
+
roomRate: "number",
|
|
13
|
+
extraBedRate: "number",
|
|
14
|
+
roomNumber: "string",
|
|
15
|
+
editTime: "string",
|
|
16
|
+
createTime: "string",
|
|
17
|
+
shiftDate: "string",
|
|
18
|
+
shiftName: "string",
|
|
19
|
+
userName: "string",
|
|
20
|
+
bookingStatus: ["ACTIVE", "CLOSE", "CANCEL", "NO_SHOW"],
|
|
21
|
+
is_specificRoom: "number",
|
|
22
|
+
guestCount: "number",
|
|
23
|
+
reasonToCancel: "string",
|
|
24
|
+
note: "string",
|
|
25
|
+
},
|
|
26
|
+
};
|
package/dist/run.test.js
CHANGED
|
@@ -14,6 +14,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
const GGExpress_1 = __importDefault(require("./GGExpress"));
|
|
16
16
|
const express_1 = __importDefault(require("express"));
|
|
17
|
+
const hotel_model_const_temp_1 = require("./hotel_model_const_temp");
|
|
17
18
|
function run() {
|
|
18
19
|
const app = (0, express_1.default)();
|
|
19
20
|
const ggapp = new GGExpress_1.default(app, "hotel", ["./"]);
|
|
@@ -21,7 +22,7 @@ function run() {
|
|
|
21
22
|
requireParams: {
|
|
22
23
|
parameter: { files: "string[]" },
|
|
23
24
|
dataType: "arrayObject",
|
|
24
|
-
structure:
|
|
25
|
+
structure: hotel_model_const_temp_1.hotel_model_const_temp["booking"],
|
|
25
26
|
},
|
|
26
27
|
responseStructure: {
|
|
27
28
|
parameter: { numberOfPeople: "number", itemName: "string" },
|
|
@@ -32,7 +33,7 @@ function run() {
|
|
|
32
33
|
},
|
|
33
34
|
},
|
|
34
35
|
}, (req, res, next) => {
|
|
35
|
-
req.query.data.data.forEach((row) => row.
|
|
36
|
+
req.query.data.data.forEach((row) => row.checkInDate === "A");
|
|
36
37
|
console.log(req.query);
|
|
37
38
|
return res.json({
|
|
38
39
|
message: "",
|
package/dist/v2/run_v2.test.js
CHANGED
|
@@ -15,7 +15,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
15
15
|
exports.hotel_model_const_temp = void 0;
|
|
16
16
|
const express_1 = __importDefault(require("express"));
|
|
17
17
|
const GGExpressV2_1 = __importDefault(require("./GGExpressV2"));
|
|
18
|
-
const typeResolver_1 = require("./typeResolver");
|
|
19
18
|
exports.hotel_model_const_temp = {
|
|
20
19
|
booking: {
|
|
21
20
|
id: "number",
|
|
@@ -50,21 +49,74 @@ function run() {
|
|
|
50
49
|
status: ["on", "off"],
|
|
51
50
|
},
|
|
52
51
|
responseStructure: {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
+
],
|
|
57
82
|
},
|
|
58
83
|
}, (req, res, next) => {
|
|
59
|
-
|
|
60
|
-
req.query.name;
|
|
61
|
-
console.log("req.query", req.query);
|
|
62
|
-
console.log("req.query.id", req.query.id);
|
|
63
|
-
// req.query.data.bookingStatus
|
|
84
|
+
req.query.status === "on";
|
|
64
85
|
return res.json({
|
|
65
86
|
message: "",
|
|
66
87
|
status: "SUCCESS",
|
|
67
|
-
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
|
+
},
|
|
68
120
|
});
|
|
69
121
|
});
|
|
70
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 = readonly (string | number)[];
|
|
3
|
+
type InputEnum = readonly string[] | readonly number[];
|
|
7
4
|
export type InputParent = {
|
|
8
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 readonly any[] ? checkEnum<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
package/src/GGExpress.ts
CHANGED
|
@@ -7,6 +7,7 @@ import { removeDuplicates } from "./helperFunction"
|
|
|
7
7
|
|
|
8
8
|
type Unarray<T> = T extends (infer U)[] ? U : T
|
|
9
9
|
type AsConstArray<T extends readonly any[]> = [...T]
|
|
10
|
+
type InputEnum = readonly string[] | readonly number[]
|
|
10
11
|
type paramType =
|
|
11
12
|
| "number"
|
|
12
13
|
| "string"
|
|
@@ -15,6 +16,7 @@ type paramType =
|
|
|
15
16
|
// | AsConstArray<Array<number>>
|
|
16
17
|
| string[]
|
|
17
18
|
| number[]
|
|
19
|
+
| InputEnum
|
|
18
20
|
interface responseStructure {
|
|
19
21
|
parameter: { [key: string]: "number" | "string" }
|
|
20
22
|
dataType: "singleObject" | "arrayObject"
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export const hotel_model_const_temp = {
|
|
2
|
+
booking: {
|
|
3
|
+
id: "number",
|
|
4
|
+
bookingGroupID: "number",
|
|
5
|
+
checkInDate: "string",
|
|
6
|
+
checkOutDate: "string",
|
|
7
|
+
checkInTime: "string",
|
|
8
|
+
checkOutTime: "string",
|
|
9
|
+
roomRate: "number",
|
|
10
|
+
extraBedRate: "number",
|
|
11
|
+
roomNumber: "string",
|
|
12
|
+
editTime: "string",
|
|
13
|
+
createTime: "string",
|
|
14
|
+
shiftDate: "string",
|
|
15
|
+
shiftName: "string",
|
|
16
|
+
userName: "string",
|
|
17
|
+
bookingStatus: ["ACTIVE", "CLOSE", "CANCEL", "NO_SHOW"],
|
|
18
|
+
is_specificRoom: "number",
|
|
19
|
+
guestCount: "number",
|
|
20
|
+
reasonToCancel: "string",
|
|
21
|
+
note: "string",
|
|
22
|
+
},
|
|
23
|
+
} as const
|
package/src/run.test.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import GGExpress from "./GGExpress"
|
|
2
2
|
import express, { Express } from "express"
|
|
3
|
+
import { hotel_model_const_temp } from "./hotel_model_const_temp"
|
|
3
4
|
function run() {
|
|
4
5
|
const app = express()
|
|
5
6
|
const ggapp = new GGExpress<"hotel">(app, "hotel", ["./"])
|
|
@@ -9,7 +10,7 @@ function run() {
|
|
|
9
10
|
requireParams: {
|
|
10
11
|
parameter: { files: "string[]" },
|
|
11
12
|
dataType: "arrayObject",
|
|
12
|
-
structure:
|
|
13
|
+
structure: hotel_model_const_temp["booking"],
|
|
13
14
|
},
|
|
14
15
|
responseStructure: {
|
|
15
16
|
parameter: { numberOfPeople: "number", itemName: "string" },
|
|
@@ -21,7 +22,7 @@ function run() {
|
|
|
21
22
|
},
|
|
22
23
|
},
|
|
23
24
|
(req, res, next) => {
|
|
24
|
-
req.query.data.data.forEach((row) => row.
|
|
25
|
+
req.query.data.data.forEach((row) => row.checkInDate === "A")
|
|
25
26
|
console.log(req.query)
|
|
26
27
|
return res.json({
|
|
27
28
|
message: "",
|
package/src/v2/run_v2.test.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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
5
|
|
|
6
6
|
export const hotel_model_const_temp = {
|
|
@@ -40,22 +40,75 @@ function run() {
|
|
|
40
40
|
status: ["on", "off"],
|
|
41
41
|
},
|
|
42
42
|
responseStructure: {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
+
],
|
|
47
73
|
},
|
|
48
74
|
},
|
|
49
75
|
(req, res, next) => {
|
|
50
|
-
|
|
51
|
-
req.query.name
|
|
52
|
-
console.log("req.query", req.query)
|
|
53
|
-
console.log("req.query.id", req.query.id)
|
|
54
|
-
// req.query.data.bookingStatus
|
|
76
|
+
req.query.status === "on"
|
|
55
77
|
return res.json({
|
|
56
78
|
message: "",
|
|
57
79
|
status: "SUCCESS",
|
|
58
|
-
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
|
+
},
|
|
59
112
|
})
|
|
60
113
|
}
|
|
61
114
|
)
|
package/src/v2/typeResolver.ts
CHANGED
|
@@ -5,11 +5,10 @@ export type CustomType =
|
|
|
5
5
|
| `${BaseType}~`
|
|
6
6
|
| `${BaseType}?~`
|
|
7
7
|
|
|
8
|
-
export type InputNest = { [key in string]: CustomType }
|
|
8
|
+
// export type InputNest = { [key in string]: CustomType }
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
// type InputEnum = readonly string
|
|
12
|
-
type InputEnum = readonly (string | number)[]
|
|
10
|
+
type InputEnum = readonly string[] | readonly number[]
|
|
11
|
+
// type InputEnum = readonly (string | number)[]
|
|
13
12
|
export type InputParent = {
|
|
14
13
|
[key in string]:
|
|
15
14
|
| CustomType
|
|
@@ -33,6 +32,31 @@ export const toArray = <T extends InputParent>(input: T) => {
|
|
|
33
32
|
return [input]
|
|
34
33
|
}
|
|
35
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
|
+
|
|
36
60
|
// let req2 = {
|
|
37
61
|
// booking: {
|
|
38
62
|
// id: "number",
|
|
@@ -76,39 +100,6 @@ export const toArray = <T extends InputParent>(input: T) => {
|
|
|
76
100
|
// },
|
|
77
101
|
// },
|
|
78
102
|
// } as const satisfies InputParent
|
|
79
|
-
|
|
80
|
-
type ResolveType<T> =
|
|
81
|
-
// both null + undefined
|
|
82
|
-
T extends `${infer B}?~`
|
|
83
|
-
? ResolveBase<B & BaseType> | null | undefined
|
|
84
|
-
: // undefined only
|
|
85
|
-
T extends `${infer B}?`
|
|
86
|
-
? ResolveBase<B & BaseType> | undefined
|
|
87
|
-
: // null only
|
|
88
|
-
T extends `${infer B}~`
|
|
89
|
-
? ResolveBase<B & BaseType> | null
|
|
90
|
-
: // plain primitive
|
|
91
|
-
ResolveBase<T & BaseType>
|
|
92
|
-
|
|
93
|
-
type convertNest<T> = ResolveType<T>
|
|
94
|
-
|
|
95
|
-
type checkEnum<T> = T extends InputEnum ? T[number] : convertNest<T>
|
|
96
|
-
type convertChildObjet<T> = {
|
|
97
|
-
[K in keyof T]: chooseType<T[K]>
|
|
98
|
-
}
|
|
99
|
-
// type convertObject<T> = T extends object ? convertChildObjet<T> : checkEnum<T>
|
|
100
|
-
|
|
101
|
-
type convertObject<T> = T extends readonly any[]
|
|
102
|
-
? checkEnum<T>
|
|
103
|
-
: T extends object
|
|
104
|
-
? convertChildObjet<T>
|
|
105
|
-
: checkEnum<T>
|
|
106
|
-
|
|
107
|
-
type chooseType<T> = T extends InputEnum ? T[number] : convertObject<T>
|
|
108
|
-
export type convertRoot<T> = {
|
|
109
|
-
[K in keyof T]: chooseType<T[K]>
|
|
110
|
-
}
|
|
111
|
-
|
|
112
103
|
// const data = {} as convertRoot<typeof req2>
|
|
113
104
|
|
|
114
105
|
// data.booking.bookingStatus
|
|
@@ -118,3 +109,4 @@ export type convertRoot<T> = {
|
|
|
118
109
|
// data.rooms.map((row) => row.status === "OFF")
|
|
119
110
|
// data.data.level_1.level_2.id
|
|
120
111
|
// data.booking.createTime
|
|
112
|
+
// req2.data.level_1.level_2
|