@nestia/sdk 2.5.4 → 2.5.5

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,467 +1,467 @@
1
- import * as Constants from "@nestjs/common/constants";
2
- import { VERSION_NEUTRAL, VersionValue } from "@nestjs/common/interfaces";
3
- import "reflect-metadata";
4
- import { equal } from "tstl/ranges/module";
5
-
6
- import { IController } from "../structures/IController";
7
- import { IErrorReport } from "../structures/IErrorReport";
8
- import { INestiaProject } from "../structures/INestiaProject";
9
- import { ParamCategory } from "../structures/ParamCategory";
10
- import { ArrayUtil } from "../utils/ArrayUtil";
11
- import { PathAnalyzer } from "./PathAnalyzer";
12
- import { SecurityAnalyzer } from "./SecurityAnalyzer";
13
-
14
- type IModule = {
15
- [key: string]: any;
16
- };
17
-
18
- export namespace ReflectAnalyzer {
19
- export const analyze =
20
- (project: INestiaProject) =>
21
- async (
22
- unique: WeakSet<any>,
23
- file: string,
24
- prefixes: string[],
25
- target?: Function,
26
- ): Promise<IController[]> => {
27
- const module: IModule = await (async () => {
28
- try {
29
- return await import(file);
30
- } catch (exp) {
31
- console.log(
32
- ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>",
33
- );
34
- console.log(`Error on "${file}" file. Check your code.`);
35
- console.log(exp);
36
- console.log(
37
- ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>",
38
- );
39
- process.exit(-1);
40
- }
41
- })();
42
- const ret: IController[] = [];
43
-
44
- for (const [key, value] of Object.entries(module)) {
45
- if (typeof value !== "function" || unique.has(value)) continue;
46
- else if ((target ?? value) !== value) continue;
47
- else unique.add(value);
48
-
49
- const result: IController | null = _Analyze_controller(project)(
50
- file,
51
- key,
52
- value,
53
- prefixes,
54
- );
55
- if (result !== null) ret.push(result);
56
- }
57
- return ret;
58
- };
59
-
60
- /* ---------------------------------------------------------
61
- CONTROLLER
62
- --------------------------------------------------------- */
63
- const _Analyze_controller =
64
- (project: INestiaProject) =>
65
- (
66
- file: string,
67
- name: string,
68
- creator: any,
69
- prefixes: string[],
70
- ): IController | null => {
71
- //----
72
- // VALIDATIONS
73
- //----
74
- // MUST BE TYPE OF A CREATOR WHO HAS THE CONSTRUCTOR
75
- if (
76
- !(
77
- creator instanceof Function && creator.constructor instanceof Function
78
- )
79
- )
80
- return null;
81
- // MUST HAVE THOSE MATADATA
82
- else if (
83
- ArrayUtil.has(
84
- Reflect.getMetadataKeys(creator),
85
- Constants.PATH_METADATA,
86
- Constants.HOST_METADATA,
87
- Constants.SCOPE_OPTIONS_METADATA,
88
- ) === false
89
- )
90
- return null;
91
-
92
- //----
93
- // CONSTRUCTION
94
- //----
95
- // BASIC INFO
96
- const meta: IController = {
97
- file,
98
- name,
99
- functions: [],
100
- prefixes,
101
- paths: _Get_paths(creator).filter((str) => {
102
- if (str.includes("*") === true) {
103
- project.warnings.push({
104
- file,
105
- controller: name,
106
- function: null,
107
- message: "@nestia/sdk does not compose wildcard controller.",
108
- });
109
- return false;
110
- }
111
- return true;
112
- }),
113
- versions: _Get_versions(creator),
114
- security: _Get_securities(creator),
115
- swaggerTgas: Reflect.getMetadata("swagger/apiUseTags", creator) ?? [],
116
- };
117
-
118
- // PARSE CHILDREN DATA
119
- for (const tuple of _Get_prototype_entries(creator)) {
120
- const child: IController.IFunction | null = _Analyze_function(project)(
121
- creator.prototype,
122
- meta,
123
- ...tuple,
124
- );
125
- if (child !== null) meta.functions.push(child);
126
- }
127
-
128
- // RETURNS
129
- return meta;
130
- };
131
-
132
- function _Get_prototype_entries(creator: any): Array<[string, unknown]> {
133
- const keyList = Object.getOwnPropertyNames(creator.prototype);
134
- const entries: Array<[string, unknown]> = keyList.map((key) => [
135
- key,
136
- creator.prototype[key],
137
- ]);
138
-
139
- const parent = Object.getPrototypeOf(creator);
140
- if (parent.prototype !== undefined)
141
- entries.push(..._Get_prototype_entries(parent));
142
-
143
- return entries;
144
- }
145
-
146
- function _Get_paths(target: any): string[] {
147
- const value: string | string[] = Reflect.getMetadata(
148
- Constants.PATH_METADATA,
149
- target,
150
- );
151
- if (typeof value === "string") return [value];
152
- else if (value.length === 0) return [""];
153
- else return value;
154
- }
155
-
156
- function _Get_versions(
157
- target: any,
158
- ):
159
- | Array<Exclude<VersionValue, Array<string | typeof VERSION_NEUTRAL>>>
160
- | undefined {
161
- const value: VersionValue | undefined = Reflect.getMetadata(
162
- Constants.VERSION_METADATA,
163
- target,
164
- );
165
- return value === undefined || Array.isArray(value) ? value : [value];
166
- }
167
-
168
- function _Get_securities(value: any): Record<string, string[]>[] {
169
- const entire: Record<string, string[]>[] | undefined = Reflect.getMetadata(
170
- "swagger/apiSecurity",
171
- value,
172
- );
173
- return entire ? SecurityAnalyzer.merge(...entire) : [];
174
- }
175
-
176
- function _Get_exceptions(
177
- value: any,
178
- ): Record<number | "2XX" | "3XX" | "4XX" | "5XX", IController.IException> {
179
- const entire: IController.IException[] | undefined = Reflect.getMetadata(
180
- "nestia/TypedException",
181
- value,
182
- );
183
- return Object.fromEntries(
184
- (entire ?? []).map((exp) => [exp.status, exp]),
185
- ) as Record<number | "2XX" | "3XX" | "4XX" | "5XX", IController.IException>;
186
- }
187
-
188
- /* ---------------------------------------------------------
189
- FUNCTION
190
- --------------------------------------------------------- */
191
- const _Analyze_function =
192
- (project: INestiaProject) =>
193
- (
194
- classProto: any,
195
- controller: IController,
196
- name: string,
197
- proto: any,
198
- ): IController.IFunction | null => {
199
- //----
200
- // VALIDATIONS
201
- //----
202
- // MUST BE TYPE OF A FUNCTION
203
- if (!(proto instanceof Function)) return null;
204
- // MUST HAVE THOSE METADATE
205
- else if (
206
- ArrayUtil.has(
207
- Reflect.getMetadataKeys(proto),
208
- Constants.PATH_METADATA,
209
- Constants.METHOD_METADATA,
210
- ) === false
211
- )
212
- return null;
213
-
214
- const errors: IErrorReport[] = [];
215
-
216
- //----
217
- // CONSTRUCTION
218
- //----
219
- // BASIC INFO
220
- const encrypted: boolean =
221
- Reflect.getMetadata(Constants.INTERCEPTORS_METADATA, proto)?.[0]
222
- ?.constructor?.name === "EncryptedRouteInterceptor";
223
- const query: boolean =
224
- Reflect.getMetadata(Constants.INTERCEPTORS_METADATA, proto)?.[0]
225
- ?.constructor?.name === "TypedQueryRouteInterceptor";
226
- const method: string =
227
- METHODS[Reflect.getMetadata(Constants.METHOD_METADATA, proto)];
228
- if (method === undefined || method === "OPTIONS") return null;
229
-
230
- const parameters: IController.IParameter[] = (() => {
231
- const nestParameters: NestParameters | undefined = Reflect.getMetadata(
232
- Constants.ROUTE_ARGS_METADATA,
233
- classProto.constructor,
234
- name,
235
- );
236
- if (nestParameters === undefined) return [];
237
-
238
- const output: IController.IParameter[] = [];
239
- for (const tuple of Object.entries(nestParameters)) {
240
- const child: IController.IParameter | null = _Analyze_parameter(
241
- ...tuple,
242
- );
243
- if (child !== null) output.push(child);
244
- }
245
- return output.sort((x, y) => x.index - y.index);
246
- })();
247
-
248
- // VALIDATE BODY
249
- const body: IController.IParameter | undefined = parameters.find(
250
- (param) => param.category === "body",
251
- );
252
- if (body !== undefined && (method === "GET" || method === "HEAD")) {
253
- project.errors.push({
254
- file: controller.file,
255
- controller: controller.name,
256
- function: name,
257
- message: `"body" parameter cannot be used in the "${method}" method.`,
258
- });
259
- return null;
260
- }
261
-
262
- // DO CONSTRUCT
263
- const meta: IController.IFunction = {
264
- name,
265
- method: method === "ALL" ? "POST" : method,
266
- paths: _Get_paths(proto).filter((str) => {
267
- if (str.includes("*") === true) {
268
- project.warnings.push({
269
- file: controller.file,
270
- controller: controller.name,
271
- function: name,
272
- message: "@nestia/sdk does not compose wildcard method.",
273
- });
274
- return false;
275
- }
276
- return true;
277
- }),
278
- versions: _Get_versions(proto),
279
- parameters,
280
- status: Reflect.getMetadata(Constants.HTTP_CODE_METADATA, proto),
281
- encrypted,
282
- contentType: encrypted
283
- ? "text/plain"
284
- : query
285
- ? "application/x-www-form-urlencoded"
286
- : Reflect.getMetadata(Constants.HEADERS_METADATA, proto)?.find(
287
- (h: Record<string, string>) =>
288
- typeof h?.name === "string" &&
289
- typeof h?.value === "string" &&
290
- h.name.toLowerCase() === "content-type",
291
- )?.value ?? "application/json",
292
- security: _Get_securities(proto),
293
- exceptions: _Get_exceptions(proto),
294
- swaggerTags: [
295
- ...new Set([
296
- ...controller.swaggerTgas,
297
- ...(Reflect.getMetadata("swagger/apiUseTags", proto) ?? []),
298
- ]),
299
- ],
300
- };
301
-
302
- // VALIDATE PATH ARGUMENTS
303
- for (const controllerLocation of controller.paths)
304
- for (const metaLocation of meta.paths) {
305
- // NORMALIZE LOCATION
306
- const location: string = PathAnalyzer.join(
307
- controllerLocation,
308
- metaLocation,
309
- );
310
- if (location.includes("*")) continue;
311
-
312
- // LIST UP PARAMETERS
313
- const binded: string[] | null = PathAnalyzer.parameters(location);
314
- if (binded === null) {
315
- project.errors.push({
316
- file: controller.file,
317
- controller: controller.name,
318
- function: name,
319
- message: `invalid path ("${location}")`,
320
- });
321
- continue;
322
- }
323
- const parameters: string[] = meta.parameters
324
- .filter((param) => param.category === "param")
325
- .map((param) => param.field!)
326
- .sort();
327
-
328
- // DO VALIDATE
329
- if (equal(binded.sort(), parameters) === false)
330
- errors.push({
331
- file: controller.file,
332
- controller: controller.name,
333
- function: name,
334
- message: `binded arguments in the "path" between function's decorator and parameters' decorators are different (function: [${binded.join(
335
- ", ",
336
- )}], parameters: [${parameters.join(", ")}]).`,
337
- });
338
- }
339
-
340
- // RETURNS
341
- if (errors.length) {
342
- project.errors.push(...errors);
343
- return null;
344
- }
345
- return meta;
346
- };
347
-
348
- /* ---------------------------------------------------------
349
- PARAMETER
350
- --------------------------------------------------------- */
351
- function _Analyze_parameter(
352
- key: string,
353
- param: INestParam,
354
- ): IController.IParameter | null {
355
- const symbol: string = key.split(":")[0];
356
- if (symbol.indexOf("__custom") !== -1)
357
- return _Analyze_custom_parameter(param);
358
-
359
- const typeIndex: number = Number(symbol[0]);
360
- if (isNaN(typeIndex) === true) return null;
361
-
362
- const type: ParamCategory | undefined = NEST_PARAMETER_TYPES[typeIndex];
363
- if (type === undefined) return null;
364
-
365
- return {
366
- custom: false,
367
- name: key,
368
- category: type,
369
- index: param.index,
370
- field: param.data,
371
- };
372
- }
373
-
374
- function _Analyze_custom_parameter(
375
- param: INestParam,
376
- ): IController.IParameter | null {
377
- if (param.factory === undefined) return null;
378
- else if (
379
- param.factory.name === "EncryptedBody" ||
380
- param.factory.name === "PlainBody" ||
381
- param.factory.name === "TypedQueryBody" ||
382
- param.factory.name === "TypedBody" ||
383
- param.factory.name === "TypedFormDataBody"
384
- )
385
- return {
386
- custom: true,
387
- category: "body",
388
- index: param.index,
389
- name: param.name,
390
- field: param.data,
391
- encrypted: param.factory.name === "EncryptedBody",
392
- contentType:
393
- param.factory.name === "PlainBody" ||
394
- param.factory.name === "EncryptedBody"
395
- ? "text/plain"
396
- : param.factory.name === "TypedQueryBody"
397
- ? "application/x-www-form-urlencoded"
398
- : param.factory.name === "TypedFormDataBody"
399
- ? "multipart/form-data"
400
- : "application/json",
401
- };
402
- else if (param.factory.name === "TypedHeaders")
403
- return {
404
- custom: true,
405
- category: "headers",
406
- name: param.name,
407
- index: param.index,
408
- field: param.data,
409
- };
410
- else if (param.factory.name === "TypedParam")
411
- return {
412
- custom: true,
413
- category: "param",
414
- name: param.name,
415
- index: param.index,
416
- field: param.data,
417
- };
418
- else if (param.factory.name === "TypedQuery")
419
- return {
420
- custom: true,
421
- name: param.name,
422
- category: "query",
423
- index: param.index,
424
- field: undefined,
425
- };
426
- else return null;
427
- }
428
-
429
- type NestParameters = {
430
- [key: string]: INestParam;
431
- };
432
-
433
- interface INestParam {
434
- name: string;
435
- index: number;
436
- factory?: (...args: any) => any;
437
- data: string | undefined;
438
- }
439
- }
440
-
441
- // node_modules/@nestjs/common/lib/enums/request-method.enum.ts
442
- const METHODS = [
443
- "GET",
444
- "POST",
445
- "PUT",
446
- "DELETE",
447
- "PATCH",
448
- "ALL",
449
- "OPTIONS",
450
- "HEAD",
451
- ];
452
-
453
- // node_modules/@nestjs/common/lib/route-paramtypes.enum.ts
454
- const NEST_PARAMETER_TYPES = [
455
- undefined,
456
- undefined,
457
- undefined,
458
- "body",
459
- "query",
460
- "param",
461
- "headers",
462
- undefined,
463
- undefined,
464
- undefined,
465
- undefined,
466
- undefined,
467
- ] as const;
1
+ import * as Constants from "@nestjs/common/constants";
2
+ import { VERSION_NEUTRAL, VersionValue } from "@nestjs/common/interfaces";
3
+ import "reflect-metadata";
4
+ import { equal } from "tstl/ranges/module";
5
+
6
+ import { IController } from "../structures/IController";
7
+ import { IErrorReport } from "../structures/IErrorReport";
8
+ import { INestiaProject } from "../structures/INestiaProject";
9
+ import { ParamCategory } from "../structures/ParamCategory";
10
+ import { ArrayUtil } from "../utils/ArrayUtil";
11
+ import { PathAnalyzer } from "./PathAnalyzer";
12
+ import { SecurityAnalyzer } from "./SecurityAnalyzer";
13
+
14
+ type IModule = {
15
+ [key: string]: any;
16
+ };
17
+
18
+ export namespace ReflectAnalyzer {
19
+ export const analyze =
20
+ (project: INestiaProject) =>
21
+ async (
22
+ unique: WeakSet<any>,
23
+ file: string,
24
+ prefixes: string[],
25
+ target?: Function,
26
+ ): Promise<IController[]> => {
27
+ const module: IModule = await (async () => {
28
+ try {
29
+ return await import(file);
30
+ } catch (exp) {
31
+ console.log(
32
+ ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>",
33
+ );
34
+ console.log(`Error on "${file}" file. Check your code.`);
35
+ console.log(exp);
36
+ console.log(
37
+ ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>",
38
+ );
39
+ process.exit(-1);
40
+ }
41
+ })();
42
+ const ret: IController[] = [];
43
+
44
+ for (const [key, value] of Object.entries(module)) {
45
+ if (typeof value !== "function" || unique.has(value)) continue;
46
+ else if ((target ?? value) !== value) continue;
47
+ else unique.add(value);
48
+
49
+ const result: IController | null = _Analyze_controller(project)(
50
+ file,
51
+ key,
52
+ value,
53
+ prefixes,
54
+ );
55
+ if (result !== null) ret.push(result);
56
+ }
57
+ return ret;
58
+ };
59
+
60
+ /* ---------------------------------------------------------
61
+ CONTROLLER
62
+ --------------------------------------------------------- */
63
+ const _Analyze_controller =
64
+ (project: INestiaProject) =>
65
+ (
66
+ file: string,
67
+ name: string,
68
+ creator: any,
69
+ prefixes: string[],
70
+ ): IController | null => {
71
+ //----
72
+ // VALIDATIONS
73
+ //----
74
+ // MUST BE TYPE OF A CREATOR WHO HAS THE CONSTRUCTOR
75
+ if (
76
+ !(
77
+ creator instanceof Function && creator.constructor instanceof Function
78
+ )
79
+ )
80
+ return null;
81
+ // MUST HAVE THOSE MATADATA
82
+ else if (
83
+ ArrayUtil.has(
84
+ Reflect.getMetadataKeys(creator),
85
+ Constants.PATH_METADATA,
86
+ Constants.HOST_METADATA,
87
+ Constants.SCOPE_OPTIONS_METADATA,
88
+ ) === false
89
+ )
90
+ return null;
91
+
92
+ //----
93
+ // CONSTRUCTION
94
+ //----
95
+ // BASIC INFO
96
+ const meta: IController = {
97
+ file,
98
+ name,
99
+ functions: [],
100
+ prefixes,
101
+ paths: _Get_paths(creator).filter((str) => {
102
+ if (str.includes("*") === true) {
103
+ project.warnings.push({
104
+ file,
105
+ controller: name,
106
+ function: null,
107
+ message: "@nestia/sdk does not compose wildcard controller.",
108
+ });
109
+ return false;
110
+ }
111
+ return true;
112
+ }),
113
+ versions: _Get_versions(creator),
114
+ security: _Get_securities(creator),
115
+ swaggerTgas: Reflect.getMetadata("swagger/apiUseTags", creator) ?? [],
116
+ };
117
+
118
+ // PARSE CHILDREN DATA
119
+ for (const tuple of _Get_prototype_entries(creator)) {
120
+ const child: IController.IFunction | null = _Analyze_function(project)(
121
+ creator.prototype,
122
+ meta,
123
+ ...tuple,
124
+ );
125
+ if (child !== null) meta.functions.push(child);
126
+ }
127
+
128
+ // RETURNS
129
+ return meta;
130
+ };
131
+
132
+ function _Get_prototype_entries(creator: any): Array<[string, unknown]> {
133
+ const keyList = Object.getOwnPropertyNames(creator.prototype);
134
+ const entries: Array<[string, unknown]> = keyList.map((key) => [
135
+ key,
136
+ creator.prototype[key],
137
+ ]);
138
+
139
+ const parent = Object.getPrototypeOf(creator);
140
+ if (parent.prototype !== undefined)
141
+ entries.push(..._Get_prototype_entries(parent));
142
+
143
+ return entries;
144
+ }
145
+
146
+ function _Get_paths(target: any): string[] {
147
+ const value: string | string[] = Reflect.getMetadata(
148
+ Constants.PATH_METADATA,
149
+ target,
150
+ );
151
+ if (typeof value === "string") return [value];
152
+ else if (value.length === 0) return [""];
153
+ else return value;
154
+ }
155
+
156
+ function _Get_versions(
157
+ target: any,
158
+ ):
159
+ | Array<Exclude<VersionValue, Array<string | typeof VERSION_NEUTRAL>>>
160
+ | undefined {
161
+ const value: VersionValue | undefined = Reflect.getMetadata(
162
+ Constants.VERSION_METADATA,
163
+ target,
164
+ );
165
+ return value === undefined || Array.isArray(value) ? value : [value];
166
+ }
167
+
168
+ function _Get_securities(value: any): Record<string, string[]>[] {
169
+ const entire: Record<string, string[]>[] | undefined = Reflect.getMetadata(
170
+ "swagger/apiSecurity",
171
+ value,
172
+ );
173
+ return entire ? SecurityAnalyzer.merge(...entire) : [];
174
+ }
175
+
176
+ function _Get_exceptions(
177
+ value: any,
178
+ ): Record<number | "2XX" | "3XX" | "4XX" | "5XX", IController.IException> {
179
+ const entire: IController.IException[] | undefined = Reflect.getMetadata(
180
+ "nestia/TypedException",
181
+ value,
182
+ );
183
+ return Object.fromEntries(
184
+ (entire ?? []).map((exp) => [exp.status, exp]),
185
+ ) as Record<number | "2XX" | "3XX" | "4XX" | "5XX", IController.IException>;
186
+ }
187
+
188
+ /* ---------------------------------------------------------
189
+ FUNCTION
190
+ --------------------------------------------------------- */
191
+ const _Analyze_function =
192
+ (project: INestiaProject) =>
193
+ (
194
+ classProto: any,
195
+ controller: IController,
196
+ name: string,
197
+ proto: any,
198
+ ): IController.IFunction | null => {
199
+ //----
200
+ // VALIDATIONS
201
+ //----
202
+ // MUST BE TYPE OF A FUNCTION
203
+ if (!(proto instanceof Function)) return null;
204
+ // MUST HAVE THOSE METADATE
205
+ else if (
206
+ ArrayUtil.has(
207
+ Reflect.getMetadataKeys(proto),
208
+ Constants.PATH_METADATA,
209
+ Constants.METHOD_METADATA,
210
+ ) === false
211
+ )
212
+ return null;
213
+
214
+ const errors: IErrorReport[] = [];
215
+
216
+ //----
217
+ // CONSTRUCTION
218
+ //----
219
+ // BASIC INFO
220
+ const encrypted: boolean =
221
+ Reflect.getMetadata(Constants.INTERCEPTORS_METADATA, proto)?.[0]
222
+ ?.constructor?.name === "EncryptedRouteInterceptor";
223
+ const query: boolean =
224
+ Reflect.getMetadata(Constants.INTERCEPTORS_METADATA, proto)?.[0]
225
+ ?.constructor?.name === "TypedQueryRouteInterceptor";
226
+ const method: string =
227
+ METHODS[Reflect.getMetadata(Constants.METHOD_METADATA, proto)];
228
+ if (method === undefined || method === "OPTIONS") return null;
229
+
230
+ const parameters: IController.IParameter[] = (() => {
231
+ const nestParameters: NestParameters | undefined = Reflect.getMetadata(
232
+ Constants.ROUTE_ARGS_METADATA,
233
+ classProto.constructor,
234
+ name,
235
+ );
236
+ if (nestParameters === undefined) return [];
237
+
238
+ const output: IController.IParameter[] = [];
239
+ for (const tuple of Object.entries(nestParameters)) {
240
+ const child: IController.IParameter | null = _Analyze_parameter(
241
+ ...tuple,
242
+ );
243
+ if (child !== null) output.push(child);
244
+ }
245
+ return output.sort((x, y) => x.index - y.index);
246
+ })();
247
+
248
+ // VALIDATE BODY
249
+ const body: IController.IParameter | undefined = parameters.find(
250
+ (param) => param.category === "body",
251
+ );
252
+ if (body !== undefined && (method === "GET" || method === "HEAD")) {
253
+ project.errors.push({
254
+ file: controller.file,
255
+ controller: controller.name,
256
+ function: name,
257
+ message: `"body" parameter cannot be used in the "${method}" method.`,
258
+ });
259
+ return null;
260
+ }
261
+
262
+ // DO CONSTRUCT
263
+ const meta: IController.IFunction = {
264
+ name,
265
+ method: method === "ALL" ? "POST" : method,
266
+ paths: _Get_paths(proto).filter((str) => {
267
+ if (str.includes("*") === true) {
268
+ project.warnings.push({
269
+ file: controller.file,
270
+ controller: controller.name,
271
+ function: name,
272
+ message: "@nestia/sdk does not compose wildcard method.",
273
+ });
274
+ return false;
275
+ }
276
+ return true;
277
+ }),
278
+ versions: _Get_versions(proto),
279
+ parameters,
280
+ status: Reflect.getMetadata(Constants.HTTP_CODE_METADATA, proto),
281
+ encrypted,
282
+ contentType: encrypted
283
+ ? "text/plain"
284
+ : query
285
+ ? "application/x-www-form-urlencoded"
286
+ : Reflect.getMetadata(Constants.HEADERS_METADATA, proto)?.find(
287
+ (h: Record<string, string>) =>
288
+ typeof h?.name === "string" &&
289
+ typeof h?.value === "string" &&
290
+ h.name.toLowerCase() === "content-type",
291
+ )?.value ?? "application/json",
292
+ security: _Get_securities(proto),
293
+ exceptions: _Get_exceptions(proto),
294
+ swaggerTags: [
295
+ ...new Set([
296
+ ...controller.swaggerTgas,
297
+ ...(Reflect.getMetadata("swagger/apiUseTags", proto) ?? []),
298
+ ]),
299
+ ],
300
+ };
301
+
302
+ // VALIDATE PATH ARGUMENTS
303
+ for (const controllerLocation of controller.paths)
304
+ for (const metaLocation of meta.paths) {
305
+ // NORMALIZE LOCATION
306
+ const location: string = PathAnalyzer.join(
307
+ controllerLocation,
308
+ metaLocation,
309
+ );
310
+ if (location.includes("*")) continue;
311
+
312
+ // LIST UP PARAMETERS
313
+ const binded: string[] | null = PathAnalyzer.parameters(location);
314
+ if (binded === null) {
315
+ project.errors.push({
316
+ file: controller.file,
317
+ controller: controller.name,
318
+ function: name,
319
+ message: `invalid path ("${location}")`,
320
+ });
321
+ continue;
322
+ }
323
+ const parameters: string[] = meta.parameters
324
+ .filter((param) => param.category === "param")
325
+ .map((param) => param.field!)
326
+ .sort();
327
+
328
+ // DO VALIDATE
329
+ if (equal(binded.sort(), parameters) === false)
330
+ errors.push({
331
+ file: controller.file,
332
+ controller: controller.name,
333
+ function: name,
334
+ message: `binded arguments in the "path" between function's decorator and parameters' decorators are different (function: [${binded.join(
335
+ ", ",
336
+ )}], parameters: [${parameters.join(", ")}]).`,
337
+ });
338
+ }
339
+
340
+ // RETURNS
341
+ if (errors.length) {
342
+ project.errors.push(...errors);
343
+ return null;
344
+ }
345
+ return meta;
346
+ };
347
+
348
+ /* ---------------------------------------------------------
349
+ PARAMETER
350
+ --------------------------------------------------------- */
351
+ function _Analyze_parameter(
352
+ key: string,
353
+ param: INestParam,
354
+ ): IController.IParameter | null {
355
+ const symbol: string = key.split(":")[0];
356
+ if (symbol.indexOf("__custom") !== -1)
357
+ return _Analyze_custom_parameter(param);
358
+
359
+ const typeIndex: number = Number(symbol[0]);
360
+ if (isNaN(typeIndex) === true) return null;
361
+
362
+ const type: ParamCategory | undefined = NEST_PARAMETER_TYPES[typeIndex];
363
+ if (type === undefined) return null;
364
+
365
+ return {
366
+ custom: false,
367
+ name: key,
368
+ category: type,
369
+ index: param.index,
370
+ field: param.data,
371
+ };
372
+ }
373
+
374
+ function _Analyze_custom_parameter(
375
+ param: INestParam,
376
+ ): IController.IParameter | null {
377
+ if (param.factory === undefined) return null;
378
+ else if (
379
+ param.factory.name === "EncryptedBody" ||
380
+ param.factory.name === "PlainBody" ||
381
+ param.factory.name === "TypedQueryBody" ||
382
+ param.factory.name === "TypedBody" ||
383
+ param.factory.name === "TypedFormDataBody"
384
+ )
385
+ return {
386
+ custom: true,
387
+ category: "body",
388
+ index: param.index,
389
+ name: param.name,
390
+ field: param.data,
391
+ encrypted: param.factory.name === "EncryptedBody",
392
+ contentType:
393
+ param.factory.name === "PlainBody" ||
394
+ param.factory.name === "EncryptedBody"
395
+ ? "text/plain"
396
+ : param.factory.name === "TypedQueryBody"
397
+ ? "application/x-www-form-urlencoded"
398
+ : param.factory.name === "TypedFormDataBody"
399
+ ? "multipart/form-data"
400
+ : "application/json",
401
+ };
402
+ else if (param.factory.name === "TypedHeaders")
403
+ return {
404
+ custom: true,
405
+ category: "headers",
406
+ name: param.name,
407
+ index: param.index,
408
+ field: param.data,
409
+ };
410
+ else if (param.factory.name === "TypedParam")
411
+ return {
412
+ custom: true,
413
+ category: "param",
414
+ name: param.name,
415
+ index: param.index,
416
+ field: param.data,
417
+ };
418
+ else if (param.factory.name === "TypedQuery")
419
+ return {
420
+ custom: true,
421
+ name: param.name,
422
+ category: "query",
423
+ index: param.index,
424
+ field: undefined,
425
+ };
426
+ else return null;
427
+ }
428
+
429
+ type NestParameters = {
430
+ [key: string]: INestParam;
431
+ };
432
+
433
+ interface INestParam {
434
+ name: string;
435
+ index: number;
436
+ factory?: (...args: any) => any;
437
+ data: string | undefined;
438
+ }
439
+ }
440
+
441
+ // node_modules/@nestjs/common/lib/enums/request-method.enum.ts
442
+ const METHODS = [
443
+ "GET",
444
+ "POST",
445
+ "PUT",
446
+ "DELETE",
447
+ "PATCH",
448
+ "ALL",
449
+ "OPTIONS",
450
+ "HEAD",
451
+ ];
452
+
453
+ // node_modules/@nestjs/common/lib/route-paramtypes.enum.ts
454
+ const NEST_PARAMETER_TYPES = [
455
+ undefined,
456
+ undefined,
457
+ undefined,
458
+ "body",
459
+ "query",
460
+ "param",
461
+ "headers",
462
+ undefined,
463
+ undefined,
464
+ undefined,
465
+ undefined,
466
+ undefined,
467
+ ] as const;