gg-express 1.0.150 → 1.0.151
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/v3/GGExpressV3.js +4 -43
- package/dist/v3/output/staticRouteInterface_hotel_v3.d.ts +4 -3
- package/dist/v3/test.d.ts +25 -0
- package/dist/v3/test.js +150 -0
- package/package.json +1 -1
- package/src/v3/GGExpressV3.ts +3 -55
- package/src/v3/output/staticRouteInterface_hotel_v3.ts +4 -3
- package/src/v3/{run_v3.test.ts → test.ts} +18 -17
package/dist/v3/GGExpressV3.js
CHANGED
|
@@ -17,7 +17,6 @@ const path_1 = __importDefault(require("path"));
|
|
|
17
17
|
const zod_1 = __importDefault(require("zod"));
|
|
18
18
|
const generateStaticRouteFileV3_1 = require("./generateStaticRouteFileV3");
|
|
19
19
|
const generateGGApi_v3_1 = require("./generateGGApi_v3");
|
|
20
|
-
const autoNumber_1 = require("./autoNumber");
|
|
21
20
|
const myExpressRouteList = [];
|
|
22
21
|
function wrapAsync(fn) {
|
|
23
22
|
return (req, res, next) => {
|
|
@@ -48,19 +47,20 @@ class GGExpressV3 {
|
|
|
48
47
|
});
|
|
49
48
|
return this.express[method](url,
|
|
50
49
|
// (req: Request, res: Response, next: NextFunction) => next(),
|
|
51
|
-
|
|
50
|
+
// autoTypeMiddleware,
|
|
51
|
+
(req, res, next) => {
|
|
52
52
|
// console.log("req.url", req.url)
|
|
53
53
|
// if (req.query) console.log("req.query", req.query)
|
|
54
54
|
// if (req.body) console.log("req.body", req.body)
|
|
55
55
|
try {
|
|
56
56
|
if (method === "get" &&
|
|
57
57
|
isEmptyZodObject(options.requireParams.data) === false) {
|
|
58
|
-
req.query.data = options.requireParams.data.parse(
|
|
58
|
+
req.query.data = options.requireParams.data.parse(req.query.data);
|
|
59
59
|
}
|
|
60
60
|
else if (method === "post" ||
|
|
61
61
|
method === "put" ||
|
|
62
62
|
method === "delete") {
|
|
63
|
-
req.body.data.data = options.requireParams.data.parse(
|
|
63
|
+
req.body.data.data = options.requireParams.data.parse(req.body.data.data);
|
|
64
64
|
}
|
|
65
65
|
}
|
|
66
66
|
catch (error) {
|
|
@@ -108,42 +108,3 @@ exports.default = GGExpressV3;
|
|
|
108
108
|
function isEmptyZodObject(schema) {
|
|
109
109
|
return schema instanceof zod_1.default.ZodObject && Object.keys(schema.shape).length === 0;
|
|
110
110
|
}
|
|
111
|
-
function autoCastBySchema(value, schema) {
|
|
112
|
-
const typeName = schema._def.typeName;
|
|
113
|
-
// 🔥 STRING
|
|
114
|
-
if (typeName === "ZodString") {
|
|
115
|
-
if (typeof value === "number") {
|
|
116
|
-
return String(value);
|
|
117
|
-
}
|
|
118
|
-
return value;
|
|
119
|
-
}
|
|
120
|
-
// 🔥 NUMBER
|
|
121
|
-
if (typeName === "ZodNumber") {
|
|
122
|
-
if (typeof value === "string" &&
|
|
123
|
-
value.trim() !== "" &&
|
|
124
|
-
!isNaN(Number(value))) {
|
|
125
|
-
return Number(value);
|
|
126
|
-
}
|
|
127
|
-
return value;
|
|
128
|
-
}
|
|
129
|
-
// 🔥 OBJECT (recursive)
|
|
130
|
-
if (typeName === "ZodObject") {
|
|
131
|
-
const shape = schema.shape;
|
|
132
|
-
if (typeof value !== "object" || value === null) {
|
|
133
|
-
return value;
|
|
134
|
-
}
|
|
135
|
-
const result = {};
|
|
136
|
-
for (const key in shape) {
|
|
137
|
-
result[key] = autoCastBySchema(value[key], shape[key]);
|
|
138
|
-
}
|
|
139
|
-
return result;
|
|
140
|
-
}
|
|
141
|
-
// 🔥 ARRAY
|
|
142
|
-
if (typeName === "ZodArray") {
|
|
143
|
-
const itemSchema = schema._def.type;
|
|
144
|
-
if (!Array.isArray(value))
|
|
145
|
-
return value;
|
|
146
|
-
return value.map((v) => autoCastBySchema(v, itemSchema));
|
|
147
|
-
}
|
|
148
|
-
return value;
|
|
149
|
-
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export interface staticRouteInterface_hotel_v3 {
|
|
2
2
|
get: {
|
|
3
|
-
"/api/
|
|
3
|
+
"/api/v3/hotel/users/id": {
|
|
4
4
|
requireParams: {
|
|
5
5
|
data: {
|
|
6
6
|
name: string;
|
|
@@ -15,7 +15,7 @@ export interface staticRouteInterface_hotel_v3 {
|
|
|
15
15
|
message: string;
|
|
16
16
|
};
|
|
17
17
|
};
|
|
18
|
-
"/api/
|
|
18
|
+
"/api/v3/hotel/users/empty": {
|
|
19
19
|
requireParams: {
|
|
20
20
|
data: {};
|
|
21
21
|
};
|
|
@@ -29,11 +29,12 @@ export interface staticRouteInterface_hotel_v3 {
|
|
|
29
29
|
};
|
|
30
30
|
};
|
|
31
31
|
post: {
|
|
32
|
-
"/api/
|
|
32
|
+
"/api/v3/hotel/item": {
|
|
33
33
|
requireParams: {
|
|
34
34
|
data: {
|
|
35
35
|
name: string;
|
|
36
36
|
price: number;
|
|
37
|
+
taxID: string;
|
|
37
38
|
};
|
|
38
39
|
};
|
|
39
40
|
responseStructure: {
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { NextFunction } from "express";
|
|
2
|
+
export declare const hotel_model_const_temp: {
|
|
3
|
+
readonly booking: {
|
|
4
|
+
readonly id: "number";
|
|
5
|
+
readonly bookingGroupID: "number";
|
|
6
|
+
readonly checkInDate: "string";
|
|
7
|
+
readonly checkOutDate: "string";
|
|
8
|
+
readonly checkInTime: "string";
|
|
9
|
+
readonly checkOutTime: "string";
|
|
10
|
+
readonly roomRate: "number";
|
|
11
|
+
readonly extraBedRate: "number";
|
|
12
|
+
readonly roomNumber: "string?~";
|
|
13
|
+
readonly editTime: "string";
|
|
14
|
+
readonly createTime: "string";
|
|
15
|
+
readonly shiftDate: "string";
|
|
16
|
+
readonly shiftName: "string~";
|
|
17
|
+
readonly userName: "string";
|
|
18
|
+
readonly bookingStatus: readonly ["ACTIVE", "CLOSE", "CANCEL", "NO_SHOW"];
|
|
19
|
+
readonly is_specificRoom: "number";
|
|
20
|
+
readonly guestCount: "number";
|
|
21
|
+
readonly reasonToCancel: "string";
|
|
22
|
+
readonly note: "string?~";
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
export declare const addMyTestMW: (req: any, res: any, next: NextFunction) => void;
|
package/dist/v3/test.js
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.addMyTestMW = exports.hotel_model_const_temp = void 0;
|
|
16
|
+
const express_1 = __importDefault(require("express"));
|
|
17
|
+
const zod_1 = require("zod");
|
|
18
|
+
const GGExpressV3_1 = __importDefault(require("./GGExpressV3"));
|
|
19
|
+
const apiConnector_hotel_v3_1 = require("./output/apiConnector_hotel_v3");
|
|
20
|
+
exports.hotel_model_const_temp = {
|
|
21
|
+
booking: {
|
|
22
|
+
id: "number",
|
|
23
|
+
bookingGroupID: "number",
|
|
24
|
+
checkInDate: "string",
|
|
25
|
+
checkOutDate: "string",
|
|
26
|
+
checkInTime: "string",
|
|
27
|
+
checkOutTime: "string",
|
|
28
|
+
roomRate: "number",
|
|
29
|
+
extraBedRate: "number",
|
|
30
|
+
roomNumber: "string?~",
|
|
31
|
+
editTime: "string",
|
|
32
|
+
createTime: "string",
|
|
33
|
+
shiftDate: "string",
|
|
34
|
+
shiftName: "string~",
|
|
35
|
+
userName: "string",
|
|
36
|
+
bookingStatus: ["ACTIVE", "CLOSE", "CANCEL", "NO_SHOW"],
|
|
37
|
+
is_specificRoom: "number",
|
|
38
|
+
guestCount: "number",
|
|
39
|
+
reasonToCancel: "string",
|
|
40
|
+
note: "string?~",
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
const addMyTestMW = (req, res, next) => {
|
|
44
|
+
req.myTest = "1234";
|
|
45
|
+
next();
|
|
46
|
+
};
|
|
47
|
+
exports.addMyTestMW = addMyTestMW;
|
|
48
|
+
function run() {
|
|
49
|
+
const app = (0, express_1.default)();
|
|
50
|
+
app.use(express_1.default.json());
|
|
51
|
+
// app.use((req, res, next) => {
|
|
52
|
+
// if (req.query) console.log("req.query", req.query)
|
|
53
|
+
// if (req.body) console.log("req.body", req.body)
|
|
54
|
+
// next()
|
|
55
|
+
// })
|
|
56
|
+
const ggapp = new GGExpressV3_1.default(app, "hotel", ["./output"]);
|
|
57
|
+
ggapp.get("/api/v3/hotel/users/id", {
|
|
58
|
+
requireParams: {
|
|
59
|
+
data: zod_1.z.object({
|
|
60
|
+
name: zod_1.z.string(),
|
|
61
|
+
age: zod_1.z.number(),
|
|
62
|
+
}),
|
|
63
|
+
},
|
|
64
|
+
responseStructure: zod_1.z.object({
|
|
65
|
+
value: zod_1.z.string(),
|
|
66
|
+
address: zod_1.z.string(),
|
|
67
|
+
}),
|
|
68
|
+
}, (req, res, next) => {
|
|
69
|
+
req.query.data.age;
|
|
70
|
+
res.json({
|
|
71
|
+
data: {
|
|
72
|
+
value: "",
|
|
73
|
+
address: "",
|
|
74
|
+
},
|
|
75
|
+
message: "",
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
ggapp.get("/api/v3/hotel/users/empty", {
|
|
79
|
+
requireParams: {
|
|
80
|
+
data: zod_1.z.object({}),
|
|
81
|
+
},
|
|
82
|
+
responseStructure: zod_1.z.object({
|
|
83
|
+
value: zod_1.z.string(),
|
|
84
|
+
address: zod_1.z.string(),
|
|
85
|
+
}),
|
|
86
|
+
}, (req, res, next) => {
|
|
87
|
+
res.json({
|
|
88
|
+
data: {
|
|
89
|
+
value: "",
|
|
90
|
+
address: "",
|
|
91
|
+
},
|
|
92
|
+
message: "",
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
ggapp.post("/api/v3/hotel/item", {
|
|
96
|
+
requireParams: {
|
|
97
|
+
data: zod_1.z.object({
|
|
98
|
+
name: zod_1.z.string(),
|
|
99
|
+
price: zod_1.z.number(),
|
|
100
|
+
taxID: zod_1.z.string(),
|
|
101
|
+
}),
|
|
102
|
+
},
|
|
103
|
+
responseStructure: zod_1.z.object({
|
|
104
|
+
value: zod_1.z.number(),
|
|
105
|
+
address: zod_1.z.string(),
|
|
106
|
+
}),
|
|
107
|
+
}, (req, res, next) => {
|
|
108
|
+
console.log(req.body.data.data);
|
|
109
|
+
res.json({
|
|
110
|
+
data: {
|
|
111
|
+
value: 0,
|
|
112
|
+
address: "",
|
|
113
|
+
},
|
|
114
|
+
message: "",
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
app.listen(3002, () => __awaiter(this, void 0, void 0, function* () {
|
|
118
|
+
yield ggapp.generateAPIFiles();
|
|
119
|
+
console.log("done");
|
|
120
|
+
// process.exit(0)
|
|
121
|
+
const api = new apiConnector_hotel_v3_1.GGApi_v3({ urlPrefix: "http://127.0.0.1:3002" });
|
|
122
|
+
api
|
|
123
|
+
.post("/api/v3/hotel/item", {
|
|
124
|
+
data: {
|
|
125
|
+
name: "tin",
|
|
126
|
+
price: 20,
|
|
127
|
+
taxID: "1559900272111",
|
|
128
|
+
},
|
|
129
|
+
})
|
|
130
|
+
.catch((error) => {
|
|
131
|
+
console.log(error);
|
|
132
|
+
});
|
|
133
|
+
// api
|
|
134
|
+
// .get("/api/v2/hotel/users/id", {
|
|
135
|
+
// data: {
|
|
136
|
+
// name: "tin",
|
|
137
|
+
// age: 31,
|
|
138
|
+
// },
|
|
139
|
+
// })
|
|
140
|
+
// .catch((error) => {})
|
|
141
|
+
// api
|
|
142
|
+
// .get("/api/v2/hotel/users/empty", {
|
|
143
|
+
// data: {},
|
|
144
|
+
// })
|
|
145
|
+
// .catch((error) => {
|
|
146
|
+
// console.log(error)
|
|
147
|
+
// })
|
|
148
|
+
}));
|
|
149
|
+
}
|
|
150
|
+
run();
|
package/package.json
CHANGED
package/src/v3/GGExpressV3.ts
CHANGED
|
@@ -103,7 +103,7 @@ export default class GGExpressV3<
|
|
|
103
103
|
return this.express[method](
|
|
104
104
|
url,
|
|
105
105
|
// (req: Request, res: Response, next: NextFunction) => next(),
|
|
106
|
-
autoTypeMiddleware,
|
|
106
|
+
// autoTypeMiddleware,
|
|
107
107
|
(req, res, next) => {
|
|
108
108
|
// console.log("req.url", req.url)
|
|
109
109
|
// if (req.query) console.log("req.query", req.query)
|
|
@@ -114,7 +114,7 @@ export default class GGExpressV3<
|
|
|
114
114
|
isEmptyZodObject(options.requireParams.data) === false
|
|
115
115
|
) {
|
|
116
116
|
req.query.data = options.requireParams.data.parse(
|
|
117
|
-
|
|
117
|
+
req.query.data,
|
|
118
118
|
) as any
|
|
119
119
|
} else if (
|
|
120
120
|
method === "post" ||
|
|
@@ -122,7 +122,7 @@ export default class GGExpressV3<
|
|
|
122
122
|
method === "delete"
|
|
123
123
|
) {
|
|
124
124
|
req.body.data.data = options.requireParams.data.parse(
|
|
125
|
-
|
|
125
|
+
req.body.data.data,
|
|
126
126
|
)
|
|
127
127
|
}
|
|
128
128
|
} catch (error) {
|
|
@@ -264,55 +264,3 @@ function isEmptyZodObject(
|
|
|
264
264
|
): schema is z.ZodObject<Record<string, never>> {
|
|
265
265
|
return schema instanceof z.ZodObject && Object.keys(schema.shape).length === 0
|
|
266
266
|
}
|
|
267
|
-
|
|
268
|
-
function autoCastBySchema(value: any, schema: z.ZodTypeAny): any {
|
|
269
|
-
const typeName = (schema as any)._def.typeName
|
|
270
|
-
|
|
271
|
-
// 🔥 STRING
|
|
272
|
-
if (typeName === "ZodString") {
|
|
273
|
-
if (typeof value === "number") {
|
|
274
|
-
return String(value)
|
|
275
|
-
}
|
|
276
|
-
return value
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
// 🔥 NUMBER
|
|
280
|
-
if (typeName === "ZodNumber") {
|
|
281
|
-
if (
|
|
282
|
-
typeof value === "string" &&
|
|
283
|
-
value.trim() !== "" &&
|
|
284
|
-
!isNaN(Number(value))
|
|
285
|
-
) {
|
|
286
|
-
return Number(value)
|
|
287
|
-
}
|
|
288
|
-
return value
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
// 🔥 OBJECT (recursive)
|
|
292
|
-
if (typeName === "ZodObject") {
|
|
293
|
-
const shape = (schema as any).shape
|
|
294
|
-
|
|
295
|
-
if (typeof value !== "object" || value === null) {
|
|
296
|
-
return value
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
const result: any = {}
|
|
300
|
-
|
|
301
|
-
for (const key in shape) {
|
|
302
|
-
result[key] = autoCastBySchema(value[key], shape[key])
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
return result
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
// 🔥 ARRAY
|
|
309
|
-
if (typeName === "ZodArray") {
|
|
310
|
-
const itemSchema = (schema as any)._def.type
|
|
311
|
-
|
|
312
|
-
if (!Array.isArray(value)) return value
|
|
313
|
-
|
|
314
|
-
return value.map((v) => autoCastBySchema(v, itemSchema))
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
return value
|
|
318
|
-
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
export interface staticRouteInterface_hotel_v3 {
|
|
3
3
|
get : {
|
|
4
|
-
"/api/
|
|
4
|
+
"/api/v3/hotel/users/id" : {
|
|
5
5
|
requireParams : { data :{
|
|
6
6
|
name: string;
|
|
7
7
|
age: number;
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
},
|
|
15
15
|
|
|
16
16
|
},
|
|
17
|
-
"/api/
|
|
17
|
+
"/api/v3/hotel/users/empty" : {
|
|
18
18
|
requireParams : { data :{} },responseStructure : {
|
|
19
19
|
data : {
|
|
20
20
|
value: string;
|
|
@@ -25,10 +25,11 @@
|
|
|
25
25
|
|
|
26
26
|
} },
|
|
27
27
|
post : {
|
|
28
|
-
"/api/
|
|
28
|
+
"/api/v3/hotel/item" : {
|
|
29
29
|
requireParams : { data :{
|
|
30
30
|
name: string;
|
|
31
31
|
price: number;
|
|
32
|
+
taxID: string;
|
|
32
33
|
} },responseStructure : {
|
|
33
34
|
data : {
|
|
34
35
|
value: number;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import express, { NextFunction } from "express"
|
|
2
|
+
import { z } from "zod"
|
|
2
3
|
import GGExpressV3 from "./GGExpressV3"
|
|
3
|
-
import z from "zod"
|
|
4
4
|
import { GGApi_v3 } from "./output/apiConnector_hotel_v3"
|
|
5
5
|
|
|
6
6
|
export const hotel_model_const_temp = {
|
|
@@ -39,9 +39,9 @@ function run() {
|
|
|
39
39
|
// if (req.body) console.log("req.body", req.body)
|
|
40
40
|
// next()
|
|
41
41
|
// })
|
|
42
|
-
const ggapp = new GGExpressV3<"hotel", "/api/
|
|
42
|
+
const ggapp = new GGExpressV3<"hotel", "/api/v3">(app, "hotel", ["./output"])
|
|
43
43
|
ggapp.get(
|
|
44
|
-
"/api/
|
|
44
|
+
"/api/v3/hotel/users/id",
|
|
45
45
|
{
|
|
46
46
|
requireParams: {
|
|
47
47
|
data: z.object({
|
|
@@ -66,7 +66,7 @@ function run() {
|
|
|
66
66
|
},
|
|
67
67
|
)
|
|
68
68
|
ggapp.get(
|
|
69
|
-
"/api/
|
|
69
|
+
"/api/v3/hotel/users/empty",
|
|
70
70
|
{
|
|
71
71
|
requireParams: {
|
|
72
72
|
data: z.object({}),
|
|
@@ -87,12 +87,13 @@ function run() {
|
|
|
87
87
|
},
|
|
88
88
|
)
|
|
89
89
|
ggapp.post(
|
|
90
|
-
"/api/
|
|
90
|
+
"/api/v3/hotel/item",
|
|
91
91
|
{
|
|
92
92
|
requireParams: {
|
|
93
93
|
data: z.object({
|
|
94
94
|
name: z.string(),
|
|
95
95
|
price: z.number(),
|
|
96
|
+
taxID: z.string(),
|
|
96
97
|
}),
|
|
97
98
|
},
|
|
98
99
|
responseStructure: z.object({
|
|
@@ -101,8 +102,7 @@ function run() {
|
|
|
101
102
|
}),
|
|
102
103
|
},
|
|
103
104
|
(req, res, next) => {
|
|
104
|
-
req.body.data.data
|
|
105
|
-
req.body.data.data.name
|
|
105
|
+
console.log(req.body.data.data)
|
|
106
106
|
res.json({
|
|
107
107
|
data: {
|
|
108
108
|
value: 0,
|
|
@@ -119,16 +119,17 @@ function run() {
|
|
|
119
119
|
// process.exit(0)
|
|
120
120
|
|
|
121
121
|
const api = new GGApi_v3({ urlPrefix: "http://127.0.0.1:3002" })
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
122
|
+
api
|
|
123
|
+
.post("/api/v3/hotel/item", {
|
|
124
|
+
data: {
|
|
125
|
+
name: "tin",
|
|
126
|
+
price: 20,
|
|
127
|
+
taxID: "1559900272111",
|
|
128
|
+
},
|
|
129
|
+
})
|
|
130
|
+
.catch((error) => {
|
|
131
|
+
console.log(error)
|
|
132
|
+
})
|
|
132
133
|
// api
|
|
133
134
|
// .get("/api/v2/hotel/users/id", {
|
|
134
135
|
// data: {
|