gg-express 1.0.75 → 1.0.81

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.
@@ -0,0 +1,110 @@
1
+ type BaseType = "string" | "number" | "string[]" | "number[]"
2
+ export type CustomType =
3
+ | BaseType
4
+ | `${BaseType}?`
5
+ | `${BaseType}~`
6
+ | `${BaseType}?~`
7
+
8
+ export type InputNest = { [key in string]: CustomType }
9
+ type InputEnum = string[] | number[]
10
+ export type InputParent = {
11
+ [key in string]:
12
+ | CustomType
13
+ | InputNest
14
+ | InputNest[]
15
+ | InputParent
16
+ | InputParent[]
17
+ | InputEnum
18
+ }
19
+ type ResolveBase<T extends BaseType> = T extends "string"
20
+ ? string
21
+ : T extends "string[]"
22
+ ? string[]
23
+ : T extends "number"
24
+ ? number
25
+ : T extends "number[]"
26
+ ? number[]
27
+ : never
28
+
29
+ export const toArray = <T extends InputParent>(input: T) => {
30
+ return [input]
31
+ }
32
+
33
+ // let req2 = {
34
+ // booking: {
35
+ // id: "number",
36
+ // bookingGroupID: "number",
37
+ // checkInDate: "string",
38
+ // checkOutDate: "string",
39
+ // checkInTime: "string",
40
+ // checkOutTime: "string",
41
+ // roomRate: "number",
42
+ // extraBedRate: "number",
43
+ // roomNumber: "string",
44
+ // editTime: "string",
45
+ // createTime: "string",
46
+ // shiftDate: "string",
47
+ // shiftName: "string",
48
+ // userName: "string",
49
+ // bookingStatus: ["ACTIVE", "CLOSE", "CANCEL", "NO_SHOW"],
50
+ // is_specificRoom: "number",
51
+ // guestCount: "number",
52
+ // reasonToCancel: "string",
53
+ // note: "string",
54
+ // },
55
+ // status: ["ACTIVE", "DISABLE"],
56
+ // rooms: toArray({
57
+ // id: "number",
58
+ // status: ["ON", "OFF"],
59
+ // roomNumber: "string",
60
+ // log: toArray({
61
+ // time: "string",
62
+ // logger: [{ info: "string" }],
63
+ // }),
64
+ // }),
65
+
66
+ // data: {
67
+ // level_1: {
68
+ // title: "string",
69
+ // level_2: {
70
+ // id: "number",
71
+ // name: "string",
72
+ // },
73
+ // },
74
+ // },
75
+ // } 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
+ // const data = {} as convertRoot<typeof req2>
103
+
104
+ // data.booking.bookingStatus
105
+ // data.status
106
+ // const id = data.booking.id
107
+ // const roomNumber = data.booking.bookingStatus === data.booking.bookingStatus
108
+ // data.rooms.map((row) => row.status === "OFF")
109
+ // data.data.level_1.level_2.id
110
+ // data.booking.createTime