typia 9.5.0 → 9.6.0

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 (45) hide show
  1. package/lib/internal/_llmApplicationFinalize.d.mts +3 -1
  2. package/lib/internal/_llmApplicationFinalize.d.ts +3 -1
  3. package/lib/internal/_llmApplicationFinalize.js +2 -1
  4. package/lib/internal/_llmApplicationFinalize.js.map +1 -1
  5. package/lib/internal/_llmApplicationFinalize.mjs +1 -0
  6. package/lib/internal/_validateReport.js +9 -1
  7. package/lib/internal/_validateReport.js.map +1 -1
  8. package/lib/internal/_validateReport.mjs +8 -1
  9. package/lib/llm.d.mts +24 -2
  10. package/lib/llm.d.ts +24 -2
  11. package/lib/llm.js.map +1 -1
  12. package/lib/programmers/ValidateProgrammer.js +14 -8
  13. package/lib/programmers/ValidateProgrammer.js.map +1 -1
  14. package/lib/programmers/ValidateProgrammer.mjs +14 -8
  15. package/lib/programmers/internal/check_dynamic_properties.js +7 -1
  16. package/lib/programmers/internal/check_dynamic_properties.js.map +1 -1
  17. package/lib/programmers/internal/check_dynamic_properties.mjs +7 -1
  18. package/lib/programmers/internal/check_object.js.map +1 -1
  19. package/lib/programmers/llm/LlmApplicationProgrammer.d.mts +3 -1
  20. package/lib/programmers/llm/LlmApplicationProgrammer.d.ts +3 -1
  21. package/lib/programmers/llm/LlmApplicationProgrammer.js +16 -14
  22. package/lib/programmers/llm/LlmApplicationProgrammer.js.map +1 -1
  23. package/lib/programmers/llm/LlmApplicationProgrammer.mjs +15 -13
  24. package/lib/programmers/llm/LlmModelPredicator.d.mts +3 -1
  25. package/lib/programmers/llm/LlmModelPredicator.d.ts +3 -1
  26. package/lib/programmers/llm/LlmModelPredicator.js.map +1 -1
  27. package/lib/transformers/features/llm/LlmApplicationTransformer.d.mts +9 -0
  28. package/lib/transformers/features/llm/LlmApplicationTransformer.d.ts +9 -0
  29. package/lib/transformers/features/llm/LlmApplicationTransformer.js +32 -5
  30. package/lib/transformers/features/llm/LlmApplicationTransformer.js.map +1 -1
  31. package/lib/transformers/features/llm/LlmApplicationTransformer.mjs +31 -4
  32. package/lib/transformers/features/llm/LlmControllerTransformer.js +8 -5
  33. package/lib/transformers/features/llm/LlmControllerTransformer.js.map +1 -1
  34. package/lib/transformers/features/llm/LlmControllerTransformer.mjs +7 -4
  35. package/package.json +2 -2
  36. package/src/internal/_llmApplicationFinalize.ts +6 -1
  37. package/src/internal/_validateReport.ts +9 -1
  38. package/src/llm.ts +28 -2
  39. package/src/programmers/ValidateProgrammer.ts +19 -9
  40. package/src/programmers/internal/check_dynamic_properties.ts +30 -1
  41. package/src/programmers/internal/check_object.ts +4 -1
  42. package/src/programmers/llm/LlmApplicationProgrammer.ts +30 -14
  43. package/src/programmers/llm/LlmModelPredicator.ts +7 -1
  44. package/src/transformers/features/llm/LlmApplicationTransformer.ts +95 -10
  45. package/src/transformers/features/llm/LlmControllerTransformer.ts +7 -8
