typia 3.4.15 → 3.5.0-dev.20221222

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 (169) hide show
  1. package/README.md +48 -7
  2. package/lib/factories/MetadataCollection.d.ts +1 -9
  3. package/lib/factories/MetadataCollection.js +2 -75
  4. package/lib/factories/MetadataCollection.js.map +1 -1
  5. package/lib/factories/ProtocolFactory.d.ts +8 -0
  6. package/lib/factories/ProtocolFactory.js +119 -0
  7. package/lib/factories/ProtocolFactory.js.map +1 -0
  8. package/lib/factories/internal/protocols/ProtocolMetadataUtil.d.ts +11 -0
  9. package/lib/factories/internal/protocols/ProtocolMetadataUtil.js +76 -0
  10. package/lib/factories/internal/protocols/ProtocolMetadataUtil.js.map +1 -0
  11. package/lib/factories/internal/protocols/emplace_protocol_object.d.ts +3 -0
  12. package/lib/factories/internal/protocols/emplace_protocol_object.js +47 -0
  13. package/lib/factories/internal/protocols/emplace_protocol_object.js.map +1 -0
  14. package/lib/factories/internal/protocols/emplace_protocol_property.d.ts +4 -0
  15. package/lib/factories/internal/protocols/emplace_protocol_property.js +20 -0
  16. package/lib/factories/internal/protocols/emplace_protocol_property.js.map +1 -0
  17. package/lib/factories/internal/protocols/iterate_protocol_atomic.d.ts +3 -0
  18. package/lib/factories/internal/protocols/iterate_protocol_atomic.js +69 -0
  19. package/lib/factories/internal/protocols/iterate_protocol_atomic.js.map +1 -0
  20. package/lib/factories/internal/protocols/iterate_protocol_constant.d.ts +2 -0
  21. package/lib/factories/internal/protocols/iterate_protocol_constant.js +30 -0
  22. package/lib/factories/internal/protocols/iterate_protocol_constant.js.map +1 -0
  23. package/lib/factories/internal/protocols/iterate_protocol_main.d.ts +3 -0
  24. package/lib/factories/internal/protocols/iterate_protocol_main.js +17 -0
  25. package/lib/factories/internal/protocols/iterate_protocol_main.js.map +1 -0
  26. package/lib/factories/internal/protocols/iterate_protocol_map.d.ts +3 -0
  27. package/lib/factories/internal/protocols/iterate_protocol_map.js +71 -0
  28. package/lib/factories/internal/protocols/iterate_protocol_map.js.map +1 -0
  29. package/lib/factories/internal/protocols/iterate_protocol_metadata.d.ts +5 -0
  30. package/lib/factories/internal/protocols/iterate_protocol_metadata.js +192 -0
  31. package/lib/factories/internal/protocols/iterate_protocol_metadata.js.map +1 -0
  32. package/lib/factories/internal/protocols/iterate_protocol_native.d.ts +2 -0
  33. package/lib/factories/internal/protocols/iterate_protocol_native.js +33 -0
  34. package/lib/factories/internal/protocols/iterate_protocol_native.js.map +1 -0
  35. package/lib/factories/internal/protocols/iterate_protocol_repeated.d.ts +4 -0
  36. package/lib/factories/internal/protocols/iterate_protocol_repeated.js +24 -0
  37. package/lib/factories/internal/protocols/iterate_protocol_repeated.js.map +1 -0
  38. package/lib/factories/internal/protocols/iterate_protocol_tuple.d.ts +3 -0
  39. package/lib/factories/internal/protocols/iterate_protocol_tuple.js +46 -0
  40. package/lib/factories/internal/protocols/iterate_protocol_tuple.js.map +1 -0
  41. package/lib/functional/$proto_bytes.d.ts +2 -0
  42. package/lib/functional/$proto_bytes.js +37 -0
  43. package/lib/functional/$proto_bytes.js.map +1 -0
  44. package/lib/functional/$proto_field.d.ts +10 -0
  45. package/lib/functional/$proto_field.js +42 -0
  46. package/lib/functional/$proto_field.js.map +1 -0
  47. package/lib/functional/$proto_float.d.ts +4 -0
  48. package/lib/functional/$proto_float.js +28 -0
  49. package/lib/functional/$proto_float.js.map +1 -0
  50. package/lib/functional/$proto_i32.d.ts +2 -0
  51. package/lib/functional/$proto_i32.js +23 -0
  52. package/lib/functional/$proto_i32.js.map +1 -0
  53. package/lib/functional/$proto_i64.d.ts +2 -0
  54. package/lib/functional/$proto_i64.js +31 -0
  55. package/lib/functional/$proto_i64.js.map +1 -0
  56. package/lib/functional/$proto_size.d.ts +6 -0
  57. package/lib/functional/$proto_size.js +76 -0
  58. package/lib/functional/$proto_size.js.map +1 -0
  59. package/lib/functional/$proto_string.d.ts +2 -0
  60. package/lib/functional/$proto_string.js +34 -0
  61. package/lib/functional/$proto_string.js.map +1 -0
  62. package/lib/functional/$varint.d.ts +6 -0
  63. package/lib/functional/$varint.js +99 -0
  64. package/lib/functional/$varint.js.map +1 -0
  65. package/lib/functional/$zigzag.d.ts +4 -0
  66. package/lib/functional/$zigzag.js +34 -0
  67. package/lib/functional/$zigzag.js.map +1 -0
  68. package/lib/messages/IProtocolMessage.d.ts +5 -0
  69. package/lib/messages/IProtocolMessage.js +3 -0
  70. package/lib/messages/IProtocolMessage.js.map +1 -0
  71. package/lib/messages/IProtocolProperty.d.ts +11 -0
  72. package/lib/messages/IProtocolProperty.js +3 -0
  73. package/lib/messages/IProtocolProperty.js.map +1 -0
  74. package/lib/metadata/IMetadataTag.d.ts +7 -3
  75. package/lib/metadata/Metadata.js +1 -1
  76. package/lib/metadata/Metadata.js.map +1 -1
  77. package/lib/module.d.ts +2 -0
  78. package/lib/module.js +5 -1
  79. package/lib/module.js.map +1 -1
  80. package/lib/programmers/MessageProgrammer.d.ts +5 -0
  81. package/lib/programmers/MessageProgrammer.js +134 -0
  82. package/lib/programmers/MessageProgrammer.js.map +1 -0
  83. package/lib/programmers/internal/application_object.js +9 -9
  84. package/lib/programmers/internal/application_object.js.map +1 -1
  85. package/lib/programmers/internal/application_schema.js +5 -3
  86. package/lib/programmers/internal/application_schema.js.map +1 -1
  87. package/lib/transformers/CallExpressionTransformer.js +3 -1
  88. package/lib/transformers/CallExpressionTransformer.js.map +1 -1
  89. package/lib/transformers/features/miscellaneous/ApplicationTransformer.js +1 -3
  90. package/lib/transformers/features/miscellaneous/ApplicationTransformer.js.map +1 -1
  91. package/lib/transformers/features/protocols/MessageTransformer.d.ts +5 -0
  92. package/lib/transformers/features/protocols/MessageTransformer.js +17 -0
  93. package/lib/transformers/features/protocols/MessageTransformer.js.map +1 -0
  94. package/lib/utils/NameEncoder.d.ts +4 -0
  95. package/lib/utils/NameEncoder.js +89 -0
  96. package/lib/utils/NameEncoder.js.map +1 -0
  97. package/package.json +2 -3
  98. package/src/executable/internal/TypiaSetupWizard.ts +173 -173
  99. package/src/factories/MetadataCollection.ts +83 -122
  100. package/src/factories/MetadataFactory.ts +47 -47
  101. package/src/factories/MetadataTagFactory.ts +351 -351
  102. package/src/factories/ProtocolFactory.ts +92 -0
  103. package/src/factories/internal/metadata/MetadataHelper.ts +12 -12
  104. package/src/factories/internal/metadata/emplace_metadata_object.ts +140 -140
  105. package/src/factories/internal/metadata/explore_metadata.ts +92 -92
  106. package/src/factories/internal/metadata/iterate_metadata.ts +80 -80
  107. package/src/factories/internal/metadata/iterate_metadata_array.ts +29 -29
  108. package/src/factories/internal/metadata/iterate_metadata_atomic.ts +59 -59
  109. package/src/factories/internal/metadata/iterate_metadata_coalesce.ts +33 -33
  110. package/src/factories/internal/metadata/iterate_metadata_constant.ts +58 -58
  111. package/src/factories/internal/metadata/iterate_metadata_map.ts +41 -41
  112. package/src/factories/internal/metadata/iterate_metadata_native.ts +227 -227
  113. package/src/factories/internal/metadata/iterate_metadata_object.ts +48 -48
  114. package/src/factories/internal/metadata/iterate_metadata_resolve.ts +27 -27
  115. package/src/factories/internal/metadata/iterate_metadata_set.ts +33 -33
  116. package/src/factories/internal/metadata/iterate_metadata_template.ts +38 -38
  117. package/src/factories/internal/metadata/iterate_metadata_tuple.ts +45 -45
  118. package/src/factories/internal/metadata/iterate_metadata_union.ts +59 -59
  119. package/src/factories/internal/protocols/ProtocolMetadataUtil.ts +81 -0
  120. package/src/factories/internal/protocols/emplace_protocol_object.ts +25 -0
  121. package/src/factories/internal/protocols/emplace_protocol_property.ts +12 -0
  122. package/src/factories/internal/protocols/iterate_protocol_atomic.ts +34 -0
  123. package/src/factories/internal/protocols/iterate_protocol_constant.ts +27 -0
  124. package/src/factories/internal/protocols/iterate_protocol_main.ts +19 -0
  125. package/src/factories/internal/protocols/iterate_protocol_map.ts +38 -0
  126. package/src/factories/internal/protocols/iterate_protocol_metadata.ts +76 -0
  127. package/src/factories/internal/protocols/iterate_protocol_native.ts +34 -0
  128. package/src/factories/internal/protocols/iterate_protocol_repeated.ts +25 -0
  129. package/src/factories/internal/protocols/iterate_protocol_tuple.ts +25 -0
  130. package/src/functional/$number.ts +12 -12
  131. package/src/functional/$proto_bytes.ts +25 -0
  132. package/src/functional/$proto_field.ts +30 -0
  133. package/src/functional/$proto_float.ts +37 -0
  134. package/src/functional/$proto_i32.ts +29 -0
  135. package/src/functional/$proto_i64.ts +37 -0
  136. package/src/functional/$proto_size.ts +82 -0
  137. package/src/functional/$proto_string.ts +24 -0
  138. package/src/functional/$varint.ts +130 -0
  139. package/src/functional/$zigzag.ts +39 -0
  140. package/src/messages/IProtocolMessage.ts +6 -0
  141. package/src/messages/IProtocolProperty.ts +11 -0
  142. package/src/metadata/IMetadataTag.ts +137 -122
  143. package/src/metadata/Metadata.ts +479 -477
  144. package/src/module.ts +1547 -1535
  145. package/src/programmers/AssertParseProgrammer.ts +55 -55
  146. package/src/programmers/AssertProgrammer.ts +445 -445
  147. package/src/programmers/AssertStringifyProgrammer.ts +65 -65
  148. package/src/programmers/CheckerProgrammer.ts +810 -810
  149. package/src/programmers/IsParseProgrammer.ts +61 -61
  150. package/src/programmers/IsProgrammer.ts +175 -175
  151. package/src/programmers/IsStringifyProgrammer.ts +69 -69
  152. package/src/programmers/MessageProgrammer.ts +116 -0
  153. package/src/programmers/StringifyProgrammer.ts +762 -762
  154. package/src/programmers/ValidateParseProgrammer.ts +59 -59
  155. package/src/programmers/ValidateProgrammer.ts +237 -237
  156. package/src/programmers/ValidateStringifyProgrammer.ts +80 -80
  157. package/src/programmers/helpers/OptionPredicator.ts +15 -15
  158. package/src/programmers/internal/application_default.ts +17 -17
  159. package/src/programmers/internal/application_object.ts +5 -5
  160. package/src/programmers/internal/application_schema.ts +231 -228
  161. package/src/programmers/internal/check_bigint.ts +85 -85
  162. package/src/programmers/internal/check_number.ts +175 -175
  163. package/src/schemas/IJsonSchema.ts +90 -90
  164. package/src/transformers/CallExpressionTransformer.ts +131 -124
  165. package/src/transformers/ITransformOptions.ts +47 -47
  166. package/src/transformers/features/miscellaneous/ApplicationTransformer.ts +117 -119
  167. package/src/transformers/features/protocols/MessageTransformer.ts +32 -0
  168. package/src/transformers/features/stringifiers/StringifyTransformer.ts +46 -46
  169. package/src/utils/NameEncoder.ts +32 -0
