typia 3.4.6 → 3.4.8

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 (130) hide show
  1. package/README.md +12 -2
  2. package/lib/executable/internal/CommandParser.d.ts +3 -0
  3. package/lib/executable/internal/CommandParser.js +21 -0
  4. package/lib/executable/internal/CommandParser.js.map +1 -0
  5. package/lib/executable/internal/TypiaSetupWizard.d.ts +2 -2
  6. package/lib/executable/internal/TypiaSetupWizard.js +57 -35
  7. package/lib/executable/internal/TypiaSetupWizard.js.map +1 -1
  8. package/lib/executable/typia.js +22 -21
  9. package/lib/executable/typia.js.map +1 -1
  10. package/lib/factories/internal/iterate_metadata.js +1 -1
  11. package/lib/factories/internal/iterate_metadata.js.map +1 -1
  12. package/lib/factories/internal/iterate_metadata_tuple.d.ts +1 -1
  13. package/lib/factories/internal/iterate_metadata_tuple.js +5 -13
  14. package/lib/factories/internal/iterate_metadata_tuple.js.map +1 -1
  15. package/package.json +2 -2
  16. package/src/IValidation.ts +21 -21
  17. package/src/Primitive.ts +82 -82
  18. package/src/TypeGuardError.ts +36 -36
  19. package/src/executable/internal/CommandParser.ts +15 -0
  20. package/src/executable/internal/TypiaSetupWizard.ts +108 -87
  21. package/src/executable/typia.ts +25 -14
  22. package/src/factories/CommentFactory.ts +10 -10
  23. package/src/factories/ExpressionFactory.ts +52 -52
  24. package/src/factories/IdentifierFactory.ts +72 -72
  25. package/src/factories/LiteralFactory.ts +44 -44
  26. package/src/factories/MetadataCollection.ts +122 -122
  27. package/src/factories/MetadataFactory.ts +46 -46
  28. package/src/factories/StatementFactory.ts +60 -60
  29. package/src/factories/TemplateFactory.ts +56 -56
  30. package/src/factories/TypeFactory.ts +101 -101
  31. package/src/factories/ValueFactory.ts +12 -12
  32. package/src/factories/internal/MetadataHelper.ts +12 -12
  33. package/src/factories/internal/emplace_metadata_object.ts +140 -140
  34. package/src/factories/internal/explore_metadata.ts +91 -91
  35. package/src/factories/internal/iterate_metadata.ts +1 -2
  36. package/src/factories/internal/iterate_metadata_array.ts +29 -29
  37. package/src/factories/internal/iterate_metadata_atomic.ts +59 -59
  38. package/src/factories/internal/iterate_metadata_coalesce.ts +33 -33
  39. package/src/factories/internal/iterate_metadata_constant.ts +58 -58
  40. package/src/factories/internal/iterate_metadata_map.ts +41 -41
  41. package/src/factories/internal/iterate_metadata_object.ts +45 -45
  42. package/src/factories/internal/iterate_metadata_resolve.ts +27 -27
  43. package/src/factories/internal/iterate_metadata_set.ts +33 -33
  44. package/src/factories/internal/iterate_metadata_template.ts +38 -38
  45. package/src/factories/internal/iterate_metadata_tuple.ts +45 -51
  46. package/src/factories/internal/iterate_metadata_union.ts +59 -59
  47. package/src/functional/$every.ts +11 -11
  48. package/src/functional/$guard.ts +35 -35
  49. package/src/functional/$is_email.ts +5 -5
  50. package/src/functional/$is_ipv4.ts +5 -5
  51. package/src/functional/$is_ipv6.ts +5 -5
  52. package/src/functional/$is_url.ts +5 -5
  53. package/src/functional/$is_uuid.ts +5 -5
  54. package/src/functional/$join.ts +50 -50
  55. package/src/functional/$report.ts +15 -15
  56. package/src/functional/$rest.ts +3 -3
  57. package/src/functional/$string.ts +37 -37
  58. package/src/functional/$tail.ts +6 -6
  59. package/src/metadata/IJsDocTagInfo.ts +10 -10
  60. package/src/metadata/IMetadata.ts +25 -25
  61. package/src/metadata/IMetadataApplication.ts +7 -7
  62. package/src/metadata/IMetadataConstant.ts +16 -16
  63. package/src/metadata/IMetadataEntry.ts +6 -6
  64. package/src/metadata/IMetadataObject.ts +29 -29
  65. package/src/metadata/IMetadataProperty.ts +11 -11
  66. package/src/metadata/IMetadataTag.ts +122 -122
  67. package/src/metadata/Metadata.ts +477 -477
  68. package/src/metadata/MetadataConstant.ts +3 -3
  69. package/src/metadata/MetadataObject.ts +131 -131
  70. package/src/metadata/MetadataProperty.ts +64 -64
  71. package/src/programmers/AssertParseProgrammer.ts +45 -45
  72. package/src/programmers/AssertProgrammer.ts +444 -444
  73. package/src/programmers/AssertStringifyProgrammer.ts +45 -45
  74. package/src/programmers/CheckerProgrammer.ts +798 -798
  75. package/src/programmers/FeatureProgrammer.ts +327 -327
  76. package/src/programmers/IsParseProgrammer.ts +51 -51
  77. package/src/programmers/IsProgrammer.ts +169 -169
  78. package/src/programmers/IsStringifyProgrammer.ts +49 -49
  79. package/src/programmers/ValidateParseProgrammer.ts +49 -49
  80. package/src/programmers/ValidateProgrammer.ts +236 -236
  81. package/src/programmers/ValidateStringifyProgrammer.ts +60 -60
  82. package/src/programmers/helpers/AtomicPredicator.ts +15 -15
  83. package/src/programmers/helpers/FunctionImporeter.ts +31 -31
  84. package/src/programmers/helpers/IExpressionEntry.ts +10 -10
  85. package/src/programmers/helpers/OptionPredicator.ts +18 -18
  86. package/src/programmers/helpers/StringifyJoinder.ts +111 -111
  87. package/src/programmers/helpers/StringifyPredicator.ts +18 -18
  88. package/src/programmers/helpers/UnionExplorer.ts +437 -437
  89. package/src/programmers/helpers/UnionPredicator.ts +81 -81
  90. package/src/programmers/internal/application_boolean.ts +17 -17
  91. package/src/programmers/internal/application_constant.ts +29 -29
  92. package/src/programmers/internal/application_default_string.ts +32 -32
  93. package/src/programmers/internal/application_native.ts +29 -29
  94. package/src/programmers/internal/application_schema.ts +221 -221
  95. package/src/programmers/internal/application_templates.ts +27 -27
  96. package/src/programmers/internal/application_tuple.ts +25 -25
  97. package/src/programmers/internal/check_array.ts +44 -44
  98. package/src/programmers/internal/check_dynamic_properties.ts +146 -146
  99. package/src/programmers/internal/check_everything.ts +25 -25
  100. package/src/programmers/internal/check_length.ts +46 -46
  101. package/src/programmers/internal/check_native.ts +9 -9
  102. package/src/programmers/internal/check_number.ts +181 -181
  103. package/src/programmers/internal/check_object.ts +42 -42
  104. package/src/programmers/internal/check_string.ts +24 -24
  105. package/src/programmers/internal/check_string_tags.ts +63 -63
  106. package/src/programmers/internal/check_template.ts +50 -50
  107. package/src/programmers/internal/decode_union_object.ts +73 -73
  108. package/src/programmers/internal/feature_object_entries.ts +49 -49
  109. package/src/programmers/internal/metadata_to_pattern.ts +31 -31
  110. package/src/programmers/internal/stringify_dynamic_properties.ts +164 -164
  111. package/src/programmers/internal/stringify_native.ts +8 -8
  112. package/src/programmers/internal/stringify_regular_properties.ts +81 -81
  113. package/src/programmers/internal/template_to_pattern.ts +15 -15
  114. package/src/schemas/IJsonApplication.ts +9 -9
  115. package/src/transform.ts +20 -20
  116. package/src/transformers/ExpressionWithArgumentTransformer.ts +66 -66
  117. package/src/transformers/FileTransformer.ts +49 -49
  118. package/src/transformers/IProject.ts +11 -11
  119. package/src/transformers/ITransformOptions.ts +4 -4
  120. package/src/transformers/NodeTransformer.ts +19 -19
  121. package/src/typings/Atomic.ts +17 -17
  122. package/src/typings/ClassProperties.ts +5 -5
  123. package/src/typings/OmitNever.ts +3 -3
  124. package/src/typings/SpecialFields.ts +3 -3
  125. package/src/typings/Writable.ts +11 -11
  126. package/src/utils/ArrayUtil.ts +49 -49
  127. package/src/utils/Escaper.ts +50 -50
  128. package/src/utils/MapUtil.ts +14 -14
  129. package/src/utils/PatternUtil.ts +30 -30
  130. package/src/utils/Singleton.ts +17 -17