@@ -117,35 +117,37 @@ export namespace LlmApplicationProgrammer {
117
117
  const prefix: string = `LLM application's function (${JSON.stringify(name)})`;
118
118
  if (func.output.size() && func.output.isRequired() === false)
119
119
  output.push(
120
- `${prefix}'s return type must not be union type with undefined.`,
120
+ `${prefix} return type cannot be optional (union with undefined).`,
121
121
  );
122
122
  if (/^[0-9]/.test(name[0] ?? "") === true)
123
- output.push(`${prefix} name must not start with a number.`);
123
+ output.push(`${prefix} name cannot start with a number.`);
124
124
  if (/^[a-zA-Z0-9_-]+$/.test(name) === false)
125
125
  output.push(
126
- `${prefix} name must be alphanumeric with underscore or hyphen.`,
126
+ `${prefix} name must contain only alphanumeric characters, underscores, or hyphens.`,
127
127
  );
128
128
  if (name.length > 64)
129
- output.push(`${prefix} name must not exceed 64 characters.`);
129
+ output.push(`${prefix} name cannot exceed 64 characters.`);
130
130
  if (func.parameters.length !== 0 && func.parameters.length !== 1)
131
- output.push(`${prefix} must have a single parameter.`);
131
+ output.push(
132
+ `${prefix} must have exactly one parameter or no parameters.`,
133
+ );
132
134
  if (func.parameters.length !== 0) {
133
135
  const type: Metadata = func.parameters[0]!.type;
134
136
  if (type.size() !== 1 || type.objects.length !== 1)
135
- output.push(`${prefix}'s parameter must be an object type.`);
137
+ output.push(`${prefix} parameter must be a single object type.`);
136
138
  else {
137
139
  if (
138
140
  type.objects[0]!.type.properties.some(
139
141
  (p) => p.key.isSoleLiteral() === false,
140
142
  )
141
143
  )
142
- output.push(`${prefix}'s parameter must not have dynamic keys.`);
144
+ output.push(`${prefix} parameter cannot have dynamic property keys.`);
143
145
  if (type.isRequired() === false)
144
146
  output.push(
145
- `${prefix}'s parameter must not be union type with undefined.`,
147
+ `${prefix} parameter cannot be optional (union with undefined).`,
146
148
  );
147
149
  if (type.nullable === true)
148
- output.push(`${prefix}'s parameter must not be nullable.`);
150
+ output.push(`${prefix} parameter cannot be nullable.`);
149
151
  }
150
152
  }
151
153
  return output;
@@ -156,7 +158,11 @@ export namespace LlmApplicationProgrammer {
156
158
  context: ITypiaContext;
157
159
  modulo: ts.LeftHandSideExpression;
158
160
  metadata: Metadata;
159
- config?: Partial<ILlmSchema.ModelConfig[Model]>;
161
+ config?: Partial<
162
+ ILlmSchema.ModelConfig[Model] & {
163
+ equals: boolean;
164
+ }
165
+ >;
160
166
  name?: string;
161
167
  }): ILlmApplication<Model> => {
162
168
  const metadata: Metadata = Metadata.unalias(props.metadata);
@@ -197,6 +203,7 @@ export namespace LlmApplicationProgrammer {
197
203
  context: props.context,
198
204
  modulo: props.modulo,
199
205
  className: props.name,
206
+ config: props.config,
200
207
  components: application.components,
201
208
  function: func,
202
209
  errors: errorMessages,
@@ -228,6 +235,13 @@ export namespace LlmApplicationProgrammer {
228
235
  parameter: MetadataParameter | null;
229
236
  errors: string[];
230
237
  className?: string;
238
+ config:
239
+ | Partial<
240
+ ILlmSchema.ModelConfig[Model] & {
241
+ equals: boolean;
242
+ }
243
+ >
244
+ | undefined;
231
245
  }): ILlmFunction<Model> | null => {
232
246
  const parameters: ILlmSchema.ModelParameters[Model] | null =
233
247
  writeParameters({
@@ -272,12 +286,13 @@ export namespace LlmApplicationProgrammer {
272
286
  })(),
273
287
  deprecated: props.function.deprecated,
274
288
  tags: props.function.tags,
275
- validate: writeValidadtor({
289
+ validate: writeValidator({
276
290
  context: props.context,
277
291
  modulo: props.modulo,
278
292
  parameter: props.parameter,
279
293
  name: props.function.name,
280
294
  className: props.className,
295
+ equals: props.config?.equals ?? false,
281
296
  }),
282
297
  };
283
298
  };
@@ -346,11 +361,12 @@ export namespace LlmApplicationProgrammer {
346
361
  return result.value;
347
362
  };
348
363
 
349
- const writeValidadtor = (props: {
364
+ const writeValidator = (props: {
350
365
  context: ITypiaContext;
351
366
  modulo: ts.LeftHandSideExpression;
352
367
  parameter: MetadataParameter | null;
353
368
  name: string;
369
+ equals: boolean;
354
370
  className?: string;
355
371
  }): ((props: unknown) => IValidation<unknown>) => {
356
372
  if (props.parameter === null)
@@ -360,7 +376,7 @@ export namespace LlmApplicationProgrammer {
360
376
  TypeFactory.keyword("any"),
361
377
  ),
362
378
  config: {
363
- equals: false,
379
+ equals: props.equals,
364
380
  },
365
381
  name: undefined,
366
382
  }) as any;
@@ -375,7 +391,7 @@ export namespace LlmApplicationProgrammer {
375
391
  ...props,
376
392
  type: props.parameter.tsType!,
377
393
  config: {
378
- equals: false,
394
+ equals: props.equals,
379
395
  },
380
396
  name: props.className
381
397
  ? `Parameters<${props.className}[${JSON.stringify(props.name)}]>[0]`
@@ -19,7 +19,13 @@ export namespace LlmModelPredicator {
19
19
  method: string;
20
20
  model: ILlmSchema.Model;
21
21
  node: ts.TypeNode | undefined;
22
- }): Partial<ILlmSchema.ModelConfig[ILlmSchema.Model]> | undefined => {
22
+ }):
23
+ | Partial<
24
+ ILlmSchema.ModelConfig[ILlmSchema.Model] & {
25
+ equals: boolean;
26
+ }
27
+ >
28
+ | undefined => {
23
29
  if (props.node === undefined) return undefined;
24
30
  const type: ts.Type = props.context.checker.getTypeFromTypeNode(props.node);
25
31
  const collection: MetadataCollection = new MetadataCollection();
@@ -15,6 +15,7 @@ import { LlmModelPredicator } from "../../../programmers/llm/LlmModelPredicator"
15
15
  import { ValidationPipe } from "../../../typings/ValidationPipe";
16
16
 
17
17
  import { ITransformProps } from "../../ITransformProps";
18
+ import { ITypiaContext } from "../../ITypiaContext";
18
19
  import { TransformerError } from "../../TransformerError";
19
20
 
20
21
  export namespace LlmApplicationTransformer {
@@ -43,14 +44,13 @@ export namespace LlmApplicationTransformer {
43
44
  value: literal,
44
45
  }),
45
46
  ts.factory.createExpressionStatement(
46
- ts.factory.createCallExpression(
47
- props.context.importer.internal("llmApplicationFinalize"),
48
- undefined,
49
- [
50
- ts.factory.createIdentifier("application"),
51
- props.expression.arguments[0],
52
- ],
53
- ),
47
+ finalize({
48
+ context: props.context,
49
+ value: ts.factory.createIdentifier("application"),
50
+ argument: props.expression.arguments[0]!,
51
+ equals: dec.config?.equals,
52
+ model: dec.application.model,
53
+ }),
54
54
  ),
55
55
  ts.factory.createReturnStatement(
56
56
  ts.factory.createIdentifier("application"),
@@ -71,6 +71,13 @@ export namespace LlmApplicationTransformer {
71
71
  application: ILlmApplication<ILlmSchema.Model>;
72
72
  type: ts.Type;
73
73
  node: ts.TypeNode;
74
+ config:
75
+ | Partial<
76
+ ILlmSchema.IConfig & {
77
+ equals: boolean;
78
+ }
79
+ >
80
+ | undefined;
74
81
  } | null => {
75
82
  // GET GENERIC ARGUMENT
76
83
  if (!props.expression.typeArguments?.length)
@@ -87,12 +94,18 @@ export namespace LlmApplicationTransformer {
87
94
  method,
88
95
  node: props.expression.typeArguments[1],
89
96
  });
90
- const config: Partial<ILlmSchema.IConfig> = LlmModelPredicator.getConfig({
97
+ const config:
98
+ | Partial<
99
+ ILlmSchema.IConfig & {
100
+ equals: boolean;
101
+ }
102
+ >
103
+ | undefined = LlmModelPredicator.getConfig({
91
104
  context: props.context,
92
105
  method,
93
106
  model,
94
107
  node: props.expression.typeArguments[2],
95
- }) as Partial<ILlmSchema.IConfig>;
108
+ });
96
109
  const type: ts.Type = props.context.checker.getTypeFromTypeNode(top);
97
110
 
98
111
  // VALIDATE TYPE
@@ -140,6 +153,78 @@ export namespace LlmApplicationTransformer {
140
153
  }),
141
154
  node: top,
142
155
  type,
156
+ config,
143
157
  };
144
158
  };
159
+
160
+ export const finalize = (props: {
161
+ context: ITypiaContext;
162
+ value: ts.Expression;
163
+ argument: ts.Expression;
164
+ equals?: boolean;
165
+ model: ILlmSchema.Model;
166
+ }) => {
167
+ const satisfiesTypeNode: ts.TypeNode = ts.factory.createTypeReferenceNode(
168
+ ts.factory.createIdentifier("Partial"),
169
+ [
170
+ ts.factory.createTypeReferenceNode(
171
+ ts.factory.createIdentifier("Pick"),
172
+ [
173
+ ts.factory.createImportTypeNode(
174
+ ts.factory.createLiteralTypeNode(
175
+ ts.factory.createStringLiteral("@samchon/openapi"),
176
+ ),
177
+ undefined,
178
+ ts.factory.createQualifiedName(
179
+ ts.factory.createIdentifier("ILlmApplication"),
180
+ ts.factory.createIdentifier("IOptions"),
181
+ ),
182
+ [
183
+ ts.factory.createLiteralTypeNode(
184
+ ts.factory.createStringLiteral(props.model),
185
+ ),
186
+ ],
187
+ false,
188
+ ),
189
+ ts.factory.createLiteralTypeNode(
190
+ ts.factory.createStringLiteral("separate"),
191
+ ),
192
+ ],
193
+ ),
194
+ ],
195
+ );
196
+ return ts.factory.createCallExpression(
197
+ props.context.importer.internal("llmApplicationFinalize"),
198
+ undefined,
199
+ [
200
+ props.value,
201
+ ts.factory.createObjectLiteralExpression(
202
+ [
203
+ ts.factory.createPropertyAssignment(
204
+ "separate",
205
+ ts.factory.createPropertyAccessChain(
206
+ ts.factory.createSatisfiesExpression(
207
+ props.argument,
208
+ satisfiesTypeNode,
209
+ ),
210
+ ts.factory.createToken(ts.SyntaxKind.QuestionDotToken),
211
+ "separate",
212
+ ),
213
+ ),
214
+ ...(typeof props.equals === "boolean"
215
+ ? [
216
+ ts.factory.createPropertyAssignment(
217
+ "equals",
218
+ props.equals === true
219
+ ? ts.factory.createTrue()
220
+ : ts.factory.createFalse(),
221
+ ),
222
+ ]
223
+ : []),
224
+ ],
225
+ true,
226
+ ),
227
+ ],
228
+ );
229
+ };
145
230
  }
@@ -63,14 +63,13 @@ export namespace LlmControllerTransformer {
63
63
  ...(props.expression.arguments?.[2] !== undefined
64
64
  ? [
65
65
  ts.factory.createExpressionStatement(
66
- ts.factory.createCallExpression(
67
- props.context.importer.internal("llmApplicationFinalize"),
68
- undefined,
69
- [
70
- ts.factory.createIdentifier("application"),
71
- props.expression.arguments[2],
72
- ],
73
- ),
66
+ LlmApplicationTransformer.finalize({
67
+ context: props.context,
68
+ value: ts.factory.createIdentifier("application"),
69
+ argument: props.expression.arguments[2]!,
70
+ equals: dec.config?.equals,
71
+ model: dec.application.model,
72
+ }),
74
73
  ),
75
74
  ]
76
75
  : []),