@nestia/migrate 11.2.1 → 11.3.1

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 (98) hide show
  1. package/lib/bundles/NEST_TEMPLATE.js +2 -2
  2. package/lib/bundles/NEST_TEMPLATE.js.map +1 -1
  3. package/lib/bundles/SDK_TEMPLATE.js +1 -1
  4. package/lib/bundles/SDK_TEMPLATE.js.map +1 -1
  5. package/lib/factories/ExpressionFactory.d.ts +9 -0
  6. package/lib/factories/ExpressionFactory.js +16 -0
  7. package/lib/factories/ExpressionFactory.js.map +1 -0
  8. package/lib/factories/IdentifierFactory.d.ts +11 -0
  9. package/lib/factories/IdentifierFactory.js +36 -0
  10. package/lib/factories/IdentifierFactory.js.map +1 -0
  11. package/lib/factories/LiteralFactory.d.ts +9 -0
  12. package/lib/factories/LiteralFactory.js +52 -0
  13. package/lib/factories/LiteralFactory.js.map +1 -0
  14. package/lib/factories/StatementFactory.d.ts +12 -0
  15. package/lib/factories/StatementFactory.js +20 -0
  16. package/lib/factories/StatementFactory.js.map +1 -0
  17. package/lib/factories/TypeFactory.d.ts +8 -0
  18. package/lib/factories/TypeFactory.js +25 -0
  19. package/lib/factories/TypeFactory.js.map +1 -0
  20. package/lib/factories/TypeLiteralFactory.d.ts +2 -2
  21. package/lib/factories/TypeLiteralFactory.js +12 -15
  22. package/lib/factories/TypeLiteralFactory.js.map +1 -1
  23. package/lib/factories/index.d.ts +5 -0
  24. package/lib/factories/index.js +22 -0
  25. package/lib/factories/index.js.map +1 -0
  26. package/lib/index.mjs +171 -126
  27. package/lib/index.mjs.map +1 -1
  28. package/lib/programmers/NestiaMigrateApiFileProgrammer.d.ts +2 -2
  29. package/lib/programmers/NestiaMigrateApiFileProgrammer.js +2 -5
  30. package/lib/programmers/NestiaMigrateApiFileProgrammer.js.map +1 -1
  31. package/lib/programmers/NestiaMigrateApiFunctionProgrammer.d.ts +3 -3
  32. package/lib/programmers/NestiaMigrateApiFunctionProgrammer.js +45 -48
  33. package/lib/programmers/NestiaMigrateApiFunctionProgrammer.js.map +1 -1
  34. package/lib/programmers/NestiaMigrateApiNamespaceProgrammer.d.ts +3 -3
  35. package/lib/programmers/NestiaMigrateApiNamespaceProgrammer.js +59 -62
  36. package/lib/programmers/NestiaMigrateApiNamespaceProgrammer.js.map +1 -1
  37. package/lib/programmers/NestiaMigrateApiProgrammer.js +2 -5
  38. package/lib/programmers/NestiaMigrateApiProgrammer.js.map +1 -1
  39. package/lib/programmers/NestiaMigrateApiSimulationProgrammer.d.ts +3 -3
  40. package/lib/programmers/NestiaMigrateApiSimulationProgrammer.js +36 -39
  41. package/lib/programmers/NestiaMigrateApiSimulationProgrammer.js.map +1 -1
  42. package/lib/programmers/NestiaMigrateApiStartProgrammer.js +20 -23
  43. package/lib/programmers/NestiaMigrateApiStartProgrammer.js.map +1 -1
  44. package/lib/programmers/NestiaMigrateDtoProgrammer.d.ts +2 -2
  45. package/lib/programmers/NestiaMigrateDtoProgrammer.js +2 -5
  46. package/lib/programmers/NestiaMigrateDtoProgrammer.js.map +1 -1
  47. package/lib/programmers/NestiaMigrateE2eFileProgrammer.d.ts +3 -3
  48. package/lib/programmers/NestiaMigrateE2eFileProgrammer.js +23 -26
  49. package/lib/programmers/NestiaMigrateE2eFileProgrammer.js.map +1 -1
  50. package/lib/programmers/NestiaMigrateE2eProgrammer.js.map +1 -1
  51. package/lib/programmers/NestiaMigrateImportProgrammer.d.ts +4 -4
  52. package/lib/programmers/NestiaMigrateImportProgrammer.js +11 -14
  53. package/lib/programmers/NestiaMigrateImportProgrammer.js.map +1 -1
  54. package/lib/programmers/NestiaMigrateNestControllerProgrammer.d.ts +2 -2
  55. package/lib/programmers/NestiaMigrateNestControllerProgrammer.js +5 -8
  56. package/lib/programmers/NestiaMigrateNestControllerProgrammer.js.map +1 -1
  57. package/lib/programmers/NestiaMigrateNestMethodProgrammer.d.ts +2 -2
  58. package/lib/programmers/NestiaMigrateNestMethodProgrammer.js +32 -37
  59. package/lib/programmers/NestiaMigrateNestMethodProgrammer.js.map +1 -1
  60. package/lib/programmers/NestiaMigrateNestModuleProgrammer.d.ts +2 -2
  61. package/lib/programmers/NestiaMigrateNestModuleProgrammer.js +9 -12
  62. package/lib/programmers/NestiaMigrateNestModuleProgrammer.js.map +1 -1
  63. package/lib/programmers/NestiaMigrateNestProgrammer.js +2 -5
  64. package/lib/programmers/NestiaMigrateNestProgrammer.js.map +1 -1
  65. package/lib/programmers/NestiaMigrateSchemaProgrammer.d.ts +2 -2
  66. package/lib/programmers/NestiaMigrateSchemaProgrammer.js +44 -43
  67. package/lib/programmers/NestiaMigrateSchemaProgrammer.js.map +1 -1
  68. package/lib/structures/INestiaMigrateConfig.d.ts +2 -2
  69. package/lib/utils/FilePrinter.d.ts +4 -4
  70. package/lib/utils/FilePrinter.js +9 -11
  71. package/lib/utils/FilePrinter.js.map +1 -1
  72. package/package.json +8 -7
  73. package/src/bundles/NEST_TEMPLATE.ts +2 -2
  74. package/src/bundles/SDK_TEMPLATE.ts +1 -1
  75. package/src/factories/ExpressionFactory.ts +30 -0
  76. package/src/factories/IdentifierFactory.ts +69 -0
  77. package/src/factories/LiteralFactory.ts +61 -0
  78. package/src/factories/StatementFactory.ts +40 -0
  79. package/src/factories/TypeFactory.ts +33 -0
  80. package/src/factories/TypeLiteralFactory.ts +17 -17
  81. package/src/factories/index.ts +5 -0
  82. package/src/programmers/NestiaMigrateApiFileProgrammer.ts +6 -7
  83. package/src/programmers/NestiaMigrateApiFunctionProgrammer.ts +81 -74
  84. package/src/programmers/NestiaMigrateApiNamespaceProgrammer.ts +143 -142
  85. package/src/programmers/NestiaMigrateApiProgrammer.ts +11 -11
  86. package/src/programmers/NestiaMigrateApiSimulationProgrammer.ts +71 -66
  87. package/src/programmers/NestiaMigrateApiStartProgrammer.ts +58 -52
  88. package/src/programmers/NestiaMigrateDtoProgrammer.ts +5 -5
  89. package/src/programmers/NestiaMigrateE2eFileProgrammer.ts +41 -34
  90. package/src/programmers/NestiaMigrateE2eProgrammer.ts +8 -9
  91. package/src/programmers/NestiaMigrateImportProgrammer.ts +22 -22
  92. package/src/programmers/NestiaMigrateNestControllerProgrammer.ts +8 -8
  93. package/src/programmers/NestiaMigrateNestMethodProgrammer.ts +68 -68
  94. package/src/programmers/NestiaMigrateNestModuleProgrammer.ts +18 -20
  95. package/src/programmers/NestiaMigrateNestProgrammer.ts +14 -14
  96. package/src/programmers/NestiaMigrateSchemaProgrammer.ts +67 -59
  97. package/src/structures/INestiaMigrateConfig.ts +2 -2
  98. package/src/utils/FilePrinter.ts +20 -21