@@ -1,221 +1,221 @@
1
- import { Metadata } from "../../metadata/Metadata";
2
- import { MetadataConstant } from "../../metadata/MetadataConstant";
3
- import { IJsonComponents } from "../../schemas/IJsonComponents";
4
- import { IJsonSchema } from "../../schemas/IJsonSchema";
5
-
6
- import { ArrayUtil } from "../../utils/ArrayUtil";
7
-
8
- import { ApplicationProgrammer } from "../ApplicationProgrammer";
9
- import { AtomicPredicator } from "../helpers/AtomicPredicator";
10
- import { application_array } from "./application_array";
11
- import { application_boolean } from "./application_boolean";
12
- import { application_constant } from "./application_constant";
13
- import { application_native } from "./application_native";
14
- import { application_number } from "./application_number";
15
- import { application_object } from "./application_object";
16
- import { application_string } from "./application_string";
17
- import { application_templates } from "./application_templates";
18
- import { application_tuple } from "./application_tuple";
19
-
20
- /**
21
- * @internal
22
- */
23
- export const application_schema =
24
- (options: ApplicationProgrammer.IOptions) =>
25
- (components: IJsonComponents) =>
26
- <BlockNever extends boolean>(blockNever: BlockNever) =>
27
- (
28
- meta: Metadata,
29
- attribute: IJsonSchema.IAttribute,
30
- ): BlockNever extends true ? IJsonSchema | null : IJsonSchema => {
31
- // VULNERABLE CASE
32
- if (meta.any === true) return {};
33
- else if (meta.nullable && meta.empty())
34
- return { type: "null", ...attribute };
35
-
36
- //----
37
- // GATHER UNION SCHEMAS
38
- //----
39
- const union: IJsonSchema[] = [];
40
-
41
- // toJSON() METHOD
42
- if (meta.resolved !== null) {
43
- const resolved = application_schema(options)(components)(
44
- blockNever,
45
- )(meta.resolved, attribute);
46
- if (resolved !== null) union.push(resolved);
47
- }
48
-
49
- // ATOMIC TYPES
50
- if (meta.templates.length && AtomicPredicator.template(meta))
51
- union.push(application_templates(meta, attribute));
52
- for (const constant of meta.constants) {
53
- if (constant.type === "string" && meta.templates.length) continue;
54
- else if (!AtomicPredicator.constant(meta)(constant.type)) continue;
55
- union.push(
56
- application_constant(constant, meta.nullable, attribute),
57
- );
58
- }
59
- for (const type of meta.atomics) {
60
- union.push(
61
- type === "string"
62
- ? application_string(meta, attribute)
63
- : type === "boolean"
64
- ? application_boolean(meta.nullable, attribute)
65
- : application_number(meta.nullable, attribute),
66
- );
67
- }
68
-
69
- // ARRAY
70
- for (const schema of meta.arrays.values())
71
- union.push(
72
- application_array(options)(components)(
73
- schema,
74
- meta.nullable,
75
- attribute,
76
- ),
77
- );
78
-
79
- // TUPLE
80
- for (const items of meta.tuples)
81
- if (
82
- options.purpose === "ajv" &&
83
- items.every((i) => i.rest === null)
84
- )
85
- union.push(
86
- application_tuple(options)(components)(
87
- items,
88
- meta.nullable,
89
- attribute,
90
- ),
91
- );
92
- else {
93
- // SWAGGER DOES NOT SUPPORT TUPLE TYPE YET
94
- const merged: Metadata = items.reduce((x, y) =>
95
- merge_metadata(x, y),
96
- );
97
- union.push(
98
- application_array(options)(components)(
99
- merged,
100
- merged?.nullable || false,
101
- attribute,
102
- ),
103
- );
104
- }
105
-
106
- // NATIVES
107
- for (const native of meta.natives)
108
- union.push(
109
- application_native(options)(components)(native)(
110
- meta.nullable,
111
- attribute,
112
- ),
113
- );
114
- if (meta.sets.length)
115
- union.push(
116
- application_native(options)(components)(`Set`)(
117
- meta.nullable,
118
- attribute,
119
- ),
120
- );
121
- if (meta.maps.length)
122
- union.push(
123
- application_native(options)(components)(`Map`)(
124
- meta.nullable,
125
- attribute,
126
- ),
127
- );
128
-
129
- // OBJECT
130
- for (const obj of meta.objects) {
131
- const key: string = obj.name + (meta.nullable ? ".Nullable" : "");
132
- application_object(options)(components)(key, obj, meta.nullable);
133
- union.push(
134
- (options.purpose === "ajv" && obj.recursive
135
- ? recursive
136
- : reference)(`${options.prefix}/${key}`, attribute),
137
- );
138
- }
139
-
140
- //----
141
- // RETURNS
142
- //----
143
- if (union.length === 0) return blockNever === true ? null! : {};
144
- else if (union.length === 1) return union[0]!;
145
- return { oneOf: union, ...attribute };
146
- };
147
-
148
- /**
149
- * @internal
150
- */
151
- const reference = (
152
- $ref: string,
153
- attribute: IJsonSchema.IAttribute,
154
- ): IJsonSchema.IReference => ({
155
- $ref,
156
- ...attribute,
157
- });
158
-
159
- /**
160
- * @internal
161
- */
162
- const recursive = (
163
- $recursiveRef: string,
164
- attribute: IJsonSchema.IAttribute,
165
- ): IJsonSchema.IRecursiveReference => ({
166
- $recursiveRef,
167
- ...attribute,
168
- });
169
-
170
- /**
171
- * @internal
172
- * @todo: not perfect
173
- */
174
- function merge_metadata(x: Metadata, y: Metadata): Metadata {
175
- const output: Metadata = Metadata.create({
176
- any: x.any || y.any,
177
- nullable: x.nullable || y.nullable,
178
- required: x.required && y.required,
179
- functional: x.functional || y.functional,
180
-
181
- resolved:
182
- x.resolved !== null && y.resolved !== null
183
- ? merge_metadata(x.resolved, y.resolved)
184
- : x.resolved || y.resolved,
185
- atomics: [...new Set([...x.atomics, ...y.atomics])],
186
- constants: [...x.constants],
187
- templates: x.templates.slice(),
188
-
189
- rest: null,
190
- arrays: x.arrays.slice(),
191
- tuples: x.tuples.slice(),
192
- objects: x.objects.slice(),
193
-
194
- natives: [...new Set([...x.natives, ...y.natives])],
195
- sets: x.sets.slice(),
196
- maps: x.maps.slice(),
197
- });
198
- for (const constant of y.constants) {
199
- const target: MetadataConstant = ArrayUtil.take(
200
- output.constants,
201
- (elem) => elem.type === constant.type,
202
- () => ({
203
- type: constant.type,
204
- values: [],
205
- }),
206
- );
207
- for (const value of constant.values)
208
- ArrayUtil.add(target.values, value);
209
- }
210
- for (const array of y.arrays)
211
- ArrayUtil.set(output.arrays, array, (elem) => elem.getName());
212
- for (const obj of y.objects)
213
- ArrayUtil.set(output.objects, obj, (elem) => elem.name);
214
-
215
- if (x.rest !== null)
216
- ArrayUtil.set(output.arrays, x.rest, (elem) => elem.getName());
217
- if (y.rest !== null)
218
- ArrayUtil.set(output.arrays, y.rest, (elem) => elem.getName());
219
-
220
- return output;
221
- }
1
+ import { Metadata } from "../../metadata/Metadata";
2
+ import { MetadataConstant } from "../../metadata/MetadataConstant";
3
+ import { IJsonComponents } from "../../schemas/IJsonComponents";
4
+ import { IJsonSchema } from "../../schemas/IJsonSchema";
5
+
6
+ import { ArrayUtil } from "../../utils/ArrayUtil";
7
+
8
+ import { ApplicationProgrammer } from "../ApplicationProgrammer";
9
+ import { AtomicPredicator } from "../helpers/AtomicPredicator";
10
+ import { application_array } from "./application_array";
11
+ import { application_boolean } from "./application_boolean";
12
+ import { application_constant } from "./application_constant";
13
+ import { application_native } from "./application_native";
14
+ import { application_number } from "./application_number";
15
+ import { application_object } from "./application_object";
16
+ import { application_string } from "./application_string";
17
+ import { application_templates } from "./application_templates";
18
+ import { application_tuple } from "./application_tuple";
19
+
20
+ /**
21
+ * @internal
22
+ */
23
+ export const application_schema =
24
+ (options: ApplicationProgrammer.IOptions) =>
25
+ (components: IJsonComponents) =>
26
+ <BlockNever extends boolean>(blockNever: BlockNever) =>
27
+ (
28
+ meta: Metadata,
29
+ attribute: IJsonSchema.IAttribute,
30
+ ): BlockNever extends true ? IJsonSchema | null : IJsonSchema => {
31
+ // VULNERABLE CASE
32
+ if (meta.any === true) return {};
33
+ else if (meta.nullable && meta.empty())
34
+ return { type: "null", ...attribute };
35
+
36
+ //----
37
+ // GATHER UNION SCHEMAS
38
+ //----
39
+ const union: IJsonSchema[] = [];
40
+
41
+ // toJSON() METHOD
42
+ if (meta.resolved !== null) {
43
+ const resolved = application_schema(options)(components)(
44
+ blockNever,
45
+ )(meta.resolved, attribute);
46
+ if (resolved !== null) union.push(resolved);
47
+ }
48
+
49
+ // ATOMIC TYPES
50
+ if (meta.templates.length && AtomicPredicator.template(meta))
51
+ union.push(application_templates(meta, attribute));
52
+ for (const constant of meta.constants) {
53
+ if (constant.type === "string" && meta.templates.length) continue;
54
+ else if (!AtomicPredicator.constant(meta)(constant.type)) continue;
55
+ union.push(
56
+ application_constant(constant, meta.nullable, attribute),
57
+ );
58
+ }
59
+ for (const type of meta.atomics) {
60
+ union.push(
61
+ type === "string"
62
+ ? application_string(meta, attribute)
63
+ : type === "boolean"
64
+ ? application_boolean(meta.nullable, attribute)
65
+ : application_number(meta.nullable, attribute),
66
+ );
67
+ }
68
+
69
+ // ARRAY
70
+ for (const schema of meta.arrays.values())
71
+ union.push(
72
+ application_array(options)(components)(
73
+ schema,
74
+ meta.nullable,
75
+ attribute,
76
+ ),
77
+ );
78
+
79
+ // TUPLE
80
+ for (const items of meta.tuples)
81
+ if (
82
+ options.purpose === "ajv" &&
83
+ items.every((i) => i.rest === null)
84
+ )
85
+ union.push(
86
+ application_tuple(options)(components)(
87
+ items,
88
+ meta.nullable,
89
+ attribute,
90
+ ),
91
+ );
92
+ else {
93
+ // SWAGGER DOES NOT SUPPORT TUPLE TYPE YET
94
+ const merged: Metadata = items.reduce((x, y) =>
95
+ merge_metadata(x, y),
96
+ );
97
+ union.push(
98
+ application_array(options)(components)(
99
+ merged,
100
+ merged?.nullable || false,
101
+ attribute,
102
+ ),
103
+ );
104
+ }
105
+
106
+ // NATIVES
107
+ for (const native of meta.natives)
108
+ union.push(
109
+ application_native(options)(components)(native)(
110
+ meta.nullable,
111
+ attribute,
112
+ ),
113
+ );
114
+ if (meta.sets.length)
115
+ union.push(
116
+ application_native(options)(components)(`Set`)(
117
+ meta.nullable,
118
+ attribute,
119
+ ),
120
+ );
121
+ if (meta.maps.length)
122
+ union.push(
123
+ application_native(options)(components)(`Map`)(
124
+ meta.nullable,
125
+ attribute,
126
+ ),
127
+ );
128
+
129
+ // OBJECT
130
+ for (const obj of meta.objects) {
131
+ const key: string = obj.name + (meta.nullable ? ".Nullable" : "");
132
+ application_object(options)(components)(key, obj, meta.nullable);
133
+ union.push(
134
+ (options.purpose === "ajv" && obj.recursive
135
+ ? recursive
136
+ : reference)(`${options.prefix}/${key}`, attribute),
137
+ );
138
+ }
139
+
140
+ //----
141
+ // RETURNS
142
+ //----
143
+ if (union.length === 0) return blockNever === true ? null! : {};
144
+ else if (union.length === 1) return union[0]!;
145
+ return { oneOf: union, ...attribute };
146
+ };
147
+
148
+ /**
149
+ * @internal
150
+ */
151
+ const reference = (
152
+ $ref: string,
153
+ attribute: IJsonSchema.IAttribute,
154
+ ): IJsonSchema.IReference => ({
155
+ $ref,
156
+ ...attribute,
157
+ });
158
+
159
+ /**
160
+ * @internal
161
+ */
162
+ const recursive = (
163
+ $recursiveRef: string,
164
+ attribute: IJsonSchema.IAttribute,
165
+ ): IJsonSchema.IRecursiveReference => ({
166
+ $recursiveRef,
167
+ ...attribute,
168
+ });
169
+
170
+ /**
171
+ * @internal
172
+ * @todo: not perfect
173
+ */
174
+ function merge_metadata(x: Metadata, y: Metadata): Metadata {
175
+ const output: Metadata = Metadata.create({
176
+ any: x.any || y.any,
177
+ nullable: x.nullable || y.nullable,
178
+ required: x.required && y.required,
179
+ functional: x.functional || y.functional,
180
+
181
+ resolved:
182
+ x.resolved !== null && y.resolved !== null
183
+ ? merge_metadata(x.resolved, y.resolved)
184
+ : x.resolved || y.resolved,
185
+ atomics: [...new Set([...x.atomics, ...y.atomics])],
186
+ constants: [...x.constants],
187
+ templates: x.templates.slice(),
188
+
189
+ rest: null,
190
+ arrays: x.arrays.slice(),
191
+ tuples: x.tuples.slice(),
192
+ objects: x.objects.slice(),
193
+
194
+ natives: [...new Set([...x.natives, ...y.natives])],
195
+ sets: x.sets.slice(),
196
+ maps: x.maps.slice(),
197
+ });
198
+ for (const constant of y.constants) {
199
+ const target: MetadataConstant = ArrayUtil.take(
200
+ output.constants,
201
+ (elem) => elem.type === constant.type,
202
+ () => ({
203
+ type: constant.type,
204
+ values: [],
205
+ }),
206
+ );
207
+ for (const value of constant.values)
208
+ ArrayUtil.add(target.values, value);
209
+ }
210
+ for (const array of y.arrays)
211
+ ArrayUtil.set(output.arrays, array, (elem) => elem.getName());
212
+ for (const obj of y.objects)
213
+ ArrayUtil.set(output.objects, obj, (elem) => elem.name);
214
+
215
+ if (x.rest !== null)
216
+ ArrayUtil.set(output.arrays, x.rest, (elem) => elem.getName());
217
+ if (y.rest !== null)
218
+ ArrayUtil.set(output.arrays, y.rest, (elem) => elem.getName());
219
+
220
+ return output;
221
+ }
@@ -1,27 +1,27 @@
1
- import { Metadata } from "../../metadata/Metadata";
2
- import { IJsonSchema } from "../../schemas/IJsonSchema";
3
-
4
- import { application_default_string } from "./application_default_string";
5
- import { metadata_to_pattern } from "./metadata_to_pattern";
6
-
7
- /**
8
- * @internal
9
- */
10
- export const application_templates = (
11
- meta: Metadata,
12
- attribute: IJsonSchema.IAttribute,
13
- ): IJsonSchema.IString => {
14
- // CONSTRUCT PATTERN
15
- const output: IJsonSchema.IString = {
16
- type: "string",
17
- nullable: meta.nullable,
18
- ...attribute,
19
- };
20
- output.pattern = metadata_to_pattern(true)(meta);
21
-
22
- // DEFAULT VALUE
23
- output.default = application_default_string(meta, attribute)(output);
24
-
25
- // RETURNS
26
- return output;
27
- };
1
+ import { Metadata } from "../../metadata/Metadata";
2
+ import { IJsonSchema } from "../../schemas/IJsonSchema";
3
+
4
+ import { application_default_string } from "./application_default_string";
5
+ import { metadata_to_pattern } from "./metadata_to_pattern";
6
+
7
+ /**
8
+ * @internal
9
+ */
10
+ export const application_templates = (
11
+ meta: Metadata,
12
+ attribute: IJsonSchema.IAttribute,
13
+ ): IJsonSchema.IString => {
14
+ // CONSTRUCT PATTERN
15
+ const output: IJsonSchema.IString = {
16
+ type: "string",
17
+ nullable: meta.nullable,
18
+ ...attribute,
19
+ };
20
+ output.pattern = metadata_to_pattern(true)(meta);
21
+
22
+ // DEFAULT VALUE
23
+ output.default = application_default_string(meta, attribute)(output);
24
+
25
+ // RETURNS
26
+ return output;
27
+ };
@@ -1,25 +1,25 @@
1
- import { Metadata } from "../../metadata/Metadata";
2
- import { IJsonComponents } from "../../schemas/IJsonComponents";
3
- import { IJsonSchema } from "../../schemas/IJsonSchema";
4
-
5
- import { ApplicationProgrammer } from "../ApplicationProgrammer";
6
- import { application_schema } from "./application_schema";
7
-
8
- /**
9
- * @internal
10
- */
11
- export const application_tuple =
12
- (options: ApplicationProgrammer.IOptions) =>
13
- (components: IJsonComponents) =>
14
- (
15
- items: Array<Metadata>,
16
- nullable: boolean,
17
- attribute: IJsonSchema.IAttribute,
18
- ): IJsonSchema.ITuple => ({
19
- type: "array",
20
- items: items.map((meta) =>
21
- application_schema(options)(components)(false)(meta, attribute),
22
- ),
23
- nullable,
24
- ...attribute,
25
- });
1
+ import { Metadata } from "../../metadata/Metadata";
2
+ import { IJsonComponents } from "../../schemas/IJsonComponents";
3
+ import { IJsonSchema } from "../../schemas/IJsonSchema";
4
+
5
+ import { ApplicationProgrammer } from "../ApplicationProgrammer";
6
+ import { application_schema } from "./application_schema";
7
+
8
+ /**
9
+ * @internal
10
+ */
11
+ export const application_tuple =
12
+ (options: ApplicationProgrammer.IOptions) =>
13
+ (components: IJsonComponents) =>
14
+ (
15
+ items: Array<Metadata>,
16
+ nullable: boolean,
17
+ attribute: IJsonSchema.IAttribute,
18
+ ): IJsonSchema.ITuple => ({
19
+ type: "array",
20
+ items: items.map((meta) =>
21
+ application_schema(options)(components)(false)(meta, attribute),
22
+ ),
23
+ nullable,
24
+ ...attribute,
25
+ });
@@ -1,44 +1,44 @@
1
- import ts from "typescript";
2
-
3
- import { ExpressionFactory } from "../../factories/ExpressionFactory";
4
- import { IdentifierFactory } from "../../factories/IdentifierFactory";
5
-
6
- import { IMetadataTag } from "../../metadata/IMetadataTag";
7
-
8
- import { check_length } from "./check_length";
9
-
10
- /**
11
- * @internal
12
- */
13
- export function check_array(
14
- input: ts.Expression,
15
- tagList: IMetadataTag[],
16
- ): ts.Expression {
17
- const conditions: ts.Expression[] = [ExpressionFactory.isArray(input)];
18
-
19
- // CHECK TAGS
20
- for (const tag of tagList)
21
- if (tag.kind === "minItems")
22
- conditions.push(
23
- ts.factory.createLessThanEquals(
24
- ts.factory.createNumericLiteral(tag.value),
25
- IdentifierFactory.join(input, "length"),
26
- ),
27
- );
28
- else if (tag.kind === "maxItems")
29
- conditions.push(
30
- ts.factory.createGreaterThanEquals(
31
- ts.factory.createNumericLiteral(tag.value),
32
- IdentifierFactory.join(input, "length"),
33
- ),
34
- );
35
- else if (tag.kind === "items")
36
- check_length(
37
- conditions,
38
- IdentifierFactory.join(input, "length"),
39
- tag,
40
- );
41
-
42
- // COMBINATION
43
- return conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y));
44
- }
1
+ import ts from "typescript";
2
+
3
+ import { ExpressionFactory } from "../../factories/ExpressionFactory";
4
+ import { IdentifierFactory } from "../../factories/IdentifierFactory";
5
+
6
+ import { IMetadataTag } from "../../metadata/IMetadataTag";
7
+
8
+ import { check_length } from "./check_length";
9
+
10
+ /**
11
+ * @internal
12
+ */
13
+ export function check_array(
14
+ input: ts.Expression,
15
+ tagList: IMetadataTag[],
16
+ ): ts.Expression {
17
+ const conditions: ts.Expression[] = [ExpressionFactory.isArray(input)];
18
+
19
+ // CHECK TAGS
20
+ for (const tag of tagList)
21
+ if (tag.kind === "minItems")
22
+ conditions.push(
23
+ ts.factory.createLessThanEquals(
24
+ ts.factory.createNumericLiteral(tag.value),
25
+ IdentifierFactory.join(input, "length"),
26
+ ),
27
+ );
28
+ else if (tag.kind === "maxItems")
29
+ conditions.push(
30
+ ts.factory.createGreaterThanEquals(
31
+ ts.factory.createNumericLiteral(tag.value),
32
+ IdentifierFactory.join(input, "length"),
33
+ ),
34
+ );
35
+ else if (tag.kind === "items")
36
+ check_length(
37
+ conditions,
38
+ IdentifierFactory.join(input, "length"),
39
+ tag,
40
+ );
41
+
42
+ // COMBINATION
43
+ return conditions.reduce((x, y) => ts.factory.createLogicalAnd(x, y));
44
+ }