typia 7.0.0-dev.20241002 → 7.0.0-dev.20241003

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 (117) hide show
  1. package/lib/factories/JsonMetadataFactory.js +4 -1
  2. package/lib/factories/JsonMetadataFactory.js.map +1 -1
  3. package/lib/factories/MetadataCollection.js +2 -2
  4. package/lib/factories/MetadataCollection.js.map +1 -1
  5. package/lib/factories/MetadataCommentTagFactory.js +284 -205
  6. package/lib/factories/MetadataCommentTagFactory.js.map +1 -1
  7. package/lib/factories/ProtobufFactory.js +4 -1
  8. package/lib/factories/ProtobufFactory.js.map +1 -1
  9. package/lib/programmers/AssertProgrammer.js +0 -24
  10. package/lib/programmers/AssertProgrammer.js.map +1 -1
  11. package/lib/programmers/CheckerProgrammer.js +9 -6
  12. package/lib/programmers/CheckerProgrammer.js.map +1 -1
  13. package/lib/programmers/RandomProgrammer.js +4 -1
  14. package/lib/programmers/RandomProgrammer.js.map +1 -1
  15. package/lib/programmers/functional/FunctionalAssertFunctionProgrammer.js +4 -1
  16. package/lib/programmers/functional/FunctionalAssertFunctionProgrammer.js.map +1 -1
  17. package/lib/programmers/functional/FunctionalAssertParametersProgrammer.js +0 -12
  18. package/lib/programmers/functional/FunctionalAssertParametersProgrammer.js.map +1 -1
  19. package/lib/programmers/functional/FunctionalIsReturnProgrammer.js +4 -1
  20. package/lib/programmers/functional/FunctionalIsReturnProgrammer.js.map +1 -1
  21. package/lib/programmers/functional/FunctionalValidateParametersProgrammer.js +4 -1
  22. package/lib/programmers/functional/FunctionalValidateParametersProgrammer.js.map +1 -1
  23. package/lib/programmers/functional/FunctionalValidateReturnProgrammer.js +4 -1
  24. package/lib/programmers/functional/FunctionalValidateReturnProgrammer.js.map +1 -1
  25. package/lib/programmers/helpers/UnionPredicator.js +1 -1
  26. package/lib/programmers/helpers/UnionPredicator.js.map +1 -1
  27. package/lib/programmers/http/HttpFormDataProgrammer.js +4 -1
  28. package/lib/programmers/http/HttpFormDataProgrammer.js.map +1 -1
  29. package/lib/programmers/http/HttpHeadersProgrammer.js +5 -2
  30. package/lib/programmers/http/HttpHeadersProgrammer.js.map +1 -1
  31. package/lib/programmers/http/HttpParameterProgrammer.js +4 -1
  32. package/lib/programmers/http/HttpParameterProgrammer.js.map +1 -1
  33. package/lib/programmers/http/HttpQueryProgrammer.js +4 -1
  34. package/lib/programmers/http/HttpQueryProgrammer.js.map +1 -1
  35. package/lib/programmers/misc/MiscCloneProgrammer.js +4 -1
  36. package/lib/programmers/misc/MiscCloneProgrammer.js.map +1 -1
  37. package/lib/programmers/misc/MiscLiteralsProgrammer.js +4 -1
  38. package/lib/programmers/misc/MiscLiteralsProgrammer.js.map +1 -1
  39. package/lib/programmers/misc/MiscPruneProgrammer.js +4 -1
  40. package/lib/programmers/misc/MiscPruneProgrammer.js.map +1 -1
  41. package/lib/programmers/notations/NotationGeneralProgrammer.js +24 -17
  42. package/lib/programmers/notations/NotationGeneralProgrammer.js.map +1 -1
  43. package/lib/programmers/protobuf/ProtobufMessageProgrammer.js +1 -1
  44. package/lib/programmers/protobuf/ProtobufMessageProgrammer.js.map +1 -1
  45. package/lib/transformers/CallExpressionTransformer.d.ts +4 -1
  46. package/lib/transformers/CallExpressionTransformer.js +30 -32
  47. package/lib/transformers/CallExpressionTransformer.js.map +1 -1
  48. package/lib/transformers/FileTransformer.js +36 -30
  49. package/lib/transformers/FileTransformer.js.map +1 -1
  50. package/lib/transformers/NodeTransformer.d.ts +4 -1
  51. package/lib/transformers/NodeTransformer.js +7 -6
  52. package/lib/transformers/NodeTransformer.js.map +1 -1
  53. package/lib/transformers/TransformerError.d.ts +4 -1
  54. package/lib/transformers/TransformerError.js +21 -23
  55. package/lib/transformers/TransformerError.js.map +1 -1
  56. package/lib/transformers/features/json/JsonApplicationTransformer.js +4 -1
  57. package/lib/transformers/features/json/JsonApplicationTransformer.js.map +1 -1
  58. package/lib/transformers/features/llm/LlmApplicationTransformer.js +4 -1
  59. package/lib/transformers/features/llm/LlmApplicationTransformer.js.map +1 -1
  60. package/lib/transformers/features/llm/LlmSchemaTransformer.js +4 -1
  61. package/lib/transformers/features/llm/LlmSchemaTransformer.js.map +1 -1
  62. package/lib/transformers/features/reflect/ReflectMetadataTransformer.js +4 -1
  63. package/lib/transformers/features/reflect/ReflectMetadataTransformer.js.map +1 -1
  64. package/lib/transformers/features/reflect/ReflectNameTransformer.js +4 -1
  65. package/lib/transformers/features/reflect/ReflectNameTransformer.js.map +1 -1
  66. package/lib/utils/MapUtil.d.ts +1 -1
  67. package/lib/utils/MapUtil.js +7 -9
  68. package/lib/utils/MapUtil.js.map +1 -1
  69. package/lib/utils/NameEncoder.d.ts +2 -2
  70. package/lib/utils/NameEncoder.js +4 -6
  71. package/lib/utils/NameEncoder.js.map +1 -1
  72. package/lib/utils/StringUtil/StringUtil.d.ts +5 -1
  73. package/lib/utils/StringUtil/StringUtil.js +8 -4
  74. package/lib/utils/StringUtil/StringUtil.js.map +1 -1
  75. package/package.json +1 -1
  76. package/src/factories/JsonMetadataFactory.ts +4 -1
  77. package/src/factories/MetadataCollection.ts +3 -2
  78. package/src/factories/MetadataCommentTagFactory.ts +212 -133
  79. package/src/factories/ProtobufFactory.ts +4 -3
  80. package/src/programmers/AssertProgrammer.ts +0 -24
  81. package/src/programmers/CheckerProgrammer.ts +9 -8
  82. package/src/programmers/RandomProgrammer.ts +4 -3
  83. package/src/programmers/functional/FunctionalAssertFunctionProgrammer.ts +4 -3
  84. package/src/programmers/functional/FunctionalAssertParametersProgrammer.ts +0 -12
  85. package/src/programmers/functional/FunctionalIsReturnProgrammer.ts +4 -3
  86. package/src/programmers/functional/FunctionalValidateParametersProgrammer.ts +4 -3
  87. package/src/programmers/functional/FunctionalValidateReturnProgrammer.ts +4 -3
  88. package/src/programmers/helpers/UnionPredicator.ts +1 -1
  89. package/src/programmers/http/HttpFormDataProgrammer.ts +4 -3
  90. package/src/programmers/http/HttpHeadersProgrammer.ts +5 -4
  91. package/src/programmers/http/HttpParameterProgrammer.ts +4 -1
  92. package/src/programmers/http/HttpQueryProgrammer.ts +4 -3
  93. package/src/programmers/misc/MiscCloneProgrammer.ts +4 -3
  94. package/src/programmers/misc/MiscLiteralsProgrammer.ts +4 -1
  95. package/src/programmers/misc/MiscPruneProgrammer.ts +4 -3
  96. package/src/programmers/notations/NotationGeneralProgrammer.ts +28 -20
  97. package/src/programmers/protobuf/ProtobufMessageProgrammer.ts +1 -1
  98. package/src/transformers/CallExpressionTransformer.ts +36 -36
  99. package/src/transformers/FileTransformer.ts +42 -32
  100. package/src/transformers/NodeTransformer.ts +10 -6
  101. package/src/transformers/TransformerError.ts +26 -27
  102. package/src/transformers/features/json/JsonApplicationTransformer.ts +4 -1
  103. package/src/transformers/features/llm/LlmApplicationTransformer.ts +4 -1
  104. package/src/transformers/features/llm/LlmSchemaTransformer.ts +4 -1
  105. package/src/transformers/features/reflect/ReflectMetadataTransformer.ts +4 -1
  106. package/src/transformers/features/reflect/ReflectNameTransformer.ts +4 -1
  107. package/src/utils/MapUtil.ts +11 -9
  108. package/src/utils/NameEncoder.ts +4 -4
  109. package/src/utils/StringUtil/StringUtil.ts +11 -4
  110. package/lib/functional/$varint.d.ts +0 -6
  111. package/lib/functional/$varint.js +0 -99
  112. package/lib/functional/$varint.js.map +0 -1
  113. package/lib/functional/$zigzag.d.ts +0 -4
  114. package/lib/functional/$zigzag.js +0 -35
  115. package/lib/functional/$zigzag.js.map +0 -1
  116. package/src/functional/$varint.ts +0 -130
  117. package/src/functional/$zigzag.ts +0 -39
