Skip to content

Commit

Permalink
Accept undefined in setLastTxnTs input but treat it as a no-op. This …
Browse files Browse the repository at this point in the history
…resolves typescript compilation errors while maintaining current behavior
  • Loading branch information
cleve-fauna committed Aug 29, 2023
1 parent 3a0904f commit 49c1c0a
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
24 changes: 24 additions & 0 deletions __tests__/integration/client-last-txn-tracking.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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("Ingores 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();
});
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
13 changes: 6 additions & 7 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/util/package-version.ts
Original file line number Diff line number Diff line change
@@ -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";

0 comments on commit 49c1c0a

Please sign in to comment.