typia 5.1.0-dev.20230923 → 5.1.0-dev.20230925
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/README.md +1 -1
- package/lib/functional/$HeadersReader.d.ts +6 -0
- package/lib/functional/$HeadersReader.js +35 -0
- package/lib/functional/$HeadersReader.js.map +1 -0
- package/lib/functional/$ParameterReader.d.ts +6 -0
- package/lib/functional/$ParameterReader.js +35 -0
- package/lib/functional/$ParameterReader.js.map +1 -0
- package/lib/functional/$QueryReader.d.ts +7 -0
- package/lib/functional/$QueryReader.js +57 -0
- package/lib/functional/$QueryReader.js.map +1 -0
- package/lib/functional/Namespace.js +9 -0
- package/lib/functional/Namespace.js.map +1 -1
- package/lib/http.d.ts +872 -0
- package/lib/http.js +112 -0
- package/lib/http.js.map +1 -0
- package/lib/json.js +2 -2
- package/lib/json.js.map +1 -1
- package/lib/misc.js +2 -2
- package/lib/misc.js.map +1 -1
- package/lib/module.d.ts +1 -0
- package/lib/module.js +2 -1
- package/lib/module.js.map +1 -1
- package/lib/programmers/helpers/HttpMetadataUtil.d.ts +5 -0
- package/lib/programmers/helpers/HttpMetadataUtil.js +44 -0
- package/lib/programmers/helpers/HttpMetadataUtil.js.map +1 -0
- package/lib/programmers/http/HttpAssertHeadersProgrammer.d.ts +5 -0
- package/lib/programmers/http/HttpAssertHeadersProgrammer.js +41 -0
- package/lib/programmers/http/HttpAssertHeadersProgrammer.js.map +1 -0
- package/lib/programmers/http/HttpAssertQueryProgrammer.d.ts +5 -0
- package/lib/programmers/http/HttpAssertQueryProgrammer.js +41 -0
- package/lib/programmers/http/HttpAssertQueryProgrammer.js.map +1 -0
- package/lib/programmers/http/HttpHeadersProgrammer.d.ts +6 -0
- package/lib/programmers/http/HttpHeadersProgrammer.js +219 -0
- package/lib/programmers/http/HttpHeadersProgrammer.js.map +1 -0
- package/lib/programmers/http/HttpIsHeadersProgrammer.d.ts +5 -0
- package/lib/programmers/http/HttpIsHeadersProgrammer.js +45 -0
- package/lib/programmers/http/HttpIsHeadersProgrammer.js.map +1 -0
- package/lib/programmers/http/HttpIsQueryProgrammer.d.ts +5 -0
- package/lib/programmers/http/HttpIsQueryProgrammer.js +45 -0
- package/lib/programmers/http/HttpIsQueryProgrammer.js.map +1 -0
- package/lib/programmers/http/HttpParameterProgrammer.d.ts +5 -0
- package/lib/programmers/http/HttpParameterProgrammer.js +101 -0
- package/lib/programmers/http/HttpParameterProgrammer.js.map +1 -0
- package/lib/programmers/http/HttpQueryProgrammer.d.ts +6 -0
- package/lib/programmers/http/HttpQueryProgrammer.js +181 -0
- package/lib/programmers/http/HttpQueryProgrammer.js.map +1 -0
- package/lib/programmers/http/HttpValidateHeadersProgrammer.d.ts +5 -0
- package/lib/programmers/http/HttpValidateHeadersProgrammer.js +41 -0
- package/lib/programmers/http/HttpValidateHeadersProgrammer.js.map +1 -0
- package/lib/programmers/http/HttpValidateQueryProgrammer.d.ts +5 -0
- package/lib/programmers/http/HttpValidateQueryProgrammer.js +41 -0
- package/lib/programmers/http/HttpValidateQueryProgrammer.js.map +1 -0
- package/lib/protobuf.d.ts +24 -24
- package/lib/protobuf.js +4 -4
- package/lib/protobuf.js.map +1 -1
- package/lib/transformers/CallExpressionTransformer.js +40 -0
- package/lib/transformers/CallExpressionTransformer.js.map +1 -1
- package/lib/transformers/features/http/CreateHttpAssertHeadersTransformer.d.ts +4 -0
- package/lib/transformers/features/http/CreateHttpAssertHeadersTransformer.js +12 -0
- package/lib/transformers/features/http/CreateHttpAssertHeadersTransformer.js.map +1 -0
- package/lib/transformers/features/http/CreateHttpAssertQueryTransformer.d.ts +4 -0
- package/lib/transformers/features/http/CreateHttpAssertQueryTransformer.js +12 -0
- package/lib/transformers/features/http/CreateHttpAssertQueryTransformer.js.map +1 -0
- package/lib/transformers/features/http/CreateHttpHeadersTransformer.d.ts +4 -0
- package/lib/transformers/features/http/CreateHttpHeadersTransformer.js +10 -0
- package/lib/transformers/features/http/CreateHttpHeadersTransformer.js.map +1 -0
- package/lib/transformers/features/http/CreateHttpIsHeadersTransformer.d.ts +4 -0
- package/lib/transformers/features/http/CreateHttpIsHeadersTransformer.js +10 -0
- package/lib/transformers/features/http/CreateHttpIsHeadersTransformer.js.map +1 -0
- package/lib/transformers/features/http/CreateHttpIsQueryTransformer.d.ts +4 -0
- package/lib/transformers/features/http/CreateHttpIsQueryTransformer.js +10 -0
- package/lib/transformers/features/http/CreateHttpIsQueryTransformer.js.map +1 -0
- package/lib/transformers/features/http/CreateHttpParameterTransformer.d.ts +4 -0
- package/lib/transformers/features/http/CreateHttpParameterTransformer.js +10 -0
- package/lib/transformers/features/http/CreateHttpParameterTransformer.js.map +1 -0
- package/lib/transformers/features/http/CreateHttpQueryTransformer.d.ts +4 -0
- package/lib/transformers/features/http/CreateHttpQueryTransformer.js +10 -0
- package/lib/transformers/features/http/CreateHttpQueryTransformer.js.map +1 -0
- package/lib/transformers/features/http/CreateHttpValidateHeadersTransformer copy.d.ts +4 -0
- package/lib/transformers/features/http/CreateHttpValidateHeadersTransformer copy.js +12 -0
- package/lib/transformers/features/http/CreateHttpValidateHeadersTransformer copy.js.map +1 -0
- package/lib/transformers/features/http/CreateHttpValidateQueryTransformer.d.ts +4 -0
- package/lib/transformers/features/http/CreateHttpValidateQueryTransformer.js +12 -0
- package/lib/transformers/features/http/CreateHttpValidateQueryTransformer.js.map +1 -0
- package/lib/transformers/features/http/HttpAssertHeadersTransformer.d.ts +4 -0
- package/lib/transformers/features/http/HttpAssertHeadersTransformer.js +12 -0
- package/lib/transformers/features/http/HttpAssertHeadersTransformer.js.map +1 -0
- package/lib/transformers/features/http/HttpAssertQueryTransformer.d.ts +4 -0
- package/lib/transformers/features/http/HttpAssertQueryTransformer.js +12 -0
- package/lib/transformers/features/http/HttpAssertQueryTransformer.js.map +1 -0
- package/lib/transformers/features/http/HttpHeadersTransformer.d.ts +4 -0
- package/lib/transformers/features/http/HttpHeadersTransformer.js +10 -0
- package/lib/transformers/features/http/HttpHeadersTransformer.js.map +1 -0
- package/lib/transformers/features/http/HttpIsHeadersTransformer.d.ts +4 -0
- package/lib/transformers/features/http/HttpIsHeadersTransformer.js +10 -0
- package/lib/transformers/features/http/HttpIsHeadersTransformer.js.map +1 -0
- package/lib/transformers/features/http/HttpIsQueryTransformer.d.ts +4 -0
- package/lib/transformers/features/http/HttpIsQueryTransformer.js +10 -0
- package/lib/transformers/features/http/HttpIsQueryTransformer.js.map +1 -0
- package/lib/transformers/features/http/HttpParameterTransformer.d.ts +4 -0
- package/lib/transformers/features/http/HttpParameterTransformer.js +10 -0
- package/lib/transformers/features/http/HttpParameterTransformer.js.map +1 -0
- package/lib/transformers/features/http/HttpQueryTransformer.d.ts +4 -0
- package/lib/transformers/features/http/HttpQueryTransformer.js +10 -0
- package/lib/transformers/features/http/HttpQueryTransformer.js.map +1 -0
- package/lib/transformers/features/http/HttpValidateHeadersTransformer.d.ts +4 -0
- package/lib/transformers/features/http/HttpValidateHeadersTransformer.js +12 -0
- package/lib/transformers/features/http/HttpValidateHeadersTransformer.js.map +1 -0
- package/lib/transformers/features/http/HttpValidateQueryTransformer.d.ts +4 -0
- package/lib/transformers/features/http/HttpValidateQueryTransformer.js +12 -0
- package/lib/transformers/features/http/HttpValidateQueryTransformer.js.map +1 -0
- package/package.json +1 -1
- package/src/functional/$HeadersReader.ts +28 -0
- package/src/functional/$ParameterReader.ts +31 -0
- package/src/functional/$QueryReader.ts +53 -0
- package/src/functional/Namespace.ts +9 -0
- package/src/http.ts +1149 -0
- package/src/json.ts +2 -2
- package/src/misc.ts +2 -2
- package/src/module.ts +1 -0
- package/src/programmers/helpers/HttpMetadataUtil.ts +21 -0
- package/src/programmers/http/HttpAssertHeadersProgrammer.ts +77 -0
- package/src/programmers/http/HttpAssertQueryProgrammer.ts +77 -0
- package/src/programmers/http/HttpHeadersProgrammer.ts +328 -0
- package/src/programmers/http/HttpIsHeadersProgrammer.ts +87 -0
- package/src/programmers/http/HttpIsQueryProgrammer.ts +87 -0
- package/src/programmers/http/HttpParameterProgrammer.ts +104 -0
- package/src/programmers/http/HttpQueryProgrammer.ts +286 -0
- package/src/programmers/http/HttpValidateHeadersProgrammer.ts +77 -0
- package/src/programmers/http/HttpValidateQueryProgrammer.ts +77 -0
- package/src/protobuf.ts +34 -28
- package/src/transformers/CallExpressionTransformer.ts +46 -0
- package/src/transformers/features/http/CreateHttpAssertHeadersTransformer.ts +12 -0
- package/src/transformers/features/http/CreateHttpAssertQueryTransformer.ts +12 -0
- package/src/transformers/features/http/CreateHttpHeadersTransformer.ts +9 -0
- package/src/transformers/features/http/CreateHttpIsHeadersTransformer.ts +9 -0
- package/src/transformers/features/http/CreateHttpIsQueryTransformer.ts +9 -0
- package/src/transformers/features/http/CreateHttpParameterTransformer.ts +9 -0
- package/src/transformers/features/http/CreateHttpQueryTransformer.ts +9 -0
- package/src/transformers/features/http/CreateHttpValidateHeadersTransformer copy.ts +12 -0
- package/src/transformers/features/http/CreateHttpValidateQueryTransformer.ts +12 -0
- package/src/transformers/features/http/HttpAssertHeadersTransformer.ts +10 -0
- package/src/transformers/features/http/HttpAssertQueryTransformer.ts +10 -0
- package/src/transformers/features/http/HttpHeadersTransformer.ts +9 -0
- package/src/transformers/features/http/HttpIsHeadersTransformer.ts +9 -0
- package/src/transformers/features/http/HttpIsQueryTransformer.ts +9 -0
- package/src/transformers/features/http/HttpParameterTransformer.ts +9 -0
- package/src/transformers/features/http/HttpQueryTransformer.ts +9 -0
- package/src/transformers/features/http/HttpValidateHeadersTransformer.ts +10 -0
- package/src/transformers/features/http/HttpValidateQueryTransformer.ts +10 -0
package/src/json.ts
CHANGED
|
@@ -121,7 +121,7 @@ export function assertParse<T>(input: string): Primitive<T>;
|
|
|
121
121
|
export function assertParse<T>(): Primitive<T> {
|
|
122
122
|
halt("assertParse");
|
|
123
123
|
}
|
|
124
|
-
Object.assign(assertParse, Namespace.assert("assertParse"));
|
|
124
|
+
Object.assign(assertParse, Namespace.assert("json.assertParse"));
|
|
125
125
|
|
|
126
126
|
/**
|
|
127
127
|
* > You must configure the generic argument `T`.
|
|
@@ -308,7 +308,7 @@ export function assertStringify<T>(input: T): unknown;
|
|
|
308
308
|
export function assertStringify(): string {
|
|
309
309
|
halt("assertStringify");
|
|
310
310
|
}
|
|
311
|
-
Object.assign(assertStringify, Namespace.assert("assertStringify"));
|
|
311
|
+
Object.assign(assertStringify, Namespace.assert("json.assertStringify"));
|
|
312
312
|
Object.assign(assertStringify, Namespace.json.stringify("assertStringify"));
|
|
313
313
|
|
|
314
314
|
/**
|
package/src/misc.ts
CHANGED
|
@@ -130,7 +130,7 @@ export function assertClone<T>(input: unknown): Resolved<T>;
|
|
|
130
130
|
export function assertClone(): never {
|
|
131
131
|
halt("assertClone");
|
|
132
132
|
}
|
|
133
|
-
Object.assign(assertClone, Namespace.assert("assertClone"));
|
|
133
|
+
Object.assign(assertClone, Namespace.assert("misc.assertClone"));
|
|
134
134
|
Object.assign(assertClone, Namespace.misc.clone("assertClone"));
|
|
135
135
|
|
|
136
136
|
/**
|
|
@@ -301,7 +301,7 @@ export function assertPrune<T>(input: unknown): T;
|
|
|
301
301
|
export function assertPrune(): unknown {
|
|
302
302
|
halt("assertPrune");
|
|
303
303
|
}
|
|
304
|
-
Object.assign(assertPrune, Namespace.assert("assertPrune"));
|
|
304
|
+
Object.assign(assertPrune, Namespace.assert("misc.assertPrune"));
|
|
305
305
|
Object.assign(assertPrune, Namespace.misc.prune("assertPrune"));
|
|
306
306
|
|
|
307
307
|
/**
|
package/src/module.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { IRandomGenerator } from "./IRandomGenerator";
|
|
|
6
6
|
import { IValidation } from "./IValidation";
|
|
7
7
|
import { Resolved } from "./Resolved";
|
|
8
8
|
|
|
9
|
+
export * as http from "./http";
|
|
9
10
|
export * as json from "./json";
|
|
10
11
|
export * as misc from "./misc";
|
|
11
12
|
export * as protobuf from "./protobuf";
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
2
|
+
|
|
3
|
+
export namespace HttpMetadataUtil {
|
|
4
|
+
export const atomics = (
|
|
5
|
+
meta: Metadata,
|
|
6
|
+
): Set<"boolean" | "bigint" | "number" | "string"> =>
|
|
7
|
+
new Set([
|
|
8
|
+
...meta.atomics.map((a) => a.type),
|
|
9
|
+
...meta.constants.map((c) => c.type),
|
|
10
|
+
...(meta.templates.length ? (["string"] as const) : []),
|
|
11
|
+
]);
|
|
12
|
+
|
|
13
|
+
export const isUnion = (meta: Metadata): boolean =>
|
|
14
|
+
atomics(meta).size +
|
|
15
|
+
meta.arrays.length +
|
|
16
|
+
meta.tuples.length +
|
|
17
|
+
meta.natives.length +
|
|
18
|
+
meta.maps.length +
|
|
19
|
+
meta.objects.length >
|
|
20
|
+
1;
|
|
21
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
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 { HttpHeadersProgrammer } from "./HttpHeadersProgrammer";
|
|
11
|
+
|
|
12
|
+
export namespace HttpAssertHeadersProgrammer {
|
|
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.createTypeReferenceNode(
|
|
29
|
+
`typia.Resolved<${
|
|
30
|
+
name ?? TypeFactory.getFullName(project.checker)(type)
|
|
31
|
+
}>`,
|
|
32
|
+
),
|
|
33
|
+
undefined,
|
|
34
|
+
ts.factory.createBlock([
|
|
35
|
+
StatementFactory.constant(
|
|
36
|
+
"decode",
|
|
37
|
+
HttpHeadersProgrammer.write({
|
|
38
|
+
...project,
|
|
39
|
+
options: {
|
|
40
|
+
...project.options,
|
|
41
|
+
functional: false,
|
|
42
|
+
numeric: false,
|
|
43
|
+
},
|
|
44
|
+
})(modulo)(type, name),
|
|
45
|
+
),
|
|
46
|
+
StatementFactory.constant(
|
|
47
|
+
"assert",
|
|
48
|
+
AssertProgrammer.write({
|
|
49
|
+
...project,
|
|
50
|
+
options: {
|
|
51
|
+
...project.options,
|
|
52
|
+
functional: false,
|
|
53
|
+
numeric: false,
|
|
54
|
+
},
|
|
55
|
+
})(modulo)(false)(type, name),
|
|
56
|
+
),
|
|
57
|
+
StatementFactory.constant(
|
|
58
|
+
"output",
|
|
59
|
+
ts.factory.createCallExpression(
|
|
60
|
+
ts.factory.createIdentifier("decode"),
|
|
61
|
+
undefined,
|
|
62
|
+
[ts.factory.createIdentifier("input")],
|
|
63
|
+
),
|
|
64
|
+
),
|
|
65
|
+
ts.factory.createReturnStatement(
|
|
66
|
+
ts.factory.createAsExpression(
|
|
67
|
+
ts.factory.createCallExpression(
|
|
68
|
+
ts.factory.createIdentifier("assert"),
|
|
69
|
+
undefined,
|
|
70
|
+
[ts.factory.createIdentifier("output")],
|
|
71
|
+
),
|
|
72
|
+
TypeFactory.keyword("any"),
|
|
73
|
+
),
|
|
74
|
+
),
|
|
75
|
+
]),
|
|
76
|
+
);
|
|
77
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
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 { HttpQueryProgrammer } from "./HttpQueryProgrammer";
|
|
11
|
+
|
|
12
|
+
export namespace HttpAssertQueryProgrammer {
|
|
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.createTypeReferenceNode(
|
|
29
|
+
`typia.Resolved<${
|
|
30
|
+
name ?? TypeFactory.getFullName(project.checker)(type)
|
|
31
|
+
}>`,
|
|
32
|
+
),
|
|
33
|
+
undefined,
|
|
34
|
+
ts.factory.createBlock([
|
|
35
|
+
StatementFactory.constant(
|
|
36
|
+
"decode",
|
|
37
|
+
HttpQueryProgrammer.write({
|
|
38
|
+
...project,
|
|
39
|
+
options: {
|
|
40
|
+
...project.options,
|
|
41
|
+
functional: false,
|
|
42
|
+
numeric: false,
|
|
43
|
+
},
|
|
44
|
+
})(modulo)(type, name),
|
|
45
|
+
),
|
|
46
|
+
StatementFactory.constant(
|
|
47
|
+
"assert",
|
|
48
|
+
AssertProgrammer.write({
|
|
49
|
+
...project,
|
|
50
|
+
options: {
|
|
51
|
+
...project.options,
|
|
52
|
+
functional: false,
|
|
53
|
+
numeric: false,
|
|
54
|
+
},
|
|
55
|
+
})(modulo)(false)(type, name),
|
|
56
|
+
),
|
|
57
|
+
StatementFactory.constant(
|
|
58
|
+
"output",
|
|
59
|
+
ts.factory.createCallExpression(
|
|
60
|
+
ts.factory.createIdentifier("decode"),
|
|
61
|
+
undefined,
|
|
62
|
+
[ts.factory.createIdentifier("input")],
|
|
63
|
+
),
|
|
64
|
+
),
|
|
65
|
+
ts.factory.createReturnStatement(
|
|
66
|
+
ts.factory.createAsExpression(
|
|
67
|
+
ts.factory.createCallExpression(
|
|
68
|
+
ts.factory.createIdentifier("assert"),
|
|
69
|
+
undefined,
|
|
70
|
+
[ts.factory.createIdentifier("output")],
|
|
71
|
+
),
|
|
72
|
+
TypeFactory.keyword("any"),
|
|
73
|
+
),
|
|
74
|
+
),
|
|
75
|
+
]),
|
|
76
|
+
);
|
|
77
|
+
}
|
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { ExpressionFactory } from "../../factories/ExpressionFactory";
|
|
4
|
+
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
5
|
+
import { MetadataCollection } from "../../factories/MetadataCollection";
|
|
6
|
+
import { MetadataFactory } from "../../factories/MetadataFactory";
|
|
7
|
+
import { StatementFactory } from "../../factories/StatementFactory";
|
|
8
|
+
import { TypeFactory } from "../../factories/TypeFactory";
|
|
9
|
+
|
|
10
|
+
import { Metadata } from "../../schemas/metadata/Metadata";
|
|
11
|
+
import { MetadataArrayType } from "../../schemas/metadata/MetadataArrayType";
|
|
12
|
+
import { MetadataObject } from "../../schemas/metadata/MetadataObject";
|
|
13
|
+
import { MetadataProperty } from "../../schemas/metadata/MetadataProperty";
|
|
14
|
+
|
|
15
|
+
import { IProject } from "../../transformers/IProject";
|
|
16
|
+
import { TransformerError } from "../../transformers/TransformerError";
|
|
17
|
+
|
|
18
|
+
import { Atomic } from "../../typings/Atomic";
|
|
19
|
+
|
|
20
|
+
import { Escaper } from "../../utils/Escaper";
|
|
21
|
+
|
|
22
|
+
import { FunctionImporter } from "../helpers/FunctionImporeter";
|
|
23
|
+
import { HttpMetadataUtil } from "../helpers/HttpMetadataUtil";
|
|
24
|
+
|
|
25
|
+
export namespace HttpHeadersProgrammer {
|
|
26
|
+
export const INPUT_TYPE = "Record<string, string | string[] | undefined>";
|
|
27
|
+
|
|
28
|
+
export const write =
|
|
29
|
+
(project: IProject) =>
|
|
30
|
+
(modulo: ts.LeftHandSideExpression) =>
|
|
31
|
+
(type: ts.Type, name?: string): ts.ArrowFunction => {
|
|
32
|
+
// GET OBJECT TYPE
|
|
33
|
+
const importer: FunctionImporter = new FunctionImporter(
|
|
34
|
+
modulo.getText(),
|
|
35
|
+
);
|
|
36
|
+
const collection: MetadataCollection = new MetadataCollection();
|
|
37
|
+
const result = MetadataFactory.analyze(project.checker)({
|
|
38
|
+
escape: false,
|
|
39
|
+
constant: true,
|
|
40
|
+
absorb: true,
|
|
41
|
+
validate,
|
|
42
|
+
})(collection)(type);
|
|
43
|
+
if (result.success === false)
|
|
44
|
+
throw TransformerError.from(`typia.http.${importer.method}`)(
|
|
45
|
+
result.errors,
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
// DO TRANSFORM
|
|
49
|
+
const object: MetadataObject = result.data.objects[0]!;
|
|
50
|
+
const statements: ts.Statement[] = decode_object(importer)(object);
|
|
51
|
+
return ts.factory.createArrowFunction(
|
|
52
|
+
undefined,
|
|
53
|
+
undefined,
|
|
54
|
+
[
|
|
55
|
+
IdentifierFactory.parameter(
|
|
56
|
+
"input",
|
|
57
|
+
ts.factory.createTypeReferenceNode(INPUT_TYPE),
|
|
58
|
+
),
|
|
59
|
+
],
|
|
60
|
+
ts.factory.createTypeReferenceNode(
|
|
61
|
+
`typia.Resolved<${
|
|
62
|
+
name ?? TypeFactory.getFullName(project.checker)(type)
|
|
63
|
+
}>`,
|
|
64
|
+
),
|
|
65
|
+
undefined,
|
|
66
|
+
ts.factory.createBlock(
|
|
67
|
+
[...importer.declare(modulo), ...statements],
|
|
68
|
+
true,
|
|
69
|
+
),
|
|
70
|
+
);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const validate = (
|
|
74
|
+
meta: Metadata,
|
|
75
|
+
explore: MetadataFactory.IExplore,
|
|
76
|
+
): string[] => {
|
|
77
|
+
const errors: string[] = [];
|
|
78
|
+
const insert = (msg: string) => errors.push(msg);
|
|
79
|
+
|
|
80
|
+
if (explore.top === true) {
|
|
81
|
+
// TOP MUST BE ONLY OBJECT
|
|
82
|
+
if (meta.objects.length !== 1 || meta.bucket() !== 1)
|
|
83
|
+
insert("only one object type is allowed.");
|
|
84
|
+
if (meta.nullable === true) insert("headers cannot be null.");
|
|
85
|
+
if (meta.isRequired() === false) insert("headers cannot be null.");
|
|
86
|
+
} else if (
|
|
87
|
+
explore.nested !== null &&
|
|
88
|
+
explore.nested instanceof MetadataArrayType
|
|
89
|
+
) {
|
|
90
|
+
const atomics = HttpMetadataUtil.atomics(meta);
|
|
91
|
+
const expected: number =
|
|
92
|
+
meta.atomics.length +
|
|
93
|
+
meta.templates.length +
|
|
94
|
+
meta.constants
|
|
95
|
+
.map((c) => c.values.length)
|
|
96
|
+
.reduce((a, b) => a + b, 0);
|
|
97
|
+
if (atomics.size > 1) insert("union type is not allowed in array.");
|
|
98
|
+
if (meta.nullable) insert("nullable type is not allowed in array.");
|
|
99
|
+
if (meta.isRequired() === false)
|
|
100
|
+
insert("optional type is not allowed.");
|
|
101
|
+
if (meta.size() !== expected)
|
|
102
|
+
insert("only atomic or constant types are allowed in array.");
|
|
103
|
+
} else if (explore.object && explore.property !== null) {
|
|
104
|
+
//----
|
|
105
|
+
// COMMON
|
|
106
|
+
//----
|
|
107
|
+
// PROPERTY MUST BE SOLE
|
|
108
|
+
if (typeof explore.property === "object")
|
|
109
|
+
insert("dynamic property is not allowed.");
|
|
110
|
+
// DO NOT ALLOW TUPLE TYPE
|
|
111
|
+
if (meta.tuples.length) insert("tuple type is not allowed.");
|
|
112
|
+
// DO NOT ALLOW UNION TYPE
|
|
113
|
+
if (HttpMetadataUtil.isUnion(meta))
|
|
114
|
+
insert("union type is not allowed.");
|
|
115
|
+
// DO NOT ALLOW NESTED OBJECT
|
|
116
|
+
if (
|
|
117
|
+
meta.objects.length ||
|
|
118
|
+
meta.sets.length ||
|
|
119
|
+
meta.maps.length ||
|
|
120
|
+
meta.natives.length
|
|
121
|
+
)
|
|
122
|
+
insert("nested object type is not allowed.");
|
|
123
|
+
// DO NOT ALLOW NULLABLE
|
|
124
|
+
if (meta.nullable) insert("nullable type is not allowed.");
|
|
125
|
+
|
|
126
|
+
//----
|
|
127
|
+
// ARRAY CASES
|
|
128
|
+
//----
|
|
129
|
+
const isArray: boolean = meta.arrays.length > 1;
|
|
130
|
+
// ARRAY TYPE MUST BE REQUIRED
|
|
131
|
+
if (isArray && meta.isRequired() === false)
|
|
132
|
+
insert("optional type is not allowed when array.");
|
|
133
|
+
// SET-COOKIE MUST BE ARRAY
|
|
134
|
+
if (explore.property === "set-cookie" && !isArray)
|
|
135
|
+
insert("set-cookie property must be array.");
|
|
136
|
+
// MUST BE SINGULAR CASE
|
|
137
|
+
if (
|
|
138
|
+
typeof explore.property === "string" &&
|
|
139
|
+
SINGULAR.has(explore.property) &&
|
|
140
|
+
isArray
|
|
141
|
+
)
|
|
142
|
+
insert("property cannot be array.");
|
|
143
|
+
}
|
|
144
|
+
return errors;
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const decode_object =
|
|
148
|
+
(importer: FunctionImporter) =>
|
|
149
|
+
(object: MetadataObject): ts.Statement[] => {
|
|
150
|
+
const output: ts.Identifier = ts.factory.createIdentifier("output");
|
|
151
|
+
const optionals: string[] = [];
|
|
152
|
+
return [
|
|
153
|
+
StatementFactory.constant(
|
|
154
|
+
"output",
|
|
155
|
+
ts.factory.createObjectLiteralExpression(
|
|
156
|
+
object.properties.map((prop) => {
|
|
157
|
+
if (
|
|
158
|
+
!prop.value.isRequired() &&
|
|
159
|
+
prop.value.arrays.length +
|
|
160
|
+
prop.value.tuples.length >
|
|
161
|
+
0
|
|
162
|
+
)
|
|
163
|
+
optionals.push(
|
|
164
|
+
prop.key.constants[0]!.values[0] as string,
|
|
165
|
+
);
|
|
166
|
+
return decode_regular_property(importer)(prop);
|
|
167
|
+
}),
|
|
168
|
+
true,
|
|
169
|
+
),
|
|
170
|
+
),
|
|
171
|
+
...optionals.map((key) => {
|
|
172
|
+
const access = IdentifierFactory.access(output)(key);
|
|
173
|
+
return ts.factory.createIfStatement(
|
|
174
|
+
ts.factory.createStrictEquality(
|
|
175
|
+
ts.factory.createNumericLiteral(0),
|
|
176
|
+
IdentifierFactory.access(access)("length"),
|
|
177
|
+
),
|
|
178
|
+
ts.factory.createExpressionStatement(
|
|
179
|
+
ts.factory.createDeleteExpression(access),
|
|
180
|
+
),
|
|
181
|
+
);
|
|
182
|
+
}),
|
|
183
|
+
ts.factory.createReturnStatement(
|
|
184
|
+
ts.factory.createAsExpression(
|
|
185
|
+
output,
|
|
186
|
+
TypeFactory.keyword("any"),
|
|
187
|
+
),
|
|
188
|
+
),
|
|
189
|
+
];
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
const decode_regular_property =
|
|
193
|
+
(importer: FunctionImporter) =>
|
|
194
|
+
(property: MetadataProperty): ts.PropertyAssignment => {
|
|
195
|
+
const key: string = property.key.constants[0]!.values[0] as string;
|
|
196
|
+
const value: Metadata = property.value;
|
|
197
|
+
|
|
198
|
+
const [type, isArray]: [Atomic.Literal, boolean] = value.atomics
|
|
199
|
+
.length
|
|
200
|
+
? [value.atomics[0]!.type, false]
|
|
201
|
+
: value.constants.length
|
|
202
|
+
? [value.constants[0]!.type, false]
|
|
203
|
+
: value.templates.length
|
|
204
|
+
? ["string", false]
|
|
205
|
+
: (() => {
|
|
206
|
+
const meta: Metadata =
|
|
207
|
+
value.arrays[0]?.type.value ??
|
|
208
|
+
value.tuples[0]!.type.elements[0]!;
|
|
209
|
+
return meta.atomics.length
|
|
210
|
+
? [meta.atomics[0]!.type, true]
|
|
211
|
+
: meta.templates.length
|
|
212
|
+
? ["string", true]
|
|
213
|
+
: [meta.constants[0]!.type, true];
|
|
214
|
+
})();
|
|
215
|
+
// if (isArray && SINGULAR.has(key))
|
|
216
|
+
// throw new Error(
|
|
217
|
+
// ErrorMessages.property(importer)(object)(key)(
|
|
218
|
+
// `property "${key}" cannot be array.`,
|
|
219
|
+
// ),
|
|
220
|
+
// );
|
|
221
|
+
// else if (!isArray && key === "set-cookie")
|
|
222
|
+
// throw new Error(
|
|
223
|
+
// ErrorMessages.property(importer)(object)(key)(
|
|
224
|
+
// `property "${key}" must be array.`,
|
|
225
|
+
// ),
|
|
226
|
+
// );
|
|
227
|
+
|
|
228
|
+
const accessor = IdentifierFactory.access(
|
|
229
|
+
ts.factory.createIdentifier("input"),
|
|
230
|
+
)(key.toLowerCase());
|
|
231
|
+
|
|
232
|
+
return ts.factory.createPropertyAssignment(
|
|
233
|
+
Escaper.variable(key)
|
|
234
|
+
? key
|
|
235
|
+
: ts.factory.createStringLiteral(key),
|
|
236
|
+
isArray
|
|
237
|
+
? key === "set-cookie"
|
|
238
|
+
? accessor
|
|
239
|
+
: decode_array(importer)(type)(key)(value)(accessor)
|
|
240
|
+
: decode_value(importer)(type)(accessor),
|
|
241
|
+
);
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
const decode_value =
|
|
245
|
+
(importer: FunctionImporter) =>
|
|
246
|
+
(type: Atomic.Literal) =>
|
|
247
|
+
(value: ts.Expression) =>
|
|
248
|
+
type === "string"
|
|
249
|
+
? value
|
|
250
|
+
: ts.factory.createCallExpression(
|
|
251
|
+
importer.use(type),
|
|
252
|
+
undefined,
|
|
253
|
+
[value],
|
|
254
|
+
);
|
|
255
|
+
|
|
256
|
+
const decode_array =
|
|
257
|
+
(importer: FunctionImporter) =>
|
|
258
|
+
(type: Atomic.Literal) =>
|
|
259
|
+
(key: string) =>
|
|
260
|
+
(value: Metadata) =>
|
|
261
|
+
(accessor: ts.Expression) => {
|
|
262
|
+
const split: ts.CallChain = ts.factory.createCallChain(
|
|
263
|
+
ts.factory.createPropertyAccessChain(
|
|
264
|
+
ts.factory.createCallChain(
|
|
265
|
+
ts.factory.createPropertyAccessChain(
|
|
266
|
+
accessor,
|
|
267
|
+
ts.factory.createToken(
|
|
268
|
+
ts.SyntaxKind.QuestionDotToken,
|
|
269
|
+
),
|
|
270
|
+
ts.factory.createIdentifier("split"),
|
|
271
|
+
),
|
|
272
|
+
undefined,
|
|
273
|
+
undefined,
|
|
274
|
+
[
|
|
275
|
+
ts.factory.createStringLiteral(
|
|
276
|
+
key === "cookie" ? "; " : ", ",
|
|
277
|
+
),
|
|
278
|
+
],
|
|
279
|
+
),
|
|
280
|
+
ts.factory.createToken(ts.SyntaxKind.QuestionDotToken),
|
|
281
|
+
ts.factory.createIdentifier("map"),
|
|
282
|
+
),
|
|
283
|
+
undefined,
|
|
284
|
+
undefined,
|
|
285
|
+
[importer.use(type)],
|
|
286
|
+
);
|
|
287
|
+
return ts.factory.createConditionalExpression(
|
|
288
|
+
ExpressionFactory.isArray(accessor),
|
|
289
|
+
undefined,
|
|
290
|
+
ts.factory.createCallExpression(
|
|
291
|
+
IdentifierFactory.access(accessor)("map"),
|
|
292
|
+
undefined,
|
|
293
|
+
[importer.use(type)],
|
|
294
|
+
),
|
|
295
|
+
undefined,
|
|
296
|
+
value.isRequired() === false
|
|
297
|
+
? split
|
|
298
|
+
: ts.factory.createBinaryExpression(
|
|
299
|
+
split,
|
|
300
|
+
ts.factory.createToken(
|
|
301
|
+
ts.SyntaxKind.QuestionQuestionToken,
|
|
302
|
+
),
|
|
303
|
+
ts.factory.createArrayLiteralExpression([], false),
|
|
304
|
+
),
|
|
305
|
+
);
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
const SINGULAR: Set<string> = new Set([
|
|
310
|
+
"age",
|
|
311
|
+
"authorization",
|
|
312
|
+
"content-length",
|
|
313
|
+
"content-type",
|
|
314
|
+
"etag",
|
|
315
|
+
"expires",
|
|
316
|
+
"from",
|
|
317
|
+
"host",
|
|
318
|
+
"if-modified-since",
|
|
319
|
+
"if-unmodified-since",
|
|
320
|
+
"last-modified",
|
|
321
|
+
"location",
|
|
322
|
+
"max-forwards",
|
|
323
|
+
"proxy-authorization",
|
|
324
|
+
"referer",
|
|
325
|
+
"retry-after",
|
|
326
|
+
"server",
|
|
327
|
+
"user-agent",
|
|
328
|
+
]);
|
|
@@ -0,0 +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
|
+
}
|