typia 3.4.13 → 3.4.14
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 +9 -8
- package/lib/factories/internal/iterate_metadata_object.js +4 -2
- package/lib/factories/internal/iterate_metadata_object.js.map +1 -1
- package/package.json +1 -1
- 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 +175 -175
- 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 +122 -122
- package/src/factories/MetadataFactory.ts +46 -46
- package/src/factories/MetadataTagFactory.ts +347 -347
- 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/MetadataHelper.ts +12 -12
- package/src/factories/internal/emplace_metadata_object.ts +140 -140
- package/src/factories/internal/explore_metadata.ts +91 -91
- package/src/factories/internal/iterate_metadata.ts +80 -80
- package/src/factories/internal/iterate_metadata_array.ts +29 -29
- package/src/factories/internal/iterate_metadata_atomic.ts +59 -59
- package/src/factories/internal/iterate_metadata_coalesce.ts +33 -33
- package/src/factories/internal/iterate_metadata_constant.ts +58 -58
- package/src/factories/internal/iterate_metadata_map.ts +41 -41
- package/src/factories/internal/iterate_metadata_native.ts +227 -227
- package/src/factories/internal/iterate_metadata_object.ts +48 -45
- package/src/factories/internal/iterate_metadata_resolve.ts +27 -27
- package/src/factories/internal/iterate_metadata_set.ts +33 -33
- package/src/factories/internal/iterate_metadata_template.ts +38 -38
- package/src/factories/internal/iterate_metadata_tuple.ts +45 -45
- package/src/factories/internal/iterate_metadata_union.ts +59 -59
- 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 +19 -19
- 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/IMetadataTag.ts +122 -122
- package/src/metadata/Metadata.ts +477 -477
- package/src/metadata/MetadataConstant.ts +3 -3
- package/src/metadata/MetadataObject.ts +131 -131
- package/src/metadata/MetadataProperty.ts +64 -64
- package/src/module.ts +1535 -1535
- package/src/programmers/ApplicationProgrammer.ts +55 -55
- package/src/programmers/AssertParseProgrammer.ts +45 -45
- package/src/programmers/AssertProgrammer.ts +444 -444
- package/src/programmers/AssertStringifyProgrammer.ts +45 -45
- package/src/programmers/CheckerProgrammer.ts +804 -804
- package/src/programmers/FeatureProgrammer.ts +327 -327
- package/src/programmers/IsParseProgrammer.ts +51 -51
- package/src/programmers/IsProgrammer.ts +172 -172
- package/src/programmers/IsStringifyProgrammer.ts +49 -49
- package/src/programmers/StringifyProgrammer.ts +756 -756
- package/src/programmers/ValidateParseProgrammer.ts +49 -49
- package/src/programmers/ValidateProgrammer.ts +236 -236
- package/src/programmers/ValidateStringifyProgrammer.ts +60 -60
- 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 +11 -11
- 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 +17 -17
- 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 +221 -221
- 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_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 +178 -178
- 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 +92 -92
- package/src/transform.ts +20 -20
- package/src/transformers/CallExpressionTransformer.ts +124 -124
- 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 +4 -4
- package/src/transformers/NodeTransformer.ts +19 -19
- package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +114 -114
- package/src/transformers/features/miscellaneous/CreateInstanceTransformer.ts +41 -41
- 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 +36 -36
- 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
|
-
(key: string, obj: MetadataObject, nullable: boolean): void => {
|
|
21
|
-
// TEMPORARY ASSIGNMENT
|
|
22
|
-
if (components.schemas[key] !== undefined) return;
|
|
23
|
-
components.schemas[key] = {} 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 + "/" + key
|
|
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[key] = 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
|
+
(key: string, obj: MetadataObject, nullable: boolean): void => {
|
|
21
|
+
// TEMPORARY ASSIGNMENT
|
|
22
|
+
if (components.schemas[key] !== undefined) return;
|
|
23
|
+
components.schemas[key] = {} 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 + "/" + key
|
|
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[key] = schema;
|
|
103
|
+
};
|
|
@@ -1,221 +1,221 @@
|
|
|
1
|
-
import { Metadata } from "../../metadata/Metadata";
|
|
2
|
-
import { MetadataConstant } from "../../metadata/MetadataConstant";
|
|
3
|
-
import { IJsonComponents } from "../../schemas/IJsonComponents";
|
|
4
|
-
import { IJsonSchema } from "../../schemas/IJsonSchema";
|
|
5
|
-
|
|
6
|
-
import { ArrayUtil } from "../../utils/ArrayUtil";
|
|
7
|
-
|
|
8
|
-
import { ApplicationProgrammer } from "../ApplicationProgrammer";
|
|
9
|
-
import { AtomicPredicator } from "../helpers/AtomicPredicator";
|
|
10
|
-
import { application_array } from "./application_array";
|
|
11
|
-
import { application_boolean } from "./application_boolean";
|
|
12
|
-
import { application_constant } from "./application_constant";
|
|
13
|
-
import { application_native } from "./application_native";
|
|
14
|
-
import { application_number } from "./application_number";
|
|
15
|
-
import { application_object } from "./application_object";
|
|
16
|
-
import { application_string } from "./application_string";
|
|
17
|
-
import { application_templates } from "./application_templates";
|
|
18
|
-
import { application_tuple } from "./application_tuple";
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* @internal
|
|
22
|
-
*/
|
|
23
|
-
export const application_schema =
|
|
24
|
-
(options: ApplicationProgrammer.IOptions) =>
|
|
25
|
-
(components: IJsonComponents) =>
|
|
26
|
-
<BlockNever extends boolean>(blockNever: BlockNever) =>
|
|
27
|
-
(
|
|
28
|
-
meta: Metadata,
|
|
29
|
-
attribute: IJsonSchema.IAttribute,
|
|
30
|
-
): BlockNever extends true ? IJsonSchema | null : IJsonSchema => {
|
|
31
|
-
// VULNERABLE CASE
|
|
32
|
-
if (meta.any === true) return {};
|
|
33
|
-
else if (meta.nullable && meta.empty())
|
|
34
|
-
return { type: "null", ...attribute };
|
|
35
|
-
|
|
36
|
-
//----
|
|
37
|
-
// GATHER UNION SCHEMAS
|
|
38
|
-
//----
|
|
39
|
-
const union: IJsonSchema[] = [];
|
|
40
|
-
|
|
41
|
-
// toJSON() METHOD
|
|
42
|
-
if (meta.resolved !== null) {
|
|
43
|
-
const resolved = application_schema(options)(components)(
|
|
44
|
-
blockNever,
|
|
45
|
-
)(meta.resolved, attribute);
|
|
46
|
-
if (resolved !== null) union.push(resolved);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// ATOMIC TYPES
|
|
50
|
-
if (meta.templates.length && AtomicPredicator.template(meta))
|
|
51
|
-
union.push(application_templates(meta, attribute));
|
|
52
|
-
for (const constant of meta.constants) {
|
|
53
|
-
if (constant.type === "string" && meta.templates.length) continue;
|
|
54
|
-
else if (!AtomicPredicator.constant(meta)(constant.type)) continue;
|
|
55
|
-
union.push(
|
|
56
|
-
application_constant(constant, meta.nullable, attribute),
|
|
57
|
-
);
|
|
58
|
-
}
|
|
59
|
-
for (const type of meta.atomics) {
|
|
60
|
-
union.push(
|
|
61
|
-
type === "string"
|
|
62
|
-
? application_string(meta, attribute)
|
|
63
|
-
: type === "boolean"
|
|
64
|
-
? application_boolean(meta.nullable, attribute)
|
|
65
|
-
: application_number(meta.nullable, attribute),
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// ARRAY
|
|
70
|
-
for (const schema of meta.arrays.values())
|
|
71
|
-
union.push(
|
|
72
|
-
application_array(options)(components)(
|
|
73
|
-
schema,
|
|
74
|
-
meta.nullable,
|
|
75
|
-
attribute,
|
|
76
|
-
),
|
|
77
|
-
);
|
|
78
|
-
|
|
79
|
-
// TUPLE
|
|
80
|
-
for (const items of meta.tuples)
|
|
81
|
-
if (
|
|
82
|
-
options.purpose === "ajv" &&
|
|
83
|
-
items.every((i) => i.rest === null)
|
|
84
|
-
)
|
|
85
|
-
union.push(
|
|
86
|
-
application_tuple(options)(components)(
|
|
87
|
-
items,
|
|
88
|
-
meta.nullable,
|
|
89
|
-
attribute,
|
|
90
|
-
),
|
|
91
|
-
);
|
|
92
|
-
else {
|
|
93
|
-
// SWAGGER DOES NOT SUPPORT TUPLE TYPE YET
|
|
94
|
-
const merged: Metadata = items.reduce((x, y) =>
|
|
95
|
-
merge_metadata(x, y),
|
|
96
|
-
);
|
|
97
|
-
union.push(
|
|
98
|
-
application_array(options)(components)(
|
|
99
|
-
merged,
|
|
100
|
-
merged?.nullable || false,
|
|
101
|
-
attribute,
|
|
102
|
-
),
|
|
103
|
-
);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
// NATIVES
|
|
107
|
-
for (const native of meta.natives)
|
|
108
|
-
union.push(
|
|
109
|
-
application_native(options)(components)(native)(
|
|
110
|
-
meta.nullable,
|
|
111
|
-
attribute,
|
|
112
|
-
),
|
|
113
|
-
);
|
|
114
|
-
if (meta.sets.length)
|
|
115
|
-
union.push(
|
|
116
|
-
application_native(options)(components)(`Set`)(
|
|
117
|
-
meta.nullable,
|
|
118
|
-
attribute,
|
|
119
|
-
),
|
|
120
|
-
);
|
|
121
|
-
if (meta.maps.length)
|
|
122
|
-
union.push(
|
|
123
|
-
application_native(options)(components)(`Map`)(
|
|
124
|
-
meta.nullable,
|
|
125
|
-
attribute,
|
|
126
|
-
),
|
|
127
|
-
);
|
|
128
|
-
|
|
129
|
-
// OBJECT
|
|
130
|
-
for (const obj of meta.objects) {
|
|
131
|
-
const key: string = obj.name + (meta.nullable ? ".Nullable" : "");
|
|
132
|
-
application_object(options)(components)(key, obj, meta.nullable);
|
|
133
|
-
union.push(
|
|
134
|
-
(options.purpose === "ajv" && obj.recursive
|
|
135
|
-
? recursive
|
|
136
|
-
: reference)(`${options.prefix}/${key}`, attribute),
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
//----
|
|
141
|
-
// RETURNS
|
|
142
|
-
//----
|
|
143
|
-
if (union.length === 0) return blockNever === true ? null! : {};
|
|
144
|
-
else if (union.length === 1) return union[0]!;
|
|
145
|
-
return { oneOf: union, ...attribute };
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
/**
|
|
149
|
-
* @internal
|
|
150
|
-
*/
|
|
151
|
-
const reference = (
|
|
152
|
-
$ref: string,
|
|
153
|
-
attribute: IJsonSchema.IAttribute,
|
|
154
|
-
): IJsonSchema.IReference => ({
|
|
155
|
-
$ref,
|
|
156
|
-
...attribute,
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* @internal
|
|
161
|
-
*/
|
|
162
|
-
const recursive = (
|
|
163
|
-
$recursiveRef: string,
|
|
164
|
-
attribute: IJsonSchema.IAttribute,
|
|
165
|
-
): IJsonSchema.IRecursiveReference => ({
|
|
166
|
-
$recursiveRef,
|
|
167
|
-
...attribute,
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* @internal
|
|
172
|
-
* @todo: not perfect
|
|
173
|
-
*/
|
|
174
|
-
function merge_metadata(x: Metadata, y: Metadata): Metadata {
|
|
175
|
-
const output: Metadata = Metadata.create({
|
|
176
|
-
any: x.any || y.any,
|
|
177
|
-
nullable: x.nullable || y.nullable,
|
|
178
|
-
required: x.required && y.required,
|
|
179
|
-
functional: x.functional || y.functional,
|
|
180
|
-
|
|
181
|
-
resolved:
|
|
182
|
-
x.resolved !== null && y.resolved !== null
|
|
183
|
-
? merge_metadata(x.resolved, y.resolved)
|
|
184
|
-
: x.resolved || y.resolved,
|
|
185
|
-
atomics: [...new Set([...x.atomics, ...y.atomics])],
|
|
186
|
-
constants: [...x.constants],
|
|
187
|
-
templates: x.templates.slice(),
|
|
188
|
-
|
|
189
|
-
rest: null,
|
|
190
|
-
arrays: x.arrays.slice(),
|
|
191
|
-
tuples: x.tuples.slice(),
|
|
192
|
-
objects: x.objects.slice(),
|
|
193
|
-
|
|
194
|
-
natives: [...new Set([...x.natives, ...y.natives])],
|
|
195
|
-
sets: x.sets.slice(),
|
|
196
|
-
maps: x.maps.slice(),
|
|
197
|
-
});
|
|
198
|
-
for (const constant of y.constants) {
|
|
199
|
-
const target: MetadataConstant = ArrayUtil.take(
|
|
200
|
-
output.constants,
|
|
201
|
-
(elem) => elem.type === constant.type,
|
|
202
|
-
() => ({
|
|
203
|
-
type: constant.type,
|
|
204
|
-
values: [],
|
|
205
|
-
}),
|
|
206
|
-
);
|
|
207
|
-
for (const value of constant.values)
|
|
208
|
-
ArrayUtil.add(target.values, value);
|
|
209
|
-
}
|
|
210
|
-
for (const array of y.arrays)
|
|
211
|
-
ArrayUtil.set(output.arrays, array, (elem) => elem.getName());
|
|
212
|
-
for (const obj of y.objects)
|
|
213
|
-
ArrayUtil.set(output.objects, obj, (elem) => elem.name);
|
|
214
|
-
|
|
215
|
-
if (x.rest !== null)
|
|
216
|
-
ArrayUtil.set(output.arrays, x.rest, (elem) => elem.getName());
|
|
217
|
-
if (y.rest !== null)
|
|
218
|
-
ArrayUtil.set(output.arrays, y.rest, (elem) => elem.getName());
|
|
219
|
-
|
|
220
|
-
return output;
|
|
221
|
-
}
|
|
1
|
+
import { Metadata } from "../../metadata/Metadata";
|
|
2
|
+
import { MetadataConstant } from "../../metadata/MetadataConstant";
|
|
3
|
+
import { IJsonComponents } from "../../schemas/IJsonComponents";
|
|
4
|
+
import { IJsonSchema } from "../../schemas/IJsonSchema";
|
|
5
|
+
|
|
6
|
+
import { ArrayUtil } from "../../utils/ArrayUtil";
|
|
7
|
+
|
|
8
|
+
import { ApplicationProgrammer } from "../ApplicationProgrammer";
|
|
9
|
+
import { AtomicPredicator } from "../helpers/AtomicPredicator";
|
|
10
|
+
import { application_array } from "./application_array";
|
|
11
|
+
import { application_boolean } from "./application_boolean";
|
|
12
|
+
import { application_constant } from "./application_constant";
|
|
13
|
+
import { application_native } from "./application_native";
|
|
14
|
+
import { application_number } from "./application_number";
|
|
15
|
+
import { application_object } from "./application_object";
|
|
16
|
+
import { application_string } from "./application_string";
|
|
17
|
+
import { application_templates } from "./application_templates";
|
|
18
|
+
import { application_tuple } from "./application_tuple";
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
export const application_schema =
|
|
24
|
+
(options: ApplicationProgrammer.IOptions) =>
|
|
25
|
+
(components: IJsonComponents) =>
|
|
26
|
+
<BlockNever extends boolean>(blockNever: BlockNever) =>
|
|
27
|
+
(
|
|
28
|
+
meta: Metadata,
|
|
29
|
+
attribute: IJsonSchema.IAttribute,
|
|
30
|
+
): BlockNever extends true ? IJsonSchema | null : IJsonSchema => {
|
|
31
|
+
// VULNERABLE CASE
|
|
32
|
+
if (meta.any === true) return {};
|
|
33
|
+
else if (meta.nullable && meta.empty())
|
|
34
|
+
return { type: "null", ...attribute };
|
|
35
|
+
|
|
36
|
+
//----
|
|
37
|
+
// GATHER UNION SCHEMAS
|
|
38
|
+
//----
|
|
39
|
+
const union: IJsonSchema[] = [];
|
|
40
|
+
|
|
41
|
+
// toJSON() METHOD
|
|
42
|
+
if (meta.resolved !== null) {
|
|
43
|
+
const resolved = application_schema(options)(components)(
|
|
44
|
+
blockNever,
|
|
45
|
+
)(meta.resolved, attribute);
|
|
46
|
+
if (resolved !== null) union.push(resolved);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// ATOMIC TYPES
|
|
50
|
+
if (meta.templates.length && AtomicPredicator.template(meta))
|
|
51
|
+
union.push(application_templates(meta, attribute));
|
|
52
|
+
for (const constant of meta.constants) {
|
|
53
|
+
if (constant.type === "string" && meta.templates.length) continue;
|
|
54
|
+
else if (!AtomicPredicator.constant(meta)(constant.type)) continue;
|
|
55
|
+
union.push(
|
|
56
|
+
application_constant(constant, meta.nullable, attribute),
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
for (const type of meta.atomics) {
|
|
60
|
+
union.push(
|
|
61
|
+
type === "string"
|
|
62
|
+
? application_string(meta, attribute)
|
|
63
|
+
: type === "boolean"
|
|
64
|
+
? application_boolean(meta.nullable, attribute)
|
|
65
|
+
: application_number(meta.nullable, attribute),
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// ARRAY
|
|
70
|
+
for (const schema of meta.arrays.values())
|
|
71
|
+
union.push(
|
|
72
|
+
application_array(options)(components)(
|
|
73
|
+
schema,
|
|
74
|
+
meta.nullable,
|
|
75
|
+
attribute,
|
|
76
|
+
),
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
// TUPLE
|
|
80
|
+
for (const items of meta.tuples)
|
|
81
|
+
if (
|
|
82
|
+
options.purpose === "ajv" &&
|
|
83
|
+
items.every((i) => i.rest === null)
|
|
84
|
+
)
|
|
85
|
+
union.push(
|
|
86
|
+
application_tuple(options)(components)(
|
|
87
|
+
items,
|
|
88
|
+
meta.nullable,
|
|
89
|
+
attribute,
|
|
90
|
+
),
|
|
91
|
+
);
|
|
92
|
+
else {
|
|
93
|
+
// SWAGGER DOES NOT SUPPORT TUPLE TYPE YET
|
|
94
|
+
const merged: Metadata = items.reduce((x, y) =>
|
|
95
|
+
merge_metadata(x, y),
|
|
96
|
+
);
|
|
97
|
+
union.push(
|
|
98
|
+
application_array(options)(components)(
|
|
99
|
+
merged,
|
|
100
|
+
merged?.nullable || false,
|
|
101
|
+
attribute,
|
|
102
|
+
),
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// NATIVES
|
|
107
|
+
for (const native of meta.natives)
|
|
108
|
+
union.push(
|
|
109
|
+
application_native(options)(components)(native)(
|
|
110
|
+
meta.nullable,
|
|
111
|
+
attribute,
|
|
112
|
+
),
|
|
113
|
+
);
|
|
114
|
+
if (meta.sets.length)
|
|
115
|
+
union.push(
|
|
116
|
+
application_native(options)(components)(`Set`)(
|
|
117
|
+
meta.nullable,
|
|
118
|
+
attribute,
|
|
119
|
+
),
|
|
120
|
+
);
|
|
121
|
+
if (meta.maps.length)
|
|
122
|
+
union.push(
|
|
123
|
+
application_native(options)(components)(`Map`)(
|
|
124
|
+
meta.nullable,
|
|
125
|
+
attribute,
|
|
126
|
+
),
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
// OBJECT
|
|
130
|
+
for (const obj of meta.objects) {
|
|
131
|
+
const key: string = obj.name + (meta.nullable ? ".Nullable" : "");
|
|
132
|
+
application_object(options)(components)(key, obj, meta.nullable);
|
|
133
|
+
union.push(
|
|
134
|
+
(options.purpose === "ajv" && obj.recursive
|
|
135
|
+
? recursive
|
|
136
|
+
: reference)(`${options.prefix}/${key}`, attribute),
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
//----
|
|
141
|
+
// RETURNS
|
|
142
|
+
//----
|
|
143
|
+
if (union.length === 0) return blockNever === true ? null! : {};
|
|
144
|
+
else if (union.length === 1) return union[0]!;
|
|
145
|
+
return { oneOf: union, ...attribute };
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* @internal
|
|
150
|
+
*/
|
|
151
|
+
const reference = (
|
|
152
|
+
$ref: string,
|
|
153
|
+
attribute: IJsonSchema.IAttribute,
|
|
154
|
+
): IJsonSchema.IReference => ({
|
|
155
|
+
$ref,
|
|
156
|
+
...attribute,
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* @internal
|
|
161
|
+
*/
|
|
162
|
+
const recursive = (
|
|
163
|
+
$recursiveRef: string,
|
|
164
|
+
attribute: IJsonSchema.IAttribute,
|
|
165
|
+
): IJsonSchema.IRecursiveReference => ({
|
|
166
|
+
$recursiveRef,
|
|
167
|
+
...attribute,
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* @internal
|
|
172
|
+
* @todo: not perfect
|
|
173
|
+
*/
|
|
174
|
+
function merge_metadata(x: Metadata, y: Metadata): Metadata {
|
|
175
|
+
const output: Metadata = Metadata.create({
|
|
176
|
+
any: x.any || y.any,
|
|
177
|
+
nullable: x.nullable || y.nullable,
|
|
178
|
+
required: x.required && y.required,
|
|
179
|
+
functional: x.functional || y.functional,
|
|
180
|
+
|
|
181
|
+
resolved:
|
|
182
|
+
x.resolved !== null && y.resolved !== null
|
|
183
|
+
? merge_metadata(x.resolved, y.resolved)
|
|
184
|
+
: x.resolved || y.resolved,
|
|
185
|
+
atomics: [...new Set([...x.atomics, ...y.atomics])],
|
|
186
|
+
constants: [...x.constants],
|
|
187
|
+
templates: x.templates.slice(),
|
|
188
|
+
|
|
189
|
+
rest: null,
|
|
190
|
+
arrays: x.arrays.slice(),
|
|
191
|
+
tuples: x.tuples.slice(),
|
|
192
|
+
objects: x.objects.slice(),
|
|
193
|
+
|
|
194
|
+
natives: [...new Set([...x.natives, ...y.natives])],
|
|
195
|
+
sets: x.sets.slice(),
|
|
196
|
+
maps: x.maps.slice(),
|
|
197
|
+
});
|
|
198
|
+
for (const constant of y.constants) {
|
|
199
|
+
const target: MetadataConstant = ArrayUtil.take(
|
|
200
|
+
output.constants,
|
|
201
|
+
(elem) => elem.type === constant.type,
|
|
202
|
+
() => ({
|
|
203
|
+
type: constant.type,
|
|
204
|
+
values: [],
|
|
205
|
+
}),
|
|
206
|
+
);
|
|
207
|
+
for (const value of constant.values)
|
|
208
|
+
ArrayUtil.add(target.values, value);
|
|
209
|
+
}
|
|
210
|
+
for (const array of y.arrays)
|
|
211
|
+
ArrayUtil.set(output.arrays, array, (elem) => elem.getName());
|
|
212
|
+
for (const obj of y.objects)
|
|
213
|
+
ArrayUtil.set(output.objects, obj, (elem) => elem.name);
|
|
214
|
+
|
|
215
|
+
if (x.rest !== null)
|
|
216
|
+
ArrayUtil.set(output.arrays, x.rest, (elem) => elem.getName());
|
|
217
|
+
if (y.rest !== null)
|
|
218
|
+
ArrayUtil.set(output.arrays, y.rest, (elem) => elem.getName());
|
|
219
|
+
|
|
220
|
+
return output;
|
|
221
|
+
}
|