@nestia/sdk 1.0.0 → 1.0.2

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 +28 -9
  3. package/lib/analyses/ControllerAnalyzer.js +21 -1
  4. package/lib/analyses/ControllerAnalyzer.js.map +1 -1
  5. package/lib/executable/internal/NestiaSdkConfig.js +168 -14
  6. package/lib/executable/internal/NestiaSdkConfig.js.map +1 -1
  7. package/lib/executable/sdk.js +16 -16
  8. package/lib/generates/FunctionGenerator.js +35 -15
  9. package/lib/generates/FunctionGenerator.js.map +1 -1
  10. package/lib/generates/SwaggerGenerator.d.ts +1 -1
  11. package/lib/generates/SwaggerGenerator.js +36 -16
  12. package/lib/generates/SwaggerGenerator.js.map +1 -1
  13. package/lib/structures/IRoute.d.ts +8 -0
  14. package/lib/structures/ISwaggerDocument.d.ts +95 -0
  15. package/lib/structures/{ISwagger.js → ISwaggerDocument.js} +1 -1
  16. package/lib/structures/ISwaggerDocument.js.map +1 -0
  17. package/package.json +3 -3
  18. package/src/INestiaConfig.ts +147 -120
  19. package/src/NestiaSdkApplication.ts +183 -183
  20. package/src/analyses/ControllerAnalyzer.ts +223 -203
  21. package/src/analyses/GenericAnalyzer.ts +53 -53
  22. package/src/analyses/ImportAnalyzer.ts +143 -143
  23. package/src/analyses/PathAnalyzer.ts +58 -58
  24. package/src/analyses/ReflectAnalyzer.ts +279 -279
  25. package/src/analyses/SourceFinder.ts +59 -59
  26. package/src/executable/internal/CommandParser.ts +15 -15
  27. package/src/executable/internal/NestiaConfigCompilerOptions.ts +18 -18
  28. package/src/executable/internal/NestiaSdkCommand.ts +174 -174
  29. package/src/executable/internal/NestiaSdkConfig.ts +35 -35
  30. package/src/executable/internal/nestia.config.getter.ts +12 -12
  31. package/src/executable/sdk.ts +74 -74
  32. package/src/generates/FileGenerator.ts +156 -156
  33. package/src/generates/FunctionGenerator.ts +322 -287
  34. package/src/generates/SdkGenerator.ts +50 -50
  35. package/src/generates/SwaggerGenerator.ts +422 -393
  36. package/src/index.ts +3 -3
  37. package/src/module.ts +2 -2
  38. package/src/structures/IController.ts +27 -27
  39. package/src/structures/IRoute.ts +33 -29
  40. package/src/structures/ISwaggerDocument.ts +117 -0
  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/ImportDictionary.ts +56 -56
  47. package/src/utils/MapUtil.ts +14 -14
  48. package/src/utils/StripEnums.ts +10 -10
  49. package/lib/structures/ISwagger.d.ts +0 -48
  50. package/lib/structures/ISwagger.js.map +0 -1
  51. package/src/structures/ISwagger.ts +0 -55
