gg-express 1.0.83 → 1.0.88

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.
@@ -50,7 +50,10 @@ function parentInputToCode(data) {
50
50
  const recusiveResult = recursiveExtract(target[keyName], keyName);
51
51
  tempResult.push(recusiveResult);
52
52
  }
53
- result = `${result} \n ${parentKeyName} : { ${tempResult.join(",")} }`;
53
+ if (parentKeyName === "root")
54
+ result = ` { ${tempResult.join(",")} } `;
55
+ else
56
+ result = `${result} \n ${parentKeyName} : { ${tempResult.join(",")} }`;
54
57
  }
55
58
  // check array ---------------------------
56
59
  else if (Array.isArray(target)) {
@@ -70,8 +73,8 @@ function parentInputToCode(data) {
70
73
  }
71
74
  return `${result}`;
72
75
  };
73
- const result = recursiveExtract(data, "data");
74
- return `${result} `;
76
+ const result = recursiveExtract(data, "root");
77
+ return `${result}`;
75
78
  }
76
79
  function generateStaticRouteFileV2(appName, data) {
77
80
  const interfaceName = `staticRouteInterface_${appName}_v2`;
@@ -80,10 +83,11 @@ function generateStaticRouteFileV2(appName, data) {
80
83
  return keyName
81
84
  .map((keyName) => `
82
85
  "${keyName}" : {
83
- requireParams : { ${data[keyName].requireParams} },
84
- responseStructure : { ${data[keyName].responseStructure},
86
+ requireParams : ${data[keyName].requireParams} ,
87
+ responseStructure : {
88
+ data : ${data[keyName].responseStructure},
85
89
  status: "SUCCESS" | "ERROR",
86
- message: string }
90
+ message: string }
87
91
  }`)
88
92
  .join(", ");
89
93
  };
@@ -10,7 +10,7 @@ class GGApi_v2 {
10
10
  get(url, requireParams) {
11
11
  return new Promise((resolve, reject) => {
12
12
  axios_1.default
13
- .get(url, { params: { data: requireParams } })
13
+ .get(url, { params: requireParams })
14
14
  .then((response) => {
15
15
  resolve(response.data);
16
16
  })
@@ -2,9 +2,7 @@ export interface staticRouteInterface_hotel_v2 {
2
2
  get: {
3
3
  "/api/hotel/users/id": {
4
4
  requireParams: {
5
- data: {
6
- id: number;
7
- };
5
+ id: number;
8
6
  };
9
7
  responseStructure: {
10
8
  data: {
@@ -21,9 +19,7 @@ export interface staticRouteInterface_hotel_v2 {
21
19
  post: {
22
20
  "/api/hotel/booking/id": {
23
21
  requireParams: {
24
- data: {
25
- id: number;
26
- };
22
+ id: number;
27
23
  };
28
24
  responseStructure: {
29
25
  data: {
@@ -1 +1,23 @@
1
- export {};
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
+ };
@@ -12,17 +12,42 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
12
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.hotel_model_const_temp = void 0;
15
16
  const express_1 = __importDefault(require("express"));
16
17
  const GGExpressV2_1 = __importDefault(require("./GGExpressV2"));
17
18
  const typeResolver_1 = require("./typeResolver");
18
- const apiConnector_hotel_v2_1 = require("./output/apiConnector_hotel_v2");
19
- // import { GGApi_v2 } from "./output/apiConnector_hotel_v2"
19
+ exports.hotel_model_const_temp = {
20
+ booking: {
21
+ id: "number",
22
+ bookingGroupID: "number",
23
+ checkInDate: "string",
24
+ checkOutDate: "string",
25
+ checkInTime: "string",
26
+ checkOutTime: "string",
27
+ roomRate: "number",
28
+ extraBedRate: "number",
29
+ roomNumber: "string",
30
+ editTime: "string",
31
+ createTime: "string",
32
+ shiftDate: "string",
33
+ shiftName: "string",
34
+ userName: "string",
35
+ bookingStatus: ["ACTIVE", "CLOSE", "CANCEL", "NO_SHOW"],
36
+ is_specificRoom: "number",
37
+ guestCount: "number",
38
+ reasonToCancel: "string",
39
+ note: "string",
40
+ },
41
+ };
20
42
  function run() {
21
43
  const app = (0, express_1.default)();
22
44
  const ggapp = new GGExpressV2_1.default(app, "hotel", ["./output"]);
23
45
  ggapp.get("/api/hotel/users/id", {
24
46
  requireParams: {
25
47
  id: "number",
48
+ data: exports.hotel_model_const_temp["booking"],
49
+ name: "string",
50
+ status: ["on", "off"],
26
51
  },
27
52
  responseStructure: {
28
53
  userData: (0, typeResolver_1.toArray)({
@@ -31,8 +56,11 @@ function run() {
31
56
  }),
32
57
  },
33
58
  }, (req, res, next) => {
34
- console.log(req.query);
35
- req.query.id;
59
+ // req.query.data.bookingStatus===''
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
36
64
  return res.json({
37
65
  message: "",
38
66
  status: "SUCCESS",
@@ -50,6 +78,7 @@ function run() {
50
78
  },
51
79
  },
52
80
  }, (req, res, next) => {
81
+ req.body.id;
53
82
  return res.json({
54
83
  message: "",
55
84
  status: "SUCCESS",
@@ -64,15 +93,20 @@ function run() {
64
93
  app.listen(3002, () => __awaiter(this, void 0, void 0, function* () {
65
94
  yield ggapp.generateAPIFiles();
66
95
  console.log("done");
67
- process.exit(0);
96
+ // process.exit(0)
68
97
  }));
69
98
  }
70
- run();
71
- const x = new apiConnector_hotel_v2_1.GGApi_v2();
72
- x.post("/api/hotel/booking/id", {
73
- data: { id: 1 },
74
- }).then((response) => {
75
- response.status === "ERROR";
76
- response.data.bookingData;
77
- response.data.bookingData.roomNumber;
78
- });
99
+ // run()
100
+ // setTimeout(() => {
101
+ // const x = new GGApi_v2()
102
+ // //@ts-ignore
103
+ // x.get("http://localhost:3002/api/hotel/users/id", {
104
+ // id: 1,
105
+ // })
106
+ // .then((response) => {
107
+ // console.log("response", response)
108
+ // })
109
+ // .catch((error) => {
110
+ // console.error("fetch error")
111
+ // })
112
+ // }, 3000)
@@ -3,9 +3,9 @@ export type CustomType = BaseType | `${BaseType}?` | `${BaseType}~` | `${BaseTyp
3
3
  export type InputNest = {
4
4
  [key in string]: CustomType;
5
5
  };
6
- type InputEnum = string[] | number[];
6
+ type InputEnum = readonly (string | number)[];
7
7
  export type InputParent = {
8
- [key in string]: CustomType | InputNest | InputNest[] | InputParent | InputParent[] | InputEnum;
8
+ [key in string]: CustomType | InputParent | InputParent[] | InputEnum;
9
9
  };
10
10
  type ResolveBase<T extends BaseType> = T extends "string" ? string : T extends "string[]" ? string[] : T extends "number" ? number : T extends "number[]" ? number[] : never;
11
11
  export declare const toArray: <T extends InputParent>(input: T) => T[];
@@ -15,7 +15,7 @@ type checkEnum<T> = T extends InputEnum ? T[number] : convertNest<T>;
15
15
  type convertChildObjet<T> = {
16
16
  [K in keyof T]: chooseType<T[K]>;
17
17
  };
18
- type convertObject<T> = T extends object ? convertChildObjet<T> : checkEnum<T>;
18
+ type convertObject<T> = T extends readonly any[] ? checkEnum<T> : T extends object ? convertChildObjet<T> : checkEnum<T>;
19
19
  type chooseType<T> = T extends InputEnum ? T[number] : convertObject<T>;
20
20
  export type convertRoot<T> = {
21
21
  [K in keyof T]: chooseType<T[K]>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gg-express",
3
- "version": "1.0.83",
3
+ "version": "1.0.88",
4
4
  "description": "",
5
5
  "main": "dist/main.js",
6
6
  "scripts": {
@@ -1,6 +1,5 @@
1
1
  import { Method } from "./GGExpressV2"
2
- import { CustomType, InputNest, InputParent, toArray } from "./typeResolver"
3
- import fs from "fs"
2
+ import { InputParent } from "./typeResolver"
4
3
  type routeList = {
5
4
  method: Method
6
5
  url: string
@@ -72,7 +71,9 @@ function parentInputToCode(data: InputParent) {
72
71
  const recusiveResult = recursiveExtract(target[keyName], keyName)
73
72
  tempResult.push(recusiveResult)
74
73
  }
75
- result = `${result} \n ${parentKeyName} : { ${tempResult.join(",")} }`
74
+ if (parentKeyName === "root") result = ` { ${tempResult.join(",")} } `
75
+ else
76
+ result = `${result} \n ${parentKeyName} : { ${tempResult.join(",")} }`
76
77
  }
77
78
 
78
79
  // check array ---------------------------
@@ -89,14 +90,14 @@ function parentInputToCode(data: InputParent) {
89
90
  .join(",")}] `
90
91
  // nest or input nest
91
92
  else if (typeof target[0] === "object")
92
- for (const row of target as InputNest[] | InputParent[]) {
93
+ for (const row of target as InputParent[]) {
93
94
  result = result + " " + recursiveExtract(row, parentKeyName) + "[] "
94
95
  }
95
96
  }
96
97
  return `${result}`
97
98
  }
98
- const result = recursiveExtract(data, "data")
99
- return `${result} `
99
+ const result = recursiveExtract(data, "root")
100
+ return `${result}`
100
101
  }
101
102
  export function generateStaticRouteFileV2(appName: string, data: routeList[]) {
102
103
  const interfaceName = `staticRouteInterface_${appName}_v2`
@@ -106,10 +107,11 @@ export function generateStaticRouteFileV2(appName: string, data: routeList[]) {
106
107
  .map(
107
108
  (keyName) => `
108
109
  "${keyName}" : {
109
- requireParams : { ${data[keyName].requireParams} },
110
- responseStructure : { ${data[keyName].responseStructure},
110
+ requireParams : ${data[keyName].requireParams} ,
111
+ responseStructure : {
112
+ data : ${data[keyName].responseStructure},
111
113
  status: "SUCCESS" | "ERROR",
112
- message: string }
114
+ message: string }
113
115
  }`
114
116
  )
115
117
  .join(", ")
@@ -1,3 +1,4 @@
1
+
1
2
  import axios from "axios"
2
3
  import { staticRouteInterface_hotel_v2 } from "./staticRouteInterface_hotel_v2"
3
4
 
@@ -10,7 +11,7 @@ export class GGApi_v2 {
10
11
  ): Promise<staticRouteInterface_hotel_v2["get"][T]["responseStructure"]> {
11
12
  return new Promise((resolve, reject) => {
12
13
  axios
13
- .get(url as string, { params: { data: requireParams } })
14
+ .get(url as string, { params: requireParams })
14
15
  .then((response) => {
15
16
  resolve(response.data)
16
17
  })
@@ -1,32 +1,24 @@
1
- export interface staticRouteInterface_hotel_v2 {
2
- get: {
3
- "/api/hotel/users/id": {
4
- requireParams: {
5
- data: { id: number }
6
- }
7
- responseStructure: {
8
- data: {
9
- userData: { id: number; name: string }[]
10
- }
11
- status: "SUCCESS" | "ERROR"
12
- message: string
13
- }
14
- }
1
+
2
+ export interface staticRouteInterface_hotel_v2 {
3
+ get : {
4
+ "/api/hotel/users/id" : {
5
+ requireParams : { id : number } ,
6
+ responseStructure : {
7
+ data : {
8
+ userData : { id : number,name : string }[] } ,
9
+ status: "SUCCESS" | "ERROR",
10
+ message: string }
11
+ } },
12
+ post : {
13
+ "/api/hotel/booking/id" : {
14
+ requireParams : { id : number } ,
15
+ responseStructure : {
16
+ data : {
17
+ bookingData : { id : number,roomNumber : string } } ,
18
+ status: "SUCCESS" | "ERROR",
19
+ message: string }
20
+ } },
21
+ put : { },
22
+ delete : { },
15
23
  }
16
- post: {
17
- "/api/hotel/booking/id": {
18
- requireParams: {
19
- data: { id: number }
20
- }
21
- responseStructure: {
22
- data: {
23
- bookingData: { id: number; roomNumber: string }
24
- }
25
- status: "SUCCESS" | "ERROR"
26
- message: string
27
- }
28
- }
29
- }
30
- put: {}
31
- delete: {}
32
- }
24
+
@@ -2,7 +2,31 @@ import express, { Express } from "express"
2
2
  import GGExpressV2 from "./GGExpressV2"
3
3
  import { toArray } from "./typeResolver"
4
4
  import { GGApi_v2 } from "./output/apiConnector_hotel_v2"
5
- // import { GGApi_v2 } from "./output/apiConnector_hotel_v2"
5
+
6
+ export const hotel_model_const_temp = {
7
+ booking: {
8
+ id: "number",
9
+ bookingGroupID: "number",
10
+ checkInDate: "string",
11
+ checkOutDate: "string",
12
+ checkInTime: "string",
13
+ checkOutTime: "string",
14
+ roomRate: "number",
15
+ extraBedRate: "number",
16
+ roomNumber: "string",
17
+ editTime: "string",
18
+ createTime: "string",
19
+ shiftDate: "string",
20
+ shiftName: "string",
21
+ userName: "string",
22
+ bookingStatus: ["ACTIVE", "CLOSE", "CANCEL", "NO_SHOW"],
23
+ is_specificRoom: "number",
24
+ guestCount: "number",
25
+ reasonToCancel: "string",
26
+ note: "string",
27
+ },
28
+ } as const
29
+
6
30
  function run() {
7
31
  const app = express()
8
32
  const ggapp = new GGExpressV2<"hotel">(app, "hotel", ["./output"])
@@ -11,6 +35,9 @@ function run() {
11
35
  {
12
36
  requireParams: {
13
37
  id: "number",
38
+ data: hotel_model_const_temp["booking"],
39
+ name: "string",
40
+ status: ["on", "off"],
14
41
  },
15
42
  responseStructure: {
16
43
  userData: toArray({
@@ -20,8 +47,11 @@ function run() {
20
47
  },
21
48
  },
22
49
  (req, res, next) => {
23
- console.log(req.query)
24
- req.query.id
50
+ // req.query.data.bookingStatus===''
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
25
55
  return res.json({
26
56
  message: "",
27
57
  status: "SUCCESS",
@@ -43,6 +73,7 @@ function run() {
43
73
  },
44
74
  },
45
75
  (req, res, next) => {
76
+ req.body.id
46
77
  return res.json({
47
78
  message: "",
48
79
  status: "SUCCESS",
@@ -59,16 +90,21 @@ function run() {
59
90
  app.listen(3002, async () => {
60
91
  await ggapp.generateAPIFiles()
61
92
  console.log("done")
62
- process.exit(0)
93
+ // process.exit(0)
63
94
  })
64
95
  }
65
- run()
96
+ // run()
66
97
 
67
- const x = new GGApi_v2()
68
- x.post("/api/hotel/booking/id", {
69
- data: { id: 1 },
70
- }).then((response) => {
71
- response.status === "ERROR"
72
- response.data.bookingData
73
- response.data.bookingData.roomNumber
74
- })
98
+ // setTimeout(() => {
99
+ // const x = new GGApi_v2()
100
+ // //@ts-ignore
101
+ // x.get("http://localhost:3002/api/hotel/users/id", {
102
+ // id: 1,
103
+ // })
104
+ // .then((response) => {
105
+ // console.log("response", response)
106
+ // })
107
+ // .catch((error) => {
108
+ // console.error("fetch error")
109
+ // })
110
+ // }, 3000)
@@ -6,12 +6,15 @@ export type CustomType =
6
6
  | `${BaseType}?~`
7
7
 
8
8
  export type InputNest = { [key in string]: CustomType }
9
- type InputEnum = string[] | number[]
9
+
10
+ // Allow readonly tuples (from `as const`) to be treated as enums.
11
+ // type InputEnum = readonly string[] | readonly number[]
12
+ type InputEnum = readonly (string | number)[]
10
13
  export type InputParent = {
11
14
  [key in string]:
12
15
  | CustomType
13
- | InputNest
14
- | InputNest[]
16
+ // | InputNest
17
+ // | InputNest[]
15
18
  | InputParent
16
19
  | InputParent[]
17
20
  | InputEnum
@@ -93,7 +96,14 @@ type checkEnum<T> = T extends InputEnum ? T[number] : convertNest<T>
93
96
  type convertChildObjet<T> = {
94
97
  [K in keyof T]: chooseType<T[K]>
95
98
  }
96
- type convertObject<T> = T extends object ? convertChildObjet<T> : checkEnum<T>
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
+
97
107
  type chooseType<T> = T extends InputEnum ? T[number] : convertObject<T>
98
108
  export type convertRoot<T> = {
99
109
  [K in keyof T]: chooseType<T[K]>