typia 6.7.0 → 6.7.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/programmers/AssertProgrammer.d.ts +0 -1
- package/lib/programmers/AssertProgrammer.js.map +1 -1
- package/lib/programmers/CheckerProgrammer.d.ts +1 -1
- package/lib/programmers/FeatureProgrammer.d.ts +1 -1
- package/lib/programmers/IsProgrammer.d.ts +1 -1
- package/lib/programmers/RandomProgrammer.d.ts +10 -1
- package/lib/programmers/RandomProgrammer.js +62 -37
- package/lib/programmers/RandomProgrammer.js.map +1 -1
- package/lib/programmers/ValidateProgrammer.d.ts +1 -1
- package/lib/programmers/json/JsonIsParseProgrammer.d.ts +1 -1
- package/lib/programmers/json/JsonIsStringifyProgrammer.d.ts +1 -1
- package/lib/programmers/json/JsonStringifyProgrammer.d.ts +1 -1
- package/lib/programmers/json/JsonStringifyProgrammer.js +1 -3
- package/lib/programmers/json/JsonStringifyProgrammer.js.map +1 -1
- package/lib/programmers/json/JsonValidateParseProgrammer.d.ts +1 -1
- package/lib/programmers/json/JsonValidateStringifyProgrammer.d.ts +1 -1
- package/lib/programmers/misc/MiscCloneProgrammer.d.ts +1 -1
- package/lib/programmers/misc/MiscCloneProgrammer.js +33 -14
- package/lib/programmers/misc/MiscCloneProgrammer.js.map +1 -1
- package/lib/programmers/misc/MiscIsCloneProgrammer.d.ts +1 -1
- package/lib/programmers/misc/MiscIsPruneProgrammer.d.ts +1 -1
- package/lib/programmers/misc/MiscPruneProgrammer.d.ts +1 -1
- package/lib/programmers/misc/MiscValidateCloneProgrammer.d.ts +1 -1
- package/lib/programmers/misc/MiscValidatePruneProgrammer.d.ts +1 -1
- package/lib/programmers/notations/NotationGeneralProgrammer.d.ts +1 -1
- package/lib/programmers/notations/NotationGeneralProgrammer.js +30 -11
- package/lib/programmers/notations/NotationGeneralProgrammer.js.map +1 -1
- package/lib/programmers/notations/NotationValidateGeneralProgrammer.d.ts +1 -1
- package/package.json +1 -1
- package/src/programmers/AssertProgrammer.ts +397 -398
- package/src/programmers/CheckerProgrammer.ts +1138 -1138
- package/src/programmers/FeatureProgrammer.ts +549 -549
- package/src/programmers/IsProgrammer.ts +1 -1
- package/src/programmers/RandomProgrammer.ts +112 -77
- package/src/programmers/ValidateProgrammer.ts +382 -382
- package/src/programmers/functional/FunctionalAssertFunctionProgrammer.ts +141 -141
- package/src/programmers/functional/FunctionalAssertParametersProgrammer.ts +108 -108
- package/src/programmers/functional/FunctionalAssertReturnProgrammer.ts +98 -98
- package/src/programmers/functional/FunctionalIsFunctionProgrammer.ts +72 -72
- package/src/programmers/functional/FunctionalIsParametersProgrammer.ts +101 -101
- package/src/programmers/functional/FunctionalIsReturnProgrammer.ts +106 -106
- package/src/programmers/functional/FunctionalValidateFunctionProgrammer.ts +123 -123
- package/src/programmers/functional/FunctionalValidateParametersProgrammer.ts +267 -267
- package/src/programmers/functional/FunctionalValidateReturnProgrammer.ts +126 -126
- package/src/programmers/helpers/FunctionImporter.ts +97 -97
- package/src/programmers/http/HttpAssertFormDataProgrammer.ts +91 -91
- package/src/programmers/http/HttpAssertHeadersProgrammer.ts +91 -91
- package/src/programmers/http/HttpAssertQueryProgrammer.ts +93 -93
- package/src/programmers/http/HttpFormDataProgrammer.ts +278 -278
- package/src/programmers/http/HttpHeadersProgrammer.ts +347 -347
- package/src/programmers/http/HttpIsFormDataProgrammer.ts +102 -102
- package/src/programmers/http/HttpIsHeadersProgrammer.ts +102 -102
- package/src/programmers/http/HttpIsQueryProgrammer.ts +104 -104
- package/src/programmers/http/HttpQueryProgrammer.ts +298 -298
- package/src/programmers/http/HttpValidateFormDataProgrammer.ts +85 -85
- package/src/programmers/http/HttpValidateHeadersProgrammer.ts +85 -85
- package/src/programmers/http/HttpValidateQueryProgrammer.ts +87 -87
- package/src/programmers/json/JsonAssertParseProgrammer.ts +96 -96
- package/src/programmers/json/JsonAssertStringifyProgrammer.ts +104 -104
- package/src/programmers/json/JsonIsParseProgrammer.ts +110 -110
- package/src/programmers/json/JsonIsStringifyProgrammer.ts +102 -102
- package/src/programmers/json/JsonStringifyProgrammer.ts +909 -910
- package/src/programmers/json/JsonValidateParseProgrammer.ts +87 -87
- package/src/programmers/json/JsonValidateStringifyProgrammer.ts +111 -111
- package/src/programmers/misc/MiscAssertCloneProgrammer.ts +87 -87
- package/src/programmers/misc/MiscAssertPruneProgrammer.ts +87 -87
- package/src/programmers/misc/MiscCloneProgrammer.ts +781 -759
- package/src/programmers/misc/MiscIsCloneProgrammer.ts +93 -93
- package/src/programmers/misc/MiscIsPruneProgrammer.ts +94 -94
- package/src/programmers/misc/MiscPruneProgrammer.ts +560 -560
- package/src/programmers/misc/MiscValidateCloneProgrammer.ts +104 -104
- package/src/programmers/misc/MiscValidatePruneProgrammer.ts +98 -98
- package/src/programmers/notations/NotationAssertGeneralProgrammer.ts +91 -91
- package/src/programmers/notations/NotationGeneralProgrammer.ts +709 -685
- package/src/programmers/notations/NotationIsGeneralProgrammer.ts +97 -97
- package/src/programmers/notations/NotationValidateGeneralProgrammer.ts +107 -107
- package/src/programmers/protobuf/ProtobufAssertDecodeProgrammer.ts +91 -91
- package/src/programmers/protobuf/ProtobufAssertEncodeProgrammer.ts +95 -95
- package/src/programmers/protobuf/ProtobufDecodeProgrammer.ts +646 -646
- package/src/programmers/protobuf/ProtobufEncodeProgrammer.ts +852 -852
- package/src/programmers/protobuf/ProtobufIsDecodeProgrammer.ts +104 -104
- package/src/programmers/protobuf/ProtobufIsEncodeProgrammer.ts +93 -93
- package/src/programmers/protobuf/ProtobufValidateDecodeProgrammer.ts +85 -85
- package/src/programmers/protobuf/ProtobufValidateEncodeProgrammer.ts +109 -109
- package/src/transformers/internal/GenericTransformer.ts +104 -104
|
@@ -1,126 +1,126 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { ExpressionFactory } from "../../factories/ExpressionFactory";
|
|
4
|
-
import { StatementFactory } from "../../factories/StatementFactory";
|
|
5
|
-
|
|
6
|
-
import { IProject } from "../../transformers/IProject";
|
|
7
|
-
|
|
8
|
-
import { StringUtil } from "../../utils/StringUtil";
|
|
9
|
-
|
|
10
|
-
import { ValidateProgrammer } from "../ValidateProgrammer";
|
|
11
|
-
import { FunctionalValidateFunctionProgrammer } from "./FunctionalValidateFunctionProgrammer";
|
|
12
|
-
import { FunctionalGeneralProgrammer } from "./internal/FunctionalGeneralProgrammer";
|
|
13
|
-
|
|
14
|
-
export namespace FunctionalValidateReturnProgrammer {
|
|
15
|
-
export const write =
|
|
16
|
-
(project: IProject) =>
|
|
17
|
-
(modulo: ts.LeftHandSideExpression) =>
|
|
18
|
-
(equals: boolean) =>
|
|
19
|
-
(
|
|
20
|
-
expression: ts.Expression,
|
|
21
|
-
declaration: ts.FunctionDeclaration,
|
|
22
|
-
): ts.CallExpression => {
|
|
23
|
-
const result = decompose(project)(modulo)(equals)(
|
|
24
|
-
expression,
|
|
25
|
-
declaration,
|
|
26
|
-
);
|
|
27
|
-
return ExpressionFactory.selfCall(
|
|
28
|
-
ts.factory.createBlock(
|
|
29
|
-
[
|
|
30
|
-
...result.functions,
|
|
31
|
-
ts.factory.createReturnStatement(
|
|
32
|
-
ts.factory.createArrowFunction(
|
|
33
|
-
result.async
|
|
34
|
-
? [ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword)]
|
|
35
|
-
: undefined,
|
|
36
|
-
undefined,
|
|
37
|
-
declaration.parameters,
|
|
38
|
-
FunctionalValidateFunctionProgrammer.getReturnTypeNode(
|
|
39
|
-
declaration,
|
|
40
|
-
result.async,
|
|
41
|
-
),
|
|
42
|
-
undefined,
|
|
43
|
-
ts.factory.createBlock(result.statements, true),
|
|
44
|
-
),
|
|
45
|
-
),
|
|
46
|
-
],
|
|
47
|
-
true,
|
|
48
|
-
),
|
|
49
|
-
);
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
export const decompose =
|
|
53
|
-
(project: IProject) =>
|
|
54
|
-
(modulo: ts.LeftHandSideExpression) =>
|
|
55
|
-
(equals: boolean) =>
|
|
56
|
-
(
|
|
57
|
-
expression: ts.Expression,
|
|
58
|
-
declaration: ts.FunctionDeclaration,
|
|
59
|
-
): {
|
|
60
|
-
async: boolean;
|
|
61
|
-
functions: ts.Statement[];
|
|
62
|
-
statements: ts.Statement[];
|
|
63
|
-
} => {
|
|
64
|
-
const { type, async } = FunctionalGeneralProgrammer.getReturnType(
|
|
65
|
-
project.checker,
|
|
66
|
-
)(declaration);
|
|
67
|
-
const caller: ts.CallExpression = ts.factory.createCallExpression(
|
|
68
|
-
expression,
|
|
69
|
-
undefined,
|
|
70
|
-
declaration.parameters.map((p) =>
|
|
71
|
-
ts.factory.createIdentifier(p.name.getText()),
|
|
72
|
-
),
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
const name: string = StringUtil.escapeDuplicate(
|
|
76
|
-
declaration.parameters.map((p) => p.name.getText()),
|
|
77
|
-
)("result");
|
|
78
|
-
return {
|
|
79
|
-
async,
|
|
80
|
-
functions: [
|
|
81
|
-
StatementFactory.constant(
|
|
82
|
-
"__validate_return",
|
|
83
|
-
ValidateProgrammer.write(project)(modulo)(equals)(type),
|
|
84
|
-
),
|
|
85
|
-
],
|
|
86
|
-
statements: [
|
|
87
|
-
StatementFactory.constant(
|
|
88
|
-
name,
|
|
89
|
-
ts.factory.createCallExpression(
|
|
90
|
-
ts.factory.createIdentifier("__validate_return"),
|
|
91
|
-
undefined,
|
|
92
|
-
[async ? ts.factory.createAwaitExpression(caller) : caller],
|
|
93
|
-
),
|
|
94
|
-
),
|
|
95
|
-
ts.factory.createIfStatement(
|
|
96
|
-
ts.factory.createStrictEquality(
|
|
97
|
-
ts.factory.createFalse(),
|
|
98
|
-
ts.factory.createPropertyAccessExpression(
|
|
99
|
-
ts.factory.createIdentifier(name),
|
|
100
|
-
ts.factory.createIdentifier("success"),
|
|
101
|
-
),
|
|
102
|
-
),
|
|
103
|
-
ts.factory.createExpressionStatement(
|
|
104
|
-
ts.factory.createBinaryExpression(
|
|
105
|
-
ts.factory.createPropertyAccessExpression(
|
|
106
|
-
ts.factory.createIdentifier(name),
|
|
107
|
-
ts.factory.createIdentifier("errors"),
|
|
108
|
-
),
|
|
109
|
-
ts.factory.createToken(ts.SyntaxKind.EqualsToken),
|
|
110
|
-
FunctionalValidateFunctionProgrammer.hookErrors({
|
|
111
|
-
expression: ts.factory.createPropertyAccessExpression(
|
|
112
|
-
ts.factory.createIdentifier(name),
|
|
113
|
-
ts.factory.createIdentifier("errors"),
|
|
114
|
-
),
|
|
115
|
-
replacer: ts.factory.createStringLiteral("$input.return"),
|
|
116
|
-
}),
|
|
117
|
-
),
|
|
118
|
-
),
|
|
119
|
-
),
|
|
120
|
-
ts.factory.createReturnStatement(
|
|
121
|
-
ts.factory.createIdentifier("result"),
|
|
122
|
-
),
|
|
123
|
-
],
|
|
124
|
-
};
|
|
125
|
-
};
|
|
126
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { ExpressionFactory } from "../../factories/ExpressionFactory";
|
|
4
|
+
import { StatementFactory } from "../../factories/StatementFactory";
|
|
5
|
+
|
|
6
|
+
import { IProject } from "../../transformers/IProject";
|
|
7
|
+
|
|
8
|
+
import { StringUtil } from "../../utils/StringUtil";
|
|
9
|
+
|
|
10
|
+
import { ValidateProgrammer } from "../ValidateProgrammer";
|
|
11
|
+
import { FunctionalValidateFunctionProgrammer } from "./FunctionalValidateFunctionProgrammer";
|
|
12
|
+
import { FunctionalGeneralProgrammer } from "./internal/FunctionalGeneralProgrammer";
|
|
13
|
+
|
|
14
|
+
export namespace FunctionalValidateReturnProgrammer {
|
|
15
|
+
export const write =
|
|
16
|
+
(project: IProject) =>
|
|
17
|
+
(modulo: ts.LeftHandSideExpression) =>
|
|
18
|
+
(equals: boolean) =>
|
|
19
|
+
(
|
|
20
|
+
expression: ts.Expression,
|
|
21
|
+
declaration: ts.FunctionDeclaration,
|
|
22
|
+
): ts.CallExpression => {
|
|
23
|
+
const result = decompose(project)(modulo)(equals)(
|
|
24
|
+
expression,
|
|
25
|
+
declaration,
|
|
26
|
+
);
|
|
27
|
+
return ExpressionFactory.selfCall(
|
|
28
|
+
ts.factory.createBlock(
|
|
29
|
+
[
|
|
30
|
+
...result.functions,
|
|
31
|
+
ts.factory.createReturnStatement(
|
|
32
|
+
ts.factory.createArrowFunction(
|
|
33
|
+
result.async
|
|
34
|
+
? [ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword)]
|
|
35
|
+
: undefined,
|
|
36
|
+
undefined,
|
|
37
|
+
declaration.parameters,
|
|
38
|
+
FunctionalValidateFunctionProgrammer.getReturnTypeNode(
|
|
39
|
+
declaration,
|
|
40
|
+
result.async,
|
|
41
|
+
),
|
|
42
|
+
undefined,
|
|
43
|
+
ts.factory.createBlock(result.statements, true),
|
|
44
|
+
),
|
|
45
|
+
),
|
|
46
|
+
],
|
|
47
|
+
true,
|
|
48
|
+
),
|
|
49
|
+
);
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
export const decompose =
|
|
53
|
+
(project: IProject) =>
|
|
54
|
+
(modulo: ts.LeftHandSideExpression) =>
|
|
55
|
+
(equals: boolean) =>
|
|
56
|
+
(
|
|
57
|
+
expression: ts.Expression,
|
|
58
|
+
declaration: ts.FunctionDeclaration,
|
|
59
|
+
): {
|
|
60
|
+
async: boolean;
|
|
61
|
+
functions: ts.Statement[];
|
|
62
|
+
statements: ts.Statement[];
|
|
63
|
+
} => {
|
|
64
|
+
const { type, async } = FunctionalGeneralProgrammer.getReturnType(
|
|
65
|
+
project.checker,
|
|
66
|
+
)(declaration);
|
|
67
|
+
const caller: ts.CallExpression = ts.factory.createCallExpression(
|
|
68
|
+
expression,
|
|
69
|
+
undefined,
|
|
70
|
+
declaration.parameters.map((p) =>
|
|
71
|
+
ts.factory.createIdentifier(p.name.getText()),
|
|
72
|
+
),
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
const name: string = StringUtil.escapeDuplicate(
|
|
76
|
+
declaration.parameters.map((p) => p.name.getText()),
|
|
77
|
+
)("result");
|
|
78
|
+
return {
|
|
79
|
+
async,
|
|
80
|
+
functions: [
|
|
81
|
+
StatementFactory.constant(
|
|
82
|
+
"__validate_return",
|
|
83
|
+
ValidateProgrammer.write(project)(modulo)(equals)(type),
|
|
84
|
+
),
|
|
85
|
+
],
|
|
86
|
+
statements: [
|
|
87
|
+
StatementFactory.constant(
|
|
88
|
+
name,
|
|
89
|
+
ts.factory.createCallExpression(
|
|
90
|
+
ts.factory.createIdentifier("__validate_return"),
|
|
91
|
+
undefined,
|
|
92
|
+
[async ? ts.factory.createAwaitExpression(caller) : caller],
|
|
93
|
+
),
|
|
94
|
+
),
|
|
95
|
+
ts.factory.createIfStatement(
|
|
96
|
+
ts.factory.createStrictEquality(
|
|
97
|
+
ts.factory.createFalse(),
|
|
98
|
+
ts.factory.createPropertyAccessExpression(
|
|
99
|
+
ts.factory.createIdentifier(name),
|
|
100
|
+
ts.factory.createIdentifier("success"),
|
|
101
|
+
),
|
|
102
|
+
),
|
|
103
|
+
ts.factory.createExpressionStatement(
|
|
104
|
+
ts.factory.createBinaryExpression(
|
|
105
|
+
ts.factory.createPropertyAccessExpression(
|
|
106
|
+
ts.factory.createIdentifier(name),
|
|
107
|
+
ts.factory.createIdentifier("errors"),
|
|
108
|
+
),
|
|
109
|
+
ts.factory.createToken(ts.SyntaxKind.EqualsToken),
|
|
110
|
+
FunctionalValidateFunctionProgrammer.hookErrors({
|
|
111
|
+
expression: ts.factory.createPropertyAccessExpression(
|
|
112
|
+
ts.factory.createIdentifier(name),
|
|
113
|
+
ts.factory.createIdentifier("errors"),
|
|
114
|
+
),
|
|
115
|
+
replacer: ts.factory.createStringLiteral("$input.return"),
|
|
116
|
+
}),
|
|
117
|
+
),
|
|
118
|
+
),
|
|
119
|
+
),
|
|
120
|
+
ts.factory.createReturnStatement(
|
|
121
|
+
ts.factory.createIdentifier("result"),
|
|
122
|
+
),
|
|
123
|
+
],
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
}
|
|
@@ -1,97 +1,97 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
|
-
import { StatementFactory } from "../../factories/StatementFactory";
|
|
5
|
-
import { TypeFactory } from "../../factories/TypeFactory";
|
|
6
|
-
|
|
7
|
-
export class FunctionImporter {
|
|
8
|
-
private readonly used_: Set<string> = new Set();
|
|
9
|
-
private readonly local_: Set<string> = new Set();
|
|
10
|
-
private readonly unions_: Map<string, [string, ts.ArrowFunction]> = new Map();
|
|
11
|
-
private readonly variables_: Map<string, ts.Expression> = new Map();
|
|
12
|
-
private sequence_: number = 0;
|
|
13
|
-
|
|
14
|
-
public constructor(public readonly method: string) {}
|
|
15
|
-
|
|
16
|
-
public empty(): boolean {
|
|
17
|
-
return this.used_.size === 0;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
public use(name: string): ts.Identifier {
|
|
21
|
-
this.used_.add(name);
|
|
22
|
-
return ts.factory.createIdentifier("$" + name);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
public useLocal(name: string): string {
|
|
26
|
-
this.local_.add(name);
|
|
27
|
-
return name;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
public hasLocal(name: string): boolean {
|
|
31
|
-
return this.local_.has(name);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
public declare(
|
|
35
|
-
modulo: ts.LeftHandSideExpression,
|
|
36
|
-
includeUnions: boolean = true,
|
|
37
|
-
): ts.Statement[] {
|
|
38
|
-
return [
|
|
39
|
-
...[...this.used_].map((name) =>
|
|
40
|
-
StatementFactory.constant(
|
|
41
|
-
"$" + name,
|
|
42
|
-
IdentifierFactory.access(
|
|
43
|
-
ts.factory.createParenthesizedExpression(
|
|
44
|
-
ts.factory.createAsExpression(modulo, TypeFactory.keyword("any")),
|
|
45
|
-
),
|
|
46
|
-
)(name),
|
|
47
|
-
),
|
|
48
|
-
),
|
|
49
|
-
...[...this.variables_.entries()].map(([key, value]) =>
|
|
50
|
-
StatementFactory.constant(key, value),
|
|
51
|
-
),
|
|
52
|
-
...(includeUnions === true
|
|
53
|
-
? [...this.unions_.values()].map(([key, arrow]) =>
|
|
54
|
-
StatementFactory.constant(key, arrow),
|
|
55
|
-
)
|
|
56
|
-
: []),
|
|
57
|
-
];
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
public declareUnions(): ts.Statement[] {
|
|
61
|
-
return [...this.unions_.values()].map(([key, arrow]) =>
|
|
62
|
-
StatementFactory.constant(key, arrow),
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
public increment(): number {
|
|
67
|
-
return ++this.sequence_;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
public emplaceUnion(
|
|
71
|
-
prefix: string,
|
|
72
|
-
name: string,
|
|
73
|
-
factory: () => ts.ArrowFunction,
|
|
74
|
-
): string {
|
|
75
|
-
const key: string = `${prefix}::${name}`;
|
|
76
|
-
const oldbie = this.unions_.get(key);
|
|
77
|
-
if (oldbie) return oldbie[0];
|
|
78
|
-
|
|
79
|
-
const index: number = this.unions_.size;
|
|
80
|
-
const accessor: string = `${prefix}p${index}`;
|
|
81
|
-
|
|
82
|
-
const tuple: [string, ReturnType<typeof factory>] = [accessor, null!];
|
|
83
|
-
this.unions_.set(key, tuple);
|
|
84
|
-
tuple[1] = factory();
|
|
85
|
-
return accessor;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
public emplaceVariable(name: string, value: ts.Expression): ts.Expression {
|
|
89
|
-
this.variables_.set(name, value);
|
|
90
|
-
return ts.factory.createIdentifier(name);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
public trace(): void {
|
|
94
|
-
console.log(...this.used_);
|
|
95
|
-
console.log(...this.local_);
|
|
96
|
-
}
|
|
97
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
|
+
import { StatementFactory } from "../../factories/StatementFactory";
|
|
5
|
+
import { TypeFactory } from "../../factories/TypeFactory";
|
|
6
|
+
|
|
7
|
+
export class FunctionImporter {
|
|
8
|
+
private readonly used_: Set<string> = new Set();
|
|
9
|
+
private readonly local_: Set<string> = new Set();
|
|
10
|
+
private readonly unions_: Map<string, [string, ts.ArrowFunction]> = new Map();
|
|
11
|
+
private readonly variables_: Map<string, ts.Expression> = new Map();
|
|
12
|
+
private sequence_: number = 0;
|
|
13
|
+
|
|
14
|
+
public constructor(public readonly method: string) {}
|
|
15
|
+
|
|
16
|
+
public empty(): boolean {
|
|
17
|
+
return this.used_.size === 0;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
public use(name: string): ts.Identifier {
|
|
21
|
+
this.used_.add(name);
|
|
22
|
+
return ts.factory.createIdentifier("$" + name);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public useLocal(name: string): string {
|
|
26
|
+
this.local_.add(name);
|
|
27
|
+
return name;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
public hasLocal(name: string): boolean {
|
|
31
|
+
return this.local_.has(name);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public declare(
|
|
35
|
+
modulo: ts.LeftHandSideExpression,
|
|
36
|
+
includeUnions: boolean = true,
|
|
37
|
+
): ts.Statement[] {
|
|
38
|
+
return [
|
|
39
|
+
...[...this.used_].map((name) =>
|
|
40
|
+
StatementFactory.constant(
|
|
41
|
+
"$" + name,
|
|
42
|
+
IdentifierFactory.access(
|
|
43
|
+
ts.factory.createParenthesizedExpression(
|
|
44
|
+
ts.factory.createAsExpression(modulo, TypeFactory.keyword("any")),
|
|
45
|
+
),
|
|
46
|
+
)(name),
|
|
47
|
+
),
|
|
48
|
+
),
|
|
49
|
+
...[...this.variables_.entries()].map(([key, value]) =>
|
|
50
|
+
StatementFactory.constant(key, value),
|
|
51
|
+
),
|
|
52
|
+
...(includeUnions === true
|
|
53
|
+
? [...this.unions_.values()].map(([key, arrow]) =>
|
|
54
|
+
StatementFactory.constant(key, arrow),
|
|
55
|
+
)
|
|
56
|
+
: []),
|
|
57
|
+
];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public declareUnions(): ts.Statement[] {
|
|
61
|
+
return [...this.unions_.values()].map(([key, arrow]) =>
|
|
62
|
+
StatementFactory.constant(key, arrow),
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
public increment(): number {
|
|
67
|
+
return ++this.sequence_;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
public emplaceUnion(
|
|
71
|
+
prefix: string,
|
|
72
|
+
name: string,
|
|
73
|
+
factory: () => ts.ArrowFunction,
|
|
74
|
+
): string {
|
|
75
|
+
const key: string = `${prefix}::${name}`;
|
|
76
|
+
const oldbie = this.unions_.get(key);
|
|
77
|
+
if (oldbie) return oldbie[0];
|
|
78
|
+
|
|
79
|
+
const index: number = this.unions_.size;
|
|
80
|
+
const accessor: string = `${prefix}p${index}`;
|
|
81
|
+
|
|
82
|
+
const tuple: [string, ReturnType<typeof factory>] = [accessor, null!];
|
|
83
|
+
this.unions_.set(key, tuple);
|
|
84
|
+
tuple[1] = factory();
|
|
85
|
+
return accessor;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
public emplaceVariable(name: string, value: ts.Expression): ts.Expression {
|
|
89
|
+
this.variables_.set(name, value);
|
|
90
|
+
return ts.factory.createIdentifier(name);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
public trace(): void {
|
|
94
|
+
console.log(...this.used_);
|
|
95
|
+
console.log(...this.local_);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -1,91 +1,91 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
|
-
import { StatementFactory } from "../../factories/StatementFactory";
|
|
5
|
-
import { TypeFactory } from "../../factories/TypeFactory";
|
|
6
|
-
|
|
7
|
-
import { IProject } from "../../transformers/IProject";
|
|
8
|
-
|
|
9
|
-
import { AssertProgrammer } from "../AssertProgrammer";
|
|
10
|
-
import { FeatureProgrammer } from "../FeatureProgrammer";
|
|
11
|
-
import { FunctionImporter } from "../helpers/FunctionImporter";
|
|
12
|
-
import { HttpFormDataProgrammer } from "./HttpFormDataProgrammer";
|
|
13
|
-
|
|
14
|
-
export namespace HttpAssertFormDataProgrammer {
|
|
15
|
-
export const decompose = (props: {
|
|
16
|
-
project: IProject;
|
|
17
|
-
importer: FunctionImporter;
|
|
18
|
-
type: ts.Type;
|
|
19
|
-
name: string | undefined;
|
|
20
|
-
init: ts.Expression | undefined;
|
|
21
|
-
}): FeatureProgrammer.IDecomposed => {
|
|
22
|
-
const assert: FeatureProgrammer.IDecomposed = AssertProgrammer.decompose({
|
|
23
|
-
...props,
|
|
24
|
-
project: {
|
|
25
|
-
...props.project,
|
|
26
|
-
options: {
|
|
27
|
-
...props.project.options,
|
|
28
|
-
functional: false,
|
|
29
|
-
numeric: true,
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
equals: false,
|
|
33
|
-
guard: false,
|
|
34
|
-
});
|
|
35
|
-
const decode: FeatureProgrammer.IDecomposed =
|
|
36
|
-
HttpFormDataProgrammer.decompose(props);
|
|
37
|
-
return {
|
|
38
|
-
functions: {
|
|
39
|
-
...assert.functions,
|
|
40
|
-
...decode.functions,
|
|
41
|
-
},
|
|
42
|
-
statements: [
|
|
43
|
-
...assert.statements,
|
|
44
|
-
...decode.statements,
|
|
45
|
-
StatementFactory.constant("__assert", assert.arrow),
|
|
46
|
-
StatementFactory.constant("__decode", decode.arrow),
|
|
47
|
-
],
|
|
48
|
-
arrow: ts.factory.createArrowFunction(
|
|
49
|
-
undefined,
|
|
50
|
-
undefined,
|
|
51
|
-
[
|
|
52
|
-
IdentifierFactory.parameter("input", TypeFactory.keyword("any")),
|
|
53
|
-
AssertProgrammer.Guardian.parameter(props.init),
|
|
54
|
-
],
|
|
55
|
-
decode.arrow.type,
|
|
56
|
-
undefined,
|
|
57
|
-
ts.factory.createCallExpression(
|
|
58
|
-
ts.factory.createIdentifier("__assert"),
|
|
59
|
-
undefined,
|
|
60
|
-
[
|
|
61
|
-
ts.factory.createCallExpression(
|
|
62
|
-
ts.factory.createIdentifier("__decode"),
|
|
63
|
-
undefined,
|
|
64
|
-
[ts.factory.createIdentifier("input")],
|
|
65
|
-
),
|
|
66
|
-
AssertProgrammer.Guardian.identifier(),
|
|
67
|
-
],
|
|
68
|
-
),
|
|
69
|
-
),
|
|
70
|
-
};
|
|
71
|
-
};
|
|
72
|
-
|
|
73
|
-
export const write =
|
|
74
|
-
(project: IProject) =>
|
|
75
|
-
(modulo: ts.LeftHandSideExpression) =>
|
|
76
|
-
(type: ts.Type, name?: string, init?: ts.Expression): ts.CallExpression => {
|
|
77
|
-
const importer: FunctionImporter = new FunctionImporter(modulo.getText());
|
|
78
|
-
const result: FeatureProgrammer.IDecomposed = decompose({
|
|
79
|
-
project,
|
|
80
|
-
importer,
|
|
81
|
-
type,
|
|
82
|
-
name,
|
|
83
|
-
init,
|
|
84
|
-
});
|
|
85
|
-
return FeatureProgrammer.writeDecomposed({
|
|
86
|
-
modulo,
|
|
87
|
-
importer,
|
|
88
|
-
result,
|
|
89
|
-
});
|
|
90
|
-
};
|
|
91
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
|
+
import { StatementFactory } from "../../factories/StatementFactory";
|
|
5
|
+
import { TypeFactory } from "../../factories/TypeFactory";
|
|
6
|
+
|
|
7
|
+
import { IProject } from "../../transformers/IProject";
|
|
8
|
+
|
|
9
|
+
import { AssertProgrammer } from "../AssertProgrammer";
|
|
10
|
+
import { FeatureProgrammer } from "../FeatureProgrammer";
|
|
11
|
+
import { FunctionImporter } from "../helpers/FunctionImporter";
|
|
12
|
+
import { HttpFormDataProgrammer } from "./HttpFormDataProgrammer";
|
|
13
|
+
|
|
14
|
+
export namespace HttpAssertFormDataProgrammer {
|
|
15
|
+
export const decompose = (props: {
|
|
16
|
+
project: IProject;
|
|
17
|
+
importer: FunctionImporter;
|
|
18
|
+
type: ts.Type;
|
|
19
|
+
name: string | undefined;
|
|
20
|
+
init: ts.Expression | undefined;
|
|
21
|
+
}): FeatureProgrammer.IDecomposed => {
|
|
22
|
+
const assert: FeatureProgrammer.IDecomposed = AssertProgrammer.decompose({
|
|
23
|
+
...props,
|
|
24
|
+
project: {
|
|
25
|
+
...props.project,
|
|
26
|
+
options: {
|
|
27
|
+
...props.project.options,
|
|
28
|
+
functional: false,
|
|
29
|
+
numeric: true,
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
equals: false,
|
|
33
|
+
guard: false,
|
|
34
|
+
});
|
|
35
|
+
const decode: FeatureProgrammer.IDecomposed =
|
|
36
|
+
HttpFormDataProgrammer.decompose(props);
|
|
37
|
+
return {
|
|
38
|
+
functions: {
|
|
39
|
+
...assert.functions,
|
|
40
|
+
...decode.functions,
|
|
41
|
+
},
|
|
42
|
+
statements: [
|
|
43
|
+
...assert.statements,
|
|
44
|
+
...decode.statements,
|
|
45
|
+
StatementFactory.constant("__assert", assert.arrow),
|
|
46
|
+
StatementFactory.constant("__decode", decode.arrow),
|
|
47
|
+
],
|
|
48
|
+
arrow: ts.factory.createArrowFunction(
|
|
49
|
+
undefined,
|
|
50
|
+
undefined,
|
|
51
|
+
[
|
|
52
|
+
IdentifierFactory.parameter("input", TypeFactory.keyword("any")),
|
|
53
|
+
AssertProgrammer.Guardian.parameter(props.init),
|
|
54
|
+
],
|
|
55
|
+
decode.arrow.type,
|
|
56
|
+
undefined,
|
|
57
|
+
ts.factory.createCallExpression(
|
|
58
|
+
ts.factory.createIdentifier("__assert"),
|
|
59
|
+
undefined,
|
|
60
|
+
[
|
|
61
|
+
ts.factory.createCallExpression(
|
|
62
|
+
ts.factory.createIdentifier("__decode"),
|
|
63
|
+
undefined,
|
|
64
|
+
[ts.factory.createIdentifier("input")],
|
|
65
|
+
),
|
|
66
|
+
AssertProgrammer.Guardian.identifier(),
|
|
67
|
+
],
|
|
68
|
+
),
|
|
69
|
+
),
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
export const write =
|
|
74
|
+
(project: IProject) =>
|
|
75
|
+
(modulo: ts.LeftHandSideExpression) =>
|
|
76
|
+
(type: ts.Type, name?: string, init?: ts.Expression): ts.CallExpression => {
|
|
77
|
+
const importer: FunctionImporter = new FunctionImporter(modulo.getText());
|
|
78
|
+
const result: FeatureProgrammer.IDecomposed = decompose({
|
|
79
|
+
project,
|
|
80
|
+
importer,
|
|
81
|
+
type,
|
|
82
|
+
name,
|
|
83
|
+
init,
|
|
84
|
+
});
|
|
85
|
+
return FeatureProgrammer.writeDecomposed({
|
|
86
|
+
modulo,
|
|
87
|
+
importer,
|
|
88
|
+
result,
|
|
89
|
+
});
|
|
90
|
+
};
|
|
91
|
+
}
|