gg-express 1.0.92 → 1.0.97
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/GGExpressV2.d.ts +10 -10
- package/dist/v2/generateStaticRouteFileV2.d.ts +3 -3
- package/dist/v2/test_typeResolver.d.ts +16 -0
- package/dist/v2/test_typeResolver.js +33 -0
- package/dist/v2/typeResolver.d.ts +10 -10
- package/dist/v2/typeResolver.js +0 -51
- package/package.json +1 -1
- package/src/v2/GGExpressV2.ts +16 -16
- package/src/v2/generateStaticRouteFileV2.ts +6 -6
- package/src/v2/run_v2.test.ts +2 -3
- package/src/v2/test_typeResolver.ts +44 -0
- package/src/v2/typeResolver.ts +25 -80
package/dist/v2/GGExpressV2.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { NextFunction, Request, Response } from "express";
|
|
2
2
|
import Express from "express-serve-static-core";
|
|
3
|
-
import {
|
|
3
|
+
import { TypeResolve, ConstSchemaType } from "./typeResolver";
|
|
4
4
|
export type Method = "get" | "post" | "put" | "delete";
|
|
5
|
-
type MyRequest<M extends Method, RQ extends
|
|
6
|
-
type MyRequestQuery<T extends
|
|
7
|
-
type MyRequestBody<T extends
|
|
8
|
-
type MyResponse<T extends
|
|
5
|
+
type MyRequest<M extends Method, RQ extends ConstSchemaType> = M extends "get" ? TypeResolve<MyRequestQuery<RQ>> : TypeResolve<MyRequestBody<RQ>>;
|
|
6
|
+
type MyRequestQuery<T extends ConstSchemaType> = Request<{}, {}, {}, T, {}>;
|
|
7
|
+
type MyRequestBody<T extends ConstSchemaType> = Request<{}, {}, T, {}, {}>;
|
|
8
|
+
type MyResponse<T extends ConstSchemaType> = Response<{
|
|
9
9
|
status: "SUCCESS" | "ERROR" | "SERVER_ERROR";
|
|
10
10
|
message: string;
|
|
11
|
-
data:
|
|
11
|
+
data: TypeResolve<T>;
|
|
12
12
|
}>;
|
|
13
13
|
export default class GGExpressV2<appName extends string> {
|
|
14
14
|
express: Express.Express;
|
|
@@ -16,19 +16,19 @@ export default class GGExpressV2<appName extends string> {
|
|
|
16
16
|
appName: string;
|
|
17
17
|
constructor(app: Express.Express, appName: appName, outputPath: string[]);
|
|
18
18
|
private rootMethod;
|
|
19
|
-
get<RQ extends
|
|
19
|
+
get<RQ extends ConstSchemaType, RS extends ConstSchemaType>(url: `/api/${appName | "seed"}/${string}` | `/api/${appName | "seed"}/${string}`[], options: {
|
|
20
20
|
requireParams: RQ;
|
|
21
21
|
responseStructure: RS;
|
|
22
22
|
}, ...middlewares: Array<(req: MyRequest<"get", RQ>, res: MyResponse<RS>, next: NextFunction) => any>): Express.Express;
|
|
23
|
-
post<RQ extends
|
|
23
|
+
post<RQ extends ConstSchemaType, RS extends ConstSchemaType>(url: `/api/${appName | "seed"}/${string}` | `/api/${appName | "seed"}/${string}`[], options: {
|
|
24
24
|
requireParams: RQ;
|
|
25
25
|
responseStructure: RS;
|
|
26
26
|
}, ...middlewares: Array<(req: MyRequest<"post", RQ>, res: MyResponse<RS>, next: NextFunction) => any>): Express.Express;
|
|
27
|
-
put<RQ extends
|
|
27
|
+
put<RQ extends ConstSchemaType, RS extends ConstSchemaType>(url: `/api/${appName | "seed"}/${string}` | `/api/${appName | "seed"}/${string}`[], options: {
|
|
28
28
|
requireParams: RQ;
|
|
29
29
|
responseStructure: RS;
|
|
30
30
|
}, ...middlewares: Array<(req: MyRequest<"put", RQ>, res: MyResponse<RS>, next: NextFunction) => any>): Express.Express;
|
|
31
|
-
delete<RQ extends
|
|
31
|
+
delete<RQ extends ConstSchemaType, RS extends ConstSchemaType>(url: `/api/${appName | "seed"}/${string}` | `/api/${appName | "seed"}/${string}`[], options: {
|
|
32
32
|
requireParams: RQ;
|
|
33
33
|
responseStructure: RS;
|
|
34
34
|
}, ...middlewares: Array<(req: MyRequest<"delete", RQ>, res: MyResponse<RS>, next: NextFunction) => any>): Express.Express;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Method } from "./GGExpressV2";
|
|
2
|
-
import {
|
|
2
|
+
import { ConstSchemaType } from "./typeResolver";
|
|
3
3
|
type routeList = {
|
|
4
4
|
method: Method;
|
|
5
5
|
url: string;
|
|
6
|
-
requireParams:
|
|
7
|
-
responseStructure:
|
|
6
|
+
requireParams: ConstSchemaType;
|
|
7
|
+
responseStructure: ConstSchemaType;
|
|
8
8
|
};
|
|
9
9
|
type PrepareRouteStucture = {
|
|
10
10
|
[K in Method]: {
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { TypeResolve } from "./typeResolver";
|
|
2
|
+
export declare const ReturnOfCalculateEachDateConst: {
|
|
3
|
+
readonly itemDetailData: {
|
|
4
|
+
readonly itemID: "number";
|
|
5
|
+
readonly zoneID: "number";
|
|
6
|
+
}[];
|
|
7
|
+
readonly itemDetailData_v2: [{
|
|
8
|
+
readonly id: "number";
|
|
9
|
+
}];
|
|
10
|
+
readonly bool: "boolean";
|
|
11
|
+
readonly requisitionQuantity: "number";
|
|
12
|
+
readonly usedQuantity: "number";
|
|
13
|
+
readonly date: "string";
|
|
14
|
+
readonly itemID: "number";
|
|
15
|
+
};
|
|
16
|
+
export type ReturnOfCalculateEachDate = TypeResolve<typeof ReturnOfCalculateEachDateConst>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ReturnOfCalculateEachDateConst = void 0;
|
|
4
|
+
const typeResolver_1 = require("./typeResolver");
|
|
5
|
+
const itemDetailDataConst = {
|
|
6
|
+
itemID: "number",
|
|
7
|
+
zoneID: "number",
|
|
8
|
+
};
|
|
9
|
+
const QuantityTypeConst = {
|
|
10
|
+
requisitionQuantity: "number",
|
|
11
|
+
usedQuantity: "number",
|
|
12
|
+
};
|
|
13
|
+
exports.ReturnOfCalculateEachDateConst = Object.assign(Object.assign({ date: "string", itemID: "number" }, QuantityTypeConst), { itemDetailData: (0, typeResolver_1.toArray)(itemDetailDataConst), itemDetailData_v2: [{ id: "number" }], bool: "boolean" });
|
|
14
|
+
const temp = {
|
|
15
|
+
bool: true,
|
|
16
|
+
itemDetailData: (0, typeResolver_1.toArray)({
|
|
17
|
+
itemID: 0,
|
|
18
|
+
zoneID: 0,
|
|
19
|
+
}),
|
|
20
|
+
itemDetailData_v2: [
|
|
21
|
+
{
|
|
22
|
+
id: 1,
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
id: 0,
|
|
26
|
+
},
|
|
27
|
+
],
|
|
28
|
+
requisitionQuantity: 0,
|
|
29
|
+
usedQuantity: 0,
|
|
30
|
+
date: "",
|
|
31
|
+
itemID: 0,
|
|
32
|
+
};
|
|
33
|
+
console.log(temp);
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
type
|
|
2
|
-
|
|
1
|
+
type Unarray<T> = T extends (infer U)[] ? U : T;
|
|
2
|
+
type BaseType = "string" | "number" | "boolean" | "string[]" | "number[]" | "boolean[]";
|
|
3
|
+
type CustomType = BaseType | `${BaseType}?` | `${BaseType}~` | `${BaseType}?~`;
|
|
3
4
|
type InputEnum = readonly string[] | readonly number[];
|
|
4
|
-
export type
|
|
5
|
-
[key in string]: CustomType |
|
|
5
|
+
export type ConstSchemaType = {
|
|
6
|
+
[key in string]: CustomType | ConstSchemaType | ConstSchemaType[] | InputEnum;
|
|
6
7
|
};
|
|
7
|
-
type ResolveBase<T extends BaseType> = T extends "string" ? string : T extends "string[]" ? string[] : T extends "number" ? number : T extends "number[]" ? number[] : never;
|
|
8
|
-
export declare const toArray: <T
|
|
9
|
-
type
|
|
10
|
-
type
|
|
11
|
-
type
|
|
12
|
-
export type convertRoot<T> = {
|
|
8
|
+
type ResolveBase<T extends BaseType> = T extends "string" ? string : T extends "string[]" ? string[] : T extends "number" ? number : T extends "number[]" ? number[] : T extends "boolean" ? boolean : T extends "boolean[]" ? boolean[] : never;
|
|
9
|
+
export declare const toArray: <T>(input: T) => T[];
|
|
10
|
+
type ResolveExtraType<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>;
|
|
11
|
+
type chooseType<T> = T extends InputEnum ? T[number] : T extends any[] ? chooseType<Unarray<T>>[] : T extends object ? TypeResolve<T> : ResolveExtraType<T>;
|
|
12
|
+
export type TypeResolve<T> = {
|
|
13
13
|
[K in keyof T]: chooseType<T[K]>;
|
|
14
14
|
};
|
|
15
15
|
export {};
|
package/dist/v2/typeResolver.js
CHANGED
|
@@ -5,54 +5,3 @@ 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
|
|
50
|
-
// const data = {} as convertRoot<typeof req2>
|
|
51
|
-
// data.booking.bookingStatus
|
|
52
|
-
// data.status
|
|
53
|
-
// const id = data.booking.id
|
|
54
|
-
// const roomNumber = data.booking.bookingStatus === data.booking.bookingStatus
|
|
55
|
-
// data.rooms.map((row) => row.status === "OFF")
|
|
56
|
-
// data.data.level_1.level_2.id
|
|
57
|
-
// data.booking.createTime
|
|
58
|
-
// req2.data.level_1.level_2
|
package/package.json
CHANGED
package/src/v2/GGExpressV2.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { NextFunction, Request, Response } from "express"
|
|
2
2
|
import Express from "express-serve-static-core"
|
|
3
3
|
import fs from "fs"
|
|
4
|
-
import {
|
|
4
|
+
import { TypeResolve, ConstSchemaType } from "./typeResolver"
|
|
5
5
|
import { generateStaticRouteFileV2 } from "./generateStaticRouteFileV2"
|
|
6
6
|
import path from "path"
|
|
7
7
|
import { generateGGApi_v2 } from "./generateGGApi_v2"
|
|
@@ -9,26 +9,26 @@ import { generateGGApi_v2 } from "./generateGGApi_v2"
|
|
|
9
9
|
type Unarray<T> = T extends (infer U)[] ? U : T
|
|
10
10
|
export type Method = "get" | "post" | "put" | "delete"
|
|
11
11
|
|
|
12
|
-
type MyRequest<M extends Method, RQ extends
|
|
12
|
+
type MyRequest<M extends Method, RQ extends ConstSchemaType> = M extends "get"
|
|
13
13
|
? //get
|
|
14
|
-
|
|
14
|
+
TypeResolve<MyRequestQuery<RQ>>
|
|
15
15
|
: // post, put, delete
|
|
16
|
-
|
|
16
|
+
TypeResolve<MyRequestBody<RQ>>
|
|
17
17
|
|
|
18
|
-
type MyRequestQuery<T extends
|
|
19
|
-
type MyRequestBody<T extends
|
|
18
|
+
type MyRequestQuery<T extends ConstSchemaType> = Request<{}, {}, {}, T, {}>
|
|
19
|
+
type MyRequestBody<T extends ConstSchemaType> = Request<{}, {}, T, {}, {}>
|
|
20
20
|
|
|
21
|
-
type MyResponse<T extends
|
|
21
|
+
type MyResponse<T extends ConstSchemaType> = Response<{
|
|
22
22
|
status: "SUCCESS" | "ERROR" | "SERVER_ERROR"
|
|
23
23
|
message: string
|
|
24
|
-
data:
|
|
24
|
+
data: TypeResolve<T>
|
|
25
25
|
}>
|
|
26
26
|
|
|
27
27
|
const myExpressRouteList: {
|
|
28
28
|
method: "get" | "post" | "put" | "delete"
|
|
29
29
|
url: string
|
|
30
|
-
requireParams:
|
|
31
|
-
responseStructure:
|
|
30
|
+
requireParams: ConstSchemaType
|
|
31
|
+
responseStructure: ConstSchemaType
|
|
32
32
|
}[] = []
|
|
33
33
|
|
|
34
34
|
export default class GGExpressV2<appName extends string> {
|
|
@@ -43,8 +43,8 @@ export default class GGExpressV2<appName extends string> {
|
|
|
43
43
|
|
|
44
44
|
private rootMethod<
|
|
45
45
|
M extends Method,
|
|
46
|
-
RQ extends
|
|
47
|
-
RS extends
|
|
46
|
+
RQ extends ConstSchemaType,
|
|
47
|
+
RS extends ConstSchemaType
|
|
48
48
|
>(
|
|
49
49
|
method: M,
|
|
50
50
|
url: string | string[],
|
|
@@ -94,7 +94,7 @@ export default class GGExpressV2<appName extends string> {
|
|
|
94
94
|
)
|
|
95
95
|
)
|
|
96
96
|
}
|
|
97
|
-
get<RQ extends
|
|
97
|
+
get<RQ extends ConstSchemaType, RS extends ConstSchemaType>(
|
|
98
98
|
url:
|
|
99
99
|
| `/api/${appName | "seed"}/${string}`
|
|
100
100
|
| `/api/${appName | "seed"}/${string}`[],
|
|
@@ -113,7 +113,7 @@ export default class GGExpressV2<appName extends string> {
|
|
|
113
113
|
return this.rootMethod("get", url, options, ...middlewares)
|
|
114
114
|
}
|
|
115
115
|
|
|
116
|
-
post<RQ extends
|
|
116
|
+
post<RQ extends ConstSchemaType, RS extends ConstSchemaType>(
|
|
117
117
|
url:
|
|
118
118
|
| `/api/${appName | "seed"}/${string}`
|
|
119
119
|
| `/api/${appName | "seed"}/${string}`[],
|
|
@@ -131,7 +131,7 @@ export default class GGExpressV2<appName extends string> {
|
|
|
131
131
|
) {
|
|
132
132
|
return this.rootMethod("post", url, options, ...middlewares)
|
|
133
133
|
}
|
|
134
|
-
put<RQ extends
|
|
134
|
+
put<RQ extends ConstSchemaType, RS extends ConstSchemaType>(
|
|
135
135
|
url:
|
|
136
136
|
| `/api/${appName | "seed"}/${string}`
|
|
137
137
|
| `/api/${appName | "seed"}/${string}`[],
|
|
@@ -149,7 +149,7 @@ export default class GGExpressV2<appName extends string> {
|
|
|
149
149
|
) {
|
|
150
150
|
return this.rootMethod("put", url, options, ...middlewares)
|
|
151
151
|
}
|
|
152
|
-
delete<RQ extends
|
|
152
|
+
delete<RQ extends ConstSchemaType, RS extends ConstSchemaType>(
|
|
153
153
|
url:
|
|
154
154
|
| `/api/${appName | "seed"}/${string}`
|
|
155
155
|
| `/api/${appName | "seed"}/${string}`[],
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Method } from "./GGExpressV2"
|
|
2
|
-
import {
|
|
2
|
+
import { ConstSchemaType } from "./typeResolver"
|
|
3
3
|
type routeList = {
|
|
4
4
|
method: Method
|
|
5
5
|
url: string
|
|
6
|
-
requireParams:
|
|
7
|
-
responseStructure:
|
|
6
|
+
requireParams: ConstSchemaType
|
|
7
|
+
responseStructure: ConstSchemaType
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
type PrepareRouteStucture = {
|
|
@@ -43,8 +43,8 @@ function extract(
|
|
|
43
43
|
return prepareRoute
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
function parentInputToCode(data:
|
|
47
|
-
const recursiveExtract = (target:
|
|
46
|
+
function parentInputToCode(data: ConstSchemaType) {
|
|
47
|
+
const recursiveExtract = (target: ConstSchemaType, parentKeyName: string) => {
|
|
48
48
|
let result = ""
|
|
49
49
|
// check nest pimitive -------------------
|
|
50
50
|
if (typeof target === "string") {
|
|
@@ -90,7 +90,7 @@ function parentInputToCode(data: InputParent) {
|
|
|
90
90
|
.join(",")}] `
|
|
91
91
|
// nest or input nest
|
|
92
92
|
else if (typeof target[0] === "object")
|
|
93
|
-
for (const row of target as
|
|
93
|
+
for (const row of target as ConstSchemaType[]) {
|
|
94
94
|
result = result + " " + recursiveExtract(row, parentKeyName) + "[] "
|
|
95
95
|
}
|
|
96
96
|
}
|
package/src/v2/run_v2.test.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import express
|
|
1
|
+
import express from "express"
|
|
2
2
|
import GGExpressV2 from "./GGExpressV2"
|
|
3
|
-
import {
|
|
4
|
-
import { GGApi_v2 } from "./output/apiConnector_hotel_v2"
|
|
3
|
+
import { toArray } from "./typeResolver"
|
|
5
4
|
|
|
6
5
|
export const hotel_model_const_temp = {
|
|
7
6
|
booking: {
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { TypeResolve, ConstSchemaType, toArray } from "./typeResolver"
|
|
2
|
+
|
|
3
|
+
const itemDetailDataConst = {
|
|
4
|
+
itemID: "number",
|
|
5
|
+
zoneID: "number",
|
|
6
|
+
} as const satisfies ConstSchemaType
|
|
7
|
+
|
|
8
|
+
const QuantityTypeConst = {
|
|
9
|
+
requisitionQuantity: "number",
|
|
10
|
+
usedQuantity: "number",
|
|
11
|
+
} as const satisfies ConstSchemaType
|
|
12
|
+
export const ReturnOfCalculateEachDateConst = {
|
|
13
|
+
date: "string",
|
|
14
|
+
itemID: "number",
|
|
15
|
+
...QuantityTypeConst,
|
|
16
|
+
itemDetailData: toArray(itemDetailDataConst),
|
|
17
|
+
itemDetailData_v2: [{ id: "number" }],
|
|
18
|
+
bool: "boolean",
|
|
19
|
+
} as const satisfies ConstSchemaType
|
|
20
|
+
|
|
21
|
+
export type ReturnOfCalculateEachDate = TypeResolve<
|
|
22
|
+
typeof ReturnOfCalculateEachDateConst
|
|
23
|
+
>
|
|
24
|
+
|
|
25
|
+
const temp: ReturnOfCalculateEachDate = {
|
|
26
|
+
bool: true,
|
|
27
|
+
itemDetailData: toArray({
|
|
28
|
+
itemID: 0,
|
|
29
|
+
zoneID: 0,
|
|
30
|
+
}),
|
|
31
|
+
itemDetailData_v2: [
|
|
32
|
+
{
|
|
33
|
+
id: 1,
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
id: 0,
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
requisitionQuantity: 0,
|
|
40
|
+
usedQuantity: 0,
|
|
41
|
+
date: "",
|
|
42
|
+
itemID: 0,
|
|
43
|
+
}
|
|
44
|
+
console.log(temp)
|
package/src/v2/typeResolver.ts
CHANGED
|
@@ -1,22 +1,17 @@
|
|
|
1
|
-
type
|
|
2
|
-
export type CustomType =
|
|
3
|
-
| BaseType
|
|
4
|
-
| `${BaseType}?`
|
|
5
|
-
| `${BaseType}~`
|
|
6
|
-
| `${BaseType}?~`
|
|
1
|
+
type Unarray<T> = T extends (infer U)[] ? U : T
|
|
7
2
|
|
|
8
|
-
|
|
3
|
+
type BaseType =
|
|
4
|
+
| "string"
|
|
5
|
+
| "number"
|
|
6
|
+
| "boolean"
|
|
7
|
+
| "string[]"
|
|
8
|
+
| "number[]"
|
|
9
|
+
| "boolean[]"
|
|
9
10
|
|
|
11
|
+
type CustomType = BaseType | `${BaseType}?` | `${BaseType}~` | `${BaseType}?~`
|
|
10
12
|
type InputEnum = readonly string[] | readonly number[]
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
[key in string]:
|
|
14
|
-
| CustomType
|
|
15
|
-
// | InputNest
|
|
16
|
-
// | InputNest[]
|
|
17
|
-
| InputParent
|
|
18
|
-
| InputParent[]
|
|
19
|
-
| InputEnum
|
|
13
|
+
export type ConstSchemaType = {
|
|
14
|
+
[key in string]: CustomType | ConstSchemaType | ConstSchemaType[] | InputEnum
|
|
20
15
|
}
|
|
21
16
|
type ResolveBase<T extends BaseType> = T extends "string"
|
|
22
17
|
? string
|
|
@@ -26,13 +21,17 @@ type ResolveBase<T extends BaseType> = T extends "string"
|
|
|
26
21
|
? number
|
|
27
22
|
: T extends "number[]"
|
|
28
23
|
? number[]
|
|
24
|
+
: T extends "boolean"
|
|
25
|
+
? boolean
|
|
26
|
+
: T extends "boolean[]"
|
|
27
|
+
? boolean[]
|
|
29
28
|
: never
|
|
30
29
|
|
|
31
|
-
export const toArray = <T
|
|
32
|
-
return [input]
|
|
30
|
+
export const toArray = <T>(input: T): T[] => {
|
|
31
|
+
return [input] as T[]
|
|
33
32
|
}
|
|
34
33
|
|
|
35
|
-
type
|
|
34
|
+
type ResolveExtraType<T> =
|
|
36
35
|
// both null + undefined
|
|
37
36
|
T extends `${infer B}?~`
|
|
38
37
|
? ResolveBase<B & BaseType> | null | undefined
|
|
@@ -45,68 +44,14 @@ type ResolveType<T> =
|
|
|
45
44
|
: // plain primitive
|
|
46
45
|
ResolveBase<T & BaseType>
|
|
47
46
|
|
|
48
|
-
type
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
?
|
|
47
|
+
type chooseType<T> = T extends InputEnum
|
|
48
|
+
? T[number]
|
|
49
|
+
: T extends any[]
|
|
50
|
+
? chooseType<Unarray<T>>[]
|
|
52
51
|
: T extends object
|
|
53
|
-
?
|
|
54
|
-
:
|
|
52
|
+
? TypeResolve<T>
|
|
53
|
+
: ResolveExtraType<T>
|
|
55
54
|
|
|
56
|
-
export type
|
|
55
|
+
export type TypeResolve<T> = {
|
|
57
56
|
[K in keyof T]: chooseType<T[K]>
|
|
58
57
|
}
|
|
59
|
-
|
|
60
|
-
// let req2 = {
|
|
61
|
-
// booking: {
|
|
62
|
-
// id: "number",
|
|
63
|
-
// bookingGroupID: "number",
|
|
64
|
-
// checkInDate: "string",
|
|
65
|
-
// checkOutDate: "string",
|
|
66
|
-
// checkInTime: "string",
|
|
67
|
-
// checkOutTime: "string",
|
|
68
|
-
// roomRate: "number",
|
|
69
|
-
// extraBedRate: "number",
|
|
70
|
-
// roomNumber: "string",
|
|
71
|
-
// editTime: "string",
|
|
72
|
-
// createTime: "string",
|
|
73
|
-
// shiftDate: "string",
|
|
74
|
-
// shiftName: "string",
|
|
75
|
-
// userName: "string",
|
|
76
|
-
// bookingStatus: ["ACTIVE", "CLOSE", "CANCEL", "NO_SHOW"],
|
|
77
|
-
// is_specificRoom: "number",
|
|
78
|
-
// guestCount: "number",
|
|
79
|
-
// reasonToCancel: "string",
|
|
80
|
-
// note: "string",
|
|
81
|
-
// },
|
|
82
|
-
// status: ["ACTIVE", "DISABLE"],
|
|
83
|
-
// rooms: toArray({
|
|
84
|
-
// id: "number",
|
|
85
|
-
// status: ["ON", "OFF"],
|
|
86
|
-
// roomNumber: "string",
|
|
87
|
-
// log: toArray({
|
|
88
|
-
// time: "string",
|
|
89
|
-
// logger: [{ info: "string" }],
|
|
90
|
-
// }),
|
|
91
|
-
// }),
|
|
92
|
-
|
|
93
|
-
// data: {
|
|
94
|
-
// level_1: {
|
|
95
|
-
// title: "string",
|
|
96
|
-
// level_2: {
|
|
97
|
-
// id: "number",
|
|
98
|
-
// name: "string",
|
|
99
|
-
// },
|
|
100
|
-
// },
|
|
101
|
-
// },
|
|
102
|
-
// } as const satisfies InputParent
|
|
103
|
-
// const data = {} as convertRoot<typeof req2>
|
|
104
|
-
|
|
105
|
-
// data.booking.bookingStatus
|
|
106
|
-
// data.status
|
|
107
|
-
// const id = data.booking.id
|
|
108
|
-
// const roomNumber = data.booking.bookingStatus === data.booking.bookingStatus
|
|
109
|
-
// data.rooms.map((row) => row.status === "OFF")
|
|
110
|
-
// data.data.level_1.level_2.id
|
|
111
|
-
// data.booking.createTime
|
|
112
|
-
// req2.data.level_1.level_2
|