Skip to content

Commit 797f9af

Browse files
committed
fix(client): improve big int parsing
1 parent b9ed52f commit 797f9af

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

presto-client/src/client.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,17 @@ import {
1010
} from './types'
1111

1212
function digitsToBigInt(_: string, value: unknown, { source }: { source: string }) {
13-
return /^\d+$/.test(source) ? BigInt(source) : value
13+
// Ignore non-numbers
14+
if (typeof value !== 'number') return value
15+
16+
// If not an integer, use the value
17+
// TODO: Check if Presto can return floats that could also lose precision
18+
if (!Number.isInteger(value)) return value
19+
20+
// If number is a safe integer, we can use it
21+
if (Number.isSafeInteger(value)) return value
22+
23+
return BigInt(source)
1424
}
1525

1626
export class PrestoClient {

0 commit comments

Comments
 (0)