From 0c4387769e62588602f94a33f0e46e09352de72c Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Mon, 11 Dec 2023 18:28:54 +0100 Subject: [PATCH] Use -1 as the default lastResponseTime Entites that didn't have an updatedAt time at the time of creation will default to having one set to 0. Since entities with an updatedAt time greater than lastResponseTime is expected to be returned this means that these entities would not be included when a client does its initial sync subscribing to a resource. Change the default lastResponseTime requested so that these entities are included. --- packages/lib/src/subscriptions.ts | 2 +- test/lib/subscriptions.js | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/lib/src/subscriptions.ts b/packages/lib/src/subscriptions.ts index b2dbdb4c..9ecd493d 100644 --- a/packages/lib/src/subscriptions.ts +++ b/packages/lib/src/subscriptions.ts @@ -208,7 +208,7 @@ export class SubscriptionController { export class EventSubscriber, V=T> { _callbacks = new Array>(); lastResponse: Event | null = null; - lastResponseTime = 0; + lastResponseTime = -1; control?: Link; constructor( diff --git a/test/lib/subscriptions.js b/test/lib/subscriptions.js index b4c77470..3405fcfa 100644 --- a/test/lib/subscriptions.js +++ b/test/lib/subscriptions.js @@ -63,8 +63,8 @@ describe("lib/subscriptions", function() { assert.deepEqual(reconstructed, response); }); - it("should be round trip json serialisable with a null event replay", function() { - const response = new lib.SubscriptionResponse(null); + it("should be round trip json serialisable with an undefined event replay", function() { + const response = new lib.SubscriptionResponse(undefined); const json = JSON.stringify(response); assert.equal(typeof json, "string"); const reconstructed = lib.SubscriptionResponse.fromJSON(JSON.parse(json)); @@ -396,13 +396,13 @@ describe("lib/subscriptions", function() { describe("_updateSubscription()", function() { it("should correctly request a subscription", async function() { - const expected = new lib.SubscriptionRequest(RegisteredEvent.name, true); + const expected = new lib.SubscriptionRequest(RegisteredEvent.name, true, -1); registeredEvent.subscribe(() => true); await events.once(mockControl.connector, "send"); assertLastRequest(expected); }); - it("should correctly request a no subscriptions", async function() { - const expected = new lib.SubscriptionRequest(RegisteredEvent.name, false); + it("should correctly request no subscriptions", async function() { + const expected = new lib.SubscriptionRequest(RegisteredEvent.name, false, -1); function callback() {} registeredEvent.subscribe(callback); await events.once(mockControl.connector, "send");