@nestia/sdk 1.3.8 → 1.3.10

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 (56) hide show
  1. package/assets/bundle/api/utils/NestiaSimulator.ts +4 -4
  2. package/lib/NestiaSdkApplication.d.ts +1 -1
  3. package/lib/NestiaSdkApplication.js +15 -9
  4. package/lib/NestiaSdkApplication.js.map +1 -1
  5. package/lib/analyses/ControllerAnalyzer.js +3 -3
  6. package/lib/analyses/ControllerAnalyzer.js.map +1 -1
  7. package/lib/analyses/ImportAnalyzer.js +2 -6
  8. package/lib/analyses/ImportAnalyzer.js.map +1 -1
  9. package/lib/executable/internal/NestiaConfigCompilerOptions.d.ts +1 -0
  10. package/lib/executable/internal/NestiaConfigCompilerOptions.js +1 -1
  11. package/lib/executable/internal/NestiaConfigCompilerOptions.js.map +1 -1
  12. package/lib/executable/internal/NestiaSdkCommand.js +2 -2
  13. package/lib/executable/internal/NestiaSdkCommand.js.map +1 -1
  14. package/lib/executable/sdk.js +11 -11
  15. package/lib/generates/SdkGenerator.js +28 -0
  16. package/lib/generates/SdkGenerator.js.map +1 -1
  17. package/lib/generates/SwaggerGenerator.js +9 -9
  18. package/lib/generates/internal/E2eFileProgrammer.js +12 -12
  19. package/lib/generates/internal/SdkSimulationProgrammer.js +15 -14
  20. package/lib/generates/internal/SdkSimulationProgrammer.js.map +1 -1
  21. package/lib/structures/IRoute.d.ts +1 -0
  22. package/package.json +2 -2
  23. package/src/NestiaSdkApplication.ts +273 -262
  24. package/src/analyses/ControllerAnalyzer.ts +266 -261
  25. package/src/analyses/GenericAnalyzer.ts +53 -53
  26. package/src/analyses/ImportAnalyzer.ts +158 -164
  27. package/src/analyses/PathAnalyzer.ts +58 -58
  28. package/src/analyses/ReflectAnalyzer.ts +321 -321
  29. package/src/executable/internal/CommandParser.ts +15 -15
  30. package/src/executable/internal/NestiaConfigCompilerOptions.ts +19 -18
  31. package/src/executable/internal/NestiaSdkCommand.ts +157 -156
  32. package/src/executable/internal/NestiaSdkConfig.ts +36 -36
  33. package/src/executable/internal/nestia.config.getter.ts +12 -12
  34. package/src/executable/sdk.ts +70 -70
  35. package/src/generates/E2eGenerator.ts +67 -67
  36. package/src/generates/SdkGenerator.ts +94 -65
  37. package/src/generates/SwaggerGenerator.ts +504 -504
  38. package/src/generates/internal/E2eFileProgrammer.ts +135 -135
  39. package/src/generates/internal/SdkRouteDirectory.ts +21 -21
  40. package/src/generates/internal/SdkSimulationProgrammer.ts +19 -19
  41. package/src/index.ts +4 -4
  42. package/src/module.ts +2 -2
  43. package/src/structures/IController.ts +31 -31
  44. package/src/structures/IRoute.ts +40 -39
  45. package/src/structures/ISwaggerDocument.ts +120 -120
  46. package/src/structures/ITypeTuple.ts +6 -6
  47. package/src/structures/MethodType.ts +11 -11
  48. package/src/structures/ParamCategory.ts +1 -1
  49. package/src/structures/TypeEntry.ts +22 -22
  50. package/src/utils/ArrayUtil.ts +26 -26
  51. package/src/utils/FileRetriever.ts +22 -22
  52. package/src/utils/ImportDictionary.ts +56 -56
  53. package/src/utils/MapUtil.ts +14 -14
  54. package/src/utils/NestiaConfigUtil.ts +21 -21
  55. package/src/utils/SourceFinder.ts +60 -60
  56. package/src/utils/StripEnums.ts +10 -10
