typia 3.5.0-dev.20221222 → 3.5.0-dev.20230124
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 +5 -2
- package/lib/executable/internal/TypiaSetupWizard.d.ts +6 -2
- package/lib/executable/internal/TypiaSetupWizard.js +23 -22
- package/lib/executable/internal/TypiaSetupWizard.js.map +1 -1
- package/lib/executable/typia.js +11 -10
- package/lib/executable/typia.js.map +1 -1
- package/lib/factories/internal/protocols/ProtocolMetadataUtil.d.ts +1 -0
- package/lib/factories/internal/protocols/ProtocolMetadataUtil.js +20 -0
- package/lib/factories/internal/protocols/ProtocolMetadataUtil.js.map +1 -1
- package/lib/factories/internal/protocols/iterate_protocol_map.d.ts +2 -1
- package/lib/factories/internal/protocols/iterate_protocol_map.js +7 -4
- package/lib/factories/internal/protocols/iterate_protocol_map.js.map +1 -1
- package/lib/factories/internal/protocols/iterate_protocol_metadata.js +3 -3
- package/lib/factories/internal/protocols/iterate_protocol_metadata.js.map +1 -1
- package/lib/factories/internal/protocols/iterate_protocol_repeated.d.ts +2 -1
- package/lib/factories/internal/protocols/iterate_protocol_repeated.js +5 -4
- package/lib/factories/internal/protocols/iterate_protocol_repeated.js.map +1 -1
- package/lib/messages/IProtocolMap.d.ts +5 -0
- package/lib/messages/IProtocolMap.js +3 -0
- package/lib/messages/IProtocolMap.js.map +1 -0
- package/lib/messages/IProtocolProperty.d.ts +2 -1
- package/lib/metadata/Metadata.d.ts +1 -0
- package/lib/metadata/Metadata.js +145 -51
- package/lib/metadata/Metadata.js.map +1 -1
- package/lib/programmers/AssertProgrammer.js +1 -1
- package/lib/programmers/AssertProgrammer.js.map +1 -1
- package/lib/programmers/CheckerProgrammer.d.ts +1 -0
- package/lib/programmers/CheckerProgrammer.js +147 -138
- package/lib/programmers/CheckerProgrammer.js.map +1 -1
- package/lib/programmers/MessageProgrammer.js +7 -2
- package/lib/programmers/MessageProgrammer.js.map +1 -1
- package/lib/programmers/ValidateProgrammer.js +1 -1
- package/lib/programmers/ValidateProgrammer.js.map +1 -1
- package/lib/programmers/helpers/UnionExplorer.d.ts +23 -29
- package/lib/programmers/helpers/UnionExplorer.js +29 -41
- package/lib/programmers/helpers/UnionExplorer.js.map +1 -1
- package/lib/programmers/internal/application_array.js +29 -27
- package/lib/programmers/internal/application_array.js.map +1 -1
- package/lib/programmers/internal/application_object.js +96 -31
- package/lib/programmers/internal/application_object.js.map +1 -1
- package/lib/programmers/internal/application_schema.js +28 -136
- package/lib/programmers/internal/application_schema.js.map +1 -1
- package/lib/programmers/internal/application_tuple.js +3 -2
- package/lib/programmers/internal/application_tuple.js.map +1 -1
- package/lib/programmers/internal/check_array.js +4 -32
- package/lib/programmers/internal/check_array.js.map +1 -1
- package/lib/programmers/internal/check_array_length.d.ts +1 -0
- package/lib/programmers/internal/check_array_length.js +47 -0
- package/lib/programmers/internal/check_array_length.js.map +1 -0
- package/lib/programmers/internal/check_union_array_like.d.ts +21 -0
- package/lib/programmers/internal/check_union_array_like.js +83 -0
- package/lib/programmers/internal/check_union_array_like.js.map +1 -0
- package/lib/programmers/internal/check_union_tuple.d.ts +1 -0
- package/lib/programmers/internal/check_union_tuple.js +11 -0
- package/lib/programmers/internal/check_union_tuple.js.map +1 -0
- package/lib/schemas/IJsonComponents.d.ts +4 -2
- package/lib/schemas/IJsonSchema.d.ts +2 -0
- package/package.json +4 -4
- package/src/IValidation.ts +21 -21
- package/src/Primitive.ts +82 -82
- package/src/TypeGuardError.ts +36 -36
- package/src/executable/internal/CommandParser.ts +15 -15
- package/src/executable/internal/TypiaSetupWizard.ts +30 -21
- package/src/executable/typia.ts +48 -46
- package/src/factories/CommentFactory.ts +10 -10
- package/src/factories/ExpressionFactory.ts +66 -66
- package/src/factories/IdentifierFactory.ts +72 -72
- package/src/factories/LiteralFactory.ts +44 -44
- package/src/factories/StatementFactory.ts +60 -60
- package/src/factories/TemplateFactory.ts +56 -56
- package/src/factories/TypeFactory.ts +101 -101
- package/src/factories/ValueFactory.ts +12 -12
- package/src/factories/internal/protocols/ProtocolMetadataUtil.ts +20 -0
- package/src/factories/internal/protocols/iterate_protocol_map.ts +9 -3
- package/src/factories/internal/protocols/iterate_protocol_metadata.ts +17 -4
- package/src/factories/internal/protocols/iterate_protocol_repeated.ts +14 -5
- package/src/functional/$every.ts +11 -11
- package/src/functional/$guard.ts +35 -35
- package/src/functional/$is_email.ts +5 -5
- package/src/functional/$is_ipv4.ts +5 -5
- package/src/functional/$is_ipv6.ts +5 -5
- package/src/functional/$is_url.ts +5 -5
- package/src/functional/$is_uuid.ts +5 -5
- package/src/functional/$join.ts +50 -50
- package/src/functional/$report.ts +15 -15
- package/src/functional/$rest.ts +3 -3
- package/src/functional/$string.ts +37 -37
- package/src/functional/$tail.ts +6 -6
- package/src/index.ts +4 -4
- package/src/messages/IProtocolMap.ts +5 -0
- package/src/messages/IProtocolProperty.ts +3 -1
- package/src/metadata/IJsDocTagInfo.ts +10 -10
- package/src/metadata/IMetadata.ts +25 -25
- package/src/metadata/IMetadataApplication.ts +7 -7
- package/src/metadata/IMetadataConstant.ts +16 -16
- package/src/metadata/IMetadataEntry.ts +6 -6
- package/src/metadata/IMetadataObject.ts +29 -29
- package/src/metadata/IMetadataProperty.ts +11 -11
- package/src/metadata/Metadata.ts +64 -7
- package/src/metadata/MetadataConstant.ts +3 -3
- package/src/metadata/MetadataObject.ts +131 -131
- package/src/metadata/MetadataProperty.ts +64 -64
- package/src/programmers/ApplicationProgrammer.ts +55 -55
- package/src/programmers/AssertProgrammer.ts +1 -1
- package/src/programmers/CheckerProgrammer.ts +252 -200
- package/src/programmers/FeatureProgrammer.ts +327 -327
- package/src/programmers/MessageProgrammer.ts +9 -2
- package/src/programmers/ValidateProgrammer.ts +1 -1
- package/src/programmers/helpers/AtomicPredicator.ts +15 -15
- package/src/programmers/helpers/FunctionImporeter.ts +31 -31
- package/src/programmers/helpers/IExpressionEntry.ts +10 -10
- package/src/programmers/helpers/StringifyJoinder.ts +111 -111
- package/src/programmers/helpers/StringifyPredicator.ts +18 -18
- package/src/programmers/helpers/UnionExplorer.ts +274 -437
- package/src/programmers/helpers/UnionPredicator.ts +81 -81
- package/src/programmers/internal/application_array.ts +47 -45
- package/src/programmers/internal/application_boolean.ts +17 -17
- package/src/programmers/internal/application_constant.ts +29 -29
- package/src/programmers/internal/application_default_string.ts +32 -32
- package/src/programmers/internal/application_native.ts +29 -29
- package/src/programmers/internal/application_number.ts +76 -76
- package/src/programmers/internal/application_object.ts +153 -103
- package/src/programmers/internal/application_schema.ts +15 -68
- package/src/programmers/internal/application_string.ts +49 -49
- package/src/programmers/internal/application_templates.ts +27 -27
- package/src/programmers/internal/application_tuple.ts +29 -25
- package/src/programmers/internal/check_array.ts +22 -44
- package/src/programmers/internal/check_array_length.ts +45 -0
- package/src/programmers/internal/check_dynamic_properties.ts +146 -146
- package/src/programmers/internal/check_everything.ts +25 -25
- package/src/programmers/internal/check_length.ts +46 -46
- package/src/programmers/internal/check_native.ts +9 -9
- package/src/programmers/internal/check_object.ts +42 -42
- package/src/programmers/internal/check_string.ts +24 -24
- package/src/programmers/internal/check_string_tags.ts +63 -63
- package/src/programmers/internal/check_template.ts +50 -50
- package/src/programmers/internal/check_union_array_like.ts +242 -0
- package/src/programmers/internal/check_union_tuple.ts +33 -0
- package/src/programmers/internal/decode_union_object.ts +73 -73
- package/src/programmers/internal/feature_object_entries.ts +49 -49
- package/src/programmers/internal/metadata_to_pattern.ts +31 -31
- package/src/programmers/internal/stringify_dynamic_properties.ts +164 -164
- package/src/programmers/internal/stringify_native.ts +8 -8
- package/src/programmers/internal/stringify_regular_properties.ts +81 -81
- package/src/programmers/internal/template_to_pattern.ts +15 -15
- package/src/schemas/IJsonApplication.ts +9 -9
- package/src/schemas/IJsonComponents.ts +26 -24
- package/src/schemas/IJsonSchema.ts +2 -0
- package/src/transform.ts +20 -20
- package/src/transformers/ExpressionWithArgumentTransformer.ts +66 -66
- package/src/transformers/FileTransformer.ts +49 -49
- package/src/transformers/IProject.ts +11 -11
- package/src/transformers/NodeTransformer.ts +19 -19
- package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +1 -0
- package/src/transformers/features/miscellaneous/MetadataTransformer.ts +55 -55
- package/src/transformers/features/parsers/AssertParseTransformer.ts +36 -36
- package/src/transformers/features/parsers/CreateAssertParseTransformer.ts +32 -32
- package/src/transformers/features/parsers/CreateIsParseTransformer.ts +32 -32
- package/src/transformers/features/parsers/CreateValidateParseTransformer.ts +32 -32
- package/src/transformers/features/parsers/IsParseTransformer.ts +36 -36
- package/src/transformers/features/parsers/ValidateParseTransformer.ts +36 -36
- package/src/transformers/features/stringifiers/AssertStringifyTransformer.ts +38 -38
- package/src/transformers/features/stringifiers/CreateAssertStringifyTransformer.ts +32 -32
- package/src/transformers/features/stringifiers/CreateIsStringifyTransformer.ts +32 -32
- package/src/transformers/features/stringifiers/CreateStringifyTransformer.ts +31 -31
- package/src/transformers/features/stringifiers/CreateValidateStringifyProgrammer.ts +32 -32
- package/src/transformers/features/stringifiers/IsStringifyTransformer.ts +38 -38
- package/src/transformers/features/stringifiers/ValidateStringifyTransformer.ts +38 -38
- package/src/transformers/features/validators/AssertTransformer.ts +43 -43
- package/src/transformers/features/validators/CreateAssertTransformer.ts +35 -35
- package/src/transformers/features/validators/CreateIsTransformer.ts +35 -35
- package/src/transformers/features/validators/CreateValidateTransformer.ts +35 -35
- package/src/transformers/features/validators/IsTransformer.ts +43 -43
- package/src/transformers/features/validators/ValidateTransformer.ts +43 -43
- package/src/typings/Atomic.ts +17 -17
- package/src/typings/ClassProperties.ts +5 -5
- package/src/typings/OmitNever.ts +3 -3
- package/src/typings/SpecialFields.ts +3 -3
- package/src/typings/Writable.ts +11 -11
- package/src/utils/ArrayUtil.ts +49 -49
- package/src/utils/Escaper.ts +50 -50
- package/src/utils/MapUtil.ts +14 -14
- package/src/utils/PatternUtil.ts +30 -30
- package/src/utils/Singleton.ts +17 -17
|
@@ -1,103 +1,153 @@
|
|
|
1
|
-
import { CommentFactory } from "../../factories/CommentFactory";
|
|
2
|
-
|
|
3
|
-
import { IJsDocTagInfo } from "../../metadata/IJsDocTagInfo";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
(
|
|
20
|
-
(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
components.schemas[id]
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
property.value.
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
"x-typia-
|
|
60
|
-
? property.
|
|
61
|
-
: undefined,
|
|
62
|
-
"x-typia-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
)
|
|
75
|
-
additionalProperties.
|
|
76
|
-
else
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
1
|
+
import { CommentFactory } from "../../factories/CommentFactory";
|
|
2
|
+
|
|
3
|
+
import { IJsDocTagInfo } from "../../metadata/IJsDocTagInfo";
|
|
4
|
+
import { Metadata } from "../../metadata/Metadata";
|
|
5
|
+
import { MetadataObject } from "../../metadata/MetadataObject";
|
|
6
|
+
import { IJsonComponents } from "../../schemas/IJsonComponents";
|
|
7
|
+
|
|
8
|
+
import { PatternUtil } from "../../utils/PatternUtil";
|
|
9
|
+
|
|
10
|
+
import { IJsonSchema } from "../../module";
|
|
11
|
+
import { ApplicationProgrammer } from "../ApplicationProgrammer";
|
|
12
|
+
import { application_schema } from "./application_schema";
|
|
13
|
+
import { metadata_to_pattern } from "./metadata_to_pattern";
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
export const application_object =
|
|
19
|
+
(options: ApplicationProgrammer.IOptions) =>
|
|
20
|
+
(components: IJsonComponents) =>
|
|
21
|
+
(id: string, obj: MetadataObject, nullable: boolean): void => {
|
|
22
|
+
// TEMPORARY ASSIGNMENT
|
|
23
|
+
if (components.schemas[id] !== undefined) return;
|
|
24
|
+
components.schemas[id] = {} as any;
|
|
25
|
+
|
|
26
|
+
// ITERATE PROPERTIES
|
|
27
|
+
const properties: Record<string, any> = {};
|
|
28
|
+
const extraMeta: ISuperfluous = {
|
|
29
|
+
patternProperties: {},
|
|
30
|
+
additionalProperties: undefined,
|
|
31
|
+
};
|
|
32
|
+
const required: string[] = [];
|
|
33
|
+
|
|
34
|
+
for (const property of obj.properties) {
|
|
35
|
+
if (
|
|
36
|
+
property.value.functional === true &&
|
|
37
|
+
property.value.nullable === false &&
|
|
38
|
+
property.value.required === true &&
|
|
39
|
+
property.value.size() === 0
|
|
40
|
+
)
|
|
41
|
+
continue;
|
|
42
|
+
|
|
43
|
+
const key: string | null = property.key.getSoleLiteral();
|
|
44
|
+
const schema: IJsonSchema | null = application_schema(options)(
|
|
45
|
+
components,
|
|
46
|
+
)(true)(property.value, {
|
|
47
|
+
deprecated:
|
|
48
|
+
!!property.jsDocTags.find(
|
|
49
|
+
(tag) => tag.name === "deprecated",
|
|
50
|
+
) || undefined,
|
|
51
|
+
title: (() => {
|
|
52
|
+
const info: IJsDocTagInfo | undefined =
|
|
53
|
+
property.jsDocTags.find((tag) => tag.name === "title");
|
|
54
|
+
return info?.text?.length
|
|
55
|
+
? CommentFactory.generate(info.text)
|
|
56
|
+
: undefined;
|
|
57
|
+
})(),
|
|
58
|
+
description: property.description,
|
|
59
|
+
"x-typia-metaTags": property.tags.length
|
|
60
|
+
? property.tags
|
|
61
|
+
: undefined,
|
|
62
|
+
"x-typia-jsDocTags": property.jsDocTags.length
|
|
63
|
+
? property.jsDocTags
|
|
64
|
+
: undefined,
|
|
65
|
+
"x-typia-required": property.value.required,
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
if (schema === null) continue;
|
|
69
|
+
else if (key !== null) {
|
|
70
|
+
properties[key] = schema;
|
|
71
|
+
if (property.value.required === true) required.push(key);
|
|
72
|
+
} else {
|
|
73
|
+
const pattern: string = metadata_to_pattern(true)(property.key);
|
|
74
|
+
if (pattern === PatternUtil.STRING)
|
|
75
|
+
extraMeta.additionalProperties = [property.value, schema];
|
|
76
|
+
else
|
|
77
|
+
extraMeta.patternProperties[pattern] = [
|
|
78
|
+
property.value,
|
|
79
|
+
schema,
|
|
80
|
+
];
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const extraProps = {
|
|
85
|
+
additionalProperties: extraMeta.additionalProperties?.[1],
|
|
86
|
+
patternProperties: (() => {
|
|
87
|
+
if (Object.keys(extraMeta.patternProperties).length === 0)
|
|
88
|
+
return undefined;
|
|
89
|
+
const output: Record<string, IJsonSchema> = {};
|
|
90
|
+
for (const [key, value] of Object.entries(
|
|
91
|
+
extraMeta.patternProperties,
|
|
92
|
+
))
|
|
93
|
+
output[key] = value[1];
|
|
94
|
+
return output;
|
|
95
|
+
})(),
|
|
96
|
+
};
|
|
97
|
+
const schema: IJsonComponents.IObject = {
|
|
98
|
+
$id:
|
|
99
|
+
options.purpose === "ajv"
|
|
100
|
+
? options.prefix + "/" + id
|
|
101
|
+
: undefined,
|
|
102
|
+
$recursiveAnchor:
|
|
103
|
+
(options.purpose === "ajv" && obj.recursive) || undefined,
|
|
104
|
+
type: "object",
|
|
105
|
+
properties,
|
|
106
|
+
nullable,
|
|
107
|
+
required: required.length ? required : undefined,
|
|
108
|
+
description: obj.description,
|
|
109
|
+
"x-typia-jsDocTags": obj.jsDocTags,
|
|
110
|
+
...(options.purpose === "ajv"
|
|
111
|
+
? extraProps
|
|
112
|
+
: {
|
|
113
|
+
// swagger can't express patternProperties
|
|
114
|
+
"x-typia-additionalProperties":
|
|
115
|
+
extraProps.additionalProperties,
|
|
116
|
+
"x-typia-patternProperties": extraProps.patternProperties,
|
|
117
|
+
additionalProperties:
|
|
118
|
+
join(options)(components)(extraMeta),
|
|
119
|
+
}),
|
|
120
|
+
};
|
|
121
|
+
components.schemas[id] = schema;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const join =
|
|
125
|
+
(options: ApplicationProgrammer.IOptions) =>
|
|
126
|
+
(components: IJsonComponents) =>
|
|
127
|
+
(extra: ISuperfluous): IJsonSchema | undefined => {
|
|
128
|
+
// LIST UP METADATA
|
|
129
|
+
const elements: [Metadata, IJsonSchema][] = Object.values(
|
|
130
|
+
extra.patternProperties || {},
|
|
131
|
+
);
|
|
132
|
+
if (extra.additionalProperties)
|
|
133
|
+
elements.push(extra.additionalProperties);
|
|
134
|
+
|
|
135
|
+
// SHORT RETURN
|
|
136
|
+
if (elements.length === 0) return undefined;
|
|
137
|
+
else if (elements.length === 1) return elements[0]![1]!;
|
|
138
|
+
|
|
139
|
+
// MERGE METADATA AND GENERATE VULNERABLE SCHEMA
|
|
140
|
+
const meta: Metadata = elements
|
|
141
|
+
.map((tuple) => tuple[0])
|
|
142
|
+
.reduce((x, y) => Metadata.merge(x, y));
|
|
143
|
+
return (
|
|
144
|
+
application_schema(options)(components)(true)(meta, {
|
|
145
|
+
"x-typia-required": false,
|
|
146
|
+
}) ?? undefined
|
|
147
|
+
);
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
interface ISuperfluous {
|
|
151
|
+
additionalProperties?: [Metadata, IJsonSchema];
|
|
152
|
+
patternProperties: Record<string, [Metadata, IJsonSchema]>;
|
|
153
|
+
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { Metadata } from "../../metadata/Metadata";
|
|
2
|
-
import { MetadataConstant } from "../../metadata/MetadataConstant";
|
|
3
2
|
import { IJsonComponents } from "../../schemas/IJsonComponents";
|
|
4
3
|
import { IJsonSchema } from "../../schemas/IJsonSchema";
|
|
5
4
|
|
|
6
|
-
import { ArrayUtil } from "../../utils/ArrayUtil";
|
|
7
5
|
import { NameEncoder } from "../../utils/NameEncoder";
|
|
8
6
|
|
|
9
7
|
import { ApplicationProgrammer } from "../ApplicationProgrammer";
|
|
@@ -75,7 +73,7 @@ export const application_schema =
|
|
|
75
73
|
// ARRAY
|
|
76
74
|
for (const schema of meta.arrays.values())
|
|
77
75
|
union.push(
|
|
78
|
-
application_array(options)(components)(
|
|
76
|
+
application_array(options)(components)()(
|
|
79
77
|
schema,
|
|
80
78
|
meta.nullable,
|
|
81
79
|
attribute,
|
|
@@ -83,31 +81,33 @@ export const application_schema =
|
|
|
83
81
|
);
|
|
84
82
|
|
|
85
83
|
// TUPLE
|
|
86
|
-
for (const items of meta.tuples)
|
|
87
|
-
|
|
84
|
+
for (const items of meta.tuples) {
|
|
85
|
+
const tuple: IJsonSchema.ITuple = application_tuple(options)(
|
|
86
|
+
components,
|
|
87
|
+
)(items, meta.nullable, attribute);
|
|
88
|
+
if (options.purpose === "swagger" && items.length === 0)
|
|
89
|
+
throw new Error(
|
|
90
|
+
"Error on typia.application(): swagger does not support zero length tuple type.",
|
|
91
|
+
);
|
|
92
|
+
else if (
|
|
88
93
|
options.purpose === "ajv" &&
|
|
89
|
-
items.
|
|
94
|
+
!items[items.length - 1]?.rest
|
|
90
95
|
)
|
|
91
|
-
union.push(
|
|
92
|
-
application_tuple(options)(components)(
|
|
93
|
-
items,
|
|
94
|
-
meta.nullable,
|
|
95
|
-
attribute,
|
|
96
|
-
),
|
|
97
|
-
);
|
|
96
|
+
union.push(tuple);
|
|
98
97
|
else {
|
|
99
98
|
// SWAGGER DOES NOT SUPPORT TUPLE TYPE YET
|
|
100
99
|
const merged: Metadata = items.reduce((x, y) =>
|
|
101
|
-
|
|
100
|
+
Metadata.merge(x, y),
|
|
102
101
|
);
|
|
103
102
|
union.push(
|
|
104
|
-
application_array(options)(components)(
|
|
103
|
+
application_array(options)(components)(tuple)(
|
|
105
104
|
merged,
|
|
106
105
|
merged?.nullable || false,
|
|
107
106
|
attribute,
|
|
108
107
|
),
|
|
109
108
|
);
|
|
110
109
|
}
|
|
110
|
+
}
|
|
111
111
|
|
|
112
112
|
// NATIVES
|
|
113
113
|
for (const native of meta.natives)
|
|
@@ -175,57 +175,4 @@ const recursive = (
|
|
|
175
175
|
...attribute,
|
|
176
176
|
});
|
|
177
177
|
|
|
178
|
-
/**
|
|
179
|
-
* @internal
|
|
180
|
-
* @todo: not perfect
|
|
181
|
-
*/
|
|
182
|
-
function merge_metadata(x: Metadata, y: Metadata): Metadata {
|
|
183
|
-
const output: Metadata = Metadata.create({
|
|
184
|
-
any: x.any || y.any,
|
|
185
|
-
nullable: x.nullable || y.nullable,
|
|
186
|
-
required: x.required && y.required,
|
|
187
|
-
functional: x.functional || y.functional,
|
|
188
|
-
|
|
189
|
-
resolved:
|
|
190
|
-
x.resolved !== null && y.resolved !== null
|
|
191
|
-
? merge_metadata(x.resolved, y.resolved)
|
|
192
|
-
: x.resolved || y.resolved,
|
|
193
|
-
atomics: [...new Set([...x.atomics, ...y.atomics])],
|
|
194
|
-
constants: [...x.constants],
|
|
195
|
-
templates: x.templates.slice(),
|
|
196
|
-
|
|
197
|
-
rest: null,
|
|
198
|
-
arrays: x.arrays.slice(),
|
|
199
|
-
tuples: x.tuples.slice(),
|
|
200
|
-
objects: x.objects.slice(),
|
|
201
|
-
|
|
202
|
-
natives: [...new Set([...x.natives, ...y.natives])],
|
|
203
|
-
sets: x.sets.slice(),
|
|
204
|
-
maps: x.maps.slice(),
|
|
205
|
-
});
|
|
206
|
-
for (const constant of y.constants) {
|
|
207
|
-
const target: MetadataConstant = ArrayUtil.take(
|
|
208
|
-
output.constants,
|
|
209
|
-
(elem) => elem.type === constant.type,
|
|
210
|
-
() => ({
|
|
211
|
-
type: constant.type,
|
|
212
|
-
values: [],
|
|
213
|
-
}),
|
|
214
|
-
);
|
|
215
|
-
for (const value of constant.values)
|
|
216
|
-
ArrayUtil.add(target.values, value);
|
|
217
|
-
}
|
|
218
|
-
for (const array of y.arrays)
|
|
219
|
-
ArrayUtil.set(output.arrays, array, (elem) => elem.getName());
|
|
220
|
-
for (const obj of y.objects)
|
|
221
|
-
ArrayUtil.set(output.objects, obj, (elem) => elem.name);
|
|
222
|
-
|
|
223
|
-
if (x.rest !== null)
|
|
224
|
-
ArrayUtil.set(output.arrays, x.rest, (elem) => elem.getName());
|
|
225
|
-
if (y.rest !== null)
|
|
226
|
-
ArrayUtil.set(output.arrays, y.rest, (elem) => elem.getName());
|
|
227
|
-
|
|
228
|
-
return output;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
178
|
const NO_BIGINT = "Error on typia.application(): does not allow bigint type.";
|
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
import { Metadata } from "../../metadata/Metadata";
|
|
2
|
-
import { IJsonSchema } from "../../schemas/IJsonSchema";
|
|
3
|
-
|
|
4
|
-
import { application_default_string } from "./application_default_string";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @internal
|
|
8
|
-
*/
|
|
9
|
-
export const application_string = (
|
|
10
|
-
meta: Metadata,
|
|
11
|
-
attribute: IJsonSchema.IAttribute,
|
|
12
|
-
): IJsonSchema.IString => {
|
|
13
|
-
const output: IJsonSchema.IString = {
|
|
14
|
-
type: "string",
|
|
15
|
-
nullable: meta.nullable,
|
|
16
|
-
...attribute,
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
// FORMAT TAG OF METADATA
|
|
20
|
-
const formatJsdocTag = attribute["x-typia-jsDocTags"]?.find(
|
|
21
|
-
(tag) => tag.name === "format",
|
|
22
|
-
);
|
|
23
|
-
if (formatJsdocTag?.text?.length)
|
|
24
|
-
output.format = formatJsdocTag?.text.map((t) => t.text).join(" ");
|
|
25
|
-
|
|
26
|
-
// REGULAR TAGS COMPATIBLE WITH JSON-SCHEMA
|
|
27
|
-
for (const tag of attribute["x-typia-metaTags"] || []) {
|
|
28
|
-
// RANGE
|
|
29
|
-
if (tag.kind === "minLength") output.minLength = tag.value;
|
|
30
|
-
else if (tag.kind === "maxLength") output.maxLength = tag.value;
|
|
31
|
-
else if (tag.kind === "length") {
|
|
32
|
-
if (tag.minimum !== undefined)
|
|
33
|
-
output.minLength =
|
|
34
|
-
tag.minimum.value + (tag.minimum.include ? 0 : 1);
|
|
35
|
-
if (tag.maximum !== undefined)
|
|
36
|
-
output.maxLength =
|
|
37
|
-
tag.maximum.value - (tag.maximum.include ? 0 : 1);
|
|
38
|
-
}
|
|
39
|
-
// FORMAT AND PATTERN
|
|
40
|
-
else if (tag.kind === "format") output.format = tag.value;
|
|
41
|
-
else if (tag.kind === "pattern") output.pattern = tag.value;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// DEFAULT CONFIGURATION
|
|
45
|
-
output.default = application_default_string(meta, attribute)(output);
|
|
46
|
-
|
|
47
|
-
// RETURNS
|
|
48
|
-
return output;
|
|
49
|
-
};
|
|
1
|
+
import { Metadata } from "../../metadata/Metadata";
|
|
2
|
+
import { IJsonSchema } from "../../schemas/IJsonSchema";
|
|
3
|
+
|
|
4
|
+
import { application_default_string } from "./application_default_string";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export const application_string = (
|
|
10
|
+
meta: Metadata,
|
|
11
|
+
attribute: IJsonSchema.IAttribute,
|
|
12
|
+
): IJsonSchema.IString => {
|
|
13
|
+
const output: IJsonSchema.IString = {
|
|
14
|
+
type: "string",
|
|
15
|
+
nullable: meta.nullable,
|
|
16
|
+
...attribute,
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
// FORMAT TAG OF METADATA
|
|
20
|
+
const formatJsdocTag = attribute["x-typia-jsDocTags"]?.find(
|
|
21
|
+
(tag) => tag.name === "format",
|
|
22
|
+
);
|
|
23
|
+
if (formatJsdocTag?.text?.length)
|
|
24
|
+
output.format = formatJsdocTag?.text.map((t) => t.text).join(" ");
|
|
25
|
+
|
|
26
|
+
// REGULAR TAGS COMPATIBLE WITH JSON-SCHEMA
|
|
27
|
+
for (const tag of attribute["x-typia-metaTags"] || []) {
|
|
28
|
+
// RANGE
|
|
29
|
+
if (tag.kind === "minLength") output.minLength = tag.value;
|
|
30
|
+
else if (tag.kind === "maxLength") output.maxLength = tag.value;
|
|
31
|
+
else if (tag.kind === "length") {
|
|
32
|
+
if (tag.minimum !== undefined)
|
|
33
|
+
output.minLength =
|
|
34
|
+
tag.minimum.value + (tag.minimum.include ? 0 : 1);
|
|
35
|
+
if (tag.maximum !== undefined)
|
|
36
|
+
output.maxLength =
|
|
37
|
+
tag.maximum.value - (tag.maximum.include ? 0 : 1);
|
|
38
|
+
}
|
|
39
|
+
// FORMAT AND PATTERN
|
|
40
|
+
else if (tag.kind === "format") output.format = tag.value;
|
|
41
|
+
else if (tag.kind === "pattern") output.pattern = tag.value;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// DEFAULT CONFIGURATION
|
|
45
|
+
output.default = application_default_string(meta, attribute)(output);
|
|
46
|
+
|
|
47
|
+
// RETURNS
|
|
48
|
+
return output;
|
|
49
|
+
};
|
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
import { Metadata } from "../../metadata/Metadata";
|
|
2
|
-
import { IJsonSchema } from "../../schemas/IJsonSchema";
|
|
3
|
-
|
|
4
|
-
import { application_default_string } from "./application_default_string";
|
|
5
|
-
import { metadata_to_pattern } from "./metadata_to_pattern";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @internal
|
|
9
|
-
*/
|
|
10
|
-
export const application_templates = (
|
|
11
|
-
meta: Metadata,
|
|
12
|
-
attribute: IJsonSchema.IAttribute,
|
|
13
|
-
): IJsonSchema.IString => {
|
|
14
|
-
// CONSTRUCT PATTERN
|
|
15
|
-
const output: IJsonSchema.IString = {
|
|
16
|
-
type: "string",
|
|
17
|
-
nullable: meta.nullable,
|
|
18
|
-
...attribute,
|
|
19
|
-
};
|
|
20
|
-
output.pattern = metadata_to_pattern(true)(meta);
|
|
21
|
-
|
|
22
|
-
// DEFAULT VALUE
|
|
23
|
-
output.default = application_default_string(meta, attribute)(output);
|
|
24
|
-
|
|
25
|
-
// RETURNS
|
|
26
|
-
return output;
|
|
27
|
-
};
|
|
1
|
+
import { Metadata } from "../../metadata/Metadata";
|
|
2
|
+
import { IJsonSchema } from "../../schemas/IJsonSchema";
|
|
3
|
+
|
|
4
|
+
import { application_default_string } from "./application_default_string";
|
|
5
|
+
import { metadata_to_pattern } from "./metadata_to_pattern";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export const application_templates = (
|
|
11
|
+
meta: Metadata,
|
|
12
|
+
attribute: IJsonSchema.IAttribute,
|
|
13
|
+
): IJsonSchema.IString => {
|
|
14
|
+
// CONSTRUCT PATTERN
|
|
15
|
+
const output: IJsonSchema.IString = {
|
|
16
|
+
type: "string",
|
|
17
|
+
nullable: meta.nullable,
|
|
18
|
+
...attribute,
|
|
19
|
+
};
|
|
20
|
+
output.pattern = metadata_to_pattern(true)(meta);
|
|
21
|
+
|
|
22
|
+
// DEFAULT VALUE
|
|
23
|
+
output.default = application_default_string(meta, attribute)(output);
|
|
24
|
+
|
|
25
|
+
// RETURNS
|
|
26
|
+
return output;
|
|
27
|
+
};
|
|
@@ -1,25 +1,29 @@
|
|
|
1
|
-
import { Metadata } from "../../metadata/Metadata";
|
|
2
|
-
import { IJsonComponents } from "../../schemas/IJsonComponents";
|
|
3
|
-
import { IJsonSchema } from "../../schemas/IJsonSchema";
|
|
4
|
-
|
|
5
|
-
import { ApplicationProgrammer } from "../ApplicationProgrammer";
|
|
6
|
-
import { application_schema } from "./application_schema";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @internal
|
|
10
|
-
*/
|
|
11
|
-
export const application_tuple =
|
|
12
|
-
(options: ApplicationProgrammer.IOptions) =>
|
|
13
|
-
(components: IJsonComponents) =>
|
|
14
|
-
(
|
|
15
|
-
items: Array<Metadata>,
|
|
16
|
-
nullable: boolean,
|
|
17
|
-
attribute: IJsonSchema.IAttribute,
|
|
18
|
-
): IJsonSchema.ITuple => ({
|
|
19
|
-
type: "array",
|
|
20
|
-
items: items.map((meta) =>
|
|
21
|
-
application_schema(options)(components)(false)(meta,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
1
|
+
import { Metadata } from "../../metadata/Metadata";
|
|
2
|
+
import { IJsonComponents } from "../../schemas/IJsonComponents";
|
|
3
|
+
import { IJsonSchema } from "../../schemas/IJsonSchema";
|
|
4
|
+
|
|
5
|
+
import { ApplicationProgrammer } from "../ApplicationProgrammer";
|
|
6
|
+
import { application_schema } from "./application_schema";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export const application_tuple =
|
|
12
|
+
(options: ApplicationProgrammer.IOptions) =>
|
|
13
|
+
(components: IJsonComponents) =>
|
|
14
|
+
(
|
|
15
|
+
items: Array<Metadata>,
|
|
16
|
+
nullable: boolean,
|
|
17
|
+
attribute: IJsonSchema.IAttribute,
|
|
18
|
+
): IJsonSchema.ITuple => ({
|
|
19
|
+
type: "array",
|
|
20
|
+
items: items.map((meta, i) =>
|
|
21
|
+
application_schema(options)(components)(false)(meta.rest ?? meta, {
|
|
22
|
+
...attribute,
|
|
23
|
+
"x-typia-rest":
|
|
24
|
+
i === items.length - 1 ? meta.rest !== null : undefined,
|
|
25
|
+
}),
|
|
26
|
+
),
|
|
27
|
+
nullable,
|
|
28
|
+
...attribute,
|
|
29
|
+
});
|
|
@@ -1,44 +1,22 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { ExpressionFactory } from "../../factories/ExpressionFactory";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
ts.factory.createLessThanEquals(
|
|
24
|
-
ts.factory.createNumericLiteral(tag.value),
|
|
25
|
-
IdentifierFactory.join(input, "length"),
|
|
26
|
-
),
|
|
27
|
-
);
|
|
28
|
-
else if (tag.kind === "maxItems")
|
|
29
|
-
conditions.push(
|
|
30
|
-
ts.factory.createGreaterThanEquals(
|
|
31
|
-
ts.factory.createNumericLiteral(tag.value),
|
|
32
|
-
IdentifierFactory.join(input, "length"),
|
|
33
|
-
),
|
|
34
|
-
);
|
|
35
|
-
else if (tag.kind === "items")
|
|
36
|
-
check_length(
|
|
37
|
-
conditions,
|
|
38
|
-
IdentifierFactory.join(input, "length"),
|
|
39
|
-
tag,
|
|
40
|
-
);
|
|
41
|
-
|
|
42
|
-
// COMBINATION
|
|
43
|
-
return conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y));
|
|
44
|
-
}
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { ExpressionFactory } from "../../factories/ExpressionFactory";
|
|
4
|
+
|
|
5
|
+
import { IMetadataTag } from "../../metadata/IMetadataTag";
|
|
6
|
+
|
|
7
|
+
import { check_array_length } from "./check_array_length";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export function check_array(
|
|
13
|
+
input: ts.Expression,
|
|
14
|
+
tagList: IMetadataTag[],
|
|
15
|
+
): ts.Expression {
|
|
16
|
+
const conditions: ts.Expression[] = [ExpressionFactory.isArray(input)];
|
|
17
|
+
|
|
18
|
+
const length: ts.Expression | null = check_array_length(input, tagList);
|
|
19
|
+
if (length !== null) conditions.push(length);
|
|
20
|
+
|
|
21
|
+
return conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y));
|
|
22
|
+
}
|