@typia/transform 12.0.1 → 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,76 +1,76 @@
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
- ? (next) =>
48
- LlmParametersProgrammer.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.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
- }
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
+ ? (next) =>
48
+ LlmParametersProgrammer.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.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
+ }
@@ -1,95 +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
- ? (next) =>
61
- LlmParseProgrammer.validate({
62
- config,
63
- metadata: next.metadata,
64
- explore: next.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
+ 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
+ ? (next) =>
61
+ LlmParseProgrammer.validate({
62
+ config,
63
+ metadata: next.metadata,
64
+ explore: next.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,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
+ }