@cratis/arc 23.8.1 → 23.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/commands/Command.ts +4 -0
  2. package/commands/for_Command/when_registering_the_same_property_changed_callback_twice.ts +47 -0
  3. package/dist/cjs/commands/Command.d.ts.map +1 -1
  4. package/dist/cjs/commands/Command.js +3 -0
  5. package/dist/cjs/commands/Command.js.map +1 -1
  6. package/dist/cjs/queries/QueryInstanceCache.d.ts.map +1 -1
  7. package/dist/cjs/queries/QueryInstanceCache.js +6 -5
  8. package/dist/cjs/queries/QueryInstanceCache.js.map +1 -1
  9. package/dist/esm/commands/Command.d.ts.map +1 -1
  10. package/dist/esm/commands/Command.js +3 -0
  11. package/dist/esm/commands/Command.js.map +1 -1
  12. package/dist/esm/commands/for_Command/when_registering_the_same_property_changed_callback_twice.d.ts +2 -0
  13. package/dist/esm/commands/for_Command/when_registering_the_same_property_changed_callback_twice.d.ts.map +1 -0
  14. package/dist/esm/commands/for_Command/when_registering_the_same_property_changed_callback_twice.js +36 -0
  15. package/dist/esm/commands/for_Command/when_registering_the_same_property_changed_callback_twice.js.map +1 -0
  16. package/dist/esm/queries/QueryInstanceCache.d.ts.map +1 -1
  17. package/dist/esm/queries/QueryInstanceCache.js +6 -5
  18. package/dist/esm/queries/QueryInstanceCache.js.map +1 -1
  19. package/dist/esm/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_pending_deferred_cleanup.js +1 -1
  20. package/dist/esm/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_pending_deferred_cleanup.js.map +1 -1
  21. package/dist/esm/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_retained_entries.d.ts +2 -0
  22. package/dist/esm/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_retained_entries.d.ts.map +1 -0
  23. package/dist/esm/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_retained_entries.js +44 -0
  24. package/dist/esm/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_retained_entries.js.map +1 -0
  25. package/dist/esm/tsconfig.tsbuildinfo +1 -1
  26. package/package.json +1 -1
  27. package/queries/QueryInstanceCache.ts +6 -6
  28. package/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_pending_deferred_cleanup.ts +1 -1
  29. package/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_retained_entries.ts +52 -0
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@cratis/arc",
4
- "version": "23.8.1",
4
+ "version": "23.8.2",
5
5
  "description": "TypeScript command, query, validation, identity, and messaging runtime for Cratis Arc — the CQRS application framework for ASP.NET Core — used by generated proxies.",
6
6
  "keywords": [
7
7
  "cratis",
@@ -372,7 +372,7 @@ export class QueryInstanceCache {
372
372
 
373
373
  /**
374
374
  * Tears down all active subscriptions and marks every entry as not subscribed,
375
- * but preserves entries, subscriber counts, and listeners. This allows
375
+ * but preserves entries, subscriber counts, listeners, and pending eviction timers. This allows
376
376
  * hooks whose effects re-run afterward to detect that the entry is no longer
377
377
  * subscribed and re-establish a fresh connection.
378
378
  *
@@ -387,11 +387,6 @@ export class QueryInstanceCache {
387
387
  }
388
388
 
389
389
  private teardownEntry(entry: QueryCacheEntry<unknown>): void {
390
- if (entry.pendingCleanup !== undefined) {
391
- clearTimeout(entry.pendingCleanup);
392
- entry.pendingCleanup = undefined;
393
- }
394
-
395
390
  entry.subscribed = false;
396
391
  entry.teardown?.();
397
392
  entry.teardown = undefined;
@@ -404,6 +399,11 @@ export class QueryInstanceCache {
404
399
  */
405
400
  dispose(): void {
406
401
  this.teardownAllSubscriptions();
402
+ for (const entry of this._entries.values()) {
403
+ if (entry.pendingCleanup !== undefined) {
404
+ clearTimeout(entry.pendingCleanup);
405
+ }
406
+ }
407
407
  this._entries.clear();
408
408
  }
409
409
 
@@ -28,6 +28,6 @@ describe('when tearing down all subscriptions with pending deferred cleanup', ()
28
28
  });
29
29
 
30
30
  it('should call teardown', () => teardownCalled.should.be.true);
31
- it('should keep the entry', () => cache.has('MyQuery::').should.be.true);
31
+ it('should evict the released entry when deferred cleanup fires', () => cache.has('MyQuery::').should.be.false);
32
32
  it('should mark the entry as not subscribed', () => cache.isSubscribed('MyQuery::').should.be.false);
33
33
  });
@@ -0,0 +1,52 @@
1
+ // Copyright (c) Cratis. All rights reserved.
2
+ // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3
+
4
+ import { QueryInstanceCache } from '../../QueryInstanceCache.js';
5
+
6
+ const describeReconnectingARetainedEntry = (hasSubscription: boolean) => describe(`when reconnecting a released entry with a subscription: ${hasSubscription}`, () => {
7
+ let cache: QueryInstanceCache;
8
+ let teardown: ReturnType<typeof vi.fn<() => void>>;
9
+
10
+ beforeEach(() => {
11
+ vi.useFakeTimers();
12
+ cache = new QueryInstanceCache(1000);
13
+ teardown = vi.fn<() => void>();
14
+ cache.getOrCreate('RetainedQuery::', () => ({}));
15
+ cache.acquire('RetainedQuery::');
16
+ if (hasSubscription) {
17
+ cache.setTeardown('RetainedQuery::', teardown);
18
+ }
19
+ cache.release('RetainedQuery::');
20
+ vi.advanceTimersByTime(400);
21
+ cache.teardownAllSubscriptions();
22
+ });
23
+
24
+ afterEach(() => {
25
+ cache.dispose();
26
+ vi.useRealTimers();
27
+ });
28
+
29
+ it('should preserve the original expiry deadline across repeated reconnects', () => {
30
+ vi.advanceTimersByTime(300);
31
+ cache.teardownAllSubscriptions();
32
+ vi.advanceTimersByTime(299);
33
+ cache.has('RetainedQuery::').should.be.true;
34
+ vi.advanceTimersByTime(1);
35
+ cache.has('RetainedQuery::').should.be.false;
36
+ teardown.mock.calls.length.should.equal(hasSubscription ? 1 : 0);
37
+ });
38
+
39
+ it('should cancel expiry when a consumer returns', () => {
40
+ cache.acquire('RetainedQuery::');
41
+ vi.advanceTimersByTime(1000);
42
+ cache.has('RetainedQuery::').should.be.true;
43
+ cache.release('RetainedQuery::');
44
+ vi.advanceTimersByTime(999);
45
+ cache.has('RetainedQuery::').should.be.true;
46
+ vi.advanceTimersByTime(1);
47
+ cache.has('RetainedQuery::').should.be.false;
48
+ });
49
+ });
50
+
51
+ describeReconnectingARetainedEntry(false);
52
+ describeReconnectingARetainedEntry(true);