@nestia/sdk 2.4.3-dev.20231207 → 2.4.4-dev.20240109-3

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 (67) hide show
  1. package/lib/INestiaConfig.d.ts +13 -0
  2. package/lib/analyses/ControllerAnalyzer.js +12 -1
  3. package/lib/analyses/ControllerAnalyzer.js.map +1 -1
  4. package/lib/analyses/PathAnalyzer.d.ts +2 -2
  5. package/lib/analyses/PathAnalyzer.js +27 -11
  6. package/lib/analyses/PathAnalyzer.js.map +1 -1
  7. package/lib/analyses/ReflectAnalyzer.js +11 -2
  8. package/lib/analyses/ReflectAnalyzer.js.map +1 -1
  9. package/lib/executable/internal/NestiaConfigLoader.js +5 -1
  10. package/lib/executable/internal/NestiaConfigLoader.js.map +1 -1
  11. package/lib/executable/sdk.js +11 -11
  12. package/lib/generates/SwaggerGenerator.js +16 -22
  13. package/lib/generates/SwaggerGenerator.js.map +1 -1
  14. package/lib/structures/ISwaggerComponents.d.ts +1 -1
  15. package/lib/structures/ISwaggerRoute.d.ts +2 -2
  16. package/package.json +5 -5
  17. package/src/INestiaConfig.ts +248 -234
  18. package/src/NestiaSdkApplication.ts +253 -253
  19. package/src/analyses/AccessorAnalyzer.ts +60 -60
  20. package/src/analyses/ConfigAnalyzer.ts +147 -147
  21. package/src/analyses/ControllerAnalyzer.ts +390 -379
  22. package/src/analyses/ExceptionAnalyzer.ts +115 -115
  23. package/src/analyses/GenericAnalyzer.ts +51 -51
  24. package/src/analyses/ImportAnalyzer.ts +138 -138
  25. package/src/analyses/PathAnalyzer.ts +110 -98
  26. package/src/analyses/ReflectAnalyzer.ts +11 -6
  27. package/src/analyses/SecurityAnalyzer.ts +20 -20
  28. package/src/executable/internal/CommandParser.ts +15 -15
  29. package/src/executable/internal/NestiaConfigLoader.ts +67 -67
  30. package/src/executable/internal/NestiaSdkCommand.ts +60 -60
  31. package/src/executable/sdk.ts +73 -73
  32. package/src/generates/E2eGenerator.ts +64 -64
  33. package/src/generates/SdkGenerator.ts +96 -96
  34. package/src/generates/SwaggerGenerator.ts +376 -372
  35. package/src/generates/internal/E2eFileProgrammer.ts +123 -123
  36. package/src/generates/internal/SdkDistributionComposer.ts +91 -91
  37. package/src/generates/internal/SdkDtoGenerator.ts +424 -424
  38. package/src/generates/internal/SdkFileProgrammer.ts +106 -106
  39. package/src/generates/internal/SdkImportWizard.ts +55 -55
  40. package/src/generates/internal/SdkRouteDirectory.ts +17 -17
  41. package/src/generates/internal/SdkSimulationProgrammer.ts +133 -133
  42. package/src/generates/internal/SdkTypeDefiner.ts +119 -119
  43. package/src/generates/internal/SwaggerSchemaValidator.ts +198 -198
  44. package/src/index.ts +4 -4
  45. package/src/module.ts +2 -2
  46. package/src/structures/IErrorReport.ts +6 -6
  47. package/src/structures/INestiaProject.ts +13 -13
  48. package/src/structures/INormalizedInput.ts +20 -20
  49. package/src/structures/ISwagger.ts +91 -91
  50. package/src/structures/ISwaggerComponents.ts +29 -29
  51. package/src/structures/ISwaggerError.ts +8 -8
  52. package/src/structures/ISwaggerInfo.ts +80 -80
  53. package/src/structures/ISwaggerLazyProperty.ts +7 -7
  54. package/src/structures/ISwaggerLazySchema.ts +7 -7
  55. package/src/structures/ISwaggerRoute.ts +51 -51
  56. package/src/structures/ISwaggerSecurityScheme.ts +65 -65
  57. package/src/structures/ITypeTuple.ts +6 -6
  58. package/src/structures/MethodType.ts +5 -5
  59. package/src/structures/ParamCategory.ts +1 -1
  60. package/src/structures/TypeEntry.ts +22 -22
  61. package/src/utils/ArrayUtil.ts +26 -26
  62. package/src/utils/FileRetriever.ts +22 -22
  63. package/src/utils/ImportDictionary.ts +125 -125
  64. package/src/utils/MapUtil.ts +14 -14
  65. package/src/utils/PathUtil.ts +10 -10
  66. package/src/utils/SourceFinder.ts +66 -66
  67. package/src/utils/StripEnums.ts +5 -5