@@ -1,124 +1,131 @@
1
- import path from "path";
2
- import ts from "typescript";
3
-
4
- import { IProject } from "./IProject";
5
- import { ApplicationTransformer } from "./features/miscellaneous/ApplicationTransformer";
6
- import { MetadataTransformer } from "./features/miscellaneous/MetadataTransformer";
7
- import { AssertParseTransformer } from "./features/parsers/AssertParseTransformer";
8
- import { CreateAssertParseTransformer } from "./features/parsers/CreateAssertParseTransformer";
9
- import { CreateIsParseTransformer } from "./features/parsers/CreateIsParseTransformer";
10
- import { CreateValidateParseTransformer } from "./features/parsers/CreateValidateParseTransformer";
11
- import { IsParseTransformer } from "./features/parsers/IsParseTransformer";
12
- import { ValidateParseTransformer } from "./features/parsers/ValidateParseTransformer";
13
- import { AssertStringifyTransformer } from "./features/stringifiers/AssertStringifyTransformer";
14
- import { CreateAssertStringifyTransformer } from "./features/stringifiers/CreateAssertStringifyTransformer";
15
- import { CreateIsStringifyTransformer } from "./features/stringifiers/CreateIsStringifyTransformer";
16
- import { CreateStringifyTransformer } from "./features/stringifiers/CreateStringifyTransformer";
17
- import { CreateValidateStringifyTransformer } from "./features/stringifiers/CreateValidateStringifyProgrammer";
18
- import { IsStringifyTransformer } from "./features/stringifiers/IsStringifyTransformer";
19
- import { StringifyTransformer } from "./features/stringifiers/StringifyTransformer";
20
- import { ValidateStringifyTransformer } from "./features/stringifiers/ValidateStringifyTransformer";
21
- import { AssertTransformer } from "./features/validators/AssertTransformer";
22
- import { CreateAssertTransformer } from "./features/validators/CreateAssertTransformer";
23
- import { CreateIsTransformer } from "./features/validators/CreateIsTransformer";
24
- import { CreateValidateTransformer } from "./features/validators/CreateValidateTransformer";
25
- import { IsTransformer } from "./features/validators/IsTransformer";
26
- import { ValidateTransformer } from "./features/validators/ValidateTransformer";
27
-
28
- export namespace CallExpressionTransformer {
29
- export function transform(
30
- project: IProject,
31
- expression: ts.CallExpression,
32
- ): ts.Expression {
33
- //----
34
- // VALIDATIONS
35
- //----
36
- // SIGNATURE DECLARATION
37
- const declaration: ts.Declaration | undefined =
38
- project.checker.getResolvedSignature(expression)?.declaration;
39
- if (!declaration) return expression;
40
-
41
- // FILE PATH
42
- const file: string = path.resolve(declaration.getSourceFile().fileName);
43
- if (file.indexOf(LIB_PATH) === -1 && file !== SRC_PATH)
44
- return expression;
45
-
46
- //----
47
- // TRANSFORMATION
48
- //----
49
- // FUNCTION NAME
50
- const { name } = project.checker.getTypeAtLocation(declaration).symbol;
51
-
52
- // FIND TRANSFORMER
53
- const functor: (() => Task) | undefined = FUNCTORS[name];
54
- if (functor === undefined) return expression;
55
-
56
- // RETURNS WITH TRANSFORMATION
57
- return functor()(project, expression.expression, expression);
58
- }
59
- }
60
-
61
- type Task = (
62
- project: IProject,
63
- modulo: ts.LeftHandSideExpression,
64
- expression: ts.CallExpression,
65
- ) => ts.Expression;
66
-
67
- const LIB_PATH = path.join("node_modules", "typia", "lib", "module.d.ts");
68
- const SRC_PATH = path.resolve(path.join(__dirname, "..", "module.ts"));
69
-
70
- const FUNCTORS: Record<string, () => Task> = {
71
- //----
72
- // SINGLE FUNCTIONS
73
- //----
74
- // BASIC VALIDATORS
75
- assert: () => AssertTransformer.transform(false),
76
- assertType: () => AssertTransformer.transform(false),
77
- is: () => IsTransformer.transform(false),
78
- validate: () => ValidateTransformer.transform(false),
79
-
80
- // STRICT VALIDATORS
81
- assertEquals: () => AssertTransformer.transform(true),
82
- equals: () => IsTransformer.transform(true),
83
- validateEquals: () => ValidateTransformer.transform(true),
84
-
85
- // PARSE FUNCTIONS
86
- isParse: () => IsParseTransformer.transform,
87
- assertParse: () => AssertParseTransformer.transform,
88
- validateParse: () => ValidateParseTransformer.transform,
89
-
90
- // STRINGIFY FUNCTIONS
91
- stringify: () => StringifyTransformer.transform,
92
- assertStringify: () => AssertStringifyTransformer.transform,
93
- isStringify: () => IsStringifyTransformer.transform,
94
- validateStringify: () => ValidateStringifyTransformer.transform,
95
-
96
- // MISC
97
- application: () => ApplicationTransformer.transform,
98
- metadata: () => MetadataTransformer.transform,
99
-
100
- //----
101
- // FACTORY FUNCTIONS
102
- //----
103
- // BASIC VALIDATORS
104
- createAssert: () => CreateAssertTransformer.transform(false),
105
- createAssertType: () => CreateAssertTransformer.transform(false),
106
- createIs: () => CreateIsTransformer.transform(false),
107
- createValidate: () => CreateValidateTransformer.transform(false),
108
-
109
- // STRICT VALIDATORS
110
- createAssertEquals: () => CreateAssertTransformer.transform(true),
111
- createEquals: () => CreateIsTransformer.transform(true),
112
- createValidateEquals: () => CreateValidateTransformer.transform(true),
113
-
114
- // PARSE FUNCTIONS
115
- createIsParse: () => CreateIsParseTransformer.transform,
116
- createAssertParse: () => CreateAssertParseTransformer.transform,
117
- createValidateParse: () => CreateValidateParseTransformer.transform,
118
-
119
- // STRINGIFY FUNCTIONS
120
- createStringify: () => CreateStringifyTransformer.transform,
121
- createAssertStringify: () => CreateAssertStringifyTransformer.transform,
122
- createIsStringify: () => CreateIsStringifyTransformer.transform,
123
- createValidateStringify: () => CreateValidateStringifyTransformer.transform,
124
- };
1
+ import path from "path";
2
+ import ts from "typescript";
3
+
4
+ import { IProject } from "./IProject";
5
+ import { ApplicationTransformer } from "./features/miscellaneous/ApplicationTransformer";
6
+ import { MetadataTransformer } from "./features/miscellaneous/MetadataTransformer";
7
+ import { AssertParseTransformer } from "./features/parsers/AssertParseTransformer";
8
+ import { CreateAssertParseTransformer } from "./features/parsers/CreateAssertParseTransformer";
9
+ import { CreateIsParseTransformer } from "./features/parsers/CreateIsParseTransformer";
10
+ import { CreateValidateParseTransformer } from "./features/parsers/CreateValidateParseTransformer";
11
+ import { IsParseTransformer } from "./features/parsers/IsParseTransformer";
12
+ import { ValidateParseTransformer } from "./features/parsers/ValidateParseTransformer";
13
+ import { MessageTransformer } from "./features/protocols/MessageTransformer";
14
+ import { AssertStringifyTransformer } from "./features/stringifiers/AssertStringifyTransformer";
15
+ import { CreateAssertStringifyTransformer } from "./features/stringifiers/CreateAssertStringifyTransformer";
16
+ import { CreateIsStringifyTransformer } from "./features/stringifiers/CreateIsStringifyTransformer";
17
+ import { CreateStringifyTransformer } from "./features/stringifiers/CreateStringifyTransformer";
18
+ import { CreateValidateStringifyTransformer } from "./features/stringifiers/CreateValidateStringifyProgrammer";
19
+ import { IsStringifyTransformer } from "./features/stringifiers/IsStringifyTransformer";
20
+ import { StringifyTransformer } from "./features/stringifiers/StringifyTransformer";
21
+ import { ValidateStringifyTransformer } from "./features/stringifiers/ValidateStringifyTransformer";
22
+ import { AssertTransformer } from "./features/validators/AssertTransformer";
23
+ import { CreateAssertTransformer } from "./features/validators/CreateAssertTransformer";
24
+ import { CreateIsTransformer } from "./features/validators/CreateIsTransformer";
25
+ import { CreateValidateTransformer } from "./features/validators/CreateValidateTransformer";
26
+ import { IsTransformer } from "./features/validators/IsTransformer";
27
+ import { ValidateTransformer } from "./features/validators/ValidateTransformer";
28
+
29
+ export namespace CallExpressionTransformer {
30
+ export function transform(
31
+ project: IProject,
32
+ expression: ts.CallExpression,
33
+ ): ts.Expression {
34
+ //----
35
+ // VALIDATIONS
36
+ //----
37
+ // SIGNATURE DECLARATION
38
+ const declaration: ts.Declaration | undefined =
39
+ project.checker.getResolvedSignature(expression)?.declaration;
40
+ if (!declaration) return expression;
41
+
42
+ // FILE PATH
43
+ const file: string = path.resolve(declaration.getSourceFile().fileName);
44
+ if (file.indexOf(LIB_PATH) === -1 && file !== SRC_PATH)
45
+ return expression;
46
+
47
+ //----
48
+ // TRANSFORMATION
49
+ //----
50
+ // FUNCTION NAME
51
+ const { name } = project.checker.getTypeAtLocation(declaration).symbol;
52
+
53
+ // FIND TRANSFORMER
54
+ const functor: (() => Task) | undefined = FUNCTORS[name];
55
+ if (functor === undefined) return expression;
56
+
57
+ // RETURNS WITH TRANSFORMATION
58
+ return functor()(project, expression.expression, expression);
59
+ }
60
+ }
61
+
62
+ type Task = (
63
+ project: IProject,
64
+ modulo: ts.LeftHandSideExpression,
65
+ expression: ts.CallExpression,
66
+ ) => ts.Expression;
67
+
68
+ const LIB_PATH = path.join("node_modules", "typia", "lib", "module.d.ts");
69
+ const SRC_PATH = path.resolve(path.join(__dirname, "..", "module.ts"));
70
+
71
+ const FUNCTORS: Record<string, () => Task> = {
72
+ //----
73
+ // VALIDATORS
74
+ //----
75
+ // BASIC VALIDATORS
76
+ assert: () => AssertTransformer.transform(false),
77
+ assertType: () => AssertTransformer.transform(false),
78
+ is: () => IsTransformer.transform(false),
79
+ validate: () => ValidateTransformer.transform(false),
80
+
81
+ // STRICT VALIDATORS
82
+ assertEquals: () => AssertTransformer.transform(true),
83
+ equals: () => IsTransformer.transform(true),
84
+ validateEquals: () => ValidateTransformer.transform(true),
85
+
86
+ //----
87
+ // PROTOCOL BUFFER
88
+ //----
89
+ message: () => MessageTransformer.transform,
90
+
91
+ //----
92
+ // JSON FUNCTIONS
93
+ //----
94
+ // SCHEMA DEFINITION
95
+ application: () => ApplicationTransformer.transform,
96
+
97
+ // PARSER FUNCTIONS
98
+ isParse: () => IsParseTransformer.transform,
99
+ assertParse: () => AssertParseTransformer.transform,
100
+ validateParse: () => ValidateParseTransformer.transform,
101
+
102
+ // STRINGIFY FUNCTIONS
103
+ stringify: () => StringifyTransformer.transform,
104
+ assertStringify: () => AssertStringifyTransformer.transform,
105
+ isStringify: () => IsStringifyTransformer.transform,
106
+ validateStringify: () => ValidateStringifyTransformer.transform,
107
+
108
+ // MISC
109
+ metadata: () => MetadataTransformer.transform,
110
+
111
+ //----
112
+ // FACTORY FUNCTIONS
113
+ //----
114
+ // VALIDATORS
115
+ createAssert: () => CreateAssertTransformer.transform(false),
116
+ createAssertType: () => CreateAssertTransformer.transform(false),
117
+ createIs: () => CreateIsTransformer.transform(false),
118
+ createValidate: () => CreateValidateTransformer.transform(false),
119
+ createAssertEquals: () => CreateAssertTransformer.transform(true),
120
+ createEquals: () => CreateIsTransformer.transform(true),
121
+ createValidateEquals: () => CreateValidateTransformer.transform(true),
122
+
123
+ // JSON FUNCTIONS
124
+ createIsParse: () => CreateIsParseTransformer.transform,
125
+ createAssertParse: () => CreateAssertParseTransformer.transform,
126
+ createValidateParse: () => CreateValidateParseTransformer.transform,
127
+ createStringify: () => CreateStringifyTransformer.transform,
128
+ createAssertStringify: () => CreateAssertStringifyTransformer.transform,
129
+ createIsStringify: () => CreateIsStringifyTransformer.transform,
130
+ createValidateStringify: () => CreateValidateStringifyTransformer.transform,
131
+ };
@@ -1,47 +1,47 @@
1
- export interface ITransformOptions {
2
- /**
3
- * Whether to validate finite number or not.
4
- *
5
- * If configured true, number typed values would be validated by Number.isNaN().
6
- *
7
- * However, whatever you configure, it would be ignored when marshaling or parsing.
8
- *
9
- * - when marshaling, always be true
10
- * - assertStringify()
11
- * - validateEncode()
12
- * - when parsing, always be false
13
- * - assertParse()
14
- * - isDecode()
15
- *
16
- * @default false
17
- */
18
- finite?: boolean;
19
-
20
- /**
21
- * Whether to validate finite number or not.
22
- *
23
- * If configured true, number typed values would be validated by Number.isFinite().
24
- *
25
- * However, whatever you configure, it can be ignored in below case.
26
- *
27
- * - when `finite` option is true, this option would be ignored
28
- * - when marshaling, always be true
29
- * - assertStringify()
30
- * - validateEncode()
31
- * - when parsing, always be false
32
- * - assertParse()
33
- * - isDecode()
34
- *
35
- * @default false
36
- */
37
- numeric?: boolean;
38
-
39
- /**
40
- * Whether to validate functional type or not.
41
- *
42
- * However, whatever you configure, it becomes false when marshaling or parsing.
43
- *
44
- * @default false
45
- */
46
- functional?: boolean;
47
- }
1
+ export interface ITransformOptions {
2
+ /**
3
+ * Whether to validate finite number or not.
4
+ *
5
+ * If configured true, number typed values would be validated by Number.isNaN().
6
+ *
7
+ * However, whatever you configure, it would be ignored when marshaling or parsing.
8
+ *
9
+ * - when marshaling, always be true
10
+ * - assertStringify()
11
+ * - validateEncode()
12
+ * - when parsing, always be false
13
+ * - assertParse()
14
+ * - isDecode()
15
+ *
16
+ * @default false
17
+ */
18
+ finite?: boolean;
19
+
20
+ /**
21
+ * Whether to validate finite number or not.
22
+ *
23
+ * If configured true, number typed values would be validated by Number.isFinite().
24
+ *
25
+ * However, whatever you configure, it can be ignored in below case.
26
+ *
27
+ * - when `finite` option is true, this option would be ignored
28
+ * - when marshaling, always be true
29
+ * - assertStringify()
30
+ * - validateEncode()
31
+ * - when parsing, always be false
32
+ * - assertParse()
33
+ * - isDecode()
34
+ *
35
+ * @default false
36
+ */
37
+ numeric?: boolean;
38
+
39
+ /**
40
+ * Whether to validate functional type or not.
41
+ *
42
+ * However, whatever you configure, it becomes false when marshaling or parsing.
43
+ *
44
+ * @default false
45
+ */
46
+ functional?: boolean;
47
+ }
@@ -1,119 +1,117 @@
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 { Metadata } from "../../../metadata/Metadata";
8
- import { IJsonApplication } from "../../../schemas/IJsonApplication";
9
-
10
- import { ApplicationProgrammer } from "../../../programmers/ApplicationProgrammer";
11
-
12
- import { IProject } from "../../IProject";
13
-
14
- export namespace ApplicationTransformer {
15
- export function transform(
16
- { checker }: IProject,
17
- _modulo: ts.LeftHandSideExpression,
18
- expression: ts.CallExpression,
19
- ): ts.Expression {
20
- if (!expression.typeArguments?.length)
21
- throw new Error(ErrorMessages.NO_GENERIC_ARGUMENT);
22
-
23
- //----
24
- // GET ARGUMENTS
25
- //----
26
- // VALIDATE TUPLE ARGUMENTS
27
- const top: ts.Node = expression.typeArguments[0]!;
28
- if (!ts.isTupleTypeNode(top)) return expression;
29
- else if (top.elements.some((child) => !ts.isTypeNode(child)))
30
- return expression;
31
-
32
- // GET TYPES
33
- const types: ts.Type[] = top.elements.map((child) =>
34
- checker.getTypeFromTypeNode(child as ts.TypeNode),
35
- );
36
- if (types.some((t) => t.isTypeParameter()))
37
- throw new Error(ErrorMessages.GENERIC_ARGUMENT);
38
-
39
- // ADDITIONAL PARAMETERS
40
- const purpose: "swagger" | "ajv" = get_parameter(
41
- checker,
42
- "Purpose",
43
- expression.typeArguments[1],
44
- (str) => str === "swagger" || str === "ajv",
45
- () => "swagger",
46
- );
47
- const prefix: string = get_parameter(
48
- checker,
49
- "Prefix",
50
- expression.typeArguments[2],
51
- () => true,
52
- () =>
53
- purpose === "swagger"
54
- ? "#/components/schemas"
55
- : "components#/schemas",
56
- );
57
-
58
- //----
59
- // GENERATORS
60
- //----
61
- // METADATA
62
- const collection: MetadataCollection = new MetadataCollection({
63
- replace: MetadataCollection.replace,
64
- });
65
- const metadatas: Array<Metadata> = types.map((type) =>
66
- MetadataFactory.generate(checker, collection, type, {
67
- resolve: true,
68
- constant: true,
69
- validate: (meta) => {
70
- if (meta.atomics.find((str) => str === "bigint"))
71
- throw new Error(ErrorMessages.NO_BIGIT);
72
- },
73
- }),
74
- );
75
-
76
- // APPLICATION
77
- const app: IJsonApplication = ApplicationProgrammer.generate(
78
- metadatas,
79
- {
80
- purpose,
81
- prefix,
82
- },
83
- );
84
-
85
- // RETURNS WITH LITERAL EXPRESSION
86
- return LiteralFactory.generate(app);
87
- }
88
-
89
- function get_parameter<T extends string>(
90
- checker: ts.TypeChecker,
91
- name: string,
92
- node: ts.TypeNode | undefined,
93
- predicator: (value: string) => boolean,
94
- defaulter: () => T,
95
- ): T {
96
- if (!node) return defaulter();
97
-
98
- // CHECK LITERAL TYPE
99
- const type: ts.Type = checker.getTypeFromTypeNode(node);
100
- if (!type.isLiteral())
101
- throw new Error(
102
- `Error on typia.application(): generic argument "${name}" must be constant.`,
103
- );
104
-
105
- // GET VALUE AND VALIDATE IT
106
- const value = type.value;
107
- if (typeof value !== "string" || predicator(value) === false)
108
- throw new Error(
109
- `Error on typia.application(): invalid value on generic argument "${name}".`,
110
- );
111
- return value as T;
112
- }
113
- }
114
-
115
- const enum ErrorMessages {
116
- NO_GENERIC_ARGUMENT = "Error on typia.application(): no generic argument.",
117
- GENERIC_ARGUMENT = "Error on typia.application(): non-specified generic argument(s).",
118
- NO_BIGIT = "Error on typia.application(): does not allow bigint type.",
119
- }
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 { Metadata } from "../../../metadata/Metadata";
8
+ import { IJsonApplication } from "../../../schemas/IJsonApplication";
9
+
10
+ import { ApplicationProgrammer } from "../../../programmers/ApplicationProgrammer";
11
+
12
+ import { IProject } from "../../IProject";
13
+
14
+ export namespace ApplicationTransformer {
15
+ export function transform(
16
+ { checker }: IProject,
17
+ _modulo: ts.LeftHandSideExpression,
18
+ expression: ts.CallExpression,
19
+ ): ts.Expression {
20
+ if (!expression.typeArguments?.length)
21
+ throw new Error(ErrorMessages.NO_GENERIC_ARGUMENT);
22
+
23
+ //----
24
+ // GET ARGUMENTS
25
+ //----
26
+ // VALIDATE TUPLE ARGUMENTS
27
+ const top: ts.Node = expression.typeArguments[0]!;
28
+ if (!ts.isTupleTypeNode(top)) return expression;
29
+ else if (top.elements.some((child) => !ts.isTypeNode(child)))
30
+ return expression;
31
+
32
+ // GET TYPES
33
+ const types: ts.Type[] = top.elements.map((child) =>
34
+ checker.getTypeFromTypeNode(child as ts.TypeNode),
35
+ );
36
+ if (types.some((t) => t.isTypeParameter()))
37
+ throw new Error(ErrorMessages.GENERIC_ARGUMENT);
38
+
39
+ // ADDITIONAL PARAMETERS
40
+ const purpose: "swagger" | "ajv" = get_parameter(
41
+ checker,
42
+ "Purpose",
43
+ expression.typeArguments[1],
44
+ (str) => str === "swagger" || str === "ajv",
45
+ () => "swagger",
46
+ );
47
+ const prefix: string = get_parameter(
48
+ checker,
49
+ "Prefix",
50
+ expression.typeArguments[2],
51
+ () => true,
52
+ () =>
53
+ purpose === "swagger"
54
+ ? "#/components/schemas"
55
+ : "components#/schemas",
56
+ );
57
+
58
+ //----
59
+ // GENERATORS
60
+ //----
61
+ // METADATA
62
+ const collection: MetadataCollection = new MetadataCollection();
63
+ const metadatas: Array<Metadata> = types.map((type) =>
64
+ MetadataFactory.generate(checker, collection, type, {
65
+ resolve: true,
66
+ constant: true,
67
+ validate: (meta) => {
68
+ if (meta.atomics.find((str) => str === "bigint"))
69
+ throw new Error(ErrorMessages.NO_BIGIT);
70
+ },
71
+ }),
72
+ );
73
+
74
+ // APPLICATION
75
+ const app: IJsonApplication = ApplicationProgrammer.generate(
76
+ metadatas,
77
+ {
78
+ purpose,
79
+ prefix,
80
+ },
81
+ );
82
+
83
+ // RETURNS WITH LITERAL EXPRESSION
84
+ return LiteralFactory.generate(app);
85
+ }
86
+
87
+ function get_parameter<T extends string>(
88
+ checker: ts.TypeChecker,
89
+ name: string,
90
+ node: ts.TypeNode | undefined,
91
+ predicator: (value: string) => boolean,
92
+ defaulter: () => T,
93
+ ): T {
94
+ if (!node) return defaulter();
95
+
96
+ // CHECK LITERAL TYPE
97
+ const type: ts.Type = checker.getTypeFromTypeNode(node);
98
+ if (!type.isLiteral())
99
+ throw new Error(
100
+ `Error on typia.application(): generic argument "${name}" must be constant.`,
101
+ );
102
+
103
+ // GET VALUE AND VALIDATE IT
104
+ const value = type.value;
105
+ if (typeof value !== "string" || predicator(value) === false)
106
+ throw new Error(
107
+ `Error on typia.application(): invalid value on generic argument "${name}".`,
108
+ );
109
+ return value as T;
110
+ }
111
+ }
112
+
113
+ const enum ErrorMessages {
114
+ NO_GENERIC_ARGUMENT = "Error on typia.application(): no generic argument.",
115
+ GENERIC_ARGUMENT = "Error on typia.application(): non-specified generic argument(s).",
116
+ NO_BIGIT = "Error on typia.application(): does not allow bigint type.",
117
+ }
@@ -0,0 +1,32 @@
1
+ import ts from "typescript";
2
+
3
+ import { MessageProgrammer } from "../../../programmers/MessageProgrammer";
4
+
5
+ import { IProject } from "../../IProject";
6
+
7
+ export namespace MessageTransformer {
8
+ export function transform(
9
+ project: IProject,
10
+ _modulo: ts.LeftHandSideExpression,
11
+ expression: ts.CallExpression,
12
+ ): ts.Expression {
13
+ // CHECK GENERIC ARGUMENT EXISTENCE
14
+ if (!expression.typeArguments || !expression.typeArguments[0])
15
+ throw new Error(ErrorMessages.NOT_SPECIFIED);
16
+
17
+ // GET TYPE INFO
18
+ const type: ts.Type = project.checker.getTypeFromTypeNode(
19
+ expression.typeArguments[0],
20
+ );
21
+ if (type.isTypeParameter())
22
+ throw new Error(ErrorMessages.GENERIC_ARGUMENT);
23
+
24
+ // DO TRANSFORM
25
+ return MessageProgrammer.generate(project)(type);
26
+ }
27
+ }
28
+
29
+ const enum ErrorMessages {
30
+ NOT_SPECIFIED = "Error on typia.message(): generic argument is not specified.",
31
+ GENERIC_ARGUMENT = "Error on typia.message(): non-specified generic argument.",
32
+ }