gg-express 1.0.55 → 1.0.56

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/.gitlab-ci.yml CHANGED
@@ -10,4 +10,6 @@ publish:
10
10
  - npm install typescript --save-dev
11
11
  - npm run build
12
12
  - echo "//registry.npmjs.org/:_authToken=${NPM_TOKEN}" > ~/.npmrc
13
- - npm publish
13
+ - npm publish
14
+
15
+
@@ -59,24 +59,25 @@ type MyResponse<DT extends responseStructure["dataType"], T extends responseStru
59
59
  [key in K]: numberOrString<T[key]>;
60
60
  };
61
61
  }>;
62
- export default class GGExpress {
62
+ export default class GGExpress<appName extends string> {
63
63
  express: Express.Express;
64
64
  private outputPath;
65
- constructor(app: Express.Express, outputPath: string[]);
65
+ appName: string;
66
+ constructor(app: Express.Express, appName: appName, outputPath: string[]);
66
67
  private rootMethod;
67
- get<M extends requireParamsStructure, T extends M["structure"], K extends keyof T, R extends responseStructure, RS extends R["structure"], KR extends keyof RS, P extends M["parameter"], PP extends R["parameter"], J extends M["isPartialStructure"]>(url: `/api/gg/${string}`, options: {
68
+ get<M extends requireParamsStructure, T extends M["structure"], K extends keyof T, R extends responseStructure, RS extends R["structure"], KR extends keyof RS, P extends M["parameter"], PP extends R["parameter"], J extends M["isPartialStructure"]>(url: `/api/${appName}/${string}`, options: {
68
69
  requireParams: M;
69
70
  responseStructure: R;
70
71
  }, ...middlewares: Array<(req: MyRequest<M["dataType"], T, K, P, J>, res: MyResponse<R["dataType"], RS, KR, PP, J>, next: NextFunction) => any>): Express.Express;
71
- post<M extends requireParamsStructure, T extends M["structure"], K extends keyof T, R extends responseStructure, RS extends R["structure"], KR extends keyof RS, P extends M["parameter"], PP extends R["parameter"], J extends M["isPartialStructure"]>(url: `/api/gg/${string}`, options: {
72
+ post<M extends requireParamsStructure, T extends M["structure"], K extends keyof T, R extends responseStructure, RS extends R["structure"], KR extends keyof RS, P extends M["parameter"], PP extends R["parameter"], J extends M["isPartialStructure"]>(url: `/api/${appName}/${string}`, options: {
72
73
  requireParams: M;
73
74
  responseStructure: R;
74
75
  }, ...middlewares: Array<(req: MyRequest<M["dataType"], T, K, P, J>, res: MyResponse<R["dataType"], RS, KR, PP, J>, next: NextFunction) => any>): Express.Express;
75
- put<M extends requireParamsStructure, T extends M["structure"], K extends keyof T, R extends responseStructure, RS extends R["structure"], KR extends keyof RS, P extends M["parameter"], PP extends R["parameter"], J extends M["isPartialStructure"]>(url: `/api/gg/${string}`, options: {
76
+ put<M extends requireParamsStructure, T extends M["structure"], K extends keyof T, R extends responseStructure, RS extends R["structure"], KR extends keyof RS, P extends M["parameter"], PP extends R["parameter"], J extends M["isPartialStructure"]>(url: `/api/${appName}/${string}`, options: {
76
77
  requireParams: M;
77
78
  responseStructure: R;
78
79
  }, ...middlewares: Array<(req: MyRequest<M["dataType"], T, K, P, J>, res: MyResponse<R["dataType"], RS, KR, PP, J>, next: NextFunction) => any>): Express.Express;
79
- delete<M extends requireParamsStructure, T extends M["structure"], K extends keyof T, R extends responseStructure, RS extends R["structure"], KR extends keyof RS, P extends M["parameter"], PP extends R["parameter"], J extends M["isPartialStructure"]>(url: `/api/gg/${string}`, options: {
80
+ delete<M extends requireParamsStructure, T extends M["structure"], K extends keyof T, R extends responseStructure, RS extends R["structure"], KR extends keyof RS, P extends M["parameter"], PP extends R["parameter"], J extends M["isPartialStructure"]>(url: `/api/${appName}/${string}`, options: {
80
81
  requireParams: M;
81
82
  responseStructure: R;
82
83
  }, ...middlewares: Array<(req: MyRequest<M["dataType"], T, K, P, J>, res: MyResponse<R["dataType"], RS, KR, PP, J>, next: NextFunction) => any>): Express.Express;
package/dist/GGExpress.js CHANGED
@@ -17,9 +17,10 @@ const path_1 = __importDefault(require("path"));
17
17
  const chalk_1 = __importDefault(require("chalk"));
18
18
  const myExpressRouteList = [];
19
19
  class GGExpress {
20
- constructor(app, outputPath) {
20
+ constructor(app, appName, outputPath) {
21
21
  this.express = app;
22
22
  this.outputPath = outputPath;
23
+ this.appName = appName;
23
24
  }
24
25
  rootMethod(method, url, options, ...middlewares) {
25
26
  myExpressRouteList.push({
@@ -170,8 +171,8 @@ class GGExpress {
170
171
  delete : { ${genInterfaceString(deleteDelete)} },
171
172
  }`;
172
173
  for (let row of this.outputPath) {
173
- fs_1.default.writeFileSync(path_1.default.join(row, "staticRouteInterface.ts"), content);
174
- yield this.generateGGApi(path_1.default.join(row, "apiConnector.ts"));
174
+ fs_1.default.writeFileSync(path_1.default.join(row, `staticRouteInterface_${this.appName}.ts`), content);
175
+ yield this.generateGGApi(path_1.default.join(row, `apiConnector_${this.appName}.ts`));
175
176
  }
176
177
  });
177
178
  }
package/dist/run.test.js CHANGED
@@ -7,12 +7,12 @@ const GGExpress_1 = __importDefault(require("./GGExpress"));
7
7
  const express_1 = __importDefault(require("express"));
8
8
  function run() {
9
9
  const app = (0, express_1.default)();
10
- const ggapp = new GGExpress_1.default(app, ["./"]);
11
- ggapp.get("/api/gg/users/id", {
10
+ const ggapp = new GGExpress_1.default(app, "hotel", ["./"]);
11
+ ggapp.get("/api/hotel/users/id", {
12
12
  requireParams: {
13
13
  parameter: {},
14
14
  dataType: "arrayObject",
15
- structure: { id: "number" },
15
+ structure: { id: "number", name: ["A", "B"] },
16
16
  },
17
17
  responseStructure: {
18
18
  parameter: { numberOfPeople: "number", itemName: "string" },
@@ -35,7 +35,7 @@ function run() {
35
35
  },
36
36
  });
37
37
  });
38
- ggapp.post("/api/gg/item", {
38
+ ggapp.post("/api/hotel/item", {
39
39
  requireParams: {
40
40
  parameter: {
41
41
  lotNumber: "number",
@@ -57,10 +57,10 @@ function run() {
57
57
  },
58
58
  },
59
59
  }, (req, res, next) => {
60
- req.body.data.data;
60
+ const x = req.body.data.data.name;
61
61
  // in body or query, you can access only requireParams that you declare at start
62
62
  const data = req.body.data;
63
- /* data structure
63
+ /* data structure =
64
64
  data: {
65
65
  parameter: {
66
66
  lotNumber: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gg-express",
3
- "version": "1.0.55",
3
+ "version": "1.0.56",
4
4
  "description": "",
5
5
  "main": "dist/GGExpress.js",
6
6
  "scripts": {
package/src/GGExpress.ts CHANGED
@@ -5,7 +5,6 @@ import fs from "fs"
5
5
  import path from "path"
6
6
  import chalk from "chalk"
7
7
 
8
- // export { GGApi } from "./GGApi"
9
8
  type Unarray<T> = T extends (infer U)[] ? U : T
10
9
  type AsConstArray<T extends readonly any[]> = [...T]
11
10
  type paramType =
@@ -102,12 +101,14 @@ const myExpressRouteList: {
102
101
  responseStructure: responseStructure
103
102
  }[] = []
104
103
 
105
- export default class GGExpress {
104
+ export default class GGExpress<appName extends string> {
106
105
  public express: Express.Express
107
106
  private outputPath: string[]
108
- constructor(app: Express.Express, outputPath: string[]) {
107
+ appName: string
108
+ constructor(app: Express.Express, appName: appName, outputPath: string[]) {
109
109
  this.express = app
110
110
  this.outputPath = outputPath
111
+ this.appName = appName
111
112
  }
112
113
 
113
114
  private rootMethod<
@@ -165,7 +166,7 @@ export default class GGExpress {
165
166
  PP extends R["parameter"],
166
167
  J extends M["isPartialStructure"]
167
168
  >(
168
- url: `/api/gg/${string}`,
169
+ url: `/api/${appName}/${string}`,
169
170
  options: {
170
171
  requireParams: M
171
172
  responseStructure: R
@@ -192,7 +193,7 @@ export default class GGExpress {
192
193
  PP extends R["parameter"],
193
194
  J extends M["isPartialStructure"]
194
195
  >(
195
- url: `/api/gg/${string}`,
196
+ url: `/api/${appName}/${string}`,
196
197
  options: {
197
198
  requireParams: M
198
199
  responseStructure: R
@@ -218,7 +219,7 @@ export default class GGExpress {
218
219
  PP extends R["parameter"],
219
220
  J extends M["isPartialStructure"]
220
221
  >(
221
- url: `/api/gg/${string}`,
222
+ url: `/api/${appName}/${string}`,
222
223
  options: {
223
224
  requireParams: M
224
225
  responseStructure: R
@@ -244,7 +245,7 @@ export default class GGExpress {
244
245
  PP extends R["parameter"],
245
246
  J extends M["isPartialStructure"]
246
247
  >(
247
- url: `/api/gg/${string}`,
248
+ url: `/api/${appName}/${string}`,
248
249
  options: {
249
250
  requireParams: M
250
251
  responseStructure: R
@@ -394,8 +395,13 @@ export default class GGExpress {
394
395
  }`
395
396
 
396
397
  for (let row of this.outputPath) {
397
- fs.writeFileSync(path.join(row, "staticRouteInterface.ts"), content)
398
- await this.generateGGApi(path.join(row, "apiConnector.ts"))
398
+ fs.writeFileSync(
399
+ path.join(row, `staticRouteInterface_${this.appName}.ts`),
400
+ content
401
+ )
402
+ await this.generateGGApi(
403
+ path.join(row, `apiConnector_${this.appName}.ts`)
404
+ )
399
405
  }
400
406
  }
401
407
  private async generateGGApi(filePathWithFileName: string) {
package/src/run.test.ts CHANGED
@@ -2,14 +2,14 @@ import GGExpress from "./GGExpress"
2
2
  import express, { Express } from "express"
3
3
  function run() {
4
4
  const app = express()
5
- const ggapp = new GGExpress(app, ["./"])
5
+ const ggapp = new GGExpress<"hotel">(app, "hotel", ["./"])
6
6
  ggapp.get(
7
- "/api/gg/users/id",
7
+ "/api/hotel/users/id",
8
8
  {
9
9
  requireParams: {
10
10
  parameter: {},
11
11
  dataType: "arrayObject",
12
- structure: { id: "number" },
12
+ structure: { id: "number", name: ["A", "B"] as const },
13
13
  },
14
14
  responseStructure: {
15
15
  parameter: { numberOfPeople: "number", itemName: "string" },
@@ -36,7 +36,7 @@ function run() {
36
36
  )
37
37
 
38
38
  ggapp.post(
39
- "/api/gg/item",
39
+ "/api/hotel/item",
40
40
  {
41
41
  requireParams: {
42
42
  parameter: {
@@ -46,7 +46,7 @@ function run() {
46
46
  dataType: "singleObject",
47
47
  structure: {
48
48
  id: "number",
49
- name: ["item-1", "item-2"],
49
+ name: ["item-1", "item-2"] as const,
50
50
  price: "number",
51
51
  },
52
52
  },
@@ -60,10 +60,11 @@ function run() {
60
60
  },
61
61
  },
62
62
  (req, res, next) => {
63
- req.body.data.data
63
+ const x = req.body.data.data.name
64
+
64
65
  // in body or query, you can access only requireParams that you declare at start
65
66
  const data = req.body.data
66
- /* data structure
67
+ /* data structure =
67
68
  data: {
68
69
  parameter: {
69
70
  lotNumber: number;