Skip to content

Commit 07aa1cf

Browse files
committed
fix(sql-orm-client): drop non-null assertions + unused castAs in M:N junction artifacts
biome `noNonNullAssertion` (error-on-warnings) flagged the `joinOnPairs[0]!` / `correlationPairs[0]!` non-null assertions. Narrow with a truthy guard on the destructured first element instead, which also removes the castAs (so its import goes too). Signed-off-by: Alexey Orlenko's AI Agent <robot@aqrln.net>
1 parent a00850c commit 07aa1cf

1 file changed

Lines changed: 5 additions & 4 deletions

File tree

packages/3-extensions/sql-orm-client/src/query-plan-select.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import {
2525
} from '@prisma-next/sql-relational-core/ast';
2626
import { codecRefForStorageColumn } from '@prisma-next/sql-relational-core/codec-descriptor-registry';
2727
import type { SqlQueryPlan } from '@prisma-next/sql-relational-core/plan';
28-
import { castAs } from '@prisma-next/utils/casts';
2928
import { ifDefined } from '@prisma-next/utils/defined';
3029
import {
3130
type PolymorphismInfo,
@@ -358,18 +357,20 @@ function buildManyToManyJunctionArtifacts(
358357
ColumnRef.of(childTableRef, targetColumns[i] ?? junctionCol),
359358
),
360359
);
360+
const firstJoinPair = joinOnPairs[0];
361361
const joinOn: AnyExpression =
362-
joinOnPairs.length === 1 ? castAs<AnyExpression>(joinOnPairs[0]!) : AndExpr.of(joinOnPairs);
362+
joinOnPairs.length === 1 && firstJoinPair ? firstJoinPair : AndExpr.of(joinOnPairs);
363363

364364
const correlationPairs = parentColumns.map((junctionCol, i) =>
365365
BinaryExpr.eq(
366366
ColumnRef.of(junctionTable, junctionCol),
367367
ColumnRef.of(parentTableName, parentLocalColumns[i] ?? junctionCol),
368368
),
369369
);
370+
const firstCorrelationPair = correlationPairs[0];
370371
const whereExpr: AnyExpression =
371-
correlationPairs.length === 1
372-
? castAs<AnyExpression>(correlationPairs[0]!)
372+
correlationPairs.length === 1 && firstCorrelationPair
373+
? firstCorrelationPair
373374
: AndExpr.of(correlationPairs);
374375

375376
const junctionJoin = JoinAst.inner(

0 commit comments

Comments
 (0)