@nestia/sdk 2.4.2 → 2.4.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 (111) hide show
  1. package/lib/NestiaSdkApplication.js +2 -6
  2. package/lib/NestiaSdkApplication.js.map +1 -1
  3. package/lib/analyses/AccessorAnalyzer.js.map +1 -1
  4. package/lib/analyses/ConfigAnalyzer.js +4 -8
  5. package/lib/analyses/ConfigAnalyzer.js.map +1 -1
  6. package/lib/analyses/ControllerAnalyzer.js +6 -8
  7. package/lib/analyses/ControllerAnalyzer.js.map +1 -1
  8. package/lib/analyses/ExceptionAnalyzer.js.map +1 -1
  9. package/lib/analyses/GenericAnalyzer.js +1 -2
  10. package/lib/analyses/GenericAnalyzer.js.map +1 -1
  11. package/lib/analyses/ImportAnalyzer.js +4 -4
  12. package/lib/analyses/ImportAnalyzer.js.map +1 -1
  13. package/lib/analyses/PathAnalyzer.js.map +1 -1
  14. package/lib/analyses/ReflectAnalyzer.js +7 -8
  15. package/lib/analyses/ReflectAnalyzer.js.map +1 -1
  16. package/lib/analyses/SecurityAnalyzer.js.map +1 -1
  17. package/lib/executable/internal/CommandParser.js.map +1 -1
  18. package/lib/executable/internal/NestiaConfigLoader.js.map +1 -1
  19. package/lib/executable/internal/NestiaSdkCommand.js.map +1 -1
  20. package/lib/executable/sdk.js +11 -11
  21. package/lib/executable/sdk.js.map +1 -1
  22. package/lib/generates/E2eGenerator.js.map +1 -1
  23. package/lib/generates/SdkGenerator.js.map +1 -1
  24. package/lib/generates/SwaggerGenerator.js +5 -11
  25. package/lib/generates/SwaggerGenerator.js.map +1 -1
  26. package/lib/generates/internal/E2eFileProgrammer.js +2 -8
  27. package/lib/generates/internal/E2eFileProgrammer.js.map +1 -1
  28. package/lib/generates/internal/SdkDistributionComposer.js.map +1 -1
  29. package/lib/generates/internal/SdkDtoGenerator.js +3 -9
  30. package/lib/generates/internal/SdkDtoGenerator.js.map +1 -1
  31. package/lib/generates/internal/SdkFileProgrammer.js +4 -4
  32. package/lib/generates/internal/SdkFileProgrammer.js.map +1 -1
  33. package/lib/generates/internal/SdkFunctionProgrammer.js +12 -20
  34. package/lib/generates/internal/SdkFunctionProgrammer.js.map +1 -1
  35. package/lib/generates/internal/SdkImportWizard.js.map +1 -1
  36. package/lib/generates/internal/SdkRouteDirectory.js +1 -3
  37. package/lib/generates/internal/SdkRouteDirectory.js.map +1 -1
  38. package/lib/generates/internal/SdkSimulationProgrammer.js +5 -7
  39. package/lib/generates/internal/SdkSimulationProgrammer.js.map +1 -1
  40. package/lib/generates/internal/SdkTypeDefiner.js +2 -5
  41. package/lib/generates/internal/SdkTypeDefiner.js.map +1 -1
  42. package/lib/generates/internal/SwaggerSchemaGenerator.js +29 -44
  43. package/lib/generates/internal/SwaggerSchemaGenerator.js.map +1 -1
  44. package/lib/generates/internal/SwaggerSchemaValidator.js +3 -9
  45. package/lib/generates/internal/SwaggerSchemaValidator.js.map +1 -1
  46. package/lib/structures/MethodType.js +1 -7
  47. package/lib/structures/MethodType.js.map +1 -1
  48. package/lib/structures/TypeEntry.js.map +1 -1
  49. package/lib/utils/ArrayUtil.js.map +1 -1
  50. package/lib/utils/FileRetriever.js.map +1 -1
  51. package/lib/utils/ImportDictionary.js +1 -4
  52. package/lib/utils/ImportDictionary.js.map +1 -1
  53. package/lib/utils/MapUtil.js.map +1 -1
  54. package/lib/utils/PathUtil.js.map +1 -1
  55. package/lib/utils/SourceFinder.js.map +1 -1
  56. package/package.json +4 -7
  57. package/src/INestiaConfig.ts +234 -234
  58. package/src/NestiaSdkApplication.ts +253 -268
  59. package/src/analyses/AccessorAnalyzer.ts +60 -60
  60. package/src/analyses/ConfigAnalyzer.ts +147 -164
  61. package/src/analyses/ControllerAnalyzer.ts +379 -399
  62. package/src/analyses/ExceptionAnalyzer.ts +115 -124
  63. package/src/analyses/GenericAnalyzer.ts +51 -57
  64. package/src/analyses/ImportAnalyzer.ts +138 -159
  65. package/src/analyses/PathAnalyzer.ts +98 -100
  66. package/src/analyses/ReflectAnalyzer.ts +425 -433
  67. package/src/analyses/SecurityAnalyzer.ts +20 -20
  68. package/src/executable/internal/CommandParser.ts +15 -15
  69. package/src/executable/internal/NestiaConfigLoader.ts +67 -68
  70. package/src/executable/internal/NestiaSdkCommand.ts +60 -64
  71. package/src/executable/sdk.ts +73 -73
  72. package/src/generates/E2eGenerator.ts +64 -67
  73. package/src/generates/SdkGenerator.ts +96 -100
  74. package/src/generates/SwaggerGenerator.ts +372 -410
  75. package/src/generates/internal/E2eFileProgrammer.ts +123 -129
  76. package/src/generates/internal/SdkDistributionComposer.ts +91 -91
  77. package/src/generates/internal/SdkDtoGenerator.ts +424 -450
  78. package/src/generates/internal/SdkFileProgrammer.ts +106 -111
  79. package/src/generates/internal/SdkFunctionProgrammer.ts +466 -501
  80. package/src/generates/internal/SdkImportWizard.ts +55 -55
  81. package/src/generates/internal/SdkRouteDirectory.ts +17 -19
  82. package/src/generates/internal/SdkSimulationProgrammer.ts +133 -142
  83. package/src/generates/internal/SdkTypeDefiner.ts +119 -124
  84. package/src/generates/internal/SwaggerSchemaGenerator.ts +382 -401
  85. package/src/generates/internal/SwaggerSchemaValidator.ts +198 -210
  86. package/src/index.ts +4 -4
  87. package/src/module.ts +2 -2
  88. package/src/structures/IController.ts +79 -81
  89. package/src/structures/IErrorReport.ts +6 -6
  90. package/src/structures/INestiaProject.ts +13 -13
  91. package/src/structures/INormalizedInput.ts +20 -20
  92. package/src/structures/IRoute.ts +40 -41
  93. package/src/structures/ISwagger.ts +91 -91
  94. package/src/structures/ISwaggerComponents.ts +29 -29
  95. package/src/structures/ISwaggerError.ts +8 -8
  96. package/src/structures/ISwaggerInfo.ts +80 -80
  97. package/src/structures/ISwaggerLazyProperty.ts +7 -7
  98. package/src/structures/ISwaggerLazySchema.ts +7 -7
  99. package/src/structures/ISwaggerRoute.ts +51 -51
  100. package/src/structures/ISwaggerSecurityScheme.ts +65 -65
  101. package/src/structures/ITypeTuple.ts +6 -6
  102. package/src/structures/MethodType.ts +5 -11
  103. package/src/structures/ParamCategory.ts +1 -1
  104. package/src/structures/TypeEntry.ts +22 -22
  105. package/src/utils/ArrayUtil.ts +26 -26
  106. package/src/utils/FileRetriever.ts +22 -22
  107. package/src/utils/ImportDictionary.ts +125 -128
  108. package/src/utils/MapUtil.ts +14 -14
  109. package/src/utils/PathUtil.ts +10 -10
  110. package/src/utils/SourceFinder.ts +66 -70
  111. package/src/utils/StripEnums.ts +5 -10
