@typia/transform 12.0.0 → 12.1.0-dev.20260325
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/LICENSE +21 -21
- package/README.md +25 -25
- package/lib/FileTransformer.js +16 -12
- package/lib/FileTransformer.js.map +1 -1
- package/lib/FileTransformer.mjs +16 -12
- package/lib/FileTransformer.mjs.map +1 -1
- package/lib/features/llm/LlmApplicationTransformer.d.ts +0 -6
- package/lib/features/llm/LlmApplicationTransformer.js +4 -82
- package/lib/features/llm/LlmApplicationTransformer.js.map +1 -1
- package/lib/features/llm/LlmApplicationTransformer.mjs +3 -80
- package/lib/features/llm/LlmApplicationTransformer.mjs.map +1 -1
- package/lib/features/llm/LlmControllerTransformer.js +64 -36
- package/lib/features/llm/LlmControllerTransformer.js.map +1 -1
- package/lib/features/llm/LlmControllerTransformer.mjs +64 -36
- package/lib/features/llm/LlmControllerTransformer.mjs.map +1 -1
- package/package.json +5 -5
- package/src/CallExpressionTransformer.ts +581 -581
- package/src/FileTransformer.ts +143 -143
- package/src/features/llm/LlmApplicationTransformer.ts +89 -226
- package/src/features/llm/LlmCoerceTransformer.ts +95 -95
- package/src/features/llm/LlmControllerTransformer.ts +100 -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 +88 -88
- package/src/features/llm/LlmStructuredOutputTransformer.ts +86 -86
package/src/FileTransformer.ts
CHANGED
|
@@ -1,143 +1,143 @@
|
|
|
1
|
-
import { ITypiaContext, ImportProgrammer } from "@typia/core";
|
|
2
|
-
import { Singleton } from "@typia/utils";
|
|
3
|
-
import ts from "typescript";
|
|
4
|
-
|
|
5
|
-
import { NodeTransformer } from "./NodeTransformer";
|
|
6
|
-
import { TransformerError } from "./TransformerError";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* TypeScript source file transformer for typia.
|
|
10
|
-
*
|
|
11
|
-
* Entry point for typia's compile-time transformation. Traverses AST nodes,
|
|
12
|
-
* transforms `typia.*` function calls into optimized runtime code, and injects
|
|
13
|
-
* required imports. Skips declaration files.
|
|
14
|
-
*
|
|
15
|
-
* @author Jeongho Nam - https://github.com/samchon
|
|
16
|
-
*/
|
|
17
|
-
export namespace FileTransformer {
|
|
18
|
-
export const transform =
|
|
19
|
-
(environments: Omit<ITypiaContext, "transformer" | "importer">) =>
|
|
20
|
-
(transformer: ts.TransformationContext) =>
|
|
21
|
-
(file: ts.SourceFile): ts.SourceFile => {
|
|
22
|
-
if (file.isDeclarationFile) return file;
|
|
23
|
-
|
|
24
|
-
const importer: ImportProgrammer = new ImportProgrammer({
|
|
25
|
-
internalPrefix: "typia_transform_",
|
|
26
|
-
runtime: environments.options.runtime,
|
|
27
|
-
});
|
|
28
|
-
const context: ITypiaContext = {
|
|
29
|
-
...environments,
|
|
30
|
-
transformer,
|
|
31
|
-
importer,
|
|
32
|
-
};
|
|
33
|
-
checkJsDocParsingMode.get(context, file);
|
|
34
|
-
|
|
35
|
-
file = ts.visitEachChild(
|
|
36
|
-
file,
|
|
37
|
-
(node) =>
|
|
38
|
-
iterate_node({
|
|
39
|
-
context,
|
|
40
|
-
node,
|
|
41
|
-
}),
|
|
42
|
-
transformer,
|
|
43
|
-
);
|
|
44
|
-
const index: number = find_import_injection_index(file);
|
|
45
|
-
return ts.factory.updateSourceFile(
|
|
46
|
-
file,
|
|
47
|
-
[
|
|
48
|
-
...file.statements.slice(0, index),
|
|
49
|
-
...importer.toStatements(),
|
|
50
|
-
...file.statements.slice(index),
|
|
51
|
-
],
|
|
52
|
-
false,
|
|
53
|
-
file.referencedFiles,
|
|
54
|
-
file.typeReferenceDirectives,
|
|
55
|
-
file.hasNoDefaultLib,
|
|
56
|
-
file.libReferenceDirectives,
|
|
57
|
-
);
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
const iterate_node = (props: {
|
|
61
|
-
context: ITypiaContext;
|
|
62
|
-
node: ts.Node;
|
|
63
|
-
}): ts.Node =>
|
|
64
|
-
ts.visitEachChild(
|
|
65
|
-
try_transform_node(props) ?? props.node,
|
|
66
|
-
(node) =>
|
|
67
|
-
iterate_node({
|
|
68
|
-
context: props.context,
|
|
69
|
-
node,
|
|
70
|
-
}),
|
|
71
|
-
props.context.transformer,
|
|
72
|
-
);
|
|
73
|
-
|
|
74
|
-
const try_transform_node = (props: {
|
|
75
|
-
context: ITypiaContext;
|
|
76
|
-
node: ts.Node;
|
|
77
|
-
}): ts.Node | null => {
|
|
78
|
-
try {
|
|
79
|
-
return NodeTransformer.transform(props);
|
|
80
|
-
} catch (exp) {
|
|
81
|
-
// ONLY ACCEPT TRANSFORMER-ERROR
|
|
82
|
-
if (!isTransformerError(exp)) throw exp;
|
|
83
|
-
|
|
84
|
-
// REPORT DIAGNOSTIC
|
|
85
|
-
const diagnostic
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
error
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
) {
|
|
125
|
-
context.extras.addDiagnostic(
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
},
|
|
143
|
-
);
|
|
1
|
+
import { ITypiaContext, ImportProgrammer } from "@typia/core";
|
|
2
|
+
import { Singleton } from "@typia/utils";
|
|
3
|
+
import ts from "typescript";
|
|
4
|
+
|
|
5
|
+
import { NodeTransformer } from "./NodeTransformer";
|
|
6
|
+
import { TransformerError } from "./TransformerError";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* TypeScript source file transformer for typia.
|
|
10
|
+
*
|
|
11
|
+
* Entry point for typia's compile-time transformation. Traverses AST nodes,
|
|
12
|
+
* transforms `typia.*` function calls into optimized runtime code, and injects
|
|
13
|
+
* required imports. Skips declaration files.
|
|
14
|
+
*
|
|
15
|
+
* @author Jeongho Nam - https://github.com/samchon
|
|
16
|
+
*/
|
|
17
|
+
export namespace FileTransformer {
|
|
18
|
+
export const transform =
|
|
19
|
+
(environments: Omit<ITypiaContext, "transformer" | "importer">) =>
|
|
20
|
+
(transformer: ts.TransformationContext) =>
|
|
21
|
+
(file: ts.SourceFile): ts.SourceFile => {
|
|
22
|
+
if (file.isDeclarationFile) return file;
|
|
23
|
+
|
|
24
|
+
const importer: ImportProgrammer = new ImportProgrammer({
|
|
25
|
+
internalPrefix: "typia_transform_",
|
|
26
|
+
runtime: environments.options.runtime,
|
|
27
|
+
});
|
|
28
|
+
const context: ITypiaContext = {
|
|
29
|
+
...environments,
|
|
30
|
+
transformer,
|
|
31
|
+
importer,
|
|
32
|
+
};
|
|
33
|
+
checkJsDocParsingMode.get(context, file);
|
|
34
|
+
|
|
35
|
+
file = ts.visitEachChild(
|
|
36
|
+
file,
|
|
37
|
+
(node) =>
|
|
38
|
+
iterate_node({
|
|
39
|
+
context,
|
|
40
|
+
node,
|
|
41
|
+
}),
|
|
42
|
+
transformer,
|
|
43
|
+
);
|
|
44
|
+
const index: number = find_import_injection_index(file);
|
|
45
|
+
return ts.factory.updateSourceFile(
|
|
46
|
+
file,
|
|
47
|
+
[
|
|
48
|
+
...file.statements.slice(0, index),
|
|
49
|
+
...importer.toStatements(),
|
|
50
|
+
...file.statements.slice(index),
|
|
51
|
+
],
|
|
52
|
+
false,
|
|
53
|
+
file.referencedFiles,
|
|
54
|
+
file.typeReferenceDirectives,
|
|
55
|
+
file.hasNoDefaultLib,
|
|
56
|
+
file.libReferenceDirectives,
|
|
57
|
+
);
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const iterate_node = (props: {
|
|
61
|
+
context: ITypiaContext;
|
|
62
|
+
node: ts.Node;
|
|
63
|
+
}): ts.Node =>
|
|
64
|
+
ts.visitEachChild(
|
|
65
|
+
try_transform_node(props) ?? props.node,
|
|
66
|
+
(node) =>
|
|
67
|
+
iterate_node({
|
|
68
|
+
context: props.context,
|
|
69
|
+
node,
|
|
70
|
+
}),
|
|
71
|
+
props.context.transformer,
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
const try_transform_node = (props: {
|
|
75
|
+
context: ITypiaContext;
|
|
76
|
+
node: ts.Node;
|
|
77
|
+
}): ts.Node | null => {
|
|
78
|
+
try {
|
|
79
|
+
return NodeTransformer.transform(props);
|
|
80
|
+
} catch (exp) {
|
|
81
|
+
// ONLY ACCEPT TRANSFORMER-ERROR
|
|
82
|
+
if (!isTransformerError(exp)) throw exp;
|
|
83
|
+
|
|
84
|
+
// REPORT DIAGNOSTIC
|
|
85
|
+
const diagnostic: ts.Diagnostic = {
|
|
86
|
+
file: props.node.getSourceFile(),
|
|
87
|
+
start: props.node.getStart(),
|
|
88
|
+
length: props.node.getWidth(),
|
|
89
|
+
messageText: exp.message,
|
|
90
|
+
category: ts.DiagnosticCategory.Error,
|
|
91
|
+
code: `(${exp.code})` as any,
|
|
92
|
+
};
|
|
93
|
+
props.context.extras.addDiagnostic(diagnostic);
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const find_import_injection_index = (file: ts.SourceFile): number => {
|
|
99
|
+
let i: number = 0;
|
|
100
|
+
for (; i < file.statements.length; ++i) {
|
|
101
|
+
const stmt: ts.Statement = file.statements[i]!;
|
|
102
|
+
if (
|
|
103
|
+
ts.isExpressionStatement(stmt) &&
|
|
104
|
+
ts.isStringLiteralLike(stmt.expression) &&
|
|
105
|
+
stmt.expression.text.startsWith("use ")
|
|
106
|
+
)
|
|
107
|
+
continue;
|
|
108
|
+
break;
|
|
109
|
+
}
|
|
110
|
+
return i;
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const isTransformerError = (error: any): error is TransformerError =>
|
|
115
|
+
typeof error === "object" &&
|
|
116
|
+
error !== null &&
|
|
117
|
+
error.constructor.name === "TransformerError" &&
|
|
118
|
+
typeof error.code === "string" &&
|
|
119
|
+
typeof error.message === "string";
|
|
120
|
+
|
|
121
|
+
const checkJsDocParsingMode = new Singleton(
|
|
122
|
+
(context: ITypiaContext, file: ts.SourceFile) => {
|
|
123
|
+
const jsDocParsingMode = (file as any).jsDocParsingMode;
|
|
124
|
+
if (typeof jsDocParsingMode === "number" && jsDocParsingMode !== 0) {
|
|
125
|
+
context.extras.addDiagnostic({
|
|
126
|
+
file,
|
|
127
|
+
start: 0,
|
|
128
|
+
length: 0,
|
|
129
|
+
messageText: [
|
|
130
|
+
`Run "npx typia setup" or "npx typia patch" command again.`,
|
|
131
|
+
``,
|
|
132
|
+
`Since TypeScript v5.3 update, "tsc" no more parses JSDoc comments. Therefore, "typia" also cannot utilize those JSDoc comments too, and it damages on some features of "typia" like "comment tags" or "JSON schema" generator.`,
|
|
133
|
+
``,
|
|
134
|
+
`To solve this problem, run "npx typia setup" or "npx typia patch" command to hack the TypeScript compiler to revive the JSDoc parsing feature.`,
|
|
135
|
+
``,
|
|
136
|
+
` - reference: https://github.com/microsoft/TypeScript/pull/55739`,
|
|
137
|
+
].join("\n"),
|
|
138
|
+
category: ts.DiagnosticCategory.Warning,
|
|
139
|
+
code: `(typia setup)` as any,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
},
|
|
143
|
+
);
|
|
@@ -1,226 +1,89 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
} from "@typia/
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
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
|
-
|
|
89
|
-
|
|
90
|
-
): {
|
|
91
|
-
application: ILlmApplication.__IPrimitive;
|
|
92
|
-
type: ts.Type;
|
|
93
|
-
node: ts.TypeNode;
|
|
94
|
-
config:
|
|
95
|
-
| Partial<
|
|
96
|
-
ILlmSchema.IConfig & {
|
|
97
|
-
equals: boolean;
|
|
98
|
-
}
|
|
99
|
-
>
|
|
100
|
-
| undefined;
|
|
101
|
-
} | null => {
|
|
102
|
-
// GET GENERIC ARGUMENT
|
|
103
|
-
if (!props.expression.typeArguments?.length)
|
|
104
|
-
throw new TransformerError({
|
|
105
|
-
code: `typia.llm.${method}`,
|
|
106
|
-
message: "no generic argument.",
|
|
107
|
-
});
|
|
108
|
-
const top: ts.Node = props.expression.typeArguments[0]!;
|
|
109
|
-
if (ts.isTypeNode(top) === false) return null;
|
|
110
|
-
|
|
111
|
-
// GET TYPE
|
|
112
|
-
const config:
|
|
113
|
-
| Partial<
|
|
114
|
-
ILlmSchema.IConfig & {
|
|
115
|
-
equals: boolean;
|
|
116
|
-
}
|
|
117
|
-
>
|
|
118
|
-
| undefined = LlmMetadataFactory.getConfig({
|
|
119
|
-
context: props.context,
|
|
120
|
-
method,
|
|
121
|
-
node: props.expression.typeArguments[1],
|
|
122
|
-
});
|
|
123
|
-
const type: ts.Type = props.context.checker.getTypeFromTypeNode(top);
|
|
124
|
-
|
|
125
|
-
// VALIDATE TYPE
|
|
126
|
-
const analyze = (validate: boolean): MetadataSchema => {
|
|
127
|
-
const result: ValidationPipe<MetadataSchema, MetadataFactory.IError> =
|
|
128
|
-
MetadataFactory.analyze({
|
|
129
|
-
checker: props.context.checker,
|
|
130
|
-
transformer: props.context.transformer,
|
|
131
|
-
options: {
|
|
132
|
-
absorb: validate,
|
|
133
|
-
escape: true,
|
|
134
|
-
constant: true,
|
|
135
|
-
functional: true,
|
|
136
|
-
validate:
|
|
137
|
-
validate === true
|
|
138
|
-
? (next) =>
|
|
139
|
-
LlmApplicationProgrammer.validate({
|
|
140
|
-
config,
|
|
141
|
-
metadata: next.metadata,
|
|
142
|
-
explore: next.explore,
|
|
143
|
-
top: next.top,
|
|
144
|
-
})
|
|
145
|
-
: undefined,
|
|
146
|
-
},
|
|
147
|
-
components: new MetadataCollection({
|
|
148
|
-
replace: MetadataCollection.replace,
|
|
149
|
-
}),
|
|
150
|
-
type,
|
|
151
|
-
});
|
|
152
|
-
if (result.success === false)
|
|
153
|
-
throw TransformerError.from({
|
|
154
|
-
code: `typia.llm.${method}`,
|
|
155
|
-
errors: result.errors,
|
|
156
|
-
});
|
|
157
|
-
return result.data;
|
|
158
|
-
};
|
|
159
|
-
analyze(true);
|
|
160
|
-
|
|
161
|
-
// GENERATE LLM APPLICATION
|
|
162
|
-
return {
|
|
163
|
-
application: LlmApplicationProgrammer.writeApplication({
|
|
164
|
-
context: props.context,
|
|
165
|
-
modulo: props.modulo,
|
|
166
|
-
metadata: analyze(false),
|
|
167
|
-
config,
|
|
168
|
-
name: top.getFullText().trim(),
|
|
169
|
-
}),
|
|
170
|
-
node: top,
|
|
171
|
-
type,
|
|
172
|
-
config,
|
|
173
|
-
};
|
|
174
|
-
};
|
|
175
|
-
|
|
176
|
-
export const getConfigArgument = (props: {
|
|
177
|
-
context: ITypiaContext;
|
|
178
|
-
argument: ts.Expression;
|
|
179
|
-
equals?: boolean | undefined;
|
|
180
|
-
}) => {
|
|
181
|
-
const satisfiesTypeNode: ts.TypeNode = ts.factory.createTypeReferenceNode(
|
|
182
|
-
ts.factory.createIdentifier("Partial"),
|
|
183
|
-
[
|
|
184
|
-
ts.factory.createTypeReferenceNode(
|
|
185
|
-
ts.factory.createIdentifier("Pick"),
|
|
186
|
-
[
|
|
187
|
-
ts.factory.createImportTypeNode(
|
|
188
|
-
ts.factory.createLiteralTypeNode(
|
|
189
|
-
ts.factory.createStringLiteral("typia"),
|
|
190
|
-
),
|
|
191
|
-
undefined,
|
|
192
|
-
ts.factory.createQualifiedName(
|
|
193
|
-
ts.factory.createIdentifier("ILlmApplication"),
|
|
194
|
-
ts.factory.createIdentifier("IConfig"),
|
|
195
|
-
),
|
|
196
|
-
undefined,
|
|
197
|
-
false,
|
|
198
|
-
),
|
|
199
|
-
ts.factory.createUnionTypeNode([
|
|
200
|
-
ts.factory.createLiteralTypeNode(
|
|
201
|
-
ts.factory.createStringLiteral("validate"),
|
|
202
|
-
),
|
|
203
|
-
]),
|
|
204
|
-
],
|
|
205
|
-
),
|
|
206
|
-
],
|
|
207
|
-
);
|
|
208
|
-
return ts.factory.createObjectLiteralExpression(
|
|
209
|
-
[
|
|
210
|
-
ts.factory.createSpreadAssignment(
|
|
211
|
-
ts.factory.createSatisfiesExpression(
|
|
212
|
-
props.argument,
|
|
213
|
-
satisfiesTypeNode,
|
|
214
|
-
),
|
|
215
|
-
),
|
|
216
|
-
ts.factory.createPropertyAssignment(
|
|
217
|
-
"equals",
|
|
218
|
-
props.equals === true
|
|
219
|
-
? ts.factory.createTrue()
|
|
220
|
-
: ts.factory.createFalse(),
|
|
221
|
-
),
|
|
222
|
-
],
|
|
223
|
-
true,
|
|
224
|
-
);
|
|
225
|
-
};
|
|
226
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
LlmApplicationProgrammer,
|
|
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 LlmApplicationTransformer {
|
|
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.application",
|
|
20
|
+
message: "no generic argument.",
|
|
21
|
+
});
|
|
22
|
+
const top: ts.Node = props.expression.typeArguments[0]!;
|
|
23
|
+
if (ts.isTypeNode(top) === false) return props.expression;
|
|
24
|
+
|
|
25
|
+
// GET CONFIG
|
|
26
|
+
const config:
|
|
27
|
+
| Partial<
|
|
28
|
+
ILlmSchema.IConfig & {
|
|
29
|
+
equals: boolean;
|
|
30
|
+
}
|
|
31
|
+
>
|
|
32
|
+
| undefined = LlmMetadataFactory.getConfig({
|
|
33
|
+
context: props.context,
|
|
34
|
+
method: "application",
|
|
35
|
+
node: props.expression.typeArguments[1],
|
|
36
|
+
});
|
|
37
|
+
const type: ts.Type = props.context.checker.getTypeFromTypeNode(top);
|
|
38
|
+
|
|
39
|
+
// VALIDATE TYPE
|
|
40
|
+
const analyze = (validate: boolean): MetadataSchema => {
|
|
41
|
+
const result: ValidationPipe<MetadataSchema, MetadataFactory.IError> =
|
|
42
|
+
MetadataFactory.analyze({
|
|
43
|
+
checker: props.context.checker,
|
|
44
|
+
transformer: props.context.transformer,
|
|
45
|
+
options: {
|
|
46
|
+
absorb: validate,
|
|
47
|
+
escape: true,
|
|
48
|
+
constant: true,
|
|
49
|
+
functional: true,
|
|
50
|
+
validate:
|
|
51
|
+
validate === true
|
|
52
|
+
? (next) =>
|
|
53
|
+
LlmApplicationProgrammer.validate({
|
|
54
|
+
config,
|
|
55
|
+
metadata: next.metadata,
|
|
56
|
+
explore: next.explore,
|
|
57
|
+
top: next.top,
|
|
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
|
+
configArgument:
|
|
83
|
+
props.expression.arguments?.[0] !== undefined
|
|
84
|
+
? props.expression.arguments[0]
|
|
85
|
+
: undefined,
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
}
|