typia 3.4.13 → 3.4.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. package/README.md +9 -8
  2. package/lib/factories/internal/iterate_metadata_object.js +4 -2
  3. package/lib/factories/internal/iterate_metadata_object.js.map +1 -1
  4. package/package.json +1 -1
  5. package/src/IValidation.ts +21 -21
  6. package/src/Primitive.ts +82 -82
  7. package/src/TypeGuardError.ts +36 -36
  8. package/src/executable/internal/CommandParser.ts +15 -15
  9. package/src/executable/internal/TypiaSetupWizard.ts +175 -175
  10. package/src/executable/typia.ts +46 -46
  11. package/src/factories/CommentFactory.ts +10 -10
  12. package/src/factories/ExpressionFactory.ts +66 -66
  13. package/src/factories/IdentifierFactory.ts +72 -72
  14. package/src/factories/LiteralFactory.ts +44 -44
  15. package/src/factories/MetadataCollection.ts +122 -122
  16. package/src/factories/MetadataFactory.ts +46 -46
  17. package/src/factories/MetadataTagFactory.ts +347 -347
  18. package/src/factories/StatementFactory.ts +60 -60
  19. package/src/factories/TemplateFactory.ts +56 -56
  20. package/src/factories/TypeFactory.ts +101 -101
  21. package/src/factories/ValueFactory.ts +12 -12
  22. package/src/factories/internal/MetadataHelper.ts +12 -12
  23. package/src/factories/internal/emplace_metadata_object.ts +140 -140
  24. package/src/factories/internal/explore_metadata.ts +91 -91
  25. package/src/factories/internal/iterate_metadata.ts +80 -80
  26. package/src/factories/internal/iterate_metadata_array.ts +29 -29
  27. package/src/factories/internal/iterate_metadata_atomic.ts +59 -59
  28. package/src/factories/internal/iterate_metadata_coalesce.ts +33 -33
  29. package/src/factories/internal/iterate_metadata_constant.ts +58 -58
  30. package/src/factories/internal/iterate_metadata_map.ts +41 -41
  31. package/src/factories/internal/iterate_metadata_native.ts +227 -227
  32. package/src/factories/internal/iterate_metadata_object.ts +48 -45
  33. package/src/factories/internal/iterate_metadata_resolve.ts +27 -27
  34. package/src/factories/internal/iterate_metadata_set.ts +33 -33
  35. package/src/factories/internal/iterate_metadata_template.ts +38 -38
  36. package/src/factories/internal/iterate_metadata_tuple.ts +45 -45
  37. package/src/factories/internal/iterate_metadata_union.ts +59 -59
  38. package/src/functional/$every.ts +11 -11
  39. package/src/functional/$guard.ts +35 -35
  40. package/src/functional/$is_email.ts +5 -5
  41. package/src/functional/$is_ipv4.ts +5 -5
  42. package/src/functional/$is_ipv6.ts +5 -5
  43. package/src/functional/$is_url.ts +5 -5
  44. package/src/functional/$is_uuid.ts +5 -5
  45. package/src/functional/$join.ts +50 -50
  46. package/src/functional/$number.ts +19 -19
  47. package/src/functional/$report.ts +15 -15
  48. package/src/functional/$rest.ts +3 -3
  49. package/src/functional/$string.ts +37 -37
  50. package/src/functional/$tail.ts +6 -6
  51. package/src/index.ts +4 -4
  52. package/src/metadata/IJsDocTagInfo.ts +10 -10
  53. package/src/metadata/IMetadata.ts +25 -25
  54. package/src/metadata/IMetadataApplication.ts +7 -7
  55. package/src/metadata/IMetadataConstant.ts +16 -16
  56. package/src/metadata/IMetadataEntry.ts +6 -6
  57. package/src/metadata/IMetadataObject.ts +29 -29
  58. package/src/metadata/IMetadataProperty.ts +11 -11
  59. package/src/metadata/IMetadataTag.ts +122 -122
  60. package/src/metadata/Metadata.ts +477 -477
  61. package/src/metadata/MetadataConstant.ts +3 -3
  62. package/src/metadata/MetadataObject.ts +131 -131
  63. package/src/metadata/MetadataProperty.ts +64 -64
  64. package/src/module.ts +1535 -1535
  65. package/src/programmers/ApplicationProgrammer.ts +55 -55
  66. package/src/programmers/AssertParseProgrammer.ts +45 -45
  67. package/src/programmers/AssertProgrammer.ts +444 -444
  68. package/src/programmers/AssertStringifyProgrammer.ts +45 -45
  69. package/src/programmers/CheckerProgrammer.ts +804 -804
  70. package/src/programmers/FeatureProgrammer.ts +327 -327
  71. package/src/programmers/IsParseProgrammer.ts +51 -51
  72. package/src/programmers/IsProgrammer.ts +172 -172
  73. package/src/programmers/IsStringifyProgrammer.ts +49 -49
  74. package/src/programmers/StringifyProgrammer.ts +756 -756
  75. package/src/programmers/ValidateParseProgrammer.ts +49 -49
  76. package/src/programmers/ValidateProgrammer.ts +236 -236
  77. package/src/programmers/ValidateStringifyProgrammer.ts +60 -60
  78. package/src/programmers/helpers/AtomicPredicator.ts +15 -15
  79. package/src/programmers/helpers/FunctionImporeter.ts +31 -31
  80. package/src/programmers/helpers/IExpressionEntry.ts +10 -10
  81. package/src/programmers/helpers/OptionPredicator.ts +11 -11
  82. package/src/programmers/helpers/StringifyJoinder.ts +111 -111
  83. package/src/programmers/helpers/StringifyPredicator.ts +18 -18
  84. package/src/programmers/helpers/UnionExplorer.ts +437 -437
  85. package/src/programmers/helpers/UnionPredicator.ts +81 -81
  86. package/src/programmers/internal/application_array.ts +45 -45
  87. package/src/programmers/internal/application_boolean.ts +17 -17
  88. package/src/programmers/internal/application_constant.ts +29 -29
  89. package/src/programmers/internal/application_default.ts +17 -17
  90. package/src/programmers/internal/application_default_string.ts +32 -32
  91. package/src/programmers/internal/application_native.ts +29 -29
  92. package/src/programmers/internal/application_number.ts +76 -76
  93. package/src/programmers/internal/application_object.ts +103 -103
  94. package/src/programmers/internal/application_schema.ts +221 -221
  95. package/src/programmers/internal/application_string.ts +49 -49
  96. package/src/programmers/internal/application_templates.ts +27 -27
  97. package/src/programmers/internal/application_tuple.ts +25 -25
  98. package/src/programmers/internal/check_array.ts +44 -44
  99. package/src/programmers/internal/check_dynamic_properties.ts +146 -146
  100. package/src/programmers/internal/check_everything.ts +25 -25
  101. package/src/programmers/internal/check_length.ts +46 -46
  102. package/src/programmers/internal/check_native.ts +9 -9
  103. package/src/programmers/internal/check_number.ts +178 -178
  104. package/src/programmers/internal/check_object.ts +42 -42
  105. package/src/programmers/internal/check_string.ts +24 -24
  106. package/src/programmers/internal/check_string_tags.ts +63 -63
  107. package/src/programmers/internal/check_template.ts +50 -50
  108. package/src/programmers/internal/decode_union_object.ts +73 -73
  109. package/src/programmers/internal/feature_object_entries.ts +49 -49
  110. package/src/programmers/internal/metadata_to_pattern.ts +31 -31
  111. package/src/programmers/internal/stringify_dynamic_properties.ts +164 -164
  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 +24 -24
  117. package/src/schemas/IJsonSchema.ts +92 -92
  118. package/src/transform.ts +20 -20
  119. package/src/transformers/CallExpressionTransformer.ts +124 -124
  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 +4 -4
  124. package/src/transformers/NodeTransformer.ts +19 -19
  125. package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +114 -114
  126. package/src/transformers/features/miscellaneous/CreateInstanceTransformer.ts +41 -41
  127. package/src/transformers/features/miscellaneous/MetadataTransformer.ts +55 -55
  128. package/src/transformers/features/parsers/AssertParseTransformer.ts +36 -36
  129. package/src/transformers/features/parsers/CreateAssertParseTransformer.ts +32 -32
  130. package/src/transformers/features/parsers/CreateIsParseTransformer.ts +32 -32
  131. package/src/transformers/features/parsers/CreateValidateParseTransformer.ts +32 -32
  132. package/src/transformers/features/parsers/IsParseTransformer.ts +36 -36
  133. package/src/transformers/features/parsers/ValidateParseTransformer.ts +36 -36
  134. package/src/transformers/features/stringifiers/AssertStringifyTransformer.ts +38 -38
  135. package/src/transformers/features/stringifiers/CreateAssertStringifyTransformer.ts +32 -32
  136. package/src/transformers/features/stringifiers/CreateIsStringifyTransformer.ts +32 -32
  137. package/src/transformers/features/stringifiers/CreateStringifyTransformer.ts +31 -31
  138. package/src/transformers/features/stringifiers/CreateValidateStringifyProgrammer.ts +32 -32
  139. package/src/transformers/features/stringifiers/IsStringifyTransformer.ts +38 -38
  140. package/src/transformers/features/stringifiers/StringifyTransformer.ts +36 -36
  141. package/src/transformers/features/stringifiers/ValidateStringifyTransformer.ts +38 -38
  142. package/src/transformers/features/validators/AssertTransformer.ts +43 -43
  143. package/src/transformers/features/validators/CreateAssertTransformer.ts +35 -35
  144. package/src/transformers/features/validators/CreateIsTransformer.ts +35 -35
  145. package/src/transformers/features/validators/CreateValidateTransformer.ts +35 -35
  146. package/src/transformers/features/validators/IsTransformer.ts +43 -43
  147. package/src/transformers/features/validators/ValidateTransformer.ts +43 -43
  148. package/src/typings/Atomic.ts +17 -17
  149. package/src/typings/ClassProperties.ts +5 -5
  150. package/src/typings/OmitNever.ts +3 -3
  151. package/src/typings/SpecialFields.ts +3 -3
  152. package/src/typings/Writable.ts +11 -11
  153. package/src/utils/ArrayUtil.ts +49 -49
  154. package/src/utils/Escaper.ts +50 -50
  155. package/src/utils/MapUtil.ts +14 -14
  156. package/src/utils/PatternUtil.ts +30 -30
  157. 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,45 +1,45 @@
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
- (
15
- metadata: Metadata,
16
- nullable: boolean,
17
- attribute: IJsonSchema.IAttribute,
18
- ): IJsonSchema.IArray => {
19
- // SCHEMA
20
- const output: IJsonSchema.IArray = {
21
- type: "array",
22
- items: application_schema(options)(components)(false)(
23
- metadata,
24
- attribute,
25
- ),
26
- nullable,
27
- ...attribute,
28
- };
29
-
30
- // RANGE
31
- for (const tag of attribute["x-typia-metaTags"] || [])
32
- if (tag.kind === "minItems") output.minItems = tag.value;
33
- else if (tag.kind === "maxItems") output.maxItems = tag.value;
34
- else if (tag.kind === "items") {
35
- if (tag.minimum !== undefined)
36
- output.minItems =
37
- tag.minimum.value +
38
- (tag.minimum.include === true ? 0 : 1);
39
- if (tag.maximum !== undefined)
40
- output.maxItems =
41
- tag.maximum.value -
42
- (tag.maximum.include === true ? 0 : 1);
43
- }
44
- return output;
45
- };
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
+ (
15
+ metadata: Metadata,
16
+ nullable: boolean,
17
+ attribute: IJsonSchema.IAttribute,
18
+ ): IJsonSchema.IArray => {
19
+ // SCHEMA
20
+ const output: IJsonSchema.IArray = {
21
+ type: "array",
22
+ items: application_schema(options)(components)(false)(
23
+ metadata,
24
+ attribute,
25
+ ),
26
+ nullable,
27
+ ...attribute,
28
+ };
29
+
30
+ // RANGE
31
+ for (const tag of attribute["x-typia-metaTags"] || [])
32
+ if (tag.kind === "minItems") output.minItems = tag.value;
33
+ else if (tag.kind === "maxItems") output.maxItems = tag.value;
34
+ else if (tag.kind === "items") {
35
+ if (tag.minimum !== undefined)
36
+ output.minItems =
37
+ tag.minimum.value +
38
+ (tag.minimum.include === true ? 0 : 1);
39
+ if (tag.maximum !== undefined)
40
+ output.maxItems =
41
+ tag.maximum.value -
42
+ (tag.maximum.include === true ? 0 : 1);
43
+ }
44
+ return output;
45
+ };
@@ -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 "../../module";
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 "../../module";
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,76 +1,76 @@
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 => {
11
- const output: IJsonSchema.INumber = {
12
- type: "number",
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 === "range") {
27
- if (tag.minimum !== undefined)
28
- if (tag.minimum.include === true)
29
- output.minimum = tag.minimum.value;
30
- else output.exclusiveMinimum = tag.minimum.value;
31
- if (tag.maximum !== undefined)
32
- if (tag.maximum.include === true)
33
- output.maximum = tag.maximum.value;
34
- else output.exclusiveMaximum = tag.maximum.value;
35
- }
36
- // MULTIPLE-OF
37
- else if (tag.kind === "multipleOf") output.multipleOf = tag.value;
38
- }
39
-
40
- // WHEN UNSIGNED INT
41
- if (
42
- output.type === "integer" &&
43
- (attribute["x-typia-metaTags"] || []).find(
44
- (tag) => tag.kind === "type" && tag.value === "uint",
45
- )
46
- )
47
- if (output.minimum === undefined || output.minimum < 0)
48
- output.minimum = 0;
49
- else if (
50
- output.exclusiveMinimum === undefined ||
51
- output.exclusiveMinimum < 0
52
- ) {
53
- delete output.exclusiveMinimum;
54
- output.maximum = 0;
55
- }
56
-
57
- // DEFAULT CONFIGURATION
58
- output.default = application_default(attribute)((str) => {
59
- const value: number = Number(str);
60
- const conditions: boolean[] = [!Number.isNaN(value)];
61
- if (output.minimum !== undefined)
62
- conditions.push(value >= output.minimum);
63
- if (output.maximum !== undefined)
64
- conditions.push(value <= output.maximum);
65
- if (output.exclusiveMinimum !== undefined)
66
- conditions.push(value > output.exclusiveMinimum);
67
- if (output.exclusiveMaximum !== undefined)
68
- conditions.push(value < output.exclusiveMaximum);
69
- if (output.multipleOf !== undefined)
70
- conditions.push(value % output.multipleOf === 0);
71
- return conditions.every((cond) => cond);
72
- })((str) => Number(str));
73
-
74
- // RETURNS
75
- return output;
76
- };
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 => {
11
+ const output: IJsonSchema.INumber = {
12
+ type: "number",
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 === "range") {
27
+ if (tag.minimum !== undefined)
28
+ if (tag.minimum.include === true)
29
+ output.minimum = tag.minimum.value;
30
+ else output.exclusiveMinimum = tag.minimum.value;
31
+ if (tag.maximum !== undefined)
32
+ if (tag.maximum.include === true)
33
+ output.maximum = tag.maximum.value;
34
+ else output.exclusiveMaximum = tag.maximum.value;
35
+ }
36
+ // MULTIPLE-OF
37
+ else if (tag.kind === "multipleOf") output.multipleOf = tag.value;
38
+ }
39
+
40
+ // WHEN UNSIGNED INT
41
+ if (
42
+ output.type === "integer" &&
43
+ (attribute["x-typia-metaTags"] || []).find(
44
+ (tag) => tag.kind === "type" && tag.value === "uint",
45
+ )
46
+ )
47
+ if (output.minimum === undefined || output.minimum < 0)
48
+ output.minimum = 0;
49
+ else if (
50
+ output.exclusiveMinimum === undefined ||
51
+ output.exclusiveMinimum < 0
52
+ ) {
53
+ delete output.exclusiveMinimum;
54
+ output.maximum = 0;
55
+ }
56
+
57
+ // DEFAULT CONFIGURATION
58
+ output.default = application_default(attribute)((str) => {
59
+ const value: number = Number(str);
60
+ const conditions: boolean[] = [!Number.isNaN(value)];
61
+ if (output.minimum !== undefined)
62
+ conditions.push(value >= output.minimum);
63
+ if (output.maximum !== undefined)
64
+ conditions.push(value <= output.maximum);
65
+ if (output.exclusiveMinimum !== undefined)
66
+ conditions.push(value > output.exclusiveMinimum);
67
+ if (output.exclusiveMaximum !== undefined)
68
+ conditions.push(value < output.exclusiveMaximum);
69
+ if (output.multipleOf !== undefined)
70
+ conditions.push(value % output.multipleOf === 0);
71
+ return conditions.every((cond) => cond);
72
+ })((str) => Number(str));
73
+
74
+ // RETURNS
75
+ return output;
76
+ };