typia 3.5.0-dev.20221222 → 3.5.0-dev.20230107
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/metadata/Metadata.js +32 -29
- 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/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_schema.js +2 -0
- package/lib/programmers/internal/application_schema.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/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/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/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 +10 -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/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 +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_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 +5 -0
- 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 +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 +24 -24
- 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,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
|
-
};
|
|
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
|
+
};
|
|
@@ -96,6 +96,11 @@ export const application_schema =
|
|
|
96
96
|
),
|
|
97
97
|
);
|
|
98
98
|
else {
|
|
99
|
+
if (items.length === 0)
|
|
100
|
+
throw new Error(
|
|
101
|
+
"Error on typia.application(): swagger does not support zero length tuple type.",
|
|
102
|
+
);
|
|
103
|
+
|
|
99
104
|
// SWAGGER DOES NOT SUPPORT TUPLE TYPE YET
|
|
100
105
|
const merged: Metadata = items.reduce((x, y) =>
|
|
101
106
|
merge_metadata(x, y),
|
|
@@ -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,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
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
4
|
+
|
|
5
|
+
import { IMetadataTag } from "../../metadata/IMetadataTag";
|
|
6
|
+
|
|
7
|
+
import { check_length } from "./check_length";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export function check_array_length(
|
|
13
|
+
input: ts.Expression,
|
|
14
|
+
tagList: IMetadataTag[],
|
|
15
|
+
): ts.Expression | null {
|
|
16
|
+
const conditions: ts.Expression[] = [];
|
|
17
|
+
|
|
18
|
+
// CHECK TAGS
|
|
19
|
+
for (const tag of tagList)
|
|
20
|
+
if (tag.kind === "minItems")
|
|
21
|
+
conditions.push(
|
|
22
|
+
ts.factory.createLessThanEquals(
|
|
23
|
+
ts.factory.createNumericLiteral(tag.value),
|
|
24
|
+
IdentifierFactory.join(input, "length"),
|
|
25
|
+
),
|
|
26
|
+
);
|
|
27
|
+
else if (tag.kind === "maxItems")
|
|
28
|
+
conditions.push(
|
|
29
|
+
ts.factory.createGreaterThanEquals(
|
|
30
|
+
ts.factory.createNumericLiteral(tag.value),
|
|
31
|
+
IdentifierFactory.join(input, "length"),
|
|
32
|
+
),
|
|
33
|
+
);
|
|
34
|
+
else if (tag.kind === "items")
|
|
35
|
+
check_length(
|
|
36
|
+
conditions,
|
|
37
|
+
IdentifierFactory.join(input, "length"),
|
|
38
|
+
tag,
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
// COMBINATION
|
|
42
|
+
return conditions.length
|
|
43
|
+
? conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y))
|
|
44
|
+
: null;
|
|
45
|
+
}
|