Skip to content

Commit 76c0068

Browse files
authored
fix(util-dynamodb): create BigInt from string value instead of number (#1544)
1 parent 1b1e40d commit 76c0068

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

Diff for: packages/util-dynamodb/src/convertToNative.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ describe("convertToNative", () => {
6565
});
6666

6767
[Number.MAX_SAFE_INTEGER + 1, Number.MAX_VALUE, Number.MIN_SAFE_INTEGER - 1]
68-
.map((num) => num.toString())
68+
.map((num) => BigInt(num).toString())
6969
.forEach((numString) => {
7070
it(`returns bigint for numbers outside SAFE_INTEGER range: ${numString}`, () => {
71-
expect(convertToNative({ ...emptyAttr, N: numString })).toEqual(BigInt(Number(numString)));
71+
expect(convertToNative({ ...emptyAttr, N: numString })).toEqual(BigInt(numString));
7272
});
7373

7474
it(`throws error for numbers outside SAFE_INTEGER range when BigInt is not defined: ${numString}`, () => {

Diff for: packages/util-dynamodb/src/convertToNative.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ const convertNumber = (numString: string, options?: unmarshallOptions): number |
5050
const infinityValues = [Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY];
5151
if ((num > Number.MAX_SAFE_INTEGER || num < Number.MIN_SAFE_INTEGER) && !infinityValues.includes(num)) {
5252
if (typeof BigInt === "function") {
53-
return BigInt(num);
53+
return BigInt(numString);
5454
} else {
5555
throw new Error(`${numString} is outside SAFE_INTEGER bounds. Set options.wrapNumbers to get string value.`);
5656
}

0 commit comments

Comments
 (0)