typia 3.6.4 → 3.6.5

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.
Files changed (138) hide show
  1. package/lib/functional/$is_uuid.js +1 -1
  2. package/lib/functional/$is_uuid.js.map +1 -1
  3. package/package.json +1 -1
  4. package/src/IRandomGenerator.ts +16 -16
  5. package/src/IValidation.ts +21 -21
  6. package/src/Primitive.ts +104 -104
  7. package/src/TypeGuardError.ts +36 -36
  8. package/src/executable/TypiaGenerateWizard.ts +87 -87
  9. package/src/executable/TypiaSetupWizard.ts +142 -142
  10. package/src/executable/setup/CommandExecutor.ts +8 -8
  11. package/src/executable/typia.ts +38 -38
  12. package/src/factories/CommentFactory.ts +10 -10
  13. package/src/factories/ExpressionFactory.ts +77 -77
  14. package/src/factories/IdentifierFactory.ts +73 -73
  15. package/src/factories/LiteralFactory.ts +44 -44
  16. package/src/factories/MetadataCollection.ts +122 -122
  17. package/src/factories/MetadataFactory.ts +51 -51
  18. package/src/factories/MetadataTagFactory.ts +265 -265
  19. package/src/factories/StatementFactory.ts +60 -60
  20. package/src/factories/TemplateFactory.ts +56 -56
  21. package/src/factories/TypeFactory.ts +129 -129
  22. package/src/factories/TypiaFileFactory.ts +117 -117
  23. package/src/factories/ValueFactory.ts +12 -12
  24. package/src/factories/internal/metadata/MetadataHelper.ts +12 -12
  25. package/src/factories/internal/metadata/explore_metadata.ts +92 -92
  26. package/src/factories/internal/metadata/iterate_metadata.ts +80 -80
  27. package/src/factories/internal/metadata/iterate_metadata_array.ts +29 -29
  28. package/src/factories/internal/metadata/iterate_metadata_atomic.ts +59 -59
  29. package/src/factories/internal/metadata/iterate_metadata_coalesce.ts +33 -33
  30. package/src/factories/internal/metadata/iterate_metadata_constant.ts +58 -58
  31. package/src/factories/internal/metadata/iterate_metadata_map.ts +41 -41
  32. package/src/factories/internal/metadata/iterate_metadata_native.ts +222 -222
  33. package/src/factories/internal/metadata/iterate_metadata_object.ts +48 -48
  34. package/src/factories/internal/metadata/iterate_metadata_resolve.ts +27 -27
  35. package/src/factories/internal/metadata/iterate_metadata_set.ts +33 -33
  36. package/src/factories/internal/metadata/iterate_metadata_template.ts +38 -38
  37. package/src/factories/internal/metadata/iterate_metadata_tuple.ts +45 -45
  38. package/src/factories/internal/metadata/iterate_metadata_union.ts +59 -59
  39. package/src/functional/$any.ts +3 -3
  40. package/src/functional/$every.ts +11 -11
  41. package/src/functional/$guard.ts +35 -35
  42. package/src/functional/$is_between.ts +7 -7
  43. package/src/functional/$is_email.ts +5 -5
  44. package/src/functional/$is_ipv4.ts +5 -5
  45. package/src/functional/$is_ipv6.ts +5 -5
  46. package/src/functional/$is_url.ts +5 -5
  47. package/src/functional/$is_uuid.ts +5 -4
  48. package/src/functional/$join.ts +50 -50
  49. package/src/functional/$number.ts +12 -12
  50. package/src/functional/$report.ts +15 -15
  51. package/src/functional/$rest.ts +3 -3
  52. package/src/functional/$string.ts +37 -37
  53. package/src/functional/$tail.ts +6 -6
  54. package/src/functional/Namespace.ts +121 -121
  55. package/src/index.ts +4 -4
  56. package/src/metadata/IJsDocTagInfo.ts +10 -10
  57. package/src/metadata/IMetadata.ts +25 -25
  58. package/src/metadata/IMetadataApplication.ts +7 -7
  59. package/src/metadata/IMetadataConstant.ts +16 -16
  60. package/src/metadata/IMetadataEntry.ts +6 -6
  61. package/src/metadata/IMetadataObject.ts +29 -29
  62. package/src/metadata/IMetadataProperty.ts +11 -11
  63. package/src/metadata/IMetadataTag.ts +113 -113
  64. package/src/metadata/Metadata.ts +534 -534
  65. package/src/metadata/MetadataConstant.ts +3 -3
  66. package/src/metadata/MetadataObject.ts +131 -131
  67. package/src/metadata/MetadataProperty.ts +64 -64
  68. package/src/programmers/ApplicationProgrammer.ts +55 -55
  69. package/src/programmers/IsProgrammer.ts +200 -200
  70. package/src/programmers/helpers/AtomicPredicator.ts +31 -31
  71. package/src/programmers/helpers/CloneJoiner.ts +134 -134
  72. package/src/programmers/helpers/FunctionImporeter.ts +55 -55
  73. package/src/programmers/helpers/IExpressionEntry.ts +12 -12
  74. package/src/programmers/helpers/OptionPredicator.ts +19 -19
  75. package/src/programmers/helpers/PruneJoiner.ts +52 -52
  76. package/src/programmers/helpers/RandomJoiner.ts +149 -149
  77. package/src/programmers/helpers/RandomRanger.ts +216 -216
  78. package/src/programmers/helpers/StringifyJoinder.ts +114 -114
  79. package/src/programmers/helpers/StringifyPredicator.ts +18 -18
  80. package/src/programmers/helpers/UnionExplorer.ts +274 -274
  81. package/src/programmers/helpers/UnionPredicator.ts +81 -81
  82. package/src/programmers/internal/application_array.ts +37 -37
  83. package/src/programmers/internal/application_boolean.ts +17 -17
  84. package/src/programmers/internal/application_constant.ts +29 -29
  85. package/src/programmers/internal/application_default.ts +17 -17
  86. package/src/programmers/internal/application_default_string.ts +32 -32
  87. package/src/programmers/internal/application_native.ts +29 -29
  88. package/src/programmers/internal/application_number.ts +70 -70
  89. package/src/programmers/internal/application_object.ts +153 -153
  90. package/src/programmers/internal/application_schema.ts +184 -184
  91. package/src/programmers/internal/application_string.ts +41 -41
  92. package/src/programmers/internal/application_templates.ts +27 -27
  93. package/src/programmers/internal/application_tuple.ts +29 -29
  94. package/src/programmers/internal/check_array.ts +22 -22
  95. package/src/programmers/internal/check_array_length.ts +44 -44
  96. package/src/programmers/internal/check_bigint.ts +64 -64
  97. package/src/programmers/internal/check_dynamic_properties.ts +197 -197
  98. package/src/programmers/internal/check_everything.ts +28 -28
  99. package/src/programmers/internal/check_native.ts +21 -21
  100. package/src/programmers/internal/check_number.ts +145 -145
  101. package/src/programmers/internal/check_object.ts +48 -48
  102. package/src/programmers/internal/check_string.ts +24 -24
  103. package/src/programmers/internal/check_string_tags.ts +63 -63
  104. package/src/programmers/internal/check_template.ts +50 -50
  105. package/src/programmers/internal/check_union_array_like.ts +260 -260
  106. package/src/programmers/internal/check_union_tuple.ts +33 -33
  107. package/src/programmers/internal/decode_union_object.ts +73 -73
  108. package/src/programmers/internal/feature_object_entries.ts +59 -59
  109. package/src/programmers/internal/metadata_to_pattern.ts +31 -31
  110. package/src/programmers/internal/prune_object_properties.ts +60 -60
  111. package/src/programmers/internal/stringify_dynamic_properties.ts +165 -165
  112. package/src/programmers/internal/stringify_native.ts +8 -8
  113. package/src/programmers/internal/stringify_regular_properties.ts +81 -81
  114. package/src/programmers/internal/template_to_pattern.ts +15 -15
  115. package/src/schemas/IJsonApplication.ts +9 -9
  116. package/src/schemas/IJsonComponents.ts +26 -26
  117. package/src/schemas/IJsonSchema.ts +127 -127
  118. package/src/transform.ts +21 -21
  119. package/src/transformers/CallExpressionTransformer.ts +172 -172
  120. package/src/transformers/ExpressionWithArgumentTransformer.ts +66 -66
  121. package/src/transformers/FileTransformer.ts +49 -49
  122. package/src/transformers/IProject.ts +11 -11
  123. package/src/transformers/ITransformOptions.ts +62 -62
  124. package/src/transformers/ImportTransformer.ts +60 -60
  125. package/src/transformers/NodeTransformer.ts +19 -19
  126. package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +120 -120
  127. package/src/transformers/features/miscellaneous/MetadataTransformer.ts +55 -55
  128. package/src/typings/Atomic.ts +17 -17
  129. package/src/typings/ClassProperties.ts +5 -5
  130. package/src/typings/OmitNever.ts +3 -3
  131. package/src/typings/SpecialFields.ts +3 -3
  132. package/src/typings/Writable.ts +11 -11
  133. package/src/utils/ArrayUtil.ts +49 -49
  134. package/src/utils/Escaper.ts +50 -50
  135. package/src/utils/MapUtil.ts +14 -14
  136. package/src/utils/PatternUtil.ts +30 -30
  137. package/src/utils/RandomGenerator.ts +90 -90
  138. package/src/utils/Singleton.ts +17 -17
