typia 7.0.0-dev.20241009-2 → 7.0.0-dev.20241010

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 (151) hide show
  1. package/lib/factories/JsonMetadataFactory.d.ts +5 -1
  2. package/lib/factories/JsonMetadataFactory.js +4 -1
  3. package/lib/factories/JsonMetadataFactory.js.map +1 -1
  4. package/lib/internal/{$httpFormDataReadArray.js → $httpFormdataReadArray.js} +1 -1
  5. package/lib/internal/$httpFormdataReadArray.js.map +1 -0
  6. package/lib/programmers/CheckerProgrammer.js +4 -1
  7. package/lib/programmers/CheckerProgrammer.js.map +1 -1
  8. package/lib/programmers/FeatureProgrammer.d.ts +4 -1
  9. package/lib/programmers/FeatureProgrammer.js +2 -2
  10. package/lib/programmers/FeatureProgrammer.js.map +1 -1
  11. package/lib/programmers/RandomProgrammer.js +12 -9
  12. package/lib/programmers/RandomProgrammer.js.map +1 -1
  13. package/lib/programmers/TypiaProgrammer.js +4 -1
  14. package/lib/programmers/TypiaProgrammer.js.map +1 -1
  15. package/lib/programmers/internal/prune_object_properties.js +3 -2
  16. package/lib/programmers/internal/prune_object_properties.js.map +1 -1
  17. package/lib/programmers/json/JsonAssertParseProgrammer.js +2 -2
  18. package/lib/programmers/json/JsonAssertParseProgrammer.js.map +1 -1
  19. package/lib/programmers/misc/MiscCloneProgrammer.js +4 -1
  20. package/lib/programmers/misc/MiscCloneProgrammer.js.map +1 -1
  21. package/lib/programmers/misc/MiscPruneProgrammer.js +4 -1
  22. package/lib/programmers/misc/MiscPruneProgrammer.js.map +1 -1
  23. package/lib/programmers/notations/NotationGeneralProgrammer.js +4 -1
  24. package/lib/programmers/notations/NotationGeneralProgrammer.js.map +1 -1
  25. package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js +1 -1
  26. package/lib/programmers/protobuf/ProtobufDecodeProgrammer.js.map +1 -1
  27. package/lib/transformers/FileTransformer.js +0 -6
  28. package/lib/transformers/FileTransformer.js.map +1 -1
  29. package/lib/transformers/ImportTransformer.d.ts +4 -1
  30. package/lib/transformers/ImportTransformer.js +34 -30
  31. package/lib/transformers/ImportTransformer.js.map +1 -1
  32. package/package.json +1 -1
  33. package/src/IRandomGenerator.ts +49 -49
  34. package/src/factories/ExpressionFactory.ts +164 -164
  35. package/src/factories/JsonMetadataFactory.ts +25 -15
  36. package/src/factories/LiteralFactory.ts +50 -50
  37. package/src/factories/MetadataCommentTagFactory.ts +650 -650
  38. package/src/functional.ts +750 -750
  39. package/src/http.ts +1042 -1042
  40. package/src/internal/$IProtobufWriter.ts +18 -18
  41. package/src/internal/$ProtobufReader.ts +194 -194
  42. package/src/internal/$ProtobufSizer.ts +151 -151
  43. package/src/internal/$ProtobufWriter.ts +145 -145
  44. package/src/internal/$accessExpressionAsString.ts +46 -46
  45. package/src/internal/$assertGuard.ts +13 -13
  46. package/src/internal/$functionalTypeGuardErrorFactory.ts +4 -4
  47. package/src/internal/$httpFormDataReadBigint.ts +18 -18
  48. package/src/internal/$httpFormDataReadBlob.ts +10 -10
  49. package/src/internal/$httpFormDataReadBoolean.ts +16 -16
  50. package/src/internal/$httpFormDataReadFile.ts +10 -10
  51. package/src/internal/$httpFormDataReadNumber.ts +15 -15
  52. package/src/internal/$httpFormDataReadString.ts +10 -10
  53. package/src/internal/{$httpFormDataReadArray.ts → $httpFormdataReadArray.ts} +4 -4
  54. package/src/internal/$httpHeaderReadBigint.ts +10 -10
  55. package/src/internal/$httpHeaderReadBoolean.ts +8 -8
  56. package/src/internal/$httpHeaderReadNumber.ts +7 -7
  57. package/src/internal/$httpParameterBigint.ts +10 -10
  58. package/src/internal/$httpParameterBoolean.ts +8 -8
  59. package/src/internal/$httpParameterNumber.ts +7 -7
  60. package/src/internal/$httpParameterString.ts +2 -2
  61. package/src/internal/$httpQueryParseURLSearchParams.ts +10 -10
  62. package/src/internal/$httpQueryReadArray.ts +4 -4
  63. package/src/internal/$httpQueryReadBigint.ts +12 -12
  64. package/src/internal/$httpQueryReadBoolean.ts +14 -14
  65. package/src/internal/$httpQueryReadNumber.ts +9 -9
  66. package/src/internal/$httpQueryReadString.ts +4 -4
  67. package/src/internal/$isBetween.ts +2 -2
  68. package/src/internal/$isBigintString.ts +8 -8
  69. package/src/internal/$jsonStringifyNumber.ts +12 -12
  70. package/src/internal/$jsonStringifyRest.ts +3 -3
  71. package/src/internal/$jsonStringifyString.ts +42 -42
  72. package/src/internal/$jsonStringifyTail.ts +2 -2
  73. package/src/internal/$llmApplicationFinalize.ts +18 -18
  74. package/src/internal/$miscCloneAny.ts +48 -48
  75. package/src/internal/$notationAny.ts +37 -37
  76. package/src/internal/$notationCamel.ts +13 -13
  77. package/src/internal/$notationPascal.ts +8 -8
  78. package/src/internal/$notationSnake.ts +43 -43
  79. package/src/internal/$randomArray.ts +21 -21
  80. package/src/internal/$randomBigint.ts +6 -6
  81. package/src/internal/$randomBoolean.ts +1 -1
  82. package/src/internal/$randomFormatByte.ts +3 -3
  83. package/src/internal/$randomFormatDate.ts +18 -18
  84. package/src/internal/$randomFormatDatetime.ts +16 -16
  85. package/src/internal/$randomFormatDuration.ts +27 -27
  86. package/src/internal/$randomFormatEmail.ts +11 -11
  87. package/src/internal/$randomFormatHostname.ts +6 -6
  88. package/src/internal/$randomFormatIdnEmail.ts +3 -3
  89. package/src/internal/$randomFormatIdnHostname.ts +3 -3
  90. package/src/internal/$randomFormatIpv4.ts +11 -11
  91. package/src/internal/$randomFormatIpv6.ts +11 -11
  92. package/src/internal/$randomFormatIri.ts +3 -3
  93. package/src/internal/$randomFormatIriReference.ts +3 -3
  94. package/src/internal/$randomFormatJsonPointer.ts +7 -7
  95. package/src/internal/$randomFormatPassword.ts +8 -8
  96. package/src/internal/$randomFormatRegex.ts +4 -4
  97. package/src/internal/$randomFormatRelativeJsonPointer.ts +8 -8
  98. package/src/internal/$randomFormatTime.ts +14 -14
  99. package/src/internal/$randomFormatUri.ts +3 -3
  100. package/src/internal/$randomFormatUriReference.ts +3 -3
  101. package/src/internal/$randomFormatUriTemplate.ts +3 -3
  102. package/src/internal/$randomFormatUrl.ts +11 -11
  103. package/src/internal/$randomFormatUuid.ts +6 -6
  104. package/src/internal/$randomInteger.ts +47 -47
  105. package/src/internal/$randomNumber.ts +74 -74
  106. package/src/internal/$randomPattern.ts +10 -10
  107. package/src/internal/$randomPick.ts +9 -9
  108. package/src/internal/$randomString.ts +24 -24
  109. package/src/internal/$throwTypeGuardError.ts +5 -5
  110. package/src/internal/$validateReport.ts +13 -13
  111. package/src/internal/private/$__notationCapitalize.ts +2 -2
  112. package/src/internal/private/$__notationUnsnake.ts +24 -24
  113. package/src/json.ts +651 -651
  114. package/src/llm.ts +178 -178
  115. package/src/misc.ts +658 -658
  116. package/src/module.ts +933 -933
  117. package/src/notations.ts +827 -827
  118. package/src/programmers/CheckerProgrammer.ts +4 -1
  119. package/src/programmers/FeatureProgrammer.ts +619 -616
  120. package/src/programmers/RandomProgrammer.ts +24 -16
  121. package/src/programmers/TypiaProgrammer.ts +4 -1
  122. package/src/programmers/functional/FunctionalAssertFunctionProgrammer.ts +153 -153
  123. package/src/programmers/functional/FunctionalAssertParametersProgrammer.ts +125 -125
  124. package/src/programmers/functional/FunctionalAssertReturnProgrammer.ts +115 -115
  125. package/src/programmers/functional/FunctionalValidateFunctionProgrammer.ts +119 -119
  126. package/src/programmers/functional/FunctionalValidateParametersProgrammer.ts +274 -274
  127. package/src/programmers/functional/FunctionalValidateReturnProgrammer.ts +135 -135
  128. package/src/programmers/helpers/FunctionProgrammer.ts +67 -67
  129. package/src/programmers/helpers/RandomJoiner.ts +168 -168
  130. package/src/programmers/helpers/StringifyJoinder.ts +115 -115
  131. package/src/programmers/helpers/disable_function_programmer_declare.ts +32 -32
  132. package/src/programmers/internal/check_dynamic_key.ts +201 -201
  133. package/src/programmers/internal/check_dynamic_properties.ts +208 -208
  134. package/src/programmers/internal/check_object.ts +75 -75
  135. package/src/programmers/internal/feature_object_entries.ts +61 -61
  136. package/src/programmers/internal/prune_object_properties.ts +71 -63
  137. package/src/programmers/json/JsonAssertParseProgrammer.ts +14 -11
  138. package/src/programmers/llm/LlmApplicationProgrammer.ts +235 -235
  139. package/src/programmers/llm/LlmSchemaProgrammer.ts +51 -51
  140. package/src/programmers/misc/MiscCloneProgrammer.ts +4 -1
  141. package/src/programmers/misc/MiscPruneProgrammer.ts +4 -1
  142. package/src/programmers/notations/NotationGeneralProgrammer.ts +4 -1
  143. package/src/programmers/protobuf/ProtobufDecodeProgrammer.ts +1 -1
  144. package/src/protobuf.ts +868 -868
  145. package/src/reflect.ts +57 -57
  146. package/src/transformers/FileTransformer.ts +0 -6
  147. package/src/transformers/ImportTransformer.ts +59 -44
  148. package/src/utils/NamingConvention.ts +94 -94
  149. package/src/utils/StringUtil.ts +16 -16
  150. package/lib/internal/$httpFormDataReadArray.js.map +0 -1
  151. /package/lib/internal/{$httpFormDataReadArray.d.ts → $httpFormdataReadArray.d.ts} +0 -0
