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
@@ -475,7 +475,12 @@ export namespace RandomProgrammer {
475
475
  ? application_bigint<"3.1">(props.atomic)
476
476
  : application_number<"3.1">(props.atomic);
477
477
  return schemaList.map((schema) => {
478
- const { method, internal } = (() => {
478
+ interface IComposed {
479
+ method: string;
480
+ internal: string;
481
+ arguments: ts.Expression[];
482
+ }
483
+ const composed = ((): IComposed => {
479
484
  if (props.atomic.type === "string") {
480
485
  const string: OpenApi.IJsonSchema.IString =
481
486
  schema as OpenApi.IJsonSchema.IString;
@@ -485,6 +490,7 @@ export namespace RandomProgrammer {
485
490
  return {
486
491
  method: "datetime",
487
492
  internal: "randomFormatDatetime",
493
+ arguments: [],
488
494
  };
489
495
  return {
490
496
  method: format
@@ -495,11 +501,23 @@ export namespace RandomProgrammer {
495
501
  .split("-")
496
502
  .map(StringUtil.capitalize)
497
503
  .join("")}`,
504
+ arguments: [],
498
505
  };
499
506
  } else if (string.pattern !== undefined)
500
507
  return {
501
508
  method: "pattern",
502
509
  internal: "randomPattern",
510
+ arguments: [
511
+ ts.factory.createNewExpression(
512
+ ts.factory.createIdentifier("RegExp"),
513
+ undefined,
514
+ [
515
+ ts.factory.createStringLiteral(
516
+ (schema as OpenApi.IJsonSchema.IString).pattern!,
517
+ ),
518
+ ],
519
+ ),
520
+ ],
503
521
  };
504
522
  } else if (props.atomic.type === "number") {
505
523
  const number:
@@ -511,11 +529,13 @@ export namespace RandomProgrammer {
511
529
  return {
512
530
  method: "integer",
513
531
  internal: "randomInteger",
532
+ arguments: [LiteralFactory.write(schema)],
514
533
  };
515
534
  }
516
535
  return {
517
536
  method: props.atomic.type,
518
537
  internal: `random${StringUtil.capitalize(props.atomic.type)}`,
538
+ arguments: [LiteralFactory.write(schema)],
519
539
  };
520
540
  })();
521
541
  return ts.factory.createCallExpression(
@@ -523,24 +543,12 @@ export namespace RandomProgrammer {
523
543
  ts.factory.createPropertyAccessChain(
524
544
  ts.factory.createIdentifier("_generator"),
525
545
  ts.factory.createToken(ts.SyntaxKind.QuestionDotToken),
526
- ts.factory.createIdentifier(method),
546
+ ts.factory.createIdentifier(composed.method),
527
547
  ),
528
- props.context.importer.internal(internal),
548
+ props.context.importer.internal(composed.internal),
529
549
  ),
530
550
  undefined,
531
- [
532
- method === "pattern"
533
- ? ts.factory.createNewExpression(
534
- ts.factory.createIdentifier("RegExp"),
535
- undefined,
536
- [
537
- ts.factory.createStringLiteral(
538
- (schema as OpenApi.IJsonSchema.IString).pattern!,
539
- ),
540
- ],
541
- )
542
- : LiteralFactory.write(schema),
543
- ],
551
+ composed.arguments,
544
552
  );
545
553
  });
546
554
  };
@@ -71,7 +71,10 @@ export namespace TypiaProgrammer {
71
71
  path.resolve(file.fileName).indexOf(location.input) !== -1,
72
72
  ),
73
73
  [
74
- ImportTransformer.transform(location.input)(location.output),
74
+ ImportTransformer.transform({
75
+ from: location.input,
76
+ to: location.output,
77
+ }),
75
78
  transform(
76
79
  program,
77
80
  ((compilerOptions.plugins as any[]) ?? []).find(
@@ -1,153 +1,153 @@
1
- import ts from "typescript";
2
-
3
- import { ExpressionFactory } from "../../factories/ExpressionFactory";
4
- import { IdentifierFactory } from "../../factories/IdentifierFactory";
5
-
6
- import { ITypiaContext } from "../../transformers/ITypiaContext";
7
-
8
- import { StringUtil } from "../../utils/StringUtil";
9
-
10
- import { AssertProgrammer } from "../AssertProgrammer";
11
- import { FunctionalAssertParametersProgrammer } from "./FunctionalAssertParametersProgrammer";
12
- import { FunctionAssertReturnProgrammer } from "./FunctionalAssertReturnProgrammer";
13
-
14
- export namespace FunctionalAssertFunctionProgrammer {
15
- export interface IConfig {
16
- equals: boolean;
17
- }
18
- export interface IProps {
19
- context: ITypiaContext;
20
- modulo: ts.LeftHandSideExpression;
21
- config: IConfig;
22
- declaration: ts.FunctionDeclaration;
23
- expression: ts.Expression;
24
- init?: ts.Expression | undefined;
25
- }
26
-
27
- export const write = (props: IProps): ts.CallExpression => {
28
- const wrapper = errorFactoryWrapper({
29
- context: props.context,
30
- parameters: props.declaration.parameters,
31
- init: props.init,
32
- });
33
- const p = FunctionalAssertParametersProgrammer.decompose({
34
- context: props.context,
35
- modulo: props.modulo,
36
- config: props.config,
37
- parameters: props.declaration.parameters,
38
- wrapper: wrapper.name,
39
- });
40
- const r = FunctionAssertReturnProgrammer.decompose({
41
- context: props.context,
42
- modulo: props.modulo,
43
- config: props.config,
44
- expression: props.expression,
45
- declaration: props.declaration,
46
- wrapper: wrapper.name,
47
- });
48
- return ExpressionFactory.selfCall(
49
- ts.factory.createBlock(
50
- [
51
- wrapper.variable,
52
- ...p.functions,
53
- ...r.functions,
54
- ts.factory.createReturnStatement(
55
- ts.factory.createArrowFunction(
56
- r.async
57
- ? [ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword)]
58
- : undefined,
59
- undefined,
60
- props.declaration.parameters,
61
- props.declaration.type,
62
- undefined,
63
- ts.factory.createBlock([
64
- ...p.expressions.map(ts.factory.createExpressionStatement),
65
- ts.factory.createReturnStatement(r.value),
66
- ]),
67
- ),
68
- ),
69
- ],
70
- true,
71
- ),
72
- );
73
- };
74
-
75
- export const errorFactoryWrapper = (props: {
76
- context: ITypiaContext;
77
- parameters: readonly ts.ParameterDeclaration[];
78
- init: ts.Expression | undefined;
79
- }): {
80
- name: string;
81
- variable: ts.VariableStatement;
82
- } => {
83
- const name: string = StringUtil.escapeDuplicate({
84
- keep: props.parameters.map((p) => p.name.getText()),
85
- input: "errorFactoryWrapper",
86
- });
87
- const variable: ts.VariableStatement = ts.factory.createVariableStatement(
88
- undefined,
89
- ts.factory.createVariableDeclarationList(
90
- [
91
- ts.factory.createVariableDeclaration(
92
- name,
93
- undefined,
94
- AssertProgrammer.Guardian.type(props.context),
95
- props.init ??
96
- props.context.importer.internal(
97
- "functionalTypeGuardErrorFactory",
98
- ),
99
- ),
100
- ],
101
- ts.NodeFlags.Const,
102
- ),
103
- );
104
- return { name, variable };
105
- };
106
-
107
- export const hookPath = (props: {
108
- wrapper: string;
109
- replacer: string;
110
- }): ts.ArrowFunction =>
111
- ts.factory.createArrowFunction(
112
- undefined,
113
- undefined,
114
- [IdentifierFactory.parameter("p")],
115
- undefined,
116
- undefined,
117
- ts.factory.createCallExpression(
118
- ts.factory.createIdentifier(props.wrapper),
119
- undefined,
120
- [
121
- ts.factory.createObjectLiteralExpression([
122
- ts.factory.createSpreadAssignment(ts.factory.createIdentifier("p")),
123
- ts.factory.createPropertyAssignment(
124
- "path",
125
- ts.factory.createConditionalExpression(
126
- ts.factory.createPropertyAccessExpression(
127
- ts.factory.createIdentifier("p"),
128
- "path",
129
- ),
130
- undefined,
131
- ts.factory.createCallExpression(
132
- ts.factory.createPropertyAccessExpression(
133
- ts.factory.createPropertyAccessExpression(
134
- ts.factory.createIdentifier("p"),
135
- "path",
136
- ),
137
- "replace",
138
- ),
139
- undefined,
140
- [
141
- ts.factory.createStringLiteral("$input"),
142
- ts.factory.createStringLiteral(props.replacer),
143
- ],
144
- ),
145
- undefined,
146
- ts.factory.createIdentifier("undefined"),
147
- ),
148
- ),
149
- ]),
150
- ],
151
- ),
152
- );
153
- }
1
+ import ts from "typescript";
2
+
3
+ import { ExpressionFactory } from "../../factories/ExpressionFactory";
4
+ import { IdentifierFactory } from "../../factories/IdentifierFactory";
5
+
6
+ import { ITypiaContext } from "../../transformers/ITypiaContext";
7
+
8
+ import { StringUtil } from "../../utils/StringUtil";
9
+
10
+ import { AssertProgrammer } from "../AssertProgrammer";
11
+ import { FunctionalAssertParametersProgrammer } from "./FunctionalAssertParametersProgrammer";
12
+ import { FunctionAssertReturnProgrammer } from "./FunctionalAssertReturnProgrammer";
13
+
14
+ export namespace FunctionalAssertFunctionProgrammer {
15
+ export interface IConfig {
16
+ equals: boolean;
17
+ }
18
+ export interface IProps {
19
+ context: ITypiaContext;
20
+ modulo: ts.LeftHandSideExpression;
21
+ config: IConfig;
22
+ declaration: ts.FunctionDeclaration;
23
+ expression: ts.Expression;
24
+ init?: ts.Expression | undefined;
25
+ }
26
+
27
+ export const write = (props: IProps): ts.CallExpression => {
28
+ const wrapper = errorFactoryWrapper({
29
+ context: props.context,
30
+ parameters: props.declaration.parameters,
31
+ init: props.init,
32
+ });
33
+ const p = FunctionalAssertParametersProgrammer.decompose({
34
+ context: props.context,
35
+ modulo: props.modulo,
36
+ config: props.config,
37
+ parameters: props.declaration.parameters,
38
+ wrapper: wrapper.name,
39
+ });
40
+ const r = FunctionAssertReturnProgrammer.decompose({
41
+ context: props.context,
42
+ modulo: props.modulo,
43
+ config: props.config,
44
+ expression: props.expression,
45
+ declaration: props.declaration,
46
+ wrapper: wrapper.name,
47
+ });
48
+ return ExpressionFactory.selfCall(
49
+ ts.factory.createBlock(
50
+ [
51
+ wrapper.variable,
52
+ ...p.functions,
53
+ ...r.functions,
54
+ ts.factory.createReturnStatement(
55
+ ts.factory.createArrowFunction(
56
+ r.async
57
+ ? [ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword)]
58
+ : undefined,
59
+ undefined,
60
+ props.declaration.parameters,
61
+ props.declaration.type,
62
+ undefined,
63
+ ts.factory.createBlock([
64
+ ...p.expressions.map(ts.factory.createExpressionStatement),
65
+ ts.factory.createReturnStatement(r.value),
66
+ ]),
67
+ ),
68
+ ),
69
+ ],
70
+ true,
71
+ ),
72
+ );
73
+ };
74
+
75
+ export const errorFactoryWrapper = (props: {
76
+ context: ITypiaContext;
77
+ parameters: readonly ts.ParameterDeclaration[];
78
+ init: ts.Expression | undefined;
79
+ }): {
80
+ name: string;
81
+ variable: ts.VariableStatement;
82
+ } => {
83
+ const name: string = StringUtil.escapeDuplicate({
84
+ keep: props.parameters.map((p) => p.name.getText()),
85
+ input: "errorFactoryWrapper",
86
+ });
87
+ const variable: ts.VariableStatement = ts.factory.createVariableStatement(
88
+ undefined,
89
+ ts.factory.createVariableDeclarationList(
90
+ [
91
+ ts.factory.createVariableDeclaration(
92
+ name,
93
+ undefined,
94
+ AssertProgrammer.Guardian.type(props.context),
95
+ props.init ??
96
+ props.context.importer.internal(
97
+ "functionalTypeGuardErrorFactory",
98
+ ),
99
+ ),
100
+ ],
101
+ ts.NodeFlags.Const,
102
+ ),
103
+ );
104
+ return { name, variable };
105
+ };
106
+
107
+ export const hookPath = (props: {
108
+ wrapper: string;
109
+ replacer: string;
110
+ }): ts.ArrowFunction =>
111
+ ts.factory.createArrowFunction(
112
+ undefined,
113
+ undefined,
114
+ [IdentifierFactory.parameter("p")],
115
+ undefined,
116
+ undefined,
117
+ ts.factory.createCallExpression(
118
+ ts.factory.createIdentifier(props.wrapper),
119
+ undefined,
120
+ [
121
+ ts.factory.createObjectLiteralExpression([
122
+ ts.factory.createSpreadAssignment(ts.factory.createIdentifier("p")),
123
+ ts.factory.createPropertyAssignment(
124
+ "path",
125
+ ts.factory.createConditionalExpression(
126
+ ts.factory.createPropertyAccessExpression(
127
+ ts.factory.createIdentifier("p"),
128
+ "path",
129
+ ),
130
+ undefined,
131
+ ts.factory.createCallExpression(
132
+ ts.factory.createPropertyAccessExpression(
133
+ ts.factory.createPropertyAccessExpression(
134
+ ts.factory.createIdentifier("p"),
135
+ "path",
136
+ ),
137
+ "replace",
138
+ ),
139
+ undefined,
140
+ [
141
+ ts.factory.createStringLiteral("$input"),
142
+ ts.factory.createStringLiteral(props.replacer),
143
+ ],
144
+ ),
145
+ undefined,
146
+ ts.factory.createIdentifier("undefined"),
147
+ ),
148
+ ),
149
+ ]),
150
+ ],
151
+ ),
152
+ );
153
+ }
@@ -1,125 +1,125 @@
1
- import ts from "typescript";
2
-
3
- import { ExpressionFactory } from "../../factories/ExpressionFactory";
4
- import { StatementFactory } from "../../factories/StatementFactory";
5
- import { TypeFactory } from "../../factories/TypeFactory";
6
-
7
- import { ITypiaContext } from "../../transformers/ITypiaContext";
8
-
9
- import { AssertProgrammer } from "../AssertProgrammer";
10
- import { FunctionalAssertFunctionProgrammer } from "./FunctionalAssertFunctionProgrammer";
11
- import { FunctionalGeneralProgrammer } from "./internal/FunctionalGeneralProgrammer";
12
-
13
- export namespace FunctionalAssertParametersProgrammer {
14
- export interface IConfig {
15
- equals: boolean;
16
- }
17
- export interface IProps {
18
- context: ITypiaContext;
19
- modulo: ts.LeftHandSideExpression;
20
- config: IConfig;
21
- declaration: ts.FunctionDeclaration;
22
- expression: ts.Expression;
23
- init?: ts.Expression | undefined;
24
- }
25
- export interface IDecomposeProps {
26
- context: ITypiaContext;
27
- config: IConfig;
28
- modulo: ts.LeftHandSideExpression;
29
- parameters: readonly ts.ParameterDeclaration[];
30
- wrapper: string;
31
- }
32
- export interface IDecomposeOutput {
33
- functions: ts.Statement[];
34
- expressions: ts.Expression[];
35
- }
36
-
37
- export const write = (props: IProps): ts.CallExpression => {
38
- const wrapper = FunctionalAssertFunctionProgrammer.errorFactoryWrapper({
39
- context: props.context,
40
- parameters: props.declaration.parameters,
41
- init: props.init,
42
- });
43
- const { async } = FunctionalGeneralProgrammer.getReturnType({
44
- checker: props.context.checker,
45
- declaration: props.declaration,
46
- });
47
- const result = decompose({
48
- context: props.context,
49
- modulo: props.modulo,
50
- config: props.config,
51
- parameters: props.declaration.parameters,
52
- wrapper: wrapper.name,
53
- });
54
- return ExpressionFactory.selfCall(
55
- ts.factory.createBlock(
56
- [
57
- wrapper.variable,
58
- ...result.functions,
59
- ts.factory.createReturnStatement(
60
- ts.factory.createArrowFunction(
61
- async
62
- ? [ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword)]
63
- : undefined,
64
- undefined,
65
- props.declaration.parameters,
66
- props.declaration.type,
67
- undefined,
68
- ts.factory.createBlock(
69
- [
70
- ...result.expressions.map(
71
- ts.factory.createExpressionStatement,
72
- ),
73
- ts.factory.createReturnStatement(
74
- ts.factory.createCallExpression(
75
- props.expression,
76
- undefined,
77
- props.declaration.parameters.map((p) =>
78
- ts.factory.createIdentifier(p.name.getText()),
79
- ),
80
- ),
81
- ),
82
- ],
83
- true,
84
- ),
85
- ),
86
- ),
87
- ],
88
- true,
89
- ),
90
- );
91
- };
92
-
93
- export const decompose = (props: IDecomposeProps): IDecomposeOutput => ({
94
- functions: props.parameters.map((p, i) =>
95
- StatementFactory.constant({
96
- name: `__assert_param_${i}`,
97
- value: AssertProgrammer.write({
98
- context: props.context,
99
- modulo: props.modulo,
100
- config: {
101
- equals: props.config.equals,
102
- guard: false,
103
- },
104
- type: p.type
105
- ? props.context.checker.getTypeFromTypeNode(p.type)
106
- : props.context.checker.getTypeFromTypeNode(
107
- TypeFactory.keyword("any"),
108
- ),
109
- name: undefined,
110
- init: FunctionalAssertFunctionProgrammer.hookPath({
111
- wrapper: props.wrapper,
112
- replacer: `$input.parameters[${i}]`,
113
- }),
114
- }),
115
- }),
116
- ),
117
- expressions: props.parameters.map((p, i) =>
118
- ts.factory.createCallExpression(
119
- ts.factory.createIdentifier(`__assert_param_${i}`),
120
- undefined,
121
- [ts.factory.createIdentifier(p.name.getText())],
122
- ),
123
- ),
124
- });
125
- }
1
+ import ts from "typescript";
2
+
3
+ import { ExpressionFactory } from "../../factories/ExpressionFactory";
4
+ import { StatementFactory } from "../../factories/StatementFactory";
5
+ import { TypeFactory } from "../../factories/TypeFactory";
6
+
7
+ import { ITypiaContext } from "../../transformers/ITypiaContext";
8
+
9
+ import { AssertProgrammer } from "../AssertProgrammer";
10
+ import { FunctionalAssertFunctionProgrammer } from "./FunctionalAssertFunctionProgrammer";
11
+ import { FunctionalGeneralProgrammer } from "./internal/FunctionalGeneralProgrammer";
12
+
13
+ export namespace FunctionalAssertParametersProgrammer {
14
+ export interface IConfig {
15
+ equals: boolean;
16
+ }
17
+ export interface IProps {
18
+ context: ITypiaContext;
19
+ modulo: ts.LeftHandSideExpression;
20
+ config: IConfig;
21
+ declaration: ts.FunctionDeclaration;
22
+ expression: ts.Expression;
23
+ init?: ts.Expression | undefined;
24
+ }
25
+ export interface IDecomposeProps {
26
+ context: ITypiaContext;
27
+ config: IConfig;
28
+ modulo: ts.LeftHandSideExpression;
29
+ parameters: readonly ts.ParameterDeclaration[];
30
+ wrapper: string;
31
+ }
32
+ export interface IDecomposeOutput {
33
+ functions: ts.Statement[];
34
+ expressions: ts.Expression[];
35
+ }
36
+
37
+ export const write = (props: IProps): ts.CallExpression => {
38
+ const wrapper = FunctionalAssertFunctionProgrammer.errorFactoryWrapper({
39
+ context: props.context,
40
+ parameters: props.declaration.parameters,
41
+ init: props.init,
42
+ });
43
+ const { async } = FunctionalGeneralProgrammer.getReturnType({
44
+ checker: props.context.checker,
45
+ declaration: props.declaration,
46
+ });
47
+ const result = decompose({
48
+ context: props.context,
49
+ modulo: props.modulo,
50
+ config: props.config,
51
+ parameters: props.declaration.parameters,
52
+ wrapper: wrapper.name,
53
+ });
54
+ return ExpressionFactory.selfCall(
55
+ ts.factory.createBlock(
56
+ [
57
+ wrapper.variable,
58
+ ...result.functions,
59
+ ts.factory.createReturnStatement(
60
+ ts.factory.createArrowFunction(
61
+ async
62
+ ? [ts.factory.createModifier(ts.SyntaxKind.AsyncKeyword)]
63
+ : undefined,
64
+ undefined,
65
+ props.declaration.parameters,
66
+ props.declaration.type,
67
+ undefined,
68
+ ts.factory.createBlock(
69
+ [
70
+ ...result.expressions.map(
71
+ ts.factory.createExpressionStatement,
72
+ ),
73
+ ts.factory.createReturnStatement(
74
+ ts.factory.createCallExpression(
75
+ props.expression,
76
+ undefined,
77
+ props.declaration.parameters.map((p) =>
78
+ ts.factory.createIdentifier(p.name.getText()),
79
+ ),
80
+ ),
81
+ ),
82
+ ],
83
+ true,
84
+ ),
85
+ ),
86
+ ),
87
+ ],
88
+ true,
89
+ ),
90
+ );
91
+ };
92
+
93
+ export const decompose = (props: IDecomposeProps): IDecomposeOutput => ({
94
+ functions: props.parameters.map((p, i) =>
95
+ StatementFactory.constant({
96
+ name: `__assert_param_${i}`,
97
+ value: AssertProgrammer.write({
98
+ context: props.context,
99
+ modulo: props.modulo,
100
+ config: {
101
+ equals: props.config.equals,
102
+ guard: false,
103
+ },
104
+ type: p.type
105
+ ? props.context.checker.getTypeFromTypeNode(p.type)
106
+ : props.context.checker.getTypeFromTypeNode(
107
+ TypeFactory.keyword("any"),
108
+ ),
109
+ name: undefined,
110
+ init: FunctionalAssertFunctionProgrammer.hookPath({
111
+ wrapper: props.wrapper,
112
+ replacer: `$input.parameters[${i}]`,
113
+ }),
114
+ }),
115
+ }),
116
+ ),
117
+ expressions: props.parameters.map((p, i) =>
118
+ ts.factory.createCallExpression(
119
+ ts.factory.createIdentifier(`__assert_param_${i}`),
120
+ undefined,
121
+ [ts.factory.createIdentifier(p.name.getText())],
122
+ ),
123
+ ),
124
+ });
125
+ }