From e687524789d1f5d1117916cf9bb3861eb9f7848c Mon Sep 17 00:00:00 2001 From: kartik-gupta-ij Date: Mon, 11 Dec 2023 02:08:48 +0530 Subject: [PATCH] Chore: Big int Support added --- package.json | 4 ++++ pnpm-lock.yaml | 26 ++++++++++++++++++++++++++ src/fetcher.ts | 6 ++++-- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 463dea11..48a30a55 100644 --- a/package.json +++ b/package.json @@ -77,6 +77,7 @@ "@changesets/changelog-github": "0.4.8", "@changesets/cli": "2.26.1", "@types/jest": "^28.0.0", + "@types/json-bigint": "^1.0.4", "@typescript-eslint/eslint-plugin": "^4.30.0", "@typescript-eslint/parser": "^4.31.0", "codecov": "^3.8.2", @@ -109,5 +110,8 @@ "tsc:check": "tsc --noEmit", "ci:version": "pnpm changeset version && pnpm install --no-frozen-lockfile && git add .", "ci:release": "pnpm changeset publish" + }, + "dependencies": { + "json-bigint": "^1.0.0" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 2f77b1cc..0333aa25 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,5 +1,14 @@ lockfileVersion: '6.0' +settings: + autoInstallPeers: true + excludeLinksFromLockfile: false + +dependencies: + json-bigint: + specifier: ^1.0.0 + version: 1.0.0 + devDependencies: '@changesets/changelog-github': specifier: 0.4.8 @@ -10,6 +19,9 @@ devDependencies: '@types/jest': specifier: ^28.0.0 version: 28.1.0 + '@types/json-bigint': + specifier: ^1.0.4 + version: 1.0.4 '@typescript-eslint/eslint-plugin': specifier: ^4.30.0 version: 4.30.0(@typescript-eslint/parser@4.31.0)(eslint@7.32.0)(typescript@4.7.2) @@ -1098,6 +1110,10 @@ packages: '@types/tough-cookie': 4.0.2 dev: true + /@types/json-bigint@1.0.4: + resolution: {integrity: sha512-ydHooXLbOmxBbubnA7Eh+RpBzuaIiQjh8WGJYQB50JFGFrdxW7JzVlyEV7fAXw0T2sqJ1ysTneJbiyNLqZRAag==} + dev: true + /@types/json-schema@7.0.11: resolution: {integrity: sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==} dev: true @@ -1567,6 +1583,10 @@ packages: is-windows: 1.0.2 dev: true + /bignumber.js@9.1.2: + resolution: {integrity: sha512-2/mKyZH9K85bzOEfhXDBFZTGd1CTs+5IHpeFQo9luiBG7hghdC851Pj2WAhb6E3R6b9tZj/XKhbg4fum+Kepug==} + dev: false + /binary-extensions@2.2.0: resolution: {integrity: sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==} engines: {node: '>=8'} @@ -3584,6 +3604,12 @@ packages: hasBin: true dev: true + /json-bigint@1.0.0: + resolution: {integrity: sha512-SiPv/8VpZuWbvLSMtTDU8hEfrZWg/mH/nV/b4o0CYbSxu1UIQPLdwKOCIyLQX+VIPO5vrLX3i8qtqFyhdPSUSQ==} + dependencies: + bignumber.js: 9.1.2 + dev: false + /json-parse-even-better-errors@2.3.1: resolution: {integrity: sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==} dev: true diff --git a/src/fetcher.ts b/src/fetcher.ts index 14a934b2..8f3cef79 100644 --- a/src/fetcher.ts +++ b/src/fetcher.ts @@ -14,6 +14,7 @@ import { _TypedFetch, TypedFetch, } from './types.js' +import JSONbig from 'json-bigint' const sendBody = (method: Method) => method === 'post' || @@ -152,11 +153,12 @@ async function getResponseData(response: Response) { return undefined } if (contentType && contentType.indexOf('application/json') !== -1) { - return await response.json() + const text = await response.text() + return JSONbig.parse(text) } const text = await response.text() try { - return JSON.parse(text) + return JSONbig.parse(text) } catch (e) { return text }