@nestia/sdk 2.5.0-dev.20240130-7 → 2.5.0-dev.20240131

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 (63) hide show
  1. package/lib/NestiaSdkApplication.js +10 -8
  2. package/lib/NestiaSdkApplication.js.map +1 -1
  3. package/lib/analyses/ControllerAnalyzer.js +7 -2
  4. package/lib/analyses/ControllerAnalyzer.js.map +1 -1
  5. package/lib/analyses/ExceptionAnalyzer.js +3 -1
  6. package/lib/analyses/ExceptionAnalyzer.js.map +1 -1
  7. package/lib/executable/sdk.js +11 -11
  8. package/lib/generates/CloneGenerator.js +2 -0
  9. package/lib/generates/CloneGenerator.js.map +1 -1
  10. package/lib/generates/internal/E2eFileProgrammer.js +3 -1
  11. package/lib/generates/internal/E2eFileProgrammer.js.map +1 -1
  12. package/lib/generates/internal/SdkCloneProgrammer.js +4 -1
  13. package/lib/generates/internal/SdkCloneProgrammer.js.map +1 -1
  14. package/lib/generates/internal/SdkTypeProgrammer.js +4 -1
  15. package/lib/generates/internal/SdkTypeProgrammer.js.map +1 -1
  16. package/package.json +3 -3
  17. package/src/NestiaSdkApplication.ts +15 -13
  18. package/src/analyses/AccessorAnalyzer.ts +60 -60
  19. package/src/analyses/ConfigAnalyzer.ts +147 -147
  20. package/src/analyses/ControllerAnalyzer.ts +399 -390
  21. package/src/analyses/ExceptionAnalyzer.ts +119 -115
  22. package/src/analyses/GenericAnalyzer.ts +51 -51
  23. package/src/analyses/ImportAnalyzer.ts +138 -138
  24. package/src/analyses/PathAnalyzer.ts +110 -110
  25. package/src/analyses/ReflectAnalyzer.ts +464 -464
  26. package/src/analyses/SecurityAnalyzer.ts +20 -20
  27. package/src/executable/internal/CommandParser.ts +15 -15
  28. package/src/executable/internal/NestiaConfigLoader.ts +67 -67
  29. package/src/executable/internal/NestiaSdkCommand.ts +60 -60
  30. package/src/executable/sdk.ts +73 -73
  31. package/src/generates/CloneGenerator.ts +1 -0
  32. package/src/generates/internal/E2eFileProgrammer.ts +5 -1
  33. package/src/generates/internal/SdkCloneProgrammer.ts +6 -1
  34. package/src/generates/internal/SdkDistributionComposer.ts +91 -91
  35. package/src/generates/internal/SdkImportWizard.ts +55 -55
  36. package/src/generates/internal/SdkRouteDirectory.ts +17 -17
  37. package/src/generates/internal/SdkTypeProgrammer.ts +6 -1
  38. package/src/generates/internal/SwaggerSchemaGenerator.ts +444 -444
  39. package/src/generates/internal/SwaggerSchemaValidator.ts +198 -198
  40. package/src/index.ts +4 -4
  41. package/src/module.ts +2 -2
  42. package/src/structures/IController.ts +91 -91
  43. package/src/structures/IErrorReport.ts +6 -6
  44. package/src/structures/INestiaProject.ts +13 -13
  45. package/src/structures/INormalizedInput.ts +20 -20
  46. package/src/structures/IRoute.ts +52 -52
  47. package/src/structures/ISwaggerComponents.ts +29 -29
  48. package/src/structures/ISwaggerError.ts +8 -8
  49. package/src/structures/ISwaggerInfo.ts +80 -80
  50. package/src/structures/ISwaggerLazyProperty.ts +7 -7
  51. package/src/structures/ISwaggerLazySchema.ts +7 -7
  52. package/src/structures/ISwaggerRoute.ts +51 -51
  53. package/src/structures/ISwaggerSecurityScheme.ts +65 -65
  54. package/src/structures/ITypeTuple.ts +6 -6
  55. package/src/structures/MethodType.ts +5 -5
  56. package/src/structures/ParamCategory.ts +1 -1
  57. package/src/structures/TypeEntry.ts +22 -22
  58. package/src/utils/ArrayUtil.ts +26 -26
  59. package/src/utils/FileRetriever.ts +22 -22
  60. package/src/utils/MapUtil.ts +14 -14
  61. package/src/utils/PathUtil.ts +10 -10
  62. package/src/utils/SourceFinder.ts +66 -66
  63. package/src/utils/StripEnums.ts +5 -5
@@ -1,147 +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 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: decodeURIComponent(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
- });
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: decodeURIComponent(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
+ });