Skip to content

Commit d02c1de

Browse files
committed
refactor(sqlite-demo): use castAs for branded-id boundary casts in M:N examples
The new main baseline (TML-2605) trips the no-bare-cast ratchet on the string->branded-id casts in the M:N example helpers (+10). Replace the bare `as PostId`/`as TagId` casts with castAs<T> to keep lint:casts at delta 0. Behaviour unchanged (casts are erased at runtime). Signed-off-by: Alexey Orlenko's AI Agent <robot@aqrln.net>
1 parent 65aaf96 commit d02c1de

4 files changed

Lines changed: 18 additions & 12 deletions

File tree

examples/prisma-next-demo-sqlite/src/orm-client/connect-post-tags.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { DefaultModelRow } from '@prisma-next/sql-orm-client';
22
import type { Runtime } from '@prisma-next/sql-runtime';
3+
import { castAs } from '@prisma-next/utils/casts';
34
import type { Contract } from '../prisma/contract.d';
45
import { createOrmClient } from './client';
56

@@ -17,13 +18,13 @@ export async function ormClientConnectPostTags(
1718
runtime: Runtime,
1819
) {
1920
const db = createOrmClient(runtime);
20-
const updated = await db.Post.where({ id: postId as PostId }).update({
21-
tags: (t) => t.connect(tagIds.map((id) => ({ id: id as TagId }))),
21+
const updated = await db.Post.where({ id: castAs<PostId>(postId) }).update({
22+
tags: (t) => t.connect(tagIds.map((id) => ({ id: castAs<TagId>(id) }))),
2223
});
2324
if (!updated) {
2425
return null;
2526
}
2627
return db.Post.include('tags', (tag) => tag.orderBy((t) => t.label.asc()))
27-
.where({ id: postId as PostId })
28+
.where({ id: castAs<PostId>(postId) })
2829
.first();
2930
}

examples/prisma-next-demo-sqlite/src/orm-client/create-post-with-tags.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { DefaultModelRow } from '@prisma-next/sql-orm-client';
22
import type { Runtime } from '@prisma-next/sql-runtime';
3+
import { castAs } from '@prisma-next/utils/casts';
34
import type { Contract } from '../prisma/contract.d';
45
import { createOrmClient } from './client';
56

@@ -24,14 +25,16 @@ export async function ormClientCreatePostWithTags(
2425
) {
2526
const db = createOrmClient(runtime);
2627
return db.Post.create({
27-
id: input.id as PostRow['id'],
28+
id: castAs<PostRow['id']>(input.id),
2829
title: input.title,
29-
userId: input.userId as PostRow['userId'],
30+
userId: castAs<PostRow['userId']>(input.userId),
3031
tags: (t) =>
3132
t.create(
32-
input.tags.map((tag) => ({
33-
label: tag.label,
34-
})) as Array<{ label: TagRow['label'] }>,
33+
castAs<Array<{ label: TagRow['label'] }>>(
34+
input.tags.map((tag) => ({
35+
label: tag.label,
36+
})),
37+
),
3538
),
3639
});
3740
}

examples/prisma-next-demo-sqlite/src/orm-client/disconnect-post-tags.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { DefaultModelRow } from '@prisma-next/sql-orm-client';
22
import type { Runtime } from '@prisma-next/sql-runtime';
3+
import { castAs } from '@prisma-next/utils/casts';
34
import type { Contract } from '../prisma/contract.d';
45
import { createOrmClient } from './client';
56

@@ -16,13 +17,13 @@ export async function ormClientDisconnectPostTags(
1617
runtime: Runtime,
1718
) {
1819
const db = createOrmClient(runtime);
19-
const updated = await db.Post.where({ id: postId as PostId }).update({
20-
tags: (t) => t.disconnect(tagIds.map((id) => ({ id: id as TagId }))),
20+
const updated = await db.Post.where({ id: castAs<PostId>(postId) }).update({
21+
tags: (t) => t.disconnect(tagIds.map((id) => ({ id: castAs<TagId>(id) }))),
2122
});
2223
if (!updated) {
2324
return null;
2425
}
2526
return db.Post.include('tags', (tag) => tag.orderBy((t) => t.label.asc()))
26-
.where({ id: postId as PostId })
27+
.where({ id: castAs<PostId>(postId) })
2728
.first();
2829
}

examples/prisma-next-demo-sqlite/src/orm-client/get-post-tags.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { DefaultModelRow } from '@prisma-next/sql-orm-client';
22
import type { Runtime } from '@prisma-next/sql-runtime';
3+
import { castAs } from '@prisma-next/utils/casts';
34
import type { Contract } from '../prisma/contract.d';
45
import { createOrmClient } from './client';
56

@@ -13,6 +14,6 @@ type PostId = DefaultModelRow<Contract, 'Post'>['id'];
1314
export async function ormClientGetPostTags(postId: string, runtime: Runtime) {
1415
const db = createOrmClient(runtime);
1516
return db.Post.include('tags', (tag) => tag.select('id', 'label').orderBy((t) => t.label.asc()))
16-
.where({ id: postId as PostId })
17+
.where({ id: castAs<PostId>(postId) })
1718
.first();
1819
}

0 commit comments

Comments
 (0)