@nestia/sdk 2.4.5 → 2.4.6

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 (66) hide show
  1. package/lib/analyses/ConfigAnalyzer.js +1 -1
  2. package/lib/analyses/ConfigAnalyzer.js.map +1 -1
  3. package/lib/analyses/ControllerAnalyzer.js.map +1 -1
  4. package/lib/analyses/PathAnalyzer.js.map +1 -1
  5. package/lib/analyses/ReflectAnalyzer.js.map +1 -1
  6. package/lib/executable/sdk.js +11 -11
  7. package/lib/generates/SwaggerGenerator.js.map +1 -1
  8. package/lib/generates/internal/SdkFunctionProgrammer.js +7 -7
  9. package/lib/generates/internal/SdkSimulationProgrammer.js.map +1 -1
  10. package/lib/generates/internal/SwaggerSchemaGenerator.js.map +1 -1
  11. package/package.json +3 -3
  12. package/src/INestiaConfig.ts +248 -248
  13. package/src/NestiaSdkApplication.ts +253 -253
  14. package/src/analyses/AccessorAnalyzer.ts +60 -60
  15. package/src/analyses/ConfigAnalyzer.ts +3 -3
  16. package/src/analyses/ControllerAnalyzer.ts +2 -2
  17. package/src/analyses/ExceptionAnalyzer.ts +115 -115
  18. package/src/analyses/GenericAnalyzer.ts +51 -51
  19. package/src/analyses/ImportAnalyzer.ts +138 -138
  20. package/src/analyses/PathAnalyzer.ts +14 -14
  21. package/src/analyses/ReflectAnalyzer.ts +9 -9
  22. package/src/analyses/SecurityAnalyzer.ts +20 -20
  23. package/src/executable/internal/CommandParser.ts +15 -15
  24. package/src/executable/internal/NestiaConfigLoader.ts +67 -67
  25. package/src/executable/internal/NestiaSdkCommand.ts +60 -60
  26. package/src/executable/sdk.ts +73 -73
  27. package/src/generates/E2eGenerator.ts +64 -64
  28. package/src/generates/SdkGenerator.ts +96 -96
  29. package/src/generates/SwaggerGenerator.ts +5 -5
  30. package/src/generates/internal/E2eFileProgrammer.ts +123 -123
  31. package/src/generates/internal/SdkDistributionComposer.ts +91 -91
  32. package/src/generates/internal/SdkDtoGenerator.ts +424 -424
  33. package/src/generates/internal/SdkFileProgrammer.ts +106 -106
  34. package/src/generates/internal/SdkFunctionProgrammer.ts +518 -518
  35. package/src/generates/internal/SdkImportWizard.ts +55 -55
  36. package/src/generates/internal/SdkRouteDirectory.ts +17 -17
  37. package/src/generates/internal/SdkSimulationProgrammer.ts +4 -4
  38. package/src/generates/internal/SdkTypeDefiner.ts +119 -119
  39. package/src/generates/internal/SwaggerSchemaGenerator.ts +16 -16
  40. package/src/generates/internal/SwaggerSchemaValidator.ts +198 -198
  41. package/src/index.ts +4 -4
  42. package/src/module.ts +2 -2
  43. package/src/structures/IController.ts +91 -91
  44. package/src/structures/IErrorReport.ts +6 -6
  45. package/src/structures/INestiaProject.ts +13 -13
  46. package/src/structures/INormalizedInput.ts +20 -20
  47. package/src/structures/IRoute.ts +52 -52
  48. package/src/structures/ISwagger.ts +91 -91
  49. package/src/structures/ISwaggerComponents.ts +29 -29
  50. package/src/structures/ISwaggerError.ts +8 -8
  51. package/src/structures/ISwaggerInfo.ts +80 -80
  52. package/src/structures/ISwaggerLazyProperty.ts +7 -7
  53. package/src/structures/ISwaggerLazySchema.ts +7 -7
  54. package/src/structures/ISwaggerRoute.ts +51 -51
  55. package/src/structures/ISwaggerSecurityScheme.ts +65 -65
  56. package/src/structures/ITypeTuple.ts +6 -6
  57. package/src/structures/MethodType.ts +5 -5
  58. package/src/structures/ParamCategory.ts +1 -1
  59. package/src/structures/TypeEntry.ts +22 -22
  60. package/src/utils/ArrayUtil.ts +26 -26
  61. package/src/utils/FileRetriever.ts +22 -22
  62. package/src/utils/ImportDictionary.ts +125 -125
  63. package/src/utils/MapUtil.ts +14 -14
  64. package/src/utils/PathUtil.ts +10 -10
  65. package/src/utils/SourceFinder.ts +66 -66
  66. package/src/utils/StripEnums.ts +5 -5
