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,616 +1,619 @@
1
- import ts from "typescript";
2
-
3
- import { IdentifierFactory } from "../factories/IdentifierFactory";
4
- import { MetadataCollection } from "../factories/MetadataCollection";
5
- import { StatementFactory } from "../factories/StatementFactory";
6
- import { TypeFactory } from "../factories/TypeFactory";
7
- import { ValueFactory } from "../factories/ValueFactory";
8
-
9
- import { Metadata } from "../schemas/metadata/Metadata";
10
- import { MetadataArray } from "../schemas/metadata/MetadataArray";
11
- import { MetadataObject } from "../schemas/metadata/MetadataObject";
12
-
13
- import { ITypiaContext } from "../transformers/ITypiaContext";
14
-
15
- import { CheckerProgrammer } from "./CheckerProgrammer";
16
- import { FunctionProgrammer } from "./helpers/FunctionProgrammer";
17
- import { IExpressionEntry } from "./helpers/IExpressionEntry";
18
- import { UnionExplorer } from "./helpers/UnionExplorer";
19
- import { feature_object_entries } from "./internal/feature_object_entries";
20
-
21
- export namespace FeatureProgrammer {
22
- /* -----------------------------------------------------------
23
- PARAMETERS
24
- ----------------------------------------------------------- */
25
- export interface IConfig<Output extends ts.ConciseBody = ts.ConciseBody> {
26
- types: IConfig.ITypes;
27
-
28
- /**
29
- * Prefix name of internal functions for specific types.
30
- */
31
- prefix: string;
32
-
33
- /**
34
- * Whether to archive access path or not.
35
- */
36
- path: boolean;
37
-
38
- /**
39
- * Whether to trace exception or not.
40
- */
41
- trace: boolean;
42
-
43
- addition?: undefined | ((collection: MetadataCollection) => ts.Statement[]);
44
-
45
- /**
46
- * Initializer of metadata.
47
- */
48
- initializer: (props: {
49
- context: ITypiaContext;
50
- functor: FunctionProgrammer;
51
- type: ts.Type;
52
- }) => [MetadataCollection, Metadata];
53
-
54
- /**
55
- * Decoder, station of every types.
56
- */
57
- decoder: (props: {
58
- metadata: Metadata;
59
- input: ts.Expression;
60
- explore: IExplore;
61
- }) => Output;
62
-
63
- /**
64
- * Object configurator.
65
- */
66
- objector: IConfig.IObjector<Output>;
67
-
68
- /**
69
- * Generator of functions for object types.
70
- */
71
- generator: IConfig.IGenerator;
72
- }
73
- export namespace IConfig {
74
- export interface ITypes {
75
- input: (type: ts.Type, name?: undefined | string) => ts.TypeNode;
76
- output: (type: ts.Type, name?: undefined | string) => ts.TypeNode;
77
- }
78
-
79
- export interface IObjector<Output extends ts.ConciseBody = ts.ConciseBody> {
80
- /**
81
- * Type checker when union object type comes.
82
- */
83
- checker: (props: {
84
- metadata: Metadata;
85
- input: ts.Expression;
86
- explore: IExplore;
87
- }) => ts.Expression;
88
-
89
- /**
90
- * Decoder, function call expression generator of specific typed objects.
91
- */
92
- decoder: (props: {
93
- input: ts.Expression;
94
- object: MetadataObject;
95
- explore: IExplore;
96
- }) => ts.Expression;
97
-
98
- /**
99
- * Joiner of expressions from properties.
100
- */
101
- joiner(props: {
102
- entries: IExpressionEntry<Output>[];
103
- input?: ts.Expression;
104
- object?: MetadataObject;
105
- }): ts.ConciseBody;
106
-
107
- /**
108
- * Union type specificator.
109
- *
110
- * Expression of an algorithm specifying object type and calling
111
- * the `decoder` function of the specified object type.
112
- */
113
- unionizer: (props: {
114
- objects: MetadataObject[];
115
- input: ts.Expression;
116
- explore: IExplore;
117
- }) => ts.Expression;
118
-
119
- /**
120
- * Handler of union type specification failure.
121
- *
122
- * @param props Properties of failure
123
- * @returns Statement of failure
124
- */
125
- failure(props: {
126
- input: ts.Expression;
127
- expected: string;
128
- explore?: undefined | IExplore;
129
- }): ts.Statement;
130
-
131
- /**
132
- * Transformer of type checking expression by discrimination.
133
- *
134
- * When an object type has been specified by a discrimination without full
135
- * iteration, the `unionizer` will decode the object instance after
136
- * the last type checking.
137
- *
138
- * In such circumtance, you can transform the last type checking function.
139
- *
140
- * @param exp Current expression about type checking
141
- * @returns Transformed expression
142
- * @deprecated
143
- */
144
- is?: undefined | ((exp: ts.Expression) => ts.Expression);
145
-
146
- /**
147
- * Transformer of non-undefined type checking by discrimination.
148
- *
149
- * When specifying an union type of objects, `typia` tries to find
150
- * descrimination way just by checking only one property type.
151
- * If succeeded to find the discrimination way, `typia` will check the target
152
- * property type and in the checking, non-undefined type checking would be
153
- * done.
154
- *
155
- * In such process, you can transform the non-undefined type checking.
156
- *
157
- * @param exp
158
- * @returns Transformed expression
159
- * @deprecated
160
- */
161
- required?: undefined | ((exp: ts.Expression) => ts.Expression);
162
-
163
- /**
164
- * Conditon wrapper when unable to specify any object type.
165
- *
166
- * When failed to specify an object type through discrimination, full
167
- * iteration type checking would be happend. In such circumstance, you
168
- * can wrap the condition with additional function.
169
- *
170
- * @param props Properties of condition
171
- * @returns The wrapper expression
172
- */
173
- full?:
174
- | undefined
175
- | ((props: {
176
- condition: ts.Expression;
177
- input: ts.Expression;
178
- expected: string;
179
- explore: IExplore;
180
- }) => ts.Expression);
181
-
182
- /**
183
- * Return type.
184
- */
185
- type?: undefined | ts.TypeNode;
186
- }
187
- export interface IGenerator {
188
- objects?:
189
- | undefined
190
- | ((collection: MetadataCollection) => ts.VariableStatement[]);
191
- unions?:
192
- | undefined
193
- | ((collection: MetadataCollection) => ts.VariableStatement[]);
194
- arrays: (collection: MetadataCollection) => ts.VariableStatement[];
195
- tuples: (collection: MetadataCollection) => ts.VariableStatement[];
196
- }
197
- }
198
-
199
- export interface IExplore {
200
- tracable: boolean;
201
- source: "top" | "function";
202
- from: "top" | "array" | "object";
203
- postfix: string;
204
- start?: undefined | number;
205
- }
206
-
207
- export type Decoder<
208
- T,
209
- Output extends ts.ConciseBody = ts.ConciseBody,
210
- > = (props: {
211
- input: ts.Expression;
212
- definition: T;
213
- explore: IExplore;
214
- }) => Output;
215
-
216
- /* -----------------------------------------------------------
217
- GENERATORS
218
- ----------------------------------------------------------- */
219
- export interface IComposed {
220
- body: ts.ConciseBody;
221
- parameters: ts.ParameterDeclaration[];
222
- functions: Record<string, ts.VariableStatement>;
223
- statements: ts.Statement[];
224
- response: ts.TypeNode;
225
- }
226
- export interface IDecomposed {
227
- functions: Record<string, ts.VariableStatement>;
228
- statements: ts.Statement[];
229
- arrow: ts.ArrowFunction;
230
- }
231
-
232
- export const compose = (props: {
233
- context: ITypiaContext;
234
- config: IConfig;
235
- functor: FunctionProgrammer;
236
- type: ts.Type;
237
- name: string | undefined;
238
- }): IComposed => {
239
- const [collection, metadata] = props.config.initializer(props);
240
- return {
241
- body: props.config.decoder({
242
- input: ValueFactory.INPUT(),
243
- metadata,
244
- explore: {
245
- tracable: props.config.path || props.config.trace,
246
- source: "top",
247
- from: "top",
248
- postfix: '""',
249
- },
250
- }),
251
- statements: props.config.addition
252
- ? props.config.addition(collection)
253
- : [],
254
- functions: {
255
- ...Object.fromEntries(
256
- (
257
- props.config.generator.objects?.(collection) ??
258
- write_object_functions({
259
- ...props,
260
- collection,
261
- })
262
- ).map((v, i) => [`${props.config.prefix}o${i}`, v]),
263
- ),
264
- ...Object.fromEntries(
265
- (
266
- props.config.generator.unions?.(collection) ??
267
- write_union_functions({
268
- config: props.config,
269
- collection,
270
- })
271
- ).map((v, i) => [`${props.config.prefix}u${i}`, v]),
272
- ),
273
- ...Object.fromEntries(
274
- props.config.generator
275
- .arrays(collection)
276
- .map((v, i) => [`${props.config.prefix}a${i}`, v]),
277
- ),
278
- ...Object.fromEntries(
279
- props.config.generator
280
- .tuples(collection)
281
- .map((v, i) => [`${props.config.prefix}t${i}`, v]),
282
- ),
283
- },
284
- parameters: parameterDeclarations({
285
- config: props.config,
286
- type: props.config.types.input(props.type, props.name),
287
- input: ValueFactory.INPUT(),
288
- }),
289
- response: props.config.types.output(props.type, props.name),
290
- };
291
- };
292
-
293
- export const writeDecomposed = (props: {
294
- modulo: ts.LeftHandSideExpression;
295
- functor: FunctionProgrammer;
296
- result: IDecomposed;
297
- }): ts.CallExpression =>
298
- ts.factory.createCallExpression(
299
- ts.factory.createArrowFunction(
300
- undefined,
301
- undefined,
302
- [],
303
- undefined,
304
- undefined,
305
- ts.factory.createBlock([
306
- ...props.functor.declare(),
307
- ...Object.entries(props.result.functions)
308
- .filter(([k]) => props.functor.hasLocal(k))
309
- .map(([_k, v]) => v),
310
- ...props.result.statements,
311
- ts.factory.createReturnStatement(props.result.arrow),
312
- ]),
313
- ),
314
- undefined,
315
- undefined,
316
- );
317
-
318
- export const write = (props: {
319
- context: ITypiaContext;
320
- config: IConfig;
321
- functor: FunctionProgrammer;
322
- type: ts.Type;
323
- name?: string | undefined;
324
- }): ts.ArrowFunction => {
325
- // ITERATE OVER ALL METADATA
326
- const [collection, metadata] = props.config.initializer(props);
327
- const output: ts.ConciseBody = props.config.decoder({
328
- metadata,
329
- input: ValueFactory.INPUT(),
330
- explore: {
331
- tracable: props.config.path || props.config.trace,
332
- source: "top",
333
- from: "top",
334
- postfix: '""',
335
- },
336
- });
337
-
338
- // RETURNS THE OPTIMAL ARROW FUNCTION
339
- const functions = {
340
- objects:
341
- props.config.generator.objects?.(collection) ??
342
- write_object_functions({
343
- config: props.config,
344
- context: props.context,
345
- collection,
346
- }),
347
- unions:
348
- props.config.generator.unions?.(collection) ??
349
- write_union_functions({
350
- config: props.config,
351
- collection,
352
- }),
353
- arrays: props.config.generator.arrays(collection),
354
- tuples: props.config.generator.tuples(collection),
355
- };
356
- const added: ts.Statement[] = (props.config.addition ?? (() => []))(
357
- collection,
358
- );
359
-
360
- return ts.factory.createArrowFunction(
361
- undefined,
362
- undefined,
363
- parameterDeclarations({
364
- config: props.config,
365
- type: props.config.types.input(props.type, props.name),
366
- input: ValueFactory.INPUT(),
367
- }),
368
- props.config.types.output(props.type, props.name),
369
- undefined,
370
- ts.factory.createBlock(
371
- [
372
- ...added,
373
- ...functions.objects.filter((_, i) =>
374
- props.functor.hasLocal(`${props.config.prefix}o${i}`),
375
- ),
376
- ...functions.unions.filter((_, i) =>
377
- props.functor.hasLocal(`${props.config.prefix}u${i}`),
378
- ),
379
- ...functions.arrays.filter((_, i) =>
380
- props.functor.hasLocal(`${props.config.prefix}a${i}`),
381
- ),
382
- ...functions.tuples.filter((_, i) =>
383
- props.functor.hasLocal(`${props.config.prefix}t${i}`),
384
- ),
385
- ...(ts.isBlock(output)
386
- ? output.statements
387
- : [ts.factory.createReturnStatement(output)]),
388
- ],
389
- true,
390
- ),
391
- );
392
- };
393
-
394
- export const write_object_functions = (props: {
395
- config: IConfig;
396
- context: ITypiaContext;
397
- collection: MetadataCollection;
398
- }) =>
399
- props.collection.objects().map((object) =>
400
- StatementFactory.constant({
401
- name: `${props.config.prefix}o${object.index}`,
402
- value: ts.factory.createArrowFunction(
403
- undefined,
404
- undefined,
405
- parameterDeclarations({
406
- config: props.config,
407
- type: TypeFactory.keyword("any"),
408
- input: ValueFactory.INPUT(),
409
- }),
410
- props.config.objector.type ?? TypeFactory.keyword("any"),
411
- undefined,
412
- props.config.objector.joiner({
413
- input: ts.factory.createIdentifier("input"),
414
- entries: feature_object_entries({
415
- config: props.config,
416
- context: props.context,
417
- input: ts.factory.createIdentifier("input"),
418
- object,
419
- }),
420
- object,
421
- }),
422
- ),
423
- }),
424
- );
425
-
426
- export const write_union_functions = (props: {
427
- config: IConfig;
428
- collection: MetadataCollection;
429
- }) =>
430
- props.collection.unions().map((union, i) =>
431
- StatementFactory.constant({
432
- name: `${props.config.prefix}u${i}`,
433
- value: write_union({
434
- config: props.config,
435
- objects: union,
436
- }),
437
- }),
438
- );
439
-
440
- const write_union = (props: { config: IConfig; objects: MetadataObject[] }) =>
441
- ts.factory.createArrowFunction(
442
- undefined,
443
- undefined,
444
- parameterDeclarations({
445
- config: props.config,
446
- type: TypeFactory.keyword("any"),
447
- input: ValueFactory.INPUT(),
448
- }),
449
- TypeFactory.keyword("any"),
450
- undefined,
451
- UnionExplorer.object({
452
- config: props.config,
453
- objects: props.objects,
454
- input: ValueFactory.INPUT(),
455
- explore: {
456
- tracable: props.config.path || props.config.trace,
457
- source: "function",
458
- from: "object",
459
- postfix: "",
460
- },
461
- }),
462
- );
463
-
464
- /* -----------------------------------------------------------
465
- DECODERS
466
- ----------------------------------------------------------- */
467
- export const decode_array = (props: {
468
- config: Pick<IConfig, "trace" | "path" | "decoder" | "prefix">;
469
- functor: FunctionProgrammer;
470
- combiner: (next: {
471
- input: ts.Expression;
472
- arrow: ts.ArrowFunction;
473
- }) => ts.Expression;
474
- array: MetadataArray;
475
- input: ts.Expression;
476
- explore: IExplore;
477
- }) => {
478
- const rand: string = props.functor.increment().toString();
479
- const tail =
480
- props.config.path || props.config.trace
481
- ? [
482
- IdentifierFactory.parameter(
483
- "_index" + rand,
484
- TypeFactory.keyword("number"),
485
- ),
486
- ]
487
- : [];
488
- const arrow: ts.ArrowFunction = ts.factory.createArrowFunction(
489
- undefined,
490
- undefined,
491
- [
492
- IdentifierFactory.parameter("elem", TypeFactory.keyword("any")),
493
- ...tail,
494
- ],
495
- undefined,
496
- undefined,
497
- props.config.decoder({
498
- input: ValueFactory.INPUT("elem"),
499
- metadata: props.array.type.value,
500
- explore: {
501
- tracable: props.explore.tracable,
502
- source: props.explore.source,
503
- from: "array",
504
- postfix: index({
505
- start: props.explore.start ?? null,
506
- postfix: props.explore.postfix,
507
- rand,
508
- }),
509
- },
510
- }),
511
- );
512
- return props.combiner({
513
- input: props.input,
514
- arrow,
515
- });
516
- };
517
-
518
- export const decode_object = (props: {
519
- config: Pick<IConfig, "trace" | "path" | "prefix">;
520
- functor: FunctionProgrammer;
521
- object: MetadataObject;
522
- input: ts.Expression;
523
- explore: IExplore;
524
- }) =>
525
- ts.factory.createCallExpression(
526
- ts.factory.createIdentifier(
527
- props.functor.useLocal(`${props.config.prefix}o${props.object.index}`),
528
- ),
529
- undefined,
530
- argumentsArray(props),
531
- );
532
-
533
- /* -----------------------------------------------------------
534
- UTILITIES FOR INTERNAL FUNCTIONS
535
- ----------------------------------------------------------- */
536
- export const index = (props: {
537
- start: number | null;
538
- postfix: string;
539
- rand: string;
540
- }) => {
541
- const tail: string =
542
- props.start !== null
543
- ? `"[" + (${props.start} + _index${props.rand}) + "]"`
544
- : `"[" + _index${props.rand} + "]"`;
545
- if (props.postfix === "") return tail;
546
- else if (props.postfix[props.postfix.length - 1] === `"`)
547
- return (
548
- props.postfix.substring(0, props.postfix.length - 1) + tail.substring(1)
549
- );
550
- return props.postfix + ` + ${tail}`;
551
- };
552
-
553
- export const argumentsArray = (props: {
554
- config: Pick<IConfig, "path" | "trace">;
555
- input: ts.Expression;
556
- explore: FeatureProgrammer.IExplore;
557
- }) => {
558
- const tail: ts.Expression[] =
559
- props.config.path === false && props.config.trace === false
560
- ? []
561
- : props.config.path === true && props.config.trace === true
562
- ? [
563
- ts.factory.createIdentifier(
564
- props.explore.postfix
565
- ? `_path + ${props.explore.postfix}`
566
- : "_path",
567
- ),
568
- props.explore.source === "function"
569
- ? ts.factory.createIdentifier(
570
- `${props.explore.tracable} && _exceptionable`,
571
- )
572
- : props.explore.tracable
573
- ? ts.factory.createTrue()
574
- : ts.factory.createFalse(),
575
- ]
576
- : props.config.path === true
577
- ? [
578
- ts.factory.createIdentifier(
579
- props.explore.postfix
580
- ? `_path + ${props.explore.postfix}`
581
- : "_path",
582
- ),
583
- ]
584
- : [
585
- props.explore.source === "function"
586
- ? ts.factory.createIdentifier(
587
- `${props.explore.tracable} && _exceptionable`,
588
- )
589
- : props.explore.tracable
590
- ? ts.factory.createTrue()
591
- : ts.factory.createFalse(),
592
- ];
593
- return [props.input, ...tail];
594
- };
595
-
596
- export const parameterDeclarations = (props: {
597
- config: Pick<CheckerProgrammer.IConfig, "path" | "trace">;
598
- type: ts.TypeNode;
599
- input: ts.Identifier;
600
- }) => {
601
- const tail: ts.ParameterDeclaration[] = [];
602
- if (props.config.path)
603
- tail.push(
604
- IdentifierFactory.parameter("_path", TypeFactory.keyword("string")),
605
- );
606
- if (props.config.trace)
607
- tail.push(
608
- IdentifierFactory.parameter(
609
- "_exceptionable",
610
- TypeFactory.keyword("boolean"),
611
- ts.factory.createTrue(),
612
- ),
613
- );
614
- return [IdentifierFactory.parameter(props.input, props.type), ...tail];
615
- };
616
- }
1
+ import ts from "typescript";
2
+
3
+ import { IdentifierFactory } from "../factories/IdentifierFactory";
4
+ import { MetadataCollection } from "../factories/MetadataCollection";
5
+ import { StatementFactory } from "../factories/StatementFactory";
6
+ import { TypeFactory } from "../factories/TypeFactory";
7
+ import { ValueFactory } from "../factories/ValueFactory";
8
+
9
+ import { Metadata } from "../schemas/metadata/Metadata";
10
+ import { MetadataArray } from "../schemas/metadata/MetadataArray";
11
+ import { MetadataObject } from "../schemas/metadata/MetadataObject";
12
+
13
+ import { ITypiaContext } from "../transformers/ITypiaContext";
14
+
15
+ import { CheckerProgrammer } from "./CheckerProgrammer";
16
+ import { FunctionProgrammer } from "./helpers/FunctionProgrammer";
17
+ import { IExpressionEntry } from "./helpers/IExpressionEntry";
18
+ import { UnionExplorer } from "./helpers/UnionExplorer";
19
+ import { feature_object_entries } from "./internal/feature_object_entries";
20
+
21
+ export namespace FeatureProgrammer {
22
+ /* -----------------------------------------------------------
23
+ PARAMETERS
24
+ ----------------------------------------------------------- */
25
+ export interface IConfig<Output extends ts.ConciseBody = ts.ConciseBody> {
26
+ types: IConfig.ITypes;
27
+
28
+ /**
29
+ * Prefix name of internal functions for specific types.
30
+ */
31
+ prefix: string;
32
+
33
+ /**
34
+ * Whether to archive access path or not.
35
+ */
36
+ path: boolean;
37
+
38
+ /**
39
+ * Whether to trace exception or not.
40
+ */
41
+ trace: boolean;
42
+
43
+ addition?: undefined | ((collection: MetadataCollection) => ts.Statement[]);
44
+
45
+ /**
46
+ * Initializer of metadata.
47
+ */
48
+ initializer: (props: {
49
+ context: ITypiaContext;
50
+ functor: FunctionProgrammer;
51
+ type: ts.Type;
52
+ }) => {
53
+ collection: MetadataCollection;
54
+ metadata: Metadata;
55
+ };
56
+
57
+ /**
58
+ * Decoder, station of every types.
59
+ */
60
+ decoder: (props: {
61
+ metadata: Metadata;
62
+ input: ts.Expression;
63
+ explore: IExplore;
64
+ }) => Output;
65
+
66
+ /**
67
+ * Object configurator.
68
+ */
69
+ objector: IConfig.IObjector<Output>;
70
+
71
+ /**
72
+ * Generator of functions for object types.
73
+ */
74
+ generator: IConfig.IGenerator;
75
+ }
76
+ export namespace IConfig {
77
+ export interface ITypes {
78
+ input: (type: ts.Type, name?: undefined | string) => ts.TypeNode;
79
+ output: (type: ts.Type, name?: undefined | string) => ts.TypeNode;
80
+ }
81
+
82
+ export interface IObjector<Output extends ts.ConciseBody = ts.ConciseBody> {
83
+ /**
84
+ * Type checker when union object type comes.
85
+ */
86
+ checker: (props: {
87
+ metadata: Metadata;
88
+ input: ts.Expression;
89
+ explore: IExplore;
90
+ }) => ts.Expression;
91
+
92
+ /**
93
+ * Decoder, function call expression generator of specific typed objects.
94
+ */
95
+ decoder: (props: {
96
+ input: ts.Expression;
97
+ object: MetadataObject;
98
+ explore: IExplore;
99
+ }) => ts.Expression;
100
+
101
+ /**
102
+ * Joiner of expressions from properties.
103
+ */
104
+ joiner(props: {
105
+ entries: IExpressionEntry<Output>[];
106
+ input?: ts.Expression;
107
+ object?: MetadataObject;
108
+ }): ts.ConciseBody;
109
+
110
+ /**
111
+ * Union type specificator.
112
+ *
113
+ * Expression of an algorithm specifying object type and calling
114
+ * the `decoder` function of the specified object type.
115
+ */
116
+ unionizer: (props: {
117
+ objects: MetadataObject[];
118
+ input: ts.Expression;
119
+ explore: IExplore;
120
+ }) => ts.Expression;
121
+
122
+ /**
123
+ * Handler of union type specification failure.
124
+ *
125
+ * @param props Properties of failure
126
+ * @returns Statement of failure
127
+ */
128
+ failure(props: {
129
+ input: ts.Expression;
130
+ expected: string;
131
+ explore?: undefined | IExplore;
132
+ }): ts.Statement;
133
+
134
+ /**
135
+ * Transformer of type checking expression by discrimination.
136
+ *
137
+ * When an object type has been specified by a discrimination without full
138
+ * iteration, the `unionizer` will decode the object instance after
139
+ * the last type checking.
140
+ *
141
+ * In such circumtance, you can transform the last type checking function.
142
+ *
143
+ * @param exp Current expression about type checking
144
+ * @returns Transformed expression
145
+ * @deprecated
146
+ */
147
+ is?: undefined | ((exp: ts.Expression) => ts.Expression);
148
+
149
+ /**
150
+ * Transformer of non-undefined type checking by discrimination.
151
+ *
152
+ * When specifying an union type of objects, `typia` tries to find
153
+ * descrimination way just by checking only one property type.
154
+ * If succeeded to find the discrimination way, `typia` will check the target
155
+ * property type and in the checking, non-undefined type checking would be
156
+ * done.
157
+ *
158
+ * In such process, you can transform the non-undefined type checking.
159
+ *
160
+ * @param exp
161
+ * @returns Transformed expression
162
+ * @deprecated
163
+ */
164
+ required?: undefined | ((exp: ts.Expression) => ts.Expression);
165
+
166
+ /**
167
+ * Conditon wrapper when unable to specify any object type.
168
+ *
169
+ * When failed to specify an object type through discrimination, full
170
+ * iteration type checking would be happend. In such circumstance, you
171
+ * can wrap the condition with additional function.
172
+ *
173
+ * @param props Properties of condition
174
+ * @returns The wrapper expression
175
+ */
176
+ full?:
177
+ | undefined
178
+ | ((props: {
179
+ condition: ts.Expression;
180
+ input: ts.Expression;
181
+ expected: string;
182
+ explore: IExplore;
183
+ }) => ts.Expression);
184
+
185
+ /**
186
+ * Return type.
187
+ */
188
+ type?: undefined | ts.TypeNode;
189
+ }
190
+ export interface IGenerator {
191
+ objects?:
192
+ | undefined
193
+ | ((collection: MetadataCollection) => ts.VariableStatement[]);
194
+ unions?:
195
+ | undefined
196
+ | ((collection: MetadataCollection) => ts.VariableStatement[]);
197
+ arrays: (collection: MetadataCollection) => ts.VariableStatement[];
198
+ tuples: (collection: MetadataCollection) => ts.VariableStatement[];
199
+ }
200
+ }
201
+
202
+ export interface IExplore {
203
+ tracable: boolean;
204
+ source: "top" | "function";
205
+ from: "top" | "array" | "object";
206
+ postfix: string;
207
+ start?: undefined | number;
208
+ }
209
+
210
+ export type Decoder<
211
+ T,
212
+ Output extends ts.ConciseBody = ts.ConciseBody,
213
+ > = (props: {
214
+ input: ts.Expression;
215
+ definition: T;
216
+ explore: IExplore;
217
+ }) => Output;
218
+
219
+ /* -----------------------------------------------------------
220
+ GENERATORS
221
+ ----------------------------------------------------------- */
222
+ export interface IComposed {
223
+ body: ts.ConciseBody;
224
+ parameters: ts.ParameterDeclaration[];
225
+ functions: Record<string, ts.VariableStatement>;
226
+ statements: ts.Statement[];
227
+ response: ts.TypeNode;
228
+ }
229
+ export interface IDecomposed {
230
+ functions: Record<string, ts.VariableStatement>;
231
+ statements: ts.Statement[];
232
+ arrow: ts.ArrowFunction;
233
+ }
234
+
235
+ export const compose = (props: {
236
+ context: ITypiaContext;
237
+ config: IConfig;
238
+ functor: FunctionProgrammer;
239
+ type: ts.Type;
240
+ name: string | undefined;
241
+ }): IComposed => {
242
+ const { collection, metadata } = props.config.initializer(props);
243
+ return {
244
+ body: props.config.decoder({
245
+ input: ValueFactory.INPUT(),
246
+ metadata,
247
+ explore: {
248
+ tracable: props.config.path || props.config.trace,
249
+ source: "top",
250
+ from: "top",
251
+ postfix: '""',
252
+ },
253
+ }),
254
+ statements: props.config.addition
255
+ ? props.config.addition(collection)
256
+ : [],
257
+ functions: {
258
+ ...Object.fromEntries(
259
+ (
260
+ props.config.generator.objects?.(collection) ??
261
+ write_object_functions({
262
+ ...props,
263
+ collection,
264
+ })
265
+ ).map((v, i) => [`${props.config.prefix}o${i}`, v]),
266
+ ),
267
+ ...Object.fromEntries(
268
+ (
269
+ props.config.generator.unions?.(collection) ??
270
+ write_union_functions({
271
+ config: props.config,
272
+ collection,
273
+ })
274
+ ).map((v, i) => [`${props.config.prefix}u${i}`, v]),
275
+ ),
276
+ ...Object.fromEntries(
277
+ props.config.generator
278
+ .arrays(collection)
279
+ .map((v, i) => [`${props.config.prefix}a${i}`, v]),
280
+ ),
281
+ ...Object.fromEntries(
282
+ props.config.generator
283
+ .tuples(collection)
284
+ .map((v, i) => [`${props.config.prefix}t${i}`, v]),
285
+ ),
286
+ },
287
+ parameters: parameterDeclarations({
288
+ config: props.config,
289
+ type: props.config.types.input(props.type, props.name),
290
+ input: ValueFactory.INPUT(),
291
+ }),
292
+ response: props.config.types.output(props.type, props.name),
293
+ };
294
+ };
295
+
296
+ export const writeDecomposed = (props: {
297
+ modulo: ts.LeftHandSideExpression;
298
+ functor: FunctionProgrammer;
299
+ result: IDecomposed;
300
+ }): ts.CallExpression =>
301
+ ts.factory.createCallExpression(
302
+ ts.factory.createArrowFunction(
303
+ undefined,
304
+ undefined,
305
+ [],
306
+ undefined,
307
+ undefined,
308
+ ts.factory.createBlock([
309
+ ...props.functor.declare(),
310
+ ...Object.entries(props.result.functions)
311
+ .filter(([k]) => props.functor.hasLocal(k))
312
+ .map(([_k, v]) => v),
313
+ ...props.result.statements,
314
+ ts.factory.createReturnStatement(props.result.arrow),
315
+ ]),
316
+ ),
317
+ undefined,
318
+ undefined,
319
+ );
320
+
321
+ export const write = (props: {
322
+ context: ITypiaContext;
323
+ config: IConfig;
324
+ functor: FunctionProgrammer;
325
+ type: ts.Type;
326
+ name?: string | undefined;
327
+ }): ts.ArrowFunction => {
328
+ // ITERATE OVER ALL METADATA
329
+ const { collection, metadata } = props.config.initializer(props);
330
+ const output: ts.ConciseBody = props.config.decoder({
331
+ metadata,
332
+ input: ValueFactory.INPUT(),
333
+ explore: {
334
+ tracable: props.config.path || props.config.trace,
335
+ source: "top",
336
+ from: "top",
337
+ postfix: '""',
338
+ },
339
+ });
340
+
341
+ // RETURNS THE OPTIMAL ARROW FUNCTION
342
+ const functions = {
343
+ objects:
344
+ props.config.generator.objects?.(collection) ??
345
+ write_object_functions({
346
+ config: props.config,
347
+ context: props.context,
348
+ collection,
349
+ }),
350
+ unions:
351
+ props.config.generator.unions?.(collection) ??
352
+ write_union_functions({
353
+ config: props.config,
354
+ collection,
355
+ }),
356
+ arrays: props.config.generator.arrays(collection),
357
+ tuples: props.config.generator.tuples(collection),
358
+ };
359
+ const added: ts.Statement[] = (props.config.addition ?? (() => []))(
360
+ collection,
361
+ );
362
+
363
+ return ts.factory.createArrowFunction(
364
+ undefined,
365
+ undefined,
366
+ parameterDeclarations({
367
+ config: props.config,
368
+ type: props.config.types.input(props.type, props.name),
369
+ input: ValueFactory.INPUT(),
370
+ }),
371
+ props.config.types.output(props.type, props.name),
372
+ undefined,
373
+ ts.factory.createBlock(
374
+ [
375
+ ...added,
376
+ ...functions.objects.filter((_, i) =>
377
+ props.functor.hasLocal(`${props.config.prefix}o${i}`),
378
+ ),
379
+ ...functions.unions.filter((_, i) =>
380
+ props.functor.hasLocal(`${props.config.prefix}u${i}`),
381
+ ),
382
+ ...functions.arrays.filter((_, i) =>
383
+ props.functor.hasLocal(`${props.config.prefix}a${i}`),
384
+ ),
385
+ ...functions.tuples.filter((_, i) =>
386
+ props.functor.hasLocal(`${props.config.prefix}t${i}`),
387
+ ),
388
+ ...(ts.isBlock(output)
389
+ ? output.statements
390
+ : [ts.factory.createReturnStatement(output)]),
391
+ ],
392
+ true,
393
+ ),
394
+ );
395
+ };
396
+
397
+ export const write_object_functions = (props: {
398
+ config: IConfig;
399
+ context: ITypiaContext;
400
+ collection: MetadataCollection;
401
+ }) =>
402
+ props.collection.objects().map((object) =>
403
+ StatementFactory.constant({
404
+ name: `${props.config.prefix}o${object.index}`,
405
+ value: ts.factory.createArrowFunction(
406
+ undefined,
407
+ undefined,
408
+ parameterDeclarations({
409
+ config: props.config,
410
+ type: TypeFactory.keyword("any"),
411
+ input: ValueFactory.INPUT(),
412
+ }),
413
+ props.config.objector.type ?? TypeFactory.keyword("any"),
414
+ undefined,
415
+ props.config.objector.joiner({
416
+ input: ts.factory.createIdentifier("input"),
417
+ entries: feature_object_entries({
418
+ config: props.config,
419
+ context: props.context,
420
+ input: ts.factory.createIdentifier("input"),
421
+ object,
422
+ }),
423
+ object,
424
+ }),
425
+ ),
426
+ }),
427
+ );
428
+
429
+ export const write_union_functions = (props: {
430
+ config: IConfig;
431
+ collection: MetadataCollection;
432
+ }) =>
433
+ props.collection.unions().map((union, i) =>
434
+ StatementFactory.constant({
435
+ name: `${props.config.prefix}u${i}`,
436
+ value: write_union({
437
+ config: props.config,
438
+ objects: union,
439
+ }),
440
+ }),
441
+ );
442
+
443
+ const write_union = (props: { config: IConfig; objects: MetadataObject[] }) =>
444
+ ts.factory.createArrowFunction(
445
+ undefined,
446
+ undefined,
447
+ parameterDeclarations({
448
+ config: props.config,
449
+ type: TypeFactory.keyword("any"),
450
+ input: ValueFactory.INPUT(),
451
+ }),
452
+ TypeFactory.keyword("any"),
453
+ undefined,
454
+ UnionExplorer.object({
455
+ config: props.config,
456
+ objects: props.objects,
457
+ input: ValueFactory.INPUT(),
458
+ explore: {
459
+ tracable: props.config.path || props.config.trace,
460
+ source: "function",
461
+ from: "object",
462
+ postfix: "",
463
+ },
464
+ }),
465
+ );
466
+
467
+ /* -----------------------------------------------------------
468
+ DECODERS
469
+ ----------------------------------------------------------- */
470
+ export const decode_array = (props: {
471
+ config: Pick<IConfig, "trace" | "path" | "decoder" | "prefix">;
472
+ functor: FunctionProgrammer;
473
+ combiner: (next: {
474
+ input: ts.Expression;
475
+ arrow: ts.ArrowFunction;
476
+ }) => ts.Expression;
477
+ array: MetadataArray;
478
+ input: ts.Expression;
479
+ explore: IExplore;
480
+ }) => {
481
+ const rand: string = props.functor.increment().toString();
482
+ const tail =
483
+ props.config.path || props.config.trace
484
+ ? [
485
+ IdentifierFactory.parameter(
486
+ "_index" + rand,
487
+ TypeFactory.keyword("number"),
488
+ ),
489
+ ]
490
+ : [];
491
+ const arrow: ts.ArrowFunction = ts.factory.createArrowFunction(
492
+ undefined,
493
+ undefined,
494
+ [
495
+ IdentifierFactory.parameter("elem", TypeFactory.keyword("any")),
496
+ ...tail,
497
+ ],
498
+ undefined,
499
+ undefined,
500
+ props.config.decoder({
501
+ input: ValueFactory.INPUT("elem"),
502
+ metadata: props.array.type.value,
503
+ explore: {
504
+ tracable: props.explore.tracable,
505
+ source: props.explore.source,
506
+ from: "array",
507
+ postfix: index({
508
+ start: props.explore.start ?? null,
509
+ postfix: props.explore.postfix,
510
+ rand,
511
+ }),
512
+ },
513
+ }),
514
+ );
515
+ return props.combiner({
516
+ input: props.input,
517
+ arrow,
518
+ });
519
+ };
520
+
521
+ export const decode_object = (props: {
522
+ config: Pick<IConfig, "trace" | "path" | "prefix">;
523
+ functor: FunctionProgrammer;
524
+ object: MetadataObject;
525
+ input: ts.Expression;
526
+ explore: IExplore;
527
+ }) =>
528
+ ts.factory.createCallExpression(
529
+ ts.factory.createIdentifier(
530
+ props.functor.useLocal(`${props.config.prefix}o${props.object.index}`),
531
+ ),
532
+ undefined,
533
+ argumentsArray(props),
534
+ );
535
+
536
+ /* -----------------------------------------------------------
537
+ UTILITIES FOR INTERNAL FUNCTIONS
538
+ ----------------------------------------------------------- */
539
+ export const index = (props: {
540
+ start: number | null;
541
+ postfix: string;
542
+ rand: string;
543
+ }) => {
544
+ const tail: string =
545
+ props.start !== null
546
+ ? `"[" + (${props.start} + _index${props.rand}) + "]"`
547
+ : `"[" + _index${props.rand} + "]"`;
548
+ if (props.postfix === "") return tail;
549
+ else if (props.postfix[props.postfix.length - 1] === `"`)
550
+ return (
551
+ props.postfix.substring(0, props.postfix.length - 1) + tail.substring(1)
552
+ );
553
+ return props.postfix + ` + ${tail}`;
554
+ };
555
+
556
+ export const argumentsArray = (props: {
557
+ config: Pick<IConfig, "path" | "trace">;
558
+ input: ts.Expression;
559
+ explore: FeatureProgrammer.IExplore;
560
+ }) => {
561
+ const tail: ts.Expression[] =
562
+ props.config.path === false && props.config.trace === false
563
+ ? []
564
+ : props.config.path === true && props.config.trace === true
565
+ ? [
566
+ ts.factory.createIdentifier(
567
+ props.explore.postfix
568
+ ? `_path + ${props.explore.postfix}`
569
+ : "_path",
570
+ ),
571
+ props.explore.source === "function"
572
+ ? ts.factory.createIdentifier(
573
+ `${props.explore.tracable} && _exceptionable`,
574
+ )
575
+ : props.explore.tracable
576
+ ? ts.factory.createTrue()
577
+ : ts.factory.createFalse(),
578
+ ]
579
+ : props.config.path === true
580
+ ? [
581
+ ts.factory.createIdentifier(
582
+ props.explore.postfix
583
+ ? `_path + ${props.explore.postfix}`
584
+ : "_path",
585
+ ),
586
+ ]
587
+ : [
588
+ props.explore.source === "function"
589
+ ? ts.factory.createIdentifier(
590
+ `${props.explore.tracable} && _exceptionable`,
591
+ )
592
+ : props.explore.tracable
593
+ ? ts.factory.createTrue()
594
+ : ts.factory.createFalse(),
595
+ ];
596
+ return [props.input, ...tail];
597
+ };
598
+
599
+ export const parameterDeclarations = (props: {
600
+ config: Pick<CheckerProgrammer.IConfig, "path" | "trace">;
601
+ type: ts.TypeNode;
602
+ input: ts.Identifier;
603
+ }) => {
604
+ const tail: ts.ParameterDeclaration[] = [];
605
+ if (props.config.path)
606
+ tail.push(
607
+ IdentifierFactory.parameter("_path", TypeFactory.keyword("string")),
608
+ );
609
+ if (props.config.trace)
610
+ tail.push(
611
+ IdentifierFactory.parameter(
612
+ "_exceptionable",
613
+ TypeFactory.keyword("boolean"),
614
+ ts.factory.createTrue(),
615
+ ),
616
+ );
617
+ return [IdentifierFactory.parameter(props.input, props.type), ...tail];
618
+ };
619
+ }