typia 5.0.0-dev.20230823-2 → 5.0.0-dev.2023084

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 (148) hide show
  1. package/lib/factories/MetadataTagFactory.js +4 -2
  2. package/lib/factories/MetadataTagFactory.js.map +1 -1
  3. package/lib/factories/ProtobufFactory.js +2 -1
  4. package/lib/factories/ProtobufFactory.js.map +1 -1
  5. package/lib/factories/internal/metadata/emend_metadata_atomics.js +6 -6
  6. package/lib/factories/internal/metadata/emend_metadata_atomics.js.map +1 -1
  7. package/lib/factories/internal/metadata/iterate_metadata_atomic.js +1 -1
  8. package/lib/factories/internal/metadata/iterate_metadata_atomic.js.map +1 -1
  9. package/lib/programmers/CheckerProgrammer.js +6 -6
  10. package/lib/programmers/CheckerProgrammer.js.map +1 -1
  11. package/lib/programmers/RandomProgrammer.js +5 -5
  12. package/lib/programmers/RandomProgrammer.js.map +1 -1
  13. package/lib/programmers/helpers/AtomicPredicator.js +2 -2
  14. package/lib/programmers/helpers/AtomicPredicator.js.map +1 -1
  15. package/lib/programmers/helpers/ProtobufUtil.js +2 -2
  16. package/lib/programmers/helpers/ProtobufUtil.js.map +1 -1
  17. package/lib/programmers/internal/application_default_string.js +2 -2
  18. package/lib/programmers/internal/application_default_string.js.map +1 -1
  19. package/lib/programmers/internal/application_schema.js +5 -5
  20. package/lib/programmers/internal/application_schema.js.map +1 -1
  21. package/lib/programmers/internal/metadata_to_pattern.js +4 -4
  22. package/lib/programmers/internal/metadata_to_pattern.js.map +1 -1
  23. package/lib/programmers/internal/stringify_dynamic_properties.js +2 -1
  24. package/lib/programmers/internal/stringify_dynamic_properties.js.map +1 -1
  25. package/lib/programmers/json/JsonStringifyProgrammer.js +16 -10
  26. package/lib/programmers/json/JsonStringifyProgrammer.js.map +1 -1
  27. package/lib/programmers/misc/MiscLiteralsProgrammer.js +2 -2
  28. package/lib/programmers/misc/MiscLiteralsProgrammer.js.map +1 -1
  29. package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js +1 -1
  30. package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js.map +1 -1
  31. package/lib/schemas/metadata/IMetadata.d.ts +2 -2
  32. package/lib/schemas/metadata/IMetadataAtomic.d.ts +12 -0
  33. package/lib/schemas/metadata/IMetadataAtomic.js +3 -0
  34. package/lib/schemas/metadata/IMetadataAtomic.js.map +1 -0
  35. package/lib/schemas/metadata/Metadata.d.ts +2 -2
  36. package/lib/schemas/metadata/Metadata.js +49 -44
  37. package/lib/schemas/metadata/Metadata.js.map +1 -1
  38. package/lib/tags/ExclusiveMaximum.d.ts +8 -0
  39. package/lib/tags/ExclusiveMaximum.js +3 -0
  40. package/lib/tags/ExclusiveMaximum.js.map +1 -0
  41. package/lib/tags/ExclusiveMinimum.d.ts +8 -0
  42. package/lib/tags/ExclusiveMinimum.js +3 -0
  43. package/lib/tags/ExclusiveMinimum.js.map +1 -0
  44. package/lib/tags/Format.d.ts +8 -0
  45. package/lib/tags/Format.js +3 -0
  46. package/lib/tags/Format.js.map +1 -0
  47. package/lib/tags/MaxItems.d.ts +8 -0
  48. package/lib/tags/MaxItems.js +3 -0
  49. package/lib/tags/MaxItems.js.map +1 -0
  50. package/lib/tags/MaxLength.d.ts +8 -0
  51. package/lib/tags/MaxLength.js +3 -0
  52. package/lib/tags/MaxLength.js.map +1 -0
  53. package/lib/tags/Maximum.d.ts +8 -0
  54. package/lib/tags/Maximum.js +3 -0
  55. package/lib/tags/Maximum.js.map +1 -0
  56. package/lib/tags/MinItems.d.ts +8 -0
  57. package/lib/tags/MinItems.js +3 -0
  58. package/lib/tags/MinItems.js.map +1 -0
  59. package/lib/tags/MinLength.d.ts +8 -0
  60. package/lib/tags/MinLength.js +3 -0
  61. package/lib/tags/MinLength.js.map +1 -0
  62. package/lib/tags/Minimum.d.ts +8 -0
  63. package/lib/tags/Minimum.js +3 -0
  64. package/lib/tags/Minimum.js.map +1 -0
  65. package/lib/tags/MultipleOf.d.ts +8 -0
  66. package/lib/tags/MultipleOf.js +3 -0
  67. package/lib/tags/MultipleOf.js.map +1 -0
  68. package/lib/tags/Pattern.d.ts +8 -0
  69. package/lib/tags/Pattern.js +3 -0
  70. package/lib/tags/Pattern.js.map +1 -0
  71. package/lib/tags/TagBase.d.ts +10 -0
  72. package/lib/tags/TagBase.js +3 -0
  73. package/lib/tags/TagBase.js.map +1 -0
  74. package/lib/tags/Type.d.ts +13 -0
  75. package/lib/tags/Type.js +3 -0
  76. package/lib/tags/Type.js.map +1 -0
  77. package/lib/tags/index.d.ts +12 -0
  78. package/lib/tags/index.js +29 -0
  79. package/lib/tags/index.js.map +1 -0
  80. package/lib/transformers/features/json/JsonApplicationTransformer.js +1 -1
  81. package/lib/transformers/features/json/JsonApplicationTransformer.js.map +1 -1
  82. package/package.json +1 -1
  83. package/src/Primitive.ts +135 -135
  84. package/src/Resolved.ts +116 -116
  85. package/src/factories/MetadataFactory.ts +46 -46
  86. package/src/factories/MetadataTagFactory.ts +366 -364
  87. package/src/factories/ProtobufFactory.ts +268 -266
  88. package/src/factories/internal/metadata/emend_metadata_atomics.ts +35 -33
  89. package/src/factories/internal/metadata/explore_metadata.ts +38 -38
  90. package/src/factories/internal/metadata/iterate_metadata_atomic.ts +63 -59
  91. package/src/factories/internal/metadata/iterate_metadata_collection.ts +133 -133
  92. package/src/factories/internal/metadata/iterate_metadata_native.ts +210 -210
  93. package/src/factories/internal/metadata/iterate_metadata_resolve.ts +49 -49
  94. package/src/factories/internal/metadata/iterate_metadata_sort.ts +69 -69
  95. package/src/functional/$ProtobufWriter.ts +151 -151
  96. package/src/json.ts +648 -648
  97. package/src/misc.ts +651 -651
  98. package/src/module.ts +709 -709
  99. package/src/programmers/AssertProgrammer.ts +281 -281
  100. package/src/programmers/CheckerProgrammer.ts +1174 -1173
  101. package/src/programmers/IsProgrammer.ts +241 -241
  102. package/src/programmers/RandomProgrammer.ts +874 -874
  103. package/src/programmers/ValidateProgrammer.ts +307 -307
  104. package/src/programmers/helpers/AtomicPredicator.ts +31 -31
  105. package/src/programmers/helpers/FunctionImporeter.ts +91 -91
  106. package/src/programmers/helpers/ProtobufUtil.ts +29 -29
  107. package/src/programmers/helpers/StringifyPredicator.ts +12 -12
  108. package/src/programmers/helpers/disable_function_importer_declare.ts +32 -32
  109. package/src/programmers/internal/application_default_string.ts +37 -33
  110. package/src/programmers/internal/application_resolved.ts +55 -55
  111. package/src/programmers/internal/application_schema.ts +157 -157
  112. package/src/programmers/internal/metadata_to_pattern.ts +34 -34
  113. package/src/programmers/internal/stringify_dynamic_properties.ts +171 -171
  114. package/src/programmers/json/JsonStringifyProgrammer.ts +995 -989
  115. package/src/programmers/misc/MiscAssertCloneProgrammer.ts +71 -71
  116. package/src/programmers/misc/MiscCloneProgrammer.ts +775 -775
  117. package/src/programmers/misc/MiscIsCloneProgrammer.ts +78 -78
  118. package/src/programmers/misc/MiscLiteralsProgrammer.ts +64 -64
  119. package/src/programmers/misc/MiscPruneProgrammer.ts +544 -544
  120. package/src/programmers/misc/MiscValidateCloneProgrammer.ts +85 -85
  121. package/src/programmers/protobuf/ProtobufAssertDecodeProgrammer.ts +75 -75
  122. package/src/programmers/protobuf/ProtobufDecodeProgrammer.ts +673 -673
  123. package/src/programmers/protobuf/ProtobufEncodeProgrammer.ts +814 -814
  124. package/src/programmers/protobuf/ProtobufIsDecodeProgrammer.ts +85 -85
  125. package/src/programmers/protobuf/ProtobufValidateDecodeProgrammer.ts +75 -75
  126. package/src/protobuf.ts +881 -881
  127. package/src/schemas/metadata/IMetadata.ts +27 -28
  128. package/src/schemas/metadata/IMetadataAtomic.ts +13 -0
  129. package/src/schemas/metadata/IMetadataEscaped.ts +6 -6
  130. package/src/schemas/metadata/Metadata.ts +643 -634
  131. package/src/schemas/metadata/MetadataEscaped.ts +51 -51
  132. package/src/tags/ExclusiveMaximum.ts +8 -0
  133. package/src/tags/ExclusiveMinimum.ts +8 -0
  134. package/src/tags/Format.ts +29 -0
  135. package/src/tags/MaxItems.ts +8 -0
  136. package/src/tags/MaxLength.ts +8 -0
  137. package/src/tags/Maximum.ts +8 -0
  138. package/src/tags/MinItems.ts +8 -0
  139. package/src/tags/MinLength.ts +8 -0
  140. package/src/tags/Minimum.ts +8 -0
  141. package/src/tags/MultipleOf.ts +10 -0
  142. package/src/tags/Pattern.ts +8 -0
  143. package/src/tags/TagBase.ts +17 -0
  144. package/src/tags/Type.ts +30 -0
  145. package/src/tags/index.ts +12 -0
  146. package/src/transformers/features/json/JsonApplicationTransformer.ts +111 -111
  147. package/src/transformers/features/misc/MetadataTransformer.ts +53 -53
  148. package/src/utils/RandomGenerator.ts +83 -83