@@ -0,0 +1,69 @@
1
+ import {
2
+ type Expression,
3
+ type Identifier,
4
+ type ParameterDeclaration,
5
+ type StringLiteral,
6
+ SyntaxKind,
7
+ type Token,
8
+ type TypeNode,
9
+ factory,
10
+ } from "@ttsc/factory";
11
+ import { NamingConvention } from "@typia/utils";
12
+
13
+ import { TypeFactory } from "./TypeFactory";
14
+
15
+ /**
16
+ * Identifier / property-access / parameter helpers, mirroring `@typia/core`'s
17
+ * `IdentifierFactory`, built on `@ttsc/factory` so no `typescript` runtime is
18
+ * bundled.
19
+ */
20
+ export namespace IdentifierFactory {
21
+ export const identifier = (name: string): Identifier | StringLiteral =>
22
+ NamingConvention.variable(name)
23
+ ? factory.createIdentifier(name)
24
+ : factory.createStringLiteral(name);
25
+
26
+ export const access = (
27
+ input: Expression,
28
+ key: string,
29
+ chain?: boolean,
30
+ ): Expression => {
31
+ const postfix: Identifier | StringLiteral = identifier(key);
32
+ return postfix.kind === "StringLiteral"
33
+ ? chain === true
34
+ ? factory.createElementAccessChain(
35
+ input,
36
+ factory.createToken(SyntaxKind.QuestionDotToken),
37
+ postfix,
38
+ )
39
+ : factory.createElementAccessExpression(input, postfix)
40
+ : chain === true
41
+ ? factory.createPropertyAccessChain(
42
+ input,
43
+ factory.createToken(SyntaxKind.QuestionDotToken),
44
+ postfix,
45
+ )
46
+ : factory.createPropertyAccessExpression(input, postfix);
47
+ };
48
+
49
+ export const parameter = (
50
+ name: string | Identifier,
51
+ type?: TypeNode,
52
+ init?: Expression | Token,
53
+ ): ParameterDeclaration => {
54
+ // a question token passed as `init` marks the parameter optional (`x?:`),
55
+ // mirroring `@typia/core`'s IdentifierFactory.parameter
56
+ const optional: boolean =
57
+ init !== undefined &&
58
+ init.kind === "Token" &&
59
+ init.token === SyntaxKind.QuestionToken;
60
+ return factory.createParameterDeclaration(
61
+ undefined,
62
+ undefined,
63
+ name,
64
+ optional ? factory.createToken(SyntaxKind.QuestionToken) : undefined,
65
+ type ?? TypeFactory.keyword("any"),
66
+ optional ? undefined : (init as Expression | undefined),
67
+ );
68
+ };
69
+ }
@@ -0,0 +1,61 @@
1
+ import {
2
+ type ArrayLiteralExpression,
3
+ type Expression,
4
+ type ObjectLiteralExpression,
5
+ factory,
6
+ } from "@ttsc/factory";
7
+
8
+ import { ExpressionFactory } from "./ExpressionFactory";
9
+ import { IdentifierFactory } from "./IdentifierFactory";
10
+
11
+ /**
12
+ * JS value → AST expression helper, mirroring `@typia/core`'s
13
+ * `LiteralFactory.write`, built on `@ttsc/factory` so no `typescript` runtime
14
+ * is bundled.
15
+ */
16
+ export namespace LiteralFactory {
17
+ export const write = (input: any): Expression => {
18
+ if (input === null) return factory.createNull();
19
+ else if (isFactoryNode(input)) return input;
20
+ else if (input instanceof Array) return writeArray(input);
21
+ else if (typeof input === "object") return writeObject(input);
22
+ else if (typeof input === "boolean")
23
+ return input ? factory.createTrue() : factory.createFalse();
24
+ else if (typeof input === "bigint") return ExpressionFactory.bigint(input);
25
+ else if (typeof input === "number") return ExpressionFactory.number(input);
26
+ else if (typeof input === "string")
27
+ return factory.createStringLiteral(input);
28
+ // unreachable code
29
+ else if (typeof input === "function")
30
+ return factory.createIdentifier("undefined");
31
+ else throw new TypeError("Error on LiteralFactory.write(): unknown type.");
32
+ };
33
+
34
+ /** Pass already-built expression nodes (arrow / call / identifier) through. */
35
+ const PASSTHROUGH: ReadonlySet<string> = new Set([
36
+ "ArrowFunction",
37
+ "CallExpression",
38
+ "Identifier",
39
+ ]);
40
+ const isFactoryNode = (input: any): input is Expression =>
41
+ typeof input === "object" &&
42
+ input !== null &&
43
+ typeof (input as { kind?: unknown }).kind === "string" &&
44
+ PASSTHROUGH.has((input as { kind: string }).kind);
45
+
46
+ const writeObject = (obj: object): ObjectLiteralExpression =>
47
+ factory.createObjectLiteralExpression(
48
+ Object.entries(obj)
49
+ .filter(([, value]) => value !== undefined)
50
+ .map(([key, value]) =>
51
+ factory.createPropertyAssignment(
52
+ IdentifierFactory.identifier(key),
53
+ write(value),
54
+ ),
55
+ ),
56
+ true,
57
+ );
58
+
59
+ const writeArray = (array: any[]): ArrayLiteralExpression =>
60
+ factory.createArrayLiteralExpression(array.map(write), true);
61
+ }
@@ -0,0 +1,40 @@
1
+ import {
2
+ type Expression,
3
+ type Identifier,
4
+ NodeFlags,
5
+ type TypeNode,
6
+ type VariableStatement,
7
+ factory,
8
+ } from "@ttsc/factory";
9
+
10
+ import { TypeFactory } from "./TypeFactory";
11
+
12
+ /**
13
+ * Variable-statement helpers, mirroring `@typia/core`'s `StatementFactory`,
14
+ * built on `@ttsc/factory` so no `typescript` runtime is bundled.
15
+ */
16
+ export namespace StatementFactory {
17
+ export const constant = (props: {
18
+ name: string | Identifier;
19
+ type?: TypeNode;
20
+ value?: Expression;
21
+ }): VariableStatement =>
22
+ factory.createVariableStatement(
23
+ undefined,
24
+ factory.createVariableDeclarationList(
25
+ [
26
+ factory.createVariableDeclaration(
27
+ props.name,
28
+ undefined,
29
+ props.type !== undefined
30
+ ? props.type
31
+ : props.value === undefined
32
+ ? TypeFactory.keyword("any")
33
+ : undefined,
34
+ props.value,
35
+ ),
36
+ ],
37
+ NodeFlags.Const,
38
+ ),
39
+ );
40
+ }
@@ -0,0 +1,33 @@
1
+ import { type KeywordTypeNode, SyntaxKind, factory } from "@ttsc/factory";
2
+
3
+ /**
4
+ * Keyword type-node helper, mirroring `@typia/core`'s `TypeFactory.keyword`,
5
+ * but built on `@ttsc/factory` so no `typescript` runtime is bundled.
6
+ */
7
+ export namespace TypeFactory {
8
+ export const keyword = (
9
+ type:
10
+ | "void"
11
+ | "any"
12
+ | "unknown"
13
+ | "boolean"
14
+ | "number"
15
+ | "bigint"
16
+ | "string",
17
+ ): KeywordTypeNode =>
18
+ factory.createKeywordTypeNode(
19
+ type === "void"
20
+ ? SyntaxKind.VoidKeyword
21
+ : type === "any"
22
+ ? SyntaxKind.AnyKeyword
23
+ : type === "unknown"
24
+ ? SyntaxKind.UnknownKeyword
25
+ : type === "boolean"
26
+ ? SyntaxKind.BooleanKeyword
27
+ : type === "number"
28
+ ? SyntaxKind.NumberKeyword
29
+ : type === "bigint"
30
+ ? SyntaxKind.BigIntKeyword
31
+ : SyntaxKind.StringKeyword,
32
+ );
33
+ }
@@ -1,8 +1,8 @@
1
+ import { SyntaxKind, type TypeNode, factory } from "@ttsc/factory";
1
2
  import { NamingConvention } from "@typia/utils";
