gg-express 1.0.35 → 1.0.37

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.
@@ -2,7 +2,7 @@ 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
4
  type AsConstArray<T extends readonly any[]> = [...T];
5
- type paramType = "number" | "string" | AsConstArray<Array<string>> | AsConstArray<Array<number>>;
5
+ type paramType = "number" | "string" | "any" | AsConstArray<Array<string>> | AsConstArray<Array<number>>;
6
6
  interface responseStructure {
7
7
  parameter: {
8
8
  [key: string]: "number" | "string";
@@ -20,29 +20,34 @@ interface requireParamsStructure {
20
20
  structure: {
21
21
  [key: string]: paramType;
22
22
  };
23
+ isStructurePartial?: boolean;
23
24
  }
24
- type numberOrString<T> = T extends "number" ? number : T extends "string" ? string : T extends string[] ? Unarray<T> : T extends number[] ? Unarray<T> : "error-type";
25
- type singleOrArrayObject<DT extends requireParamsStructure["dataType"], T extends requireParamsStructure["structure"], K extends keyof T, P extends requireParamsStructure["parameter"]> = DT extends "arrayObject" ? {
25
+ type numberOrString<T> = T extends "number" ? number : T extends "string" ? string : T extends "any" ? any : T extends string[] ? Unarray<T> : T extends number[] ? Unarray<T> : "error-type";
26
+ type singleOrArrayObject<DT extends requireParamsStructure["dataType"], T extends requireParamsStructure["structure"], K extends keyof T, P extends requireParamsStructure["parameter"], J extends requireParamsStructure["isStructurePartial"]> = DT extends "arrayObject" ? {
26
27
  data: {
27
28
  parameter: {
28
29
  [Key in keyof P]: numberOrString<P[Key]>;
29
30
  };
30
- data: {
31
+ data: (J extends true ? Partial<{
31
32
  [Key in K]: numberOrString<T[Key]>;
32
- }[];
33
+ }> : {
34
+ [Key in K]: numberOrString<T[Key]>;
35
+ })[];
33
36
  };
34
37
  } : {
35
38
  data: {
36
39
  parameter: {
37
40
  [Key in keyof P]: numberOrString<P[Key]>;
38
41
  };
39
- data: {
42
+ data: J extends true ? Partial<{
43
+ [Key in K]: numberOrString<T[Key]>;
44
+ }> : {
40
45
  [Key in K]: numberOrString<T[Key]>;
41
46
  };
42
47
  };
43
48
  };
44
- type MyRequest<DT extends requireParamsStructure["dataType"], T extends requireParamsStructure["structure"], K extends keyof T, P extends requireParamsStructure["parameter"]> = Request<{}, {}, singleOrArrayObject<DT, T, K, P>, singleOrArrayObject<DT, T, K, P>, {}>;
45
- type MyResponse<DT extends responseStructure["dataType"], T extends responseStructure["structure"], K extends keyof T, P extends responseStructure["parameter"]> = Response<{
49
+ type MyRequest<DT extends requireParamsStructure["dataType"], T extends requireParamsStructure["structure"], K extends keyof T, P extends requireParamsStructure["parameter"], J extends requireParamsStructure["isStructurePartial"]> = Request<{}, {}, singleOrArrayObject<DT, T, K, P, J>, singleOrArrayObject<DT, T, K, P, J>, {}>;
50
+ type MyResponse<DT extends responseStructure["dataType"], T extends responseStructure["structure"], K extends keyof T, P extends responseStructure["parameter"], J extends requireParamsStructure["isStructurePartial"]> = Response<{
46
51
  status: "SUCCESS" | "ERROR";
47
52
  message: string;
48
53
  parameter: {
@@ -59,22 +64,22 @@ export default class GGExpress {
59
64
  private outputPath;
60
65
  constructor(app: Express.Express, outputPath: string[]);
61
66
  private rootMethod;
62
- 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"]>(url: `/api/${string}`, options: {
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["isStructurePartial"]>(url: `/api/${string}`, options: {
63
68
  requireParams: M;
64
69
  responseStructure: R;
65
- }, ...middlewares: Array<(req: MyRequest<M["dataType"], T, K, P>, res: MyResponse<R["dataType"], RS, KR, PP>, next: NextFunction) => any>): Express.Express;
66
- 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"]>(url: `/api/${string}`, options: {
70
+ }, ...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["isStructurePartial"]>(url: `/api/${string}`, options: {
67
72
  requireParams: M;
68
73
  responseStructure: R;
69
- }, ...middlewares: Array<(req: MyRequest<M["dataType"], T, K, P>, res: MyResponse<R["dataType"], RS, KR, PP>, next: NextFunction) => any>): Express.Express;
70
- 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"]>(url: `/api/${string}`, options: {
74
+ }, ...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["isStructurePartial"]>(url: `/api/${string}`, options: {
71
76
  requireParams: M;
72
77
  responseStructure: R;
73
- }, ...middlewares: Array<(req: MyRequest<M["dataType"], T, K, P>, res: MyResponse<R["dataType"], RS, KR, PP>, next: NextFunction) => any>): Express.Express;
74
- 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"]>(url: `/api/${string}`, options: {
78
+ }, ...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["isStructurePartial"]>(url: `/api/${string}`, options: {
75
80
  requireParams: M;
76
81
  responseStructure: R;
77
- }, ...middlewares: Array<(req: MyRequest<M["dataType"], T, K, P>, res: MyResponse<R["dataType"], RS, KR, PP>, next: NextFunction) => any>): Express.Express;
82
+ }, ...middlewares: Array<(req: MyRequest<M["dataType"], T, K, P, J>, res: MyResponse<R["dataType"], RS, KR, PP, J>, next: NextFunction) => any>): Express.Express;
78
83
  generateAPIFiles(): void;
79
84
  private generateStaticRouteFile;
80
85
  private generateGGApi;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gg-express",
3
- "version": "1.0.35",
3
+ "version": "1.0.37",
4
4
  "description": "",
5
5
  "main": "dist/GGExpress.js",
6
6
  "scripts": {
package/src/GGExpress.ts CHANGED
@@ -11,6 +11,7 @@ type AsConstArray<T extends readonly any[]> = [...T]
11
11
  type paramType =
12
12
  | "number"
13
13
  | "string"
14
+ | "any"
14
15
  | AsConstArray<Array<string>>
15
16
  | AsConstArray<Array<number>>
16
17
  interface responseStructure {
@@ -27,11 +28,14 @@ interface requireParamsStructure {
27
28
  structure: {
28
29
  [key: string]: paramType
29
30
  }
31
+ isStructurePartial?: boolean
30
32
  }
31
33
  type numberOrString<T> = T extends "number"
32
34
  ? number
33
35
  : T extends "string"
34
36
  ? string
37
+ : T extends "any"
38
+ ? any
35
39
  : T extends string[]
36
40
  ? Unarray<T>
37
41
  : T extends number[]
@@ -42,18 +46,23 @@ type singleOrArrayObject<
42
46
  DT extends requireParamsStructure["dataType"],
43
47
  T extends requireParamsStructure["structure"],
44
48
  K extends keyof T,
45
- P extends requireParamsStructure["parameter"]
49
+ P extends requireParamsStructure["parameter"],
50
+ J extends requireParamsStructure["isStructurePartial"]
46
51
  > = DT extends "arrayObject"
47
52
  ? {
48
53
  data: {
49
54
  parameter: { [Key in keyof P]: numberOrString<P[Key]> }
50
- data: { [Key in K]: numberOrString<T[Key]> }[]
55
+ data: (J extends true
56
+ ? Partial<{ [Key in K]: numberOrString<T[Key]> }>
57
+ : { [Key in K]: numberOrString<T[Key]> })[]
51
58
  }
52
59
  }
53
60
  : {
54
61
  data: {
55
62
  parameter: { [Key in keyof P]: numberOrString<P[Key]> }
56
- data: { [Key in K]: numberOrString<T[Key]> }
63
+ data: J extends true
64
+ ? Partial<{ [Key in K]: numberOrString<T[Key]> }>
65
+ : { [Key in K]: numberOrString<T[Key]> }
57
66
  }
58
67
  }
59
68
 
@@ -61,12 +70,13 @@ type MyRequest<
61
70
  DT extends requireParamsStructure["dataType"],
62
71
  T extends requireParamsStructure["structure"],
63
72
  K extends keyof T,
64
- P extends requireParamsStructure["parameter"]
73
+ P extends requireParamsStructure["parameter"],
74
+ J extends requireParamsStructure["isStructurePartial"]
65
75
  > = Request<
66
76
  {},
67
77
  {},
68
- singleOrArrayObject<DT, T, K, P>,
69
- singleOrArrayObject<DT, T, K, P>,
78
+ singleOrArrayObject<DT, T, K, P, J>,
79
+ singleOrArrayObject<DT, T, K, P, J>,
70
80
  {}
71
81
  >
72
82
 
@@ -74,7 +84,8 @@ type MyResponse<
74
84
  DT extends responseStructure["dataType"],
75
85
  T extends responseStructure["structure"],
76
86
  K extends keyof T,
77
- P extends responseStructure["parameter"]
87
+ P extends responseStructure["parameter"],
88
+ J extends requireParamsStructure["isStructurePartial"]
78
89
  > = Response<{
79
90
  status: "SUCCESS" | "ERROR"
80
91
  message: string
@@ -107,7 +118,8 @@ export default class GGExpress {
107
118
  RS extends R["structure"],
108
119
  KR extends keyof RS,
109
120
  P extends M["parameter"],
110
- PP extends R["parameter"]
121
+ PP extends R["parameter"],
122
+ J extends M["isStructurePartial"]
111
123
  >(
112
124
  method: "get" | "post" | "put" | "delete",
113
125
  url: string,
@@ -117,8 +129,8 @@ export default class GGExpress {
117
129
  },
118
130
  ...middlewares: Array<
119
131
  (
120
- req: MyRequest<M["dataType"], T, K, P>,
121
- res: MyResponse<R["dataType"], RS, KR, PP>,
132
+ req: MyRequest<M["dataType"], T, K, P, J>,
133
+ res: MyResponse<R["dataType"], RS, KR, PP, J>,
122
134
  next: NextFunction
123
135
  ) => any
124
136
  >
@@ -133,7 +145,7 @@ export default class GGExpress {
133
145
  return this.express[method](
134
146
  url,
135
147
  (
136
- req: MyRequest<M["dataType"], T, K, P>,
148
+ req: MyRequest<M["dataType"], T, K, P, J>,
137
149
  res: Response,
138
150
  next: NextFunction
139
151
  ) => {
@@ -150,7 +162,8 @@ export default class GGExpress {
150
162
  RS extends R["structure"],
151
163
  KR extends keyof RS,
152
164
  P extends M["parameter"],
153
- PP extends R["parameter"]
165
+ PP extends R["parameter"],
166
+ J extends M["isStructurePartial"]
154
167
  >(
155
168
  url: `/api/${string}`,
156
169
  options: {
@@ -159,8 +172,8 @@ export default class GGExpress {
159
172
  },
160
173
  ...middlewares: Array<
161
174
  (
162
- req: MyRequest<M["dataType"], T, K, P>,
163
- res: MyResponse<R["dataType"], RS, KR, PP>,
175
+ req: MyRequest<M["dataType"], T, K, P, J>,
176
+ res: MyResponse<R["dataType"], RS, KR, PP, J>,
164
177
  next: NextFunction
165
178
  ) => any
166
179
  >
@@ -176,7 +189,8 @@ export default class GGExpress {
176
189
  RS extends R["structure"],
177
190
  KR extends keyof RS,
178
191
  P extends M["parameter"],
179
- PP extends R["parameter"]
192
+ PP extends R["parameter"],
193
+ J extends M["isStructurePartial"]
180
194
  >(
181
195
  url: `/api/${string}`,
182
196
  options: {
@@ -185,8 +199,8 @@ export default class GGExpress {
185
199
  },
186
200
  ...middlewares: Array<
187
201
  (
188
- req: MyRequest<M["dataType"], T, K, P>,
189
- res: MyResponse<R["dataType"], RS, KR, PP>,
202
+ req: MyRequest<M["dataType"], T, K, P, J>,
203
+ res: MyResponse<R["dataType"], RS, KR, PP, J>,
190
204
  next: NextFunction
191
205
  ) => any
192
206
  >
@@ -201,7 +215,8 @@ export default class GGExpress {
201
215
  RS extends R["structure"],
202
216
  KR extends keyof RS,
203
217
  P extends M["parameter"],
204
- PP extends R["parameter"]
218
+ PP extends R["parameter"],
219
+ J extends M["isStructurePartial"]
205
220
  >(
206
221
  url: `/api/${string}`,
207
222
  options: {
@@ -210,8 +225,8 @@ export default class GGExpress {
210
225
  },
211
226
  ...middlewares: Array<
212
227
  (
213
- req: MyRequest<M["dataType"], T, K, P>,
214
- res: MyResponse<R["dataType"], RS, KR, PP>,
228
+ req: MyRequest<M["dataType"], T, K, P, J>,
229
+ res: MyResponse<R["dataType"], RS, KR, PP, J>,
215
230
  next: NextFunction
216
231
  ) => any
217
232
  >
@@ -226,7 +241,8 @@ export default class GGExpress {
226
241
  RS extends R["structure"],
227
242
  KR extends keyof RS,
228
243
  P extends M["parameter"],
229
- PP extends R["parameter"]
244
+ PP extends R["parameter"],
245
+ J extends M["isStructurePartial"]
230
246
  >(
231
247
  url: `/api/${string}`,
232
248
  options: {
@@ -235,8 +251,8 @@ export default class GGExpress {
235
251
  },
236
252
  ...middlewares: Array<
237
253
  (
238
- req: MyRequest<M["dataType"], T, K, P>,
239
- res: MyResponse<R["dataType"], RS, KR, PP>,
254
+ req: MyRequest<M["dataType"], T, K, P, J>,
255
+ res: MyResponse<R["dataType"], RS, KR, PP, J>,
240
256
  next: NextFunction
241
257
  ) => any
242
258
  >