@typia/transform 12.0.0-dev.20260307-2 → 12.0.0-dev.20260310

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.
Files changed (171) hide show
  1. package/lib/CallExpressionTransformer.js +8 -0
  2. package/lib/CallExpressionTransformer.js.map +1 -1
  3. package/lib/CallExpressionTransformer.mjs +8 -0
  4. package/lib/CallExpressionTransformer.mjs.map +1 -1
  5. package/lib/features/json/JsonApplicationTransformer.js +3 -4
  6. package/lib/features/json/JsonApplicationTransformer.js.map +1 -1
  7. package/lib/features/json/JsonApplicationTransformer.mjs +4 -5
  8. package/lib/features/json/JsonApplicationTransformer.mjs.map +1 -1
  9. package/lib/features/json/JsonSchemaTransformer.js +2 -8
  10. package/lib/features/json/JsonSchemaTransformer.js.map +1 -1
  11. package/lib/features/json/JsonSchemaTransformer.mjs +3 -9
  12. package/lib/features/json/JsonSchemaTransformer.mjs.map +1 -1
  13. package/lib/features/json/JsonSchemasTransformer.js +2 -8
  14. package/lib/features/json/JsonSchemasTransformer.js.map +1 -1
  15. package/lib/features/json/JsonSchemasTransformer.mjs +3 -9
  16. package/lib/features/json/JsonSchemasTransformer.mjs.map +1 -1
  17. package/lib/features/llm/LlmApplicationTransformer.js +56 -20
  18. package/lib/features/llm/LlmApplicationTransformer.js.map +1 -1
  19. package/lib/features/llm/LlmApplicationTransformer.mjs +56 -20
  20. package/lib/features/llm/LlmApplicationTransformer.mjs.map +1 -1
  21. package/lib/features/llm/LlmCoerceTransformer.d.ts +5 -0
  22. package/lib/features/llm/LlmCoerceTransformer.js +81 -0
  23. package/lib/features/llm/LlmCoerceTransformer.js.map +1 -0
  24. package/lib/features/llm/LlmCoerceTransformer.mjs +77 -0
  25. package/lib/features/llm/LlmCoerceTransformer.mjs.map +1 -0
  26. package/lib/features/llm/LlmControllerTransformer.js +12 -10
  27. package/lib/features/llm/LlmControllerTransformer.js.map +1 -1
  28. package/lib/features/llm/LlmControllerTransformer.mjs +12 -10
  29. package/lib/features/llm/LlmControllerTransformer.mjs.map +1 -1
  30. package/lib/features/llm/LlmCreateCoerceTransformer.d.ts +5 -0
  31. package/lib/features/llm/LlmCreateCoerceTransformer.js +75 -0
  32. package/lib/features/llm/LlmCreateCoerceTransformer.js.map +1 -0
  33. package/lib/features/llm/LlmCreateCoerceTransformer.mjs +71 -0
  34. package/lib/features/llm/LlmCreateCoerceTransformer.mjs.map +1 -0
  35. package/lib/features/llm/LlmCreateParseTransformer.d.ts +5 -0
  36. package/lib/features/llm/LlmCreateParseTransformer.js +75 -0
  37. package/lib/features/llm/LlmCreateParseTransformer.js.map +1 -0
  38. package/lib/features/llm/LlmCreateParseTransformer.mjs +71 -0
  39. package/lib/features/llm/LlmCreateParseTransformer.mjs.map +1 -0
  40. package/lib/features/llm/LlmParametersTransformer.d.ts +1 -1
  41. package/lib/features/llm/LlmParametersTransformer.js +3 -6
  42. package/lib/features/llm/LlmParametersTransformer.js.map +1 -1
  43. package/lib/features/llm/LlmParametersTransformer.mjs +4 -7
  44. package/lib/features/llm/LlmParametersTransformer.mjs.map +1 -1
  45. package/lib/features/llm/LlmParseTransformer.d.ts +5 -0
  46. package/lib/features/llm/LlmParseTransformer.js +81 -0
  47. package/lib/features/llm/LlmParseTransformer.js.map +1 -0
  48. package/lib/features/llm/LlmParseTransformer.mjs +77 -0
  49. package/lib/features/llm/LlmParseTransformer.mjs.map +1 -0
  50. package/lib/features/llm/LlmSchemaTransformer.d.ts +1 -1
  51. package/lib/features/llm/LlmSchemaTransformer.js +10 -25
  52. package/lib/features/llm/LlmSchemaTransformer.js.map +1 -1
  53. package/lib/features/llm/LlmSchemaTransformer.mjs +11 -26
  54. package/lib/features/llm/LlmSchemaTransformer.mjs.map +1 -1
  55. package/package.json +4 -4
  56. package/src/CallExpressionTransformer.ts +579 -571
  57. package/src/FileTransformer.ts +143 -143
  58. package/src/ITransformProps.ts +20 -20
  59. package/src/ImportTransformer.ts +262 -262
  60. package/src/NodeTransformer.ts +25 -25
  61. package/src/TransformerError.ts +85 -85
  62. package/src/TypiaGenerator.ts +172 -172
  63. package/src/features/AssertTransformer.ts +24 -24
  64. package/src/features/CreateAssertTransformer.ts +24 -24
  65. package/src/features/CreateIsTransformer.ts +18 -18
  66. package/src/features/CreateRandomTransformer.ts +42 -42
  67. package/src/features/CreateValidateTransformer.ts +18 -18
  68. package/src/features/IsTransformer.ts +18 -18
  69. package/src/features/RandomTransformer.ts +40 -40
  70. package/src/features/ValidateTransformer.ts +18 -18
  71. package/src/features/functional/FunctionalGenericTransformer.ts +55 -55
  72. package/src/features/http/CreateHttpAssertFormDataTransformer.ts +13 -13
  73. package/src/features/http/CreateHttpAssertHeadersTransformer.ts +13 -13
  74. package/src/features/http/CreateHttpAssertQueryTransformer.ts +13 -13
  75. package/src/features/http/CreateHttpFormDataTransformer.ts +13 -13
  76. package/src/features/http/CreateHttpHeadersTransformer.ts +13 -13
  77. package/src/features/http/CreateHttpIsFormDataTransformer.ts +13 -13
  78. package/src/features/http/CreateHttpIsHeadersTransformer.ts +13 -13
  79. package/src/features/http/CreateHttpIsQueryTransformer.ts +13 -13
  80. package/src/features/http/CreateHttpParameterTransformer.ts +13 -13
  81. package/src/features/http/CreateHttpQueryTransformer.ts +13 -13
  82. package/src/features/http/CreateHttpValidateFormDataTransformer.ts +13 -13
  83. package/src/features/http/CreateHttpValidateHeadersTransformer.ts +13 -13
  84. package/src/features/http/CreateHttpValidateQueryTransformer.ts +13 -13
  85. package/src/features/http/HttpAssertFormDataTransformer.ts +13 -13
  86. package/src/features/http/HttpAssertHeadersTransformer.ts +13 -13
  87. package/src/features/http/HttpAssertQueryTransformer.ts +13 -13
  88. package/src/features/http/HttpFormDataTransformer.ts +13 -13
  89. package/src/features/http/HttpHeadersTransformer.ts +13 -13
  90. package/src/features/http/HttpIsFormDataTransformer.ts +13 -13
  91. package/src/features/http/HttpIsHeadersTransformer.ts +13 -13
  92. package/src/features/http/HttpIsQueryTransformer.ts +13 -13
  93. package/src/features/http/HttpParameterTransformer.ts +13 -13
  94. package/src/features/http/HttpQueryTransformer.ts +13 -13
  95. package/src/features/http/HttpValidateFormDataTransformer.ts +13 -13
  96. package/src/features/http/HttpValidateHeadersTransformer.ts +13 -13
  97. package/src/features/http/HttpValidateQueryTransformer.ts +13 -13
  98. package/src/features/json/JsonApplicationTransformer.ts +99 -102
  99. package/src/features/json/JsonAssertParseTransformer.ts +13 -13
  100. package/src/features/json/JsonAssertStringifyTransformer.ts +13 -13
  101. package/src/features/json/JsonCreateAssertParseTransformer.ts +13 -13
  102. package/src/features/json/JsonCreateAssertStringifyTransformer.ts +13 -13
  103. package/src/features/json/JsonCreateIsParseTransformer.ts +13 -13
  104. package/src/features/json/JsonCreateIsStringifyTransformer.ts +13 -13
  105. package/src/features/json/JsonCreateStringifyTransformer.ts +13 -13
  106. package/src/features/json/JsonCreateValidateParseTransformer.ts +13 -13
  107. package/src/features/json/JsonCreateValidateStringifyProgrammer.ts +13 -13
  108. package/src/features/json/JsonIsParseTransformer.ts +13 -13
  109. package/src/features/json/JsonIsStringifyTransformer.ts +13 -13
  110. package/src/features/json/JsonSchemaTransformer.ts +120 -132
  111. package/src/features/json/JsonSchemasTransformer.ts +130 -142
  112. package/src/features/json/JsonStringifyTransformer.ts +13 -13
  113. package/src/features/json/JsonValidateParseTransformer.ts +13 -13
  114. package/src/features/json/JsonValidateStringifyTransformer.ts +13 -13
  115. package/src/features/llm/LlmApplicationTransformer.ts +224 -184
  116. package/src/features/llm/LlmCoerceTransformer.ts +95 -0
  117. package/src/features/llm/LlmControllerTransformer.ts +81 -76
  118. package/src/features/llm/LlmCreateCoerceTransformer.ts +84 -0
  119. package/src/features/llm/LlmCreateParseTransformer.ts +84 -0
  120. package/src/features/llm/LlmParametersTransformer.ts +76 -88
  121. package/src/features/llm/LlmParseTransformer.ts +95 -0
  122. package/src/features/llm/LlmSchemaTransformer.ts +87 -133
  123. package/src/features/misc/MiscAssertCloneTransformer.ts +13 -13
  124. package/src/features/misc/MiscAssertPruneTransformer.ts +13 -13
  125. package/src/features/misc/MiscCloneTransformer.ts +13 -13
  126. package/src/features/misc/MiscCreateAssertCloneTransformer.ts +13 -13
  127. package/src/features/misc/MiscCreateAssertPruneTransformer.ts +13 -13
  128. package/src/features/misc/MiscCreateCloneTransformer.ts +13 -13
  129. package/src/features/misc/MiscCreateIsCloneTransformer.ts +13 -13
  130. package/src/features/misc/MiscCreateIsPruneTransformer.ts +13 -13
  131. package/src/features/misc/MiscCreatePruneTransformer.ts +13 -13
  132. package/src/features/misc/MiscCreateValidateCloneTransformer.ts +13 -13
  133. package/src/features/misc/MiscCreateValidatePruneTransformer.ts +13 -13
  134. package/src/features/misc/MiscIsCloneTransformer.ts +13 -13
  135. package/src/features/misc/MiscIsPruneTransformer.ts +13 -13
  136. package/src/features/misc/MiscLiteralsTransformer.ts +34 -34
  137. package/src/features/misc/MiscPruneTransformer.ts +13 -13
  138. package/src/features/misc/MiscValidateCloneTransformer.ts +13 -13
  139. package/src/features/misc/MiscValidatePruneTransformer.ts +13 -13
  140. package/src/features/notations/NotationAssertGeneralTransformer.ts +19 -19
  141. package/src/features/notations/NotationCreateAssertGeneralTransformer.ts +19 -19
  142. package/src/features/notations/NotationCreateGeneralTransformer.ts +19 -19
  143. package/src/features/notations/NotationCreateIsGeneralTransformer.ts +19 -19
  144. package/src/features/notations/NotationCreateValidateGeneralTransformer.ts +19 -19
  145. package/src/features/notations/NotationGeneralTransformer.ts +18 -18
  146. package/src/features/notations/NotationIsGeneralTransformer.ts +19 -19
  147. package/src/features/notations/NotationValidateGeneralTransformer.ts +19 -19
  148. package/src/features/protobuf/ProtobufAssertDecodeTransformer.ts +13 -13
  149. package/src/features/protobuf/ProtobufAssertEncodeTransformer.ts +13 -13
  150. package/src/features/protobuf/ProtobufCreateAssertDecodeTransformer.ts +13 -13
  151. package/src/features/protobuf/ProtobufCreateAssertEncodeTransformer.ts +13 -13
  152. package/src/features/protobuf/ProtobufCreateDecodeTransformer.ts +13 -13
  153. package/src/features/protobuf/ProtobufCreateEncodeTransformer.ts +13 -13
  154. package/src/features/protobuf/ProtobufCreateIsDecodeTransformer.ts +13 -13
  155. package/src/features/protobuf/ProtobufCreateIsEncodeTransformer.ts +13 -13
  156. package/src/features/protobuf/ProtobufCreateValidateDecodeTransformer.ts +13 -13
  157. package/src/features/protobuf/ProtobufCreateValidateEncodeTransformer.ts +13 -13
  158. package/src/features/protobuf/ProtobufDecodeTransformer.ts +13 -13
  159. package/src/features/protobuf/ProtobufEncodeTransformer.ts +13 -13
  160. package/src/features/protobuf/ProtobufIsDecodeTransformer.ts +13 -13
  161. package/src/features/protobuf/ProtobufIsEncodeTransformer.ts +13 -13
  162. package/src/features/protobuf/ProtobufMessageTransformer.ts +34 -34
  163. package/src/features/protobuf/ProtobufValidateDecodeTransformer.ts +13 -13
  164. package/src/features/protobuf/ProtobufValidateEncodeTransformer.ts +13 -13
  165. package/src/features/reflect/ReflectMetadataTransformer.ts +69 -69
  166. package/src/features/reflect/ReflectNameTransformer.ts +81 -81
  167. package/src/features/reflect/ReflectSchemaTransformer.ts +65 -65
  168. package/src/features/reflect/ReflectSchemasTransformer.ts +69 -69
  169. package/src/index.ts +7 -7
  170. package/src/internal/GenericTransformer.ts +101 -101
  171. package/src/transform.ts +68 -68
