@nestia/sdk 3.0.0-dev.20231209 → 3.0.0-dev.20240412

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.
Files changed (168) hide show
  1. package/README.md +12 -9
  2. package/assets/config/nestia.config.ts +82 -79
  3. package/lib/INestiaConfig.d.ts +28 -6
  4. package/lib/NestiaSdkApplication.js +12 -10
  5. package/lib/NestiaSdkApplication.js.map +1 -1
  6. package/lib/analyses/ConfigAnalyzer.js +1 -1
  7. package/lib/analyses/ConfigAnalyzer.js.map +1 -1
  8. package/lib/analyses/ControllerAnalyzer.js +30 -15
  9. package/lib/analyses/ControllerAnalyzer.js.map +1 -1
  10. package/lib/analyses/ExceptionAnalyzer.js +35 -6
  11. package/lib/analyses/ExceptionAnalyzer.js.map +1 -1
  12. package/lib/analyses/ImportAnalyzer.d.ts +1 -2
  13. package/lib/analyses/ImportAnalyzer.js +2 -2
  14. package/lib/analyses/ImportAnalyzer.js.map +1 -1
  15. package/lib/analyses/PathAnalyzer.d.ts +2 -4
  16. package/lib/analyses/PathAnalyzer.js +27 -11
  17. package/lib/analyses/PathAnalyzer.js.map +1 -1
  18. package/lib/analyses/ReflectAnalyzer.js +34 -22
  19. package/lib/analyses/ReflectAnalyzer.js.map +1 -1
  20. package/lib/analyses/SecurityAnalyzer.js +13 -8
  21. package/lib/analyses/SecurityAnalyzer.js.map +1 -1
  22. package/lib/executable/internal/NestiaConfigLoader.js +300 -220
  23. package/lib/executable/internal/NestiaConfigLoader.js.map +1 -1
  24. package/lib/executable/sdk.js +11 -11
  25. package/lib/generates/CloneGenerator.d.ts +6 -0
  26. package/lib/generates/CloneGenerator.js +62 -0
  27. package/lib/generates/CloneGenerator.js.map +1 -0
  28. package/lib/generates/E2eGenerator.d.ts +2 -1
  29. package/lib/generates/E2eGenerator.js +2 -2
  30. package/lib/generates/E2eGenerator.js.map +1 -1
  31. package/lib/generates/SdkGenerator.js +3 -11
  32. package/lib/generates/SdkGenerator.js.map +1 -1
  33. package/lib/generates/SwaggerGenerator.d.ts +2 -0
  34. package/lib/generates/SwaggerGenerator.js +119 -62
  35. package/lib/generates/SwaggerGenerator.js.map +1 -1
  36. package/lib/generates/internal/E2eFileProgrammer.d.ts +2 -1
  37. package/lib/generates/internal/E2eFileProgrammer.js +49 -53
  38. package/lib/generates/internal/E2eFileProgrammer.js.map +1 -1
  39. package/lib/generates/internal/FilePrinter.d.ts +10 -0
  40. package/lib/generates/internal/FilePrinter.js +46 -0
  41. package/lib/generates/internal/FilePrinter.js.map +1 -0
  42. package/lib/{utils → generates/internal}/ImportDictionary.d.ts +2 -1
  43. package/lib/{utils → generates/internal}/ImportDictionary.js +20 -14
  44. package/lib/generates/internal/ImportDictionary.js.map +1 -0
  45. package/lib/generates/internal/SdkAliasCollection.d.ts +12 -0
  46. package/lib/generates/internal/SdkAliasCollection.js +97 -0
  47. package/lib/generates/internal/SdkAliasCollection.js.map +1 -0
  48. package/lib/generates/internal/SdkCloneProgrammer.d.ts +12 -0
  49. package/lib/generates/internal/SdkCloneProgrammer.js +99 -0
  50. package/lib/generates/internal/SdkCloneProgrammer.js.map +1 -0
  51. package/lib/generates/internal/SdkFileProgrammer.d.ts +2 -1
  52. package/lib/generates/internal/SdkFileProgrammer.js +27 -28
  53. package/lib/generates/internal/SdkFileProgrammer.js.map +1 -1
  54. package/lib/generates/internal/SdkFunctionProgrammer.d.ts +7 -2
  55. package/lib/generates/internal/SdkFunctionProgrammer.js +115 -322
  56. package/lib/generates/internal/SdkFunctionProgrammer.js.map +1 -1
  57. package/lib/generates/internal/SdkImportWizard.d.ts +1 -1
  58. package/lib/generates/internal/SdkNamespaceProgrammer.d.ts +11 -0
  59. package/lib/generates/internal/SdkNamespaceProgrammer.js +180 -0
  60. package/lib/generates/internal/SdkNamespaceProgrammer.js.map +1 -0
  61. package/lib/generates/internal/SdkRouteProgrammer.d.ts +7 -0
  62. package/lib/generates/internal/SdkRouteProgrammer.js +55 -0
  63. package/lib/generates/internal/SdkRouteProgrammer.js.map +1 -0
  64. package/lib/generates/internal/SdkSimulationProgrammer.d.ts +8 -2
  65. package/lib/generates/internal/SdkSimulationProgrammer.js +103 -89
  66. package/lib/generates/internal/SdkSimulationProgrammer.js.map +1 -1
  67. package/lib/generates/internal/SdkTypeProgrammer.d.ts +9 -0
  68. package/lib/generates/internal/SdkTypeProgrammer.js +228 -0
  69. package/lib/generates/internal/SdkTypeProgrammer.js.map +1 -0
  70. package/lib/generates/internal/SwaggerSchemaGenerator.d.ts +4 -4
  71. package/lib/generates/internal/SwaggerSchemaGenerator.js +30 -28
  72. package/lib/generates/internal/SwaggerSchemaGenerator.js.map +1 -1
  73. package/lib/structures/IController.d.ts +4 -2
  74. package/lib/structures/IRoute.d.ts +5 -4
  75. package/lib/structures/ISwaggerLazyProperty.d.ts +2 -2
  76. package/lib/structures/ISwaggerLazySchema.d.ts +2 -2
  77. package/lib/structures/ParamCategory.d.ts +1 -1
  78. package/lib/structures/TypeEntry.js +2 -2
  79. package/lib/structures/TypeEntry.js.map +1 -1
  80. package/lib/utils/StringUtil.d.ts +3 -0
  81. package/lib/utils/StringUtil.js +8 -0
  82. package/lib/utils/StringUtil.js.map +1 -0
  83. package/package.json +12 -16
  84. package/src/INestiaConfig.ts +30 -6
  85. package/src/NestiaSdkApplication.ts +255 -253
  86. package/src/analyses/AccessorAnalyzer.ts +60 -60
  87. package/src/analyses/ConfigAnalyzer.ts +147 -147
  88. package/src/analyses/ControllerAnalyzer.ts +42 -19
  89. package/src/analyses/ExceptionAnalyzer.ts +148 -115
  90. package/src/analyses/GenericAnalyzer.ts +51 -51
  91. package/src/analyses/ImportAnalyzer.ts +1 -2
  92. package/src/analyses/PathAnalyzer.ts +110 -98
  93. package/src/analyses/ReflectAnalyzer.ts +39 -35
  94. package/src/analyses/SecurityAnalyzer.ts +24 -20
  95. package/src/executable/internal/CommandParser.ts +15 -15
  96. package/src/executable/internal/NestiaConfigLoader.ts +67 -67
  97. package/src/executable/internal/NestiaSdkCommand.ts +60 -60
  98. package/src/executable/sdk.ts +73 -73
  99. package/src/generates/CloneGenerator.ts +62 -0
  100. package/src/generates/E2eGenerator.ts +66 -64
  101. package/src/generates/SdkGenerator.ts +84 -96
  102. package/src/generates/SwaggerGenerator.ts +145 -53
  103. package/src/generates/internal/E2eFileProgrammer.ts +182 -123
  104. package/src/generates/internal/FilePrinter.ts +53 -0
  105. package/src/{utils → generates/internal}/ImportDictionary.ts +35 -13
  106. package/src/generates/internal/SdkAliasCollection.ts +152 -0
  107. package/src/generates/internal/SdkCloneProgrammer.ts +155 -0
  108. package/src/generates/internal/SdkDistributionComposer.ts +91 -91
  109. package/src/generates/internal/SdkFileProgrammer.ts +115 -106
  110. package/src/generates/internal/SdkFunctionProgrammer.ts +298 -518
  111. package/src/generates/internal/SdkImportWizard.ts +55 -55
  112. package/src/generates/internal/SdkNamespaceProgrammer.ts +510 -0
  113. package/src/generates/internal/SdkRouteDirectory.ts +17 -17
  114. package/src/generates/internal/SdkRouteProgrammer.ts +83 -0
  115. package/src/generates/internal/SdkSimulationProgrammer.ts +365 -133
  116. package/src/generates/internal/SdkTypeProgrammer.ts +386 -0
  117. package/src/generates/internal/SwaggerSchemaGenerator.ts +437 -427
  118. package/src/generates/internal/SwaggerSchemaValidator.ts +198 -198
  119. package/src/index.ts +4 -4
  120. package/src/module.ts +2 -2
  121. package/src/structures/IController.ts +94 -95
  122. package/src/structures/IErrorReport.ts +6 -6
  123. package/src/structures/INestiaProject.ts +13 -13
  124. package/src/structures/INormalizedInput.ts +20 -20
  125. package/src/structures/IRoute.ts +53 -53
  126. package/src/structures/ISwaggerLazyProperty.ts +2 -2
  127. package/src/structures/ISwaggerLazySchema.ts +2 -2
  128. package/src/structures/ITypeTuple.ts +6 -6
  129. package/src/structures/MethodType.ts +5 -5
  130. package/src/structures/ParamCategory.ts +1 -1
  131. package/src/structures/TypeEntry.ts +1 -1
  132. package/src/utils/ArrayUtil.ts +26 -26
  133. package/src/utils/FileRetriever.ts +22 -22
  134. package/src/utils/MapUtil.ts +14 -14
  135. package/src/utils/PathUtil.ts +10 -10
  136. package/src/utils/SourceFinder.ts +66 -66
  137. package/src/utils/StringUtil.ts +6 -0
  138. package/src/utils/StripEnums.ts +5 -5
  139. package/assets/bundle/api/utils/NestiaSimulator.ts +0 -70
  140. package/lib/generates/internal/SdkDtoGenerator.d.ts +0 -9
  141. package/lib/generates/internal/SdkDtoGenerator.js +0 -294
  142. package/lib/generates/internal/SdkDtoGenerator.js.map +0 -1
  143. package/lib/generates/internal/SdkTypeDefiner.d.ts +0 -11
  144. package/lib/generates/internal/SdkTypeDefiner.js +0 -82
  145. package/lib/generates/internal/SdkTypeDefiner.js.map +0 -1
  146. package/lib/structures/ISwagger.d.ts +0 -72
  147. package/lib/structures/ISwagger.js +0 -3
  148. package/lib/structures/ISwagger.js.map +0 -1
  149. package/lib/structures/ISwaggerComponents.d.ts +0 -26
  150. package/lib/structures/ISwaggerComponents.js +0 -3
  151. package/lib/structures/ISwaggerComponents.js.map +0 -1
  152. package/lib/structures/ISwaggerInfo.d.ts +0 -71
  153. package/lib/structures/ISwaggerInfo.js +0 -3
  154. package/lib/structures/ISwaggerInfo.js.map +0 -1
  155. package/lib/structures/ISwaggerRoute.d.ts +0 -47
  156. package/lib/structures/ISwaggerRoute.js +0 -3
  157. package/lib/structures/ISwaggerRoute.js.map +0 -1
  158. package/lib/structures/ISwaggerSecurityScheme.d.ts +0 -56
  159. package/lib/structures/ISwaggerSecurityScheme.js +0 -3
  160. package/lib/structures/ISwaggerSecurityScheme.js.map +0 -1
  161. package/lib/utils/ImportDictionary.js.map +0 -1
  162. package/src/generates/internal/SdkDtoGenerator.ts +0 -424
  163. package/src/generates/internal/SdkTypeDefiner.ts +0 -119
  164. package/src/structures/ISwagger.ts +0 -91
  165. package/src/structures/ISwaggerComponents.ts +0 -29
  166. package/src/structures/ISwaggerInfo.ts +0 -80
  167. package/src/structures/ISwaggerRoute.ts +0 -51
  168. package/src/structures/ISwaggerSecurityScheme.ts +0 -65
