@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,128 +1,125 @@
1
- import path from "path";
2
- import { HashMap } from "tstl/container/HashMap";
3
- import { HashSet } from "tstl/container/HashSet";
4
- import { Pair } from "tstl/utility/Pair";
5
-
6
- export class ImportDictionary {
7
- private readonly components_: HashMap<Pair<string, boolean>, IComposition> =
8
- new HashMap();
9
-
10
- public constructor(public readonly file: string) {}
11
-
12
- public empty(): boolean {
13
- return this.components_.empty();
14
- }
15
-
16
- public external(props: ImportDictionary.IExternalProps): string {
17
- const composition: IComposition = this.components_.take(
18
- new Pair(props.library, props.type),
19
- () => ({
20
- location: `node_modules/${props.library}`,
21
- elements: new HashSet(),
22
- default: false,
23
- type: props.type,
24
- }),
25
- );
26
- if (props.instance === null) composition.default = true;
27
- else composition.elements.insert(props.instance);
28
- return props.instance ?? props.library;
29
- }
30
-
31
- public internal(props: ImportDictionary.IInternalProps): string {
32
- const file: string = (() => {
33
- if (props.file.substring(props.file.length - 5) === ".d.ts")
34
- return props.file.substring(0, props.file.length - 5);
35
- else if (props.file.substring(props.file.length - 3) === ".ts")
36
- return props.file.substring(0, props.file.length - 3);
37
- return props.file;
38
- })();
39
- const composition: IComposition = this.components_.take(
40
- new Pair(file, props.type),
41
- () => ({
42
- location: file,
43
- elements: new HashSet(),
44
- default: false,
45
- type: props.type,
46
- }),
47
- );
48
- if (props.instance === null) {
49
- composition.default = true;
50
- if (props.name) composition.name = props.name;
51
- } else composition.elements.insert(props.instance);
52
- return props.instance ?? file;
53
- }
54
-
55
- public toScript(outDir: string): string {
56
- const external: string[] = [];
57
- const internal: string[] = [];
58
-
59
- const locator = (str: string) => {
60
- const location: string = path
61
- .relative(outDir, str)
62
- .split("\\")
63
- .join("/");
64
- const index: number = location.lastIndexOf(NODE_MODULES);
65
- return index === -1
66
- ? location.startsWith("..")
67
- ? location
68
- : `./${location}`
69
- : location.substring(index + NODE_MODULES.length);
70
- };
71
- const enroll =
72
- (filter: (str: string) => boolean) => (container: string[]) => {
73
- const compositions: IComposition[] = this.components_
74
- .toJSON()
75
- .filter((c) => filter(c.second.location))
76
- .map((e) => ({
77
- ...e.second,
78
- location: locator(e.second.location),
79
- }))
80
- .sort((a, b) => a.location.localeCompare(b.location));
81
- for (const c of compositions) {
82
- const brackets: string[] = [];
83
- if (c.default) brackets.push(c.name ?? c.location);
84
- if (c.elements.empty() === false)
85
- brackets.push(
86
- `{ ${c.elements
87
- .toJSON()
88
- .sort((a, b) => a.localeCompare(b))
89
- .join(", ")} }`,
90
- );
91
- container.push(
92
- `import ${c.type ? "type " : ""}${brackets.join(
93
- ", ",
94
- )} from "${c.location}";`,
95
- );
96
- }
97
- };
98
-
99
- enroll((str) => str.indexOf(NODE_MODULES) !== -1)(external);
100
- enroll((str) => str.indexOf(NODE_MODULES) === -1)(internal);
101
-
102
- if (external.length && internal.length) external.push("");
103
- return [...external, ...internal].join("\n");
104
- }
105
- }
106
- export namespace ImportDictionary {
107
- export interface IExternalProps {
108
- type: boolean;
109
- library: string;
110
- instance: string | null;
111
- }
112
- export interface IInternalProps {
113
- type: boolean;
114
- file: string;
115
- instance: string | null;
116
- name?: string | null;
117
- }
118
- }
119
-
120
- interface IComposition {
121
- location: string;
122
- type: boolean;
123
- default: boolean;
124
- name?: string;
125
- elements: HashSet<string>;
126
- }
127
-
128
- const NODE_MODULES = "node_modules/";
1
+ import path from "path";
2
+ import { HashMap } from "tstl/container/HashMap";
3
+ import { HashSet } from "tstl/container/HashSet";
4
+ import { Pair } from "tstl/utility/Pair";
5
+
6
+ export class ImportDictionary {
7
+ private readonly components_: HashMap<Pair<string, boolean>, IComposition> =
8
+ new HashMap();
9
+
10
+ public constructor(public readonly file: string) {}
11
+
12
+ public empty(): boolean {
13
+ return this.components_.empty();
14
+ }
15
+
16
+ public external(props: ImportDictionary.IExternalProps): string {
17
+ const composition: IComposition = this.components_.take(
18
+ new Pair(props.library, props.type),
19
+ () => ({
20
+ location: `node_modules/${props.library}`,
21
+ elements: new HashSet(),
22
+ default: false,
23
+ type: props.type,
24
+ }),
25
+ );
26
+ if (props.instance === null) composition.default = true;
27
+ else composition.elements.insert(props.instance);
28
+ return props.instance ?? props.library;
29
+ }
30
+
31
+ public internal(props: ImportDictionary.IInternalProps): string {
32
+ const file: string = (() => {
33
+ if (props.file.substring(props.file.length - 5) === ".d.ts")
34
+ return props.file.substring(0, props.file.length - 5);
35
+ else if (props.file.substring(props.file.length - 3) === ".ts")
36
+ return props.file.substring(0, props.file.length - 3);
37
+ return props.file;
38
+ })();
39
+ const composition: IComposition = this.components_.take(
40
+ new Pair(file, props.type),
41
+ () => ({
42
+ location: file,
43
+ elements: new HashSet(),
44
+ default: false,
45
+ type: props.type,
46
+ }),
47
+ );
48
+ if (props.instance === null) {
49
+ composition.default = true;
50
+ if (props.name) composition.name = props.name;
51
+ } else composition.elements.insert(props.instance);
52
+ return props.instance ?? file;
53
+ }
54
+
55
+ public toScript(outDir: string): string {
56
+ const external: string[] = [];
57
+ const internal: string[] = [];
58
+
59
+ const locator = (str: string) => {
60
+ const location: string = path.relative(outDir, str).split("\\").join("/");
61
+ const index: number = location.lastIndexOf(NODE_MODULES);
62
+ return index === -1
63
+ ? location.startsWith("..")
64
+ ? location
65
+ : `./${location}`
66
+ : location.substring(index + NODE_MODULES.length);
67
+ };
68
+ const enroll =
69
+ (filter: (str: string) => boolean) => (container: string[]) => {
70
+ const compositions: IComposition[] = this.components_
71
+ .toJSON()
72
+ .filter((c) => filter(c.second.location))
73
+ .map((e) => ({
74
+ ...e.second,
75
+ location: locator(e.second.location),
76
+ }))
77
+ .sort((a, b) => a.location.localeCompare(b.location));
78
+ for (const c of compositions) {
79
+ const brackets: string[] = [];
80
+ if (c.default) brackets.push(c.name ?? c.location);
81
+ if (c.elements.empty() === false)
82
+ brackets.push(
83
+ `{ ${c.elements
84
+ .toJSON()
85
+ .sort((a, b) => a.localeCompare(b))
86
+ .join(", ")} }`,
87
+ );
88
+ container.push(
89
+ `import ${c.type ? "type " : ""}${brackets.join(", ")} from "${
90
+ c.location
91
+ }";`,
92
+ );
93
+ }
94
+ };
95
+
96
+ enroll((str) => str.indexOf(NODE_MODULES) !== -1)(external);
97
+ enroll((str) => str.indexOf(NODE_MODULES) === -1)(internal);
98
+
99
+ if (external.length && internal.length) external.push("");
100
+ return [...external, ...internal].join("\n");
101
+ }
102
+ }
103
+ export namespace ImportDictionary {
104
+ export interface IExternalProps {
105
+ type: boolean;
106
+ library: string;
107
+ instance: string | null;
108
+ }
109
+ export interface IInternalProps {
110
+ type: boolean;
111
+ file: string;
112
+ instance: string | null;
113
+ name?: string | null;
114
+ }
115
+ }
116
+
117
+ interface IComposition {
118
+ location: string;
119
+ type: boolean;
120
+ default: boolean;
121
+ name?: string;
122
+ elements: HashSet<string>;
123
+ }
124
+
125
+ const NODE_MODULES = "node_modules/";
@@ -1,14 +1,14 @@
1
- export namespace MapUtil {
2
- export function take<Key, T>(
3
- dict: Map<Key, T>,
4
- key: Key,
5
- generator: () => T,
6
- ): T {
7
- const oldbie: T | undefined = dict.get(key);
8
- if (oldbie) return oldbie;
9
-
10
- const value: T = generator();
11
- dict.set(key, value);
12
- return value;
13
- }
14
- }
1
+ export namespace MapUtil {
2
+ export function take<Key, T>(
3
+ dict: Map<Key, T>,
4
+ key: Key,
5
+ generator: () => T,
6
+ ): T {
7
+ const oldbie: T | undefined = dict.get(key);
8
+ if (oldbie) return oldbie;
9
+
10
+ const value: T = generator();
11
+ dict.set(key, value);
12
+ return value;
13
+ }
14
+ }
@@ -1,10 +1,10 @@
1
- export namespace PathUtil {
2
- export const accessors = (path: string) =>
3
- path
4
- .split("/")
5
- .filter((str) => str.length && str[0] !== ":")
6
- .map(normalize);
7
-
8
- const normalize = (str: string) =>
9
- str.split("-").join("_").split(".").join("_");
10
- }
1
+ export namespace PathUtil {
2
+ export const accessors = (path: string) =>
3
+ path
4
+ .split("/")
5
+ .filter((str) => str.length && str[0] !== ":")
6
+ .map(normalize);
7
+
8
+ const normalize = (str: string) =>
9
+ str.split("-").join("_").split(".").join("_");
10
+ }
@@ -1,70 +1,66 @@
1
- import fs from "fs";
2
- import glob from "glob";
3
- import path from "path";
4
-
5
- export namespace SourceFinder {
6
- interface IProps {
7
- exclude?: string[];
8
- include: string[];
9
- filter: (location: string) => Promise<boolean>;
10
- }
11
-
12
- export const find = async (props: IProps): Promise<string[]> => {
13
- const dict: Set<string> = new Set();
14
-
15
- await emplace(props.filter)(props.include)((str) => dict.add(str));
16
- if (props.exclude?.length)
17
- await emplace(props.filter)(props.exclude)((str) =>
18
- dict.delete(str),
19
- );
20
-
21
- return [...dict];
22
- };
23
-
24
- const emplace =
25
- (filter: (file: string) => Promise<boolean>) =>
26
- (input: string[]) =>
27
- async (closure: (location: string) => void): Promise<void> => {
28
- for (const pattern of input) {
29
- if (_Is_file(pattern)) {
30
- closure(path.resolve(pattern));
31
- continue;
32
- }
33
- for (const file of await _Glob(pattern)) {
34
- const stats: fs.Stats = await fs.promises.stat(file);
35
- if (stats.isDirectory() === true)
36
- await iterate(filter)(closure)(file);
37
- else if (stats.isFile() && (await filter(file)))
38
- closure(file);
39
- }
40
- }
41
- };
42
-
43
- const iterate =
44
- (filter: (location: string) => Promise<boolean>) =>
45
- (closure: (location: string) => void) =>
46
- async (location: string): Promise<void> => {
47
- const directory: string[] = await fs.promises.readdir(location);
48
- for (const file of directory) {
49
- const next: string = path.resolve(`${location}/${file}`);
50
- const stats: fs.Stats = await fs.promises.stat(next);
51
-
52
- if (stats.isDirectory() === true)
53
- await iterate(filter)(closure)(next);
54
- else if (stats.isFile() && (await filter(next))) closure(next);
55
- }
56
- };
57
-
58
- const _Glob = (pattern: string): Promise<string[]> =>
59
- new Promise((resolve, reject) => {
60
- glob(pattern, (err, matches) => {
61
- if (err) reject(err);
62
- else resolve(matches.map((str) => path.resolve(str)));
63
- });
64
- });
65
-
66
- const _Is_file = (pattern: string): boolean =>
67
- pattern.endsWith(".ts") &&
68
- !pattern.endsWith(".d.ts") &&
69
- fs.existsSync(pattern);
70
- }
1
+ import fs from "fs";
2
+ import glob from "glob";
3
+ import path from "path";
4
+
5
+ export namespace SourceFinder {
6
+ interface IProps {
7
+ exclude?: string[];
8
+ include: string[];
9
+ filter: (location: string) => Promise<boolean>;
10
+ }
11
+
12
+ export const find = async (props: IProps): Promise<string[]> => {
13
+ const dict: Set<string> = new Set();
14
+
15
+ await emplace(props.filter)(props.include)((str) => dict.add(str));
16
+ if (props.exclude?.length)
17
+ await emplace(props.filter)(props.exclude)((str) => dict.delete(str));
18
+
19
+ return [...dict];
20
+ };
21
+
22
+ const emplace =
23
+ (filter: (file: string) => Promise<boolean>) =>
24
+ (input: string[]) =>
25
+ async (closure: (location: string) => void): Promise<void> => {
26
+ for (const pattern of input) {
27
+ if (_Is_file(pattern)) {
28
+ closure(path.resolve(pattern));
29
+ continue;
30
+ }
31
+ for (const file of await _Glob(pattern)) {
32
+ const stats: fs.Stats = await fs.promises.stat(file);
33
+ if (stats.isDirectory() === true)
34
+ await iterate(filter)(closure)(file);
35
+ else if (stats.isFile() && (await filter(file))) closure(file);
36
+ }
37
+ }
38
+ };
39
+
40
+ const iterate =
41
+ (filter: (location: string) => Promise<boolean>) =>
42
+ (closure: (location: string) => void) =>
43
+ async (location: string): Promise<void> => {
44
+ const directory: string[] = await fs.promises.readdir(location);
45
+ for (const file of directory) {
46
+ const next: string = path.resolve(`${location}/${file}`);
47
+ const stats: fs.Stats = await fs.promises.stat(next);
48
+
49
+ if (stats.isDirectory() === true) await iterate(filter)(closure)(next);
50
+ else if (stats.isFile() && (await filter(next))) closure(next);
51
+ }
52
+ };
53
+
54
+ const _Glob = (pattern: string): Promise<string[]> =>
55
+ new Promise((resolve, reject) => {
56
+ glob(pattern, (err, matches) => {
57
+ if (err) reject(err);
58
+ else resolve(matches.map((str) => path.resolve(str)));
59
+ });
60
+ });
61
+
62
+ const _Is_file = (pattern: string): boolean =>
63
+ pattern.endsWith(".ts") &&
64
+ !pattern.endsWith(".d.ts") &&
65
+ fs.existsSync(pattern);
66
+ }
@@ -1,10 +1,5 @@
1
- export type StripEnums<T extends Record<string, any>> = {
2
- [Key in keyof T]: T[Key] extends
3
- | string
4
- | boolean
5
- | object
6
- | undefined
7
- | any[]
8
- ? T[Key]
9
- : any;
10
- };
1
+ export type StripEnums<T extends Record<string, any>> = {
2
+ [Key in keyof T]: T[Key] extends string | boolean | object | undefined | any[]
3
+ ? T[Key]
4
+ : any;
5
+ };