@cratis/arc 22.0.2 → 22.2.0
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/queries/ObservableQueryFor.js +6 -1
- package/dist/cjs/queries/ObservableQueryFor.js.map +1 -1
- package/dist/cjs/queries/QueryInstanceCache.js +6 -6
- package/dist/cjs/queries/QueryInstanceCache.js.map +1 -1
- package/dist/cjs/queries/QueryResult.js +23 -4
- package/dist/cjs/queries/QueryResult.js.map +1 -1
- package/dist/cjs/queries/QueryResultWithState.js +20 -7
- package/dist/cjs/queries/QueryResultWithState.js.map +1 -1
- package/dist/cjs/queries/ServerSentEventHubConnection.js +120 -58
- package/dist/cjs/queries/ServerSentEventHubConnection.js.map +1 -1
- package/dist/cjs/queries/WebSocketHubConnection.js +121 -51
- package/dist/cjs/queries/WebSocketHubConnection.js.map +1 -1
- package/dist/esm/queries/IQueryResult.d.ts +1 -0
- package/dist/esm/queries/IQueryResult.d.ts.map +1 -1
- package/dist/esm/queries/ObservableQueryFor.d.ts.map +1 -1
- package/dist/esm/queries/ObservableQueryFor.js +6 -1
- package/dist/esm/queries/ObservableQueryFor.js.map +1 -1
- package/dist/esm/queries/QueryInstanceCache.d.ts +1 -1
- package/dist/esm/queries/QueryInstanceCache.d.ts.map +1 -1
- package/dist/esm/queries/QueryInstanceCache.js +6 -6
- package/dist/esm/queries/QueryInstanceCache.js.map +1 -1
- package/dist/esm/queries/QueryResult.d.ts +2 -0
- package/dist/esm/queries/QueryResult.d.ts.map +1 -1
- package/dist/esm/queries/QueryResult.js +23 -4
- package/dist/esm/queries/QueryResult.js.map +1 -1
- package/dist/esm/queries/QueryResultWithState.d.ts +3 -3
- package/dist/esm/queries/QueryResultWithState.d.ts.map +1 -1
- package/dist/esm/queries/QueryResultWithState.js +20 -7
- package/dist/esm/queries/QueryResultWithState.js.map +1 -1
- package/dist/esm/queries/ServerSentEventHubConnection.d.ts +11 -4
- package/dist/esm/queries/ServerSentEventHubConnection.d.ts.map +1 -1
- package/dist/esm/queries/ServerSentEventHubConnection.js +120 -58
- package/dist/esm/queries/ServerSentEventHubConnection.js.map +1 -1
- package/dist/esm/queries/WebSocketHubConnection.d.ts +13 -2
- package/dist/esm/queries/WebSocketHubConnection.d.ts.map +1 -1
- package/dist/esm/queries/WebSocketHubConnection.js +121 -51
- package/dist/esm/queries/WebSocketHubConnection.js.map +1 -1
- package/dist/esm/queries/for_ObservableQueryFor/when_performing/with_a_not_ready_result.d.ts +2 -0
- package/dist/esm/queries/for_ObservableQueryFor/when_performing/with_a_not_ready_result.d.ts.map +1 -0
- package/dist/esm/queries/for_ObservableQueryFor/when_performing/with_a_not_ready_result.js +34 -0
- package/dist/esm/queries/for_ObservableQueryFor/when_performing/with_a_not_ready_result.js.map +1 -0
- package/dist/esm/queries/for_ObservableQueryFor/when_subscribing/with_direct_mode_and_sse_transport.js +26 -2
- package/dist/esm/queries/for_ObservableQueryFor/when_subscribing/with_direct_mode_and_sse_transport.js.map +1 -1
- package/dist/esm/queries/for_ObservableQueryFor/when_subscribing/with_direct_mode_disabled_and_sse_transport.js +60 -3
- package/dist/esm/queries/for_ObservableQueryFor/when_subscribing/with_direct_mode_disabled_and_sse_transport.js.map +1 -1
- package/dist/esm/queries/for_ObservableQueryFor/when_subscribing/with_web_socket_hub_payload_without_readiness.d.ts +2 -0
- package/dist/esm/queries/for_ObservableQueryFor/when_subscribing/with_web_socket_hub_payload_without_readiness.d.ts.map +1 -0
- package/dist/esm/queries/for_ObservableQueryFor/when_subscribing/with_web_socket_hub_payload_without_readiness.js +83 -0
- package/dist/esm/queries/for_ObservableQueryFor/when_subscribing/with_web_socket_hub_payload_without_readiness.js.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_setting_last_result/with_only_readiness_changed.d.ts +2 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_setting_last_result/with_only_readiness_changed.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_setting_last_result/with_only_readiness_changed.js +22 -0
- package/dist/esm/queries/for_QueryInstanceCache/when_setting_last_result/with_only_readiness_changed.js.map +1 -0
- package/dist/esm/queries/for_QueryResult/when_constructing_from_a_server_result/with_readiness_false.d.ts +2 -0
- package/dist/esm/queries/for_QueryResult/when_constructing_from_a_server_result/with_readiness_false.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryResult/when_constructing_from_a_server_result/with_readiness_false.js +17 -0
- package/dist/esm/queries/for_QueryResult/when_constructing_from_a_server_result/with_readiness_false.js.map +1 -0
- package/dist/esm/queries/for_QueryResult/when_constructing_from_a_server_result/without_readiness.d.ts +2 -0
- package/dist/esm/queries/for_QueryResult/when_constructing_from_a_server_result/without_readiness.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryResult/when_constructing_from_a_server_result/without_readiness.js +16 -0
- package/dist/esm/queries/for_QueryResult/when_constructing_from_a_server_result/without_readiness.js.map +1 -0
- package/dist/esm/queries/for_QueryResultWithState/when_creating_from_query_result/with_readiness_false.d.ts +2 -0
- package/dist/esm/queries/for_QueryResultWithState/when_creating_from_query_result/with_readiness_false.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryResultWithState/when_creating_from_query_result/with_readiness_false.js +19 -0
- package/dist/esm/queries/for_QueryResultWithState/when_creating_from_query_result/with_readiness_false.js.map +1 -0
- package/dist/esm/queries/for_QueryResultWithState/when_creating_from_query_result/without_readiness.d.ts +2 -0
- package/dist/esm/queries/for_QueryResultWithState/when_creating_from_query_result/without_readiness.d.ts.map +1 -0
- package/dist/esm/queries/for_QueryResultWithState/when_creating_from_query_result/without_readiness.js +19 -0
- package/dist/esm/queries/for_QueryResultWithState/when_creating_from_query_result/without_readiness.js.map +1 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/given/a_deferred_promise.d.ts +7 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/given/a_deferred_promise.d.ts.map +1 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/given/a_deferred_promise.js +12 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/given/a_deferred_promise.js.map +1 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/given/a_server_sent_event_hub_connection.d.ts +2 -1
- package/dist/esm/queries/for_ServerSentEventHubConnection/given/a_server_sent_event_hub_connection.d.ts.map +1 -1
- package/dist/esm/queries/for_ServerSentEventHubConnection/given/a_server_sent_event_hub_connection.js +15 -4
- package/dist/esm/queries/for_ServerSentEventHubConnection/given/a_server_sent_event_hub_connection.js.map +1 -1
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_a_retired_event_source_fires/ignores_connected_and_error_callbacks.d.ts +2 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_a_retired_event_source_fires/ignores_connected_and_error_callbacks.d.ts.map +1 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_a_retired_event_source_fires/ignores_connected_and_error_callbacks.js +44 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_a_retired_event_source_fires/ignores_connected_and_error_callbacks.js.map +1 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_connection_changes_while_subscribe_is_in_flight/and_the_query_is_replaced.d.ts +2 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_connection_changes_while_subscribe_is_in_flight/and_the_query_is_replaced.d.ts.map +1 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_connection_changes_while_subscribe_is_in_flight/and_the_query_is_replaced.js +74 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_connection_changes_while_subscribe_is_in_flight/and_the_query_is_replaced.js.map +1 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_connection_changes_while_subscribe_is_in_flight/and_the_query_is_unsubscribed.d.ts +2 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_connection_changes_while_subscribe_is_in_flight/and_the_query_is_unsubscribed.d.ts.map +1 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_connection_changes_while_subscribe_is_in_flight/and_the_query_is_unsubscribed.js +74 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_connection_changes_while_subscribe_is_in_flight/and_the_query_is_unsubscribed.js.map +1 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_connection_changes_while_subscribe_is_in_flight/and_the_stale_request_is_rejected.d.ts +2 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_connection_changes_while_subscribe_is_in_flight/and_the_stale_request_is_rejected.d.ts.map +1 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_connection_changes_while_subscribe_is_in_flight/and_the_stale_request_is_rejected.js +59 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_connection_changes_while_subscribe_is_in_flight/and_the_stale_request_is_rejected.js.map +1 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_connection_changes_while_subscribe_is_in_flight/and_the_stale_request_returns_non_ok.d.ts +2 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_connection_changes_while_subscribe_is_in_flight/and_the_stale_request_returns_non_ok.d.ts.map +1 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_connection_changes_while_subscribe_is_in_flight/and_the_stale_request_returns_non_ok.js +58 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_connection_changes_while_subscribe_is_in_flight/and_the_stale_request_returns_non_ok.js.map +1 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_disposing/cleans_up_resources.js +6 -3
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_disposing/cleans_up_resources.js.map +1 -1
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_receiving_unauthorized/notifies_subscriber_and_removes_subscription.js +23 -6
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_receiving_unauthorized/notifies_subscriber_and_removes_subscription.js.map +1 -1
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_reconnecting/after_error.js +20 -5
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_reconnecting/after_error.js.map +1 -1
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_reconnecting/and_an_immediate_open_wins_the_backoff_race.d.ts +2 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_reconnecting/and_an_immediate_open_wins_the_backoff_race.d.ts.map +1 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_reconnecting/and_an_immediate_open_wins_the_backoff_race.js +20 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_reconnecting/and_an_immediate_open_wins_the_backoff_race.js.map +1 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_replacing_a_subscription/ignores_messages_from_the_retired_generation.d.ts +2 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_replacing_a_subscription/ignores_messages_from_the_retired_generation.d.ts.map +1 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_replacing_a_subscription/ignores_messages_from_the_retired_generation.js +68 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_replacing_a_subscription/ignores_messages_from_the_retired_generation.js.map +1 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_subscribing/sends_subscribe_post.js +38 -13
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_subscribing/sends_subscribe_post.js.map +1 -1
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_subscription_revisions_are_not_advertised/uses_legacy_protocol.d.ts +2 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_subscription_revisions_are_not_advertised/uses_legacy_protocol.d.ts.map +1 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_subscription_revisions_are_not_advertised/uses_legacy_protocol.js +54 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_subscription_revisions_are_not_advertised/uses_legacy_protocol.js.map +1 -0
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_unsubscribing/the_only_query.js +18 -4
- package/dist/esm/queries/for_ServerSentEventHubConnection/when_unsubscribing/the_only_query.js.map +1 -1
- package/dist/esm/queries/for_WebSocketHubConnection/when_receiving_unauthorized/notifies_subscriber_and_removes_subscription.js +22 -5
- package/dist/esm/queries/for_WebSocketHubConnection/when_receiving_unauthorized/notifies_subscriber_and_removes_subscription.js.map +1 -1
- package/dist/esm/queries/for_WebSocketHubConnection/when_reconnecting/ignores_a_pending_reconnect_and_stale_socket_callbacks.d.ts +2 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_reconnecting/ignores_a_pending_reconnect_and_stale_socket_callbacks.d.ts.map +1 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_reconnecting/ignores_a_pending_reconnect_and_stale_socket_callbacks.js +108 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_reconnecting/ignores_a_pending_reconnect_and_stale_socket_callbacks.js.map +1 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_reconnecting/replaces_a_closing_socket_safely.d.ts +2 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_reconnecting/replaces_a_closing_socket_safely.d.ts.map +1 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_reconnecting/replaces_a_closing_socket_safely.js +33 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_reconnecting/replaces_a_closing_socket_safely.js.map +1 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_reconnecting/resubscribes_all_queries.js +26 -4
- package/dist/esm/queries/for_WebSocketHubConnection/when_reconnecting/resubscribes_all_queries.js.map +1 -1
- package/dist/esm/queries/for_WebSocketHubConnection/when_replacing_a_subscription/ignores_stale_result_unauthorized_and_error.d.ts +2 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_replacing_a_subscription/ignores_stale_result_unauthorized_and_error.d.ts.map +1 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_replacing_a_subscription/ignores_stale_result_unauthorized_and_error.js +62 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_replacing_a_subscription/ignores_stale_result_unauthorized_and_error.js.map +1 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_subscribing/to_a_query.js +18 -5
- package/dist/esm/queries/for_WebSocketHubConnection/when_subscribing/to_a_query.js.map +1 -1
- package/dist/esm/queries/for_WebSocketHubConnection/when_subscription_revisions_are_supported/upgrades_active_subscriptions_to_strict_mode.d.ts +2 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_subscription_revisions_are_supported/upgrades_active_subscriptions_to_strict_mode.d.ts.map +1 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_subscription_revisions_are_supported/upgrades_active_subscriptions_to_strict_mode.js +56 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_subscription_revisions_are_supported/upgrades_active_subscriptions_to_strict_mode.js.map +1 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_unsubscribing/the_only_query.js +16 -3
- package/dist/esm/queries/for_WebSocketHubConnection/when_unsubscribing/the_only_query.js.map +1 -1
- package/dist/esm/queries/for_WebSocketHubConnection/when_unsubscribing/with_revision_support_not_advertised.d.ts +2 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_unsubscribing/with_revision_support_not_advertised.d.ts.map +1 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_unsubscribing/with_revision_support_not_advertised.js +33 -0
- package/dist/esm/queries/for_WebSocketHubConnection/when_unsubscribing/with_revision_support_not_advertised.js.map +1 -0
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/queries/IQueryResult.ts +10 -0
- package/queries/ObservableQueryFor.ts +44 -16
- package/queries/QueryInstanceCache.ts +42 -19
- package/queries/QueryResult.ts +145 -79
- package/queries/QueryResultWithState.ts +32 -9
- package/queries/ServerSentEventHubConnection.ts +270 -83
- package/queries/WebSocketHubConnection.ts +188 -56
- package/queries/for_ObservableQueryFor/when_performing/with_a_not_ready_result.ts +46 -0
- package/queries/for_ObservableQueryFor/when_subscribing/with_direct_mode_and_sse_transport.ts +91 -57
- package/queries/for_ObservableQueryFor/when_subscribing/with_direct_mode_disabled_and_sse_transport.ts +125 -53
- package/queries/for_ObservableQueryFor/when_subscribing/with_web_socket_hub_payload_without_readiness.ts +107 -0
- package/queries/for_QueryInstanceCache/when_setting_last_result/with_only_readiness_changed.ts +63 -0
- package/queries/for_QueryResult/when_constructing_from_a_server_result/with_readiness_false.ts +25 -0
- package/queries/for_QueryResult/when_constructing_from_a_server_result/without_readiness.ts +24 -0
- package/queries/for_QueryResultWithState/when_creating_from_query_result/with_readiness_false.ts +28 -0
- package/queries/for_QueryResultWithState/when_creating_from_query_result/without_readiness.ts +25 -0
- package/queries/for_ServerSentEventHubConnection/given/a_deferred_promise.ts +15 -0
- package/queries/for_ServerSentEventHubConnection/given/a_server_sent_event_hub_connection.ts +18 -7
- package/queries/for_ServerSentEventHubConnection/when_a_retired_event_source_fires/ignores_connected_and_error_callbacks.ts +59 -0
- package/queries/for_ServerSentEventHubConnection/when_connection_changes_while_subscribe_is_in_flight/and_the_query_is_replaced.ts +113 -0
- package/queries/for_ServerSentEventHubConnection/when_connection_changes_while_subscribe_is_in_flight/and_the_query_is_unsubscribed.ts +109 -0
- package/queries/for_ServerSentEventHubConnection/when_connection_changes_while_subscribe_is_in_flight/and_the_stale_request_is_rejected.ts +81 -0
- package/queries/for_ServerSentEventHubConnection/when_connection_changes_while_subscribe_is_in_flight/and_the_stale_request_returns_non_ok.ts +83 -0
- package/queries/for_ServerSentEventHubConnection/when_disposing/cleans_up_resources.ts +30 -21
- package/queries/for_ServerSentEventHubConnection/when_receiving_unauthorized/notifies_subscriber_and_removes_subscription.ts +56 -32
- package/queries/for_ServerSentEventHubConnection/when_reconnecting/after_error.ts +23 -6
- package/queries/for_ServerSentEventHubConnection/when_reconnecting/and_an_immediate_open_wins_the_backoff_race.ts +41 -0
- package/queries/for_ServerSentEventHubConnection/when_replacing_a_subscription/ignores_messages_from_the_retired_generation.ts +92 -0
- package/queries/for_ServerSentEventHubConnection/when_subscribing/sends_subscribe_post.ts +69 -30
- package/queries/for_ServerSentEventHubConnection/when_subscription_revisions_are_not_advertised/uses_legacy_protocol.ts +69 -0
- package/queries/for_ServerSentEventHubConnection/when_unsubscribing/the_only_query.ts +43 -24
- package/queries/for_WebSocketHubConnection/when_receiving_unauthorized/notifies_subscriber_and_removes_subscription.ts +53 -29
- package/queries/for_WebSocketHubConnection/when_reconnecting/ignores_a_pending_reconnect_and_stale_socket_callbacks.ts +131 -0
- package/queries/for_WebSocketHubConnection/when_reconnecting/replaces_a_closing_socket_safely.ts +39 -0
- package/queries/for_WebSocketHubConnection/when_reconnecting/resubscribes_all_queries.ts +72 -36
- package/queries/for_WebSocketHubConnection/when_replacing_a_subscription/ignores_stale_result_unauthorized_and_error.ts +88 -0
- package/queries/for_WebSocketHubConnection/when_subscribing/to_a_query.ts +54 -27
- package/queries/for_WebSocketHubConnection/when_subscription_revisions_are_supported/upgrades_active_subscriptions_to_strict_mode.ts +72 -0
- package/queries/for_WebSocketHubConnection/when_unsubscribing/the_only_query.ts +43 -18
- package/queries/for_WebSocketHubConnection/when_unsubscribing/with_revision_support_not_advertised.ts +44 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import sinon from 'sinon';
|
|
2
|
+
import { given } from '../../../given';
|
|
3
|
+
import { HubMessageType } from '../../WebSocketHubConnection';
|
|
4
|
+
import { a_server_sent_event_hub_connection } from '../given/a_server_sent_event_hub_connection';
|
|
5
|
+
describe('when the SSE server does not advertise subscription revision support', given(a_server_sent_event_hub_connection, (context) => {
|
|
6
|
+
const queryId = 'query-1';
|
|
7
|
+
let callback;
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
context.setup();
|
|
10
|
+
callback = sinon.stub();
|
|
11
|
+
context.connection.subscribe(queryId, { queryName: 'MyQuery' }, callback);
|
|
12
|
+
context.simulateOpen();
|
|
13
|
+
context.simulateMessage({
|
|
14
|
+
type: HubMessageType.Connected,
|
|
15
|
+
payload: 'legacy-connection',
|
|
16
|
+
});
|
|
17
|
+
context.simulateMessage({
|
|
18
|
+
type: HubMessageType.QueryResult,
|
|
19
|
+
queryId,
|
|
20
|
+
payload: { data: ['legacy'] },
|
|
21
|
+
});
|
|
22
|
+
context.connection.unsubscribe(queryId);
|
|
23
|
+
});
|
|
24
|
+
afterEach(() => sinon.restore());
|
|
25
|
+
it('should omit the revision from the subscribe request', () => (subscribeBody().revision === undefined).should.equal(true));
|
|
26
|
+
it('should accept a missing-revision result frame', () => {
|
|
27
|
+
callback.calledOnce.should.equal(true);
|
|
28
|
+
callback.firstCall.args[0].should.deep.equal({ data: ['legacy'] });
|
|
29
|
+
});
|
|
30
|
+
it('should omit the revision from the unsubscribe request', () => (unsubscribeBody().revision === undefined).should.equal(true));
|
|
31
|
+
function subscribeBody() {
|
|
32
|
+
return parseBody(context.fetchStub.firstCall.args[1].body);
|
|
33
|
+
}
|
|
34
|
+
function unsubscribeBody() {
|
|
35
|
+
const unsubscribeCall = context.fetchStub
|
|
36
|
+
.getCalls()
|
|
37
|
+
.find((call) => call.args[0].includes('unsubscribe'));
|
|
38
|
+
if (!unsubscribeCall) {
|
|
39
|
+
throw new Error('Expected an unsubscribe request');
|
|
40
|
+
}
|
|
41
|
+
return parseBody(unsubscribeCall.args[1].body);
|
|
42
|
+
}
|
|
43
|
+
function parseBody(rawBody) {
|
|
44
|
+
try {
|
|
45
|
+
return JSON.parse(rawBody);
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
throw new Error('Expected a valid subscription request body', {
|
|
49
|
+
cause: error,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}));
|
|
54
|
+
//# sourceMappingURL=uses_legacy_protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"uses_legacy_protocol.js","sourceRoot":"","sources":["../../../../../queries/for_ServerSentEventHubConnection/when_subscription_revisions_are_not_advertised/uses_legacy_protocol.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,kCAAkC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AAC,EAAE,IAAI,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;IACvE,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,uDAAuD,EAAE,GAAG,EAAE,CAC7D,CAAC,eAAe,EAAE,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;IAEnE,SAAS,aAAa;QAClB,OAAO,SAAS,CAAC,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAc,CAAC,CAAC;IACzE,CAAC;IAED,SAAS,eAAe;QACpB,MAAM,eAAe,GAAG,OAAO,CAAC,SAAS;aACpC,QAAQ,EAAE;aACV,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAE,IAAI,CAAC,IAAI,CAAC,CAAC,CAAY,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC,CAAC;QACtE,IAAI,CAAC,eAAe,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;QACvD,CAAC;QACD,OAAO,SAAS,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAc,CAAC,CAAC;IAC7D,CAAC;IAED,SAAS,SAAS,CAAC,OAAe;QAC9B,IAAI,CAAC;YACD,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAA0B,CAAC;QACxD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,4CAA4C,EAAE;gBAC1D,KAAK,EAAE,KAAK;aACf,CAAC,CAAC;QACP,CAAC;IACL,CAAC;AACL,CAAC,CAAC,CACL,CAAC"}
|
package/dist/esm/queries/for_ServerSentEventHubConnection/when_unsubscribing/the_only_query.js
CHANGED
|
@@ -2,20 +2,34 @@ import sinon from 'sinon';
|
|
|
2
2
|
import { a_server_sent_event_hub_connection } from '../given/a_server_sent_event_hub_connection';
|
|
3
3
|
import { given } from '../../../given';
|
|
4
4
|
import { HubMessageType } from '../../WebSocketHubConnection';
|
|
5
|
-
describe('when unsubscribing the only query', given(a_server_sent_event_hub_connection, context => {
|
|
5
|
+
describe('when unsubscribing the only query', given(a_server_sent_event_hub_connection, (context) => {
|
|
6
6
|
beforeEach(async () => {
|
|
7
7
|
context.setup();
|
|
8
8
|
context.connection.subscribe('q1', { queryName: 'MyQuery' }, sinon.stub());
|
|
9
9
|
context.simulateOpen();
|
|
10
|
-
context.simulateMessage({
|
|
10
|
+
context.simulateMessage({
|
|
11
|
+
type: HubMessageType.Connected,
|
|
12
|
+
payload: 'conn-abc',
|
|
13
|
+
supportsSubscriptionRevisions: true,
|
|
14
|
+
});
|
|
11
15
|
context.connection.unsubscribe('q1');
|
|
12
16
|
await Promise.resolve();
|
|
13
17
|
});
|
|
14
18
|
afterEach(() => sinon.restore());
|
|
15
19
|
it('should close the event source', () => context.fakeEventSource.close.calledOnce.should.be.true);
|
|
16
|
-
it('should send an unsubscribe POST request', () => {
|
|
17
|
-
const unsubscribeCalls = context.fetchStub.args.filter((args) => typeof args[0] === 'string' &&
|
|
20
|
+
it('should send an unsubscribe POST request with the exact revision', () => {
|
|
21
|
+
const unsubscribeCalls = context.fetchStub.args.filter((args) => typeof args[0] === 'string' &&
|
|
22
|
+
args[0].includes('unsubscribe'));
|
|
18
23
|
unsubscribeCalls.length.should.equal(1);
|
|
24
|
+
getBody(unsubscribeCalls[0][1]).revision.should.equal(1);
|
|
19
25
|
});
|
|
26
|
+
function getBody(init) {
|
|
27
|
+
try {
|
|
28
|
+
return JSON.parse(init.body);
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
throw new Error('Expected a valid unsubscribe body', { cause: error });
|
|
32
|
+
}
|
|
33
|
+
}
|
|
20
34
|
}));
|
|
21
35
|
//# sourceMappingURL=the_only_query.js.map
|
package/dist/esm/queries/for_ServerSentEventHubConnection/when_unsubscribing/the_only_query.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"the_only_query.js","sourceRoot":"","sources":["../../../../../queries/for_ServerSentEventHubConnection/when_unsubscribing/the_only_query.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,kCAAkC,EAAE,MAAM,6CAA6C,CAAC;AACjG,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D,QAAQ,
|
|
1
|
+
{"version":3,"file":"the_only_query.js","sourceRoot":"","sources":["../../../../../queries/for_ServerSentEventHubConnection/when_unsubscribing/the_only_query.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,kCAAkC,EAAE,MAAM,6CAA6C,CAAC;AACjG,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE9D,QAAQ,CACJ,mCAAmC,EACnC,KAAK,CAAC,kCAAkC,EAAE,CAAC,OAAO,EAAE,EAAE;IAClD,UAAU,CAAC,KAAK,IAAI,EAAE;QAClB,OAAO,CAAC,KAAK,EAAE,CAAC;QAChB,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,SAAS,EAAE,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;QAC3E,OAAO,CAAC,YAAY,EAAE,CAAC;QACvB,OAAO,CAAC,eAAe,CAAC;YACpB,IAAI,EAAE,cAAc,CAAC,SAAS;YAC9B,OAAO,EAAE,UAAU;YACnB,6BAA6B,EAAE,IAAI;SACtC,CAAC,CAAC;QAEH,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QAGrC,MAAM,OAAO,CAAC,OAAO,EAAE,CAAC;IAC5B,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IAEjC,EAAE,CAAC,+BAA+B,EAAE,GAAG,EAAE,CACrC,OAAO,CAAC,eAAe,CAAC,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;IAE7D,EAAE,CAAC,iEAAiE,EAAE,GAAG,EAAE;QACvE,MAAM,gBAAgB,GAAG,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAClD,CAAC,IAAe,EAAE,EAAE,CAChB,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ;YAC1B,IAAI,CAAC,CAAC,CAAY,CAAC,QAAQ,CAAC,aAAa,CAAC,CAClD,CAAC;QACF,gBAAgB,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;QACxC,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC7D,CAAC,CAAC,CAAC;IAEH,SAAS,OAAO,CAAC,IAAiB;QAC9B,IAAI,CAAC;YACD,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAc,CAAyB,CAAC;QACnE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,mCAAmC,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;QAC3E,CAAC;IACL,CAAC;AACL,CAAC,CAAC,CACL,CAAC"}
|
|
@@ -2,7 +2,7 @@ import sinon from 'sinon';
|
|
|
2
2
|
import { a_web_socket_hub_connection } from '../given/a_web_socket_hub_connection';
|
|
3
3
|
import { given } from '../../../given';
|
|
4
4
|
import { HubMessageType } from '../../WebSocketHubConnection';
|
|
5
|
-
describe('when receiving unauthorized for a subscribed query', given(a_web_socket_hub_connection, context => {
|
|
5
|
+
describe('when receiving unauthorized for a subscribed query', given(a_web_socket_hub_connection, (context) => {
|
|
6
6
|
let callback;
|
|
7
7
|
let receivedResult;
|
|
8
8
|
const queryId = 'q-auth-1';
|
|
@@ -11,20 +11,37 @@ describe('when receiving unauthorized for a subscribed query', given(a_web_socke
|
|
|
11
11
|
callback = sinon.stub();
|
|
12
12
|
context.connection.subscribe(queryId, { queryName: 'SecureQuery' }, callback);
|
|
13
13
|
context.simulateOpen();
|
|
14
|
-
context.simulateMessage({
|
|
14
|
+
context.simulateMessage({
|
|
15
|
+
type: HubMessageType.Connected,
|
|
16
|
+
supportsSubscriptionRevisions: true,
|
|
17
|
+
});
|
|
18
|
+
const subscribe = getSubscribeMessage();
|
|
19
|
+
context.simulateMessage({
|
|
20
|
+
type: HubMessageType.Unauthorized,
|
|
21
|
+
queryId,
|
|
22
|
+
revision: subscribe.revision,
|
|
23
|
+
});
|
|
15
24
|
receivedResult = callback.firstCall?.args[0];
|
|
16
25
|
});
|
|
17
26
|
afterEach(() => {
|
|
18
27
|
sinon.restore();
|
|
19
28
|
});
|
|
29
|
+
function getSubscribeMessage() {
|
|
30
|
+
try {
|
|
31
|
+
return JSON.parse(context.fakeSocket.send.getCall(1).args[0]);
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
throw new Error('Expected a valid subscribe message', { cause: error });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
20
37
|
it('should invoke the subscriber callback', () => {
|
|
21
|
-
callback.calledOnce.should.
|
|
38
|
+
callback.calledOnce.should.equal(true);
|
|
22
39
|
});
|
|
23
40
|
it('should report isAuthorized as false', () => {
|
|
24
|
-
receivedResult.isAuthorized.should.
|
|
41
|
+
receivedResult.isAuthorized.should.equal(false);
|
|
25
42
|
});
|
|
26
43
|
it('should report isSuccess as false', () => {
|
|
27
|
-
receivedResult.isSuccess.should.
|
|
44
|
+
receivedResult.isSuccess.should.equal(false);
|
|
28
45
|
});
|
|
29
46
|
it('should remove the subscription', () => {
|
|
30
47
|
context.connection.queryCount.should.equal(0);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notifies_subscriber_and_removes_subscription.js","sourceRoot":"","sources":["../../../../../queries/for_WebSocketHubConnection/when_receiving_unauthorized/notifies_subscriber_and_removes_subscription.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,2BAA2B,EAAE,MAAM,sCAAsC,CAAC;AACnF,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAG9D,QAAQ,
|
|
1
|
+
{"version":3,"file":"notifies_subscriber_and_removes_subscription.js","sourceRoot":"","sources":["../../../../../queries/for_WebSocketHubConnection/when_receiving_unauthorized/notifies_subscriber_and_removes_subscription.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,2BAA2B,EAAE,MAAM,sCAAsC,CAAC;AACnF,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAG9D,QAAQ,CACJ,oDAAoD,EACpD,KAAK,CAAC,2BAA2B,EAAE,CAAC,OAAO,EAAE,EAAE;IAC3C,IAAI,QAAyB,CAAC;IAC9B,IAAI,cAAgD,CAAC;IACrD,MAAM,OAAO,GAAG,UAAU,CAAC;IAE3B,UAAU,CAAC,GAAG,EAAE;QACZ,OAAO,CAAC,KAAK,EAAE,CAAC;QAChB,QAAQ,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;QAExB,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,OAAO,EAAE,EAAE,SAAS,EAAE,aAAa,EAAE,EAAE,QAAQ,CAAC,CAAC;QAC9E,OAAO,CAAC,YAAY,EAAE,CAAC;QACvB,OAAO,CAAC,eAAe,CAAC;YACpB,IAAI,EAAE,cAAc,CAAC,SAAS;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U,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAClD,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CACL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ignores_a_pending_reconnect_and_stale_socket_callbacks.d.ts","sourceRoot":"","sources":["../../../../../queries/for_WebSocketHubConnection/when_reconnecting/ignores_a_pending_reconnect_and_stale_socket_callbacks.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import sinon from 'sinon';
|
|
2
|
+
import { a_web_socket_hub_connection } from '../given/a_web_socket_hub_connection';
|
|
3
|
+
import { given } from '../../../given';
|
|
4
|
+
import { HubMessageType } from '../../WebSocketHubConnection';
|
|
5
|
+
for (const supportsSubscriptionRevisions of [false, true]) {
|
|
6
|
+
const mode = supportsSubscriptionRevisions ? 'revision-aware' : 'legacy';
|
|
7
|
+
describe(`when an immediate ${mode} socket open wins during reconnect backoff`, given(a_web_socket_hub_connection, context => {
|
|
8
|
+
const queryId = 'query-a';
|
|
9
|
+
let callback;
|
|
10
|
+
let secondSocket;
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
context.setup();
|
|
13
|
+
sinon.stub(console, 'log');
|
|
14
|
+
sinon.stub(console, 'warn');
|
|
15
|
+
sinon.stub(console, 'error');
|
|
16
|
+
callback = sinon.stub();
|
|
17
|
+
context.connection.subscribe(queryId, { queryName: 'Original' }, sinon.stub());
|
|
18
|
+
const firstSocket = context.fakeSocket;
|
|
19
|
+
firstSocket.readyState = WebSocket.OPEN;
|
|
20
|
+
firstSocket.onopen?.();
|
|
21
|
+
if (supportsSubscriptionRevisions) {
|
|
22
|
+
firstSocket.onmessage?.(messageEvent({
|
|
23
|
+
type: HubMessageType.Connected,
|
|
24
|
+
supportsSubscriptionRevisions: true,
|
|
25
|
+
}));
|
|
26
|
+
}
|
|
27
|
+
const staleMessage = firstSocket.onmessage;
|
|
28
|
+
const staleClose = firstSocket.onclose;
|
|
29
|
+
const staleError = firstSocket.onerror;
|
|
30
|
+
firstSocket.readyState = WebSocket.CLOSED;
|
|
31
|
+
staleClose();
|
|
32
|
+
secondSocket = createSocket();
|
|
33
|
+
context.WebSocketStub.onSecondCall().returns(secondSocket);
|
|
34
|
+
context.connection.subscribe(queryId, { queryName: 'Replacement' }, callback);
|
|
35
|
+
const reconnectCallback = context.policy.schedule.firstCall.args[0];
|
|
36
|
+
reconnectCallback();
|
|
37
|
+
secondSocket.readyState = WebSocket.OPEN;
|
|
38
|
+
secondSocket.onopen?.();
|
|
39
|
+
if (supportsSubscriptionRevisions) {
|
|
40
|
+
secondSocket.onmessage?.(messageEvent({
|
|
41
|
+
type: HubMessageType.Connected,
|
|
42
|
+
supportsSubscriptionRevisions: true,
|
|
43
|
+
}));
|
|
44
|
+
}
|
|
45
|
+
const revision = supportsSubscriptionRevisions
|
|
46
|
+
? sentMessages(secondSocket).find(message => message.type === HubMessageType.Subscribe && message.revision !== undefined).revision
|
|
47
|
+
: undefined;
|
|
48
|
+
staleMessage(messageEvent({
|
|
49
|
+
type: HubMessageType.Connected,
|
|
50
|
+
supportsSubscriptionRevisions: true,
|
|
51
|
+
}));
|
|
52
|
+
staleMessage(messageEvent({
|
|
53
|
+
type: HubMessageType.QueryResult,
|
|
54
|
+
queryId,
|
|
55
|
+
revision,
|
|
56
|
+
payload: { data: ['stale'] },
|
|
57
|
+
}));
|
|
58
|
+
staleMessage(messageEvent({
|
|
59
|
+
type: HubMessageType.Unauthorized,
|
|
60
|
+
queryId,
|
|
61
|
+
revision,
|
|
62
|
+
}));
|
|
63
|
+
staleMessage(messageEvent({
|
|
64
|
+
type: HubMessageType.Error,
|
|
65
|
+
queryId,
|
|
66
|
+
revision,
|
|
67
|
+
payload: 'stale',
|
|
68
|
+
}));
|
|
69
|
+
staleError({});
|
|
70
|
+
staleClose();
|
|
71
|
+
secondSocket.onmessage?.(messageEvent({
|
|
72
|
+
type: HubMessageType.QueryResult,
|
|
73
|
+
queryId,
|
|
74
|
+
revision,
|
|
75
|
+
payload: { data: ['current'] },
|
|
76
|
+
}));
|
|
77
|
+
});
|
|
78
|
+
afterEach(() => {
|
|
79
|
+
context.connection.dispose();
|
|
80
|
+
sinon.restore();
|
|
81
|
+
});
|
|
82
|
+
it('should cancel the pending reconnect when the immediate open wins', () => context.policy.cancel.calledOnce.should.be.true);
|
|
83
|
+
it('should not let the pending callback create a third socket', () => context.WebSocketStub.callCount.should.equal(2));
|
|
84
|
+
it('should not close the current socket', () => secondSocket.close.called.should.be.false);
|
|
85
|
+
it('should not schedule another reconnect from the stale close', () => context.policy.schedule.calledOnce.should.be.true);
|
|
86
|
+
it('should not process stale result or unauthorized frames', () => callback.calledOnce.should.be.true);
|
|
87
|
+
it('should retain the current subscription', () => context.connection.queryCount.should.equal(1));
|
|
88
|
+
it('should not process the stale error frame or callback', () => console.error.called.should.be.false);
|
|
89
|
+
}));
|
|
90
|
+
}
|
|
91
|
+
function createSocket() {
|
|
92
|
+
return {
|
|
93
|
+
onopen: null,
|
|
94
|
+
onclose: null,
|
|
95
|
+
onerror: null,
|
|
96
|
+
onmessage: null,
|
|
97
|
+
send: sinon.stub(),
|
|
98
|
+
close: sinon.stub(),
|
|
99
|
+
readyState: WebSocket.CONNECTING,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
function messageEvent(message) {
|
|
103
|
+
return { data: JSON.stringify(message) };
|
|
104
|
+
}
|
|
105
|
+
function sentMessages(socket) {
|
|
106
|
+
return socket.send.args.map(args => JSON.parse(args[0]));
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=ignores_a_pending_reconnect_and_stale_socket_callbacks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ignores_a_pending_reconnect_and_stale_socket_callbacks.js","sourceRoot":"","sources":["../../../../../queries/for_WebSocketHubConnection/when_reconnecting/ignores_a_pending_reconnect_and_stale_socket_callbacks.ts"],"names":[],"mappings":"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C,CAAe,CAAC,CAAC;AAC3E,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replaces_a_closing_socket_safely.d.ts","sourceRoot":"","sources":["../../../../../queries/for_WebSocketHubConnection/when_reconnecting/replaces_a_closing_socket_safely.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import sinon from 'sinon';
|
|
2
|
+
import { a_web_socket_hub_connection } from '../given/a_web_socket_hub_connection';
|
|
3
|
+
import { given } from '../../../given';
|
|
4
|
+
describe('when opening while the owned socket is closing', given(a_web_socket_hub_connection, context => {
|
|
5
|
+
let firstSocket;
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
context.setup();
|
|
8
|
+
context.connection.subscribe('q1', { queryName: 'First' }, sinon.stub());
|
|
9
|
+
firstSocket = context.fakeSocket;
|
|
10
|
+
firstSocket.readyState = WebSocket.CLOSING;
|
|
11
|
+
context.WebSocketStub.onSecondCall().returns({
|
|
12
|
+
onopen: null,
|
|
13
|
+
onclose: null,
|
|
14
|
+
onerror: null,
|
|
15
|
+
onmessage: null,
|
|
16
|
+
send: sinon.stub(),
|
|
17
|
+
close: sinon.stub(),
|
|
18
|
+
readyState: WebSocket.CONNECTING,
|
|
19
|
+
});
|
|
20
|
+
context.connection.subscribe('q2', { queryName: 'Second' }, sinon.stub());
|
|
21
|
+
});
|
|
22
|
+
afterEach(() => {
|
|
23
|
+
context.connection.dispose();
|
|
24
|
+
sinon.restore();
|
|
25
|
+
});
|
|
26
|
+
it('should close the replaced socket', () => firstSocket.close.calledOnce.should.be.true);
|
|
27
|
+
it('should detach the replaced socket open handler', () => (firstSocket.onopen === null).should.be.true);
|
|
28
|
+
it('should detach the replaced socket close handler', () => (firstSocket.onclose === null).should.be.true);
|
|
29
|
+
it('should detach the replaced socket error handler', () => (firstSocket.onerror === null).should.be.true);
|
|
30
|
+
it('should detach the replaced socket message handler', () => (firstSocket.onmessage === null).should.be.true);
|
|
31
|
+
it('should create one replacement socket', () => context.WebSocketStub.callCount.should.equal(2));
|
|
32
|
+
}));
|
|
33
|
+
//# sourceMappingURL=replaces_a_closing_socket_safely.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"replaces_a_closing_socket_safely.js","sourceRoot":"","sources":["../../../../../queries/for_WebSocketHubConnection/when_reconnecting/replaces_a_closing_socket_safely.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,2BAA2B,EAAE,MAAM,sCAAsC,CAAC;AACnF,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAEvC,QAAQ,CAAC,gDAAgD,EAAE,KAAK,CAAC,2BAA2B,EAAE,OAAO,CAAC,EAAE;IACpG,IAAI,WAAsC,CAAC;IAE3C,UAAU,CAAC,GAAG,EAAE;QACZ,OAAO,CAAC,KAAK,EAAE,CAAC;QAChB,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;QACzE,WAAW,GAAG,OAAO,CAAC,UAAU,CAAC;QACjC,WAAW,CAAC,UAAU,GAAG,SAAS,CAAC,OAAO,CAAC;QAC3C,OAAO,CAAC,aAAa,CAAC,YAAY,EAAE,CAAC,OAAO,CAAC;YACzC,MAAM,EAAE,IAAI;YACZ,OAAO,EAAE,IAAI;YACb,OAAO,EAAE,IAAI;YACb,SAAS,EAAE,IAAI;YACf,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE;YAClB,KAAK,EAAE,KAAK,CAAC,IAAI,EAAE;YACnB,UAAU,EAAE,SAAS,CAAC,UAAU;SACnC,CAAC,CAAC;QACH,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,EAAE,KAAK,CAAC,IAAI,EAAE,CAAC,CAAC;IAC9E,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACX,OAAO,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;QAC7B,KAAK,CAAC,OAAO,EAAE,CAAC;IACpB,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,kCAAkC,EAAE,GAAG,EAAE,CAAC,WAAW,CAAC,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;IAC1F,EAAE,CAAC,gDAAgD,EAAE,GAAG,EAAE,CAAC,CAAC,WAAW,CAAC,MAAM,KAAK,IAAI,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;IACzG,EAAE,CAAC,iDAAiD,EAAE,GAAG,EAAE,CAAC,CAAC,WAAW,CAAC,OAAO,KAAK,IAAI,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;IAC3G,EAAE,CAAC,iDAAiD,EAAE,GAAG,EAAE,CAAC,CAAC,WAAW,CAAC,OAAO,KAAK,IAAI,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;IAC3G,EAAE,CAAC,mDAAmD,EAAE,GAAG,EAAE,CAAC,CAAC,WAAW,CAAC,SAAS,KAAK,IAAI,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;IAC/G,EAAE,CAAC,sCAAsC,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,aAAa,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;AACtG,CAAC,CAAC,CAAC,CAAC"}
|
package/dist/esm/queries/for_WebSocketHubConnection/when_reconnecting/resubscribes_all_queries.js
CHANGED
|
@@ -2,7 +2,7 @@ import sinon from 'sinon';
|
|
|
2
2
|
import { a_web_socket_hub_connection } from '../given/a_web_socket_hub_connection';
|
|
3
3
|
import { given } from '../../../given';
|
|
4
4
|
import { HubMessageType } from '../../WebSocketHubConnection';
|
|
5
|
-
describe('when reconnecting after a drop', given(a_web_socket_hub_connection, context => {
|
|
5
|
+
describe('when reconnecting after a drop', given(a_web_socket_hub_connection, (context) => {
|
|
6
6
|
const queryId = 'q1';
|
|
7
7
|
let callbackStub;
|
|
8
8
|
beforeEach(() => {
|
|
@@ -10,22 +10,44 @@ describe('when reconnecting after a drop', given(a_web_socket_hub_connection, co
|
|
|
10
10
|
context.setup();
|
|
11
11
|
context.connection.subscribe(queryId, { queryName: 'MyQuery' }, callbackStub);
|
|
12
12
|
context.simulateOpen();
|
|
13
|
+
context.simulateMessage({
|
|
14
|
+
type: HubMessageType.Connected,
|
|
15
|
+
supportsSubscriptionRevisions: true,
|
|
16
|
+
});
|
|
13
17
|
context.simulateClose();
|
|
14
18
|
const reconnectCallback = context.policy.schedule.getCall(0).args[0];
|
|
15
19
|
context.fakeSocket.send.reset();
|
|
16
20
|
context.policy.reset.reset();
|
|
17
21
|
reconnectCallback();
|
|
18
22
|
context.simulateOpen();
|
|
23
|
+
context.simulateMessage({
|
|
24
|
+
type: HubMessageType.Connected,
|
|
25
|
+
supportsSubscriptionRevisions: true,
|
|
26
|
+
});
|
|
19
27
|
});
|
|
20
28
|
afterEach(() => sinon.restore());
|
|
21
|
-
it('should
|
|
22
|
-
|
|
23
|
-
const msg = JSON.parse(context.fakeSocket.send.getCall(0).args[0]);
|
|
29
|
+
it('should reset to a legacy subscription on the new socket', () => {
|
|
30
|
+
const msg = getSentMessage(0);
|
|
24
31
|
msg.type.should.equal(HubMessageType.Subscribe);
|
|
25
32
|
msg.queryId.should.equal(queryId);
|
|
33
|
+
(msg.revision === undefined).should.equal(true);
|
|
34
|
+
});
|
|
35
|
+
it('should upgrade the reconnect subscription after the new handshake', () => {
|
|
36
|
+
const msg = getSentMessage(1);
|
|
37
|
+
msg.type.should.equal(HubMessageType.Subscribe);
|
|
38
|
+
msg.queryId.should.equal(queryId);
|
|
39
|
+
(msg.revision ?? 0).should.be.greaterThan(0);
|
|
26
40
|
});
|
|
27
41
|
it('should reset the reconnect policy on successful open', () => {
|
|
28
42
|
context.policy.reset.calledOnce.should.be.true;
|
|
29
43
|
});
|
|
44
|
+
function getSentMessage(index) {
|
|
45
|
+
try {
|
|
46
|
+
return JSON.parse(context.fakeSocket.send.getCall(index).args[0]);
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
throw new Error('Expected a valid hub message', { cause: error });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
30
52
|
}));
|
|
31
53
|
//# sourceMappingURL=resubscribes_all_queries.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resubscribes_all_queries.js","sourceRoot":"","sources":["../../../../../queries/for_WebSocketHubConnection/when_reconnecting/resubscribes_all_queries.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,2BAA2B,EAAE,MAAM,sCAAsC,CAAC;AACnF,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAG9D,QAAQ,
|
|
1
|
+
{"version":3,"file":"resubscribes_all_queries.js","sourceRoot":"","sources":["../../../../../queries/for_WebSocketHubConnection/when_reconnecting/resubscribes_all_queries.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,2BAA2B,EAAE,MAAM,sCAAsC,CAAC;AACnF,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAG9D,QAAQ,CACJ,gCAAgC,EAChC,KAAK,CAAC,2BAA2B,EAAE,CAAC,OAAO,EAAE,EAAE;IAC3C,MAAM,OAAO,GAAG,IAAI,CAAC;IACrB,IAAI,YAA6B,CAAC;IAElC,UAAU,CAAC,GAAG,EAAE;QACZ,YAAY,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC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AEH,EAAE,CAAC,mEAAmE,EAAE,GAAG,EAAE;QACzE,MAAM,GAAG,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC;QAC9B,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;QAChD,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QAClC,CAAC,GAAG,CAAC,QAAQ,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;IACjD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,sDAAsD,EAAE,GAAG,EAAE;QAC3D,OAAO,CAAC,MAAM,CAAC,KAAyB,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC;IACxE,CAAC,CAAC,CAAC;IAEH,SAAS,cAAc,CAAC,KAAa;QAKjC,IAAI,CAAC;YACD,OAAO,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAI/D,CAAC;QACN,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,8BAA8B,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;QACtE,CAAC;IACL,CAAC;AACL,CAAC,CAAC,CACL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ignores_stale_result_unauthorized_and_error.d.ts","sourceRoot":"","sources":["../../../../../queries/for_WebSocketHubConnection/when_replacing_a_subscription/ignores_stale_result_unauthorized_and_error.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import sinon from 'sinon';
|
|
2
|
+
import { a_web_socket_hub_connection } from '../given/a_web_socket_hub_connection';
|
|
3
|
+
import { given } from '../../../given';
|
|
4
|
+
import { HubMessageType } from '../../WebSocketHubConnection';
|
|
5
|
+
describe('when stale frames arrive after a WebSocket subscription is replaced', given(a_web_socket_hub_connection, (context) => {
|
|
6
|
+
const queryId = 'query-a';
|
|
7
|
+
let originalCallback;
|
|
8
|
+
let replacementCallback;
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
context.setup();
|
|
11
|
+
sinon.stub(console, 'warn');
|
|
12
|
+
sinon.stub(console, 'error');
|
|
13
|
+
originalCallback = sinon.stub();
|
|
14
|
+
replacementCallback = sinon.stub();
|
|
15
|
+
context.connection.subscribe(queryId, { queryName: 'Original' }, originalCallback);
|
|
16
|
+
context.simulateOpen();
|
|
17
|
+
context.simulateMessage({
|
|
18
|
+
type: HubMessageType.Connected,
|
|
19
|
+
supportsSubscriptionRevisions: true,
|
|
20
|
+
});
|
|
21
|
+
const originalRevision = sentMessage(1).revision;
|
|
22
|
+
context.connection.subscribe(queryId, { queryName: 'Replacement' }, replacementCallback);
|
|
23
|
+
const replacementRevision = sentMessage(2).revision;
|
|
24
|
+
context.simulateMessage({
|
|
25
|
+
type: HubMessageType.QueryResult,
|
|
26
|
+
queryId,
|
|
27
|
+
revision: originalRevision,
|
|
28
|
+
payload: { data: ['stale'] },
|
|
29
|
+
});
|
|
30
|
+
context.simulateMessage({
|
|
31
|
+
type: HubMessageType.Unauthorized,
|
|
32
|
+
queryId,
|
|
33
|
+
revision: originalRevision,
|
|
34
|
+
});
|
|
35
|
+
context.simulateMessage({
|
|
36
|
+
type: HubMessageType.Error,
|
|
37
|
+
queryId,
|
|
38
|
+
revision: originalRevision,
|
|
39
|
+
payload: 'stale',
|
|
40
|
+
});
|
|
41
|
+
context.simulateMessage({
|
|
42
|
+
type: HubMessageType.QueryResult,
|
|
43
|
+
queryId,
|
|
44
|
+
revision: replacementRevision,
|
|
45
|
+
payload: { data: ['current'] },
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
afterEach(() => sinon.restore());
|
|
49
|
+
it('should not deliver the stale result', () => originalCallback.called.should.be.false);
|
|
50
|
+
it('should deliver the replacement result', () => replacementCallback.calledOnce.should.be.true);
|
|
51
|
+
it('should retain the replacement after stale unauthorized', () => context.connection.queryCount.should.equal(1));
|
|
52
|
+
it('should not log the stale error', () => console.error.called.should.be.false);
|
|
53
|
+
function sentMessage(index) {
|
|
54
|
+
try {
|
|
55
|
+
return JSON.parse(context.fakeSocket.send.getCall(index).args[0]);
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
throw new Error('Expected a valid hub message', { cause: error });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}));
|
|
62
|
+
//# sourceMappingURL=ignores_stale_result_unauthorized_and_error.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ignores_stale_result_unauthorized_and_error.js","sourceRoot":"","sources":["../../../../../queries/for_WebSocketHubConnection/when_replacing_a_subscription/ignores_stale_result_unauthorized_and_error.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,2BAA2B,EAAE,MAAM,sCAAsC,CAAC;AACnF,OAAO,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AACvC,OAAO,EAAmB,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAE/E,QAAQ,CACJ,qEAAqE,EACrE,KAAK,CAAC,2BAA2B,EAAE,CAAC,OAAO,EAAE,EAAE;IAC3C,MAAM,OAAO,GAAG,SAAS,CAAC;IAC1B,IAAI,gBAAiC,CAAC;IACtC,IAAI,mBAAoC,CAAC;IAEzC,UAAU,CAAC,GAAG,EAAE;QACZ,OAAO,CAAC,KAAK,EAAE,CAAC;QAChB,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAC5B,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC7B,gBAAgB,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;QAChC,mBAAmB,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AAC,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IAEjC,EAAE,CAAC,qCAAqC,EAAE,GAAG,EAAE,CAC3C,gBAAgB,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;IAC7C,EAAE,CAAC,uCAAuC,EAAE,GAAG,EAAE,CAC7C,mBAAmB,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC;IACnD,EAAE,CAAC,wDAAwD,EAAE,GAAG,EAAE,CAC9D,OAAO,CAAC,UAAU,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACnD,EAAE,CAAC,gCAAgC,EAAE,GAAG,EAAE,CACrC,OAAO,CAAC,KAAyB,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;IAE/D,SAAS,WAAW,CAAC,KAAa;QAC9B,IAAI,CAAC;YACD,OAAO,IAAI,CAAC,KAAK,CACb,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CACnC,CAAC;QACpB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,MAAM,IAAI,KAAK,CAAC,8BAA8B,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,CAAC,CAAC;QACtE,CAAC;IACL,CAAC;AACL,CAAC,CAAC,CACL,CAAC"}
|
|
@@ -2,7 +2,7 @@ import sinon from 'sinon';
|
|
|
2
2
|
import { a_web_socket_hub_connection } from '../given/a_web_socket_hub_connection';
|
|
3
3
|
import { given } from '../../../given';
|
|
4
4
|
import { HubMessageType } from '../../WebSocketHubConnection';
|
|
5
|
-
describe('when subscribing to a query', given(a_web_socket_hub_connection, context => {
|
|
5
|
+
describe('when subscribing to a query', given(a_web_socket_hub_connection, (context) => {
|
|
6
6
|
const queryId = 'q1';
|
|
7
7
|
const request = { queryName: 'MyQuery', arguments: {} };
|
|
8
8
|
let callback;
|
|
@@ -14,16 +14,29 @@ describe('when subscribing to a query', given(a_web_socket_hub_connection, conte
|
|
|
14
14
|
});
|
|
15
15
|
afterEach(() => sinon.restore());
|
|
16
16
|
it('should open a WebSocket', () => context.WebSocketStub.calledOnce.should.be.true);
|
|
17
|
-
it('should send a subscribe message once the socket opens', () => {
|
|
18
|
-
context.fakeSocket.send.calledOnce.should.
|
|
19
|
-
const msg =
|
|
17
|
+
it('should send a legacy subscribe message once the socket opens', () => {
|
|
18
|
+
context.fakeSocket.send.calledOnce.should.equal(true);
|
|
19
|
+
const msg = getSentMessage();
|
|
20
20
|
msg.type.should.equal(HubMessageType.Subscribe);
|
|
21
21
|
msg.queryId.should.equal(queryId);
|
|
22
|
+
(msg.revision === undefined).should.equal(true);
|
|
22
23
|
});
|
|
24
|
+
function getSentMessage() {
|
|
25
|
+
try {
|
|
26
|
+
return JSON.parse(context.fakeSocket.send.firstCall.args[0]);
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
throw new Error('Expected a valid hub message', { cause: error });
|
|
30
|
+
}
|
|
31
|
+
}
|
|
23
32
|
describe('when a query result message arrives', () => {
|
|
24
33
|
const result = { isSuccess: true, data: [1, 2, 3] };
|
|
25
34
|
beforeEach(() => {
|
|
26
|
-
context.simulateMessage({
|
|
35
|
+
context.simulateMessage({
|
|
36
|
+
type: HubMessageType.QueryResult,
|
|
37
|
+
queryId,
|
|
38
|
+
payload: result,
|
|
39
|
+
});
|
|
27
40
|
});
|
|
28
41
|
it('should invoke the callback with the result', () => callback.calledOnce.should.be.true);
|
|
29
42
|
it('should pass the result payload', () => callback.getCall(0).args[0].should.deep.equal(result));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to_a_query.js","sourceRoot":"","sources":["../../../../../queries/for_WebSocketHubConnection/when_subscribing/to_a_query.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,O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C,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC;IAC/D,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CACL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upgrades_active_subscriptions_to_strict_mode.d.ts","sourceRoot":"","sources":["../../../../../queries/for_WebSocketHubConnection/when_subscription_revisions_are_supported/upgrades_active_subscriptions_to_strict_mode.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import sinon from 'sinon';
|
|
2
|
+
import { given } from '../../../given';
|
|
3
|
+
import { HubMessageType } from '../../WebSocketHubConnection';
|
|
4
|
+
import { a_web_socket_hub_connection } from '../given/a_web_socket_hub_connection';
|
|
5
|
+
describe('when the WebSocket server advertises subscription revision support', given(a_web_socket_hub_connection, (context) => {
|
|
6
|
+
const queryId = 'query-1';
|
|
7
|
+
let callback;
|
|
8
|
+
let revision;
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
context.setup();
|
|
11
|
+
callback = sinon.stub();
|
|
12
|
+
context.connection.subscribe(queryId, { queryName: 'MyQuery' }, callback);
|
|
13
|
+
context.simulateOpen();
|
|
14
|
+
context.simulateMessage({
|
|
15
|
+
type: HubMessageType.Connected,
|
|
16
|
+
supportsSubscriptionRevisions: true,
|
|
17
|
+
});
|
|
18
|
+
const upgradedRevision = sentMessage(1).revision;
|
|
19
|
+
if (upgradedRevision === undefined) {
|
|
20
|
+
throw new Error('Expected the upgraded subscription to carry a revision');
|
|
21
|
+
}
|
|
22
|
+
revision = upgradedRevision;
|
|
23
|
+
context.simulateMessage({
|
|
24
|
+
type: HubMessageType.QueryResult,
|
|
25
|
+
queryId,
|
|
26
|
+
payload: { data: ['legacy'] },
|
|
27
|
+
});
|
|
28
|
+
context.simulateMessage({
|
|
29
|
+
type: HubMessageType.QueryResult,
|
|
30
|
+
queryId,
|
|
31
|
+
revision,
|
|
32
|
+
payload: { data: ['current'] },
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
afterEach(() => sinon.restore());
|
|
36
|
+
it('should initially subscribe without a revision for older servers', () => (sentMessage(0).revision === undefined).should.equal(true));
|
|
37
|
+
it('should replace the legacy subscription with its current revision', () => {
|
|
38
|
+
const message = sentMessage(1);
|
|
39
|
+
message.type.should.equal(HubMessageType.Subscribe);
|
|
40
|
+
(message.queryId === queryId).should.equal(true);
|
|
41
|
+
revision.should.be.greaterThan(0);
|
|
42
|
+
});
|
|
43
|
+
it('should ignore the temporary legacy result and deliver the strict result once', () => {
|
|
44
|
+
callback.calledOnce.should.equal(true);
|
|
45
|
+
callback.firstCall.args[0].should.deep.equal({ data: ['current'] });
|
|
46
|
+
});
|
|
47
|
+
function sentMessage(index) {
|
|
48
|
+
try {
|
|
49
|
+
return JSON.parse(context.fakeSocket.send.getCall(index).args[0]);
|
|
50
|
+
}
|
|
51
|
+
catch (error) {
|
|
52
|
+
throw new Error('Expected a valid hub message', { cause: error });
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}));
|
|
56
|
+
//# sourceMappingURL=upgrades_active_subscriptions_to_strict_mode.js.map
|