@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.
@@ -1,88 +1,88 @@
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
- ? (next) =>
48
- LlmSchemaProgrammer.validate({
49
- config,
50
- metadata: next.metadata,
51
- explore: next.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.schema",
63
- errors: result.errors,
64
- });
65
- return result.data;
66
- };
67
- analyze(true);
68
-
69
- // GENERATE LLM SCHEMA
70
- const expr = LlmSchemaProgrammer.write({
71
- context: props.context,
72
- metadata: analyze(false),
73
- config,
74
- });
75
-
76
- // If user provided $defs argument and expression is a function, call it with $defs
77
- if (
78
- props.expression.arguments?.[0] !== undefined &&
79
- ts.isArrowFunction(expr)
80
- ) {
81
- return ts.factory.createCallExpression(expr, undefined, [
82
- props.expression.arguments[0]!,
83
- ]);
84
- }
85
-
86
- return expr;
87
- };
88
- }
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
+ ? (next) =>
48
+ LlmSchemaProgrammer.validate({
49
+ config,
50
+ metadata: next.metadata,
51
+ explore: next.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.schema",
63
+ errors: result.errors,
64
+ });
65
+ return result.data;
66
+ };
67
+ analyze(true);
68
+
69
+ // GENERATE LLM SCHEMA
70
+ const expr = LlmSchemaProgrammer.write({
71
+ context: props.context,
72
+ metadata: analyze(false),
73
+ config,
74
+ });
75
+
76
+ // If user provided $defs argument and expression is a function, call it with $defs
77
+ if (
78
+ props.expression.arguments?.[0] !== undefined &&
79
+ ts.isArrowFunction(expr)
80
+ ) {
81
+ return ts.factory.createCallExpression(expr, undefined, [
82
+ props.expression.arguments[0]!,
83
+ ]);
84
+ }
85
+
86
+ return expr;
87
+ };
88
+ }
@@ -1,86 +1,86 @@
1
- import {
2
- LlmMetadataFactory,
3
- LlmStructuredOutputProgrammer,
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 LlmStructuredOutputTransformer {
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.structuredOutput",
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 & { equals: boolean }> =
28
- LlmMetadataFactory.getConfig({
29
- context: props.context,
30
- method: "structuredOutput",
31
- node: props.expression.typeArguments[1],
32
- }) as Partial<ILlmSchema.IConfig & { equals: boolean }>;
33
-
34
- const type: ts.Type = props.context.checker.getTypeFromTypeNode(top);
35
-
36
- if (type.isTypeParameter())
37
- throw new TransformerError({
38
- code: "typia.llm.structuredOutput",
39
- message: "non-specified generic argument.",
40
- });
41
-
42
- // VALIDATE TYPE
43
- const analyze = (validate: boolean): MetadataSchema => {
44
- const result: ValidationPipe<MetadataSchema, MetadataFactory.IError> =
45
- MetadataFactory.analyze({
46
- checker: props.context.checker,
47
- transformer: props.context.transformer,
48
- options: {
49
- absorb: validate,
50
- escape: true,
51
- constant: true,
52
- validate:
53
- validate === true
54
- ? (next) =>
55
- LlmStructuredOutputProgrammer.validate({
56
- config,
57
- metadata: next.metadata,
58
- explore: next.explore,
59
- })
60
- : undefined,
61
- },
62
- components: new MetadataCollection({
63
- replace: MetadataCollection.replace,
64
- }),
65
- type,
66
- });
67
- if (result.success === false)
68
- throw TransformerError.from({
69
- code: "typia.llm.structuredOutput",
70
- errors: result.errors,
71
- });
72
- return result.data;
73
- };
74
- analyze(true);
75
-
76
- // GENERATE CODE
77
- return LlmStructuredOutputProgrammer.write({
78
- context: props.context,
79
- modulo: props.modulo,
80
- type,
81
- metadata: analyze(false),
82
- config,
83
- name: (top as ts.TypeNode).getFullText().trim(),
84
- });
85
- };
86
- }
1
+ import {
2
+ LlmMetadataFactory,
3
+ LlmStructuredOutputProgrammer,
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 LlmStructuredOutputTransformer {
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.structuredOutput",
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 & { equals: boolean }> =
28
+ LlmMetadataFactory.getConfig({
29
+ context: props.context,
30
+ method: "structuredOutput",
31
+ node: props.expression.typeArguments[1],
32
+ }) as Partial<ILlmSchema.IConfig & { equals: boolean }>;
33
+
34
+ const type: ts.Type = props.context.checker.getTypeFromTypeNode(top);
35
+
36
+ if (type.isTypeParameter())
37
+ throw new TransformerError({
38
+ code: "typia.llm.structuredOutput",
39
+ message: "non-specified generic argument.",
40
+ });
41
+
42
+ // VALIDATE TYPE
43
+ const analyze = (validate: boolean): MetadataSchema => {
44
+ const result: ValidationPipe<MetadataSchema, MetadataFactory.IError> =
45
+ MetadataFactory.analyze({
46
+ checker: props.context.checker,
47
+ transformer: props.context.transformer,
48
+ options: {
49
+ absorb: validate,
50
+ escape: true,
51
+ constant: true,
52
+ validate:
53
+ validate === true
54
+ ? (next) =>
55
+ LlmStructuredOutputProgrammer.validate({
56
+ config,
57
+ metadata: next.metadata,
58
+ explore: next.explore,
59
+ })
60
+ : undefined,
61
+ },
62
+ components: new MetadataCollection({
63
+ replace: MetadataCollection.replace,
64
+ }),
65
+ type,
66
+ });
67
+ if (result.success === false)
68
+ throw TransformerError.from({
69
+ code: "typia.llm.structuredOutput",
70
+ errors: result.errors,
71
+ });
72
+ return result.data;
73
+ };
74
+ analyze(true);
75
+
76
+ // GENERATE CODE
77
+ return LlmStructuredOutputProgrammer.write({
78
+ context: props.context,
79
+ modulo: props.modulo,
80
+ type,
81
+ metadata: analyze(false),
82
+ config,
83
+ name: (top as ts.TypeNode).getFullText().trim(),
84
+ });
85
+ };
86
+ }