Skip to content

Commit

Permalink
Support UUID cast to Object (#693)
Browse files Browse the repository at this point in the history
  • Loading branch information
scotttrinh authored Jan 17, 2024
1 parent 95cde2b commit 316a398
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
17 changes: 17 additions & 0 deletions integration-tests/lts/casts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,21 @@ describe("casts", () => {

tc.assert<tc.IsExact<(typeof expr)["__element__"], $Movie>>(true);
});

test("UUID to object cast", () => {
const expr = e.cast(
e.Movie,
e.cast(e.uuid, "00000000-0000-0000-0000-000000000000")
);

assert.equal(
expr.toEdgeQL(),
`<default::Movie>(<std::uuid>("00000000-0000-0000-0000-000000000000"))`
);

tc.assert<tc.IsExact<(typeof expr)["__element__"], $Movie>>(true);

// @ts-expect-error: does not allow assignment of non UUID
e.cast(e.Movie, 42);
});
});
5 changes: 5 additions & 0 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,6 +21,10 @@ export function cast<Target extends BaseType | ObjectTypeExpression>(
: never,
Cardinality.Empty
>;
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>
Expand Down

0 comments on commit 316a398

Please sign in to comment.