@@ -8,20 +8,7 @@ import {
88 QueryInfo ,
99 Table ,
1010} from './types'
11-
12- function digitsToBigInt ( _ : string , value : unknown , { source } : { source : string } ) {
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 )
24- }
11+ import { parseWithBigInts , isJsonParseContextAvailable } from './utils'
2512
2613export class PrestoClient {
2714 private baseUrl : string
@@ -351,9 +338,13 @@ export class PrestoClient {
351338
352339 private async prestoConversionToJSON ( { response } : { response : Response } ) : Promise < unknown > {
353340 const text = await response . text ( )
354- // eslint-disable-next-line @typescript-eslint/ban-ts-comment
355- // @ts -ignore JSON.parse with a 3 argument reviver is a stage 3 proposal with some support, allow it here.
356- return JSON . parse ( text , digitsToBigInt )
341+ if ( isJsonParseContextAvailable ( ) ) {
342+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
343+ // @ts -ignore JSON.parse with a 3 argument reviver is a stage 3 proposal with some support, allow it here.
344+ return JSON . parse ( text , parseWithBigInts )
345+ } else {
346+ return JSON . parse ( text )
347+ }
357348 }
358349}
359350
0 commit comments