@typia/transform 12.0.0-dev.20260307-2 → 12.0.0-dev.20260310
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/CallExpressionTransformer.js +8 -0
- package/lib/CallExpressionTransformer.js.map +1 -1
- package/lib/CallExpressionTransformer.mjs +8 -0
- package/lib/CallExpressionTransformer.mjs.map +1 -1
- package/lib/features/json/JsonApplicationTransformer.js +3 -4
- package/lib/features/json/JsonApplicationTransformer.js.map +1 -1
- package/lib/features/json/JsonApplicationTransformer.mjs +4 -5
- package/lib/features/json/JsonApplicationTransformer.mjs.map +1 -1
- package/lib/features/json/JsonSchemaTransformer.js +2 -8
- package/lib/features/json/JsonSchemaTransformer.js.map +1 -1
- package/lib/features/json/JsonSchemaTransformer.mjs +3 -9
- package/lib/features/json/JsonSchemaTransformer.mjs.map +1 -1
- package/lib/features/json/JsonSchemasTransformer.js +2 -8
- package/lib/features/json/JsonSchemasTransformer.js.map +1 -1
- package/lib/features/json/JsonSchemasTransformer.mjs +3 -9
- package/lib/features/json/JsonSchemasTransformer.mjs.map +1 -1
- package/lib/features/llm/LlmApplicationTransformer.js +56 -20
- package/lib/features/llm/LlmApplicationTransformer.js.map +1 -1
- package/lib/features/llm/LlmApplicationTransformer.mjs +56 -20
- package/lib/features/llm/LlmApplicationTransformer.mjs.map +1 -1
- package/lib/features/llm/LlmCoerceTransformer.d.ts +5 -0
- package/lib/features/llm/LlmCoerceTransformer.js +81 -0
- package/lib/features/llm/LlmCoerceTransformer.js.map +1 -0
- package/lib/features/llm/LlmCoerceTransformer.mjs +77 -0
- package/lib/features/llm/LlmCoerceTransformer.mjs.map +1 -0
- package/lib/features/llm/LlmControllerTransformer.js +12 -10
- package/lib/features/llm/LlmControllerTransformer.js.map +1 -1
- package/lib/features/llm/LlmControllerTransformer.mjs +12 -10
- package/lib/features/llm/LlmControllerTransformer.mjs.map +1 -1
- package/lib/features/llm/LlmCreateCoerceTransformer.d.ts +5 -0
- package/lib/features/llm/LlmCreateCoerceTransformer.js +75 -0
- package/lib/features/llm/LlmCreateCoerceTransformer.js.map +1 -0
- package/lib/features/llm/LlmCreateCoerceTransformer.mjs +71 -0
- package/lib/features/llm/LlmCreateCoerceTransformer.mjs.map +1 -0
- package/lib/features/llm/LlmCreateParseTransformer.d.ts +5 -0
- package/lib/features/llm/LlmCreateParseTransformer.js +75 -0
- package/lib/features/llm/LlmCreateParseTransformer.js.map +1 -0
- package/lib/features/llm/LlmCreateParseTransformer.mjs +71 -0
- package/lib/features/llm/LlmCreateParseTransformer.mjs.map +1 -0
- package/lib/features/llm/LlmParametersTransformer.d.ts +1 -1
- package/lib/features/llm/LlmParametersTransformer.js +3 -6
- package/lib/features/llm/LlmParametersTransformer.js.map +1 -1
- package/lib/features/llm/LlmParametersTransformer.mjs +4 -7
- package/lib/features/llm/LlmParametersTransformer.mjs.map +1 -1
- package/lib/features/llm/LlmParseTransformer.d.ts +5 -0
- package/lib/features/llm/LlmParseTransformer.js +81 -0
- package/lib/features/llm/LlmParseTransformer.js.map +1 -0
- package/lib/features/llm/LlmParseTransformer.mjs +77 -0
- package/lib/features/llm/LlmParseTransformer.mjs.map +1 -0
- package/lib/features/llm/LlmSchemaTransformer.d.ts +1 -1
- package/lib/features/llm/LlmSchemaTransformer.js +10 -25
- package/lib/features/llm/LlmSchemaTransformer.js.map +1 -1
- package/lib/features/llm/LlmSchemaTransformer.mjs +11 -26
- package/lib/features/llm/LlmSchemaTransformer.mjs.map +1 -1
- package/package.json +4 -4
- package/src/CallExpressionTransformer.ts +579 -571
- package/src/FileTransformer.ts +143 -143
- package/src/ITransformProps.ts +20 -20
- package/src/ImportTransformer.ts +262 -262
- package/src/NodeTransformer.ts +25 -25
- package/src/TransformerError.ts +85 -85
- package/src/TypiaGenerator.ts +172 -172
- package/src/features/AssertTransformer.ts +24 -24
- package/src/features/CreateAssertTransformer.ts +24 -24
- package/src/features/CreateIsTransformer.ts +18 -18
- package/src/features/CreateRandomTransformer.ts +42 -42
- package/src/features/CreateValidateTransformer.ts +18 -18
- package/src/features/IsTransformer.ts +18 -18
- package/src/features/RandomTransformer.ts +40 -40
- package/src/features/ValidateTransformer.ts +18 -18
- package/src/features/functional/FunctionalGenericTransformer.ts +55 -55
- package/src/features/http/CreateHttpAssertFormDataTransformer.ts +13 -13
- package/src/features/http/CreateHttpAssertHeadersTransformer.ts +13 -13
- package/src/features/http/CreateHttpAssertQueryTransformer.ts +13 -13
- package/src/features/http/CreateHttpFormDataTransformer.ts +13 -13
- package/src/features/http/CreateHttpHeadersTransformer.ts +13 -13
- package/src/features/http/CreateHttpIsFormDataTransformer.ts +13 -13
- package/src/features/http/CreateHttpIsHeadersTransformer.ts +13 -13
- package/src/features/http/CreateHttpIsQueryTransformer.ts +13 -13
- package/src/features/http/CreateHttpParameterTransformer.ts +13 -13
- package/src/features/http/CreateHttpQueryTransformer.ts +13 -13
- package/src/features/http/CreateHttpValidateFormDataTransformer.ts +13 -13
- package/src/features/http/CreateHttpValidateHeadersTransformer.ts +13 -13
- package/src/features/http/CreateHttpValidateQueryTransformer.ts +13 -13
- package/src/features/http/HttpAssertFormDataTransformer.ts +13 -13
- package/src/features/http/HttpAssertHeadersTransformer.ts +13 -13
- package/src/features/http/HttpAssertQueryTransformer.ts +13 -13
- package/src/features/http/HttpFormDataTransformer.ts +13 -13
- package/src/features/http/HttpHeadersTransformer.ts +13 -13
- package/src/features/http/HttpIsFormDataTransformer.ts +13 -13
- package/src/features/http/HttpIsHeadersTransformer.ts +13 -13
- package/src/features/http/HttpIsQueryTransformer.ts +13 -13
- package/src/features/http/HttpParameterTransformer.ts +13 -13
- package/src/features/http/HttpQueryTransformer.ts +13 -13
- package/src/features/http/HttpValidateFormDataTransformer.ts +13 -13
- package/src/features/http/HttpValidateHeadersTransformer.ts +13 -13
- package/src/features/http/HttpValidateQueryTransformer.ts +13 -13
- package/src/features/json/JsonApplicationTransformer.ts +99 -102
- package/src/features/json/JsonAssertParseTransformer.ts +13 -13
- package/src/features/json/JsonAssertStringifyTransformer.ts +13 -13
- package/src/features/json/JsonCreateAssertParseTransformer.ts +13 -13
- package/src/features/json/JsonCreateAssertStringifyTransformer.ts +13 -13
- package/src/features/json/JsonCreateIsParseTransformer.ts +13 -13
- package/src/features/json/JsonCreateIsStringifyTransformer.ts +13 -13
- package/src/features/json/JsonCreateStringifyTransformer.ts +13 -13
- package/src/features/json/JsonCreateValidateParseTransformer.ts +13 -13
- package/src/features/json/JsonCreateValidateStringifyProgrammer.ts +13 -13
- package/src/features/json/JsonIsParseTransformer.ts +13 -13
- package/src/features/json/JsonIsStringifyTransformer.ts +13 -13
- package/src/features/json/JsonSchemaTransformer.ts +120 -132
- package/src/features/json/JsonSchemasTransformer.ts +130 -142
- package/src/features/json/JsonStringifyTransformer.ts +13 -13
- package/src/features/json/JsonValidateParseTransformer.ts +13 -13
- package/src/features/json/JsonValidateStringifyTransformer.ts +13 -13
- package/src/features/llm/LlmApplicationTransformer.ts +224 -184
- package/src/features/llm/LlmCoerceTransformer.ts +95 -0
- package/src/features/llm/LlmControllerTransformer.ts +81 -76
- package/src/features/llm/LlmCreateCoerceTransformer.ts +84 -0
- package/src/features/llm/LlmCreateParseTransformer.ts +84 -0
- package/src/features/llm/LlmParametersTransformer.ts +76 -88
- package/src/features/llm/LlmParseTransformer.ts +95 -0
- package/src/features/llm/LlmSchemaTransformer.ts +87 -133
- package/src/features/misc/MiscAssertCloneTransformer.ts +13 -13
- package/src/features/misc/MiscAssertPruneTransformer.ts +13 -13
- package/src/features/misc/MiscCloneTransformer.ts +13 -13
- package/src/features/misc/MiscCreateAssertCloneTransformer.ts +13 -13
- package/src/features/misc/MiscCreateAssertPruneTransformer.ts +13 -13
- package/src/features/misc/MiscCreateCloneTransformer.ts +13 -13
- package/src/features/misc/MiscCreateIsCloneTransformer.ts +13 -13
- package/src/features/misc/MiscCreateIsPruneTransformer.ts +13 -13
- package/src/features/misc/MiscCreatePruneTransformer.ts +13 -13
- package/src/features/misc/MiscCreateValidateCloneTransformer.ts +13 -13
- package/src/features/misc/MiscCreateValidatePruneTransformer.ts +13 -13
- package/src/features/misc/MiscIsCloneTransformer.ts +13 -13
- package/src/features/misc/MiscIsPruneTransformer.ts +13 -13
- package/src/features/misc/MiscLiteralsTransformer.ts +34 -34
- package/src/features/misc/MiscPruneTransformer.ts +13 -13
- package/src/features/misc/MiscValidateCloneTransformer.ts +13 -13
- package/src/features/misc/MiscValidatePruneTransformer.ts +13 -13
- package/src/features/notations/NotationAssertGeneralTransformer.ts +19 -19
- package/src/features/notations/NotationCreateAssertGeneralTransformer.ts +19 -19
- package/src/features/notations/NotationCreateGeneralTransformer.ts +19 -19
- package/src/features/notations/NotationCreateIsGeneralTransformer.ts +19 -19
- package/src/features/notations/NotationCreateValidateGeneralTransformer.ts +19 -19
- package/src/features/notations/NotationGeneralTransformer.ts +18 -18
- package/src/features/notations/NotationIsGeneralTransformer.ts +19 -19
- package/src/features/notations/NotationValidateGeneralTransformer.ts +19 -19
- package/src/features/protobuf/ProtobufAssertDecodeTransformer.ts +13 -13
- package/src/features/protobuf/ProtobufAssertEncodeTransformer.ts +13 -13
- package/src/features/protobuf/ProtobufCreateAssertDecodeTransformer.ts +13 -13
- package/src/features/protobuf/ProtobufCreateAssertEncodeTransformer.ts +13 -13
- package/src/features/protobuf/ProtobufCreateDecodeTransformer.ts +13 -13
- package/src/features/protobuf/ProtobufCreateEncodeTransformer.ts +13 -13
- package/src/features/protobuf/ProtobufCreateIsDecodeTransformer.ts +13 -13
- package/src/features/protobuf/ProtobufCreateIsEncodeTransformer.ts +13 -13
- package/src/features/protobuf/ProtobufCreateValidateDecodeTransformer.ts +13 -13
- package/src/features/protobuf/ProtobufCreateValidateEncodeTransformer.ts +13 -13
- package/src/features/protobuf/ProtobufDecodeTransformer.ts +13 -13
- package/src/features/protobuf/ProtobufEncodeTransformer.ts +13 -13
- package/src/features/protobuf/ProtobufIsDecodeTransformer.ts +13 -13
- package/src/features/protobuf/ProtobufIsEncodeTransformer.ts +13 -13
- package/src/features/protobuf/ProtobufMessageTransformer.ts +34 -34
- package/src/features/protobuf/ProtobufValidateDecodeTransformer.ts +13 -13
- package/src/features/protobuf/ProtobufValidateEncodeTransformer.ts +13 -13
- package/src/features/reflect/ReflectMetadataTransformer.ts +69 -69
- package/src/features/reflect/ReflectNameTransformer.ts +81 -81
- package/src/features/reflect/ReflectSchemaTransformer.ts +65 -65
- package/src/features/reflect/ReflectSchemasTransformer.ts +69 -69
- package/src/index.ts +7 -7
- package/src/internal/GenericTransformer.ts +101 -101
- package/src/transform.ts +68 -68
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import {
|
|
2
|
+
LlmCoerceProgrammer,
|
|
3
|
+
LlmMetadataFactory,
|
|
4
|
+
MetadataCollection,
|
|
5
|
+
MetadataFactory,
|
|
6
|
+
MetadataSchema,
|
|
7
|
+
} from "@typia/core";
|
|
8
|
+
import { ILlmSchema, ValidationPipe } from "@typia/interface";
|
|
9
|
+
import ts from "typescript";
|
|
10
|
+
|
|
11
|
+
import { ITransformProps } from "../../ITransformProps";
|
|
12
|
+
import { TransformerError } from "../../TransformerError";
|
|
13
|
+
|
|
14
|
+
export namespace LlmCreateCoerceTransformer {
|
|
15
|
+
export const transform = (props: ITransformProps): ts.Expression => {
|
|
16
|
+
// GET GENERIC ARGUMENT
|
|
17
|
+
if (!props.expression.typeArguments?.length)
|
|
18
|
+
throw new TransformerError({
|
|
19
|
+
code: "typia.llm.createCoerce",
|
|
20
|
+
message: "no generic argument.",
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const top: ts.Node = props.expression.typeArguments[0]!;
|
|
24
|
+
if (ts.isTypeNode(top) === false) return props.expression;
|
|
25
|
+
|
|
26
|
+
// GET TYPE AND CONFIG
|
|
27
|
+
const config: Partial<ILlmSchema.IConfig> = LlmMetadataFactory.getConfig({
|
|
28
|
+
context: props.context,
|
|
29
|
+
method: "createCoerce",
|
|
30
|
+
node: props.expression.typeArguments[1],
|
|
31
|
+
}) as Partial<ILlmSchema.IConfig>;
|
|
32
|
+
|
|
33
|
+
const type: ts.Type = props.context.checker.getTypeFromTypeNode(top);
|
|
34
|
+
|
|
35
|
+
if (type.isTypeParameter())
|
|
36
|
+
throw new TransformerError({
|
|
37
|
+
code: "typia.llm.createCoerce",
|
|
38
|
+
message: "non-specified generic argument.",
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// VALIDATE TYPE
|
|
42
|
+
const analyze = (validate: boolean): MetadataSchema => {
|
|
43
|
+
const result: ValidationPipe<MetadataSchema, MetadataFactory.IError> =
|
|
44
|
+
MetadataFactory.analyze({
|
|
45
|
+
checker: props.context.checker,
|
|
46
|
+
transformer: props.context.transformer,
|
|
47
|
+
options: {
|
|
48
|
+
absorb: validate,
|
|
49
|
+
escape: true,
|
|
50
|
+
constant: true,
|
|
51
|
+
validate:
|
|
52
|
+
validate === true
|
|
53
|
+
? (metadata, explore) =>
|
|
54
|
+
LlmCoerceProgrammer.validate({
|
|
55
|
+
config,
|
|
56
|
+
metadata,
|
|
57
|
+
explore,
|
|
58
|
+
})
|
|
59
|
+
: undefined,
|
|
60
|
+
},
|
|
61
|
+
components: new MetadataCollection({
|
|
62
|
+
replace: MetadataCollection.replace,
|
|
63
|
+
}),
|
|
64
|
+
type,
|
|
65
|
+
});
|
|
66
|
+
if (result.success === false)
|
|
67
|
+
throw TransformerError.from({
|
|
68
|
+
code: "typia.llm.createCoerce",
|
|
69
|
+
errors: result.errors,
|
|
70
|
+
});
|
|
71
|
+
return result.data;
|
|
72
|
+
};
|
|
73
|
+
analyze(true);
|
|
74
|
+
|
|
75
|
+
// GENERATE CODE (factory returns the function directly)
|
|
76
|
+
return LlmCoerceProgrammer.write({
|
|
77
|
+
context: props.context,
|
|
78
|
+
modulo: props.modulo,
|
|
79
|
+
metadata: analyze(false),
|
|
80
|
+
name: (top as ts.TypeNode).getFullText().trim(),
|
|
81
|
+
config,
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import {
|
|
2
|
+
LlmMetadataFactory,
|
|
3
|
+
LlmParseProgrammer,
|
|
4
|
+
MetadataCollection,
|
|
5
|
+
MetadataFactory,
|
|
6
|
+
MetadataSchema,
|
|
7
|
+
} from "@typia/core";
|
|
8
|
+
import { ILlmSchema, ValidationPipe } from "@typia/interface";
|
|
9
|
+
import ts from "typescript";
|
|
10
|
+
|
|
11
|
+
import { ITransformProps } from "../../ITransformProps";
|
|
12
|
+
import { TransformerError } from "../../TransformerError";
|
|
13
|
+
|
|
14
|
+
export namespace LlmCreateParseTransformer {
|
|
15
|
+
export const transform = (props: ITransformProps): ts.Expression => {
|
|
16
|
+
// GET GENERIC ARGUMENT
|
|
17
|
+
if (!props.expression.typeArguments?.length)
|
|
18
|
+
throw new TransformerError({
|
|
19
|
+
code: "typia.llm.createParse",
|
|
20
|
+
message: "no generic argument.",
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const top: ts.Node = props.expression.typeArguments[0]!;
|
|
24
|
+
if (ts.isTypeNode(top) === false) return props.expression;
|
|
25
|
+
|
|
26
|
+
// GET TYPE AND CONFIG
|
|
27
|
+
const config: Partial<ILlmSchema.IConfig> = LlmMetadataFactory.getConfig({
|
|
28
|
+
context: props.context,
|
|
29
|
+
method: "createParse",
|
|
30
|
+
node: props.expression.typeArguments[1],
|
|
31
|
+
}) as Partial<ILlmSchema.IConfig>;
|
|
32
|
+
|
|
33
|
+
const type: ts.Type = props.context.checker.getTypeFromTypeNode(top);
|
|
34
|
+
|
|
35
|
+
if (type.isTypeParameter())
|
|
36
|
+
throw new TransformerError({
|
|
37
|
+
code: "typia.llm.createParse",
|
|
38
|
+
message: "non-specified generic argument.",
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// VALIDATE TYPE
|
|
42
|
+
const analyze = (validate: boolean): MetadataSchema => {
|
|
43
|
+
const result: ValidationPipe<MetadataSchema, MetadataFactory.IError> =
|
|
44
|
+
MetadataFactory.analyze({
|
|
45
|
+
checker: props.context.checker,
|
|
46
|
+
transformer: props.context.transformer,
|
|
47
|
+
options: {
|
|
48
|
+
absorb: validate,
|
|
49
|
+
escape: true,
|
|
50
|
+
constant: true,
|
|
51
|
+
validate:
|
|
52
|
+
validate === true
|
|
53
|
+
? (metadata, explore) =>
|
|
54
|
+
LlmParseProgrammer.validate({
|
|
55
|
+
config,
|
|
56
|
+
metadata,
|
|
57
|
+
explore,
|
|
58
|
+
})
|
|
59
|
+
: undefined,
|
|
60
|
+
},
|
|
61
|
+
components: new MetadataCollection({
|
|
62
|
+
replace: MetadataCollection.replace,
|
|
63
|
+
}),
|
|
64
|
+
type,
|
|
65
|
+
});
|
|
66
|
+
if (result.success === false)
|
|
67
|
+
throw TransformerError.from({
|
|
68
|
+
code: "typia.llm.createParse",
|
|
69
|
+
errors: result.errors,
|
|
70
|
+
});
|
|
71
|
+
return result.data;
|
|
72
|
+
};
|
|
73
|
+
analyze(true);
|
|
74
|
+
|
|
75
|
+
// GENERATE CODE (factory returns the function directly)
|
|
76
|
+
return LlmParseProgrammer.write({
|
|
77
|
+
context: props.context,
|
|
78
|
+
modulo: props.modulo,
|
|
79
|
+
metadata: analyze(false),
|
|
80
|
+
name: (top as ts.TypeNode).getFullText().trim(),
|
|
81
|
+
config,
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
}
|
|
@@ -1,88 +1,76 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} from "@typia/
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export
|
|
16
|
-
|
|
17
|
-
props
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
},
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return ts.factory.createSatisfiesExpression(
|
|
78
|
-
LiteralFactory.write(out),
|
|
79
|
-
props.context.importer.type({
|
|
80
|
-
file: "typia",
|
|
81
|
-
name: ts.factory.createQualifiedName(
|
|
82
|
-
ts.factory.createIdentifier("ILlmSchema"),
|
|
83
|
-
ts.factory.createIdentifier("IParameters"),
|
|
84
|
-
),
|
|
85
|
-
}),
|
|
86
|
-
);
|
|
87
|
-
};
|
|
88
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
LlmMetadataFactory,
|
|
3
|
+
LlmParametersProgrammer,
|
|
4
|
+
MetadataCollection,
|
|
5
|
+
MetadataFactory,
|
|
6
|
+
MetadataSchema,
|
|
7
|
+
} from "@typia/core";
|
|
8
|
+
import { ILlmSchema, ValidationPipe } from "@typia/interface";
|
|
9
|
+
import ts from "typescript";
|
|
10
|
+
|
|
11
|
+
import { ITransformProps } from "../../ITransformProps";
|
|
12
|
+
import { TransformerError } from "../../TransformerError";
|
|
13
|
+
|
|
14
|
+
export namespace LlmParametersTransformer {
|
|
15
|
+
export const transform = (props: ITransformProps): ts.Expression => {
|
|
16
|
+
// GET GENERIC ARGUMENT
|
|
17
|
+
if (!props.expression.typeArguments?.length)
|
|
18
|
+
throw new TransformerError({
|
|
19
|
+
code: "typia.llm.parameters",
|
|
20
|
+
message: "no generic argument.",
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const top: ts.Node = props.expression.typeArguments[0]!;
|
|
24
|
+
if (ts.isTypeNode(top) === false) return props.expression;
|
|
25
|
+
|
|
26
|
+
// GET TYPE
|
|
27
|
+
const config: Partial<ILlmSchema.IConfig> = LlmMetadataFactory.getConfig({
|
|
28
|
+
context: props.context,
|
|
29
|
+
method: "parameters",
|
|
30
|
+
node: props.expression.typeArguments[1],
|
|
31
|
+
}) as Partial<ILlmSchema.IConfig>;
|
|
32
|
+
|
|
33
|
+
const type: ts.Type = props.context.checker.getTypeFromTypeNode(top);
|
|
34
|
+
|
|
35
|
+
// VALIDATE TYPE
|
|
36
|
+
const analyze = (validate: boolean): MetadataSchema => {
|
|
37
|
+
const result: ValidationPipe<MetadataSchema, MetadataFactory.IError> =
|
|
38
|
+
MetadataFactory.analyze({
|
|
39
|
+
checker: props.context.checker,
|
|
40
|
+
transformer: props.context.transformer,
|
|
41
|
+
options: {
|
|
42
|
+
absorb: validate,
|
|
43
|
+
escape: true,
|
|
44
|
+
constant: true,
|
|
45
|
+
validate:
|
|
46
|
+
validate === true
|
|
47
|
+
? (metadata, explore) =>
|
|
48
|
+
LlmParametersProgrammer.validate({
|
|
49
|
+
config,
|
|
50
|
+
metadata,
|
|
51
|
+
explore,
|
|
52
|
+
})
|
|
53
|
+
: undefined,
|
|
54
|
+
},
|
|
55
|
+
components: new MetadataCollection({
|
|
56
|
+
replace: MetadataCollection.replace,
|
|
57
|
+
}),
|
|
58
|
+
type,
|
|
59
|
+
});
|
|
60
|
+
if (result.success === false)
|
|
61
|
+
throw TransformerError.from({
|
|
62
|
+
code: "typia.llm.parameters",
|
|
63
|
+
errors: result.errors,
|
|
64
|
+
});
|
|
65
|
+
return result.data;
|
|
66
|
+
};
|
|
67
|
+
analyze(true);
|
|
68
|
+
|
|
69
|
+
// GENERATE LLM PARAMETERS SCHEMA
|
|
70
|
+
return LlmParametersProgrammer.write({
|
|
71
|
+
context: props.context,
|
|
72
|
+
metadata: analyze(false),
|
|
73
|
+
config,
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import {
|
|
2
|
+
LlmMetadataFactory,
|
|
3
|
+
LlmParseProgrammer,
|
|
4
|
+
MetadataCollection,
|
|
5
|
+
MetadataFactory,
|
|
6
|
+
MetadataSchema,
|
|
7
|
+
} from "@typia/core";
|
|
8
|
+
import { ILlmSchema, ValidationPipe } from "@typia/interface";
|
|
9
|
+
import ts from "typescript";
|
|
10
|
+
|
|
11
|
+
import { ITransformProps } from "../../ITransformProps";
|
|
12
|
+
import { TransformerError } from "../../TransformerError";
|
|
13
|
+
|
|
14
|
+
export namespace LlmParseTransformer {
|
|
15
|
+
export const transform = (props: ITransformProps): ts.Expression => {
|
|
16
|
+
// CHECK PARAMETER
|
|
17
|
+
if (props.expression.arguments.length === 0)
|
|
18
|
+
throw new TransformerError({
|
|
19
|
+
code: "typia.llm.parse",
|
|
20
|
+
message: "no input value.",
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// GET GENERIC ARGUMENT
|
|
24
|
+
if (!props.expression.typeArguments?.length)
|
|
25
|
+
throw new TransformerError({
|
|
26
|
+
code: "typia.llm.parse",
|
|
27
|
+
message: "no generic argument.",
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
const top: ts.Node = props.expression.typeArguments[0]!;
|
|
31
|
+
if (ts.isTypeNode(top) === false) return props.expression;
|
|
32
|
+
|
|
33
|
+
// GET TYPE AND CONFIG
|
|
34
|
+
const config: Partial<ILlmSchema.IConfig> = LlmMetadataFactory.getConfig({
|
|
35
|
+
context: props.context,
|
|
36
|
+
method: "parse",
|
|
37
|
+
node: props.expression.typeArguments[1],
|
|
38
|
+
}) as Partial<ILlmSchema.IConfig>;
|
|
39
|
+
|
|
40
|
+
const type: ts.Type = props.context.checker.getTypeFromTypeNode(top);
|
|
41
|
+
|
|
42
|
+
if (type.isTypeParameter())
|
|
43
|
+
throw new TransformerError({
|
|
44
|
+
code: "typia.llm.parse",
|
|
45
|
+
message: "non-specified generic argument.",
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// VALIDATE TYPE
|
|
49
|
+
const analyze = (validate: boolean): MetadataSchema => {
|
|
50
|
+
const result: ValidationPipe<MetadataSchema, MetadataFactory.IError> =
|
|
51
|
+
MetadataFactory.analyze({
|
|
52
|
+
checker: props.context.checker,
|
|
53
|
+
transformer: props.context.transformer,
|
|
54
|
+
options: {
|
|
55
|
+
absorb: validate,
|
|
56
|
+
escape: true,
|
|
57
|
+
constant: true,
|
|
58
|
+
validate:
|
|
59
|
+
validate === true
|
|
60
|
+
? (metadata, explore) =>
|
|
61
|
+
LlmParseProgrammer.validate({
|
|
62
|
+
config,
|
|
63
|
+
metadata,
|
|
64
|
+
explore,
|
|
65
|
+
})
|
|
66
|
+
: undefined,
|
|
67
|
+
},
|
|
68
|
+
components: new MetadataCollection({
|
|
69
|
+
replace: MetadataCollection.replace,
|
|
70
|
+
}),
|
|
71
|
+
type,
|
|
72
|
+
});
|
|
73
|
+
if (result.success === false)
|
|
74
|
+
throw TransformerError.from({
|
|
75
|
+
code: "typia.llm.parse",
|
|
76
|
+
errors: result.errors,
|
|
77
|
+
});
|
|
78
|
+
return result.data;
|
|
79
|
+
};
|
|
80
|
+
analyze(true);
|
|
81
|
+
|
|
82
|
+
// GENERATE CODE
|
|
83
|
+
return ts.factory.createCallExpression(
|
|
84
|
+
LlmParseProgrammer.write({
|
|
85
|
+
context: props.context,
|
|
86
|
+
modulo: props.modulo,
|
|
87
|
+
metadata: analyze(false),
|
|
88
|
+
name: (top as ts.TypeNode).getFullText().trim(),
|
|
89
|
+
config,
|
|
90
|
+
}),
|
|
91
|
+
undefined,
|
|
92
|
+
props.expression.arguments,
|
|
93
|
+
);
|
|
94
|
+
};
|
|
95
|
+
}
|
|
@@ -1,133 +1,87 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
import
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
undefined,
|
|
89
|
-
undefined,
|
|
90
|
-
[
|
|
91
|
-
IdentifierFactory.parameter(
|
|
92
|
-
"$defs",
|
|
93
|
-
ts.factory.createTypeReferenceNode("Record", [
|
|
94
|
-
ts.factory.createKeywordTypeNode(ts.SyntaxKind.StringKeyword),
|
|
95
|
-
schemaTypeNode,
|
|
96
|
-
]),
|
|
97
|
-
undefined,
|
|
98
|
-
),
|
|
99
|
-
],
|
|
100
|
-
undefined,
|
|
101
|
-
undefined,
|
|
102
|
-
ts.factory.createBlock(
|
|
103
|
-
[
|
|
104
|
-
ts.factory.createExpressionStatement(
|
|
105
|
-
ts.factory.createCallExpression(
|
|
106
|
-
ts.factory.createIdentifier("Object.assign"),
|
|
107
|
-
undefined,
|
|
108
|
-
[
|
|
109
|
-
ts.factory.createIdentifier("$defs"),
|
|
110
|
-
ts.factory.createAsExpression(
|
|
111
|
-
LiteralFactory.write(out.$defs),
|
|
112
|
-
ts.factory.createTypeReferenceNode("Record", [
|
|
113
|
-
ts.factory.createKeywordTypeNode(
|
|
114
|
-
ts.SyntaxKind.StringKeyword,
|
|
115
|
-
),
|
|
116
|
-
schemaTypeNode,
|
|
117
|
-
]),
|
|
118
|
-
),
|
|
119
|
-
],
|
|
120
|
-
),
|
|
121
|
-
),
|
|
122
|
-
ts.factory.createReturnStatement(literal),
|
|
123
|
-
],
|
|
124
|
-
true,
|
|
125
|
-
),
|
|
126
|
-
),
|
|
127
|
-
undefined,
|
|
128
|
-
props.expression.arguments?.[0] !== undefined
|
|
129
|
-
? [props.expression.arguments[0]!]
|
|
130
|
-
: [],
|
|
131
|
-
);
|
|
132
|
-
};
|
|
133
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
LlmMetadataFactory,
|
|
3
|
+
LlmSchemaProgrammer,
|
|
4
|
+
MetadataCollection,
|
|
5
|
+
MetadataFactory,
|
|
6
|
+
MetadataSchema,
|
|
7
|
+
} from "@typia/core";
|
|
8
|
+
import { ILlmSchema, ValidationPipe } from "@typia/interface";
|
|
9
|
+
import ts from "typescript";
|
|
10
|
+
|
|
11
|
+
import { ITransformProps } from "../../ITransformProps";
|
|
12
|
+
import { TransformerError } from "../../TransformerError";
|
|
13
|
+
|
|
14
|
+
export namespace LlmSchemaTransformer {
|
|
15
|
+
export const transform = (props: ITransformProps): ts.Expression => {
|
|
16
|
+
// GET GENERIC ARGUMENT
|
|
17
|
+
if (!props.expression.typeArguments?.length)
|
|
18
|
+
throw new TransformerError({
|
|
19
|
+
code: "typia.llm.schema",
|
|
20
|
+
message: "no generic argument.",
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const top: ts.Node = props.expression.typeArguments[0]!;
|
|
24
|
+
if (ts.isTypeNode(top) === false) return props.expression;
|
|
25
|
+
|
|
26
|
+
// GET TYPE
|
|
27
|
+
const config: Partial<ILlmSchema.IConfig> = LlmMetadataFactory.getConfig({
|
|
28
|
+
context: props.context,
|
|
29
|
+
method: "schema",
|
|
30
|
+
node: props.expression.typeArguments[1],
|
|
31
|
+
}) as Partial<ILlmSchema.IConfig>;
|
|
32
|
+
|
|
33
|
+
const type: ts.Type = props.context.checker.getTypeFromTypeNode(top);
|
|
34
|
+
|
|
35
|
+
// VALIDATE TYPE
|
|
36
|
+
const analyze = (validate: boolean): MetadataSchema => {
|
|
37
|
+
const result: ValidationPipe<MetadataSchema, MetadataFactory.IError> =
|
|
38
|
+
MetadataFactory.analyze({
|
|
39
|
+
checker: props.context.checker,
|
|
40
|
+
transformer: props.context.transformer,
|
|
41
|
+
options: {
|
|
42
|
+
absorb: validate,
|
|
43
|
+
constant: true,
|
|
44
|
+
escape: true,
|
|
45
|
+
validate:
|
|
46
|
+
validate === true
|
|
47
|
+
? (metadata: MetadataSchema) =>
|
|
48
|
+
LlmSchemaProgrammer.validate({
|
|
49
|
+
config,
|
|
50
|
+
metadata,
|
|
51
|
+
})
|
|
52
|
+
: undefined,
|
|
53
|
+
},
|
|
54
|
+
components: new MetadataCollection({
|
|
55
|
+
replace: MetadataCollection.replace,
|
|
56
|
+
}),
|
|
57
|
+
type,
|
|
58
|
+
});
|
|
59
|
+
if (result.success === false)
|
|
60
|
+
throw TransformerError.from({
|
|
61
|
+
code: "typia.llm.schema",
|
|
62
|
+
errors: result.errors,
|
|
63
|
+
});
|
|
64
|
+
return result.data;
|
|
65
|
+
};
|
|
66
|
+
analyze(true);
|
|
67
|
+
|
|
68
|
+
// GENERATE LLM SCHEMA
|
|
69
|
+
const expr = LlmSchemaProgrammer.write({
|
|
70
|
+
context: props.context,
|
|
71
|
+
metadata: analyze(false),
|
|
72
|
+
config,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
// If user provided $defs argument and expression is a function, call it with $defs
|
|
76
|
+
if (
|
|
77
|
+
props.expression.arguments?.[0] !== undefined &&
|
|
78
|
+
ts.isArrowFunction(expr)
|
|
79
|
+
) {
|
|
80
|
+
return ts.factory.createCallExpression(expr, undefined, [
|
|
81
|
+
props.expression.arguments[0]!,
|
|
82
|
+
]);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return expr;
|
|
86
|
+
};
|
|
87
|
+
}
|