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.
- package/lib/factories/JsonMetadataFactory.js +4 -1
- package/lib/factories/JsonMetadataFactory.js.map +1 -1
- package/lib/factories/MetadataCollection.js +2 -2
- package/lib/factories/MetadataCollection.js.map +1 -1
- package/lib/factories/MetadataCommentTagFactory.js +284 -205
- package/lib/factories/MetadataCommentTagFactory.js.map +1 -1
- package/lib/factories/ProtobufFactory.js +4 -1
- package/lib/factories/ProtobufFactory.js.map +1 -1
- package/lib/programmers/AssertProgrammer.js +0 -24
- package/lib/programmers/AssertProgrammer.js.map +1 -1
- package/lib/programmers/CheckerProgrammer.js +9 -6
- package/lib/programmers/CheckerProgrammer.js.map +1 -1
- package/lib/programmers/RandomProgrammer.js +4 -1
- package/lib/programmers/RandomProgrammer.js.map +1 -1
- package/lib/programmers/functional/FunctionalAssertFunctionProgrammer.js +4 -1
- package/lib/programmers/functional/FunctionalAssertFunctionProgrammer.js.map +1 -1
- package/lib/programmers/functional/FunctionalAssertParametersProgrammer.js +0 -12
- package/lib/programmers/functional/FunctionalAssertParametersProgrammer.js.map +1 -1
- package/lib/programmers/functional/FunctionalIsReturnProgrammer.js +4 -1
- package/lib/programmers/functional/FunctionalIsReturnProgrammer.js.map +1 -1
- package/lib/programmers/functional/FunctionalValidateParametersProgrammer.js +4 -1
- package/lib/programmers/functional/FunctionalValidateParametersProgrammer.js.map +1 -1
- package/lib/programmers/functional/FunctionalValidateReturnProgrammer.js +4 -1
- package/lib/programmers/functional/FunctionalValidateReturnProgrammer.js.map +1 -1
- package/lib/programmers/helpers/UnionPredicator.js +1 -1
- package/lib/programmers/helpers/UnionPredicator.js.map +1 -1
- package/lib/programmers/http/HttpFormDataProgrammer.js +4 -1
- package/lib/programmers/http/HttpFormDataProgrammer.js.map +1 -1
- package/lib/programmers/http/HttpHeadersProgrammer.js +5 -2
- package/lib/programmers/http/HttpHeadersProgrammer.js.map +1 -1
- package/lib/programmers/http/HttpParameterProgrammer.js +4 -1
- package/lib/programmers/http/HttpParameterProgrammer.js.map +1 -1
- package/lib/programmers/http/HttpQueryProgrammer.js +4 -1
- package/lib/programmers/http/HttpQueryProgrammer.js.map +1 -1
- package/lib/programmers/misc/MiscCloneProgrammer.js +4 -1
- package/lib/programmers/misc/MiscCloneProgrammer.js.map +1 -1
- package/lib/programmers/misc/MiscLiteralsProgrammer.js +4 -1
- package/lib/programmers/misc/MiscLiteralsProgrammer.js.map +1 -1
- package/lib/programmers/misc/MiscPruneProgrammer.js +4 -1
- package/lib/programmers/misc/MiscPruneProgrammer.js.map +1 -1
- package/lib/programmers/notations/NotationGeneralProgrammer.js +24 -17
- package/lib/programmers/notations/NotationGeneralProgrammer.js.map +1 -1
- package/lib/programmers/protobuf/ProtobufMessageProgrammer.js +1 -1
- package/lib/programmers/protobuf/ProtobufMessageProgrammer.js.map +1 -1
- package/lib/transformers/CallExpressionTransformer.d.ts +4 -1
- package/lib/transformers/CallExpressionTransformer.js +30 -32
- package/lib/transformers/CallExpressionTransformer.js.map +1 -1
- package/lib/transformers/FileTransformer.js +36 -30
- package/lib/transformers/FileTransformer.js.map +1 -1
- package/lib/transformers/NodeTransformer.d.ts +4 -1
- package/lib/transformers/NodeTransformer.js +7 -6
- package/lib/transformers/NodeTransformer.js.map +1 -1
- package/lib/transformers/TransformerError.d.ts +4 -1
- package/lib/transformers/TransformerError.js +21 -23
- package/lib/transformers/TransformerError.js.map +1 -1
- package/lib/transformers/features/json/JsonApplicationTransformer.js +4 -1
- package/lib/transformers/features/json/JsonApplicationTransformer.js.map +1 -1
- package/lib/transformers/features/llm/LlmApplicationTransformer.js +4 -1
- package/lib/transformers/features/llm/LlmApplicationTransformer.js.map +1 -1
- package/lib/transformers/features/llm/LlmSchemaTransformer.js +4 -1
- package/lib/transformers/features/llm/LlmSchemaTransformer.js.map +1 -1
- package/lib/transformers/features/reflect/ReflectMetadataTransformer.js +4 -1
- package/lib/transformers/features/reflect/ReflectMetadataTransformer.js.map +1 -1
- package/lib/transformers/features/reflect/ReflectNameTransformer.js +4 -1
- package/lib/transformers/features/reflect/ReflectNameTransformer.js.map +1 -1
- package/lib/utils/MapUtil.d.ts +1 -1
- package/lib/utils/MapUtil.js +7 -9
- package/lib/utils/MapUtil.js.map +1 -1
- package/lib/utils/NameEncoder.d.ts +2 -2
- package/lib/utils/NameEncoder.js +4 -6
- package/lib/utils/NameEncoder.js.map +1 -1
- package/lib/utils/StringUtil/StringUtil.d.ts +5 -1
- package/lib/utils/StringUtil/StringUtil.js +8 -4
- package/lib/utils/StringUtil/StringUtil.js.map +1 -1
- package/package.json +1 -1
- package/src/factories/JsonMetadataFactory.ts +4 -1
- package/src/factories/MetadataCollection.ts +3 -2
- package/src/factories/MetadataCommentTagFactory.ts +212 -133
- package/src/factories/ProtobufFactory.ts +4 -3
- package/src/programmers/AssertProgrammer.ts +0 -24
- package/src/programmers/CheckerProgrammer.ts +9 -8
- package/src/programmers/RandomProgrammer.ts +4 -3
- package/src/programmers/functional/FunctionalAssertFunctionProgrammer.ts +4 -3
- package/src/programmers/functional/FunctionalAssertParametersProgrammer.ts +0 -12
- package/src/programmers/functional/FunctionalIsReturnProgrammer.ts +4 -3
- package/src/programmers/functional/FunctionalValidateParametersProgrammer.ts +4 -3
- package/src/programmers/functional/FunctionalValidateReturnProgrammer.ts +4 -3
- package/src/programmers/helpers/UnionPredicator.ts +1 -1
- package/src/programmers/http/HttpFormDataProgrammer.ts +4 -3
- package/src/programmers/http/HttpHeadersProgrammer.ts +5 -4
- package/src/programmers/http/HttpParameterProgrammer.ts +4 -1
- package/src/programmers/http/HttpQueryProgrammer.ts +4 -3
- package/src/programmers/misc/MiscCloneProgrammer.ts +4 -3
- package/src/programmers/misc/MiscLiteralsProgrammer.ts +4 -1
- package/src/programmers/misc/MiscPruneProgrammer.ts +4 -3
- package/src/programmers/notations/NotationGeneralProgrammer.ts +28 -20
- package/src/programmers/protobuf/ProtobufMessageProgrammer.ts +1 -1
- package/src/transformers/CallExpressionTransformer.ts +36 -36
- package/src/transformers/FileTransformer.ts +42 -32
- package/src/transformers/NodeTransformer.ts +10 -6
- package/src/transformers/TransformerError.ts +26 -27
- package/src/transformers/features/json/JsonApplicationTransformer.ts +4 -1
- package/src/transformers/features/llm/LlmApplicationTransformer.ts +4 -1
- package/src/transformers/features/llm/LlmSchemaTransformer.ts +4 -1
- package/src/transformers/features/reflect/ReflectMetadataTransformer.ts +4 -1
- package/src/transformers/features/reflect/ReflectNameTransformer.ts +4 -1
- package/src/utils/MapUtil.ts +11 -9
- package/src/utils/NameEncoder.ts +4 -4
- package/src/utils/StringUtil/StringUtil.ts +11 -4
- package/lib/functional/$varint.d.ts +0 -6
- package/lib/functional/$varint.js +0 -99
- package/lib/functional/$varint.js.map +0 -1
- package/lib/functional/$zigzag.d.ts +0 -4
- package/lib/functional/$zigzag.js +0 -35
- package/lib/functional/$zigzag.js.map +0 -1
- package/src/functional/$varint.ts +0 -130
- 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(
|
|
280
|
-
|
|
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
|
-
(
|
|
831
|
-
(
|
|
832
|
-
|
|
831
|
+
(merge: (x: ts.Expression, y: ts.Expression) => ts.Expression) =>
|
|
832
|
+
(instance: IInstance) =>
|
|
833
|
+
instance.body
|
|
833
834
|
? {
|
|
834
|
-
expression:
|
|
835
|
+
expression: merge(instance.head, instance.body),
|
|
835
836
|
combined: true,
|
|
836
837
|
}
|
|
837
838
|
: {
|
|
838
|
-
expression:
|
|
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(
|
|
73
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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(
|
|
49
|
-
|
|
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(
|
|
53
|
-
|
|
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
|
|
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(
|
|
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(
|
|
57
|
-
|
|
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(
|
|
981
|
-
|
|
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(
|
|
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(
|
|
688
|
-
|
|
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
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
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(
|
|
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
|
-
|
|
761
|
-
|
|
762
|
-
|
|
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(
|
|
908
|
-
|
|
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
|
|
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
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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
|
|
16
|
+
const context: ITypiaContext = {
|
|
17
17
|
...environments,
|
|
18
18
|
transformer,
|
|
19
19
|
};
|
|
20
|
-
checkJsDocParsingMode.get(
|
|
20
|
+
checkJsDocParsingMode.get(context, file);
|
|
21
21
|
|
|
22
22
|
return ts.visitEachChild(
|
|
23
23
|
file,
|
|
24
|
-
(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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
(
|
|
78
|
+
(context: ITypiaContext, file: ts.SourceFile) => {
|
|
69
79
|
if (
|
|
70
80
|
typeof file.jsDocParsingMode === "number" &&
|
|
71
81
|
file.jsDocParsingMode !== 0
|
|
72
82
|
) {
|
|
73
|
-
|
|
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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(
|
|
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(
|
|
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(
|
|
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);
|