2
- import ts from "typescript";
3
3
 
4
4
  export namespace TypeLiteralFactory {
5
- export const generate = (value: any): ts.TypeNode =>
5
+ export const generate = (value: any): TypeNode =>
6
6
  typeof value === "boolean"
7
7
  ? generateBoolean(value)
8
8
  : typeof value === "number"
@@ -15,40 +15,40 @@ export namespace TypeLiteralFactory {
15
15
  : Array.isArray(value)
16
16
  ? generateTuple(value)
17
17
  : generateObject(value)
18
- : ts.factory.createKeywordTypeNode(ts.SyntaxKind.AnyKeyword);
18
+ : factory.createKeywordTypeNode(SyntaxKind.AnyKeyword);
19
19
 
20
20
  const generatestring = (str: string) =>
21
- ts.factory.createLiteralTypeNode(ts.factory.createStringLiteral(str));
21
+ factory.createLiteralTypeNode(factory.createStringLiteral(str));
22
22
 
23
23
  const generateNumber = (num: number) =>
24
- ts.factory.createLiteralTypeNode(
24
+ factory.createLiteralTypeNode(
25
25
  num < 0
26
- ? ts.factory.createPrefixUnaryExpression(
27
- ts.SyntaxKind.MinusToken,
28
- ts.factory.createNumericLiteral(-num),
26
+ ? factory.createPrefixUnaryExpression(
27
+ SyntaxKind.MinusToken,
28
+ factory.createNumericLiteral(-num),
29
29
  )
30
- : ts.factory.createNumericLiteral(num),
30
+ : factory.createNumericLiteral(num),
31
31
  );
32
32
 
33
33
  const generateBoolean = (bool: boolean) =>
34
- ts.factory.createLiteralTypeNode(
35
- bool ? ts.factory.createTrue() : ts.factory.createFalse(),
34
+ factory.createLiteralTypeNode(
35
+ bool ? factory.createTrue() : factory.createFalse(),
36
36
  );
37
37
 
38
38
  const generateNull = () =>
39
- ts.factory.createLiteralTypeNode(ts.factory.createNull());
39
+ factory.createLiteralTypeNode(factory.createNull());
40
40
 
41
41
  const generateTuple = (items: any[]) =>
42
- ts.factory.createTupleTypeNode(items.map(generate));
42
+ factory.createTupleTypeNode(items.map(generate));
43
43
 
44
44
  const generateObject = (obj: object) =>
45
- ts.factory.createTypeLiteralNode(
45
+ factory.createTypeLiteralNode(
46
46
  Object.entries(obj).map(([key, value]) =>
47
- ts.factory.createPropertySignature(
47
+ factory.createPropertySignature(
48
48
  undefined,
49
49
  NamingConvention.variable(key)
50
- ? ts.factory.createIdentifier(key)
51
- : ts.factory.createStringLiteral(key),
50
+ ? factory.createIdentifier(key)
51
+ : factory.createStringLiteral(key),
52
52
  undefined,
53
53
  generate(value),
54
54
  ),
@@ -0,0 +1,5 @@
1
+ export * from "./ExpressionFactory";
2
+ export * from "./IdentifierFactory";
3
+ export * from "./LiteralFactory";
4
+ export * from "./StatementFactory";
5
+ export * from "./TypeFactory";
@@ -1,5 +1,5 @@
1
+ import { type Statement, factory } from "@ttsc/factory";
1
2
  import { IHttpMigrateRoute, OpenApi } from "@typia/interface";
2
- import ts from "typescript";
3
3
 
4
4
  import { INestiaMigrateConfig } from "../structures/INestiaMigrateConfig";
5
5
  import { FilePrinter } from "../utils/FilePrinter";
@@ -16,10 +16,10 @@ export namespace NestiaMigrateApiFileProgrammer {
16
16
  children: Set<string>;
17
17
  }
18
18
 
19
- export const write = (props: IProps): ts.Statement[] => {
19
+ export const write = (props: IProps): Statement[] => {
20
20
  const importer: NestiaMigrateImportProgrammer =
21
21
  new NestiaMigrateImportProgrammer();
22
- const statements: ts.Statement[] = props.routes
22
+ const statements: Statement[] = props.routes
23
23
  .map((route) => [
24
24
  FilePrinter.newLine(),
25
25
  NestiaMigrateApiFunctionProgrammer.write({
@@ -41,12 +41,11 @@ export namespace NestiaMigrateApiFileProgrammer {
41
41
  (ref) => `../${"../".repeat(props.namespace.length)}structures/${ref}`,
42
42
  ),
43
43
  ...[...props.children].map((child) =>
44
- ts.factory.createExportDeclaration(
44
+ factory.createExportDeclaration(
45
45
  undefined,
46
46
  false,
47
- ts.factory.createNamespaceExport(ts.factory.createIdentifier(child)),
48
- ts.factory.createStringLiteral(`./${child}/index`),
49
- undefined,
47
+ factory.createNamespaceExport(factory.createIdentifier(child)),
48
+ factory.createStringLiteral(`./${child}/index`),
50
49
  ),
51
50
  ),
52
51
  ...statements,
@@ -1,8 +1,15 @@
1
- import { IdentifierFactory, StatementFactory } from "@typia/core";
1
+ import {
2
+ type Expression,
3
+ type FunctionDeclaration,
4
+ type ParameterDeclaration,
5
+ type Statement,
6
+ SyntaxKind,
7
+ factory,
8
+ } from "@ttsc/factory";
2
9
  import { IHttpMigrateRoute, OpenApi } from "@typia/interface";
3
10
  import { NamingConvention } from "@typia/utils";
4
- import ts from "typescript";
5
11
 
12
+ import { IdentifierFactory, StatementFactory } from "../factories";
6
13
  import { INestiaMigrateConfig } from "../structures/INestiaMigrateConfig";
7
14
  import { FilePrinter } from "../utils/FilePrinter";
8
15
  import { NestiaMigrateImportProgrammer } from "./NestiaMigrateImportProgrammer";
@@ -16,25 +23,25 @@ export namespace NestiaMigrateApiFunctionProgrammer {
16
23
  route: IHttpMigrateRoute;
17
24
  }
18
25
 
19
- export const write = (ctx: IContext): ts.FunctionDeclaration =>
26
+ export const write = (ctx: IContext): FunctionDeclaration =>
20
27
  FilePrinter.description(
21
- ts.factory.createFunctionDeclaration(
28
+ factory.createFunctionDeclaration(
22
29
  [
23
- ts.factory.createModifier(ts.SyntaxKind.ExportKeyword),
24
- ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword),
30
+ factory.createModifier(SyntaxKind.ExportKeyword),
31
+ factory.createModifier(SyntaxKind.AsyncKeyword),
25
32
  ],
26
33
  undefined,
27
34
  ctx.route.accessor.at(-1)!,
28
35
  undefined,
29
36
  writeParameterDeclarations(ctx),
30
- ts.factory.createTypeReferenceNode("Promise", [
31
- ts.factory.createTypeReferenceNode(
37
+ factory.createTypeReferenceNode("Promise", [
38
+ factory.createTypeReferenceNode(
32
39
  ctx.route.success === null
33
40
  ? "void"
34
41
  : `${ctx.route.accessor.at(-1)!}.Response`,
35
42
  ),
36
43
  ]),
37
- ts.factory.createBlock(writeBody(ctx), true),
44
+ factory.createBlock(writeBody(ctx), true),
38
45
  ),
39
46
  writeDescription(ctx.config, ctx.route),
40
47
  );
@@ -42,10 +49,10 @@ export namespace NestiaMigrateApiFunctionProgrammer {
42
49
  export const writeParameterDeclarations = (
43
50
  ctx: IContext,
44
51
  connectionName?: string,
45
- ): ts.ParameterDeclaration[] => {
46
- const connection: ts.ParameterDeclaration = IdentifierFactory.parameter(
52
+ ): ParameterDeclaration[] => {
53
+ const connection: ParameterDeclaration = IdentifierFactory.parameter(
47
54
  connectionName ?? "connection",
48
- ts.factory.createTypeReferenceNode(
55
+ factory.createTypeReferenceNode(
49
56
  ctx.importer.external({
50
57
  type: "instance",
51
58
  library: "@nestia/fetcher",
@@ -53,7 +60,7 @@ export namespace NestiaMigrateApiFunctionProgrammer {
53
60
  }),
54
61
  ctx.route.headers
55
62
  ? [
56
- ts.factory.createTypeReferenceNode(
63
+ factory.createTypeReferenceNode(
57
64
  `${ctx.route.accessor.at(-1)!}.Headers`,
58
65
  ),
59
66
  ]
@@ -68,12 +75,12 @@ export namespace NestiaMigrateApiFunctionProgrammer {
68
75
  if (isProps === false) return [connection];
69
76
  return [
70
77
  connection,
71
- ts.factory.createParameterDeclaration(
78
+ factory.createParameterDeclaration(
72
79
  undefined,
73
80
  undefined,
74
81
  "props",
75
82
  undefined,
76
- ts.factory.createTypeReferenceNode(
83
+ factory.createTypeReferenceNode(
77
84
  `${ctx.route.accessor.at(-1)!}.Props`,
78
85
  ),
79
86
  ),
@@ -95,7 +102,7 @@ export namespace NestiaMigrateApiFunctionProgrammer {
95
102
  ? [
96
103
  IdentifierFactory.parameter(
97
104
  ctx.route.query.key,
98
- ts.factory.createTypeReferenceNode(
105
+ factory.createTypeReferenceNode(
99
106
  `${ctx.route.accessor.at(-1)!}.Query`,
100
107
  ),
101
108
  ),
@@ -105,13 +112,13 @@ export namespace NestiaMigrateApiFunctionProgrammer {
105
112
  ? [
106
113
  IdentifierFactory.parameter(
107
114
  ctx.route.body.key,
108
- ts.factory.createTypeReferenceNode(
115
+ factory.createTypeReferenceNode(
109
116
  `${ctx.route.accessor.at(-1)!}.Body`,
110
117
  ),
111
118
  (ctx.route.body.type === "application/json" ||
112
119
  ctx.route.body.type === "text/plain") &&
113
120
  ctx.route.operation().requestBody?.required === false
114
- ? ts.factory.createToken(ts.SyntaxKind.QuestionToken)
121
+ ? factory.createToken(SyntaxKind.QuestionToken)
115
122
  : undefined,
116
123
  ),
117
124
  ]
@@ -134,19 +141,19 @@ export namespace NestiaMigrateApiFunctionProgrammer {
134
141
  ].join("\n");
135
142
  };
136
143
 
137
- const writeBody = (ctx: IContext): ts.Statement[] => {
144
+ const writeBody = (ctx: IContext): Statement[] => {
138
145
  const encrypted: boolean = !!ctx.route.success?.["x-nestia-encrypted"];
139
146
  const contentType: string = ctx.route.body?.type ?? "application/json";
140
147
 
141
- const property = (key: string): ts.Expression =>
148
+ const property = (key: string): Expression =>
142
149
  ctx.config.keyword === true
143
- ? IdentifierFactory.access(ts.factory.createIdentifier("props"), key)
144
- : ts.factory.createIdentifier(key);
150
+ ? IdentifierFactory.access(factory.createIdentifier("props"), key)
151
+ : factory.createIdentifier(key);
145
152
  const fetch = () =>
146
- ts.factory.createAwaitExpression(
147
- ts.factory.createCallExpression(
153
+ factory.createAwaitExpression(
154
+ factory.createCallExpression(
148
155
  IdentifierFactory.access(
149
- ts.factory.createIdentifier(
156
+ factory.createIdentifier(
150
157
  ctx.importer.external({
151
158
  type: "instance",
152
159
  library: encrypted
@@ -160,24 +167,24 @@ export namespace NestiaMigrateApiFunctionProgrammer {
160
167
  undefined,
161
168
  [
162
169
  contentType && contentType !== "multipart/form-data"
163
- ? ts.factory.createObjectLiteralExpression(
170
+ ? factory.createObjectLiteralExpression(
164
171
  [
165
- ts.factory.createSpreadAssignment(
166
- ts.factory.createIdentifier("connection"),
172
+ factory.createSpreadAssignment(
173
+ factory.createIdentifier("connection"),
167
174
  ),
168
- ts.factory.createPropertyAssignment(
175
+ factory.createPropertyAssignment(
169
176
  "headers",
170
- ts.factory.createObjectLiteralExpression(
177
+ factory.createObjectLiteralExpression(
171
178
  [
172
- ts.factory.createSpreadAssignment(
179
+ factory.createSpreadAssignment(
173
180
  IdentifierFactory.access(
174
- ts.factory.createIdentifier("connection"),
181
+ factory.createIdentifier("connection"),
175
182
  "headers",
176
183
  ),
177
184
  ),
178
- ts.factory.createPropertyAssignment(
179
- ts.factory.createStringLiteral("Content-Type"),
180
- ts.factory.createStringLiteral(contentType),
185
+ factory.createPropertyAssignment(
186
+ factory.createStringLiteral("Content-Type"),
187
+ factory.createStringLiteral(contentType),
181
188
  ),
182
189
  ],
183
190
  true,
@@ -186,29 +193,29 @@ export namespace NestiaMigrateApiFunctionProgrammer {
186
193
  ],
187
194
  true,
188
195
  )
189
- : ts.factory.createIdentifier("connection"),
190
- ts.factory.createObjectLiteralExpression(
196
+ : factory.createIdentifier("connection"),
197
+ factory.createObjectLiteralExpression(
191
198
  [
192
- ts.factory.createSpreadAssignment(
199
+ factory.createSpreadAssignment(
193
200
  IdentifierFactory.access(
194
- ts.factory.createIdentifier(ctx.route.accessor.at(-1)!),
201
+ factory.createIdentifier(ctx.route.accessor.at(-1)!),
195
202
  "METADATA",
196
203
  ),
197
204
  ),
198
- ts.factory.createPropertyAssignment(
205
+ factory.createPropertyAssignment(
199
206
  "path",
200
- ts.factory.createCallExpression(
207
+ factory.createCallExpression(
201
208
  IdentifierFactory.access(
202
- ts.factory.createIdentifier(ctx.route.accessor.at(-1)!),
209
+ factory.createIdentifier(ctx.route.accessor.at(-1)!),
203
210
  "path",
204
211
  ),
205
212
  undefined,
206
213
  getArguments(ctx, false),
207
214
  ),
208
215
  ),
209
- ts.factory.createPropertyAssignment(
216
+ factory.createPropertyAssignment(
210
217
  "status",
211
- ts.factory.createNull(),
218
+ factory.createNull(),
212
219
  ),
213
220
  ],
214
221
  true,
@@ -218,22 +225,22 @@ export namespace NestiaMigrateApiFunctionProgrammer {
218
225
  ),
219
226
  );
220
227
 
221
- const value: ts.Expression =
228
+ const value: Expression =
222
229
  ctx.config.simulate !== true
223
230
  ? fetch()
224
- : ts.factory.createConditionalExpression(
225
- ts.factory.createStrictEquality(
226
- ts.factory.createTrue(),
227
- ts.factory.createIdentifier("connection.simulate"),
231
+ : factory.createConditionalExpression(
232
+ factory.createStrictEquality(
233
+ factory.createTrue(),
234
+ factory.createIdentifier("connection.simulate"),
228
235
  ),
229
236
  undefined,
230
- ts.factory.createCallExpression(
231
- ts.factory.createIdentifier(
237
+ factory.createCallExpression(
238
+ factory.createIdentifier(
232
239
  `${ctx.route.accessor.at(-1)!}.simulate`,
233
240
  ),
234
241
  [],
235
242
  [
236
- ts.factory.createIdentifier("connection"),
243
+ factory.createIdentifier("connection"),
237
244
  ...getArguments(ctx, true),
238
245
  ],
239
246
  ),
@@ -243,51 +250,51 @@ export namespace NestiaMigrateApiFunctionProgrammer {
243
250
  const headers: Array<IAssignHeader | ISetHeader> = getHeaders(
244
251
  ctx.route.comment(),
245
252
  );
246
- if (headers.length === 0) return [ts.factory.createReturnStatement(value)];
253
+ if (headers.length === 0) return [factory.createReturnStatement(value)];
247
254
  return [
248
255
  StatementFactory.constant({
249
256
  name: "output",
250
- type: ts.factory.createTypeReferenceNode(
257
+ type: factory.createTypeReferenceNode(
251
258
  `${ctx.route.accessor.at(-1)!}.Response`,
252
259
  ),
253
260
  value,
254
261
  }),
255
- ts.factory.createExpressionStatement(
256
- ts.factory.createBinaryExpression(
257
- ts.factory.createIdentifier("connection.headers"),
258
- ts.factory.createToken(ts.SyntaxKind.QuestionQuestionEqualsToken),
259
- ts.factory.createObjectLiteralExpression([]),
262
+ factory.createExpressionStatement(
263
+ factory.createBinaryExpression(
264
+ factory.createIdentifier("connection.headers"),
265
+ factory.createToken(SyntaxKind.QuestionQuestionEqualsToken),
266
+ factory.createObjectLiteralExpression([]),
260
267
  ),
261
268
  ),
262
269
  ...headers.map((h) =>
263
- ts.factory.createExpressionStatement(
270
+ factory.createExpressionStatement(
264
271
  h.type === "assign"
265
- ? ts.factory.createCallExpression(
266
- ts.factory.createIdentifier("Object.assign"),
272
+ ? factory.createCallExpression(
273
+ factory.createIdentifier("Object.assign"),
267
274
  undefined,
268
275
  [
269
- ts.factory.createIdentifier("connection.headers"),
270
- ts.factory.createIdentifier(`output.${h.accessor}`),
276
+ factory.createIdentifier("connection.headers"),
277
+ factory.createIdentifier(`output.${h.accessor}`),
271
278
  ],
272
279
  )
273
- : ts.factory.createBinaryExpression(
274
- ts.factory.createIdentifier(
280
+ : factory.createBinaryExpression(
281
+ factory.createIdentifier(
275
282
  `connection.headers${
276
283
  NamingConvention.variable(h.property)
277
284
  ? `.${h.property}`
278
285
  : `[${JSON.stringify(h.property)}]`
279
286
  }`,
280
287
  ),
281
- ts.factory.createToken(ts.SyntaxKind.EqualsToken),
282
- ts.factory.createIdentifier(`output.${h.accessor}`),
288
+ factory.createToken(SyntaxKind.EqualsToken),
289
+ factory.createIdentifier(`output.${h.accessor}`),
283
290
  ),
284
291
  ),
285
292
  ),
286
- ts.factory.createReturnStatement(ts.factory.createIdentifier("output")),
293
+ factory.createReturnStatement(factory.createIdentifier("output")),
287
294
  ];
288
295
  };
289
296
 
290
- const getArguments = (ctx: IContext, body: boolean): ts.Expression[] => {
297
+ const getArguments = (ctx: IContext, body: boolean): Expression[] => {
291
298
  if (
292
299
  ctx.route.parameters.length === 0 &&
293
300
  ctx.route.query === null &&
@@ -295,14 +302,14 @@ export namespace NestiaMigrateApiFunctionProgrammer {
295
302
  )
296
303
  return [];
297
304
  else if (ctx.config.keyword === true)
298
- return [ts.factory.createIdentifier("props")];
305
+ return [factory.createIdentifier("props")];
299
306
  return [
300
- ...ctx.route.parameters.map((p) => ts.factory.createIdentifier(p.key)),
307
+ ...ctx.route.parameters.map((p) => factory.createIdentifier(p.key)),
301
308
  ...(ctx.route.query
302
- ? [ts.factory.createIdentifier(ctx.route.query.key)]
309
+ ? [factory.createIdentifier(ctx.route.query.key)]
303
310
  : []),
304
311
  ...(body && ctx.route.body
305
- ? [ts.factory.createIdentifier(ctx.route.body.key)]
312
+ ? [factory.createIdentifier(ctx.route.body.key)]
306
313
  : []),
307
314
  ];
308
315
  };