@@ -1,51 +1,51 @@
1
- import { IJsonSchema } from "typia";
2
- import { IJsDocTagInfo } from "typia/lib/schemas/metadata/IJsDocTagInfo";
3
-
4
- export interface ISwaggerRoute {
5
- deprecated?: boolean;
6
- security?: Record<string, string[]>[];
7
- operationId?: string;
8
- tags: string[];
9
- parameters: ISwaggerRoute.IParameter[];
10
- requestBody?: ISwaggerRoute.IRequestBody;
11
- responses: ISwaggerRoute.IResponseBody;
12
- summary?: string;
13
- description?: string;
14
- "x-nestia-method"?: string;
15
- "x-nestia-namespace"?: string;
16
- "x-nestia-jsDocTags"?: IJsDocTagInfo[];
17
- }
18
- export namespace ISwaggerRoute {
19
- export interface IParameter {
20
- name: string;
21
- in: string;
22
- schema: IJsonSchema;
23
- required: boolean;
24
- description?: string;
25
- }
26
- export interface IRequestBody {
27
- description?: string;
28
- content: IContent;
29
- required: true;
30
- "x-nestia-encrypted"?: boolean;
31
- }
32
- export type IResponseBody = Record<
33
- string,
34
- {
35
- description: string;
36
- content?: IContent;
37
- "x-nestia-encrypted"?: boolean;
38
- }
39
- >;
40
- export interface IContent {
41
- "application/x-www-form-urlencoded"?: {
42
- schema: IJsonSchema;
43
- };
44
- "application/json"?: {
45
- schema: IJsonSchema;
46
- };
47
- "text/plain"?: {
48
- schema: IJsonSchema;
49
- };
50
- }
51
- }
1
+ import { IJsonSchema } from "typia";
2
+ import { IJsDocTagInfo } from "typia/lib/schemas/metadata/IJsDocTagInfo";
3
+
4
+ export interface ISwaggerRoute {
5
+ deprecated?: boolean;
6
+ security?: Record<string, string[]>[];
7
+ operationId?: string;
8
+ tags: string[];
9
+ parameters: ISwaggerRoute.IParameter[];
10
+ requestBody?: ISwaggerRoute.IRequestBody;
11
+ responses: ISwaggerRoute.IResponseBody;
12
+ summary?: string;
13
+ description?: string;
14
+ "x-nestia-method"?: string;
15
+ "x-nestia-namespace"?: string;
16
+ "x-nestia-jsDocTags"?: IJsDocTagInfo[];
17
+ }
18
+ export namespace ISwaggerRoute {
19
+ export interface IParameter {
20
+ name: string;
21
+ in: string;
22
+ schema: IJsonSchema;
23
+ required: boolean;
24
+ description?: string;
25
+ }
26
+ export interface IRequestBody {
27
+ description?: string;
28
+ content: IContent;
29
+ required: true;
30
+ "x-nestia-encrypted"?: boolean;
31
+ }
32
+ export type IResponseBody = Record<
33
+ string,
34
+ {
35
+ description: string;
36
+ content?: IContent;
37
+ "x-nestia-encrypted"?: boolean;
38
+ }
39
+ >;
40
+ export interface IContent {
41
+ "application/x-www-form-urlencoded"?: {
42
+ schema: IJsonSchema;
43
+ };
44
+ "application/json"?: {
45
+ schema: IJsonSchema;
46
+ };
47
+ "text/plain"?: {
48
+ schema: IJsonSchema;
49
+ };
50
+ }
51
+ }
@@ -1,65 +1,65 @@
1
- /**
2
- * Security scheme of Swagger Documents.
3
- *
4
- * `ISwaggerSecurityScheme` is a data structure representing content of
5
- * `securitySchemes` in `swagger.json` file. It is composed with 5 types of security
6
- * schemes as an union type like below.
7
- *
8
- * @reference https://swagger.io/specification/#security-scheme-object
9
- * @author Jeongho Nam - https://github.com/samchon
10
- */
11
- export type ISwaggerSecurityScheme =
12
- | ISwaggerSecurityScheme.IHttpBasic
13
- | ISwaggerSecurityScheme.IHttpBearer
14
- | ISwaggerSecurityScheme.IApiKey
15
- | ISwaggerSecurityScheme.IOpenId
16
- | ISwaggerSecurityScheme.IOAuth2;
17
- export namespace ISwaggerSecurityScheme {
18
- export interface IHttpBasic {
19
- type: "http";
20
- scheme: "basic";
21
- }
22
- export interface IHttpBearer {
23
- type: "http";
24
- scheme: "bearer";
25
- bearerFormat?: string;
26
- }
27
- export interface IApiKey {
28
- type: "apiKey";
29
-
30
- /**
31
- * @default header
32
- */
33
- in?: "header" | "query" | "cookie";
34
-
35
- /**
36
- * @default Authorization
37
- */
38
- name?: string;
39
- }
40
-
41
- export interface IOpenId {
42
- type: "openIdConnect";
43
- openIdConnectUrl: string;
44
- }
45
-
46
- export interface IOAuth2 {
47
- type: "oauth2";
48
- flows: IOAuth2.IFlowSet;
49
- description?: string;
50
- }
51
- export namespace IOAuth2 {
52
- export interface IFlowSet {
53
- authorizationCode?: IFlow;
54
- implicit?: Omit<IFlow, "tokenUrl">;
55
- password?: Omit<IFlow, "authorizationUrl">;
56
- clientCredentials?: Omit<IFlow, "authorizationUrl">;
57
- }
58
- export interface IFlow {
59
- authorizationUrl: string;
60
- tokenUrl: string;
61
- refreshUrl: string;
62
- scopes?: Record<string, string>;
63
- }
64
- }
65
- }
1
+ /**
2
+ * Security scheme of Swagger Documents.
3
+ *
4
+ * `ISwaggerSecurityScheme` is a data structure representing content of
5
+ * `securitySchemes` in `swagger.json` file. It is composed with 5 types of security
6
+ * schemes as an union type like below.
7
+ *
8
+ * @reference https://swagger.io/specification/#security-scheme-object
9
+ * @author Jeongho Nam - https://github.com/samchon
10
+ */
11
+ export type ISwaggerSecurityScheme =
12
+ | ISwaggerSecurityScheme.IHttpBasic
13
+ | ISwaggerSecurityScheme.IHttpBearer
14
+ | ISwaggerSecurityScheme.IApiKey
15
+ | ISwaggerSecurityScheme.IOpenId
16
+ | ISwaggerSecurityScheme.IOAuth2;
17
+ export namespace ISwaggerSecurityScheme {
18
+ export interface IHttpBasic {
19
+ type: "http";
20
+ scheme: "basic";
21
+ }
22
+ export interface IHttpBearer {
23
+ type: "http";
24
+ scheme: "bearer";
25
+ bearerFormat?: string;
26
+ }
27
+ export interface IApiKey {
28
+ type: "apiKey";
29
+
30
+ /**
31
+ * @default header
32
+ */
33
+ in?: "header" | "query" | "cookie";
34
+
35
+ /**
36
+ * @default Authorization
37
+ */
38
+ name?: string;
39
+ }
40
+
41
+ export interface IOpenId {
42
+ type: "openIdConnect";
43
+ openIdConnectUrl: string;
44
+ }
45
+
46
+ export interface IOAuth2 {
47
+ type: "oauth2";
48
+ flows: IOAuth2.IFlowSet;
49
+ description?: string;
50
+ }
51
+ export namespace IOAuth2 {
52
+ export interface IFlowSet {
53
+ authorizationCode?: IFlow;
54
+ implicit?: Omit<IFlow, "tokenUrl">;
55
+ password?: Omit<IFlow, "authorizationUrl">;
56
+ clientCredentials?: Omit<IFlow, "authorizationUrl">;
57
+ }
58
+ export interface IFlow {
59
+ authorizationUrl: string;
60
+ tokenUrl: string;
61
+ refreshUrl: string;
62
+ scopes?: Record<string, string>;
63
+ }
64
+ }
65
+ }
@@ -1,6 +1,6 @@
1
- import ts from "typescript";
2
-
3
- export interface ITypeTuple {
4
- type: ts.Type;
5
- typeName: string;
6
- }
1
+ import ts from "typescript";
2
+
3
+ export interface ITypeTuple {
4
+ type: ts.Type;
5
+ typeName: string;
6
+ }
@@ -1,5 +1,5 @@
1
- export type MethodType = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
2
-
3
- export namespace MethodType {
4
- export const VALUES: MethodType[] = ["GET", "POST", "PUT", "PATCH", "DELETE"];
5
- }
1
+ export type MethodType = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
2
+
3
+ export namespace MethodType {
4
+ export const VALUES: MethodType[] = ["GET", "POST", "PUT", "PATCH", "DELETE"];
5
+ }
@@ -1 +1 @@
1
- export type ParamCategory = "param" | "query" | "body" | "headers";
1
+ export type ParamCategory = "param" | "query" | "body" | "headers";
@@ -1,22 +1,22 @@
1
- import { hash } from "tstl/functional/hash";
2
- import ts from "typescript";
3
-
4
- export class TypeEntry {
5
- public constructor(
6
- public readonly type: ts.Type,
7
- public readonly nullable: boolean,
8
- public readonly required: boolean,
9
- ) {}
10
-
11
- public equals(obj: TypeEntry): boolean {
12
- return (
13
- this.type === obj.type &&
14
- this.nullable === obj.nullable &&
15
- this.required === obj.required
16
- );
17
- }
18
-
19
- public hashCode(): number {
20
- return hash(this.type, this.nullable, this.required);
21
- }
22
- }
1
+ import { hash } from "tstl/functional/hash";
2
+ import ts from "typescript";
3
+
4
+ export class TypeEntry {
5
+ public constructor(
6
+ public readonly type: ts.Type,
7
+ public readonly nullable: boolean,
8
+ public readonly required: boolean,
9
+ ) {}
10
+
11
+ public equals(obj: TypeEntry): boolean {
12
+ return (
13
+ this.type === obj.type &&
14
+ this.nullable === obj.nullable &&
15
+ this.required === obj.required
16
+ );
17
+ }
18
+
19
+ public hashCode(): number {
20
+ return hash(this.type, this.nullable, this.required);
21
+ }
22
+ }
@@ -1,26 +1,26 @@
1
- export namespace ArrayUtil {
2
- export function has<T>(array: T[], ...items: T[]): boolean {
3
- return items.every(
4
- (elem) => array.find((org) => org === elem) !== undefined,
5
- );
6
- }
7
-
8
- export async function asyncMap<Input, Output>(
9
- array: Input[],
10
- closure: (input: Input) => Promise<Output>,
11
- ): Promise<Output[]> {
12
- const ret: Output[] = [];
13
- for (const elem of array) ret.push(await closure(elem));
14
- return ret;
15
- }
16
-
17
- export async function asyncFilter<Input>(
18
- array: Input[],
19
- closure: (input: Input) => Promise<boolean>,
20
- ): Promise<Input[]> {
21
- const ret: Input[] = [];
22
- for (const elem of array)
23
- if ((await closure(elem)) === true) ret.push(elem);
24
- return ret;
25
- }
26
- }
1
+ export namespace ArrayUtil {
2
+ export function has<T>(array: T[], ...items: T[]): boolean {
3
+ return items.every(
4
+ (elem) => array.find((org) => org === elem) !== undefined,
5
+ );
6
+ }
7
+
8
+ export async function asyncMap<Input, Output>(
9
+ array: Input[],
10
+ closure: (input: Input) => Promise<Output>,
11
+ ): Promise<Output[]> {
12
+ const ret: Output[] = [];
13
+ for (const elem of array) ret.push(await closure(elem));
14
+ return ret;
15
+ }
16
+
17
+ export async function asyncFilter<Input>(
18
+ array: Input[],
19
+ closure: (input: Input) => Promise<boolean>,
20
+ ): Promise<Input[]> {
21
+ const ret: Input[] = [];
22
+ for (const elem of array)
23
+ if ((await closure(elem)) === true) ret.push(elem);
24
+ return ret;
25
+ }
26
+ }
@@ -1,22 +1,22 @@
1
- import fs from "fs";
2
- import path from "path";
3
-
4
- export namespace FileRetriever {
5
- export const directory =
6
- (name: string) =>
7
- (dir: string, depth: number = 0): string | null => {
8
- const location: string = path.join(dir, name);
9
- if (fs.existsSync(location)) return dir;
10
- else if (depth > 2) return null;
11
- return directory(name)(path.join(dir, ".."), depth + 1);
12
- };
13
-
14
- export const file =
15
- (name: string) =>
16
- (directory: string, depth: number = 0): string | null => {
17
- const location: string = path.join(directory, name);
18
- if (fs.existsSync(location)) return location;
19
- else if (depth > 2) return null;
20
- return file(name)(path.join(directory, ".."), depth + 1);
21
- };
22
- }
1
+ import fs from "fs";
2
+ import path from "path";
3
+
4
+ export namespace FileRetriever {
5
+ export const directory =
6
+ (name: string) =>
7
+ (dir: string, depth: number = 0): string | null => {
8
+ const location: string = path.join(dir, name);
9
+ if (fs.existsSync(location)) return dir;
10
+ else if (depth > 2) return null;
11
+ return directory(name)(path.join(dir, ".."), depth + 1);
12
+ };
13
+
14
+ export const file =
15
+ (name: string) =>
16
+ (directory: string, depth: number = 0): string | null => {
17
+ const location: string = path.join(directory, name);
18
+ if (fs.existsSync(location)) return location;
19
+ else if (depth > 2) return null;
20
+ return file(name)(path.join(directory, ".."), depth + 1);
21
+ };
22
+ }
@@ -1,125 +1,125 @@
1
- import path from "path";
2
- import { HashMap } from "tstl/container/HashMap";
3
- import { HashSet } from "tstl/container/HashSet";
4
- import { Pair } from "tstl/utility/Pair";
5
-
6
- export class ImportDictionary {
7
- private readonly components_: HashMap<Pair<string, boolean>, IComposition> =
8
- new HashMap();
9
-
10
- public constructor(public readonly file: string) {}
11
-
12
- public empty(): boolean {
13
- return this.components_.empty();
14
- }
15
-
16
- public external(props: ImportDictionary.IExternalProps): string {
17
- const composition: IComposition = this.components_.take(
18
- new Pair(props.library, props.type),
19
- () => ({
20
- location: `node_modules/${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;
29
- }
30
-
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(props.file.length - 3) === ".ts")
36
- return props.file.substring(0, props.file.length - 3);
37
- return props.file;
38
- })();
39
- const composition: IComposition = this.components_.take(
40
- new Pair(file, props.type),
41
- () => ({
42
- location: file,
43
- elements: new HashSet(),
44
- default: false,
45
- type: props.type,
46
- }),
47
- );
48
- if (props.instance === null) {
49
- composition.default = true;
50
- if (props.name) composition.name = props.name;
51
- } else composition.elements.insert(props.instance);
52
- return props.instance ?? file;
53
- }
54
-
55
- public toScript(outDir: string): string {
56
- const external: string[] = [];
57
- const internal: string[] = [];
58
-
59
- const locator = (str: string) => {
60
- const location: string = path.relative(outDir, str).split("\\").join("/");
61
- const index: number = location.lastIndexOf(NODE_MODULES);
62
- return index === -1
63
- ? location.startsWith("..")
64
- ? location
65
- : `./${location}`
66
- : location.substring(index + NODE_MODULES.length);
67
- };
68
- const enroll =
69
- (filter: (str: string) => boolean) => (container: string[]) => {
70
- const compositions: IComposition[] = this.components_
71
- .toJSON()
72
- .filter((c) => filter(c.second.location))
73
- .map((e) => ({
74
- ...e.second,
75
- location: locator(e.second.location),
76
- }))
77
- .sort((a, b) => a.location.localeCompare(b.location));
78
- for (const c of compositions) {
79
- const brackets: string[] = [];
80
- if (c.default) brackets.push(c.name ?? c.location);
81
- if (c.elements.empty() === false)
82
- brackets.push(
83
- `{ ${c.elements
84
- .toJSON()
85
- .sort((a, b) => a.localeCompare(b))
86
- .join(", ")} }`,
87
- );
88
- container.push(
89
- `import ${c.type ? "type " : ""}${brackets.join(", ")} from "${
90
- c.location
91
- }";`,
92
- );
93
- }
94
- };
95
-
96
- enroll((str) => str.indexOf(NODE_MODULES) !== -1)(external);
97
- enroll((str) => str.indexOf(NODE_MODULES) === -1)(internal);
98
-
99
- if (external.length && internal.length) external.push("");
100
- return [...external, ...internal].join("\n");
101
- }
102
- }
103
- export namespace ImportDictionary {
104
- export interface IExternalProps {
105
- type: boolean;
106
- library: string;
107
- instance: string | null;
108
- }
109
- export interface IInternalProps {
110
- type: boolean;
111
- file: string;
112
- instance: string | null;
113
- name?: string | null;
114
- }
115
- }
116
-
117
- interface IComposition {
118
- location: string;
119
- type: boolean;
120
- default: boolean;
121
- name?: string;
122
- elements: HashSet<string>;
123
- }
124
-
125
- const NODE_MODULES = "node_modules/";
1
+ import path from "path";
2
+ import { HashMap } from "tstl/container/HashMap";
3
+ import { HashSet } from "tstl/container/HashSet";
4
+ import { Pair } from "tstl/utility/Pair";
5
+
6
+ export class ImportDictionary {
7
+ private readonly components_: HashMap<Pair<string, boolean>, IComposition> =
8
+ new HashMap();
9
+
10
+ public constructor(public readonly file: string) {}
11
+
12
+ public empty(): boolean {
13
+ return this.components_.empty();
14
+ }
15
+
16
+ public external(props: ImportDictionary.IExternalProps): string {
17
+ const composition: IComposition = this.components_.take(
18
+ new Pair(props.library, props.type),
19
+ () => ({
20
+ location: `node_modules/${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;
29
+ }
30
+
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(props.file.length - 3) === ".ts")
36
+ return props.file.substring(0, props.file.length - 3);
37
+ return props.file;
38
+ })();
39
+ const composition: IComposition = this.components_.take(
40
+ new Pair(file, props.type),
41
+ () => ({
42
+ location: file,
43
+ elements: new HashSet(),
44
+ default: false,
45
+ type: props.type,
46
+ }),
47
+ );
48
+ if (props.instance === null) {
49
+ composition.default = true;
50
+ if (props.name) composition.name = props.name;
51
+ } else composition.elements.insert(props.instance);
52
+ return props.instance ?? file;
53
+ }
54
+
55
+ public toScript(outDir: string): string {
56
+ const external: string[] = [];
57
+ const internal: string[] = [];
58
+
59
+ const locator = (str: string) => {
60
+ const location: string = path.relative(outDir, str).split("\\").join("/");
61
+ const index: number = location.lastIndexOf(NODE_MODULES);
62
+ return index === -1
63
+ ? location.startsWith("..")
64
+ ? location
65
+ : `./${location}`
66
+ : location.substring(index + NODE_MODULES.length);
67
+ };
68
+ const enroll =
69
+ (filter: (str: string) => boolean) => (container: string[]) => {
70
+ const compositions: IComposition[] = this.components_
71
+ .toJSON()
72
+ .filter((c) => filter(c.second.location))
73
+ .map((e) => ({
74
+ ...e.second,
75
+ location: locator(e.second.location),
76
+ }))
77
+ .sort((a, b) => a.location.localeCompare(b.location));
78
+ for (const c of compositions) {
79
+ const brackets: string[] = [];
80
+ if (c.default) brackets.push(c.name ?? c.location);
81
+ if (c.elements.empty() === false)
82
+ brackets.push(
83
+ `{ ${c.elements
84
+ .toJSON()
85
+ .sort((a, b) => a.localeCompare(b))
86
+ .join(", ")} }`,
87
+ );
88
+ container.push(
89
+ `import ${c.type ? "type " : ""}${brackets.join(", ")} from "${
90
+ c.location
91
+ }";`,
92
+ );
93
+ }
94
+ };
95
+
96
+ enroll((str) => str.indexOf(NODE_MODULES) !== -1)(external);
97
+ enroll((str) => str.indexOf(NODE_MODULES) === -1)(internal);
98
+
99
+ if (external.length && internal.length) external.push("");
100
+ return [...external, ...internal].join("\n");
101
+ }
102
+ }
103
+ export namespace ImportDictionary {
104
+ export interface IExternalProps {
105
+ type: boolean;
106
+ library: string;
107
+ instance: string | null;
108
+ }
109
+ export interface IInternalProps {
110
+ type: boolean;
111
+ file: string;
112
+ instance: string | null;
113
+ name?: string | null;
114
+ }
115
+ }
116
+
117
+ interface IComposition {
118
+ location: string;
119
+ type: boolean;
120
+ default: boolean;
121
+ name?: string;
122
+ elements: HashSet<string>;
123
+ }
124
+
125
+ const NODE_MODULES = "node_modules/";