typia 5.1.3 → 5.1.4-dev.20230929
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/executable/TypiaSetupWizard.js +1 -19
- package/lib/executable/TypiaSetupWizard.js.map +1 -1
- package/package.json +1 -1
- package/src/executable/TypiaSetupWizard.ts +1 -16
- package/src/factories/MetadataCollection.ts +277 -277
- package/src/factories/MetadataFactory.ts +238 -238
- package/src/factories/MetadataTypeTagFactory.ts +325 -325
- package/src/factories/internal/metadata/emend_metadata_atomics.ts +41 -41
- package/src/factories/internal/metadata/iterate_metadata_intersection.ts +259 -259
- package/src/functional/$HeadersReader.ts +28 -28
- package/src/functional/$ParameterReader.ts +31 -31
- package/src/functional/$QueryReader.ts +56 -56
- package/src/functional/Namespace.ts +142 -142
- package/src/http.ts +1149 -1149
- package/src/json.ts +648 -648
- package/src/misc.ts +651 -651
- package/src/module.ts +657 -657
- package/src/programmers/helpers/HttpMetadataUtil.ts +21 -21
- package/src/programmers/http/HttpAssertHeadersProgrammer.ts +77 -77
- package/src/programmers/http/HttpAssertQueryProgrammer.ts +77 -77
- package/src/programmers/http/HttpHeadersProgrammer.ts +339 -339
- package/src/programmers/http/HttpIsHeadersProgrammer.ts +87 -87
- package/src/programmers/http/HttpIsQueryProgrammer.ts +87 -87
- package/src/programmers/http/HttpParameterProgrammer.ts +104 -104
- package/src/programmers/http/HttpQueryProgrammer.ts +273 -273
- package/src/programmers/http/HttpValidateHeadersProgrammer.ts +77 -77
- package/src/programmers/http/HttpValidateQueryProgrammer.ts +77 -77
- package/src/programmers/internal/application_boolean.ts +30 -30
- package/src/programmers/internal/application_number.ts +90 -90
- package/src/programmers/internal/application_schema.ts +180 -180
- package/src/programmers/internal/application_string.ts +54 -54
- package/src/programmers/internal/check_array_length.ts +44 -44
- package/src/programmers/internal/check_bigint.ts +48 -48
- package/src/programmers/internal/check_number.ts +108 -108
- package/src/programmers/internal/check_string.ts +48 -48
- package/src/programmers/protobuf/ProtobufEncodeProgrammer.ts +882 -882
- package/src/protobuf.ts +887 -887
- package/src/schemas/json/IJsonComponents.ts +34 -34
- package/src/schemas/json/IJsonSchema.ts +112 -112
- package/src/schemas/metadata/IMetadataConstant.ts +25 -25
- package/src/schemas/metadata/IMetadataTypeTag.ts +8 -8
- package/src/schemas/metadata/Metadata.ts +686 -686
- package/src/tags/Default.ts +15 -15
- package/src/tags/Format.ts +30 -30
- package/src/tags/Pattern.ts +9 -9
- package/src/tags/TagBase.ts +68 -68
- package/src/tags/index.ts +14 -14
- package/src/transformers/CallExpressionTransformer.ts +289 -289
- package/src/transformers/features/http/CreateHttpAssertHeadersTransformer.ts +12 -12
- package/src/transformers/features/http/CreateHttpAssertQueryTransformer.ts +12 -12
- package/src/transformers/features/http/CreateHttpHeadersTransformer.ts +9 -9
- package/src/transformers/features/http/CreateHttpIsHeadersTransformer.ts +9 -9
- package/src/transformers/features/http/CreateHttpIsQueryTransformer.ts +9 -9
- package/src/transformers/features/http/CreateHttpParameterTransformer.ts +9 -9
- package/src/transformers/features/http/CreateHttpQueryTransformer.ts +9 -9
- package/src/transformers/features/http/CreateHttpValidateHeadersTransformer.ts +12 -12
- package/src/transformers/features/http/CreateHttpValidateQueryTransformer.ts +12 -12
- package/src/transformers/features/http/HttpAssertHeadersTransformer.ts +10 -10
- package/src/transformers/features/http/HttpAssertQueryTransformer.ts +10 -10
- package/src/transformers/features/http/HttpHeadersTransformer.ts +9 -9
- package/src/transformers/features/http/HttpIsHeadersTransformer.ts +9 -9
- package/src/transformers/features/http/HttpIsQueryTransformer.ts +9 -9
- package/src/transformers/features/http/HttpParameterTransformer.ts +9 -9
- package/src/transformers/features/http/HttpQueryTransformer.ts +9 -9
- package/src/transformers/features/http/HttpValidateHeadersTransformer.ts +10 -10
- package/src/transformers/features/http/HttpValidateQueryTransformer.ts +10 -10
|
@@ -1,87 +1,87 @@
|
|
|
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 { IsProgrammer } from "../IsProgrammer";
|
|
10
|
-
import { HttpHeadersProgrammer } from "./HttpHeadersProgrammer";
|
|
11
|
-
|
|
12
|
-
export namespace HttpIsHeadersProgrammer {
|
|
13
|
-
export const write =
|
|
14
|
-
(project: IProject) =>
|
|
15
|
-
(modulo: ts.LeftHandSideExpression) =>
|
|
16
|
-
(type: ts.Type, name?: string): ts.ArrowFunction =>
|
|
17
|
-
ts.factory.createArrowFunction(
|
|
18
|
-
undefined,
|
|
19
|
-
undefined,
|
|
20
|
-
[
|
|
21
|
-
IdentifierFactory.parameter(
|
|
22
|
-
"input",
|
|
23
|
-
ts.factory.createTypeReferenceNode(
|
|
24
|
-
HttpHeadersProgrammer.INPUT_TYPE,
|
|
25
|
-
),
|
|
26
|
-
),
|
|
27
|
-
],
|
|
28
|
-
ts.factory.createUnionTypeNode([
|
|
29
|
-
ts.factory.createTypeReferenceNode(
|
|
30
|
-
`typia.Resolved<${
|
|
31
|
-
name ??
|
|
32
|
-
TypeFactory.getFullName(project.checker)(type)
|
|
33
|
-
}>`,
|
|
34
|
-
),
|
|
35
|
-
ts.factory.createLiteralTypeNode(ts.factory.createNull()),
|
|
36
|
-
]),
|
|
37
|
-
undefined,
|
|
38
|
-
ts.factory.createBlock([
|
|
39
|
-
StatementFactory.constant(
|
|
40
|
-
"is",
|
|
41
|
-
IsProgrammer.write({
|
|
42
|
-
...project,
|
|
43
|
-
options: {
|
|
44
|
-
...project.options,
|
|
45
|
-
functional: false,
|
|
46
|
-
numeric: false,
|
|
47
|
-
},
|
|
48
|
-
})(modulo)(false)(type, name),
|
|
49
|
-
),
|
|
50
|
-
StatementFactory.constant(
|
|
51
|
-
"headers",
|
|
52
|
-
HttpHeadersProgrammer.write({
|
|
53
|
-
...project,
|
|
54
|
-
options: {
|
|
55
|
-
...project.options,
|
|
56
|
-
functional: false,
|
|
57
|
-
numeric: false,
|
|
58
|
-
},
|
|
59
|
-
})(modulo)(type, name),
|
|
60
|
-
),
|
|
61
|
-
StatementFactory.constant(
|
|
62
|
-
"output",
|
|
63
|
-
ts.factory.createCallExpression(
|
|
64
|
-
ts.factory.createIdentifier("headers"),
|
|
65
|
-
undefined,
|
|
66
|
-
[ts.factory.createIdentifier("input")],
|
|
67
|
-
),
|
|
68
|
-
),
|
|
69
|
-
ts.factory.createIfStatement(
|
|
70
|
-
ts.factory.createPrefixUnaryExpression(
|
|
71
|
-
ts.SyntaxKind.ExclamationToken,
|
|
72
|
-
ts.factory.createCallExpression(
|
|
73
|
-
ts.factory.createIdentifier("is"),
|
|
74
|
-
undefined,
|
|
75
|
-
[ts.factory.createIdentifier("output")],
|
|
76
|
-
),
|
|
77
|
-
),
|
|
78
|
-
ts.factory.createReturnStatement(
|
|
79
|
-
ts.factory.createNull(),
|
|
80
|
-
),
|
|
81
|
-
),
|
|
82
|
-
ts.factory.createReturnStatement(
|
|
83
|
-
ts.factory.createIdentifier("output"),
|
|
84
|
-
),
|
|
85
|
-
]),
|
|
86
|
-
);
|
|
87
|
-
}
|
|
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 { IsProgrammer } from "../IsProgrammer";
|
|
10
|
+
import { HttpHeadersProgrammer } from "./HttpHeadersProgrammer";
|
|
11
|
+
|
|
12
|
+
export namespace HttpIsHeadersProgrammer {
|
|
13
|
+
export const write =
|
|
14
|
+
(project: IProject) =>
|
|
15
|
+
(modulo: ts.LeftHandSideExpression) =>
|
|
16
|
+
(type: ts.Type, name?: string): ts.ArrowFunction =>
|
|
17
|
+
ts.factory.createArrowFunction(
|
|
18
|
+
undefined,
|
|
19
|
+
undefined,
|
|
20
|
+
[
|
|
21
|
+
IdentifierFactory.parameter(
|
|
22
|
+
"input",
|
|
23
|
+
ts.factory.createTypeReferenceNode(
|
|
24
|
+
HttpHeadersProgrammer.INPUT_TYPE,
|
|
25
|
+
),
|
|
26
|
+
),
|
|
27
|
+
],
|
|
28
|
+
ts.factory.createUnionTypeNode([
|
|
29
|
+
ts.factory.createTypeReferenceNode(
|
|
30
|
+
`typia.Resolved<${
|
|
31
|
+
name ??
|
|
32
|
+
TypeFactory.getFullName(project.checker)(type)
|
|
33
|
+
}>`,
|
|
34
|
+
),
|
|
35
|
+
ts.factory.createLiteralTypeNode(ts.factory.createNull()),
|
|
36
|
+
]),
|
|
37
|
+
undefined,
|
|
38
|
+
ts.factory.createBlock([
|
|
39
|
+
StatementFactory.constant(
|
|
40
|
+
"is",
|
|
41
|
+
IsProgrammer.write({
|
|
42
|
+
...project,
|
|
43
|
+
options: {
|
|
44
|
+
...project.options,
|
|
45
|
+
functional: false,
|
|
46
|
+
numeric: false,
|
|
47
|
+
},
|
|
48
|
+
})(modulo)(false)(type, name),
|
|
49
|
+
),
|
|
50
|
+
StatementFactory.constant(
|
|
51
|
+
"headers",
|
|
52
|
+
HttpHeadersProgrammer.write({
|
|
53
|
+
...project,
|
|
54
|
+
options: {
|
|
55
|
+
...project.options,
|
|
56
|
+
functional: false,
|
|
57
|
+
numeric: false,
|
|
58
|
+
},
|
|
59
|
+
})(modulo)(type, name),
|
|
60
|
+
),
|
|
61
|
+
StatementFactory.constant(
|
|
62
|
+
"output",
|
|
63
|
+
ts.factory.createCallExpression(
|
|
64
|
+
ts.factory.createIdentifier("headers"),
|
|
65
|
+
undefined,
|
|
66
|
+
[ts.factory.createIdentifier("input")],
|
|
67
|
+
),
|
|
68
|
+
),
|
|
69
|
+
ts.factory.createIfStatement(
|
|
70
|
+
ts.factory.createPrefixUnaryExpression(
|
|
71
|
+
ts.SyntaxKind.ExclamationToken,
|
|
72
|
+
ts.factory.createCallExpression(
|
|
73
|
+
ts.factory.createIdentifier("is"),
|
|
74
|
+
undefined,
|
|
75
|
+
[ts.factory.createIdentifier("output")],
|
|
76
|
+
),
|
|
77
|
+
),
|
|
78
|
+
ts.factory.createReturnStatement(
|
|
79
|
+
ts.factory.createNull(),
|
|
80
|
+
),
|
|
81
|
+
),
|
|
82
|
+
ts.factory.createReturnStatement(
|
|
83
|
+
ts.factory.createIdentifier("output"),
|
|
84
|
+
),
|
|
85
|
+
]),
|
|
86
|
+
);
|
|
87
|
+
}
|
|
@@ -1,87 +1,87 @@
|
|
|
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 { IsProgrammer } from "../IsProgrammer";
|
|
10
|
-
import { HttpQueryProgrammer } from "./HttpQueryProgrammer";
|
|
11
|
-
|
|
12
|
-
export namespace HttpIsQueryProgrammer {
|
|
13
|
-
export const write =
|
|
14
|
-
(project: IProject) =>
|
|
15
|
-
(modulo: ts.LeftHandSideExpression) =>
|
|
16
|
-
(type: ts.Type, name?: string): ts.ArrowFunction =>
|
|
17
|
-
ts.factory.createArrowFunction(
|
|
18
|
-
undefined,
|
|
19
|
-
undefined,
|
|
20
|
-
[
|
|
21
|
-
IdentifierFactory.parameter(
|
|
22
|
-
"input",
|
|
23
|
-
ts.factory.createTypeReferenceNode(
|
|
24
|
-
HttpQueryProgrammer.INPUT_TYPE,
|
|
25
|
-
),
|
|
26
|
-
),
|
|
27
|
-
],
|
|
28
|
-
ts.factory.createUnionTypeNode([
|
|
29
|
-
ts.factory.createTypeReferenceNode(
|
|
30
|
-
`typia.Resolved<${
|
|
31
|
-
name ??
|
|
32
|
-
TypeFactory.getFullName(project.checker)(type)
|
|
33
|
-
}>`,
|
|
34
|
-
),
|
|
35
|
-
ts.factory.createLiteralTypeNode(ts.factory.createNull()),
|
|
36
|
-
]),
|
|
37
|
-
undefined,
|
|
38
|
-
ts.factory.createBlock([
|
|
39
|
-
StatementFactory.constant(
|
|
40
|
-
"is",
|
|
41
|
-
IsProgrammer.write({
|
|
42
|
-
...project,
|
|
43
|
-
options: {
|
|
44
|
-
...project.options,
|
|
45
|
-
functional: false,
|
|
46
|
-
numeric: false,
|
|
47
|
-
},
|
|
48
|
-
})(modulo)(false)(type, name),
|
|
49
|
-
),
|
|
50
|
-
StatementFactory.constant(
|
|
51
|
-
"query",
|
|
52
|
-
HttpQueryProgrammer.write({
|
|
53
|
-
...project,
|
|
54
|
-
options: {
|
|
55
|
-
...project.options,
|
|
56
|
-
functional: false,
|
|
57
|
-
numeric: false,
|
|
58
|
-
},
|
|
59
|
-
})(modulo)(type, name),
|
|
60
|
-
),
|
|
61
|
-
StatementFactory.constant(
|
|
62
|
-
"output",
|
|
63
|
-
ts.factory.createCallExpression(
|
|
64
|
-
ts.factory.createIdentifier("query"),
|
|
65
|
-
undefined,
|
|
66
|
-
[ts.factory.createIdentifier("input")],
|
|
67
|
-
),
|
|
68
|
-
),
|
|
69
|
-
ts.factory.createIfStatement(
|
|
70
|
-
ts.factory.createPrefixUnaryExpression(
|
|
71
|
-
ts.SyntaxKind.ExclamationToken,
|
|
72
|
-
ts.factory.createCallExpression(
|
|
73
|
-
ts.factory.createIdentifier("is"),
|
|
74
|
-
undefined,
|
|
75
|
-
[ts.factory.createIdentifier("output")],
|
|
76
|
-
),
|
|
77
|
-
),
|
|
78
|
-
ts.factory.createReturnStatement(
|
|
79
|
-
ts.factory.createNull(),
|
|
80
|
-
),
|
|
81
|
-
),
|
|
82
|
-
ts.factory.createReturnStatement(
|
|
83
|
-
ts.factory.createIdentifier("output"),
|
|
84
|
-
),
|
|
85
|
-
]),
|
|
86
|
-
);
|
|
87
|
-
}
|
|
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 { IsProgrammer } from "../IsProgrammer";
|
|
10
|
+
import { HttpQueryProgrammer } from "./HttpQueryProgrammer";
|
|
11
|
+
|
|
12
|
+
export namespace HttpIsQueryProgrammer {
|
|
13
|
+
export const write =
|
|
14
|
+
(project: IProject) =>
|
|
15
|
+
(modulo: ts.LeftHandSideExpression) =>
|
|
16
|
+
(type: ts.Type, name?: string): ts.ArrowFunction =>
|
|
17
|
+
ts.factory.createArrowFunction(
|
|
18
|
+
undefined,
|
|
19
|
+
undefined,
|
|
20
|
+
[
|
|
21
|
+
IdentifierFactory.parameter(
|
|
22
|
+
"input",
|
|
23
|
+
ts.factory.createTypeReferenceNode(
|
|
24
|
+
HttpQueryProgrammer.INPUT_TYPE,
|
|
25
|
+
),
|
|
26
|
+
),
|
|
27
|
+
],
|
|
28
|
+
ts.factory.createUnionTypeNode([
|
|
29
|
+
ts.factory.createTypeReferenceNode(
|
|
30
|
+
`typia.Resolved<${
|
|
31
|
+
name ??
|
|
32
|
+
TypeFactory.getFullName(project.checker)(type)
|
|
33
|
+
}>`,
|
|
34
|
+
),
|
|
35
|
+
ts.factory.createLiteralTypeNode(ts.factory.createNull()),
|
|
36
|
+
]),
|
|
37
|
+
undefined,
|
|
38
|
+
ts.factory.createBlock([
|
|
39
|
+
StatementFactory.constant(
|
|
40
|
+
"is",
|
|
41
|
+
IsProgrammer.write({
|
|
42
|
+
...project,
|
|
43
|
+
options: {
|
|
44
|
+
...project.options,
|
|
45
|
+
functional: false,
|
|
46
|
+
numeric: false,
|
|
47
|
+
},
|
|
48
|
+
})(modulo)(false)(type, name),
|
|
49
|
+
),
|
|
50
|
+
StatementFactory.constant(
|
|
51
|
+
"query",
|
|
52
|
+
HttpQueryProgrammer.write({
|
|
53
|
+
...project,
|
|
54
|
+
options: {
|
|
55
|
+
...project.options,
|
|
56
|
+
functional: false,
|
|
57
|
+
numeric: false,
|
|
58
|
+
},
|
|
59
|
+
})(modulo)(type, name),
|
|
60
|
+
),
|
|
61
|
+
StatementFactory.constant(
|
|
62
|
+
"output",
|
|
63
|
+
ts.factory.createCallExpression(
|
|
64
|
+
ts.factory.createIdentifier("query"),
|
|
65
|
+
undefined,
|
|
66
|
+
[ts.factory.createIdentifier("input")],
|
|
67
|
+
),
|
|
68
|
+
),
|
|
69
|
+
ts.factory.createIfStatement(
|
|
70
|
+
ts.factory.createPrefixUnaryExpression(
|
|
71
|
+
ts.SyntaxKind.ExclamationToken,
|
|
72
|
+
ts.factory.createCallExpression(
|
|
73
|
+
ts.factory.createIdentifier("is"),
|
|
74
|
+
undefined,
|
|
75
|
+
[ts.factory.createIdentifier("output")],
|
|
76
|
+
),
|
|
77
|
+
),
|
|
78
|
+
ts.factory.createReturnStatement(
|
|
79
|
+
ts.factory.createNull(),
|
|
80
|
+
),
|
|
81
|
+
),
|
|
82
|
+
ts.factory.createReturnStatement(
|
|
83
|
+
ts.factory.createIdentifier("output"),
|
|
84
|
+
),
|
|
85
|
+
]),
|
|
86
|
+
);
|
|
87
|
+
}
|
|
@@ -1,104 +1,104 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
|
-
import { MetadataCollection } from "../../factories/MetadataCollection";
|
|
5
|
-
import { MetadataFactory } from "../../factories/MetadataFactory";
|
|
6
|
-
import { StatementFactory } from "../../factories/StatementFactory";
|
|
7
|
-
import { TypeFactory } from "../../factories/TypeFactory";
|
|
8
|
-
|
|
9
|
-
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
10
|
-
|
|
11
|
-
import { IProject } from "../../transformers/IProject";
|
|
12
|
-
import { TransformerError } from "../../transformers/TransformerError";
|
|
13
|
-
|
|
14
|
-
import { AssertProgrammer } from "../AssertProgrammer";
|
|
15
|
-
import { FunctionImporter } from "../helpers/FunctionImporeter";
|
|
16
|
-
import { HttpMetadataUtil } from "../helpers/HttpMetadataUtil";
|
|
17
|
-
|
|
18
|
-
export namespace HttpParameterProgrammer {
|
|
19
|
-
export const write =
|
|
20
|
-
(project: IProject) =>
|
|
21
|
-
(modulo: ts.LeftHandSideExpression) =>
|
|
22
|
-
(type: ts.Type, name?: string): ts.ArrowFunction => {
|
|
23
|
-
const result = MetadataFactory.analyze(project.checker)({
|
|
24
|
-
escape: false,
|
|
25
|
-
constant: true,
|
|
26
|
-
absorb: true,
|
|
27
|
-
validate,
|
|
28
|
-
})(new MetadataCollection())(type);
|
|
29
|
-
if (result.success === false)
|
|
30
|
-
throw TransformerError.from(modulo.getText())(result.errors);
|
|
31
|
-
|
|
32
|
-
const atomic = [...HttpMetadataUtil.atomics(result.data)][0]!;
|
|
33
|
-
const importer: FunctionImporter = new FunctionImporter(
|
|
34
|
-
modulo.getText(),
|
|
35
|
-
);
|
|
36
|
-
const block: ts.Statement[] = [
|
|
37
|
-
StatementFactory.constant(
|
|
38
|
-
"assert",
|
|
39
|
-
AssertProgrammer.write({
|
|
40
|
-
...project,
|
|
41
|
-
options: {
|
|
42
|
-
numeric: true,
|
|
43
|
-
},
|
|
44
|
-
})(modulo)(false)(type, name),
|
|
45
|
-
),
|
|
46
|
-
StatementFactory.constant(
|
|
47
|
-
"value",
|
|
48
|
-
ts.factory.createCallExpression(
|
|
49
|
-
importer.use(atomic),
|
|
50
|
-
undefined,
|
|
51
|
-
[ts.factory.createIdentifier("input")],
|
|
52
|
-
),
|
|
53
|
-
),
|
|
54
|
-
ts.factory.createReturnStatement(
|
|
55
|
-
ts.factory.createCallExpression(
|
|
56
|
-
ts.factory.createIdentifier("assert"),
|
|
57
|
-
undefined,
|
|
58
|
-
[ts.factory.createIdentifier("value")],
|
|
59
|
-
),
|
|
60
|
-
),
|
|
61
|
-
];
|
|
62
|
-
|
|
63
|
-
return ts.factory.createArrowFunction(
|
|
64
|
-
undefined,
|
|
65
|
-
undefined,
|
|
66
|
-
[
|
|
67
|
-
IdentifierFactory.parameter(
|
|
68
|
-
"input",
|
|
69
|
-
ts.factory.createTypeReferenceNode("string"),
|
|
70
|
-
),
|
|
71
|
-
],
|
|
72
|
-
ts.factory.createTypeReferenceNode(
|
|
73
|
-
name ?? TypeFactory.getFullName(project.checker)(type),
|
|
74
|
-
),
|
|
75
|
-
undefined,
|
|
76
|
-
ts.factory.createBlock(
|
|
77
|
-
[...importer.declare(modulo), ...block],
|
|
78
|
-
true,
|
|
79
|
-
),
|
|
80
|
-
);
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
export const validate = (meta: Metadata): string[] => {
|
|
84
|
-
const errors: string[] = [];
|
|
85
|
-
const insert = (msg: string) => errors.push(msg);
|
|
86
|
-
|
|
87
|
-
if (meta.any) insert("do not allow any type");
|
|
88
|
-
if (meta.isRequired() === false)
|
|
89
|
-
insert("do not allow undefindable type");
|
|
90
|
-
|
|
91
|
-
const atomics = HttpMetadataUtil.atomics(meta);
|
|
92
|
-
const expected: number =
|
|
93
|
-
meta.atomics.length +
|
|
94
|
-
meta.templates.length +
|
|
95
|
-
meta.constants
|
|
96
|
-
.map((c) => c.values.length)
|
|
97
|
-
.reduce((a, b) => a + b, 0);
|
|
98
|
-
if (meta.size() !== expected || atomics.size === 0)
|
|
99
|
-
insert("only atomic or constant types are allowed");
|
|
100
|
-
if (atomics.size > 1) insert("do not allow union type");
|
|
101
|
-
|
|
102
|
-
return errors;
|
|
103
|
-
};
|
|
104
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
|
+
import { MetadataCollection } from "../../factories/MetadataCollection";
|
|
5
|
+
import { MetadataFactory } from "../../factories/MetadataFactory";
|
|
6
|
+
import { StatementFactory } from "../../factories/StatementFactory";
|
|
7
|
+
import { TypeFactory } from "../../factories/TypeFactory";
|
|
8
|
+
|
|
9
|
+
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
10
|
+
|
|
11
|
+
import { IProject } from "../../transformers/IProject";
|
|
12
|
+
import { TransformerError } from "../../transformers/TransformerError";
|
|
13
|
+
|
|
14
|
+
import { AssertProgrammer } from "../AssertProgrammer";
|
|
15
|
+
import { FunctionImporter } from "../helpers/FunctionImporeter";
|
|
16
|
+
import { HttpMetadataUtil } from "../helpers/HttpMetadataUtil";
|
|
17
|
+
|
|
18
|
+
export namespace HttpParameterProgrammer {
|
|
19
|
+
export const write =
|
|
20
|
+
(project: IProject) =>
|
|
21
|
+
(modulo: ts.LeftHandSideExpression) =>
|
|
22
|
+
(type: ts.Type, name?: string): ts.ArrowFunction => {
|
|
23
|
+
const result = MetadataFactory.analyze(project.checker)({
|
|
24
|
+
escape: false,
|
|
25
|
+
constant: true,
|
|
26
|
+
absorb: true,
|
|
27
|
+
validate,
|
|
28
|
+
})(new MetadataCollection())(type);
|
|
29
|
+
if (result.success === false)
|
|
30
|
+
throw TransformerError.from(modulo.getText())(result.errors);
|
|
31
|
+
|
|
32
|
+
const atomic = [...HttpMetadataUtil.atomics(result.data)][0]!;
|
|
33
|
+
const importer: FunctionImporter = new FunctionImporter(
|
|
34
|
+
modulo.getText(),
|
|
35
|
+
);
|
|
36
|
+
const block: ts.Statement[] = [
|
|
37
|
+
StatementFactory.constant(
|
|
38
|
+
"assert",
|
|
39
|
+
AssertProgrammer.write({
|
|
40
|
+
...project,
|
|
41
|
+
options: {
|
|
42
|
+
numeric: true,
|
|
43
|
+
},
|
|
44
|
+
})(modulo)(false)(type, name),
|
|
45
|
+
),
|
|
46
|
+
StatementFactory.constant(
|
|
47
|
+
"value",
|
|
48
|
+
ts.factory.createCallExpression(
|
|
49
|
+
importer.use(atomic),
|
|
50
|
+
undefined,
|
|
51
|
+
[ts.factory.createIdentifier("input")],
|
|
52
|
+
),
|
|
53
|
+
),
|
|
54
|
+
ts.factory.createReturnStatement(
|
|
55
|
+
ts.factory.createCallExpression(
|
|
56
|
+
ts.factory.createIdentifier("assert"),
|
|
57
|
+
undefined,
|
|
58
|
+
[ts.factory.createIdentifier("value")],
|
|
59
|
+
),
|
|
60
|
+
),
|
|
61
|
+
];
|
|
62
|
+
|
|
63
|
+
return ts.factory.createArrowFunction(
|
|
64
|
+
undefined,
|
|
65
|
+
undefined,
|
|
66
|
+
[
|
|
67
|
+
IdentifierFactory.parameter(
|
|
68
|
+
"input",
|
|
69
|
+
ts.factory.createTypeReferenceNode("string"),
|
|
70
|
+
),
|
|
71
|
+
],
|
|
72
|
+
ts.factory.createTypeReferenceNode(
|
|
73
|
+
name ?? TypeFactory.getFullName(project.checker)(type),
|
|
74
|
+
),
|
|
75
|
+
undefined,
|
|
76
|
+
ts.factory.createBlock(
|
|
77
|
+
[...importer.declare(modulo), ...block],
|
|
78
|
+
true,
|
|
79
|
+
),
|
|
80
|
+
);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export const validate = (meta: Metadata): string[] => {
|
|
84
|
+
const errors: string[] = [];
|
|
85
|
+
const insert = (msg: string) => errors.push(msg);
|
|
86
|
+
|
|
87
|
+
if (meta.any) insert("do not allow any type");
|
|
88
|
+
if (meta.isRequired() === false)
|
|
89
|
+
insert("do not allow undefindable type");
|
|
90
|
+
|
|
91
|
+
const atomics = HttpMetadataUtil.atomics(meta);
|
|
92
|
+
const expected: number =
|
|
93
|
+
meta.atomics.length +
|
|
94
|
+
meta.templates.length +
|
|
95
|
+
meta.constants
|
|
96
|
+
.map((c) => c.values.length)
|
|
97
|
+
.reduce((a, b) => a + b, 0);
|
|
98
|
+
if (meta.size() !== expected || atomics.size === 0)
|
|
99
|
+
insert("only atomic or constant types are allowed");
|
|
100
|
+
if (atomics.size > 1) insert("do not allow union type");
|
|
101
|
+
|
|
102
|
+
return errors;
|
|
103
|
+
};
|
|
104
|
+
}
|