Skip to content

Commit 0e1aca2

Browse files
committed
Schema satisfies T as T
1 parent 75a009d commit 0e1aca2

File tree

4 files changed

+53
-35
lines changed

4 files changed

+53
-35
lines changed

packages/transform/src/features/llm/LlmApplicationTransformer.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,22 @@ export namespace LlmApplicationTransformer {
1717
export const transform = (props: ITransformProps): ts.Expression => {
1818
const dec = decompose("application", props);
1919
if (dec === null) return props.expression;
20+
21+
const typeNode: ts.ImportTypeNode = props.context.importer.type({
22+
file: "typia",
23+
name: "ILlmApplication.__IPrimitive",
24+
arguments: [dec.node],
25+
});
2026
return ts.factory.createCallExpression(
2127
props.context.importer.internal("llmApplicationFinalize"),
2228
[dec.node],
2329
[
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-
}),
30+
ts.factory.createAsExpression(
31+
ts.factory.createSatisfiesExpression(
32+
LiteralFactory.write(dec.application),
33+
typeNode,
34+
),
35+
typeNode,
3136
),
3237
...(props.expression.arguments?.[0] !== undefined
3338
? [

packages/transform/src/features/llm/LlmControllerTransformer.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ export namespace LlmControllerTransformer {
2020
message: `no executor.`,
2121
});
2222

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+
});
2333
const value: ts.ObjectLiteralExpression =
2434
ts.factory.createObjectLiteralExpression(
2535
[
@@ -41,13 +51,12 @@ export namespace LlmControllerTransformer {
4151
props.context.importer.internal("llmApplicationFinalize"),
4252
undefined,
4353
[
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-
}),
54+
ts.factory.createAsExpression(
55+
ts.factory.createSatisfiesExpression(
56+
LiteralFactory.write(dec.application),
57+
primitiveTypeNode,
58+
),
59+
primitiveTypeNode,
5160
),
5261
...(props.expression.arguments?.[2] !== undefined
5362
? [
@@ -64,13 +73,9 @@ export namespace LlmControllerTransformer {
6473
],
6574
true,
6675
);
67-
return ts.factory.createSatisfiesExpression(
68-
value,
69-
props.context.importer.type({
70-
file: "typia",
71-
name: "ILlmController",
72-
arguments: [dec.node],
73-
}),
76+
return ts.factory.createAsExpression(
77+
ts.factory.createSatisfiesExpression(value, typeNode),
78+
typeNode,
7479
);
7580
};
7681
}

packages/transform/src/features/llm/LlmParametersTransformer.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,25 @@ export namespace LlmParametersTransformer {
6969
};
7070
analyze(true);
7171

72-
// GENERATE LLM SCHEMA
73-
const out: ILlmSchema.IParameters = LlmParametersProgrammer.write({
74-
metadata: analyze(false),
75-
config,
72+
// GENERATE LLM PARAMETERS SCHEMA
73+
const typeNode: ts.ImportTypeNode = props.context.importer.type({
74+
file: "typia",
75+
name: ts.factory.createQualifiedName(
76+
ts.factory.createIdentifier("ILlmSchema"),
77+
ts.factory.createIdentifier("IParameters"),
78+
),
7679
});
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"),
80+
return ts.factory.createAsExpression(
81+
ts.factory.createSatisfiesExpression(
82+
LiteralFactory.write(
83+
LlmParametersProgrammer.write({
84+
metadata: analyze(false),
85+
config,
86+
}),
8487
),
85-
}),
88+
typeNode,
89+
),
90+
typeNode,
8691
);
8792
};
8893
}

packages/transform/src/features/llm/LlmSchemaTransformer.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,11 @@ export namespace LlmSchemaTransformer {
7878
file: "typia",
7979
name: "ILlmSchema",
8080
});
81-
const literal = ts.factory.createSatisfiesExpression(
82-
LiteralFactory.write(out.schema),
81+
const literal = ts.factory.createAsExpression(
82+
ts.factory.createSatisfiesExpression(
83+
LiteralFactory.write(out.schema),
84+
schemaTypeNode,
85+
),
8386
schemaTypeNode,
8487
);
8588
if (Object.keys(out.$defs).length === 0) return literal;

0 commit comments

Comments
 (0)