@cratis/arc 20.1.3 → 20.1.5
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.
- package/dist/cjs/identity/IdentityProvider.d.ts +2 -1
- package/dist/cjs/identity/IdentityProvider.d.ts.map +1 -1
- package/dist/cjs/identity/IdentityProvider.js +16 -2
- package/dist/cjs/identity/IdentityProvider.js.map +1 -1
- package/dist/cjs/identity/for_IdentityProvider/when_refreshing/with_unauthorized_response.d.ts +2 -0
- package/dist/cjs/identity/for_IdentityProvider/when_refreshing/with_unauthorized_response.d.ts.map +1 -0
- package/dist/cjs/queries/HubConnectionKeepAlive.d.ts +2 -1
- package/dist/cjs/queries/HubConnectionKeepAlive.d.ts.map +1 -1
- package/dist/cjs/queries/HubConnectionKeepAlive.js +4 -2
- package/dist/cjs/queries/HubConnectionKeepAlive.js.map +1 -1
- package/dist/cjs/queries/QueryInstanceCache.d.ts +8 -0
- package/dist/cjs/queries/QueryInstanceCache.d.ts.map +1 -1
- package/dist/cjs/queries/QueryInstanceCache.js +70 -9
- package/dist/cjs/queries/QueryInstanceCache.js.map +1 -1
- package/dist/cjs/queries/QueryResult.d.ts +1 -0
- package/dist/cjs/queries/QueryResult.d.ts.map +1 -1
- package/dist/cjs/queries/QueryResult.js +18 -0
- package/dist/cjs/queries/QueryResult.js.map +1 -1
- package/dist/cjs/queries/ReconnectPolicy.d.ts.map +1 -1
- package/dist/cjs/queries/ReconnectPolicy.js +1 -0
- package/dist/cjs/queries/ReconnectPolicy.js.map +1 -1
- package/dist/cjs/queries/ServerSentEventHubConnection.d.ts +1 -0
- package/dist/cjs/queries/ServerSentEventHubConnection.d.ts.map +1 -1
- package/dist/cjs/queries/ServerSentEventHubConnection.js +22 -3
- package/dist/cjs/queries/ServerSentEventHubConnection.js.map +1 -1
- package/dist/cjs/queries/WebSocketHubConnection.d.ts +1 -0
- package/dist/cjs/queries/WebSocketHubConnection.d.ts.map +1 -1
- package/dist/cjs/queries/WebSocketHubConnection.js +11 -0
- package/dist/cjs/queries/WebSocketHubConnection.js.map +1 -1
- package/dist/cjs/queries/for_HubConnectionKeepAlive/when_started_with_custom_idle_threshold/respects_threshold.d.ts +2 -0
- package/dist/cjs/queries/for_HubConnectionKeepAlive/when_started_with_custom_idle_threshold/respects_threshold.d.ts.map +1 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_acquiring/after_release_in_development_mode.d.ts +2 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_acquiring/after_release_in_development_mode.d.ts.map +1 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_deferring_dispose/with_cancellation_before_timeout.d.ts +2 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_deferring_dispose/with_cancellation_before_timeout.d.ts.map +1 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_deferring_dispose/without_cancellation.d.ts +2 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_deferring_dispose/without_cancellation.d.ts.map +1 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_disposing/an_empty_cache.d.ts +2 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_disposing/an_empty_cache.d.ts.map +1 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_disposing/with_active_subscriptions.d.ts +2 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_disposing/with_active_subscriptions.d.ts.map +1 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_disposing/with_pending_deferred_cleanup.d.ts +2 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_disposing/with_pending_deferred_cleanup.d.ts.map +1 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_releasing/the_only_subscriber_in_development_mode.d.ts +2 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_releasing/the_only_subscriber_in_development_mode.d.ts.map +1 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_releasing/the_only_subscriber_outside_development_mode.d.ts +2 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_releasing/the_only_subscriber_outside_development_mode.d.ts.map +1 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_active_subscriptions.d.ts +2 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_active_subscriptions.d.ts.map +1 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_no_subscriptions.d.ts +2 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_no_subscriptions.d.ts.map +1 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_pending_deferred_cleanup.d.ts +2 -0
- package/dist/cjs/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_pending_deferred_cleanup.d.ts.map +1 -0
- package/dist/cjs/queries/for_ReconnectPolicy/when_scheduling/and_rescheduled_before_first_fires/cancels_previous_timer.d.ts +2 -0
- package/dist/cjs/queries/for_ReconnectPolicy/when_scheduling/and_rescheduled_before_first_fires/cancels_previous_timer.d.ts.map +1 -0
- package/dist/cjs/queries/for_ServerSentEventHubConnection/when_receiving_unauthorized/notifies_subscriber_and_removes_subscription.d.ts +2 -0
- package/dist/cjs/queries/for_ServerSentEventHubConnection/when_receiving_unauthorized/notifies_subscriber_and_removes_subscription.d.ts.map +1 -0
- package/dist/cjs/queries/for_ServerSentEventHubConnection/when_subscribing/and_subscribe_post_fails.d.ts +2 -0
- package/dist/cjs/queries/for_ServerSentEventHubConnection/when_subscribing/and_subscribe_post_fails.d.ts.map +1 -0
- package/dist/cjs/queries/for_WebSocketHubConnection/when_receiving_unauthorized/notifies_subscriber_and_removes_subscription.d.ts +2 -0
- package/dist/cjs/queries/for_WebSocketHubConnection/when_receiving_unauthorized/notifies_subscriber_and_removes_subscription.d.ts.map +1 -0
- package/dist/esm/identity/IdentityProvider.d.ts +2 -1
- package/dist/esm/identity/IdentityProvider.d.ts.map +1 -1
- package/dist/esm/identity/IdentityProvider.js +16 -2
- package/dist/esm/identity/IdentityProvider.js.map +1 -1
- package/dist/esm/identity/for_IdentityProvider/when_refreshing/with_unauthorized_response.d.ts +2 -0
- package/dist/esm/identity/for_IdentityProvider/when_refreshing/with_unauthorized_response.d.ts.map +1 -0
- package/dist/esm/identity/for_IdentityProvider/when_refreshing/with_unauthorized_response.js +19 -0
- package/dist/esm/identity/for_IdentityProvider/when_refreshing/with_unauthorized_response.js.map +1 -0
- package/dist/esm/queries/HubConnectionKeepAlive.d.ts +2 -1
- package/dist/esm/queries/HubConnectionKeepAlive.d.ts.map +1 -1
- package/dist/esm/queries/HubConnectionKeepAlive.js +4 -2
- package/dist/esm/queries/HubConnectionKeepAlive.js.map +1 -1
- package/dist/esm/queries/QueryInstanceCache.d.ts +8 -0
- package/dist/esm/queries/QueryInstanceCache.d.ts.map +1 -1
- package/dist/esm/queries/QueryInstanceCache.js +70 -9
- package/dist/esm/queries/QueryInstanceCache.js.map +1 -1
- package/dist/esm/queries/QueryResult.d.ts +1 -0
- package/dist/esm/queries/QueryResult.d.ts.map +1 -1
- package/dist/esm/queries/QueryResult.js +18 -0
- package/dist/esm/queries/QueryResult.js.map +1 -1
- package/dist/esm/queries/ReconnectPolicy.d.ts.map +1 -1
- package/dist/esm/queries/ReconnectPolicy.js +1 -0
- package/dist/esm/queries/ReconnectPolicy.js.map +1 -1
- package/dist/esm/queries/ServerSentEventHubConnection.d.ts +1 -0
- package/dist/esm/queries/ServerSentEventHubConnection.d.ts.map +1 -1
- package/dist/esm/queries/ServerSentEventHubConnection.js +22 -3
- package/dist/esm/queries/ServerSentEventHubConnection.js.map +1 -1
- package/dist/esm/queries/WebSocketHubConnection.d.ts +1 -0
- package/dist/esm/queries/WebSocketHubConnection.d.ts.map +1 -1
- package/dist/esm/queries/WebSocketHubConnection.js +11 -0
- package/dist/esm/queries/WebSocketHubConnection.js.map +1 -1
- package/dist/esm/queries/for_HubConnectionKeepAlive/when_started_with_custom_idle_threshold/respects_threshold.d.ts +2 -0
- package/dist/esm/queries/for_HubConnectionKeepAlive/when_started_with_custom_idle_threshold/respects_threshold.d.ts.map +1 -0
- package/dist/esm/queries/for_HubConnectionKeepAlive/when_started_with_custom_idle_threshold/respects_threshold.js +33 -0
- package/dist/esm/queries/for_HubConnectionKeepAlive/when_started_with_custom_idle_threshold/respects_threshold.js.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_acquiring/after_release_in_development_mode.d.ts +2 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_acquiring/after_release_in_development_mode.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_acquiring/after_release_in_development_mode.js +23 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_acquiring/after_release_in_development_mode.js.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_deferring_dispose/with_cancellation_before_timeout.d.ts +2 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_deferring_dispose/with_cancellation_before_timeout.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_deferring_dispose/with_cancellation_before_timeout.js +23 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_deferring_dispose/with_cancellation_before_timeout.js.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_deferring_dispose/without_cancellation.d.ts +2 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_deferring_dispose/without_cancellation.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_deferring_dispose/without_cancellation.js +21 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_deferring_dispose/without_cancellation.js.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_disposing/an_empty_cache.d.ts +2 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_disposing/an_empty_cache.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_disposing/an_empty_cache.js +17 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_disposing/an_empty_cache.js.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_disposing/with_active_subscriptions.d.ts +2 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_disposing/with_active_subscriptions.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_disposing/with_active_subscriptions.js +23 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_disposing/with_active_subscriptions.js.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_disposing/with_pending_deferred_cleanup.d.ts +2 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_disposing/with_pending_deferred_cleanup.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_disposing/with_pending_deferred_cleanup.js +22 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_disposing/with_pending_deferred_cleanup.js.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_releasing/the_only_subscriber_in_development_mode.d.ts +2 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_releasing/the_only_subscriber_in_development_mode.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_releasing/the_only_subscriber_in_development_mode.js +28 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_releasing/the_only_subscriber_in_development_mode.js.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_releasing/the_only_subscriber_outside_development_mode.d.ts +2 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_releasing/the_only_subscriber_outside_development_mode.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_releasing/the_only_subscriber_outside_development_mode.js +25 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_releasing/the_only_subscriber_outside_development_mode.js.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_active_subscriptions.d.ts +2 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_active_subscriptions.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_active_subscriptions.js +25 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_active_subscriptions.js.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_no_subscriptions.d.ts +2 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_no_subscriptions.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_no_subscriptions.js +12 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_no_subscriptions.js.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_pending_deferred_cleanup.d.ts +2 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_pending_deferred_cleanup.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_pending_deferred_cleanup.js +23 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_pending_deferred_cleanup.js.map +1 -0
- package/dist/esm/queries/for_ReconnectPolicy/when_scheduling/and_rescheduled_before_first_fires/cancels_previous_timer.d.ts +2 -0
- package/dist/esm/queries/for_ReconnectPolicy/when_scheduling/and_rescheduled_before_first_fires/cancels_previous_timer.d.ts.map +1 -0
- package/dist/esm/queries/for_ReconnectPolicy/when_scheduling/and_rescheduled_before_first_fires/cancels_previous_timer.js +24 -0
- package/dist/esm/queries/for_ReconnectPolicy/when_scheduling/and_rescheduled_before_first_fires/cancels_previous_timer.js.map +1 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_keep_alive_is_idle/triggers_reconnect.js +1 -1
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_keep_alive_is_idle/triggers_reconnect.js.map +1 -1
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_receiving_unauthorized/notifies_subscriber_and_removes_subscription.d.ts +2 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_receiving_unauthorized/notifies_subscriber_and_removes_subscription.d.ts.map +1 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_receiving_unauthorized/notifies_subscriber_and_removes_subscription.js +35 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_receiving_unauthorized/notifies_subscriber_and_removes_subscription.js.map +1 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_subscribing/and_subscribe_post_fails.d.ts +2 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_subscribing/and_subscribe_post_fails.d.ts.map +1 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_subscribing/and_subscribe_post_fails.js +33 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_subscribing/and_subscribe_post_fails.js.map +1 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_receiving_unauthorized/notifies_subscriber_and_removes_subscription.d.ts +2 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_receiving_unauthorized/notifies_subscriber_and_removes_subscription.d.ts.map +1 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_receiving_unauthorized/notifies_subscriber_and_removes_subscription.js +33 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_receiving_unauthorized/notifies_subscriber_and_removes_subscription.js.map +1 -0
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/identity/IdentityProvider.ts +23 -2
- package/identity/for_IdentityProvider/when_refreshing/with_unauthorized_response.ts +26 -0
- package/package.json +1 -1
- package/queries/HubConnectionKeepAlive.ts +20 -6
- package/queries/QueryInstanceCache.ts +133 -12
- package/queries/QueryResult.ts +19 -0
- package/queries/ReconnectPolicy.ts +4 -0
- package/queries/ServerSentEventHubConnection.ts +29 -4
- package/queries/WebSocketHubConnection.ts +11 -0
- package/queries/for_HubConnectionKeepAlive/when_started_with_custom_idle_threshold/respects_threshold.ts +46 -0
- package/queries/for_QueryInstanceCache/when_acquiring/after_release_in_development_mode.ts +31 -0
- package/queries/for_QueryInstanceCache/when_deferring_dispose/with_cancellation_before_timeout.ts +31 -0
- package/queries/for_QueryInstanceCache/when_deferring_dispose/without_cancellation.ts +28 -0
- package/queries/for_QueryInstanceCache/when_disposing/an_empty_cache.ts +21 -0
- package/queries/for_QueryInstanceCache/when_disposing/with_active_subscriptions.ts +30 -0
- package/queries/for_QueryInstanceCache/when_disposing/with_pending_deferred_cleanup.ts +31 -0
- package/queries/for_QueryInstanceCache/when_releasing/the_only_subscriber_in_development_mode.ts +36 -0
- package/queries/for_QueryInstanceCache/when_releasing/the_only_subscriber_outside_development_mode.ts +33 -0
- package/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_active_subscriptions.ts +32 -0
- package/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_no_subscriptions.ts +18 -0
- package/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_pending_deferred_cleanup.ts +33 -0
- package/queries/for_ReconnectPolicy/when_scheduling/and_rescheduled_before_first_fires/cancels_previous_timer.ts +36 -0
- package/queries/for_ServerSentEventHubConnection/when_keep_alive_is_idle/triggers_reconnect.ts +5 -2
- package/queries/for_ServerSentEventHubConnection/when_receiving_unauthorized/notifies_subscriber_and_removes_subscription.ts +51 -0
- package/queries/for_ServerSentEventHubConnection/when_subscribing/and_subscribe_post_fails.ts +51 -0
- package/queries/for_WebSocketHubConnection/when_receiving_unauthorized/notifies_subscriber_and_removes_subscription.ts +47 -0
|
@@ -0,0 +1,31 @@
|
|
|
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';
|
|
5
|
+
|
|
6
|
+
describe('when disposing with pending deferred cleanup', () => {
|
|
7
|
+
let cache: QueryInstanceCache;
|
|
8
|
+
let teardownCalled: number;
|
|
9
|
+
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
vi.useFakeTimers();
|
|
12
|
+
teardownCalled = 0;
|
|
13
|
+
cache = new QueryInstanceCache(true);
|
|
14
|
+
cache.getOrCreate('MyQuery::', () => ({}));
|
|
15
|
+
cache.acquire('MyQuery::');
|
|
16
|
+
cache.setTeardown('MyQuery::', () => { teardownCalled++; });
|
|
17
|
+
cache.release('MyQuery::');
|
|
18
|
+
|
|
19
|
+
// At this point a deferred cleanup is pending. Dispose should
|
|
20
|
+
// tear down immediately and cancel the deferred cleanup.
|
|
21
|
+
cache.dispose();
|
|
22
|
+
vi.advanceTimersByTime(0);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
afterEach(() => {
|
|
26
|
+
vi.useRealTimers();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('should call teardown exactly once', () => teardownCalled.should.equal(1));
|
|
30
|
+
it('should evict the entry', () => cache.has('MyQuery::').should.be.false);
|
|
31
|
+
});
|
package/queries/for_QueryInstanceCache/when_releasing/the_only_subscriber_in_development_mode.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
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';
|
|
5
|
+
|
|
6
|
+
describe('when releasing the only subscriber in development mode', () => {
|
|
7
|
+
let cache: QueryInstanceCache;
|
|
8
|
+
let teardownCalled: boolean;
|
|
9
|
+
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
vi.useFakeTimers();
|
|
12
|
+
teardownCalled = false;
|
|
13
|
+
cache = new QueryInstanceCache(true);
|
|
14
|
+
cache.getOrCreate('MyQuery::', () => ({}));
|
|
15
|
+
cache.acquire('MyQuery::');
|
|
16
|
+
cache.setTeardown('MyQuery::', () => { teardownCalled = true; });
|
|
17
|
+
cache.release('MyQuery::');
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
afterEach(() => {
|
|
21
|
+
vi.useRealTimers();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('should not call teardown synchronously', () => teardownCalled.should.be.false);
|
|
25
|
+
it('should keep the entry before the timer fires', () => cache.has('MyQuery::').should.be.true);
|
|
26
|
+
it('should still report as subscribed before the timer fires', () => cache.isSubscribed('MyQuery::').should.be.true);
|
|
27
|
+
|
|
28
|
+
describe('and the deferred timer fires', () => {
|
|
29
|
+
beforeEach(() => {
|
|
30
|
+
vi.advanceTimersByTime(0);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('should call teardown', () => teardownCalled.should.be.true);
|
|
34
|
+
it('should evict the entry', () => cache.has('MyQuery::').should.be.false);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
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';
|
|
5
|
+
|
|
6
|
+
describe('when releasing the only subscriber outside development mode', () => {
|
|
7
|
+
let cache: QueryInstanceCache;
|
|
8
|
+
let teardownCalled: boolean;
|
|
9
|
+
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
vi.useFakeTimers();
|
|
12
|
+
teardownCalled = false;
|
|
13
|
+
cache = new QueryInstanceCache(false);
|
|
14
|
+
cache.getOrCreate('MyQuery::', () => ({}));
|
|
15
|
+
cache.acquire('MyQuery::');
|
|
16
|
+
cache.setTeardown('MyQuery::', () => { teardownCalled = true; });
|
|
17
|
+
cache.release('MyQuery::');
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
afterEach(() => {
|
|
21
|
+
vi.useRealTimers();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('should call teardown synchronously', () => teardownCalled.should.be.true);
|
|
25
|
+
|
|
26
|
+
describe('and the deferred timer fires', () => {
|
|
27
|
+
beforeEach(() => {
|
|
28
|
+
vi.advanceTimersByTime(0);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('should evict the entry', () => cache.has('MyQuery::').should.be.false);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
@@ -0,0 +1,32 @@
|
|
|
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';
|
|
5
|
+
|
|
6
|
+
describe('when tearing down all subscriptions with active subscriptions', () => {
|
|
7
|
+
let cache: QueryInstanceCache;
|
|
8
|
+
let firstTeardownCalled: boolean;
|
|
9
|
+
let secondTeardownCalled: boolean;
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
firstTeardownCalled = false;
|
|
13
|
+
secondTeardownCalled = false;
|
|
14
|
+
cache = new QueryInstanceCache();
|
|
15
|
+
cache.getOrCreate('QueryA::', () => ({}));
|
|
16
|
+
cache.acquire('QueryA::');
|
|
17
|
+
cache.setTeardown('QueryA::', () => { firstTeardownCalled = true; });
|
|
18
|
+
|
|
19
|
+
cache.getOrCreate('QueryB::', () => ({}));
|
|
20
|
+
cache.acquire('QueryB::');
|
|
21
|
+
cache.setTeardown('QueryB::', () => { secondTeardownCalled = true; });
|
|
22
|
+
|
|
23
|
+
cache.teardownAllSubscriptions();
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('should call teardown for the first entry', () => firstTeardownCalled.should.be.true);
|
|
27
|
+
it('should call teardown for the second entry', () => secondTeardownCalled.should.be.true);
|
|
28
|
+
it('should keep the first entry', () => cache.has('QueryA::').should.be.true);
|
|
29
|
+
it('should keep the second entry', () => cache.has('QueryB::').should.be.true);
|
|
30
|
+
it('should mark the first entry as not subscribed', () => cache.isSubscribed('QueryA::').should.be.false);
|
|
31
|
+
it('should mark the second entry as not subscribed', () => cache.isSubscribed('QueryB::').should.be.false);
|
|
32
|
+
});
|
package/queries/for_QueryInstanceCache/when_tearing_down_all_subscriptions/with_no_subscriptions.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
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';
|
|
5
|
+
|
|
6
|
+
describe('when tearing down all subscriptions with no subscriptions', () => {
|
|
7
|
+
let cache: QueryInstanceCache;
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
cache = new QueryInstanceCache();
|
|
11
|
+
cache.getOrCreate('MyQuery::', () => ({}));
|
|
12
|
+
|
|
13
|
+
cache.teardownAllSubscriptions();
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should keep the entry', () => cache.has('MyQuery::').should.be.true);
|
|
17
|
+
it('should still report as not subscribed', () => cache.isSubscribed('MyQuery::').should.be.false);
|
|
18
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
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';
|
|
5
|
+
|
|
6
|
+
describe('when tearing down all subscriptions with pending deferred cleanup', () => {
|
|
7
|
+
let cache: QueryInstanceCache;
|
|
8
|
+
let teardownCalled: boolean;
|
|
9
|
+
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
vi.useFakeTimers();
|
|
12
|
+
teardownCalled = false;
|
|
13
|
+
cache = new QueryInstanceCache(true);
|
|
14
|
+
cache.getOrCreate('MyQuery::', () => ({}));
|
|
15
|
+
cache.acquire('MyQuery::');
|
|
16
|
+
cache.setTeardown('MyQuery::', () => { teardownCalled = true; });
|
|
17
|
+
|
|
18
|
+
// Release the only subscriber — in dev mode this defers cleanup.
|
|
19
|
+
cache.release('MyQuery::');
|
|
20
|
+
|
|
21
|
+
// Tear down all before the deferred timer fires.
|
|
22
|
+
cache.teardownAllSubscriptions();
|
|
23
|
+
vi.advanceTimersByTime(0);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
afterEach(() => {
|
|
27
|
+
vi.useRealTimers();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('should call teardown', () => teardownCalled.should.be.true);
|
|
31
|
+
it('should keep the entry', () => cache.has('MyQuery::').should.be.true);
|
|
32
|
+
it('should mark the entry as not subscribed', () => cache.isSubscribed('MyQuery::').should.be.false);
|
|
33
|
+
});
|
|
@@ -0,0 +1,36 @@
|
|
|
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 sinon from 'sinon';
|
|
5
|
+
import { ReconnectPolicy } from '../../../ReconnectPolicy';
|
|
6
|
+
|
|
7
|
+
describe('when scheduling twice before the first timer fires', () => {
|
|
8
|
+
let policy: ReconnectPolicy;
|
|
9
|
+
let clock: sinon.SinonFakeTimers;
|
|
10
|
+
let firstCallback: sinon.SinonStub;
|
|
11
|
+
let secondCallback: sinon.SinonStub;
|
|
12
|
+
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
clock = sinon.useFakeTimers();
|
|
15
|
+
policy = new ReconnectPolicy(100, 500, 500, 10_000);
|
|
16
|
+
firstCallback = sinon.stub();
|
|
17
|
+
secondCallback = sinon.stub();
|
|
18
|
+
|
|
19
|
+
policy.schedule(firstCallback, 'first');
|
|
20
|
+
// Schedule again before the first timer fires.
|
|
21
|
+
policy.schedule(secondCallback, 'second');
|
|
22
|
+
|
|
23
|
+
// Advance past both potential delays:
|
|
24
|
+
// Attempt 1: min(500+500*1, 10_000) = 1000ms
|
|
25
|
+
// Attempt 2: min(500+500*2, 10_000) = 1500ms
|
|
26
|
+
clock.tick(2000);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
afterEach(() => {
|
|
30
|
+
clock.restore();
|
|
31
|
+
sinon.restore();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('should cancel the first timer so it never fires', () => firstCallback.called.should.be.false);
|
|
35
|
+
it('should fire the second timer', () => secondCallback.calledOnce.should.be.true);
|
|
36
|
+
});
|
package/queries/for_ServerSentEventHubConnection/when_keep_alive_is_idle/triggers_reconnect.ts
CHANGED
|
@@ -33,8 +33,11 @@ describe('when keep-alive interval elapses without any server message', given(a_
|
|
|
33
33
|
// Deliver Connected so the connection is fully established.
|
|
34
34
|
context.simulateMessage({ type: HubMessageType.Connected, payload: 'conn-123' });
|
|
35
35
|
|
|
36
|
-
// Advance past the keep-alive interval without any further messages.
|
|
37
|
-
|
|
36
|
+
// Advance past the idle threshold (1.5× keep-alive interval) without any further messages.
|
|
37
|
+
// The check interval fires every KEEP_ALIVE_MS; the idle threshold is KEEP_ALIVE_MS * 1.5.
|
|
38
|
+
// After the first interval tick (500ms) the elapsed idle time (500ms) is below the
|
|
39
|
+
// threshold (750ms). At the second tick (1000ms) the elapsed time exceeds the threshold.
|
|
40
|
+
clock.tick(KEEP_ALIVE_MS * 2 + 1);
|
|
38
41
|
});
|
|
39
42
|
|
|
40
43
|
afterEach(() => {
|
|
@@ -0,0 +1,51 @@
|
|
|
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 sinon from 'sinon';
|
|
5
|
+
import { a_server_sent_event_hub_connection } from '../given/a_server_sent_event_hub_connection';
|
|
6
|
+
import { given } from '../../../given';
|
|
7
|
+
import { HubMessageType } from '../../WebSocketHubConnection';
|
|
8
|
+
import { QueryResult } from '../../QueryResult';
|
|
9
|
+
|
|
10
|
+
describe('when receiving unauthorized for a subscribed query', given(a_server_sent_event_hub_connection, context => {
|
|
11
|
+
let callback: sinon.SinonStub;
|
|
12
|
+
let receivedResult: QueryResult<unknown> | undefined;
|
|
13
|
+
const queryId = 'q-auth-1';
|
|
14
|
+
const connectionId = 'conn-123';
|
|
15
|
+
|
|
16
|
+
beforeEach(() => {
|
|
17
|
+
context.setup();
|
|
18
|
+
callback = sinon.stub();
|
|
19
|
+
|
|
20
|
+
context.connection.subscribe(queryId, { queryName: 'SecureQuery' }, callback);
|
|
21
|
+
context.simulateOpen();
|
|
22
|
+
|
|
23
|
+
// Server sends Connected message with the connection ID.
|
|
24
|
+
context.simulateMessage({ type: HubMessageType.Connected, payload: connectionId });
|
|
25
|
+
|
|
26
|
+
// Server replies with Unauthorized for this subscription.
|
|
27
|
+
context.simulateMessage({ type: HubMessageType.Unauthorized, queryId });
|
|
28
|
+
|
|
29
|
+
receivedResult = callback.firstCall?.args[0] as QueryResult<unknown> | undefined;
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
afterEach(() => {
|
|
33
|
+
sinon.restore();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('should invoke the subscriber callback', () => {
|
|
37
|
+
callback.calledOnce.should.be.true;
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('should report isAuthorized as false', () => {
|
|
41
|
+
receivedResult!.isAuthorized.should.be.false;
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('should report isSuccess as false', () => {
|
|
45
|
+
receivedResult!.isSuccess.should.be.false;
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it('should remove the subscription', () => {
|
|
49
|
+
context.connection.queryCount.should.equal(0);
|
|
50
|
+
});
|
|
51
|
+
}));
|
|
@@ -0,0 +1,51 @@
|
|
|
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 sinon from 'sinon';
|
|
5
|
+
import { a_server_sent_event_hub_connection } from '../given/a_server_sent_event_hub_connection';
|
|
6
|
+
import { given } from '../../../given';
|
|
7
|
+
import { HubMessageType } from '../../WebSocketHubConnection';
|
|
8
|
+
|
|
9
|
+
describe('when subscribe POST returns a non-OK status', given(a_server_sent_event_hub_connection, context => {
|
|
10
|
+
beforeEach(async () => {
|
|
11
|
+
context.setup();
|
|
12
|
+
|
|
13
|
+
// Make the subscribe POST resolve with a 404 (connection not found on server).
|
|
14
|
+
context.fetchStub.resolves({ ok: false, status: 404 });
|
|
15
|
+
|
|
16
|
+
context.connection.subscribe('q1', { queryName: 'MyQuery' }, sinon.stub());
|
|
17
|
+
context.simulateOpen();
|
|
18
|
+
context.simulateMessage({ type: HubMessageType.Connected, payload: 'conn-abc' });
|
|
19
|
+
|
|
20
|
+
// Allow the fetch promise chain (.then) to execute.
|
|
21
|
+
await new Promise(resolve => setTimeout(resolve, 0));
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
afterEach(() => sinon.restore());
|
|
25
|
+
|
|
26
|
+
it('should schedule a reconnect via the policy', () => {
|
|
27
|
+
(context.policy.schedule as sinon.SinonStub).calledOnce.should.be.true;
|
|
28
|
+
});
|
|
29
|
+
}));
|
|
30
|
+
|
|
31
|
+
describe('when subscribe POST rejects with a network error', given(a_server_sent_event_hub_connection, context => {
|
|
32
|
+
beforeEach(async () => {
|
|
33
|
+
context.setup();
|
|
34
|
+
|
|
35
|
+
// Make the subscribe POST reject (network failure).
|
|
36
|
+
context.fetchStub.rejects(new Error('Network error'));
|
|
37
|
+
|
|
38
|
+
context.connection.subscribe('q1', { queryName: 'MyQuery' }, sinon.stub());
|
|
39
|
+
context.simulateOpen();
|
|
40
|
+
context.simulateMessage({ type: HubMessageType.Connected, payload: 'conn-abc' });
|
|
41
|
+
|
|
42
|
+
// Allow the fetch promise chain (.catch) to execute.
|
|
43
|
+
await new Promise(resolve => setTimeout(resolve, 0));
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
afterEach(() => sinon.restore());
|
|
47
|
+
|
|
48
|
+
it('should schedule a reconnect via the policy', () => {
|
|
49
|
+
(context.policy.schedule as sinon.SinonStub).calledOnce.should.be.true;
|
|
50
|
+
});
|
|
51
|
+
}));
|
|
@@ -0,0 +1,47 @@
|
|
|
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 sinon from 'sinon';
|
|
5
|
+
import { a_web_socket_hub_connection } from '../given/a_web_socket_hub_connection';
|
|
6
|
+
import { given } from '../../../given';
|
|
7
|
+
import { HubMessageType } from '../../WebSocketHubConnection';
|
|
8
|
+
import { QueryResult } from '../../QueryResult';
|
|
9
|
+
|
|
10
|
+
describe('when receiving unauthorized for a subscribed query', given(a_web_socket_hub_connection, context => {
|
|
11
|
+
let callback: sinon.SinonStub;
|
|
12
|
+
let receivedResult: QueryResult<unknown> | undefined;
|
|
13
|
+
const queryId = 'q-auth-1';
|
|
14
|
+
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
context.setup();
|
|
17
|
+
callback = sinon.stub();
|
|
18
|
+
|
|
19
|
+
context.connection.subscribe(queryId, { queryName: 'SecureQuery' }, callback);
|
|
20
|
+
context.simulateOpen();
|
|
21
|
+
|
|
22
|
+
// Server replies with Unauthorized for this subscription.
|
|
23
|
+
context.simulateMessage({ type: HubMessageType.Unauthorized, queryId });
|
|
24
|
+
|
|
25
|
+
receivedResult = callback.firstCall?.args[0] as QueryResult<unknown> | undefined;
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
afterEach(() => {
|
|
29
|
+
sinon.restore();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('should invoke the subscriber callback', () => {
|
|
33
|
+
callback.calledOnce.should.be.true;
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it('should report isAuthorized as false', () => {
|
|
37
|
+
receivedResult!.isAuthorized.should.be.false;
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it('should report isSuccess as false', () => {
|
|
41
|
+
receivedResult!.isSuccess.should.be.false;
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('should remove the subscription', () => {
|
|
45
|
+
context.connection.queryCount.should.equal(0);
|
|
46
|
+
});
|
|
47
|
+
}));
|