@nestia/sdk 2.4.7 → 2.5.0-dev.20240129

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 (40) hide show
  1. package/lib/generates/internal/E2eFileProgrammer.js +44 -46
  2. package/lib/generates/internal/E2eFileProgrammer.js.map +1 -1
  3. package/lib/generates/internal/SdkDtoGenerator.js +2 -1
  4. package/lib/generates/internal/SdkDtoGenerator.js.map +1 -1
  5. package/lib/generates/internal/SdkFileProgrammer.js +16 -10
  6. package/lib/generates/internal/SdkFileProgrammer.js.map +1 -1
  7. package/lib/generates/internal/SdkFunctionProgrammer.d.ts +6 -1
  8. package/lib/generates/internal/SdkFunctionProgrammer.js +73 -323
  9. package/lib/generates/internal/SdkFunctionProgrammer.js.map +1 -1
  10. package/lib/generates/internal/SdkNamespaceProgrammer.d.ts +11 -0
  11. package/lib/generates/internal/SdkNamespaceProgrammer.js +175 -0
  12. package/lib/generates/internal/SdkNamespaceProgrammer.js.map +1 -0
  13. package/lib/generates/internal/SdkRouteProgrammer.d.ts +7 -0
  14. package/lib/generates/internal/SdkRouteProgrammer.js +55 -0
  15. package/lib/generates/internal/SdkRouteProgrammer.js.map +1 -0
  16. package/lib/generates/internal/SdkSimulationProgrammer.d.ts +7 -1
  17. package/lib/generates/internal/SdkSimulationProgrammer.js +98 -88
  18. package/lib/generates/internal/SdkSimulationProgrammer.js.map +1 -1
  19. package/lib/utils/FormatUtil.d.ts +6 -0
  20. package/lib/utils/FormatUtil.js +36 -0
  21. package/lib/utils/FormatUtil.js.map +1 -0
  22. package/lib/utils/ImportDictionary.d.ts +2 -0
  23. package/lib/utils/ImportDictionary.js +45 -0
  24. package/lib/utils/ImportDictionary.js.map +1 -1
  25. package/package.json +6 -3
  26. package/src/analyses/ConfigAnalyzer.ts +147 -147
  27. package/src/analyses/ControllerAnalyzer.ts +390 -390
  28. package/src/analyses/PathAnalyzer.ts +110 -110
  29. package/src/analyses/ReflectAnalyzer.ts +464 -464
  30. package/src/generates/SwaggerGenerator.ts +376 -376
  31. package/src/generates/internal/E2eFileProgrammer.ts +148 -73
  32. package/src/generates/internal/SdkDtoGenerator.ts +6 -1
  33. package/src/generates/internal/SdkFileProgrammer.ts +40 -13
  34. package/src/generates/internal/SdkFunctionProgrammer.ts +176 -475
  35. package/src/generates/internal/SdkNamespaceProgrammer.ts +495 -0
  36. package/src/generates/internal/SdkRouteProgrammer.ts +82 -0
  37. package/src/generates/internal/SdkSimulationProgrammer.ts +359 -133
  38. package/src/generates/internal/SwaggerSchemaGenerator.ts +444 -444
  39. package/src/utils/FormatUtil.ts +30 -0
  40. package/src/utils/ImportDictionary.ts +72 -0
@@ -0,0 +1,30 @@
1
+ import { format } from "prettier";
2
+ import ts from "typescript";
3
+
4
+ export namespace FormatUtil {
5
+ export const description = <Node extends ts.Node>(
6
+ node: Node,
7
+ comment: string,
8
+ ): Node => {
9
+ ts.addSyntheticLeadingComment(
10
+ node,
11
+ ts.SyntaxKind.MultiLineCommentTrivia,
12
+ ["*", ...comment.split("\n").map((str) => ` * ${str}`), ""].join("\n"),
13
+ true,
14
+ );
15
+ return node;
16
+ };
17
+
18
+ export const enter = () =>
19
+ ts.factory.createExpressionStatement(ts.factory.createIdentifier("\n"));
20
+
21
+ export const beautify = async (script: string): Promise<string> => {
22
+ try {
23
+ return format(script, {
24
+ parser: "typescript",
25
+ });
26
+ } catch {
27
+ return script;
28
+ }
29
+ };
30
+ }
@@ -2,6 +2,9 @@ import path from "path";
2
2
  import { HashMap } from "tstl/container/HashMap";
3
3
  import { HashSet } from "tstl/container/HashSet";
4
4
  import { Pair } from "tstl/utility/Pair";
5
+ import ts from "typescript";
6
+
7
+ import { FormatUtil } from "./FormatUtil";
5
8
 
6
9
  export class ImportDictionary {
7
10
  private readonly components_: HashMap<Pair<string, boolean>, IComposition> =
@@ -52,6 +55,75 @@ export class ImportDictionary {
52
55
  return props.instance ?? file;
53
56
  }
54
57
 
58
+ public toStatements(outDir: string): ts.Statement[] {
59
+ const external: ts.ImportDeclaration[] = [];
60
+ const internal: ts.ImportDeclaration[] = [];
61
+
62
+ const locator = (str: string) => {
63
+ const location: string = path.relative(outDir, str).split("\\").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) =>
73
+ (container: ts.ImportDeclaration[]) => {
74
+ const compositions: IComposition[] = this.components_
75
+ .toJSON()
76
+ .filter((c) => filter(c.second.location))
77
+ .map((e) => ({
78
+ ...e.second,
79
+ location: locator(e.second.location),
80
+ }))
81
+ .sort((a, b) => a.location.localeCompare(b.location));
82
+ for (const c of compositions) {
83
+ const brackets: string[] = [];
84
+ if (c.default) brackets.push(c.name ?? c.location);
85
+ if (c.elements.empty() === false)
86
+ brackets.push(
87
+ `{ ${c.elements
88
+ .toJSON()
89
+ .sort((a, b) => a.localeCompare(b))
90
+ .join(", ")} }`,
91
+ );
92
+ container.push(
93
+ ts.factory.createImportDeclaration(
94
+ undefined,
95
+ ts.factory.createImportClause(
96
+ c.type,
97
+ c.default
98
+ ? ts.factory.createIdentifier(c.name ?? c.location)
99
+ : undefined,
100
+ c.elements.empty() === false
101
+ ? ts.factory.createNamedImports(
102
+ [...c.elements].map((elem) =>
103
+ ts.factory.createImportSpecifier(
104
+ false,
105
+ undefined,
106
+ ts.factory.createIdentifier(elem),
107
+ ),
108
+ ),
109
+ )
110
+ : undefined,
111
+ ),
112
+ ts.factory.createStringLiteral(c.location),
113
+ ),
114
+ );
115
+ }
116
+ };
117
+
118
+ enroll((str) => str.indexOf(NODE_MODULES) !== -1)(external);
119
+ enroll((str) => str.indexOf(NODE_MODULES) === -1)(internal);
120
+ return [
121
+ ...external,
122
+ ...(external.length && internal.length ? [FormatUtil.enter()] : []),
123
+ ...internal,
124
+ ];
125
+ }
126
+
55
127
  public toScript(outDir: string): string {
56
128
  const external: string[] = [];
57
129
  const internal: string[] = [];