Skip to content

Commit

Permalink
fix(util-dynamodb): create BigInt from string value instead of number (
Browse files Browse the repository at this point in the history
  • Loading branch information
trivikr committed Sep 30, 2020
1 parent 1b1e40d commit 76c0068
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/util-dynamodb/src/convertToNative.spec.ts
Expand Up @@ -65,10 +65,10 @@ describe("convertToNative", () => {
});

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

it(`throws error for numbers outside SAFE_INTEGER range when BigInt is not defined: ${numString}`, () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/util-dynamodb/src/convertToNative.ts
Expand Up @@ -50,7 +50,7 @@ const convertNumber = (numString: string, options?: unmarshallOptions): number |
const infinityValues = [Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY];
if ((num > Number.MAX_SAFE_INTEGER || num < Number.MIN_SAFE_INTEGER) && !infinityValues.includes(num)) {
if (typeof BigInt === "function") {
return BigInt(num);
return BigInt(numString);
} else {
throw new Error(`${numString} is outside SAFE_INTEGER bounds. Set options.wrapNumbers to get string value.`);
}
Expand Down

0 comments on commit 76c0068

Please sign in to comment.