@nestia/migrate 12.0.0-rc.2 → 12.0.0-rc.3

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/LICENSE +21 -21
  2. package/lib/_virtual/_tstl.mjs +2 -2
  3. package/lib/_virtual/index.mjs +2 -2
  4. package/lib/_virtual/index2.mjs +2 -2
  5. package/lib/_virtual/index3.mjs +2 -2
  6. package/lib/archivers/NestiaMigrateFileArchiver2.mjs +2 -2
  7. package/lib/archivers/NestiaMigrateFileArchiver2.mjs.map +1 -1
  8. package/lib/bundles/NEST_TEMPLATE.js +47 -47
  9. package/lib/bundles/NEST_TEMPLATE.js.map +1 -1
  10. package/lib/bundles/NEST_TEMPLATE2.mjs +47 -47
  11. package/lib/bundles/NEST_TEMPLATE2.mjs.map +1 -1
  12. package/lib/bundles/SDK_TEMPLATE.js +20 -20
  13. package/lib/bundles/SDK_TEMPLATE.js.map +1 -1
  14. package/lib/bundles/SDK_TEMPLATE2.mjs +20 -20
  15. package/lib/bundles/SDK_TEMPLATE2.mjs.map +1 -1
  16. package/lib/index2.mjs +1 -1
  17. package/lib/module2.mjs +2 -2
  18. package/lib/programmers/NestiaMigrateApiProgrammer2.mjs +4 -4
  19. package/lib/programmers/NestiaMigrateApiProgrammer2.mjs.map +1 -1
  20. package/lib/programmers/index2.mjs +1 -1
  21. package/lib/structures/index2.mjs +1 -1
  22. package/package.json +6 -6
  23. package/src/NestiaMigrateApplication.ts +196 -196
  24. package/src/analyzers/NestiaMigrateControllerAnalyzer.ts +51 -51
  25. package/src/archivers/NestiaMigrateFileArchiver.ts +28 -28
  26. package/src/bundles/NEST_TEMPLATE.ts +47 -47
  27. package/src/bundles/SDK_TEMPLATE.ts +20 -20
  28. package/src/executable/NestiaMigrateCommander.ts +115 -115
  29. package/src/executable/NestiaMigrateInquirer.ts +106 -106
  30. package/src/executable/bundle.js +323 -349
  31. package/src/executable/migrate.ts +7 -7
  32. package/src/factories/ExpressionFactory.ts +23 -23
  33. package/src/factories/FormatCheatSheet.ts +71 -71
  34. package/src/factories/IdentifierFactory.ts +84 -84
  35. package/src/factories/LiteralFactory.ts +54 -54
  36. package/src/factories/StatementFactory.ts +56 -56
  37. package/src/factories/TypeFactory.ts +27 -27
  38. package/src/factories/TypeLiteralFactory.ts +62 -62
  39. package/src/index.ts +4 -4
  40. package/src/internal/ts.ts +75 -75
  41. package/src/module.ts +6 -6
  42. package/src/programmers/NestiaMigrateApiFileProgrammer.ts +55 -55
  43. package/src/programmers/NestiaMigrateApiFunctionProgrammer.ts +358 -358
  44. package/src/programmers/NestiaMigrateApiNamespaceProgrammer.ts +511 -511
  45. package/src/programmers/NestiaMigrateApiProgrammer.ts +108 -108
  46. package/src/programmers/NestiaMigrateApiSimulationProgrammer.ts +309 -309
  47. package/src/programmers/NestiaMigrateApiStartProgrammer.ts +198 -198
  48. package/src/programmers/NestiaMigrateDtoProgrammer.ts +117 -117
  49. package/src/programmers/NestiaMigrateE2eFileProgrammer.ts +155 -155
  50. package/src/programmers/NestiaMigrateE2eProgrammer.ts +48 -48
  51. package/src/programmers/NestiaMigrateImportProgrammer.ts +119 -119
  52. package/src/programmers/NestiaMigrateNestControllerProgrammer.ts +70 -70
  53. package/src/programmers/NestiaMigrateNestMethodProgrammer.ts +402 -402
  54. package/src/programmers/NestiaMigrateNestModuleProgrammer.ts +64 -64
  55. package/src/programmers/NestiaMigrateNestProgrammer.ts +89 -89
  56. package/src/programmers/NestiaMigrateSchemaProgrammer.ts +475 -475
  57. package/src/programmers/index.ts +15 -15
  58. package/src/structures/INestiaMigrateConfig.ts +19 -19
  59. package/src/structures/INestiaMigrateContext.ts +9 -9
  60. package/src/structures/INestiaMigrateController.ts +8 -8
  61. package/src/structures/INestiaMigrateFile.ts +5 -5
  62. package/src/structures/index.ts +4 -4
  63. package/src/utils/FilePrinter.ts +44 -44
  64. package/src/utils/MapUtil.ts +13 -13
  65. package/src/utils/StringUtil.ts +109 -109
  66. package/README.md +0 -93
