From afc82754ebdbf70d3a36be4fbba8bc29de495992 Mon Sep 17 00:00:00 2001 From: Cleve Stuart <90649124+cleve-fauna@users.noreply.github.com> Date: Tue, 25 Jul 2023 12:01:24 -0700 Subject: [PATCH] #188 - Fix double encoding bug (doubles being encoded as integers) (#189) --- __tests__/unit/tagged-format.test.ts | 1 + package.json | 2 +- src/tagged-type.ts | 2 +- src/util/package-version.ts | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/__tests__/unit/tagged-format.test.ts b/__tests__/unit/tagged-format.test.ts index 9c587f71..573181f1 100644 --- a/__tests__/unit/tagged-format.test.ts +++ b/__tests__/unit/tagged-format.test.ts @@ -298,6 +298,7 @@ describe.each` ${LONG_MAX} | ${LONG_MAX} | ${long_type} | ${"@long"} | ${"2**64 - 1"} ${1.3 ** 63} | ${1.3 ** 63} | ${"number"} | ${"@double"} | ${"1.3**63"} ${1.3} | ${1.3} | ${"number"} | ${"@double"} | ${"1.3"} + ${0.000000008} | ${0.000000008} | ${"number"} | ${"@double"} | ${"0.000000008"} `( `Properly encodes and decodes number $testCase`, async ({ input, expected, expectedType, tag, testCase }) => { diff --git a/package.json b/package.json index 3e57e0c7..adb1f9a4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fauna", - "version": "0.9.3", + "version": "0.9.4", "description": "A driver to query Fauna databases in browsers, Node.js, and other Javascript runtimes", "homepage": "https://fauna.com", "bugs": { diff --git a/src/tagged-type.ts b/src/tagged-type.ts index 5979b1cd..c7f29a87 100644 --- a/src/tagged-type.ts +++ b/src/tagged-type.ts @@ -142,7 +142,7 @@ const encodeMap = { throw new RangeError(`Cannot convert ${value} to a Fauna type.`); } - if (`${value}`.includes(".")) { + if (!Number.isInteger(value)) { return { "@double": value.toString() }; } else { if (value >= INT_MIN && value <= INT_MAX) { diff --git a/src/util/package-version.ts b/src/util/package-version.ts index 44071ab1..8607969f 100644 --- a/src/util/package-version.ts +++ b/src/util/package-version.ts @@ -1,4 +1,4 @@ //THIS FILE IS AUTOGENERATED. DO NOT EDIT. SEE .husky/pre-commit /** The current package version. */ -export const packageVersion = "0.9.3"; +export const packageVersion = "0.9.4";