@@ -1,143 +1,143 @@
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 {
22
- type = get_type(checker, type);
23
- return {
24
- type,
25
- name: explore_escaped_name(checker, genericDict, importDict, type),
26
- };
27
- }
28
-
29
- /* ---------------------------------------------------------
30
- TYPE
31
- --------------------------------------------------------- */
32
- function get_type(checker: ts.TypeChecker, type: ts.Type): ts.Type {
33
- const symbol: ts.Symbol | undefined = type.getSymbol();
34
- return symbol && get_name(symbol) === "Promise"
35
- ? escape_promise(checker, type)
36
- : type;
37
- }
38
-
39
- function escape_promise(checker: ts.TypeChecker, type: ts.Type): ts.Type {
40
- const generic: readonly ts.Type[] = checker.getTypeArguments(
41
- type as ts.TypeReference,
42
- );
43
- if (generic.length !== 1)
44
- throw new Error(
45
- "Error on ImportAnalyzer.analyze(): invalid promise type.",
46
- );
47
- return generic[0];
48
- }
49
-
50
- function get_name(symbol: ts.Symbol): string {
51
- return explore_name(
52
- symbol.escapedName.toString(),
53
- symbol.getDeclarations()![0].parent,
54
- );
55
- }
56
-
57
- /* ---------------------------------------------------------
58
- ESCAPED TEXT WITH IMPORT STATEMENTS
59
- --------------------------------------------------------- */
60
- function explore_escaped_name(
61
- checker: ts.TypeChecker,
62
- genericDict: GenericAnalyzer.Dictionary,
63
- importDict: Dictionary,
64
- type: ts.Type,
65
- ): string {
66
- //----
67
- // CONDITIONAL BRANCHES
68
- //----
69
- // DECOMPOSE GENERIC ARGUMENT
70
- while (genericDict.has(type) === true) type = genericDict.get(type)!;
71
-
72
- // PRIMITIVE
73
- const symbol: ts.Symbol | undefined =
74
- type.aliasSymbol || type.getSymbol();
75
- if (symbol === undefined)
76
- return checker.typeToString(type, undefined, undefined);
77
- // UNION OR INTERSECT
78
- else if (
79
- type.aliasSymbol === undefined &&
80
- type.isUnionOrIntersection()
81
- ) {
82
- const joiner: string = type.isIntersection() ? " & " : " | ";
83
- return type.types
84
- .map((child) =>
85
- explore_escaped_name(
86
- checker,
87
- genericDict,
88
- importDict,
89
- child,
90
- ),
91
- )
92
- .join(joiner);
93
- }
94
-
95
- //----
96
- // SPECIALIZATION
97
- //----
98
- const name: string = get_name(symbol);
99
- const sourceFile: ts.SourceFile =
100
- symbol.declarations![0].getSourceFile();
101
-
102
- if (sourceFile.fileName.indexOf("typescript/lib") === -1) {
103
- const set: HashSet<string> = importDict.take(
104
- sourceFile.fileName,
105
- () => new HashSet(),
106
- );
107
- set.insert(name.split(".")[0]);
108
- }
109
-
110
- // CHECK GENERIC
111
- const generic: readonly ts.Type[] = type.aliasSymbol
112
- ? type.aliasTypeArguments || []
113
- : checker.getTypeArguments(type as ts.TypeReference);
114
- return generic.length
115
- ? name === "Promise"
116
- ? explore_escaped_name(
117
- checker,
118
- genericDict,
119
- importDict,
120
- generic[0],
121
- )
122
- : `${name}<${generic
123
- .map((child) =>
124
- explore_escaped_name(
125
- checker,
126
- genericDict,
127
- importDict,
128
- child,
129
- ),
130
- )
131
- .join(", ")}>`
132
- : name;
133
- }
134
-
135
- function explore_name(name: string, decl: ts.Node): string {
136
- return ts.isModuleBlock(decl)
137
- ? explore_name(
138
- `${decl.parent.name.getText()}.${name}`,
139
- decl.parent.parent,
140
- )
141
- : name;
142
- }
143
- }
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 {
22
+ type = get_type(checker, type);
23
+ return {
24
+ type,
25
+ name: explore_escaped_name(checker, genericDict, importDict, type),
26
+ };
27
+ }
28
+
29
+ /* ---------------------------------------------------------
30
+ TYPE
31
+ --------------------------------------------------------- */
32
+ function get_type(checker: ts.TypeChecker, type: ts.Type): ts.Type {
33
+ const symbol: ts.Symbol | undefined = type.getSymbol();
34
+ return symbol && get_name(symbol) === "Promise"
35
+ ? escape_promise(checker, type)
36
+ : type;
37
+ }
38
+
39
+ function escape_promise(checker: ts.TypeChecker, type: ts.Type): ts.Type {
40
+ const generic: readonly ts.Type[] = checker.getTypeArguments(
41
+ type as ts.TypeReference,
42
+ );
43
+ if (generic.length !== 1)
44
+ throw new Error(
45
+ "Error on ImportAnalyzer.analyze(): invalid promise type.",
46
+ );
47
+ return generic[0];
48
+ }
49
+
50
+ function get_name(symbol: ts.Symbol): string {
51
+ return explore_name(
52
+ symbol.escapedName.toString(),
53
+ symbol.getDeclarations()![0].parent,
54
+ );
55
+ }
56
+
57
+ /* ---------------------------------------------------------
58
+ ESCAPED TEXT WITH IMPORT STATEMENTS
59
+ --------------------------------------------------------- */
60
+ function explore_escaped_name(
61
+ checker: ts.TypeChecker,
62
+ genericDict: GenericAnalyzer.Dictionary,
63
+ importDict: Dictionary,
64
+ type: ts.Type,
65
+ ): string {
66
+ //----
67
+ // CONDITIONAL BRANCHES
68
+ //----
69
+ // DECOMPOSE GENERIC ARGUMENT
70
+ while (genericDict.has(type) === true) type = genericDict.get(type)!;
71
+
72
+ // PRIMITIVE
73
+ const symbol: ts.Symbol | undefined =
74
+ type.aliasSymbol || type.getSymbol();
75
+ if (symbol === undefined)
76
+ return checker.typeToString(type, undefined, undefined);
77
+ // UNION OR INTERSECT
78
+ else if (
79
+ type.aliasSymbol === undefined &&
80
+ type.isUnionOrIntersection()
81
+ ) {
82
+ const joiner: string = type.isIntersection() ? " & " : " | ";
83
+ return type.types
84
+ .map((child) =>
85
+ explore_escaped_name(
86
+ checker,
87
+ genericDict,
88
+ importDict,
89
+ child,
90
+ ),
91
+ )
92
+ .join(joiner);
93
+ }
94
+
95
+ //----
96
+ // SPECIALIZATION
97
+ //----
98
+ const name: string = get_name(symbol);
99
+ const sourceFile: ts.SourceFile =
100
+ symbol.declarations![0].getSourceFile();
101
+
102
+ if (sourceFile.fileName.indexOf("typescript/lib") === -1) {
103
+ const set: HashSet<string> = importDict.take(
104
+ sourceFile.fileName,
105
+ () => new HashSet(),
106
+ );
107
+ set.insert(name.split(".")[0]);
108
+ }
109
+
110
+ // CHECK GENERIC
111
+ const generic: readonly ts.Type[] = type.aliasSymbol
112
+ ? type.aliasTypeArguments || []
113
+ : checker.getTypeArguments(type as ts.TypeReference);
114
+ return generic.length
115
+ ? name === "Promise"
116
+ ? explore_escaped_name(
117
+ checker,
118
+ genericDict,
119
+ importDict,
120
+ generic[0],
121
+ )
122
+ : `${name}<${generic
123
+ .map((child) =>
124
+ explore_escaped_name(
125
+ checker,
126
+ genericDict,
127
+ importDict,
128
+ child,
129
+ ),
130
+ )
131
+ .join(", ")}>`
132
+ : name;
133
+ }
134
+
135
+ function explore_name(name: string, decl: ts.Node): string {
136
+ return ts.isModuleBlock(decl)
137
+ ? explore_name(
138
+ `${decl.parent.name.getText()}.${name}`,
139
+ decl.parent.parent,
140
+ )
141
+ : name;
142
+ }
143
+ }
@@ -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";