@@ -276,9 +276,10 @@ export namespace CheckerProgrammer {
276
276
  type: next.type,
277
277
  });
278
278
  if (result.success === false)
279
- throw TransformerError.from(`typia.${next.importer.method}`)(
280
- result.errors,
281
- );
279
+ throw TransformerError.from({
280
+ code: `typia.${next.importer.method}`,
281
+ errors: result.errors,
282
+ });
282
283
  return [collection, result.data];
283
284
  },
284
285
  addition: props.config.addition,
@@ -827,15 +828,15 @@ export namespace CheckerProgrammer {
827
828
 
828
829
  if (instances.length) {
829
830
  const transformer =
830
- (merger: (x: ts.Expression, y: ts.Expression) => ts.Expression) =>
831
- (ins: IInstance) =>
832
- ins.body
831
+ (merge: (x: ts.Expression, y: ts.Expression) => ts.Expression) =>
832
+ (instance: IInstance) =>
833
+ instance.body
833
834
  ? {
834
- expression: merger(ins.head, ins.body),
835
+ expression: merge(instance.head, instance.body),
835
836
  combined: true,
836
837
  }
837
838
  : {
838
- expression: ins.head,
839
+ expression: instance.head,
839
840
  combined: false,
840
841
  };
841
842
  if (instances.length === 1)
@@ -69,9 +69,10 @@ export namespace RandomProgrammer {
69
69
  type: props.type,
70
70
  });
71
71
  if (result.success === false)
72
- throw TransformerError.from(`typia.${props.importer.method}`)(
73
- result.errors,
74
- );
72
+ throw TransformerError.from({
73
+ code: `typia.${props.importer.method}`,
74
+ errors: result.errors,
75
+ });
75
76
 
76
77
  // GENERATE FUNCTION
77
78
  const functions: Record<string, ts.VariableStatement> = Object.fromEntries([
@@ -81,9 +81,10 @@ export namespace FunctionalAssertFunctionProgrammer {
81
81
  name: string;
82
82
  variable: ts.VariableStatement;
83
83
  } => {
84
- const name: string = StringUtil.escapeDuplicate(
85
- props.parameters.map((p) => p.name.getText()),
86
- )("errorFactoryWrapper");
84
+ const name: string = StringUtil.escapeDuplicate({
85
+ keep: props.parameters.map((p) => p.name.getText()),
86
+ input: "errorFactoryWrapper",
87
+ });
87
88
  const variable: ts.VariableStatement = ts.factory.createVariableStatement(
88
89
  undefined,
89
90
  ts.factory.createVariableDeclarationList(
@@ -112,18 +112,6 @@ export namespace FunctionalAssertParametersProgrammer {
112
112
  replacer: `$input.parameters[${i}]`,
113
113
  }),
114
114
  }),
115
- // project)(modulo)(equals)(
116
- // p.type
117
- // ? project.checker.getTypeFromTypeNode(p.type)
118
- // : project.checker.getTypeFromTypeNode(TypeFactory.keyword("any")),
119
- // undefined,
120
- // FunctionalAssertFunctionProgrammer.hookPath({
121
- // wrapper: props.wrapper,
122
- // replacer: `$input.parameters[${i}]`,
123
- // }),
124
- // ),
125
- // undefined,
126
- // [ts.factory.createIdentifier(p.name.getText())],
127
115
  }),
128
116
  ),