@@ -1,7 +1,8 @@
1
1
  import * as Constants from "@nestjs/common/constants";
2
+ import { RouteParamtypes } from "@nestjs/common/enums/route-paramtypes.enum";
2
3
  import { VERSION_NEUTRAL, VersionValue } from "@nestjs/common/interfaces";
3
4
  import "reflect-metadata";
4
- import { equal } from "tstl/ranges/module";
5
+ import { ranges } from "tstl";
5
6
 
6
7
  import { IController } from "../structures/IController";
7
8
  import { IErrorReport } from "../structures/IErrorReport";
@@ -94,6 +95,7 @@ export namespace ReflectAnalyzer {
94
95
  //----
95
96
  // BASIC INFO
96
97
  const meta: IController = {
98
+ target: creator,
97
99
  file,
98
100
  name,
99
101
  functions: [],
@@ -261,6 +263,7 @@ export namespace ReflectAnalyzer {
261
263
 
262
264
  // DO CONSTRUCT
263
265
  const meta: IController.IFunction = {
266
+ target: proto,
264
267
  name,
265
268
  method: method === "ALL" ? "POST" : method,
266
269
  paths: _Get_paths(proto).filter((str) => {
@@ -280,15 +283,15 @@ export namespace ReflectAnalyzer {
280
283
  status: Reflect.getMetadata(Constants.HTTP_CODE_METADATA, proto),
281
284
  encrypted,
282
285
  contentType: encrypted
283
- ? "application/octet-stream"
286
+ ? "text/plain"
284
287
  : 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",
288
+ ? "application/x-www-form-urlencoded"
289
+ : Reflect.getMetadata(Constants.HEADERS_METADATA, proto)?.find(
290
+ (h: Record<string, string>) =>
291
+ typeof h?.name === "string" &&
292
+ typeof h?.value === "string" &&
293
+ h.name.toLowerCase() === "content-type",
294
+ )?.value ?? "application/json",
292
295
  security: _Get_securities(proto),
293
296
  exceptions: _Get_exceptions(proto),
294
297
  swaggerTags: [
@@ -310,18 +313,23 @@ export namespace ReflectAnalyzer {
310
313
  if (location.includes("*")) continue;
311
314
 
312
315
  // LIST UP PARAMETERS
313
- const binded: string[] = PathAnalyzer.parameters(
314
- location,
315
- () => `${controller.name}.${name}()`,
316
- ).sort();
317
-
316
+ const binded: string[] | null = PathAnalyzer.parameters(location);
317
+ if (binded === null) {
318
+ project.errors.push({
319
+ file: controller.file,
320
+ controller: controller.name,
321
+ function: name,
322
+ message: `invalid path ("${location}")`,
323
+ });
324
+ continue;
325
+ }
318
326
  const parameters: string[] = meta.parameters
319
327
  .filter((param) => param.category === "param")
320
328
  .map((param) => param.field!)
321
329
  .sort();
322
330
 
323
331
  // DO VALIDATE
324
- if (equal(binded, parameters) === false)
332
+ if (ranges.equal(binded.sort(), parameters) === false)
325
333
  errors.push({
326
334
  file: controller.file,
327
335
  controller: controller.name,
@@ -351,10 +359,10 @@ export namespace ReflectAnalyzer {
351
359
  if (symbol.indexOf("__custom") !== -1)
352
360
  return _Analyze_custom_parameter(param);
353
361
 
354
- const typeIndex: number = Number(symbol[0]);
362
+ const typeIndex: RouteParamtypes = Number(symbol[0]) as RouteParamtypes;
355
363
  if (isNaN(typeIndex) === true) return null;
356
364
 
357
- const type: ParamCategory | undefined = NEST_PARAMETER_TYPES[typeIndex];
365
+ const type: ParamCategory | undefined = getNestParamType(typeIndex);
358
366
  if (type === undefined) return null;
359
367
 
360
368
  return {
@@ -374,7 +382,8 @@ export namespace ReflectAnalyzer {
374
382
  param.factory.name === "EncryptedBody" ||
375
383
  param.factory.name === "PlainBody" ||
376
384
  param.factory.name === "TypedQueryBody" ||
377
- param.factory.name === "TypedBody"
385
+ param.factory.name === "TypedBody" ||
386
+ param.factory.name === "TypedFormDataBody"
378
387
  )
379
388
  return {
380
389
  custom: true,
@@ -388,8 +397,10 @@ export namespace ReflectAnalyzer {
388
397
  param.factory.name === "EncryptedBody"
389
398
  ? "text/plain"
390
399
  : param.factory.name === "TypedQueryBody"
391
- ? "application/x-www-form-urlencoded"
392
- : "application/json",
400
+ ? "application/x-www-form-urlencoded"
401
+ : param.factory.name === "TypedFormDataBody"
402
+ ? "multipart/form-data"
403
+ : "application/json",
393
404
  };
394
405
  else if (param.factory.name === "TypedHeaders")
395
406
  return {
@@ -442,18 +453,11 @@ const METHODS = [
442
453
  "HEAD",
443
454
  ];
444
455
 
445
- // node_modules/@nestjs/common/lib/route-paramtypes.enum.ts
446
- const NEST_PARAMETER_TYPES = [
447
- undefined,
448
- undefined,
449
- undefined,
450
- "body",
451
- "query",
452
- "param",
453
- "headers",
454
- undefined,
455
- undefined,
456
- undefined,
457
- undefined,
458
- undefined,
459
- ] as const;
456
+ // https://github.com/nestjs/nest/blob/master/packages/common/enums/route-paramtypes.enum.ts
457
+ const getNestParamType = (value: RouteParamtypes) => {
458
+ if (value === RouteParamtypes.BODY) return "body";
459
+ else if (value === RouteParamtypes.HEADERS) return "headers";
460
+ else if (value === RouteParamtypes.QUERY) return "query";
461
+ else if (value === RouteParamtypes.PARAM) return "param";
462
+ return undefined;
463
+ };
@@ -1,20 +1,24 @@
1
- import { MapUtil } from "../utils/MapUtil";
2
-
3
- export namespace SecurityAnalyzer {
4
- export const merge = (...entire: Record<string, string[]>[]) => {
5
- const dict: Map<string, Set<string>> = new Map();
6
- for (const obj of entire)
7
- for (const [key, value] of Object.entries(obj)) {
8
- const set = MapUtil.take(dict, key, () => new Set());
9
- for (const val of value) set.add(val);
10
- }
11
- const output: Record<string, string[]>[] = [];
12
- for (const [key, set] of dict) {
13
- const obj = {
14
- [key]: [...set],
15
- };
16
- output.push(obj);
17
- }
18
- return output;
19
- };
20
- }
1
+ import { MapUtil } from "../utils/MapUtil";
2
+
3
+ export namespace SecurityAnalyzer {
4
+ const none = Symbol("none");
5
+ export const merge = (...entire: Record<string, string[]>[]) => {
6
+ const dict: Map<string | typeof none, Set<string>> = new Map();
7
+ for (const obj of entire) {
8
+ const entries = Object.entries(obj);
9
+ for (const [key, value] of entries) {
10
+ const set = MapUtil.take(dict, key, () => new Set());
11
+ for (const val of value) set.add(val);
12
+ }
13
+ if (entries.length === 0) MapUtil.take(dict, none, () => new Set());
14
+ }
15
+ const output: Record<string, string[]>[] = [];
16
+ for (const [key, set] of dict)
17
+ key === none
18
+ ? output.push({})
19
+ : output.push({
20
+ [key]: [...set],
21
+ });
22
+ return output;
23
+ };
24
+ }
@@ -1,15 +1,15 @@
1
- export namespace CommandParser {
2
- export function parse(argList: string[]): Record<string, string> {
3
- const output: Record<string, string> = {};
4
- argList.forEach((arg, i) => {
5
- if (arg.startsWith("--") === false) return;
6
-
7
- const key = arg.slice(2);
8
- const value: string | undefined = argList[i + 1];
9
- if (value === undefined || value.startsWith("--")) return;
10
-
11
- output[key] = value;
12
- });
13
- return output;
14
- }
15
- }
1
+ export namespace CommandParser {
2
+ export function parse(argList: string[]): Record<string, string> {
3
+ const output: Record<string, string> = {};
4
+ argList.forEach((arg, i) => {
5
+ if (arg.startsWith("--") === false) return;
6
+
7
+ const key = arg.slice(2);
8
+ const value: string | undefined = argList[i + 1];
9
+ if (value === undefined || value.startsWith("--")) return;
10
+
11
+ output[key] = value;
12
+ });
13
+ return output;
14
+ }
15
+ }
@@ -1,67 +1,67 @@
1
- import fs from "fs";
2
- import path from "path";
3
- import { register } from "ts-node";
4
- import { parseNative } from "tsconfck";
5
- import ts from "typescript";
6
- import typia from "typia";
7
-
8
- import { INestiaConfig } from "../../INestiaConfig";
9
-
10
- export namespace NestiaConfigLoader {
11
- export const compilerOptions = async (
12
- project: string,
13
- ): Promise<ts.CompilerOptions> => {
14
- const configFileName = ts.findConfigFile(
15
- process.cwd(),
16
- ts.sys.fileExists,
17
- project,
18
- );
19
- if (!configFileName) throw new Error(`unable to find "${project}" file.`);
20
-
21
- const { tsconfig } = await parseNative(configFileName);
22
- const configFileText = JSON.stringify(tsconfig);
23
- const { config } = ts.parseConfigFileTextToJson(
24
- configFileName,
25
- configFileText,
26
- );
27
- const configParseResult = ts.parseJsonConfigFileContent(
28
- config,
29
- ts.sys,
30
- path.dirname(configFileName),
31
- );
32
-
33
- const { moduleResolution, ...result } =
34
- configParseResult.raw.compilerOptions;
35
- return result;
36
- };
37
-
38
- export const config = async (
39
- file: string,
40
- options: ts.CompilerOptions,
41
- ): Promise<INestiaConfig> => {
42
- if (fs.existsSync(path.resolve(file)) === false)
43
- throw new Error(`Unable to find "${file}" file.`);
44
-
45
- register({
46
- emit: false,
47
- compilerOptions: options,
48
- require: options.baseUrl ? ["tsconfig-paths/register"] : undefined,
49
- });
50
-
51
- const loaded: INestiaConfig & { default?: INestiaConfig } = await import(
52
- path.resolve(file)
53
- );
54
- const config: INestiaConfig =
55
- typeof loaded?.default === "object" && loaded.default !== null
56
- ? loaded.default
57
- : loaded;
58
-
59
- try {
60
- return typia.assert(config);
61
- } catch (exp) {
62
- if (typia.is<typia.TypeGuardError>(exp))
63
- exp.message = `invalid "${file}" data.`;
64
- throw exp;
65
- }
66
- };
67
- }
1
+ import fs from "fs";
2
+ import path from "path";
3
+ import { register } from "ts-node";
4
+ import { parseNative } from "tsconfck";
5
+ import ts from "typescript";
6
+ import typia from "typia";
7
+
8
+ import { INestiaConfig } from "../../INestiaConfig";
9
+
10
+ export namespace NestiaConfigLoader {
11
+ export const compilerOptions = async (
12
+ project: string,
13
+ ): Promise<ts.CompilerOptions> => {
14
+ const configFileName = ts.findConfigFile(
15
+ process.cwd(),
16
+ ts.sys.fileExists,
17
+ project,
18
+ );
19
+ if (!configFileName) throw new Error(`unable to find "${project}" file.`);
20
+
21
+ const { tsconfig } = await parseNative(configFileName);
22
+ const configFileText = JSON.stringify(tsconfig);
23
+ const { config } = ts.parseConfigFileTextToJson(
24
+ configFileName,
25
+ configFileText,
26
+ );
27
+ const configParseResult = ts.parseJsonConfigFileContent(
28
+ config,
29
+ ts.sys,
30
+ path.dirname(configFileName),
31
+ );
32
+
33
+ const { moduleResolution, ...result } =
34
+ configParseResult.raw.compilerOptions;
35
+ return result;
36
+ };
37
+
38
+ export const config = async (
39
+ file: string,
40
+ options: ts.CompilerOptions,
41
+ ): Promise<INestiaConfig> => {
42
+ if (fs.existsSync(path.resolve(file)) === false)
43
+ throw new Error(`Unable to find "${file}" file.`);
44
+
45
+ register({
46
+ emit: false,
47
+ compilerOptions: options,
48
+ require: options.baseUrl ? ["tsconfig-paths/register"] : undefined,
49
+ });
50
+
51
+ const loaded: INestiaConfig & { default?: INestiaConfig } = await import(
52
+ path.resolve(file)
53
+ );
54
+ const config: INestiaConfig =
55
+ typeof loaded?.default === "object" && loaded.default !== null
56
+ ? loaded.default
57
+ : loaded;
58
+
59
+ try {
60
+ return typia.assert(config);
61
+ } catch (exp) {
62
+ if (typia.is<typia.TypeGuardError>(exp))
63
+ exp.message = `invalid "${file}" data.`;
64
+ throw exp;
65
+ }
66
+ };
67
+ }
@@ -1,60 +1,60 @@
1
- import ts from "typescript";
2
-
3
- import { INestiaConfig } from "../../INestiaConfig";
4
- import { NestiaSdkApplication } from "../../NestiaSdkApplication";
5
- import { NestiaConfigLoader } from "./NestiaConfigLoader";
6
-
7
- export namespace NestiaSdkCommand {
8
- export const sdk = () => main((app) => app.sdk());
9
- export const swagger = () => main((app) => app.swagger());
10
- export const e2e = () => main((app) => app.e2e());
11
-
12
- const main = async (task: (app: NestiaSdkApplication) => Promise<void>) => {
13
- await generate(task);
14
- };
15
-
16
- const generate = async (
17
- task: (app: NestiaSdkApplication) => Promise<void>,
18
- ) => {
19
- // LOAD CONFIG INFO
20
- const compilerOptions: ts.CompilerOptions =
21
- await NestiaConfigLoader.compilerOptions(
22
- getFileArgument({
23
- type: "project",
24
- extension: "json",
25
- }) ?? "tsconfig.json",
26
- );
27
- const config: INestiaConfig = await NestiaConfigLoader.config(
28
- getFileArgument({
29
- type: "config",
30
- extension: "ts",
31
- }) ?? "nestia.config.ts",
32
- compilerOptions,
33
- );
34
-
35
- // GENERATE
36
- const app: NestiaSdkApplication = new NestiaSdkApplication(
37
- config,
38
- compilerOptions,
39
- );
40
- await task(app);
41
- };
42
-
43
- const getFileArgument = (props: {
44
- type: string;
45
- extension: string;
46
- }): string | null => {
47
- const argv: string[] = process.argv.slice(3);
48
- if (argv.length === 0) return null;
49
-
50
- const index: number = argv.findIndex((str) => str === `--${props.type}`);
51
- if (index === -1) return null;
52
- else if (argv.length === 1)
53
- throw new Error(`${props.type} file must be provided`);
54
-
55
- const file: string = argv[index + 1];
56
- if (file.endsWith(props.extension) === false)
57
- throw new Error(`${props.type} file must be ${props.extension} file`);
58
- return file;
59
- };
60
- }
1
+ import ts from "typescript";
2
+
3
+ import { INestiaConfig } from "../../INestiaConfig";
4
+ import { NestiaSdkApplication } from "../../NestiaSdkApplication";
5
+ import { NestiaConfigLoader } from "./NestiaConfigLoader";
6
+
7
+ export namespace NestiaSdkCommand {
8
+ export const sdk = () => main((app) => app.sdk());
9
+ export const swagger = () => main((app) => app.swagger());
10
+ export const e2e = () => main((app) => app.e2e());
11
+
12
+ const main = async (task: (app: NestiaSdkApplication) => Promise<void>) => {
13
+ await generate(task);
14
+ };
15
+
16
+ const generate = async (
17
+ task: (app: NestiaSdkApplication) => Promise<void>,
18
+ ) => {
19
+ // LOAD CONFIG INFO
20
+ const compilerOptions: ts.CompilerOptions =
21
+ await NestiaConfigLoader.compilerOptions(
22
+ getFileArgument({
23
+ type: "project",
24
+ extension: "json",
25
+ }) ?? "tsconfig.json",
26
+ );
27
+ const config: INestiaConfig = await NestiaConfigLoader.config(
28
+ getFileArgument({
29
+ type: "config",
30
+ extension: "ts",
31
+ }) ?? "nestia.config.ts",
32
+ compilerOptions,
33
+ );
34
+
35
+ // GENERATE
36
+ const app: NestiaSdkApplication = new NestiaSdkApplication(
37
+ config,
38
+ compilerOptions,
39
+ );
40
+ await task(app);
41
+ };
42
+
43
+ const getFileArgument = (props: {
44
+ type: string;
45
+ extension: string;
46
+ }): string | null => {
47
+ const argv: string[] = process.argv.slice(3);
48
+ if (argv.length === 0) return null;
49
+
50
+ const index: number = argv.findIndex((str) => str === `--${props.type}`);
51
+ if (index === -1) return null;
52
+ else if (argv.length === 1)
53
+ throw new Error(`${props.type} file must be provided`);
54
+
55
+ const file: string = argv[index + 1];
56
+ if (file.endsWith(props.extension) === false)
57
+ throw new Error(`${props.type} file must be ${props.extension} file`);
58
+ return file;
59
+ };
60
+ }
@@ -1,73 +1,73 @@
1
- #!/usr/bin/env node
2
- import cp from "child_process";
3
- import fs from "fs";
4
- import process from "process";
5
-
6
- import { CommandParser } from "./internal/CommandParser";
7
- import type { NestiaSdkCommand } from "./internal/NestiaSdkCommand";
8
-
9
- const USAGE = `Wrong command has been detected. Use like below:
10
-
11
- npx @nestia/sdk [command] [options?]
12
-
13
- 1. npx @nestia/sdk dependencies --manager (npm|pnpm|yarn)
14
- - npx @nestia/sdk dependencies
15
- - npx @nestia/sdk dependencies --manager pnpm
16
- 2. npx @nestia/sdk init
17
- 3. npx @nestia/sdk sdk --config? [config file]
18
- 4. npx @nestia/sdk swagger --config? [config file]
19
- 5. npx @nestia/sdk e2e --config? [config file]
20
- `;
21
-
22
- function halt(desc: string): never {
23
- console.error(desc);
24
- process.exit(-1);
25
- }
26
-
27
- function dependencies(argv: string[]): void {
28
- // INSTALL DEPENDENCIES
29
- const module = CommandParser.parse(argv).module ?? "npm";
30
- const prefix: string = module === "yarn" ? "yarn add" : `${module} install`;
31
-
32
- for (const lib of ["@nestia/fetcher", "typia"]) {
33
- const command: string = `${prefix} ${lib}`;
34
- console.log(`\n$ ${command}`);
35
- cp.execSync(command, { stdio: "inherit" });
36
- }
37
- }
38
-
39
- async function initialize(): Promise<void> {
40
- if (fs.existsSync("nestia.config.ts") === true)
41
- halt(
42
- `Error on nestia.sdk.initialize(): "nestia.config.ts" file already has been configured.`,
43
- );
44
- await fs.promises.copyFile(
45
- `${__dirname}/../../assets/config/nestia.config.ts`,
46
- "nestia.config.ts",
47
- );
48
- }
49
-
50
- async function execute(
51
- closure: (commander: typeof NestiaSdkCommand) => Promise<void>,
52
- ): Promise<void> {
53
- const module = await import("./internal/NestiaSdkCommand");
54
- await closure(module.NestiaSdkCommand);
55
- }
56
-
57
- async function main() {
58
- const type: string | undefined = process.argv[2];
59
- const argv: string[] = process.argv.slice(3);
60
-
61
- if (type === "dependencies") dependencies(argv);
62
- else if (type === "init") await initialize();
63
- else if (type === "sdk") await execute((c) => c.sdk());
64
- else if (type === "swagger") await execute((c) => c.swagger());
65
- else if (type === "e2e") await execute((c) => c.e2e());
66
- else halt(USAGE);
67
-
68
- process.exit(0);
69
- }
70
- main().catch((exp) => {
71
- console.log(exp);
72
- process.exit(-1);
73
- });
1
+ #!/usr/bin/env node
2
+ import cp from "child_process";
3
+ import fs from "fs";
4
+ import process from "process";
5
+
6
+ import { CommandParser } from "./internal/CommandParser";
7
+ import type { NestiaSdkCommand } from "./internal/NestiaSdkCommand";
8
+
9
+ const USAGE = `Wrong command has been detected. Use like below:
10
+
11
+ npx @nestia/sdk [command] [options?]
12
+
13
+ 1. npx @nestia/sdk dependencies --manager (npm|pnpm|yarn)
14
+ - npx @nestia/sdk dependencies
15
+ - npx @nestia/sdk dependencies --manager pnpm
16
+ 2. npx @nestia/sdk init
17
+ 3. npx @nestia/sdk sdk --config? [config file]
18
+ 4. npx @nestia/sdk swagger --config? [config file]
19
+ 5. npx @nestia/sdk e2e --config? [config file]
20
+ `;
21
+
22
+ function halt(desc: string): never {
23
+ console.error(desc);
24
+ process.exit(-1);
25
+ }
26
+
27
+ function dependencies(argv: string[]): void {
28
+ // INSTALL DEPENDENCIES
29
+ const module = CommandParser.parse(argv).module ?? "npm";
30
+ const prefix: string = module === "yarn" ? "yarn add" : `${module} install`;
31
+
32
+ for (const lib of ["@nestia/fetcher", "typia"]) {
33
+ const command: string = `${prefix} ${lib}`;
34
+ console.log(`\n$ ${command}`);
35
+ cp.execSync(command, { stdio: "inherit" });
36
+ }
37
+ }
38
+
39
+ async function initialize(): Promise<void> {
40
+ if (fs.existsSync("nestia.config.ts") === true)
41
+ halt(
42
+ `Error on nestia.sdk.initialize(): "nestia.config.ts" file already has been configured.`,
43
+ );
44
+ await fs.promises.copyFile(
45
+ `${__dirname}/../../assets/config/nestia.config.ts`,
46
+ "nestia.config.ts",
47
+ );
48
+ }
49
+
50
+ async function execute(
51
+ closure: (commander: typeof NestiaSdkCommand) => Promise<void>,
52
+ ): Promise<void> {
53
+ const module = await import("./internal/NestiaSdkCommand");
54
+ await closure(module.NestiaSdkCommand);
55
+ }
56
+
57
+ async function main() {
58
+ const type: string | undefined = process.argv[2];
59
+ const argv: string[] = process.argv.slice(3);
60
+
61
+ if (type === "dependencies") dependencies(argv);
62
+ else if (type === "init") await initialize();
63
+ else if (type === "sdk") await execute((c) => c.sdk());
64
+ else if (type === "swagger") await execute((c) => c.swagger());
65
+ else if (type === "e2e") await execute((c) => c.e2e());
66
+ else halt(USAGE);
67
+
68
+ process.exit(0);
69
+ }
70
+ main().catch((exp) => {
71
+ console.log(exp);
72
+ process.exit(-1);
73
+ });