gg-express 1.0.97 → 1.0.98
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 +8 -3
- package/dist/v2/GGExpressV2.js +1 -1
- package/dist/v2/run_v2.test.js +17 -0
- package/package.json +1 -1
- package/src/v2/GGExpressV2.ts +15 -11
- package/src/v2/run_v2.test.ts +22 -0
- package/src/v2/typeResolver.ts +1 -0
package/dist/v2/GGExpressV2.d.ts
CHANGED
|
@@ -5,11 +5,16 @@ export type Method = "get" | "post" | "put" | "delete";
|
|
|
5
5
|
type MyRequest<M extends Method, RQ extends ConstSchemaType> = M extends "get" ? TypeResolve<MyRequestQuery<RQ>> : TypeResolve<MyRequestBody<RQ>>;
|
|
6
6
|
type MyRequestQuery<T extends ConstSchemaType> = Request<{}, {}, {}, T, {}>;
|
|
7
7
|
type MyRequestBody<T extends ConstSchemaType> = Request<{}, {}, T, {}, {}>;
|
|
8
|
-
type
|
|
9
|
-
status: "SUCCESS"
|
|
8
|
+
type SuccessResponse<T extends ConstSchemaType> = {
|
|
9
|
+
status: "SUCCESS";
|
|
10
10
|
message: string;
|
|
11
11
|
data: TypeResolve<T>;
|
|
12
|
-
}
|
|
12
|
+
};
|
|
13
|
+
type ErrorResponse = {
|
|
14
|
+
status: "ERROR" | "SERVER_ERROR";
|
|
15
|
+
message: string;
|
|
16
|
+
};
|
|
17
|
+
type MyResponse<T extends ConstSchemaType> = Response<SuccessResponse<T> | ErrorResponse>;
|
|
13
18
|
export default class GGExpressV2<appName extends string> {
|
|
14
19
|
express: Express.Express;
|
|
15
20
|
private outputPath;
|
package/dist/v2/GGExpressV2.js
CHANGED
|
@@ -43,7 +43,7 @@ class GGExpressV2 {
|
|
|
43
43
|
// Express handler ต้องกว้าง
|
|
44
44
|
(req, res, next) => next(),
|
|
45
45
|
// แต่ middleware ของคุณจะถูก wrap ทีละตัว
|
|
46
|
-
...middlewares.map((mw) => (
|
|
46
|
+
...middlewares.map((mw) => (req, res, next) => mw(req, res, next)));
|
|
47
47
|
}
|
|
48
48
|
get(url, options, ...middlewares) {
|
|
49
49
|
return this.rootMethod("get", url, options, ...middlewares);
|
package/dist/v2/run_v2.test.js
CHANGED
|
@@ -142,6 +142,23 @@ function run() {
|
|
|
142
142
|
},
|
|
143
143
|
});
|
|
144
144
|
});
|
|
145
|
+
ggapp.post("/api/hotel/booking/id", {
|
|
146
|
+
requireParams: {
|
|
147
|
+
id: "number",
|
|
148
|
+
},
|
|
149
|
+
responseStructure: {
|
|
150
|
+
bookingData: {
|
|
151
|
+
id: "number",
|
|
152
|
+
roomNumber: "string",
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
}, (req, res, next) => {
|
|
156
|
+
req.body.id;
|
|
157
|
+
return res.json({
|
|
158
|
+
status: "ERROR",
|
|
159
|
+
message: "",
|
|
160
|
+
});
|
|
161
|
+
});
|
|
145
162
|
app.listen(3002, () => __awaiter(this, void 0, void 0, function* () {
|
|
146
163
|
yield ggapp.generateAPIFiles();
|
|
147
164
|
console.log("done");
|
package/package.json
CHANGED
package/src/v2/GGExpressV2.ts
CHANGED
|
@@ -6,7 +6,6 @@ import { generateStaticRouteFileV2 } from "./generateStaticRouteFileV2"
|
|
|
6
6
|
import path from "path"
|
|
7
7
|
import { generateGGApi_v2 } from "./generateGGApi_v2"
|
|
8
8
|
|
|
9
|
-
type Unarray<T> = T extends (infer U)[] ? U : T
|
|
10
9
|
export type Method = "get" | "post" | "put" | "delete"
|
|
11
10
|
|
|
12
11
|
type MyRequest<M extends Method, RQ extends ConstSchemaType> = M extends "get"
|
|
@@ -18,12 +17,22 @@ type MyRequest<M extends Method, RQ extends ConstSchemaType> = M extends "get"
|
|
|
18
17
|
type MyRequestQuery<T extends ConstSchemaType> = Request<{}, {}, {}, T, {}>
|
|
19
18
|
type MyRequestBody<T extends ConstSchemaType> = Request<{}, {}, T, {}, {}>
|
|
20
19
|
|
|
21
|
-
type
|
|
22
|
-
status: "SUCCESS"
|
|
20
|
+
type SuccessResponse<T extends ConstSchemaType> = {
|
|
21
|
+
status: "SUCCESS"
|
|
23
22
|
message: string
|
|
24
23
|
data: TypeResolve<T>
|
|
25
|
-
}
|
|
24
|
+
}
|
|
26
25
|
|
|
26
|
+
type ErrorResponse = {
|
|
27
|
+
status: "ERROR" | "SERVER_ERROR"
|
|
28
|
+
message: string
|
|
29
|
+
}
|
|
30
|
+
type MyResponse<T extends ConstSchemaType> = Response<
|
|
31
|
+
SuccessResponse<T> | ErrorResponse
|
|
32
|
+
>
|
|
33
|
+
type GGHandlerReturn<RS extends ConstSchemaType> = Response<
|
|
34
|
+
MyResponse<RS>
|
|
35
|
+
> | void // สำหรับ next()
|
|
27
36
|
const myExpressRouteList: {
|
|
28
37
|
method: "get" | "post" | "put" | "delete"
|
|
29
38
|
url: string
|
|
@@ -84,13 +93,8 @@ export default class GGExpressV2<appName extends string> {
|
|
|
84
93
|
|
|
85
94
|
// แต่ middleware ของคุณจะถูก wrap ทีละตัว
|
|
86
95
|
...middlewares.map(
|
|
87
|
-
(mw) =>
|
|
88
|
-
(
|
|
89
|
-
mw(
|
|
90
|
-
req as unknown as MyRequest<M, RQ>,
|
|
91
|
-
res as MyResponse<RS>,
|
|
92
|
-
next
|
|
93
|
-
)) as Express.RequestHandler
|
|
96
|
+
(mw) => (req: Request, res: Response, next: NextFunction) =>
|
|
97
|
+
mw(req as unknown as MyRequest<M, RQ>, res as MyResponse<RS>, next)
|
|
94
98
|
)
|
|
95
99
|
)
|
|
96
100
|
}
|
package/src/v2/run_v2.test.ts
CHANGED
|
@@ -139,6 +139,28 @@ function run() {
|
|
|
139
139
|
}
|
|
140
140
|
)
|
|
141
141
|
|
|
142
|
+
ggapp.post(
|
|
143
|
+
"/api/hotel/booking/id",
|
|
144
|
+
{
|
|
145
|
+
requireParams: {
|
|
146
|
+
id: "number",
|
|
147
|
+
},
|
|
148
|
+
responseStructure: {
|
|
149
|
+
bookingData: {
|
|
150
|
+
id: "number",
|
|
151
|
+
roomNumber: "string",
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
(req, res, next) => {
|
|
156
|
+
req.body.id
|
|
157
|
+
return res.json({
|
|
158
|
+
status: "ERROR",
|
|
159
|
+
message: "",
|
|
160
|
+
})
|
|
161
|
+
}
|
|
162
|
+
)
|
|
163
|
+
|
|
142
164
|
app.listen(3002, async () => {
|
|
143
165
|
await ggapp.generateAPIFiles()
|
|
144
166
|
console.log("done")
|
package/src/v2/typeResolver.ts
CHANGED
|
@@ -10,6 +10,7 @@ type BaseType =
|
|
|
10
10
|
|
|
11
11
|
type CustomType = BaseType | `${BaseType}?` | `${BaseType}~` | `${BaseType}?~`
|
|
12
12
|
type InputEnum = readonly string[] | readonly number[]
|
|
13
|
+
|
|
13
14
|
export type ConstSchemaType = {
|
|
14
15
|
[key in string]: CustomType | ConstSchemaType | ConstSchemaType[] | InputEnum
|
|
15
16
|
}
|