@@ -1,155 +1,155 @@
1
- import { NodeFlags, SyntaxKind, factory } from "@ttsc/factory";
2
- import { IHttpMigrateRoute } from "@typia/interface";
3
- import { OpenApi } from "typia";
4
-
5
- import { IdentifierFactory } from "../factories/IdentifierFactory";
6
- import { LiteralFactory } from "../factories/LiteralFactory";
7
- import ts from "../internal/ts";
8
- import { INestiaMigrateConfig } from "../structures/INestiaMigrateConfig";
9
- import { NestiaMigrateImportProgrammer } from "./NestiaMigrateImportProgrammer";
10
- import { NestiaMigrateSchemaProgrammer } from "./NestiaMigrateSchemaProgrammer";
11
-
12
- export namespace NestiaMigrateE2eFunctionProgrammer {
13
- export interface IContext {
14
- config: INestiaMigrateConfig;
15
- components: OpenApi.IComponents;
16
- importer: NestiaMigrateImportProgrammer;
17
- route: IHttpMigrateRoute;
18
- }
19
-
20
- export const write = (ctx: IContext): ts.FunctionDeclaration =>
21
- factory.createFunctionDeclaration(
22
- [
23
- factory.createModifier(SyntaxKind.ExportKeyword),
24
- factory.createModifier(SyntaxKind.AsyncKeyword),
25
- ],
26
- undefined,
27
- ["test", "api", ...ctx.route.accessor].join("_"),
28
- undefined,
29
- [
30
- IdentifierFactory.parameter(
31
- "connection",
32
- factory.createTypeReferenceNode(
33
- factory.createQualifiedName(
34
- factory.createIdentifier(
35
- ctx.importer.external({
36
- type: "default",
37
- library: "@ORGANIZATION/PROJECT-api",
38
- name: "api",
39
- }),
40
- ),
41
- factory.createIdentifier("IConnection"),
42
- ),
43
- ),
44
- ),
45
- ],
46
- undefined,
47
- factory.createBlock(writeBody(ctx), true),
48
- );
49
-
50
- export const writeBody = (ctx: IContext): ts.Statement[] => [
51
- factory.createVariableStatement(
52
- [],
53
- factory.createVariableDeclarationList(
54
- [
55
- factory.createVariableDeclaration(
56
- "output",
57
- undefined,
58
- ctx.route.success
59
- ? NestiaMigrateSchemaProgrammer.write({
60
- components: ctx.components,
61
- importer: ctx.importer,
62
- schema: ctx.route.success.schema,
63
- })
64
- : undefined,
65
- factory.createAwaitExpression(writeCallExpressionn(ctx)),
66
- ),
67
- ],
68
- NodeFlags.Const,
69
- ),
70
- ),
71
- factory.createExpressionStatement(
72
- factory.createCallExpression(
73
- factory.createPropertyAccessExpression(
74
- factory.createIdentifier(
75
- ctx.importer.external({
76
- type: "default",
77
- library: "typia",
78
- name: "typia",
79
- }),
80
- ),
81
- "assert",
82
- ),
83
- undefined,
84
- [factory.createIdentifier("output")],
85
- ),
86
- ),
87
- ];
88
-
89
- const writeCallExpressionn = (ctx: IContext): ts.CallExpression => {
90
- const fetch = factory.createPropertyAccessExpression(
91
- factory.createIdentifier("api.functional"),
92
- factory.createIdentifier(ctx.route.accessor.join(".")),
93
- );
94
- const connection = factory.createIdentifier("connection");
95
- if (
96
- ctx.route.parameters.length === 0 &&
97
- ctx.route.query === null &&
98
- ctx.route.body === null
99
- )
100
- return factory.createCallExpression(fetch, undefined, [connection]);
101
-
102
- const random = factory.createPropertyAccessExpression(
103
- factory.createIdentifier(
104
- ctx.importer.external({
105
- type: "default",
106
- library: "typia",
107
- name: "typia",
108
- }),
109
- ),
110
- "random",
111
- );
112
- if (ctx.config.keyword === true)
113
- return factory.createCallExpression(fetch, undefined, [
114
- connection,
115
- LiteralFactory.write(
116
- Object.fromEntries(
117
- [...ctx.route.parameters, ctx.route.query, ctx.route.body]
118
- .filter((x) => x !== null)
119
- .map(({ key, schema: value }) => [
120
- key,
121
- factory.createCallExpression(
122
- random,
123
- [
124
- NestiaMigrateSchemaProgrammer.write({
125
- components: ctx.components,
126
- importer: ctx.importer,
127
- schema: value,
128
- }),
129
- ],
130
- undefined,
131
- ),
132
- ]),
133
- ),
134
- ),
135
- ]);
136
- return factory.createCallExpression(fetch, undefined, [
137
- connection,
138
- ...[...ctx.route.parameters, ctx.route.query, ctx.route.body]
139
- .filter((p) => !!p)
140
- .map((p) =>
141
- factory.createCallExpression(
142
- random,
143
- [
144
- NestiaMigrateSchemaProgrammer.write({
145
- components: ctx.components,
146
- importer: ctx.importer,
147
- schema: p.schema,
148
- }),
149
- ],
150
- undefined,
151
- ),
152
- ),
153
- ]);
154
- };
155
- }
1
+ import { NodeFlags, SyntaxKind, factory } from "@ttsc/factory";
2
+ import { IHttpMigrateRoute } from "@typia/interface";
3
+ import { OpenApi } from "typia";
4
+
5
+ import { IdentifierFactory } from "../factories/IdentifierFactory";
6
+ import { LiteralFactory } from "../factories/LiteralFactory";
7
+ import ts from "../internal/ts";
8
+ import { INestiaMigrateConfig } from "../structures/INestiaMigrateConfig";
9
+ import { NestiaMigrateImportProgrammer } from "./NestiaMigrateImportProgrammer";
10
+ import { NestiaMigrateSchemaProgrammer } from "./NestiaMigrateSchemaProgrammer";
11
+
12
+ export namespace NestiaMigrateE2eFunctionProgrammer {
13
+ export interface IContext {
14
+ config: INestiaMigrateConfig;
15
+ components: OpenApi.IComponents;
16
+ importer: NestiaMigrateImportProgrammer;
17
+ route: IHttpMigrateRoute;
18
+ }
19
+
20
+ export const write = (ctx: IContext): ts.FunctionDeclaration =>
21
+ factory.createFunctionDeclaration(
22
+ [
23
+ factory.createModifier(SyntaxKind.ExportKeyword),
24
+ factory.createModifier(SyntaxKind.AsyncKeyword),
25
+ ],
26
+ undefined,
27
+ ["test", "api", ...ctx.route.accessor].join("_"),
28
+ undefined,
29
+ [
30
+ IdentifierFactory.parameter(
31
+ "connection",
32
+ factory.createTypeReferenceNode(
33
+ factory.createQualifiedName(
34
+ factory.createIdentifier(
35
+ ctx.importer.external({
36
+ type: "default",
37
+ library: "@ORGANIZATION/PROJECT-api",
38
+ name: "api",
39
+ }),
40
+ ),
41
+ factory.createIdentifier("IConnection"),
42
+ ),
43
+ ),
44
+ ),
45
+ ],
46
+ undefined,
47
+ factory.createBlock(writeBody(ctx), true),
48
+ );
49
+
50
+ export const writeBody = (ctx: IContext): ts.Statement[] => [
51
+ factory.createVariableStatement(
52
+ [],
53
+ factory.createVariableDeclarationList(
54
+ [
55
+ factory.createVariableDeclaration(
56
+ "output",
57
+ undefined,
58
+ ctx.route.success
59
+ ? NestiaMigrateSchemaProgrammer.write({
60
+ components: ctx.components,
61
+ importer: ctx.importer,
62
+ schema: ctx.route.success.schema,
63
+ })
64
+ : undefined,
65
+ factory.createAwaitExpression(writeCallExpressionn(ctx)),
66
+ ),
67
+ ],
68
+ NodeFlags.Const,
69
+ ),
70
+ ),
71
+ factory.createExpressionStatement(
72
+ factory.createCallExpression(
73
+ factory.createPropertyAccessExpression(
74
+ factory.createIdentifier(
75
+ ctx.importer.external({
76
+ type: "default",
77
+ library: "typia",
78
+ name: "typia",
79
+ }),
80
+ ),
81
+ "assert",
82
+ ),
83
+ undefined,
84
+ [factory.createIdentifier("output")],
85
+ ),
86
+ ),
87
+ ];
88
+
89
+ const writeCallExpressionn = (ctx: IContext): ts.CallExpression => {
90
+ const fetch = factory.createPropertyAccessExpression(
91
+ factory.createIdentifier("api.functional"),
92
+ factory.createIdentifier(ctx.route.accessor.join(".")),
93
+ );
94
+ const connection = factory.createIdentifier("connection");
95
+ if (
96
+ ctx.route.parameters.length === 0 &&
97
+ ctx.route.query === null &&
98
+ ctx.route.body === null
99
+ )
100
+ return factory.createCallExpression(fetch, undefined, [connection]);
101
+
102
+ const random = factory.createPropertyAccessExpression(
103
+ factory.createIdentifier(
104
+ ctx.importer.external({
105
+ type: "default",
106
+ library: "typia",
107
+ name: "typia",
108
+ }),
109
+ ),
110
+ "random",
111
+ );
112
+ if (ctx.config.keyword === true)
113
+ return factory.createCallExpression(fetch, undefined, [
114
+ connection,
115
+ LiteralFactory.write(
116
+ Object.fromEntries(
117
+ [...ctx.route.parameters, ctx.route.query, ctx.route.body]
118
+ .filter((x) => x !== null)
119
+ .map(({ key, schema: value }) => [
120
+ key,
121
+ factory.createCallExpression(
122
+ random,
123
+ [
124
+ NestiaMigrateSchemaProgrammer.write({
125
+ components: ctx.components,
126
+ importer: ctx.importer,
127
+ schema: value,
128
+ }),
129
+ ],
130
+ undefined,
131
+ ),
132
+ ]),
133
+ ),
134
+ ),
135
+ ]);
136
+ return factory.createCallExpression(fetch, undefined, [
137
+ connection,
138
+ ...[...ctx.route.parameters, ctx.route.query, ctx.route.body]
139
+ .filter((p) => !!p)
140
+ .map((p) =>
141
+ factory.createCallExpression(
142
+ random,
143
+ [
144
+ NestiaMigrateSchemaProgrammer.write({
145
+ components: ctx.components,
146
+ importer: ctx.importer,
147
+ schema: p.schema,
148
+ }),
149
+ ],
150
+ undefined,
151
+ ),
152
+ ),
153
+ ]);
154
+ };
155
+ }
@@ -1,48 +1,48 @@
1
- import { IHttpMigrateRoute, OpenApi } from "@typia/interface";
2
- import ts from "../internal/ts";
3
-
4
- import { INestiaMigrateConfig } from "../structures/INestiaMigrateConfig";
5
- import { INestiaMigrateContext } from "../structures/INestiaMigrateContext";
6
- import { INestiaMigrateFile } from "../structures/INestiaMigrateFile";
7
- import { FilePrinter } from "../utils/FilePrinter";
8
- import { NestiaMigrateE2eFunctionProgrammer } from "./NestiaMigrateE2eFileProgrammer";
9
- import { NestiaMigrateImportProgrammer } from "./NestiaMigrateImportProgrammer";
10
-
11
- export namespace NestiaMigrateE2eProgrammer {
12
- export const write = (ctx: INestiaMigrateContext): Record<string, string> =>
13
- Object.fromEntries(
14
- ctx.application.routes
15
- .map((r) =>
16
- writeFile(ctx.config, ctx.application.document().components, r),
17
- )
18
- .map((r) => [`${r.location}/${r.file}`, r.content]),
19
- );
20
-
21
- const writeFile = (
22
- config: INestiaMigrateConfig,
23
- components: OpenApi.IComponents,
24
- route: IHttpMigrateRoute,
25
- ): INestiaMigrateFile => {
26
- const importer: NestiaMigrateImportProgrammer =
27
- new NestiaMigrateImportProgrammer();
28
- const func: ts.FunctionDeclaration =
29
- NestiaMigrateE2eFunctionProgrammer.write({
30
- config,
31
- components,
32
- importer,
33
- route,
34
- });
35
- const statements: ts.Statement[] = [
36
- ...importer.toStatements(
37
- (name) => `@ORGANIZATION/PROJECT-api/lib/structures/${name}`,
38
- ),
39
- FilePrinter.newLine(),
40
- func,
41
- ];
42
- return {
43
- location: `test/features/api`,
44
- file: `${["test", "api", ...route.accessor].join("_")}.ts`,
45
- content: FilePrinter.write({ statements }),
46
- };
47
- };
48
- }
1
+ import { IHttpMigrateRoute, OpenApi } from "@typia/interface";
2
+ import ts from "../internal/ts";
3
+
4
+ import { INestiaMigrateConfig } from "../structures/INestiaMigrateConfig";
5
+ import { INestiaMigrateContext } from "../structures/INestiaMigrateContext";
6
+ import { INestiaMigrateFile } from "../structures/INestiaMigrateFile";
7
+ import { FilePrinter } from "../utils/FilePrinter";
8
+ import { NestiaMigrateE2eFunctionProgrammer } from "./NestiaMigrateE2eFileProgrammer";
9
+ import { NestiaMigrateImportProgrammer } from "./NestiaMigrateImportProgrammer";
10
+
11
+ export namespace NestiaMigrateE2eProgrammer {
12
+ export const write = (ctx: INestiaMigrateContext): Record<string, string> =>
13
+ Object.fromEntries(
14
+ ctx.application.routes
15
+ .map((r) =>
16
+ writeFile(ctx.config, ctx.application.document().components, r),
17
+ )
18
+ .map((r) => [`${r.location}/${r.file}`, r.content]),
19
+ );
20
+
21
+ const writeFile = (
22
+ config: INestiaMigrateConfig,
23
+ components: OpenApi.IComponents,
24
+ route: IHttpMigrateRoute,
25
+ ): INestiaMigrateFile => {
26
+ const importer: NestiaMigrateImportProgrammer =
27
+ new NestiaMigrateImportProgrammer();
28
+ const func: ts.FunctionDeclaration =
29
+ NestiaMigrateE2eFunctionProgrammer.write({
30
+ config,
31
+ components,
32
+ importer,
33
+ route,
34
+ });
35
+ const statements: ts.Statement[] = [
36
+ ...importer.toStatements(
37
+ (name) => `@ORGANIZATION/PROJECT-api/lib/structures/${name}`,
38
+ ),
39
+ FilePrinter.newLine(),
40
+ func,
41
+ ];
42
+ return {
43
+ location: `test/features/api`,
44
+ file: `${["test", "api", ...route.accessor].join("_")}.ts`,
45
+ content: FilePrinter.write({ statements }),
46
+ };
47
+ };
48
+ }
@@ -1,119 +1,119 @@
1
- import { factory } from "@ttsc/factory";
2
-
3
- import { TypeLiteralFactory } from "../factories/TypeLiteralFactory";
4
- import ts from "../internal/ts";
5
- import { FilePrinter } from "../utils/FilePrinter";
6
- import { MapUtil } from "../utils/MapUtil";
7
-
8
- export class NestiaMigrateImportProgrammer {
9
- private external_: Map<string, IClause> = new Map();
10
- private dtos_: Set<string> = new Set();
11
-
12
- public constructor() {}
13
-
14
- public empty(): boolean {
15
- return this.external_.size === 0 && this.dtos_.size === 0;
16
- }
17
-
18
- public external(props: MigrateImportProgrammer.IProps): string {
19
- const clause: IClause = MapUtil.take(this.external_)(props.library)(() => ({
20
- default: null,
21
- instances: new Set(),
22
- }));
23
- const name: string = props.name.split(".")[0]!;
24
- if (props.type === "default") clause.default = props.name;
25
- else clause.instances.add(name);
26
- return name;
27
- }
28
-
29
- public dto(name: string, namespace?: string): ts.TypeReferenceNode {
30
- const file: string = name.split(".")[0]!;
31
- this.dtos_.add(file);
32
- return factory.createTypeReferenceNode(
33
- namespace?.length
34
- ? factory.createQualifiedName(
35
- factory.createIdentifier(namespace),
36
- factory.createIdentifier(file),
37
- )
38
- : name,
39
- );
40
- }
41
-
42
- public tag(type: string, arg?: any): ts.TypeReferenceNode {
43
- const instance: string = this.external({
44
- type: "instance",
45
- library: "typia",
46
- name: "tags",
47
- });
48
- return factory.createTypeReferenceNode(
49
- `${instance}.${type}`,
50
- arg === undefined ? [] : [TypeLiteralFactory.generate(arg)],
51
- );
52
- }
53
-
54
- public toStatements(
55
- dtoPath: (name: string) => string,
56
- current?: string,
57
- ): ts.Statement[] {
58
- return [
59
- ...[...this.external_.entries()].map(([library, props]) =>
60
- factory.createImportDeclaration(
61
- undefined,
62
- factory.createImportClause(
63
- false,
64
- props.default !== null
65
- ? factory.createIdentifier(props.default)
66
- : undefined,
67
- props.instances.size
68
- ? factory.createNamedImports(
69
- [...props.instances].map((i) =>
70
- factory.createImportSpecifier(
71
- false,
72
- undefined,
73
- factory.createIdentifier(i),
74
- ),
75
- ),
76
- )
77
- : undefined,
78
- ),
79
- factory.createStringLiteral(library),
80
- ),
81
- ),
82
- ...(this.external_.size && this.dtos_.size
83
- ? [FilePrinter.newLine()]
84
- : []),
85
- ...[...this.dtos_]
86
- .filter(
87
- current ? (name) => name !== current!.split(".")[0] : () => true,
88
- )
89
- .map((i) =>
90
- factory.createImportDeclaration(
91
- undefined,
92
- factory.createImportClause(
93
- false,
94
- undefined,
95
- factory.createNamedImports([
96
- factory.createImportSpecifier(
97
- false,
98
- undefined,
99
- factory.createIdentifier(i),
100
- ),
101
- ]),
102
- ),
103
- factory.createStringLiteral(dtoPath(i)),
104
- ),
105
- ),
106
- ];
107
- }
108
- }
109
- export namespace MigrateImportProgrammer {
110
- export interface IProps {
111
- type: "default" | "instance";
112
- library: string;
113
- name: string;
114
- }
115
- }
116
- interface IClause {
117
- default: string | null;
118
- instances: Set<string>;
119
- }
1
+ import { factory } from "@ttsc/factory";
2
+
3
+ import { TypeLiteralFactory } from "../factories/TypeLiteralFactory";
4
+ import ts from "../internal/ts";
5
+ import { FilePrinter } from "../utils/FilePrinter";
6
+ import { MapUtil } from "../utils/MapUtil";
7
+
8
+ export class NestiaMigrateImportProgrammer {
9
+ private external_: Map<string, IClause> = new Map();
10
+ private dtos_: Set<string> = new Set();
11
+
12
+ public constructor() {}
13
+
14
+ public empty(): boolean {
15
+ return this.external_.size === 0 && this.dtos_.size === 0;
16
+ }
17
+
18
+ public external(props: MigrateImportProgrammer.IProps): string {
19
+ const clause: IClause = MapUtil.take(this.external_)(props.library)(() => ({
20
+ default: null,
21
+ instances: new Set(),
22
+ }));
23
+ const name: string = props.name.split(".")[0]!;
24
+ if (props.type === "default") clause.default = props.name;
25
+ else clause.instances.add(name);
26
+ return name;
27
+ }
28
+
29
+ public dto(name: string, namespace?: string): ts.TypeReferenceNode {
30
+ const file: string = name.split(".")[0]!;
31
+ this.dtos_.add(file);
32
+ return factory.createTypeReferenceNode(
33
+ namespace?.length
34
+ ? factory.createQualifiedName(
35
+ factory.createIdentifier(namespace),
36
+ factory.createIdentifier(file),
37
+ )
38
+ : name,
39
+ );
40
+ }
41
+
42
+ public tag(type: string, arg?: any): ts.TypeReferenceNode {
43
+ const instance: string = this.external({
44
+ type: "instance",
45
+ library: "typia",
46
+ name: "tags",
47
+ });
48
+ return factory.createTypeReferenceNode(
49
+ `${instance}.${type}`,
50
+ arg === undefined ? [] : [TypeLiteralFactory.generate(arg)],
51
+ );
52
+ }
53
+
54
+ public toStatements(
55
+ dtoPath: (name: string) => string,
56
+ current?: string,
57
+ ): ts.Statement[] {
58
+ return [
59
+ ...[...this.external_.entries()].map(([library, props]) =>
60
+ factory.createImportDeclaration(
61
+ undefined,
62
+ factory.createImportClause(
63
+ false,
64
+ props.default !== null
65
+ ? factory.createIdentifier(props.default)
66
+ : undefined,
67
+ props.instances.size
68
+ ? factory.createNamedImports(
69
+ [...props.instances].map((i) =>
70
+ factory.createImportSpecifier(
71
+ false,
72
+ undefined,
73
+ factory.createIdentifier(i),
74
+ ),
75
+ ),
76
+ )
77
+ : undefined,
78
+ ),
79
+ factory.createStringLiteral(library),
80
+ ),
81
+ ),
82
+ ...(this.external_.size && this.dtos_.size
83
+ ? [FilePrinter.newLine()]
84
+ : []),
85
+ ...[...this.dtos_]
86
+ .filter(
87
+ current ? (name) => name !== current!.split(".")[0] : () => true,
88
+ )
89
+ .map((i) =>
90
+ factory.createImportDeclaration(
91
+ undefined,
92
+ factory.createImportClause(
93
+ false,
94
+ undefined,
95
+ factory.createNamedImports([
96
+ factory.createImportSpecifier(
97
+ false,
98
+ undefined,
99
+ factory.createIdentifier(i),
100
+ ),
101
+ ]),
102
+ ),
103
+ factory.createStringLiteral(dtoPath(i)),
104
+ ),
105
+ ),
106
+ ];
107
+ }
108
+ }
109
+ export namespace MigrateImportProgrammer {
110
+ export interface IProps {
111
+ type: "default" | "instance";
112
+ library: string;
113
+ name: string;
114
+ }
115
+ }
116
+ interface IClause {
117
+ default: string | null;
118
+ instances: Set<string>;
119
+ }