@@ -1,164 +1,158 @@
1
- import { HashMap } from "tstl/container/HashMap";
2
- import { HashSet } from "tstl/container/HashSet";
3
- import ts from "typescript";
4
-
5
- import { ITypeTuple } from "../structures/ITypeTuple";
6
- import { GenericAnalyzer } from "./GenericAnalyzer";
7
-
8
- export namespace ImportAnalyzer {
9
- export interface IOutput {
10
- features: [string, string[]][];
11
- alias: string;
12
- }
13
-
14
- export type Dictionary = HashMap<string, HashSet<string>>;
15
-
16
- export function analyze(
17
- checker: ts.TypeChecker,
18
- genericDict: GenericAnalyzer.Dictionary,
19
- importDict: Dictionary,
20
- type: ts.Type,
21
- ): ITypeTuple | null {
22
- type = get_type(checker, type);
23
- explore_escaped_name(checker, genericDict, importDict, type);
24
-
25
- try {
26
- return {
27
- type,
28
- name: explore_escaped_name(
29
- checker,
30
- genericDict,
31
- importDict,
32
- type,
33
- ),
34
- };
35
- } catch {
36
- return null;
37
- }
38
- }
39
-
40
- /* ---------------------------------------------------------
41
- TYPE
42
- --------------------------------------------------------- */
43
- function get_type(checker: ts.TypeChecker, type: ts.Type): ts.Type {
44
- const symbol: ts.Symbol | undefined = type.getSymbol();
45
- return symbol && get_name(symbol) === "Promise"
46
- ? escape_promise(checker, type)
47
- : type;
48
- }
49
-
50
- function escape_promise(checker: ts.TypeChecker, type: ts.Type): ts.Type {
51
- const generic: readonly ts.Type[] = checker.getTypeArguments(
52
- type as ts.TypeReference,
53
- );
54
- if (generic.length !== 1)
55
- throw new Error(
56
- "Error on ImportAnalyzer.analyze(): invalid promise type.",
57
- );
58
- return generic[0];
59
- }
60
-
61
- function get_name(symbol: ts.Symbol): string {
62
- return explore_name(
63
- symbol.escapedName.toString(),
64
- symbol.getDeclarations()![0].parent,
65
- );
66
- }
67
-
68
- /* ---------------------------------------------------------
69
- ESCAPED TEXT WITH IMPORT STATEMENTS
70
- --------------------------------------------------------- */
71
- function explore_escaped_name(
72
- checker: ts.TypeChecker,
73
- genericDict: GenericAnalyzer.Dictionary,
74
- importDict: Dictionary,
75
- type: ts.Type,
76
- ): string {
77
- //----
78
- // CONDITIONAL BRANCHES
79
- //----
80
- // DECOMPOSE GENERIC ARGUMENT
81
- while (genericDict.has(type) === true) type = genericDict.get(type)!;
82
-
83
- // PRIMITIVE
84
- const symbol: ts.Symbol | undefined =
85
- type.aliasSymbol ?? type.getSymbol();
86
-
87
- // UNION OR INTERSECT
88
- if (type.aliasSymbol === undefined && type.isUnionOrIntersection()) {
89
- const joiner: string = type.isIntersection() ? " & " : " | ";
90
- return type.types
91
- .map((child) =>
92
- explore_escaped_name(
93
- checker,
94
- genericDict,
95
- importDict,
96
- child,
97
- ),
98
- )
99
- .join(joiner);
100
- }
101
-
102
- // NO SYMBOL
103
- else if (symbol === undefined) {
104
- const raw: string = checker.typeToString(
105
- type,
106
- undefined,
107
- ts.TypeFormatFlags.NoTruncation,
108
- );
109
- if (raw === "__object")
110
- throw new Error(
111
- "Error on ImportAnalyzer.analyze(): unnamed type exists.",
112
- );
113
- return raw;
114
- }
115
-
116
- //----
117
- // SPECIALIZATION
118
- //----
119
- const name: string = get_name(symbol);
120
- const sourceFile: ts.SourceFile =
121
- symbol.declarations![0].getSourceFile();
122
-
123
- if (sourceFile.fileName.indexOf("typescript/lib") === -1) {
124
- const set: HashSet<string> = importDict.take(
125
- sourceFile.fileName,
126
- () => new HashSet(),
127
- );
128
- set.insert(name.split(".")[0]);
129
- }
130
-
131
- // CHECK GENERIC
132
- const generic: readonly ts.Type[] = type.aliasSymbol
133
- ? type.aliasTypeArguments || []
134
- : checker.getTypeArguments(type as ts.TypeReference);
135
- return generic.length
136
- ? name === "Promise"
137
- ? explore_escaped_name(
138
- checker,
139
- genericDict,
140
- importDict,
141
- generic[0],
142
- )
143
- : `${name}<${generic
144
- .map((child) =>
145
- explore_escaped_name(
146
- checker,
147
- genericDict,
148
- importDict,
149
- child,
150
- ),
151
- )
152
- .join(", ")}>`
153
- : name;
154
- }
155
-
156
- function explore_name(name: string, decl: ts.Node): string {
157
- return ts.isModuleBlock(decl)
158
- ? explore_name(
159
- `${decl.parent.name.getFullText().trim()}.${name}`,
160
- decl.parent.parent,
161
- )
162
- : name;
163
- }
164
- }
1
+ import { HashMap } from "tstl/container/HashMap";
2
+ import { HashSet } from "tstl/container/HashSet";
3
+ import ts from "typescript";
4
+
5
+ import { ITypeTuple } from "../structures/ITypeTuple";
6
+ import { GenericAnalyzer } from "./GenericAnalyzer";
7
+
8
+ export namespace ImportAnalyzer {
9
+ export interface IOutput {
10
+ features: [string, string[]][];
11
+ alias: string;
12
+ }
13
+
14
+ export type Dictionary = HashMap<string, HashSet<string>>;
15
+
16
+ export function analyze(
17
+ checker: ts.TypeChecker,
18
+ genericDict: GenericAnalyzer.Dictionary,
19
+ importDict: Dictionary,
20
+ type: ts.Type,
21
+ ): ITypeTuple | null {
22
+ type = get_type(checker, type);
23
+ explore_escaped_name(checker, genericDict, importDict, type);
24
+
25
+ try {
26
+ return {
27
+ type,
28
+ name: explore_escaped_name(
29
+ checker,
30
+ genericDict,
31
+ importDict,
32
+ type,
33
+ ),
34
+ };
35
+ } catch {
36
+ return null;
37
+ }
38
+ }
39
+
40
+ /* ---------------------------------------------------------
41
+ TYPE
42
+ --------------------------------------------------------- */
43
+ function get_type(checker: ts.TypeChecker, type: ts.Type): ts.Type {
44
+ const symbol: ts.Symbol | undefined = type.getSymbol();
45
+ return symbol && get_name(symbol) === "Promise"
46
+ ? escape_promise(checker, type)
47
+ : type;
48
+ }
49
+
50
+ function escape_promise(checker: ts.TypeChecker, type: ts.Type): ts.Type {
51
+ const generic: readonly ts.Type[] = checker.getTypeArguments(
52
+ type as ts.TypeReference,
53
+ );
54
+ if (generic.length !== 1)
55
+ throw new Error(
56
+ "Error on ImportAnalyzer.analyze(): invalid promise type.",
57
+ );
58
+ return generic[0];
59
+ }
60
+
61
+ function get_name(symbol: ts.Symbol): string {
62
+ return explore_name(
63
+ symbol.escapedName.toString(),
64
+ symbol.getDeclarations()![0].parent,
65
+ );
66
+ }
67
+
68
+ /* ---------------------------------------------------------
69
+ ESCAPED TEXT WITH IMPORT STATEMENTS
70
+ --------------------------------------------------------- */
71
+ function explore_escaped_name(
72
+ checker: ts.TypeChecker,
73
+ genericDict: GenericAnalyzer.Dictionary,
74
+ importDict: Dictionary,
75
+ type: ts.Type,
76
+ ): string {
77
+ //----
78
+ // CONDITIONAL BRANCHES
79
+ //----
80
+ // DECOMPOSE GENERIC ARGUMENT
81
+ while (genericDict.has(type) === true) type = genericDict.get(type)!;
82
+
83
+ // PRIMITIVE
84
+ const symbol: ts.Symbol | undefined =
85
+ type.aliasSymbol ?? type.getSymbol();
86
+
87
+ // UNION OR INTERSECT
88
+ if (type.aliasSymbol === undefined && type.isUnionOrIntersection()) {
89
+ const joiner: string = type.isIntersection() ? " & " : " | ";
90
+ return type.types
91
+ .map((child) =>
92
+ explore_escaped_name(
93
+ checker,
94
+ genericDict,
95
+ importDict,
96
+ child,
97
+ ),
98
+ )
99
+ .join(joiner);
100
+ }
101
+
102
+ // NO SYMBOL
103
+ else if (symbol === undefined)
104
+ return checker.typeToString(
105
+ type,
106
+ undefined,
107
+ ts.TypeFormatFlags.NoTruncation,
108
+ );
109
+
110
+ //----
111
+ // SPECIALIZATION
112
+ //----
113
+ const name: string = get_name(symbol);
114
+ const sourceFile: ts.SourceFile =
115
+ symbol.declarations![0].getSourceFile();
116
+
117
+ if (sourceFile.fileName.indexOf("typescript/lib") === -1) {
118
+ const set: HashSet<string> = importDict.take(
119
+ sourceFile.fileName,
120
+ () => new HashSet(),
121
+ );
122
+ set.insert(name.split(".")[0]);
123
+ }
124
+
125
+ // CHECK GENERIC
126
+ const generic: readonly ts.Type[] = type.aliasSymbol
127
+ ? type.aliasTypeArguments || []
128
+ : checker.getTypeArguments(type as ts.TypeReference);
129
+ return generic.length
130
+ ? name === "Promise"
131
+ ? explore_escaped_name(
132
+ checker,
133
+ genericDict,
134
+ importDict,
135
+ generic[0],
136
+ )
137
+ : `${name}<${generic
138
+ .map((child) =>
139
+ explore_escaped_name(
140
+ checker,
141
+ genericDict,
142
+ importDict,
143
+ child,
144
+ ),
145
+ )
146
+ .join(", ")}>`
147
+ : name;
148
+ }
149
+
150
+ function explore_name(name: string, decl: ts.Node): string {
151
+ return ts.isModuleBlock(decl)
152
+ ? explore_name(
153
+ `${decl.parent.name.getFullText().trim()}.${name}`,
154
+ decl.parent.parent,
155
+ )
156
+ : name;
157
+ }
158
+ }
@@ -1,58 +1,58 @@
1
- import path from "path";
2
- import { Token, parse } from "path-to-regexp";
3
-
4
- export namespace PathAnalyzer {
5
- export const join = (...args: string[]) =>
6
- "/" +
7
- _Trim(
8
- path
9
- .join(...args)
10
- .split("\\")
11
- .join("/"),
12
- );
13
-
14
- export const espace = (str: string, method: () => string) =>
15
- "/" +
16
- _Parse(str, method)
17
- .map((arg) => (arg.type === "param" ? `:${arg.value}` : arg.value))
18
- .join("/");
19
-
20
- export const parameters = (str: string, method: () => string) =>
21
- _Parse(str, method)
22
- .filter((arg) => arg.type === "param")
23
- .map((arg) => arg.value);
24
-
25
- function _Parse(str: string, method: () => string): IArgument[] {
26
- const tokens: Token[] = parse(path.join(str).split("\\").join("/"));
27
- const output: IArgument[] = [];
28
-
29
- for (const key of tokens) {
30
- if (typeof key === "string")
31
- output.push({
32
- type: "path",
33
- value: _Trim(key),
34
- });
35
- else if (typeof key.name === "number" || _Trim(key.name) === "")
36
- throw new Error(`Error on ${method}: ${ERROR_MESSAGE}.`);
37
- else
38
- output.push({
39
- type: "param",
40
- value: _Trim(key.name),
41
- });
42
- }
43
- return output;
44
- }
45
-
46
- function _Trim(str: string): string {
47
- if (str[0] === "/") str = str.substring(1);
48
- if (str[str.length - 1] === "/") str = str.substring(0, str.length - 1);
49
- return str;
50
- }
51
-
52
- interface IArgument {
53
- type: "param" | "path";
54
- value: string;
55
- }
56
- }
57
-
58
- const ERROR_MESSAGE = "nestia supports only string typed parameter on path";
1
+ import path from "path";
2
+ import { Token, parse } from "path-to-regexp";
3
+
4
+ export namespace PathAnalyzer {
5
+ export const join = (...args: string[]) =>
6
+ "/" +
7
+ _Trim(
8
+ path
9
+ .join(...args)
10
+ .split("\\")
11
+ .join("/"),
12
+ );
13
+
14
+ export const espace = (str: string, method: () => string) =>
15
+ "/" +
16
+ _Parse(str, method)
17
+ .map((arg) => (arg.type === "param" ? `:${arg.value}` : arg.value))
18
+ .join("/");
19
+
20
+ export const parameters = (str: string, method: () => string) =>
21
+ _Parse(str, method)
22
+ .filter((arg) => arg.type === "param")
23
+ .map((arg) => arg.value);
24
+
25
+ function _Parse(str: string, method: () => string): IArgument[] {
26
+ const tokens: Token[] = parse(path.join(str).split("\\").join("/"));
27
+ const output: IArgument[] = [];
28
+
29
+ for (const key of tokens) {
30
+ if (typeof key === "string")
31
+ output.push({
32
+ type: "path",
33
+ value: _Trim(key),
34
+ });
35
+ else if (typeof key.name === "number" || _Trim(key.name) === "")
36
+ throw new Error(`Error on ${method}: ${ERROR_MESSAGE}.`);
37
+ else
38
+ output.push({
39
+ type: "param",
40
+ value: _Trim(key.name),
41
+ });
42
+ }
43
+ return output;
44
+ }
45
+
46
+ function _Trim(str: string): string {
47
+ if (str[0] === "/") str = str.substring(1);
48
+ if (str[str.length - 1] === "/") str = str.substring(0, str.length - 1);
49
+ return str;
50
+ }
51
+
52
+ interface IArgument {
53
+ type: "param" | "path";
54
+ value: string;
55
+ }
56
+ }
57
+
58
+ const ERROR_MESSAGE = "nestia supports only string typed parameter on path";