Skip to content

Commit

Permalink
Tighten overload to require UUID cast
Browse files Browse the repository at this point in the history
  • Loading branch information
scotttrinh committed Jan 17, 2024
1 parent acf6145 commit 9b0e5a4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
5 changes: 5 additions & 0 deletions integration-tests/stable/uuid-to-object-cast.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,10 @@ SELECT __scope_0_defaultPgVectorTest {
single internal := <default::PgVectorTest>(<std::uuid>("${inserted.id}"))
}`
);

e.select(e.PgVectorTest, () => ({
// @ts-expect-error: does not allow assignment of non UUID
internal: e.cast(e.PgVectorTest, inserted.id),
}));
});
});
16 changes: 7 additions & 9 deletions packages/generate/src/syntax/cast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
BaseType,
TypeSet,
ObjectTypeExpression,
ScalarType,
} from "./typesystem";
import { $expressionify } from "./path";
import type { orScalarLiteral } from "./castMaps";
Expand All @@ -20,18 +21,15 @@ export function cast<Target extends BaseType | ObjectTypeExpression>(
: never,
Cardinality.Empty
>;
export function cast<
Target extends BaseType | ObjectTypeExpression,
Expr extends TypeSet
>(
export function cast<Target extends ObjectTypeExpression>(
target: Target,
arg: TypeSet<ScalarType<"std::uuid">>
): $expr_Cast<Target["__element__"], Cardinality.One>;
export function cast<Target extends BaseType, Expr extends TypeSet>(
target: Target,
expr: orScalarLiteral<Expr>
): $expr_Cast<
Target extends BaseType
? Target
: Target extends ObjectTypeExpression
? Target["__element__"]
: never,
Target,
Cardinality extends Expr["__cardinality__"]
? Cardinality.One
: Expr["__cardinality__"]
Expand Down

0 comments on commit 9b0e5a4

Please sign in to comment.