129
117
  expressions: props.parameters.map((p, i) =>
@@ -75,9 +75,10 @@ export namespace FunctionalIsReturnProgrammer {
75
75
  ts.factory.createIdentifier(p.name.getText()),
76
76
  ),
77
77
  );
78
- const name: string = StringUtil.escapeDuplicate(
79
- props.declaration.parameters.map((p) => p.name.getText()),
80
- )("result");
78
+ const name: string = StringUtil.escapeDuplicate({
79
+ keep: props.declaration.parameters.map((p) => p.name.getText()),
80
+ input: "result",
81
+ });
81
82
  return {
82
83
  async,
83
84
  functions: [
@@ -101,9 +101,10 @@ export namespace FunctionalValidateParametersProgrammer {
101
101
  };
102
102
 
103
103
  export const decompose = (props: IDecomposeProps): IDecomposeOutput => {
104
- const resultName: string = StringUtil.escapeDuplicate(
105
- props.declaration.parameters.map((p) => p.name.getText()),
106
- )("paramErrorResults");
104
+ const resultName: string = StringUtil.escapeDuplicate({
105
+ keep: props.declaration.parameters.map((p) => p.name.getText()),
106
+ input: "paramErrorResults",
107
+ });
107
108
  const validationResultArray: ts.ArrayLiteralExpression =
108
109
  ts.factory.createArrayLiteralExpression(
109
110
  props.declaration.parameters.map((p, i) =>
@@ -76,9 +76,10 @@ export namespace FunctionalValidateReturnProgrammer {
76
76
  ),
77
77
  );
78
78
 
79
- const name: string = StringUtil.escapeDuplicate(
80
- props.declaration.parameters.map((p) => p.name.getText()),
81
- )("result");
79
+ const name: string = StringUtil.escapeDuplicate({
80
+ keep: props.declaration.parameters.map((p) => p.name.getText()),
81
+ input: "result",
82
+ });
82
83
  return {
83
84
  async,
84
85
  functions: [
@@ -20,7 +20,7 @@ export namespace UnionPredicator {
20
20
  for (const prop of obj.properties) {
21
21
  const key: string | null = prop.key.getSoleLiteral();
22
22
  if (key !== null)
23
- MapUtil.take(matrix)(key, () =>
23
+ MapUtil.take(matrix, key, () =>
24
24
  ArrayUtil.repeat(objects.length, () => null),
25
25
  );
26
26
  }
@@ -45,9 +45,10 @@ export namespace HttpFormDataProgrammer {
45
45
  type: props.type,
46
46
  });
47
47
  if (result.success === false)
48
- throw TransformerError.from(`typia.http.${props.importer.method}`)(
49
- result.errors,
50
- );
48
+ throw TransformerError.from({
49
+ code: `typia.http.${props.importer.method}`,
50
+ errors: result.errors,
51
+ });
51
52
 
52
53
  // DO TRANSFORM
53
54
  const object: MetadataObject = result.data.objects[0]!;
@@ -49,9 +49,10 @@ export namespace HttpHeadersProgrammer {
49
49
  type: props.type,
50
50
  });
51
51
  if (result.success === false)
52
- throw TransformerError.from(`typia.http.${props.importer.method}`)(
53
- result.errors,
54
- );
52
+ throw TransformerError.from({
53
+ code: `typia.http.${props.importer.method}`,
54
+ errors: result.errors,
55
+ });
55
56
 
56
57
  // DO TRANSFORM
57
58
  const object: MetadataObject = result.data.objects[0]!;
@@ -188,7 +189,7 @@ export namespace HttpHeadersProgrammer {
188
189
  const key: string | null = prop.key.getSoleLiteral();
189
190
  if (key === null) continue;
190
191
 
191
- MapUtil.take(counter)(key.toLowerCase(), () => new Set()).add(key);
192
+ MapUtil.take(counter, key.toLowerCase(), () => new Set()).add(key);
192
193
  }
193
194
  for (const [key, set] of counter)
194
195
  if (set.size > 1)
@@ -30,7 +30,10 @@ export namespace HttpParameterProgrammer {
30
30
  type: props.type,
31
31
  });
32
32
  if (result.success === false)
33
- throw TransformerError.from(props.modulo.getText())(result.errors);
33
+ throw TransformerError.from({
34
+ code: props.modulo.getText(),
35
+ errors: result.errors,
36
+ });
34
37
 
35
38
  const atomic = [...HttpMetadataUtil.atomics(result.data)][0]!;
36
39
  const importer: FunctionImporter = new FunctionImporter(
@@ -53,9 +53,10 @@ export namespace HttpQueryProgrammer {
53
53
  type: props.type,
54
54
  });
55
55
  if (result.success === false)
56
- throw TransformerError.from(`typia.http.${props.importer.method}`)(
57
- result.errors,
58
- );
56
+ throw TransformerError.from({
57
+ code: `typia.http.${props.importer.method}`,
58
+ errors: result.errors,
59
+ });
59
60
 
60
61
  // DO TRANSFORM
61
62
  const object: MetadataObject = result.data.objects[0]!;
@@ -977,9 +977,10 @@ export namespace MiscCloneProgrammer {
977
977
  type: props.type,
978
978
  });
979
979
  if (result.success === false)
980
- throw TransformerError.from(`typia.misc.${props.importer.method}`)(
981
- result.errors,
982
- );
980
+ throw TransformerError.from({
981
+ code: `typia.misc.${props.importer.method}`,
982
+ errors: result.errors,
983
+ });
983
984
  return [collection, result.data];
984
985
  };
985
986
 
@@ -39,7 +39,10 @@ export namespace MiscLiteralsProgrammer {
39
39
  type: props.type,
40
40
  });
41
41
  if (result.success === false)
42
- throw TransformerError.from(`typia.misc.literals`)(result.errors);
42
+ throw TransformerError.from({
43
+ code: `typia.misc.literals`,
44
+ errors: result.errors,
45
+ });
43
46
 
44
47
  const metadata: Metadata = result.data;
45
48
  const values: Set<Atomic.Type | null> = new Set([
@@ -684,9 +684,10 @@ export namespace MiscPruneProgrammer {
684
684
  type: props.type,
685
685
  });
686
686
  if (result.success === false)
687
- throw TransformerError.from(`typia.misc.${props.importer.method}`)(
688
- result.errors,
689
- );
687
+ throw TransformerError.from({
688
+ code: `typia.misc.${props.importer.method}`,
689
+ errors: result.errors,
690
+ });
690
691
  return [collection, result.data];
691
692
  };
692
693
 
@@ -722,19 +722,24 @@ export namespace NotationGeneralProgrammer {
722
722
  definitions: T[];
723
723
  explore: FeatureProgrammer.IExplore;
724
724
  }): ts.Expression => {
725
- const arrow =
726
- (parameters: ts.ParameterDeclaration[]) =>
727
- (explore: FeatureProgrammer.IExplore) =>
728
- (input: ts.Expression): ts.ArrowFunction =>
729
- props.factory({
730
- parameters,
731
- input,
732
- definitions: props.definitions,
733
- explore,
734
- });
725
+ const arrow = (next: {
726
+ parameters: ts.ParameterDeclaration[];
727
+ explore: FeatureProgrammer.IExplore;
728
+ input: ts.Expression;
729
+ }): ts.ArrowFunction =>
730
+ props.factory({
731
+ parameters: next.parameters,
732
+ definitions: props.definitions,
733
+ explore: next.explore,
734
+ input: next.input,
735
+ });
735
736
  if (props.definitions.every((e) => e.type.recursive === false))
736
737
  ts.factory.createCallExpression(
737
- arrow([])(props.explore)(props.input),
738
+ arrow({
739
+ parameters: [],
740
+ explore: props.explore,
741
+ input: props.input,
742
+ }),
738
743
  undefined,
739
744
  [],
740
745
  );
@@ -750,16 +755,18 @@ export namespace NotationGeneralProgrammer {
750
755
  props.config.prefix,
751
756
  props.definitions.map((e) => e.type.name).join(" | "),
752
757
  () =>
753
- arrow(
754
- FeatureProgrammer.parameterDeclarations({
758
+ arrow({
759
+ parameters: FeatureProgrammer.parameterDeclarations({
755
760
  config: props.config,
756
761
  type: TypeFactory.keyword("any"),
757
762
  input: ts.factory.createIdentifier("input"),
758
763
  }),
759
- )({
760
- ...arrayExplore,
761
- postfix: "",
762
- })(ts.factory.createIdentifier("input")),
764
+ explore: {
765
+ ...arrayExplore,
766
+ postfix: "",
767
+ },
768
+ input: ts.factory.createIdentifier("input"),
769
+ }),
763
770
  ),
764
771
  ),
765
772
  undefined,
@@ -904,9 +911,10 @@ export namespace NotationGeneralProgrammer {
904
911
  type: props.type,
905
912
  });
906
913
  if (result.success === false)
907
- throw TransformerError.from(`typia.misc.${props.importer.method}`)(
908
- result.errors,
909
- );
914
+ throw TransformerError.from({
915
+ code: `typia.misc.${props.importer.method}`,
916
+ errors: result.errors,
917
+ });
910
918
  return [collection, result.data];
911
919
  };
912
920
 
@@ -57,7 +57,7 @@ export namespace ProtobufMessageProgrammer {
57
57
  let hierarchies: Map<string, Hierarchy> = props.hierarchies;
58
58
  const accessors: string[] = props.object.name.split(".");
59
59
  accessors.forEach((access, i) => {
60
- const hierarchy: Hierarchy = MapUtil.take(hierarchies)(access, () => ({
60
+ const hierarchy: Hierarchy = MapUtil.take(hierarchies, access, () => ({
61
61
  key: access,
62
62
  object: null!,
63
63
  children: new Map(),
@@ -113,42 +113,42 @@ import { ReflectMetadataTransformer } from "./features/reflect/ReflectMetadataTr
113
113
  import { ReflectNameTransformer } from "./features/reflect/ReflectNameTransformer";
114
114
 
115
115
  export namespace CallExpressionTransformer {
116
- export const transform =
117
- (context: ITypiaContext) =>
118
- (expression: ts.CallExpression): ts.Expression | null => {
119
- //----
120
- // VALIDATIONS
121
- //----
122
- // SIGNATURE DECLARATION
123
- const declaration: ts.Declaration | undefined =
124
- context.checker.getResolvedSignature(expression)?.declaration;
125
- if (!declaration) return expression;
126
-
127
- // FILE PATH
128
- const location: string = path.resolve(
129
- declaration.getSourceFile().fileName,
130
- );
131
- if (isTarget(location) === false) return expression;
132
-
133
- //----
134
- // TRANSFORMATION
135
- //----
136
- // FUNCTION NAME
137
- const module: string = location.split(path.sep).at(-1)!.split(".")[0]!;
138
- const { name } = context.checker.getTypeAtLocation(declaration).symbol;
139
-
140
- // FIND TRANSFORMER
141
- const functor: (() => Task) | undefined = FUNCTORS[module]?.[name];
142
- if (functor === undefined) return expression;
143
-
144
- // RETURNS WITH TRANSFORMATION
145
- const result: ts.Expression | null = functor()({
146
- context,
147
- modulo: expression.expression,
148
- expression,
149
- });
150
- return result ?? expression;
151
- };
116
+ export const transform = (props: {
117
+ context: ITypiaContext;
118
+ expression: ts.CallExpression;
119
+ }): ts.Expression | null => {
120
+ //----
121
+ // VALIDATIONS
122
+ //----
123
+ // SIGNATURE DECLARATION
124
+ const declaration: ts.Declaration | undefined =
125
+ props.context.checker.getResolvedSignature(props.expression)?.declaration;
126
+ if (!declaration) return props.expression;
127
+
128
+ // FILE PATH
129
+ const location: string = path.resolve(declaration.getSourceFile().fileName);
130
+ if (isTarget(location) === false) return props.expression;
131
+
132
+ //----
133
+ // TRANSFORMATION
134
+ //----
135
+ // FUNCTION NAME
136
+ const module: string = location.split(path.sep).at(-1)!.split(".")[0]!;
137
+ const { name } =
138
+ props.context.checker.getTypeAtLocation(declaration).symbol;
139
+
140
+ // FIND TRANSFORMER
141
+ const functor: (() => Task) | undefined = FUNCTORS[module]?.[name];
142
+ if (functor === undefined) return props.expression;
143
+
144
+ // RETURNS WITH TRANSFORMATION
145
+ const result: ts.Expression | null = functor()({
146
+ context: props.context,
147
+ modulo: props.expression.expression,
148
+ expression: props.expression,
149
+ });
150
+ return result ?? props.expression;
151
+ };
152
152
 
153
153
  const isTarget = (location: string): boolean => {
154
154
  const files: string[] = Object.keys(FUNCTORS);
@@ -13,48 +13,58 @@ export namespace FileTransformer {
13
13
  (file: ts.SourceFile): ts.SourceFile => {
14
14
  if (file.isDeclarationFile) return file;
15
15
 
16
- const project: ITypiaContext = {
16
+ const context: ITypiaContext = {
17
17
  ...environments,
18
18
  transformer,
19
19
  };
20
- checkJsDocParsingMode.get(project, file);
20
+ checkJsDocParsingMode.get(context, file);
21
21
 
22
22
  return ts.visitEachChild(
23
23
  file,
24
- (node) => iterate_node(project)(node),
24
+ (node) =>
25
+ iterate_node({
26
+ context,
27
+ node,
28
+ }),
25
29
  transformer,
26
30
  );
27
31
  };
28
32
 
29
- const iterate_node =
30
- (project: ITypiaContext) =>
31
- (node: ts.Node): ts.Node =>
32
- ts.visitEachChild(
33
- try_transform_node(project)(node) ?? node,
34
- (child) => iterate_node(project)(child),
35
- project.transformer,
36
- );
33
+ const iterate_node = (props: {
34
+ context: ITypiaContext;
35
+ node: ts.Node;
36
+ }): ts.Node =>
37
+ ts.visitEachChild(
38
+ try_transform_node(props) ?? props.node,
39
+ (node) =>
40
+ iterate_node({
41
+ context: props.context,
42
+ node,
43
+ }),
44
+ props.context.transformer,
45
+ );
37
46
 
38
- const try_transform_node =
39
- (project: ITypiaContext) =>
40
- (node: ts.Node): ts.Node | null => {
41
- try {
42
- return NodeTransformer.transform(project)(node);
43
- } catch (exp) {
44
- // ONLY ACCEPT TRANSFORMER-ERROR
45
- if (!isTransformerError(exp)) throw exp;
47
+ const try_transform_node = (props: {
48
+ context: ITypiaContext;
49
+ node: ts.Node;
50
+ }): ts.Node | null => {
51
+ try {
52
+ return NodeTransformer.transform(props);
53
+ } catch (exp) {
54
+ // ONLY ACCEPT TRANSFORMER-ERROR
55
+ if (!isTransformerError(exp)) throw exp;
46
56
 
47
- // REPORT DIAGNOSTIC
48
- const diagnostic = ts.createDiagnosticForNode(node, {
49
- key: exp.code,
50
- category: ts.DiagnosticCategory.Error,
51
- message: exp.message,
52
- code: `(${exp.code})` as any,
53
- });
54
- project.extras.addDiagnostic(diagnostic);
55
- return null;
56
- }
57
- };
57
+ // REPORT DIAGNOSTIC
58
+ const diagnostic = ts.createDiagnosticForNode(props.node, {
59
+ key: exp.code,
60
+ category: ts.DiagnosticCategory.Error,
61
+ message: exp.message,
62
+ code: `(${exp.code})` as any,
63
+ });
64
+ props.context.extras.addDiagnostic(diagnostic);
65
+ return null;
66
+ }
67
+ };
58
68
  }
59
69
 
60
70
  const isTransformerError = (error: any): error is TransformerError =>
@@ -65,12 +75,12 @@ const isTransformerError = (error: any): error is TransformerError =>
65
75
  typeof error.message === "string";
66
76
 
67
77
  const checkJsDocParsingMode = new Singleton(
68
- (project: ITypiaContext, file: ts.SourceFile) => {
78
+ (context: ITypiaContext, file: ts.SourceFile) => {
69
79
  if (
70
80
  typeof file.jsDocParsingMode === "number" &&
71
81
  file.jsDocParsingMode !== 0
72
82
  ) {
73
- project.extras.addDiagnostic(
83
+ context.extras.addDiagnostic(
74
84
  ts.createDiagnosticForNode(file, {
75
85
  code: `(typia setup)` as any,
76
86
  key: "jsDocParsingMode",
@@ -4,10 +4,14 @@ import { CallExpressionTransformer } from "./CallExpressionTransformer";
4
4
  import { ITypiaContext } from "./ITypiaContext";
5
5
 
6
6
  export namespace NodeTransformer {
7
- export const transform =
8
- (project: ITypiaContext) =>
9
- (expression: ts.Node): ts.Node | null =>
10
- ts.isCallExpression(expression) && expression.parent
11
- ? CallExpressionTransformer.transform(project)(expression)
12
- : expression;
7
+ export const transform = (props: {
8
+ context: ITypiaContext;
9
+ node: ts.Node;
10
+ }): ts.Node | null =>
11
+ ts.isCallExpression(props.node) && props.node.parent
12
+ ? CallExpressionTransformer.transform({
13
+ context: props.context,
14
+ expression: props.node,
15
+ })
16
+ : props.node;
13
17
  }
@@ -23,33 +23,32 @@ export namespace TransformerError {
23
23
  message: string;
24
24
  }
25
25
 
26
- export const from =
27
- (method: string) =>
28
- (errors: MetadataFactory.IError[]): TransformerError => {
29
- const body: string = errors
30
- .map((e) => {
31
- const subject: string =
32
- e.explore.object === null
33
- ? ""
34
- : join(e.explore.object)(e.explore.property);
35
- const middle: string = e.explore.parameter
36
- ? `(parameter: ${JSON.stringify(e.explore.parameter)})`
37
- : e.explore.output
38
- ? "(return type)"
39
- : "";
40
- const type: string = `${subject.length ? `${subject}: ` : ""}${
41
- e.name
42
- }`;
43
- return `- ${type}${middle}\n${e.messages
44
- .map((msg) => ` - ${msg}`)
45
- .join("\n")}`;
46
- })
47
- .join("\n\n");
48
- return new TransformerError({
49
- code: method,
50
- message: `unsupported type detected\n\n${body}`,
51
- });
52
- };
26
+ export const from = (props: {
27
+ code: string;
28
+ errors: MetadataFactory.IError[];
29
+ }): TransformerError => {
30
+ const body: string = props.errors
31
+ .map((e) => {
32
+ const subject: string =
33
+ e.explore.object === null
34
+ ? ""
35
+ : join(e.explore.object)(e.explore.property);
36
+ const middle: string = e.explore.parameter
37
+ ? `(parameter: ${JSON.stringify(e.explore.parameter)})`
38
+ : e.explore.output
39
+ ? "(return type)"
40
+ : "";
41
+ const type: string = `${subject.length ? `${subject}: ` : ""}${e.name}`;
42
+ return `- ${type}${middle}\n${e.messages
43
+ .map((msg) => ` - ${msg}`)
44
+ .join("\n")}`;
45
+ })
46
+ .join("\n\n");
47
+ return new TransformerError({
48
+ code: props.code,
49
+ message: `unsupported type detected\n\n${body}`,
50
+ });
51
+ };
53
52
 
54
53
  const join = (object: MetadataObject) => (key: string | object | null) => {
55
54
  if (key === null) return object.name;
@@ -83,7 +83,10 @@ export namespace JsonApplicationTransformer {
83
83
  else metadatas.push(r.data);
84
84
  }
85
85
  if (errors.length)
86
- throw TransformerError.from("typia.json.application")(errors);
86
+ throw TransformerError.from({
87
+ code: "typia.json.application",
88
+ errors,
89
+ });
87
90
 
88
91
  // APPLICATION
89
92
  const app: IJsonApplication<any> =
@@ -50,7 +50,10 @@ export namespace LlmApplicationTransformer {
50
50
  type,
51
51
  });
52
52
  if (result.success === false)
53
- throw TransformerError.from("typia.llm.application")(result.errors);
53
+ throw TransformerError.from({
54
+ code: "typia.llm.application",
55
+ errors: result.errors,
56
+ });
54
57
 
55
58
  // GENERATE LLM APPLICATION
56
59
  const schema: ILlmApplication = LlmApplicationProgrammer.write(result.data);
@@ -47,7 +47,10 @@ export namespace LlmSchemaTransformer {
47
47
  type,
48
48
  });
49
49
  if (result.success === false)
50
- throw TransformerError.from("typia.llm.schema")(result.errors);
50
+ throw TransformerError.from({
51
+ code: "typia.llm.schema",
52
+ errors: result.errors,
53
+ });
51
54
 
52
55
  // GENERATE LLM SCHEMA
53
56
  const schema: ILlmSchema = LlmSchemaProgrammer.write(result.data);