From c302db9c03b1c669b668133cc2539ee838fc3888 Mon Sep 17 00:00:00 2001 From: Cleve Stuart <90649124+cleve-fauna@users.noreply.github.com> Date: Tue, 29 Aug 2023 08:33:31 -0700 Subject: [PATCH] Accept undefined in setLastTxnTs input but treat it as a no-op. This resolves typescript compilation errors while maintaining current behavior (#200) --- .../client-last-txn-tracking.test.ts | 24 +++++++++++++++++++ package.json | 2 +- src/client.ts | 13 +++++----- src/util/package-version.ts | 2 +- 4 files changed, 32 insertions(+), 9 deletions(-) diff --git a/__tests__/integration/client-last-txn-tracking.test.ts b/__tests__/integration/client-last-txn-tracking.test.ts index d7dfebd2..e67c0871 100644 --- a/__tests__/integration/client-last-txn-tracking.test.ts +++ b/__tests__/integration/client-last-txn-tracking.test.ts @@ -98,5 +98,29 @@ describe("last_txn_ts tracking in client", () => { `); expect(resultThree.txn_ts).not.toBeUndefined(); expect(resultThree.txn_ts).not.toEqual(resultTwo.txn_ts); + myClient.close(); + }); + + it("Ignores overrides of the lastTxnTs that are less than the current value or undefined", async () => { + let expectedLastTxn: number; + + const myClient = getClient({ + query_timeout_ms: 60_000, + }); + + expect(myClient.lastTxnTs).toBeUndefined(); + + const resultOne = await myClient.query(fql` + if (Collection.byName('Foozball') == null) {\ + Collection.create({ name: 'Foozball' })\ + } + `); + expect(myClient.lastTxnTs).toBeDefined(); + expectedLastTxn = myClient.lastTxnTs!; + myClient.lastTxnTs = expectedLastTxn - 1; + expect(myClient.lastTxnTs).toEqual(expectedLastTxn); + myClient.lastTxnTs = undefined; + expect(myClient.lastTxnTs).toEqual(expectedLastTxn); + myClient.close(); }); }); diff --git a/package.json b/package.json index d5e3b72f..9b453886 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fauna", - "version": "1.0.1", + "version": "1.0.2", "description": "A driver to query Fauna databases in browsers, Node.js, and other Javascript runtimes", "homepage": "https://fauna.com", "bugs": { diff --git a/src/client.ts b/src/client.ts index a87531dd..72bb1c97 100644 --- a/src/client.ts +++ b/src/client.ts @@ -125,20 +125,19 @@ export class Client { /** * @returns the last transaction time seen by this client, or undefined if this client has not seen a transaction time. */ - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore it's okay that #lastTxnTs could be undefined on get, but we want - // to enforce that the user never intentionally set it to undefined. get lastTxnTs(): number | undefined { return this.#lastTxnTs; } /** * Sets the last transaction time of this client. * @param ts - the last transaction timestamp to set, as microseconds since - * the epoch. If `ts` is less than the existing `#lastTxnTs` value, then no - * change is made. + * the epoch. If `ts` is less than the existing `#lastTxnTs` value or is + * undefined , then no change is made. */ - set lastTxnTs(ts: number) { - this.#lastTxnTs = this.#lastTxnTs ? Math.max(ts, this.#lastTxnTs) : ts; + set lastTxnTs(ts: number | undefined) { + if (ts !== undefined) { + this.#lastTxnTs = this.#lastTxnTs ? Math.max(ts, this.#lastTxnTs) : ts; + } } /** diff --git a/src/util/package-version.ts b/src/util/package-version.ts index b3bd471e..c28c6101 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 = "1.0.1"; +export const packageVersion = "1.0.2";