@nestia/migrate 11.3.0 → 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.
- package/lib/bundles/NEST_TEMPLATE.js +2 -2
- package/lib/bundles/NEST_TEMPLATE.js.map +1 -1
- package/lib/bundles/SDK_TEMPLATE.js +1 -1
- package/lib/bundles/SDK_TEMPLATE.js.map +1 -1
- package/lib/factories/ExpressionFactory.d.ts +9 -0
- package/lib/factories/ExpressionFactory.js +16 -0
- package/lib/factories/ExpressionFactory.js.map +1 -0
- package/lib/factories/IdentifierFactory.d.ts +11 -0
- package/lib/factories/IdentifierFactory.js +36 -0
- package/lib/factories/IdentifierFactory.js.map +1 -0
- package/lib/factories/LiteralFactory.d.ts +9 -0
- package/lib/factories/LiteralFactory.js +52 -0
- package/lib/factories/LiteralFactory.js.map +1 -0
- package/lib/factories/StatementFactory.d.ts +12 -0
- package/lib/factories/StatementFactory.js +20 -0
- package/lib/factories/StatementFactory.js.map +1 -0
- package/lib/factories/TypeFactory.d.ts +8 -0
- package/lib/factories/TypeFactory.js +25 -0
- package/lib/factories/TypeFactory.js.map +1 -0
- package/lib/factories/TypeLiteralFactory.d.ts +2 -2
- package/lib/factories/TypeLiteralFactory.js +12 -15
- package/lib/factories/TypeLiteralFactory.js.map +1 -1
- package/lib/factories/index.d.ts +5 -0
- package/lib/factories/index.js +22 -0
- package/lib/factories/index.js.map +1 -0
- package/lib/index.mjs +171 -126
- package/lib/index.mjs.map +1 -1
- package/lib/programmers/NestiaMigrateApiFileProgrammer.d.ts +2 -2
- package/lib/programmers/NestiaMigrateApiFileProgrammer.js +2 -5
- package/lib/programmers/NestiaMigrateApiFileProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateApiFunctionProgrammer.d.ts +3 -3
- package/lib/programmers/NestiaMigrateApiFunctionProgrammer.js +45 -48
- package/lib/programmers/NestiaMigrateApiFunctionProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateApiNamespaceProgrammer.d.ts +3 -3
- package/lib/programmers/NestiaMigrateApiNamespaceProgrammer.js +59 -62
- package/lib/programmers/NestiaMigrateApiNamespaceProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateApiProgrammer.js +2 -5
- package/lib/programmers/NestiaMigrateApiProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateApiSimulationProgrammer.d.ts +3 -3
- package/lib/programmers/NestiaMigrateApiSimulationProgrammer.js +36 -39
- package/lib/programmers/NestiaMigrateApiSimulationProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateApiStartProgrammer.js +20 -23
- package/lib/programmers/NestiaMigrateApiStartProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateDtoProgrammer.d.ts +2 -2
- package/lib/programmers/NestiaMigrateDtoProgrammer.js +2 -5
- package/lib/programmers/NestiaMigrateDtoProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateE2eFileProgrammer.d.ts +3 -3
- package/lib/programmers/NestiaMigrateE2eFileProgrammer.js +23 -26
- package/lib/programmers/NestiaMigrateE2eFileProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateE2eProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateImportProgrammer.d.ts +4 -4
- package/lib/programmers/NestiaMigrateImportProgrammer.js +11 -14
- package/lib/programmers/NestiaMigrateImportProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateNestControllerProgrammer.d.ts +2 -2
- package/lib/programmers/NestiaMigrateNestControllerProgrammer.js +5 -8
- package/lib/programmers/NestiaMigrateNestControllerProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateNestMethodProgrammer.d.ts +2 -2
- package/lib/programmers/NestiaMigrateNestMethodProgrammer.js +32 -37
- package/lib/programmers/NestiaMigrateNestMethodProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateNestModuleProgrammer.d.ts +2 -2
- package/lib/programmers/NestiaMigrateNestModuleProgrammer.js +9 -12
- package/lib/programmers/NestiaMigrateNestModuleProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateNestProgrammer.js +2 -5
- package/lib/programmers/NestiaMigrateNestProgrammer.js.map +1 -1
- package/lib/programmers/NestiaMigrateSchemaProgrammer.d.ts +2 -2
- package/lib/programmers/NestiaMigrateSchemaProgrammer.js +44 -43
- package/lib/programmers/NestiaMigrateSchemaProgrammer.js.map +1 -1
- package/lib/structures/INestiaMigrateConfig.d.ts +2 -2
- package/lib/utils/FilePrinter.d.ts +4 -4
- package/lib/utils/FilePrinter.js +9 -11
- package/lib/utils/FilePrinter.js.map +1 -1
- package/package.json +8 -7
- package/src/bundles/NEST_TEMPLATE.ts +2 -2
- package/src/bundles/SDK_TEMPLATE.ts +1 -1
- package/src/factories/ExpressionFactory.ts +30 -0
- package/src/factories/IdentifierFactory.ts +69 -0
- package/src/factories/LiteralFactory.ts +61 -0
- package/src/factories/StatementFactory.ts +40 -0
- package/src/factories/TypeFactory.ts +33 -0
- package/src/factories/TypeLiteralFactory.ts +17 -17
- package/src/factories/index.ts +5 -0
- package/src/programmers/NestiaMigrateApiFileProgrammer.ts +6 -7
- package/src/programmers/NestiaMigrateApiFunctionProgrammer.ts +81 -74
- package/src/programmers/NestiaMigrateApiNamespaceProgrammer.ts +143 -142
- package/src/programmers/NestiaMigrateApiProgrammer.ts +11 -11
- package/src/programmers/NestiaMigrateApiSimulationProgrammer.ts +71 -66
- package/src/programmers/NestiaMigrateApiStartProgrammer.ts +58 -52
- package/src/programmers/NestiaMigrateDtoProgrammer.ts +5 -5
- package/src/programmers/NestiaMigrateE2eFileProgrammer.ts +41 -34
- package/src/programmers/NestiaMigrateE2eProgrammer.ts +8 -9
- package/src/programmers/NestiaMigrateImportProgrammer.ts +22 -22
- package/src/programmers/NestiaMigrateNestControllerProgrammer.ts +8 -8
- package/src/programmers/NestiaMigrateNestMethodProgrammer.ts +68 -68
- package/src/programmers/NestiaMigrateNestModuleProgrammer.ts +18 -20
- package/src/programmers/NestiaMigrateNestProgrammer.ts +14 -14
- package/src/programmers/NestiaMigrateSchemaProgrammer.ts +67 -59
- package/src/structures/INestiaMigrateConfig.ts +2 -2
- 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):
|
|
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
|
-
:
|
|
18
|
+
: factory.createKeywordTypeNode(SyntaxKind.AnyKeyword);
|
|
19
19
|
|
|
20
20
|
const generatestring = (str: string) =>
|
|
21
|
-
|
|
21
|
+
factory.createLiteralTypeNode(factory.createStringLiteral(str));
|
|
22
22
|
|
|
23
23
|
const generateNumber = (num: number) =>
|
|
24
|
-
|
|
24
|
+
factory.createLiteralTypeNode(
|
|
25
25
|
num < 0
|
|
26
|
-
?
|
|
27
|
-
|
|
28
|
-
|
|
26
|
+
? factory.createPrefixUnaryExpression(
|
|
27
|
+
SyntaxKind.MinusToken,
|
|
28
|
+
factory.createNumericLiteral(-num),
|
|
29
29
|
)
|
|
30
|
-
:
|
|
30
|
+
: factory.createNumericLiteral(num),
|
|
31
31
|
);
|
|
32
32
|
|
|
33
33
|
const generateBoolean = (bool: boolean) =>
|
|
34
|
-
|
|
35
|
-
bool ?
|
|
34
|
+
factory.createLiteralTypeNode(
|
|
35
|
+
bool ? factory.createTrue() : factory.createFalse(),
|
|
36
36
|
);
|
|
37
37
|
|
|
38
38
|
const generateNull = () =>
|
|
39
|
-
|
|
39
|
+
factory.createLiteralTypeNode(factory.createNull());
|
|
40
40
|
|
|
41
41
|
const generateTuple = (items: any[]) =>
|
|
42
|
-
|
|
42
|
+
factory.createTupleTypeNode(items.map(generate));
|
|
43
43
|
|
|
44
44
|
const generateObject = (obj: object) =>
|
|
45
|
-
|
|
45
|
+
factory.createTypeLiteralNode(
|
|
46
46
|
Object.entries(obj).map(([key, value]) =>
|
|
47
|
-
|
|
47
|
+
factory.createPropertySignature(
|
|
48
48
|
undefined,
|
|
49
49
|
NamingConvention.variable(key)
|
|
50
|
-
?
|
|
51
|
-
:
|
|
50
|
+
? factory.createIdentifier(key)
|
|
51
|
+
: factory.createStringLiteral(key),
|
|
52
52
|
undefined,
|
|
53
53
|
generate(value),
|
|
54
54
|
),
|
|
@@ -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):
|
|
19
|
+
export const write = (props: IProps): Statement[] => {
|
|
20
20
|
const importer: NestiaMigrateImportProgrammer =
|
|
21
21
|
new NestiaMigrateImportProgrammer();
|
|
22
|
-
const statements:
|
|
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
|
-
|
|
44
|
+
factory.createExportDeclaration(
|
|
45
45
|
undefined,
|
|
46
46
|
false,
|
|
47
|
-
|
|
48
|
-
|
|
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 {
|
|
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):
|
|
26
|
+
export const write = (ctx: IContext): FunctionDeclaration =>
|
|
20
27
|
FilePrinter.description(
|
|
21
|
-
|
|
28
|
+
factory.createFunctionDeclaration(
|
|
22
29
|
[
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
31
|
-
|
|
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
|
-
|
|
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
|
-
):
|
|
46
|
-
const connection:
|
|
52
|
+
): ParameterDeclaration[] => {
|
|
53
|
+
const connection: ParameterDeclaration = IdentifierFactory.parameter(
|
|
47
54
|
connectionName ?? "connection",
|
|
48
|
-
|
|
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
|
-
|
|
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
|
-
|
|
78
|
+
factory.createParameterDeclaration(
|
|
72
79
|
undefined,
|
|
73
80
|
undefined,
|
|
74
81
|
"props",
|
|
75
82
|
undefined,
|
|
76
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
?
|
|
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):
|
|
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):
|
|
148
|
+
const property = (key: string): Expression =>
|
|
142
149
|
ctx.config.keyword === true
|
|
143
|
-
? IdentifierFactory.access(
|
|
144
|
-
:
|
|
150
|
+
? IdentifierFactory.access(factory.createIdentifier("props"), key)
|
|
151
|
+
: factory.createIdentifier(key);
|
|
145
152
|
const fetch = () =>
|
|
146
|
-
|
|
147
|
-
|
|
153
|
+
factory.createAwaitExpression(
|
|
154
|
+
factory.createCallExpression(
|
|
148
155
|
IdentifierFactory.access(
|
|
149
|
-
|
|
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
|
-
?
|
|
170
|
+
? factory.createObjectLiteralExpression(
|
|
164
171
|
[
|
|
165
|
-
|
|
166
|
-
|
|
172
|
+
factory.createSpreadAssignment(
|
|
173
|
+
factory.createIdentifier("connection"),
|
|
167
174
|
),
|
|
168
|
-
|
|
175
|
+
factory.createPropertyAssignment(
|
|
169
176
|
"headers",
|
|
170
|
-
|
|
177
|
+
factory.createObjectLiteralExpression(
|
|
171
178
|
[
|
|
172
|
-
|
|
179
|
+
factory.createSpreadAssignment(
|
|
173
180
|
IdentifierFactory.access(
|
|
174
|
-
|
|
181
|
+
factory.createIdentifier("connection"),
|
|
175
182
|
"headers",
|
|
176
183
|
),
|
|
177
184
|
),
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
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
|
-
:
|
|
190
|
-
|
|
196
|
+
: factory.createIdentifier("connection"),
|
|
197
|
+
factory.createObjectLiteralExpression(
|
|
191
198
|
[
|
|
192
|
-
|
|
199
|
+
factory.createSpreadAssignment(
|
|
193
200
|
IdentifierFactory.access(
|
|
194
|
-
|
|
201
|
+
factory.createIdentifier(ctx.route.accessor.at(-1)!),
|
|
195
202
|
"METADATA",
|
|
196
203
|
),
|
|
197
204
|
),
|
|
198
|
-
|
|
205
|
+
factory.createPropertyAssignment(
|
|
199
206
|
"path",
|
|
200
|
-
|
|
207
|
+
factory.createCallExpression(
|
|
201
208
|
IdentifierFactory.access(
|
|
202
|
-
|
|
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
|
-
|
|
216
|
+
factory.createPropertyAssignment(
|
|
210
217
|
"status",
|
|
211
|
-
|
|
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:
|
|
228
|
+
const value: Expression =
|
|
222
229
|
ctx.config.simulate !== true
|
|
223
230
|
? fetch()
|
|
224
|
-
:
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
231
|
+
: factory.createConditionalExpression(
|
|
232
|
+
factory.createStrictEquality(
|
|
233
|
+
factory.createTrue(),
|
|
234
|
+
factory.createIdentifier("connection.simulate"),
|
|
228
235
|
),
|
|
229
236
|
undefined,
|
|
230
|
-
|
|
231
|
-
|
|
237
|
+
factory.createCallExpression(
|
|
238
|
+
factory.createIdentifier(
|
|
232
239
|
`${ctx.route.accessor.at(-1)!}.simulate`,
|
|
233
240
|
),
|
|
234
241
|
[],
|
|
235
242
|
[
|
|
236
|
-
|
|
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 [
|
|
253
|
+
if (headers.length === 0) return [factory.createReturnStatement(value)];
|
|
247
254
|
return [
|
|
248
255
|
StatementFactory.constant({
|
|
249
256
|
name: "output",
|
|
250
|
-
type:
|
|
257
|
+
type: factory.createTypeReferenceNode(
|
|
251
258
|
`${ctx.route.accessor.at(-1)!}.Response`,
|
|
252
259
|
),
|
|
253
260
|
value,
|
|
254
261
|
}),
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
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
|
-
|
|
270
|
+
factory.createExpressionStatement(
|
|
264
271
|
h.type === "assign"
|
|
265
|
-
?
|
|
266
|
-
|
|
272
|
+
? factory.createCallExpression(
|
|
273
|
+
factory.createIdentifier("Object.assign"),
|
|
267
274
|
undefined,
|
|
268
275
|
[
|
|
269
|
-
|
|
270
|
-
|
|
276
|
+
factory.createIdentifier("connection.headers"),
|
|
277
|
+
factory.createIdentifier(`output.${h.accessor}`),
|
|
271
278
|
],
|
|
272
279
|
)
|
|
273
|
-
:
|
|
274
|
-
|
|
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
|
-
|
|
282
|
-
|
|
288
|
+
factory.createToken(SyntaxKind.EqualsToken),
|
|
289
|
+
factory.createIdentifier(`output.${h.accessor}`),
|
|
283
290
|
),
|
|
284
291
|
),
|
|
285
292
|
),
|
|
286
|
-
|
|
293
|
+
factory.createReturnStatement(factory.createIdentifier("output")),
|
|
287
294
|
];
|
|
288
295
|
};
|
|
289
296
|
|
|
290
|
-
const getArguments = (ctx: IContext, body: boolean):
|
|
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 [
|
|
305
|
+
return [factory.createIdentifier("props")];
|
|
299
306
|
return [
|
|
300
|
-
...ctx.route.parameters.map((p) =>
|
|
307
|
+
...ctx.route.parameters.map((p) => factory.createIdentifier(p.key)),
|
|
301
308
|
...(ctx.route.query
|
|
302
|
-
? [
|
|
309
|
+
? [factory.createIdentifier(ctx.route.query.key)]
|
|
303
310
|
: []),
|
|
304
311
|
...(body && ctx.route.body
|
|
305
|
-
? [
|
|
312
|
+
? [factory.createIdentifier(ctx.route.body.key)]
|
|
306
313
|
: []),
|
|
307
314
|
];
|
|
308
315
|
};
|