gg-express 1.0.61 → 1.0.66

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.
@@ -1,8 +1,7 @@
1
1
  import { NextFunction, Request, Response } from "express";
2
2
  import Express from "express-serve-static-core";
3
3
  type Unarray<T> = T extends (infer U)[] ? U : T;
4
- type AsConstArray<T extends readonly any[]> = [...T];
5
- type paramType = "number" | "string" | "any" | AsConstArray<Array<string>> | AsConstArray<Array<number>>;
4
+ type paramType = "number" | "string" | "any" | string[] | number[];
6
5
  interface responseStructure {
7
6
  parameter: {
8
7
  [key: string]: "number" | "string";
package/dist/GGExpress.js CHANGED
@@ -12,9 +12,9 @@ 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
+ const chalk_1 = __importDefault(require("chalk"));
15
16
  const fs_1 = __importDefault(require("fs"));
16
17
  const path_1 = __importDefault(require("path"));
17
- const chalk_1 = __importDefault(require("chalk"));
18
18
  const myExpressRouteList = [];
19
19
  class GGExpress {
20
20
  constructor(app, appName, outputPath) {
@@ -0,0 +1,8 @@
1
+ import { staticRouteInterface_hotel } from "./staticRouteInterface_hotel";
2
+ export declare class GGApi {
3
+ constructor();
4
+ get<T extends keyof staticRouteInterface_hotel["get"]>(url: T, requireParams: staticRouteInterface_hotel["get"][T]["requireParams"]): Promise<staticRouteInterface_hotel["get"][T]["responseStructure"]>;
5
+ post<T extends keyof staticRouteInterface_hotel["post"]>(url: T, requireParams: staticRouteInterface_hotel["post"][T]["requireParams"]): Promise<staticRouteInterface_hotel["post"][T]["responseStructure"]>;
6
+ put<T extends keyof staticRouteInterface_hotel["put"]>(url: T, requireParams: staticRouteInterface_hotel["put"][T]["requireParams"]): Promise<staticRouteInterface_hotel["put"][T]["responseStructure"]>;
7
+ delete<T extends keyof staticRouteInterface_hotel["delete"]>(url: T, requireParams: staticRouteInterface_hotel["delete"][T]["requireParams"]): Promise<staticRouteInterface_hotel["delete"][T]["responseStructure"]>;
8
+ }
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.GGApi = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ class GGApi {
9
+ constructor() { }
10
+ get(url, requireParams) {
11
+ return new Promise((resolve, reject) => {
12
+ axios_1.default
13
+ .get(url, { params: { data: requireParams } })
14
+ .then((response) => {
15
+ resolve(response.data);
16
+ })
17
+ .catch((error) => {
18
+ reject(error);
19
+ });
20
+ });
21
+ }
22
+ post(url, requireParams) {
23
+ return new Promise((resolve, reject) => {
24
+ axios_1.default
25
+ .post(url, { data: requireParams })
26
+ .then((response) => {
27
+ resolve(response.data);
28
+ })
29
+ .catch((error) => {
30
+ reject(error);
31
+ });
32
+ });
33
+ }
34
+ put(url, requireParams) {
35
+ return new Promise((resolve, reject) => {
36
+ axios_1.default
37
+ .put(url, { data: requireParams })
38
+ .then((response) => {
39
+ resolve(response.data);
40
+ })
41
+ .catch((error) => {
42
+ reject(error);
43
+ });
44
+ });
45
+ }
46
+ delete(url, requireParams) {
47
+ return new Promise((resolve, reject) => {
48
+ axios_1.default
49
+ .delete(url, { data: { data: requireParams } })
50
+ .then((response) => {
51
+ resolve(response.data);
52
+ })
53
+ .catch((error) => {
54
+ reject(error);
55
+ });
56
+ });
57
+ }
58
+ }
59
+ exports.GGApi = GGApi;
package/dist/run.test.js CHANGED
@@ -23,7 +23,7 @@ function run() {
23
23
  },
24
24
  },
25
25
  }, (req, res, next) => {
26
- req.query.data.data;
26
+ req.query.data.data.forEach((row) => row.name === "A");
27
27
  console.log(req.query);
28
28
  return res.json({
29
29
  message: "",
@@ -57,7 +57,6 @@ function run() {
57
57
  },
58
58
  },
59
59
  }, (req, res, next) => {
60
- const x = req.body.data.data.name;
61
60
  // in body or query, you can access only requireParams that you declare at start
62
61
  const data = req.body.data;
63
62
  /* data structure =
@@ -0,0 +1,55 @@
1
+ export interface staticRouteInterface_hotel {
2
+ get: {
3
+ "/api/hotel/users/id": {
4
+ requireParams: {
5
+ parameter: {
6
+ files: string[];
7
+ };
8
+ data: {
9
+ id: number;
10
+ name: "A" | "B";
11
+ }[];
12
+ };
13
+ responseStructure: {
14
+ status: "SUCCESS" | "ERROR";
15
+ message: string;
16
+ parameter: {
17
+ numberOfPeople: number;
18
+ itemName: string;
19
+ };
20
+ data: {
21
+ id: number;
22
+ name: string;
23
+ }[];
24
+ };
25
+ };
26
+ };
27
+ post: {
28
+ "/api/hotel/item": {
29
+ requireParams: {
30
+ parameter: Partial<{
31
+ lotNumber: number;
32
+ }>;
33
+ data: Partial<{
34
+ id: number;
35
+ name: "item-1" | "item-2";
36
+ price: number;
37
+ }>;
38
+ };
39
+ responseStructure: {
40
+ status: "SUCCESS" | "ERROR";
41
+ message: string;
42
+ parameter: {
43
+ numberOfPeople: number;
44
+ itemName: string;
45
+ };
46
+ data: {
47
+ id: number;
48
+ name: string;
49
+ }[];
50
+ };
51
+ };
52
+ };
53
+ put: {};
54
+ delete: {};
55
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gg-express",
3
- "version": "1.0.61",
3
+ "version": "1.0.66",
4
4
  "description": "",
5
5
  "main": "dist/GGExpress.js",
6
6
  "scripts": {
package/src/GGExpress.ts CHANGED
@@ -1,9 +1,8 @@
1
- import appRootPath from "app-root-path"
1
+ import chalk from "chalk"
2
2
  import { NextFunction, Request, Response } from "express"
3
3
  import Express from "express-serve-static-core"
4
4
  import fs from "fs"
5
5
  import path from "path"
6
- import chalk from "chalk"
7
6
 
8
7
  type Unarray<T> = T extends (infer U)[] ? U : T
9
8
  type AsConstArray<T extends readonly any[]> = [...T]
@@ -11,8 +10,10 @@ type paramType =
11
10
  | "number"
12
11
  | "string"
13
12
  | "any"
14
- | AsConstArray<Array<string>>
15
- | AsConstArray<Array<number>>
13
+ // | AsConstArray<Array<string>>
14
+ // | AsConstArray<Array<number>>
15
+ | string[]
16
+ | number[]
16
17
  interface responseStructure {
17
18
  parameter: { [key: string]: "number" | "string" }
18
19
  dataType: "singleObject" | "arrayObject"
@@ -22,7 +23,7 @@ interface responseStructure {
22
23
  }
23
24
 
24
25
  interface requireParamsStructure {
25
- parameter: { [key: string]: "number" | "string" | "number[]" | "string[]" }
26
+ parameter: { [key: string]: "number" | "string" | "number[]" | "string[]" }
26
27
  dataType: "singleObject" | "arrayObject"
27
28
  structure: {
28
29
  [key: string]: paramType
@@ -34,9 +35,9 @@ type numberOrString<T> = T extends "number"
34
35
  ? number
35
36
  : T extends "string"
36
37
  ? string
37
- : T extends "number[]"
38
+ : T extends "number[]"
38
39
  ? number[]
39
- : T extends "string[]"
40
+ : T extends "string[]"
40
41
  ? string[]
41
42
  : T extends "any"
42
43
  ? any
@@ -56,9 +57,9 @@ type singleOrArrayObject<
56
57
  > = DT extends "arrayObject"
57
58
  ? {
58
59
  data: {
59
- parameter: L extends true ?
60
- Partial<{ [Key in keyof P]: numberOrString<P[Key]> }>:
61
- { [Key in keyof P]: numberOrString<P[Key]> }
60
+ parameter: L extends true
61
+ ? Partial<{ [Key in keyof P]: numberOrString<P[Key]> }>
62
+ : { [Key in keyof P]: numberOrString<P[Key]> }
62
63
  data: (J extends true
63
64
  ? Partial<{ [Key in K]: numberOrString<T[Key]> }>
64
65
  : { [Key in K]: numberOrString<T[Key]> })[]
@@ -80,12 +81,11 @@ type MyRequest<
80
81
  P extends requireParamsStructure["parameter"],
81
82
  J extends requireParamsStructure["isPartialStructure"],
82
83
  L extends requireParamsStructure["isPartialParameter"]
83
-
84
84
  > = Request<
85
85
  {},
86
86
  {},
87
- singleOrArrayObject<DT, T, K, P, J,L>,
88
- singleOrArrayObject<DT, T, K, P, J,L>,
87
+ singleOrArrayObject<DT, T, K, P, J, L>,
88
+ singleOrArrayObject<DT, T, K, P, J, L>,
89
89
  {}
90
90
  >
91
91
 
@@ -141,7 +141,7 @@ export default class GGExpress<appName extends string> {
141
141
  },
142
142
  ...middlewares: Array<
143
143
  (
144
- req: MyRequest<M["dataType"], T, K, P, J,L>,
144
+ req: MyRequest<M["dataType"], T, K, P, J, L>,
145
145
  res: MyResponse<R["dataType"], RS, KR, PP, J>,
146
146
  next: NextFunction
147
147
  ) => any
@@ -157,7 +157,7 @@ export default class GGExpress<appName extends string> {
157
157
  return this.express[method](
158
158
  url,
159
159
  (
160
- req: MyRequest<M["dataType"], T, K, P, J,L>,
160
+ req: MyRequest<M["dataType"], T, K, P, J, L>,
161
161
  res: Response,
162
162
  next: NextFunction
163
163
  ) => {
@@ -177,7 +177,6 @@ export default class GGExpress<appName extends string> {
177
177
  PP extends R["parameter"],
178
178
  J extends M["isPartialStructure"],
179
179
  L extends M["isPartialParameter"]
180
-
181
180
  >(
182
181
  url: `/api/${appName}/${string}`,
183
182
  options: {
@@ -186,7 +185,7 @@ export default class GGExpress<appName extends string> {
186
185
  },
187
186
  ...middlewares: Array<
188
187
  (
189
- req: MyRequest<M["dataType"], T, K, P, J,L>,
188
+ req: MyRequest<M["dataType"], T, K, P, J, L>,
190
189
  res: MyResponse<R["dataType"], RS, KR, PP, J>,
191
190
  next: NextFunction
192
191
  ) => any
@@ -206,7 +205,6 @@ export default class GGExpress<appName extends string> {
206
205
  PP extends R["parameter"],
207
206
  J extends M["isPartialStructure"],
208
207
  L extends M["isPartialParameter"]
209
-
210
208
  >(
211
209
  url: `/api/${appName}/${string}`,
212
210
  options: {
@@ -215,7 +213,7 @@ export default class GGExpress<appName extends string> {
215
213
  },
216
214
  ...middlewares: Array<
217
215
  (
218
- req: MyRequest<M["dataType"], T, K, P, J,L>,
216
+ req: MyRequest<M["dataType"], T, K, P, J, L>,
219
217
  res: MyResponse<R["dataType"], RS, KR, PP, J>,
220
218
  next: NextFunction
221
219
  ) => any
@@ -234,7 +232,6 @@ export default class GGExpress<appName extends string> {
234
232
  PP extends R["parameter"],
235
233
  J extends M["isPartialStructure"],
236
234
  L extends M["isPartialParameter"]
237
-
238
235
  >(
239
236
  url: `/api/${appName}/${string}`,
240
237
  options: {
@@ -243,7 +240,7 @@ export default class GGExpress<appName extends string> {
243
240
  },
244
241
  ...middlewares: Array<
245
242
  (
246
- req: MyRequest<M["dataType"], T, K, P, J,L>,
243
+ req: MyRequest<M["dataType"], T, K, P, J, L>,
247
244
  res: MyResponse<R["dataType"], RS, KR, PP, J>,
248
245
  next: NextFunction
249
246
  ) => any
@@ -262,7 +259,6 @@ export default class GGExpress<appName extends string> {
262
259
  PP extends R["parameter"],
263
260
  J extends M["isPartialStructure"],
264
261
  L extends M["isPartialParameter"]
265
-
266
262
  >(
267
263
  url: `/api/${appName}/${string}`,
268
264
  options: {
@@ -271,7 +267,7 @@ export default class GGExpress<appName extends string> {
271
267
  },
272
268
  ...middlewares: Array<
273
269
  (
274
- req: MyRequest<M["dataType"], T, K, P, J,L>,
270
+ req: MyRequest<M["dataType"], T, K, P, J, L>,
275
271
  res: MyResponse<R["dataType"], RS, KR, PP, J>,
276
272
  next: NextFunction
277
273
  ) => any
@@ -371,8 +367,7 @@ export default class GGExpress<appName extends string> {
371
367
  }
372
368
  const requireParameterCode = () => {
373
369
  if (parameterCode === "") return ""
374
- else
375
- return ` parameter:${isPartial(`{${parameterCode}}`)}`
370
+ else return ` parameter:${isPartial(`{${parameterCode}}`)}`
376
371
  // return ` parameter:{${parameterCode}} `
377
372
  }
378
373
  const requireDataCode = () => {
@@ -1,14 +1,14 @@
1
1
 
2
2
  import axios from "axios"
3
- import { staticRouteInterface } from "./staticRouteInterface"
3
+ import { staticRouteInterface_hotel } from "./staticRouteInterface_hotel"
4
4
 
5
5
  export class GGApi {
6
6
  constructor() {}
7
7
 
8
- get<T extends keyof staticRouteInterface["get"]>(
8
+ get<T extends keyof staticRouteInterface_hotel["get"]>(
9
9
  url: T,
10
- requireParams: staticRouteInterface["get"][T]["requireParams"]
11
- ): Promise<staticRouteInterface["get"][T]["responseStructure"]> {
10
+ requireParams: staticRouteInterface_hotel["get"][T]["requireParams"]
11
+ ): Promise<staticRouteInterface_hotel["get"][T]["responseStructure"]> {
12
12
  return new Promise((resolve, reject) => {
13
13
  axios
14
14
  .get(url as string, { params: { data: requireParams } })
@@ -21,10 +21,10 @@ export class GGApi {
21
21
  })
22
22
  }
23
23
 
24
- post<T extends keyof staticRouteInterface["post"]>(
24
+ post<T extends keyof staticRouteInterface_hotel["post"]>(
25
25
  url: T,
26
- requireParams: staticRouteInterface["post"][T]["requireParams"]
27
- ): Promise<staticRouteInterface["post"][T]["responseStructure"]> {
26
+ requireParams: staticRouteInterface_hotel["post"][T]["requireParams"]
27
+ ): Promise<staticRouteInterface_hotel["post"][T]["responseStructure"]> {
28
28
  return new Promise((resolve, reject) => {
29
29
  axios
30
30
  .post(url as string, { data: requireParams })
@@ -36,10 +36,10 @@ export class GGApi {
36
36
  })
37
37
  })
38
38
  }
39
- put<T extends keyof staticRouteInterface["put"]>(
39
+ put<T extends keyof staticRouteInterface_hotel["put"]>(
40
40
  url: T,
41
- requireParams: staticRouteInterface["put"][T]["requireParams"]
42
- ): Promise<staticRouteInterface["put"][T]["responseStructure"]> {
41
+ requireParams: staticRouteInterface_hotel["put"][T]["requireParams"]
42
+ ): Promise<staticRouteInterface_hotel["put"][T]["responseStructure"]> {
43
43
  return new Promise((resolve, reject) => {
44
44
  axios
45
45
  .put(url as string, { data: requireParams })
@@ -51,10 +51,10 @@ export class GGApi {
51
51
  })
52
52
  })
53
53
  }
54
- delete<T extends keyof staticRouteInterface["delete"]>(
54
+ delete<T extends keyof staticRouteInterface_hotel["delete"]>(
55
55
  url: T,
56
- requireParams: staticRouteInterface["delete"][T]["requireParams"]
57
- ): Promise<staticRouteInterface["delete"][T]["responseStructure"]> {
56
+ requireParams: staticRouteInterface_hotel["delete"][T]["requireParams"]
57
+ ): Promise<staticRouteInterface_hotel["delete"][T]["responseStructure"]> {
58
58
  return new Promise((resolve, reject) => {
59
59
  axios
60
60
  .delete(url as string, { data: { data: requireParams } })
package/src/run.test.ts CHANGED
@@ -7,9 +7,9 @@ function run() {
7
7
  "/api/hotel/users/id",
8
8
  {
9
9
  requireParams: {
10
- parameter: {files : "string[]"},
10
+ parameter: { files: "string[]" },
11
11
  dataType: "arrayObject",
12
- structure: { id: "number", name: ["A", "B"] as const },
12
+ structure: { id: "number", name: ["A", "B"] },
13
13
  },
14
14
  responseStructure: {
15
15
  parameter: { numberOfPeople: "number", itemName: "string" },
@@ -21,7 +21,7 @@ function run() {
21
21
  },
22
22
  },
23
23
  (req, res, next) => {
24
- req.query.data.data
24
+ req.query.data.data.forEach((row) => row.name === "A")
25
25
  console.log(req.query)
26
26
  return res.json({
27
27
  message: "",
@@ -46,7 +46,7 @@ function run() {
46
46
  dataType: "singleObject",
47
47
  structure: {
48
48
  id: "number",
49
- name: ["item-1", "item-2"] as const,
49
+ name: ["item-1", "item-2"],
50
50
  price: "number",
51
51
  },
52
52
  },
@@ -60,8 +60,6 @@ function run() {
60
60
  },
61
61
  },
62
62
  (req, res, next) => {
63
- const x = req.body.data.data.name
64
-
65
63
  // in body or query, you can access only requireParams that you declare at start
66
64
  const data = req.body.data
67
65
  /* data structure =
@@ -0,0 +1,32 @@
1
+ export interface staticRouteInterface_hotel {
2
+ get: {
3
+ "/api/hotel/users/id": {
4
+ requireParams: {
5
+ parameter: { files: string[] }
6
+ data: { id: number; name: "A" | "B" }[]
7
+ }
8
+ responseStructure: {
9
+ status: "SUCCESS" | "ERROR"
10
+ message: string
11
+ parameter: { numberOfPeople: number; itemName: string }
12
+ data: { id: number; name: string }[]
13
+ }
14
+ }
15
+ }
16
+ post: {
17
+ "/api/hotel/item": {
18
+ requireParams: {
19
+ parameter: Partial<{ lotNumber: number }>
20
+ data: Partial<{ id: number; name: "item-1" | "item-2"; price: number }>
21
+ }
22
+ responseStructure: {
23
+ status: "SUCCESS" | "ERROR"
24
+ message: string
25
+ parameter: { numberOfPeople: number; itemName: string }
26
+ data: { id: number; name: string }[]
27
+ }
28
+ }
29
+ }
30
+ put: {}
31
+ delete: {}
32
+ }