@@ -1,81 +1,81 @@
1
- import { Metadata } from "../../metadata/Metadata";
2
- import { MetadataObject } from "../../metadata/MetadataObject";
3
- import { MetadataProperty } from "../../metadata/MetadataProperty";
4
-
5
- import { ArrayUtil } from "../../utils/ArrayUtil";
6
- import { MapUtil } from "../../utils/MapUtil";
7
-
8
- export namespace UnionPredicator {
9
- export interface ISpecialized {
10
- index: number;
11
- object: MetadataObject;
12
- property: MetadataProperty;
13
- neighbour: boolean;
14
- }
15
-
16
- export function object(targets: MetadataObject[]): Array<ISpecialized> {
17
- // PROPERTY MATRIX
18
- const matrix: Map<string, Array<MetadataProperty | null>> = new Map();
19
- for (const obj of targets)
20
- for (const prop of obj.properties) {
21
- const key: string | null = prop.key.getSoleLiteral();
22
- if (key !== null)
23
- MapUtil.take(matrix, key, () =>
24
- ArrayUtil.repeat(targets.length, () => null),
25
- );
26
- }
27
- targets.forEach((obj, i) => {
28
- for (const prop of obj.properties) {
29
- const key: string | null = prop.key.getSoleLiteral();
30
- if (key !== null) matrix.get(key)![i] = prop;
31
- }
32
- });
33
-
34
- // EXPLORE SPECIALIZERS
35
- const output: ISpecialized[] = [];
36
- targets.forEach((obj, i) => {
37
- const children: ISpecializedProperty[] = [];
38
- obj.properties.forEach((prop) => {
39
- // MUST BE REQUIRED
40
- if (prop.value.required === false) return;
41
- const key: string | null = prop.key.getSoleLiteral();
42
- if (key === null) return;
43
-
44
- // FIND NEIGHBORHOOD PROPERTIES
45
- const neighbors: MetadataProperty[] = matrix
46
- .get(key)!
47
- .filter(
48
- (oppo, k) => i !== k && oppo !== null,
49
- ) as MetadataProperty[];
50
-
51
- // NO NEIGHBORHOOD
52
- const unique: boolean =
53
- neighbors.length === 0 ||
54
- neighbors.every(
55
- (n) => !Metadata.intersects(prop.value, n.value, false),
56
- );
57
- if (unique === true)
58
- children.push({
59
- property: prop,
60
- neighbour: neighbors.length !== 0,
61
- });
62
- });
63
- if (children.length === 0) return;
64
-
65
- const top: ISpecializedProperty =
66
- children.find((child) => child.property.value.isConstant()) ||
67
- children[0]!;
68
- output.push({
69
- index: i,
70
- object: obj,
71
- ...top,
72
- });
73
- });
74
- return output;
75
- }
76
- }
77
-
78
- interface ISpecializedProperty {
79
- property: MetadataProperty;
80
- neighbour: boolean;
81
- }
1
+ import { Metadata } from "../../metadata/Metadata";
2
+ import { MetadataObject } from "../../metadata/MetadataObject";
3
+ import { MetadataProperty } from "../../metadata/MetadataProperty";
4
+
5
+ import { ArrayUtil } from "../../utils/ArrayUtil";
6
+ import { MapUtil } from "../../utils/MapUtil";
7
+
8
+ export namespace UnionPredicator {
9
+ export interface ISpecialized {
10
+ index: number;
11
+ object: MetadataObject;
12
+ property: MetadataProperty;
13
+ neighbour: boolean;
14
+ }
15
+
16
+ export function object(targets: MetadataObject[]): Array<ISpecialized> {
17
+ // PROPERTY MATRIX
18
+ const matrix: Map<string, Array<MetadataProperty | null>> = new Map();
19
+ for (const obj of targets)
20
+ for (const prop of obj.properties) {
21
+ const key: string | null = prop.key.getSoleLiteral();
22
+ if (key !== null)
23
+ MapUtil.take(matrix, key, () =>
24
+ ArrayUtil.repeat(targets.length, () => null),
25
+ );
26
+ }
27
+ targets.forEach((obj, i) => {
28
+ for (const prop of obj.properties) {
29
+ const key: string | null = prop.key.getSoleLiteral();
30
+ if (key !== null) matrix.get(key)![i] = prop;
31
+ }
32
+ });
33
+
34
+ // EXPLORE SPECIALIZERS
35
+ const output: ISpecialized[] = [];
36
+ targets.forEach((obj, i) => {
37
+ const children: ISpecializedProperty[] = [];
38
+ obj.properties.forEach((prop) => {
39
+ // MUST BE REQUIRED
40
+ if (prop.value.required === false) return;
41
+ const key: string | null = prop.key.getSoleLiteral();
42
+ if (key === null) return;
43
+
44
+ // FIND NEIGHBORHOOD PROPERTIES
45
+ const neighbors: MetadataProperty[] = matrix
46
+ .get(key)!
47
+ .filter(
48
+ (oppo, k) => i !== k && oppo !== null,
49
+ ) as MetadataProperty[];
50
+
51
+ // NO NEIGHBORHOOD
52
+ const unique: boolean =
53
+ neighbors.length === 0 ||
54
+ neighbors.every(
55
+ (n) => !Metadata.intersects(prop.value, n.value, false),
56
+ );
57
+ if (unique === true)
58
+ children.push({
59
+ property: prop,
60
+ neighbour: neighbors.length !== 0,
61
+ });
62
+ });
63
+ if (children.length === 0) return;
64
+
65
+ const top: ISpecializedProperty =
66
+ children.find((child) => child.property.value.isConstant()) ||
67
+ children[0]!;
68
+ output.push({
69
+ index: i,
70
+ object: obj,
71
+ ...top,
72
+ });
73
+ });
74
+ return output;
75
+ }
76
+ }
77
+
78
+ interface ISpecializedProperty {
79
+ property: MetadataProperty;
80
+ neighbour: boolean;
81
+ }
@@ -1,37 +1,37 @@
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_array =
12
- (options: ApplicationProgrammer.IOptions) =>
13
- (components: IJsonComponents) =>
14
- (tuple?: IJsonSchema.ITuple) =>
15
- (
16
- metadata: Metadata,
17
- nullable: boolean,
18
- attribute: IJsonSchema.IAttribute,
19
- ): IJsonSchema.IArray => {
20
- // SCHEMA
21
- const output: IJsonSchema.IArray = {
22
- type: "array",
23
- items: application_schema(options)(components)(false)(
24
- metadata,
25
- attribute,
26
- ),
27
- nullable,
28
- "x-typia-tuple": tuple,
29
- ...attribute,
30
- };
31
-
32
- // RANGE
33
- for (const tag of attribute["x-typia-metaTags"] || [])
34
- if (tag.kind === "minItems") output.minItems = tag.value;
35
- else if (tag.kind === "maxItems") output.maxItems = tag.value;
36
- return output;
37
- };
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_array =
12
+ (options: ApplicationProgrammer.IOptions) =>
13
+ (components: IJsonComponents) =>
14
+ (tuple?: IJsonSchema.ITuple) =>
15
+ (
16
+ metadata: Metadata,
17
+ nullable: boolean,
18
+ attribute: IJsonSchema.IAttribute,
19
+ ): IJsonSchema.IArray => {
20
+ // SCHEMA
21
+ const output: IJsonSchema.IArray = {
22
+ type: "array",
23
+ items: application_schema(options)(components)(false)(
24
+ metadata,
25
+ attribute,
26
+ ),
27
+ nullable,
28
+ "x-typia-tuple": tuple,
29
+ ...attribute,
30
+ };
31
+
32
+ // RANGE
33
+ for (const tag of attribute["x-typia-metaTags"] || [])
34
+ if (tag.kind === "minItems") output.minItems = tag.value;
35
+ else if (tag.kind === "maxItems") output.maxItems = tag.value;
36
+ return output;
37
+ };
@@ -1,17 +1,17 @@
1
- import { IJsonSchema } from "../../module";
2
- import { application_default } from "./application_default";
3
-
4
- /**
5
- * @internal
6
- */
7
- export const application_boolean = (
8
- nullable: boolean,
9
- attribute: IJsonSchema.IAttribute,
10
- ): IJsonSchema.IBoolean => ({
11
- type: "boolean",
12
- nullable,
13
- ...attribute,
14
- default: application_default(attribute)(
15
- (def) => def === "true" || def === "false",
16
- )((str) => Boolean(str)),
17
- });
1
+ import { IJsonSchema } from "../../module";
2
+ import { application_default } from "./application_default";
3
+
4
+ /**
5
+ * @internal
6
+ */
7
+ export const application_boolean = (
8
+ nullable: boolean,
9
+ attribute: IJsonSchema.IAttribute,
10
+ ): IJsonSchema.IBoolean => ({
11
+ type: "boolean",
12
+ nullable,
13
+ ...attribute,
14
+ default: application_default(attribute)(
15
+ (def) => def === "true" || def === "false",
16
+ )((str) => Boolean(str)),
17
+ });
@@ -1,29 +1,29 @@
1
- import { MetadataConstant } from "../../metadata/MetadataConstant";
2
- import { IJsonSchema } from "../../schemas/IJsonSchema";
3
-
4
- import { application_default } from "./application_default";
5
-
6
- /**
7
- * @internal
8
- */
9
- export const application_constant = (
10
- constant: MetadataConstant,
11
- nullable: boolean,
12
- attribute: IJsonSchema.IAttribute,
13
- ): IJsonSchema.IEnumeration<any> => ({
14
- type: constant.type,
15
- enum: constant.values as any,
16
- nullable,
17
- ...attribute,
18
- default: application_default(attribute)((def) =>
19
- constant.values.some((v) => v.toString() === def),
20
- )(
21
- constant.type === "string"
22
- ? (str) => str
23
- : constant.type === "number"
24
- ? (str) => Number(str)
25
- : constant.type === "boolean"
26
- ? (str) => Boolean(str)
27
- : (str) => BigInt(str) as any,
28
- ),
29
- });
1
+ import { MetadataConstant } from "../../metadata/MetadataConstant";
2
+ import { IJsonSchema } from "../../schemas/IJsonSchema";
3
+
4
+ import { application_default } from "./application_default";
5
+
6
+ /**
7
+ * @internal
8
+ */
9
+ export const application_constant = (
10
+ constant: MetadataConstant,
11
+ nullable: boolean,
12
+ attribute: IJsonSchema.IAttribute,
13
+ ): IJsonSchema.IEnumeration<any> => ({
14
+ type: constant.type,
15
+ enum: constant.values as any,
16
+ nullable,
17
+ ...attribute,
18
+ default: application_default(attribute)((def) =>
19
+ constant.values.some((v) => v.toString() === def),
20
+ )(
21
+ constant.type === "string"
22
+ ? (str) => str
23
+ : constant.type === "number"
24
+ ? (str) => Number(str)
25
+ : constant.type === "boolean"
26
+ ? (str) => Boolean(str)
27
+ : (str) => BigInt(str) as any,
28
+ ),
29
+ });
@@ -1,17 +1,17 @@
1
- import { IJsonSchema } from "../../schemas/IJsonSchema";
2
-
3
- /**
4
- * @internal
5
- */
6
- export const application_default =
7
- (attribute: IJsonSchema.IAttribute) =>
8
- (pred: (value: string) => boolean) =>
9
- <T>(caster: (str: string) => T): T | undefined => {
10
- const defaults = (attribute["x-typia-jsDocTags"] || []).filter(
11
- (tag) => tag.name === "default",
12
- );
13
- for (const def of defaults)
14
- if (def.text?.length && pred(def.text[0]!.text))
15
- return caster(def.text[0]!.text);
16
- return undefined;
17
- };
1
+ import { IJsonSchema } from "../../schemas/IJsonSchema";
2
+
3
+ /**
4
+ * @internal
5
+ */
6
+ export const application_default =
7
+ (attribute: IJsonSchema.IAttribute) =>
8
+ (pred: (value: string) => boolean) =>
9
+ <T>(caster: (str: string) => T): T | undefined => {
10
+ const defaults = (attribute["x-typia-jsDocTags"] || []).filter(
11
+ (tag) => tag.name === "default",
12
+ );
13
+ for (const def of defaults)
14
+ if (def.text?.length && pred(def.text[0]!.text))
15
+ return caster(def.text[0]!.text);
16
+ return undefined;
17
+ };
@@ -1,32 +1,32 @@
1
- import { Metadata } from "../../metadata/Metadata";
2
-
3
- import { IJsonSchema } from "../../module";
4
- import { application_default } from "./application_default";
5
-
6
- /**
7
- * @internal
8
- */
9
- export const application_default_string =
10
- (meta: Metadata, attribute: IJsonSchema.IAttribute) =>
11
- (schema: IJsonSchema.IString) =>
12
- application_default(attribute)((str) => {
13
- const conditions: boolean[] = [];
14
-
15
- // OTHER ATOMIC TYPES
16
- if (meta.atomics.find((t) => t === "number" || t === "bigint"))
17
- conditions.push(Number.isNaN(Number(str)));
18
- if (meta.atomics.find((t) => t === "boolean"))
19
- conditions.push(str !== "true" && str !== "false");
20
- for (const constant of meta.constants)
21
- for (const value of constant.values)
22
- conditions.push(str !== value.toString());
23
-
24
- // CONSIDER TAGS
25
- if (schema.minLength !== undefined)
26
- conditions.push(str.length >= schema.minLength);
27
- if (schema.maxLength !== undefined)
28
- conditions.push(str.length <= schema.maxLength);
29
- if (schema.pattern !== undefined)
30
- conditions.push(new RegExp(schema.pattern).test(str));
31
- return conditions.every((c) => c);
32
- })((str) => str);
1
+ import { Metadata } from "../../metadata/Metadata";
2
+
3
+ import { IJsonSchema } from "../../module";
4
+ import { application_default } from "./application_default";
5
+
6
+ /**
7
+ * @internal
8
+ */
9
+ export const application_default_string =
10
+ (meta: Metadata, attribute: IJsonSchema.IAttribute) =>
11
+ (schema: IJsonSchema.IString) =>
12
+ application_default(attribute)((str) => {
13
+ const conditions: boolean[] = [];
14
+
15
+ // OTHER ATOMIC TYPES
16
+ if (meta.atomics.find((t) => t === "number" || t === "bigint"))
17
+ conditions.push(Number.isNaN(Number(str)));
18
+ if (meta.atomics.find((t) => t === "boolean"))
19
+ conditions.push(str !== "true" && str !== "false");
20
+ for (const constant of meta.constants)
21
+ for (const value of constant.values)
22
+ conditions.push(str !== value.toString());
23
+
24
+ // CONSIDER TAGS
25
+ if (schema.minLength !== undefined)
26
+ conditions.push(str.length >= schema.minLength);
27
+ if (schema.maxLength !== undefined)
28
+ conditions.push(str.length <= schema.maxLength);
29
+ if (schema.pattern !== undefined)
30
+ conditions.push(new RegExp(schema.pattern).test(str));
31
+ return conditions.every((c) => c);
32
+ })((str) => str);
@@ -1,29 +1,29 @@
1
- import { IJsonComponents } from "../../schemas/IJsonComponents";
2
-
3
- import { IJsonSchema } from "../../module";
4
- import { ApplicationProgrammer } from "../ApplicationProgrammer";
5
-
6
- export const application_native =
7
- (options: ApplicationProgrammer.IOptions) =>
8
- (components: IJsonComponents) =>
9
- (name: string) =>
10
- (
11
- nullable: boolean,
12
- attribute: IJsonSchema.IAttribute,
13
- ): IJsonSchema.IReference => {
14
- const key: string = name + (nullable ? ".Nullable" : "");
15
- if (components.schemas[key] === undefined)
16
- components.schemas[key] = {
17
- type: "object",
18
- $id:
19
- options.purpose === "ajv"
20
- ? options.prefix + "/" + key
21
- : undefined,
22
- properties: {},
23
- nullable,
24
- };
25
- return {
26
- $ref: `#/components/schemas/${name}`,
27
- ...attribute,
28
- };
29
- };
1
+ import { IJsonComponents } from "../../schemas/IJsonComponents";
2
+
3
+ import { IJsonSchema } from "../../module";
4
+ import { ApplicationProgrammer } from "../ApplicationProgrammer";
5
+
6
+ export const application_native =
7
+ (options: ApplicationProgrammer.IOptions) =>
8
+ (components: IJsonComponents) =>
9
+ (name: string) =>
10
+ (
11
+ nullable: boolean,
12
+ attribute: IJsonSchema.IAttribute,
13
+ ): IJsonSchema.IReference => {
14
+ const key: string = name + (nullable ? ".Nullable" : "");
15
+ if (components.schemas[key] === undefined)
16
+ components.schemas[key] = {
17
+ type: "object",
18
+ $id:
19
+ options.purpose === "ajv"
20
+ ? options.prefix + "/" + key
21
+ : undefined,
22
+ properties: {},
23
+ nullable,
24
+ };
25
+ return {
26
+ $ref: `#/components/schemas/${name}`,
27
+ ...attribute,
28
+ };
29
+ };
@@ -1,70 +1,70 @@
1
- import { IJsonSchema } from "../../module";
2
- import { application_default } from "./application_default";
3
-
4
- /**
5
- * @internal
6
- */
7
- export const application_number = (
8
- nullable: boolean,
9
- attribute: IJsonSchema.IAttribute,
10
- ): IJsonSchema.INumber | IJsonSchema.IInteger => {
11
- const output: IJsonSchema.INumber | IJsonSchema.IInteger = {
12
- type: "number" as "number" | "integer",
13
- nullable,
14
- ...attribute,
15
- };
16
- for (const tag of attribute["x-typia-metaTags"] || []) {
17
- // CHECK TYPE
18
- if (
19
- tag.kind === "type" &&
20
- (tag.value === "int" || tag.value === "uint")
21
- )
22
- output.type = "integer";
23
- // RANGE TAG
24
- else if (tag.kind === "minimum") output.minimum = tag.value;
25
- else if (tag.kind === "maximum") output.maximum = tag.value;
26
- else if (tag.kind === "exclusiveMinimum")
27
- output.exclusiveMinimum = tag.value;
28
- else if (tag.kind === "exclusiveMaximum")
29
- output.exclusiveMaximum = tag.value;
30
- // MULTIPLE-OF
31
- else if (tag.kind === "multipleOf") output.multipleOf = tag.value;
32
- }
33
-
34
- // WHEN UNSIGNED INT
35
- if (
36
- output.type === "integer" &&
37
- (attribute["x-typia-metaTags"] || []).find(
38
- (tag) => tag.kind === "type" && tag.value === "uint",
39
- )
40
- )
41
- if (output.minimum === undefined || output.minimum < 0)
42
- output.minimum = 0;
43
- else if (
44
- output.exclusiveMinimum === undefined ||
45
- output.exclusiveMinimum < 0
46
- ) {
47
- delete output.exclusiveMinimum;
48
- output.maximum = 0;
49
- }
50
-
51
- // DEFAULT CONFIGURATION
52
- output.default = application_default(attribute)((str) => {
53
- const value: number = Number(str);
54
- const conditions: boolean[] = [!Number.isNaN(value)];
55
- if (output.minimum !== undefined)
56
- conditions.push(value >= output.minimum);
57
- if (output.maximum !== undefined)
58
- conditions.push(value <= output.maximum);
59
- if (output.exclusiveMinimum !== undefined)
60
- conditions.push(value > output.exclusiveMinimum);
61
- if (output.exclusiveMaximum !== undefined)
62
- conditions.push(value < output.exclusiveMaximum);
63
- if (output.multipleOf !== undefined)
64
- conditions.push(value % output.multipleOf === 0);
65
- return conditions.every((cond) => cond);
66
- })((str) => Number(str));
67
-
68
- // RETURNS
69
- return output;
70
- };
1
+ import { IJsonSchema } from "../../module";
2
+ import { application_default } from "./application_default";
3
+
4
+ /**
5
+ * @internal
6
+ */
7
+ export const application_number = (
8
+ nullable: boolean,
9
+ attribute: IJsonSchema.IAttribute,
10
+ ): IJsonSchema.INumber | IJsonSchema.IInteger => {
11
+ const output: IJsonSchema.INumber | IJsonSchema.IInteger = {
12
+ type: "number" as "number" | "integer",
13
+ nullable,
14
+ ...attribute,
15
+ };
16
+ for (const tag of attribute["x-typia-metaTags"] || []) {
17
+ // CHECK TYPE
18
+ if (
19
+ tag.kind === "type" &&
20
+ (tag.value === "int" || tag.value === "uint")
21
+ )
22
+ output.type = "integer";
23
+ // RANGE TAG
24
+ else if (tag.kind === "minimum") output.minimum = tag.value;
25
+ else if (tag.kind === "maximum") output.maximum = tag.value;
26
+ else if (tag.kind === "exclusiveMinimum")
27
+ output.exclusiveMinimum = tag.value;
28
+ else if (tag.kind === "exclusiveMaximum")
29
+ output.exclusiveMaximum = tag.value;
30
+ // MULTIPLE-OF
31
+ else if (tag.kind === "multipleOf") output.multipleOf = tag.value;
32
+ }
33
+
34
+ // WHEN UNSIGNED INT
35
+ if (
36
+ output.type === "integer" &&
37
+ (attribute["x-typia-metaTags"] || []).find(
38
+ (tag) => tag.kind === "type" && tag.value === "uint",
39
+ )
40
+ )
41
+ if (output.minimum === undefined || output.minimum < 0)
42
+ output.minimum = 0;
43
+ else if (
44
+ output.exclusiveMinimum === undefined ||
45
+ output.exclusiveMinimum < 0
46
+ ) {
47
+ delete output.exclusiveMinimum;
48
+ output.maximum = 0;
49
+ }
50
+
51
+ // DEFAULT CONFIGURATION
52
+ output.default = application_default(attribute)((str) => {
53
+ const value: number = Number(str);
54
+ const conditions: boolean[] = [!Number.isNaN(value)];
55
+ if (output.minimum !== undefined)
56
+ conditions.push(value >= output.minimum);
57
+ if (output.maximum !== undefined)
58
+ conditions.push(value <= output.maximum);
59
+ if (output.exclusiveMinimum !== undefined)
60
+ conditions.push(value > output.exclusiveMinimum);
61
+ if (output.exclusiveMaximum !== undefined)
62
+ conditions.push(value < output.exclusiveMaximum);
63
+ if (output.multipleOf !== undefined)
64
+ conditions.push(value % output.multipleOf === 0);
65
+ return conditions.every((cond) => cond);
66
+ })((str) => Number(str));
67
+
68
+ // RETURNS
69
+ return output;
70
+ };