@nestia/sdk 1.3.2 → 1.3.4

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 (51) hide show
  1. package/assets/config/nestia.config.ts +70 -70
  2. package/lib/INestiaConfig.d.ts +13 -0
  3. package/lib/executable/internal/NestiaSdkConfig.js +6 -2
  4. package/lib/executable/internal/NestiaSdkConfig.js.map +1 -1
  5. package/lib/executable/sdk.js +11 -11
  6. package/lib/generates/SwaggerGenerator.js +9 -9
  7. package/lib/generates/internal/DistributionComposer.js +1 -1
  8. package/lib/generates/internal/DistributionComposer.js.map +1 -1
  9. package/lib/generates/internal/E2eFileProgrammer.js +12 -12
  10. package/lib/generates/internal/SdkFileProgrammer.js +7 -5
  11. package/lib/generates/internal/SdkFileProgrammer.js.map +1 -1
  12. package/lib/generates/internal/SdkFunctionProgrammer.js +42 -49
  13. package/lib/generates/internal/SdkFunctionProgrammer.js.map +1 -1
  14. package/package.json +6 -4
  15. package/src/INestiaConfig.ts +204 -190
  16. package/src/NestiaSdkApplication.ts +262 -262
  17. package/src/analyses/ControllerAnalyzer.ts +261 -261
  18. package/src/analyses/GenericAnalyzer.ts +53 -53
  19. package/src/analyses/ImportAnalyzer.ts +164 -164
  20. package/src/analyses/PathAnalyzer.ts +58 -58
  21. package/src/analyses/ReflectAnalyzer.ts +321 -321
  22. package/src/executable/internal/CommandParser.ts +15 -15
  23. package/src/executable/internal/NestiaConfigCompilerOptions.ts +18 -18
  24. package/src/executable/internal/NestiaSdkCommand.ts +156 -156
  25. package/src/executable/internal/NestiaSdkConfig.ts +36 -36
  26. package/src/executable/internal/nestia.config.getter.ts +12 -12
  27. package/src/executable/sdk.ts +70 -70
  28. package/src/generates/E2eGenerator.ts +67 -67
  29. package/src/generates/SdkGenerator.ts +56 -56
  30. package/src/generates/SwaggerGenerator.ts +504 -504
  31. package/src/generates/internal/DistributionComposer.ts +98 -97
  32. package/src/generates/internal/E2eFileProgrammer.ts +135 -135
  33. package/src/generates/internal/SdkFileProgrammer.ts +150 -144
  34. package/src/generates/internal/SdkFunctionProgrammer.ts +51 -58
  35. package/src/generates/internal/SdkRouteDirectory.ts +21 -21
  36. package/src/index.ts +4 -4
  37. package/src/module.ts +2 -2
  38. package/src/structures/IController.ts +31 -31
  39. package/src/structures/IRoute.ts +39 -39
  40. package/src/structures/ISwaggerDocument.ts +120 -120
  41. package/src/structures/ITypeTuple.ts +6 -6
  42. package/src/structures/MethodType.ts +11 -11
  43. package/src/structures/ParamCategory.ts +1 -1
  44. package/src/structures/TypeEntry.ts +22 -22
  45. package/src/utils/ArrayUtil.ts +26 -26
  46. package/src/utils/FileRetriever.ts +22 -22
  47. package/src/utils/ImportDictionary.ts +56 -56
  48. package/src/utils/MapUtil.ts +14 -14
  49. package/src/utils/NestiaConfigUtil.ts +21 -21
  50. package/src/utils/SourceFinder.ts +60 -60
  51. package/src/utils/StripEnums.ts +10 -10
@@ -1,164 +1,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
- 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
+ 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,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";