typia 3.5.0-dev.20221219 → 3.5.0-dev.20221222
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 +58 -16
- package/lib/executable/internal/TypiaSetupWizard.js +2 -1
- package/lib/executable/internal/TypiaSetupWizard.js.map +1 -1
- package/lib/factories/MetadataCollection.d.ts +1 -9
- package/lib/factories/MetadataCollection.js +2 -77
- package/lib/factories/MetadataCollection.js.map +1 -1
- package/lib/factories/MetadataTagFactory.js +4 -1
- package/lib/factories/MetadataTagFactory.js.map +1 -1
- package/lib/factories/ProtocolFactory.d.ts +0 -1
- package/lib/factories/ProtocolFactory.js +0 -6
- package/lib/factories/ProtocolFactory.js.map +1 -1
- package/lib/factories/internal/metadata/iterate_metadata_object.js +4 -2
- package/lib/factories/internal/metadata/iterate_metadata_object.js.map +1 -1
- package/lib/factories/internal/protocols/iterate_protocol_main.js +2 -3
- package/lib/factories/internal/protocols/iterate_protocol_main.js.map +1 -1
- package/lib/factories/internal/protocols/iterate_protocol_map.js +3 -4
- package/lib/factories/internal/protocols/iterate_protocol_map.js.map +1 -1
- package/lib/factories/internal/protocols/iterate_protocol_metadata.js +2 -0
- package/lib/factories/internal/protocols/iterate_protocol_metadata.js.map +1 -1
- package/lib/factories/internal/protocols/iterate_protocol_repeated.js +3 -4
- package/lib/factories/internal/protocols/iterate_protocol_repeated.js.map +1 -1
- package/lib/factories/internal/protocols/iterate_protocol_tuple.js +3 -4
- package/lib/factories/internal/protocols/iterate_protocol_tuple.js.map +1 -1
- package/lib/functional/$number.js +2 -9
- package/lib/functional/$number.js.map +1 -1
- package/lib/programmers/AssertParseProgrammer.js +12 -1
- package/lib/programmers/AssertParseProgrammer.js.map +1 -1
- package/lib/programmers/AssertProgrammer.js +2 -1
- package/lib/programmers/AssertProgrammer.js.map +1 -1
- package/lib/programmers/AssertStringifyProgrammer.js +13 -2
- package/lib/programmers/AssertStringifyProgrammer.js.map +1 -1
- package/lib/programmers/CheckerProgrammer.js +6 -0
- package/lib/programmers/CheckerProgrammer.js.map +1 -1
- package/lib/programmers/IsParseProgrammer.js +12 -1
- package/lib/programmers/IsParseProgrammer.js.map +1 -1
- package/lib/programmers/IsProgrammer.js +5 -2
- package/lib/programmers/IsProgrammer.js.map +1 -1
- package/lib/programmers/IsStringifyProgrammer.js +13 -2
- package/lib/programmers/IsStringifyProgrammer.js.map +1 -1
- package/lib/programmers/MessageProgrammer.js +11 -6
- package/lib/programmers/MessageProgrammer.js.map +1 -1
- package/lib/programmers/StringifyProgrammer.js +6 -1
- package/lib/programmers/StringifyProgrammer.js.map +1 -1
- package/lib/programmers/ValidateParseProgrammer.js +12 -1
- package/lib/programmers/ValidateParseProgrammer.js.map +1 -1
- package/lib/programmers/ValidateProgrammer.js +2 -1
- package/lib/programmers/ValidateProgrammer.js.map +1 -1
- package/lib/programmers/ValidateStringifyProgrammer.js +13 -2
- package/lib/programmers/ValidateStringifyProgrammer.js.map +1 -1
- package/lib/programmers/helpers/OptionPredicator.d.ts +2 -1
- package/lib/programmers/helpers/OptionPredicator.js +8 -6
- package/lib/programmers/helpers/OptionPredicator.js.map +1 -1
- package/lib/programmers/internal/application_object.js +9 -9
- package/lib/programmers/internal/application_object.js.map +1 -1
- package/lib/programmers/internal/application_schema.js +12 -6
- package/lib/programmers/internal/application_schema.js.map +1 -1
- package/lib/programmers/internal/check_bigint.d.ts +3 -0
- package/lib/programmers/internal/check_bigint.js +97 -0
- package/lib/programmers/internal/check_bigint.js.map +1 -0
- package/lib/programmers/internal/check_number.js +21 -23
- package/lib/programmers/internal/check_number.js.map +1 -1
- package/lib/schemas/IJsonSchema.d.ts +3 -5
- package/lib/transformers/ITransformOptions.d.ts +43 -2
- package/lib/transformers/features/miscellaneous/ApplicationTransformer.js +5 -3
- package/lib/transformers/features/miscellaneous/ApplicationTransformer.js.map +1 -1
- package/lib/transformers/features/stringifiers/StringifyTransformer.js +12 -1
- package/lib/transformers/features/stringifiers/StringifyTransformer.js.map +1 -1
- package/lib/utils/NameEncoder.d.ts +4 -0
- package/lib/utils/NameEncoder.js +89 -0
- package/lib/utils/NameEncoder.js.map +1 -0
- package/package.json +3 -2
- 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 +7 -3
- package/src/executable/typia.ts +46 -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/MetadataCollection.ts +2 -43
- package/src/factories/MetadataTagFactory.ts +5 -1
- package/src/factories/ProtocolFactory.ts +0 -5
- 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/metadata/iterate_metadata_object.ts +6 -3
- package/src/factories/internal/protocols/iterate_protocol_main.ts +2 -3
- package/src/factories/internal/protocols/iterate_protocol_map.ts +3 -5
- package/src/factories/internal/protocols/iterate_protocol_metadata.ts +1 -0
- package/src/factories/internal/protocols/iterate_protocol_repeated.ts +3 -6
- package/src/factories/internal/protocols/iterate_protocol_tuple.ts +3 -6
- 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/$number.ts +2 -9
- 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/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/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/AssertParseProgrammer.ts +11 -1
- package/src/programmers/AssertProgrammer.ts +3 -2
- package/src/programmers/AssertStringifyProgrammer.ts +22 -2
- package/src/programmers/CheckerProgrammer.ts +6 -0
- package/src/programmers/FeatureProgrammer.ts +327 -327
- package/src/programmers/IsParseProgrammer.ts +11 -1
- package/src/programmers/IsProgrammer.ts +5 -2
- package/src/programmers/IsStringifyProgrammer.ts +22 -2
- package/src/programmers/MessageProgrammer.ts +12 -6
- package/src/programmers/StringifyProgrammer.ts +7 -1
- package/src/programmers/ValidateParseProgrammer.ts +11 -1
- package/src/programmers/ValidateProgrammer.ts +2 -1
- package/src/programmers/ValidateStringifyProgrammer.ts +22 -2
- 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/OptionPredicator.ts +7 -10
- package/src/programmers/helpers/StringifyJoinder.ts +111 -111
- package/src/programmers/helpers/StringifyPredicator.ts +18 -18
- package/src/programmers/helpers/UnionExplorer.ts +437 -437
- package/src/programmers/helpers/UnionPredicator.ts +81 -81
- package/src/programmers/internal/application_array.ts +45 -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.ts +1 -1
- 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 +103 -103
- package/src/programmers/internal/application_schema.ts +15 -5
- 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 +25 -25
- package/src/programmers/internal/check_array.ts +44 -44
- package/src/programmers/internal/check_bigint.ts +85 -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_number.ts +45 -51
- 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/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 +24 -24
- package/src/schemas/IJsonSchema.ts +4 -6
- 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/ITransformOptions.ts +45 -2
- package/src/transformers/NodeTransformer.ts +19 -19
- package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +6 -3
- 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/StringifyTransformer.ts +11 -1
- 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/NameEncoder.ts +32 -0
- package/src/utils/PatternUtil.ts +30 -30
- package/src/utils/Singleton.ts +17 -17
- package/lib/transformers/features/miscellaneous/CreateInstanceTransformer.d.ts +0 -5
- package/lib/transformers/features/miscellaneous/CreateInstanceTransformer.js +0 -29
- package/lib/transformers/features/miscellaneous/CreateInstanceTransformer.js.map +0 -1
- package/src/transformers/features/miscellaneous/CreateInstanceTransformer.ts +0 -41
|
@@ -1,103 +1,103 @@
|
|
|
1
|
-
import { CommentFactory } from "../../factories/CommentFactory";
|
|
2
|
-
|
|
3
|
-
import { IJsDocTagInfo } from "../../metadata/IJsDocTagInfo";
|
|
4
|
-
import { MetadataObject } from "../../metadata/MetadataObject";
|
|
5
|
-
import { IJsonComponents } from "../../schemas/IJsonComponents";
|
|
6
|
-
|
|
7
|
-
import { PatternUtil } from "../../utils/PatternUtil";
|
|
8
|
-
|
|
9
|
-
import { IJsonSchema } from "../../module";
|
|
10
|
-
import { ApplicationProgrammer } from "../ApplicationProgrammer";
|
|
11
|
-
import { application_schema } from "./application_schema";
|
|
12
|
-
import { metadata_to_pattern } from "./metadata_to_pattern";
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @internal
|
|
16
|
-
*/
|
|
17
|
-
export const application_object =
|
|
18
|
-
(options: ApplicationProgrammer.IOptions) =>
|
|
19
|
-
(components: IJsonComponents) =>
|
|
20
|
-
(
|
|
21
|
-
// TEMPORARY ASSIGNMENT
|
|
22
|
-
if (components.schemas[
|
|
23
|
-
components.schemas[
|
|
24
|
-
|
|
25
|
-
// ITERATE PROPERTIES
|
|
26
|
-
const properties: Record<string, any> = {};
|
|
27
|
-
const patternProperties: Record<string, any> = {};
|
|
28
|
-
const additionalProperties: IJsonSchema[] = [];
|
|
29
|
-
const required: string[] = [];
|
|
30
|
-
|
|
31
|
-
for (const property of obj.properties) {
|
|
32
|
-
if (
|
|
33
|
-
property.value.functional === true &&
|
|
34
|
-
property.value.nullable === false &&
|
|
35
|
-
property.value.required === true &&
|
|
36
|
-
property.value.size() === 0
|
|
37
|
-
)
|
|
38
|
-
continue;
|
|
39
|
-
|
|
40
|
-
const key: string | null = property.key.getSoleLiteral();
|
|
41
|
-
const value: IJsonSchema | null = application_schema(options)(
|
|
42
|
-
components,
|
|
43
|
-
)(true)(property.value, {
|
|
44
|
-
deprecated:
|
|
45
|
-
!!property.jsDocTags.find(
|
|
46
|
-
(tag) => tag.name === "deprecated",
|
|
47
|
-
) || undefined,
|
|
48
|
-
title: (() => {
|
|
49
|
-
const info: IJsDocTagInfo | undefined =
|
|
50
|
-
property.jsDocTags.find((tag) => tag.name === "title");
|
|
51
|
-
return info?.text?.length
|
|
52
|
-
? CommentFactory.generate(info.text)
|
|
53
|
-
: undefined;
|
|
54
|
-
})(),
|
|
55
|
-
description: property.description,
|
|
56
|
-
"x-typia-metaTags": property.tags.length
|
|
57
|
-
? property.tags
|
|
58
|
-
: undefined,
|
|
59
|
-
"x-typia-jsDocTags": property.jsDocTags.length
|
|
60
|
-
? property.jsDocTags
|
|
61
|
-
: undefined,
|
|
62
|
-
"x-typia-required": property.value.required,
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
if (value === null) continue;
|
|
66
|
-
else if (key !== null) {
|
|
67
|
-
properties[key] = value;
|
|
68
|
-
if (property.value.required === true) required.push(key);
|
|
69
|
-
} else {
|
|
70
|
-
const pattern: string = metadata_to_pattern(true)(property.key);
|
|
71
|
-
if (
|
|
72
|
-
options.purpose === "swagger" ||
|
|
73
|
-
pattern === PatternUtil.STRING
|
|
74
|
-
)
|
|
75
|
-
additionalProperties.push(value);
|
|
76
|
-
else patternProperties[pattern] = value;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const schema: IJsonComponents.IObject = {
|
|
81
|
-
$id:
|
|
82
|
-
options.purpose === "ajv"
|
|
83
|
-
? options.prefix + "/" +
|
|
84
|
-
: undefined,
|
|
85
|
-
$recursiveAnchor:
|
|
86
|
-
(options.purpose === "ajv" && obj.recursive) || undefined,
|
|
87
|
-
type: "object",
|
|
88
|
-
properties,
|
|
89
|
-
patternProperties: Object.keys(patternProperties).length
|
|
90
|
-
? patternProperties
|
|
91
|
-
: undefined,
|
|
92
|
-
additionalProperties: additionalProperties.length
|
|
93
|
-
? additionalProperties.length === 1
|
|
94
|
-
? additionalProperties[0]
|
|
95
|
-
: { oneOf: additionalProperties }
|
|
96
|
-
: undefined,
|
|
97
|
-
nullable,
|
|
98
|
-
required: required.length ? required : undefined,
|
|
99
|
-
description: obj.description,
|
|
100
|
-
"x-typia_jsDocTags": obj.jsDocTags,
|
|
101
|
-
};
|
|
102
|
-
components.schemas[
|
|
103
|
-
};
|
|
1
|
+
import { CommentFactory } from "../../factories/CommentFactory";
|
|
2
|
+
|
|
3
|
+
import { IJsDocTagInfo } from "../../metadata/IJsDocTagInfo";
|
|
4
|
+
import { MetadataObject } from "../../metadata/MetadataObject";
|
|
5
|
+
import { IJsonComponents } from "../../schemas/IJsonComponents";
|
|
6
|
+
|
|
7
|
+
import { PatternUtil } from "../../utils/PatternUtil";
|
|
8
|
+
|
|
9
|
+
import { IJsonSchema } from "../../module";
|
|
10
|
+
import { ApplicationProgrammer } from "../ApplicationProgrammer";
|
|
11
|
+
import { application_schema } from "./application_schema";
|
|
12
|
+
import { metadata_to_pattern } from "./metadata_to_pattern";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export const application_object =
|
|
18
|
+
(options: ApplicationProgrammer.IOptions) =>
|
|
19
|
+
(components: IJsonComponents) =>
|
|
20
|
+
(id: string, obj: MetadataObject, nullable: boolean): void => {
|
|
21
|
+
// TEMPORARY ASSIGNMENT
|
|
22
|
+
if (components.schemas[id] !== undefined) return;
|
|
23
|
+
components.schemas[id] = {} as any;
|
|
24
|
+
|
|
25
|
+
// ITERATE PROPERTIES
|
|
26
|
+
const properties: Record<string, any> = {};
|
|
27
|
+
const patternProperties: Record<string, any> = {};
|
|
28
|
+
const additionalProperties: IJsonSchema[] = [];
|
|
29
|
+
const required: string[] = [];
|
|
30
|
+
|
|
31
|
+
for (const property of obj.properties) {
|
|
32
|
+
if (
|
|
33
|
+
property.value.functional === true &&
|
|
34
|
+
property.value.nullable === false &&
|
|
35
|
+
property.value.required === true &&
|
|
36
|
+
property.value.size() === 0
|
|
37
|
+
)
|
|
38
|
+
continue;
|
|
39
|
+
|
|
40
|
+
const key: string | null = property.key.getSoleLiteral();
|
|
41
|
+
const value: IJsonSchema | null = application_schema(options)(
|
|
42
|
+
components,
|
|
43
|
+
)(true)(property.value, {
|
|
44
|
+
deprecated:
|
|
45
|
+
!!property.jsDocTags.find(
|
|
46
|
+
(tag) => tag.name === "deprecated",
|
|
47
|
+
) || undefined,
|
|
48
|
+
title: (() => {
|
|
49
|
+
const info: IJsDocTagInfo | undefined =
|
|
50
|
+
property.jsDocTags.find((tag) => tag.name === "title");
|
|
51
|
+
return info?.text?.length
|
|
52
|
+
? CommentFactory.generate(info.text)
|
|
53
|
+
: undefined;
|
|
54
|
+
})(),
|
|
55
|
+
description: property.description,
|
|
56
|
+
"x-typia-metaTags": property.tags.length
|
|
57
|
+
? property.tags
|
|
58
|
+
: undefined,
|
|
59
|
+
"x-typia-jsDocTags": property.jsDocTags.length
|
|
60
|
+
? property.jsDocTags
|
|
61
|
+
: undefined,
|
|
62
|
+
"x-typia-required": property.value.required,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
if (value === null) continue;
|
|
66
|
+
else if (key !== null) {
|
|
67
|
+
properties[key] = value;
|
|
68
|
+
if (property.value.required === true) required.push(key);
|
|
69
|
+
} else {
|
|
70
|
+
const pattern: string = metadata_to_pattern(true)(property.key);
|
|
71
|
+
if (
|
|
72
|
+
options.purpose === "swagger" ||
|
|
73
|
+
pattern === PatternUtil.STRING
|
|
74
|
+
)
|
|
75
|
+
additionalProperties.push(value);
|
|
76
|
+
else patternProperties[pattern] = value;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const schema: IJsonComponents.IObject = {
|
|
81
|
+
$id:
|
|
82
|
+
options.purpose === "ajv"
|
|
83
|
+
? options.prefix + "/" + id
|
|
84
|
+
: undefined,
|
|
85
|
+
$recursiveAnchor:
|
|
86
|
+
(options.purpose === "ajv" && obj.recursive) || undefined,
|
|
87
|
+
type: "object",
|
|
88
|
+
properties,
|
|
89
|
+
patternProperties: Object.keys(patternProperties).length
|
|
90
|
+
? patternProperties
|
|
91
|
+
: undefined,
|
|
92
|
+
additionalProperties: additionalProperties.length
|
|
93
|
+
? additionalProperties.length === 1
|
|
94
|
+
? additionalProperties[0]
|
|
95
|
+
: { oneOf: additionalProperties }
|
|
96
|
+
: undefined,
|
|
97
|
+
nullable,
|
|
98
|
+
required: required.length ? required : undefined,
|
|
99
|
+
description: obj.description,
|
|
100
|
+
"x-typia_jsDocTags": obj.jsDocTags,
|
|
101
|
+
};
|
|
102
|
+
components.schemas[id] = schema;
|
|
103
|
+
};
|
|
@@ -4,6 +4,7 @@ import { IJsonComponents } from "../../schemas/IJsonComponents";
|
|
|
4
4
|
import { IJsonSchema } from "../../schemas/IJsonSchema";
|
|
5
5
|
|
|
6
6
|
import { ArrayUtil } from "../../utils/ArrayUtil";
|
|
7
|
+
import { NameEncoder } from "../../utils/NameEncoder";
|
|
7
8
|
|
|
8
9
|
import { ApplicationProgrammer } from "../ApplicationProgrammer";
|
|
9
10
|
import { AtomicPredicator } from "../helpers/AtomicPredicator";
|
|
@@ -50,13 +51,18 @@ export const application_schema =
|
|
|
50
51
|
if (meta.templates.length && AtomicPredicator.template(meta))
|
|
51
52
|
union.push(application_templates(meta, attribute));
|
|
52
53
|
for (const constant of meta.constants) {
|
|
53
|
-
if (constant.type === "
|
|
54
|
-
else if (
|
|
54
|
+
if (constant.type === "bigint") throw new Error(NO_BIGINT);
|
|
55
|
+
else if (
|
|
56
|
+
(constant.type === "string" && meta.templates.length) ||
|
|
57
|
+
AtomicPredicator.constant(meta)(constant.type) === false
|
|
58
|
+
)
|
|
59
|
+
continue;
|
|
55
60
|
union.push(
|
|
56
61
|
application_constant(constant, meta.nullable, attribute),
|
|
57
62
|
);
|
|
58
63
|
}
|
|
59
64
|
for (const type of meta.atomics) {
|
|
65
|
+
if (type === "bigint") throw new Error(NO_BIGINT);
|
|
60
66
|
union.push(
|
|
61
67
|
type === "string"
|
|
62
68
|
? application_string(meta, attribute)
|
|
@@ -128,12 +134,14 @@ export const application_schema =
|
|
|
128
134
|
|
|
129
135
|
// OBJECT
|
|
130
136
|
for (const obj of meta.objects) {
|
|
131
|
-
const
|
|
132
|
-
|
|
137
|
+
const id: string =
|
|
138
|
+
NameEncoder.encode(obj.name) +
|
|
139
|
+
(meta.nullable ? ".Nullable" : "");
|
|
140
|
+
application_object(options)(components)(id, obj, meta.nullable);
|
|
133
141
|
union.push(
|
|
134
142
|
(options.purpose === "ajv" && obj.recursive
|
|
135
143
|
? recursive
|
|
136
|
-
: reference)(`${options.prefix}/${
|
|
144
|
+
: reference)(`${options.prefix}/${id}`, attribute),
|
|
137
145
|
);
|
|
138
146
|
}
|
|
139
147
|
|
|
@@ -219,3 +227,5 @@ function merge_metadata(x: Metadata, y: Metadata): Metadata {
|
|
|
219
227
|
|
|
220
228
|
return output;
|
|
221
229
|
}
|
|
230
|
+
|
|
231
|
+
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,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) =>
|
|
21
|
-
application_schema(options)(components)(false)(meta, attribute),
|
|
22
|
-
),
|
|
23
|
-
nullable,
|
|
24
|
-
...attribute,
|
|
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) =>
|
|
21
|
+
application_schema(options)(components)(false)(meta, attribute),
|
|
22
|
+
),
|
|
23
|
+
nullable,
|
|
24
|
+
...attribute,
|
|
25
|
+
});
|
|
@@ -1,44 +1,44 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { ExpressionFactory } from "../../factories/ExpressionFactory";
|
|
4
|
-
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
5
|
-
|
|
6
|
-
import { IMetadataTag } from "../../metadata/IMetadataTag";
|
|
7
|
-
|
|
8
|
-
import { check_length } from "./check_length";
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @internal
|
|
12
|
-
*/
|
|
13
|
-
export function check_array(
|
|
14
|
-
input: ts.Expression,
|
|
15
|
-
tagList: IMetadataTag[],
|
|
16
|
-
): ts.Expression {
|
|
17
|
-
const conditions: ts.Expression[] = [ExpressionFactory.isArray(input)];
|
|
18
|
-
|
|
19
|
-
// CHECK TAGS
|
|
20
|
-
for (const tag of tagList)
|
|
21
|
-
if (tag.kind === "minItems")
|
|
22
|
-
conditions.push(
|
|
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
|
+
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
5
|
+
|
|
6
|
+
import { IMetadataTag } from "../../metadata/IMetadataTag";
|
|
7
|
+
|
|
8
|
+
import { check_length } from "./check_length";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export function check_array(
|
|
14
|
+
input: ts.Expression,
|
|
15
|
+
tagList: IMetadataTag[],
|
|
16
|
+
): ts.Expression {
|
|
17
|
+
const conditions: ts.Expression[] = [ExpressionFactory.isArray(input)];
|
|
18
|
+
|
|
19
|
+
// CHECK TAGS
|
|
20
|
+
for (const tag of tagList)
|
|
21
|
+
if (tag.kind === "minItems")
|
|
22
|
+
conditions.push(
|
|
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
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { IMetadataTag } from "../../metadata/IMetadataTag";
|
|
4
|
+
|
|
5
|
+
export function check_bigint(input: ts.Expression, tagList: IMetadataTag[]) {
|
|
6
|
+
const caster = (value: number) =>
|
|
7
|
+
ts.factory.createIdentifier(`${Math.floor(value)}n`);
|
|
8
|
+
|
|
9
|
+
// TYPEOF STATEMENT
|
|
10
|
+
const conditions: ts.Expression[] = [
|
|
11
|
+
ts.factory.createStrictEquality(
|
|
12
|
+
ts.factory.createStringLiteral("bigint"),
|
|
13
|
+
ts.factory.createTypeOfExpression(input),
|
|
14
|
+
),
|
|
15
|
+
];
|
|
16
|
+
|
|
17
|
+
// TAG (RANGE)
|
|
18
|
+
for (const tag of tagList)
|
|
19
|
+
if (tag.kind === "multipleOf")
|
|
20
|
+
conditions.push(
|
|
21
|
+
ts.factory.createStrictEquality(
|
|
22
|
+
caster(0),
|
|
23
|
+
ts.factory.createModulo(input, caster(tag.value)),
|
|
24
|
+
),
|
|
25
|
+
);
|
|
26
|
+
else if (tag.kind === "step") {
|
|
27
|
+
const modulo = () =>
|
|
28
|
+
ts.factory.createModulo(input, caster(tag.value));
|
|
29
|
+
const minimum = (() => {
|
|
30
|
+
for (const tag of tagList)
|
|
31
|
+
if (tag.kind === "minimum") return tag.value;
|
|
32
|
+
else if (tag.kind === "exclusiveMinimum") return tag.value;
|
|
33
|
+
else if (tag.kind === "range" && tag.minimum !== undefined)
|
|
34
|
+
return tag.minimum.value;
|
|
35
|
+
return undefined;
|
|
36
|
+
})();
|
|
37
|
+
conditions.push(
|
|
38
|
+
ts.factory.createStrictEquality(
|
|
39
|
+
caster(0),
|
|
40
|
+
minimum !== undefined
|
|
41
|
+
? ts.factory.createSubtract(modulo(), caster(minimum))
|
|
42
|
+
: modulo(),
|
|
43
|
+
),
|
|
44
|
+
);
|
|
45
|
+
} else if (tag.kind === "range") {
|
|
46
|
+
if (tag.minimum !== undefined)
|
|
47
|
+
conditions.push(
|
|
48
|
+
(tag.minimum.include
|
|
49
|
+
? ts.factory.createLessThanEquals
|
|
50
|
+
: ts.factory.createLessThan)(
|
|
51
|
+
caster(tag.minimum.value),
|
|
52
|
+
input,
|
|
53
|
+
),
|
|
54
|
+
);
|
|
55
|
+
if (tag.maximum !== undefined)
|
|
56
|
+
conditions.push(
|
|
57
|
+
(tag.maximum.include
|
|
58
|
+
? ts.factory.createLessThanEquals
|
|
59
|
+
: ts.factory.createLessThan)(
|
|
60
|
+
input,
|
|
61
|
+
caster(tag.maximum.value),
|
|
62
|
+
),
|
|
63
|
+
);
|
|
64
|
+
} else if (tag.kind === "minimum")
|
|
65
|
+
conditions.push(
|
|
66
|
+
ts.factory.createLessThanEquals(caster(tag.value), input),
|
|
67
|
+
);
|
|
68
|
+
else if (tag.kind === "maximum")
|
|
69
|
+
conditions.push(
|
|
70
|
+
ts.factory.createGreaterThanEquals(caster(tag.value), input),
|
|
71
|
+
);
|
|
72
|
+
else if (tag.kind === "exclusiveMinimum")
|
|
73
|
+
conditions.push(
|
|
74
|
+
ts.factory.createLessThan(caster(tag.value), input),
|
|
75
|
+
);
|
|
76
|
+
else if (tag.kind === "exclusiveMaximum")
|
|
77
|
+
conditions.push(
|
|
78
|
+
ts.factory.createGreaterThan(caster(tag.value), input),
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
// COMBINATION
|
|
82
|
+
return conditions.length === 1
|
|
83
|
+
? conditions[0]!
|
|
84
|
+
: conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y));
|
|
85
|
+
}
|