typia 3.7.5-dev.20230413 → 3.7.6
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 +35 -228
- package/lib/executable/TypiaSetupWizard.d.ts +1 -0
- package/lib/executable/TypiaSetupWizard.js +62 -30
- package/lib/executable/TypiaSetupWizard.js.map +1 -1
- package/lib/executable/setup/PackageManager.d.ts +1 -1
- package/lib/executable/typia.d.ts +1 -1
- package/lib/executable/typia.js +1 -1
- package/lib/executable/typia.js.map +1 -1
- package/lib/factories/IdentifierFactory.d.ts +1 -1
- package/lib/factories/IdentifierFactory.js +1 -1
- package/lib/factories/IdentifierFactory.js.map +1 -1
- package/lib/factories/TypiaFileFactory.js +9 -4
- package/lib/factories/TypiaFileFactory.js.map +1 -1
- package/lib/programmers/internal/check_string_tags.js +2 -2
- package/lib/programmers/internal/check_string_tags.js.map +1 -1
- package/lib/programmers/internal/check_template.js +1 -1
- package/lib/programmers/internal/check_template.js.map +1 -1
- package/package.json +11 -12
- package/src/CustomValidatorMap.ts +126 -126
- package/src/IRandomGenerator.ts +33 -33
- package/src/IValidation.ts +21 -21
- package/src/Primitive.ts +104 -104
- package/src/TypeGuardError.ts +36 -36
- package/src/executable/TypiaGenerateWizard.ts +85 -85
- package/src/executable/TypiaSetupWizard.ts +47 -14
- package/src/executable/setup/ArgumentParser.ts +45 -45
- package/src/executable/setup/CommandExecutor.ts +8 -8
- package/src/executable/setup/FileRetriever.ts +22 -22
- package/src/executable/setup/PackageManager.ts +1 -1
- package/src/executable/setup/PluginConfigurator.ts +59 -59
- package/src/executable/typia.ts +54 -53
- package/src/factories/CommentFactory.ts +10 -10
- package/src/factories/ExpressionFactory.ts +77 -77
- package/src/factories/IdentifierFactory.ts +81 -59
- package/src/factories/LiteralFactory.ts +44 -44
- package/src/factories/MetadataCollection.ts +122 -122
- package/src/factories/MetadataFactory.ts +51 -51
- package/src/factories/MetadataTagFactory.ts +302 -302
- package/src/factories/StatementFactory.ts +60 -60
- package/src/factories/TemplateFactory.ts +56 -56
- package/src/factories/TypeFactory.ts +129 -129
- package/src/factories/TypiaFileFactory.ts +12 -3
- package/src/factories/ValueFactory.ts +12 -12
- package/src/factories/internal/metadata/MetadataHelper.ts +12 -12
- package/src/factories/internal/metadata/emplace_metadata_object.ts +142 -142
- package/src/factories/internal/metadata/explore_metadata.ts +92 -92
- package/src/factories/internal/metadata/iterate_metadata.ts +80 -80
- package/src/factories/internal/metadata/iterate_metadata_array.ts +29 -29
- package/src/factories/internal/metadata/iterate_metadata_atomic.ts +59 -59
- package/src/factories/internal/metadata/iterate_metadata_coalesce.ts +33 -33
- package/src/factories/internal/metadata/iterate_metadata_constant.ts +58 -58
- package/src/factories/internal/metadata/iterate_metadata_map.ts +41 -41
- package/src/factories/internal/metadata/iterate_metadata_native.ts +222 -222
- package/src/factories/internal/metadata/iterate_metadata_object.ts +48 -48
- package/src/factories/internal/metadata/iterate_metadata_resolve.ts +27 -27
- package/src/factories/internal/metadata/iterate_metadata_set.ts +33 -33
- package/src/factories/internal/metadata/iterate_metadata_template.ts +38 -38
- package/src/factories/internal/metadata/iterate_metadata_tuple.ts +45 -45
- package/src/factories/internal/metadata/iterate_metadata_union.ts +59 -59
- package/src/functional/$any.ts +3 -3
- package/src/functional/$dictionary.ts +20 -20
- package/src/functional/$every.ts +11 -11
- package/src/functional/$guard.ts +35 -35
- package/src/functional/$is_between.ts +7 -7
- package/src/functional/$is_custom.ts +14 -14
- package/src/functional/$is_date.ts +4 -4
- package/src/functional/$is_datetime.ts +3 -3
- 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 +12 -12
- 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/functional/Namespace.ts +127 -127
- package/src/index.ts +4 -4
- package/src/metadata/ICommentTag.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 +105 -105
- package/src/metadata/Metadata.ts +534 -534
- 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 +2043 -2043
- package/src/programmers/ApplicationProgrammer.ts +55 -55
- package/src/programmers/AssertCloneProgrammer.ts +70 -70
- package/src/programmers/AssertParseProgrammer.ts +65 -65
- package/src/programmers/AssertProgrammer.ts +284 -284
- package/src/programmers/AssertPruneProgrammer.ts +67 -67
- package/src/programmers/AssertStringifyProgrammer.ts +71 -71
- package/src/programmers/CheckerProgrammer.ts +922 -922
- package/src/programmers/CloneProgrammer.ts +388 -388
- package/src/programmers/FeatureProgrammer.ts +512 -512
- package/src/programmers/IsCloneProgrammer.ts +80 -80
- package/src/programmers/IsParseProgrammer.ts +74 -74
- package/src/programmers/IsProgrammer.ts +206 -206
- package/src/programmers/IsPruneProgrammer.ts +75 -75
- package/src/programmers/IsStringifyProgrammer.ts +81 -81
- package/src/programmers/LiteralsProgrammer.ts +65 -65
- package/src/programmers/PruneProgrammer.ts +343 -343
- package/src/programmers/RandomProgrammer.ts +413 -413
- package/src/programmers/StringifyProgrammer.ts +801 -801
- package/src/programmers/ValidateCloneProgrammer.ts +90 -90
- package/src/programmers/ValidateParseProgrammer.ts +69 -69
- package/src/programmers/ValidateProgrammer.ts +317 -317
- package/src/programmers/ValidatePruneProgrammer.ts +83 -83
- package/src/programmers/ValidateStringifyProgrammer.ts +89 -89
- package/src/programmers/helpers/AtomicPredicator.ts +31 -31
- package/src/programmers/helpers/CloneJoiner.ts +134 -134
- package/src/programmers/helpers/FunctionImporeter.ts +55 -55
- package/src/programmers/helpers/ICheckEntry.ts +12 -12
- package/src/programmers/helpers/IExpressionEntry.ts +12 -12
- package/src/programmers/helpers/OptionPredicator.ts +19 -19
- package/src/programmers/helpers/PruneJoiner.ts +52 -52
- package/src/programmers/helpers/RandomJoiner.ts +161 -161
- package/src/programmers/helpers/RandomRanger.ts +216 -216
- package/src/programmers/helpers/StringifyJoinder.ts +114 -114
- package/src/programmers/helpers/StringifyPredicator.ts +18 -18
- package/src/programmers/helpers/UnionExplorer.ts +281 -281
- package/src/programmers/helpers/UnionPredicator.ts +81 -81
- package/src/programmers/internal/application_array.ts +37 -37
- 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 +32 -32
- package/src/programmers/internal/application_number.ts +73 -73
- package/src/programmers/internal/application_object.ts +153 -153
- package/src/programmers/internal/application_schema.ts +184 -184
- package/src/programmers/internal/application_string.ts +45 -45
- package/src/programmers/internal/application_templates.ts +27 -27
- package/src/programmers/internal/application_tuple.ts +29 -29
- package/src/programmers/internal/check_array.ts +30 -30
- package/src/programmers/internal/check_array_length.ts +35 -35
- package/src/programmers/internal/check_bigint.ts +82 -82
- package/src/programmers/internal/check_custom.ts +33 -33
- package/src/programmers/internal/check_dynamic_properties.ts +197 -197
- package/src/programmers/internal/check_everything.ts +28 -28
- package/src/programmers/internal/check_native.ts +21 -21
- package/src/programmers/internal/check_number.ts +177 -177
- package/src/programmers/internal/check_object.ts +55 -55
- package/src/programmers/internal/check_string.ts +25 -25
- package/src/programmers/internal/check_string_tags.ts +9 -15
- package/src/programmers/internal/check_template.ts +6 -9
- package/src/programmers/internal/check_union_array_like.ts +272 -272
- package/src/programmers/internal/check_union_tuple.ts +35 -35
- package/src/programmers/internal/decode_union_object.ts +73 -73
- package/src/programmers/internal/feature_object_entries.ts +63 -63
- package/src/programmers/internal/get_comment_tags.ts +23 -23
- package/src/programmers/internal/metadata_to_pattern.ts +34 -34
- package/src/programmers/internal/prune_object_properties.ts +60 -60
- package/src/programmers/internal/random_custom.ts +30 -30
- package/src/programmers/internal/stringify_dynamic_properties.ts +168 -168
- package/src/programmers/internal/stringify_native.ts +8 -8
- package/src/programmers/internal/stringify_regular_properties.ts +84 -84
- package/src/programmers/internal/template_to_pattern.ts +15 -15
- package/src/schemas/IJsonApplication.ts +9 -9
- package/src/schemas/IJsonComponents.ts +26 -26
- package/src/schemas/IJsonSchema.ts +121 -121
- package/src/transform.ts +21 -21
- package/src/transformers/CallExpressionTransformer.ts +174 -174
- 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 +62 -62
- package/src/transformers/ImportTransformer.ts +66 -66
- package/src/transformers/NodeTransformer.ts +19 -19
- package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +119 -119
- package/src/transformers/features/miscellaneous/AssertCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/AssertPruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateAssertCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateAssertPruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateIsCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateIsPruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreatePruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateRandomTransformer.ts +41 -41
- package/src/transformers/features/miscellaneous/CreateValidateCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/CreateValidatePruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/IsCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/IsPruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/LiteralsTransformer.ts +30 -30
- package/src/transformers/features/miscellaneous/MetadataTransformer.ts +54 -54
- package/src/transformers/features/miscellaneous/PruneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/RandomTransformer.ts +46 -46
- package/src/transformers/features/miscellaneous/ValidateCloneTransformer.ts +9 -9
- package/src/transformers/features/miscellaneous/ValidatePruneTransformer.ts +9 -9
- package/src/transformers/features/parsers/AssertParseTransformer.ts +9 -9
- package/src/transformers/features/parsers/CreateAssertParseTransformer.ts +9 -9
- package/src/transformers/features/parsers/CreateIsParseTransformer.ts +9 -9
- package/src/transformers/features/parsers/CreateValidateParseTransformer.ts +9 -9
- package/src/transformers/features/parsers/IsParseTransformer.ts +9 -9
- package/src/transformers/features/parsers/ValidateParseTransformer.ts +9 -9
- package/src/transformers/features/stringifiers/AssertStringifyTransformer.ts +10 -10
- package/src/transformers/features/stringifiers/CreateAssertStringifyTransformer.ts +9 -9
- package/src/transformers/features/stringifiers/CreateIsStringifyTransformer.ts +9 -9
- package/src/transformers/features/stringifiers/CreateStringifyTransformer.ts +9 -9
- package/src/transformers/features/stringifiers/CreateValidateStringifyProgrammer.ts +11 -11
- package/src/transformers/features/stringifiers/IsStringifyTransformer.ts +9 -9
- package/src/transformers/features/stringifiers/StringifyTransformer.ts +9 -9
- package/src/transformers/features/stringifiers/ValidateStringifyTransformer.ts +10 -10
- package/src/transformers/features/validators/AssertTransformer.ts +11 -11
- package/src/transformers/features/validators/CreateAssertTransformer.ts +12 -12
- package/src/transformers/features/validators/CreateIsTransformer.ts +10 -10
- package/src/transformers/features/validators/CreateValidateTransformer.ts +12 -12
- package/src/transformers/features/validators/IsTransformer.ts +10 -10
- package/src/transformers/features/validators/ValidateTransformer.ts +11 -11
- package/src/transformers/internal/GenericTransformer.ts +99 -99
- package/src/typings/Atomic.ts +17 -17
- package/src/typings/ClassProperties.ts +5 -5
- package/src/typings/Customizable.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/RandomGenerator.ts +96 -96
- package/src/utils/Singleton.ts +17 -17
|
@@ -1,184 +1,184 @@
|
|
|
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 { AtomicPredicator } from "../helpers/AtomicPredicator";
|
|
7
|
-
import { application_array } from "./application_array";
|
|
8
|
-
import { application_boolean } from "./application_boolean";
|
|
9
|
-
import { application_constant } from "./application_constant";
|
|
10
|
-
import { application_native } from "./application_native";
|
|
11
|
-
import { application_number } from "./application_number";
|
|
12
|
-
import { application_object } from "./application_object";
|
|
13
|
-
import { application_string } from "./application_string";
|
|
14
|
-
import { application_templates } from "./application_templates";
|
|
15
|
-
import { application_tuple } from "./application_tuple";
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* @internal
|
|
19
|
-
*/
|
|
20
|
-
export const application_schema =
|
|
21
|
-
(options: ApplicationProgrammer.IOptions) =>
|
|
22
|
-
(components: IJsonComponents) =>
|
|
23
|
-
<BlockNever extends boolean>(blockNever: BlockNever) =>
|
|
24
|
-
(
|
|
25
|
-
meta: Metadata,
|
|
26
|
-
attribute: IJsonSchema.IAttribute,
|
|
27
|
-
): BlockNever extends true ? IJsonSchema | null : IJsonSchema => {
|
|
28
|
-
// VULNERABLE CASE
|
|
29
|
-
if (meta.any === true) return {};
|
|
30
|
-
else if (meta.nullable && meta.empty())
|
|
31
|
-
return { type: "null", ...attribute };
|
|
32
|
-
|
|
33
|
-
//----
|
|
34
|
-
// GATHER UNION SCHEMAS
|
|
35
|
-
//----
|
|
36
|
-
const union: IJsonSchema[] = [];
|
|
37
|
-
|
|
38
|
-
// toJSON() METHOD
|
|
39
|
-
if (meta.resolved !== null) {
|
|
40
|
-
const resolved = application_schema(options)(components)(
|
|
41
|
-
blockNever,
|
|
42
|
-
)(meta.resolved, attribute);
|
|
43
|
-
if (resolved !== null) union.push(resolved);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// ATOMIC TYPES
|
|
47
|
-
if (meta.templates.length && AtomicPredicator.template(meta))
|
|
48
|
-
union.push(application_templates(meta, attribute));
|
|
49
|
-
for (const constant of meta.constants)
|
|
50
|
-
if (constant.type === "bigint") throw new Error(NO_BIGINT);
|
|
51
|
-
else if (
|
|
52
|
-
(constant.type === "string" && meta.templates.length) ||
|
|
53
|
-
AtomicPredicator.constant(meta)(constant.type) === false
|
|
54
|
-
)
|
|
55
|
-
continue;
|
|
56
|
-
else
|
|
57
|
-
union.push(
|
|
58
|
-
application_constant(constant, meta.nullable, attribute),
|
|
59
|
-
);
|
|
60
|
-
for (const type of meta.atomics)
|
|
61
|
-
if (type === "bigint") throw new Error(NO_BIGINT);
|
|
62
|
-
else if (AtomicPredicator.atomic(meta)(type) === false) continue;
|
|
63
|
-
else
|
|
64
|
-
union.push(
|
|
65
|
-
type === "string"
|
|
66
|
-
? application_string(meta, attribute)
|
|
67
|
-
: type === "boolean"
|
|
68
|
-
? application_boolean(meta.nullable, attribute)
|
|
69
|
-
: application_number(meta.nullable, attribute),
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
// ARRAY
|
|
73
|
-
for (const schema of meta.arrays.values())
|
|
74
|
-
union.push(
|
|
75
|
-
application_array(options)(components)()(
|
|
76
|
-
schema,
|
|
77
|
-
meta.nullable,
|
|
78
|
-
attribute,
|
|
79
|
-
),
|
|
80
|
-
);
|
|
81
|
-
|
|
82
|
-
// TUPLE
|
|
83
|
-
for (const items of meta.tuples) {
|
|
84
|
-
const tuple: IJsonSchema.ITuple = application_tuple(options)(
|
|
85
|
-
components,
|
|
86
|
-
)(items, meta.nullable, attribute);
|
|
87
|
-
if (options.purpose === "swagger" && items.length === 0)
|
|
88
|
-
throw new Error(
|
|
89
|
-
"Error on typia.application(): swagger does not support zero length tuple type.",
|
|
90
|
-
);
|
|
91
|
-
else if (
|
|
92
|
-
options.purpose === "ajv" &&
|
|
93
|
-
!items[items.length - 1]?.rest
|
|
94
|
-
)
|
|
95
|
-
union.push(tuple);
|
|
96
|
-
else {
|
|
97
|
-
// SWAGGER DOES NOT SUPPORT TUPLE TYPE YET
|
|
98
|
-
const merged: Metadata = items.reduce((x, y) =>
|
|
99
|
-
Metadata.merge(x, y),
|
|
100
|
-
);
|
|
101
|
-
union.push(
|
|
102
|
-
application_array(options)(components)(tuple)(
|
|
103
|
-
merged,
|
|
104
|
-
merged?.nullable || false,
|
|
105
|
-
attribute,
|
|
106
|
-
),
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
// NATIVES
|
|
112
|
-
for (const native of meta.natives)
|
|
113
|
-
if (AtomicPredicator.native(native))
|
|
114
|
-
union.push(
|
|
115
|
-
native === "String"
|
|
116
|
-
? application_string(meta, attribute)
|
|
117
|
-
: native === "Boolean"
|
|
118
|
-
? application_boolean(meta.nullable, attribute)
|
|
119
|
-
: application_number(meta.nullable, attribute),
|
|
120
|
-
);
|
|
121
|
-
else
|
|
122
|
-
union.push(
|
|
123
|
-
application_native(options)(components)(native)(
|
|
124
|
-
meta.nullable,
|
|
125
|
-
attribute,
|
|
126
|
-
),
|
|
127
|
-
);
|
|
128
|
-
if (meta.sets.length)
|
|
129
|
-
union.push(
|
|
130
|
-
application_native(options)(components)(`Set`)(
|
|
131
|
-
meta.nullable,
|
|
132
|
-
attribute,
|
|
133
|
-
),
|
|
134
|
-
);
|
|
135
|
-
if (meta.maps.length)
|
|
136
|
-
union.push(
|
|
137
|
-
application_native(options)(components)(`Map`)(
|
|
138
|
-
meta.nullable,
|
|
139
|
-
attribute,
|
|
140
|
-
),
|
|
141
|
-
);
|
|
142
|
-
|
|
143
|
-
// OBJECT
|
|
144
|
-
for (const obj of meta.objects) {
|
|
145
|
-
const key: string = obj.name + (meta.nullable ? ".Nullable" : "");
|
|
146
|
-
application_object(options)(components)(key, obj, meta.nullable);
|
|
147
|
-
union.push(
|
|
148
|
-
(options.purpose === "ajv" && obj.recursive
|
|
149
|
-
? recursive
|
|
150
|
-
: reference)(`${options.prefix}/${key}`, attribute),
|
|
151
|
-
);
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
//----
|
|
155
|
-
// RETURNS
|
|
156
|
-
//----
|
|
157
|
-
if (union.length === 0) return blockNever === true ? null! : {};
|
|
158
|
-
else if (union.length === 1) return union[0]!;
|
|
159
|
-
return { oneOf: union, ...attribute };
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* @internal
|
|
164
|
-
*/
|
|
165
|
-
const reference = (
|
|
166
|
-
$ref: string,
|
|
167
|
-
attribute: IJsonSchema.IAttribute,
|
|
168
|
-
): IJsonSchema.IReference => ({
|
|
169
|
-
$ref,
|
|
170
|
-
...attribute,
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
/**
|
|
174
|
-
* @internal
|
|
175
|
-
*/
|
|
176
|
-
const recursive = (
|
|
177
|
-
$recursiveRef: string,
|
|
178
|
-
attribute: IJsonSchema.IAttribute,
|
|
179
|
-
): IJsonSchema.IRecursiveReference => ({
|
|
180
|
-
$recursiveRef,
|
|
181
|
-
...attribute,
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
const NO_BIGINT = "Error on typia.application(): does not allow bigint type.";
|
|
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 { AtomicPredicator } from "../helpers/AtomicPredicator";
|
|
7
|
+
import { application_array } from "./application_array";
|
|
8
|
+
import { application_boolean } from "./application_boolean";
|
|
9
|
+
import { application_constant } from "./application_constant";
|
|
10
|
+
import { application_native } from "./application_native";
|
|
11
|
+
import { application_number } from "./application_number";
|
|
12
|
+
import { application_object } from "./application_object";
|
|
13
|
+
import { application_string } from "./application_string";
|
|
14
|
+
import { application_templates } from "./application_templates";
|
|
15
|
+
import { application_tuple } from "./application_tuple";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
export const application_schema =
|
|
21
|
+
(options: ApplicationProgrammer.IOptions) =>
|
|
22
|
+
(components: IJsonComponents) =>
|
|
23
|
+
<BlockNever extends boolean>(blockNever: BlockNever) =>
|
|
24
|
+
(
|
|
25
|
+
meta: Metadata,
|
|
26
|
+
attribute: IJsonSchema.IAttribute,
|
|
27
|
+
): BlockNever extends true ? IJsonSchema | null : IJsonSchema => {
|
|
28
|
+
// VULNERABLE CASE
|
|
29
|
+
if (meta.any === true) return {};
|
|
30
|
+
else if (meta.nullable && meta.empty())
|
|
31
|
+
return { type: "null", ...attribute };
|
|
32
|
+
|
|
33
|
+
//----
|
|
34
|
+
// GATHER UNION SCHEMAS
|
|
35
|
+
//----
|
|
36
|
+
const union: IJsonSchema[] = [];
|
|
37
|
+
|
|
38
|
+
// toJSON() METHOD
|
|
39
|
+
if (meta.resolved !== null) {
|
|
40
|
+
const resolved = application_schema(options)(components)(
|
|
41
|
+
blockNever,
|
|
42
|
+
)(meta.resolved, attribute);
|
|
43
|
+
if (resolved !== null) union.push(resolved);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// ATOMIC TYPES
|
|
47
|
+
if (meta.templates.length && AtomicPredicator.template(meta))
|
|
48
|
+
union.push(application_templates(meta, attribute));
|
|
49
|
+
for (const constant of meta.constants)
|
|
50
|
+
if (constant.type === "bigint") throw new Error(NO_BIGINT);
|
|
51
|
+
else if (
|
|
52
|
+
(constant.type === "string" && meta.templates.length) ||
|
|
53
|
+
AtomicPredicator.constant(meta)(constant.type) === false
|
|
54
|
+
)
|
|
55
|
+
continue;
|
|
56
|
+
else
|
|
57
|
+
union.push(
|
|
58
|
+
application_constant(constant, meta.nullable, attribute),
|
|
59
|
+
);
|
|
60
|
+
for (const type of meta.atomics)
|
|
61
|
+
if (type === "bigint") throw new Error(NO_BIGINT);
|
|
62
|
+
else if (AtomicPredicator.atomic(meta)(type) === false) continue;
|
|
63
|
+
else
|
|
64
|
+
union.push(
|
|
65
|
+
type === "string"
|
|
66
|
+
? application_string(meta, attribute)
|
|
67
|
+
: type === "boolean"
|
|
68
|
+
? application_boolean(meta.nullable, attribute)
|
|
69
|
+
: application_number(meta.nullable, attribute),
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
// ARRAY
|
|
73
|
+
for (const schema of meta.arrays.values())
|
|
74
|
+
union.push(
|
|
75
|
+
application_array(options)(components)()(
|
|
76
|
+
schema,
|
|
77
|
+
meta.nullable,
|
|
78
|
+
attribute,
|
|
79
|
+
),
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
// TUPLE
|
|
83
|
+
for (const items of meta.tuples) {
|
|
84
|
+
const tuple: IJsonSchema.ITuple = application_tuple(options)(
|
|
85
|
+
components,
|
|
86
|
+
)(items, meta.nullable, attribute);
|
|
87
|
+
if (options.purpose === "swagger" && items.length === 0)
|
|
88
|
+
throw new Error(
|
|
89
|
+
"Error on typia.application(): swagger does not support zero length tuple type.",
|
|
90
|
+
);
|
|
91
|
+
else if (
|
|
92
|
+
options.purpose === "ajv" &&
|
|
93
|
+
!items[items.length - 1]?.rest
|
|
94
|
+
)
|
|
95
|
+
union.push(tuple);
|
|
96
|
+
else {
|
|
97
|
+
// SWAGGER DOES NOT SUPPORT TUPLE TYPE YET
|
|
98
|
+
const merged: Metadata = items.reduce((x, y) =>
|
|
99
|
+
Metadata.merge(x, y),
|
|
100
|
+
);
|
|
101
|
+
union.push(
|
|
102
|
+
application_array(options)(components)(tuple)(
|
|
103
|
+
merged,
|
|
104
|
+
merged?.nullable || false,
|
|
105
|
+
attribute,
|
|
106
|
+
),
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// NATIVES
|
|
112
|
+
for (const native of meta.natives)
|
|
113
|
+
if (AtomicPredicator.native(native))
|
|
114
|
+
union.push(
|
|
115
|
+
native === "String"
|
|
116
|
+
? application_string(meta, attribute)
|
|
117
|
+
: native === "Boolean"
|
|
118
|
+
? application_boolean(meta.nullable, attribute)
|
|
119
|
+
: application_number(meta.nullable, attribute),
|
|
120
|
+
);
|
|
121
|
+
else
|
|
122
|
+
union.push(
|
|
123
|
+
application_native(options)(components)(native)(
|
|
124
|
+
meta.nullable,
|
|
125
|
+
attribute,
|
|
126
|
+
),
|
|
127
|
+
);
|
|
128
|
+
if (meta.sets.length)
|
|
129
|
+
union.push(
|
|
130
|
+
application_native(options)(components)(`Set`)(
|
|
131
|
+
meta.nullable,
|
|
132
|
+
attribute,
|
|
133
|
+
),
|
|
134
|
+
);
|
|
135
|
+
if (meta.maps.length)
|
|
136
|
+
union.push(
|
|
137
|
+
application_native(options)(components)(`Map`)(
|
|
138
|
+
meta.nullable,
|
|
139
|
+
attribute,
|
|
140
|
+
),
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
// OBJECT
|
|
144
|
+
for (const obj of meta.objects) {
|
|
145
|
+
const key: string = obj.name + (meta.nullable ? ".Nullable" : "");
|
|
146
|
+
application_object(options)(components)(key, obj, meta.nullable);
|
|
147
|
+
union.push(
|
|
148
|
+
(options.purpose === "ajv" && obj.recursive
|
|
149
|
+
? recursive
|
|
150
|
+
: reference)(`${options.prefix}/${key}`, attribute),
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
//----
|
|
155
|
+
// RETURNS
|
|
156
|
+
//----
|
|
157
|
+
if (union.length === 0) return blockNever === true ? null! : {};
|
|
158
|
+
else if (union.length === 1) return union[0]!;
|
|
159
|
+
return { oneOf: union, ...attribute };
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* @internal
|
|
164
|
+
*/
|
|
165
|
+
const reference = (
|
|
166
|
+
$ref: string,
|
|
167
|
+
attribute: IJsonSchema.IAttribute,
|
|
168
|
+
): IJsonSchema.IReference => ({
|
|
169
|
+
$ref,
|
|
170
|
+
...attribute,
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* @internal
|
|
175
|
+
*/
|
|
176
|
+
const recursive = (
|
|
177
|
+
$recursiveRef: string,
|
|
178
|
+
attribute: IJsonSchema.IAttribute,
|
|
179
|
+
): IJsonSchema.IRecursiveReference => ({
|
|
180
|
+
$recursiveRef,
|
|
181
|
+
...attribute,
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
const NO_BIGINT = "Error on typia.application(): does not allow bigint type.";
|
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import { IMetadataTag } from "../../metadata/IMetadataTag";
|
|
2
|
-
import { Metadata } from "../../metadata/Metadata";
|
|
3
|
-
import { IJsonSchema } from "../../schemas/IJsonSchema";
|
|
4
|
-
|
|
5
|
-
import { application_default_string } from "./application_default_string";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @internal
|
|
9
|
-
*/
|
|
10
|
-
export const application_string = (
|
|
11
|
-
meta: Metadata,
|
|
12
|
-
attribute: IJsonSchema.IAttribute,
|
|
13
|
-
): IJsonSchema.IString => {
|
|
14
|
-
const output: IJsonSchema.IString = {
|
|
15
|
-
type: "string",
|
|
16
|
-
nullable: meta.nullable,
|
|
17
|
-
...attribute,
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
// FORMAT TAG OF METADATA
|
|
21
|
-
const formatJsdocTag = attribute["x-typia-jsDocTags"]?.find(
|
|
22
|
-
(tag) => tag.name === "format",
|
|
23
|
-
);
|
|
24
|
-
if (formatJsdocTag?.text?.length)
|
|
25
|
-
output.format = formatJsdocTag?.text.map((t) => t.text).join(" ");
|
|
26
|
-
|
|
27
|
-
// REGULAR TAGS COMPATIBLE WITH JSON-SCHEMA
|
|
28
|
-
for (const tag of attribute["x-typia-metaTags"] ?? []) {
|
|
29
|
-
// RANGE
|
|
30
|
-
if (tag.kind === "minLength") output.minLength = tag.value;
|
|
31
|
-
else if (tag.kind === "maxLength") output.maxLength = tag.value;
|
|
32
|
-
// FORMAT AND PATTERN
|
|
33
|
-
else if (tag.kind === "format") output.format = emendFormat(tag.value);
|
|
34
|
-
else if (tag.kind === "pattern") output.pattern = tag.value;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// DEFAULT CONFIGURATION
|
|
38
|
-
output.default = application_default_string(meta, attribute)(output);
|
|
39
|
-
|
|
40
|
-
// RETURNS
|
|
41
|
-
return output;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
const emendFormat = (tag: IMetadataTag.IFormat["value"]) =>
|
|
45
|
-
tag === "datetime" ? "date-time" : tag;
|
|
1
|
+
import { IMetadataTag } from "../../metadata/IMetadataTag";
|
|
2
|
+
import { Metadata } from "../../metadata/Metadata";
|
|
3
|
+
import { IJsonSchema } from "../../schemas/IJsonSchema";
|
|
4
|
+
|
|
5
|
+
import { application_default_string } from "./application_default_string";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export const application_string = (
|
|
11
|
+
meta: Metadata,
|
|
12
|
+
attribute: IJsonSchema.IAttribute,
|
|
13
|
+
): IJsonSchema.IString => {
|
|
14
|
+
const output: IJsonSchema.IString = {
|
|
15
|
+
type: "string",
|
|
16
|
+
nullable: meta.nullable,
|
|
17
|
+
...attribute,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// FORMAT TAG OF METADATA
|
|
21
|
+
const formatJsdocTag = attribute["x-typia-jsDocTags"]?.find(
|
|
22
|
+
(tag) => tag.name === "format",
|
|
23
|
+
);
|
|
24
|
+
if (formatJsdocTag?.text?.length)
|
|
25
|
+
output.format = formatJsdocTag?.text.map((t) => t.text).join(" ");
|
|
26
|
+
|
|
27
|
+
// REGULAR TAGS COMPATIBLE WITH JSON-SCHEMA
|
|
28
|
+
for (const tag of attribute["x-typia-metaTags"] ?? []) {
|
|
29
|
+
// RANGE
|
|
30
|
+
if (tag.kind === "minLength") output.minLength = tag.value;
|
|
31
|
+
else if (tag.kind === "maxLength") output.maxLength = tag.value;
|
|
32
|
+
// FORMAT AND PATTERN
|
|
33
|
+
else if (tag.kind === "format") output.format = emendFormat(tag.value);
|
|
34
|
+
else if (tag.kind === "pattern") output.pattern = tag.value;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// DEFAULT CONFIGURATION
|
|
38
|
+
output.default = application_default_string(meta, attribute)(output);
|
|
39
|
+
|
|
40
|
+
// RETURNS
|
|
41
|
+
return output;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const emendFormat = (tag: IMetadataTag.IFormat["value"]) =>
|
|
45
|
+
tag === "datetime" ? "date-time" : tag;
|
|
@@ -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,29 +1,29 @@
|
|
|
1
|
-
import { Metadata } from "../../metadata/Metadata";
|
|
2
|
-
import { IJsonComponents } from "../../schemas/IJsonComponents";
|
|
3
|
-
import { IJsonSchema } from "../../schemas/IJsonSchema";
|
|
4
|
-
|
|
5
|
-
import { ApplicationProgrammer } from "../ApplicationProgrammer";
|
|
6
|
-
import { application_schema } from "./application_schema";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @internal
|
|
10
|
-
*/
|
|
11
|
-
export const application_tuple =
|
|
12
|
-
(options: ApplicationProgrammer.IOptions) =>
|
|
13
|
-
(components: IJsonComponents) =>
|
|
14
|
-
(
|
|
15
|
-
items: Array<Metadata>,
|
|
16
|
-
nullable: boolean,
|
|
17
|
-
attribute: IJsonSchema.IAttribute,
|
|
18
|
-
): IJsonSchema.ITuple => ({
|
|
19
|
-
type: "array",
|
|
20
|
-
items: items.map((meta, i) =>
|
|
21
|
-
application_schema(options)(components)(false)(meta.rest ?? meta, {
|
|
22
|
-
...attribute,
|
|
23
|
-
"x-typia-rest":
|
|
24
|
-
i === items.length - 1 ? meta.rest !== null : undefined,
|
|
25
|
-
}),
|
|
26
|
-
),
|
|
27
|
-
nullable,
|
|
28
|
-
...attribute,
|
|
29
|
-
});
|
|
1
|
+
import { Metadata } from "../../metadata/Metadata";
|
|
2
|
+
import { IJsonComponents } from "../../schemas/IJsonComponents";
|
|
3
|
+
import { IJsonSchema } from "../../schemas/IJsonSchema";
|
|
4
|
+
|
|
5
|
+
import { ApplicationProgrammer } from "../ApplicationProgrammer";
|
|
6
|
+
import { application_schema } from "./application_schema";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
export const application_tuple =
|
|
12
|
+
(options: ApplicationProgrammer.IOptions) =>
|
|
13
|
+
(components: IJsonComponents) =>
|
|
14
|
+
(
|
|
15
|
+
items: Array<Metadata>,
|
|
16
|
+
nullable: boolean,
|
|
17
|
+
attribute: IJsonSchema.IAttribute,
|
|
18
|
+
): IJsonSchema.ITuple => ({
|
|
19
|
+
type: "array",
|
|
20
|
+
items: items.map((meta, i) =>
|
|
21
|
+
application_schema(options)(components)(false)(meta.rest ?? meta, {
|
|
22
|
+
...attribute,
|
|
23
|
+
"x-typia-rest":
|
|
24
|
+
i === items.length - 1 ? meta.rest !== null : undefined,
|
|
25
|
+
}),
|
|
26
|
+
),
|
|
27
|
+
nullable,
|
|
28
|
+
...attribute,
|
|
29
|
+
});
|
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
import ts from "typescript";
|
|
2
|
-
|
|
3
|
-
import { ExpressionFactory } from "../../factories/ExpressionFactory";
|
|
4
|
-
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
5
|
-
|
|
6
|
-
import { IJsDocTagInfo } from "../../metadata/IJsDocTagInfo";
|
|
7
|
-
import { IMetadataTag } from "../../metadata/IMetadataTag";
|
|
8
|
-
|
|
9
|
-
import { FunctionImporter } from "../helpers/FunctionImporeter";
|
|
10
|
-
import { ICheckEntry } from "../helpers/ICheckEntry";
|
|
11
|
-
import { check_array_length } from "./check_array_length";
|
|
12
|
-
import { check_custom } from "./check_custom";
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @internal
|
|
16
|
-
*/
|
|
17
|
-
export const check_array =
|
|
18
|
-
(importer: FunctionImporter) =>
|
|
19
|
-
(metaTags: IMetadataTag[]) =>
|
|
20
|
-
(jsDocTags: IJsDocTagInfo[]) =>
|
|
21
|
-
(input: ts.Expression): ICheckEntry => ({
|
|
22
|
-
expression: ExpressionFactory.isArray(input),
|
|
23
|
-
tags: [
|
|
24
|
-
...check_array_length(metaTags)(
|
|
25
|
-
IdentifierFactory.join(input, "length"),
|
|
26
|
-
),
|
|
27
|
-
...check_custom("array", "Array")(importer)(jsDocTags)(input),
|
|
28
|
-
// check custom array for legacy (3.7.0)
|
|
29
|
-
],
|
|
30
|
-
});
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
|
|
3
|
+
import { ExpressionFactory } from "../../factories/ExpressionFactory";
|
|
4
|
+
import { IdentifierFactory } from "../../factories/IdentifierFactory";
|
|
5
|
+
|
|
6
|
+
import { IJsDocTagInfo } from "../../metadata/IJsDocTagInfo";
|
|
7
|
+
import { IMetadataTag } from "../../metadata/IMetadataTag";
|
|
8
|
+
|
|
9
|
+
import { FunctionImporter } from "../helpers/FunctionImporeter";
|
|
10
|
+
import { ICheckEntry } from "../helpers/ICheckEntry";
|
|
11
|
+
import { check_array_length } from "./check_array_length";
|
|
12
|
+
import { check_custom } from "./check_custom";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export const check_array =
|
|
18
|
+
(importer: FunctionImporter) =>
|
|
19
|
+
(metaTags: IMetadataTag[]) =>
|
|
20
|
+
(jsDocTags: IJsDocTagInfo[]) =>
|
|
21
|
+
(input: ts.Expression): ICheckEntry => ({
|
|
22
|
+
expression: ExpressionFactory.isArray(input),
|
|
23
|
+
tags: [
|
|
24
|
+
...check_array_length(metaTags)(
|
|
25
|
+
IdentifierFactory.join(input, "length"),
|
|
26
|
+
),
|
|
27
|
+
...check_custom("array", "Array")(importer)(jsDocTags)(input),
|
|
28
|
+
// check custom array for legacy (3.7.0)
|
|
29
|
+
],
|
|
30
|
+
});
|