@@ -1,184 +1,224 @@
1
- import {
2
- ITypiaContext,
3
- LiteralFactory,
4
- LlmApplicationProgrammer,
5
- LlmMetadataFactory,
6
- MetadataCollection,
7
- MetadataFactory,
8
- MetadataSchema,
9
- } from "@typia/core";
10
- import { ILlmApplication, ILlmSchema, ValidationPipe } from "@typia/interface";
11
- import ts from "typescript";
12
-
13
- import { ITransformProps } from "../../ITransformProps";
14
- import { TransformerError } from "../../TransformerError";
15
-
16
- export namespace LlmApplicationTransformer {
17
- export const transform = (props: ITransformProps): ts.Expression => {
18
- const dec = decompose("application", props);
19
- if (dec === null) return props.expression;
20
- return ts.factory.createCallExpression(
21
- props.context.importer.internal("llmApplicationFinalize"),
22
- [dec.node],
23
- [
24
- ts.factory.createSatisfiesExpression(
25
- LiteralFactory.write(dec.application),
26
- props.context.importer.type({
27
- file: "typia",
28
- name: "ILlmApplication.__IPrimitive",
29
- arguments: [dec.node],
30
- }),
31
- ),
32
- ...(props.expression.arguments?.[0] !== undefined
33
- ? [
34
- getConfigArgument({
35
- context: props.context,
36
- argument: props.expression.arguments[0],
37
- equals: dec.config?.equals,
38
- }),
39
- ]
40
- : []),
41
- ],
42
- );
43
- };
44
-
45
- /** @internal */
46
- export const decompose = (
47
- method: string,
48
- props: ITransformProps,
49
- ): {
50
- application: ILlmApplication.__IPrimitive;
51
- type: ts.Type;
52
- node: ts.TypeNode;
53
- config:
54
- | Partial<
55
- ILlmSchema.IConfig & {
56
- equals: boolean;
57
- }
58
- >
59
- | undefined;
60
- } | null => {
61
- // GET GENERIC ARGUMENT
62
- if (!props.expression.typeArguments?.length)
63
- throw new TransformerError({
64
- code: `typia.llm.${method}`,
65
- message: "no generic argument.",
66
- });
67
- const top: ts.Node = props.expression.typeArguments[0]!;
68
- if (ts.isTypeNode(top) === false) return null;
69
-
70
- // GET TYPE
71
- const config:
72
- | Partial<
73
- ILlmSchema.IConfig & {
74
- equals: boolean;
75
- }
76
- >
77
- | undefined = LlmMetadataFactory.getConfig({
78
- context: props.context,
79
- method,
80
- node: props.expression.typeArguments[1],
81
- });
82
- const type: ts.Type = props.context.checker.getTypeFromTypeNode(top);
83
-
84
- // VALIDATE TYPE
85
- const analyze = (validate: boolean): MetadataSchema => {
86
- const result: ValidationPipe<MetadataSchema, MetadataFactory.IError> =
87
- MetadataFactory.analyze({
88
- checker: props.context.checker,
89
- transformer: props.context.transformer,
90
- options: {
91
- absorb: validate,
92
- escape: true,
93
- constant: true,
94
- functional: true,
95
- validate:
96
- validate === true
97
- ? (metadata, explore) =>
98
- LlmApplicationProgrammer.validate({
99
- config,
100
- metadata,
101
- explore,
102
- })
103
- : undefined,
104
- },
105
- components: new MetadataCollection({
106
- replace: MetadataCollection.replace,
107
- }),
108
- type,
109
- });
110
- if (result.success === false)
111
- throw TransformerError.from({
112
- code: `typia.llm.${method}`,
113
- errors: result.errors,
114
- });
115
- return result.data;
116
- };
117
- analyze(true);
118
-
119
- // GENERATE LLM APPLICATION
120
- return {
121
- application: LlmApplicationProgrammer.write({
122
- context: props.context,
123
- modulo: props.modulo,
124
- metadata: analyze(false),
125
- config,
126
- name: top.getFullText().trim(),
127
- }),
128
- node: top,
129
- type,
130
- config,
131
- };
132
- };
133
-
134
- export const getConfigArgument = (props: {
135
- context: ITypiaContext;
136
- argument: ts.Expression;
137
- equals?: boolean | undefined;
138
- }) => {
139
- const satisfiesTypeNode: ts.TypeNode = ts.factory.createTypeReferenceNode(
140
- ts.factory.createIdentifier("Partial"),
141
- [
142
- ts.factory.createTypeReferenceNode(
143
- ts.factory.createIdentifier("Pick"),
144
- [
145
- ts.factory.createImportTypeNode(
146
- ts.factory.createLiteralTypeNode(
147
- ts.factory.createStringLiteral("typia"),
148
- ),
149
- undefined,
150
- ts.factory.createQualifiedName(
151
- ts.factory.createIdentifier("ILlmApplication"),
152
- ts.factory.createIdentifier("IConfig"),
153
- ),
154
- undefined,
155
- false,
156
- ),
157
- ts.factory.createUnionTypeNode([
158
- ts.factory.createLiteralTypeNode(
159
- ts.factory.createStringLiteral("validate"),
160
- ),
161
- ]),
162
- ],
163
- ),
164
- ],
165
- );
166
- return ts.factory.createObjectLiteralExpression(
167
- [
168
- ts.factory.createSpreadAssignment(
169
- ts.factory.createSatisfiesExpression(
170
- props.argument,
171
- satisfiesTypeNode,
172
- ),
173
- ),
174
- ts.factory.createPropertyAssignment(
175
- "equals",
176
- props.equals === true
177
- ? ts.factory.createTrue()
178
- : ts.factory.createFalse(),
179
- ),
180
- ],
181
- true,
182
- );
183
- };
184
- }
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
+ }
@@ -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
+ }
@@ -1,76 +1,81 @@
1
- import { LiteralFactory } from "@typia/core";
2
- import ts from "typescript";
3
-
4
- import { ITransformProps } from "../../ITransformProps";
5
- import { TransformerError } from "../../TransformerError";
6
- import { LlmApplicationTransformer } from "./LlmApplicationTransformer";
7
-
8
- export namespace LlmControllerTransformer {
9
- export const transform = (props: ITransformProps): ts.Expression => {
10
- const dec = LlmApplicationTransformer.decompose("application", props);
11
- if (dec === null) return props.expression;
12
- else if (props.expression.arguments[0] === undefined)
13
- throw new TransformerError({
14
- code: `typia.llm.controller`,
15
- message: `no identifier name.`,
16
- });
17
- else if (props.expression.arguments[1] === undefined)
18
- throw new TransformerError({
19
- code: `typia.llm.controller`,
20
- message: `no executor.`,
21
- });
22
-
23
- const value: ts.ObjectLiteralExpression =
24
- ts.factory.createObjectLiteralExpression(
25
- [
26
- ts.factory.createPropertyAssignment(
27
- "protocol",
28
- ts.factory.createStringLiteral("class"),
29
- ),
30
- ts.factory.createPropertyAssignment(
31
- "name",
32
- props.expression.arguments[0],
33
- ),
34
- ts.factory.createPropertyAssignment(
35
- "execute",
36
- props.expression.arguments[1],
37
- ),
38
- ts.factory.createPropertyAssignment(
39
- "application",
40
- ts.factory.createCallExpression(
41
- props.context.importer.internal("llmApplicationFinalize"),
42
- undefined,
43
- [
44
- ts.factory.createSatisfiesExpression(
45
- LiteralFactory.write(dec.application),
46
- props.context.importer.type({
47
- file: "typia",
48
- name: "ILlmApplication.__IPrimitive",
49
- arguments: [dec.node],
50
- }),
51
- ),
52
- ...(props.expression.arguments?.[2] !== undefined
53
- ? [
54
- LlmApplicationTransformer.getConfigArgument({
55
- context: props.context,
56
- argument: props.expression.arguments[2],
57
- equals: dec.config?.equals,
58
- }),
59
- ]
60
- : []),
61
- ],
62
- ),
63
- ),
64
- ],
65
- true,
66
- );
67
- return ts.factory.createSatisfiesExpression(
68
- value,
69
- props.context.importer.type({
70
- file: "typia",
71
- name: "ILlmController",
72
- arguments: [dec.node],
73
- }),
74
- );
75
- };
76
- }
1
+ import { LiteralFactory } from "@typia/core";
2
+ import ts from "typescript";
3
+
4
+ import { ITransformProps } from "../../ITransformProps";
5
+ import { TransformerError } from "../../TransformerError";
6
+ import { LlmApplicationTransformer } from "./LlmApplicationTransformer";
7
+
8
+ export namespace LlmControllerTransformer {
9
+ export const transform = (props: ITransformProps): ts.Expression => {
10
+ const dec = LlmApplicationTransformer.decompose("application", props);
11
+ if (dec === null) return props.expression;
12
+ else if (props.expression.arguments[0] === undefined)
13
+ throw new TransformerError({
14
+ code: `typia.llm.controller`,
15
+ message: `no identifier name.`,
16
+ });
17
+ else if (props.expression.arguments[1] === undefined)
18
+ throw new TransformerError({
19
+ code: `typia.llm.controller`,
20
+ message: `no executor.`,
21
+ });
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
+ });
33
+ const value: ts.ObjectLiteralExpression =
34
+ ts.factory.createObjectLiteralExpression(
35
+ [
36
+ ts.factory.createPropertyAssignment(
37
+ "protocol",
38
+ ts.factory.createStringLiteral("class"),
39
+ ),
40
+ ts.factory.createPropertyAssignment(
41
+ "name",
42
+ props.expression.arguments[0],
43
+ ),
44
+ ts.factory.createPropertyAssignment(
45
+ "execute",
46
+ props.expression.arguments[1],
47
+ ),
48
+ ts.factory.createPropertyAssignment(
49
+ "application",
50
+ ts.factory.createCallExpression(
51
+ props.context.importer.internal("llmApplicationFinalize"),
52
+ undefined,
53
+ [
54
+ ts.factory.createAsExpression(
55
+ ts.factory.createSatisfiesExpression(
56
+ LiteralFactory.write(dec.application),
57
+ primitiveTypeNode,
58
+ ),
59
+ primitiveTypeNode,
60
+ ),
61
+ ...(props.expression.arguments?.[2] !== undefined
62
+ ? [
63
+ LlmApplicationTransformer.getConfigArgument({
64
+ context: props.context,
65
+ argument: props.expression.arguments[2],
66
+ equals: dec.config?.equals,
67
+ }),
68
+ ]
69
+ : []),
70
+ ],
71
+ ),
72
+ ),
73
+ ],
74
+ true,
75
+ );
76
+ return ts.factory.createAsExpression(
77
+ ts.factory.createSatisfiesExpression(value, typeNode),
78
+ typeNode,
79
+ );
80
+ };
81
+ }