@@ -1,208 +1,208 @@
1
- import ts from "typescript";
2
-
3
- import { ExpressionFactory } from "../../factories/ExpressionFactory";
4
- import { IdentifierFactory } from "../../factories/IdentifierFactory";
5
- import { StatementFactory } from "../../factories/StatementFactory";
6
-
7
- import { ITypiaContext } from "../../transformers/ITypiaContext";
8
-
9
- import { IExpressionEntry } from "../helpers/IExpressionEntry";
10
- import { check_dynamic_key } from "./check_dynamic_key";
11
- import { check_everything } from "./check_everything";
12
- import { check_object } from "./check_object";
13
-
14
- /**
15
- * @internal
16
- */
17
- export const check_dynamic_properties = (props: {
18
- config: check_object.IConfig;
19
- context: ITypiaContext;
20
- regular: IExpressionEntry<ts.Expression>[];
21
- dynamic: IExpressionEntry<ts.Expression>[];
22
- input: ts.Expression;
23
- }): ts.Expression => {
24
- const length = IdentifierFactory.access(
25
- ts.factory.createCallExpression(
26
- ts.factory.createIdentifier("Object.keys"),
27
- undefined,
28
- [props.input],
29
- ),
30
- "length",
31
- );
32
- const left: ts.Expression | null =
33
- props.config.equals === true && props.dynamic.length === 0
34
- ? props.config.undefined === true ||
35
- props.regular.every((r) => r.meta.isRequired())
36
- ? ts.factory.createStrictEquality(
37
- ExpressionFactory.number(
38
- props.regular.filter((r) => r.meta.isRequired()).length,
39
- ),
40
- length,
41
- )
42
- : ts.factory.createCallExpression(
43
- props.context.importer.internal("isBetween"),
44
- [],
45
- [
46
- length,
47
- ExpressionFactory.number(
48
- props.regular.filter((r) => r.meta.isRequired()).length,
49
- ),
50
- ExpressionFactory.number(props.regular.length),
51
- ],
52
- )
53
- : null;
54
- if (
55
- left !== null &&
56
- props.config.undefined === false &&
57
- props.regular.every((r) => r.meta.isRequired())
58
- )
59
- return left;
60
-
61
- const criteria: ts.CallExpression = props.config.entries
62
- ? ts.factory.createCallExpression(props.config.entries, undefined, [
63
- ts.factory.createCallExpression(
64
- ts.factory.createIdentifier("Object.keys"),
65
- undefined,
66
- [props.input],
67
- ),
68
- check_dynamic_property(props),
69
- ])
70
- : ts.factory.createCallExpression(
71
- IdentifierFactory.access(
72
- ts.factory.createCallExpression(
73
- ts.factory.createIdentifier("Object.keys"),
74
- undefined,
75
- [props.input],
76
- ),
77
- props.config.assert ? "every" : "map",
78
- ),
79
- undefined,
80
- [check_dynamic_property(props)],
81
- );
82
- const right: ts.Expression = (props.config.halt || ((elem) => elem))(
83
- props.config.assert ? criteria : check_everything(criteria),
84
- );
85
- return left
86
- ? (props.config.undefined
87
- ? ts.factory.createLogicalOr
88
- : ts.factory.createLogicalAnd)(left, right)
89
- : right;
90
- };
91
-
92
- /**
93
- * @internal
94
- */
95
- const check_dynamic_property = (props: {
96
- config: check_object.IConfig;
97
- context: ITypiaContext;
98
- regular: IExpressionEntry<ts.Expression>[];
99
- dynamic: IExpressionEntry<ts.Expression>[];
100
- input: ts.Expression;
101
- }) => {
102
- //----
103
- // IF CONDITIONS
104
- //----
105
- // PREPARE ASSETS
106
- const key = ts.factory.createIdentifier("key");
107
- const value = ts.factory.createIdentifier("value");
108
-
109
- const statements: ts.Statement[] = [];
110
- const add = (expression: ts.Expression, output: ts.Expression) =>
111
- statements.push(
112
- ts.factory.createIfStatement(
113
- expression,
114
- ts.factory.createReturnStatement(output),
115
- ),
116
- );
117
- const broken = { value: false };
118
-
119
- // GATHER CONDITIONS
120
- if (props.regular.length)
121
- add(is_regular_property(props.regular), props.config.positive);
122
- statements.push(
123
- StatementFactory.constant({
124
- name: "value",
125
- value: ts.factory.createElementAccessExpression(props.input, key),
126
- }),
127
- );
128
- if (props.config.undefined === true)
129
- add(
130
- ts.factory.createStrictEquality(
131
- ts.factory.createIdentifier("undefined"),
132
- value,
133
- ),
134
- props.config.positive,
135
- );
136
-
137
- for (const entry of props.dynamic) {
138
- const condition: ts.Expression = check_dynamic_key({
139
- context: props.context,
140
- metadata: entry.key,
141
- input: key,
142
- });
143
- if (condition.kind === ts.SyntaxKind.TrueKeyword) {
144
- statements.push(ts.factory.createReturnStatement(entry.expression));
145
- broken.value = true;
146
- break;
147
- } else add(condition, entry.expression);
148
- }
149
-
150
- //----
151
- // FUNCTION BODY
152
- //----
153
- // CLOSURE BLOCK
154
- const block: ts.Block = ts.factory.createBlock(
155
- [
156
- ...statements,
157
- ...(broken.value
158
- ? []
159
- : [
160
- ts.factory.createReturnStatement(
161
- props.config.equals === true
162
- ? props.config.superfluous(value)
163
- : props.config.positive,
164
- ),
165
- ]),
166
- ],
167
- true,
168
- );
169
-
170
- // RETURNS
171
- return ts.factory.createArrowFunction(
172
- undefined,
173
- undefined,
174
- [IdentifierFactory.parameter("key")],
175
- undefined,
176
- undefined,
177
- block,
178
- );
179
- };
180
-
181
- /**
182
- * @internal
183
- */
184
- const is_regular_property = (regular: IExpressionEntry[]) =>
185
- ts.factory.createCallExpression(
186
- IdentifierFactory.access(
187
- ts.factory.createArrayLiteralExpression(
188
- regular.map((entry) =>
189
- ts.factory.createStringLiteral(entry.key.getSoleLiteral()!),
190
- ),
191
- ),
192
- "some",
193
- ),
194
- undefined,
195
- [
196
- ts.factory.createArrowFunction(
197
- undefined,
198
- undefined,
199
- [IdentifierFactory.parameter("prop")],
200
- undefined,
201
- undefined,
202
- ts.factory.createStrictEquality(
203
- ts.factory.createIdentifier("key"),
204
- ts.factory.createIdentifier("prop"),
205
- ),
206
- ),
207
- ],
208
- );
1
+ import ts from "typescript";
2
+
3
+ import { ExpressionFactory } from "../../factories/ExpressionFactory";
4
+ import { IdentifierFactory } from "../../factories/IdentifierFactory";
5
+ import { StatementFactory } from "../../factories/StatementFactory";
6
+
7
+ import { ITypiaContext } from "../../transformers/ITypiaContext";
8
+
9
+ import { IExpressionEntry } from "../helpers/IExpressionEntry";
10
+ import { check_dynamic_key } from "./check_dynamic_key";
11
+ import { check_everything } from "./check_everything";
12
+ import { check_object } from "./check_object";
13
+
14
+ /**
15
+ * @internal
16
+ */
17
+ export const check_dynamic_properties = (props: {
18
+ config: check_object.IConfig;
19
+ context: ITypiaContext;
20
+ regular: IExpressionEntry<ts.Expression>[];
21
+ dynamic: IExpressionEntry<ts.Expression>[];
22
+ input: ts.Expression;
23
+ }): ts.Expression => {
24
+ const length = IdentifierFactory.access(
25
+ ts.factory.createCallExpression(
26
+ ts.factory.createIdentifier("Object.keys"),
27
+ undefined,
28
+ [props.input],
29
+ ),
30
+ "length",
31
+ );
32
+ const left: ts.Expression | null =
33
+ props.config.equals === true && props.dynamic.length === 0
34
+ ? props.config.undefined === true ||
35
+ props.regular.every((r) => r.meta.isRequired())
36
+ ? ts.factory.createStrictEquality(
37
+ ExpressionFactory.number(
38
+ props.regular.filter((r) => r.meta.isRequired()).length,
39
+ ),
40
+ length,
41
+ )
42
+ : ts.factory.createCallExpression(
43
+ props.context.importer.internal("isBetween"),
44
+ [],
45
+ [
46
+ length,
47
+ ExpressionFactory.number(
48
+ props.regular.filter((r) => r.meta.isRequired()).length,
49
+ ),
50
+ ExpressionFactory.number(props.regular.length),
51
+ ],
52
+ )
53
+ : null;
54
+ if (
55
+ left !== null &&
56
+ props.config.undefined === false &&
57
+ props.regular.every((r) => r.meta.isRequired())
58
+ )
59
+ return left;
60
+
61
+ const criteria: ts.CallExpression = props.config.entries
62
+ ? ts.factory.createCallExpression(props.config.entries, undefined, [
63
+ ts.factory.createCallExpression(
64
+ ts.factory.createIdentifier("Object.keys"),
65
+ undefined,
66
+ [props.input],
67
+ ),
68
+ check_dynamic_property(props),
69
+ ])
70
+ : ts.factory.createCallExpression(
71
+ IdentifierFactory.access(
72
+ ts.factory.createCallExpression(
73
+ ts.factory.createIdentifier("Object.keys"),
74
+ undefined,
75
+ [props.input],
76
+ ),
77
+ props.config.assert ? "every" : "map",
78
+ ),
79
+ undefined,
80
+ [check_dynamic_property(props)],
81
+ );
82
+ const right: ts.Expression = (props.config.halt || ((elem) => elem))(
83
+ props.config.assert ? criteria : check_everything(criteria),
84
+ );
85
+ return left
86
+ ? (props.config.undefined
87
+ ? ts.factory.createLogicalOr
88
+ : ts.factory.createLogicalAnd)(left, right)
89
+ : right;
90
+ };
91
+
92
+ /**
93
+ * @internal
94
+ */
95
+ const check_dynamic_property = (props: {
96
+ config: check_object.IConfig;
97
+ context: ITypiaContext;
98
+ regular: IExpressionEntry<ts.Expression>[];
99
+ dynamic: IExpressionEntry<ts.Expression>[];
100
+ input: ts.Expression;
101
+ }) => {
102
+ //----
103
+ // IF CONDITIONS
104
+ //----
105
+ // PREPARE ASSETS
106
+ const key = ts.factory.createIdentifier("key");
107
+ const value = ts.factory.createIdentifier("value");
108
+
109
+ const statements: ts.Statement[] = [];
110
+ const add = (expression: ts.Expression, output: ts.Expression) =>
111
+ statements.push(
112
+ ts.factory.createIfStatement(
113
+ expression,
114
+ ts.factory.createReturnStatement(output),
115
+ ),
116
+ );
117
+ const broken = { value: false };
118
+
119
+ // GATHER CONDITIONS
120
+ if (props.regular.length)
121
+ add(is_regular_property(props.regular), props.config.positive);
122
+ statements.push(
123
+ StatementFactory.constant({
124
+ name: "value",
125
+ value: ts.factory.createElementAccessExpression(props.input, key),
126
+ }),
127
+ );
128
+ if (props.config.undefined === true)
129
+ add(
130
+ ts.factory.createStrictEquality(
131
+ ts.factory.createIdentifier("undefined"),
132
+ value,
133
+ ),
134
+ props.config.positive,
135
+ );
136
+
137
+ for (const entry of props.dynamic) {
138
+ const condition: ts.Expression = check_dynamic_key({
139
+ context: props.context,
140
+ metadata: entry.key,
141
+ input: key,
142
+ });
143
+ if (condition.kind === ts.SyntaxKind.TrueKeyword) {
144
+ statements.push(ts.factory.createReturnStatement(entry.expression));
145
+ broken.value = true;
146
+ break;
147
+ } else add(condition, entry.expression);
148
+ }
149
+
150
+ //----
151
+ // FUNCTION BODY
152
+ //----
153
+ // CLOSURE BLOCK
154
+ const block: ts.Block = ts.factory.createBlock(
155
+ [
156
+ ...statements,
157
+ ...(broken.value
158
+ ? []
159
+ : [
160
+ ts.factory.createReturnStatement(
161
+ props.config.equals === true
162
+ ? props.config.superfluous(value)
163
+ : props.config.positive,
164
+ ),
165
+ ]),
166
+ ],
167
+ true,
168
+ );
169
+
170
+ // RETURNS
171
+ return ts.factory.createArrowFunction(
172
+ undefined,
173
+ undefined,
174
+ [IdentifierFactory.parameter("key")],
175
+ undefined,
176
+ undefined,
177
+ block,
178
+ );
179
+ };
180
+
181
+ /**
182
+ * @internal
183
+ */
184
+ const is_regular_property = (regular: IExpressionEntry[]) =>
185
+ ts.factory.createCallExpression(
186
+ IdentifierFactory.access(
187
+ ts.factory.createArrayLiteralExpression(
188
+ regular.map((entry) =>
189
+ ts.factory.createStringLiteral(entry.key.getSoleLiteral()!),
190
+ ),
191
+ ),
192
+ "some",
193
+ ),
194
+ undefined,
195
+ [
196
+ ts.factory.createArrowFunction(
197
+ undefined,
198
+ undefined,
199
+ [IdentifierFactory.parameter("prop")],
200
+ undefined,
201
+ undefined,
202
+ ts.factory.createStrictEquality(
203
+ ts.factory.createIdentifier("key"),
204
+ ts.factory.createIdentifier("prop"),
205
+ ),
206
+ ),
207
+ ],
208
+ );
@@ -1,75 +1,75 @@
1
- import ts from "typescript";
2
-
3
- import { ITypiaContext } from "../../transformers/ITypiaContext";
4
-
5
- import { IExpressionEntry } from "../helpers/IExpressionEntry";
6
- import { check_dynamic_properties } from "./check_dynamic_properties";
7
- import { check_everything } from "./check_everything";
8
-
9
- /**
10
- * @internal
11
- */
12
- export const check_object = (props: {
13
- config: check_object.IConfig;
14
- context: ITypiaContext;
15
- input: ts.Expression;
16
- entries: IExpressionEntry<ts.Expression>[];
17
- }) => {
18
- // PREPARE ASSETS
19
- const regular = props.entries.filter((entry) => entry.key.isSoleLiteral());
20
- const dynamic = props.entries.filter((entry) => !entry.key.isSoleLiteral());
21
- const flags: ts.Expression[] = regular.map((entry) => entry.expression);
22
-
23
- // REGULAR WITHOUT DYNAMIC PROPERTIES
24
- if (props.config.equals === false && dynamic.length === 0)
25
- return regular.length === 0
26
- ? props.config.positive
27
- : reduce({
28
- config: props.config,
29
- expressions: flags,
30
- });
31
-
32
- // CHECK DYNAMIC PROPERTIES
33
- flags.push(
34
- check_dynamic_properties({
35
- config: props.config,
36
- context: props.context,
37
- input: props.input,
38
- regular,
39
- dynamic,
40
- }),
41
- );
42
- return reduce({
43
- config: props.config,
44
- expressions: flags,
45
- });
46
- };
47
-
48
- /**
49
- * @internal
50
- */
51
- export namespace check_object {
52
- export interface IConfig {
53
- equals: boolean;
54
- assert: boolean;
55
- undefined: boolean;
56
- halt?: undefined | ((exp: ts.Expression) => ts.Expression);
57
- reduce: (a: ts.Expression, b: ts.Expression) => ts.Expression;
58
- positive: ts.Expression;
59
- superfluous: (value: ts.Expression) => ts.Expression;
60
- entries?: undefined | ts.Identifier;
61
- }
62
- }
63
-
64
- /**
65
- * @internal
66
- */
67
- const reduce = (props: {
68
- config: check_object.IConfig;
69
- expressions: ts.Expression[];
70
- }) =>
71
- props.config.assert
72
- ? props.expressions.reduce(props.config.reduce)
73
- : check_everything(
74
- ts.factory.createArrayLiteralExpression(props.expressions),
75
- );
1
+ import ts from "typescript";
2
+
3
+ import { ITypiaContext } from "../../transformers/ITypiaContext";
4
+
5
+ import { IExpressionEntry } from "../helpers/IExpressionEntry";
6
+ import { check_dynamic_properties } from "./check_dynamic_properties";
7
+ import { check_everything } from "./check_everything";
8
+
9
+ /**
10
+ * @internal
11
+ */
12
+ export const check_object = (props: {
13
+ config: check_object.IConfig;
14
+ context: ITypiaContext;
15
+ input: ts.Expression;
16
+ entries: IExpressionEntry<ts.Expression>[];
17
+ }) => {
18
+ // PREPARE ASSETS
19
+ const regular = props.entries.filter((entry) => entry.key.isSoleLiteral());
20
+ const dynamic = props.entries.filter((entry) => !entry.key.isSoleLiteral());
21
+ const flags: ts.Expression[] = regular.map((entry) => entry.expression);
22
+
23
+ // REGULAR WITHOUT DYNAMIC PROPERTIES
24
+ if (props.config.equals === false && dynamic.length === 0)
25
+ return regular.length === 0
26
+ ? props.config.positive
27
+ : reduce({
28
+ config: props.config,
29
+ expressions: flags,
30
+ });
31
+
32
+ // CHECK DYNAMIC PROPERTIES
33
+ flags.push(
34
+ check_dynamic_properties({
35
+ config: props.config,
36
+ context: props.context,
37
+ input: props.input,
38
+ regular,
39
+ dynamic,
40
+ }),
41
+ );
42
+ return reduce({
43
+ config: props.config,
44
+ expressions: flags,
45
+ });
46
+ };
47
+
48
+ /**
49
+ * @internal
50
+ */
51
+ export namespace check_object {
52
+ export interface IConfig {
53
+ equals: boolean;
54
+ assert: boolean;
55
+ undefined: boolean;
56
+ halt?: undefined | ((exp: ts.Expression) => ts.Expression);
57
+ reduce: (a: ts.Expression, b: ts.Expression) => ts.Expression;
58
+ positive: ts.Expression;
59
+ superfluous: (value: ts.Expression) => ts.Expression;
60
+ entries?: undefined | ts.Identifier;
61
+ }
62
+ }
63
+
64
+ /**
65
+ * @internal
66
+ */
67
+ const reduce = (props: {
68
+ config: check_object.IConfig;
69
+ expressions: ts.Expression[];
70
+ }) =>
71
+ props.config.assert
72
+ ? props.expressions.reduce(props.config.reduce)
73
+ : check_everything(
74
+ ts.factory.createArrayLiteralExpression(props.expressions),
75
+ );