@@ -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
+ });
@@ -1,64 +1,64 @@
1
- import fs from "fs";
2
- import path from "path";
3
-
4
- import { INestiaConfig } from "../INestiaConfig";
5
- import { ConfigAnalyzer } from "../analyses/ConfigAnalyzer";
6
- import { IRoute } from "../structures/IRoute";
7
- import { E2eFileProgrammer } from "./internal/E2eFileProgrammer";
8
-
9
- export namespace E2eGenerator {
10
- export const generate =
11
- (config: INestiaConfig) =>
12
- async (routeList: IRoute[]): Promise<void> => {
13
- console.log("Generating E2E Test Functions");
14
-
15
- // PREPARE DIRECTORIES
16
- const output: string = path.resolve(config.e2e!);
17
- await mkdir(output);
18
- await mkdir(path.join(output, "features"));
19
- await mkdir(path.join(output, "features", "api"));
20
- await mkdir(path.join(output, "features", "api", "automated"));
21
-
22
- // GENERATE TEST INDEX FILE
23
- await index(config)(path.join(config.e2e!, "index.ts"));
24
-
25
- // GENERATE EACH TEST FILES
26
- for (const route of routeList)
27
- await E2eFileProgrammer.generate(config)({
28
- api: path.resolve(config.output!),
29
- current: path.join(output, "features", "api", "automated"),
30
- })(route);
31
- };
32
-
33
- const index =
34
- (config: INestiaConfig) =>
35
- async (output: string): Promise<void> => {
36
- if (fs.existsSync(output)) return;
37
-
38
- const location: string = path.join(
39
- __dirname,
40
- "..",
41
- "..",
42
- "assets",
43
- "bundle",
44
- "e2e",
45
- "index.ts",
46
- );
47
- const content: string = await fs.promises.readFile(location, "utf8");
48
-
49
- await fs.promises.writeFile(
50
- output,
51
- content.replace(
52
- "${input}",
53
- JSON.stringify(await ConfigAnalyzer.input(config)),
54
- ),
55
- "utf8",
56
- );
57
- };
58
- }
59
-
60
- const mkdir = async (location: string): Promise<void> => {
61
- try {
62
- await fs.promises.mkdir(location);
63
- } catch {}
64
- };
1
+ import fs from "fs";
2
+ import path from "path";
3
+
4
+ import { INestiaConfig } from "../INestiaConfig";
5
+ import { ConfigAnalyzer } from "../analyses/ConfigAnalyzer";
6
+ import { IRoute } from "../structures/IRoute";
7
+ import { E2eFileProgrammer } from "./internal/E2eFileProgrammer";
8
+
9
+ export namespace E2eGenerator {
10
+ export const generate =
11
+ (config: INestiaConfig) =>
12
+ async (routeList: IRoute[]): Promise<void> => {
13
+ console.log("Generating E2E Test Functions");
14
+
15
+ // PREPARE DIRECTORIES
16
+ const output: string = path.resolve(config.e2e!);
17
+ await mkdir(output);
18
+ await mkdir(path.join(output, "features"));
19
+ await mkdir(path.join(output, "features", "api"));
20
+ await mkdir(path.join(output, "features", "api", "automated"));
21
+
22
+ // GENERATE TEST INDEX FILE
23
+ await index(config)(path.join(config.e2e!, "index.ts"));
24
+
25
+ // GENERATE EACH TEST FILES
26
+ for (const route of routeList)
27
+ await E2eFileProgrammer.generate(config)({
28
+ api: path.resolve(config.output!),
29
+ current: path.join(output, "features", "api", "automated"),
30
+ })(route);
31
+ };
32
+
33
+ const index =
34
+ (config: INestiaConfig) =>
35
+ async (output: string): Promise<void> => {
36
+ if (fs.existsSync(output)) return;
37
+
38
+ const location: string = path.join(
39
+ __dirname,
40
+ "..",
41
+ "..",
42
+ "assets",
43
+ "bundle",
44
+ "e2e",
45
+ "index.ts",
46
+ );
47
+ const content: string = await fs.promises.readFile(location, "utf8");
48
+
49
+ await fs.promises.writeFile(
50
+ output,
51
+ content.replace(
52
+ "${input}",
53
+ JSON.stringify(await ConfigAnalyzer.input(config)),
54
+ ),
55
+ "utf8",
56
+ );
57
+ };
58
+ }
59
+
60
+ const mkdir = async (location: string): Promise<void> => {
61
+ try {
62
+ await fs.promises.mkdir(location);
63
+ } catch {}
64
+ };
@@ -1,96 +1,96 @@
1
- import fs from "fs";
2
- import NodePath from "path";
3
- import { IPointer } from "tstl";
4
- import ts from "typescript";
5
-
6
- import { INestiaConfig } from "../INestiaConfig";
7
- import { IRoute } from "../structures/IRoute";
8
- import { SdkDistributionComposer } from "./internal/SdkDistributionComposer";
9
- import { SdkDtoGenerator } from "./internal/SdkDtoGenerator";
10
- import { SdkFileProgrammer } from "./internal/SdkFileProgrammer";
11
-
12
- export namespace SdkGenerator {
13
- export const generate =
14
- (checker: ts.TypeChecker) =>
15
- (config: INestiaConfig) =>
16
- async (routes: IRoute[]): Promise<void> => {
17
- console.log("Generating SDK Library");
18
-
19
- // PREPARE NEW DIRECTORIES
20
- try {
21
- await fs.promises.mkdir(config.output!);
22
- } catch {}
23
-
24
- // BUNDLING
25
- const bundle: string[] = await fs.promises.readdir(BUNDLE_PATH);
26
- for (const file of bundle) {
27
- const current: string = `${BUNDLE_PATH}/${file}`;
28
- const target: string = `${config.output}/${file}`;
29
- const stats: fs.Stats = await fs.promises.stat(current);
30
-
31
- if (stats.isFile() === true) {
32
- const content: string = await fs.promises.readFile(current, "utf8");
33
- if (fs.existsSync(target) === false)
34
- await fs.promises.writeFile(target, content, "utf8");
35
- else if (BUNDLE_CHANGES[file] !== undefined) {
36
- const r: IPointer<string> = {
37
- value: await fs.promises.readFile(target, "utf8"),
38
- };
39
- for (const [before, after] of BUNDLE_CHANGES[file])
40
- r.value = r.value.replace(before, after);
41
- await fs.promises.writeFile(target, r.value, "utf8");
42
- }
43
- }
44
- }
45
- if (
46
- config.simulate === true &&
47
- routes.some((r) => !!r.parameters.length)
48
- ) {
49
- try {
50
- await fs.promises.mkdir(`${config.output}/utils`);
51
- } catch {}
52
- await fs.promises.copyFile(
53
- `${BUNDLE_PATH}/utils/NestiaSimulator.ts`,
54
- `${config.output}/utils/NestiaSimulator.ts`,
55
- );
56
- }
57
-
58
- // STRUCTURES
59
- if (config.clone) await SdkDtoGenerator.generate(checker)(config)(routes);
60
-
61
- // FUNCTIONAL
62
- await SdkFileProgrammer.generate(config)(routes);
63
-
64
- // DISTRIBUTION
65
- if (config.distribute !== undefined)
66
- await SdkDistributionComposer.compose(config);
67
- };
68
-
69
- export const BUNDLE_PATH = NodePath.join(
70
- __dirname,
71
- "..",
72
- "..",
73
- "assets",
74
- "bundle",
75
- "api",
76
- );
77
- }
78
-
79
- const BUNDLE_CHANGES: Record<string, [string, string][]> = {
80
- "IConnection.ts": [
81
- [
82
- `export { IConnection } from "@nestia/fetcher"`,
83
- `export type { IConnection } from "@nestia/fetcher"`,
84
- ],
85
- ],
86
- "module.ts": [
87
- [`export * from "./IConnection"`, `export type * from "./IConnection"`],
88
- [`export * from "./Primitive"`, `export type * from "./Primitive"`],
89
- ],
90
- "Primitive.ts": [
91
- [
92
- `export { Primitive } from "@nestia/fetcher"`,
93
- `export type { Primitive } from "@nestia/fetcher"`,
94
- ],
95
- ],
96
- };
1
+ import fs from "fs";
2
+ import NodePath from "path";
3
+ import { IPointer } from "tstl";
4
+ import ts from "typescript";
5
+
6
+ import { INestiaConfig } from "../INestiaConfig";
7
+ import { IRoute } from "../structures/IRoute";
8
+ import { SdkDistributionComposer } from "./internal/SdkDistributionComposer";
9
+ import { SdkDtoGenerator } from "./internal/SdkDtoGenerator";
10
+ import { SdkFileProgrammer } from "./internal/SdkFileProgrammer";
11
+
12
+ export namespace SdkGenerator {
13
+ export const generate =
14
+ (checker: ts.TypeChecker) =>
15
+ (config: INestiaConfig) =>
16
+ async (routes: IRoute[]): Promise<void> => {
17
+ console.log("Generating SDK Library");
18
+
19
+ // PREPARE NEW DIRECTORIES
20
+ try {
21
+ await fs.promises.mkdir(config.output!);
22
+ } catch {}
23
+
24
+ // BUNDLING
25
+ const bundle: string[] = await fs.promises.readdir(BUNDLE_PATH);
26
+ for (const file of bundle) {
27
+ const current: string = `${BUNDLE_PATH}/${file}`;
28
+ const target: string = `${config.output}/${file}`;
29
+ const stats: fs.Stats = await fs.promises.stat(current);
30
+
31
+ if (stats.isFile() === true) {
32
+ const content: string = await fs.promises.readFile(current, "utf8");
33
+ if (fs.existsSync(target) === false)
34
+ await fs.promises.writeFile(target, content, "utf8");
35
+ else if (BUNDLE_CHANGES[file] !== undefined) {
36
+ const r: IPointer<string> = {
37
+ value: await fs.promises.readFile(target, "utf8"),
38
+ };
39
+ for (const [before, after] of BUNDLE_CHANGES[file])
40
+ r.value = r.value.replace(before, after);
41
+ await fs.promises.writeFile(target, r.value, "utf8");
42
+ }
43
+ }
44
+ }
45
+ if (
46
+ config.simulate === true &&
47
+ routes.some((r) => !!r.parameters.length)
48
+ ) {
49
+ try {
50
+ await fs.promises.mkdir(`${config.output}/utils`);
51
+ } catch {}
52
+ await fs.promises.copyFile(
53
+ `${BUNDLE_PATH}/utils/NestiaSimulator.ts`,
54
+ `${config.output}/utils/NestiaSimulator.ts`,
55
+ );
56
+ }
57
+
58
+ // STRUCTURES
59
+ if (config.clone) await SdkDtoGenerator.generate(checker)(config)(routes);
60
+
61
+ // FUNCTIONAL
62
+ await SdkFileProgrammer.generate(config)(routes);
63
+
64
+ // DISTRIBUTION
65
+ if (config.distribute !== undefined)
66
+ await SdkDistributionComposer.compose(config);
67
+ };
68
+
69
+ export const BUNDLE_PATH = NodePath.join(
70
+ __dirname,
71
+ "..",
72
+ "..",
73
+ "assets",
74
+ "bundle",
75
+ "api",
76
+ );
77
+ }
78
+
79
+ const BUNDLE_CHANGES: Record<string, [string, string][]> = {
80
+ "IConnection.ts": [
81
+ [
82
+ `export { IConnection } from "@nestia/fetcher"`,
83
+ `export type { IConnection } from "@nestia/fetcher"`,
84
+ ],
85
+ ],
86
+ "module.ts": [
87
+ [`export * from "./IConnection"`, `export type * from "./IConnection"`],
88
+ [`export * from "./Primitive"`, `export type * from "./Primitive"`],
89
+ ],
90
+ "Primitive.ts": [
91
+ [
92
+ `export { Primitive } from "@nestia/fetcher"`,
93
+ `export type { Primitive } from "@nestia/fetcher"`,
94
+ ],
95
+ ],
96
+ };