@@ -1,51 +1,51 @@
1
- import { ClassProperties } from "../../typings/ClassProperties";
2
-
3
- import { IMetadataDictionary } from "./IMetadataDictionary";
4
- import { IMetadataEscaped } from "./IMetadataEscaped";
5
- import { Metadata } from "./Metadata";
6
-
7
- export class MetadataEscaped {
8
- public readonly original: Metadata;
9
- public readonly returns: Metadata;
10
-
11
- /**
12
- * @hidden
13
- */
14
- private constructor(props: ClassProperties<MetadataEscaped>) {
15
- this.original = props.original;
16
- this.returns = props.returns;
17
- }
18
-
19
- /**
20
- * @internal
21
- */
22
- public static _From(
23
- props: IMetadataEscaped,
24
- dict: IMetadataDictionary,
25
- ): MetadataEscaped {
26
- return this.create({
27
- original: Metadata._From(props.original, dict),
28
- returns: Metadata._From(props.returns, dict),
29
- });
30
- }
31
-
32
- /**
33
- * @internal
34
- */
35
- public static create(
36
- props: ClassProperties<MetadataEscaped>,
37
- ): MetadataEscaped {
38
- return new MetadataEscaped(props);
39
- }
40
-
41
- public getName(): string {
42
- return this.returns.getName();
43
- }
44
-
45
- public toJSON(): IMetadataEscaped {
46
- return {
47
- original: this.original.toJSON(),
48
- returns: this.returns.toJSON(),
49
- };
50
- }
51
- }
1
+ import { ClassProperties } from "../../typings/ClassProperties";
2
+
3
+ import { IMetadataDictionary } from "./IMetadataDictionary";
4
+ import { IMetadataEscaped } from "./IMetadataEscaped";
5
+ import { Metadata } from "./Metadata";
6
+
7
+ export class MetadataEscaped {
8
+ public readonly original: Metadata;
9
+ public readonly returns: Metadata;
10
+
11
+ /**
12
+ * @hidden
13
+ */
14
+ private constructor(props: ClassProperties<MetadataEscaped>) {
15
+ this.original = props.original;
16
+ this.returns = props.returns;
17
+ }
18
+
19
+ /**
20
+ * @internal
21
+ */
22
+ public static _From(
23
+ props: IMetadataEscaped,
24
+ dict: IMetadataDictionary,
25
+ ): MetadataEscaped {
26
+ return this.create({
27
+ original: Metadata._From(props.original, dict),
28
+ returns: Metadata._From(props.returns, dict),
29
+ });
30
+ }
31
+
32
+ /**
33
+ * @internal
34
+ */
35
+ public static create(
36
+ props: ClassProperties<MetadataEscaped>,
37
+ ): MetadataEscaped {
38
+ return new MetadataEscaped(props);
39
+ }
40
+
41
+ public getName(): string {
42
+ return this.returns.getName();
43
+ }
44
+
45
+ public toJSON(): IMetadataEscaped {
46
+ return {
47
+ original: this.original.toJSON(),
48
+ returns: this.returns.toJSON(),
49
+ };
50
+ }
51
+ }
@@ -0,0 +1,8 @@
1
+ export type ExclusiveMaximum<Fixed extends number | bigint> = {
2
+ "typia.tag"?: {
3
+ target: Fixed extends number ? "number" : "bigint";
4
+ kind: "exclusiveMaximum";
5
+ value: Fixed;
6
+ validate?: `$input < ${Fixed}`;
7
+ };
8
+ };
@@ -0,0 +1,8 @@
1
+ export type ExclusiveMinimum<Fixed extends number | bigint> = {
2
+ "typia.tag"?: {
3
+ target: Fixed extends number ? "number" : "bigint";
4
+ kind: "exclusiveMinimum";
5
+ value: Fixed;
6
+ validate?: `${Fixed} < $input`;
7
+ };
8
+ };
@@ -0,0 +1,29 @@
1
+ export type Format<
2
+ Value extends
3
+ | "email"
4
+ | "uuid"
5
+ | "ipv4"
6
+ | "ipv6"
7
+ | "url"
8
+ | "date"
9
+ | "date-time",
10
+ > = {
11
+ "typia.tag"?: {
12
+ target: "string";
13
+ kind: "format";
14
+ value: Value;
15
+ validate: Value extends "email"
16
+ ? `/^(([^<>()[\]\.,;:\s@\"]+(\.[^<>()[\]\.,;:\s@\"]+)*)|(\".+\"))@(([^<>()[\]\.,;:\s@\"]+\.)+[^<>()[\]\.,;:\s@\"]{2,})$/i.test($input)`
17
+ : Value extends "uuid"
18
+ ? `/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i.test($input)`
19
+ : Value extends "ipv4"
20
+ ? `/^(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/.test($input)`
21
+ : Value extends "ipv6"
22
+ ? `/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/.test($input)`
23
+ : Value extends "url"
24
+ ? `/^[a-zA-Z0-9]+:\/\/(?:www.)?[-a-zA-Z0-9@:%._+~#=]{1,256}.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_+.~#?&/=]*)$/.test($input)`
25
+ : Value extends "date"
26
+ ? `/^(\d{4})-(\d{2})-(\d{2})$/.test($input)`
27
+ : `!isNaN(new Date($input).getTime())`;
28
+ };
29
+ };
@@ -0,0 +1,8 @@
1
+ export type MaxItems<Size extends number> = {
2
+ "typia.tag"?: {
3
+ targeet: "array";
4
+ kind: "maxItems";
5
+ value: Size;
6
+ validate: `$input.length <= ${Size}`;
7
+ };
8
+ };
@@ -0,0 +1,8 @@
1
+ export type MaxLength<Fixed extends number> = {
2
+ "typia.tag"?: {
3
+ target: "array";
4
+ kind: "maxLength";
5
+ value: number;
6
+ validate: `$input.length <= ${Fixed}`;
7
+ };
8
+ };
@@ -0,0 +1,8 @@
1
+ export type Maximum<Fixed extends number | bigint> = {
2
+ "typia.tag"?: {
3
+ target: Fixed extends number ? "number" : "bigint";
4
+ kind: "maximum";
5
+ value: Fixed;
6
+ validate: `$input <= ${Fixed}`;
7
+ };
8
+ };
@@ -0,0 +1,8 @@
1
+ export type MinItems<Size extends number> = {
2
+ "typia.tag"?: {
3
+ targeet: "array";
4
+ kind: "minItems";
5
+ value: Size;
6
+ validate: `${Size} <= $input.length`;
7
+ };
8
+ };
@@ -0,0 +1,8 @@
1
+ export type MinLength<Fixed extends number> = {
2
+ "typia.tag"?: {
3
+ target: "array";
4
+ kind: "minLength";
5
+ value: number;
6
+ validate: `${Fixed} <= $input.length`;
7
+ };
8
+ };
@@ -0,0 +1,8 @@
1
+ export type Minimum<Fixed extends number | bigint> = {
2
+ "typia.tag"?: {
3
+ target: Fixed extends number ? "number" : "bigint";
4
+ kind: "minimum";
5
+ value: Fixed;
6
+ validate?: `${Fixed} <= $input`;
7
+ };
8
+ };
@@ -0,0 +1,10 @@
1
+ export type MultipleOf<Fixed extends number | bigint> = {
2
+ "typia.tag"?: {
3
+ target: Fixed extends bigint ? "bigint" : "number";
4
+ kind: "multipleOf";
5
+ value: Fixed;
6
+ validate: `$input % ${Fixed} === ${Fixed extends bigint
7
+ ? "bigint"
8
+ : "number"}`;
9
+ };
10
+ };
@@ -0,0 +1,8 @@
1
+ export type Pattern<Value extends string> = {
2
+ "typia.tag"?: {
3
+ target: "string";
4
+ kind: "pattern";
5
+ value: Value;
6
+ validate: `RegExp(/${Value}/).test($input)`;
7
+ };
8
+ };
@@ -0,0 +1,17 @@
1
+ export type TagBase<
2
+ Target extends "bigint" | "number" | "string" | "array",
3
+ Kind extends string,
4
+ Value,
5
+ Validate extends
6
+ | string
7
+ | {
8
+ [key in Target]?: string;
9
+ },
10
+ > = {
11
+ "typia.tag"?: {
12
+ target: Target;
13
+ kind: Kind;
14
+ value: Value;
15
+ validate: Validate;
16
+ };
17
+ };
@@ -0,0 +1,30 @@
1
+ export type Type<
2
+ Target extends
3
+ | "int"
4
+ | "uint"
5
+ | "int32"
6
+ | "uint32"
7
+ | "int64"
8
+ | "uint64"
9
+ | "float",
10
+ > = {
11
+ "typia.tag"?: {
12
+ target: Target extends "uint64" ? "bigint" : "number" | "bigint";
13
+ kind: "type";
14
+ value: Target;
15
+ validate: Target extends "int" | "int32"
16
+ ? `Number.isInteger($input) && -2147483648 <= $input && $input <= 2147483647`
17
+ : Target extends "uint" | "uint32"
18
+ ? `Number.isInteger($input) && 0 <= $input && $input <= 4294967295`
19
+ : Target extends "int64"
20
+ ? {
21
+ number: `Number.isInteger($input) && -9223372036854775808 <= $input && $input <= 9223372036854775807`;
22
+ }
23
+ : Target extends "uint64"
24
+ ? {
25
+ number: `Number.isInteger($input) && 0 <= $input && $input <= 18446744073709551615`;
26
+ bigint: `BigInt(0) <= $input && $input <= BigInt(18446744073709551615)`;
27
+ }
28
+ : `-1.175494351e38 <= $input <= 3.4028235e38`;
29
+ };
30
+ };
@@ -0,0 +1,12 @@
1
+ export * from "./ExclusiveMaximum";
2
+ export * from "./ExclusiveMinimum";
3
+ export * from "./Format";
4
+ export * from "./Maximum";
5
+ export * from "./MaxItems";
6
+ export * from "./MaxLength";
7
+ export * from "./Minimum";
8
+ export * from "./MinItems";
9
+ export * from "./MinLength";
10
+ export * from "./Pattern";
11
+ export * from "./TagBase";
12
+ export * from "./Type";
@@ -1,111 +1,111 @@
1
- import ts from "typescript";
2
-
3
- import { LiteralFactory } from "../../../factories/LiteralFactory";
4
- import { MetadataCollection } from "../../../factories/MetadataCollection";
5
- import { MetadataFactory } from "../../../factories/MetadataFactory";
6
-
7
- import { IJsonApplication } from "../../../schemas/json/IJsonApplication";
8
- import { Metadata } from "../../../schemas/metadata/Metadata";
9
-
10
- import { JsonApplicationProgrammer } from "../../../programmers/json/JsonApplicationProgrammer";
11
-
12
- import { IProject } from "../../IProject";
13
-
14
- export namespace JsonApplicationTransformer {
15
- export const transform =
16
- ({ checker }: IProject) =>
17
- (expression: ts.CallExpression): ts.Expression => {
18
- if (!expression.typeArguments?.length)
19
- throw new Error(NO_GENERIC_ARGUMENT);
20
-
21
- //----
22
- // GET ARGUMENTS
23
- //----
24
- // VALIDATE TUPLE ARGUMENTS
25
- const top: ts.Node = expression.typeArguments[0]!;
26
- if (!ts.isTupleTypeNode(top)) return expression;
27
- else if (top.elements.some((child) => !ts.isTypeNode(child)))
28
- return expression;
29
-
30
- // GET TYPES
31
- const types: ts.Type[] = top.elements.map((child) =>
32
- checker.getTypeFromTypeNode(child as ts.TypeNode),
33
- );
34
- if (types.some((t) => t.isTypeParameter()))
35
- throw new Error(GENERIC_ARGUMENT);
36
-
37
- // ADDITIONAL PARAMETERS
38
- const purpose: "swagger" | "ajv" = get_parameter(
39
- checker,
40
- "Purpose",
41
- expression.typeArguments[1],
42
- (str) => str === "swagger" || str === "ajv",
43
- () => "swagger",
44
- );
45
-
46
- //----
47
- // GENERATORS
48
- //----
49
- // METADATA
50
- const collection: MetadataCollection = new MetadataCollection();
51
- const metadatas: Array<Metadata> = types.map((type) =>
52
- MetadataFactory.analyze(checker)({
53
- escape: true,
54
- constant: true,
55
- absorb: false,
56
- validate: (meta) => {
57
- if (meta.atomics.find((str) => str === "bigint"))
58
- throw new Error(NO_BIGIT);
59
- else if (
60
- meta.arrays.some(
61
- (array) => array.value.isRequired() === false,
62
- )
63
- )
64
- throw new Error(NO_UNDEFINED_IN_ARRAY);
65
- },
66
- })(collection)(type),
67
- );
68
-
69
- // APPLICATION
70
- const app: IJsonApplication = JsonApplicationProgrammer.write({
71
- purpose,
72
- })(metadatas);
73
-
74
- // RETURNS WITH LITERAL EXPRESSION
75
- return LiteralFactory.generate(app);
76
- };
77
-
78
- const get_parameter = <T extends string>(
79
- checker: ts.TypeChecker,
80
- name: string,
81
- node: ts.TypeNode | undefined,
82
- predicator: (value: string) => boolean,
83
- defaulter: () => T,
84
- ): T => {
85
- if (!node) return defaulter();
86
-
87
- // CHECK LITERAL TYPE
88
- const type: ts.Type = checker.getTypeFromTypeNode(node);
89
- if (!type.isLiteral())
90
- throw new Error(
91
- `Error on typia.application(): generic argument "${name}" must be constant.`,
92
- );
93
-
94
- // GET VALUE AND VALIDATE IT
95
- const value = type.value;
96
- if (typeof value !== "string" || predicator(value) === false)
97
- throw new Error(
98
- `Error on typia.application(): invalid value on generic argument "${name}".`,
99
- );
100
- return value as T;
101
- };
102
- }
103
-
104
- const NO_GENERIC_ARGUMENT =
105
- "Error on typia.json.application(): no generic argument.";
106
- const GENERIC_ARGUMENT =
107
- "Error on typia.json.application(): non-specified generic argument(s).";
108
- const NO_BIGIT =
109
- "Error on typia.json.application(): does not allow bigint type.";
110
- const NO_UNDEFINED_IN_ARRAY =
111
- "Error on typia.json.application(): does not allow undefined type in array.";
1
+ import ts from "typescript";
2
+
3
+ import { LiteralFactory } from "../../../factories/LiteralFactory";
4
+ import { MetadataCollection } from "../../../factories/MetadataCollection";
5
+ import { MetadataFactory } from "../../../factories/MetadataFactory";
6
+
7
+ import { IJsonApplication } from "../../../schemas/json/IJsonApplication";
8
+ import { Metadata } from "../../../schemas/metadata/Metadata";
9
+
10
+ import { JsonApplicationProgrammer } from "../../../programmers/json/JsonApplicationProgrammer";
11
+
12
+ import { IProject } from "../../IProject";
13
+
14
+ export namespace JsonApplicationTransformer {
15
+ export const transform =
16
+ ({ checker }: IProject) =>
17
+ (expression: ts.CallExpression): ts.Expression => {
18
+ if (!expression.typeArguments?.length)
19
+ throw new Error(NO_GENERIC_ARGUMENT);
20
+
21
+ //----
22
+ // GET ARGUMENTS
23
+ //----
24
+ // VALIDATE TUPLE ARGUMENTS
25
+ const top: ts.Node = expression.typeArguments[0]!;
26
+ if (!ts.isTupleTypeNode(top)) return expression;
27
+ else if (top.elements.some((child) => !ts.isTypeNode(child)))
28
+ return expression;
29
+
30
+ // GET TYPES
31
+ const types: ts.Type[] = top.elements.map((child) =>
32
+ checker.getTypeFromTypeNode(child as ts.TypeNode),
33
+ );
34
+ if (types.some((t) => t.isTypeParameter()))
35
+ throw new Error(GENERIC_ARGUMENT);
36
+
37
+ // ADDITIONAL PARAMETERS
38
+ const purpose: "swagger" | "ajv" = get_parameter(
39
+ checker,
40
+ "Purpose",
41
+ expression.typeArguments[1],
42
+ (str) => str === "swagger" || str === "ajv",
43
+ () => "swagger",
44
+ );
45
+
46
+ //----
47
+ // GENERATORS
48
+ //----
49
+ // METADATA
50
+ const collection: MetadataCollection = new MetadataCollection();
51
+ const metadatas: Array<Metadata> = types.map((type) =>
52
+ MetadataFactory.analyze(checker)({
53
+ escape: true,
54
+ constant: true,
55
+ absorb: false,
56
+ validate: (meta) => {
57
+ if (meta.atomics.find((atom) => atom.type === "bigint"))
58
+ throw new Error(NO_BIGIT);
59
+ else if (
60
+ meta.arrays.some(
61
+ (array) => array.value.isRequired() === false,
62
+ )
63
+ )
64
+ throw new Error(NO_UNDEFINED_IN_ARRAY);
65
+ },
66
+ })(collection)(type),
67
+ );
68
+
69
+ // APPLICATION
70
+ const app: IJsonApplication = JsonApplicationProgrammer.write({
71
+ purpose,
72
+ })(metadatas);
73
+
74
+ // RETURNS WITH LITERAL EXPRESSION
75
+ return LiteralFactory.generate(app);
76
+ };
77
+
78
+ const get_parameter = <T extends string>(
79
+ checker: ts.TypeChecker,
80
+ name: string,
81
+ node: ts.TypeNode | undefined,
82
+ predicator: (value: string) => boolean,
83
+ defaulter: () => T,
84
+ ): T => {
85
+ if (!node) return defaulter();
86
+
87
+ // CHECK LITERAL TYPE
88
+ const type: ts.Type = checker.getTypeFromTypeNode(node);
89
+ if (!type.isLiteral())
90
+ throw new Error(
91
+ `Error on typia.application(): generic argument "${name}" must be constant.`,
92
+ );
93
+
94
+ // GET VALUE AND VALIDATE IT
95
+ const value = type.value;
96
+ if (typeof value !== "string" || predicator(value) === false)
97
+ throw new Error(
98
+ `Error on typia.application(): invalid value on generic argument "${name}".`,
99
+ );
100
+ return value as T;
101
+ };
102
+ }
103
+
104
+ const NO_GENERIC_ARGUMENT =
105
+ "Error on typia.json.application(): no generic argument.";
106
+ const GENERIC_ARGUMENT =
107
+ "Error on typia.json.application(): non-specified generic argument(s).";
108
+ const NO_BIGIT =
109
+ "Error on typia.json.application(): does not allow bigint type.";
110
+ const NO_UNDEFINED_IN_ARRAY =
111
+ "Error on typia.json.application(): does not allow undefined type in array.";
@@ -1,53 +1,53 @@
1
- import ts from "typescript";
2
-
3
- import { LiteralFactory } from "../../../factories/LiteralFactory";
4
- import { MetadataCollection } from "../../../factories/MetadataCollection";
5
- import { MetadataFactory } from "../../../factories/MetadataFactory";
6
-
7
- import { IMetadataApplication } from "../../../schemas/metadata/IMetadataApplication";
8
- import { Metadata } from "../../../schemas/metadata/Metadata";
9
-
10
- import { IProject } from "../../IProject";
11
-
12
- export namespace MetadataTransformer {
13
- export const transform =
14
- ({ checker }: IProject) =>
15
- (expression: ts.CallExpression): ts.Expression => {
16
- if (!expression.typeArguments?.length)
17
- throw new Error(NO_GENERIC_ARGUMENT);
18
-
19
- // VALIDATE TUPLE ARGUMENTS
20
- const top: ts.Node = expression.typeArguments[0]!;
21
- if (!ts.isTupleTypeNode(top)) return expression;
22
- else if (top.elements.some((child) => !ts.isTypeNode(child)))
23
- return expression;
24
-
25
- // GET TYPES
26
- const types: ts.Type[] = top.elements.map((child) =>
27
- checker.getTypeFromTypeNode(child as ts.TypeNode),
28
- );
29
- if (types.some((t) => t.isTypeParameter()))
30
- throw new Error(GENERIC_ARGUMENT);
31
-
32
- // METADATA
33
- const collection: MetadataCollection = new MetadataCollection();
34
- const metadatas: Array<Metadata> = types.map((type) =>
35
- MetadataFactory.analyze(checker)({
36
- escape: true,
37
- constant: true,
38
- absorb: true,
39
- })(collection)(type),
40
- );
41
-
42
- // CONVERT TO PRIMITIVE TYPE
43
- const app: IMetadataApplication = {
44
- metadatas: metadatas.map((metadata) => metadata.toJSON()),
45
- collection: collection.toJSON(),
46
- };
47
- return LiteralFactory.generate(app);
48
- };
49
- }
50
-
51
- const NO_GENERIC_ARGUMENT = "Error on typia.metadata(): no generic argument.";
52
- const GENERIC_ARGUMENT =
53
- "Error on typia.metadata(): non-specified generic argument(s).";
1
+ import ts from "typescript";
2
+
3
+ import { LiteralFactory } from "../../../factories/LiteralFactory";
4
+ import { MetadataCollection } from "../../../factories/MetadataCollection";
5
+ import { MetadataFactory } from "../../../factories/MetadataFactory";
6
+
7
+ import { IMetadataApplication } from "../../../schemas/metadata/IMetadataApplication";
8
+ import { Metadata } from "../../../schemas/metadata/Metadata";
9
+
10
+ import { IProject } from "../../IProject";
11
+
12
+ export namespace MetadataTransformer {
13
+ export const transform =
14
+ ({ checker }: IProject) =>
15
+ (expression: ts.CallExpression): ts.Expression => {
16
+ if (!expression.typeArguments?.length)
17
+ throw new Error(NO_GENERIC_ARGUMENT);
18
+
19
+ // VALIDATE TUPLE ARGUMENTS
20
+ const top: ts.Node = expression.typeArguments[0]!;
21
+ if (!ts.isTupleTypeNode(top)) return expression;
22
+ else if (top.elements.some((child) => !ts.isTypeNode(child)))
23
+ return expression;
24
+
25
+ // GET TYPES
26
+ const types: ts.Type[] = top.elements.map((child) =>
27
+ checker.getTypeFromTypeNode(child as ts.TypeNode),
28
+ );
29
+ if (types.some((t) => t.isTypeParameter()))
30
+ throw new Error(GENERIC_ARGUMENT);
31
+
32
+ // METADATA
33
+ const collection: MetadataCollection = new MetadataCollection();
34
+ const metadatas: Array<Metadata> = types.map((type) =>
35
+ MetadataFactory.analyze(checker)({
36
+ escape: true,
37
+ constant: true,
38
+ absorb: true,
39
+ })(collection)(type),
40
+ );
41
+
42
+ // CONVERT TO PRIMITIVE TYPE
43
+ const app: IMetadataApplication = {
44
+ metadatas: metadatas.map((metadata) => metadata.toJSON()),
45
+ collection: collection.toJSON(),
46
+ };
47
+ return LiteralFactory.generate(app);
48
+ };
49
+ }
50
+
51
+ const NO_GENERIC_ARGUMENT = "Error on typia.metadata(): no generic argument.";
52
+ const GENERIC_ARGUMENT =
53
+ "Error on typia.metadata(): non-specified generic argument(s).";