@typia/transform 12.0.0-dev.20260309 → 12.0.0-dev.20260311
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/package.json +4 -4
- package/src/CallExpressionTransformer.ts +579 -579
- 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 -99
- 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 -120
- package/src/features/json/JsonSchemasTransformer.ts +130 -130
- 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 -224
- package/src/features/llm/LlmCoerceTransformer.ts +95 -95
- package/src/features/llm/LlmControllerTransformer.ts +81 -81
- package/src/features/llm/LlmCreateCoerceTransformer.ts +84 -84
- package/src/features/llm/LlmCreateParseTransformer.ts +84 -84
- package/src/features/llm/LlmParametersTransformer.ts +76 -76
- package/src/features/llm/LlmParseTransformer.ts +95 -95
- package/src/features/llm/LlmSchemaTransformer.ts +87 -87
- 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
|
@@ -1,224 +1,224 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ITypiaContext,
|
|
3
|
-
LlmApplicationProgrammer,
|
|
4
|
-
LlmMetadataFactory,
|
|
5
|
-
MetadataCollection,
|
|
6
|
-
MetadataFactory,
|
|
7
|
-
MetadataSchema,
|
|
8
|
-
} from "@typia/core";
|
|
9
|
-
import { ILlmApplication, ILlmSchema, ValidationPipe } from "@typia/interface";
|
|
10
|
-
import ts from "typescript";
|
|
11
|
-
|
|
12
|
-
import { ITransformProps } from "../../ITransformProps";
|
|
13
|
-
import { TransformerError } from "../../TransformerError";
|
|
14
|
-
|
|
15
|
-
export namespace LlmApplicationTransformer {
|
|
16
|
-
export const transform = (props: ITransformProps): ts.Expression => {
|
|
17
|
-
// GET GENERIC ARGUMENT
|
|
18
|
-
if (!props.expression.typeArguments?.length)
|
|
19
|
-
throw new TransformerError({
|
|
20
|
-
code: "typia.llm.application",
|
|
21
|
-
message: "no generic argument.",
|
|
22
|
-
});
|
|
23
|
-
const top: ts.Node = props.expression.typeArguments[0]!;
|
|
24
|
-
if (ts.isTypeNode(top) === false) return props.expression;
|
|
25
|
-
|
|
26
|
-
// GET CONFIG
|
|
27
|
-
const config:
|
|
28
|
-
| Partial<
|
|
29
|
-
ILlmSchema.IConfig & {
|
|
30
|
-
equals: boolean;
|
|
31
|
-
}
|
|
32
|
-
>
|
|
33
|
-
| undefined = LlmMetadataFactory.getConfig({
|
|
34
|
-
context: props.context,
|
|
35
|
-
method: "application",
|
|
36
|
-
node: props.expression.typeArguments[1],
|
|
37
|
-
});
|
|
38
|
-
const type: ts.Type = props.context.checker.getTypeFromTypeNode(top);
|
|
39
|
-
|
|
40
|
-
// VALIDATE TYPE
|
|
41
|
-
const analyze = (validate: boolean): MetadataSchema => {
|
|
42
|
-
const result: ValidationPipe<MetadataSchema, MetadataFactory.IError> =
|
|
43
|
-
MetadataFactory.analyze({
|
|
44
|
-
checker: props.context.checker,
|
|
45
|
-
transformer: props.context.transformer,
|
|
46
|
-
options: {
|
|
47
|
-
absorb: validate,
|
|
48
|
-
escape: true,
|
|
49
|
-
constant: true,
|
|
50
|
-
functional: true,
|
|
51
|
-
validate:
|
|
52
|
-
validate === true
|
|
53
|
-
? (metadata, explore) =>
|
|
54
|
-
LlmApplicationProgrammer.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.application",
|
|
69
|
-
errors: result.errors,
|
|
70
|
-
});
|
|
71
|
-
return result.data;
|
|
72
|
-
};
|
|
73
|
-
analyze(true);
|
|
74
|
-
|
|
75
|
-
// GENERATE LLM APPLICATION
|
|
76
|
-
return LlmApplicationProgrammer.write({
|
|
77
|
-
context: props.context,
|
|
78
|
-
modulo: props.modulo,
|
|
79
|
-
metadata: analyze(false),
|
|
80
|
-
name: top.getFullText().trim(),
|
|
81
|
-
config,
|
|
82
|
-
});
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
/** @internal */
|
|
86
|
-
export const decompose = (
|
|
87
|
-
method: string,
|
|
88
|
-
props: ITransformProps,
|
|
89
|
-
): {
|
|
90
|
-
application: ILlmApplication.__IPrimitive;
|
|
91
|
-
type: ts.Type;
|
|
92
|
-
node: ts.TypeNode;
|
|
93
|
-
config:
|
|
94
|
-
| Partial<
|
|
95
|
-
ILlmSchema.IConfig & {
|
|
96
|
-
equals: boolean;
|
|
97
|
-
}
|
|
98
|
-
>
|
|
99
|
-
| undefined;
|
|
100
|
-
} | null => {
|
|
101
|
-
// GET GENERIC ARGUMENT
|
|
102
|
-
if (!props.expression.typeArguments?.length)
|
|
103
|
-
throw new TransformerError({
|
|
104
|
-
code: `typia.llm.${method}`,
|
|
105
|
-
message: "no generic argument.",
|
|
106
|
-
});
|
|
107
|
-
const top: ts.Node = props.expression.typeArguments[0]!;
|
|
108
|
-
if (ts.isTypeNode(top) === false) return null;
|
|
109
|
-
|
|
110
|
-
// GET TYPE
|
|
111
|
-
const config:
|
|
112
|
-
| Partial<
|
|
113
|
-
ILlmSchema.IConfig & {
|
|
114
|
-
equals: boolean;
|
|
115
|
-
}
|
|
116
|
-
>
|
|
117
|
-
| undefined = LlmMetadataFactory.getConfig({
|
|
118
|
-
context: props.context,
|
|
119
|
-
method,
|
|
120
|
-
node: props.expression.typeArguments[1],
|
|
121
|
-
});
|
|
122
|
-
const type: ts.Type = props.context.checker.getTypeFromTypeNode(top);
|
|
123
|
-
|
|
124
|
-
// VALIDATE TYPE
|
|
125
|
-
const analyze = (validate: boolean): MetadataSchema => {
|
|
126
|
-
const result: ValidationPipe<MetadataSchema, MetadataFactory.IError> =
|
|
127
|
-
MetadataFactory.analyze({
|
|
128
|
-
checker: props.context.checker,
|
|
129
|
-
transformer: props.context.transformer,
|
|
130
|
-
options: {
|
|
131
|
-
absorb: validate,
|
|
132
|
-
escape: true,
|
|
133
|
-
constant: true,
|
|
134
|
-
functional: true,
|
|
135
|
-
validate:
|
|
136
|
-
validate === true
|
|
137
|
-
? (metadata, explore) =>
|
|
138
|
-
LlmApplicationProgrammer.validate({
|
|
139
|
-
config,
|
|
140
|
-
metadata,
|
|
141
|
-
explore,
|
|
142
|
-
})
|
|
143
|
-
: undefined,
|
|
144
|
-
},
|
|
145
|
-
components: new MetadataCollection({
|
|
146
|
-
replace: MetadataCollection.replace,
|
|
147
|
-
}),
|
|
148
|
-
type,
|
|
149
|
-
});
|
|
150
|
-
if (result.success === false)
|
|
151
|
-
throw TransformerError.from({
|
|
152
|
-
code: `typia.llm.${method}`,
|
|
153
|
-
errors: result.errors,
|
|
154
|
-
});
|
|
155
|
-
return result.data;
|
|
156
|
-
};
|
|
157
|
-
analyze(true);
|
|
158
|
-
|
|
159
|
-
// GENERATE LLM APPLICATION
|
|
160
|
-
return {
|
|
161
|
-
application: LlmApplicationProgrammer.writeApplication({
|
|
162
|
-
context: props.context,
|
|
163
|
-
modulo: props.modulo,
|
|
164
|
-
metadata: analyze(false),
|
|
165
|
-
config,
|
|
166
|
-
name: top.getFullText().trim(),
|
|
167
|
-
}),
|
|
168
|
-
node: top,
|
|
169
|
-
type,
|
|
170
|
-
config,
|
|
171
|
-
};
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
export const getConfigArgument = (props: {
|
|
175
|
-
context: ITypiaContext;
|
|
176
|
-
argument: ts.Expression;
|
|
177
|
-
equals?: boolean | undefined;
|
|
178
|
-
}) => {
|
|
179
|
-
const satisfiesTypeNode: ts.TypeNode = ts.factory.createTypeReferenceNode(
|
|
180
|
-
ts.factory.createIdentifier("Partial"),
|
|
181
|
-
[
|
|
182
|
-
ts.factory.createTypeReferenceNode(
|
|
183
|
-
ts.factory.createIdentifier("Pick"),
|
|
184
|
-
[
|
|
185
|
-
ts.factory.createImportTypeNode(
|
|
186
|
-
ts.factory.createLiteralTypeNode(
|
|
187
|
-
ts.factory.createStringLiteral("typia"),
|
|
188
|
-
),
|
|
189
|
-
undefined,
|
|
190
|
-
ts.factory.createQualifiedName(
|
|
191
|
-
ts.factory.createIdentifier("ILlmApplication"),
|
|
192
|
-
ts.factory.createIdentifier("IConfig"),
|
|
193
|
-
),
|
|
194
|
-
undefined,
|
|
195
|
-
false,
|
|
196
|
-
),
|
|
197
|
-
ts.factory.createUnionTypeNode([
|
|
198
|
-
ts.factory.createLiteralTypeNode(
|
|
199
|
-
ts.factory.createStringLiteral("validate"),
|
|
200
|
-
),
|
|
201
|
-
]),
|
|
202
|
-
],
|
|
203
|
-
),
|
|
204
|
-
],
|
|
205
|
-
);
|
|
206
|
-
return ts.factory.createObjectLiteralExpression(
|
|
207
|
-
[
|
|
208
|
-
ts.factory.createSpreadAssignment(
|
|
209
|
-
ts.factory.createSatisfiesExpression(
|
|
210
|
-
props.argument,
|
|
211
|
-
satisfiesTypeNode,
|
|
212
|
-
),
|
|
213
|
-
),
|
|
214
|
-
ts.factory.createPropertyAssignment(
|
|
215
|
-
"equals",
|
|
216
|
-
props.equals === true
|
|
217
|
-
? ts.factory.createTrue()
|
|
218
|
-
: ts.factory.createFalse(),
|
|
219
|
-
),
|
|
220
|
-
],
|
|
221
|
-
true,
|
|
222
|
-
);
|
|
223
|
-
};
|
|
224
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
ITypiaContext,
|
|
3
|
+
LlmApplicationProgrammer,
|
|
4
|
+
LlmMetadataFactory,
|
|
5
|
+
MetadataCollection,
|
|
6
|
+
MetadataFactory,
|
|
7
|
+
MetadataSchema,
|
|
8
|
+
} from "@typia/core";
|
|
9
|
+
import { ILlmApplication, ILlmSchema, ValidationPipe } from "@typia/interface";
|
|
10
|
+
import ts from "typescript";
|
|
11
|
+
|
|
12
|
+
import { ITransformProps } from "../../ITransformProps";
|
|
13
|
+
import { TransformerError } from "../../TransformerError";
|
|
14
|
+
|
|
15
|
+
export namespace LlmApplicationTransformer {
|
|
16
|
+
export const transform = (props: ITransformProps): ts.Expression => {
|
|
17
|
+
// GET GENERIC ARGUMENT
|
|
18
|
+
if (!props.expression.typeArguments?.length)
|
|
19
|
+
throw new TransformerError({
|
|
20
|
+
code: "typia.llm.application",
|
|
21
|
+
message: "no generic argument.",
|
|
22
|
+
});
|
|
23
|
+
const top: ts.Node = props.expression.typeArguments[0]!;
|
|
24
|
+
if (ts.isTypeNode(top) === false) return props.expression;
|
|
25
|
+
|
|
26
|
+
// GET CONFIG
|
|
27
|
+
const config:
|
|
28
|
+
| Partial<
|
|
29
|
+
ILlmSchema.IConfig & {
|
|
30
|
+
equals: boolean;
|
|
31
|
+
}
|
|
32
|
+
>
|
|
33
|
+
| undefined = LlmMetadataFactory.getConfig({
|
|
34
|
+
context: props.context,
|
|
35
|
+
method: "application",
|
|
36
|
+
node: props.expression.typeArguments[1],
|
|
37
|
+
});
|
|
38
|
+
const type: ts.Type = props.context.checker.getTypeFromTypeNode(top);
|
|
39
|
+
|
|
40
|
+
// VALIDATE TYPE
|
|
41
|
+
const analyze = (validate: boolean): MetadataSchema => {
|
|
42
|
+
const result: ValidationPipe<MetadataSchema, MetadataFactory.IError> =
|
|
43
|
+
MetadataFactory.analyze({
|
|
44
|
+
checker: props.context.checker,
|
|
45
|
+
transformer: props.context.transformer,
|
|
46
|
+
options: {
|
|
47
|
+
absorb: validate,
|
|
48
|
+
escape: true,
|
|
49
|
+
constant: true,
|
|
50
|
+
functional: true,
|
|
51
|
+
validate:
|
|
52
|
+
validate === true
|
|
53
|
+
? (metadata, explore) =>
|
|
54
|
+
LlmApplicationProgrammer.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.application",
|
|
69
|
+
errors: result.errors,
|
|
70
|
+
});
|
|
71
|
+
return result.data;
|
|
72
|
+
};
|
|
73
|
+
analyze(true);
|
|
74
|
+
|
|
75
|
+
// GENERATE LLM APPLICATION
|
|
76
|
+
return LlmApplicationProgrammer.write({
|
|
77
|
+
context: props.context,
|
|
78
|
+
modulo: props.modulo,
|
|
79
|
+
metadata: analyze(false),
|
|
80
|
+
name: top.getFullText().trim(),
|
|
81
|
+
config,
|
|
82
|
+
});
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/** @internal */
|
|
86
|
+
export const decompose = (
|
|
87
|
+
method: string,
|
|
88
|
+
props: ITransformProps,
|
|
89
|
+
): {
|
|
90
|
+
application: ILlmApplication.__IPrimitive;
|
|
91
|
+
type: ts.Type;
|
|
92
|
+
node: ts.TypeNode;
|
|
93
|
+
config:
|
|
94
|
+
| Partial<
|
|
95
|
+
ILlmSchema.IConfig & {
|
|
96
|
+
equals: boolean;
|
|
97
|
+
}
|
|
98
|
+
>
|
|
99
|
+
| undefined;
|
|
100
|
+
} | null => {
|
|
101
|
+
// GET GENERIC ARGUMENT
|
|
102
|
+
if (!props.expression.typeArguments?.length)
|
|
103
|
+
throw new TransformerError({
|
|
104
|
+
code: `typia.llm.${method}`,
|
|
105
|
+
message: "no generic argument.",
|
|
106
|
+
});
|
|
107
|
+
const top: ts.Node = props.expression.typeArguments[0]!;
|
|
108
|
+
if (ts.isTypeNode(top) === false) return null;
|
|
109
|
+
|
|
110
|
+
// GET TYPE
|
|
111
|
+
const config:
|
|
112
|
+
| Partial<
|
|
113
|
+
ILlmSchema.IConfig & {
|
|
114
|
+
equals: boolean;
|
|
115
|
+
}
|
|
116
|
+
>
|
|
117
|
+
| undefined = LlmMetadataFactory.getConfig({
|
|
118
|
+
context: props.context,
|
|
119
|
+
method,
|
|
120
|
+
node: props.expression.typeArguments[1],
|
|
121
|
+
});
|
|
122
|
+
const type: ts.Type = props.context.checker.getTypeFromTypeNode(top);
|
|
123
|
+
|
|
124
|
+
// VALIDATE TYPE
|
|
125
|
+
const analyze = (validate: boolean): MetadataSchema => {
|
|
126
|
+
const result: ValidationPipe<MetadataSchema, MetadataFactory.IError> =
|
|
127
|
+
MetadataFactory.analyze({
|
|
128
|
+
checker: props.context.checker,
|
|
129
|
+
transformer: props.context.transformer,
|
|
130
|
+
options: {
|
|
131
|
+
absorb: validate,
|
|
132
|
+
escape: true,
|
|
133
|
+
constant: true,
|
|
134
|
+
functional: true,
|
|
135
|
+
validate:
|
|
136
|
+
validate === true
|
|
137
|
+
? (metadata, explore) =>
|
|
138
|
+
LlmApplicationProgrammer.validate({
|
|
139
|
+
config,
|
|
140
|
+
metadata,
|
|
141
|
+
explore,
|
|
142
|
+
})
|
|
143
|
+
: undefined,
|
|
144
|
+
},
|
|
145
|
+
components: new MetadataCollection({
|
|
146
|
+
replace: MetadataCollection.replace,
|
|
147
|
+
}),
|
|
148
|
+
type,
|
|
149
|
+
});
|
|
150
|
+
if (result.success === false)
|
|
151
|
+
throw TransformerError.from({
|
|
152
|
+
code: `typia.llm.${method}`,
|
|
153
|
+
errors: result.errors,
|
|
154
|
+
});
|
|
155
|
+
return result.data;
|
|
156
|
+
};
|
|
157
|
+
analyze(true);
|
|
158
|
+
|
|
159
|
+
// GENERATE LLM APPLICATION
|
|
160
|
+
return {
|
|
161
|
+
application: LlmApplicationProgrammer.writeApplication({
|
|
162
|
+
context: props.context,
|
|
163
|
+
modulo: props.modulo,
|
|
164
|
+
metadata: analyze(false),
|
|
165
|
+
config,
|
|
166
|
+
name: top.getFullText().trim(),
|
|
167
|
+
}),
|
|
168
|
+
node: top,
|
|
169
|
+
type,
|
|
170
|
+
config,
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
export const getConfigArgument = (props: {
|
|
175
|
+
context: ITypiaContext;
|
|
176
|
+
argument: ts.Expression;
|
|
177
|
+
equals?: boolean | undefined;
|
|
178
|
+
}) => {
|
|
179
|
+
const satisfiesTypeNode: ts.TypeNode = ts.factory.createTypeReferenceNode(
|
|
180
|
+
ts.factory.createIdentifier("Partial"),
|
|
181
|
+
[
|
|
182
|
+
ts.factory.createTypeReferenceNode(
|
|
183
|
+
ts.factory.createIdentifier("Pick"),
|
|
184
|
+
[
|
|
185
|
+
ts.factory.createImportTypeNode(
|
|
186
|
+
ts.factory.createLiteralTypeNode(
|
|
187
|
+
ts.factory.createStringLiteral("typia"),
|
|
188
|
+
),
|
|
189
|
+
undefined,
|
|
190
|
+
ts.factory.createQualifiedName(
|
|
191
|
+
ts.factory.createIdentifier("ILlmApplication"),
|
|
192
|
+
ts.factory.createIdentifier("IConfig"),
|
|
193
|
+
),
|
|
194
|
+
undefined,
|
|
195
|
+
false,
|
|
196
|
+
),
|
|
197
|
+
ts.factory.createUnionTypeNode([
|
|
198
|
+
ts.factory.createLiteralTypeNode(
|
|
199
|
+
ts.factory.createStringLiteral("validate"),
|
|
200
|
+
),
|
|
201
|
+
]),
|
|
202
|
+
],
|
|
203
|
+
),
|
|
204
|
+
],
|
|
205
|
+
);
|
|
206
|
+
return ts.factory.createObjectLiteralExpression(
|
|
207
|
+
[
|
|
208
|
+
ts.factory.createSpreadAssignment(
|
|
209
|
+
ts.factory.createSatisfiesExpression(
|
|
210
|
+
props.argument,
|
|
211
|
+
satisfiesTypeNode,
|
|
212
|
+
),
|
|
213
|
+
),
|
|
214
|
+
ts.factory.createPropertyAssignment(
|
|
215
|
+
"equals",
|
|
216
|
+
props.equals === true
|
|
217
|
+
? ts.factory.createTrue()
|
|
218
|
+
: ts.factory.createFalse(),
|
|
219
|
+
),
|
|
220
|
+
],
|
|
221
|
+
true,
|
|
222
|
+
);
|
|
223
|
+
};
|
|
224
|
+
}
|
|
@@ -1,95 +1,95 @@
|
|
|
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 LlmCoerceTransformer {
|
|
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.coerce",
|
|
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.coerce",
|
|
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: "coerce",
|
|
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.coerce",
|
|
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
|
-
LlmCoerceProgrammer.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.coerce",
|
|
76
|
-
errors: result.errors,
|
|
77
|
-
});
|
|
78
|
-
return result.data;
|
|
79
|
-
};
|
|
80
|
-
analyze(true);
|
|
81
|
-
|
|
82
|
-
// GENERATE CODE
|
|
83
|
-
return ts.factory.createCallExpression(
|
|
84
|
-
LlmCoerceProgrammer.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
|
+
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 LlmCoerceTransformer {
|
|
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.coerce",
|
|
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.coerce",
|
|
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: "coerce",
|
|
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.coerce",
|
|
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
|
+
LlmCoerceProgrammer.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.coerce",
|
|
76
|
+
errors: result.errors,
|
|
77
|
+
});
|
|
78
|
+
return result.data;
|
|
79
|
+
};
|
|
80
|
+
analyze(true);
|
|
81
|
+
|
|
82
|
+
// GENERATE CODE
|
|
83
|
+
return ts.factory.createCallExpression(
|
|
84
|
+
LlmCoerceProgrammer.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
|
+
}
|