@nestia/sdk 1.6.7-dev.20230830 → 2.0.0-dev.20230830

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 (27) hide show
  1. package/assets/config/nestia.config.ts +15 -40
  2. package/lib/executable/internal/NestiaSdkConfig.js +4 -0
  3. package/lib/executable/internal/NestiaSdkConfig.js.map +1 -1
  4. package/lib/generates/E2eGenerator.js +2 -1
  5. package/lib/generates/E2eGenerator.js.map +1 -1
  6. package/lib/generates/SwaggerGenerator.js +10 -10
  7. package/lib/generates/internal/E2eFileProgrammer.d.ts +2 -1
  8. package/lib/generates/internal/E2eFileProgrammer.js +30 -19
  9. package/lib/generates/internal/E2eFileProgrammer.js.map +1 -1
  10. package/lib/generates/internal/SdkFileProgrammer.js +14 -30
  11. package/lib/generates/internal/SdkFileProgrammer.js.map +1 -1
  12. package/lib/generates/internal/SdkFunctionProgrammer.d.ts +2 -1
  13. package/lib/generates/internal/SdkFunctionProgrammer.js +72 -26
  14. package/lib/generates/internal/SdkFunctionProgrammer.js.map +1 -1
  15. package/lib/generates/internal/SdkSimulationProgrammer.d.ts +3 -1
  16. package/lib/generates/internal/SdkSimulationProgrammer.js +42 -24
  17. package/lib/generates/internal/SdkSimulationProgrammer.js.map +1 -1
  18. package/lib/utils/ImportDictionary.d.ts +16 -2
  19. package/lib/utils/ImportDictionary.js +66 -25
  20. package/lib/utils/ImportDictionary.js.map +1 -1
  21. package/package.json +5 -5
  22. package/src/generates/E2eGenerator.ts +4 -1
  23. package/src/generates/internal/E2eFileProgrammer.ts +36 -19
  24. package/src/generates/internal/SdkFileProgrammer.ts +20 -56
  25. package/src/generates/internal/SdkFunctionProgrammer.ts +85 -24
  26. package/src/generates/internal/SdkSimulationProgrammer.ts +107 -73
  27. package/src/utils/ImportDictionary.ts +97 -33
@@ -4,53 +4,117 @@ import { HashSet } from "tstl/container/HashSet";
4
4
  import { Pair } from "tstl/utility/Pair";
5
5
 
6
6
  export class ImportDictionary {
7
- private readonly dict_: HashMap<string, Pair<boolean, HashSet<string>>> =
7
+ private readonly externals_: HashMap<Pair<string, boolean>, IComposition> =
8
+ new HashMap();
9
+ private readonly internals_: HashMap<Pair<string, boolean>, IComposition> =
8
10
  new HashMap();
9
11
 
10
12
  public empty(): boolean {
11
- return this.dict_.empty();
13
+ return this.internals_.empty() && this.externals_.empty();
14
+ }
15
+
16
+ public external(props: ImportDictionary.IExternalProps): string {
17
+ const composition: IComposition = this.externals_.take(
18
+ new Pair(props.library, props.type),
19
+ () => ({
20
+ location: 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;
12
29
  }
13
30
 
14
- public emplace(file: string, realistic: boolean, instance: string): void {
15
- if (file.substr(-5) === ".d.ts") file = file.substr(0, file.length - 5);
16
- else if (file.substr(-3) === ".ts")
17
- file = file.substr(0, file.length - 3);
18
- else
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(0, props.file.length - 3) === ".ts")
36
+ return props.file.substring(0, props.file.length - 3);
19
37
  throw new Error(
20
- `Error on ImportDictionary.emplace(): extension of the target file "${file}" is not "ts".`,
38
+ `Error on ImportDictionary.emplace(): extension of the target file "${props.file}" is not "ts".`,
21
39
  );
22
-
23
- const pair: Pair<boolean, HashSet<string>> = this.dict_.take(
24
- file,
25
- () => new Pair(realistic, new HashSet()),
40
+ })();
41
+ const composition: IComposition = this.internals_.take(
42
+ new Pair(file, props.type),
43
+ () => ({
44
+ location: file,
45
+ elements: new HashSet(),
46
+ default: false,
47
+ type: props.type,
48
+ }),
26
49
  );
27
- pair.second.insert(instance);
50
+ if (props.instance === null) composition.default = true;
51
+ else composition.elements.insert(props.instance);
52
+ return props.instance ?? file;
28
53
  }
29
54
 
30
55
  public toScript(outDir: string): string {
31
56
  const statements: string[] = [];
32
- for (const it of this.dict_) {
33
- const file: string = (() => {
34
- const location: string = path
35
- .relative(outDir, it.first)
36
- .split("\\")
37
- .join("/");
38
- const index: number = location.lastIndexOf(NODE_MODULES);
39
- return index === -1
40
- ? `./${location}`
41
- : location.substring(index + NODE_MODULES.length);
42
- })();
43
- const realistic: boolean = it.second.first;
44
- const instances: string[] = it.second.second.toJSON();
45
-
46
- statements.push(
47
- `import ${!realistic ? "type " : ""}{ ${instances.join(
48
- ", ",
49
- )} } from "${file}";`,
50
- );
51
- }
57
+ const enroll =
58
+ (locator: (str: string) => string) =>
59
+ (dict: HashMap<Pair<string, boolean>, IComposition>) => {
60
+ const compositions: IComposition[] = dict
61
+ .toJSON()
62
+ .map((e) => ({
63
+ ...e.second,
64
+ location: locator(e.second.location),
65
+ }))
66
+ .sort((a, b) => a.location.localeCompare(b.location));
67
+ for (const c of compositions) {
68
+ const brackets: string[] = [];
69
+ if (c.default) brackets.push(c.location);
70
+ if (c.elements.empty() === false)
71
+ brackets.push(
72
+ `{${c.elements
73
+ .toJSON()
74
+ .sort((a, b) => a.localeCompare(b))
75
+ .join(", ")}`,
76
+ );
77
+ statements.push(
78
+ `import ${c.type ? "type " : ""} ${brackets.join(
79
+ ", ",
80
+ )} from "${c.location}";`,
81
+ );
82
+ }
83
+ };
84
+
85
+ enroll((str) => str)(this.externals_);
86
+ if (this.internals_.size()) statements.push("");
87
+ enroll((str) => {
88
+ const location: string = path
89
+ .relative(outDir, str)
90
+ .split("\\")
91
+ .join("/");
92
+ const index: number = location.lastIndexOf(NODE_MODULES);
93
+ return index === -1
94
+ ? `./${location}`
95
+ : location.substring(index + NODE_MODULES.length);
96
+ })(this.internals_);
52
97
  return statements.join("\n");
53
98
  }
54
99
  }
100
+ export namespace ImportDictionary {
101
+ export interface IInternalProps {
102
+ type: boolean;
103
+ file: string;
104
+ instance: string;
105
+ }
106
+ export interface IExternalProps {
107
+ type: boolean;
108
+ library: string;
109
+ instance: string | null;
110
+ }
111
+ }
112
+
113
+ interface IComposition {
114
+ location: string;
115
+ type: boolean;
116
+ default: boolean;
117
+ elements: HashSet<string>;
118
+ }
55
119
 
56
120
  const NODE_MODULES = "node_modules/";