@typia/transform 12.0.0-dev.20260307 → 12.0.0-dev.20260309
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 +8 -0
- package/src/features/json/JsonApplicationTransformer.ts +7 -10
- package/src/features/json/JsonSchemaTransformer.ts +3 -15
- package/src/features/json/JsonSchemasTransformer.ts +3 -15
- package/src/features/llm/LlmApplicationTransformer.ts +66 -26
- package/src/features/llm/LlmCoerceTransformer.ts +95 -0
- package/src/features/llm/LlmControllerTransformer.ts +19 -14
- package/src/features/llm/LlmCreateCoerceTransformer.ts +84 -0
- package/src/features/llm/LlmCreateParseTransformer.ts +84 -0
- package/src/features/llm/LlmParametersTransformer.ts +4 -16
- package/src/features/llm/LlmParseTransformer.ts +95 -0
- package/src/features/llm/LlmSchemaTransformer.ts +15 -61
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
JsonApplicationProgrammer,
|
|
3
|
-
LiteralFactory,
|
|
4
3
|
MetadataCollection,
|
|
5
4
|
MetadataFactory,
|
|
6
5
|
MetadataSchema,
|
|
7
6
|
} from "@typia/core";
|
|
8
|
-
import {
|
|
7
|
+
import { ValidationPipe } from "@typia/interface";
|
|
9
8
|
import ts from "typescript";
|
|
10
9
|
|
|
11
10
|
import { ITransformProps } from "../../ITransformProps";
|
|
@@ -56,14 +55,12 @@ export namespace JsonApplicationTransformer {
|
|
|
56
55
|
errors: result.errors,
|
|
57
56
|
});
|
|
58
57
|
|
|
59
|
-
// GENERATE
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const literal: ts.Expression = LiteralFactory.write(app);
|
|
66
|
-
return literal;
|
|
58
|
+
// GENERATE JSON APPLICATION
|
|
59
|
+
return JsonApplicationProgrammer.write({
|
|
60
|
+
context: props.context,
|
|
61
|
+
version,
|
|
62
|
+
metadata: result.data,
|
|
63
|
+
});
|
|
67
64
|
};
|
|
68
65
|
|
|
69
66
|
const get_parameter =
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import {
|
|
2
2
|
JsonSchemaProgrammer,
|
|
3
3
|
JsonSchemasProgrammer,
|
|
4
|
-
LiteralFactory,
|
|
5
4
|
MetadataCollection,
|
|
6
5
|
MetadataFactory,
|
|
7
6
|
MetadataSchema,
|
|
8
7
|
} from "@typia/core";
|
|
9
|
-
import {
|
|
8
|
+
import { ValidationPipe } from "@typia/interface";
|
|
10
9
|
import ts from "typescript";
|
|
11
10
|
|
|
12
11
|
import { ITransformProps } from "../../ITransformProps";
|
|
@@ -78,22 +77,11 @@ export namespace JsonSchemaTransformer {
|
|
|
78
77
|
analyze(true);
|
|
79
78
|
|
|
80
79
|
// APPLICATION
|
|
81
|
-
|
|
80
|
+
return JsonSchemaProgrammer.write({
|
|
81
|
+
context: props.context,
|
|
82
82
|
version,
|
|
83
83
|
metadata: analyze(false),
|
|
84
84
|
});
|
|
85
|
-
return ts.factory.createAsExpression(
|
|
86
|
-
LiteralFactory.write(app),
|
|
87
|
-
props.context.importer.type({
|
|
88
|
-
file: "typia",
|
|
89
|
-
name: "IJsonSchemaUnit",
|
|
90
|
-
arguments: [
|
|
91
|
-
ts.factory.createLiteralTypeNode(
|
|
92
|
-
ts.factory.createStringLiteral(version),
|
|
93
|
-
),
|
|
94
|
-
],
|
|
95
|
-
}),
|
|
96
|
-
);
|
|
97
85
|
};
|
|
98
86
|
|
|
99
87
|
const getParameter =
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
JsonSchemasProgrammer,
|
|
3
|
-
LiteralFactory,
|
|
4
3
|
MetadataCollection,
|
|
5
4
|
MetadataFactory,
|
|
6
5
|
MetadataSchema,
|
|
7
6
|
} from "@typia/core";
|
|
8
|
-
import {
|
|
7
|
+
import { ValidationPipe } from "@typia/interface";
|
|
9
8
|
import ts from "typescript";
|
|
10
9
|
|
|
11
10
|
import { ITransformProps } from "../../ITransformProps";
|
|
@@ -88,22 +87,11 @@ export namespace JsonSchemasTransformer {
|
|
|
88
87
|
analyze(true);
|
|
89
88
|
|
|
90
89
|
// APPLICATION
|
|
91
|
-
|
|
90
|
+
return JsonSchemasProgrammer.write({
|
|
91
|
+
context: props.context,
|
|
92
92
|
version,
|
|
93
93
|
metadatas: analyze(false),
|
|
94
94
|
});
|
|
95
|
-
return ts.factory.createAsExpression(
|
|
96
|
-
LiteralFactory.write(collection),
|
|
97
|
-
props.context.importer.type({
|
|
98
|
-
file: "typia",
|
|
99
|
-
name: "IJsonSchemaCollection",
|
|
100
|
-
arguments: [
|
|
101
|
-
ts.factory.createLiteralTypeNode(
|
|
102
|
-
ts.factory.createStringLiteral(version),
|
|
103
|
-
),
|
|
104
|
-
],
|
|
105
|
-
}),
|
|
106
|
-
);
|
|
107
95
|
};
|
|
108
96
|
|
|
109
97
|
const getParameter =
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ITypiaContext,
|
|
3
|
-
LiteralFactory,
|
|
4
3
|
LlmApplicationProgrammer,
|
|
5
4
|
LlmMetadataFactory,
|
|
6
5
|
MetadataCollection,
|
|
@@ -15,31 +14,72 @@ import { TransformerError } from "../../TransformerError";
|
|
|
15
14
|
|
|
16
15
|
export namespace LlmApplicationTransformer {
|
|
17
16
|
export const transform = (props: ITransformProps): ts.Expression => {
|
|
18
|
-
|
|
19
|
-
if (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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,
|
|
30
63
|
}),
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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
|
+
});
|
|
43
83
|
};
|
|
44
84
|
|
|
45
85
|
/** @internal */
|
|
@@ -118,7 +158,7 @@ export namespace LlmApplicationTransformer {
|
|
|
118
158
|
|
|
119
159
|
// GENERATE LLM APPLICATION
|
|
120
160
|
return {
|
|
121
|
-
application: LlmApplicationProgrammer.
|
|
161
|
+
application: LlmApplicationProgrammer.writeApplication({
|
|
122
162
|
context: props.context,
|
|
123
163
|
modulo: props.modulo,
|
|
124
164
|
metadata: analyze(false),
|
|
@@ -0,0 +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
|
+
}
|
|
@@ -20,6 +20,16 @@ export namespace LlmControllerTransformer {
|
|
|
20
20
|
message: `no executor.`,
|
|
21
21
|
});
|
|
22
22
|
|
|
23
|
+
const typeNode: ts.ImportTypeNode = props.context.importer.type({
|
|
24
|
+
file: "typia",
|
|
25
|
+
name: "ILlmController",
|
|
26
|
+
arguments: [dec.node],
|
|
27
|
+
});
|
|
28
|
+
const primitiveTypeNode: ts.ImportTypeNode = props.context.importer.type({
|
|
29
|
+
file: "typia",
|
|
30
|
+
name: "ILlmApplication.__IPrimitive",
|
|
31
|
+
arguments: [dec.node],
|
|
32
|
+
});
|
|
23
33
|
const value: ts.ObjectLiteralExpression =
|
|
24
34
|
ts.factory.createObjectLiteralExpression(
|
|
25
35
|
[
|
|
@@ -41,13 +51,12 @@ export namespace LlmControllerTransformer {
|
|
|
41
51
|
props.context.importer.internal("llmApplicationFinalize"),
|
|
42
52
|
undefined,
|
|
43
53
|
[
|
|
44
|
-
ts.factory.
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}),
|
|
54
|
+
ts.factory.createAsExpression(
|
|
55
|
+
ts.factory.createSatisfiesExpression(
|
|
56
|
+
LiteralFactory.write(dec.application),
|
|
57
|
+
primitiveTypeNode,
|
|
58
|
+
),
|
|
59
|
+
primitiveTypeNode,
|
|
51
60
|
),
|
|
52
61
|
...(props.expression.arguments?.[2] !== undefined
|
|
53
62
|
? [
|
|
@@ -64,13 +73,9 @@ export namespace LlmControllerTransformer {
|
|
|
64
73
|
],
|
|
65
74
|
true,
|
|
66
75
|
);
|
|
67
|
-
return ts.factory.
|
|
68
|
-
value,
|
|
69
|
-
|
|
70
|
-
file: "typia",
|
|
71
|
-
name: "ILlmController",
|
|
72
|
-
arguments: [dec.node],
|
|
73
|
-
}),
|
|
76
|
+
return ts.factory.createAsExpression(
|
|
77
|
+
ts.factory.createSatisfiesExpression(value, typeNode),
|
|
78
|
+
typeNode,
|
|
74
79
|
);
|
|
75
80
|
};
|
|
76
81
|
}
|
|
@@ -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,5 +1,4 @@
|
|
|
1
1
|
import {
|
|
2
|
-
LiteralFactory,
|
|
3
2
|
LlmMetadataFactory,
|
|
4
3
|
LlmParametersProgrammer,
|
|
5
4
|
MetadataCollection,
|
|
@@ -13,9 +12,7 @@ import { ITransformProps } from "../../ITransformProps";
|
|
|
13
12
|
import { TransformerError } from "../../TransformerError";
|
|
14
13
|
|
|
15
14
|
export namespace LlmParametersTransformer {
|
|
16
|
-
export const transform = (
|
|
17
|
-
props: Omit<ITransformProps, "modulo">,
|
|
18
|
-
): ts.Expression => {
|
|
15
|
+
export const transform = (props: ITransformProps): ts.Expression => {
|
|
19
16
|
// GET GENERIC ARGUMENT
|
|
20
17
|
if (!props.expression.typeArguments?.length)
|
|
21
18
|
throw new TransformerError({
|
|
@@ -69,20 +66,11 @@ export namespace LlmParametersTransformer {
|
|
|
69
66
|
};
|
|
70
67
|
analyze(true);
|
|
71
68
|
|
|
72
|
-
// GENERATE LLM SCHEMA
|
|
73
|
-
|
|
69
|
+
// GENERATE LLM PARAMETERS SCHEMA
|
|
70
|
+
return LlmParametersProgrammer.write({
|
|
71
|
+
context: props.context,
|
|
74
72
|
metadata: analyze(false),
|
|
75
73
|
config,
|
|
76
74
|
});
|
|
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
75
|
};
|
|
88
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
|
+
}
|