gg-express 1.0.36 → 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.
@@ -20,29 +20,34 @@ interface requireParamsStructure {
20
20
  structure: {
21
21
  [key: string]: paramType;
22
22
  };
23
+ isStructurePartial?: boolean;
23
24
  }
24
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";
25
- type singleOrArrayObject<DT extends requireParamsStructure["dataType"], T extends requireParamsStructure["structure"], K extends keyof T, P extends requireParamsStructure["parameter"]> = DT extends "arrayObject" ? {
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.36",
3
+ "version": "1.0.37",
4
4
  "description": "",
5
5
  "main": "dist/GGExpress.js",
6
6
  "scripts": {
package/src/GGExpress.ts CHANGED
@@ -28,6 +28,7 @@ interface requireParamsStructure {
28
28
  structure: {
29
29
  [key: string]: paramType
30
30
  }
31
+ isStructurePartial?: boolean
31
32
  }
32
33
  type numberOrString<T> = T extends "number"
33
34
  ? number
@@ -45,18 +46,23 @@ type singleOrArrayObject<
45
46
  DT extends requireParamsStructure["dataType"],
46
47
  T extends requireParamsStructure["structure"],
47
48
  K extends keyof T,
48
- P extends requireParamsStructure["parameter"]
49
+ P extends requireParamsStructure["parameter"],
50
+ J extends requireParamsStructure["isStructurePartial"]
49
51
  > = DT extends "arrayObject"
50
52
  ? {
51
53
  data: {
52
54
  parameter: { [Key in keyof P]: numberOrString<P[Key]> }
53
- 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]> })[]
54
58
  }
55
59
  }
56
60
  : {
57
61
  data: {
58
62
  parameter: { [Key in keyof P]: numberOrString<P[Key]> }
59
- 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]> }
60
66
  }
61
67
  }
62
68
 
@@ -64,12 +70,13 @@ type MyRequest<
64
70
  DT extends requireParamsStructure["dataType"],
65
71
  T extends requireParamsStructure["structure"],
66
72
  K extends keyof T,
67
- P extends requireParamsStructure["parameter"]
73
+ P extends requireParamsStructure["parameter"],
74
+ J extends requireParamsStructure["isStructurePartial"]
68
75
  > = Request<
69
76
  {},
70
77
  {},
71
- singleOrArrayObject<DT, T, K, P>,
72
- singleOrArrayObject<DT, T, K, P>,
78
+ singleOrArrayObject<DT, T, K, P, J>,
79
+ singleOrArrayObject<DT, T, K, P, J>,
73
80
  {}
74
81
  >
75
82
 
@@ -77,7 +84,8 @@ type MyResponse<
77
84
  DT extends responseStructure["dataType"],
78
85
  T extends responseStructure["structure"],
79
86
  K extends keyof T,
80
- P extends responseStructure["parameter"]
87
+ P extends responseStructure["parameter"],
88
+ J extends requireParamsStructure["isStructurePartial"]
81
89
  > = Response<{
82
90
  status: "SUCCESS" | "ERROR"
83
91
  message: string
@@ -110,7 +118,8 @@ export default class GGExpress {
110
118
  RS extends R["structure"],
111
119
  KR extends keyof RS,
112
120
  P extends M["parameter"],
113
- PP extends R["parameter"]
121
+ PP extends R["parameter"],
122
+ J extends M["isStructurePartial"]
114
123
  >(
115
124
  method: "get" | "post" | "put" | "delete",
116
125
  url: string,
@@ -120,8 +129,8 @@ export default class GGExpress {
120
129
  },
121
130
  ...middlewares: Array<
122
131
  (
123
- req: MyRequest<M["dataType"], T, K, P>,
124
- 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>,
125
134
  next: NextFunction
126
135
  ) => any
127
136
  >
@@ -136,7 +145,7 @@ export default class GGExpress {
136
145
  return this.express[method](
137
146
  url,
138
147
  (
139
- req: MyRequest<M["dataType"], T, K, P>,
148
+ req: MyRequest<M["dataType"], T, K, P, J>,
140
149
  res: Response,
141
150
  next: NextFunction
142
151
  ) => {
@@ -153,7 +162,8 @@ export default class GGExpress {
153
162
  RS extends R["structure"],
154
163
  KR extends keyof RS,
155
164
  P extends M["parameter"],
156
- PP extends R["parameter"]
165
+ PP extends R["parameter"],
166
+ J extends M["isStructurePartial"]
157
167
  >(
158
168
  url: `/api/${string}`,
159
169
  options: {
@@ -162,8 +172,8 @@ export default class GGExpress {
162
172
  },
163
173
  ...middlewares: Array<
164
174
  (
165
- req: MyRequest<M["dataType"], T, K, P>,
166
- 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>,
167
177
  next: NextFunction
168
178
  ) => any
169
179
  >
@@ -179,7 +189,8 @@ export default class GGExpress {
179
189
  RS extends R["structure"],
180
190
  KR extends keyof RS,
181
191
  P extends M["parameter"],
182
- PP extends R["parameter"]
192
+ PP extends R["parameter"],
193
+ J extends M["isStructurePartial"]
183
194
  >(
184
195
  url: `/api/${string}`,
185
196
  options: {
@@ -188,8 +199,8 @@ export default class GGExpress {
188
199
  },
189
200
  ...middlewares: Array<
190
201
  (
191
- req: MyRequest<M["dataType"], T, K, P>,
192
- 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>,
193
204
  next: NextFunction
194
205
  ) => any
195
206
  >
@@ -204,7 +215,8 @@ export default class GGExpress {
204
215
  RS extends R["structure"],
205
216
  KR extends keyof RS,
206
217
  P extends M["parameter"],
207
- PP extends R["parameter"]
218
+ PP extends R["parameter"],
219
+ J extends M["isStructurePartial"]
208
220
  >(
209
221
  url: `/api/${string}`,
210
222
  options: {
@@ -213,8 +225,8 @@ export default class GGExpress {
213
225
  },
214
226
  ...middlewares: Array<
215
227
  (
216
- req: MyRequest<M["dataType"], T, K, P>,
217
- 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>,
218
230
  next: NextFunction
219
231
  ) => any
220
232
  >
@@ -229,7 +241,8 @@ export default class GGExpress {
229
241
  RS extends R["structure"],
230
242
  KR extends keyof RS,
231
243
  P extends M["parameter"],
232
- PP extends R["parameter"]
244
+ PP extends R["parameter"],
245
+ J extends M["isStructurePartial"]
233
246
  >(
234
247
  url: `/api/${string}`,
235
248
  options: {
@@ -238,8 +251,8 @@ export default class GGExpress {
238
251
  },
239
252
  ...middlewares: Array<
240
253
  (
241
- req: MyRequest<M["dataType"], T, K, P>,
242
- 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>,
243
256
  next: NextFunction
244
257
  ) => any
245
258
  >