typia 4.0.0-dev.20230520 → 4.0.0-dev.20230527
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/lib/transform.js +1 -1
- package/lib/transform.js.map +1 -1
- package/package.json +1 -1
- package/src/CustomValidatorMap.ts +126 -126
- package/src/IRandomGenerator.ts +33 -33
- package/src/IValidation.ts +21 -21
- package/src/Primitive.ts +123 -123
- package/src/TypeGuardError.ts +36 -36
- package/src/executable/TypiaGenerateWizard.ts +85 -85
- package/src/executable/TypiaSetupWizard.ts +133 -133
- 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 +71 -71
- package/src/executable/setup/PluginConfigurator.ts +70 -70
- package/src/executable/typia.ts +52 -52
- package/src/factories/CommentFactory.ts +14 -14
- package/src/factories/ExpressionFactory.ts +77 -77
- package/src/factories/IdentifierFactory.ts +62 -62
- package/src/factories/LiteralFactory.ts +57 -57
- package/src/factories/MetadataCollection.ts +123 -123
- package/src/factories/MetadataFactory.ts +53 -53
- package/src/factories/MetadataTagFactory.ts +295 -295
- package/src/factories/StatementFactory.ts +20 -20
- package/src/factories/TemplateFactory.ts +64 -64
- package/src/factories/TypeFactory.ts +145 -145
- package/src/factories/ValueFactory.ts +15 -15
- package/src/factories/internal/metadata/MetadataHelper.ts +12 -12
- package/src/factories/internal/metadata/emplace_metadata_object.ts +152 -152
- package/src/factories/internal/metadata/explore_metadata.ts +93 -93
- package/src/factories/internal/metadata/iterate_metadata.ts +63 -63
- package/src/factories/internal/metadata/iterate_metadata_array.ts +32 -32
- 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 +62 -62
- package/src/factories/internal/metadata/iterate_metadata_map.ts +41 -41
- package/src/factories/internal/metadata/iterate_metadata_native.ts +217 -217
- package/src/factories/internal/metadata/iterate_metadata_object.ts +51 -51
- package/src/factories/internal/metadata/iterate_metadata_resolve.ts +30 -30
- package/src/factories/internal/metadata/iterate_metadata_set.ts +36 -36
- package/src/factories/internal/metadata/iterate_metadata_template.ts +40 -40
- package/src/factories/internal/metadata/iterate_metadata_tuple.ts +51 -51
- package/src/factories/internal/metadata/iterate_metadata_union.ts +59 -59
- package/src/functional/$any.ts +2 -2
- package/src/functional/$dictionary.ts +25 -25
- package/src/functional/$every.ts +11 -11
- package/src/functional/$guard.ts +35 -35
- package/src/functional/$is_between.ts +2 -2
- package/src/functional/$is_custom.ts +14 -14
- package/src/functional/$is_date.ts +3 -3
- package/src/functional/$is_datetime.ts +2 -2
- package/src/functional/$is_email.ts +4 -4
- package/src/functional/$is_ipv4.ts +4 -4
- package/src/functional/$is_ipv6.ts +4 -4
- package/src/functional/$is_url.ts +4 -4
- package/src/functional/$is_uuid.ts +4 -4
- package/src/functional/$join.ts +46 -46
- 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 +5 -5
- 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 +26 -26
- 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 +539 -539
- package/src/metadata/MetadataConstant.ts +3 -3
- package/src/metadata/MetadataObject.ts +127 -127
- package/src/metadata/MetadataProperty.ts +64 -64
- package/src/module.ts +2038 -2038
- package/src/programmers/ApplicationProgrammer.ts +48 -48
- package/src/programmers/AssertCloneProgrammer.ts +68 -68
- package/src/programmers/AssertParseProgrammer.ts +66 -66
- package/src/programmers/AssertProgrammer.ts +274 -274
- package/src/programmers/AssertPruneProgrammer.ts +73 -73
- package/src/programmers/AssertStringifyProgrammer.ts +66 -66
- package/src/programmers/CheckerProgrammer.ts +897 -897
- package/src/programmers/CloneProgrammer.ts +387 -387
- package/src/programmers/FeatureProgrammer.ts +510 -510
- package/src/programmers/IsCloneProgrammer.ts +79 -79
- package/src/programmers/IsParseProgrammer.ts +72 -72
- package/src/programmers/IsProgrammer.ts +223 -223
- package/src/programmers/IsPruneProgrammer.ts +83 -83
- package/src/programmers/IsStringifyProgrammer.ts +77 -77
- package/src/programmers/LiteralsProgrammer.ts +65 -65
- package/src/programmers/PruneProgrammer.ts +348 -348
- package/src/programmers/RandomProgrammer.ts +444 -444
- package/src/programmers/StringifyProgrammer.ts +758 -758
- package/src/programmers/TypiaProgrammer.ts +141 -141
- package/src/programmers/ValidateCloneProgrammer.ts +93 -93
- package/src/programmers/ValidateParseProgrammer.ts +78 -78
- package/src/programmers/ValidateProgrammer.ts +317 -317
- package/src/programmers/ValidatePruneProgrammer.ts +86 -86
- package/src/programmers/ValidateStringifyProgrammer.ts +93 -93
- package/src/programmers/helpers/AtomicPredicator.ts +31 -31
- package/src/programmers/helpers/CloneJoiner.ts +138 -138
- package/src/programmers/helpers/FunctionImporeter.ts +56 -56
- package/src/programmers/helpers/ICheckEntry.ts +12 -12
- package/src/programmers/helpers/IExpressionEntry.ts +12 -12
- package/src/programmers/helpers/OptionPredicator.ts +15 -15
- package/src/programmers/helpers/PruneJoiner.ts +156 -156
- package/src/programmers/helpers/RandomJoiner.ts +165 -165
- package/src/programmers/helpers/RandomRanger.ts +218 -218
- package/src/programmers/helpers/StringifyJoinder.ts +118 -118
- package/src/programmers/helpers/StringifyPredicator.ts +12 -12
- package/src/programmers/helpers/UnionExplorer.ts +281 -281
- package/src/programmers/helpers/UnionPredicator.ts +81 -81
- package/src/programmers/helpers/disable_function_importer_declare.ts +21 -21
- package/src/programmers/internal/JSON_SCHEMA_PREFIX.ts +1 -1
- package/src/programmers/internal/application_array.ts +32 -32
- package/src/programmers/internal/application_boolean.ts +15 -15
- package/src/programmers/internal/application_constant.ts +26 -26
- package/src/programmers/internal/application_default.ts +17 -17
- package/src/programmers/internal/application_default_string.ts +33 -33
- package/src/programmers/internal/application_native.ts +36 -36
- package/src/programmers/internal/application_number.ts +71 -71
- package/src/programmers/internal/application_object.ts +162 -162
- package/src/programmers/internal/application_schema.ts +198 -198
- package/src/programmers/internal/application_string.ts +44 -44
- package/src/programmers/internal/application_templates.ts +25 -25
- package/src/programmers/internal/application_tuple.ts +27 -27
- package/src/programmers/internal/check_array.ts +31 -31
- package/src/programmers/internal/check_array_length.ts +35 -35
- package/src/programmers/internal/check_bigint.ts +95 -95
- package/src/programmers/internal/check_custom.ts +32 -32
- package/src/programmers/internal/check_dynamic_properties.ts +198 -198
- package/src/programmers/internal/check_everything.ts +28 -28
- package/src/programmers/internal/check_native.ts +22 -22
- package/src/programmers/internal/check_number.ts +177 -177
- package/src/programmers/internal/check_object.ts +65 -65
- package/src/programmers/internal/check_string.ts +27 -27
- package/src/programmers/internal/check_string_tags.ts +68 -68
- package/src/programmers/internal/check_template.ts +57 -57
- package/src/programmers/internal/check_union_array_like.ts +273 -273
- package/src/programmers/internal/check_union_tuple.ts +34 -34
- package/src/programmers/internal/decode_union_object.ts +75 -75
- package/src/programmers/internal/feature_object_entries.ts +64 -64
- 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 +63 -63
- package/src/programmers/internal/random_custom.ts +30 -30
- package/src/programmers/internal/stringify_dynamic_properties.ts +173 -173
- package/src/programmers/internal/stringify_native.ts +7 -7
- package/src/programmers/internal/stringify_regular_properties.ts +89 -89
- package/src/programmers/internal/template_to_pattern.ts +15 -15
- package/src/schemas/IJsonApplication.ts +13 -13
- package/src/schemas/IJsonComponents.ts +33 -33
- package/src/schemas/IJsonSchema.ts +134 -134
- package/src/transform.ts +39 -39
- package/src/transformers/CallExpressionTransformer.ts +183 -183
- package/src/transformers/FileTransformer.ts +50 -50
- package/src/transformers/IProject.ts +18 -18
- package/src/transformers/ITransformOptions.ts +62 -62
- package/src/transformers/ImportTransformer.ts +74 -74
- package/src/transformers/NodeTransformer.ts +13 -13
- package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +107 -107
- 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 +43 -43
- 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 +31 -31
- package/src/transformers/features/miscellaneous/MetadataTransformer.ts +56 -56
- 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 +12 -12
- 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 +12 -12
- 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 +13 -13
- package/src/transformers/features/validators/CreateIsTransformer.ts +11 -11
- package/src/transformers/features/validators/CreateValidateTransformer.ts +13 -13
- package/src/transformers/features/validators/IsTransformer.ts +11 -11
- package/src/transformers/features/validators/ValidateTransformer.ts +11 -11
- package/src/transformers/internal/GenericTransformer.ts +101 -101
- 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 +44 -44
- package/src/utils/Escaper.ts +45 -45
- package/src/utils/MapUtil.ts +12 -12
- package/src/utils/PatternUtil.ts +30 -30
- package/src/utils/RandomGenerator.ts +81 -81
- package/src/utils/Singleton.ts +17 -17
- package/src/utils/TsNodeUtil.ts +17 -17
- package/src/utils/TsSymbolUtil.ts +153 -153
- package/src/utils/TsTypeUtil.ts +38 -38
|
@@ -1,198 +1,198 @@
|
|
|
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 { JSON_SCHEMA_PREFIX } from "./JSON_SCHEMA_PREFIX";
|
|
8
|
-
import { application_array } from "./application_array";
|
|
9
|
-
import { application_boolean } from "./application_boolean";
|
|
10
|
-
import { application_constant } from "./application_constant";
|
|
11
|
-
import { application_native } from "./application_native";
|
|
12
|
-
import { application_number } from "./application_number";
|
|
13
|
-
import { application_object } from "./application_object";
|
|
14
|
-
import { application_string } from "./application_string";
|
|
15
|
-
import { application_templates } from "./application_templates";
|
|
16
|
-
import { application_tuple } from "./application_tuple";
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* @internal
|
|
20
|
-
*/
|
|
21
|
-
export const application_schema =
|
|
22
|
-
(options: ApplicationProgrammer.IOptions) =>
|
|
23
|
-
<BlockNever extends boolean>(blockNever: BlockNever) =>
|
|
24
|
-
(components: IJsonComponents) =>
|
|
25
|
-
(meta: Metadata) =>
|
|
26
|
-
(
|
|
27
|
-
attribute: IJsonSchema.IAttribute,
|
|
28
|
-
): BlockNever extends true ? IJsonSchema | null : IJsonSchema => {
|
|
29
|
-
// VULNERABLE CASE
|
|
30
|
-
if (meta.any === true)
|
|
31
|
-
return {
|
|
32
|
-
...attribute,
|
|
33
|
-
type: undefined,
|
|
34
|
-
};
|
|
35
|
-
else if (meta.nullable && meta.empty())
|
|
36
|
-
return { type: "null", ...attribute };
|
|
37
|
-
|
|
38
|
-
//----
|
|
39
|
-
// GATHER UNION SCHEMAS
|
|
40
|
-
//----
|
|
41
|
-
const union: IJsonSchema[] = [];
|
|
42
|
-
if (meta.nullable && options.purpose !== "swagger")
|
|
43
|
-
union.push({
|
|
44
|
-
...attribute,
|
|
45
|
-
type: "null",
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
const insert =
|
|
49
|
-
meta.nullable && options.purpose === "swagger"
|
|
50
|
-
? (significant: IJsonSchema.ISignificant<any>) =>
|
|
51
|
-
union.push({
|
|
52
|
-
...significant,
|
|
53
|
-
nullable: true,
|
|
54
|
-
})
|
|
55
|
-
: (schema: IJsonSchema) => union.push(schema);
|
|
56
|
-
|
|
57
|
-
// toJSON() METHOD
|
|
58
|
-
if (meta.resolved !== null) {
|
|
59
|
-
const resolved = application_schema(options)(blockNever)(
|
|
60
|
-
components,
|
|
61
|
-
)(meta.resolved)(attribute);
|
|
62
|
-
if (resolved !== null) union.push(resolved);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// ATOMIC TYPES
|
|
66
|
-
if (meta.templates.length && AtomicPredicator.template(meta))
|
|
67
|
-
insert(application_templates(meta)(attribute));
|
|
68
|
-
for (const constant of meta.constants)
|
|
69
|
-
if (constant.type === "bigint") throw new Error(NO_BIGINT);
|
|
70
|
-
else if (
|
|
71
|
-
(constant.type === "string" && meta.templates.length) ||
|
|
72
|
-
AtomicPredicator.constant(meta)(constant.type) === false
|
|
73
|
-
)
|
|
74
|
-
continue;
|
|
75
|
-
else insert(application_constant(constant)(attribute));
|
|
76
|
-
for (const type of meta.atomics)
|
|
77
|
-
if (type === "bigint") throw new Error(NO_BIGINT);
|
|
78
|
-
else if (AtomicPredicator.atomic(meta)(type) === false) continue;
|
|
79
|
-
else
|
|
80
|
-
insert(
|
|
81
|
-
type === "string"
|
|
82
|
-
? application_string(meta)(attribute)
|
|
83
|
-
: type === "boolean"
|
|
84
|
-
? application_boolean(attribute)
|
|
85
|
-
: application_number(attribute),
|
|
86
|
-
);
|
|
87
|
-
|
|
88
|
-
// ARRAY
|
|
89
|
-
for (const schema of meta.arrays.values())
|
|
90
|
-
insert(application_array(options)(components)()(schema)(attribute));
|
|
91
|
-
|
|
92
|
-
// TUPLE
|
|
93
|
-
for (const items of meta.tuples) {
|
|
94
|
-
const tuple: IJsonSchema.ITuple =
|
|
95
|
-
application_tuple(options)(components)(items)(attribute);
|
|
96
|
-
if (options.purpose === "swagger" && items.length === 0)
|
|
97
|
-
throw new Error(
|
|
98
|
-
"Error on typia.application(): swagger does not support zero length tuple type.",
|
|
99
|
-
);
|
|
100
|
-
else if (
|
|
101
|
-
options.purpose === "ajv" &&
|
|
102
|
-
!items[items.length - 1]?.rest
|
|
103
|
-
)
|
|
104
|
-
insert(tuple);
|
|
105
|
-
else {
|
|
106
|
-
// SWAGGER DOES NOT SUPPORT TUPLE TYPE YET
|
|
107
|
-
const merged: Metadata = items.reduce((x, y) =>
|
|
108
|
-
Metadata.merge(x, y),
|
|
109
|
-
);
|
|
110
|
-
insert(
|
|
111
|
-
application_array(options)(components)(tuple)(merged)(
|
|
112
|
-
attribute,
|
|
113
|
-
),
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// NATIVES
|
|
119
|
-
for (const native of meta.natives)
|
|
120
|
-
if (AtomicPredicator.native(native))
|
|
121
|
-
insert(
|
|
122
|
-
native === "String"
|
|
123
|
-
? application_string(meta)(attribute)
|
|
124
|
-
: native === "Boolean"
|
|
125
|
-
? application_boolean(attribute)
|
|
126
|
-
: application_number(attribute),
|
|
127
|
-
);
|
|
128
|
-
else
|
|
129
|
-
union.push(
|
|
130
|
-
application_native(options)(components)(native)({
|
|
131
|
-
nullable: meta.nullable,
|
|
132
|
-
attribute,
|
|
133
|
-
}),
|
|
134
|
-
);
|
|
135
|
-
if (meta.sets.length)
|
|
136
|
-
union.push(
|
|
137
|
-
application_native(options)(components)(`Set`)({
|
|
138
|
-
nullable: meta.nullable,
|
|
139
|
-
attribute,
|
|
140
|
-
}),
|
|
141
|
-
);
|
|
142
|
-
if (meta.maps.length)
|
|
143
|
-
union.push(
|
|
144
|
-
application_native(options)(components)(`Map`)({
|
|
145
|
-
nullable: meta.nullable,
|
|
146
|
-
attribute,
|
|
147
|
-
}),
|
|
148
|
-
);
|
|
149
|
-
|
|
150
|
-
// OBJECT
|
|
151
|
-
for (const obj of meta.objects) {
|
|
152
|
-
const key: string = application_object(options)(components)(obj)(
|
|
153
|
-
meta.nullable,
|
|
154
|
-
);
|
|
155
|
-
union.push(
|
|
156
|
-
(options.purpose === "ajv" && obj.recursive
|
|
157
|
-
? recursive
|
|
158
|
-
: reference)(`${JSON_SCHEMA_PREFIX}/${key}`, attribute),
|
|
159
|
-
);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
//----
|
|
163
|
-
// RETURNS
|
|
164
|
-
//----
|
|
165
|
-
if (union.length === 0)
|
|
166
|
-
return blockNever === true
|
|
167
|
-
? null!
|
|
168
|
-
: {
|
|
169
|
-
...attribute,
|
|
170
|
-
type: undefined,
|
|
171
|
-
};
|
|
172
|
-
else if (union.length === 1) return union[0]!;
|
|
173
|
-
return { oneOf: union, ...attribute };
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* @internal
|
|
178
|
-
*/
|
|
179
|
-
const reference = (
|
|
180
|
-
$ref: string,
|
|
181
|
-
attribute: IJsonSchema.IAttribute,
|
|
182
|
-
): IJsonSchema.IReference => ({
|
|
183
|
-
$ref,
|
|
184
|
-
...attribute,
|
|
185
|
-
});
|
|
186
|
-
|
|
187
|
-
/**
|
|
188
|
-
* @internal
|
|
189
|
-
*/
|
|
190
|
-
const recursive = (
|
|
191
|
-
$recursiveRef: string,
|
|
192
|
-
attribute: IJsonSchema.IAttribute,
|
|
193
|
-
): IJsonSchema.IRecursiveReference => ({
|
|
194
|
-
$recursiveRef,
|
|
195
|
-
...attribute,
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
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 { JSON_SCHEMA_PREFIX } from "./JSON_SCHEMA_PREFIX";
|
|
8
|
+
import { application_array } from "./application_array";
|
|
9
|
+
import { application_boolean } from "./application_boolean";
|
|
10
|
+
import { application_constant } from "./application_constant";
|
|
11
|
+
import { application_native } from "./application_native";
|
|
12
|
+
import { application_number } from "./application_number";
|
|
13
|
+
import { application_object } from "./application_object";
|
|
14
|
+
import { application_string } from "./application_string";
|
|
15
|
+
import { application_templates } from "./application_templates";
|
|
16
|
+
import { application_tuple } from "./application_tuple";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
export const application_schema =
|
|
22
|
+
(options: ApplicationProgrammer.IOptions) =>
|
|
23
|
+
<BlockNever extends boolean>(blockNever: BlockNever) =>
|
|
24
|
+
(components: IJsonComponents) =>
|
|
25
|
+
(meta: Metadata) =>
|
|
26
|
+
(
|
|
27
|
+
attribute: IJsonSchema.IAttribute,
|
|
28
|
+
): BlockNever extends true ? IJsonSchema | null : IJsonSchema => {
|
|
29
|
+
// VULNERABLE CASE
|
|
30
|
+
if (meta.any === true)
|
|
31
|
+
return {
|
|
32
|
+
...attribute,
|
|
33
|
+
type: undefined,
|
|
34
|
+
};
|
|
35
|
+
else if (meta.nullable && meta.empty())
|
|
36
|
+
return { type: "null", ...attribute };
|
|
37
|
+
|
|
38
|
+
//----
|
|
39
|
+
// GATHER UNION SCHEMAS
|
|
40
|
+
//----
|
|
41
|
+
const union: IJsonSchema[] = [];
|
|
42
|
+
if (meta.nullable && options.purpose !== "swagger")
|
|
43
|
+
union.push({
|
|
44
|
+
...attribute,
|
|
45
|
+
type: "null",
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
const insert =
|
|
49
|
+
meta.nullable && options.purpose === "swagger"
|
|
50
|
+
? (significant: IJsonSchema.ISignificant<any>) =>
|
|
51
|
+
union.push({
|
|
52
|
+
...significant,
|
|
53
|
+
nullable: true,
|
|
54
|
+
})
|
|
55
|
+
: (schema: IJsonSchema) => union.push(schema);
|
|
56
|
+
|
|
57
|
+
// toJSON() METHOD
|
|
58
|
+
if (meta.resolved !== null) {
|
|
59
|
+
const resolved = application_schema(options)(blockNever)(
|
|
60
|
+
components,
|
|
61
|
+
)(meta.resolved)(attribute);
|
|
62
|
+
if (resolved !== null) union.push(resolved);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// ATOMIC TYPES
|
|
66
|
+
if (meta.templates.length && AtomicPredicator.template(meta))
|
|
67
|
+
insert(application_templates(meta)(attribute));
|
|
68
|
+
for (const constant of meta.constants)
|
|
69
|
+
if (constant.type === "bigint") throw new Error(NO_BIGINT);
|
|
70
|
+
else if (
|
|
71
|
+
(constant.type === "string" && meta.templates.length) ||
|
|
72
|
+
AtomicPredicator.constant(meta)(constant.type) === false
|
|
73
|
+
)
|
|
74
|
+
continue;
|
|
75
|
+
else insert(application_constant(constant)(attribute));
|
|
76
|
+
for (const type of meta.atomics)
|
|
77
|
+
if (type === "bigint") throw new Error(NO_BIGINT);
|
|
78
|
+
else if (AtomicPredicator.atomic(meta)(type) === false) continue;
|
|
79
|
+
else
|
|
80
|
+
insert(
|
|
81
|
+
type === "string"
|
|
82
|
+
? application_string(meta)(attribute)
|
|
83
|
+
: type === "boolean"
|
|
84
|
+
? application_boolean(attribute)
|
|
85
|
+
: application_number(attribute),
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
// ARRAY
|
|
89
|
+
for (const schema of meta.arrays.values())
|
|
90
|
+
insert(application_array(options)(components)()(schema)(attribute));
|
|
91
|
+
|
|
92
|
+
// TUPLE
|
|
93
|
+
for (const items of meta.tuples) {
|
|
94
|
+
const tuple: IJsonSchema.ITuple =
|
|
95
|
+
application_tuple(options)(components)(items)(attribute);
|
|
96
|
+
if (options.purpose === "swagger" && items.length === 0)
|
|
97
|
+
throw new Error(
|
|
98
|
+
"Error on typia.application(): swagger does not support zero length tuple type.",
|
|
99
|
+
);
|
|
100
|
+
else if (
|
|
101
|
+
options.purpose === "ajv" &&
|
|
102
|
+
!items[items.length - 1]?.rest
|
|
103
|
+
)
|
|
104
|
+
insert(tuple);
|
|
105
|
+
else {
|
|
106
|
+
// SWAGGER DOES NOT SUPPORT TUPLE TYPE YET
|
|
107
|
+
const merged: Metadata = items.reduce((x, y) =>
|
|
108
|
+
Metadata.merge(x, y),
|
|
109
|
+
);
|
|
110
|
+
insert(
|
|
111
|
+
application_array(options)(components)(tuple)(merged)(
|
|
112
|
+
attribute,
|
|
113
|
+
),
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// NATIVES
|
|
119
|
+
for (const native of meta.natives)
|
|
120
|
+
if (AtomicPredicator.native(native))
|
|
121
|
+
insert(
|
|
122
|
+
native === "String"
|
|
123
|
+
? application_string(meta)(attribute)
|
|
124
|
+
: native === "Boolean"
|
|
125
|
+
? application_boolean(attribute)
|
|
126
|
+
: application_number(attribute),
|
|
127
|
+
);
|
|
128
|
+
else
|
|
129
|
+
union.push(
|
|
130
|
+
application_native(options)(components)(native)({
|
|
131
|
+
nullable: meta.nullable,
|
|
132
|
+
attribute,
|
|
133
|
+
}),
|
|
134
|
+
);
|
|
135
|
+
if (meta.sets.length)
|
|
136
|
+
union.push(
|
|
137
|
+
application_native(options)(components)(`Set`)({
|
|
138
|
+
nullable: meta.nullable,
|
|
139
|
+
attribute,
|
|
140
|
+
}),
|
|
141
|
+
);
|
|
142
|
+
if (meta.maps.length)
|
|
143
|
+
union.push(
|
|
144
|
+
application_native(options)(components)(`Map`)({
|
|
145
|
+
nullable: meta.nullable,
|
|
146
|
+
attribute,
|
|
147
|
+
}),
|
|
148
|
+
);
|
|
149
|
+
|
|
150
|
+
// OBJECT
|
|
151
|
+
for (const obj of meta.objects) {
|
|
152
|
+
const key: string = application_object(options)(components)(obj)(
|
|
153
|
+
meta.nullable,
|
|
154
|
+
);
|
|
155
|
+
union.push(
|
|
156
|
+
(options.purpose === "ajv" && obj.recursive
|
|
157
|
+
? recursive
|
|
158
|
+
: reference)(`${JSON_SCHEMA_PREFIX}/${key}`, attribute),
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
//----
|
|
163
|
+
// RETURNS
|
|
164
|
+
//----
|
|
165
|
+
if (union.length === 0)
|
|
166
|
+
return blockNever === true
|
|
167
|
+
? null!
|
|
168
|
+
: {
|
|
169
|
+
...attribute,
|
|
170
|
+
type: undefined,
|
|
171
|
+
};
|
|
172
|
+
else if (union.length === 1) return union[0]!;
|
|
173
|
+
return { oneOf: union, ...attribute };
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* @internal
|
|
178
|
+
*/
|
|
179
|
+
const reference = (
|
|
180
|
+
$ref: string,
|
|
181
|
+
attribute: IJsonSchema.IAttribute,
|
|
182
|
+
): IJsonSchema.IReference => ({
|
|
183
|
+
$ref,
|
|
184
|
+
...attribute,
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* @internal
|
|
189
|
+
*/
|
|
190
|
+
const recursive = (
|
|
191
|
+
$recursiveRef: string,
|
|
192
|
+
attribute: IJsonSchema.IAttribute,
|
|
193
|
+
): IJsonSchema.IRecursiveReference => ({
|
|
194
|
+
$recursiveRef,
|
|
195
|
+
...attribute,
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
const NO_BIGINT = "Error on typia.application(): does not allow bigint type.";
|
|
@@ -1,44 +1,44 @@
|
|
|
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): IJsonSchema.IString => {
|
|
13
|
-
const output: IJsonSchema.IString = {
|
|
14
|
-
...attribute,
|
|
15
|
-
type: "string",
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
// FORMAT TAG OF METADATA
|
|
19
|
-
const formatJsdocTag = attribute["x-typia-jsDocTags"]?.find(
|
|
20
|
-
(tag) => tag.name === "format",
|
|
21
|
-
);
|
|
22
|
-
if (formatJsdocTag?.text?.length)
|
|
23
|
-
output.format = formatJsdocTag?.text.map((t) => t.text).join(" ");
|
|
24
|
-
|
|
25
|
-
// REGULAR TAGS COMPATIBLE WITH JSON-SCHEMA
|
|
26
|
-
for (const tag of attribute["x-typia-metaTags"] ?? []) {
|
|
27
|
-
// RANGE
|
|
28
|
-
if (tag.kind === "minLength") output.minLength = tag.value;
|
|
29
|
-
else if (tag.kind === "maxLength") output.maxLength = tag.value;
|
|
30
|
-
// FORMAT AND PATTERN
|
|
31
|
-
else if (tag.kind === "format")
|
|
32
|
-
output.format = emendFormat(tag.value);
|
|
33
|
-
else if (tag.kind === "pattern") output.pattern = tag.value;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// DEFAULT CONFIGURATION
|
|
37
|
-
output.default = application_default_string(meta)(attribute)(output);
|
|
38
|
-
|
|
39
|
-
// RETURNS
|
|
40
|
-
return output;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
const emendFormat = (tag: IMetadataTag.IFormat["value"]) =>
|
|
44
|
-
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): IJsonSchema.IString => {
|
|
13
|
+
const output: IJsonSchema.IString = {
|
|
14
|
+
...attribute,
|
|
15
|
+
type: "string",
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// FORMAT TAG OF METADATA
|
|
19
|
+
const formatJsdocTag = attribute["x-typia-jsDocTags"]?.find(
|
|
20
|
+
(tag) => tag.name === "format",
|
|
21
|
+
);
|
|
22
|
+
if (formatJsdocTag?.text?.length)
|
|
23
|
+
output.format = formatJsdocTag?.text.map((t) => t.text).join(" ");
|
|
24
|
+
|
|
25
|
+
// REGULAR TAGS COMPATIBLE WITH JSON-SCHEMA
|
|
26
|
+
for (const tag of attribute["x-typia-metaTags"] ?? []) {
|
|
27
|
+
// RANGE
|
|
28
|
+
if (tag.kind === "minLength") output.minLength = tag.value;
|
|
29
|
+
else if (tag.kind === "maxLength") output.maxLength = tag.value;
|
|
30
|
+
// FORMAT AND PATTERN
|
|
31
|
+
else if (tag.kind === "format")
|
|
32
|
+
output.format = emendFormat(tag.value);
|
|
33
|
+
else if (tag.kind === "pattern") output.pattern = tag.value;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// DEFAULT CONFIGURATION
|
|
37
|
+
output.default = application_default_string(meta)(attribute)(output);
|
|
38
|
+
|
|
39
|
+
// RETURNS
|
|
40
|
+
return output;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const emendFormat = (tag: IMetadataTag.IFormat["value"]) =>
|
|
44
|
+
tag === "datetime" ? "date-time" : tag;
|
|
@@ -1,25 +1,25 @@
|
|
|
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): IJsonSchema.IString => {
|
|
13
|
-
// CONSTRUCT PATTERN
|
|
14
|
-
const output: IJsonSchema.IString = {
|
|
15
|
-
type: "string",
|
|
16
|
-
...attribute,
|
|
17
|
-
};
|
|
18
|
-
output.pattern = metadata_to_pattern(true)(meta);
|
|
19
|
-
|
|
20
|
-
// DEFAULT VALUE
|
|
21
|
-
output.default = application_default_string(meta)(attribute)(output);
|
|
22
|
-
|
|
23
|
-
// RETURNS
|
|
24
|
-
return output;
|
|
25
|
-
};
|
|
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): IJsonSchema.IString => {
|
|
13
|
+
// CONSTRUCT PATTERN
|
|
14
|
+
const output: IJsonSchema.IString = {
|
|
15
|
+
type: "string",
|
|
16
|
+
...attribute,
|
|
17
|
+
};
|
|
18
|
+
output.pattern = metadata_to_pattern(true)(meta);
|
|
19
|
+
|
|
20
|
+
// DEFAULT VALUE
|
|
21
|
+
output.default = application_default_string(meta)(attribute)(output);
|
|
22
|
+
|
|
23
|
+
// RETURNS
|
|
24
|
+
return output;
|
|
25
|
+
};
|
|
@@ -1,27 +1,27 @@
|
|
|
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
|
-
(items: Array<Metadata>) =>
|
|
15
|
-
(attribute: IJsonSchema.IAttribute): IJsonSchema.ITuple => ({
|
|
16
|
-
type: "array",
|
|
17
|
-
items: items.map((meta, i) =>
|
|
18
|
-
application_schema(options)(false)(components)(meta.rest ?? meta)({
|
|
19
|
-
...attribute,
|
|
20
|
-
"x-typia-rest":
|
|
21
|
-
i === items.length - 1 ? meta.rest !== null : undefined,
|
|
22
|
-
"x-typia-required": meta.required,
|
|
23
|
-
"x-typia-optional": meta.optional,
|
|
24
|
-
}),
|
|
25
|
-
),
|
|
26
|
-
...attribute,
|
|
27
|
-
});
|
|
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
|
+
(items: Array<Metadata>) =>
|
|
15
|
+
(attribute: IJsonSchema.IAttribute): IJsonSchema.ITuple => ({
|
|
16
|
+
type: "array",
|
|
17
|
+
items: items.map((meta, i) =>
|
|
18
|
+
application_schema(options)(false)(components)(meta.rest ?? meta)({
|
|
19
|
+
...attribute,
|
|
20
|
+
"x-typia-rest":
|
|
21
|
+
i === items.length - 1 ? meta.rest !== null : undefined,
|
|
22
|
+
"x-typia-required": meta.required,
|
|
23
|
+
"x-typia-optional": meta.optional,
|
|
24
|
+
}),
|
|
25
|
+
),
|
|
26
|
+
...attribute,
|
|
27
|
+
});
|
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import type ts from "typescript/lib/tsclibrary";
|
|
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
|
-
(tsc: typeof ts) =>
|
|
19
|
-
(importer: FunctionImporter) =>
|
|
20
|
-
(metaTags: IMetadataTag[]) =>
|
|
21
|
-
(jsDocTags: IJsDocTagInfo[]) =>
|
|
22
|
-
(input: ts.Expression): ICheckEntry => ({
|
|
23
|
-
expression: ExpressionFactory.isArray(tsc)(input),
|
|
24
|
-
tags: [
|
|
25
|
-
...check_array_length(tsc)(metaTags)(
|
|
26
|
-
IdentifierFactory.access(tsc)(input)("length"),
|
|
27
|
-
),
|
|
28
|
-
...check_custom(tsc)("array", "Array")(importer)(jsDocTags)(input),
|
|
29
|
-
// check custom array for legacy (3.7.0)
|
|
30
|
-
],
|
|
31
|
-
});
|
|
1
|
+
import type ts from "typescript/lib/tsclibrary";
|
|
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
|
+
(tsc: typeof ts) =>
|
|
19
|
+
(importer: FunctionImporter) =>
|
|
20
|
+
(metaTags: IMetadataTag[]) =>
|
|
21
|
+
(jsDocTags: IJsDocTagInfo[]) =>
|
|
22
|
+
(input: ts.Expression): ICheckEntry => ({
|
|
23
|
+
expression: ExpressionFactory.isArray(tsc)(input),
|
|
24
|
+
tags: [
|
|
25
|
+
...check_array_length(tsc)(metaTags)(
|
|
26
|
+
IdentifierFactory.access(tsc)(input)("length"),
|
|
27
|
+
),
|
|
28
|
+
...check_custom(tsc)("array", "Array")(importer)(jsDocTags)(input),
|
|
29
|
+
// check custom array for legacy (3.7.0)
|
|
30
|
+
],
|
|
31
|
+
});
|