@@ -1,164 +1,147 @@
1
- import { INestApplication, VersioningType } from "@nestjs/common";
2
- import { MODULE_PATH } from "@nestjs/common/constants";
3
- import { NestContainer } from "@nestjs/core";
4
- import { Module } from "@nestjs/core/injector/module";
5
- import fs from "fs";
6
- import path from "path";
7
- import { HashMap, Pair, Singleton } from "tstl";
8
-
9
- import { INestiaConfig } from "../INestiaConfig";
10
- import { SdkGenerator } from "../generates/SdkGenerator";
11
- import { INormalizedInput } from "../structures/INormalizedInput";
12
- import { ArrayUtil } from "../utils/ArrayUtil";
13
- import { MapUtil } from "../utils/MapUtil";
14
- import { SourceFinder } from "../utils/SourceFinder";
15
-
16
- export namespace ConfigAnalyzer {
17
- export const input = (config: INestiaConfig): Promise<INormalizedInput> =>
18
- MapUtil.take(memory, config, async () => {
19
- const input = config.input;
20
- if (Array.isArray(input)) return transform_input(config)(input);
21
- else if (typeof input === "function")
22
- return analyze_application(await input());
23
- else if (typeof input === "object")
24
- if (input === null)
25
- throw new Error("Invalid input config. It can't be null.");
26
- else
27
- return transform_input(config)(
28
- input.include,
29
- input.exclude,
30
- );
31
- else if (typeof input === "string")
32
- return transform_input(config)([input]);
33
- else throw new Error("Invalid input config.");
34
- });
35
-
36
- const analyze_application = async (
37
- app: INestApplication,
38
- ): Promise<INormalizedInput> => {
39
- const files: HashMap<
40
- Pair<Function, string>,
41
- Set<string>
42
- > = new HashMap();
43
- const container: NestContainer = (app as any)
44
- .container as NestContainer;
45
- const modules: Module[] = [...container.getModules().values()].filter(
46
- (m) => !!m.controllers.size,
47
- );
48
- for (const m of modules) {
49
- const path: string =
50
- Reflect.getMetadata(
51
- MODULE_PATH + container.getModules().applicationId,
52
- m.metatype,
53
- ) ??
54
- Reflect.getMetadata(MODULE_PATH, m.metatype) ??
55
- "";
56
- for (const controller of [...m.controllers.keys()]) {
57
- const file: string | null =
58
- (await require("get-function-location")(controller))
59
- ?.source ?? null;
60
- if (file === null) continue;
61
-
62
- const location: string = normalize_file(file);
63
- if (location.length === 0) continue;
64
-
65
- const key: Pair<Function, string> = new Pair(
66
- controller as Function,
67
- location,
68
- );
69
- files.take(key, () => new Set([])).add(path);
70
- }
71
- }
72
-
73
- const versioning = (app as any).config?.versioningOptions;
74
- return {
75
- include: files.toJSON().map((pair) => ({
76
- controller: pair.first.first,
77
- file: pair.first.second,
78
- paths: [...pair.second.values()],
79
- })),
80
- globalPrefix:
81
- typeof (app as any).config?.globalPrefix === "string"
82
- ? {
83
- prefix: (app as any).config.globalPrefix,
84
- exclude:
85
- (app as any).config.globalPrefixOptions
86
- ?.exclude ?? {},
87
- }
88
- : undefined,
89
- versioning:
90
- versioning === undefined ||
91
- versioning.type !== VersioningType.URI
92
- ? undefined
93
- : {
94
- prefix:
95
- versioning.prefix === undefined ||
96
- versioning.prefix === false
97
- ? "v"
98
- : versioning.prefix,
99
- defaultVersion: versioning.defaultVersion,
100
- },
101
- };
102
- };
103
-
104
- const normalize_file = (str: string) =>
105
- str.substring(
106
- str.startsWith("file:///")
107
- ? process.cwd()[0] === "/"
108
- ? 7
109
- : 8
110
- : str.startsWith("file://")
111
- ? 7
112
- : 0,
113
- );
114
-
115
- const transform_input =
116
- (config: INestiaConfig) =>
117
- async (include: string[], exclude?: string[]) => ({
118
- include: (
119
- await SourceFinder.find({
120
- include,
121
- exclude,
122
- filter: filter(config),
123
- })
124
- ).map((file) => ({
125
- paths: [""],
126
- file,
127
- })),
128
- });
129
-
130
- const filter =
131
- (config: INestiaConfig) =>
132
- async (location: string): Promise<boolean> =>
133
- location.endsWith(".ts") &&
134
- !location.endsWith(".d.ts") &&
135
- (config.output === undefined ||
136
- (location.indexOf(path.join(config.output, "functional")) ===
137
- -1 &&
138
- (await (
139
- await bundler.get(config.output)
140
- )(location))) === false);
141
- }
142
-
143
- const memory = new Map<INestiaConfig, Promise<INormalizedInput>>();
144
- const bundler = new Singleton(async (output: string) => {
145
- const assets: string[] = await fs.promises.readdir(
146
- SdkGenerator.BUNDLE_PATH,
147
- );
148
- const tuples: Pair<string, boolean>[] = await ArrayUtil.asyncMap(
149
- assets,
150
- async (file) => {
151
- const relative: string = path.join(output, file);
152
- const location: string = path.join(SdkGenerator.BUNDLE_PATH, file);
153
- const stats: fs.Stats = await fs.promises.stat(location);
154
- return new Pair(relative, stats.isDirectory());
155
- },
156
- );
157
- return async (file: string): Promise<boolean> => {
158
- for (const it of tuples)
159
- if (it.second === false && file === it.first) return true;
160
- else if (it.second === true && file.indexOf(it.first) === 0)
161
- return true;
162
- return false;
163
- };
164
- });
1
+ import { INestApplication, VersioningType } from "@nestjs/common";
2
+ import { MODULE_PATH } from "@nestjs/common/constants";
3
+ import { NestContainer } from "@nestjs/core";
4
+ import { Module } from "@nestjs/core/injector/module";
5
+ import fs from "fs";
6
+ import path from "path";
7
+ import { HashMap, Pair, Singleton } from "tstl";
8
+
9
+ import { INestiaConfig } from "../INestiaConfig";
10
+ import { SdkGenerator } from "../generates/SdkGenerator";
11
+ import { INormalizedInput } from "../structures/INormalizedInput";
12
+ import { ArrayUtil } from "../utils/ArrayUtil";
13
+ import { MapUtil } from "../utils/MapUtil";
14
+ import { SourceFinder } from "../utils/SourceFinder";
15
+
16
+ export namespace ConfigAnalyzer {
17
+ export const input = (config: INestiaConfig): Promise<INormalizedInput> =>
18
+ MapUtil.take(memory, config, async () => {
19
+ const input = config.input;
20
+ if (Array.isArray(input)) return transform_input(config)(input);
21
+ else if (typeof input === "function")
22
+ return analyze_application(await input());
23
+ else if (typeof input === "object")
24
+ if (input === null)
25
+ throw new Error("Invalid input config. It can't be null.");
26
+ else return transform_input(config)(input.include, input.exclude);
27
+ else if (typeof input === "string")
28
+ return transform_input(config)([input]);
29
+ else throw new Error("Invalid input config.");
30
+ });
31
+
32
+ const analyze_application = async (
33
+ app: INestApplication,
34
+ ): Promise<INormalizedInput> => {
35
+ const files: HashMap<Pair<Function, string>, Set<string>> = new HashMap();
36
+ const container: NestContainer = (app as any).container as NestContainer;
37
+ const modules: Module[] = [...container.getModules().values()].filter(
38
+ (m) => !!m.controllers.size,
39
+ );
40
+ for (const m of modules) {
41
+ const path: string =
42
+ Reflect.getMetadata(
43
+ MODULE_PATH + container.getModules().applicationId,
44
+ m.metatype,
45
+ ) ??
46
+ Reflect.getMetadata(MODULE_PATH, m.metatype) ??
47
+ "";
48
+ for (const controller of [...m.controllers.keys()]) {
49
+ const file: string | null =
50
+ (await require("get-function-location")(controller))?.source ?? null;
51
+ if (file === null) continue;
52
+
53
+ const location: string = normalize_file(file);
54
+ if (location.length === 0) continue;
55
+
56
+ const key: Pair<Function, string> = new Pair(
57
+ controller as Function,
58
+ location,
59
+ );
60
+ files.take(key, () => new Set([])).add(path);
61
+ }
62
+ }
63
+
64
+ const versioning = (app as any).config?.versioningOptions;
65
+ return {
66
+ include: files.toJSON().map((pair) => ({
67
+ controller: pair.first.first,
68
+ file: pair.first.second,
69
+ paths: [...pair.second.values()],
70
+ })),
71
+ globalPrefix:
72
+ typeof (app as any).config?.globalPrefix === "string"
73
+ ? {
74
+ prefix: (app as any).config.globalPrefix,
75
+ exclude: (app as any).config.globalPrefixOptions?.exclude ?? {},
76
+ }
77
+ : undefined,
78
+ versioning:
79
+ versioning === undefined || versioning.type !== VersioningType.URI
80
+ ? undefined
81
+ : {
82
+ prefix:
83
+ versioning.prefix === undefined || versioning.prefix === false
84
+ ? "v"
85
+ : versioning.prefix,
86
+ defaultVersion: versioning.defaultVersion,
87
+ },
88
+ };
89
+ };
90
+
91
+ const normalize_file = (str: string) =>
92
+ str.substring(
93
+ str.startsWith("file:///")
94
+ ? process.cwd()[0] === "/"
95
+ ? 7
96
+ : 8
97
+ : str.startsWith("file://")
98
+ ? 7
99
+ : 0,
100
+ );
101
+
102
+ const transform_input =
103
+ (config: INestiaConfig) =>
104
+ async (include: string[], exclude?: string[]) => ({
105
+ include: (
106
+ await SourceFinder.find({
107
+ include,
108
+ exclude,
109
+ filter: filter(config),
110
+ })
111
+ ).map((file) => ({
112
+ paths: [""],
113
+ file,
114
+ })),
115
+ });
116
+
117
+ const filter =
118
+ (config: INestiaConfig) =>
119
+ async (location: string): Promise<boolean> =>
120
+ location.endsWith(".ts") &&
121
+ !location.endsWith(".d.ts") &&
122
+ (config.output === undefined ||
123
+ (location.indexOf(path.join(config.output, "functional")) === -1 &&
124
+ (await (
125
+ await bundler.get(config.output)
126
+ )(location))) === false);
127
+ }
128
+
129
+ const memory = new Map<INestiaConfig, Promise<INormalizedInput>>();
130
+ const bundler = new Singleton(async (output: string) => {
131
+ const assets: string[] = await fs.promises.readdir(SdkGenerator.BUNDLE_PATH);
132
+ const tuples: Pair<string, boolean>[] = await ArrayUtil.asyncMap(
133
+ assets,
134
+ async (file) => {
135
+ const relative: string = path.join(output, file);
136
+ const location: string = path.join(SdkGenerator.BUNDLE_PATH, file);
137
+ const stats: fs.Stats = await fs.promises.stat(location);
138
+ return new Pair(relative, stats.isDirectory());
139
+ },
140
+ );
141
+ return async (file: string): Promise<boolean> => {
142
+ for (const it of tuples)
143
+ if (it.second === false && file === it.first) return true;
144
+ else if (it.second === true && file.indexOf(it.first) === 0) return true;
145
+ return false;
146
+ };
147
+ });