Skip to content

Commit 8d66956

Browse files
authored
fix(#423): avoid coercing non-validators to bigint (#427)
* stop coercing mapped attribute values into BigInt inside addBigIntValidation, limiting conversion to real validator attributes * add regression test proving @map-decorated BigInt fields create and update successfully
1 parent 4240ecd commit 8d66956

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

packages/orm/src/client/crud/validator/utils.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,19 +125,19 @@ export function addBigIntValidation(schema: z.ZodBigInt, attributes: AttributeAp
125125
if (val === undefined) {
126126
continue;
127127
}
128-
const bigIntVal = BigInt(val);
128+
129129
match(attr.name)
130130
.with('@gt', () => {
131-
result = result.gt(bigIntVal);
131+
result = result.gt(BigInt(val));
132132
})
133133
.with('@gte', () => {
134-
result = result.gte(bigIntVal);
134+
result = result.gte(BigInt(val));
135135
})
136136
.with('@lt', () => {
137-
result = result.lt(bigIntVal);
137+
result = result.lt(BigInt(val));
138138
})
139139
.with('@lte', () => {
140-
result = result.lte(bigIntVal);
140+
result = result.lte(BigInt(val));
141141
});
142142
}
143143
return result;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { createTestClient } from '@zenstackhq/testtools';
2+
import { describe, expect, it } from 'vitest';
3+
4+
describe('Regression for issue #423', () => {
5+
it('verifies non-validation attributes for BigInt does not fail', async () => {
6+
const db = await createTestClient(
7+
`
8+
model SampleBigInt {
9+
id BigInt @id @map("sample_id")
10+
data String
11+
}`,
12+
);
13+
await expect(db.SampleBigInt.create({ data: { data: "create", id: BigInt(1) } })).resolves.toMatchObject({ id: BigInt(1), data: "create" });
14+
await expect(db.SampleBigInt.update({ data: { data: "update" }, where: { id: BigInt(1) } })).resolves.toMatchObject({ id: BigInt(1), data: "update" });
15+
});
16+
});

0 commit comments

Comments
 (0)